odf.js 6.4.0 → 6.4.1

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.
@@ -15,14 +15,40 @@ const JPEG_SIGNATURE = [
15
15
  216,
16
16
  255
17
17
  ];
18
+ const GIF87A_SIGNATURE = [
19
+ 71,
20
+ 73,
21
+ 70,
22
+ 56,
23
+ 55,
24
+ 97
25
+ ];
26
+ const GIF89A_SIGNATURE = [
27
+ 71,
28
+ 73,
29
+ 70,
30
+ 56,
31
+ 57,
32
+ 97
33
+ ];
18
34
  function startsWith(bytes, signature) {
19
35
  if (bytes.length < signature.length) return false;
20
36
  for (let i = 0; i < signature.length; i++) if (bytes[i] !== signature[i]) return false;
21
37
  return true;
22
38
  }
39
+ const SVG_SNIFF_WINDOW = 1024;
40
+ function looksLikeSvg(bytes) {
41
+ const window = bytes.subarray(0, Math.min(bytes.length, SVG_SNIFF_WINDOW));
42
+ let text = "";
43
+ for (const byte of window) text += String.fromCharCode(byte);
44
+ const trimmed = text.trimStart();
45
+ return trimmed.startsWith("<?xml") || trimmed.startsWith("<svg");
46
+ }
23
47
  function sniffImageFormat(bytes) {
24
48
  if (startsWith(bytes, PNG_SIGNATURE)) return "png";
25
49
  if (startsWith(bytes, JPEG_SIGNATURE)) return "jpeg";
50
+ if (startsWith(bytes, GIF87A_SIGNATURE) || startsWith(bytes, GIF89A_SIGNATURE)) return "gif";
51
+ if (looksLikeSvg(bytes)) return "svg";
26
52
  }
27
53
  //#endregion
28
54
  exports.sniffImageFormat = sniffImageFormat;
@@ -1,2 +1,2 @@
1
- import { n as sniffImageFormat, t as ImageFormat } from "../sniff-DGOBHA0O.cjs";
1
+ import { n as sniffImageFormat, t as ImageFormat } from "../sniff-eR8lObzF.cjs";
2
2
  export { ImageFormat, sniffImageFormat };
@@ -1,2 +1,2 @@
1
- import { n as sniffImageFormat, t as ImageFormat } from "../sniff-DGOBHA0O.js";
1
+ import { n as sniffImageFormat, t as ImageFormat } from "../sniff-eR8lObzF.js";
2
2
  export { ImageFormat, sniffImageFormat };
@@ -14,14 +14,40 @@ const JPEG_SIGNATURE = [
14
14
  216,
15
15
  255
16
16
  ];
17
+ const GIF87A_SIGNATURE = [
18
+ 71,
19
+ 73,
20
+ 70,
21
+ 56,
22
+ 55,
23
+ 97
24
+ ];
25
+ const GIF89A_SIGNATURE = [
26
+ 71,
27
+ 73,
28
+ 70,
29
+ 56,
30
+ 57,
31
+ 97
32
+ ];
17
33
  function startsWith(bytes, signature) {
18
34
  if (bytes.length < signature.length) return false;
19
35
  for (let i = 0; i < signature.length; i++) if (bytes[i] !== signature[i]) return false;
20
36
  return true;
21
37
  }
38
+ const SVG_SNIFF_WINDOW = 1024;
39
+ function looksLikeSvg(bytes) {
40
+ const window = bytes.subarray(0, Math.min(bytes.length, SVG_SNIFF_WINDOW));
41
+ let text = "";
42
+ for (const byte of window) text += String.fromCharCode(byte);
43
+ const trimmed = text.trimStart();
44
+ return trimmed.startsWith("<?xml") || trimmed.startsWith("<svg");
45
+ }
22
46
  function sniffImageFormat(bytes) {
23
47
  if (startsWith(bytes, PNG_SIGNATURE)) return "png";
24
48
  if (startsWith(bytes, JPEG_SIGNATURE)) return "jpeg";
49
+ if (startsWith(bytes, GIF87A_SIGNATURE) || startsWith(bytes, GIF89A_SIGNATURE)) return "gif";
50
+ if (looksLikeSvg(bytes)) return "svg";
25
51
  }
26
52
  //#endregion
27
53
  export { sniffImageFormat };
package/dist/index.d.cts CHANGED
@@ -8,7 +8,7 @@ import { n as unzipPackage, r as zipPackage, t as ZipEntry } from "./zip-ie17sOo
8
8
  import { n as bytesToBase64, t as base64ToBytes } from "./base64--HuymRl_.cjs";
