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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/dist-cjs/index.d.ts +118 -15
  2. package/dist-cjs/index.js +3 -1
  3. package/dist-cjs/index.js.map +2 -2
  4. package/dist-cjs/lib/TldrawEditor.js +4 -0
  5. package/dist-cjs/lib/TldrawEditor.js.map +2 -2
  6. package/dist-cjs/lib/components/GeometryDebuggingView.js +2 -2
  7. package/dist-cjs/lib/components/GeometryDebuggingView.js.map +2 -2
  8. package/dist-cjs/lib/editor/Editor.js +63 -16
  9. package/dist-cjs/lib/editor/Editor.js.map +2 -2
  10. package/dist-cjs/lib/editor/shapes/group/GroupShapeUtil.js +1 -13
  11. package/dist-cjs/lib/editor/shapes/group/GroupShapeUtil.js.map +2 -2
  12. package/dist-cjs/lib/exports/StyleEmbedder.js +19 -5
  13. package/dist-cjs/lib/exports/StyleEmbedder.js.map +2 -2
  14. package/dist-cjs/lib/exports/cssRules.js +127 -0
  15. package/dist-cjs/lib/exports/cssRules.js.map +7 -0
  16. package/dist-cjs/lib/exports/parseCss.js +0 -69
  17. package/dist-cjs/lib/exports/parseCss.js.map +2 -2
  18. package/dist-cjs/lib/primitives/geometry/Geometry2d.js +133 -16
  19. package/dist-cjs/lib/primitives/geometry/Geometry2d.js.map +3 -3
  20. package/dist-cjs/lib/primitives/geometry/Group2d.js +54 -11
  21. package/dist-cjs/lib/primitives/geometry/Group2d.js.map +2 -2
  22. package/dist-cjs/lib/primitives/intersect.js +20 -0
  23. package/dist-cjs/lib/primitives/intersect.js.map +2 -2
  24. package/dist-cjs/lib/utils/reorderShapes.js +2 -8
  25. package/dist-cjs/lib/utils/reorderShapes.js.map +2 -2
  26. package/dist-cjs/version.js +3 -3
  27. package/dist-cjs/version.js.map +1 -1
  28. package/dist-esm/index.d.mts +118 -15
  29. package/dist-esm/index.mjs +8 -2
  30. package/dist-esm/index.mjs.map +2 -2
  31. package/dist-esm/lib/TldrawEditor.mjs +4 -0
  32. package/dist-esm/lib/TldrawEditor.mjs.map +2 -2
  33. package/dist-esm/lib/components/GeometryDebuggingView.mjs +3 -3
  34. package/dist-esm/lib/components/GeometryDebuggingView.mjs.map +2 -2
  35. package/dist-esm/lib/editor/Editor.mjs +63 -16
  36. package/dist-esm/lib/editor/Editor.mjs.map +2 -2
  37. package/dist-esm/lib/editor/shapes/group/GroupShapeUtil.mjs +1 -13
  38. package/dist-esm/lib/editor/shapes/group/GroupShapeUtil.mjs.map +2 -2
  39. package/dist-esm/lib/exports/StyleEmbedder.mjs +21 -12
  40. package/dist-esm/lib/exports/StyleEmbedder.mjs.map +2 -2
  41. package/dist-esm/lib/exports/cssRules.mjs +107 -0
  42. package/dist-esm/lib/exports/cssRules.mjs.map +7 -0
  43. package/dist-esm/lib/exports/parseCss.mjs +0 -69
  44. package/dist-esm/lib/exports/parseCss.mjs.map +2 -2
  45. package/dist-esm/lib/primitives/geometry/Geometry2d.mjs +137 -14
  46. package/dist-esm/lib/primitives/geometry/Geometry2d.mjs.map +2 -2
  47. package/dist-esm/lib/primitives/geometry/Group2d.mjs +55 -12
  48. package/dist-esm/lib/primitives/geometry/Group2d.mjs.map +2 -2
  49. package/dist-esm/lib/primitives/intersect.mjs +20 -0
  50. package/dist-esm/lib/primitives/intersect.mjs.map +2 -2
  51. package/dist-esm/lib/utils/reorderShapes.mjs +2 -8
  52. package/dist-esm/lib/utils/reorderShapes.mjs.map +2 -2
  53. package/dist-esm/version.mjs +3 -3
  54. package/dist-esm/version.mjs.map +1 -1
  55. package/package.json +7 -7
  56. package/src/index.ts +6 -1
  57. package/src/lib/TldrawEditor.tsx +27 -1
  58. package/src/lib/components/GeometryDebuggingView.tsx +3 -3
  59. package/src/lib/editor/Editor.ts +96 -23
  60. package/src/lib/editor/shapes/group/GroupShapeUtil.tsx +3 -15
  61. package/src/lib/exports/StyleEmbedder.ts +25 -15
  62. package/src/lib/exports/cssRules.ts +126 -0
  63. package/src/lib/exports/parseCss.ts +0 -79
  64. package/src/lib/primitives/geometry/Geometry2d.ts +196 -16
  65. package/src/lib/primitives/geometry/Group2d.ts +76 -13
  66. package/src/lib/primitives/intersect.ts +41 -0
  67. package/src/lib/utils/reorderShapes.ts +2 -9
  68. package/src/version.ts +3 -3
