@folijs/docx 0.3.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +53 -0
- package/README.md +72 -10
- package/dist/export/content.d.ts +2 -0
- package/dist/export/content.d.ts.map +1 -1
- package/dist/export/content.js +41 -3
- package/dist/export/content.js.map +1 -1
- package/dist/export/index.d.ts +14 -2
- package/dist/export/index.d.ts.map +1 -1
- package/dist/export/index.js +76 -15
- package/dist/export/index.js.map +1 -1
- package/dist/export/parts.d.ts.map +1 -1
- package/dist/export/parts.js +13 -0
- package/dist/export/parts.js.map +1 -1
- package/dist/export/pictures.d.ts +51 -0
- package/dist/export/pictures.d.ts.map +1 -0
- package/dist/export/pictures.js +346 -0
- package/dist/export/pictures.js.map +1 -0
- package/dist/export/properties.d.ts +11 -1
- package/dist/export/properties.d.ts.map +1 -1
- package/dist/export/properties.js +1 -1
- package/dist/export/properties.js.map +1 -1
- package/dist/export/tables.d.ts +27 -0
- package/dist/export/tables.d.ts.map +1 -0
- package/dist/export/tables.js +344 -0
- package/dist/export/tables.js.map +1 -0
- package/dist/images.d.ts +21 -0
- package/dist/images.d.ts.map +1 -0
- package/dist/images.js +53 -0
- package/dist/images.js.map +1 -0
- package/dist/import/content.d.ts +5 -1
- package/dist/import/content.d.ts.map +1 -1
- package/dist/import/content.js +161 -7
- package/dist/import/content.js.map +1 -1
- package/dist/import/index.d.ts +6 -1
- package/dist/import/index.d.ts.map +1 -1
- package/dist/import/index.js +16 -4
- package/dist/import/index.js.map +1 -1
- package/dist/import/ooxml.d.ts +1 -0
- package/dist/import/ooxml.d.ts.map +1 -1
- package/dist/import/ooxml.js +1 -0
- package/dist/import/ooxml.js.map +1 -1
- package/dist/import/parts.d.ts.map +1 -1
- package/dist/import/parts.js +7 -0
- package/dist/import/parts.js.map +1 -1
- package/dist/import/pictures.d.ts +34 -0
- package/dist/import/pictures.d.ts.map +1 -0
- package/dist/import/pictures.js +147 -0
- package/dist/import/pictures.js.map +1 -0
- package/dist/import/properties.d.ts.map +1 -1
- package/dist/import/properties.js +2 -1
- package/dist/import/properties.js.map +1 -1
- package/dist/import/report.d.ts +6 -0
- package/dist/import/report.d.ts.map +1 -1
- package/dist/import/report.js +5 -0
- package/dist/import/report.js.map +1 -1
- package/dist/import/tables.d.ts +31 -0
- package/dist/import/tables.d.ts.map +1 -0
- package/dist/import/tables.js +236 -0
- package/dist/import/tables.js.map +1 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/settings.d.ts +8 -0
- package/dist/settings.d.ts.map +1 -0
- package/dist/settings.js +72 -0
- package/dist/settings.js.map +1 -0
- package/package.json +2 -2
- package/src/export/content.ts +49 -5
- package/src/export/index.ts +135 -19
- package/src/export/parts.ts +15 -0
- package/src/export/pictures.ts +405 -0
- package/src/export/properties.ts +1 -1
- package/src/export/tables.ts +386 -0
- package/src/images.ts +60 -0
- package/src/import/content.ts +154 -9
- package/src/import/index.ts +20 -5
- package/src/import/ooxml.ts +1 -0
- package/src/import/parts.ts +13 -0
- package/src/import/pictures.ts +176 -0
- package/src/import/properties.ts +4 -1
- package/src/import/report.ts +11 -0
- package/src/import/tables.ts +267 -0
- package/src/index.ts +2 -1
- package/src/settings.ts +75 -0
package/src/settings.ts
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Word's document settings part (`settings.xml`): Foli reads and writes only
|
|
3
|
+
* `w:trackRevisions` (whether Word records edits as tracked changes); the rest is kept verbatim.
|
|
4
|
+
*/
|
|
5
|
+
import { isW, W } from "./import/ooxml.js";
|
|
6
|
+
import type { XmlElement } from "./xml.js";
|
|
7
|
+
|
|
8
|
+
/** Whether `settings` (the `w:settings` root) turns tracked changes on. */
|
|
9
|
+
export function trackRevisionsOf(settings: XmlElement | undefined): boolean {
|
|
10
|
+
const element = settings?.children.find(
|
|
11
|
+
(c): c is XmlElement => c.kind === "element" && isW(c, "trackRevisions"),
|
|
12
|
+
);
|
|
13
|
+
if (!element) return false;
|
|
14
|
+
const value = element.attributes.find((a) => a.ns === W && a.local === "val")?.value;
|
|
15
|
+
return value === undefined || !["false", "0", "off"].includes(value);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** Elements `w:settings` has before `w:trackRevisions` (ECMA-376 CT_Settings, in order). */
|
|
19
|
+
const BEFORE = new Set([
|
|
20
|
+
"writeProtection",
|
|
21
|
+
"view",
|
|
22
|
+
"zoom",
|
|
23
|
+
"removePersonalInformation",
|
|
24
|
+
"removeDateAndTime",
|
|
25
|
+
"doNotDisplayPageBoundaries",
|
|
26
|
+
"displayBackgroundShape",
|
|
27
|
+
"printPostScriptOverText",
|
|
28
|
+
"printFractionalCharacterWidth",
|
|
29
|
+
"printFormsData",
|
|
30
|
+
"embedTrueTypeFonts",
|
|
31
|
+
"embedSystemFonts",
|
|
32
|
+
"saveSubsetFonts",
|
|
33
|
+
"saveFormsData",
|
|
34
|
+
"mirrorMargins",
|
|
35
|
+
"alignBordersAndEdges",
|
|
36
|
+
"bordersDoNotSurroundHeader",
|
|
37
|
+
"bordersDoNotSurroundFooter",
|
|
38
|
+
"gutterAtTop",
|
|
39
|
+
"hideSpellingErrors",
|
|
40
|
+
"hideGrammaticalErrors",
|
|
41
|
+
"activeWritingStyle",
|
|
42
|
+
"proofState",
|
|
43
|
+
"formsDesign",
|
|
44
|
+
"attachedTemplate",
|
|
45
|
+
"linkStyles",
|
|
46
|
+
"stylePaneFormatFilter",
|
|
47
|
+
"stylePaneSortMethod",
|
|
48
|
+
"documentType",
|
|
49
|
+
"mailMerge",
|
|
50
|
+
"revisionView",
|
|
51
|
+
]);
|
|
52
|
+
|
|
53
|
+
/** `source` (a settings part, `root` its `w:settings`) with tracked changes `on`. */
|
|
54
|
+
export function withTrackRevisions(source: string, root: XmlElement, on: boolean): string {
|
|
55
|
+
if (trackRevisionsOf(root) === on) return source;
|
|
56
|
+
const children = root.children.filter((c): c is XmlElement => c.kind === "element");
|
|
57
|
+
const existing = children.find((c) => isW(c, "trackRevisions"));
|
|
58
|
+
const prefix = root.prefix ? `${root.prefix}:` : "";
|
|
59
|
+
const element = `<${prefix}trackRevisions/>`;
|
|
60
|
+
// Off: removed. On over an explicit "off": replaced.
|
|
61
|
+
if (existing)
|
|
62
|
+
return source.slice(0, existing.start) + (on ? element : "") + source.slice(existing.end);
|
|
63
|
+
const after = children.filter((c) => c.ns === W && BEFORE.has(c.local)).at(-1);
|
|
64
|
+
if (after) return source.slice(0, after.end) + element + source.slice(after.end);
|
|
65
|
+
if (root.openEnd === root.end) {
|
|
66
|
+
// `<w:settings/>`: opened and closed.
|
|
67
|
+
return `${source.slice(0, root.openEnd - 2)}>${element}</${root.name}>${source.slice(root.end)}`;
|
|
68
|
+
}
|
|
69
|
+
return source.slice(0, root.openEnd) + element + source.slice(root.openEnd);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** A new settings part with tracked changes on. */
|
|
73
|
+
export function newSettingsXml(): string {
|
|
74
|
+
return `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\r\n<w:settings xmlns:w="${W}"><w:trackRevisions/></w:settings>`;
|
|
75
|
+
}
|