@tldraw/editor 3.12.0-canary.3acee343372d → 3.12.0-canary.3e2ed74b5e86

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 (104) hide show
  1. package/dist-cjs/index.d.ts +123 -17
  2. package/dist-cjs/index.js +3 -1
  3. package/dist-cjs/index.js.map +2 -2
  4. package/dist-cjs/lib/TldrawEditor.js +4 -0
  5. package/dist-cjs/lib/TldrawEditor.js.map +2 -2
  6. package/dist-cjs/lib/components/GeometryDebuggingView.js +2 -2
  7. package/dist-cjs/lib/components/GeometryDebuggingView.js.map +2 -2
  8. package/dist-cjs/lib/components/Shape.js +10 -14
  9. package/dist-cjs/lib/components/Shape.js.map +2 -2
  10. package/dist-cjs/lib/editor/Editor.js +79 -30
  11. package/dist-cjs/lib/editor/Editor.js.map +2 -2
  12. package/dist-cjs/lib/editor/derivations/notVisibleShapes.js +1 -1
  13. package/dist-cjs/lib/editor/derivations/notVisibleShapes.js.map +2 -2
  14. package/dist-cjs/lib/editor/managers/FontManager.js +1 -1
  15. package/dist-cjs/lib/editor/managers/FontManager.js.map +2 -2
  16. package/dist-cjs/lib/editor/shapes/group/GroupShapeUtil.js +1 -13
  17. package/dist-cjs/lib/editor/shapes/group/GroupShapeUtil.js.map +2 -2
  18. package/dist-cjs/lib/editor/tools/StateNode.js +4 -1
  19. package/dist-cjs/lib/editor/tools/StateNode.js.map +2 -2
  20. package/dist-cjs/lib/exports/StyleEmbedder.js +19 -5
  21. package/dist-cjs/lib/exports/StyleEmbedder.js.map +2 -2
  22. package/dist-cjs/lib/exports/cssRules.js +127 -0
  23. package/dist-cjs/lib/exports/cssRules.js.map +7 -0
  24. package/dist-cjs/lib/exports/parseCss.js +0 -69
  25. package/dist-cjs/lib/exports/parseCss.js.map +2 -2
  26. package/dist-cjs/lib/hooks/useCanvasEvents.js +12 -7
  27. package/dist-cjs/lib/hooks/useCanvasEvents.js.map +3 -3
  28. package/dist-cjs/lib/hooks/useGestureEvents.js +12 -6
  29. package/dist-cjs/lib/hooks/useGestureEvents.js.map +2 -2
  30. package/dist-cjs/lib/primitives/geometry/Geometry2d.js +133 -16
  31. package/dist-cjs/lib/primitives/geometry/Geometry2d.js.map +3 -3
  32. package/dist-cjs/lib/primitives/geometry/Group2d.js +54 -11
  33. package/dist-cjs/lib/primitives/geometry/Group2d.js.map +2 -2
  34. package/dist-cjs/lib/primitives/intersect.js +20 -0
  35. package/dist-cjs/lib/primitives/intersect.js.map +2 -2
  36. package/dist-cjs/lib/utils/debug-flags.js +2 -1
  37. package/dist-cjs/lib/utils/debug-flags.js.map +2 -2
  38. package/dist-cjs/lib/utils/reorderShapes.js +2 -8
  39. package/dist-cjs/lib/utils/reorderShapes.js.map +2 -2
  40. package/dist-cjs/version.js +3 -3
  41. package/dist-cjs/version.js.map +1 -1
  42. package/dist-esm/index.d.mts +123 -17
  43. package/dist-esm/index.mjs +8 -2
  44. package/dist-esm/index.mjs.map +2 -2
  45. package/dist-esm/lib/TldrawEditor.mjs +4 -0
  46. package/dist-esm/lib/TldrawEditor.mjs.map +2 -2
  47. package/dist-esm/lib/components/GeometryDebuggingView.mjs +3 -3
  48. package/dist-esm/lib/components/GeometryDebuggingView.mjs.map +2 -2
  49. package/dist-esm/lib/components/Shape.mjs +11 -15
  50. package/dist-esm/lib/components/Shape.mjs.map +2 -2
  51. package/dist-esm/lib/editor/Editor.mjs +79 -30
  52. package/dist-esm/lib/editor/Editor.mjs.map +2 -2
  53. package/dist-esm/lib/editor/derivations/notVisibleShapes.mjs +1 -1
  54. package/dist-esm/lib/editor/derivations/notVisibleShapes.mjs.map +2 -2
  55. package/dist-esm/lib/editor/managers/FontManager.mjs +1 -1
  56. package/dist-esm/lib/editor/managers/FontManager.mjs.map +2 -2
  57. package/dist-esm/lib/editor/shapes/group/GroupShapeUtil.mjs +1 -13
  58. package/dist-esm/lib/editor/shapes/group/GroupShapeUtil.mjs.map +2 -2
  59. package/dist-esm/lib/editor/tools/StateNode.mjs +4 -1
  60. package/dist-esm/lib/editor/tools/StateNode.mjs.map +2 -2
  61. package/dist-esm/lib/exports/StyleEmbedder.mjs +21 -12
  62. package/dist-esm/lib/exports/StyleEmbedder.mjs.map +2 -2
  63. package/dist-esm/lib/exports/cssRules.mjs +107 -0
  64. package/dist-esm/lib/exports/cssRules.mjs.map +7 -0
  65. package/dist-esm/lib/exports/parseCss.mjs +0 -69
  66. package/dist-esm/lib/exports/parseCss.mjs.map +2 -2
  67. package/dist-esm/lib/hooks/useCanvasEvents.mjs +12 -7
  68. package/dist-esm/lib/hooks/useCanvasEvents.mjs.map +3 -3
  69. package/dist-esm/lib/hooks/useGestureEvents.mjs +12 -6
  70. package/dist-esm/lib/hooks/useGestureEvents.mjs.map +2 -2
  71. package/dist-esm/lib/primitives/geometry/Geometry2d.mjs +137 -14
  72. package/dist-esm/lib/primitives/geometry/Geometry2d.mjs.map +2 -2
  73. package/dist-esm/lib/primitives/geometry/Group2d.mjs +55 -12
  74. package/dist-esm/lib/primitives/geometry/Group2d.mjs.map +2 -2
  75. package/dist-esm/lib/primitives/intersect.mjs +20 -0
  76. package/dist-esm/lib/primitives/intersect.mjs.map +2 -2
  77. package/dist-esm/lib/utils/debug-flags.mjs +2 -1
  78. package/dist-esm/lib/utils/debug-flags.mjs.map +2 -2
  79. package/dist-esm/lib/utils/reorderShapes.mjs +2 -8
  80. package/dist-esm/lib/utils/reorderShapes.mjs.map +2 -2
  81. package/dist-esm/version.mjs +3 -3
  82. package/dist-esm/version.mjs.map +1 -1
  83. package/editor.css +17 -11
  84. package/package.json +7 -7
  85. package/src/index.ts +6 -1
  86. package/src/lib/TldrawEditor.tsx +29 -3
  87. package/src/lib/components/GeometryDebuggingView.tsx +3 -3
  88. package/src/lib/components/Shape.tsx +15 -19
  89. package/src/lib/editor/Editor.ts +115 -38
  90. package/src/lib/editor/derivations/notVisibleShapes.ts +1 -1
  91. package/src/lib/editor/managers/FontManager.ts +1 -1
  92. package/src/lib/editor/shapes/group/GroupShapeUtil.tsx +3 -15
  93. package/src/lib/editor/tools/StateNode.ts +6 -1
  94. package/src/lib/exports/StyleEmbedder.ts +25 -15
  95. package/src/lib/exports/cssRules.ts +126 -0
  96. package/src/lib/exports/parseCss.ts +0 -79
  97. package/src/lib/hooks/useCanvasEvents.ts +14 -7
  98. package/src/lib/hooks/useGestureEvents.ts +12 -6
  99. package/src/lib/primitives/geometry/Geometry2d.ts +196 -16
  100. package/src/lib/primitives/geometry/Group2d.ts +76 -13
  101. package/src/lib/primitives/intersect.ts +41 -0
  102. package/src/lib/utils/debug-flags.ts +1 -0
  103. package/src/lib/utils/reorderShapes.ts +2 -9
  104. package/src/version.ts +3 -3
