@tldraw/editor 3.8.0-canary.bc462846819a → 3.8.0-canary.be65d368fd8b
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 +259 -60
- package/dist-cjs/index.js +15 -8
- package/dist-cjs/index.js.map +2 -2
- package/dist-cjs/lib/components/default-components/DefaultCanvas.js +2 -5
- package/dist-cjs/lib/components/default-components/DefaultCanvas.js.map +2 -2
- package/dist-cjs/lib/config/TLSessionStateSnapshot.js.map +2 -2
- package/dist-cjs/lib/config/createTLStore.js +4 -2
- package/dist-cjs/lib/config/createTLStore.js.map +2 -2
- package/dist-cjs/lib/editor/Editor.js +98 -23
- package/dist-cjs/lib/editor/Editor.js.map +2 -2
- package/dist-cjs/lib/editor/managers/SnapManager/BoundsSnaps.js.map +2 -2
- package/dist-cjs/lib/editor/managers/TextManager.js +1 -0
- package/dist-cjs/lib/editor/managers/TextManager.js.map +2 -2
- package/dist-cjs/lib/editor/shapes/ShapeUtil.js.map +2 -2
- package/dist-cjs/lib/editor/shapes/shared/resizeScaled.js +66 -0
- package/dist-cjs/lib/editor/shapes/shared/resizeScaled.js.map +7 -0
- package/dist-cjs/lib/editor/types/SvgExportContext.js.map +2 -2
- package/dist-cjs/lib/editor/types/emit-types.js.map +1 -1
- package/dist-cjs/lib/editor/types/external-content.js.map +1 -1
- package/dist-cjs/lib/editor/types/misc-types.js.map +1 -1
- package/dist-cjs/lib/exports/StyleEmbedder.js.map +2 -2
- package/dist-cjs/lib/exports/exportToSvg.js.map +2 -2
- package/dist-cjs/lib/exports/getSvgAsImage.js +83 -0
- package/dist-cjs/lib/exports/getSvgAsImage.js.map +7 -0
- package/dist-cjs/lib/exports/getSvgJsx.js +16 -3
- package/dist-cjs/lib/exports/getSvgJsx.js.map +2 -2
- package/dist-cjs/lib/hooks/useDocumentEvents.js +1 -3
- package/dist-cjs/lib/hooks/useDocumentEvents.js.map +2 -2
- package/dist-cjs/lib/hooks/useLocalStore.js +1 -1
- package/dist-cjs/lib/hooks/useLocalStore.js.map +2 -2
- package/dist-cjs/lib/hooks/usePassThroughWheelEvents.js +4 -0
- package/dist-cjs/lib/hooks/usePassThroughWheelEvents.js.map +3 -3
- package/dist-cjs/lib/options.js +3 -1
- package/dist-cjs/lib/options.js.map +2 -2
- package/dist-cjs/lib/utils/browserCanvasMaxSize.js +75 -0
- package/dist-cjs/lib/utils/browserCanvasMaxSize.js.map +7 -0
- package/dist-cjs/lib/utils/dom.js +6 -0
- package/dist-cjs/lib/utils/dom.js.map +2 -2
- package/dist-cjs/lib/utils/sync/TLLocalSyncClient.js +3 -1
- package/dist-cjs/lib/utils/sync/TLLocalSyncClient.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 +259 -60
- package/dist-esm/index.mjs +9 -1
- package/dist-esm/index.mjs.map +2 -2
- package/dist-esm/lib/components/default-components/DefaultCanvas.mjs +2 -5
- package/dist-esm/lib/components/default-components/DefaultCanvas.mjs.map +2 -2
- package/dist-esm/lib/config/TLSessionStateSnapshot.mjs.map +2 -2
- package/dist-esm/lib/config/createTLStore.mjs +4 -2
- package/dist-esm/lib/config/createTLStore.mjs.map +2 -2
- package/dist-esm/lib/editor/Editor.mjs +98 -23
- package/dist-esm/lib/editor/Editor.mjs.map +2 -2
- package/dist-esm/lib/editor/managers/SnapManager/BoundsSnaps.mjs.map +2 -2
- package/dist-esm/lib/editor/managers/TextManager.mjs +1 -0
- package/dist-esm/lib/editor/managers/TextManager.mjs.map +2 -2
- package/dist-esm/lib/editor/shapes/ShapeUtil.mjs.map +2 -2
- package/dist-esm/lib/editor/shapes/shared/resizeScaled.mjs +46 -0
- package/dist-esm/lib/editor/shapes/shared/resizeScaled.mjs.map +7 -0
- package/dist-esm/lib/editor/types/SvgExportContext.mjs.map +2 -2
- package/dist-esm/lib/exports/StyleEmbedder.mjs.map +2 -2
- package/dist-esm/lib/exports/exportToSvg.mjs.map +2 -2
- package/dist-esm/lib/exports/getSvgAsImage.mjs +63 -0
- package/dist-esm/lib/exports/getSvgAsImage.mjs.map +7 -0
- package/dist-esm/lib/exports/getSvgJsx.mjs +16 -3
- package/dist-esm/lib/exports/getSvgJsx.mjs.map +2 -2
- package/dist-esm/lib/hooks/useDocumentEvents.mjs +2 -4
- package/dist-esm/lib/hooks/useDocumentEvents.mjs.map +2 -2
- package/dist-esm/lib/hooks/useLocalStore.mjs +1 -1
- package/dist-esm/lib/hooks/useLocalStore.mjs.map +2 -2
- package/dist-esm/lib/hooks/usePassThroughWheelEvents.mjs +4 -0
- package/dist-esm/lib/hooks/usePassThroughWheelEvents.mjs.map +3 -3
- package/dist-esm/lib/options.mjs +3 -1
- package/dist-esm/lib/options.mjs.map +2 -2
- package/dist-esm/lib/utils/browserCanvasMaxSize.mjs +45 -0
- package/dist-esm/lib/utils/browserCanvasMaxSize.mjs.map +7 -0
- package/dist-esm/lib/utils/dom.mjs +6 -0
- package/dist-esm/lib/utils/dom.mjs.map +2 -2
- package/dist-esm/lib/utils/sync/TLLocalSyncClient.mjs +3 -1
- package/dist-esm/lib/utils/sync/TLLocalSyncClient.mjs.map +2 -2
- package/dist-esm/version.mjs +3 -3
- package/dist-esm/version.mjs.map +1 -1
- package/editor.css +2 -1
- package/package.json +22 -20
- package/src/index.ts +20 -1
- package/src/lib/components/default-components/DefaultCanvas.tsx +2 -5
- package/src/lib/config/TLSessionStateSnapshot.ts +3 -1
- package/src/lib/config/createTLStore.ts +4 -2
- package/src/lib/editor/Editor.ts +147 -57
- package/src/lib/editor/managers/SnapManager/BoundsSnaps.ts +4 -4
- package/src/lib/editor/managers/TextManager.ts +1 -0
- package/src/lib/editor/shapes/ShapeUtil.ts +30 -1
- package/src/lib/editor/shapes/shared/resizeScaled.ts +61 -0
- package/src/lib/editor/types/SvgExportContext.tsx +21 -0
- package/src/lib/editor/types/emit-types.ts +1 -0
- package/src/lib/editor/types/external-content.ts +90 -50
- package/src/lib/editor/types/misc-types.ts +55 -2
- package/src/lib/exports/StyleEmbedder.ts +1 -1
- package/src/lib/exports/exportToSvg.tsx +2 -2
- package/src/lib/exports/getSvgAsImage.ts +92 -0
- package/src/lib/exports/getSvgJsx.tsx +17 -2
- package/src/lib/hooks/useDocumentEvents.ts +2 -11
- package/src/lib/hooks/useLocalStore.ts +1 -1
- package/src/lib/hooks/usePassThroughWheelEvents.ts +7 -0
- package/src/lib/options.ts +11 -0
- package/src/lib/utils/browserCanvasMaxSize.ts +65 -0
- package/src/lib/utils/dom.ts +12 -0
- package/src/lib/utils/sync/TLLocalSyncClient.ts +3 -1
- package/src/version.ts +3 -3
|
@@ -111,6 +111,7 @@ import {
|
|
|
111
111
|
ZOOM_TO_FIT_PADDING
|
|
112
112
|
} from "../constants.mjs";
|
|
113
113
|
import { exportToSvg } from "../exports/exportToSvg.mjs";
|
|
114
|
+
import { getSvgAsImage } from "../exports/getSvgAsImage.mjs";
|
|
114
115
|
import { tlenv } from "../globals/environment.mjs";
|
|
115
116
|
import { tlmenus } from "../globals/menus.mjs";
|
|
116
117
|
import { tltime } from "../globals/time.mjs";
|
|
@@ -838,6 +839,10 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
838
839
|
assert(shapeUtil, `No shape util found for type "${type}"`);
|
|
839
840
|
return shapeUtil;
|
|
840
841
|
}
|
|
842
|
+
hasShapeUtil(arg) {
|
|
843
|
+
const type = typeof arg === "string" ? arg : arg.type;
|
|
844
|
+
return hasOwnProperty(this.shapeUtils, type);
|
|
845
|
+
}
|
|
841
846
|
getBindingUtil(arg) {
|
|
842
847
|
const type = typeof arg === "string" ? arg : arg.type;
|
|
843
848
|
const bindingUtil = getOwnProperty(this.bindingUtils, type);
|
|
@@ -1064,9 +1069,20 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
1064
1069
|
},
|
|
1065
1070
|
extras: {
|
|
1066
1071
|
activeStateNode: this.root.getPath(),
|
|
1067
|
-
selectedShapes: this.getSelectedShapes()
|
|
1072
|
+
selectedShapes: this.getSelectedShapes().map((s) => {
|
|
1073
|
+
const { props, ...rest } = s;
|
|
1074
|
+
const { text: _text, richText: _richText, ...restProps } = props;
|
|
1075
|
+
return {
|
|
1076
|
+
...rest,
|
|
1077
|
+
props: restProps
|
|
1078
|
+
};
|
|
1079
|
+
}),
|
|
1080
|
+
selectionCount: this.getSelectedShapes().length,
|
|
1068
1081
|
editingShape: editingShapeId ? this.getShape(editingShapeId) : void 0,
|
|
1069
|
-
inputs: this.inputs
|
|
1082
|
+
inputs: this.inputs,
|
|
1083
|
+
pageState: this.getCurrentPageState(),
|
|
1084
|
+
instanceState: this.getInstanceState(),
|
|
1085
|
+
collaboratorCount: this.getCollaboratorsOnCurrentPage().length
|
|
1070
1086
|
}
|
|
1071
1087
|
};
|
|
1072
1088
|
} catch {
|
|
@@ -1174,8 +1190,8 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
1174
1190
|
*
|
|
1175
1191
|
* @example
|
|
1176
1192
|
* ```ts
|
|
1177
|
-
*
|
|
1178
|
-
*
|
|
1193
|
+
* editor.getStateDescendant('select')
|
|
1194
|
+
* editor.getStateDescendant('select.brushing')
|
|
1179
1195
|
* ```
|
|
1180
1196
|
*
|
|
1181
1197
|
* @param path - The descendant's path of state ids, separated by periods.
|
|
@@ -1229,7 +1245,7 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
1229
1245
|
if (partial.isChangingStyle === true) {
|
|
1230
1246
|
this._isChangingStyleTimeout = this.timers.setTimeout(() => {
|
|
1231
1247
|
this._updateInstanceState({ isChangingStyle: false }, { history: "ignore" });
|
|
1232
|
-
},
|
|
1248
|
+
}, 1e3);
|
|
1233
1249
|
}
|
|
1234
1250
|
}
|
|
1235
1251
|
return this;
|
|
@@ -3180,11 +3196,14 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
3180
3196
|
if (!assetId) return null;
|
|
3181
3197
|
const asset = this.getAsset(assetId);
|
|
3182
3198
|
if (!asset) return null;
|
|
3183
|
-
const {
|
|
3199
|
+
const {
|
|
3200
|
+
screenScale = 1,
|
|
3201
|
+
shouldResolveToOriginal = false,
|
|
3202
|
+
dpr = this.getInstanceState().devicePixelRatio
|
|
3203
|
+
} = context;
|
|
3184
3204
|
const zoomStepFunction = (zoom) => Math.pow(2, Math.ceil(Math.log2(zoom)));
|
|
3185
|
-
const steppedScreenScale =
|
|
3205
|
+
const steppedScreenScale = zoomStepFunction(screenScale);
|
|
3186
3206
|
const networkEffectiveType = "connection" in navigator ? navigator.connection.effectiveType : null;
|
|
3187
|
-
const dpr = this.getInstanceState().devicePixelRatio;
|
|
3188
3207
|
return await this.store.props.assets.resolve(asset, {
|
|
3189
3208
|
screenScale: screenScale || 1,
|
|
3190
3209
|
steppedScreenScale,
|
|
@@ -5105,6 +5124,7 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
5105
5124
|
scale = new Vec(Math.sign(scale.x) * Math.abs(scale.y), scale.y);
|
|
5106
5125
|
}
|
|
5107
5126
|
}
|
|
5127
|
+
let didResize = false;
|
|
5108
5128
|
if (util.onResize && util.canResize(initialShape)) {
|
|
5109
5129
|
const newPagePoint = this._scalePagePoint(
|
|
5110
5130
|
Mat.applyToPoint(pageTransform, new Vec(0, 0)),
|
|
@@ -5129,24 +5149,28 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
5129
5149
|
util.onResizeStart?.(initialShape) ?? void 0
|
|
5130
5150
|
);
|
|
5131
5151
|
}
|
|
5152
|
+
const resizedShape = util.onResize(
|
|
5153
|
+
{ ...initialShape, x, y },
|
|
5154
|
+
{
|
|
5155
|
+
newPoint: newLocalPoint,
|
|
5156
|
+
handle: opts.dragHandle ?? "bottom_right",
|
|
5157
|
+
// don't set isSingle to true for children
|
|
5158
|
+
mode: opts.mode ?? "scale_shape",
|
|
5159
|
+
scaleX: myScale.x,
|
|
5160
|
+
scaleY: myScale.y,
|
|
5161
|
+
initialBounds,
|
|
5162
|
+
initialShape
|
|
5163
|
+
}
|
|
5164
|
+
);
|
|
5165
|
+
if (resizedShape) {
|
|
5166
|
+
didResize = true;
|
|
5167
|
+
}
|
|
5132
5168
|
workingShape = applyPartialToRecordWithProps(workingShape, {
|
|
5133
5169
|
id,
|
|
5134
5170
|
type: initialShape.type,
|
|
5135
5171
|
x: newLocalPoint.x,
|
|
5136
5172
|
y: newLocalPoint.y,
|
|
5137
|
-
...
|
|
5138
|
-
{ ...initialShape, x, y },
|
|
5139
|
-
{
|
|
5140
|
-
newPoint: newLocalPoint,
|
|
5141
|
-
handle: opts.dragHandle ?? "bottom_right",
|
|
5142
|
-
// don't set isSingle to true for children
|
|
5143
|
-
mode: opts.mode ?? "scale_shape",
|
|
5144
|
-
scaleX: myScale.x,
|
|
5145
|
-
scaleY: myScale.y,
|
|
5146
|
-
initialBounds,
|
|
5147
|
-
initialShape
|
|
5148
|
-
}
|
|
5149
|
-
)
|
|
5173
|
+
...resizedShape
|
|
5150
5174
|
});
|
|
5151
5175
|
if (!opts.skipStartAndEndCallbacks) {
|
|
5152
5176
|
workingShape = applyPartialToRecordWithProps(
|
|
@@ -5155,7 +5179,8 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
5155
5179
|
);
|
|
5156
5180
|
}
|
|
5157
5181
|
this.updateShapes([workingShape]);
|
|
5158
|
-
}
|
|
5182
|
+
}
|
|
5183
|
+
if (!didResize) {
|
|
5159
5184
|
const initialPageCenter = Mat.applyToPoint(pageTransform, initialBounds.center);
|
|
5160
5185
|
const newPageCenter = this._scalePagePoint(
|
|
5161
5186
|
initialPageCenter,
|
|
@@ -6302,7 +6327,7 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
6302
6327
|
* @public
|
|
6303
6328
|
*/
|
|
6304
6329
|
async getSvgElement(shapes, opts = {}) {
|
|
6305
|
-
const ids = typeof shapes[0] === "string" ? shapes : shapes.map((s) => s.id);
|
|
6330
|
+
const ids = shapes.length === 0 ? this.getCurrentPageShapeIdsSorted() : typeof shapes[0] === "string" ? shapes : shapes.map((s) => s.id);
|
|
6306
6331
|
if (ids.length === 0) return void 0;
|
|
6307
6332
|
return exportToSvg(this, ids, opts);
|
|
6308
6333
|
}
|
|
@@ -6332,6 +6357,55 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
6332
6357
|
if (!result) return void 0;
|
|
6333
6358
|
return result.svg;
|
|
6334
6359
|
}
|
|
6360
|
+
/**
|
|
6361
|
+
* Get an exported image of the given shapes.
|
|
6362
|
+
*
|
|
6363
|
+
* @param shapes - The shapes (or shape ids) to export.
|
|
6364
|
+
* @param opts - Options for the export.
|
|
6365
|
+
*
|
|
6366
|
+
* @returns A blob of the image.
|
|
6367
|
+
* @public
|
|
6368
|
+
*/
|
|
6369
|
+
async toImage(shapes, opts = {}) {
|
|
6370
|
+
const withDefaults = {
|
|
6371
|
+
format: "png",
|
|
6372
|
+
scale: 1,
|
|
6373
|
+
pixelRatio: opts.format === "svg" ? void 0 : 2,
|
|
6374
|
+
...opts
|
|
6375
|
+
};
|
|
6376
|
+
const result = await this.getSvgString(shapes, withDefaults);
|
|
6377
|
+
if (!result) throw new Error("Could not create SVG");
|
|
6378
|
+
switch (withDefaults.format) {
|
|
6379
|
+
case "svg":
|
|
6380
|
+
return {
|
|
6381
|
+
blob: new Blob([result.svg], { type: "text/plain" }),
|
|
6382
|
+
width: result.width,
|
|
6383
|
+
height: result.height
|
|
6384
|
+
};
|
|
6385
|
+
case "jpeg":
|
|
6386
|
+
case "png":
|
|
6387
|
+
case "webp": {
|
|
6388
|
+
const blob = await getSvgAsImage(result.svg, {
|
|
6389
|
+
type: withDefaults.format,
|
|
6390
|
+
quality: withDefaults.quality,
|
|
6391
|
+
pixelRatio: withDefaults.pixelRatio,
|
|
6392
|
+
width: result.width,
|
|
6393
|
+
height: result.height
|
|
6394
|
+
});
|
|
6395
|
+
if (!blob) {
|
|
6396
|
+
throw new Error("Could not construct image.");
|
|
6397
|
+
}
|
|
6398
|
+
return {
|
|
6399
|
+
blob,
|
|
6400
|
+
width: result.width,
|
|
6401
|
+
height: result.height
|
|
6402
|
+
};
|
|
6403
|
+
}
|
|
6404
|
+
default: {
|
|
6405
|
+
exhaustiveSwitchError(withDefaults.format);
|
|
6406
|
+
}
|
|
6407
|
+
}
|
|
6408
|
+
}
|
|
6335
6409
|
/**
|
|
6336
6410
|
* Update the input points from a pointer, pinch, or wheel event.
|
|
6337
6411
|
*
|
|
@@ -6825,6 +6899,7 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
6825
6899
|
}
|
|
6826
6900
|
_flushEventForTick(info) {
|
|
6827
6901
|
if (this.getCrashingError()) return this;
|
|
6902
|
+
this.emit("before-event", info);
|
|
6828
6903
|
const { inputs } = this;
|
|
6829
6904
|
const { type } = info;
|
|
6830
6905
|
if (info.type === "misc") {
|