@folijs/view 0.5.0 → 1.0.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.
Files changed (82) hide show
  1. package/CHANGELOG.md +194 -0
  2. package/README.md +1 -1
  3. package/dist/clipboard.d.ts +1 -49
  4. package/dist/clipboard.d.ts.map +1 -1
  5. package/dist/clipboard.js +65 -13
  6. package/dist/clipboard.js.map +1 -1
  7. package/dist/extension.d.ts +90 -0
  8. package/dist/extension.d.ts.map +1 -0
  9. package/dist/extension.js +152 -0
  10. package/dist/extension.js.map +1 -0
  11. package/dist/index.d.ts +2 -1
  12. package/dist/index.d.ts.map +1 -1
  13. package/dist/index.js.map +1 -1
  14. package/dist/layout/flow.d.ts +1 -109
  15. package/dist/layout/flow.d.ts.map +1 -1
  16. package/dist/layout/flow.js +808 -103
  17. package/dist/layout/flow.js.map +1 -1
  18. package/dist/print.d.ts +6 -0
  19. package/dist/print.d.ts.map +1 -0
  20. package/dist/print.js +35 -0
  21. package/dist/print.js.map +1 -0
  22. package/dist/render.d.ts +1 -24
  23. package/dist/render.d.ts.map +1 -1
  24. package/dist/render.js +4 -1
  25. package/dist/render.js.map +1 -1
  26. package/dist/view.d.ts +244 -64
  27. package/dist/view.d.ts.map +1 -1
  28. package/dist/view.js +1945 -215
  29. package/dist/view.js.map +1 -1
  30. package/dist/word/blocks.d.ts +0 -146
  31. package/dist/word/blocks.d.ts.map +1 -1
  32. package/dist/word/blocks.js +294 -59
  33. package/dist/word/blocks.js.map +1 -1
  34. package/dist/word/columns.d.ts +2 -0
  35. package/dist/word/columns.d.ts.map +1 -0
  36. package/dist/word/columns.js +63 -0
  37. package/dist/word/columns.js.map +1 -0
  38. package/dist/word/controls.d.ts +2 -0
  39. package/dist/word/controls.d.ts.map +1 -0
  40. package/dist/word/controls.js +416 -0
  41. package/dist/word/controls.js.map +1 -0
  42. package/dist/word/edit.d.ts +1 -71
  43. package/dist/word/edit.d.ts.map +1 -1
  44. package/dist/word/edit.js +338 -29
  45. package/dist/word/edit.js.map +1 -1
  46. package/dist/word/matches.d.ts +2 -0
  47. package/dist/word/matches.d.ts.map +1 -0
  48. package/dist/word/matches.js +102 -0
  49. package/dist/word/matches.js.map +1 -0
  50. package/dist/word/notes.d.ts +2 -0
  51. package/dist/word/notes.d.ts.map +1 -0
  52. package/dist/word/notes.js +403 -0
  53. package/dist/word/notes.js.map +1 -0
  54. package/dist/word/pages.d.ts +30 -20
  55. package/dist/word/pages.d.ts.map +1 -1
  56. package/dist/word/pages.js +421 -229
  57. package/dist/word/pages.js.map +1 -1
  58. package/dist/word/regions.d.ts +2 -0
  59. package/dist/word/regions.d.ts.map +1 -0
  60. package/dist/word/regions.js +388 -0
  61. package/dist/word/regions.js.map +1 -0
  62. package/dist/word/table.d.ts +1 -78
  63. package/dist/word/table.d.ts.map +1 -1
  64. package/dist/word/table.js +13 -3
  65. package/dist/word/table.js.map +1 -1
  66. package/package.json +6 -3
  67. package/src/clipboard.ts +93 -20
  68. package/src/extension.ts +267 -0
  69. package/src/index.ts +10 -0
  70. package/src/layout/flow.ts +997 -116
  71. package/src/print.ts +55 -0
  72. package/src/render.ts +6 -1
  73. package/src/view.ts +2178 -245
  74. package/src/word/blocks.ts +339 -62
  75. package/src/word/columns.ts +81 -0
  76. package/src/word/controls.ts +457 -0
  77. package/src/word/edit.ts +381 -31
  78. package/src/word/matches.ts +104 -0
  79. package/src/word/notes.ts +464 -0
  80. package/src/word/pages.ts +518 -221
  81. package/src/word/regions.ts +488 -0
  82. package/src/word/table.ts +33 -8
