@tldraw/editor 3.8.0-canary.888d6f3ea97f → 3.8.0-canary.8c96638cdde8

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 (98) hide show
  1. package/dist-cjs/index.d.ts +257 -60
  2. package/dist-cjs/index.js +14 -8
  3. package/dist-cjs/index.js.map +2 -2
  4. package/dist-cjs/lib/components/default-components/DefaultCanvas.js +2 -5
  5. package/dist-cjs/lib/components/default-components/DefaultCanvas.js.map +2 -2
  6. package/dist-cjs/lib/config/TLSessionStateSnapshot.js.map +2 -2
  7. package/dist-cjs/lib/config/createTLStore.js +4 -2
  8. package/dist-cjs/lib/config/createTLStore.js.map +2 -2
  9. package/dist-cjs/lib/editor/Editor.js +98 -23
  10. package/dist-cjs/lib/editor/Editor.js.map +2 -2
  11. package/dist-cjs/lib/editor/managers/SnapManager/BoundsSnaps.js.map +2 -2
  12. package/dist-cjs/lib/editor/managers/TextManager.js +1 -0
  13. package/dist-cjs/lib/editor/managers/TextManager.js.map +2 -2
  14. package/dist-cjs/lib/editor/shapes/ShapeUtil.js.map +2 -2
  15. package/dist-cjs/lib/editor/shapes/shared/resizeScaled.js +66 -0
  16. package/dist-cjs/lib/editor/shapes/shared/resizeScaled.js.map +7 -0
  17. package/dist-cjs/lib/editor/types/SvgExportContext.js.map +2 -2
  18. package/dist-cjs/lib/editor/types/emit-types.js.map +1 -1
  19. package/dist-cjs/lib/editor/types/external-content.js.map +1 -1
  20. package/dist-cjs/lib/editor/types/misc-types.js.map +1 -1
  21. package/dist-cjs/lib/exports/StyleEmbedder.js.map +2 -2
  22. package/dist-cjs/lib/exports/exportToSvg.js.map +2 -2
  23. package/dist-cjs/lib/exports/getSvgAsImage.js +83 -0
  24. package/dist-cjs/lib/exports/getSvgAsImage.js.map +7 -0
  25. package/dist-cjs/lib/exports/getSvgJsx.js +16 -3
  26. package/dist-cjs/lib/exports/getSvgJsx.js.map +2 -2
  27. package/dist-cjs/lib/hooks/useLocalStore.js +1 -1
  28. package/dist-cjs/lib/hooks/useLocalStore.js.map +2 -2
  29. package/dist-cjs/lib/hooks/usePassThroughWheelEvents.js +4 -0
  30. package/dist-cjs/lib/hooks/usePassThroughWheelEvents.js.map +3 -3
  31. package/dist-cjs/lib/options.js +3 -1
  32. package/dist-cjs/lib/options.js.map +2 -2
  33. package/dist-cjs/lib/utils/browserCanvasMaxSize.js +75 -0
  34. package/dist-cjs/lib/utils/browserCanvasMaxSize.js.map +7 -0
  35. package/dist-cjs/lib/utils/sync/TLLocalSyncClient.js +3 -1
  36. package/dist-cjs/lib/utils/sync/TLLocalSyncClient.js.map +2 -2
  37. package/dist-cjs/version.js +3 -3
  38. package/dist-cjs/version.js.map +1 -1
  39. package/dist-esm/index.d.mts +257 -60
  40. package/dist-esm/index.mjs +7 -1
  41. package/dist-esm/index.mjs.map +2 -2
  42. package/dist-esm/lib/components/default-components/DefaultCanvas.mjs +2 -5
  43. package/dist-esm/lib/components/default-components/DefaultCanvas.mjs.map +2 -2
  44. package/dist-esm/lib/config/TLSessionStateSnapshot.mjs.map +2 -2
  45. package/dist-esm/lib/config/createTLStore.mjs +4 -2
  46. package/dist-esm/lib/config/createTLStore.mjs.map +2 -2
  47. package/dist-esm/lib/editor/Editor.mjs +98 -23
  48. package/dist-esm/lib/editor/Editor.mjs.map +2 -2
  49. package/dist-esm/lib/editor/managers/SnapManager/BoundsSnaps.mjs.map +2 -2
  50. package/dist-esm/lib/editor/managers/TextManager.mjs +1 -0
  51. package/dist-esm/lib/editor/managers/TextManager.mjs.map +2 -2
  52. package/dist-esm/lib/editor/shapes/ShapeUtil.mjs.map +2 -2
  53. package/dist-esm/lib/editor/shapes/shared/resizeScaled.mjs +46 -0
  54. package/dist-esm/lib/editor/shapes/shared/resizeScaled.mjs.map +7 -0
  55. package/dist-esm/lib/editor/types/SvgExportContext.mjs.map +2 -2
  56. package/dist-esm/lib/exports/StyleEmbedder.mjs.map +2 -2
  57. package/dist-esm/lib/exports/exportToSvg.mjs.map +2 -2
  58. package/dist-esm/lib/exports/getSvgAsImage.mjs +63 -0
  59. package/dist-esm/lib/exports/getSvgAsImage.mjs.map +7 -0
  60. package/dist-esm/lib/exports/getSvgJsx.mjs +16 -3
  61. package/dist-esm/lib/exports/getSvgJsx.mjs.map +2 -2
  62. package/dist-esm/lib/hooks/useLocalStore.mjs +1 -1
  63. package/dist-esm/lib/hooks/useLocalStore.mjs.map +2 -2
  64. package/dist-esm/lib/hooks/usePassThroughWheelEvents.mjs +4 -0
  65. package/dist-esm/lib/hooks/usePassThroughWheelEvents.mjs.map +3 -3
  66. package/dist-esm/lib/options.mjs +3 -1
  67. package/dist-esm/lib/options.mjs.map +2 -2
  68. package/dist-esm/lib/utils/browserCanvasMaxSize.mjs +45 -0
  69. package/dist-esm/lib/utils/browserCanvasMaxSize.mjs.map +7 -0
  70. package/dist-esm/lib/utils/sync/TLLocalSyncClient.mjs +3 -1
  71. package/dist-esm/lib/utils/sync/TLLocalSyncClient.mjs.map +2 -2
  72. package/dist-esm/version.mjs +3 -3
  73. package/dist-esm/version.mjs.map +1 -1
  74. package/editor.css +2 -1
  75. package/package.json +22 -20
  76. package/src/index.ts +19 -1
  77. package/src/lib/components/default-components/DefaultCanvas.tsx +2 -5
  78. package/src/lib/config/TLSessionStateSnapshot.ts +3 -1
  79. package/src/lib/config/createTLStore.ts +4 -2
  80. package/src/lib/editor/Editor.ts +147 -57
  81. package/src/lib/editor/managers/SnapManager/BoundsSnaps.ts +4 -4
  82. package/src/lib/editor/managers/TextManager.ts +1 -0
  83. package/src/lib/editor/shapes/ShapeUtil.ts +30 -1
  84. package/src/lib/editor/shapes/shared/resizeScaled.ts +61 -0
  85. package/src/lib/editor/types/SvgExportContext.tsx +21 -0
  86. package/src/lib/editor/types/emit-types.ts +1 -0
  87. package/src/lib/editor/types/external-content.ts +90 -50
  88. package/src/lib/editor/types/misc-types.ts +55 -2
  89. package/src/lib/exports/StyleEmbedder.ts +1 -1
  90. package/src/lib/exports/exportToSvg.tsx +2 -2
  91. package/src/lib/exports/getSvgAsImage.ts +92 -0
  92. package/src/lib/exports/getSvgJsx.tsx +17 -2
  93. package/src/lib/hooks/useLocalStore.ts +1 -1
  94. package/src/lib/hooks/usePassThroughWheelEvents.ts +7 -0
  95. package/src/lib/options.ts +11 -0
  96. package/src/lib/utils/browserCanvasMaxSize.ts +65 -0
  97. package/src/lib/utils/sync/TLLocalSyncClient.ts +3 -1
  98. package/src/version.ts +3 -3
