@stll/docx-core 0.4.0 → 0.5.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.
|
@@ -907,6 +907,26 @@ type MathEquation = {
|
|
|
907
907
|
ommlXml: string; /** Plain text representation for accessibility/fallback */
|
|
908
908
|
plainText?: string;
|
|
909
909
|
};
|
|
910
|
+
/**
|
|
911
|
+
* Largest value a revision id (`w:id`) may carry: 2^31 - 1.
|
|
912
|
+
*
|
|
913
|
+
* `w:id` on `<w:ins>`/`<w:del>` comes from `CT_Markup`, typed
|
|
914
|
+
* `ST_DecimalNumber` — which ECMA-376 defines as an unbounded integer. The
|
|
915
|
+
* bound below is an implementation limit: conforming consumers read
|
|
916
|
+
* `ST_DecimalNumber` into a signed 32-bit int, and a value past this bound
|
|
917
|
+
* overflows on load and surfaces as an unreadable document. Port of
|
|
918
|
+
* eigenpal/docx-editor#1093.
|
|
919
|
+
*/
|
|
920
|
+
declare const MAX_REVISION_ID = 2147483647;
|
|
921
|
+
/**
|
|
922
|
+
* Coerce any revision id — including one parsed from an untrusted DOCX — into
|
|
923
|
+
* the range serialized `w:id` attributes may occupy.
|
|
924
|
+
*
|
|
925
|
+
* - Malformed (negative, fractional, `NaN`, `Infinity`): collapse to `0`.
|
|
926
|
+
* - Well-formed but out of range: fold modulo the range (not clamp) so a
|
|
927
|
+
* contiguous run of overflowing ids stays distinguishable.
|
|
928
|
+
*/
|
|
929
|
+
declare function normalizeRevisionId(id: number): number;
|
|
910
930
|
/**
|
|
911
931
|
* Tracked change metadata (w:ins, w:del attributes)
|
|
912
932
|
*/
|
|
@@ -914,6 +934,11 @@ type TrackedChangeInfo = {
|
|
|
914
934
|
/** Revision ID */id: number; /** Author who made the change */
|
|
915
935
|
author: string; /** Date of the change */
|
|
916
936
|
date?: string;
|
|
937
|
+
/**
|
|
938
|
+
* Author initials (w:initials). Optional attribution used by the review UI
|
|
939
|
+
* and carried through the round-trip when present on the source document.
|
|
940
|
+
*/
|
|
941
|
+
initials?: string;
|
|
917
942
|
};
|
|
918
943
|
/**
|
|
919
944
|
* Generic tracked property-change wrapper metadata (w:*PrChange)
|
|
@@ -1720,4 +1745,4 @@ type Document = {
|
|
|
1720
1745
|
warnings?: string[];
|
|
1721
1746
|
};
|
|
1722
1747
|
//#endregion
|
|
1723
|
-
export { ImageTransform as $,
|
|
1748
|
+
export { ImageTransform as $, TrackedRunChange as $t, ComplexField as A, TextFormatting as An, SectionPropertyChange as At, FooterReference as B, SymbolContent as Bt, BookmarkStart as C, TableCellFormatting as Cn, Run as Ct, CommentRangeEnd as D, TableRowFormatting as Dn, SdtType as Dt, Comment as E, TableMeasurement as En, SdtProperties as Et, EndnotePosition as F, ShadingProperties as Fn, ShapeOutline as Ft, HeaderFooterType as G, TablePropertyChange as Gt, FootnotePosition as H, Table as Ht, EndnoteProperties as I, ThemeColorSlot as In, ShapeTextBody as It, Image as J, TableStructuralChangeInfo as Jt, HeaderReference as K, TableRow as Kt, Field as L, ShapeType as Lt, DocumentBody as M, BorderSpec as Mn, Shape as Mt, DrawingContent as N, ColorValue as Nn, ShapeContent as Nt, CommentRangeStart as O, TableWidthType as On, Section as Ot, Endnote as P, KnownBorderStyle as Pn, ShapeFill as Pt, ImageSize as Q, TrackedChangeInfo as Qt, FieldCharContent as R, SimpleField as Rt, BookmarkEnd as S, TableCellBorders as Sn, PropertyChangeInfo as St, Column as T, TableLook as Tn, RunPropertyChange as Tt, FootnoteProperties as U, TableCell as Ut, Footnote as V, TabContent as Vt, HeaderFooter as W, TableCellPropertyChange as Wt, ImagePadding as X, TextContent as Xt, ImageCrop as Y, TextBox as Yt, ImagePosition as Z, TextWatermark as Zt, ThemeColorScheme as _, SpacingExplicit as _n, Paragraph as _t, DocxPackage as a, ListLevel as an, MAX_REVISION_ID as at, BlockContent as b, TabStopAlignment as bn, ParagraphPropertyChange as bt, FontTable as c, NumberingDefinitions as cn, MoveFromRangeEnd as ct, RelationshipMap as d, ConditionalFormatStyle as dn, MoveToRangeEnd as dt, VerticalAlign as en, ImageWrap as et, RelationshipType as f, EmphasisMark as fn, MoveToRangeStart as ft, Theme as g, ParagraphFormatting as gn, PageOrientation as gt, StyleType as h, ParagraphAlignment as hn, NoteReferenceContent as ht, DocxConformanceClass as i, LevelSuffix as in, LineNumberRestart as it, Deletion as j, UnderlineStyle as jn, SectionStart as jt, CommentReference as k, TextEffect as kn, SectionProperties as kt, MediaFile as l, NumberingInstance as ln, MoveFromRangeStart as lt, StyleDefinitions as m, LineSpacingRule as mn, NoteNumberRestart as mt, Document as n, normalizeRevisionId as nn, Insertion as nt, DocDefaults as o, ListRendering as on, MathEquation as ot, Style as p, FloatingTableProperties as pn, NoBreakHyphenContent as pt, Hyperlink as q, TableRowPropertyChange as qt, DocumentSettings as r, AbstractNumbering as rn, InstrTextContent as rt, FontInfo as s, NumberFormat as sn, MoveFrom as st, DOCX_CONFORMANCE_CLASSES as t, Watermark as tn, InlineSdt as tt, Relationship as u, CellMargins as un, MoveTo as ut, ThemeFont as v, TabLeader as vn, ParagraphContent as vt, BreakContent as w, TableFormatting as wn, RunContent as wt, BlockSdt as x, TableBorders as xn, PictureWatermark as xt, ThemeFontScheme as y, TabStop as yn, ParagraphMarkChange as yt, FieldType as z, SoftHyphenContent as zt };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
//#region src/model/content.ts
|
|
2
|
+
/**
|
|
3
|
+
* Largest value a revision id (`w:id`) may carry: 2^31 - 1.
|
|
4
|
+
*
|
|
5
|
+
* `w:id` on `<w:ins>`/`<w:del>` comes from `CT_Markup`, typed
|
|
6
|
+
* `ST_DecimalNumber` — which ECMA-376 defines as an unbounded integer. The
|
|
7
|
+
* bound below is an implementation limit: conforming consumers read
|
|
8
|
+
* `ST_DecimalNumber` into a signed 32-bit int, and a value past this bound
|
|
9
|
+
* overflows on load and surfaces as an unreadable document. Port of
|
|
10
|
+
* eigenpal/docx-editor#1093.
|
|
11
|
+
*/
|
|
12
|
+
const MAX_REVISION_ID = 2147483647;
|
|
13
|
+
/**
|
|
14
|
+
* Coerce any revision id — including one parsed from an untrusted DOCX — into
|
|
15
|
+
* the range serialized `w:id` attributes may occupy.
|
|
16
|
+
*
|
|
17
|
+
* - Malformed (negative, fractional, `NaN`, `Infinity`): collapse to `0`.
|
|
18
|
+
* - Well-formed but out of range: fold modulo the range (not clamp) so a
|
|
19
|
+
* contiguous run of overflowing ids stays distinguishable.
|
|
20
|
+
*/
|
|
21
|
+
function normalizeRevisionId(id) {
|
|
22
|
+
if (!Number.isInteger(id) || id < 0) return 0;
|
|
23
|
+
if (id > 2147483647) return id % 2147483648;
|
|
24
|
+
return id;
|
|
25
|
+
}
|
|
26
|
+
//#endregion
|
|
27
|
+
//#region src/model/document.ts
|
|
28
|
+
/** DOCX package conformance classes. */
|
|
29
|
+
const DOCX_CONFORMANCE_CLASSES = Object.freeze({
|
|
30
|
+
STRICT: "strict",
|
|
31
|
+
TRANSITIONAL: "transitional",
|
|
32
|
+
UNKNOWN: "unknown"
|
|
33
|
+
});
|
|
34
|
+
//#endregion
|
|
35
|
+
export { MAX_REVISION_ID as n, normalizeRevisionId as r, DOCX_CONFORMANCE_CLASSES as t };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Ct as
|
|
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-BeYAaXPa.js";
|
|
2
2
|
|
|
3
3
|
//#region src/legal-source/types.d.ts
|
|
4
4
|
type LegalDocumentKind = "agreement" | "letter" | "memo" | "checklist" | "pleading" | "other";
|
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-BeYAaXPa.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