svelte-rtf-editor 1.9.0 → 1.10.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,77 @@
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
+ /**
28
+ * Make the elements under `root` safe, in place. With `only`, just the elements it accepts (the
29
+ * ones a paste brought in) are looked at; the rest of the document is left as it is. With
30
+ * `idTaken`, an id it says the page already uses is taken off.
31
+ * Returns whether anything was taken out or changed.
32
+ */
33
+ export declare function sanitizeTree(root: Element, only?: (el: Element) => boolean, idTaken?: (id: string) => boolean): boolean;
34
+ /**
35
+ * HTML made safe to show and edit: see the top of this file for what is kept. It is parsed in a
36
+ * document of its own, where nothing in it runs or loads, before any of it reaches the page.
37
+ * Where there is no DOM to parse it with (on a server), nothing is returned: HTML that could
38
+ * not be checked is not passed on.
39
+ */
40
+ export declare function sanitizeHtml(html: string): string;
41
+ /**
42
+ * The same, as nodes for `into` to hold. The editor puts these in the page as they are: what was
43
+ * checked is what is shown. Written out as text and read in again, a second reading has to
44
+ * agree with the first for the check to mean anything, and that is where a sanitizer is got
45
+ * round; it is also a third pass over a document that may hold megabytes of pictures.
46
+ */
47
+ export declare function sanitizedNodes(html: string, into: Document, idTaken?: (id: string) => boolean): Node[];
48
+ /** A run of a paste's text. */
49
+ interface PastePiece {
50
+ text: string;
51
+ /** Hidden by Word's mark. */
52
+ hidden: boolean;
53
+ /** Not shown by a style a browser knows, or by `hidden`. */
54
+ undisplayed: boolean;
55
+ }
56
+ /** What a paste holds that a browser may not carry into the page as it is. */
57
+ export interface PasteNotes {
58
+ /** Its text in order. */
59
+ pieces: PastePiece[];
60
+ /** What each of its text boxes held. */
61
+ textareas: string[];
62
+ }
63
+ /**
64
+ * Read from a paste's HTML what the browser's own paste may lose: null where it holds neither
65
+ * Word's hidden text nor a text box, which is nearly every paste.
66
+ */
67
+ export declare function pasteNotes(html: string): PasteNotes | null;
68
+ /**
69
+ * Take Word's hidden text out of what a paste put under `root`. The paste is the text from the
70
+ * `from`th to the `to`th character of `root` that is not white space. Nothing is done unless
71
+ * that text is the paste's own, character for character: only then is it known which of the
72
+ * characters were the hidden ones. An element left with nothing in it goes too, where
73
+ * `mayRemove` allows (a paragraph that was hidden whole would stay as an empty line in the
74
+ * RTF). Returns whether anything was taken out.
75
+ */
76
+ export declare function removeWordHidden(root: Element, from: number, to: number, notes: PasteNotes, mayRemove?: (el: Element) => boolean): boolean;
77
+ export {};