9
9
  import { n as OdfNamespacePrefix, r as xmlnsAttributes, t as ODF_NAMESPACES } from "./ns-Cihto3Fx.cjs";
10
10
  import { n as OdfExtension, r as mediaTypeForExtension, t as ODF_MEDIA_TYPES } from "./media-type-BOLkcHkJ.cjs";
11
- import { n as sniffImageFormat, t as ImageFormat } from "./sniff-DGOBHA0O.cjs";
11
+ import { n as sniffImageFormat, t as ImageFormat } from "./sniff-eR8lObzF.cjs";
12
12
  import { n as writeMimetype, t as readMimetype } from "./mimetype-1BaQzNiS.cjs";
13
13
  import { n as txt, t as el } from "./fragment-9dNg-m46.cjs";
14
14
  import { n as encodeXmlText, t as decodeXmlText } from "./entities-BZlXvHqu.cjs";
package/dist/index.d.ts CHANGED
@@ -8,7 +8,7 @@ import { n as unzipPackage, r as zipPackage, t as ZipEntry } from "./zip-ie17sOo
8
8
  import { n as bytesToBase64, t as base64ToBytes } from "./base64--HuymRl_.js";
9
9
  import { n as OdfNamespacePrefix, r as xmlnsAttributes, t as ODF_NAMESPACES } from "./ns-Cihto3Fx.js";
10
10
  import { n as OdfExtension, r as mediaTypeForExtension, t as ODF_MEDIA_TYPES } from "./media-type-BOLkcHkJ.js";
11
- import { n as sniffImageFormat, t as ImageFormat } from "./sniff-DGOBHA0O.js";
11
+ import { n as sniffImageFormat, t as ImageFormat } from "./sniff-eR8lObzF.js";
12
12
  import { n as writeMimetype, t as readMimetype } from "./mimetype-DvMCOzmu.js";
13
13
  import { n as txt, t as el } from "./fragment-ClgCV_if.js";
14
14
  import { n as encodeXmlText, t as decodeXmlText } from "./entities-BZlXvHqu.js";
package/dist/manifest.cjs CHANGED
@@ -82,6 +82,8 @@ function resolvePartMediaType(path, bytes, overrides) {
82
82
  const sniffed = require_image_sniff.sniffImageFormat(bytes);
83
83
  if (sniffed === "png") return "image/png";
84
84
  if (sniffed === "jpeg") return "image/jpeg";
85
+ if (sniffed === "gif") return "image/gif";
86
+ if (sniffed === "svg") return "image/svg+xml";
85
87
  }
86
88
  return "";
87
89
  }
package/dist/manifest.js CHANGED
@@ -81,6 +81,8 @@ function resolvePartMediaType(path, bytes, overrides) {
81
81
  const sniffed = sniffImageFormat(bytes);
82
82
  if (sniffed === "png") return "image/png";
83
83
  if (sniffed === "jpeg") return "image/jpeg";
84
+ if (sniffed === "gif") return "image/gif";
85
+ if (sniffed === "svg") return "image/svg+xml";
84
86
  }
85
87
  return "";
86
88
  }
@@ -1,5 +1,5 @@
1
1
  //#region src/image/sniff.d.ts
2
- type ImageFormat = "png" | "jpeg";
2
+ type ImageFormat = "png" | "jpeg" | "gif" | "svg";
3
3
  declare function sniffImageFormat(bytes: Uint8Array<ArrayBuffer>): ImageFormat | undefined;
4
4
  //#endregion
5
5
  export { sniffImageFormat as n, ImageFormat as t };
@@ -1,5 +1,5 @@
1
1
  //#region src/image/sniff.d.ts
2
- type ImageFormat = "png" | "jpeg";
2
+ type ImageFormat = "png" | "jpeg" | "gif" | "svg";
3
3
  declare function sniffImageFormat(bytes: Uint8Array<ArrayBuffer>): ImageFormat | undefined;
4
4
  //#endregion
5
5
  export { sniffImageFormat as n, ImageFormat as t };
@@ -5,6 +5,7 @@ const require_typed_shared_units = require("../shared/units.cjs");
5
5
  const require_typed_shared_list = require("../shared/list.cjs");
6
6
  const require_typed_shared_paragraph = require("../shared/paragraph.cjs");
7
7
  const require_typed_shared_table = require("../shared/table.cjs");
