@stll/folio-core 0.68.0 → 0.69.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 (177) hide show
  1. package/dist/ai-edits/headless.js +2 -2
  2. package/dist/ai-edits/newListNumbering.d.ts +14 -1
  3. package/dist/ai-edits/newListNumbering.js +24 -1
  4. package/dist/ai-edits/pending-suggestions.js +2 -2
  5. package/dist/controller/canonicalClipboard.js +2 -2
  6. package/dist/controller/canonicalComposition.js +34 -5
  7. package/dist/controller/canonicalInput.js +4 -6
  8. package/dist/controller/canonicalLockGuard.d.ts +17 -2
  9. package/dist/controller/canonicalLockGuard.js +46 -1
  10. package/dist/controller/canonicalProjectionBlocks.d.ts +79 -0
  11. package/dist/controller/canonicalProjectionBlocks.js +75 -0
  12. package/dist/controller/canonicalPublicOperations.js +476 -100
  13. package/dist/controller/canonicalSeedContent.d.ts +12 -0
  14. package/dist/controller/canonicalSeedContent.js +131 -0
  15. package/dist/controller/canonicalSession.d.ts +53 -21
  16. package/dist/controller/canonicalSession.js +489 -210
  17. package/dist/controller/canonicalSourceNormalization.d.ts +21 -0
  18. package/dist/controller/canonicalSourceNormalization.js +148 -0
  19. package/dist/controller/canonicalStoryEditor.d.ts +1 -1
  20. package/dist/controller/canonicalStoryEditor.js +16 -12
  21. package/dist/controller/folioEditor.js +3 -0
  22. package/dist/controller/headerFooterEditorManager.d.ts +5 -0
  23. package/dist/controller/headerFooterEditorManager.js +7 -2
  24. package/dist/controller/hiddenEditorApi.d.ts +11 -2
  25. package/dist/controller/hiddenEditorApi.js +3 -0
  26. package/dist/controller/hiddenEditorManager.d.ts +7 -0
  27. package/dist/controller/hiddenEditorManager.js +66 -11
  28. package/dist/controller/layoutPipeline.js +2 -1
  29. package/dist/controller/layoutSession.d.ts +3 -0
  30. package/dist/controller/layoutSession.js +3 -1
  31. package/dist/controller/noteEditorManager.d.ts +5 -0
  32. package/dist/controller/noteEditorManager.js +7 -2
  33. package/dist/display-list/dom/renderDisplayListToDom.js +9 -7
  34. package/dist/document-operations.d.ts +1 -1
  35. package/dist/docx/canonicalSave.js +7 -2
  36. package/dist/docx/commentAnchorIndex.d.ts +19 -0
  37. package/dist/docx/commentAnchorIndex.js +55 -1
  38. package/dist/docx/containerChildren.js +1 -1
  39. package/dist/docx/contentTypeRegistry.js +1 -1
  40. package/dist/docx/hostCommentThreads.d.ts +11 -1
  41. package/dist/docx/hostCommentThreads.js +25 -2
  42. package/dist/docx/listModelNormalization.js +4 -5
  43. package/dist/docx/listNumberingInstances.d.ts +1 -1
  44. package/dist/docx/listNumberingInstances.js +2 -2
  45. package/dist/docx/numberingIds.d.ts +6 -0
  46. package/dist/docx/numberingIds.js +6 -1
  47. package/dist/docx/numberingReferenceNormalization.d.ts +4 -0
  48. package/dist/docx/numberingReferenceNormalization.js +12 -2
  49. package/dist/docx/paragraphPropertySource.d.ts +22 -0
  50. package/dist/docx/paragraphPropertySource.js +85 -16
  51. package/dist/docx/parser.js +2 -0
  52. package/dist/docx/removeHeaderFooterParts.js +1 -1
  53. package/dist/docx/reviewResolutionProvenance.js +72 -19
  54. package/dist/docx/serializer/documentSerializer.js +2 -1
  55. package/dist/docx/serializer/partNamespaces.d.ts +1 -1
  56. package/dist/docx/serializer/partNamespaces.js +1 -1
  57. package/dist/docx/server/build.d.ts +1 -1
  58. package/dist/docx/storyBlockReplay.js +15 -2
  59. package/dist/docx/structuralXmlPatch.js +25 -4
  60. package/dist/docx/xmlParser.d.ts +1 -1
  61. package/dist/docx/xmlParser.js +2 -3
  62. package/dist/i18n/messages/ar.gen.js +1 -0
  63. package/dist/i18n/messages/catalogs.gen.d.ts +17 -0
  64. package/dist/i18n/messages/catalogs.gen.js +17 -0
  65. package/dist/i18n/messages/cs.gen.js +1 -0
  66. package/dist/i18n/messages/de.gen.js +1 -0
  67. package/dist/i18n/messages/en.gen.js +1 -0
  68. package/dist/i18n/messages/es.gen.js +1 -0
  69. package/dist/i18n/messages/et.gen.js +1 -0
  70. package/dist/i18n/messages/fr.gen.js +1 -0
  71. package/dist/i18n/messages/he.gen.js +1 -0
  72. package/dist/i18n/messages/hi.gen.js +1 -0
  73. package/dist/i18n/messages/hu.gen.js +1 -0
  74. package/dist/i18n/messages/lt.gen.js +1 -0
  75. package/dist/i18n/messages/lv.gen.js +1 -0
  76. package/dist/i18n/messages/messages.gen.d.ts +1 -0
  77. package/dist/i18n/messages/pl.gen.js +1 -0
  78. package/dist/i18n/messages/pt-BR.gen.js +1 -0
  79. package/dist/i18n/messages/sk.gen.js +1 -0
  80. package/dist/i18n/messages/tr.gen.js +1 -0
  81. package/dist/i18n/messages/zh-CN.gen.js +1 -0
  82. package/dist/internal/pageBreakRunDescendantIndex.d.ts +7 -2
  83. package/dist/internal/pageBreakRunDescendantIndex.js +12 -3
  84. package/dist/internal/subtreeHolds.d.ts +12 -0
  85. package/dist/internal/subtreeHolds.js +25 -0
  86. package/dist/internal/wholeStoryRevisionResolution.js +1 -1
  87. package/dist/layout-bridge/cellSelectionHighlight.js +3 -3
  88. package/dist/layout-bridge/convert/flowBlockPostprocessing.js +20 -12
  89. package/dist/layout-bridge/convert/flowConversionShared.d.ts +15 -1
  90. package/dist/layout-bridge/convert/flowConversionShared.js +9 -1
  91. package/dist/layout-bridge/convert/paragraphAttrs.d.ts +15 -4
  92. package/dist/layout-bridge/convert/paragraphAttrs.js +11 -4
  93. package/dist/layout-bridge/convert/paragraphBlockCache.d.ts +26 -0
  94. package/dist/layout-bridge/convert/paragraphBlockCache.js +137 -0
  95. package/dist/layout-bridge/convert/paragraphConversion.d.ts +12 -2
  96. package/dist/layout-bridge/convert/paragraphConversion.js +37 -5
  97. package/dist/layout-bridge/convert/paragraphRuns.d.ts +2 -2
  98. package/dist/layout-bridge/convert/sectionBoundaries.js +16 -0
  99. package/dist/layout-bridge/convert/toFlowBlocks.js +144 -15
  100. package/dist/layout-bridge/convert/topLevelConversion.d.ts +74 -0
  101. package/dist/layout-bridge/convert/topLevelConversion.js +109 -0
  102. package/dist/layout-bridge/dom/clickToPositionDom.js +41 -40
  103. package/dist/layout-bridge/dom/findBodyPmSpans.js +4 -3
  104. package/dist/layout-bridge/dom/findHfPmSpans.js +10 -15
  105. package/dist/layout-bridge/dom/imeCaretAnchor.d.ts +8 -0
  106. package/dist/layout-bridge/dom/imeCaretAnchor.js +71 -7
  107. package/dist/layout-bridge/dom/textStreamDom.js +3 -2
  108. package/dist/layout-bridge/headerFooterLayout.js +12 -11
  109. package/dist/layout-bridge/tableInsertHover.js +2 -1
  110. package/dist/layout-engine/measure/cache.d.ts +2 -0
  111. package/dist/layout-engine/measure/cache.js +6 -1
  112. package/dist/layout-engine/measure/paragraphKeyMemo.d.ts +8 -0
  113. package/dist/layout-engine/measure/paragraphKeyMemo.js +92 -0
  114. package/dist/layout-engine/types.d.ts +6 -0
  115. package/dist/layout-painter/imageLayout.js +2 -1
  116. package/dist/layout-painter/pageShellStyles.d.ts +10 -0
  117. package/dist/layout-painter/pageShellStyles.js +32 -0
  118. package/dist/layout-painter/reconcileRenderedContent.d.ts +19 -0
  119. package/dist/layout-painter/reconcileRenderedContent.js +117 -0
  120. package/dist/layout-painter/renderFragment.js +4 -6
  121. package/dist/layout-painter/renderImage.js +2 -2
  122. package/dist/layout-painter/renderPage.js +8 -29
  123. package/dist/layout-painter/renderParagraph.js +3 -3
  124. package/dist/layout-painter/renderTable.js +9 -12
  125. package/dist/layout-painter/renderTextBox.js +2 -2
  126. package/dist/layout-painter/sdtBoundary.js +3 -2
  127. package/dist/paged-layout/blockGeometry.js +3 -2
  128. package/dist/paged-layout/editorScrollRoot.d.ts +9 -0
  129. package/dist/paged-layout/editorScrollRoot.js +10 -1
  130. package/dist/paged-layout/rangeProjection.js +5 -4
  131. package/dist/paged-layout/scrollToPmPosition.js +3 -3
  132. package/dist/paged-layout/selectionViewportRect.d.ts +6 -0
  133. package/dist/paged-layout/selectionViewportRect.js +8 -2
  134. package/dist/prosemirror/attrs/index.js +1 -0
  135. package/dist/prosemirror/commands/comments.d.ts +5 -2
  136. package/dist/prosemirror/commands/comments.js +88 -8
  137. package/dist/prosemirror/commentRecords.d.ts +137 -0
  138. package/dist/prosemirror/commentRecords.js +400 -0
  139. package/dist/prosemirror/conversion/fromProseDoc.js +9 -3
  140. package/dist/prosemirror/conversion/index.d.ts +1 -1
  141. package/dist/prosemirror/conversion/toProseDoc.d.ts +13 -4
  142. package/dist/prosemirror/conversion/toProseDoc.js +126 -38
  143. package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.d.ts +22 -0
  144. package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.js +61 -32
  145. package/dist/prosemirror/extensions/marks/CommentExtension.js +3 -1
  146. package/dist/prosemirror/extensions/nodes/CommentReferenceExtension.js +3 -1
  147. package/dist/prosemirror/index.d.ts +1 -1
  148. package/dist/prosemirror/nativeSelection.d.ts +33 -0
  149. package/dist/prosemirror/nativeSelection.js +74 -0
  150. package/dist/prosemirror/numberedRefFields.d.ts +2 -0
  151. package/dist/prosemirror/numberedRefFields.js +16 -5
  152. package/dist/prosemirror/paragraphMarkJoin.d.ts +6 -8
  153. package/dist/prosemirror/paragraphMarkJoin.js +155 -16
  154. package/dist/prosemirror/plugins/contentControlWidgets.js +2 -2
  155. package/dist/prosemirror/plugins/documentNumbering.js +33 -14
  156. package/dist/prosemirror/plugins/suggestionMode.js +13 -1
  157. package/dist/prosemirror/runIdentityAcrossRevisions.d.ts +23 -1
  158. package/dist/prosemirror/runIdentityAcrossRevisions.js +57 -8
  159. package/dist/prosemirror/schema/marks.d.ts +7 -1
  160. package/dist/prosemirror/storyListNumbering.js +7 -2
  161. package/dist/prosemirror/tableResize.d.ts +10 -9
  162. package/dist/prosemirror/tableResize.js +60 -49
  163. package/dist/prosemirror/textInput.d.ts +30 -1
  164. package/dist/prosemirror/textInput.js +144 -17
  165. package/dist/prosemirror/utils/visualLineNavigation.js +20 -18
  166. package/dist/prosemirror/validation.d.ts +19 -0
  167. package/dist/prosemirror/validation.js +78 -5
  168. package/dist/render-dom/HeaderFooterSelectionOverlay.js +5 -4
  169. package/dist/render-dom/RenderedDomContext.js +7 -6
  170. package/dist/types/canonicalCapabilities.d.ts +12 -11
  171. package/dist/types/canonicalCapabilities.js +12 -13
  172. package/dist/utils/findMatchView.js +4 -3
  173. package/dist/utils/formatToStyle.d.ts +1 -1
  174. package/dist/utils/mergeDocumentContent.js +2 -2
  175. package/dist/utils/paintedPositions.d.ts +60 -0
  176. package/dist/utils/paintedPositions.js +101 -0
  177. package/package.json +2 -3
