odf.js 6.3.0 → 6.4.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.
Files changed (128) hide show
  1. package/README.md +172 -18
  2. package/dist/{codec-BnzBd5_I.d.cts → codec-CFdlbFLJ.d.cts} +16 -10
  3. package/dist/{codec-Dg_HWuH1.d.ts → codec-DTAgph2r.d.ts} +16 -10
  4. package/dist/codec.d.cts +1 -1
  5. package/dist/codec.d.ts +1 -1
  6. package/dist/{embedded-BONPxvS3.js → embedded-BnavfkP-.js} +3 -3
  7. package/dist/{embedded-wrtHCJ68.cjs → embedded-Bxyss_ck.cjs} +14 -2
  8. package/dist/index.cjs +34 -1
  9. package/dist/index.d.cts +19 -13
  10. package/dist/index.d.ts +19 -13
  11. package/dist/index.js +12 -6
  12. package/dist/{list-vhXd0Jf6.d.ts → list-7FO0SDqZ.d.ts} +14 -1
  13. package/dist/{list-Bttwr1mk.d.cts → list-BorrTJBY.d.cts} +14 -1
  14. package/dist/{ns-C14w-Zhf.d.cts → ns-DrleaIZQ.d.cts} +3 -1
  15. package/dist/{ns-CTyKJZeF.d.ts → ns-E0TfX9tZ.d.ts} +3 -1
  16. package/dist/ooo1/ns.cjs +9 -0
  17. package/dist/ooo1/ns.d.cts +2 -2
  18. package/dist/ooo1/ns.d.ts +2 -2
  19. package/dist/ooo1/ns.js +8 -1
  20. package/dist/ooo1/properties.cjs +30 -0
  21. package/dist/ooo1/properties.d.cts +6 -2
  22. package/dist/ooo1/properties.d.ts +6 -2
  23. package/dist/ooo1/properties.js +30 -1
  24. package/dist/ooo1/read.cjs +1 -1
  25. package/dist/ooo1/read.d.cts +1 -1
  26. package/dist/ooo1/read.d.ts +1 -1
  27. package/dist/ooo1/read.js +1 -1
  28. package/dist/ooo1/transform.cjs +290 -0
  29. package/dist/ooo1/transform.d.cts +2 -2
  30. package/dist/ooo1/transform.d.ts +2 -2
  31. package/dist/ooo1/transform.js +293 -4
  32. package/dist/ooo1/write.cjs +40 -0
  33. package/dist/ooo1/write.d.cts +2 -0
  34. package/dist/ooo1/write.d.ts +2 -0
  35. package/dist/ooo1/write.js +32 -0
  36. package/dist/package-io/scaffold.cjs +2 -1
  37. package/dist/package-io/scaffold.js +2 -1
  38. package/dist/{paragraph-BdwsQisB.d.cts → paragraph-Bf6Iq5wC.d.cts} +1 -1
  39. package/dist/{paragraph-BoVy1LrN.d.ts → paragraph-DtC86tft.d.ts} +1 -1
  40. package/dist/{path-CK0dIPgx.d.cts → path-8HQS-J7y.d.cts} +3 -1
  41. package/dist/{path-CK0dIPgx.d.ts → path-8HQS-J7y.d.ts} +3 -1
  42. package/dist/{read-Bo1GBjSE.d.ts → read-A3CJkqVM.d.ts} +3 -1
  43. package/dist/{read-RFqq4ckj.d.cts → read-BgnLFuSi.d.cts} +1 -1
  44. package/dist/{read-3yy5EFV_.d.ts → read-CqaZ01kU.d.ts} +1 -1
  45. package/dist/{read-tpfiT_n4.d.cts → read-fphkvCpR.d.cts} +3 -1
  46. package/dist/{shapes-DUzrrf7b.d.ts → shapes-B6Ms7ibr.d.ts} +1 -1
  47. package/dist/{shapes-BQhXAk0D.d.cts → shapes-CbBc9t0y.d.cts} +1 -1
  48. package/dist/{table-ByhqRnSG.d.cts → table-CECMtPxZ.d.cts} +6 -2
  49. package/dist/{table-DElqGcT0.d.ts → table-XuniPr2I.d.ts} +6 -2
  50. package/dist/{transform-SDysw9wx.d.cts → transform-DFCPKX7e.d.cts} +2 -1
  51. package/dist/{transform-DRr76JEu.d.ts → transform-DPliWQuD.d.ts} +2 -1
  52. package/dist/typed/draw/embedded.cjs +1 -1
  53. package/dist/typed/draw/embedded.js +1 -1
  54. package/dist/typed/draw/shapes.cjs +7 -2
  55. package/dist/typed/draw/shapes.d.cts +1 -1
  56. package/dist/typed/draw/shapes.d.ts +1 -1
  57. package/dist/typed/draw/shapes.js +7 -2
  58. package/dist/typed/draw/write-shapes.cjs +210 -0
  59. package/dist/typed/draw/write-shapes.d.cts +2 -0
  60. package/dist/typed/draw/write-shapes.d.ts +2 -0
  61. package/dist/typed/draw/write-shapes.js +203 -0
  62. package/dist/typed/draw/write-vectors.cjs +132 -0
  63. package/dist/typed/draw/write-vectors.d.cts +2 -0
  64. package/dist/typed/draw/write-vectors.d.ts +2 -0
  65. package/dist/typed/draw/write-vectors.js +129 -0
  66. package/dist/typed/odb/form.cjs +1 -1
  67. package/dist/typed/odb/form.js +1 -1
  68. package/dist/typed/odg/write.cjs +80 -0
  69. package/dist/typed/odg/write.d.cts +2 -0
  70. package/dist/typed/odg/write.d.ts +2 -0
  71. package/dist/typed/odg/write.js +77 -0
  72. package/dist/typed/odp/write.cjs +108 -0
  73. package/dist/typed/odp/write.d.cts +2 -0
  74. package/dist/typed/odp/write.d.ts +2 -0
  75. package/dist/typed/odp/write.js +105 -0
  76. package/dist/typed/ods/read.cjs +3 -1
  77. package/dist/typed/ods/read.d.cts +2 -2
  78. package/dist/typed/ods/read.d.ts +2 -2
  79. package/dist/typed/ods/read.js +2 -2
  80. package/dist/typed/ods/write.cjs +578 -0
  81. package/dist/typed/ods/write.d.cts +2 -0
  82. package/dist/typed/ods/write.d.ts +2 -0
  83. package/dist/typed/ods/write.js +575 -0
  84. package/dist/typed/odt/read.cjs +1 -1
  85. package/dist/typed/odt/read.js +1 -1
  86. package/dist/typed/odt/write.cjs +9 -140
  87. package/dist/typed/odt/write.d.cts +1 -1
  88. package/dist/typed/odt/write.d.ts +1 -1
  89. package/dist/typed/odt/write.js +8 -139
  90. package/dist/typed/shared/canonicalise.cjs +126 -0
  91. package/dist/typed/shared/canonicalise.d.cts +10 -0
  92. package/dist/typed/shared/canonicalise.d.ts +10 -0
  93. package/dist/typed/shared/canonicalise.js +120 -0
  94. package/dist/typed/shared/list.cjs +32 -0
  95. package/dist/typed/shared/list.d.cts +2 -2
  96. package/dist/typed/shared/list.d.ts +2 -2
  97. package/dist/typed/shared/list.js +28 -1
  98. package/dist/typed/shared/paragraph.d.cts +1 -1
  99. package/dist/typed/shared/paragraph.d.ts +1 -1
  100. package/dist/typed/shared/path.cjs +19 -0
  101. package/dist/typed/shared/path.d.cts +2 -2
  102. package/dist/typed/shared/path.d.ts +2 -2
  103. package/dist/typed/shared/path.js +18 -1
  104. package/dist/typed/shared/table.cjs +3 -0
  105. package/dist/typed/shared/table.d.cts +2 -2
  106. package/dist/typed/shared/table.d.ts +2 -2
  107. package/dist/typed/shared/table.js +1 -1
  108. package/dist/typed/shared/units.cjs +16 -1
  109. package/dist/typed/shared/units.d.cts +2 -2
  110. package/dist/typed/shared/units.d.ts +2 -2
  111. package/dist/typed/shared/units.js +16 -2
  112. package/dist/{units-BQSNkTQZ.d.ts → units-DdyaQolR.d.cts} +2 -1
  113. package/dist/{units-BQSNkTQZ.d.cts → units-DdyaQolR.d.ts} +2 -1
  114. package/dist/write-4kMi-asu.d.ts +14 -0
  115. package/dist/write-BZXpT8F6.d.cts +17 -0
  116. package/dist/write-BhG3t3fJ.d.cts +14 -0
  117. package/dist/write-BuLQmwLD.d.cts +14 -0
  118. package/dist/write-C2c4xBXs.d.cts +14 -0
  119. package/dist/{write-7Uu_wlkL.d.cts → write-CPATqG4v.d.cts} +1 -0
  120. package/dist/write-CfTE2jY8.d.ts +14 -0
  121. package/dist/write-DttX1rTC.d.ts +14 -0
  122. package/dist/{write-DGcI9W7Z.d.ts → write-JERychL3.d.ts} +1 -0
  123. package/dist/write-SKnCTU4C.d.ts +17 -0
  124. package/dist/write-shapes-Co7BrmMZ.d.ts +36 -0
  125. package/dist/write-shapes-D4piGKf4.d.cts +36 -0
  126. package/dist/write-vectors-B-RVHAKI.d.cts +11 -0
  127. package/dist/write-vectors-CYjZoVBW.d.ts +11 -0
  128. package/package.json +2 -2
