@stll/folio-core 0.45.0 → 0.46.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.
Files changed (207) hide show
  1. package/dist/ai-edits/apply.js +59 -19
  2. package/dist/ai-edits/headless.js +1 -1
  3. package/dist/compare/compare.js +2 -5
  4. package/dist/compare/scenario.js +2 -5
  5. package/dist/compare/types.d.ts +9 -1
  6. package/dist/compare/types.js +12 -1
  7. package/dist/compat/eigenpal.d.ts +2 -1
  8. package/dist/compat/eigenpal.js +2 -1
  9. package/dist/content-controls/checkboxDisplay.d.ts +11 -0
  10. package/dist/content-controls/checkboxDisplay.js +40 -0
  11. package/dist/content-controls/findContentControls.js +3 -1
  12. package/dist/content-controls/mutateContentControls.js +17 -2
  13. package/dist/controller/contentControlWidgetController.d.ts +1 -0
  14. package/dist/controller/contentControlWidgetController.js +3 -0
  15. package/dist/controller/hiddenEditorApi.js +3 -1
  16. package/dist/controller/hiddenEditorManager.d.ts +1 -1
  17. package/dist/controller/hiddenEditorManager.js +6 -3
  18. package/dist/display-list/build/buildDisplayList.js +20 -1
  19. package/dist/display-list/build/imagePrimitives.d.ts +1 -1
  20. package/dist/display-list/build/imagePrimitives.js +3 -1
  21. package/dist/display-list/build/paragraphPrimitives.js +21 -2
  22. package/dist/display-list/dom/renderDisplayListToDom.js +10 -2
  23. package/dist/display-list/types.d.ts +17 -0
  24. package/dist/docx/attributeRemainder.d.ts +43 -0
  25. package/dist/docx/attributeRemainder.js +65 -0
  26. package/dist/docx/blockContentParser.d.ts +1 -1
  27. package/dist/docx/blockContentParser.js +87 -63
  28. package/dist/docx/blockPlainText.d.ts +3 -4
  29. package/dist/docx/blockPlainText.js +1 -0
  30. package/dist/docx/bookmarkPlacement.js +2 -0
  31. package/dist/docx/commentAnchorIndex.d.ts +30 -0
  32. package/dist/docx/commentAnchorIndex.js +50 -0
  33. package/dist/docx/commentParser.d.ts +1 -1
  34. package/dist/docx/commentParser.js +54 -37
  35. package/dist/docx/commentRangeIntegrity.d.ts +16 -1
  36. package/dist/docx/commentRangeIntegrity.js +42 -1
  37. package/dist/docx/commentRangeJoin.d.ts +9 -0
  38. package/dist/docx/commentRangeJoin.js +33 -0
  39. package/dist/docx/commentReferenceCompletion.d.ts +9 -0
  40. package/dist/docx/commentReferenceCompletion.js +47 -0
  41. package/dist/docx/commentReferenceNormalization.js +1 -0
  42. package/dist/docx/commentReplyMarkers.js +11 -19
  43. package/dist/docx/compatibility.js +1 -0
  44. package/dist/docx/containerChildren.d.ts +111 -0
  45. package/dist/docx/containerChildren.gen.d.ts +28 -0
  46. package/dist/docx/containerChildren.gen.js +246 -0
  47. package/dist/docx/containerChildren.js +103 -0
  48. package/dist/docx/documentParser.d.ts +1 -1
  49. package/dist/docx/documentParser.js +3 -3
  50. package/dist/docx/ensureParaIds.js +17 -7
  51. package/dist/docx/fieldParser.d.ts +1 -1
  52. package/dist/docx/fieldParser.js +4 -4
  53. package/dist/docx/fieldState.d.ts +26 -0
  54. package/dist/docx/fieldState.js +53 -0
  55. package/dist/docx/footnoteParser.d.ts +1 -1
  56. package/dist/docx/graphicFrameLocks.d.ts +16 -4
  57. package/dist/docx/graphicFrameLocks.js +19 -6
  58. package/dist/docx/headerFooterParser.js +1 -1
  59. package/dist/docx/headerFooterReferenceNormalization.js +1 -0
  60. package/dist/docx/hyperlinkParser.d.ts +27 -8
  61. package/dist/docx/hyperlinkParser.js +76 -18
  62. package/dist/docx/imageParser.js +33 -8
  63. package/dist/docx/inlineWrapperContent.d.ts +85 -0
  64. package/dist/docx/inlineWrapperContent.js +84 -0
  65. package/dist/docx/normalizeBaseDirection.js +10 -1
  66. package/dist/docx/paraIdAttribute.d.ts +21 -0
  67. package/dist/docx/paraIdAttribute.js +64 -0
  68. package/dist/docx/paragraphParser.d.ts +1 -1
  69. package/dist/docx/paragraphParser.js +277 -168
  70. package/dist/docx/paragraphPropertySource.js +5 -1
  71. package/dist/docx/paragraphTextBoxEnrichment.d.ts +1 -1
  72. package/dist/docx/paragraphTextBoxEnrichment.js +6 -52
  73. package/dist/docx/paragraphTraversal.js +7 -4
  74. package/dist/docx/parseWarningMessage.js +2 -1
  75. package/dist/docx/preservedRunContent.d.ts +32 -0
  76. package/dist/docx/preservedRunContent.js +86 -0
  77. package/dist/docx/renderedPageBreakNormalization.js +2 -4
  78. package/dist/docx/rezip.js +74 -18
  79. package/dist/docx/runParser.d.ts +1 -1
  80. package/dist/docx/runParser.js +16 -12
  81. package/dist/docx/sectionParser.js +8 -1
  82. package/dist/docx/selectiveXmlPatch.d.ts +46 -2
  83. package/dist/docx/selectiveXmlPatch.js +86 -39
  84. package/dist/docx/serializer/borderSerializer.js +2 -2
  85. package/dist/docx/serializer/commentSerializer.js +5 -7
  86. package/dist/docx/serializer/documentSerializer.js +8 -11
  87. package/dist/docx/serializer/headerFooterSerializer.js +7 -9
  88. package/dist/docx/serializer/noteSerializer.js +8 -8
  89. package/dist/docx/serializer/paragraphSerializer.js +76 -56
  90. package/dist/docx/serializer/runSerializer.js +25 -16
  91. package/dist/docx/serializer/sectionPropertiesSerializer.js +8 -4
  92. package/dist/docx/serializer/tableSerializer.js +18 -8
  93. package/dist/docx/server/createBilingualDocument.js +3 -1
  94. package/dist/docx/server/materializeYjsDocx.d.ts +1 -1
  95. package/dist/docx/server/materializeYjsDocx.js +9 -1
  96. package/dist/docx/server/migrateYjsAttrSchema.d.ts +55 -0
  97. package/dist/docx/server/migrateYjsAttrSchema.js +95 -0
  98. package/dist/docx/shapeParser.js +5 -5
  99. package/dist/docx/tableParser.d.ts +1 -1
  100. package/dist/docx/tableParser.js +206 -85
  101. package/dist/docx/textBoxParser.d.ts +25 -2
  102. package/dist/docx/textBoxParser.js +52 -2
  103. package/dist/docx/unzip.js +5 -4
  104. package/dist/docx/vmlImageParser.d.ts +17 -1
  105. package/dist/docx/vmlImageParser.js +17 -1
  106. package/dist/docx/xmlEncoding.d.ts +5 -0
  107. package/dist/docx/xmlEncoding.js +12 -0
  108. package/dist/docx/xmlParser.d.ts +10 -1
  109. package/dist/docx/xmlParser.js +14 -1
  110. package/dist/headless-layout.js +10 -1
  111. package/dist/index.d.ts +2 -1
  112. package/dist/index.js +2 -1
  113. package/dist/internal/pageBreakRunSourceDescendantIndex.js +5 -2
  114. package/dist/layout-bridge/convert/toFlowBlocks.js +102 -12
  115. package/dist/layout-engine/measure/tableCellFloating.d.ts +2 -0
  116. package/dist/layout-engine/measure/tableCellFloating.js +2 -0
  117. package/dist/layout-engine/types.d.ts +23 -1
  118. package/dist/layout-painter/renderImage.d.ts +5 -1
  119. package/dist/layout-painter/renderImage.js +10 -3
  120. package/dist/layout-painter/renderPage.d.ts +2 -0
  121. package/dist/layout-painter/renderPage.js +4 -0
  122. package/dist/layout-painter/renderParagraph.d.ts +13 -1
  123. package/dist/layout-painter/renderParagraph.js +22 -3
  124. package/dist/managers/autoSaveCodec.d.ts +9 -1
  125. package/dist/managers/autoSaveCodec.js +12 -4
  126. package/dist/markdown/renderBlock.js +1 -0
  127. package/dist/markdown/renderRuns.d.ts +1 -1
  128. package/dist/markdown/renderRuns.js +28 -5
  129. package/dist/markdown/renderTable.js +22 -5
  130. package/dist/markdown/trailers.js +4 -1
  131. package/dist/pdf/images.js +142 -6
  132. package/dist/prosemirror/attrs/index.d.ts +14 -3
  133. package/dist/prosemirror/attrs/index.js +155 -2
  134. package/dist/prosemirror/authoredTransformAttrs.d.ts +28 -0
  135. package/dist/prosemirror/authoredTransformAttrs.js +64 -0
  136. package/dist/prosemirror/commands/contentControls.js +10 -2
  137. package/dist/prosemirror/commands/image.d.ts +9 -2
  138. package/dist/prosemirror/commands/image.js +42 -28
  139. package/dist/prosemirror/commands/pageBreak.js +1 -1
  140. package/dist/prosemirror/commentReferenceAttrs.d.ts +8 -0
  141. package/dist/prosemirror/commentReferenceAttrs.js +33 -0
  142. package/dist/prosemirror/commentReferenceIntegrity.d.ts +47 -0
  143. package/dist/prosemirror/commentReferenceIntegrity.js +43 -0
  144. package/dist/prosemirror/conversion/fromProseDoc.d.ts +2 -13
  145. package/dist/prosemirror/conversion/fromProseDoc.js +269 -70
  146. package/dist/prosemirror/conversion/index.d.ts +2 -2
  147. package/dist/prosemirror/conversion/toProseDoc.d.ts +7 -9
  148. package/dist/prosemirror/conversion/toProseDoc.js +468 -308
  149. package/dist/prosemirror/extensions/StarterKit.js +8 -58
  150. package/dist/prosemirror/extensions/core/DocExtension.js +1 -1
  151. package/dist/prosemirror/extensions/core/ParagraphExtension.js +2 -1
  152. package/dist/prosemirror/extensions/features/BaseKeymapExtension.js +45 -27
  153. package/dist/prosemirror/extensions/features/EmptyParagraphFormatExtension.js +3 -1
  154. package/dist/prosemirror/extensions/features/ImagePasteExtension.js +5 -3
  155. package/dist/prosemirror/extensions/features/ParaIdAllocatorExtension.js +1 -0
  156. package/dist/prosemirror/extensions/markRegistry.d.ts +41 -0
  157. package/dist/prosemirror/extensions/markRegistry.js +75 -0
  158. package/dist/prosemirror/extensions/marks/InlineWrapperExtension.d.ts +18 -0
  159. package/dist/prosemirror/extensions/marks/InlineWrapperExtension.js +63 -0
  160. package/dist/prosemirror/extensions/marks/markUtils.d.ts +2 -1
  161. package/dist/prosemirror/extensions/marks/markUtils.js +47 -4
  162. package/dist/prosemirror/extensions/nodes/CommentReferenceExtension.d.ts +11 -0
  163. package/dist/prosemirror/extensions/nodes/CommentReferenceExtension.js +87 -0
  164. package/dist/prosemirror/extensions/nodes/FieldExtension.js +9 -7
  165. package/dist/prosemirror/extensions/nodes/ImageExtension.js +16 -0
  166. package/dist/prosemirror/extensions/nodes/PreservedBlockExtension.d.ts +32 -0
  167. package/dist/prosemirror/extensions/nodes/PreservedBlockExtension.js +67 -0
  168. package/dist/prosemirror/extensions/nodes/PreservedXmlExtension.d.ts +16 -0
  169. package/dist/prosemirror/extensions/nodes/PreservedXmlExtension.js +60 -0
  170. package/dist/prosemirror/extensions/nodes/ShapeExtension.js +3 -0
  171. package/dist/prosemirror/extensions/nodes/TableExtension.js +3 -2
  172. package/dist/prosemirror/extensions/nodes/TextBoxExtension.js +5 -1
  173. package/dist/prosemirror/inlineWrapperStack.d.ts +39 -0
  174. package/dist/prosemirror/inlineWrapperStack.js +75 -0
  175. package/dist/prosemirror/pageBreakRunProjection.d.ts +17 -7
  176. package/dist/prosemirror/pageBreakRunProjection.js +19 -9
  177. package/dist/prosemirror/replacedAnnotations.d.ts +59 -0
  178. package/dist/prosemirror/replacedAnnotations.js +165 -0
  179. package/dist/prosemirror/runFormattingInlineCarriers.d.ts +3 -1
  180. package/dist/prosemirror/runFormattingInlineCarriers.js +5 -1
  181. package/dist/prosemirror/schema/index.d.ts +3 -3
  182. package/dist/prosemirror/schema/marks.d.ts +25 -1
  183. package/dist/prosemirror/schema/nodes.d.ts +90 -3
  184. package/dist/prosemirror/schema/nodes.js +16 -1
  185. package/dist/prosemirror/trackedRunInlineAtoms.d.ts +2 -0
  186. package/dist/prosemirror/trackedRunInlineAtoms.js +2 -0
  187. package/dist/prosemirror/validation.js +16 -2
  188. package/dist/prosemirror/yjsDocumentMetadata.d.ts +73 -0
  189. package/dist/prosemirror/yjsDocumentMetadata.js +171 -0
  190. package/dist/prosemirror/zeroWidthAnchors.js +2 -0
  191. package/dist/render-dom/commentAnchorAttributes.d.ts +37 -0
  192. package/dist/render-dom/commentAnchorAttributes.js +54 -0
  193. package/dist/server.d.ts +3 -1
  194. package/dist/server.js +3 -1
  195. package/dist/types/content.d.ts +2 -2
  196. package/dist/utils/clipboard.d.ts +9 -1
  197. package/dist/utils/clipboard.js +27 -1
  198. package/dist/utils/findReplace.js +1 -1
  199. package/dist/utils/imageLuminance.d.ts +15 -0
  200. package/dist/utils/imageLuminance.js +32 -0
  201. package/dist/utils/mergeDocumentContent.js +7 -17
  202. package/dist/utils/replaceText.js +1 -0
  203. package/package.json +2 -2
  204. package/dist/docx/blockRangeMarkers.d.ts +0 -36
  205. package/dist/docx/blockRangeMarkers.js +0 -59
  206. package/dist/prosemirror/yjsParagraphSourceContract.d.ts +0 -9
  207. package/dist/prosemirror/yjsParagraphSourceContract.js +0 -26