@@ -0,0 +1,92 @@
1
+ import { documentFontFactsCacheIdentity } from "../../fonts/documentFontFacts.js";
2
+ // src/layout-engine/measure/paragraphKeyMemo.ts
3
+ /**
4
+ * The measurement key of a paragraph that an edit only moved, without
5
+ * serializing it again.
6
+ *
7
+ * Every layout pass converts the document into fresh blocks, and a paragraph
8
+ * after an edit comes out as a copy of the block kept for it with shifted
9
+ * positions. Its key is the key of what it was moved from whenever every
10
+ * value the key reads is the one it read then: the key never reads
11
+ * positions, and the values a moved block shares are never written after
12
+ * conversion. A block whose values differ, or whose origin is unknown, is
13
+ * serialized in full.
14
+ */
15
+ /** The run fields the key leaves out: they say where a run stands. */
16
+ const POSITION_FIELDS = /* @__PURE__ */ new Set(["pmStart", "pmEnd"]);
17
+ const NO_FIELDS = /* @__PURE__ */ new Set();
18
+ const isPlainObject = (value) => typeof value === "object" && value !== null && Object.getPrototypeOf(value) === Object.prototype;
19
+ const fieldsOf = (record, skip) => Object.entries(record).filter(([name]) => !skip.has(name)).map(([name, value]) => [name, isPlainObject(value) ? { fields: Object.entries(value) } : { value }]);
20
+ const countFields = (record, skip) => {
21
+ let count = 0;
22
+ for (const name of Object.keys(record)) if (!skip.has(name)) count += 1;
23
+ return count;
24
+ };
25
+ /** Whether `record` holds the values `fields` recorded, nested ones included. */
26
+ const holds = (record, fields, skip) => {
27
+ if (countFields(record, skip) !== fields.length) return false;
28
+ for (const [name, recorded] of fields) {
29
+ const value = record[name];
30
+ if (!("fields" in recorded)) {
31
+ if (value !== recorded.value) return false;
32
+ continue;
33
+ }
34
+ if (!isPlainObject(value)) return false;
35
+ if (Object.keys(value).length !== recorded.fields.length) return false;
36
+ for (const [nestedName, nestedValue] of recorded.fields) if (value[nestedName] !== nestedValue) return false;
37
+ }
38
+ return true;
39
+ };
40
+ const factIdentitiesOf = (block) => {
41
+ const identities = [factIdentity(block.attrs?.documentFontFacts)];
42
+ for (const run of block.runs) if ("documentFontFacts" in run) identities.push(factIdentity(run.documentFontFacts));
43
+ return identities;
44
+ };
45
+ const factIdentity = (facts) => documentFontFactsCacheIdentity(facts);
46
+ const record = (block, key, generation) => ({
47
+ key,
48
+ generation,
49
+ attrs: block.attrs === void 0 ? void 0 : fieldsOf(block.attrs, NO_FIELDS),
50
+ runs: block.runs.map((run) => fieldsOf(run, POSITION_FIELDS)),
51
+ factIdentities: factIdentitiesOf(block)
52
+ });
53
+ const stillHolds = (recorded, block, generation) => {
54
+ if (recorded.generation !== generation) return false;
55
+ if (recorded.runs.length !== block.runs.length) return false;
56
+ if (recorded.attrs === void 0 !== (block.attrs === void 0)) return false;
57
+ if (recorded.attrs !== void 0 && !holds(block.attrs, recorded.attrs, NO_FIELDS)) return false;
58
+ for (const [index, run] of block.runs.entries()) {
59
+ const fields = recorded.runs[index];
60
+ if (!fields || !holds(run, fields, POSITION_FIELDS)) return false;
61
+ }
62
+ const identities = factIdentitiesOf(block);
63
+ return identities.length === recorded.factIdentities.length && identities.every((identity, index) => identity === recorded.factIdentities[index]);
64
+ };
65
+ /** The block each block was moved from, as the block cache keeps it. */
66
+ const origins = /* @__PURE__ */ new WeakMap();
67
+ /** The key last given to a block or to blocks moved from an origin. */
68
+ const keys = /* @__PURE__ */ new WeakMap();
69
+ /**
70
+ * Record that `block` is `origin`, the block kept for its paragraph, moved:
71
+ * the two show the same, positions aside.
72
+ */
73
+ const noteParagraphOrigin = (block, origin) => {
74
+ origins.set(block, origin);
75
+ };
76
+ /** `block`'s key: a recorded one while its values hold, else `compute`'s. */
77
+ const memoizedParagraphKey = (block, generation, compute) => {
78
+ const own = keys.get(block);
79
+ if (own && stillHolds(own, block, generation)) return own.key;
80
+ const origin = origins.get(block);
81
+ const moved = origin === void 0 ? void 0 : keys.get(origin);
82
+ if (moved && stillHolds(moved, block, generation)) {
83
+ keys.set(block, moved);
84
+ return moved.key;
85
+ }
86
+ const key = compute(block);
87
+ const recorded = record(block, key, generation);
88
+ keys.set(block, recorded);
89
+ if (origin !== void 0) keys.set(origin, recorded);
90
+ return key;
91
+ };
92
+ export { memoizedParagraphKey, noteParagraphOrigin };
@@ -559,6 +559,12 @@ export type ParagraphAttrs = {
559
559
  date?: string;
560
560
  revisionId?: number;
561
561
  };
