odf.js 1.12.0 → 1.13.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 +39 -0
- package/dist/codec.cjs +28 -0
- package/dist/codec.d.cts +72 -0
- package/dist/codec.d.ts +72 -0
- package/dist/codec.js +24 -0
- package/dist/image/sniff.cjs +28 -0
- package/dist/image/sniff.d.cts +5 -0
- package/dist/image/sniff.d.ts +5 -0
- package/dist/image/sniff.js +27 -0
- package/dist/index.cjs +156 -3242
- package/dist/index.d.cts +42 -679
- package/dist/index.d.ts +42 -679
- package/dist/index.js +42 -3129
- package/dist/manifest.cjs +252 -0
- package/dist/manifest.d.cts +41 -0
- package/dist/manifest.d.ts +41 -0
- package/dist/manifest.js +242 -0
- package/dist/media-type.cjs +27 -0
- package/dist/media-type.d.cts +20 -0
- package/dist/media-type.d.ts +20 -0
- package/dist/media-type.js +25 -0
- package/dist/mimetype.cjs +19 -0
- package/dist/mimetype.d.cts +7 -0
- package/dist/mimetype.d.ts +7 -0
- package/dist/mimetype.js +16 -0
- package/dist/model/node.cjs +67 -0
- package/dist/model/node.d.cts +2 -0
- package/dist/model/node.d.ts +2 -0
- package/dist/model/node.js +58 -0
- package/dist/model/package.cjs +19 -0
- package/dist/model/package.d.cts +114 -0
- package/dist/model/package.d.ts +114 -0
- package/dist/model/package.js +15 -0
- package/dist/node-CkBWRjNR.d.cts +83 -0
- package/dist/node-CkBWRjNR.d.ts +83 -0
- package/dist/ns.cjs +37 -0
- package/dist/ns.d.cts +32 -0
- package/dist/ns.d.ts +32 -0
- package/dist/ns.js +35 -0
- package/dist/package-io/read.cjs +35 -0
- package/dist/package-io/read.d.cts +5 -0
- package/dist/package-io/read.d.ts +5 -0
- package/dist/package-io/read.js +34 -0
- package/dist/package-io/write.cjs +36 -0
- package/dist/package-io/write.d.cts +7 -0
- package/dist/package-io/write.d.ts +7 -0
- package/dist/package-io/write.js +33 -0
- package/dist/styles/properties.cjs +286 -0
- package/dist/styles/properties.d.cts +45 -0
- package/dist/styles/properties.d.ts +45 -0
- package/dist/styles/properties.js +277 -0
- package/dist/styles/registry.cjs +212 -0
- package/dist/styles/registry.d.cts +37 -0
- package/dist/styles/registry.d.ts +37 -0
- package/dist/styles/registry.js +209 -0
- package/dist/styles/serialize.cjs +23 -0
- package/dist/styles/serialize.d.cts +7 -0
- package/dist/styles/serialize.d.ts +7 -0
- package/dist/styles/serialize.js +21 -0
- package/dist/styles/span.cjs +114 -0
- package/dist/styles/span.d.cts +5 -0
- package/dist/styles/span.d.ts +5 -0
- package/dist/styles/span.js +113 -0
- package/dist/typed/draw/shapes.cjs +314 -0
- package/dist/typed/draw/shapes.d.cts +14 -0
- package/dist/typed/draw/shapes.d.ts +14 -0
- package/dist/typed/draw/shapes.js +311 -0
- package/dist/typed/formula/read.cjs +48 -0
- package/dist/typed/formula/read.d.cts +12 -0
- package/dist/typed/formula/read.d.ts +12 -0
- package/dist/typed/formula/read.js +47 -0
- package/dist/typed/odb/read.cjs +112 -0
- package/dist/typed/odb/read.d.cts +17 -0
- package/dist/typed/odb/read.d.ts +17 -0
- package/dist/typed/odb/read.js +111 -0
- package/dist/typed/odg/read.cjs +30 -0
- package/dist/typed/odg/read.d.cts +10 -0
- package/dist/typed/odg/read.d.ts +10 -0
- package/dist/typed/odg/read.js +29 -0
- package/dist/typed/odm/read.cjs +37 -0
- package/dist/typed/odm/read.d.cts +15 -0
- package/dist/typed/odm/read.d.ts +15 -0
- package/dist/typed/odm/read.js +36 -0
- package/dist/typed/odp/read.cjs +39 -0
- package/dist/typed/odp/read.d.cts +10 -0
- package/dist/typed/odp/read.d.ts +10 -0
- package/dist/typed/odp/read.js +38 -0
- package/dist/typed/ods/read.cjs +318 -0
- package/dist/typed/ods/read.d.cts +10 -0
- package/dist/typed/ods/read.d.ts +10 -0
- package/dist/typed/ods/read.js +317 -0
- package/dist/typed/odt/read.cjs +112 -0
- package/dist/typed/odt/read.d.cts +10 -0
- package/dist/typed/odt/read.d.ts +10 -0
- package/dist/typed/odt/read.js +111 -0
- package/dist/typed/shared/a1.cjs +68 -0
- package/dist/typed/shared/a1.d.cts +18 -0
- package/dist/typed/shared/a1.d.ts +18 -0
- package/dist/typed/shared/a1.js +63 -0
- package/dist/typed/shared/cascade.cjs +102 -0
- package/dist/typed/shared/cascade.d.cts +22 -0
- package/dist/typed/shared/cascade.d.ts +22 -0
- package/dist/typed/shared/cascade.js +99 -0
- package/dist/typed/shared/color.cjs +14 -0
- package/dist/typed/shared/color.d.cts +6 -0
- package/dist/typed/shared/color.d.ts +6 -0
- package/dist/typed/shared/color.js +12 -0
- package/dist/typed/shared/geometry.cjs +79 -0
- package/dist/typed/shared/geometry.d.cts +12 -0
- package/dist/typed/shared/geometry.d.ts +12 -0
- package/dist/typed/shared/geometry.js +75 -0
- package/dist/typed/shared/masterpage.cjs +39 -0
- package/dist/typed/shared/masterpage.d.cts +8 -0
- package/dist/typed/shared/masterpage.d.ts +8 -0
- package/dist/typed/shared/masterpage.js +37 -0
- package/dist/typed/shared/metadata.cjs +42 -0
- package/dist/typed/shared/metadata.d.cts +7 -0
- package/dist/typed/shared/metadata.d.ts +7 -0
- package/dist/typed/shared/metadata.js +40 -0
- package/dist/typed/shared/paragraph.cjs +57 -0
- package/dist/typed/shared/paragraph.d.cts +7 -0
- package/dist/typed/shared/paragraph.d.ts +7 -0
- package/dist/typed/shared/paragraph.js +56 -0
- package/dist/typed/shared/path.cjs +261 -0
- package/dist/typed/shared/path.d.cts +34 -0
- package/dist/typed/shared/path.d.ts +34 -0
- package/dist/typed/shared/path.js +255 -0
- package/dist/typed/shared/style.cjs +8 -0
- package/dist/typed/shared/style.d.cts +2 -0
- package/dist/typed/shared/style.d.ts +2 -0
- package/dist/typed/shared/style.js +2 -0
- package/dist/typed/shared/table.cjs +84 -0
- package/dist/typed/shared/table.d.cts +7 -0
- package/dist/typed/shared/table.d.ts +7 -0
- package/dist/typed/shared/table.js +83 -0
- package/dist/typed/shared/text.cjs +43 -0
- package/dist/typed/shared/text.d.cts +8 -0
- package/dist/typed/shared/text.d.ts +8 -0
- package/dist/typed/shared/text.js +39 -0
- package/dist/typed/shared/transform.cjs +112 -0
- package/dist/typed/shared/transform.d.cts +26 -0
- package/dist/typed/shared/transform.d.ts +26 -0
- package/dist/typed/shared/transform.js +107 -0
- package/dist/typed/shared/units.cjs +35 -0
- package/dist/typed/shared/units.d.cts +2 -0
- package/dist/typed/shared/units.d.ts +2 -0
- package/dist/typed/shared/units.js +33 -0
- package/dist/units-7pCiECuP.d.cts +6 -0
- package/dist/units-7pCiECuP.d.ts +6 -0
- package/dist/util/base64.cjs +48 -0
- package/dist/util/base64.d.cts +5 -0
- package/dist/util/base64.d.ts +5 -0
- package/dist/util/base64.js +46 -0
- package/dist/xml/build.cjs +46 -0
- package/dist/xml/build.d.cts +5 -0
- package/dist/xml/build.d.ts +5 -0
- package/dist/xml/build.js +46 -0
- package/dist/xml/entities.cjs +19 -0
- package/dist/xml/entities.d.cts +5 -0
- package/dist/xml/entities.d.ts +5 -0
- package/dist/xml/entities.js +17 -0
- package/dist/xml/fragment.cjs +22 -0
- package/dist/xml/fragment.d.cts +6 -0
- package/dist/xml/fragment.d.ts +6 -0
- package/dist/xml/fragment.js +20 -0
- package/dist/xml/parse.cjs +88 -0
- package/dist/xml/parse.d.cts +5 -0
- package/dist/xml/parse.d.ts +5 -0
- package/dist/xml/parse.js +88 -0
- package/dist/xml/query.cjs +33 -0
- package/dist/xml/query.d.cts +9 -0
- package/dist/xml/query.d.ts +9 -0
- package/dist/xml/query.js +28 -0
- package/dist/zip.cjs +15 -0
- package/dist/zip.d.cts +9 -0
- package/dist/zip.d.ts +9 -0
- package/dist/zip.js +13 -0
- package/package.json +9 -1
package/README.md
CHANGED
|
@@ -10,6 +10,35 @@
|
|
|
10
10
|
|
|
11
11
|
Both packages **do** depend on [`document-schema.js`](https://github.com/ExaDev/document-schema.js), the genuinely shared canonical schema for `ContentDocument`/`LayoutDocument` — the semantic content model (paragraphs, runs, tables, shapes, slides) both an ODF and an OOXML reader ultimately produce. `odf.js`'s typed readers return the real, imported `ContentSection`/`ContentSlide`/etc. types from that package, not a structurally-similar lookalike, so a downstream consumer (`documents.js`) can run an `.odt` through the exact same layout/pagination engine it already uses for `.docx`, unmodified.
|
|
12
12
|
|
|
13
|
+
```mermaid
|
|
14
|
+
graph TD
|
|
15
|
+
schema("document-schema.js")
|
|
16
|
+
ooxml("ooxml.js")
|
|
17
|
+
odf("odf.js")
|
|
18
|
+
pdfcodec("pdf-codec")
|
|
19
|
+
documents("documents.js")
|
|
20
|
+
cli("document-cli")
|
|
21
|
+
|
|
22
|
+
schema --> ooxml
|
|
23
|
+
schema --> odf
|
|
24
|
+
schema --> pdfcodec
|
|
25
|
+
schema --> documents
|
|
26
|
+
ooxml --> documents
|
|
27
|
+
odf --> documents
|
|
28
|
+
pdfcodec --> documents
|
|
29
|
+
documents --> cli
|
|
30
|
+
odf --> cli
|
|
31
|
+
|
|
32
|
+
click schema "https://github.com/ExaDev/document-schema.js" "document-schema.js"
|
|
33
|
+
click ooxml "https://github.com/ExaDev/ooxml.js" "ooxml.js"
|
|
34
|
+
click odf "https://github.com/ExaDev/odf.js" "odf.js"
|
|
35
|
+
click pdfcodec "https://github.com/ExaDev/pdf-codec" "pdf-codec"
|
|
36
|
+
click documents "https://github.com/ExaDev/documents.js" "documents.js"
|
|
37
|
+
click cli "https://github.com/ExaDev/document-cli" "document-cli"
|
|
38
|
+
|
|
39
|
+
style odf fill:#f9a825,stroke:#333,stroke-width:3px
|
|
40
|
+
```
|
|
41
|
+
|
|
13
42
|
## Status
|
|
14
43
|
|
|
15
44
|
This package is under active development. What's built and shipped:
|
|
@@ -68,6 +97,16 @@ syncManifest(pkg); // rebuilds manifest.xml to exactly match pkg's current parts
|
|
|
68
97
|
readMimetype(pkg); // 'application/vnd.oasis.opendocument.text'
|
|
69
98
|
```
|
|
70
99
|
|
|
100
|
+
Every module is also importable directly by its own subpath, without going through the barrel — useful for a caller that wants one narrow piece of the package (e.g. a bundler doing tree-shaking, or a script that only needs the length-unit parser) without pulling in the rest:
|
|
101
|
+
|
|
102
|
+
```ts
|
|
103
|
+
import { parseOdfLength } from 'odf.js/typed/shared/units';
|
|
104
|
+
|
|
105
|
+
parseOdfLength('2.5cm'); // 70.86614173228347
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
Any `src/**/*.ts` module (excluding tests and internal `test-support/` fixtures) resolves this way, at its path relative to `src/` — `src/manifest.ts` as `odf.js/manifest`, `src/typed/odt/read.ts` as `odf.js/typed/odt/read`, and so on.
|
|
109
|
+
|
|
71
110
|
## Architecture
|
|
72
111
|
|
|
73
112
|
Layered from a lossless core outward, mirroring `ooxml.js`'s own structure:
|
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;
|
package/dist/codec.d.cts
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { d as XmlNode } from "./node-CkBWRjNR.cjs";
|
|
2
|
+
import { Package } from "./model/package.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 };
|
package/dist/codec.d.ts
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { d as XmlNode } from "./node-CkBWRjNR.js";
|
|
2
|
+
import { Package } from "./model/package.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,28 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region src/image/sniff.ts
|
|
3
|
+
const PNG_SIGNATURE = [
|
|
4
|
+
137,
|
|
5
|
+
80,
|
|
6
|
+
78,
|
|
7
|
+
71,
|
|
8
|
+
13,
|
|
9
|
+
10,
|
|
10
|
+
26,
|
|
11
|
+
10
|
|
12
|
+
];
|
|
13
|
+
const JPEG_SIGNATURE = [
|
|
14
|
+
255,
|
|
15
|
+
216,
|
|
16
|
+
255
|
|
17
|
+
];
|
|
18
|
+
function startsWith(bytes, signature) {
|
|
19
|
+
if (bytes.length < signature.length) return false;
|
|
20
|
+
for (let i = 0; i < signature.length; i++) if (bytes[i] !== signature[i]) return false;
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
function sniffImageFormat(bytes) {
|
|
24
|
+
if (startsWith(bytes, PNG_SIGNATURE)) return "png";
|
|
25
|
+
if (startsWith(bytes, JPEG_SIGNATURE)) return "jpeg";
|
|
26
|
+
}
|
|
27
|
+
//#endregion
|
|
28
|
+
exports.sniffImageFormat = sniffImageFormat;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
//#region src/image/sniff.ts
|
|
2
|
+
const PNG_SIGNATURE = [
|
|
3
|
+
137,
|
|
4
|
+
80,
|
|
5
|
+
78,
|
|
6
|
+
71,
|
|
7
|
+
13,
|
|
8
|
+
10,
|
|
9
|
+
26,
|
|
10
|
+
10
|
|
11
|
+
];
|
|
12
|
+
const JPEG_SIGNATURE = [
|
|
13
|
+
255,
|
|
14
|
+
216,
|
|
15
|
+
255
|
|
16
|
+
];
|
|
17
|
+
function startsWith(bytes, signature) {
|
|
18
|
+
if (bytes.length < signature.length) return false;
|
|
19
|
+
for (let i = 0; i < signature.length; i++) if (bytes[i] !== signature[i]) return false;
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
function sniffImageFormat(bytes) {
|
|
23
|
+
if (startsWith(bytes, PNG_SIGNATURE)) return "png";
|
|
24
|
+
if (startsWith(bytes, JPEG_SIGNATURE)) return "jpeg";
|
|
25
|
+
}
|
|
26
|
+
//#endregion
|
|
27
|
+
export { sniffImageFormat };
|