ooxml.js 1.2.0 → 1.3.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.
package/README.md CHANGED
@@ -182,6 +182,7 @@ The package is layered from a lossless core outward to lossy convenience views:
182
182
  - **Binary-vs-XML part classification is a byte sniff, not an extension check.** `package-io/read.ts`'s `looksLikeXml` looks for a leading `<` after skipping a UTF-8 BOM and whitespace; this is deliberate (no standard OOXML binary part starts with `<`) but means any future binary format starting with `<` would misclassify.
183
183
  - **`Array.isArray` narrows `unknown` to `any[]`, not `unknown[]`.** `lib.es5.d.ts` types its parameter as `any`, so TypeScript can't do better even after the check succeeds — indexing straight into the result (e.g. `value[0]`) silently reintroduces `any` and trips `@typescript-eslint/no-unsafe-assignment`. `compact.ts` and `xml/parse.ts` each define a local `isUnknownArray` guard (`value is unknown[]`) for exactly this reason; reach for it instead of `Array.isArray` wherever the narrowed element is going to be read.
184
184
  - **TypeScript is pinned to the latest 6.x, not 7.** TypeScript 7 restructured its JS-facing API surface heavily enough that both `typescript-eslint` (peer range `<6.1.0`) and `cosmiconfig`'s TypeScript loader (used by `semantic-release` to read `release.config.ts`, via `typescript.findConfigFile`, which TS 7 no longer exports) break under it. Upgrading past 6.x has to wait for that ecosystem tooling to add TS 7 support.
185
+ - **`release-notes-generator`'s `preset` is `angular`, not `conventionalcommits`, unlike `commit-analyzer`'s.** `conventional-changelog-conventionalcommits@10.2.1` exports its changelog body under the key `template`, but the `conventional-changelog-writer` version `@semantic-release/release-notes-generator@14.1.1` bundles only reads `options.mainTemplate` — so the body silently falls back to the writer's own generic default, whose commit partial doesn't match conventionalcommits' function-based partial signature either. The result is a changelog with a version header and nothing under it, confirmed even with zero custom configuration (`preset: 'conventionalcommits'`, no `presetConfig` at all) — not something introduced by this project's own config. `commit-analyzer` is unaffected because it only reads `whatBump` data from the same preset, no template rendering involved. Don't "fix the inconsistency" by switching `release-notes-generator` to `conventionalcommits` too without first checking whether this upstream mismatch has been resolved.
185
186
 
186
187
  ## Fidelity
187
188
 
package/dist/index.cjs CHANGED
@@ -310,6 +310,82 @@ function encodePackage(pkg) {
310
310
  return zod.z.encode(packageCodec, pkg);
311
311
  }
312
312
  //#endregion
