ooxml.js 6.3.4 → 6.3.6

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.cjs CHANGED
@@ -15,7 +15,7 @@ const require_typed_util = require("./typed/util.cjs");
15
15
  const require_typed_shared_color = require("./typed/shared/color.cjs");
16
16
  const require_typed_shared_metadata = require("./typed/shared/metadata.cjs");
17
17
  const require_image_sniff = require("./image/sniff.cjs");
18
- const require_read = require("./read-CXksZHJW.cjs");
18
+ const require_read = require("./read-6whiWc5N.cjs");
19
19
  const require_typed_xlsx_content = require("./typed/xlsx/content.cjs");
20
20
  const require_typed_docx_numbering = require("./typed/docx/numbering.cjs");
21
21
  const require_typed_xlsx_build = require("./typed/xlsx/build.cjs");
package/dist/index.d.cts CHANGED
@@ -12,7 +12,7 @@ import { a as elementsWithTag, c as textContent, i as decodeEntities, l as walk,
12
12
  import { _ as encodeCompactPackage, b as toCompact, c as CompactPart, f as CompactXmlNode, g as decodeCompactPackage, h as compactPackageCodec, l as CompactPartSchema, m as compactCodec, o as CompactPackage, p as CompactXmlNodeSchema, s as CompactPackageSchema, t as CompactAttrPairs, v as fromCompact, y as isCompactXmlNode } from "./compact-DMCbYORW.cjs";
13
13
  import { n as applyColorTransforms, t as ColorTransform } from "./color-DLoZOrg3.cjs";
14
14
  import { n as DocumentMetadataSchema, t as DocumentMetadata } from "./metadata-C74-XCrx.cjs";
15
- import { n as sniffImageFormat, t as ImageFormat } from "./sniff-DGOBHA0O.cjs";
15
+ import { n as sniffImageFormat, t as ImageFormat } from "./sniff-eR8lObzF.cjs";
16
16
  import { i as buildDocxPackageFromContent, n as DocxContent, r as EmbeddedPresentationSerialiser, t as BuildDocxContentOptions } from "./write-BGTpp3RS.cjs";
17
17
  import { a as readXlsx, i as readPptx, n as buildXlsxPackage, r as readDocx, t as buildDocxPackage } from "./document-tree-CjI-Z4Tp.cjs";
18
18
  import { a as Footnote, c as HeaderFooterPartSchema, d as readDocxContent, i as DocxDocumentSchema, l as SectionHeaderFooterReferences, n as CommentSchema, o as FootnoteSchema, r as DocxDocument, s as HeaderFooterPart, t as Comment, u as SectionHeaderFooterReferencesSchema } from "./read-DGjfFreS.cjs";
package/dist/index.d.ts CHANGED
@@ -12,7 +12,7 @@ import { a as elementsWithTag, c as textContent, i as decodeEntities, l as walk,
12
12
  import { _ as encodeCompactPackage, b as toCompact, c as CompactPart, f as CompactXmlNode, g as decodeCompactPackage, h as compactPackageCodec, l as CompactPartSchema, m as compactCodec, o as CompactPackage, p as CompactXmlNodeSchema, s as CompactPackageSchema, t as CompactAttrPairs, v as fromCompact, y as isCompactXmlNode } from "./compact-CmOeA2dl.js";
13
13
  import { n as applyColorTransforms, t as ColorTransform } from "./color-DLoZOrg3.js";
14
14
  import { n as DocumentMetadataSchema, t as DocumentMetadata } from "./metadata-Bjfa88HQ.js";
15
- import { n as sniffImageFormat, t as ImageFormat } from "./sniff-DGOBHA0O.js";
15
+ import { n as sniffImageFormat, t as ImageFormat } from "./sniff-eR8lObzF.js";
16
16
  import { i as buildDocxPackageFromContent, n as DocxContent, r as EmbeddedPresentationSerialiser, t as BuildDocxContentOptions } from "./write-Cnfu3zdB.js";
17
17
  import { a as readXlsx, i as readPptx, n as buildXlsxPackage, r as readDocx, t as buildDocxPackage } from "./document-tree-B17XbBOR.js";
18
18
  import { a as Footnote, c as HeaderFooterPartSchema, d as readDocxContent, i as DocxDocumentSchema, l as SectionHeaderFooterReferences, n as CommentSchema, o as FootnoteSchema, r as DocxDocument, s as HeaderFooterPart, t as Comment, u as SectionHeaderFooterReferencesSchema } from "./read-1brymJUA.js";
package/dist/index.js CHANGED
@@ -14,7 +14,7 @@ import { attr, childrenWithTag, decodeEntities, elementsWithTag, resolveRelation
14
14
  import { applyColorTransforms } from "./typed/shared/color.js";
15
15
  import { DocumentMetadataSchema } from "./typed/shared/metadata.js";
16
16
  import { sniffImageFormat } from "./image/sniff.js";
17
- import { a as SectionHeaderFooterReferencesSchema, i as HeaderFooterPartSchema, l as PptxDocumentSchema, n as DocxDocumentSchema, o as readDocxContent, r as FootnoteSchema, t as CommentSchema, u as readPptxContent } from "./read-BZ_jycSX.js";
17
+ import { a as SectionHeaderFooterReferencesSchema, i as HeaderFooterPartSchema, l as PptxDocumentSchema, n as DocxDocumentSchema, o as readDocxContent, r as FootnoteSchema, t as CommentSchema, u as readPptxContent } from "./read-BrAuHnvH.js";
18
18
  import { readXlsxContent } from "./typed/xlsx/content.js";
19
19
  import { NumberingDefinitionSchema, NumberingLevelSchema, readNumberingDefinitions } from "./typed/docx/numbering.js";
20
20
  import { buildXlsxPackageFromContent } from "./typed/xlsx/build.js";
@@ -255,13 +255,18 @@ function readBlipImage(parent, slideRels, pkg, frame) {
255
255
  const mediaPart = rel === void 0 ? void 0 : pkg.parts[rel.target];
256
256
  if (mediaPart?.kind !== "binary") return;
257
257
  const format = require_image_sniff.sniffImageFormat(require_util_base64.base64ToBytes(mediaPart.base64));
258
- return format === void 0 ? void 0 : {
258
+ if (format === void 0) return;
259
+ const image = {
259
260
  kind: "image",
260
261
  format,
261
262
  base64: mediaPart.base64,
262
263
  widthPt: frame.widthPt,
263
264
  heightPt: frame.heightPt
264
265
  };
266
+ const cNvPr = require_typed_util.elementsWithTag([parent], "p:cNvPr")[0];
267
+ const altText = cNvPr === void 0 ? void 0 : require_typed_util.attr(cNvPr, "descr") ?? require_typed_util.attr(cNvPr, "title");
268
+ if (altText !== void 0) image.altText = require_typed_util.decodeEntities(altText);
269
+ return image;
265
270
  }
266
271
  function readPicShape(pic, context, slideRels, pkg, parentTransform) {
267
272
  const resolved = resolveShapeFrame(pic, context, parentTransform);
@@ -255,13 +255,18 @@ function readBlipImage(parent, slideRels, pkg, frame) {
255
255
  const mediaPart = rel === void 0 ? void 0 : pkg.parts[rel.target];
256
256
  if (mediaPart?.kind !== "binary") return;
257
257
  const format = sniffImageFormat(base64ToBytes(mediaPart.base64));
258
- return format === void 0 ? void 0 : {
258
+ if (format === void 0) return;
259
+ const image = {
259
260
  kind: "image",
260
261
  format,
261
262
  base64: mediaPart.base64,
262
263
  widthPt: frame.widthPt,
263
264
  heightPt: frame.heightPt
264
265
  };
266
+ const cNvPr = elementsWithTag([parent], "p:cNvPr")[0];
267
+ const altText = cNvPr === void 0 ? void 0 : attr(cNvPr, "descr") ?? attr(cNvPr, "title");
268
+ if (altText !== void 0) image.altText = decodeEntities(altText);
269
+ return image;
265
270
  }
266
271
  function readPicShape(pic, context, slideRels, pkg, parentTransform) {
267
272
  const resolved = resolveShapeFrame(pic, context, parentTransform);
@@ -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 };
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_read = require("../read-CXksZHJW.cjs");
2
+ const require_read = require("../read-6whiWc5N.cjs");
3
3
  const require_typed_xlsx_content = require("./xlsx/content.cjs");
4
4
  const require_typed_xlsx_build = require("./xlsx/build.cjs");
5
5
  const require_typed_docx_write = require("./docx/write.cjs");
@@ -1,4 +1,4 @@
1
- import { o as readDocxContent, u as readPptxContent } from "../read-BZ_jycSX.js";
1
+ import { o as readDocxContent, u as readPptxContent } from "../read-BrAuHnvH.js";
2
2
  import { readXlsxContent } from "./xlsx/content.js";
3
3
  import { buildXlsxPackageFromContent } from "./xlsx/build.js";
4
4
  import { buildDocxPackageFromContent } from "./docx/write.js";
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_read = require("../../read-CXksZHJW.cjs");
2
+ const require_read = require("../../read-6whiWc5N.cjs");
3
3
  exports.CommentSchema = require_read.CommentSchema;
4
4
  exports.DocxDocumentSchema = require_read.DocxDocumentSchema;
5
5
  exports.FootnoteSchema = require_read.FootnoteSchema;
@@ -1,2 +1,2 @@
1
- import { a as SectionHeaderFooterReferencesSchema, i as HeaderFooterPartSchema, n as DocxDocumentSchema, o as readDocxContent, r as FootnoteSchema, t as CommentSchema } from "../../read-BZ_jycSX.js";
1
+ import { a as SectionHeaderFooterReferencesSchema, i as HeaderFooterPartSchema, n as DocxDocumentSchema, o as readDocxContent, r as FootnoteSchema, t as CommentSchema } from "../../read-BrAuHnvH.js";
2
2
  export { CommentSchema, DocxDocumentSchema, FootnoteSchema, HeaderFooterPartSchema, SectionHeaderFooterReferencesSchema, readDocxContent };
@@ -70,11 +70,19 @@ function hyperlinkRelationshipId(state, uri) {
70
70
  state.hyperlinkIds.set(uri, id);
71
71
  return id;
72
72
  }
73
+ function mediaExtension(format) {
74
+ switch (format) {
75
+ case "png": return "png";
76
+ case "jpeg": return "jpeg";
77
+ case "gif": return "gif";
78
+ }
79
+ }
73
80
  function imageRelationshipId(state, image) {
81
+ if (image.format === "svg") throw new Error("buildDocxPackageFromContent: an image block in svg format has no OOXML blip this writer can produce (WordprocessingML's a:blip only references a raster part Word decodes directly -- png/jpeg/gif -- and this writer does not build the a:svgBlip extension plus raster-fallback pair SVG needs to render at all)");
74
82
  const key = `${image.format}:${image.base64}`;
75
83
  const existing = state.mediaIds.get(key);
76
84
  if (existing !== void 0) return existing;
77
- const name = `image${state.mediaParts.size + 1}.${image.format === "png" ? "png" : "jpeg"}`;
85
+ const name = `image${state.mediaParts.size + 1}.${mediaExtension(image.format)}`;
78
86
  state.mediaParts.set(name, {
79
87
  format: image.format,
80
88
  base64: image.base64
@@ -781,6 +789,10 @@ function buildContentTypesPart(state) {
781
789
  Extension: "jpeg",
782
790
  ContentType: "image/jpeg"
783
791
  }));
792
+ if (mediaFormats.has("gif")) defaults.push(require_xml_fragment.el("Default", {
793
+ Extension: "gif",
794
+ ContentType: "image/gif"
795
+ }));
784
796
  const embeddingOverrides = [...state.embeddingParts].map(([name, payload]) => require_xml_fragment.el("Override", {
785
797
  PartName: `/word/embeddings/${name}`,
786
798
  ContentType: EMBEDDED_PART_CONTENT_TYPES[payload.extension]
@@ -69,11 +69,19 @@ function hyperlinkRelationshipId(state, uri) {
69
69
  state.hyperlinkIds.set(uri, id);
70
70
  return id;
71
71
  }
72
+ function mediaExtension(format) {
73
+ switch (format) {
74
+ case "png": return "png";
75
+ case "jpeg": return "jpeg";
76
+ case "gif": return "gif";
77
+ }
78
+ }
72
79
  function imageRelationshipId(state, image) {
80
+ if (image.format === "svg") throw new Error("buildDocxPackageFromContent: an image block in svg format has no OOXML blip this writer can produce (WordprocessingML's a:blip only references a raster part Word decodes directly -- png/jpeg/gif -- and this writer does not build the a:svgBlip extension plus raster-fallback pair SVG needs to render at all)");
73
81
  const key = `${image.format}:${image.base64}`;
74
82
  const existing = state.mediaIds.get(key);
75
83
  if (existing !== void 0) return existing;
76
- const name = `image${state.mediaParts.size + 1}.${image.format === "png" ? "png" : "jpeg"}`;
84
+ const name = `image${state.mediaParts.size + 1}.${mediaExtension(image.format)}`;
77
85
  state.mediaParts.set(name, {
78
86
  format: image.format,
79
87
  base64: image.base64
@@ -780,6 +788,10 @@ function buildContentTypesPart(state) {
780
788
  Extension: "jpeg",
781
789
  ContentType: "image/jpeg"
782
790
  }));
791
+ if (mediaFormats.has("gif")) defaults.push(el("Default", {
792
+ Extension: "gif",
793
+ ContentType: "image/gif"
794
+ }));
783
795
  const embeddingOverrides = [...state.embeddingParts].map(([name, payload]) => el("Override", {
784
796
  PartName: `/word/embeddings/${name}`,
785
797
  ContentType: EMBEDDED_PART_CONTENT_TYPES[payload.extension]
@@ -1,4 +1,4 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_read = require("../read-CXksZHJW.cjs");
2
+ const require_read = require("../read-6whiWc5N.cjs");
3
3
  exports.readEmbeddedOoxmlPayload = require_read.readEmbeddedOoxmlPayload;
4
4
  exports.readEmbeddedPayloadPart = require_read.readEmbeddedPayloadPart;
@@ -1,2 +1,2 @@
1
- import { c as readEmbeddedPayloadPart, s as readEmbeddedOoxmlPayload } from "../read-BZ_jycSX.js";
1
+ import { c as readEmbeddedPayloadPart, s as readEmbeddedOoxmlPayload } from "../read-BrAuHnvH.js";
2
2
  export { readEmbeddedOoxmlPayload, readEmbeddedPayloadPart };
@@ -1,4 +1,4 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_read = require("../../read-CXksZHJW.cjs");
2
+ const require_read = require("../../read-6whiWc5N.cjs");
3
3
  exports.PptxDocumentSchema = require_read.PptxDocumentSchema;
4
4
  exports.readPptxContent = require_read.readPptxContent;
@@ -1,2 +1,2 @@
1
- import { l as PptxDocumentSchema, u as readPptxContent } from "../../read-BZ_jycSX.js";
1
+ import { l as PptxDocumentSchema, u as readPptxContent } from "../../read-BrAuHnvH.js";
2
2
  export { PptxDocumentSchema, readPptxContent };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ooxml.js",
3
- "version": "6.3.4",
3
+ "version": "6.3.6",
4
4
  "description": "Type-safe, lossless round-trip conversion between OOXML packages (docx, pptx, xlsx) and JSON, built on Zod 4 codecs.",
5
5
  "type": "module",
6
6
  "repository": {
@@ -80,8 +80,8 @@
80
80
  "license": "MIT",
81
81
  "packageManager": "pnpm@11.6.0",
82
82
  "dependencies": {
83
- "archive-codec": "^1.4.0",
84
- "document-schema.js": "^5.5.1",
83
+ "archive-codec": "^1.4.1",
84
+ "document-schema.js": "^5.6.0",
85
85
  "excel-number-format": "^1.0.0",
86
86
  "fast-xml-parser": "^5.10.1",
87
87
  "fflate": "^0.8.3",