ooxml.js 2.4.0 → 2.5.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 (138) hide show
  1. package/README.md +40 -2
  2. package/dist/codec.cjs +28 -0
  3. package/dist/codec.d.cts +72 -0
  4. package/dist/codec.d.ts +72 -0
  5. package/dist/codec.js +24 -0
  6. package/dist/compact.cjs +162 -0
  7. package/dist/compact.d.cts +70 -0
  8. package/dist/compact.d.ts +70 -0
  9. package/dist/compact.js +152 -0
  10. package/dist/image/sniff.cjs +28 -0
  11. package/dist/image/sniff.d.cts +5 -0
  12. package/dist/image/sniff.d.ts +5 -0
  13. package/dist/image/sniff.js +27 -0
  14. package/dist/index.cjs +83 -3025
  15. package/dist/index.d.cts +22 -527
  16. package/dist/index.d.ts +22 -527
  17. package/dist/index.js +22 -2964
  18. package/dist/model/node.cjs +67 -0
  19. package/dist/model/node.d.cts +2 -0
  20. package/dist/model/node.d.ts +2 -0
  21. package/dist/model/node.js +58 -0
  22. package/dist/model/package.cjs +19 -0
  23. package/dist/model/package.d.cts +2 -0
  24. package/dist/model/package.d.ts +2 -0
  25. package/dist/model/package.js +15 -0
  26. package/dist/node-CkBWRjNR.d.cts +83 -0
  27. package/dist/node-CkBWRjNR.d.ts +83 -0
  28. package/dist/package-BUojjTXf.d.ts +114 -0
  29. package/dist/package-L24lkba-.d.cts +114 -0
  30. package/dist/package-io/read.cjs +33 -0
  31. package/dist/package-io/read.d.cts +5 -0
  32. package/dist/package-io/read.d.ts +5 -0
  33. package/dist/package-io/read.js +32 -0
  34. package/dist/package-io/write.cjs +18 -0
  35. package/dist/package-io/write.d.cts +5 -0
  36. package/dist/package-io/write.d.ts +5 -0
  37. package/dist/package-io/write.js +17 -0
  38. package/dist/typed/docx/read.cjs +332 -0
  39. package/dist/typed/docx/read.d.cts +52 -0
  40. package/dist/typed/docx/read.d.ts +52 -0
  41. package/dist/typed/docx/read.js +328 -0
  42. package/dist/typed/docx/styles.cjs +148 -0
  43. package/dist/typed/docx/styles.d.cts +29 -0
  44. package/dist/typed/docx/styles.d.ts +29 -0
  45. package/dist/typed/docx/styles.js +146 -0
  46. package/dist/typed/pptx/inherit.cjs +96 -0
  47. package/dist/typed/pptx/inherit.d.cts +30 -0
  48. package/dist/typed/pptx/inherit.d.ts +30 -0
  49. package/dist/typed/pptx/inherit.js +90 -0
  50. package/dist/typed/pptx/read.cjs +364 -0
  51. package/dist/typed/pptx/read.d.cts +44 -0
  52. package/dist/typed/pptx/read.d.ts +44 -0
  53. package/dist/typed/pptx/read.js +362 -0
  54. package/dist/typed/shared/color.cjs +85 -0
  55. package/dist/typed/shared/color.d.cts +9 -0
  56. package/dist/typed/shared/color.d.ts +9 -0
  57. package/dist/typed/shared/color.js +84 -0
  58. package/dist/typed/shared/drawingml.cjs +191 -0
  59. package/dist/typed/shared/drawingml.d.cts +40 -0
  60. package/dist/typed/shared/drawingml.d.ts +40 -0
  61. package/dist/typed/shared/drawingml.js +180 -0
  62. package/dist/typed/shared/metadata.cjs +44 -0
  63. package/dist/typed/shared/metadata.d.cts +16 -0
  64. package/dist/typed/shared/metadata.d.ts +16 -0
  65. package/dist/typed/shared/metadata.js +42 -0
  66. package/dist/typed/shared/source-path.cjs +18 -0
  67. package/dist/typed/shared/source-path.d.cts +5 -0
  68. package/dist/typed/shared/source-path.d.ts +5 -0
  69. package/dist/typed/shared/source-path.js +17 -0
  70. package/dist/typed/shared/units.cjs +55 -0
  71. package/dist/typed/shared/units.d.cts +20 -0
  72. package/dist/typed/shared/units.d.ts +20 -0
  73. package/dist/typed/shared/units.js +38 -0
  74. package/dist/typed/util.cjs +85 -0
  75. package/dist/typed/util.d.cts +18 -0
  76. package/dist/typed/util.d.ts +18 -0
  77. package/dist/typed/util.js +77 -0
  78. package/dist/typed/xlsx/a1.cjs +64 -0
  79. package/dist/typed/xlsx/a1.d.cts +19 -0
  80. package/dist/typed/xlsx/a1.d.ts +19 -0
  81. package/dist/typed/xlsx/a1.js +58 -0
  82. package/dist/typed/xlsx/build.cjs +456 -0
  83. package/dist/typed/xlsx/build.d.cts +6 -0
  84. package/dist/typed/xlsx/build.d.ts +6 -0
  85. package/dist/typed/xlsx/build.js +455 -0
  86. package/dist/typed/xlsx/content.cjs +257 -0
  87. package/dist/typed/xlsx/content.d.cts +6 -0
  88. package/dist/typed/xlsx/content.d.ts +6 -0
  89. package/dist/typed/xlsx/content.js +256 -0
  90. package/dist/typed/xlsx/defined-names.cjs +90 -0
  91. package/dist/typed/xlsx/defined-names.d.cts +20 -0
  92. package/dist/typed/xlsx/defined-names.d.ts +20 -0
  93. package/dist/typed/xlsx/defined-names.js +83 -0
  94. package/dist/typed/xlsx/print-settings.cjs +116 -0
  95. package/dist/typed/xlsx/print-settings.d.cts +8 -0
  96. package/dist/typed/xlsx/print-settings.d.ts +8 -0
  97. package/dist/typed/xlsx/print-settings.js +114 -0
  98. package/dist/typed/xlsx/shared-strings.cjs +35 -0
  99. package/dist/typed/xlsx/shared-strings.d.cts +12 -0
  100. package/dist/typed/xlsx/shared-strings.d.ts +12 -0
  101. package/dist/typed/xlsx/shared-strings.js +33 -0
  102. package/dist/typed/xlsx/units.cjs +21 -0
  103. package/dist/typed/xlsx/units.d.cts +8 -0
  104. package/dist/typed/xlsx/units.d.ts +8 -0
  105. package/dist/typed/xlsx/units.js +16 -0
  106. package/dist/typed/xlsx/util.cjs +53 -0
  107. package/dist/typed/xlsx/util.d.cts +10 -0
  108. package/dist/typed/xlsx/util.d.ts +10 -0
  109. package/dist/typed/xlsx/util.js +47 -0
  110. package/dist/typed/xlsx.cjs +140 -0
  111. package/dist/typed/xlsx.d.cts +43 -0
  112. package/dist/typed/xlsx.d.ts +43 -0
  113. package/dist/typed/xlsx.js +135 -0
  114. package/dist/util/base64.cjs +48 -0
  115. package/dist/util/base64.d.cts +5 -0
  116. package/dist/util/base64.d.ts +5 -0
  117. package/dist/util/base64.js +46 -0
  118. package/dist/xml/build.cjs +46 -0
  119. package/dist/xml/build.d.cts +5 -0
  120. package/dist/xml/build.d.ts +5 -0
  121. package/dist/xml/build.js +46 -0
  122. package/dist/xml/entities.cjs +7 -0
  123. package/dist/xml/entities.d.cts +4 -0
  124. package/dist/xml/entities.d.ts +4 -0
  125. package/dist/xml/entities.js +6 -0
  126. package/dist/xml/fragment.cjs +22 -0
  127. package/dist/xml/fragment.d.cts +6 -0
  128. package/dist/xml/fragment.d.ts +6 -0
  129. package/dist/xml/fragment.js +20 -0
  130. package/dist/xml/parse.cjs +88 -0
  131. package/dist/xml/parse.d.cts +5 -0
  132. package/dist/xml/parse.d.ts +5 -0
  133. package/dist/xml/parse.js +88 -0
  134. package/dist/zip.cjs +12 -0
  135. package/dist/zip.d.cts +5 -0
  136. package/dist/zip.d.ts +5 -0
  137. package/dist/zip.js +10 -0
  138. package/package.json +9 -1
