@office-open/xml 0.10.0 → 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/index.d.mts +2 -2
- package/dist/index.mjs +2 -2
- package/dist/{utils-DJSm61Ws.d.mts → utils-DhRRTcbt.d.mts} +15 -1
- package/dist/utils.d.mts +2 -2
- package/dist/utils.mjs +22 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { C as
|
|
1
|
+
import { C as XmlAtom, D as XmlObject, E as XmlDescArray, O as XmlOption, S as Xml2JsOptions, T as XmlDesc, _ as Element, a as attrNum, b as IgnoreOptions, c as children, d as findChild, f as findDeep, g as DeclarationAttributes, h as Attributes, i as attrMeasure, l as collectText, m as textOf, n as attr, o as childCount, p as hasChild, r as attrBool, s as childText, t as allChildren, u as colorAttr, v as ElementCompact, w as XmlAttrs, x as Js2XmlOptions, y as ElementObject } from "./utils-DhRRTcbt.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/serialize.d.ts
|
|
4
4
|
/**
|
|
@@ -84,4 +84,4 @@ declare function element(name: string, attrRecord?: Readonly<Record<string, stri
|
|
|
84
84
|
/** Convert XML string to JSON string — xml-js compatible export */
|
|
85
85
|
declare function xml2json(xml: string, options?: Xml2JsOptions): string;
|
|
86
86
|
//#endregion
|
|
87
|
-
export { type Attributes, type DeclarationAttributes, type Element, type ElementCompact, type ElementObject, type IgnoreOptions, type Js2XmlOptions, type Xml2JsOptions, type XmlAtom, type XmlAttrs, type XmlDesc, type XmlDescArray, type XmlObject, type XmlOption, allChildren, attr, attrBool, attrNum, attrs, attrsRaw, childCount, childText, children, collectText, colorAttr, element, escapeXml, findChild, findDeep, hasChild, stringify as js2xml, stringify, json2xml, nativeTypeValue, parse, parse as xml2js, parseAttributes, selfCloseElement, textOf, toElement, unescapeXml, xml, xml2json };
|
|
87
|
+
export { type Attributes, type DeclarationAttributes, type Element, type ElementCompact, type ElementObject, type IgnoreOptions, type Js2XmlOptions, type Xml2JsOptions, type XmlAtom, type XmlAttrs, type XmlDesc, type XmlDescArray, type XmlObject, type XmlOption, allChildren, attr, attrBool, attrMeasure, attrNum, attrs, attrsRaw, childCount, childText, children, collectText, colorAttr, element, escapeXml, findChild, findDeep, hasChild, stringify as js2xml, stringify, json2xml, nativeTypeValue, parse, parse as xml2js, parseAttributes, selfCloseElement, textOf, toElement, unescapeXml, xml, xml2json };
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { allChildren, attr, attrBool, attrNum, childCount, childText, children, collectText, colorAttr, findChild, findDeep, hasChild, textOf } from "./utils.mjs";
|
|
1
|
+
import { allChildren, attr, attrBool, attrMeasure, attrNum, childCount, childText, children, collectText, colorAttr, findChild, findDeep, hasChild, textOf } from "./utils.mjs";
|
|
2
2
|
//#region src/escape.ts
|
|
3
3
|
/** Escape text content for XML. Fast path returns original string when no special chars. */
|
|
4
4
|
function escapeXml(str) {
|
|
@@ -616,4 +616,4 @@ function xml2json(xml, options) {
|
|
|
616
616
|
return JSON.stringify(parse(xml, options));
|
|
617
617
|
}
|
|
618
618
|
//#endregion
|
|
619
|
-
export { allChildren, attr, attrBool, attrNum, attrs, attrsRaw, childCount, childText, children, collectText, colorAttr, element, escapeXml, findChild, findDeep, hasChild, stringify as js2xml, stringify, json2xml, nativeTypeValue, parse, parse as xml2js, parseAttributes, selfCloseElement, textOf, toElement, unescapeXml, xml, xml2json };
|
|
619
|
+
export { allChildren, attr, attrBool, attrMeasure, attrNum, attrs, attrsRaw, childCount, childText, children, collectText, colorAttr, element, escapeXml, findChild, findDeep, hasChild, stringify as js2xml, stringify, json2xml, nativeTypeValue, parse, parse as xml2js, parseAttributes, selfCloseElement, textOf, toElement, unescapeXml, xml, xml2json };
|
|
@@ -155,6 +155,20 @@ declare function attr(element: Element | undefined, name: string): string | unde
|
|
|
155
155
|
* Get an attribute value as a number.
|
|
156
156
|
*/
|
|
157
157
|
declare function attrNum(element: Element | undefined, name: string): number | undefined;
|
|
158
|
+
/**
|
|
159
|
+
* Get a measurement attribute as a number or a verbatim measure/percent string.
|
|
160
|
+
*
|
|
161
|
+
* Counterpart to {@link attrNum} for XSD attribute unions of a decimal number
|
|
162
|
+
* and UniversalMeasure/Percentage (ST_TwipsMeasure, ST_MeasurementOrPercent,
|
|
163
|
+
* CT_TblWidth/@w, CT_Height/@val): a plain numeric token yields a number, while
|
|
164
|
+
* UniversalMeasure ("5mm") and Percentage ("50%") stay verbatim so they
|
|
165
|
+
* round-trip with the stringify-side value helpers in @office-open/core.
|
|
166
|
+
*
|
|
167
|
+
* Pass the sibling @type for CT_TblWidth with type="pct" — its fiftieths token
|
|
168
|
+
* ("5000") must stay a string, since converting it to 5000 would make a later
|
|
169
|
+
* stringify re-emit "5000%", changing the value.
|
|
170
|
+
*/
|
|
171
|
+
declare function attrMeasure(element: Element | undefined, name: string, type?: string): number | string | undefined;
|
|
158
172
|
/**
|
|
159
173
|
* Get an attribute value as a boolean.
|
|
160
174
|
*/
|
|
@@ -178,4 +192,4 @@ declare function findDeep(parent: Element | undefined, name: string): Element[];
|
|
|
178
192
|
*/
|
|
179
193
|
declare function childCount(parent: Element | undefined): number;
|
|
180
194
|
//#endregion
|
|
181
|
-
export {
|
|
195
|
+
export { XmlAtom as C, XmlObject as D, XmlDescArray as E, XmlOption as O, Xml2JsOptions as S, XmlDesc as T, Element as _, attrNum as a, IgnoreOptions as b, children as c, findChild as d, findDeep as f, DeclarationAttributes as g, Attributes as h, attrMeasure as i, collectText as l, textOf as m, attr as n, childCount as o, hasChild as p, attrBool as r, childText as s, allChildren as t, colorAttr as u, ElementCompact as v, XmlAttrs as w, Js2XmlOptions as x, ElementObject as y };
|
package/dist/utils.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as
|
|
2
|
-
export { allChildren, attr, attrBool, attrNum, childCount, childText, children, collectText, colorAttr, findChild, findDeep, hasChild, textOf };
|
|
1
|
+
import { a as attrNum, c as children, d as findChild, f as findDeep, i as attrMeasure, l as collectText, m as textOf, n as attr, o as childCount, p as hasChild, r as attrBool, s as childText, t as allChildren, u as colorAttr } from "./utils-DhRRTcbt.mjs";
|
|
2
|
+
export { allChildren, attr, attrBool, attrMeasure, attrNum, childCount, childText, children, collectText, colorAttr, findChild, findDeep, hasChild, textOf };
|
package/dist/utils.mjs
CHANGED
|
@@ -64,6 +64,27 @@ function attrNum(element, name) {
|
|
|
64
64
|
return isNaN(n) ? void 0 : n;
|
|
65
65
|
}
|
|
66
66
|
/**
|
|
67
|
+
* Get a measurement attribute as a number or a verbatim measure/percent string.
|
|
68
|
+
*
|
|
69
|
+
* Counterpart to {@link attrNum} for XSD attribute unions of a decimal number
|
|
70
|
+
* and UniversalMeasure/Percentage (ST_TwipsMeasure, ST_MeasurementOrPercent,
|
|
71
|
+
* CT_TblWidth/@w, CT_Height/@val): a plain numeric token yields a number, while
|
|
72
|
+
* UniversalMeasure ("5mm") and Percentage ("50%") stay verbatim so they
|
|
73
|
+
* round-trip with the stringify-side value helpers in @office-open/core.
|
|
74
|
+
*
|
|
75
|
+
* Pass the sibling @type for CT_TblWidth with type="pct" — its fiftieths token
|
|
76
|
+
* ("5000") must stay a string, since converting it to 5000 would make a later
|
|
77
|
+
* stringify re-emit "5000%", changing the value.
|
|
78
|
+
*/
|
|
79
|
+
function attrMeasure(element, name, type) {
|
|
80
|
+
const v = element?.attributes?.[name];
|
|
81
|
+
if (v === void 0) return void 0;
|
|
82
|
+
const raw = String(v);
|
|
83
|
+
if (type === "pct") return raw;
|
|
84
|
+
const n = Number(raw);
|
|
85
|
+
return Number.isNaN(n) ? raw : n;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
67
88
|
* Get an attribute value as a boolean.
|
|
68
89
|
*/
|
|
69
90
|
function attrBool(element, name) {
|
|
@@ -113,4 +134,4 @@ function childCount(parent) {
|
|
|
113
134
|
return parent?.elements?.length ?? 0;
|
|
114
135
|
}
|
|
115
136
|
//#endregion
|
|
116
|
-
export { allChildren, attr, attrBool, attrNum, childCount, childText, children, collectText, colorAttr, findChild, findDeep, hasChild, textOf };
|
|
137
|
+
export { allChildren, attr, attrBool, attrMeasure, attrNum, childCount, childText, children, collectText, colorAttr, findChild, findDeep, hasChild, textOf };
|