@@ -137,13 +137,15 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
137
137
  autoFocus,
138
138
  inferDarkMode,
139
139
  options,
140
+ // eslint-disable-next-line @typescript-eslint/no-deprecated
140
141
  isShapeHidden,
142
+ getShapeVisibility,
141
143
  fontAssetUrls
142
144
  }) {
143
145
  super();
144
146
  __runInitializers(_init, 5, this);
145
147
  __publicField(this, "id", (0, import_utils.uniqueId)());
146
- __publicField(this, "_isShapeHiddenPredicate");
148
+ __publicField(this, "_getShapeVisibility");
147
149
  __publicField(this, "options");
148
150
  __publicField(this, "contextId", (0, import_utils.uniqueId)());
149
151
  /**
@@ -299,6 +301,7 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
299
301
  __publicField(this, "_currentPageShapeIds");
300
302
  /* --------------------- Shapes --------------------- */
301
303
  __publicField(this, "_shapeGeometryCaches", {});
304
+ __publicField(this, "_shapePageGeometryCaches", {});
302
305
  // Parents and children
303
306
  /**
304
307
  * A cache of parents to children.
@@ -410,7 +413,14 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
410
413
  /** @internal */
411
414
  __publicField(this, "performanceTrackerTimeout", -1);
412
415
  __publicField(this, "_pendingEventsForNextTick", []);
413
- this._isShapeHiddenPredicate = isShapeHidden;
416
+ (0, import_utils.assert)(
417
+ !(isShapeHidden && getShapeVisibility),
418
+ "Cannot use both isShapeHidden and getShapeVisibility"
419
+ );
420
+ this._getShapeVisibility = isShapeHidden ? (
421
+ // eslint-disable-next-line @typescript-eslint/no-deprecated
422
+ (shape, editor) => isShapeHidden(shape, editor) ? "hidden" : "inherit"
423
+ ) : getShapeVisibility;
414
424
  this.options = { ...import_options.defaultTldrawOptions, ...options };
415
425
  this.store = store;
416
426
  this.disposables.add(this.store.dispose.bind(this.store));
@@ -803,15 +813,16 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
803
813
  }
804
814
  }
805
815
  getIsShapeHiddenCache() {
806
- if (!this._isShapeHiddenPredicate) return null;
816
+ if (!this._getShapeVisibility) return null;
807
817
  return this.store.createComputedCache("isShapeHidden", (shape) => {
808
- const hiddenParent = this.findShapeAncestor(shape, (p) => this.isShapeHidden(p));
809
- if (hiddenParent) return true;
810
- return this._isShapeHiddenPredicate(shape, this) ?? false;
818
+ const visibility = this._getShapeVisibility(shape, this);
819
+ const isParentHidden = import_tlschema.PageRecordType.isId(shape.parentId) ? false : this.isShapeHidden(shape.parentId);
820
+ if (isParentHidden) return visibility !== "visible";
821
+ return visibility === "hidden";
811
822
  });
812
823
  }
