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.
Files changed (178) hide show
  1. package/README.md +39 -0
  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/image/sniff.cjs +28 -0
  7. package/dist/image/sniff.d.cts +5 -0
  8. package/dist/image/sniff.d.ts +5 -0
  9. package/dist/image/sniff.js +27 -0
  10. package/dist/index.cjs +156 -3242
  11. package/dist/index.d.cts +42 -679
  12. package/dist/index.d.ts +42 -679
  13. package/dist/index.js +42 -3129
  14. package/dist/manifest.cjs +252 -0
  15. package/dist/manifest.d.cts +41 -0
  16. package/dist/manifest.d.ts +41 -0
  17. package/dist/manifest.js +242 -0
  18. package/dist/media-type.cjs +27 -0
  19. package/dist/media-type.d.cts +20 -0
  20. package/dist/media-type.d.ts +20 -0
  21. package/dist/media-type.js +25 -0
  22. package/dist/mimetype.cjs +19 -0
  23. package/dist/mimetype.d.cts +7 -0
  24. package/dist/mimetype.d.ts +7 -0
  25. package/dist/mimetype.js +16 -0
  26. package/dist/model/node.cjs +67 -0
  27. package/dist/model/node.d.cts +2 -0
  28. package/dist/model/node.d.ts +2 -0
  29. package/dist/model/node.js +58 -0
  30. package/dist/model/package.cjs +19 -0
  31. package/dist/model/package.d.cts +114 -0
  32. package/dist/model/package.d.ts +114 -0
  33. package/dist/model/package.js +15 -0
  34. package/dist/node-CkBWRjNR.d.cts +83 -0
  35. package/dist/node-CkBWRjNR.d.ts +83 -0
  36. package/dist/ns.cjs +37 -0
  37. package/dist/ns.d.cts +32 -0
  38. package/dist/ns.d.ts +32 -0
  39. package/dist/ns.js +35 -0
  40. package/dist/package-io/read.cjs +35 -0
  41. package/dist/package-io/read.d.cts +5 -0
  42. package/dist/package-io/read.d.ts +5 -0
  43. package/dist/package-io/read.js +34 -0
  44. package/dist/package-io/write.cjs +36 -0
  45. package/dist/package-io/write.d.cts +7 -0
  46. package/dist/package-io/write.d.ts +7 -0
  47. package/dist/package-io/write.js +33 -0
  48. package/dist/styles/properties.cjs +286 -0
  49. package/dist/styles/properties.d.cts +45 -0
  50. package/dist/styles/properties.d.ts +45 -0
  51. package/dist/styles/properties.js +277 -0
  52. package/dist/styles/registry.cjs +212 -0
  53. package/dist/styles/registry.d.cts +37 -0
  54. package/dist/styles/registry.d.ts +37 -0
  55. package/dist/styles/registry.js +209 -0
  56. package/dist/styles/serialize.cjs +23 -0
  57. package/dist/styles/serialize.d.cts +7 -0
  58. package/dist/styles/serialize.d.ts +7 -0
  59. package/dist/styles/serialize.js +21 -0
  60. package/dist/styles/span.cjs +114 -0
  61. package/dist/styles/span.d.cts +5 -0
  62. package/dist/styles/span.d.ts +5 -0
  63. package/dist/styles/span.js +113 -0
  64. package/dist/typed/draw/shapes.cjs +314 -0
  65. package/dist/typed/draw/shapes.d.cts +14 -0
  66. package/dist/typed/draw/shapes.d.ts +14 -0
  67. package/dist/typed/draw/shapes.js +311 -0
  68. package/dist/typed/formula/read.cjs +48 -0
  69. package/dist/typed/formula/read.d.cts +12 -0
  70. package/dist/typed/formula/read.d.ts +12 -0
  71. package/dist/typed/formula/read.js +47 -0
  72. package/dist/typed/odb/read.cjs +112 -0
  73. package/dist/typed/odb/read.d.cts +17 -0
  74. package/dist/typed/odb/read.d.ts +17 -0
  75. package/dist/typed/odb/read.js +111 -0
  76. package/dist/typed/odg/read.cjs +30 -0
  77. package/dist/typed/odg/read.d.cts +10 -0
  78. package/dist/typed/odg/read.d.ts +10 -0
  79. package/dist/typed/odg/read.js +29 -0
  80. package/dist/typed/odm/read.cjs +37 -0
  81. package/dist/typed/odm/read.d.cts +15 -0
  82. package/dist/typed/odm/read.d.ts +15 -0
  83. package/dist/typed/odm/read.js +36 -0
  84. package/dist/typed/odp/read.cjs +39 -0
  85. package/dist/typed/odp/read.d.cts +10 -0
  86. package/dist/typed/odp/read.d.ts +10 -0
  87. package/dist/typed/odp/read.js +38 -0
  88. package/dist/typed/ods/read.cjs +318 -0
  89. package/dist/typed/ods/read.d.cts +10 -0
  90. package/dist/typed/ods/read.d.ts +10 -0
  91. package/dist/typed/ods/read.js +317 -0
  92. package/dist/typed/odt/read.cjs +112 -0
  93. package/dist/typed/odt/read.d.cts +10 -0
  94. package/dist/typed/odt/read.d.ts +10 -0
  95. package/dist/typed/odt/read.js +111 -0
  96. package/dist/typed/shared/a1.cjs +68 -0
  97. package/dist/typed/shared/a1.d.cts +18 -0
  98. package/dist/typed/shared/a1.d.ts +18 -0
  99. package/dist/typed/shared/a1.js +63 -0
  100. package/dist/typed/shared/cascade.cjs +102 -0
  101. package/dist/typed/shared/cascade.d.cts +22 -0
  102. package/dist/typed/shared/cascade.d.ts +22 -0
  103. package/dist/typed/shared/cascade.js +99 -0
  104. package/dist/typed/shared/color.cjs +14 -0
  105. package/dist/typed/shared/color.d.cts +6 -0
  106. package/dist/typed/shared/color.d.ts +6 -0
  107. package/dist/typed/shared/color.js +12 -0
  108. package/dist/typed/shared/geometry.cjs +79 -0
  109. package/dist/typed/shared/geometry.d.cts +12 -0
  110. package/dist/typed/shared/geometry.d.ts +12 -0
  111. package/dist/typed/shared/geometry.js +75 -0
  112. package/dist/typed/shared/masterpage.cjs +39 -0
  113. package/dist/typed/shared/masterpage.d.cts +8 -0
  114. package/dist/typed/shared/masterpage.d.ts +8 -0
  115. package/dist/typed/shared/masterpage.js +37 -0
  116. package/dist/typed/shared/metadata.cjs +42 -0
  117. package/dist/typed/shared/metadata.d.cts +7 -0
  118. package/dist/typed/shared/metadata.d.ts +7 -0
  119. package/dist/typed/shared/metadata.js +40 -0
  120. package/dist/typed/shared/paragraph.cjs +57 -0
  121. package/dist/typed/shared/paragraph.d.cts +7 -0
  122. package/dist/typed/shared/paragraph.d.ts +7 -0
  123. package/dist/typed/shared/paragraph.js +56 -0
  124. package/dist/typed/shared/path.cjs +261 -0
  125. package/dist/typed/shared/path.d.cts +34 -0
  126. package/dist/typed/shared/path.d.ts +34 -0
  127. package/dist/typed/shared/path.js +255 -0
  128. package/dist/typed/shared/style.cjs +8 -0
  129. package/dist/typed/shared/style.d.cts +2 -0
  130. package/dist/typed/shared/style.d.ts +2 -0
  131. package/dist/typed/shared/style.js +2 -0
  132. package/dist/typed/shared/table.cjs +84 -0
  133. package/dist/typed/shared/table.d.cts +7 -0
  134. package/dist/typed/shared/table.d.ts +7 -0
  135. package/dist/typed/shared/table.js +83 -0
  136. package/dist/typed/shared/text.cjs +43 -0
  137. package/dist/typed/shared/text.d.cts +8 -0
  138. package/dist/typed/shared/text.d.ts +8 -0
  139. package/dist/typed/shared/text.js +39 -0
  140. package/dist/typed/shared/transform.cjs +112 -0
  141. package/dist/typed/shared/transform.d.cts +26 -0
  142. package/dist/typed/shared/transform.d.ts +26 -0
  143. package/dist/typed/shared/transform.js +107 -0
  144. package/dist/typed/shared/units.cjs +35 -0
  145. package/dist/typed/shared/units.d.cts +2 -0
  146. package/dist/typed/shared/units.d.ts +2 -0
  147. package/dist/typed/shared/units.js +33 -0
  148. package/dist/units-7pCiECuP.d.cts +6 -0
  149. package/dist/units-7pCiECuP.d.ts +6 -0
  150. package/dist/util/base64.cjs +48 -0
  151. package/dist/util/base64.d.cts +5 -0
  152. package/dist/util/base64.d.ts +5 -0
  153. package/dist/util/base64.js +46 -0
  154. package/dist/xml/build.cjs +46 -0
  155. package/dist/xml/build.d.cts +5 -0
  156. package/dist/xml/build.d.ts +5 -0
  157. package/dist/xml/build.js +46 -0
  158. package/dist/xml/entities.cjs +19 -0
  159. package/dist/xml/entities.d.cts +5 -0
  160. package/dist/xml/entities.d.ts +5 -0
  161. package/dist/xml/entities.js +17 -0
  162. package/dist/xml/fragment.cjs +22 -0
  163. package/dist/xml/fragment.d.cts +6 -0
  164. package/dist/xml/fragment.d.ts +6 -0
  165. package/dist/xml/fragment.js +20 -0
  166. package/dist/xml/parse.cjs +88 -0
  167. package/dist/xml/parse.d.cts +5 -0
  168. package/dist/xml/parse.d.ts +5 -0
  169. package/dist/xml/parse.js +88 -0
  170. package/dist/xml/query.cjs +33 -0
  171. package/dist/xml/query.d.cts +9 -0
  172. package/dist/xml/query.d.ts +9 -0
  173. package/dist/xml/query.js +28 -0
  174. package/dist/zip.cjs +15 -0
  175. package/dist/zip.d.cts +9 -0
  176. package/dist/zip.d.ts +9 -0
  177. package/dist/zip.js +13 -0
  178. 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;
@@ -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 };
@@ -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,5 @@
1
+ //#region src/image/sniff.d.ts
2
+ type ImageFormat = 'png' | 'jpeg';
3
+ declare function sniffImageFormat(bytes: Uint8Array<ArrayBuffer>): ImageFormat | undefined;
4
+ //#endregion
5
+ export { ImageFormat, sniffImageFormat };
@@ -0,0 +1,5 @@
1
+ //#region src/image/sniff.d.ts
2
+ type ImageFormat = 'png' | 'jpeg';
3
+ declare function sniffImageFormat(bytes: Uint8Array<ArrayBuffer>): ImageFormat | undefined;
4
+ //#endregion
5
+ export { ImageFormat, 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 };