@tldraw/editor 3.16.0-canary.dfdf6b7de8c2 → 3.16.0-canary.e5e61b17cef3

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 (167) hide show
  1. package/dist-cjs/index.d.ts +131 -110
  2. package/dist-cjs/index.js +3 -5
  3. package/dist-cjs/index.js.map +2 -2
  4. package/dist-cjs/lib/TldrawEditor.js +6 -6
  5. package/dist-cjs/lib/TldrawEditor.js.map +2 -2
  6. package/dist-cjs/lib/components/Shape.js +7 -10
  7. package/dist-cjs/lib/components/Shape.js.map +2 -2
  8. package/dist-cjs/lib/components/default-components/DefaultCanvas.js +4 -23
  9. package/dist-cjs/lib/components/default-components/DefaultCanvas.js.map +2 -2
  10. package/dist-cjs/lib/components/default-components/DefaultCollaboratorHint.js +1 -1
  11. package/dist-cjs/lib/components/default-components/DefaultCollaboratorHint.js.map +1 -1
  12. package/dist-cjs/lib/components/default-components/DefaultErrorFallback.js +1 -1
  13. package/dist-cjs/lib/components/default-components/DefaultErrorFallback.js.map +2 -2
  14. package/dist-cjs/lib/components/default-components/DefaultScribble.js +1 -1
  15. package/dist-cjs/lib/components/default-components/DefaultScribble.js.map +2 -2
  16. package/dist-cjs/lib/components/default-components/DefaultShapeIndicator.js +9 -1
  17. package/dist-cjs/lib/components/default-components/DefaultShapeIndicator.js.map +2 -2
  18. package/dist-cjs/lib/config/TLUserPreferences.js +9 -3
  19. package/dist-cjs/lib/config/TLUserPreferences.js.map +2 -2
  20. package/dist-cjs/lib/editor/Editor.js +80 -135
  21. package/dist-cjs/lib/editor/Editor.js.map +2 -2
  22. package/dist-cjs/lib/editor/derivations/notVisibleShapes.js +4 -0
  23. package/dist-cjs/lib/editor/derivations/notVisibleShapes.js.map +2 -2
  24. package/dist-cjs/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.js +9 -4
  25. package/dist-cjs/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.js.map +2 -2
  26. package/dist-cjs/lib/editor/shapes/ShapeUtil.js +23 -0
  27. package/dist-cjs/lib/editor/shapes/ShapeUtil.js.map +2 -2
  28. package/dist-cjs/lib/editor/types/misc-types.js.map +1 -1
  29. package/dist-cjs/lib/exports/getSvgJsx.js +35 -16
  30. package/dist-cjs/lib/exports/getSvgJsx.js.map +2 -2
  31. package/dist-cjs/lib/hooks/useCanvasEvents.js +7 -5
  32. package/dist-cjs/lib/hooks/useCanvasEvents.js.map +2 -2
  33. package/dist-cjs/lib/hooks/usePassThroughMouseOverEvents.js +4 -1
  34. package/dist-cjs/lib/hooks/usePassThroughMouseOverEvents.js.map +2 -2
  35. package/dist-cjs/lib/hooks/usePassThroughWheelEvents.js +4 -1
  36. package/dist-cjs/lib/hooks/usePassThroughWheelEvents.js.map +2 -2
  37. package/dist-cjs/lib/license/LicenseManager.js +120 -50
  38. package/dist-cjs/lib/license/LicenseManager.js.map +2 -2
  39. package/dist-cjs/lib/license/LicenseProvider.js +39 -1
  40. package/dist-cjs/lib/license/LicenseProvider.js.map +2 -2
  41. package/dist-cjs/lib/license/Watermark.js +72 -10
  42. package/dist-cjs/lib/license/Watermark.js.map +3 -3
  43. package/dist-cjs/lib/license/useLicenseManagerState.js.map +2 -2
  44. package/dist-cjs/lib/options.js +7 -0
  45. package/dist-cjs/lib/options.js.map +2 -2
  46. package/dist-cjs/lib/primitives/Box.js +3 -0
  47. package/dist-cjs/lib/primitives/Box.js.map +2 -2
  48. package/dist-cjs/lib/primitives/Vec.js +0 -4
  49. package/dist-cjs/lib/primitives/Vec.js.map +2 -2
  50. package/dist-cjs/lib/primitives/geometry/Geometry2d.js +50 -20
  51. package/dist-cjs/lib/primitives/geometry/Geometry2d.js.map +2 -2
  52. package/dist-cjs/lib/primitives/geometry/Group2d.js +8 -1
  53. package/dist-cjs/lib/primitives/geometry/Group2d.js.map +2 -2
  54. package/dist-cjs/lib/utils/reparenting.js +2 -35
  55. package/dist-cjs/lib/utils/reparenting.js.map +3 -3
  56. package/dist-cjs/version.js +3 -3
  57. package/dist-cjs/version.js.map +1 -1
  58. package/dist-esm/index.d.mts +131 -110
  59. package/dist-esm/index.mjs +3 -5
  60. package/dist-esm/index.mjs.map +2 -2
  61. package/dist-esm/lib/TldrawEditor.mjs +6 -6
  62. package/dist-esm/lib/TldrawEditor.mjs.map +2 -2
  63. package/dist-esm/lib/components/Shape.mjs +7 -10
  64. package/dist-esm/lib/components/Shape.mjs.map +2 -2
  65. package/dist-esm/lib/components/default-components/DefaultCanvas.mjs +4 -23
  66. package/dist-esm/lib/components/default-components/DefaultCanvas.mjs.map +2 -2
  67. package/dist-esm/lib/components/default-components/DefaultCollaboratorHint.mjs +1 -1
  68. package/dist-esm/lib/components/default-components/DefaultCollaboratorHint.mjs.map +1 -1
  69. package/dist-esm/lib/components/default-components/DefaultErrorFallback.mjs +1 -1
  70. package/dist-esm/lib/components/default-components/DefaultErrorFallback.mjs.map +2 -2
  71. package/dist-esm/lib/components/default-components/DefaultScribble.mjs +1 -1
  72. package/dist-esm/lib/components/default-components/DefaultScribble.mjs.map +2 -2
  73. package/dist-esm/lib/components/default-components/DefaultShapeIndicator.mjs +9 -1
  74. package/dist-esm/lib/components/default-components/DefaultShapeIndicator.mjs.map +2 -2
  75. package/dist-esm/lib/config/TLUserPreferences.mjs +9 -3
  76. package/dist-esm/lib/config/TLUserPreferences.mjs.map +2 -2
  77. package/dist-esm/lib/editor/Editor.mjs +80 -135
  78. package/dist-esm/lib/editor/Editor.mjs.map +2 -2
  79. package/dist-esm/lib/editor/derivations/notVisibleShapes.mjs +4 -0
  80. package/dist-esm/lib/editor/derivations/notVisibleShapes.mjs.map +2 -2
  81. package/dist-esm/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.mjs +9 -4
  82. package/dist-esm/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.mjs.map +2 -2
  83. package/dist-esm/lib/editor/shapes/ShapeUtil.mjs +23 -0
  84. package/dist-esm/lib/editor/shapes/ShapeUtil.mjs.map +2 -2
  85. package/dist-esm/lib/exports/getSvgJsx.mjs +36 -16
  86. package/dist-esm/lib/exports/getSvgJsx.mjs.map +2 -2
  87. package/dist-esm/lib/hooks/useCanvasEvents.mjs +7 -5
  88. package/dist-esm/lib/hooks/useCanvasEvents.mjs.map +2 -2
  89. package/dist-esm/lib/hooks/usePassThroughMouseOverEvents.mjs +4 -1
  90. package/dist-esm/lib/hooks/usePassThroughMouseOverEvents.mjs.map +2 -2
  91. package/dist-esm/lib/hooks/usePassThroughWheelEvents.mjs +4 -1
  92. package/dist-esm/lib/hooks/usePassThroughWheelEvents.mjs.map +2 -2
  93. package/dist-esm/lib/license/LicenseManager.mjs +121 -51
  94. package/dist-esm/lib/license/LicenseManager.mjs.map +2 -2
  95. package/dist-esm/lib/license/LicenseProvider.mjs +39 -2
  96. package/dist-esm/lib/license/LicenseProvider.mjs.map +2 -2
  97. package/dist-esm/lib/license/Watermark.mjs +72 -10
  98. package/dist-esm/lib/license/Watermark.mjs.map +3 -3
  99. package/dist-esm/lib/license/useLicenseManagerState.mjs.map +2 -2
  100. package/dist-esm/lib/options.mjs +7 -0
  101. package/dist-esm/lib/options.mjs.map +2 -2
  102. package/dist-esm/lib/primitives/Box.mjs +4 -1
  103. package/dist-esm/lib/primitives/Box.mjs.map +2 -2
  104. package/dist-esm/lib/primitives/Vec.mjs +0 -4
  105. package/dist-esm/lib/primitives/Vec.mjs.map +2 -2
  106. package/dist-esm/lib/primitives/geometry/Geometry2d.mjs +53 -21
  107. package/dist-esm/lib/primitives/geometry/Geometry2d.mjs.map +2 -2
  108. package/dist-esm/lib/primitives/geometry/Group2d.mjs +8 -1
  109. package/dist-esm/lib/primitives/geometry/Group2d.mjs.map +2 -2
  110. package/dist-esm/lib/utils/reparenting.mjs +3 -40
  111. package/dist-esm/lib/utils/reparenting.mjs.map +2 -2
  112. package/dist-esm/version.mjs +3 -3
  113. package/dist-esm/version.mjs.map +1 -1
  114. package/editor.css +308 -290
  115. package/package.json +14 -37
  116. package/src/index.ts +3 -9
  117. package/src/lib/TldrawEditor.tsx +7 -14
  118. package/src/lib/components/Shape.tsx +6 -12
  119. package/src/lib/components/default-components/DefaultCanvas.tsx +5 -22
  120. package/src/lib/components/default-components/DefaultCollaboratorHint.tsx +1 -1
  121. package/src/lib/components/default-components/DefaultErrorFallback.tsx +1 -1
  122. package/src/lib/components/default-components/DefaultScribble.tsx +1 -1
  123. package/src/lib/components/default-components/DefaultShapeIndicator.tsx +5 -1
  124. package/src/lib/config/TLUserPreferences.ts +8 -1
  125. package/src/lib/editor/Editor.test.ts +12 -11
  126. package/src/lib/editor/Editor.ts +112 -195
  127. package/src/lib/editor/derivations/notVisibleShapes.ts +6 -0
  128. package/src/lib/editor/managers/ClickManager/ClickManager.test.ts +15 -14
  129. package/src/lib/editor/managers/EdgeScrollManager/EdgeScrollManager.test.ts +16 -15
  130. package/src/lib/editor/managers/FocusManager/FocusManager.test.ts +49 -48
  131. package/src/lib/editor/managers/FontManager/FontManager.test.ts +24 -23
  132. package/src/lib/editor/managers/HistoryManager/HistoryManager.test.ts +7 -6
  133. package/src/lib/editor/managers/ScribbleManager/ScribbleManager.test.ts +12 -11
  134. package/src/lib/editor/managers/SnapManager/SnapManager.test.ts +57 -50
  135. package/src/lib/editor/managers/TextManager/TextManager.test.ts +51 -26
  136. package/src/lib/editor/managers/TickManager/TickManager.test.ts +14 -13
  137. package/src/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.test.ts +34 -26
  138. package/src/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.ts +6 -1
  139. package/src/lib/editor/shapes/ShapeUtil.ts +46 -0
  140. package/src/lib/editor/types/misc-types.ts +54 -7
  141. package/src/lib/exports/getSvgJsx.test.ts +868 -0
  142. package/src/lib/exports/getSvgJsx.tsx +78 -21
  143. package/src/lib/hooks/useCanvasEvents.ts +6 -6
  144. package/src/lib/hooks/usePassThroughMouseOverEvents.ts +4 -1
  145. package/src/lib/hooks/usePassThroughWheelEvents.ts +6 -1
  146. package/src/lib/license/LicenseManager.test.ts +648 -383
  147. package/src/lib/license/LicenseManager.ts +173 -53
  148. package/src/lib/license/LicenseProvider.tsx +74 -2
  149. package/src/lib/license/Watermark.test.tsx +2 -1
  150. package/src/lib/license/Watermark.tsx +77 -10
  151. package/src/lib/license/useLicenseManagerState.ts +2 -2
  152. package/src/lib/options.ts +8 -0
  153. package/src/lib/primitives/Box.test.ts +126 -0
  154. package/src/lib/primitives/Box.ts +10 -1
  155. package/src/lib/primitives/Vec.ts +0 -5
  156. package/src/lib/primitives/geometry/Geometry2d.test.ts +420 -0
  157. package/src/lib/primitives/geometry/Geometry2d.ts +78 -21
  158. package/src/lib/primitives/geometry/Group2d.ts +10 -1
  159. package/src/lib/utils/reparenting.ts +3 -69
  160. package/src/lib/utils/sync/LocalIndexedDb.test.ts +2 -1
  161. package/src/lib/utils/sync/TLLocalSyncClient.test.ts +15 -15
  162. package/src/version.ts +3 -3
  163. package/dist-cjs/lib/utils/nearestMultiple.js +0 -34
  164. package/dist-cjs/lib/utils/nearestMultiple.js.map +0 -7
  165. package/dist-esm/lib/utils/nearestMultiple.mjs +0 -14
  166. package/dist-esm/lib/utils/nearestMultiple.mjs.map +0 -7
  167. package/src/lib/utils/nearestMultiple.ts +0 -13
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/lib/components/default-components/DefaultScribble.tsx"],
4
- "sourcesContent": ["import { TLScribble } from '@tldraw/tlschema'\nimport classNames from 'classnames'\nimport { getSvgPathFromPoints } from '../../utils/getSvgPathFromPoints'\n\n/** @public */\nexport interface TLScribbleProps {\n\tuserId?: string\n\tscribble: TLScribble\n\tzoom: number\n\tcolor?: string\n\topacity?: number\n\tclassName?: string\n}\n\n/** @public @react */\nexport function DefaultScribble({ scribble, zoom, color, opacity, className }: TLScribbleProps) {\n\tif (!scribble.points.length) return null\n\n\treturn (\n\t\t<svg className={className ? classNames('tl-overlays__item', className) : className}>\n\t\t\t<path\n\t\t\t\tclassName=\"tl-scribble\"\n\t\t\t\td={getSvgPathFromPoints(scribble.points, false)}\n\t\t\t\tstroke={color ?? `var(--color-${scribble.color})`}\n\t\t\t\tfill=\"none\"\n\t\t\t\tstrokeWidth={8 / zoom}\n\t\t\t\topacity={opacity ?? scribble.opacity}\n\t\t\t/>\n\t\t</svg>\n\t)\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAoBG;AAnBH,wBAAuB;AACvB,kCAAqC;AAa9B,SAAS,gBAAgB,EAAE,UAAU,MAAM,OAAO,SAAS,UAAU,GAAoB;AAC/F,MAAI,CAAC,SAAS,OAAO,OAAQ,QAAO;AAEpC,SACC,4CAAC,SAAI,WAAW,gBAAY,kBAAAA,SAAW,qBAAqB,SAAS,IAAI,WACxE;AAAA,IAAC;AAAA;AAAA,MACA,WAAU;AAAA,MACV,OAAG,kDAAqB,SAAS,QAAQ,KAAK;AAAA,MAC9C,QAAQ,SAAS,eAAe,SAAS,KAAK;AAAA,MAC9C,MAAK;AAAA,MACL,aAAa,IAAI;AAAA,MACjB,SAAS,WAAW,SAAS;AAAA;AAAA,EAC9B,GACD;AAEF;",
4
+ "sourcesContent": ["import { TLScribble } from '@tldraw/tlschema'\nimport classNames from 'classnames'\nimport { getSvgPathFromPoints } from '../../utils/getSvgPathFromPoints'\n\n/** @public */\nexport interface TLScribbleProps {\n\tuserId?: string\n\tscribble: TLScribble\n\tzoom: number\n\tcolor?: string\n\topacity?: number\n\tclassName?: string\n}\n\n/** @public @react */\nexport function DefaultScribble({ scribble, zoom, color, opacity, className }: TLScribbleProps) {\n\tif (!scribble.points.length) return null\n\n\treturn (\n\t\t<svg className={className ? classNames('tl-overlays__item', className) : className}>\n\t\t\t<path\n\t\t\t\tclassName=\"tl-scribble\"\n\t\t\t\td={getSvgPathFromPoints(scribble.points, false)}\n\t\t\t\tstroke={color ?? `var(--tl-color-${scribble.color})`}\n\t\t\t\tfill=\"none\"\n\t\t\t\tstrokeWidth={8 / zoom}\n\t\t\t\topacity={opacity ?? scribble.opacity}\n\t\t\t/>\n\t\t</svg>\n\t)\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAoBG;AAnBH,wBAAuB;AACvB,kCAAqC;AAa9B,SAAS,gBAAgB,EAAE,UAAU,MAAM,OAAO,SAAS,UAAU,GAAoB;AAC/F,MAAI,CAAC,SAAS,OAAO,OAAQ,QAAO;AAEpC,SACC,4CAAC,SAAI,WAAW,gBAAY,kBAAAA,SAAW,qBAAqB,SAAS,IAAI,WACxE;AAAA,IAAC;AAAA;AAAA,MACA,WAAU;AAAA,MACV,OAAG,kDAAqB,SAAS,QAAQ,KAAK;AAAA,MAC9C,QAAQ,SAAS,kBAAkB,SAAS,KAAK;AAAA,MACjD,MAAK;AAAA,MACL,aAAa,IAAI;AAAA,MACjB,SAAS,WAAW,SAAS;AAAA;AAAA,EAC9B,GACD;AAEF;",
6
6
  "names": ["classNames"]
7
7
  }
@@ -92,6 +92,14 @@ const DefaultShapeIndicator = (0, import_react.memo)(function DefaultShapeIndica
92
92
  if (!elm) return;
93
93
  elm.style.setProperty("display", hidden ? "none" : "block");
94
94
  }, [hidden]);
