@tldraw/editor 5.5.0-next.f9308d324e1c → 5.5.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 (192) hide show
  1. package/dist-cjs/index.d.ts +49 -23
  2. package/dist-cjs/index.js +1 -1
  3. package/dist-cjs/index.js.map +2 -2
  4. package/dist-cjs/lib/TldrawEditor.js +16 -12
  5. package/dist-cjs/lib/TldrawEditor.js.map +2 -2
  6. package/dist-cjs/lib/components/MenuClickCapture.js +42 -3
  7. package/dist-cjs/lib/components/MenuClickCapture.js.map +2 -2
  8. package/dist-cjs/lib/components/default-components/DefaultCanvas.js +5 -1
  9. package/dist-cjs/lib/components/default-components/DefaultCanvas.js.map +2 -2
  10. package/dist-cjs/lib/components/default-components/DefaultErrorFallback.js +2 -5
  11. package/dist-cjs/lib/components/default-components/DefaultErrorFallback.js.map +3 -3
  12. package/dist-cjs/lib/components/default-components/DefaultSpinner.js.map +2 -2
  13. package/dist-cjs/lib/editor/Editor.js +168 -181
  14. package/dist-cjs/lib/editor/Editor.js.map +3 -3
  15. package/dist-cjs/lib/editor/derivations/bindingsIndex.js +2 -0
  16. package/dist-cjs/lib/editor/derivations/bindingsIndex.js.map +2 -2
  17. package/dist-cjs/lib/editor/managers/ClickManager/ClickManager.js +3 -2
  18. package/dist-cjs/lib/editor/managers/ClickManager/ClickManager.js.map +2 -2
  19. package/dist-cjs/lib/editor/managers/EditorManager.js +11 -2
  20. package/dist-cjs/lib/editor/managers/EditorManager.js.map +2 -2
  21. package/dist-cjs/lib/editor/managers/PerformanceManager/PerformanceManager.js +49 -63
  22. package/dist-cjs/lib/editor/managers/PerformanceManager/PerformanceManager.js.map +2 -2
  23. package/dist-cjs/lib/editor/managers/ScribbleManager/ScribbleManager.js +1 -1
  24. package/dist-cjs/lib/editor/managers/ScribbleManager/ScribbleManager.js.map +2 -2
  25. package/dist-cjs/lib/editor/managers/SnapManager/BoundsSnaps.js +24 -24
  26. package/dist-cjs/lib/editor/managers/SnapManager/BoundsSnaps.js.map +2 -2
  27. package/dist-cjs/lib/editor/managers/SnapManager/HandleSnaps.js +7 -1
  28. package/dist-cjs/lib/editor/managers/SnapManager/HandleSnaps.js.map +2 -2
  29. package/dist-cjs/lib/editor/managers/SnapManager/SnapManager.js +4 -3
  30. package/dist-cjs/lib/editor/managers/SnapManager/SnapManager.js.map +2 -2
  31. package/dist-cjs/lib/editor/managers/TextManager/TextManager.js +4 -4
  32. package/dist-cjs/lib/editor/managers/TextManager/TextManager.js.map +2 -2
  33. package/dist-cjs/lib/editor/shapes/group/GroupShapeUtil.js +14 -6
  34. package/dist-cjs/lib/editor/shapes/group/GroupShapeUtil.js.map +3 -3
  35. package/dist-cjs/lib/editor/types/external-content.js.map +1 -1
  36. package/dist-cjs/lib/exports/ExportDelay.js +10 -2
  37. package/dist-cjs/lib/exports/ExportDelay.js.map +2 -2
  38. package/dist-cjs/lib/exports/FontEmbedder.js +25 -11
  39. package/dist-cjs/lib/exports/FontEmbedder.js.map +2 -2
  40. package/dist-cjs/lib/exports/StyleEmbedder.js +9 -4
  41. package/dist-cjs/lib/exports/StyleEmbedder.js.map +2 -2
  42. package/dist-cjs/lib/exports/fetchCache.js +3 -0
  43. package/dist-cjs/lib/exports/fetchCache.js.map +2 -2
  44. package/dist-cjs/lib/exports/getSvgAsImage.js +10 -4
  45. package/dist-cjs/lib/exports/getSvgAsImage.js.map +2 -2
  46. package/dist-cjs/lib/exports/getSvgJsx.js +18 -9
  47. package/dist-cjs/lib/exports/getSvgJsx.js.map +2 -2
  48. package/dist-cjs/lib/exports/parseCss.js +1 -1
  49. package/dist-cjs/lib/exports/parseCss.js.map +1 -1
  50. package/dist-cjs/lib/hooks/EditorComponentsContext.js.map +2 -2
  51. package/dist-cjs/lib/hooks/useCanvasEvents.js +24 -0
  52. package/dist-cjs/lib/hooks/useCanvasEvents.js.map +2 -2
  53. package/dist-cjs/lib/hooks/useIdentity.js +6 -2
  54. package/dist-cjs/lib/hooks/useIdentity.js.map +3 -3
  55. package/dist-cjs/lib/license/LicenseManager.js +9 -1
  56. package/dist-cjs/lib/license/LicenseManager.js.map +2 -2
  57. package/dist-cjs/lib/license/LicenseProvider.js +12 -4
  58. package/dist-cjs/lib/license/LicenseProvider.js.map +2 -2
  59. package/dist-cjs/lib/utils/debug-flags.js +0 -6
  60. package/dist-cjs/lib/utils/debug-flags.js.map +2 -2
  61. package/dist-cjs/lib/utils/deepLinks.js +2 -1
  62. package/dist-cjs/lib/utils/deepLinks.js.map +2 -2
  63. package/dist-cjs/lib/utils/sync/LocalIndexedDb.js +32 -25
  64. package/dist-cjs/lib/utils/sync/LocalIndexedDb.js.map +2 -2
  65. package/dist-cjs/lib/utils/sync/TLLocalSyncClient.js +81 -40
  66. package/dist-cjs/lib/utils/sync/TLLocalSyncClient.js.map +2 -2
  67. package/dist-cjs/version.js +3 -3
  68. package/dist-cjs/version.js.map +1 -1
  69. package/dist-esm/index.d.mts +49 -23
  70. package/dist-esm/index.mjs +4 -2
  71. package/dist-esm/index.mjs.map +2 -2
  72. package/dist-esm/lib/TldrawEditor.mjs +17 -13
  73. package/dist-esm/lib/TldrawEditor.mjs.map +2 -2
  74. package/dist-esm/lib/components/MenuClickCapture.mjs +42 -3
  75. package/dist-esm/lib/components/MenuClickCapture.mjs.map +2 -2
  76. package/dist-esm/lib/components/default-components/DefaultCanvas.mjs +5 -1
  77. package/dist-esm/lib/components/default-components/DefaultCanvas.mjs.map +2 -2
  78. package/dist-esm/lib/components/default-components/DefaultErrorFallback.mjs +2 -5
  79. package/dist-esm/lib/components/default-components/DefaultErrorFallback.mjs.map +3 -3
  80. package/dist-esm/lib/components/default-components/DefaultSpinner.mjs.map +2 -2
  81. package/dist-esm/lib/editor/Editor.mjs +168 -181
  82. package/dist-esm/lib/editor/Editor.mjs.map +3 -3
  83. package/dist-esm/lib/editor/derivations/bindingsIndex.mjs +2 -0
  84. package/dist-esm/lib/editor/derivations/bindingsIndex.mjs.map +2 -2
  85. package/dist-esm/lib/editor/managers/ClickManager/ClickManager.mjs +3 -2
  86. package/dist-esm/lib/editor/managers/ClickManager/ClickManager.mjs.map +2 -2
  87. package/dist-esm/lib/editor/managers/EditorManager.mjs +11 -2
  88. package/dist-esm/lib/editor/managers/EditorManager.mjs.map +2 -2
  89. package/dist-esm/lib/editor/managers/PerformanceManager/PerformanceManager.mjs +49 -63
  90. package/dist-esm/lib/editor/managers/PerformanceManager/PerformanceManager.mjs.map +2 -2
  91. package/dist-esm/lib/editor/managers/ScribbleManager/ScribbleManager.mjs +1 -1
  92. package/dist-esm/lib/editor/managers/ScribbleManager/ScribbleManager.mjs.map +2 -2
  93. package/dist-esm/lib/editor/managers/SnapManager/BoundsSnaps.mjs +24 -24
  94. package/dist-esm/lib/editor/managers/SnapManager/BoundsSnaps.mjs.map +2 -2
  95. package/dist-esm/lib/editor/managers/SnapManager/HandleSnaps.mjs +7 -1
  96. package/dist-esm/lib/editor/managers/SnapManager/HandleSnaps.mjs.map +2 -2
  97. package/dist-esm/lib/editor/managers/SnapManager/SnapManager.mjs +4 -3
  98. package/dist-esm/lib/editor/managers/SnapManager/SnapManager.mjs.map +2 -2
  99. package/dist-esm/lib/editor/managers/TextManager/TextManager.mjs +4 -4
  100. package/dist-esm/lib/editor/managers/TextManager/TextManager.mjs.map +2 -2
  101. package/dist-esm/lib/editor/shapes/group/GroupShapeUtil.mjs +14 -6
  102. package/dist-esm/lib/editor/shapes/group/GroupShapeUtil.mjs.map +3 -3
  103. package/dist-esm/lib/exports/ExportDelay.mjs +11 -3
  104. package/dist-esm/lib/exports/ExportDelay.mjs.map +2 -2
  105. package/dist-esm/lib/exports/FontEmbedder.mjs +25 -11
  106. package/dist-esm/lib/exports/FontEmbedder.mjs.map +2 -2
  107. package/dist-esm/lib/exports/StyleEmbedder.mjs +9 -4
  108. package/dist-esm/lib/exports/StyleEmbedder.mjs.map +2 -2
  109. package/dist-esm/lib/exports/fetchCache.mjs +3 -0
  110. package/dist-esm/lib/exports/fetchCache.mjs.map +2 -2
  111. package/dist-esm/lib/exports/getSvgAsImage.mjs +10 -4
  112. package/dist-esm/lib/exports/getSvgAsImage.mjs.map +2 -2
  113. package/dist-esm/lib/exports/getSvgJsx.mjs +18 -9
  114. package/dist-esm/lib/exports/getSvgJsx.mjs.map +2 -2
  115. package/dist-esm/lib/exports/parseCss.mjs +1 -1
  116. package/dist-esm/lib/exports/parseCss.mjs.map +1 -1
  117. package/dist-esm/lib/hooks/EditorComponentsContext.mjs.map +2 -2
  118. package/dist-esm/lib/hooks/useCanvasEvents.mjs +24 -0
  119. package/dist-esm/lib/hooks/useCanvasEvents.mjs.map +2 -2
  120. package/dist-esm/lib/hooks/useIdentity.mjs +7 -3
  121. package/dist-esm/lib/hooks/useIdentity.mjs.map +3 -3
  122. package/dist-esm/lib/license/LicenseManager.mjs +9 -1
  123. package/dist-esm/lib/license/LicenseManager.mjs.map +2 -2
  124. package/dist-esm/lib/license/LicenseProvider.mjs +13 -5
  125. package/dist-esm/lib/license/LicenseProvider.mjs.map +2 -2
  126. package/dist-esm/lib/utils/debug-flags.mjs +0 -6
  127. package/dist-esm/lib/utils/debug-flags.mjs.map +2 -2
  128. package/dist-esm/lib/utils/deepLinks.mjs +2 -1
  129. package/dist-esm/lib/utils/deepLinks.mjs.map +2 -2
  130. package/dist-esm/lib/utils/sync/LocalIndexedDb.mjs +32 -25
  131. package/dist-esm/lib/utils/sync/LocalIndexedDb.mjs.map +2 -2
  132. package/dist-esm/lib/utils/sync/TLLocalSyncClient.mjs +81 -40
  133. package/dist-esm/lib/utils/sync/TLLocalSyncClient.mjs.map +2 -2
  134. package/dist-esm/version.mjs +3 -3
  135. package/dist-esm/version.mjs.map +1 -1
  136. package/editor.css +9 -1
  137. package/package.json +8 -11
  138. package/src/index.ts +5 -1
  139. package/src/lib/TldrawEditor.tsx +35 -21
  140. package/src/lib/components/MenuClickCapture.tsx +55 -4
  141. package/src/lib/components/default-components/DefaultCanvas.tsx +7 -1
  142. package/src/lib/components/default-components/DefaultErrorFallback.tsx +13 -5
  143. package/src/lib/components/default-components/DefaultSpinner.tsx +4 -1
  144. package/src/lib/editor/Editor.test.ts +65 -0
  145. package/src/lib/editor/Editor.ts +261 -294
  146. package/src/lib/editor/derivations/bindingsIndex.ts +3 -0
  147. package/src/lib/editor/managers/ClickManager/ClickManager.test.ts +1 -0
  148. package/src/lib/editor/managers/ClickManager/ClickManager.ts +3 -2
  149. package/src/lib/editor/managers/EditorManager.test.ts +32 -1
  150. package/src/lib/editor/managers/EditorManager.ts +15 -3
  151. package/src/lib/editor/managers/PerformanceManager/PerformanceManager.test.ts +80 -0
  152. package/src/lib/editor/managers/PerformanceManager/PerformanceManager.ts +54 -81
  153. package/src/lib/editor/managers/ScribbleManager/ScribbleManager.ts +1 -1
  154. package/src/lib/editor/managers/SnapManager/BoundsSnaps.ts +32 -36
  155. package/src/lib/editor/managers/SnapManager/HandleSnaps.ts +13 -2
  156. package/src/lib/editor/managers/SnapManager/SnapManager.test.ts +13 -0
  157. package/src/lib/editor/managers/SnapManager/SnapManager.ts +6 -4
  158. package/src/lib/editor/managers/TextManager/TextManager.test.ts +74 -0
  159. package/src/lib/editor/managers/TextManager/TextManager.ts +6 -5
  160. package/src/lib/editor/shapes/group/GroupShapeUtil.tsx +23 -8
  161. package/src/lib/editor/types/external-content.ts +5 -0
  162. package/src/lib/exports/ExportDelay.tsx +16 -4
  163. package/src/lib/exports/FontEmbedder.test.ts +99 -0
  164. package/src/lib/exports/FontEmbedder.ts +32 -11
  165. package/src/lib/exports/StyleEmbedder.ts +13 -4
  166. package/src/lib/exports/fetchCache.test.ts +22 -0
  167. package/src/lib/exports/fetchCache.ts +4 -0
  168. package/src/lib/exports/getSvgAsImage.ts +13 -5
  169. package/src/lib/exports/getSvgJsx.test.ts +43 -1
  170. package/src/lib/exports/getSvgJsx.tsx +28 -16
  171. package/src/lib/exports/parseCss.test.ts +4 -0
  172. package/src/lib/exports/parseCss.ts +2 -2
  173. package/src/lib/hooks/EditorComponentsContext.tsx +2 -1
  174. package/src/lib/hooks/useCanvasEvents.ts +42 -0
  175. package/src/lib/hooks/useIdentity.tsx +12 -1
  176. package/src/lib/license/LicenseManager.ts +13 -1
  177. package/src/lib/license/LicenseProvider.test.tsx +76 -0
  178. package/src/lib/license/LicenseProvider.tsx +19 -5
  179. package/src/lib/test/preserveFocus.test.tsx +81 -0
  180. package/src/lib/utils/debug-flags.ts +0 -6
  181. package/src/lib/utils/deepLinks.test.ts +15 -0
  182. package/src/lib/utils/deepLinks.ts +8 -3
  183. package/src/lib/utils/sync/LocalIndexedDb.test.ts +121 -1
  184. package/src/lib/utils/sync/LocalIndexedDb.ts +41 -28
  185. package/src/lib/utils/sync/TLLocalSyncClient.test.ts +257 -1
  186. package/src/lib/utils/sync/TLLocalSyncClient.ts +112 -54
  187. package/src/version.ts +3 -3
  188. package/dist-cjs/lib/primitives/geometry/geometry.bench.js +0 -133
  189. package/dist-cjs/lib/primitives/geometry/geometry.bench.js.map +0 -7
  190. package/dist-esm/lib/primitives/geometry/geometry.bench.mjs +0 -132
  191. package/dist-esm/lib/primitives/geometry/geometry.bench.mjs.map +0 -7
  192. package/src/lib/primitives/geometry/geometry.bench.ts +0 -179
@@ -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 { 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\teditor.markHistoryStoppingPoint('drop')\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\teditor.markHistoryStoppingPoint('drop')\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": ";;;;;;;;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B;AAAA,MACnB;AAEA,eAAS,cAAc,GAAqB;AAG3C,YAAI,CAAC,OAAO,QAAQ,kBAAmB;AAGvC,YAAI,CAAC,EAAE,YAAY,UAAW;AAS9B,YAAI,KAAC,sCAAsB,CAAC,EAAG;AAC/B,uCAAe,CAAC;AAAA,MACjB;AAEA,aAAO;AAAA,QACN;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACD;AAAA,IACD;AAAA,IACA,CAAC,MAAM;AAAA,EACR;AAOA,8BAAU,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,yBAAM,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,OAAG,sCAAe,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\t\t\t// The button each accepted press started with, by pointer id. pointercancel\n\t\t\t// reports button -1, so the synthetic pointer_up needs the original.\n\t\t\tconst pointerDownButtons = new Map<number, number>()\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\t// Only remember presses the editor will act on. A rejected palm in pen mode\n\t\t\t\t// must not overwrite the button of the pen press it lands on top of, or the\n\t\t\t\t// pen's pointercancel would release the wrong button and skip the\n\t\t\t\t// stylus-eraser tool restore.\n\t\t\t\tconst isPenMode = editor.getInstanceState().isPenMode\n\t\t\t\tif (!editor.inputs.getIsPinching() && !(isPenMode && e.pointerType !== 'pen')) {\n\t\t\t\t\tpointerDownButtons.set(e.pointerId, button)\n\t\t\t\t}\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\tpointerDownButtons.delete(e.pointerId)\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 onPointerCancel(e: React.PointerEvent) {\n\t\t\t\tif (editor.wasEventAlreadyHandled(e)) return\n\t\t\t\tconst pointerDownButton = pointerDownButtons.get(e.pointerId)\n\t\t\t\tpointerDownButtons.delete(e.pointerId)\n\t\t\t\t// In pen mode a cancelled touch is usually a rejected palm, and the pen's own\n\t\t\t\t// interaction must survive it.\n\t\t\t\tif (editor.getInstanceState().isPenMode && e.pointerType !== 'pen') return\n\n\t\t\t\treleasePointerCapture(e.currentTarget, e)\n\n\t\t\t\t// Nothing to end if the press itself was filtered out (pen mode, unsupported\n\t\t\t\t// button), or if this pointer never started an accepted press.\n\t\t\t\tif (!editor.inputs.getIsPointing() || pointerDownButton === undefined) return\n\n\t\t\t\t// The browser has taken the pointer (edge swipe, incoming call) and will never send\n\t\t\t\t// pointerup, so end the gesture here or the tool stays stuck in its pointing or\n\t\t\t\t// dragging state and the next touch continues it.\n\t\t\t\teditor.interrupt()\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: pointerDownButton,\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\teditor.markHistoryStoppingPoint('drop')\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\teditor.markHistoryStoppingPoint('drop')\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\tonPointerCancel,\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;AAAA;AAAA;AAAA;AAAA;AAAA,yBAAyB;AACzB,mBAA0C;AAC1C,yBAAsB;AACtB,iBAKO;AACP,4BAA+B;AAC/B,qBAAiF;AACjF,uBAA0B;AAEnB,SAAS,kBAAkB;AACjC,QAAM,aAAS,4BAAU;AACzB,QAAM,gBAAgB,OAAO,qBAAqB;AAClD,QAAM,kBAAc,6BAAS,gBAAgB,MAAM,OAAO,eAAe,GAAG,CAAC,MAAM,CAAC;AAEpF,QAAM,aAAS;AAAA,IACd,SAAS,eAAe;AACvB,UAAI,8BAA8B;AAGlC,YAAM,qBAAqB,oBAAI,IAAoB;AAEnD,eAAS,cAAc,GAAuB;AAC7C,YAAI,OAAO,uBAAuB,CAAC,EAAG;AACtC,cAAM,aAAS,sCAAsB,CAAC;AACtC,sCAA8B,WAAW;AAIzC,YAAI,WAAW,KAAK,CAAC,OAAO,QAAQ,mBAAmB;AACtD,iBAAO,SAAS;AAAA,YACf,MAAM;AAAA,YACN,QAAQ;AAAA,YACR,MAAM;AAAA,YACN,OAAG,sCAAe,QAAQ,CAAC;AAAA,UAC5B,CAAC;AACD;AAAA,QACD;AAEA,YAAI,WAAW,KAAK,WAAW,KAAK,WAAW,KAAK,WAAW,EAAG;AAIlE,cAAM,kBAAc,mCAAmB,CAAC;AAExC,0CAAkB,EAAE,eAAe,CAAC;AAMpC,cAAM,YAAY,OAAO,iBAAiB,EAAE;AAC5C,YAAI,CAAC,OAAO,OAAO,cAAc,KAAK,EAAE,aAAa,EAAE,gBAAgB,QAAQ;AAC9E,6BAAmB,IAAI,EAAE,WAAW,MAAM;AAAA,Q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AAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACD;AAAA,IACD;AAAA,IACA,CAAC,MAAM;AAAA,EACR;AAOA,8BAAU,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,yBAAM,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,OAAG,sCAAe,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
  }
