@office-open/core 0.10.2 → 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.
@@ -152,6 +152,22 @@ const patchSpaceAttribute = (element) => ({
152
152
  attributes: { "xml:space": "preserve" }
153
153
  });
154
154
  const getFirstLevelElements = (relationships, id) => relationships.elements?.find((e) => e.name === id)?.elements ?? [];
155
+ /**
156
+ * Next sequential numeric id: the largest `attr` value among direct children
157
+ * named `childName`, plus one. `seed` is the floor — e.g. PPTX `<p:sldId>`
158
+ * values start at 255, so the first appended id is at least 256.
159
+ *
160
+ * Unifies the per-package `maxCommentId` / `maxSldId` / `maxSheetId` helpers.
161
+ */
162
+ const nextNumericId = (parent, childName, attr, seed = 0) => {
163
+ let maxId = seed;
164
+ for (const child of parent?.elements ?? []) {
165
+ if (child.name !== childName) continue;
166
+ const id = Number(child.attributes?.[attr]);
167
+ if (Number.isFinite(id)) maxId = Math.max(maxId, id);
168
+ }
169
+ return maxId + 1;
170
+ };
155
171
  //#endregion
156
172
  //#region src/patch/paragraph-split-inject.ts
157
173
  var TokenNotFoundError = class extends Error {
@@ -437,10 +453,21 @@ const goToParentElementFromPath = (json, path) => goToElementFromPath(json, path
437
453
  const getLastElementIndexFromPath = (path) => path[path.length - 1];
438
454
  //#endregion
439
455
  //#region src/patch/content-types-manager.ts
456
+ /**
457
+ * The `<Types>` child array, initialized in place when absent (so a `<Default>`
458
+ * or `<Override>` can always be appended). Returns `undefined` if `element` has
459
+ * no `<Types>` child (malformed `[Content_Types].xml`).
460
+ */
461
+ const typesChildren = (element) => {
462
+ const types = element.elements?.find((e) => e.name === "Types");
463
+ if (!types) return void 0;
464
+ return types.elements ?? (types.elements = []);
465
+ };
440
466
  const appendContentType = (element, contentType, extension) => {
441
- const relationshipElements = getFirstLevelElements(element, "Types");
442
- if (relationshipElements.some((el) => el.type === "element" && el.name === "Default" && el?.attributes?.ContentType === contentType && el?.attributes?.Extension === extension)) return;
443
- relationshipElements.push({
467
+ const els = typesChildren(element);
468
+ if (!els) return;
469
+ if (els.some((el) => el.type === "element" && el.name === "Default" && el?.attributes?.ContentType === contentType && el?.attributes?.Extension === extension)) return;
470
+ els.push({
444
471
  attributes: {
445
472
  ContentType: contentType,
446
473
  Extension: extension
@@ -449,6 +476,24 @@ const appendContentType = (element, contentType, extension) => {
449
476
  type: "element"
450
477
  });
451
478
  };
479
+ /**
480
+ * Append an `<Override>` element to a `[Content_Types].xml` root, deduped by
481
+ * `PartName`. Sibling to {@link appendContentType} (which handles `<Default>`):
482
+ * unifies the per-package Override-dedup blocks in docx/pptx/xlsx patchers.
483
+ */
484
+ const appendOverride = (element, partName, contentType) => {
485
+ const els = typesChildren(element);
486
+ if (!els) return;
487
+ if (els.some((el) => el.type === "element" && el.name === "Override" && el?.attributes?.PartName === partName)) return;
488
+ els.push({
489
+ attributes: {
490
+ PartName: partName,
491
+ ContentType: contentType
492
+ },
493
+ name: "Override",
494
+ type: "element"
495
+ });
496
+ };
452
497
  //#endregion
453
498
  //#region src/patch/relationship-manager.ts
454
499
  const getIdFromRelationshipId = (relationshipId) => {
@@ -481,4 +526,4 @@ function applyCorePropertiesOverride(corePropsDoc, overrides) {
481
526
  });
482
527
  }
483
528
  //#endregion
484
- export { buildCorePropertiesXml as _, createReplacer as a, createTokenReplacer as c, createTextElementContents as d, getFirstLevelElements as f, PPTX_NS as g, DOCX_NS as h, appendContentType as i, TokenNotFoundError as l, toJson as m, appendRelationship as n, createTraverser as o, patchSpaceAttribute as p, getNextRelationshipIndex as r, createRunRenderer as s, applyCorePropertiesOverride as t, createSplitInject as u, buildCorePropertiesXmlString as v, parseCorePropsElement as y };
529
+ export { DOCX_NS as _, appendOverride as a, buildCorePropertiesXmlString as b, createRunRenderer as c, createSplitInject as d, createTextElementContents as f, toJson as g, patchSpaceAttribute as h, appendContentType as i, createTokenReplacer as l, nextNumericId as m, appendRelationship as n, createReplacer as o, getFirstLevelElements as p, getNextRelationshipIndex as r, createTraverser as s, applyCorePropertiesOverride as t, TokenNotFoundError as u, PPTX_NS as v, parseCorePropsElement as x, buildCorePropertiesXml as y };