@tldraw/editor 5.2.0-canary.6421dbe4e25a → 5.2.0-canary.667cbd6bb6ff

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 (94) hide show
  1. package/dist-cjs/index.d.ts +13 -13
  2. package/dist-cjs/index.js +1 -5
  3. package/dist-cjs/index.js.map +2 -2
  4. package/dist-cjs/lib/components/MenuClickCapture.js +8 -5
  5. package/dist-cjs/lib/components/MenuClickCapture.js.map +2 -2
  6. package/dist-cjs/lib/components/default-components/DefaultCanvas.js +1 -16
  7. package/dist-cjs/lib/components/default-components/DefaultCanvas.js.map +2 -2
  8. package/dist-cjs/lib/editor/Editor.js +11 -2
  9. package/dist-cjs/lib/editor/Editor.js.map +2 -2
  10. package/dist-cjs/lib/editor/managers/FontManager/FontManager.js +28 -4
  11. package/dist-cjs/lib/editor/managers/FontManager/FontManager.js.map +3 -3
  12. package/dist-cjs/lib/editor/managers/HistoryManager/HistoryManager.js +12 -0
  13. package/dist-cjs/lib/editor/managers/HistoryManager/HistoryManager.js.map +2 -2
  14. package/dist-cjs/lib/editor/managers/InputsManager/InputsManager.js +14 -3
  15. package/dist-cjs/lib/editor/managers/InputsManager/InputsManager.js.map +2 -2
  16. package/dist-cjs/lib/editor/managers/TickManager/TickManager.js +0 -1
  17. package/dist-cjs/lib/editor/managers/TickManager/TickManager.js.map +2 -2
  18. package/dist-cjs/lib/editor/types/event-types.js.map +2 -2
  19. package/dist-cjs/lib/globals/environment.js +6 -1
  20. package/dist-cjs/lib/globals/environment.js.map +2 -2
  21. package/dist-cjs/lib/hooks/EditorComponentsContext.js.map +2 -2
  22. package/dist-cjs/lib/hooks/useCanvasEvents.js +17 -8
  23. package/dist-cjs/lib/hooks/useCanvasEvents.js.map +2 -2
  24. package/dist-cjs/lib/hooks/useEditorComponents.js +0 -1
  25. package/dist-cjs/lib/hooks/useEditorComponents.js.map +2 -2
  26. package/dist-cjs/lib/utils/getPointerInfo.js +2 -1
  27. package/dist-cjs/lib/utils/getPointerInfo.js.map +2 -2
  28. package/dist-cjs/lib/{hooks/useTransform.js → utils/pointer.js} +17 -23
  29. package/dist-cjs/lib/utils/pointer.js.map +7 -0
  30. package/dist-cjs/version.js +3 -3
  31. package/dist-cjs/version.js.map +1 -1
  32. package/dist-esm/index.d.mts +13 -13
  33. package/dist-esm/index.mjs +1 -7
  34. package/dist-esm/index.mjs.map +2 -2
  35. package/dist-esm/lib/components/MenuClickCapture.mjs +8 -5
  36. package/dist-esm/lib/components/MenuClickCapture.mjs.map +2 -2
  37. package/dist-esm/lib/components/default-components/DefaultCanvas.mjs +1 -16
  38. package/dist-esm/lib/components/default-components/DefaultCanvas.mjs.map +2 -2
  39. package/dist-esm/lib/editor/Editor.mjs +11 -2
  40. package/dist-esm/lib/editor/Editor.mjs.map +2 -2
  41. package/dist-esm/lib/editor/managers/FontManager/FontManager.mjs +28 -4
  42. package/dist-esm/lib/editor/managers/FontManager/FontManager.mjs.map +3 -3
  43. package/dist-esm/lib/editor/managers/HistoryManager/HistoryManager.mjs +12 -0
  44. package/dist-esm/lib/editor/managers/HistoryManager/HistoryManager.mjs.map +2 -2
  45. package/dist-esm/lib/editor/managers/InputsManager/InputsManager.mjs +14 -3
  46. package/dist-esm/lib/editor/managers/InputsManager/InputsManager.mjs.map +2 -2
  47. package/dist-esm/lib/editor/managers/TickManager/TickManager.mjs +0 -1
  48. package/dist-esm/lib/editor/managers/TickManager/TickManager.mjs.map +2 -2
  49. package/dist-esm/lib/editor/types/event-types.mjs.map +2 -2
  50. package/dist-esm/lib/globals/environment.mjs +6 -1
  51. package/dist-esm/lib/globals/environment.mjs.map +2 -2
  52. package/dist-esm/lib/hooks/EditorComponentsContext.mjs.map +2 -2
  53. package/dist-esm/lib/hooks/useCanvasEvents.mjs +17 -8
  54. package/dist-esm/lib/hooks/useCanvasEvents.mjs.map +2 -2
  55. package/dist-esm/lib/hooks/useEditorComponents.mjs +0 -1
  56. package/dist-esm/lib/hooks/useEditorComponents.mjs.map +2 -2
  57. package/dist-esm/lib/utils/getPointerInfo.mjs +2 -1
  58. package/dist-esm/lib/utils/getPointerInfo.mjs.map +2 -2
  59. package/dist-esm/lib/utils/pointer.mjs +17 -0
  60. package/dist-esm/lib/utils/pointer.mjs.map +7 -0
  61. package/dist-esm/version.mjs +3 -3
  62. package/dist-esm/version.mjs.map +1 -1
  63. package/editor.css +3 -3
  64. package/package.json +10 -7
  65. package/src/index.ts +0 -5
  66. package/src/lib/components/MenuClickCapture.tsx +8 -4
  67. package/src/lib/components/default-components/DefaultCanvas.tsx +1 -17
  68. package/src/lib/editor/Editor.ts +15 -5
  69. package/src/lib/editor/managers/FontManager/FontManager.test.ts +24 -1
  70. package/src/lib/editor/managers/FontManager/FontManager.ts +46 -1
  71. package/src/lib/editor/managers/HistoryManager/HistoryManager.test.ts +32 -0
  72. package/src/lib/editor/managers/HistoryManager/HistoryManager.ts +14 -2
  73. package/src/lib/editor/managers/InputsManager/InputsManager.test.ts +61 -0
  74. package/src/lib/editor/managers/InputsManager/InputsManager.ts +16 -4
  75. package/src/lib/editor/managers/TickManager/TickManager.test.ts +0 -40
  76. package/src/lib/editor/managers/TickManager/TickManager.ts +0 -1
  77. package/src/lib/editor/types/event-types.ts +7 -0
  78. package/src/lib/globals/environment.ts +7 -0
  79. package/src/lib/hooks/EditorComponentsContext.tsx +0 -2
  80. package/src/lib/hooks/useCanvasEvents.ts +24 -12
  81. package/src/lib/hooks/useEditorComponents.tsx +0 -1
  82. package/src/lib/utils/getPointerInfo.ts +2 -1
  83. package/src/lib/utils/pointer.test.ts +76 -0
  84. package/src/lib/utils/pointer.ts +42 -0
  85. package/src/version.ts +3 -3
  86. package/dist-cjs/lib/components/default-components/DefaultSelectionBackground.js +0 -49
  87. package/dist-cjs/lib/components/default-components/DefaultSelectionBackground.js.map +0 -7
  88. package/dist-cjs/lib/hooks/useTransform.js.map +0 -7
  89. package/dist-esm/lib/components/default-components/DefaultSelectionBackground.mjs +0 -19
  90. package/dist-esm/lib/components/default-components/DefaultSelectionBackground.mjs.map +0 -7
  91. package/dist-esm/lib/hooks/useTransform.mjs +0 -23
  92. package/dist-esm/lib/hooks/useTransform.mjs.map +0 -7
  93. package/src/lib/components/default-components/DefaultSelectionBackground.tsx +0 -25
  94. package/src/lib/hooks/useTransform.ts +0 -30
@@ -8,6 +8,7 @@ import {
8
8
  setPointerCapture
9
9
  } from "../utils/dom.mjs";
10
10
  import { getPointerInfo } from "../utils/getPointerInfo.mjs";
11
+ import { getPointerEventButton, isDirectDisplayPen, isSecondaryClickEvent } from "../utils/pointer.mjs";
11
12
  import { useEditor } from "./useEditor.mjs";