@@ -0,0 +1,73 @@
1
+ import { Node } from "prosemirror-model";
2
+ import { Result } from "better-result";
3
+ import * as Y from "yjs";
4
+ //#region src/prosemirror/yjsDocumentMetadata.d.ts
5
+ /**
6
+ * Carry a snapshot written under `version` forward to the next version,
7
+ * rewriting the fragment in place and answering how many paragraphs changed.
8
+ */
9
+ type AttrSchemaMigrationStep = (fragment: Y.XmlFragment) => number;
10
+ /** Every attr-schema version this build reads, oldest first, with no gaps. */
11
+ declare const FOLIO_YJS_ATTR_SCHEMA_VERSIONS: readonly [0, 1, 2, 3];
12
+ /** An attr-schema version this build can read. */
13
+ type FolioYjsAttrSchemaVersion = (typeof FOLIO_YJS_ATTR_SCHEMA_VERSIONS)[number];
14
+ /**
15
+ * The attr-schema version this build writes. Derived against the migration map
16
+ * so the constant and the map cannot disagree.
17
+ */
18
+ declare const FOLIO_YJS_ATTR_SCHEMA_VERSION = 3;
19
+ /**
20
+ * The steps that carry a snapshot written under `fromVersion` up to
21
+ * {@link FOLIO_YJS_ATTR_SCHEMA_VERSION}, in order. Empty when the snapshot is
22
+ * already current.
23
+ */
24
+ declare const attrSchemaMigrationSteps: (fromVersion: FolioYjsAttrSchemaVersion) => readonly AttrSchemaMigrationStep[];
25
+ /**
26
+ * Carry a fragment this build is about to read or write up to the attr shape
27
+ * this build writes, and stamp the marker.
28
+ *
29
+ * Every entry point that hands a fragment to `initProseMirrorDoc` calls this,
30
+ * for two reasons that are the same reason. A step that rewrites values has to
31
+ * run before a node is built from them, or the build reads the old shape as
32
+ * the new one. And the marker has to say what the fragment may now hold before
33
+ * the first edit writes an attr of this build's shape into it, because an
34
+ * older build reading an unmarked snapshot drops what it does not know without
35
+ * a trace.
36
+ *
37
+ * Returns how many elements the steps rewrote.
38
+ */
39
+ declare const applyAttrSchemaMigrations: (ydoc: Y.Doc, fragment: Y.XmlFragment, fromVersion: FolioYjsAttrSchemaVersion) => number;
40
+ declare const FolioYjsAttrSchemaVersionError_base: import("better-result").TaggedErrorClass<"FolioYjsAttrSchemaVersionError">;
41
+ /** Raised when a snapshot's attr-schema marker is ahead of the running code. */
42
+ declare class FolioYjsAttrSchemaVersionError extends FolioYjsAttrSchemaVersionError_base<{
43
+ message: string;
44
+ /** The marker exactly as stored, so the host can log what it refused. */
45
+ marker: unknown;
46
+ /** The newest attr-schema version this build understands. */
47
+ supportedVersion: FolioYjsAttrSchemaVersion;
48
+ }> {}
49
+ /**
50
+ * The attr-schema version a collaboration document was written under.
51
+ *
52
+ * An absent marker is version 0: every snapshot predates the marker, so no
53
+ * backfill is needed to classify one. An older version loads, because
54
+ * {@link attrSchemaMigrationSteps} says what it means. A marker this
55
+ * build does not know is a snapshot written by newer code, and reading it would
56
+ * be a silent misread: ProseMirror copies unknown attr values into the node
57
+ * verbatim and drops unknown keys without a trace. It fails instead.
58
+ */
59
+ declare const readYjsAttrSchemaVersion: (ydoc: Y.Doc) => Result<FolioYjsAttrSchemaVersion, FolioYjsAttrSchemaVersionError>;
60
+ declare const proseDocumentParagraphSourceContract: (document: Node) => string | null;
61
+ /** Stamp the attr-schema version of the build that wrote the current fragment. */
62
+ declare const writeYjsAttrSchemaVersion: (ydoc: Y.Doc) => void;
63
+ /**
64
+ * Write both metadata bindings for a freshly seeded collaboration document.
65
+ * The attr-schema version is written unconditionally; the paragraph-source
66
+ * contract only when the seeding document carries one, because a document
67
+ * built in memory rather than parsed from a package has no source to bind to.
68
+ */
69
+ declare const writeYjsDocumentMetadata: (ydoc: Y.Doc, document: Node) => void;
70
+ declare const readYjsParagraphSourceContract: (ydoc: Y.Doc) => string | null;
71
+ declare const withParagraphSourceContract: (document: Node, contract: string) => Node;
72
+ //#endregion
73
+ export { FOLIO_YJS_ATTR_SCHEMA_VERSION, FolioYjsAttrSchemaVersion, FolioYjsAttrSchemaVersionError, applyAttrSchemaMigrations, attrSchemaMigrationSteps, proseDocumentParagraphSourceContract, readYjsAttrSchemaVersion, readYjsParagraphSourceContract, withParagraphSourceContract, writeYjsAttrSchemaVersion, writeYjsDocumentMetadata };
@@ -0,0 +1,171 @@
1
+ import { PROSE_PARAGRAPH_SOURCE_CONTRACT_ATTR, getProseDocumentParagraphPropertySourceContract } from "../docx/paragraphPropertySource.js";
2
+ import { Result, TaggedError, panic } from "better-result";
3
+ //#region src/prosemirror/yjsDocumentMetadata.ts
4
+ /**
5
+ * Folio's own keys inside a collaboration document: one map, two independent
6
+ * bindings.
7
+ *
8
+ * `paragraphSourceContract` binds the snapshot to the exact bytes of the DOCX
9
+ * it was seeded from. `attrSchemaVersion` binds it to the shape of the node
10
+ * attrs Folio persists. A snapshot can be current on one and stale on the
11
+ * other, so neither key may be derived from the other.
12
+ */
13
+ const FOLIO_YJS_METADATA_MAP_NAME = "folio:document-metadata";
14
+ const PARAGRAPH_SOURCE_CONTRACT_KEY = "paragraphSourceContract";
15
+ const ATTR_SCHEMA_VERSION_KEY = "attrSchemaVersion";
16
+ /**
17
+ * Version 0 is every snapshot written before the marker existed. The marker
18
+ * shipped without changing a single attr, so carrying a v0 snapshot to v1 is
19
+ * the identity: it only stamps the key.
20
+ */
21
+ const stampMarkerOnly = () => 0;
22
+ /** The node types whose `fldLock` and `dirty` attrs version 2 rewrites. */
23
+ const FIELD_ELEMENT_NAMES = /* @__PURE__ */ new Set(["field", "structuredField"]);
24
+ const STATED_FLAG_ATTRS = ["fldLock", "dirty"];
25
+ /**
26
+ * Version 1 stored `fldLock` and `dirty` as booleans defaulting to `false`,
27
+ * because the reader that filled them tested `=== true`. A field that authored
28
+ * an explicit `w:fldLock="0"` and one that authored nothing were both stored as
29
+ * `false`, so `false` never meant an explicit off and cannot be kept as one now
30
+ * that `null` is the absence: a v1 snapshot's `false` would start writing an
31
+ * attribute the document never carried.
32
+ */
33
+ const dropUnstatedFieldFlags = (fragment) => {
34
+ let rewritten = 0;
35
+ const visit = (node) => {
36
+ if ("nodeName" in node && FIELD_ELEMENT_NAMES.has(node.nodeName)) {
37
+ const attributes = node.getAttributes();
38
+ let changed = false;
39
+ for (const attr of STATED_FLAG_ATTRS) if (attributes[attr] === false) {
40
+ node.removeAttribute(attr);
41
+ changed = true;
42
+ }
43
+ if (changed) rewritten += 1;
44
+ }
45
+ for (const child of node.toArray()) if (typeof child !== "string" && "toArray" in child) visit(child);
46
+ };
47
+ visit(fragment);
48
+ return rewritten;
49
+ };
50
+ /**
51
+ * Version 3 adds `docxRotation`, `docxFlipH` and `docxFlipV` to the drawing
52
+ * nodes. A v2 snapshot states none of them, and `readAuthoredTransform` reads
53
+ * such a node from its `transform` CSS, which is the only record it ever had,
54
+ * so nothing has to be rewritten. The marker still moves: a v3 snapshot read
55
+ * by a v2 build would have the three attrs dropped without a trace.
56
+ */
57
+ const drawingTransformAttrsAreAdditive = () => 0;
58
+ /** Every attr-schema version this build reads, oldest first, with no gaps. */
59
+ const FOLIO_YJS_ATTR_SCHEMA_VERSIONS = [
60
+ 0,
61
+ 1,
62
+ 2,
63
+ 3
64
+ ];
65
+ /**
66
+ * The one place a persisted attr-shape change is decided.
67
+ *
68
+ * Changing the shape of any node or mark attr Folio persists means: append the
69
+ * new version to {@link FOLIO_YJS_ATTR_SCHEMA_VERSIONS}, map the previous
70
+ * version to the step that rewrites it, and map the new version to `"current"`.
71
+ * The map is total over the version union, so a version added without a
72
+ * decision does not compile, and `migrateFolioYjsSnapshot` picks the new step
73
+ * up without being touched.
74
+ */
75
+ const ATTR_SCHEMA_MIGRATIONS = {
76
+ 0: stampMarkerOnly,
77
+ 1: dropUnstatedFieldFlags,
78
+ 2: drawingTransformAttrsAreAdditive,
79
+ 3: "current"
80
+ };
81
+ /**
82
+ * The attr-schema version this build writes. Derived against the migration map
83
+ * so the constant and the map cannot disagree.
84
+ */
85
+ const FOLIO_YJS_ATTR_SCHEMA_VERSION = 3;
86
+ /**
87
+ * The steps that carry a snapshot written under `fromVersion` up to
88
+ * {@link FOLIO_YJS_ATTR_SCHEMA_VERSION}, in order. Empty when the snapshot is
89
+ * already current.
90
+ */
91
+ const attrSchemaMigrationSteps = (fromVersion) => FOLIO_YJS_ATTR_SCHEMA_VERSIONS.filter((version) => version >= fromVersion).flatMap((version) => {
92
+ const step = ATTR_SCHEMA_MIGRATIONS[version];
93
+ return step === "current" ? [] : [step];
94
+ });
95
+ /**
96
+ * Carry a fragment this build is about to read or write up to the attr shape
97
+ * this build writes, and stamp the marker.
98
+ *
99
+ * Every entry point that hands a fragment to `initProseMirrorDoc` calls this,
100
+ * for two reasons that are the same reason. A step that rewrites values has to
101
+ * run before a node is built from them, or the build reads the old shape as
102
+ * the new one. And the marker has to say what the fragment may now hold before
103
+ * the first edit writes an attr of this build's shape into it, because an
104
+ * older build reading an unmarked snapshot drops what it does not know without
105
+ * a trace.
106
+ *
107
+ * Returns how many elements the steps rewrote.
108
+ */
109
+ const applyAttrSchemaMigrations = (ydoc, fragment, fromVersion) => {
110
+ if (fromVersion === 3) return 0;
111
+ let rewritten = 0;
112
+ ydoc.transact(() => {
113
+ for (const step of attrSchemaMigrationSteps(fromVersion)) rewritten += step(fragment);
114
+ writeYjsAttrSchemaVersion(ydoc);
115
+ });
116
+ return rewritten;
117
+ };
118
+ /** Raised when a snapshot's attr-schema marker is ahead of the running code. */
119
+ var FolioYjsAttrSchemaVersionError = class extends TaggedError("FolioYjsAttrSchemaVersionError") {};
120
+ const isReadableVersion = (marker) => typeof marker === "number" && Number.isInteger(marker) && marker >= 0 && marker <= 3;
121
+ /**
122
+ * The attr-schema version a collaboration document was written under.
123
+ *
124
+ * An absent marker is version 0: every snapshot predates the marker, so no
125
+ * backfill is needed to classify one. An older version loads, because
126
+ * {@link attrSchemaMigrationSteps} says what it means. A marker this
127
+ * build does not know is a snapshot written by newer code, and reading it would
128
+ * be a silent misread: ProseMirror copies unknown attr values into the node
129
+ * verbatim and drops unknown keys without a trace. It fails instead.
130
+ */
131
+ const readYjsAttrSchemaVersion = (ydoc) => {
132
+ const marker = ydoc.getMap(FOLIO_YJS_METADATA_MAP_NAME).get(ATTR_SCHEMA_VERSION_KEY);
133
+ if (marker === void 0) return Result.ok(0);
134
+ if (isReadableVersion(marker)) return Result.ok(marker);
135
+ return Result.err(new FolioYjsAttrSchemaVersionError({
136
+ marker,
137
+ message: "The collaboration snapshot was written by a newer Folio attr schema than this build reads.",
138
+ supportedVersion: 3
139
+ }));
140
+ };
141
+ const proseDocumentParagraphSourceContract = (document) => {
142
+ return getProseDocumentParagraphPropertySourceContract(document);
143
+ };
144
+ /** Stamp the attr-schema version of the build that wrote the current fragment. */
145
+ const writeYjsAttrSchemaVersion = (ydoc) => {
146
+ ydoc.getMap(FOLIO_YJS_METADATA_MAP_NAME).set(ATTR_SCHEMA_VERSION_KEY, 3);
147
+ };
148
+ /**
149
+ * Write both metadata bindings for a freshly seeded collaboration document.
150
+ * The attr-schema version is written unconditionally; the paragraph-source
151
+ * contract only when the seeding document carries one, because a document
152
+ * built in memory rather than parsed from a package has no source to bind to.
153
+ */
154
+ const writeYjsDocumentMetadata = (ydoc, document) => {
155
+ writeYjsAttrSchemaVersion(ydoc);
156
+ const contract = proseDocumentParagraphSourceContract(document);
157
+ if (contract) ydoc.getMap(FOLIO_YJS_METADATA_MAP_NAME).set(PARAGRAPH_SOURCE_CONTRACT_KEY, contract);
158
+ };
159
+ const readYjsParagraphSourceContract = (ydoc) => {
160
+ const contract = ydoc.getMap(FOLIO_YJS_METADATA_MAP_NAME).get(PARAGRAPH_SOURCE_CONTRACT_KEY);
161
+ return typeof contract === "string" ? contract : null;
162
+ };
163
+ const withParagraphSourceContract = (document, contract) => {
164
+ if (document.type.name !== "doc") panic("A paragraph-property source contract can only attach to a document node");
165
+ return document.type.create({
166
+ ...document.attrs,
167
+ [PROSE_PARAGRAPH_SOURCE_CONTRACT_ATTR]: contract
168
+ }, document.content, document.marks);
169
+ };
170
+ //#endregion
171
+ export { FOLIO_YJS_ATTR_SCHEMA_VERSION, FolioYjsAttrSchemaVersionError, applyAttrSchemaMigrations, attrSchemaMigrationSteps, proseDocumentParagraphSourceContract, readYjsAttrSchemaVersion, readYjsParagraphSourceContract, withParagraphSourceContract, writeYjsAttrSchemaVersion, writeYjsDocumentMetadata };
@@ -1,9 +1,11 @@
1
1
  import { BOOKMARK_BOUNDARY_NODE_NAME } from "./extensions/nodes/BookmarkBoundaryExtension.js";
