@tldraw/editor 3.16.0-next.f9f54ec051f3 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (221) hide show
  1. package/dist-cjs/index.d.ts +197 -114
  2. package/dist-cjs/index.js +5 -5
  3. package/dist-cjs/index.js.map +2 -2
  4. package/dist-cjs/lib/TldrawEditor.js +9 -9
  5. package/dist-cjs/lib/TldrawEditor.js.map +2 -2
  6. package/dist-cjs/lib/components/MenuClickCapture.js +0 -5
  7. package/dist-cjs/lib/components/MenuClickCapture.js.map +2 -2
  8. package/dist-cjs/lib/components/Shape.js +7 -10
  9. package/dist-cjs/lib/components/Shape.js.map +2 -2
  10. package/dist-cjs/lib/components/default-components/DefaultCanvas.js +14 -23
  11. package/dist-cjs/lib/components/default-components/DefaultCanvas.js.map +2 -2
  12. package/dist-cjs/lib/components/default-components/DefaultCollaboratorHint.js +1 -1
  13. package/dist-cjs/lib/components/default-components/DefaultCollaboratorHint.js.map +1 -1
  14. package/dist-cjs/lib/components/default-components/DefaultErrorFallback.js +1 -1
  15. package/dist-cjs/lib/components/default-components/DefaultErrorFallback.js.map +2 -2
  16. package/dist-cjs/lib/components/default-components/DefaultScribble.js +1 -1
  17. package/dist-cjs/lib/components/default-components/DefaultScribble.js.map +2 -2
  18. package/dist-cjs/lib/components/default-components/DefaultShapeIndicator.js +9 -1
  19. package/dist-cjs/lib/components/default-components/DefaultShapeIndicator.js.map +2 -2
  20. package/dist-cjs/lib/config/TLUserPreferences.js +21 -4
  21. package/dist-cjs/lib/config/TLUserPreferences.js.map +2 -2
  22. package/dist-cjs/lib/editor/Editor.js +121 -138
  23. package/dist-cjs/lib/editor/Editor.js.map +2 -2
  24. package/dist-cjs/lib/editor/derivations/notVisibleShapes.js +4 -0
  25. package/dist-cjs/lib/editor/derivations/notVisibleShapes.js.map +2 -2
  26. package/dist-cjs/lib/editor/managers/FocusManager/FocusManager.js +4 -2
  27. package/dist-cjs/lib/editor/managers/FocusManager/FocusManager.js.map +2 -2
  28. package/dist-cjs/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.js +14 -4
  29. package/dist-cjs/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.js.map +2 -2
  30. package/dist-cjs/lib/editor/shapes/ShapeUtil.js +23 -0
  31. package/dist-cjs/lib/editor/shapes/ShapeUtil.js.map +2 -2
  32. package/dist-cjs/lib/editor/types/misc-types.js.map +1 -1
  33. package/dist-cjs/lib/exports/getSvgJsx.js +35 -16
  34. package/dist-cjs/lib/exports/getSvgJsx.js.map +2 -2
  35. package/dist-cjs/lib/hooks/useCanvasEvents.js +47 -38
  36. package/dist-cjs/lib/hooks/useCanvasEvents.js.map +2 -2
  37. package/dist-cjs/lib/hooks/useDocumentEvents.js +5 -5
  38. package/dist-cjs/lib/hooks/useDocumentEvents.js.map +2 -2
  39. package/dist-cjs/lib/hooks/useFixSafariDoubleTapZoomPencilEvents.js +1 -2
  40. package/dist-cjs/lib/hooks/useFixSafariDoubleTapZoomPencilEvents.js.map +2 -2
  41. package/dist-cjs/lib/hooks/useGestureEvents.js +1 -1
  42. package/dist-cjs/lib/hooks/useGestureEvents.js.map +2 -2
  43. package/dist-cjs/lib/hooks/useHandleEvents.js +6 -6
  44. package/dist-cjs/lib/hooks/useHandleEvents.js.map +2 -2
  45. package/dist-cjs/lib/hooks/usePassThroughMouseOverEvents.js +4 -1
  46. package/dist-cjs/lib/hooks/usePassThroughMouseOverEvents.js.map +2 -2
  47. package/dist-cjs/lib/hooks/usePassThroughWheelEvents.js +4 -1
  48. package/dist-cjs/lib/hooks/usePassThroughWheelEvents.js.map +2 -2
  49. package/dist-cjs/lib/hooks/useSelectionEvents.js +8 -8
  50. package/dist-cjs/lib/hooks/useSelectionEvents.js.map +2 -2
  51. package/dist-cjs/lib/{utils/nearestMultiple.js → hooks/useStateAttribute.js} +15 -14
  52. package/dist-cjs/lib/hooks/useStateAttribute.js.map +7 -0
  53. package/dist-cjs/lib/license/LicenseManager.js +143 -53
  54. package/dist-cjs/lib/license/LicenseManager.js.map +2 -2
  55. package/dist-cjs/lib/license/LicenseProvider.js +39 -1
  56. package/dist-cjs/lib/license/LicenseProvider.js.map +2 -2
  57. package/dist-cjs/lib/license/Watermark.js +144 -75
  58. package/dist-cjs/lib/license/Watermark.js.map +3 -3
  59. package/dist-cjs/lib/license/useLicenseManagerState.js.map +2 -2
  60. package/dist-cjs/lib/options.js +7 -0
  61. package/dist-cjs/lib/options.js.map +2 -2
  62. package/dist-cjs/lib/primitives/Box.js +3 -0
  63. package/dist-cjs/lib/primitives/Box.js.map +2 -2
  64. package/dist-cjs/lib/primitives/Vec.js +0 -4
  65. package/dist-cjs/lib/primitives/Vec.js.map +2 -2
  66. package/dist-cjs/lib/primitives/geometry/Geometry2d.js +50 -20
  67. package/dist-cjs/lib/primitives/geometry/Geometry2d.js.map +2 -2
  68. package/dist-cjs/lib/primitives/geometry/Group2d.js +8 -1
  69. package/dist-cjs/lib/primitives/geometry/Group2d.js.map +2 -2
  70. package/dist-cjs/lib/utils/EditorAtom.js +45 -0
  71. package/dist-cjs/lib/utils/EditorAtom.js.map +7 -0
  72. package/dist-cjs/lib/utils/dom.js.map +2 -2
  73. package/dist-cjs/lib/utils/getPointerInfo.js +2 -3
  74. package/dist-cjs/lib/utils/getPointerInfo.js.map +2 -2
  75. package/dist-cjs/lib/utils/reparenting.js +7 -36
  76. package/dist-cjs/lib/utils/reparenting.js.map +3 -3
  77. package/dist-cjs/version.js +4 -4
  78. package/dist-cjs/version.js.map +1 -1
  79. package/dist-esm/index.d.mts +197 -114
  80. package/dist-esm/index.mjs +5 -5
  81. package/dist-esm/index.mjs.map +2 -2
  82. package/dist-esm/lib/TldrawEditor.mjs +9 -9
  83. package/dist-esm/lib/TldrawEditor.mjs.map +2 -2
  84. package/dist-esm/lib/components/MenuClickCapture.mjs +0 -5
  85. package/dist-esm/lib/components/MenuClickCapture.mjs.map +2 -2
  86. package/dist-esm/lib/components/Shape.mjs +7 -10
  87. package/dist-esm/lib/components/Shape.mjs.map +2 -2
  88. package/dist-esm/lib/components/default-components/DefaultCanvas.mjs +14 -23
  89. package/dist-esm/lib/components/default-components/DefaultCanvas.mjs.map +2 -2
  90. package/dist-esm/lib/components/default-components/DefaultCollaboratorHint.mjs +1 -1
  91. package/dist-esm/lib/components/default-components/DefaultCollaboratorHint.mjs.map +1 -1
  92. package/dist-esm/lib/components/default-components/DefaultErrorFallback.mjs +1 -1
  93. package/dist-esm/lib/components/default-components/DefaultErrorFallback.mjs.map +2 -2
  94. package/dist-esm/lib/components/default-components/DefaultScribble.mjs +1 -1
  95. package/dist-esm/lib/components/default-components/DefaultScribble.mjs.map +2 -2
  96. package/dist-esm/lib/components/default-components/DefaultShapeIndicator.mjs +9 -1
  97. package/dist-esm/lib/components/default-components/DefaultShapeIndicator.mjs.map +2 -2
  98. package/dist-esm/lib/config/TLUserPreferences.mjs +21 -4
  99. package/dist-esm/lib/config/TLUserPreferences.mjs.map +2 -2
  100. package/dist-esm/lib/editor/Editor.mjs +121 -138
  101. package/dist-esm/lib/editor/Editor.mjs.map +2 -2
  102. package/dist-esm/lib/editor/derivations/notVisibleShapes.mjs +4 -0
  103. package/dist-esm/lib/editor/derivations/notVisibleShapes.mjs.map +2 -2
  104. package/dist-esm/lib/editor/managers/FocusManager/FocusManager.mjs +4 -2
  105. package/dist-esm/lib/editor/managers/FocusManager/FocusManager.mjs.map +2 -2
  106. package/dist-esm/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.mjs +14 -4
  107. package/dist-esm/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.mjs.map +2 -2
  108. package/dist-esm/lib/editor/shapes/ShapeUtil.mjs +23 -0
  109. package/dist-esm/lib/editor/shapes/ShapeUtil.mjs.map +2 -2
  110. package/dist-esm/lib/exports/getSvgJsx.mjs +36 -16
  111. package/dist-esm/lib/exports/getSvgJsx.mjs.map +2 -2
  112. package/dist-esm/lib/hooks/useCanvasEvents.mjs +49 -45
  113. package/dist-esm/lib/hooks/useCanvasEvents.mjs.map +2 -2
  114. package/dist-esm/lib/hooks/useDocumentEvents.mjs +6 -6
  115. package/dist-esm/lib/hooks/useDocumentEvents.mjs.map +2 -2
  116. package/dist-esm/lib/hooks/useFixSafariDoubleTapZoomPencilEvents.mjs +1 -2
  117. package/dist-esm/lib/hooks/useFixSafariDoubleTapZoomPencilEvents.mjs.map +2 -2
  118. package/dist-esm/lib/hooks/useGestureEvents.mjs +2 -2
  119. package/dist-esm/lib/hooks/useGestureEvents.mjs.map +2 -2
  120. package/dist-esm/lib/hooks/useHandleEvents.mjs +6 -6
  121. package/dist-esm/lib/hooks/useHandleEvents.mjs.map +2 -2
  122. package/dist-esm/lib/hooks/usePassThroughMouseOverEvents.mjs +4 -1
  123. package/dist-esm/lib/hooks/usePassThroughMouseOverEvents.mjs.map +2 -2
  124. package/dist-esm/lib/hooks/usePassThroughWheelEvents.mjs +4 -1
  125. package/dist-esm/lib/hooks/usePassThroughWheelEvents.mjs.map +2 -2
  126. package/dist-esm/lib/hooks/useSelectionEvents.mjs +9 -14
  127. package/dist-esm/lib/hooks/useSelectionEvents.mjs.map +2 -2
  128. package/dist-esm/lib/hooks/useStateAttribute.mjs +15 -0
  129. package/dist-esm/lib/hooks/useStateAttribute.mjs.map +7 -0
  130. package/dist-esm/lib/license/LicenseManager.mjs +144 -54
  131. package/dist-esm/lib/license/LicenseManager.mjs.map +2 -2
  132. package/dist-esm/lib/license/LicenseProvider.mjs +39 -2
  133. package/dist-esm/lib/license/LicenseProvider.mjs.map +2 -2
  134. package/dist-esm/lib/license/Watermark.mjs +145 -76
  135. package/dist-esm/lib/license/Watermark.mjs.map +3 -3
  136. package/dist-esm/lib/license/useLicenseManagerState.mjs.map +2 -2
  137. package/dist-esm/lib/options.mjs +7 -0
  138. package/dist-esm/lib/options.mjs.map +2 -2
  139. package/dist-esm/lib/primitives/Box.mjs +4 -1
  140. package/dist-esm/lib/primitives/Box.mjs.map +2 -2
  141. package/dist-esm/lib/primitives/Vec.mjs +0 -4
  142. package/dist-esm/lib/primitives/Vec.mjs.map +2 -2
  143. package/dist-esm/lib/primitives/geometry/Geometry2d.mjs +53 -21
  144. package/dist-esm/lib/primitives/geometry/Geometry2d.mjs.map +2 -2
  145. package/dist-esm/lib/primitives/geometry/Group2d.mjs +8 -1
  146. package/dist-esm/lib/primitives/geometry/Group2d.mjs.map +2 -2
  147. package/dist-esm/lib/utils/EditorAtom.mjs +25 -0
  148. package/dist-esm/lib/utils/EditorAtom.mjs.map +7 -0
  149. package/dist-esm/lib/utils/dom.mjs.map +2 -2
  150. package/dist-esm/lib/utils/getPointerInfo.mjs +2 -3
  151. package/dist-esm/lib/utils/getPointerInfo.mjs.map +2 -2
  152. package/dist-esm/lib/utils/reparenting.mjs +8 -41
  153. package/dist-esm/lib/utils/reparenting.mjs.map +2 -2
  154. package/dist-esm/version.mjs +4 -4
  155. package/dist-esm/version.mjs.map +1 -1
  156. package/editor.css +308 -290
  157. package/package.json +14 -37
  158. package/src/index.ts +4 -9
  159. package/src/lib/TldrawEditor.tsx +14 -21
  160. package/src/lib/components/MenuClickCapture.tsx +0 -8
  161. package/src/lib/components/Shape.tsx +6 -12
  162. package/src/lib/components/default-components/DefaultCanvas.tsx +11 -22
  163. package/src/lib/components/default-components/DefaultCollaboratorHint.tsx +1 -1
  164. package/src/lib/components/default-components/DefaultErrorFallback.tsx +1 -1
  165. package/src/lib/components/default-components/DefaultScribble.tsx +1 -1
  166. package/src/lib/components/default-components/DefaultShapeIndicator.tsx +5 -1
  167. package/src/lib/config/TLUserPreferences.ts +21 -1
  168. package/src/lib/editor/Editor.test.ts +102 -11
  169. package/src/lib/editor/Editor.ts +165 -198
  170. package/src/lib/editor/derivations/notVisibleShapes.ts +6 -0
  171. package/src/lib/editor/managers/ClickManager/ClickManager.test.ts +15 -14
  172. package/src/lib/editor/managers/EdgeScrollManager/EdgeScrollManager.test.ts +16 -15
  173. package/src/lib/editor/managers/FocusManager/FocusManager.test.ts +49 -48
  174. package/src/lib/editor/managers/FocusManager/FocusManager.ts +6 -2
  175. package/src/lib/editor/managers/FontManager/FontManager.test.ts +24 -23
  176. package/src/lib/editor/managers/HistoryManager/HistoryManager.test.ts +7 -6
  177. package/src/lib/editor/managers/ScribbleManager/ScribbleManager.test.ts +12 -11
  178. package/src/lib/editor/managers/SnapManager/SnapManager.test.ts +57 -50
  179. package/src/lib/editor/managers/TextManager/TextManager.test.ts +51 -26
  180. package/src/lib/editor/managers/TickManager/TickManager.test.ts +14 -13
  181. package/src/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.test.ts +56 -26
  182. package/src/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.ts +13 -1
  183. package/src/lib/editor/shapes/ShapeUtil.ts +46 -0
  184. package/src/lib/editor/types/misc-types.ts +54 -7
  185. package/src/lib/exports/getSvgJsx.test.ts +868 -0
  186. package/src/lib/exports/getSvgJsx.tsx +78 -21
  187. package/src/lib/hooks/useCanvasEvents.ts +62 -55
  188. package/src/lib/hooks/useDocumentEvents.ts +6 -6
  189. package/src/lib/hooks/useFixSafariDoubleTapZoomPencilEvents.ts +1 -1
  190. package/src/lib/hooks/useGestureEvents.ts +2 -2
  191. package/src/lib/hooks/useHandleEvents.ts +6 -6
  192. package/src/lib/hooks/usePassThroughMouseOverEvents.ts +4 -1
  193. package/src/lib/hooks/usePassThroughWheelEvents.ts +6 -1
  194. package/src/lib/hooks/useSelectionEvents.ts +9 -14
  195. package/src/lib/hooks/useStateAttribute.ts +15 -0
  196. package/src/lib/license/LicenseManager.test.ts +724 -383
  197. package/src/lib/license/LicenseManager.ts +204 -58
  198. package/src/lib/license/LicenseProvider.tsx +74 -2
  199. package/src/lib/license/Watermark.test.tsx +2 -1
  200. package/src/lib/license/Watermark.tsx +152 -77
  201. package/src/lib/license/useLicenseManagerState.ts +2 -2
  202. package/src/lib/options.ts +8 -0
  203. package/src/lib/primitives/Box.test.ts +126 -0
  204. package/src/lib/primitives/Box.ts +10 -1
  205. package/src/lib/primitives/Vec.ts +0 -5
  206. package/src/lib/primitives/geometry/Geometry2d.test.ts +420 -0
  207. package/src/lib/primitives/geometry/Geometry2d.ts +78 -21
  208. package/src/lib/primitives/geometry/Group2d.ts +10 -1
  209. package/src/lib/test/InFrontOfTheCanvas.test.tsx +187 -0
  210. package/src/lib/utils/EditorAtom.ts +37 -0
  211. package/src/lib/utils/dom.test.ts +103 -0
  212. package/src/lib/utils/dom.ts +8 -1
  213. package/src/lib/utils/getPointerInfo.ts +3 -2
  214. package/src/lib/utils/reparenting.ts +10 -70
  215. package/src/lib/utils/sync/LocalIndexedDb.test.ts +2 -1
  216. package/src/lib/utils/sync/TLLocalSyncClient.test.ts +15 -15
  217. package/src/version.ts +4 -4
  218. package/dist-cjs/lib/utils/nearestMultiple.js.map +0 -7
  219. package/dist-esm/lib/utils/nearestMultiple.mjs +0 -14
  220. package/dist-esm/lib/utils/nearestMultiple.mjs.map +0 -7
  221. package/src/lib/utils/nearestMultiple.ts +0 -13
