@tldraw/editor 3.8.0-canary.d9f1dbe89786 → 3.8.0-canary.da7502dc0e6b

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 (61) hide show
  1. package/dist-cjs/index.d.ts +109 -13
  2. package/dist-cjs/index.js +5 -1
  3. package/dist-cjs/index.js.map +2 -2
  4. package/dist-cjs/lib/components/default-components/DefaultCanvas.js +1 -4
  5. package/dist-cjs/lib/components/default-components/DefaultCanvas.js.map +2 -2
  6. package/dist-cjs/lib/config/createTLStore.js +4 -2
  7. package/dist-cjs/lib/config/createTLStore.js.map +2 -2
  8. package/dist-cjs/lib/editor/Editor.js +71 -7
  9. package/dist-cjs/lib/editor/Editor.js.map +2 -2
  10. package/dist-cjs/lib/editor/types/SvgExportContext.js.map +2 -2
  11. package/dist-cjs/lib/editor/types/misc-types.js.map +1 -1
  12. package/dist-cjs/lib/exports/exportToSvg.js.map +2 -2
  13. package/dist-cjs/lib/exports/getSvgAsImage.js +83 -0
  14. package/dist-cjs/lib/exports/getSvgAsImage.js.map +7 -0
  15. package/dist-cjs/lib/exports/getSvgJsx.js +16 -3
  16. package/dist-cjs/lib/exports/getSvgJsx.js.map +2 -2
  17. package/dist-cjs/lib/hooks/useLocalStore.js +1 -1
  18. package/dist-cjs/lib/hooks/useLocalStore.js.map +2 -2
  19. package/dist-cjs/lib/utils/browserCanvasMaxSize.js +75 -0
  20. package/dist-cjs/lib/utils/browserCanvasMaxSize.js.map +7 -0
  21. package/dist-cjs/lib/utils/sync/TLLocalSyncClient.js +3 -1
  22. package/dist-cjs/lib/utils/sync/TLLocalSyncClient.js.map +2 -2
  23. package/dist-cjs/version.js +3 -3
  24. package/dist-cjs/version.js.map +1 -1
  25. package/dist-esm/index.d.mts +109 -13
  26. package/dist-esm/index.mjs +5 -1
  27. package/dist-esm/index.mjs.map +2 -2
  28. package/dist-esm/lib/components/default-components/DefaultCanvas.mjs +1 -4
  29. package/dist-esm/lib/components/default-components/DefaultCanvas.mjs.map +2 -2
  30. package/dist-esm/lib/config/createTLStore.mjs +4 -2
  31. package/dist-esm/lib/config/createTLStore.mjs.map +2 -2
  32. package/dist-esm/lib/editor/Editor.mjs +71 -7
  33. package/dist-esm/lib/editor/Editor.mjs.map +2 -2
  34. package/dist-esm/lib/editor/types/SvgExportContext.mjs.map +2 -2
  35. package/dist-esm/lib/exports/exportToSvg.mjs.map +2 -2
  36. package/dist-esm/lib/exports/getSvgAsImage.mjs +63 -0
  37. package/dist-esm/lib/exports/getSvgAsImage.mjs.map +7 -0
  38. package/dist-esm/lib/exports/getSvgJsx.mjs +16 -3
  39. package/dist-esm/lib/exports/getSvgJsx.mjs.map +2 -2
  40. package/dist-esm/lib/hooks/useLocalStore.mjs +1 -1
  41. package/dist-esm/lib/hooks/useLocalStore.mjs.map +2 -2
  42. package/dist-esm/lib/utils/browserCanvasMaxSize.mjs +45 -0
  43. package/dist-esm/lib/utils/browserCanvasMaxSize.mjs.map +7 -0
  44. package/dist-esm/lib/utils/sync/TLLocalSyncClient.mjs +3 -1
  45. package/dist-esm/lib/utils/sync/TLLocalSyncClient.mjs.map +2 -2
  46. package/dist-esm/version.mjs +3 -3
  47. package/dist-esm/version.mjs.map +1 -1
  48. package/package.json +9 -7
  49. package/src/index.ts +4 -0
  50. package/src/lib/components/default-components/DefaultCanvas.tsx +1 -4
  51. package/src/lib/config/createTLStore.ts +4 -2
  52. package/src/lib/editor/Editor.ts +88 -25
  53. package/src/lib/editor/types/SvgExportContext.tsx +21 -0
  54. package/src/lib/editor/types/misc-types.ts +55 -2
  55. package/src/lib/exports/exportToSvg.tsx +2 -2
  56. package/src/lib/exports/getSvgAsImage.ts +92 -0
  57. package/src/lib/exports/getSvgJsx.tsx +17 -2
  58. package/src/lib/hooks/useLocalStore.ts +1 -1
  59. package/src/lib/utils/browserCanvasMaxSize.ts +65 -0
  60. package/src/lib/utils/sync/TLLocalSyncClient.ts +3 -1
  61. package/src/version.ts +3 -3
@@ -87,6 +87,7 @@ var import_defaultBindings = require("../config/defaultBindings");
87
87
  var import_defaultShapes = require("../config/defaultShapes");
88
88
  var import_constants = require("../constants");
89
89
  var import_exportToSvg = require("../exports/exportToSvg");
90
+ var import_getSvgAsImage = require("../exports/getSvgAsImage");
90
91
  var import_environment = require("../globals/environment");
