@tldraw/editor 3.16.0-canary.cb97f41de62b → 3.16.0-canary.cc5427cdff41

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 (112) hide show
  1. package/dist-cjs/index.d.ts +52 -101
  2. package/dist-cjs/index.js +3 -5
  3. package/dist-cjs/index.js.map +2 -2
  4. package/dist-cjs/lib/TldrawEditor.js +5 -5
  5. package/dist-cjs/lib/TldrawEditor.js.map +2 -2
  6. package/dist-cjs/lib/components/Shape.js +7 -10
  7. package/dist-cjs/lib/components/Shape.js.map +2 -2
  8. package/dist-cjs/lib/components/default-components/DefaultCanvas.js +4 -23
  9. package/dist-cjs/lib/components/default-components/DefaultCanvas.js.map +2 -2
  10. package/dist-cjs/lib/editor/Editor.js +31 -109
  11. package/dist-cjs/lib/editor/Editor.js.map +2 -2
  12. package/dist-cjs/lib/editor/shapes/ShapeUtil.js +13 -0
  13. package/dist-cjs/lib/editor/shapes/ShapeUtil.js.map +2 -2
  14. package/dist-cjs/lib/editor/types/misc-types.js.map +1 -1
  15. package/dist-cjs/lib/exports/getSvgJsx.js +34 -14
  16. package/dist-cjs/lib/exports/getSvgJsx.js.map +2 -2
  17. package/dist-cjs/lib/hooks/useCanvasEvents.js +7 -5
  18. package/dist-cjs/lib/hooks/useCanvasEvents.js.map +2 -2
  19. package/dist-cjs/lib/hooks/usePassThroughMouseOverEvents.js +4 -1
  20. package/dist-cjs/lib/hooks/usePassThroughMouseOverEvents.js.map +2 -2
  21. package/dist-cjs/lib/hooks/usePassThroughWheelEvents.js +4 -1
  22. package/dist-cjs/lib/hooks/usePassThroughWheelEvents.js.map +2 -2
  23. package/dist-cjs/lib/license/LicenseManager.js +120 -50
  24. package/dist-cjs/lib/license/LicenseManager.js.map +2 -2
  25. package/dist-cjs/lib/license/LicenseProvider.js +22 -0
  26. package/dist-cjs/lib/license/LicenseProvider.js.map +2 -2
  27. package/dist-cjs/lib/license/Watermark.js +68 -6
  28. package/dist-cjs/lib/license/Watermark.js.map +3 -3
  29. package/dist-cjs/lib/license/useLicenseManagerState.js.map +2 -2
  30. package/dist-cjs/lib/primitives/Box.js +3 -0
  31. package/dist-cjs/lib/primitives/Box.js.map +2 -2
  32. package/dist-cjs/lib/primitives/Vec.js +0 -4
  33. package/dist-cjs/lib/primitives/Vec.js.map +2 -2
  34. package/dist-cjs/lib/primitives/geometry/Geometry2d.js +26 -18
  35. package/dist-cjs/lib/primitives/geometry/Geometry2d.js.map +2 -2
  36. package/dist-cjs/lib/primitives/geometry/Group2d.js +3 -0
  37. package/dist-cjs/lib/primitives/geometry/Group2d.js.map +2 -2
  38. package/dist-cjs/lib/utils/reparenting.js +2 -35
  39. package/dist-cjs/lib/utils/reparenting.js.map +3 -3
  40. package/dist-cjs/version.js +3 -3
  41. package/dist-cjs/version.js.map +1 -1
  42. package/dist-esm/index.d.mts +52 -101
  43. package/dist-esm/index.mjs +3 -5
  44. package/dist-esm/index.mjs.map +2 -2
  45. package/dist-esm/lib/TldrawEditor.mjs +5 -5
  46. package/dist-esm/lib/TldrawEditor.mjs.map +2 -2
  47. package/dist-esm/lib/components/Shape.mjs +7 -10
  48. package/dist-esm/lib/components/Shape.mjs.map +2 -2
  49. package/dist-esm/lib/components/default-components/DefaultCanvas.mjs +4 -23
  50. package/dist-esm/lib/components/default-components/DefaultCanvas.mjs.map +2 -2
  51. package/dist-esm/lib/editor/Editor.mjs +31 -109
  52. package/dist-esm/lib/editor/Editor.mjs.map +2 -2
  53. package/dist-esm/lib/editor/shapes/ShapeUtil.mjs +13 -0
  54. package/dist-esm/lib/editor/shapes/ShapeUtil.mjs.map +2 -2
  55. package/dist-esm/lib/exports/getSvgJsx.mjs +34 -14
  56. package/dist-esm/lib/exports/getSvgJsx.mjs.map +2 -2
  57. package/dist-esm/lib/hooks/useCanvasEvents.mjs +7 -5
  58. package/dist-esm/lib/hooks/useCanvasEvents.mjs.map +2 -2
  59. package/dist-esm/lib/hooks/usePassThroughMouseOverEvents.mjs +4 -1
  60. package/dist-esm/lib/hooks/usePassThroughMouseOverEvents.mjs.map +2 -2
  61. package/dist-esm/lib/hooks/usePassThroughWheelEvents.mjs +4 -1
  62. package/dist-esm/lib/hooks/usePassThroughWheelEvents.mjs.map +2 -2
  63. package/dist-esm/lib/license/LicenseManager.mjs +121 -51
  64. package/dist-esm/lib/license/LicenseManager.mjs.map +2 -2
  65. package/dist-esm/lib/license/LicenseProvider.mjs +23 -1
  66. package/dist-esm/lib/license/LicenseProvider.mjs.map +2 -2
  67. package/dist-esm/lib/license/Watermark.mjs +68 -6
  68. package/dist-esm/lib/license/Watermark.mjs.map +3 -3
  69. package/dist-esm/lib/license/useLicenseManagerState.mjs.map +2 -2
  70. package/dist-esm/lib/primitives/Box.mjs +4 -1
  71. package/dist-esm/lib/primitives/Box.mjs.map +2 -2
  72. package/dist-esm/lib/primitives/Vec.mjs +0 -4
  73. package/dist-esm/lib/primitives/Vec.mjs.map +2 -2
  74. package/dist-esm/lib/primitives/geometry/Geometry2d.mjs +29 -19
  75. package/dist-esm/lib/primitives/geometry/Geometry2d.mjs.map +2 -2
  76. package/dist-esm/lib/primitives/geometry/Group2d.mjs +3 -0
  77. package/dist-esm/lib/primitives/geometry/Group2d.mjs.map +2 -2
  78. package/dist-esm/lib/utils/reparenting.mjs +3 -40
  79. package/dist-esm/lib/utils/reparenting.mjs.map +2 -2
  80. package/dist-esm/version.mjs +3 -3
  81. package/dist-esm/version.mjs.map +1 -1
  82. package/editor.css +16 -3
  83. package/package.json +7 -7
  84. package/src/index.ts +2 -9
  85. package/src/lib/TldrawEditor.tsx +6 -12
  86. package/src/lib/components/Shape.tsx +6 -12
  87. package/src/lib/components/default-components/DefaultCanvas.tsx +5 -22
  88. package/src/lib/editor/Editor.ts +38 -146
  89. package/src/lib/editor/shapes/ShapeUtil.ts +35 -0
  90. package/src/lib/editor/types/misc-types.ts +0 -6
  91. package/src/lib/exports/getSvgJsx.test.ts +868 -0
  92. package/src/lib/exports/getSvgJsx.tsx +76 -19
  93. package/src/lib/hooks/useCanvasEvents.ts +6 -6
  94. package/src/lib/hooks/usePassThroughMouseOverEvents.ts +4 -1
  95. package/src/lib/hooks/usePassThroughWheelEvents.ts +6 -1
  96. package/src/lib/license/LicenseManager.test.ts +645 -382
  97. package/src/lib/license/LicenseManager.ts +173 -53
  98. package/src/lib/license/LicenseProvider.tsx +34 -1
  99. package/src/lib/license/Watermark.tsx +73 -6
  100. package/src/lib/license/useLicenseManagerState.ts +2 -2
  101. package/src/lib/primitives/Box.test.ts +126 -0
  102. package/src/lib/primitives/Box.ts +10 -1
  103. package/src/lib/primitives/Vec.ts +0 -5
  104. package/src/lib/primitives/geometry/Geometry2d.ts +49 -19
  105. package/src/lib/primitives/geometry/Group2d.ts +4 -0
  106. package/src/lib/utils/reparenting.ts +3 -69
  107. package/src/version.ts +3 -3
  108. package/dist-cjs/lib/utils/nearestMultiple.js +0 -34
  109. package/dist-cjs/lib/utils/nearestMultiple.js.map +0 -7
  110. package/dist-esm/lib/utils/nearestMultiple.mjs +0 -14
  111. package/dist-esm/lib/utils/nearestMultiple.mjs.map +0 -7
  112. package/src/lib/utils/nearestMultiple.ts +0 -13