@@ -44,7 +44,7 @@ function useHandleEvents(id, handleId) {
44
44
  const editor = (0, import_useEditor.useEditor)();
45
45
  return React.useMemo(() => {
46
46
  const onPointerDown = (e) => {
47
- if (e.isKilled) return;
47
+ if (editor.wasEventAlreadyHandled(e)) return;
48
48
  const target = (0, import_dom.loopToHtmlElement)(e.currentTarget);
49
49
  (0, import_dom.setPointerCapture)(target, e);
50
50
  const { shape, handle } = getHandle(editor, id, handleId);
@@ -55,12 +55,12 @@ function useHandleEvents(id, handleId) {
55
55
  handle,
56
56
  shape,
57
57
  name: "pointer_down",
58
- ...(0, import_getPointerInfo.getPointerInfo)(e)
58
+ ...(0, import_getPointerInfo.getPointerInfo)(editor, e)
59
59
  });
60
60
  };
61
61
  let lastX, lastY;
62
62
  const onPointerMove = (e) => {
63
- if (e.isKilled) return;
63
+ if (editor.wasEventAlreadyHandled(e)) return;
64
64
  if (e.clientX === lastX && e.clientY === lastY) return;
65
65
  lastX = e.clientX;
66
66
  lastY = e.clientY;
@@ -72,11 +72,11 @@ function useHandleEvents(id, handleId) {
72
72
  handle,
73
73
  shape,
74
74
  name: "pointer_move",
75
- ...(0, import_getPointerInfo.getPointerInfo)(e)
75
+ ...(0, import_getPointerInfo.getPointerInfo)(editor, e)
76
76
  });
77
77
  };
78
78
  const onPointerUp = (e) => {
79
- if (e.isKilled) return;
79
+ if (editor.wasEventAlreadyHandled(e)) return;
80
80
  const target = (0, import_dom.loopToHtmlElement)(e.currentTarget);
81
81
  (0, import_dom.releasePointerCapture)(target, e);
82
82
  const { shape, handle } = getHandle(editor, id, handleId);
@@ -87,7 +87,7 @@ function useHandleEvents(id, handleId) {
87
87
  handle,
88
88
  shape,
89
89
  name: "pointer_up",
90
- ...(0, import_getPointerInfo.getPointerInfo)(e)
90
+ ...(0, import_getPointerInfo.getPointerInfo)(editor, e)
91
91
  });
92
92
  };