91
92
  var import_menus = require("../globals/menus");
92
93
  var import_time = require("../globals/time");
@@ -1038,9 +1039,20 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
1038
1039
  },
1039
1040
  extras: {
1040
1041
  activeStateNode: this.root.getPath(),
1041
- selectedShapes: this.getSelectedShapes(),
1042
+ selectedShapes: this.getSelectedShapes().map((s) => {
1043
+ const { props, ...rest } = s;
1044
+ const { text: _text, richText: _richText, ...restProps } = props;
1045
+ return {
1046
+ ...rest,
1047
+ props: restProps
1048
+ };
1049
+ }),
1050
+ selectionCount: this.getSelectedShapes().length,
1042
1051
  editingShape: editingShapeId ? this.getShape(editingShapeId) : void 0,
1043
- inputs: this.inputs
1052
+ inputs: this.inputs,
1053
+ pageState: this.getCurrentPageState(),
1054
+ instanceState: this.getInstanceState(),
1055
+ collaboratorCount: this.getCollaboratorsOnCurrentPage().length
1044
1056
  }
1045
1057
  };
1046
1058
  } catch {
@@ -1203,7 +1215,7 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
1203
1215
  if (partial.isChangingStyle === true) {
1204
1216
  this._isChangingStyleTimeout = this.timers.setTimeout(() => {
1205
1217
  this._updateInstanceState({ isChangingStyle: false }, { history: "ignore" });
1206
- }, 2e3);
1218
+ }, 1e3);
1207
1219
  }
1208
1220
  }
1209
1221
  return this;
@@ -3154,11 +3166,14 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
3154
3166
  if (!assetId) return null;
3155
3167
  const asset = this.getAsset(assetId);
3156
3168
  if (!asset) return null;
3157
- const { screenScale = 1, shouldResolveToOriginal = false } = context;
3169
+ const {
3170
+ screenScale = 1,
3171
+ shouldResolveToOriginal = false,
3172
+ dpr = this.getInstanceState().devicePixelRatio
3173
+ } = context;
3158
3174
  const zoomStepFunction = (zoom) => Math.pow(2, Math.ceil(Math.log2(zoom)));
3159
- const steppedScreenScale = Math.max(0.125, zoomStepFunction(screenScale));
3175
+ const steppedScreenScale = zoomStepFunction(screenScale);
3160
3176
  const networkEffectiveType = "connection" in navigator ? navigator.connection.effectiveType : null;
3161
- const dpr = this.getInstanceState().devicePixelRatio;
3162
3177
  return await this.store.props.assets.resolve(asset, {
3163
3178
  screenScale: screenScale || 1,
3164
3179
  steppedScreenScale,
@@ -6276,7 +6291,7 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
6276
6291
  * @public
6277
6292
  */
6278
6293
  async getSvgElement(shapes, opts = {}) {
6279
- const ids = typeof shapes[0] === "string" ? shapes : shapes.map((s) => s.id);
6294
+ const ids = shapes.length === 0 ? this.getCurrentPageShapeIdsSorted() : typeof shapes[0] === "string" ? shapes : shapes.map((s) => s.id);
6280
6295
  if (ids.length === 0) return void 0;
6281
6296
  return (0, import_exportToSvg.exportToSvg)(this, ids, opts);
6282
6297
  }
@@ -6306,6 +6321,55 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
6306
6321
  if (!result) return void 0;
6307
6322
  return result.svg;
6308
6323
  }
6324
+ /**
6325
+ * Get an exported image of the given shapes.
6326
+ *
6327
+ * @param shapes - The shapes (or shape ids) to export.
6328
+ * @param opts - Options for the export.
6329
+ *
6330
+ * @returns A blob of the image.
6331
+ * @public
6332
+ */
6333
+ async toImage(shapes, opts = {}) {
6334
+ const withDefaults = {
6335
+ format: "png",
6336
+ scale: 1,
6337
+ pixelRatio: opts.format === "svg" ? void 0 : 2,
6338
+ ...opts
6339
+ };
6340
+ const result = await this.getSvgString(shapes, withDefaults);
6341
+ if (!result) throw new Error("Could not create SVG");
6342
+ switch (withDefaults.format) {
6343
+ case "svg":
6344
+ return {
6345
+ blob: new Blob([result.svg], { type: "text/plain" }),
6346
+ width: result.width,
6347
+ height: result.height
6348
+ };
6349
+ case "jpeg":
6350
+ case "png":
6351
+ case "webp": {
6352
+ const blob = await (0, import_getSvgAsImage.getSvgAsImage)(result.svg, {
6353
+ type: withDefaults.format,
6354
+ quality: withDefaults.quality,
6355
+ pixelRatio: withDefaults.pixelRatio,
6356
+ width: result.width,
6357
+ height: result.height
6358
+ });
6359
+ if (!blob) {
6360
+ throw new Error("Could not construct image.");
6361
+ }
6362
+ return {
6363
+ blob,
6364
+ width: result.width,
6365
+ height: result.height
6366
+ };
6367
+ }
6368
+ default: {
6369
+ (0, import_utils.exhaustiveSwitchError)(withDefaults.format);
6370
+ }
6371
+ }
6372
+ }
6309
6373
  /**
6310
6374
  * Update the input points from a pointer, pinch, or wheel event.
6311
6375
  *