@stll/docx-core 0.4.0 → 0.5.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.
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { Ct as
|
|
2
|
-
|
|
1
|
+
import { Ct as Run, Ht as Table, Kt as TableRow, M as DocumentBody, Ut as TableCell, Xt as TextContent, _t as Paragraph, a as DocxPackage, b as BlockContent, i as DocxConformanceClass, kt as SectionProperties, n as Document, p as Style, t as DOCX_CONFORMANCE_CLASSES, vt as ParagraphContent, w as BreakContent, wt as RunContent } from "./document-DfFH8YGu.js";
|
|
3
2
|
//#region src/legal-source/types.d.ts
|
|
4
3
|
type LegalDocumentKind = "agreement" | "letter" | "memo" | "checklist" | "pleading" | "other";
|
|
5
4
|
type LegalNumberingProfile = "legal" | "none" | "checklist";
|
|
@@ -116,7 +115,8 @@ declare const compileLegalSourceToDocx: (source: string, options?: LegalSourceCo
|
|
|
116
115
|
//#endregion
|
|
117
116
|
//#region src/serialize/docx.d.ts
|
|
118
117
|
type SerializeDocumentOptions = {
|
|
119
|
-
/** BCP-47 language tag (e.g. "en", "cs", "cs-CZ"); used for footer labels. */
|
|
118
|
+
/** BCP-47 language tag (e.g. "en", "cs", "cs-CZ"); used for footer labels. */
|
|
119
|
+
language?: string;
|
|
120
120
|
};
|
|
121
121
|
declare const serializeDocumentToDocx: (document: Document, options?: SerializeDocumentOptions) => Promise<ArrayBuffer>;
|
|
122
122
|
//#endregion
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DOCX_CONFORMANCE_CLASSES } from "./
|
|
1
|
+
import { t as DOCX_CONFORMANCE_CLASSES } from "./document-D4XHQQIj.js";
|
|
2
2
|
import JSZip from "jszip";
|
|
3
3
|
import { panic } from "better-result";
|
|
4
4
|
//#region src/serialize/xml.ts
|
|
@@ -320,9 +320,50 @@ const serializeCoreProperties = (document) => {
|
|
|
320
320
|
};
|
|
321
321
|
//#endregion
|
|
322
322
|
//#region src/validate/docx.ts
|
|
323
|
+
/**
|
|
324
|
+
* Local bounds on the ZIP archive `validateDocxPackage` inflates parts from.
|
|
325
|
+
* `docx-core` has no dependency on `@stll/folio-core`, so these mirror the
|
|
326
|
+
* shape of `packages/core/src/docx/server/boundedArchive.ts` rather than
|
|
327
|
+
* importing it: an untrusted or generator-produced buffer must be rejected
|
|
328
|
+
* for entry count and declared uncompressed size before `document.xml` /
|
|
329
|
+
* `document.xml.rels` are inflated, so a decompression-bomb entry or an
|
|
330
|
+
* archive with an excessive part count can't force an unbounded allocation.
|
|
331
|
+
*/
|
|
332
|
+
const VALIDATE_DOCX_MAX_ENTRIES = 4096;
|
|
333
|
+
const VALIDATE_DOCX_MAX_ENTRY_BYTES = 128 * 1024 * 1024;
|
|
334
|
+
const VALIDATE_DOCX_MAX_TOTAL_BYTES = 256 * 1024 * 1024;
|
|
335
|
+
const getDeclaredUncompressedSize = (file) => {
|
|
336
|
+
const metadata = file._data;
|
|
337
|
+
return typeof metadata?.uncompressedSize === "number" ? metadata.uncompressedSize : null;
|
|
338
|
+
};
|
|
339
|
+
/**
|
|
340
|
+
* Reject an archive whose entry count or declared uncompressed size (total
|
|
341
|
+
* or per-entry) exceeds the local bounds above, before any part is inflated.
|
|
342
|
+
* A declared size JSZip could not determine is skipped rather than treated
|
|
343
|
+
* as unbounded — the per-entry cap below still bounds what an inflate call
|
|
344
|
+
* can actually produce once it runs.
|
|
345
|
+
*/
|
|
346
|
+
const checkDocxArchiveBounds = (zip) => {
|
|
347
|
+
const entries = Object.values(zip.files);
|
|
348
|
+
if (entries.length > VALIDATE_DOCX_MAX_ENTRIES) return `Generated DOCX declares ${entries.length} archive entries, over the ${VALIDATE_DOCX_MAX_ENTRIES}-entry limit.`;
|
|
349
|
+
let totalUncompressedBytes = 0;
|
|
350
|
+
for (const entry of entries) {
|
|
351
|
+
const declaredBytes = getDeclaredUncompressedSize(entry);
|
|
352
|
+
if (declaredBytes === null) continue;
|
|
353
|
+
if (declaredBytes > VALIDATE_DOCX_MAX_ENTRY_BYTES) return `Generated DOCX entry "${entry.name}" declares ${declaredBytes} uncompressed bytes, over the ${VALIDATE_DOCX_MAX_ENTRY_BYTES}-byte limit.`;
|
|
354
|
+
totalUncompressedBytes += declaredBytes;
|
|
355
|
+
if (totalUncompressedBytes > VALIDATE_DOCX_MAX_TOTAL_BYTES) return `Generated DOCX declares more than ${VALIDATE_DOCX_MAX_TOTAL_BYTES} cumulative uncompressed bytes.`;
|
|
356
|
+
}
|
|
357
|
+
return null;
|
|
358
|
+
};
|
|
323
359
|
const validateDocxPackage = async (buffer) => {
|
|
324
360
|
try {
|
|
325
361
|
const zip = await JSZip.loadAsync(buffer);
|
|
362
|
+
const boundsError = checkDocxArchiveBounds(zip);
|
|
363
|
+
if (boundsError) return {
|
|
364
|
+
valid: false,
|
|
365
|
+
error: boundsError
|
|
366
|
+
};
|
|
326
367
|
for (const requiredPath of [
|
|
327
368
|
"[Content_Types].xml",
|
|
328
369
|
"_rels/.rels",
|
package/dist/model/document.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { $ as ImageTransform, $t as
|
|
2
|
-
export { type AbstractNumbering, type BlockContent, type BlockSdt, type BookmarkEnd, type BookmarkStart, type BorderSpec, type BreakContent, type CellMargins, type ColorValue, type Column, type Comment, type CommentRangeEnd, type CommentRangeStart, type CommentReference, type ComplexField, type ConditionalFormatStyle, DOCX_CONFORMANCE_CLASSES, type Deletion, type DocDefaults, Document, type DocumentBody, DocumentSettings, DocxConformanceClass, DocxPackage, type DrawingContent, type EmphasisMark, type Endnote, type EndnotePosition, type EndnoteProperties, type Field, type FieldCharContent, type FieldType, type FloatingTableProperties, type FontInfo, type FontTable, type FooterReference, type Footnote, type FootnotePosition, type FootnoteProperties, type HeaderFooter, type HeaderFooterType, type HeaderReference, type Hyperlink, type Image, type ImageCrop, type ImagePadding, type ImagePosition, type ImageSize, type ImageTransform, type ImageWrap, type InlineSdt, type Insertion, type InstrTextContent, type KnownBorderStyle, type LevelSuffix, type LineNumberRestart, type LineSpacingRule, type ListLevel, type ListRendering, type MathEquation, type MediaFile, type MoveFrom, type MoveFromRangeEnd, type MoveFromRangeStart, type MoveTo, type MoveToRangeEnd, type MoveToRangeStart, type NoBreakHyphenContent, type NoteNumberRestart, type NoteReferenceContent, type NumberFormat, type NumberingDefinitions, type NumberingInstance, type PageOrientation, type Paragraph, type ParagraphAlignment, type ParagraphContent, type ParagraphFormatting, type ParagraphMarkChange, type ParagraphPropertyChange, type PictureWatermark, type PropertyChangeInfo, type Relationship, type RelationshipMap, type RelationshipType, type Run, type RunContent, type RunPropertyChange, type SdtProperties, type SdtType, type Section, type SectionProperties, type SectionPropertyChange, type SectionStart, type ShadingProperties, type Shape, type ShapeContent, type ShapeFill, type ShapeOutline, type ShapeTextBody, type ShapeType, type SimpleField, type SoftHyphenContent, type SpacingExplicit, type Style, type StyleDefinitions, type StyleType, type SymbolContent, type TabContent, type TabLeader, type TabStop, type TabStopAlignment, type Table, type TableBorders, type TableCell, type TableCellBorders, type TableCellFormatting, type TableCellPropertyChange, type TableFormatting, type TableLook, type TableMeasurement, type TablePropertyChange, type TableRow, type TableRowFormatting, type TableRowPropertyChange, type TableStructuralChangeInfo, type TableWidthType, type TextBox, type TextContent, type TextEffect, type TextFormatting, type TextWatermark, type Theme, type ThemeColorScheme, type ThemeColorSlot, type ThemeFont, type ThemeFontScheme, type TrackedChangeInfo, type TrackedRunChange, type UnderlineStyle, type VerticalAlign, type Watermark };
|
|
1
|
+
import { $ as ImageTransform, $t as TrackedRunChange, A as ComplexField, An as TextFormatting, At as SectionPropertyChange, B as FooterReference, Bt as SymbolContent, C as BookmarkStart, Cn as TableCellFormatting, Ct as Run, D as CommentRangeEnd, Dn as TableRowFormatting, Dt as SdtType, E as Comment, En as TableMeasurement, Et as SdtProperties, F as EndnotePosition, Fn as ShadingProperties, Ft as ShapeOutline, G as HeaderFooterType, Gt as TablePropertyChange, H as FootnotePosition, Ht as Table, I as EndnoteProperties, In as ThemeColorSlot, It as ShapeTextBody, J as Image, Jt as TableStructuralChangeInfo, K as HeaderReference, Kt as TableRow, L as Field, Lt as ShapeType, M as DocumentBody, Mn as BorderSpec, Mt as Shape, N as DrawingContent, Nn as ColorValue, Nt as ShapeContent, O as CommentRangeStart, On as TableWidthType, Ot as Section, P as Endnote, Pn as KnownBorderStyle, Pt as ShapeFill, Q as ImageSize, Qt as TrackedChangeInfo, R as FieldCharContent, Rt as SimpleField, S as BookmarkEnd, Sn as TableCellBorders, St as PropertyChangeInfo, T as Column, Tn as TableLook, Tt as RunPropertyChange, U as FootnoteProperties, Ut as TableCell, V as Footnote, Vt as TabContent, W as HeaderFooter, Wt as TableCellPropertyChange, X as ImagePadding, Xt as TextContent, Y as ImageCrop, Yt as TextBox, Z as ImagePosition, Zt as TextWatermark, _ as ThemeColorScheme, _n as SpacingExplicit, _t as Paragraph, a as DocxPackage, an as ListLevel, at as MAX_REVISION_ID, b as BlockContent, bn as TabStopAlignment, bt as ParagraphPropertyChange, c as FontTable, cn as NumberingDefinitions, ct as MoveFromRangeEnd, d as RelationshipMap, dn as ConditionalFormatStyle, dt as MoveToRangeEnd, en as VerticalAlign, et as ImageWrap, f as RelationshipType, fn as EmphasisMark, ft as MoveToRangeStart, g as Theme, gn as ParagraphFormatting, gt as PageOrientation, h as StyleType, hn as ParagraphAlignment, ht as NoteReferenceContent, i as DocxConformanceClass, in as LevelSuffix, it as LineNumberRestart, j as Deletion, jn as UnderlineStyle, jt as SectionStart, k as CommentReference, kn as TextEffect, kt as SectionProperties, l as MediaFile, ln as NumberingInstance, lt as MoveFromRangeStart, m as StyleDefinitions, mn as LineSpacingRule, mt as NoteNumberRestart, n as Document, nn as normalizeRevisionId, nt as Insertion, o as DocDefaults, on as ListRendering, ot as MathEquation, p as Style, pn as FloatingTableProperties, pt as NoBreakHyphenContent, q as Hyperlink, qt as TableRowPropertyChange, r as DocumentSettings, rn as AbstractNumbering, rt as InstrTextContent, s as FontInfo, sn as NumberFormat, st as MoveFrom, t as DOCX_CONFORMANCE_CLASSES, tn as Watermark, tt as InlineSdt, u as Relationship, un as CellMargins, ut as MoveTo, v as ThemeFont, vn as TabLeader, vt as ParagraphContent, w as BreakContent, wn as TableFormatting, wt as RunContent, x as BlockSdt, xn as TableBorders, xt as PictureWatermark, y as ThemeFontScheme, yn as TabStop, yt as ParagraphMarkChange, z as FieldType, zt as SoftHyphenContent } from "../document-DfFH8YGu.js";
|
|
2
|
+
export { type AbstractNumbering, type BlockContent, type BlockSdt, type BookmarkEnd, type BookmarkStart, type BorderSpec, type BreakContent, type CellMargins, type ColorValue, type Column, type Comment, type CommentRangeEnd, type CommentRangeStart, type CommentReference, type ComplexField, type ConditionalFormatStyle, DOCX_CONFORMANCE_CLASSES, type Deletion, type DocDefaults, Document, type DocumentBody, DocumentSettings, DocxConformanceClass, DocxPackage, type DrawingContent, type EmphasisMark, type Endnote, type EndnotePosition, type EndnoteProperties, type Field, type FieldCharContent, type FieldType, type FloatingTableProperties, type FontInfo, type FontTable, type FooterReference, type Footnote, type FootnotePosition, type FootnoteProperties, type HeaderFooter, type HeaderFooterType, type HeaderReference, type Hyperlink, type Image, type ImageCrop, type ImagePadding, type ImagePosition, type ImageSize, type ImageTransform, type ImageWrap, type InlineSdt, type Insertion, type InstrTextContent, type KnownBorderStyle, type LevelSuffix, type LineNumberRestart, type LineSpacingRule, type ListLevel, type ListRendering, MAX_REVISION_ID, type MathEquation, type MediaFile, type MoveFrom, type MoveFromRangeEnd, type MoveFromRangeStart, type MoveTo, type MoveToRangeEnd, type MoveToRangeStart, type NoBreakHyphenContent, type NoteNumberRestart, type NoteReferenceContent, type NumberFormat, type NumberingDefinitions, type NumberingInstance, type PageOrientation, type Paragraph, type ParagraphAlignment, type ParagraphContent, type ParagraphFormatting, type ParagraphMarkChange, type ParagraphPropertyChange, type PictureWatermark, type PropertyChangeInfo, type Relationship, type RelationshipMap, type RelationshipType, type Run, type RunContent, type RunPropertyChange, type SdtProperties, type SdtType, type Section, type SectionProperties, type SectionPropertyChange, type SectionStart, type ShadingProperties, type Shape, type ShapeContent, type ShapeFill, type ShapeOutline, type ShapeTextBody, type ShapeType, type SimpleField, type SoftHyphenContent, type SpacingExplicit, type Style, type StyleDefinitions, type StyleType, type SymbolContent, type TabContent, type TabLeader, type TabStop, type TabStopAlignment, type Table, type TableBorders, type TableCell, type TableCellBorders, type TableCellFormatting, type TableCellPropertyChange, type TableFormatting, type TableLook, type TableMeasurement, type TablePropertyChange, type TableRow, type TableRowFormatting, type TableRowPropertyChange, type TableStructuralChangeInfo, type TableWidthType, type TextBox, type TextContent, type TextEffect, type TextFormatting, type TextWatermark, type Theme, type ThemeColorScheme, type ThemeColorSlot, type ThemeFont, type ThemeFontScheme, type TrackedChangeInfo, type TrackedRunChange, type UnderlineStyle, type VerticalAlign, type Watermark, normalizeRevisionId };
|
package/dist/model/document.js
CHANGED
|
@@ -1,9 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const DOCX_CONFORMANCE_CLASSES = Object.freeze({
|
|
4
|
-
STRICT: "strict",
|
|
5
|
-
TRANSITIONAL: "transitional",
|
|
6
|
-
UNKNOWN: "unknown"
|
|
7
|
-
});
|
|
8
|
-
//#endregion
|
|
9
|
-
export { DOCX_CONFORMANCE_CLASSES };
|
|
1
|
+
import { n as MAX_REVISION_ID, r as normalizeRevisionId, t as DOCX_CONFORMANCE_CLASSES } from "../document-D4XHQQIj.js";
|
|
2
|
+
export { DOCX_CONFORMANCE_CLASSES, MAX_REVISION_ID, normalizeRevisionId };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stll/docx-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.1",
|
|
4
4
|
"description": "Typed OOXML/DOCX document model with parsing, validation, and serialization, plus a legal-source compiler that produces DOCX packages.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"document-model",
|
|
@@ -54,12 +54,12 @@
|
|
|
54
54
|
"prepack": "bun run build"
|
|
55
55
|
},
|
|
56
56
|
"dependencies": {
|
|
57
|
-
"better-result": "2.
|
|
57
|
+
"better-result": "2.10.0",
|
|
58
58
|
"jszip": "3.10.1"
|
|
59
59
|
},
|
|
60
60
|
"devDependencies": {
|
|
61
61
|
"@types/bun": "1.3.14",
|
|
62
|
-
"tsdown": "0.22.
|
|
62
|
+
"tsdown": "0.22.9"
|
|
63
63
|
},
|
|
64
64
|
"main": "./dist/index.js",
|
|
65
65
|
"types": "./dist/index.d.ts"
|