562
+ /**
563
+ * Set when the paragraph holds a pending formatting change: of its own
564
+ * properties (`w:pPrChange`) or of a run in it (`w:rPrChange`). The text
565
+ * paints with its current formatting, so the change bar is what shows it.
566
+ */
567
+ formattingRevision?: true;
562
568
  /**
563
569
  * When the marker text contains a TAB character (\t), the marker is
564
570
  * rendered as a flex layout with two slots; this is the column offset
@@ -1,3 +1,4 @@
1
+ import { hasPaintedStart } from "../utils/paintedPositions.js";
1
2
  import { pixelsToEmu } from "../utils/units.js";
2
3
  // src/layout-painter/imageLayout.ts
3
4
  const LAYOUT_IMAGE_CLASSES = {
@@ -30,7 +31,7 @@ function findImageElement(target) {
30
31
  if (!(target instanceof HTMLElement)) return null;
31
32
  if (target.tagName === "IMG" && target.classList.contains(LAYOUT_IMAGE_CLASSES.runImage)) return target;
32
33
  const container = target.closest(IMAGE_HIT_SELECTOR);
33
- if (container && container.dataset["pmStart"]) return container;
34
+ if (container && hasPaintedStart(container)) return container;
34
35
  return null;
35
36
  }
36
37
  /**
@@ -0,0 +1,10 @@
1
+ import { resolveFontFamily } from "../utils/fontResolver.js";
2
+ type PageShellStyleProperty = "position" | "width" | "height" | "backgroundColor" | "color" | "overflow" | "border" | "boxShadow" | "outline" | "fontFamily" | "fontSize";
3
+ export type PageShellStyleOptions = NonNullable<Parameters<typeof resolveFontFamily>[1]> & {
4
+ backgroundColor?: string | undefined;
5
+ };
6
+ /** The shell's styles for a `width` x `height` page, one value per property. */
7
+ export declare const pageShellStyles: (width: number, height: number, options: PageShellStyleOptions) => Readonly<Record<PageShellStyleProperty, string>>;
8
+ /** Give `element` the shell styles, each property written once. */
9
+ export declare const applyPageShellStyles: (element: HTMLElement, width: number, height: number, options: PageShellStyleOptions) => void;
10
+ export {};
@@ -0,0 +1,32 @@
1
+ import { DEFAULT_FONT_FAMILY } from "../layout-engine/measure/measureHelpers.js";
2
+ import { resolveFontFamily } from "../utils/fontResolver.js";
3
+ // src/layout-painter/pageShellStyles.ts
4
+ /**
5
+ * The inline styles of a painted page's shell.
6
+ *
7
+ * Every layout pass applies them to every page shell. The page's text
8
+ * inherits colour and font from the shell, so a property written to another
9
+ * value and back within a pass restyles every line painted on the page, on
10
+ * every keystroke. Each property therefore appears once, with its final
11
+ * value: writing a value the shell already holds changes nothing.
12
+ */
13
+ /** The shell's styles for a `width` x `height` page, one value per property. */
14
+ const pageShellStyles = (width, height, options) => ({
15
+ position: "relative",
16
+ width: `${width}px`,
17
+ height: `${height}px`,
18
+ backgroundColor: options.backgroundColor ?? "var(--doc-canvas, #ffffff)",
19
+ color: "var(--doc-canvas-text, #000)",
20
+ overflow: "hidden",
21
+ border: "none",
22
+ boxShadow: "none",
23
+ outline: "none",
24
+ fontFamily: resolveFontFamily(DEFAULT_FONT_FAMILY, options).cssFallback,
25
+ fontSize: `${1056 / 72}px`
26
+ });
27
+ /** Give `element` the shell styles, each property written once. */
28
+ const applyPageShellStyles = (element, width, height, options) => {
29
+ const styles = pageShellStyles(width, height, options);
30
+ for (const property of Object.keys(styles)) element.style[property] = styles[property];
31
+ };
32
+ export { applyPageShellStyles, pageShellStyles };
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Bring a painted page's content up to a fresh rendering of it while keeping
3
+ * the painted nodes that did not change. Replacing the whole content area for
4
+ * one edited paragraph makes the browser restyle, lay out, paint and raster
5
+ * every line on the page; keeping the unchanged nodes limits that to the
6
+ * paragraphs the edit touched.
7
+ */
8
+ /**
9
+ * Make `painted` equal to `fresh` (as `isEqualNode` compares them), keeping
10
+ * every node of `painted` that shows what its counterpart in `fresh` shows and
11
+ * moving in from `fresh` only the smallest subtrees that differ: an edit in
12
+ * one table cell replaces that cell's changed line, not the table. Returns
13
+ * false, changing nothing, when the two differ in their own attributes or in
14
+ * their number of children: the caller then replaces `painted` whole.
15
+ *
16
+ * The fresh nodes it moves leave `fresh`; what remains there is the caller's
17
+ * to release.
18
+ */
19
+ export declare const reconcileRenderedContent: (painted: Element, fresh: Element) => boolean;
@@ -0,0 +1,117 @@
1
+ import { releaseDisplayPageResources } from "../display-list/pageResourceOwnership.js";
2
+ import { PAINTED_POSITION_ATTRIBUTES } from "../utils/paintedPositions.js";
3
+ // src/layout-painter/reconcileRenderedContent.ts
4
+ /**
5
+ * Bring a painted page's content up to a fresh rendering of it while keeping
6
+ * the painted nodes that did not change. Replacing the whole content area for
7
+ * one edited paragraph makes the browser restyle, lay out, paint and raster
8
+ * every line on the page; keeping the unchanged nodes limits that to the
9
+ * paragraphs the edit touched.
10
+ */
11
+ /**
12
+ * The attributes that say where a painted node stands in the editor document.
13
+ * An edit before a paragraph shifts them without changing what it shows, so a
14
+ * node that differs from its fresh rendering only in these is kept and takes
15
+ * the fresh values.
16
+ */
17
+ const POSITION_ATTRIBUTES = PAINTED_POSITION_ATTRIBUTES;
18
+ const sameAttributes = (painted, fresh, ignoring) => {
19
+ if (painted.attributes.length !== fresh.attributes.length) return false;
20
+ for (const attribute of Array.from(fresh.attributes)) {
21
+ if (ignoring.has(attribute.name)) {
22
+ if (!painted.hasAttribute(attribute.name)) return false;
23
+ continue;
24
+ }
25
+ if (painted.getAttribute(attribute.name) !== attribute.value) return false;
26
+ }
27
+ return true;
28
+ };
29
+ const NO_ATTRIBUTES = /* @__PURE__ */ new Set();
30
+ /** Whether `painted` shows what `fresh` shows, positions aside. */
31
+ const showsTheSame = (painted, fresh) => {
32
+ if (painted.nodeType !== fresh.nodeType) return false;
33
+ if (painted.nodeType !== painted.ELEMENT_NODE) return painted.isEqualNode(fresh);
34
+ const paintedElement = painted;
35
+ const freshElement = fresh;
36
+ if (paintedElement.namespaceURI !== freshElement.namespaceURI || paintedElement.localName !== freshElement.localName || !sameAttributes(paintedElement, freshElement, POSITION_ATTRIBUTES)) return false;
37
+ const paintedChildren = painted.childNodes;
38
+ const freshChildren = fresh.childNodes;
39
+ if (paintedChildren.length !== freshChildren.length) return false;
40
+ for (let index = 0; index < freshChildren.length; index += 1) {
41
+ const paintedChild = paintedChildren[index];
42
+ const freshChild = freshChildren[index];
43
+ if (!paintedChild || !freshChild || !showsTheSame(paintedChild, freshChild)) return false;
44
+ }
45
+ return true;
46
+ };
47
+ /** Give `painted` its own position attributes from `fresh`. */
48
+ const takeOwnPositions = (painted, fresh) => {
49
+ for (const name of POSITION_ATTRIBUTES) {
50
+ const value = fresh.getAttribute(name);
51
+ if (value !== null && painted.getAttribute(name) !== value) painted.setAttribute(name, value);
52
+ }
53
+ };
54
+ /** Give `painted` the position attributes of `fresh`, which shows the same. */
55
+ const takePositions = (painted, fresh) => {
56
+ if (painted.nodeType !== painted.ELEMENT_NODE) return;
57
+ takeOwnPositions(painted, fresh);
58
+ const paintedChildren = painted.childNodes;
59
+ const freshChildren = fresh.childNodes;
60
+ for (let index = 0; index < freshChildren.length; index += 1) {
61
+ const paintedChild = paintedChildren[index];
62
+ const freshChild = freshChildren[index];
63
+ if (paintedChild && freshChild) takePositions(paintedChild, freshChild);
64
+ }
65
+ };
66
+ /**
67
+ * Whether `painted` can stay with `fresh`'s position attributes while its
68
+ * children are brought up to `fresh`'s one by one.
69
+ */
70
+ const sameShell = (painted, fresh) => {
71
+ if (painted.nodeType !== painted.ELEMENT_NODE || fresh.nodeType !== fresh.ELEMENT_NODE) return false;
72
+ const paintedElement = painted;
73
+ const freshElement = fresh;
74
+ return paintedElement.namespaceURI === freshElement.namespaceURI && paintedElement.localName === freshElement.localName && painted.childNodes.length === fresh.childNodes.length && sameAttributes(paintedElement, freshElement, POSITION_ATTRIBUTES);
75
+ };
76
+ /**
77
+ * Bring each child of `painted` up to its counterpart in `fresh`: keep it when
78
+ * it shows the same, descend into it when only some of its children differ,
79
+ * and move the fresh one in otherwise. The two have as many children.
80
+ */
81
+ const reconcileChildren = (painted, fresh) => {
82
+ const paintedChildren = Array.from(painted.childNodes);
83
+ const freshChildren = Array.from(fresh.childNodes);
84
+ for (const [index, freshChild] of freshChildren.entries()) {
85
+ const paintedChild = paintedChildren[index];
86
+ if (!paintedChild) continue;
87
+ if (paintedChild.isEqualNode(freshChild)) continue;
88
+ if (showsTheSame(paintedChild, freshChild)) {
89
+ takePositions(paintedChild, freshChild);
90
+ continue;
91
+ }
92
+ if (sameShell(paintedChild, freshChild)) {
93
+ takeOwnPositions(paintedChild, freshChild);
94
+ reconcileChildren(paintedChild, freshChild);
95
+ continue;
96
+ }
97
+ if (paintedChild.nodeType === paintedChild.ELEMENT_NODE) releaseDisplayPageResources(paintedChild);
98
+ paintedChild.replaceWith(freshChild);
99
+ }
100
+ };
101
+ /**
102
+ * Make `painted` equal to `fresh` (as `isEqualNode` compares them), keeping
103
+ * every node of `painted` that shows what its counterpart in `fresh` shows and
104
+ * moving in from `fresh` only the smallest subtrees that differ: an edit in
105
+ * one table cell replaces that cell's changed line, not the table. Returns
106
+ * false, changing nothing, when the two differ in their own attributes or in
107
+ * their number of children: the caller then replaces `painted` whole.
108
+ *
109
+ * The fresh nodes it moves leave `fresh`; what remains there is the caller's
110
+ * to release.
111
+ */
112
+ const reconcileRenderedContent = (painted, fresh) => {
113
+ if (painted.localName !== fresh.localName || !sameAttributes(painted, fresh, NO_ATTRIBUTES) || painted.childNodes.length !== fresh.childNodes.length) return false;
114
+ reconcileChildren(painted, fresh);
115
+ return true;
116
+ };
117
+ export { reconcileRenderedContent };
@@ -1,3 +1,4 @@
1
+ import { writePaintedRange } from "../utils/paintedPositions.js";
1
2
  import { applySdtDataAttrs } from "./sdtBoundary.js";