2
+ import { COMMENT_REFERENCE_NODE_NAME } from "./extensions/nodes/CommentReferenceExtension.js";
2
3
  import { RENDERED_PAGE_BREAK_NODE_NAME } from "./extensions/nodes/RenderedPageBreakExtension.js";
3
4
  import { TEXT_BOX_ANCHOR_NODE_NAME } from "./extensions/nodes/TextBoxAnchorExtension.js";
4
5
  //#region src/prosemirror/zeroWidthAnchors.ts
5
6
  const ZERO_WIDTH_ANCHOR_NODE_NAMES = /* @__PURE__ */ new Set([
6
7
  BOOKMARK_BOUNDARY_NODE_NAME,
8
+ COMMENT_REFERENCE_NODE_NAME,
7
9
  RENDERED_PAGE_BREAK_NODE_NAME,
8
10
  TEXT_BOX_ANCHOR_NODE_NAME
9
11
  ]);
@@ -0,0 +1,37 @@
1
+ //#region src/render-dom/commentAnchorAttributes.d.ts
2
+ /**
3
+ * How a painted run advertises which comments it sits inside.
4
+ *
5
+ * Comment ranges overlap: a run covered by two `w:commentRangeStart` /
6
+ * `w:commentRangeEnd` pairs belongs to both, and hover styling, the active
7
+ * highlight and the sidebar anchor all have to see both memberships.
8
+ *
9
+ * `data-comment-id` carries the first id, which is what every existing reader
10
+ * scrolls to and what keeps a single-range run's DOM exactly as the painter
11
+ * emitted it before. `data-comment-ids` carries the whole membership and is
12
+ * written only when there is more than one id. Readers ask through the
13
+ * helpers here instead of reading either attribute, so the two spellings
14
+ * cannot come to answer differently.
15
+ */
16
+ /** The painted anchors inside a container, whichever comment they belong to. */
17
+ declare const COMMENT_ANCHOR_SELECTOR = "[data-comment-id]";
18
+ /** What a painter, a reader and their test fakes all offer. */
19
+ type CommentAnchor = {
20
+ dataset: Record<string, string | undefined>;
21
+ };
22
+ /** Record the comments a painted run sits inside. */
23
+ declare const writeCommentAnchorIds: (element: CommentAnchor, commentIds: readonly number[]) => void;
24
+ /** Every comment id a painted anchor sits inside, first id first. */
25
+ declare const commentAnchorIds: (element: CommentAnchor) => readonly string[];
26
+ /**
27
+ * Selector for every painted anchor inside one comment, optionally scoped.
28
+ *
29
+ * `comment.id` is typed as a number, but a controlled `comments` prop supplied
30
+ * by the host app is not runtime-checked, so the value is escaped before it is
31
+ * spliced into the selector.
32
+ */
33
+ declare const commentAnchorSelector: (id: string | number, scope?: string) => string;
34
+ /** First painted anchor per comment id, in one pass over `container`. */
35
+ declare const indexCommentAnchors: (container: ParentNode) => Map<string, HTMLElement>;
36
+ //#endregion
37
+ export { COMMENT_ANCHOR_SELECTOR, commentAnchorIds, commentAnchorSelector, indexCommentAnchors, writeCommentAnchorIds };
@@ -0,0 +1,54 @@
1
+ //#region src/render-dom/commentAnchorAttributes.ts
2
+ /**
3
+ * How a painted run advertises which comments it sits inside.
4
+ *
5
+ * Comment ranges overlap: a run covered by two `w:commentRangeStart` /
6
+ * `w:commentRangeEnd` pairs belongs to both, and hover styling, the active
7
+ * highlight and the sidebar anchor all have to see both memberships.
8
+ *
9
+ * `data-comment-id` carries the first id, which is what every existing reader
10
+ * scrolls to and what keeps a single-range run's DOM exactly as the painter
11
+ * emitted it before. `data-comment-ids` carries the whole membership and is
12
+ * written only when there is more than one id. Readers ask through the
13
+ * helpers here instead of reading either attribute, so the two spellings
14
+ * cannot come to answer differently.
15
+ */
16
+ /** Attribute carrying the run's first comment id. */
17
+ const PRIMARY_ATTRIBUTE = "data-comment-id";
18
+ /** Attribute carrying every comment id the run is inside, space separated. */
19
+ const MEMBERSHIP_ATTRIBUTE = "data-comment-ids";
20
+ /** The painted anchors inside a container, whichever comment they belong to. */
21
+ const COMMENT_ANCHOR_SELECTOR = `[${PRIMARY_ATTRIBUTE}]`;
22
+ /** Record the comments a painted run sits inside. */
23
+ const writeCommentAnchorIds = (element, commentIds) => {
24
+ const primary = commentIds.at(0);
25
+ if (primary === void 0) return;
26
+ element.dataset["commentId"] = String(primary);
27
+ if (commentIds.length > 1) element.dataset["commentIds"] = commentIds.join(" ");
28
+ };
29
+ /** Every comment id a painted anchor sits inside, first id first. */
30
+ const commentAnchorIds = (element) => {
31
+ const membership = element.dataset["commentIds"];
32
+ if (membership !== void 0 && membership.length > 0) return membership.split(" ");
33
+ const primary = element.dataset["commentId"];
34
+ return primary === void 0 || primary.length === 0 ? [] : [primary];
35
+ };
36
+ /**
37
+ * Selector for every painted anchor inside one comment, optionally scoped.
38
+ *
39
+ * `comment.id` is typed as a number, but a controlled `comments` prop supplied
40
+ * by the host app is not runtime-checked, so the value is escaped before it is
41
+ * spliced into the selector.
42
+ */
43
+ const commentAnchorSelector = (id, scope = "") => {
44
+ const value = CSS.escape(String(id));
45
+ return `${scope}[${PRIMARY_ATTRIBUTE}="${value}"], ${scope}[${MEMBERSHIP_ATTRIBUTE}~="${value}"]`;
46
+ };
47
+ /** First painted anchor per comment id, in one pass over `container`. */
48
+ const indexCommentAnchors = (container) => {
49
+ const anchors = /* @__PURE__ */ new Map();
50
+ for (const element of container.querySelectorAll(COMMENT_ANCHOR_SELECTOR)) for (const id of commentAnchorIds(element)) if (!anchors.has(id)) anchors.set(id, element);
51
+ return anchors;
52
+ };
53
+ //#endregion
54
+ export { COMMENT_ANCHOR_SELECTOR, commentAnchorIds, commentAnchorSelector, indexCommentAnchors, writeCommentAnchorIds };
package/dist/server.d.ts CHANGED
@@ -11,6 +11,7 @@ import { CreateEmptyDocumentOptions, createEmptyDocument } from "./utils/createD
11
11
  import { DocumentStyleCatalog, DocumentStyleCatalogEntry, ExtractDocumentStyleSetOptions, extractDocumentStyleSet, extractDocumentStyleSetFromDocx, inspectDocumentStyles, inspectDocumentStylesFromDocx } from "./style-sets/extract.js";