813
824
  isShapeHidden(shapeOrId) {
814
- if (!this._isShapeHiddenPredicate) return false;
825
+ if (!this._getShapeVisibility) return false;
815
826
  return !!this.getIsShapeHiddenCache().get(
816
827
  typeof shapeOrId === "string" ? shapeOrId : shapeOrId.id
817
828
  );
@@ -2825,7 +2836,13 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
2825
2836
  const addShapeById = (id, opacity, isAncestorErasing) => {
2826
2837
  const shape = this.getShape(id);
2827
2838
  if (!shape) return;
2828
- if (this.isShapeHidden(shape)) return;
2839
+ if (this.isShapeHidden(shape)) {
2840
+ const isErasing = isAncestorErasing || erasingShapeIds.includes(id);
2841
+ for (const childId of this.getSortedChildIdsForParent(id)) {
2842
+ addShapeById(childId, opacity, isErasing);
2843
+ }
2844
+ return;
2845
+ }
2829
2846
  opacity *= shape.opacity;
2830
2847
  let isShapeErasing = false;
2831
2848
  const util = this.getShapeUtil(shape);
@@ -3252,7 +3269,7 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
3252
3269
  return await this.store.props.assets.upload(asset, file, abortSignal);
3253
3270
  }
3254
3271
  /**
3255
- * Get the geometry of a shape.
3272
+ * Get the geometry of a shape in shape-space.
3256
3273
  *
3257
3274
  * @example
3258
3275
  * ```ts
@@ -3282,6 +3299,41 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
3282
3299
  typeof shape === "string" ? shape : shape.id
3283
3300
  );
3284
3301
  }
3302
+ /**
3303
+ * Get the geometry of a shape in page-space.
3304
+ *
3305
+ * @example
3306
+ * ```ts
3307
+ * editor.getShapePageGeometry(myShape)
3308
+ * editor.getShapePageGeometry(myShapeId)
3309
+ * editor.getShapePageGeometry(myShapeId, { context: "arrow" })
3310
+ * ```
3311
+ *
3312
+ * @param shape - The shape (or shape id) to get the geometry for.
3313
+ * @param opts - Additional options about the request for geometry. Passed to {@link ShapeUtil.getGeometry}.
3314
+ *
3315
+ * @public
3316
+ */
3317
+ getShapePageGeometry(shape, opts) {
3318
+ const context = opts?.context ?? "none";
3319
+ if (!this._shapePageGeometryCaches[context]) {
3320
+ this._shapePageGeometryCaches[context] = this.store.createComputedCache(
3321
+ "bounds",
3322
+ (shape2) => {
3323
+ const geometry = this.getShapeGeometry(shape2.id, opts);
3324
+ const pageTransform = this.getShapePageTransform(shape2.id);
3325
+ return geometry.transform(pageTransform);
3326
+ },
3327
+ {
3328
+ // we only depend directly on the shape id, and changing geometry/transform will update us anyway
3329
+ areRecordsEqual: () => true
3330
+ }
3331
+ );
3332
+ }
3333
+ return this._shapePageGeometryCaches[context].get(
3334
+ typeof shape === "string" ? shape : shape.id
3335
+ );
3336
+ }
3285
3337
  _getShapeHandlesCache() {
3286
3338
  return this.store.createComputedCache("handles", (shape) => {
3287
3339
  return this.getShapeUtil(shape).getHandles?.(shape);
@@ -3369,12 +3421,7 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
3369
3421
  }
3370
3422
  _getShapePageBoundsCache() {
3371
3423
  return this.store.createComputedCache("pageBoundsCache", (shape) => {
3372
- const pageTransform = this._getShapePageTransformCache().get(shape.id);
3373
- if (!pageTransform) return new import_Box.Box();
3374
- const result = import_Box.Box.FromPoints(
3375
- import_Mat.Mat.applyToPoints(pageTransform, this.getShapeGeometry(shape).vertices)
3376
- );
3377
- return result;
3424
+ return this.getShapePageGeometry(shape).bounds;
3378
3425
  });
3379
3426
  }
3380
3427
  /**
@@ -3434,7 +3481,7 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
3434
3481
  const pageMask = frameAncestors.map(
3435
3482
  (s) => (
3436
3483
  // Apply the frame transform to the frame outline to get the frame outline in the current page space
3437
- this._getShapePageTransformCache().get(s.id).applyToPoints(this.getShapeGeometry(s).vertices)
3484
+ this.getShapePageGeometry(s.id).vertices
3438
3485
  )
3439
3486
  ).reduce((acc, b) => {
3440
3487
  if (!(b && acc)) return void 0;