@@ -1,2 +1,2 @@
1
- import { a as readSxi, c as readSxwContent, i as readSxdContent, n as readSxcContent, o as readSxiContent, r as readSxd, s as readSxw, t as readSxc } from "../read-3yy5EFV_.js";
1
+ import { a as readSxi, c as readSxwContent, i as readSxdContent, n as readSxcContent, o as readSxiContent, r as readSxd, s as readSxw, t as readSxc } from "../read-CqaZ01kU.js";
2
2
  export { readSxc, readSxcContent, readSxd, readSxdContent, readSxi, readSxiContent, readSxw, readSxwContent };
package/dist/ooo1/read.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { readOdg, readOdgContent } from "../typed/odg/read.js";
2
2
  import { readOdp, readOdpContent } from "../typed/odp/read.js";
3
- import { a as readOdtContent, i as readOdt, o as readOds, s as readOdsContent } from "../embedded-BONPxvS3.js";
3
+ import { a as readOdtContent, c as readOds, i as readOdt, l as readOdsContent } from "../embedded-BnavfkP-.js";
4
4
  import { transformOoo1Package } from "./transform.js";
5
5
  //#region src/ooo1/read.ts
6
6
  function readSxwContent(pkg, options = {}) {
@@ -1,7 +1,9 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_util_base64 = require("../util/base64.cjs");
3
3
  const require_ns = require("../ns.cjs");
4
+ const require_mimetype = require("../mimetype.cjs");
4
5
  const require_xml_query = require("../xml/query.cjs");
6
+ const require_typed_shared_list = require("../typed/shared/list.cjs");
5
7
  const require_ooo1_ns = require("./ns.cjs");
6
8
  const require_ooo1_properties = require("./properties.cjs");
7
9
  //#region src/ooo1/transform.ts
@@ -151,7 +153,10 @@ const INCH_TOKEN = /(^|\s)(-?(?:\d+(?:\.\d+)?|\.\d+))inch(?=\s|$)/g;
151
153
  function carriesNoLength(attributeName) {
152
154
  return attributeName.endsWith("name") || attributeName === "xlink:href";
153
155
  }
156
+ const OOO1_GRAPHIC_STYLE_FAMILY = "graphics";
157
+ const ODF_GRAPHIC_STYLE_FAMILY = "graphic";
154
158
  function normaliseAttributeValue(name, value) {
159
+ if (name === "style:family") return value === OOO1_GRAPHIC_STYLE_FAMILY ? ODF_GRAPHIC_STYLE_FAMILY : value;
155
160
  if (carriesNoLength(name)) return value;
156
161
  return value.replace(INCH_TOKEN, "$1$2in");
157
162
  }
@@ -398,5 +403,290 @@ function transformOoo1Package(pkg) {
398
403
  };
399
404
  return { parts };
400
405
  }
