@arbidocs/blocks 0.4.111 → 0.4.112
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/{NativeDocxEditor-AQKRZBIU.cjs → NativeDocxEditor-AQZSUGET.cjs} +8 -8
- package/dist/{NativeDocxEditor-AQKRZBIU.cjs.map → NativeDocxEditor-AQZSUGET.cjs.map} +1 -1
- package/dist/{NativeDocxEditor-IN2HEO5I.js → NativeDocxEditor-MBCBXYDZ.js} +4 -4
- package/dist/{NativeDocxEditor-IN2HEO5I.js.map → NativeDocxEditor-MBCBXYDZ.js.map} +1 -1
- package/dist/agents/index.cjs +208 -208
- package/dist/agents/index.js +3 -3
- package/dist/{chunk-2C7TCVQZ.js → chunk-3OT37I24.js} +30 -297
- package/dist/chunk-3OT37I24.js.map +1 -0
- package/dist/{chunk-XIGWUDOD.cjs → chunk-ETBB5KMN.cjs} +61 -316
- package/dist/chunk-ETBB5KMN.cjs.map +1 -0
- package/dist/{chunk-Q6B77ZWZ.js → chunk-GIBRZ54P.js} +3 -3
- package/dist/{chunk-Q6B77ZWZ.js.map → chunk-GIBRZ54P.js.map} +1 -1
- package/dist/{chunk-2WO5L7YT.cjs → chunk-HF4PAYBM.cjs} +5 -5
- package/dist/{chunk-2WO5L7YT.cjs.map → chunk-HF4PAYBM.cjs.map} +1 -1
- package/dist/chunk-I2QSDQQV.cjs +126 -0
- package/dist/chunk-I2QSDQQV.cjs.map +1 -0
- package/dist/chunk-QXMR5YHC.js +80 -0
- package/dist/chunk-QXMR5YHC.js.map +1 -0
- package/dist/{chunk-TF47ATYS.cjs → chunk-RUFNJRLW.cjs} +4 -4
- package/dist/{chunk-TF47ATYS.cjs.map → chunk-RUFNJRLW.cjs.map} +1 -1
- package/dist/{chunk-WTM65ZNG.js → chunk-TKJSCHSX.js} +3 -3
- package/dist/{chunk-WTM65ZNG.js.map → chunk-TKJSCHSX.js.map} +1 -1
- package/dist/{chunk-WPVIOGDG.cjs → chunk-US5ASM4G.cjs} +22 -22
- package/dist/{chunk-WPVIOGDG.cjs.map → chunk-US5ASM4G.cjs.map} +1 -1
- package/dist/{chunk-CECWAIHL.js → chunk-XFZ7HNPG.js} +3 -3
- package/dist/{chunk-CECWAIHL.js.map → chunk-XFZ7HNPG.js.map} +1 -1
- package/dist/{chunk-FXUQZFAN.cjs → chunk-Z2NSU7D5.cjs} +4 -4
- package/dist/{chunk-FXUQZFAN.cjs.map → chunk-Z2NSU7D5.cjs.map} +1 -1
- package/dist/{chunk-6Z7DLJU2.js → chunk-ZP4IFW2E.js} +4 -4
- package/dist/{chunk-6Z7DLJU2.js.map → chunk-ZP4IFW2E.js.map} +1 -1
- package/dist/collaboration/index.cjs +1 -1
- package/dist/collaboration/index.js +1 -1
- package/dist/connect/docx.cjs +7 -7
- package/dist/connect/docx.js +5 -5
- package/dist/connect/index.cjs +16 -16
- package/dist/connect/index.js +9 -9
- package/dist/docx/definitions/commands.d.ts +3 -52
- package/dist/docx/definitions/fragment.d.ts +5 -31
- package/dist/docx/definitions/port.d.ts +2 -22
- package/dist/docx/index.cjs +47 -47
- package/dist/docx/index.js +4 -4
- package/dist/docx/references/commands.d.ts +3 -89
- package/dist/docx/references/port.d.ts +2 -11
- package/dist/facts/index.cjs +1 -1
- package/dist/facts/index.js +1 -1
- package/dist/files/index.cjs +1 -1
- package/dist/files/index.js +1 -1
- package/dist/index.cjs +388 -388
- package/dist/index.js +10 -10
- package/dist/settings/index.cjs +1 -1
- package/dist/settings/index.js +1 -1
- package/dist/shell/index.cjs +9 -9
- package/dist/shell/index.js +1 -1
- package/dist/tags/definitions.d.ts +4 -25
- package/dist/tags/ooxml.d.ts +1 -19
- package/dist/workflow-canvas/index.cjs +10 -10
- package/dist/workflow-canvas/index.js +3 -3
- package/node_modules/@arbidocs/coedit/dist/commands.cjs +687 -0
- package/node_modules/@arbidocs/coedit/dist/commands.cjs.map +1 -1
- package/node_modules/@arbidocs/coedit/dist/commands.d.cts +263 -157
- package/node_modules/@arbidocs/coedit/dist/commands.d.ts +263 -157
- package/node_modules/@arbidocs/coedit/dist/commands.js +646 -2
- package/node_modules/@arbidocs/coedit/dist/commands.js.map +1 -1
- package/node_modules/@arbidocs/coedit/dist/port-ip7WByvH.d.cts +188 -0
- package/node_modules/@arbidocs/coedit/dist/port-ip7WByvH.d.ts +188 -0
- package/node_modules/@arbidocs/coedit/dist/server.cjs +675 -65
- package/node_modules/@arbidocs/coedit/dist/server.cjs.map +1 -1
- package/node_modules/@arbidocs/coedit/dist/server.d.cts +15 -4
- package/node_modules/@arbidocs/coedit/dist/server.d.ts +15 -4
- package/node_modules/@arbidocs/coedit/dist/server.js +676 -67
- package/node_modules/@arbidocs/coedit/dist/server.js.map +1 -1
- package/node_modules/@arbidocs/coedit/dist/template.d.cts +3 -17
- package/node_modules/@arbidocs/coedit/dist/template.d.ts +3 -17
- package/node_modules/@arbidocs/coedit/dist/track-eYC94jTp.d.cts +17 -0
- package/node_modules/@arbidocs/coedit/dist/track-eYC94jTp.d.ts +17 -0
- package/node_modules/@arbidocs/coedit/package.json +1 -1
- package/package.json +4 -4
- package/dist/chunk-2A4MDHJR.cjs +0 -198
- package/dist/chunk-2A4MDHJR.cjs.map +0 -1
- package/dist/chunk-2C7TCVQZ.js.map +0 -1
- package/dist/chunk-EPHGD4YV.js +0 -174
- package/dist/chunk-EPHGD4YV.js.map +0 -1
- package/dist/chunk-XIGWUDOD.cjs.map +0 -1
|
@@ -4,6 +4,8 @@ var awareness = require('y-protocols/awareness');
|
|
|
4
4
|
var automation = require('@docx-editor.dev/core/automation');
|
|
5
5
|
var replication = require('@docx-editor.dev/core/collaboration/replication');
|
|
6
6
|
var store = require('@docx-editor.dev/core/store');
|
|
7
|
+
var layout = require('@docx-editor.dev/core/layout');
|
|
8
|
+
var fflate = require('fflate');
|
|
7
9
|
var Y3 = require('yjs');
|
|
8
10
|
var collaboration = require('@docx-editor.dev/core/collaboration');
|
|
9
11
|
|
|
@@ -29,8 +31,528 @@ var Y3__namespace = /*#__PURE__*/_interopNamespace(Y3);
|
|
|
29
31
|
|
|
30
32
|
// src/server.ts
|
|
31
33
|
|
|
34
|
+
// src/commands/read.ts
|
|
35
|
+
var DEFINED_TERM_STYLE = "DefinedTerm";
|
|
36
|
+
var CROSS_REFERENCE_STYLE = "CrossReference";
|
|
37
|
+
var BROKEN_CROSS_REFERENCE_STYLE = "CrossReferenceBroken";
|
|
38
|
+
var WATCHED_STYLES = /* @__PURE__ */ new Set([BROKEN_CROSS_REFERENCE_STYLE]);
|
|
39
|
+
var attr = (node, name) => node.attributes?.find((a) => a.localName === name)?.value;
|
|
40
|
+
var FIELD_ATOM = "\uFFFC";
|
|
41
|
+
var HEADING_STYLE = /^(heading|berschrift|titre|t[ií]tulo|titolo|kop)\s*\d/i;
|
|
42
|
+
function readParagraphs(root) {
|
|
43
|
+
const out = [];
|
|
44
|
+
const body = root.children?.find((n) => n.kind === "body") ?? root;
|
|
45
|
+
const visit = (node, topLevel, pending) => {
|
|
46
|
+
for (const child of node.children ?? []) {
|
|
47
|
+
if (child.kind === "paragraph") {
|
|
48
|
+
out.push(readParagraph(child, topLevel, pending.splice(0)));
|
|
49
|
+
} else if (child.localName === "bookmarkStart") {
|
|
50
|
+
const name = attr(child, "name");
|
|
51
|
+
if (name) pending.push(name);
|
|
52
|
+
} else if (child.localName === "tbl" || child.localName === "tr" || child.localName === "tc") {
|
|
53
|
+
visit(child, false, pending);
|
|
54
|
+
} else if (child.localName === "sdt" || child.localName === "sdtContent") {
|
|
55
|
+
visit(child, topLevel, pending);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
visit(body, true, []);
|
|
60
|
+
return out;
|
|
61
|
+
}
|
|
62
|
+
function readParagraph(node, topLevel, bookmarks) {
|
|
63
|
+
let text = "";
|
|
64
|
+
const links = [];
|
|
65
|
+
let styleId;
|
|
66
|
+
let outline = false;
|
|
67
|
+
let fieldDepth = 0;
|
|
68
|
+
const marks = [];
|
|
69
|
+
let runStyle;
|
|
70
|
+
const fields = [];
|
|
71
|
+
const notes = [];
|
|
72
|
+
let current = null;
|
|
73
|
+
const field = (c) => {
|
|
74
|
+
const type = attr(c, "fldCharType");
|
|
75
|
+
if (type === "begin") {
|
|
76
|
+
if (fieldDepth === 0) {
|
|
77
|
+
current = { offset: text.length, instruction: "", result: "", inResult: false };
|
|
78
|
+
text += FIELD_ATOM;
|
|
79
|
+
}
|
|
80
|
+
fieldDepth++;
|
|
81
|
+
} else if (type === "separate" && fieldDepth === 1 && current) current.inResult = true;
|
|
82
|
+
else if (type === "end") {
|
|
83
|
+
fieldDepth = Math.max(0, fieldDepth - 1);
|
|
84
|
+
if (fieldDepth === 0 && current) {
|
|
85
|
+
const { offset, instruction, result } = current;
|
|
86
|
+
fields.push({ offset, instruction: instruction.trim(), result });
|
|
87
|
+
current = null;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
const walk = (n, link) => {
|
|
92
|
+
for (const c of n.children ?? []) {
|
|
93
|
+
if (c.localName === "fldChar") {
|
|
94
|
+
field(c);
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
if (c.localName === "fldSimple") {
|
|
98
|
+
if (fieldDepth === 0) text += FIELD_ATOM;
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
if (c.localName === "instrText") {
|
|
102
|
+
if (fieldDepth === 1 && current)
|
|
103
|
+
current.instruction += (c.children ?? []).map((t) => t.value ?? "").join("");
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
if (c.kind === "paragraphProperties" || c.localName === "pPr") {
|
|
107
|
+
for (const p of c.children ?? []) {
|
|
108
|
+
if (p.localName === "pStyle") styleId = attr(p, "val");
|
|
109
|
+
if (p.localName === "outlineLvl" && Number(attr(p, "val")) < 9) outline = true;
|
|
110
|
+
}
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
if (c.localName === "delText" || c.localName === "del" || c.localName === "rPr") continue;
|
|
114
|
+
if (c.localName === "r") {
|
|
115
|
+
const rStyle = c.children?.find((x) => x.localName === "rPr")?.children?.find((x) => x.localName === "rStyle");
|
|
116
|
+
const watched = rStyle && attr(rStyle, "val");
|
|
117
|
+
runStyle = watched && WATCHED_STYLES.has(watched) ? watched : void 0;
|
|
118
|
+
walk(c, link);
|
|
119
|
+
runStyle = void 0;
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
if ((c.localName === "footnoteReference" || c.localName === "endnoteReference") && fieldDepth === 0) {
|
|
123
|
+
notes.push({
|
|
124
|
+
offset: text.length,
|
|
125
|
+
kind: c.localName === "footnoteReference" ? "footnote" : "endnote",
|
|
126
|
+
id: attr(c, "id") ?? ""
|
|
127
|
+
});
|
|
128
|
+
text += FIELD_ATOM;
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
if (c.localName === "bookmarkStart") {
|
|
132
|
+
const name = attr(c, "name");
|
|
133
|
+
if (name) bookmarks.push(name);
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
if (c.localName === "hyperlink") {
|
|
137
|
+
const anchor = attr(c, "anchor");
|
|
138
|
+
const next = anchor ? { anchor, text: "", offset: text.length } : void 0;
|
|
139
|
+
walk(c, next ?? link);
|
|
140
|
+
if (next) links.push(next);
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
if (c.kind === "textValue") {
|
|
144
|
+
if (fieldDepth > 0) {
|
|
145
|
+
const open = current;
|
|
146
|
+
if (fieldDepth === 1 && open?.inResult) open.result += c.value ?? "";
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
if (runStyle && c.value) {
|
|
150
|
+
const last = marks[marks.length - 1];
|
|
151
|
+
if (last && last.styleId === runStyle && last.offset + last.text.length === text.length)
|
|
152
|
+
last.text += c.value;
|
|
153
|
+
else marks.push({ styleId: runStyle, offset: text.length, text: c.value });
|
|
154
|
+
}
|
|
155
|
+
text += c.value ?? "";
|
|
156
|
+
if (link) link.text += c.value ?? "";
|
|
157
|
+
continue;
|
|
158
|
+
}
|
|
159
|
+
if (c.localName === "tab" && fieldDepth === 0) text += " ";
|
|
160
|
+
walk(c, link);
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
walk(node);
|
|
164
|
+
const paraId = attr(node, "paraId");
|
|
165
|
+
return {
|
|
166
|
+
id: node.id,
|
|
167
|
+
...paraId ? { paraId } : {},
|
|
168
|
+
text,
|
|
169
|
+
heading: outline || !!styleId && HEADING_STYLE.test(styleId),
|
|
170
|
+
styleId,
|
|
171
|
+
topLevel,
|
|
172
|
+
bookmarks,
|
|
173
|
+
links,
|
|
174
|
+
...fields.length ? { fields } : {},
|
|
175
|
+
...marks.length ? { marks } : {},
|
|
176
|
+
...notes.length ? { notes } : {}
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
function documentNumbering(source) {
|
|
180
|
+
let numbering;
|
|
181
|
+
let cascade;
|
|
182
|
+
const index = () => {
|
|
183
|
+
if (!numbering) {
|
|
184
|
+
cascade = layout.buildStyleCascadeTable(
|
|
185
|
+
source.stylesRoot(),
|
|
186
|
+
void 0,
|
|
187
|
+
source.settingsRoot()
|
|
188
|
+
);
|
|
189
|
+
numbering = layout.withNumberingStyleLinks(
|
|
190
|
+
layout.buildNumberingIndex(source.numberingRoot()),
|
|
191
|
+
cascade
|
|
192
|
+
);
|
|
193
|
+
}
|
|
194
|
+
return numbering;
|
|
195
|
+
};
|
|
196
|
+
return {
|
|
197
|
+
listItems: () => {
|
|
198
|
+
const body = source.root().children?.find((n) => n.kind === "body");
|
|
199
|
+
const items = layout.resolveStoryListItems(
|
|
200
|
+
body?.children ?? [],
|
|
201
|
+
index(),
|
|
202
|
+
cascade
|
|
203
|
+
);
|
|
204
|
+
const out = /* @__PURE__ */ new Map();
|
|
205
|
+
for (const [id, item] of items)
|
|
206
|
+
out.set(id, {
|
|
207
|
+
numId: item.numId,
|
|
208
|
+
ilvl: item.ilvl,
|
|
209
|
+
markerText: item.markerText,
|
|
210
|
+
numFmt: item.numFmt
|
|
211
|
+
});
|
|
212
|
+
return out;
|
|
213
|
+
},
|
|
214
|
+
levelOf: (numId, ilvl) => {
|
|
215
|
+
const level = layout.resolveNumberingLevel(index(), numId, ilvl)?.level;
|
|
216
|
+
return level ? { lvlText: level.lvlText, numFmt: level.numFmt } : null;
|
|
217
|
+
}
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
var W_NAMESPACES = 'xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"';
|
|
221
|
+
var INVALID_XML = /[\u0000-\u0008\u000B\u000C\u000E-\u001F]/g;
|
|
222
|
+
var esc = (text) => text.replace(INVALID_XML, "").replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
223
|
+
var documentXml = (body) => `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
224
|
+
<w:document ${W_NAMESPACES}><w:body>${body}</w:body></w:document>`;
|
|
225
|
+
var stylesXml = (defaults, styles) => `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
226
|
+
<w:styles xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">${defaults}${styles}</w:styles>`;
|
|
227
|
+
var CONTENT_TYPES = `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
228
|
+
<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types"><Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/><Default Extension="xml" ContentType="application/xml"/><Override PartName="/word/document.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml"/><Override PartName="/word/styles.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml"/><Override PartName="/docProps/core.xml" ContentType="application/vnd.openxmlformats-package.core-properties+xml"/></Types>`;
|
|
229
|
+
var ROOT_RELS = `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
230
|
+
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="word/document.xml"/><Relationship Id="rId2" Type="http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties" Target="docProps/core.xml"/></Relationships>`;
|
|
231
|
+
var documentRels = (more = "") => `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
232
|
+
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles" Target="styles.xml"/>${more}</Relationships>`;
|
|
233
|
+
var coreXml = (title, at) => `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
234
|
+
<cp:coreProperties xmlns:cp="http://schemas.openxmlformats.org/package/2006/metadata/core-properties" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><dc:title>${esc(
|
|
235
|
+
title
|
|
236
|
+
)}</dc:title><dcterms:created xsi:type="dcterms:W3CDTF">${at}</dcterms:created><dcterms:modified xsi:type="dcterms:W3CDTF">${at}</dcterms:modified></cp:coreProperties>`;
|
|
237
|
+
function docxPackage(parts) {
|
|
238
|
+
const at = new Date(parts.at ?? Date.now()).toISOString().replace(/\.\d{3}Z$/, "Z");
|
|
239
|
+
return fflate.zipSync({
|
|
240
|
+
"[Content_Types].xml": fflate.strToU8(CONTENT_TYPES),
|
|
241
|
+
"_rels/.rels": fflate.strToU8(ROOT_RELS),
|
|
242
|
+
"docProps/core.xml": fflate.strToU8(coreXml(parts.title, at)),
|
|
243
|
+
"word/document.xml": fflate.strToU8(parts.document),
|
|
244
|
+
"word/styles.xml": fflate.strToU8(parts.styles),
|
|
245
|
+
"word/_rels/document.xml.rels": fflate.strToU8(documentRels(parts.relationships))
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
// src/commands/references.ts
|
|
250
|
+
var RUN_PARTS = /* @__PURE__ */ new Set(["rPr", "t", "tab", "br", "lastRenderedPageBreak"]);
|
|
251
|
+
var SKIPPED = /* @__PURE__ */ new Set(["pPr", "bookmarkStart", "bookmarkEnd", "proofErr", "permStart", "permEnd"]);
|
|
252
|
+
function serialize(node) {
|
|
253
|
+
if (node.kind === "textValue") return esc(node.value ?? "");
|
|
254
|
+
const name = `${node.prefix ?? "w"}:${node.localName}`;
|
|
255
|
+
const attrs = (node.attributes ?? []).map((a) => ` ${a.prefix ? `${a.prefix}:` : ""}${a.localName}="${esc(a.value)}"`).join("");
|
|
256
|
+
const children = (node.children ?? []).map((c) => serialize(c)).join("");
|
|
257
|
+
return children ? `<${name}${attrs}>${children}</${name}>` : `<${name}${attrs}/>`;
|
|
258
|
+
}
|
|
259
|
+
function paragraphRunsXml(paragraph) {
|
|
260
|
+
const runs = [];
|
|
261
|
+
for (const child of paragraph.children ?? []) {
|
|
262
|
+
if (child.localName && SKIPPED.has(child.localName)) continue;
|
|
263
|
+
if (child.localName !== "r") return null;
|
|
264
|
+
if ((child.children ?? []).some((c) => !c.localName || !RUN_PARTS.has(c.localName))) return null;
|
|
265
|
+
runs.push(serialize(child));
|
|
266
|
+
}
|
|
267
|
+
return runs.length ? runs.join("") : null;
|
|
268
|
+
}
|
|
269
|
+
var W_NS = "http://schemas.openxmlformats.org/wordprocessingml/2006/main";
|
|
270
|
+
var TemplateError = class extends Error {
|
|
271
|
+
constructor(message) {
|
|
272
|
+
super(message);
|
|
273
|
+
this.name = "TemplateError";
|
|
274
|
+
}
|
|
275
|
+
};
|
|
276
|
+
function parse(xml, part = "part") {
|
|
277
|
+
const read = store.readXml(xml, { maxBytes: 64 * 1024 * 1024, maxElements: 2e6 });
|
|
278
|
+
if (!read.ok) throw new TemplateError(`${part} is not readable XML (${read.reason})`);
|
|
279
|
+
const convert = (node) => node.type === "text" ? node.value : { name: node.name, attrs: { ...node.attributes }, children: node.children.map(convert) };
|
|
280
|
+
const root = read.nodes.map(convert).find((n) => typeof n !== "string");
|
|
281
|
+
if (!root) throw new TemplateError(`${part} has no root element`);
|
|
282
|
+
const w = root.attrs["xmlns:w"];
|
|
283
|
+
if (w !== void 0 && w !== W_NS) throw new TemplateError(`${part} binds w: to ${w}`);
|
|
284
|
+
return root;
|
|
285
|
+
}
|
|
286
|
+
var escText = (s) => s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
287
|
+
var escAttr = (s) => escText(s).replace(/"/g, """);
|
|
288
|
+
function serialize2(root) {
|
|
289
|
+
const out = ['<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n'];
|
|
290
|
+
const walk = (node) => {
|
|
291
|
+
if (typeof node === "string") return void out.push(escText(node));
|
|
292
|
+
out.push("<", node.name);
|
|
293
|
+
for (const [k, v] of Object.entries(node.attrs)) out.push(" ", k, '="', escAttr(v), '"');
|
|
294
|
+
if (node.children.length === 0) return void out.push("/>");
|
|
295
|
+
out.push(">");
|
|
296
|
+
node.children.forEach(walk);
|
|
297
|
+
out.push("</", node.name, ">");
|
|
298
|
+
};
|
|
299
|
+
walk(root);
|
|
300
|
+
return out.join("");
|
|
301
|
+
}
|
|
302
|
+
var el = (name, attrs = {}, children = []) => ({
|
|
303
|
+
name,
|
|
304
|
+
attrs,
|
|
305
|
+
children
|
|
306
|
+
});
|
|
307
|
+
var isEl = (n) => typeof n === "object" && n !== null;
|
|
308
|
+
var kids = (e, name) => e.children.filter((c) => isEl(c) && (name === void 0 || c.name === name));
|
|
309
|
+
var kid = (e, name) => e ? kids(e, name)[0] : void 0;
|
|
310
|
+
|
|
311
|
+
// src/template/pkg.ts
|
|
312
|
+
var REL = "http://schemas.openxmlformats.org/officeDocument/2006/relationships";
|
|
313
|
+
var RT = {
|
|
314
|
+
officeDocument: `${REL}/officeDocument`};
|
|
315
|
+
var Pkg = class _Pkg {
|
|
316
|
+
files;
|
|
317
|
+
types;
|
|
318
|
+
constructor(files) {
|
|
319
|
+
this.files = files;
|
|
320
|
+
const ct = this.find("[Content_Types].xml");
|
|
321
|
+
if (!ct) throw new TemplateError("not a Word package: no [Content_Types].xml");
|
|
322
|
+
this.types = parse(fflate.strFromU8(files.get(ct)), "[Content_Types].xml");
|
|
323
|
+
}
|
|
324
|
+
static read(bytes) {
|
|
325
|
+
let files;
|
|
326
|
+
try {
|
|
327
|
+
files = fflate.unzipSync(bytes);
|
|
328
|
+
} catch {
|
|
329
|
+
throw new TemplateError("not a Word package: not a zip");
|
|
330
|
+
}
|
|
331
|
+
return new _Pkg(new Map(Object.entries(files).filter(([n]) => !n.endsWith("/"))));
|
|
332
|
+
}
|
|
333
|
+
write() {
|
|
334
|
+
this.files.set(
|
|
335
|
+
this.find("[Content_Types].xml") ?? "[Content_Types].xml",
|
|
336
|
+
fflate.strToU8(serialize2(this.types))
|
|
337
|
+
);
|
|
338
|
+
return fflate.zipSync(Object.fromEntries(this.files), { level: 6 });
|
|
339
|
+
}
|
|
340
|
+
/** The stored name of a part, matched case-insensitively as OPC does. */
|
|
341
|
+
find(name) {
|
|
342
|
+
const key = name.replace(/^\//, "").toLowerCase();
|
|
343
|
+
for (const n of this.files.keys()) if (n.toLowerCase() === key) return n;
|
|
344
|
+
return void 0;
|
|
345
|
+
}
|
|
346
|
+
has(name) {
|
|
347
|
+
return this.find(name) !== void 0;
|
|
348
|
+
}
|
|
349
|
+
text(name) {
|
|
350
|
+
const n = this.find(name);
|
|
351
|
+
return n === void 0 ? void 0 : fflate.strFromU8(this.files.get(n));
|
|
352
|
+
}
|
|
353
|
+
xml(name) {
|
|
354
|
+
const t = this.text(name);
|
|
355
|
+
return t === void 0 ? void 0 : parse(t, name);
|
|
356
|
+
}
|
|
357
|
+
setXml(name, root, contentType) {
|
|
358
|
+
this.files.set(this.find(name) ?? name, fflate.strToU8(serialize2(root)));
|
|
359
|
+
if (contentType) this.setContentType(name, contentType);
|
|
360
|
+
}
|
|
361
|
+
setBytes(name, bytes, contentType) {
|
|
362
|
+
this.files.set(this.find(name) ?? name, bytes);
|
|
363
|
+
if (contentType) this.setContentType(name, contentType);
|
|
364
|
+
}
|
|
365
|
+
remove(name) {
|
|
366
|
+
const n = this.find(name);
|
|
367
|
+
if (n === void 0) return;
|
|
368
|
+
this.files.delete(n);
|
|
369
|
+
this.types.children = this.types.children.filter(
|
|
370
|
+
(c) => !(typeof c !== "string" && c.name === "Override" && c.attrs.PartName.toLowerCase() === `/${n.toLowerCase()}`)
|
|
371
|
+
);
|
|
372
|
+
this.files.delete(relsName(n));
|
|
373
|
+
}
|
|
374
|
+
contentType(name) {
|
|
375
|
+
const part = `/${name.replace(/^\//, "")}`.toLowerCase();
|
|
376
|
+
const override = kids(this.types, "Override").find(
|
|
377
|
+
(o) => o.attrs.PartName.toLowerCase() === part
|
|
378
|
+
);
|
|
379
|
+
if (override) return override.attrs.ContentType;
|
|
380
|
+
const ext = part.slice(part.lastIndexOf(".") + 1);
|
|
381
|
+
return kids(this.types, "Default").find((d) => d.attrs.Extension.toLowerCase() === ext)?.attrs.ContentType;
|
|
382
|
+
}
|
|
383
|
+
setContentType(name, type) {
|
|
384
|
+
const part = `/${name.replace(/^\//, "")}`;
|
|
385
|
+
const override = kids(this.types, "Override").find(
|
|
386
|
+
(o) => o.attrs.PartName.toLowerCase() === part.toLowerCase()
|
|
387
|
+
);
|
|
388
|
+
if (override) override.attrs.ContentType = type;
|
|
389
|
+
else this.types.children.push(el("Override", { PartName: part, ContentType: type }));
|
|
390
|
+
}
|
|
391
|
+
/** A `Default` for an extension (media), unless one exists. */
|
|
392
|
+
ensureDefault(ext, type) {
|
|
393
|
+
if (!kids(this.types, "Default").some(
|
|
394
|
+
(d) => d.attrs.Extension.toLowerCase() === ext.toLowerCase()
|
|
395
|
+
))
|
|
396
|
+
this.types.children.unshift(el("Default", { Extension: ext, ContentType: type }));
|
|
397
|
+
}
|
|
398
|
+
rels(owner) {
|
|
399
|
+
const root = this.xml(relsName(owner));
|
|
400
|
+
if (!root) return [];
|
|
401
|
+
return kids(root, "Relationship").map((r) => ({
|
|
402
|
+
id: r.attrs.Id,
|
|
403
|
+
type: r.attrs.Type,
|
|
404
|
+
target: r.attrs.Target,
|
|
405
|
+
external: r.attrs.TargetMode === "External"
|
|
406
|
+
}));
|
|
407
|
+
}
|
|
408
|
+
setRels(owner, rels) {
|
|
409
|
+
const root = el(
|
|
410
|
+
"Relationships",
|
|
411
|
+
{ xmlns: "http://schemas.openxmlformats.org/package/2006/relationships" },
|
|
412
|
+
rels.map(
|
|
413
|
+
(r) => el("Relationship", {
|
|
414
|
+
Id: r.id,
|
|
415
|
+
Type: r.type,
|
|
416
|
+
Target: r.target,
|
|
417
|
+
...r.external ? { TargetMode: "External" } : {}
|
|
418
|
+
})
|
|
419
|
+
)
|
|
420
|
+
);
|
|
421
|
+
this.setXml(relsName(owner), root);
|
|
422
|
+
}
|
|
423
|
+
/** Add a relationship from `owner`; returns its new id. */
|
|
424
|
+
addRel(owner, type, target, external = false) {
|
|
425
|
+
const rels = this.rels(owner);
|
|
426
|
+
const id = freshId(new Set(rels.map((r) => r.id)), "rIdT");
|
|
427
|
+
rels.push({ id, type, target, external });
|
|
428
|
+
this.setRels(owner, rels);
|
|
429
|
+
return id;
|
|
430
|
+
}
|
|
431
|
+
/** The part a relationship of `owner` points at (internal targets only). */
|
|
432
|
+
target(owner, rel) {
|
|
433
|
+
return resolveTarget(owner, rel.target);
|
|
434
|
+
}
|
|
435
|
+
/** The first internal part of a relationship type from `owner`. */
|
|
436
|
+
partOf(owner, type) {
|
|
437
|
+
const rel = this.rels(owner).find((r) => r.type === type && !r.external);
|
|
438
|
+
return rel && this.find(this.target(owner, rel));
|
|
439
|
+
}
|
|
440
|
+
/** The main document part (`word/document.xml` by convention). */
|
|
441
|
+
get main() {
|
|
442
|
+
const main = this.partOf("", RT.officeDocument);
|
|
443
|
+
if (!main) throw new TemplateError("not a Word package: no main document part");
|
|
444
|
+
return main;
|
|
445
|
+
}
|
|
446
|
+
};
|
|
447
|
+
function relsName(owner) {
|
|
448
|
+
const slash = owner.lastIndexOf("/");
|
|
449
|
+
return `${owner.slice(0, slash + 1)}_rels/${owner.slice(slash + 1)}.rels`;
|
|
450
|
+
}
|
|
451
|
+
function resolveTarget(owner, target) {
|
|
452
|
+
if (target.startsWith("/")) return target.slice(1);
|
|
453
|
+
const base = owner.slice(0, owner.lastIndexOf("/") + 1).split("/").filter(Boolean);
|
|
454
|
+
for (const seg of target.split("/")) {
|
|
455
|
+
if (seg === "..") base.pop();
|
|
456
|
+
else if (seg !== "." && seg !== "") base.push(seg);
|
|
457
|
+
}
|
|
458
|
+
return base.join("/");
|
|
459
|
+
}
|
|
460
|
+
function freshId(taken, prefix) {
|
|
461
|
+
for (let i = 1; ; i++) if (!taken.has(`${prefix}${i}`)) return `${prefix}${i}`;
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
// src/template/track.ts
|
|
465
|
+
var TRACKED = /* @__PURE__ */ new Set(["w:ins", "w:del", "w:moveFrom", "w:moveTo"]);
|
|
466
|
+
function trackInsertion(fragment, revision, covered) {
|
|
467
|
+
const pkg = Pkg.read(fragment);
|
|
468
|
+
const main = pkg.main;
|
|
469
|
+
const root = pkg.xml(main);
|
|
470
|
+
const body = kid(root, "w:body");
|
|
471
|
+
if (!root || !body) return fragment;
|
|
472
|
+
const attrs = { "w:id": "1", "w:author": revision.author, "w:date": revision.date };
|
|
473
|
+
const lastParagraph = body.children.filter(isEl).findLast((c) => c.name === "w:p");
|
|
474
|
+
const visit = (node) => {
|
|
475
|
+
node.children = node.children.map((child) => {
|
|
476
|
+
if (!isEl(child)) return child;
|
|
477
|
+
if (child.name === "w:r") return TRACKED.has(node.name) ? child : el("w:ins", attrs, [child]);
|
|
478
|
+
if (TRACKED.has(child.name)) return child;
|
|
479
|
+
if (child.name === "w:tr") {
|
|
480
|
+
markRow(child, attrs);
|
|
481
|
+
return child;
|
|
482
|
+
}
|
|
483
|
+
visit(child);
|
|
484
|
+
if (child.name === "w:p" && (covered || child !== lastParagraph)) markParagraph(child, attrs);
|
|
485
|
+
return child;
|
|
486
|
+
});
|
|
487
|
+
};
|
|
488
|
+
visit(body);
|
|
489
|
+
pkg.setXml(main, root);
|
|
490
|
+
return pkg.write();
|
|
491
|
+
}
|
|
492
|
+
function markParagraph(p, attrs) {
|
|
493
|
+
let pPr = kid(p, "w:pPr");
|
|
494
|
+
if (!pPr) p.children.unshift(pPr = el("w:pPr"));
|
|
495
|
+
let rPr = kid(pPr, "w:rPr");
|
|
496
|
+
if (!rPr) {
|
|
497
|
+
rPr = el("w:rPr");
|
|
498
|
+
const at = pPr.children.findIndex(
|
|
499
|
+
(c) => isEl(c) && (c.name === "w:sectPr" || c.name === "w:pPrChange")
|
|
500
|
+
);
|
|
501
|
+
pPr.children.splice(at < 0 ? pPr.children.length : at, 0, rPr);
|
|
502
|
+
}
|
|
503
|
+
if (!kid(rPr, "w:ins")) rPr.children.unshift(el("w:ins", attrs));
|
|
504
|
+
}
|
|
505
|
+
function markRow(tr, attrs) {
|
|
506
|
+
let trPr = kid(tr, "w:trPr");
|
|
507
|
+
if (!trPr) {
|
|
508
|
+
trPr = el("w:trPr");
|
|
509
|
+
const after = tr.children.findIndex((c) => isEl(c) && c.name === "w:tblPrEx");
|
|
510
|
+
tr.children.splice(after + 1, 0, trPr);
|
|
511
|
+
}
|
|
512
|
+
if (kid(trPr, "w:ins")) return;
|
|
513
|
+
const at = trPr.children.findIndex((c) => isEl(c) && c.name === "w:trPrChange");
|
|
514
|
+
trPr.children.splice(at < 0 ? trPr.children.length : at, 0, el("w:ins", attrs));
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
// src/commands/fragment.ts
|
|
518
|
+
var CHARACTER_STYLES = {
|
|
519
|
+
[DEFINED_TERM_STYLE]: `<w:style w:type="character" w:customStyle="1" w:styleId="${DEFINED_TERM_STYLE}"><w:name w:val="Defined Term"/><w:rPr><w:u w:val="dotted" w:color="7F7F7F"/></w:rPr></w:style>`,
|
|
520
|
+
[CROSS_REFERENCE_STYLE]: `<w:style w:type="character" w:customStyle="1" w:styleId="${CROSS_REFERENCE_STYLE}"><w:name w:val="Cross Reference"/><w:rPr><w:color w:val="1F4E79"/><w:u w:val="dotted" w:color="8EA9C1"/></w:rPr></w:style>`,
|
|
521
|
+
[BROKEN_CROSS_REFERENCE_STYLE]: `<w:style w:type="character" w:customStyle="1" w:styleId="${BROKEN_CROSS_REFERENCE_STYLE}"><w:name w:val="Cross Reference Broken"/><w:basedOn w:val="${CROSS_REFERENCE_STYLE}"/><w:rPr><w:color w:val="C00000"/><w:u w:val="wave" w:color="C00000"/></w:rPr></w:style>`
|
|
522
|
+
};
|
|
523
|
+
function stylesUsed(body) {
|
|
524
|
+
return [...new Set([...body.matchAll(/<w:rStyle w:val="([^"]+)"/g)].map((m) => m[1]))];
|
|
525
|
+
}
|
|
526
|
+
var fragmentStyles = (ids) => stylesXml(
|
|
527
|
+
"",
|
|
528
|
+
`<w:style w:type="paragraph" w:default="1" w:styleId="Normal"><w:name w:val="Normal"/><w:qFormat/></w:style>${ids.map((id) => CHARACTER_STYLES[id] ?? "").join("")}`
|
|
529
|
+
);
|
|
530
|
+
function fragmentPackage(body, covered, {
|
|
531
|
+
revision,
|
|
532
|
+
relationships,
|
|
533
|
+
styles = stylesUsed(body)
|
|
534
|
+
} = {}) {
|
|
535
|
+
const untracked = docxPackage({
|
|
536
|
+
document: documentXml(body),
|
|
537
|
+
styles: fragmentStyles(styles),
|
|
538
|
+
title: "Defined terms",
|
|
539
|
+
relationships
|
|
540
|
+
});
|
|
541
|
+
return revision ? trackInsertion(untracked, revision, covered) : untracked;
|
|
542
|
+
}
|
|
543
|
+
var attr2 = (node, name) => node.attributes?.find((a) => a.localName === name)?.value;
|
|
544
|
+
function documentStyleIds(root) {
|
|
545
|
+
const ids = /* @__PURE__ */ new Set();
|
|
546
|
+
for (const style of root?.children ?? [])
|
|
547
|
+
if (style.localName === "style") {
|
|
548
|
+
const id = attr2(style, "styleId");
|
|
549
|
+
if (id) ids.add(id);
|
|
550
|
+
}
|
|
551
|
+
return ids;
|
|
552
|
+
}
|
|
553
|
+
|
|
32
554
|
// src/rich.ts
|
|
33
|
-
var
|
|
555
|
+
var WML2 = "http://schemas.openxmlformats.org/wordprocessingml/2006/main";
|
|
34
556
|
var WRAPPERS = /* @__PURE__ */ new Set([
|
|
35
557
|
"ins",
|
|
36
558
|
"del",
|
|
@@ -45,24 +567,24 @@ var WRAPPERS = /* @__PURE__ */ new Set([
|
|
|
45
567
|
"sdtContent"
|
|
46
568
|
]);
|
|
47
569
|
var TEXT_ELEMENTS = /* @__PURE__ */ new Set(["t", "delText", "instrText"]);
|
|
48
|
-
var
|
|
49
|
-
var isWml = (
|
|
50
|
-
function describe(
|
|
51
|
-
const desc = { ns:
|
|
52
|
-
if (
|
|
570
|
+
var isEl2 = (n) => typeof n !== "string";
|
|
571
|
+
var isWml = (el2, local) => el2.ns === WML2 && el2.local === local;
|
|
572
|
+
function describe(el2) {
|
|
573
|
+
const desc = { ns: el2.ns, local: el2.local, attrs: el2.attrs, bindings: el2.bindings };
|
|
574
|
+
if (el2.prefix !== void 0) desc.prefix = el2.prefix;
|
|
53
575
|
return desc;
|
|
54
576
|
}
|
|
55
577
|
function withChildren(desc, children, id) {
|
|
56
|
-
const
|
|
578
|
+
const el2 = {
|
|
57
579
|
ns: desc.ns,
|
|
58
580
|
local: desc.local,
|
|
59
581
|
attrs: desc.attrs,
|
|
60
582
|
bindings: desc.bindings,
|
|
61
583
|
children
|
|
62
584
|
};
|
|
63
|
-
if (desc.prefix !== void 0)
|
|
64
|
-
if (id !== void 0)
|
|
65
|
-
return
|
|
585
|
+
if (desc.prefix !== void 0) el2.prefix = desc.prefix;
|
|
586
|
+
if (id !== void 0) el2._id = id;
|
|
587
|
+
return el2;
|
|
66
588
|
}
|
|
67
589
|
var counter = 0;
|
|
68
590
|
function newRunId() {
|
|
@@ -79,7 +601,7 @@ function encodeRun(run, wrappers, out) {
|
|
|
79
601
|
let rPr = null;
|
|
80
602
|
let start = 0;
|
|
81
603
|
const first = children[0];
|
|
82
|
-
if (first !== void 0 &&
|
|
604
|
+
if (first !== void 0 && isEl2(first) && isWml(first, "rPr")) {
|
|
83
605
|
rPr = first;
|
|
84
606
|
start = 1;
|
|
85
607
|
}
|
|
@@ -87,9 +609,9 @@ function encodeRun(run, wrappers, out) {
|
|
|
87
609
|
let produced = false;
|
|
88
610
|
for (let i = start; i < children.length; i++) {
|
|
89
611
|
const child = children[i];
|
|
90
|
-
if (!
|
|
612
|
+
if (!isEl2(child)) fail();
|
|
91
613
|
const only = child.children[0];
|
|
92
|
-
if (child.ns ===
|
|
614
|
+
if (child.ns === WML2 && TEXT_ELEMENTS.has(child.local) && child.children.length === 1 && typeof only === "string" && only.length > 0) {
|
|
93
615
|
const tx = describe(child);
|
|
94
616
|
for (let c = 0; c < only.length; c++) out.push({ v: only[c], a: { ...base, tx, k: null } });
|
|
95
617
|
} else {
|
|
@@ -99,16 +621,16 @@ function encodeRun(run, wrappers, out) {
|
|
|
99
621
|
}
|
|
100
622
|
if (!produced)
|
|
101
623
|
out.push({
|
|
102
|
-
v: { x: { ns:
|
|
624
|
+
v: { x: { ns: WML2, local: "e", attrs: [], bindings: [], children: [] } },
|
|
103
625
|
a: { ...base, tx: null, k: "e" }
|
|
104
626
|
});
|
|
105
627
|
}
|
|
106
628
|
function encodeInline(children, wrappers, out) {
|
|
107
629
|
for (const child of children) {
|
|
108
|
-
if (!
|
|
109
|
-
if (child.ns ===
|
|
630
|
+
if (!isEl2(child)) fail();
|
|
631
|
+
if (child.ns === WML2 && child.local === "r") {
|
|
110
632
|
encodeRun(child, wrappers, out);
|
|
111
|
-
} else if (child.ns ===
|
|
633
|
+
} else if (child.ns === WML2 && WRAPPERS.has(child.local)) {
|
|
112
634
|
const before = out.length;
|
|
113
635
|
const desc = { ...describe(child), head: [], id: child._id ?? newRunId() };
|
|
114
636
|
let ok = true;
|
|
@@ -124,10 +646,10 @@ function encodeInline(children, wrappers, out) {
|
|
|
124
646
|
out.length = before;
|
|
125
647
|
out.push(atom(child, wrappers));
|
|
126
648
|
}
|
|
127
|
-
} else if (child.ns ===
|
|
649
|
+
} else if (child.ns === WML2 && child.local === "sdt") {
|
|
128
650
|
const last = child.children[child.children.length - 1];
|
|
129
651
|
const head = child.children.slice(0, -1);
|
|
130
|
-
if (last !== void 0 &&
|
|
652
|
+
if (last !== void 0 && isEl2(last) && isWml(last, "sdtContent") && head.every(isEl2)) {
|
|
131
653
|
const before = out.length;
|
|
132
654
|
const sdt = {
|
|
133
655
|
...describe(child),
|
|
@@ -154,14 +676,14 @@ function encodeInline(children, wrappers, out) {
|
|
|
154
676
|
}
|
|
155
677
|
}
|
|
156
678
|
}
|
|
157
|
-
function atom(
|
|
158
|
-
return { v: { x:
|
|
679
|
+
function atom(el2, wrappers) {
|
|
680
|
+
return { v: { x: el2 }, a: { r: null, ra: null, ri: null, w: wrappers, tx: null, k: "a" } };
|
|
159
681
|
}
|
|
160
682
|
function encodeParagraph(children) {
|
|
161
683
|
const head = [];
|
|
162
684
|
let start = 0;
|
|
163
685
|
const first = children[0];
|
|
164
|
-
if (first !== void 0 &&
|
|
686
|
+
if (first !== void 0 && isEl2(first) && isWml(first, "pPr")) {
|
|
165
687
|
head.push(first);
|
|
166
688
|
start = 1;
|
|
167
689
|
}
|
|
@@ -338,8 +860,8 @@ function writeUnits(text, units) {
|
|
|
338
860
|
function isRichParagraph(map) {
|
|
339
861
|
return map.has("inline");
|
|
340
862
|
}
|
|
341
|
-
function isParagraphEl(
|
|
342
|
-
return
|
|
863
|
+
function isParagraphEl(el2) {
|
|
864
|
+
return el2.ns === WML2 && el2.local === "p";
|
|
343
865
|
}
|
|
344
866
|
function fieldsOf(map, xml) {
|
|
345
867
|
map.set("ns", xml.ns);
|
|
@@ -361,7 +883,7 @@ function createRichParagraph(xml, encoded) {
|
|
|
361
883
|
const map = new Y3__namespace.Map();
|
|
362
884
|
fieldsOf(map, xml);
|
|
363
885
|
const children = new Y3__namespace.Array();
|
|
364
|
-
children.push(encoded.head.map((
|
|
886
|
+
children.push(encoded.head.map((el2) => xmlToLive(el2)));
|
|
365
887
|
map.set("children", children);
|
|
366
888
|
const inline = new Y3__namespace.Text();
|
|
367
889
|
writeUnits(inline, encoded.units);
|
|
@@ -400,14 +922,14 @@ function liveToXml(map) {
|
|
|
400
922
|
var escapeText = (value) => value.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
401
923
|
var escapeAttr = (value) => value.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/\t/g, "	").replace(/\n/g, " ").replace(/\r/g, " ");
|
|
402
924
|
var qualified = (prefix, local) => prefix ? `${prefix}:${local}` : local;
|
|
403
|
-
function serializeXml(
|
|
925
|
+
function serializeXml(el2, scope) {
|
|
404
926
|
const inScope = new Map(scope);
|
|
405
|
-
for (const b of
|
|
406
|
-
let out = `<${qualified(
|
|
407
|
-
for (const b of
|
|
927
|
+
for (const b of el2.bindings) inScope.set(b.prefix, b.ns);
|
|
928
|
+
let out = `<${qualified(el2.prefix, el2.local)}`;
|
|
929
|
+
for (const b of el2.bindings) {
|
|
408
930
|
out += b.prefix === "" ? ` xmlns="${escapeAttr(b.ns)}"` : ` xmlns:${b.prefix}="${escapeAttr(b.ns)}"`;
|
|
409
931
|
}
|
|
410
|
-
for (const a of
|
|
932
|
+
for (const a of el2.attrs) {
|
|
411
933
|
let p = a.prefix;
|
|
412
934
|
if (a.ns !== "" && !p) {
|
|
413
935
|
for (const [candidate, uri] of inScope) {
|
|
@@ -419,20 +941,20 @@ function serializeXml(el, scope) {
|
|
|
419
941
|
}
|
|
420
942
|
out += ` ${qualified(p, a.local)}="${escapeAttr(a.value)}"`;
|
|
421
943
|
}
|
|
422
|
-
if (
|
|
944
|
+
if (el2.children.length === 0) return `${out}/>`;
|
|
423
945
|
out += ">";
|
|
424
|
-
for (const child of
|
|
946
|
+
for (const child of el2.children) {
|
|
425
947
|
out += typeof child === "string" ? escapeText(child) : serializeXml(child, inScope);
|
|
426
948
|
}
|
|
427
|
-
return `${out}</${qualified(
|
|
949
|
+
return `${out}</${qualified(el2.prefix, el2.local)}>`;
|
|
428
950
|
}
|
|
429
|
-
function serializeLive(
|
|
430
|
-
if (isRichParagraph(
|
|
431
|
-
const prefix =
|
|
432
|
-
const local =
|
|
433
|
-
const bindings =
|
|
434
|
-
const attrs =
|
|
435
|
-
const children =
|
|
951
|
+
function serializeLive(el2, scope) {
|
|
952
|
+
if (isRichParagraph(el2)) return serializeXml(liveToXml(el2), scope);
|
|
953
|
+
const prefix = el2.get("prefix");
|
|
954
|
+
const local = el2.get("local");
|
|
955
|
+
const bindings = el2.get("bindings").toArray();
|
|
956
|
+
const attrs = el2.get("attrs").toArray();
|
|
957
|
+
const children = el2.get("children").toArray();
|
|
436
958
|
const inScope = new Map(scope);
|
|
437
959
|
for (const b of bindings) inScope.set(b.prefix, b.ns);
|
|
438
960
|
let out = `<${qualified(prefix, local)}`;
|
|
@@ -480,8 +1002,8 @@ function canonicalToXml(node) {
|
|
|
480
1002
|
if (node.prefix !== void 0) xml.prefix = node.prefix;
|
|
481
1003
|
return xml;
|
|
482
1004
|
}
|
|
483
|
-
function encodeElement(
|
|
484
|
-
return xmlToLive(canonicalToXml(
|
|
1005
|
+
function encodeElement(el2) {
|
|
1006
|
+
return xmlToLive(canonicalToXml(el2));
|
|
485
1007
|
}
|
|
486
1008
|
function bootstrap(doc, pkg) {
|
|
487
1009
|
doc.transact(() => {
|
|
@@ -666,14 +1188,14 @@ function materialize(doc, cache, changed = null) {
|
|
|
666
1188
|
sinkSafe: store.validateExternalTarget(r.rawTarget).ok
|
|
667
1189
|
});
|
|
668
1190
|
}
|
|
669
|
-
const
|
|
1191
|
+
const relsName2 = store.relsPartNameFor(owner);
|
|
670
1192
|
const read = store.readOoxmlPart(relationshipsXml(records), {
|
|
671
|
-
name:
|
|
1193
|
+
name: relsName2,
|
|
672
1194
|
contentType: RELS_CONTENT_TYPE
|
|
673
1195
|
});
|
|
674
1196
|
if (!read.ok)
|
|
675
1197
|
throw new MaterializeError(`relationships of ${owner} are not valid: ${read.reason}`);
|
|
676
|
-
parts.set(
|
|
1198
|
+
parts.set(relsName2, read.part);
|
|
677
1199
|
}
|
|
678
1200
|
const contentTypes = {
|
|
679
1201
|
defaults: new Map(doc.getMap("ctDefaults")),
|
|
@@ -739,14 +1261,14 @@ var RegistryError = class extends Error {
|
|
|
739
1261
|
this.name = "RegistryError";
|
|
740
1262
|
}
|
|
741
1263
|
};
|
|
742
|
-
function childrenOf(
|
|
743
|
-
return
|
|
1264
|
+
function childrenOf(el2) {
|
|
1265
|
+
return el2.get("children");
|
|
744
1266
|
}
|
|
745
|
-
function attrsOf(
|
|
746
|
-
return
|
|
1267
|
+
function attrsOf(el2) {
|
|
1268
|
+
return el2.get("attrs");
|
|
747
1269
|
}
|
|
748
|
-
function bindingsOf(
|
|
749
|
-
return
|
|
1270
|
+
function bindingsOf(el2) {
|
|
1271
|
+
return el2.get("bindings");
|
|
750
1272
|
}
|
|
751
1273
|
var IDENTIFIED = /* @__PURE__ */ new Set([
|
|
752
1274
|
"r",
|
|
@@ -773,7 +1295,7 @@ function plainToXml(node) {
|
|
|
773
1295
|
children: node.children.map(plainToXml)
|
|
774
1296
|
};
|
|
775
1297
|
if (node.prefix !== void 0) xml.prefix = node.prefix;
|
|
776
|
-
if (node.ns ===
|
|
1298
|
+
if (node.ns === WML2 && IDENTIFIED.has(node.local)) {
|
|
777
1299
|
node.rid ??= newRunId();
|
|
778
1300
|
xml._id = node.rid;
|
|
779
1301
|
}
|
|
@@ -974,7 +1496,7 @@ var NodeRegistry = class {
|
|
|
974
1496
|
const stored = head.toArray().map((child) => liveToXml(child));
|
|
975
1497
|
if (JSON.stringify(stored) !== JSON.stringify(encoded.head)) {
|
|
976
1498
|
head.delete(0, head.length);
|
|
977
|
-
head.push(encoded.head.map((
|
|
1499
|
+
head.push(encoded.head.map((el2) => xmlToLive(el2)));
|
|
978
1500
|
}
|
|
979
1501
|
const inline = live.get("inline");
|
|
980
1502
|
applyUnits(inline, readUnits(inline), encoded.units);
|
|
@@ -1108,14 +1630,14 @@ function attrJson(qname, value) {
|
|
|
1108
1630
|
function setAttribute(registry, id, qname, value) {
|
|
1109
1631
|
const entry = registry.require(id);
|
|
1110
1632
|
if ("plain" in entry) {
|
|
1111
|
-
const
|
|
1112
|
-
const index2 =
|
|
1633
|
+
const el2 = asPlainElement(entry.plain, id);
|
|
1634
|
+
const index2 = el2.attrs.findIndex((a) => sameAttr(a, qname));
|
|
1113
1635
|
if (value === null) {
|
|
1114
|
-
if (index2 >= 0)
|
|
1636
|
+
if (index2 >= 0) el2.attrs.splice(index2, 1);
|
|
1115
1637
|
} else if (index2 >= 0) {
|
|
1116
|
-
|
|
1638
|
+
el2.attrs[index2] = attrJson(qname, value);
|
|
1117
1639
|
} else {
|
|
1118
|
-
|
|
1640
|
+
el2.attrs.push(attrJson(qname, value));
|
|
1119
1641
|
}
|
|
1120
1642
|
return;
|
|
1121
1643
|
}
|
|
@@ -1131,12 +1653,12 @@ function setNamespaceBinding(registry, id, prefix, uri) {
|
|
|
1131
1653
|
const entry = registry.require(id);
|
|
1132
1654
|
const binding = uri === null ? null : { prefix, ns: uri };
|
|
1133
1655
|
if ("plain" in entry) {
|
|
1134
|
-
const
|
|
1135
|
-
const index2 =
|
|
1136
|
-
if (index2 >= 0)
|
|
1656
|
+
const el2 = asPlainElement(entry.plain, id);
|
|
1657
|
+
const index2 = el2.bindings.findIndex((b) => b.prefix === prefix);
|
|
1658
|
+
if (index2 >= 0) el2.bindings.splice(index2, 1);
|
|
1137
1659
|
if (binding) {
|
|
1138
|
-
if (index2 >= 0)
|
|
1139
|
-
else
|
|
1660
|
+
if (index2 >= 0) el2.bindings.splice(index2, 0, binding);
|
|
1661
|
+
else el2.bindings.push(binding);
|
|
1140
1662
|
}
|
|
1141
1663
|
return;
|
|
1142
1664
|
}
|
|
@@ -1859,8 +2381,8 @@ function openRoomStore(options) {
|
|
|
1859
2381
|
return {
|
|
1860
2382
|
store: store$1,
|
|
1861
2383
|
session,
|
|
1862
|
-
transact(build) {
|
|
1863
|
-
const result = store$1.transact(
|
|
2384
|
+
transact(build, scope = { kind: "body" }) {
|
|
2385
|
+
const result = store$1.transact(scope, build, {
|
|
1864
2386
|
origin: store.ORIGIN_IDS.mutationAgent,
|
|
1865
2387
|
actorId: options.identity.actorId,
|
|
1866
2388
|
recordsHistory: false
|
|
@@ -1893,6 +2415,93 @@ function openRoomStore(options) {
|
|
|
1893
2415
|
throw error;
|
|
1894
2416
|
}
|
|
1895
2417
|
}
|
|
2418
|
+
function roomCommandsPort(room, { revision, actorId } = {}) {
|
|
2419
|
+
const view = () => room.view();
|
|
2420
|
+
const root = () => view().part().root;
|
|
2421
|
+
const numbering = () => documentNumbering({
|
|
2422
|
+
root,
|
|
2423
|
+
stylesRoot: () => view().stylesRoot(),
|
|
2424
|
+
numberingRoot: () => view().numberingRoot(),
|
|
2425
|
+
settingsRoot: () => view().settingsRoot()
|
|
2426
|
+
});
|
|
2427
|
+
let caret = null;
|
|
2428
|
+
const at = () => {
|
|
2429
|
+
if (!caret) throw new Error("No position to write at.");
|
|
2430
|
+
return caret;
|
|
2431
|
+
};
|
|
2432
|
+
const apply = (op) => {
|
|
2433
|
+
const result = room.transact((ctx) => {
|
|
2434
|
+
ctx.apply(op);
|
|
2435
|
+
});
|
|
2436
|
+
if (!result.ok) throw new Error(`The editor refused the change (${op.op}).`);
|
|
2437
|
+
};
|
|
2438
|
+
const find = (node, id) => {
|
|
2439
|
+
if (node.id === id) return node;
|
|
2440
|
+
for (const child of node.children ?? []) {
|
|
2441
|
+
const found = find(child, id);
|
|
2442
|
+
if (found) return found;
|
|
2443
|
+
}
|
|
2444
|
+
return void 0;
|
|
2445
|
+
};
|
|
2446
|
+
return {
|
|
2447
|
+
paragraphs: () => readParagraphs(root()),
|
|
2448
|
+
caret: () => caret,
|
|
2449
|
+
setCaret: (point) => {
|
|
2450
|
+
caret = point;
|
|
2451
|
+
},
|
|
2452
|
+
deleteRange: (from, to) => {
|
|
2453
|
+
if (from.paragraphId !== to.paragraphId) throw new Error("A deletion stays in one paragraph.");
|
|
2454
|
+
apply({
|
|
2455
|
+
op: "deleteText",
|
|
2456
|
+
paragraphId: from.paragraphId,
|
|
2457
|
+
start: from.offset,
|
|
2458
|
+
end: to.offset,
|
|
2459
|
+
...revision ? { revision } : {}
|
|
2460
|
+
});
|
|
2461
|
+
},
|
|
2462
|
+
paste: (body, _text, covered, relationships) => {
|
|
2463
|
+
const point = at();
|
|
2464
|
+
const defined = documentStyleIds(view().stylesRoot());
|
|
2465
|
+
const styles = stylesUsed(body).filter((id) => !defined.has(id));
|
|
2466
|
+
const result = room.store.applyFragmentPaste(
|
|
2467
|
+
{ kind: "body" },
|
|
2468
|
+
{
|
|
2469
|
+
paragraphId: point.paragraphId,
|
|
2470
|
+
offset: point.offset,
|
|
2471
|
+
fragmentBytes: fragmentPackage(body, covered, { revision, relationships, styles }),
|
|
2472
|
+
lastMarkCovered: covered,
|
|
2473
|
+
actorId
|
|
2474
|
+
}
|
|
2475
|
+
);
|
|
2476
|
+
if (result.ok) room.flush();
|
|
2477
|
+
return result.ok;
|
|
2478
|
+
},
|
|
2479
|
+
splitParagraph: () => {
|
|
2480
|
+
const point = at();
|
|
2481
|
+
apply({ op: "splitParagraph", paragraphId: point.paragraphId, offset: point.offset });
|
|
2482
|
+
const paragraphs = readParagraphs(root());
|
|
2483
|
+
const next = paragraphs[paragraphs.findIndex((p) => p.id === point.paragraphId) + 1];
|
|
2484
|
+
caret = next ? { paragraphId: next.id, offset: 0 } : point;
|
|
2485
|
+
},
|
|
2486
|
+
typeText: (text) => {
|
|
2487
|
+
const point = at();
|
|
2488
|
+
apply({
|
|
2489
|
+
op: "insertText",
|
|
2490
|
+
paragraphId: point.paragraphId,
|
|
2491
|
+
offset: point.offset,
|
|
2492
|
+
text,
|
|
2493
|
+
...revision ? { revision } : {}
|
|
2494
|
+
});
|
|
2495
|
+
caret = { paragraphId: point.paragraphId, offset: point.offset + text.length };
|
|
2496
|
+
},
|
|
2497
|
+
listItems: () => numbering().listItems(),
|
|
2498
|
+
levelOf: (numId, ilvl) => numbering().levelOf(numId, ilvl),
|
|
2499
|
+
runsXml: (paragraphId) => {
|
|
2500
|
+
const node = find(root(), paragraphId);
|
|
2501
|
+
return node ? paragraphRunsXml(node) : null;
|
|
2502
|
+
}
|
|
2503
|
+
};
|
|
2504
|
+
}
|
|
1896
2505
|
|
|
1897
2506
|
exports.COLLAB_PROTOCOL = COLLAB_PROTOCOL;
|
|
1898
2507
|
exports.CollaborationCompatibilityError = CollaborationCompatibilityError;
|
|
@@ -1903,6 +2512,7 @@ exports.normalizeDocx = normalizeDocx;
|
|
|
1903
2512
|
exports.openRoomAutomation = openRoomAutomation;
|
|
1904
2513
|
exports.openRoomStore = openRoomStore;
|
|
1905
2514
|
exports.readRoom = readRoom;
|
|
2515
|
+
exports.roomCommandsPort = roomCommandsPort;
|
|
1906
2516
|
exports.seedRoom = seedRoom;
|
|
1907
2517
|
//# sourceMappingURL=server.cjs.map
|
|
1908
2518
|
//# sourceMappingURL=server.cjs.map
|