@tldraw/editor 3.8.0-canary.d24380aab845 → 3.8.0-canary.d4f1bcb032ef
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 +48 -149
- package/dist-cjs/index.js +8 -10
- package/dist-cjs/index.js.map +2 -2
- package/dist-cjs/lib/components/default-components/DefaultCanvas.js +1 -1
- 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/editor/Editor.js +16 -27
- 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 +0 -1
- 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/types/emit-types.js.map +1 -1
- package/dist-cjs/lib/editor/types/external-content.js.map +1 -1
- package/dist-cjs/lib/exports/StyleEmbedder.js.map +2 -2
- package/dist-cjs/lib/hooks/usePassThroughWheelEvents.js +0 -4
- package/dist-cjs/lib/hooks/usePassThroughWheelEvents.js.map +3 -3
- package/dist-cjs/lib/options.js +1 -3
- package/dist-cjs/lib/options.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 +48 -149
- package/dist-esm/index.mjs +1 -3
- package/dist-esm/index.mjs.map +2 -2
- package/dist-esm/lib/components/default-components/DefaultCanvas.mjs +1 -1
- 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/editor/Editor.mjs +16 -27
- 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 +0 -1
- 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/exports/StyleEmbedder.mjs.map +2 -2
- package/dist-esm/lib/hooks/usePassThroughWheelEvents.mjs +0 -4
- package/dist-esm/lib/hooks/usePassThroughWheelEvents.mjs.map +3 -3
- package/dist-esm/lib/options.mjs +1 -3
- package/dist-esm/lib/options.mjs.map +2 -2
- package/dist-esm/version.mjs +3 -3
- package/dist-esm/version.mjs.map +1 -1
- package/editor.css +1 -2
- package/package.json +20 -20
- package/src/index.ts +1 -15
- package/src/lib/components/default-components/DefaultCanvas.tsx +1 -1
- package/src/lib/config/TLSessionStateSnapshot.ts +1 -3
- package/src/lib/editor/Editor.ts +32 -59
- package/src/lib/editor/managers/SnapManager/BoundsSnaps.ts +4 -4
- package/src/lib/editor/managers/TextManager.ts +0 -1
- package/src/lib/editor/shapes/ShapeUtil.ts +1 -30
- package/src/lib/editor/types/emit-types.ts +0 -1
- package/src/lib/editor/types/external-content.ts +50 -90
- package/src/lib/exports/StyleEmbedder.ts +1 -1
- package/src/lib/hooks/usePassThroughWheelEvents.ts +0 -7
- package/src/lib/options.ts +0 -11
- package/src/version.ts +3 -3
- package/dist-cjs/lib/editor/shapes/shared/resizeScaled.js +0 -66
- package/dist-cjs/lib/editor/shapes/shared/resizeScaled.js.map +0 -7
- package/dist-esm/lib/editor/shapes/shared/resizeScaled.mjs +0 -46
- package/dist-esm/lib/editor/shapes/shared/resizeScaled.mjs.map +0 -7
- package/src/lib/editor/shapes/shared/resizeScaled.ts +0 -61
|
@@ -2,97 +2,57 @@ import { TLAssetId } from '@tldraw/tlschema'
|
|
|
2
2
|
import { VecLike } from '../../primitives/Vec'
|
|
3
3
|
import { TLContent } from './clipboard-types'
|
|
4
4
|
|
|
5
|
-
/** @public */
|
|
6
|
-
export interface TLTldrawExternalContentSource {
|
|
7
|
-
type: 'tldraw'
|
|
8
|
-
data: TLContent
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
/** @public */
|
|
12
|
-
export interface TLExcalidrawExternalContentSource {
|
|
13
|
-
type: 'excalidraw'
|
|
14
|
-
data: any
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/** @public */
|
|
18
|
-
export interface TLTextExternalContentSource {
|
|
19
|
-
type: 'text'
|
|
20
|
-
data: string
|
|
21
|
-
subtype: 'json' | 'html' | 'text' | 'url'
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/** @public */
|
|
25
|
-
export interface TLErrorExternalContentSource {
|
|
26
|
-
type: 'error'
|
|
27
|
-
data: string | null
|
|
28
|
-
reason: string
|
|
29
|
-
}
|
|
30
|
-
|
|
31
5
|
/** @public */
|
|
32
6
|
export type TLExternalContentSource =
|
|
33
|
-
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
7
|
+
| {
|
|
8
|
+
type: 'tldraw'
|
|
9
|
+
data: TLContent
|
|
10
|
+
}
|
|
11
|
+
| {
|
|
12
|
+
type: 'excalidraw'
|
|
13
|
+
data: any
|
|
14
|
+
}
|
|
15
|
+
| {
|
|
16
|
+
type: 'text'
|
|
17
|
+
data: string
|
|
18
|
+
subtype: 'json' | 'html' | 'text' | 'url'
|
|
19
|
+
}
|
|
20
|
+
| {
|
|
21
|
+
type: 'error'
|
|
22
|
+
data: string | null
|
|
23
|
+
reason: string
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** @public */
|
|
27
|
+
export type TLExternalContent<EmbedDefinition> = {
|
|
40
28
|
sources?: TLExternalContentSource[]
|
|
41
29
|
point?: VecLike
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
type: 'embed'
|
|
72
|
-
url: string
|
|
73
|
-
embed: EmbedDefinition
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/** @public */
|
|
77
|
-
export type TLExternalContent<EmbedDefinition> =
|
|
78
|
-
| TLTextExternalContent
|
|
79
|
-
| TLFilesExternalContent
|
|
80
|
-
| TLUrlExternalContent
|
|
81
|
-
| TLSvgTextExternalContent
|
|
82
|
-
| TLEmbedExternalContent<EmbedDefinition>
|
|
83
|
-
|
|
84
|
-
/** @public */
|
|
85
|
-
export interface TLFileExternalAsset {
|
|
86
|
-
type: 'file'
|
|
87
|
-
file: File
|
|
88
|
-
assetId?: TLAssetId
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/** @public */
|
|
92
|
-
export interface TLUrlExternalAsset {
|
|
93
|
-
type: 'url'
|
|
94
|
-
url: string
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
/** @public */
|
|
98
|
-
export type TLExternalAsset = TLFileExternalAsset | TLUrlExternalAsset
|
|
30
|
+
} & (
|
|
31
|
+
| {
|
|
32
|
+
type: 'text'
|
|
33
|
+
text: string
|
|
34
|
+
}
|
|
35
|
+
| {
|
|
36
|
+
type: 'files'
|
|
37
|
+
files: File[]
|
|
38
|
+
ignoreParent: boolean
|
|
39
|
+
}
|
|
40
|
+
| {
|
|
41
|
+
type: 'url'
|
|
42
|
+
url: string
|
|
43
|
+
}
|
|
44
|
+
| {
|
|
45
|
+
type: 'svg-text'
|
|
46
|
+
text: string
|
|
47
|
+
}
|
|
48
|
+
| {
|
|
49
|
+
type: 'embed'
|
|
50
|
+
url: string
|
|
51
|
+
embed: EmbedDefinition
|
|
52
|
+
}
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
/** @public */
|
|
56
|
+
export type TLExternalAssetContent =
|
|
57
|
+
| { type: 'file'; file: File; assetId?: TLAssetId }
|
|
58
|
+
| { type: 'url'; url: string }
|
|
@@ -54,7 +54,7 @@ export class StyleEmbedder {
|
|
|
54
54
|
: NO_STYLES
|
|
55
55
|
|
|
56
56
|
const parentStyles = shouldSkipInheritedParentStyles
|
|
57
|
-
?
|
|
57
|
+
? this.styles.get(element.parentElement as Element)?.self ?? NO_STYLES
|
|
58
58
|
: NO_STYLES
|
|
59
59
|
|
|
60
60
|
const info: ElementStyleInfo = {
|
|
@@ -11,13 +11,6 @@ export function usePassThroughWheelEvents(ref: RefObject<HTMLElement>) {
|
|
|
11
11
|
useEffect(() => {
|
|
12
12
|
function onWheel(e: WheelEvent) {
|
|
13
13
|
if ((e as any).isSpecialRedispatchedEvent) return
|
|
14
|
-
|
|
15
|
-
// if the element is scrollable, don't redispatch the event
|
|
16
|
-
const elm = ref.current
|
|
17
|
-
if (elm && elm.scrollHeight > elm.clientHeight) {
|
|
18
|
-
return
|
|
19
|
-
}
|
|
20
|
-
|
|
21
14
|
preventDefault(e)
|
|
22
15
|
const cvs = container.querySelector('.tl-canvas')
|
|
23
16
|
if (!cvs) return
|
package/src/lib/options.ts
CHANGED
|
@@ -66,15 +66,6 @@ export interface TldrawOptions {
|
|
|
66
66
|
* external context providers. By default, this is `React.Fragment`.
|
|
67
67
|
*/
|
|
68
68
|
readonly exportProvider: ComponentType<{ children: React.ReactNode }>
|
|
69
|
-
/**
|
|
70
|
-
* How should the note shape resize? By default it does not resize (except automatically based on its text content),
|
|
71
|
-
* but you can set it to be user-resizable using scale.
|
|
72
|
-
*/
|
|
73
|
-
readonly noteShapeResizeMode: 'none' | 'scale'
|
|
74
|
-
/**
|
|
75
|
-
* By default, the toolbar items are accessible via number shortcuts according to their order. To disable this, set this option to false.
|
|
76
|
-
*/
|
|
77
|
-
readonly enableToolbarKeyboardShortcuts: boolean
|
|
78
69
|
}
|
|
79
70
|
|
|
80
71
|
/** @public */
|
|
@@ -120,6 +111,4 @@ export const defaultTldrawOptions = {
|
|
|
120
111
|
actionShortcutsLocation: 'swap',
|
|
121
112
|
createTextOnCanvasDoubleClick: true,
|
|
122
113
|
exportProvider: Fragment,
|
|
123
|
-
noteShapeResizeMode: 'none',
|
|
124
|
-
enableToolbarKeyboardShortcuts: true,
|
|
125
114
|
} as const satisfies TldrawOptions
|
package/src/version.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// This file is automatically generated by internal/scripts/refresh-assets.ts.
|
|
2
2
|
// Do not edit manually. Or do, I'm a comment, not a cop.
|
|
3
3
|
|
|
4
|
-
export const version = '3.8.0-canary.
|
|
4
|
+
export const version = '3.8.0-canary.d4f1bcb032ef'
|
|
5
5
|
export const publishDates = {
|
|
6
6
|
major: '2024-09-13T14:36:29.063Z',
|
|
7
|
-
minor: '2025-
|
|
8
|
-
patch: '2025-
|
|
7
|
+
minor: '2025-01-28T10:33:45.853Z',
|
|
8
|
+
patch: '2025-01-28T10:33:45.853Z',
|
|
9
9
|
}
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var resizeScaled_exports = {};
|
|
20
|
-
__export(resizeScaled_exports, {
|
|
21
|
-
resizeScaled: () => resizeScaled
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(resizeScaled_exports);
|
|
24
|
-
var import_utils = require("@tldraw/utils");
|
|
25
|
-
var import_Vec = require("../../../primitives/Vec");
|
|
26
|
-
function resizeScaled(shape, { initialBounds, scaleX, scaleY, newPoint, handle }) {
|
|
27
|
-
let scaleDelta;
|
|
28
|
-
switch (handle) {
|
|
29
|
-
case "bottom_left":
|
|
30
|
-
case "bottom_right":
|
|
31
|
-
case "top_left":
|
|
32
|
-
case "top_right": {
|
|
33
|
-
scaleDelta = Math.max(0.01, Math.max(Math.abs(scaleX), Math.abs(scaleY)));
|
|
34
|
-
break;
|
|
35
|
-
}
|
|
36
|
-
case "left":
|
|
37
|
-
case "right": {
|
|
38
|
-
scaleDelta = Math.max(0.01, Math.abs(scaleX));
|
|
39
|
-
break;
|
|
40
|
-
}
|
|
41
|
-
case "bottom":
|
|
42
|
-
case "top": {
|
|
43
|
-
scaleDelta = Math.max(0.01, Math.abs(scaleY));
|
|
44
|
-
break;
|
|
45
|
-
}
|
|
46
|
-
default: {
|
|
47
|
-
throw (0, import_utils.exhaustiveSwitchError)(handle);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
const offset = new import_Vec.Vec(0, 0);
|
|
51
|
-
if (scaleX < 0) {
|
|
52
|
-
offset.x = -(initialBounds.width * scaleDelta);
|
|
53
|
-
}
|
|
54
|
-
if (scaleY < 0) {
|
|
55
|
-
offset.y = -(initialBounds.height * scaleDelta);
|
|
56
|
-
}
|
|
57
|
-
const { x, y } = import_Vec.Vec.Add(newPoint, offset.rot(shape.rotation));
|
|
58
|
-
return {
|
|
59
|
-
x,
|
|
60
|
-
y,
|
|
61
|
-
props: {
|
|
62
|
-
scale: scaleDelta * shape.props.scale
|
|
63
|
-
}
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
//# sourceMappingURL=resizeScaled.js.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../../../src/lib/editor/shapes/shared/resizeScaled.ts"],
|
|
4
|
-
"sourcesContent": ["import { TLBaseShape } from '@tldraw/tlschema'\nimport { exhaustiveSwitchError } from '@tldraw/utils'\nimport { Vec } from '../../../primitives/Vec'\nimport { TLResizeInfo } from '../ShapeUtil'\n\n/**\n * Resize a shape that has a scale prop.\n *\n * @param shape - The shape to resize\n * @param info - The resize info\n *\n * @public */\nexport function resizeScaled(\n\tshape: TLBaseShape<any, { scale: number }>,\n\t{ initialBounds, scaleX, scaleY, newPoint, handle }: TLResizeInfo<any>\n) {\n\tlet scaleDelta: number\n\tswitch (handle) {\n\t\tcase 'bottom_left':\n\t\tcase 'bottom_right':\n\t\tcase 'top_left':\n\t\tcase 'top_right': {\n\t\t\tscaleDelta = Math.max(0.01, Math.max(Math.abs(scaleX), Math.abs(scaleY)))\n\t\t\tbreak\n\t\t}\n\t\tcase 'left':\n\t\tcase 'right': {\n\t\t\tscaleDelta = Math.max(0.01, Math.abs(scaleX))\n\t\t\tbreak\n\t\t}\n\t\tcase 'bottom':\n\t\tcase 'top': {\n\t\t\tscaleDelta = Math.max(0.01, Math.abs(scaleY))\n\t\t\tbreak\n\t\t}\n\t\tdefault: {\n\t\t\tthrow exhaustiveSwitchError(handle)\n\t\t}\n\t}\n\n\t// Compute the offset (if flipped X or flipped Y)\n\tconst offset = new Vec(0, 0)\n\n\tif (scaleX < 0) {\n\t\toffset.x = -(initialBounds.width * scaleDelta)\n\t}\n\tif (scaleY < 0) {\n\t\toffset.y = -(initialBounds.height * scaleDelta)\n\t}\n\n\t// Apply the offset to the new point\n\tconst { x, y } = Vec.Add(newPoint, offset.rot(shape.rotation))\n\n\treturn {\n\t\tx,\n\t\ty,\n\t\tprops: {\n\t\t\tscale: scaleDelta * shape.props.scale,\n\t\t},\n\t}\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAAsC;AACtC,iBAAoB;AAUb,SAAS,aACf,OACA,EAAE,eAAe,QAAQ,QAAQ,UAAU,OAAO,GACjD;AACD,MAAI;AACJ,UAAQ,QAAQ;AAAA,IACf,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK,aAAa;AACjB,mBAAa,KAAK,IAAI,MAAM,KAAK,IAAI,KAAK,IAAI,MAAM,GAAG,KAAK,IAAI,MAAM,CAAC,CAAC;AACxE;AAAA,IACD;AAAA,IACA,KAAK;AAAA,IACL,KAAK,SAAS;AACb,mBAAa,KAAK,IAAI,MAAM,KAAK,IAAI,MAAM,CAAC;AAC5C;AAAA,IACD;AAAA,IACA,KAAK;AAAA,IACL,KAAK,OAAO;AACX,mBAAa,KAAK,IAAI,MAAM,KAAK,IAAI,MAAM,CAAC;AAC5C;AAAA,IACD;AAAA,IACA,SAAS;AACR,gBAAM,oCAAsB,MAAM;AAAA,IACnC;AAAA,EACD;AAGA,QAAM,SAAS,IAAI,eAAI,GAAG,CAAC;AAE3B,MAAI,SAAS,GAAG;AACf,WAAO,IAAI,EAAE,cAAc,QAAQ;AAAA,EACpC;AACA,MAAI,SAAS,GAAG;AACf,WAAO,IAAI,EAAE,cAAc,SAAS;AAAA,EACrC;AAGA,QAAM,EAAE,GAAG,EAAE,IAAI,eAAI,IAAI,UAAU,OAAO,IAAI,MAAM,QAAQ,CAAC;AAE7D,SAAO;AAAA,IACN;AAAA,IACA;AAAA,IACA,OAAO;AAAA,MACN,OAAO,aAAa,MAAM,MAAM;AAAA,IACjC;AAAA,EACD;AACD;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { exhaustiveSwitchError } from "@tldraw/utils";
|
|
2
|
-
import { Vec } from "../../../primitives/Vec.mjs";
|
|
3
|
-
function resizeScaled(shape, { initialBounds, scaleX, scaleY, newPoint, handle }) {
|
|
4
|
-
let scaleDelta;
|
|
5
|
-
switch (handle) {
|
|
6
|
-
case "bottom_left":
|
|
7
|
-
case "bottom_right":
|
|
8
|
-
case "top_left":
|
|
9
|
-
case "top_right": {
|
|
10
|
-
scaleDelta = Math.max(0.01, Math.max(Math.abs(scaleX), Math.abs(scaleY)));
|
|
11
|
-
break;
|
|
12
|
-
}
|
|
13
|
-
case "left":
|
|
14
|
-
case "right": {
|
|
15
|
-
scaleDelta = Math.max(0.01, Math.abs(scaleX));
|
|
16
|
-
break;
|
|
17
|
-
}
|
|
18
|
-
case "bottom":
|
|
19
|
-
case "top": {
|
|
20
|
-
scaleDelta = Math.max(0.01, Math.abs(scaleY));
|
|
21
|
-
break;
|
|
22
|
-
}
|
|
23
|
-
default: {
|
|
24
|
-
throw exhaustiveSwitchError(handle);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
const offset = new Vec(0, 0);
|
|
28
|
-
if (scaleX < 0) {
|
|
29
|
-
offset.x = -(initialBounds.width * scaleDelta);
|
|
30
|
-
}
|
|
31
|
-
if (scaleY < 0) {
|
|
32
|
-
offset.y = -(initialBounds.height * scaleDelta);
|
|
33
|
-
}
|
|
34
|
-
const { x, y } = Vec.Add(newPoint, offset.rot(shape.rotation));
|
|
35
|
-
return {
|
|
36
|
-
x,
|
|
37
|
-
y,
|
|
38
|
-
props: {
|
|
39
|
-
scale: scaleDelta * shape.props.scale
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
export {
|
|
44
|
-
resizeScaled
|
|
45
|
-
};
|
|
46
|
-
//# sourceMappingURL=resizeScaled.mjs.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../../../src/lib/editor/shapes/shared/resizeScaled.ts"],
|
|
4
|
-
"sourcesContent": ["import { TLBaseShape } from '@tldraw/tlschema'\nimport { exhaustiveSwitchError } from '@tldraw/utils'\nimport { Vec } from '../../../primitives/Vec'\nimport { TLResizeInfo } from '../ShapeUtil'\n\n/**\n * Resize a shape that has a scale prop.\n *\n * @param shape - The shape to resize\n * @param info - The resize info\n *\n * @public */\nexport function resizeScaled(\n\tshape: TLBaseShape<any, { scale: number }>,\n\t{ initialBounds, scaleX, scaleY, newPoint, handle }: TLResizeInfo<any>\n) {\n\tlet scaleDelta: number\n\tswitch (handle) {\n\t\tcase 'bottom_left':\n\t\tcase 'bottom_right':\n\t\tcase 'top_left':\n\t\tcase 'top_right': {\n\t\t\tscaleDelta = Math.max(0.01, Math.max(Math.abs(scaleX), Math.abs(scaleY)))\n\t\t\tbreak\n\t\t}\n\t\tcase 'left':\n\t\tcase 'right': {\n\t\t\tscaleDelta = Math.max(0.01, Math.abs(scaleX))\n\t\t\tbreak\n\t\t}\n\t\tcase 'bottom':\n\t\tcase 'top': {\n\t\t\tscaleDelta = Math.max(0.01, Math.abs(scaleY))\n\t\t\tbreak\n\t\t}\n\t\tdefault: {\n\t\t\tthrow exhaustiveSwitchError(handle)\n\t\t}\n\t}\n\n\t// Compute the offset (if flipped X or flipped Y)\n\tconst offset = new Vec(0, 0)\n\n\tif (scaleX < 0) {\n\t\toffset.x = -(initialBounds.width * scaleDelta)\n\t}\n\tif (scaleY < 0) {\n\t\toffset.y = -(initialBounds.height * scaleDelta)\n\t}\n\n\t// Apply the offset to the new point\n\tconst { x, y } = Vec.Add(newPoint, offset.rot(shape.rotation))\n\n\treturn {\n\t\tx,\n\t\ty,\n\t\tprops: {\n\t\t\tscale: scaleDelta * shape.props.scale,\n\t\t},\n\t}\n}\n"],
|
|
5
|
-
"mappings": "AACA,SAAS,6BAA6B;AACtC,SAAS,WAAW;AAUb,SAAS,aACf,OACA,EAAE,eAAe,QAAQ,QAAQ,UAAU,OAAO,GACjD;AACD,MAAI;AACJ,UAAQ,QAAQ;AAAA,IACf,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK,aAAa;AACjB,mBAAa,KAAK,IAAI,MAAM,KAAK,IAAI,KAAK,IAAI,MAAM,GAAG,KAAK,IAAI,MAAM,CAAC,CAAC;AACxE;AAAA,IACD;AAAA,IACA,KAAK;AAAA,IACL,KAAK,SAAS;AACb,mBAAa,KAAK,IAAI,MAAM,KAAK,IAAI,MAAM,CAAC;AAC5C;AAAA,IACD;AAAA,IACA,KAAK;AAAA,IACL,KAAK,OAAO;AACX,mBAAa,KAAK,IAAI,MAAM,KAAK,IAAI,MAAM,CAAC;AAC5C;AAAA,IACD;AAAA,IACA,SAAS;AACR,YAAM,sBAAsB,MAAM;AAAA,IACnC;AAAA,EACD;AAGA,QAAM,SAAS,IAAI,IAAI,GAAG,CAAC;AAE3B,MAAI,SAAS,GAAG;AACf,WAAO,IAAI,EAAE,cAAc,QAAQ;AAAA,EACpC;AACA,MAAI,SAAS,GAAG;AACf,WAAO,IAAI,EAAE,cAAc,SAAS;AAAA,EACrC;AAGA,QAAM,EAAE,GAAG,EAAE,IAAI,IAAI,IAAI,UAAU,OAAO,IAAI,MAAM,QAAQ,CAAC;AAE7D,SAAO;AAAA,IACN;AAAA,IACA;AAAA,IACA,OAAO;AAAA,MACN,OAAO,aAAa,MAAM,MAAM;AAAA,IACjC;AAAA,EACD;AACD;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import { TLBaseShape } from '@tldraw/tlschema'
|
|
2
|
-
import { exhaustiveSwitchError } from '@tldraw/utils'
|
|
3
|
-
import { Vec } from '../../../primitives/Vec'
|
|
4
|
-
import { TLResizeInfo } from '../ShapeUtil'
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Resize a shape that has a scale prop.
|
|
8
|
-
*
|
|
9
|
-
* @param shape - The shape to resize
|
|
10
|
-
* @param info - The resize info
|
|
11
|
-
*
|
|
12
|
-
* @public */
|
|
13
|
-
export function resizeScaled(
|
|
14
|
-
shape: TLBaseShape<any, { scale: number }>,
|
|
15
|
-
{ initialBounds, scaleX, scaleY, newPoint, handle }: TLResizeInfo<any>
|
|
16
|
-
) {
|
|
17
|
-
let scaleDelta: number
|
|
18
|
-
switch (handle) {
|
|
19
|
-
case 'bottom_left':
|
|
20
|
-
case 'bottom_right':
|
|
21
|
-
case 'top_left':
|
|
22
|
-
case 'top_right': {
|
|
23
|
-
scaleDelta = Math.max(0.01, Math.max(Math.abs(scaleX), Math.abs(scaleY)))
|
|
24
|
-
break
|
|
25
|
-
}
|
|
26
|
-
case 'left':
|
|
27
|
-
case 'right': {
|
|
28
|
-
scaleDelta = Math.max(0.01, Math.abs(scaleX))
|
|
29
|
-
break
|
|
30
|
-
}
|
|
31
|
-
case 'bottom':
|
|
32
|
-
case 'top': {
|
|
33
|
-
scaleDelta = Math.max(0.01, Math.abs(scaleY))
|
|
34
|
-
break
|
|
35
|
-
}
|
|
36
|
-
default: {
|
|
37
|
-
throw exhaustiveSwitchError(handle)
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// Compute the offset (if flipped X or flipped Y)
|
|
42
|
-
const offset = new Vec(0, 0)
|
|
43
|
-
|
|
44
|
-
if (scaleX < 0) {
|
|
45
|
-
offset.x = -(initialBounds.width * scaleDelta)
|
|
46
|
-
}
|
|
47
|
-
if (scaleY < 0) {
|
|
48
|
-
offset.y = -(initialBounds.height * scaleDelta)
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// Apply the offset to the new point
|
|
52
|
-
const { x, y } = Vec.Add(newPoint, offset.rot(shape.rotation))
|
|
53
|
-
|
|
54
|
-
return {
|
|
55
|
-
x,
|
|
56
|
-
y,
|
|
57
|
-
props: {
|
|
58
|
-
scale: scaleDelta * shape.props.scale,
|
|
59
|
-
},
|
|
60
|
-
}
|
|
61
|
-
}
|