@@ -0,0 +1,152 @@
1
+ /**
2
+ * The view's side of extensions (ADR-0008, 12.4): node views draw custom nodes, mark views style
3
+ * runs of custom marks, decorations put classes and attributes on drawn ranges, and plugin views
4
+ * live as long as the `EditorView`. Core has no DOM: these hooks are on `ViewExtension`, which an
5
+ * app gives to `createEditor` as an ordinary extension; the view reads them from
6
+ * `editor.extensions`.
7
+ *
8
+ * Everything here is drawn with DOM calls, never parsed from HTML: attribute names are checked
9
+ * (no `on*` handlers, no `contenteditable`, none of the view's own `data-foli-*`), and URL
10
+ * attributes must be safe links (`isSafeHref`).
11
+ */
12
+ import { isSafeHref, } from "@folijs/core";
13
+ /** @internal */
14
+ export function viewsOf(extensions) {
15
+ return {
16
+ nodes: new Map(extensions.flatMap((e) => Object.entries(e.nodeViews ?? {}))),
17
+ marks: new Map(extensions.flatMap((e) => Object.entries(e.markViews ?? {}))),
18
+ };
19
+ }
20
+ const NAME = /^[a-z_][\w.:-]*$/i;
21
+ const URL_ATTRS = new Set([
22
+ "href",
23
+ "src",
24
+ "xlink:href",
25
+ "action",
26
+ "formaction",
27
+ "poster",
28
+ "background",
29
+ ]);
30
+ /** Attributes holding several URLs: `srcset` (comma separated, each before its size), `ping`. */
31
+ const URL_LISTS = {
32
+ srcset: (value) => value.split(",").map((part) => part.trim().split(/\s+/)[0] ?? ""),
33
+ ping: (value) => value.split(/\s+/).filter(Boolean),
34
+ };
35
+ /** Style that fetches or runs something (escapes could spell it otherwise). */
36
+ const UNSAFE_STYLE = /url\s*\(|image-set|expression|@import|-moz-binding|behavior|\\/i;
37
+ /** Content elements a node view may make with `h` (no scripts, styles, forms, frames, `base`). */
38
+ const TAGS = new Set(("a abbr address article aside audio b bdi bdo blockquote br button canvas caption cite code " +
39
+ "col colgroup data dd del details dfn div dl dt em figcaption figure footer h1 h2 h3 h4 h5 h6 " +
40
+ "header hgroup hr i img ins kbd label li mark meter ol p picture pre progress q rp rt ruby s " +
41
+ "samp section small source span strong sub summary sup table tbody td tfoot th thead time tr " +
42
+ "track u ul var video wbr").split(" "));
43
+ /** Throws on an attribute a view must not set: handlers, editing, the view's own, unsafe URLs. */
44
+ function check(name, value) {
45
+ const lower = name.toLowerCase();
46
+ if (!NAME.test(name) ||
47
+ lower.startsWith("on") ||
48
+ lower === "contenteditable" ||
49
+ lower === "srcdoc" ||
50
+ lower.startsWith("data-foli-") ||
51
+ (URL_ATTRS.has(lower) && !isSafeHref(value)) ||
52
+ URL_LISTS[lower]?.(value).some((url) => !isSafeHref(url)) ||
53
+ (lower === "style" && UNSAFE_STYLE.test(value)) ||
54
+ (lower === "class" && /(^|\s)foli-/.test(value)))
55
+ throw new TypeError(`Foli: attribute ${name} is not allowed on drawn content`);
56
+ }
57
+ /**
58
+ * Throws when `attrs` holds one an extension must not set (`check`).
59
+ * @internal
60
+ */
61
+ export function checkAttrs(attrs) {
62
+ for (const [name, value] of Object.entries(attrs))
63
+ if (value !== undefined)
64
+ check(name, value);
65
+ }
66
+ /**
67
+ * Puts `attrs` on `element` (classes and style added, the rest set).
68
+ * @internal
69
+ */
70
+ export function applyAttrs(element, attrs) {
71
+ checkAttrs(attrs);
72
+ for (const [name, value] of Object.entries(attrs)) {
73
+ if (value === undefined)
74
+ continue;
75
+ if (name === "class")
76
+ element.classList.add(...value.split(/\s+/).filter(Boolean));
77
+ else if (name === "style") {
78
+ const style = element.getAttribute("style")?.trim() ?? "";
79
+ element.setAttribute("style", style && !style.endsWith(";") ? `${style};${value}` : style + value);
80
+ }
81
+ else
82
+ element.setAttribute(name, value);
83
+ }
84
+ }
85
+ /**
86
+ * Reports an extension's failure without stopping the editor.
87
+ * @internal
88
+ */
89
+ export function reportError(error) {
90
+ console.error("Foli: an extension failed", error);
91
+ }
92
+ /** The DOM API node views draw with. @internal */
93
+ export function nodeViewDOM(document) {
94
+ return {
95
+ document,
96
+ h(tag, attrs, ...children) {
97
+ if (!TAGS.has(tag.toLowerCase()))
98
+ throw new TypeError(`Foli: element ${tag} is not allowed in a node view`);
99
+ const element = document.createElement(tag);
100
+ if (attrs)
101
+ applyAttrs(element, attrs);
102
+ element.append(...children);
103
+ return element;
104
+ },
105
+ };
106
+ }
107
+ /**
108
+ * The decorations of each block (`units`: the blocks drawn, in document order, with the position
109
+ * before each), relative to its content's start: a node decoration on the block itself is at -1.
110
+ * @internal
111
+ */
112
+ export function decorationsByBlock(units, decorations) {
113
+ const out = [];
114
+ const add = (i, d) => {
115
+ const list = out[i] ?? [];
116
+ out[i] = list;
117
+ list.push(d);
118
+ };
119
+ for (const decoration of decorations) {
120
+ const { from, to } = decoration;
121
+ if (!(from <= to) || (!decoration.node && from === to))
122
+ continue;
123
+ // The first block ending after `from` (blocks do not overlap: their ends are sorted too).
124
+ let low = 0;
125
+ let high = units.length;
126
+ while (low < high) {
127
+ const mid = (low + high) >> 1;
128
+ const unit = units[mid];
129
+ if (unit.pos + unit.node.nodeSize <= from)
130
+ low = mid + 1;
131
+ else
132
+ high = mid;
133
+ }
134
+ for (let i = low; i < units.length; i++) {
135
+ const { pos, node } = units[i];
136
+ const start = pos + 1;
137
+ if (decoration.node) {
138
+ if (from >= pos && from < pos + node.nodeSize)
139
+ add(i, { ...decoration, from: from - start, to: to - start });
140
+ break;
141
+ }
142
+ if (pos >= to)
143
+ break;
144
+ const end = pos + node.nodeSize - 1;
145
+ // A block leaf has no text to decorate.
146
+ if (!node.isLeaf && from < end && to > start)
147
+ add(i, { ...decoration, from: from - start, to: to - start });
148
+ }
149
+ }
150
+ return out;
151
+ }
152
+ //# sourceMappingURL=extension.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extension.js","sourceRoot":"","sources":["../src/extension.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EAGL,UAAU,GAGX,MAAM,cAAc,CAAC;AAuGtB,gBAAgB;AAChB,MAAM,UAAU,OAAO,CAAC,UAAoC;IAC1D,OAAO;QACL,KAAK,EAAE,IAAI,GAAG,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,IAAI,EAAE,CAAC,CAAC,CAAC;QAC5E,KAAK,EAAE,IAAI,GAAG,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,IAAI,EAAE,CAAC,CAAC,CAAC;KAC7E,C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CAAC,CAAC;YACpC,wCAAwC;YACxC,IAAI,CAAC,IAAI,CAAC,MAAM,IAAI,IAAI,GAAG,GAAG,IAAI,EAAE,GAAG,KAAK;gBAC1C,GAAG,CAAC,CAAC,EAAE,EAAE,GAAG,UAAU,EAAE,IAAI,EAAE,IAAI,GAAG,KAAK,EAAE,EAAE,EAAE,EAAE,GAAG,KAAK,EAAE,CAAC,CAAC;QAClE,CAAC;IACH,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export { FOLI_MIME, htmlToDoc, textToDoc } from "./clipboard.js";
2
+ export type { Decoration, DecorationAttrs, MarkView, NodeView, NodeViewDOM, PluginView, ViewExtension, } from "./extension.js";
2
3
  export { EditorView, type EditorViewOptions, keyName, measureImageFile, textWidthEmu, } from "./view.js";
3
4
  export { EMU_PER_PX } from "./word/blocks.js";
4
- export { type DocumentPages, type ReviewView, renderDocument, WORD_PAGE_CLASS, } from "./word/pages.js";
5
+ export { type DocumentPages, type RenderDocumentOptions, type ReviewView, renderDocument, WORD_PAGE_CLASS, } from "./word/pages.js";
5
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AACjE,OAAO,EACL,UAAU,EACV,KAAK,iBAAiB,EACtB,OAAO,EACP,gBAAgB,EAChB,YAAY,GACb,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,UAAU,EACf,cAAc,EACd,eAAe,GAChB,MAAM,iBAAiB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AACjE,YAAY,EACV,UAAU,EACV,eAAe,EACf,QAAQ,EACR,QAAQ,EACR,WAAW,EACX,UAAU,EACV,aAAa,GACd,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,UAAU,EACV,KAAK,iBAAiB,EACtB,OAAO,EACP,gBAAgB,EAChB,YAAY,GACb,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,qBAAqB,EAC1B,KAAK,UAAU,EACf,cAAc,EACd,eAAe,GAChB,MAAM,iBAAiB,CAAC"}
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AACjE,OAAO,EACL,UAAU,EAEV,OAAO,EACP,gBAAgB,EAChB,YAAY,GACb,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAGL,cAAc,EACd,eAAe,GAChB,MAAM,iBAAiB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAUjE,OAAO,EACL,UAAU,EAEV,OAAO,EACP,gBAAgB,EAChB,YAAY,GACb,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAIL,cAAc,EACd,eAAe,GAChB,MAAM,iBAAiB,CAAC"}
@@ -1,110 +1,2 @@
1
- import type { DocumentSettings } from "@folijs/core";
2
- /** CSS pixels per millimetre (CSS fixes 1in = 96px = 25.4mm). */
3
- export declare const PX_PER_MM: number;
4
- /** A rendered block's border-box height and vertical margins, in CSS px. */
5
- export interface BlockBox {
6
- height: number;
7
- marginTop: number;
8
- marginBottom: number;
9
- /**
10
- * The bottom of each line box, from the block's top (the last one is `height`). Only called
11
- * for a block that does not fit where it is, or has page breaks, since measuring lines is
12
- * expensive.
13
- */
14
- lines(): readonly number[];
15
- /** Keep on the same page as the start of the next block (headings). */
16
- keepWithNext?: boolean;
17
- /** The lines that end with an explicit page break (indices into `lines()`), if any. */
18
- breaksAfter?(): readonly number[];
19
- /** Height shown again at the top of each fragment after the first (a table's header rows). */
20
- repeat?: number;
21
- /** Splits at any of its line ends, without widow and orphan control (a table's rows). */
22
- anyLine?: boolean;
23
- /**
24
- * Content height of the pages this block goes on, when not the flow's (a section's page). A
25
- * block with another page height than the one before it must start a page (an explicit
26
- * break before it): a page has one height.
27
- */
28
- pageHeight?: number;
29
- }
30
- /** The lines `[fromLine, toLine)` of a block, placed on one page (`toLine` Infinity: to the end). */
31
- export interface Fragment {
32
- page: number;
33
- fromLine: number;
34
- toLine: number;
35
- }
36
- export interface FlowRules {
37
- /** Fewest lines of a split block left at the bottom of a page. */
38
- orphans: number;
39
- /** Fewest lines of a split block carried to the top of the next page. */
40
- widows: number;
41
- /**
42
- * How margins (paragraph spacing) combine. `css` (the default): as CSS in a padded page.
43
- * `word`: as Word spaces paragraphs. The space after one and the space before the next add up.
44
- * A page that a block flowed onto (not one an explicit break started, nor the first) drops
45
- * the space before its first block. The space after the last block on a page need not fit.
46
- */
47
- spacing?: "css" | "word";
48
- }
49
- export declare const DEFAULT_RULES: FlowRules;
50
- /** Height of a page's content box (page height minus top and bottom margins), in CSS px. */
51
- export declare function contentHeight({ pageSize, margins }: DocumentSettings): number;
52
- /** Where the flow stands before a block: shared by a full and an incremental flow. */
53
- export interface FlowState {
54
- page: number;
55
- used: number;
56
- previousMargin: number;
57
- onPage: number;
58
- /** An explicit page break ended the previous block: the next one starts a new page. */
59
- breakPending: boolean;
60
- /** The page is the first or an explicit break started it (Word keeps its first space before). */
61
- forcedPage: boolean;
62
- }
63
- /**
64
- * Page flow: the fragments of each block, in order. Blocks fill a page in order; a block that
65
- * does not fit is split at a line boundary, the lines that fit staying on the page, the rest
66
- * continuing at the top of the next one (as many pages as it takes). A page with room for no
67
- * line of the next block ends; an empty page always takes at least one line.
68
- *
69
- * Rules:
70
- * - Explicit page breaks: the line holding one ends its page.
71
- * - Widows and orphans: a split leaves at least `orphans` lines at the bottom of a page and
72
- * carries at least `widows` lines to the next; a block too short for both moves whole. Not
73
- * applied where only an empty page could hold the lines, nor across an explicit break.
74
- * - Keep with next: a `keepWithNext` block (and a chain of them) moves to the next page when
75
- * the block after it would start there, unless it already starts its page or the move would
76
- * not bring them together (then the flow stays as it was).
77
- *
78
- * Spacing follows CSS inside a padded page: the first block keeps its top margin, adjacent
79
- * margins collapse to the larger, and the last block's bottom margin stays inside the page
80
- * (it does not collapse into the padding), so it must fit too. Fragments are rendered without
81
- * the margins at their split edges: a continued fragment has no bottom margin, a continuation
82
- * no top margin.
83
- *
84
- * shortcut: positive margins only (negative margins collapse differently).
85
- */
86
- export declare function flow(boxes: readonly BlockBox[], pageHeight: number, rules?: FlowRules): Fragment[][];
87
- /** A flow with the state before each block (and after the last), for the next incremental one. */
88
- export interface FlowResult {
89
- fragments: Fragment[][];
90
- states: FlowState[];
91
- }
92
- /** What an incremental flow may reuse from the previous one. */
93
- export interface Reuse {
94
- previous: FlowResult;
95
- /** Blocks before this index are the previous flow's first blocks, with the same boxes. */
96
- from: number;
97
- /**
98
- * The previous index of block `i` when it and every block after it are unchanged from the
99
- * previous flow (the common tail of an edit), else -1.
100
- */
101
- previousIndex(i: number): number;
102
- }
103
- /**
104
- * `flow`, reusing a previous one: it starts at `reuse.from` (backed up over a chain of
105
- * keep-with-next blocks, whose placement depends on what follows) with the previous state
106
- * there, and once the state before an unchanged block equals the previous state before it, the
107
- * rest is the previous flow's. The result is the same as a full flow.
108
- */
109
- export declare function flowFrom(boxes: readonly BlockBox[], flowHeight: number, rules?: FlowRules, reuse?: Reuse): FlowResult;
1
+ export {};
110
2
  //# sourceMappingURL=flow.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"flow.d.ts","sourceRoot":"","sources":["../../src/layout/flow.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAErD,iEAAiE;AACjE,eAAO,MAAM,SAAS,QAAY,CAAC;AAEnC,4EAA4E;AAC5E,MAAM,WAAW,QAAQ;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,MAAM,CAAC;IACrB;;;;OAIG;IACH,KAAK,IAAI,SAAS,MAAM,EAAE,CAAC;IAC3B,uEAAuE;IACvE,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,uFAAuF;IACvF,WAAW,CAAC,IAAI,SAAS,MAAM,EAAE,CAAC;IAClC,8FAA8F;IAC9F,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,yFAAyF;IACzF,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB;;;;OAIG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,qGAAqG;AACrG,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,SAAS;IACxB,kEAAkE;IAClE,OAAO,EAAE,MAAM,CAAC;IAChB,yEAAyE;IACzE,MAAM,EAAE,MAAM,CAAC;IACf;;;;;OAKG;IACH,OAAO,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC;CAC1B;AAED,eAAO,MAAM,aAAa,EAAE,SAAqC,CAAC;AAElE,4FAA4F;AAC5F,wBAAgB,aAAa,CAAC,EAAE,QAAQ,EAAE,OAAO,EAAE,EAAE,gBAAgB,GAAG,MAAM,CAE7E;A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