313
+ //#region src/typed/util.ts
314
+ function* walk(nodes) {
315
+ for (const node of nodes) {
316
+ yield node;
317
+ if (node.type === "element") yield* walk(node.children);
318
+ }
319
+ }
320
+ function elementsWithTag(nodes, tag) {
321
+ const out = [];
322
+ for (const node of walk(nodes)) if (node.type === "element" && node.tag === tag) out.push(node);
323
+ return out;
324
+ }
325
+ function childrenWithTag(element, tag) {
326
+ const out = [];
327
+ for (const child of element.children) if (child.type === "element" && child.tag === tag) out.push(child);
328
+ return out;
329
+ }
330
+ function attr(element, name) {
331
+ for (const a of element.attributes) if (a.name === name) return a.value;
332
+ }
333
+ function rootElement(part) {
334
+ if (part?.kind !== "xml") return;
335
+ for (const node of part.nodes) if (node.type === "element") return node;
336
+ }
337
+ function decodeEntities(value) {
338
+ return value.replace(/&(?:amp|lt|gt|quot|apos);/g, (entity) => {
339
+ switch (entity) {
340
+ case "&amp;": return "&";
341
+ case "&lt;": return "<";
342
+ case "&gt;": return ">";
343
+ case "&quot;": return "\"";
344
+ case "&apos;": return "'";
345
+ default: return entity;
346
+ }
347
+ });
348
+ }
349
+ function textContent(element) {
350
+ let text = "";
351
+ for (const node of walk(element.children)) if (node.type === "text" || node.type === "cdata") text += node.value;
352
+ return decodeEntities(text);
353
+ }
354
+ function relsPathFor(partPath) {
355
+ const lastSlash = partPath.lastIndexOf("/");
356
+ return `${lastSlash === -1 ? "" : partPath.slice(0, lastSlash)}/_rels/${lastSlash === -1 ? partPath : partPath.slice(lastSlash + 1)}.rels`;
357
+ }
358
+ function resolveRelTarget$1(partPath, target) {
359
+ if (target.startsWith("/")) return target.slice(1);
360
+ const lastSlash = partPath.lastIndexOf("/");
361
+ const baseDir = lastSlash === -1 ? "" : partPath.slice(0, lastSlash);
362
+ const resolved = [];
363
+ for (const segment of `${baseDir}/${target}`.split("/")) {
364
+ if (segment === "" || segment === ".") continue;
365
+ if (segment === "..") resolved.pop();
366
+ else resolved.push(segment);
367
+ }
368
+ return resolved.join("/");
369
+ }
370
+ function resolveRelationships(pkg, partPath) {
371
+ const map = /* @__PURE__ */ new Map();
372
+ const rels = rootElement(pkg.parts[relsPathFor(partPath)]);
373
+ if (rels === void 0) return map;
374
+ for (const rel of childrenWithTag(rels, "Relationship")) {
375
+ const id = attr(rel, "Id");
376
+ const type = attr(rel, "Type");
377
+ const target = attr(rel, "Target");
378
+ if (id === void 0 || type === void 0 || target === void 0) continue;
379
+ const targetMode = attr(rel, "TargetMode");
380
+ map.set(id, {
381
+ type,
382
+ target: targetMode === "External" ? target : resolveRelTarget$1(partPath, target),
383
+ targetMode
384
+ });
385
+ }
386
+ return map;
387
+ }
388
+ //#endregion
313
389
  //#region src/compact.ts
