@tldraw/editor 3.16.0-internal.51e99e128bd4 → 3.16.0-next.15f085081fd5

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 (63) hide show
  1. package/dist-cjs/index.d.ts +26 -0
  2. package/dist-cjs/index.js +1 -1
  3. package/dist-cjs/lib/TldrawEditor.js +5 -1
  4. package/dist-cjs/lib/TldrawEditor.js.map +2 -2
  5. package/dist-cjs/lib/components/Shape.js +7 -10
  6. package/dist-cjs/lib/components/Shape.js.map +2 -2
  7. package/dist-cjs/lib/components/default-components/DefaultCanvas.js +4 -23
  8. package/dist-cjs/lib/components/default-components/DefaultCanvas.js.map +2 -2
  9. package/dist-cjs/lib/editor/Editor.js +17 -0
  10. package/dist-cjs/lib/editor/Editor.js.map +2 -2
  11. package/dist-cjs/lib/editor/shapes/ShapeUtil.js +13 -0
  12. package/dist-cjs/lib/editor/shapes/ShapeUtil.js.map +2 -2
  13. package/dist-cjs/lib/exports/getSvgJsx.js +34 -14
  14. package/dist-cjs/lib/exports/getSvgJsx.js.map +2 -2
  15. package/dist-cjs/lib/hooks/useCanvasEvents.js +7 -5
  16. package/dist-cjs/lib/hooks/useCanvasEvents.js.map +2 -2
  17. package/dist-cjs/lib/hooks/usePassThroughWheelEvents.js +4 -1
  18. package/dist-cjs/lib/hooks/usePassThroughWheelEvents.js.map +2 -2
  19. package/dist-cjs/lib/primitives/Box.js +3 -0
  20. package/dist-cjs/lib/primitives/Box.js.map +2 -2
  21. package/dist-cjs/version.js +3 -3
  22. package/dist-cjs/version.js.map +1 -1
  23. package/dist-esm/index.d.mts +26 -0
  24. package/dist-esm/index.mjs +1 -1
  25. package/dist-esm/lib/TldrawEditor.mjs +5 -1
  26. package/dist-esm/lib/TldrawEditor.mjs.map +2 -2
  27. package/dist-esm/lib/components/Shape.mjs +7 -10
  28. package/dist-esm/lib/components/Shape.mjs.map +2 -2
  29. package/dist-esm/lib/components/default-components/DefaultCanvas.mjs +4 -23
  30. package/dist-esm/lib/components/default-components/DefaultCanvas.mjs.map +2 -2
  31. package/dist-esm/lib/editor/Editor.mjs +17 -0
  32. package/dist-esm/lib/editor/Editor.mjs.map +2 -2
  33. package/dist-esm/lib/editor/shapes/ShapeUtil.mjs +13 -0
  34. package/dist-esm/lib/editor/shapes/ShapeUtil.mjs.map +2 -2
  35. package/dist-esm/lib/exports/getSvgJsx.mjs +34 -14
  36. package/dist-esm/lib/exports/getSvgJsx.mjs.map +2 -2
  37. package/dist-esm/lib/hooks/useCanvasEvents.mjs +7 -5
  38. package/dist-esm/lib/hooks/useCanvasEvents.mjs.map +2 -2
  39. package/dist-esm/lib/hooks/usePassThroughWheelEvents.mjs +4 -1
  40. package/dist-esm/lib/hooks/usePassThroughWheelEvents.mjs.map +2 -2
  41. package/dist-esm/lib/primitives/Box.mjs +4 -1
  42. package/dist-esm/lib/primitives/Box.mjs.map +2 -2
  43. package/dist-esm/version.mjs +3 -3
  44. package/dist-esm/version.mjs.map +1 -1
  45. package/editor.css +8 -0
  46. package/package.json +7 -7
  47. package/src/lib/TldrawEditor.tsx +6 -1
  48. package/src/lib/components/Shape.tsx +6 -12
  49. package/src/lib/components/default-components/DefaultCanvas.tsx +5 -22
  50. package/src/lib/editor/Editor.ts +18 -0
  51. package/src/lib/editor/shapes/ShapeUtil.ts +14 -0
  52. package/src/lib/exports/getSvgJsx.test.ts +868 -0
  53. package/src/lib/exports/getSvgJsx.tsx +76 -19
  54. package/src/lib/hooks/useCanvasEvents.ts +6 -6
  55. package/src/lib/hooks/usePassThroughWheelEvents.ts +6 -1
  56. package/src/lib/primitives/Box.test.ts +126 -0
  57. package/src/lib/primitives/Box.ts +10 -1
  58. package/src/version.ts +3 -3
  59. package/dist-cjs/lib/utils/nearestMultiple.js +0 -34
  60. package/dist-cjs/lib/utils/nearestMultiple.js.map +0 -7
  61. package/dist-esm/lib/utils/nearestMultiple.mjs +0 -14
  62. package/dist-esm/lib/utils/nearestMultiple.mjs.map +0 -7
  63. package/src/lib/utils/nearestMultiple.ts +0 -13
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/lib/primitives/Box.ts"],
4
- "sourcesContent": ["import { BoxModel } from '@tldraw/tlschema'\nimport { Vec, VecLike } from './Vec'\nimport { PI, PI2, toPrecision } from './utils'\n\n/** @public */\nexport type BoxLike = BoxModel | Box\n\n/** @public */\nexport type SelectionEdge = 'top' | 'right' | 'bottom' | 'left'\n\n/** @public */\nexport type SelectionCorner = 'top_left' | 'top_right' | 'bottom_right' | 'bottom_left'\n\n/** @public */\nexport type SelectionHandle = SelectionEdge | SelectionCorner\n\n/** @public */\nexport type RotateCorner =\n\t| 'top_left_rotate'\n\t| 'top_right_rotate'\n\t| 'bottom_right_rotate'\n\t| 'bottom_left_rotate'\n\t| 'mobile_rotate'\n\n/** @public */\nexport class Box {\n\tconstructor(x = 0, y = 0, w = 0, h = 0) {\n\t\tthis.x = x\n\t\tthis.y = y\n\t\tthis.w = w\n\t\tthis.h = h\n\t}\n\n\tx = 0\n\ty = 0\n\tw = 0\n\th = 0\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget point() {\n\t\treturn new Vec(this.x, this.y)\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tset point(val: Vec) {\n\t\tthis.x = val.x\n\t\tthis.y = val.y\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget minX() {\n\t\treturn this.x\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tset minX(n: number) {\n\t\tthis.x = n\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget left() {\n\t\treturn this.x\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget midX() {\n\t\treturn this.x + this.w / 2\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget maxX() {\n\t\treturn this.x + this.w\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget right() {\n\t\treturn this.x + this.w\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget minY() {\n\t\treturn this.y\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tset minY(n: number) {\n\t\tthis.y = n\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget top() {\n\t\treturn this.y\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget midY() {\n\t\treturn this.y + this.h / 2\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget maxY() {\n\t\treturn this.y + this.h\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget bottom() {\n\t\treturn this.y + this.h\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget width() {\n\t\treturn this.w\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tset width(n: number) {\n\t\tthis.w = n\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget height() {\n\t\treturn this.h\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tset height(n: number) {\n\t\tthis.h = n\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget aspectRatio() {\n\t\treturn this.width / this.height\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget center() {\n\t\treturn new Vec(this.x + this.w / 2, this.y + this.h / 2)\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tset center(v: Vec) {\n\t\tthis.x = v.x - this.w / 2\n\t\tthis.y = v.y - this.h / 2\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget corners() {\n\t\treturn [\n\t\t\tnew Vec(this.x, this.y),\n\t\t\tnew Vec(this.x + this.w, this.y),\n\t\t\tnew Vec(this.x + this.w, this.y + this.h),\n\t\t\tnew Vec(this.x, this.y + this.h),\n\t\t]\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget cornersAndCenter() {\n\t\treturn [\n\t\t\tnew Vec(this.x, this.y),\n\t\t\tnew Vec(this.x + this.w, this.y),\n\t\t\tnew Vec(this.x + this.w, this.y + this.h),\n\t\t\tnew Vec(this.x, this.y + this.h),\n\t\t\tnew Vec(this.x + this.w / 2, this.y + this.h / 2),\n\t\t]\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget sides(): Array<[Vec, Vec]> {\n\t\tconst { corners } = this\n\t\treturn [\n\t\t\t[corners[0], corners[1]],\n\t\t\t[corners[1], corners[2]],\n\t\t\t[corners[2], corners[3]],\n\t\t\t[corners[3], corners[0]],\n\t\t]\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget size(): Vec {\n\t\treturn new Vec(this.w, this.h)\n\t}\n\n\ttoFixed() {\n\t\tthis.x = toPrecision(this.x)\n\t\tthis.y = toPrecision(this.y)\n\t\tthis.w = toPrecision(this.w)\n\t\tthis.h = toPrecision(this.h)\n\t\treturn this\n\t}\n\n\tsetTo(B: Box) {\n\t\tthis.x = B.x\n\t\tthis.y = B.y\n\t\tthis.w = B.w\n\t\tthis.h = B.h\n\t\treturn this\n\t}\n\n\tset(x = 0, y = 0, w = 0, h = 0) {\n\t\tthis.x = x\n\t\tthis.y = y\n\t\tthis.w = w\n\t\tthis.h = h\n\t\treturn this\n\t}\n\n\texpand(A: Box) {\n\t\tconst minX = Math.min(this.x, A.x)\n\t\tconst minY = Math.min(this.y, A.y)\n\t\tconst maxX = Math.max(this.x + this.w, A.x + A.w)\n\t\tconst maxY = Math.max(this.y + this.h, A.y + A.h)\n\n\t\tthis.x = minX\n\t\tthis.y = minY\n\t\tthis.w = maxX - minX\n\t\tthis.h = maxY - minY\n\t\treturn this\n\t}\n\n\texpandBy(n: number) {\n\t\tthis.x -= n\n\t\tthis.y -= n\n\t\tthis.w += n * 2\n\t\tthis.h += n * 2\n\t\treturn this\n\t}\n\n\tscale(n: number) {\n\t\tthis.x /= n\n\t\tthis.y /= n\n\t\tthis.w /= n\n\t\tthis.h /= n\n\t\treturn this\n\t}\n\n\tclone() {\n\t\tconst { x, y, w, h } = this\n\t\treturn new Box(x, y, w, h)\n\t}\n\n\ttranslate(delta: VecLike) {\n\t\tthis.x += delta.x\n\t\tthis.y += delta.y\n\t\treturn this\n\t}\n\n\tsnapToGrid(size: number) {\n\t\tconst minX = Math.round(this.x / size) * size\n\t\tconst minY = Math.round(this.y / size) * size\n\t\tconst maxX = Math.round((this.x + this.w) / size) * size\n\t\tconst maxY = Math.round((this.y + this.h) / size) * size\n\t\tthis.minX = minX\n\t\tthis.minY = minY\n\t\tthis.width = Math.max(1, maxX - minX)\n\t\tthis.height = Math.max(1, maxY - minY)\n\t}\n\n\tcollides(B: Box) {\n\t\treturn Box.Collides(this, B)\n\t}\n\n\tcontains(B: Box) {\n\t\treturn Box.Contains(this, B)\n\t}\n\n\tincludes(B: Box) {\n\t\treturn Box.Includes(this, B)\n\t}\n\n\tcontainsPoint(V: VecLike, margin = 0) {\n\t\treturn Box.ContainsPoint(this, V, margin)\n\t}\n\n\tgetHandlePoint(handle: SelectionCorner | SelectionEdge) {\n\t\tswitch (handle) {\n\t\t\tcase 'top_left':\n\t\t\t\treturn new Vec(this.x, this.y)\n\t\t\tcase 'top_right':\n\t\t\t\treturn new Vec(this.x + this.w, this.y)\n\t\t\tcase 'bottom_left':\n\t\t\t\treturn new Vec(this.x, this.y + this.h)\n\t\t\tcase 'bottom_right':\n\t\t\t\treturn new Vec(this.x + this.w, this.y + this.h)\n\t\t\tcase 'top':\n\t\t\t\treturn new Vec(this.x + this.w / 2, this.y)\n\t\t\tcase 'right':\n\t\t\t\treturn new Vec(this.x + this.w, this.y + this.h / 2)\n\t\t\tcase 'bottom':\n\t\t\t\treturn new Vec(this.x + this.w / 2, this.y + this.h)\n\t\t\tcase 'left':\n\t\t\t\treturn new Vec(this.x, this.y + this.h / 2)\n\t\t}\n\t}\n\n\ttoJson(): BoxModel {\n\t\treturn { x: this.x, y: this.y, w: this.w, h: this.h }\n\t}\n\n\tresize(handle: SelectionCorner | SelectionEdge | string, dx: number, dy: number) {\n\t\tconst { minX: a0x, minY: a0y, maxX: a1x, maxY: a1y } = this\n\t\tlet { minX: b0x, minY: b0y, maxX: b1x, maxY: b1y } = this\n\n\t\t// Use the delta to adjust the new box by changing its corners.\n\t\t// The dragging handle (corner or edge) will determine which\n\t\t// corners should change.\n\t\tswitch (handle) {\n\t\t\tcase 'left':\n\t\t\tcase 'top_left':\n\t\t\tcase 'bottom_left': {\n\t\t\t\tb0x += dx\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase 'right':\n\t\t\tcase 'top_right':\n\t\t\tcase 'bottom_right': {\n\t\t\t\tb1x += dx\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t\tswitch (handle) {\n\t\t\tcase 'top':\n\t\t\tcase 'top_left':\n\t\t\tcase 'top_right': {\n\t\t\t\tb0y += dy\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase 'bottom':\n\t\t\tcase 'bottom_left':\n\t\t\tcase 'bottom_right': {\n\t\t\t\tb1y += dy\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\n\t\tconst scaleX = (b1x - b0x) / (a1x - a0x)\n\t\tconst scaleY = (b1y - b0y) / (a1y - a0y)\n\n\t\tconst flipX = scaleX < 0\n\t\tconst flipY = scaleY < 0\n\n\t\tif (flipX) {\n\t\t\tconst t = b1x\n\t\t\tb1x = b0x\n\t\t\tb0x = t\n\t\t}\n\n\t\tif (flipY) {\n\t\t\tconst t = b1y\n\t\t\tb1y = b0y\n\t\t\tb0y = t\n\t\t}\n\n\t\tthis.minX = b0x\n\t\tthis.minY = b0y\n\t\tthis.width = Math.abs(b1x - b0x)\n\t\tthis.height = Math.abs(b1y - b0y)\n\t}\n\n\tunion(box: BoxModel) {\n\t\tconst minX = Math.min(this.x, box.x)\n\t\tconst minY = Math.min(this.y, box.y)\n\t\tconst maxX = Math.max(this.x + this.w, box.x + box.w)\n\t\tconst maxY = Math.max(this.y + this.h, box.y + box.h)\n\n\t\tthis.x = minX\n\t\tthis.y = minY\n\t\tthis.width = maxX - minX\n\t\tthis.height = maxY - minY\n\n\t\treturn this\n\t}\n\n\tstatic From(box: BoxModel) {\n\t\treturn new Box(box.x, box.y, box.w, box.h)\n\t}\n\n\tstatic FromCenter(center: VecLike, size: VecLike) {\n\t\treturn new Box(center.x - size.x / 2, center.y - size.y / 2, size.x, size.y)\n\t}\n\n\tstatic FromPoints(points: VecLike[]) {\n\t\tif (points.length === 0) return new Box()\n\t\tlet minX = Infinity\n\t\tlet minY = Infinity\n\t\tlet maxX = -Infinity\n\t\tlet maxY = -Infinity\n\t\tlet point: VecLike\n\t\tfor (let i = 0, n = points.length; i < n; i++) {\n\t\t\tpoint = points[i]\n\t\t\tminX = Math.min(point.x, minX)\n\t\t\tminY = Math.min(point.y, minY)\n\t\t\tmaxX = Math.max(point.x, maxX)\n\t\t\tmaxY = Math.max(point.y, maxY)\n\t\t}\n\n\t\treturn new Box(minX, minY, maxX - minX, maxY - minY)\n\t}\n\n\tstatic Expand(A: Box, B: Box) {\n\t\tconst minX = Math.min(B.minX, A.minX)\n\t\tconst minY = Math.min(B.minY, A.minY)\n\t\tconst maxX = Math.max(B.maxX, A.maxX)\n\t\tconst maxY = Math.max(B.maxY, A.maxY)\n\n\t\treturn new Box(minX, minY, maxX - minX, maxY - minY)\n\t}\n\n\tstatic ExpandBy(A: Box, n: number) {\n\t\treturn new Box(A.minX - n, A.minY - n, A.width + n * 2, A.height + n * 2)\n\t}\n\n\tstatic Collides(A: Box, B: Box) {\n\t\treturn !(A.maxX < B.minX || A.minX > B.maxX || A.maxY < B.minY || A.minY > B.maxY)\n\t}\n\n\tstatic Contains(A: Box, B: Box) {\n\t\treturn A.minX < B.minX && A.minY < B.minY && A.maxY > B.maxY && A.maxX > B.maxX\n\t}\n\n\tstatic Includes(A: Box, B: Box) {\n\t\treturn Box.Collides(A, B) || Box.Contains(A, B)\n\t}\n\n\tstatic ContainsPoint(A: Box, B: VecLike, margin = 0) {\n\t\treturn !(\n\t\t\tB.x < A.minX - margin ||\n\t\t\tB.y < A.minY - margin ||\n\t\t\tB.x > A.maxX + margin ||\n\t\t\tB.y > A.maxY + margin\n\t\t)\n\t}\n\n\tstatic Common(boxes: Box[]) {\n\t\tlet minX = Infinity\n\t\tlet minY = Infinity\n\t\tlet maxX = -Infinity\n\t\tlet maxY = -Infinity\n\n\t\tfor (let i = 0; i < boxes.length; i++) {\n\t\t\tconst B = boxes[i]\n\t\t\tminX = Math.min(minX, B.minX)\n\t\t\tminY = Math.min(minY, B.minY)\n\t\t\tmaxX = Math.max(maxX, B.maxX)\n\t\t\tmaxY = Math.max(maxY, B.maxY)\n\t\t}\n\n\t\treturn new Box(minX, minY, maxX - minX, maxY - minY)\n\t}\n\n\tstatic Sides(A: Box, inset = 0) {\n\t\tconst { corners } = A\n\t\tif (inset) {\n\t\t\t// TODO: Inset the corners by the inset amount.\n\t\t}\n\n\t\treturn [\n\t\t\t[corners[0], corners[1]],\n\t\t\t[corners[1], corners[2]],\n\t\t\t[corners[2], corners[3]],\n\t\t\t[corners[3], corners[0]],\n\t\t]\n\t}\n\n\tstatic Resize(\n\t\tbox: Box,\n\t\thandle: SelectionCorner | SelectionEdge | string,\n\t\tdx: number,\n\t\tdy: number,\n\t\tisAspectRatioLocked = false\n\t) {\n\t\tconst { minX: a0x, minY: a0y, maxX: a1x, maxY: a1y } = box\n\t\tlet { minX: b0x, minY: b0y, maxX: b1x, maxY: b1y } = box\n\n\t\t// Use the delta to adjust the new box by changing its corners.\n\t\t// The dragging handle (corner or edge) will determine which\n\t\t// corners should change.\n\t\tswitch (handle) {\n\t\t\tcase 'left':\n\t\t\tcase 'top_left':\n\t\t\tcase 'bottom_left': {\n\t\t\t\tb0x += dx\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase 'right':\n\t\t\tcase 'top_right':\n\t\t\tcase 'bottom_right': {\n\t\t\t\tb1x += dx\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t\tswitch (handle) {\n\t\t\tcase 'top':\n\t\t\tcase 'top_left':\n\t\t\tcase 'top_right': {\n\t\t\t\tb0y += dy\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase 'bottom':\n\t\t\tcase 'bottom_left':\n\t\t\tcase 'bottom_right': {\n\t\t\t\tb1y += dy\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\n\t\tconst scaleX = (b1x - b0x) / (a1x - a0x)\n\t\tconst scaleY = (b1y - b0y) / (a1y - a0y)\n\n\t\tconst flipX = scaleX < 0\n\t\tconst flipY = scaleY < 0\n\n\t\t/*\n 2. Aspect ratio\n If the aspect ratio is locked, adjust the corners so that the\n new box's aspect ratio matches the original aspect ratio.\n */\n\t\tif (isAspectRatioLocked) {\n\t\t\tconst aspectRatio = (a1x - a0x) / (a1y - a0y)\n\t\t\tconst bw = Math.abs(b1x - b0x)\n\t\t\tconst bh = Math.abs(b1y - b0y)\n\t\t\tconst tw = bw * (scaleY < 0 ? 1 : -1) * (1 / aspectRatio)\n\t\t\tconst th = bh * (scaleX < 0 ? 1 : -1) * aspectRatio\n\t\t\tconst isTall = aspectRatio < bw / bh\n\n\t\t\tswitch (handle) {\n\t\t\t\tcase 'top_left': {\n\t\t\t\t\tif (isTall) b0y = b1y + tw\n\t\t\t\t\telse b0x = b1x + th\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcase 'top_right': {\n\t\t\t\t\tif (isTall) b0y = b1y + tw\n\t\t\t\t\telse b1x = b0x - th\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcase 'bottom_right': {\n\t\t\t\t\tif (isTall) b1y = b0y - tw\n\t\t\t\t\telse b1x = b0x - th\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcase 'bottom_left': {\n\t\t\t\t\tif (isTall) b1y = b0y - tw\n\t\t\t\t\telse b0x = b1x + th\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcase 'bottom':\n\t\t\t\tcase 'top': {\n\t\t\t\t\tconst m = (b0x + b1x) / 2\n\t\t\t\t\tconst w = bh * aspectRatio\n\t\t\t\t\tb0x = m - w / 2\n\t\t\t\t\tb1x = m + w / 2\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcase 'left':\n\t\t\t\tcase 'right': {\n\t\t\t\t\tconst m = (b0y + b1y) / 2\n\t\t\t\t\tconst h = bw / aspectRatio\n\t\t\t\t\tb0y = m - h / 2\n\t\t\t\t\tb1y = m + h / 2\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (flipX) {\n\t\t\tconst t = b1x\n\t\t\tb1x = b0x\n\t\t\tb0x = t\n\t\t}\n\n\t\tif (flipY) {\n\t\t\tconst t = b1y\n\t\t\tb1y = b0y\n\t\t\tb0y = t\n\t\t}\n\n\t\tconst final = new Box(b0x, b0y, Math.abs(b1x - b0x), Math.abs(b1y - b0y))\n\n\t\treturn {\n\t\t\tbox: final,\n\t\t\tscaleX: +((final.width / box.width) * (scaleX > 0 ? 1 : -1)).toFixed(5),\n\t\t\tscaleY: +((final.height / box.height) * (scaleY > 0 ? 1 : -1)).toFixed(5),\n\t\t}\n\t}\n\n\tequals(other: Box | BoxModel) {\n\t\treturn Box.Equals(this, other)\n\t}\n\n\tstatic Equals(a: Box | BoxModel, b: Box | BoxModel) {\n\t\treturn b.x === a.x && b.y === a.y && b.w === a.w && b.h === a.h\n\t}\n\n\tzeroFix() {\n\t\tthis.w = Math.max(1, this.w)\n\t\tthis.h = Math.max(1, this.h)\n\t\treturn this\n\t}\n\n\tstatic ZeroFix(other: Box | BoxModel) {\n\t\treturn new Box(other.x, other.y, Math.max(1, other.w), Math.max(1, other.h))\n\t}\n}\n\n/** @public */\nexport function flipSelectionHandleY(handle: SelectionHandle) {\n\tswitch (handle) {\n\t\tcase 'top':\n\t\t\treturn 'bottom'\n\t\tcase 'bottom':\n\t\t\treturn 'top'\n\t\tcase 'top_left':\n\t\t\treturn 'bottom_left'\n\t\tcase 'top_right':\n\t\t\treturn 'bottom_right'\n\t\tcase 'bottom_left':\n\t\t\treturn 'top_left'\n\t\tcase 'bottom_right':\n\t\t\treturn 'top_right'\n\t\tdefault:\n\t\t\treturn handle\n\t}\n}\n\n/** @public */\nexport function flipSelectionHandleX(handle: SelectionHandle) {\n\tswitch (handle) {\n\t\tcase 'left':\n\t\t\treturn 'right'\n\t\tcase 'right':\n\t\t\treturn 'left'\n\t\tcase 'top_left':\n\t\t\treturn 'top_right'\n\t\tcase 'top_right':\n\t\t\treturn 'top_left'\n\t\tcase 'bottom_left':\n\t\t\treturn 'bottom_right'\n\t\tcase 'bottom_right':\n\t\t\treturn 'bottom_left'\n\t\tdefault:\n\t\t\treturn handle\n\t}\n}\n\nconst ORDERED_SELECTION_HANDLES = [\n\t'top',\n\t'top_right',\n\t'right',\n\t'bottom_right',\n\t'bottom',\n\t'bottom_left',\n\t'left',\n\t'top_left',\n] as const\n\n/** @public */\nexport function rotateSelectionHandle(handle: SelectionHandle, rotation: number): SelectionHandle {\n\t// first find out how many tau we need to rotate by\n\trotation = rotation % PI2\n\tconst numSteps = Math.round(rotation / (PI / 4))\n\n\tconst currentIndex = ORDERED_SELECTION_HANDLES.indexOf(handle)\n\treturn ORDERED_SELECTION_HANDLES[(currentIndex + numSteps) % ORDERED_SELECTION_HANDLES.length]\n}\n\n/** @public */\nexport function isSelectionCorner(selection: string): selection is SelectionCorner {\n\treturn (\n\t\tselection === 'top_left' ||\n\t\tselection === 'top_right' ||\n\t\tselection === 'bottom_right' ||\n\t\tselection === 'bottom_left'\n\t)\n}\n\n/** @public */\nexport const ROTATE_CORNER_TO_SELECTION_CORNER = {\n\ttop_left_rotate: 'top_left',\n\ttop_right_rotate: 'top_right',\n\tbottom_right_rotate: 'bottom_right',\n\tbottom_left_rotate: 'bottom_left',\n\tmobile_rotate: 'top_left',\n} as const\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,iBAA6B;AAC7B,mBAAqC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,WAAiD;AAClF,SACC,cAAc,cACd,cAAc,eACd,cAAc,kBACd,cAAc;AAEhB;AAGO,MAAM,oCAAoC;AAAA,EAChD,iBAAiB;AAAA,EACjB,kBAAkB;AAAA,EAClB,qBAAqB;AAAA,EACrB,oBAAoB;AAAA,EACpB,eAAe;AAChB;",
4
+ "sourcesContent": ["import { BoxModel } from '@tldraw/tlschema'\nimport { Vec, VecLike } from './Vec'\nimport { approximatelyLte, PI, PI2, toPrecision } from './utils'\n\n/** @public */\nexport type BoxLike = BoxModel | Box\n\n/** @public */\nexport type SelectionEdge = 'top' | 'right' | 'bottom' | 'left'\n\n/** @public */\nexport type SelectionCorner = 'top_left' | 'top_right' | 'bottom_right' | 'bottom_left'\n\n/** @public */\nexport type SelectionHandle = SelectionEdge | SelectionCorner\n\n/** @public */\nexport type RotateCorner =\n\t| 'top_left_rotate'\n\t| 'top_right_rotate'\n\t| 'bottom_right_rotate'\n\t| 'bottom_left_rotate'\n\t| 'mobile_rotate'\n\n/** @public */\nexport class Box {\n\tconstructor(x = 0, y = 0, w = 0, h = 0) {\n\t\tthis.x = x\n\t\tthis.y = y\n\t\tthis.w = w\n\t\tthis.h = h\n\t}\n\n\tx = 0\n\ty = 0\n\tw = 0\n\th = 0\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget point() {\n\t\treturn new Vec(this.x, this.y)\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tset point(val: Vec) {\n\t\tthis.x = val.x\n\t\tthis.y = val.y\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget minX() {\n\t\treturn this.x\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tset minX(n: number) {\n\t\tthis.x = n\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget left() {\n\t\treturn this.x\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget midX() {\n\t\treturn this.x + this.w / 2\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget maxX() {\n\t\treturn this.x + this.w\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget right() {\n\t\treturn this.x + this.w\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget minY() {\n\t\treturn this.y\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tset minY(n: number) {\n\t\tthis.y = n\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget top() {\n\t\treturn this.y\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget midY() {\n\t\treturn this.y + this.h / 2\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget maxY() {\n\t\treturn this.y + this.h\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget bottom() {\n\t\treturn this.y + this.h\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget width() {\n\t\treturn this.w\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tset width(n: number) {\n\t\tthis.w = n\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget height() {\n\t\treturn this.h\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tset height(n: number) {\n\t\tthis.h = n\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget aspectRatio() {\n\t\treturn this.width / this.height\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget center() {\n\t\treturn new Vec(this.x + this.w / 2, this.y + this.h / 2)\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tset center(v: Vec) {\n\t\tthis.x = v.x - this.w / 2\n\t\tthis.y = v.y - this.h / 2\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget corners() {\n\t\treturn [\n\t\t\tnew Vec(this.x, this.y),\n\t\t\tnew Vec(this.x + this.w, this.y),\n\t\t\tnew Vec(this.x + this.w, this.y + this.h),\n\t\t\tnew Vec(this.x, this.y + this.h),\n\t\t]\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget cornersAndCenter() {\n\t\treturn [\n\t\t\tnew Vec(this.x, this.y),\n\t\t\tnew Vec(this.x + this.w, this.y),\n\t\t\tnew Vec(this.x + this.w, this.y + this.h),\n\t\t\tnew Vec(this.x, this.y + this.h),\n\t\t\tnew Vec(this.x + this.w / 2, this.y + this.h / 2),\n\t\t]\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget sides(): Array<[Vec, Vec]> {\n\t\tconst { corners } = this\n\t\treturn [\n\t\t\t[corners[0], corners[1]],\n\t\t\t[corners[1], corners[2]],\n\t\t\t[corners[2], corners[3]],\n\t\t\t[corners[3], corners[0]],\n\t\t]\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget size(): Vec {\n\t\treturn new Vec(this.w, this.h)\n\t}\n\n\ttoFixed() {\n\t\tthis.x = toPrecision(this.x)\n\t\tthis.y = toPrecision(this.y)\n\t\tthis.w = toPrecision(this.w)\n\t\tthis.h = toPrecision(this.h)\n\t\treturn this\n\t}\n\n\tsetTo(B: Box) {\n\t\tthis.x = B.x\n\t\tthis.y = B.y\n\t\tthis.w = B.w\n\t\tthis.h = B.h\n\t\treturn this\n\t}\n\n\tset(x = 0, y = 0, w = 0, h = 0) {\n\t\tthis.x = x\n\t\tthis.y = y\n\t\tthis.w = w\n\t\tthis.h = h\n\t\treturn this\n\t}\n\n\texpand(A: Box) {\n\t\tconst minX = Math.min(this.x, A.x)\n\t\tconst minY = Math.min(this.y, A.y)\n\t\tconst maxX = Math.max(this.x + this.w, A.x + A.w)\n\t\tconst maxY = Math.max(this.y + this.h, A.y + A.h)\n\n\t\tthis.x = minX\n\t\tthis.y = minY\n\t\tthis.w = maxX - minX\n\t\tthis.h = maxY - minY\n\t\treturn this\n\t}\n\n\texpandBy(n: number) {\n\t\tthis.x -= n\n\t\tthis.y -= n\n\t\tthis.w += n * 2\n\t\tthis.h += n * 2\n\t\treturn this\n\t}\n\n\tscale(n: number) {\n\t\tthis.x /= n\n\t\tthis.y /= n\n\t\tthis.w /= n\n\t\tthis.h /= n\n\t\treturn this\n\t}\n\n\tclone() {\n\t\tconst { x, y, w, h } = this\n\t\treturn new Box(x, y, w, h)\n\t}\n\n\ttranslate(delta: VecLike) {\n\t\tthis.x += delta.x\n\t\tthis.y += delta.y\n\t\treturn this\n\t}\n\n\tsnapToGrid(size: number) {\n\t\tconst minX = Math.round(this.x / size) * size\n\t\tconst minY = Math.round(this.y / size) * size\n\t\tconst maxX = Math.round((this.x + this.w) / size) * size\n\t\tconst maxY = Math.round((this.y + this.h) / size) * size\n\t\tthis.minX = minX\n\t\tthis.minY = minY\n\t\tthis.width = Math.max(1, maxX - minX)\n\t\tthis.height = Math.max(1, maxY - minY)\n\t}\n\n\tcollides(B: Box) {\n\t\treturn Box.Collides(this, B)\n\t}\n\n\tcontains(B: Box) {\n\t\treturn Box.Contains(this, B)\n\t}\n\n\tincludes(B: Box) {\n\t\treturn Box.Includes(this, B)\n\t}\n\n\tcontainsPoint(V: VecLike, margin = 0) {\n\t\treturn Box.ContainsPoint(this, V, margin)\n\t}\n\n\tgetHandlePoint(handle: SelectionCorner | SelectionEdge) {\n\t\tswitch (handle) {\n\t\t\tcase 'top_left':\n\t\t\t\treturn new Vec(this.x, this.y)\n\t\t\tcase 'top_right':\n\t\t\t\treturn new Vec(this.x + this.w, this.y)\n\t\t\tcase 'bottom_left':\n\t\t\t\treturn new Vec(this.x, this.y + this.h)\n\t\t\tcase 'bottom_right':\n\t\t\t\treturn new Vec(this.x + this.w, this.y + this.h)\n\t\t\tcase 'top':\n\t\t\t\treturn new Vec(this.x + this.w / 2, this.y)\n\t\t\tcase 'right':\n\t\t\t\treturn new Vec(this.x + this.w, this.y + this.h / 2)\n\t\t\tcase 'bottom':\n\t\t\t\treturn new Vec(this.x + this.w / 2, this.y + this.h)\n\t\t\tcase 'left':\n\t\t\t\treturn new Vec(this.x, this.y + this.h / 2)\n\t\t}\n\t}\n\n\ttoJson(): BoxModel {\n\t\treturn { x: this.x, y: this.y, w: this.w, h: this.h }\n\t}\n\n\tresize(handle: SelectionCorner | SelectionEdge | string, dx: number, dy: number) {\n\t\tconst { minX: a0x, minY: a0y, maxX: a1x, maxY: a1y } = this\n\t\tlet { minX: b0x, minY: b0y, maxX: b1x, maxY: b1y } = this\n\n\t\t// Use the delta to adjust the new box by changing its corners.\n\t\t// The dragging handle (corner or edge) will determine which\n\t\t// corners should change.\n\t\tswitch (handle) {\n\t\t\tcase 'left':\n\t\t\tcase 'top_left':\n\t\t\tcase 'bottom_left': {\n\t\t\t\tb0x += dx\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase 'right':\n\t\t\tcase 'top_right':\n\t\t\tcase 'bottom_right': {\n\t\t\t\tb1x += dx\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t\tswitch (handle) {\n\t\t\tcase 'top':\n\t\t\tcase 'top_left':\n\t\t\tcase 'top_right': {\n\t\t\t\tb0y += dy\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase 'bottom':\n\t\t\tcase 'bottom_left':\n\t\t\tcase 'bottom_right': {\n\t\t\t\tb1y += dy\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\n\t\tconst scaleX = (b1x - b0x) / (a1x - a0x)\n\t\tconst scaleY = (b1y - b0y) / (a1y - a0y)\n\n\t\tconst flipX = scaleX < 0\n\t\tconst flipY = scaleY < 0\n\n\t\tif (flipX) {\n\t\t\tconst t = b1x\n\t\t\tb1x = b0x\n\t\t\tb0x = t\n\t\t}\n\n\t\tif (flipY) {\n\t\t\tconst t = b1y\n\t\t\tb1y = b0y\n\t\t\tb0y = t\n\t\t}\n\n\t\tthis.minX = b0x\n\t\tthis.minY = b0y\n\t\tthis.width = Math.abs(b1x - b0x)\n\t\tthis.height = Math.abs(b1y - b0y)\n\t}\n\n\tunion(box: BoxModel) {\n\t\tconst minX = Math.min(this.x, box.x)\n\t\tconst minY = Math.min(this.y, box.y)\n\t\tconst maxX = Math.max(this.x + this.w, box.x + box.w)\n\t\tconst maxY = Math.max(this.y + this.h, box.y + box.h)\n\n\t\tthis.x = minX\n\t\tthis.y = minY\n\t\tthis.width = maxX - minX\n\t\tthis.height = maxY - minY\n\n\t\treturn this\n\t}\n\n\tstatic From(box: BoxModel) {\n\t\treturn new Box(box.x, box.y, box.w, box.h)\n\t}\n\n\tstatic FromCenter(center: VecLike, size: VecLike) {\n\t\treturn new Box(center.x - size.x / 2, center.y - size.y / 2, size.x, size.y)\n\t}\n\n\tstatic FromPoints(points: VecLike[]) {\n\t\tif (points.length === 0) return new Box()\n\t\tlet minX = Infinity\n\t\tlet minY = Infinity\n\t\tlet maxX = -Infinity\n\t\tlet maxY = -Infinity\n\t\tlet point: VecLike\n\t\tfor (let i = 0, n = points.length; i < n; i++) {\n\t\t\tpoint = points[i]\n\t\t\tminX = Math.min(point.x, minX)\n\t\t\tminY = Math.min(point.y, minY)\n\t\t\tmaxX = Math.max(point.x, maxX)\n\t\t\tmaxY = Math.max(point.y, maxY)\n\t\t}\n\n\t\treturn new Box(minX, minY, maxX - minX, maxY - minY)\n\t}\n\n\tstatic Expand(A: Box, B: Box) {\n\t\tconst minX = Math.min(B.minX, A.minX)\n\t\tconst minY = Math.min(B.minY, A.minY)\n\t\tconst maxX = Math.max(B.maxX, A.maxX)\n\t\tconst maxY = Math.max(B.maxY, A.maxY)\n\n\t\treturn new Box(minX, minY, maxX - minX, maxY - minY)\n\t}\n\n\tstatic ExpandBy(A: Box, n: number) {\n\t\treturn new Box(A.minX - n, A.minY - n, A.width + n * 2, A.height + n * 2)\n\t}\n\n\tstatic Collides(A: Box, B: Box) {\n\t\treturn !(A.maxX < B.minX || A.minX > B.maxX || A.maxY < B.minY || A.minY > B.maxY)\n\t}\n\n\tstatic Contains(A: Box, B: Box) {\n\t\treturn A.minX < B.minX && A.minY < B.minY && A.maxY > B.maxY && A.maxX > B.maxX\n\t}\n\n\tstatic ContainsApproximately(A: Box, B: Box, precision?: number) {\n\t\treturn (\n\t\t\tapproximatelyLte(A.minX, B.minX, precision) &&\n\t\t\tapproximatelyLte(A.minY, B.minY, precision) &&\n\t\t\tapproximatelyLte(B.maxX, A.maxX, precision) &&\n\t\t\tapproximatelyLte(B.maxY, A.maxY, precision)\n\t\t)\n\t}\n\n\tstatic Includes(A: Box, B: Box) {\n\t\treturn Box.Collides(A, B) || Box.Contains(A, B)\n\t}\n\n\tstatic ContainsPoint(A: Box, B: VecLike, margin = 0) {\n\t\treturn !(\n\t\t\tB.x < A.minX - margin ||\n\t\t\tB.y < A.minY - margin ||\n\t\t\tB.x > A.maxX + margin ||\n\t\t\tB.y > A.maxY + margin\n\t\t)\n\t}\n\n\tstatic Common(boxes: Box[]) {\n\t\tlet minX = Infinity\n\t\tlet minY = Infinity\n\t\tlet maxX = -Infinity\n\t\tlet maxY = -Infinity\n\n\t\tfor (let i = 0; i < boxes.length; i++) {\n\t\t\tconst B = boxes[i]\n\t\t\tminX = Math.min(minX, B.minX)\n\t\t\tminY = Math.min(minY, B.minY)\n\t\t\tmaxX = Math.max(maxX, B.maxX)\n\t\t\tmaxY = Math.max(maxY, B.maxY)\n\t\t}\n\n\t\treturn new Box(minX, minY, maxX - minX, maxY - minY)\n\t}\n\n\tstatic Sides(A: Box, inset = 0) {\n\t\tconst { corners } = A\n\t\tif (inset) {\n\t\t\t// TODO: Inset the corners by the inset amount.\n\t\t}\n\n\t\treturn [\n\t\t\t[corners[0], corners[1]],\n\t\t\t[corners[1], corners[2]],\n\t\t\t[corners[2], corners[3]],\n\t\t\t[corners[3], corners[0]],\n\t\t]\n\t}\n\n\tstatic Resize(\n\t\tbox: Box,\n\t\thandle: SelectionCorner | SelectionEdge | string,\n\t\tdx: number,\n\t\tdy: number,\n\t\tisAspectRatioLocked = false\n\t) {\n\t\tconst { minX: a0x, minY: a0y, maxX: a1x, maxY: a1y } = box\n\t\tlet { minX: b0x, minY: b0y, maxX: b1x, maxY: b1y } = box\n\n\t\t// Use the delta to adjust the new box by changing its corners.\n\t\t// The dragging handle (corner or edge) will determine which\n\t\t// corners should change.\n\t\tswitch (handle) {\n\t\t\tcase 'left':\n\t\t\tcase 'top_left':\n\t\t\tcase 'bottom_left': {\n\t\t\t\tb0x += dx\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase 'right':\n\t\t\tcase 'top_right':\n\t\t\tcase 'bottom_right': {\n\t\t\t\tb1x += dx\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t\tswitch (handle) {\n\t\t\tcase 'top':\n\t\t\tcase 'top_left':\n\t\t\tcase 'top_right': {\n\t\t\t\tb0y += dy\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase 'bottom':\n\t\t\tcase 'bottom_left':\n\t\t\tcase 'bottom_right': {\n\t\t\t\tb1y += dy\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\n\t\tconst scaleX = (b1x - b0x) / (a1x - a0x)\n\t\tconst scaleY = (b1y - b0y) / (a1y - a0y)\n\n\t\tconst flipX = scaleX < 0\n\t\tconst flipY = scaleY < 0\n\n\t\t/*\n 2. Aspect ratio\n If the aspect ratio is locked, adjust the corners so that the\n new box's aspect ratio matches the original aspect ratio.\n */\n\t\tif (isAspectRatioLocked) {\n\t\t\tconst aspectRatio = (a1x - a0x) / (a1y - a0y)\n\t\t\tconst bw = Math.abs(b1x - b0x)\n\t\t\tconst bh = Math.abs(b1y - b0y)\n\t\t\tconst tw = bw * (scaleY < 0 ? 1 : -1) * (1 / aspectRatio)\n\t\t\tconst th = bh * (scaleX < 0 ? 1 : -1) * aspectRatio\n\t\t\tconst isTall = aspectRatio < bw / bh\n\n\t\t\tswitch (handle) {\n\t\t\t\tcase 'top_left': {\n\t\t\t\t\tif (isTall) b0y = b1y + tw\n\t\t\t\t\telse b0x = b1x + th\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcase 'top_right': {\n\t\t\t\t\tif (isTall) b0y = b1y + tw\n\t\t\t\t\telse b1x = b0x - th\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcase 'bottom_right': {\n\t\t\t\t\tif (isTall) b1y = b0y - tw\n\t\t\t\t\telse b1x = b0x - th\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcase 'bottom_left': {\n\t\t\t\t\tif (isTall) b1y = b0y - tw\n\t\t\t\t\telse b0x = b1x + th\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcase 'bottom':\n\t\t\t\tcase 'top': {\n\t\t\t\t\tconst m = (b0x + b1x) / 2\n\t\t\t\t\tconst w = bh * aspectRatio\n\t\t\t\t\tb0x = m - w / 2\n\t\t\t\t\tb1x = m + w / 2\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcase 'left':\n\t\t\t\tcase 'right': {\n\t\t\t\t\tconst m = (b0y + b1y) / 2\n\t\t\t\t\tconst h = bw / aspectRatio\n\t\t\t\t\tb0y = m - h / 2\n\t\t\t\t\tb1y = m + h / 2\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (flipX) {\n\t\t\tconst t = b1x\n\t\t\tb1x = b0x\n\t\t\tb0x = t\n\t\t}\n\n\t\tif (flipY) {\n\t\t\tconst t = b1y\n\t\t\tb1y = b0y\n\t\t\tb0y = t\n\t\t}\n\n\t\tconst final = new Box(b0x, b0y, Math.abs(b1x - b0x), Math.abs(b1y - b0y))\n\n\t\treturn {\n\t\t\tbox: final,\n\t\t\tscaleX: +((final.width / box.width) * (scaleX > 0 ? 1 : -1)).toFixed(5),\n\t\t\tscaleY: +((final.height / box.height) * (scaleY > 0 ? 1 : -1)).toFixed(5),\n\t\t}\n\t}\n\n\tequals(other: Box | BoxModel) {\n\t\treturn Box.Equals(this, other)\n\t}\n\n\tstatic Equals(a: Box | BoxModel, b: Box | BoxModel) {\n\t\treturn b.x === a.x && b.y === a.y && b.w === a.w && b.h === a.h\n\t}\n\n\tzeroFix() {\n\t\tthis.w = Math.max(1, this.w)\n\t\tthis.h = Math.max(1, this.h)\n\t\treturn this\n\t}\n\n\tstatic ZeroFix(other: Box | BoxModel) {\n\t\treturn new Box(other.x, other.y, Math.max(1, other.w), Math.max(1, other.h))\n\t}\n}\n\n/** @public */\nexport function flipSelectionHandleY(handle: SelectionHandle) {\n\tswitch (handle) {\n\t\tcase 'top':\n\t\t\treturn 'bottom'\n\t\tcase 'bottom':\n\t\t\treturn 'top'\n\t\tcase 'top_left':\n\t\t\treturn 'bottom_left'\n\t\tcase 'top_right':\n\t\t\treturn 'bottom_right'\n\t\tcase 'bottom_left':\n\t\t\treturn 'top_left'\n\t\tcase 'bottom_right':\n\t\t\treturn 'top_right'\n\t\tdefault:\n\t\t\treturn handle\n\t}\n}\n\n/** @public */\nexport function flipSelectionHandleX(handle: SelectionHandle) {\n\tswitch (handle) {\n\t\tcase 'left':\n\t\t\treturn 'right'\n\t\tcase 'right':\n\t\t\treturn 'left'\n\t\tcase 'top_left':\n\t\t\treturn 'top_right'\n\t\tcase 'top_right':\n\t\t\treturn 'top_left'\n\t\tcase 'bottom_left':\n\t\t\treturn 'bottom_right'\n\t\tcase 'bottom_right':\n\t\t\treturn 'bottom_left'\n\t\tdefault:\n\t\t\treturn handle\n\t}\n}\n\nconst ORDERED_SELECTION_HANDLES = [\n\t'top',\n\t'top_right',\n\t'right',\n\t'bottom_right',\n\t'bottom',\n\t'bottom_left',\n\t'left',\n\t'top_left',\n] as const\n\n/** @public */\nexport function rotateSelectionHandle(handle: SelectionHandle, rotation: number): SelectionHandle {\n\t// first find out how many tau we need to rotate by\n\trotation = rotation % PI2\n\tconst numSteps = Math.round(rotation / (PI / 4))\n\n\tconst currentIndex = ORDERED_SELECTION_HANDLES.indexOf(handle)\n\treturn ORDERED_SELECTION_HANDLES[(currentIndex + numSteps) % ORDERED_SELECTION_HANDLES.length]\n}\n\n/** @public */\nexport function isSelectionCorner(selection: string): selection is SelectionCorner {\n\treturn (\n\t\tselection === 'top_left' ||\n\t\tselection === 'top_right' ||\n\t\tselection === 'bottom_right' ||\n\t\tselection === 'bottom_left'\n\t)\n}\n\n/** @public */\nexport const ROTATE_CORNER_TO_SELECTION_CORNER = {\n\ttop_left_rotate: 'top_left',\n\ttop_right_rotate: 'top_right',\n\tbottom_right_rotate: 'bottom_right',\n\tbottom_left_rotate: 'bottom_left',\n\tmobile_rotate: 'top_left',\n} as const\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,iBAA6B;AAC7B,mBAAuD;AAuBhD,MAAM,IAAI;AAAA,EAChB,YAAY,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG;AACvC,SAAK,IAAI;AACT,SAAK,IAAI;AACT,SAAK,IAAI;AACT,SAAK,IAAI;AAAA,EACV;AAAA,EAEA,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA;AAAA,EAGJ,IAAI,QAAQ;AACX,WAAO,IAAI,eAAI,KAAK,GAAG,KAAK,CAAC;AAAA,EAC9B;AAAA;AAAA,EAGA,IAAI,MAAM,KAAU;AACnB,SAAK,IAAI,IAAI;AACb,SAAK,IAAI,IAAI;AAAA,EACd;AAAA;AAAA,EAGA,IAAI,OAAO;AACV,WAAO,KAAK;AAAA,EACb;AAAA;AAAA,EAGA,IAAI,KAAK,GAAW;AACnB,SAAK,IAAI;AAAA,EACV;AAAA;AAAA,EAGA,IAAI,OAAO;AACV,WAAO,KAAK;AAAA,EACb;AAAA;AAAA,EAGA,IAAI,OAAO;AACV,WAAO,KAAK,IAAI,KAAK,IAAI;AAAA,EAC1B;AAAA;AAAA,EAGA,IAAI,OAAO;AACV,WAAO,KAAK,IAAI,KAAK;AAAA,EACtB;AAAA;AAAA,EAGA,IAAI,QAAQ;AACX,WAAO,KAAK,IAAI,KAAK;AAAA,EACtB;AAAA;AAAA,EAGA,IAAI,OAAO;AACV,WAAO,KAAK;AAAA,EACb;AAAA;AAAA,EAGA,IAAI,KAAK,GAAW;A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UAAQ,QAAQ;AAAA,IACf,KAAK;AACJ,aAAO;AAAA,IACR,KAAK;AACJ,aAAO;AAAA,IACR,KAAK;AACJ,aAAO;AAAA,IACR,KAAK;AACJ,aAAO;AAAA,IACR,KAAK;AACJ,aAAO;AAAA,IACR,KAAK;AACJ,aAAO;AAAA,IACR;AACC,aAAO;AAAA,EACT;AACD;AAEA,MAAM,4BAA4B;AAAA,EACjC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD;AAGO,SAAS,sBAAsB,QAAyB,UAAmC;AAEjG,aAAW,WAAW;AACtB,QAAM,WAAW,KAAK,MAAM,YAAY,kBAAK,EAAE;AAE/C,QAAM,eAAe,0BAA0B,QAAQ,MAAM;AAC7D,SAAO,2BAA2B,eAAe,YAAY,0BAA0B,MAAM;AAC9F;AAGO,SAAS,kBAAkB,WAAiD;AAClF,SACC,cAAc,cACd,cAAc,eACd,cAAc,kBACd,cAAc;AAEhB;AAGO,MAAM,oCAAoC;AAAA,EAChD,iBAAiB;AAAA,EACjB,kBAAkB;AAAA,EAClB,qBAAqB;AAAA,EACrB,oBAAoB;AAAA,EACpB,eAAe;AAChB;",
6
6
  "names": []
7
7
  }
@@ -22,10 +22,10 @@ __export(version_exports, {
22
22
  version: () => version
23
23
  });
24
24
  module.exports = __toCommonJS(version_exports);
25
- const version = "3.16.0-internal.51e99e128bd4";
25
+ const version = "3.16.0-next.15f085081fd5";
26
26
  const publishDates = {
27
27
  major: "2024-09-13T14:36:29.063Z",
28
- minor: "2025-08-19T10:06:54.740Z",
29
- patch: "2025-08-19T10:06:54.740Z"
28
+ minor: "2025-08-27T13:43:07.665Z",
29
+ patch: "2025-08-27T13:43:07.665Z"
30
30
  };
31
31
  //# sourceMappingURL=version.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/version.ts"],
4
- "sourcesContent": ["// This file is automatically generated by internal/scripts/refresh-assets.ts.\n// Do not edit manually. Or do, I'm a comment, not a cop.\n\nexport const version = '3.16.0-internal.51e99e128bd4'\nexport const publishDates = {\n\tmajor: '2024-09-13T14:36:29.063Z',\n\tminor: '2025-08-19T10:06:54.740Z',\n\tpatch: '2025-08-19T10:06:54.740Z',\n}\n"],
4
+ "sourcesContent": ["// This file is automatically generated by internal/scripts/refresh-assets.ts.\n// Do not edit manually. Or do, I'm a comment, not a cop.\n\nexport const version = '3.16.0-next.15f085081fd5'\nexport const publishDates = {\n\tmajor: '2024-09-13T14:36:29.063Z',\n\tminor: '2025-08-27T13:43:07.665Z',\n\tpatch: '2025-08-27T13:43:07.665Z',\n}\n"],
5
5
  "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGO,MAAM,UAAU;AAChB,MAAM,eAAe;AAAA,EAC3B,OAAO;AAAA,EACP,OAAO;AAAA,EACP,OAAO;AACR;",
6
6
  "names": []
7
7
  }
