svelte-rtf-editor 1.9.0 → 1.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,99 @@
1
+ /**
2
+ * HTML that is safe to put in the editor.
3
+ *
4
+ * The editor shows HTML it is given: the `content` prop, setHTML(), a draft restored from
5
+ * localStorage, and whatever a paste brings. Written to the page as it is, an
6
+ * <img onerror="…"> in any of those runs as script, and a pasted block with position: fixed
7
+ * covers the page the editor sits in. So all of it goes through here first.
8
+ *
9
+ * What stays is what a document is made of: text, the elements that format it, links to web,
10
+ * mail and phone addresses, pictures, tables. What goes:
11
+ *
12
+ * - elements that run code or load something of their own (<script>, <iframe>, <object>,
13
+ * <svg>, …), with everything in them;
14
+ * - elements that take input (<button>, <textarea>, <select>, <input>) and formulas (<math>):
15
+ * the element goes and the words it showed stay, as text. Words it did not show (the element
16
+ * or a part of it was hidden) go with it;
17
+ * - every attribute not listed below, which is how event handlers (onclick, onerror) go;
18
+ * - `class`, which would take on what the page's own stylesheet gives that name, an `id` that
19
+ * the page already uses for something of its own, and the `id` of a link;
20
+ * - a link address that is not a web, mail or phone address (javascript:, data:, file:), and a
21
+ * picture address that is not a web address or picture data;
22
+ * - every style property not listed below (position, z-index, …), any value with a url(), and
23
+ * any size that would put the element, or its words, outside the page it is on or out of
24
+ * sight (a margin below zero, a padding of thousands of pixels, a first line that starts left
25
+ * of its paragraph, text of no size).
26
+ */
27
+ /** What an application asked to have kept on its own documents. */
28
+ export interface KeepOptions {
29
+ /** `data-` attributes that stay on any element. */
30
+ keepAttributes?: readonly string[];
31
+ /** Class names that stay in an element's class list. */
32
+ keepClasses?: readonly string[];
33
+ }
34
+ /** The same, as the sets the sanitizer reads. */
35
+ export interface Kept {
36
+ attributes: ReadonlySet<string>;
37
+ classes: ReadonlySet<string>;
38
+ }
39
+ /**
40
+ * What an application asked to have kept (the editor's `keepAttributes` and `keepClasses`), as
41
+ * the sets the sanitizer reads. Only `data-` attributes can be asked for: they mark an element
42
+ * and do nothing else, where `onclick`, `src` or `style` asked for here would undo what this
43
+ * file is for. A class is kept by its name alone; what it looks like is the page's stylesheet,
44
+ * which is why none is kept unless the application names it. A name that is neither is left out.
45
+ */
46
+ export declare function keptMarks(options: KeepOptions | undefined): Kept;
47
+ /**
48
+ * Make the elements under `root` safe, in place. With `only`, just the elements it accepts (the
49
+ * ones a paste brought in) are looked at; the rest of the document is left as it is. With
50
+ * `idTaken`, an id it says the page already uses is taken off. With `keep` (see keptMarks),
51
+ * the application's own `data-` attributes and classes stay.
52
+ * Returns whether anything was taken out or changed.
53
+ */
54
+ export declare function sanitizeTree(root: Element, only?: (el: Element) => boolean, idTaken?: (id: string) => boolean, keep?: Kept): boolean;
55
+ /**
56
+ * HTML made safe to show and edit: see the top of this file for what is kept. It is parsed in a
57
+ * document of its own, where nothing in it runs or loads, before any of it reaches the page.
58
+ * Where there is no DOM to parse it with (on a server), nothing is returned: HTML that could
59
+ * not be checked is not passed on. `keepAttributes` and `keepClasses` name marks of the
60
+ * application's own to leave on (see keptMarks).
61
+ */
62
+ export declare function sanitizeHtml(html: string, options?: KeepOptions): string;
63
+ /**
64
+ * The same, as nodes for `into` to hold. The editor puts these in the page as they are: what was
65
+ * checked is what is shown. Written out as text and read in again, a second reading has to
66
+ * agree with the first for the check to mean anything, and that is where a sanitizer is got
67
+ * round; it is also a third pass over a document that may hold megabytes of pictures.
68
+ */
69
+ export declare function sanitizedNodes(html: string, into: Document, idTaken?: (id: string) => boolean, keep?: Kept): Node[];
70
+ /** A run of a paste's text. */
71
+ interface PastePiece {
72
+ text: string;
73
+ /** Hidden by Word's mark. */
74
+ hidden: boolean;
75
+ /** Not shown by a style a browser knows, or by `hidden`. */
76
+ undisplayed: boolean;
77
+ }
78
+ /** What a paste holds that a browser may not carry into the page as it is. */
79
+ export interface PasteNotes {
80
+ /** Its text in order. */
81
+ pieces: PastePiece[];
82
+ /** What each of its text boxes held. */
83
+ textareas: string[];
84
+ }
85
+ /**
86
+ * Read from a paste's HTML what the browser's own paste may lose: null where it holds neither
87
+ * Word's hidden text nor a text box, which is nearly every paste.
88
+ */
89
+ export declare function pasteNotes(html: string): PasteNotes | null;
90
+ /**
91
+ * Take Word's hidden text out of what a paste put under `root`. The paste is the text from the
92
+ * `from`th to the `to`th character of `root` that is not white space. Nothing is done unless
93
+ * that text is the paste's own, character for character: only then is it known which of the
94
+ * characters were the hidden ones. An element left with nothing in it goes too, where
95
+ * `mayRemove` allows (a paragraph that was hidden whole would stay as an empty line in the
96
+ * RTF). Returns whether anything was taken out.
97
+ */
98
+ export declare function removeWordHidden(root: Element, from: number, to: number, notes: PasteNotes, mayRemove?: (el: Element) => boolean): boolean;
99
+ export {};