@@ -68,6 +68,7 @@ import { TLPropsMigrations } from '@tldraw/tlschema';
68
68
  import { TLRecord } from '@tldraw/tlschema';
69
69
  import { TLScribble } from '@tldraw/tlschema';
70
70
  import { TLShape } from '@tldraw/tlschema';
71
+ import { TLShapeCrop } from '@tldraw/tlschema';
71
72
  import { TLShapeId } from '@tldraw/tlschema';
72
73
  import { TLShapePartial } from '@tldraw/tlschema';
73
74
  import { TLStore } from '@tldraw/tlschema';
@@ -536,6 +537,8 @@ export declare type BoxLike = Box | BoxModel;
536
537
  */
537
538
  export declare function canonicalizeRotation(a: number): number;
538
539
 
540
+ /* Excluded from this release type: CanvasMaxSize */
541
+
539
542
  /**
540
543
  * Get the center of a circle from three points.
541
544
  *
@@ -615,6 +618,8 @@ export declare function clamp(n: number, min: number, max: number): number;
615
618
  */
616
619
  export declare function clampRadians(r: number): number;
617
620
 
621
+ /* Excluded from this release type: clampToBrowserMaxCanvasSize */
622
+
618
623
  /** @public */
619
624
  export declare class ClickManager {
620
625
  editor: Editor;
@@ -847,6 +852,7 @@ export declare const defaultTldrawOptions: {
847
852
  readonly edgeScrollDistance: 8;
848
853
  readonly edgeScrollEaseDuration: 200;
849
854
  readonly edgeScrollSpeed: 25;
855
+ readonly enableToolbarKeyboardShortcuts: true;
850
856
  readonly exportProvider: ExoticComponent< {
851
857
  children?: ReactNode;
852
858
  }>;
@@ -880,6 +886,7 @@ export declare const defaultTldrawOptions: {
880
886
  readonly maxPointsPerDrawShape: 500;
881
887
  readonly maxShapesPerPage: 4000;
882
888
  readonly multiClickDurationMs: 200;
889
+ readonly noteShapeResizeMode: "none";
883
890
  readonly temporaryAssetPreviewLifetimeMs: 180000;
884
891
  readonly textShadowLod: 0.35;
885
892
  };
@@ -1113,6 +1120,14 @@ export declare class Editor extends EventEmitter<TLEventMap> {
1113
1120
  getShapeUtil<S extends TLUnknownShape>(shape: S | TLShapePartial<S>): ShapeUtil<S>;
1114
1121
  getShapeUtil<S extends TLUnknownShape>(type: S['type']): ShapeUtil<S>;
1115
1122
  getShapeUtil<T extends ShapeUtil>(type: T extends ShapeUtil<infer R> ? R['type'] : string): T;
1123
+ /**
1124
+ * Returns true if the editor has a shape util for the given shape / shape type.
1125
+ *
1126
+ * @param shape - A shape, shape partial, or shape type.
1127
+ */
1128
+ hasShapeUtil<S extends TLUnknownShape>(shape: S | TLShapePartial<S>): boolean;
1129
+ hasShapeUtil<S extends TLUnknownShape>(type: S['type']): boolean;
1130
+ hasShapeUtil<T extends ShapeUtil>(type: T extends ShapeUtil<infer R> ? R['type'] : string): boolean;
1116
1131
  /**
1117
1132
  * A map of shape utility classes (TLShapeUtils) by shape type.
1118
1133
  *
@@ -1365,8 +1380,8 @@ export declare class Editor extends EventEmitter<TLEventMap> {
1365
1380
  *
1366
1381
  * @example
1367
1382
  * ```ts
1368
- * state.getStateDescendant('select')
1369
- * state.getStateDescendant('select.brushing')
1383
+ * editor.getStateDescendant('select')
1384
+ * editor.getStateDescendant('select.brushing')
1370
1385
  * ```
1371
1386
  *
1372
1387
  * @param path - The descendant's path of state ids, separated by periods.
@@ -2348,6 +2363,7 @@ export declare class Editor extends EventEmitter<TLEventMap> {
2348
2363
  */
2349
2364
  getAsset<T extends TLAsset>(asset: T | T['id']): T | undefined;
2350
2365
  resolveAssetUrl(assetId: null | TLAssetId, context: {
2366
+ dpr?: number;
2351
2367
  screenScale?: number;
2352
2368
  shouldResolveToOriginal?: boolean;
2353
2369
  }): Promise<null | string>;
@@ -2355,7 +2371,10 @@ export declare class Editor extends EventEmitter<TLEventMap> {
2355
2371
  * Upload an asset to the store's asset service, returning a URL that can be used to resolve the
2356
2372
  * asset.
2357
2373
  */
2358
- uploadAsset(asset: TLAsset, file: File, abortSignal?: AbortSignal): Promise<string>;
2374
+ uploadAsset(asset: TLAsset, file: File, abortSignal?: AbortSignal): Promise<{
2375
+ meta?: JsonObject;
2376
+ src: string;
2377
+ }>;
2359
2378
  private _getShapeGeometryCache;
2360
2379
  /**
2361
2380
  * Get the geometry of a shape.
@@ -3426,7 +3445,7 @@ export declare class Editor extends EventEmitter<TLEventMap> {
3426
3445
  *
3427
3446
  * @public
3428
3447
  */
3429
- registerExternalAssetHandler<T extends TLExternalAssetContent['type']>(type: T, handler: ((info: TLExternalAssetContent & {
3448
+ registerExternalAssetHandler<T extends TLExternalAsset['type']>(type: T, handler: ((info: TLExternalAsset & {
3430
3449
  type: T;
3431
3450
  }) => Promise<TLAsset>) | null): this;
3432
3451
  /**
@@ -3472,8 +3491,8 @@ export declare class Editor extends EventEmitter<TLEventMap> {
3472
3491
  * @param info - Info about the external content.
3473
3492
  * @returns The asset.
3474
3493
  */
3475
- getAssetForExternalContent(info: TLExternalAssetContent): Promise<TLAsset | undefined>;
3476
- hasExternalAssetHandler(type: TLExternalAssetContent['type']): boolean;
3494
+ getAssetForExternalContent(info: TLExternalAsset): Promise<TLAsset | undefined>;
3495
+ hasExternalAssetHandler(type: TLExternalAsset['type']): boolean;
3477
3496
  /* Excluded from this release type: externalContentHandlers */
3478
3497
  /**
3479
3498
  * Register an external content handler. This handler will be called when the editor receives
@@ -3538,7 +3557,7 @@ export declare class Editor extends EventEmitter<TLEventMap> {
3538
3557
  *
3539
3558
  * @public
3540
3559
  */
3541
- getSvgElement(shapes: TLShape[] | TLShapeId[], opts?: TLImageExportOptions): Promise<{
3560
+ getSvgElement(shapes: TLShape[] | TLShapeId[], opts?: TLSvgExportOptions): Promise<{
3542
3561
  height: number;
3543
3562
  svg: SVGSVGElement;
3544
3563
  width: number;
@@ -3553,13 +3572,27 @@ export declare class Editor extends EventEmitter<TLEventMap> {
3553
3572
  *
3554
3573
  * @public
3555
3574
  */
3556
- getSvgString(shapes: TLShape[] | TLShapeId[], opts?: TLImageExportOptions): Promise<{
3575
+ getSvgString(shapes: TLShape[] | TLShapeId[], opts?: TLSvgExportOptions): Promise<{
3557
3576
  height: number;
3558
3577
  svg: string;
3559
3578
  width: number;
3560
3579
  } | undefined>;
3561
3580
  /** @deprecated Use {@link Editor.getSvgString} or {@link Editor.getSvgElement} instead. */
3562
- getSvg(shapes: TLShape[] | TLShapeId[], opts?: TLImageExportOptions): Promise<SVGSVGElement | undefined>;
3581
+ getSvg(shapes: TLShape[] | TLShapeId[], opts?: TLSvgExportOptions): Promise<SVGSVGElement | undefined>;
3582
+ /**
3583
+ * Get an exported image of the given shapes.
3584
+ *
3585
+ * @param shapes - The shapes (or shape ids) to export.
3586
+ * @param opts - Options for the export.
3587
+ *
3588
+ * @returns A blob of the image.
3589
+ * @public
3590
+ */
3591
+ toImage(shapes: TLShape[] | TLShapeId[], opts?: TLImageExportOptions): Promise<{
3592
+ blob: Blob;
3593
+ height: number;
3594
+ width: number;
3595
+ }>;
3563
3596
  /**
3564
3597
  * The app's current input state.
3565
3598
  *
@@ -4073,6 +4106,15 @@ export declare function getPolygonVertices(width: number, height: number, sides:
4073
4106
  /** @public */
4074
4107
  export declare function getSnapshot(store: TLStore): TLEditorSnapshot;
4075
4108
 
4109
+ /** @public */
4110
+ export declare function getSvgAsImage(svgString: string, options: {
4111
+ height: number;
4112
+ pixelRatio?: number;
4113
+ quality?: number;
4114
+ type: 'jpeg' | 'png' | 'webp';
4115
+ width: number;
4116
+ }): Promise<Blob | null>;
4117
+
4076
4118
  /**
4077
4119
  * Turn an array of points into a path of quadradic curves.
4078
4120
  *
@@ -4652,6 +4694,23 @@ export declare interface ResizeBoxOptions {
4652
4694
  maxHeight?: number;
4653
4695
  }
4654
4696
 
4697
+ /**
4698
+ * Resize a shape that has a scale prop.
4699
+ *
4700
+ * @param shape - The shape to resize
4701
+ * @param info - The resize info
4702
+ *
4703
+ * @public */
4704
+ export declare function resizeScaled(shape: TLBaseShape<any, {
4705
+ scale: number;
4706
+ }>, { initialBounds, scaleX, scaleY, newPoint, handle }: TLResizeInfo<any>): {
4707
+ props: {
4708
+ scale: number;
4709
+ };
4710
+ x: number;
4711
+ y: number;
4712
+ };
4713
+
4655
4714
  /** @public */
4656
4715
  export declare const ROTATE_CORNER_TO_SELECTION_CORNER: {
4657
4716
  readonly bottom_left_rotate: "bottom_left";
@@ -5023,6 +5082,15 @@ export declare abstract class ShapeUtil<Shape extends TLUnknownShape = TLUnknown
5023
5082
  * @public
5024
5083
  */
5025
5084
  onBeforeUpdate?(prev: Shape, next: Shape): Shape | void;
5085
+ /**
5086
+ * A callback called when a shape changes from a crop.
5087
+ *
5088
+ * @param shape - The shape at the start of the crop.
5089
+ * @param info - Info about the crop.
5090
+ * @returns A change to apply to the shape, or void.
5091
+ * @public
5092
+ */
5093
+ onCrop?(shape: Shape, info: TLCropInfo<Shape>): Omit<TLShapePartial<Shape>, 'id' | 'type'> | undefined | void;
5026
5094
  /**
5027
5095
  * A callback called when some other shapes are dragged over this one.
5028
5096
  *
@@ -5404,10 +5472,27 @@ export declare interface SvgExportContext {
5404
5472
  * method depending on your use-case.
5405
5473
  */
5406
5474
  waitUntil(promise: Promise<void>): void;
5475
+ /**
5476
+ * Resolve an asset URL in the context of this export. Supply the asset ID and the width in
5477
+ * shape-pixels it'll be displayed at, and this will resolve the asset according to the export
5478
+ * options.
5479
+ */
5480
+ resolveAssetUrl(assetId: TLAssetId, width: number): Promise<null | string>;
5407
5481
  /**
5408
5482
  * Whether the export should be in dark mode.
5409
5483
  */
5410
5484
  readonly isDarkMode: boolean;
5485
+ /**
5486
+ * The scale of the export - how much CSS pixels will be scaled up/down by.
5487
+ */
5488
+ readonly scale: number;
5489
+ /**
5490
+ * Use this value to optionally downscale images in the export. If we're exporting directly to
5491
+ * an SVG, this will usually be null, and you shouldn't downscale images. If the export is to a
5492
+ * raster format like PNG, this will be the number of raster pixels in the resulting bitmap per
5493
+ * CSS pixel in the resulting SVG.
5494
+ */
5495
+ readonly pixelRatio: null | number;
5411
5496
  }
5412
5497
 
5413
5498
  /** @public */
@@ -5498,6 +5583,12 @@ export declare interface TLBaseEventInfo {
5498
5583
  accelKey: boolean;
5499
5584
  }
5500
5585
 
5586
+ /** @public */
5587
+ export declare interface TLBaseExternalContent {
5588
+ sources?: TLExternalContentSource[];
5589
+ point?: VecLike;
5590
+ }
5591
+
5501
5592
  /** @public */
5502
5593
  export declare interface TLBindingUtilConstructor<T extends TLUnknownBinding, U extends BindingUtil<T> = BindingUtil<T>> {
5503
5594
  new (editor: Editor): U;
@@ -5663,6 +5754,24 @@ export declare interface TLContent {
5663
5754
  schema: SerializedSchema;
5664
5755
  }
5665
5756
 
5757
+ /**
5758
+ * Info about a crop.
5759
+ * @param handle - The handle being dragged.
5760
+ * @param change - The distance the handle is moved.
5761
+ * @param initialShape - The shape at the start of the resize.
5762
+ * @public
5763
+ */
5764
+ export declare interface TLCropInfo<T extends TLShape> {
5765
+ handle: SelectionHandle;
5766
+ change: Vec;
5767
+ crop: TLShapeCrop;
5768
+ uncroppedSize: {
5769
+ h: number;
5770
+ w: number;
5771
+ };
5772
+ initialShape: T;
5773
+ }
5774
+
5666
5775
  /** @public */
5667
5776
  export declare interface TLCursorProps {
5668
5777
  className?: string;
@@ -5915,6 +6024,15 @@ export declare interface TldrawOptions {
5915
6024
  readonly exportProvider: ComponentType<{
5916
6025
  children: React.ReactNode;
5917
6026
  }>;
6027
+ /**
6028
+ * How should the note shape resize? By default it does not resize (except automatically based on its text content),
6029
+ * but you can set it to be user-resizable using scale.
6030
+ */
6031
+ readonly noteShapeResizeMode: 'none' | 'scale';
6032
+ /**
6033
+ * By default, the toolbar items are accessible via number shortcuts according to their order. To disable this, set this option to false.
6034
+ */
6035
+ readonly enableToolbarKeyboardShortcuts: boolean;
5918
6036
  }
5919
6037
 
5920
6038
  /** @public */
@@ -6016,6 +6134,13 @@ export declare interface TLEditorSnapshot {
6016
6134
  session: TLSessionStateSnapshot;
6017
6135
  }
6018
6136
 
6137
+ /** @public */
6138
+ export declare interface TLEmbedExternalContent<EmbedDefinition> extends TLBaseExternalContent {
6139
+ type: 'embed';
6140
+ url: string;
6141
+ embed: EmbedDefinition;
6142
+ }
6143
+
6019
6144
  /** @public */
6020
6145
  export declare type TLEnterEventHandler = (info: any, from: string) => void;
6021
6146
 
@@ -6041,6 +6166,13 @@ export declare interface TLErrorBoundaryProps {
6041
6166
  fallback: TLErrorFallbackComponent;
6042
6167
  }
6043
6168
 
6169
+ /** @public */
6170
+ export declare interface TLErrorExternalContentSource {
6171
+ type: 'error';
6172
+ data: null | string;
6173
+ reason: string;
6174
+ }
6175
+
6044
6176
  /** @public */
6045
6177
  export declare type TLErrorFallbackComponent = ComponentType<{
6046
6178
  editor?: Editor;
@@ -6086,6 +6218,7 @@ export declare interface TLEventMap {
6086
6218
  }];
6087
6219
  'stop-camera-animation': [];
6088
6220
  'stop-following': [];
6221
+ 'before-event': [TLEventInfo];
6089
6222
  event: [TLEventInfo];
6090
6223
  tick: [number];
6091
6224
  frame: [number];
@@ -6100,58 +6233,40 @@ export declare type TLEventMapHandler<T extends keyof TLEventMap> = (...args: TL
6100
6233
  /** @public */
6101
6234
  export declare type TLEventName = 'cancel' | 'complete' | 'interrupt' | 'tick' | 'wheel' | TLCLickEventName | TLKeyboardEventName | TLPinchEventName | TLPointerEventName;
6102
6235
 
6236
+ /** @public */
6237
+ export declare interface TLExcalidrawExternalContentSource {
6238
+ type: 'excalidraw';
6239
+ data: any;
6240
+ }
6241
+
6103
6242
  /** @public */
6104
6243
  export declare type TLExitEventHandler = (info: any, to: string) => void;
6105
6244
 
6106
6245
  /** @public */
6107
- export declare type TLExternalAssetContent = {
6108
- assetId?: TLAssetId;
6109
- file: File;
6246
+ export declare type TLExportType = 'jpeg' | 'png' | 'svg' | 'webp';
6247
+
6248
+ /** @public */
6249
+ export declare type TLExternalAsset = TLFileExternalAsset | TLUrlExternalAsset;
6250
+
6251
+ /** @public */
6252
+ export declare type TLExternalContent<EmbedDefinition> = TLEmbedExternalContent<EmbedDefinition> | TLFilesExternalContent | TLSvgTextExternalContent | TLTextExternalContent | TLUrlExternalContent;
6253
+
6254
+ /** @public */
6255
+ export declare type TLExternalContentSource = TLErrorExternalContentSource | TLExcalidrawExternalContentSource | TLTextExternalContentSource | TLTldrawExternalContentSource;
6256
+
6257
+ /** @public */
6258
+ export declare interface TLFileExternalAsset {
6110
6259
  type: 'file';
6111
- } | {
6112
- type: 'url';
6113
- url: string;
6114
- };
6260
+ file: File;
6261
+ assetId?: TLAssetId;
6262
+ }
6115
6263
 
6116
6264
  /** @public */
6117
- export declare type TLExternalContent<EmbedDefinition> = {
6118
- point?: VecLike;
6119
- sources?: TLExternalContentSource[];
6120
- } & ({
6121
- embed: EmbedDefinition;
6122
- type: 'embed';
6123
- url: string;
6124
- } | {
6265
+ export declare interface TLFilesExternalContent extends TLBaseExternalContent {
6266
+ type: 'files';
6125
6267
  files: File[];
6126
6268
  ignoreParent: boolean;
6127
- type: 'files';
6128
- } | {
6129
- text: string;
6130
- type: 'svg-text';
6131
- } | {
6132
- text: string;
6133
- type: 'text';
6134
- } | {
6135
- type: 'url';
6136
- url: string;
6137
- });
6138
-
6139
- /** @public */
6140
- export declare type TLExternalContentSource = {
6141
- data: any;
6142
- type: 'excalidraw';
6143
- } | {
6144
- data: null | string;
6145
- reason: string;
6146
- type: 'error';
6147
- } | {
6148
- data: string;
6149
- subtype: 'html' | 'json' | 'text' | 'url';
6150
- type: 'text';
6151
- } | {
6152
- data: TLContent;
6153
- type: 'tldraw';
6154
- };
6269
+ }
6155
6270
 
6156
6271
  /** @public */
6157
6272
  export declare interface TLGridProps {
@@ -6209,15 +6324,16 @@ export declare interface TLHistoryMark {
6209
6324
  }
6210
6325
 
6211
6326
  /** @public */
6212
- export declare interface TLImageExportOptions {
6213
- bounds?: Box;
6214
- scale?: number;
6327
+ export declare interface TLImageExportOptions extends TLSvgExportOptions {
6328
+ /**
6329
+ * If the export is being converted to a lossy bitmap format (e.g. jpeg), this is the quality of
6330
+ * the export. This is a number between 0 and 1.
6331
+ */
6215
6332
  quality?: number;
6216
- pixelRatio?: number;
6217
- background?: boolean;
6218
- padding?: number;
6219
- darkMode?: boolean;
6220
- preserveAspectRatio?: React.SVGAttributes<SVGSVGElement>['preserveAspectRatio'];
6333
+ /**
6334
+ * The format to export as. Defaults to 'png'.
6335
+ */
6336
+ format?: TLExportType;
6221
6337
  }
6222
6338
 
6223
6339
  /** @public */
@@ -6721,12 +6837,75 @@ export declare type TLStoreWithStatus = {
6721
6837
  readonly store: TLStore;
6722
6838
  };
6723
6839
 
6840
+ /** @public */
6841
+ export declare interface TLSvgExportOptions {
6842
+ /**
6843
+ * The bounding box, in page coordinates, of the area being exported.
6844
+ */
6845
+ bounds?: Box;
6846
+ /**
6847
+ * The logical scale of the export. This scales the resulting size of the SVG being generated.
6848
+ */
6849
+ scale?: number;
6850
+ /**
6851
+ * When exporting an SVG, the expected pixel ratio of the export will be passed in to
6852
+ * {@link @tldraw/tlschema#TLAssetStore.resolve} as the `dpr` property, so that assets can be
6853
+ * downscaled to the appropriate resolution.
6854
+ *
6855
+ * When exporting to a bitmap image format, the size of the resulting image will be multiplied
6856
+ * by this number.
6857
+ *
6858
+ * For SVG exports, this defaults to undefined - which means we'll request original-quality
6859
+ * assets. For bitmap exports, this defaults to 2.
6860
+ */
6861
+ pixelRatio?: number;
6862
+ /**
6863
+ * Should the background color be included in the export? If false, the generated image will be
6864
+ * transparent (if exporting to a format that supports transparency).
6865
+ */
6866
+ background?: boolean;
6867
+ /**
6868
+ * How much padding to include around the bounds of exports? Defaults to 32px.
6869
+ */
6870
+ padding?: number;
6871
+ /**
6872
+ * Should the export be rendered in dark mode (true) or light mode (false)? Defaults to the
6873
+ * current instance's dark mode setting.
6874
+ */
6875
+ darkMode?: boolean;
6876
+ /**
6877
+ * The
6878
+ * {@link https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/preserveAspectRatio | `preserveAspectRatio` }
6879
+ * attribute of the SVG element.
6880
+ */
6881
+ preserveAspectRatio?: React.SVGAttributes<SVGSVGElement>['preserveAspectRatio'];
6882
+ }
6883
+
6724
6884
  /**
6725
6885
  * @public
6726
6886
  * @deprecated use {@link TLImageExportOptions} instead
6727
6887
  */
6728
6888
  export declare type TLSvgOptions = TLImageExportOptions;
6729
6889
 
6890
+ /** @public */
6891
+ export declare interface TLSvgTextExternalContent extends TLBaseExternalContent {
6892
+ type: 'svg-text';
6893
+ text: string;
6894
+ }
6895
+
6896
+ /** @public */
6897
+ export declare interface TLTextExternalContent extends TLBaseExternalContent {
6898
+ type: 'text';
6899
+ text: string;
6900
+ }
6901
+
6902
+ /** @public */
6903
+ export declare interface TLTextExternalContentSource {
6904
+ type: 'text';
6905
+ data: string;
6906
+ subtype: 'html' | 'json' | 'text' | 'url';
6907
+ }
6908
+
6730
6909
  /** @public */
6731
6910
  export declare type TLTickEvent = (info: TLTickEventInfo) => void;
6732
6911
 
@@ -6744,6 +6923,24 @@ export declare interface TLTickEventInfo {
6744
6923
  */
6745
6924
  export declare const tltime: Timers;
6746
6925
 
6926
+ /** @public */
6927
+ export declare interface TLTldrawExternalContentSource {
6928
+ type: 'tldraw';
6929
+ data: TLContent;
6930
+ }
6931
+
6932
+ /** @public */
6933
+ export declare interface TLUrlExternalAsset {
6934
+ type: 'url';
6935
+ url: string;
6936
+ }
6937
+
6938
+ /** @public */
6939
+ export declare interface TLUrlExternalContent extends TLBaseExternalContent {
6940
+ type: 'url';
6941
+ url: string;
6942
+ }
6943
+
6747
6944
  /** @public */
6748
6945
  export declare interface TLUser {
6749
6946
  readonly userPreferences: Signal<TLUserPreferences>;
@@ -23,6 +23,7 @@ import {
23
23
  useStateTracking,
24
24
  useValue
25
25
  } from "@tldraw/state-react";
26
+ import { resizeScaled } from "./lib/editor/shapes/shared/resizeScaled.mjs";
26
27
  import { LocalIndexedDb, Table } from "./lib/utils/sync/LocalIndexedDb.mjs";
27
28
  export * from "@tldraw/store";
28
29
  export * from "@tldraw/tlschema";
@@ -142,6 +143,7 @@ import {
142
143
  import {
143
144
  EVENT_NAME_MAP
144
145
  } from "./lib/editor/types/event-types.mjs";
146
+ import { getSvgAsImage } from "./lib/exports/getSvgAsImage.mjs";
145
147
  import { tlenv } from "./lib/globals/environment.mjs";
146
148
  import { tlmenus } from "./lib/globals/menus.mjs";
147
149
  import { tltime } from "./lib/globals/time.mjs";
@@ -250,6 +252,7 @@ import {
250
252
  SharedStyleMap
251
253
  } from "./lib/utils/SharedStylesMap.mjs";
252
254
  import { dataUrlToFile, getDefaultCdnBaseUrl } from "./lib/utils/assets.mjs";
255
+ import { clampToBrowserMaxCanvasSize } from "./lib/utils/browserCanvasMaxSize.mjs";
253
256
  import {
254
257
  debugFlags,
255
258
  featureFlags
@@ -285,7 +288,7 @@ function debugEnableLicensing() {
285
288
  }
286
289
  registerTldrawLibraryVersion(
287
290
  "@tldraw/editor",
288
- "3.8.0-canary.888d6f3ea97f",
291
+ "3.8.0-canary.8c96638cdde8",
289
292
  "esm"
290
293
  );
291
294
  export {
@@ -377,6 +380,7 @@ export {
377
380
  centerOfCircleFromThreePoints,
378
381
  clamp,
379
382
  clampRadians,
383
+ clampToBrowserMaxCanvasSize,
380
384
  clockwiseAngleDist,
381
385
  computed,
382
386
  coreShapes,
@@ -407,6 +411,7 @@ export {
407
411
  getPolygonVertices,
408
412
  getRotationSnapshot,
409
413
  getSnapshot,
414
+ getSvgAsImage,
410
415
  getSvgPathFromPoints,
411
416
  getUserPreferences,
412
417
  hardReset,
@@ -443,6 +448,7 @@ export {
443
448
  refreshPage,
444
449
  releasePointerCapture,
445
450
  resizeBox,
451
+ resizeScaled,
446
452
  rotateSelectionHandle,
447
453
  runtime,
448
454
  sanitizeId,