@@ -510,6 +510,7 @@ export declare class Box {
510
510
  static ExpandBy(A: Box, n: number): Box;
511
511
  static Collides(A: Box, B: Box): boolean;
512
512
  static Contains(A: Box, B: Box): boolean;
513
+ static ContainsApproximately(A: Box, B: Box, precision?: number): boolean;
513
514
  static Includes(A: Box, B: Box): boolean;
514
515
  static ContainsPoint(A: Box, B: VecLike, margin?: number): boolean;
515
516
  static Common(boxes: Box[]): Box;
@@ -3708,6 +3709,20 @@ export declare class Editor extends EventEmitter<TLEventMap> {
3708
3709
  height: number;
3709
3710
  width: number;
3710
3711
  }>;
3712
+ /**
3713
+ * Get an exported image of the given shapes as a data URL.
3714
+ *
3715
+ * @param shapes - The shapes (or shape ids) to export.
3716
+ * @param opts - Options for the export.
3717
+ *
3718
+ * @returns A data URL of the image.
3719
+ * @public
3720
+ */
3721
+ toImageDataUrl(shapes: TLShape[] | TLShapeId[], opts?: TLImageExportOptions): Promise<{
3722
+ height: number;
3723
+ url: string;
3724
+ width: number;
3725
+ }>;
3711
3726
  /**
3712
3727
  * The app's current input state.
3713
3728
  *
@@ -5265,6 +5280,17 @@ export declare abstract class ShapeUtil<Shape extends TLUnknownShape = TLUnknown
5265
5280
  * @public
5266
5281
  */
5267
5282
  isAspectRatioLocked(_shape: Shape): boolean;
5283
+ /**
5284
+ * By default, the bounds of an image export are the bounds of all the shapes it contains, plus
5285
+ * some padding. If an export includes a shape where `isExportBoundsContainer` is true, then the
5286
+ * padding is skipped _if the bounds of that shape contains all the other shapes_. This is
5287
+ * useful in cases like annotating on top of an image, where you usually want to avoid extra
5288
+ * padding around the image if you don't need it.
5289
+ *
5290
+ * @param _shape - The shape to check
5291
+ * @returns True if this shape should be treated as an export bounds container
5292
+ */
5293
+ isExportBoundsContainer(_shape: Shape): boolean;
5268
5294
  /* Excluded from this release type: backgroundComponent */
5269
5295
  /**
5270
5296
  * Get the interpolated props for an animating shape. This is an optional method.
@@ -303,7 +303,7 @@ function debugEnableLicensing() {
303
303
  }
304
304
  registerTldrawLibraryVersion(
305
305
  "@tldraw/editor",
306
- "3.16.0-internal.51e99e128bd4",
306
+ "3.16.0-next.15f085081fd5",
307
307
  "esm"
308
308
  );
309
309
  export {
@@ -298,8 +298,12 @@ function TldrawEditorWithReadyStore({
298
298
  if (editor !== fontLoadingState?.editor) {
299
299
  fontLoadingState = null;
300
300
  }
301
- useEffect(() => {
301
+ useLayoutEffect(() => {
302
302
  if (!editor) return;
303
+ if (editor.options.maxFontsToLoadBeforeRender === 0) {
304
+ setFontLoadingState({ editor, isLoaded: true });
305
+ return;
306
+ }
303
307
  let isCancelled = false;
304
308
  setFontLoadingState({ editor, isLoaded: false });
305
309
  editor.fonts.loadRequiredFontsForCurrentPage(editor.options.maxFontsToLoadBeforeRender).finally(() => {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/lib/TldrawEditor.tsx"],
4
- "sourcesContent": ["import { MigrationSequence, Store } from '@tldraw/store'\nimport { TLShape, TLStore, TLStoreSnapshot } from '@tldraw/tlschema'\nimport { annotateError, Required } from '@tldraw/utils'\nimport React, {\n\tmemo,\n\tReactNode,\n\tuseCallback,\n\tuseEffect,\n\tuseLayoutEffect,\n\tuseMemo,\n\tuseRef,\n\tuseState,\n\tuseSyncExternalStore,\n} from 'react'\n\nimport classNames from 'classnames'\nimport { version } from '../version'\nimport { DefaultErrorFallback } from './components/default-components/DefaultErrorFallback'\nimport { OptionalErrorBoundary } from './components/ErrorBoundary'\nimport { TLStoreBaseOptions } from './config/createTLStore'\nimport { createTLUser, TLUser } from './config/createTLUser'\nimport { TLAnyBindingUtilConstructor } from './config/defaultBindings'\nimport { TLAnyShapeUtilConstructor } from './config/defaultShapes'\nimport { TLEditorSnapshot } from './config/TLEditorSnapshot'\nimport { Editor } from './editor/Editor'\nimport { TLStateNodeConstructor } from './editor/tools/StateNode'\nimport { TLCameraOptions } from './editor/types/misc-types'\nimport { ContainerProvider, useContainer } from './hooks/useContainer'\nimport { useCursor } from './hooks/useCursor'\nimport { useDarkMode } from './hooks/useDarkMode'\nimport { EditorProvider, useEditor } from './hooks/useEditor'\nimport {\n\tEditorComponentsProvider,\n\tTLEditorComponents,\n\tuseEditorComponents,\n} from './hooks/useEditorComponents'\nimport { useEvent } from './hooks/useEvent'\nimport { useForceUpdate } from './hooks/useForceUpdate'\nimport { useShallowObjectIdentity } from './hooks/useIdentity'\nimport { useLocalStore } from './hooks/useLocalStore'\nimport { useRefState } from './hooks/useRefState'\nimport { useStateAttribute } from './hooks/useStateAttribute'\nimport { useZoomCss } from './hooks/useZoomCss'\nimport { LicenseProvider } from './license/LicenseProvider'\nimport { Watermark } from './license/Watermark'\nimport { TldrawOptions } from './options'\nimport { TLDeepLinkOptions } from './utils/deepLinks'\nimport { stopEventPropagation } from './utils/dom'\nimport { TLTextOptions } from './utils/richText'\nimport { TLStoreWithStatus } from './utils/sync/StoreWithStatus'\n\n/**\n * Props for the {@link tldraw#Tldraw} and {@link TldrawEditor} components, when passing in a\n * `TLStore` directly. If you would like tldraw to create a store for you, use\n * {@link TldrawEditorWithoutStoreProps}.\n *\n * @public\n */\nexport interface TldrawEditorWithStoreProps {\n\t/**\n\t * The store to use in the editor.\n\t */\n\tstore: TLStore | TLStoreWithStatus\n}\n\n/**\n * Props for the {@link tldraw#Tldraw} and {@link TldrawEditor} components, when not passing in a\n * `TLStore` directly. If you would like to pass in a store directly, use\n * {@link TldrawEditorWithStoreProps}.\n *\n * @public\n */\nexport interface TldrawEditorWithoutStoreProps extends TLStoreBaseOptions {\n\tstore?: undefined\n\n\t/**\n\t * Additional migrations to use in the store\n\t */\n\tmigrations?: readonly MigrationSequence[]\n\n\t/**\n\t * A starting snapshot of data to pre-populate the store. Do not supply both this and\n\t * `initialData`.\n\t */\n\tsnapshot?: TLEditorSnapshot | TLStoreSnapshot\n\n\t/**\n\t * If you would like to persist the store to the browser's local IndexedDB storage and sync it\n\t * across tabs, provide a key here. Each key represents a single tldraw document.\n\t */\n\tpersistenceKey?: string\n\n\tsessionId?: string\n}\n\n/** @public */\nexport type TldrawEditorStoreProps = TldrawEditorWithStoreProps | TldrawEditorWithoutStoreProps\n\n/**\n * Props for the {@link tldraw#Tldraw} and {@link TldrawEditor} components.\n *\n * @public\n **/\nexport type TldrawEditorProps = TldrawEditorBaseProps & TldrawEditorStoreProps\n\n/**\n * Base props for the {@link tldraw#Tldraw} and {@link TldrawEditor} components.\n *\n * @public\n */\nexport interface TldrawEditorBaseProps {\n\t/**\n\t * The component's children.\n\t */\n\tchildren?: ReactNode\n\n\t/**\n\t * An array of shape utils to use in the editor.\n\t */\n\tshapeUtils?: readonly TLAnyShapeUtilConstructor[]\n\n\t/**\n\t * An array of binding utils to use in the editor.\n\t */\n\tbindingUtils?: readonly TLAnyBindingUtilConstructor[]\n\n\t/**\n\t * An array of tools to add to the editor's state chart.\n\t */\n\ttools?: readonly TLStateNodeConstructor[]\n\n\t/**\n\t * Whether to automatically focus the editor when it mounts.\n\t */\n\tautoFocus?: boolean\n\n\t/**\n\t * Overrides for the editor's components, such as handles, collaborator cursors, etc.\n\t */\n\tcomponents?: TLEditorComponents\n\n\t/**\n\t * Called when the editor has mounted.\n\t */\n\tonMount?: TLOnMountHandler\n\n\t/**\n\t * The editor's initial state (usually the id of the first active tool).\n\t */\n\tinitialState?: string\n\n\t/**\n\t * A classname to pass to the editor's container.\n\t */\n\tclassName?: string\n\n\t/**\n\t * The user interacting with the editor.\n\t */\n\tuser?: TLUser\n\n\t/**\n\t * Whether to infer dark mode from the user's OS. Defaults to false.\n\t */\n\tinferDarkMode?: boolean\n\n\t/**\n\t * Camera options for the editor.\n\t */\n\tcameraOptions?: Partial<TLCameraOptions>\n\n\t/**\n\t * Text options for the editor.\n\t */\n\ttextOptions?: TLTextOptions\n\n\t/**\n\t * Options for the editor.\n\t */\n\toptions?: Partial<TldrawOptions>\n\n\t/**\n\t * The license key.\n\t */\n\tlicenseKey?: string\n\n\t/**\n\t * Options for syncing the editor's camera state with the URL.\n\t */\n\tdeepLinks?: true | TLDeepLinkOptions\n\n\t/**\n\t * Predicate for whether or not a shape should be hidden.\n\t *\n\t * @deprecated Use {@link TldrawEditorBaseProps#getShapeVisibility} instead.\n\t */\n\tisShapeHidden?(shape: TLShape, editor: Editor): boolean\n\n\t/**\n\t * Provides a way to hide shapes.\n\t *\n\t * Hidden shapes will not render in the editor, and they will not be eligible for hit test via\n\t * {@link Editor#getShapeAtPoint} and {@link Editor#getShapesAtPoint}. But otherwise they will\n\t * remain in the store and participate in all other operations.\n\t *\n\t * @example\n\t * ```ts\n\t * getShapeVisibility={(shape, editor) => shape.meta.hidden ? 'hidden' : 'inherit'}\n\t * ```\n\t *\n\t * - `'inherit' | undefined` - (default) The shape will be visible unless its parent is hidden.\n\t * - `'hidden'` - The shape will be hidden.\n\t * - `'visible'` - The shape will be visible.\n\t *\n\t * @param shape - The shape to check.\n\t * @param editor - The editor instance.\n\t */\n\tgetShapeVisibility?(\n\t\tshape: TLShape,\n\t\teditor: Editor\n\t): 'visible' | 'hidden' | 'inherit' | null | undefined\n\n\t/**\n\t * The URLs for the fonts to use in the editor.\n\t */\n\tassetUrls?: { fonts?: { [key: string]: string | undefined } }\n}\n\n/**\n * Called when the editor has mounted.\n * @example\n * ```ts\n * <Tldraw onMount={(editor) => editor.selectAll()} />\n * ```\n * @param editor - The editor instance.\n *\n * @public\n */\nexport type TLOnMountHandler = (editor: Editor) => (() => void | undefined) | undefined | void\n\ndeclare global {\n\tinterface Window {\n\t\ttldrawReady: boolean\n\t}\n}\n\nconst EMPTY_SHAPE_UTILS_ARRAY = [] as const\nconst EMPTY_BINDING_UTILS_ARRAY = [] as const\nconst EMPTY_TOOLS_ARRAY = [] as const\n/** @internal */\nexport const TL_CONTAINER_CLASS = 'tl-container'\n\n/** @public @react */\nexport const TldrawEditor = memo(function TldrawEditor({\n\tstore,\n\tcomponents,\n\tclassName,\n\tuser: _user,\n\toptions: _options,\n\t...rest\n}: TldrawEditorProps) {\n\tconst [container, setContainer] = useState<HTMLElement | null>(null)\n\tconst user = useMemo(() => _user ?? createTLUser(), [_user])\n\n\tconst ErrorFallback =\n\t\tcomponents?.ErrorFallback === undefined ? DefaultErrorFallback : components?.ErrorFallback\n\n\t// apply defaults. if you're using the bare @tldraw/editor package, we\n\t// default these to the \"tldraw zero\" configuration. We have different\n\t// defaults applied in tldraw.\n\tconst withDefaults = {\n\t\t...rest,\n\t\tshapeUtils: rest.shapeUtils ?? EMPTY_SHAPE_UTILS_ARRAY,\n\t\tbindingUtils: rest.bindingUtils ?? EMPTY_BINDING_UTILS_ARRAY,\n\t\ttools: rest.tools ?? EMPTY_TOOLS_ARRAY,\n\t\tcomponents,\n\t\toptions: useShallowObjectIdentity(_options),\n\t}\n\n\treturn (\n\t\t<div\n\t\t\tref={setContainer}\n\t\t\tdata-tldraw={version}\n\t\t\tdraggable={false}\n\t\t\tclassName={classNames(`${TL_CONTAINER_CLASS} tl-theme__light`, className)}\n\t\t\tonPointerDown={stopEventPropagation}\n\t\t\ttabIndex={-1}\n\t\t\trole=\"application\"\n\t\t\taria-label={_options?.branding ?? 'tldraw'}\n\t\t>\n\t\t\t<OptionalErrorBoundary\n\t\t\t\tfallback={ErrorFallback}\n\t\t\t\tonError={(error) => annotateError(error, { tags: { origin: 'react.tldraw-before-app' } })}\n\t\t\t>\n\t\t\t\t{container && (\n\t\t\t\t\t<LicenseProvider licenseKey={rest.licenseKey}>\n\t\t\t\t\t\t<ContainerProvider container={container}>\n\t\t\t\t\t\t\t<EditorComponentsProvider overrides={components}>\n\t\t\t\t\t\t\t\t{store ? (\n\t\t\t\t\t\t\t\t\tstore instanceof Store ? (\n\t\t\t\t\t\t\t\t\t\t// Store is ready to go, whether externally synced or not\n\t\t\t\t\t\t\t\t\t\t<TldrawEditorWithReadyStore {...withDefaults} store={store} user={user} />\n\t\t\t\t\t\t\t\t\t) : (\n\t\t\t\t\t\t\t\t\t\t// Store is a synced store, so handle syncing stages internally\n\t\t\t\t\t\t\t\t\t\t<TldrawEditorWithLoadingStore {...withDefaults} store={store} user={user} />\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t) : (\n\t\t\t\t\t\t\t\t\t// We have no store (it's undefined) so create one and possibly sync it\n\t\t\t\t\t\t\t\t\t<TldrawEditorWithOwnStore {...withDefaults} store={store} user={user} />\n\t\t\t\t\t\t\t\t)}\n\t\t\t\t\t\t\t</EditorComponentsProvider>\n\t\t\t\t\t\t</ContainerProvider>\n\t\t\t\t\t</LicenseProvider>\n\t\t\t\t)}\n\t\t\t</OptionalErrorBoundary>\n\t\t</div>\n\t)\n})\n\nfunction TldrawEditorWithOwnStore(\n\tprops: Required<\n\t\tTldrawEditorProps & { store: undefined; user: TLUser },\n\t\t'shapeUtils' | 'bindingUtils' | 'tools'\n\t>\n) {\n\tconst {\n\t\tdefaultName,\n\t\tsnapshot,\n\t\tinitialData,\n\t\tshapeUtils,\n\t\tbindingUtils,\n\t\tpersistenceKey,\n\t\tsessionId,\n\t\tuser,\n\t\tassets,\n\t\tmigrations,\n\t} = props\n\n\tconst syncedStore = useLocalStore({\n\t\tshapeUtils,\n\t\tbindingUtils,\n\t\tinitialData,\n\t\tpersistenceKey,\n\t\tsessionId,\n\t\tdefaultName,\n\t\tsnapshot,\n\t\tassets,\n\t\tmigrations,\n\t})\n\n\treturn <TldrawEditorWithLoadingStore {...props} store={syncedStore} user={user} />\n}\n\nconst TldrawEditorWithLoadingStore = memo(function TldrawEditorBeforeLoading({\n\tstore,\n\tuser,\n\t...rest\n}: Required<\n\tTldrawEditorProps & { store: TLStoreWithStatus; user: TLUser },\n\t'shapeUtils' | 'bindingUtils' | 'tools'\n>) {\n\tconst container = useContainer()\n\n\tuseLayoutEffect(() => {\n\t\tif (user.userPreferences.get().colorScheme === 'dark') {\n\t\t\tcontainer.classList.remove('tl-theme__light')\n\t\t\tcontainer.classList.add('tl-theme__dark')\n\t\t}\n\t}, [container, user])\n\n\tconst { LoadingScreen } = useEditorComponents()\n\n\tswitch (store.status) {\n\t\tcase 'error': {\n\t\t\t// for error handling, we fall back to the default error boundary.\n\t\t\t// if users want to handle this error differently, they can render\n\t\t\t// their own error screen before the TldrawEditor component\n\t\t\tthrow store.error\n\t\t}\n\t\tcase 'loading': {\n\t\t\treturn LoadingScreen ? <LoadingScreen /> : null\n\t\t}\n\t\tcase 'not-synced': {\n\t\t\tbreak\n\t\t}\n\t\tcase 'synced-local': {\n\t\t\tbreak\n\t\t}\n\t\tcase 'synced-remote': {\n\t\t\tbreak\n\t\t}\n\t}\n\n\treturn <TldrawEditorWithReadyStore {...rest} store={store.store} user={user} />\n})\n\nconst noAutoFocus = () => document.location.search.includes('tldraw_preserve_focus') // || !document.hasFocus() // breaks in nextjs\n\nfunction TldrawEditorWithReadyStore({\n\tonMount,\n\tchildren,\n\tstore,\n\ttools,\n\tshapeUtils,\n\tbindingUtils,\n\tuser,\n\tinitialState,\n\tautoFocus = true,\n\tinferDarkMode,\n\tcameraOptions,\n\ttextOptions,\n\toptions,\n\tlicenseKey,\n\tdeepLinks: _deepLinks,\n\t// eslint-disable-next-line @typescript-eslint/no-deprecated\n\tisShapeHidden,\n\tgetShapeVisibility,\n\tassetUrls,\n}: Required<\n\tTldrawEditorProps & {\n\t\tstore: TLStore\n\t\tuser: TLUser\n\t},\n\t'shapeUtils' | 'bindingUtils' | 'tools'\n>) {\n\tconst { ErrorFallback } = useEditorComponents()\n\tconst container = useContainer()\n\n\tconst [editor, setEditor] = useRefState<Editor | null>(null)\n\n\tconst canvasRef = useRef<HTMLDivElement | null>(null)\n\n\tconst deepLinks = useShallowObjectIdentity(_deepLinks === true ? {} : _deepLinks)\n\n\t// props in this ref can be changed without causing the editor to be recreated.\n\tconst editorOptionsRef = useRef({\n\t\t// for these, it's because they're only used when the editor first mounts:\n\t\tautoFocus: autoFocus && !noAutoFocus(),\n\t\tinferDarkMode,\n\t\tinitialState,\n\n\t\t// for these, it's because we keep them up to date in a separate effect:\n\t\tcameraOptions,\n\t\tdeepLinks,\n\t})\n\n\tuseLayoutEffect(() => {\n\t\teditorOptionsRef.current = {\n\t\t\tautoFocus: autoFocus && !noAutoFocus(),\n\t\t\tinferDarkMode,\n\t\t\tinitialState,\n\t\t\tcameraOptions,\n\t\t\tdeepLinks,\n\t\t}\n\t}, [autoFocus, inferDarkMode, initialState, cameraOptions, deepLinks])\n\n\tuseLayoutEffect(\n\t\t() => {\n\t\t\tconst { autoFocus, inferDarkMode, initialState, cameraOptions, deepLinks } =\n\t\t\t\teditorOptionsRef.current\n\t\t\tconst editor = new Editor({\n\t\t\t\tstore,\n\t\t\t\tshapeUtils,\n\t\t\t\tbindingUtils,\n\t\t\t\ttools,\n\t\t\t\tgetContainer: () => container,\n\t\t\t\tuser,\n\t\t\t\tinitialState,\n\t\t\t\t// we should check for some kind of query parameter that turns off autofocus\n\t\t\t\tautoFocus,\n\t\t\t\tinferDarkMode,\n\t\t\t\tcameraOptions,\n\t\t\t\ttextOptions,\n\t\t\t\toptions,\n\t\t\t\tlicenseKey,\n\t\t\t\tisShapeHidden,\n\t\t\t\tgetShapeVisibility,\n\t\t\t\tfontAssetUrls: assetUrls?.fonts,\n\t\t\t})\n\n\t\t\teditor.updateViewportScreenBounds(canvasRef.current ?? container)\n\n\t\t\t// Use the ref here because we only want to do this once when the editor is created.\n\t\t\t// We don't want changes to the urlStateSync prop to trigger creating new editors.\n\t\t\tif (deepLinks) {\n\t\t\t\tif (!deepLinks?.getUrl) {\n\t\t\t\t\t// load the state from window.location\n\t\t\t\t\teditor.navigateToDeepLink(deepLinks)\n\t\t\t\t} else {\n\t\t\t\t\t// load the state from the provided URL\n\t\t\t\t\teditor.navigateToDeepLink({ ...deepLinks, url: deepLinks.getUrl(editor) })\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tsetEditor(editor)\n\n\t\t\treturn () => {\n\t\t\t\teditor.dispose()\n\t\t\t}\n\t\t},\n\t\t// if any of these change, we need to recreate the editor.\n\t\t[\n\t\t\tbindingUtils,\n\t\t\tcontainer,\n\t\t\toptions,\n\t\t\tshapeUtils,\n\t\t\tstore,\n\t\t\ttools,\n\t\t\tuser,\n\t\t\tsetEditor,\n\t\t\tlicenseKey,\n\t\t\tisShapeHidden,\n\t\t\tgetShapeVisibility,\n\t\t\ttextOptions,\n\t\t\tassetUrls,\n\t\t]\n\t)\n\n\tuseLayoutEffect(() => {\n\t\tif (!editor) return\n\t\tif (deepLinks) {\n\t\t\treturn editor.registerDeepLinkListener(deepLinks)\n\t\t}\n\t}, [editor, deepLinks])\n\n\t// keep the editor up to date with the latest camera options\n\tuseLayoutEffect(() => {\n\t\tif (editor && cameraOptions) {\n\t\t\teditor.setCameraOptions(cameraOptions)\n\t\t}\n\t}, [editor, cameraOptions])\n\n\tconst crashingError = useSyncExternalStore(\n\t\tuseCallback(\n\t\t\t(onStoreChange) => {\n\t\t\t\tif (editor) {\n\t\t\t\t\teditor.on('crash', onStoreChange)\n\t\t\t\t\treturn () => editor.off('crash', onStoreChange)\n\t\t\t\t}\n\t\t\t\treturn () => {\n\t\t\t\t\t// noop\n\t\t\t\t}\n\t\t\t},\n\t\t\t[editor]\n\t\t),\n\t\t() => editor?.getCrashingError() ?? null\n\t)\n\n\t// For our examples site, we want autoFocus to be true on the examples site, but not\n\t// when embedded in our docs site. If present, the `tldraw_preserve_focus` search param\n\t// overrides the `autoFocus` prop and prevents the editor from focusing immediately,\n\t// however here we also add some logic to focus the editor when the user clicks\n\t// on it and unfocus it when the user clicks away from it.\n\tuseEffect(\n\t\tfunction handleFocusOnPointerDownForPreserveFocusMode() {\n\t\t\tif (!editor) return\n\n\t\t\tfunction handleFocusOnPointerDown() {\n\t\t\t\tif (!editor) return\n\t\t\t\teditor.focus()\n\t\t\t}\n\n\t\t\tfunction handleBlurOnPointerDown() {\n\t\t\t\tif (!editor) return\n\t\t\t\teditor.blur()\n\t\t\t}\n\n\t\t\tif (autoFocus && noAutoFocus()) {\n\t\t\t\teditor.getContainer().addEventListener('pointerdown', handleFocusOnPointerDown)\n\t\t\t\tdocument.body.addEventListener('pointerdown', handleBlurOnPointerDown)\n\n\t\t\t\treturn () => {\n\t\t\t\t\teditor.getContainer()?.removeEventListener('pointerdown', handleFocusOnPointerDown)\n\t\t\t\t\tdocument.body.removeEventListener('pointerdown', handleBlurOnPointerDown)\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\t[editor, autoFocus]\n\t)\n\n\tconst [_fontLoadingState, setFontLoadingState] = useState<{\n\t\teditor: Editor\n\t\tisLoaded: boolean\n\t} | null>(null)\n\tlet fontLoadingState = _fontLoadingState\n\tif (editor !== fontLoadingState?.editor) {\n\t\tfontLoadingState = null\n\t}\n\tuseEffect(() => {\n\t\tif (!editor) return\n\t\tlet isCancelled = false\n\n\t\tsetFontLoadingState({ editor, isLoaded: false })\n\n\t\teditor.fonts\n\t\t\t.loadRequiredFontsForCurrentPage(editor.options.maxFontsToLoadBeforeRender)\n\t\t\t.finally(() => {\n\t\t\t\tif (isCancelled) return\n\t\t\t\tsetFontLoadingState({ editor, isLoaded: true })\n\t\t\t})\n\n\t\treturn () => {\n\t\t\tisCancelled = true\n\t\t}\n\t}, [editor])\n\n\tconst { Canvas, LoadingScreen } = useEditorComponents()\n\n\tif (!editor || !fontLoadingState?.isLoaded) {\n\t\treturn (\n\t\t\t<>\n\t\t\t\t{LoadingScreen && <LoadingScreen />}\n\t\t\t\t<div className=\"tl-canvas\" ref={canvasRef} />\n\t\t\t</>\n\t\t)\n\t}\n\n\treturn (\n\t\t// the top-level tldraw component also renders an error boundary almost\n\t\t// identical to this one. the reason we have two is because this one has\n\t\t// access to `App`, which means that here we can enrich errors with data\n\t\t// from app for reporting, and also still attempt to render the user's\n\t\t// document in the event of an error to reassure them that their work is\n\t\t// not lost.\n\t\t<OptionalErrorBoundary\n\t\t\tfallback={ErrorFallback as any}\n\t\t\tonError={(error) =>\n\t\t\t\teditor.annotateError(error, { origin: 'react.tldraw', willCrashApp: true })\n\t\t\t}\n\t\t>\n\t\t\t{crashingError ? (\n\t\t\t\t<Crash crashingError={crashingError} />\n\t\t\t) : (\n\t\t\t\t<EditorProvider editor={editor}>\n\t\t\t\t\t<Layout onMount={onMount}>\n\t\t\t\t\t\t{children ?? (Canvas ? <Canvas key={editor.contextId} /> : null)}\n\t\t\t\t\t\t<Watermark />\n\t\t\t\t\t</Layout>\n\t\t\t\t</EditorProvider>\n\t\t\t)}\n\t\t</OptionalErrorBoundary>\n\t)\n}\n\nfunction Layout({ children, onMount }: { children: ReactNode; onMount?: TLOnMountHandler }) {\n\tuseZoomCss()\n\tuseCursor()\n\tuseDarkMode()\n\tuseForceUpdate()\n\tuseStateAttribute()\n\tuseOnMount((editor) => {\n\t\tconst teardownStore = editor.store.props.onMount(editor)\n\t\tconst teardownCallback = onMount?.(editor)\n\n\t\treturn () => {\n\t\t\tteardownStore?.()\n\t\t\tteardownCallback?.()\n\t\t}\n\t})\n\n\treturn children\n}\n\nfunction Crash({ crashingError }: { crashingError: unknown }): null {\n\tthrow crashingError\n}\n\n/** @public */\nexport interface LoadingScreenProps {\n\tchildren: ReactNode\n}\n\n/** @public @react */\nexport function LoadingScreen({ children }: LoadingScreenProps) {\n\treturn (\n\t\t<div className=\"tl-loading\" aria-busy=\"true\" tabIndex={0}>\n\t\t\t{children}\n\t\t</div>\n\t)\n}\n\n/** @public @react */\nexport function ErrorScreen({ children }: LoadingScreenProps) {\n\treturn <div className=\"tl-loading\">{children}</div>\n}\n\n/** @internal */\nexport function useOnMount(onMount?: TLOnMountHandler) {\n\tconst editor = useEditor()\n\n\tconst onMountEvent = useEvent((editor: Editor) => {\n\t\tlet teardown: (() => void) | void = undefined\n\t\t// If the user wants to do something when the editor mounts, we make sure it doesn't effect the history.\n\t\t// todo: is this reeeeally what we want to do, or should we leave it up to the caller?\n\t\teditor.run(\n\t\t\t() => {\n\t\t\t\tteardown = onMount?.(editor)\n\t\t\t\teditor.emit('mount')\n\t\t\t},\n\t\t\t{ history: 'ignore' }\n\t\t)\n\t\twindow.tldrawReady = true\n\t\treturn teardown\n\t})\n\n\tReact.useLayoutEffect(() => {\n\t\tif (editor) return onMountEvent?.(editor)\n\t}, [editor, onMountEvent])\n}\n"],
5
- "mappings": "AA6SU,SAqTP,UArTO,KAqTP,YArTO;AA7SV,SAA4B,aAAa;AAEzC,SAAS,qBAA+B;AACxC,OAAO;AAAA,EACN;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AAEP,OAAO,gBAAgB;AACvB,SAAS,eAAe;AACxB,SAAS,4BAA4B;AACrC,SAAS,6BAA6B;AAEtC,SAAS,oBAA4B;AAIrC,SAAS,cAAc;AAGvB,SAAS,mBAAmB,oBAAoB;AAChD,SAAS,iBAAiB;AAC1B,SAAS,mBAAmB;AAC5B,SAAS,gBAAgB,iBAAiB;AAC1C;AAAA,EACC;AAAA,EAEA;AAAA,OACM;AACP,SAAS,gBAAgB;AACzB,SAAS,sBAAsB;AAC/B,SAAS,gCAAgC;AACzC,SAAS,qBAAqB;AAC9B,SAAS,m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AAG,CAAC,QAAQ,YAAY,CAAC;AAC1B;",
4
+ "sourcesContent": ["import { MigrationSequence, Store } from '@tldraw/store'\nimport { TLShape, TLStore, TLStoreSnapshot } from '@tldraw/tlschema'\nimport { annotateError, Required } from '@tldraw/utils'\nimport React, {\n\tmemo,\n\tReactNode,\n\tuseCallback,\n\tuseEffect,\n\tuseLayoutEffect,\n\tuseMemo,\n\tuseRef,\n\tuseState,\n\tuseSyncExternalStore,\n} from 'react'\n\nimport classNames from 'classnames'\nimport { version } from '../version'\nimport { DefaultErrorFallback } from './components/default-components/DefaultErrorFallback'\nimport { OptionalErrorBoundary } from './components/ErrorBoundary'\nimport { TLStoreBaseOptions } from './config/createTLStore'\nimport { createTLUser, TLUser } from './config/createTLUser'\nimport { TLAnyBindingUtilConstructor } from './config/defaultBindings'\nimport { TLAnyShapeUtilConstructor } from './config/defaultShapes'\nimport { TLEditorSnapshot } from './config/TLEditorSnapshot'\nimport { Editor } from './editor/Editor'\nimport { TLStateNodeConstructor } from './editor/tools/StateNode'\nimport { TLCameraOptions } from './editor/types/misc-types'\nimport { ContainerProvider, useContainer } from './hooks/useContainer'\nimport { useCursor } from './hooks/useCursor'\nimport { useDarkMode } from './hooks/useDarkMode'\nimport { EditorProvider, useEditor } from './hooks/useEditor'\nimport {\n\tEditorComponentsProvider,\n\tTLEditorComponents,\n\tuseEditorComponents,\n} from './hooks/useEditorComponents'\nimport { useEvent } from './hooks/useEvent'\nimport { useForceUpdate } from './hooks/useForceUpdate'\nimport { useShallowObjectIdentity } from './hooks/useIdentity'\nimport { useLocalStore } from './hooks/useLocalStore'\nimport { useRefState } from './hooks/useRefState'\nimport { useStateAttribute } from './hooks/useStateAttribute'\nimport { useZoomCss } from './hooks/useZoomCss'\nimport { LicenseProvider } from './license/LicenseProvider'\nimport { Watermark } from './license/Watermark'\nimport { TldrawOptions } from './options'\nimport { TLDeepLinkOptions } from './utils/deepLinks'\nimport { stopEventPropagation } from './utils/dom'\nimport { TLTextOptions } from './utils/richText'\nimport { TLStoreWithStatus } from './utils/sync/StoreWithStatus'\n\n/**\n * Props for the {@link tldraw#Tldraw} and {@link TldrawEditor} components, when passing in a\n * `TLStore` directly. If you would like tldraw to create a store for you, use\n * {@link TldrawEditorWithoutStoreProps}.\n *\n * @public\n */\nexport interface TldrawEditorWithStoreProps {\n\t/**\n\t * The store to use in the editor.\n\t */\n\tstore: TLStore | TLStoreWithStatus\n}\n\n/**\n * Props for the {@link tldraw#Tldraw} and {@link TldrawEditor} components, when not passing in a\n * `TLStore` directly. If you would like to pass in a store directly, use\n * {@link TldrawEditorWithStoreProps}.\n *\n * @public\n */\nexport interface TldrawEditorWithoutStoreProps extends TLStoreBaseOptions {\n\tstore?: undefined\n\n\t/**\n\t * Additional migrations to use in the store\n\t */\n\tmigrations?: readonly MigrationSequence[]\n\n\t/**\n\t * A starting snapshot of data to pre-populate the store. Do not supply both this and\n\t * `initialData`.\n\t */\n\tsnapshot?: TLEditorSnapshot | TLStoreSnapshot\n\n\t/**\n\t * If you would like to persist the store to the browser's local IndexedDB storage and sync it\n\t * across tabs, provide a key here. Each key represents a single tldraw document.\n\t */\n\tpersistenceKey?: string\n\n\tsessionId?: string\n}\n\n/** @public */\nexport type TldrawEditorStoreProps = TldrawEditorWithStoreProps | TldrawEditorWithoutStoreProps\n\n/**\n * Props for the {@link tldraw#Tldraw} and {@link TldrawEditor} components.\n *\n * @public\n **/\nexport type TldrawEditorProps = TldrawEditorBaseProps & TldrawEditorStoreProps\n\n/**\n * Base props for the {@link tldraw#Tldraw} and {@link TldrawEditor} components.\n *\n * @public\n */\nexport interface TldrawEditorBaseProps {\n\t/**\n\t * The component's children.\n\t */\n\tchildren?: ReactNode\n\n\t/**\n\t * An array of shape utils to use in the editor.\n\t */\n\tshapeUtils?: readonly TLAnyShapeUtilConstructor[]\n\n\t/**\n\t * An array of binding utils to use in the editor.\n\t */\n\tbindingUtils?: readonly TLAnyBindingUtilConstructor[]\n\n\t/**\n\t * An array of tools to add to the editor's state chart.\n\t */\n\ttools?: readonly TLStateNodeConstructor[]\n\n\t/**\n\t * Whether to automatically focus the editor when it mounts.\n\t */\n\tautoFocus?: boolean\n\n\t/**\n\t * Overrides for the editor's components, such as handles, collaborator cursors, etc.\n\t */\n\tcomponents?: TLEditorComponents\n\n\t/**\n\t * Called when the editor has mounted.\n\t */\n\tonMount?: TLOnMountHandler\n\n\t/**\n\t * The editor's initial state (usually the id of the first active tool).\n\t */\n\tinitialState?: string\n\n\t/**\n\t * A classname to pass to the editor's container.\n\t */\n\tclassName?: string\n\n\t/**\n\t * The user interacting with the editor.\n\t */\n\tuser?: TLUser\n\n\t/**\n\t * Whether to infer dark mode from the user's OS. Defaults to false.\n\t */\n\tinferDarkMode?: boolean\n\n\t/**\n\t * Camera options for the editor.\n\t */\n\tcameraOptions?: Partial<TLCameraOptions>\n\n\t/**\n\t * Text options for the editor.\n\t */\n\ttextOptions?: TLTextOptions\n\n\t/**\n\t * Options for the editor.\n\t */\n\toptions?: Partial<TldrawOptions>\n\n\t/**\n\t * The license key.\n\t */\n\tlicenseKey?: string\n\n\t/**\n\t * Options for syncing the editor's camera state with the URL.\n\t */\n\tdeepLinks?: true | TLDeepLinkOptions\n\n\t/**\n\t * Predicate for whether or not a shape should be hidden.\n\t *\n\t * @deprecated Use {@link TldrawEditorBaseProps#getShapeVisibility} instead.\n\t */\n\tisShapeHidden?(shape: TLShape, editor: Editor): boolean\n\n\t/**\n\t * Provides a way to hide shapes.\n\t *\n\t * Hidden shapes will not render in the editor, and they will not be eligible for hit test via\n\t * {@link Editor#getShapeAtPoint} and {@link Editor#getShapesAtPoint}. But otherwise they will\n\t * remain in the store and participate in all other operations.\n\t *\n\t * @example\n\t * ```ts\n\t * getShapeVisibility={(shape, editor) => shape.meta.hidden ? 'hidden' : 'inherit'}\n\t * ```\n\t *\n\t * - `'inherit' | undefined` - (default) The shape will be visible unless its parent is hidden.\n\t * - `'hidden'` - The shape will be hidden.\n\t * - `'visible'` - The shape will be visible.\n\t *\n\t * @param shape - The shape to check.\n\t * @param editor - The editor instance.\n\t */\n\tgetShapeVisibility?(\n\t\tshape: TLShape,\n\t\teditor: Editor\n\t): 'visible' | 'hidden' | 'inherit' | null | undefined\n\n\t/**\n\t * The URLs for the fonts to use in the editor.\n\t */\n\tassetUrls?: { fonts?: { [key: string]: string | undefined } }\n}\n\n/**\n * Called when the editor has mounted.\n * @example\n * ```ts\n * <Tldraw onMount={(editor) => editor.selectAll()} />\n * ```\n * @param editor - The editor instance.\n *\n * @public\n */\nexport type TLOnMountHandler = (editor: Editor) => (() => void | undefined) | undefined | void\n\ndeclare global {\n\tinterface Window {\n\t\ttldrawReady: boolean\n\t}\n}\n\nconst EMPTY_SHAPE_UTILS_ARRAY = [] as const\nconst EMPTY_BINDING_UTILS_ARRAY = [] as const\nconst EMPTY_TOOLS_ARRAY = [] as const\n/** @internal */\nexport const TL_CONTAINER_CLASS = 'tl-container'\n\n/** @public @react */\nexport const TldrawEditor = memo(function TldrawEditor({\n\tstore,\n\tcomponents,\n\tclassName,\n\tuser: _user,\n\toptions: _options,\n\t...rest\n}: TldrawEditorProps) {\n\tconst [container, setContainer] = useState<HTMLElement | null>(null)\n\tconst user = useMemo(() => _user ?? createTLUser(), [_user])\n\n\tconst ErrorFallback =\n\t\tcomponents?.ErrorFallback === undefined ? DefaultErrorFallback : components?.ErrorFallback\n\n\t// apply defaults. if you're using the bare @tldraw/editor package, we\n\t// default these to the \"tldraw zero\" configuration. We have different\n\t// defaults applied in tldraw.\n\tconst withDefaults = {\n\t\t...rest,\n\t\tshapeUtils: rest.shapeUtils ?? EMPTY_SHAPE_UTILS_ARRAY,\n\t\tbindingUtils: rest.bindingUtils ?? EMPTY_BINDING_UTILS_ARRAY,\n\t\ttools: rest.tools ?? EMPTY_TOOLS_ARRAY,\n\t\tcomponents,\n\t\toptions: useShallowObjectIdentity(_options),\n\t}\n\n\treturn (\n\t\t<div\n\t\t\tref={setContainer}\n\t\t\tdata-tldraw={version}\n\t\t\tdraggable={false}\n\t\t\tclassName={classNames(`${TL_CONTAINER_CLASS} tl-theme__light`, className)}\n\t\t\tonPointerDown={stopEventPropagation}\n\t\t\ttabIndex={-1}\n\t\t\trole=\"application\"\n\t\t\taria-label={_options?.branding ?? 'tldraw'}\n\t\t>\n\t\t\t<OptionalErrorBoundary\n\t\t\t\tfallback={ErrorFallback}\n\t\t\t\tonError={(error) => annotateError(error, { tags: { origin: 'react.tldraw-before-app' } })}\n\t\t\t>\n\t\t\t\t{container && (\n\t\t\t\t\t<LicenseProvider licenseKey={rest.licenseKey}>\n\t\t\t\t\t\t<ContainerProvider container={container}>\n\t\t\t\t\t\t\t<EditorComponentsProvider overrides={components}>\n\t\t\t\t\t\t\t\t{store ? (\n\t\t\t\t\t\t\t\t\tstore instanceof Store ? (\n\t\t\t\t\t\t\t\t\t\t// Store is ready to go, whether externally synced or not\n\t\t\t\t\t\t\t\t\t\t<TldrawEditorWithReadyStore {...withDefaults} store={store} user={user} />\n\t\t\t\t\t\t\t\t\t) : (\n\t\t\t\t\t\t\t\t\t\t// Store is a synced store, so handle syncing stages internally\n\t\t\t\t\t\t\t\t\t\t<TldrawEditorWithLoadingStore {...withDefaults} store={store} user={user} />\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t) : (\n\t\t\t\t\t\t\t\t\t// We have no store (it's undefined) so create one and possibly sync it\n\t\t\t\t\t\t\t\t\t<TldrawEditorWithOwnStore {...withDefaults} store={store} user={user} />\n\t\t\t\t\t\t\t\t)}\n\t\t\t\t\t\t\t</EditorComponentsProvider>\n\t\t\t\t\t\t</ContainerProvider>\n\t\t\t\t\t</LicenseProvider>\n\t\t\t\t)}\n\t\t\t</OptionalErrorBoundary>\n\t\t</div>\n\t)\n})\n\nfunction TldrawEditorWithOwnStore(\n\tprops: Required<\n\t\tTldrawEditorProps & { store: undefined; user: TLUser },\n\t\t'shapeUtils' | 'bindingUtils' | 'tools'\n\t>\n) {\n\tconst {\n\t\tdefaultName,\n\t\tsnapshot,\n\t\tinitialData,\n\t\tshapeUtils,\n\t\tbindingUtils,\n\t\tpersistenceKey,\n\t\tsessionId,\n\t\tuser,\n\t\tassets,\n\t\tmigrations,\n\t} = props\n\n\tconst syncedStore = useLocalStore({\n\t\tshapeUtils,\n\t\tbindingUtils,\n\t\tinitialData,\n\t\tpersistenceKey,\n\t\tsessionId,\n\t\tdefaultName,\n\t\tsnapshot,\n\t\tassets,\n\t\tmigrations,\n\t})\n\n\treturn <TldrawEditorWithLoadingStore {...props} store={syncedStore} user={user} />\n}\n\nconst TldrawEditorWithLoadingStore = memo(function TldrawEditorBeforeLoading({\n\tstore,\n\tuser,\n\t...rest\n}: Required<\n\tTldrawEditorProps & { store: TLStoreWithStatus; user: TLUser },\n\t'shapeUtils' | 'bindingUtils' | 'tools'\n>) {\n\tconst container = useContainer()\n\n\tuseLayoutEffect(() => {\n\t\tif (user.userPreferences.get().colorScheme === 'dark') {\n\t\t\tcontainer.classList.remove('tl-theme__light')\n\t\t\tcontainer.classList.add('tl-theme__dark')\n\t\t}\n\t}, [container, user])\n\n\tconst { LoadingScreen } = useEditorComponents()\n\n\tswitch (store.status) {\n\t\tcase 'error': {\n\t\t\t// for error handling, we fall back to the default error boundary.\n\t\t\t// if users want to handle this error differently, they can render\n\t\t\t// their own error screen before the TldrawEditor component\n\t\t\tthrow store.error\n\t\t}\n\t\tcase 'loading': {\n\t\t\treturn LoadingScreen ? <LoadingScreen /> : null\n\t\t}\n\t\tcase 'not-synced': {\n\t\t\tbreak\n\t\t}\n\t\tcase 'synced-local': {\n\t\t\tbreak\n\t\t}\n\t\tcase 'synced-remote': {\n\t\t\tbreak\n\t\t}\n\t}\n\n\treturn <TldrawEditorWithReadyStore {...rest} store={store.store} user={user} />\n})\n\nconst noAutoFocus = () => document.location.search.includes('tldraw_preserve_focus') // || !document.hasFocus() // breaks in nextjs\n\nfunction TldrawEditorWithReadyStore({\n\tonMount,\n\tchildren,\n\tstore,\n\ttools,\n\tshapeUtils,\n\tbindingUtils,\n\tuser,\n\tinitialState,\n\tautoFocus = true,\n\tinferDarkMode,\n\tcameraOptions,\n\ttextOptions,\n\toptions,\n\tlicenseKey,\n\tdeepLinks: _deepLinks,\n\t// eslint-disable-next-line @typescript-eslint/no-deprecated\n\tisShapeHidden,\n\tgetShapeVisibility,\n\tassetUrls,\n}: Required<\n\tTldrawEditorProps & {\n\t\tstore: TLStore\n\t\tuser: TLUser\n\t},\n\t'shapeUtils' | 'bindingUtils' | 'tools'\n>) {\n\tconst { ErrorFallback } = useEditorComponents()\n\tconst container = useContainer()\n\n\tconst [editor, setEditor] = useRefState<Editor | null>(null)\n\n\tconst canvasRef = useRef<HTMLDivElement | null>(null)\n\n\tconst deepLinks = useShallowObjectIdentity(_deepLinks === true ? {} : _deepLinks)\n\n\t// props in this ref can be changed without causing the editor to be recreated.\n\tconst editorOptionsRef = useRef({\n\t\t// for these, it's because they're only used when the editor first mounts:\n\t\tautoFocus: autoFocus && !noAutoFocus(),\n\t\tinferDarkMode,\n\t\tinitialState,\n\n\t\t// for these, it's because we keep them up to date in a separate effect:\n\t\tcameraOptions,\n\t\tdeepLinks,\n\t})\n\n\tuseLayoutEffect(() => {\n\t\teditorOptionsRef.current = {\n\t\t\tautoFocus: autoFocus && !noAutoFocus(),\n\t\t\tinferDarkMode,\n\t\t\tinitialState,\n\t\t\tcameraOptions,\n\t\t\tdeepLinks,\n\t\t}\n\t}, [autoFocus, inferDarkMode, initialState, cameraOptions, deepLinks])\n\n\tuseLayoutEffect(\n\t\t() => {\n\t\t\tconst { autoFocus, inferDarkMode, initialState, cameraOptions, deepLinks } =\n\t\t\t\teditorOptionsRef.current\n\t\t\tconst editor = new Editor({\n\t\t\t\tstore,\n\t\t\t\tshapeUtils,\n\t\t\t\tbindingUtils,\n\t\t\t\ttools,\n\t\t\t\tgetContainer: () => container,\n\t\t\t\tuser,\n\t\t\t\tinitialState,\n\t\t\t\t// we should check for some kind of query parameter that turns off autofocus\n\t\t\t\tautoFocus,\n\t\t\t\tinferDarkMode,\n\t\t\t\tcameraOptions,\n\t\t\t\ttextOptions,\n\t\t\t\toptions,\n\t\t\t\tlicenseKey,\n\t\t\t\tisShapeHidden,\n\t\t\t\tgetShapeVisibility,\n\t\t\t\tfontAssetUrls: assetUrls?.fonts,\n\t\t\t})\n\n\t\t\teditor.updateViewportScreenBounds(canvasRef.current ?? container)\n\n\t\t\t// Use the ref here because we only want to do this once when the editor is created.\n\t\t\t// We don't want changes to the urlStateSync prop to trigger creating new editors.\n\t\t\tif (deepLinks) {\n\t\t\t\tif (!deepLinks?.getUrl) {\n\t\t\t\t\t// load the state from window.location\n\t\t\t\t\teditor.navigateToDeepLink(deepLinks)\n\t\t\t\t} else {\n\t\t\t\t\t// load the state from the provided URL\n\t\t\t\t\teditor.navigateToDeepLink({ ...deepLinks, url: deepLinks.getUrl(editor) })\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tsetEditor(editor)\n\n\t\t\treturn () => {\n\t\t\t\teditor.dispose()\n\t\t\t}\n\t\t},\n\t\t// if any of these change, we need to recreate the editor.\n\t\t[\n\t\t\tbindingUtils,\n\t\t\tcontainer,\n\t\t\toptions,\n\t\t\tshapeUtils,\n\t\t\tstore,\n\t\t\ttools,\n\t\t\tuser,\n\t\t\tsetEditor,\n\t\t\tlicenseKey,\n\t\t\tisShapeHidden,\n\t\t\tgetShapeVisibility,\n\t\t\ttextOptions,\n\t\t\tassetUrls,\n\t\t]\n\t)\n\n\tuseLayoutEffect(() => {\n\t\tif (!editor) return\n\t\tif (deepLinks) {\n\t\t\treturn editor.registerDeepLinkListener(deepLinks)\n\t\t}\n\t}, [editor, deepLinks])\n\n\t// keep the editor up to date with the latest camera options\n\tuseLayoutEffect(() => {\n\t\tif (editor && cameraOptions) {\n\t\t\teditor.setCameraOptions(cameraOptions)\n\t\t}\n\t}, [editor, cameraOptions])\n\n\tconst crashingError = useSyncExternalStore(\n\t\tuseCallback(\n\t\t\t(onStoreChange) => {\n\t\t\t\tif (editor) {\n\t\t\t\t\teditor.on('crash', onStoreChange)\n\t\t\t\t\treturn () => editor.off('crash', onStoreChange)\n\t\t\t\t}\n\t\t\t\treturn () => {\n\t\t\t\t\t// noop\n\t\t\t\t}\n\t\t\t},\n\t\t\t[editor]\n\t\t),\n\t\t() => editor?.getCrashingError() ?? null\n\t)\n\n\t// For our examples site, we want autoFocus to be true on the examples site, but not\n\t// when embedded in our docs site. If present, the `tldraw_preserve_focus` search param\n\t// overrides the `autoFocus` prop and prevents the editor from focusing immediately,\n\t// however here we also add some logic to focus the editor when the user clicks\n\t// on it and unfocus it when the user clicks away from it.\n\tuseEffect(\n\t\tfunction handleFocusOnPointerDownForPreserveFocusMode() {\n\t\t\tif (!editor) return\n\n\t\t\tfunction handleFocusOnPointerDown() {\n\t\t\t\tif (!editor) return\n\t\t\t\teditor.focus()\n\t\t\t}\n\n\t\t\tfunction handleBlurOnPointerDown() {\n\t\t\t\tif (!editor) return\n\t\t\t\teditor.blur()\n\t\t\t}\n\n\t\t\tif (autoFocus && noAutoFocus()) {\n\t\t\t\teditor.getContainer().addEventListener('pointerdown', handleFocusOnPointerDown)\n\t\t\t\tdocument.body.addEventListener('pointerdown', handleBlurOnPointerDown)\n\n\t\t\t\treturn () => {\n\t\t\t\t\teditor.getContainer()?.removeEventListener('pointerdown', handleFocusOnPointerDown)\n\t\t\t\t\tdocument.body.removeEventListener('pointerdown', handleBlurOnPointerDown)\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\t[editor, autoFocus]\n\t)\n\n\tconst [_fontLoadingState, setFontLoadingState] = useState<{\n\t\teditor: Editor\n\t\tisLoaded: boolean\n\t} | null>(null)\n\tlet fontLoadingState = _fontLoadingState\n\tif (editor !== fontLoadingState?.editor) {\n\t\tfontLoadingState = null\n\t}\n\tuseLayoutEffect(() => {\n\t\tif (!editor) return\n\t\tif (editor.options.maxFontsToLoadBeforeRender === 0) {\n\t\t\tsetFontLoadingState({ editor, isLoaded: true })\n\t\t\treturn\n\t\t}\n\n\t\tlet isCancelled = false\n\n\t\tsetFontLoadingState({ editor, isLoaded: false })\n\n\t\teditor.fonts\n\t\t\t.loadRequiredFontsForCurrentPage(editor.options.maxFontsToLoadBeforeRender)\n\t\t\t.finally(() => {\n\t\t\t\tif (isCancelled) return\n\t\t\t\tsetFontLoadingState({ editor, isLoaded: true })\n\t\t\t})\n\n\t\treturn () => {\n\t\t\tisCancelled = true\n\t\t}\n\t}, [editor])\n\n\tconst { Canvas, LoadingScreen } = useEditorComponents()\n\n\tif (!editor || !fontLoadingState?.isLoaded) {\n\t\treturn (\n\t\t\t<>\n\t\t\t\t{LoadingScreen && <LoadingScreen />}\n\t\t\t\t<div className=\"tl-canvas\" ref={canvasRef} />\n\t\t\t</>\n\t\t)\n\t}\n\n\treturn (\n\t\t// the top-level tldraw component also renders an error boundary almost\n\t\t// identical to this one. the reason we have two is because this one has\n\t\t// access to `App`, which means that here we can enrich errors with data\n\t\t// from app for reporting, and also still attempt to render the user's\n\t\t// document in the event of an error to reassure them that their work is\n\t\t// not lost.\n\t\t<OptionalErrorBoundary\n\t\t\tfallback={ErrorFallback as any}\n\t\t\tonError={(error) =>\n\t\t\t\teditor.annotateError(error, { origin: 'react.tldraw', willCrashApp: true })\n\t\t\t}\n\t\t>\n\t\t\t{crashingError ? (\n\t\t\t\t<Crash crashingError={crashingError} />\n\t\t\t) : (\n\t\t\t\t<EditorProvider editor={editor}>\n\t\t\t\t\t<Layout onMount={onMount}>\n\t\t\t\t\t\t{children ?? (Canvas ? <Canvas key={editor.contextId} /> : null)}\n\t\t\t\t\t\t<Watermark />\n\t\t\t\t\t</Layout>\n\t\t\t\t</EditorProvider>\n\t\t\t)}\n\t\t</OptionalErrorBoundary>\n\t)\n}\n\nfunction Layout({ children, onMount }: { children: ReactNode; onMount?: TLOnMountHandler }) {\n\tuseZoomCss()\n\tuseCursor()\n\tuseDarkMode()\n\tuseForceUpdate()\n\tuseStateAttribute()\n\tuseOnMount((editor) => {\n\t\tconst teardownStore = editor.store.props.onMount(editor)\n\t\tconst teardownCallback = onMount?.(editor)\n\n\t\treturn () => {\n\t\t\tteardownStore?.()\n\t\t\tteardownCallback?.()\n\t\t}\n\t})\n\n\treturn children\n}\n\nfunction Crash({ crashingError }: { crashingError: unknown }): null {\n\tthrow crashingError\n}\n\n/** @public */\nexport interface LoadingScreenProps {\n\tchildren: ReactNode\n}\n\n/** @public @react */\nexport function LoadingScreen({ children }: LoadingScreenProps) {\n\treturn (\n\t\t<div className=\"tl-loading\" aria-busy=\"true\" tabIndex={0}>\n\t\t\t{children}\n\t\t</div>\n\t)\n}\n\n/** @public @react */\nexport function ErrorScreen({ children }: LoadingScreenProps) {\n\treturn <div className=\"tl-loading\">{children}</div>\n}\n\n/** @internal */\nexport function useOnMount(onMount?: TLOnMountHandler) {\n\tconst editor = useEditor()\n\n\tconst onMountEvent = useEvent((editor: Editor) => {\n\t\tlet teardown: (() => void) | void = undefined\n\t\t// If the user wants to do something when the editor mounts, we make sure it doesn't effect the history.\n\t\t// todo: is this reeeeally what we want to do, or should we leave it up to the caller?\n\t\teditor.run(\n\t\t\t() => {\n\t\t\t\tteardown = onMount?.(editor)\n\t\t\t\teditor.emit('mount')\n\t\t\t},\n\t\t\t{ history: 'ignore' }\n\t\t)\n\t\twindow.tldrawReady = true\n\t\treturn teardown\n\t})\n\n\tReact.useLayoutEffect(() => {\n\t\tif (editor) return onMountEvent?.(editor)\n\t}, [editor, onMountEvent])\n}\n"],
5
+ "mappings": "AA6SU,SA0TP,UA1TO,KA0TP,YA1TO;AA7SV,SAA4B,aAAa;AAEzC,SAAS,qBAA+B;AACxC,OAAO;AAAA,EACN;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AAEP,OAAO,gBAAgB;AACvB,SAAS,eAAe;AACxB,SAAS,4BAA4B;AACrC,SAAS,6BAA6B;AAEtC,SAAS,oBAA4B;AAIrC,SAAS,cAAc;AAGvB,SA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S,UAAU;AAEzB,QAAM,eAAe,SAAS,CAACM,YAAmB;AACjD,QAAI,WAAgC;AAGpC,IAAAA,QAAO;AAAA,MACN,MAAM;AACL,mBAAW,UAAUA,OAAM;AAC3B,QAAAA,QAAO,KAAK,OAAO;AAAA,MACpB;AAAA,MACA,EAAE,SAAS,SAAS;AAAA,IACrB;AACA,WAAO,cAAc;AACrB,WAAO;AAAA,EACR,CAAC;AAED,QAAM,gBAAgB,MAAM;AAC3B,QAAI,OAAQ,QAAO,eAAe,MAAM;AAAA,EACzC,GAAG,CAAC,QAAQ,YAAY,CAAC;AAC1B;",
6
6
  "names": ["TldrawEditor", "LoadingScreen", "autoFocus", "inferDarkMode", "initialState", "cameraOptions", "deepLinks", "editor"]
7
7
  }
@@ -14,8 +14,7 @@ const Shape = memo(function Shape2({
14
14
  util,
15
15
  index,
16
16
  backgroundIndex,
17
- opacity,
18
- dprMultiple
17
+ opacity
19
18
  }) {
20
19
  const editor = useEditor();
21
20
  const { ShapeErrorFallback, ShapeWrapper } = useEditorComponents();
@@ -56,15 +55,13 @@ const Shape = memo(function Shape2({
56
55
  setStyleProperty(bgContainerRef.current, "transform", transform);
57
56
  prev.transform = transform;
58
57
  }
59
- const widthRemainder = bounds.w % dprMultiple;
60
- const heightRemainder = bounds.h % dprMultiple;
61
- const width = widthRemainder === 0 ? bounds.w : bounds.w + (dprMultiple - widthRemainder);
62
- const height = heightRemainder === 0 ? bounds.h : bounds.h + (dprMultiple - heightRemainder);
58
+ const width = Math.max(bounds.width, 1);
59
+ const height = Math.max(bounds.height, 1);
63
60
  if (width !== prev.width || height !== prev.height) {
64
- setStyleProperty(containerRef.current, "width", Math.max(width, dprMultiple) + "px");
65
- setStyleProperty(containerRef.current, "height", Math.max(height, dprMultiple) + "px");
66
- setStyleProperty(bgContainerRef.current, "width", Math.max(width, dprMultiple) + "px");
67
- setStyleProperty(bgContainerRef.current, "height", Math.max(height, dprMultiple) + "px");
61
+ setStyleProperty(containerRef.current, "width", width + "px");
62
+ setStyleProperty(containerRef.current, "height", height + "px");
63
+ setStyleProperty(bgContainerRef.current, "width", width + "px");
64
+ setStyleProperty(bgContainerRef.current, "height", height + "px");
68
65
  prev.width = width;
69
66
  prev.height = height;
70
67
  }
@@ -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, 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 { areShapesContentEqual } from '../utils/areShapesContentEqual'\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\tdprMultiple,\n}: {\n\tid: TLShapeId\n\tshape: TLShape\n\tutil: ShapeUtil\n\tindex: number\n\tbackgroundIndex: number\n\topacity: number\n\tdprMultiple: number\n}) {\n\tconst editor = useEditor()\n\n\tconst { ShapeErrorFallback, ShapeWrapper } = 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\t// We round the shape width and height up to the nearest multiple of dprMultiple\n\t\t\t// to avoid the browser making miscalculations when applying the transform.\n\t\t\tconst widthRemainder = bounds.w % dprMultiple\n\t\t\tconst heightRemainder = bounds.h % dprMultiple\n\t\t\tconst width = widthRemainder === 0 ? bounds.w : bounds.w + (dprMultiple - widthRemainder)\n\t\t\tconst height = heightRemainder === 0 ? bounds.h : bounds.h + (dprMultiple - heightRemainder)\n\n\t\t\tif (width !== prev.width || height !== prev.height) {\n\t\t\t\tsetStyleProperty(containerRef.current, 'width', Math.max(width, dprMultiple) + 'px')\n\t\t\t\tsetStyleProperty(containerRef.current, 'height', Math.max(height, dprMultiple) + 'px')\n\t\t\t\tsetStyleProperty(bgContainerRef.current, 'width', Math.max(width, dprMultiple) + 'px')\n\t\t\t\tsetStyleProperty(bgContainerRef.current, 'height', Math.max(height, dprMultiple) + '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 || !ShapeWrapper) return null\n\n\treturn (\n\t\t<>\n\t\t\t{util.backgroundComponent && (\n\t\t\t\t<ShapeWrapper ref={bgContainerRef} shape={shape} isBackground={true}>\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</ShapeWrapper>\n\t\t\t)}\n\t\t\t<ShapeWrapper ref={containerRef} shape={shape} isBackground={false}>\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</ShapeWrapper>\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) => areShapesContentEqual(prev.shape, next.shape) && prev.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": "AAsJE,mBAII,KAJJ;AAtJF,SAAS,aAAa;AACtB,SAAS,iBAAiB,wBAAwB;AAElD,SAAS,MAAM,aAAa,WA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AAE;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 { areShapesContentEqual } from '../utils/areShapesContentEqual'\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, ShapeWrapper } = 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 || !ShapeWrapper) return null\n\n\treturn (\n\t\t<>\n\t\t\t{util.backgroundComponent && (\n\t\t\t\t<ShapeWrapper ref={bgContainerRef} shape={shape} isBackground={true}>\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</ShapeWrapper>\n\t\t\t)}\n\t\t\t<ShapeWrapper ref={containerRef} shape={shape} isBackground={false}>\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</ShapeWrapper>\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) => areShapesContentEqual(prev.shape, next.shape) && prev.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": "AAgJE,mBAII,KAJJ;AAhJF,SAAS,aAAa;AACtB,SAAS,iBAAiB,wBAAwB;AAElD,SAAS,MAAM,aAAa,WAAW,iBAAiB,cAAc;AAEtE,SAAS,iBAAiB;AAC1B,SAAS,2BAA2B;AACpC,SAAS,WAAW;AACpB,SAAS,6BAA6B;AACtC,SAAS,wBAAwB;AACjC,SAAS,6BAA6B;AAa/B,MAAM,QAAQ,KAAK,SAASA,OAAM;AAAA,EACxC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD,GAOG;AACF,QAAM,SAAS,UAAU;AAEzB,QAAM,EAAE,oBAAoB,aAAa,IAAI,oBAAoB;AAEjE,QAAM,eAAe,OAAuB,IAAI;AAChD,Q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AAC,cAAW,OAAc,MAAY,GACvC,GACD;AAAA,KACD;AAEF,CAAC;AAEM,MAAM,aAAa;AAAA,EACzB,SAASC,YAA8B,EAAE,OAAO,KAAK,GAAqC;AACzF,WAAO;AAAA,MACN,gBAAgB,MAAM;AAAA,MACtB;AAAA;AAAA;AAAA,QAGC,KAAK,UAAU,KAAK,OAAO,MAAM,wBAAwB,MAAM,EAAE,CAAM;AAAA;AAAA,MACxE,CAAC,MAAM,MAAM,EAAE;AAAA,IAChB;AAAA,EACD;AAAA,EACA,CAAC,MAAM,SAAS,sBAAsB,KAAK,OAAO,KAAK,KAAK,KAAK,KAAK,SAAS,KAAK;AACrF;AAEO,MAAM,uBAAuB;AAAA,EACnC,SAASC,sBAAwC;AAAA,IAChD;AAAA,IACA;AAAA,EACD,GAGG;AACF,WAAO;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;",
6
6
  "names": ["Shape", "shape", "InnerShape", "InnerShapeBackground"]
7
7
  }
@@ -21,7 +21,6 @@ import { Vec } from "../../primitives/Vec.mjs";
21
21
  import { toDomPrecision } from "../../primitives/utils.mjs";
22
22
  import { debugFlags } from "../../utils/debug-flags.mjs";
23
23
  import { setStyleProperty } from "../../utils/dom.mjs";
24
- import { nearestMultiple } from "../../utils/nearestMultiple.mjs";
25
24
  import { GeometryDebuggingView } from "../GeometryDebuggingView.mjs";
26
25
  import { LiveCollaborators } from "../LiveCollaborators.mjs";
27
26
  import { MenuClickCapture } from "../MenuClickCapture.mjs";
@@ -134,12 +133,12 @@ function DefaultCanvas({ className }) {
134
133
  /* @__PURE__ */ jsx(OverlaysWrapper, {}),
135
134
  /* @__PURE__ */ jsx(LiveCollaborators, {})
136
135
  ] }) }),