95
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("svg", { ref: rIndicator, className: (0, import_classnames.default)("tl-overlays__item", className), "aria-hidden": "true", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("g", { className: "tl-shape-indicator", stroke: color ?? "var(--color-selected)", opacity, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(InnerIndicator, { editor, id: shapeId }) }) });
95
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("svg", { ref: rIndicator, className: (0, import_classnames.default)("tl-overlays__item", className), "aria-hidden": "true", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
96
+ "g",
97
+ {
98
+ className: "tl-shape-indicator",
99
+ stroke: color ?? "var(--tl-color-selected)",
100
+ opacity,
101
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(InnerIndicator, { editor, id: shapeId })
102
+ }
103
+ ) });
96
104
  });
97
105
  //# sourceMappingURL=DefaultShapeIndicator.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/lib/components/default-components/DefaultShapeIndicator.tsx"],
4
- "sourcesContent": ["import { useQuickReactor, useStateTracking, useValue } from '@tldraw/state-react'\nimport { TLShape, TLShapeId } from '@tldraw/tlschema'\nimport classNames from 'classnames'\nimport { memo, useLayoutEffect, useRef } from 'react'\nimport type { Editor } from '../../editor/Editor'\nimport { ShapeUtil } from '../../editor/shapes/ShapeUtil'\nimport { useEditor } from '../../hooks/useEditor'\nimport { useEditorComponents } from '../../hooks/useEditorComponents'\nimport { OptionalErrorBoundary } from '../ErrorBoundary'\n\n// need an extra layer of indirection here to allow hooks to be used inside the indicator render\nconst EvenInnererIndicator = memo(\n\t({ shape, util }: { shape: TLShape; util: ShapeUtil<any> }) => {\n\t\treturn useStateTracking('Indicator: ' + shape.type, () =>\n\t\t\t// always fetch the latest shape from the store even if the props/meta have not changed, to avoid\n\t\t\t// calling the render method with stale data.\n\t\t\tutil.indicator(util.editor.store.unsafeGetWithoutCapture(shape.id) as TLShape)\n\t\t)\n\t},\n\t(prevProps, nextProps) => {\n\t\treturn (\n\t\t\tprevProps.shape.props === nextProps.shape.props &&\n\t\t\tprevProps.shape.meta === nextProps.shape.meta\n\t\t)\n\t}\n)\n\nconst InnerIndicator = memo(({ editor, id }: { editor: Editor; id: TLShapeId }) => {\n\tconst shape = useValue('shape for indicator', () => editor.store.get(id), [editor, id])\n\n\tconst { ShapeIndicatorErrorFallback } = useEditorComponents()\n\n\tif (!shape || shape.isLocked) return null\n\n\treturn (\n\t\t<OptionalErrorBoundary\n\t\t\tfallback={ShapeIndicatorErrorFallback}\n\t\t\tonError={(error) =>\n\t\t\t\teditor.annotateError(error, { origin: 'react.shapeIndicator', willCrashApp: false })\n\t\t\t}\n\t\t>\n\t\t\t<EvenInnererIndicator key={shape.id} shape={shape} util={editor.getShapeUtil(shape)} />\n\t\t</OptionalErrorBoundary>\n\t)\n})\n\n/** @public */\nexport interface TLShapeIndicatorProps {\n\tuserId?: string\n\tshapeId: TLShapeId\n\tcolor?: string | undefined\n\topacity?: number\n\tclassName?: string\n\thidden?: boolean\n}\n\n/** @public @react */\nexport const DefaultShapeIndicator = memo(function DefaultShapeIndicator({\n\tshapeId,\n\tclassName,\n\tcolor,\n\thidden,\n\topacity,\n}: TLShapeIndicatorProps) {\n\tconst editor = useEditor()\n\n\tconst rIndicator = useRef<SVGSVGElement>(null)\n\n\tuseQuickReactor(\n\t\t'indicator transform',\n\t\t() => {\n\t\t\tif (hidden) return\n\t\t\tconst elm = rIndicator.current\n\t\t\tif (!elm) return\n\t\t\tconst pageTransform = editor.getShapePageTransform(shapeId)\n\t\t\tif (!pageTransform) return\n\t\t\telm.style.setProperty('transform', pageTransform.toCssString())\n\t\t},\n\t\t[editor, shapeId, hidden]\n\t)\n\n\tuseLayoutEffect(() => {\n\t\tconst elm = rIndicator.current\n\t\tif (!elm) return\n\t\telm.style.setProperty('display', hidden ? 'none' : 'block')\n\t}, [hidden])\n\n\treturn (\n\t\t<svg ref={rIndicator} className={classNames('tl-overlays__item', className)} aria-hidden=\"true\">\n\t\t\t<g className=\"tl-shape-indicator\" stroke={color ?? 'var(--color-selected)'} opacity={opacity}>\n\t\t\t\t<InnerIndicator editor={editor} id={shapeId} />\n\t\t\t</g>\n\t\t</svg>\n\t)\n})\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAyCG;AAzCH,yBAA4D;AAE5D,wBAAuB;AACvB,mBAA8C;AAG9C,uBAA0B;AAC1B,iCAAoC;AACpC,2BAAsC;AAGtC,MAAM,2BAAuB;AAAA,EAC5B,CAAC,EAAE,OAAO,KAAK,M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AAgB,MAAM;AACrB,UAAM,MAAM,WAAW;AACvB,QAAI,CAAC,IAAK;AACV,QAAI,MAAM,YAAY,WAAW,SAAS,SAAS,OAAO;AAAA,EAC3D,GAAG,CAAC,MAAM,CAAC;AAEX,SACC,4CAAC,SAAI,KAAK,YAAY,eAAW,kBAAAC,SAAW,qBAAqB,SAAS,GAAG,eAAY,QACxF,sDAAC,OAAE,WAAU,sBAAqB,QAAQ,SAAS,yBAAyB,SAC3E,sDAAC,kBAAe,QAAgB,IAAI,SAAS,GAC9C,GACD;AAEF,CAAC;",
4
+ "sourcesContent": ["import { useQuickReactor, useStateTracking, useValue } from '@tldraw/state-react'\nimport { TLShape, TLShapeId } from '@tldraw/tlschema'\nimport classNames from 'classnames'\nimport { memo, useLayoutEffect, useRef } from 'react'\nimport type { Editor } from '../../editor/Editor'\nimport { ShapeUtil } from '../../editor/shapes/ShapeUtil'\nimport { useEditor } from '../../hooks/useEditor'\nimport { useEditorComponents } from '../../hooks/useEditorComponents'\nimport { OptionalErrorBoundary } from '../ErrorBoundary'\n\n// need an extra layer of indirection here to allow hooks to be used inside the indicator render\nconst EvenInnererIndicator = memo(\n\t({ shape, util }: { shape: TLShape; util: ShapeUtil<any> }) => {\n\t\treturn useStateTracking('Indicator: ' + shape.type, () =>\n\t\t\t// always fetch the latest shape from the store even if the props/meta have not changed, to avoid\n\t\t\t// calling the render method with stale data.\n\t\t\tutil.indicator(util.editor.store.unsafeGetWithoutCapture(shape.id) as TLShape)\n\t\t)\n\t},\n\t(prevProps, nextProps) => {\n\t\treturn (\n\t\t\tprevProps.shape.props === nextProps.shape.props &&\n\t\t\tprevProps.shape.meta === nextProps.shape.meta\n\t\t)\n\t}\n)\n\nconst InnerIndicator = memo(({ editor, id }: { editor: Editor; id: TLShapeId }) => {\n\tconst shape = useValue('shape for indicator', () => editor.store.get(id), [editor, id])\n\n\tconst { ShapeIndicatorErrorFallback } = useEditorComponents()\n\n\tif (!shape || shape.isLocked) return null\n\n\treturn (\n\t\t<OptionalErrorBoundary\n\t\t\tfallback={ShapeIndicatorErrorFallback}\n\t\t\tonError={(error) =>\n\t\t\t\teditor.annotateError(error, { origin: 'react.shapeIndicator', willCrashApp: false })\n\t\t\t}\n\t\t>\n\t\t\t<EvenInnererIndicator key={shape.id} shape={shape} util={editor.getShapeUtil(shape)} />\n\t\t</OptionalErrorBoundary>\n\t)\n})\n\n/** @public */\nexport interface TLShapeIndicatorProps {\n\tuserId?: string\n\tshapeId: TLShapeId\n\tcolor?: string | undefined\n\topacity?: number\n\tclassName?: string\n\thidden?: boolean\n}\n\n/** @public @react */\nexport const DefaultShapeIndicator = memo(function DefaultShapeIndicator({\n\tshapeId,\n\tclassName,\n\tcolor,\n\thidden,\n\topacity,\n}: TLShapeIndicatorProps) {\n\tconst editor = useEditor()\n\n\tconst rIndicator = useRef<SVGSVGElement>(null)\n\n\tuseQuickReactor(\n\t\t'indicator transform',\n\t\t() => {\n\t\t\tif (hidden) return\n\t\t\tconst elm = rIndicator.current\n\t\t\tif (!elm) return\n\t\t\tconst pageTransform = editor.getShapePageTransform(shapeId)\n\t\t\tif (!pageTransform) return\n\t\t\telm.style.setProperty('transform', pageTransform.toCssString())\n\t\t},\n\t\t[editor, shapeId, hidden]\n\t)\n\n\tuseLayoutEffect(() => {\n\t\tconst elm = rIndicator.current\n\t\tif (!elm) return\n\t\telm.style.setProperty('display', hidden ? 'none' : 'block')\n\t}, [hidden])\n\n\treturn (\n\t\t<svg ref={rIndicator} className={classNames('tl-overlays__item', className)} aria-hidden=\"true\">\n\t\t\t<g\n\t\t\t\tclassName=\"tl-shape-indicator\"\n\t\t\t\tstroke={color ?? 'var(--tl-color-selected)'}\n\t\t\t\topacity={opacity}\n\t\t\t>\n\t\t\t\t<InnerIndicator editor={editor} id={shapeId} />\n\t\t\t</g>\n\t\t</svg>\n\t)\n})\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAyCG;AA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OAAO;AAC1D,UAAI,CAAC,cAAe;AACpB,UAAI,MAAM,YAAY,aAAa,cAAc,YAAY,CAAC;AAAA,IAC/D;AAAA,IACA,CAAC,QAAQ,SAAS,MAAM;AAAA,EACzB;AAEA,oCAAgB,MAAM;AACrB,UAAM,MAAM,WAAW;AACvB,QAAI,CAAC,IAAK;AACV,QAAI,MAAM,YAAY,WAAW,SAAS,SAAS,OAAO;AAAA,EAC3D,GAAG,CAAC,MAAM,CAAC;AAEX,SACC,4CAAC,SAAI,KAAK,YAAY,eAAW,kBAAAC,SAAW,qBAAqB,SAAS,GAAG,eAAY,QACxF;AAAA,IAAC;AAAA;AAAA,MACA,WAAU;AAAA,MACV,QAAQ,SAAS;AAAA,MACjB;AAAA,MAEA,sDAAC,kBAAe,QAAgB,IAAI,SAAS;AAAA;AAAA,EAC9C,GACD;AAEF,CAAC;",
6
6
  "names": ["DefaultShapeIndicator", "classNames"]
7
7
  }
@@ -45,7 +45,8 @@ const userTypeValidator = import_validate.T.object({
45
45
  isSnapMode: import_validate.T.boolean.nullable().optional(),
46
46
  isWrapMode: import_validate.T.boolean.nullable().optional(),
47
47
  isDynamicSizeMode: import_validate.T.boolean.nullable().optional(),
48
- isPasteAtCursorMode: import_validate.T.boolean.nullable().optional()
48
+ isPasteAtCursorMode: import_validate.T.boolean.nullable().optional(),
49
+ showUiLabels: import_validate.T.boolean.nullable().optional()
49
50
  });
50
51
  const Versions = {
51
52
  AddAnimationSpeed: 1,
@@ -56,7 +57,8 @@ const Versions = {
56
57
  AddDynamicSizeMode: 6,
57
58
  AllowSystemColorScheme: 7,
58
59
  AddPasteAtCursor: 8,
59
- AddKeyboardShortcuts: 9
60
+ AddKeyboardShortcuts: 9,
61
+ AddShowUiLabels: 10
60
62
  };
61
63
  const CURRENT_VERSION = Math.max(...Object.values(Versions));
62
64
  function migrateSnapshot(data) {
@@ -91,6 +93,9 @@ function migrateSnapshot(data) {
91
93
  if (data.version < Versions.AddKeyboardShortcuts) {
92
94
  data.user.areKeyboardShortcutsEnabled = true;
93
95
  }
96
+ if (data.version < Versions.AddShowUiLabels) {
97
+ data.user.showUiLabels = false;
98
+ }
94
99
  data.version = CURRENT_VERSION;
95
100
  }
96
101
  const USER_COLORS = [
@@ -111,7 +116,7 @@ function getRandomColor() {
111
116
  return USER_COLORS[Math.floor(Math.random() * USER_COLORS.length)];
112
117
  }
113
118
  function userPrefersReducedMotion() {
114
- if (typeof window !== "undefined" && "matchMedia" in window) {
119
+ if (typeof window !== "undefined" && window.matchMedia) {
115
120
  return window.matchMedia?.("(prefers-reduced-motion: reduce)")?.matches ?? false;
116
121
  }
117
122
  return false;
@@ -128,6 +133,7 @@ const defaultUserPreferences = Object.freeze({
128
133
  isWrapMode: false,
129
134
  isDynamicSizeMode: false,
130
135
  isPasteAtCursorMode: false,
136
+ showUiLabels: false,
131
137
  colorScheme: "light"
132
138
  });
133
139
  function getFreshUserPreferences() {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/lib/config/TLUserPreferences.ts"],
4
- "sourcesContent": ["import { atom } from '@tldraw/state'\nimport { getDefaultTranslationLocale } from '@tldraw/tlschema'\nimport { getFromLocalStorage, setInLocalStorage, structuredClone, uniqueId } from '@tldraw/utils'\nimport { T } from '@tldraw/validate'\n\nconst USER_DATA_KEY = 'TLDRAW_USER_DATA_v3'\n\n/**\n * A user of tldraw\n *\n * @public\n */\nexport interface TLUserPreferences {\n\tid: string\n\tname?: string | null\n\tcolor?: string | null\n\t// N.B. These are duplicated in TLdrawAppUser.\n\tlocale?: string | null\n\tanimationSpeed?: number | null\n\tareKeyboardShortcutsEnabled?: boolean | null\n\tedgeScrollSpeed?: number | null\n\tcolorScheme?: 'light' | 'dark' | 'system'\n\tisSnapMode?: boolean | null\n\tisWrapMode?: boolean | null\n\tisDynamicSizeMode?: boolean | null\n\tisPasteAtCursorMode?: boolean | null\n}\n\ninterface UserDataSnapshot {\n\tversion: number\n\tuser: TLUserPreferences\n}\n\ninterface UserChangeBroadcastMessage {\n\ttype: typeof broadcastEventKey\n\torigin: string\n\tdata: UserDataSnapshot\n}\n\n/** @public */\nexport const userTypeValidator: T.Validator<TLUserPreferences> = T.object<TLUserPreferences>({\n\tid: T.string,\n\tname: T.string.nullable().optional(),\n\tcolor: T.string.nullable().optional(),\n\t// N.B. These are duplicated in TLdrawAppUser.\n\tlocale: T.string.nullable().optional(),\n\tanimationSpeed: T.number.nullable().optional(),\n\tareKeyboardShortcutsEnabled: T.boolean.nullable().optional(),\n\tedgeScrollSpeed: T.number.nullable().optional(),\n\tcolorScheme: T.literalEnum('light', 'dark', 'system').optional(),\n\tisSnapMode: T.boolean.nullable().optional(),\n\tisWrapMode: T.boolean.nullable().optional(),\n\tisDynamicSizeMode: T.boolean.nullable().optional(),\n\tisPasteAtCursorMode: T.boolean.nullable().optional(),\n})\n\nconst Versions = {\n\tAddAnimationSpeed: 1,\n\tAddIsSnapMode: 2,\n\tMakeFieldsNullable: 3,\n\tAddEdgeScrollSpeed: 4,\n\tAddExcalidrawSelectMode: 5,\n\tAddDynamicSizeMode: 6,\n\tAllowSystemColorScheme: 7,\n\tAddPasteAtCursor: 8,\n\tAddKeyboardShortcuts: 9,\n} as const\n\nconst CURRENT_VERSION = Math.max(...Object.values(Versions))\n\nfunction migrateSnapshot(data: { version: number; user: any }) {\n\tif (data.version < Versions.AddAnimationSpeed) {\n\t\tdata.user.animationSpeed = 1\n\t}\n\tif (data.version < Versions.AddIsSnapMode) {\n\t\tdata.user.isSnapMode = false\n\t}\n\tif (data.version < Versions.MakeFieldsNullable) {\n\t\t// noop\n\t}\n\tif (data.version < Versions.AddEdgeScrollSpeed) {\n\t\tdata.user.edgeScrollSpeed = 1\n\t}\n\tif (data.version < Versions.AddExcalidrawSelectMode) {\n\t\tdata.user.isWrapMode = false\n\t}\n\tif (data.version < Versions.AllowSystemColorScheme) {\n\t\tif (data.user.isDarkMode === true) {\n\t\t\tdata.user.colorScheme = 'dark'\n\t\t} else if (data.user.isDarkMode === false) {\n\t\t\tdata.user.colorScheme = 'light'\n\t\t}\n\t\tdelete data.user.isDarkMode\n\t}\n\n\tif (data.version < Versions.AddDynamicSizeMode) {\n\t\tdata.user.isDynamicSizeMode = false\n\t}\n\tif (data.version < Versions.AddPasteAtCursor) {\n\t\tdata.user.isPasteAtCursorMode = false\n\t}\n\tif (data.version < Versions.AddKeyboardShortcuts) {\n\t\tdata.user.areKeyboardShortcutsEnabled = true\n\t}\n\n\t// finally\n\tdata.version = CURRENT_VERSION\n}\n\n/** @internal */\nexport const USER_COLORS = [\n\t'#FF802B',\n\t'#EC5E41',\n\t'#F2555A',\n\t'#F04F88',\n\t'#E34BA9',\n\t'#BD54C6',\n\t'#9D5BD2',\n\t'#7B66DC',\n\t'#02B1CC',\n\t'#11B3A3',\n\t'#39B178',\n\t'#55B467',\n] as const\n\nfunction getRandomColor() {\n\treturn USER_COLORS[Math.floor(Math.random() * USER_COLORS.length)]\n}\n\n/** @internal */\nexport function userPrefersReducedMotion() {\n\tif (typeof window !== 'undefined' && 'matchMedia' in window) {\n\t\treturn window.matchMedia?.('(prefers-reduced-motion: reduce)')?.matches ?? false\n\t}\n\n\treturn false\n}\n\n/** @public */\nexport const defaultUserPreferences = Object.freeze({\n\tname: '',\n\tlocale: getDefaultTranslationLocale(),\n\tcolor: getRandomColor(),\n\n\t// N.B. These are duplicated in TLdrawAppUser.\n\tedgeScrollSpeed: 1,\n\tanimationSpeed: userPrefersReducedMotion() ? 0 : 1,\n\tareKeyboardShortcutsEnabled: true,\n\tisSnapMode: false,\n\tisWrapMode: false,\n\tisDynamicSizeMode: false,\n\tisPasteAtCursorMode: false,\n\tcolorScheme: 'light',\n}) satisfies Readonly<Omit<TLUserPreferences, 'id'>>\n\n/** @public */\nexport function getFreshUserPreferences(): TLUserPreferences {\n\treturn {\n\t\tid: uniqueId(),\n\t\tcolor: getRandomColor(),\n\t}\n}\n\nfunction migrateUserPreferences(userData: unknown): TLUserPreferences {\n\tif (userData === null || typeof userData !== 'object') {\n\t\treturn getFreshUserPreferences()\n\t}\n\n\tif (!('version' in userData) || !('user' in userData) || typeof userData.version !== 'number') {\n\t\treturn getFreshUserPreferences()\n\t}\n\n\tconst snapshot = structuredClone(userData) as any\n\n\tmigrateSnapshot(snapshot)\n\n\ttry {\n\t\treturn userTypeValidator.validate(snapshot.user)\n\t} catch {\n\t\treturn getFreshUserPreferences()\n\t}\n}\n\nfunction loadUserPreferences(): TLUserPreferences {\n\tconst userData = (JSON.parse(getFromLocalStorage(USER_DATA_KEY) || 'null') ??\n\t\tnull) as null | UserDataSnapshot\n\n\treturn migrateUserPreferences(userData)\n}\n\nconst globalUserPreferences = atom<TLUserPreferences | null>('globalUserData', null)\n\nfunction storeUserPreferences() {\n\tsetInLocalStorage(\n\t\tUSER_DATA_KEY,\n\t\tJSON.stringify({\n\t\t\tversion: CURRENT_VERSION,\n\t\t\tuser: globalUserPreferences.get(),\n\t\t})\n\t)\n}\n\n/** @public */\nexport function setUserPreferences(user: TLUserPreferences) {\n\tuserTypeValidator.validate(user)\n\tglobalUserPreferences.set(user)\n\tstoreUserPreferences()\n\tbroadcastUserPreferencesChange()\n}\n\nconst isTest = typeof process !== 'undefined' && process.env.NODE_ENV === 'test'\n\nconst channel =\n\ttypeof BroadcastChannel !== 'undefined' && !isTest\n\t\t? new BroadcastChannel('tldraw-user-sync')\n\t\t: null\n\nchannel?.addEventListener('message', (e) => {\n\tconst data = e.data as undefined | UserChangeBroadcastMessage\n\tif (data?.type === broadcastEventKey && data?.origin !== getBroadcastOrigin()) {\n\t\tglobalUserPreferences.set(migrateUserPreferences(data.data))\n\t}\n})\n\nlet _broadcastOrigin = null as null | string\nfunction getBroadcastOrigin() {\n\tif (_broadcastOrigin === null) {\n\t\t_broadcastOrigin = uniqueId()\n\t}\n\treturn _broadcastOrigin\n}\nconst broadcastEventKey = 'tldraw-user-preferences-change' as const\n\nfunction broadcastUserPreferencesChange() {\n\tchannel?.postMessage({\n\t\ttype: broadcastEventKey,\n\t\torigin: getBroadcastOrigin(),\n\t\tdata: {\n\t\t\tuser: getUserPreferences(),\n\t\t\tversion: CURRENT_VERSION,\n\t\t},\n\t} satisfies UserChangeBroadcastMessage)\n}\n\n/** @public */\nexport function getUserPreferences(): TLUserPreferences {\n\tlet prefs = globalUserPreferences.get()\n\tif (!prefs) {\n\t\tprefs = loadUserPreferences()\n\t\tsetUserPreferences(prefs)\n\t}\n\treturn prefs\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAqB;AACrB,sBAA4C;AAC5C,mBAAkF;AAClF,sBAAkB;AAElB,MAAM,gBAAgB;AAmCf,MAAM,oBAAoD,kBAAE,OAA0B;AAAA,EAC5F,IAAI,kBAAE;AAAA,EACN,MAAM,kBAAE,OAAO,SAAS,EAAE,SAAS;AAAA,EACnC,OAAO,kBAAE,OAAO,SAAS,EAAE,SAAS;AAAA;AAAA,EAEpC,QAAQ,kBAAE,OAAO,SAAS,EAAE,SAAS;AAAA,EACrC,gBAAgB,kBAAE,OAAO,SAAS,EAAE,SAAS;AAAA,EAC7C,6BAA6B,kBAAE,QAAQ,SAAS,EAAE,SAAS;AAAA,EAC3D,iBAAiB,kBAAE,OAAO,SAAS,EAAE,SAAS;AAAA,EAC9C,aAAa,kBAAE,YAAY,SAAS,QAAQ,QAAQ,EAAE,SAAS;AAAA,EAC/D,YAAY,kBAAE,QAAQ,SAAS,EAAE,SAAS;AAAA,EAC1C,YAAY,kBAAE,QAAQ,SAAS,EAAE,SAAS;AAAA,EAC1C,mBAAmB,kBAAE,QAAQ,SAAS,EAAE,SAAS;AAAA,EACjD,qBAAqB,kBAAE,QAAQ,SAAS,EAAE,SAAS;AACpD,CAAC;AAED,MAAM,WAAW;AAAA,EAChB,mBAAmB;AAAA,EACnB,eAAe;AAAA,EACf,oBAAoB;AAAA,EACpB,oBAAoB;AAAA,EACp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EACF;AACD;AAGO,SAAS,mBAAmB,MAAyB;AAC3D,oBAAkB,SAAS,IAAI;AAC/B,wBAAsB,IAAI,IAAI;AAC9B,uBAAqB;AACrB,iCAA+B;AAChC;AAEA,MAAM,SAAS,OAAO,YAAY,eAAe,QAAQ,IAAI,aAAa;AAE1E,MAAM,UACL,OAAO,qBAAqB,eAAe,CAAC,SACzC,IAAI,iBAAiB,kBAAkB,IACvC;AAEJ,SAAS,iBAAiB,WAAW,CAAC,MAAM;AAC3C,QAAM,OAAO,EAAE;AACf,MAAI,MAAM,SAAS,qBAAqB,MAAM,WAAW,mBAAmB,GAAG;AAC9E,0BAAsB,IAAI,uBAAuB,KAAK,IAAI,CAAC;AAAA,EAC5D;AACD,CAAC;AAED,IAAI,mBAAmB;AACvB,SAAS,qBAAqB;AAC7B,MAAI,qBAAqB,MAAM;AAC9B,2BAAmB,uBAAS;AAAA,EAC7B;AACA,SAAO;AACR;AACA,MAAM,oBAAoB;AAE1B,SAAS,iCAAiC;AACzC,WAAS,YAAY;AAAA,IACpB,MAAM;AAAA,IACN,QAAQ,mBAAmB;AAAA,IAC3B,MAAM;AAAA,MACL,MAAM,mBAAmB;AAAA,MACzB,SAAS;AAAA,IACV;AAAA,EACD,CAAsC;AACvC;AAGO,SAAS,qBAAwC;AACvD,MAAI,QAAQ,sBAAsB,IAAI;AACtC,MAAI,CAAC,OAAO;AACX,YAAQ,oBAAoB;AAC5B,uBAAmB,KAAK;AAAA,EACzB;AACA,SAAO;AACR;",
4
+ "sourcesContent": ["import { atom } from '@tldraw/state'\nimport { getDefaultTranslationLocale } from '@tldraw/tlschema'\nimport { getFromLocalStorage, setInLocalStorage, structuredClone, uniqueId } from '@tldraw/utils'\nimport { T } from '@tldraw/validate'\n\nconst USER_DATA_KEY = 'TLDRAW_USER_DATA_v3'\n\n/**\n * A user of tldraw\n *\n * @public\n */\nexport interface TLUserPreferences {\n\tid: string\n\tname?: string | null\n\tcolor?: string | null\n\t// N.B. These are duplicated in TLdrawAppUser.\n\tlocale?: string | null\n\tanimationSpeed?: number | null\n\tareKeyboardShortcutsEnabled?: boolean | null\n\tedgeScrollSpeed?: number | null\n\tcolorScheme?: 'light' | 'dark' | 'system'\n\tisSnapMode?: boolean | null\n\tisWrapMode?: boolean | null\n\tisDynamicSizeMode?: boolean | null\n\tisPasteAtCursorMode?: boolean | null\n\tshowUiLabels?: boolean | null\n}\n\ninterface UserDataSnapshot {\n\tversion: number\n\tuser: TLUserPreferences\n}\n\ninterface UserChangeBroadcastMessage {\n\ttype: typeof broadcastEventKey\n\torigin: string\n\tdata: UserDataSnapshot\n}\n\n/** @public */\nexport const userTypeValidator: T.Validator<TLUserPreferences> = T.object<TLUserPreferences>({\n\tid: T.string,\n\tname: T.string.nullable().optional(),\n\tcolor: T.string.nullable().optional(),\n\t// N.B. These are duplicated in TLdrawAppUser.\n\tlocale: T.string.nullable().optional(),\n\tanimationSpeed: T.number.nullable().optional(),\n\tareKeyboardShortcutsEnabled: T.boolean.nullable().optional(),\n\tedgeScrollSpeed: T.number.nullable().optional(),\n\tcolorScheme: T.literalEnum('light', 'dark', 'system').optional(),\n\tisSnapMode: T.boolean.nullable().optional(),\n\tisWrapMode: T.boolean.nullable().optional(),\n\tisDynamicSizeMode: T.boolean.nullable().optional(),\n\tisPasteAtCursorMode: T.boolean.nullable().optional(),\n\tshowUiLabels: T.boolean.nullable().optional(),\n})\n\nconst Versions = {\n\tAddAnimationSpeed: 1,\n\tAddIsSnapMode: 2,\n\tMakeFieldsNullable: 3,\n\tAddEdgeScrollSpeed: 4,\n\tAddExcalidrawSelectMode: 5,\n\tAddDynamicSizeMode: 6,\n\tAllowSystemColorScheme: 7,\n\tAddPasteAtCursor: 8,\n\tAddKeyboardShortcuts: 9,\n\tAddShowUiLabels: 10,\n} as const\n\nconst CURRENT_VERSION = Math.max(...Object.values(Versions))\n\nfunction migrateSnapshot(data: { version: number; user: any }) {\n\tif (data.version < Versions.AddAnimationSpeed) {\n\t\tdata.user.animationSpeed = 1\n\t}\n\tif (data.version < Versions.AddIsSnapMode) {\n\t\tdata.user.isSnapMode = false\n\t}\n\tif (data.version < Versions.MakeFieldsNullable) {\n\t\t// noop\n\t}\n\tif (data.version < Versions.AddEdgeScrollSpeed) {\n\t\tdata.user.edgeScrollSpeed = 1\n\t}\n\tif (data.version < Versions.AddExcalidrawSelectMode) {\n\t\tdata.user.isWrapMode = false\n\t}\n\tif (data.version < Versions.AllowSystemColorScheme) {\n\t\tif (data.user.isDarkMode === true) {\n\t\t\tdata.user.colorScheme = 'dark'\n\t\t} else if (data.user.isDarkMode === false) {\n\t\t\tdata.user.colorScheme = 'light'\n\t\t}\n\t\tdelete data.user.isDarkMode\n\t}\n\n\tif (data.version < Versions.AddDynamicSizeMode) {\n\t\tdata.user.isDynamicSizeMode = false\n\t}\n\tif (data.version < Versions.AddPasteAtCursor) {\n\t\tdata.user.isPasteAtCursorMode = false\n\t}\n\tif (data.version < Versions.AddKeyboardShortcuts) {\n\t\tdata.user.areKeyboardShortcutsEnabled = true\n\t}\n\tif (data.version < Versions.AddShowUiLabels) {\n\t\tdata.user.showUiLabels = false\n\t}\n\n\t// finally\n\tdata.version = CURRENT_VERSION\n}\n\n/** @internal */\nexport const USER_COLORS = [\n\t'#FF802B',\n\t'#EC5E41',\n\t'#F2555A',\n\t'#F04F88',\n\t'#E34BA9',\n\t'#BD54C6',\n\t'#9D5BD2',\n\t'#7B66DC',\n\t'#02B1CC',\n\t'#11B3A3',\n\t'#39B178',\n\t'#55B467',\n] as const\n\nfunction getRandomColor() {\n\treturn USER_COLORS[Math.floor(Math.random() * USER_COLORS.length)]\n}\n\n/** @internal */\nexport function userPrefersReducedMotion() {\n\tif (typeof window !== 'undefined' && window.matchMedia) {\n\t\treturn window.matchMedia?.('(prefers-reduced-motion: reduce)')?.matches ?? false\n\t}\n\n\treturn false\n}\n\n/** @public */\nexport const defaultUserPreferences = Object.freeze({\n\tname: '',\n\tlocale: getDefaultTranslationLocale(),\n\tcolor: getRandomColor(),\n\n\t// N.B. These are duplicated in TLdrawAppUser.\n\tedgeScrollSpeed: 1,\n\tanimationSpeed: userPrefersReducedMotion() ? 0 : 1,\n\tareKeyboardShortcutsEnabled: true,\n\tisSnapMode: false,\n\tisWrapMode: false,\n\tisDynamicSizeMode: false,\n\tisPasteAtCursorMode: false,\n\tshowUiLabels: false,\n\tcolorScheme: 'light',\n}) satisfies Readonly<Omit<TLUserPreferences, 'id'>>\n\n/** @public */\nexport function getFreshUserPreferences(): TLUserPreferences {\n\treturn {\n\t\tid: uniqueId(),\n\t\tcolor: getRandomColor(),\n\t}\n}\n\nfunction migrateUserPreferences(userData: unknown): TLUserPreferences {\n\tif (userData === null || typeof userData !== 'object') {\n\t\treturn getFreshUserPreferences()\n\t}\n\n\tif (!('version' in userData) || !('user' in userData) || typeof userData.version !== 'number') {\n\t\treturn getFreshUserPreferences()\n\t}\n\n\tconst snapshot = structuredClone(userData) as any\n\n\tmigrateSnapshot(snapshot)\n\n\ttry {\n\t\treturn userTypeValidator.validate(snapshot.user)\n\t} catch {\n\t\treturn getFreshUserPreferences()\n\t}\n}\n\nfunction loadUserPreferences(): TLUserPreferences {\n\tconst userData = (JSON.parse(getFromLocalStorage(USER_DATA_KEY) || 'null') ??\n\t\tnull) as null | UserDataSnapshot\n\n\treturn migrateUserPreferences(userData)\n}\n\nconst globalUserPreferences = atom<TLUserPreferences | null>('globalUserData', null)\n\nfunction storeUserPreferences() {\n\tsetInLocalStorage(\n\t\tUSER_DATA_KEY,\n\t\tJSON.stringify({\n\t\t\tversion: CURRENT_VERSION,\n\t\t\tuser: globalUserPreferences.get(),\n\t\t})\n\t)\n}\n\n/** @public */\nexport function setUserPreferences(user: TLUserPreferences) {\n\tuserTypeValidator.validate(user)\n\tglobalUserPreferences.set(user)\n\tstoreUserPreferences()\n\tbroadcastUserPreferencesChange()\n}\n\nconst isTest = typeof process !== 'undefined' && process.env.NODE_ENV === 'test'\n\nconst channel =\n\ttypeof BroadcastChannel !== 'undefined' && !isTest\n\t\t? new BroadcastChannel('tldraw-user-sync')\n\t\t: null\n\nchannel?.addEventListener('message', (e) => {\n\tconst data = e.data as undefined | UserChangeBroadcastMessage\n\tif (data?.type === broadcastEventKey && data?.origin !== getBroadcastOrigin()) {\n\t\tglobalUserPreferences.set(migrateUserPreferences(data.data))\n\t}\n})\n\nlet _broadcastOrigin = null as null | string\nfunction getBroadcastOrigin() {\n\tif (_broadcastOrigin === null) {\n\t\t_broadcastOrigin = uniqueId()\n\t}\n\treturn _broadcastOrigin\n}\nconst broadcastEventKey = 'tldraw-user-preferences-change' as const\n\nfunction broadcastUserPreferencesChange() {\n\tchannel?.postMessage({\n\t\ttype: broadcastEventKey,\n\t\torigin: getBroadcastOrigin(),\n\t\tdata: {\n\t\t\tuser: getUserPreferences(),\n\t\t\tversion: CURRENT_VERSION,\n\t\t},\n\t} satisfies UserChangeBroadcastMessage)\n}\n\n/** @public */\nexport function getUserPreferences(): TLUserPreferences {\n\tlet prefs = globalUserPreferences.get()\n\tif (!prefs) {\n\t\tprefs = loadUserPreferences()\n\t\tsetUserPreferences(prefs)\n\t}\n\treturn prefs\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAqB;AACrB,sBAA4C;AAC5C,mBAAkF;AAClF,sBAAkB;AAElB,MAAM,gBAAgB;AAoCf,MAAM,oBAAoD,kBAAE,OAA0B;AAAA,EAC5F,IAAI,kBAAE;AAAA,EACN,MAAM,kBAAE,OAAO,SAAS,EAAE,SAAS;AAAA,EACnC,OAAO,kBAAE,OAAO,SAAS,EAAE,SAAS;AAAA;AAAA,EAEpC,QAAQ,kBAAE,OAAO,SAAS,EAAE,SAAS;AAAA,EACrC,gBAAgB,kBAAE,OAAO,SAAS,EAAE,SAAS;AAAA,EAC7C,6BAA6B,kBAAE,QAAQ,SAAS,EAAE,SAAS;AAAA,EAC3D,iBAAiB,k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AAM;AAAA,IACN,QAAQ,mBAAmB;AAAA,IAC3B,MAAM;AAAA,MACL,MAAM,mBAAmB;AAAA,MACzB,SAAS;AAAA,IACV;AAAA,EACD,CAAsC;AACvC;AAGO,SAAS,qBAAwC;AACvD,MAAI,QAAQ,sBAAsB,IAAI;AACtC,MAAI,CAAC,OAAO;AACX,YAAQ,oBAAoB;AAC5B,uBAAmB,KAAK;AAAA,EACzB;AACA,SAAO;AACR;",
6
6
  "names": []
7
7
  }
@@ -88,7 +88,6 @@ var import_defaultShapes = require("../config/defaultShapes");
88
88
  var import_constants = require("../constants");
89
89
  var import_exportToSvg = require("../exports/exportToSvg");
90
90
  var import_getSvgAsImage = require("../exports/getSvgAsImage");
91
- var import_environment = require("../globals/environment");
92
91
  var import_menus = require("../globals/menus");
93
92
  var import_time = require("../globals/time");
94
93
  var import_options = require("../options");
@@ -123,8 +122,8 @@ var import_TextManager = require("./managers/TextManager/TextManager");
123
122
  var import_TickManager = require("./managers/TickManager/TickManager");
124
123
  var import_UserPreferencesManager = require("./managers/UserPreferencesManager/UserPreferencesManager");
125
124
  var import_RootState = require("./tools/RootState");
126
- var __setMetaKeyTimeout_dec, __setCtrlKeyTimeout_dec, __setAltKeyTimeout_dec, __setShiftKeyTimeout_dec, _getIsReadonly_dec, _getIsFocused_dec, _getSharedOpacity_dec, _getSharedStyles_dec, __getSelectionSharedStyles_dec, __getBindingsIndexCache_dec, _getCurrentPageRenderingShapesSorted_dec, _getCurrentPageShapesSorted_dec, _getCurrentPageShapes_dec, _getCurrentPageBounds_dec, _getCulledShapes_dec, _getNotVisibleShapes_dec, __getShapeMaskedPageBoundsCache_dec, __getShapeMaskCache_dec, __getShapeClipPathCache_dec, __getShapePageBoundsCache_dec, __getShapePageTransformCache_dec, __getShapeHandlesCache_dec, __getAllAssetsQuery_dec, _getCurrentPageShapeIdsSorted_dec, _getCurrentPageId_dec, _getPages_dec, __getAllPagesQuery_dec, _getRenderingShapes_dec, _getCollaboratorsOnCurrentPage_dec, _getCollaborators_dec, __getCollaboratorsQuery_dec, _getViewportPageBounds_dec, _getViewportScreenCenter_dec, _getViewportScreenBounds_dec, _getZoomLevel_dec, _getCameraForFollowing_dec, _getViewportPageBoundsForFollowing_dec, _getCamera_dec, __unsafe_getCameraId_dec, _getErasingShapes_dec, _getErasingShapeIds_dec, _getHintingShape_dec, _getHintingShapeIds_dec, _getHoveredShape_dec, _getHoveredShapeId_dec, _getRichTextEditor_dec, _getEditingShape_dec, _getEditingShapeId_dec, _getFocusedGroup_dec, _getFocusedGroupId_dec, _getSelectionRotatedScreenBounds_dec, _getSelectionRotatedPageBounds_dec, _getSelectionRotation_dec, _getSelectionPageBounds_dec, _getOnlySelectedShape_dec, _getOnlySelectedShapeId_dec, _getCurrentPageShapesInReadingOrder_dec, _getSelectedShapes_dec, _getSelectedShapeIds_dec, __getCurrentPageStateId_dec, _getCurrentPageState_dec, __getPageStatesQuery_dec, _getPageStates_dec, _getIsMenuOpen_dec, _getOpenMenus_dec, _getInstanceState_dec, _getDocumentSettings_dec, _getCurrentToolId_dec, _getCurrentTool_dec, _getPath_dec, _getCanRedo_dec, _getCanUndo_dec, _getIsShapeHiddenCache_dec, _a, _init;
127
- class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_dec = [import_state.computed], _getCanUndo_dec = [import_state.computed], _getCanRedo_dec = [import_state.computed], _getPath_dec = [import_state.computed], _getCurrentTool_dec = [import_state.computed], _getCurrentToolId_dec = [import_state.computed], _getDocumentSettings_dec = [import_state.computed], _getInstanceState_dec = [import_state.computed], _getOpenMenus_dec = [import_state.computed], _getIsMenuOpen_dec = [import_state.computed], _getPageStates_dec = [import_state.computed], __getPageStatesQuery_dec = [import_state.computed], _getCurrentPageState_dec = [import_state.computed], __getCurrentPageStateId_dec = [import_state.computed], _getSelectedShapeIds_dec = [import_state.computed], _getSelectedShapes_dec = [import_state.computed], _getCurrentPageShapesInReadingOrder_dec = [import_state.computed], _getOnlySelectedShapeId_dec = [import_state.computed], _getOnlySelectedShape_dec = [import_state.computed], _getSelectionPageBounds_dec = [import_state.computed], _getSelectionRotation_dec = [import_state.computed], _getSelectionRotatedPageBounds_dec = [import_state.computed], _getSelectionRotatedScreenBounds_dec = [import_state.computed], _getFocusedGroupId_dec = [import_state.computed], _getFocusedGroup_dec = [import_state.computed], _getEditingShapeId_dec = [import_state.computed], _getEditingShape_dec = [import_state.computed], _getRichTextEditor_dec = [import_state.computed], _getHoveredShapeId_dec = [import_state.computed], _getHoveredShape_dec = [import_state.computed], _getHintingShapeIds_dec = [import_state.computed], _getHintingShape_dec = [import_state.computed], _getErasingShapeIds_dec = [import_state.computed], _getErasingShapes_dec = [import_state.computed], __unsafe_getCameraId_dec = [import_state.computed], _getCamera_dec = [import_state.computed], _getViewportPageBoundsForFollowing_dec = [import_state.computed], _getCameraForFollowing_dec = [import_state.computed], _getZoomLevel_dec = [import_state.computed], _getViewportScreenBounds_dec = [import_state.computed], _getViewportScreenCenter_dec = [import_state.computed], _getViewportPageBounds_dec = [import_state.computed], __getCollaboratorsQuery_dec = [import_state.computed], _getCollaborators_dec = [import_state.computed], _getCollaboratorsOnCurrentPage_dec = [import_state.computed], _getRenderingShapes_dec = [import_state.computed], __getAllPagesQuery_dec = [import_state.computed], _getPages_dec = [import_state.computed], _getCurrentPageId_dec = [import_state.computed], _getCurrentPageShapeIdsSorted_dec = [import_state.computed], __getAllAssetsQuery_dec = [import_state.computed], __getShapeHandlesCache_dec = [import_state.computed], __getShapePageTransformCache_dec = [import_state.computed], __getShapePageBoundsCache_dec = [import_state.computed], __getShapeClipPathCache_dec = [import_state.computed], __getShapeMaskCache_dec = [import_state.computed], __getShapeMaskedPageBoundsCache_dec = [import_state.computed], _getNotVisibleShapes_dec = [import_state.computed], _getCulledShapes_dec = [import_state.computed], _getCurrentPageBounds_dec = [import_state.computed], _getCurrentPageShapes_dec = [import_state.computed], _getCurrentPageShapesSorted_dec = [import_state.computed], _getCurrentPageRenderingShapesSorted_dec = [import_state.computed], __getBindingsIndexCache_dec = [import_state.computed], __getSelectionSharedStyles_dec = [import_state.computed], _getSharedStyles_dec = [(0, import_state.computed)({ isEqual: (a, b) => a.equals(b) })], _getSharedOpacity_dec = [import_state.computed], _getIsFocused_dec = [import_state.computed], _getIsReadonly_dec = [import_state.computed], __setShiftKeyTimeout_dec = [import_utils.bind], __setAltKeyTimeout_dec = [import_utils.bind], __setCtrlKeyTimeout_dec = [import_utils.bind], __setMetaKeyTimeout_dec = [import_utils.bind], _a) {
125
+ var __setMetaKeyTimeout_dec, __setCtrlKeyTimeout_dec, __setAltKeyTimeout_dec, __setShiftKeyTimeout_dec, _getIsReadonly_dec, _getIsFocused_dec, _getSharedOpacity_dec, _getSharedStyles_dec, __getSelectionSharedStyles_dec, __getBindingsIndexCache_dec, _getCurrentPageRenderingShapesSorted_dec, _getCurrentPageShapesSorted_dec, _getCurrentPageShapes_dec, _getCurrentPageBounds_dec, _getCulledShapes_dec, _getNotVisibleShapes_dec, __getShapeMaskedPageBoundsCache_dec, __getShapeMaskCache_dec, __getShapeClipPathCache_dec, __getShapePageBoundsCache_dec, __getShapePageTransformCache_dec, __getShapeHandlesCache_dec, __getAllAssetsQuery_dec, _getCurrentPageShapeIdsSorted_dec, _getCurrentPageId_dec, _getPages_dec, __getAllPagesQuery_dec, _getRenderingShapes_dec, _getCollaboratorsOnCurrentPage_dec, _getCollaborators_dec, __getCollaboratorsQuery_dec, _getViewportPageBounds_dec, _getViewportScreenCenter_dec, _getViewportScreenBounds_dec, _getZoomLevel_dec, _getCameraForFollowing_dec, _getViewportPageBoundsForFollowing_dec, _getCamera_dec, __unsafe_getCameraId_dec, _getErasingShapes_dec, _getErasingShapeIds_dec, _getHintingShape_dec, _getHintingShapeIds_dec, _getHoveredShape_dec, _getHoveredShapeId_dec, _getRichTextEditor_dec, _getEditingShape_dec, _getEditingShapeId_dec, _getFocusedGroup_dec, _getFocusedGroupId_dec, _getSelectionRotatedScreenBounds_dec, _getSelectionRotatedPageBounds_dec, _getSelectionRotation_dec, _getSelectionPageBounds_dec, _getOnlySelectedShape_dec, _getOnlySelectedShapeId_dec, _getCurrentPageShapesInReadingOrder_dec, _getSelectedShapes_dec, _getSelectedShapeIds_dec, __getCurrentPageStateId_dec, _getCurrentPageState_dec, __getPageStatesQuery_dec, _getPageStates_dec, _getInstanceState_dec, _getDocumentSettings_dec, _getCurrentToolId_dec, _getCurrentTool_dec, _getPath_dec, _getCanRedo_dec, _getCanUndo_dec, _getIsShapeHiddenCache_dec, _a, _init;
126
+ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_dec = [import_state.computed], _getCanUndo_dec = [import_state.computed], _getCanRedo_dec = [import_state.computed], _getPath_dec = [import_state.computed], _getCurrentTool_dec = [import_state.computed], _getCurrentToolId_dec = [import_state.computed], _getDocumentSettings_dec = [import_state.computed], _getInstanceState_dec = [import_state.computed], _getPageStates_dec = [import_state.computed], __getPageStatesQuery_dec = [import_state.computed], _getCurrentPageState_dec = [import_state.computed], __getCurrentPageStateId_dec = [import_state.computed], _getSelectedShapeIds_dec = [import_state.computed], _getSelectedShapes_dec = [import_state.computed], _getCurrentPageShapesInReadingOrder_dec = [import_state.computed], _getOnlySelectedShapeId_dec = [import_state.computed], _getOnlySelectedShape_dec = [import_state.computed], _getSelectionPageBounds_dec = [import_state.computed], _getSelectionRotation_dec = [import_state.computed], _getSelectionRotatedPageBounds_dec = [import_state.computed], _getSelectionRotatedScreenBounds_dec = [import_state.computed], _getFocusedGroupId_dec = [import_state.computed], _getFocusedGroup_dec = [import_state.computed], _getEditingShapeId_dec = [import_state.computed], _getEditingShape_dec = [import_state.computed], _getRichTextEditor_dec = [import_state.computed], _getHoveredShapeId_dec = [import_state.computed], _getHoveredShape_dec = [import_state.computed], _getHintingShapeIds_dec = [import_state.computed], _getHintingShape_dec = [import_state.computed], _getErasingShapeIds_dec = [import_state.computed], _getErasingShapes_dec = [import_state.computed], __unsafe_getCameraId_dec = [import_state.computed], _getCamera_dec = [import_state.computed], _getViewportPageBoundsForFollowing_dec = [import_state.computed], _getCameraForFollowing_dec = [import_state.computed], _getZoomLevel_dec = [import_state.computed], _getViewportScreenBounds_dec = [import_state.computed], _getViewportScreenCenter_dec = [import_state.computed], _getViewportPageBounds_dec = [import_state.computed], __getCollaboratorsQuery_dec = [import_state.computed], _getCollaborators_dec = [import_state.computed], _getCollaboratorsOnCurrentPage_dec = [import_state.computed], _getRenderingShapes_dec = [import_state.computed], __getAllPagesQuery_dec = [import_state.computed], _getPages_dec = [import_state.computed], _getCurrentPageId_dec = [import_state.computed], _getCurrentPageShapeIdsSorted_dec = [import_state.computed], __getAllAssetsQuery_dec = [import_state.computed], __getShapeHandlesCache_dec = [import_state.computed], __getShapePageTransformCache_dec = [import_state.computed], __getShapePageBoundsCache_dec = [import_state.computed], __getShapeClipPathCache_dec = [import_state.computed], __getShapeMaskCache_dec = [import_state.computed], __getShapeMaskedPageBoundsCache_dec = [import_state.computed], _getNotVisibleShapes_dec = [import_state.computed], _getCulledShapes_dec = [import_state.computed], _getCurrentPageBounds_dec = [import_state.computed], _getCurrentPageShapes_dec = [import_state.computed], _getCurrentPageShapesSorted_dec = [import_state.computed], _getCurrentPageRenderingShapesSorted_dec = [import_state.computed], __getBindingsIndexCache_dec = [import_state.computed], __getSelectionSharedStyles_dec = [import_state.computed], _getSharedStyles_dec = [(0, import_state.computed)({ isEqual: (a, b) => a.equals(b) })], _getSharedOpacity_dec = [import_state.computed], _getIsFocused_dec = [import_state.computed], _getIsReadonly_dec = [import_state.computed], __setShiftKeyTimeout_dec = [import_utils.bind], __setAltKeyTimeout_dec = [import_utils.bind], __setCtrlKeyTimeout_dec = [import_utils.bind], __setMetaKeyTimeout_dec = [import_utils.bind], _a) {
128
127
  constructor({
129
128
  store,
130
129
  user,
@@ -138,8 +137,6 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
138
137
  autoFocus,
139
138
  inferDarkMode,
140
139
  options,
141
- // eslint-disable-next-line @typescript-eslint/no-deprecated
142
- isShapeHidden,
143
140
  getShapeVisibility,
144
141
  fontAssetUrls
145
142
  }) {
@@ -206,13 +203,6 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
206
203
  * @public
207
204
  */
208
205
  __publicField(this, "fonts");
209
- /**
210
- * A manager for the editor's environment.
211
- *
212
- * @deprecated This is deprecated and will be removed in a future version. Use the `tlenv` global export instead.
213
- * @public
214
- */
215
- __publicField(this, "environment", import_environment.tlenv);
216
206
  /**
217
207
  * A manager for the editor's scribbles.
218
208
  *
@@ -415,14 +405,7 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
415
405
  /** @internal */
416
406
  __publicField(this, "performanceTrackerTimeout", -1);
417
407
  __publicField(this, "_pendingEventsForNextTick", []);
418
- (0, import_utils.assert)(
419
- !(isShapeHidden && getShapeVisibility),
420
- "Cannot use both isShapeHidden and getShapeVisibility"
421
- );
422
- this._getShapeVisibility = isShapeHidden ? (
423
- // eslint-disable-next-line @typescript-eslint/no-deprecated
424
- (shape, editor) => isShapeHidden(shape, editor) ? "hidden" : "inherit"
425
- ) : getShapeVisibility;
408
+ this._getShapeVisibility = getShapeVisibility;
426
409
  this.options = { ...import_options.defaultTldrawOptions, ...options };
427
410
  this.store = store;
428
411
  this.history = new import_HistoryManager.HistoryManager({
@@ -902,34 +885,6 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
902
885
  getCanRedo() {
903
886
  return this.history.getNumRedos() > 0;
904
887
  }
905
- /**
906
- * Create a new "mark", or stopping point, in the undo redo history. Creating a mark will clear
907
- * any redos.
908
- *
909
- * @example
910
- * ```ts
911
- * editor.mark()
912
- * editor.mark('flip shapes')
913
- * ```
914
- *
915
- * @param markId - The mark's id, usually the reason for adding the mark.
916
- *
917
- * @public
918
- * @deprecated use {@link Editor.markHistoryStoppingPoint} instead
919
- */
920
- mark(markId) {
921
- if (typeof markId === "string") {
922
- console.warn(
923
- `[tldraw] \`editor.history.mark("${markId}")\` is deprecated. Please use \`const myMarkId = editor.markHistoryStoppingPoint()\` instead.`
924
- );
925
- } else {
926
- console.warn(
927
- "[tldraw] `editor.mark()` is deprecated. Use `editor.markHistoryStoppingPoint()` instead."
928
- );
929
- }
930
- this.history._mark(markId ?? (0, import_utils.uniqueId)());
931
- return this;
932
- }
933
888
  /**
934
889
  * Create a new "mark", or stopping point, in the undo redo history. Creating a mark will clear
935
890
  * any redos. You typically want to do this just before a user interaction begins or is handled.
@@ -1045,12 +1000,6 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
1045
1000
  }
1046
1001
  return this;
1047
1002
  }
1048
- /**
1049
- * @deprecated Use `Editor.run` instead.
1050
- */
1051
- batch(fn, opts) {
1052
- return this.run(fn, opts);
1053
- }
1054
1003
  /* --------------------- Errors --------------------- */
1055
1004
  /** @internal */
1056
1005
  annotateError(error, {
@@ -1272,39 +1221,6 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
1272
1221
  ]);
1273
1222
  }, opts);
1274
1223
  }
1275
- getOpenMenus() {
1276
- return this.menus.getOpenMenus();
1277
- }
1278
- /**
1279
- * @deprecated Use `editor.menus.addOpenMenu` instead.
1280
- *
1281
- * @public
1282
- */
1283
- addOpenMenu(id) {
1284
- this.menus.addOpenMenu(id);
1285
- return this;
1286
- }
1287
- /**
1288
- * @deprecated Use `editor.menus.deleteOpenMenu` instead.
1289
- *
1290
- * @public
1291
- */
1292
- deleteOpenMenu(id) {
1293
- this.menus.deleteOpenMenu(id);
1294
- return this;
1295
- }
1296
- /**
1297
- * @deprecated Use `editor.menus.clearOpenMenus` instead.
1298
- *
1299
- * @public
1300
- */
1301
- clearOpenMenus() {
1302
- this.menus.clearOpenMenus();
1303
- return this;
1304
- }
1305
- getIsMenuOpen() {
1306
- return this.menus.hasAnyOpenMenus();
1307
- }
1308
1224
  /* --------------------- Cursor --------------------- */
1309
1225
  /**
1310
1226
  * Set the cursor.
@@ -3612,8 +3528,9 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
3612
3528
  return this.store.createComputedCache("pageBoundsCache", (shape) => {
3613
3529
  const pageTransform = this.getShapePageTransform(shape);
3614
3530
  if (!pageTransform) return void 0;
3615
- const geometry = this.getShapeGeometry(shape);
3616
- return import_Box.Box.FromPoints(pageTransform.applyToPoints(geometry.vertices));
3531
+ return import_Box.Box.FromPoints(
3532
+ pageTransform.applyToPoints(this.getShapeGeometry(shape).boundsVertices)
3533
+ );
3617
3534
  });
3618
3535
  }
3619
3536
  /**
@@ -3666,16 +3583,17 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
3666
3583
  _getShapeMaskCache() {
3667
3584
  return this.store.createComputedCache("pageMaskCache", (shape) => {
3668
3585
  if ((0, import_tlschema.isPageId)(shape.parentId)) return void 0;
3669
- const frameAncestors = this.getShapeAncestors(shape.id).filter(
3670
- (shape2) => this.isShapeOfType(shape2, "frame")
3671
- );
3672
- if (frameAncestors.length === 0) return void 0;
3673
- const pageMask = frameAncestors.map((s) => {
3674
- const geometry = this.getShapeGeometry(s.id);
3675
- const pageTransform = this.getShapePageTransform(s.id);
3676
- return pageTransform.applyToPoints(geometry.vertices);
3677
- }).reduce((acc, b) => {
3678
- if (!(b && acc)) return void 0;
3586
+ const clipPaths = [];
3587
+ for (const ancestor of this.getShapeAncestors(shape.id)) {
3588
+ const util = this.getShapeUtil(ancestor);
3589
+ const clipPath = util.getClipPath?.(ancestor);
3590
+ if (!clipPath) continue;
3591
+ if (util.shouldClipChild?.(shape) === false) continue;
3592
+ const pageTransform = this.getShapePageTransform(ancestor.id);
3593
+ clipPaths.push(pageTransform.applyToPoints(clipPath));
3594
+ }
3595
+ if (clipPaths.length === 0) return void 0;
3596
+ const pageMask = clipPaths.reduce((acc, b) => {
3679
3597
  const intersection = (0, import_intersect.intersectPolygonPolygon)(acc, b);
3680
3598
  if (intersection) {
3681
3599
  return intersection.map(import_Vec.Vec.Cast);
@@ -3910,6 +3828,7 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
3910
3828
  hitInside = false,
3911
3829
  hitFrameInside = false
3912
3830
  } = opts;
3831
+ const [innerMargin, outerMargin] = Array.isArray(margin) ? margin : [margin, margin];
3913
3832
  let inHollowSmallestArea = Infinity;
3914
3833
  let inHollowSmallestAreaHit = null;
3915
3834
  let inMarginClosestToEdgeDistance = Infinity;
@@ -3919,7 +3838,7 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
3919
3838
  return false;
3920
3839
  const pageMask = this.getShapeMask(shape);
3921
3840
  if (pageMask && !(0, import_utils2.pointInPolygon)(point, pageMask)) return false;
3922
- if (filter) return filter(shape);
3841
+ if (filter && !filter(shape)) return false;
3923
3842
  return true;
3924
3843
  });
3925
3844
  for (let i = shapesToCheck.length - 1; i >= 0; i--) {
@@ -3935,8 +3854,8 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
3935
3854
  }
3936
3855
  }
3937
3856
  if (this.isShapeOfType(shape, "frame")) {
3938
- const distance2 = geometry.distanceToPoint(pointInShapeSpace, hitInside);
3939
- if (Math.abs(distance2) <= margin) {
3857
+ const distance2 = geometry.distanceToPoint(pointInShapeSpace, hitFrameInside);
3858
+ if (hitFrameInside ? distance2 > 0 && distance2 <= outerMargin || distance2 <= 0 && distance2 > -innerMargin : distance2 > 0 && distance2 <= outerMargin) {
3940
3859
  return inMarginClosestToEdgeHit || shape;
3941
3860
  }
3942
3861
  if (geometry.hitTestPoint(pointInShapeSpace, 0, true)) {
@@ -3956,10 +3875,10 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
3956
3875
  }
3957
3876
  distance = minDistance;
3958
3877
  } else {
3959
- if (margin === 0 && (geometry.bounds.w < 1 || geometry.bounds.h < 1)) {
3878
+ if (outerMargin === 0 && (geometry.bounds.w < 1 || geometry.bounds.h < 1)) {
3960
3879
  distance = geometry.distanceToPoint(pointInShapeSpace, hitInside);
3961
3880
  } else {
3962
- if (geometry.bounds.containsPoint(pointInShapeSpace, margin)) {
3881
+ if (geometry.bounds.containsPoint(pointInShapeSpace, outerMargin)) {
3963
3882
  distance = geometry.distanceToPoint(pointInShapeSpace, hitInside);
3964
3883
  } else {
3965
3884
  distance = Infinity;
@@ -3967,12 +3886,22 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
3967
3886
  }
3968
3887
  }
3969
3888
  if (geometry.isClosed) {
3970
- if (distance <= margin) {
3889
+ if (distance <= outerMargin || hitInside && distance <= 0 && distance > -innerMargin) {
3971
3890
  if (geometry.isFilled || isGroup && geometry.children[0].isFilled) {
3972
3891
  return inMarginClosestToEdgeHit || shape;
3973
3892
  } else {
3974
3893
  if (this.getShapePageBounds(shape).contains(viewportPageBounds)) continue;
3975
- if (Math.abs(distance) < margin) {
3894
+ if (hitInside ? (
3895
+ // On hitInside, the distance will be negative for hits inside
3896
+ // If the distance is positive, check against the outer margin
3897
+ distance > 0 && distance <= outerMargin || // If the distance is negative, check against the inner margin
3898
+ distance <= 0 && distance > -innerMargin
3899
+ ) : (
3900
+ // If hitInside is false, then sadly _we do not know_ whether the
3901
+ // point is inside or outside of the shape, so we check against
3902
+ // the max of the two margins
3903
+ Math.abs(distance) <= Math.max(innerMargin, outerMargin)
3904
+ )) {
3976
3905
  if (Math.abs(distance) < inMarginClosestToEdgeDistance) {
3977
3906
  inMarginClosestToEdgeDistance = Math.abs(distance);
3978
3907
  inMarginClosestToEdgeHit = shape;
@@ -4362,10 +4291,6 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
4362
4291
  }
4363
4292
  return shapeIds;
4364
4293
  }
4365
- /** @deprecated Use {@link Editor.getDraggingOverShape} instead */
4366
- getDroppingOverShape(point, droppingShapes) {
4367
- return this.getDraggingOverShape(point, droppingShapes);
4368
- }
4369
4294
  /**
4370
4295
  * Get the shape that some shapes should be dropped on at a given point.
4371
4296
  *
@@ -4737,7 +4662,16 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
4737
4662
  }
4738
4663
  this.createShapes(shapesToCreate);
4739
4664
  this.createBindings(bindingsToCreate);
4740
- this.setSelectedShapes((0, import_utils.compact)(ids.map((id) => shapeIds.get(id))));
4665
+ this.setSelectedShapes(
4666
+ (0, import_utils.compact)(
4667
+ ids.map((oldId) => {
4668
+ const newId = shapeIds.get(oldId);
4669
+ if (!newId) return null;
4670
+ if (!this.getShape(newId)) return null;
4671
+ return newId;
4672
+ })
4673
+ )
4674
+ );
4741
4675
  if (offset !== void 0) {
4742
4676
  const selectionPageBounds = this.getSelectionPageBounds();
4743
4677
  const viewportPageBounds = this.getViewportPageBounds();
@@ -5491,8 +5425,7 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
5491
5425
  const shapesMovingTogether = [shape];
5492
5426
  const boundsOfShapesMovingTogether = [shapePageBounds];
5493
5427
  if (!this.getShapeUtil(shape).canBeLaidOut?.(shape, {
5494
- type: "stretch",
5495
- shapes: shapesToStretchFirstPass
5428
+ type: "stretch"
5496
5429
  })) {
5497
5430
  continue;
5498
5431
  }
@@ -5817,21 +5750,24 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
5817
5750
  }
5818
5751
  if (!partial.parentId || !(this.store.has(partial.parentId) || shapes.some((p) => p.id === partial.parentId))) {
5819
5752
  let parentId = this.getFocusedGroupId();
5820
- for (let i = currentPageShapesSorted.length - 1; i >= 0; i--) {
5821
- const parent = currentPageShapesSorted[i];
5822
- const util = this.getShapeUtil(parent);
5823
- if (util.canReceiveNewChildrenOfType(parent, partial.type) && !this.isShapeHidden(parent) && this.isPointInShape(
5824
- parent,
5825
- // If no parent is provided, then we can treat the
5826
- // shape's provided x/y as being in the page's space.
5827
- { x: partial.x ?? 0, y: partial.y ?? 0 },
5828
- {
5829
- margin: 0,
5830
- hitInside: true
5753
+ const isPositioned = partial.x !== void 0 && partial.y !== void 0;
5754
+ if (isPositioned) {
5755
+ for (let i = currentPageShapesSorted.length - 1; i >= 0; i--) {
5756
+ const parent = currentPageShapesSorted[i];
5757
+ const util = this.getShapeUtil(parent);
5758
+ if (util.canReceiveNewChildrenOfType(parent, partial.type) && !this.isShapeHidden(parent) && this.isPointInShape(
5759
+ parent,
5760
+ // If no parent is provided, then we can treat the
5761
+ // shape's provided x/y as being in the page's space.
5762
+ { x: partial.x ?? 0, y: partial.y ?? 0 },
5763
+ {
5764
+ margin: 0,
5765
+ hitInside: true
5766
+ }
5767
+ )) {
5768
+ parentId = parent.id;
5769
+ break;
5831
5770
  }
5832
- )) {
5833
- parentId = parent.id;
5834
- break;
5835
5771
  }
5836
5772
  }
5837
5773
  const prevParentId = partial.parentId;
@@ -6865,12 +6801,6 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
6865
6801
  height: result.height
6866
6802
  };
6867
6803
  }
6868
- /** @deprecated Use {@link Editor.getSvgString} or {@link Editor.getSvgElement} instead. */
6869
- async getSvg(shapes, opts = {}) {
6870
- const result = await this.getSvgElement(shapes, opts);
6871
- if (!result) return void 0;
6872
- return result.svg;
6873
- }
6874
6804
  /**
6875
6805
  * Get an exported image of the given shapes.
6876
6806
  *
@@ -6920,6 +6850,23 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
6920
6850
  }
6921
6851
  }
6922
6852
  }
6853
+ /**
6854
+ * Get an exported image of the given shapes as a data URL.
6855
+ *
6856
+ * @param shapes - The shapes (or shape ids) to export.
6857
+ * @param opts - Options for the export.
6858
+ *
6859
+ * @returns A data URL of the image.
6860
+ * @public
6861
+ */
6862
+ async toImageDataUrl(shapes, opts = {}) {
6863
+ const { blob, width, height } = await this.toImage(shapes, opts);
6864
+ return {
6865
+ url: await import_utils.FileHelpers.blobToDataUrl(blob),
6866
+ width,
6867
+ height
6868
+ };
6869
+ }
6923
6870
  /**
6924
6871
  * Update the input points from a pointer, pinch, or wheel event.
6925
6872
  *
@@ -7834,8 +7781,6 @@ __decorateElement(_init, 1, "getCurrentTool", _getCurrentTool_dec, Editor);
7834
7781
  __decorateElement(_init, 1, "getCurrentToolId", _getCurrentToolId_dec, Editor);
7835
7782
  __decorateElement(_init, 1, "getDocumentSettings", _getDocumentSettings_dec, Editor);
7836
7783
  __decorateElement(_init, 1, "getInstanceState", _getInstanceState_dec, Editor);
7837
- __decorateElement(_init, 1, "getOpenMenus", _getOpenMenus_dec, Editor);
7838
- __decorateElement(_init, 1, "getIsMenuOpen", _getIsMenuOpen_dec, Editor);
7839
7784
  __decorateElement(_init, 1, "getPageStates", _getPageStates_dec, Editor);
7840
7785
  __decorateElement(_init, 1, "_getPageStatesQuery", __getPageStatesQuery_dec, Editor);
7841
7786
  __decorateElement(_init, 1, "getCurrentPageState", _getCurrentPageState_dec, Editor);