@stll/docx-core 0.39.2 → 0.41.0

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.
@@ -1 +1 @@
1
- export { a as SEQUENCE_CHILDREN, o as SETTINGS_CHILDREN, t as assertSafePreservedMarkup, n as isSafePreservedChildXml, r as isWithinPreservedMarkupBudget, i as serializeSequenceChildren } from "../sequenceChildren-CrMcryEF.js";
1
+ export { a as SEQUENCE_CHILDREN, o as SETTINGS_CHILDREN, t as assertSafePreservedMarkup, n as isSafePreservedChildXml, r as isWithinPreservedMarkupBudget, i as serializeSequenceChildren } from "../sequenceChildren-CSn0-1ov.js";
@@ -1,5 +1,5 @@
1
+ import { o as readXml } from "./streamingXmlParser-GnKxUuw_.js";
1
2
  import { TaggedError } from "better-result";
2
- import { XMLParser, XMLValidator } from "fast-xml-parser";
3
3
  import { OOXML_NS } from "@stll/docx-utils";
4
4
  // src/schema/sequenceChildren.gen.ts
5
5
  /**
@@ -375,18 +375,6 @@ const MAX_PRESERVED_CHILD_XML_CHARACTERS = 1048576;
375
375
  const MAX_PRESERVED_CHILD_COUNT = 4096;
376
376
  const MAX_PRESERVED_MARKUP_CHARACTERS = 4194304;
377
377
  const PRESERVED_CHILD_WRAPPER = "folio-preserved-child-root";
378
- const preservedChildParser = new XMLParser({
379
- preserveOrder: true,
380
- ignoreAttributes: false,
381
- attributeNamePrefix: "",
382
- trimValues: false,
383
- parseTagValue: false,
384
- parseAttributeValue: false,
385
- ignoreDeclaration: false,
386
- ignorePiTags: false,
387
- processEntities: false,
388
- htmlEntities: false
389
- });
390
378
  const InvalidPreservedChildXmlErrorBase = TaggedError("InvalidPreservedChildXmlError");
391
379
  var InvalidPreservedChildXmlError = class extends InvalidPreservedChildXmlErrorBase {};
392
380
  const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
@@ -467,12 +455,9 @@ const hasValidNamespaces = (root, inherited) => {
467
455
  const current = pending.pop();
468
456
  if (current === void 0) continue;
469
457
  const { node, bindings: parentBindings } = current;
470
- const nodeNames = Object.keys(node).filter((name) => name !== ":@");
471
- const name = nodeNames[0];
472
- if (nodeNames.length !== 1 || name === void 0) return false;
473
- if (name.startsWith("#") || name.startsWith("?") || name.startsWith("!")) continue;
474
- const rawAttributes = node[":@"];
475
- const attributes = isRecord(rawAttributes) ? rawAttributes : {};
458
+ const name = node.name;
459
+ if (node.type !== "element" || name === void 0) continue;
460
+ const attributes = node.attributes ?? {};
476
461
  const bindings = applyNamespaceDeclarations(attributes, parentBindings);
477
462
  if (bindings === void 0) return false;
478
463
  const elementPrefix = namespacePrefix(name);
@@ -489,15 +474,10 @@ const hasValidNamespaces = (root, inherited) => {
489
474
  if (expandedAttributeNames.has(expandedName)) return false;
490
475
  expandedAttributeNames.add(expandedName);
491
476
  }
492
- const children = node[name];
493
- if (!Array.isArray(children)) return false;
494
- for (const child of children) {
495
- if (!isRecord(child)) return false;
496
- pending.push({
497
- node: child,
498
- bindings
499
- });
500
- }
477
+ for (const child of node.elements ?? []) pending.push({
478
+ node: child,
479
+ bindings
480
+ });
501
481
  }
502
482
  return true;
503
483
  };
@@ -506,23 +486,15 @@ const isSafePreservedChildXml = (xml) => {
506
486
  const trimmed = xml.trim();
507
487
  if (trimmed.length === 0 || trimmed.length > MAX_PRESERVED_CHILD_XML_CHARACTERS || /<!\s*(?:DOCTYPE|ENTITY)\b/iu.test(trimmed) || !hasOnlyValidXmlReferences(trimmed)) return false;
508
488
  const wrapped = `<${PRESERVED_CHILD_WRAPPER}>${trimmed}</${PRESERVED_CHILD_WRAPPER}>`;
509
- if (XMLValidator.validate(wrapped) !== true) return false;
510
- let parsed;
511
- try {
512
- parsed = preservedChildParser.parse(wrapped);
513
- } catch {
514
- return false;
515
- }
516
- if (!Array.isArray(parsed) || parsed.length !== 1) return false;
517
- const wrapper = parsed[0];
518
- if (!isRecord(wrapper)) return false;
519
- const children = wrapper[PRESERVED_CHILD_WRAPPER];
520
- if (!Array.isArray(children) || children.length !== 1) return false;
521
- const child = children[0];
522
- if (!isRecord(child)) return false;
523
- const nodeNames = Object.keys(child).filter((name) => name !== ":@");
524
- const nodeName = nodeNames[0];
525
- return nodeNames.length === 1 && nodeName !== void 0 && !nodeName.startsWith("#") && !nodeName.startsWith("?") && !nodeName.startsWith("!") && hasValidNamespaces(child, INHERITED_NAMESPACE_BINDINGS);
489
+ const read = readXml(wrapped, {
490
+ conformance: "well-formed",
491
+ references: "raw",
492
+ instructions: "retain"
493
+ });
494
+ if (read.status === "rejected") return false;
495
+ const children = read.value.elements?.at(0)?.elements ?? [];
496
+ const child = children.at(0);
497
+ return children.length === 1 && child?.type === "element" && hasValidNamespaces(child, INHERITED_NAMESPACE_BINDINGS);
526
498
  };
527
499
  /** Whether a capture collection stays within its aggregate resource budget. */
528
500
  const isWithinPreservedMarkupBudget = (children) => {