ooxml.js 6.3.5 → 6.3.7
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/dist/image/sniff.cjs +26 -0
- package/dist/image/sniff.d.cts +1 -1
- package/dist/image/sniff.d.ts +1 -1
- package/dist/image/sniff.js +26 -0
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/{sniff-DGOBHA0O.d.cts → sniff-eR8lObzF.d.cts} +1 -1
- package/dist/{sniff-DGOBHA0O.d.ts → sniff-eR8lObzF.d.ts} +1 -1
- package/dist/typed/docx/write.cjs +13 -1
- package/dist/typed/docx/write.js +13 -1
- package/package.json +4 -4
package/dist/image/sniff.cjs
CHANGED
|
@@ -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;
|
package/dist/image/sniff.d.cts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as sniffImageFormat, t as ImageFormat } from "../sniff-
|
|
1
|
+
import { n as sniffImageFormat, t as ImageFormat } from "../sniff-eR8lObzF.cjs";
|
|
2
2
|
export { ImageFormat, sniffImageFormat };
|
package/dist/image/sniff.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as sniffImageFormat, t as ImageFormat } from "../sniff-
|
|
1
|
+
import { n as sniffImageFormat, t as ImageFormat } from "../sniff-eR8lObzF.js";
|
|
2
2
|
export { ImageFormat, sniffImageFormat };
|
package/dist/image/sniff.js
CHANGED
|
@@ -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
|
@@ -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-
|
|
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-
|
|
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";
|
|
@@ -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 };
|
|
@@ -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
|
|
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]
|
package/dist/typed/docx/write.js
CHANGED
|
@@ -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
|
|
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]
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ooxml.js",
|
|
3
|
-
"version": "6.3.
|
|
3
|
+
"version": "6.3.7",
|
|
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,9 +80,9 @@
|
|
|
80
80
|
"license": "MIT",
|
|
81
81
|
"packageManager": "pnpm@11.6.0",
|
|
82
82
|
"dependencies": {
|
|
83
|
-
"archive-codec": "^1.4.
|
|
84
|
-
"document-schema.js": "^5.
|
|
85
|
-
"excel-number-format": "^1.0.
|
|
83
|
+
"archive-codec": "^1.4.2",
|
|
84
|
+
"document-schema.js": "^5.6.0",
|
|
85
|
+
"excel-number-format": "^1.0.1",
|
|
86
86
|
"fast-xml-parser": "^5.10.1",
|
|
87
87
|
"fflate": "^0.8.3",
|
|
88
88
|
"zod": "^4.4.3"
|