web-doc 0.6.2 → 0.7.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/THIRD_PARTY_NOTICES.md +26 -1
- package/dist/adapters/docx-images.d.ts +13 -4
- package/dist/adapters/docx-images.js +3 -0
- package/dist/adapters/docx-paragraphs.d.ts +65 -0
- package/dist/adapters/docx-paragraphs.js +165 -0
- package/dist/adapters/docx-prepass.d.ts +17 -0
- package/dist/adapters/docx-prepass.js +230 -0
- package/dist/adapters/office.d.ts +31 -5
- package/dist/adapters/office.js +60 -29
- package/dist/adapters/pdf.d.ts +9 -0
- package/dist/adapters/pdf.js +10 -0
- package/dist/assets/pdfium/pdfium.wasm +0 -0
- package/dist/contracts.d.ts +47 -2
- package/dist/edit/assets.d.ts +23 -0
- package/dist/edit/assets.js +75 -0
- package/dist/edit/docx/elements.d.ts +6 -0
- package/dist/edit/docx/elements.js +90 -0
- package/dist/edit/docx/engine.d.ts +51 -0
- package/dist/edit/docx/engine.js +473 -0
- package/dist/edit/docx/handlers.d.ts +3 -0
- package/dist/edit/docx/handlers.js +15 -0
- package/dist/edit/docx/ids.d.ts +45 -0
- package/dist/edit/docx/ids.js +101 -0
- package/dist/edit/docx/model.d.ts +92 -0
- package/dist/edit/docx/model.js +339 -0
- package/dist/edit/docx/operations.d.ts +37 -0
- package/dist/edit/docx/operations.js +3 -0
- package/dist/edit/docx/provider.d.ts +13 -0
- package/dist/edit/docx/provider.js +34 -0
- package/dist/edit/docx/schemas.d.ts +6 -0
- package/dist/edit/docx/schemas.js +192 -0
- package/dist/edit/docx/session.d.ts +37 -0
- package/dist/edit/docx/session.js +426 -0
- package/dist/edit/docx/structure-ops.d.ts +6 -0
- package/dist/edit/docx/structure-ops.js +494 -0
- package/dist/edit/docx/style.d.ts +45 -0
- package/dist/edit/docx/style.js +375 -0
- package/dist/edit/docx/table-ops.d.ts +4 -0
- package/dist/edit/docx/table-ops.js +219 -0
- package/dist/edit/docx/text-ops.d.ts +18 -0
- package/dist/edit/docx/text-ops.js +458 -0
- package/dist/edit/docx/text.d.ts +34 -0
- package/dist/edit/docx/text.js +263 -0
- package/dist/edit/docx/types.d.ts +191 -0
- package/dist/edit/docx/types.js +1 -0
- package/dist/edit/docx/write.d.ts +50 -0
- package/dist/edit/docx/write.js +352 -0
- package/dist/edit/engine.d.ts +117 -0
- package/dist/edit/engine.js +1 -0
- package/dist/edit/history.d.ts +53 -0
- package/dist/edit/history.js +101 -0
- package/dist/edit/ooxml/names.d.ts +20 -0
- package/dist/edit/ooxml/names.js +61 -0
- package/dist/edit/ooxml/opc.d.ts +50 -0
- package/dist/edit/ooxml/opc.js +150 -0
- package/dist/edit/ooxml/package.d.ts +82 -0
- package/dist/edit/ooxml/package.js +233 -0
- package/dist/edit/ooxml/patch.d.ts +51 -0
- package/dist/edit/ooxml/patch.js +250 -0
- package/dist/edit/ooxml/transaction.d.ts +39 -0
- package/dist/edit/ooxml/transaction.js +316 -0
- package/dist/edit/ooxml/worker.d.ts +8 -0
- package/dist/edit/ooxml/worker.js +12 -0
- package/dist/edit/ooxml/writer.d.ts +21 -0
- package/dist/edit/ooxml/writer.js +187 -0
- package/dist/edit/ooxml/xml.d.ts +74 -0
- package/dist/edit/ooxml/xml.js +451 -0
- package/dist/edit/ooxml/zip.d.ts +54 -0
- package/dist/edit/ooxml/zip.js +280 -0
- package/dist/edit/operations.d.ts +19 -0
- package/dist/edit/operations.js +137 -0
- package/dist/edit/pdf/engine/compact.d.ts +6 -0
- package/dist/edit/pdf/engine/compact.js +442 -0
- package/dist/edit/pdf/engine/document.d.ts +95 -0
- package/dist/edit/pdf/engine/document.js +868 -0
- package/dist/edit/pdf/engine/elements.d.ts +45 -0
- package/dist/edit/pdf/engine/elements.js +313 -0
- package/dist/edit/pdf/engine/existing-text.d.ts +4 -0
- package/dist/edit/pdf/engine/existing-text.js +424 -0
- package/dist/edit/pdf/engine/fonts.d.ts +78 -0
- package/dist/edit/pdf/engine/fonts.js +466 -0
- package/dist/edit/pdf/engine/geometry.d.ts +36 -0
- package/dist/edit/pdf/engine/geometry.js +97 -0
- package/dist/edit/pdf/engine/handler.d.ts +21 -0
- package/dist/edit/pdf/engine/handler.js +108 -0
- package/dist/edit/pdf/engine/images.d.ts +33 -0
- package/dist/edit/pdf/engine/images.js +188 -0
- package/dist/edit/pdf/engine/layout.d.ts +23 -0
- package/dist/edit/pdf/engine/layout.js +177 -0
- package/dist/edit/pdf/engine/operations.d.ts +67 -0
- package/dist/edit/pdf/engine/operations.js +3 -0
- package/dist/edit/pdf/engine/pages.d.ts +6 -0
- package/dist/edit/pdf/engine/pages.js +98 -0
- package/dist/edit/pdf/engine/pdfium.d.ts +195 -0
- package/dist/edit/pdf/engine/pdfium.js +249 -0
- package/dist/edit/pdf/engine/shapes.d.ts +4 -0
- package/dist/edit/pdf/engine/shapes.js +183 -0
- package/dist/edit/pdf/engine/tables.d.ts +44 -0
- package/dist/edit/pdf/engine/tables.js +315 -0
- package/dist/edit/pdf/engine/text-box.d.ts +71 -0
- package/dist/edit/pdf/engine/text-box.js +317 -0
- package/dist/edit/pdf/engine/text-layout.d.ts +28 -0
- package/dist/edit/pdf/engine/text-layout.js +67 -0
- package/dist/edit/pdf/engine/transform.d.ts +5 -0
- package/dist/edit/pdf/engine/transform.js +137 -0
- package/dist/edit/pdf/provider.d.ts +35 -0
- package/dist/edit/pdf/provider.js +92 -0
- package/dist/edit/pdf/range-map.d.ts +14 -0
- package/dist/edit/pdf/range-map.js +107 -0
- package/dist/edit/pdf/schemas.d.ts +11 -0
- package/dist/edit/pdf/schemas.js +291 -0
- package/dist/edit/pdf/selection.d.ts +5 -0
- package/dist/edit/pdf/selection.js +152 -0
- package/dist/edit/pdf/session.d.ts +53 -0
- package/dist/edit/pdf/session.js +273 -0
- package/dist/edit/pdf/types.d.ts +336 -0
- package/dist/edit/pdf/types.js +1 -0
- package/dist/edit/pptx/elements.d.ts +74 -0
- package/dist/edit/pptx/elements.js +301 -0
- package/dist/edit/pptx/engine.d.ts +37 -0
- package/dist/edit/pptx/engine.js +466 -0
- package/dist/edit/pptx/geometry.d.ts +72 -0
- package/dist/edit/pptx/geometry.js +193 -0
- package/dist/edit/pptx/handler.d.ts +7 -0
- package/dist/edit/pptx/handler.js +91 -0
- package/dist/edit/pptx/handlers.d.ts +3 -0
- package/dist/edit/pptx/handlers.js +21 -0
- package/dist/edit/pptx/image-table-ops.d.ts +5 -0
- package/dist/edit/pptx/image-table-ops.js +233 -0
- package/dist/edit/pptx/model.d.ts +69 -0
- package/dist/edit/pptx/model.js +170 -0
- package/dist/edit/pptx/operations.d.ts +50 -0
- package/dist/edit/pptx/operations.js +11 -0
- package/dist/edit/pptx/provider.d.ts +17 -0
- package/dist/edit/pptx/provider.js +40 -0
- package/dist/edit/pptx/schemas.d.ts +6 -0
- package/dist/edit/pptx/schemas.js +220 -0
- package/dist/edit/pptx/session.d.ts +44 -0
- package/dist/edit/pptx/session.js +114 -0
- package/dist/edit/pptx/shape-ops.d.ts +10 -0
- package/dist/edit/pptx/shape-ops.js +486 -0
- package/dist/edit/pptx/slide-ops.d.ts +6 -0
- package/dist/edit/pptx/slide-ops.js +353 -0
- package/dist/edit/pptx/style.d.ts +31 -0
- package/dist/edit/pptx/style.js +181 -0
- package/dist/edit/pptx/text-ops.d.ts +13 -0
- package/dist/edit/pptx/text-ops.js +267 -0
- package/dist/edit/pptx/text-write.d.ts +67 -0
- package/dist/edit/pptx/text-write.js +293 -0
- package/dist/edit/pptx/text.d.ts +41 -0
- package/dist/edit/pptx/text.js +99 -0
- package/dist/edit/pptx/types.d.ts +232 -0
- package/dist/edit/pptx/types.js +1 -0
- package/dist/edit/schema.d.ts +11 -0
- package/dist/edit/schema.js +275 -0
- package/dist/edit/session.d.ts +66 -0
- package/dist/edit/session.js +701 -0
- package/dist/edit/sessions.d.ts +8 -0
- package/dist/edit/sessions.js +1 -0
- package/dist/edit/types.d.ts +276 -0
- package/dist/edit/types.js +1 -0
- package/dist/edit/worker-engine.d.ts +31 -0
- package/dist/edit/worker-engine.js +91 -0
- package/dist/fonts/THIRD_PARTY_NOTICES.md +3 -0
- package/dist/fonts/manifest.json +6 -1
- package/dist/fonts/noto-sans-latin-cyrillic.ttf +0 -0
- package/dist/fonts.d.ts +2 -0
- package/dist/fonts.js +4 -0
- package/dist/headless.d.ts +4 -0
- package/dist/headless.js +4 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +5 -0
- package/dist/limits.js +3 -0
- package/dist/ooxml-edit-worker.d.ts +1 -0
- package/dist/ooxml-edit-worker.js +8 -0
- package/dist/pdf-edit-worker.d.ts +1 -0
- package/dist/pdf-edit-worker.js +35 -0
- package/dist/spreadsheet-viewport.d.ts +5 -0
- package/dist/spreadsheet-viewport.js +11 -0
- package/dist/ui.js +7 -0
- package/dist/viewer.d.ts +6 -0
- package/dist/viewer.js +293 -19
- package/dist/viewport.d.ts +13 -0
- package/dist/viewport.js +126 -1
- package/dist/worker-protocol.d.ts +39 -2
- package/dist/workers/ooxml-edit-worker.js +8671 -0
- package/dist/workers/pdf-edit-worker.js +10844 -0
- package/package.json +3 -3
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import { ViewerError } from "../../errors.js";
|
|
2
|
+
import { entryNameOf, partKey } from "./names.js";
|
|
3
|
+
import { crc32, localRecordOf, METHOD_DEFLATED, METHOD_STORED, } from "./zip.js";
|
|
4
|
+
const SIGNATURE_LOCAL = 0x04034b50;
|
|
5
|
+
const SIGNATURE_CENTRAL = 0x02014b50;
|
|
6
|
+
const SIGNATURE_EOCD = 0x06054b50;
|
|
7
|
+
const VERSION_NEEDED = 20;
|
|
8
|
+
const VERSION_MADE_BY = 0x0314; // UNIX, 2.0
|
|
9
|
+
/** 1980-01-01 00:00 in MS-DOS time and date. */
|
|
10
|
+
const FIXED_TIME = 0;
|
|
11
|
+
const FIXED_DATE = 0x0021;
|
|
12
|
+
const MAX_32 = 0xffffffff;
|
|
13
|
+
const MAX_ENTRIES = 0xffff;
|
|
14
|
+
const encoder = new TextEncoder();
|
|
15
|
+
/** The package bytes for the archive with the overlay applied. */
|
|
16
|
+
export async function writeZip(archive, overlay, options = {}) {
|
|
17
|
+
const compression = options.compression ?? "store";
|
|
18
|
+
const changed = keyed(overlay.changed);
|
|
19
|
+
const added = keyed(overlay.added);
|
|
20
|
+
const removed = new Set([...overlay.removed].map(partKey));
|
|
21
|
+
const locals = [];
|
|
22
|
+
const centrals = [];
|
|
23
|
+
let offset = 0;
|
|
24
|
+
const seen = new Set();
|
|
25
|
+
for (const entry of archive.entries) {
|
|
26
|
+
throwIfAborted(options.signal);
|
|
27
|
+
const key = partKey(entry.name);
|
|
28
|
+
seen.add(key);
|
|
29
|
+
if (removed.has(key))
|
|
30
|
+
continue;
|
|
31
|
+
const change = changed.get(key);
|
|
32
|
+
if (change) {
|
|
33
|
+
const written = await fresh(entry.name, change.bytes, compression, entry);
|
|
34
|
+
locals.push([written.local, written.data]);
|
|
35
|
+
centrals.push(written.central(offset));
|
|
36
|
+
offset += written.local.byteLength + written.data.byteLength;
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
const local = localRecordOf(archive, entry);
|
|
40
|
+
const record = archive.bytes.subarray(local.headerOffset, local.recordEnd);
|
|
41
|
+
locals.push([record]);
|
|
42
|
+
centrals.push(centralWithOffset(archive, entry, offset));
|
|
43
|
+
offset += record.byteLength;
|
|
44
|
+
}
|
|
45
|
+
for (const [key, change] of added) {
|
|
46
|
+
if (seen.has(key) && !removed.has(key))
|
|
47
|
+
throw new ViewerError("invalid-file", `Part ${key} is added but exists`);
|
|
48
|
+
throwIfAborted(options.signal);
|
|
49
|
+
const name = entryNameOf(change.name);
|
|
50
|
+
const written = await fresh(name, change.bytes, compression);
|
|
51
|
+
locals.push([written.local, written.data]);
|
|
52
|
+
centrals.push(written.central(offset));
|
|
53
|
+
offset += written.local.byteLength + written.data.byteLength;
|
|
54
|
+
}
|
|
55
|
+
if (centrals.length > MAX_ENTRIES)
|
|
56
|
+
throw new ViewerError("unsupported-package", "The package would need ZIP64: more than 65,535 entries");
|
|
57
|
+
const centralOffset = offset;
|
|
58
|
+
let centralLength = 0;
|
|
59
|
+
for (const central of centrals)
|
|
60
|
+
centralLength += central.byteLength;
|
|
61
|
+
if (centralOffset + centralLength > MAX_32)
|
|
62
|
+
throw new ViewerError("unsupported-package", "The package would need ZIP64: it exceeds 4 GiB");
|
|
63
|
+
const eocd = new Uint8Array(22 + archive.comment.byteLength);
|
|
64
|
+
const view = new DataView(eocd.buffer);
|
|
65
|
+
view.setUint32(0, SIGNATURE_EOCD, true);
|
|
66
|
+
view.setUint16(4, 0, true);
|
|
67
|
+
view.setUint16(6, 0, true);
|
|
68
|
+
view.setUint16(8, centrals.length, true);
|
|
69
|
+
view.setUint16(10, centrals.length, true);
|
|
70
|
+
view.setUint32(12, centralLength, true);
|
|
71
|
+
view.setUint32(16, centralOffset, true);
|
|
72
|
+
view.setUint16(20, archive.comment.byteLength, true);
|
|
73
|
+
eocd.set(archive.comment, 22);
|
|
74
|
+
const out = new Uint8Array(centralOffset + centralLength + eocd.byteLength);
|
|
75
|
+
let at = 0;
|
|
76
|
+
for (const parts of locals)
|
|
77
|
+
for (const part of parts) {
|
|
78
|
+
out.set(part, at);
|
|
79
|
+
at += part.byteLength;
|
|
80
|
+
}
|
|
81
|
+
for (const central of centrals) {
|
|
82
|
+
out.set(central, at);
|
|
83
|
+
at += central.byteLength;
|
|
84
|
+
}
|
|
85
|
+
out.set(eocd, at);
|
|
86
|
+
return out;
|
|
87
|
+
}
|
|
88
|
+
function keyed(parts) {
|
|
89
|
+
const map = new Map();
|
|
90
|
+
for (const change of parts.values())
|
|
91
|
+
map.set(partKey(change.name), change);
|
|
92
|
+
return map;
|
|
93
|
+
}
|
|
94
|
+
/** The central record of an untouched entry with the new local-header offset. */
|
|
95
|
+
function centralWithOffset(archive, entry, localHeaderOffset) {
|
|
96
|
+
const record = archive.bytes.slice(entry.centralOffset, entry.centralOffset + entry.centralLength);
|
|
97
|
+
new DataView(record.buffer).setUint32(42, localHeaderOffset, true);
|
|
98
|
+
return record;
|
|
99
|
+
}
|
|
100
|
+
/** Fresh local and central records around stored or deflated data. */
|
|
101
|
+
async function fresh(name, bytes, compression, previous) {
|
|
102
|
+
if (bytes.byteLength > MAX_32)
|
|
103
|
+
throw new ViewerError("unsupported-package", `Part ${name} would need ZIP64: it exceeds 4 GiB`);
|
|
104
|
+
const nameBytes = previous?.nameBytes ?? encoder.encode(name);
|
|
105
|
+
const extra = previous?.extra ?? new Uint8Array(0);
|
|
106
|
+
const comment = previous?.comment ?? new Uint8Array(0);
|
|
107
|
+
const method = compression === "deflate" ? METHOD_DEFLATED : METHOD_STORED;
|
|
108
|
+
const data = method === METHOD_DEFLATED ? await deflateRaw(bytes) : bytes;
|
|
109
|
+
const crc = crc32(bytes);
|
|
110
|
+
const modTime = previous?.modTime ?? FIXED_TIME;
|
|
111
|
+
const modDate = previous?.modDate ?? FIXED_DATE;
|
|
112
|
+
const local = new Uint8Array(30 + nameBytes.byteLength + extra.byteLength);
|
|
113
|
+
const localView = new DataView(local.buffer);
|
|
114
|
+
localView.setUint32(0, SIGNATURE_LOCAL, true);
|
|
115
|
+
localView.setUint16(4, VERSION_NEEDED, true);
|
|
116
|
+
localView.setUint16(6, 0, true);
|
|
117
|
+
localView.setUint16(8, method, true);
|
|
118
|
+
localView.setUint16(10, modTime, true);
|
|
119
|
+
localView.setUint16(12, modDate, true);
|
|
120
|
+
localView.setUint32(14, crc, true);
|
|
121
|
+
localView.setUint32(18, data.byteLength, true);
|
|
122
|
+
localView.setUint32(22, bytes.byteLength, true);
|
|
123
|
+
localView.setUint16(26, nameBytes.byteLength, true);
|
|
124
|
+
localView.setUint16(28, extra.byteLength, true);
|
|
125
|
+
local.set(nameBytes, 30);
|
|
126
|
+
local.set(extra, 30 + nameBytes.byteLength);
|
|
127
|
+
return {
|
|
128
|
+
local,
|
|
129
|
+
data,
|
|
130
|
+
central(localHeaderOffset) {
|
|
131
|
+
const central = new Uint8Array(46 + nameBytes.byteLength + extra.byteLength + comment.byteLength);
|
|
132
|
+
const view = new DataView(central.buffer);
|
|
133
|
+
view.setUint32(0, SIGNATURE_CENTRAL, true);
|
|
134
|
+
view.setUint16(4, previous?.versionMadeBy ?? VERSION_MADE_BY, true);
|
|
135
|
+
view.setUint16(6, VERSION_NEEDED, true);
|
|
136
|
+
view.setUint16(8, 0, true);
|
|
137
|
+
view.setUint16(10, method, true);
|
|
138
|
+
view.setUint16(12, modTime, true);
|
|
139
|
+
view.setUint16(14, modDate, true);
|
|
140
|
+
view.setUint32(16, crc, true);
|
|
141
|
+
view.setUint32(20, data.byteLength, true);
|
|
142
|
+
view.setUint32(24, bytes.byteLength, true);
|
|
143
|
+
view.setUint16(28, nameBytes.byteLength, true);
|
|
144
|
+
view.setUint16(30, extra.byteLength, true);
|
|
145
|
+
view.setUint16(32, comment.byteLength, true);
|
|
146
|
+
view.setUint16(34, 0, true);
|
|
147
|
+
view.setUint16(36, previous?.internalAttributes ?? 0, true);
|
|
148
|
+
view.setUint32(38, previous?.externalAttributes ?? 0, true);
|
|
149
|
+
view.setUint32(42, localHeaderOffset, true);
|
|
150
|
+
central.set(nameBytes, 46);
|
|
151
|
+
central.set(extra, 46 + nameBytes.byteLength);
|
|
152
|
+
central.set(comment, 46 + nameBytes.byteLength + extra.byteLength);
|
|
153
|
+
return central;
|
|
154
|
+
},
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
async function deflateRaw(bytes) {
|
|
158
|
+
if (typeof CompressionStream !== "function")
|
|
159
|
+
throw new ViewerError("edit-unsupported", 'This environment has no CompressionStream; save with compression: "store"', { details: { reason: "no-compression-stream" } });
|
|
160
|
+
const stream = new CompressionStream("deflate-raw");
|
|
161
|
+
const writer = stream.writable.getWriter();
|
|
162
|
+
const writing = writer
|
|
163
|
+
.write(bytes.slice())
|
|
164
|
+
.then(() => writer.close());
|
|
165
|
+
const chunks = [];
|
|
166
|
+
let total = 0;
|
|
167
|
+
const reader = stream.readable.getReader();
|
|
168
|
+
for (;;) {
|
|
169
|
+
const chunk = await reader.read();
|
|
170
|
+
if (chunk.done)
|
|
171
|
+
break;
|
|
172
|
+
chunks.push(chunk.value);
|
|
173
|
+
total += chunk.value.byteLength;
|
|
174
|
+
}
|
|
175
|
+
await writing;
|
|
176
|
+
const out = new Uint8Array(total);
|
|
177
|
+
let at = 0;
|
|
178
|
+
for (const chunk of chunks) {
|
|
179
|
+
out.set(chunk, at);
|
|
180
|
+
at += chunk.byteLength;
|
|
181
|
+
}
|
|
182
|
+
return out;
|
|
183
|
+
}
|
|
184
|
+
function throwIfAborted(signal) {
|
|
185
|
+
if (signal?.aborted)
|
|
186
|
+
throw new ViewerError("aborted", "Writing the package was aborted");
|
|
187
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
export interface XmlRange {
|
|
2
|
+
readonly kind: "declaration" | "comment" | "pi" | "cdata" | "doctype";
|
|
3
|
+
readonly start: number;
|
|
4
|
+
readonly end: number;
|
|
5
|
+
}
|
|
6
|
+
export interface XmlAttribute {
|
|
7
|
+
/** Qualified, as written. */
|
|
8
|
+
readonly name: string;
|
|
9
|
+
/** Entities decoded. */
|
|
10
|
+
readonly value: string;
|
|
11
|
+
/** As written, without the quotes. */
|
|
12
|
+
readonly rawValue: string;
|
|
13
|
+
/** Of the attribute name. */
|
|
14
|
+
readonly start: number;
|
|
15
|
+
/** After the closing quote. */
|
|
16
|
+
readonly end: number;
|
|
17
|
+
}
|
|
18
|
+
export interface XmlElement {
|
|
19
|
+
/** Qualified, as written: "p:sp". */
|
|
20
|
+
readonly name: string;
|
|
21
|
+
readonly prefix: string;
|
|
22
|
+
readonly local: string;
|
|
23
|
+
/** Resolved through xmlns declarations in scope, when declared. */
|
|
24
|
+
readonly namespace?: string;
|
|
25
|
+
readonly attributes: readonly XmlAttribute[];
|
|
26
|
+
/** "<" of the start tag. */
|
|
27
|
+
readonly start: number;
|
|
28
|
+
/** After ">" of the end tag, or after "/>". */
|
|
29
|
+
readonly end: number;
|
|
30
|
+
/** The content between the tags; empty and equal for a self-closing element. */
|
|
31
|
+
readonly contentStart: number;
|
|
32
|
+
readonly contentEnd: number;
|
|
33
|
+
readonly selfClosing: boolean;
|
|
34
|
+
readonly children: readonly XmlElement[];
|
|
35
|
+
readonly parent?: XmlElement;
|
|
36
|
+
/** Index among the parent's element children. */
|
|
37
|
+
readonly index: number;
|
|
38
|
+
/** Child-index path from the root. */
|
|
39
|
+
readonly path: readonly number[];
|
|
40
|
+
}
|
|
41
|
+
export interface XmlPart {
|
|
42
|
+
readonly name: string;
|
|
43
|
+
/** The decoded text the ranges index into (UTF-16 code units). */
|
|
44
|
+
readonly text: string;
|
|
45
|
+
readonly encoding: "utf-8";
|
|
46
|
+
readonly hasBom: boolean;
|
|
47
|
+
/** The overlay revision the part was scanned at; a patch from another revision is stale. */
|
|
48
|
+
readonly revision: number;
|
|
49
|
+
readonly declaration: XmlRange | undefined;
|
|
50
|
+
readonly root: XmlElement;
|
|
51
|
+
/** Comments, processing instructions, CDATA sections and a DOCTYPE, in document order. */
|
|
52
|
+
readonly opaque: readonly XmlRange[];
|
|
53
|
+
find(name: string, under?: XmlElement): XmlElement | undefined;
|
|
54
|
+
findAll(name: string, under?: XmlElement): readonly XmlElement[];
|
|
55
|
+
at(path: readonly number[]): XmlElement | undefined;
|
|
56
|
+
/** Concatenated character data of a subtree, entities decoded, CDATA included. */
|
|
57
|
+
textOf(node: XmlElement): string;
|
|
58
|
+
attribute(node: XmlElement, name: string): string | undefined;
|
|
59
|
+
}
|
|
60
|
+
/** Decodes a part as UTF-8; a part that is not UTF-8 cannot be patched. */
|
|
61
|
+
export declare function decodePart(name: string, bytes: Uint8Array): {
|
|
62
|
+
readonly text: string;
|
|
63
|
+
readonly hasBom: boolean;
|
|
64
|
+
};
|
|
65
|
+
/** The bytes of a part's text; `decodePart` guarantees they equal the original. */
|
|
66
|
+
export declare function encodePart(text: string): Uint8Array;
|
|
67
|
+
/** Scans a part's text; throws `malformed-xml` for what it cannot read. */
|
|
68
|
+
export declare function scanXml(name: string, text: string, revision?: number): XmlPart;
|
|
69
|
+
/** Escapes character data for element content. */
|
|
70
|
+
export declare function escapeText(value: string): string;
|
|
71
|
+
/** Escapes an attribute value and quotes it with double quotes. */
|
|
72
|
+
export declare function escapeAttribute(value: string): string;
|
|
73
|
+
/** Decodes the predefined and numeric entities; anything else stays as written. */
|
|
74
|
+
export declare function decodeEntities(raw: string): string;
|