12
13
  function useCanvasEvents() {
13
14
  const editor = useEditor();
@@ -15,9 +16,12 @@ function useCanvasEvents() {
15
16
  const currentTool = useValue("current tool", () => editor.getCurrentTool(), [editor]);
16
17
  const events = useMemo(
17
18
  function canvasEvents() {
19
+ let isSecondaryClickPointerDown = false;
18
20
  function onPointerDown(e) {
19
21
  if (editor.wasEventAlreadyHandled(e)) return;
20
- if (e.button === 2 && !editor.options.rightClickPanning) {
22
+ const button = getPointerEventButton(e);
23
+ isSecondaryClickPointerDown = button === 2;
24
+ if (button === 2 && !editor.options.rightClickPanning) {
21
25
  editor.dispatch({
22
26
  type: "pointer",
23
27
  target: "canvas",
@@ -26,28 +30,32 @@ function useCanvasEvents() {
26
30
  });
27
31
  return;
28
32
  }
29
- if (e.button !== 0 && e.button !== 1 && e.button !== 2 && e.button !== 5) return;
33
+ if (button !== 0 && button !== 1 && button !== 2 && button !== 5) return;
34
+ const isPenDirect = isDirectDisplayPen(e);
30
35
  setPointerCapture(e.currentTarget, e);
31
36
  editor.dispatch({
32
37
  type: "pointer",
33
38
  target: "canvas",
34
39
  name: "pointer_down",
35
- ...getPointerInfo(editor, e)
40
+ ...getPointerInfo(editor, e),
41
+ isPenDirect
36
42
  });
37
43
  }
38
44
  function onPointerUp(e) {
39
45
  if (editor.wasEventAlreadyHandled(e)) return;
40
- if (e.button !== 0 && e.button !== 1 && e.button !== 2 && e.button !== 5) return;
46
+ const button = isSecondaryClickPointerDown ? 2 : getPointerEventButton(e);
47
+ if (button !== 0 && button !== 1 && button !== 2 && button !== 5) return;
41
48
  const rightClickPanning = editor.options.rightClickPanning;
42
- const wasRightClickPanning = rightClickPanning && e.button === 2 && editor.inputs.getIsPanning();
49
+ const wasRightClickPanning = rightClickPanning && button === 2 && editor.inputs.getIsPanning();
43
50
  releasePointerCapture(e.currentTarget, e);
44
51
  editor.dispatch({
45
52
  type: "pointer",
46
53
  target: "canvas",
47
54
  name: "pointer_up",
48
- ...getPointerInfo(editor, e)
55
+ ...getPointerInfo(editor, e),
56
+ button
49
57
  });
50
- if (rightClickPanning && e.button === 2 && !wasRightClickPanning) {
58
+ if (rightClickPanning && button === 2 && !wasRightClickPanning) {
51
59
  const contextMenuEvent = new PointerEvent("contextmenu", {
52
60
  bubbles: true,
53
61
  clientX: e.clientX,
@@ -60,6 +68,7 @@ function useCanvasEvents() {
60
68
  });
61
69
  e.currentTarget.dispatchEvent(contextMenuEvent);
62
70
  }
71
+ isSecondaryClickPointerDown = false;
63
72
  }
64
73
  function onPointerEnter(e) {
65
74
  if (editor.wasEventAlreadyHandled(e)) return;
@@ -134,7 +143,7 @@ function useCanvasEvents() {
134
143
  function onContextMenu(e) {
135
144
  if (!editor.options.rightClickPanning) return;
136
145
  if (!e.nativeEvent.isTrusted) return;
137
- if (e.button !== 2 || e.ctrlKey) return;
146
+ if (!isSecondaryClickEvent(e)) return;
138
147
  preventDefault(e);
139
148
  }
140
149
  return {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/lib/hooks/useCanvasEvents.ts"],
4
- "sourcesContent": ["import { useValue } from '@tldraw/state-react'\nimport React, { useEffect, useMemo } from 'react'\nimport { tlenv } from '../globals/environment'\nimport {\n\telementShouldCaptureKeys,\n\tpreventDefault,\n\treleasePointerCapture,\n\tsetPointerCapture,\n} from '../utils/dom'\nimport { getPointerInfo } from '../utils/getPointerInfo'\nimport { useEditor } from './useEditor'\n\nexport function useCanvasEvents() {\n\tconst editor = useEditor()\n\tconst ownerDocument = editor.getContainerDocument()\n\tconst currentTool = useValue('current tool', () => editor.getCurrentTool(), [editor])\n\n\tconst events = useMemo(\n\t\tfunction canvasEvents() {\n\t\t\tfunction onPointerDown(e: React.PointerEvent) {\n\t\t\t\tif (editor.wasEventAlreadyHandled(e)) return\n\n\t\t\t\t// With right-click panning disabled, fire right_click on press and let the\n\t\t\t\t// native contextmenu through so the menu opens at the pointer-down location.\n\t\t\t\tif (e.button === 2 && !editor.options.rightClickPanning) {\n\t\t\t\t\teditor.dispatch({\n\t\t\t\t\t\ttype: 'pointer',\n\t\t\t\t\t\ttarget: 'canvas',\n\t\t\t\t\t\tname: 'right_click',\n\t\t\t\t\t\t...getPointerInfo(editor, e),\n\t\t\t\t\t})\n\t\t\t\t\treturn\n\t\t\t\t}\n\n\t\t\t\tif (e.button !== 0 && e.button !== 1 && e.button !== 2 && e.button !== 5) return\n\n\t\t\t\tsetPointerCapture(e.currentTarget, e)\n\n\t\t\t\teditor.dispatch({\n\t\t\t\t\ttype: 'pointer',\n\t\t\t\t\ttarget: 'canvas',\n\t\t\t\t\tname: 'pointer_down',\n\t\t\t\t\t...getPointerInfo(editor, e),\n\t\t\t\t})\n\t\t\t}\n\n\t\t\tfunction onPointerUp(e: React.PointerEvent) {\n\t\t\t\tif (editor.wasEventAlreadyHandled(e)) return\n\t\t\t\tif (e.button !== 0 && e.button !== 1 && e.button !== 2 && e.button !== 5) return\n\n\t\t\t\tconst rightClickPanning = editor.options.rightClickPanning\n\t\t\t\t// Check before dispatch (which resets isPanning)\n\t\t\t\tconst wasRightClickPanning =\n\t\t\t\t\trightClickPanning && e.button === 2 && editor.inputs.getIsPanning()\n\n\t\t\t\treleasePointerCapture(e.currentTarget, e)\n\n\t\t\t\teditor.dispatch({\n\t\t\t\t\ttype: 'pointer',\n\t\t\t\t\ttarget: 'canvas',\n\t\t\t\t\tname: 'pointer_up',\n\t\t\t\t\t...getPointerInfo(editor, e),\n\t\t\t\t})\n\n\t\t\t\t// Static right-click: fire contextmenu at the pointer-up location\n\t\t\t\tif (rightClickPanning && e.button === 2 && !wasRightClickPanning) {\n\t\t\t\t\tconst contextMenuEvent = new PointerEvent('contextmenu', {\n\t\t\t\t\t\tbubbles: true,\n\t\t\t\t\t\tclientX: e.clientX,\n\t\t\t\t\t\tclientY: e.clientY,\n\t\t\t\t\t\tbutton: 2,\n\t\t\t\t\t\tbuttons: 0,\n\t\t\t\t\t\tpointerId: e.pointerId,\n\t\t\t\t\t\tpointerType: e.pointerType,\n\t\t\t\t\t\tisPrimary: e.isPrimary,\n\t\t\t\t\t})\n\t\t\t\t\te.currentTarget.dispatchEvent(contextMenuEvent)\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tfunction onPointerEnter(e: React.PointerEvent) {\n\t\t\t\tif (editor.wasEventAlreadyHandled(e)) return\n\t\t\t\tif (editor.getInstanceState().isPenMode && e.pointerType !== 'pen') return\n\t\t\t\tconst canHover = e.pointerType === 'mouse' || e.pointerType === 'pen'\n\t\t\t\teditor.updateInstanceState({ isHoveringCanvas: canHover ? true : null })\n\t\t\t}\n\n\t\t\tfunction onPointerLeave(e: React.PointerEvent) {\n\t\t\t\tif (editor.wasEventAlreadyHandled(e)) return\n\t\t\t\tif (editor.getInstanceState().isPenMode && e.pointerType !== 'pen') return\n\t\t\t\tconst canHover = e.pointerType === 'mouse' || e.pointerType === 'pen'\n\t\t\t\teditor.updateInstanceState({ isHoveringCanvas: canHover ? false : null })\n\t\t\t}\n\n\t\t\tfunction onTouchStart(e: React.TouchEvent) {\n\t\t\t\tif (editor.wasEventAlreadyHandled(e)) return\n\t\t\t\teditor.markEventAsHandled(e)\n\t\t\t\tpreventDefault(e)\n\t\t\t}\n\n\t\t\tfunction onTouchEnd(e: React.TouchEvent) {\n\t\t\t\tif (editor.wasEventAlreadyHandled(e)) return\n\t\t\t\teditor.markEventAsHandled(e)\n\t\t\t\tif (!(e.target instanceof editor.getContainerWindow().HTMLElement)) return\n\n\t\t\t\tconst editingShapeId = editor.getEditingShapeId()\n\t\t\t\tif (\n\t\t\t\t\t// if the target is not inside the editing shape\n\t\t\t\t\t!(editingShapeId && e.target.closest(`[data-shape-id=\"${editingShapeId}\"]`)) &&\n\t\t\t\t\t// and the target is not an clickable element\n\t\t\t\t\te.target.tagName !== 'A' &&\n\t\t\t\t\t// and the target is not an editable element\n\t\t\t\t\t!elementShouldCaptureKeys(e.target, false)\n\t\t\t\t) {\n\t\t\t\t\tpreventDefault(e)\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tfunction onDragOver(e: React.DragEvent<Element>) {\n\t\t\t\tif (editor.wasEventAlreadyHandled(e)) return\n\t\t\t\tpreventDefault(e)\n\t\t\t}\n\n\t\t\tasync function onDrop(e: React.DragEvent<Element>) {\n\t\t\t\tif (editor.wasEventAlreadyHandled(e)) return\n\t\t\t\tpreventDefault(e)\n\t\t\t\te.stopPropagation()\n\n\t\t\t\tconst pagePoint = editor.screenToPage({ x: e.clientX, y: e.clientY })\n\n\t\t\t\t// Call the custom onDropOnCanvas callback if provided\n\t\t\t\tif (editor.options.experimental__onDropOnCanvas) {\n\t\t\t\t\tconst handled = editor.options.experimental__onDropOnCanvas({\n\t\t\t\t\t\tpoint: pagePoint,\n\t\t\t\t\t\tevent: e,\n\t\t\t\t\t})\n\t\t\t\t\tif (handled) return\n\t\t\t\t}\n\n\t\t\t\tif (e.dataTransfer?.files?.length) {\n\t\t\t\t\tconst files = Array.from(e.dataTransfer.files)\n\n\t\t\t\t\tawait editor.putExternalContent({\n\t\t\t\t\t\ttype: 'files',\n\t\t\t\t\t\tfiles,\n\t\t\t\t\t\tpoint: pagePoint,\n\t\t\t\t\t})\n\t\t\t\t\treturn\n\t\t\t\t}\n\n\t\t\t\tconst url = e.dataTransfer.getData('url')\n\t\t\t\tif (url) {\n\t\t\t\t\tawait editor.putExternalContent({\n\t\t\t\t\t\ttype: 'url',\n\t\t\t\t\t\turl,\n\t\t\t\t\t\tpoint: pagePoint,\n\t\t\t\t\t})\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tfunction onClick(e: React.MouseEvent) {\n\t\t\t\tif (editor.wasEventAlreadyHandled(e)) return\n\t\t\t\te.stopPropagation()\n\t\t\t}\n\n\t\t\tfunction onContextMenu(e: React.MouseEvent) {\n\t\t\t\t// With right-click panning disabled, let the native contextmenu through so the\n\t\t\t\t// menu opens on press.\n\t\t\t\tif (!editor.options.rightClickPanning) return\n\t\t\t\t// Synthetic events \u2014 our own dispatch from onPointerUp, or tests using\n\t\t\t\t// fireEvent.contextMenu \u2014 pass through so Radix can open the menu.\n\t\t\t\tif (!e.nativeEvent.isTrusted) return\n\t\t\t\t// Only suppress the native browser contextmenu when it follows a real\n\t\t\t\t// right-click (button=2 with no ctrl modifier). For those, our pointer\n\t\t\t\t// handling has already decided what to do (either we'll dispatch a\n\t\t\t\t// synthetic contextmenu on pointerup to open the menu at the release\n\t\t\t\t// position, or we panned and don't want a menu at all).\n\t\t\t\t//\n\t\t\t\t// Other contextmenu sources must reach Radix so the menu opens:\n\t\t\t\t// - ctrl+click on macOS (button=0, or button=2 with ctrlKey=true)\n\t\t\t\t// - long-press on touch devices (button=0, pointerType=touch)\n\t\t\t\tif (e.button !== 2 || e.ctrlKey) return\n\t\t\t\tpreventDefault(e)\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\tonPointerDown,\n\t\t\t\tonPointerUp,\n\t\t\t\tonPointerEnter,\n\t\t\t\tonPointerLeave,\n\t\t\t\tonDragOver,\n\t\t\t\tonDrop,\n\t\t\t\tonTouchStart,\n\t\t\t\tonTouchEnd,\n\t\t\t\tonClick,\n\t\t\t\tonContextMenu,\n\t\t\t}\n\t\t},\n\t\t[editor]\n\t)\n\n\t// onPointerMove is special: where we're only interested in the other events when they're\n\t// happening _on_ the canvas (as opposed to outside of it, or on UI floating over it), we want\n\t// the pointer position to be up to date regardless of whether it's over the tldraw canvas or\n\t// not. So instead of returning a listener to be attached to the canvas, we directly attach a\n\t// listener to the whole document instead.\n\tuseEffect(() => {\n\t\tlet lastX: number, lastY: number\n\n\t\tfunction onPointerMove(e: PointerEvent) {\n\t\t\tif (editor.wasEventAlreadyHandled(e)) return\n\t\t\teditor.markEventAsHandled(e)\n\n\t\t\tif (e.clientX === lastX && e.clientY === lastY) return\n\t\t\tlastX = e.clientX\n\t\t\tlastY = e.clientY\n\n\t\t\t// For tools that benefit from a higher fidelity of events,\n\t\t\t// we dispatch the coalesced events.\n\t\t\t// N.B. Sometimes getCoalescedEvents isn't present on iOS, ugh.\n\t\t\t// Specifically, in local mode (non-https) mode, iOS does not `useCoalescedEvents`\n\t\t\t// so it appears like the ink is working locally, when really it's just that `useCoalescedEvents`\n\t\t\t// is disabled. The intent here is to have `useCoalescedEvents` disabled for iOS.\n\t\t\tconst events =\n\t\t\t\t!tlenv.isIos && currentTool.useCoalescedEvents && e.getCoalescedEvents\n\t\t\t\t\t? e.getCoalescedEvents()\n\t\t\t\t\t: [e]\n\n\t\t\tfor (const singleEvent of events) {\n\t\t\t\teditor.dispatch({\n\t\t\t\t\ttype: 'pointer',\n\t\t\t\t\ttarget: 'canvas',\n\t\t\t\t\tname: 'pointer_move',\n\t\t\t\t\t...getPointerInfo(editor, singleEvent),\n\t\t\t\t})\n\t\t\t}\n\t\t}\n\n\t\townerDocument.body.addEventListener('pointermove', onPointerMove)\n\t\treturn () => {\n\t\t\townerDocument.body.removeEventListener('pointermove', onPointerMove)\n\t\t}\n\t}, [editor, currentTool, ownerDocument])\n\n\treturn events\n}\n"],
5
- "mappings": "AAAA,SAAS,gBAAgB;AACzB,SAAgB,WAAW,eAAe;AAC1C,SAAS,aAAa;AACtB;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP,SAAS,sBAAsB;AAC/B,SAAS,iBAAiB;AAEnB,SAAS,kBAAkB;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AM;AAAA,EACR;AAOA,YAAU,MAAM;AACf,QAAI,OAAe;AAEnB,aAAS,cAAc,GAAiB;AACvC,UAAI,OAAO,uBAAuB,CAAC,EAAG;AACtC,aAAO,mBAAmB,CAAC;AAE3B,UAAI,EAAE,YAAY,SAAS,EAAE,YAAY,MAAO;AAChD,cAAQ,EAAE;AACV,cAAQ,EAAE;AAQV,YAAMA,UACL,CAAC,MAAM,SAAS,YAAY,sBAAsB,EAAE,qBACjD,EAAE,mBAAmB,IACrB,CAAC,CAAC;AAEN,iBAAW,eAAeA,SAAQ;AACjC,eAAO,SAAS;AAAA,UACf,MAAM;AAAA,UACN,QAAQ;AAAA,UACR,MAAM;AAAA,UACN,GAAG,eAAe,QAAQ,WAAW;AAAA,QACtC,CAAC;AAAA,MACF;AAAA,IACD;AAEA,kBAAc,KAAK,iBAAiB,eAAe,aAAa;AAChE,WAAO,MAAM;AACZ,oBAAc,KAAK,oBAAoB,eAAe,aAAa;AAAA,IACpE;AAAA,EACD,GAAG,CAAC,QAAQ,aAAa,aAAa,CAAC;AAEvC,SAAO;AACR;",
4
+ "sourcesContent": ["import { useValue } from '@tldraw/state-react'\nimport React, { useEffect, useMemo } from 'react'\nimport { tlenv } from '../globals/environment'\nimport {\n\telementShouldCaptureKeys,\n\tpreventDefault,\n\treleasePointerCapture,\n\tsetPointerCapture,\n} from '../utils/dom'\nimport { getPointerInfo } from '../utils/getPointerInfo'\nimport { getPointerEventButton, isDirectDisplayPen, isSecondaryClickEvent } from '../utils/pointer'\nimport { useEditor } from './useEditor'\n\nexport function useCanvasEvents() {\n\tconst editor = useEditor()\n\tconst ownerDocument = editor.getContainerDocument()\n\tconst currentTool = useValue('current tool', () => editor.getCurrentTool(), [editor])\n\n\tconst events = useMemo(\n\t\tfunction canvasEvents() {\n\t\t\tlet isSecondaryClickPointerDown = false\n\n\t\t\tfunction onPointerDown(e: React.PointerEvent) {\n\t\t\t\tif (editor.wasEventAlreadyHandled(e)) return\n\t\t\t\tconst button = getPointerEventButton(e)\n\t\t\t\tisSecondaryClickPointerDown = button === 2\n\n\t\t\t\t// With right-click panning disabled, fire right_click on press and let the\n\t\t\t\t// native contextmenu through so the menu opens at the pointer-down location.\n\t\t\t\tif (button === 2 && !editor.options.rightClickPanning) {\n\t\t\t\t\teditor.dispatch({\n\t\t\t\t\t\ttype: 'pointer',\n\t\t\t\t\t\ttarget: 'canvas',\n\t\t\t\t\t\tname: 'right_click',\n\t\t\t\t\t\t...getPointerInfo(editor, e),\n\t\t\t\t\t})\n\t\t\t\t\treturn\n\t\t\t\t}\n\n\t\t\t\tif (button !== 0 && button !== 1 && button !== 2 && button !== 5) return\n\n\t\t\t\t// Detect direct-display pen input (Apple Pencil, Surface Pen on a touchscreen) so we\n\t\t\t\t// only auto-enable pen mode for it, not for an indirect desktop tablet stylus.\n\t\t\t\tconst isPenDirect = isDirectDisplayPen(e)\n\n\t\t\t\tsetPointerCapture(e.currentTarget, e)\n\n\t\t\t\teditor.dispatch({\n\t\t\t\t\ttype: 'pointer',\n\t\t\t\t\ttarget: 'canvas',\n\t\t\t\t\tname: 'pointer_down',\n\t\t\t\t\t...getPointerInfo(editor, e),\n\t\t\t\t\tisPenDirect,\n\t\t\t\t})\n\t\t\t}\n\n\t\t\tfunction onPointerUp(e: React.PointerEvent) {\n\t\t\t\tif (editor.wasEventAlreadyHandled(e)) return\n\t\t\t\tconst button = isSecondaryClickPointerDown ? 2 : getPointerEventButton(e)\n\t\t\t\tif (button !== 0 && button !== 1 && button !== 2 && button !== 5) return\n\n\t\t\t\tconst rightClickPanning = editor.options.rightClickPanning\n\t\t\t\t// Check before dispatch (which resets isPanning)\n\t\t\t\tconst wasRightClickPanning =\n\t\t\t\t\trightClickPanning && button === 2 && editor.inputs.getIsPanning()\n\n\t\t\t\treleasePointerCapture(e.currentTarget, e)\n\n\t\t\t\teditor.dispatch({\n\t\t\t\t\ttype: 'pointer',\n\t\t\t\t\ttarget: 'canvas',\n\t\t\t\t\tname: 'pointer_up',\n\t\t\t\t\t...getPointerInfo(editor, e),\n\t\t\t\t\tbutton,\n\t\t\t\t})\n\n\t\t\t\t// Static right-click: fire contextmenu at the pointer-up location\n\t\t\t\tif (rightClickPanning && button === 2 && !wasRightClickPanning) {\n\t\t\t\t\tconst contextMenuEvent = new PointerEvent('contextmenu', {\n\t\t\t\t\t\tbubbles: true,\n\t\t\t\t\t\tclientX: e.clientX,\n\t\t\t\t\t\tclientY: e.clientY,\n\t\t\t\t\t\tbutton: 2,\n\t\t\t\t\t\tbuttons: 0,\n\t\t\t\t\t\tpointerId: e.pointerId,\n\t\t\t\t\t\tpointerType: e.pointerType,\n\t\t\t\t\t\tisPrimary: e.isPrimary,\n\t\t\t\t\t})\n\t\t\t\t\te.currentTarget.dispatchEvent(contextMenuEvent)\n\t\t\t\t}\n\t\t\t\tisSecondaryClickPointerDown = false\n\t\t\t}\n\n\t\t\tfunction onPointerEnter(e: React.PointerEvent) {\n\t\t\t\tif (editor.wasEventAlreadyHandled(e)) return\n\t\t\t\tif (editor.getInstanceState().isPenMode && e.pointerType !== 'pen') return\n\t\t\t\tconst canHover = e.pointerType === 'mouse' || e.pointerType === 'pen'\n\t\t\t\teditor.updateInstanceState({ isHoveringCanvas: canHover ? true : null })\n\t\t\t}\n\n\t\t\tfunction onPointerLeave(e: React.PointerEvent) {\n\t\t\t\tif (editor.wasEventAlreadyHandled(e)) return\n\t\t\t\tif (editor.getInstanceState().isPenMode && e.pointerType !== 'pen') return\n\t\t\t\tconst canHover = e.pointerType === 'mouse' || e.pointerType === 'pen'\n\t\t\t\teditor.updateInstanceState({ isHoveringCanvas: canHover ? false : null })\n\t\t\t}\n\n\t\t\tfunction onTouchStart(e: React.TouchEvent) {\n\t\t\t\tif (editor.wasEventAlreadyHandled(e)) return\n\t\t\t\teditor.markEventAsHandled(e)\n\t\t\t\tpreventDefault(e)\n\t\t\t}\n\n\t\t\tfunction onTouchEnd(e: React.TouchEvent) {\n\t\t\t\tif (editor.wasEventAlreadyHandled(e)) return\n\t\t\t\teditor.markEventAsHandled(e)\n\t\t\t\tif (!(e.target instanceof editor.getContainerWindow().HTMLElement)) return\n\n\t\t\t\tconst editingShapeId = editor.getEditingShapeId()\n\t\t\t\tif (\n\t\t\t\t\t// if the target is not inside the editing shape\n\t\t\t\t\t!(editingShapeId && e.target.closest(`[data-shape-id=\"${editingShapeId}\"]`)) &&\n\t\t\t\t\t// and the target is not an clickable element\n\t\t\t\t\te.target.tagName !== 'A' &&\n\t\t\t\t\t// and the target is not an editable element\n\t\t\t\t\t!elementShouldCaptureKeys(e.target, false)\n\t\t\t\t) {\n\t\t\t\t\tpreventDefault(e)\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tfunction onDragOver(e: React.DragEvent<Element>) {\n\t\t\t\tif (editor.wasEventAlreadyHandled(e)) return\n\t\t\t\tpreventDefault(e)\n\t\t\t}\n\n\t\t\tasync function onDrop(e: React.DragEvent<Element>) {\n\t\t\t\tif (editor.wasEventAlreadyHandled(e)) return\n\t\t\t\tpreventDefault(e)\n\t\t\t\te.stopPropagation()\n\n\t\t\t\tconst pagePoint = editor.screenToPage({ x: e.clientX, y: e.clientY })\n\n\t\t\t\t// Call the custom onDropOnCanvas callback if provided\n\t\t\t\tif (editor.options.experimental__onDropOnCanvas) {\n\t\t\t\t\tconst handled = editor.options.experimental__onDropOnCanvas({\n\t\t\t\t\t\tpoint: pagePoint,\n\t\t\t\t\t\tevent: e,\n\t\t\t\t\t})\n\t\t\t\t\tif (handled) return\n\t\t\t\t}\n\n\t\t\t\tif (e.dataTransfer?.files?.length) {\n\t\t\t\t\tconst files = Array.from(e.dataTransfer.files)\n\n\t\t\t\t\tawait editor.putExternalContent({\n\t\t\t\t\t\ttype: 'files',\n\t\t\t\t\t\tfiles,\n\t\t\t\t\t\tpoint: pagePoint,\n\t\t\t\t\t})\n\t\t\t\t\treturn\n\t\t\t\t}\n\n\t\t\t\tconst url = e.dataTransfer.getData('url')\n\t\t\t\tif (url) {\n\t\t\t\t\tawait editor.putExternalContent({\n\t\t\t\t\t\ttype: 'url',\n\t\t\t\t\t\turl,\n\t\t\t\t\t\tpoint: pagePoint,\n\t\t\t\t\t})\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tfunction onClick(e: React.MouseEvent) {\n\t\t\t\tif (editor.wasEventAlreadyHandled(e)) return\n\t\t\t\te.stopPropagation()\n\t\t\t}\n\n\t\t\tfunction onContextMenu(e: React.MouseEvent) {\n\t\t\t\t// With right-click panning disabled, let the native contextmenu through so the\n\t\t\t\t// menu opens on press.\n\t\t\t\tif (!editor.options.rightClickPanning) return\n\t\t\t\t// Synthetic events \u2014 our own dispatch from onPointerUp, or tests using\n\t\t\t\t// fireEvent.contextMenu \u2014 pass through so Radix can open the menu.\n\t\t\t\tif (!e.nativeEvent.isTrusted) return\n\t\t\t\t// Only suppress the native browser contextmenu when it follows a\n\t\t\t\t// secondary click. For those, our pointer handling has already\n\t\t\t\t// decided what to do (either we'll dispatch a synthetic contextmenu on\n\t\t\t\t// pointerup to open the menu at the release position, or we panned and\n\t\t\t\t// don't want a menu at all).\n\t\t\t\t//\n\t\t\t\t// Other contextmenu sources must reach Radix so the menu opens:\n\t\t\t\t// - long-press on touch devices (button=0, pointerType=touch)\n\t\t\t\tif (!isSecondaryClickEvent(e)) return\n\t\t\t\tpreventDefault(e)\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\tonPointerDown,\n\t\t\t\tonPointerUp,\n\t\t\t\tonPointerEnter,\n\t\t\t\tonPointerLeave,\n\t\t\t\tonDragOver,\n\t\t\t\tonDrop,\n\t\t\t\tonTouchStart,\n\t\t\t\tonTouchEnd,\n\t\t\t\tonClick,\n\t\t\t\tonContextMenu,\n\t\t\t}\n\t\t},\n\t\t[editor]\n\t)\n\n\t// onPointerMove is special: where we're only interested in the other events when they're\n\t// happening _on_ the canvas (as opposed to outside of it, or on UI floating over it), we want\n\t// the pointer position to be up to date regardless of whether it's over the tldraw canvas or\n\t// not. So instead of returning a listener to be attached to the canvas, we directly attach a\n\t// listener to the whole document instead.\n\tuseEffect(() => {\n\t\tlet lastX: number, lastY: number\n\n\t\tfunction onPointerMove(e: PointerEvent) {\n\t\t\tif (editor.wasEventAlreadyHandled(e)) return\n\t\t\teditor.markEventAsHandled(e)\n\n\t\t\tif (e.clientX === lastX && e.clientY === lastY) return\n\t\t\tlastX = e.clientX\n\t\t\tlastY = e.clientY\n\n\t\t\t// For tools that benefit from a higher fidelity of events,\n\t\t\t// we dispatch the coalesced events.\n\t\t\t// N.B. Sometimes getCoalescedEvents isn't present on iOS, ugh.\n\t\t\t// Specifically, in local mode (non-https) mode, iOS does not `useCoalescedEvents`\n\t\t\t// so it appears like the ink is working locally, when really it's just that `useCoalescedEvents`\n\t\t\t// is disabled. The intent here is to have `useCoalescedEvents` disabled for iOS.\n\t\t\tconst events =\n\t\t\t\t!tlenv.isIos && currentTool.useCoalescedEvents && e.getCoalescedEvents\n\t\t\t\t\t? e.getCoalescedEvents()\n\t\t\t\t\t: [e]\n\n\t\t\tfor (const singleEvent of events) {\n\t\t\t\teditor.dispatch({\n\t\t\t\t\ttype: 'pointer',\n\t\t\t\t\ttarget: 'canvas',\n\t\t\t\t\tname: 'pointer_move',\n\t\t\t\t\t...getPointerInfo(editor, singleEvent),\n\t\t\t\t})\n\t\t\t}\n\t\t}\n\n\t\townerDocument.body.addEventListener('pointermove', onPointerMove)\n\t\treturn () => {\n\t\t\townerDocument.body.removeEventListener('pointermove', onPointerMove)\n\t\t}\n\t}, [editor, currentTool, ownerDocument])\n\n\treturn events\n}\n"],
5
+ "mappings": "AAAA,SAAS,gBAAgB;AACzB,SAAgB,WAAW,eAAe;AAC1C,SAAS,aAAa;AACtB;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP,SAAS,sBAAsB;AAC/B,SAAS,uBAAuB,oBAAoB,6BAA6B;AACjF,SAAS,iBAAiB;AAEnB,SAAS,kBAAkB;AACjC,QAAM,SAAS,UAAU;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ACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACD;AAAA,IACD;AAAA,IACA,CAAC,MAAM;AAAA,EACR;AAOA,YAAU,MAAM;AACf,QAAI,OAAe;AAEnB,aAAS,cAAc,GAAiB;AACvC,UAAI,OAAO,uBAAuB,CAAC,EAAG;AACtC,aAAO,mBAAmB,CAAC;AAE3B,UAAI,EAAE,YAAY,SAAS,EAAE,YAAY,MAAO;AAChD,cAAQ,EAAE;AACV,cAAQ,EAAE;AAQV,YAAMA,UACL,CAAC,MAAM,SAAS,YAAY,sBAAsB,EAAE,qBACjD,EAAE,mBAAmB,IACrB,CAAC,CAAC;AAEN,iBAAW,eAAeA,SAAQ;AACjC,eAAO,SAAS;AAAA,UACf,MAAM;AAAA,UACN,QAAQ;AAAA,UACR,MAAM;AAAA,UACN,GAAG,eAAe,QAAQ,WAAW;AAAA,QACtC,CAAC;AAAA,MACF;AAAA,IACD;AAEA,kBAAc,KAAK,iBAAiB,eAAe,aAAa;AAChE,WAAO,MAAM;AACZ,oBAAc,KAAK,oBAAoB,eAAe,aAAa;AAAA,IACpE;AAAA,EACD,GAAG,CAAC,QAAQ,aAAa,aAAa,CAAC;AAEvC,SAAO;AACR;",
6
6
  "names": ["events"]
7
7
  }
@@ -25,7 +25,6 @@ function EditorComponentsProvider({
25
25
  InFrontOfTheCanvas: null,
26
26
  LoadingScreen: DefaultLoadingScreen,
27
27
  OnTheCanvas: null,
28
- SelectionBackground: null,
29
28
  ShapeWrapper: DefaultShapeWrapper,
30
29
  Spinner: DefaultSpinner,
31
30
  SvgDefs: DefaultSvgDefs,
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/lib/hooks/useEditorComponents.tsx"],
4
- "sourcesContent": ["import { ReactNode, useMemo } from 'react'\nimport { DefaultBackground } from '../components/default-components/DefaultBackground'\nimport { DefaultCanvas } from '../components/default-components/DefaultCanvas'\nimport { DefaultErrorFallback } from '../components/default-components/DefaultErrorFallback'\nimport { DefaultGrid } from '../components/default-components/DefaultGrid'\nimport { DefaultLoadingScreen } from '../components/default-components/DefaultLoadingScreen'\nimport { DefaultShapeErrorFallback } from '../components/default-components/DefaultShapeErrorFallback'\nimport { DefaultShapeWrapper } from '../components/default-components/DefaultShapeWrapper'\nimport { DefaultSpinner } from '../components/default-components/DefaultSpinner'\nimport { DefaultSvgDefs } from '../components/default-components/DefaultSvgDefs'\nimport { EditorComponentsContext } from './EditorComponentsContext'\nimport type { TLEditorComponents } from './EditorComponentsContext'\nimport { useShallowObjectIdentity } from './useIdentity'\n\nexport { useEditorComponents } from './EditorComponentsContext'\nexport type { TLEditorComponents } from './EditorComponentsContext'\n\ninterface ComponentsContextProviderProps {\n\toverrides?: TLEditorComponents\n\tchildren: ReactNode\n}\n\nexport function EditorComponentsProvider({\n\toverrides = {},\n\tchildren,\n}: ComponentsContextProviderProps) {\n\tconst _overrides = useShallowObjectIdentity(overrides)\n\tconst value = useMemo(\n\t\t(): Required<TLEditorComponents> => ({\n\t\t\tBackground: DefaultBackground,\n\t\t\tCanvas: DefaultCanvas,\n\t\t\tGrid: DefaultGrid,\n\t\t\tInFrontOfTheCanvas: null,\n\t\t\tLoadingScreen: DefaultLoadingScreen,\n\t\t\tOnTheCanvas: null,\n\t\t\tSelectionBackground: null,\n\t\t\tShapeWrapper: DefaultShapeWrapper,\n\t\t\tSpinner: DefaultSpinner,\n\t\t\tSvgDefs: DefaultSvgDefs,\n\n\t\t\tErrorFallback: DefaultErrorFallback,\n\t\t\tShapeErrorFallback: DefaultShapeErrorFallback,\n\n\t\t\t..._overrides,\n\t\t}),\n\t\t[_overrides]\n\t)\n\n\treturn (\n\t\t<EditorComponentsContext.Provider value={value}>{children}</EditorComponentsContext.Provider>\n\t)\n}\n"],
5
- "mappings": "AAiDE;AAjDF,SAAoB,eAAe;AACnC,SAAS,yBAAyB;AAClC,SAAS,qBAAqB;AAC9B,SAAS,4BAA4B;AACrC,SAAS,mBAAmB;AAC5B,SAAS,4BAA4B;AACrC,SAAS,iCAAiC;AAC1C,SAAS,2BAA2B;AACpC,SAAS,sBAAsB;AAC/B,SAAS,sBAAsB;AAC/B,SAAS,+BAA+B;AAExC,SAAS,gCAAgC;AAEzC,SAAS,2BAA2B;AAQ7B,SAAS,yBAAyB;AAAA,EACxC,YAAY,CAAC;AAAA,EACb;AACD,GAAmC;AAClC,QAAM,aAAa,yBAAyB,SAAS;AACrD,QAAM,QAAQ;AAAA,IACb,OAAqC;AAAA,MACpC,YAAY;AAAA,MACZ,QAAQ;AAAA,MACR,MAAM;AAAA,MACN,oBAAoB;AAAA,MACpB,eAAe;AAAA,MACf,aAAa;AAAA,MACb,qBAAqB;AAAA,MACrB,cAAc;AAAA,MACd,SAAS;AAAA,MACT,SAAS;AAAA,MAET,eAAe;AAAA,MACf,oBAAoB;AAAA,MAEpB,GAAG;AAAA,IACJ;AAAA,IACA,CAAC,UAAU;AAAA,EACZ;AAEA,SACC,oBAAC,wBAAwB,UAAxB,EAAiC,OAAe,UAAS;AAE5D;",
4
+ "sourcesContent": ["import { ReactNode, useMemo } from 'react'\nimport { DefaultBackground } from '../components/default-components/DefaultBackground'\nimport { DefaultCanvas } from '../components/default-components/DefaultCanvas'\nimport { DefaultErrorFallback } from '../components/default-components/DefaultErrorFallback'\nimport { DefaultGrid } from '../components/default-components/DefaultGrid'\nimport { DefaultLoadingScreen } from '../components/default-components/DefaultLoadingScreen'\nimport { DefaultShapeErrorFallback } from '../components/default-components/DefaultShapeErrorFallback'\nimport { DefaultShapeWrapper } from '../components/default-components/DefaultShapeWrapper'\nimport { DefaultSpinner } from '../components/default-components/DefaultSpinner'\nimport { DefaultSvgDefs } from '../components/default-components/DefaultSvgDefs'\nimport { EditorComponentsContext } from './EditorComponentsContext'\nimport type { TLEditorComponents } from './EditorComponentsContext'\nimport { useShallowObjectIdentity } from './useIdentity'\n\nexport { useEditorComponents } from './EditorComponentsContext'\nexport type { TLEditorComponents } from './EditorComponentsContext'\n\ninterface ComponentsContextProviderProps {\n\toverrides?: TLEditorComponents\n\tchildren: ReactNode\n}\n\nexport function EditorComponentsProvider({\n\toverrides = {},\n\tchildren,\n}: ComponentsContextProviderProps) {\n\tconst _overrides = useShallowObjectIdentity(overrides)\n\tconst value = useMemo(\n\t\t(): Required<TLEditorComponents> => ({\n\t\t\tBackground: DefaultBackground,\n\t\t\tCanvas: DefaultCanvas,\n\t\t\tGrid: DefaultGrid,\n\t\t\tInFrontOfTheCanvas: null,\n\t\t\tLoadingScreen: DefaultLoadingScreen,\n\t\t\tOnTheCanvas: null,\n\t\t\tShapeWrapper: DefaultShapeWrapper,\n\t\t\tSpinner: DefaultSpinner,\n\t\t\tSvgDefs: DefaultSvgDefs,\n\n\t\t\tErrorFallback: DefaultErrorFallback,\n\t\t\tShapeErrorFallback: DefaultShapeErrorFallback,\n\n\t\t\t..._overrides,\n\t\t}),\n\t\t[_overrides]\n\t)\n\n\treturn (\n\t\t<EditorComponentsContext.Provider value={value}>{children}</EditorComponentsContext.Provider>\n\t)\n}\n"],
5
+ "mappings": "AAgDE;AAhDF,SAAoB,eAAe;AACnC,SAAS,yBAAyB;AAClC,SAAS,qBAAqB;AAC9B,SAAS,4BAA4B;AACrC,SAAS,mBAAmB;AAC5B,SAAS,4BAA4B;AACrC,SAAS,iCAAiC;AAC1C,SAAS,2BAA2B;AACpC,SAAS,sBAAsB;AAC/B,SAAS,sBAAsB;AAC/B,SAAS,+BAA+B;AAExC,SAAS,gCAAgC;AAEzC,SAAS,2BAA2B;AAQ7B,SAAS,yBAAyB;AAAA,EACxC,YAAY,CAAC;AAAA,EACb;AACD,GAAmC;AAClC,QAAM,aAAa,yBAAyB,SAAS;AACrD,QAAM,QAAQ;AAAA,IACb,OAAqC;AAAA,MACpC,YAAY;AAAA,MACZ,QAAQ;AAAA,MACR,MAAM;AAAA,MACN,oBAAoB;AAAA,MACpB,eAAe;AAAA,MACf,aAAa;AAAA,MACb,cAAc;AAAA,MACd,SAAS;AAAA,MACT,SAAS;AAAA,MAET,eAAe;AAAA,MACf,oBAAoB;AAAA,MAEpB,GAAG;AAAA,IACJ;AAAA,IACA,CAAC,UAAU;AAAA,EACZ;AAEA,SACC,oBAAC,wBAAwB,UAAxB,EAAiC,OAAe,UAAS;AAE5D;",
6
6
  "names": []
7
7
  }
@@ -1,4 +1,5 @@
1
1
  import { isAccelKey } from "./keyboard.mjs";
2
+ import { getPointerEventButton } from "./pointer.mjs";
2
3
  function getPointerInfo(editor, e) {
3
4
  editor.markEventAsHandled(e);
4
5
  return {
@@ -13,7 +14,7 @@ function getPointerInfo(editor, e) {
13
14
  metaKey: e.metaKey,
14
15
  accelKey: isAccelKey(e),
15
16
  pointerId: e.pointerId,
16
- button: e.button,
17
+ button: getPointerEventButton(e),
17
18
  isPen: e.pointerType === "pen"
18
19
  };
19
20
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/lib/utils/getPointerInfo.ts"],
4
- "sourcesContent": ["import type React from 'react'\nimport { Editor } from '../editor/Editor'\nimport { isAccelKey } from './keyboard'\n\n/** @public */\nexport function getPointerInfo(editor: Editor, e: React.PointerEvent | PointerEvent) {\n\teditor.markEventAsHandled(e)\n\n\treturn {\n\t\tpoint: {\n\t\t\tx: e.clientX,\n\t\t\ty: e.clientY,\n\t\t\tz: e.pressure,\n\t\t},\n\t\tshiftKey: e.shiftKey,\n\t\taltKey: e.altKey,\n\t\tctrlKey: e.metaKey || e.ctrlKey,\n\t\tmetaKey: e.metaKey,\n\t\taccelKey: isAccelKey(e),\n\t\tpointerId: e.pointerId,\n\t\tbutton: e.button,\n\t\tisPen: e.pointerType === 'pen',\n\t}\n}\n"],
5
- "mappings": "AAEA,SAAS,kBAAkB;AAGpB,SAAS,eAAe,QAAgB,GAAsC;AACpF,SAAO,mBAAmB,CAAC;AAE3B,SAAO;AAAA,IACN,OAAO;AAAA,MACN,GAAG,EAAE;AAAA,MACL,GAAG,EAAE;AAAA,MACL,GAAG,EAAE;AAAA,IACN;AAAA,IACA,UAAU,EAAE;AAAA,IACZ,QAAQ,EAAE;AAAA,IACV,SAAS,EAAE,WAAW,EAAE;AAAA,IACxB,SAAS,EAAE;AAAA,IACX,UAAU,WAAW,CAAC;AAAA,IACtB,WAAW,EAAE;AAAA,IACb,QAAQ,EAAE;AAAA,IACV,OAAO,EAAE,gBAAgB;AAAA,EAC1B;AACD;",
4
+ "sourcesContent": ["import type React from 'react'\nimport { Editor } from '../editor/Editor'\nimport { isAccelKey } from './keyboard'\nimport { getPointerEventButton } from './pointer'\n\n/** @public */\nexport function getPointerInfo(editor: Editor, e: React.PointerEvent | PointerEvent) {\n\teditor.markEventAsHandled(e)\n\n\treturn {\n\t\tpoint: {\n\t\t\tx: e.clientX,\n\t\t\ty: e.clientY,\n\t\t\tz: e.pressure,\n\t\t},\n\t\tshiftKey: e.shiftKey,\n\t\taltKey: e.altKey,\n\t\tctrlKey: e.metaKey || e.ctrlKey,\n\t\tmetaKey: e.metaKey,\n\t\taccelKey: isAccelKey(e),\n\t\tpointerId: e.pointerId,\n\t\tbutton: getPointerEventButton(e),\n\t\tisPen: e.pointerType === 'pen',\n\t}\n}\n"],
5
+ "mappings": "AAEA,SAAS,kBAAkB;AAC3B,SAAS,6BAA6B;AAG/B,SAAS,eAAe,QAAgB,GAAsC;AACpF,SAAO,mBAAmB,CAAC;AAE3B,SAAO;AAAA,IACN,OAAO;AAAA,MACN,GAAG,EAAE;AAAA,MACL,GAAG,EAAE;AAAA,MACL,GAAG,EAAE;AAAA,IACN;AAAA,IACA,UAAU,EAAE;AAAA,IACZ,QAAQ,EAAE;AAAA,IACV,SAAS,EAAE,WAAW,EAAE;AAAA,IACxB,SAAS,EAAE;AAAA,IACX,UAAU,WAAW,CAAC;AAAA,IACtB,WAAW,EAAE;AAAA,IACb,QAAQ,sBAAsB,CAAC;AAAA,IAC/B,OAAO,EAAE,gBAAgB;AAAA,EAC1B;AACD;",
6
6
  "names": []
7
7
  }
@@ -0,0 +1,17 @@
1
+ import { tlenv } from "../globals/environment.mjs";
2
+ function isDirectDisplayPen(e) {
3
+ if (e.pointerType !== "pen") return false;
4
+ return tlenv.isTouchDevice;
5
+ }
6
+ function isSecondaryClickEvent(e) {
7
+ return e.button === 2 || tlenv.isDarwin && e.button === 0 && e.ctrlKey && !e.metaKey;
8
+ }
9
+ function getPointerEventButton(e) {
10
+ return isSecondaryClickEvent(e) ? 2 : e.button;
11
+ }
12
+ export {
13
+ getPointerEventButton,
14
+ isDirectDisplayPen,
15
+ isSecondaryClickEvent
16
+ };
17
+ //# sourceMappingURL=pointer.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/lib/utils/pointer.ts"],
4
+ "sourcesContent": ["import type React from 'react'\nimport { tlenv } from '../globals/environment'\n\n/**\n * Decide whether a pen pointer event looks like direct manipulation on the display (e.g. Apple\n * Pencil on an iPad or a Surface Pen on a touchscreen) rather than indirect input from a desktop\n * graphics tablet (e.g. a Wacom Intuos).\n *\n * We can't tell the two apart from the pointer event itself: both report `pointerType: 'pen'`, and\n * implicit pointer capture \u2014 which in theory distinguishes direct-manipulation pointers \u2014 isn't\n * reliably observable across browsers (notably WebKit/iPad). Instead we key off the device: a\n * direct-display pen draws on a touch-capable screen, while an indirect graphics tablet is used on\n * a non-touch desktop alongside a mouse. A device with no touch input therefore can't host a\n * direct-display pen.\n *\n * Note this uses {@link tlenv.isTouchDevice} \u2014 the device's fixed touch capability \u2014 not the\n * editor's dynamic `isCoarsePointer` state, which a pen `pointerdown` flips to coarse regardless\n * of device.\n *\n * @internal\n */\nexport function isDirectDisplayPen(e: React.PointerEvent | PointerEvent): boolean {\n\tif (e.pointerType !== 'pen') return false\n\treturn tlenv.isTouchDevice\n}\n\n/** @internal */\ninterface PointerLike {\n\tbutton: number\n\tctrlKey: boolean\n\tmetaKey: boolean\n}\n\n/** @internal */\nexport function isSecondaryClickEvent(e: PointerLike) {\n\treturn e.button === 2 || (tlenv.isDarwin && e.button === 0 && e.ctrlKey && !e.metaKey)\n}\n\n/** @internal */\nexport function getPointerEventButton(e: PointerLike) {\n\treturn isSecondaryClickEvent(e) ? 2 : e.button\n}\n"],
5
+ "mappings": "AACA,SAAS,aAAa;AAoBf,SAAS,mBAAmB,GAA+C;AACjF,MAAI,EAAE,gBAAgB,MAAO,QAAO;AACpC,SAAO,MAAM;AACd;AAUO,SAAS,sBAAsB,GAAgB;AACrD,SAAO,EAAE,WAAW,KAAM,MAAM,YAAY,EAAE,WAAW,KAAK,EAAE,WAAW,CAAC,EAAE;AAC/E;AAGO,SAAS,sBAAsB,GAAgB;AACrD,SAAO,sBAAsB,CAAC,IAAI,IAAI,EAAE;AACzC;",
6
+ "names": []
7
+ }
@@ -1,8 +1,8 @@
1
- const version = "5.2.0-canary.6421dbe4e25a";
1
+ const version = "5.2.0-canary.667cbd6bb6ff";
2
2
  const publishDates = {
3
3
  major: "2026-05-06T16:28:18.473Z",
4
- minor: "2026-06-16T10:18:19.799Z",
5
- patch: "2026-06-16T10:18:19.799Z"
4
+ minor: "2026-06-22T09:09:59.347Z",
5
+ patch: "2026-06-22T09:09:59.347Z"
6
6
  };
7
7
  export {
8
8
  publishDates,
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/version.ts"],
4
- "sourcesContent": ["// This file is automatically generated by internal/scripts/refresh-assets.ts.\n// Do not edit manually. Or do, I'm a comment, not a cop.\n\nexport const version = '5.2.0-canary.6421dbe4e25a'\nexport const publishDates = {\n\tmajor: '2026-05-06T16:28:18.473Z',\n\tminor: '2026-06-16T10:18:19.799Z',\n\tpatch: '2026-06-16T10:18:19.799Z',\n}\n"],
4
+ "sourcesContent": ["// This file is automatically generated by internal/scripts/refresh-assets.ts.\n// Do not edit manually. Or do, I'm a comment, not a cop.\n\nexport const version = '5.2.0-canary.667cbd6bb6ff'\nexport const publishDates = {\n\tmajor: '2026-05-06T16:28:18.473Z',\n\tminor: '2026-06-22T09:09:59.347Z',\n\tpatch: '2026-06-22T09:09:59.347Z',\n}\n"],
5
5
  "mappings": "AAGO,MAAM,UAAU;AAChB,MAAM,eAAe;AAAA,EAC3B,OAAO;AAAA,EACP,OAAO;AAAA,EACP,OAAO;AACR;",
6
6
  "names": []
7
7
  }
package/editor.css CHANGED
@@ -764,17 +764,17 @@ input,
764
764
  .tl-rich-text ol {
765
765
  text-align: left;
766
766
  margin: 0;
767
- padding-left: 3.25ch;
767
+ padding-left: 1.625ch;
768
768
  /* Some resets, like Tailwind, nix the list styling. */
769
769
  list-style: revert;
770
770
  }
771
771
 
772
772
  .tl-rich-text ol:has(> li:nth-child(10)) {
773
- padding-left: 4.25ch;
773
+ padding-left: 2.625ch;
774
774
  }
775
775
 
776
776
  .tl-rich-text ol:has(> li:nth-child(100)) {
777
- padding-left: 5.25ch;
777
+ padding-left: 3.625ch;
778
778
  }
779
779
 
780
780
  .tl-rich-text h1,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tldraw/editor",
3
3
  "description": "tldraw infinite canvas SDK (editor).",
4
- "version": "5.2.0-canary.6421dbe4e25a",
4
+ "version": "5.2.0-canary.667cbd6bb6ff",
5
5
  "author": {
6
6
  "name": "tldraw Inc.",
7
7
  "email": "hello@tldraw.com"
@@ -49,12 +49,12 @@
49
49
  "@tiptap/core": "^3.12.1",
50
50
  "@tiptap/pm": "^3.12.1",
51
51
  "@tiptap/react": "^3.12.1",
52
- "@tldraw/state": "5.2.0-canary.6421dbe4e25a",
53
- "@tldraw/state-react": "5.2.0-canary.6421dbe4e25a",
54
- "@tldraw/store": "5.2.0-canary.6421dbe4e25a",
55
- "@tldraw/tlschema": "5.2.0-canary.6421dbe4e25a",
56
- "@tldraw/utils": "5.2.0-canary.6421dbe4e25a",
57
- "@tldraw/validate": "5.2.0-canary.6421dbe4e25a",
52
+ "@tldraw/state": "5.2.0-canary.667cbd6bb6ff",
53
+ "@tldraw/state-react": "5.2.0-canary.667cbd6bb6ff",
54
+ "@tldraw/store": "5.2.0-canary.667cbd6bb6ff",
55
+ "@tldraw/tlschema": "5.2.0-canary.667cbd6bb6ff",
56
+ "@tldraw/utils": "5.2.0-canary.667cbd6bb6ff",
57
+ "@tldraw/validate": "5.2.0-canary.667cbd6bb6ff",
58
58
  "classnames": "^2.5.1",
59
59
  "eventemitter3": "^4.0.7",
60
60
  "idb": "^7.1.1",
@@ -82,6 +82,9 @@
82
82
  "resize-observer-polyfill": "^1.5.1",
83
83
  "vitest": "^4.1.7"
84
84
  },
85
+ "engines": {
86
+ "node": ">=22.12.0"
87
+ },
85
88
  "module": "dist-esm/index.mjs",
86
89
  "source": "src/index.ts",
87
90
  "exports": {
package/src/index.ts CHANGED
@@ -23,10 +23,6 @@ export {
23
23
  type TLErrorFallbackComponent,
24
24
  } from './lib/components/default-components/DefaultErrorFallback'
25
25
  export { DefaultGrid, type TLGridProps } from './lib/components/default-components/DefaultGrid'
26
- export {
27
- DefaultSelectionBackground,
28
- type TLSelectionBackgroundProps,
29
- } from './lib/components/default-components/DefaultSelectionBackground'
30
26
  export { type TLShapeErrorFallbackComponent } from './lib/components/default-components/DefaultShapeErrorFallback'
31
27
  export {
32
28
  DefaultShapeWrapper,
@@ -322,7 +318,6 @@ export {
322
318
  type SafeId,
323
319
  } from './lib/hooks/useSafeId'
324
320
  export { useTLSchemaFromUtils, useTLStore } from './lib/hooks/useTLStore'
325
- export { useTransform } from './lib/hooks/useTransform'
326
321
  export { useViewportHeight } from './lib/hooks/useViewportHeight'
327
322
  export {
328
323
  LicenseManager,
@@ -6,6 +6,7 @@ import { useEditor } from '../hooks/useEditor'
6
6
  import { Vec } from '../primitives/Vec'
7
7
  import { releasePointerCapture, setPointerCapture } from '../utils/dom'
8
8
  import { getPointerInfo } from '../utils/getPointerInfo'
9
+ import { getPointerEventButton } from '../utils/pointer'
9
10
 
10
11
  /**
11
12
  * When a menu is open, this component prevents the user from interacting with the canvas.
@@ -68,18 +69,19 @@ export function MenuClickCapture() {
68
69
 
69
70
  const handlePointerDown = useCallback(
70
71
  (e: PointerEvent) => {
71
- if (e.button !== 0 && e.button !== 2) return
72
+ const button = getPointerEventButton(e)
73
+ if (button !== 0 && button !== 2) return
72
74
 
73
75
  flushSync(() => setIsPointing(true))
74
76
  setPointerCapture(e.currentTarget, e)
75
77
  rPointerState.current = {
76
78
  isDown: true,
77
79
  isDragging: false,
78
- button: e.button,
80
+ button,
79
81
  start: new Vec(e.clientX, e.clientY),
80
82
  }
81
83
 
82
- if (e.button === 2) {
84
+ if (button === 2) {
83
85
  if (!editor.options.rightClickPanning) {
84
86
  // Right-click panning off: close the open menu and swallow the native
85
87
  // contextmenu that would otherwise briefly open a new one (causing a flash).
@@ -141,13 +143,15 @@ export function MenuClickCapture() {
141
143
 
142
144
  const handlePointerUp = useCallback(
143
145
  (e: PointerEvent) => {
144
- const isStaticRightClick = e.button === 2 && !rPointerState.current.isDragging
146
+ const isStaticRightClick =
147
+ rPointerState.current.button === 2 && !rPointerState.current.isDragging
145
148
 
146
149
  editor.dispatch({
147
150
  type: 'pointer',
148
151
  target: 'canvas',
149
152
  name: 'pointer_up',
150
153
  ...getPointerInfo(editor, e),
154
+ button: rPointerState.current.button === 2 ? 2 : getPointerEventButton(e),
151
155
  })
152
156
 
153
157
  if (isStaticRightClick && editor.options.rightClickPanning) {
@@ -32,7 +32,7 @@ export interface TLCanvasComponentProps {
32
32
  export function DefaultCanvas({ className }: TLCanvasComponentProps) {
33
33
  const editor = useEditor()
34
34
 
35
- const { SelectionBackground, Background, SvgDefs } = useEditorComponents()
35
+ const { Background, SvgDefs } = useEditorComponents()
36
36
 
37
37
  const rCanvas = useRef<HTMLDivElement>(null)
38
38
  const rHtmlLayer = useRef<HTMLDivElement>(null)
@@ -160,7 +160,6 @@ export function DefaultCanvas({ className }: TLCanvasComponentProps) {
160
160
  {isGridMode && Grid && <GridWrapper />}
161
161
  <div ref={rHtmlLayer} className="tl-html-layer tl-shapes" draggable={false}>
162
162
  <OnTheCanvasWrapper />
163
- {SelectionBackground && <SelectionBackgroundWrapper />}
164
163
  {hideShapes ? null : <ShapesLayer canvasRef={rCanvas} />}
165
164
  </div>
166
165
  <CanvasOverlays />
@@ -345,21 +344,6 @@ function DebugSvgCopy({ id, mode }: { id: TLShapeId; mode: 'img' | 'iframe' }) {
345
344
  )
346
345
  }
347
346
 
348
- function SelectionBackgroundWrapper() {
349
- const editor = useEditor()
350
- const selectionRotation = useValue('selection rotation', () => editor.getSelectionRotation(), [
351
- editor,
352
- ])
353
- const selectionBounds = useValue(
354
- 'selection bounds',
355
- () => editor.getSelectionRotatedPageBounds(),
356
- [editor]
357
- )
358
- const { SelectionBackground } = useEditorComponents()
359
- if (!selectionBounds || !SelectionBackground) return null
360
- return <SelectionBackground bounds={selectionBounds} rotation={selectionRotation} />
361
- }
362
-
363
347
  function OnTheCanvasWrapper() {
364
348
  const { OnTheCanvas } = useEditorComponents()
365
349
  if (!OnTheCanvas) return null
@@ -409,9 +409,6 @@ export class Editor extends EventEmitter<TLEventMap> {
409
409
  this._tickManager = new TickManager(this)
410
410
  this.disposables.add(() => this._tickManager.dispose())
411
411
  this.disposables.add(() => {
412
- // Reset camera state to 'idle' so the store isn't left stuck at 'moving'
413
- // when tick events stop (e.g. React strict mode disposes while camera is moving)
414
- this.off('tick', this._decayCameraStateTimeout)
415
412
  this._setCameraState('idle')
416
413
  })
417
414
 
@@ -419,6 +416,7 @@ export class Editor extends EventEmitter<TLEventMap> {
419
416
  this.disposables.add(() => this.fonts.dispose())
420
417
 
421
418
  this.inputs = new InputsManager(this)
419
+ this.disposables.add(() => this.inputs.dispose())
422
420
  this.performance = new PerformanceManager(this)
423
421
  this.disposables.add(() => this.performance.dispose())
424
422
  this.collaborators = new CollaboratorsManager(this)
@@ -1179,6 +1177,7 @@ export class Editor extends EventEmitter<TLEventMap> {
1179
1177
  this.store.dispose()
1180
1178
  this.isDisposed = true
1181
1179
  this.emit('dispose')
1180
+ this.removeAllListeners()
1182
1181
  }
1183
1182
 
1184
1183
  /* ------------------ Themes (shadowing the theme manager) ------------------ */
@@ -1551,6 +1550,15 @@ export class Editor extends EventEmitter<TLEventMap> {
1551
1550
  return this.history.getMarkIdMatching(idSubstring)
1552
1551
  }
1553
1552
 
1553
+ /**
1554
+ * Whether the editor is currently replaying history (i.e. an undo or redo is being applied).
1555
+ *
1556
+ * @internal
1557
+ */
1558
+ isReplayingHistory(): boolean {
1559
+ return this.history.isReplaying()
1560
+ }
1561
+
1554
1562
  /**
1555
1563
  * Coalesces all changes since the given mark into a single change, removing any intermediate marks.
1556
1564
  *
@@ -11215,8 +11223,10 @@ export class Editor extends EventEmitter<TLEventMap> {
11215
11223
  inputs.setIsPointing(true)
11216
11224
  inputs.setIsDragging(false)
11217
11225
 
11218
- // If pen mode is off but we're not already in pen mode, turn that on
11219
- if (!isPenMode && isPen) {
11226
+ // If pen mode is off, turn it on for direct-display pen input only (e.g. Apple
11227
+ // Pencil on an iPad or a Surface Pen on a touchscreen). Indirect desktop tablet
11228
+ // styluses still draw as pens, but should not auto-enable pen mode.
11229
+ if (!isPenMode && info.isPenDirect) {
11220
11230
  this.updateInstanceState({ isPenMode: true })
11221
11231
  // Once pen mode is on, touch input is ignored, so we discard the
11222
11232
  // in-progress touch interaction .
@@ -9,7 +9,7 @@ import {
9
9
  import { IndexKey } from '@tldraw/utils'
10
10
  import { Mock, Mocked, vi } from 'vitest'
11
11
  import { Editor } from '../../Editor'
12
- import { FontManager } from './FontManager'
12
+ import { clearFontFaceCacheForTests, FontManager } from './FontManager'
13
13
 
14
14
  // Mock the Editor class
15
15
  vi.mock('../../Editor')
@@ -73,6 +73,7 @@ describe('FontManager', () => {
73
73
 
74
74
  beforeEach(() => {
75
75
  vi.clearAllMocks()
76
+ clearFontFaceCacheForTests()
76
77
 
77
78
  mockAssetUrls = {
78
79
  'test-font.woff2': 'https://example.com/fonts/test-font.woff2',
@@ -314,4 +315,26 @@ describe('FontManager', () => {
314
315
  await expect(fontManager.ensureFontIsLoaded(minimalFont)).resolves.toBeUndefined()
315
316
  })
316
317
  })
318
+
319
+ describe('findOrCreateFontFace caching', () => {
320
+ it('reuses a font face across manager instances instead of recreating it on remount', async () => {
321
+ const font = createMockFont()
322
+ await fontManager.ensureFontIsLoaded(font)
323
+ expect(global.FontFace).toHaveBeenCalledTimes(1)
324
+
325
+ // A fresh manager on the same document simulates an editor remount.
326
+ const remounted = new FontManager(editor, mockAssetUrls)
327
+ await remounted.ensureFontIsLoaded(font)
328
+
329
+ // The per-document cache lets the second manager reuse the existing face
330
+ // rather than re-scanning document.fonts and creating a new one.
331
+ expect(global.FontFace).toHaveBeenCalledTimes(1)
332
+ })
333
+
334
+ it('creates separate font faces for fonts with different descriptors', async () => {
335
+ await fontManager.ensureFontIsLoaded(createMockFont({ weight: 'normal' }))
336
+ await fontManager.ensureFontIsLoaded(createMockFont({ weight: 'bold' }))
337
+ expect(global.FontFace).toHaveBeenCalledTimes(2)
338
+ })
339
+ })
317
340
  })
@@ -145,7 +145,26 @@ export class FontManager {
145
145
  }
146
146
 
147
147
  private findOrCreateFontFace(font: TLFontFace) {
148
- const fonts = this.editor.getContainerDocument().fonts
148
+ const containerDocument = this.editor.getContainerDocument()
149
+
150
+ // `findOrCreateFontFace` runs for every font on every editor mount, and a fresh
151
+ // editor (e.g. switching documents) gets a fresh FontManager with no memory of the
152
+ // previous one. The dedup below is an O(n) scan of the document's whole FontFaceSet,
153
+ // so without a cache that scan re-ran on every mount (measurably expensive on mobile
154
+ // Safari). Cache the resolved FontFace per document so repeated lookups - and
155
+ // remounts - are O(1). Keyed per document for cross-window embedding.
156
+ let cache = fontFaceCacheByDocument.get(containerDocument)
157
+ if (!cache) {
158
+ cache = new Map()
159
+ fontFaceCacheByDocument.set(containerDocument, cache)
160
+ }
161
+ const key = getFontFaceCacheKey(font)
162
+ const cached = cache.get(key)
163
+ if (cached) return cached
164
+
165
+ const fonts = containerDocument.fonts
166
+ // On a cache miss we still scan once, so font faces added outside this manager
167
+ // (e.g. preloaded fonts) are reused rather than duplicated.
149
168
  for (const existing of fonts) {
150
169
  if (
151
170
  existing.family === font.family &&
@@ -153,6 +172,7 @@ export class FontManager {
153
172
  ([key, defaultValue]) => existing[key] === (font[key] ?? defaultValue)
154
173
  )
155
174
  ) {
175
+ cache.set(key, existing)
156
176
  return existing
157
177
  }
158
178
  }
@@ -164,6 +184,7 @@ export class FontManager {
164
184
  })
165
185
 
166
186
  fonts.add(instance)
187
+ cache.set(key, instance)
167
188
 
168
189
  return instance
169
190
  }
@@ -205,3 +226,27 @@ const defaultFontFaceDescriptors = {
205
226
  descentOverride: 'normal',
206
227
  lineGapOverride: 'normal',
207
228
  }
229
+
230
+ // A FontFace is fully determined by its family and descriptors, so resolved faces can be
231
+ // cached per document and reused across FontManager instances (e.g. editor remounts),
232
+ // turning the per-lookup FontFaceSet scan into an O(1) map lookup. Faces are never removed
233
+ // from `document.fonts` (FontManager.dispose leaves them), so the cache stays valid for the
234
+ // document's lifetime. Keyed per document for cross-window embedding.
235
+ let fontFaceCacheByDocument = new WeakMap<Document, Map<string, FontFace>>()
236
+
237
+ function getFontFaceCacheKey(font: TLFontFace): string {
238
+ return JSON.stringify([
239
+ font.family,
240
+ ...objectMapEntries(defaultFontFaceDescriptors).map(
241
+ ([key, defaultValue]) => font[key] ?? defaultValue
242
+ ),
243
+ ])
244
+ }
245
+
246
+ /**
247
+ * Resets the per-document font-face cache. Only intended for tests.
248
+ * @internal
249
+ */
250
+ export function clearFontFaceCacheForTests() {
251
+ fontFaceCacheByDocument = new WeakMap()
252
+ }
@@ -584,6 +584,38 @@ describe('HistoryManager getters and utilities', () => {
584
584
  store.update(ids.a, (s) => ({ ...s, value: 2 }))
585
585
  expect(manager.getNumRedos()).toBe(0)
586
586
  })
587
+
588
+ it('should only report replaying while undoing or redoing', () => {
589
+ const replayStates: boolean[] = []
590
+ const dispose = store.addHistoryInterceptor(() => {
591
+ replayStates.push(manager.isReplaying())
592
+ })
593
+
594
+ store.update(ids.a, (s) => ({ ...s, value: 1 }))
595
+ expect(replayStates).toEqual([false])
596
+
597
+ replayStates.length = 0
598
+ manager.undo()
599
+ expect(replayStates).toEqual([true])
600
+ expect(manager.isReplaying()).toBe(false)
601
+
602
+ replayStates.length = 0
603
+ manager.redo()
604
+ expect(replayStates).toEqual([true])
605
+ expect(manager.isReplaying()).toBe(false)
606
+
607
+ replayStates.length = 0
608
+ manager.batch(
609
+ () => {
610
+ store.update(ids.a, (s) => ({ ...s, value: 2 }))
611
+ },
612
+ { history: 'ignore' }
613
+ )
614
+ expect(replayStates).toEqual([false])
615
+ expect(manager.isReplaying()).toBe(false)
616
+
617
+ dispose()
618
+ })
587
619
  })
588
620
 
589
621
  describe('getMarkIdMatching', () => {