package/README.md CHANGED
@@ -6,6 +6,35 @@
6
6
 
7
7
  An OOXML file is a ZIP archive of parts (an OPC "package"): `[Content_Types].xml`, relationships (`*.rels`), XML content parts, and binary parts (images, embedded objects). `ooxml.js` decodes the **whole package** into a faithful JSON model and encodes it back — part for part — so `encode(decode(file))` reproduces the original content.
8
8
 
9
+ ```mermaid
10
+ graph TD
11
+ schema("document-schema.js")
12
+ ooxml("ooxml.js")
13
+ odf("odf.js")
14
+ pdfcodec("pdf-codec")
15
+ documents("documents.js")
16
+ cli("document-cli")
17
+
18
+ schema --> ooxml
19
+ schema --> odf
20
+ schema --> pdfcodec
21
+ schema --> documents
22
+ ooxml --> documents
23
+ odf --> documents
24
+ pdfcodec --> documents
25
+ documents --> cli
26
+ odf --> cli
27
+
28
+ click schema "https://github.com/ExaDev/document-schema.js" "document-schema.js"
29
+ click ooxml "https://github.com/ExaDev/ooxml.js" "ooxml.js"
30
+ click odf "https://github.com/ExaDev/odf.js" "odf.js"
31
+ click pdfcodec "https://github.com/ExaDev/pdf-codec" "pdf-codec"
32
+ click documents "https://github.com/ExaDev/documents.js" "documents.js"
33
+ click cli "https://github.com/ExaDev/document-cli" "document-cli"
34
+
35
+ style ooxml fill:#f9a825,stroke:#333,stroke-width:3px
36
+ ```
37
+
9
38
  ## Why
10
39
 
11
40
  Semantic, typed document models are lossy and one-directional: they cannot round-trip. True round-trip requires capturing every part, relationship, and binary byte-for-byte at the content level. `ooxml.js` provides that lossless generic foundation, with ergonomic typed reading views (`Document`, `Presentation`, `Workbook`) layered on top for convenient access.
