@arbidocs/blocks 0.4.100 → 0.4.102
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/agents/index.cjs +207 -207
- package/dist/agents/index.js +2 -2
- package/dist/{chunk-NJX774HB.js → chunk-5NQIBJPP.js} +3 -3
- package/dist/{chunk-NJX774HB.js.map → chunk-5NQIBJPP.js.map} +1 -1
- package/dist/chunk-6MG62I5B.cjs +272 -0
- package/dist/chunk-6MG62I5B.cjs.map +1 -0
- package/dist/{chunk-NW3LFDZL.cjs → chunk-DDYXFALG.cjs} +3 -3
- package/dist/{chunk-NW3LFDZL.cjs.map → chunk-DDYXFALG.cjs.map} +1 -1
- package/dist/chunk-EQB3WELX.js +269 -0
- package/dist/chunk-EQB3WELX.js.map +1 -0
- package/dist/{chunk-B7P73VHX.cjs → chunk-FAGQTB3D.cjs} +30 -214
- package/dist/chunk-FAGQTB3D.cjs.map +1 -0
- package/dist/{chunk-6HZNFOHW.js → chunk-G5JH2YMQ.js} +3 -3
- package/dist/{chunk-6HZNFOHW.js.map → chunk-G5JH2YMQ.js.map} +1 -1
- package/dist/{chunk-72PQ42YI.js → chunk-MYALCKDR.js} +34 -217
- package/dist/chunk-MYALCKDR.js.map +1 -0
- package/dist/{chunk-O24WPHLD.cjs → chunk-Y5XW57U4.cjs} +5 -5
- package/dist/{chunk-O24WPHLD.cjs.map → chunk-Y5XW57U4.cjs.map} +1 -1
- package/dist/{chunk-E2QWWLK5.js → chunk-YGREW5TZ.js} +3 -3
- package/dist/{chunk-E2QWWLK5.js.map → chunk-YGREW5TZ.js.map} +1 -1
- package/dist/{chunk-IE55TWIG.cjs → chunk-ZT2EBBSC.cjs} +5 -5
- package/dist/{chunk-IE55TWIG.cjs.map → chunk-ZT2EBBSC.cjs.map} +1 -1
- package/dist/connect/docx.cjs +6 -6
- package/dist/connect/docx.js +4 -4
- package/dist/connect/index.cjs +3 -3
- package/dist/connect/index.js +2 -2
- package/dist/document-tools/AdoptSignatureDialog.d.ts +25 -0
- package/dist/document-tools/DocumentToolButtons.d.ts +2 -0
- package/dist/document-tools/SignatureRequestBanner.d.ts +18 -0
- package/dist/document-tools/index.cjs +175 -0
- package/dist/document-tools/index.cjs.map +1 -1
- package/dist/document-tools/index.d.ts +3 -1
- package/dist/document-tools/index.js +168 -3
- package/dist/document-tools/index.js.map +1 -1
- package/dist/document-tools/viewer/GuidedSigningViewer.d.ts +26 -0
- package/dist/document-tools/viewer/SignatureFieldsOverlay.d.ts +41 -0
- package/dist/document-tools/viewer/SignatureRequestEditor.d.ts +26 -0
- package/dist/document-tools/viewer/index.cjs +983 -0
- package/dist/document-tools/viewer/index.cjs.map +1 -1
- package/dist/document-tools/viewer/index.d.ts +3 -0
- package/dist/document-tools/viewer/index.js +983 -5
- package/dist/document-tools/viewer/index.js.map +1 -1
- package/dist/docx/NativeDocxEditor.d.ts +1 -1
- package/dist/docx/definitions/DefinedTerms.d.ts +1 -12
- package/dist/docx/definitions/commands.d.ts +3 -27
- package/dist/docx/index.cjs +35 -39
- package/dist/docx/index.d.ts +1 -1
- package/dist/docx/index.js +3 -3
- 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/home/index.cjs +1 -1
- package/dist/home/index.js +1 -1
- package/dist/index.cjs +253 -253
- package/dist/index.js +3 -3
- package/dist/shell/index.cjs +1 -1
- package/dist/shell/index.js +1 -1
- package/dist/studio/index.cjs +1 -1
- package/dist/studio/index.js +1 -1
- package/dist/workflow-canvas/index.cjs +9 -9
- package/dist/workflow-canvas/index.js +2 -2
- package/node_modules/@arbidocs/coedit/LICENSE +21 -0
- package/node_modules/@arbidocs/coedit/dist/encoding.cjs +751 -0
- package/node_modules/@arbidocs/coedit/dist/encoding.cjs.map +1 -0
- package/node_modules/@arbidocs/coedit/dist/encoding.d.cts +192 -0
- package/node_modules/@arbidocs/coedit/dist/encoding.d.ts +192 -0
- package/node_modules/@arbidocs/coedit/dist/encoding.js +716 -0
- package/node_modules/@arbidocs/coedit/dist/encoding.js.map +1 -0
- package/node_modules/@arbidocs/coedit/dist/hocuspocus.cjs +1759 -0
- package/node_modules/@arbidocs/coedit/dist/hocuspocus.cjs.map +1 -0
- package/node_modules/@arbidocs/coedit/dist/hocuspocus.d.cts +39 -0
- package/node_modules/@arbidocs/coedit/dist/hocuspocus.d.ts +39 -0
- package/node_modules/@arbidocs/coedit/dist/hocuspocus.js +1736 -0
- package/node_modules/@arbidocs/coedit/dist/hocuspocus.js.map +1 -0
- package/node_modules/@arbidocs/coedit/dist/index.cjs +1692 -0
- package/node_modules/@arbidocs/coedit/dist/index.cjs.map +1 -0
- package/node_modules/@arbidocs/coedit/dist/index.d.cts +16 -0
- package/node_modules/@arbidocs/coedit/dist/index.d.ts +16 -0
- package/node_modules/@arbidocs/coedit/dist/index.js +1664 -0
- package/node_modules/@arbidocs/coedit/dist/index.js.map +1 -0
- package/node_modules/@arbidocs/coedit/dist/server.cjs +1852 -0
- package/node_modules/@arbidocs/coedit/dist/server.cjs.map +1 -0
- package/node_modules/@arbidocs/coedit/dist/server.d.cts +43 -0
- package/node_modules/@arbidocs/coedit/dist/server.d.ts +43 -0
- package/node_modules/@arbidocs/coedit/dist/server.js +1822 -0
- package/node_modules/@arbidocs/coedit/dist/server.js.map +1 -0
- package/node_modules/@arbidocs/coedit/dist/session-Cf9iu1Vt.d.cts +82 -0
- package/node_modules/@arbidocs/coedit/dist/session-Cf9iu1Vt.d.ts +82 -0
- package/node_modules/@arbidocs/coedit/dist/template.cjs +1627 -0
- package/node_modules/@arbidocs/coedit/dist/template.cjs.map +1 -0
- package/node_modules/@arbidocs/coedit/dist/template.d.cts +125 -0
- package/node_modules/@arbidocs/coedit/dist/template.d.ts +125 -0
- package/node_modules/@arbidocs/coedit/dist/template.js +1612 -0
- package/node_modules/@arbidocs/coedit/dist/template.js.map +1 -0
- package/node_modules/@arbidocs/coedit/dist/versions-DXiFQMA6.d.cts +8 -0
- package/node_modules/@arbidocs/coedit/dist/versions-DXiFQMA6.d.ts +8 -0
- package/node_modules/@arbidocs/coedit/package.json +68 -0
- package/node_modules/@docx-editor.dev/core/LICENSE +201 -0
- package/node_modules/@docx-editor.dev/core/README.md +125 -0
- package/node_modules/@docx-editor.dev/core/THIRD_PARTY_NOTICES.md +56 -0
- package/node_modules/@docx-editor.dev/core/dist/automation.cjs +1 -0
- package/node_modules/@docx-editor.dev/core/dist/automation.d.ts +162 -0
- package/node_modules/@docx-editor.dev/core/dist/automation.js +1 -0
- package/node_modules/@docx-editor.dev/core/dist/binding.cjs +1 -0
- package/node_modules/@docx-editor.dev/core/dist/binding.d.ts +164 -0
- package/node_modules/@docx-editor.dev/core/dist/binding.js +1 -0
- package/node_modules/@docx-editor.dev/core/dist/chunk-2GO5T2JU.cjs +1 -0
- package/node_modules/@docx-editor.dev/core/dist/chunk-2RC2EPND.js +3 -0
- package/node_modules/@docx-editor.dev/core/dist/chunk-4GBTELJV.cjs +28 -0
- package/node_modules/@docx-editor.dev/core/dist/chunk-4R3TEXMN.js +18 -0
- package/node_modules/@docx-editor.dev/core/dist/chunk-5CSUYANV.js +1 -0
- package/node_modules/@docx-editor.dev/core/dist/chunk-6APGXLBB.cjs +3 -0
- package/node_modules/@docx-editor.dev/core/dist/chunk-6AWEKBLB.cjs +1 -0
- package/node_modules/@docx-editor.dev/core/dist/chunk-6EYYL7FL.js +1 -0
- package/node_modules/@docx-editor.dev/core/dist/chunk-6JIJOZDW.js +1 -0
- package/node_modules/@docx-editor.dev/core/dist/chunk-BTQKU64Q.cjs +1 -0
- package/node_modules/@docx-editor.dev/core/dist/chunk-E7BQA6UP.js +2 -0
- package/node_modules/@docx-editor.dev/core/dist/chunk-EO4C5QJW.cjs +2 -0
- package/node_modules/@docx-editor.dev/core/dist/chunk-ETTO6GK3.js +1 -0
- package/node_modules/@docx-editor.dev/core/dist/chunk-FIJZIQXA.cjs +18 -0
- package/node_modules/@docx-editor.dev/core/dist/chunk-FRXAOVTB.js +28 -0
- package/node_modules/@docx-editor.dev/core/dist/chunk-J6BVWIDB.js +2 -0
- package/node_modules/@docx-editor.dev/core/dist/chunk-JGNVNT2A.cjs +2 -0
- package/node_modules/@docx-editor.dev/core/dist/chunk-K5U2PLDP.cjs +2 -0
- package/node_modules/@docx-editor.dev/core/dist/chunk-KKIJG3C6.js +2 -0
- package/node_modules/@docx-editor.dev/core/dist/chunk-LWDSDCMO.js +27 -0
- package/node_modules/@docx-editor.dev/core/dist/chunk-NBCVVZOM.cjs +1 -0
- package/node_modules/@docx-editor.dev/core/dist/chunk-O2AL2HSJ.cjs +1 -0
- package/node_modules/@docx-editor.dev/core/dist/chunk-O5INAWZQ.js +1 -0
- package/node_modules/@docx-editor.dev/core/dist/chunk-QMLCVPCD.cjs +1 -0
- package/node_modules/@docx-editor.dev/core/dist/chunk-RCHS4ZEH.cjs +27 -0
- package/node_modules/@docx-editor.dev/core/dist/chunk-RIYSCEFQ.js +2 -0
- package/node_modules/@docx-editor.dev/core/dist/chunk-S6J4O5XP.js +1 -0
- package/node_modules/@docx-editor.dev/core/dist/chunk-SRPILEWV.cjs +5 -0
- package/node_modules/@docx-editor.dev/core/dist/chunk-TSLBZ26X.js +1 -0
- package/node_modules/@docx-editor.dev/core/dist/chunk-UKVVUHZL.cjs +1 -0
- package/node_modules/@docx-editor.dev/core/dist/chunk-VDNNLG6X.js +2 -0
- package/node_modules/@docx-editor.dev/core/dist/chunk-VHAVHCQY.js +7 -0
- package/node_modules/@docx-editor.dev/core/dist/chunk-VX43VBAX.cjs +7 -0
- package/node_modules/@docx-editor.dev/core/dist/chunk-Z6WBFXJU.js +5 -0
- package/node_modules/@docx-editor.dev/core/dist/chunk-ZUHOMK52.cjs +2 -0
- package/node_modules/@docx-editor.dev/core/dist/collaboration/replication.cjs +1 -0
- package/node_modules/@docx-editor.dev/core/dist/collaboration/replication.d.ts +270 -0
- package/node_modules/@docx-editor.dev/core/dist/collaboration/replication.js +1 -0
- package/node_modules/@docx-editor.dev/core/dist/collaboration.cjs +1 -0
- package/node_modules/@docx-editor.dev/core/dist/collaboration.d.ts +269 -0
- package/node_modules/@docx-editor.dev/core/dist/collaboration.js +1 -0
- package/node_modules/@docx-editor.dev/core/dist/contracts/document.cjs +1 -0
- package/node_modules/@docx-editor.dev/core/dist/contracts/document.d.ts +290 -0
- package/node_modules/@docx-editor.dev/core/dist/contracts/document.js +0 -0
- package/node_modules/@docx-editor.dev/core/dist/contracts/editor.cjs +1 -0
- package/node_modules/@docx-editor.dev/core/dist/contracts/editor.d.ts +22 -0
- package/node_modules/@docx-editor.dev/core/dist/contracts/editor.js +1 -0
- package/node_modules/@docx-editor.dev/core/dist/contracts/interaction.cjs +1 -0
- package/node_modules/@docx-editor.dev/core/dist/contracts/interaction.d.ts +103 -0
- package/node_modules/@docx-editor.dev/core/dist/contracts/interaction.js +0 -0
- package/node_modules/@docx-editor.dev/core/dist/contracts/modules.cjs +1 -0
- package/node_modules/@docx-editor.dev/core/dist/contracts/modules.d.ts +143 -0
- package/node_modules/@docx-editor.dev/core/dist/contracts/modules.js +1 -0
- package/node_modules/@docx-editor.dev/core/dist/contracts/types.cjs +1 -0
- package/node_modules/@docx-editor.dev/core/dist/contracts/types.d.ts +11 -0
- package/node_modules/@docx-editor.dev/core/dist/contracts/types.js +0 -0
- package/node_modules/@docx-editor.dev/core/dist/custom-node-writes-cvL5rhcD.d.ts +323 -0
- package/node_modules/@docx-editor.dev/core/dist/dist-PKZR6RSH.js +2 -0
- package/node_modules/@docx-editor.dev/core/dist/document-protection-BAGVGqaP.d.ts +20 -0
- package/node_modules/@docx-editor.dev/core/dist/editor-Ci7IZGmG.d.ts +2448 -0
- package/node_modules/@docx-editor.dev/core/dist/editor-scope-OHPwVQ5l.d.ts +84 -0
- package/node_modules/@docx-editor.dev/core/dist/editor.cjs +1 -0
- package/node_modules/@docx-editor.dev/core/dist/editor.css +15 -0
- package/node_modules/@docx-editor.dev/core/dist/editor.d.ts +1394 -0
- package/node_modules/@docx-editor.dev/core/dist/editor.js +1 -0
- package/node_modules/@docx-editor.dev/core/dist/export.cjs +2 -0
- package/node_modules/@docx-editor.dev/core/dist/export.d.ts +391 -0
- package/node_modules/@docx-editor.dev/core/dist/export.js +2 -0
- package/node_modules/@docx-editor.dev/core/dist/failure-NS2lsya4.d.ts +115 -0
- package/node_modules/@docx-editor.dev/core/dist/font-resolver-BVQB14qT.d.ts +256 -0
- package/node_modules/@docx-editor.dev/core/dist/harfbuzz.wasm +0 -0
- package/node_modules/@docx-editor.dev/core/dist/headless-document-view-qH331moE.d.ts +143 -0
- package/node_modules/@docx-editor.dev/core/dist/image-resources-BN-hUgCn.d.ts +211 -0
- package/node_modules/@docx-editor.dev/core/dist/index-Bsg7oIKP.d.ts +3869 -0
- package/node_modules/@docx-editor.dev/core/dist/index.cjs +1 -0
- package/node_modules/@docx-editor.dev/core/dist/index.d.ts +53 -0
- package/node_modules/@docx-editor.dev/core/dist/index.js +1 -0
- package/node_modules/@docx-editor.dev/core/dist/layout-shaping-BEyuiQOk.d.ts +246 -0
- package/node_modules/@docx-editor.dev/core/dist/layout.cjs +1 -0
- package/node_modules/@docx-editor.dev/core/dist/layout.d.ts +3151 -0
- package/node_modules/@docx-editor.dev/core/dist/layout.js +1 -0
- package/node_modules/@docx-editor.dev/core/dist/node-module-shim-TTKTT66I.js +1 -0
- package/node_modules/@docx-editor.dev/core/dist/note-properties-4Y9o6Gyk.d.ts +68 -0
- package/node_modules/@docx-editor.dev/core/dist/omml-equation-CuzBL5DD.d.ts +85 -0
- package/node_modules/@docx-editor.dev/core/dist/output.cjs +1 -0
- package/node_modules/@docx-editor.dev/core/dist/output.d.ts +97 -0
- package/node_modules/@docx-editor.dev/core/dist/output.js +1 -0
- package/node_modules/@docx-editor.dev/core/dist/protocol-Bqk4Izjc.d.ts +1651 -0
- package/node_modules/@docx-editor.dev/core/dist/review-pane-D9jm8DcY.d.ts +128 -0
- package/node_modules/@docx-editor.dev/core/dist/review-paragraph-order-DT-n6ouC.d.ts +85 -0
- package/node_modules/@docx-editor.dev/core/dist/revision-projection-DZ4kKVev.d.ts +242 -0
- package/node_modules/@docx-editor.dev/core/dist/semantic-cell-selection-D9D1KSXq.d.ts +464 -0
- package/node_modules/@docx-editor.dev/core/dist/semantic-interaction-CIC-PooQ.d.ts +135 -0
- package/node_modules/@docx-editor.dev/core/dist/semantic-paint-BME37OMv.d.ts +326 -0
- package/node_modules/@docx-editor.dev/core/dist/semantic-record-queries-CBlZqZNa.d.ts +177 -0
- package/node_modules/@docx-editor.dev/core/dist/semantic-records-4B3WwFAi.d.ts +3532 -0
- package/node_modules/@docx-editor.dev/core/dist/store.cjs +1 -0
- package/node_modules/@docx-editor.dev/core/dist/store.d.ts +2706 -0
- package/node_modules/@docx-editor.dev/core/dist/store.js +1 -0
- package/node_modules/@docx-editor.dev/core/dist/tree-package-fragment-BeeKxDw8.d.ts +1201 -0
- package/node_modules/@docx-editor.dev/core/dist/tree-session-contract-CVbmlMlq.d.ts +664 -0
- package/node_modules/@docx-editor.dev/core/dist/types-barrel-D3xCgQX6.d.ts +4269 -0
- package/node_modules/@docx-editor.dev/core/licenses/HarfBuzz-COPYING.txt +42 -0
- package/node_modules/@docx-editor.dev/core/package.json +140 -0
- package/node_modules/@docx-editor.dev/react/LICENSE +201 -0
- package/node_modules/@docx-editor.dev/react/README.md +141 -0
- package/node_modules/@docx-editor.dev/react/THIRD_PARTY_NOTICES.md +18 -0
- package/node_modules/@docx-editor.dev/react/dist/index.d.mts +4928 -0
- package/node_modules/@docx-editor.dev/react/dist/index.d.ts +4928 -0
- package/node_modules/@docx-editor.dev/react/dist/index.js +4 -0
- package/node_modules/@docx-editor.dev/react/dist/index.mjs +4 -0
- package/node_modules/@docx-editor.dev/react/package.json +74 -0
- package/node_modules/@docx-editor.dev/react/src/styles/editor.css +6 -0
- package/node_modules/@docx-editor.dev/react/src/styles/zIndex.ts +28 -0
- package/package.json +26 -15
- package/src/docx/README.md +2 -3
- package/dist/chunk-72PQ42YI.js.map +0 -1
- package/dist/chunk-B7P73VHX.cjs.map +0 -1
|
@@ -0,0 +1,1612 @@
|
|
|
1
|
+
import { strToU8, zipSync, strFromU8, unzipSync, zlibSync } from 'fflate';
|
|
2
|
+
import { readXml } from '@docx-editor.dev/core/store';
|
|
3
|
+
|
|
4
|
+
// src/template/pkg.ts
|
|
5
|
+
var W_NS = "http://schemas.openxmlformats.org/wordprocessingml/2006/main";
|
|
6
|
+
var R_NS = "http://schemas.openxmlformats.org/officeDocument/2006/relationships";
|
|
7
|
+
var TemplateError = class extends Error {
|
|
8
|
+
constructor(message) {
|
|
9
|
+
super(message);
|
|
10
|
+
this.name = "TemplateError";
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
function parse(xml, part = "part") {
|
|
14
|
+
const read = readXml(xml, { maxBytes: 64 * 1024 * 1024, maxElements: 2e6 });
|
|
15
|
+
if (!read.ok) throw new TemplateError(`${part} is not readable XML (${read.reason})`);
|
|
16
|
+
const convert = (node) => node.type === "text" ? node.value : { name: node.name, attrs: { ...node.attributes }, children: node.children.map(convert) };
|
|
17
|
+
const root = read.nodes.map(convert).find((n) => typeof n !== "string");
|
|
18
|
+
if (!root) throw new TemplateError(`${part} has no root element`);
|
|
19
|
+
const w = root.attrs["xmlns:w"];
|
|
20
|
+
if (w !== void 0 && w !== W_NS) throw new TemplateError(`${part} binds w: to ${w}`);
|
|
21
|
+
return root;
|
|
22
|
+
}
|
|
23
|
+
var escText = (s) => s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
24
|
+
var escAttr = (s) => escText(s).replace(/"/g, """);
|
|
25
|
+
function serialize(root) {
|
|
26
|
+
const out = ['<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n'];
|
|
27
|
+
const walk2 = (node) => {
|
|
28
|
+
if (typeof node === "string") return void out.push(escText(node));
|
|
29
|
+
out.push("<", node.name);
|
|
30
|
+
for (const [k, v] of Object.entries(node.attrs)) out.push(" ", k, '="', escAttr(v), '"');
|
|
31
|
+
if (node.children.length === 0) return void out.push("/>");
|
|
32
|
+
out.push(">");
|
|
33
|
+
node.children.forEach(walk2);
|
|
34
|
+
out.push("</", node.name, ">");
|
|
35
|
+
};
|
|
36
|
+
walk2(root);
|
|
37
|
+
return out.join("");
|
|
38
|
+
}
|
|
39
|
+
var el = (name, attrs = {}, children = []) => ({
|
|
40
|
+
name,
|
|
41
|
+
attrs,
|
|
42
|
+
children
|
|
43
|
+
});
|
|
44
|
+
var isEl = (n) => typeof n === "object" && n !== null;
|
|
45
|
+
var kids = (e, name) => e.children.filter((c) => isEl(c) && (name === void 0 || c.name === name));
|
|
46
|
+
var kid = (e, name) => e ? kids(e, name)[0] : void 0;
|
|
47
|
+
var val = (e, name) => kid(e, name)?.attrs["w:val"];
|
|
48
|
+
function* walk(e) {
|
|
49
|
+
yield e;
|
|
50
|
+
for (const c of e.children) if (isEl(c)) yield* walk(c);
|
|
51
|
+
}
|
|
52
|
+
var clone = (n) => typeof n === "string" ? n : { name: n.name, attrs: { ...n.attrs }, children: n.children.map(clone) };
|
|
53
|
+
var textOf = (e) => [...walk(e)].filter((x) => x.name === "w:t").map((x) => x.children.filter((c) => typeof c === "string").join("")).join("");
|
|
54
|
+
|
|
55
|
+
// src/template/pkg.ts
|
|
56
|
+
var REL = "http://schemas.openxmlformats.org/officeDocument/2006/relationships";
|
|
57
|
+
var RT = {
|
|
58
|
+
officeDocument: `${REL}/officeDocument`,
|
|
59
|
+
styles: `${REL}/styles`,
|
|
60
|
+
numbering: `${REL}/numbering`,
|
|
61
|
+
theme: `${REL}/theme`,
|
|
62
|
+
fontTable: `${REL}/fontTable`,
|
|
63
|
+
settings: `${REL}/settings`,
|
|
64
|
+
header: `${REL}/header`,
|
|
65
|
+
footer: `${REL}/footer`,
|
|
66
|
+
image: `${REL}/image`,
|
|
67
|
+
glossary: `${REL}/glossaryDocument`,
|
|
68
|
+
attachedTemplate: `${REL}/attachedTemplate`
|
|
69
|
+
};
|
|
70
|
+
var WML = "application/vnd.openxmlformats-officedocument.wordprocessingml";
|
|
71
|
+
var CT = {
|
|
72
|
+
document: `${WML}.document.main+xml`,
|
|
73
|
+
template: `${WML}.template.main+xml`,
|
|
74
|
+
styles: `${WML}.styles+xml`,
|
|
75
|
+
numbering: `${WML}.numbering+xml`,
|
|
76
|
+
settings: `${WML}.settings+xml`,
|
|
77
|
+
fontTable: `${WML}.fontTable+xml`,
|
|
78
|
+
header: `${WML}.header+xml`,
|
|
79
|
+
footer: `${WML}.footer+xml`,
|
|
80
|
+
glossary: `${WML}.document.glossary+xml`,
|
|
81
|
+
theme: "application/vnd.openxmlformats-officedocument.theme+xml",
|
|
82
|
+
rels: "application/vnd.openxmlformats-package.relationships+xml"
|
|
83
|
+
};
|
|
84
|
+
var Pkg = class _Pkg {
|
|
85
|
+
files;
|
|
86
|
+
types;
|
|
87
|
+
constructor(files) {
|
|
88
|
+
this.files = files;
|
|
89
|
+
const ct = this.find("[Content_Types].xml");
|
|
90
|
+
if (!ct) throw new TemplateError("not a Word package: no [Content_Types].xml");
|
|
91
|
+
this.types = parse(strFromU8(files.get(ct)), "[Content_Types].xml");
|
|
92
|
+
}
|
|
93
|
+
static read(bytes) {
|
|
94
|
+
let files;
|
|
95
|
+
try {
|
|
96
|
+
files = unzipSync(bytes);
|
|
97
|
+
} catch {
|
|
98
|
+
throw new TemplateError("not a Word package: not a zip");
|
|
99
|
+
}
|
|
100
|
+
return new _Pkg(new Map(Object.entries(files).filter(([n]) => !n.endsWith("/"))));
|
|
101
|
+
}
|
|
102
|
+
write() {
|
|
103
|
+
this.files.set(
|
|
104
|
+
this.find("[Content_Types].xml") ?? "[Content_Types].xml",
|
|
105
|
+
strToU8(serialize(this.types))
|
|
106
|
+
);
|
|
107
|
+
return zipSync(Object.fromEntries(this.files), { level: 6 });
|
|
108
|
+
}
|
|
109
|
+
/** The stored name of a part, matched case-insensitively as OPC does. */
|
|
110
|
+
find(name) {
|
|
111
|
+
const key = name.replace(/^\//, "").toLowerCase();
|
|
112
|
+
for (const n of this.files.keys()) if (n.toLowerCase() === key) return n;
|
|
113
|
+
return void 0;
|
|
114
|
+
}
|
|
115
|
+
has(name) {
|
|
116
|
+
return this.find(name) !== void 0;
|
|
117
|
+
}
|
|
118
|
+
text(name) {
|
|
119
|
+
const n = this.find(name);
|
|
120
|
+
return n === void 0 ? void 0 : strFromU8(this.files.get(n));
|
|
121
|
+
}
|
|
122
|
+
xml(name) {
|
|
123
|
+
const t = this.text(name);
|
|
124
|
+
return t === void 0 ? void 0 : parse(t, name);
|
|
125
|
+
}
|
|
126
|
+
setXml(name, root, contentType) {
|
|
127
|
+
this.files.set(this.find(name) ?? name, strToU8(serialize(root)));
|
|
128
|
+
if (contentType) this.setContentType(name, contentType);
|
|
129
|
+
}
|
|
130
|
+
setBytes(name, bytes, contentType) {
|
|
131
|
+
this.files.set(this.find(name) ?? name, bytes);
|
|
132
|
+
if (contentType) this.setContentType(name, contentType);
|
|
133
|
+
}
|
|
134
|
+
remove(name) {
|
|
135
|
+
const n = this.find(name);
|
|
136
|
+
if (n === void 0) return;
|
|
137
|
+
this.files.delete(n);
|
|
138
|
+
this.types.children = this.types.children.filter(
|
|
139
|
+
(c) => !(typeof c !== "string" && c.name === "Override" && c.attrs.PartName.toLowerCase() === `/${n.toLowerCase()}`)
|
|
140
|
+
);
|
|
141
|
+
this.files.delete(relsName(n));
|
|
142
|
+
}
|
|
143
|
+
contentType(name) {
|
|
144
|
+
const part = `/${name.replace(/^\//, "")}`.toLowerCase();
|
|
145
|
+
const override = kids(this.types, "Override").find(
|
|
146
|
+
(o) => o.attrs.PartName.toLowerCase() === part
|
|
147
|
+
);
|
|
148
|
+
if (override) return override.attrs.ContentType;
|
|
149
|
+
const ext = part.slice(part.lastIndexOf(".") + 1);
|
|
150
|
+
return kids(this.types, "Default").find((d) => d.attrs.Extension.toLowerCase() === ext)?.attrs.ContentType;
|
|
151
|
+
}
|
|
152
|
+
setContentType(name, type) {
|
|
153
|
+
const part = `/${name.replace(/^\//, "")}`;
|
|
154
|
+
const override = kids(this.types, "Override").find(
|
|
155
|
+
(o) => o.attrs.PartName.toLowerCase() === part.toLowerCase()
|
|
156
|
+
);
|
|
157
|
+
if (override) override.attrs.ContentType = type;
|
|
158
|
+
else this.types.children.push(el("Override", { PartName: part, ContentType: type }));
|
|
159
|
+
}
|
|
160
|
+
/** A `Default` for an extension (media), unless one exists. */
|
|
161
|
+
ensureDefault(ext, type) {
|
|
162
|
+
if (!kids(this.types, "Default").some(
|
|
163
|
+
(d) => d.attrs.Extension.toLowerCase() === ext.toLowerCase()
|
|
164
|
+
))
|
|
165
|
+
this.types.children.unshift(el("Default", { Extension: ext, ContentType: type }));
|
|
166
|
+
}
|
|
167
|
+
rels(owner) {
|
|
168
|
+
const root = this.xml(relsName(owner));
|
|
169
|
+
if (!root) return [];
|
|
170
|
+
return kids(root, "Relationship").map((r) => ({
|
|
171
|
+
id: r.attrs.Id,
|
|
172
|
+
type: r.attrs.Type,
|
|
173
|
+
target: r.attrs.Target,
|
|
174
|
+
external: r.attrs.TargetMode === "External"
|
|
175
|
+
}));
|
|
176
|
+
}
|
|
177
|
+
setRels(owner, rels) {
|
|
178
|
+
const root = el(
|
|
179
|
+
"Relationships",
|
|
180
|
+
{ xmlns: "http://schemas.openxmlformats.org/package/2006/relationships" },
|
|
181
|
+
rels.map(
|
|
182
|
+
(r) => el("Relationship", {
|
|
183
|
+
Id: r.id,
|
|
184
|
+
Type: r.type,
|
|
185
|
+
Target: r.target,
|
|
186
|
+
...r.external ? { TargetMode: "External" } : {}
|
|
187
|
+
})
|
|
188
|
+
)
|
|
189
|
+
);
|
|
190
|
+
this.setXml(relsName(owner), root);
|
|
191
|
+
}
|
|
192
|
+
/** Add a relationship from `owner`; returns its new id. */
|
|
193
|
+
addRel(owner, type, target, external = false) {
|
|
194
|
+
const rels = this.rels(owner);
|
|
195
|
+
const id = freshId(new Set(rels.map((r) => r.id)), "rIdT");
|
|
196
|
+
rels.push({ id, type, target, external });
|
|
197
|
+
this.setRels(owner, rels);
|
|
198
|
+
return id;
|
|
199
|
+
}
|
|
200
|
+
/** The part a relationship of `owner` points at (internal targets only). */
|
|
201
|
+
target(owner, rel) {
|
|
202
|
+
return resolveTarget(owner, rel.target);
|
|
203
|
+
}
|
|
204
|
+
/** The first internal part of a relationship type from `owner`. */
|
|
205
|
+
partOf(owner, type) {
|
|
206
|
+
const rel = this.rels(owner).find((r) => r.type === type && !r.external);
|
|
207
|
+
return rel && this.find(this.target(owner, rel));
|
|
208
|
+
}
|
|
209
|
+
/** The main document part (`word/document.xml` by convention). */
|
|
210
|
+
get main() {
|
|
211
|
+
const main = this.partOf("", RT.officeDocument);
|
|
212
|
+
if (!main) throw new TemplateError("not a Word package: no main document part");
|
|
213
|
+
return main;
|
|
214
|
+
}
|
|
215
|
+
};
|
|
216
|
+
function relsName(owner) {
|
|
217
|
+
const slash = owner.lastIndexOf("/");
|
|
218
|
+
return `${owner.slice(0, slash + 1)}_rels/${owner.slice(slash + 1)}.rels`;
|
|
219
|
+
}
|
|
220
|
+
function resolveTarget(owner, target) {
|
|
221
|
+
if (target.startsWith("/")) return target.slice(1);
|
|
222
|
+
const base = owner.slice(0, owner.lastIndexOf("/") + 1).split("/").filter(Boolean);
|
|
223
|
+
for (const seg of target.split("/")) {
|
|
224
|
+
if (seg === "..") base.pop();
|
|
225
|
+
else if (seg !== "." && seg !== "") base.push(seg);
|
|
226
|
+
}
|
|
227
|
+
return base.join("/");
|
|
228
|
+
}
|
|
229
|
+
function relativeTarget(owner, part) {
|
|
230
|
+
const from = owner.slice(0, owner.lastIndexOf("/") + 1);
|
|
231
|
+
return part.startsWith(from) ? part.slice(from.length) : `/${part}`;
|
|
232
|
+
}
|
|
233
|
+
function freshId(taken, prefix) {
|
|
234
|
+
for (let i = 1; ; i++) if (!taken.has(`${prefix}${i}`)) return `${prefix}${i}`;
|
|
235
|
+
}
|
|
236
|
+
function freshPartName(pkg, folder, stem, ext) {
|
|
237
|
+
for (let i = 1; ; i++) {
|
|
238
|
+
const name = `${folder}${stem}${i}.${ext}`;
|
|
239
|
+
if (!pkg.has(name)) return name;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
// src/template/merge.ts
|
|
244
|
+
var nameKey = (s) => s.trim().toLowerCase();
|
|
245
|
+
var SETTINGS_ORDER = [
|
|
246
|
+
"w:writeProtection",
|
|
247
|
+
"w:view",
|
|
248
|
+
"w:zoom",
|
|
249
|
+
"w:removePersonalInformation",
|
|
250
|
+
"w:removeDateAndTime",
|
|
251
|
+
"w:doNotDisplayPageBoundaries",
|
|
252
|
+
"w:displayBackgroundShape",
|
|
253
|
+
"w:printPostScriptOverText",
|
|
254
|
+
"w:printFractionalCharacterWidth",
|
|
255
|
+
"w:printFormsData",
|
|
256
|
+
"w:embedTrueTypeFonts",
|
|
257
|
+
"w:embedSystemFonts",
|
|
258
|
+
"w:saveSubsetFonts",
|
|
259
|
+
"w:saveFormsData",
|
|
260
|
+
"w:mirrorMargins",
|
|
261
|
+
"w:alignBordersAndEdges",
|
|
262
|
+
"w:bordersDoNotSurroundHeader",
|
|
263
|
+
"w:bordersDoNotSurroundFooter",
|
|
264
|
+
"w:gutterAtTop",
|
|
265
|
+
"w:hideSpellingErrors",
|
|
266
|
+
"w:hideGrammaticalErrors",
|
|
267
|
+
"w:activeWritingStyle",
|
|
268
|
+
"w:proofState",
|
|
269
|
+
"w:formsDesign",
|
|
270
|
+
"w:attachedTemplate",
|
|
271
|
+
"w:linkStyles",
|
|
272
|
+
"w:stylePaneFormatFilter",
|
|
273
|
+
"w:stylePaneSortMethod",
|
|
274
|
+
"w:documentType",
|
|
275
|
+
"w:mailMerge",
|
|
276
|
+
"w:revisionView",
|
|
277
|
+
"w:trackRevisions",
|
|
278
|
+
"w:doNotTrackMoves",
|
|
279
|
+
"w:doNotTrackFormatting",
|
|
280
|
+
"w:documentProtection",
|
|
281
|
+
"w:autoFormatOverride",
|
|
282
|
+
"w:styleLockTheme",
|
|
283
|
+
"w:styleLockQFSet",
|
|
284
|
+
"w:defaultTabStop",
|
|
285
|
+
"w:autoHyphenation",
|
|
286
|
+
"w:consecutiveHyphenLimit",
|
|
287
|
+
"w:hyphenationZone",
|
|
288
|
+
"w:doNotHyphenateCaps",
|
|
289
|
+
"w:showEnvelope",
|
|
290
|
+
"w:summaryLength",
|
|
291
|
+
"w:clickAndTypeStyle",
|
|
292
|
+
"w:defaultTableStyle",
|
|
293
|
+
"w:evenAndOddHeaders",
|
|
294
|
+
"w:bookFoldRevPrinting",
|
|
295
|
+
"w:bookFoldPrinting",
|
|
296
|
+
"w:bookFoldPrintingSheets",
|
|
297
|
+
"w:drawingGridHorizontalSpacing",
|
|
298
|
+
"w:drawingGridVerticalSpacing",
|
|
299
|
+
"w:displayHorizontalDrawingGridEvery",
|
|
300
|
+
"w:displayVerticalDrawingGridEvery",
|
|
301
|
+
"w:doNotUseMarginsForDrawingGridOrigin",
|
|
302
|
+
"w:drawingGridHorizontalOrigin",
|
|
303
|
+
"w:drawingGridVerticalOrigin",
|
|
304
|
+
"w:doNotShadeFormData",
|
|
305
|
+
"w:noPunctuationKerning",
|
|
306
|
+
"w:characterSpacingControl",
|
|
307
|
+
"w:printTwoOnOne",
|
|
308
|
+
"w:strictFirstAndLastChars",
|
|
309
|
+
"w:noLineBreaksAfter",
|
|
310
|
+
"w:noLineBreaksBefore",
|
|
311
|
+
"w:savePreviewPicture",
|
|
312
|
+
"w:doNotValidateAgainstSchema",
|
|
313
|
+
"w:saveInvalidXml",
|
|
314
|
+
"w:ignoreMixedContent",
|
|
315
|
+
"w:alwaysShowPlaceholderText",
|
|
316
|
+
"w:doNotDemarcateInvalidXml",
|
|
317
|
+
"w:saveXmlDataOnly",
|
|
318
|
+
"w:useXSLTWhenSaving",
|
|
319
|
+
"w:saveThroughXslt",
|
|
320
|
+
"w:showXMLTags",
|
|
321
|
+
"w:alwaysMergeEmptyNamespace",
|
|
322
|
+
"w:updateFields",
|
|
323
|
+
"w:hdrShapeDefaults",
|
|
324
|
+
"w:footnotePr",
|
|
325
|
+
"w:endnotePr",
|
|
326
|
+
"w:compat",
|
|
327
|
+
"w:docVars",
|
|
328
|
+
"w:rsids",
|
|
329
|
+
"m:mathPr",
|
|
330
|
+
"w:attachedSchema",
|
|
331
|
+
"w:themeFontLang",
|
|
332
|
+
"w:clrSchemeMapping",
|
|
333
|
+
"w:doNotIncludeSubdocsInStats",
|
|
334
|
+
"w:doNotAutoCompressPictures",
|
|
335
|
+
"w:forceUpgrade",
|
|
336
|
+
"w:captions",
|
|
337
|
+
"w:readModeInkLockDown",
|
|
338
|
+
"w:smartTagType",
|
|
339
|
+
"sl:schemaLibrary",
|
|
340
|
+
"w:shapeDefaults",
|
|
341
|
+
"w:doNotEmbedSmartTags",
|
|
342
|
+
"w:decimalSymbol",
|
|
343
|
+
"w:listSeparator"
|
|
344
|
+
];
|
|
345
|
+
function placeOrdered(parent, child, order) {
|
|
346
|
+
const at = parent.children.findIndex((c) => isEl(c) && c.name === child.name);
|
|
347
|
+
if (at >= 0) return void (parent.children[at] = child);
|
|
348
|
+
const rank = order.indexOf(child.name);
|
|
349
|
+
const before = parent.children.findIndex(
|
|
350
|
+
(c) => isEl(c) && rank >= 0 && order.indexOf(c.name) > rank
|
|
351
|
+
);
|
|
352
|
+
if (before < 0) parent.children.push(child);
|
|
353
|
+
else parent.children.splice(before, 0, child);
|
|
354
|
+
}
|
|
355
|
+
var TEMPLATE_SETTINGS = [
|
|
356
|
+
"w:defaultTabStop",
|
|
357
|
+
"w:characterSpacingControl",
|
|
358
|
+
"w:compat",
|
|
359
|
+
"w:themeFontLang",
|
|
360
|
+
"w:clrSchemeMapping",
|
|
361
|
+
"w:hyphenationZone",
|
|
362
|
+
"w:autoHyphenation",
|
|
363
|
+
"w:defaultTableStyle"
|
|
364
|
+
];
|
|
365
|
+
var W_DOC_ATTRS = { "xmlns:w": W_NS, "xmlns:r": R_NS };
|
|
366
|
+
function ensurePart(pkg, type, name, contentType, root) {
|
|
367
|
+
const existing = pkg.partOf(pkg.main, type);
|
|
368
|
+
if (existing) return existing;
|
|
369
|
+
const part = pkg.has(name) ? freshPartName(pkg, "word/", name.replace(/^word\/|\d*\.xml$/g, ""), "xml") : name;
|
|
370
|
+
pkg.setXml(part, root(), contentType);
|
|
371
|
+
pkg.addRel(pkg.main, type, relativeTarget(pkg.main, part));
|
|
372
|
+
return part;
|
|
373
|
+
}
|
|
374
|
+
function indexStyles(styles) {
|
|
375
|
+
const byId = /* @__PURE__ */ new Map();
|
|
376
|
+
const byName = /* @__PURE__ */ new Map();
|
|
377
|
+
for (const s of kids(styles, "w:style")) {
|
|
378
|
+
const id = s.attrs["w:styleId"];
|
|
379
|
+
if (!id) continue;
|
|
380
|
+
byId.set(id, s);
|
|
381
|
+
const keys = [val(s, "w:name"), ...val(s, "w:aliases")?.split(",") ?? []];
|
|
382
|
+
for (const k of keys) if (k) byName.set(`${s.attrs["w:type"]}:${nameKey(k)}`, s);
|
|
383
|
+
}
|
|
384
|
+
return { byId, byName };
|
|
385
|
+
}
|
|
386
|
+
var STYLE_REFS = [
|
|
387
|
+
"w:basedOn",
|
|
388
|
+
"w:next",
|
|
389
|
+
"w:link",
|
|
390
|
+
"w:pStyle",
|
|
391
|
+
"w:rStyle",
|
|
392
|
+
"w:tblStyle",
|
|
393
|
+
"w:numStyleLink",
|
|
394
|
+
"w:styleLink"
|
|
395
|
+
];
|
|
396
|
+
function renameStyleRefs(root, map) {
|
|
397
|
+
if (map.size === 0) return;
|
|
398
|
+
for (const e of walk(root))
|
|
399
|
+
if (STYLE_REFS.includes(e.name) && map.has(e.attrs["w:val"]))
|
|
400
|
+
e.attrs["w:val"] = map.get(e.attrs["w:val"]);
|
|
401
|
+
}
|
|
402
|
+
var numIdsIn = (root) => [...walk(root)].filter((e) => e.name === "w:numId").map((e) => e.attrs["w:val"]);
|
|
403
|
+
function maxId(nodes, attr) {
|
|
404
|
+
return nodes.reduce((m, n) => Math.max(m, Number(n.attrs[attr]) || 0), 0);
|
|
405
|
+
}
|
|
406
|
+
function importNumbering(from, into, numIds, styleNumId) {
|
|
407
|
+
const map = /* @__PURE__ */ new Map();
|
|
408
|
+
if (!from) return map;
|
|
409
|
+
const nums = new Map(kids(from, "w:num").map((n) => [n.attrs["w:numId"], n]));
|
|
410
|
+
const abstracts = new Map(kids(from, "w:abstractNum").map((a) => [a.attrs["w:abstractNumId"], a]));
|
|
411
|
+
const abstractMap = /* @__PURE__ */ new Map();
|
|
412
|
+
let nextNum = maxId(kids(into, "w:num"), "w:numId") + 1;
|
|
413
|
+
let nextAbstract = maxId(kids(into, "w:abstractNum"), "w:abstractNumId") + 1;
|
|
414
|
+
const nsids = new Set(kids(into, "w:abstractNum").map((a) => val(a, "w:nsid")));
|
|
415
|
+
const queue = [...numIds];
|
|
416
|
+
while (queue.length) {
|
|
417
|
+
const id = queue.shift();
|
|
418
|
+
if (map.has(id) || id === "0") continue;
|
|
419
|
+
const num = nums.get(id);
|
|
420
|
+
if (!num) continue;
|
|
421
|
+
const absId = val(num, "w:abstractNumId");
|
|
422
|
+
if (absId !== void 0 && !abstractMap.has(absId)) {
|
|
423
|
+
const abs = abstracts.get(absId);
|
|
424
|
+
if (abs) {
|
|
425
|
+
const copy2 = clone(abs);
|
|
426
|
+
copy2.attrs["w:abstractNumId"] = String(nextAbstract);
|
|
427
|
+
abstractMap.set(absId, String(nextAbstract++));
|
|
428
|
+
const nsid = kid(copy2, "w:nsid");
|
|
429
|
+
if (nsid && nsids.has(nsid.attrs["w:val"])) {
|
|
430
|
+
let n = (parseInt(nsid.attrs["w:val"], 16) || 268435456) + 1;
|
|
431
|
+
while (nsids.has(n.toString(16).toUpperCase().padStart(8, "0"))) n++;
|
|
432
|
+
nsid.attrs["w:val"] = n.toString(16).toUpperCase().padStart(8, "0");
|
|
433
|
+
}
|
|
434
|
+
if (nsid) nsids.add(nsid.attrs["w:val"]);
|
|
435
|
+
for (const l of kids(copy2, "w:lvl"))
|
|
436
|
+
l.children = l.children.filter((c) => !(isEl(c) && c.name === "w:lvlPicBulletId"));
|
|
437
|
+
const firstNum = into.children.findIndex(
|
|
438
|
+
(c) => isEl(c) && (c.name === "w:num" || c.name === "w:numIdMacAtCleanup")
|
|
439
|
+
);
|
|
440
|
+
if (firstNum < 0) into.children.push(copy2);
|
|
441
|
+
else into.children.splice(firstNum, 0, copy2);
|
|
442
|
+
const link = val(copy2, "w:numStyleLink");
|
|
443
|
+
const linked = link ? styleNumId(link) : void 0;
|
|
444
|
+
if (linked) queue.push(linked);
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
const copy = clone(num);
|
|
448
|
+
copy.attrs["w:numId"] = String(nextNum);
|
|
449
|
+
map.set(id, String(nextNum++));
|
|
450
|
+
const absRef = kid(copy, "w:abstractNumId");
|
|
451
|
+
if (absRef && abstractMap.has(absRef.attrs["w:val"]))
|
|
452
|
+
absRef.attrs["w:val"] = abstractMap.get(absRef.attrs["w:val"]);
|
|
453
|
+
const cleanup = into.children.findIndex((c) => isEl(c) && c.name === "w:numIdMacAtCleanup");
|
|
454
|
+
if (cleanup < 0) into.children.push(copy);
|
|
455
|
+
else into.children.splice(cleanup, 0, copy);
|
|
456
|
+
}
|
|
457
|
+
return map;
|
|
458
|
+
}
|
|
459
|
+
function applyStyles(doc, tpl, report) {
|
|
460
|
+
const tplStylesPart = tpl.partOf(tpl.main, RT.styles);
|
|
461
|
+
if (!tplStylesPart) return;
|
|
462
|
+
const T = tpl.xml(tplStylesPart);
|
|
463
|
+
const stylesPart = ensurePart(
|
|
464
|
+
doc,
|
|
465
|
+
RT.styles,
|
|
466
|
+
"word/styles.xml",
|
|
467
|
+
CT.styles,
|
|
468
|
+
() => el("w:styles", { ...W_DOC_ATTRS })
|
|
469
|
+
);
|
|
470
|
+
const D = doc.xml(stylesPart);
|
|
471
|
+
for (const [k, v] of Object.entries(T.attrs))
|
|
472
|
+
if (k.startsWith("xmlns:") && !(k in D.attrs)) D.attrs[k] = v;
|
|
473
|
+
for (const name of ["w:latentStyles", "w:docDefaults"]) {
|
|
474
|
+
const t = kid(T, name);
|
|
475
|
+
if (!t) continue;
|
|
476
|
+
const at = D.children.findIndex((c) => isEl(c) && c.name === name);
|
|
477
|
+
if (at >= 0) D.children[at] = clone(t);
|
|
478
|
+
else D.children.unshift(clone(t));
|
|
479
|
+
}
|
|
480
|
+
const dd = kid(D, "w:docDefaults");
|
|
481
|
+
const ls = kid(D, "w:latentStyles");
|
|
482
|
+
D.children = D.children.filter((c) => c !== dd && c !== ls);
|
|
483
|
+
D.children.unshift(...[dd, ls].filter(Boolean));
|
|
484
|
+
const dIndex = indexStyles(D);
|
|
485
|
+
const rename = /* @__PURE__ */ new Map();
|
|
486
|
+
for (const s of kids(T, "w:style")) {
|
|
487
|
+
const id = s.attrs["w:styleId"];
|
|
488
|
+
if (dIndex.byId.has(id)) continue;
|
|
489
|
+
const name = val(s, "w:name");
|
|
490
|
+
const match = name && dIndex.byName.get(`${s.attrs["w:type"]}:${nameKey(name)}`);
|
|
491
|
+
if (match && !kids(T, "w:style").some((o) => o.attrs["w:styleId"] === match.attrs["w:styleId"]))
|
|
492
|
+
rename.set(id, match.attrs["w:styleId"]);
|
|
493
|
+
}
|
|
494
|
+
const imported = kids(T, "w:style").map((s) => {
|
|
495
|
+
const copy = clone(s);
|
|
496
|
+
if (rename.has(copy.attrs["w:styleId"]))
|
|
497
|
+
copy.attrs["w:styleId"] = rename.get(copy.attrs["w:styleId"]);
|
|
498
|
+
renameStyleRefs(copy, rename);
|
|
499
|
+
return copy;
|
|
500
|
+
});
|
|
501
|
+
const tplNumbering = tpl.partOf(tpl.main, RT.numbering);
|
|
502
|
+
const T_num = tplNumbering ? tpl.xml(tplNumbering) : void 0;
|
|
503
|
+
const wanted = imported.flatMap(numIdsIn);
|
|
504
|
+
let numMap = /* @__PURE__ */ new Map();
|
|
505
|
+
if (T_num && wanted.length) {
|
|
506
|
+
const numberingPart = ensurePart(
|
|
507
|
+
doc,
|
|
508
|
+
RT.numbering,
|
|
509
|
+
"word/numbering.xml",
|
|
510
|
+
CT.numbering,
|
|
511
|
+
() => el("w:numbering", { ...W_DOC_ATTRS })
|
|
512
|
+
);
|
|
513
|
+
const D_num = doc.xml(numberingPart);
|
|
514
|
+
const tplStyleNum = (sid) => {
|
|
515
|
+
const st = kids(T, "w:style").find((s) => s.attrs["w:styleId"] === sid);
|
|
516
|
+
return st ? numIdsIn(st)[0] : void 0;
|
|
517
|
+
};
|
|
518
|
+
numMap = importNumbering(T_num, D_num, wanted, tplStyleNum);
|
|
519
|
+
for (const abs of kids(D_num, "w:abstractNum")) renameStyleRefs(abs, rename);
|
|
520
|
+
doc.setXml(numberingPart, D_num);
|
|
521
|
+
}
|
|
522
|
+
for (const s of imported)
|
|
523
|
+
for (const e of walk(s))
|
|
524
|
+
if (e.name === "w:numId" && numMap.has(e.attrs["w:val"]))
|
|
525
|
+
e.attrs["w:val"] = numMap.get(e.attrs["w:val"]);
|
|
526
|
+
for (const s of imported) {
|
|
527
|
+
const id = s.attrs["w:styleId"];
|
|
528
|
+
const at = D.children.findIndex(
|
|
529
|
+
(c) => isEl(c) && c.name === "w:style" && c.attrs["w:styleId"] === id
|
|
530
|
+
);
|
|
531
|
+
if (at >= 0) D.children[at] = s;
|
|
532
|
+
else D.children.push(s);
|
|
533
|
+
}
|
|
534
|
+
for (const s of imported)
|
|
535
|
+
if (s.attrs["w:default"] === "1" || s.attrs["w:default"] === "true") {
|
|
536
|
+
for (const o of kids(D, "w:style"))
|
|
537
|
+
if (o !== s && o.attrs["w:type"] === s.attrs["w:type"] && o.attrs["w:default"])
|
|
538
|
+
delete o.attrs["w:default"];
|
|
539
|
+
}
|
|
540
|
+
doc.setXml(stylesPart, D);
|
|
541
|
+
report.styles = imported.map((s) => s.attrs["w:styleId"]);
|
|
542
|
+
report.renamed = Object.fromEntries(rename);
|
|
543
|
+
report.numbering = Object.fromEntries(numMap);
|
|
544
|
+
}
|
|
545
|
+
function applyTheme(doc, tpl) {
|
|
546
|
+
const t = tpl.partOf(tpl.main, RT.theme);
|
|
547
|
+
if (!t) return;
|
|
548
|
+
const bytes = tpl.files.get(t);
|
|
549
|
+
const d = doc.partOf(doc.main, RT.theme);
|
|
550
|
+
if (d) return void doc.setBytes(d, bytes);
|
|
551
|
+
const name = doc.has("word/theme/theme1.xml") ? freshPartName(doc, "word/theme/", "theme", "xml") : "word/theme/theme1.xml";
|
|
552
|
+
doc.setBytes(name, bytes, CT.theme);
|
|
553
|
+
doc.addRel(doc.main, RT.theme, relativeTarget(doc.main, name));
|
|
554
|
+
}
|
|
555
|
+
function applyFonts(doc, tpl) {
|
|
556
|
+
const t = tpl.partOf(tpl.main, RT.fontTable);
|
|
557
|
+
if (!t) return;
|
|
558
|
+
const T = tpl.xml(t);
|
|
559
|
+
const part = ensurePart(
|
|
560
|
+
doc,
|
|
561
|
+
RT.fontTable,
|
|
562
|
+
"word/fontTable.xml",
|
|
563
|
+
CT.fontTable,
|
|
564
|
+
() => el("w:fonts", { ...W_DOC_ATTRS })
|
|
565
|
+
);
|
|
566
|
+
const D = doc.xml(part);
|
|
567
|
+
for (const f of kids(T, "w:font")) {
|
|
568
|
+
const copy = clone(f);
|
|
569
|
+
copy.children = copy.children.filter((c) => !(isEl(c) && /^w:embed/.test(c.name)));
|
|
570
|
+
const at = D.children.findIndex(
|
|
571
|
+
(c) => isEl(c) && c.name === "w:font" && c.attrs["w:name"] === f.attrs["w:name"]
|
|
572
|
+
);
|
|
573
|
+
if (at >= 0) D.children[at] = copy;
|
|
574
|
+
else D.children.push(copy);
|
|
575
|
+
}
|
|
576
|
+
doc.setXml(part, D);
|
|
577
|
+
}
|
|
578
|
+
function settingsOf(pkg) {
|
|
579
|
+
const part = ensurePart(
|
|
580
|
+
pkg,
|
|
581
|
+
RT.settings,
|
|
582
|
+
"word/settings.xml",
|
|
583
|
+
CT.settings,
|
|
584
|
+
() => el("w:settings", { ...W_DOC_ATTRS })
|
|
585
|
+
);
|
|
586
|
+
return { part, root: pkg.xml(part) };
|
|
587
|
+
}
|
|
588
|
+
function applySettings(doc, tpl, opts) {
|
|
589
|
+
const tPart = tpl.partOf(tpl.main, RT.settings);
|
|
590
|
+
const T = tPart ? tpl.xml(tPart) : void 0;
|
|
591
|
+
const { part, root } = settingsOf(doc);
|
|
592
|
+
if (T)
|
|
593
|
+
for (const name of TEMPLATE_SETTINGS) {
|
|
594
|
+
const t = kid(T, name);
|
|
595
|
+
if (t) placeOrdered(root, clone(t), SETTINGS_ORDER);
|
|
596
|
+
}
|
|
597
|
+
if (opts.furniture && T) {
|
|
598
|
+
const even = kid(T, "w:evenAndOddHeaders");
|
|
599
|
+
root.children = root.children.filter((c) => !(isEl(c) && c.name === "w:evenAndOddHeaders"));
|
|
600
|
+
if (even) placeOrdered(root, clone(even), SETTINGS_ORDER);
|
|
601
|
+
}
|
|
602
|
+
if (opts.attachedTemplate) {
|
|
603
|
+
if (!root.attrs["xmlns:r"]) root.attrs["xmlns:r"] = R_NS;
|
|
604
|
+
const rels = doc.rels(part).filter((r) => r.type !== RT.attachedTemplate);
|
|
605
|
+
doc.setRels(part, rels);
|
|
606
|
+
const id = doc.addRel(part, RT.attachedTemplate, encodeURI(opts.attachedTemplate), true);
|
|
607
|
+
placeOrdered(root, el("w:attachedTemplate", { "r:id": id }), SETTINGS_ORDER);
|
|
608
|
+
}
|
|
609
|
+
doc.setXml(part, root);
|
|
610
|
+
}
|
|
611
|
+
function copyPart(doc, tpl, source, stem) {
|
|
612
|
+
const ext = source.slice(source.lastIndexOf(".") + 1);
|
|
613
|
+
const folder = source.slice(0, source.lastIndexOf("/") + 1);
|
|
614
|
+
const name = freshPartName(doc, folder, stem, ext);
|
|
615
|
+
doc.setBytes(name, tpl.files.get(source), tpl.contentType(source));
|
|
616
|
+
const rels = tpl.rels(source).map((r) => {
|
|
617
|
+
if (r.external) return { ...r };
|
|
618
|
+
const target = tpl.find(tpl.target(source, r));
|
|
619
|
+
if (!target) return { ...r };
|
|
620
|
+
const tExt = target.slice(target.lastIndexOf(".") + 1);
|
|
621
|
+
const tFolder = target.slice(0, target.lastIndexOf("/") + 1);
|
|
622
|
+
const tStem = target.slice(tFolder.length, target.length - tExt.length - 1).replace(/\d+$/, "");
|
|
623
|
+
const copied = freshPartName(doc, tFolder, tStem || "part", tExt);
|
|
624
|
+
doc.setBytes(copied, tpl.files.get(target));
|
|
625
|
+
const type = tpl.contentType(target);
|
|
626
|
+
if (type) {
|
|
627
|
+
if (/^(image|video|audio)\//.test(type)) doc.ensureDefault(tExt, type);
|
|
628
|
+
else doc.setContentType(copied, type);
|
|
629
|
+
}
|
|
630
|
+
return { ...r, target: relativeTarget(name, copied) };
|
|
631
|
+
});
|
|
632
|
+
if (rels.length) doc.setRels(name, rels);
|
|
633
|
+
return name;
|
|
634
|
+
}
|
|
635
|
+
function finalSectPr(body) {
|
|
636
|
+
return kid(body, "w:sectPr");
|
|
637
|
+
}
|
|
638
|
+
function applyFurniture(doc, tpl) {
|
|
639
|
+
const tDoc = tpl.xml(tpl.main);
|
|
640
|
+
const tSect = finalSectPr(kid(tDoc, "w:body"));
|
|
641
|
+
if (!tSect) return;
|
|
642
|
+
const dRoot = doc.xml(doc.main);
|
|
643
|
+
const body = kid(dRoot, "w:body");
|
|
644
|
+
if (!body) throw new TemplateError("the document has no body");
|
|
645
|
+
for (const [k, v] of Object.entries(tDoc.attrs))
|
|
646
|
+
if (k.startsWith("xmlns:") && !(k in dRoot.attrs)) dRoot.attrs[k] = v;
|
|
647
|
+
const old = finalSectPr(body);
|
|
648
|
+
const oldIds = old ? kids(old).filter((c) => c.name === "w:headerReference" || c.name === "w:footerReference").map((c) => c.attrs["r:id"]) : [];
|
|
649
|
+
const stillUsed = new Set(
|
|
650
|
+
[...walk(body)].filter(
|
|
651
|
+
(e) => e !== old && (e.name === "w:headerReference" || e.name === "w:footerReference")
|
|
652
|
+
).filter((e) => !old || ![...walk(old)].includes(e)).map((e) => e.attrs["r:id"])
|
|
653
|
+
);
|
|
654
|
+
const sect = clone(tSect);
|
|
655
|
+
for (const ref of kids(sect)) {
|
|
656
|
+
if (ref.name !== "w:headerReference" && ref.name !== "w:footerReference") continue;
|
|
657
|
+
const rel = tpl.rels(tpl.main).find((r) => r.id === ref.attrs["r:id"]);
|
|
658
|
+
const source = rel && tpl.find(tpl.target(tpl.main, rel));
|
|
659
|
+
if (!rel || !source) {
|
|
660
|
+
sect.children.splice(sect.children.indexOf(ref), 1);
|
|
661
|
+
continue;
|
|
662
|
+
}
|
|
663
|
+
const copied = copyPart(
|
|
664
|
+
doc,
|
|
665
|
+
tpl,
|
|
666
|
+
source,
|
|
667
|
+
ref.name === "w:headerReference" ? "header" : "footer"
|
|
668
|
+
);
|
|
669
|
+
ref.attrs["r:id"] = doc.addRel(doc.main, rel.type, relativeTarget(doc.main, copied));
|
|
670
|
+
}
|
|
671
|
+
if (old) body.children[body.children.indexOf(old)] = sect;
|
|
672
|
+
else body.children.push(sect);
|
|
673
|
+
const rels = doc.rels(doc.main);
|
|
674
|
+
for (const id of oldIds) {
|
|
675
|
+
if (stillUsed.has(id)) continue;
|
|
676
|
+
const rel = rels.find((r) => r.id === id);
|
|
677
|
+
if (!rel) continue;
|
|
678
|
+
doc.remove(doc.target(doc.main, rel));
|
|
679
|
+
rels.splice(rels.indexOf(rel), 1);
|
|
680
|
+
}
|
|
681
|
+
doc.setRels(doc.main, rels);
|
|
682
|
+
doc.setXml(doc.main, dRoot);
|
|
683
|
+
}
|
|
684
|
+
function applyTemplate(document, template, options = {}) {
|
|
685
|
+
const doc = Pkg.read(document);
|
|
686
|
+
const tpl = Pkg.read(template);
|
|
687
|
+
const report = { styles: [], renamed: {}, numbering: {} };
|
|
688
|
+
applyStyles(doc, tpl, report);
|
|
689
|
+
applyTheme(doc, tpl);
|
|
690
|
+
applyFonts(doc, tpl);
|
|
691
|
+
applySettings(doc, tpl, options);
|
|
692
|
+
if (options.furniture) applyFurniture(doc, tpl);
|
|
693
|
+
return { bytes: doc.write(), report };
|
|
694
|
+
}
|
|
695
|
+
function newFromTemplate(template, options = {}) {
|
|
696
|
+
const pkg = Pkg.read(template);
|
|
697
|
+
const main = pkg.main;
|
|
698
|
+
pkg.setContentType(main, CT.document);
|
|
699
|
+
const rels = pkg.rels(main);
|
|
700
|
+
for (const rel of rels.filter((r) => r.type === RT.glossary || /vbaProject$/.test(r.type))) {
|
|
701
|
+
const target = pkg.find(pkg.target(main, rel));
|
|
702
|
+
if (target) {
|
|
703
|
+
for (const sub of pkg.rels(target)) if (!sub.external) pkg.remove(pkg.target(target, sub));
|
|
704
|
+
pkg.remove(target);
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
pkg.setRels(
|
|
708
|
+
main,
|
|
709
|
+
rels.filter((r) => r.type !== RT.glossary && !/vbaProject$/.test(r.type))
|
|
710
|
+
);
|
|
711
|
+
if (options.attachedTemplate) {
|
|
712
|
+
const { part, root } = settingsOf(pkg);
|
|
713
|
+
if (!root.attrs["xmlns:r"]) root.attrs["xmlns:r"] = R_NS;
|
|
714
|
+
pkg.setRels(
|
|
715
|
+
part,
|
|
716
|
+
pkg.rels(part).filter((r) => r.type !== RT.attachedTemplate)
|
|
717
|
+
);
|
|
718
|
+
const id = pkg.addRel(part, RT.attachedTemplate, encodeURI(options.attachedTemplate), true);
|
|
719
|
+
placeOrdered(root, el("w:attachedTemplate", { "r:id": id }), SETTINGS_ORDER);
|
|
720
|
+
pkg.setXml(part, root);
|
|
721
|
+
}
|
|
722
|
+
return pkg.write();
|
|
723
|
+
}
|
|
724
|
+
function composeWithTemplate(content, template, attachedTemplate) {
|
|
725
|
+
return applyTemplate(content, template, { furniture: true, attachedTemplate }).bytes;
|
|
726
|
+
}
|
|
727
|
+
function glossaryOf(pkg) {
|
|
728
|
+
const part = pkg.partOf(pkg.main, RT.glossary) ?? pkg.find("word/glossary/document.xml");
|
|
729
|
+
const root = part ? pkg.xml(part) : void 0;
|
|
730
|
+
return part && root ? { part, root } : void 0;
|
|
731
|
+
}
|
|
732
|
+
function docParts(root) {
|
|
733
|
+
return kids(kid(root, "w:docParts") ?? root, "w:docPart");
|
|
734
|
+
}
|
|
735
|
+
function infoOf(part) {
|
|
736
|
+
const pr = kid(part, "w:docPartPr");
|
|
737
|
+
const name = val(pr, "w:name");
|
|
738
|
+
if (!name) return void 0;
|
|
739
|
+
const category = kid(pr, "w:category");
|
|
740
|
+
return {
|
|
741
|
+
name,
|
|
742
|
+
gallery: val(category, "w:gallery") ?? "docParts",
|
|
743
|
+
category: val(category, "w:name") ?? "General",
|
|
744
|
+
description: val(pr, "w:description") ?? "",
|
|
745
|
+
// One space between paragraphs (and table cells), as a one-line preview reads.
|
|
746
|
+
text: [...walk(kid(part, "w:docPartBody") ?? part)].filter((e) => e.name === "w:p").map(textOf).filter(Boolean).join(" ")
|
|
747
|
+
};
|
|
748
|
+
}
|
|
749
|
+
function listBuildingBlocks(template) {
|
|
750
|
+
const g = glossaryOf(Pkg.read(template));
|
|
751
|
+
if (!g) return [];
|
|
752
|
+
return docParts(g.root).map(infoOf).filter((b) => !!b && b.gallery !== "placeholder");
|
|
753
|
+
}
|
|
754
|
+
var MIN_CONTENT_TYPES = `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
755
|
+
<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types"><Default Extension="rels" ContentType="${CT.rels}"/><Default Extension="xml" ContentType="application/xml"/></Types>`;
|
|
756
|
+
function buildingBlockFragment(template, name) {
|
|
757
|
+
const tpl = Pkg.read(template);
|
|
758
|
+
const g = glossaryOf(tpl);
|
|
759
|
+
const part = g && docParts(g.root).find((p) => val(kid(p, "w:docPartPr"), "w:name") === name);
|
|
760
|
+
const body = part && kid(part, "w:docPartBody");
|
|
761
|
+
if (!g || !body) return void 0;
|
|
762
|
+
const out = new Pkg(/* @__PURE__ */ new Map([["[Content_Types].xml", strToU8(MIN_CONTENT_TYPES)]]));
|
|
763
|
+
out.setRels("", [
|
|
764
|
+
{ id: "rId1", type: RT.officeDocument, target: "word/document.xml", external: false }
|
|
765
|
+
]);
|
|
766
|
+
const main = "word/document.xml";
|
|
767
|
+
const blocks = body.children.filter(isEl).map(clone);
|
|
768
|
+
out.setXml(
|
|
769
|
+
main,
|
|
770
|
+
el("w:document", { ...g.root.attrs, "xmlns:w": W_NS, "xmlns:r": R_NS }, [
|
|
771
|
+
el("w:body", {}, blocks)
|
|
772
|
+
]),
|
|
773
|
+
CT.document
|
|
774
|
+
);
|
|
775
|
+
const rels = [];
|
|
776
|
+
const stylesPart = tpl.partOf(g.part, RT.styles) ?? tpl.partOf(tpl.main, RT.styles);
|
|
777
|
+
if (stylesPart) {
|
|
778
|
+
const styles = tpl.xml(stylesPart);
|
|
779
|
+
styles.children = styles.children.filter((c) => !(isEl(c) && c.name === "w:docDefaults"));
|
|
780
|
+
out.setXml("word/styles.xml", styles, CT.styles);
|
|
781
|
+
rels.push({ id: "rIdStyles", type: RT.styles, target: "styles.xml", external: false });
|
|
782
|
+
}
|
|
783
|
+
const numberingPart = tpl.partOf(g.part, RT.numbering) ?? tpl.partOf(tpl.main, RT.numbering);
|
|
784
|
+
if (numberingPart) {
|
|
785
|
+
out.setBytes("word/numbering.xml", tpl.files.get(numberingPart), CT.numbering);
|
|
786
|
+
rels.push({ id: "rIdNumbering", type: RT.numbering, target: "numbering.xml", external: false });
|
|
787
|
+
}
|
|
788
|
+
const used = /* @__PURE__ */ new Set();
|
|
789
|
+
for (const e of blocks.flatMap((b) => [...walk(b)]))
|
|
790
|
+
for (const [k, v] of Object.entries(e.attrs)) if (k.startsWith("r:")) used.add(v);
|
|
791
|
+
for (const rel of tpl.rels(g.part).filter((r) => used.has(r.id))) {
|
|
792
|
+
if (rel.external) {
|
|
793
|
+
rels.push({ ...rel });
|
|
794
|
+
continue;
|
|
795
|
+
}
|
|
796
|
+
const target = tpl.find(tpl.target(g.part, rel));
|
|
797
|
+
if (!target) continue;
|
|
798
|
+
const file = `word/media/${target.slice(target.lastIndexOf("/") + 1)}`;
|
|
799
|
+
out.setBytes(file, tpl.files.get(target));
|
|
800
|
+
const type = tpl.contentType(target);
|
|
801
|
+
if (type) out.ensureDefault(file.slice(file.lastIndexOf(".") + 1), type);
|
|
802
|
+
rels.push({ ...rel, target: file.slice("word/".length) });
|
|
803
|
+
}
|
|
804
|
+
out.setRels(main, rels);
|
|
805
|
+
return out.write();
|
|
806
|
+
}
|
|
807
|
+
function fragmentClipboardHtml(fragment, covered = true) {
|
|
808
|
+
let binary = "";
|
|
809
|
+
for (let i = 0; i < fragment.length; i += 32768)
|
|
810
|
+
binary += String.fromCharCode(...fragment.subarray(i, i + 32768));
|
|
811
|
+
return `<div data-docx-fragment="${btoa(binary)}" data-docx-fragment-end="${covered ? "covered" : "open"}"></div>`;
|
|
812
|
+
}
|
|
813
|
+
|
|
814
|
+
// src/template/track.ts
|
|
815
|
+
var TRACKED = /* @__PURE__ */ new Set(["w:ins", "w:del", "w:moveFrom", "w:moveTo"]);
|
|
816
|
+
function trackInsertion(fragment, revision, covered) {
|
|
817
|
+
const pkg = Pkg.read(fragment);
|
|
818
|
+
const main = pkg.main;
|
|
819
|
+
const root = pkg.xml(main);
|
|
820
|
+
const body = kid(root, "w:body");
|
|
821
|
+
if (!root || !body) return fragment;
|
|
822
|
+
const attrs = { "w:id": "1", "w:author": revision.author, "w:date": revision.date };
|
|
823
|
+
const lastParagraph = body.children.filter(isEl).findLast((c) => c.name === "w:p");
|
|
824
|
+
const visit = (node) => {
|
|
825
|
+
node.children = node.children.map((child) => {
|
|
826
|
+
if (!isEl(child)) return child;
|
|
827
|
+
if (child.name === "w:r") return TRACKED.has(node.name) ? child : el("w:ins", attrs, [child]);
|
|
828
|
+
if (TRACKED.has(child.name)) return child;
|
|
829
|
+
if (child.name === "w:tr") {
|
|
830
|
+
markRow(child, attrs);
|
|
831
|
+
return child;
|
|
832
|
+
}
|
|
833
|
+
visit(child);
|
|
834
|
+
if (child.name === "w:p" && (covered || child !== lastParagraph)) markParagraph(child, attrs);
|
|
835
|
+
return child;
|
|
836
|
+
});
|
|
837
|
+
};
|
|
838
|
+
visit(body);
|
|
839
|
+
pkg.setXml(main, root);
|
|
840
|
+
return pkg.write();
|
|
841
|
+
}
|
|
842
|
+
function markParagraph(p, attrs) {
|
|
843
|
+
let pPr = kid(p, "w:pPr");
|
|
844
|
+
if (!pPr) p.children.unshift(pPr = el("w:pPr"));
|
|
845
|
+
let rPr = kid(pPr, "w:rPr");
|
|
846
|
+
if (!rPr) {
|
|
847
|
+
rPr = el("w:rPr");
|
|
848
|
+
const at = pPr.children.findIndex(
|
|
849
|
+
(c) => isEl(c) && (c.name === "w:sectPr" || c.name === "w:pPrChange")
|
|
850
|
+
);
|
|
851
|
+
pPr.children.splice(at < 0 ? pPr.children.length : at, 0, rPr);
|
|
852
|
+
}
|
|
853
|
+
if (!kid(rPr, "w:ins")) rPr.children.unshift(el("w:ins", attrs));
|
|
854
|
+
}
|
|
855
|
+
function markRow(tr, attrs) {
|
|
856
|
+
let trPr = kid(tr, "w:trPr");
|
|
857
|
+
if (!trPr) {
|
|
858
|
+
trPr = el("w:trPr");
|
|
859
|
+
const after = tr.children.findIndex((c) => isEl(c) && c.name === "w:tblPrEx");
|
|
860
|
+
tr.children.splice(after + 1, 0, trPr);
|
|
861
|
+
}
|
|
862
|
+
if (kid(trPr, "w:ins")) return;
|
|
863
|
+
const at = trPr.children.findIndex((c) => isEl(c) && c.name === "w:trPrChange");
|
|
864
|
+
trPr.children.splice(at < 0 ? trPr.children.length : at, 0, el("w:ins", attrs));
|
|
865
|
+
}
|
|
866
|
+
|
|
867
|
+
// src/template/divergence.ts
|
|
868
|
+
var UI_ONLY = /* @__PURE__ */ new Set([
|
|
869
|
+
"w:uiPriority",
|
|
870
|
+
"w:semiHidden",
|
|
871
|
+
"w:unhideWhenUsed",
|
|
872
|
+
"w:qFormat",
|
|
873
|
+
"w:locked",
|
|
874
|
+
"w:personal",
|
|
875
|
+
"w:personalCompose",
|
|
876
|
+
"w:personalReply",
|
|
877
|
+
"w:rsid",
|
|
878
|
+
"w:autoRedefine",
|
|
879
|
+
"w:hidden",
|
|
880
|
+
"w:aliases"
|
|
881
|
+
]);
|
|
882
|
+
function numberingSignature(numbering, numId) {
|
|
883
|
+
if (!numbering) return `num:${numId}`;
|
|
884
|
+
const num = kids(numbering, "w:num").find((n) => n.attrs["w:numId"] === numId);
|
|
885
|
+
const abs = num && kids(numbering, "w:abstractNum").find(
|
|
886
|
+
(a) => a.attrs["w:abstractNumId"] === val(num, "w:abstractNumId")
|
|
887
|
+
);
|
|
888
|
+
if (!abs) return `num:${numId}`;
|
|
889
|
+
const levels = kids(abs, "w:lvl").map((l) => {
|
|
890
|
+
const c = clone(l);
|
|
891
|
+
c.children = c.children.filter(
|
|
892
|
+
(x) => !(isEl(x) && (x.name === "w:lvlPicBulletId" || x.name === "w:pStyle"))
|
|
893
|
+
);
|
|
894
|
+
return canonical(c);
|
|
895
|
+
});
|
|
896
|
+
return levels.join("|");
|
|
897
|
+
}
|
|
898
|
+
function canonical(e) {
|
|
899
|
+
const c = clone(e);
|
|
900
|
+
for (const x of walk(c)) {
|
|
901
|
+
for (const k of Object.keys(x.attrs))
|
|
902
|
+
if (/^w:rsid/.test(k) || k.startsWith("xmlns")) delete x.attrs[k];
|
|
903
|
+
x.attrs = Object.fromEntries(Object.entries(x.attrs).sort(([a], [b]) => a.localeCompare(b)));
|
|
904
|
+
x.children = x.children.filter((k) => isEl(k) && !UI_ONLY.has(k.name));
|
|
905
|
+
}
|
|
906
|
+
return serialize(c).replace(/^<\?xml[^>]*>\n/, "");
|
|
907
|
+
}
|
|
908
|
+
function styleSignature(style2, numbering) {
|
|
909
|
+
const c = clone(style2);
|
|
910
|
+
for (const x of walk(c))
|
|
911
|
+
if (x.name === "w:numId") x.attrs["w:val"] = numberingSignature(numbering, x.attrs["w:val"]);
|
|
912
|
+
delete c.attrs["w:styleId"];
|
|
913
|
+
return canonical(c);
|
|
914
|
+
}
|
|
915
|
+
function partsOf(bytes) {
|
|
916
|
+
const pkg = Pkg.read(bytes);
|
|
917
|
+
const stylesPart = pkg.partOf(pkg.main, RT.styles);
|
|
918
|
+
const numberingPart = pkg.partOf(pkg.main, RT.numbering);
|
|
919
|
+
return {
|
|
920
|
+
styles: stylesPart ? pkg.xml(stylesPart) : void 0,
|
|
921
|
+
numbering: numberingPart ? pkg.xml(numberingPart) : void 0
|
|
922
|
+
};
|
|
923
|
+
}
|
|
924
|
+
function styleDivergence(document, template) {
|
|
925
|
+
const d = partsOf(document);
|
|
926
|
+
const t = partsOf(template);
|
|
927
|
+
const result = { styles: [], docDefaults: false };
|
|
928
|
+
if (!t.styles) return result;
|
|
929
|
+
const dStyles = d.styles ? kids(d.styles, "w:style") : [];
|
|
930
|
+
const byId = new Map(dStyles.map((s) => [s.attrs["w:styleId"], s]));
|
|
931
|
+
const byName = new Map(
|
|
932
|
+
dStyles.map((s) => [`${s.attrs["w:type"]}:${(val(s, "w:name") ?? "").toLowerCase()}`, s])
|
|
933
|
+
);
|
|
934
|
+
for (const s of kids(t.styles, "w:style")) {
|
|
935
|
+
const id = s.attrs["w:styleId"];
|
|
936
|
+
const name = val(s, "w:name") ?? id;
|
|
937
|
+
const mine = byId.get(id) ?? byName.get(`${s.attrs["w:type"]}:${name.toLowerCase()}`);
|
|
938
|
+
if (!mine) result.styles.push({ styleId: id, name, kind: "missing" });
|
|
939
|
+
else if (styleSignature(mine, d.numbering) !== styleSignature(s, t.numbering))
|
|
940
|
+
result.styles.push({ styleId: mine.attrs["w:styleId"], name, kind: "changed" });
|
|
941
|
+
}
|
|
942
|
+
const dd = d.styles && kid(d.styles, "w:docDefaults");
|
|
943
|
+
const td = kid(t.styles, "w:docDefaults");
|
|
944
|
+
result.docDefaults = (dd ? canonical(dd) : "") !== (td ? canonical(td) : "");
|
|
945
|
+
return result;
|
|
946
|
+
}
|
|
947
|
+
function attachedTemplateOf(document) {
|
|
948
|
+
const pkg = Pkg.read(document);
|
|
949
|
+
const settings = pkg.partOf(pkg.main, RT.settings);
|
|
950
|
+
const root = settings ? pkg.xml(settings) : void 0;
|
|
951
|
+
const id = root && kid(root, "w:attachedTemplate")?.attrs["r:id"];
|
|
952
|
+
const rel = id ? pkg.rels(settings).find((r) => r.id === id) : void 0;
|
|
953
|
+
if (!rel) return void 0;
|
|
954
|
+
const target = decodeURI(rel.target);
|
|
955
|
+
return target.slice(Math.max(target.lastIndexOf("/"), target.lastIndexOf("\\")) + 1);
|
|
956
|
+
}
|
|
957
|
+
var W_DECL = 'xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"';
|
|
958
|
+
var VML_DECL = 'xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w10="urn:schemas-microsoft-com:office:word"';
|
|
959
|
+
var DRAWING_DECL = 'xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" xmlns:pic="http://schemas.openxmlformats.org/drawingml/2006/picture"';
|
|
960
|
+
var XML = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n';
|
|
961
|
+
var esc = (s) => s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
962
|
+
var STEP = 720;
|
|
963
|
+
function style(s) {
|
|
964
|
+
const type = s.type ?? "paragraph";
|
|
965
|
+
return [
|
|
966
|
+
`<w:style w:type="${type}"`,
|
|
967
|
+
s.isDefault ? ' w:default="1"' : "",
|
|
968
|
+
s.custom ? ' w:customStyle="1"' : "",
|
|
969
|
+
` w:styleId="${s.id}">`,
|
|
970
|
+
`<w:name w:val="${esc(s.name)}"/>`,
|
|
971
|
+
s.aliases ? `<w:aliases w:val="${esc(s.aliases)}"/>` : "",
|
|
972
|
+
s.basedOn ? `<w:basedOn w:val="${s.basedOn}"/>` : "",
|
|
973
|
+
s.next ? `<w:next w:val="${s.next}"/>` : "",
|
|
974
|
+
s.link ? `<w:link w:val="${s.link}"/>` : "",
|
|
975
|
+
s.uiPriority !== void 0 ? `<w:uiPriority w:val="${s.uiPriority}"/>` : "",
|
|
976
|
+
s.qFormat ? "<w:qFormat/>" : "",
|
|
977
|
+
s.extra ?? "",
|
|
978
|
+
s.pPr ? `<w:pPr>${s.pPr}</w:pPr>` : "",
|
|
979
|
+
s.rPr ? `<w:rPr>${s.rPr}</w:rPr>` : "",
|
|
980
|
+
"</w:style>"
|
|
981
|
+
].join("");
|
|
982
|
+
}
|
|
983
|
+
var ind = (left, hanging = 0) => `<w:ind w:left="${left}"${hanging ? ` w:hanging="${hanging}"` : ""}/>`;
|
|
984
|
+
var numPr = (numId, ilvl = 0) => `<w:numPr>${ilvl ? `<w:ilvl w:val="${ilvl}"/>` : ""}<w:numId w:val="${numId}"/></w:numPr>`;
|
|
985
|
+
var LEGAL_NUM = { clauses: 1, parties: 2, background: 3, schedules: 4 };
|
|
986
|
+
var LEVEL_TEXT = [STEP, STEP, 2 * STEP, 3 * STEP, 4 * STEP];
|
|
987
|
+
var LEGAL_STYLES = [
|
|
988
|
+
{ id: "Normal", name: "Normal", isDefault: true, qFormat: true, uiPriority: 0 },
|
|
989
|
+
{
|
|
990
|
+
id: "DefaultParagraphFont",
|
|
991
|
+
name: "Default Paragraph Font",
|
|
992
|
+
type: "character",
|
|
993
|
+
isDefault: true,
|
|
994
|
+
uiPriority: 1,
|
|
995
|
+
extra: "<w:semiHidden/><w:unhideWhenUsed/>"
|
|
996
|
+
},
|
|
997
|
+
{
|
|
998
|
+
id: "TableNormal",
|
|
999
|
+
name: "Normal Table",
|
|
1000
|
+
type: "table",
|
|
1001
|
+
isDefault: true,
|
|
1002
|
+
uiPriority: 99,
|
|
1003
|
+
extra: '<w:semiHidden/><w:unhideWhenUsed/><w:tblPr><w:tblInd w:w="0" w:type="dxa"/><w:tblCellMar><w:top w:w="0" w:type="dxa"/><w:left w:w="108" w:type="dxa"/><w:bottom w:w="0" w:type="dxa"/><w:right w:w="108" w:type="dxa"/></w:tblCellMar></w:tblPr>'
|
|
1004
|
+
},
|
|
1005
|
+
{
|
|
1006
|
+
id: "NoList",
|
|
1007
|
+
name: "No List",
|
|
1008
|
+
type: "numbering",
|
|
1009
|
+
isDefault: true,
|
|
1010
|
+
uiPriority: 99,
|
|
1011
|
+
extra: "<w:semiHidden/><w:unhideWhenUsed/>"
|
|
1012
|
+
},
|
|
1013
|
+
{
|
|
1014
|
+
id: "Title",
|
|
1015
|
+
name: "Title",
|
|
1016
|
+
next: "Normal",
|
|
1017
|
+
qFormat: true,
|
|
1018
|
+
uiPriority: 10,
|
|
1019
|
+
pPr: '<w:keepNext/><w:spacing w:after="360"/><w:jc w:val="center"/>',
|
|
1020
|
+
rPr: '<w:b/><w:caps/><w:sz w:val="28"/><w:szCs w:val="28"/>'
|
|
1021
|
+
},
|
|
1022
|
+
...[1, 2, 3].map((n) => ({
|
|
1023
|
+
id: `Heading${n}`,
|
|
1024
|
+
name: `heading ${n}`,
|
|
1025
|
+
basedOn: "Normal",
|
|
1026
|
+
next: "Normal",
|
|
1027
|
+
qFormat: true,
|
|
1028
|
+
uiPriority: 9,
|
|
1029
|
+
pPr: `<w:keepNext/><w:spacing w:before="240"/><w:outlineLvl w:val="${n - 1}"/>`,
|
|
1030
|
+
rPr: `<w:b/>${n === 1 ? "<w:caps/>" : ""}${n === 3 ? "<w:i/>" : ""}`
|
|
1031
|
+
})),
|
|
1032
|
+
{
|
|
1033
|
+
id: "Parties",
|
|
1034
|
+
name: "Parties",
|
|
1035
|
+
basedOn: "Normal",
|
|
1036
|
+
custom: true,
|
|
1037
|
+
qFormat: true,
|
|
1038
|
+
pPr: `${numPr(LEGAL_NUM.parties)}${ind(STEP, STEP)}`
|
|
1039
|
+
},
|
|
1040
|
+
{
|
|
1041
|
+
id: "Background",
|
|
1042
|
+
name: "Background",
|
|
1043
|
+
basedOn: "Normal",
|
|
1044
|
+
custom: true,
|
|
1045
|
+
qFormat: true,
|
|
1046
|
+
pPr: `${numPr(LEGAL_NUM.background)}${ind(STEP, STEP)}`
|
|
1047
|
+
},
|
|
1048
|
+
...[1, 2, 3, 4, 5].map((n) => ({
|
|
1049
|
+
id: `Level${n}`,
|
|
1050
|
+
name: `Level ${n}`,
|
|
1051
|
+
basedOn: "Normal",
|
|
1052
|
+
custom: true,
|
|
1053
|
+
qFormat: true,
|
|
1054
|
+
next: `Level${n}`,
|
|
1055
|
+
pPr: `${numPr(LEGAL_NUM.clauses, n - 1)}${n === 1 ? "<w:keepNext/>" : ""}${ind(
|
|
1056
|
+
LEVEL_TEXT[n - 1],
|
|
1057
|
+
STEP
|
|
1058
|
+
)}${n === 1 ? '<w:outlineLvl w:val="0"/>' : ""}`,
|
|
1059
|
+
rPr: n === 1 ? "<w:b/><w:caps/>" : void 0
|
|
1060
|
+
})),
|
|
1061
|
+
...[1, 2, 3, 4, 5].map((n) => ({
|
|
1062
|
+
id: `Body${n}`,
|
|
1063
|
+
name: `Body ${n}`,
|
|
1064
|
+
basedOn: "Normal",
|
|
1065
|
+
custom: true,
|
|
1066
|
+
qFormat: true,
|
|
1067
|
+
pPr: ind(LEVEL_TEXT[n - 1])
|
|
1068
|
+
})),
|
|
1069
|
+
{
|
|
1070
|
+
id: "Definition",
|
|
1071
|
+
name: "Definition",
|
|
1072
|
+
basedOn: "Normal",
|
|
1073
|
+
custom: true,
|
|
1074
|
+
qFormat: true,
|
|
1075
|
+
pPr: ind(STEP)
|
|
1076
|
+
},
|
|
1077
|
+
{
|
|
1078
|
+
id: "Schedule",
|
|
1079
|
+
name: "Schedule",
|
|
1080
|
+
basedOn: "Normal",
|
|
1081
|
+
next: "Normal",
|
|
1082
|
+
custom: true,
|
|
1083
|
+
qFormat: true,
|
|
1084
|
+
pPr: `${numPr(LEGAL_NUM.schedules)}<w:keepNext/><w:pageBreakBefore/><w:jc w:val="center"/><w:outlineLvl w:val="0"/>`,
|
|
1085
|
+
rPr: "<w:b/><w:caps/>"
|
|
1086
|
+
},
|
|
1087
|
+
{
|
|
1088
|
+
id: "Part",
|
|
1089
|
+
name: "Part",
|
|
1090
|
+
basedOn: "Normal",
|
|
1091
|
+
next: "Normal",
|
|
1092
|
+
custom: true,
|
|
1093
|
+
qFormat: true,
|
|
1094
|
+
pPr: `${numPr(LEGAL_NUM.schedules, 1)}<w:keepNext/><w:jc w:val="center"/><w:outlineLvl w:val="1"/>`,
|
|
1095
|
+
rPr: "<w:b/>"
|
|
1096
|
+
},
|
|
1097
|
+
{
|
|
1098
|
+
id: "BlockText",
|
|
1099
|
+
name: "Block Text",
|
|
1100
|
+
aliases: "Block Quote",
|
|
1101
|
+
basedOn: "Normal",
|
|
1102
|
+
uiPriority: 99,
|
|
1103
|
+
pPr: `<w:ind w:left="${2 * STEP}" w:right="${2 * STEP}"/>`
|
|
1104
|
+
},
|
|
1105
|
+
{
|
|
1106
|
+
id: "Quote",
|
|
1107
|
+
name: "Quote",
|
|
1108
|
+
basedOn: "Normal",
|
|
1109
|
+
next: "Normal",
|
|
1110
|
+
qFormat: true,
|
|
1111
|
+
uiPriority: 29,
|
|
1112
|
+
pPr: `<w:ind w:left="${STEP}" w:right="${STEP}"/>`,
|
|
1113
|
+
rPr: "<w:i/>"
|
|
1114
|
+
},
|
|
1115
|
+
{
|
|
1116
|
+
id: "Marking",
|
|
1117
|
+
name: "Document Marking",
|
|
1118
|
+
basedOn: "Normal",
|
|
1119
|
+
next: "Normal",
|
|
1120
|
+
custom: true,
|
|
1121
|
+
pPr: '<w:jc w:val="right"/>',
|
|
1122
|
+
rPr: "<w:b/><w:caps/>"
|
|
1123
|
+
},
|
|
1124
|
+
{
|
|
1125
|
+
id: "FootnoteText",
|
|
1126
|
+
name: "footnote text",
|
|
1127
|
+
basedOn: "Normal",
|
|
1128
|
+
link: "FootnoteTextChar",
|
|
1129
|
+
uiPriority: 99,
|
|
1130
|
+
pPr: '<w:spacing w:after="0" w:line="240" w:lineRule="auto"/>',
|
|
1131
|
+
rPr: '<w:sz w:val="18"/><w:szCs w:val="18"/>'
|
|
1132
|
+
},
|
|
1133
|
+
{
|
|
1134
|
+
id: "FootnoteTextChar",
|
|
1135
|
+
name: "Footnote Text Char",
|
|
1136
|
+
type: "character",
|
|
1137
|
+
basedOn: "DefaultParagraphFont",
|
|
1138
|
+
link: "FootnoteText",
|
|
1139
|
+
custom: true,
|
|
1140
|
+
uiPriority: 99,
|
|
1141
|
+
rPr: '<w:sz w:val="18"/><w:szCs w:val="18"/>'
|
|
1142
|
+
},
|
|
1143
|
+
{
|
|
1144
|
+
id: "FootnoteReference",
|
|
1145
|
+
name: "footnote reference",
|
|
1146
|
+
type: "character",
|
|
1147
|
+
basedOn: "DefaultParagraphFont",
|
|
1148
|
+
uiPriority: 99,
|
|
1149
|
+
rPr: '<w:vertAlign w:val="superscript"/>'
|
|
1150
|
+
},
|
|
1151
|
+
{
|
|
1152
|
+
id: "EndnoteText",
|
|
1153
|
+
name: "endnote text",
|
|
1154
|
+
basedOn: "FootnoteText",
|
|
1155
|
+
uiPriority: 99
|
|
1156
|
+
},
|
|
1157
|
+
{
|
|
1158
|
+
id: "EndnoteReference",
|
|
1159
|
+
name: "endnote reference",
|
|
1160
|
+
type: "character",
|
|
1161
|
+
basedOn: "DefaultParagraphFont",
|
|
1162
|
+
uiPriority: 99,
|
|
1163
|
+
rPr: '<w:vertAlign w:val="superscript"/>'
|
|
1164
|
+
},
|
|
1165
|
+
{
|
|
1166
|
+
id: "Header",
|
|
1167
|
+
name: "header",
|
|
1168
|
+
basedOn: "Normal",
|
|
1169
|
+
uiPriority: 99,
|
|
1170
|
+
pPr: `<w:tabs><w:tab w:val="center" w:pos="4513"/><w:tab w:val="right" w:pos="9026"/></w:tabs><w:spacing w:after="0"/>`,
|
|
1171
|
+
rPr: '<w:sz w:val="16"/><w:szCs w:val="16"/>'
|
|
1172
|
+
},
|
|
1173
|
+
{
|
|
1174
|
+
id: "Footer",
|
|
1175
|
+
name: "footer",
|
|
1176
|
+
basedOn: "Header",
|
|
1177
|
+
uiPriority: 99
|
|
1178
|
+
},
|
|
1179
|
+
{
|
|
1180
|
+
id: "Hyperlink",
|
|
1181
|
+
name: "Hyperlink",
|
|
1182
|
+
type: "character",
|
|
1183
|
+
basedOn: "DefaultParagraphFont",
|
|
1184
|
+
uiPriority: 99,
|
|
1185
|
+
rPr: '<w:color w:val="0563C1" w:themeColor="hyperlink"/><w:u w:val="single"/>'
|
|
1186
|
+
},
|
|
1187
|
+
{
|
|
1188
|
+
id: "TableGrid",
|
|
1189
|
+
name: "Table Grid",
|
|
1190
|
+
type: "table",
|
|
1191
|
+
basedOn: "TableNormal",
|
|
1192
|
+
uiPriority: 39,
|
|
1193
|
+
pPr: '<w:spacing w:after="0" w:line="240" w:lineRule="auto"/>',
|
|
1194
|
+
extra: '<w:tblPr><w:tblBorders><w:top w:val="single" w:sz="4" w:space="0" w:color="auto"/><w:left w:val="single" w:sz="4" w:space="0" w:color="auto"/><w:bottom w:val="single" w:sz="4" w:space="0" w:color="auto"/><w:right w:val="single" w:sz="4" w:space="0" w:color="auto"/><w:insideH w:val="single" w:sz="4" w:space="0" w:color="auto"/><w:insideV w:val="single" w:sz="4" w:space="0" w:color="auto"/></w:tblBorders></w:tblPr>'
|
|
1195
|
+
}
|
|
1196
|
+
];
|
|
1197
|
+
var DOC_DEFAULTS = '<w:docDefaults><w:rPrDefault><w:rPr><w:rFonts w:asciiTheme="minorHAnsi" w:eastAsiaTheme="minorHAnsi" w:hAnsiTheme="minorHAnsi" w:cstheme="minorBidi"/><w:sz w:val="21"/><w:szCs w:val="21"/><w:lang w:val="en-GB" w:eastAsia="en-US" w:bidi="ar-SA"/></w:rPr></w:rPrDefault><w:pPrDefault><w:pPr><w:spacing w:after="240" w:line="288" w:lineRule="auto"/><w:jc w:val="both"/></w:pPr></w:pPrDefault></w:docDefaults>';
|
|
1198
|
+
var LATENT = '<w:latentStyles w:defLockedState="0" w:defUIPriority="99" w:defSemiHidden="0" w:defUnhideWhenUsed="0" w:defQFormat="0" w:count="376"><w:lsdException w:name="Normal" w:uiPriority="0" w:qFormat="1"/><w:lsdException w:name="heading 1" w:uiPriority="9" w:qFormat="1"/><w:lsdException w:name="heading 2" w:uiPriority="9" w:qFormat="1"/><w:lsdException w:name="heading 3" w:uiPriority="9" w:qFormat="1"/><w:lsdException w:name="Title" w:uiPriority="10" w:qFormat="1"/><w:lsdException w:name="Quote" w:uiPriority="29" w:qFormat="1"/></w:latentStyles>';
|
|
1199
|
+
function legalStylesXml() {
|
|
1200
|
+
return `${XML}<w:styles ${W_DECL}>${DOC_DEFAULTS}${LATENT}${LEGAL_STYLES.map(style).join("")}</w:styles>`;
|
|
1201
|
+
}
|
|
1202
|
+
function lvl(i, l) {
|
|
1203
|
+
return `<w:lvl w:ilvl="${i}"><w:start w:val="${l.start ?? 1}"/><w:numFmt w:val="${l.fmt}"/>${l.pStyle ? `<w:pStyle w:val="${l.pStyle}"/>` : ""}<w:lvlText w:val="${esc(l.text)}"/><w:lvlJc w:val="${l.jc ?? "left"}"/><w:pPr>${ind(
|
|
1204
|
+
l.left,
|
|
1205
|
+
l.hanging ?? 0
|
|
1206
|
+
)}</w:pPr>${l.rPr ? `<w:rPr>${l.rPr}</w:rPr>` : ""}</w:lvl>`;
|
|
1207
|
+
}
|
|
1208
|
+
function abstractNum(id, nsid, name, levels) {
|
|
1209
|
+
return `<w:abstractNum w:abstractNumId="${id}"><w:nsid w:val="${nsid}"/><w:multiLevelType w:val="${levels.length > 1 ? "multilevel" : "singleLevel"}"/><w:name w:val="${esc(name)}"/>${levels.map((l, i) => lvl(i, l)).join("")}</w:abstractNum>`;
|
|
1210
|
+
}
|
|
1211
|
+
var CLAUSE_LEVELS = [
|
|
1212
|
+
{ fmt: "decimal", text: "%1.", pStyle: "Level1", left: STEP, hanging: STEP, rPr: "<w:b/>" },
|
|
1213
|
+
{
|
|
1214
|
+
fmt: "decimal",
|
|
1215
|
+
text: "%1.%2",
|
|
1216
|
+
pStyle: "Level2",
|
|
1217
|
+
left: STEP,
|
|
1218
|
+
hanging: STEP,
|
|
1219
|
+
rPr: '<w:b w:val="0"/><w:caps w:val="0"/>'
|
|
1220
|
+
},
|
|
1221
|
+
{ fmt: "lowerLetter", text: "(%3)", pStyle: "Level3", left: 2 * STEP, hanging: STEP },
|
|
1222
|
+
{ fmt: "lowerRoman", text: "(%4)", pStyle: "Level4", left: 3 * STEP, hanging: STEP },
|
|
1223
|
+
{ fmt: "upperLetter", text: "(%5)", pStyle: "Level5", left: 4 * STEP, hanging: STEP }
|
|
1224
|
+
];
|
|
1225
|
+
function legalNumberingXml() {
|
|
1226
|
+
const abstracts = [
|
|
1227
|
+
abstractNum(0, "4C2A1B01", "Legal clauses", CLAUSE_LEVELS),
|
|
1228
|
+
abstractNum(1, "4C2A1B02", "Parties", [
|
|
1229
|
+
{ fmt: "decimal", text: "(%1)", pStyle: "Parties", left: STEP, hanging: STEP }
|
|
1230
|
+
]),
|
|
1231
|
+
abstractNum(2, "4C2A1B03", "Background", [
|
|
1232
|
+
{ fmt: "upperLetter", text: "(%1)", pStyle: "Background", left: STEP, hanging: STEP }
|
|
1233
|
+
]),
|
|
1234
|
+
abstractNum(3, "4C2A1B04", "Schedules", [
|
|
1235
|
+
{ fmt: "decimal", text: "Schedule %1", pStyle: "Schedule", left: 0, jc: "center" },
|
|
1236
|
+
{ fmt: "decimal", text: "Part %2", pStyle: "Part", left: 0, jc: "center" }
|
|
1237
|
+
])
|
|
1238
|
+
];
|
|
1239
|
+
const nums = [1, 2, 3, 4].map(
|
|
1240
|
+
(n) => `<w:num w:numId="${n}"><w:abstractNumId w:val="${n - 1}"/></w:num>`
|
|
1241
|
+
);
|
|
1242
|
+
return `${XML}<w:numbering ${W_DECL}>${abstracts.join("")}${nums.join("")}</w:numbering>`;
|
|
1243
|
+
}
|
|
1244
|
+
var THEME_COLORS = [
|
|
1245
|
+
["dk2", "1F2937"],
|
|
1246
|
+
["lt2", "E7E6E6"],
|
|
1247
|
+
["accent1", "1F3864"],
|
|
1248
|
+
["accent2", "7B2C2C"],
|
|
1249
|
+
["accent3", "2E5A2E"],
|
|
1250
|
+
["accent4", "7F6000"],
|
|
1251
|
+
["accent5", "2F5597"],
|
|
1252
|
+
["accent6", "595959"],
|
|
1253
|
+
["hlink", "0563C1"],
|
|
1254
|
+
["folHlink", "954F72"]
|
|
1255
|
+
];
|
|
1256
|
+
function themeXml(major = "Arial", minor = "Arial") {
|
|
1257
|
+
const font = (f) => `<a:latin typeface="${esc(f)}"/><a:ea typeface=""/><a:cs typeface=""/>`;
|
|
1258
|
+
return `${XML}<a:theme xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" name="ARBI Legal"><a:themeElements><a:clrScheme name="ARBI Legal"><a:dk1><a:sysClr val="windowText" lastClr="000000"/></a:dk1><a:lt1><a:sysClr val="window" lastClr="FFFFFF"/></a:lt1>${THEME_COLORS.map(
|
|
1259
|
+
([k, v]) => `<a:${k}><a:srgbClr val="${v}"/></a:${k}>`
|
|
1260
|
+
).join(
|
|
1261
|
+
""
|
|
1262
|
+
)}</a:clrScheme><a:fontScheme name="ARBI Legal"><a:majorFont>${font(major)}</a:majorFont><a:minorFont>${font(
|
|
1263
|
+
minor
|
|
1264
|
+
)}</a:minorFont></a:fontScheme><a:fmtScheme name="Office"><a:fillStyleLst><a:solidFill><a:schemeClr val="phClr"/></a:solidFill><a:solidFill><a:schemeClr val="phClr"/></a:solidFill><a:solidFill><a:schemeClr val="phClr"/></a:solidFill></a:fillStyleLst><a:lnStyleLst><a:ln w="6350"><a:solidFill><a:schemeClr val="phClr"/></a:solidFill></a:ln><a:ln w="12700"><a:solidFill><a:schemeClr val="phClr"/></a:solidFill></a:ln><a:ln w="19050"><a:solidFill><a:schemeClr val="phClr"/></a:solidFill></a:ln></a:lnStyleLst><a:effectStyleLst><a:effectStyle><a:effectLst/></a:effectStyle><a:effectStyle><a:effectLst/></a:effectStyle><a:effectStyle><a:effectLst/></a:effectStyle></a:effectStyleLst><a:bgFillStyleLst><a:solidFill><a:schemeClr val="phClr"/></a:solidFill><a:solidFill><a:schemeClr val="phClr"/></a:solidFill><a:solidFill><a:schemeClr val="phClr"/></a:solidFill></a:bgFillStyleLst></a:fmtScheme></a:themeElements></a:theme>`;
|
|
1265
|
+
}
|
|
1266
|
+
var FONT_TABLE = `${XML}<w:fonts ${W_DECL}><w:font w:name="Arial"><w:panose1 w:val="020B0604020202020204"/><w:charset w:val="00"/><w:family w:val="swiss"/><w:pitch w:val="variable"/></w:font><w:font w:name="Times New Roman"><w:panose1 w:val="02020603050405020304"/><w:charset w:val="00"/><w:family w:val="roman"/><w:pitch w:val="variable"/></w:font></w:fonts>`;
|
|
1267
|
+
function settingsXml(o) {
|
|
1268
|
+
return `${XML}<w:settings ${W_DECL}><w:zoom w:percent="100"/>${o.template ? "" : ""}<w:defaultTabStop w:val="${STEP}"/>${o.evenAndOdd ? "<w:evenAndOddHeaders/>" : ""}<w:characterSpacingControl w:val="doNotCompress"/><w:footnotePr><w:footnote w:id="-1"/><w:footnote w:id="0"/></w:footnotePr><w:endnotePr><w:endnote w:id="-1"/><w:endnote w:id="0"/></w:endnotePr><w:compat><w:compatSetting w:name="compatibilityMode" w:uri="http://schemas.microsoft.com/office/word" w:val="15"/></w:compat><w:themeFontLang w:val="en-GB"/></w:settings>`;
|
|
1269
|
+
}
|
|
1270
|
+
var NOTES = (kind) => `${XML}<w:${kind}s ${W_DECL}><w:${kind} w:type="separator" w:id="-1"><w:p><w:pPr><w:spacing w:after="0" w:line="240" w:lineRule="auto"/></w:pPr><w:r><w:separator/></w:r></w:p></w:${kind}><w:${kind} w:type="continuationSeparator" w:id="0"><w:p><w:pPr><w:spacing w:after="0" w:line="240" w:lineRule="auto"/></w:pPr><w:r><w:continuationSeparator/></w:r></w:p></w:${kind}></w:${kind}s>`;
|
|
1271
|
+
var run = (text, rPr = "") => `<w:r>${rPr ? `<w:rPr>${rPr}</w:rPr>` : ""}<w:t xml:space="preserve">${esc(text)}</w:t></w:r>`;
|
|
1272
|
+
var para = (text, styleId, extra = "") => `<w:p>${styleId || extra ? `<w:pPr>${styleId ? `<w:pStyle w:val="${styleId}"/>` : ""}${extra}</w:pPr>` : ""}${text ? run(text) : ""}</w:p>`;
|
|
1273
|
+
var field = (code, shown) => `<w:r><w:fldChar w:fldCharType="begin"/></w:r><w:r><w:instrText xml:space="preserve"> ${code} </w:instrText></w:r><w:r><w:fldChar w:fldCharType="separate"/></w:r>${run(
|
|
1274
|
+
shown
|
|
1275
|
+
)}<w:r><w:fldChar w:fldCharType="end"/></w:r>`;
|
|
1276
|
+
function executionTable(rows) {
|
|
1277
|
+
const cell = (xml, w) => `<w:tc><w:tcPr><w:tcW w:w="${w}" w:type="dxa"/></w:tcPr>${xml}</w:tc>`;
|
|
1278
|
+
const lines = (s) => s.split("\n").map((t) => `<w:p><w:pPr><w:jc w:val="left"/></w:pPr>${run(t)}</w:p>`).join("");
|
|
1279
|
+
return `<w:tbl><w:tblPr><w:tblW w:w="9026" w:type="dxa"/><w:tblLook w:val="0000" w:firstRow="0" w:lastRow="0" w:firstColumn="0" w:lastColumn="0" w:noHBand="0" w:noVBand="0"/></w:tblPr><w:tblGrid><w:gridCol w:w="4513"/><w:gridCol w:w="4513"/></w:tblGrid>${rows.map(([l, r]) => `<w:tr>${cell(lines(l), 4513)}${cell(lines(r), 4513)}</w:tr>`).join("")}</w:tbl><w:p/>`;
|
|
1280
|
+
}
|
|
1281
|
+
var SIGN = "\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026";
|
|
1282
|
+
var AGREEMENT_BODY = [
|
|
1283
|
+
para("[Title of agreement]", "Title"),
|
|
1284
|
+
para("This agreement is dated [DATE]"),
|
|
1285
|
+
para("Parties", "Heading1"),
|
|
1286
|
+
para(
|
|
1287
|
+
"[NAME] incorporated and registered in England and Wales with company number [NUMBER] whose registered office is at [ADDRESS]",
|
|
1288
|
+
"Parties"
|
|
1289
|
+
),
|
|
1290
|
+
para(
|
|
1291
|
+
"[NAME] incorporated and registered in England and Wales with company number [NUMBER] whose registered office is at [ADDRESS]",
|
|
1292
|
+
"Parties"
|
|
1293
|
+
),
|
|
1294
|
+
para("Background", "Heading1"),
|
|
1295
|
+
para("[Recital]", "Background"),
|
|
1296
|
+
para("Agreed terms", "Heading1"),
|
|
1297
|
+
para("Interpretation", "Level1"),
|
|
1298
|
+
para("The following definitions apply in this agreement.", "Level2"),
|
|
1299
|
+
para("[Term]: [definition].", "Definition"),
|
|
1300
|
+
para("[Clause]", "Level1"),
|
|
1301
|
+
para("[Sub-clause]", "Level2")
|
|
1302
|
+
].join("");
|
|
1303
|
+
var LEGAL_BUILDING_BLOCKS = [
|
|
1304
|
+
{
|
|
1305
|
+
name: "Individual (signed)",
|
|
1306
|
+
category: "Signature blocks",
|
|
1307
|
+
description: "An individual signing a simple contract.",
|
|
1308
|
+
body: executionTable([["Signed by [NAME]", `${SIGN}
|
|
1309
|
+
[Signature]`]])
|
|
1310
|
+
},
|
|
1311
|
+
{
|
|
1312
|
+
name: "Company: director and secretary",
|
|
1313
|
+
category: "Signature blocks",
|
|
1314
|
+
description: "A company signing by a director and its secretary (Companies Act 2006, s.44(2)(a)).",
|
|
1315
|
+
body: executionTable([
|
|
1316
|
+
[
|
|
1317
|
+
"Signed by [NAME], a director, for and on behalf of [COMPANY NAME] LIMITED",
|
|
1318
|
+
`${SIGN}
|
|
1319
|
+
Director`
|
|
1320
|
+
],
|
|
1321
|
+
[
|
|
1322
|
+
"Signed by [NAME], the secretary, for and on behalf of [COMPANY NAME] LIMITED",
|
|
1323
|
+
`${SIGN}
|
|
1324
|
+
Secretary`
|
|
1325
|
+
]
|
|
1326
|
+
])
|
|
1327
|
+
},
|
|
1328
|
+
{
|
|
1329
|
+
name: "Company: two directors",
|
|
1330
|
+
category: "Signature blocks",
|
|
1331
|
+
description: "A company signing by two directors (Companies Act 2006, s.44(2)(a)).",
|
|
1332
|
+
body: executionTable([
|
|
1333
|
+
[
|
|
1334
|
+
"Signed by [NAME], a director, for and on behalf of [COMPANY NAME] LIMITED",
|
|
1335
|
+
`${SIGN}
|
|
1336
|
+
Director`
|
|
1337
|
+
],
|
|
1338
|
+
[
|
|
1339
|
+
"Signed by [NAME], a director, for and on behalf of [COMPANY NAME] LIMITED",
|
|
1340
|
+
`${SIGN}
|
|
1341
|
+
Director`
|
|
1342
|
+
]
|
|
1343
|
+
])
|
|
1344
|
+
},
|
|
1345
|
+
{
|
|
1346
|
+
name: "Company deed: director and witness",
|
|
1347
|
+
category: "Signature blocks",
|
|
1348
|
+
description: "A company executing a deed by one director in the presence of a witness (Companies Act 2006, ss.44(2)(b) and 46).",
|
|
1349
|
+
body: executionTable([
|
|
1350
|
+
[
|
|
1351
|
+
"Executed as a deed by [COMPANY NAME] LIMITED acting by [NAME], a director, in the presence of:",
|
|
1352
|
+
`${SIGN}
|
|
1353
|
+
Director`
|
|
1354
|
+
],
|
|
1355
|
+
[
|
|
1356
|
+
"Witness signature\nWitness name\nWitness address\nWitness occupation",
|
|
1357
|
+
`${SIGN}
|
|
1358
|
+
${SIGN}
|
|
1359
|
+
${SIGN}
|
|
1360
|
+
${SIGN}`
|
|
1361
|
+
]
|
|
1362
|
+
])
|
|
1363
|
+
},
|
|
1364
|
+
{
|
|
1365
|
+
name: "LLP: two members",
|
|
1366
|
+
category: "Signature blocks",
|
|
1367
|
+
description: "An LLP signing by two members (Limited Liability Partnerships (Application of Companies Act 2006) Regulations 2009, reg.4).",
|
|
1368
|
+
body: executionTable([
|
|
1369
|
+
["Signed by [NAME], a member, for and on behalf of [LLP NAME] LLP", `${SIGN}
|
|
1370
|
+
Member`],
|
|
1371
|
+
["Signed by [NAME], a member, for and on behalf of [LLP NAME] LLP", `${SIGN}
|
|
1372
|
+
Member`]
|
|
1373
|
+
])
|
|
1374
|
+
},
|
|
1375
|
+
{
|
|
1376
|
+
name: "Individual deed with witness",
|
|
1377
|
+
category: "Signature blocks",
|
|
1378
|
+
description: "An individual executing a deed in the presence of a witness.",
|
|
1379
|
+
body: executionTable([
|
|
1380
|
+
["Signed as a deed by [NAME] in the presence of:", `${SIGN}
|
|
1381
|
+
[Signature]`],
|
|
1382
|
+
[
|
|
1383
|
+
"Witness signature\nWitness name\nWitness address\nWitness occupation",
|
|
1384
|
+
`${SIGN}
|
|
1385
|
+
${SIGN}
|
|
1386
|
+
${SIGN}
|
|
1387
|
+
${SIGN}`
|
|
1388
|
+
]
|
|
1389
|
+
])
|
|
1390
|
+
},
|
|
1391
|
+
{
|
|
1392
|
+
name: "Agreement",
|
|
1393
|
+
category: "Documents",
|
|
1394
|
+
description: "The front of an agreement: title, date, parties, background and the first clauses.",
|
|
1395
|
+
body: AGREEMENT_BODY
|
|
1396
|
+
},
|
|
1397
|
+
...[
|
|
1398
|
+
[
|
|
1399
|
+
"Without prejudice save as to costs",
|
|
1400
|
+
"Settlement correspondence that may be shown to the court on costs."
|
|
1401
|
+
],
|
|
1402
|
+
["Privileged & confidential", "Legally privileged communication."],
|
|
1403
|
+
["Subject to contract", "Negotiations not intended to be binding."],
|
|
1404
|
+
["Draft for discussion", "A draft that is not final."]
|
|
1405
|
+
].map(([text, description]) => ({
|
|
1406
|
+
name: text,
|
|
1407
|
+
category: "Headings",
|
|
1408
|
+
description,
|
|
1409
|
+
body: para(text, "Marking")
|
|
1410
|
+
}))
|
|
1411
|
+
];
|
|
1412
|
+
function glossaryXml(blocks) {
|
|
1413
|
+
const guid = (i) => `{4C2A1B${String(i).padStart(2, "0")}-0000-4000-8000-${String(i).padStart(12, "0")}}`;
|
|
1414
|
+
return `${XML}<w:glossaryDocument ${W_DECL}><w:docParts>${blocks.map(
|
|
1415
|
+
(b, i) => `<w:docPart><w:docPartPr><w:name w:val="${esc(b.name)}"/><w:category><w:name w:val="${esc(
|
|
1416
|
+
b.category
|
|
1417
|
+
)}"/><w:gallery w:val="docParts"/></w:category><w:behaviors><w:behavior w:val="content"/></w:behaviors><w:description w:val="${esc(
|
|
1418
|
+
b.description
|
|
1419
|
+
)}"/><w:guid w:val="${guid(i + 1)}"/></w:docPartPr><w:docPartBody>${b.body}</w:docPartBody></w:docPart>`
|
|
1420
|
+
).join("")}</w:docParts></w:glossaryDocument>`;
|
|
1421
|
+
}
|
|
1422
|
+
function placeholderPng(w = 160, h = 48, grey = 208) {
|
|
1423
|
+
const crcTable = Array.from({ length: 256 }, (_, n) => {
|
|
1424
|
+
let c = n;
|
|
1425
|
+
for (let k = 0; k < 8; k++) c = c & 1 ? 3988292384 ^ c >>> 1 : c >>> 1;
|
|
1426
|
+
return c >>> 0;
|
|
1427
|
+
});
|
|
1428
|
+
const crc = (bytes) => {
|
|
1429
|
+
let c = 4294967295;
|
|
1430
|
+
for (const b of bytes) c = crcTable[(c ^ b) & 255] ^ c >>> 8;
|
|
1431
|
+
return (c ^ 4294967295) >>> 0;
|
|
1432
|
+
};
|
|
1433
|
+
const u32 = (n) => [n >>> 24 & 255, n >>> 16 & 255, n >>> 8 & 255, n & 255];
|
|
1434
|
+
const chunk = (type, data) => {
|
|
1435
|
+
const body = new Uint8Array([...strToU8(type), ...data]);
|
|
1436
|
+
return [...u32(data.length), ...body, ...u32(crc(body))];
|
|
1437
|
+
};
|
|
1438
|
+
const raw = new Uint8Array(h * (w + 1));
|
|
1439
|
+
for (let y = 0; y < h; y++) raw.fill(grey, y * (w + 1) + 1, (y + 1) * (w + 1));
|
|
1440
|
+
return new Uint8Array([
|
|
1441
|
+
137,
|
|
1442
|
+
80,
|
|
1443
|
+
78,
|
|
1444
|
+
71,
|
|
1445
|
+
13,
|
|
1446
|
+
10,
|
|
1447
|
+
26,
|
|
1448
|
+
10,
|
|
1449
|
+
...chunk("IHDR", new Uint8Array([...u32(w), ...u32(h), 8, 0, 0, 0, 0])),
|
|
1450
|
+
...chunk("IDAT", zlibSync(raw)),
|
|
1451
|
+
...chunk("IEND", new Uint8Array())
|
|
1452
|
+
]);
|
|
1453
|
+
}
|
|
1454
|
+
function inlineImage(rId, cx, cy, id, name) {
|
|
1455
|
+
return `<w:r><w:drawing><wp:inline distT="0" distB="0" distL="0" distR="0"><wp:extent cx="${cx}" cy="${cy}"/><wp:docPr id="${id}" name="${esc(
|
|
1456
|
+
name
|
|
1457
|
+
)}" descr="${esc(name)}"/><a:graphic><a:graphicData uri="http://schemas.openxmlformats.org/drawingml/2006/picture"><pic:pic><pic:nvPicPr><pic:cNvPr id="${id}" name="${esc(
|
|
1458
|
+
name
|
|
1459
|
+
)}"/><pic:cNvPicPr/></pic:nvPicPr><pic:blipFill><a:blip r:embed="${rId}"/><a:stretch><a:fillRect/></a:stretch></pic:blipFill><pic:spPr><a:xfrm><a:off x="0" y="0"/><a:ext cx="${cx}" cy="${cy}"/></a:xfrm><a:prstGeom prst="rect"><a:avLst/></a:prstGeom></pic:spPr></pic:pic></a:graphicData></a:graphic></wp:inline></w:drawing></w:r>`;
|
|
1460
|
+
}
|
|
1461
|
+
function watermarkXml(text) {
|
|
1462
|
+
return `<w:p><w:pPr><w:pStyle w:val="Header"/></w:pPr><w:r><w:pict><v:shapetype id="_x0000_t136" coordsize="21600,21600" o:spt="136" adj="10800" path="m@7,l@8,m@5,21600l@6,21600e"><v:path textpathok="t" o:connecttype="custom"/><v:textpath on="t" fitshape="t"/><o:lock v:ext="edit" text="t" shapetype="t"/></v:shapetype><v:shape id="PowerPlusWaterMarkObject1" o:spid="_x0000_s1025" type="#_x0000_t136" style="position:absolute;margin-left:0;margin-top:0;width:412.4pt;height:164.95pt;rotation:315;z-index:-251657216;mso-position-horizontal:center;mso-position-horizontal-relative:margin;mso-position-vertical:center;mso-position-vertical-relative:margin" o:allowincell="f" fillcolor="silver" stroked="f"><v:fill opacity=".5"/><v:textpath style="font-family:"Arial";font-size:1pt" string="${esc(
|
|
1463
|
+
text
|
|
1464
|
+
)}"/><w10:wrap anchorx="margin" anchory="margin"/></v:shape></w:pict></w:r></w:p>`;
|
|
1465
|
+
}
|
|
1466
|
+
var hdr = (kind, body) => `${XML}<w:${kind} ${W_DECL} ${VML_DECL} ${DRAWING_DECL}>${body}</w:${kind}>`;
|
|
1467
|
+
function defaultLegalTemplate(options = {}) {
|
|
1468
|
+
const files = {};
|
|
1469
|
+
const put = (name, xml) => files[name] = strToU8(xml);
|
|
1470
|
+
const overrides = [
|
|
1471
|
+
["/word/document.xml", options.asDocument ? CT.document : CT.template],
|
|
1472
|
+
["/word/styles.xml", CT.styles],
|
|
1473
|
+
["/word/numbering.xml", CT.numbering],
|
|
1474
|
+
["/word/settings.xml", CT.settings],
|
|
1475
|
+
["/word/fontTable.xml", CT.fontTable],
|
|
1476
|
+
["/word/theme/theme1.xml", CT.theme],
|
|
1477
|
+
[
|
|
1478
|
+
"/word/footnotes.xml",
|
|
1479
|
+
"application/vnd.openxmlformats-officedocument.wordprocessingml.footnotes+xml"
|
|
1480
|
+
],
|
|
1481
|
+
[
|
|
1482
|
+
"/word/endnotes.xml",
|
|
1483
|
+
"application/vnd.openxmlformats-officedocument.wordprocessingml.endnotes+xml"
|
|
1484
|
+
],
|
|
1485
|
+
["/docProps/core.xml", "application/vnd.openxmlformats-package.core-properties+xml"]
|
|
1486
|
+
];
|
|
1487
|
+
const rels = [
|
|
1488
|
+
["rId1", RT.styles, "styles.xml"],
|
|
1489
|
+
["rId2", RT.numbering, "numbering.xml"],
|
|
1490
|
+
["rId3", RT.settings, "settings.xml"],
|
|
1491
|
+
["rId4", RT.fontTable, "fontTable.xml"],
|
|
1492
|
+
["rId5", RT.theme, "theme/theme1.xml"],
|
|
1493
|
+
["rId6", `${RT.styles.replace("styles", "footnotes")}`, "footnotes.xml"],
|
|
1494
|
+
["rId7", `${RT.styles.replace("styles", "endnotes")}`, "endnotes.xml"]
|
|
1495
|
+
];
|
|
1496
|
+
put("word/styles.xml", legalStylesXml());
|
|
1497
|
+
put("word/numbering.xml", legalNumberingXml());
|
|
1498
|
+
put("word/fontTable.xml", FONT_TABLE);
|
|
1499
|
+
put("word/theme/theme1.xml", themeXml());
|
|
1500
|
+
put("word/footnotes.xml", NOTES("footnote"));
|
|
1501
|
+
put("word/endnotes.xml", NOTES("endnote"));
|
|
1502
|
+
const refs = [];
|
|
1503
|
+
const footer = para("", "Footer", '<w:jc w:val="center"/>').replace(
|
|
1504
|
+
"</w:p>",
|
|
1505
|
+
`${run("Page ")}${field("PAGE", "1")}${run(" of ")}${field("NUMPAGES", "1")}</w:p>`
|
|
1506
|
+
);
|
|
1507
|
+
put("word/footer1.xml", hdr("ftr", footer));
|
|
1508
|
+
overrides.push(["/word/footer1.xml", CT.footer]);
|
|
1509
|
+
rels.push(["rId20", RT.footer, "footer1.xml"]);
|
|
1510
|
+
refs.push('<w:footerReference w:type="default" r:id="rId20"/>');
|
|
1511
|
+
const mark = options.watermark ? watermarkXml(options.watermark) : "";
|
|
1512
|
+
if (options.letterhead) {
|
|
1513
|
+
files["word/media/letterhead-logo.png"] = placeholderPng();
|
|
1514
|
+
put(
|
|
1515
|
+
"word/header1.xml",
|
|
1516
|
+
hdr(
|
|
1517
|
+
"hdr",
|
|
1518
|
+
`${mark}<w:p><w:pPr><w:pStyle w:val="Header"/><w:jc w:val="right"/></w:pPr>${inlineImage(
|
|
1519
|
+
"rIdLogo",
|
|
1520
|
+
1828800,
|
|
1521
|
+
548640,
|
|
1522
|
+
1,
|
|
1523
|
+
"Logo placeholder"
|
|
1524
|
+
)}</w:p>${para("[Firm name]", "Header", '<w:jc w:val="right"/>')}${para(
|
|
1525
|
+
"[Address line] \xB7 [Telephone] \xB7 [Email] \xB7 [Website]",
|
|
1526
|
+
"Header",
|
|
1527
|
+
'<w:jc w:val="right"/>'
|
|
1528
|
+
)}`
|
|
1529
|
+
)
|
|
1530
|
+
);
|
|
1531
|
+
put(
|
|
1532
|
+
"word/_rels/header1.xml.rels",
|
|
1533
|
+
`${XML}<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rIdLogo" Type="${RT.image}" Target="media/letterhead-logo.png"/></Relationships>`
|
|
1534
|
+
);
|
|
1535
|
+
put(
|
|
1536
|
+
"word/header2.xml",
|
|
1537
|
+
hdr("hdr", `${mark}${para("[Document title]", "Header", '<w:jc w:val="right"/>')}`)
|
|
1538
|
+
);
|
|
1539
|
+
overrides.push(["/word/header1.xml", CT.header], ["/word/header2.xml", CT.header]);
|
|
1540
|
+
rels.push(["rId21", RT.header, "header1.xml"], ["rId22", RT.header, "header2.xml"]);
|
|
1541
|
+
refs.unshift(
|
|
1542
|
+
'<w:headerReference w:type="first" r:id="rId21"/>',
|
|
1543
|
+
'<w:headerReference w:type="default" r:id="rId22"/>'
|
|
1544
|
+
);
|
|
1545
|
+
refs.push('<w:footerReference w:type="first" r:id="rId20"/>');
|
|
1546
|
+
} else if (mark) {
|
|
1547
|
+
put("word/header1.xml", hdr("hdr", mark));
|
|
1548
|
+
overrides.push(["/word/header1.xml", CT.header]);
|
|
1549
|
+
rels.push(["rId21", RT.header, "header1.xml"]);
|
|
1550
|
+
refs.unshift('<w:headerReference w:type="default" r:id="rId21"/>');
|
|
1551
|
+
}
|
|
1552
|
+
const sectPr = `<w:sectPr>${refs.join("")}<w:pgSz w:w="11906" w:h="16838"/><w:pgMar w:top="1440" w:right="1440" w:bottom="1440" w:left="1440" w:header="708" w:footer="708" w:gutter="0"/><w:cols w:space="708"/>${options.letterhead ? "<w:titlePg/>" : ""}<w:docGrid w:linePitch="360"/></w:sectPr>`;
|
|
1553
|
+
put(
|
|
1554
|
+
"word/document.xml",
|
|
1555
|
+
`${XML}<w:document ${W_DECL} ${VML_DECL} ${DRAWING_DECL}><w:body>${options.body ?? "<w:p/>"}${sectPr}</w:body></w:document>`
|
|
1556
|
+
);
|
|
1557
|
+
put("word/settings.xml", settingsXml({}));
|
|
1558
|
+
if (options.buildingBlocks !== false) {
|
|
1559
|
+
put("word/glossary/document.xml", glossaryXml(LEGAL_BUILDING_BLOCKS));
|
|
1560
|
+
put("word/glossary/styles.xml", legalStylesXml());
|
|
1561
|
+
put("word/glossary/numbering.xml", legalNumberingXml());
|
|
1562
|
+
put(
|
|
1563
|
+
"word/glossary/_rels/document.xml.rels",
|
|
1564
|
+
`${XML}<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rId1" Type="${RT.styles}" Target="styles.xml"/><Relationship Id="rId2" Type="${RT.numbering}" Target="numbering.xml"/></Relationships>`
|
|
1565
|
+
);
|
|
1566
|
+
overrides.push(
|
|
1567
|
+
["/word/glossary/document.xml", CT.glossary],
|
|
1568
|
+
["/word/glossary/styles.xml", CT.styles],
|
|
1569
|
+
["/word/glossary/numbering.xml", CT.numbering]
|
|
1570
|
+
);
|
|
1571
|
+
rels.push(["rId30", RT.glossary, "glossary/document.xml"]);
|
|
1572
|
+
}
|
|
1573
|
+
put(
|
|
1574
|
+
"docProps/core.xml",
|
|
1575
|
+
`${XML}<cp:coreProperties xmlns:cp="http://schemas.openxmlformats.org/package/2006/metadata/core-properties" xmlns:dc="http://purl.org/dc/elements/1.1/"><dc:title>ARBI legal template</dc:title></cp:coreProperties>`
|
|
1576
|
+
);
|
|
1577
|
+
put(
|
|
1578
|
+
"word/_rels/document.xml.rels",
|
|
1579
|
+
`${XML}<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">${rels.map(([id, type, target]) => `<Relationship Id="${id}" Type="${type}" Target="${target}"/>`).join("")}</Relationships>`
|
|
1580
|
+
);
|
|
1581
|
+
put(
|
|
1582
|
+
"_rels/.rels",
|
|
1583
|
+
`${XML}<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rId1" Type="${RT.officeDocument}" Target="word/document.xml"/><Relationship Id="rId2" Type="http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties" Target="docProps/core.xml"/></Relationships>`
|
|
1584
|
+
);
|
|
1585
|
+
put(
|
|
1586
|
+
"[Content_Types].xml",
|
|
1587
|
+
`${XML}<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types"><Default Extension="rels" ContentType="${CT.rels}"/><Default Extension="xml" ContentType="application/xml"/><Default Extension="png" ContentType="image/png"/>${overrides.map(([p, t]) => `<Override PartName="${p}" ContentType="${t}"/>`).join("")}</Types>`
|
|
1588
|
+
);
|
|
1589
|
+
return zipSync(files, { level: 6 });
|
|
1590
|
+
}
|
|
1591
|
+
|
|
1592
|
+
// src/template/numbering.ts
|
|
1593
|
+
function linkedLevelStyles(document) {
|
|
1594
|
+
const pkg = Pkg.read(document);
|
|
1595
|
+
const part = pkg.partOf(pkg.main, RT.numbering);
|
|
1596
|
+
const numbering = part ? pkg.xml(part) : void 0;
|
|
1597
|
+
const out = {};
|
|
1598
|
+
for (const abs of numbering ? kids(numbering, "w:abstractNum") : []) {
|
|
1599
|
+
const levels = kids(abs, "w:lvl").map((l) => ({ ilvl: Number(l.attrs["w:ilvl"]), style: val(l, "w:pStyle") })).sort((a, b) => a.ilvl - b.ilvl);
|
|
1600
|
+
levels.forEach(({ style: style2 }, i) => {
|
|
1601
|
+
if (!style2 || out[style2]) return;
|
|
1602
|
+
const next = levels[i + 1]?.style;
|
|
1603
|
+
const previous = levels[i - 1]?.style;
|
|
1604
|
+
out[style2] = { ...next ? { next } : {}, ...previous ? { previous } : {} };
|
|
1605
|
+
});
|
|
1606
|
+
}
|
|
1607
|
+
return out;
|
|
1608
|
+
}
|
|
1609
|
+
|
|
1610
|
+
export { LEGAL_BUILDING_BLOCKS, LEGAL_NUM, TemplateError, applyTemplate, attachedTemplateOf, buildingBlockFragment, composeWithTemplate, defaultLegalTemplate, fragmentClipboardHtml, linkedLevelStyles, listBuildingBlocks, newFromTemplate, styleDivergence, trackInsertion };
|
|
1611
|
+
//# sourceMappingURL=template.js.map
|
|
1612
|
+
//# sourceMappingURL=template.js.map
|