406
+ const CLASS_BY_GENRE_ELEMENT = /* @__PURE__ */ new Map([
407
+ ["office:text", "text"],
408
+ ["office:spreadsheet", "spreadsheet"],
409
+ ["office:presentation", "presentation"],
410
+ ["office:drawing", "drawing"],
411
+ ["office:chart", "chart"]
412
+ ]);
413
+ const REVERSE_RENAMED_ELEMENTS = /* @__PURE__ */ new Map([
414
+ ["office:font-face-decls", "office:font-decls"],
415
+ ["office:scripts", "office:script"],
416
+ ["office:script", "office:script-data"],
417
+ ["office:event-listeners", "office:events"],
418
+ ["style:page-layout", "style:page-master"],
419
+ ["text:tab", "text:tab-stop"],
420
+ ["text:database-row-select", "text:database-select"],
421
+ ["text:index-entry-chapter", "text:index-entry-chapter-number"],
422
+ ["table:dependencies", "table:dependences"],
423
+ ["table:dependency", "table:dependence"]
424
+ ]);
425
+ function reverseNoteTag(tag, noteClass) {
426
+ const isEndnote = noteClass === "endnote";
427
+ if (tag === "text:note") return isEndnote ? "text:endnote" : "text:footnote";
428
+ if (tag === "text:note-ref") return isEndnote ? "text:endnote-ref" : "text:footnote-ref";
429
+ if (tag === "text:notes-configuration") return isEndnote ? "text:endnotes-configuration" : "text:footnotes-configuration";
430
+ }
431
+ function reverseNoteBodyOrCitation(tag, noteClass) {
432
+ const isEndnote = noteClass === "endnote";
433
+ if (tag === "text:note-body") return isEndnote ? "text:endnote-body" : "text:footnote-body";
434
+ if (tag === "text:note-citation") return isEndnote ? "text:endnote-citation" : "text:footnote-citation";
435
+ }
436
+ const PT_IN_TOKEN = /(^|\s)(-?(?:\d+(?:\.\d+)?|\.\d+))in(?=\s|$)/g;
437
+ function reverseAttributeValue(name, value) {
438
+ if (name === "style:family") return value === ODF_GRAPHIC_STYLE_FAMILY ? OOO1_GRAPHIC_STYLE_FAMILY : value;
439
+ if (name === "fo:keep-with-next") {
440
+ if (value === "always") return "true";
441
+ if (value === "auto") return "false";
442
+ return value;
443
+ }
444
+ if (carriesNoLength(name)) return value;
445
+ return value.replace(PT_IN_TOKEN, "$1$2inch");
446
+ }
447
+ function reverseRewriteHref(tag, name, value) {
448
+ if (name === "xlink:href" && PACKAGE_HREF_ELEMENTS.has(tag) && !value.startsWith("#") && !value.includes("://")) return `#${value}`;
449
+ return value;
450
+ }
451
+ function reverseRenamedAttributeName(tag, name) {
452
+ switch (name) {
453
+ case "style:page-layout-name": return "style:page-master-name";
454
+ case "style:leader-text": return "style:leader-char";
455
+ case "text:count-in-text-boxes": return "text:count-in-floating-frames";
456
+ case "form:control-implementation": return "form:service-name";
457
+ case "form:text-style-name": return "form:column-style-name";
458
+ case "office:value-type": return tag === "form:property" ? "form:property-type" : void 0;
459
+ default: return;
460
+ }
461
+ }
462
+ function reverseAttributeNameFor(tag, name) {
463
+ if (tag === "text:h" && name === "text:outline-level") return "text:level";
464
+ if (CELL_ELEMENTS.has(tag)) {
465
+ if (name === "table:content-validation-name") return "table:validation-name";
466
+ for (const local of VALUE_ATTRIBUTE_LOCAL_NAMES) if (name === `office:${local}`) return `table:${local}`;
467
+ }
468
+ if (TEXT_VALUE_ELEMENTS.has(tag)) {
469
+ for (const local of VALUE_ATTRIBUTE_LOCAL_NAMES) if (name === `office:${local}`) return `text:${local}`;
470
+ }
471
+ if (tag === "style:column") {
472
+ if (name === "fo:start-indent") return "fo:margin-left";
473
+ if (name === "fo:end-indent") return "fo:margin-right";
474
+ }
475
+ return reverseRenamedAttributeName(tag, name) ?? name;
476
+ }
477
+ function transformNamespaceDeclarationToOoo1(attribute) {
478
+ const canonical = CANONICAL_PREFIX_BY_URI.get(attribute.value);
479
+ if (canonical === void 0 || !require_ooo1_ns.isOoo1NamespacePrefix(canonical)) return attribute;
480
+ return {
481
+ name: attribute.name === "xmlns" ? "xmlns" : `xmlns:${canonical}`,
482
+ value: require_ooo1_ns.OOO1_NAMESPACES[canonical]
483
+ };
484
+ }
485
+ function reverseTransformAttributes(element, tag, prefixes) {
486
+ const out = [];
487
+ for (const attribute of element.attributes) {
488
+ if (attribute.name === "xmlns" || attribute.name.startsWith("xmlns:")) {
489
+ out.push(transformNamespaceDeclarationToOoo1(attribute));
490
+ continue;
491
+ }
492
+ const name = renameQName(attribute.name, prefixes);
493
+ const value = reverseRewriteHref(tag, name, reverseAttributeValue(name, attribute.value));
494
+ out.push({
495
+ name: reverseAttributeNameFor(tag, name),
496
+ value
497
+ });
498
+ }
499
+ return out;
500
+ }
501
+ function unwrapFrame(frameAttributes, frameChildren) {
502
+ let shape;
503
+ const otherChildren = [];
504
+ for (const child of frameChildren) {
505
+ if (shape === void 0 && child.type === "element" && FRAME_SHAPES.has(child.tag)) {
506
+ shape = child;
507
+ continue;
508
+ }
509
+ otherChildren.push(child);
510
+ }
511
+ if (shape === void 0) return;
512
+ return element(shape.tag, [...shape.attributes, ...frameAttributes], [...shape.children, ...otherChildren]);
513
+ }
514
+ function elementRawText(el) {
515
+ let text = "";
516
+ for (const child of el.children) if (child.type === "text") text += child.value;
517
+ return text;
518
+ }
519
+ function reverseMovedChildren(tag, children) {
520
+ const moved = MOVED_TO_CHILD_ELEMENT.get(tag);
521
+ if (moved === void 0) return;
522
+ const childTagToAttribute = new Map([...moved.entries()].map(([attributeName, childTag]) => [childTag, attributeName]));
523
+ const attributes = [];
524
+ const rest = [];
525
+ for (const child of children) {
526
+ const attributeName = child.type === "element" ? childTagToAttribute.get(child.tag) : void 0;
527
+ if (attributeName !== void 0 && child.type === "element") {
528
+ attributes.push({
529
+ name: attributeName,
530
+ value: elementRawText(child)
531
+ });
532
+ continue;
533
+ }
534
+ rest.push(child);
535
+ }
536
+ return {
537
+ attributes,
538
+ rest
539
+ };
540
+ }
541
+ function wrapMetaKeywords(nodes) {
542
+ const keywords = nodes.filter((node) => node.type === "element" && node.tag === "meta:keyword");
543
+ if (keywords.length === 0) return [...nodes];
544
+ const out = [];
545
+ let inserted = false;
546
+ for (const node of nodes) {
547
+ if (node.type === "element" && node.tag === "meta:keyword") {
548
+ if (!inserted) {
549
+ out.push({
550
+ type: "element",
551
+ tag: "meta:keywords",
552
+ attributes: [],
553
+ children: keywords
554
+ });
555
+ inserted = true;
556
+ }
557
+ continue;
558
+ }
559
+ out.push(node);
560
+ }
561
+ return out;
562
+ }
563
+ function finaliseReversedChildren(nodes) {
564
+ const { merged, rest } = require_ooo1_properties.mergeStyleProperties(nodes);
565
+ return wrapMetaKeywords(merged === void 0 ? rest : [merged, ...rest]);
566
+ }
567
+ function reverseTransformNodes(nodes, context) {
568
+ const out = [];
569
+ for (const node of nodes) {
570
+ if (node.type !== "element") {
571
+ out.push(node);
572
+ continue;
573
+ }
574
+ out.push(...reverseTransformElement(node, context));
575
+ }
576
+ return out;
577
+ }
578
+ function reverseListKind(source, context) {
579
+ return require_typed_shared_list.resolveOdfListKind(context.pkg, require_xml_query.attrValue(source, "text:style-name")) ?? context.listKind;
580
+ }
581
+ function reverseTransformElement(source, context) {
582
+ const renamedTag = renameQName(source.tag, context.prefixes);
583
+ const attributes = reverseTransformAttributes(source, renamedTag, context.prefixes);
584
+ const genreChild = renamedTag === "office:body" ? source.children.find((child) => child.type === "element") : void 0;
585
+ const recurseInto = genreChild !== void 0 && CLASS_BY_GENRE_ELEMENT.has(genreChild.tag) ? genreChild.children : source.children;
586
+ let childContext = context;
587
+ if (renamedTag === "text:note") childContext = {
588
+ ...context,
589
+ noteClass: require_xml_query.attrValue(source, "text:note-class") === "endnote" ? "endnote" : "footnote"
590
+ };
591
+ else if (renamedTag === "text:list") childContext = {
592
+ ...context,
593
+ listKind: reverseListKind(source, context)
594
+ };
595
+ const children = finaliseReversedChildren(reverseTransformNodes(recurseInto, childContext));
596
+ if (renamedTag === "office:body") return [element("office:body", attributes, children)];
597
+ if (renamedTag === "draw:frame") return [unwrapFrame(attributes, children) ?? element(renamedTag, attributes, children)];
598
+ if (renamedTag === "text:note" || renamedTag === "text:note-ref" || renamedTag === "text:notes-configuration") {
599
+ const noteClassRaw = require_xml_query.attrValue(source, "text:note-class");
600
+ const withoutClass = attributes.filter((attribute) => attribute.name !== "text:note-class");
601
+ return [element(reverseNoteTag(renamedTag, noteClassRaw) ?? renamedTag, withoutClass, children)];
602
+ }
603
+ if (renamedTag === "text:note-body" || renamedTag === "text:note-citation") return [element(reverseNoteBodyOrCitation(renamedTag, context.noteClass) ?? renamedTag, attributes, children)];
604
+ if (renamedTag === "table:table" && require_xml_query.attrValue(source, "table:is-sub-table") === "true") return [element("table:sub-table", attributes.filter((attribute) => attribute.name !== "table:is-sub-table"), children)];
605
+ if (renamedTag === "style:font-face") return [element("style:font-decl", attributes.map((attribute) => {
606
+ if (attribute.name === "svg:font-family") return {
607
+ name: "fo:font-family",
608
+ value: attribute.value
609
+ };
610
+ if (attribute.name === "style:font-adornments") return {
611
+ name: "style:font-style-name",
612
+ value: attribute.value
613
+ };
614
+ return attribute;
615
+ }), children)];
616
+ const movedBack = reverseMovedChildren(renamedTag, children);
617
+ if (movedBack !== void 0) return [element(renamedTag, [...attributes, ...movedBack.attributes], movedBack.rest)];
618
+ if (renamedTag === "text:list") {
619
+ const kind = reverseListKind(source, context);
620
+ return [element(kind === "ordered" ? "text:ordered-list" : kind === "bullet" ? "text:unordered-list" : renamedTag, attributes, children)];
621
+ }
622
+ const tag = REVERSE_RENAMED_ELEMENTS.get(renamedTag) ?? renamedTag;
623
+ return [element(tag, DOCUMENT_ROOT_ELEMENTS.has(tag) && context.documentClass !== void 0 ? [...attributes, {
624
+ name: "office:class",
625
+ value: context.documentClass
626
+ }] : attributes, children)];
627
+ }
628
+ const CONTENT_XML_PATH = "content.xml";
629
+ function documentClassOf(pkg) {
630
+ const content = pkg.parts[CONTENT_XML_PATH];
631
+ if (content?.kind !== "xml") return;
632
+ const root = require_xml_query.rootElement(content.nodes);
633
+ const genre = (root === void 0 ? void 0 : require_xml_query.findChildElement(root.children, "office:body"))?.children.find((child) => child.type === "element");
634
+ return genre === void 0 ? void 0 : CLASS_BY_GENRE_ELEMENT.get(genre.tag);
635
+ }
636
+ function reverseTransformXmlPart(nodes, context) {
637
+ const root = require_xml_query.rootElement(nodes);
638
+ if (root === void 0) return [...nodes];
639
+ return reverseTransformNodes(nodes, {
640
+ prefixes: prefixRenames(root),
641
+ ...context
642
+ });
643
+ }
644
+ function rewriteManifestToOoo1(nodes, ooo1MediaType) {
645
+ return nodes.map((node) => {
646
+ if (node.type !== "element") return node;
647
+ return {
648
+ ...node,
649
+ children: node.children.map((entry) => {
650
+ if (entry.type !== "element" || entry.tag !== "manifest:file-entry") return entry;
651
+ if (entry.attributes.find((attribute) => attribute.name === "manifest:full-path")?.value !== "/") return entry;
652
+ return {
653
+ ...entry,
654
+ attributes: entry.attributes.map((attribute) => attribute.name === "manifest:media-type" ? {
655
+ name: attribute.name,
656
+ value: ooo1MediaType
657
+ } : attribute)
658
+ };
659
+ })
660
+ };
661
+ });
662
+ }
663
+ function transformToOoo1Package(pkg) {
664
+ const odfMediaType = require_mimetype.readMimetype(pkg);
665
+ if (odfMediaType === void 0) return pkg;
666
+ const ooo1MediaType = require_ooo1_ns.ooo1MediaTypeForOdfMediaType(odfMediaType);
667
+ if (ooo1MediaType === void 0) return pkg;
668
+ const documentClass = documentClassOf(pkg);
669
+ const parts = {};
670
+ for (const [path, part] of Object.entries(pkg.parts)) {
671
+ if (path === MIMETYPE_PATH) continue;
672
+ if (part.kind !== "xml") {
673
+ parts[path] = part;
674
+ continue;
675
+ }
676
+ const nodes = reverseTransformXmlPart(part.nodes, {
677
+ pkg,
678
+ documentClass
679
+ });
680
+ parts[path] = path === MANIFEST_PATH ? {
681
+ kind: "xml",
682
+ nodes: rewriteManifestToOoo1(nodes, ooo1MediaType)
683
+ } : {
684
+ kind: "xml",
685
+ nodes
686
+ };
687
+ }
688
+ return { parts };
689
+ }
401
690
  //#endregion