@@ -116,7 +116,6 @@ import {
116
116
  } from '../constants'
117
117
  import { exportToSvg } from '../exports/exportToSvg'
118
118
  import { getSvgAsImage } from '../exports/getSvgAsImage'
119
- import { tlenv } from '../globals/environment'
120
119
  import { tlmenus } from '../globals/menus'
121
120
  import { tltime } from '../globals/time'
122
121
  import { TldrawOptions, defaultTldrawOptions } from '../options'
@@ -244,16 +243,6 @@ export interface TLEditorOptions {
244
243
  options?: Partial<TldrawOptions>
245
244
  licenseKey?: string
246
245
  fontAssetUrls?: { [key: string]: string | undefined }
247
- /**
248
- * A predicate that should return true if the given shape should be hidden.
249
- *
250
- * @deprecated Use {@link Editor#getShapeVisibility} instead.
251
- *
252
- * @param shape - The shape to check.
253
- * @param editor - The editor instance.
254
- */
255
- isShapeHidden?(shape: TLShape, editor: Editor): boolean
256
-
257
246
  /**
258
247
  * Provides a way to hide shapes.
259
248
  *
@@ -309,21 +298,12 @@ export class Editor extends EventEmitter<TLEventMap> {
309
298
  autoFocus,
310
299
  inferDarkMode,
311
300
  options,
312
- // eslint-disable-next-line @typescript-eslint/no-deprecated
313
- isShapeHidden,
314
301
  getShapeVisibility,
315
302
  fontAssetUrls,
316
303
  }: TLEditorOptions) {
317
304
  super()
318
- assert(
319
- !(isShapeHidden && getShapeVisibility),
320
- 'Cannot use both isShapeHidden and getShapeVisibility'
321
- )
322
305
 
323
- this._getShapeVisibility = isShapeHidden
324
- ? // eslint-disable-next-line @typescript-eslint/no-deprecated
325
- (shape: TLShape, editor: Editor) => (isShapeHidden(shape, editor) ? 'hidden' : 'inherit')
326
- : getShapeVisibility
306
+ this._getShapeVisibility = getShapeVisibility
327
307
 
328
308
  this.options = { ...defaultTldrawOptions, ...options }
329
309
 
@@ -907,14 +887,6 @@ export class Editor extends EventEmitter<TLEventMap> {
907
887
  */
908
888
  readonly fonts: FontManager
909
889
 
910
- /**
911
- * A manager for the editor's environment.
912
- *
913
- * @deprecated This is deprecated and will be removed in a future version. Use the `tlenv` global export instead.
914
- * @public
915
- */
916
- readonly environment = tlenv
917
-
918
890
  /**
919
891
  * A manager for the editor's scribbles.
920
892
  *
@@ -1119,35 +1091,6 @@ export class Editor extends EventEmitter<TLEventMap> {
1119
1091
  return this.history.getNumRedos() > 0
1120
1092
  }
1121
1093
 
1122
- /**
1123
- * Create a new "mark", or stopping point, in the undo redo history. Creating a mark will clear
1124
- * any redos.
1125
- *
1126
- * @example
1127
- * ```ts
1128
- * editor.mark()
1129
- * editor.mark('flip shapes')
1130
- * ```
1131
- *
1132
- * @param markId - The mark's id, usually the reason for adding the mark.
1133
- *
1134
- * @public
1135
- * @deprecated use {@link Editor.markHistoryStoppingPoint} instead
1136
- */
1137
- mark(markId?: string): this {
1138
- if (typeof markId === 'string') {
1139
- console.warn(
1140
- `[tldraw] \`editor.history.mark("${markId}")\` is deprecated. Please use \`const myMarkId = editor.markHistoryStoppingPoint()\` instead.`
1141
- )
1142
- } else {
1143
- console.warn(
1144
- '[tldraw] `editor.mark()` is deprecated. Use `editor.markHistoryStoppingPoint()` instead.'
1145
- )
1146
- }
1147
- this.history._mark(markId ?? uniqueId())
1148
- return this
1149
- }
1150
-
1151
1094
  /**
1152
1095
  * Create a new "mark", or stopping point, in the undo redo history. Creating a mark will clear
1153
1096
  * any redos. You typically want to do this just before a user interaction begins or is handled.
@@ -1272,13 +1215,6 @@ export class Editor extends EventEmitter<TLEventMap> {
1272
1215
  return this
1273
1216
  }
1274
1217
 
1275
- /**
1276
- * @deprecated Use `Editor.run` instead.
1277
- */
1278
- batch(fn: () => void, opts?: TLEditorRunOptions): this {
1279
- return this.run(fn, opts)
1280
- }
1281
-
1282
1218
  /* --------------------- Errors --------------------- */
1283
1219
 
1284
1220
  /** @internal */
@@ -1580,54 +1516,6 @@ export class Editor extends EventEmitter<TLEventMap> {
1580
1516
 
1581
1517
  menus = tlmenus.forContext(this.contextId)
1582
1518
 
1583
- /**
1584
- * @deprecated Use `editor.menus.getOpenMenus` instead.
1585
- *
1586
- * @public
1587
- */
1588
- @computed getOpenMenus(): string[] {
1589
- return this.menus.getOpenMenus()
1590
- }
1591
-
1592
- /**
1593
- * @deprecated Use `editor.menus.addOpenMenu` instead.
1594
- *
1595
- * @public
1596
- */
1597
- addOpenMenu(id: string): this {
1598
- this.menus.addOpenMenu(id)
1599
- return this
1600
- }
1601
-
1602
- /**
1603
- * @deprecated Use `editor.menus.deleteOpenMenu` instead.
1604
- *
1605
- * @public
1606
- */
1607
- deleteOpenMenu(id: string): this {
1608
- this.menus.deleteOpenMenu(id)
1609
- return this
1610
- }
1611
-
1612
- /**
1613
- * @deprecated Use `editor.menus.clearOpenMenus` instead.
1614
- *
1615
- * @public
1616
- */
1617
- clearOpenMenus(): this {
1618
- this.menus.clearOpenMenus()
1619
- return this
1620
- }
1621
-
1622
- /**
1623
- * @deprecated Use `editor.menus.hasAnyOpenMenus` instead.
1624
- *
1625
- * @public
1626
- */
1627
- @computed getIsMenuOpen(): boolean {
1628
- return this.menus.hasAnyOpenMenus()
1629
- }
1630
-
1631
1519
  /* --------------------- Cursor --------------------- */
1632
1520
 
1633
1521
  /**
@@ -4860,27 +4748,25 @@ export class Editor extends EventEmitter<TLEventMap> {
4860
4748
  return this.store.createComputedCache('pageMaskCache', (shape) => {
4861
4749
  if (isPageId(shape.parentId)) return undefined
4862
4750
 
4863
- const frameAncestors = this.getShapeAncestors(shape.id).filter((shape) =>
4864
- this.isShapeOfType<TLFrameShape>(shape, 'frame')
4865
- )
4866
-
4867
- if (frameAncestors.length === 0) return undefined
4868
-
4869
- const pageMask = frameAncestors
4870
- .map<Vec[] | undefined>((s) => {
4871
- // Apply the frame transform to the frame outline to get the frame outline in the current page space
4872
- const geometry = this.getShapeGeometry(s.id)
4873
- const pageTransform = this.getShapePageTransform(s.id)
4874
- return pageTransform.applyToPoints(geometry.vertices)
4875
- })
4876
- .reduce((acc, b) => {
4877
- if (!(b && acc)) return undefined
4878
- const intersection = intersectPolygonPolygon(acc, b)
4879
- if (intersection) {
4880
- return intersection.map(Vec.Cast)
4881
- }
4882
- return []
4883
- })
4751
+ const clipPaths: Vec[][] = []
4752
+ // Get all ancestors that can potentially clip this shape
4753
+ for (const ancestor of this.getShapeAncestors(shape.id)) {
4754
+ const util = this.getShapeUtil(ancestor)
4755
+ const clipPath = util.getClipPath?.(ancestor)
4756
+ if (!clipPath) continue
4757
+ if (util.shouldClipChild?.(shape) === false) continue
4758
+ const pageTransform = this.getShapePageTransform(ancestor.id)
4759
+ clipPaths.push(pageTransform.applyToPoints(clipPath))
4760
+ }
4761
+ if (clipPaths.length === 0) return undefined
4762
+
4763
+ const pageMask = clipPaths.reduce((acc, b) => {
4764
+ const intersection = intersectPolygonPolygon(acc, b)
4765
+ if (intersection) {
4766
+ return intersection.map(Vec.Cast)
4767
+ }
4768
+ return []
4769
+ })
4884
4770
 
4885
4771
  return pageMask
4886
4772
  })
@@ -5841,11 +5727,6 @@ export class Editor extends EventEmitter<TLEventMap> {
5841
5727
  return shapeIds
5842
5728
  }
5843
5729
 
5844
- /** @deprecated Use {@link Editor.getDraggingOverShape} instead */
5845
- getDroppingOverShape(point: Vec, droppingShapes: TLShape[]): TLShape | undefined {
5846
- return this.getDraggingOverShape(point, droppingShapes)
5847
- }
5848
-
5849
5730
  /**
5850
5731
  * Get the shape that some shapes should be dropped on at a given point.
5851
5732
  *
@@ -9461,13 +9342,6 @@ export class Editor extends EventEmitter<TLEventMap> {
9461
9342
  }
9462
9343
  }
9463
9344
 
9464
- /** @deprecated Use {@link Editor.getSvgString} or {@link Editor.getSvgElement} instead. */
9465
- async getSvg(shapes: TLShapeId[] | TLShape[], opts: TLSvgExportOptions = {}) {
9466
- const result = await this.getSvgElement(shapes, opts)
9467
- if (!result) return undefined
9468
- return result.svg
9469
- }
9470
-
9471
9345
  /**
9472
9346
  * Get an exported image of the given shapes.
9473
9347
  *
@@ -9519,6 +9393,24 @@ export class Editor extends EventEmitter<TLEventMap> {
9519
9393
  }
9520
9394
  }
9521
9395
 
9396
+ /**
9397
+ * Get an exported image of the given shapes as a data URL.
9398
+ *
9399
+ * @param shapes - The shapes (or shape ids) to export.
9400
+ * @param opts - Options for the export.
9401
+ *
9402
+ * @returns A data URL of the image.
9403
+ * @public
9404
+ */
9405
+ async toImageDataUrl(shapes: TLShapeId[] | TLShape[], opts: TLImageExportOptions = {}) {
9406
+ const { blob, width, height } = await this.toImage(shapes, opts)
9407
+ return {
9408
+ url: await FileHelpers.blobToDataUrl(blob),
9409
+ width,
9410
+ height,
9411
+ }
9412
+ }
9413
+
9522
9414
  /* --------------------- Events --------------------- */
9523
9415
 
9524
9416
  /**
@@ -296,6 +296,27 @@ export abstract class ShapeUtil<Shape extends TLUnknownShape = TLUnknownShape> {
296
296
  return false
297
297
  }
298
298
 
299
+ /**
300
+ * Get the clip path to apply to this shape's children.
301
+ *
302
+ * @param shape - The shape to get the clip path for
303
+ * @returns Array of points defining the clipping polygon in local coordinates, or undefined if no clipping
304
+ * @public
305
+ */
306
+ getClipPath?(shape: Shape): Vec[] | undefined
307
+
308
+ /**
309
+ * Whether a specific child shape should be clipped by this shape.
310
+ * Only called if getClipPath returns a valid polygon.
311
+ *
312
+ * If not defined, the default behavior is to clip all children.
313
+ *
314
+ * @param child - The child shape to check
315
+ * @returns boolean indicating if this child should be clipped
316
+ * @public
317
+ */
318
+ shouldClipChild?(child: TLShape): boolean
319
+
299
320
  /**
300
321
  * Whether the shape should hide its resize handles when selected.
301
322
  *
@@ -341,6 +362,20 @@ export abstract class ShapeUtil<Shape extends TLUnknownShape = TLUnknownShape> {
341
362
  return false
342
363
  }
343
364
 
365
+ /**
366
+ * By default, the bounds of an image export are the bounds of all the shapes it contains, plus
367
+ * some padding. If an export includes a shape where `isExportBoundsContainer` is true, then the
368
+ * padding is skipped _if the bounds of that shape contains all the other shapes_. This is
369
+ * useful in cases like annotating on top of an image, where you usually want to avoid extra
370
+ * padding around the image if you don't need it.
371
+ *
372
+ * @param _shape - The shape to check
373
+ * @returns True if this shape should be treated as an export bounds container
374
+ */
375
+ isExportBoundsContainer(_shape: Shape): boolean {
376
+ return false
377
+ }
378
+
344
379
  /**
345
380
  * Get a JSX element for the shape (as an HTML element) to be rendered as part of the canvas background - behind any other shape content.
346
381
  *
@@ -72,12 +72,6 @@ export interface TLImageExportOptions extends TLSvgExportOptions {
72
72
  format?: TLExportType
73
73
  }
74
74
 
75
- /**
76
- * @public
77
- * @deprecated use {@link TLImageExportOptions} instead
78
- */
79
- export type TLSvgOptions = TLImageExportOptions
80
-
81
75
  /** @public */
82
76
  export interface TLCameraMoveOptions {
83
77
  /** Whether to move the camera immediately, rather than on the next tick. */