@office-open/core 0.8.1 → 0.9.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/README.md +32 -60
- package/dist/chart/index.d.mts +2 -2
- package/dist/chart/index.mjs +2 -2
- package/dist/chart-DNpai28f.mjs +365 -0
- package/dist/descriptor/index.d.mts +2 -0
- package/dist/descriptor/index.mjs +2 -0
- package/dist/descriptor-57JUzfpG.mjs +282 -0
- package/dist/drawingml/index.d.mts +2 -2
- package/dist/drawingml/index.mjs +2 -2
- package/dist/{index-Cj2Yf5mk.d.mts → index-BKotL3AP.d.mts} +10 -7
- package/dist/{index-DEvpdl1o.d.mts → index-BqJRDf5H.d.mts} +1423 -1837
- package/dist/index-D81RV9Vc.d.mts +153 -0
- package/dist/{index-BCUfgp9A.d.mts → index-DmPBJwSk.d.mts} +2 -2
- package/dist/{index-D0N5Bw2M.d.mts → index-eu1aFQCm.d.mts} +39 -28
- package/dist/index-xXbaecaB.d.mts +137 -0
- package/dist/index.d.mts +8 -558
- package/dist/index.mjs +7 -2091
- package/dist/patch/index.d.mts +1 -1
- package/dist/smartart/index.d.mts +2 -2
- package/dist/smartart/index.mjs +2 -2
- package/dist/{smartart-9ZpWgmIy.mjs → smartart-DCY-Vdv7.mjs} +120 -204
- package/dist/src-DPuDEZYF.mjs +7477 -0
- package/dist/theme/index.d.mts +2 -2
- package/dist/theme/index.mjs +2 -2
- package/dist/{theme-FWD_20fH.mjs → theme-CiNzdl-9.mjs} +117 -22
- package/dist/{values.d.mts → util/values.d.mts} +1 -1
- package/dist/{values.mjs → util/values.mjs} +1 -1
- package/dist/{values-BOWpTgBE.mjs → values-CVIZcTRw.mjs} +1 -1
- package/dist/{values-COjPGYkS.d.mts → values-Dqj8cbcy.d.mts} +1 -1
- package/package.json +13 -10
- package/dist/chart-CigYrDhf.mjs +0 -1242
- package/dist/drawingml-B-2eEHAF.mjs +0 -7109
- package/dist/index-Bh6s66Up.d.mts +0 -381
- package/dist/index-CoTp4wVf.d.mts +0 -202
- package/dist/xml-components-BuFdDxHN.mjs +0 -322
|
@@ -1,322 +0,0 @@
|
|
|
1
|
-
import { c as hpsMeasureValue } from "./values-BOWpTgBE.mjs";
|
|
2
|
-
import { escapeXml, xml, 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
|
-
* Direct XML serialization. Override in subclasses for zero-allocation output.
|
|
15
|
-
*/
|
|
16
|
-
toXml(_context) {
|
|
17
|
-
return "";
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
//#endregion
|
|
21
|
-
//#region src/xml-components/component.ts
|
|
22
|
-
/**
|
|
23
|
-
* Core XML Component classes for building OOXML element trees.
|
|
24
|
-
*
|
|
25
|
-
* @module
|
|
26
|
-
*/
|
|
27
|
-
function formatAttrs(a) {
|
|
28
|
-
let s = "";
|
|
29
|
-
for (const key of Object.keys(a)) s += (s ? " " : "") + `${key}="${escapeXml(String(a[key]))}"`;
|
|
30
|
-
return s;
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Empty object singleton used for empty XML elements.
|
|
34
|
-
*
|
|
35
|
-
* @internal
|
|
36
|
-
*/
|
|
37
|
-
const EMPTY_OBJECT = Object.seal({});
|
|
38
|
-
/**
|
|
39
|
-
* Base class for all XML components in OOXML documents.
|
|
40
|
-
*
|
|
41
|
-
* `toXml()` traverses the `root` array and calls `toXml()` on each
|
|
42
|
-
* `BaseXmlComponent` child — this avoids building the intermediate
|
|
43
|
-
* `IXmlableObject` tree. Inline `IXmlableObject` children fall back to
|
|
44
|
-
* `xml()` for serialization.
|
|
45
|
-
*/
|
|
46
|
-
var XmlComponent = class extends BaseXmlComponent {
|
|
47
|
-
/**
|
|
48
|
-
* Array of child components, text nodes, and attributes.
|
|
49
|
-
*/
|
|
50
|
-
root;
|
|
51
|
-
constructor(rootKey) {
|
|
52
|
-
super(rootKey);
|
|
53
|
-
this.root = [];
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Direct XML serialization — traverses `root` and calls `toXml()` on
|
|
57
|
-
* each child, concatenating the results into a single string.
|
|
58
|
-
*/
|
|
59
|
-
toXml(context) {
|
|
60
|
-
const root = this.root;
|
|
61
|
-
const len = root.length;
|
|
62
|
-
if (len === 0) return `<${this.rootKey}/>`;
|
|
63
|
-
if (len === 1) {
|
|
64
|
-
const child = root[0];
|
|
65
|
-
if (child instanceof BaseXmlComponent) {
|
|
66
|
-
const s = child.toXml(context);
|
|
67
|
-
return s ? `<${this.rootKey}>${s}</${this.rootKey}>` : `<${this.rootKey}/>`;
|
|
68
|
-
}
|
|
69
|
-
if (typeof child === "string") return `<${this.rootKey}>${escapeXml(child)}</${this.rootKey}>`;
|
|
70
|
-
if (child != null && typeof child === "object") {
|
|
71
|
-
const a = "_attr" in child ? child._attr : "_attributes" in child ? child._attributes : null;
|
|
72
|
-
if (a) {
|
|
73
|
-
const attrStr = formatAttrs(a);
|
|
74
|
-
return `<${this.rootKey}${attrStr ? " " + attrStr : ""}/>`;
|
|
75
|
-
}
|
|
76
|
-
return `<${this.rootKey}>${xml(child)}</${this.rootKey}>`;
|
|
77
|
-
}
|
|
78
|
-
return `<${this.rootKey}/>`;
|
|
79
|
-
}
|
|
80
|
-
const childParts = [];
|
|
81
|
-
const attrParts = [];
|
|
82
|
-
for (let i = 0; i < len; i++) {
|
|
83
|
-
const child = root[i];
|
|
84
|
-
if (child instanceof BaseXmlComponent) {
|
|
85
|
-
const s = child.toXml(context);
|
|
86
|
-
if (s) childParts.push(s);
|
|
87
|
-
} else if (typeof child === "string") childParts.push(escapeXml(child));
|
|
88
|
-
else if (child != null && typeof child === "object") {
|
|
89
|
-
const a = "_attr" in child ? child._attr : "_attributes" in child ? child._attributes : null;
|
|
90
|
-
if (a) for (const key of Object.keys(a)) attrParts.push(`${key}="${escapeXml(String(a[key]))}"`);
|
|
91
|
-
else childParts.push(xml(child));
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
const attrStr = attrParts.length ? " " + attrParts.join(" ") : "";
|
|
95
|
-
const body = childParts.join("");
|
|
96
|
-
return body.length === 0 ? `<${this.rootKey}${attrStr}/>` : `<${this.rootKey}${attrStr}>${body}</${this.rootKey}>`;
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* @internal
|
|
100
|
-
*/
|
|
101
|
-
addChildElement(child) {
|
|
102
|
-
this.root.push(child);
|
|
103
|
-
return this;
|
|
104
|
-
}
|
|
105
|
-
};
|
|
106
|
-
/**
|
|
107
|
-
* XML component that is excluded from output if it has no meaningful content.
|
|
108
|
-
*/
|
|
109
|
-
var IgnoreIfEmptyXmlComponent = class extends XmlComponent {
|
|
110
|
-
includeIfEmpty;
|
|
111
|
-
constructor(rootKey, includeIfEmpty) {
|
|
112
|
-
super(rootKey);
|
|
113
|
-
this.includeIfEmpty = includeIfEmpty;
|
|
114
|
-
}
|
|
115
|
-
/**
|
|
116
|
-
* Suppress empty elements — super.toXml() produces a self-closing tag
|
|
117
|
-
* (`<tag/>`) when there are no child elements; IgnoreIfEmpty returns ""
|
|
118
|
-
* in that case. Child components that already override toXml() (e.g.
|
|
119
|
-
* Worksheet) are unaffected.
|
|
120
|
-
*/
|
|
121
|
-
toXml(context) {
|
|
122
|
-
if (this.includeIfEmpty) return super.toXml(context);
|
|
123
|
-
const result = super.toXml(context);
|
|
124
|
-
return result.endsWith("/>") ? "" : result;
|
|
125
|
-
}
|
|
126
|
-
};
|
|
127
|
-
//#endregion
|
|
128
|
-
//#region src/xml-components/elements.ts
|
|
129
|
-
/**
|
|
130
|
-
* Simple XML element types for common OOXML patterns.
|
|
131
|
-
*
|
|
132
|
-
* @module
|
|
133
|
-
*/
|
|
134
|
-
/**
|
|
135
|
-
* Build an XML element with arbitrary attributes, filtering out undefined values.
|
|
136
|
-
*/
|
|
137
|
-
function attrObj(name, attrs) {
|
|
138
|
-
const filtered = {};
|
|
139
|
-
for (const [key, val] of Object.entries(attrs)) if (val !== void 0) filtered[key] = val;
|
|
140
|
-
return { [name]: { _attr: filtered } };
|
|
141
|
-
}
|
|
142
|
-
const ON_OFF_TRUE_CACHE = /* @__PURE__ */ new Map();
|
|
143
|
-
/**
|
|
144
|
-
* Build a CT_OnOff XML object without allocating any XmlComponent.
|
|
145
|
-
* `val=true` returns a frozen singleton (cached per name).
|
|
146
|
-
*/
|
|
147
|
-
function onOffObj(name, val = true) {
|
|
148
|
-
if (val === true) {
|
|
149
|
-
let cached = ON_OFF_TRUE_CACHE.get(name);
|
|
150
|
-
if (!cached) {
|
|
151
|
-
cached = Object.freeze({ [name]: Object.freeze({}) });
|
|
152
|
-
ON_OFF_TRUE_CACHE.set(name, cached);
|
|
153
|
-
}
|
|
154
|
-
return cached;
|
|
155
|
-
}
|
|
156
|
-
const ns = name.split(":")[0];
|
|
157
|
-
return { [name]: { _attr: { [`${ns}:val`]: val } } };
|
|
158
|
-
}
|
|
159
|
-
/**
|
|
160
|
-
* Build a CT_HpsMeasure XML object (half-point size) without allocation.
|
|
161
|
-
*/
|
|
162
|
-
function hpsMeasureObj(name, val) {
|
|
163
|
-
const ns = name.split(":")[0];
|
|
164
|
-
return { [name]: { _attr: { [`${ns}:val`]: hpsMeasureValue(val) } } };
|
|
165
|
-
}
|
|
166
|
-
/**
|
|
167
|
-
* Build a CT_String XML object (string value attribute) without allocation.
|
|
168
|
-
*/
|
|
169
|
-
function stringValObj(name, val) {
|
|
170
|
-
const ns = name.split(":")[0];
|
|
171
|
-
return { [name]: { _attr: { [`${ns}:val`]: val } } };
|
|
172
|
-
}
|
|
173
|
-
/**
|
|
174
|
-
* Build a numeric value attribute XML object without allocation.
|
|
175
|
-
*/
|
|
176
|
-
function numberValObj(name, val) {
|
|
177
|
-
const ns = name.split(":")[0];
|
|
178
|
-
return { [name]: { _attr: { [`${ns}:val`]: val } } };
|
|
179
|
-
}
|
|
180
|
-
/**
|
|
181
|
-
* Build a string enum value attribute XML object without allocation.
|
|
182
|
-
*/
|
|
183
|
-
function stringEnumValObj(name, val) {
|
|
184
|
-
const ns = name.split(":")[0];
|
|
185
|
-
return { [name]: { _attr: { [`${ns}:val`]: val } } };
|
|
186
|
-
}
|
|
187
|
-
/**
|
|
188
|
-
* Build an element wrapping a text string without allocation.
|
|
189
|
-
*/
|
|
190
|
-
function stringContainerObj(name, val) {
|
|
191
|
-
return { [name]: [val] };
|
|
192
|
-
}
|
|
193
|
-
/**
|
|
194
|
-
* XML element representing an empty element (CT_Empty).
|
|
195
|
-
*/
|
|
196
|
-
var EmptyElement = class extends XmlComponent {};
|
|
197
|
-
/**
|
|
198
|
-
* Flexible XML element builder with explicit attribute and child configuration.
|
|
199
|
-
*/
|
|
200
|
-
var BuilderElement = class extends XmlComponent {
|
|
201
|
-
constructor({ name, attributes, children }) {
|
|
202
|
-
super(name);
|
|
203
|
-
if (attributes) {
|
|
204
|
-
const attrs = {};
|
|
205
|
-
const vals = Object.values(attributes);
|
|
206
|
-
for (let i = 0; i < vals.length; i++) {
|
|
207
|
-
const { key, value } = vals[i];
|
|
208
|
-
if (value !== void 0) attrs[key] = value;
|
|
209
|
-
}
|
|
210
|
-
this.root.push({ _attr: attrs });
|
|
211
|
-
}
|
|
212
|
-
if (children) this.root.push(...children);
|
|
213
|
-
}
|
|
214
|
-
};
|
|
215
|
-
/**
|
|
216
|
-
* Builds an attribute-only IXmlableObject from a plain key-value record.
|
|
217
|
-
*/
|
|
218
|
-
function buildAttrObject(attrs) {
|
|
219
|
-
const result = {};
|
|
220
|
-
for (const [key, value] of Object.entries(attrs)) if (value !== void 0) result[key] = value;
|
|
221
|
-
return Object.keys(result).length > 0 ? { _attr: result } : EMPTY_OBJECT;
|
|
222
|
-
}
|
|
223
|
-
/**
|
|
224
|
-
* Creates an attribute IXmlableObject for chart elements.
|
|
225
|
-
*/
|
|
226
|
-
const chartAttr = (attrs) => buildAttrObject(attrs);
|
|
227
|
-
/**
|
|
228
|
-
* Wraps a component in a named XmlComponent element.
|
|
229
|
-
*/
|
|
230
|
-
function wrapEl(elementName, child) {
|
|
231
|
-
const el = new class extends XmlComponent {
|
|
232
|
-
constructor(name) {
|
|
233
|
-
super(name);
|
|
234
|
-
}
|
|
235
|
-
}(elementName);
|
|
236
|
-
el["root"].push(child);
|
|
237
|
-
return el;
|
|
238
|
-
}
|
|
239
|
-
//#endregion
|
|
240
|
-
//#region src/xml-components/imported.ts
|
|
241
|
-
/**
|
|
242
|
-
* Imported XML Component module for handling external XML content.
|
|
243
|
-
*
|
|
244
|
-
* @module
|
|
245
|
-
*/
|
|
246
|
-
/**
|
|
247
|
-
* Converts an xml-js Element into an XmlComponent tree.
|
|
248
|
-
*/
|
|
249
|
-
const convertToXmlComponent = (element) => {
|
|
250
|
-
switch (element.type) {
|
|
251
|
-
case void 0:
|
|
252
|
-
case "element": {
|
|
253
|
-
const xmlComponent = new ImportedXmlComponent(element.name, element.attributes);
|
|
254
|
-
const childElements = element.elements || [];
|
|
255
|
-
for (const childElm of childElements) {
|
|
256
|
-
const child = convertToXmlComponent(childElm);
|
|
257
|
-
if (child !== void 0) xmlComponent.push(child);
|
|
258
|
-
}
|
|
259
|
-
return xmlComponent;
|
|
260
|
-
}
|
|
261
|
-
case "text": return element.text;
|
|
262
|
-
default: return;
|
|
263
|
-
}
|
|
264
|
-
};
|
|
265
|
-
/**
|
|
266
|
-
* XML component representing imported XML content.
|
|
267
|
-
*/
|
|
268
|
-
var ImportedXmlComponent = class extends XmlComponent {
|
|
269
|
-
_sourceXml;
|
|
270
|
-
static fromXmlString(importedContent) {
|
|
271
|
-
const xmlObj = xml2js(importedContent, { compact: false });
|
|
272
|
-
const component = convertToXmlComponent(xmlObj.elements?.[0] ?? xmlObj);
|
|
273
|
-
component._sourceXml = importedContent;
|
|
274
|
-
return component;
|
|
275
|
-
}
|
|
276
|
-
get sourceXml() {
|
|
277
|
-
return this._sourceXml;
|
|
278
|
-
}
|
|
279
|
-
toXml(_context) {
|
|
280
|
-
return this._sourceXml ?? super.toXml(_context);
|
|
281
|
-
}
|
|
282
|
-
constructor(rootKey, _attr) {
|
|
283
|
-
super(rootKey);
|
|
284
|
-
if (_attr) this.root.push({ _attr });
|
|
285
|
-
}
|
|
286
|
-
push(xmlComponent) {
|
|
287
|
-
this.root.push(xmlComponent);
|
|
288
|
-
}
|
|
289
|
-
};
|
|
290
|
-
/**
|
|
291
|
-
* Represents attributes for imported root elements.
|
|
292
|
-
* The { _attr } in root is consumed by the parent's toXml() serialization.
|
|
293
|
-
*/
|
|
294
|
-
var ImportedRootElementAttributes = class extends XmlComponent {
|
|
295
|
-
_attr;
|
|
296
|
-
constructor(_attr) {
|
|
297
|
-
super("");
|
|
298
|
-
this._attr = _attr;
|
|
299
|
-
if (_attr) this.root.push({ _attr });
|
|
300
|
-
}
|
|
301
|
-
toXml(_context) {
|
|
302
|
-
return "";
|
|
303
|
-
}
|
|
304
|
-
};
|
|
305
|
-
//#endregion
|
|
306
|
-
//#region src/xml-components/initializable.ts
|
|
307
|
-
/**
|
|
308
|
-
* Initializable XML Component module.
|
|
309
|
-
*
|
|
310
|
-
* @module
|
|
311
|
-
*/
|
|
312
|
-
/**
|
|
313
|
-
* XML component that can be initialized from another component.
|
|
314
|
-
*/
|
|
315
|
-
var InitializableXmlComponent = class extends XmlComponent {
|
|
316
|
-
constructor(rootKey, initComponent) {
|
|
317
|
-
super(rootKey);
|
|
318
|
-
if (initComponent instanceof XmlComponent) this.root = initComponent.root;
|
|
319
|
-
}
|
|
320
|
-
};
|
|
321
|
-
//#endregion
|
|
322
|
-
export { EMPTY_OBJECT as _, BuilderElement as a, BaseXmlComponent as b, buildAttrObject as c, numberValObj as d, onOffObj as f, wrapEl as g, stringValObj as h, convertToXmlComponent as i, chartAttr as l, stringEnumValObj as m, ImportedRootElementAttributes as n, EmptyElement as o, stringContainerObj as p, ImportedXmlComponent as r, attrObj as s, InitializableXmlComponent as t, hpsMeasureObj as u, IgnoreIfEmptyXmlComponent as v, XmlComponent as y };
|