402
691
  exports.transformOoo1Package = transformOoo1Package;
692
+ exports.transformToOoo1Package = transformToOoo1Package;
@@ -1,2 +1,2 @@
1
- import { t as transformOoo1Package } from "../transform-SDysw9wx.cjs";
2
- export { transformOoo1Package };
1
+ import { n as transformToOoo1Package, t as transformOoo1Package } from "../transform-DFCPKX7e.cjs";
2
+ export { transformOoo1Package, transformToOoo1Package };
@@ -1,2 +1,2 @@
1
- import { t as transformOoo1Package } from "../transform-DRr76JEu.js";
2
- export { transformOoo1Package };
1
+ import { n as transformToOoo1Package, t as transformOoo1Package } from "../transform-DPliWQuD.js";
2
+ export { transformOoo1Package, transformToOoo1Package };
@@ -1,8 +1,10 @@
1
1
  import { bytesToBase64 } from "../util/base64.js";
2
2
  import { ODF_NAMESPACES } from "../ns.js";
3
- import { rootElement } from "../xml/query.js";
4
- import { OOO1_NAMESPACES, isOoo1Package, odfMediaTypeForOoo1MediaType } from "./ns.js";
5
- import { propertyTypesForContainer, splitStyleProperties } from "./properties.js";
3
+ import { readMimetype } from "../mimetype.js";
4
+ import { attrValue, findChildElement, rootElement } from "../xml/query.js";
5
+ import { resolveOdfListKind } from "../typed/shared/list.js";
6
+ import { OOO1_NAMESPACES, isOoo1NamespacePrefix, isOoo1Package, odfMediaTypeForOoo1MediaType, ooo1MediaTypeForOdfMediaType } from "./ns.js";
7
+ import { mergeStyleProperties, propertyTypesForContainer, splitStyleProperties } from "./properties.js";
6
8
  //#region src/ooo1/transform.ts
