platejs 54.0.0-beta.2 → 54.0.0-beta.4
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/README.md +1 -1
- package/THIRD_PARTY_NOTICES.md +56 -0
- package/dist/{AIChatRequestContext-BMVWhfPV.d.ts → AIChatRequestContext-DrUahdTc.d.ts} +2 -2
- package/dist/{BaseSuggestionPlugin-DBl3fqnm.d.ts → BaseSuggestionPlugin-_7Ka6nY3.d.ts} +7 -3
- package/dist/{PlateStatic-DhNv2ejp.d.ts → PlateStatic-D3Cb-QwH.d.ts} +7 -7
- package/dist/ai/index.d.ts +1 -1
- package/dist/ai/react/AIChatPlugin.js +113 -78
- package/dist/ai/react/CopilotPlugin.js +1 -1
- package/dist/ai/react/index.d.ts +23 -16
- package/dist/authored/index.d.ts +4 -4
- package/dist/code-block/codemirror/createCodeMirrorAdapter.js +12 -9
- package/dist/code-block/codemirror/index.d.ts +1 -1
- package/dist/{combobox-DkBGgyd3.d.ts → combobox-Dr0OYZIE.d.ts} +2 -2
- package/dist/{comparison-types-CYnJ35qU.d.ts → comparison-types-DdwE6mYq-BogsHoUO.d.ts} +10 -2
- package/dist/compiler/index.d.ts +2 -2
- package/dist/{core-BJG8l_mk.d.ts → core-BqR-fEDp.d.ts} +493 -116
- package/dist/diff/index.d.ts +2 -2
- package/dist/docs/ai.md +4 -3
- package/dist/docs/api/core/plate-components.md +0 -19
- package/dist/docs/api/core/plate-controller.md +5 -3
- package/dist/docs/api/core/plate-plugin.md +3 -0
- package/dist/docs/api/core/plate-store.md +3 -3
- package/dist/docs/api/core.md +45 -5
- package/dist/docs/api/dom.md +11 -4
- package/dist/docs/api/editor-transforms.md +2 -1
- package/dist/docs/api/react-hooks.md +45 -13
- package/dist/docs/authored-changes.md +9 -4
- package/dist/docs/basic-blocks.md +42 -29
- package/dist/docs/block-placeholder.md +4 -2
- package/dist/docs/blockquote.md +5 -3
- package/dist/docs/board.md +118 -10
- package/dist/docs/code-block.md +47 -0
- package/dist/docs/comment.md +2 -2
- package/dist/docs/discussion.md +1 -1
- package/dist/docs/document-model.md +15 -3
- package/dist/docs/docx.md +1 -1
- package/dist/docs/dom-coverage.md +5 -0
- package/dist/docs/editor.md +50 -4
- package/dist/docs/examples/editable-voids.md +2 -3
- package/dist/docs/external-text.md +2 -0
- package/dist/docs/field.md +370 -0
- package/dist/docs/find.md +9 -6
- package/dist/docs/form.md +2 -0
- package/dist/docs/heading.md +6 -0
- package/dist/docs/installation/manual.md +0 -4
- package/dist/docs/link.md +3 -3
- package/dist/docs/llms.txt +4 -2
- package/dist/docs/markdown.md +270 -14
- package/dist/docs/plugin-components.md +13 -10
- package/dist/docs/plugin-input-rules.md +66 -15
- package/dist/docs/prompt-editor.md +205 -0
- package/dist/docs/roots.md +8 -6
- package/dist/docs/rtl.md +6 -4
- package/dist/docs/selection.md +7 -4
- package/dist/docs/suggestion.md +1 -1
- package/dist/docs/toolbar.md +26 -30
- package/dist/docs/upload.md +106 -17
- package/dist/docx/export/index.d.ts +3 -3
- package/dist/docx/export/lib/docxStaticComponents.js +12 -2
- package/dist/docx/export/lib/exportDocx.js +46 -17
- package/dist/docx/export/lib/internal/xml-builder.js +11 -16
- package/dist/docx/export/lib/reviewPart.js +1 -1
- package/dist/docx/export/lib/reviewProjection.js +52 -10
- package/dist/docx/import/index.d.ts +4 -4
- package/dist/docx/paste/index.d.ts +4 -4
- package/dist/dom/index.d.ts +1 -6
- package/dist/dom/plite-dom.internal.js +2 -2
- package/dist/excalidraw/index.d.ts +3 -2
- package/dist/excalidraw/react/index.d.ts +3 -2
- package/dist/facade.js +2 -2
- package/dist/features/basic-nodes/lib/BaseBlockPlugins.js +13 -5
- package/dist/features/basic-nodes/lib/BaseHeadingPlugins.js +32 -10
- package/dist/features/board/index.d.ts +2 -2
- package/dist/features/board/lib/BaseBoardPlugin.js +14 -1
- package/dist/features/board/lib/boardStroke.internal.js +13 -1
- package/dist/features/board/lib/boardTypes.internal.js +16 -0
- package/dist/features/callout/index.d.ts +3 -2
- package/dist/features/code-block/lib/BaseCodeBlockPlugin.js +14 -5
- package/dist/features/combobox/index.d.ts +2 -2
- package/dist/features/comments/BaseCommentsPlugin.js +33 -17
- package/dist/features/comments/index.d.ts +1 -1
- package/dist/features/date/index.d.ts +3 -2
- package/dist/features/details/index.d.ts +3 -2
- package/dist/features/details/lib/BaseDetailsPlugin.js +25 -12
- package/dist/features/field/index.d.ts +2 -0
- package/dist/features/field/index.js +4 -0
- package/dist/features/field/lib/BaseFieldPlugin.js +360 -0
- package/dist/features/field/lib/applyFieldValues.js +188 -0
- package/dist/features/field/lib/fieldRules.internal.js +204 -0
- package/dist/features/find/index.d.ts +3 -2
- package/dist/features/footnote/index.d.ts +1 -1
- package/dist/features/ink/index.d.ts +1 -1
- package/dist/features/ink/lib/BaseInkPlugin.js +126 -103
- package/dist/features/ink/lib/inkCodec.internal.js +130 -0
- package/dist/features/ink/lib/inkGone.internal.js +229 -48
- package/dist/features/ink/lib/inkPlaces.internal.js +534 -64
- package/dist/features/layout/index.d.ts +1 -1
- package/dist/features/link/lib/BaseLinkPlugin.js +6 -4
- package/dist/features/lint/index.d.ts +3 -2
- package/dist/features/media/index.d.ts +2 -2
- package/dist/features/media/index.js +2 -2
- package/dist/features/media/lib/media/parseMediaUrl.js +11 -1
- package/dist/features/media/lib/media-embed/BaseMediaEmbedPlugin.js +206 -4
- package/dist/features/mention/index.d.ts +5 -4
- package/dist/features/suggestion/index.d.ts +1 -1
- package/dist/features/table/index.d.ts +1 -1
- package/dist/features/table/lib/BaseTablePlugin.js +64 -15
- package/dist/features/table/lib/internal/selection.js +4 -2
- package/dist/features/toc/index.d.ts +1 -1
- package/dist/features/upload/index.d.ts +2 -2
- package/dist/features/upload/lib/BaseUploadPlugin.js +464 -250
- package/dist/history/index.d.ts +2 -2
- package/dist/html/index.d.ts +3 -3
- package/dist/html/server/index.d.ts +1 -1
- package/dist/{htmlTypes-DjeFG3P8.d.ts → htmlTypes-eT2ZGDAj.d.ts} +2 -31
- package/dist/hyperscript/index.d.ts +1 -1
- package/dist/{index-DzD6BIFJ.d.ts → index-B33E1CRJ.d.ts} +295 -6
- package/dist/{index-Cl77E9yr.d.ts → index-B7moSod7.d.ts} +2 -2
- package/dist/{index-hsC_sOn2.d.ts → index-B8-5Sr7I.d.ts} +35 -5
- package/dist/{index-BiQerPJS.d.ts → index-B8QJDAmG.d.ts} +2 -2
- package/dist/{index-BBKGrsG3.d.ts → index-BTx5oK7k.d.ts} +1 -1
- package/dist/{index-iaZOhA76.d.ts → index-BWPcE4ac-Cto_IsNs.d.ts} +7 -1
- package/dist/{index-BU6k1Aev.d.ts → index-BXjLmx1n-CXk17buG.d.ts} +4781 -4584
- package/dist/{index-kLKMc-pI.d.ts → index-BXwU9QH6.d.ts} +2 -2
- package/dist/{index-DTgaSxKr.d.ts → index-BkwR-5hH.d.ts} +40 -4
- package/dist/{index-Bq3sdm3S.d.ts → index-BsV2McRr.d.ts} +5 -4
- package/dist/index-C9Fu-P4E.d.ts +773 -0
- package/dist/{index-D5W-p9bS.d.ts → index-Ca48r1ng.d.ts} +49 -4
- package/dist/{index-CcZbqPqk.d.ts → index-Cob_iBdu.d.ts} +116 -41
- package/dist/{index-Bxfvicyy.d.ts → index-CpY7Xnxw.d.ts} +4 -3
- package/dist/{index-BkR7-GLI.d.ts → index-DNQXzU-X.d.ts} +2 -2
- package/dist/{index-D1CFXA-i.d.ts → index-DPowErHa.d.ts} +471 -141
- package/dist/{index-DaM37gF6.d.ts → index-DShbzec2.d.ts} +38 -23
- package/dist/{index-DC_MNGyu.d.ts → index-DYdObeFQ.d.ts} +3 -3
- package/dist/{index-Bc2Yg_2j.d.ts → index-Dq3Jlj8O-BJ6NxZm0.d.ts} +2 -2
- package/dist/{index-CT7miqQN.d.ts → index-DwWQVwQt.d.ts} +29 -11
- package/dist/{index-xdmCBvlT.d.ts → index-JWgwL5l3.d.ts} +5 -2
- package/dist/{index-DLA2DUR2.d.ts → index-M781pyx9.d.ts} +4 -3
- package/dist/{index-DdIRduDG.d.ts → index-d7io3MzC.d.ts} +3 -2
- package/dist/index.d.ts +4 -4
- package/dist/{react/internal → internal}/penStroke.internal.js +1 -1
- package/dist/internal/plugin/OverridePlugin.js +101 -119
- package/dist/internal/plugin/collectPlateNodeMappings.js +5 -1
- package/dist/internal/plugin/pastedUploadFiles.js +4 -0
- package/dist/internal/plugin/resolvePlugin.js +1 -1
- package/dist/internal/plugin/resolvePlugins.js +3 -0
- package/dist/internal/plugin/uploadDrafts.js +6 -0
- package/dist/internal/utils/mergePlugins.js +1 -0
- package/dist/lib/plugins/element-id/ElementIdPlugin.js +14 -18
- package/dist/lib/plugins/html/HtmlPlugin.js +9 -0
- package/dist/lib/plugins/html/htmlSafety.js +1 -1
- package/dist/lib/plugins/input-rules/InputRulesPlugin.js +77 -28
- package/dist/lib/plugins/input-rules/inputRuleVeto.internal.js +16 -0
- package/dist/markdown/index.d.ts +2 -2
- package/dist/markdown/index.js +3 -1
- package/dist/markdown/lib/MarkdownPlugin.js +14 -11
- package/dist/markdown/lib/RawHtmlPlugin.js +26 -0
- package/dist/markdown/lib/deserializer/mdastToSlate.js +12 -2
- package/dist/markdown/lib/internal/markdownConversion.js +776 -74
- package/dist/markdown/lib/internal/markdownDiagnostics.js +18 -7
- package/dist/markdown/lib/internal/markdownFootnoteWriter.js +35 -0
- package/dist/markdown/lib/internal/markdownFrontmatter.js +102 -0
- package/dist/markdown/lib/internal/markdownIntrinsics.js +125 -43
- package/dist/markdown/lib/internal/markdownLine.js +5 -3
- package/dist/markdown/lib/internal/markdownMappings.js +19 -7
- package/dist/markdown/lib/internal/markdownOpenTail.js +381 -0
- package/dist/markdown/lib/internal/markdownRawHtml.js +353 -0
- package/dist/markdown/lib/internal/markdownSegments.js +57 -48
- package/dist/markdown/lib/internal/markdownTags.js +29 -9
- package/dist/markdown/lib/serializer/convertNodesSerialize.js +10 -8
- package/dist/markdown/lib/serializer/convertPhrasingSerialize.js +226 -0
- package/dist/markdown/lib/serializer/listToMdastTree.js +2 -0
- package/dist/math/index.d.ts +3 -2
- package/dist/math/react/index.d.ts +4 -3
- package/dist/migrations/index.d.ts +3 -3
- package/dist/migrations/migratePlateV54.js +4 -6
- package/dist/migrations/migratePlateV54RetiredMarks.internal.js +23 -8
- package/dist/migrations/migratePlateV54Suggestions.internal.js +2 -2
- package/dist/migrations/v53-manifest.internal.js +4 -0
- package/dist/pagination/index.d.ts +1 -1
- package/dist/pagination/react/index.d.ts +4 -4
- package/dist/react/components/EditorContentView.internal.js +42 -23
- package/dist/react/components/EditorProvider.js +5 -5
- package/dist/react/components/Plate.js +102 -128
- package/dist/react/components/PlateContainer.js +40 -32
- package/dist/react/components/PlateController.js +28 -16
- package/dist/react/components/PlateRoot.internal.js +3 -2
- package/dist/react/core.js +4 -4
- package/dist/react/features/board/BoardSurface.js +116 -87
- package/dist/react/features/board/boardClipboard.internal.js +15 -5
- package/dist/react/features/board/boardExport.internal.js +470 -0
- package/dist/react/features/board/boardGesture.internal.js +6 -3
- package/dist/react/features/board/boardIndex.internal.js +7 -18
- package/dist/react/features/board/boardPictureStyles.internal.js +415 -0
- package/dist/react/features/board/boardPictures.internal.js +19 -13
- package/dist/react/features/board/boardView.internal.js +190 -50
- package/dist/react/features/board/boardVoice.internal.js +10 -11
- package/dist/react/features/board/index.d.ts +108 -18
- package/dist/react/features/callout/index.d.ts +3 -2
- package/dist/react/features/combobox/index.d.ts +8 -8
- package/dist/react/features/comments/index.d.ts +6 -5
- package/dist/react/features/date/index.d.ts +4 -3
- package/dist/react/features/details/index.d.ts +4 -3
- package/dist/react/features/field/FieldPlugin.js +35 -0
- package/dist/react/features/field/index.d.ts +315 -0
- package/dist/react/features/field/index.js +2 -0
- package/dist/react/features/footnote/index.d.ts +7 -6
- package/dist/react/features/format-painter/index.d.ts +4 -3
- package/dist/react/features/ink/InkContent.js +313 -0
- package/dist/react/features/ink/index.d.ts +57 -33
- package/dist/react/features/ink/index.js +2 -2
- package/dist/react/features/ink/inkCapture.internal.js +39 -17
- package/dist/react/features/ink/inkInput.internal.js +1 -1
- package/dist/react/features/ink/inkLayout.internal.js +6 -3
- package/dist/react/features/ink/inkPaint.internal.js +78 -2
- package/dist/react/features/ink/inkPlacement.internal.js +332 -104
- package/dist/react/features/ink/inkWatch.internal.js +7 -5
- package/dist/react/features/layout/index.d.ts +5 -4
- package/dist/react/features/media/index.d.ts +5 -4
- package/dist/react/features/mention/index.d.ts +6 -5
- package/dist/react/features/resizable/Resizable.js +4 -6
- package/dist/react/features/resizable/index.d.ts +5 -5
- package/dist/react/features/suggestion/index.d.ts +6 -5
- package/dist/react/features/table/TablePlugin.js +4 -11
- package/dist/react/features/table/index.d.ts +10 -8
- package/dist/react/features/table/useTableResize.js +10 -1
- package/dist/react/features/toc/index.d.ts +2 -2
- package/dist/react/features/upload/index.d.ts +11 -6
- package/dist/react/index.d.ts +6 -6
- package/dist/react/index.js +4 -4
- package/dist/react/internal/plate-context.js +434 -188
- package/dist/react/plite-react.js +2 -2
- package/dist/react/plugins/navigation-feedback/NavigationFeedbackPlugin.js +12 -10
- package/dist/react/stores/plate/useEditor.js +32 -14
- package/dist/react/stores/plate/useEditorHistory.js +55 -0
- package/dist/react/stores/plate/useEditorSelector.js +79 -21
- package/dist/react/utils/BlockPlaceholderPlugin.js +5 -2
- package/dist/react/utils/pipeRenderElement.internal.js +1 -1
- package/dist/react/utils/pluginRenderElement.internal.js +1 -1
- package/dist/react/virtualized.d.ts +4 -4
- package/dist/{source-CNKy99Th.d.ts → source-BGohy8vH.d.ts} +4 -4
- package/dist/static/index.d.ts +18 -18
- package/dist/static/internal/renderStaticHtmlWithOverrides.js +2 -2
- package/dist/static/internal/staticPresentation.js +4 -4
- package/dist/static/internal/writeStaticSelectionClipboardData.js +7 -2
- package/dist/tabbable/index.d.ts +1 -1
- package/dist/tabbable/react/index.d.ts +3 -3
- package/dist/testing/index.d.ts +3 -3
- package/dist/yjs/index.d.ts +1 -1
- package/dist/yjs/react/index.d.ts +6 -6
- package/package.json +20 -2
- package/dist/markdown/lib/serializer/convertTextsSerialize.js +0 -163
- package/dist/react/components/EditorSelectionView.js +0 -40
- package/dist/react/features/ink/InkLayer.js +0 -218
- package/dist/react/internal/createPlateTargetScope.js +0 -62
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { INK_MOVE_TOLERANCE, measureInkBlock } from "./inkMeasure.internal.js";
|
|
2
|
+
import { keepsLayouts } from "./inkWatch.internal.js";
|
|
2
3
|
//#region src/react/features/ink/inkLayout.internal.ts
|
|
3
4
|
const near = (a, b) => Math.abs(a - b) <= INK_MOVE_TOLERANCE;
|
|
4
5
|
const createInkLayouts = () => {
|
|
5
6
|
let kept = /* @__PURE__ */ new WeakMap();
|
|
6
7
|
return {
|
|
7
8
|
changed: (change, within) => {
|
|
8
|
-
if (change
|
|
9
|
+
if (keepsLayouts(change)) return;
|
|
9
10
|
if (!within) {
|
|
10
11
|
kept = /* @__PURE__ */ new WeakMap();
|
|
11
12
|
return;
|
|
@@ -13,11 +14,13 @@ const createInkLayouts = () => {
|
|
|
13
14
|
for (let node = within; node; node = node.parentElement) kept.delete(node);
|
|
14
15
|
if (change === "styles") for (const inner of within.querySelectorAll("*")) kept.delete(inner);
|
|
15
16
|
},
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
lines: (element) => kept.get(element)?.lines,
|
|
18
|
+
measure: (element, text, box, origin, fresh = false) => {
|
|
19
|
+
const layout = fresh ? void 0 : kept.get(element);
|
|
18
20
|
if (layout && near(layout.box.width, box.width) && near(layout.box.height, box.height)) return layout.movedTo(box, origin);
|
|
19
21
|
const measured = measureInkBlock(element, text, origin);
|
|
20
22
|
if (measured) kept.set(element, measured);
|
|
23
|
+
else if (fresh) kept.delete(element);
|
|
21
24
|
return measured;
|
|
22
25
|
}
|
|
23
26
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { strokePolygon } from "
|
|
1
|
+
import { strokePolygon } from "../../../internal/penStroke.internal.js";
|
|
2
2
|
//#region src/react/features/ink/inkPaint.internal.ts
|
|
3
3
|
const INK_THINNING = .25;
|
|
4
4
|
/**
|
|
@@ -13,5 +13,81 @@ const inkOutline = (samples, brush, { dx = 0, dy = 0, last = true } = {}) => str
|
|
|
13
13
|
size: brush.size / 1.25,
|
|
14
14
|
thinning: INK_THINNING
|
|
15
15
|
}, last);
|
|
16
|
+
const HALO = [
|
|
17
|
+
"data-picked",
|
|
18
|
+
"stroke",
|
|
19
|
+
"stroke-opacity",
|
|
20
|
+
"stroke-width"
|
|
21
|
+
];
|
|
22
|
+
const createInkSurface = (into) => {
|
|
23
|
+
const outlines = /* @__PURE__ */ new WeakMap();
|
|
24
|
+
const paths = /* @__PURE__ */ new Map();
|
|
25
|
+
let hidden = false;
|
|
26
|
+
let ink = [];
|
|
27
|
+
let picked = [];
|
|
28
|
+
const outlineOf = (mark) => {
|
|
29
|
+
let outline = outlines.get(mark);
|
|
30
|
+
if (outline === void 0) {
|
|
31
|
+
outline = inkOutline(mark.samples, mark.brush);
|
|
32
|
+
outlines.set(mark, outline);
|
|
33
|
+
}
|
|
34
|
+
return outline;
|
|
35
|
+
};
|
|
36
|
+
const draw = () => {
|
|
37
|
+
const shown = [];
|
|
38
|
+
const left = new Set(paths.keys());
|
|
39
|
+
for (const { dx, dy, mark } of hidden ? [] : ink) {
|
|
40
|
+
const { color, opacity, size } = mark.brush;
|
|
41
|
+
const halo = picked.includes(mark.id);
|
|
42
|
+
const kept = paths.get(mark.id);
|
|
43
|
+
const inked = kept?.mark !== mark;
|
|
44
|
+
const moved = kept?.dx !== dx || kept?.dy !== dy;
|
|
45
|
+
const path = kept?.path ?? into.ownerDocument.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
46
|
+
if (!kept) path.setAttribute("data-ink-mark", mark.id);
|
|
47
|
+
if (inked) {
|
|
48
|
+
path.setAttribute("d", outlineOf(mark));
|
|
49
|
+
path.setAttribute("fill", color);
|
|
50
|
+
path.setAttribute("opacity", String(opacity));
|
|
51
|
+
}
|
|
52
|
+
if (halo && (inked || !kept?.halo)) {
|
|
53
|
+
path.setAttribute("data-picked", "true");
|
|
54
|
+
path.setAttribute("stroke", color);
|
|
55
|
+
path.setAttribute("stroke-opacity", "0.35");
|
|
56
|
+
path.setAttribute("stroke-width", String(size * 2));
|
|
57
|
+
} else if (!halo && kept?.halo) for (const name of HALO) path.removeAttribute(name);
|
|
58
|
+
if (moved) path.setAttribute("transform", `translate(${dx} ${dy})`);
|
|
59
|
+
if (inked || moved || kept?.halo !== halo) paths.set(mark.id, {
|
|
60
|
+
dx,
|
|
61
|
+
dy,
|
|
62
|
+
halo,
|
|
63
|
+
mark,
|
|
64
|
+
path
|
|
65
|
+
});
|
|
66
|
+
left.delete(mark.id);
|
|
67
|
+
shown.push(path);
|
|
68
|
+
}
|
|
69
|
+
for (const id of left) {
|
|
70
|
+
paths.get(id)?.path.remove();
|
|
71
|
+
paths.delete(id);
|
|
72
|
+
}
|
|
73
|
+
let previous = null;
|
|
74
|
+
for (const path of shown) {
|
|
75
|
+
if (path.parentNode !== into || path.previousSibling !== previous) if (previous) previous.after(path);
|
|
76
|
+
else into.prepend(path);
|
|
77
|
+
previous = path;
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
return {
|
|
81
|
+
paint: (placed) => {
|
|
82
|
+
ink = placed;
|
|
83
|
+
draw();
|
|
84
|
+
},
|
|
85
|
+
setLook: (nextHidden, nextPicked) => {
|
|
86
|
+
hidden = nextHidden;
|
|
87
|
+
picked = nextPicked;
|
|
88
|
+
draw();
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
};
|
|
16
92
|
//#endregion
|
|
17
|
-
export { inkOutline };
|
|
93
|
+
export { createInkSurface, inkOutline };
|
|
@@ -1,21 +1,27 @@
|
|
|
1
|
+
import { readElementById } from "../../../facade.js";
|
|
2
|
+
import { blockAbove } from "../../../features/ink/lib/inkGone.internal.js";
|
|
1
3
|
import { placeMark } from "../../../features/ink/lib/inkMatch.internal.js";
|
|
2
|
-
import {
|
|
3
|
-
import { inkBoxOf, inkTextBlockOf, inkWordBoxes } from "./inkMeasure.internal.js";
|
|
4
|
+
import { byMark, readInkDeletedSigns, readInkIndexedMark, readInkSign } from "../../../features/ink/lib/inkPlaces.internal.js";
|
|
5
|
+
import { inkBoxOf, inkTextBlockOf, inkWordBoxes, sameInkBox } from "./inkMeasure.internal.js";
|
|
4
6
|
import { createInkLayouts } from "./inkLayout.internal.js";
|
|
7
|
+
import { InkPlugin } from "./InkPlugin.js";
|
|
5
8
|
//#region src/react/features/ink/inkPlacement.internal.ts
|
|
6
9
|
const NOTHING_PLACED = {
|
|
7
10
|
bottom: 0,
|
|
11
|
+
contentOrigin: {
|
|
12
|
+
left: 0,
|
|
13
|
+
top: 0
|
|
14
|
+
},
|
|
8
15
|
ink: [],
|
|
9
16
|
signs: []
|
|
10
17
|
};
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
reason: "changed",
|
|
17
|
-
type: "sign"
|
|
18
|
+
const metrics = {
|
|
19
|
+
arrivalLookups: 0,
|
|
20
|
+
decided: 0,
|
|
21
|
+
shownIds: 0,
|
|
22
|
+
signReads: 0
|
|
18
23
|
};
|
|
24
|
+
const crosses = (box, { from, to }) => box.top <= to && box.top + box.height >= from;
|
|
19
25
|
const inkInputs = (mark, copies, places, measure, candidatesBetween) => {
|
|
20
26
|
const live = places.map((place) => place && place.kind !== "gone" ? measure(place.key) : void 0);
|
|
21
27
|
const at = live.findIndex((block) => block !== void 0);
|
|
@@ -23,25 +29,23 @@ const inkInputs = (mark, copies, places, measure, candidatesBetween) => {
|
|
|
23
29
|
const reach = mark.brush.size / 2 + Math.max(0, ...copies.flatMap((copy) => copy.lines.map((line) => line.height)));
|
|
24
30
|
const shift = first ? first.box.top - mark.blocks[at].top : 0;
|
|
25
31
|
const ys = mark.samples.map(([, y]) => y + shift);
|
|
26
|
-
const
|
|
27
|
-
|
|
32
|
+
const band = {
|
|
33
|
+
from: Math.min(...ys) - reach,
|
|
34
|
+
to: Math.max(...ys) + reach
|
|
35
|
+
};
|
|
28
36
|
const marked = new Set(places.flatMap((place) => place && place.kind !== "gone" ? [place.key] : []));
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
return measure(key) ?? [];
|
|
32
|
-
});
|
|
37
|
+
const crossing = candidatesBetween(band.from, band.to).filter(({ box }) => crosses(box, band));
|
|
38
|
+
const others = crossing.flatMap(({ key }) => marked.has(key) ? [] : [key]);
|
|
33
39
|
return {
|
|
34
|
-
band
|
|
35
|
-
|
|
36
|
-
to
|
|
37
|
-
},
|
|
40
|
+
band,
|
|
41
|
+
crossing: crossing.length,
|
|
38
42
|
first,
|
|
43
|
+
keys: [...marked, ...others],
|
|
39
44
|
live,
|
|
40
|
-
near
|
|
45
|
+
near: others.flatMap((key) => measure(key) ?? [])
|
|
41
46
|
};
|
|
42
47
|
};
|
|
43
|
-
const placeInkMarks = (view, editable, origin, marks, decide) => {
|
|
44
|
-
const { read } = view.plugin(InkPlugin);
|
|
48
|
+
const placeInkMarks = (view, editable, origin, marks, deleted, entryOf, signOf, decide) => {
|
|
45
49
|
const editableBox = inkBoxOf(editable, origin);
|
|
46
50
|
const style = getComputedStyle(editable);
|
|
47
51
|
const rails = {
|
|
@@ -49,6 +53,22 @@ const placeInkMarks = (view, editable, origin, marks, decide) => {
|
|
|
49
53
|
rtl: editableBox.left
|
|
50
54
|
};
|
|
51
55
|
const startTop = editableBox.top + (Number.parseFloat(style.paddingTop) || 0);
|
|
56
|
+
const pins = /* @__PURE__ */ new Map();
|
|
57
|
+
const pinAt = (element) => {
|
|
58
|
+
let pin = pins.get(element);
|
|
59
|
+
if (!pin) {
|
|
60
|
+
const { left, top } = inkBoxOf(element, origin);
|
|
61
|
+
pin = {
|
|
62
|
+
at: {
|
|
63
|
+
left,
|
|
64
|
+
top
|
|
65
|
+
},
|
|
66
|
+
element
|
|
67
|
+
};
|
|
68
|
+
pins.set(element, pin);
|
|
69
|
+
}
|
|
70
|
+
return pin;
|
|
71
|
+
};
|
|
52
72
|
const anchors = /* @__PURE__ */ new Map();
|
|
53
73
|
const anchorBox = (key) => {
|
|
54
74
|
if (!anchors.has(key)) {
|
|
@@ -57,6 +77,15 @@ const placeInkMarks = (view, editable, origin, marks, decide) => {
|
|
|
57
77
|
}
|
|
58
78
|
return anchors.get(key);
|
|
59
79
|
};
|
|
80
|
+
const above = /* @__PURE__ */ new Map();
|
|
81
|
+
const aboveOf = (key) => {
|
|
82
|
+
if (!above.has(key)) above.set(key, view.read((state) => {
|
|
83
|
+
const [, path] = state.nodes.get(key) ?? [];
|
|
84
|
+
const id = path && blockAbove(state.value(), path);
|
|
85
|
+
return id === void 0 ? void 0 : readElementById(state.nodes, id)?.key;
|
|
86
|
+
}));
|
|
87
|
+
return above.get(key);
|
|
88
|
+
};
|
|
60
89
|
const anchorOf = (place) => {
|
|
61
90
|
if (place?.kind === "live" || place?.kind === "changed") return {
|
|
62
91
|
id: place.key,
|
|
@@ -67,29 +96,43 @@ const placeInkMarks = (view, editable, origin, marks, decide) => {
|
|
|
67
96
|
id: "start",
|
|
68
97
|
top: startTop
|
|
69
98
|
};
|
|
70
|
-
const
|
|
99
|
+
const upper = beside.at === "before" ? aboveOf(beside.key) : void 0;
|
|
100
|
+
const { at, key } = upper === void 0 ? beside : {
|
|
101
|
+
at: "after",
|
|
102
|
+
key: upper
|
|
103
|
+
};
|
|
104
|
+
const box = anchorBox(key);
|
|
71
105
|
return {
|
|
72
|
-
id: `${
|
|
73
|
-
top: box ? box.top + (
|
|
106
|
+
id: `${at}:${key}`,
|
|
107
|
+
top: box ? box.top + (at === "after" ? box.height : 0) : startTop
|
|
74
108
|
};
|
|
75
109
|
};
|
|
76
110
|
const ink = [];
|
|
77
111
|
const signs = /* @__PURE__ */ new Map();
|
|
78
112
|
for (const mark of marks) {
|
|
79
|
-
const
|
|
80
|
-
if (
|
|
81
|
-
const
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
113
|
+
const entry = entryOf(mark);
|
|
114
|
+
if (!entry) continue;
|
|
115
|
+
const kept = signOf(mark);
|
|
116
|
+
let state = kept?.state;
|
|
117
|
+
let place = kept?.place;
|
|
118
|
+
if (!kept) {
|
|
119
|
+
const decided = decide(mark, entry);
|
|
120
|
+
if (!decided) continue;
|
|
121
|
+
const { pin, placement } = decided;
|
|
122
|
+
if (placement.type === "ink") ink.push({
|
|
123
|
+
dx: placement.dx,
|
|
124
|
+
dy: placement.dy,
|
|
125
|
+
mark,
|
|
126
|
+
...pin && { pin: pinAt(pin) }
|
|
127
|
+
});
|
|
128
|
+
state = placement.type === "sign" ? placement.reason : placement.sign;
|
|
129
|
+
({place} = decided);
|
|
130
|
+
}
|
|
89
131
|
if (!state) continue;
|
|
90
|
-
const anchor = anchorOf(
|
|
132
|
+
const anchor = anchorOf(place);
|
|
91
133
|
const id = `${mark.direction}|${anchor.id}|${state}`;
|
|
92
134
|
const sign = signs.get(id) ?? {
|
|
135
|
+
first: mark,
|
|
93
136
|
left: rails[mark.direction],
|
|
94
137
|
marks: [],
|
|
95
138
|
state,
|
|
@@ -98,16 +141,46 @@ const placeInkMarks = (view, editable, origin, marks, decide) => {
|
|
|
98
141
|
sign.marks.push(mark.id);
|
|
99
142
|
signs.set(id, sign);
|
|
100
143
|
}
|
|
144
|
+
const gone = /* @__PURE__ */ new Map();
|
|
145
|
+
for (const { ids, marks: of, place } of deleted) {
|
|
146
|
+
const anchor = anchorOf(place);
|
|
147
|
+
const id = `${of[0].direction}|${anchor.id}|deleted`;
|
|
148
|
+
const there = gone.get(id);
|
|
149
|
+
const merged = there && [...there.marks, ...of].sort(byMark);
|
|
150
|
+
gone.set(id, {
|
|
151
|
+
ids: merged ? merged.map((mark) => mark.id) : ids,
|
|
152
|
+
marks: merged ?? of,
|
|
153
|
+
top: anchor.top
|
|
154
|
+
});
|
|
155
|
+
}
|
|
101
156
|
return {
|
|
102
157
|
bottom: editable.offsetTop + editable.offsetHeight,
|
|
158
|
+
contentOrigin: {
|
|
159
|
+
left: editableBox.left - editable.scrollLeft,
|
|
160
|
+
top: editableBox.top - editable.scrollTop
|
|
161
|
+
},
|
|
103
162
|
ink,
|
|
104
|
-
signs: [...signs].map(([id, { marks: ofSign, state, ...
|
|
105
|
-
...
|
|
163
|
+
signs: [...[...signs].map(([id, { marks: ofSign, state, ...at }]) => ({
|
|
164
|
+
...at,
|
|
106
165
|
id,
|
|
107
166
|
sign: {
|
|
108
167
|
marks: ofSign,
|
|
109
168
|
state
|
|
110
169
|
}
|
|
170
|
+
})), ...[...gone].map(([id, { ids, marks: of, top }]) => ({
|
|
171
|
+
first: of[0],
|
|
172
|
+
id,
|
|
173
|
+
left: rails[of[0].direction],
|
|
174
|
+
sign: {
|
|
175
|
+
marks: ids,
|
|
176
|
+
state: "deleted"
|
|
177
|
+
},
|
|
178
|
+
top
|
|
179
|
+
}))].sort((a, b) => byMark(a.first, b.first)).map(({ id, left, sign, top }) => ({
|
|
180
|
+
id,
|
|
181
|
+
left,
|
|
182
|
+
sign,
|
|
183
|
+
top
|
|
111
184
|
}))
|
|
112
185
|
};
|
|
113
186
|
};
|
|
@@ -131,20 +204,29 @@ const createInkPlacer = ({ editable, layer, view }) => {
|
|
|
131
204
|
const layouts = createInkLayouts();
|
|
132
205
|
const lowestOf = /* @__PURE__ */ new WeakMap();
|
|
133
206
|
const textBlocks = /* @__PURE__ */ new WeakMap();
|
|
134
|
-
const held = /* @__PURE__ */ new
|
|
135
|
-
const ids = /* @__PURE__ */ new WeakMap();
|
|
136
|
-
let nextId = 0;
|
|
207
|
+
const held = /* @__PURE__ */ new Map();
|
|
137
208
|
let index = null;
|
|
138
|
-
let
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
209
|
+
let heading = 1;
|
|
210
|
+
let contentTop;
|
|
211
|
+
const entryOf = (mark) => view.read((state) => readInkIndexedMark({
|
|
212
|
+
copy: read.copy,
|
|
213
|
+
editor: view,
|
|
214
|
+
state
|
|
215
|
+
}, mark));
|
|
216
|
+
const signOf = (mark) => {
|
|
217
|
+
metrics.signReads += 1;
|
|
218
|
+
return view.read((state) => readInkSign({
|
|
219
|
+
copy: read.copy,
|
|
220
|
+
editor: view,
|
|
221
|
+
state
|
|
222
|
+
}, mark));
|
|
147
223
|
};
|
|
224
|
+
const deletedSigns = () => view.read((state) => readInkDeletedSigns({
|
|
225
|
+
copy: read.copy,
|
|
226
|
+
editor: view,
|
|
227
|
+
marks: read.marks,
|
|
228
|
+
state
|
|
229
|
+
}));
|
|
148
230
|
const textBlock = (key) => {
|
|
149
231
|
const node = view.read.nodes.get(key)?.[0];
|
|
150
232
|
if (!node) return void 0;
|
|
@@ -169,8 +251,10 @@ const createInkPlacer = ({ editable, layer, view }) => {
|
|
|
169
251
|
const indexed = (marks) => {
|
|
170
252
|
if (index?.marks === marks) return index;
|
|
171
253
|
const byBlock = /* @__PURE__ */ new Map();
|
|
254
|
+
const saved = new Set(marks.map((mark) => mark.id));
|
|
172
255
|
let reachAbove = 0;
|
|
173
256
|
let reachBelow = 0;
|
|
257
|
+
for (const id of held.keys()) if (!saved.has(id)) held.delete(id);
|
|
174
258
|
for (const mark of marks) {
|
|
175
259
|
for (const block of mark.blocks) {
|
|
176
260
|
const copy = read.copy(block.copy);
|
|
@@ -192,16 +276,11 @@ const createInkPlacer = ({ editable, layer, view }) => {
|
|
|
192
276
|
reachAbove,
|
|
193
277
|
reachBelow
|
|
194
278
|
};
|
|
195
|
-
gone = null;
|
|
196
279
|
return index;
|
|
197
280
|
};
|
|
198
|
-
const
|
|
281
|
+
const openPass = (span, fresh) => {
|
|
199
282
|
const marks = read.marks();
|
|
200
|
-
if (marks.length === 0) return
|
|
201
|
-
bottom: editable.offsetTop + editable.offsetHeight,
|
|
202
|
-
ink: [],
|
|
203
|
-
signs: []
|
|
204
|
-
};
|
|
283
|
+
if (marks.length === 0) return void 0;
|
|
205
284
|
const rect = layer.getBoundingClientRect();
|
|
206
285
|
const origin = {
|
|
207
286
|
left: rect.left,
|
|
@@ -236,19 +315,22 @@ const createInkPlacer = ({ editable, layer, view }) => {
|
|
|
236
315
|
const blocks = blocksBetween(viewportLow, viewportHigh);
|
|
237
316
|
const byKey = new Map(blocks.map((block) => [block.key, block]));
|
|
238
317
|
const measured = /* @__PURE__ */ new Map();
|
|
239
|
-
const
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
318
|
+
const blockAt = (key) => {
|
|
319
|
+
if (!byKey.has(key)) {
|
|
320
|
+
const element = view.api.dom.resolveDOMNode(key);
|
|
321
|
+
const found = textBlock(key);
|
|
322
|
+
byKey.set(key, element && found ? {
|
|
323
|
+
box: inkBoxOf(element, origin),
|
|
324
|
+
element,
|
|
325
|
+
text: found.text
|
|
326
|
+
} : void 0);
|
|
327
|
+
}
|
|
328
|
+
return byKey.get(key);
|
|
247
329
|
};
|
|
248
330
|
const measure = (key) => {
|
|
249
331
|
if (!measured.has(key)) {
|
|
250
|
-
const block =
|
|
251
|
-
measured.set(key, block && layouts.measure(block.element, block.text, block.box, origin));
|
|
332
|
+
const block = blockAt(key);
|
|
333
|
+
measured.set(key, block && layouts.measure(block.element, block.text, block.box, origin, fresh));
|
|
252
334
|
}
|
|
253
335
|
return measured.get(key);
|
|
254
336
|
};
|
|
@@ -258,30 +340,51 @@ const createInkPlacer = ({ editable, layer, view }) => {
|
|
|
258
340
|
for (const block of band) if (!byKey.has(block.key)) byKey.set(block.key, block);
|
|
259
341
|
return band;
|
|
260
342
|
};
|
|
261
|
-
const
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
block.box.left,
|
|
268
|
-
block.box.top - top
|
|
269
|
-
].join(":") : "-";
|
|
270
|
-
const key = [
|
|
271
|
-
rect.width,
|
|
272
|
-
inputs.live.map(part).join(","),
|
|
273
|
-
inputs.near.map(part).join(",")
|
|
274
|
-
].join("|");
|
|
275
|
-
const kept = held.get(mark);
|
|
276
|
-
if (kept?.key === key) {
|
|
277
|
-
const { placement } = kept;
|
|
278
|
-
if (placement.type !== "ink") return placement;
|
|
279
|
-
return {
|
|
280
|
-
...placement,
|
|
281
|
-
dy: placement.dy + top - kept.top
|
|
282
|
-
};
|
|
343
|
+
const pinsOf = /* @__PURE__ */ new Map();
|
|
344
|
+
const pinOf = (element) => {
|
|
345
|
+
if (!pinsOf.has(element)) {
|
|
346
|
+
let pin = element;
|
|
347
|
+
while (pin && pin !== editable && !/sticky|fixed/.test(getComputedStyle(pin).position)) pin = pin.parentElement;
|
|
348
|
+
pinsOf.set(element, pin && pin !== editable ? pin : void 0);
|
|
283
349
|
}
|
|
284
|
-
|
|
350
|
+
return pinsOf.get(element);
|
|
351
|
+
};
|
|
352
|
+
const candidatesMovingWith = (pin) => pin ? (from, to) => candidatesBetween(from, to).filter(({ element }) => pinOf(element) === pin) : candidatesBetween;
|
|
353
|
+
const stillHeld = (mark, entry) => {
|
|
354
|
+
const kept = held.get(mark.id);
|
|
355
|
+
if (kept?.entry !== entry || kept.width !== rect.width) return;
|
|
356
|
+
const top = blockAt(kept.firstKey)?.box.top;
|
|
357
|
+
if (top === void 0) return void 0;
|
|
358
|
+
const band = {
|
|
359
|
+
from: kept.bandFromFirst.from + top,
|
|
360
|
+
to: kept.bandFromFirst.to + top
|
|
361
|
+
};
|
|
362
|
+
if (candidatesMovingWith(kept.pin)(band.from, band.to).filter(({ box }) => crosses(box, band)).length !== kept.crossing || !kept.witnesses.every(({ boxFromFirst, key, lines }) => {
|
|
363
|
+
const now = blockAt(key);
|
|
364
|
+
return now !== void 0 && layouts.lines(now.element) === lines && sameInkBox({
|
|
365
|
+
...now.box,
|
|
366
|
+
top: now.box.top - top
|
|
367
|
+
}, boxFromFirst);
|
|
368
|
+
})) return;
|
|
369
|
+
const { pin, place, placement } = kept;
|
|
370
|
+
return {
|
|
371
|
+
pin,
|
|
372
|
+
place,
|
|
373
|
+
placement: placement.type === "ink" ? {
|
|
374
|
+
...placement,
|
|
375
|
+
dy: placement.dy + top - kept.firstTop
|
|
376
|
+
} : placement
|
|
377
|
+
};
|
|
378
|
+
};
|
|
379
|
+
const decide = (mark, entry) => {
|
|
380
|
+
const kept = fresh ? void 0 : stillHeld(mark, entry);
|
|
381
|
+
if (kept) return kept;
|
|
382
|
+
const { copies } = entry;
|
|
383
|
+
const places = copies.map((copy) => read.place(copy.id));
|
|
384
|
+
const [start] = places.flatMap((at) => at && at.kind !== "gone" ? [at.key] : []);
|
|
385
|
+
const anchor = start === void 0 ? void 0 : blockAt(start)?.element;
|
|
386
|
+
const pin = anchor && pinOf(anchor);
|
|
387
|
+
const { band, crossing, first, keys, live, near } = inkInputs(mark, copies, places, measure, candidatesMovingWith(pin));
|
|
285
388
|
const placement = placeMark({
|
|
286
389
|
copies,
|
|
287
390
|
live,
|
|
@@ -295,22 +398,150 @@ const createInkPlacer = ({ editable, layer, view }) => {
|
|
|
295
398
|
mark,
|
|
296
399
|
nearby: near.flatMap((block) => inkWordBoxes(block, band))
|
|
297
400
|
});
|
|
298
|
-
|
|
299
|
-
|
|
401
|
+
const place = places.find((at) => at?.kind !== "live") ?? places[0];
|
|
402
|
+
const firstTop = first?.box.top ?? 0;
|
|
403
|
+
const witnesses = keys.flatMap((key) => {
|
|
404
|
+
const block = blockAt(key);
|
|
405
|
+
const lines = measure(key)?.lines;
|
|
406
|
+
return block && lines ? [{
|
|
407
|
+
boxFromFirst: {
|
|
408
|
+
...block.box,
|
|
409
|
+
top: block.box.top - firstTop
|
|
410
|
+
},
|
|
411
|
+
key,
|
|
412
|
+
lines
|
|
413
|
+
}] : [];
|
|
414
|
+
});
|
|
415
|
+
const everyBlockMeasured = live[0] !== void 0 && witnesses.length === keys.length;
|
|
416
|
+
metrics.decided += 1;
|
|
417
|
+
if (everyBlockMeasured) held.set(mark.id, {
|
|
418
|
+
bandFromFirst: {
|
|
419
|
+
from: band.from - firstTop,
|
|
420
|
+
to: band.to - firstTop
|
|
421
|
+
},
|
|
422
|
+
crossing,
|
|
423
|
+
entry,
|
|
424
|
+
firstKey: keys[0],
|
|
425
|
+
firstTop,
|
|
426
|
+
pin,
|
|
427
|
+
place,
|
|
300
428
|
placement,
|
|
301
|
-
|
|
429
|
+
width: rect.width,
|
|
430
|
+
witnesses
|
|
302
431
|
});
|
|
303
|
-
|
|
432
|
+
else held.delete(mark.id);
|
|
433
|
+
return {
|
|
434
|
+
pin,
|
|
435
|
+
place,
|
|
436
|
+
placement
|
|
437
|
+
};
|
|
438
|
+
};
|
|
439
|
+
return {
|
|
440
|
+
blocks,
|
|
441
|
+
decide,
|
|
442
|
+
deleted: deletedSigns(),
|
|
443
|
+
marksOn: (block) => markIndex.byBlock.get(block) ?? [],
|
|
444
|
+
origin,
|
|
445
|
+
shown: [...new Set(blocks.flatMap((block) => markIndex.byBlock.get(block.id) ?? []))].filter((mark) => signOf(mark)?.state !== "deleted").sort(byMark),
|
|
446
|
+
stillHeld
|
|
447
|
+
};
|
|
448
|
+
};
|
|
449
|
+
const placeWithin = (span) => {
|
|
450
|
+
const pass = openPass(span, false);
|
|
451
|
+
return pass ? placeInkMarks(view, editable, pass.origin, pass.shown, pass.deleted, entryOf, signOf, pass.decide) : {
|
|
452
|
+
...NOTHING_PLACED,
|
|
453
|
+
bottom: editable.offsetTop + editable.offsetHeight
|
|
304
454
|
};
|
|
305
|
-
gone ??= marks.filter((mark) => mark.blocks.some((block) => {
|
|
306
|
-
const copy = read.copy(block.copy);
|
|
307
|
-
return copy && read.place(copy.id)?.kind === "gone";
|
|
308
|
-
}));
|
|
309
|
-
const shown = new Set(gone);
|
|
310
|
-
for (const block of blocks) for (const mark of markIndex.byBlock.get(block.id) ?? []) shown.add(mark);
|
|
311
|
-
return placeInkMarks(view, editable, origin, marks.filter((mark) => shown.has(mark)), decide);
|
|
312
455
|
};
|
|
313
456
|
return {
|
|
457
|
+
arrive: (shown, expired) => {
|
|
458
|
+
const pass = openPass(nearView, false);
|
|
459
|
+
if (!pass) return {
|
|
460
|
+
placed: placeWithin(nearView),
|
|
461
|
+
undecided: void 0
|
|
462
|
+
};
|
|
463
|
+
const screen = layer.ownerDocument.defaultView?.innerHeight ?? 0;
|
|
464
|
+
const ranks = /* @__PURE__ */ new Map();
|
|
465
|
+
for (const { box, id } of pass.blocks) {
|
|
466
|
+
const top = box.top + pass.origin.top;
|
|
467
|
+
const ahead = top >= screen === heading > 0 ? 1 : 2;
|
|
468
|
+
const rank = top < screen && top + box.height > 0 ? 0 : ahead;
|
|
469
|
+
for (const mark of pass.marksOn(id)) ranks.set(mark, Math.min(rank, ranks.get(mark) ?? rank));
|
|
470
|
+
}
|
|
471
|
+
const showing = new Set(pass.deleted.map(({ ids }) => ids));
|
|
472
|
+
let before;
|
|
473
|
+
const shownBefore = (id) => {
|
|
474
|
+
metrics.arrivalLookups += 1;
|
|
475
|
+
if (!before) {
|
|
476
|
+
before = /* @__PURE__ */ new Set([...shown.ink.map(({ mark }) => mark.id), ...shown.signs.flatMap(({ sign }) => showing.has(sign.marks) ? [] : sign.marks)]);
|
|
477
|
+
metrics.shownIds += before.size;
|
|
478
|
+
}
|
|
479
|
+
return before.has(id);
|
|
480
|
+
};
|
|
481
|
+
const decided = /* @__PURE__ */ new Map();
|
|
482
|
+
let undecided;
|
|
483
|
+
let arrivalsDecided = 0;
|
|
484
|
+
for (const [mark, rank] of [...ranks].sort(([, a], [, b]) => a - b)) {
|
|
485
|
+
const entry = entryOf(mark);
|
|
486
|
+
if (!entry || signOf(mark)) continue;
|
|
487
|
+
const kept = pass.stillHeld(mark, entry);
|
|
488
|
+
if (!kept && !shownBefore(mark.id)) {
|
|
489
|
+
if (undecided || arrivalsDecided > 0 && expired(rank === 0)) {
|
|
490
|
+
undecided ??= rank === 0 ? "screen" : "band";
|
|
491
|
+
continue;
|
|
492
|
+
}
|
|
493
|
+
arrivalsDecided += 1;
|
|
494
|
+
}
|
|
495
|
+
decided.set(mark, kept ?? pass.decide(mark, entry));
|
|
496
|
+
}
|
|
497
|
+
return {
|
|
498
|
+
placed: placeInkMarks(view, editable, pass.origin, pass.shown, pass.deleted, entryOf, signOf, (mark) => decided.get(mark)),
|
|
499
|
+
undecided
|
|
500
|
+
};
|
|
501
|
+
},
|
|
502
|
+
audit: () => {
|
|
503
|
+
const pass = openPass(nearView, true);
|
|
504
|
+
let at = 0;
|
|
505
|
+
return (expired) => {
|
|
506
|
+
if (!pass) return false;
|
|
507
|
+
while (at < pass.shown.length) {
|
|
508
|
+
const mark = pass.shown[at];
|
|
509
|
+
const entry = entryOf(mark);
|
|
510
|
+
at += 1;
|
|
511
|
+
if (entry && !signOf(mark)) pass.decide(mark, entry);
|
|
512
|
+
if (expired()) break;
|
|
513
|
+
}
|
|
514
|
+
return at < pass.shown.length;
|
|
515
|
+
};
|
|
516
|
+
},
|
|
517
|
+
follow: ({ contentOrigin, ink }) => {
|
|
518
|
+
const rect = layer.getBoundingClientRect();
|
|
519
|
+
const box = inkBoxOf(editable, rect);
|
|
520
|
+
const top = box.top - editable.scrollTop;
|
|
521
|
+
const moved = /* @__PURE__ */ new Map([[void 0, {
|
|
522
|
+
left: box.left - editable.scrollLeft - contentOrigin.left,
|
|
523
|
+
top: top - contentOrigin.top
|
|
524
|
+
}]]);
|
|
525
|
+
if (contentTop !== void 0 && top + rect.top !== contentTop) heading = top + rect.top < contentTop ? 1 : -1;
|
|
526
|
+
contentTop = top + rect.top;
|
|
527
|
+
const next = ink.map((each) => {
|
|
528
|
+
let by = moved.get(each.pin?.element);
|
|
529
|
+
if (!by && each.pin) {
|
|
530
|
+
const now = inkBoxOf(each.pin.element, rect);
|
|
531
|
+
by = {
|
|
532
|
+
left: now.left - each.pin.at.left,
|
|
533
|
+
top: now.top - each.pin.at.top
|
|
534
|
+
};
|
|
535
|
+
moved.set(each.pin.element, by);
|
|
536
|
+
}
|
|
537
|
+
return by && (by.left !== 0 || by.top !== 0) ? {
|
|
538
|
+
...each,
|
|
539
|
+
dx: each.dx + by.left,
|
|
540
|
+
dy: each.dy + by.top
|
|
541
|
+
} : each;
|
|
542
|
+
});
|
|
543
|
+
return next.every((each, n) => each === ink[n]) ? ink : next;
|
|
544
|
+
},
|
|
314
545
|
layoutChanged: (change, within) => {
|
|
315
546
|
layouts.changed(change, within);
|
|
316
547
|
if (change !== "words") return;
|
|
@@ -319,9 +550,6 @@ const createInkPlacer = ({ editable, layer, view }) => {
|
|
|
319
550
|
break;
|
|
320
551
|
}
|
|
321
552
|
},
|
|
322
|
-
nodesChanged: () => {
|
|
323
|
-
gone = null;
|
|
324
|
-
},
|
|
325
553
|
place: () => placeWithin(nearView),
|
|
326
554
|
placeEvery: () => placeWithin(everywhere)
|
|
327
555
|
};
|