platejs 54.0.0-beta.2 → 54.0.0-beta.3

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 (237) hide show
  1. package/README.md +1 -1
  2. package/THIRD_PARTY_NOTICES.md +56 -0
  3. package/dist/{AIChatRequestContext-BMVWhfPV.d.ts → AIChatRequestContext-DY104TqL.d.ts} +2 -2
  4. package/dist/{BaseSuggestionPlugin-DBl3fqnm.d.ts → BaseSuggestionPlugin-Deo6n6Fs.d.ts} +7 -3
  5. package/dist/{PlateStatic-DhNv2ejp.d.ts → PlateStatic-CJX5bKuv.d.ts} +7 -7
  6. package/dist/ai/index.d.ts +1 -1
  7. package/dist/ai/react/AIChatPlugin.js +113 -78
  8. package/dist/ai/react/CopilotPlugin.js +1 -1
  9. package/dist/ai/react/index.d.ts +23 -16
  10. package/dist/authored/index.d.ts +4 -4
  11. package/dist/code-block/codemirror/createCodeMirrorAdapter.js +12 -9
  12. package/dist/code-block/codemirror/index.d.ts +1 -1
  13. package/dist/{combobox-DkBGgyd3.d.ts → combobox-DAOYWuvC.d.ts} +2 -2
  14. package/dist/{comparison-types-CYnJ35qU.d.ts → comparison-types-Dt-unJZY-DCddmbSD.d.ts} +10 -2
  15. package/dist/compiler/index.d.ts +2 -2
  16. package/dist/{core-BJG8l_mk.d.ts → core-ClHasORr.d.ts} +433 -95
  17. package/dist/diff/index.d.ts +2 -2
  18. package/dist/docs/ai.md +4 -3
  19. package/dist/docs/api/core/plate-components.md +0 -19
  20. package/dist/docs/api/core/plate-controller.md +4 -2
  21. package/dist/docs/api/core/plate-plugin.md +3 -0
  22. package/dist/docs/api/core/plate-store.md +3 -3
  23. package/dist/docs/api/dom.md +14 -4
  24. package/dist/docs/api/editor-transforms.md +2 -1
  25. package/dist/docs/api/react-hooks.md +25 -11
  26. package/dist/docs/authored-changes.md +5 -2
  27. package/dist/docs/basic-blocks.md +42 -29
  28. package/dist/docs/blockquote.md +5 -3
  29. package/dist/docs/board.md +63 -8
  30. package/dist/docs/code-block.md +47 -0
  31. package/dist/docs/discussion.md +1 -1
  32. package/dist/docs/docx.md +1 -1
  33. package/dist/docs/dom-coverage.md +5 -0
  34. package/dist/docs/examples/editable-voids.md +2 -3
  35. package/dist/docs/external-text.md +2 -0
  36. package/dist/docs/field.md +370 -0
  37. package/dist/docs/find.md +9 -6
  38. package/dist/docs/form.md +2 -0
  39. package/dist/docs/heading.md +6 -0
  40. package/dist/docs/installation/manual.md +0 -4
  41. package/dist/docs/link.md +3 -3
  42. package/dist/docs/llms.txt +4 -2
  43. package/dist/docs/markdown.md +176 -8
  44. package/dist/docs/plugin-components.md +13 -10
  45. package/dist/docs/plugin-input-rules.md +4 -12
  46. package/dist/docs/prompt-editor.md +205 -0
  47. package/dist/docs/roots.md +8 -6
  48. package/dist/docs/rtl.md +6 -4
  49. package/dist/docs/selection.md +7 -4
  50. package/dist/docs/suggestion.md +1 -1
  51. package/dist/docs/toolbar.md +26 -30
  52. package/dist/docs/upload.md +106 -17
  53. package/dist/docx/export/index.d.ts +3 -3
  54. package/dist/docx/export/lib/docxStaticComponents.js +12 -2
  55. package/dist/docx/export/lib/exportDocx.js +29 -5
  56. package/dist/docx/export/lib/reviewPart.js +1 -1
  57. package/dist/docx/export/lib/reviewProjection.js +10 -8
  58. package/dist/docx/import/index.d.ts +4 -4
  59. package/dist/docx/paste/index.d.ts +4 -4
  60. package/dist/dom/index.d.ts +1 -6
  61. package/dist/dom/plite-dom.internal.js +2 -2
  62. package/dist/excalidraw/index.d.ts +3 -2
  63. package/dist/excalidraw/react/index.d.ts +3 -2
  64. package/dist/facade.js +2 -2
  65. package/dist/features/basic-nodes/lib/BaseBlockPlugins.js +13 -5
  66. package/dist/features/basic-nodes/lib/BaseHeadingPlugins.js +32 -10
  67. package/dist/features/board/index.d.ts +2 -2
  68. package/dist/features/board/lib/BaseBoardPlugin.js +14 -1
  69. package/dist/features/board/lib/boardStroke.internal.js +13 -1
  70. package/dist/features/board/lib/boardTypes.internal.js +16 -0
  71. package/dist/features/callout/index.d.ts +3 -2
  72. package/dist/features/code-block/lib/BaseCodeBlockPlugin.js +14 -5
  73. package/dist/features/combobox/index.d.ts +2 -2
  74. package/dist/features/comments/index.d.ts +1 -1
  75. package/dist/features/date/index.d.ts +3 -2
  76. package/dist/features/details/index.d.ts +3 -2
  77. package/dist/features/details/lib/BaseDetailsPlugin.js +10 -10
  78. package/dist/features/field/index.d.ts +2 -0
  79. package/dist/features/field/index.js +2 -0
  80. package/dist/features/field/lib/BaseFieldPlugin.js +414 -0
  81. package/dist/features/field/lib/fieldRules.internal.js +42 -0
  82. package/dist/features/find/index.d.ts +3 -2
  83. package/dist/features/footnote/index.d.ts +1 -1
  84. package/dist/features/ink/index.d.ts +1 -1
  85. package/dist/features/ink/lib/BaseInkPlugin.js +126 -103
  86. package/dist/features/ink/lib/inkCodec.internal.js +130 -0
  87. package/dist/features/ink/lib/inkGone.internal.js +229 -48
  88. package/dist/features/ink/lib/inkPlaces.internal.js +533 -62
  89. package/dist/features/layout/index.d.ts +1 -1
  90. package/dist/features/link/lib/BaseLinkPlugin.js +6 -4
  91. package/dist/features/lint/index.d.ts +3 -2
  92. package/dist/features/media/index.d.ts +1 -1
  93. package/dist/features/media/lib/media/parseMediaUrl.js +11 -1
  94. package/dist/features/media/lib/media-embed/BaseMediaEmbedPlugin.js +6 -2
  95. package/dist/features/mention/index.d.ts +5 -4
  96. package/dist/features/suggestion/index.d.ts +1 -1
  97. package/dist/features/table/index.d.ts +1 -1
  98. package/dist/features/table/lib/BaseTablePlugin.js +14 -8
  99. package/dist/features/table/lib/internal/selection.js +4 -2
  100. package/dist/features/toc/index.d.ts +1 -1
  101. package/dist/features/upload/index.d.ts +2 -2
  102. package/dist/features/upload/lib/BaseUploadPlugin.js +464 -250
  103. package/dist/history/index.d.ts +2 -2
  104. package/dist/html/index.d.ts +3 -3
  105. package/dist/html/server/index.d.ts +1 -1
  106. package/dist/{htmlTypes-DjeFG3P8.d.ts → htmlTypes-cg_cWsaN.d.ts} +2 -31
  107. package/dist/hyperscript/index.d.ts +1 -1
  108. package/dist/{index-D1CFXA-i.d.ts → index-8WO2vI0U.d.ts} +475 -143
  109. package/dist/{index-DaM37gF6.d.ts → index-B5mYEawV.d.ts} +37 -21
  110. package/dist/{index-Bq3sdm3S.d.ts → index-BZWFoUXt.d.ts} +5 -4
  111. package/dist/{index-DdIRduDG.d.ts → index-C0POz7rg.d.ts} +3 -2
  112. package/dist/{index-Bxfvicyy.d.ts → index-C1_JIhL4.d.ts} +4 -3
  113. package/dist/{index-DC_MNGyu.d.ts → index-C35V_hj0.d.ts} +3 -3
  114. package/dist/{index-kLKMc-pI.d.ts → index-C6ql9pKw.d.ts} +2 -2
  115. package/dist/{index-hsC_sOn2.d.ts → index-C9DiGDVj.d.ts} +35 -5
  116. package/dist/{index-DTgaSxKr.d.ts → index-CLsEe3LY.d.ts} +40 -4
  117. package/dist/{index-CT7miqQN.d.ts → index-CdOLsPaW.d.ts} +29 -9
  118. package/dist/{index-DLA2DUR2.d.ts → index-CktYvOgk.d.ts} +4 -3
  119. package/dist/{index-BBKGrsG3.d.ts → index-Cmuluh6f.d.ts} +1 -1
  120. package/dist/{index-BiQerPJS.d.ts → index-CzLwBZpY.d.ts} +2 -2
  121. package/dist/{index-DzD6BIFJ.d.ts → index-D3-2iM1b.d.ts} +7 -5
  122. package/dist/{index-Cl77E9yr.d.ts → index-DKOFvteF.d.ts} +2 -2
  123. package/dist/{index-iaZOhA76.d.ts → index-DPWyk3lG-DOYwohXO.d.ts} +1 -1
  124. package/dist/index-DQnjqtQa.d.ts +678 -0
  125. package/dist/{index-CcZbqPqk.d.ts → index-Do9pj1GK.d.ts} +73 -39
  126. package/dist/{index-BU6k1Aev.d.ts → index-DpltOCot-A2b3p3Eb.d.ts} +4735 -4586
  127. package/dist/{index-Bc2Yg_2j.d.ts → index-HPYawTae-BCUQLEWF.d.ts} +2 -2
  128. package/dist/{index-BkR7-GLI.d.ts → index-baQOK89E.d.ts} +2 -2
  129. package/dist/{index-D5W-p9bS.d.ts → index-oIJAZxc2.d.ts} +49 -4
  130. package/dist/{index-xdmCBvlT.d.ts → index-r7yb77Wy.d.ts} +3 -2
  131. package/dist/index.d.ts +4 -4
  132. package/dist/{react/internal → internal}/penStroke.internal.js +1 -1
  133. package/dist/internal/plugin/OverridePlugin.js +101 -119
  134. package/dist/internal/plugin/collectPlateNodeMappings.js +5 -1
  135. package/dist/internal/plugin/pastedUploadFiles.js +4 -0
  136. package/dist/internal/plugin/resolvePlugin.js +1 -1
  137. package/dist/internal/plugin/resolvePlugins.js +3 -0
  138. package/dist/internal/plugin/uploadDrafts.js +6 -0
  139. package/dist/internal/utils/mergePlugins.js +1 -0
  140. package/dist/lib/plugins/element-id/ElementIdPlugin.js +8 -2
  141. package/dist/lib/plugins/html/HtmlPlugin.js +9 -0
  142. package/dist/lib/plugins/html/htmlSafety.js +1 -1
  143. package/dist/lib/plugins/input-rules/InputRulesPlugin.js +5 -15
  144. package/dist/lib/plugins/input-rules/inputRuleVeto.internal.js +16 -0
  145. package/dist/markdown/index.d.ts +2 -2
  146. package/dist/markdown/index.js +2 -1
  147. package/dist/markdown/lib/MarkdownPlugin.js +16 -9
  148. package/dist/markdown/lib/RawHtmlPlugin.js +24 -0
  149. package/dist/markdown/lib/deserializer/mdastToSlate.js +12 -2
  150. package/dist/markdown/lib/internal/markdownConversion.js +773 -74
  151. package/dist/markdown/lib/internal/markdownDiagnostics.js +18 -7
  152. package/dist/markdown/lib/internal/markdownFrontmatter.js +102 -0
  153. package/dist/markdown/lib/internal/markdownIntrinsics.js +125 -43
  154. package/dist/markdown/lib/internal/markdownLine.js +5 -3
  155. package/dist/markdown/lib/internal/markdownMappings.js +19 -7
  156. package/dist/markdown/lib/internal/markdownOpenTail.js +381 -0
  157. package/dist/markdown/lib/internal/markdownRawHtml.js +314 -0
  158. package/dist/markdown/lib/internal/markdownSegments.js +57 -48
  159. package/dist/markdown/lib/internal/markdownTags.js +22 -8
  160. package/dist/markdown/lib/serializer/convertNodesSerialize.js +10 -8
  161. package/dist/markdown/lib/serializer/convertPhrasingSerialize.js +226 -0
  162. package/dist/markdown/lib/serializer/listToMdastTree.js +2 -0
  163. package/dist/math/index.d.ts +3 -2
  164. package/dist/math/react/index.d.ts +4 -3
  165. package/dist/migrations/index.d.ts +3 -3
  166. package/dist/pagination/index.d.ts +1 -1
  167. package/dist/pagination/react/index.d.ts +4 -4
  168. package/dist/react/components/EditorContentView.internal.js +17 -8
  169. package/dist/react/components/EditorProvider.js +5 -5
  170. package/dist/react/components/Plate.js +103 -122
  171. package/dist/react/components/PlateContainer.js +40 -32
  172. package/dist/react/components/PlateController.js +28 -16
  173. package/dist/react/components/PlateRoot.internal.js +3 -2
  174. package/dist/react/core.js +4 -4
  175. package/dist/react/features/board/BoardSurface.js +116 -87
  176. package/dist/react/features/board/boardClipboard.internal.js +15 -5
  177. package/dist/react/features/board/boardGesture.internal.js +6 -3
  178. package/dist/react/features/board/boardIndex.internal.js +7 -18
  179. package/dist/react/features/board/boardPictures.internal.js +19 -13
  180. package/dist/react/features/board/boardView.internal.js +184 -49
  181. package/dist/react/features/board/boardVoice.internal.js +10 -11
  182. package/dist/react/features/board/index.d.ts +64 -18
  183. package/dist/react/features/callout/index.d.ts +3 -2
  184. package/dist/react/features/combobox/index.d.ts +8 -8
  185. package/dist/react/features/comments/index.d.ts +6 -5
  186. package/dist/react/features/date/index.d.ts +4 -3
  187. package/dist/react/features/details/index.d.ts +4 -3
  188. package/dist/react/features/field/FieldPlugin.js +34 -0
  189. package/dist/react/features/field/index.d.ts +312 -0
  190. package/dist/react/features/field/index.js +2 -0
  191. package/dist/react/features/footnote/index.d.ts +7 -6
  192. package/dist/react/features/format-painter/index.d.ts +4 -3
  193. package/dist/react/features/ink/InkContent.js +313 -0
  194. package/dist/react/features/ink/index.d.ts +57 -29
  195. package/dist/react/features/ink/index.js +2 -2
  196. package/dist/react/features/ink/inkCapture.internal.js +39 -17
  197. package/dist/react/features/ink/inkInput.internal.js +1 -1
  198. package/dist/react/features/ink/inkLayout.internal.js +6 -3
  199. package/dist/react/features/ink/inkPaint.internal.js +78 -2
  200. package/dist/react/features/ink/inkPlacement.internal.js +331 -104
  201. package/dist/react/features/ink/inkWatch.internal.js +7 -5
  202. package/dist/react/features/layout/index.d.ts +5 -4
  203. package/dist/react/features/media/index.d.ts +5 -4
  204. package/dist/react/features/mention/index.d.ts +6 -5
  205. package/dist/react/features/resizable/Resizable.js +4 -6
  206. package/dist/react/features/resizable/index.d.ts +5 -5
  207. package/dist/react/features/suggestion/index.d.ts +6 -5
  208. package/dist/react/features/table/TablePlugin.js +4 -11
  209. package/dist/react/features/table/index.d.ts +8 -7
  210. package/dist/react/features/toc/index.d.ts +2 -2
  211. package/dist/react/features/upload/index.d.ts +11 -6
  212. package/dist/react/index.d.ts +6 -6
  213. package/dist/react/index.js +4 -4
  214. package/dist/react/internal/plate-context.js +425 -188
  215. package/dist/react/plite-react.js +2 -2
  216. package/dist/react/plugins/navigation-feedback/NavigationFeedbackPlugin.js +12 -10
  217. package/dist/react/stores/plate/useEditor.js +32 -14
  218. package/dist/react/stores/plate/useEditorHistory.js +55 -0
  219. package/dist/react/stores/plate/useEditorSelector.js +66 -21
  220. package/dist/react/utils/pipeRenderElement.internal.js +1 -1
  221. package/dist/react/utils/pluginRenderElement.internal.js +1 -1
  222. package/dist/react/virtualized.d.ts +4 -4
  223. package/dist/{source-CNKy99Th.d.ts → source-aUwpNnAw.d.ts} +4 -4
  224. package/dist/static/index.d.ts +18 -18
  225. package/dist/static/internal/renderStaticHtmlWithOverrides.js +2 -2
  226. package/dist/static/internal/staticPresentation.js +4 -4
  227. package/dist/static/internal/writeStaticSelectionClipboardData.js +7 -2
  228. package/dist/tabbable/index.d.ts +1 -1
  229. package/dist/tabbable/react/index.d.ts +3 -3
  230. package/dist/testing/index.d.ts +3 -3
  231. package/dist/yjs/index.d.ts +1 -1
  232. package/dist/yjs/react/index.d.ts +6 -6
  233. package/package.json +20 -2
  234. package/dist/markdown/lib/serializer/convertTextsSerialize.js +0 -163
  235. package/dist/react/components/EditorSelectionView.js +0 -40
  236. package/dist/react/features/ink/InkLayer.js +0 -218
  237. package/dist/react/internal/createPlateTargetScope.js +0 -62