12
12
  import { STELLA_STYLE_SET_NAME, createStellaStyleDocumentPreset, createStellaStyleSet } from "./style-sets/stellaStyle.js";
13
13
  import { DocumentPropertiesOptions, createDocx } from "./docx/rezip.js";
14
+ import { FOLIO_YJS_ATTR_SCHEMA_VERSION, FolioYjsAttrSchemaVersion, FolioYjsAttrSchemaVersionError } from "./prosemirror/yjsDocumentMetadata.js";
14
15
  import { EnsureParaIdsError, EnsureParaIdsOptions, EnsureParaIdsResult, ensureParaIds } from "./docx/ensureParaIds.js";
15
16
  import { FOLIO_DOCUMENT_METADATA_PROPERTIES, FOLIO_DOCUMENT_PRIVACY_TRANSFORMS, FolioDocumentMetadataProperty, FolioDocumentPrivacyArchiveError, FolioDocumentPrivacyOptions, FolioDocumentPrivacyReport, FolioDocumentPrivacyTransform, InvalidFolioDocumentPrivacyOptionsError, RewriteDocxMetadataPrivacyResult, isFolioDocumentPrivacyTransform, rewriteDocxMetadataPrivacy } from "./docx/metadataPrivacy.js";
16
17
  import { ParseOptions, parseDocx } from "./docx/parser.js";
@@ -26,6 +27,7 @@ import { docxToMarkdown } from "./docx/server/docxToMarkdown.js";
26
27
  import { DocxParagraphSource, DocxTableRowKind, DocxTableRowPosition, ExtractedDocxParagraph, ExtractedDocxTableCell, ExtractedDocxTableCellParagraph, ExtractedDocxText, extractDocxText } from "./docx/server/extractDocxText.js";
27
28
  import { FOLIO_DOCX_PACKAGE_INSPECTION_DEFAULTS, FOLIO_DOCX_PACKAGE_INSPECTION_ERROR_CODES, FOLIO_DOCX_PACKAGE_INSPECTION_VERSION, FolioDocxInspectedXmlPart, FolioDocxPackageInspection, FolioDocxPackageInspectionError, FolioDocxPackageInspectionErrorCode, FolioDocxPackageInspectionLimits, FolioDocxPackagePart, FolioDocxPackagePartKind, InspectDocxPackageOptions, inspectDocxPackage } from "./docx/server/inspectDocxPackage.js";
28
29
  import { FOLIO_YJS_DOCX_MATERIALIZATION_ERROR_CODES, FOLIO_YJS_PROSEMIRROR_FRAGMENT_NAME, FOLIO_YJS_UPDATE_MAX_BYTES, FolioYjsDocxMaterializationError, FolioYjsDocxMaterializationErrorCode, MaterializeYjsDocxOptions, materializeYjsDocx } from "./docx/server/materializeYjsDocx.js";
30
+ import { FOLIO_YJS_SNAPSHOT_MIGRATION_ERROR_CODES, FolioYjsSnapshotMigrationError, FolioYjsSnapshotMigrationErrorCode, FolioYjsSnapshotMigrationResult, migrateFolioYjsSnapshot } from "./docx/server/migrateYjsAttrSchema.js";
29
31
  import { GenerateRedlineDocxOptions, GenerateRedlineDocxResult, GenerateRedlineUnprocessedStory, InvalidGenerateRedlineDocxOptionsError, generateRedlineDocx } from "./redline.js";
30
32
  import { FOLIO_VERSION_COMPARISON_PRIVACY_TRANSFORMS, FOLIO_VERSION_COMPARISON_SCOPES, FolioBlockDiff, FolioBlockProperty, FolioCompareDocxVersionsOptions, FolioDocumentMetadataValue, FolioFormatProperty, FolioMetadataDiff, FolioStoryDiff, FolioVersionBlockHandle, FolioVersionChangeProperty, FolioVersionComparisonPrivacyTransform, FolioVersionComparisonScope, FolioVersionDiff, FolioVersionDiffPrivacyOptions, FolioVersionDiffPrivacyReport, FolioVersionDiffSegment, FolioVersionDiffSummaryCounts, InvalidFolioVersionComparisonOptionsError, applyFolioVersionDiffPrivacy, compareDocxVersions, isFolioVersionComparisonPrivacyTransform, isFolioVersionComparisonScope } from "./version-comparison.js";
