@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.
- package/dist/ai-edits/headless.js +2 -2
- package/dist/ai-edits/newListNumbering.d.ts +14 -1
- package/dist/ai-edits/newListNumbering.js +24 -1
- package/dist/ai-edits/pending-suggestions.js +2 -2
- package/dist/controller/canonicalClipboard.js +2 -2
- package/dist/controller/canonicalComposition.js +34 -5
- package/dist/controller/canonicalInput.js +4 -6
- package/dist/controller/canonicalLockGuard.d.ts +17 -2
- package/dist/controller/canonicalLockGuard.js +46 -1
- package/dist/controller/canonicalProjectionBlocks.d.ts +79 -0
- package/dist/controller/canonicalProjectionBlocks.js +75 -0
- package/dist/controller/canonicalPublicOperations.js +476 -100
- package/dist/controller/canonicalSeedContent.d.ts +12 -0
- package/dist/controller/canonicalSeedContent.js +131 -0
- package/dist/controller/canonicalSession.d.ts +53 -21
- package/dist/controller/canonicalSession.js +489 -210
- package/dist/controller/canonicalSourceNormalization.d.ts +21 -0
- package/dist/controller/canonicalSourceNormalization.js +148 -0
- package/dist/controller/canonicalStoryEditor.d.ts +1 -1
- package/dist/controller/canonicalStoryEditor.js +16 -12
- package/dist/controller/folioEditor.js +3 -0
- package/dist/controller/headerFooterEditorManager.d.ts +5 -0
- package/dist/controller/headerFooterEditorManager.js +7 -2
- package/dist/controller/hiddenEditorApi.d.ts +11 -2
- package/dist/controller/hiddenEditorApi.js +3 -0
- package/dist/controller/hiddenEditorManager.d.ts +7 -0
- package/dist/controller/hiddenEditorManager.js +66 -11
- package/dist/controller/layoutPipeline.js +2 -1
- package/dist/controller/layoutSession.d.ts +3 -0
- package/dist/controller/layoutSession.js +3 -1
- package/dist/controller/noteEditorManager.d.ts +5 -0
- package/dist/controller/noteEditorManager.js +7 -2
- package/dist/display-list/dom/renderDisplayListToDom.js +9 -7
- package/dist/document-operations.d.ts +1 -1
- package/dist/docx/canonicalSave.js +7 -2
- package/dist/docx/commentAnchorIndex.d.ts +19 -0
- package/dist/docx/commentAnchorIndex.js +55 -1
- package/dist/docx/containerChildren.js +1 -1
- package/dist/docx/contentTypeRegistry.js +1 -1
- package/dist/docx/hostCommentThreads.d.ts +11 -1
- package/dist/docx/hostCommentThreads.js +25 -2
- package/dist/docx/listModelNormalization.js +4 -5
- package/dist/docx/listNumberingInstances.d.ts +1 -1
- package/dist/docx/listNumberingInstances.js +2 -2
- package/dist/docx/numberingIds.d.ts +6 -0
- package/dist/docx/numberingIds.js +6 -1
- package/dist/docx/numberingReferenceNormalization.d.ts +4 -0
- package/dist/docx/numberingReferenceNormalization.js +12 -2
- package/dist/docx/paragraphPropertySource.d.ts +22 -0
- package/dist/docx/paragraphPropertySource.js +85 -16
- package/dist/docx/parser.js +2 -0
- package/dist/docx/removeHeaderFooterParts.js +1 -1
- package/dist/docx/reviewResolutionProvenance.js +72 -19
- package/dist/docx/serializer/documentSerializer.js +2 -1
- package/dist/docx/serializer/partNamespaces.d.ts +1 -1
- package/dist/docx/serializer/partNamespaces.js +1 -1
- package/dist/docx/server/build.d.ts +1 -1
- package/dist/docx/storyBlockReplay.js +15 -2
- package/dist/docx/structuralXmlPatch.js +25 -4
- package/dist/docx/xmlParser.d.ts +1 -1
- package/dist/docx/xmlParser.js +2 -3
- package/dist/i18n/messages/ar.gen.js +1 -0
- package/dist/i18n/messages/catalogs.gen.d.ts +17 -0
- package/dist/i18n/messages/catalogs.gen.js +17 -0
- package/dist/i18n/messages/cs.gen.js +1 -0
- package/dist/i18n/messages/de.gen.js +1 -0
- package/dist/i18n/messages/en.gen.js +1 -0
- package/dist/i18n/messages/es.gen.js +1 -0
- package/dist/i18n/messages/et.gen.js +1 -0
- package/dist/i18n/messages/fr.gen.js +1 -0
- package/dist/i18n/messages/he.gen.js +1 -0
- package/dist/i18n/messages/hi.gen.js +1 -0
- package/dist/i18n/messages/hu.gen.js +1 -0
- package/dist/i18n/messages/lt.gen.js +1 -0
- package/dist/i18n/messages/lv.gen.js +1 -0
- package/dist/i18n/messages/messages.gen.d.ts +1 -0
- package/dist/i18n/messages/pl.gen.js +1 -0
- package/dist/i18n/messages/pt-BR.gen.js +1 -0
- package/dist/i18n/messages/sk.gen.js +1 -0
- package/dist/i18n/messages/tr.gen.js +1 -0
- package/dist/i18n/messages/zh-CN.gen.js +1 -0
- package/dist/internal/pageBreakRunDescendantIndex.d.ts +7 -2
- package/dist/internal/pageBreakRunDescendantIndex.js +12 -3
- package/dist/internal/subtreeHolds.d.ts +12 -0
- package/dist/internal/subtreeHolds.js +25 -0
- package/dist/internal/wholeStoryRevisionResolution.js +1 -1
- package/dist/layout-bridge/cellSelectionHighlight.js +3 -3
- package/dist/layout-bridge/convert/flowBlockPostprocessing.js +20 -12
- package/dist/layout-bridge/convert/flowConversionShared.d.ts +15 -1
- package/dist/layout-bridge/convert/flowConversionShared.js +9 -1
- package/dist/layout-bridge/convert/paragraphAttrs.d.ts +15 -4
- package/dist/layout-bridge/convert/paragraphAttrs.js +11 -4
- package/dist/layout-bridge/convert/paragraphBlockCache.d.ts +26 -0
- package/dist/layout-bridge/convert/paragraphBlockCache.js +137 -0
- package/dist/layout-bridge/convert/paragraphConversion.d.ts +12 -2
- package/dist/layout-bridge/convert/paragraphConversion.js +37 -5
- package/dist/layout-bridge/convert/paragraphRuns.d.ts +2 -2
- package/dist/layout-bridge/convert/sectionBoundaries.js +16 -0
- package/dist/layout-bridge/convert/toFlowBlocks.js +144 -15
- package/dist/layout-bridge/convert/topLevelConversion.d.ts +74 -0
- package/dist/layout-bridge/convert/topLevelConversion.js +109 -0
- package/dist/layout-bridge/dom/clickToPositionDom.js +41 -40
- package/dist/layout-bridge/dom/findBodyPmSpans.js +4 -3
- package/dist/layout-bridge/dom/findHfPmSpans.js +10 -15
- package/dist/layout-bridge/dom/imeCaretAnchor.d.ts +8 -0
- package/dist/layout-bridge/dom/imeCaretAnchor.js +71 -7
- package/dist/layout-bridge/dom/textStreamDom.js +3 -2
- package/dist/layout-bridge/headerFooterLayout.js +12 -11
- package/dist/layout-bridge/tableInsertHover.js +2 -1
- package/dist/layout-engine/measure/cache.d.ts +2 -0
- package/dist/layout-engine/measure/cache.js +6 -1
- package/dist/layout-engine/measure/paragraphKeyMemo.d.ts +8 -0
- package/dist/layout-engine/measure/paragraphKeyMemo.js +92 -0
- package/dist/layout-engine/types.d.ts +6 -0
- package/dist/layout-painter/imageLayout.js +2 -1
- package/dist/layout-painter/pageShellStyles.d.ts +10 -0
- package/dist/layout-painter/pageShellStyles.js +32 -0
- package/dist/layout-painter/reconcileRenderedContent.d.ts +19 -0
- package/dist/layout-painter/reconcileRenderedContent.js +117 -0
- package/dist/layout-painter/renderFragment.js +4 -6
- package/dist/layout-painter/renderImage.js +2 -2
- package/dist/layout-painter/renderPage.js +8 -29
- package/dist/layout-painter/renderParagraph.js +3 -3
- package/dist/layout-painter/renderTable.js +9 -12
- package/dist/layout-painter/renderTextBox.js +2 -2
- package/dist/layout-painter/sdtBoundary.js +3 -2
- package/dist/paged-layout/blockGeometry.js +3 -2
- package/dist/paged-layout/editorScrollRoot.d.ts +9 -0
- package/dist/paged-layout/editorScrollRoot.js +10 -1
- package/dist/paged-layout/rangeProjection.js +5 -4
- package/dist/paged-layout/scrollToPmPosition.js +3 -3
- package/dist/paged-layout/selectionViewportRect.d.ts +6 -0
- package/dist/paged-layout/selectionViewportRect.js +8 -2
- package/dist/prosemirror/attrs/index.js +1 -0
- package/dist/prosemirror/commands/comments.d.ts +5 -2
- package/dist/prosemirror/commands/comments.js +88 -8
- package/dist/prosemirror/commentRecords.d.ts +137 -0
- package/dist/prosemirror/commentRecords.js +400 -0
- package/dist/prosemirror/conversion/fromProseDoc.js +9 -3
- package/dist/prosemirror/conversion/index.d.ts +1 -1
- package/dist/prosemirror/conversion/toProseDoc.d.ts +13 -4
- package/dist/prosemirror/conversion/toProseDoc.js +126 -38
- package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.d.ts +22 -0
- package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.js +61 -32
- package/dist/prosemirror/extensions/marks/CommentExtension.js +3 -1
- package/dist/prosemirror/extensions/nodes/CommentReferenceExtension.js +3 -1
- package/dist/prosemirror/index.d.ts +1 -1
- package/dist/prosemirror/nativeSelection.d.ts +33 -0
- package/dist/prosemirror/nativeSelection.js +74 -0
- package/dist/prosemirror/numberedRefFields.d.ts +2 -0
- package/dist/prosemirror/numberedRefFields.js +16 -5
- package/dist/prosemirror/paragraphMarkJoin.d.ts +6 -8
- package/dist/prosemirror/paragraphMarkJoin.js +155 -16
- package/dist/prosemirror/plugins/contentControlWidgets.js +2 -2
- package/dist/prosemirror/plugins/documentNumbering.js +33 -14
- package/dist/prosemirror/plugins/suggestionMode.js +13 -1
- package/dist/prosemirror/runIdentityAcrossRevisions.d.ts +23 -1
- package/dist/prosemirror/runIdentityAcrossRevisions.js +57 -8
- package/dist/prosemirror/schema/marks.d.ts +7 -1
- package/dist/prosemirror/storyListNumbering.js +7 -2
- package/dist/prosemirror/tableResize.d.ts +10 -9
- package/dist/prosemirror/tableResize.js +60 -49
- package/dist/prosemirror/textInput.d.ts +30 -1
- package/dist/prosemirror/textInput.js +144 -17
- package/dist/prosemirror/utils/visualLineNavigation.js +20 -18
- package/dist/prosemirror/validation.d.ts +19 -0
- package/dist/prosemirror/validation.js +78 -5
- package/dist/render-dom/HeaderFooterSelectionOverlay.js +5 -4
- package/dist/render-dom/RenderedDomContext.js +7 -6
- package/dist/types/canonicalCapabilities.d.ts +12 -11
- package/dist/types/canonicalCapabilities.js +12 -13
- package/dist/utils/findMatchView.js +4 -3
- package/dist/utils/formatToStyle.d.ts +1 -1
- package/dist/utils/mergeDocumentContent.js +2 -2
- package/dist/utils/paintedPositions.d.ts +60 -0
- package/dist/utils/paintedPositions.js +101 -0
- package/package.json +2 -3
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { closestHtmlElement, findHtmlElement, htmlQueryAll, queryHtmlElement } from "../../utils/domGuards.js";
|
|
2
|
+
import { PAINTED_RANGE_SELECTOR, PAINTED_START_SELECTOR, hasPaintedRange, hasPaintedStart, readPaintedEnd, readPaintedStart } from "../../utils/paintedPositions.js";
|
|
2
3
|
import { descendantTextNodes, logicalTextOffset, measurePaintedSpanRange, paintedTextOffset, textBoundaryAt, totalTextLength } from "./textStreamDom.js";
|
|
3
4
|
// src/layout-bridge/dom/clickToPositionDom.ts
|
|
4
5
|
/**
|
|
@@ -24,18 +25,18 @@ function clickToPositionDom(container, clientX, clientY, zoom = 1) {
|
|
|
24
25
|
const elements = document.elementsFromPoint(clientX, clientY);
|
|
25
26
|
const pageEl = findHtmlElement(elements, (el) => el.classList.contains("layout-page"));
|
|
26
27
|
if (!pageEl) return null;
|
|
27
|
-
const spanEl = findHtmlElement(elements, (el) => el.tagName === "SPAN" && el
|
|
28
|
+
const spanEl = findHtmlElement(elements, (el) => el.tagName === "SPAN" && hasPaintedRange(el));
|
|
28
29
|
if (spanEl) return findPositionInSpan(spanEl, clientX, clientY);
|
|
29
30
|
const emptyRun = findHtmlElement(elements, (el) => el.classList.contains("layout-empty-run"));
|
|
30
31
|
if (emptyRun) {
|
|
31
32
|
const paragraph = closestHtmlElement(emptyRun, ".layout-paragraph");
|
|
32
|
-
if (paragraph && paragraph
|
|
33
|
+
if (paragraph && hasPaintedStart(paragraph)) return readPaintedStart(paragraph) ?? NaN;
|
|
33
34
|
}
|
|
34
|
-
const paragraphEl = findHtmlElement(elements, (el) => el.classList.contains("layout-paragraph") && el
|
|
35
|
-
if (paragraphEl && paragraphEl
|
|
35
|
+
const paragraphEl = findHtmlElement(elements, (el) => el.classList.contains("layout-paragraph") && hasPaintedStart(el));
|
|
36
|
+
if (paragraphEl && hasPaintedStart(paragraphEl)) {
|
|
36
37
|
const nearestPos = findNearestSpanInElement(paragraphEl, clientX, clientY);
|
|
37
38
|
if (nearestPos !== null) return nearestPos;
|
|
38
|
-
return
|
|
39
|
+
return readPaintedStart(paragraphEl) ?? NaN;
|
|
39
40
|
}
|
|
40
41
|
const cellEl = findHtmlElement(elements, (el) => el.classList.contains("layout-table-cell"));
|
|
41
42
|
if (cellEl) return findNearestSpanInElement(cellEl, clientX, clientY);
|
|
@@ -52,8 +53,8 @@ function clickToPositionDom(container, clientX, clientY, zoom = 1) {
|
|
|
52
53
|
* caret API resolved to a sibling text node at the same y).
|
|
53
54
|
*/
|
|
54
55
|
function findPositionInSpan(spanEl, clientX, clientY) {
|
|
55
|
-
const pmStart =
|
|
56
|
-
const pmEnd =
|
|
56
|
+
const pmStart = readPaintedStart(spanEl) ?? NaN;
|
|
57
|
+
const pmEnd = readPaintedEnd(spanEl) ?? NaN;
|
|
57
58
|
if (spanEl.classList.contains("layout-run-tab")) {
|
|
58
59
|
const rect = spanEl.getBoundingClientRect();
|
|
59
60
|
return clientX < (rect.left + rect.right) / 2 ? pmStart : pmEnd;
|
|
@@ -132,9 +133,9 @@ function caretOffsetFromPoint(ownerDoc, textNodes, clientX, clientY) {
|
|
|
132
133
|
function findNearestSpanInElement(element, clientX, clientY) {
|
|
133
134
|
const emptyRun = queryHtmlElement(element, ".layout-empty-run");
|
|
134
135
|
if (emptyRun) {
|
|
135
|
-
if (emptyRun
|
|
136
|
+
if (hasPaintedStart(emptyRun)) return readPaintedStart(emptyRun) ?? NaN;
|
|
136
137
|
const paragraph = closestHtmlElement(emptyRun, ".layout-paragraph");
|
|
137
|
-
if (paragraph && paragraph
|
|
138
|
+
if (paragraph && hasPaintedStart(paragraph)) return readPaintedStart(paragraph) ?? NaN;
|
|
138
139
|
}
|
|
139
140
|
const lines = htmlQueryAll(element, ".layout-line");
|
|
140
141
|
let closestLine = null;
|
|
@@ -149,15 +150,15 @@ function findNearestSpanInElement(element, clientX, clientY) {
|
|
|
149
150
|
}
|
|
150
151
|
}
|
|
151
152
|
if (!closestLine) {
|
|
152
|
-
const paragraph = queryHtmlElement(element,
|
|
153
|
-
if (paragraph
|
|
154
|
-
if (element
|
|
153
|
+
const paragraph = queryHtmlElement(element, `.layout-paragraph${PAINTED_START_SELECTOR}`);
|
|
154
|
+
if (paragraph !== null && hasPaintedStart(paragraph)) return readPaintedStart(paragraph) ?? NaN;
|
|
155
|
+
if (hasPaintedStart(element)) return readPaintedStart(element) ?? NaN;
|
|
155
156
|
return null;
|
|
156
157
|
}
|
|
157
|
-
const lineSpans = htmlQueryAll(closestLine,
|
|
158
|
+
const lineSpans = htmlQueryAll(closestLine, `span${PAINTED_RANGE_SELECTOR}`);
|
|
158
159
|
if (lineSpans.length === 0) {
|
|
159
160
|
const paragraph = closestHtmlElement(closestLine, ".layout-paragraph");
|
|
160
|
-
if (paragraph
|
|
161
|
+
if (paragraph !== null && hasPaintedStart(paragraph)) return readPaintedStart(paragraph) ?? NaN;
|
|
161
162
|
return null;
|
|
162
163
|
}
|
|
163
164
|
let closestSpan = null;
|
|
@@ -172,17 +173,17 @@ function findNearestSpanInElement(element, clientX, clientY) {
|
|
|
172
173
|
}
|
|
173
174
|
}
|
|
174
175
|
if (!closestSpan) return null;
|
|
175
|
-
if (clientX < closestSpan.getBoundingClientRect().left) return
|
|
176
|
-
return
|
|
176
|
+
if (clientX < closestSpan.getBoundingClientRect().left) return readPaintedStart(closestSpan) ?? NaN;
|
|
177
|
+
return readPaintedEnd(closestSpan) ?? NaN;
|
|
177
178
|
}
|
|
178
179
|
/**
|
|
179
180
|
* Find the nearest text span when click is not directly on text.
|
|
180
181
|
* This handles clicks in margins, between lines, etc.
|
|
181
182
|
*/
|
|
182
183
|
function findNearestSpan(_container, pageEl, clientX, clientY, _zoom) {
|
|
183
|
-
if (htmlQueryAll(pageEl,
|
|
184
|
+
if (htmlQueryAll(pageEl, `.layout-page-content span[data-pm-start][data-pm-end]`).length === 0) {
|
|
184
185
|
const firstP = htmlQueryAll(pageEl, ".layout-page-content .layout-paragraph").at(0);
|
|
185
|
-
if (firstP) return
|
|
186
|
+
if (firstP) return readPaintedStart(firstP) || 0;
|
|
186
187
|
return null;
|
|
187
188
|
}
|
|
188
189
|
const lines = htmlQueryAll(pageEl, ".layout-page-content .layout-line");
|
|
@@ -198,10 +199,10 @@ function findNearestSpan(_container, pageEl, clientX, clientY, _zoom) {
|
|
|
198
199
|
}
|
|
199
200
|
}
|
|
200
201
|
if (!closestLine) return null;
|
|
201
|
-
const lineSpans = htmlQueryAll(closestLine,
|
|
202
|
+
const lineSpans = htmlQueryAll(closestLine, `span${PAINTED_RANGE_SELECTOR}`);
|
|
202
203
|
if (lineSpans.length === 0) {
|
|
203
204
|
const paragraph = closestHtmlElement(closestLine, ".layout-paragraph");
|
|
204
|
-
if (paragraph
|
|
205
|
+
if (paragraph !== null && hasPaintedStart(paragraph)) return readPaintedStart(paragraph) ?? NaN;
|
|
205
206
|
return null;
|
|
206
207
|
}
|
|
207
208
|
let closestSpan = null;
|
|
@@ -216,12 +217,12 @@ function findNearestSpan(_container, pageEl, clientX, clientY, _zoom) {
|
|
|
216
217
|
}
|
|
217
218
|
}
|
|
218
219
|
if (!closestSpan) return null;
|
|
219
|
-
if (clientX < closestSpan.getBoundingClientRect().left) return
|
|
220
|
-
return
|
|
220
|
+
if (clientX < closestSpan.getBoundingClientRect().left) return readPaintedStart(closestSpan) ?? NaN;
|
|
221
|
+
return readPaintedEnd(closestSpan) ?? NaN;
|
|
221
222
|
}
|
|
222
223
|
function getSelectionRectsFromDom(container, from, to, overlayRect) {
|
|
223
224
|
const rects = [];
|
|
224
|
-
const spans = htmlQueryAll(container,
|
|
225
|
+
const spans = htmlQueryAll(container, `.layout-page-content span${PAINTED_RANGE_SELECTOR}`);
|
|
225
226
|
for (const spanEl of spans) {
|
|
226
227
|
const measurement = measurePaintedSpanRange(spanEl, from, to);
|
|
227
228
|
if (measurement.type === "outside") continue;
|
|
@@ -255,8 +256,8 @@ function getCollapsedLineEdgeCaretGeometry(spanEl, pmPos) {
|
|
|
255
256
|
const line = closestHtmlElement(spanEl, ".layout-line");
|
|
256
257
|
const anchorRect = sibling?.getBoundingClientRect() ?? line?.getBoundingClientRect() ?? spanRect;
|
|
257
258
|
const lineRect = line?.getBoundingClientRect();
|
|
258
|
-
const pmStart =
|
|
259
|
-
const pmEnd =
|
|
259
|
+
const pmStart = readPaintedStart(spanEl) ?? NaN;
|
|
260
|
+
const pmEnd = readPaintedEnd(spanEl) ?? NaN;
|
|
260
261
|
const storedSpaceAdvance = Number(spanEl.dataset["collapsedSpaceAdvance"]);
|
|
261
262
|
const lineScale = line && line.offsetWidth > 0 && lineRect ? lineRect.width / line.offsetWidth : 1;
|
|
262
263
|
const trailingSpaceCount = isTrailing && pmPos !== void 0 && Number.isFinite(pmStart) && Number.isFinite(pmEnd) ? Math.max(0, Math.min(pmPos, pmEnd) - pmStart) : 0;
|
|
@@ -275,8 +276,8 @@ function getCollapsedLineEdgeCaretGeometry(spanEl, pmPos) {
|
|
|
275
276
|
*/
|
|
276
277
|
function findCollapsedLineEdgeCaretTarget(spans, pmPos) {
|
|
277
278
|
for (const span of spans) {
|
|
278
|
-
const pmStart =
|
|
279
|
-
const pmEnd =
|
|
279
|
+
const pmStart = readPaintedStart(span) ?? NaN;
|
|
280
|
+
const pmEnd = readPaintedEnd(span) ?? NaN;
|
|
280
281
|
if (pmPos < pmStart || pmPos > pmEnd) continue;
|
|
281
282
|
const geometry = getCollapsedLineEdgeCaretGeometry(span, pmPos);
|
|
282
283
|
if (geometry) return {
|
|
@@ -292,7 +293,7 @@ const getPaintedSpanCaretGeometry = (span, pmPos) => {
|
|
|
292
293
|
const spanRect = span.getBoundingClientRect();
|
|
293
294
|
const lineHeight = closestHtmlElement(span, ".layout-line")?.getBoundingClientRect().height || spanRect.height || 16;
|
|
294
295
|
if (span.classList.contains("layout-run-tab")) return {
|
|
295
|
-
left: pmPos >=
|
|
296
|
+
left: pmPos >= (readPaintedEnd(span) ?? NaN) ? spanRect.right : spanRect.left,
|
|
296
297
|
top: spanRect.top,
|
|
297
298
|
height: lineHeight
|
|
298
299
|
};
|
|
@@ -302,10 +303,10 @@ const getPaintedSpanCaretGeometry = (span, pmPos) => {
|
|
|
302
303
|
top: spanRect.top,
|
|
303
304
|
height: lineHeight
|
|
304
305
|
};
|
|
305
|
-
const pmStart =
|
|
306
|
+
const pmStart = readPaintedStart(span) ?? NaN;
|
|
306
307
|
const charIndex = paintedTextOffset({
|
|
307
308
|
pmStart,
|
|
308
|
-
pmEnd:
|
|
309
|
+
pmEnd: readPaintedEnd(span) ?? NaN,
|
|
309
310
|
pmPosition: pmPos,
|
|
310
311
|
textLength: totalTextLength(textNodes)
|
|
311
312
|
});
|
|
@@ -334,12 +335,12 @@ const getPaintedSpanCaretGeometry = (span, pmPos) => {
|
|
|
334
335
|
function findParagraphGapCaretTarget(container, pmPos) {
|
|
335
336
|
let best;
|
|
336
337
|
for (const paragraph of htmlQueryAll(container, ".layout-page-content .layout-paragraph")) {
|
|
337
|
-
const paragraphStart =
|
|
338
|
-
const paragraphEnd =
|
|
338
|
+
const paragraphStart = readPaintedStart(paragraph) ?? NaN;
|
|
339
|
+
const paragraphEnd = readPaintedEnd(paragraph) ?? NaN;
|
|
339
340
|
if (!(pmPos > paragraphStart && pmPos < paragraphEnd)) continue;
|
|
340
|
-
for (const span of htmlQueryAll(paragraph,
|
|
341
|
-
const spanStart =
|
|
342
|
-
const spanEnd =
|
|
341
|
+
for (const span of htmlQueryAll(paragraph, `span${PAINTED_RANGE_SELECTOR}`)) {
|
|
342
|
+
const spanStart = readPaintedStart(span) ?? NaN;
|
|
343
|
+
const spanEnd = readPaintedEnd(span) ?? NaN;
|
|
343
344
|
if (!Number.isFinite(spanStart) || !Number.isFinite(spanEnd)) continue;
|
|
344
345
|
const boundaryPos = pmPos < spanStart ? spanStart : spanEnd;
|
|
345
346
|
const distance = Math.abs(boundaryPos - pmPos);
|
|
@@ -357,7 +358,7 @@ function findParagraphGapCaretTarget(container, pmPos) {
|
|
|
357
358
|
};
|
|
358
359
|
}
|
|
359
360
|
function getCaretPositionFromDom(container, pmPos, overlayRect) {
|
|
360
|
-
const spans = htmlQueryAll(container,
|
|
361
|
+
const spans = htmlQueryAll(container, `.layout-page-content span${PAINTED_RANGE_SELECTOR}`);
|
|
361
362
|
const collapsedTarget = findCollapsedLineEdgeCaretTarget(spans, pmPos);
|
|
362
363
|
if (collapsedTarget) {
|
|
363
364
|
const pageEl = closestHtmlElement(collapsedTarget.span, ".layout-page");
|
|
@@ -370,8 +371,8 @@ function getCaretPositionFromDom(container, pmPos, overlayRect) {
|
|
|
370
371
|
};
|
|
371
372
|
}
|
|
372
373
|
for (const spanEl of spans) {
|
|
373
|
-
const pmStart =
|
|
374
|
-
const pmEnd =
|
|
374
|
+
const pmStart = readPaintedStart(spanEl) ?? NaN;
|
|
375
|
+
const pmEnd = readPaintedEnd(spanEl) ?? NaN;
|
|
375
376
|
if (spanEl.classList.contains("layout-run-tab")) {
|
|
376
377
|
if (pmPos >= pmStart && pmPos < pmEnd) {
|
|
377
378
|
const spanRect = spanEl.getBoundingClientRect();
|
|
@@ -440,8 +441,8 @@ function getCaretPositionFromDom(container, pmPos, overlayRect) {
|
|
|
440
441
|
}
|
|
441
442
|
const paragraphs = htmlQueryAll(container, ".layout-paragraph");
|
|
442
443
|
for (const pEl of paragraphs) {
|
|
443
|
-
const pStart =
|
|
444
|
-
const pEnd =
|
|
444
|
+
const pStart = readPaintedStart(pEl) ?? NaN;
|
|
445
|
+
const pEnd = readPaintedEnd(pEl) ?? NaN;
|
|
445
446
|
if (pmPos >= pStart && pmPos <= pEnd) {
|
|
446
447
|
const targetEl = pEl.querySelector(".layout-empty-run") || pEl;
|
|
447
448
|
const rect = targetEl.getBoundingClientRect();
|
|
@@ -1,16 +1,17 @@
|
|
|
1
|
+
import { PAINTED_RANGE_SELECTOR, PAINTED_START_SELECTOR, paintedStartSelector } from "../../utils/paintedPositions.js";
|
|
1
2
|
// src/layout-bridge/dom/findBodyPmSpans.ts
|
|
2
3
|
const BODY_SCOPE = ".layout-page-content";
|
|
3
4
|
function findBodyPmSpans(container) {
|
|
4
|
-
return Array.from(container.querySelectorAll(`${BODY_SCOPE} span
|
|
5
|
+
return Array.from(container.querySelectorAll(`${BODY_SCOPE} span${PAINTED_RANGE_SELECTOR}`));
|
|
5
6
|
}
|
|
6
7
|
function findBodyEmptyRuns(container) {
|
|
7
8
|
return Array.from(container.querySelectorAll(`${BODY_SCOPE} .layout-empty-run`));
|
|
8
9
|
}
|
|
9
10
|
function findBodyPmAnchors(container) {
|
|
10
|
-
return Array.from(container.querySelectorAll(`${BODY_SCOPE}
|
|
11
|
+
return Array.from(container.querySelectorAll(`${BODY_SCOPE} ${PAINTED_START_SELECTOR}`));
|
|
11
12
|
}
|
|
12
13
|
function findBodyPmAnchor(container, pmStart) {
|
|
13
14
|
if (!Number.isFinite(pmStart)) return null;
|
|
14
|
-
return container.querySelector(`${BODY_SCOPE}
|
|
15
|
+
return container.querySelector(`${BODY_SCOPE} ${paintedStartSelector(pmStart)}`);
|
|
15
16
|
}
|
|
16
17
|
export { findBodyEmptyRuns, findBodyPmAnchor, findBodyPmAnchors, findBodyPmSpans };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { PAINTED_RANGE_SELECTOR, PAINTED_START_SELECTOR, hasPaintedRange, paintedStartSelector, readPaintedEnd, readPaintedStart } from "../../utils/paintedPositions.js";
|
|
1
2
|
import { findPositionInSpan } from "./clickToPositionDom.js";
|
|
2
3
|
// src/layout-bridge/dom/findHfPmSpans.ts
|
|
3
4
|
/**
|
|
@@ -26,14 +27,14 @@ function querySlotAnchors(container, kind, rId, selector) {
|
|
|
26
27
|
return uniqueElements([...querySlotDescendants(container, kind, rId, selector), ...Array.from(container.querySelectorAll(`${associatedSlotSelector(kind, rId)}${selector}`))]);
|
|
27
28
|
}
|
|
28
29
|
function findHfPmSpans(container, kind, rId) {
|
|
29
|
-
return querySlotDescendants(container, kind, rId,
|
|
30
|
+
return querySlotDescendants(container, kind, rId, `span${PAINTED_RANGE_SELECTOR}`);
|
|
30
31
|
}
|
|
31
32
|
function findHfPmAnchors(container, kind, rId) {
|
|
32
|
-
return querySlotAnchors(container, kind, rId,
|
|
33
|
+
return querySlotAnchors(container, kind, rId, PAINTED_START_SELECTOR);
|
|
33
34
|
}
|
|
34
35
|
function findHfPmAnchor(container, kind, rId, pmStart) {
|
|
35
36
|
if (!Number.isFinite(pmStart)) return null;
|
|
36
|
-
return container.querySelector(`${slotSelector(kind, rId)}
|
|
37
|
+
return container.querySelector(`${slotSelector(kind, rId)} ${paintedStartSelector(pmStart)}`) ?? container.querySelector(`${associatedSlotSelector(kind, rId)} ${paintedStartSelector(pmStart)}`) ?? container.querySelector(`${associatedSlotSelector(kind, rId)}${paintedStartSelector(pmStart)}`);
|
|
37
38
|
}
|
|
38
39
|
function findHfCaretSpan(container, kind, rId, pos) {
|
|
39
40
|
if (!Number.isFinite(pos)) return null;
|
|
@@ -45,11 +46,9 @@ function findHfCaretSpan(container, kind, rId, pos) {
|
|
|
45
46
|
const spans = findHfPmSpans(container, kind, rId);
|
|
46
47
|
let best = null;
|
|
47
48
|
for (const span of spans) {
|
|
48
|
-
const
|
|
49
|
-
const
|
|
50
|
-
if (
|
|
51
|
-
const start = Number.parseInt(startStr, 10);
|
|
52
|
-
const end = Number.parseInt(endStr, 10);
|
|
49
|
+
const start = readPaintedStart(span);
|
|
50
|
+
const end = readPaintedEnd(span);
|
|
51
|
+
if (start === void 0 || end === void 0) continue;
|
|
53
52
|
if (!Number.isFinite(start) || !Number.isFinite(end)) continue;
|
|
54
53
|
if (pos === end) best = {
|
|
55
54
|
element: span,
|
|
@@ -83,7 +82,7 @@ function clickToPositionInHfSlot(container, kind, rId, clientX, clientY) {
|
|
|
83
82
|
if (!(el instanceof HTMLElement)) continue;
|
|
84
83
|
const slot = findHfSlotForTarget(el);
|
|
85
84
|
if (!slot || slot.kind !== kind || slot.rId !== rId) continue;
|
|
86
|
-
if (el.tagName === "SPAN" && el
|
|
85
|
+
if (el.tagName === "SPAN" && hasPaintedRange(el)) return findPositionInSpan(el, clientX, clientY);
|
|
87
86
|
}
|
|
88
87
|
return findNearestSpanInHfSlots(container, kind, rId, clientX, clientY);
|
|
89
88
|
}
|
|
@@ -114,12 +113,8 @@ function findNearestSpanInHfSlots(container, kind, rId, clientX, clientY) {
|
|
|
114
113
|
}
|
|
115
114
|
if (!bestSpan) return null;
|
|
116
115
|
if (bestInside) return findPositionInSpan(bestSpan, clientX, clientY);
|
|
117
|
-
if (clientX < bestSpan.getBoundingClientRect().left)
|
|
118
|
-
|
|
119
|
-
return v ? Number(v) : null;
|
|
120
|
-
}
|
|
121
|
-
const v = bestSpan.dataset["pmEnd"];
|
|
122
|
-
return v ? Number(v) : null;
|
|
116
|
+
if (clientX < bestSpan.getBoundingClientRect().left) return readPaintedStart(bestSpan) ?? null;
|
|
117
|
+
return readPaintedEnd(bestSpan) ?? null;
|
|
123
118
|
}
|
|
124
119
|
function findHfSlotForTarget(target) {
|
|
125
120
|
if (!target) return null;
|
|
@@ -1,7 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The class of the box hosts put the hidden editor's host in: a tiny clipping
|
|
3
|
+
* box off-screen, which the browser may scroll to reveal the native caret.
|
|
4
|
+
*/
|
|
5
|
+
export declare const HIDDEN_EDITOR_WRAPPER_CLASS = "paged-editor__hidden-pm-wrapper";
|
|
1
6
|
type ImeCaretHost = {
|
|
2
7
|
style: {
|
|
3
8
|
transform: string;
|
|
4
9
|
};
|
|
10
|
+
readonly parentElement?: {
|
|
11
|
+
closest: (selectors: string) => unknown;
|
|
12
|
+
} | null;
|
|
5
13
|
};
|
|
6
14
|
type ImeCaretEditorView = {
|
|
7
15
|
readonly composing: boolean;
|
|
@@ -1,6 +1,62 @@
|
|
|
1
|
+
import { scrollClipBoxToOrigin } from "../../paged-layout/editorScrollRoot.js";
|
|
1
2
|
// src/layout-bridge/dom/imeCaretAnchor.ts
|
|
3
|
+
/**
|
|
4
|
+
* The class of the box hosts put the hidden editor's host in: a tiny clipping
|
|
5
|
+
* box off-screen, which the browser may scroll to reveal the native caret.
|
|
6
|
+
*/
|
|
7
|
+
const HIDDEN_EDITOR_WRAPPER_CLASS = "paged-editor__hidden-pm-wrapper";
|
|
8
|
+
const isScrollingWrapper = (value) => typeof value === "object" && value !== null && "scrollLeft" in value && "scrollTop" in value && "addEventListener" in value;
|
|
9
|
+
const toOrigin = (wrapper) => scrollClipBoxToOrigin(wrapper);
|
|
10
|
+
const heldWrappers = /* @__PURE__ */ new WeakSet();
|
|
11
|
+
/**
|
|
12
|
+
* Keep the wrapper around the host scrolled to its origin. The translation
|
|
13
|
+
* moves the native caret outside the clipping wrapper, so the browser scrolls
|
|
14
|
+
* the wrapper to reveal it, by any amount, whenever it reveals the caret; the
|
|
15
|
+
* translation is measured with the wrapper at its origin and is only right
|
|
16
|
+
* there. So the wrapper goes back to its origin before every measurement, and
|
|
17
|
+
* after every scroll of it, which leaves the caret where the last measurement
|
|
18
|
+
* put it.
|
|
19
|
+
*/
|
|
20
|
+
const holdWrapperAtOrigin = (hiddenHost) => {
|
|
21
|
+
const wrapper = hiddenHost.parentElement?.closest(`.${HIDDEN_EDITOR_WRAPPER_CLASS}`);
|
|
22
|
+
if (!isScrollingWrapper(wrapper)) return;
|
|
23
|
+
toOrigin(wrapper);
|
|
24
|
+
if (heldWrappers.has(wrapper)) return;
|
|
25
|
+
heldWrappers.add(wrapper);
|
|
26
|
+
wrapper.addEventListener("scroll", () => toOrigin(wrapper), { passive: true });
|
|
27
|
+
};
|
|
28
|
+
/** A translation this module wrote, as the browser or a test reads it back. */
|
|
29
|
+
const ANCHOR_TRANSLATION = /^translate3d\((-?\d+(?:\.\d+)?)px, (-?\d+(?:\.\d+)?)px, 0(?:px)?\)$/u;
|
|
30
|
+
/**
|
|
31
|
+
* The offset the host carries now: none without a transform, the translation
|
|
32
|
+
* for one this module wrote, null for any other transform.
|
|
33
|
+
*/
|
|
34
|
+
const hostOffset = (hiddenHost) => {
|
|
35
|
+
const transform = hiddenHost.style.transform;
|
|
36
|
+
if (transform === "") return {
|
|
37
|
+
dx: 0,
|
|
38
|
+
dy: 0
|
|
39
|
+
};
|
|
40
|
+
const match = ANCHOR_TRANSLATION.exec(transform);
|
|
41
|
+
if (!match) return null;
|
|
42
|
+
return {
|
|
43
|
+
dx: Number(match[1]),
|
|
44
|
+
dy: Number(match[2])
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Give the host an offset, writing only when it changes. A reset keeps a zero
|
|
49
|
+
* translation rather than removing the transform: the host holds the whole
|
|
50
|
+
* hidden document, and adding or removing its transform makes the browser
|
|
51
|
+
* rebuild paint properties for every node under it.
|
|
52
|
+
*/
|
|
53
|
+
const placeHost = (hiddenHost, dx, dy) => {
|
|
54
|
+
const current = hostOffset(hiddenHost);
|
|
55
|
+
if (current && current.dx === dx && current.dy === dy) return;
|
|
56
|
+
hiddenHost.style.transform = `translate3d(${dx}px, ${dy}px, 0)`;
|
|
57
|
+
};
|
|
2
58
|
const resetHostTransform = (hiddenHost) => {
|
|
3
|
-
if (hiddenHost) hiddenHost
|
|
59
|
+
if (hiddenHost) placeHost(hiddenHost, 0, 0);
|
|
4
60
|
};
|
|
5
61
|
const getNativeSelectionCaret = (editorView) => {
|
|
6
62
|
const editorDom = editorView.dom;
|
|
@@ -25,6 +81,7 @@ const getNativeSelectionCaret = (editorView) => {
|
|
|
25
81
|
*/
|
|
26
82
|
const syncImeCaretAnchor = ({ hiddenHost, editorView, visibleCaret }) => {
|
|
27
83
|
if (!hiddenHost) return false;
|
|
84
|
+
holdWrapperAtOrigin(hiddenHost);
|
|
28
85
|
if (!editorView) {
|
|
29
86
|
resetHostTransform(hiddenHost);
|
|
30
87
|
return false;
|
|
@@ -35,24 +92,31 @@ const syncImeCaretAnchor = ({ hiddenHost, editorView, visibleCaret }) => {
|
|
|
35
92
|
return false;
|
|
36
93
|
}
|
|
37
94
|
const previousTransform = hiddenHost.style.transform;
|
|
38
|
-
|
|
95
|
+
let offset = hostOffset(hiddenHost);
|
|
96
|
+
if (!offset) {
|
|
97
|
+
hiddenHost.style.transform = "";
|
|
98
|
+
offset = {
|
|
99
|
+
dx: 0,
|
|
100
|
+
dy: 0
|
|
101
|
+
};
|
|
102
|
+
}
|
|
39
103
|
let hiddenCaret;
|
|
40
104
|
try {
|
|
41
105
|
hiddenCaret = getNativeSelectionCaret(editorView) ?? editorView.coordsAtPos(editorView.state.selection.head);
|
|
42
106
|
} catch {
|
|
43
|
-
hiddenHost.style.transform = previousTransform;
|
|
107
|
+
if (hiddenHost.style.transform !== previousTransform) hiddenHost.style.transform = previousTransform;
|
|
44
108
|
return false;
|
|
45
109
|
}
|
|
46
110
|
if (!Number.isFinite(hiddenCaret.left) || !Number.isFinite(hiddenCaret.top) || !Number.isFinite(visibleCaret.left) || !Number.isFinite(visibleCaret.top)) {
|
|
47
111
|
resetHostTransform(hiddenHost);
|
|
48
112
|
return false;
|
|
49
113
|
}
|
|
50
|
-
const dx = Math.round(visibleCaret.left - hiddenCaret.left);
|
|
51
|
-
const dy = Math.round(visibleCaret.top - hiddenCaret.top);
|
|
52
|
-
hiddenHost
|
|
114
|
+
const dx = Math.round(visibleCaret.left - (hiddenCaret.left - offset.dx));
|
|
115
|
+
const dy = Math.round(visibleCaret.top - (hiddenCaret.top - offset.dy));
|
|
116
|
+
placeHost(hiddenHost, dx, dy);
|
|
53
117
|
return true;
|
|
54
118
|
};
|
|
55
119
|
const resetImeCaretAnchor = (hiddenHost) => {
|
|
56
120
|
resetHostTransform(hiddenHost);
|
|
57
121
|
};
|
|
58
|
-
export { resetImeCaretAnchor, syncImeCaretAnchor };
|
|
122
|
+
export { HIDDEN_EDITOR_WRAPPER_CLASS, resetImeCaretAnchor, syncImeCaretAnchor };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { readPaintedEnd, readPaintedStart } from "../../utils/paintedPositions.js";
|
|
1
2
|
// src/layout-bridge/dom/textStreamDom.ts
|
|
2
3
|
const TEXT_NODE_TYPE = 3;
|
|
3
4
|
const isTextNode = (node) => node.nodeType === TEXT_NODE_TYPE;
|
|
@@ -58,8 +59,8 @@ const createTextStreamRange = (element, startOffset, endOffset) => {
|
|
|
58
59
|
};
|
|
59
60
|
/** Measure the intersecting portion of one painted position span. */
|
|
60
61
|
const measurePaintedSpanRange = (element, from, to) => {
|
|
61
|
-
const pmStart =
|
|
62
|
-
const pmEnd =
|
|
62
|
+
const pmStart = readPaintedStart(element) ?? NaN;
|
|
63
|
+
const pmEnd = readPaintedEnd(element) ?? NaN;
|
|
63
64
|
if (!Number.isFinite(pmStart) || !Number.isFinite(pmEnd) || pmEnd <= from || pmStart >= to) return { type: "outside" };
|
|
64
65
|
if (element.classList.contains("layout-run-tab")) return {
|
|
65
66
|
type: "element",
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { PAINTED_RANGE_SELECTOR, paintedStartSelector, readPaintedEnd, readPaintedStart } from "../utils/paintedPositions.js";
|
|
1
2
|
import { getCollapsedLineEdgeCaretGeometry } from "./dom/clickToPositionDom.js";
|
|
2
3
|
import { createTextStreamRange, descendantTextNodes, totalTextLength } from "./dom/textStreamDom.js";
|
|
3
4
|
// src/layout-bridge/headerFooterLayout.ts
|
|
@@ -35,8 +36,8 @@ function getHfDomSnapshot(section, doc) {
|
|
|
35
36
|
}
|
|
36
37
|
const cached = hfDomCache[section];
|
|
37
38
|
if (cached && cached.host === host && cached.host.isConnected) return cached;
|
|
38
|
-
const spans = Array.from(host.querySelectorAll(
|
|
39
|
-
const ranged = Array.from(host.querySelectorAll(
|
|
39
|
+
const spans = Array.from(host.querySelectorAll(`span${PAINTED_RANGE_SELECTOR}`));
|
|
40
|
+
const ranged = Array.from(host.querySelectorAll(PAINTED_RANGE_SELECTOR));
|
|
40
41
|
const snapshot = {
|
|
41
42
|
host,
|
|
42
43
|
spans,
|
|
@@ -66,8 +67,8 @@ function computeHfCaretRectFromView(view, section, doc = globalThis.document) {
|
|
|
66
67
|
if (!snapshot) return null;
|
|
67
68
|
const { host, spans } = snapshot;
|
|
68
69
|
for (const span of spans) {
|
|
69
|
-
const start =
|
|
70
|
-
const end =
|
|
70
|
+
const start = readPaintedStart(span) ?? NaN;
|
|
71
|
+
const end = readPaintedEnd(span) ?? NaN;
|
|
71
72
|
if (!Number.isFinite(start) || !Number.isFinite(end)) continue;
|
|
72
73
|
if (pmPos >= start && pmPos <= end) {
|
|
73
74
|
const collapsedGeometry = getCollapsedLineEdgeCaretGeometry(span, pmPos);
|
|
@@ -95,7 +96,7 @@ function computeHfCaretRectFromView(view, section, doc = globalThis.document) {
|
|
|
95
96
|
};
|
|
96
97
|
}
|
|
97
98
|
}
|
|
98
|
-
const anchor = host.querySelector(
|
|
99
|
+
const anchor = host.querySelector(paintedStartSelector(pmPos));
|
|
99
100
|
if (anchor) {
|
|
100
101
|
const rect = anchor.getBoundingClientRect();
|
|
101
102
|
return {
|
|
@@ -108,8 +109,8 @@ function computeHfCaretRectFromView(view, section, doc = globalThis.document) {
|
|
|
108
109
|
let bestEl = null;
|
|
109
110
|
let bestSpan = Infinity;
|
|
110
111
|
for (const el of ranged) {
|
|
111
|
-
const start =
|
|
112
|
-
const end =
|
|
112
|
+
const start = readPaintedStart(el) ?? NaN;
|
|
113
|
+
const end = readPaintedEnd(el) ?? NaN;
|
|
113
114
|
if (!Number.isFinite(start) || !Number.isFinite(end)) continue;
|
|
114
115
|
if (pmPos < start || pmPos > end) continue;
|
|
115
116
|
const span = end - start;
|
|
@@ -120,7 +121,7 @@ function computeHfCaretRectFromView(view, section, doc = globalThis.document) {
|
|
|
120
121
|
}
|
|
121
122
|
if (bestEl) {
|
|
122
123
|
const rect = bestEl.getBoundingClientRect();
|
|
123
|
-
const atEnd = pmPos >=
|
|
124
|
+
const atEnd = pmPos >= (readPaintedEnd(bestEl) ?? NaN);
|
|
124
125
|
return {
|
|
125
126
|
top: rect.top,
|
|
126
127
|
left: atEnd ? rect.right : rect.left + 1,
|
|
@@ -130,7 +131,7 @@ function computeHfCaretRectFromView(view, section, doc = globalThis.document) {
|
|
|
130
131
|
let trailingEl = null;
|
|
131
132
|
let trailingStart = -Infinity;
|
|
132
133
|
for (const el of ranged) {
|
|
133
|
-
const start =
|
|
134
|
+
const start = readPaintedStart(el) ?? NaN;
|
|
134
135
|
if (!Number.isFinite(start)) continue;
|
|
135
136
|
if (start > pmPos) continue;
|
|
136
137
|
if (start > trailingStart) {
|
|
@@ -175,8 +176,8 @@ function computeHfSelectionRectsFromView(view, section, doc = globalThis.documen
|
|
|
175
176
|
if (!snapshot) return out;
|
|
176
177
|
const { spans } = snapshot;
|
|
177
178
|
for (const spanEl of spans) {
|
|
178
|
-
const pmStart =
|
|
179
|
-
const pmEnd =
|
|
179
|
+
const pmStart = readPaintedStart(spanEl) ?? NaN;
|
|
180
|
+
const pmEnd = readPaintedEnd(spanEl) ?? NaN;
|
|
180
181
|
if (!Number.isFinite(pmStart) || !Number.isFinite(pmEnd)) continue;
|
|
181
182
|
if (pmEnd <= from || pmStart >= to) continue;
|
|
182
183
|
if (spanEl.classList.contains("layout-run-tab")) {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { readPaintedStart } from "../utils/paintedPositions.js";
|
|
1
2
|
// src/layout-bridge/tableInsertHover.ts
|
|
2
3
|
/**
|
|
3
4
|
* Table-insert "+" hover hit-test.
|
|
@@ -65,7 +66,7 @@ function detectTableInsertHover(input) {
|
|
|
65
66
|
if (!nearLeftEdge && !nearTopEdge) return null;
|
|
66
67
|
const rows = tableEl.querySelectorAll(`:scope > ${rowSelector}`);
|
|
67
68
|
if (rows.length === 0) return null;
|
|
68
|
-
const getCellPmPos = (el) => el ?
|
|
69
|
+
const getCellPmPos = (el) => el ? readPaintedStart(el) || 0 : 0;
|
|
69
70
|
if (nearLeftEdge) for (const row of Array.from(rows)) {
|
|
70
71
|
const rowRect = row.getBoundingClientRect();
|
|
71
72
|
if (mouseY >= rowRect.top && mouseY <= rowRect.bottom) {
|
|
@@ -57,6 +57,8 @@ export declare function setFontCacheSize(size: number): void;
|
|
|
57
57
|
export declare function getFontCacheSize(): number;
|
|
58
58
|
/** Serialize the complete, semantically normalized paragraph measurement contract into a cache key. */
|
|
59
59
|
export declare function hashParagraphBlock(block: ParagraphBlock): string;
|
|
60
|
+
/** `hashParagraphBlock` computed in full. */
|
|
61
|
+
export declare function serializeParagraphBlock(block: ParagraphBlock): string;
|
|
60
62
|
/**
|
|
61
63
|
* Get cached paragraph measurement or return undefined
|
|
62
64
|
*/
|
|
@@ -2,6 +2,7 @@ import { documentFontFactsCacheIdentity } from "../../fonts/documentFontFacts.js
|
|
|
2
2
|
import { embeddedFontFingerprint } from "../../fonts/embeddedFontFingerprint.js";
|
|
3
3
|
import { getLineBreakProviderGeneration } from "./lineBreakProvider.js";
|
|
4
4
|
import { clearFontResolvedCache } from "./measureHelpers.js";
|
|
5
|
+
import { memoizedParagraphKey } from "./paragraphKeyMemo.js";
|
|
5
6
|
import { panic } from "better-result";
|
|
6
7
|
// src/layout-engine/measure/cache.ts
|
|
7
8
|
/**
|
|
@@ -232,6 +233,10 @@ const paragraphAttrsMeasureCacheInput = (attrs, fontContextRef, documentFontCont
|
|
|
232
233
|
};
|
|
233
234
|
/** Serialize the complete, semantically normalized paragraph measurement contract into a cache key. */
|
|
234
235
|
function hashParagraphBlock(block) {
|
|
236
|
+
return memoizedParagraphKey(block, getLineBreakProviderGeneration(), serializeParagraphBlock);
|
|
237
|
+
}
|
|
238
|
+
/** `hashParagraphBlock` computed in full. */
|
|
239
|
+
function serializeParagraphBlock(block) {
|
|
235
240
|
const fontContexts = [];
|
|
236
241
|
const contextRefs = /* @__PURE__ */ new Map();
|
|
237
242
|
const documentFontContexts = [];
|
|
@@ -377,4 +382,4 @@ function labelMeasureCachesFontSet(fontSet) {
|
|
|
377
382
|
function getTotalCacheSize() {
|
|
378
383
|
return getTextCacheSize() + getFontCacheSize() + getParagraphCacheSize();
|
|
379
384
|
}
|
|
380
|
-
export { clearAllCaches, clearFontMetricsCache, clearParagraphMeasureCache, clearTextWidthCache, getCachedFontMetrics, getCachedParagraphMeasure, getCachedTextWidth, getFontCacheSize, getParagraphCacheSize, getTextCacheSize, getTextWidthCacheGeneration, getTotalCacheSize, hashParagraphBlock, labelMeasureCachesFontSet, setCachedFontMetrics, setCachedParagraphMeasure, setCachedTextWidth, setFontCacheSize, setParagraphCacheSize, setTextCacheSize, syncMeasureCachesToFontSet };
|
|
385
|
+
export { clearAllCaches, clearFontMetricsCache, clearParagraphMeasureCache, clearTextWidthCache, getCachedFontMetrics, getCachedParagraphMeasure, getCachedTextWidth, getFontCacheSize, getParagraphCacheSize, getTextCacheSize, getTextWidthCacheGeneration, getTotalCacheSize, hashParagraphBlock, labelMeasureCachesFontSet, serializeParagraphBlock, setCachedFontMetrics, setCachedParagraphMeasure, setCachedTextWidth, setFontCacheSize, setParagraphCacheSize, setTextCacheSize, syncMeasureCachesToFontSet };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ParagraphBlock } from "../types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Record that `block` is `origin`, the block kept for its paragraph, moved:
|
|
4
|
+
* the two show the same, positions aside.
|
|
5
|
+
*/
|
|
6
|
+
export declare const noteParagraphOrigin: (block: ParagraphBlock, origin: ParagraphBlock) => void;
|
|
7
|
+
/** `block`'s key: a recorded one while its values hold, else `compute`'s. */
|
|
8
|
+
export declare const memoizedParagraphKey: (block: ParagraphBlock, generation: number, compute: (block: ParagraphBlock) => string) => string;
|