@office-open/core 0.9.8 → 0.10.1
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/descriptor/index.mjs +1 -1
- package/dist/{descriptor-TtMXoZgS.mjs → descriptor-BdWTH1vv.mjs} +4 -3
- package/dist/drawingml/index.d.mts +1 -1
- package/dist/drawingml/index.mjs +1 -1
- package/dist/{index-CeVhA1an.d.mts → index-Bpw3LFuI.d.mts} +253 -209
- package/dist/index-DEeO4sOq.d.mts +239 -0
- package/dist/index.d.mts +3 -3
- package/dist/index.mjs +4 -4
- package/dist/patch/index.d.mts +2 -2
- package/dist/patch/index.mjs +2 -2
- package/dist/{patch-ilNZTQmG.mjs → patch-DocIv0Sn.mjs} +125 -3
- package/dist/{src-CSka9ln4.mjs → src-DaZbVB3f.mjs} +265 -154
- package/package.json +2 -2
- package/dist/index-DYy8l709.d.mts +0 -127
|
@@ -1,17 +1,13 @@
|
|
|
1
|
+
import "./patch-DocIv0Sn.mjs";
|
|
1
2
|
import "./smartart-DCY-Vdv7.mjs";
|
|
2
3
|
import "./chart-DwE8FCFk.mjs";
|
|
3
|
-
import { d as parse$1, f as stringify$1 } from "./descriptor-
|
|
4
|
-
import "./patch-ilNZTQmG.mjs";
|
|
4
|
+
import { d as parse$1, f as stringify$1 } from "./descriptor-BdWTH1vv.mjs";
|
|
5
5
|
import "./theme-CiNzdl-9.mjs";
|
|
6
|
-
import { attr, attrNum, element, escapeXml, findChild, js2xml, stringify, textOf, xml2js } from "@office-open/xml";
|
|
6
|
+
import { attr, attrMeasure, attrNum, element, escapeXml, findChild, js2xml, stringify, textOf, xml2js } from "@office-open/xml";
|
|
7
7
|
import { AsyncZipDeflate, Zip, ZipPassThrough, strFromU8, strFromU8 as strFromU8$1, strToU8, unzipSync, unzipSync as unzipSync$1, zip, zipSync } from "fflate";
|
|
8
8
|
import { sha1 } from "@noble/hashes/legacy.js";
|
|
9
9
|
import { bytesToHex } from "@noble/hashes/utils.js";
|
|
10
10
|
import { sha512 } from "@noble/hashes/sha2.js";
|
|
11
|
-
//#region src/opc/app-properties.ts
|
|
12
|
-
/** Static app properties XML constant. */
|
|
13
|
-
const APP_PROPS_XML = "<Properties xmlns=\"http://schemas.openxmlformats.org/officeDocument/2006/extended-properties\" xmlns:vt=\"http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes\"><Application>Microsoft Office Word</Application></Properties>";
|
|
14
|
-
//#endregion
|
|
15
11
|
//#region src/opc/relationships.ts
|
|
16
12
|
const TargetModeType = { EXTERNAL: "External" };
|
|
17
13
|
/**
|
|
@@ -55,103 +51,162 @@ const createDefault = (contentType, extension) => extension !== void 0 ? `<Defau
|
|
|
55
51
|
*/
|
|
56
52
|
const createOverride = (contentType, partName) => partName !== void 0 ? `<Override ContentType="${contentType}" PartName="${partName}"/>` : `<Override ContentType="${contentType}"/>`;
|
|
57
53
|
//#endregion
|
|
58
|
-
//#region src/opc/
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
{
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
54
|
+
//#region src/opc/app-properties.ts
|
|
55
|
+
/**
|
|
56
|
+
* Extended (App) Properties module — shared OPC part (docProps/app.xml).
|
|
57
|
+
*
|
|
58
|
+
* Format-agnostic: CT_Properties (ISO-IEC29500-2_2016 shared-documentPropertiesExtended.xsd)
|
|
59
|
+
* is identical across docx/pptx/xlsx. Each package surfaces only the fields it populates
|
|
60
|
+
* (Pages/Words for docx, Slides for pptx, etc.) — all fields are optional.
|
|
61
|
+
*
|
|
62
|
+
* @module
|
|
63
|
+
*/
|
|
64
|
+
/** xsd:boolean lexical form — spec canonical form is "true"/"false" (Word's convention). */
|
|
65
|
+
const xsdBoolean = (value) => value ? "true" : "false";
|
|
66
|
+
const appPropertiesDesc = {
|
|
67
|
+
kind: "custom",
|
|
68
|
+
stringify(opts, _ctx) {
|
|
69
|
+
const p = ["<Properties xmlns=\"http://schemas.openxmlformats.org/officeDocument/2006/extended-properties\" xmlns:vt=\"http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes\">"];
|
|
70
|
+
if (opts.template !== void 0) p.push(`<Template>${escapeXml(opts.template)}</Template>`);
|
|
71
|
+
if (opts.manager !== void 0) p.push(`<Manager>${escapeXml(opts.manager)}</Manager>`);
|
|
72
|
+
if (opts.company !== void 0) p.push(`<Company>${escapeXml(opts.company)}</Company>`);
|
|
73
|
+
if (opts.pages !== void 0) p.push(`<Pages>${opts.pages}</Pages>`);
|
|
74
|
+
if (opts.words !== void 0) p.push(`<Words>${opts.words}</Words>`);
|
|
75
|
+
if (opts.characters !== void 0) p.push(`<Characters>${opts.characters}</Characters>`);
|
|
76
|
+
if (opts.lines !== void 0) p.push(`<Lines>${opts.lines}</Lines>`);
|
|
77
|
+
if (opts.paragraphs !== void 0) p.push(`<Paragraphs>${opts.paragraphs}</Paragraphs>`);
|
|
78
|
+
if (opts.slides !== void 0) p.push(`<Slides>${opts.slides}</Slides>`);
|
|
79
|
+
if (opts.notes !== void 0) p.push(`<Notes>${opts.notes}</Notes>`);
|
|
80
|
+
if (opts.totalTime !== void 0) p.push(`<TotalTime>${opts.totalTime}</TotalTime>`);
|
|
81
|
+
if (opts.hiddenSlides !== void 0) p.push(`<HiddenSlides>${opts.hiddenSlides}</HiddenSlides>`);
|
|
82
|
+
if (opts.mmClips !== void 0) p.push(`<MMClips>${opts.mmClips}</MMClips>`);
|
|
83
|
+
if (opts.scaleCrop !== void 0) p.push(`<ScaleCrop>${xsdBoolean(opts.scaleCrop)}</ScaleCrop>`);
|
|
84
|
+
if (opts.linksUpToDate !== void 0) p.push(`<LinksUpToDate>${xsdBoolean(opts.linksUpToDate)}</LinksUpToDate>`);
|
|
85
|
+
if (opts.charactersWithSpaces !== void 0) p.push(`<CharactersWithSpaces>${opts.charactersWithSpaces}</CharactersWithSpaces>`);
|
|
86
|
+
if (opts.sharedDoc !== void 0) p.push(`<SharedDoc>${xsdBoolean(opts.sharedDoc)}</SharedDoc>`);
|
|
87
|
+
if (opts.hyperlinkBase !== void 0) p.push(`<HyperlinkBase>${escapeXml(opts.hyperlinkBase)}</HyperlinkBase>`);
|
|
88
|
+
if (opts.hyperlinksChanged !== void 0) p.push(`<HyperlinksChanged>${xsdBoolean(opts.hyperlinksChanged)}</HyperlinksChanged>`);
|
|
89
|
+
if (opts.application !== void 0) p.push(`<Application>${escapeXml(opts.application)}</Application>`);
|
|
90
|
+
if (opts.appVersion !== void 0) p.push(`<AppVersion>${escapeXml(opts.appVersion)}</AppVersion>`);
|
|
91
|
+
if (opts.docSecurity !== void 0) p.push(`<DocSecurity>${opts.docSecurity}</DocSecurity>`);
|
|
92
|
+
p.push("</Properties>");
|
|
93
|
+
return p.join("");
|
|
79
94
|
},
|
|
80
|
-
{
|
|
81
|
-
|
|
82
|
-
|
|
95
|
+
parse(el, _ctx) {
|
|
96
|
+
const result = {};
|
|
97
|
+
for (const child of el.elements ?? []) {
|
|
98
|
+
if (typeof child.name !== "string") continue;
|
|
99
|
+
const text = child.elements?.[0]?.text;
|
|
100
|
+
switch (child.name) {
|
|
101
|
+
case "Template":
|
|
102
|
+
if (typeof text === "string") result.template = text;
|
|
103
|
+
break;
|
|
104
|
+
case "Manager":
|
|
105
|
+
if (typeof text === "string") result.manager = text;
|
|
106
|
+
break;
|
|
107
|
+
case "Company":
|
|
108
|
+
if (typeof text === "string") result.company = text;
|
|
109
|
+
break;
|
|
110
|
+
case "Pages":
|
|
111
|
+
if (typeof text === "string") result.pages = Number(text);
|
|
112
|
+
break;
|
|
113
|
+
case "Words":
|
|
114
|
+
if (typeof text === "string") result.words = Number(text);
|
|
115
|
+
break;
|
|
116
|
+
case "Characters":
|
|
117
|
+
if (typeof text === "string") result.characters = Number(text);
|
|
118
|
+
break;
|
|
119
|
+
case "Lines":
|
|
120
|
+
if (typeof text === "string") result.lines = Number(text);
|
|
121
|
+
break;
|
|
122
|
+
case "Paragraphs":
|
|
123
|
+
if (typeof text === "string") result.paragraphs = Number(text);
|
|
124
|
+
break;
|
|
125
|
+
case "Slides":
|
|
126
|
+
if (typeof text === "string") result.slides = Number(text);
|
|
127
|
+
break;
|
|
128
|
+
case "Notes":
|
|
129
|
+
if (typeof text === "string") result.notes = Number(text);
|
|
130
|
+
break;
|
|
131
|
+
case "TotalTime":
|
|
132
|
+
if (typeof text === "string") result.totalTime = Number(text);
|
|
133
|
+
break;
|
|
134
|
+
case "HiddenSlides":
|
|
135
|
+
if (typeof text === "string") result.hiddenSlides = Number(text);
|
|
136
|
+
break;
|
|
137
|
+
case "MMClips":
|
|
138
|
+
if (typeof text === "string") result.mmClips = Number(text);
|
|
139
|
+
break;
|
|
140
|
+
case "ScaleCrop":
|
|
141
|
+
if (typeof text === "string") result.scaleCrop = text === "1" || text === "true";
|
|
142
|
+
break;
|
|
143
|
+
case "LinksUpToDate":
|
|
144
|
+
if (typeof text === "string") result.linksUpToDate = text === "1" || text === "true";
|
|
145
|
+
break;
|
|
146
|
+
case "CharactersWithSpaces":
|
|
147
|
+
if (typeof text === "string") result.charactersWithSpaces = Number(text);
|
|
148
|
+
break;
|
|
149
|
+
case "SharedDoc":
|
|
150
|
+
if (typeof text === "string") result.sharedDoc = text === "1" || text === "true";
|
|
151
|
+
break;
|
|
152
|
+
case "HyperlinkBase":
|
|
153
|
+
if (typeof text === "string") result.hyperlinkBase = text;
|
|
154
|
+
break;
|
|
155
|
+
case "HyperlinksChanged":
|
|
156
|
+
if (typeof text === "string") result.hyperlinksChanged = text === "1" || text === "true";
|
|
157
|
+
break;
|
|
158
|
+
case "Application":
|
|
159
|
+
if (typeof text === "string") result.application = text;
|
|
160
|
+
break;
|
|
161
|
+
case "AppVersion":
|
|
162
|
+
if (typeof text === "string") result.appVersion = text;
|
|
163
|
+
break;
|
|
164
|
+
case "DocSecurity":
|
|
165
|
+
if (typeof text === "string") result.docSecurity = Number(text);
|
|
166
|
+
break;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
return result;
|
|
83
170
|
}
|
|
84
|
-
|
|
171
|
+
};
|
|
172
|
+
//#endregion
|
|
173
|
+
//#region src/opc/custom-properties.ts
|
|
85
174
|
/**
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
const n = Number(rev);
|
|
102
|
-
if (!isNaN(n)) props.revision = rev;
|
|
175
|
+
* Custom Properties module — shared OPC part (docProps/custom.xml).
|
|
176
|
+
*
|
|
177
|
+
* Format-agnostic: CT_CustomProperties (ISO-IEC29500-4_2016 shared-documentPropertiesCustom.xsd)
|
|
178
|
+
* is identical across docx/pptx/xlsx.
|
|
179
|
+
*
|
|
180
|
+
* @module
|
|
181
|
+
*/
|
|
182
|
+
const customPropertiesDesc = {
|
|
183
|
+
kind: "custom",
|
|
184
|
+
stringify(opts, _ctx) {
|
|
185
|
+
const p = ["<Properties xmlns=\"http://schemas.openxmlformats.org/officeDocument/2006/custom-properties\" xmlns:vt=\"http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes\">"];
|
|
186
|
+
let pid = 2;
|
|
187
|
+
for (const prop of opts.properties) {
|
|
188
|
+
p.push(`<property fmtid="{D5CDD505-2E9C-101B-9397-08002B2CF9AE}" pid="${pid}" name="${escapeXml(prop.name)}"><vt:lpwstr>${escapeXml(prop.value)}</vt:lpwstr></property>`);
|
|
189
|
+
pid++;
|
|
103
190
|
}
|
|
191
|
+
p.push("</Properties>");
|
|
192
|
+
return p.join("");
|
|
193
|
+
},
|
|
194
|
+
parse(el, _ctx) {
|
|
195
|
+
const properties = [];
|
|
196
|
+
for (const child of el.elements ?? []) {
|
|
197
|
+
if (child.name !== "property") continue;
|
|
198
|
+
const name = attr(child, "name");
|
|
199
|
+
if (!name) continue;
|
|
200
|
+
const valueEl = child.elements?.find((e) => e.name?.startsWith("vt:"));
|
|
201
|
+
const value = valueEl ? textOf(valueEl) ?? "" : "";
|
|
202
|
+
properties.push({
|
|
203
|
+
name,
|
|
204
|
+
value
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
return { properties };
|
|
104
208
|
}
|
|
105
|
-
|
|
106
|
-
}
|
|
107
|
-
const CORE_PROPS_NS = Object.freeze({ _attr: Object.freeze({
|
|
108
|
-
"xmlns:cp": "http://schemas.openxmlformats.org/package/2006/metadata/core-properties",
|
|
109
|
-
"xmlns:dc": "http://purl.org/dc/elements/1.1/",
|
|
110
|
-
"xmlns:dcmitype": "http://purl.org/dc/dcmitype/",
|
|
111
|
-
"xmlns:dcterms": "http://purl.org/dc/terms/",
|
|
112
|
-
"xmlns:xsi": "http://www.w3.org/2001/XMLSchema-instance"
|
|
113
|
-
}) });
|
|
114
|
-
const W3CDTF_ATTR = Object.freeze({ _attr: Object.freeze({ "xsi:type": "dcterms:W3CDTF" }) });
|
|
115
|
-
/**
|
|
116
|
-
* Build a cp:coreProperties XML object from metadata.
|
|
117
|
-
*
|
|
118
|
-
* Shared by docx and pptx to avoid duplicating namespace declarations
|
|
119
|
-
* and Dublin Core property construction.
|
|
120
|
-
*/
|
|
121
|
-
function buildCorePropertiesXml(opts) {
|
|
122
|
-
const children = [CORE_PROPS_NS];
|
|
123
|
-
if (opts.title) children.push({ "dc:title": [opts.title] });
|
|
124
|
-
if (opts.subject) children.push({ "dc:subject": [opts.subject] });
|
|
125
|
-
if (opts.creator) children.push({ "dc:creator": [opts.creator] });
|
|
126
|
-
if (opts.keywords) children.push({ "cp:keywords": [opts.keywords] });
|
|
127
|
-
if (opts.description) children.push({ "dc:description": [opts.description] });
|
|
128
|
-
children.push({ "cp:lastModifiedBy": [opts.lastModifiedBy || opts.creator || "Unknown"] });
|
|
129
|
-
if (opts.revision) children.push({ "cp:revision": [String(opts.revision)] });
|
|
130
|
-
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
131
|
-
children.push({ "dcterms:created": [W3CDTF_ATTR, now] });
|
|
132
|
-
children.push({ "dcterms:modified": [W3CDTF_ATTR, now] });
|
|
133
|
-
return { "cp:coreProperties": children };
|
|
134
|
-
}
|
|
135
|
-
/**
|
|
136
|
-
* Build a cp:coreProperties XML string directly (fast path).
|
|
137
|
-
*
|
|
138
|
-
* Shared by pptx and xlsx to bypass the toXml() → xml() pipeline.
|
|
139
|
-
*/
|
|
140
|
-
function buildCorePropertiesXmlString(opts) {
|
|
141
|
-
const p = ["<cp:coreProperties xmlns:cp=\"http://schemas.openxmlformats.org/package/2006/metadata/core-properties\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:dcmitype=\"http://purl.org/dc/dcmitype/\" xmlns:dcterms=\"http://purl.org/dc/terms/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">"];
|
|
142
|
-
if (opts.title) p.push(`<dc:title>${escapeXml(opts.title)}</dc:title>`);
|
|
143
|
-
if (opts.subject) p.push(`<dc:subject>${escapeXml(opts.subject)}</dc:subject>`);
|
|
144
|
-
if (opts.creator) p.push(`<dc:creator>${escapeXml(opts.creator)}</dc:creator>`);
|
|
145
|
-
if (opts.keywords) p.push(`<cp:keywords>${escapeXml(opts.keywords)}</cp:keywords>`);
|
|
146
|
-
if (opts.description) p.push(`<dc:description>${escapeXml(opts.description)}</dc:description>`);
|
|
147
|
-
p.push(`<cp:lastModifiedBy>${escapeXml(opts.lastModifiedBy || opts.creator || "Unknown")}</cp:lastModifiedBy>`);
|
|
148
|
-
if (opts.revision) p.push(`<cp:revision>${opts.revision}</cp:revision>`);
|
|
149
|
-
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
150
|
-
p.push(`<dcterms:created xsi:type="dcterms:W3CDTF">${now}</dcterms:created>`);
|
|
151
|
-
p.push(`<dcterms:modified xsi:type="dcterms:W3CDTF">${now}</dcterms:modified>`);
|
|
152
|
-
p.push("</cp:coreProperties>");
|
|
153
|
-
return p.join("");
|
|
154
|
-
}
|
|
209
|
+
};
|
|
155
210
|
//#endregion
|
|
156
211
|
//#region \0polyfill-node.global.js
|
|
157
212
|
var _polyfill_node_global_default = typeof _polyfill_node_global_default !== "undefined" ? _polyfill_node_global_default : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {};
|
|
@@ -1404,6 +1459,49 @@ function isSlowBuffer(obj) {
|
|
|
1404
1459
|
return typeof obj.readFloatLE === "function" && typeof obj.slice === "function" && isFastBuffer(obj.slice(0, 0));
|
|
1405
1460
|
}
|
|
1406
1461
|
//#endregion
|
|
1462
|
+
//#region src/util/base64.ts
|
|
1463
|
+
/**
|
|
1464
|
+
* Shared base64 encode/decode helpers.
|
|
1465
|
+
*
|
|
1466
|
+
* Both prefer the native `Uint8Array` base64 methods (Node 22+, modern
|
|
1467
|
+
* browsers): they avoid the intermediate binary string that `btoa`/`atob`
|
|
1468
|
+
* materialize and cannot stack-overflow on large buffers. Node `Buffer` is the
|
|
1469
|
+
* secondary path; a manual loop covers older runtimes.
|
|
1470
|
+
*
|
|
1471
|
+
* @module
|
|
1472
|
+
*/
|
|
1473
|
+
/**
|
|
1474
|
+
* Decode a base64 string into a `Uint8Array`.
|
|
1475
|
+
*
|
|
1476
|
+
* Prefers native `Uint8Array.fromBase64` (no intermediate binary string), then
|
|
1477
|
+
* Node `Buffer` (zero-copy), then `atob`.
|
|
1478
|
+
*/
|
|
1479
|
+
function decodeBase64(input) {
|
|
1480
|
+
const fromBase64 = Uint8Array.fromBase64;
|
|
1481
|
+
if (typeof fromBase64 === "function") return fromBase64.call(Uint8Array, input);
|
|
1482
|
+
if (typeof Buffer !== "undefined") return Buffer.from(input, "base64");
|
|
1483
|
+
return Uint8Array.from(atob(input), (c) => c.codePointAt(0));
|
|
1484
|
+
}
|
|
1485
|
+
/**
|
|
1486
|
+
* Encode a `Uint8Array` into a base64 string.
|
|
1487
|
+
*
|
|
1488
|
+
* Prefers native `Uint8Array.prototype.toBase64` (no intermediate binary
|
|
1489
|
+
* string), then Node `Buffer` (zero-copy), then a `btoa` fallback.
|
|
1490
|
+
*
|
|
1491
|
+
* The fallback builds the binary string in a loop rather than
|
|
1492
|
+
* `String.fromCharCode(...bytes)` — the spread form places every byte on the
|
|
1493
|
+
* call stack and overflows for large buffers (V8 caps function arguments near
|
|
1494
|
+
* ~65k).
|
|
1495
|
+
*/
|
|
1496
|
+
function encodeBase64(bytes) {
|
|
1497
|
+
const toBase64 = Uint8Array.prototype.toBase64;
|
|
1498
|
+
if (typeof toBase64 === "function") return toBase64.call(bytes);
|
|
1499
|
+
if (typeof Buffer !== "undefined") return Buffer.from(bytes).toString("base64");
|
|
1500
|
+
let binary = "";
|
|
1501
|
+
for (let i = 0; i < bytes.length; i++) binary += String.fromCharCode(bytes[i]);
|
|
1502
|
+
return btoa(binary);
|
|
1503
|
+
}
|
|
1504
|
+
//#endregion
|
|
1407
1505
|
//#region src/opc/output.ts
|
|
1408
1506
|
/**
|
|
1409
1507
|
* Output type definitions for OOXML document export.
|
|
@@ -1421,7 +1519,7 @@ const convertOutput = (data, type, mimeType = OoxmlMimeType.DOCX) => {
|
|
|
1421
1519
|
case "blob": return new Blob([data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength)], { type: mimeType });
|
|
1422
1520
|
case "arraybuffer": return data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength);
|
|
1423
1521
|
case "uint8array": return data;
|
|
1424
|
-
case "base64": return
|
|
1522
|
+
case "base64": return encodeBase64(data);
|
|
1425
1523
|
case "string":
|
|
1426
1524
|
case "text":
|
|
1427
1525
|
case "binarystring": return strFromU8(data, true);
|
|
@@ -1616,38 +1714,6 @@ async function nativeZipAsync(files, level = 6) {
|
|
|
1616
1714
|
*
|
|
1617
1715
|
* @module
|
|
1618
1716
|
*/
|
|
1619
|
-
const DATA_URL_RE = /^data:([\w.+-]+\/[\w.+-]+)?;base64,/;
|
|
1620
|
-
/** Test whether a string is a base64 data URL (`data:[mime];base64,...`). */
|
|
1621
|
-
function isBase64DataURL(input) {
|
|
1622
|
-
return DATA_URL_RE.test(input);
|
|
1623
|
-
}
|
|
1624
|
-
/**
|
|
1625
|
-
* Decode a base64 string into a Uint8Array using the most efficient path
|
|
1626
|
-
* available: Node `Buffer` (zero-copy) > `Uint8Array.fromBase64()` (2025
|
|
1627
|
-
* baseline, no intermediate binary string) > `atob` fallback. Prefer this over
|
|
1628
|
-
* raw `atob` for large payloads — `atob` materializes a UCS-2 binary string
|
|
1629
|
-
* (~2x memory) before the byte array.
|
|
1630
|
-
*/
|
|
1631
|
-
function decodeBase64(input) {
|
|
1632
|
-
if (typeof Buffer !== "undefined") return Buffer.from(input, "base64");
|
|
1633
|
-
const fromBase64 = Uint8Array.fromBase64;
|
|
1634
|
-
if (typeof fromBase64 === "function") return fromBase64.call(Uint8Array, input);
|
|
1635
|
-
return Uint8Array.from(atob(input), (c) => c.codePointAt(0));
|
|
1636
|
-
}
|
|
1637
|
-
function toUint8Array(data) {
|
|
1638
|
-
if (data instanceof Uint8Array) return data;
|
|
1639
|
-
if (data instanceof ArrayBuffer) return new Uint8Array(data);
|
|
1640
|
-
if (data instanceof DataView) return new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
|
|
1641
|
-
if (typeof data === "string") {
|
|
1642
|
-
const match = data.match(DATA_URL_RE);
|
|
1643
|
-
if (match) return decodeBase64(data.slice(match[0].length));
|
|
1644
|
-
return new TextEncoder().encode(data);
|
|
1645
|
-
}
|
|
1646
|
-
if (Array.isArray(data)) return new Uint8Array(data);
|
|
1647
|
-
if (data instanceof Blob) throw new TypeError("Blob input requires async processing");
|
|
1648
|
-
if (data instanceof ReadableStream) throw new TypeError("ReadableStream input requires async processing");
|
|
1649
|
-
throw new TypeError(`Unsupported data type: ${typeof data}`);
|
|
1650
|
-
}
|
|
1651
1717
|
/** Default DEFLATE level for XML entries (SuperFast, matching MS Office). */
|
|
1652
1718
|
const ZIP_DEFLATE_LEVEL = 1;
|
|
1653
1719
|
/** Default level for media entries (STORE — no compression). */
|
|
@@ -2715,6 +2781,30 @@ const XLSX_PARTS = {
|
|
|
2715
2781
|
kind: "conditional",
|
|
2716
2782
|
flag: "any formula cell"
|
|
2717
2783
|
}
|
|
2784
|
+
},
|
|
2785
|
+
{
|
|
2786
|
+
path: "xl/revisionHeaders.xml",
|
|
2787
|
+
contentType: "application/vnd.openxmlformats-officedocument.spreadsheetml.revisionHeaders+xml",
|
|
2788
|
+
presence: {
|
|
2789
|
+
kind: "conditional",
|
|
2790
|
+
flag: "revisionLog"
|
|
2791
|
+
}
|
|
2792
|
+
},
|
|
2793
|
+
{
|
|
2794
|
+
path: "xl/revisions/revision${i}.xml",
|
|
2795
|
+
contentType: "application/vnd.openxmlformats-officedocument.spreadsheetml.revisionLog+xml",
|
|
2796
|
+
presence: {
|
|
2797
|
+
kind: "repeated",
|
|
2798
|
+
countFrom: "revisionLog.logs.length"
|
|
2799
|
+
}
|
|
2800
|
+
},
|
|
2801
|
+
{
|
|
2802
|
+
path: "xl/users.xml",
|
|
2803
|
+
contentType: "application/vnd.openxmlformats-officedocument.spreadsheetml.users+xml",
|
|
2804
|
+
presence: {
|
|
2805
|
+
kind: "conditional",
|
|
2806
|
+
flag: "revisionLog.users"
|
|
2807
|
+
}
|
|
2718
2808
|
}
|
|
2719
2809
|
]
|
|
2720
2810
|
};
|
|
@@ -3336,6 +3426,38 @@ const createColorElement = (color) => {
|
|
|
3336
3426
|
*/
|
|
3337
3427
|
const createSolidFill = (options) => element("a:solidFill", void 0, [createColorElement(options)]);
|
|
3338
3428
|
//#endregion
|
|
3429
|
+
//#region src/util/data-type.ts
|
|
3430
|
+
/**
|
|
3431
|
+
* Binary input normalization.
|
|
3432
|
+
*
|
|
3433
|
+
* Accepts the full range of binary inputs (Buffer/Uint8Array/ArrayBuffer/
|
|
3434
|
+
* DataView/number[]/string/base64 data URL/…) and normalizes to `Uint8Array`.
|
|
3435
|
+
* Centralized here so every entry point (packer, patch, descriptor helpers)
|
|
3436
|
+
* shares one definition instead of re-declaring per module.
|
|
3437
|
+
*
|
|
3438
|
+
* @module
|
|
3439
|
+
*/
|
|
3440
|
+
const DATA_URL_RE = /^data:([\w.+-]+\/[\w.+-]+)?;base64,/;
|
|
3441
|
+
/** Test whether a string is a base64 data URL (`data:[mime];base64,...`). */
|
|
3442
|
+
function isBase64DataURL(input) {
|
|
3443
|
+
return DATA_URL_RE.test(input);
|
|
3444
|
+
}
|
|
3445
|
+
/** Normalize any supported binary input to a `Uint8Array`. */
|
|
3446
|
+
function toUint8Array(data) {
|
|
3447
|
+
if (data instanceof Uint8Array) return data;
|
|
3448
|
+
if (data instanceof ArrayBuffer) return new Uint8Array(data);
|
|
3449
|
+
if (data instanceof DataView) return new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
|
|
3450
|
+
if (typeof data === "string") {
|
|
3451
|
+
const match = data.match(DATA_URL_RE);
|
|
3452
|
+
if (match) return decodeBase64(data.slice(match[0].length));
|
|
3453
|
+
return new TextEncoder().encode(data);
|
|
3454
|
+
}
|
|
3455
|
+
if (Array.isArray(data)) return new Uint8Array(data);
|
|
3456
|
+
if (data instanceof Blob) throw new TypeError("Blob input requires async processing");
|
|
3457
|
+
if (data instanceof ReadableStream) throw new TypeError("ReadableStream input requires async processing");
|
|
3458
|
+
throw new TypeError(`Unsupported data type: ${typeof data}`);
|
|
3459
|
+
}
|
|
3460
|
+
//#endregion
|
|
3339
3461
|
//#region src/util/generators.ts
|
|
3340
3462
|
/**
|
|
3341
3463
|
* Unique ID generation utilities.
|
|
@@ -7576,13 +7698,13 @@ const transform2DDesc = {
|
|
|
7576
7698
|
}
|
|
7577
7699
|
const off = findChild(el, "a:off");
|
|
7578
7700
|
if (off?.attributes) {
|
|
7579
|
-
result.x =
|
|
7580
|
-
result.y =
|
|
7701
|
+
result.x = attrMeasure(off, "x") ?? 0;
|
|
7702
|
+
result.y = attrMeasure(off, "y") ?? 0;
|
|
7581
7703
|
}
|
|
7582
7704
|
const ext = findChild(el, "a:ext");
|
|
7583
7705
|
if (ext?.attributes) {
|
|
7584
|
-
result.width =
|
|
7585
|
-
result.height =
|
|
7706
|
+
result.width = attrMeasure(ext, "cx") ?? 0;
|
|
7707
|
+
result.height = attrMeasure(ext, "cy") ?? 0;
|
|
7586
7708
|
}
|
|
7587
7709
|
return result;
|
|
7588
7710
|
}
|
|
@@ -7600,13 +7722,13 @@ const groupTransform2DDesc = {
|
|
|
7600
7722
|
const result = transform2DDesc.parse(el, ctx);
|
|
7601
7723
|
const chOff = findChild(el, "a:chOff");
|
|
7602
7724
|
if (chOff?.attributes) {
|
|
7603
|
-
result.childOffsetX =
|
|
7604
|
-
result.childOffsetY =
|
|
7725
|
+
result.childOffsetX = attrMeasure(chOff, "x") ?? 0;
|
|
7726
|
+
result.childOffsetY = attrMeasure(chOff, "y") ?? 0;
|
|
7605
7727
|
}
|
|
7606
7728
|
const chExt = findChild(el, "a:chExt");
|
|
7607
7729
|
if (chExt?.attributes) {
|
|
7608
|
-
result.childExtentWidth =
|
|
7609
|
-
result.childExtentHeight =
|
|
7730
|
+
result.childExtentWidth = attrMeasure(chExt, "cx") ?? 0;
|
|
7731
|
+
result.childExtentHeight = attrMeasure(chExt, "cy") ?? 0;
|
|
7610
7732
|
}
|
|
7611
7733
|
return result;
|
|
7612
7734
|
}
|
|
@@ -8231,17 +8353,6 @@ function compileMapping(mapping, overrides, media, mediaLevel = 0) {
|
|
|
8231
8353
|
*
|
|
8232
8354
|
* @module
|
|
8233
8355
|
*/
|
|
8234
|
-
let _bufToBase64;
|
|
8235
|
-
try {
|
|
8236
|
-
const { Buffer: Buf } = await import("node:buffer");
|
|
8237
|
-
_bufToBase64 = (bytes) => Buf.from(bytes).toString("base64");
|
|
8238
|
-
} catch {}
|
|
8239
|
-
function toBase64(bytes) {
|
|
8240
|
-
if (_bufToBase64) return _bufToBase64(bytes);
|
|
8241
|
-
let binary = "";
|
|
8242
|
-
for (let i = 0; i < bytes.length; i++) binary += String.fromCharCode(bytes[i]);
|
|
8243
|
-
return btoa(binary);
|
|
8244
|
-
}
|
|
8245
8356
|
function utf16leEncode(str) {
|
|
8246
8357
|
const bytes = new Uint8Array(str.length * 2);
|
|
8247
8358
|
for (let i = 0; i < str.length; i++) {
|
|
@@ -8278,7 +8389,7 @@ function hashPasswordAgile(password, salt, spinCount) {
|
|
|
8278
8389
|
buf[h.length + 3] = i >> 24 & 255;
|
|
8279
8390
|
h = sha512(buf);
|
|
8280
8391
|
}
|
|
8281
|
-
return
|
|
8392
|
+
return encodeBase64(new Uint8Array(h));
|
|
8282
8393
|
}
|
|
8283
8394
|
/**
|
|
8284
8395
|
* Derives a password hash for OOXML document protection.
|
|
@@ -8290,7 +8401,7 @@ function derivePasswordHash(password, spinCount = 1e5) {
|
|
|
8290
8401
|
const salt = randomBytes(16);
|
|
8291
8402
|
return {
|
|
8292
8403
|
hashValue: hashPasswordAgile(password, salt, spinCount),
|
|
8293
|
-
saltValue:
|
|
8404
|
+
saltValue: encodeBase64(salt),
|
|
8294
8405
|
spinCount,
|
|
8295
8406
|
algorithmName: "SHA-512"
|
|
8296
8407
|
};
|
|
@@ -8479,4 +8590,4 @@ function replaceHyperlinkPlaceholders(xml, hyperlinks, offset) {
|
|
|
8479
8590
|
return replacePlaceholders(xml, map);
|
|
8480
8591
|
}
|
|
8481
8592
|
//#endregion
|
|
8482
|
-
export { solidFillDesc as $, createTileInfo as $n,
|
|
8593
|
+
export { solidFillDesc as $, createTileInfo as $n, unzipSync$1 as $r, convertToTwip as $t, bevelDesc as A, createFillOverlayEffect as An, SchemeColor as Ar, createHierBranch as At, shapeLockingDesc as B, createLineEnd as Bn, PART_REGISTRIES as Br, createTableStyleList as Bt, diagramStyleDesc as C, PresetShadowVal as Cn, uniqueUuid as Cr, AnimateOneByOneValue as Ct, sourceRectangleDesc as D, createInnerShadowEffect as Dn, createSolidFill as Dr, createAdjustList as Dt, blipFillDesc as E, createOuterShadowEffect as En, createColorElement as Er, createAdjust as Et, customGeometryDesc as F, PresetDash as Fn, createPresetColor as Fr, createGraphicFrameLocking as Ft, patternFillDesc as G, extractBlipFillMedia as Gn, ParsedArchive as Gr, convertEmuToPoints as Gt, outlineDesc as H, createGroupFill as Hn, XLSX_PARTS as Hr, createTransformation as Ht, presetGeometryDesc as I, createOutline as In, createHslColor as Ir, createGroupLocking as It, parseColorChoice as J, PathShadeType as Jn, ZIP_STORED_LEVEL as Jr, convertMillimetersToTwip as Jt, getColorDescriptor as K, PresetPattern as Kn, parseArchive as Kr, convertInchesToEmu as Kt, graphicFrameLockingDesc as L, LineEndLength as Ln, createColorTransforms as Lr, createPictureLocking as Lt, shape3DDesc as M, LineCap as Mn, createScRgbColor as Mr, createOrgChart as Mt, groupTransform2DDesc as N, LineJoin as Nn, createRgbColor as Nr, createPreferredChildren as Nt, stretchDesc as O, createGlowEffect as On, SystemColor as Or, createAnimateOneByOne as Ot, transform2DDesc as P, PenAlignment as Pn, PresetColor as Pr, createPresentationLayoutVariables as Pt, schemeColorDesc as Q, TileAlignment as Qn, strFromU8$1 as Qr, convertToEmu as Qt, groupLockingDesc as R, LineEndType as Rn, buildContentTypeOverrides as Rr, createShapeLocking as Rt, diagramRelationshipIdsDesc as S, createReflectionEffect as Sn, uniqueNumericIdCreator as Sr, createStyleDefinitionHeaderList as St, blipDesc as T, RectAlignment as Tn, toUint8Array as Tr, HierBranchStyle as Tt, fillDesc as U, createNoFill as Un, summarizeOpcIssues as Ur, convertEmuToInches as Ut, effectListDesc as V, createCustomDash as Vn, PPTX_PARTS as Vr, parseTableStyleList as Vt, gradientFillDesc as W, buildFill as Wn, validateOpcConsistency as Wr, convertEmuToPixels as Wt, rgbColorDesc as X, createGradientFill as Xn, createZipStream as Xr, convertPointsToEmu as Xt, presetColorDesc as Y, TileFlipMode as Yn, createPacker as Yr, convertPixelsToEmu as Yt, scRgbColorDesc as Z, createGradientStop as Zn, levelForMediaName as Zr, convertPositionToEmu as Zt, derivePasswordHash as _, createScene3D as _n, xsdVerticalMergeRev as _r, createColorsDefinitionHeader as _t, getMediaRefs as a, encodeBase64 as ai, stringifyStretch as an, xsdLineEndSize as ar, ColorMethod as at, compileMapping as b, createEffectList as bn, hashedId as br, createLayoutDefinitionHeaderList as bt, hasPlaceholders as c, createDefault as ci, createExtentionList as cn, xsdPattern as cr, StyleMatrixIndex as ct, replaceHyperlinkPlaceholders as d, TargetModeType as di, stringifyAdjustmentValues as dn, xsdRectAlignment as dr, createFillColorList as dt, zipAndConvert as ei, convertUniversalMeasureToEmu as en, invertMap as er, systemColorDesc as et, replaceImagePlaceholders as f, PresetMaterialType as fn, xsdStrikeStyle as fr, createLineColorList as ft, replaceVideoPlaceholders as g, createBottomBevel as gn, xsdUnderlineStyle as gr, createTextLineColorList as gt, replaceSmartArtPlaceholders as h, createBevel as hn, xsdTextCaps as hr, createTextFillColorList as ht, formatId as i, decodeBase64 as ii, createTransform2D as in, xsdLineCap as ir, createDiagramRelationshipIds as it, scene3DDesc as j, CompoundLine as jn, createSchemeColor as jr, createMaxChildren as jt, tileDesc as k, BlendMode as kn, createSystemColor as kr, createAnimationLevel as kt, replaceAllPlaceholders as l, createOverride as li, createCustomGeometry as ln, xsdPenAlignment as lr, createDiagramStyle as lt, replaceNumberingPlaceholders as m, BevelPresetType as mn, xsdTextAnchor as mr, createTextEffectColorList as mt, collectPlaceholderKeys as n, OoxmlMimeType as ni, parseUniversalMeasure as nn, xsdCompoundLine as nr, createDiagramShape3D as nt, getReferencedMedia as o, customPropertiesDesc as oi, createBlipFill as on, xsdMaterialType as or, FontCollectionIndex as ot, replaceMediaPlaceholders as p, createShape3D as pn, xsdTextAlign as pr, createStyleLabel as pt, hslColorDesc as q, createPatternFill as qn, ZIP_DEFLATE_LEVEL as qr, convertInchesToTwip as qt, findAndReplaceImagePlaceholders as r, convertOutput as ri, createGroupTransform2D as rn, xsdEffectContainer as rr, createDiagramTextProperties as rt, getVideoRefs as s, appPropertiesDesc as si, createBlip as sn, xsdPathFillMode as sr, HueDirection as st, addSmartArtRelationships as t, zipSyncAndConvert as ti, convertUniversalMeasureToTwip as tn, xsdBlendMode as tr, createDiagramExtensionList as tt, replaceChartPlaceholders as u, Relationships as ui, stringifyPresetGeometry as un, xsdPresetShadow as ur, createEffectColorList as ut, hashPasswordAgile as v, createEffectDag as vn, createSourceRectangle as vr, createColorsDefinitionHeaderList as vt, presentationLayoutVariablesDesc as w, createPresetShadowEffect as wn, isBase64DataURL as wr, AnimationLevelValue as wt, diagramExtensionListDesc as x, createSoftEdgeEffect as xn, uniqueId as xr, createStyleDefinitionHeader as xt, randomBytes as y, calculateEffectExtent as yn, createBlipEffects as yr, createLayoutDefinitionHeader as yt, pictureLockingDesc as z, LineEndWidth as zn, DOCX_PARTS as zr, createTableStyle as zt };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@office-open/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.1",
|
|
4
4
|
"description": "Shared OOXML infrastructure — XML components, validators, converters, charts, and SmartArt",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"core",
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
"dependencies": {
|
|
67
67
|
"@noble/hashes": "2.2.0",
|
|
68
68
|
"fflate": "0.8.3",
|
|
69
|
-
"@office-open/xml": "0.
|
|
69
|
+
"@office-open/xml": "0.10.1"
|
|
70
70
|
},
|
|
71
71
|
"scripts": {
|
|
72
72
|
"dev": "basis build --stub",
|