@office-open/xml 0.10.1 → 0.10.3

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 CHANGED
@@ -1,4 +1,4 @@
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";
1
+ import { C as Xml2JsOptions, D as XmlDescArray, E as XmlDesc, O as XmlObject, S as Js2XmlOptions, T as XmlAttrs, _ as DeclarationAttributes, a as attrNum, b as ElementObject, c as children, d as findChild, f as findDeep, g as Attributes, h as textOf, i as attrMeasure, k as XmlOption, l as collectText, m as hasChild, n as attr, o as childCount, p as findFirst, r as attrBool, s as childText, t as allChildren, u as colorAttr, v as Element, w as XmlAtom, x as IgnoreOptions, y as ElementCompact } from "./utils-CDLayhwk.mjs";
2
2
 
3
3
  //#region src/serialize.d.ts
4
4
  /**
@@ -30,7 +30,7 @@ declare function json2xml(json: Element, options?: Js2XmlOptions): string;
30
30
  * Convert XmlObject (node-xml format) directly to Element (xml-js format).
31
31
  * Eliminates the redundant xml() → xml2js() bridge path.
32
32
  */
33
- declare function toElement(xmlObject: Record<string, any>): Element;
33
+ declare function toElement(xmlObject: Record<string, unknown>): Element;
34
34
  //#endregion
35
35
  //#region src/escape.d.ts
36
36
  /** Escape text content for XML. Fast path returns original string when no special chars. */
@@ -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, 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 };
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, findFirst, 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, attrMeasure, 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, findFirst, 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) {
@@ -600,11 +600,12 @@ function toElement(xmlObject) {
600
600
  if (children.length > 0) element.elements = children;
601
601
  return element;
602
602
  }
603
- if (typeof value === "object") {
604
- if (value._attr) element.attributes = value._attr;
605
- if (value._cdata) element.elements = [{
603
+ if (typeof value === "object" && value !== null) {
604
+ const obj = value;
605
+ if (obj._attr) element.attributes = obj._attr;
606
+ if (obj._cdata) element.elements = [{
606
607
  type: "cdata",
607
- cdata: String(value._cdata)
608
+ cdata: String(obj._cdata)
608
609
  }];
609
610
  }
610
611
  return element;
@@ -616,4 +617,4 @@ function xml2json(xml, options) {
616
617
  return JSON.stringify(parse(xml, options));
617
618
  }
618
619
  //#endregion
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 };
620
+ export { allChildren, attr, attrBool, attrMeasure, attrNum, attrs, attrsRaw, childCount, childText, children, collectText, colorAttr, element, escapeXml, findChild, findDeep, findFirst, hasChild, stringify as js2xml, stringify, json2xml, nativeTypeValue, parse, parse as xml2js, parseAttributes, selfCloseElement, textOf, toElement, unescapeXml, xml, xml2json };
@@ -187,9 +187,15 @@ declare function hasChild(parent: Element | undefined, name: string): boolean;
187
187
  * Find deep descendant elements matching the given name.
188
188
  */
189
189
  declare function findDeep(parent: Element | undefined, name: string): Element[];
190
+ /**
191
+ * Find the first descendant element with the given name (depth-first pre-order).
192
+ * Short-circuits at the first match — prefer this over `findDeep(parent, name)[0]`
193
+ * to avoid traversing the whole subtree and allocating the full results array.
194
+ */
195
+ declare function findFirst(parent: Element | undefined, name: string): Element | undefined;
190
196
  /**
191
197
  * Get the number of direct child elements.
192
198
  */
193
199
  declare function childCount(parent: Element | undefined): number;
194
200
  //#endregion
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 };
201
+ export { Xml2JsOptions as C, XmlDescArray as D, XmlDesc as E, XmlObject as O, Js2XmlOptions as S, XmlAttrs as T, DeclarationAttributes as _, attrNum as a, ElementObject as b, children as c, findChild as d, findDeep as f, Attributes as g, textOf as h, attrMeasure as i, XmlOption as k, collectText as l, hasChild as m, attr as n, childCount as o, findFirst as p, attrBool as r, childText as s, allChildren as t, colorAttr as u, Element as v, XmlAtom as w, IgnoreOptions as x, ElementCompact as y };
package/dist/utils.d.mts CHANGED
@@ -1,2 +1,2 @@
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 };
1
+ import { a as attrNum, c as children, d as findChild, f as findDeep, h as textOf, i as attrMeasure, l as collectText, m as hasChild, n as attr, o as childCount, p as findFirst, r as attrBool, s as childText, t as allChildren, u as colorAttr } from "./utils-CDLayhwk.mjs";
2
+ export { allChildren, attr, attrBool, attrMeasure, attrNum, childCount, childText, children, collectText, colorAttr, findChild, findDeep, findFirst, hasChild, textOf };
package/dist/utils.mjs CHANGED
@@ -128,10 +128,23 @@ function findDeep(parent, name) {
128
128
  return result;
129
129
  }
130
130
  /**
131
+ * Find the first descendant element with the given name (depth-first pre-order).
132
+ * Short-circuits at the first match — prefer this over `findDeep(parent, name)[0]`
133
+ * to avoid traversing the whole subtree and allocating the full results array.
134
+ */
135
+ function findFirst(parent, name) {
136
+ if (!parent) return void 0;
137
+ for (const child of parent.elements ?? []) {
138
+ if (child.name === name) return child;
139
+ const found = findFirst(child, name);
140
+ if (found) return found;
141
+ }
142
+ }
143
+ /**
131
144
  * Get the number of direct child elements.
132
145
  */
133
146
  function childCount(parent) {
134
147
  return parent?.elements?.length ?? 0;
135
148
  }
136
149
  //#endregion
137
- export { allChildren, attr, attrBool, attrMeasure, attrNum, childCount, childText, children, collectText, colorAttr, findChild, findDeep, hasChild, textOf };
150
+ export { allChildren, attr, attrBool, attrMeasure, attrNum, childCount, childText, children, collectText, colorAttr, findChild, findDeep, findFirst, hasChild, textOf };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@office-open/xml",
3
- "version": "0.10.1",
3
+ "version": "0.10.3",
4
4
  "description": "XML parsing and serialization for Office Open XML. Zero dependencies, drop-in replacement for xml + xml-js.",
5
5
  "keywords": [
6
6
  "office-open",