@@ -0,0 +1,313 @@
1
+ import { useEditorViewState } from "../../plite-react.js";
2
+ import { useEditableRef, useEditor, useModelEditor } from "../../stores/plate/useEditor.js";
3
+ import { useViewStore } from "../../stores/plate/useViewStore.js";
4
+ import { INK_TOUCH_ACTION } from "./inkInput.internal.js";
5
+ import { createInkSurface } from "./inkPaint.internal.js";
6
+ import { observeInkLayout, stackInkSigns } from "./inkWatch.internal.js";
7
+ import { attachInkCapture } from "./inkCapture.internal.js";
8
+ import { InkPlugin } from "./InkPlugin.js";
9
+ import { NOTHING_PLACED, createInkPlacer } from "./inkPlacement.internal.js";
10
+ import * as React$1 from "react";
11
+ import { c } from "react/compiler-runtime";
12
+ //#region src/react/features/ink/InkContent.tsx
13
+ const ARRIVE_MS = 50;
14
+ const SETTLE_MS = 250;
15
+ const SLICE_MS = 3;
16
+ const whenIdle = (run, timeoutMs) => {
17
+ if (typeof requestIdleCallback === "function") {
18
+ const id = requestIdleCallback(run, timeoutMs === void 0 ? void 0 : { timeout: Math.max(1, timeoutMs) });
19
+ return () => cancelIdleCallback(id);
20
+ }
21
+ const id = setTimeout(run, 0);
22
+ return () => clearTimeout(id);
23
+ };
24
+ const sameSigns = (a, b) => a.bottom === b.bottom && a.signs.length === b.signs.length && a.signs.every(({ id, left, sign, top }, at) => id === b.signs[at].id && left === b.signs[at].left && top === b.signs[at].top && (sign.marks === b.signs[at].sign.marks || sign.marks.length === b.signs[at].sign.marks.length && sign.marks.every((mark, n) => mark === b.signs[at].sign.marks[n])));
25
+ const firstElementAfter = (element) => {
26
+ for (let at = element; at; at = at.parentElement) if (at.nextElementSibling) return at.nextElementSibling;
27
+ return null;
28
+ };
29
+ /**
30
+ * The ink plugin's `wrapContent` slot: the slot's content, then a layer with
31
+ * the ink of its Editable, drawn over it and its margins. Each mark
32
+ * draws on its words while they stand as they were when it was drawn, and
33
+ * otherwise shows as a `sign` in the Editable's padding where the mark's lines
34
+ * end, the left padding for a mark drawn in right-to-left text: at its
35
+ * block's top when the block's words changed or cannot be measured, or a
36
+ * margin note's margin is too narrow, and beside the nearest block left when a
37
+ * marked block is gone, or on the document's start when none is left. A place
38
+ * shows one sign per state, and a sign that would cover the one above it on its
39
+ * side of the Editable moves down below it. A press on a sign is the sign's
40
+ * own. The layer draws the marks of the blocks within a screen of the view,
41
+ * and every mark once the page is about to print. With the Draw tool on, a pen
42
+ * or the primary mouse button draws a mark, which saves when the contact ends
43
+ * and keeps the Editable's focus and caret. A finger still scrolls, and other
44
+ * mouse buttons keep their own behavior. The view's `hidden` hides ink and
45
+ * signs, and picked marks paint with a halo. Turning the view read-only turns
46
+ * the tool off. The layer fills the nearest positioned ancestor of the
47
+ * Editable, which should hold the Editable and its margins, and reaches at
48
+ * least to the Editable's bottom, so it covers the whole content of a
49
+ * scrolling ancestor. Pass the slot's props on with a `sign`, as in
50
+ * `wrapContent: (props) => <InkContent {...props} sign={Sign} />`, so the
51
+ * layer comes right after the Editable and before every `afterEditable` slot.
52
+ * In development, the mount throws unless the layer is the first element after
53
+ * the Editable, so a mount from `wrapRoot`, `beforeEditable` or
54
+ * `afterEditable` that puts the layer elsewhere, such as after a toolbar,
55
+ * fails. The layer sits at z-index 50, so a press on a control inside the
56
+ * content at that level or below, such as a block's drag handle, reaches the
57
+ * layer, while a toolbar or menu at that level from an `afterEditable` slot or
58
+ * a portal stays above it. When page chrome at or below that level, such as a
59
+ * sticky header, can sit over the editor, give the positioned ancestor its own
60
+ * stacking context, such as with `isolation: isolate`, so the layer stays
61
+ * below that chrome.
62
+ */
63
+ function InkContent(t0) {
64
+ const $ = c(5);
65
+ const { children, sign } = t0;
66
+ let t1;
67
+ if ($[0] !== sign) {
68
+ t1 = /* @__PURE__ */ React$1.createElement(InkLayer, { sign });
69
+ $[0] = sign;
70
+ $[1] = t1;
71
+ } else t1 = $[1];
72
+ let t2;
73
+ if ($[2] !== children || $[3] !== t1) {
74
+ t2 = /* @__PURE__ */ React$1.createElement(React$1.Fragment, null, children, t1);
75
+ $[2] = children;
76
+ $[3] = t1;
77
+ $[4] = t2;
78
+ } else t2 = $[4];
79
+ return t2;
80
+ }
81
+ function InkLayer({ sign: Sign }) {
82
+ const editableRef = useEditableRef();
83
+ const view = useEditor();
84
+ const editor = useModelEditor();
85
+ const tool = useViewStore(InkPlugin, (state) => state.tool);
86
+ const hidden = useViewStore(InkPlugin, (state_0) => state_0.hidden);
87
+ const picked = useViewStore(InkPlugin, (state_1) => state_1.picked);
88
+ const readOnly = useEditorViewState(view, (state_2) => state_2.isReadOnly());
89
+ const [layer, setLayer] = React$1.useState(null);
90
+ const [surface, setSurface] = React$1.useState(null);
91
+ const mountInk = React$1.useCallback((into) => {
92
+ setSurface(into && createInkSurface(into));
93
+ }, []);
94
+ const [shown] = React$1.useState(() => {
95
+ let current = NOTHING_PLACED;
96
+ const listeners = /* @__PURE__ */ new Set();
97
+ return {
98
+ get: () => current,
99
+ set: (next) => {
100
+ current = next;
101
+ for (const listener of listeners) listener();
102
+ },
103
+ subscribe: (listener_0) => {
104
+ listeners.add(listener_0);
105
+ return () => {
106
+ listeners.delete(listener_0);
107
+ };
108
+ }
109
+ };
110
+ });
111
+ const placed = React$1.useSyncExternalStore(shown.subscribe, shown.get, shown.get);
112
+ const preview = React$1.useRef(null);
113
+ const currentTool = React$1.useRef(tool);
114
+ const capture = React$1.useRef(null);
115
+ React$1.useLayoutEffect(() => {
116
+ currentTool.current = tool;
117
+ }, [tool]);
118
+ React$1.useEffect(() => {
119
+ if (!readOnly) return;
120
+ capture.current?.cancel();
121
+ view.plugin(InkPlugin).api.setTool(null);
122
+ }, [readOnly, view]);
123
+ React$1.useEffect(() => {
124
+ const editable = editableRef.current;
125
+ const path = preview.current;
126
+ if (!layer || !editable || !path || !surface) return void 0;
127
+ if (process.env.NODE_ENV !== "production" && firstElementAfter(editable) !== layer) throw new Error("InkContent must be the `wrapContent` slot of its plugin, so its ink layer is the first element after the Editable. Mounted elsewhere, the layer can cover what comes after the Editable, such as a toolbar.");
128
+ const attached = attachInkCapture({
129
+ editor,
130
+ layer,
131
+ preview: path,
132
+ tool: () => currentTool.current,
133
+ view
134
+ });
135
+ const placer = createInkPlacer({
136
+ editable,
137
+ layer,
138
+ view
139
+ });
140
+ const page = layer.ownerDocument;
141
+ const win = page.defaultView;
142
+ let frame = 0;
143
+ let moveFrame = 0;
144
+ let settle;
145
+ let stopSlice;
146
+ let audit;
147
+ let painted = NOTHING_PLACED;
148
+ let scrollStartedAt;
149
+ let stopArrival;
150
+ const show = (next_0) => {
151
+ const { bottom, ink, signs } = next_0;
152
+ painted = next_0;
153
+ surface.paint(ink);
154
+ if (!sameSigns(next_0, shown.get())) shown.set({
155
+ bottom,
156
+ signs
157
+ });
158
+ };
159
+ const stopArriving = () => {
160
+ stopArrival?.();
161
+ stopArrival = void 0;
162
+ scrollStartedAt = void 0;
163
+ };
164
+ const paint = () => {
165
+ frame = 0;
166
+ show(placer.place());
167
+ };
168
+ const arrive = () => {
169
+ const start = performance.now();
170
+ const { placed: next_1, undecided } = placer.arrive(painted, (onScreen) => {
171
+ const now = performance.now();
172
+ const sliceSpent = now - start >= SLICE_MS;
173
+ const screenOverdue = onScreen && scrollStartedAt !== void 0 && now >= scrollStartedAt + ARRIVE_MS;
174
+ return sliceSpent && !screenOverdue;
175
+ });
176
+ show(next_1);
177
+ if (undecided !== "screen") scrollStartedAt = void 0;
178
+ stopArrival = undecided ? whenIdle(arrive, scrollStartedAt === void 0 ? void 0 : scrollStartedAt + ARRIVE_MS - performance.now()) : void 0;
179
+ };
180
+ const move = () => {
181
+ const ink_0 = placer.follow(painted);
182
+ moveFrame = 0;
183
+ if (ink_0 !== painted.ink) surface.paint(ink_0);
184
+ };
185
+ const stopAudit = () => {
186
+ clearTimeout(settle);
187
+ stopSlice?.();
188
+ stopSlice = void 0;
189
+ audit = void 0;
190
+ };
191
+ const slice = () => {
192
+ const start_0 = performance.now();
193
+ audit ??= placer.audit();
194
+ if (audit(() => performance.now() - start_0 >= SLICE_MS)) {
195
+ stopSlice = whenIdle(slice);
196
+ return;
197
+ }
198
+ stopAudit();
199
+ show(placer.place());
200
+ };
201
+ const settleLater = () => {
202
+ stopAudit();
203
+ settle = setTimeout(() => {
204
+ stopSlice = whenIdle(slice);
205
+ }, SETTLE_MS);
206
+ };
207
+ const schedule = () => {
208
+ frame ||= requestAnimationFrame(paint);
209
+ settleLater();
210
+ };
211
+ const onScroll = ({ target }) => {
212
+ if (target instanceof Element && target !== editable && editable.contains(target)) return;
213
+ if (scrollStartedAt === void 0) {
214
+ scrollStartedAt = performance.now();
215
+ stopArrival?.();
216
+ stopArrival = whenIdle(arrive, ARRIVE_MS);
217
+ }
218
+ moveFrame ||= requestAnimationFrame(move);
219
+ settleLater();
220
+ };
221
+ const onPrint = () => {
222
+ cancelAnimationFrame(frame);
223
+ cancelAnimationFrame(moveFrame);
224
+ frame = 0;
225
+ moveFrame = 0;
226
+ stopAudit();
227
+ stopArriving();
228
+ show(placer.placeEvery());
229
+ };
230
+ const unsubscribe = editor.subscribeCommit(({ changed }) => {
231
+ if (!changed.hasAny("document")) return;
232
+ schedule();
233
+ });
234
+ const stopLayout = observeInkLayout(editable, layer, (change, within) => {
235
+ placer.layoutChanged(change, within);
236
+ attached.layoutChanged(change);
237
+ if (change !== "scroll") schedule();
238
+ });
239
+ page.addEventListener("scroll", onScroll, {
240
+ capture: true,
241
+ passive: true
242
+ });
243
+ win?.addEventListener("resize", schedule);
244
+ win?.addEventListener("beforeprint", onPrint);
245
+ capture.current = attached;
246
+ schedule();
247
+ return () => {
248
+ cancelAnimationFrame(frame);
249
+ cancelAnimationFrame(moveFrame);
250
+ stopAudit();
251
+ stopArriving();
252
+ unsubscribe();
253
+ stopLayout();
254
+ page.removeEventListener("scroll", onScroll, { capture: true });
255
+ win?.removeEventListener("resize", schedule);
256
+ win?.removeEventListener("beforeprint", onPrint);
257
+ attached.detach();
258
+ capture.current = null;
259
+ };
260
+ }, [
261
+ editableRef,
262
+ editor,
263
+ layer,
264
+ shown,
265
+ surface,
266
+ view
267
+ ]);
268
+ React$1.useLayoutEffect(() => {
269
+ surface?.setLook(hidden, picked);
270
+ }, [
271
+ hidden,
272
+ picked,
273
+ surface
274
+ ]);
275
+ React$1.useLayoutEffect(() => layer && !hidden ? stackInkSigns(layer, placed.signs) : void 0);
276
+ return /* @__PURE__ */ React$1.createElement("div", {
277
+ "data-ink-layer": "",
278
+ ref: setLayer,
279
+ style: {
280
+ cursor: tool ? "crosshair" : void 0,
281
+ inset: 0,
282
+ minHeight: placed.bottom,
283
+ pointerEvents: tool && !readOnly ? "auto" : "none",
284
+ position: "absolute",
285
+ touchAction: INK_TOUCH_ACTION,
286
+ zIndex: 50
287
+ }
288
+ }, /* @__PURE__ */ React$1.createElement("svg", {
289
+ "aria-hidden": true,
290
+ style: {
291
+ height: "100%",
292
+ left: 0,
293
+ overflow: "visible",
294
+ pointerEvents: "none",
295
+ position: "absolute",
296
+ top: 0,
297
+ width: "100%"
298
+ }
299
+ }, /* @__PURE__ */ React$1.createElement("g", { ref: mountInk }), /* @__PURE__ */ React$1.createElement("path", {
300
+ "data-ink-stroke": "",
301
+ ref: preview
302
+ })), !hidden && placed.signs.map(({ id, left, sign }) => /* @__PURE__ */ React$1.createElement("div", {
303
+ "data-ink-sign": sign.state,
304
+ key: id,
305
+ style: {
306
+ left,
307
+ pointerEvents: "auto",
308
+ position: "absolute"
309
+ }
310
+ }, /* @__PURE__ */ React$1.createElement(Sign, { sign }))));
311
+ }
312
+ //#endregion
313
+ export { InkContent };
@@ -1,19 +1,10 @@
1
- import { $i as NodeKey, Kl as SchemaElementPropertyDefinition, Qo as TxDeclaredMethod, na as Plugin, vl as PropertyStringDescriptor } from "../../../index-BU6k1Aev.js";
2
- import { _ as BasePlugin, bo as PluginReference, ra as BasePluginDependencyReferenceFor, vo as PluginDependency, wi as ElementIdEntry } from "../../../core-BJG8l_mk.js";
3
- import { cn as InternalReactPluginAdapterResult, jt as PluginApiContext } from "../../../index-D1CFXA-i.js";
4
- import { a as InkCopyPlace, c as InkMargin, d as InkMarkInput, h as InkTool, o as InkDirection, p as InkSample, r as InkBrush, s as InkLine, u as InkMarkBlock } from "../../../index-CT7miqQN.js";
5
- import * as React$1 from "react";
6
- import React from "react";
7
- /**
8
- * The words the marks `marks` names were drawn on, as plain text laid out by
9
- * their saved lines, with each mark's ink over them. Marks drawn on the
10
- * same blocks share one copy, and the copy's box takes in their ink, so a
11
- * note drawn in the margin shows beside its words. A mark no longer saved
12
- * shows nothing.
13
- */
14
- declare function InkCopyView({ marks }: {
15
- marks: readonly string[];
16
- }): React.JSX.Element;
1
+ import { Ws as SchemaElementPropertyDefinition, eu as TxDeclaredMethod, is as PropertyStringDescriptor, ro as Plugin, xa as NodeKey } from "../../../index-DpltOCot-A2b3p3Eb.js";
2
+ import "../../../htmlTypes-cg_cWsaN.js";
3
+ import { _ as BasePlugin, ra as BasePluginDependencyReferenceFor, wi as ElementIdEntry, xo as PluginReference, yo as PluginDependency } from "../../../core-ClHasORr.js";
4
+ import { Xt as WrapContentProps, cn as InternalReactPluginAdapterResult, jt as PluginApiContext } from "../../../index-8WO2vI0U.js";
5
+ import { a as InkCopyPlace, c as InkMargin, d as InkMarkInput, h as InkTool, o as InkDirection, p as InkSample, r as InkBrush, s as InkLine, u as InkMarkBlock } from "../../../index-CdOLsPaW.js";
6
+ import * as React from "react";
7
+ import React$1 from "react";
17
8
  /**
18
9
  * Marks whose ink is not on the page, shown as one sign: `changed` when their
19
10
  * words changed or moved, `deleted` when a marked block is gone, and `narrow`
@@ -24,7 +15,8 @@ type InkSign = Readonly<{
24
15
  state: 'changed' | 'deleted' | 'narrow';
25
16
  }>;
26
17
  /**
27
- * The ink of a mounted Editable, drawn over it and its margins. Each mark
18
+ * The ink plugin's `wrapContent` slot: the slot's content, then a layer with
19
+ * the ink of its Editable, drawn over it and its margins. Each mark
28
20
  * draws on its words while they stand as they were when it was drawn, and
29
21
  * otherwise shows as a `sign` in the Editable's padding where the mark's lines
30
22
  * end, the left padding for a mark drawn in right-to-left text: at its
@@ -42,20 +34,34 @@ type InkSign = Readonly<{
42
34
  * the tool off. The layer fills the nearest positioned ancestor of the
43
35
  * Editable, which should hold the Editable and its margins, and reaches at
44
36
  * least to the Editable's bottom, so it covers the whole content of a
45
- * scrolling ancestor. Render it after the content from the plugin's
46
- * `wrapContent` slot, so it comes after the Editable and before every
47
- * `afterEditable` slot. It sits at z-index 50, so a press on a control inside
48
- * the content at that level or below, such as a block's drag handle, reaches
49
- * the layer, while a toolbar or menu at that level from an `afterEditable`
50
- * slot or a portal stays above it. When page chrome at or below that level,
51
- * such as a sticky header, can sit over the editor, give the positioned
52
- * ancestor its own stacking context, such as with `isolation: isolate`, so the
53
- * layer stays below that chrome.
37
+ * scrolling ancestor. Pass the slot's props on with a `sign`, as in
38
+ * `wrapContent: (props) => <InkContent {...props} sign={Sign} />`, so the
39
+ * layer comes right after the Editable and before every `afterEditable` slot.
40
+ * In development, the mount throws unless the layer is the first element after
41
+ * the Editable, so a mount from `wrapRoot`, `beforeEditable` or
42
+ * `afterEditable` that puts the layer elsewhere, such as after a toolbar,
43
+ * fails. The layer sits at z-index 50, so a press on a control inside the
44
+ * content at that level or below, such as a block's drag handle, reaches the
45
+ * layer, while a toolbar or menu at that level from an `afterEditable` slot or
46
+ * a portal stays above it. When page chrome at or below that level, such as a
47
+ * sticky header, can sit over the editor, give the positioned ancestor its own
48
+ * stacking context, such as with `isolation: isolate`, so the layer stays
49
+ * below that chrome.
54
50
  */
