@office-open/core 0.6.7 → 0.6.9
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 +9 -9
- package/dist/chart/index.d.mts +1 -1
- package/dist/chart/index.mjs +1 -1
- package/dist/{chart-DO9i3S1G.mjs → chart-BjBXDvRe.mjs} +1 -1
- package/dist/drawingml/index.d.mts +2 -2
- package/dist/drawingml/index.mjs +1 -1
- package/dist/{drawingml-DzU9sEb0.mjs → drawingml-B_cFnIfw.mjs} +9 -9
- package/dist/{index-BCjRiF78.d.mts → index-BD7Tgfi4.d.mts} +1 -1
- package/dist/{index-CCGNb26x.d.mts → index-C0Iqsm0K.d.mts} +2 -2
- package/dist/{index-Bf86IyeY.d.mts → index-CECweGf1.d.mts} +2 -2
- package/dist/{index-bZQnCpM1.d.mts → index-CzsIq-Qi.d.mts} +25 -40
- package/dist/index.d.mts +31 -30
- package/dist/index.mjs +24 -42
- package/dist/patch/index.d.mts +2 -2
- package/dist/patch/index.mjs +1 -1
- package/dist/{patch-O6SD_BaJ.mjs → patch-DCGadPUU.mjs} +56 -38
- package/dist/smartart/index.d.mts +1 -1
- package/dist/smartart/index.mjs +1 -1
- package/dist/{smartart-vyDm6U1_.mjs → smartart-3Aw0Aho1.mjs} +5 -9
- package/dist/values.d.mts +1 -1
- package/dist/{xml-components-ctIqansl.mjs → xml-components-BWnF8xox.mjs} +38 -83
- package/package.json +2 -2
- /package/dist/{index-DNLRdIqy.d.mts → index-BCUfgp9A.d.mts} +0 -0
- /package/dist/{values-QyWq4U4A.d.mts → values-COjPGYkS.d.mts} +0 -0
|
@@ -2,11 +2,6 @@ import { hpsMeasureValue } from "./values.mjs";
|
|
|
2
2
|
import { escapeXml, xml, xml2js } from "@office-open/xml";
|
|
3
3
|
//#region src/xml-components/base.ts
|
|
4
4
|
/**
|
|
5
|
-
* Base XML Component infrastructure for OOXML document generation.
|
|
6
|
-
*
|
|
7
|
-
* @module
|
|
8
|
-
*/
|
|
9
|
-
/**
|
|
10
5
|
* Abstract base class for all XML components.
|
|
11
6
|
*/
|
|
12
7
|
var BaseXmlComponent = class {
|
|
@@ -16,12 +11,14 @@ var BaseXmlComponent = class {
|
|
|
16
11
|
this.rootKey = rootKey;
|
|
17
12
|
}
|
|
18
13
|
/**
|
|
14
|
+
* @deprecated Use `toXml()` instead.
|
|
15
|
+
*/
|
|
16
|
+
prepForXml(_context) {}
|
|
17
|
+
/**
|
|
19
18
|
* Direct XML serialization. Override in subclasses for zero-allocation output.
|
|
20
|
-
* Default falls back to prepForXml() + xml().
|
|
21
19
|
*/
|
|
22
|
-
toXml(
|
|
23
|
-
|
|
24
|
-
return obj ? xml(obj) : "";
|
|
20
|
+
toXml(_context) {
|
|
21
|
+
return "";
|
|
25
22
|
}
|
|
26
23
|
};
|
|
27
24
|
//#endregion
|
|
@@ -55,7 +52,7 @@ var XmlComponent = class extends BaseXmlComponent {
|
|
|
55
52
|
this.root = [];
|
|
56
53
|
}
|
|
57
54
|
/**
|
|
58
|
-
*
|
|
55
|
+
* @deprecated Use `toXml()` instead.
|
|
59
56
|
*/
|
|
60
57
|
prepForXml(context) {
|
|
61
58
|
context.stack.push(this);
|
|
@@ -77,21 +74,12 @@ var XmlComponent = class extends BaseXmlComponent {
|
|
|
77
74
|
for (const child of this.root) if (child instanceof BaseXmlComponent) {
|
|
78
75
|
const s = child.toXml(context);
|
|
79
76
|
if (s) childParts.push(s);
|
|
80
|
-
if (!s && child.constructor.name === "NextAttributeComponent") {
|
|
81
|
-
const prepped = child.prepForXml(context);
|
|
82
|
-
if (prepped && typeof prepped === "object" && "_attr" in prepped) {
|
|
83
|
-
const a = prepped._attr;
|
|
84
|
-
for (const key of Object.keys(a)) attrParts.push(`${key}="${escapeXml(String(a[key]))}"`);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
77
|
} else if (typeof child === "string") childParts.push(escapeXml(child));
|
|
88
|
-
else if (child != null && typeof child === "object")
|
|
89
|
-
const a = child._attr;
|
|
90
|
-
for (const key of Object.keys(a)) attrParts.push(`${key}="${escapeXml(String(a[key]))}"`);
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
for (const key of Object.keys(a)) attrParts.push(`${key}="${escapeXml(String(a[key]))}"`);
|
|
94
|
-
} else childParts.push(xml(child));
|
|
78
|
+
else if (child != null && typeof child === "object") {
|
|
79
|
+
const a = "_attr" in child ? child._attr : "_attributes" in child ? child._attributes : null;
|
|
80
|
+
if (a) for (const key of Object.keys(a)) attrParts.push(`${key}="${escapeXml(String(a[key]))}"`);
|
|
81
|
+
else childParts.push(xml(child));
|
|
82
|
+
}
|
|
95
83
|
const attrStr = attrParts.length ? " " + attrParts.join(" ") : "";
|
|
96
84
|
const body = childParts.join("");
|
|
97
85
|
return body.length === 0 ? `<${this.rootKey}${attrStr}/>` : `<${this.rootKey}${attrStr}>${body}</${this.rootKey}>`;
|
|
@@ -113,10 +101,13 @@ var IgnoreIfEmptyXmlComponent = class extends XmlComponent {
|
|
|
113
101
|
super(rootKey);
|
|
114
102
|
this.includeIfEmpty = includeIfEmpty;
|
|
115
103
|
}
|
|
104
|
+
/**
|
|
105
|
+
* @deprecated Use `toXml()` instead.
|
|
106
|
+
*/
|
|
116
107
|
prepForXml(context) {
|
|
108
|
+
if (this.includeIfEmpty) return super.prepForXml(context);
|
|
117
109
|
const result = super.prepForXml(context);
|
|
118
|
-
|
|
119
|
-
if (result && (typeof result[this.rootKey] !== "object" || Object.keys(result[this.rootKey]).length)) return result;
|
|
110
|
+
return result && result[this.rootKey] === EMPTY_OBJECT ? void 0 : result;
|
|
120
111
|
}
|
|
121
112
|
/**
|
|
122
113
|
* Suppress empty elements — super.toXml() produces a self-closing tag
|
|
@@ -131,56 +122,6 @@ var IgnoreIfEmptyXmlComponent = class extends XmlComponent {
|
|
|
131
122
|
}
|
|
132
123
|
};
|
|
133
124
|
//#endregion
|
|
134
|
-
//#region src/xml-components/attributes.ts
|
|
135
|
-
/**
|
|
136
|
-
* XML attribute components for OOXML document generation.
|
|
137
|
-
*
|
|
138
|
-
* @module
|
|
139
|
-
*/
|
|
140
|
-
/**
|
|
141
|
-
* Base class for creating XML attributes with automatic name mapping.
|
|
142
|
-
*/
|
|
143
|
-
var XmlAttributeComponent = class extends BaseXmlComponent {
|
|
144
|
-
/** Optional mapping from property names to XML attribute names. */
|
|
145
|
-
xmlKeys;
|
|
146
|
-
constructor(root) {
|
|
147
|
-
super("_attr");
|
|
148
|
-
this.root = root;
|
|
149
|
-
}
|
|
150
|
-
prepForXml(_) {
|
|
151
|
-
const attrs = {};
|
|
152
|
-
Object.entries(this.root).forEach(([key, value]) => {
|
|
153
|
-
if (value !== void 0) {
|
|
154
|
-
const newKey = this.xmlKeys && this.xmlKeys[key] || key;
|
|
155
|
-
attrs[newKey] = value;
|
|
156
|
-
}
|
|
157
|
-
});
|
|
158
|
-
return { _attr: attrs };
|
|
159
|
-
}
|
|
160
|
-
};
|
|
161
|
-
/**
|
|
162
|
-
* Next-generation attribute component with explicit key-value pairs.
|
|
163
|
-
*/
|
|
164
|
-
var NextAttributeComponent = class extends BaseXmlComponent {
|
|
165
|
-
constructor(root) {
|
|
166
|
-
super("_attr");
|
|
167
|
-
this.root = root;
|
|
168
|
-
}
|
|
169
|
-
prepForXml(_) {
|
|
170
|
-
const attrs = {};
|
|
171
|
-
const values = Object.values(this.root);
|
|
172
|
-
for (let i = 0; i < values.length; i++) {
|
|
173
|
-
const { key, value } = values[i];
|
|
174
|
-
if (value !== void 0) attrs[key] = value;
|
|
175
|
-
}
|
|
176
|
-
return { _attr: attrs };
|
|
177
|
-
}
|
|
178
|
-
/** Attribute components produce no XML output — attrs are inlined by the parent. */
|
|
179
|
-
toXml(_context) {
|
|
180
|
-
return "";
|
|
181
|
-
}
|
|
182
|
-
};
|
|
183
|
-
//#endregion
|
|
184
125
|
//#region src/xml-components/elements.ts
|
|
185
126
|
/**
|
|
186
127
|
* Simple XML element types for common OOXML patterns.
|
|
@@ -269,12 +210,17 @@ var BuilderElement = class extends XmlComponent {
|
|
|
269
210
|
}
|
|
270
211
|
};
|
|
271
212
|
/**
|
|
272
|
-
*
|
|
213
|
+
* Builds an attribute-only IXmlableObject from a plain key-value record.
|
|
273
214
|
*/
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
value
|
|
277
|
-
}
|
|
215
|
+
function buildAttrObject(attrs) {
|
|
216
|
+
const result = {};
|
|
217
|
+
for (const [key, value] of Object.entries(attrs)) if (value !== void 0) result[key] = value;
|
|
218
|
+
return Object.keys(result).length > 0 ? { _attr: result } : EMPTY_OBJECT;
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Creates an attribute IXmlableObject for chart elements.
|
|
222
|
+
*/
|
|
223
|
+
const chartAttr = (attrs) => buildAttrObject(attrs);
|
|
278
224
|
/**
|
|
279
225
|
* Wraps a component in a named XmlComponent element.
|
|
280
226
|
*/
|
|
@@ -340,15 +286,24 @@ var ImportedXmlComponent = class extends XmlComponent {
|
|
|
340
286
|
};
|
|
341
287
|
/**
|
|
342
288
|
* Represents attributes for imported root elements.
|
|
289
|
+
* The { _attr } in root is consumed by the parent's toXml() serialization.
|
|
343
290
|
*/
|
|
344
291
|
var ImportedRootElementAttributes = class extends XmlComponent {
|
|
292
|
+
_attr;
|
|
345
293
|
constructor(_attr) {
|
|
346
294
|
super("");
|
|
347
295
|
this._attr = _attr;
|
|
296
|
+
if (_attr) this.root.push({ _attr });
|
|
348
297
|
}
|
|
349
|
-
|
|
298
|
+
/**
|
|
299
|
+
* @deprecated Use `toXml()` instead.
|
|
300
|
+
*/
|
|
301
|
+
prepForXml(_context) {
|
|
350
302
|
return { _attr: this._attr };
|
|
351
303
|
}
|
|
304
|
+
toXml(_context) {
|
|
305
|
+
return "";
|
|
306
|
+
}
|
|
352
307
|
};
|
|
353
308
|
//#endregion
|
|
354
309
|
//#region src/xml-components/initializable.ts
|
|
@@ -367,4 +322,4 @@ var InitializableXmlComponent = class extends XmlComponent {
|
|
|
367
322
|
}
|
|
368
323
|
};
|
|
369
324
|
//#endregion
|
|
370
|
-
export {
|
|
325
|
+
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 };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@office-open/core",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.9",
|
|
4
4
|
"description": "Shared OOXML infrastructure: XmlComponent, value validators, unit converters",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"core",
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
"fflate": "0.8.3",
|
|
56
56
|
"hash.js": "1.1.7",
|
|
57
57
|
"nanoid": "5.1.11",
|
|
58
|
-
"@office-open/xml": "0.6.
|
|
58
|
+
"@office-open/xml": "0.6.9"
|
|
59
59
|
},
|
|
60
60
|
"scripts": {
|
|
61
61
|
"dev": "basis build --stub",
|
|
File without changes
|
|
File without changes
|