8
+ const require_typed_shared_image = require("../shared/image.cjs");
8
9
  const require_typed_shared_canonicalise = require("../shared/canonicalise.cjs");
9
10
  //#region src/typed/draw/write-shapes.ts
10
11
  function unsupportedShapeContent(what) {
@@ -145,7 +146,7 @@ function writeShapeTextBox(paragraphs, state) {
145
146
  }
146
147
  const PICTURES_DIRECTORY = "Pictures";
147
148
  function writeShapeImage(image, state) {
148
- const extension = image.format === "png" ? "png" : "jpg";
149
+ const extension = require_typed_shared_image.imageExtension(image.format);
149
150
  const path = `${PICTURES_DIRECTORY}/image${state.nextImage}.${extension}`;
150
151
  state.nextImage += 1;
151
152
  state.pkg.parts[path] = {
@@ -4,6 +4,7 @@ import { formatOdfLength, formatOdfNumber } from "../shared/units.js";
4
4
  import { buildOdfListStyle, closeListPlan, listKindOf, planListMembership, writeOdfList } from "../shared/list.js";
5
5
  import { writeOdfParagraph } from "../shared/paragraph.js";
6
6
  import { writeOdfTable } from "../shared/table.js";
7
+ import { imageExtension } from "../shared/image.js";
7
8
  import { canonicalImage, canonicalParagraph, canonicalTable } from "../shared/canonicalise.js";
8
9
  //#region src/typed/draw/write-shapes.ts
9
10
  function unsupportedShapeContent(what) {
@@ -144,7 +145,7 @@ function writeShapeTextBox(paragraphs, state) {
144
145
  }
145
146
  const PICTURES_DIRECTORY = "Pictures";
146
147
  function writeShapeImage(image, state) {
147
- const extension = image.format === "png" ? "png" : "jpg";
148
+ const extension = imageExtension(image.format);
148
149
  const path = `${PICTURES_DIRECTORY}/image${state.nextImage}.${extension}`;
149
150
  state.nextImage += 1;
150
151
  state.pkg.parts[path] = {
@@ -11,6 +11,7 @@ const require_typed_shared_metadata = require("../shared/metadata.cjs");
11
11
  const require_typed_shared_paragraph = require("../shared/paragraph.cjs");
12
12
  const require_typed_shared_table = require("../shared/table.cjs");
13
13
  const require_package_io_scaffold = require("../../package-io/scaffold.cjs");
14
+ const require_typed_shared_image = require("../shared/image.cjs");
14
15
  require("../../embedded-Bxyss_ck.cjs");
15
16
  let document_schema_js = require("document-schema.js");
16
17
  //#region src/typed/ods/write.ts
@@ -190,7 +191,7 @@ function groupImagesByPosition(images) {
190
191
  return byPosition;
191
192
  }
192
193
  function writeSheetImageFrame(image, state) {
193
- const extension = image.format === "png" ? "png" : "jpg";
194
+ const extension = require_typed_shared_image.imageExtension(image.format);
194
195
  const path = `${PICTURES_DIRECTORY}/image${state.nextImage}.${extension}`;
195
196
  state.nextImage += 1;
196
197
  state.pkg.parts[path] = {
@@ -10,6 +10,7 @@ import { writeOdfMetadata } from "../shared/metadata.js";
10
10
  import { segmentOdfParagraphRuns, writeOdfParagraph } from "../shared/paragraph.js";
11
11
  import { BORDER_EDGE_ATTRS, BORDER_EDGE_KEYS, formatBorderEdge } from "../shared/table.js";
12
12
  import { createOdfPackage, odfPartContainer } from "../../package-io/scaffold.js";
13
+ import { imageExtension } from "../shared/image.js";
13
14
  import "../../embedded-BnavfkP-.js";
14
15
  import { colorToRgbHex, flattenTree, rgbHexToColor } from "document-schema.js";
15
16
  //#region src/typed/ods/write.ts
@@ -189,7 +190,7 @@ function groupImagesByPosition(images) {
189
190
  return byPosition;
190
191
  }
191
192
  function writeSheetImageFrame(image, state) {
192
- const extension = image.format === "png" ? "png" : "jpg";
193
+ const extension = imageExtension(image.format);
193
194
  const path = `${PICTURES_DIRECTORY}/image${state.nextImage}.${extension}`;
194
195
  state.nextImage += 1;
195
196
  state.pkg.parts[path] = {
@@ -10,6 +10,7 @@ const require_typed_shared_list = require("../shared/list.cjs");
10
10
  const require_typed_shared_paragraph = require("../shared/paragraph.cjs");
11
11
  const require_typed_shared_table = require("../shared/table.cjs");
12
12
  const require_package_io_scaffold = require("../../package-io/scaffold.cjs");
13
+ const require_typed_shared_image = require("../shared/image.cjs");
13
14
  const require_typed_shared_canonicalise = require("../shared/canonicalise.cjs");
14
15
  let document_schema_js = require("document-schema.js");
15
16
  //#region src/typed/odt/write.ts
@@ -163,7 +164,7 @@ function listStyleNameFor(kind, state) {
163
164
  return name;
164
165
  }
165
166
  function writeImageFrame(image, state) {
166
- const extension = image.format === "png" ? "png" : "jpg";
167
+ const extension = require_typed_shared_image.imageExtension(image.format);
167
168
  const path = `${PICTURES_DIRECTORY}/image${state.nextImage}.${extension}`;
168
169
  state.nextImage += 1;
169
170
  state.pkg.parts[path] = {
@@ -9,6 +9,7 @@ import { buildOdfListStyle, closeListPlan, listKindOf, planListMembership, write
9
9
  import { writeOdfParagraph } from "../shared/paragraph.js";
10
10
  import { writeOdfTable } from "../shared/table.js";
11
11
  import { createOdfPackage, odfPartContainer } from "../../package-io/scaffold.js";
12
+ import { imageExtension } from "../shared/image.js";
12
13
  import { canonicalImage, canonicalMetadata, canonicalParagraph, canonicalTable } from "../shared/canonicalise.js";
13
14
  import { flattenTree } from "document-schema.js";
14
15
  //#region src/typed/odt/write.ts
@@ -162,7 +163,7 @@ function listStyleNameFor(kind, state) {
162
163
  return name;
163
164
  }
164
165
  function writeImageFrame(image, state) {
165
- const extension = image.format === "png" ? "png" : "jpg";
166
+ const extension = imageExtension(image.format);
166
167
  const path = `${PICTURES_DIRECTORY}/image${state.nextImage}.${extension}`;
167
168
  state.nextImage += 1;
168
169
  state.pkg.parts[path] = {
@@ -0,0 +1,12 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ //#region src/typed/shared/image.ts
3
+ function imageExtension(format) {
4
+ switch (format) {
5
+ case "png": return "png";
6
+ case "jpeg": return "jpg";
7
+ case "svg": return "svg";
8
+ case "gif": return "gif";
9
+ }
10
+ }
11
+ //#endregion
12
+ exports.imageExtension = imageExtension;
@@ -0,0 +1,5 @@
1
+ import { ContentImageBlock } from "document-schema.js";
2
+ //#region src/typed/shared/image.d.ts
3
+ declare function imageExtension(format: ContentImageBlock["format"]): string;
4
+ //#endregion
5
+ export { imageExtension };
@@ -0,0 +1,5 @@
1
+ import { ContentImageBlock } from "document-schema.js";
2
+ //#region src/typed/shared/image.d.ts
3
+ declare function imageExtension(format: ContentImageBlock["format"]): string;
4
+ //#endregion
5
+ export { imageExtension };
@@ -0,0 +1,11 @@
1
+ //#region src/typed/shared/image.ts
2
+ function imageExtension(format) {
3
+ switch (format) {
4
+ case "png": return "png";
5
+ case "jpeg": return "jpg";
6
+ case "svg": return "svg";
7
+ case "gif": return "gif";
8
+ }
9
+ }
10
+ //#endregion
11
+ export { imageExtension };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "odf.js",
3
- "version": "6.4.0",
3
+ "version": "6.4.1",
4
4
  "description": "Type-safe, lossless round-trip conversion between OpenDocument Format packages (odt, ods, odp) and JSON, plus read support for the pre-OASIS OpenOffice.org 1.x documents ODF was based on (sxw, sxc, sxi, sxd), hand-written and dependency-minimal, built on Zod 4 codecs.",
5
5
  "type": "module",
6
6
  "repository": {
@@ -85,7 +85,7 @@
85
85
  "license": "MIT",
86
86
  "packageManager": "pnpm@11.6.0",
87
87
  "dependencies": {
88
- "document-schema.js": "^5.5.1",
88
+ "document-schema.js": "^5.6.0",
89
89
  "fast-xml-parser": "^5.10.1",
90
90
  "fflate": "^0.8.3",
91
91
  "zod": "^4.4.3"