@@ -18,15 +18,16 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var useIdentity_exports = {};
20
20
  __export(useIdentity_exports, {
21
+ useDeepObjectIdentity: () => useDeepObjectIdentity,
21
22
  useShallowArrayIdentity: () => useShallowArrayIdentity,
22
23
  useShallowObjectIdentity: () => useShallowObjectIdentity
23
24
  });
24
25
  module.exports = __toCommonJS(useIdentity_exports);
25
26
  var import_utils = require("@tldraw/utils");
26
27
  var import_react = require("react");
27
- function useIdentity(value, isEqual) {
28
+ function useIdentity(value, isEqual2) {
28
29
  const ref = (0, import_react.useRef)(value);
29
- if (isEqual(value, ref.current)) {
30
+ if (isEqual2(value, ref.current)) {
30
31
  return ref.current;
31
32
  }
32
33
  ref.current = value;
@@ -60,4 +61,7 @@ const areNullableObjectsShallowEqual = (a, b) => {
60
61
  function useShallowObjectIdentity(obj) {
61
62
  return useIdentity(obj, areNullableObjectsShallowEqual);
62
63
  }
64
+ function useDeepObjectIdentity(obj) {
65
+ return useIdentity(obj, import_utils.isEqual);
66
+ }
63
67
  //# sourceMappingURL=useIdentity.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/lib/hooks/useIdentity.tsx"],
4
- "sourcesContent": ["import { areArraysShallowEqual, areObjectsShallowEqual } from '@tldraw/utils'\nimport { useRef } from 'react'\n\nfunction useIdentity<T>(value: T, isEqual: (a: T, b: T) => boolean): T {\n\tconst ref = useRef(value)\n\tif (isEqual(value, ref.current)) {\n\t\treturn ref.current\n\t}\n\tref.current = value\n\treturn value\n}\n\nconst areNullableArraysShallowEqual = (\n\ta: readonly any[] | null | undefined,\n\tb: readonly any[] | null | undefined\n) => {\n\ta ??= null\n\tb ??= null\n\tif (a === b) {\n\t\treturn true\n\t}\n\tif (!a || !b) {\n\t\treturn false\n\t}\n\treturn areArraysShallowEqual(a, b)\n}\n\n/** @internal */\nexport function useShallowArrayIdentity<T extends readonly any[] | null | undefined>(arr: T): T {\n\treturn useIdentity(arr, areNullableArraysShallowEqual)\n}\n\nconst areNullableObjectsShallowEqual = (\n\ta: object | null | undefined,\n\tb: object | null | undefined\n) => {\n\ta ??= null\n\tb ??= null\n\tif (a === b) {\n\t\treturn true\n\t}\n\tif (!a || !b) {\n\t\treturn false\n\t}\n\treturn areObjectsShallowEqual(a, b)\n}\n\n/** @internal */\nexport function useShallowObjectIdentity<T extends object | null | undefined>(obj: T): T {\n\treturn useIdentity(obj, areNullableObjectsShallowEqual)\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA8D;AAC9D,mBAAuB;AAEvB,SAAS,YAAe,OAAU,SAAqC;AACtE,QAAM,UAAM,qBAAO,KAAK;AACxB,MAAI,QAAQ,OAAO,IAAI,OAAO,GAAG;AAChC,WAAO,IAAI;AAAA,EACZ;AACA,MAAI,UAAU;AACd,SAAO;AACR;AAEA,MAAM,gCAAgC,CACrC,GACA,MACI;AACJ,QAAM;AACN,QAAM;AACN,MAAI,MAAM,GAAG;AACZ,WAAO;AAAA,EACR;AACA,MAAI,CAAC,KAAK,CAAC,GAAG;AACb,WAAO;AAAA,EACR;AACA,aAAO,oCAAsB,GAAG,CAAC;AAClC;AAGO,SAAS,wBAAqE,KAAW;AAC/F,SAAO,YAAY,KAAK,6BAA6B;AACtD;AAEA,MAAM,iCAAiC,CACtC,GACA,MACI;AACJ,QAAM;AACN,QAAM;AACN,MAAI,MAAM,GAAG;AACZ,WAAO;AAAA,EACR;AACA,MAAI,CAAC,KAAK,CAAC,GAAG;AACb,WAAO;AAAA,EACR;AACA,aAAO,qCAAuB,GAAG,CAAC;AACnC;AAGO,SAAS,yBAA8D,KAAW;AACxF,SAAO,YAAY,KAAK,8BAA8B;AACvD;",
6
- "names": []
4
+ "sourcesContent": ["import { areArraysShallowEqual, areObjectsShallowEqual, isEqual } from '@tldraw/utils'\nimport { useRef } from 'react'\n\nfunction useIdentity<T>(value: T, isEqual: (a: T, b: T) => boolean): T {\n\tconst ref = useRef(value)\n\tif (isEqual(value, ref.current)) {\n\t\treturn ref.current\n\t}\n\tref.current = value\n\treturn value\n}\n\nconst areNullableArraysShallowEqual = (\n\ta: readonly any[] | null | undefined,\n\tb: readonly any[] | null | undefined\n) => {\n\ta ??= null\n\tb ??= null\n\tif (a === b) {\n\t\treturn true\n\t}\n\tif (!a || !b) {\n\t\treturn false\n\t}\n\treturn areArraysShallowEqual(a, b)\n}\n\n/** @internal */\nexport function useShallowArrayIdentity<T extends readonly any[] | null | undefined>(arr: T): T {\n\treturn useIdentity(arr, areNullableArraysShallowEqual)\n}\n\nconst areNullableObjectsShallowEqual = (\n\ta: object | null | undefined,\n\tb: object | null | undefined\n) => {\n\ta ??= null\n\tb ??= null\n\tif (a === b) {\n\t\treturn true\n\t}\n\tif (!a || !b) {\n\t\treturn false\n\t}\n\treturn areObjectsShallowEqual(a, b)\n}\n\n/** @internal */\nexport function useShallowObjectIdentity<T extends object | null | undefined>(obj: T): T {\n\treturn useIdentity(obj, areNullableObjectsShallowEqual)\n}\n\n/**\n * For small option objects that may nest (e.g. camera constraints), where a shallow comparison\n * would still see a fresh identity on every render. Functions and class instances inside still\n * compare by reference, so an inline callback or a fresh `Extension.configure()` counts as a change.\n *\n * @internal\n */\nexport function useDeepObjectIdentity<T extends object | null | undefined>(obj: T): T {\n\treturn useIdentity(obj, isEqual)\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAuE;AACvE,mBAAuB;AAEvB,SAAS,YAAe,OAAUA,UAAqC;AACtE,QAAM,UAAM,qBAAO,KAAK;AACxB,MAAIA,SAAQ,OAAO,IAAI,OAAO,GAAG;AAChC,WAAO,IAAI;AAAA,EACZ;AACA,MAAI,UAAU;AACd,SAAO;AACR;AAEA,MAAM,gCAAgC,CACrC,GACA,MACI;AACJ,QAAM;AACN,QAAM;AACN,MAAI,MAAM,GAAG;AACZ,WAAO;AAAA,EACR;AACA,MAAI,CAAC,KAAK,CAAC,GAAG;AACb,WAAO;AAAA,EACR;AACA,aAAO,oCAAsB,GAAG,CAAC;AAClC;AAGO,SAAS,wBAAqE,KAAW;AAC/F,SAAO,YAAY,KAAK,6BAA6B;AACtD;AAEA,MAAM,iCAAiC,CACtC,GACA,MACI;AACJ,QAAM;AACN,QAAM;AACN,MAAI,MAAM,GAAG;AACZ,WAAO;AAAA,EACR;AACA,MAAI,CAAC,KAAK,CAAC,GAAG;AACb,WAAO;AAAA,EACR;AACA,aAAO,qCAAuB,GAAG,CAAC;AACnC;AAGO,SAAS,yBAA8D,KAAW;AACxF,SAAO,YAAY,KAAK,8BAA8B;AACvD;AASO,SAAS,sBAA2D,KAAW;AACrF,SAAO,YAAY,KAAK,oBAAO;AAChC;",
6
+ "names": ["isEqual"]
7
7
  }
@@ -26,6 +26,7 @@ __export(LicenseManager_exports, {
26
26
  });
27
27
  module.exports = __toCommonJS(LicenseManager_exports);
28
28
  var import_state = require("@tldraw/state");
29
+ var import_utils = require("@tldraw/utils");
29
30
  var import_version = require("../../version");
30
31
  var import_assets = require("../utils/assets");
31
32
  var import_licensing = require("../utils/licensing");
@@ -80,6 +81,7 @@ class LicenseManager {
80
81
  ...NO_FEATURES
81
82
  });
82
83
  verbose = true;
84
+ isDisposed = false;
83
85
  constructor(licenseKey, testPublicKey) {
84
86
  this.isTest = process.env.NODE_ENV === "test";
85
87
  this.isDevelopment = this.getIsDevelopment();
@@ -89,6 +91,7 @@ class LicenseManager {
89
91
  this.featureFlags.set({ ...ALL_FEATURES });
90
92
  }
91
93
  this.getLicenseFromKey(licenseKey).then((result) => {
94
+ if (this.isDisposed) return;
92
95
  const licenseState = getLicenseState(
93
96
  result,
94
97
  (messages) => this.outputMessages(messages),
@@ -100,10 +103,15 @@ class LicenseManager {
100
103
  this.featureFlags.set(getEnabledFeatures(result, licenseState, this.isDevelopment));
101
104
  });
102
105
  }).catch((error) => {
106
+ if (this.isDisposed) return;
103
107
  console.error("License validation failed:", error);
104
108
  this.state.set("unlicensed");
105
109
  });
106
110
  }
111
+ /** Ignore the pending validation: nothing is logged, tracked or set once the manager is replaced. */
112
+ dispose() {
113
+ this.isDisposed = true;
114
+ }
107
115
  /**
108
116
  * Returns whether a given licensable feature is enabled. Reactive: reading this inside a signal
109
117
  * recomputes when license validation resolves.
@@ -158,7 +166,7 @@ class LicenseManager {
158
166
  if (process.env.NODE_ENV) {
159
167
  url.searchParams.set("environment", process.env.NODE_ENV);
160
168
  }
161
- fetch(url.toString());
169
+ fetch(url.toString()).catch(import_utils.noop);
162
170
  }
163
171
  async extractLicenseKey(licenseKey) {
164
172
  const [data, signature] = licenseKey.split(".");
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/lib/license/LicenseManager.ts"],
4
- "sourcesContent": ["import { atom, transact } from '@tldraw/state'\nimport { publishDates, version } from '../../version'\nimport { getDefaultCdnBaseUrl } from '../utils/assets'\nimport { importPublicKey, str2ab } from '../utils/licensing'\n\nconst GRACE_PERIOD_DAYS = 30\n\nexport const FLAGS = {\n\t// -- MUTUALLY EXCLUSIVE FLAGS\n\t// Annual means the license expires after a time period, usually 1 year.\n\tANNUAL_LICENSE: 1,\n\t// Perpetual means the license never expires up to the max supported version.\n\tPERPETUAL_LICENSE: 1 << 1,\n\n\t// -- ADDITIVE FLAGS --\n\t// Internal means the license is for internal use only.\n\tINTERNAL_LICENSE: 1 << 2,\n\t// Watermark means the product is watermarked.\n\tWITH_WATERMARK: 1 << 3,\n\t// Evaluation means the license is for evaluation purposes only.\n\tEVALUATION_LICENSE: 1 << 4,\n\t// Native means the license is for native apps which switches\n\t// on special-case logic.\n\tNATIVE_LICENSE: 1 << 5,\n\n\t// -- FEATURE FLAGS --\n\t// Collaboration is the umbrella flag for collaboration features; it grants all sub-features.\n\tFEAT_COLLABORATION: 1 << 6,\n\t// Commenting is the first sub-feature of collaboration.\n\tFEAT_COMMENTING: 1 << 7,\n}\nconst HIGHEST_FLAG = Math.max(...Object.values(FLAGS))\n\nexport const PROPERTIES = {\n\tID: 0,\n\tHOSTS: 1,\n\tFLAGS: 2,\n\tEXPIRY_DATE: 3,\n}\nconst NUMBER_OF_KNOWN_PROPERTIES = Object.keys(PROPERTIES).length\n\nconst LICENSE_EMAIL = 'sales@tldraw.com'\n\nconst WATERMARK_TRACK_SRC = `${getDefaultCdnBaseUrl()}/watermarks/watermark-track.svg`\n\n/** @internal */\nexport interface LicenseInfo {\n\tid: string\n\thosts: string[]\n\tflags: number\n\texpiryDate: string\n}\n\n/**\n * Names of the licensable product features gated by the license. `collaboration` is an umbrella\n * that also grants all of its sub-features (currently just `commenting`).\n *\n * @internal\n */\nexport type LicenseFeatureName = 'collaboration' | 'commenting'\n\nconst NO_FEATURES: Readonly<Record<LicenseFeatureName, boolean>> = {\n\tcollaboration: false,\n\tcommenting: false,\n}\nconst ALL_FEATURES: Readonly<Record<LicenseFeatureName, boolean>> = {\n\tcollaboration: true,\n\tcommenting: true,\n}\n\n/** @internal */\nexport type LicenseState =\n\t| 'pending' // License validation is in progress\n\t| 'licensed' // License is valid and active (no restrictions)\n\t| 'licensed-with-watermark' // License is valid but shows watermark (evaluation licenses, WITH_WATERMARK licenses)\n\t| 'unlicensed' // No valid license found or license is invalid (development)\n\t| 'unlicensed-production' // No valid license in production deployment (missing, invalid, or wrong domain)\n\t| 'expired' // License has been expired (30 days past expiration for regular licenses, immediately for evaluation licenses)\n/** @internal */\nexport type InvalidLicenseReason =\n\t| 'invalid-license-key'\n\t| 'no-key-provided'\n\t| 'has-key-development-mode'\n\n/** @internal */\nexport type LicenseFromKeyResult = InvalidLicenseKeyResult | ValidLicenseKeyResult\n\n/** @internal */\nexport interface InvalidLicenseKeyResult {\n\tisLicenseParseable: false\n\treason: InvalidLicenseReason\n}\n\n/** @internal */\nexport interface ValidLicenseKeyResult {\n\tisLicenseParseable: true\n\tlicense: LicenseInfo\n\tisDevelopment: boolean\n\tisDomainValid: boolean\n\texpiryDate: Date\n\tisAnnualLicense: boolean\n\tisAnnualLicenseExpired: boolean\n\tisPerpetualLicense: boolean\n\tisPerpetualLicenseExpired: boolean\n\tisInternalLicense: boolean\n\tisNativeLicense: boolean\n\tisLicensedWithWatermark: boolean\n\tisEvaluationLicense: boolean\n\tisEvaluationLicenseExpired: boolean\n\tisCollaborationEnabled: boolean\n\tisCommentingEnabled: boolean\n\tdaysSinceExpiry: number\n}\n\n/** @internal */\nexport type TrackType = 'unlicensed' | 'with_watermark' | 'evaluation' | null\n\n/** @internal */\nexport class LicenseManager {\n\tprivate publicKey =\n\t\t'MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEHJh0uUfxHtCGyerXmmatE368Hd9rI6LH9oPDQihnaCryRFWEVeOvf9U/SPbyxX74LFyJs5tYeAHq5Nc0Ax25LQ'\n\tpublic isDevelopment: boolean\n\tpublic isTest: boolean\n\tpublic isCryptoAvailable: boolean\n\tstate = atom<LicenseState>('license state', 'pending')\n\tfeatureFlags = atom<Record<LicenseFeatureName, boolean>>('license feature flags', {\n\t\t...NO_FEATURES,\n\t})\n\tpublic verbose = true\n\n\tconstructor(licenseKey: string | undefined, testPublicKey?: string) {\n\t\tthis.isTest = process.env.NODE_ENV === 'test'\n\t\tthis.isDevelopment = this.getIsDevelopment()\n\t\tthis.publicKey = testPublicKey || this.publicKey\n\t\tthis.isCryptoAvailable = !!crypto.subtle\n\n\t\t// In development every feature is enabled (see `getEnabledFeatures`), and that doesn't depend\n\t\t// on the async validation result. Reflect it eagerly so features aren't reported as disabled\n\t\t// during the validation window \u2014 or left disabled if validation rejects (the `.catch` below\n\t\t// never sets `featureFlags`). In production the fail-closed default stands until validation.\n\t\tif (this.isDevelopment) {\n\t\t\tthis.featureFlags.set({ ...ALL_FEATURES })\n\t\t}\n\n\t\tthis.getLicenseFromKey(licenseKey)\n\t\t\t.then((result) => {\n\t\t\t\tconst licenseState = getLicenseState(\n\t\t\t\t\tresult,\n\t\t\t\t\t(messages: string[]) => this.outputMessages(messages),\n\t\t\t\t\tthis.isDevelopment\n\t\t\t\t)\n\n\t\t\t\tthis.maybeTrack(result, licenseState)\n\n\t\t\t\t// Update both atoms atomically so dependents never observe the license state and the\n\t\t\t\t// feature flags out of sync mid-update.\n\t\t\t\ttransact(() => {\n\t\t\t\t\tthis.state.set(licenseState)\n\t\t\t\t\tthis.featureFlags.set(getEnabledFeatures(result, licenseState, this.isDevelopment))\n\t\t\t\t})\n\t\t\t})\n\t\t\t.catch((error) => {\n\t\t\t\tconsole.error('License validation failed:', error)\n\t\t\t\tthis.state.set('unlicensed')\n\t\t\t})\n\t}\n\n\t/**\n\t * Returns whether a given licensable feature is enabled. Reactive: reading this inside a signal\n\t * recomputes when license validation resolves.\n\t */\n\tisFeatureEnabled(feature: LicenseFeatureName): boolean {\n\t\treturn this.featureFlags.get()[feature]\n\t}\n\n\tprivate getIsDevelopment() {\n\t\tconst protocol = window.location.protocol\n\t\tconst hostname = window.location.hostname\n\n\t\t// Tauri uses `tauri://localhost` on macOS and Linux and `http://tauri.localhost` on Windows.\n\t\tif (hostname.toLowerCase().endsWith('.localhost')) {\n\t\t\treturn process.env.NODE_ENV !== 'production'\n\t\t}\n\n\t\treturn (\n\t\t\tprotocol === 'http:' ||\n\t\t\t(protocol === 'https:' && this.isLoopbackHost(hostname)) ||\n\t\t\tprocess.env.NODE_ENV !== 'production'\n\t\t)\n\t}\n\n\tprivate isLoopbackHost(hostname: string) {\n\t\t// localhost, IPv4 loopback (127.0.0.0/8) and IPv6 loopback (::1) are all local development hosts\n\t\tconst host = hostname.toLowerCase().replace(/^\\[|\\]$/g, '')\n\t\treturn host === 'localhost' || host === '::1' || /^127(?:\\.\\d{1,3}){3}$/.test(host)\n\t}\n\n\tprivate getTrackType(result: LicenseFromKeyResult, licenseState: LicenseState): TrackType {\n\t\t// Track watermark for unlicensed production deployments\n\t\tif (licenseState === 'unlicensed-production') {\n\t\t\treturn 'unlicensed'\n\t\t}\n\n\t\tif (this.isDevelopment) {\n\t\t\treturn null\n\t\t}\n\n\t\tif (!result.isLicenseParseable) {\n\t\t\treturn null\n\t\t}\n\n\t\t// Track evaluation licenses (for analytics, even though no watermark is shown)\n\t\tif (result.isEvaluationLicense) {\n\t\t\treturn 'evaluation'\n\t\t}\n\n\t\t// Track licenses that show watermarks\n\t\tif (licenseState === 'licensed-with-watermark') {\n\t\t\treturn 'with_watermark'\n\t\t}\n\n\t\treturn null\n\t}\n\n\tprivate maybeTrack(result: LicenseFromKeyResult, licenseState: LicenseState): void {\n\t\tconst trackType = this.getTrackType(result, licenseState)\n\t\tif (!trackType) {\n\t\t\treturn\n\t\t}\n\n\t\tconst url = new URL(WATERMARK_TRACK_SRC)\n\t\turl.searchParams.set('version', version)\n\t\turl.searchParams.set('license_type', trackType)\n\t\tif ('license' in result) {\n\t\t\turl.searchParams.set('license_id', result.license.id)\n\t\t\tconst sku = this.isFlagEnabled(result.license.flags, FLAGS.EVALUATION_LICENSE)\n\t\t\t\t? 'evaluation'\n\t\t\t\t: this.isFlagEnabled(result.license.flags, FLAGS.ANNUAL_LICENSE)\n\t\t\t\t\t? 'annual'\n\t\t\t\t\t: this.isFlagEnabled(result.license.flags, FLAGS.PERPETUAL_LICENSE)\n\t\t\t\t\t\t? 'perpetual'\n\t\t\t\t\t\t: 'unknown'\n\t\t\turl.searchParams.set('sku', sku)\n\t\t}\n\t\turl.searchParams.set('url', window.location.href)\n\t\tif (process.env.NODE_ENV) {\n\t\t\turl.searchParams.set('environment', process.env.NODE_ENV)\n\t\t}\n\n\t\t// eslint-disable-next-line no-restricted-globals\n\t\tfetch(url.toString())\n\t}\n\n\tprivate async extractLicenseKey(licenseKey: string): Promise<LicenseInfo> {\n\t\tconst [data, signature] = licenseKey.split('.')\n\t\tconst [prefix, encodedData] = data.split('/')\n\n\t\tif (!prefix.startsWith('tldraw-')) {\n\t\t\tthrow new Error(`Unsupported prefix '${prefix}'`)\n\t\t}\n\n\t\tconst publicCryptoKey = await importPublicKey(this.publicKey)\n\n\t\tlet isVerified\n\t\ttry {\n\t\t\tisVerified = await crypto.subtle.verify(\n\t\t\t\t{\n\t\t\t\t\tname: 'ECDSA',\n\t\t\t\t\thash: { name: 'SHA-256' },\n\t\t\t\t},\n\t\t\t\tpublicCryptoKey,\n\t\t\t\tnew Uint8Array(str2ab(atob(signature))),\n\t\t\t\tnew Uint8Array(str2ab(atob(encodedData)))\n\t\t\t)\n\t\t} catch (e) {\n\t\t\tconsole.error(e)\n\t\t\tthrow new Error('Could not perform signature validation')\n\t\t}\n\n\t\tif (!isVerified) {\n\t\t\tthrow new Error('Invalid signature')\n\t\t}\n\n\t\tlet decodedData: any\n\t\ttry {\n\t\t\tdecodedData = JSON.parse(atob(encodedData))\n\t\t} catch {\n\t\t\tthrow new Error('Could not parse object')\n\t\t}\n\t\tif (decodedData.length > NUMBER_OF_KNOWN_PROPERTIES) {\n\t\t\tthis.outputMessages([\n\t\t\t\t'License key contains some unknown properties.',\n\t\t\t\t'You may want to update tldraw packages to a newer version to get access to new functionality.',\n\t\t\t])\n\t\t}\n\n\t\treturn {\n\t\t\tid: decodedData[PROPERTIES.ID],\n\t\t\thosts: decodedData[PROPERTIES.HOSTS],\n\t\t\tflags: decodedData[PROPERTIES.FLAGS],\n\t\t\texpiryDate: decodedData[PROPERTIES.EXPIRY_DATE],\n\t\t}\n\t}\n\n\tasync getLicenseFromKey(licenseKey?: string): Promise<LicenseFromKeyResult> {\n\t\tif (!licenseKey) {\n\t\t\tif (!this.isDevelopment) {\n\t\t\t\tthis.outputNoLicenseKeyProvided()\n\t\t\t}\n\n\t\t\treturn { isLicenseParseable: false, reason: 'no-key-provided' }\n\t\t}\n\n\t\tif (this.isDevelopment && !this.isCryptoAvailable) {\n\t\t\tif (this.verbose) {\n\t\t\t\t// eslint-disable-next-line no-console\n\t\t\t\tconsole.log(\n\t\t\t\t\t'tldraw: you seem to be in a development environment that does not support crypto. License not verified.'\n\t\t\t\t)\n\t\t\t\t// eslint-disable-next-line no-console\n\t\t\t\tconsole.log('You should check that this works in production separately.')\n\t\t\t}\n\t\t\t// We can't parse the license if we are in development mode since crypto\n\t\t\t// is not available on http\n\t\t\treturn { isLicenseParseable: false, reason: 'has-key-development-mode' }\n\t\t}\n\n\t\t// Borrowed idea from AG Grid:\n\t\t// Copying from various sources (like PDFs) can include zero-width characters.\n\t\t// This helps makes sure the key validation doesn't fail.\n\t\tlet cleanedLicenseKey = licenseKey.replace(/[\\u200B-\\u200D\\uFEFF]/g, '')\n\t\tcleanedLicenseKey = cleanedLicenseKey.replace(/\\r?\\n|\\r/g, '')\n\n\t\ttry {\n\t\t\tconst licenseInfo = await this.extractLicenseKey(cleanedLicenseKey)\n\t\t\tconst expiryDate = new Date(licenseInfo.expiryDate)\n\t\t\tconst isAnnualLicense = this.isFlagEnabled(licenseInfo.flags, FLAGS.ANNUAL_LICENSE)\n\t\t\tconst isPerpetualLicense = this.isFlagEnabled(licenseInfo.flags, FLAGS.PERPETUAL_LICENSE)\n\t\t\tconst isEvaluationLicense = this.isFlagEnabled(licenseInfo.flags, FLAGS.EVALUATION_LICENSE)\n\n\t\t\tconst isAnnualLicenseExpired = isAnnualLicense && this.isAnnualLicenseExpired(expiryDate)\n\t\t\tconst isPerpetualLicenseExpired =\n\t\t\t\tisPerpetualLicense && this.isPerpetualLicenseExpired(expiryDate)\n\n\t\t\t// The collaboration umbrella grants all of its sub-features, so commenting is enabled\n\t\t\t// by either the commenting flag or the collaboration flag.\n\t\t\tconst isCollaborationEnabled = this.isFlagEnabled(licenseInfo.flags, FLAGS.FEAT_COLLABORATION)\n\t\t\tconst isCommentingEnabled =\n\t\t\t\tisCollaborationEnabled || this.isFlagEnabled(licenseInfo.flags, FLAGS.FEAT_COMMENTING)\n\n\t\t\t// For perpetual licenses, the calendar expiry date only gates access to future\n\t\t\t// major/minor releases; it does not \"expire\" the license itself. While the user\n\t\t\t// is still on a covered version we report `daysSinceExpiry` as 0 so consumers\n\t\t\t// (and the grace-period warning) don't treat them as past expiry.\n\t\t\tconst daysSinceExpiry =\n\t\t\t\tisPerpetualLicense && !isPerpetualLicenseExpired ? 0 : this.getDaysSinceExpiry(expiryDate)\n\n\t\t\tconst result: ValidLicenseKeyResult = {\n\t\t\t\tlicense: licenseInfo,\n\t\t\t\tisLicenseParseable: true,\n\t\t\t\tisDevelopment: this.isDevelopment,\n\t\t\t\tisDomainValid: this.isDomainValid(licenseInfo),\n\t\t\t\texpiryDate,\n\t\t\t\tisAnnualLicense,\n\t\t\t\tisAnnualLicenseExpired,\n\t\t\t\tisPerpetualLicense,\n\t\t\t\tisPerpetualLicenseExpired,\n\t\t\t\tisInternalLicense: this.isFlagEnabled(licenseInfo.flags, FLAGS.INTERNAL_LICENSE),\n\t\t\t\tisNativeLicense: this.isNativeLicense(licenseInfo),\n\t\t\t\tisLicensedWithWatermark: this.isFlagEnabled(licenseInfo.flags, FLAGS.WITH_WATERMARK),\n\t\t\t\tisEvaluationLicense,\n\t\t\t\tisEvaluationLicenseExpired:\n\t\t\t\t\tisEvaluationLicense && this.isEvaluationLicenseExpired(expiryDate),\n\t\t\t\tisCollaborationEnabled,\n\t\t\t\tisCommentingEnabled,\n\t\t\t\tdaysSinceExpiry,\n\t\t\t}\n\t\t\tthis.outputLicenseInfoIfNeeded(result)\n\n\t\t\treturn result\n\t\t} catch (e: any) {\n\t\t\tthis.outputInvalidLicenseKey(e.message)\n\t\t\t// If the license can't be parsed, it's invalid\n\t\t\treturn { isLicenseParseable: false, reason: 'invalid-license-key' }\n\t\t}\n\t}\n\n\tprivate isDomainValid(licenseInfo: LicenseInfo) {\n\t\tconst currentHostname = window.location.hostname.toLowerCase()\n\n\t\treturn licenseInfo.hosts.some((host) => {\n\t\t\tconst normalizedHostOrUrlRegex = host.toLowerCase().trim()\n\n\t\t\t// Allow the domain if listed and www variations, 'example.com' allows 'example.com' and 'www.example.com'\n\t\t\tif (\n\t\t\t\tnormalizedHostOrUrlRegex === currentHostname ||\n\t\t\t\t`www.${normalizedHostOrUrlRegex}` === currentHostname ||\n\t\t\t\tnormalizedHostOrUrlRegex === `www.${currentHostname}`\n\t\t\t) {\n\t\t\t\treturn true\n\t\t\t}\n\n\t\t\t// If host is '*', we allow all domains.\n\t\t\tif (host === '*') {\n\t\t\t\t// All domains allowed.\n\t\t\t\treturn true\n\t\t\t}\n\n\t\t\t// Native license support\n\t\t\t// In this case, `normalizedHost` is actually a protocol, e.g. `app-bundle:`\n\t\t\tif (this.isNativeLicense(licenseInfo)) {\n\t\t\t\treturn new RegExp(normalizedHostOrUrlRegex).test(window.location.href)\n\t\t\t}\n\n\t\t\t// Glob testing, we only support '*.somedomain.com' right now.\n\t\t\tif (host.includes('*')) {\n\t\t\t\tconst globToRegex = new RegExp(\n\t\t\t\t\tnormalizedHostOrUrlRegex.replace(/\\./g, '\\\\.').replace(/\\*/g, '.*?') + '$'\n\t\t\t\t)\n\t\t\t\treturn globToRegex.test(currentHostname) || globToRegex.test(`www.${currentHostname}`)\n\t\t\t}\n\n\t\t\t// VSCode support\n\t\t\tif (window.location.protocol === 'vscode-webview:') {\n\t\t\t\tconst currentUrl = new URL(window.location.href)\n\t\t\t\tconst extensionId = currentUrl.searchParams.get('extensionId')\n\t\t\t\tif (normalizedHostOrUrlRegex === extensionId) {\n\t\t\t\t\treturn true\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn false\n\t\t})\n\t}\n\n\tprivate isNativeLicense(licenseInfo: LicenseInfo) {\n\t\treturn this.isFlagEnabled(licenseInfo.flags, FLAGS.NATIVE_LICENSE)\n\t}\n\n\tprivate getExpirationDateWithoutGracePeriod(expiryDate: Date) {\n\t\t// The named expiry date is the last day the license is fully usable, so the license\n\t\t// expires at the end of that day, i.e. the start of the following day. We work in UTC\n\t\t// (the expiry date is minted and parsed as a UTC date-only string) so the cutoff is a\n\t\t// single predictable instant for every user regardless of their local timezone.\n\t\treturn new Date(\n\t\t\tDate.UTC(\n\t\t\t\texpiryDate.getUTCFullYear(),\n\t\t\t\texpiryDate.getUTCMonth(),\n\t\t\t\texpiryDate.getUTCDate() + 1 // Add 1 day so the named date is fully usable\n\t\t\t)\n\t\t)\n\t}\n\n\tprivate getExpirationDateWithGracePeriod(expiryDate: Date) {\n\t\treturn new Date(\n\t\t\tDate.UTC(\n\t\t\t\texpiryDate.getUTCFullYear(),\n\t\t\t\texpiryDate.getUTCMonth(),\n\t\t\t\texpiryDate.getUTCDate() + GRACE_PERIOD_DAYS + 1 // Add 1 day to include the expiration day\n\t\t\t)\n\t\t)\n\t}\n\n\tprivate isAnnualLicenseExpired(expiryDate: Date) {\n\t\tconst expiration = this.getExpirationDateWithGracePeriod(expiryDate)\n\t\treturn new Date() >= expiration\n\t}\n\n\tprivate isPerpetualLicenseExpired(expiryDate: Date) {\n\t\tconst expiration = this.getExpirationDateWithGracePeriod(expiryDate)\n\t\tconst dates = {\n\t\t\tmajor: new Date(publishDates.major),\n\t\t\tminor: new Date(publishDates.minor),\n\t\t}\n\t\t// We allow patch releases, but the major and minor releases should be within the expiration date\n\t\treturn dates.major >= expiration || dates.minor >= expiration\n\t}\n\n\tprivate getDaysSinceExpiry(expiryDate: Date): number {\n\t\tconst now = new Date()\n\t\tconst expiration = this.getExpirationDateWithoutGracePeriod(expiryDate)\n\t\tconst diffTime = now.getTime() - expiration.getTime()\n\t\tconst diffDays = Math.floor(diffTime / (1000 * 60 * 60 * 24))\n\t\treturn Math.max(0, diffDays)\n\t}\n\n\tprivate isEvaluationLicenseExpired(expiryDate: Date): boolean {\n\t\t// Evaluation licenses have no grace period - they expire immediately\n\t\tconst now = new Date()\n\t\tconst expiration = this.getExpirationDateWithoutGracePeriod(expiryDate)\n\t\treturn now >= expiration\n\t}\n\n\tprivate isFlagEnabled(flags: number, flag: number) {\n\t\treturn (flags & flag) === flag\n\t}\n\n\tprivate outputNoLicenseKeyProvided() {\n\t\t// Noop, we don't need to show this message.\n\t\t// this.outputMessages([\n\t\t// \t'No tldraw license key provided!',\n\t\t// \t`Please reach out to ${LICENSE_EMAIL} if you would like to license tldraw or if you'd like a trial.`,\n\t\t// ])\n\t}\n\n\tprivate outputInvalidLicenseKey(msg: string) {\n\t\tthis.outputMessages(['Invalid tldraw license key', `Reason: ${msg}`])\n\t}\n\n\tprivate outputLicenseInfoIfNeeded(result: ValidLicenseKeyResult) {\n\t\t// If we added a new flag it will be twice the value of the currently highest flag.\n\t\t// And if all the current flags are on we would get the `HIGHEST_FLAG * 2 - 1`, so anything higher than that means there are new flags.\n\t\tif (result.license.flags >= HIGHEST_FLAG * 2) {\n\t\t\tthis.outputMessages(\n\t\t\t\t[\n\t\t\t\t\t'Warning: This tldraw license contains some unknown flags.',\n\t\t\t\t\t'This will still work, however, you may want to update tldraw packages to a newer version to get access to new functionality.',\n\t\t\t\t],\n\t\t\t\t'warning'\n\t\t\t)\n\t\t}\n\t}\n\n\tprivate outputMessages(messages: string[], type: 'warning' | 'error' = 'error') {\n\t\tif (this.isTest) return\n\t\tif (this.verbose) {\n\t\t\tthis.outputDelimiter(type)\n\t\t\tfor (const message of messages) {\n\t\t\t\tconst bgColor = type === 'warning' ? 'orange' : 'crimson'\n\t\t\t\t// eslint-disable-next-line no-console\n\t\t\t\tconsole.log(\n\t\t\t\t\t`%c${message}`,\n\t\t\t\t\t`color: white; background: ${bgColor}; padding: 2px; border-radius: 3px;`\n\t\t\t\t)\n\t\t\t}\n\t\t\tthis.outputDelimiter(type)\n\t\t}\n\t}\n\n\tprivate outputDelimiter(type: 'warning' | 'error' = 'error') {\n\t\tconst bgColor = type === 'warning' ? 'orange' : 'crimson'\n\t\t// eslint-disable-next-line no-console\n\t\tconsole.log(\n\t\t\t'%c-------------------------------------------------------------------',\n\t\t\t`color: white; background: ${bgColor}; padding: 2px; border-radius: 3px;`\n\t\t)\n\t}\n\n\tstatic className = 'tl-watermark_SEE-LICENSE'\n}\n\n/**\n * Derives which licensable features are enabled from the parse result and the derived license\n * state. In development every feature is enabled so SDK developers can build against them; in\n * production a feature requires both an active, valid license and the corresponding flag.\n *\n * @internal\n */\nexport function getEnabledFeatures(\n\tresult: LicenseFromKeyResult,\n\tlicenseState: LicenseState,\n\tisDevelopment: boolean\n): Record<LicenseFeatureName, boolean> {\n\t// Development gets all features so SDK developers can build against them.\n\tif (isDevelopment) {\n\t\treturn { ...ALL_FEATURES }\n\t}\n\n\t// Features require an active, valid license. Both the 30-day grace-period 'licensed' state and\n\t// the watermark state count as valid; unlicensed/expired/pending do not.\n\tif (\n\t\t!result.isLicenseParseable ||\n\t\t(licenseState !== 'licensed' && licenseState !== 'licensed-with-watermark')\n\t) {\n\t\treturn { ...NO_FEATURES }\n\t}\n\n\t// Evaluation licenses get every feature so prospects can trial the whole product without us\n\t// having to mint per-feature evaluation keys. Expired evaluation licenses are already excluded\n\t// above: they resolve to the 'expired' state.\n\tif (result.isEvaluationLicense) {\n\t\treturn { ...ALL_FEATURES }\n\t}\n\n\treturn {\n\t\tcollaboration: result.isCollaborationEnabled,\n\t\tcommenting: result.isCommentingEnabled,\n\t}\n}\n\nexport function getLicenseState(\n\tresult: LicenseFromKeyResult,\n\toutputMessages: (messages: string[]) => void,\n\tisDevelopment: boolean\n): LicenseState {\n\tif (!result.isLicenseParseable) {\n\t\tif (isDevelopment) {\n\t\t\treturn 'unlicensed'\n\t\t}\n\n\t\t// All unlicensed scenarios should not work in production\n\t\tif (result.reason === 'no-key-provided') {\n\t\t\toutputMessages([\n\t\t\t\t'No tldraw license key provided!',\n\t\t\t\t'A license is required for production deployments.',\n\t\t\t\t`Please reach out to ${LICENSE_EMAIL} to purchase a license.`,\n\t\t\t])\n\t\t} else {\n\t\t\toutputMessages([\n\t\t\t\t'Invalid license key. tldraw requires a valid license for production use.',\n\t\t\t\t`Please reach out to ${LICENSE_EMAIL} to purchase a license.`,\n\t\t\t])\n\t\t}\n\t\treturn 'unlicensed-production'\n\t}\n\n\tif (!result.isDomainValid && !result.isDevelopment) {\n\t\toutputMessages([\n\t\t\t'License key is not valid for this domain.',\n\t\t\t'A license is required for production deployments.',\n\t\t\t`Please reach out to ${LICENSE_EMAIL} to purchase a license.`,\n\t\t])\n\t\treturn 'unlicensed-production'\n\t}\n\n\t// Handle evaluation licenses - they expire immediately with no grace period\n\tif (result.isEvaluationLicense) {\n\t\tif (result.isEvaluationLicenseExpired) {\n\t\t\toutputMessages([\n\t\t\t\t'Your tldraw evaluation license has expired!',\n\t\t\t\t`Please reach out to ${LICENSE_EMAIL} to purchase a full license.`,\n\t\t\t])\n\t\t\treturn 'expired'\n\t\t} else {\n\t\t\t// Valid evaluation license - tracked but no watermark shown\n\t\t\treturn 'licensed'\n\t\t}\n\t}\n\n\t// Handle expired regular licenses (both annual and perpetual)\n\tif (result.isPerpetualLicenseExpired || result.isAnnualLicenseExpired) {\n\t\toutputMessages([\n\t\t\t'Your tldraw license has been expired for more than 30 days!',\n\t\t\t`Please reach out to ${LICENSE_EMAIL} to renew your license.`,\n\t\t])\n\t\treturn 'expired'\n\t}\n\n\t// Check if license is past expiry date but within grace period\n\tconst daysSinceExpiry = result.daysSinceExpiry\n\tif (daysSinceExpiry > 0 && !result.isEvaluationLicense) {\n\t\toutputMessages([\n\t\t\t'Your tldraw license has expired.',\n\t\t\t`License expired ${daysSinceExpiry} days ago.`,\n\t\t\t`Please reach out to ${LICENSE_EMAIL} to renew your license.`,\n\t\t])\n\t\t// Within 30-day grace period: still licensed (no watermark)\n\t\treturn 'licensed'\n\t}\n\n\t// License is valid, determine if it has watermark\n\tif (result.isLicensedWithWatermark) {\n\t\treturn 'licensed-with-watermark'\n\t}\n\n\treturn 'licensed'\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA+B;AAC/B,qBAAsC;AACtC,oBAAqC;AACrC,uBAAwC;AAExC,MAAM,oBAAoB;AAEnB,MAAM,QAAQ;AAAA;AAAA;AAAA,EAGpB,gBAAgB;AAAA;AAAA,EAEhB,mBAAmB,KAAK;AAAA;AAAA;AAAA,EAIxB,kBAAkB,KAAK;AAAA;AAAA,EAEvB,gBAAgB,KAAK;AAAA;AAAA,EAErB,oBAAoB,KAAK;AAAA;AAAA;AAAA,EAGzB,gBAAgB,KAAK;AAAA;AAAA;AAAA,EAIrB,oBAAoB,KAAK;AAAA;AAAA,EAEzB,iBAAiB,KAAK;AACvB;AACA,MAAM,eAAe,KAAK,IAAI,GAAG,OAAO,OAAO,KAAK,CAAC;AAE9C,MAAM,aAAa;AAAA,EACzB,IAAI;AAAA,EACJ,OAAO;AAAA,EACP,OAAO;AAAA,EACP,aAAa;AACd;AACA,MAAM,6BAA6B,OAAO,KAA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AqB;AAC/B,WAAO,EAAE,GAAG,aAAa;AAAA,EAC1B;AAEA,SAAO;AAAA,IACN,eAAe,OAAO;AAAA,IACtB,YAAY,OAAO;AAAA,EACpB;AACD;AAEO,SAAS,gBACf,QACA,gBACA,eACe;AACf,MAAI,CAAC,OAAO,oBAAoB;AAC/B,QAAI,eAAe;AAClB,aAAO;AAAA,IACR;AAGA,QAAI,OAAO,WAAW,mBAAmB;AACxC,qBAAe;AAAA,QACd;AAAA,QACA;AAAA,QACA,uBAAuB,aAAa;AAAA,MACrC,CAAC;AAAA,IACF,OAAO;AACN,qBAAe;AAAA,QACd;AAAA,QACA,uBAAuB,aAAa;AAAA,MACrC,CAAC;AAAA,IACF;AACA,WAAO;AAAA,EACR;AAEA,MAAI,CAAC,OAAO,iBAAiB,CAAC,OAAO,eAAe;AACnD,mBAAe;AAAA,MACd;AAAA,MACA;AAAA,MACA,uBAAuB,aAAa;AAAA,IACrC,CAAC;AACD,WAAO;AAAA,EACR;AAGA,MAAI,OAAO,qBAAqB;AAC/B,QAAI,OAAO,4BAA4B;AACtC,qBAAe;AAAA,QACd;AAAA,QACA,uBAAuB,aAAa;AAAA,MACrC,CAAC;AACD,aAAO;AAAA,IACR,OAAO;AAEN,aAAO;AAAA,IACR;AAAA,EACD;AAGA,MAAI,OAAO,6BAA6B,OAAO,wBAAwB;AACtE,mBAAe;AAAA,MACd;AAAA,MACA,uBAAuB,aAAa;AAAA,IACrC,CAAC;AACD,WAAO;AAAA,EACR;AAGA,QAAM,kBAAkB,OAAO;AAC/B,MAAI,kBAAkB,KAAK,CAAC,OAAO,qBAAqB;AACvD,mBAAe;AAAA,MACd;AAAA,MACA,mBAAmB,eAAe;AAAA,MAClC,uBAAuB,aAAa;AAAA,IACrC,CAAC;AAED,WAAO;AAAA,EACR;AAGA,MAAI,OAAO,yBAAyB;AACnC,WAAO;AAAA,EACR;AAEA,SAAO;AACR;",
4
+ "sourcesContent": ["import { atom, transact } from '@tldraw/state'\nimport { noop } from '@tldraw/utils'\nimport { publishDates, version } from '../../version'\nimport { getDefaultCdnBaseUrl } from '../utils/assets'\nimport { importPublicKey, str2ab } from '../utils/licensing'\n\nconst GRACE_PERIOD_DAYS = 30\n\nexport const FLAGS = {\n\t// -- MUTUALLY EXCLUSIVE FLAGS\n\t// Annual means the license expires after a time period, usually 1 year.\n\tANNUAL_LICENSE: 1,\n\t// Perpetual means the license never expires up to the max supported version.\n\tPERPETUAL_LICENSE: 1 << 1,\n\n\t// -- ADDITIVE FLAGS --\n\t// Internal means the license is for internal use only.\n\tINTERNAL_LICENSE: 1 << 2,\n\t// Watermark means the product is watermarked.\n\tWITH_WATERMARK: 1 << 3,\n\t// Evaluation means the license is for evaluation purposes only.\n\tEVALUATION_LICENSE: 1 << 4,\n\t// Native means the license is for native apps which switches\n\t// on special-case logic.\n\tNATIVE_LICENSE: 1 << 5,\n\n\t// -- FEATURE FLAGS --\n\t// Collaboration is the umbrella flag for collaboration features; it grants all sub-features.\n\tFEAT_COLLABORATION: 1 << 6,\n\t// Commenting is the first sub-feature of collaboration.\n\tFEAT_COMMENTING: 1 << 7,\n}\nconst HIGHEST_FLAG = Math.max(...Object.values(FLAGS))\n\nexport const PROPERTIES = {\n\tID: 0,\n\tHOSTS: 1,\n\tFLAGS: 2,\n\tEXPIRY_DATE: 3,\n}\nconst NUMBER_OF_KNOWN_PROPERTIES = Object.keys(PROPERTIES).length\n\nconst LICENSE_EMAIL = 'sales@tldraw.com'\n\nconst WATERMARK_TRACK_SRC = `${getDefaultCdnBaseUrl()}/watermarks/watermark-track.svg`\n\n/** @internal */\nexport interface LicenseInfo {\n\tid: string\n\thosts: string[]\n\tflags: number\n\texpiryDate: string\n}\n\n/**\n * Names of the licensable product features gated by the license. `collaboration` is an umbrella\n * that also grants all of its sub-features (currently just `commenting`).\n *\n * @internal\n */\nexport type LicenseFeatureName = 'collaboration' | 'commenting'\n\nconst NO_FEATURES: Readonly<Record<LicenseFeatureName, boolean>> = {\n\tcollaboration: false,\n\tcommenting: false,\n}\nconst ALL_FEATURES: Readonly<Record<LicenseFeatureName, boolean>> = {\n\tcollaboration: true,\n\tcommenting: true,\n}\n\n/** @internal */\nexport type LicenseState =\n\t| 'pending' // License validation is in progress\n\t| 'licensed' // License is valid and active (no restrictions)\n\t| 'licensed-with-watermark' // License is valid but shows watermark (evaluation licenses, WITH_WATERMARK licenses)\n\t| 'unlicensed' // No valid license found or license is invalid (development)\n\t| 'unlicensed-production' // No valid license in production deployment (missing, invalid, or wrong domain)\n\t| 'expired' // License has been expired (30 days past expiration for regular licenses, immediately for evaluation licenses)\n/** @internal */\nexport type InvalidLicenseReason =\n\t| 'invalid-license-key'\n\t| 'no-key-provided'\n\t| 'has-key-development-mode'\n\n/** @internal */\nexport type LicenseFromKeyResult = InvalidLicenseKeyResult | ValidLicenseKeyResult\n\n/** @internal */\nexport interface InvalidLicenseKeyResult {\n\tisLicenseParseable: false\n\treason: InvalidLicenseReason\n}\n\n/** @internal */\nexport interface ValidLicenseKeyResult {\n\tisLicenseParseable: true\n\tlicense: LicenseInfo\n\tisDevelopment: boolean\n\tisDomainValid: boolean\n\texpiryDate: Date\n\tisAnnualLicense: boolean\n\tisAnnualLicenseExpired: boolean\n\tisPerpetualLicense: boolean\n\tisPerpetualLicenseExpired: boolean\n\tisInternalLicense: boolean\n\tisNativeLicense: boolean\n\tisLicensedWithWatermark: boolean\n\tisEvaluationLicense: boolean\n\tisEvaluationLicenseExpired: boolean\n\tisCollaborationEnabled: boolean\n\tisCommentingEnabled: boolean\n\tdaysSinceExpiry: number\n}\n\n/** @internal */\nexport type TrackType = 'unlicensed' | 'with_watermark' | 'evaluation' | null\n\n/** @internal */\nexport class LicenseManager {\n\tprivate publicKey =\n\t\t'MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEHJh0uUfxHtCGyerXmmatE368Hd9rI6LH9oPDQihnaCryRFWEVeOvf9U/SPbyxX74LFyJs5tYeAHq5Nc0Ax25LQ'\n\tpublic isDevelopment: boolean\n\tpublic isTest: boolean\n\tpublic isCryptoAvailable: boolean\n\tstate = atom<LicenseState>('license state', 'pending')\n\tfeatureFlags = atom<Record<LicenseFeatureName, boolean>>('license feature flags', {\n\t\t...NO_FEATURES,\n\t})\n\tpublic verbose = true\n\tprivate isDisposed = false\n\n\tconstructor(licenseKey: string | undefined, testPublicKey?: string) {\n\t\tthis.isTest = process.env.NODE_ENV === 'test'\n\t\tthis.isDevelopment = this.getIsDevelopment()\n\t\tthis.publicKey = testPublicKey || this.publicKey\n\t\tthis.isCryptoAvailable = !!crypto.subtle\n\n\t\t// In development every feature is enabled (see `getEnabledFeatures`), and that doesn't depend\n\t\t// on the async validation result. Reflect it eagerly so features aren't reported as disabled\n\t\t// during the validation window \u2014 or left disabled if validation rejects (the `.catch` below\n\t\t// never sets `featureFlags`). In production the fail-closed default stands until validation.\n\t\tif (this.isDevelopment) {\n\t\t\tthis.featureFlags.set({ ...ALL_FEATURES })\n\t\t}\n\n\t\tthis.getLicenseFromKey(licenseKey)\n\t\t\t.then((result) => {\n\t\t\t\t// replaced by a manager for a newer key: this one's messages, tracking ping and state\n\t\t\t\t// would describe a key the app no longer uses\n\t\t\t\tif (this.isDisposed) return\n\t\t\t\tconst licenseState = getLicenseState(\n\t\t\t\t\tresult,\n\t\t\t\t\t(messages: string[]) => this.outputMessages(messages),\n\t\t\t\t\tthis.isDevelopment\n\t\t\t\t)\n\n\t\t\t\tthis.maybeTrack(result, licenseState)\n\n\t\t\t\t// Update both atoms atomically so dependents never observe the license state and the\n\t\t\t\t// feature flags out of sync mid-update.\n\t\t\t\ttransact(() => {\n\t\t\t\t\tthis.state.set(licenseState)\n\t\t\t\t\tthis.featureFlags.set(getEnabledFeatures(result, licenseState, this.isDevelopment))\n\t\t\t\t})\n\t\t\t})\n\t\t\t.catch((error) => {\n\t\t\t\tif (this.isDisposed) return\n\t\t\t\tconsole.error('License validation failed:', error)\n\t\t\t\tthis.state.set('unlicensed')\n\t\t\t})\n\t}\n\n\t/** Ignore the pending validation: nothing is logged, tracked or set once the manager is replaced. */\n\tdispose() {\n\t\tthis.isDisposed = true\n\t}\n\n\t/**\n\t * Returns whether a given licensable feature is enabled. Reactive: reading this inside a signal\n\t * recomputes when license validation resolves.\n\t */\n\tisFeatureEnabled(feature: LicenseFeatureName): boolean {\n\t\treturn this.featureFlags.get()[feature]\n\t}\n\n\tprivate getIsDevelopment() {\n\t\tconst protocol = window.location.protocol\n\t\tconst hostname = window.location.hostname\n\n\t\t// Tauri uses `tauri://localhost` on macOS and Linux and `http://tauri.localhost` on Windows.\n\t\tif (hostname.toLowerCase().endsWith('.localhost')) {\n\t\t\treturn process.env.NODE_ENV !== 'production'\n\t\t}\n\n\t\treturn (\n\t\t\tprotocol === 'http:' ||\n\t\t\t(protocol === 'https:' && this.isLoopbackHost(hostname)) ||\n\t\t\tprocess.env.NODE_ENV !== 'production'\n\t\t)\n\t}\n\n\tprivate isLoopbackHost(hostname: string) {\n\t\t// localhost, IPv4 loopback (127.0.0.0/8) and IPv6 loopback (::1) are all local development hosts\n\t\tconst host = hostname.toLowerCase().replace(/^\\[|\\]$/g, '')\n\t\treturn host === 'localhost' || host === '::1' || /^127(?:\\.\\d{1,3}){3}$/.test(host)\n\t}\n\n\tprivate getTrackType(result: LicenseFromKeyResult, licenseState: LicenseState): TrackType {\n\t\t// Track watermark for unlicensed production deployments\n\t\tif (licenseState === 'unlicensed-production') {\n\t\t\treturn 'unlicensed'\n\t\t}\n\n\t\tif (this.isDevelopment) {\n\t\t\treturn null\n\t\t}\n\n\t\tif (!result.isLicenseParseable) {\n\t\t\treturn null\n\t\t}\n\n\t\t// Track evaluation licenses (for analytics, even though no watermark is shown)\n\t\tif (result.isEvaluationLicense) {\n\t\t\treturn 'evaluation'\n\t\t}\n\n\t\t// Track licenses that show watermarks\n\t\tif (licenseState === 'licensed-with-watermark') {\n\t\t\treturn 'with_watermark'\n\t\t}\n\n\t\treturn null\n\t}\n\n\tprivate maybeTrack(result: LicenseFromKeyResult, licenseState: LicenseState): void {\n\t\tconst trackType = this.getTrackType(result, licenseState)\n\t\tif (!trackType) {\n\t\t\treturn\n\t\t}\n\n\t\tconst url = new URL(WATERMARK_TRACK_SRC)\n\t\turl.searchParams.set('version', version)\n\t\turl.searchParams.set('license_type', trackType)\n\t\tif ('license' in result) {\n\t\t\turl.searchParams.set('license_id', result.license.id)\n\t\t\tconst sku = this.isFlagEnabled(result.license.flags, FLAGS.EVALUATION_LICENSE)\n\t\t\t\t? 'evaluation'\n\t\t\t\t: this.isFlagEnabled(result.license.flags, FLAGS.ANNUAL_LICENSE)\n\t\t\t\t\t? 'annual'\n\t\t\t\t\t: this.isFlagEnabled(result.license.flags, FLAGS.PERPETUAL_LICENSE)\n\t\t\t\t\t\t? 'perpetual'\n\t\t\t\t\t\t: 'unknown'\n\t\t\turl.searchParams.set('sku', sku)\n\t\t}\n\t\turl.searchParams.set('url', window.location.href)\n\t\tif (process.env.NODE_ENV) {\n\t\t\turl.searchParams.set('environment', process.env.NODE_ENV)\n\t\t}\n\n\t\t// best-effort: a blocked or offline request must not surface as an unhandled rejection\n\t\t// eslint-disable-next-line no-restricted-globals\n\t\tfetch(url.toString()).catch(noop)\n\t}\n\n\tprivate async extractLicenseKey(licenseKey: string): Promise<LicenseInfo> {\n\t\tconst [data, signature] = licenseKey.split('.')\n\t\tconst [prefix, encodedData] = data.split('/')\n\n\t\tif (!prefix.startsWith('tldraw-')) {\n\t\t\tthrow new Error(`Unsupported prefix '${prefix}'`)\n\t\t}\n\n\t\tconst publicCryptoKey = await importPublicKey(this.publicKey)\n\n\t\tlet isVerified\n\t\ttry {\n\t\t\tisVerified = await crypto.subtle.verify(\n\t\t\t\t{\n\t\t\t\t\tname: 'ECDSA',\n\t\t\t\t\thash: { name: 'SHA-256' },\n\t\t\t\t},\n\t\t\t\tpublicCryptoKey,\n\t\t\t\tnew Uint8Array(str2ab(atob(signature))),\n\t\t\t\tnew Uint8Array(str2ab(atob(encodedData)))\n\t\t\t)\n\t\t} catch (e) {\n\t\t\tconsole.error(e)\n\t\t\tthrow new Error('Could not perform signature validation')\n\t\t}\n\n\t\tif (!isVerified) {\n\t\t\tthrow new Error('Invalid signature')\n\t\t}\n\n\t\tlet decodedData: any\n\t\ttry {\n\t\t\tdecodedData = JSON.parse(atob(encodedData))\n\t\t} catch {\n\t\t\tthrow new Error('Could not parse object')\n\t\t}\n\t\tif (decodedData.length > NUMBER_OF_KNOWN_PROPERTIES) {\n\t\t\tthis.outputMessages([\n\t\t\t\t'License key contains some unknown properties.',\n\t\t\t\t'You may want to update tldraw packages to a newer version to get access to new functionality.',\n\t\t\t])\n\t\t}\n\n\t\treturn {\n\t\t\tid: decodedData[PROPERTIES.ID],\n\t\t\thosts: decodedData[PROPERTIES.HOSTS],\n\t\t\tflags: decodedData[PROPERTIES.FLAGS],\n\t\t\texpiryDate: decodedData[PROPERTIES.EXPIRY_DATE],\n\t\t}\n\t}\n\n\tasync getLicenseFromKey(licenseKey?: string): Promise<LicenseFromKeyResult> {\n\t\tif (!licenseKey) {\n\t\t\tif (!this.isDevelopment) {\n\t\t\t\tthis.outputNoLicenseKeyProvided()\n\t\t\t}\n\n\t\t\treturn { isLicenseParseable: false, reason: 'no-key-provided' }\n\t\t}\n\n\t\tif (this.isDevelopment && !this.isCryptoAvailable) {\n\t\t\tif (this.verbose) {\n\t\t\t\t// eslint-disable-next-line no-console\n\t\t\t\tconsole.log(\n\t\t\t\t\t'tldraw: you seem to be in a development environment that does not support crypto. License not verified.'\n\t\t\t\t)\n\t\t\t\t// eslint-disable-next-line no-console\n\t\t\t\tconsole.log('You should check that this works in production separately.')\n\t\t\t}\n\t\t\t// We can't parse the license if we are in development mode since crypto\n\t\t\t// is not available on http\n\t\t\treturn { isLicenseParseable: false, reason: 'has-key-development-mode' }\n\t\t}\n\n\t\t// Borrowed idea from AG Grid:\n\t\t// Copying from various sources (like PDFs) can include zero-width characters.\n\t\t// This helps makes sure the key validation doesn't fail.\n\t\tlet cleanedLicenseKey = licenseKey.replace(/[\\u200B-\\u200D\\uFEFF]/g, '')\n\t\tcleanedLicenseKey = cleanedLicenseKey.replace(/\\r?\\n|\\r/g, '')\n\n\t\ttry {\n\t\t\tconst licenseInfo = await this.extractLicenseKey(cleanedLicenseKey)\n\t\t\tconst expiryDate = new Date(licenseInfo.expiryDate)\n\t\t\tconst isAnnualLicense = this.isFlagEnabled(licenseInfo.flags, FLAGS.ANNUAL_LICENSE)\n\t\t\tconst isPerpetualLicense = this.isFlagEnabled(licenseInfo.flags, FLAGS.PERPETUAL_LICENSE)\n\t\t\tconst isEvaluationLicense = this.isFlagEnabled(licenseInfo.flags, FLAGS.EVALUATION_LICENSE)\n\n\t\t\tconst isAnnualLicenseExpired = isAnnualLicense && this.isAnnualLicenseExpired(expiryDate)\n\t\t\tconst isPerpetualLicenseExpired =\n\t\t\t\tisPerpetualLicense && this.isPerpetualLicenseExpired(expiryDate)\n\n\t\t\t// The collaboration umbrella grants all of its sub-features, so commenting is enabled\n\t\t\t// by either the commenting flag or the collaboration flag.\n\t\t\tconst isCollaborationEnabled = this.isFlagEnabled(licenseInfo.flags, FLAGS.FEAT_COLLABORATION)\n\t\t\tconst isCommentingEnabled =\n\t\t\t\tisCollaborationEnabled || this.isFlagEnabled(licenseInfo.flags, FLAGS.FEAT_COMMENTING)\n\n\t\t\t// For perpetual licenses, the calendar expiry date only gates access to future\n\t\t\t// major/minor releases; it does not \"expire\" the license itself. While the user\n\t\t\t// is still on a covered version we report `daysSinceExpiry` as 0 so consumers\n\t\t\t// (and the grace-period warning) don't treat them as past expiry.\n\t\t\tconst daysSinceExpiry =\n\t\t\t\tisPerpetualLicense && !isPerpetualLicenseExpired ? 0 : this.getDaysSinceExpiry(expiryDate)\n\n\t\t\tconst result: ValidLicenseKeyResult = {\n\t\t\t\tlicense: licenseInfo,\n\t\t\t\tisLicenseParseable: true,\n\t\t\t\tisDevelopment: this.isDevelopment,\n\t\t\t\tisDomainValid: this.isDomainValid(licenseInfo),\n\t\t\t\texpiryDate,\n\t\t\t\tisAnnualLicense,\n\t\t\t\tisAnnualLicenseExpired,\n\t\t\t\tisPerpetualLicense,\n\t\t\t\tisPerpetualLicenseExpired,\n\t\t\t\tisInternalLicense: this.isFlagEnabled(licenseInfo.flags, FLAGS.INTERNAL_LICENSE),\n\t\t\t\tisNativeLicense: this.isNativeLicense(licenseInfo),\n\t\t\t\tisLicensedWithWatermark: this.isFlagEnabled(licenseInfo.flags, FLAGS.WITH_WATERMARK),\n\t\t\t\tisEvaluationLicense,\n\t\t\t\tisEvaluationLicenseExpired:\n\t\t\t\t\tisEvaluationLicense && this.isEvaluationLicenseExpired(expiryDate),\n\t\t\t\tisCollaborationEnabled,\n\t\t\t\tisCommentingEnabled,\n\t\t\t\tdaysSinceExpiry,\n\t\t\t}\n\t\t\tthis.outputLicenseInfoIfNeeded(result)\n\n\t\t\treturn result\n\t\t} catch (e: any) {\n\t\t\tthis.outputInvalidLicenseKey(e.message)\n\t\t\t// If the license can't be parsed, it's invalid\n\t\t\treturn { isLicenseParseable: false, reason: 'invalid-license-key' }\n\t\t}\n\t}\n\n\tprivate isDomainValid(licenseInfo: LicenseInfo) {\n\t\tconst currentHostname = window.location.hostname.toLowerCase()\n\n\t\treturn licenseInfo.hosts.some((host) => {\n\t\t\tconst normalizedHostOrUrlRegex = host.toLowerCase().trim()\n\n\t\t\t// Allow the domain if listed and www variations, 'example.com' allows 'example.com' and 'www.example.com'\n\t\t\tif (\n\t\t\t\tnormalizedHostOrUrlRegex === currentHostname ||\n\t\t\t\t`www.${normalizedHostOrUrlRegex}` === currentHostname ||\n\t\t\t\tnormalizedHostOrUrlRegex === `www.${currentHostname}`\n\t\t\t) {\n\t\t\t\treturn true\n\t\t\t}\n\n\t\t\t// If host is '*', we allow all domains.\n\t\t\tif (host === '*') {\n\t\t\t\t// All domains allowed.\n\t\t\t\treturn true\n\t\t\t}\n\n\t\t\t// Native license support\n\t\t\t// In this case, `normalizedHost` is actually a protocol, e.g. `app-bundle:`\n\t\t\tif (this.isNativeLicense(licenseInfo)) {\n\t\t\t\treturn new RegExp(normalizedHostOrUrlRegex).test(window.location.href)\n\t\t\t}\n\n\t\t\t// Glob testing, we only support '*.somedomain.com' right now.\n\t\t\tif (host.includes('*')) {\n\t\t\t\tconst globToRegex = new RegExp(\n\t\t\t\t\tnormalizedHostOrUrlRegex.replace(/\\./g, '\\\\.').replace(/\\*/g, '.*?') + '$'\n\t\t\t\t)\n\t\t\t\treturn globToRegex.test(currentHostname) || globToRegex.test(`www.${currentHostname}`)\n\t\t\t}\n\n\t\t\t// VSCode support\n\t\t\tif (window.location.protocol === 'vscode-webview:') {\n\t\t\t\tconst currentUrl = new URL(window.location.href)\n\t\t\t\tconst extensionId = currentUrl.searchParams.get('extensionId')\n\t\t\t\tif (normalizedHostOrUrlRegex === extensionId) {\n\t\t\t\t\treturn true\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn false\n\t\t})\n\t}\n\n\tprivate isNativeLicense(licenseInfo: LicenseInfo) {\n\t\treturn this.isFlagEnabled(licenseInfo.flags, FLAGS.NATIVE_LICENSE)\n\t}\n\n\tprivate getExpirationDateWithoutGracePeriod(expiryDate: Date) {\n\t\t// The named expiry date is the last day the license is fully usable, so the license\n\t\t// expires at the end of that day, i.e. the start of the following day. We work in UTC\n\t\t// (the expiry date is minted and parsed as a UTC date-only string) so the cutoff is a\n\t\t// single predictable instant for every user regardless of their local timezone.\n\t\treturn new Date(\n\t\t\tDate.UTC(\n\t\t\t\texpiryDate.getUTCFullYear(),\n\t\t\t\texpiryDate.getUTCMonth(),\n\t\t\t\texpiryDate.getUTCDate() + 1 // Add 1 day so the named date is fully usable\n\t\t\t)\n\t\t)\n\t}\n\n\tprivate getExpirationDateWithGracePeriod(expiryDate: Date) {\n\t\treturn new Date(\n\t\t\tDate.UTC(\n\t\t\t\texpiryDate.getUTCFullYear(),\n\t\t\t\texpiryDate.getUTCMonth(),\n\t\t\t\texpiryDate.getUTCDate() + GRACE_PERIOD_DAYS + 1 // Add 1 day to include the expiration day\n\t\t\t)\n\t\t)\n\t}\n\n\tprivate isAnnualLicenseExpired(expiryDate: Date) {\n\t\tconst expiration = this.getExpirationDateWithGracePeriod(expiryDate)\n\t\treturn new Date() >= expiration\n\t}\n\n\tprivate isPerpetualLicenseExpired(expiryDate: Date) {\n\t\tconst expiration = this.getExpirationDateWithGracePeriod(expiryDate)\n\t\tconst dates = {\n\t\t\tmajor: new Date(publishDates.major),\n\t\t\tminor: new Date(publishDates.minor),\n\t\t}\n\t\t// We allow patch releases, but the major and minor releases should be within the expiration date\n\t\treturn dates.major >= expiration || dates.minor >= expiration\n\t}\n\n\tprivate getDaysSinceExpiry(expiryDate: Date): number {\n\t\tconst now = new Date()\n\t\tconst expiration = this.getExpirationDateWithoutGracePeriod(expiryDate)\n\t\tconst diffTime = now.getTime() - expiration.getTime()\n\t\tconst diffDays = Math.floor(diffTime / (1000 * 60 * 60 * 24))\n\t\treturn Math.max(0, diffDays)\n\t}\n\n\tprivate isEvaluationLicenseExpired(expiryDate: Date): boolean {\n\t\t// Evaluation licenses have no grace period - they expire immediately\n\t\tconst now = new Date()\n\t\tconst expiration = this.getExpirationDateWithoutGracePeriod(expiryDate)\n\t\treturn now >= expiration\n\t}\n\n\tprivate isFlagEnabled(flags: number, flag: number) {\n\t\treturn (flags & flag) === flag\n\t}\n\n\tprivate outputNoLicenseKeyProvided() {\n\t\t// Noop, we don't need to show this message.\n\t\t// this.outputMessages([\n\t\t// \t'No tldraw license key provided!',\n\t\t// \t`Please reach out to ${LICENSE_EMAIL} if you would like to license tldraw or if you'd like a trial.`,\n\t\t// ])\n\t}\n\n\tprivate outputInvalidLicenseKey(msg: string) {\n\t\tthis.outputMessages(['Invalid tldraw license key', `Reason: ${msg}`])\n\t}\n\n\tprivate outputLicenseInfoIfNeeded(result: ValidLicenseKeyResult) {\n\t\t// If we added a new flag it will be twice the value of the currently highest flag.\n\t\t// And if all the current flags are on we would get the `HIGHEST_FLAG * 2 - 1`, so anything higher than that means there are new flags.\n\t\tif (result.license.flags >= HIGHEST_FLAG * 2) {\n\t\t\tthis.outputMessages(\n\t\t\t\t[\n\t\t\t\t\t'Warning: This tldraw license contains some unknown flags.',\n\t\t\t\t\t'This will still work, however, you may want to update tldraw packages to a newer version to get access to new functionality.',\n\t\t\t\t],\n\t\t\t\t'warning'\n\t\t\t)\n\t\t}\n\t}\n\n\tprivate outputMessages(messages: string[], type: 'warning' | 'error' = 'error') {\n\t\tif (this.isTest) return\n\t\tif (this.verbose) {\n\t\t\tthis.outputDelimiter(type)\n\t\t\tfor (const message of messages) {\n\t\t\t\tconst bgColor = type === 'warning' ? 'orange' : 'crimson'\n\t\t\t\t// eslint-disable-next-line no-console\n\t\t\t\tconsole.log(\n\t\t\t\t\t`%c${message}`,\n\t\t\t\t\t`color: white; background: ${bgColor}; padding: 2px; border-radius: 3px;`\n\t\t\t\t)\n\t\t\t}\n\t\t\tthis.outputDelimiter(type)\n\t\t}\n\t}\n\n\tprivate outputDelimiter(type: 'warning' | 'error' = 'error') {\n\t\tconst bgColor = type === 'warning' ? 'orange' : 'crimson'\n\t\t// eslint-disable-next-line no-console\n\t\tconsole.log(\n\t\t\t'%c-------------------------------------------------------------------',\n\t\t\t`color: white; background: ${bgColor}; padding: 2px; border-radius: 3px;`\n\t\t)\n\t}\n\n\tstatic className = 'tl-watermark_SEE-LICENSE'\n}\n\n/**\n * Derives which licensable features are enabled from the parse result and the derived license\n * state. In development every feature is enabled so SDK developers can build against them; in\n * production a feature requires both an active, valid license and the corresponding flag.\n *\n * @internal\n */\nexport function getEnabledFeatures(\n\tresult: LicenseFromKeyResult,\n\tlicenseState: LicenseState,\n\tisDevelopment: boolean\n): Record<LicenseFeatureName, boolean> {\n\t// Development gets all features so SDK developers can build against them.\n\tif (isDevelopment) {\n\t\treturn { ...ALL_FEATURES }\n\t}\n\n\t// Features require an active, valid license. Both the 30-day grace-period 'licensed' state and\n\t// the watermark state count as valid; unlicensed/expired/pending do not.\n\tif (\n\t\t!result.isLicenseParseable ||\n\t\t(licenseState !== 'licensed' && licenseState !== 'licensed-with-watermark')\n\t) {\n\t\treturn { ...NO_FEATURES }\n\t}\n\n\t// Evaluation licenses get every feature so prospects can trial the whole product without us\n\t// having to mint per-feature evaluation keys. Expired evaluation licenses are already excluded\n\t// above: they resolve to the 'expired' state.\n\tif (result.isEvaluationLicense) {\n\t\treturn { ...ALL_FEATURES }\n\t}\n\n\treturn {\n\t\tcollaboration: result.isCollaborationEnabled,\n\t\tcommenting: result.isCommentingEnabled,\n\t}\n}\n\nexport function getLicenseState(\n\tresult: LicenseFromKeyResult,\n\toutputMessages: (messages: string[]) => void,\n\tisDevelopment: boolean\n): LicenseState {\n\tif (!result.isLicenseParseable) {\n\t\tif (isDevelopment) {\n\t\t\treturn 'unlicensed'\n\t\t}\n\n\t\t// All unlicensed scenarios should not work in production\n\t\tif (result.reason === 'no-key-provided') {\n\t\t\toutputMessages([\n\t\t\t\t'No tldraw license key provided!',\n\t\t\t\t'A license is required for production deployments.',\n\t\t\t\t`Please reach out to ${LICENSE_EMAIL} to purchase a license.`,\n\t\t\t])\n\t\t} else {\n\t\t\toutputMessages([\n\t\t\t\t'Invalid license key. tldraw requires a valid license for production use.',\n\t\t\t\t`Please reach out to ${LICENSE_EMAIL} to purchase a license.`,\n\t\t\t])\n\t\t}\n\t\treturn 'unlicensed-production'\n\t}\n\n\tif (!result.isDomainValid && !result.isDevelopment) {\n\t\toutputMessages([\n\t\t\t'License key is not valid for this domain.',\n\t\t\t'A license is required for production deployments.',\n\t\t\t`Please reach out to ${LICENSE_EMAIL} to purchase a license.`,\n\t\t])\n\t\treturn 'unlicensed-production'\n\t}\n\n\t// Handle evaluation licenses - they expire immediately with no grace period\n\tif (result.isEvaluationLicense) {\n\t\tif (result.isEvaluationLicenseExpired) {\n\t\t\toutputMessages([\n\t\t\t\t'Your tldraw evaluation license has expired!',\n\t\t\t\t`Please reach out to ${LICENSE_EMAIL} to purchase a full license.`,\n\t\t\t])\n\t\t\treturn 'expired'\n\t\t} else {\n\t\t\t// Valid evaluation license - tracked but no watermark shown\n\t\t\treturn 'licensed'\n\t\t}\n\t}\n\n\t// Handle expired regular licenses (both annual and perpetual)\n\tif (result.isPerpetualLicenseExpired || result.isAnnualLicenseExpired) {\n\t\toutputMessages([\n\t\t\t'Your tldraw license has been expired for more than 30 days!',\n\t\t\t`Please reach out to ${LICENSE_EMAIL} to renew your license.`,\n\t\t])\n\t\treturn 'expired'\n\t}\n\n\t// Check if license is past expiry date but within grace period\n\tconst daysSinceExpiry = result.daysSinceExpiry\n\tif (daysSinceExpiry > 0 && !result.isEvaluationLicense) {\n\t\toutputMessages([\n\t\t\t'Your tldraw license has expired.',\n\t\t\t`License expired ${daysSinceExpiry} days ago.`,\n\t\t\t`Please reach out to ${LICENSE_EMAIL} to renew your license.`,\n\t\t])\n\t\t// Within 30-day grace period: still licensed (no watermark)\n\t\treturn 'licensed'\n\t}\n\n\t// License is valid, determine if it has watermark\n\tif (result.isLicensedWithWatermark) {\n\t\treturn 'licensed-with-watermark'\n\t}\n\n\treturn 'licensed'\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA+B;AAC/B,mBAAqB;AACrB,qBAAsC;AACtC,oBAAqC;AACrC,uBAAwC;AAExC,MAAM,oBAAoB;AAEnB,MAAM,QAAQ;AAAA;AAAA;AAAA,EAGpB,gBAAgB;AAAA;AAAA,EAEhB,mBAAmB,KAAK;AAAA;AAAA;AAAA,EAIxB,kBAAkB,KAAK;AAAA;AAAA,EAEvB,gBAAgB,KAAK;AAAA;AAAA,EAErB,oBAAoB,KAAK;AAAA;AAAA;AAAA,EAGzB,gBAAgB,KAAK;AAAA;AAAA;AAAA,EAIrB,oBAAoB,KAAK;AAAA;AAAA,EAEzB,iBAAiB,KAAK;AACvB;AACA,MAAM,eAAe,KAAK,IAAI,GAAG,OAAO,OAAO,KAAK,CAA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KAAK,CAAC,OAAO,qBAAqB;AACvD,mBAAe;AAAA,MACd;AAAA,MACA,mBAAmB,eAAe;AAAA,MAClC,uBAAuB,aAAa;AAAA,IACrC,CAAC;AAED,WAAO;AAAA,EACR;AAGA,MAAI,OAAO,yBAAyB;AACnC,WAAO;AAAA,EACR;AAEA,SAAO;AACR;",
6
6
  "names": []
7
7
  }
@@ -54,17 +54,25 @@ function LicenseProvider({
54
54
  licenseKey = getLicenseKeyFromEnv() ?? void 0,
55
55
  children
56
56
  }) {
57
- const [licenseManager] = (0, import_react.useState)(() => new import_LicenseManager.LicenseManager(licenseKey));
57
+ const licenseManager = (0, import_react.useMemo)(() => new import_LicenseManager.LicenseManager(licenseKey), [licenseKey]);
58
58
  const licenseState = (0, import_state_react.useValue)(licenseManager.state);
59
- const [showEditor, setShowEditor] = (0, import_react.useState)(true);
59
+ const [gatedManager, setGatedManager] = (0, import_react.useState)(null);
60
+ const showEditor = gatedManager !== licenseManager;
61
+ const previousManager = (0, import_react.useRef)(null);
62
+ (0, import_react.useEffect)(() => {
63
+ if (previousManager.current && previousManager.current !== licenseManager) {
64
+ previousManager.current.dispose();
65
+ }
66
+ previousManager.current = licenseManager;
67
+ }, [licenseManager]);
60
68
  (0, import_react.useEffect)(() => {
61
69
  if (shouldHideEditorAfterDelay(licenseState) && showEditor) {
62
70
  const timer = setTimeout(() => {
63
- setShowEditor(false);
71
+ setGatedManager(licenseManager);
64
72
  }, LICENSE_TIMEOUT);
65
73
  return () => clearTimeout(timer);
66
74
  }
67
- }, [licenseState, showEditor]);
75
+ }, [licenseManager, licenseState, showEditor]);
68
76
  if (shouldHideEditorAfterDelay(licenseState) && !showEditor) {
69
77
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(LicenseGate, {});
70
78
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/lib/license/LicenseProvider.tsx"],
4
- "sourcesContent": ["import { useValue } from '@tldraw/state-react'\nimport { createContext, ReactNode, useContext, useEffect, useState } from 'react'\nimport { useMaybeEditor } from '../hooks/useEditor'\nimport { LicenseManager } from './LicenseManager'\n\n/** @internal */\nexport const LicenseContext = createContext<LicenseManager | null>(null)\n\n/** @internal */\nexport function useLicenseContext(): LicenseManager {\n\tconst licenseManager = useMaybeLicenseManager()\n\tif (!licenseManager) {\n\t\tthrow new Error(\n\t\t\t'useLicenseContext must be used inside of the <Tldraw /> or <TldrawEditor /> components, or inside an <EditorProvider /> wrapping an editor created by them'\n\t\t)\n\t}\n\treturn licenseManager\n}\n\n/**\n * Returns the license manager for the current editor, or `null` if there is none. Reads the\n * license context when inside `<TldrawEditor />`, and otherwise falls back to the license manager\n * of the nearest editor, so UI mounted outside the editor tree (via `EditorProvider`) resolves the\n * same license as the editor it belongs to.\n *\n * @internal\n */\nexport function useMaybeLicenseManager(): LicenseManager | null {\n\tconst licenseManager = useContext(LicenseContext)\n\tconst editor = useMaybeEditor()\n\treturn licenseManager ?? editor?.licenseManager ?? null\n}\n\nfunction shouldHideEditorAfterDelay(licenseState: string): boolean {\n\treturn licenseState === 'expired' || licenseState === 'unlicensed-production'\n}\n\n/** @internal */\nexport const LICENSE_TIMEOUT = 5000\n\n/** @internal */\nexport function LicenseProvider({\n\tlicenseKey = getLicenseKeyFromEnv() ?? undefined,\n\tchildren,\n}: {\n\tlicenseKey?: string\n\tchildren: ReactNode\n}) {\n\tconst [licenseManager] = useState(() => new LicenseManager(licenseKey))\n\tconst licenseState = useValue(licenseManager.state)\n\tconst [showEditor, setShowEditor] = useState(true)\n\n\t// When license expires or no license in production, show for 5 seconds then hide\n\tuseEffect(() => {\n\t\tif (shouldHideEditorAfterDelay(licenseState) && showEditor) {\n\t\t\t// eslint-disable-next-line no-restricted-globals\n\t\t\tconst timer = setTimeout(() => {\n\t\t\t\tsetShowEditor(false)\n\t\t\t}, LICENSE_TIMEOUT)\n\n\t\t\treturn () => clearTimeout(timer)\n\t\t}\n\t}, [licenseState, showEditor])\n\n\t// If license is expired or no license in production and 5 seconds have passed, don't render anything (blank screen)\n\tif (shouldHideEditorAfterDelay(licenseState) && !showEditor) {\n\t\treturn <LicenseGate />\n\t}\n\n\treturn <LicenseContext.Provider value={licenseManager}>{children}</LicenseContext.Provider>\n}\n\n// Renders as a hidden div that can be detected by tests\nfunction LicenseGate() {\n\treturn <div data-testid=\"tl-license-expired\" style={{ display: 'none' }} />\n}\n\nlet envLicenseKey: string | undefined | null = undefined\nfunction getLicenseKeyFromEnv() {\n\tif (envLicenseKey !== undefined) {\n\t\treturn envLicenseKey\n\t}\n\t// it's important here that we write out the full process.env.WHATEVER expression instead of\n\t// doing something like process.env[someVariable]. This is because most bundlers do something\n\t// like a find-replace inject environment variables, and so won't pick up on dynamic ones. It\n\t// also means we can't do checks like `process.env && process.env.WHATEVER`, which is why we use\n\t// the `getEnv` try/catch approach.\n\n\t// framework-specific prefixes borrowed from the ones vercel uses, but trimmed down to just the\n\t// react-y ones: https://vercel.com/docs/environment-variables/framework-environment-variables\n\tenvLicenseKey =\n\t\tgetEnv(() => process.env.TLDRAW_LICENSE_KEY) ||\n\t\tgetEnv(() => process.env.NEXT_PUBLIC_TLDRAW_LICENSE_KEY) ||\n\t\tgetEnv(() => process.env.REACT_APP_TLDRAW_LICENSE_KEY) ||\n\t\tgetEnv(() => process.env.GATSBY_TLDRAW_LICENSE_KEY) ||\n\t\tgetEnv(() => process.env.VITE_TLDRAW_LICENSE_KEY) ||\n\t\tgetEnv(() => process.env.PUBLIC_TLDRAW_LICENSE_KEY) ||\n\t\tgetEnv(() => (import.meta as any).env.TLDRAW_LICENSE_KEY) ||\n\t\tgetEnv(() => (import.meta as any).env.NEXT_PUBLIC_TLDRAW_LICENSE_KEY) ||\n\t\tgetEnv(() => (import.meta as any).env.REACT_APP_TLDRAW_LICENSE_KEY) ||\n\t\tgetEnv(() => (import.meta as any).env.GATSBY_TLDRAW_LICENSE_KEY) ||\n\t\tgetEnv(() => (import.meta as any).env.VITE_TLDRAW_LICENSE_KEY) ||\n\t\tgetEnv(() => (import.meta as any).env.PUBLIC_TLDRAW_LICENSE_KEY) ||\n\t\tnull\n\n\treturn envLicenseKey\n}\n\nfunction getEnv(cb: () => string | undefined) {\n\ttry {\n\t\treturn cb()\n\t} catch {\n\t\treturn undefined\n\t}\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAkES;AAlET,yBAAyB;AACzB,mBAA0E;AAC1E,uBAA+B;AAC/B,4BAA+B;AAH/B;AAMO,MAAM,qBAAiB,4BAAqC,IAAI;AAGhE,SAAS,oBAAoC;AACnD,QAAM,iBAAiB,uBAAuB;AAC9C,MAAI,CAAC,gBAAgB;AACpB,UAAM,IAAI;AAAA,MACT;AAAA,IACD;AAAA,EACD;AACA,SAAO;AACR;AAUO,SAAS,yBAAgD;AAC/D,QAAM,qBAAiB,yBAAW,cAAc;AAChD,QAAM,aAAS,iCAAe;AAC9B,SAAO,kBAAkB,QAAQ,kBAAkB;AACpD;AAEA,SAAS,2BAA2B,cAA+B;AAClE,SAAO,iBAAiB,aAAa,iBAAiB;AACvD;AAGO,MAAM,kBAAkB;AAGxB,SAAS,gBAAgB;AAAA,EAC/B,aAAa,qBAAqB,KAAK;AAAA,EACvC;AACD,GAGG;AACF,QAAM,CAAC,cAAc,QAAI,uBAAS,MAAM,IAAI,qCAAe,UAAU,CAAC;AACtE,QAAM,mBAAe,6BAAS,eAAe,KAAK;AAClD,QAAM,CAAC,YAAY,aAAa,QAAI,uBAAS,IAAI;AAGjD,8BAAU,MAAM;AACf,QAAI,2BAA2B,YAAY,KAAK,YAAY;AAE3D,YAAM,QAAQ,WAAW,MAAM;AAC9B,sBAAc,KAAK;AAAA,MACpB,GAAG,eAAe;AAElB,aAAO,MAAM,aAAa,KAAK;AAAA,IAChC;AAAA,EACD,GAAG,CAAC,cAAc,UAAU,CAAC;AAG7B,MAAI,2BAA2B,YAAY,KAAK,CAAC,YAAY;AAC5D,WAAO,4CAAC,eAAY;AAAA,EACrB;AAEA,SAAO,4CAAC,eAAe,UAAf,EAAwB,OAAO,gBAAiB,UAAS;AAClE;AAGA,SAAS,cAAc;AACtB,SAAO,4CAAC,SAAI,eAAY,sBAAqB,OAAO,EAAE,SAAS,OAAO,GAAG;AAC1E;AAEA,IAAI,gBAA2C;AAC/C,SAAS,uBAAuB;AAC/B,MAAI,kBAAkB,QAAW;AAChC,WAAO;AAAA,EACR;AASA,kBACC,OAAO,MAAM,QAAQ,IAAI,kBAAkB,KAC3C,OAAO,MAAM,QAAQ,IAAI,8BAA8B,KACvD,OAAO,MAAM,QAAQ,IAAI,4BAA4B,KACrD,OAAO,MAAM,QAAQ,IAAI,yBAAyB,KAClD,OAAO,MAAM,QAAQ,IAAI,uBAAuB,KAChD,OAAO,MAAM,QAAQ,IAAI,yBAAyB,KAClD,OAAO,MAAO,YAAoB,IAAI,kBAAkB,KACxD,OAAO,MAAO,YAAoB,IAAI,8BAA8B,KACpE,OAAO,MAAO,YAAoB,IAAI,4BAA4B,KAClE,OAAO,MAAO,YAAoB,IAAI,yBAAyB,KAC/D,OAAO,MAAO,YAAoB,IAAI,uBAAuB,KAC7D,OAAO,MAAO,YAAoB,IAAI,yBAAyB,KAC/D;AAED,SAAO;AACR;AAEA,SAAS,OAAO,IAA8B;AAC7C,MAAI;AACH,WAAO,GAAG;AAAA,EACX,QAAQ;AACP,WAAO;AAAA,EACR;AACD;",
4
+ "sourcesContent": ["import { useValue } from '@tldraw/state-react'\nimport { createContext, ReactNode, useContext, useEffect, useMemo, useRef, useState } from 'react'\nimport { useMaybeEditor } from '../hooks/useEditor'\nimport { LicenseManager } from './LicenseManager'\n\n/** @internal */\nexport const LicenseContext = createContext<LicenseManager | null>(null)\n\n/** @internal */\nexport function useLicenseContext(): LicenseManager {\n\tconst licenseManager = useMaybeLicenseManager()\n\tif (!licenseManager) {\n\t\tthrow new Error(\n\t\t\t'useLicenseContext must be used inside of the <Tldraw /> or <TldrawEditor /> components, or inside an <EditorProvider /> wrapping an editor created by them'\n\t\t)\n\t}\n\treturn licenseManager\n}\n\n/**\n * Returns the license manager for the current editor, or `null` if there is none. Reads the\n * license context when inside `<TldrawEditor />`, and otherwise falls back to the license manager\n * of the nearest editor, so UI mounted outside the editor tree (via `EditorProvider`) resolves the\n * same license as the editor it belongs to.\n *\n * @internal\n */\nexport function useMaybeLicenseManager(): LicenseManager | null {\n\tconst licenseManager = useContext(LicenseContext)\n\tconst editor = useMaybeEditor()\n\treturn licenseManager ?? editor?.licenseManager ?? null\n}\n\nfunction shouldHideEditorAfterDelay(licenseState: string): boolean {\n\treturn licenseState === 'expired' || licenseState === 'unlicensed-production'\n}\n\n/** @internal */\nexport const LICENSE_TIMEOUT = 5000\n\n/** @internal */\nexport function LicenseProvider({\n\tlicenseKey = getLicenseKeyFromEnv() ?? undefined,\n\tchildren,\n}: {\n\tlicenseKey?: string\n\tchildren: ReactNode\n}) {\n\t// Keyed on the license key: the editor is recreated when the key changes, and must not be\n\t// handed a manager that validated the old key.\n\tconst licenseManager = useMemo(() => new LicenseManager(licenseKey), [licenseKey])\n\tconst licenseState = useValue(licenseManager.state)\n\t// The manager whose LICENSE_TIMEOUT elapsed; compared by identity so a new key un-gates the editor.\n\tconst [gatedManager, setGatedManager] = useState<LicenseManager | null>(null)\n\tconst showEditor = gatedManager !== licenseManager\n\n\t// Dispose only the replaced manager, never on cleanup: strict mode re-runs effects with the\n\t// same manager, and disposing it there would silence the live one.\n\tconst previousManager = useRef<LicenseManager | null>(null)\n\tuseEffect(() => {\n\t\tif (previousManager.current && previousManager.current !== licenseManager) {\n\t\t\tpreviousManager.current.dispose()\n\t\t}\n\t\tpreviousManager.current = licenseManager\n\t}, [licenseManager])\n\n\t// When license expires or no license in production, show for 5 seconds then hide\n\tuseEffect(() => {\n\t\tif (shouldHideEditorAfterDelay(licenseState) && showEditor) {\n\t\t\t// eslint-disable-next-line no-restricted-globals\n\t\t\tconst timer = setTimeout(() => {\n\t\t\t\tsetGatedManager(licenseManager)\n\t\t\t}, LICENSE_TIMEOUT)\n\n\t\t\treturn () => clearTimeout(timer)\n\t\t}\n\t}, [licenseManager, licenseState, showEditor])\n\n\t// If license is expired or no license in production and 5 seconds have passed, don't render anything (blank screen)\n\tif (shouldHideEditorAfterDelay(licenseState) && !showEditor) {\n\t\treturn <LicenseGate />\n\t}\n\n\treturn <LicenseContext.Provider value={licenseManager}>{children}</LicenseContext.Provider>\n}\n\n// Renders as a hidden div that can be detected by tests\nfunction LicenseGate() {\n\treturn <div data-testid=\"tl-license-expired\" style={{ display: 'none' }} />\n}\n\nlet envLicenseKey: string | undefined | null = undefined\nfunction getLicenseKeyFromEnv() {\n\tif (envLicenseKey !== undefined) {\n\t\treturn envLicenseKey\n\t}\n\t// it's important here that we write out the full process.env.WHATEVER expression instead of\n\t// doing something like process.env[someVariable]. This is because most bundlers do something\n\t// like a find-replace inject environment variables, and so won't pick up on dynamic ones. It\n\t// also means we can't do checks like `process.env && process.env.WHATEVER`, which is why we use\n\t// the `getEnv` try/catch approach.\n\n\t// framework-specific prefixes borrowed from the ones vercel uses, but trimmed down to just the\n\t// react-y ones: https://vercel.com/docs/environment-variables/framework-environment-variables\n\tenvLicenseKey =\n\t\tgetEnv(() => process.env.TLDRAW_LICENSE_KEY) ||\n\t\tgetEnv(() => process.env.NEXT_PUBLIC_TLDRAW_LICENSE_KEY) ||\n\t\tgetEnv(() => process.env.REACT_APP_TLDRAW_LICENSE_KEY) ||\n\t\tgetEnv(() => process.env.GATSBY_TLDRAW_LICENSE_KEY) ||\n\t\tgetEnv(() => process.env.VITE_TLDRAW_LICENSE_KEY) ||\n\t\tgetEnv(() => process.env.PUBLIC_TLDRAW_LICENSE_KEY) ||\n\t\tgetEnv(() => (import.meta as any).env.TLDRAW_LICENSE_KEY) ||\n\t\tgetEnv(() => (import.meta as any).env.NEXT_PUBLIC_TLDRAW_LICENSE_KEY) ||\n\t\tgetEnv(() => (import.meta as any).env.REACT_APP_TLDRAW_LICENSE_KEY) ||\n\t\tgetEnv(() => (import.meta as any).env.GATSBY_TLDRAW_LICENSE_KEY) ||\n\t\tgetEnv(() => (import.meta as any).env.VITE_TLDRAW_LICENSE_KEY) ||\n\t\tgetEnv(() => (import.meta as any).env.PUBLIC_TLDRAW_LICENSE_KEY) ||\n\t\tnull\n\n\treturn envLicenseKey\n}\n\nfunction getEnv(cb: () => string | undefined) {\n\ttry {\n\t\treturn cb()\n\t} catch {\n\t\treturn undefined\n\t}\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAgFS;AAhFT,yBAAyB;AACzB,mBAA2F;AAC3F,uBAA+B;AAC/B,4BAA+B;AAH/B;AAMO,MAAM,qBAAiB,4BAAqC,IAAI;AAGhE,SAAS,oBAAoC;AACnD,QAAM,iBAAiB,uBAAuB;AAC9C,MAAI,CAAC,gBAAgB;AACpB,UAAM,IAAI;AAAA,MACT;AAAA,IACD;AAAA,EACD;AACA,SAAO;AACR;AAUO,SAAS,yBAAgD;AAC/D,QAAM,qBAAiB,yBAAW,cAAc;AAChD,QAAM,aAAS,iCAAe;AAC9B,SAAO,kBAAkB,QAAQ,kBAAkB;AACpD;AAEA,SAAS,2BAA2B,cAA+B;AAClE,SAAO,iBAAiB,aAAa,iBAAiB;AACvD;AAGO,MAAM,kBAAkB;AAGxB,SAAS,gBAAgB;AAAA,EAC/B,aAAa,qBAAqB,KAAK;AAAA,EACvC;AACD,GAGG;AAGF,QAAM,qBAAiB,sBAAQ,MAAM,IAAI,qCAAe,UAAU,GAAG,CAAC,UAAU,CAAC;AACjF,QAAM,mBAAe,6BAAS,eAAe,KAAK;AAElD,QAAM,CAAC,cAAc,eAAe,QAAI,uBAAgC,IAAI;AAC5E,QAAM,aAAa,iBAAiB;AAIpC,QAAM,sBAAkB,qBAA8B,IAAI;AAC1D,8BAAU,MAAM;AACf,QAAI,gBAAgB,WAAW,gBA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H,WAAO,GAAG;AAAA,EACX,QAAQ;AACP,WAAO;AAAA,EACR;AACD;",
6
6
  "names": []
7
7
  }
@@ -57,12 +57,6 @@ const debugFlags = {
57
57
  throwToBlob: createDebugValue("throwToBlob", {
58
58
  defaults: { all: false }
59
59
  }),
60
- reconnectOnPing: createDebugValue("reconnectOnPing", {
61
- defaults: { all: false }
62
- }),
63
- debugCursors: createDebugValue("debugCursors", {
64
- defaults: { all: false }
65
- }),
66
60
  forceSrgb: createDebugValue("forceSrgbColors", { defaults: { all: false } }),
67
61
  debugGeometry: createDebugValue("debugGeometry", { defaults: { all: false } }),
68
62
  hideShapes: createDebugValue("hideShapes", { defaults: { all: false } }),
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/lib/utils/debug-flags.ts"],
4
- "sourcesContent": ["import { Atom, atom, react } from '@tldraw/state'\nimport { deleteFromSessionStorage, getFromSessionStorage, setInSessionStorage } from '@tldraw/utils'\n\n// --- 1. DEFINE ---\n//\n// Define your debug values and feature flags here. Use `createDebugValue` to\n// create an arbitrary value with defaults for production, staging, and\n// development. Use `createFeatureFlag` to create a boolean flag which will be\n// `true` by default in development and staging, and `false` in production.\n/** @internal */\nexport const featureFlags: Record<string, DebugFlag<boolean>> = {}\n\n/** @internal */\nexport const pointerCaptureTrackingObject = createDebugValue(\n\t'pointerCaptureTrackingObject',\n\t// ideally we wouldn't store this mutable value in an atom but it's not\n\t// a big deal for debug values\n\t{\n\t\tdefaults: { all: new Map<Element, number>() },\n\t\tshouldStoreForSession: false,\n\t}\n)\n\n/** @internal */\nexport const debugFlags = {\n\t// --- DEBUG VALUES ---\n\tlogPreventDefaults: createDebugValue('logPreventDefaults', {\n\t\tdefaults: { all: false },\n\t}),\n\tlogPointerCaptures: createDebugValue('logPointerCaptures', {\n\t\tdefaults: { all: false },\n\t}),\n\tlogElementRemoves: createDebugValue('logElementRemoves', {\n\t\tdefaults: { all: false },\n\t}),\n\tdebugSvg: createDebugValue('debugSvg', {\n\t\tdefaults: { all: false },\n\t}),\n\tshowFps: createDebugValue('showFps', {\n\t\tdefaults: { all: false },\n\t}),\n\tmeasurePerformance: createDebugValue('measurePerformance', { defaults: { all: false } }),\n\tthrowToBlob: createDebugValue('throwToBlob', {\n\t\tdefaults: { all: false },\n\t}),\n\treconnectOnPing: createDebugValue('reconnectOnPing', {\n\t\tdefaults: { all: false },\n\t}),\n\tdebugCursors: createDebugValue('debugCursors', {\n\t\tdefaults: { all: false },\n\t}),\n\tforceSrgb: createDebugValue('forceSrgbColors', { defaults: { all: false } }),\n\tdebugGeometry: createDebugValue('debugGeometry', { defaults: { all: false } }),\n\thideShapes: createDebugValue('hideShapes', { defaults: { all: false } }),\n\teditOnType: createDebugValue('editOnType', { defaults: { all: false } }),\n\ta11y: createDebugValue('a11y', { defaults: { all: false } }),\n\tdebugElbowArrows: createDebugValue('debugElbowArrows', { defaults: { all: false } }),\n} as const\n\n// --- 2. USE ---\n// In normal code, read from debug flags directly by calling .value on them:\n// if (debugFlags.preventDefaultLogging.value) { ... }\n//\n// In react, wrap your reads in `useValue` (or your component in `track`)\n// so they react to changes:\n// const shouldLog = useValue(debugFlags.preventDefaultLogging)\n\n// --- 3. GET FUNKY ---\n// If you need to do fun stuff like monkey-patching in response to flag changes,\n// add that here. Make sure you wrap your code in `react` so it runs\n// automatically when values change!\n\nif (typeof Element !== 'undefined') {\n\tconst nativeElementRemoveChild = Element.prototype.removeChild\n\treact('element removal logging', () => {\n\t\tif (debugFlags.logElementRemoves.get()) {\n\t\t\tElement.prototype.removeChild = function <T extends Node>(this: any, child: Node): T {\n\t\t\t\tconsole.warn('[tldraw] removing child:', child)\n\t\t\t\treturn nativeElementRemoveChild.call(this, child) as T\n\t\t\t}\n\t\t} else {\n\t\t\tElement.prototype.removeChild = nativeElementRemoveChild\n\t\t}\n\t})\n}\n\n// --- IMPLEMENTATION ---\n// you probably don't need to read this if you're just using the debug values system\n/** @public */\nexport function createDebugValue<T>(\n\tname: string,\n\t{\n\t\tdefaults,\n\t\tshouldStoreForSession = true,\n\t}: { defaults: DebugFlagDefaults<T>; shouldStoreForSession?: boolean }\n) {\n\treturn createDebugValueBase({\n\t\tname,\n\t\tdefaults,\n\t\tshouldStoreForSession,\n\t})\n}\n\nfunction createDebugValueBase<T>(def: DebugFlagDef<T>): DebugFlag<T> {\n\tconst defaultValue = getDefaultValue(def)\n\tconst storedValue = def.shouldStoreForSession\n\t\t? (getStoredInitialValue(def.name) as T | null)\n\t\t: null\n\tconst valueAtom = atom(`debug:${def.name}`, storedValue ?? defaultValue)\n\n\tif (typeof window !== 'undefined') {\n\t\tif (def.shouldStoreForSession) {\n\t\t\treact(`debug:${def.name}`, () => {\n\t\t\t\tconst currentValue = valueAtom.get()\n\t\t\t\tif (currentValue === defaultValue) {\n\t\t\t\t\tdeleteFromSessionStorage(`tldraw_debug:${def.name}`)\n\t\t\t\t} else {\n\t\t\t\t\tsetInSessionStorage(`tldraw_debug:${def.name}`, JSON.stringify(currentValue))\n\t\t\t\t}\n\t\t\t})\n\t\t}\n\n\t\tObject.defineProperty(window, `tldraw${def.name.replace(/^[a-z]/, (l) => l.toUpperCase())}`, {\n\t\t\tget() {\n\t\t\t\treturn valueAtom.get()\n\t\t\t},\n\t\t\tset(newValue) {\n\t\t\t\tvalueAtom.set(newValue)\n\t\t\t},\n\t\t\tconfigurable: true,\n\t\t})\n\t}\n\n\treturn Object.assign(valueAtom, def, {\n\t\treset: () => valueAtom.set(defaultValue),\n\t})\n}\n\nfunction getStoredInitialValue(name: string) {\n\ttry {\n\t\treturn JSON.parse(getFromSessionStorage(`tldraw_debug:${name}`) ?? 'null')\n\t} catch {\n\t\treturn null\n\t}\n}\n\n// process.env might not be defined, but we can't access it using optional\n// chaining because some bundlers search for `process.env.SOMETHING` as a string\n// and replace it with its value.\nfunction readEnv(fn: () => string | undefined) {\n\ttry {\n\t\treturn fn()\n\t} catch {\n\t\treturn null\n\t}\n}\n\nfunction getDefaultValue<T>(def: DebugFlagDef<T>): T {\n\tconst env =\n\t\treadEnv(() => process.env.TLDRAW_ENV) ??\n\t\treadEnv(() => process.env.VERCEL_PUBLIC_TLDRAW_ENV) ??\n\t\treadEnv(() => process.env.NEXT_PUBLIC_TLDRAW_ENV) ??\n\t\t// default to production because if we don't have one of these, this is probably a library use\n\t\t'production'\n\n\tswitch (env) {\n\t\tcase 'production':\n\t\t\treturn def.defaults.production ?? def.defaults.all\n\t\tcase 'preview':\n\t\tcase 'staging':\n\t\t\treturn def.defaults.staging ?? def.defaults.all\n\t\tdefault:\n\t\t\treturn def.defaults.development ?? def.defaults.all\n\t}\n}\n\n/** @public */\nexport interface DebugFlagDefaults<T> {\n\tdevelopment?: T\n\tstaging?: T\n\tproduction?: T\n\tall: T\n}\n\n/** @public */\nexport interface DebugFlagDef<T> {\n\tname: string\n\tdefaults: DebugFlagDefaults<T>\n\tshouldStoreForSession: boolean\n}\n\n/** @public */\nexport interface DebugFlag<T> extends DebugFlagDef<T>, Atom<T> {\n\treset(): void\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAkC;AAClC,mBAAqF;AAS9E,MAAM,eAAmD,CAAC;AAG1D,MAAM,+BAA+B;AAAA,EAC3C;AAAA;AAAA;AAAA,EAGA;AAAA,IACC,UAAU,EAAE,KAAK,oBAAI,IAAqB,EAAE;AAAA,IAC5C,uBAAuB;AAAA,EACxB;AACD;AAGO,MAAM,aAAa;AAAA;AAAA,EAEzB,oBAAoB,iBAAiB,sBAAsB;AAAA,IAC1D,UAAU,EAAE,KAAK,MAAM;AAAA,EACxB,CAAC;AAAA,EACD,oBAAoB,iBAAiB,sBAAsB;AAAA,IAC1D,UAAU,EAAE,KAAK,MAAM;AAAA,EACxB,CAAC;AAAA,EACD,mBAAmB,iBAAiB,qBAAqB;AAAA,IACxD,UAAU,EAAE,KAAK,MAAM;AAAA,EACxB,CAAC;AAAA,EACD,U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,QAAQ,IAA8B;AAC9C,MAAI;AACH,WAAO,GAAG;AAAA,EACX,QAAQ;AACP,WAAO;AAAA,EACR;AACD;AAEA,SAAS,gBAAmB,KAAyB;AACpD,QAAM,MACL,QAAQ,MAAM,QAAQ,IAAI,UAAU,KACpC,QAAQ,MAAM,QAAQ,IAAI,wBAAwB,KAClD,QAAQ,MAAM,QAAQ,IAAI,sBAAsB;AAAA,EAEhD;AAED,UAAQ,KAAK;AAAA,IACZ,KAAK;AACJ,aAAO,IAAI,SAAS,cAAc,IAAI,SAAS;AAAA,IAChD,KAAK;AAAA,IACL,KAAK;AACJ,aAAO,IAAI,SAAS,WAAW,IAAI,SAAS;AAAA,IAC7C;AACC,aAAO,IAAI,SAAS,eAAe,IAAI,SAAS;AAAA,EAClD;AACD;",
4
+ "sourcesContent": ["import { Atom, atom, react } from '@tldraw/state'\nimport { deleteFromSessionStorage, getFromSessionStorage, setInSessionStorage } from '@tldraw/utils'\n\n// --- 1. DEFINE ---\n//\n// Define your debug values and feature flags here. Use `createDebugValue` to\n// create an arbitrary value with defaults for production, staging, and\n// development. Use `createFeatureFlag` to create a boolean flag which will be\n// `true` by default in development and staging, and `false` in production.\n/** @internal */\nexport const featureFlags: Record<string, DebugFlag<boolean>> = {}\n\n/** @internal */\nexport const pointerCaptureTrackingObject = createDebugValue(\n\t'pointerCaptureTrackingObject',\n\t// ideally we wouldn't store this mutable value in an atom but it's not\n\t// a big deal for debug values\n\t{\n\t\tdefaults: { all: new Map<Element, number>() },\n\t\tshouldStoreForSession: false,\n\t}\n)\n\n/** @internal */\nexport const debugFlags = {\n\t// --- DEBUG VALUES ---\n\tlogPreventDefaults: createDebugValue('logPreventDefaults', {\n\t\tdefaults: { all: false },\n\t}),\n\tlogPointerCaptures: createDebugValue('logPointerCaptures', {\n\t\tdefaults: { all: false },\n\t}),\n\tlogElementRemoves: createDebugValue('logElementRemoves', {\n\t\tdefaults: { all: false },\n\t}),\n\tdebugSvg: createDebugValue('debugSvg', {\n\t\tdefaults: { all: false },\n\t}),\n\tshowFps: createDebugValue('showFps', {\n\t\tdefaults: { all: false },\n\t}),\n\tmeasurePerformance: createDebugValue('measurePerformance', { defaults: { all: false } }),\n\tthrowToBlob: createDebugValue('throwToBlob', {\n\t\tdefaults: { all: false },\n\t}),\n\tforceSrgb: createDebugValue('forceSrgbColors', { defaults: { all: false } }),\n\tdebugGeometry: createDebugValue('debugGeometry', { defaults: { all: false } }),\n\thideShapes: createDebugValue('hideShapes', { defaults: { all: false } }),\n\teditOnType: createDebugValue('editOnType', { defaults: { all: false } }),\n\ta11y: createDebugValue('a11y', { defaults: { all: false } }),\n\tdebugElbowArrows: createDebugValue('debugElbowArrows', { defaults: { all: false } }),\n} as const\n\n// --- 2. USE ---\n// In normal code, read from debug flags directly by calling .value on them:\n// if (debugFlags.preventDefaultLogging.value) { ... }\n//\n// In react, wrap your reads in `useValue` (or your component in `track`)\n// so they react to changes:\n// const shouldLog = useValue(debugFlags.preventDefaultLogging)\n\n// --- 3. GET FUNKY ---\n// If you need to do fun stuff like monkey-patching in response to flag changes,\n// add that here. Make sure you wrap your code in `react` so it runs\n// automatically when values change!\n\nif (typeof Element !== 'undefined') {\n\tconst nativeElementRemoveChild = Element.prototype.removeChild\n\treact('element removal logging', () => {\n\t\tif (debugFlags.logElementRemoves.get()) {\n\t\t\tElement.prototype.removeChild = function <T extends Node>(this: any, child: Node): T {\n\t\t\t\tconsole.warn('[tldraw] removing child:', child)\n\t\t\t\treturn nativeElementRemoveChild.call(this, child) as T\n\t\t\t}\n\t\t} else {\n\t\t\tElement.prototype.removeChild = nativeElementRemoveChild\n\t\t}\n\t})\n}\n\n// --- IMPLEMENTATION ---\n// you probably don't need to read this if you're just using the debug values system\n/** @public */\nexport function createDebugValue<T>(\n\tname: string,\n\t{\n\t\tdefaults,\n\t\tshouldStoreForSession = true,\n\t}: { defaults: DebugFlagDefaults<T>; shouldStoreForSession?: boolean }\n) {\n\treturn createDebugValueBase({\n\t\tname,\n\t\tdefaults,\n\t\tshouldStoreForSession,\n\t})\n}\n\nfunction createDebugValueBase<T>(def: DebugFlagDef<T>): DebugFlag<T> {\n\tconst defaultValue = getDefaultValue(def)\n\tconst storedValue = def.shouldStoreForSession\n\t\t? (getStoredInitialValue(def.name) as T | null)\n\t\t: null\n\tconst valueAtom = atom(`debug:${def.name}`, storedValue ?? defaultValue)\n\n\tif (typeof window !== 'undefined') {\n\t\tif (def.shouldStoreForSession) {\n\t\t\treact(`debug:${def.name}`, () => {\n\t\t\t\tconst currentValue = valueAtom.get()\n\t\t\t\tif (currentValue === defaultValue) {\n\t\t\t\t\tdeleteFromSessionStorage(`tldraw_debug:${def.name}`)\n\t\t\t\t} else {\n\t\t\t\t\tsetInSessionStorage(`tldraw_debug:${def.name}`, JSON.stringify(currentValue))\n\t\t\t\t}\n\t\t\t})\n\t\t}\n\n\t\tObject.defineProperty(window, `tldraw${def.name.replace(/^[a-z]/, (l) => l.toUpperCase())}`, {\n\t\t\tget() {\n\t\t\t\treturn valueAtom.get()\n\t\t\t},\n\t\t\tset(newValue) {\n\t\t\t\tvalueAtom.set(newValue)\n\t\t\t},\n\t\t\tconfigurable: true,\n\t\t})\n\t}\n\n\treturn Object.assign(valueAtom, def, {\n\t\treset: () => valueAtom.set(defaultValue),\n\t})\n}\n\nfunction getStoredInitialValue(name: string) {\n\ttry {\n\t\treturn JSON.parse(getFromSessionStorage(`tldraw_debug:${name}`) ?? 'null')\n\t} catch {\n\t\treturn null\n\t}\n}\n\n// process.env might not be defined, but we can't access it using optional\n// chaining because some bundlers search for `process.env.SOMETHING` as a string\n// and replace it with its value.\nfunction readEnv(fn: () => string | undefined) {\n\ttry {\n\t\treturn fn()\n\t} catch {\n\t\treturn null\n\t}\n}\n\nfunction getDefaultValue<T>(def: DebugFlagDef<T>): T {\n\tconst env =\n\t\treadEnv(() => process.env.TLDRAW_ENV) ??\n\t\treadEnv(() => process.env.VERCEL_PUBLIC_TLDRAW_ENV) ??\n\t\treadEnv(() => process.env.NEXT_PUBLIC_TLDRAW_ENV) ??\n\t\t// default to production because if we don't have one of these, this is probably a library use\n\t\t'production'\n\n\tswitch (env) {\n\t\tcase 'production':\n\t\t\treturn def.defaults.production ?? def.defaults.all\n\t\tcase 'preview':\n\t\tcase 'staging':\n\t\t\treturn def.defaults.staging ?? def.defaults.all\n\t\tdefault:\n\t\t\treturn def.defaults.development ?? def.defaults.all\n\t}\n}\n\n/** @public */\nexport interface DebugFlagDefaults<T> {\n\tdevelopment?: T\n\tstaging?: T\n\tproduction?: T\n\tall: T\n}\n\n/** @public */\nexport interface DebugFlagDef<T> {\n\tname: string\n\tdefaults: DebugFlagDefaults<T>\n\tshouldStoreForSession: boolean\n}\n\n/** @public */\nexport interface DebugFlag<T> extends DebugFlagDef<T>, Atom<T> {\n\treset(): void\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAkC;AAClC,mBAAqF;AAS9E,MAAM,eAAmD,CAAC;AAG1D,MAAM,+BAA+B;AAAA,EAC3C;AAAA;AAAA;AAAA,EAGA;AAAA,IACC,UAAU,EAAE,KAAK,oBAAI,IAAqB,EAAE;AAAA,IAC5C,uBAAuB;AAAA,EACxB;AACD;AAGO,MAAM,aAAa;AAAA;AAAA,EAEzB,oBAAoB,iBAAiB,sBAAsB;AAAA,IAC1D,UAAU,EAAE,KAAK,MAAM;AAAA,EACxB,CAAC;AAAA,EACD,oBAAoB,iBAAiB,sBAAsB;AAAA,IAC1D,UAAU,EAAE,KAAK,MAAM;AAAA,EACxB,CAAC;AAAA,EACD,mBAAmB,iBAAiB,qBAAqB;AAAA,IACxD,UAAU,EAAE,KAAK,MAAM;AAAA,EACxB,CAAC;AAAA,EACD,UAAU,iBAAiB,YAAY;AAAA,IACtC,UAAU,EAAE,KAAK,MAAM;AAAA,EACxB,CAAC;AAAA,EACD,SAAS,iBAAiB,WAAW;AAAA,IACpC,UAAU,EAAE,KA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IAAI,SAAS,cAAc,IAAI,SAAS;AAAA,IAChD,KAAK;AAAA,IACL,KAAK;AACJ,aAAO,IAAI,SAAS,WAAW,IAAI,SAAS;AAAA,IAC7C;AACC,aAAO,IAAI,SAAS,eAAe,IAAI,SAAS;AAAA,EAClD;AACD;",
6
6
  "names": []
7
7
  }
@@ -60,7 +60,8 @@ function parseDeepLinkString(deepLinkString) {
60
60
  case "v": {
61
61
  const [x, y, w, h, pageId] = deepLinkString.slice(1).split(".");
62
62
  const bounds = new import_Box.Box(Number(x), Number(y), Number(w), Number(h));
63
- if (![bounds.x, bounds.y, bounds.w, bounds.h].every(Number.isFinite)) {
63
+ const isUsableViewport = [bounds.x, bounds.y, bounds.w, bounds.h].every(Number.isFinite) && bounds.w > 0 && bounds.h > 0;
64
+ if (!isUsableViewport) {
64
65
  throw Error("Invalid deep link string");
65
66
  }
66
67
  return {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/lib/utils/deepLinks.ts"],
4
- "sourcesContent": ["import { BoxModel, PageRecordType, TLPageId, TLShapeId, createShapeId } from '@tldraw/tlschema'\nimport { exhaustiveSwitchError } from '@tldraw/utils'\nimport type { Editor } from '../editor/Editor'\nimport { Box } from '../primitives/Box'\n\n/** @public */\nexport type TLDeepLink =\n\t| {\n\t\t\ttype: 'shapes'\n\t\t\tshapeIds: TLShapeId[]\n\t }\n\t| { type: 'viewport'; bounds: BoxModel; pageId?: TLPageId }\n\t| { type: 'page'; pageId: TLPageId }\n\n/**\n * Converts a deep link descriptor to a url-safe string\n *\n * @example\n * ```ts\n * const url = `https://example.com?d=${createDeepLinkString({ type: 'shapes', shapeIds: ['shape:1', 'shape:2'] })}`\n * navigator.clipboard.writeText(url)\n * ```\n *\n * @param deepLink - the deep link descriptor\n * @returns a url-safe string\n *\n * @public\n */\nexport function createDeepLinkString(deepLink: TLDeepLink): string {\n\tswitch (deepLink.type) {\n\t\tcase 'shapes': {\n\t\t\tconst ids = deepLink.shapeIds.map((id) => encodeId(id.slice('shape:'.length)))\n\t\t\treturn `s${ids.join('.')}`\n\t\t}\n\t\tcase 'page': {\n\t\t\treturn 'p' + encodeId(PageRecordType.parseId(deepLink.pageId))\n\t\t}\n\t\tcase 'viewport': {\n\t\t\tconst { bounds, pageId } = deepLink\n\t\t\tlet res = `v${Math.round(bounds.x)}.${Math.round(bounds.y)}.${Math.round(bounds.w)}.${Math.round(bounds.h)}`\n\t\t\tif (pageId) {\n\t\t\t\tres += '.' + encodeId(PageRecordType.parseId(pageId))\n\t\t\t}\n\t\t\treturn res\n\t\t}\n\t\tdefault:\n\t\t\texhaustiveSwitchError(deepLink)\n\t}\n}\n\n/**\n * Parses a string created by {@link createDeepLinkString} back into a deep link descriptor.\n *\n * @param deepLinkString - the deep link string\n * @returns a deep link descriptor\n *\n * @public\n */\nexport function parseDeepLinkString(deepLinkString: string): TLDeepLink {\n\tconst type = deepLinkString[0]\n\tswitch (type) {\n\t\tcase 's': {\n\t\t\tconst shapeIds = deepLinkString\n\t\t\t\t.slice(1)\n\t\t\t\t.split('.')\n\t\t\t\t.filter(Boolean)\n\t\t\t\t.map((id) => createShapeId(decodeURIComponent(id)))\n\t\t\treturn { type: 'shapes', shapeIds }\n\t\t}\n\t\tcase 'p': {\n\t\t\tconst pageId = PageRecordType.createId(decodeURIComponent(deepLinkString.slice(1)))\n\t\t\treturn { type: 'page', pageId }\n\t\t}\n\t\tcase 'v': {\n\t\t\tconst [x, y, w, h, pageId] = deepLinkString.slice(1).split('.')\n\t\t\tconst bounds = new Box(Number(x), Number(y), Number(w), Number(h))\n\t\t\t// Number('abc') is NaN rather than an error, so without this check a malformed\n\t\t\t// viewport link would bypass the caller's fallback and park the camera at the origin\n\t\t\tif (![bounds.x, bounds.y, bounds.w, bounds.h].every(Number.isFinite)) {\n\t\t\t\tthrow Error('Invalid deep link string')\n\t\t\t}\n\t\t\treturn {\n\t\t\t\ttype: 'viewport',\n\t\t\t\tbounds,\n\t\t\t\tpageId: pageId ? PageRecordType.createId(decodeURIComponent(pageId)) : undefined,\n\t\t\t}\n\t\t}\n\t\tdefault:\n\t\t\tthrow Error('Invalid deep link string')\n\t}\n}\n\nfunction encodeId(str: string): string {\n\t// need to encode dots because they are used as separators\n\treturn encodeURIComponent(str).replace(/\\./g, '%2E')\n}\n\n/** @public */\nexport interface TLDeepLinkOptions {\n\t/**\n\t * The name of the url search param to use for the deep link.\n\t *\n\t * Defaults to `'d'`\n\t */\n\tparam?: string\n\t/**\n\t * The debounce time in ms for updating the url.\n\t */\n\tdebounceMs?: number\n\t/**\n\t * Should return the current url to augment with a deep link query parameter.\n\t * If you supply this function, you must also supply an `onChange` function.\n\t */\n\tgetUrl?(editor: Editor): string | URL\n\t/**\n\t * Should return the current deep link target.\n\t * Defaults to returning the current page and viewport position.\n\t */\n\tgetTarget?(editor: Editor): TLDeepLink\n\t/**\n\t * This is fired when the URL is updated.\n\t *\n\t * If not supplied, the default behavior is to update `window.location`.\n\t *\n\t * @param url - the updated URL\n\t */\n\tonChange?(url: URL, editor: Editor): void\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAA6E;AAC7E,mBAAsC;AAEtC,iBAAoB;AAyBb,SAAS,qBAAqB,UAA8B;AAClE,UAAQ,SAAS,MAAM;AAAA,IACtB,KAAK,UAAU;AACd,YAAM,MAAM,SAAS,SAAS,IAAI,CAAC,OAAO,SAAS,GAAG,MAAM,SAAS,MAAM,CAAC,CAAC;AAC7E,aAAO,IAAI,IAAI,KAAK,GAAG,CAAC;AAAA,IACzB;AAAA,IACA,KAAK,QAAQ;AACZ,aAAO,MAAM,SAAS,+BAAe,QAAQ,SAAS,MAAM,CAAC;AAAA,IAC9D;AAAA,IACA,KAAK,YAAY;AAChB,YAAM,EAAE,QAAQ,OAAO,IAAI;AAC3B,UAAI,MAAM,IAAI,KAAK,MAAM,OAAO,CAAC,CAAC,IAAI,KAAK,MAAM,OA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BAAmB,GAAG,EAAE,QAAQ,OAAO,KAAK;AACpD;",
4
+ "sourcesContent": ["import { BoxModel, PageRecordType, TLPageId, TLShapeId, createShapeId } from '@tldraw/tlschema'\nimport { exhaustiveSwitchError } from '@tldraw/utils'\nimport type { Editor } from '../editor/Editor'\nimport { Box } from '../primitives/Box'\n\n/** @public */\nexport type TLDeepLink =\n\t| {\n\t\t\ttype: 'shapes'\n\t\t\tshapeIds: TLShapeId[]\n\t }\n\t| { type: 'viewport'; bounds: BoxModel; pageId?: TLPageId }\n\t| { type: 'page'; pageId: TLPageId }\n\n/**\n * Converts a deep link descriptor to a url-safe string\n *\n * @example\n * ```ts\n * const url = `https://example.com?d=${createDeepLinkString({ type: 'shapes', shapeIds: ['shape:1', 'shape:2'] })}`\n * navigator.clipboard.writeText(url)\n * ```\n *\n * @param deepLink - the deep link descriptor\n * @returns a url-safe string\n *\n * @public\n */\nexport function createDeepLinkString(deepLink: TLDeepLink): string {\n\tswitch (deepLink.type) {\n\t\tcase 'shapes': {\n\t\t\tconst ids = deepLink.shapeIds.map((id) => encodeId(id.slice('shape:'.length)))\n\t\t\treturn `s${ids.join('.')}`\n\t\t}\n\t\tcase 'page': {\n\t\t\treturn 'p' + encodeId(PageRecordType.parseId(deepLink.pageId))\n\t\t}\n\t\tcase 'viewport': {\n\t\t\tconst { bounds, pageId } = deepLink\n\t\t\tlet res = `v${Math.round(bounds.x)}.${Math.round(bounds.y)}.${Math.round(bounds.w)}.${Math.round(bounds.h)}`\n\t\t\tif (pageId) {\n\t\t\t\tres += '.' + encodeId(PageRecordType.parseId(pageId))\n\t\t\t}\n\t\t\treturn res\n\t\t}\n\t\tdefault:\n\t\t\texhaustiveSwitchError(deepLink)\n\t}\n}\n\n/**\n * Parses a string created by {@link createDeepLinkString} back into a deep link descriptor.\n *\n * @param deepLinkString - the deep link string\n * @returns a deep link descriptor\n *\n * @public\n */\nexport function parseDeepLinkString(deepLinkString: string): TLDeepLink {\n\tconst type = deepLinkString[0]\n\tswitch (type) {\n\t\tcase 's': {\n\t\t\tconst shapeIds = deepLinkString\n\t\t\t\t.slice(1)\n\t\t\t\t.split('.')\n\t\t\t\t.filter(Boolean)\n\t\t\t\t.map((id) => createShapeId(decodeURIComponent(id)))\n\t\t\treturn { type: 'shapes', shapeIds }\n\t\t}\n\t\tcase 'p': {\n\t\t\tconst pageId = PageRecordType.createId(decodeURIComponent(deepLinkString.slice(1)))\n\t\t\treturn { type: 'page', pageId }\n\t\t}\n\t\tcase 'v': {\n\t\t\tconst [x, y, w, h, pageId] = deepLinkString.slice(1).split('.')\n\t\t\tconst bounds = new Box(Number(x), Number(y), Number(w), Number(h))\n\t\t\t// Number('abc') is NaN rather than an error, and a box with no area parses cleanly but\n\t\t\t// can only be zoomed to by clamping to max zoom at its corner. Both bypass the caller's\n\t\t\t// fallback and park the camera at the origin, so both count as an invalid link here.\n\t\t\tconst isUsableViewport =\n\t\t\t\t[bounds.x, bounds.y, bounds.w, bounds.h].every(Number.isFinite) &&\n\t\t\t\tbounds.w > 0 &&\n\t\t\t\tbounds.h > 0\n\t\t\tif (!isUsableViewport) {\n\t\t\t\tthrow Error('Invalid deep link string')\n\t\t\t}\n\t\t\treturn {\n\t\t\t\ttype: 'viewport',\n\t\t\t\tbounds,\n\t\t\t\tpageId: pageId ? PageRecordType.createId(decodeURIComponent(pageId)) : undefined,\n\t\t\t}\n\t\t}\n\t\tdefault:\n\t\t\tthrow Error('Invalid deep link string')\n\t}\n}\n\nfunction encodeId(str: string): string {\n\t// need to encode dots because they are used as separators\n\treturn encodeURIComponent(str).replace(/\\./g, '%2E')\n}\n\n/** @public */\nexport interface TLDeepLinkOptions {\n\t/**\n\t * The name of the url search param to use for the deep link.\n\t *\n\t * Defaults to `'d'`\n\t */\n\tparam?: string\n\t/**\n\t * The debounce time in ms for updating the url.\n\t */\n\tdebounceMs?: number\n\t/**\n\t * Should return the current url to augment with a deep link query parameter.\n\t * If you supply this function, you must also supply an `onChange` function.\n\t */\n\tgetUrl?(editor: Editor): string | URL\n\t/**\n\t * Should return the current deep link target.\n\t * Defaults to returning the current page and viewport position.\n\t */\n\tgetTarget?(editor: Editor): TLDeepLink\n\t/**\n\t * This is fired when the URL is updated.\n\t *\n\t * If not supplied, the default behavior is to update `window.location`.\n\t *\n\t * @param url - the updated URL\n\t */\n\tonChange?(url: URL, editor: Editor): void\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAA6E;AAC7E,mBAAsC;AAEtC,iBAAoB;AAyBb,SAAS,qBAAqB,UAA8B;AAClE,UAAQ,SAAS,MAAM;AAAA,IACtB,KAAK,UAAU;AACd,YAAM,MAAM,SAAS,SAAS,IAAI,CAAC,OAAO,SAAS,GAAG,MAAM,SAAS,MAAM,CAAC,CAAC;AAC7E,aAAO,IAAI,IAAI,KAAK,GAAG,CAAC;AAAA,IACzB;AAAA,IACA,KAAK,QAAQ;AACZ,aAAO,MAAM,SAAS,+BAAe,QAAQ,SAAS,MAAM,CAAC;AAAA,IAC9D;AAAA,IACA,KAAK,YAAY;AAChB,YAAM,EAAE,QAAQ,OAAO,IAAI;AAC3B,UAAI,MAAM,IAAI,KAAK,MAAM,OAAO,CAAC,CAAC,IAAI,KAAK,MAAM,OAAO,CAAC,CAAC,IAAI,KAAK,MAAM,OAAO,CAAC,CAAC,IAAI,KAAK,MAAM,OAAO,CAAC,CAAC;AAC1G,UAAI,QAAQ;AACX,eAAO,MAAM,SAAS,+BAAe,QAAQ,MAAM,CAAC;AAAA,MACrD;AACA,aAAO;AAAA,IACR;AAAA,IACA;AACC,8CAAsB,QAAQ;AAAA,EAChC;AACD;AAUO,SAAS,oBAAoB,gBAAoC;AACvE,QAAM,OAAO,eAAe,CAAC;AAC7B,UAAQ,MAAM;AAAA,IACb,KAAK,KAAK;AACT,YAAM,WAAW,eACf,MAAM,CAAC,EACP,MAAM,GAAG,EACT,OAAO,OAAO,EACd,IAAI,CAAC,WAAO,+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