7
9
  const CANONICAL_PREFIX_BY_URI = new Map([...Object.entries(OOO1_NAMESPACES).map(([prefix, uri]) => [uri, prefix]), ...Object.entries(ODF_NAMESPACES).map(([prefix, uri]) => [uri, prefix])]);
8
10
  function isOdfNamespacePrefix(prefix) {
@@ -150,7 +152,10 @@ const INCH_TOKEN = /(^|\s)(-?(?:\d+(?:\.\d+)?|\.\d+))inch(?=\s|$)/g;
150
152
  function carriesNoLength(attributeName) {
151
153
  return attributeName.endsWith("name") || attributeName === "xlink:href";
152
154
  }
155
+ const OOO1_GRAPHIC_STYLE_FAMILY = "graphics";
156
+ const ODF_GRAPHIC_STYLE_FAMILY = "graphic";
153
157
  function normaliseAttributeValue(name, value) {
158
+ if (name === "style:family") return value === OOO1_GRAPHIC_STYLE_FAMILY ? ODF_GRAPHIC_STYLE_FAMILY : value;
154
159
  if (carriesNoLength(name)) return value;
155
160
  return value.replace(INCH_TOKEN, "$1$2in");
156
161
  }
@@ -397,5 +402,289 @@ function transformOoo1Package(pkg) {
397
402
  };
398
403
  return { parts };
399
404
  }