@@ -46,10 +46,10 @@ const Shape = (0, import_react.memo)(function Shape2({
46
46
  const bgContainerRef = (0, import_react.useRef)(null);
47
47
  (0, import_react.useEffect)(() => {
48
48
  return (0, import_state.react)("load fonts", () => {
49
- const fonts = editor.fonts.getShapeFontFaces(shape);
49
+ const fonts = editor.fonts.getShapeFontFaces(id);
50
50
  editor.fonts.requestFonts(fonts);
51
51
  });
52
- }, [editor, shape]);
52
+ }, [editor, id]);
53
53
  const memoizedStuffRef = (0, import_react.useRef)({
54
54
  transform: "",
55
55
  clipPath: "none",
@@ -92,18 +92,14 @@ const Shape = (0, import_react.memo)(function Shape2({
92
92
  },
93
93
  [editor]
94
94
  );
95
- (0, import_state_react.useQuickReactor)(
96
- "set opacity and z-index",
97
- () => {
98
- const container = containerRef.current;
99
- const bgContainer = bgContainerRef.current;
100
- (0, import_dom.setStyleProperty)(container, "opacity", opacity);
101
- (0, import_dom.setStyleProperty)(bgContainer, "opacity", opacity);
102
- (0, import_dom.setStyleProperty)(container, "z-index", index);
103
- (0, import_dom.setStyleProperty)(bgContainer, "z-index", backgroundIndex);
104
- },
105
- [opacity, index, backgroundIndex]
106
- );
95
+ (0, import_react.useLayoutEffect)(() => {
96
+ const container = containerRef.current;
97
+ const bgContainer = bgContainerRef.current;
98
+ (0, import_dom.setStyleProperty)(container, "opacity", opacity);
99
+ (0, import_dom.setStyleProperty)(bgContainer, "opacity", opacity);
100
+ (0, import_dom.setStyleProperty)(container, "z-index", index);
101
+ (0, import_dom.setStyleProperty)(bgContainer, "z-index", backgroundIndex);
102
+ }, [opacity, index, backgroundIndex]);
107
103
  (0, import_state_react.useQuickReactor)(
108
104
  "set display",
109
105
  () => {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/lib/components/Shape.tsx"],
4
- "sourcesContent": ["import { react } from '@tldraw/state'\nimport { useQuickReactor, useStateTracking } from '@tldraw/state-react'\nimport { TLShape, TLShapeId } from '@tldraw/tlschema'\nimport { memo, useCallback, useEffect, useRef } from 'react'\nimport { ShapeUtil } from '../editor/shapes/ShapeUtil'\nimport { useEditor } from '../hooks/useEditor'\nimport { useEditorComponents } from '../hooks/useEditorComponents'\nimport { Mat } from '../primitives/Mat'\nimport { setStyleProperty } from '../utils/dom'\nimport { OptionalErrorBoundary } from './ErrorBoundary'\n\n/*\nThis component renders shapes on the canvas. There are two stages: positioning\nand styling the shape's container using CSS, and then rendering the shape's \nJSX using its shape util's render method. Rendering the \"inside\" of a shape is\nmore expensive than positioning it or changing its color, so we use memo\nto wrap the inner shape and only re-render it when the shape's props change. \n\nThe shape also receives props for its index and opacity. The index is used to\ndetermine the z-index of the shape, and the opacity is used to set the shape's\nopacity based on its own opacity and that of its parent's.\n*/\nexport const Shape = memo(function Shape({\n\tid,\n\tshape,\n\tutil,\n\tindex,\n\tbackgroundIndex,\n\topacity,\n}: {\n\tid: TLShapeId\n\tshape: TLShape\n\tutil: ShapeUtil\n\tindex: number\n\tbackgroundIndex: number\n\topacity: number\n}) {\n\tconst editor = useEditor()\n\n\tconst { ShapeErrorFallback } = useEditorComponents()\n\n\tconst containerRef = useRef<HTMLDivElement>(null)\n\tconst bgContainerRef = useRef<HTMLDivElement>(null)\n\n\tuseEffect(() => {\n\t\treturn react('load fonts', () => {\n\t\t\tconst fonts = editor.fonts.getShapeFontFaces(shape)\n\t\t\teditor.fonts.requestFonts(fonts)\n\t\t})\n\t}, [editor, shape])\n\n\tconst memoizedStuffRef = useRef({\n\t\ttransform: '',\n\t\tclipPath: 'none',\n\t\twidth: 0,\n\t\theight: 0,\n\t\tx: 0,\n\t\ty: 0,\n\t\tisCulled: false,\n\t})\n\n\tuseQuickReactor(\n\t\t'set shape stuff',\n\t\t() => {\n\t\t\tconst shape = editor.getShape(id)\n\t\t\tif (!shape) return // probably the shape was just deleted\n\n\t\t\tconst prev = memoizedStuffRef.current\n\n\t\t\t// Clip path\n\t\t\tconst clipPath = editor.getShapeClipPath(id) ?? 'none'\n\t\t\tif (clipPath !== prev.clipPath) {\n\t\t\t\tsetStyleProperty(containerRef.current, 'clip-path', clipPath)\n\t\t\t\tsetStyleProperty(bgContainerRef.current, 'clip-path', clipPath)\n\t\t\t\tprev.clipPath = clipPath\n\t\t\t}\n\n\t\t\t// Page transform\n\t\t\tconst pageTransform = editor.getShapePageTransform(id)\n\t\t\tconst transform = Mat.toCssString(pageTransform)\n\t\t\tconst bounds = editor.getShapeGeometry(shape).bounds\n\n\t\t\t// Update if the tranform has changed\n\t\t\tif (transform !== prev.transform) {\n\t\t\t\tsetStyleProperty(containerRef.current, 'transform', transform)\n\t\t\t\tsetStyleProperty(bgContainerRef.current, 'transform', transform)\n\t\t\t\tprev.transform = transform\n\t\t\t}\n\n\t\t\t// Width / Height\n\t\t\tconst width = Math.max(bounds.width, 1)\n\t\t\tconst height = Math.max(bounds.height, 1)\n\n\t\t\tif (width !== prev.width || height !== prev.height) {\n\t\t\t\tsetStyleProperty(containerRef.current, 'width', width + 'px')\n\t\t\t\tsetStyleProperty(containerRef.current, 'height', height + 'px')\n\t\t\t\tsetStyleProperty(bgContainerRef.current, 'width', width + 'px')\n\t\t\t\tsetStyleProperty(bgContainerRef.current, 'height', height + 'px')\n\t\t\t\tprev.width = width\n\t\t\t\tprev.height = height\n\t\t\t}\n\t\t},\n\t\t[editor]\n\t)\n\n\t// This stuff changes pretty infrequently, so we can change them together\n\tuseQuickReactor(\n\t\t'set opacity and z-index',\n\t\t() => {\n\t\t\tconst container = containerRef.current\n\t\t\tconst bgContainer = bgContainerRef.current\n\n\t\t\t// Opacity\n\t\t\tsetStyleProperty(container, 'opacity', opacity)\n\t\t\tsetStyleProperty(bgContainer, 'opacity', opacity)\n\n\t\t\t// Z-Index\n\t\t\tsetStyleProperty(container, 'z-index', index)\n\t\t\tsetStyleProperty(bgContainer, 'z-index', backgroundIndex)\n\t\t},\n\t\t[opacity, index, backgroundIndex]\n\t)\n\n\tuseQuickReactor(\n\t\t'set display',\n\t\t() => {\n\t\t\tconst shape = editor.getShape(id)\n\t\t\tif (!shape) return // probably the shape was just deleted\n\n\t\t\tconst culledShapes = editor.getCulledShapes()\n\t\t\tconst isCulled = culledShapes.has(id)\n\t\t\tif (isCulled !== memoizedStuffRef.current.isCulled) {\n\t\t\t\tsetStyleProperty(containerRef.current, 'display', isCulled ? 'none' : 'block')\n\t\t\t\tsetStyleProperty(bgContainerRef.current, 'display', isCulled ? 'none' : 'block')\n\t\t\t\tmemoizedStuffRef.current.isCulled = isCulled\n\t\t\t}\n\t\t},\n\t\t[editor]\n\t)\n\tconst annotateError = useCallback(\n\t\t(error: any) => editor.annotateError(error, { origin: 'shape', willCrashApp: false }),\n\t\t[editor]\n\t)\n\n\tif (!shape) return null\n\n\tconst isFilledShape = 'fill' in shape.props && shape.props.fill !== 'none'\n\n\treturn (\n\t\t<>\n\t\t\t{util.backgroundComponent && (\n\t\t\t\t<div\n\t\t\t\t\tref={bgContainerRef}\n\t\t\t\t\tclassName=\"tl-shape tl-shape-background\"\n\t\t\t\t\tdata-shape-type={shape.type}\n\t\t\t\t\tdata-shape-id={shape.id}\n\t\t\t\t\tdraggable={false}\n\t\t\t\t>\n\t\t\t\t\t<OptionalErrorBoundary fallback={ShapeErrorFallback} onError={annotateError}>\n\t\t\t\t\t\t<InnerShapeBackground shape={shape} util={util} />\n\t\t\t\t\t</OptionalErrorBoundary>\n\t\t\t\t</div>\n\t\t\t)}\n\t\t\t<div\n\t\t\t\tref={containerRef}\n\t\t\t\tclassName=\"tl-shape\"\n\t\t\t\tdata-shape-type={shape.type}\n\t\t\t\tdata-shape-is-filled={isFilledShape}\n\t\t\t\tdata-shape-id={shape.id}\n\t\t\t\tdraggable={false}\n\t\t\t>\n\t\t\t\t<OptionalErrorBoundary fallback={ShapeErrorFallback as any} onError={annotateError}>\n\t\t\t\t\t<InnerShape shape={shape} util={util} />\n\t\t\t\t</OptionalErrorBoundary>\n\t\t\t</div>\n\t\t</>\n\t)\n})\n\nexport const InnerShape = memo(\n\tfunction InnerShape<T extends TLShape>({ shape, util }: { shape: T; util: ShapeUtil<T> }) {\n\t\treturn useStateTracking(\n\t\t\t'InnerShape:' + shape.type,\n\t\t\t() =>\n\t\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\t// calling the render method with stale data.\n\t\t\t\tutil.component(util.editor.store.unsafeGetWithoutCapture(shape.id) as T),\n\t\t\t[util, shape.id]\n\t\t)\n\t},\n\t(prev, next) =>\n\t\tprev.shape.props === next.shape.props &&\n\t\tprev.shape.meta === next.shape.meta &&\n\t\tprev.util === next.util\n)\n\nexport const InnerShapeBackground = memo(\n\tfunction InnerShapeBackground<T extends TLShape>({\n\t\tshape,\n\t\tutil,\n\t}: {\n\t\tshape: T\n\t\tutil: ShapeUtil<T>\n\t}) {\n\t\treturn useStateTracking(\n\t\t\t'InnerShape:' + shape.type,\n\t\t\t() =>\n\t\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\t// calling the render method with stale data.\n\t\t\t\tutil.backgroundComponent?.(util.editor.store.unsafeGetWithoutCapture(shape.id) as T),\n\t\t\t[util, shape.id]\n\t\t)\n\t},\n\t(prev, next) =>\n\t\tprev.shape.props === next.shape.props &&\n\t\tprev.shape.meta === next.shape.meta &&\n\t\tprev.util === next.util\n)\n"],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,EACD,GAGG;AACF,eAAO;AAAA,MACN,gBAAgB,MAAM;AAAA,MACtB;AAAA;AAAA;AAAA,QAGC,KAAK,sBAAsB,KAAK,OAAO,MAAM,wBAAwB,MAAM,EAAE,CAAM;AAAA;AAAA,MACpF,CAAC,MAAM,MAAM,EAAE;AAAA,IAChB;AAAA,EACD;AAAA,EACA,CAAC,MAAM,SACN,KAAK,MAAM,UAAU,KAAK,MAAM,SAChC,KAAK,MAAM,SAAS,KAAK,MAAM,QAC/B,KAAK,SAAS,KAAK;AACrB;",
4
+ "sourcesContent": ["import { react } from '@tldraw/state'\nimport { useQuickReactor, useStateTracking } from '@tldraw/state-react'\nimport { TLShape, TLShapeId } from '@tldraw/tlschema'\nimport { memo, useCallback, useEffect, useLayoutEffect, useRef } from 'react'\nimport { ShapeUtil } from '../editor/shapes/ShapeUtil'\nimport { useEditor } from '../hooks/useEditor'\nimport { useEditorComponents } from '../hooks/useEditorComponents'\nimport { Mat } from '../primitives/Mat'\nimport { setStyleProperty } from '../utils/dom'\nimport { OptionalErrorBoundary } from './ErrorBoundary'\n\n/*\nThis component renders shapes on the canvas. There are two stages: positioning\nand styling the shape's container using CSS, and then rendering the shape's \nJSX using its shape util's render method. Rendering the \"inside\" of a shape is\nmore expensive than positioning it or changing its color, so we use memo\nto wrap the inner shape and only re-render it when the shape's props change. \n\nThe shape also receives props for its index and opacity. The index is used to\ndetermine the z-index of the shape, and the opacity is used to set the shape's\nopacity based on its own opacity and that of its parent's.\n*/\nexport const Shape = memo(function Shape({\n\tid,\n\tshape,\n\tutil,\n\tindex,\n\tbackgroundIndex,\n\topacity,\n}: {\n\tid: TLShapeId\n\tshape: TLShape\n\tutil: ShapeUtil\n\tindex: number\n\tbackgroundIndex: number\n\topacity: number\n}) {\n\tconst editor = useEditor()\n\n\tconst { ShapeErrorFallback } = useEditorComponents()\n\n\tconst containerRef = useRef<HTMLDivElement>(null)\n\tconst bgContainerRef = useRef<HTMLDivElement>(null)\n\n\tuseEffect(() => {\n\t\treturn react('load fonts', () => {\n\t\t\tconst fonts = editor.fonts.getShapeFontFaces(id)\n\t\t\teditor.fonts.requestFonts(fonts)\n\t\t})\n\t}, [editor, id])\n\n\tconst memoizedStuffRef = useRef({\n\t\ttransform: '',\n\t\tclipPath: 'none',\n\t\twidth: 0,\n\t\theight: 0,\n\t\tx: 0,\n\t\ty: 0,\n\t\tisCulled: false,\n\t})\n\n\tuseQuickReactor(\n\t\t'set shape stuff',\n\t\t() => {\n\t\t\tconst shape = editor.getShape(id)\n\t\t\tif (!shape) return // probably the shape was just deleted\n\n\t\t\tconst prev = memoizedStuffRef.current\n\n\t\t\t// Clip path\n\t\t\tconst clipPath = editor.getShapeClipPath(id) ?? 'none'\n\t\t\tif (clipPath !== prev.clipPath) {\n\t\t\t\tsetStyleProperty(containerRef.current, 'clip-path', clipPath)\n\t\t\t\tsetStyleProperty(bgContainerRef.current, 'clip-path', clipPath)\n\t\t\t\tprev.clipPath = clipPath\n\t\t\t}\n\n\t\t\t// Page transform\n\t\t\tconst pageTransform = editor.getShapePageTransform(id)\n\t\t\tconst transform = Mat.toCssString(pageTransform)\n\t\t\tconst bounds = editor.getShapeGeometry(shape).bounds\n\n\t\t\t// Update if the tranform has changed\n\t\t\tif (transform !== prev.transform) {\n\t\t\t\tsetStyleProperty(containerRef.current, 'transform', transform)\n\t\t\t\tsetStyleProperty(bgContainerRef.current, 'transform', transform)\n\t\t\t\tprev.transform = transform\n\t\t\t}\n\n\t\t\t// Width / Height\n\t\t\tconst width = Math.max(bounds.width, 1)\n\t\t\tconst height = Math.max(bounds.height, 1)\n\n\t\t\tif (width !== prev.width || height !== prev.height) {\n\t\t\t\tsetStyleProperty(containerRef.current, 'width', width + 'px')\n\t\t\t\tsetStyleProperty(containerRef.current, 'height', height + 'px')\n\t\t\t\tsetStyleProperty(bgContainerRef.current, 'width', width + 'px')\n\t\t\t\tsetStyleProperty(bgContainerRef.current, 'height', height + 'px')\n\t\t\t\tprev.width = width\n\t\t\t\tprev.height = height\n\t\t\t}\n\t\t},\n\t\t[editor]\n\t)\n\n\t// This stuff changes pretty infrequently, so we can change them together\n\tuseLayoutEffect(() => {\n\t\tconst container = containerRef.current\n\t\tconst bgContainer = bgContainerRef.current\n\n\t\t// Opacity\n\t\tsetStyleProperty(container, 'opacity', opacity)\n\t\tsetStyleProperty(bgContainer, 'opacity', opacity)\n\n\t\t// Z-Index\n\t\tsetStyleProperty(container, 'z-index', index)\n\t\tsetStyleProperty(bgContainer, 'z-index', backgroundIndex)\n\t}, [opacity, index, backgroundIndex])\n\n\tuseQuickReactor(\n\t\t'set display',\n\t\t() => {\n\t\t\tconst shape = editor.getShape(id)\n\t\t\tif (!shape) return // probably the shape was just deleted\n\n\t\t\tconst culledShapes = editor.getCulledShapes()\n\t\t\tconst isCulled = culledShapes.has(id)\n\t\t\tif (isCulled !== memoizedStuffRef.current.isCulled) {\n\t\t\t\tsetStyleProperty(containerRef.current, 'display', isCulled ? 'none' : 'block')\n\t\t\t\tsetStyleProperty(bgContainerRef.current, 'display', isCulled ? 'none' : 'block')\n\t\t\t\tmemoizedStuffRef.current.isCulled = isCulled\n\t\t\t}\n\t\t},\n\t\t[editor]\n\t)\n\tconst annotateError = useCallback(\n\t\t(error: any) => editor.annotateError(error, { origin: 'shape', willCrashApp: false }),\n\t\t[editor]\n\t)\n\n\tif (!shape) return null\n\n\tconst isFilledShape = 'fill' in shape.props && shape.props.fill !== 'none'\n\n\treturn (\n\t\t<>\n\t\t\t{util.backgroundComponent && (\n\t\t\t\t<div\n\t\t\t\t\tref={bgContainerRef}\n\t\t\t\t\tclassName=\"tl-shape tl-shape-background\"\n\t\t\t\t\tdata-shape-type={shape.type}\n\t\t\t\t\tdata-shape-id={shape.id}\n\t\t\t\t\tdraggable={false}\n\t\t\t\t>\n\t\t\t\t\t<OptionalErrorBoundary fallback={ShapeErrorFallback} onError={annotateError}>\n\t\t\t\t\t\t<InnerShapeBackground shape={shape} util={util} />\n\t\t\t\t\t</OptionalErrorBoundary>\n\t\t\t\t</div>\n\t\t\t)}\n\t\t\t<div\n\t\t\t\tref={containerRef}\n\t\t\t\tclassName=\"tl-shape\"\n\t\t\t\tdata-shape-type={shape.type}\n\t\t\t\tdata-shape-is-filled={isFilledShape}\n\t\t\t\tdata-shape-id={shape.id}\n\t\t\t\tdraggable={false}\n\t\t\t>\n\t\t\t\t<OptionalErrorBoundary fallback={ShapeErrorFallback as any} onError={annotateError}>\n\t\t\t\t\t<InnerShape shape={shape} util={util} />\n\t\t\t\t</OptionalErrorBoundary>\n\t\t\t</div>\n\t\t</>\n\t)\n})\n\nexport const InnerShape = memo(\n\tfunction InnerShape<T extends TLShape>({ shape, util }: { shape: T; util: ShapeUtil<T> }) {\n\t\treturn useStateTracking(\n\t\t\t'InnerShape:' + shape.type,\n\t\t\t() =>\n\t\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\t// calling the render method with stale data.\n\t\t\t\tutil.component(util.editor.store.unsafeGetWithoutCapture(shape.id) as T),\n\t\t\t[util, shape.id]\n\t\t)\n\t},\n\t(prev, next) =>\n\t\tprev.shape.props === next.shape.props &&\n\t\tprev.shape.meta === next.shape.meta &&\n\t\tprev.util === next.util\n)\n\nexport const InnerShapeBackground = memo(\n\tfunction InnerShapeBackground<T extends TLShape>({\n\t\tshape,\n\t\tutil,\n\t}: {\n\t\tshape: T\n\t\tutil: ShapeUtil<T>\n\t}) {\n\t\treturn useStateTracking(\n\t\t\t'InnerShape:' + shape.type,\n\t\t\t() =>\n\t\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\t// calling the render method with stale data.\n\t\t\t\tutil.backgroundComponent?.(util.editor.store.unsafeGetWithoutCapture(shape.id) as T),\n\t\t\t[util, shape.id]\n\t\t)\n\t},\n\t(prev, next) =>\n\t\tprev.shape.props === next.shape.props &&\n\t\tprev.shape.meta === next.shape.meta &&\n\t\tprev.util === next.util\n)\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;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AAAA,MACtB;AAAA;AAAA;AAAA,QAGC,KAAK,sBAAsB,KAAK,OAAO,MAAM,wBAAwB,MAAM,EAAE,CAAM;AAAA;AAAA,MACpF,CAAC,MAAM,MAAM,EAAE;AAAA,IAChB;AAAA,EACD;AAAA,EACA,CAAC,MAAM,SACN,KAAK,MAAM,UAAU,KAAK,MAAM,SAChC,KAAK,MAAM,SAAS,KAAK,MAAM,QAC/B,KAAK,SAAS,KAAK;AACrB;",
6
6
  "names": ["Shape", "shape", "InnerShape", "InnerShapeBackground"]
7
7
  }
@@ -137,13 +137,15 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
137
137
  autoFocus,
138
138
  inferDarkMode,
139
139
  options,
140
+ // eslint-disable-next-line @typescript-eslint/no-deprecated
140
141
  isShapeHidden,
142
+ getShapeVisibility,
141
143
  fontAssetUrls
142
144
  }) {
143
145
  super();
144
146
  __runInitializers(_init, 5, this);
145
147
  __publicField(this, "id", (0, import_utils.uniqueId)());
146
- __publicField(this, "_isShapeHiddenPredicate");
148
+ __publicField(this, "_getShapeVisibility");
147
149
  __publicField(this, "options");
148
150
  __publicField(this, "contextId", (0, import_utils.uniqueId)());
149
151
  /**
@@ -299,6 +301,7 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
299
301
  __publicField(this, "_currentPageShapeIds");
300
302
  /* --------------------- Shapes --------------------- */
301
303
  __publicField(this, "_shapeGeometryCaches", {});
304
+ __publicField(this, "_shapePageGeometryCaches", {});
302
305
  // Parents and children
303
306
  /**
304
307
  * A cache of parents to children.
@@ -410,7 +413,14 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
410
413
  /** @internal */
411
414
  __publicField(this, "performanceTrackerTimeout", -1);
412
415
  __publicField(this, "_pendingEventsForNextTick", []);
413
- this._isShapeHiddenPredicate = isShapeHidden;
416
+ (0, import_utils.assert)(
417
+ !(isShapeHidden && getShapeVisibility),
418
+ "Cannot use both isShapeHidden and getShapeVisibility"
419
+ );
420
+ this._getShapeVisibility = isShapeHidden ? (
421
+ // eslint-disable-next-line @typescript-eslint/no-deprecated
422
+ (shape, editor) => isShapeHidden(shape, editor) ? "hidden" : "inherit"
423
+ ) : getShapeVisibility;
414
424
  this.options = { ...import_options.defaultTldrawOptions, ...options };
415
425
  this.store = store;
416
426
  this.disposables.add(this.store.dispose.bind(this.store));
@@ -803,15 +813,16 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
803
813
  }
804
814
  }
805
815
  getIsShapeHiddenCache() {
806
- if (!this._isShapeHiddenPredicate) return null;
816
+ if (!this._getShapeVisibility) return null;
807
817
  return this.store.createComputedCache("isShapeHidden", (shape) => {
808
- const hiddenParent = this.findShapeAncestor(shape, (p) => this.isShapeHidden(p));
809
- if (hiddenParent) return true;
810
- return this._isShapeHiddenPredicate(shape, this) ?? false;
818
+ const visibility = this._getShapeVisibility(shape, this);
819
+ const isParentHidden = import_tlschema.PageRecordType.isId(shape.parentId) ? false : this.isShapeHidden(shape.parentId);
820
+ if (isParentHidden) return visibility !== "visible";
821
+ return visibility === "hidden";
811
822
  });
812
823
  }
813
824
  isShapeHidden(shapeOrId) {
814
- if (!this._isShapeHiddenPredicate) return false;
825
+ if (!this._getShapeVisibility) return false;
815
826
  return !!this.getIsShapeHiddenCache().get(
816
827
  typeof shapeOrId === "string" ? shapeOrId : shapeOrId.id
817
828
  );
@@ -2825,7 +2836,13 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
2825
2836
  const addShapeById = (id, opacity, isAncestorErasing) => {
2826
2837
  const shape = this.getShape(id);
2827
2838
  if (!shape) return;
2828
- if (this.isShapeHidden(shape)) return;
2839
+ if (this.isShapeHidden(shape)) {
2840
+ const isErasing = isAncestorErasing || erasingShapeIds.includes(id);
2841
+ for (const childId of this.getSortedChildIdsForParent(id)) {
2842
+ addShapeById(childId, opacity, isErasing);
2843
+ }
2844
+ return;
2845
+ }
2829
2846
  opacity *= shape.opacity;
2830
2847
  let isShapeErasing = false;
2831
2848
  const util = this.getShapeUtil(shape);
@@ -3252,7 +3269,7 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
3252
3269
  return await this.store.props.assets.upload(asset, file, abortSignal);
3253
3270
  }
3254
3271
  /**
3255
- * Get the geometry of a shape.
3272
+ * Get the geometry of a shape in shape-space.
3256
3273
  *
3257
3274
  * @example
3258
3275
  * ```ts
@@ -3282,6 +3299,41 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
3282
3299
  typeof shape === "string" ? shape : shape.id
3283
3300
  );
3284
3301
  }
3302
+ /**
3303
+ * Get the geometry of a shape in page-space.
3304
+ *
3305
+ * @example
3306
+ * ```ts
3307
+ * editor.getShapePageGeometry(myShape)
3308
+ * editor.getShapePageGeometry(myShapeId)
3309
+ * editor.getShapePageGeometry(myShapeId, { context: "arrow" })
3310
+ * ```
3311
+ *
3312
+ * @param shape - The shape (or shape id) to get the geometry for.
3313
+ * @param opts - Additional options about the request for geometry. Passed to {@link ShapeUtil.getGeometry}.
3314
+ *
3315
+ * @public
3316
+ */
3317
+ getShapePageGeometry(shape, opts) {
3318
+ const context = opts?.context ?? "none";
3319
+ if (!this._shapePageGeometryCaches[context]) {
3320
+ this._shapePageGeometryCaches[context] = this.store.createComputedCache(
3321
+ "bounds",
3322
+ (shape2) => {
3323
+ const geometry = this.getShapeGeometry(shape2.id, opts);
3324
+ const pageTransform = this.getShapePageTransform(shape2.id);
3325
+ return geometry.transform(pageTransform);
3326
+ },
3327
+ {
3328
+ // we only depend directly on the shape id, and changing geometry/transform will update us anyway
3329
+ areRecordsEqual: () => true
3330
+ }
3331
+ );
3332
+ }
3333
+ return this._shapePageGeometryCaches[context].get(
3334
+ typeof shape === "string" ? shape : shape.id
3335
+ );
3336
+ }
3285
3337
  _getShapeHandlesCache() {
3286
3338
  return this.store.createComputedCache("handles", (shape) => {
3287
3339
  return this.getShapeUtil(shape).getHandles?.(shape);
@@ -3369,12 +3421,7 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
3369
3421
  }
3370
3422
  _getShapePageBoundsCache() {
3371
3423
  return this.store.createComputedCache("pageBoundsCache", (shape) => {
3372
- const pageTransform = this._getShapePageTransformCache().get(shape.id);
3373
- if (!pageTransform) return new import_Box.Box();
3374
- const result = import_Box.Box.FromPoints(
3375
- import_Mat.Mat.applyToPoints(pageTransform, this.getShapeGeometry(shape).vertices)
3376
- );
3377
- return result;
3424
+ return this.getShapePageGeometry(shape).bounds;
3378
3425
  });
3379
3426
  }
3380
3427
  /**
@@ -3434,7 +3481,7 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
3434
3481
  const pageMask = frameAncestors.map(
3435
3482
  (s) => (
3436
3483
  // Apply the frame transform to the frame outline to get the frame outline in the current page space
3437
- this._getShapePageTransformCache().get(s.id).applyToPoints(this.getShapeGeometry(s).vertices)
3484
+ this.getShapePageGeometry(s.id).vertices
3438
3485
  )
3439
3486
  ).reduce((acc, b) => {
3440
3487
  if (!(b && acc)) return void 0;
@@ -5942,8 +5989,15 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
5942
5989
  const styles = new import_SharedStylesMap.SharedStyleMap();
5943
5990
  if (!currentTool) return styles;
5944
5991
  if (currentTool.shapeType) {
5945
- for (const style of this.styleProps[currentTool.shapeType].keys()) {
5946
- styles.applyValue(style, this.getStyleForNextShape(style));
5992
+ if (currentTool.shapeType === "frame" && !this.getShapeUtil("frame").options.showColors) {
5993
+ for (const style of this.styleProps[currentTool.shapeType].keys()) {
5994
+ if (style.id === "tldraw:color") continue;
5995
+ styles.applyValue(style, this.getStyleForNextShape(style));
5996
+ }
5997
+ } else {
5998
+ for (const style of this.styleProps[currentTool.shapeType].keys()) {
5999
+ styles.applyValue(style, this.getStyleForNextShape(style));
6000
+ }
5947
6001
  }
5948
6002
  }
5949
6003
  return styles;
@@ -7201,12 +7255,12 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
7201
7255
  this.stopFollowingUser();
7202
7256
  }
7203
7257
  const { x: cx, y: cy, z: cz } = (0, import_state.unsafe__withoutCapture)(() => this.getCamera());
7204
- const { panSpeed, zoomSpeed } = cameraOptions;
7258
+ const { panSpeed } = cameraOptions;
7205
7259
  this._setCamera(
7206
7260
  new import_Vec.Vec(
7207
- cx + dx * panSpeed / cz - x / cz + x / (z * zoomSpeed),
7208
- cy + dy * panSpeed / cz - y / cz + y / (z * zoomSpeed),
7209
- z * zoomSpeed
7261
+ cx + dx * panSpeed / cz - x / cz + x / z,
7262
+ cy + dy * panSpeed / cz - y / cz + y / z,
7263
+ z
7210
7264
  ),
7211
7265
  { immediate: true }
7212
7266
  );
@@ -7257,14 +7311,9 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
7257
7311
  }
7258
7312
  }
7259
7313
  const zoom = cz + (delta ?? 0) * zoomSpeed * cz;
7260
- this._setCamera(
7261
- new import_Vec.Vec(
7262
- cx + (x / zoom - x) - (x / cz - x),
7263
- cy + (y / zoom - y) - (y / cz - y),
7264
- zoom
7265
- ),
7266
- { immediate: true }
7267
- );
7314
+ this._setCamera(new import_Vec.Vec(cx + x / zoom - x / cz, cy + y / zoom - y / cz, zoom), {
7315
+ immediate: true
7316
+ });
7268
7317
  this.maybeTrackPerformance("Zooming");
7269
7318
  return;
7270
7319
  }