136
+ /* @__PURE__ */ jsx("div", { className: "tl-canvas__in-front", children: /* @__PURE__ */ jsx(InFrontOfTheCanvasWrapper, {}) }),
137
137
  /* @__PURE__ */ jsx(MovingCameraHitTestBlocker, {})
138
138
  ]
139
139
  }
140
140
  ),
141
- /* @__PURE__ */ jsx(MenuClickCapture, {}),
142
- /* @__PURE__ */ jsx(InFrontOfTheCanvasWrapper, {})
141
+ /* @__PURE__ */ jsx(MenuClickCapture, {})
143
142
  ] });
144
143
  }
145
144
  function InFrontOfTheCanvasWrapper() {
@@ -283,17 +282,8 @@ function OverlaysWrapper() {
283
282
  function ShapesWithSVGs() {
284
283
  const editor = useEditor();
285
284
  const renderingShapes = useValue("rendering shapes", () => editor.getRenderingShapes(), [editor]);
286
- const dprMultiple = useValue(
287
- "dpr multiple",
288
- () => (
289
- // dprMultiple is the smallest number we can multiply dpr by to get an integer
290
- // it's usually 1, 2, or 4 (for e.g. dpr of 2, 2.5 and 2.25 respectively)
291
- (nearestMultiple(Math.floor(editor.getInstanceState().devicePixelRatio * 100) / 100))
292
- ),
293
- [editor]
294
- );
295
285
  return renderingShapes.map((result) => /* @__PURE__ */ jsxs(Fragment2, { children: [
296
- /* @__PURE__ */ jsx(Shape, { ...result, dprMultiple }),
286
+ /* @__PURE__ */ jsx(Shape, { ...result }),
297
287
  /* @__PURE__ */ jsx(DebugSvgCopy, { id: result.id, mode: "iframe" })
298
288
  ] }, result.id + "_fragment"));
299
289
  }
@@ -318,17 +308,8 @@ function ReflowIfNeeded() {
318
308
  function ShapesToDisplay() {
319
309
  const editor = useEditor();
320
310
  const renderingShapes = useValue("rendering shapes", () => editor.getRenderingShapes(), [editor]);
321
- const dprMultiple = useValue(
322
- "dpr multiple",
323
- () => (
324
- // dprMultiple is the smallest number we can multiply dpr by to get an integer
325
- // it's usually 1, 2, or 4 (for e.g. dpr of 2, 2.5 and 2.25 respectively)
326
- (nearestMultiple(Math.floor(editor.getInstanceState().devicePixelRatio * 100) / 100))
327
- ),
328
- [editor]
329
- );
330
311
  return /* @__PURE__ */ jsxs(Fragment, { children: [
331
- renderingShapes.map((result) => /* @__PURE__ */ jsx(Shape, { ...result, dprMultiple }, result.id + "_shape")),
312
+ renderingShapes.map((result) => /* @__PURE__ */ jsx(Shape, { ...result }, result.id + "_shape")),
332
313
  tlenv.isSafari && /* @__PURE__ */ jsx(ReflowIfNeeded, {})
333
314
  ] });
334
315
  }