2
3
  // src/layout-painter/renderFragment.ts
3
4
  /**
@@ -50,8 +51,7 @@ function renderParagraphFragmentPlaceholder(fragment, _context, doc) {
50
51
  el.dataset["blockId"] = String(fragment.blockId);
51
52
  el.dataset["fromLine"] = String(fragment.fromLine);
52
53
  el.dataset["toLine"] = String(fragment.toLine);
53
- if (fragment.pmStart !== void 0) el.dataset["pmStart"] = String(fragment.pmStart);
54
- if (fragment.pmEnd !== void 0) el.dataset["pmEnd"] = String(fragment.pmEnd);
54
+ writePaintedRange(el, fragment.pmStart, fragment.pmEnd);
55
55
  if (fragment.continuesFromPrev) el.dataset["continuesFromPrev"] = "true";
56
56
  if (fragment.continuesOnNext) el.dataset["continuesOnNext"] = "true";
57
57
  applySdtDataAttrs(el, fragment.sdtGroups);
@@ -70,8 +70,7 @@ function renderTableFragmentPlaceholder(fragment, _context, doc) {
70
70
  el.dataset["blockId"] = String(fragment.blockId);
71
71
  el.dataset["fromRow"] = String(fragment.fromRow);
72
72
  el.dataset["toRow"] = String(fragment.toRow);
73
- if (fragment.pmStart !== void 0) el.dataset["pmStart"] = String(fragment.pmStart);
74
- if (fragment.pmEnd !== void 0) el.dataset["pmEnd"] = String(fragment.pmEnd);
73
+ writePaintedRange(el, fragment.pmStart, fragment.pmEnd);
75
74
  applySdtDataAttrs(el, fragment.sdtGroups);
76
75
  return el;
77
76
  }
@@ -83,8 +82,7 @@ function renderImageFragmentPlaceholder(fragment, _context, doc) {
83
82
  el.className = `${FRAGMENT_CLASS_NAMES.fragment} ${FRAGMENT_CLASS_NAMES.image}`;
84
83
  applyBaseFragmentStyles(el);
85
84
  el.dataset["blockId"] = String(fragment.blockId);
86
- if (fragment.pmStart !== void 0) el.dataset["pmStart"] = String(fragment.pmStart);
87
- if (fragment.pmEnd !== void 0) el.dataset["pmEnd"] = String(fragment.pmEnd);
85
+ writePaintedRange(el, fragment.pmStart, fragment.pmEnd);
88
86
  if (fragment.isAnchored) el.dataset["anchored"] = "true";
89
87
  if (fragment.zIndex !== void 0) el.style.zIndex = String(fragment.zIndex);
90
88
  return el;
@@ -1,4 +1,5 @@
1
1
  import { imageLuminanceFilter } from "../utils/imageLuminance.js";
2
+ import { writePaintedRange } from "../utils/paintedPositions.js";
2
3
  import { applySanitizedImageSrc } from "../utils/sanitizeImageSrc.js";
3
4
  import { anchorTargetAttrs, sanitizeExternalUrl } from "../utils/urlSecurity.js";
4
5
  import { paintedImageSource } from "./previewSvg.js";
@@ -137,8 +138,7 @@ function renderImageFragment(fragment, block, _measure, _context, options = {})
137
138
  if (fragment.zIndex !== void 0) containerEl.style.zIndex = String(fragment.zIndex);
138
139
  if (block.anchor?.behindDoc) containerEl.style.zIndex = "-1";
139
140
  containerEl.dataset["blockId"] = String(fragment.blockId);
140
- if (fragment.pmStart !== void 0) containerEl.dataset["pmStart"] = String(fragment.pmStart);
141
- if (fragment.pmEnd !== void 0) containerEl.dataset["pmEnd"] = String(fragment.pmEnd);
141
+ writePaintedRange(containerEl, fragment.pmStart, fragment.pmEnd);
142
142
  const imgEl = doc.createElement("img");
143
143
  applySanitizedImageSrc(imgEl, paintedImageSource(block));
144
144
  imgEl.alt = block.alt ?? "";
@@ -13,11 +13,14 @@ import { cssBorderStyle } from "../utils/borderCss.js";
13
13
  import { resolveFontFamily } from "../utils/fontResolver.js";
14
14
  import { borderToStyle } from "../utils/formatToStyle.js";
15
15
  import { normalizeHorizontalScalePercent } from "../utils/horizontalScale.js";
16
+ import { shiftPaintedPositions, writePaintedRange } from "../utils/paintedPositions.js";
16
17
  import { pageHorizontalColumns, paragraphInlinePictureViewport } from "../utils/paragraphInlineLayout.js";
17
18
  import { applySanitizedImageSrc } from "../utils/sanitizeImageSrc.js";
18
19
  import { eighthsToPixels, pointsToPixels } from "../utils/units.js";
19
20
  import { resolveAnchoredImagePosition as resolveAnchoredImagePosition$1 } from "./anchoredImagePosition.js";
21
+ import { applyPageShellStyles } from "./pageShellStyles.js";
20
22
  import { paintedImageSource } from "./previewSvg.js";
23
+ import { reconcileRenderedContent } from "./reconcileRenderedContent.js";
21
24
  import { renderFragment } from "./renderFragment.js";
22
25
  import { applyImageVisualAttrs, hasImageVisualAttrs, renderImageFragment } from "./renderImage.js";
23
26
  import { renderParagraphFragment } from "./renderParagraph.js";
@@ -58,18 +61,7 @@ const windowOfNote = (windows, noteId) => windows?.find((candidate) => candidate
58
61
  * Apply page styles to an element
59
62
  */