405
+ const CLASS_BY_GENRE_ELEMENT = /* @__PURE__ */ new Map([
406
+ ["office:text", "text"],
407
+ ["office:spreadsheet", "spreadsheet"],
408
+ ["office:presentation", "presentation"],
409
+ ["office:drawing", "drawing"],
410
+ ["office:chart", "chart"]
411
+ ]);
412
+ const REVERSE_RENAMED_ELEMENTS = /* @__PURE__ */ new Map([
413
+ ["office:font-face-decls", "office:font-decls"],
414
+ ["office:scripts", "office:script"],
415
+ ["office:script", "office:script-data"],
416
+ ["office:event-listeners", "office:events"],
417
+ ["style:page-layout", "style:page-master"],
418
+ ["text:tab", "text:tab-stop"],
419
+ ["text:database-row-select", "text:database-select"],
420
+ ["text:index-entry-chapter", "text:index-entry-chapter-number"],
421
+ ["table:dependencies", "table:dependences"],
422
+ ["table:dependency", "table:dependence"]
423
+ ]);
424
+ function reverseNoteTag(tag, noteClass) {
425
+ const isEndnote = noteClass === "endnote";
426
+ if (tag === "text:note") return isEndnote ? "text:endnote" : "text:footnote";
427
+ if (tag === "text:note-ref") return isEndnote ? "text:endnote-ref" : "text:footnote-ref";
428
+ if (tag === "text:notes-configuration") return isEndnote ? "text:endnotes-configuration" : "text:footnotes-configuration";
429
+ }
430
+ function reverseNoteBodyOrCitation(tag, noteClass) {
431
+ const isEndnote = noteClass === "endnote";
432
+ if (tag === "text:note-body") return isEndnote ? "text:endnote-body" : "text:footnote-body";
433
+ if (tag === "text:note-citation") return isEndnote ? "text:endnote-citation" : "text:footnote-citation";
434
+ }
435
+ const PT_IN_TOKEN = /(^|\s)(-?(?:\d+(?:\.\d+)?|\.\d+))in(?=\s|$)/g;
436
+ function reverseAttributeValue(name, value) {
437
+ if (name === "style:family") return value === ODF_GRAPHIC_STYLE_FAMILY ? OOO1_GRAPHIC_STYLE_FAMILY : value;
438
+ if (name === "fo:keep-with-next") {
439
+ if (value === "always") return "true";
440
+ if (value === "auto") return "false";
441
+ return value;
442
+ }
443
+ if (carriesNoLength(name)) return value;
444
+ return value.replace(PT_IN_TOKEN, "$1$2inch");
445
+ }
446
+ function reverseRewriteHref(tag, name, value) {
447
+ if (name === "xlink:href" && PACKAGE_HREF_ELEMENTS.has(tag) && !value.startsWith("#") && !value.includes("://")) return `#${value}`;
448
+ return value;
449
+ }
450
+ function reverseRenamedAttributeName(tag, name) {
451
+ switch (name) {
452
+ case "style:page-layout-name": return "style:page-master-name";
453
+ case "style:leader-text": return "style:leader-char";
454
+ case "text:count-in-text-boxes": return "text:count-in-floating-frames";
455
+ case "form:control-implementation": return "form:service-name";
456
+ case "form:text-style-name": return "form:column-style-name";
457
+ case "office:value-type": return tag === "form:property" ? "form:property-type" : void 0;
458
+ default: return;
459
+ }
460
+ }
461
+ function reverseAttributeNameFor(tag, name) {
462
+ if (tag === "text:h" && name === "text:outline-level") return "text:level";
463
+ if (CELL_ELEMENTS.has(tag)) {
464
+ if (name === "table:content-validation-name") return "table:validation-name";
465
+ for (const local of VALUE_ATTRIBUTE_LOCAL_NAMES) if (name === `office:${local}`) return `table:${local}`;
466
+ }
467
+ if (TEXT_VALUE_ELEMENTS.has(tag)) {
468
+ for (const local of VALUE_ATTRIBUTE_LOCAL_NAMES) if (name === `office:${local}`) return `text:${local}`;
469
+ }
470
+ if (tag === "style:column") {
471
+ if (name === "fo:start-indent") return "fo:margin-left";
472
+ if (name === "fo:end-indent") return "fo:margin-right";
473
+ }
474
+ return reverseRenamedAttributeName(tag, name) ?? name;
475
+ }
476
+ function transformNamespaceDeclarationToOoo1(attribute) {
477
+ const canonical = CANONICAL_PREFIX_BY_URI.get(attribute.value);
478
+ if (canonical === void 0 || !isOoo1NamespacePrefix(canonical)) return attribute;
479
+ return {
480
+ name: attribute.name === "xmlns" ? "xmlns" : `xmlns:${canonical}`,
481
+ value: OOO1_NAMESPACES[canonical]
482
+ };
483
+ }
484
+ function reverseTransformAttributes(element, tag, prefixes) {
485
+ const out = [];
486
+ for (const attribute of element.attributes) {
487
+ if (attribute.name === "xmlns" || attribute.name.startsWith("xmlns:")) {
488
+ out.push(transformNamespaceDeclarationToOoo1(attribute));
489
+ continue;
490
+ }
491
+ const name = renameQName(attribute.name, prefixes);
492
+ const value = reverseRewriteHref(tag, name, reverseAttributeValue(name, attribute.value));
493
+ out.push({
494
+ name: reverseAttributeNameFor(tag, name),
495
+ value
496
+ });
497
+ }
498
+ return out;
499
+ }
500
+ function unwrapFrame(frameAttributes, frameChildren) {
501
+ let shape;
502
+ const otherChildren = [];
503
+ for (const child of frameChildren) {
504
+ if (shape === void 0 && child.type === "element" && FRAME_SHAPES.has(child.tag)) {
505
+ shape = child;
506
+ continue;
507
+ }
508
+ otherChildren.push(child);
509
+ }
510
+ if (shape === void 0) return;
511
+ return element(shape.tag, [...shape.attributes, ...frameAttributes], [...shape.children, ...otherChildren]);
512
+ }
513
+ function elementRawText(el) {
514
+ let text = "";
515
+ for (const child of el.children) if (child.type === "text") text += child.value;
516
+ return text;
517
+ }
518
+ function reverseMovedChildren(tag, children) {
519
+ const moved = MOVED_TO_CHILD_ELEMENT.get(tag);
520
+ if (moved === void 0) return;
521
+ const childTagToAttribute = new Map([...moved.entries()].map(([attributeName, childTag]) => [childTag, attributeName]));
522
+ const attributes = [];
523
+ const rest = [];
524
+ for (const child of children) {
525
+ const attributeName = child.type === "element" ? childTagToAttribute.get(child.tag) : void 0;
526
+ if (attributeName !== void 0 && child.type === "element") {
527
+ attributes.push({
528
+ name: attributeName,
529
+ value: elementRawText(child)
530
+ });
531
+ continue;
532
+ }
533
+ rest.push(child);
534
+ }
535
+ return {
536
+ attributes,
537
+ rest
538
+ };
539
+ }
540
+ function wrapMetaKeywords(nodes) {
541
+ const keywords = nodes.filter((node) => node.type === "element" && node.tag === "meta:keyword");
542
+ if (keywords.length === 0) return [...nodes];
543
+ const out = [];
544
+ let inserted = false;
545
+ for (const node of nodes) {
546
+ if (node.type === "element" && node.tag === "meta:keyword") {
547
+ if (!inserted) {
548
+ out.push({
549
+ type: "element",
550
+ tag: "meta:keywords",
551
+ attributes: [],
552
+ children: keywords
553
+ });
554
+ inserted = true;
555
+ }
556
+ continue;
557
+ }
558
+ out.push(node);
559
+ }
560
+ return out;
561
+ }
562
+ function finaliseReversedChildren(nodes) {
563
+ const { merged, rest } = mergeStyleProperties(nodes);
564
+ return wrapMetaKeywords(merged === void 0 ? rest : [merged, ...rest]);
565
+ }
566
+ function reverseTransformNodes(nodes, context) {
567
+ const out = [];
568
+ for (const node of nodes) {
569
+ if (node.type !== "element") {
570
+ out.push(node);
571
+ continue;
572
+ }
573
+ out.push(...reverseTransformElement(node, context));
574
+ }
575
+ return out;
576
+ }
577
+ function reverseListKind(source, context) {
578
+ return resolveOdfListKind(context.pkg, attrValue(source, "text:style-name")) ?? context.listKind;
579
+ }
580
+ function reverseTransformElement(source, context) {
581
+ const renamedTag = renameQName(source.tag, context.prefixes);
582
+ const attributes = reverseTransformAttributes(source, renamedTag, context.prefixes);
583
+ const genreChild = renamedTag === "office:body" ? source.children.find((child) => child.type === "element") : void 0;
584
+ const recurseInto = genreChild !== void 0 && CLASS_BY_GENRE_ELEMENT.has(genreChild.tag) ? genreChild.children : source.children;
585
+ let childContext = context;
586
+ if (renamedTag === "text:note") childContext = {
587
+ ...context,
588
+ noteClass: attrValue(source, "text:note-class") === "endnote" ? "endnote" : "footnote"
589
+ };
590
+ else if (renamedTag === "text:list") childContext = {
591
+ ...context,
592
+ listKind: reverseListKind(source, context)
593
+ };
594
+ const children = finaliseReversedChildren(reverseTransformNodes(recurseInto, childContext));
595
+ if (renamedTag === "office:body") return [element("office:body", attributes, children)];
596
+ if (renamedTag === "draw:frame") return [unwrapFrame(attributes, children) ?? element(renamedTag, attributes, children)];
597
+ if (renamedTag === "text:note" || renamedTag === "text:note-ref" || renamedTag === "text:notes-configuration") {
598
+ const noteClassRaw = attrValue(source, "text:note-class");
599
+ const withoutClass = attributes.filter((attribute) => attribute.name !== "text:note-class");
600
+ return [element(reverseNoteTag(renamedTag, noteClassRaw) ?? renamedTag, withoutClass, children)];
601
+ }
602
+ if (renamedTag === "text:note-body" || renamedTag === "text:note-citation") return [element(reverseNoteBodyOrCitation(renamedTag, context.noteClass) ?? renamedTag, attributes, children)];
603
+ if (renamedTag === "table:table" && attrValue(source, "table:is-sub-table") === "true") return [element("table:sub-table", attributes.filter((attribute) => attribute.name !== "table:is-sub-table"), children)];
604
+ if (renamedTag === "style:font-face") return [element("style:font-decl", attributes.map((attribute) => {
605
+ if (attribute.name === "svg:font-family") return {
606
+ name: "fo:font-family",
607
+ value: attribute.value
608
+ };
609
+ if (attribute.name === "style:font-adornments") return {
610
+ name: "style:font-style-name",
611
+ value: attribute.value
612
+ };
613
+ return attribute;
614
+ }), children)];
615
+ const movedBack = reverseMovedChildren(renamedTag, children);
616
+ if (movedBack !== void 0) return [element(renamedTag, [...attributes, ...movedBack.attributes], movedBack.rest)];
617
+ if (renamedTag === "text:list") {
618
+ const kind = reverseListKind(source, context);
619
+ return [element(kind === "ordered" ? "text:ordered-list" : kind === "bullet" ? "text:unordered-list" : renamedTag, attributes, children)];
620
+ }
621
+ const tag = REVERSE_RENAMED_ELEMENTS.get(renamedTag) ?? renamedTag;
622
+ return [element(tag, DOCUMENT_ROOT_ELEMENTS.has(tag) && context.documentClass !== void 0 ? [...attributes, {
623
+ name: "office:class",
624
+ value: context.documentClass
625
+ }] : attributes, children)];
626
+ }
627
+ const CONTENT_XML_PATH = "content.xml";
628
+ function documentClassOf(pkg) {
629
+ const content = pkg.parts[CONTENT_XML_PATH];
630
+ if (content?.kind !== "xml") return;
631
+ const root = rootElement(content.nodes);
632
+ const genre = (root === void 0 ? void 0 : findChildElement(root.children, "office:body"))?.children.find((child) => child.type === "element");
633
+ return genre === void 0 ? void 0 : CLASS_BY_GENRE_ELEMENT.get(genre.tag);
634
+ }
635
+ function reverseTransformXmlPart(nodes, context) {
636
+ const root = rootElement(nodes);
637
+ if (root === void 0) return [...nodes];
638
+ return reverseTransformNodes(nodes, {
639
+ prefixes: prefixRenames(root),
640
+ ...context
641
+ });
642
+ }
643
+ function rewriteManifestToOoo1(nodes, ooo1MediaType) {
644
+ return nodes.map((node) => {
645
+ if (node.type !== "element") return node;
646
+ return {
647
+ ...node,
648
+ children: node.children.map((entry) => {
649
+ if (entry.type !== "element" || entry.tag !== "manifest:file-entry") return entry;
650
+ if (entry.attributes.find((attribute) => attribute.name === "manifest:full-path")?.value !== "/") return entry;
651
+ return {
652
+ ...entry,
653
+ attributes: entry.attributes.map((attribute) => attribute.name === "manifest:media-type" ? {
654
+ name: attribute.name,
655
+ value: ooo1MediaType
656
+ } : attribute)
657
+ };
658
+ })
659
+ };
660
+ });
661
+ }
662
+ function transformToOoo1Package(pkg) {
663
+ const odfMediaType = readMimetype(pkg);
664
+ if (odfMediaType === void 0) return pkg;
665
+ const ooo1MediaType = ooo1MediaTypeForOdfMediaType(odfMediaType);
666
+ if (ooo1MediaType === void 0) return pkg;
667
+ const documentClass = documentClassOf(pkg);
668
+ const parts = {};
669
+ for (const [path, part] of Object.entries(pkg.parts)) {
670
+ if (path === MIMETYPE_PATH) continue;
671
+ if (part.kind !== "xml") {
672
+ parts[path] = part;
673
+ continue;
674
+ }
675
+ const nodes = reverseTransformXmlPart(part.nodes, {
676
+ pkg,
677
+ documentClass
678
+ });
679
+ parts[path] = path === MANIFEST_PATH ? {
680
+ kind: "xml",
681
+ nodes: rewriteManifestToOoo1(nodes, ooo1MediaType)
682
+ } : {
683
+ kind: "xml",
684
+ nodes
685
+ };
686
+ }
687
+ return { parts };
688
+ }
400
689
  //#endregion
401
- export { transformOoo1Package };
690
+ export { transformOoo1Package, transformToOoo1Package };