UNPKG

1.87 kBTypeScriptView Raw
1import { Widget } from '@lumino/widgets';
2/**
3 * Any object is "printable" if it implements the `IPrintable` interface.
4 *
5 * To do this it, it must have a method called `Printing.symbol` which returns either a function
6 * to print the object or null if it cannot be printed.
7 *
8 * One way of printing is to use the `printWidget` function, which creates a hidden iframe
9 * and copies the DOM nodes from your widget to that iframe and printing just that iframe.
10 *
11 * Another way to print is to use the `printURL` function, which takes a URL and prints that page.
12 */
13export declare namespace Printing {
14 /**
15 * Function that takes no arguments and when invoked prints out some object or null if printing is not defined.
16 */
17 type OptionalAsyncThunk = (() => Promise<void>) | null;
18 /**
19 * Symbol to use for a method that returns a function to print an object.
20 */
21 const symbol: unique symbol;
22 /**
23 * Objects who provide a custom way of printing themselves
24 * should implement this interface.
25 */
26 interface IPrintable {
27 /**
28 * Returns a function to print this object or null if it cannot be printed.
29 */
30 [symbol]: () => OptionalAsyncThunk;
31 }
32 /**
33 * Returns whether an object implements a print method.
34 */
35 function isPrintable(a: unknown): a is IPrintable;
36 /**
37 * Returns the print function for an object, or null if it does not provide a handler.
38 */
39 function getPrintFunction(val: unknown): OptionalAsyncThunk;
40 /**
41 * Prints a widget by copying it's DOM node
42 * to a hidden iframe and printing that iframe.
43 */
44 function printWidget(widget: Widget): Promise<void>;
45 /**
46 * Prints a URL by loading it into an iframe.
47 *
48 * @param url URL to load into an iframe.
49 */
50 function printURL(url: string): Promise<void>;
51}