314
390
  function isUnknownArray(value) {
315
391
  return Array.isArray(value);
@@ -458,82 +534,6 @@ function encodeCompactPackage(cpkg) {
458
534
  return zod.z.encode(compactPackageCodec, cpkg);
459
535
  }
460
536
  //#endregion
461
- //#region src/typed/util.ts
462
- function* walk(nodes) {
463
- for (const node of nodes) {
464
- yield node;
465
- if (node.type === "element") yield* walk(node.children);
466
- }
467
- }
468
- function elementsWithTag(nodes, tag) {
469
- const out = [];
470
- for (const node of walk(nodes)) if (node.type === "element" && node.tag === tag) out.push(node);
471
- return out;
472
- }
473
- function childrenWithTag(element, tag) {
474
- const out = [];
475
- for (const child of element.children) if (child.type === "element" && child.tag === tag) out.push(child);
476
- return out;
477
- }
478
- function attr(element, name) {
479
- for (const a of element.attributes) if (a.name === name) return a.value;
480
- }
481
- function rootElement(part) {
482
- if (part?.kind !== "xml") return;
483
- for (const node of part.nodes) if (node.type === "element") return node;
484
- }
485
- function decodeEntities(value) {
486
- return value.replace(/&(?:amp|lt|gt|quot|apos);/g, (entity) => {
487
- switch (entity) {
488
- case "&amp;": return "&";
489
- case "&lt;": return "<";
490
- case "&gt;": return ">";
491
- case "&quot;": return "\"";
492
- case "&apos;": return "'";
493
- default: return entity;
494
- }
495
- });
496
- }
497
- function textContent(element) {
498
- let text = "";
499
- for (const node of walk(element.children)) if (node.type === "text" || node.type === "cdata") text += node.value;
500
- return decodeEntities(text);
501
- }
502
- function relsPathFor(partPath) {
503
- const lastSlash = partPath.lastIndexOf("/");
504
- return `${lastSlash === -1 ? "" : partPath.slice(0, lastSlash)}/_rels/${lastSlash === -1 ? partPath : partPath.slice(lastSlash + 1)}.rels`;
505
- }
506
- function resolveRelTarget$1(partPath, target) {
507
- if (target.startsWith("/")) return target.slice(1);
508
- const lastSlash = partPath.lastIndexOf("/");
509
- const baseDir = lastSlash === -1 ? "" : partPath.slice(0, lastSlash);
510
- const resolved = [];
511
- for (const segment of `${baseDir}/${target}`.split("/")) {
512
- if (segment === "" || segment === ".") continue;
513
- if (segment === "..") resolved.pop();
514
- else resolved.push(segment);
515
- }
516
- return resolved.join("/");
517
- }
518
- function resolveRelationships(pkg, partPath) {
519
- const map = /* @__PURE__ */ new Map();
520
- const rels = rootElement(pkg.parts[relsPathFor(partPath)]);
521
- if (rels === void 0) return map;
522
- for (const rel of childrenWithTag(rels, "Relationship")) {
523
- const id = attr(rel, "Id");
524
- const type = attr(rel, "Type");
525
- const target = attr(rel, "Target");
526
- if (id === void 0 || type === void 0 || target === void 0) continue;
527
- const targetMode = attr(rel, "TargetMode");
528
- map.set(id, {
529
- type,
530
- target: targetMode === "External" ? target : resolveRelTarget$1(partPath, target),
531
- targetMode
532
- });
533
- }
534
- return map;
535
- }
536
- //#endregion
537
537
  //#region src/typed/docx.ts
538
538
  const RunSchema = zod.z.object({
539
539
  text: zod.z.string(),
@@ -919,13 +919,17 @@ exports.XmlNodeSchema = XmlNodeSchema;
919
919
  exports.XmlPartSchema = XmlPartSchema;
920
920
  exports.XmlPiSchema = XmlPiSchema;
921
921
  exports.XmlTextSchema = XmlTextSchema;
922
+ exports.attr = attr;
922
923
  exports.base64ToBytes = base64ToBytes;
923
924
  exports.buildXml = buildXml;
924
925
  exports.bytesToBase64 = bytesToBase64;
926
+ exports.childrenWithTag = childrenWithTag;
925
927
  exports.compactCodec = compactCodec;
926
928
  exports.compactPackageCodec = compactPackageCodec;
927
929
  exports.decodeCompactPackage = decodeCompactPackage;
930
+ exports.decodeEntities = decodeEntities;
928
931
  exports.decodePackage = decodePackage;
932
+ exports.elementsWithTag = elementsWithTag;
929
933
  exports.encodeCompactPackage = encodeCompactPackage;
930
934
  exports.encodePackage = encodePackage;
931
935
  exports.fromCompact = fromCompact;
@@ -937,8 +941,12 @@ exports.parseXml = parseXml;
937
941
  exports.readDocx = readDocx;
938
942
  exports.readPptx = readPptx;
939
943
  exports.readXlsx = readXlsx;
944
+ exports.resolveRelationships = resolveRelationships;
945
+ exports.rootElement = rootElement;
940
946
  exports.serializePackage = serializePackage;
947
+ exports.textContent = textContent;
941
948
  exports.toCompact = toCompact;
942
949
  exports.unzipPackage = unzipPackage;
950
+ exports.walk = walk;
943
951
  exports.xmlCodec = xmlCodec;
944
952
  exports.zipPackage = zipPackage;
package/dist/index.d.cts CHANGED
@@ -279,6 +279,21 @@ declare function zipPackage(parts: Record<string, Uint8Array<ArrayBuffer>>): Uin
279
279
  declare function bytesToBase64(bytes: Uint8Array<ArrayBuffer>): string;
280
280
  declare function base64ToBytes(b64: string): Uint8Array<ArrayBuffer>;
281
281
  //#endregion
282
+ //#region src/typed/util.d.ts
283
+ declare function walk(nodes: XmlNode[]): Generator<XmlNode>;
284
+ declare function elementsWithTag(nodes: XmlNode[], tag: string): XmlElement[];
285
+ declare function childrenWithTag(element: XmlElement, tag: string): XmlElement[];
286
+ declare function attr(element: XmlElement, name: string): string | undefined;
287
+ declare function rootElement(part: Part | undefined): XmlElement | undefined;
288
+ declare function decodeEntities(value: string): string;
289
+ declare function textContent(element: XmlElement): string;
290
+ interface Relationship {
291
+ type: string;
292
+ target: string;
293
+ targetMode?: string;
294
+ }
295
+ declare function resolveRelationships(pkg: Package, partPath: string): Map<string, Relationship>;
296
+ //#endregion
282
297
  //#region src/compact.d.ts
283
298
  type CompactAttrPairs = number[];
284
299
  type CompactElement = [0, number, CompactAttrPairs, CompactXmlNode[]];
@@ -578,4 +593,4 @@ declare const XlsxWorkbookSchema: z.ZodObject<{
578
593
  type XlsxWorkbook = z.infer<typeof XlsxWorkbookSchema>;
579
594
  declare function readXlsx(pkg: Package): XlsxWorkbook;
580
595
  //#endregion
581
- export { type Attribute, AttributeSchema, type BinaryPart, BinaryPartSchema, type Comment, CommentSchema, type CompactAttrPairs, type CompactPackage, CompactPackageSchema, type CompactPart, CompactPartSchema, type CompactXmlNode, CompactXmlNodeSchema, type DefinedName, DefinedNameSchema, type DocxDocument, DocxDocumentSchema, type Footnote, FootnoteSchema, type Hyperlink, HyperlinkSchema, type ListMembership, ListMembershipSchema, type Package, PackageSchema, type Paragraph, ParagraphSchema, type Part, PartSchema, type PptxPresentation, PptxPresentationSchema, type PptxTable, type PptxTableCell, PptxTableCellSchema, type PptxTableRow, PptxTableRowSchema, PptxTableSchema, type Run, RunSchema, type Shape, ShapeSchema, type Slide, SlideSchema, type Table, type TableCell, TableCellSchema, type TableRow, TableRowSchema, TableSchema, type XlsxCell, XlsxCellSchema, type XlsxSheet, XlsxSheetSchema, type XlsxWorkbook, XlsxWorkbookSchema, type XmlCdata, XmlCdataSchema, type XmlComment, XmlCommentSchema, type XmlDeclaration, XmlDeclarationSchema, type XmlElement, XmlElementSchema, type XmlNode, XmlNodeSchema, type XmlPart, XmlPartSchema, type XmlPi, XmlPiSchema, type XmlText, XmlTextSchema, base64ToBytes, buildXml, bytesToBase64, compactCodec, compactPackageCodec, decodeCompactPackage, decodePackage, encodeCompactPackage, encodePackage, fromCompact, isCompactXmlNode, isXmlNode, packageCodec, parsePackage, parseXml, readDocx, readPptx, readXlsx, serializePackage, toCompact, unzipPackage, xmlCodec, zipPackage };
596
+ export { type Attribute, AttributeSchema, type BinaryPart, BinaryPartSchema, type Comment, CommentSchema, type CompactAttrPairs, type CompactPackage, CompactPackageSchema, type CompactPart, CompactPartSchema, type CompactXmlNode, CompactXmlNodeSchema, type DefinedName, DefinedNameSchema, type DocxDocument, DocxDocumentSchema, type Footnote, FootnoteSchema, type Hyperlink, HyperlinkSchema, type ListMembership, ListMembershipSchema, type Package, PackageSchema, type Paragraph, ParagraphSchema, type Part, PartSchema, type PptxPresentation, PptxPresentationSchema, type PptxTable, type PptxTableCell, PptxTableCellSchema, type PptxTableRow, PptxTableRowSchema, PptxTableSchema, type Relationship, type Run, RunSchema, type Shape, ShapeSchema, type Slide, SlideSchema, type Table, type TableCell, TableCellSchema, type TableRow, TableRowSchema, TableSchema, type XlsxCell, XlsxCellSchema, type XlsxSheet, XlsxSheetSchema, type XlsxWorkbook, XlsxWorkbookSchema, type XmlCdata, XmlCdataSchema, type XmlComment, XmlCommentSchema, type XmlDeclaration, XmlDeclarationSchema, type XmlElement, XmlElementSchema, type XmlNode, XmlNodeSchema, type XmlPart, XmlPartSchema, type XmlPi, XmlPiSchema, type XmlText, XmlTextSchema, attr, base64ToBytes, buildXml, bytesToBase64, childrenWithTag, compactCodec, compactPackageCodec, decodeCompactPackage, decodeEntities, decodePackage, elementsWithTag, encodeCompactPackage, encodePackage, fromCompact, isCompactXmlNode, isXmlNode, packageCodec, parsePackage, parseXml, readDocx, readPptx, readXlsx, resolveRelationships, rootElement, serializePackage, textContent, toCompact, unzipPackage, walk, xmlCodec, zipPackage };
package/dist/index.d.ts CHANGED
@@ -279,6 +279,21 @@ declare function zipPackage(parts: Record<string, Uint8Array<ArrayBuffer>>): Uin
279
279
  declare function bytesToBase64(bytes: Uint8Array<ArrayBuffer>): string;
280
280
  declare function base64ToBytes(b64: string): Uint8Array<ArrayBuffer>;
281
281
  //#endregion
282
+ //#region src/typed/util.d.ts
283
+ declare function walk(nodes: XmlNode[]): Generator<XmlNode>;
284
+ declare function elementsWithTag(nodes: XmlNode[], tag: string): XmlElement[];
285
+ declare function childrenWithTag(element: XmlElement, tag: string): XmlElement[];
286
+ declare function attr(element: XmlElement, name: string): string | undefined;
287
+ declare function rootElement(part: Part | undefined): XmlElement | undefined;
288
+ declare function decodeEntities(value: string): string;
289
+ declare function textContent(element: XmlElement): string;
290
+ interface Relationship {
291
+ type: string;
292
+ target: string;
293
+ targetMode?: string;
294
+ }
295
+ declare function resolveRelationships(pkg: Package, partPath: string): Map<string, Relationship>;
296
+ //#endregion
282
297
  //#region src/compact.d.ts
283
298
  type CompactAttrPairs = number[];
284
299
  type CompactElement = [0, number, CompactAttrPairs, CompactXmlNode[]];
@@ -578,4 +593,4 @@ declare const XlsxWorkbookSchema: z.ZodObject<{
578
593
  type XlsxWorkbook = z.infer<typeof XlsxWorkbookSchema>;
579
594
  declare function readXlsx(pkg: Package): XlsxWorkbook;
580
595
  //#endregion
581
- export { type Attribute, AttributeSchema, type BinaryPart, BinaryPartSchema, type Comment, CommentSchema, type CompactAttrPairs, type CompactPackage, CompactPackageSchema, type CompactPart, CompactPartSchema, type CompactXmlNode, CompactXmlNodeSchema, type DefinedName, DefinedNameSchema, type DocxDocument, DocxDocumentSchema, type Footnote, FootnoteSchema, type Hyperlink, HyperlinkSchema, type ListMembership, ListMembershipSchema, type Package, PackageSchema, type Paragraph, ParagraphSchema, type Part, PartSchema, type PptxPresentation, PptxPresentationSchema, type PptxTable, type PptxTableCell, PptxTableCellSchema, type PptxTableRow, PptxTableRowSchema, PptxTableSchema, type Run, RunSchema, type Shape, ShapeSchema, type Slide, SlideSchema, type Table, type TableCell, TableCellSchema, type TableRow, TableRowSchema, TableSchema, type XlsxCell, XlsxCellSchema, type XlsxSheet, XlsxSheetSchema, type XlsxWorkbook, XlsxWorkbookSchema, type XmlCdata, XmlCdataSchema, type XmlComment, XmlCommentSchema, type XmlDeclaration, XmlDeclarationSchema, type XmlElement, XmlElementSchema, type XmlNode, XmlNodeSchema, type XmlPart, XmlPartSchema, type XmlPi, XmlPiSchema, type XmlText, XmlTextSchema, base64ToBytes, buildXml, bytesToBase64, compactCodec, compactPackageCodec, decodeCompactPackage, decodePackage, encodeCompactPackage, encodePackage, fromCompact, isCompactXmlNode, isXmlNode, packageCodec, parsePackage, parseXml, readDocx, readPptx, readXlsx, serializePackage, toCompact, unzipPackage, xmlCodec, zipPackage };
596
+ export { type Attribute, AttributeSchema, type BinaryPart, BinaryPartSchema, type Comment, CommentSchema, type CompactAttrPairs, type CompactPackage, CompactPackageSchema, type CompactPart, CompactPartSchema, type CompactXmlNode, CompactXmlNodeSchema, type DefinedName, DefinedNameSchema, type DocxDocument, DocxDocumentSchema, type Footnote, FootnoteSchema, type Hyperlink, HyperlinkSchema, type ListMembership, ListMembershipSchema, type Package, PackageSchema, type Paragraph, ParagraphSchema, type Part, PartSchema, type PptxPresentation, PptxPresentationSchema, type PptxTable, type PptxTableCell, PptxTableCellSchema, type PptxTableRow, PptxTableRowSchema, PptxTableSchema, type Relationship, type Run, RunSchema, type Shape, ShapeSchema, type Slide, SlideSchema, type Table, type TableCell, TableCellSchema, type TableRow, TableRowSchema, TableSchema, type XlsxCell, XlsxCellSchema, type XlsxSheet, XlsxSheetSchema, type XlsxWorkbook, XlsxWorkbookSchema, type XmlCdata, XmlCdataSchema, type XmlComment, XmlCommentSchema, type XmlDeclaration, XmlDeclarationSchema, type XmlElement, XmlElementSchema, type XmlNode, XmlNodeSchema, type XmlPart, XmlPartSchema, type XmlPi, XmlPiSchema, type XmlText, XmlTextSchema, attr, base64ToBytes, buildXml, bytesToBase64, childrenWithTag, compactCodec, compactPackageCodec, decodeCompactPackage, decodeEntities, decodePackage, elementsWithTag, encodeCompactPackage, encodePackage, fromCompact, isCompactXmlNode, isXmlNode, packageCodec, parsePackage, parseXml, readDocx, readPptx, readXlsx, resolveRelationships, rootElement, serializePackage, textContent, toCompact, unzipPackage, walk, xmlCodec, zipPackage };
package/dist/index.js CHANGED
@@ -309,6 +309,82 @@ function encodePackage(pkg) {
309
309
  return z.encode(packageCodec, pkg);
310
310
  }
311
311
  //#endregion
312
+ //#region src/typed/util.ts
313
+ function* walk(nodes) {
314
+ for (const node of nodes) {
315
+ yield node;
316
+ if (node.type === "element") yield* walk(node.children);
317
+ }
318
+ }
319
+ function elementsWithTag(nodes, tag) {
320
+ const out = [];
321
+ for (const node of walk(nodes)) if (node.type === "element" && node.tag === tag) out.push(node);
322
+ return out;
323
+ }
324
+ function childrenWithTag(element, tag) {
325
+ const out = [];
326
+ for (const child of element.children) if (child.type === "element" && child.tag === tag) out.push(child);
327
+ return out;
328
+ }
329
+ function attr(element, name) {
330
+ for (const a of element.attributes) if (a.name === name) return a.value;
331
+ }
332
+ function rootElement(part) {
333
+ if (part?.kind !== "xml") return;
334
+ for (const node of part.nodes) if (node.type === "element") return node;
335
+ }
336
+ function decodeEntities(value) {
337
+ return value.replace(/&(?:amp|lt|gt|quot|apos);/g, (entity) => {
338
+ switch (entity) {
339
+ case "&amp;": return "&";
340
+ case "&lt;": return "<";
341
+ case "&gt;": return ">";
342
+ case "&quot;": return "\"";
343
+ case "&apos;": return "'";
344
+ default: return entity;
345
+ }
346
+ });
347
+ }
348
+ function textContent(element) {
349
+ let text = "";
350
+ for (const node of walk(element.children)) if (node.type === "text" || node.type === "cdata") text += node.value;
351
+ return decodeEntities(text);
352
+ }
353
+ function relsPathFor(partPath) {
354
+ const lastSlash = partPath.lastIndexOf("/");
355
+ return `${lastSlash === -1 ? "" : partPath.slice(0, lastSlash)}/_rels/${lastSlash === -1 ? partPath : partPath.slice(lastSlash + 1)}.rels`;
356
+ }
357
+ function resolveRelTarget$1(partPath, target) {
358
+ if (target.startsWith("/")) return target.slice(1);
359
+ const lastSlash = partPath.lastIndexOf("/");
360
+ const baseDir = lastSlash === -1 ? "" : partPath.slice(0, lastSlash);
361
+ const resolved = [];
362
+ for (const segment of `${baseDir}/${target}`.split("/")) {
363
+ if (segment === "" || segment === ".") continue;
364
+ if (segment === "..") resolved.pop();
365
+ else resolved.push(segment);
366
+ }
367
+ return resolved.join("/");
368
+ }
369
+ function resolveRelationships(pkg, partPath) {
370
+ const map = /* @__PURE__ */ new Map();
371
+ const rels = rootElement(pkg.parts[relsPathFor(partPath)]);
372
+ if (rels === void 0) return map;
373
+ for (const rel of childrenWithTag(rels, "Relationship")) {
374
+ const id = attr(rel, "Id");
375
+ const type = attr(rel, "Type");
376
+ const target = attr(rel, "Target");
377
+ if (id === void 0 || type === void 0 || target === void 0) continue;
378
+ const targetMode = attr(rel, "TargetMode");
379
+ map.set(id, {
380
+ type,
381
+ target: targetMode === "External" ? target : resolveRelTarget$1(partPath, target),
382
+ targetMode
383
+ });
384
+ }
385
+ return map;
386
+ }
387
+ //#endregion
312
388
  //#region src/compact.ts
313
389
  function isUnknownArray(value) {
314
390
  return Array.isArray(value);
@@ -457,82 +533,6 @@ function encodeCompactPackage(cpkg) {
457
533
  return z.encode(compactPackageCodec, cpkg);
458
534
  }
459
535
  //#endregion
460
- //#region src/typed/util.ts
461
- function* walk(nodes) {
462
- for (const node of nodes) {
463
- yield node;
464
- if (node.type === "element") yield* walk(node.children);
465
- }
466
- }
467
- function elementsWithTag(nodes, tag) {
468
- const out = [];
469
- for (const node of walk(nodes)) if (node.type === "element" && node.tag === tag) out.push(node);
470
- return out;
471
- }
472
- function childrenWithTag(element, tag) {
473
- const out = [];
474
- for (const child of element.children) if (child.type === "element" && child.tag === tag) out.push(child);
475
- return out;
476
- }
477
- function attr(element, name) {
478
- for (const a of element.attributes) if (a.name === name) return a.value;
479
- }
480
- function rootElement(part) {
481
- if (part?.kind !== "xml") return;
482
- for (const node of part.nodes) if (node.type === "element") return node;
483
- }
484
- function decodeEntities(value) {
485
- return value.replace(/&(?:amp|lt|gt|quot|apos);/g, (entity) => {
486
- switch (entity) {
487
- case "&amp;": return "&";
488
- case "&lt;": return "<";
489
- case "&gt;": return ">";
490
- case "&quot;": return "\"";
491
- case "&apos;": return "'";
492
- default: return entity;
493
- }
494
- });
495
- }
496
- function textContent(element) {
497
- let text = "";
498
- for (const node of walk(element.children)) if (node.type === "text" || node.type === "cdata") text += node.value;
499
- return decodeEntities(text);
500
- }
501
- function relsPathFor(partPath) {
502
- const lastSlash = partPath.lastIndexOf("/");
503
- return `${lastSlash === -1 ? "" : partPath.slice(0, lastSlash)}/_rels/${lastSlash === -1 ? partPath : partPath.slice(lastSlash + 1)}.rels`;
504
- }
505
- function resolveRelTarget$1(partPath, target) {
506
- if (target.startsWith("/")) return target.slice(1);
507
- const lastSlash = partPath.lastIndexOf("/");
508
- const baseDir = lastSlash === -1 ? "" : partPath.slice(0, lastSlash);
509
- const resolved = [];
510
- for (const segment of `${baseDir}/${target}`.split("/")) {
511
- if (segment === "" || segment === ".") continue;
512
- if (segment === "..") resolved.pop();
513
- else resolved.push(segment);
514
- }
515
- return resolved.join("/");
516
- }
517
- function resolveRelationships(pkg, partPath) {
518
- const map = /* @__PURE__ */ new Map();
519
- const rels = rootElement(pkg.parts[relsPathFor(partPath)]);
520
- if (rels === void 0) return map;
521
- for (const rel of childrenWithTag(rels, "Relationship")) {
522
- const id = attr(rel, "Id");
523
- const type = attr(rel, "Type");
524
- const target = attr(rel, "Target");
525
- if (id === void 0 || type === void 0 || target === void 0) continue;
526
- const targetMode = attr(rel, "TargetMode");
527
- map.set(id, {
528
- type,
529
- target: targetMode === "External" ? target : resolveRelTarget$1(partPath, target),
530
- targetMode
531
- });
532
- }
533
- return map;
534
- }
535
- //#endregion
536
536
  //#region src/typed/docx.ts
537
537
  const RunSchema = z.object({
538
538
  text: z.string(),
@@ -883,4 +883,4 @@ function readXlsx(pkg) {
883
883
  };
884
884
  }
885
885
  //#endregion
886
- export { AttributeSchema, BinaryPartSchema, CommentSchema, CompactPackageSchema, CompactPartSchema, CompactXmlNodeSchema, DefinedNameSchema, DocxDocumentSchema, FootnoteSchema, HyperlinkSchema, ListMembershipSchema, PackageSchema, ParagraphSchema, PartSchema, PptxPresentationSchema, PptxTableCellSchema, PptxTableRowSchema, PptxTableSchema, RunSchema, ShapeSchema, SlideSchema, TableCellSchema, TableRowSchema, TableSchema, XlsxCellSchema, XlsxSheetSchema, XlsxWorkbookSchema, XmlCdataSchema, XmlCommentSchema, XmlDeclarationSchema, XmlElementSchema, XmlNodeSchema, XmlPartSchema, XmlPiSchema, XmlTextSchema, base64ToBytes, buildXml, bytesToBase64, compactCodec, compactPackageCodec, decodeCompactPackage, decodePackage, encodeCompactPackage, encodePackage, fromCompact, isCompactXmlNode, isXmlNode, packageCodec, parsePackage, parseXml, readDocx, readPptx, readXlsx, serializePackage, toCompact, unzipPackage, xmlCodec, zipPackage };
886
+ export { AttributeSchema, BinaryPartSchema, CommentSchema, CompactPackageSchema, CompactPartSchema, CompactXmlNodeSchema, DefinedNameSchema, DocxDocumentSchema, FootnoteSchema, HyperlinkSchema, ListMembershipSchema, PackageSchema, ParagraphSchema, PartSchema, PptxPresentationSchema, PptxTableCellSchema, PptxTableRowSchema, PptxTableSchema, RunSchema, ShapeSchema, SlideSchema, TableCellSchema, TableRowSchema, TableSchema, XlsxCellSchema, XlsxSheetSchema, XlsxWorkbookSchema, XmlCdataSchema, XmlCommentSchema, XmlDeclarationSchema, XmlElementSchema, XmlNodeSchema, XmlPartSchema, XmlPiSchema, XmlTextSchema, attr, base64ToBytes, buildXml, bytesToBase64, childrenWithTag, compactCodec, compactPackageCodec, decodeCompactPackage, decodeEntities, decodePackage, elementsWithTag, encodeCompactPackage, encodePackage, fromCompact, isCompactXmlNode, isXmlNode, packageCodec, parsePackage, parseXml, readDocx, readPptx, readXlsx, resolveRelationships, rootElement, serializePackage, textContent, toCompact, unzipPackage, walk, xmlCodec, zipPackage };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ooxml.js",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "description": "Type-safe, lossless round-trip conversion between OOXML packages (docx, pptx, xlsx) and JSON, built on Zod 4 codecs.",
5
5
  "type": "module",
6
6
  "repository": {