@office-open/core 0.3.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/LICENSE +21 -0
- package/README.md +111 -0
- package/dist/_chunks/id-generators-Ch07cHW1.mjs +72 -0
- package/dist/_chunks/index-3uVYzs32.d.mts +241 -0
- package/dist/_chunks/values-BrGywpRh.d.mts +400 -0
- package/dist/_chunks/xml-components-DazgCiyL.mjs +364 -0
- package/dist/archive.d.mts +42 -0
- package/dist/archive.mjs +101 -0
- package/dist/chart/index.d.mts +83 -0
- package/dist/chart/index.mjs +360 -0
- package/dist/drawingml/index.d.mts +3119 -0
- package/dist/drawingml/index.mjs +3698 -0
- package/dist/index.d.mts +126 -0
- package/dist/index.mjs +118 -0
- package/dist/smartart/index.d.mts +69 -0
- package/dist/smartart/index.mjs +304 -0
- package/dist/values.d.mts +2 -0
- package/dist/values.mjs +371 -0
- package/package.json +70 -0
|
@@ -0,0 +1,364 @@
|
|
|
1
|
+
import { hpsMeasureValue } from "../values.mjs";
|
|
2
|
+
import { xml2js } from "@office-open/xml";
|
|
3
|
+
//#region src/xml-components/base.ts
|
|
4
|
+
/**
|
|
5
|
+
* Abstract base class for all XML components.
|
|
6
|
+
*/
|
|
7
|
+
var BaseXmlComponent = class {
|
|
8
|
+
/** The XML element name for this component (e.g., "w:p" for paragraph). */
|
|
9
|
+
rootKey;
|
|
10
|
+
constructor(rootKey) {
|
|
11
|
+
this.rootKey = rootKey;
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
//#endregion
|
|
15
|
+
//#region src/xml-components/component.ts
|
|
16
|
+
/**
|
|
17
|
+
* Core XML Component classes for building OOXML element trees.
|
|
18
|
+
*
|
|
19
|
+
* @module
|
|
20
|
+
*/
|
|
21
|
+
/**
|
|
22
|
+
* Empty object singleton used for empty XML elements.
|
|
23
|
+
*
|
|
24
|
+
* @internal
|
|
25
|
+
*/
|
|
26
|
+
const EMPTY_OBJECT = Object.seal({});
|
|
27
|
+
/**
|
|
28
|
+
* Base class for all XML components in OOXML documents.
|
|
29
|
+
*/
|
|
30
|
+
var XmlComponent = class extends BaseXmlComponent {
|
|
31
|
+
/**
|
|
32
|
+
* Array of child components, text nodes, and attributes.
|
|
33
|
+
*/
|
|
34
|
+
root;
|
|
35
|
+
constructor(rootKey) {
|
|
36
|
+
super(rootKey);
|
|
37
|
+
this.root = new Array();
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Prepares this component and its children for XML serialization.
|
|
41
|
+
*/
|
|
42
|
+
prepForXml(context) {
|
|
43
|
+
context.stack.push(this);
|
|
44
|
+
const children = [];
|
|
45
|
+
for (const comp of this.root) if (comp instanceof BaseXmlComponent) {
|
|
46
|
+
const prepared = comp.prepForXml(context);
|
|
47
|
+
if (prepared !== void 0) children.push(prepared);
|
|
48
|
+
} else children.push(comp);
|
|
49
|
+
context.stack.pop();
|
|
50
|
+
return { [this.rootKey]: children.length ? children.length === 1 && children[0] && typeof children[0] === "object" && "_attr" in children[0] ? children[0] : children : EMPTY_OBJECT };
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* @deprecated Internal use only.
|
|
54
|
+
*/
|
|
55
|
+
addChildElement(child) {
|
|
56
|
+
this.root.push(child);
|
|
57
|
+
return this;
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* XML component that is excluded from output if it has no meaningful content.
|
|
62
|
+
*/
|
|
63
|
+
var IgnoreIfEmptyXmlComponent = class extends XmlComponent {
|
|
64
|
+
includeIfEmpty;
|
|
65
|
+
constructor(rootKey, includeIfEmpty) {
|
|
66
|
+
super(rootKey);
|
|
67
|
+
this.includeIfEmpty = includeIfEmpty;
|
|
68
|
+
}
|
|
69
|
+
prepForXml(context) {
|
|
70
|
+
const result = super.prepForXml(context);
|
|
71
|
+
if (this.includeIfEmpty) return result;
|
|
72
|
+
if (result && (typeof result[this.rootKey] !== "object" || Object.keys(result[this.rootKey]).length)) return result;
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
//#endregion
|
|
76
|
+
//#region src/xml-components/attributes.ts
|
|
77
|
+
/**
|
|
78
|
+
* XML attribute components for OOXML document generation.
|
|
79
|
+
*
|
|
80
|
+
* @module
|
|
81
|
+
*/
|
|
82
|
+
/**
|
|
83
|
+
* Base class for creating XML attributes with automatic name mapping.
|
|
84
|
+
*/
|
|
85
|
+
var XmlAttributeComponent = class extends BaseXmlComponent {
|
|
86
|
+
/** Optional mapping from property names to XML attribute names. */
|
|
87
|
+
xmlKeys;
|
|
88
|
+
constructor(root) {
|
|
89
|
+
super("_attr");
|
|
90
|
+
this.root = root;
|
|
91
|
+
}
|
|
92
|
+
prepForXml(_) {
|
|
93
|
+
const attrs = {};
|
|
94
|
+
Object.entries(this.root).forEach(([key, value]) => {
|
|
95
|
+
if (value !== void 0) {
|
|
96
|
+
const newKey = this.xmlKeys && this.xmlKeys[key] || key;
|
|
97
|
+
attrs[newKey] = value;
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
return { _attr: attrs };
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
/**
|
|
104
|
+
* Next-generation attribute component with explicit key-value pairs.
|
|
105
|
+
*/
|
|
106
|
+
var NextAttributeComponent = class extends BaseXmlComponent {
|
|
107
|
+
constructor(root) {
|
|
108
|
+
super("_attr");
|
|
109
|
+
this.root = root;
|
|
110
|
+
}
|
|
111
|
+
prepForXml(_) {
|
|
112
|
+
return { _attr: Object.values(this.root).filter(({ value }) => value !== void 0).reduce((acc, { key, value }) => ({
|
|
113
|
+
...acc,
|
|
114
|
+
[key]: value
|
|
115
|
+
}), {}) };
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
//#endregion
|
|
119
|
+
//#region src/xml-components/elements.ts
|
|
120
|
+
/**
|
|
121
|
+
* Simple XML element types for common OOXML patterns.
|
|
122
|
+
*
|
|
123
|
+
* @module
|
|
124
|
+
*/
|
|
125
|
+
const ON_OFF_TRUE_CACHE = /* @__PURE__ */ new Map();
|
|
126
|
+
/**
|
|
127
|
+
* Build a CT_OnOff XML object without allocating any XmlComponent.
|
|
128
|
+
* `val=true` returns a frozen singleton (cached per name).
|
|
129
|
+
*/
|
|
130
|
+
function onOffObj(name, val = true) {
|
|
131
|
+
if (val === true) {
|
|
132
|
+
let cached = ON_OFF_TRUE_CACHE.get(name);
|
|
133
|
+
if (!cached) {
|
|
134
|
+
cached = Object.freeze({ [name]: Object.freeze({}) });
|
|
135
|
+
ON_OFF_TRUE_CACHE.set(name, cached);
|
|
136
|
+
}
|
|
137
|
+
return cached;
|
|
138
|
+
}
|
|
139
|
+
const ns = name.split(":")[0];
|
|
140
|
+
return { [name]: { _attr: { [`${ns}:val`]: val } } };
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Build a CT_HpsMeasure XML object (half-point size) without allocation.
|
|
144
|
+
*/
|
|
145
|
+
function hpsMeasureObj(name, val) {
|
|
146
|
+
const ns = name.split(":")[0];
|
|
147
|
+
return { [name]: { _attr: { [`${ns}:val`]: hpsMeasureValue(val) } } };
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Build a CT_String XML object (string value attribute) without allocation.
|
|
151
|
+
*/
|
|
152
|
+
function stringValObj(name, val) {
|
|
153
|
+
const ns = name.split(":")[0];
|
|
154
|
+
return { [name]: { _attr: { [`${ns}:val`]: val } } };
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Build a numeric value attribute XML object without allocation.
|
|
158
|
+
*/
|
|
159
|
+
function numberValObj(name, val) {
|
|
160
|
+
const ns = name.split(":")[0];
|
|
161
|
+
return { [name]: { _attr: { [`${ns}:val`]: val } } };
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Build a string enum value attribute XML object without allocation.
|
|
165
|
+
*/
|
|
166
|
+
function stringEnumValObj(name, val) {
|
|
167
|
+
const ns = name.split(":")[0];
|
|
168
|
+
return { [name]: { _attr: { [`${ns}:val`]: val } } };
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Build an element wrapping a text string without allocation.
|
|
172
|
+
*/
|
|
173
|
+
function stringContainerObj(name, val) {
|
|
174
|
+
return { [name]: [val] };
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* XML element representing a boolean on/off value (CT_OnOff).
|
|
178
|
+
* @deprecated Use `onOffObj()` for hot-path code.
|
|
179
|
+
*/
|
|
180
|
+
var OnOffElement = class extends XmlComponent {
|
|
181
|
+
constructor(name, val = true) {
|
|
182
|
+
super(name);
|
|
183
|
+
if (val !== true) this.root.push(new NextAttributeComponent({ val: {
|
|
184
|
+
key: `${name.split(":")[0]}:val`,
|
|
185
|
+
value: val
|
|
186
|
+
} }));
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
/**
|
|
190
|
+
* XML element representing a half-point size measurement (CT_HpsMeasure).
|
|
191
|
+
* @deprecated Use `hpsMeasureObj()` for hot-path code.
|
|
192
|
+
*/
|
|
193
|
+
var HpsMeasureElement = class extends XmlComponent {
|
|
194
|
+
constructor(name, val) {
|
|
195
|
+
super(name);
|
|
196
|
+
const ns = name.split(":")[0];
|
|
197
|
+
this.root.push(new NextAttributeComponent({ val: {
|
|
198
|
+
key: `${ns}:val`,
|
|
199
|
+
value: hpsMeasureValue(val)
|
|
200
|
+
} }));
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
/**
|
|
204
|
+
* XML element representing an empty element (CT_Empty).
|
|
205
|
+
*/
|
|
206
|
+
var EmptyElement = class extends XmlComponent {};
|
|
207
|
+
/**
|
|
208
|
+
* XML element with a string value attribute (CT_String).
|
|
209
|
+
* @deprecated Use `stringValObj()` for hot-path code.
|
|
210
|
+
*/
|
|
211
|
+
var StringValueElement = class extends XmlComponent {
|
|
212
|
+
constructor(name, val) {
|
|
213
|
+
super(name);
|
|
214
|
+
const ns = name.split(":")[0];
|
|
215
|
+
this.root.push(new NextAttributeComponent({ val: {
|
|
216
|
+
key: `${ns}:val`,
|
|
217
|
+
value: val
|
|
218
|
+
} }));
|
|
219
|
+
}
|
|
220
|
+
};
|
|
221
|
+
/**
|
|
222
|
+
* XML element with a numeric value attribute.
|
|
223
|
+
* @deprecated Use `numberValObj()` for hot-path code.
|
|
224
|
+
*/
|
|
225
|
+
var NumberValueElement = class extends XmlComponent {
|
|
226
|
+
constructor(name, val) {
|
|
227
|
+
super(name);
|
|
228
|
+
const ns = name.split(":")[0];
|
|
229
|
+
this.root.push(new NextAttributeComponent({ val: {
|
|
230
|
+
key: `${ns}:val`,
|
|
231
|
+
value: val
|
|
232
|
+
} }));
|
|
233
|
+
}
|
|
234
|
+
};
|
|
235
|
+
/**
|
|
236
|
+
* XML element with a string enum value attribute.
|
|
237
|
+
* @deprecated Use `stringEnumValObj()` for hot-path code.
|
|
238
|
+
*/
|
|
239
|
+
var StringEnumValueElement = class extends XmlComponent {
|
|
240
|
+
constructor(name, val) {
|
|
241
|
+
super(name);
|
|
242
|
+
const ns = name.split(":")[0];
|
|
243
|
+
this.root.push(new NextAttributeComponent({ val: {
|
|
244
|
+
key: `${ns}:val`,
|
|
245
|
+
value: val
|
|
246
|
+
} }));
|
|
247
|
+
}
|
|
248
|
+
};
|
|
249
|
+
/**
|
|
250
|
+
* XML element containing text content.
|
|
251
|
+
* @deprecated Use `stringContainerObj()` for hot-path code.
|
|
252
|
+
*/
|
|
253
|
+
var StringContainer = class extends XmlComponent {
|
|
254
|
+
constructor(name, val) {
|
|
255
|
+
super(name);
|
|
256
|
+
this.root.push(val);
|
|
257
|
+
}
|
|
258
|
+
};
|
|
259
|
+
/**
|
|
260
|
+
* Flexible XML element builder with explicit attribute and child configuration.
|
|
261
|
+
*/
|
|
262
|
+
var BuilderElement = class extends XmlComponent {
|
|
263
|
+
constructor({ name, attributes, children }) {
|
|
264
|
+
super(name);
|
|
265
|
+
if (attributes) this.root.push(new NextAttributeComponent(attributes));
|
|
266
|
+
if (children) this.root.push(...children);
|
|
267
|
+
}
|
|
268
|
+
};
|
|
269
|
+
/**
|
|
270
|
+
* Creates a NextAttributeComponent with explicit XML attribute keys.
|
|
271
|
+
*/
|
|
272
|
+
const chartAttr = (attrs) => new NextAttributeComponent(Object.fromEntries(Object.entries(attrs).map(([key, value]) => [key, {
|
|
273
|
+
key,
|
|
274
|
+
value
|
|
275
|
+
}])));
|
|
276
|
+
/**
|
|
277
|
+
* Wraps a component in a named XmlComponent element.
|
|
278
|
+
*/
|
|
279
|
+
function wrapEl(elementName, child) {
|
|
280
|
+
const el = new class extends XmlComponent {
|
|
281
|
+
constructor(name) {
|
|
282
|
+
super(name);
|
|
283
|
+
}
|
|
284
|
+
}(elementName);
|
|
285
|
+
el["root"].push(child);
|
|
286
|
+
return el;
|
|
287
|
+
}
|
|
288
|
+
//#endregion
|
|
289
|
+
//#region src/xml-components/imported.ts
|
|
290
|
+
/**
|
|
291
|
+
* Imported XML Component module for handling external XML content.
|
|
292
|
+
*
|
|
293
|
+
* @module
|
|
294
|
+
*/
|
|
295
|
+
/**
|
|
296
|
+
* Converts an xml-js Element into an XmlComponent tree.
|
|
297
|
+
*/
|
|
298
|
+
const convertToXmlComponent = (element) => {
|
|
299
|
+
switch (element.type) {
|
|
300
|
+
case void 0:
|
|
301
|
+
case "element": {
|
|
302
|
+
const xmlComponent = new ImportedXmlComponent(element.name, element.attributes);
|
|
303
|
+
const childElements = element.elements || [];
|
|
304
|
+
for (const childElm of childElements) {
|
|
305
|
+
const child = convertToXmlComponent(childElm);
|
|
306
|
+
if (child !== void 0) xmlComponent.push(child);
|
|
307
|
+
}
|
|
308
|
+
return xmlComponent;
|
|
309
|
+
}
|
|
310
|
+
case "text": return element.text;
|
|
311
|
+
default: return;
|
|
312
|
+
}
|
|
313
|
+
};
|
|
314
|
+
/**
|
|
315
|
+
* Internal attribute component for imported XML elements.
|
|
316
|
+
* @internal
|
|
317
|
+
*/
|
|
318
|
+
var ImportedXmlComponentAttributes = class extends XmlAttributeComponent {};
|
|
319
|
+
/**
|
|
320
|
+
* XML component representing imported XML content.
|
|
321
|
+
*/
|
|
322
|
+
var ImportedXmlComponent = class extends XmlComponent {
|
|
323
|
+
static fromXmlString(importedContent) {
|
|
324
|
+
const xmlObj = xml2js(importedContent, { compact: false });
|
|
325
|
+
return convertToXmlComponent(xmlObj.elements?.[0] ?? xmlObj);
|
|
326
|
+
}
|
|
327
|
+
constructor(rootKey, _attr) {
|
|
328
|
+
super(rootKey);
|
|
329
|
+
if (_attr) this.root.push(new ImportedXmlComponentAttributes(_attr));
|
|
330
|
+
}
|
|
331
|
+
push(xmlComponent) {
|
|
332
|
+
this.root.push(xmlComponent);
|
|
333
|
+
}
|
|
334
|
+
};
|
|
335
|
+
/**
|
|
336
|
+
* Represents attributes for imported root elements.
|
|
337
|
+
*/
|
|
338
|
+
var ImportedRootElementAttributes = class extends XmlComponent {
|
|
339
|
+
constructor(_attr) {
|
|
340
|
+
super("");
|
|
341
|
+
this._attr = _attr;
|
|
342
|
+
}
|
|
343
|
+
prepForXml(_) {
|
|
344
|
+
return { _attr: this._attr };
|
|
345
|
+
}
|
|
346
|
+
};
|
|
347
|
+
//#endregion
|
|
348
|
+
//#region src/xml-components/initializable.ts
|
|
349
|
+
/**
|
|
350
|
+
* Initializable XML Component module.
|
|
351
|
+
*
|
|
352
|
+
* @module
|
|
353
|
+
*/
|
|
354
|
+
/**
|
|
355
|
+
* XML component that can be initialized from another component.
|
|
356
|
+
*/
|
|
357
|
+
var InitializableXmlComponent = class extends XmlComponent {
|
|
358
|
+
constructor(rootKey, initComponent) {
|
|
359
|
+
super(rootKey);
|
|
360
|
+
if (initComponent instanceof XmlComponent) this.root = initComponent.root;
|
|
361
|
+
}
|
|
362
|
+
};
|
|
363
|
+
//#endregion
|
|
364
|
+
export { EMPTY_OBJECT as C, BaseXmlComponent as E, XmlAttributeComponent as S, XmlComponent as T, stringContainerObj as _, BuilderElement as a, wrapEl as b, NumberValueElement as c, StringEnumValueElement as d, StringValueElement as f, onOffObj as g, numberValObj as h, convertToXmlComponent as i, OnOffElement as l, hpsMeasureObj as m, ImportedRootElementAttributes as n, EmptyElement as o, chartAttr as p, ImportedXmlComponent as r, HpsMeasureElement as s, InitializableXmlComponent as t, StringContainer as u, stringEnumValObj as v, IgnoreIfEmptyXmlComponent as w, NextAttributeComponent as x, stringValObj as y };
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Element } from "@office-open/xml";
|
|
2
|
+
|
|
3
|
+
//#region src/archive.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Unzip an OOXML file (.docx, .pptx) into a Map of path → Uint8Array.
|
|
6
|
+
*/
|
|
7
|
+
declare function unzipToMap(data: Uint8Array): Map<string, Uint8Array>;
|
|
8
|
+
/**
|
|
9
|
+
* Read a file from the zip as a UTF-8 string.
|
|
10
|
+
*/
|
|
11
|
+
declare function readTextFromZip(zip: Map<string, Uint8Array>, path: string): string | undefined;
|
|
12
|
+
/**
|
|
13
|
+
* Parse an XML file from the zip into an Element tree.
|
|
14
|
+
*/
|
|
15
|
+
declare function readXmlFromZip(zip: Map<string, Uint8Array>, path: string): Element | undefined;
|
|
16
|
+
/**
|
|
17
|
+
* Read a binary file from the zip.
|
|
18
|
+
*/
|
|
19
|
+
declare function readBinaryFromZip(zip: Map<string, Uint8Array>, path: string): Uint8Array | undefined;
|
|
20
|
+
/**
|
|
21
|
+
* List all files in the zip matching a prefix.
|
|
22
|
+
*/
|
|
23
|
+
declare function listFiles(zip: Map<string, Uint8Array>, prefix: string): string[];
|
|
24
|
+
/**
|
|
25
|
+
* Convert Uint8Array to base64 string.
|
|
26
|
+
*/
|
|
27
|
+
declare function uint8ToBase64(data: Uint8Array): string;
|
|
28
|
+
/**
|
|
29
|
+
* Determine image type from file extension.
|
|
30
|
+
*/
|
|
31
|
+
declare function getImageType(fileName: string): string;
|
|
32
|
+
interface Relationship {
|
|
33
|
+
id: string;
|
|
34
|
+
target: string;
|
|
35
|
+
type: string;
|
|
36
|
+
targetMode?: string;
|
|
37
|
+
}
|
|
38
|
+
declare function parseRels(zip: Map<string, Uint8Array>, path: string): Relationship[];
|
|
39
|
+
declare function findRel(rels: Relationship[], id: string): Relationship | undefined;
|
|
40
|
+
declare function findRelsByType(rels: Relationship[], typeSubstring: string): Relationship[];
|
|
41
|
+
//#endregion
|
|
42
|
+
export { Relationship, findRel, findRelsByType, getImageType, listFiles, parseRels, readBinaryFromZip, readTextFromZip, readXmlFromZip, uint8ToBase64, unzipToMap };
|
package/dist/archive.mjs
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { attr, xml2js } from "@office-open/xml";
|
|
2
|
+
import { strFromU8, unzipSync } from "fflate";
|
|
3
|
+
//#region src/archive.ts
|
|
4
|
+
const XML_PARSE_OPTIONS = {
|
|
5
|
+
nativeTypeAttributes: true,
|
|
6
|
+
captureSpacesBetweenElements: true
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Unzip an OOXML file (.docx, .pptx) into a Map of path → Uint8Array.
|
|
10
|
+
*/
|
|
11
|
+
function unzipToMap(data) {
|
|
12
|
+
const entries = unzipSync(data);
|
|
13
|
+
const map = /* @__PURE__ */ new Map();
|
|
14
|
+
for (const [path, bytes] of Object.entries(entries)) map.set(path, bytes);
|
|
15
|
+
return map;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Read a file from the zip as a UTF-8 string.
|
|
19
|
+
*/
|
|
20
|
+
function readTextFromZip(zip, path) {
|
|
21
|
+
const data = zip.get(path);
|
|
22
|
+
if (data === void 0) return void 0;
|
|
23
|
+
return strFromU8(data);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Parse an XML file from the zip into an Element tree.
|
|
27
|
+
*/
|
|
28
|
+
function readXmlFromZip(zip, path) {
|
|
29
|
+
const text = readTextFromZip(zip, path);
|
|
30
|
+
if (text === void 0) return void 0;
|
|
31
|
+
return xml2js(text, XML_PARSE_OPTIONS).elements?.find((e) => e.type === "element");
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Read a binary file from the zip.
|
|
35
|
+
*/
|
|
36
|
+
function readBinaryFromZip(zip, path) {
|
|
37
|
+
return zip.get(path);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* List all files in the zip matching a prefix.
|
|
41
|
+
*/
|
|
42
|
+
function listFiles(zip, prefix) {
|
|
43
|
+
const result = [];
|
|
44
|
+
for (const path of zip.keys()) if (path.startsWith(prefix)) result.push(path);
|
|
45
|
+
return result;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Convert Uint8Array to base64 string.
|
|
49
|
+
*/
|
|
50
|
+
function uint8ToBase64(data) {
|
|
51
|
+
let binary = "";
|
|
52
|
+
for (let i = 0; i < data.length; i++) binary += String.fromCharCode(data[i]);
|
|
53
|
+
return btoa(binary);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Determine image type from file extension.
|
|
57
|
+
*/
|
|
58
|
+
function getImageType(fileName) {
|
|
59
|
+
const ext = fileName.split(".").pop()?.toLowerCase() ?? "";
|
|
60
|
+
if ([
|
|
61
|
+
"png",
|
|
62
|
+
"jpg",
|
|
63
|
+
"jpeg",
|
|
64
|
+
"gif",
|
|
65
|
+
"bmp",
|
|
66
|
+
"tif",
|
|
67
|
+
"tiff",
|
|
68
|
+
"ico",
|
|
69
|
+
"emf",
|
|
70
|
+
"wmf",
|
|
71
|
+
"svg"
|
|
72
|
+
].includes(ext)) return ext === "jpeg" ? "jpg" : ext;
|
|
73
|
+
return "png";
|
|
74
|
+
}
|
|
75
|
+
function parseRels(zip, path) {
|
|
76
|
+
const xml = readXmlFromZip(zip, path);
|
|
77
|
+
if (!xml) return [];
|
|
78
|
+
const result = [];
|
|
79
|
+
for (const rel of xml.elements ?? []) {
|
|
80
|
+
if (rel.name !== "Relationship") continue;
|
|
81
|
+
const id = attr(rel, "Id");
|
|
82
|
+
const target = attr(rel, "Target");
|
|
83
|
+
const type = attr(rel, "Type");
|
|
84
|
+
const targetMode = attr(rel, "TargetMode");
|
|
85
|
+
if (id && target) result.push({
|
|
86
|
+
id,
|
|
87
|
+
target,
|
|
88
|
+
type: type ?? "",
|
|
89
|
+
...targetMode ? { targetMode } : {}
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
return result;
|
|
93
|
+
}
|
|
94
|
+
function findRel(rels, id) {
|
|
95
|
+
return rels.find((r) => r.id === id);
|
|
96
|
+
}
|
|
97
|
+
function findRelsByType(rels, typeSubstring) {
|
|
98
|
+
return rels.filter((r) => r.type.includes(typeSubstring));
|
|
99
|
+
}
|
|
100
|
+
//#endregion
|
|
101
|
+
export { findRel, findRelsByType, getImageType, listFiles, parseRels, readBinaryFromZip, readTextFromZip, readXmlFromZip, uint8ToBase64, unzipToMap };
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { O as XmlComponent } from "../_chunks/index-3uVYzs32.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/chart/chart-collection.d.ts
|
|
4
|
+
interface IChartData {
|
|
5
|
+
readonly key: string;
|
|
6
|
+
readonly chartSpace: XmlComponent;
|
|
7
|
+
}
|
|
8
|
+
declare class ChartCollection {
|
|
9
|
+
private readonly map;
|
|
10
|
+
constructor();
|
|
11
|
+
addChart(key: string, chartData: IChartData): void;
|
|
12
|
+
get Array(): readonly IChartData[];
|
|
13
|
+
}
|
|
14
|
+
//#endregion
|
|
15
|
+
//#region src/chart/chart-types/area-chart.d.ts
|
|
16
|
+
interface IAreaChartOptions {
|
|
17
|
+
readonly categories: readonly string[];
|
|
18
|
+
readonly series: readonly IChartSeriesData[];
|
|
19
|
+
}
|
|
20
|
+
declare class AreaChart extends XmlComponent {
|
|
21
|
+
constructor(options: IAreaChartOptions);
|
|
22
|
+
}
|
|
23
|
+
//#endregion
|
|
24
|
+
//#region src/chart/chart-types/bar-chart.d.ts
|
|
25
|
+
interface IBarChartOptions {
|
|
26
|
+
readonly barDirection: "col" | "bar";
|
|
27
|
+
readonly categories: readonly string[];
|
|
28
|
+
readonly series: readonly IChartSeriesData[];
|
|
29
|
+
}
|
|
30
|
+
declare class BarChart extends XmlComponent {
|
|
31
|
+
constructor(options: IBarChartOptions);
|
|
32
|
+
}
|
|
33
|
+
//#endregion
|
|
34
|
+
//#region src/chart/chart-types/line-chart.d.ts
|
|
35
|
+
interface ILineChartOptions {
|
|
36
|
+
readonly categories: readonly string[];
|
|
37
|
+
readonly series: readonly IChartSeriesData[];
|
|
38
|
+
}
|
|
39
|
+
declare class LineChart extends XmlComponent {
|
|
40
|
+
constructor(options: ILineChartOptions);
|
|
41
|
+
}
|
|
42
|
+
//#endregion
|
|
43
|
+
//#region src/chart/chart-types/pie-chart.d.ts
|
|
44
|
+
interface IPieChartOptions {
|
|
45
|
+
readonly categories: readonly string[];
|
|
46
|
+
readonly series: readonly IChartSeriesData[];
|
|
47
|
+
}
|
|
48
|
+
declare class PieChart extends XmlComponent {
|
|
49
|
+
constructor(options: IPieChartOptions);
|
|
50
|
+
}
|
|
51
|
+
//#endregion
|
|
52
|
+
//#region src/chart/chart-types/scatter-chart.d.ts
|
|
53
|
+
interface IScatterChartOptions {
|
|
54
|
+
readonly categories: readonly string[];
|
|
55
|
+
readonly series: readonly IChartSeriesData[];
|
|
56
|
+
}
|
|
57
|
+
declare class ScatterChart extends XmlComponent {
|
|
58
|
+
constructor(options: IScatterChartOptions);
|
|
59
|
+
}
|
|
60
|
+
//#endregion
|
|
61
|
+
//#region src/chart/create-chart-type.d.ts
|
|
62
|
+
interface IChartSeriesData {
|
|
63
|
+
readonly name: string;
|
|
64
|
+
readonly values: readonly number[];
|
|
65
|
+
}
|
|
66
|
+
type ChartType = "column" | "bar" | "line" | "pie" | "area" | "scatter";
|
|
67
|
+
interface IChartTypeOptions {
|
|
68
|
+
readonly type: ChartType;
|
|
69
|
+
readonly series: readonly IChartSeriesData[];
|
|
70
|
+
readonly categories: readonly string[];
|
|
71
|
+
}
|
|
72
|
+
declare const createChartType: (options: IChartTypeOptions) => BarChart | LineChart | PieChart | AreaChart | ScatterChart;
|
|
73
|
+
//#endregion
|
|
74
|
+
//#region src/chart/series/series-data.d.ts
|
|
75
|
+
declare const createStrRef: (values: string | readonly string[]) => XmlComponent;
|
|
76
|
+
declare const createNumRef: (values: readonly number[]) => XmlComponent;
|
|
77
|
+
//#endregion
|
|
78
|
+
//#region src/chart/title.d.ts
|
|
79
|
+
declare class ChartTitle extends XmlComponent {
|
|
80
|
+
constructor(title: string);
|
|
81
|
+
}
|
|
82
|
+
//#endregion
|
|
83
|
+
export { AreaChart, BarChart, ChartCollection, ChartTitle, ChartType, IChartData, IChartSeriesData, IChartTypeOptions, LineChart, PieChart, ScatterChart, createChartType, createNumRef, createStrRef };
|