@office-open/xml 0.3.0 → 0.3.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.
|
@@ -159,6 +159,12 @@ declare function attrNum(element: Element | undefined, name: string): number | u
|
|
|
159
159
|
* Get an attribute value as a boolean.
|
|
160
160
|
*/
|
|
161
161
|
declare function attrBool(element: Element | undefined, name: string): boolean | undefined;
|
|
162
|
+
/**
|
|
163
|
+
* Get a hex color attribute, handling nativeTypeValue coercion.
|
|
164
|
+
* nativeTypeAttributes converts "000000" → 0 (number); this recovers
|
|
165
|
+
* the original 6-digit hex string by zero-padding numeric values.
|
|
166
|
+
*/
|
|
167
|
+
declare function colorAttr(element: Element | undefined, name: string): string | undefined;
|
|
162
168
|
/**
|
|
163
169
|
* Check if an element has a specific child element.
|
|
164
170
|
*/
|
|
@@ -172,4 +178,4 @@ declare function findDeep(parent: Element | undefined, name: string): Element[];
|
|
|
172
178
|
*/
|
|
173
179
|
declare function childCount(parent: Element | undefined): number;
|
|
174
180
|
//#endregion
|
|
175
|
-
export {
|
|
181
|
+
export { XmlAttrs as C, XmlOption as D, XmlObject as E, XmlAtom as S, XmlDescArray as T, ElementCompact as _, childCount as a, Js2XmlOptions as b, collectText as c, findDeep as d, hasChild as f, Element as g, DeclarationAttributes as h, attrNum as i, colorAttr as l, Attributes as m, attr as n, childText as o, textOf as p, attrBool as r, children as s, allChildren as t, findChild as u, ElementObject as v, XmlDesc as w, Xml2JsOptions as x, IgnoreOptions as y };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { C as
|
|
1
|
+
import { C as XmlAttrs, D as XmlOption, E as XmlObject, S as XmlAtom, T as XmlDescArray, _ as ElementCompact, a as childCount, b as Js2XmlOptions, c as collectText, d as findDeep, f as hasChild, g as Element, h as DeclarationAttributes, i as attrNum, l as colorAttr, m as Attributes, n as attr, o as childText, p as textOf, r as attrBool, s as children, t as allChildren, u as findChild, v as ElementObject, w as XmlDesc, x as Xml2JsOptions, y as IgnoreOptions } from "./_chunks/utils-BHmdH50s.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/serialize.d.ts
|
|
4
4
|
declare function xml(input: Record<string, any> | Record<string, any>[], options?: boolean | string | {
|
|
@@ -37,4 +37,4 @@ declare function escapeAttributeValue(str: string): string;
|
|
|
37
37
|
/** Convert XML string to JSON string — xml-js compatible export */
|
|
38
38
|
declare function xml2json(xml: string, options?: Xml2JsOptions): string;
|
|
39
39
|
//#endregion
|
|
40
|
-
export { Attributes, DeclarationAttributes, Element, ElementCompact, ElementObject, IgnoreOptions, Js2XmlOptions, Xml2JsOptions, XmlAtom, XmlAttrs, XmlDesc, XmlDescArray, XmlObject, XmlOption, allChildren, attr, attrBool, attrNum, childCount, childText, children, collectText, escapeAttributeValue, escapeXml, findChild, findDeep, hasChild, js2xml, json2xml, textOf, toElement, xml, xml2js, xml2json };
|
|
40
|
+
export { Attributes, DeclarationAttributes, Element, ElementCompact, ElementObject, IgnoreOptions, Js2XmlOptions, Xml2JsOptions, XmlAtom, XmlAttrs, XmlDesc, XmlDescArray, XmlObject, XmlOption, allChildren, attr, attrBool, attrNum, childCount, childText, children, collectText, colorAttr, escapeAttributeValue, escapeXml, findChild, findDeep, hasChild, js2xml, json2xml, textOf, toElement, xml, xml2js, xml2json };
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { allChildren, attr, attrBool, attrNum, childCount, childText, children, collectText, findChild, findDeep, hasChild, textOf } from "./utils.mjs";
|
|
1
|
+
import { allChildren, attr, attrBool, attrNum, childCount, childText, children, collectText, colorAttr, findChild, findDeep, hasChild, textOf } from "./utils.mjs";
|
|
2
2
|
//#region src/escape.ts
|
|
3
3
|
const XML_CHAR_MAP = {
|
|
4
4
|
"&": "&",
|
|
@@ -67,6 +67,7 @@ function resolve(data, indent, depth) {
|
|
|
67
67
|
switch (typeof values) {
|
|
68
68
|
case "object":
|
|
69
69
|
if (values._attr) for (const key of Object.keys(values._attr)) attributes.push(`${key}="${escapeXml(String(values._attr[key]))}"`);
|
|
70
|
+
if (values._attributes) for (const key of Object.keys(values._attributes)) attributes.push(`${key}="${escapeXml(String(values._attributes[key]))}"`);
|
|
70
71
|
if (values._cdata) {
|
|
71
72
|
const escaped = String(values._cdata).replace(/\]\]>/g, "]]]]><![CDATA[>");
|
|
72
73
|
content.push(`<![CDATA[${escaped}]]>`);
|
|
@@ -81,6 +82,7 @@ function resolve(data, indent, depth) {
|
|
|
81
82
|
emptyArray: true
|
|
82
83
|
};
|
|
83
84
|
for (const value of values) if (value && typeof value === "object" && "_attr" in value) for (const key of Object.keys(value._attr)) attributes.push(`${key}="${escapeXml(String(value._attr[key]))}"`);
|
|
85
|
+
else if (value && typeof value === "object" && "_attributes" in value) for (const key of Object.keys(value._attributes)) attributes.push(`${key}="${escapeXml(String(value._attributes[key]))}"`);
|
|
84
86
|
else if (value && typeof value === "object") content.push(resolve(value, indent, depth + 1));
|
|
85
87
|
else if (value != null) content.push(escapeXml(String(value)));
|
|
86
88
|
}
|
|
@@ -500,4 +502,4 @@ function xml2json(xml, options) {
|
|
|
500
502
|
return JSON.stringify(xml2js(xml, options));
|
|
501
503
|
}
|
|
502
504
|
//#endregion
|
|
503
|
-
export { allChildren, attr, attrBool, attrNum, childCount, childText, children, collectText, escapeAttributeValue, escapeXml, findChild, findDeep, hasChild, js2xml, json2xml, textOf, toElement, xml, xml2js, xml2json };
|
|
505
|
+
export { allChildren, attr, attrBool, attrNum, childCount, childText, children, collectText, colorAttr, escapeAttributeValue, escapeXml, findChild, findDeep, hasChild, js2xml, json2xml, textOf, toElement, xml, xml2js, xml2json };
|
package/dist/utils.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as childCount, c as collectText, d as
|
|
2
|
-
export { allChildren, attr, attrBool, attrNum, childCount, childText, children, collectText, findChild, findDeep, hasChild, textOf };
|
|
1
|
+
import { a as childCount, c as collectText, d as findDeep, f as hasChild, i as attrNum, l as colorAttr, n as attr, o as childText, p as textOf, r as attrBool, s as children, t as allChildren, u as findChild } from "./_chunks/utils-BHmdH50s.mjs";
|
|
2
|
+
export { allChildren, attr, attrBool, attrNum, childCount, childText, children, collectText, colorAttr, findChild, findDeep, hasChild, textOf };
|
package/dist/utils.mjs
CHANGED
|
@@ -75,6 +75,20 @@ function attrBool(element, name) {
|
|
|
75
75
|
if (lower === "false" || lower === "0") return false;
|
|
76
76
|
}
|
|
77
77
|
/**
|
|
78
|
+
* Get a hex color attribute, handling nativeTypeValue coercion.
|
|
79
|
+
* nativeTypeAttributes converts "000000" → 0 (number); this recovers
|
|
80
|
+
* the original 6-digit hex string by zero-padding numeric values.
|
|
81
|
+
*/
|
|
82
|
+
function colorAttr(element, name) {
|
|
83
|
+
const raw = element?.attributes?.[name];
|
|
84
|
+
if (raw === void 0 || raw === "") return void 0;
|
|
85
|
+
if (typeof raw === "boolean") return void 0;
|
|
86
|
+
if (typeof raw === "number") return String(raw).padStart(6, "0");
|
|
87
|
+
if (raw === "auto") return "auto";
|
|
88
|
+
if (/^[0-9A-Fa-f]{6}$/.test(raw)) return raw;
|
|
89
|
+
return raw;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
78
92
|
* Check if an element has a specific child element.
|
|
79
93
|
*/
|
|
80
94
|
function hasChild(parent, name) {
|
|
@@ -99,4 +113,4 @@ function childCount(parent) {
|
|
|
99
113
|
return parent?.elements?.length ?? 0;
|
|
100
114
|
}
|
|
101
115
|
//#endregion
|
|
102
|
-
export { allChildren, attr, attrBool, attrNum, childCount, childText, children, collectText, findChild, findDeep, hasChild, textOf };
|
|
116
|
+
export { allChildren, attr, attrBool, attrNum, childCount, childText, children, collectText, colorAttr, findChild, findDeep, hasChild, textOf };
|