@tldraw/editor 4.5.0-canary.a915d60dd080 → 4.5.0-canary.a91c1d1ad09b
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.
- package/dist-cjs/index.d.ts +27 -6
- package/dist-cjs/index.js +1 -1
- package/dist-cjs/lib/config/createTLStore.js +1 -0
- package/dist-cjs/lib/config/createTLStore.js.map +2 -2
- package/dist-cjs/lib/editor/Editor.js +29 -13
- package/dist-cjs/lib/editor/Editor.js.map +2 -2
- package/dist-cjs/lib/editor/managers/FocusManager/FocusManager.js +8 -4
- package/dist-cjs/lib/editor/managers/FocusManager/FocusManager.js.map +2 -2
- package/dist-cjs/lib/editor/types/misc-types.js.map +1 -1
- package/dist-cjs/lib/exports/exportToSvg.js +1 -1
- package/dist-cjs/lib/exports/exportToSvg.js.map +2 -2
- package/dist-cjs/lib/exports/getSvgAsImage.js +180 -29
- package/dist-cjs/lib/exports/getSvgAsImage.js.map +3 -3
- package/dist-cjs/lib/exports/getSvgJsx.js +18 -7
- package/dist-cjs/lib/exports/getSvgJsx.js.map +2 -2
- package/dist-cjs/lib/license/Watermark.js +10 -0
- package/dist-cjs/lib/license/Watermark.js.map +2 -2
- package/dist-cjs/lib/primitives/Vec.js +35 -22
- package/dist-cjs/lib/primitives/Vec.js.map +2 -2
- package/dist-cjs/lib/primitives/geometry/Arc2d.js +6 -13
- package/dist-cjs/lib/primitives/geometry/Arc2d.js.map +2 -2
- package/dist-cjs/lib/primitives/geometry/Circle2d.js +31 -2
- package/dist-cjs/lib/primitives/geometry/Circle2d.js.map +2 -2
- package/dist-cjs/lib/primitives/geometry/CubicBezier2d.js +9 -0
- package/dist-cjs/lib/primitives/geometry/CubicBezier2d.js.map +2 -2
- package/dist-cjs/lib/primitives/geometry/CubicSpline2d.js +9 -0
- package/dist-cjs/lib/primitives/geometry/CubicSpline2d.js.map +2 -2
- package/dist-cjs/lib/primitives/geometry/Edge2d.js +32 -18
- package/dist-cjs/lib/primitives/geometry/Edge2d.js.map +2 -2
- package/dist-cjs/lib/primitives/geometry/Ellipse2d.js +12 -0
- package/dist-cjs/lib/primitives/geometry/Ellipse2d.js.map +2 -2
- package/dist-cjs/lib/primitives/geometry/Polyline2d.js +51 -12
- package/dist-cjs/lib/primitives/geometry/Polyline2d.js.map +2 -2
- package/dist-cjs/lib/primitives/geometry/Stadium2d.js +12 -0
- package/dist-cjs/lib/primitives/geometry/Stadium2d.js.map +2 -2
- package/dist-cjs/lib/primitives/geometry/geometry.bench.js +133 -0
- package/dist-cjs/lib/primitives/geometry/geometry.bench.js.map +7 -0
- package/dist-cjs/lib/primitives/intersect.js +16 -15
- package/dist-cjs/lib/primitives/intersect.js.map +2 -2
- package/dist-cjs/lib/primitives/utils.js +0 -1
- package/dist-cjs/lib/primitives/utils.js.map +2 -2
- package/dist-cjs/version.js +3 -3
- package/dist-cjs/version.js.map +1 -1
- package/dist-esm/index.d.mts +27 -6
- package/dist-esm/index.mjs +1 -1
- package/dist-esm/lib/config/createTLStore.mjs +1 -0
- package/dist-esm/lib/config/createTLStore.mjs.map +2 -2
- package/dist-esm/lib/editor/Editor.mjs +30 -14
- package/dist-esm/lib/editor/Editor.mjs.map +2 -2
- package/dist-esm/lib/editor/managers/FocusManager/FocusManager.mjs +8 -4
- package/dist-esm/lib/editor/managers/FocusManager/FocusManager.mjs.map +2 -2
- package/dist-esm/lib/exports/exportToSvg.mjs +1 -1
- package/dist-esm/lib/exports/exportToSvg.mjs.map +2 -2
- package/dist-esm/lib/exports/getSvgAsImage.mjs +180 -29
- package/dist-esm/lib/exports/getSvgAsImage.mjs.map +3 -3
- package/dist-esm/lib/exports/getSvgJsx.mjs +18 -7
- package/dist-esm/lib/exports/getSvgJsx.mjs.map +2 -2
- package/dist-esm/lib/license/Watermark.mjs +10 -0
- package/dist-esm/lib/license/Watermark.mjs.map +2 -2
- package/dist-esm/lib/primitives/Vec.mjs +35 -22
- package/dist-esm/lib/primitives/Vec.mjs.map +2 -2
- package/dist-esm/lib/primitives/geometry/Arc2d.mjs +6 -13
- package/dist-esm/lib/primitives/geometry/Arc2d.mjs.map +2 -2
- package/dist-esm/lib/primitives/geometry/Circle2d.mjs +31 -2
- package/dist-esm/lib/primitives/geometry/Circle2d.mjs.map +2 -2
- package/dist-esm/lib/primitives/geometry/CubicBezier2d.mjs +9 -0
- package/dist-esm/lib/primitives/geometry/CubicBezier2d.mjs.map +2 -2
- package/dist-esm/lib/primitives/geometry/CubicSpline2d.mjs +9 -0
- package/dist-esm/lib/primitives/geometry/CubicSpline2d.mjs.map +2 -2
- package/dist-esm/lib/primitives/geometry/Edge2d.mjs +32 -18
- package/dist-esm/lib/primitives/geometry/Edge2d.mjs.map +2 -2
- package/dist-esm/lib/primitives/geometry/Ellipse2d.mjs +13 -1
- package/dist-esm/lib/primitives/geometry/Ellipse2d.mjs.map +2 -2
- package/dist-esm/lib/primitives/geometry/Polyline2d.mjs +51 -12
- package/dist-esm/lib/primitives/geometry/Polyline2d.mjs.map +2 -2
- package/dist-esm/lib/primitives/geometry/Stadium2d.mjs +13 -1
- package/dist-esm/lib/primitives/geometry/Stadium2d.mjs.map +2 -2
- package/dist-esm/lib/primitives/geometry/geometry.bench.mjs +132 -0
- package/dist-esm/lib/primitives/geometry/geometry.bench.mjs.map +7 -0
- package/dist-esm/lib/primitives/intersect.mjs +17 -16
- package/dist-esm/lib/primitives/intersect.mjs.map +2 -2
- package/dist-esm/lib/primitives/utils.mjs +0 -1
- package/dist-esm/lib/primitives/utils.mjs.map +2 -2
- package/dist-esm/version.mjs +3 -3
- package/dist-esm/version.mjs.map +1 -1
- package/package.json +7 -7
- package/src/lib/config/createTLStore.ts +3 -0
- package/src/lib/editor/Editor.ts +28 -12
- package/src/lib/editor/managers/FocusManager/FocusManager.ts +8 -4
- package/src/lib/editor/types/misc-types.ts +8 -2
- package/src/lib/exports/exportToSvg.tsx +1 -1
- package/src/lib/exports/getSvgAsImage.ts +290 -31
- package/src/lib/exports/getSvgJsx.test.ts +103 -101
- package/src/lib/exports/getSvgJsx.tsx +30 -8
- package/src/lib/license/Watermark.tsx +10 -0
- package/src/lib/primitives/Vec.ts +51 -24
- package/src/lib/primitives/geometry/Arc2d.ts +10 -15
- package/src/lib/primitives/geometry/Circle2d.ts +40 -2
- package/src/lib/primitives/geometry/CubicBezier2d.ts +10 -0
- package/src/lib/primitives/geometry/CubicSpline2d.ts +10 -0
- package/src/lib/primitives/geometry/Edge2d.ts +41 -18
- package/src/lib/primitives/geometry/Ellipse2d.ts +14 -1
- package/src/lib/primitives/geometry/Polyline2d.ts +60 -12
- package/src/lib/primitives/geometry/Stadium2d.ts +14 -1
- package/src/lib/primitives/geometry/geometry.bench.ts +179 -0
- package/src/lib/primitives/intersect.ts +27 -27
- package/src/lib/primitives/utils.ts +4 -4
- package/src/version.ts +3 -3
package/dist-cjs/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { AtomSet } from '@tldraw/store';
|
|
|
3
3
|
import { BoxModel } from '@tldraw/tlschema';
|
|
4
4
|
import { ComponentType } from 'react';
|
|
5
5
|
import { Computed } from '@tldraw/state';
|
|
6
|
+
import { CustomRecordInfo } from '@tldraw/tlschema';
|
|
6
7
|
import { Dispatch } from 'react';
|
|
7
8
|
import { Editor as Editor_2 } from '@tiptap/core';
|
|
8
9
|
import { EditorProviderProps as EditorProviderProps_2 } from '@tiptap/react';
|
|
@@ -577,6 +578,8 @@ export declare class Circle2d extends Geometry2d {
|
|
|
577
578
|
getBounds(): Box;
|
|
578
579
|
getVertices(): Vec[];
|
|
579
580
|
nearestPoint(point: VecLike): Vec;
|
|
581
|
+
distanceToPoint(point: VecLike, hitInside?: boolean): number;
|
|
582
|
+
hitTestPoint(point: VecLike, margin?: number, hitInside?: boolean): boolean;
|
|
580
583
|
hitTestLineSegment(A: VecLike, B: VecLike, distance?: number): boolean;
|
|
581
584
|
getSvgPathData(): string;
|
|
582
585
|
}
|
|
@@ -749,6 +752,7 @@ export declare class CubicBezier2d extends Polyline2d {
|
|
|
749
752
|
});
|
|
750
753
|
getVertices(): Vec[];
|
|
751
754
|
nearestPoint(A: VecLike): Vec;
|
|
755
|
+
distanceToPoint(point: VecLike, _hitInside?: boolean): number;
|
|
752
756
|
getSvgPathData(first?: boolean): string;
|
|
753
757
|
static GetAtT(segment: CubicBezier2d, t: number): Vec;
|
|
754
758
|
getLength(_filters?: Geometry2dFilters, precision?: number): number;
|
|
@@ -765,6 +769,7 @@ export declare class CubicSpline2d extends Geometry2d {
|
|
|
765
769
|
getLength(): number;
|
|
766
770
|
getVertices(): Vec[];
|
|
767
771
|
nearestPoint(A: VecLike): Vec;
|
|
772
|
+
distanceToPoint(point: VecLike, _hitInside?: boolean): number;
|
|
768
773
|
hitTestLineSegment(A: VecLike, B: VecLike): boolean;
|
|
769
774
|
getSvgPathData(): string;
|
|
770
775
|
}
|
|
@@ -983,9 +988,9 @@ export declare const EASINGS: {
|
|
|
983
988
|
export declare class Edge2d extends Geometry2d {
|
|
984
989
|
private _start;
|
|
985
990
|
private _end;
|
|
986
|
-
private
|
|
987
|
-
private
|
|
988
|
-
private
|
|
991
|
+
private _dx;
|
|
992
|
+
private _dy;
|
|
993
|
+
private _len2;
|
|
989
994
|
constructor(config: {
|
|
990
995
|
end: Vec;
|
|
991
996
|
start: Vec;
|
|
@@ -993,6 +998,7 @@ export declare class Edge2d extends Geometry2d {
|
|
|
993
998
|
getLength(): number;
|
|
994
999
|
getVertices(): Vec[];
|
|
995
1000
|
nearestPoint(point: VecLike): Vec;
|
|
1001
|
+
distanceToPoint(point: VecLike, _hitInside?: boolean): number;
|
|
996
1002
|
getSvgPathData(first?: boolean): string;
|
|
997
1003
|
}
|
|
998
1004
|
|
|
@@ -3791,6 +3797,7 @@ export declare class Editor extends EventEmitter<TLEventMap> {
|
|
|
3791
3797
|
getSvgElement(shapes: TLShape[] | TLShapeId[], opts?: TLSvgExportOptions): Promise<{
|
|
3792
3798
|
height: number;
|
|
3793
3799
|
svg: SVGSVGElement;
|
|
3800
|
+
trimPadding: number;
|
|
3794
3801
|
width: number;
|
|
3795
3802
|
} | undefined>;
|
|
3796
3803
|
/**
|
|
@@ -3806,6 +3813,7 @@ export declare class Editor extends EventEmitter<TLEventMap> {
|
|
|
3806
3813
|
getSvgString(shapes: TLShape[] | TLShapeId[], opts?: TLSvgExportOptions): Promise<{
|
|
3807
3814
|
height: number;
|
|
3808
3815
|
svg: string;
|
|
3816
|
+
trimPadding: number;
|
|
3809
3817
|
width: number;
|
|
3810
3818
|
} | undefined>;
|
|
3811
3819
|
/**
|
|
@@ -4181,6 +4189,7 @@ export declare class Ellipse2d extends Geometry2d {
|
|
|
4181
4189
|
get edges(): Edge2d[];
|
|
4182
4190
|
getVertices(): any[];
|
|
4183
4191
|
nearestPoint(A: VecLike): Vec;
|
|
4192
|
+
distanceToPoint(point: VecLike, hitInside?: boolean): number;
|
|
4184
4193
|
hitTestLineSegment(A: VecLike, B: VecLike): boolean;
|
|
4185
4194
|
getBounds(): Box;
|
|
4186
4195
|
getLength(): number;
|
|
@@ -5216,6 +5225,8 @@ export declare class Polyline2d extends Geometry2d {
|
|
|
5216
5225
|
getLength(): number;
|
|
5217
5226
|
getVertices(): Vec[];
|
|
5218
5227
|
nearestPoint(A: VecLike): Vec;
|
|
5228
|
+
hitTestPoint(point: VecLike, margin?: number, hitInside?: boolean): boolean;
|
|
5229
|
+
distanceToPoint(point: VecLike, hitInside?: boolean): number;
|
|
5219
5230
|
hitTestLineSegment(A: VecLike, B: VecLike, distance?: number): boolean;
|
|
5220
5231
|
getSvgPathData(): string;
|
|
5221
5232
|
}
|
|
@@ -6303,6 +6314,7 @@ export declare class Stadium2d extends Geometry2d {
|
|
|
6303
6314
|
width: number;
|
|
6304
6315
|
});
|
|
6305
6316
|
nearestPoint(A: VecLike): Vec;
|
|
6317
|
+
distanceToPoint(point: VecLike, hitInside?: boolean): number;
|
|
6306
6318
|
hitTestLineSegment(A: VecLike, B: VecLike): boolean;
|
|
6307
6319
|
getVertices(): Vec[];
|
|
6308
6320
|
getBounds(): Box;
|
|
@@ -8218,6 +8230,7 @@ export declare type TLStoreOptions = TLStoreBaseOptions & {
|
|
|
8218
8230
|
export declare type TLStoreSchemaOptions = {
|
|
8219
8231
|
bindingUtils?: readonly TLAnyBindingUtilConstructor[];
|
|
8220
8232
|
migrations?: readonly MigrationSequence[];
|
|
8233
|
+
records?: Record<string, CustomRecordInfo>;
|
|
8221
8234
|
shapeUtils?: readonly TLAnyShapeUtilConstructor[];
|
|
8222
8235
|
} | {
|
|
8223
8236
|
schema?: StoreSchema<TLRecord, TLStoreProps>;
|
|
@@ -8275,9 +8288,15 @@ export declare interface TLSvgExportOptions {
|
|
|
8275
8288
|
*/
|
|
8276
8289
|
background?: boolean;
|
|
8277
8290
|
/**
|
|
8278
|
-
* How much padding to include around the bounds of exports
|
|
8291
|
+
* How much padding to include around the bounds of exports.
|
|
8292
|
+
*
|
|
8293
|
+
* - `'auto'` (default) — trim to visual content bounds, capturing overflow (like thick
|
|
8294
|
+
* strokes or arrowheads) without extra whitespace.
|
|
8295
|
+
* - `number` (e.g. `32`) — fixed padding in px. No trimming; overflow beyond the padding
|
|
8296
|
+
* region is clipped.
|
|
8297
|
+
* - `0` — no padding, no trimming, overflow is clipped.
|
|
8279
8298
|
*/
|
|
8280
|
-
padding?: number;
|
|
8299
|
+
padding?: 'auto' | number;
|
|
8281
8300
|
/**
|
|
8282
8301
|
* Should the export be rendered in dark mode (true) or light mode (false)? Defaults to the
|
|
8283
8302
|
* current instance's dark mode setting.
|
|
@@ -8776,6 +8795,7 @@ export declare class Vec {
|
|
|
8776
8795
|
static Cast(A: VecLike): Vec;
|
|
8777
8796
|
static Slope(A: VecLike, B: VecLike): number;
|
|
8778
8797
|
static IsNaN(A: VecLike): boolean;
|
|
8798
|
+
static IsFinite(A: VecLike): boolean;
|
|
8779
8799
|
/**
|
|
8780
8800
|
* Get the angle from position A to position B.
|
|
8781
8801
|
*/
|
|
@@ -8820,8 +8840,9 @@ export declare class Vec {
|
|
|
8820
8840
|
* @param A - The first point.
|
|
8821
8841
|
* @param B - The second point.
|
|
8822
8842
|
* @param steps - The number of points to return.
|
|
8843
|
+
* @param ease - The easing to use.
|
|
8823
8844
|
*/
|
|
8824
|
-
static PointsBetween(A: VecModel, B: VecModel, steps?: number): Vec[];
|
|
8845
|
+
static PointsBetween(A: VecModel, B: VecModel, steps?: number, ease?: (t: number) => number): Vec[];
|
|
8825
8846
|
static SnapToGrid(A: VecLike, gridSize?: number): Vec;
|
|
8826
8847
|
}
|
|
8827
8848
|
|
package/dist-cjs/index.js
CHANGED
|
@@ -370,7 +370,7 @@ var import_LocalIndexedDb = require("./lib/utils/sync/LocalIndexedDb");
|
|
|
370
370
|
var import_uniq = require("./lib/utils/uniq");
|
|
371
371
|
(0, import_utils.registerTldrawLibraryVersion)(
|
|
372
372
|
"@tldraw/editor",
|
|
373
|
-
"4.5.0-canary.
|
|
373
|
+
"4.5.0-canary.a91c1d1ad09b",
|
|
374
374
|
"cjs"
|
|
375
375
|
);
|
|
376
376
|
//# sourceMappingURL=index.js.map
|
|
@@ -41,6 +41,7 @@ function createTLSchemaFromUtils(opts) {
|
|
|
41
41
|
return (0, import_tlschema.createTLSchema)({
|
|
42
42
|
shapes: "shapeUtils" in opts && opts.shapeUtils ? utilsToMap((0, import_defaultShapes.checkShapesAndAddCore)(opts.shapeUtils)) : void 0,
|
|
43
43
|
bindings: "bindingUtils" in opts && opts.bindingUtils ? utilsToMap((0, import_defaultBindings.checkBindings)(opts.bindingUtils)) : void 0,
|
|
44
|
+
records: "records" in opts ? opts.records : void 0,
|
|
44
45
|
migrations: "migrations" in opts ? opts.migrations : void 0
|
|
45
46
|
});
|
|
46
47
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/lib/config/createTLStore.ts"],
|
|
4
|
-
"sourcesContent": ["import { Signal } from '@tldraw/state'\nimport { HistoryEntry, MigrationSequence, SerializedStore, Store, StoreSchema } from '@tldraw/store'\nimport {\n\tSchemaPropsInfo,\n\tTLAssetStore,\n\tTLRecord,\n\tTLStore,\n\tTLStoreProps,\n\tTLStoreSnapshot,\n\tcreateTLSchema,\n} from '@tldraw/tlschema'\nimport { FileHelpers, assert } from '@tldraw/utils'\nimport { Editor } from '../editor/Editor'\nimport { TLEditorSnapshot, loadSnapshot } from './TLEditorSnapshot'\nimport { TLAnyBindingUtilConstructor, checkBindings } from './defaultBindings'\nimport { TLAnyShapeUtilConstructor, checkShapesAndAddCore } from './defaultShapes'\n\n/** @public */\nexport interface TLStoreBaseOptions {\n\t/** The initial data for the store. */\n\tinitialData?: SerializedStore<TLRecord>\n\n\t/** A snapshot of initial data to migrate and load into the store. */\n\tsnapshot?: Partial<TLEditorSnapshot> | TLStoreSnapshot\n\n\t/** The default name for the store. */\n\tdefaultName?: string\n\n\t/** How should this store upload & resolve assets? */\n\tassets?: TLAssetStore\n\n\t/** Called when the store is connected to an {@link @tldraw/editor#Editor}. */\n\tonMount?(editor: Editor): void | (() => void)\n}\n\n/** @public */\nexport type TLStoreSchemaOptions =\n\t| {\n\t\t\tschema?: StoreSchema<TLRecord, TLStoreProps>\n\t }\n\t| {\n\t\t\tshapeUtils?: readonly TLAnyShapeUtilConstructor[]\n\t\t\tmigrations?: readonly MigrationSequence[]\n\t\t\tbindingUtils?: readonly TLAnyBindingUtilConstructor[]\n\t }\n\n/** @public */\nexport type TLStoreOptions = TLStoreBaseOptions & {\n\tid?: string\n\t/** Collaboration options for the store. */\n\tcollaboration?: {\n\t\tstatus: Signal<'online' | 'offline'> | null\n\t\tmode?: Signal<'readonly' | 'readwrite'> | null\n\t}\n} & TLStoreSchemaOptions\n\n/** @public */\nexport type TLStoreEventInfo = HistoryEntry<TLRecord>\n\nconst defaultAssetResolve: NonNullable<TLAssetStore['resolve']> = (asset) => asset.props.src\n\n/** @public */\nexport const inlineBase64AssetStore: TLAssetStore = {\n\tupload: async (_, file) => {\n\t\treturn { src: await FileHelpers.blobToDataUrl(file) }\n\t},\n}\n\n/**\n * A helper for creating a TLStore schema from either an object with shapeUtils, bindingUtils, and\n * migrations, or a schema.\n *\n * @param opts - Options for creating the schema.\n *\n * @public\n */\nexport function createTLSchemaFromUtils(\n\topts: TLStoreSchemaOptions\n): StoreSchema<TLRecord, TLStoreProps> {\n\tif ('schema' in opts && opts.schema) return opts.schema\n\n\treturn createTLSchema({\n\t\tshapes:\n\t\t\t'shapeUtils' in opts && opts.shapeUtils\n\t\t\t\t? utilsToMap(checkShapesAndAddCore(opts.shapeUtils))\n\t\t\t\t: undefined,\n\t\tbindings:\n\t\t\t'bindingUtils' in opts && opts.bindingUtils\n\t\t\t\t? utilsToMap(checkBindings(opts.bindingUtils))\n\t\t\t\t: undefined,\n\t\tmigrations: 'migrations' in opts ? opts.migrations : undefined,\n\t})\n}\n\n/**\n * A helper for creating a TLStore.\n *\n * @param opts - Options for creating the store.\n *\n * @public\n */\nexport function createTLStore({\n\tinitialData,\n\tdefaultName = '',\n\tid,\n\tassets = inlineBase64AssetStore,\n\tonMount,\n\tcollaboration,\n\t...rest\n}: TLStoreOptions = {}): TLStore {\n\tconst schema = createTLSchemaFromUtils(rest)\n\n\tconst store = new Store({\n\t\tid,\n\t\tschema,\n\t\tinitialData,\n\t\tprops: {\n\t\t\tdefaultName,\n\t\t\tassets: {\n\t\t\t\tupload: assets.upload,\n\t\t\t\tresolve: assets.resolve ?? defaultAssetResolve,\n\t\t\t\tremove: assets.remove ?? (() => Promise.resolve()),\n\t\t\t},\n\t\t\tonMount: (editor) => {\n\t\t\t\tassert(editor instanceof Editor)\n\t\t\t\tonMount?.(editor)\n\t\t\t},\n\t\t\tcollaboration,\n\t\t},\n\t})\n\n\tif (rest.snapshot) {\n\t\tif (initialData) throw new Error('Cannot provide both initialData and snapshot')\n\t\tloadSnapshot(store, rest.snapshot, { forceOverwriteSessionState: true })\n\t}\n\n\treturn store\n}\n\nfunction utilsToMap<T extends SchemaPropsInfo & { type: string }>(utils: T[]) {\n\treturn Object.fromEntries(\n\t\tutils.map((s): [string, SchemaPropsInfo] => [\n\t\t\ts.type,\n\t\t\t{\n\t\t\t\tprops: s.props,\n\t\t\t\tmigrations: s.migrations,\n\t\t\t},\n\t\t])\n\t)\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAAqF;AACrF,
|
|
4
|
+
"sourcesContent": ["import { Signal } from '@tldraw/state'\nimport { HistoryEntry, MigrationSequence, SerializedStore, Store, StoreSchema } from '@tldraw/store'\nimport {\n\tCustomRecordInfo,\n\tSchemaPropsInfo,\n\tTLAssetStore,\n\tTLRecord,\n\tTLStore,\n\tTLStoreProps,\n\tTLStoreSnapshot,\n\tcreateTLSchema,\n} from '@tldraw/tlschema'\nimport { FileHelpers, assert } from '@tldraw/utils'\nimport { Editor } from '../editor/Editor'\nimport { TLEditorSnapshot, loadSnapshot } from './TLEditorSnapshot'\nimport { TLAnyBindingUtilConstructor, checkBindings } from './defaultBindings'\nimport { TLAnyShapeUtilConstructor, checkShapesAndAddCore } from './defaultShapes'\n\n/** @public */\nexport interface TLStoreBaseOptions {\n\t/** The initial data for the store. */\n\tinitialData?: SerializedStore<TLRecord>\n\n\t/** A snapshot of initial data to migrate and load into the store. */\n\tsnapshot?: Partial<TLEditorSnapshot> | TLStoreSnapshot\n\n\t/** The default name for the store. */\n\tdefaultName?: string\n\n\t/** How should this store upload & resolve assets? */\n\tassets?: TLAssetStore\n\n\t/** Called when the store is connected to an {@link @tldraw/editor#Editor}. */\n\tonMount?(editor: Editor): void | (() => void)\n}\n\n/** @public */\nexport type TLStoreSchemaOptions =\n\t| {\n\t\t\tschema?: StoreSchema<TLRecord, TLStoreProps>\n\t }\n\t| {\n\t\t\tshapeUtils?: readonly TLAnyShapeUtilConstructor[]\n\t\t\tmigrations?: readonly MigrationSequence[]\n\t\t\tbindingUtils?: readonly TLAnyBindingUtilConstructor[]\n\t\t\trecords?: Record<string, CustomRecordInfo>\n\t }\n\n/** @public */\nexport type TLStoreOptions = TLStoreBaseOptions & {\n\tid?: string\n\t/** Collaboration options for the store. */\n\tcollaboration?: {\n\t\tstatus: Signal<'online' | 'offline'> | null\n\t\tmode?: Signal<'readonly' | 'readwrite'> | null\n\t}\n} & TLStoreSchemaOptions\n\n/** @public */\nexport type TLStoreEventInfo = HistoryEntry<TLRecord>\n\nconst defaultAssetResolve: NonNullable<TLAssetStore['resolve']> = (asset) => asset.props.src\n\n/** @public */\nexport const inlineBase64AssetStore: TLAssetStore = {\n\tupload: async (_, file) => {\n\t\treturn { src: await FileHelpers.blobToDataUrl(file) }\n\t},\n}\n\n/**\n * A helper for creating a TLStore schema from either an object with shapeUtils, bindingUtils, and\n * migrations, or a schema.\n *\n * @param opts - Options for creating the schema.\n *\n * @public\n */\nexport function createTLSchemaFromUtils(\n\topts: TLStoreSchemaOptions\n): StoreSchema<TLRecord, TLStoreProps> {\n\tif ('schema' in opts && opts.schema) return opts.schema\n\n\treturn createTLSchema({\n\t\tshapes:\n\t\t\t'shapeUtils' in opts && opts.shapeUtils\n\t\t\t\t? utilsToMap(checkShapesAndAddCore(opts.shapeUtils))\n\t\t\t\t: undefined,\n\t\tbindings:\n\t\t\t'bindingUtils' in opts && opts.bindingUtils\n\t\t\t\t? utilsToMap(checkBindings(opts.bindingUtils))\n\t\t\t\t: undefined,\n\t\trecords: 'records' in opts ? opts.records : undefined,\n\t\tmigrations: 'migrations' in opts ? opts.migrations : undefined,\n\t})\n}\n\n/**\n * A helper for creating a TLStore.\n *\n * @param opts - Options for creating the store.\n *\n * @public\n */\nexport function createTLStore({\n\tinitialData,\n\tdefaultName = '',\n\tid,\n\tassets = inlineBase64AssetStore,\n\tonMount,\n\tcollaboration,\n\t...rest\n}: TLStoreOptions = {}): TLStore {\n\tconst schema = createTLSchemaFromUtils(rest)\n\n\tconst store = new Store({\n\t\tid,\n\t\tschema,\n\t\tinitialData,\n\t\tprops: {\n\t\t\tdefaultName,\n\t\t\tassets: {\n\t\t\t\tupload: assets.upload,\n\t\t\t\tresolve: assets.resolve ?? defaultAssetResolve,\n\t\t\t\tremove: assets.remove ?? (() => Promise.resolve()),\n\t\t\t},\n\t\t\tonMount: (editor) => {\n\t\t\t\tassert(editor instanceof Editor)\n\t\t\t\tonMount?.(editor)\n\t\t\t},\n\t\t\tcollaboration,\n\t\t},\n\t})\n\n\tif (rest.snapshot) {\n\t\tif (initialData) throw new Error('Cannot provide both initialData and snapshot')\n\t\tloadSnapshot(store, rest.snapshot, { forceOverwriteSessionState: true })\n\t}\n\n\treturn store\n}\n\nfunction utilsToMap<T extends SchemaPropsInfo & { type: string }>(utils: T[]) {\n\treturn Object.fromEntries(\n\t\tutils.map((s): [string, SchemaPropsInfo] => [\n\t\t\ts.type,\n\t\t\t{\n\t\t\t\tprops: s.props,\n\t\t\t\tmigrations: s.migrations,\n\t\t\t},\n\t\t])\n\t)\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAAqF;AACrF,sBASO;AACP,mBAAoC;AACpC,oBAAuB;AACvB,8BAA+C;AAC/C,6BAA2D;AAC3D,2BAAiE;AA6CjE,MAAM,sBAA4D,CAAC,UAAU,MAAM,MAAM;AAGlF,MAAM,yBAAuC;AAAA,EACnD,QAAQ,OAAO,GAAG,SAAS;AAC1B,WAAO,EAAE,KAAK,MAAM,yBAAY,cAAc,IAAI,EAAE;AAAA,EACrD;AACD;AAUO,SAAS,wBACf,MACsC;AACtC,MAAI,YAAY,QAAQ,KAAK,OAAQ,QAAO,KAAK;AAEjD,aAAO,gCAAe;AAAA,IACrB,QACC,gBAAgB,QAAQ,KAAK,aAC1B,eAAW,4CAAsB,KAAK,UAAU,CAAC,IACjD;AAAA,IACJ,UACC,kBAAkB,QAAQ,KAAK,eAC5B,eAAW,sCAAc,KAAK,YAAY,CAAC,IAC3C;AAAA,IACJ,SAAS,aAAa,OAAO,KAAK,UAAU;AAAA,IAC5C,YAAY,gBAAgB,OAAO,KAAK,aAAa;AAAA,EACtD,CAAC;AACF;AASO,SAAS,cAAc;AAAA,EAC7B;AAAA,EACA,cAAc;AAAA,EACd;AAAA,EACA,SAAS;AAAA,EACT;AAAA,EACA;AAAA,EACA,GAAG;AACJ,IAAoB,CAAC,GAAY;AAChC,QAAM,SAAS,wBAAwB,IAAI;AAE3C,QAAM,QAAQ,IAAI,mBAAM;AAAA,IACvB;AAAA,IACA;AAAA,IACA;AAAA,IACA,OAAO;AAAA,MACN;AAAA,MACA,QAAQ;AAAA,QACP,QAAQ,OAAO;AAAA,QACf,SAAS,OAAO,WAAW;AAAA,QAC3B,QAAQ,OAAO,WAAW,MAAM,QAAQ,QAAQ;AAAA,MACjD;AAAA,MACA,SAAS,CAAC,WAAW;AACpB,iCAAO,kBAAkB,oBAAM;AAC/B,kBAAU,MAAM;AAAA,MACjB;AAAA,MACA;AAAA,IACD;AAAA,EACD,CAAC;AAED,MAAI,KAAK,UAAU;AAClB,QAAI,YAAa,OAAM,IAAI,MAAM,8CAA8C;AAC/E,8CAAa,OAAO,KAAK,UAAU,EAAE,4BAA4B,KAAK,CAAC;AAAA,EACxE;AAEA,SAAO;AACR;AAEA,SAAS,WAAyD,OAAY;AAC7E,SAAO,OAAO;AAAA,IACb,MAAM,IAAI,CAAC,MAAiC;AAAA,MAC3C,EAAE;AAAA,MACF;AAAA,QACC,OAAO,EAAE;AAAA,QACT,YAAY,EAAE;AAAA,MACf;AAAA,IACD,CAAC;AAAA,EACF;AACD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -6914,7 +6914,8 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
|
|
|
6914
6914
|
return {
|
|
6915
6915
|
svg: serializer.serializeToString(result.svg),
|
|
6916
6916
|
width: result.width,
|
|
6917
|
-
height: result.height
|
|
6917
|
+
height: result.height,
|
|
6918
|
+
trimPadding: result.trimPadding
|
|
6918
6919
|
};
|
|
6919
6920
|
}
|
|
6920
6921
|
/**
|
|
@@ -6936,30 +6937,45 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
|
|
|
6936
6937
|
const result = await this.getSvgString(shapes, withDefaults);
|
|
6937
6938
|
if (!result) throw new Error("Could not create SVG");
|
|
6938
6939
|
switch (withDefaults.format) {
|
|
6939
|
-
case "svg":
|
|
6940
|
+
case "svg": {
|
|
6941
|
+
let svg = result.svg;
|
|
6942
|
+
let w = result.width;
|
|
6943
|
+
let h = result.height;
|
|
6944
|
+
if (result.trimPadding > 0) {
|
|
6945
|
+
const trimmed = await (0, import_getSvgAsImage.trimSvgToContent)(svg, {
|
|
6946
|
+
width: w,
|
|
6947
|
+
height: h,
|
|
6948
|
+
trimPadding: result.trimPadding,
|
|
6949
|
+
scale: withDefaults.scale
|
|
6950
|
+
});
|
|
6951
|
+
if (trimmed) {
|
|
6952
|
+
svg = trimmed.svg;
|
|
6953
|
+
w = trimmed.width;
|
|
6954
|
+
h = trimmed.height;
|
|
6955
|
+
}
|
|
6956
|
+
}
|
|
6940
6957
|
return {
|
|
6941
|
-
blob: new Blob([
|
|
6942
|
-
width:
|
|
6943
|
-
height:
|
|
6958
|
+
blob: new Blob([svg], { type: "image/svg+xml" }),
|
|
6959
|
+
width: w,
|
|
6960
|
+
height: h
|
|
6944
6961
|
};
|
|
6962
|
+
}
|
|
6945
6963
|
case "jpeg":
|
|
6946
6964
|
case "png":
|
|
6947
6965
|
case "webp": {
|
|
6948
|
-
const
|
|
6966
|
+
const imageResult = await (0, import_getSvgAsImage.getSvgAsImageWithOptions)(result.svg, {
|
|
6949
6967
|
type: withDefaults.format,
|
|
6950
6968
|
quality: withDefaults.quality,
|
|
6951
6969
|
pixelRatio: withDefaults.pixelRatio,
|
|
6952
6970
|
width: result.width,
|
|
6953
|
-
height: result.height
|
|
6971
|
+
height: result.height,
|
|
6972
|
+
trimPadding: result.trimPadding,
|
|
6973
|
+
scale: withDefaults.scale
|
|
6954
6974
|
});
|
|
6955
|
-
if (!
|
|
6975
|
+
if (!imageResult) {
|
|
6956
6976
|
throw new Error("Could not construct image.");
|
|
6957
6977
|
}
|
|
6958
|
-
return
|
|
6959
|
-
blob,
|
|
6960
|
-
width: result.width,
|
|
6961
|
-
height: result.height
|
|
6962
|
-
};
|
|
6978
|
+
return imageResult;
|
|
6963
6979
|
}
|
|
6964
6980
|
default: {
|
|
6965
6981
|
(0, import_utils.exhaustiveSwitchError)(withDefaults.format);
|