55
- declare function InkLayer({ sign: Sign }: {
56
- sign: React$1.ComponentType<{
51
+ declare function InkContent({ children, sign }: WrapContentProps & {
52
+ sign: React.ComponentType<{
57
53
  sign: InkSign;
58
54
  }>;
55
+ }): React.JSX.Element;
56
+ /**
57
+ * The words the marks `marks` names were drawn on, as plain text laid out by
58
+ * their saved lines, with each mark's ink over them. Marks drawn on the
59
+ * same blocks share one copy, and the copy's box takes in their ink, so a
60
+ * note drawn in the margin shows beside its words. A mark no longer saved
61
+ * shows nothing.
62
+ */
63
+ declare function InkCopyView({ marks }: {
64
+ marks: readonly string[];
59
65
  }): React$1.JSX.Element;
60
66
  /**
61
67
  * Pen markup on a document's text, with each view's Draw tool. A view keeps
@@ -72,6 +78,11 @@ declare const InkPlugin: InternalReactPluginAdapterResult<BasePlugin<Readonly<{
72
78
  readonly records: {
73
79
  readonly "ink-copies": {
74
80
  readonly history: "retain";
81
+ readonly namedBy: {
82
+ keep: (id: string) => boolean;
83
+ names: ({ copies }: Readonly<Record<string, unknown>>) => string[] | null;
84
+ set: "ink-marks";
85
+ };
75
86
  };
76
87
  readonly "ink-gone": {
77
88
  readonly history: "retain";
@@ -108,6 +119,9 @@ declare const InkPlugin: InternalReactPluginAdapterResult<BasePlugin<Readonly<{
108
119
  }>, Readonly<{
109
120
  group: "element";
110
121
  kind: "group";
122
+ }>, Readonly<{
123
+ key: string;
124
+ map: (value: string, renamed: (name: string) => string | undefined) => string;
111
125
  }>>;
112
126
  };
113
127
  }>> & Readonly<Record<never, never>>> & Pick<BasePlugin<Readonly<{
@@ -129,6 +143,9 @@ declare const InkPlugin: InternalReactPluginAdapterResult<BasePlugin<Readonly<{
129
143
  }>, Readonly<{
130
144
  group: "element";
131
145
  kind: "group";
146
+ }>, Readonly<{
147
+ key: string;
148
+ map: (value: string, renamed: (name: string) => string | undefined) => string;
132
149
  }>>;
133
150
  };
134
151
  };
@@ -197,6 +214,11 @@ declare const InkPlugin: InternalReactPluginAdapterResult<BasePlugin<Readonly<{
197
214
  readonly records: {
198
215
  readonly "ink-copies": {
199
216
  readonly history: "retain";
217
+ readonly namedBy: {
218
+ keep: (id: string) => boolean;
219
+ names: ({ copies }: Readonly<Record<string, unknown>>) => string[] | null;
220
+ set: "ink-marks";
221
+ };
200
222
  };
201
223
  readonly "ink-gone": {
202
224
  readonly history: "retain";
@@ -233,6 +255,9 @@ declare const InkPlugin: InternalReactPluginAdapterResult<BasePlugin<Readonly<{
233
255
  }>, Readonly<{
234
256
  group: "element";
235
257
  kind: "group";
258
+ }>, Readonly<{
259
+ key: string;
260
+ map: (value: string, renamed: (name: string) => string | undefined) => string;
236
261
  }>>;
237
262
  };
238
263
  }>> & Readonly<Record<never, never>>> & Pick<BasePlugin<Readonly<{
@@ -254,6 +279,9 @@ declare const InkPlugin: InternalReactPluginAdapterResult<BasePlugin<Readonly<{
254
279
  }>, Readonly<{
255
280
  group: "element";
256
281
  kind: "group";
282
+ }>, Readonly<{
283
+ key: string;
284
+ map: (value: string, renamed: (name: string) => string | undefined) => string;
257
285
  }>>;
258
286
  };
259
287
  };
@@ -323,4 +351,4 @@ declare const InkPlugin: InternalReactPluginAdapterResult<BasePlugin<Readonly<{
323
351
  setTool: (tool: InkTool | null) => boolean;
324
352
  };
325
353
  }>;
326
- export { InkCopyView, InkLayer, InkPlugin, InkSign };
354
+ export { InkContent, InkCopyView, InkPlugin, InkSign };
@@ -1,4 +1,4 @@
1
1
  import { InkPlugin } from "./InkPlugin.js";
2
+ import { InkContent } from "./InkContent.js";
2
3
  import { InkCopyView } from "./InkCopyView.js";
3
- import { InkLayer } from "./InkLayer.js";
4
- export { InkCopyView, InkLayer, InkPlugin };
4
+ export { InkContent, InkCopyView, InkPlugin };
@@ -1,11 +1,17 @@
1
1
  import { PathApi, scheduleAfterCommitNotification } from "../../../facade.js";
2
2
  import { HistoryPlugin } from "../../../lib/plugins/HistoryPlugin.js";
3
+ import { roundPixel, roundSample } from "../../../features/ink/lib/inkCodec.internal.js";
4
+ import { holdInkBlock } from "../../../features/ink/lib/inkGone.internal.js";
3
5
  import { footprintEnters, gapAround, inkTouchedWords, inkWords } from "../../../features/ink/lib/inkMatch.internal.js";
4
6
  import { BaseInkPlugin } from "../../../features/ink/lib/BaseInkPlugin.js";
5
- import { inkOutline } from "./inkPaint.internal.js";
6
7
  import { inkDraws, inkPressure, inkSamplesOf } from "./inkInput.internal.js";
7
8
  import { inkBoxOf, inkTextBlocks, inkWordBoxes, measureInkBlock, sameInkBox, sameInkLayout } from "./inkMeasure.internal.js";
9
+ import { inkOutline } from "./inkPaint.internal.js";
10
+ import { keepsLayouts } from "./inkWatch.internal.js";
8
11
  //#region src/react/features/ink/inkCapture.internal.ts
12
+ const release = (epoch) => {
13
+ for (const free of epoch.holds.splice(0)) free();
14
+ };
9
15
  const heldBy = (epoch) => epoch.blocks.length > 0 || !epoch.note ? epoch.blocks : [epoch.note];
10
16
  const lineStart = (live, index) => index === 0 ? 0 : live.lines[index - 1].end;
11
17
  const runsOf = (live, points, radius) => {
@@ -164,17 +170,24 @@ const attachInkCapture = ({ editor, layer, preview, tool, view }) => {
164
170
  const seal = () => {
165
171
  const done = epoch;
166
172
  epoch = null;
167
- if (!done || !contact) return;
168
- const input = inputOf(done, contact.brush);
169
- if (!input) return;
173
+ if (!done) return;
174
+ const input = contact && inputOf(done, contact.brush);
175
+ if (!input) {
176
+ release(done);
177
+ return;
178
+ }
170
179
  scheduleAfterCommitNotification(editor, () => {
171
- const tracked = editor.plugin(HistoryPlugin).installed;
172
- const joins = tracked && savedAt === editor.read.history().revision;
173
- editor.update((tx) => {
174
- if (joins) tx.history.merge();
175
- tx.plugin(BaseInkPlugin).add(input);
176
- });
177
- savedAt = tracked ? editor.read.history().revision : void 0;
180
+ try {
181
+ const tracked = editor.plugin(HistoryPlugin).installed;
182
+ const joins = tracked && savedAt === editor.read.history().revision;
183
+ editor.update((tx) => {
184
+ if (joins) tx.history.merge();
185
+ tx.plugin(BaseInkPlugin).add(input);
186
+ });
187
+ savedAt = tracked ? editor.read.history().revision : void 0;
188
+ } finally {
189
+ release(done);
190
+ }
178
191
  });
179
192
  };
180
193
  const cutAt = (time) => {
@@ -187,7 +200,7 @@ const attachInkCapture = ({ editor, layer, preview, tool, view }) => {
187
200
  cutAt(performance.now());
188
201
  draw();
189
202
  };
190
- const heldMoved = (open, origin, change) => heldBy(open).some(({ block, live }) => change === "boxes" ? !sameInkBox(live.box, inkBoxOf(block.element, origin)) : !sameInkLayout(live, measureInkBlock(block.element, block.text, origin)));
203
+ const heldMoved = (open, origin, change) => heldBy(open).some(({ block, live }) => keepsLayouts(change) ? !sameInkBox(live.box, inkBoxOf(block.element, origin)) : !sameInkLayout(live, measureInkBlock(block.element, block.text, origin)));
191
204
  const changedAt = (block) => block.path.flatMap((_, at) => {
192
205
  const key = view.key(block.path.slice(0, at + 1));
193
206
  const time = key === null ? void 0 : changedSinceCut.get(key);
@@ -195,7 +208,7 @@ const attachInkCapture = ({ editor, layer, preview, tool, view }) => {
195
208
  });
196
209
  const take = (event, origin) => {
197
210
  if (!contact || event.timeStamp < dropBefore) return;
198
- const point = [event.clientX - origin.left, event.clientY - origin.top];
211
+ const point = [roundPixel(event.clientX - origin.left), roundPixel(event.clientY - origin.top)];
199
212
  const [previous] = epoch?.samples.slice(-1) ?? [];
200
213
  const { brush } = contact;
201
214
  const radius = brush.size / 2;
@@ -210,19 +223,27 @@ const attachInkCapture = ({ editor, layer, preview, tool, view }) => {
210
223
  const open = epoch ?? {
211
224
  at: Date.now(),
212
225
  blocks: [],
226
+ holds: [],
213
227
  note: void 0,
214
228
  samples: [],
215
229
  start: event.timeStamp
216
230
  };
217
231
  const [last] = open.samples.slice(-1);
218
232
  const segment = last ? [[last[0], last[1]], point] : [point];
233
+ const hold = (entered) => {
234
+ open.holds.push(holdInkBlock(editor, entered.block.id));
235
+ return entered;
236
+ };
219
237
  epoch = open;
220
238
  for (const { block } of entering(segment)) {
221
239
  const entered = enter(block, origin);
222
- if (entered) open.blocks.push(entered);
240
+ if (entered) open.blocks.push(hold(entered));
241
+ }
242
+ if (open.samples.length === 0 && open.blocks.length === 0) {
243
+ const note = nearestTo(point, origin);
244
+ open.note = note && hold(note);
223
245
  }
224
- if (open.samples.length === 0 && open.blocks.length === 0) open.note = nearestTo(point, origin);
225
- open.samples.push([
246
+ open.samples.push(roundSample([
226
247
  point[0],
227
248
  point[1],
228
249
  inkPressure(event, last && {
@@ -230,9 +251,10 @@ const attachInkCapture = ({ editor, layer, preview, tool, view }) => {
230
251
  pressure: last[2]
231
252
  }, brush.size),
232
253
  Math.max(last?.[3] ?? 0, event.timeStamp - open.start)
233
- ]);
254
+ ]));
234
255
  };
235
256
  const cancel = () => {
257
+ if (epoch) release(epoch);
236
258
  epoch = null;
237
259
  contact = null;
238
260
  changedSinceCut = /* @__PURE__ */ new Map();
@@ -1,4 +1,4 @@
1
- import { simulatedPressure } from "../../internal/penStroke.internal.js";
1
+ import { simulatedPressure } from "../../../internal/penStroke.internal.js";
2
2
  //#region src/react/features/ink/inkInput.internal.ts
3
3
  /**
4
4
  * The layer's `touch-action`: a finger still pans the page natively while the
@@ -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 === "boxes") return;
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
- measure: (element, text, box, origin) => {
17
- const layout = kept.get(element);
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
  };