60
63
  function applyPageStyles(element, width, height, options) {
61
- element.style.position = "relative";
62
- element.style.width = `${width}px`;
63
- element.style.height = `${height}px`;
64
- element.style.backgroundColor = options.backgroundColor ?? "var(--doc-canvas, #ffffff)";
65
- element.style.color = "var(--doc-canvas-text, #1f2937)";
66
- element.style.overflow = "hidden";
67
- element.style.border = "none";
68
- element.style.boxShadow = "none";
69
- element.style.outline = "none";
70
- element.style.fontFamily = resolveFontFamily(DEFAULT_FONT_FAMILY, options).cssFallback;
71
- element.style.fontSize = `${1056 / 72}px`;
72
- element.style.color = "var(--doc-canvas-text, #000)";
64
+ applyPageShellStyles(element, width, height, options);
73
65
  }
74
66
  function pageBorderShouldRender(pageNumber, display) {
75
67
  switch (display ?? "allPages") {
@@ -440,8 +432,7 @@ function renderFloatingImagesLayer(floatingImages, doc, layerMode = "front") {
440
432
  container.style.pointerEvents = "auto";
441
433
  container.style.top = `${floatImg.y}px`;
442
434
  container.style.left = `${floatImg.x}px`;
443
- if (floatImg.pmStart !== void 0) container.dataset["pmStart"] = String(floatImg.pmStart);
444
- if (floatImg.pmEnd !== void 0) container.dataset["pmEnd"] = String(floatImg.pmEnd);
435
+ writePaintedRange(container, floatImg.pmStart, floatImg.pmEnd);
445
436
  const img = doc.createElement("img");
446
437
  applySanitizedImageSrc(img, paintedImageSource(floatImg));
447
438
  img.style.width = `${floatImg.width}px`;
@@ -594,8 +585,7 @@ function renderHeaderFooterContent(content, context, options, layout) {
594
585
  img.height = floatImg.height;
595
586
  if (floatImg.alt) img.alt = floatImg.alt;
596
587
  img.classList.add("layout-run", "layout-run-image");
597
- if (floatImg.pmStart !== void 0) img.dataset["pmStart"] = String(floatImg.pmStart);
598
- if (floatImg.pmEnd !== void 0) img.dataset["pmEnd"] = String(floatImg.pmEnd);
588
+ writePaintedRange(img, floatImg.pmStart, floatImg.pmEnd);
599
589
  img.style.position = "absolute";
600
590
  img.style.display = "block";
601
591
  img.style.width = `${floatImg.width}px`;
@@ -1900,7 +1890,7 @@ function repopulatePageContent(shell, pageDataMap, totalPages, options) {
1900
1890
  if (newFontStyle && oldFontStyle) replaceRenderedPageElement(oldFontStyle, newFontStyle);
1901
1891
  else if (newFontStyle) shell.prepend(newFontStyle);
1902
1892
  else if (oldFontStyle) removeRenderedPage(oldFontStyle);
1903
- replaceRenderedPageElement(oldContentEl, newContentEl);
1893
+ if (!reconcileRenderedContent(oldContentEl, newContentEl)) replaceRenderedPageElement(oldContentEl, newContentEl);
1904
1894
  syncPageWatermarkOverlay(shell, data.page, pageOptions, options.document ?? document);
1905
1895
  releaseDisplayPageResources(fullPageEl);
1906
1896
  return;
@@ -1914,11 +1904,7 @@ function syncRenderedPmPositionData(shell, oldPage, newPage) {
1914
1904
  const delta = getUniformPagePositionDelta(oldPage, newPage);
1915
1905
  if (delta === null) return false;
1916
1906
  if (delta === 0) return true;
1917
- for (const element of shell.querySelectorAll("[data-pm-start], [data-pm-end], [data-table-pm-start]")) {
1918
- shiftNumericDatasetValue(element, "pmStart", delta);
1919
- shiftNumericDatasetValue(element, "pmEnd", delta);
1920
- shiftNumericDatasetValue(element, "tablePmStart", delta);
1921
- }
1907
+ shiftPaintedPositions(shell, delta);
1922
1908
  return true;
1923
1909
  }
1924
1910
  function getUniformPagePositionDelta(oldPage, newPage) {
@@ -1947,13 +1933,6 @@ function readPositionDelta(previous, next) {
1947
1933
  if (previous === void 0 || next === void 0) return null;
1948
1934
  return next - previous;
1949
1935
  }
1950
- function shiftNumericDatasetValue(element, key, delta) {
1951
- const value = element.dataset[key];
1952
- if (value === void 0) return;
1953
- const numeric = Number(value);
1954
- if (!Number.isFinite(numeric)) return;
1955
- element.dataset[key] = String(numeric + delta);
1956
- }
1957
1936
  function syncPageShellFingerprints(shell, data, options) {
1958
1937
  const pageState = shell.parentElement?.__pageRenderState?.pageStates[data.index];
1959
1938
  if (!pageState || pageState.element !== shell) return;
@@ -16,6 +16,7 @@ import { resolveFontFamily } from "../utils/fontResolver.js";
16
16
  import "../utils/fontWeights.js";
17
17
  import { underlineDecorationCss } from "../utils/formatToStyle.js";
18
18
  import { getHorizontalScaleFactor } from "../utils/horizontalScale.js";
19
+ import { writePaintedRange } from "../utils/paintedPositions.js";
19
20
  import { getParagraphFrame } from "../utils/paragraphFrame.js";
20
21
  import { inlinePictureClipInsets, resolveParagraphLineGeometryForBlock, resolvePhysicalParagraphInlineLayout } from "../utils/paragraphInlineLayout.js";
21
22
  import { inlineImageBoundingBox, parseRotationDegrees, rotatedBoundingBox } from "../utils/rotationBoundingBox.js";
@@ -345,8 +346,7 @@ function reserveScaledAdvance({ element, unscaledWidth, horizontalScale, visualS
345
346
  * Apply PM position data attributes
346
347
  */
347
348
  function applyPmPositions(element, pmStart, pmEnd) {
348
- if (pmStart !== void 0) element.dataset["pmStart"] = String(pmStart);
349
- if (pmEnd !== void 0) element.dataset["pmEnd"] = String(pmEnd);
349
+ writePaintedRange(element, pmStart, pmEnd);
350
350
  }
351
351
  const NON_COMPRESSIBLE_WHITESPACE_PATTERN = /([^\S ]+)/gu;
352
352
  const HAS_NON_COMPRESSIBLE_WHITESPACE_PATTERN = /[^\S ]/u;
@@ -1613,7 +1613,7 @@ function bordersFormGroup(a, b) {
1613
1613
  if (!a || !b) return false;
1614
1614
  return bordersEqual(a.top, b.top) && bordersEqual(a.bottom, b.bottom) && bordersEqual(a.left, b.left) && bordersEqual(a.right, b.right) && bordersEqual(a.between, b.between);
1615
1615
  }
1616
- const paragraphHasTrackedChanges = (block) => block.reviewIndicator === "change-bar" || block.attrs?.listMarkerRevision !== void 0 || block.runs.some((run) => run.kind !== "lineBreak" && (run.isInsertion === true || run.isDeletion === true));
1616
+ const paragraphHasTrackedChanges = (block) => block.reviewIndicator === "change-bar" || block.attrs?.listMarkerRevision !== void 0 || block.attrs?.formattingRevision === true || block.runs.some((run) => run.kind !== "lineBreak" && (run.isInsertion === true || run.isDeletion === true));
1617
1617
  /**
1618
1618
  * Render a paragraph fragment
1619
1619
  *
@@ -7,6 +7,7 @@ import { resolveTableInlineOffset, resolveTableInlinePlacement } from "../layout
7
7
  import { bandFromOrigin, isOutsideBand, tableHasFloatingCellContent, tableRowPaintBottom } from "../layout-engine/measure/tableVisibleBand.js";
8
8
  import { isFloatingTextBoxBlock, resolveTableCellPadding, tableColumnsArePinned } from "../layout-engine/types.js";
9
9
  import { paintsCssBorder } from "../utils/borderCss.js";
10
+ import { writePaintedRange, writePaintedTableStart } from "../utils/paintedPositions.js";
10
11
  import { applySanitizedImageSrc } from "../utils/sanitizeImageSrc.js";
11
12
  import { emuToPixels } from "../utils/units.js";
12
13
  import { resolveAnchoredImagePosition } from "./anchoredImagePosition.js";
@@ -100,8 +101,7 @@ function renderCellContent({ cell, cellMeasure, context, doc, contentWidthOverri
100
101
  imgContainer.style.left = `${img.x}px`;
101
102
  imgContainer.style.top = `${img.y}px`;
102
103
  imgContainer.style.pointerEvents = "auto";
103
- if (img.pmStart !== void 0) imgContainer.dataset["pmStart"] = String(img.pmStart);
104
- if (img.pmEnd !== void 0) imgContainer.dataset["pmEnd"] = String(img.pmEnd);
104
+ writePaintedRange(imgContainer, img.pmStart, img.pmEnd);
105
105
  const imgEl = doc.createElement("img");
106
106
  applySanitizedImageSrc(imgEl, paintedImageSource(img));
107
107
  imgEl.style.width = `${img.width}px`;
@@ -298,8 +298,7 @@ function renderNestedTable(block, measure, context, doc, frameWidth = context.co
298
298
  tableEl.style.marginRight = `${placement.offset}px`;
299
299
  } else tableEl.style.marginLeft = `${placement.offset}px`;
300
300
  tableEl.dataset["blockId"] = String(block.id);
301
- if (block.pmStart !== void 0) tableEl.dataset["pmStart"] = String(block.pmStart);
302
- if (block.pmEnd !== void 0) tableEl.dataset["pmEnd"] = String(block.pmEnd);
301
+ writePaintedRange(tableEl, block.pmStart, block.pmEnd);
303
302
  const rowYPositions = [];
304
303
  let yPos = 0;
305
304
  for (const i_item of measure.rows) {
@@ -498,8 +497,7 @@ function renderTableCell({ cell, cellMeasure, x, y = 0, width, rowHeight, border
498
497
  const firstBlock = cell.blocks.at(0);
499
498
  const lastBlock = cell.blocks.at(-1);
500
499
  const pmStart = firstBlock !== void 0 && "pmStart" in firstBlock ? firstBlock.pmStart : void 0;
501
- if (pmStart !== void 0) cellEl.dataset["pmStart"] = String(pmStart);
502
- if (lastBlock && "pmEnd" in lastBlock) cellEl.dataset["pmEnd"] = String(lastBlock.pmEnd);
500
+ writePaintedRange(cellEl, pmStart, lastBlock && "pmEnd" in lastBlock ? lastBlock.pmEnd : void 0);
503
501
  }
504
502
  return cellEl;
505
503
  }
@@ -639,8 +637,7 @@ function renderTableFragment(fragment, block, measure, context, options = {}) {
639
637
  tableEl.dataset["blockId"] = String(fragment.blockId);
640
638
  tableEl.dataset["fromRow"] = String(fragment.fromRow);
641
639
  tableEl.dataset["toRow"] = String(fragment.toRow);
642
- if (fragment.pmStart !== void 0) tableEl.dataset["pmStart"] = String(fragment.pmStart);
643
- if (fragment.pmEnd !== void 0) tableEl.dataset["pmEnd"] = String(fragment.pmEnd);
640
+ writePaintedRange(tableEl, fragment.pmStart, fragment.pmEnd);
644
641
  const tableColumnsWidth = block.bidi ? measure.columnWidths.reduce((sum, columnWidth) => sum + columnWidth, 0) : 0;
645
642
  let handleX = 0;
646
643
  for (let col = 0; col < measure.columnWidths.length - 1; col++) {
@@ -658,7 +655,7 @@ function renderTableFragment(fragment, block, measure, context, options = {}) {
658
655
  handle.dataset["columnIndex"] = String(col);
659
656
  handle.dataset["tableBlockId"] = String(fragment.blockId);
660
657
  if (block.bidi) handle.dataset["bidi"] = "true";
661
- if (fragment.pmStart !== void 0) handle.dataset["tablePmStart"] = String(fragment.pmStart);
658
+ if (fragment.pmStart !== void 0) writePaintedTableStart(handle, fragment.pmStart);
662
659
  tableEl.append(handle);
663
660
  }
664
661
  const rowYPositions = [];
@@ -805,7 +802,7 @@ function renderTableFragment(fragment, block, measure, context, options = {}) {
805
802
  rowHandle.style.zIndex = "10";
806
803
  rowHandle.dataset["rowIndex"] = String(rowIdx);
807
804
  rowHandle.dataset["tableBlockId"] = String(fragment.blockId);
808
- if (fragment.pmStart !== void 0) rowHandle.dataset["tablePmStart"] = String(fragment.pmStart);
805
+ if (fragment.pmStart !== void 0) writePaintedTableStart(rowHandle, fragment.pmStart);
809
806
  tableEl.append(rowHandle);
810
807
  }
811
808
  }
@@ -822,7 +819,7 @@ function renderTableFragment(fragment, block, measure, context, options = {}) {
822
819
  bottomHandle.dataset["rowIndex"] = String(block.rows.length - 1);
823
820
  bottomHandle.dataset["tableBlockId"] = String(fragment.blockId);
824
821
  bottomHandle.dataset["isEdge"] = "bottom";
825
- if (fragment.pmStart !== void 0) bottomHandle.dataset["tablePmStart"] = String(fragment.pmStart);
822
+ if (fragment.pmStart !== void 0) writePaintedTableStart(bottomHandle, fragment.pmStart);
826
823
  tableEl.append(bottomHandle);
827
824
  }
828
825
  if (fragment.toRow === block.rows.length) {
@@ -839,7 +836,7 @@ function renderTableFragment(fragment, block, measure, context, options = {}) {
839
836
  rightHandle.dataset["columnIndex"] = String(block.bidi ? 0 : measure.columnWidths.length - 1);
840
837
  rightHandle.dataset["tableBlockId"] = String(fragment.blockId);
841
838
  rightHandle.dataset["isEdge"] = "right";
842
- if (fragment.pmStart !== void 0) rightHandle.dataset["tablePmStart"] = String(fragment.pmStart);
839
+ if (fragment.pmStart !== void 0) writePaintedTableStart(rightHandle, fragment.pmStart);
843
840
  tableEl.append(rightHandle);
844
841
  }
845
842
  return tableEl;
@@ -2,6 +2,7 @@ import { layoutTextBoxContent } from "../layout-engine/measure/textBoxParagraphL
2
2
  import { DEFAULT_TEXTBOX_MARGINS } from "../layout-engine/types.js";
3
3
  import { presetDashForOutlineAttr } from "../types/documentEnumValues.js";
4
4
  import { cssBorderStyleForDash } from "../utils/borderCss.js";
5
+ import { writePaintedRange } from "../utils/paintedPositions.js";
5
6
  import { setAuthoredBackgroundColor } from "./documentColors.js";
6
7
  import { renderParagraphFragment } from "./renderParagraph.js";
7
8
  import { panic } from "better-result";
@@ -69,8 +70,7 @@ function renderTextBoxFragment(fragment, block, measure, context, options = {})
69
70
  containerEl.style.justifyContent = block.verticalAlign === "middle" ? "center" : "flex-end";
70
71
  }
71
72
  containerEl.dataset["blockId"] = String(fragment.blockId);
72
- if (fragment.pmStart !== void 0) containerEl.dataset["pmStart"] = String(fragment.pmStart);
73
- if (fragment.pmEnd !== void 0) containerEl.dataset["pmEnd"] = String(fragment.pmEnd);
73
+ writePaintedRange(containerEl, fragment.pmStart, fragment.pmEnd);
74
74
  const innerWidth = fragment.width - margins.left - margins.right;
75
75
  const contentLayout = layoutTextBoxContent(block.content, measure.innerMeasures);
76
76
  for (let i = 0; i < block.content.length; i++) {
@@ -1,3 +1,4 @@
1
+ import { readPaintedContentControlKey, writePaintedContentControlKey } from "../utils/paintedPositions.js";
1
2
  // src/layout-painter/sdtBoundary.ts
2
3
  function applySdtDataAttrs(el, sdtGroups) {
3
4
  if (!sdtGroups || sdtGroups.length === 0) return;
@@ -5,7 +6,7 @@ function applySdtDataAttrs(el, sdtGroups) {
5
6
  const innermost = sdtGroups.at(-1);
6
7
  if (innermost) {
7
8
  el.dataset["sdtId"] = innermost.id;
8
- el.dataset["sdtPmPos"] = String(innermost.pmPos);
9
+ writePaintedContentControlKey(el, innermost.pmPos);
9
10
  el.dataset["sdtType"] = innermost.sdtType;
10
11
  if (innermost.position) el.dataset["sdtPosition"] = innermost.position;
11
12
  if (innermost.alias) el.dataset["sdtAlias"] = innermost.alias;
@@ -58,7 +59,7 @@ function enclosingSdtGroupIds(doc, from, to) {
58
59
  function applySdtFocus(container, focusedIds) {
59
60
  const boxes = container.querySelectorAll("[data-sdt-boundary]");
60
61
  for (const box of boxes) {
61
- const id = box.dataset["sdtPmPos"];
62
+ const id = readPaintedContentControlKey(box);
62
63
  const on = id != null && focusedIds.has(id);
63
64
  if (on !== box.classList.contains("is-focused")) box.classList.toggle("is-focused", on);
64
65
  }
@@ -1,7 +1,8 @@
1
1
  import { resolveSequentialBlockAnchor } from "../ai-edits/blockRange.js";
2
2
  import { PAINTER_PAINTED_EVENT, findPageShellForPmPos } from "../layout-painter/renderPage.js";
3
+ import { PAINTED_START_SELECTOR, readPaintedStart } from "../utils/paintedPositions.js";
3
4
  // src/paged-layout/blockGeometry.ts
4
- const PAINTED_BLOCK_SELECTOR = "[data-block-id][data-pm-start]";
5
+ const PAINTED_BLOCK_SELECTOR = `[data-block-id]${PAINTED_START_SELECTOR}`;
5
6
  const PAGE_SELECTOR = "[data-page-number]";
6
7
  const pageNumberOf = (page) => {
7
8
  const raw = page.dataset["pageNumber"];
@@ -23,7 +24,7 @@ const requestedBlocks = (blockIds, snapshot) => {
23
24
  const paintedBlocksByPmStart = (page) => {
24
25
  const blocks = /* @__PURE__ */ new Map();
25
26
  for (const element of page.querySelectorAll(PAINTED_BLOCK_SELECTOR)) {
26
- const pmStart = Number(element.dataset["pmStart"]);
27
+ const pmStart = readPaintedStart(element) ?? NaN;
27
28
  if (Number.isFinite(pmStart) && !blocks.has(pmStart)) blocks.set(pmStart, element);
28
29
  }
29
30
  return blocks;
@@ -1,6 +1,15 @@
1
1
  export declare const getEditorScrollRoot: (element: HTMLElement | null) => HTMLElement | null;
2
2
  /** Resolve the root even when a caller holds a painted descendant or viewport. */
3
3
  export declare const scrollEditorTo: (element: HTMLElement | null, options: ScrollToOptions) => void;
4
+ /**
5
+ * Scroll a box that only clips (such as the hidden editor's wrapper) back to
6
+ * its origin. It is not the editor's scroll root; the browser scrolls it to
7
+ * reveal a caret, and nothing it shows may move with that scroll.
8
+ */
9
+ export declare const scrollClipBoxToOrigin: (box: {
10
+ scrollLeft: number;
11
+ scrollTop: number;
12
+ }) => void;
4
13
  export declare const scrollEditorBy: (element: HTMLElement | null, delta: number) => void;
5
14
  type ScrollEditorElementOptions = {
6
15
  block?: "start" | "center" | "end" | "nearest";