@@ -69,6 +98,13 @@ const content = readXlsxContent(decodePackage(bytes)); // ContentDocument, kind:
69
98
  const pkg = buildXlsxPackage(content); // a fresh Package built from scratch, not a write-back into `pkg`
70
99
  ```
71
100
 
101
+ Every module under `src/` is also importable directly, by the same path it has relative to `src/`, without going through the barrel — useful for a caller that only needs one small piece and wants to avoid pulling in the rest:
102
+
103
+ ```ts
104
+ import { bytesToBase64, base64ToBytes } from 'ooxml.js/util/base64';
105
+ import { readXlsxContent } from 'ooxml.js/typed/xlsx/content';
106
+ ```
107
+
72
108
  ## The ooxml.js format
73
109
 
74
110
  The verbose `Package` JSON is faithful but repetitive: every node repeats its `type`/`tag`/`attributes`/`children` keys, and tag and namespace strings recur thousands of times across a real document. **The ooxml.js format** is a compact, still-plain-JSON alternative — tuple-encoded nodes plus a single interned string table — that composes on top of `packageCodec` without changing what it guarantees:
@@ -152,7 +188,7 @@ const out = encodeCompactPackage(compact); // CompactPackage -> OOXML bytes dire
152
188
  ## Build, test, and lint
153
189
 
154
190
  ```sh
155
- pnpm build # tsdown -> dist/ (ESM + CJS + .d.ts, via tsdown.config.ts)
191
+ pnpm build # tsdown -> dist/ (one ESM + CJS + .d.ts set per source module, via tsdown.config.ts)
156
192
  pnpm lint # eslint . --max-warnings 0
157
193
  pnpm typecheck # tsc --noEmit
158
194
  pnpm test # vitest run
@@ -162,7 +198,9 @@ pnpm test:smoke # builds dist/, then runs test/smoke.test.mjs to verify the
162
198
 
163
199
  `pnpm prepublishOnly` runs `lint`, `typecheck`, `tsdown`, `publint`, and `@arethetypeswrong/cli` (`attw --pack`) — the full publish-readiness check — before a release.
164
200
 
165
- `test/smoke.test.mjs` loads the actual built `dist/index.js` (ESM) and `dist/index.cjs` (CJS) artifacts and checks they load and behave identically — a check none of `vitest`'s normal run, `tsc`, `publint`, or `attw` can do, since those either run against source or statically analyse package metadata without executing the compiled output. `vitest.config.ts` defines it as its own `smoke` project (vitest's `test.projects`), separate from the `unit` project (`src/**/*.test.ts`); `pnpm test`/`test:watch` pass `--project unit` and `pnpm test:smoke` passes `--project smoke` after `tsdown` rebuilds `dist/`, so neither run touches the other project's files.
201
+ `test/smoke.test.mjs` loads the actual built `dist/index.js` (ESM) and `dist/index.cjs` (CJS) barrel artifacts and checks they load and behave identically — a check none of `vitest`'s normal run, `tsc`, `publint`, or `attw` can do, since those either run against source or statically analyse package metadata without executing the compiled output. `vitest.config.ts` defines it as its own `smoke` project (vitest's `test.projects`), separate from the `unit` project (`src/**/*.test.ts`); `pnpm test`/`test:watch` pass `--project unit` and `pnpm test:smoke` passes `--project smoke` after `tsdown` rebuilds `dist/`, so neither run touches the other project's files.
202
+
203
+ `tsdown.config.ts`'s `entry` is a glob (`src/**/*.ts`, excluding tests and `.d.ts` files) rather than a single `src/index.ts` bundle, so `dist/` holds one ESM/CJS/`.d.ts`/`.d.cts` set per source module, laid out under `dist/` at the same relative path each module has under `src/` (pinned via the sibling `root: 'src'` option). `dist/index.js`/`dist/index.cjs` are just the file `tsdown` produces for `src/index.ts`, matched by that same glob — they still re-export everything the barrel always has. `package.json`'s `exports` map adds a `"./*"` wildcard alongside `"."`, so any module is importable by its own path, not only through the barrel.
166
204
 
167
205
  To run a single test file: `pnpm vitest run src/typed/docx.test.ts`.
168
206
 
