documents.js 1.35.1 → 1.36.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 +2 -2
- package/dist/index.cjs +42 -0
- package/dist/index.d.cts +5 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.js +39 -1
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -103,7 +103,7 @@ const docxBack = z.encode(docxPdfCodec, pdfFromDocx);
|
|
|
103
103
|
|
|
104
104
|
The package is layered from generic primitives outward to the two conversion directions:
|
|
105
105
|
|
|
106
|
-
- **`src/model/`** — thin, documents.js-specific additions on top of the sibling [`document-content-model`](https://github.com/ExaDev/document-content-model) package, which now owns the two pivot models themselves: `LayoutDocument` (the PDF-side pivot: pages of positioned text/image/rect/line/ellipse/link items, PDF-native coordinates and units) and `ContentDocument` (the semantic pivot: a discriminated union of `wordprocessing` and `presentation` variants sharing paragraph/run/table/image building blocks) are both imported, not defined here — `document-content-model` exists specifically so `ooxml.js
|
|
106
|
+
- **`src/model/`** — thin, documents.js-specific additions on top of the sibling [`document-content-model`](https://github.com/ExaDev/document-content-model) package, which now owns the two pivot models themselves: `LayoutDocument` (the PDF-side pivot: pages of positioned text/image/rect/line/ellipse/link items, PDF-native coordinates and units) and `ContentDocument` (the semantic pivot: a discriminated union of `wordprocessing` and `presentation` variants sharing paragraph/run/table/image building blocks) are both imported, not defined here — `document-content-model` exists specifically so `ooxml.js`, `odf.js`, and `documents.js` share one schema instead of each maintaining an independent, drift-prone copy. What remains local: `bytes.ts` (magic-byte-validated `Uint8Array` schemas for docx/pptx/PDF, plus `Odt`/`Ods`/`Odp`/`OdgBytesSchema`, which check the package's actual declared media type against `odf.js`'s `ODF_MEDIA_TYPES` table rather than only the generic ZIP signature the OOXML schemas are limited to), `units.ts` (OOXML EMU/twip/point/half-point conversions), and `geometry.ts`/`color.ts`/`style.ts`, each now mostly a thin re-export of `document-content-model`'s `Box`/`Margins`/`PageSize`/`Color`/`Alignment`/`LayoutFont` — the one genuinely PDF-specific piece each still adds locally is `geometry.ts`'s `flipY` (the top-left/y-down ↔ bottom-left/y-up space conversion between OOXML/ODF and PDF coordinates); `LayoutFont`/`DEFAULT_LAYOUT_FONT` moved to `document-content-model` too (since `LayoutText`, part of the pivot, needs the field), leaving only the standard-14 font *resolution* logic that consumes it (`src/pdf/fonts.ts`/`font-read.ts`) as PDF-specific and local.
|
|
107
107
|
- **`src/bytes/`** and **`src/image/`** — generic byte and image-container primitives with zero PDF or OOXML knowledge: a chunked byte writer, a backtracking byte reader, CRC32, and a hand-written PNG decoder/encoder (palette/gray/RGB/alpha, multi-`IDAT` files, all five scanline filters) plus JPEG marker scanning for dimensions only — JPEG's compressed bytes pass through completely unchanged in both directions. `src/bytes/flate.ts` is the only file that imports `fflate`, mirroring how `ooxml.js`'s own `src/zip.ts` wraps it for ZIP handling.
|
|
108
108
|
- **`src/xml/`** and **`src/opc/`** — parent-aware XML query/mutation and OPC package mechanics (relationship IDs, content-type entries, atomic media-part insertion) built over `ooxml.js`'s `Package`/`XmlNode`, needed because `ooxml.js`'s own XML nodes have no parent pointers and `ooxml.js` never writes new parts into an existing package.
|
|
109
109
|
- **`src/edit/`** — the read-and-write editable model: live-view classes (`DocxEditor`/`DocxParagraph`/`DocxRun`/`DocxTable`, `PptxEditor`/`PptxSlide`/`PptxShape`) wrapping the actual `XmlElement` objects inside a decoded `Package`, plus `buildDocxPackage`/`buildPptxPackage` bridging a `ContentDocument` to a fresh package built entirely through those same primitives.
|
|
@@ -179,7 +179,7 @@ Commits follow Conventional Commits (`feat:`, `fix:`, `test:`, `chore:`, …), e
|
|
|
179
179
|
|
|
180
180
|
- [ooxml.js](https://github.com/ExaDev/ooxml.js) — the sibling package this depends on for all docx/pptx/xlsx ⇄ JSON handling and cascade-resolved typed reading.
|
|
181
181
|
- [document-content-model](https://github.com/ExaDev/document-content-model) — the sibling package that owns `ContentDocument`/`LayoutDocument` themselves; both `ooxml.js` and `documents.js` import from it rather than each maintaining an independent copy.
|
|
182
|
-
- [odf.js](https://github.com/ExaDev/odf.js) — a sibling package doing the equivalent lossless-codec job for the OpenDocument Format (odt/ods/odp/odg/…), also built on `document-content-model`.
|
|
182
|
+
- [odf.js](https://github.com/ExaDev/odf.js) — a sibling package doing the equivalent lossless-codec job for the OpenDocument Format (odt/ods/odp/odg/…), also built on `document-content-model`. A dependency of `documents.js` as of this package's `Odt`/`Ods`/`Odp`/`OdgBytesSchema` (`src/model/bytes.ts`), which validate against its `ODF_MEDIA_TYPES` table, and `src/interop.test.ts`, a type-level guard that `ooxml.js`'s and `odf.js`'s raw `XmlElement`/`XmlNode`/`Attribute`/`Package` container types stay structurally compatible. Full odt/ods/odp/odg → `ContentDocument` reading (the equivalent of `readDocxContent`/`readPptxContent`) is not yet integrated.
|
|
183
183
|
|
|
184
184
|
## License
|
|
185
185
|
|
package/dist/index.cjs
CHANGED
|
@@ -2,6 +2,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
2
2
|
let ooxml_js = require("ooxml.js");
|
|
3
3
|
let document_content_model = require("document-content-model");
|
|
4
4
|
let zod = require("zod");
|
|
5
|
+
let odf_js = require("odf.js");
|
|
5
6
|
let fflate = require("fflate");
|
|
6
7
|
//#region src/model/content.ts
|
|
7
8
|
const CONTENT_FORMAT_VERSION = 1;
|
|
@@ -65,6 +66,43 @@ function zipBytesSchema(label) {
|
|
|
65
66
|
const DocxBytesSchema = zipBytesSchema("docx");
|
|
66
67
|
const PptxBytesSchema = zipBytesSchema("pptx");
|
|
67
68
|
const PdfBytesSchema = zod.z.instanceof(Uint8Array).refine((bytes) => containsBytesWithin(bytes, PDF_HEADER, PDF_HEADER_SEARCH_WINDOW), { message: "not a valid PDF file: missing the %PDF- header" });
|
|
69
|
+
const MIMETYPE_ENTRY_FILENAME = "mimetype";
|
|
70
|
+
const MIMETYPE_FILENAME_OFFSET = 30;
|
|
71
|
+
const MIMETYPE_CONTENT_OFFSET = 38;
|
|
72
|
+
const COMPRESSION_METHOD_OFFSET = 8;
|
|
73
|
+
const COMPRESSED_SIZE_OFFSET = 18;
|
|
74
|
+
function readUint16LE(bytes, offset) {
|
|
75
|
+
const b0 = bytes[offset];
|
|
76
|
+
const b1 = bytes[offset + 1];
|
|
77
|
+
if (b0 === void 0 || b1 === void 0) return;
|
|
78
|
+
return b0 | b1 << 8;
|
|
79
|
+
}
|
|
80
|
+
function readUint32LE(bytes, offset) {
|
|
81
|
+
const b0 = bytes[offset];
|
|
82
|
+
const b1 = bytes[offset + 1];
|
|
83
|
+
const b2 = bytes[offset + 2];
|
|
84
|
+
const b3 = bytes[offset + 3];
|
|
85
|
+
if (b0 === void 0 || b1 === void 0 || b2 === void 0 || b3 === void 0) return;
|
|
86
|
+
return (b0 | b1 << 8 | b2 << 16 | b3 << 24) >>> 0;
|
|
87
|
+
}
|
|
88
|
+
function readAsciiSlice(bytes, offset, length) {
|
|
89
|
+
if (bytes.length < offset + length) return;
|
|
90
|
+
return new TextDecoder().decode(bytes.subarray(offset, offset + length));
|
|
91
|
+
}
|
|
92
|
+
function hasOdfMimetypeEntry(bytes, mediaType) {
|
|
93
|
+
if (!startsWithBytes(bytes, ZIP_LOCAL_FILE_HEADER)) return false;
|
|
94
|
+
if (readUint16LE(bytes, COMPRESSION_METHOD_OFFSET) !== 0) return false;
|
|
95
|
+
if (readAsciiSlice(bytes, MIMETYPE_FILENAME_OFFSET, 8) !== MIMETYPE_ENTRY_FILENAME) return false;
|
|
96
|
+
if (readUint32LE(bytes, COMPRESSED_SIZE_OFFSET) !== mediaType.length) return false;
|
|
97
|
+
return readAsciiSlice(bytes, MIMETYPE_CONTENT_OFFSET, mediaType.length) === mediaType;
|
|
98
|
+
}
|
|
99
|
+
function odfBytesSchema(label, mediaType) {
|
|
100
|
+
return zod.z.instanceof(Uint8Array).refine((bytes) => hasOdfMimetypeEntry(bytes, mediaType), { message: `not a valid ${label} file: the first zip entry is not a stored "mimetype" part declaring "${mediaType}"` });
|
|
101
|
+
}
|
|
102
|
+
const OdtBytesSchema = odfBytesSchema("odt", odf_js.ODF_MEDIA_TYPES.odt);
|
|
103
|
+
const OdsBytesSchema = odfBytesSchema("ods", odf_js.ODF_MEDIA_TYPES.ods);
|
|
104
|
+
const OdpBytesSchema = odfBytesSchema("odp", odf_js.ODF_MEDIA_TYPES.odp);
|
|
105
|
+
const OdgBytesSchema = odfBytesSchema("odg", odf_js.ODF_MEDIA_TYPES.odg);
|
|
68
106
|
//#endregion
|
|
69
107
|
//#region src/xml/fragment.ts
|
|
70
108
|
function el(tag, attrs = {}, children = []) {
|
|
@@ -7942,6 +7980,10 @@ Object.defineProperty(exports, "LAYOUT_FORMAT_VERSION", {
|
|
|
7942
7980
|
}
|
|
7943
7981
|
});
|
|
7944
7982
|
exports.NOOP_DIAGNOSTIC_SINK = NOOP_DIAGNOSTIC_SINK;
|
|
7983
|
+
exports.OdgBytesSchema = OdgBytesSchema;
|
|
7984
|
+
exports.OdpBytesSchema = OdpBytesSchema;
|
|
7985
|
+
exports.OdsBytesSchema = OdsBytesSchema;
|
|
7986
|
+
exports.OdtBytesSchema = OdtBytesSchema;
|
|
7945
7987
|
Object.defineProperty(exports, "PAGE_SIZE_A4", {
|
|
7946
7988
|
enumerable: true,
|
|
7947
7989
|
get: function() {
|
package/dist/index.d.cts
CHANGED
|
@@ -77,6 +77,10 @@ declare function flipY(box: Box$1, containerHeightPt: number): Box$1;
|
|
|
77
77
|
declare const DocxBytesSchema: z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>;
|
|
78
78
|
declare const PptxBytesSchema: z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>;
|
|
79
79
|
declare const PdfBytesSchema: z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>;
|
|
80
|
+
declare const OdtBytesSchema: z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>;
|
|
81
|
+
declare const OdsBytesSchema: z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>;
|
|
82
|
+
declare const OdpBytesSchema: z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>;
|
|
83
|
+
declare const OdgBytesSchema: z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>;
|
|
80
84
|
//#endregion
|
|
81
85
|
//#region src/edit/docx/image.d.ts
|
|
82
86
|
interface ImageInit$1 {
|
|
@@ -570,4 +574,4 @@ declare function fixedClock(date: Date): ClockPort;
|
|
|
570
574
|
//#region src/ports/abort.d.ts
|
|
571
575
|
declare function throwIfAborted(signal: AbortSignal | undefined): void;
|
|
572
576
|
//#endregion
|
|
573
|
-
export { type Alignment, type Attribute, AttributeSchema, type BinaryPart, BinaryPartSchema, type Box, COLOR_BLACK, CONTENT_FORMAT_VERSION, type ClockPort, type Comment, CommentSchema, type CompactAttrPairs, type CompactPackage, CompactPackageSchema, type CompactPart, CompactPartSchema, type CompactXmlNode, CompactXmlNodeSchema, type ContentBlock, ContentBlockSchema, type ContentDocument, ContentDocumentSchema, type ContentImageBlock, ContentImageBlockSchema, type ContentListMembership, type ContentPageBreak, ContentPageBreakSchema, type ContentParagraph, ContentParagraphSchema, type ContentRun, ContentRunSchema, type ContentSection, ContentSectionSchema, type ContentShape, ContentShapeSchema, type ContentSlide, ContentSlideSchema, type ContentTable, type ContentTableCell, ContentTableCellSchema, type ContentTableRow, ContentTableRowSchema, ContentTableSchema, type ConversionRequest, type ConversionResult, DEFAULT_LAYOUT_FONT, type DefinedName, DefinedNameSchema, type Diagnostic, type DocumentConverter, type DocumentFormat, type DocumentPayload, type DocumentToPdfOptions, type DocxBody, DocxBytesSchema, DocxEditor, DocxParagraph, DocxRun, DocxTable, DocxTableCell, DocxTableRow, type DrawingParagraphInit, type DrawingRunInit, type EngineLayoutOptions, LAYOUT_FORMAT_VERSION, type LayoutColor, type LayoutDocument, type LayoutEllipse, type LayoutFont, type LayoutImage, type LayoutImageAsset, type LayoutItem, type LayoutLine, type LayoutLink, type LayoutMetadata, type LayoutPage, type LayoutRect, type LayoutText, type Margins, NOOP_DIAGNOSTIC_SINK, PAGE_SIZE_A4, PAGE_SIZE_LETTER, type Package, PackageSchema, type PageSize, type Part, PartSchema, PdfBytesSchema, type PdfDiagnostic, type PdfDiagnosticSeverity, type PdfDiagnosticSink, PdfEncryptedError, PdfParseError, type PdfToDocumentOptions, PptxBytesSchema, PptxEditor, PptxShape, PptxSlide, type ReadPdfOptions, type ReconstructOptions, type Relationship, SLIDE_SIZE_STANDARD, SLIDE_SIZE_WIDESCREEN, type SlideImageInit, type SlidesLayoutOptions, type TextBoxInit, type WinAnsiSubstitution, type WritePdfOptions, type XmlCdata, XmlCdataSchema, type XmlComment, XmlCommentSchema, type XmlDeclaration, XmlDeclarationSchema, type XmlElement, XmlElementSchema, type XmlNode, XmlNodeSchema, type XmlPart, XmlPartSchema, type XmlPi, XmlPiSchema, type XmlText, XmlTextSchema, attr, base64ToBytes, buildDocxPackage, buildPptxPackage, buildXml, bytesToBase64, childrenWithTag, compactCodec, compactPackageCodec, convertPresentationToLayout, convertWordprocessingToLayout, createDocx, createLocalDocumentConverter, createPptx, decodeCompactPackage, decodeEntities, decodePackage, docxPdfCodec, docxToPdf, elementsWithTag, encodeCompactPackage, encodePackage, fixedClock, flipY, fromCompact, isCompactXmlNode, isContentBlock, isXmlNode, openDocx, openPptx, packageCodec, parsePackage, parseXml, pdfCodec, pdfToDocx, pdfToPptx, pptxPdfCodec, pptxToPdf, readDocxContent, readPdf, readPptxContent, reconstructPresentation, reconstructWordprocessing, resolveRelationships, rgbHexToColor, rootElement, serializePackage, systemClock, textContent, throwIfAborted, toCompact, unzipPackage, walk, writePdf, xmlCodec, zipPackage };
|
|
577
|
+
export { type Alignment, type Attribute, AttributeSchema, type BinaryPart, BinaryPartSchema, type Box, COLOR_BLACK, CONTENT_FORMAT_VERSION, type ClockPort, type Comment, CommentSchema, type CompactAttrPairs, type CompactPackage, CompactPackageSchema, type CompactPart, CompactPartSchema, type CompactXmlNode, CompactXmlNodeSchema, type ContentBlock, ContentBlockSchema, type ContentDocument, ContentDocumentSchema, type ContentImageBlock, ContentImageBlockSchema, type ContentListMembership, type ContentPageBreak, ContentPageBreakSchema, type ContentParagraph, ContentParagraphSchema, type ContentRun, ContentRunSchema, type ContentSection, ContentSectionSchema, type ContentShape, ContentShapeSchema, type ContentSlide, ContentSlideSchema, type ContentTable, type ContentTableCell, ContentTableCellSchema, type ContentTableRow, ContentTableRowSchema, ContentTableSchema, type ConversionRequest, type ConversionResult, DEFAULT_LAYOUT_FONT, type DefinedName, DefinedNameSchema, type Diagnostic, type DocumentConverter, type DocumentFormat, type DocumentPayload, type DocumentToPdfOptions, type DocxBody, DocxBytesSchema, DocxEditor, DocxParagraph, DocxRun, DocxTable, DocxTableCell, DocxTableRow, type DrawingParagraphInit, type DrawingRunInit, type EngineLayoutOptions, LAYOUT_FORMAT_VERSION, type LayoutColor, type LayoutDocument, type LayoutEllipse, type LayoutFont, type LayoutImage, type LayoutImageAsset, type LayoutItem, type LayoutLine, type LayoutLink, type LayoutMetadata, type LayoutPage, type LayoutRect, type LayoutText, type Margins, NOOP_DIAGNOSTIC_SINK, OdgBytesSchema, OdpBytesSchema, OdsBytesSchema, OdtBytesSchema, PAGE_SIZE_A4, PAGE_SIZE_LETTER, type Package, PackageSchema, type PageSize, type Part, PartSchema, PdfBytesSchema, type PdfDiagnostic, type PdfDiagnosticSeverity, type PdfDiagnosticSink, PdfEncryptedError, PdfParseError, type PdfToDocumentOptions, PptxBytesSchema, PptxEditor, PptxShape, PptxSlide, type ReadPdfOptions, type ReconstructOptions, type Relationship, SLIDE_SIZE_STANDARD, SLIDE_SIZE_WIDESCREEN, type SlideImageInit, type SlidesLayoutOptions, type TextBoxInit, type WinAnsiSubstitution, type WritePdfOptions, type XmlCdata, XmlCdataSchema, type XmlComment, XmlCommentSchema, type XmlDeclaration, XmlDeclarationSchema, type XmlElement, XmlElementSchema, type XmlNode, XmlNodeSchema, type XmlPart, XmlPartSchema, type XmlPi, XmlPiSchema, type XmlText, XmlTextSchema, attr, base64ToBytes, buildDocxPackage, buildPptxPackage, buildXml, bytesToBase64, childrenWithTag, compactCodec, compactPackageCodec, convertPresentationToLayout, convertWordprocessingToLayout, createDocx, createLocalDocumentConverter, createPptx, decodeCompactPackage, decodeEntities, decodePackage, docxPdfCodec, docxToPdf, elementsWithTag, encodeCompactPackage, encodePackage, fixedClock, flipY, fromCompact, isCompactXmlNode, isContentBlock, isXmlNode, openDocx, openPptx, packageCodec, parsePackage, parseXml, pdfCodec, pdfToDocx, pdfToPptx, pptxPdfCodec, pptxToPdf, readDocxContent, readPdf, readPptxContent, reconstructPresentation, reconstructWordprocessing, resolveRelationships, rgbHexToColor, rootElement, serializePackage, systemClock, textContent, throwIfAborted, toCompact, unzipPackage, walk, writePdf, xmlCodec, zipPackage };
|
package/dist/index.d.ts
CHANGED
|
@@ -77,6 +77,10 @@ declare function flipY(box: Box$1, containerHeightPt: number): Box$1;
|
|
|
77
77
|
declare const DocxBytesSchema: z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>;
|
|
78
78
|
declare const PptxBytesSchema: z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>;
|
|
79
79
|
declare const PdfBytesSchema: z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>;
|
|
80
|
+
declare const OdtBytesSchema: z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>;
|
|
81
|
+
declare const OdsBytesSchema: z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>;
|
|
82
|
+
declare const OdpBytesSchema: z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>;
|
|
83
|
+
declare const OdgBytesSchema: z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>;
|
|
80
84
|
//#endregion
|
|
81
85
|
//#region src/edit/docx/image.d.ts
|
|
82
86
|
interface ImageInit$1 {
|
|
@@ -570,4 +574,4 @@ declare function fixedClock(date: Date): ClockPort;
|
|
|
570
574
|
//#region src/ports/abort.d.ts
|
|
571
575
|
declare function throwIfAborted(signal: AbortSignal | undefined): void;
|
|
572
576
|
//#endregion
|
|
573
|
-
export { type Alignment, type Attribute, AttributeSchema, type BinaryPart, BinaryPartSchema, type Box, COLOR_BLACK, CONTENT_FORMAT_VERSION, type ClockPort, type Comment, CommentSchema, type CompactAttrPairs, type CompactPackage, CompactPackageSchema, type CompactPart, CompactPartSchema, type CompactXmlNode, CompactXmlNodeSchema, type ContentBlock, ContentBlockSchema, type ContentDocument, ContentDocumentSchema, type ContentImageBlock, ContentImageBlockSchema, type ContentListMembership, type ContentPageBreak, ContentPageBreakSchema, type ContentParagraph, ContentParagraphSchema, type ContentRun, ContentRunSchema, type ContentSection, ContentSectionSchema, type ContentShape, ContentShapeSchema, type ContentSlide, ContentSlideSchema, type ContentTable, type ContentTableCell, ContentTableCellSchema, type ContentTableRow, ContentTableRowSchema, ContentTableSchema, type ConversionRequest, type ConversionResult, DEFAULT_LAYOUT_FONT, type DefinedName, DefinedNameSchema, type Diagnostic, type DocumentConverter, type DocumentFormat, type DocumentPayload, type DocumentToPdfOptions, type DocxBody, DocxBytesSchema, DocxEditor, DocxParagraph, DocxRun, DocxTable, DocxTableCell, DocxTableRow, type DrawingParagraphInit, type DrawingRunInit, type EngineLayoutOptions, LAYOUT_FORMAT_VERSION, type LayoutColor, type LayoutDocument, type LayoutEllipse, type LayoutFont, type LayoutImage, type LayoutImageAsset, type LayoutItem, type LayoutLine, type LayoutLink, type LayoutMetadata, type LayoutPage, type LayoutRect, type LayoutText, type Margins, NOOP_DIAGNOSTIC_SINK, PAGE_SIZE_A4, PAGE_SIZE_LETTER, type Package, PackageSchema, type PageSize, type Part, PartSchema, PdfBytesSchema, type PdfDiagnostic, type PdfDiagnosticSeverity, type PdfDiagnosticSink, PdfEncryptedError, PdfParseError, type PdfToDocumentOptions, PptxBytesSchema, PptxEditor, PptxShape, PptxSlide, type ReadPdfOptions, type ReconstructOptions, type Relationship, SLIDE_SIZE_STANDARD, SLIDE_SIZE_WIDESCREEN, type SlideImageInit, type SlidesLayoutOptions, type TextBoxInit, type WinAnsiSubstitution, type WritePdfOptions, type XmlCdata, XmlCdataSchema, type XmlComment, XmlCommentSchema, type XmlDeclaration, XmlDeclarationSchema, type XmlElement, XmlElementSchema, type XmlNode, XmlNodeSchema, type XmlPart, XmlPartSchema, type XmlPi, XmlPiSchema, type XmlText, XmlTextSchema, attr, base64ToBytes, buildDocxPackage, buildPptxPackage, buildXml, bytesToBase64, childrenWithTag, compactCodec, compactPackageCodec, convertPresentationToLayout, convertWordprocessingToLayout, createDocx, createLocalDocumentConverter, createPptx, decodeCompactPackage, decodeEntities, decodePackage, docxPdfCodec, docxToPdf, elementsWithTag, encodeCompactPackage, encodePackage, fixedClock, flipY, fromCompact, isCompactXmlNode, isContentBlock, isXmlNode, openDocx, openPptx, packageCodec, parsePackage, parseXml, pdfCodec, pdfToDocx, pdfToPptx, pptxPdfCodec, pptxToPdf, readDocxContent, readPdf, readPptxContent, reconstructPresentation, reconstructWordprocessing, resolveRelationships, rgbHexToColor, rootElement, serializePackage, systemClock, textContent, throwIfAborted, toCompact, unzipPackage, walk, writePdf, xmlCodec, zipPackage };
|
|
577
|
+
export { type Alignment, type Attribute, AttributeSchema, type BinaryPart, BinaryPartSchema, type Box, COLOR_BLACK, CONTENT_FORMAT_VERSION, type ClockPort, type Comment, CommentSchema, type CompactAttrPairs, type CompactPackage, CompactPackageSchema, type CompactPart, CompactPartSchema, type CompactXmlNode, CompactXmlNodeSchema, type ContentBlock, ContentBlockSchema, type ContentDocument, ContentDocumentSchema, type ContentImageBlock, ContentImageBlockSchema, type ContentListMembership, type ContentPageBreak, ContentPageBreakSchema, type ContentParagraph, ContentParagraphSchema, type ContentRun, ContentRunSchema, type ContentSection, ContentSectionSchema, type ContentShape, ContentShapeSchema, type ContentSlide, ContentSlideSchema, type ContentTable, type ContentTableCell, ContentTableCellSchema, type ContentTableRow, ContentTableRowSchema, ContentTableSchema, type ConversionRequest, type ConversionResult, DEFAULT_LAYOUT_FONT, type DefinedName, DefinedNameSchema, type Diagnostic, type DocumentConverter, type DocumentFormat, type DocumentPayload, type DocumentToPdfOptions, type DocxBody, DocxBytesSchema, DocxEditor, DocxParagraph, DocxRun, DocxTable, DocxTableCell, DocxTableRow, type DrawingParagraphInit, type DrawingRunInit, type EngineLayoutOptions, LAYOUT_FORMAT_VERSION, type LayoutColor, type LayoutDocument, type LayoutEllipse, type LayoutFont, type LayoutImage, type LayoutImageAsset, type LayoutItem, type LayoutLine, type LayoutLink, type LayoutMetadata, type LayoutPage, type LayoutRect, type LayoutText, type Margins, NOOP_DIAGNOSTIC_SINK, OdgBytesSchema, OdpBytesSchema, OdsBytesSchema, OdtBytesSchema, PAGE_SIZE_A4, PAGE_SIZE_LETTER, type Package, PackageSchema, type PageSize, type Part, PartSchema, PdfBytesSchema, type PdfDiagnostic, type PdfDiagnosticSeverity, type PdfDiagnosticSink, PdfEncryptedError, PdfParseError, type PdfToDocumentOptions, PptxBytesSchema, PptxEditor, PptxShape, PptxSlide, type ReadPdfOptions, type ReconstructOptions, type Relationship, SLIDE_SIZE_STANDARD, SLIDE_SIZE_WIDESCREEN, type SlideImageInit, type SlidesLayoutOptions, type TextBoxInit, type WinAnsiSubstitution, type WritePdfOptions, type XmlCdata, XmlCdataSchema, type XmlComment, XmlCommentSchema, type XmlDeclaration, XmlDeclarationSchema, type XmlElement, XmlElementSchema, type XmlNode, XmlNodeSchema, type XmlPart, XmlPartSchema, type XmlPi, XmlPiSchema, type XmlText, XmlTextSchema, attr, base64ToBytes, buildDocxPackage, buildPptxPackage, buildXml, bytesToBase64, childrenWithTag, compactCodec, compactPackageCodec, convertPresentationToLayout, convertWordprocessingToLayout, createDocx, createLocalDocumentConverter, createPptx, decodeCompactPackage, decodeEntities, decodePackage, docxPdfCodec, docxToPdf, elementsWithTag, encodeCompactPackage, encodePackage, fixedClock, flipY, fromCompact, isCompactXmlNode, isContentBlock, isXmlNode, openDocx, openPptx, packageCodec, parsePackage, parseXml, pdfCodec, pdfToDocx, pdfToPptx, pptxPdfCodec, pptxToPdf, readDocxContent, readPdf, readPptxContent, reconstructPresentation, reconstructWordprocessing, resolveRelationships, rgbHexToColor, rootElement, serializePackage, systemClock, textContent, throwIfAborted, toCompact, unzipPackage, walk, writePdf, xmlCodec, zipPackage };
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { AttributeSchema, BinaryPartSchema, CommentSchema, CompactPackageSchema, CompactPartSchema, CompactXmlNodeSchema, DefinedNameSchema, PackageSchema, PartSchema, XmlCdataSchema, XmlCommentSchema, XmlDeclarationSchema, XmlElementSchema, XmlNodeSchema, XmlPartSchema, XmlPiSchema, XmlTextSchema, attr, attr as attr$1, base64ToBytes, base64ToBytes as base64ToBytes$1, buildXml, bytesToBase64, bytesToBase64 as bytesToBase64$1, childrenWithTag, compactCodec, compactPackageCodec, decodeCompactPackage, decodeEntities, decodePackage, decodePackage as decodePackage$1, elementsWithTag, encodeCompactPackage, encodePackage, encodePackage as encodePackage$1, fromCompact, isCompactXmlNode, isXmlNode, packageCodec, parsePackage, parseXml, readDocx, readPptx, resolveRelationships, resolveRelationships as resolveRelationships$1, rootElement, rootElement as rootElement$1, serializePackage, textContent, textContent as textContent$1, toCompact, unzipPackage, walk, xmlCodec, zipPackage } from "ooxml.js";
|
|
2
2
|
import { COLOR_BLACK, ContentBlockSchema, ContentImageBlockSchema, ContentPageBreakSchema, ContentParagraphSchema, ContentRunSchema, ContentSectionSchema, ContentSectionSchema as ContentSectionSchema$1, ContentShapeSchema, ContentSlideSchema, ContentSlideSchema as ContentSlideSchema$1, ContentTableCellSchema, ContentTableRowSchema, ContentTableSchema, DEFAULT_LAYOUT_FONT, LAYOUT_FORMAT_VERSION, LAYOUT_FORMAT_VERSION as LAYOUT_FORMAT_VERSION$1, LayoutDocumentSchema, LayoutMetadataSchema, PAGE_SIZE_A4, PAGE_SIZE_LETTER, SLIDE_SIZE_STANDARD, SLIDE_SIZE_WIDESCREEN, colorToRgbHex, isContentBlock, rgbHexToColor } from "document-content-model";
|
|
3
3
|
import { z } from "zod";
|
|
4
|
+
import { ODF_MEDIA_TYPES } from "odf.js";
|
|
4
5
|
import { Unzlib, inflateSync, unzlibSync, zlibSync } from "fflate";
|
|
5
6
|
//#region src/model/content.ts
|
|
6
7
|
const CONTENT_FORMAT_VERSION = 1;
|
|
@@ -64,6 +65,43 @@ function zipBytesSchema(label) {
|
|
|
64
65
|
const DocxBytesSchema = zipBytesSchema("docx");
|
|
65
66
|
const PptxBytesSchema = zipBytesSchema("pptx");
|
|
66
67
|
const PdfBytesSchema = z.instanceof(Uint8Array).refine((bytes) => containsBytesWithin(bytes, PDF_HEADER, PDF_HEADER_SEARCH_WINDOW), { message: "not a valid PDF file: missing the %PDF- header" });
|
|
68
|
+
const MIMETYPE_ENTRY_FILENAME = "mimetype";
|
|
69
|
+
const MIMETYPE_FILENAME_OFFSET = 30;
|
|
70
|
+
const MIMETYPE_CONTENT_OFFSET = 38;
|
|
71
|
+
const COMPRESSION_METHOD_OFFSET = 8;
|
|
72
|
+
const COMPRESSED_SIZE_OFFSET = 18;
|
|
73
|
+
function readUint16LE(bytes, offset) {
|
|
74
|
+
const b0 = bytes[offset];
|
|
75
|
+
const b1 = bytes[offset + 1];
|
|
76
|
+
if (b0 === void 0 || b1 === void 0) return;
|
|
77
|
+
return b0 | b1 << 8;
|
|
78
|
+
}
|
|
79
|
+
function readUint32LE(bytes, offset) {
|
|
80
|
+
const b0 = bytes[offset];
|
|
81
|
+
const b1 = bytes[offset + 1];
|
|
82
|
+
const b2 = bytes[offset + 2];
|
|
83
|
+
const b3 = bytes[offset + 3];
|
|
84
|
+
if (b0 === void 0 || b1 === void 0 || b2 === void 0 || b3 === void 0) return;
|
|
85
|
+
return (b0 | b1 << 8 | b2 << 16 | b3 << 24) >>> 0;
|
|
86
|
+
}
|
|
87
|
+
function readAsciiSlice(bytes, offset, length) {
|
|
88
|
+
if (bytes.length < offset + length) return;
|
|
89
|
+
return new TextDecoder().decode(bytes.subarray(offset, offset + length));
|
|
90
|
+
}
|
|
91
|
+
function hasOdfMimetypeEntry(bytes, mediaType) {
|
|
92
|
+
if (!startsWithBytes(bytes, ZIP_LOCAL_FILE_HEADER)) return false;
|
|
93
|
+
if (readUint16LE(bytes, COMPRESSION_METHOD_OFFSET) !== 0) return false;
|
|
94
|
+
if (readAsciiSlice(bytes, MIMETYPE_FILENAME_OFFSET, 8) !== MIMETYPE_ENTRY_FILENAME) return false;
|
|
95
|
+
if (readUint32LE(bytes, COMPRESSED_SIZE_OFFSET) !== mediaType.length) return false;
|
|
96
|
+
return readAsciiSlice(bytes, MIMETYPE_CONTENT_OFFSET, mediaType.length) === mediaType;
|
|
97
|
+
}
|
|
98
|
+
function odfBytesSchema(label, mediaType) {
|
|
99
|
+
return z.instanceof(Uint8Array).refine((bytes) => hasOdfMimetypeEntry(bytes, mediaType), { message: `not a valid ${label} file: the first zip entry is not a stored "mimetype" part declaring "${mediaType}"` });
|
|
100
|
+
}
|
|
101
|
+
const OdtBytesSchema = odfBytesSchema("odt", ODF_MEDIA_TYPES.odt);
|
|
102
|
+
const OdsBytesSchema = odfBytesSchema("ods", ODF_MEDIA_TYPES.ods);
|
|
103
|
+
const OdpBytesSchema = odfBytesSchema("odp", ODF_MEDIA_TYPES.odp);
|
|
104
|
+
const OdgBytesSchema = odfBytesSchema("odg", ODF_MEDIA_TYPES.odg);
|
|
67
105
|
//#endregion
|
|
68
106
|
//#region src/xml/fragment.ts
|
|
69
107
|
function el(tag, attrs = {}, children = []) {
|
|
@@ -7805,4 +7843,4 @@ function fixedClock(date) {
|
|
|
7805
7843
|
return { now: () => date };
|
|
7806
7844
|
}
|
|
7807
7845
|
//#endregion
|
|
7808
|
-
export { AttributeSchema, BinaryPartSchema, COLOR_BLACK, CONTENT_FORMAT_VERSION, CommentSchema, CompactPackageSchema, CompactPartSchema, CompactXmlNodeSchema, ContentBlockSchema, ContentDocumentSchema, ContentImageBlockSchema, ContentPageBreakSchema, ContentParagraphSchema, ContentRunSchema, ContentSectionSchema, ContentShapeSchema, ContentSlideSchema, ContentTableCellSchema, ContentTableRowSchema, ContentTableSchema, DEFAULT_LAYOUT_FONT, DefinedNameSchema, DocxBytesSchema, DocxEditor, DocxParagraph, DocxRun, DocxTable, DocxTableCell, DocxTableRow, LAYOUT_FORMAT_VERSION, NOOP_DIAGNOSTIC_SINK, PAGE_SIZE_A4, PAGE_SIZE_LETTER, PackageSchema, PartSchema, PdfBytesSchema, PdfEncryptedError, PdfParseError, PptxBytesSchema, PptxEditor, PptxShape, PptxSlide, SLIDE_SIZE_STANDARD, SLIDE_SIZE_WIDESCREEN, XmlCdataSchema, XmlCommentSchema, XmlDeclarationSchema, XmlElementSchema, XmlNodeSchema, XmlPartSchema, XmlPiSchema, XmlTextSchema, attr, base64ToBytes, buildDocxPackage, buildPptxPackage, buildXml, bytesToBase64, childrenWithTag, compactCodec, compactPackageCodec, convertPresentationToLayout, convertWordprocessingToLayout, createDocx, createLocalDocumentConverter, createPptx, decodeCompactPackage, decodeEntities, decodePackage, docxPdfCodec, docxToPdf, elementsWithTag, encodeCompactPackage, encodePackage, fixedClock, flipY, fromCompact, isCompactXmlNode, isContentBlock, isXmlNode, openDocx, openPptx, packageCodec, parsePackage, parseXml, pdfCodec, pdfToDocx, pdfToPptx, pptxPdfCodec, pptxToPdf, readDocxContent, readPdf, readPptxContent, reconstructPresentation, reconstructWordprocessing, resolveRelationships, rgbHexToColor, rootElement, serializePackage, systemClock, textContent, throwIfAborted, toCompact, unzipPackage, walk, writePdf, xmlCodec, zipPackage };
|
|
7846
|
+
export { AttributeSchema, BinaryPartSchema, COLOR_BLACK, CONTENT_FORMAT_VERSION, CommentSchema, CompactPackageSchema, CompactPartSchema, CompactXmlNodeSchema, ContentBlockSchema, ContentDocumentSchema, ContentImageBlockSchema, ContentPageBreakSchema, ContentParagraphSchema, ContentRunSchema, ContentSectionSchema, ContentShapeSchema, ContentSlideSchema, ContentTableCellSchema, ContentTableRowSchema, ContentTableSchema, DEFAULT_LAYOUT_FONT, DefinedNameSchema, DocxBytesSchema, DocxEditor, DocxParagraph, DocxRun, DocxTable, DocxTableCell, DocxTableRow, LAYOUT_FORMAT_VERSION, NOOP_DIAGNOSTIC_SINK, OdgBytesSchema, OdpBytesSchema, OdsBytesSchema, OdtBytesSchema, PAGE_SIZE_A4, PAGE_SIZE_LETTER, PackageSchema, PartSchema, PdfBytesSchema, PdfEncryptedError, PdfParseError, PptxBytesSchema, PptxEditor, PptxShape, PptxSlide, SLIDE_SIZE_STANDARD, SLIDE_SIZE_WIDESCREEN, XmlCdataSchema, XmlCommentSchema, XmlDeclarationSchema, XmlElementSchema, XmlNodeSchema, XmlPartSchema, XmlPiSchema, XmlTextSchema, attr, base64ToBytes, buildDocxPackage, buildPptxPackage, buildXml, bytesToBase64, childrenWithTag, compactCodec, compactPackageCodec, convertPresentationToLayout, convertWordprocessingToLayout, createDocx, createLocalDocumentConverter, createPptx, decodeCompactPackage, decodeEntities, decodePackage, docxPdfCodec, docxToPdf, elementsWithTag, encodeCompactPackage, encodePackage, fixedClock, flipY, fromCompact, isCompactXmlNode, isContentBlock, isXmlNode, openDocx, openPptx, packageCodec, parsePackage, parseXml, pdfCodec, pdfToDocx, pdfToPptx, pptxPdfCodec, pptxToPdf, readDocxContent, readPdf, readPptxContent, reconstructPresentation, reconstructWordprocessing, resolveRelationships, rgbHexToColor, rootElement, serializePackage, systemClock, textContent, throwIfAborted, toCompact, unzipPackage, walk, writePdf, xmlCodec, zipPackage };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "documents.js",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.36.0",
|
|
4
4
|
"description": "Bidirectional docx/pptx <-> PDF conversion and a read+write editable OOXML document model, built on ooxml.js and Zod 4 codecs.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -66,6 +66,7 @@
|
|
|
66
66
|
"dependencies": {
|
|
67
67
|
"document-content-model": "^1.1.0",
|
|
68
68
|
"fflate": "^0.8.3",
|
|
69
|
+
"odf.js": "^1.8.0",
|
|
69
70
|
"ooxml.js": "^2.1.0",
|
|
70
71
|
"zod": "^4.4.3"
|
|
71
72
|
},
|