@formicoidea/labre-core 0.50.0 → 0.51.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.
- package/dist/_pkgs/affine-block-attachment/asset-picker.d.ts +24 -0
- package/dist/_pkgs/affine-block-attachment/asset-picker.js +87 -0
- package/dist/_pkgs/affine-block-attachment/configs/slash-menu.js +3 -20
- package/dist/_pkgs/affine-block-attachment/index.d.ts +1 -0
- package/dist/_pkgs/affine-block-attachment/index.js +1 -0
- package/dist/_pkgs/affine-block-attachment/utils.d.ts +9 -1
- package/dist/_pkgs/affine-block-attachment/utils.js +9 -0
- package/dist/_pkgs/affine-block-bookmark/adapters/markdown/markdown.js +14 -1
- package/dist/_pkgs/affine-block-bookmark/adapters/notion-html.js +5 -1
- package/dist/_pkgs/affine-block-database/adapters/markdown.js +5 -3
- package/dist/_pkgs/affine-block-embed/common/adapters/html.js +5 -3
- package/dist/_pkgs/affine-block-embed/common/adapters/markdown.js +11 -0
- package/dist/_pkgs/affine-block-frame/frame-template.d.ts +58 -0
- package/dist/_pkgs/affine-block-frame/frame-template.js +207 -0
- package/dist/_pkgs/affine-block-frame/frame-toolbar.js +19 -3
- package/dist/_pkgs/affine-block-frame/index.d.ts +1 -0
- package/dist/_pkgs/affine-block-frame/index.js +1 -0
- package/dist/_pkgs/affine-block-frame/translations.d.ts +7 -0
- package/dist/_pkgs/affine-block-frame/translations.js +16 -1
- package/dist/_pkgs/affine-block-frame/view.js +6 -0
- package/dist/_pkgs/affine-block-image/asset-picker.d.ts +63 -0
- package/dist/_pkgs/affine-block-image/asset-picker.js +183 -0
- package/dist/_pkgs/affine-block-image/commands/insert-images.d.ts +5 -0
- package/dist/_pkgs/affine-block-image/commands/insert-images.js +8 -8
- package/dist/_pkgs/affine-block-image/components/page-image-block.d.ts +11 -0
- package/dist/_pkgs/affine-block-image/components/page-image-block.js +81 -12
- package/dist/_pkgs/affine-block-image/configs/replace-action.d.ts +9 -0
- package/dist/_pkgs/affine-block-image/configs/replace-action.js +27 -0
- package/dist/_pkgs/affine-block-image/configs/toolbar.js +6 -0
- package/dist/_pkgs/affine-block-image/crop/crop-controller.d.ts +46 -0
- package/dist/_pkgs/affine-block-image/crop/crop-controller.js +104 -0
- package/dist/_pkgs/affine-block-image/crop/crop-math.d.ts +70 -0
- package/dist/_pkgs/affine-block-image/crop/crop-math.js +141 -0
- package/dist/_pkgs/affine-block-image/crop/crop-overlay.d.ts +57 -0
- package/dist/_pkgs/affine-block-image/crop/crop-overlay.js +343 -0
- package/dist/_pkgs/affine-block-image/crop/crop-toolbar.d.ts +12 -0
- package/dist/_pkgs/affine-block-image/crop/crop-toolbar.js +78 -0
- package/dist/_pkgs/affine-block-image/crop/write-crop.d.ts +16 -0
- package/dist/_pkgs/affine-block-image/crop/write-crop.js +57 -0
- package/dist/_pkgs/affine-block-image/edgeless-clipboard-config.js +4 -1
- package/dist/_pkgs/affine-block-image/effects.js +2 -0
- package/dist/_pkgs/affine-block-image/image-block.d.ts +2 -0
- package/dist/_pkgs/affine-block-image/image-block.js +2 -0
- package/dist/_pkgs/affine-block-image/image-edgeless-block.d.ts +2 -0
- package/dist/_pkgs/affine-block-image/image-edgeless-block.js +36 -8
- package/dist/_pkgs/affine-block-image/image-resize-manager.js +15 -0
- package/dist/_pkgs/affine-block-image/index.d.ts +1 -0
- package/dist/_pkgs/affine-block-image/index.js +1 -0
- package/dist/_pkgs/affine-block-image/translations.d.ts +15 -0
- package/dist/_pkgs/affine-block-image/translations.js +43 -0
- package/dist/_pkgs/affine-block-image/utils.d.ts +13 -0
- package/dist/_pkgs/affine-block-image/utils.js +10 -1
- package/dist/_pkgs/affine-block-root/clipboard/page-clipboard.js +5 -0
- package/dist/_pkgs/affine-block-root/commands/page-export-commands.d.ts +2 -0
- package/dist/_pkgs/affine-block-root/commands/page-export-commands.js +71 -0
- package/dist/_pkgs/affine-block-root/index.d.ts +1 -0
- package/dist/_pkgs/affine-block-root/index.js +1 -0
- package/dist/_pkgs/affine-block-root/view.js +8 -0
- package/dist/_pkgs/affine-block-surface/extensions/drawio-export/capability.d.ts +30 -0
- package/dist/_pkgs/affine-block-surface/extensions/drawio-export/capability.js +44 -0
- package/dist/_pkgs/affine-block-surface/extensions/drawio-export/colors.d.ts +26 -0
- package/dist/_pkgs/affine-block-surface/extensions/drawio-export/colors.js +82 -0
- package/dist/_pkgs/affine-block-surface/extensions/drawio-export/command.d.ts +18 -0
- package/dist/_pkgs/affine-block-surface/extensions/drawio-export/command.js +91 -0
- package/dist/_pkgs/affine-block-surface/extensions/drawio-export/index.d.ts +3 -0
- package/dist/_pkgs/affine-block-surface/extensions/drawio-export/index.js +3 -0
- package/dist/_pkgs/affine-block-surface/extensions/drawio-export/writer.d.ts +50 -0
- package/dist/_pkgs/affine-block-surface/extensions/drawio-export/writer.js +732 -0
- package/dist/_pkgs/affine-block-surface/extensions/export-manager/draw-image-block.d.ts +12 -0
- package/dist/_pkgs/affine-block-surface/extensions/export-manager/draw-image-block.js +15 -0
- package/dist/_pkgs/affine-block-surface/extensions/export-manager/export-manager.js +7 -1
- package/dist/_pkgs/affine-block-surface/extensions/export-svg/command.d.ts +7 -1
- package/dist/_pkgs/affine-block-surface/extensions/export-svg/command.js +60 -1
- package/dist/_pkgs/affine-block-surface/extensions/export-svg/index.d.ts +2 -2
- package/dist/_pkgs/affine-block-surface/extensions/export-svg/index.js +2 -2
- package/dist/_pkgs/affine-block-surface/extensions/export-svg/marker-version.d.ts +6 -0
- package/dist/_pkgs/affine-block-surface/extensions/export-svg/marker-version.js +8 -0
- package/dist/_pkgs/affine-block-surface/extensions/export-svg/render.d.ts +28 -1
- package/dist/_pkgs/affine-block-surface/extensions/export-svg/render.js +66 -6
- package/dist/_pkgs/affine-block-surface/extensions/export-svg/svg-context.d.ts +2 -7
- package/dist/_pkgs/affine-block-surface/extensions/export-svg/svg-context.js +2 -6
- package/dist/_pkgs/affine-block-surface/extensions/index.d.ts +2 -0
- package/dist/_pkgs/affine-block-surface/extensions/index.js +2 -0
- package/dist/_pkgs/affine-block-surface/extensions/interchange-export.d.ts +84 -0
- package/dist/_pkgs/affine-block-surface/extensions/interchange-export.js +150 -0
- package/dist/_pkgs/affine-block-surface/extensions/interchange-import.js +24 -2
- package/dist/_pkgs/affine-block-surface/extensions/interchange.d.ts +23 -2
- package/dist/_pkgs/affine-block-surface/extensions/interchange.js +4 -1
- package/dist/_pkgs/affine-block-surface/extensions/legend-role.d.ts +18 -0
- package/dist/_pkgs/affine-block-surface/extensions/legend-role.js +20 -0
- package/dist/_pkgs/affine-block-surface/extensions/legend.d.ts +2 -19
- package/dist/_pkgs/affine-block-surface/extensions/legend.js +2 -18
- package/dist/_pkgs/affine-block-surface/extensions/svg-sanitize.d.ts +67 -0
- package/dist/_pkgs/affine-block-surface/extensions/svg-sanitize.js +235 -0
- package/dist/_pkgs/affine-block-surface/extensions/svg-sketch-translations.d.ts +1 -0
- package/dist/_pkgs/affine-block-surface/extensions/svg-sketch-translations.js +9 -0
- package/dist/_pkgs/affine-block-surface/extensions/svg-sketch.d.ts +17 -13
- package/dist/_pkgs/affine-block-surface/extensions/svg-sketch.js +52 -80
- package/dist/_pkgs/affine-block-surface/extensions/xml-element.d.ts +98 -0
- package/dist/_pkgs/affine-block-surface/extensions/xml-element.js +261 -0
- package/dist/_pkgs/affine-block-surface/extensions/xml-reader.d.ts +238 -0
- package/dist/_pkgs/affine-block-surface/extensions/xml-reader.js +570 -0
- package/dist/_pkgs/affine-block-surface/framework-background/def.js +1 -1
- package/dist/_pkgs/affine-block-surface/interchange-headless.d.ts +29 -0
- package/dist/_pkgs/affine-block-surface/interchange-headless.js +32 -0
- package/dist/_pkgs/affine-block-surface/view.js +22 -2
- package/dist/_pkgs/affine-block-table/adapters/utils.js +24 -1
- package/dist/_pkgs/affine-gfx-note/toolbar/note-menu.js +5 -8
- package/dist/_pkgs/affine-gfx-template/contribute.d.ts +14 -4
- package/dist/_pkgs/affine-gfx-template/contribute.js +47 -6
- package/dist/_pkgs/affine-gfx-template/toolbar/builtin-templates.d.ts +7 -2
- package/dist/_pkgs/affine-gfx-template/toolbar/builtin-templates.js +14 -40
- package/dist/_pkgs/affine-gfx-template/toolbar/resolve-name.d.ts +1 -1
- package/dist/_pkgs/affine-gfx-template/toolbar/resolve-name.js +1 -1
- package/dist/_pkgs/affine-gfx-template/toolbar/template-panel.d.ts +4 -4
- package/dist/_pkgs/affine-gfx-template/toolbar/template-panel.js +9 -9
- package/dist/_pkgs/affine-gfx-template/toolbar/template-type.d.ts +2 -4
- package/dist/_pkgs/affine-gfx-template/translations.d.ts +5 -0
- package/dist/_pkgs/affine-gfx-template/translations.js +9 -0
- package/dist/_pkgs/affine-inline-footnote/adapters/markdown/inline-delta.js +6 -0
- package/dist/_pkgs/affine-inline-footnote/adapters/markdown/markdown-inline.js +7 -0
- package/dist/_pkgs/affine-inline-link/adapters/html/html-inline.js +4 -1
- package/dist/_pkgs/affine-inline-link/adapters/html/inline-delta.js +3 -1
- package/dist/_pkgs/affine-inline-link/adapters/markdown/inline-delta.js +4 -1
- package/dist/_pkgs/affine-inline-link/adapters/notion-html/html-inline.js +2 -1
- package/dist/_pkgs/affine-inline-link/link-node/affine-link.d.ts +7 -0
- package/dist/_pkgs/affine-inline-link/link-node/affine-link.js +37 -0
- package/dist/_pkgs/affine-inline-link/link-node/index.d.ts +1 -0
- package/dist/_pkgs/affine-inline-link/link-node/index.js +1 -0
- package/dist/_pkgs/affine-inline-link/link-node/propose-views.d.ts +22 -0
- package/dist/_pkgs/affine-inline-link/link-node/propose-views.js +59 -0
- package/dist/_pkgs/affine-model/blocks/image/image-crop.d.ts +48 -0
- package/dist/_pkgs/affine-model/blocks/image/image-crop.js +78 -0
- package/dist/_pkgs/affine-model/blocks/image/image-model.d.ts +6 -0
- package/dist/_pkgs/affine-model/blocks/image/image-model.js +2 -0
- package/dist/_pkgs/affine-model/blocks/image/index.d.ts +1 -0
- package/dist/_pkgs/affine-model/blocks/image/index.js +1 -0
- package/dist/_pkgs/affine-model/consts/shape.d.ts +2 -0
- package/dist/_pkgs/affine-model/consts/shape.js +5 -0
- package/dist/_pkgs/affine-model/elements/bpmn/consts.d.ts +31 -0
- package/dist/_pkgs/affine-model/elements/bpmn/consts.js +31 -0
- package/dist/_pkgs/affine-model/elements/bpmn/index.d.ts +1 -0
- package/dist/_pkgs/affine-model/elements/bpmn/index.js +1 -0
- package/dist/_pkgs/affine-model/elements/bpmn/pool.d.ts +0 -25
- package/dist/_pkgs/affine-model/elements/bpmn/pool.js +1 -25
- package/dist/_pkgs/affine-model/elements/shape/shape.d.ts +0 -2
- package/dist/_pkgs/affine-model/elements/shape/shape.js +1 -2
- package/dist/_pkgs/affine-model/elements/uml/consts.d.ts +133 -0
- package/dist/_pkgs/affine-model/elements/uml/consts.js +107 -0
- package/dist/_pkgs/affine-model/elements/uml/diagram.d.ts +1 -79
- package/dist/_pkgs/affine-model/elements/uml/diagram.js +1 -53
- package/dist/_pkgs/affine-model/elements/uml/fragment.d.ts +0 -15
- package/dist/_pkgs/affine-model/elements/uml/fragment.js +1 -15
- package/dist/_pkgs/affine-model/elements/uml/index.d.ts +1 -0
- package/dist/_pkgs/affine-model/elements/uml/index.js +1 -0
- package/dist/_pkgs/affine-model/elements/uml/partition.d.ts +0 -20
- package/dist/_pkgs/affine-model/elements/uml/partition.js +1 -20
- package/dist/_pkgs/affine-model/elements/uml/region.d.ts +0 -11
- package/dist/_pkgs/affine-model/elements/uml/region.js +1 -11
- package/dist/_pkgs/affine-model/headless.d.ts +19 -0
- package/dist/_pkgs/affine-model/headless.js +19 -0
- package/dist/_pkgs/affine-shared/headless.d.ts +10 -0
- package/dist/_pkgs/affine-shared/headless.js +10 -0
- package/dist/_pkgs/affine-shared/services/asset-picker-service.d.ts +63 -0
- package/dist/_pkgs/affine-shared/services/asset-picker-service.js +20 -0
- package/dist/_pkgs/affine-shared/services/frame-template-service.d.ts +83 -0
- package/dist/_pkgs/affine-shared/services/frame-template-service.js +17 -0
- package/dist/_pkgs/affine-shared/services/index.d.ts +2 -0
- package/dist/_pkgs/affine-shared/services/index.js +2 -0
- package/dist/_pkgs/affine-shared/services/translation-service/chrome.d.ts +6 -0
- package/dist/_pkgs/affine-shared/services/translation-service/chrome.js +10 -0
- package/dist/_pkgs/affine-widget-drag-handle/watchers/drag-event-watcher.js +8 -3
- package/dist/_pkgs/affine-widget-keyboard-toolbar/config.js +4 -16
- package/dist/_pkgs/affine-widget-linked-doc/transformers/html.d.ts +7 -0
- package/dist/_pkgs/affine-widget-linked-doc/transformers/html.js +25 -24
- package/dist/_pkgs/affine-widget-linked-doc/transformers/index.d.ts +1 -1
- package/dist/_pkgs/affine-widget-linked-doc/transformers/markdown.d.ts +7 -0
- package/dist/_pkgs/affine-widget-linked-doc/transformers/markdown.js +26 -25
- package/dist/_pkgs/affine-widget-linked-doc/transformers/utils.d.ts +23 -0
- package/dist/_pkgs/affine-widget-linked-doc/transformers/utils.js +14 -0
- package/dist/commands.js +5 -2
- package/dist/host-panels.d.ts +21 -1
- package/dist/host-panels.js +50 -10
- package/dist/interchange.d.ts +1 -0
- package/dist/interchange.js +1 -0
- package/dist/model/headless.d.ts +1 -0
- package/dist/model/headless.js +1 -0
- package/dist/shared/headless.d.ts +1 -0
- package/dist/shared/headless.js +1 -0
- package/dist/translations.js +8 -1
- package/package.json +13 -1
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A tolerant XML READER — the inverse of UML's `xml.ts` writer, and the one
|
|
3
|
+
* thing an importer cannot do without. Read by the XMI and draw.io importers,
|
|
4
|
+
* by BPMN and by the SVG sketch (through `xml-element.ts`), all four servable
|
|
5
|
+
* from the editor-free `./interchange` entry.
|
|
6
|
+
*
|
|
7
|
+
* ## Why not `DOMParser`
|
|
8
|
+
*
|
|
9
|
+
* BPMN and the SVG sketch used to call it, and the P0 import spike measured
|
|
10
|
+
* the cost on a server: a DOM to install (jsdom, 6 MB, behind `vm`), and a
|
|
11
|
+
* BPMN read that grew quadratically on it. An interchange parser is a PURE function of a string (`docs/adr/0012` P3) — the
|
|
12
|
+
* same function an editor command, a unit test and labre-mcp all call — and
|
|
13
|
+
* `DOMParser` is a DOM global that exists in exactly one of those three. A
|
|
14
|
+
* reader that needs `happy-dom` to be loaded is a reader with an environment in
|
|
15
|
+
* its signature.
|
|
16
|
+
*
|
|
17
|
+
* So: two hundred lines of scanner, and no global in sight.
|
|
18
|
+
*
|
|
19
|
+
* ## Tolerant, and what that costs
|
|
20
|
+
*
|
|
21
|
+
* **It never throws.** A file that stops mid-element, a close tag that names
|
|
22
|
+
* the wrong element, an attribute with no quotes, an entity nobody declared —
|
|
23
|
+
* every one of them produces a tree with a NOTE beside it rather than an
|
|
24
|
+
* exception. That is not sloppiness, it is the job: the files this reader is
|
|
25
|
+
* handed were written by Papyrus, StarUML, Enterprise Architect and a dozen
|
|
26
|
+
* scripts, and a user who exported a model from one of them is entitled to get
|
|
27
|
+
* back everything it said even when part of it is malformed. The alternative —
|
|
28
|
+
* one exception for one stray `&` — imports nothing at all.
|
|
29
|
+
*
|
|
30
|
+
* What it does NOT do is pretend to be a conformant parser. There is no DTD, no
|
|
31
|
+
* entity declaration, no namespace RESOLUTION (prefixes are kept exactly as the
|
|
32
|
+
* file spelled them — see {@link XmlNode.prefix}), no attribute-value
|
|
33
|
+
* normalization beyond the character references XML 1.0 §3.3.3 makes
|
|
34
|
+
* mandatory. Every one of those is a feature an XMI file in the wild does not
|
|
35
|
+
* use, and each would be a piece of surface with nothing behind it.
|
|
36
|
+
*
|
|
37
|
+
* ## Verbatim means the source's own bytes
|
|
38
|
+
*
|
|
39
|
+
* Every node records the byte RANGE it was read from ({@link XmlNode.range}),
|
|
40
|
+
* and {@link xmlFragmentOf} hands back that slice of the original string. So a
|
|
41
|
+
* quarantined fragment (ADR 0012 D5) is the file's own text — its comments, its
|
|
42
|
+
* whitespace, its attribute order, its prefixes — and not this reader's opinion
|
|
43
|
+
* of it. {@link serializeXmlNode} re-serializes from the tree instead, and is
|
|
44
|
+
* the fallback for a node assembled rather than read.
|
|
45
|
+
*
|
|
46
|
+
* ## Bounded, because a server reads it too
|
|
47
|
+
*
|
|
48
|
+
* The one exception to "never throws": a document past {@link XML_MAX_NODES}
|
|
49
|
+
* nodes or {@link XML_MAX_CHARACTERS} characters is refused with an
|
|
50
|
+
* {@link InterchangeImportError} carrying a static key, at the node that
|
|
51
|
+
* crosses the line and not after the tree is built. Each node costs about two
|
|
52
|
+
* hundred bytes of heap, and a 1.5 KiB `.drawio` inflates to a million of
|
|
53
|
+
* them (the 2026-10-14 security review: 3.2 s and 223 MiB before the cap). The
|
|
54
|
+
* scan is linear in the source otherwise: an orphan close tag is answered from
|
|
55
|
+
* a count of open names, not by searching the stack.
|
|
56
|
+
*
|
|
57
|
+
* Pure: a string in, a tree out. No `std`, no DOM, no clock.
|
|
58
|
+
*/
|
|
59
|
+
import type { ChromeWording } from '../../affine-shared/services/index.js';
|
|
60
|
+
/**
|
|
61
|
+
* One element.
|
|
62
|
+
*
|
|
63
|
+
* `name` is the qualified name AS WRITTEN (`uml:Model`), with {@link prefix}
|
|
64
|
+
* and {@link local} split out beside it, because an importer asks both
|
|
65
|
+
* questions: the prefix is how a file says which vocabulary it means, and the
|
|
66
|
+
* local name is the only half two tools reliably agree on — Papyrus writes
|
|
67
|
+
* `uml:Class`, an older Enterprise Architect writes `UML:Class`, and a
|
|
68
|
+
* namespace-defaulted file writes `Class`.
|
|
69
|
+
*/
|
|
70
|
+
export interface XmlNode {
|
|
71
|
+
/** The qualified name, verbatim: `uml:Model`, `packagedElement`. */
|
|
72
|
+
name: string;
|
|
73
|
+
/** The prefix, `''` when the name carries none. */
|
|
74
|
+
prefix: string;
|
|
75
|
+
/** The local name — `Model`, `packagedElement`. */
|
|
76
|
+
local: string;
|
|
77
|
+
/** Attributes by qualified name, values entity-decoded, in document order. */
|
|
78
|
+
attrs: Record<string, string>;
|
|
79
|
+
children: XmlNode[];
|
|
80
|
+
/**
|
|
81
|
+
* The element's character data — text and CDATA, concatenated and decoded.
|
|
82
|
+
*
|
|
83
|
+
* Absent rather than `''` when the element holds nothing but whitespace and
|
|
84
|
+
* children, which is what every element of an indented XMI document holds.
|
|
85
|
+
* A `<body>` with prose in it has this; a `<packagedElement>` does not.
|
|
86
|
+
*/
|
|
87
|
+
text?: string;
|
|
88
|
+
/**
|
|
89
|
+
* `[start, end)` in the SOURCE string — what {@link xmlFragmentOf} slices.
|
|
90
|
+
*
|
|
91
|
+
* `end` is the offset just past this element's close tag (or past `/>`). For
|
|
92
|
+
* an element the file never closed it is the end of what was read, which is
|
|
93
|
+
* the honest answer and keeps the slice well-formed enough to re-parse.
|
|
94
|
+
*/
|
|
95
|
+
range: [number, number];
|
|
96
|
+
/**
|
|
97
|
+
* Everything inside the element IN DOCUMENT ORDER: child elements, character
|
|
98
|
+
* data (text and CDATA, decoded, whitespace included), comments and
|
|
99
|
+
* processing instructions. {@link text} and {@link children} are the two
|
|
100
|
+
* convenient projections of it; this is what a reader needs when order or
|
|
101
|
+
* markup that is not an element matters (`<text>a<tspan>b</tspan>c</text>`,
|
|
102
|
+
* a vendor comment carried back verbatim). Always present on a node
|
|
103
|
+
* {@link readXml} produced; absent on one a caller assembled.
|
|
104
|
+
*/
|
|
105
|
+
content?: XmlContent[];
|
|
106
|
+
}
|
|
107
|
+
/** One entry of {@link XmlNode.content}. */
|
|
108
|
+
export type XmlContent = XmlNode
|
|
109
|
+
/** Text and CDATA are one kind: a consumer escapes both the same way. */
|
|
110
|
+
| {
|
|
111
|
+
kind: 'text';
|
|
112
|
+
value: string;
|
|
113
|
+
} | {
|
|
114
|
+
kind: 'comment';
|
|
115
|
+
value: string;
|
|
116
|
+
} | {
|
|
117
|
+
kind: 'pi';
|
|
118
|
+
/** The target, `xml-stylesheet` in `<?xml-stylesheet href="…"?>`. */
|
|
119
|
+
target: string;
|
|
120
|
+
/** The rest, leading whitespace dropped, as the DOM's `data` has it. */
|
|
121
|
+
data: string;
|
|
122
|
+
};
|
|
123
|
+
/** How strictly {@link readXml} reads. */
|
|
124
|
+
export interface XmlReadOptions {
|
|
125
|
+
/**
|
|
126
|
+
* Two XML 1.0 rules the tolerant default leaves out, for a caller that used
|
|
127
|
+
* to read with `DOMParser` and must keep its answers (BPMN, the SVG sketch):
|
|
128
|
+
* attribute values are whitespace-normalized as §3.3.3 makes mandatory (a
|
|
129
|
+
* literal tab or newline reads as a space, a character reference keeps its
|
|
130
|
+
* character), and a second top-level element is a note. Off by default, so
|
|
131
|
+
* the XMI and draw.io readers keep reading exactly what they read before.
|
|
132
|
+
*/
|
|
133
|
+
conformant?: boolean;
|
|
134
|
+
/**
|
|
135
|
+
* Elements, attributes, character runs, comments, instructions and notes,
|
|
136
|
+
* counted together. Default {@link XML_MAX_NODES}.
|
|
137
|
+
*/
|
|
138
|
+
maxNodes?: number;
|
|
139
|
+
/**
|
|
140
|
+
* Characters of decoded text, attribute values, comments and instructions.
|
|
141
|
+
* Default {@link XML_MAX_CHARACTERS}.
|
|
142
|
+
*/
|
|
143
|
+
maxCharacters?: number;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Safe for a function with 256 MiB and two seconds: the largest file of the
|
|
147
|
+
* corpus holds a few thousand nodes, a reading at the cap about 40 MiB.
|
|
148
|
+
*/
|
|
149
|
+
export declare const XML_MAX_NODES = 200000;
|
|
150
|
+
/** Notes written in full; the rest are counted in one last note. */
|
|
151
|
+
export declare const XML_MAX_NOTES = 100;
|
|
152
|
+
/** 2 MiB of decoded characters, well past any drawing the canvas can show. */
|
|
153
|
+
export declare const XML_MAX_CHARACTERS: number;
|
|
154
|
+
/** The reader's one refusal; static, so a server can hand the key on. */
|
|
155
|
+
export declare const XML_READ_TOO_LARGE: ChromeWording;
|
|
156
|
+
/** A document, and everything the reader had to complain about to read it. */
|
|
157
|
+
export interface XmlDocument {
|
|
158
|
+
/** The first top-level element, or `undefined` for a document with none. */
|
|
159
|
+
root?: XmlNode;
|
|
160
|
+
/**
|
|
161
|
+
* Every top-level element, in order.
|
|
162
|
+
*
|
|
163
|
+
* A well-formed document has exactly one. A file that has been concatenated,
|
|
164
|
+
* truncated or hand-edited has none or several, and the reader says what it
|
|
165
|
+
* found rather than deciding which one was meant.
|
|
166
|
+
*/
|
|
167
|
+
roots: XmlNode[];
|
|
168
|
+
/** One line each, in the user's words — see the header on tolerance. */
|
|
169
|
+
notes: string[];
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Character data as its characters — the five named entities and any numeric
|
|
173
|
+
* reference.
|
|
174
|
+
*
|
|
175
|
+
* An entity this reader does not know (` `, a DTD-declared one) is left
|
|
176
|
+
* EXACTLY as it was written, unresolved and unannounced. Two reasons, and the
|
|
177
|
+
* second is the one that matters: resolving it would need the DTD the file
|
|
178
|
+
* does not ship, and dropping it would lose a character; leaving the reference
|
|
179
|
+
* standing means a later re-serialization writes back what the file said, which
|
|
180
|
+
* is the promise `xmlFragmentOf` makes and this keeps true for text as well.
|
|
181
|
+
*/
|
|
182
|
+
export declare function decodeXmlText(value: string): string;
|
|
183
|
+
/**
|
|
184
|
+
* Read a document. Throws only past its size caps; see the header.
|
|
185
|
+
*
|
|
186
|
+
* The scan is a single left-to-right pass with an explicit stack, which is what
|
|
187
|
+
* makes the tolerance cheap: every recovery is "say what is wrong, and carry on
|
|
188
|
+
* from the next `<`", and there is no recursion to unwind. In conformant mode
|
|
189
|
+
* the first note STOPS the read: its callers refuse on any note, and a file
|
|
190
|
+
* built to raise twenty thousand of them must not get to.
|
|
191
|
+
*/
|
|
192
|
+
export declare function readXml(source: string, options?: XmlReadOptions): XmlDocument;
|
|
193
|
+
/**
|
|
194
|
+
* The element's own bytes, from the string it was read from.
|
|
195
|
+
*
|
|
196
|
+
* This is what a quarantined fragment is (ADR 0012 D5): the file's text, not a
|
|
197
|
+
* re-rendering of this reader's tree. Comments, attribute order, prefixes and
|
|
198
|
+
* whitespace all survive, because none of them was ever taken apart.
|
|
199
|
+
*/
|
|
200
|
+
export declare function xmlFragmentOf(source: string, node: XmlNode): string;
|
|
201
|
+
/**
|
|
202
|
+
* A node back as XML, from the TREE rather than from the source.
|
|
203
|
+
*
|
|
204
|
+
* The fallback for a fragment that has no range to slice — one assembled by a
|
|
205
|
+
* caller, or read out of a document this function's caller no longer holds. It
|
|
206
|
+
* is faithful to what the tree records and therefore drops what the tree does
|
|
207
|
+
* not: comments, processing instructions, and the file's own indentation.
|
|
208
|
+
* Prefer {@link xmlFragmentOf} whenever the source string is still in hand.
|
|
209
|
+
*/
|
|
210
|
+
export declare function serializeXmlNode(node: XmlNode): string;
|
|
211
|
+
/** Children with this local name, whatever prefix the file gave them. */
|
|
212
|
+
export declare function xmlChildren(node: XmlNode, local: string): XmlNode[];
|
|
213
|
+
/** The first child with this local name, if any. */
|
|
214
|
+
export declare function xmlChild(node: XmlNode, local: string): XmlNode | undefined;
|
|
215
|
+
/**
|
|
216
|
+
* An attribute by LOCAL name — `xmi:id`, `xmi:ID` and a bare `id` all answer.
|
|
217
|
+
*
|
|
218
|
+
* Prefix-insensitive on purpose, and it is the difference between reading three
|
|
219
|
+
* tools and reading one: the XMI prefix is `xmi` by convention and by nothing
|
|
220
|
+
* else, Enterprise Architect has shipped files under `XMI`, and an
|
|
221
|
+
* attribute-defaulted file drops it altogether. The QUALIFIED name is still in
|
|
222
|
+
* `attrs` for anything that needs it, and {@link xmlFragmentOf} still writes
|
|
223
|
+
* back what the file said.
|
|
224
|
+
*
|
|
225
|
+
* The first match in document order wins, which only matters for a file that
|
|
226
|
+
* spells the same attribute twice under two prefixes.
|
|
227
|
+
*/
|
|
228
|
+
export declare function xmlAttr(node: XmlNode, local: string): string | undefined;
|
|
229
|
+
/** Every `xmlns` / `xmlns:*` declaration on this element, by prefix (`''`). */
|
|
230
|
+
export declare function xmlNamespaces(node: XmlNode): Record<string, string>;
|
|
231
|
+
/**
|
|
232
|
+
* Every element under `node`, at any depth, in document order.
|
|
233
|
+
*
|
|
234
|
+
* An explicit stack rather than recursion: the depth of a file is whatever its
|
|
235
|
+
* author chose, and a hostile one nested a hundred thousand deep must cost a
|
|
236
|
+
* loop, not the call stack.
|
|
237
|
+
*/
|
|
238
|
+
export declare function xmlDescendants(node: XmlNode): XmlNode[];
|