package/dist/codec.cjs ADDED
@@ -0,0 +1,28 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_model_node = require("./model/node.cjs");
3
+ const require_model_package = require("./model/package.cjs");
4
+ const require_xml_parse = require("./xml/parse.cjs");
5
+ const require_package_io_read = require("./package-io/read.cjs");
6
+ const require_xml_build = require("./xml/build.cjs");
7
+ const require_package_io_write = require("./package-io/write.cjs");
8
+ let zod = require("zod");
9
+ //#region src/codec.ts
10
+ const xmlCodec = zod.z.codec(zod.z.string(), zod.z.array(require_model_node.XmlNodeSchema), {
11
+ decode: (xml) => require_xml_parse.parseXml(xml),
12
+ encode: (nodes) => require_xml_build.buildXml(nodes)
13
+ });
14
+ const packageCodec = zod.z.codec(zod.z.instanceof(Uint8Array), require_model_package.PackageSchema, {
15
+ decode: (bytes) => require_package_io_read.parsePackage(bytes),
16
+ encode: (pkg) => require_package_io_write.serializePackage(pkg)
17
+ });
18
+ function decodePackage(bytes) {
19
+ return zod.z.decode(packageCodec, bytes);
20
+ }
21
+ function encodePackage(pkg) {
22
+ return zod.z.encode(packageCodec, pkg);
23
+ }
24
+ //#endregion
25
+ exports.decodePackage = decodePackage;
26
+ exports.encodePackage = encodePackage;
27
+ exports.packageCodec = packageCodec;
28
+ exports.xmlCodec = xmlCodec;
@@ -0,0 +1,72 @@
1
+ import { d as XmlNode } from "./node-CkBWRjNR.cjs";
2
+ import { r as Package } from "./package-L24lkba-.cjs";
3
+ import { z } from "zod";
4
+ //#region src/codec.d.ts
5
+ declare const xmlCodec: z.ZodCodec<z.ZodString, z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
6
+ type: z.ZodLiteral<"text">;
7
+ value: z.ZodString;
8
+ }, z.core.$strip>, z.ZodObject<{
9
+ type: z.ZodLiteral<"cdata">;
10
+ value: z.ZodString;
11
+ }, z.core.$strip>, z.ZodObject<{
12
+ type: z.ZodLiteral<"comment">;
13
+ value: z.ZodString;
14
+ }, z.core.$strip>, z.ZodObject<{
15
+ type: z.ZodLiteral<"declaration">;
16
+ attributes: z.ZodArray<z.ZodObject<{
17
+ name: z.ZodString;
18
+ value: z.ZodString;
19
+ }, z.core.$strip>>;
20
+ }, z.core.$strip>, z.ZodObject<{
21
+ type: z.ZodLiteral<"pi">;
22
+ target: z.ZodString;
23
+ content: z.ZodString;
24
+ }, z.core.$strip>, z.ZodObject<{
25
+ type: z.ZodLiteral<"element">;
26
+ tag: z.ZodString;
27
+ attributes: z.ZodArray<z.ZodObject<{
28
+ name: z.ZodString;
29
+ value: z.ZodString;
30
+ }, z.core.$strip>>;
31
+ children: z.ZodArray<z.ZodCustom<XmlNode, XmlNode>>;
32
+ }, z.core.$strip>], "type">>>;
33
+ declare const packageCodec: z.ZodCodec<z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>, z.ZodObject<{
34
+ parts: z.ZodRecord<z.ZodString, z.ZodDiscriminatedUnion<[z.ZodObject<{
35
+ kind: z.ZodLiteral<"xml">;
36
+ nodes: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
37
+ type: z.ZodLiteral<"text">;
38
+ value: z.ZodString;
39
+ }, z.core.$strip>, z.ZodObject<{
40
+ type: z.ZodLiteral<"cdata">;
41
+ value: z.ZodString;
42
+ }, z.core.$strip>, z.ZodObject<{
43
+ type: z.ZodLiteral<"comment">;
44
+ value: z.ZodString;
45
+ }, z.core.$strip>, z.ZodObject<{
46
+ type: z.ZodLiteral<"declaration">;
47
+ attributes: z.ZodArray<z.ZodObject<{
48
+ name: z.ZodString;
49
+ value: z.ZodString;
50
+ }, z.core.$strip>>;
51
+ }, z.core.$strip>, z.ZodObject<{
52
+ type: z.ZodLiteral<"pi">;
53
+ target: z.ZodString;
54
+ content: z.ZodString;
55
+ }, z.core.$strip>, z.ZodObject<{
56
+ type: z.ZodLiteral<"element">;
57
+ tag: z.ZodString;
58
+ attributes: z.ZodArray<z.ZodObject<{
59
+ name: z.ZodString;
60
+ value: z.ZodString;
61
+ }, z.core.$strip>>;
62
+ children: z.ZodArray<z.ZodCustom<XmlNode, XmlNode>>;
63
+ }, z.core.$strip>], "type">>;
64
+ }, z.core.$strip>, z.ZodObject<{
65
+ kind: z.ZodLiteral<"binary">;
66
+ base64: z.ZodString;
67
+ }, z.core.$strip>], "kind">>;
68
+ }, z.core.$strip>>;
69
+ declare function decodePackage(bytes: Uint8Array<ArrayBuffer>): Package;
70
+ declare function encodePackage(pkg: Package): Uint8Array<ArrayBuffer>;
71
+ //#endregion
72
+ export { type XmlNode, decodePackage, encodePackage, packageCodec, xmlCodec };
@@ -0,0 +1,72 @@
1
+ import { d as XmlNode } from "./node-CkBWRjNR.js";
2
+ import { r as Package } from "./package-BUojjTXf.js";
3
+ import { z } from "zod";
4
+ //#region src/codec.d.ts
5
+ declare const xmlCodec: z.ZodCodec<z.ZodString, z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
6
+ type: z.ZodLiteral<"text">;
7
+ value: z.ZodString;
8
+ }, z.core.$strip>, z.ZodObject<{
9
+ type: z.ZodLiteral<"cdata">;
10
+ value: z.ZodString;
11
+ }, z.core.$strip>, z.ZodObject<{
12
+ type: z.ZodLiteral<"comment">;
13
+ value: z.ZodString;
14
+ }, z.core.$strip>, z.ZodObject<{
15
+ type: z.ZodLiteral<"declaration">;
16
+ attributes: z.ZodArray<z.ZodObject<{
17
+ name: z.ZodString;
18
+ value: z.ZodString;
19
+ }, z.core.$strip>>;
20
+ }, z.core.$strip>, z.ZodObject<{
21
+ type: z.ZodLiteral<"pi">;
22
+ target: z.ZodString;
23
+ content: z.ZodString;
24
+ }, z.core.$strip>, z.ZodObject<{
25
+ type: z.ZodLiteral<"element">;
26
+ tag: z.ZodString;
27
+ attributes: z.ZodArray<z.ZodObject<{
28
+ name: z.ZodString;
29
+ value: z.ZodString;
30
+ }, z.core.$strip>>;
31
+ children: z.ZodArray<z.ZodCustom<XmlNode, XmlNode>>;
32
+ }, z.core.$strip>], "type">>>;
33
+ declare const packageCodec: z.ZodCodec<z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>, z.ZodObject<{
34
+ parts: z.ZodRecord<z.ZodString, z.ZodDiscriminatedUnion<[z.ZodObject<{
35
+ kind: z.ZodLiteral<"xml">;
36
+ nodes: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
37
+ type: z.ZodLiteral<"text">;
38
+ value: z.ZodString;
39
+ }, z.core.$strip>, z.ZodObject<{
40
+ type: z.ZodLiteral<"cdata">;
41
+ value: z.ZodString;
42
+ }, z.core.$strip>, z.ZodObject<{
43
+ type: z.ZodLiteral<"comment">;
44
+ value: z.ZodString;
45
+ }, z.core.$strip>, z.ZodObject<{
46
+ type: z.ZodLiteral<"declaration">;
47
+ attributes: z.ZodArray<z.ZodObject<{
48
+ name: z.ZodString;
49
+ value: z.ZodString;
50
+ }, z.core.$strip>>;
51
+ }, z.core.$strip>, z.ZodObject<{
52
+ type: z.ZodLiteral<"pi">;
53
+ target: z.ZodString;
54
+ content: z.ZodString;
55
+ }, z.core.$strip>, z.ZodObject<{
56
+ type: z.ZodLiteral<"element">;
57
+ tag: z.ZodString;
58
+ attributes: z.ZodArray<z.ZodObject<{
59
+ name: z.ZodString;
60
+ value: z.ZodString;
61
+ }, z.core.$strip>>;
62
+ children: z.ZodArray<z.ZodCustom<XmlNode, XmlNode>>;
63
+ }, z.core.$strip>], "type">>;
64
+ }, z.core.$strip>, z.ZodObject<{
65
+ kind: z.ZodLiteral<"binary">;
66
+ base64: z.ZodString;
67
+ }, z.core.$strip>], "kind">>;
68
+ }, z.core.$strip>>;
69
+ declare function decodePackage(bytes: Uint8Array<ArrayBuffer>): Package;
70
+ declare function encodePackage(pkg: Package): Uint8Array<ArrayBuffer>;
71
+ //#endregion
72
+ export { type XmlNode, decodePackage, encodePackage, packageCodec, xmlCodec };
package/dist/codec.js ADDED
@@ -0,0 +1,24 @@
1
+ import { XmlNodeSchema } from "./model/node.js";
2
+ import { PackageSchema } from "./model/package.js";
3
+ import { parseXml } from "./xml/parse.js";
4
+ import { parsePackage } from "./package-io/read.js";
5
+ import { buildXml } from "./xml/build.js";
6
+ import { serializePackage } from "./package-io/write.js";
7
+ import { z } from "zod";
8
+ //#region src/codec.ts
9
+ const xmlCodec = z.codec(z.string(), z.array(XmlNodeSchema), {
10
+ decode: (xml) => parseXml(xml),
11
+ encode: (nodes) => buildXml(nodes)
12
+ });
13
+ const packageCodec = z.codec(z.instanceof(Uint8Array), PackageSchema, {
14
+ decode: (bytes) => parsePackage(bytes),
15
+ encode: (pkg) => serializePackage(pkg)
16
+ });
17
+ function decodePackage(bytes) {
18
+ return z.decode(packageCodec, bytes);
19
+ }
20
+ function encodePackage(pkg) {
21
+ return z.encode(packageCodec, pkg);
22
+ }
23
+ //#endregion
24
+ export { decodePackage, encodePackage, packageCodec, xmlCodec };
@@ -0,0 +1,162 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_model_package = require("./model/package.cjs");
3
+ const require_codec = require("./codec.cjs");
4
+ let zod = require("zod");
5
+ //#region src/compact.ts
6
+ function isUnknownArray(value) {
7
+ return Array.isArray(value);
8
+ }
9
+ function isCompactAttrPairs(value) {
10
+ return isUnknownArray(value) && value.every((v) => typeof v === "number");
11
+ }
12
+ function isCompactXmlNode(value) {
13
+ if (!isUnknownArray(value)) return false;
14
+ const code = value[0];
15
+ if (code === 1 || code === 2 || code === 3) return value.length === 2 && typeof value[1] === "number";
16
+ if (code === 4) return value.length === 2 && isCompactAttrPairs(value[1]);
17
+ if (code === 5) return value.length === 3 && typeof value[1] === "number" && typeof value[2] === "number";
18
+ if (code === 0) return value.length === 4 && typeof value[1] === "number" && isCompactAttrPairs(value[2]) && Array.isArray(value[3]) && value[3].every(isCompactXmlNode);
19
+ return false;
20
+ }
21
+ const CompactXmlNodeSchema = zod.z.custom(isCompactXmlNode);
22
+ const CompactPartSchema = zod.z.union([zod.z.array(CompactXmlNodeSchema), zod.z.number()]);
23
+ const CompactPackageSchema = zod.z.object({
24
+ s: zod.z.array(zod.z.string()),
25
+ p: zod.z.record(zod.z.string(), CompactPartSchema)
26
+ });
27
+ var StringTable = class {
28
+ indices = /* @__PURE__ */ new Map();
29
+ strings = [];
30
+ intern(value) {
31
+ const existing = this.indices.get(value);
32
+ if (existing !== void 0) return existing;
33
+ const index = this.strings.length;
34
+ this.indices.set(value, index);
35
+ this.strings.push(value);
36
+ return index;
37
+ }
38
+ };
39
+ function encodeAttrs(attributes, table) {
40
+ const pairs = [];
41
+ for (const attribute of attributes) pairs.push(table.intern(attribute.name), table.intern(attribute.value));
42
+ return pairs;
43
+ }
44
+ function encodeNode(node, table) {
45
+ switch (node.type) {
46
+ case "text": return [1, table.intern(node.value)];
47
+ case "cdata": return [2, table.intern(node.value)];
48
+ case "comment": return [3, table.intern(node.value)];
49
+ case "declaration": return [4, encodeAttrs(node.attributes, table)];
50
+ case "pi": return [
51
+ 5,
52
+ table.intern(node.target),
53
+ table.intern(node.content)
54
+ ];
55
+ case "element": return [
56
+ 0,
57
+ table.intern(node.tag),
58
+ encodeAttrs(node.attributes, table),
59
+ node.children.map((child) => encodeNode(child, table))
60
+ ];
61
+ }
62
+ }
63
+ function packageToCompact(pkg) {
64
+ const table = new StringTable();
65
+ const p = {};
66
+ for (const [path, part] of Object.entries(pkg.parts)) p[path] = part.kind === "binary" ? table.intern(part.base64) : part.nodes.map((node) => encodeNode(node, table));
67
+ return {
68
+ s: table.strings,
69
+ p
70
+ };
71
+ }
72
+ function stringAt(strings, index) {
73
+ const value = strings[index];
74
+ if (value === void 0) throw new Error(`fromCompact: string table index ${index} is out of range`);
75
+ return value;
76
+ }
77
+ function decodeAttrs(pairs, strings) {
78
+ const attributes = [];
79
+ for (let i = 0; i < pairs.length; i += 2) {
80
+ const nameIdx = pairs[i];
81
+ const valueIdx = pairs[i + 1];
82
+ if (nameIdx === void 0 || valueIdx === void 0) throw new Error("fromCompact: attribute index pairs array has odd length");
83
+ attributes.push({
84
+ name: stringAt(strings, nameIdx),
85
+ value: stringAt(strings, valueIdx)
86
+ });
87
+ }
88
+ return attributes;
89
+ }
90
+ function decodeNode(node, strings) {
91
+ switch (node[0]) {
92
+ case 1: return {
93
+ type: "text",
94
+ value: stringAt(strings, node[1])
95
+ };
96
+ case 2: return {
97
+ type: "cdata",
98
+ value: stringAt(strings, node[1])
99
+ };
100
+ case 3: return {
101
+ type: "comment",
102
+ value: stringAt(strings, node[1])
103
+ };
104
+ case 4: return {
105
+ type: "declaration",
106
+ attributes: decodeAttrs(node[1], strings)
107
+ };
108
+ case 5: return {
109
+ type: "pi",
110
+ target: stringAt(strings, node[1]),
111
+ content: stringAt(strings, node[2])
112
+ };
113
+ case 0: return {
114
+ type: "element",
115
+ tag: stringAt(strings, node[1]),
116
+ attributes: decodeAttrs(node[2], strings),
117
+ children: node[3].map((child) => decodeNode(child, strings))
118
+ };
119
+ }
120
+ }
121
+ function compactToPackage(cpkg) {
122
+ const parts = {};
123
+ for (const [path, part] of Object.entries(cpkg.p)) parts[path] = typeof part === "number" ? {
124
+ kind: "binary",
125
+ base64: stringAt(cpkg.s, part)
126
+ } : {
127
+ kind: "xml",
128
+ nodes: part.map((node) => decodeNode(node, cpkg.s))
129
+ };
130
+ return { parts };
131
+ }
132
+ const compactCodec = zod.z.codec(require_model_package.PackageSchema, CompactPackageSchema, {
133
+ decode: (pkg) => packageToCompact(pkg),
134
+ encode: (cpkg) => compactToPackage(cpkg)
135
+ });
136
+ function toCompact(pkg) {
137
+ return zod.z.decode(compactCodec, pkg);
138
+ }
139
+ function fromCompact(cpkg) {
140
+ return zod.z.encode(compactCodec, cpkg);
141
+ }
142
+ const compactPackageCodec = zod.z.codec(zod.z.instanceof(Uint8Array), CompactPackageSchema, {
143
+ decode: (bytes) => toCompact(require_codec.decodePackage(bytes)),
144
+ encode: (cpkg) => require_codec.encodePackage(fromCompact(cpkg))
145
+ });
146
+ function decodeCompactPackage(bytes) {
147
+ return zod.z.decode(compactPackageCodec, bytes);
148
+ }
149
+ function encodeCompactPackage(cpkg) {
150
+ return zod.z.encode(compactPackageCodec, cpkg);
151
+ }
152
+ //#endregion
153
+ exports.CompactPackageSchema = CompactPackageSchema;
154
+ exports.CompactPartSchema = CompactPartSchema;
155
+ exports.CompactXmlNodeSchema = CompactXmlNodeSchema;
156
+ exports.compactCodec = compactCodec;
157
+ exports.compactPackageCodec = compactPackageCodec;
158
+ exports.decodeCompactPackage = decodeCompactPackage;
159
+ exports.encodeCompactPackage = encodeCompactPackage;
160
+ exports.fromCompact = fromCompact;
161
+ exports.isCompactXmlNode = isCompactXmlNode;
162
+ exports.toCompact = toCompact;
@@ -0,0 +1,70 @@
1
+ import { d as XmlNode } from "./node-CkBWRjNR.cjs";
2
+ import { r as Package } from "./package-L24lkba-.cjs";
3
+ import { z } from "zod";
4
+ //#region src/compact.d.ts
5
+ type CompactAttrPairs = number[];
6
+ type CompactElement = [0, number, CompactAttrPairs, CompactXmlNode[]];
7
+ type CompactText = [1, number];
8
+ type CompactCdata = [2, number];
9
+ type CompactComment = [3, number];
10
+ type CompactDeclaration = [4, CompactAttrPairs];
11
+ type CompactPi = [5, number, number];
12
+ type CompactXmlNode = CompactElement | CompactText | CompactCdata | CompactComment | CompactDeclaration | CompactPi;
13
+ declare function isCompactXmlNode(value: unknown): value is CompactXmlNode;
14
+ declare const CompactXmlNodeSchema: z.ZodCustom<CompactXmlNode, CompactXmlNode>;
15
+ declare const CompactPartSchema: z.ZodUnion<readonly [z.ZodArray<z.ZodCustom<CompactXmlNode, CompactXmlNode>>, z.ZodNumber]>;
16
+ type CompactPart = z.infer<typeof CompactPartSchema>;
17
+ declare const CompactPackageSchema: z.ZodObject<{
18
+ s: z.ZodArray<z.ZodString>;
19
+ p: z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodArray<z.ZodCustom<CompactXmlNode, CompactXmlNode>>, z.ZodNumber]>>;
20
+ }, z.core.$strip>;
21
+ type CompactPackage = z.infer<typeof CompactPackageSchema>;
22
+ declare const compactCodec: z.ZodCodec<z.ZodObject<{
23
+ parts: z.ZodRecord<z.ZodString, z.ZodDiscriminatedUnion<[z.ZodObject<{
24
+ kind: z.ZodLiteral<"xml">;
25
+ nodes: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
26
+ type: z.ZodLiteral<"text">;
27
+ value: z.ZodString;
28
+ }, z.core.$strip>, z.ZodObject<{
29
+ type: z.ZodLiteral<"cdata">;
30
+ value: z.ZodString;
31
+ }, z.core.$strip>, z.ZodObject<{
32
+ type: z.ZodLiteral<"comment">;
33
+ value: z.ZodString;
34
+ }, z.core.$strip>, z.ZodObject<{
35
+ type: z.ZodLiteral<"declaration">;
36
+ attributes: z.ZodArray<z.ZodObject<{
37
+ name: z.ZodString;
38
+ value: z.ZodString;
39
+ }, z.core.$strip>>;
40
+ }, z.core.$strip>, z.ZodObject<{
41
+ type: z.ZodLiteral<"pi">;
42
+ target: z.ZodString;
43
+ content: z.ZodString;
44
+ }, z.core.$strip>, z.ZodObject<{
45
+ type: z.ZodLiteral<"element">;
46
+ tag: z.ZodString;
47
+ attributes: z.ZodArray<z.ZodObject<{
48
+ name: z.ZodString;
49
+ value: z.ZodString;
50
+ }, z.core.$strip>>;
51
+ children: z.ZodArray<z.ZodCustom<XmlNode, XmlNode>>;
52
+ }, z.core.$strip>], "type">>;
53
+ }, z.core.$strip>, z.ZodObject<{
54
+ kind: z.ZodLiteral<"binary">;
55
+ base64: z.ZodString;
56
+ }, z.core.$strip>], "kind">>;
57
+ }, z.core.$strip>, z.ZodObject<{
58
+ s: z.ZodArray<z.ZodString>;
59
+ p: z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodArray<z.ZodCustom<CompactXmlNode, CompactXmlNode>>, z.ZodNumber]>>;
60
+ }, z.core.$strip>>;
61
+ declare function toCompact(pkg: Package): CompactPackage;
62
+ declare function fromCompact(cpkg: CompactPackage): Package;
63
+ declare const compactPackageCodec: z.ZodCodec<z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>, z.ZodObject<{
64
+ s: z.ZodArray<z.ZodString>;
65
+ p: z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodArray<z.ZodCustom<CompactXmlNode, CompactXmlNode>>, z.ZodNumber]>>;
66
+ }, z.core.$strip>>;
67
+ declare function decodeCompactPackage(bytes: Uint8Array<ArrayBuffer>): CompactPackage;
68
+ declare function encodeCompactPackage(cpkg: CompactPackage): Uint8Array<ArrayBuffer>;
69
+ //#endregion
70
+ export { CompactAttrPairs, CompactCdata, CompactComment, CompactDeclaration, CompactElement, CompactPackage, CompactPackageSchema, CompactPart, CompactPartSchema, CompactPi, CompactText, CompactXmlNode, CompactXmlNodeSchema, compactCodec, compactPackageCodec, decodeCompactPackage, encodeCompactPackage, fromCompact, isCompactXmlNode, toCompact };
@@ -0,0 +1,70 @@
1
+ import { d as XmlNode } from "./node-CkBWRjNR.js";
2
+ import { r as Package } from "./package-BUojjTXf.js";
3
+ import { z } from "zod";
4
+ //#region src/compact.d.ts
5
+ type CompactAttrPairs = number[];
6
+ type CompactElement = [0, number, CompactAttrPairs, CompactXmlNode[]];
7
+ type CompactText = [1, number];
8
+ type CompactCdata = [2, number];
9
+ type CompactComment = [3, number];
10
+ type CompactDeclaration = [4, CompactAttrPairs];
11
+ type CompactPi = [5, number, number];
12
+ type CompactXmlNode = CompactElement | CompactText | CompactCdata | CompactComment | CompactDeclaration | CompactPi;
13
+ declare function isCompactXmlNode(value: unknown): value is CompactXmlNode;
14
+ declare const CompactXmlNodeSchema: z.ZodCustom<CompactXmlNode, CompactXmlNode>;
15
+ declare const CompactPartSchema: z.ZodUnion<readonly [z.ZodArray<z.ZodCustom<CompactXmlNode, CompactXmlNode>>, z.ZodNumber]>;
16
+ type CompactPart = z.infer<typeof CompactPartSchema>;
17
+ declare const CompactPackageSchema: z.ZodObject<{
18
+ s: z.ZodArray<z.ZodString>;
19
+ p: z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodArray<z.ZodCustom<CompactXmlNode, CompactXmlNode>>, z.ZodNumber]>>;
20
+ }, z.core.$strip>;
21
+ type CompactPackage = z.infer<typeof CompactPackageSchema>;
22
+ declare const compactCodec: z.ZodCodec<z.ZodObject<{
23
+ parts: z.ZodRecord<z.ZodString, z.ZodDiscriminatedUnion<[z.ZodObject<{
24
+ kind: z.ZodLiteral<"xml">;
25
+ nodes: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
26
+ type: z.ZodLiteral<"text">;
27
+ value: z.ZodString;
28
+ }, z.core.$strip>, z.ZodObject<{
29
+ type: z.ZodLiteral<"cdata">;
30
+ value: z.ZodString;
31
+ }, z.core.$strip>, z.ZodObject<{
32
+ type: z.ZodLiteral<"comment">;
33
+ value: z.ZodString;
34
+ }, z.core.$strip>, z.ZodObject<{
35
+ type: z.ZodLiteral<"declaration">;
36
+ attributes: z.ZodArray<z.ZodObject<{
37
+ name: z.ZodString;
38
+ value: z.ZodString;
39
+ }, z.core.$strip>>;
40
+ }, z.core.$strip>, z.ZodObject<{
41
+ type: z.ZodLiteral<"pi">;
42
+ target: z.ZodString;
43
+ content: z.ZodString;
44
+ }, z.core.$strip>, z.ZodObject<{
45
+ type: z.ZodLiteral<"element">;
46
+ tag: z.ZodString;
47
+ attributes: z.ZodArray<z.ZodObject<{
48
+ name: z.ZodString;
49
+ value: z.ZodString;
50
+ }, z.core.$strip>>;
51
+ children: z.ZodArray<z.ZodCustom<XmlNode, XmlNode>>;
52
+ }, z.core.$strip>], "type">>;
53
+ }, z.core.$strip>, z.ZodObject<{
54
+ kind: z.ZodLiteral<"binary">;
55
+ base64: z.ZodString;
56
+ }, z.core.$strip>], "kind">>;
57
+ }, z.core.$strip>, z.ZodObject<{
58
+ s: z.ZodArray<z.ZodString>;
59
+ p: z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodArray<z.ZodCustom<CompactXmlNode, CompactXmlNode>>, z.ZodNumber]>>;
60
+ }, z.core.$strip>>;
61
+ declare function toCompact(pkg: Package): CompactPackage;
62
+ declare function fromCompact(cpkg: CompactPackage): Package;
63
+ declare const compactPackageCodec: z.ZodCodec<z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>, z.ZodObject<{
64
+ s: z.ZodArray<z.ZodString>;
65
+ p: z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodArray<z.ZodCustom<CompactXmlNode, CompactXmlNode>>, z.ZodNumber]>>;
66
+ }, z.core.$strip>>;
67
+ declare function decodeCompactPackage(bytes: Uint8Array<ArrayBuffer>): CompactPackage;
68
+ declare function encodeCompactPackage(cpkg: CompactPackage): Uint8Array<ArrayBuffer>;
69
+ //#endregion
70
+ export { CompactAttrPairs, CompactCdata, CompactComment, CompactDeclaration, CompactElement, CompactPackage, CompactPackageSchema, CompactPart, CompactPartSchema, CompactPi, CompactText, CompactXmlNode, CompactXmlNodeSchema, compactCodec, compactPackageCodec, decodeCompactPackage, encodeCompactPackage, fromCompact, isCompactXmlNode, toCompact };