@stll/docx-core 0.39.0 → 0.39.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,4 +1,5 @@
1
1
  import { B as finalizeParagraphFormatting, Dn as Run, E as Style, H as setDocumentBodyComments, K as BlockContent, On as RunContent, Pn as SectionProperties, Q as BreakContent, V as isCanonicallyEmptyParagraphFormatting, Vr as NumberingDefinitions, Xn as TableCell, Yn as Table, _n as PositionalTab, cr as TextContent, ct as DocumentBackground, dn as Paragraph, fn as ParagraphContent, i as Document, ir as TableRow, lt as DocumentBackgroundDrawing, o as DocxConformanceClass, r as DOCX_CONFORMANCE_CLASSES, s as DocxPackage, ut as DocumentBody } from "./document-BkGU2ctn.js";
2
+ import { TaggedErrorClass } from "better-result";
2
3
  import JSZip from "jszip";
3
4
  import { Buffer } from "node:buffer";
4
5
  //#region src/legal-source/types.d.ts
@@ -178,9 +179,9 @@ type SerializeDocumentOptions = {
178
179
  export declare const serializeDocumentToDocx: (document: Document, options?: SerializeDocumentOptions) => Promise<ArrayBuffer>;
179
180
  //#endregion
180
181
  //#region src/serialize/numericIds.d.ts
181
- declare const InvalidOoxmlNumericIdError_base: import("better-result").TaggedErrorClass<"InvalidOoxmlNumericIdError">;
182
+ declare const InvalidOoxmlNumericIdErrorBase: TaggedErrorClass<"InvalidOoxmlNumericIdError">;
182
183
  /** A writer would emit an identifier outside its OOXML schema's numeric domain. */
183
- export declare class InvalidOoxmlNumericIdError extends InvalidOoxmlNumericIdError_base<{
184
+ export declare class InvalidOoxmlNumericIdError extends InvalidOoxmlNumericIdErrorBase<{
184
185
  message: string;
185
186
  partPath: string;
186
187
  elementName: string;
@@ -260,45 +261,6 @@ export declare const serializeOnOffElement: (value: boolean | undefined, name: s
260
261
  export declare const pushOnOffElement: (parts: string[], value: boolean | undefined, name: string) => void;
261
262
  //#endregion
262
263
  //#region src/serialize/xmlEscape.d.ts
263
- /**
264
- * The one owner of XML character escaping for every part folio writes.
265
- *
266
- * Two contexts, two functions. A value going into element content takes
267
- * {@link escapeXmlText}; a value going between the quotes of an attribute
268
- * takes {@link escapeXmlAttribute}. Nothing else escapes XML by hand: a
269
- * second escaper always ends up disagreeing with this one about some
270
- * character, and the disagreement is a package Word refuses to open.
271
- *
272
- * Both functions guarantee the same contract: **the result is always legal
273
- * XML 1.0 character data.** That is what makes the contract checkable — a
274
- * caller cannot produce a corrupt part by forgetting something.
275
- *
276
- * XML 1.0 §2.2 `Char` admits tab, LF, CR, `#x20`-`#xD7FF`, `#xE000`-`#xFFFD`
277
- * and the astral planes. Everything else — the rest of C0, `#xFFFE`,
278
- * `#xFFFF`, an unpaired surrogate — cannot appear in a document at all, and
279
- * cannot be escaped into one either: `&#0;` is as illegal as a raw NUL
280
- * (§4.1 requires a character reference to refer to a legal `Char`). The only
281
- * output that is well-formed is one without them, so they are dropped here.
282
- * Callers that own an input boundary sanitise before this point, with
283
- * `sanitizeXmlCharacters`, so a user-visible value loses its illegal
284
- * characters where something can still report it; the drop below is the last
285
- * line of defence for a boundary nobody has covered yet.
286
- *
287
- * The whitespace rules are where the two contexts part:
288
- *
289
- * - §3.3.3 normalises tab, LF and CR in an **attribute value** to a space in
290
- * every conformant parser, so a literal one does not survive a save. They
291
- * are written as character references, which the same step leaves alone.
292
- * - §2.11 normalises a literal CR (and CRLF) in **content** to LF on read, so
293
- * CR is written as a reference there too. Tab and LF survive as themselves.
294
- *
295
- * Both contexts escape all five of `& < > " '`. Only `&` and `<` must be
296
- * escaped in content, but folio has always written the full set, `>` closes
297
- * the `]]>` hazard of §2.4 without a special case, and one lexical form
298
- * across every writer is worth more than the bytes it costs. Every spelling
299
- * here reads back as the character it stands for, so the rule preserves the
300
- * value whichever context it lands in.
301
- */
302
264
  /** Escape a value for XML element content. Tab and LF survive as themselves. */
303
265
  export declare const escapeXmlText: (value: string) => string;
304
266
  /**
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { T as borderStyleToken, Z as headingOutlineLevel, _t as isCanonicallyEmptyParagraphFormatting, ct as paragraphNumberingReferenceId, d as isNoteReferenceId, f as isOoxmlSymbolCharacter, gt as finalizeParagraphFormatting, k as statesNoBorder, lt as paragraphNumberingSlots, ot as paragraphNumberingLevel, r as DOCX_CONFORMANCE_CLASSES, s as MAX_REVISION_ID, st as paragraphNumberingReference, vt as setDocumentBodyComments } from "./document-oU-dz9zs.js";
2
- import { i as serializeSequenceChildren } from "./sequenceChildren-ByDxvF4j.js";
2
+ import { i as serializeSequenceChildren } from "./sequenceChildren-9SUK1Tm1.js";
3
3
  import { writeZipPart } from "./zip/writeZipPart.js";
4
4
  import { a as hasIllegalXmlCharacters, i as escapeXmlText, n as sanitizeMarkdownHref, o as sanitizeXmlCharacters, r as escapeXmlAttribute, t as sanitizeExternalUrl } from "./href-2XSCK-T8.js";
5
5
  import { Result, TaggedError, panic } from "better-result";
@@ -33,8 +33,9 @@ const ID_VALUE_ELEMENTS = /* @__PURE__ */ new Set([
33
33
  const STRING_ID_ELEMENTS = /* @__PURE__ */ new Set(["permStart", "permEnd"]);
34
34
  const MAX_UNSIGNED_ID = 4294967295;
35
35
  const MIN_SIGNED_ID = -2147483648;
36
+ const InvalidOoxmlNumericIdErrorBase = TaggedError("InvalidOoxmlNumericIdError");
36
37
  /** A writer would emit an identifier outside its OOXML schema's numeric domain. */
37
- var InvalidOoxmlNumericIdError = class extends TaggedError("InvalidOoxmlNumericIdError") {};
38
+ var InvalidOoxmlNumericIdError = class extends InvalidOoxmlNumericIdErrorBase {};
38
39
  const isValidOoxmlNumericId = (value, domain = "signed32") => {
39
40
  const spelling = String(value).trim();
40
41
  const numeric = Number(spelling);
@@ -767,7 +768,8 @@ const relationshipSource = (path) => {
767
768
  const match = /^(.*\/)?_rels\/([^/]+)\.rels$/u.exec(path);
768
769
  return match ? `${match.at(1) ?? ""}${match.at(2) ?? ""}` : null;
769
770
  };
770
- var PackageUriError = class extends TaggedError("PackageUriError") {};
771
+ const PackageUriErrorBase = TaggedError("PackageUriError");
772
+ var PackageUriError = class extends PackageUriErrorBase {};
771
773
  const resolveTarget = (source, target) => {
772
774
  const targetPath = target.split("#").at(0);
773
775
  if (!targetPath || targetPath.includes("\\") || targetPath.includes("?") || /^[a-z]+:/iu.test(targetPath)) return null;
@@ -1,5 +1,5 @@
1
1
  import { C as Relationship, D as StyleDefinitions, Dn as Run, Dt as HeaderFooter, Hr as NumberingInstance, Jn as TabContent, Jr as ParagraphFormatting, K as BlockContent, Mr as AbstractNumbering, Nn as Section, Oi as HeadingOutlineLevel, On as RunContent, Ot as HeaderFooterType, Pn as SectionProperties, Q as BreakContent, S as MediaFile, Vr as NumberingDefinitions, Y as BookmarkEnd, Yn as Table, a as DocumentSettings, dn as Paragraph, ei as TableCellFormatting, et as Comment, fn as ParagraphContent, g as ExhaustiveFields, gt as Endnote, hn as ParagraphPropertyChange, i as Document, ir as TableRow, jt as INSERTION_SEAM_POLICIES, li as TextFormatting, oi as TableRowFormatting, pn as ParagraphMarkChange, s as DocxPackage, ti as TableFormatting, ut as DocumentBody, wt as Footnote } from "../document-BkGU2ctn.js";
2
- import { Result } from "better-result";
2
+ import { Result, TaggedErrorClass } from "better-result";
3
3
  //#region src/ops/types.d.ts
4
4
  /** JSON-safe map presence, including an explicitly undefined section map. */
5
5
  type SectionMapState = {
@@ -1020,6 +1020,7 @@ type DocumentEdit = {
1020
1020
  export declare const combineEdits: (document: Document, edits: readonly DocumentEdit[]) => DocumentEdit;
1021
1021
  //#endregion
1022
1022
  //#region src/ops/refusal.d.ts
1023
+ declare const DocumentOpRefusalBase: TaggedErrorClass<"DocumentOpRefusal">;
1023
1024
  /**
1024
1025
  * Why an operation was not applied. A refused operation changes nothing: the
1025
1026
  * document it was applied to is returned as it was.
@@ -1120,9 +1121,8 @@ export declare const DOCUMENT_OP_REFUSAL_REASONS: Readonly<{
1120
1121
  }>;
1121
1122
  /** One of {@link DOCUMENT_OP_REFUSAL_REASONS}. */
1122
1123
  type DocumentOpRefusalReason = (typeof DOCUMENT_OP_REFUSAL_REASONS)[keyof typeof DOCUMENT_OP_REFUSAL_REASONS];
1123
- declare const DocumentOpRefusal_base: import("better-result").TaggedErrorClass<"DocumentOpRefusal">;
1124
1124
  /** An operation the document cannot take as stated. */
1125
- export declare class DocumentOpRefusal extends DocumentOpRefusal_base<{
1125
+ export declare class DocumentOpRefusal extends DocumentOpRefusalBase<{
1126
1126
  message: string;
1127
1127
  reason: DocumentOpRefusalReason;
1128
1128
  opType: DocumentOpType | undefined;
@@ -1644,17 +1644,7 @@ export declare function isTextOnlyRun(run: Run): boolean;
1644
1644
  * is carried over from one side by default. Naming each one here forces the
1645
1645
  * next field to state whether that default is right before it can compile.
1646
1646
  */
1647
- type MergeDecidedRunField =
1648
- /** Identical for every run. */
1649
- "type" |
1650
- /** Concatenated; see {@link mergeRunContent}. */
1651
- "content" |
1652
- /** Must be equal, and the survivor keeps it. */
1653
- "formatting" |
1654
- /** Must be equal, and the survivor keeps it. */
1655
- "preservedAttributes" |
1656
- /** Refuses the merge outright; see {@link canMergeRun}. */
1657
- "propertyChanges";
1647
+ type MergeDecidedRunField = "type" | "content" | "formatting" | "preservedAttributes" | "propertyChanges";
1658
1648
  type MergeDecidedRun = ExhaustiveFields<Run, MergeDecidedRunField>;
1659
1649
  /**
1660
1650
  * May two adjacent runs become one?
@@ -1674,9 +1664,9 @@ export declare function runsMergeable(a: MergeDecidedRun, b: MergeDecidedRun): b
1674
1664
  export declare function mergeRunContent(content1: RunContent[], content2: RunContent[]): RunContent[];
1675
1665
  //#endregion
1676
1666
  //#region src/ops/contract.d.ts
1677
- declare const DocumentOpsContractError_base: import("better-result").TaggedErrorClass<"DocumentOpsContractError">;
1667
+ declare const DocumentOpsContractErrorBase: TaggedErrorClass<"DocumentOpsContractError">;
1678
1668
  /** A document that does not meet the seed contract. */
1679
- export declare class DocumentOpsContractError extends DocumentOpsContractError_base<{
1669
+ export declare class DocumentOpsContractError extends DocumentOpsContractErrorBase<{
1680
1670
  message: string;
1681
1671
  reason: DocumentOpRefusalReason;
1682
1672
  }> {}
@@ -1793,8 +1783,8 @@ export declare const BATCH_REJECTION_REASONS: {
1793
1783
  readonly TABLE_REQUIRES_EXCLUSIVE_EDIT: "tableRequiresExclusiveEdit";
1794
1784
  };
1795
1785
  type BatchRejectionReason = (typeof BATCH_REJECTION_REASONS)[keyof typeof BATCH_REJECTION_REASONS];
1796
- declare const BatchRejection_base: import("better-result").TaggedErrorClass<"BatchRejection">;
1797
- export declare class BatchRejection extends BatchRejection_base<{
1786
+ declare const BatchRejectionBase: TaggedErrorClass<"BatchRejection">;
1787
+ export declare class BatchRejection extends BatchRejectionBase<{
1798
1788
  message: string;
1799
1789
  reason: BatchRejectionReason;
1800
1790
  opId?: string;
@@ -38,6 +38,7 @@ const derivedFields = (entries) => entries.some(([key, value]) => key === "type"
38
38
  const equalForStaleness = (left, right) => equal(left, right, derivedFields);
39
39
  //#endregion
40
40
  //#region src/ops/refusal.ts
41
+ const DocumentOpRefusalBase = TaggedError("DocumentOpRefusal");
41
42
  /**
42
43
  * Why an operation was not applied. A refused operation changes nothing: the
43
44
  * document it was applied to is returned as it was.
@@ -137,7 +138,7 @@ const DOCUMENT_OP_REFUSAL_REASONS = Object.freeze({
137
138
  EMPTY_RECORD: "emptyRecord"
138
139
  });
139
140
  /** An operation the document cannot take as stated. */
140
- var DocumentOpRefusal = class extends TaggedError("DocumentOpRefusal") {};
141
+ var DocumentOpRefusal = class extends DocumentOpRefusalBase {};
141
142
  //#endregion
142
143
  //#region src/ops/paragraphPropertySnapshot.ts
143
144
  const snapshots = /* @__PURE__ */ new WeakMap();
@@ -562,6 +563,7 @@ const replaceStoryBody = ({ document, story, body }) => {
562
563
  * wherever it sits in that tree, and a replacement rebuilds only the records
563
564
  * on the path to it, so every other block is `===` to its input.
564
565
  */
566
+ const SectionViewErrorBase = TaggedError("SectionViewError");
565
567
  const collectParagraphs = (blocks, list, out) => {
566
568
  for (const [index, block] of blocks.entries()) switch (block.type) {
567
569
  case "paragraph":
@@ -749,7 +751,7 @@ const deriveSections = (content, previous) => {
749
751
  return changed ? out : previous;
750
752
  };
751
753
  /** A section edit that cannot preserve the canonical section contract. */
752
- var SectionViewError = class extends TaggedError("SectionViewError") {};
754
+ var SectionViewError = class extends SectionViewErrorBase {};
753
755
  const sectionFailure = (message) => Result.err(new SectionViewError({
754
756
  reason: DOCUMENT_OP_REFUSAL_REASONS.SECTION_BOUNDARY,
755
757
  message
@@ -2412,8 +2414,9 @@ const removedNoteStories = (before, after) => {
2412
2414
  * so a document an operation produced is not checked again: documents are
2413
2415
  * values, never modified in place.
2414
2416
  */
2417
+ const DocumentOpsContractErrorBase = TaggedError("DocumentOpsContractError");
2415
2418
  /** A document that does not meet the seed contract. */
2416
- var DocumentOpsContractError = class extends TaggedError("DocumentOpsContractError") {};
2419
+ var DocumentOpsContractError = class extends DocumentOpsContractErrorBase {};
2417
2420
  const holdsEmptyRecord$1 = (nodes) => nodes.some((node) => isEmptyRecord(node) || holdsEmptyRecord$1(childNodes(node) ?? []));
2418
2421
  const MULTIPLE_PROPERTY_CHANGES = /* @__PURE__ */ new WeakMap();
2419
2422
  const blocksHaveMultiplePropertyChanges = (blocks) => {
@@ -15208,7 +15211,8 @@ const BATCH_REJECTION_REASONS = {
15208
15211
  INVALID_OPERATION: "invalidOperation",
15209
15212
  TABLE_REQUIRES_EXCLUSIVE_EDIT: "tableRequiresExclusiveEdit"
15210
15213
  };
15211
- var BatchRejection = class extends TaggedError("BatchRejection") {};
15214
+ const BatchRejectionBase = TaggedError("BatchRejection");
15215
+ var BatchRejection = class extends BatchRejectionBase {};
15212
15216
  /** Table edits and their structural inverses require exclusive editing until transforms exist. */
15213
15217
  const TABLE_EXCLUSIVE_OP_TYPES = {
15214
15218
  insertTable: true,
@@ -1,3 +1,4 @@
1
+ import { TaggedErrorClass } from "better-result";
1
2
  //#region src/generated/docx_kernel.d.ts
2
3
  /* tslint:disable */
3
4
  /* eslint-disable */
@@ -45,13 +46,13 @@ type DocxPackageProjectionWire = readonly [schemaVersion: 2, document: DocxProje
45
46
  type DocxProjectionContainer = "body" | "tableCell";
46
47
  //#endregion
47
48
  //#region src/projection.d.ts
48
- declare const DocxProjectionInitializationError_base: import("better-result").TaggedErrorClass<"DocxProjectionInitializationError">;
49
- export declare class DocxProjectionInitializationError extends DocxProjectionInitializationError_base<{
49
+ declare const DocxProjectionInitializationErrorBase: TaggedErrorClass<"DocxProjectionInitializationError">;
50
+ export declare class DocxProjectionInitializationError extends DocxProjectionInitializationErrorBase<{
50
51
  message: string;
51
52
  cause: unknown;
52
53
  }> {}
53
- declare const DocxProjectionError_base: import("better-result").TaggedErrorClass<"DocxProjectionError">;
54
- export declare class DocxProjectionError extends DocxProjectionError_base<{
54
+ declare const DocxProjectionErrorBase: TaggedErrorClass<"DocxProjectionError">;
55
+ export declare class DocxProjectionError extends DocxProjectionErrorBase<{
55
56
  message: string;
56
57
  cause: unknown;
57
58
  }> {}
@@ -291,8 +291,10 @@ async function __wbg_init(module_or_path) {
291
291
  }
292
292
  //#endregion
293
293
  //#region src/projection.ts
294
- var DocxProjectionInitializationError = class extends TaggedError("DocxProjectionInitializationError") {};
295
- var DocxProjectionError = class extends TaggedError("DocxProjectionError") {};
294
+ const DocxProjectionInitializationErrorBase = TaggedError("DocxProjectionInitializationError");
295
+ var DocxProjectionInitializationError = class extends DocxProjectionInitializationErrorBase {};
296
+ const DocxProjectionErrorBase = TaggedError("DocxProjectionError");
297
+ var DocxProjectionError = class extends DocxProjectionErrorBase {};
296
298
  let initialization;
297
299
  const DOCUMENT_PROJECTION_FAILURE_MESSAGE = "Could not project the DOCX document";
298
300
  const PACKAGE_PROJECTION_FAILURE_MESSAGE = "Could not project the DOCX package with review facts";
@@ -1 +1 @@
1
- export { a as SEQUENCE_CHILDREN, o as SETTINGS_CHILDREN, t as assertSafePreservedMarkup, n as isSafePreservedChildXml, r as isWithinPreservedMarkupBudget, i as serializeSequenceChildren } from "../sequenceChildren-ByDxvF4j.js";
1
+ export { a as SEQUENCE_CHILDREN, o as SETTINGS_CHILDREN, t as assertSafePreservedMarkup, n as isSafePreservedChildXml, r as isWithinPreservedMarkupBudget, i as serializeSequenceChildren } from "../sequenceChildren-9SUK1Tm1.js";
@@ -388,7 +388,8 @@ const preservedChildParser = new XMLParser({
388
388
  processEntities: false,
389
389
  htmlEntities: false
390
390
  });
391
- var InvalidPreservedChildXmlError = class extends TaggedError("InvalidPreservedChildXmlError") {};
391
+ const InvalidPreservedChildXmlErrorBase = TaggedError("InvalidPreservedChildXmlError");
392
+ var InvalidPreservedChildXmlError = class extends InvalidPreservedChildXmlErrorBase {};
392
393
  const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
393
394
  const XML_NAMESPACE_URI = "http://www.w3.org/XML/1998/namespace";
394
395
  const XMLNS_NAMESPACE_URI = "http://www.w3.org/2000/xmlns/";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stll/docx-core",
3
- "version": "0.39.0",
3
+ "version": "0.39.1",
4
4
  "description": "Typed OOXML/DOCX model, validation, serialization, legal-source compilation, and browser-native package projection.",
5
5
  "keywords": [
6
6
  "document-model",
@@ -79,7 +79,7 @@
79
79
  "dependencies": {
80
80
  "@nodable/entities": "^3.0.0",
81
81
  "@stll/docx-utils": "^0.2.0",
82
- "@stll/utf8-boundaries": "0.1.1",
82
+ "@stll/utf8-boundaries": "0.1.2",
83
83
  "better-result": "3.0.1",
84
84
  "fast-xml-parser": "^5.11.2",
85
85
  "jszip": "3.10.2",