93
93
  return {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/lib/hooks/useHandleEvents.ts"],
4
- "sourcesContent": ["import { TLArrowShape, TLLineShape, TLShapeId } from '@tldraw/tlschema'\nimport * as React from 'react'\nimport { Editor } from '../editor/Editor'\nimport { loopToHtmlElement, releasePointerCapture, setPointerCapture } from '../utils/dom'\nimport { getPointerInfo } from '../utils/getPointerInfo'\nimport { useEditor } from './useEditor'\n\nfunction getHandle(editor: Editor, id: TLShapeId, handleId: string) {\n\tconst shape = editor.getShape<TLArrowShape | TLLineShape>(id)!\n\tconst handles = editor.getShapeHandles(shape)!\n\treturn { shape, handle: handles.find((h) => h.id === handleId) }\n}\n\nexport function useHandleEvents(id: TLShapeId, handleId: string) {\n\tconst editor = useEditor()\n\n\treturn React.useMemo(() => {\n\t\tconst onPointerDown = (e: React.PointerEvent) => {\n\t\t\tif ((e as any).isKilled) return\n\n\t\t\t// Must set pointer capture on an HTML element!\n\t\t\tconst target = loopToHtmlElement(e.currentTarget)\n\t\t\tsetPointerCapture(target, e)\n\n\t\t\tconst { shape, handle } = getHandle(editor, id, handleId)\n\n\t\t\tif (!handle) return\n\n\t\t\teditor.dispatch({\n\t\t\t\ttype: 'pointer',\n\t\t\t\ttarget: 'handle',\n\t\t\t\thandle,\n\t\t\t\tshape,\n\t\t\t\tname: 'pointer_down',\n\t\t\t\t...getPointerInfo(e),\n\t\t\t})\n\t\t}\n\n\t\t// Track the last screen point\n\t\tlet lastX: number, lastY: number\n\n\t\tconst onPointerMove = (e: React.PointerEvent) => {\n\t\t\tif ((e as any).isKilled) return\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\tconst { shape, handle } = getHandle(editor, id, handleId)\n\n\t\t\tif (!handle) return\n\n\t\t\teditor.dispatch({\n\t\t\t\ttype: 'pointer',\n\t\t\t\ttarget: 'handle',\n\t\t\t\thandle,\n\t\t\t\tshape,\n\t\t\t\tname: 'pointer_move',\n\t\t\t\t...getPointerInfo(e),\n\t\t\t})\n\t\t}\n\n\t\tconst onPointerUp = (e: React.PointerEvent) => {\n\t\t\tif ((e as any).isKilled) return\n\n\t\t\tconst target = loopToHtmlElement(e.currentTarget)\n\t\t\treleasePointerCapture(target, e)\n\n\t\t\tconst { shape, handle } = getHandle(editor, id, handleId)\n\n\t\t\tif (!handle) return\n\n\t\t\teditor.dispatch({\n\t\t\t\ttype: 'pointer',\n\t\t\t\ttarget: 'handle',\n\t\t\t\thandle,\n\t\t\t\tshape,\n\t\t\t\tname: 'pointer_up',\n\t\t\t\t...getPointerInfo(e),\n\t\t\t})\n\t\t}\n\n\t\treturn {\n\t\t\tonPointerDown,\n\t\t\tonPointerMove,\n\t\t\tonPointerUp,\n\t\t}\n\t}, [editor, id, handleId])\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,YAAuB;AAEvB,iBAA4E;AAC5E,4BAA+B;AAC/B,uBAA0B;AAE1B,SAA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I,QAAQ;AAExD,UAAI,CAAC,OAAQ;AAEb,aAAO,SAAS;AAAA,QACf,MAAM;AAAA,QACN,QAAQ;AAAA,QACR;AAAA,QACA;AAAA,QACA,MAAM;AAAA,QACN,OAAG,sCAAe,CAAC;AAAA,MACpB,CAAC;AAAA,IACF;AAEA,WAAO;AAAA,MACN;AAAA,MACA;AAAA,MACA;AAAA,IACD;AAAA,EACD,GAAG,CAAC,QAAQ,IAAI,QAAQ,CAAC;AAC1B;",
4
+ "sourcesContent": ["import { TLArrowShape, TLLineShape, TLShapeId } from '@tldraw/tlschema'\nimport * as React from 'react'\nimport { Editor } from '../editor/Editor'\nimport { loopToHtmlElement, releasePointerCapture, setPointerCapture } from '../utils/dom'\nimport { getPointerInfo } from '../utils/getPointerInfo'\nimport { useEditor } from './useEditor'\n\nfunction getHandle(editor: Editor, id: TLShapeId, handleId: string) {\n\tconst shape = editor.getShape<TLArrowShape | TLLineShape>(id)!\n\tconst handles = editor.getShapeHandles(shape)!\n\treturn { shape, handle: handles.find((h) => h.id === handleId) }\n}\n\nexport function useHandleEvents(id: TLShapeId, handleId: string) {\n\tconst editor = useEditor()\n\n\treturn React.useMemo(() => {\n\t\tconst onPointerDown = (e: React.PointerEvent) => {\n\t\t\tif (editor.wasEventAlreadyHandled(e)) return\n\n\t\t\t// Must set pointer capture on an HTML element!\n\t\t\tconst target = loopToHtmlElement(e.currentTarget)\n\t\t\tsetPointerCapture(target, e)\n\n\t\t\tconst { shape, handle } = getHandle(editor, id, handleId)\n\n\t\t\tif (!handle) return\n\n\t\t\teditor.dispatch({\n\t\t\t\ttype: 'pointer',\n\t\t\t\ttarget: 'handle',\n\t\t\t\thandle,\n\t\t\t\tshape,\n\t\t\t\tname: 'pointer_down',\n\t\t\t\t...getPointerInfo(editor, e),\n\t\t\t})\n\t\t}\n\n\t\t// Track the last screen point\n\t\tlet lastX: number, lastY: number\n\n\t\tconst onPointerMove = (e: React.PointerEvent) => {\n\t\t\tif (editor.wasEventAlreadyHandled(e)) return\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\tconst { shape, handle } = getHandle(editor, id, handleId)\n\n\t\t\tif (!handle) return\n\n\t\t\teditor.dispatch({\n\t\t\t\ttype: 'pointer',\n\t\t\t\ttarget: 'handle',\n\t\t\t\thandle,\n\t\t\t\tshape,\n\t\t\t\tname: 'pointer_move',\n\t\t\t\t...getPointerInfo(editor, e),\n\t\t\t})\n\t\t}\n\n\t\tconst onPointerUp = (e: React.PointerEvent) => {\n\t\t\tif (editor.wasEventAlreadyHandled(e)) return\n\n\t\t\tconst target = loopToHtmlElement(e.currentTarget)\n\t\t\treleasePointerCapture(target, e)\n\n\t\t\tconst { shape, handle } = getHandle(editor, id, handleId)\n\n\t\t\tif (!handle) return\n\n\t\t\teditor.dispatch({\n\t\t\t\ttype: 'pointer',\n\t\t\t\ttarget: 'handle',\n\t\t\t\thandle,\n\t\t\t\tshape,\n\t\t\t\tname: 'pointer_up',\n\t\t\t\t...getPointerInfo(editor, e),\n\t\t\t})\n\t\t}\n\n\t\treturn {\n\t\t\tonPointerDown,\n\t\t\tonPointerMove,\n\t\t\tonPointerUp,\n\t\t}\n\t}, [editor, id, handleId])\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,YAAuB;AAEvB,iBAA4E;AAC5E,4BAA+B;AAC/B,uBAA0B;AAE1B,SAAS,UAAU,QAAgB,IAAe,UAAkB;AACnE,QAAM,QAAQ,OAAO,SAAqC,EAAE;AAC5D,QAAM,UAAU,OAAO,gBAAgB,KAAK;AAC5C,SAAO,EAAE,OAAO,QAAQ,QAAQ,KAAK,CAAC,MAAM,EAAE,OAAO,QAAQ,EAAE;AAChE;AAEO,SAAS,gBAAgB,IAAe,UAAkB;AAChE,QAAM,aAAS,4BAAU;AAEzB,SAAO,MAAM,QAAQ,MAAM;AAC1B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MACA;AAAA,IACD;AAAA,EACD,GAAG,CAAC,QAAQ,IAAI,QAAQ,CAAC;AAC1B;",
6
6
  "names": []
7
7
  }
@@ -24,11 +24,14 @@ module.exports = __toCommonJS(usePassThroughMouseOverEvents_exports);
24
24
  var import_react = require("react");
25
25
  var import_dom = require("../utils/dom");
26
26
  var import_useContainer = require("./useContainer");
27
+ var import_useEditor = require("./useEditor");
27
28
  function usePassThroughMouseOverEvents(ref) {
28
29
  if (!ref) throw Error("usePassThroughWheelEvents must be passed a ref");
29
30
  const container = (0, import_useContainer.useContainer)();
31
+ const editor = (0, import_useEditor.useMaybeEditor)();
30
32
  (0, import_react.useEffect)(() => {
31
33
  function onMouseOver(e) {
34
+ if (!editor?.getInstanceState().isFocused) return;
32
35
  if (e.isSpecialRedispatchedEvent) return;
33
36
  (0, import_dom.preventDefault)(e);
34
37
  const cvs = container.querySelector(".tl-canvas");
@@ -43,6 +46,6 @@ function usePassThroughMouseOverEvents(ref) {
43
46
  return () => {
44
47
  elm.removeEventListener("mouseover", onMouseOver);
45
48
  };
46
- }, [container, ref]);
49
+ }, [container, editor, ref]);
47
50
  }
48
51
  //# sourceMappingURL=usePassThroughMouseOverEvents.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/lib/hooks/usePassThroughMouseOverEvents.ts"],
4
- "sourcesContent": ["import { RefObject, useEffect } from 'react'\nimport { preventDefault } from '../utils/dom'\nimport { useContainer } from './useContainer'\n\n/** @public */\nexport function usePassThroughMouseOverEvents(ref: RefObject<HTMLElement>) {\n\tif (!ref) throw Error('usePassThroughWheelEvents must be passed a ref')\n\tconst container = useContainer()\n\n\tuseEffect(() => {\n\t\tfunction onMouseOver(e: MouseEvent) {\n\t\t\tif ((e as any).isSpecialRedispatchedEvent) return\n\t\t\tpreventDefault(e)\n\t\t\tconst cvs = container.querySelector('.tl-canvas')\n\t\t\tif (!cvs) return\n\t\t\tconst newEvent = new PointerEvent(e.type, e as any)\n\t\t\t;(newEvent as any).isSpecialRedispatchedEvent = true\n\t\t\tcvs.dispatchEvent(newEvent)\n\t\t}\n\n\t\tconst elm = ref.current\n\t\tif (!elm) return\n\n\t\telm.addEventListener('mouseover', onMouseOver, { passive: false })\n\t\treturn () => {\n\t\t\telm.removeEventListener('mouseover', onMouseOver)\n\t\t}\n\t}, [container, ref])\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAqC;AACrC,iBAA+B;AAC/B,0BAA6B;AAGtB,SAAS,8BAA8B,KAA6B;AAC1E,MAAI,CAAC,IAAK,OAAM,MAAM,gDAAgD;AACtE,QAAM,gBAAY,kCAAa;AAE/B,8BAAU,MAAM;AACf,aAAS,YAAY,GAAe;AACnC,UAAK,EAAU,2BAA4B;AAC3C,qCAAe,CAAC;AAChB,YAAM,MAAM,UAAU,cAAc,YAAY;AAChD,UAAI,CAAC,IAAK;AACV,YAAM,WAAW,IAAI,aAAa,EAAE,MAAM,CAAQ;AACjD,MAAC,SAAiB,6BAA6B;AAChD,UAAI,cAAc,QAAQ;AAAA,IAC3B;AAEA,UAAM,MAAM,IAAI;AAChB,QAAI,CAAC,IAAK;AAEV,QAAI,iBAAiB,aAAa,aAAa,EAAE,SAAS,MAAM,CAAC;AACjE,WAAO,MAAM;AACZ,UAAI,oBAAoB,aAAa,WAAW;AAAA,IACjD;AAAA,EACD,GAAG,CAAC,WAAW,GAAG,CAAC;AACpB;",
4
+ "sourcesContent": ["import { RefObject, useEffect } from 'react'\nimport { preventDefault } from '../utils/dom'\nimport { useContainer } from './useContainer'\nimport { useMaybeEditor } from './useEditor'\n\n/** @public */\nexport function usePassThroughMouseOverEvents(ref: RefObject<HTMLElement>) {\n\tif (!ref) throw Error('usePassThroughWheelEvents must be passed a ref')\n\tconst container = useContainer()\n\tconst editor = useMaybeEditor()\n\n\tuseEffect(() => {\n\t\tfunction onMouseOver(e: MouseEvent) {\n\t\t\tif (!editor?.getInstanceState().isFocused) return\n\t\t\tif ((e as any).isSpecialRedispatchedEvent) return\n\t\t\tpreventDefault(e)\n\t\t\tconst cvs = container.querySelector('.tl-canvas')\n\t\t\tif (!cvs) return\n\t\t\tconst newEvent = new PointerEvent(e.type, e as any)\n\t\t\t;(newEvent as any).isSpecialRedispatchedEvent = true\n\t\t\tcvs.dispatchEvent(newEvent)\n\t\t}\n\n\t\tconst elm = ref.current\n\t\tif (!elm) return\n\n\t\telm.addEventListener('mouseover', onMouseOver, { passive: false })\n\t\treturn () => {\n\t\t\telm.removeEventListener('mouseover', onMouseOver)\n\t\t}\n\t}, [container, editor, ref])\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAqC;AACrC,iBAA+B;AAC/B,0BAA6B;AAC7B,uBAA+B;AAGxB,SAAS,8BAA8B,KAA6B;AAC1E,MAAI,CAAC,IAAK,OAAM,MAAM,gDAAgD;AACtE,QAAM,gBAAY,kCAAa;AAC/B,QAAM,aAAS,iCAAe;AAE9B,8BAAU,MAAM;AACf,aAAS,YAAY,GAAe;AACnC,UAAI,CAAC,QAAQ,iBAAiB,EAAE,UAAW;AAC3C,UAAK,EAAU,2BAA4B;AAC3C,qCAAe,CAAC;AAChB,YAAM,MAAM,UAAU,cAAc,YAAY;AAChD,UAAI,CAAC,IAAK;AACV,YAAM,WAAW,IAAI,aAAa,EAAE,MAAM,CAAQ;AACjD,MAAC,SAAiB,6BAA6B;AAChD,UAAI,cAAc,QAAQ;AAAA,IAC3B;AAEA,UAAM,MAAM,IAAI;AAChB,QAAI,CAAC,IAAK;AAEV,QAAI,iBAAiB,aAAa,aAAa,EAAE,SAAS,MAAM,CAAC;AACjE,WAAO,MAAM;AACZ,UAAI,oBAAoB,aAAa,WAAW;AAAA,IACjD;AAAA,EACD,GAAG,CAAC,WAAW,QAAQ,GAAG,CAAC;AAC5B;",
6
6
  "names": []
7
7
  }
@@ -24,11 +24,14 @@ module.exports = __toCommonJS(usePassThroughWheelEvents_exports);
24
24
  var import_react = require("react");
25
25
  var import_dom = require("../utils/dom");
26
26
  var import_useContainer = require("./useContainer");
27
+ var import_useEditor = require("./useEditor");
27
28
  function usePassThroughWheelEvents(ref) {
28
29
  if (!ref) throw Error("usePassThroughWheelEvents must be passed a ref");
29
30
  const container = (0, import_useContainer.useContainer)();
31
+ const editor = (0, import_useEditor.useMaybeEditor)();
30
32
  (0, import_react.useEffect)(() => {
31
33
  function onWheel(e) {
34
+ if (!editor?.getInstanceState().isFocused) return;
32
35
  if (e.isSpecialRedispatchedEvent) return;
33
36
  const elm2 = ref.current;
34
37
  if (elm2 && elm2.scrollHeight > elm2.clientHeight) {
@@ -47,6 +50,6 @@ function usePassThroughWheelEvents(ref) {
47
50
  return () => {
48
51
  elm.removeEventListener("wheel", onWheel);
49
52
  };
50
- }, [container, ref]);
53
+ }, [container, editor, ref]);
51
54
  }
52
55
  //# sourceMappingURL=usePassThroughWheelEvents.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/lib/hooks/usePassThroughWheelEvents.ts"],
4
- "sourcesContent": ["import { RefObject, useEffect } from 'react'\nimport { preventDefault } from '../utils/dom'\nimport { useContainer } from './useContainer'\n\n/** @public */\nexport function usePassThroughWheelEvents(ref: RefObject<HTMLElement>) {\n\tif (!ref) throw Error('usePassThroughWheelEvents must be passed a ref')\n\tconst container = useContainer()\n\n\tuseEffect(() => {\n\t\tfunction onWheel(e: WheelEvent) {\n\t\t\tif ((e as any).isSpecialRedispatchedEvent) return\n\n\t\t\t// if the element is scrollable, don't redispatch the event\n\t\t\tconst elm = ref.current\n\t\t\tif (elm && elm.scrollHeight > elm.clientHeight) {\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tpreventDefault(e)\n\t\t\tconst cvs = container.querySelector('.tl-canvas')\n\t\t\tif (!cvs) return\n\t\t\tconst newEvent = new WheelEvent('wheel', e as any)\n\t\t\t;(newEvent as any).isSpecialRedispatchedEvent = true\n\t\t\tcvs.dispatchEvent(newEvent)\n\t\t}\n\n\t\tconst elm = ref.current\n\t\tif (!elm) return\n\n\t\telm.addEventListener('wheel', onWheel, { passive: false })\n\t\treturn () => {\n\t\t\telm.removeEventListener('wheel', onWheel)\n\t\t}\n\t}, [container, ref])\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAqC;AACrC,iBAA+B;AAC/B,0BAA6B;AAGtB,SAAS,0BAA0B,KAA6B;AACtE,MAAI,CAAC,IAAK,OAAM,MAAM,gDAAgD;AACtE,QAAM,gBAAY,kCAAa;AAE/B,8BAAU,MAAM;AACf,aAAS,QAAQ,GAAe;AAC/B,UAAK,EAAU,2BAA4B;AAG3C,YAAMA,OAAM,IAAI;AAChB,UAAIA,QAAOA,KAAI,eAAeA,KAAI,cAAc;AAC/C;AAAA,MACD;AAEA,qCAAe,CAAC;AAChB,YAAM,MAAM,UAAU,cAAc,YAAY;AAChD,UAAI,CAAC,IAAK;AACV,YAAM,WAAW,IAAI,WAAW,SAAS,CAAQ;AAChD,MAAC,SAAiB,6BAA6B;AAChD,UAAI,cAAc,QAAQ;AAAA,IAC3B;AAEA,UAAM,MAAM,IAAI;AAChB,QAAI,CAAC,IAAK;AAEV,QAAI,iBAAiB,SAAS,SAAS,EAAE,SAAS,MAAM,CAAC;AACzD,WAAO,MAAM;AACZ,UAAI,oBAAoB,SAAS,OAAO;AAAA,IACzC;AAAA,EACD,GAAG,CAAC,WAAW,GAAG,CAAC;AACpB;",
4
+ "sourcesContent": ["import { RefObject, useEffect } from 'react'\nimport { preventDefault } from '../utils/dom'\nimport { useContainer } from './useContainer'\nimport { useMaybeEditor } from './useEditor'\n\n/** @public */\nexport function usePassThroughWheelEvents(ref: RefObject<HTMLElement>) {\n\tif (!ref) throw Error('usePassThroughWheelEvents must be passed a ref')\n\tconst container = useContainer()\n\tconst editor = useMaybeEditor()\n\n\tuseEffect(() => {\n\t\tfunction onWheel(e: WheelEvent) {\n\t\t\t// Only pass through wheel events if the editor is focused\n\t\t\tif (!editor?.getInstanceState().isFocused) return\n\n\t\t\tif ((e as any).isSpecialRedispatchedEvent) return\n\n\t\t\t// if the element is scrollable, don't redispatch the event\n\t\t\tconst elm = ref.current\n\t\t\tif (elm && elm.scrollHeight > elm.clientHeight) {\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tpreventDefault(e)\n\t\t\tconst cvs = container.querySelector('.tl-canvas')\n\t\t\tif (!cvs) return\n\t\t\tconst newEvent = new WheelEvent('wheel', e as any)\n\t\t\t;(newEvent as any).isSpecialRedispatchedEvent = true\n\t\t\tcvs.dispatchEvent(newEvent)\n\t\t}\n\n\t\tconst elm = ref.current\n\t\tif (!elm) return\n\n\t\telm.addEventListener('wheel', onWheel, { passive: false })\n\t\treturn () => {\n\t\t\telm.removeEventListener('wheel', onWheel)\n\t\t}\n\t}, [container, editor, ref])\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAqC;AACrC,iBAA+B;AAC/B,0BAA6B;AAC7B,uBAA+B;AAGxB,SAAS,0BAA0B,KAA6B;AACtE,MAAI,CAAC,IAAK,OAAM,MAAM,gDAAgD;AACtE,QAAM,gBAAY,kCAAa;AAC/B,QAAM,aAAS,iCAAe;AAE9B,8BAAU,MAAM;AACf,aAAS,QAAQ,GAAe;AAE/B,UAAI,CAAC,QAAQ,iBAAiB,EAAE,UAAW;AAE3C,UAAK,EAAU,2BAA4B;AAG3C,YAAMA,OAAM,IAAI;AAChB,UAAIA,QAAOA,KAAI,eAAeA,KAAI,cAAc;AAC/C;AAAA,MACD;AAEA,qCAAe,CAAC;AAChB,YAAM,MAAM,UAAU,cAAc,YAAY;AAChD,UAAI,CAAC,IAAK;AACV,YAAM,WAAW,IAAI,WAAW,SAAS,CAAQ;AAChD,MAAC,SAAiB,6BAA6B;AAChD,UAAI,cAAc,QAAQ;AAAA,IAC3B;AAEA,UAAM,MAAM,IAAI;AAChB,QAAI,CAAC,IAAK;AAEV,QAAI,iBAAiB,SAAS,SAAS,EAAE,SAAS,MAAM,CAAC;AACzD,WAAO,MAAM;AACZ,UAAI,oBAAoB,SAAS,OAAO;AAAA,IACzC;AAAA,EACD,GAAG,CAAC,WAAW,QAAQ,GAAG,CAAC;AAC5B;",
6
6
  "names": ["elm"]
7
7
  }
@@ -31,14 +31,14 @@ function useSelectionEvents(handle) {
31
31
  const events = (0, import_react.useMemo)(
32
32
  function selectionEvents() {
33
33
  const onPointerDown = (e) => {
34
- if (e.isKilled) return;
34
+ if (editor.wasEventAlreadyHandled(e)) return;
35
35
  if (e.button === import_constants.RIGHT_MOUSE_BUTTON) {
36
36
  editor.dispatch({
37
37
  type: "pointer",
38
38
  target: "selection",
39
39
  handle,
40
40
  name: "right_click",
41
- ...(0, import_getPointerInfo.getPointerInfo)(e)
41
+ ...(0, import_getPointerInfo.getPointerInfo)(editor, e)
42
42
  });
43
43
  return;
44
44
  }
@@ -55,13 +55,13 @@ function useSelectionEvents(handle) {
55
55
  type: "pointer",
56
56
  target: "selection",
57
57
  handle,
58
- ...(0, import_getPointerInfo.getPointerInfo)(e)
58
+ ...(0, import_getPointerInfo.getPointerInfo)(editor, e)
59
59
  });
60
- (0, import_dom.stopEventPropagation)(e);
60
+ editor.markEventAsHandled(e);
61
61
  };
62
62
  let lastX, lastY;
63
63
  function onPointerMove(e) {
64
- if (e.isKilled) return;
64
+ if (editor.wasEventAlreadyHandled(e)) return;
65
65
  if (e.button !== 0) return;
66
66
  if (e.clientX === lastX && e.clientY === lastY) return;
67
67
  lastX = e.clientX;
@@ -71,18 +71,18 @@ function useSelectionEvents(handle) {
71
71
  type: "pointer",
72
72
  target: "selection",
73
73
  handle,
74
- ...(0, import_getPointerInfo.getPointerInfo)(e)
74
+ ...(0, import_getPointerInfo.getPointerInfo)(editor, e)
75
75
  });
76
76
  }
77
77
  const onPointerUp = (e) => {
78
- if (e.isKilled) return;
78
+ if (editor.wasEventAlreadyHandled(e)) return;
79
79
  if (e.button !== 0) return;
80
80
  editor.dispatch({
81
81
  name: "pointer_up",
82
82
  type: "pointer",
83
83
  target: "selection",
84
84
  handle,
85
- ...(0, import_getPointerInfo.getPointerInfo)(e)
85
+ ...(0, import_getPointerInfo.getPointerInfo)(editor, e)
86
86
  });
87
87
  };
88
88
  return {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/lib/hooks/useSelectionEvents.ts"],
4
- "sourcesContent": ["import { useMemo } from 'react'\nimport { RIGHT_MOUSE_BUTTON } from '../constants'\nimport { TLSelectionHandle } from '../editor/types/selection-types'\nimport {\n\tloopToHtmlElement,\n\treleasePointerCapture,\n\tsetPointerCapture,\n\tstopEventPropagation,\n} from '../utils/dom'\nimport { getPointerInfo } from '../utils/getPointerInfo'\nimport { useEditor } from './useEditor'\n\n/** @public */\nexport function useSelectionEvents(handle: TLSelectionHandle) {\n\tconst editor = useEditor()\n\n\tconst events = useMemo(\n\t\tfunction selectionEvents() {\n\t\t\tconst onPointerDown: React.PointerEventHandler = (e) => {\n\t\t\t\tif ((e as any).isKilled) return\n\n\t\t\t\tif (e.button === RIGHT_MOUSE_BUTTON) {\n\t\t\t\t\teditor.dispatch({\n\t\t\t\t\t\ttype: 'pointer',\n\t\t\t\t\t\ttarget: 'selection',\n\t\t\t\t\t\thandle,\n\t\t\t\t\t\tname: 'right_click',\n\t\t\t\t\t\t...getPointerInfo(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) return\n\n\t\t\t\t// Because the events are probably set on SVG elements,\n\t\t\t\t// we need to instead place pointer capture on the first HTML\n\t\t\t\t// element above the event's target; and set a listener to\n\t\t\t\t// remove pointer capture when the pointer is released.\n\n\t\t\t\tconst elm = loopToHtmlElement(e.currentTarget)\n\n\t\t\t\tfunction releaseCapture() {\n\t\t\t\t\telm.removeEventListener('pointerup', releaseCapture)\n\t\t\t\t\treleasePointerCapture(elm, e)\n\t\t\t\t}\n\n\t\t\t\tsetPointerCapture(elm, e)\n\t\t\t\telm.addEventListener('pointerup', releaseCapture)\n\n\t\t\t\teditor.dispatch({\n\t\t\t\t\tname: 'pointer_down',\n\t\t\t\t\ttype: 'pointer',\n\t\t\t\t\ttarget: 'selection',\n\t\t\t\t\thandle,\n\t\t\t\t\t...getPointerInfo(e),\n\t\t\t\t})\n\t\t\t\tstopEventPropagation(e)\n\t\t\t}\n\n\t\t\t// Track the last screen point\n\t\t\tlet lastX: number, lastY: number\n\n\t\t\tfunction onPointerMove(e: React.PointerEvent) {\n\t\t\t\tif ((e as any).isKilled) return\n\t\t\t\tif (e.button !== 0) return\n\t\t\t\tif (e.clientX === lastX && e.clientY === lastY) return\n\t\t\t\tlastX = e.clientX\n\t\t\t\tlastY = e.clientY\n\n\t\t\t\teditor.dispatch({\n\t\t\t\t\tname: 'pointer_move',\n\t\t\t\t\ttype: 'pointer',\n\t\t\t\t\ttarget: 'selection',\n\t\t\t\t\thandle,\n\t\t\t\t\t...getPointerInfo(e),\n\t\t\t\t})\n\t\t\t}\n\n\t\t\tconst onPointerUp: React.PointerEventHandler = (e) => {\n\t\t\t\tif ((e as any).isKilled) return\n\t\t\t\tif (e.button !== 0) return\n\n\t\t\t\teditor.dispatch({\n\t\t\t\t\tname: 'pointer_up',\n\t\t\t\t\ttype: 'pointer',\n\t\t\t\t\ttarget: 'selection',\n\t\t\t\t\thandle,\n\t\t\t\t\t...getPointerInfo(e),\n\t\t\t\t})\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\tonPointerDown,\n\t\t\t\tonPointerMove,\n\t\t\t\tonPointerUp,\n\t\t\t}\n\t\t},\n\t\t[editor, handle]\n\t)\n\n\treturn events\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAwB;AACxB,uBAAmC;AAE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,UACN,QAAQ;AAAA,UACR;AAAA,UACA,OAAG,sCAAe,CAAC;AAAA,QACpB,CAAC;AAAA,MACF;AAEA,aAAO;AAAA,QACN;AAAA,QACA;AAAA,QACA;AAAA,MACD;AAAA,IACD;AAAA,IACA,CAAC,QAAQ,MAAM;AAAA,EAChB;AAEA,SAAO;AACR;",
4
+ "sourcesContent": ["import { useMemo } from 'react'\nimport { RIGHT_MOUSE_BUTTON } from '../constants'\nimport { TLSelectionHandle } from '../editor/types/selection-types'\nimport { loopToHtmlElement, releasePointerCapture, setPointerCapture } from '../utils/dom'\nimport { getPointerInfo } from '../utils/getPointerInfo'\nimport { useEditor } from './useEditor'\n\n/** @public */\nexport function useSelectionEvents(handle: TLSelectionHandle) {\n\tconst editor = useEditor()\n\n\tconst events = useMemo(\n\t\tfunction selectionEvents() {\n\t\t\tconst onPointerDown: React.PointerEventHandler = (e) => {\n\t\t\t\tif (editor.wasEventAlreadyHandled(e)) return\n\n\t\t\t\tif (e.button === RIGHT_MOUSE_BUTTON) {\n\t\t\t\t\teditor.dispatch({\n\t\t\t\t\t\ttype: 'pointer',\n\t\t\t\t\t\ttarget: 'selection',\n\t\t\t\t\t\thandle,\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) return\n\n\t\t\t\t// Because the events are probably set on SVG elements,\n\t\t\t\t// we need to instead place pointer capture on the first HTML\n\t\t\t\t// element above the event's target; and set a listener to\n\t\t\t\t// remove pointer capture when the pointer is released.\n\n\t\t\t\tconst elm = loopToHtmlElement(e.currentTarget)\n\n\t\t\t\tfunction releaseCapture() {\n\t\t\t\t\telm.removeEventListener('pointerup', releaseCapture)\n\t\t\t\t\treleasePointerCapture(elm, e)\n\t\t\t\t}\n\n\t\t\t\tsetPointerCapture(elm, e)\n\t\t\t\telm.addEventListener('pointerup', releaseCapture)\n\n\t\t\t\teditor.dispatch({\n\t\t\t\t\tname: 'pointer_down',\n\t\t\t\t\ttype: 'pointer',\n\t\t\t\t\ttarget: 'selection',\n\t\t\t\t\thandle,\n\t\t\t\t\t...getPointerInfo(editor, e),\n\t\t\t\t})\n\t\t\t\teditor.markEventAsHandled(e)\n\t\t\t}\n\n\t\t\t// Track the last screen point\n\t\t\tlet lastX: number, lastY: number\n\n\t\t\tfunction onPointerMove(e: React.PointerEvent) {\n\t\t\t\tif (editor.wasEventAlreadyHandled(e)) return\n\t\t\t\tif (e.button !== 0) return\n\t\t\t\tif (e.clientX === lastX && e.clientY === lastY) return\n\t\t\t\tlastX = e.clientX\n\t\t\t\tlastY = e.clientY\n\n\t\t\t\teditor.dispatch({\n\t\t\t\t\tname: 'pointer_move',\n\t\t\t\t\ttype: 'pointer',\n\t\t\t\t\ttarget: 'selection',\n\t\t\t\t\thandle,\n\t\t\t\t\t...getPointerInfo(editor, e),\n\t\t\t\t})\n\t\t\t}\n\n\t\t\tconst onPointerUp: React.PointerEventHandler = (e) => {\n\t\t\t\tif (editor.wasEventAlreadyHandled(e)) return\n\t\t\t\tif (e.button !== 0) return\n\n\t\t\t\teditor.dispatch({\n\t\t\t\t\tname: 'pointer_up',\n\t\t\t\t\ttype: 'pointer',\n\t\t\t\t\ttarget: 'selection',\n\t\t\t\t\thandle,\n\t\t\t\t\t...getPointerInfo(editor, e),\n\t\t\t\t})\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\tonPointerDown,\n\t\t\t\tonPointerMove,\n\t\t\t\tonPointerUp,\n\t\t\t}\n\t\t},\n\t\t[editor, handle]\n\t)\n\n\treturn events\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAwB;AACxB,uBAAmC;AAEnC,iBAA4E;AAC5E,4BAA+B;AAC/B,uBAA0B;AAGnB,SAAS,mBAAmB,QAA2B;AAC7D,QAAM,aAAS,4BAAU;AAEzB,QAAM,aAAS;A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,sCAAe,QAAQ,CAAC;AAAA,QAC5B,CAAC;AAAA,MACF;AAEA,aAAO;AAAA,QACN;AAAA,QACA;AAAA,QACA;AAAA,MACD;AAAA,IACD;AAAA,IACA,CAAC,QAAQ,MAAM;AAAA,EAChB;AAEA,SAAO;AACR;",
6
6
  "names": []
7
7
  }
@@ -16,19 +16,20 @@ var __copyProps = (to, from, except, desc) => {
16
16
  return to;
17
17
  };
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var nearestMultiple_exports = {};
20
- __export(nearestMultiple_exports, {
21
- nearestMultiple: () => nearestMultiple
19
+ var useStateAttribute_exports = {};
20
+ __export(useStateAttribute_exports, {
21
+ useStateAttribute: () => useStateAttribute
22
22
  });
23
- module.exports = __toCommonJS(nearestMultiple_exports);
24
- function gcd(a, b) {
25
- return b === 0 ? a : gcd(b, a % b);
23
+ module.exports = __toCommonJS(useStateAttribute_exports);
24
+ var import_state = require("@tldraw/state");
25
+ var import_react = require("react");
26
+ var import_useEditor = require("./useEditor");
27
+ function useStateAttribute() {
28
+ const editor = (0, import_useEditor.useEditor)();
29
+ (0, import_react.useLayoutEffect)(() => {
30
+ return (0, import_state.react)("stateAttribute", () => {
31
+ editor.getContainer().setAttribute("data-state", editor.getPath());
32
+ });
33
+ }, [editor]);
26
34
  }
27
- function nearestMultiple(float) {
28
- const decimal = float.toString().split(".")[1];
29
- if (!decimal) return 1;
30
- const denominator = Math.pow(10, decimal.length);
31
- const numerator = parseInt(decimal, 10);
32
- return denominator / gcd(numerator, denominator);
33
- }
34
- //# sourceMappingURL=nearestMultiple.js.map
35
+ //# sourceMappingURL=useStateAttribute.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/lib/hooks/useStateAttribute.ts"],
4
+ "sourcesContent": ["import { react } from '@tldraw/state'\nimport { useLayoutEffect } from 'react'\nimport { useEditor } from './useEditor'\n\nexport function useStateAttribute() {\n\tconst editor = useEditor()\n\n\t// we use a layout effect because we don't want there to be any perceptible delay between the\n\t// editor mounting and this attribute being applied, because styles may depend on it:\n\tuseLayoutEffect(() => {\n\t\treturn react('stateAttribute', () => {\n\t\t\teditor.getContainer().setAttribute('data-state', editor.getPath())\n\t\t})\n\t}, [editor])\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAsB;AACtB,mBAAgC;AAChC,uBAA0B;AAEnB,SAAS,oBAAoB;AACnC,QAAM,aAAS,4BAAU;AAIzB,oCAAgB,MAAM;AACrB,eAAO,oBAAM,kBAAkB,MAAM;AACpC,aAAO,aAAa,EAAE,aAAa,cAAc,OAAO,QAAQ,CAAC;AAAA,IAClE,CAAC;AAAA,EACF,GAAG,CAAC,MAAM,CAAC;AACZ;",
6
+ "names": []
7
+ }
@@ -21,20 +21,30 @@ __export(LicenseManager_exports, {
21
21
  FLAGS: () => FLAGS,
22
22
  LicenseManager: () => LicenseManager,
23
23
  PROPERTIES: () => PROPERTIES,
24
- isEditorUnlicensed: () => isEditorUnlicensed
24
+ getLicenseState: () => getLicenseState
25
25
  });
26
26
  module.exports = __toCommonJS(LicenseManager_exports);
27
27
  var import_state = require("@tldraw/state");
28
- var import_utils = require("@tldraw/utils");
29
28
  var import_version = require("../../version");
30
29
  var import_assets = require("../utils/assets");
31
30
  var import_licensing = require("../utils/licensing");
32
- const GRACE_PERIOD_DAYS = 5;
31
+ const GRACE_PERIOD_DAYS = 30;
33
32
  const FLAGS = {
33
+ // -- MUTUALLY EXCLUSIVE FLAGS --
34
+ // Annual means the license expires after a time period, usually 1 year.
34
35
  ANNUAL_LICENSE: 1,
35
- PERPETUAL_LICENSE: 2,
36
- INTERNAL_LICENSE: 4,
37
- WITH_WATERMARK: 8
36
+ // Perpetual means the license never expires up to the max supported version.
37
+ PERPETUAL_LICENSE: 1 << 1,
38
+ // -- ADDITIVE FLAGS --
39
+ // Internal means the license is for internal use only.
40
+ INTERNAL_LICENSE: 1 << 2,
41
+ // Watermark means the product is watermarked.
42
+ WITH_WATERMARK: 1 << 3,
43
+ // Evaluation means the license is for evaluation purposes only.
44
+ EVALUATION_LICENSE: 1 << 4,
45
+ // Native means the license is for native apps which switches
46
+ // on special-case logic.
47
+ NATIVE_LICENSE: 1 << 5
38
48
  };
39
49
  const HIGHEST_FLAG = Math.max(...Object.values(FLAGS));
40
50
  const PROPERTIES = {
@@ -51,10 +61,7 @@ class LicenseManager {
51
61
  isDevelopment;
52
62
  isTest;
53
63
  isCryptoAvailable;
54
- state = (0, import_state.atom)(
55
- "license state",
56
- "pending"
57
- );
64
+ state = (0, import_state.atom)("license state", "pending");
58
65
  verbose = true;
59
66
  constructor(licenseKey, testPublicKey, testEnvironment) {
60
67
  this.isTest = process.env.NODE_ENV === "test";
@@ -62,17 +69,16 @@ class LicenseManager {
62
69
  this.publicKey = testPublicKey || this.publicKey;
63
70
  this.isCryptoAvailable = !!crypto.subtle;
64
71
  this.getLicenseFromKey(licenseKey).then((result) => {
65
- const isUnlicensed = isEditorUnlicensed(result);
66
- if (!this.isDevelopment && isUnlicensed) {
67
- (0, import_utils.fetch)(WATERMARK_TRACK_SRC);
68
- }
69
- if (isUnlicensed) {
70
- this.state.set("unlicensed");
71
- } else if (result.isLicensedWithWatermark) {
72
- this.state.set("licensed-with-watermark");
73
- } else {
74
- this.state.set("licensed");
75
- }
72
+ const licenseState = getLicenseState(
73
+ result,
74
+ (messages) => this.outputMessages(messages),
75
+ this.isDevelopment
76
+ );
77
+ this.maybeTrack(result, licenseState);
78
+ this.state.set(licenseState);
79
+ }).catch((error) => {
80
+ console.error("License validation failed:", error);
81
+ this.state.set("unlicensed");
76
82
  });
77
83
  }
78
84
  getIsDevelopment(testEnvironment) {
@@ -80,6 +86,37 @@ class LicenseManager {
80
86
  if (testEnvironment === "production") return false;
81
87
  return !["https:", "vscode-webview:"].includes(window.location.protocol) || window.location.hostname === "localhost";
82
88
  }
89
+ getTrackType(result, licenseState) {
90
+ if (licenseState === "unlicensed-production") {
91
+ return "unlicensed";
92
+ }
93
+ if (this.isDevelopment) {
94
+ return null;
95
+ }
96
+ if (!result.isLicenseParseable) {
97
+ return null;
98
+ }
99
+ if (result.isEvaluationLicense) {
100
+ return "evaluation";
101
+ }
102
+ if (licenseState === "licensed-with-watermark") {
103
+ return "with_watermark";
104
+ }
105
+ return null;
106
+ }
107
+ maybeTrack(result, licenseState) {
108
+ const trackType = this.getTrackType(result, licenseState);
109
+ if (!trackType) {
110
+ return;
111
+ }
112
+ const url = new URL(WATERMARK_TRACK_SRC);
113
+ url.searchParams.set("version", import_version.version);
114
+ url.searchParams.set("license_type", trackType);
115
+ if ("license" in result) {
116
+ url.searchParams.set("license_id", result.license.id);
117
+ }
118
+ fetch(url.toString());
119
+ }
83
120
  async extractLicenseKey(licenseKey) {
84
121
  const [data, signature] = licenseKey.split(".");
85
122
  const [prefix, encodedData] = data.split("/");
@@ -147,6 +184,8 @@ class LicenseManager {
147
184
  const expiryDate = new Date(licenseInfo.expiryDate);
148
185
  const isAnnualLicense = this.isFlagEnabled(licenseInfo.flags, FLAGS.ANNUAL_LICENSE);
149
186
  const isPerpetualLicense = this.isFlagEnabled(licenseInfo.flags, FLAGS.PERPETUAL_LICENSE);
187
+ const isEvaluationLicense = this.isFlagEnabled(licenseInfo.flags, FLAGS.EVALUATION_LICENSE);
188
+ const daysSinceExpiry = this.getDaysSinceExpiry(expiryDate);
150
189
  const result = {
151
190
  license: licenseInfo,
152
191
  isLicenseParseable: true,
@@ -158,7 +197,11 @@ class LicenseManager {
158
197
  isPerpetualLicense,
159
198
  isPerpetualLicenseExpired: isPerpetualLicense && this.isPerpetualLicenseExpired(expiryDate),
160
199
  isInternalLicense: this.isFlagEnabled(licenseInfo.flags, FLAGS.INTERNAL_LICENSE),
161
- isLicensedWithWatermark: this.isFlagEnabled(licenseInfo.flags, FLAGS.WITH_WATERMARK)
200
+ isNativeLicense: this.isNativeLicense(licenseInfo),
201
+ isLicensedWithWatermark: this.isFlagEnabled(licenseInfo.flags, FLAGS.WITH_WATERMARK),
202
+ isEvaluationLicense,
203
+ isEvaluationLicenseExpired: isEvaluationLicense && this.isEvaluationLicenseExpired(expiryDate),
204
+ daysSinceExpiry
162
205
  };
163
206
  this.outputLicenseInfoIfNeeded(result);
164
207
  return result;
@@ -170,13 +213,16 @@ class LicenseManager {
170
213
  isDomainValid(licenseInfo) {
171
214
  const currentHostname = window.location.hostname.toLowerCase();
172
215
  return licenseInfo.hosts.some((host) => {
173
- const normalizedHost = host.toLowerCase().trim();
174
- if (normalizedHost === currentHostname || `www.${normalizedHost}` === currentHostname || normalizedHost === `www.${currentHostname}`) {
216
+ const normalizedHostOrUrlRegex = host.toLowerCase().trim();
217
+ if (normalizedHostOrUrlRegex === currentHostname || `www.${normalizedHostOrUrlRegex}` === currentHostname || normalizedHostOrUrlRegex === `www.${currentHostname}`) {
175
218
  return true;
176
219
  }
177
220
  if (host === "*") {
178
221
  return true;
179
222
  }
223
+ if (this.isNativeLicense(licenseInfo)) {
224
+ return new RegExp(normalizedHostOrUrlRegex).test(window.location.href);
225
+ }
180
226
  if (host.includes("*")) {
181
227
  const globToRegex = new RegExp(host.replace(/\*/g, ".*?"));
182
228
  return globToRegex.test(currentHostname) || globToRegex.test(`www.${currentHostname}`);
@@ -184,13 +230,16 @@ class LicenseManager {
184
230
  if (window.location.protocol === "vscode-webview:") {
185
231
  const currentUrl = new URL(window.location.href);
186
232
  const extensionId = currentUrl.searchParams.get("extensionId");
187
- if (normalizedHost === extensionId) {
233
+ if (normalizedHostOrUrlRegex === extensionId) {
188
234
  return true;
189
235
  }
190
236
  }
191
237
  return false;
192
238
  });
193
239
  }
240
+ isNativeLicense(licenseInfo) {
241
+ return this.isFlagEnabled(licenseInfo.flags, FLAGS.NATIVE_LICENSE);
242
+ }
194
243
  getExpirationDateWithoutGracePeriod(expiryDate) {
195
244
  return new Date(expiryDate.getFullYear(), expiryDate.getMonth(), expiryDate.getDate());
196
245
  }
@@ -204,14 +253,7 @@ class LicenseManager {
204
253
  }
205
254
  isAnnualLicenseExpired(expiryDate) {
206
255
  const expiration = this.getExpirationDateWithGracePeriod(expiryDate);
207
- const isExpired = /* @__PURE__ */ new Date() >= expiration;
208
- if (!isExpired && /* @__PURE__ */ new Date() >= this.getExpirationDateWithoutGracePeriod(expiryDate)) {
209
- this.outputMessages([
210
- "tldraw license is about to expire, you are in a grace period.",
211
- `Please reach out to ${LICENSE_EMAIL} if you would like to renew your license.`
212
- ]);
213
- }
214
- return isExpired;
256
+ return /* @__PURE__ */ new Date() >= expiration;
215
257
  }
216
258
  isPerpetualLicenseExpired(expiryDate) {
217
259
  const expiration = this.getExpirationDateWithGracePeriod(expiryDate);
@@ -221,6 +263,18 @@ class LicenseManager {
221
263
  };
222
264
  return dates.major >= expiration || dates.minor >= expiration;
223
265
  }
266
+ getDaysSinceExpiry(expiryDate) {
267
+ const now = /* @__PURE__ */ new Date();
268
+ const expiration = this.getExpirationDateWithoutGracePeriod(expiryDate);
269
+ const diffTime = now.getTime() - expiration.getTime();
270
+ const diffDays = Math.floor(diffTime / (1e3 * 60 * 60 * 24));
271
+ return Math.max(0, diffDays);
272
+ }
273
+ isEvaluationLicenseExpired(expiryDate) {
274
+ const now = /* @__PURE__ */ new Date();
275
+ const expiration = this.getExpirationDateWithoutGracePeriod(expiryDate);
276
+ return now >= expiration;
277
+ }
224
278
  isFlagEnabled(flags, flag) {
225
279
  return (flags & flag) === flag;
226
280
  }
@@ -230,18 +284,6 @@ class LicenseManager {
230
284
  this.outputMessages(["Invalid tldraw license key", `Reason: ${msg}`]);
231
285
  }
232
286
  outputLicenseInfoIfNeeded(result) {
233
- if (result.isAnnualLicenseExpired) {
234
- this.outputMessages([
235
- "Your tldraw license has expired!",
236
- `Please reach out to ${LICENSE_EMAIL} to renew.`
237
- ]);
238
- }
239
- if (!result.isDomainValid && !result.isDevelopment) {
240
- this.outputMessages([
241
- "This tldraw license key is not valid for this domain!",
242
- `Please reach out to ${LICENSE_EMAIL} if you would like to use tldraw on other domains.`
243
- ]);
244
- }
245
287
  if (result.license.flags >= HIGHEST_FLAG * 2) {
246
288
  this.outputMessages([
247
289
  "This tldraw license contains some unknown flags.",
@@ -270,15 +312,63 @@ class LicenseManager {
270
312
  }
271
313
  static className = "tl-watermark_SEE-LICENSE";
272
314
  }
273
- function isEditorUnlicensed(result) {
274
- if (!result.isLicenseParseable) return true;
275
- if (!result.isDomainValid && !result.isDevelopment) return true;
276
- if (result.isPerpetualLicenseExpired || result.isAnnualLicenseExpired) {
277
- if (result.isInternalLicense) {
278
- throw new Error("License: Internal license expired.");
315
+ function getLicenseState(result, outputMessages, isDevelopment) {
316
+ if (!result.isLicenseParseable) {
317
+ if (isDevelopment) {
318
+ return "unlicensed";
319
+ }
320
+ if (result.reason === "no-key-provided") {
321
+ outputMessages([
322
+ "No tldraw license key provided!",
323
+ "A license is required for production deployments.",
324
+ `Please reach out to ${LICENSE_EMAIL} to purchase a license.`
325
+ ]);
326
+ } else {
327
+ outputMessages([
328
+ "Invalid license key. tldraw requires a valid license for production use.",
329
+ `Please reach out to ${LICENSE_EMAIL} to purchase a license.`
330
+ ]);
331
+ }
332
+ return "unlicensed-production";
333
+ }
334
+ if (!result.isDomainValid && !result.isDevelopment) {
335
+ outputMessages([
336
+ "License key is not valid for this domain.",
337
+ "A license is required for production deployments.",
338
+ `Please reach out to ${LICENSE_EMAIL} to purchase a license.`
339
+ ]);
340
+ return "unlicensed-production";
341
+ }
342
+ if (result.isEvaluationLicense) {
343
+ if (result.isEvaluationLicenseExpired) {
344
+ outputMessages([
345
+ "Your tldraw evaluation license has expired!",
346
+ `Please reach out to ${LICENSE_EMAIL} to purchase a full license.`
347
+ ]);
348
+ return "expired";
349
+ } else {
350
+ return "licensed";
279
351
  }
280
- return true;
281
352
  }
282
- return false;
353
+ if (result.isPerpetualLicenseExpired || result.isAnnualLicenseExpired) {
354
+ outputMessages([
355
+ "Your tldraw license has been expired for more than 30 days!",
356
+ `Please reach out to ${LICENSE_EMAIL} to renew your license.`
357
+ ]);
358
+ return "expired";
359
+ }
360
+ const daysSinceExpiry = result.daysSinceExpiry;
361
+ if (daysSinceExpiry > 0 && !result.isEvaluationLicense) {
362
+ outputMessages([
363
+ "Your tldraw license has expired.",
364
+ `License expired ${daysSinceExpiry} days ago.`,
365
+ `Please reach out to ${LICENSE_EMAIL} to renew your license.`
366
+ ]);
367
+ return "licensed";
368
+ }
369
+ if (result.isLicensedWithWatermark) {
370
+ return "licensed-with-watermark";
371
+ }
372
+ return "licensed";
283
373
  }
284
374
  //# sourceMappingURL=LicenseManager.js.map