31
- export { type ApplyDocxXmlPatchProposalArgs, type ApplyFolioAIEditsToBufferOptions, type ApplyFolioAIEditsToBufferResult, BILINGUAL_TABLE_LAYOUTS, type BilingualBorders, type BilingualParagraphRef, type BilingualRow, type BilingualRowKind, type BilingualTableLayout, type BilingualTableParagraphRef, type CreateBilingualDocumentOptions, type CreateBilingualDocumentResult, type CreateBilingualDocxOptions, type CreateBilingualDocxResult, type CreateCommentReplyInput, type CreateEmptyDocumentOptions, DOCUMENT_PRESET_VERSION, DOCUMENT_STYLE_SET_VERSION, type DeriveBlockIdInput, type DocumentPreset, type DocumentPropertiesOptions, type DocumentStyleCatalog, type DocumentStyleCatalogEntry, type DocumentStyleSet, DocxArchiveError, type DocxArchiveOptions, type DocxParagraphSource, type DocxTableRowKind, type DocxTableRowPosition, EnsureParaIdsError, type EnsureParaIdsOptions, type EnsureParaIdsResult, type EvaluateDocxXmlPatchProposalArgs, type ExtractDocumentStyleSetOptions, type ExtractedDocxParagraph, type ExtractedDocxTableCell, type ExtractedDocxTableCellParagraph, type ExtractedDocxText, FOLIO_DOCUMENT_METADATA_PROPERTIES, FOLIO_DOCUMENT_OPERATION_BATCH_MODES, FOLIO_DOCUMENT_OPERATION_BATCH_PRECONDITIONS, FOLIO_DOCUMENT_OPERATION_CONTRACT_VERSION, FOLIO_DOCUMENT_OPERATION_KEYS_BY_TYPE, FOLIO_DOCUMENT_OPERATION_MODES, FOLIO_DOCUMENT_OPERATION_MODES_BY_TYPE, FOLIO_DOCUMENT_OPERATION_PRECONDITIONS, FOLIO_DOCUMENT_OPERATION_STORIES, FOLIO_DOCUMENT_OPERATION_TYPES, FOLIO_DOCUMENT_PRIVACY_TRANSFORMS, FOLIO_DOCX_CONFORMANCE_CHECKS, FOLIO_DOCX_CONFORMANCE_ISSUE_CODES, FOLIO_DOCX_CONFORMANCE_PROFILE, FOLIO_DOCX_CONFORMANCE_REPORT_VERSION, FOLIO_DOCX_PACKAGE_INSPECTION_DEFAULTS, FOLIO_DOCX_PACKAGE_INSPECTION_ERROR_CODES, FOLIO_DOCX_PACKAGE_INSPECTION_VERSION, FOLIO_DOCX_XML_PATCH_APPLICATION_PROFILE, FOLIO_DOCX_XML_PATCH_APPLICATION_VERSION, FOLIO_DOCX_XML_PATCH_PROPOSAL_DEFAULTS, FOLIO_DOCX_XML_PATCH_PROPOSAL_ISSUE_CODES, FOLIO_DOCX_XML_PATCH_PROPOSAL_PROFILE, FOLIO_DOCX_XML_PATCH_PROPOSAL_VERSION, FOLIO_LINE_SPACING_RULE_VALUES, FOLIO_PAGE_BREAK_CLEAR_VALUES, FOLIO_PARAGRAPH_ALIGNMENT_VALUES, FOLIO_RESOLVED_REVIEWED_VIEWS, FOLIO_REVIEWED_VIEWS, FOLIO_VERSION_COMPARISON_PRIVACY_TRANSFORMS, FOLIO_VERSION_COMPARISON_SCOPES, FOLIO_YJS_DOCX_MATERIALIZATION_ERROR_CODES, FOLIO_YJS_PROSEMIRROR_FRAGMENT_NAME, FOLIO_YJS_UPDATE_MAX_BYTES, type FolioAIBlock, type FolioAIBlockAnchor, type FolioAIBlockKind, type FolioAIBlockPreviewRun, type FolioAIBlockStructuralBoundary, type FolioAIComment, type FolioAIEditApplyMode, type FolioAIEditApplyResult, type FolioAIEditNormalization, type FolioAIEditNormalizationCode, type FolioAIEditOperation, type FolioAIEditPrecondition, type FolioAIEditSnapshot, type FolioAIInlineBooleanProperty, type FolioAIInlineFormatting, type FolioAIInlineFormattingPatch, type FolioAIParagraphSpacing, type FolioAITextRangeHandle, type FolioApplyDocumentOperationsOptions, type FolioApplyDocumentOperationsToStoryOptions, type FolioApplyOperationsOptions, type FolioBlockDiff, type FolioBlockId, type FolioBlockProperty, type FolioCompareDocxVersionsOptions, type FolioContentParagraphKind, type FolioDocumentMetadataProperty, type FolioDocumentMetadataValue, type FolioDocumentNavigationTarget, type FolioDocumentOperation, type FolioDocumentOperationAffectedTarget, type FolioDocumentOperationBatch, type FolioDocumentOperationBatchPrecondition, type FolioDocumentOperationCapabilities, type FolioDocumentOperationIssue, type FolioDocumentOperationMode, type FolioDocumentOperationPrecondition, type FolioDocumentOperationQueuedOperation, type FolioDocumentOperationReceipt, type FolioDocumentOperationRecovery, type FolioDocumentOperationResult, type FolioDocumentOperationResultBase, type FolioDocumentOperationStatus, type FolioDocumentOperationStory, type FolioDocumentOperationType, type FolioDocumentOperationUndoFailureReason, type FolioDocumentOperationUndoHandle, type FolioDocumentOperationUndoResult, type FolioDocumentOutline, type FolioDocumentOutlineEntry, FolioDocumentPrivacyArchiveError, type FolioDocumentPrivacyOptions, type FolioDocumentPrivacyReport, type FolioDocumentPrivacyTransform, type FolioDocumentSection, type FolioDocumentSectionHandle, type FolioDocumentSectionReadResult, type FolioDocumentStory, type FolioDocumentStoryHandle, FolioDocumentStoryNotFoundError, type FolioDocxConformanceCheck, type FolioDocxConformanceCheckId, type FolioDocxConformanceCheckStatus, type FolioDocxConformanceIssue, type FolioDocxConformanceIssueCode, type FolioDocxConformanceReport, type FolioDocxConformanceStatus, type FolioDocxInspectedXmlPart, type FolioDocxPackageInspection, FolioDocxPackageInspectionError, type FolioDocxPackageInspectionErrorCode, type FolioDocxPackageInspectionLimits, type FolioDocxPackagePart, type FolioDocxPackagePartKind, type FolioDocxPreparedXmlReplacement, FolioDocxReviewer, type FolioDocxReviewerOptions, type FolioDocxXmlPatchApplication, FolioDocxXmlPatchApplicationError, type FolioDocxXmlPatchApplicationReceipt, type FolioDocxXmlPatchProposal, type FolioDocxXmlPatchProposalEvaluation, type FolioDocxXmlPatchProposalIssue, type FolioDocxXmlPatchProposalIssueCode, type FolioDocxXmlPatchProposalLimits, type FolioDocxXmlReplacement, type FolioEditableDocumentStoryHandle, type FolioFormatProperty, type FolioMetadataDiff, type FolioReadReviewedStoryOptions, type FolioResolveReviewedStoryOptions, type FolioResolvedReviewedView, type FolioReviewChange, type FolioReviewChangeFilter, type FolioReviewChangeKind, type FolioReviewComment, type FolioReviewCommentFilter, type FolioReviewCommentReply, type FolioReviewReplyInput, type FolioReviewedStory, type FolioReviewedView, type FolioStoryDiff, type FolioVersionBlockHandle, type FolioVersionChangeProperty, type FolioVersionComparisonPrivacyTransform, type FolioVersionComparisonScope, type FolioVersionDiff, type FolioVersionDiffPrivacyOptions, type FolioVersionDiffPrivacyReport, type FolioVersionDiffSegment, type FolioVersionDiffSummaryCounts, FolioYjsDocxMaterializationError, type FolioYjsDocxMaterializationErrorCode, type GenerateRedlineDocxOptions, type GenerateRedlineDocxResult, type GenerateRedlineUnprocessedStory, HEADING_LEVELS, type HeadingLevel, type InspectDocxPackageOptions, InvalidBilingualDocumentOptionsError, InvalidFolioDocumentOperationBatchError, InvalidFolioDocumentPrivacyOptionsError, InvalidFolioDocxXmlPatchProposalError, InvalidFolioDocxXmlPatchProposalOptionsError, InvalidFolioReportBuilderOptionsError, InvalidFolioVersionComparisonOptionsError, InvalidGenerateRedlineDocxOptionsError, type MaterializeYjsDocxOptions, type ParseOptions, type RewriteDocxMetadataPrivacyResult, STELLA_STYLE_SET_NAME, type TableCellSpec, UnsupportedFolioDocumentOperationVersionError, UnsupportedFolioDocxXmlPatchApplicationProfileError, UnsupportedFolioReviewedViewError, type ValidateDocxConformanceOptions, applyDocxXmlPatchProposal, applyFolioAIEditsToBuffer, applyFolioVersionDiffPrivacy, assertSupportedFolioDocumentOperationVersion, bookmark, compareDocxVersions, createBilingualDocument, createBilingualDocx, createDocx, createEmptyDocument, createFolioAITextRangeHandle, createStellaStyleDocumentPreset, createStellaStyleSet, createTableOfContentsField, deriveBlockId, docxToMarkdown, endnote, ensureParaIds, evaluateDocxXmlPatchProposal, extractDocumentStyleSet, extractDocumentStyleSetFromDocx, extractDocxText, generateRedlineDocx, getFolioDocumentOperationCapabilities, getFolioDocumentOperationIssues, getFolioDocumentOperationReceipts, getFolioDocumentOutline, getFolioParaIdFromBlockId, hashFolioAIBlockText, heading, hyperlink, inspectDocumentStyles, inspectDocumentStylesFromDocx, inspectDocxPackage, isFolioAIContentBlock, isFolioBlockId, isFolioDocumentOperationModeSupported, isFolioDocumentPrivacyTransform, isFolioResolvedReviewedView, isFolioReviewedView, isFolioVersionComparisonPrivacyTransform, isFolioVersionComparisonScope, isSequentialFolioBlockId, isSupportedFolioDocumentOperationVersion, materializeYjsDocx, normalizeFolioAIBlockText, pageBreak, paragraph, parseDocx, parseFolioDocumentOperationBatch, parseFolioDocxXmlPatchProposal, readBilingualDocument, readBilingualDocx, readFolioDocumentSection, replyToComment, rewriteDocxMetadataPrivacy, run, table, validateDocxConformance };
33
+ export { type ApplyDocxXmlPatchProposalArgs, type ApplyFolioAIEditsToBufferOptions, type ApplyFolioAIEditsToBufferResult, BILINGUAL_TABLE_LAYOUTS, type BilingualBorders, type BilingualParagraphRef, type BilingualRow, type BilingualRowKind, type BilingualTableLayout, type BilingualTableParagraphRef, type CreateBilingualDocumentOptions, type CreateBilingualDocumentResult, type CreateBilingualDocxOptions, type CreateBilingualDocxResult, type CreateCommentReplyInput, type CreateEmptyDocumentOptions, DOCUMENT_PRESET_VERSION, DOCUMENT_STYLE_SET_VERSION, type DeriveBlockIdInput, type DocumentPreset, type DocumentPropertiesOptions, type DocumentStyleCatalog, type DocumentStyleCatalogEntry, type DocumentStyleSet, DocxArchiveError, type DocxArchiveOptions, type DocxParagraphSource, type DocxTableRowKind, type DocxTableRowPosition, EnsureParaIdsError, type EnsureParaIdsOptions, type EnsureParaIdsResult, type EvaluateDocxXmlPatchProposalArgs, type ExtractDocumentStyleSetOptions, type ExtractedDocxParagraph, type ExtractedDocxTableCell, type ExtractedDocxTableCellParagraph, type ExtractedDocxText, FOLIO_DOCUMENT_METADATA_PROPERTIES, FOLIO_DOCUMENT_OPERATION_BATCH_MODES, FOLIO_DOCUMENT_OPERATION_BATCH_PRECONDITIONS, FOLIO_DOCUMENT_OPERATION_CONTRACT_VERSION, FOLIO_DOCUMENT_OPERATION_KEYS_BY_TYPE, FOLIO_DOCUMENT_OPERATION_MODES, FOLIO_DOCUMENT_OPERATION_MODES_BY_TYPE, FOLIO_DOCUMENT_OPERATION_PRECONDITIONS, FOLIO_DOCUMENT_OPERATION_STORIES, FOLIO_DOCUMENT_OPERATION_TYPES, FOLIO_DOCUMENT_PRIVACY_TRANSFORMS, FOLIO_DOCX_CONFORMANCE_CHECKS, FOLIO_DOCX_CONFORMANCE_ISSUE_CODES, FOLIO_DOCX_CONFORMANCE_PROFILE, FOLIO_DOCX_CONFORMANCE_REPORT_VERSION, FOLIO_DOCX_PACKAGE_INSPECTION_DEFAULTS, FOLIO_DOCX_PACKAGE_INSPECTION_ERROR_CODES, FOLIO_DOCX_PACKAGE_INSPECTION_VERSION, FOLIO_DOCX_XML_PATCH_APPLICATION_PROFILE, FOLIO_DOCX_XML_PATCH_APPLICATION_VERSION, FOLIO_DOCX_XML_PATCH_PROPOSAL_DEFAULTS, FOLIO_DOCX_XML_PATCH_PROPOSAL_ISSUE_CODES, FOLIO_DOCX_XML_PATCH_PROPOSAL_PROFILE, FOLIO_DOCX_XML_PATCH_PROPOSAL_VERSION, FOLIO_LINE_SPACING_RULE_VALUES, FOLIO_PAGE_BREAK_CLEAR_VALUES, FOLIO_PARAGRAPH_ALIGNMENT_VALUES, FOLIO_RESOLVED_REVIEWED_VIEWS, FOLIO_REVIEWED_VIEWS, FOLIO_VERSION_COMPARISON_PRIVACY_TRANSFORMS, FOLIO_VERSION_COMPARISON_SCOPES, FOLIO_YJS_ATTR_SCHEMA_VERSION, FOLIO_YJS_DOCX_MATERIALIZATION_ERROR_CODES, FOLIO_YJS_PROSEMIRROR_FRAGMENT_NAME, FOLIO_YJS_SNAPSHOT_MIGRATION_ERROR_CODES, FOLIO_YJS_UPDATE_MAX_BYTES, type FolioAIBlock, type FolioAIBlockAnchor, type FolioAIBlockKind, type FolioAIBlockPreviewRun, type FolioAIBlockStructuralBoundary, type FolioAIComment, type FolioAIEditApplyMode, type FolioAIEditApplyResult, type FolioAIEditNormalization, type FolioAIEditNormalizationCode, type FolioAIEditOperation, type FolioAIEditPrecondition, type FolioAIEditSnapshot, type FolioAIInlineBooleanProperty, type FolioAIInlineFormatting, type FolioAIInlineFormattingPatch, type FolioAIParagraphSpacing, type FolioAITextRangeHandle, type FolioApplyDocumentOperationsOptions, type FolioApplyDocumentOperationsToStoryOptions, type FolioApplyOperationsOptions, type FolioBlockDiff, type FolioBlockId, type FolioBlockProperty, type FolioCompareDocxVersionsOptions, type FolioContentParagraphKind, type FolioDocumentMetadataProperty, type FolioDocumentMetadataValue, type FolioDocumentNavigationTarget, type FolioDocumentOperation, type FolioDocumentOperationAffectedTarget, type FolioDocumentOperationBatch, type FolioDocumentOperationBatchPrecondition, type FolioDocumentOperationCapabilities, type FolioDocumentOperationIssue, type FolioDocumentOperationMode, type FolioDocumentOperationPrecondition, type FolioDocumentOperationQueuedOperation, type FolioDocumentOperationReceipt, type FolioDocumentOperationRecovery, type FolioDocumentOperationResult, type FolioDocumentOperationResultBase, type FolioDocumentOperationStatus, type FolioDocumentOperationStory, type FolioDocumentOperationType, type FolioDocumentOperationUndoFailureReason, type FolioDocumentOperationUndoHandle, type FolioDocumentOperationUndoResult, type FolioDocumentOutline, type FolioDocumentOutlineEntry, FolioDocumentPrivacyArchiveError, type FolioDocumentPrivacyOptions, type FolioDocumentPrivacyReport, type FolioDocumentPrivacyTransform, type FolioDocumentSection, type FolioDocumentSectionHandle, type FolioDocumentSectionReadResult, type FolioDocumentStory, type FolioDocumentStoryHandle, FolioDocumentStoryNotFoundError, type FolioDocxConformanceCheck, type FolioDocxConformanceCheckId, type FolioDocxConformanceCheckStatus, type FolioDocxConformanceIssue, type FolioDocxConformanceIssueCode, type FolioDocxConformanceReport, type FolioDocxConformanceStatus, type FolioDocxInspectedXmlPart, type FolioDocxPackageInspection, FolioDocxPackageInspectionError, type FolioDocxPackageInspectionErrorCode, type FolioDocxPackageInspectionLimits, type FolioDocxPackagePart, type FolioDocxPackagePartKind, type FolioDocxPreparedXmlReplacement, FolioDocxReviewer, type FolioDocxReviewerOptions, type FolioDocxXmlPatchApplication, FolioDocxXmlPatchApplicationError, type FolioDocxXmlPatchApplicationReceipt, type FolioDocxXmlPatchProposal, type FolioDocxXmlPatchProposalEvaluation, type FolioDocxXmlPatchProposalIssue, type FolioDocxXmlPatchProposalIssueCode, type FolioDocxXmlPatchProposalLimits, type FolioDocxXmlReplacement, type FolioEditableDocumentStoryHandle, type FolioFormatProperty, type FolioMetadataDiff, type FolioReadReviewedStoryOptions, type FolioResolveReviewedStoryOptions, type FolioResolvedReviewedView, type FolioReviewChange, type FolioReviewChangeFilter, type FolioReviewChangeKind, type FolioReviewComment, type FolioReviewCommentFilter, type FolioReviewCommentReply, type FolioReviewReplyInput, type FolioReviewedStory, type FolioReviewedView, type FolioStoryDiff, type FolioVersionBlockHandle, type FolioVersionChangeProperty, type FolioVersionComparisonPrivacyTransform, type FolioVersionComparisonScope, type FolioVersionDiff, type FolioVersionDiffPrivacyOptions, type FolioVersionDiffPrivacyReport, type FolioVersionDiffSegment, type FolioVersionDiffSummaryCounts, type FolioYjsAttrSchemaVersion, FolioYjsAttrSchemaVersionError, FolioYjsDocxMaterializationError, type FolioYjsDocxMaterializationErrorCode, FolioYjsSnapshotMigrationError, type FolioYjsSnapshotMigrationErrorCode, type FolioYjsSnapshotMigrationResult, type GenerateRedlineDocxOptions, type GenerateRedlineDocxResult, type GenerateRedlineUnprocessedStory, HEADING_LEVELS, type HeadingLevel, type InspectDocxPackageOptions, InvalidBilingualDocumentOptionsError, InvalidFolioDocumentOperationBatchError, InvalidFolioDocumentPrivacyOptionsError, InvalidFolioDocxXmlPatchProposalError, InvalidFolioDocxXmlPatchProposalOptionsError, InvalidFolioReportBuilderOptionsError, InvalidFolioVersionComparisonOptionsError, InvalidGenerateRedlineDocxOptionsError, type MaterializeYjsDocxOptions, type ParseOptions, type RewriteDocxMetadataPrivacyResult, STELLA_STYLE_SET_NAME, type TableCellSpec, UnsupportedFolioDocumentOperationVersionError, UnsupportedFolioDocxXmlPatchApplicationProfileError, UnsupportedFolioReviewedViewError, type ValidateDocxConformanceOptions, applyDocxXmlPatchProposal, applyFolioAIEditsToBuffer, applyFolioVersionDiffPrivacy, assertSupportedFolioDocumentOperationVersion, bookmark, compareDocxVersions, createBilingualDocument, createBilingualDocx, createDocx, createEmptyDocument, createFolioAITextRangeHandle, createStellaStyleDocumentPreset, createStellaStyleSet, createTableOfContentsField, deriveBlockId, docxToMarkdown, endnote, ensureParaIds, evaluateDocxXmlPatchProposal, extractDocumentStyleSet, extractDocumentStyleSetFromDocx, extractDocxText, generateRedlineDocx, getFolioDocumentOperationCapabilities, getFolioDocumentOperationIssues, getFolioDocumentOperationReceipts, getFolioDocumentOutline, getFolioParaIdFromBlockId, hashFolioAIBlockText, heading, hyperlink, inspectDocumentStyles, inspectDocumentStylesFromDocx, inspectDocxPackage, isFolioAIContentBlock, isFolioBlockId, isFolioDocumentOperationModeSupported, isFolioDocumentPrivacyTransform, isFolioResolvedReviewedView, isFolioReviewedView, isFolioVersionComparisonPrivacyTransform, isFolioVersionComparisonScope, isSequentialFolioBlockId, isSupportedFolioDocumentOperationVersion, materializeYjsDocx, migrateFolioYjsSnapshot, normalizeFolioAIBlockText, pageBreak, paragraph, parseDocx, parseFolioDocumentOperationBatch, parseFolioDocxXmlPatchProposal, readBilingualDocument, readBilingualDocx, readFolioDocumentSection, replyToComment, rewriteDocxMetadataPrivacy, run, table, validateDocxConformance };
package/dist/server.js CHANGED
@@ -17,7 +17,9 @@ import { FOLIO_DOCX_XML_PATCH_PROPOSAL_DEFAULTS, FOLIO_DOCX_XML_PATCH_PROPOSAL_I
17
17
  import { extractDocxText } from "./docx/server/extractDocxText.js";
18
18
  import { FOLIO_DOCX_PACKAGE_INSPECTION_DEFAULTS, FOLIO_DOCX_PACKAGE_INSPECTION_ERROR_CODES, FOLIO_DOCX_PACKAGE_INSPECTION_VERSION, FolioDocxPackageInspectionError, inspectDocxPackage } from "./docx/server/inspectDocxPackage.js";
19
19
  import { FOLIO_YJS_DOCX_MATERIALIZATION_ERROR_CODES, FOLIO_YJS_PROSEMIRROR_FRAGMENT_NAME, FOLIO_YJS_UPDATE_MAX_BYTES, FolioYjsDocxMaterializationError, materializeYjsDocx } from "./docx/server/materializeYjsDocx.js";
20
+ import { FOLIO_YJS_SNAPSHOT_MIGRATION_ERROR_CODES, FolioYjsSnapshotMigrationError, migrateFolioYjsSnapshot } from "./docx/server/migrateYjsAttrSchema.js";
20
21
  import { FOLIO_DOCX_CONFORMANCE_CHECKS, FOLIO_DOCX_CONFORMANCE_ISSUE_CODES, FOLIO_DOCX_CONFORMANCE_PROFILE, FOLIO_DOCX_CONFORMANCE_REPORT_VERSION, validateDocxConformance } from "./docx/server/validateDocxConformance.js";
22
+ import { FOLIO_YJS_ATTR_SCHEMA_VERSION, FolioYjsAttrSchemaVersionError } from "./prosemirror/yjsDocumentMetadata.js";
21
23
  import { InvalidGenerateRedlineDocxOptionsError, generateRedlineDocx } from "./redline.js";
22
24
  import { extractDocumentStyleSet, extractDocumentStyleSetFromDocx, inspectDocumentStyles, inspectDocumentStylesFromDocx } from "./style-sets/extract.js";
23
25
  import { STELLA_STYLE_SET_NAME, createStellaStyleDocumentPreset, createStellaStyleSet } from "./style-sets/stellaStyle.js";
@@ -25,4 +27,4 @@ import { DOCUMENT_PRESET_VERSION, DOCUMENT_STYLE_SET_VERSION } from "./style-set
25
27
  import { deriveBlockId, getFolioParaIdFromBlockId, isFolioBlockId, isSequentialFolioBlockId } from "./types/block-id.js";
26
28
  import { createEmptyDocument } from "./utils/createDocument.js";
27
29
  import { FOLIO_VERSION_COMPARISON_PRIVACY_TRANSFORMS, FOLIO_VERSION_COMPARISON_SCOPES, InvalidFolioVersionComparisonOptionsError, applyFolioVersionDiffPrivacy, compareDocxVersions, isFolioVersionComparisonPrivacyTransform, isFolioVersionComparisonScope } from "./version-comparison.js";
28
- export { BILINGUAL_TABLE_LAYOUTS, DOCUMENT_PRESET_VERSION, DOCUMENT_STYLE_SET_VERSION, DocxArchiveError, EnsureParaIdsError, FOLIO_DOCUMENT_METADATA_PROPERTIES, FOLIO_DOCUMENT_OPERATION_BATCH_MODES, FOLIO_DOCUMENT_OPERATION_BATCH_PRECONDITIONS, FOLIO_DOCUMENT_OPERATION_CONTRACT_VERSION, FOLIO_DOCUMENT_OPERATION_KEYS_BY_TYPE, FOLIO_DOCUMENT_OPERATION_MODES, FOLIO_DOCUMENT_OPERATION_MODES_BY_TYPE, FOLIO_DOCUMENT_OPERATION_PRECONDITIONS, FOLIO_DOCUMENT_OPERATION_STORIES, FOLIO_DOCUMENT_OPERATION_TYPES, FOLIO_DOCUMENT_PRIVACY_TRANSFORMS, FOLIO_DOCX_CONFORMANCE_CHECKS, FOLIO_DOCX_CONFORMANCE_ISSUE_CODES, FOLIO_DOCX_CONFORMANCE_PROFILE, FOLIO_DOCX_CONFORMANCE_REPORT_VERSION, FOLIO_DOCX_PACKAGE_INSPECTION_DEFAULTS, FOLIO_DOCX_PACKAGE_INSPECTION_ERROR_CODES, FOLIO_DOCX_PACKAGE_INSPECTION_VERSION, FOLIO_DOCX_XML_PATCH_APPLICATION_PROFILE, FOLIO_DOCX_XML_PATCH_APPLICATION_VERSION, FOLIO_DOCX_XML_PATCH_PROPOSAL_DEFAULTS, FOLIO_DOCX_XML_PATCH_PROPOSAL_ISSUE_CODES, FOLIO_DOCX_XML_PATCH_PROPOSAL_PROFILE, FOLIO_DOCX_XML_PATCH_PROPOSAL_VERSION, FOLIO_LINE_SPACING_RULE_VALUES, FOLIO_PAGE_BREAK_CLEAR_VALUES, FOLIO_PARAGRAPH_ALIGNMENT_VALUES, FOLIO_RESOLVED_REVIEWED_VIEWS, FOLIO_REVIEWED_VIEWS, FOLIO_VERSION_COMPARISON_PRIVACY_TRANSFORMS, FOLIO_VERSION_COMPARISON_SCOPES, FOLIO_YJS_DOCX_MATERIALIZATION_ERROR_CODES, FOLIO_YJS_PROSEMIRROR_FRAGMENT_NAME, FOLIO_YJS_UPDATE_MAX_BYTES, FolioDocumentPrivacyArchiveError, FolioDocumentStoryNotFoundError, FolioDocxPackageInspectionError, FolioDocxReviewer, FolioDocxXmlPatchApplicationError, FolioYjsDocxMaterializationError, HEADING_LEVELS, InvalidBilingualDocumentOptionsError, InvalidFolioDocumentOperationBatchError, InvalidFolioDocumentPrivacyOptionsError, InvalidFolioDocxXmlPatchProposalError, InvalidFolioDocxXmlPatchProposalOptionsError, InvalidFolioReportBuilderOptionsError, InvalidFolioVersionComparisonOptionsError, InvalidGenerateRedlineDocxOptionsError, STELLA_STYLE_SET_NAME, UnsupportedFolioDocumentOperationVersionError, UnsupportedFolioDocxXmlPatchApplicationProfileError, UnsupportedFolioReviewedViewError, applyDocxXmlPatchProposal, applyFolioAIEditsToBuffer, applyFolioVersionDiffPrivacy, assertSupportedFolioDocumentOperationVersion, bookmark, compareDocxVersions, createBilingualDocument, createBilingualDocx, createDocx, createEmptyDocument, createFolioAITextRangeHandle, createStellaStyleDocumentPreset, createStellaStyleSet, createTableOfContentsField, deriveBlockId, docxToMarkdown, endnote, ensureParaIds, evaluateDocxXmlPatchProposal, extractDocumentStyleSet, extractDocumentStyleSetFromDocx, extractDocxText, generateRedlineDocx, getFolioDocumentOperationCapabilities, getFolioDocumentOperationIssues, getFolioDocumentOperationReceipts, getFolioDocumentOutline, getFolioParaIdFromBlockId, hashFolioAIBlockText, heading, hyperlink, inspectDocumentStyles, inspectDocumentStylesFromDocx, inspectDocxPackage, isFolioAIContentBlock, isFolioBlockId, isFolioDocumentOperationModeSupported, isFolioDocumentPrivacyTransform, isFolioResolvedReviewedView, isFolioReviewedView, isFolioVersionComparisonPrivacyTransform, isFolioVersionComparisonScope, isSequentialFolioBlockId, isSupportedFolioDocumentOperationVersion, materializeYjsDocx, normalizeFolioAIBlockText, pageBreak, paragraph, parseDocx, parseFolioDocumentOperationBatch, parseFolioDocxXmlPatchProposal, readBilingualDocument, readBilingualDocx, readFolioDocumentSection, replyToComment, rewriteDocxMetadataPrivacy, run, table, validateDocxConformance };
30
+ export { BILINGUAL_TABLE_LAYOUTS, DOCUMENT_PRESET_VERSION, DOCUMENT_STYLE_SET_VERSION, DocxArchiveError, EnsureParaIdsError, FOLIO_DOCUMENT_METADATA_PROPERTIES, FOLIO_DOCUMENT_OPERATION_BATCH_MODES, FOLIO_DOCUMENT_OPERATION_BATCH_PRECONDITIONS, FOLIO_DOCUMENT_OPERATION_CONTRACT_VERSION, FOLIO_DOCUMENT_OPERATION_KEYS_BY_TYPE, FOLIO_DOCUMENT_OPERATION_MODES, FOLIO_DOCUMENT_OPERATION_MODES_BY_TYPE, FOLIO_DOCUMENT_OPERATION_PRECONDITIONS, FOLIO_DOCUMENT_OPERATION_STORIES, FOLIO_DOCUMENT_OPERATION_TYPES, FOLIO_DOCUMENT_PRIVACY_TRANSFORMS, FOLIO_DOCX_CONFORMANCE_CHECKS, FOLIO_DOCX_CONFORMANCE_ISSUE_CODES, FOLIO_DOCX_CONFORMANCE_PROFILE, FOLIO_DOCX_CONFORMANCE_REPORT_VERSION, FOLIO_DOCX_PACKAGE_INSPECTION_DEFAULTS, FOLIO_DOCX_PACKAGE_INSPECTION_ERROR_CODES, FOLIO_DOCX_PACKAGE_INSPECTION_VERSION, FOLIO_DOCX_XML_PATCH_APPLICATION_PROFILE, FOLIO_DOCX_XML_PATCH_APPLICATION_VERSION, FOLIO_DOCX_XML_PATCH_PROPOSAL_DEFAULTS, FOLIO_DOCX_XML_PATCH_PROPOSAL_ISSUE_CODES, FOLIO_DOCX_XML_PATCH_PROPOSAL_PROFILE, FOLIO_DOCX_XML_PATCH_PROPOSAL_VERSION, FOLIO_LINE_SPACING_RULE_VALUES, FOLIO_PAGE_BREAK_CLEAR_VALUES, FOLIO_PARAGRAPH_ALIGNMENT_VALUES, FOLIO_RESOLVED_REVIEWED_VIEWS, FOLIO_REVIEWED_VIEWS, FOLIO_VERSION_COMPARISON_PRIVACY_TRANSFORMS, FOLIO_VERSION_COMPARISON_SCOPES, FOLIO_YJS_ATTR_SCHEMA_VERSION, FOLIO_YJS_DOCX_MATERIALIZATION_ERROR_CODES, FOLIO_YJS_PROSEMIRROR_FRAGMENT_NAME, FOLIO_YJS_SNAPSHOT_MIGRATION_ERROR_CODES, FOLIO_YJS_UPDATE_MAX_BYTES, FolioDocumentPrivacyArchiveError, FolioDocumentStoryNotFoundError, FolioDocxPackageInspectionError, FolioDocxReviewer, FolioDocxXmlPatchApplicationError, FolioYjsAttrSchemaVersionError, FolioYjsDocxMaterializationError, FolioYjsSnapshotMigrationError, HEADING_LEVELS, InvalidBilingualDocumentOptionsError, InvalidFolioDocumentOperationBatchError, InvalidFolioDocumentPrivacyOptionsError, InvalidFolioDocxXmlPatchProposalError, InvalidFolioDocxXmlPatchProposalOptionsError, InvalidFolioReportBuilderOptionsError, InvalidFolioVersionComparisonOptionsError, InvalidGenerateRedlineDocxOptionsError, STELLA_STYLE_SET_NAME, UnsupportedFolioDocumentOperationVersionError, UnsupportedFolioDocxXmlPatchApplicationProfileError, UnsupportedFolioReviewedViewError, applyDocxXmlPatchProposal, applyFolioAIEditsToBuffer, applyFolioVersionDiffPrivacy, assertSupportedFolioDocumentOperationVersion, bookmark, compareDocxVersions, createBilingualDocument, createBilingualDocx, createDocx, createEmptyDocument, createFolioAITextRangeHandle, createStellaStyleDocumentPreset, createStellaStyleSet, createTableOfContentsField, deriveBlockId, docxToMarkdown, endnote, ensureParaIds, evaluateDocxXmlPatchProposal, extractDocumentStyleSet, extractDocumentStyleSetFromDocx, extractDocxText, generateRedlineDocx, getFolioDocumentOperationCapabilities, getFolioDocumentOperationIssues, getFolioDocumentOperationReceipts, getFolioDocumentOutline, getFolioParaIdFromBlockId, hashFolioAIBlockText, heading, hyperlink, inspectDocumentStyles, inspectDocumentStylesFromDocx, inspectDocxPackage, isFolioAIContentBlock, isFolioBlockId, isFolioDocumentOperationModeSupported, isFolioDocumentPrivacyTransform, isFolioResolvedReviewedView, isFolioReviewedView, isFolioVersionComparisonPrivacyTransform, isFolioVersionComparisonScope, isSequentialFolioBlockId, isSupportedFolioDocumentOperationVersion, materializeYjsDocx, migrateFolioYjsSnapshot, normalizeFolioAIBlockText, pageBreak, paragraph, parseDocx, parseFolioDocumentOperationBatch, parseFolioDocxXmlPatchProposal, readBilingualDocument, readBilingualDocx, readFolioDocumentSection, replyToComment, rewriteDocxMetadataPrivacy, run, table, validateDocxConformance };
@@ -1,2 +1,2 @@
1
- import { BlockContent, BlockRangeMarkerCapture, BlockSdt, BookmarkEnd, BookmarkStart, BreakContent, Column, Comment, CommentRangeEnd, CommentRangeStart, CommentReference, ComplexField, Deletion, DisplacedByCustomXml, DocumentBody, DrawingContent, DrawingRawXmlMode, Endnote, EndnotePosition, EndnoteProperties, Field, FieldCharContent, FieldType, FooterReference, Footnote, FootnotePosition, FootnoteProperties, HeaderFooter, HeaderFooterType, HeaderReference, Hyperlink, Image, ImageCrop, ImagePadding, ImagePosition, ImageSize, ImageTransform, ImageWrap, InlineSdt, Insertion, InstrTextContent, LineNumberRestart, MathEquation, MoveFrom, MoveFromRangeEnd, MoveFromRangeStart, MoveTo, MoveToRangeEnd, MoveToRangeStart, NoBreakHyphenContent, NoteNumberRestart, NoteReferenceContent, PageOrientation, Paragraph, ParagraphContent, ParagraphPropertyChange, PositionalTab, PropertyChangeInfo, Run, RunContent, RunPropertyChange, SdtProperties, SdtType, Section, SectionProperties, SectionStart, Shape, ShapeContent, ShapeFill, ShapeGeometryAdjustment, ShapeOutline, ShapeTextBody, ShapeType, SimpleField, SoftHyphenContent, SymbolContent, TabContent, Table, TableCell, TableCellPropertyChange, TableRow, TableRowPropertyChange, TableStructuralChangeInfo, TextBox, TextContent, TrackedChangeInfo, TrackedRunChange, TrackedRunContent, VerticalAlign } from "@stll/docx-core/model";
2
- export type { BlockContent, BlockRangeMarkerCapture, BlockSdt, BookmarkEnd, BookmarkStart, BreakContent, Column, Comment, CommentRangeEnd, CommentRangeStart, CommentReference, ComplexField, Deletion, DisplacedByCustomXml, DocumentBody, DrawingContent, DrawingRawXmlMode, Endnote, EndnotePosition, EndnoteProperties, Field, FieldCharContent, FieldType, FooterReference, Footnote, FootnotePosition, FootnoteProperties, HeaderFooter, HeaderFooterType, HeaderReference, Hyperlink, Image, ImageCrop, ImagePadding, ImagePosition, ImageSize, ImageTransform, ImageWrap, InlineSdt, Insertion, InstrTextContent, LineNumberRestart, MathEquation, MoveFrom, MoveFromRangeEnd, MoveFromRangeStart, MoveTo, MoveToRangeEnd, MoveToRangeStart, NoBreakHyphenContent, NoteNumberRestart, NoteReferenceContent, PageOrientation, Paragraph, ParagraphContent, ParagraphPropertyChange, PositionalTab, PropertyChangeInfo, Run, RunContent, RunPropertyChange, SdtProperties, SdtType, Section, SectionProperties, SectionStart, Shape, ShapeContent, ShapeFill, ShapeGeometryAdjustment, ShapeOutline, ShapeTextBody, ShapeType, SimpleField, SoftHyphenContent, SymbolContent, TabContent, Table, TableCell, TableCellPropertyChange, TableRow, TableRowPropertyChange, TableStructuralChangeInfo, TextBox, TextContent, TrackedChangeInfo, TrackedRunChange, TrackedRunContent, VerticalAlign };
1
+ import { BlockContent, BlockSdt, BookmarkEnd, BookmarkStart, BreakContent, Column, Comment, CommentRangeEnd, CommentRangeStart, CommentReference, ComplexField, Deletion, DisplacedByCustomXml, DocumentBody, DrawingContent, DrawingRawXmlMode, Endnote, EndnotePosition, EndnoteProperties, Field, FieldCharContent, FieldType, FooterReference, Footnote, FootnotePosition, FootnoteProperties, HeaderFooter, HeaderFooterType, HeaderReference, Hyperlink, Image, ImageCrop, ImagePadding, ImagePosition, ImageSize, ImageTransform, ImageWrap, InlineSdt, Insertion, InstrTextContent, LineNumberRestart, MathEquation, MoveFrom, MoveFromRangeEnd, MoveFromRangeStart, MoveTo, MoveToRangeEnd, MoveToRangeStart, NoBreakHyphenContent, NoteNumberRestart, NoteReferenceContent, PageOrientation, Paragraph, ParagraphContent, ParagraphPropertyChange, PositionalTab, PreservedAttribute, PreservedBlock, PreservedInline, PropertyChangeInfo, Run, RunContent, RunPropertyChange, SdtProperties, SdtType, Section, SectionProperties, SectionStart, Shape, ShapeContent, ShapeFill, ShapeGeometryAdjustment, ShapeOutline, ShapeTextBody, ShapeType, SimpleField, SoftHyphenContent, SymbolContent, TabContent, Table, TableCell, TableCellBlock, TableCellPropertyChange, TableRow, TableRowPropertyChange, TableStructuralChangeInfo, TextBox, TextContent, TrackedChangeInfo, TrackedRunChange, TrackedRunContent, VerticalAlign } from "@stll/docx-core/model";
2
+ export type { BlockContent, BlockSdt, BookmarkEnd, BookmarkStart, BreakContent, Column, Comment, CommentRangeEnd, CommentRangeStart, CommentReference, ComplexField, Deletion, DisplacedByCustomXml, DocumentBody, DrawingContent, DrawingRawXmlMode, Endnote, EndnotePosition, EndnoteProperties, Field, FieldCharContent, FieldType, FooterReference, Footnote, FootnotePosition, FootnoteProperties, HeaderFooter, HeaderFooterType, HeaderReference, Hyperlink, Image, ImageCrop, ImagePadding, ImagePosition, ImageSize, ImageTransform, ImageWrap, InlineSdt, Insertion, InstrTextContent, LineNumberRestart, MathEquation, MoveFrom, MoveFromRangeEnd, MoveFromRangeStart, MoveTo, MoveToRangeEnd, MoveToRangeStart, NoBreakHyphenContent, NoteNumberRestart, NoteReferenceContent, PageOrientation, Paragraph, ParagraphContent, ParagraphPropertyChange, PositionalTab, PreservedAttribute, PreservedBlock, PreservedInline, PropertyChangeInfo, Run, RunContent, RunPropertyChange, SdtProperties, SdtType, Section, SectionProperties, SectionStart, Shape, ShapeContent, ShapeFill, ShapeGeometryAdjustment, ShapeOutline, ShapeTextBody, ShapeType, SimpleField, SoftHyphenContent, SymbolContent, TabContent, Table, TableCell, TableCellBlock, TableCellPropertyChange, TableRow, TableRowPropertyChange, TableStructuralChangeInfo, TextBox, TextContent, TrackedChangeInfo, TrackedRunChange, TrackedRunContent, VerticalAlign };
@@ -51,9 +51,17 @@ declare const CLIPBOARD_TYPES: {
51
51
  */
52
52
  type ClipboardDataLike = {
53
53
  files?: FileList | readonly File[] | undefined;
54
+ getData?: ((format: string) => string) | undefined;
54
55
  items?: DataTransferItemList | readonly DataTransferItem[] | undefined;
56
+ types?: ArrayLike<string> | undefined;
55
57
  };
56
58
  declare function getClipboardImageFiles(clipboardData: ClipboardDataLike | null): File[];
59
+ /**
60
+ * Return image files only when the clipboard has no readable editor content.
61
+ * Rich HTML, internal payloads, and plain text must stay on the normal paste
62
+ * path; some applications include a rendered image beside that content.
63
+ */
64
+ declare function getStandaloneClipboardImageFiles(clipboardData: ClipboardDataLike | null): File[];
57
65
  /**
58
66
  * Copy runs to clipboard with formatting
59
67
  */
@@ -141,4 +149,4 @@ declare const _default: {
141
149
  createClipboardHandlers: typeof createClipboardHandlers;
142
150
  };
143
151
  //#endregion
144
- export { CLIPBOARD_TYPES, ClipboardContent, ClipboardOptions, INTERNAL_CLIPBOARD_TYPE, ParsedClipboardContent, cleanWordHtml, copyParagraphs, copyRuns, createClipboardHandlers, _default as default, getClipboardImageFiles, handlePasteEvent, htmlToRuns, isEditorHtml, isWordHtml, paragraphsToClipboardContent, parseClipboardHtml, readFromClipboard, runsToClipboardContent, sanitizeInboundClipboardHtml, writeToClipboard };
152
+ export { CLIPBOARD_TYPES, ClipboardContent, ClipboardOptions, INTERNAL_CLIPBOARD_TYPE, ParsedClipboardContent, cleanWordHtml, copyParagraphs, copyRuns, createClipboardHandlers, _default as default, getClipboardImageFiles, getStandaloneClipboardImageFiles, handlePasteEvent, htmlToRuns, isEditorHtml, isWordHtml, paragraphsToClipboardContent, parseClipboardHtml, readFromClipboard, runsToClipboardContent, sanitizeInboundClipboardHtml, writeToClipboard };
@@ -93,6 +93,32 @@ function getClipboardImageFiles(clipboardData) {
93
93
  for (const group of groups.values()) deduped.push(pickBest(group));
94
94
  return deduped;
95
95
  }
96
+ const ENGINE_CLIPBOARD_TYPES = [
97
+ INTERNAL_CLIPBOARD_TYPE,
98
+ CLIPBOARD_TYPES.HTML,
99
+ CLIPBOARD_TYPES.PLAIN
100
+ ];
101
+ const hasEngineClipboardContent = (clipboardData) => {
102
+ if (!clipboardData.types || !clipboardData.getData) return false;
103
+ const availableTypes = new Set(Array.from(clipboardData.types));
104
+ for (const type of ENGINE_CLIPBOARD_TYPES) {
105
+ if (!availableTypes.has(type)) continue;
106
+ try {
107
+ if (clipboardData.getData(type) !== "") return true;
108
+ } catch {}
109
+ }
110
+ return false;
111
+ };
112
+ /**
113
+ * Return image files only when the clipboard has no readable editor content.
114
+ * Rich HTML, internal payloads, and plain text must stay on the normal paste
115
+ * path; some applications include a rendered image beside that content.
116
+ */
117
+ function getStandaloneClipboardImageFiles(clipboardData) {
118
+ const imageFiles = getClipboardImageFiles(clipboardData);
119
+ if (imageFiles.length === 0 || !clipboardData) return imageFiles;
120
+ return hasEngineClipboardContent(clipboardData) ? [] : imageFiles;
121
+ }
96
122
  /**
97
123
  * Copy runs to clipboard with formatting
98
124
  */
@@ -648,4 +674,4 @@ var clipboard_default = {
648
674
  createClipboardHandlers
649
675
  };
650
676
  //#endregion
651
- export { CLIPBOARD_TYPES, INTERNAL_CLIPBOARD_TYPE, cleanWordHtml, copyParagraphs, copyRuns, createClipboardHandlers, clipboard_default as default, getClipboardImageFiles, handlePasteEvent, htmlToRuns, isEditorHtml, isWordHtml, paragraphsToClipboardContent, parseClipboardHtml, readFromClipboard, runsToClipboardContent, sanitizeInboundClipboardHtml, writeToClipboard };
677
+ export { CLIPBOARD_TYPES, INTERNAL_CLIPBOARD_TYPE, cleanWordHtml, copyParagraphs, copyRuns, createClipboardHandlers, clipboard_default as default, getClipboardImageFiles, getStandaloneClipboardImageFiles, handlePasteEvent, htmlToRuns, isEditorHtml, isWordHtml, paragraphsToClipboardContent, parseClipboardHtml, readFromClipboard, runsToClipboardContent, sanitizeInboundClipboardHtml, writeToClipboard };
@@ -106,7 +106,7 @@ const getParagraphContentSearchProjection = (content) => {
106
106
  if (content.type === "run") return getRunSearchProjection(content);
107
107
  if (content.type === "hyperlink") return getHyperlinkSearchProjection(content);
108
108
  if (content.type === "inlineSdt") return joinSearchProjections(content.content.map(getParagraphContentSearchProjection));
109
- if (content.type === "simpleField") return joinSearchProjections(content.content.map((child) => child.type === "run" ? getRunSearchProjection(child) : getHyperlinkSearchProjection(child)));
109
+ if (content.type === "simpleField") return joinSearchProjections(content.content.map(getParagraphContentSearchProjection));
110
110
  if (content.type === "complexField") return joinSearchProjections(content.fieldResult.map(getRunSearchProjection));
111
111
  return {
112
112
  text: "",
@@ -0,0 +1,15 @@
1
+ //#region src/utils/imageLuminance.d.ts
2
+ type ImageLuminance = {
3
+ brightness?: number | null;
4
+ contrast?: number | null;
5
+ };
6
+ /** Clamp a finite percentage to the range accepted by DrawingML `a:lum`. */
7
+ declare const normalizeImageLuminancePercent: (value: number) => number;
8
+ /**
9
+ * Convert DrawingML brightness and contrast percentages into Word's single
10
+ * linear per-channel transfer, expressed as CSS filters without an
11
+ * intermediate clamp changing the result.
12
+ */
13
+ declare const imageLuminanceFilter: ({ brightness, contrast }: ImageLuminance) => string | undefined;
14
+ //#endregion
15
+ export { ImageLuminance, imageLuminanceFilter, normalizeImageLuminancePercent };
@@ -0,0 +1,32 @@
1
+ //#region src/utils/imageLuminance.ts
2
+ const MAX_PERCENT = 100;
3
+ const HARD_STEP_SLOPE = 1e3;
4
+ /** Clamp a finite percentage to the range accepted by DrawingML `a:lum`. */
5
+ const normalizeImageLuminancePercent = (value) => Math.max(-100, Math.min(MAX_PERCENT, value));
6
+ const finitePercent = (value) => value == null || !Number.isFinite(value) ? 0 : normalizeImageLuminancePercent(value);
7
+ const styleNumber = (value) => {
8
+ const rounded = Math.round(value * 1e6) / 1e6;
9
+ return String(Object.is(rounded, -0) ? 0 : rounded);
10
+ };
11
+ /**
12
+ * Convert DrawingML brightness and contrast percentages into Word's single
13
+ * linear per-channel transfer, expressed as CSS filters without an
14
+ * intermediate clamp changing the result.
15
+ */
16
+ const imageLuminanceFilter = ({ brightness, contrast }) => {
17
+ const bright = finitePercent(brightness) / MAX_PERCENT;
18
+ const contrastAmount = finitePercent(contrast) / MAX_PERCENT;
19
+ if (bright === 0 && contrastAmount === 0) return;
20
+ const slope = contrastAmount >= 0 ? Math.min(HARD_STEP_SLOPE, 1 / (1 - contrastAmount)) : Math.max(0, 1 + contrastAmount);
21
+ const pivot = .5 - bright / 2;
22
+ const intercept = pivot + bright - slope * pivot;
23
+ if (intercept >= 0) {
24
+ const brightnessAmount = slope + 2 * intercept;
25
+ if (brightnessAmount <= 0) return "brightness(0)";
26
+ return `contrast(${styleNumber(slope / brightnessAmount)}) brightness(${styleNumber(brightnessAmount)})`;
27
+ }
28
+ const contrastFactor = 1 - 2 * intercept;
29
+ return `brightness(${styleNumber(slope / contrastFactor)}) contrast(${styleNumber(contrastFactor)})`;
30
+ };
31
+ //#endregion
32
+ export { imageLuminanceFilter, normalizeImageLuminancePercent };
@@ -91,6 +91,12 @@ function remapBlock(block, numIdRemap, abstractNumIdRemap) {
91
91
  };
92
92
  return block;
93
93
  }
94
+ /** A cell holds no content control, so the walk stays inside its own union. */
95
+ function remapCellBlock(block, numIdRemap, abstractNumIdRemap) {
96
+ if (block.type === "paragraph") return remapParagraph(block, numIdRemap, abstractNumIdRemap);
97
+ if (block.type === "table") return remapTable(block, numIdRemap, abstractNumIdRemap);
98
+ return block;
99
+ }
94
100
  function remapTable(table, numIdRemap, abstractNumIdRemap) {
95
101
  return {
96
102
  ...table,
@@ -98,27 +104,11 @@ function remapTable(table, numIdRemap, abstractNumIdRemap) {
98
104
  ...row,
99
105
  cells: row.cells.map((cell) => ({
100
106
  ...cell,
101
- content: cell.content.map((item) => remapCellItem(item, numIdRemap, abstractNumIdRemap))
107
+ content: cell.content.map((item) => remapCellBlock(item, numIdRemap, abstractNumIdRemap))
102
108
  }))
103
109
  }))
104
110
  };
105
111
  }
106
- /**
107
- * `TableCell.content` is typed as `(Paragraph | Table)[]` — narrower than
108
- * `BlockContent` — because folio's own DOCX parser flattens a `w:sdt` inside
109
- * a cell into its `sdtContent` children (see `tableParser.ts`) rather than
110
- * keeping a `blockSdt` wrapper. A hand-built `Document` is not bound by that
111
- * invariant, so delegate to `remapBlock` (which fully handles paragraph,
112
- * table, and container blocks, including nested tables) and only accept its
113
- * result back into the cell when it is still a `Paragraph | Table` — an
114
- * anomalous `blockSdt` (or any other shape `remapBlock` had to pass through
115
- * unchanged) is left as-is rather than smuggled into a field the type system
116
- * says can't hold it.
117
- */
118
- function remapCellItem(item, numIdRemap, abstractNumIdRemap) {
119
- const remapped = remapBlock(item, numIdRemap, abstractNumIdRemap);
120
- return remapped.type === "blockSdt" ? item : remapped;
121
- }
122
112
  function remapParagraph(paragraph, numIdRemap, abstractNumIdRemap) {
123
113
  const numId = paragraph.formatting?.numPr?.numId;
124
114
  const remappedNumId = numId === void 0 ? void 0 : numIdRemap.get(numId);
@@ -49,6 +49,7 @@ function getParagraphByIndex(body, paragraphIndex) {
49
49
  }
50
50
  continue;
51
51
  }
52
+ if (block.type === "preservedBlock") continue;
52
53
  const found = walkBlocks(block.content);
53
54
  if (found !== null) return found;
54
55
  }