tldraw 5.2.2 → 5.3.0-canary.26ec89c1864b
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/DOCS.md +1 -1
- package/RELEASE_NOTES.md +1 -5
- package/dist-cjs/index.js +1 -1
- package/dist-cjs/lib/bindings/arrow/ArrowBindingUtil.js +12 -1
- package/dist-cjs/lib/bindings/arrow/ArrowBindingUtil.js.map +2 -2
- package/dist-cjs/lib/shapes/arrow/toolStates/Pointing.js +1 -1
- package/dist-cjs/lib/shapes/arrow/toolStates/Pointing.js.map +2 -2
- package/dist-cjs/lib/shapes/geo/toolStates/Pointing.js +1 -1
- package/dist-cjs/lib/shapes/geo/toolStates/Pointing.js.map +2 -2
- package/dist-cjs/lib/shapes/line/LineShapeUtil.js +6 -2
- package/dist-cjs/lib/shapes/line/LineShapeUtil.js.map +2 -2
- package/dist-cjs/lib/shapes/line/toolStates/Pointing.js +1 -1
- package/dist-cjs/lib/shapes/line/toolStates/Pointing.js.map +2 -2
- package/dist-cjs/lib/shapes/note/toolStates/Pointing.js +1 -1
- package/dist-cjs/lib/shapes/note/toolStates/Pointing.js.map +2 -2
- package/dist-cjs/lib/shapes/shared/crop.js +61 -15
- package/dist-cjs/lib/shapes/shared/crop.js.map +2 -2
- package/dist-cjs/lib/shapes/text/toolStates/Pointing.js +1 -1
- package/dist-cjs/lib/shapes/text/toolStates/Pointing.js.map +2 -2
- package/dist-cjs/lib/tools/SelectTool/DragAndDropManager.js +1 -1
- package/dist-cjs/lib/tools/SelectTool/DragAndDropManager.js.map +2 -2
- package/dist-cjs/lib/tools/SelectTool/childStates/Crop/children/Cropping.js +70 -16
- package/dist-cjs/lib/tools/SelectTool/childStates/Crop/children/Cropping.js.map +2 -2
- package/dist-cjs/lib/ui/components/HelperButtons/BackToContent.js +33 -4
- package/dist-cjs/lib/ui/components/HelperButtons/BackToContent.js.map +2 -2
- package/dist-cjs/lib/ui/version.js +3 -3
- package/dist-cjs/lib/ui/version.js.map +1 -1
- package/dist-esm/index.mjs +1 -1
- package/dist-esm/lib/bindings/arrow/ArrowBindingUtil.mjs +12 -1
- package/dist-esm/lib/bindings/arrow/ArrowBindingUtil.mjs.map +2 -2
- package/dist-esm/lib/shapes/arrow/toolStates/Pointing.mjs +2 -7
- package/dist-esm/lib/shapes/arrow/toolStates/Pointing.mjs.map +2 -2
- package/dist-esm/lib/shapes/geo/toolStates/Pointing.mjs +1 -2
- package/dist-esm/lib/shapes/geo/toolStates/Pointing.mjs.map +2 -2
- package/dist-esm/lib/shapes/line/LineShapeUtil.mjs +6 -2
- package/dist-esm/lib/shapes/line/LineShapeUtil.mjs.map +2 -2
- package/dist-esm/lib/shapes/line/toolStates/Pointing.mjs +1 -2
- package/dist-esm/lib/shapes/line/toolStates/Pointing.mjs.map +2 -2
- package/dist-esm/lib/shapes/note/toolStates/Pointing.mjs +1 -2
- package/dist-esm/lib/shapes/note/toolStates/Pointing.mjs.map +2 -2
- package/dist-esm/lib/shapes/shared/crop.mjs +61 -15
- package/dist-esm/lib/shapes/shared/crop.mjs.map +2 -2
- package/dist-esm/lib/shapes/text/toolStates/Pointing.mjs +1 -2
- package/dist-esm/lib/shapes/text/toolStates/Pointing.mjs.map +2 -2
- package/dist-esm/lib/tools/SelectTool/DragAndDropManager.mjs +1 -1
- package/dist-esm/lib/tools/SelectTool/DragAndDropManager.mjs.map +2 -2
- package/dist-esm/lib/tools/SelectTool/childStates/Crop/children/Cropping.mjs +75 -17
- package/dist-esm/lib/tools/SelectTool/childStates/Crop/children/Cropping.mjs.map +2 -2
- package/dist-esm/lib/ui/components/HelperButtons/BackToContent.mjs +34 -5
- package/dist-esm/lib/ui/components/HelperButtons/BackToContent.mjs.map +2 -2
- package/dist-esm/lib/ui/version.mjs +3 -3
- package/dist-esm/lib/ui/version.mjs.map +1 -1
- package/package.json +4 -4
- package/src/lib/bindings/arrow/ArrowBindingUtil.ts +24 -2
- package/src/lib/shapes/arrow/ArrowShapeUtil.test.ts +147 -2
- package/src/lib/shapes/arrow/toolStates/Pointing.tsx +3 -8
- package/src/lib/shapes/geo/toolStates/Pointing.ts +2 -2
- package/src/lib/shapes/line/LineShapeUtil.test.tsx +121 -0
- package/src/lib/shapes/line/LineShapeUtil.tsx +10 -2
- package/src/lib/shapes/line/toolStates/Pointing.ts +2 -2
- package/src/lib/shapes/note/toolStates/Pointing.ts +2 -2
- package/src/lib/shapes/shared/crop.ts +75 -16
- package/src/lib/shapes/text/toolStates/Pointing.ts +2 -2
- package/src/lib/tools/SelectTool/DragAndDropManager.ts +5 -1
- package/src/lib/tools/SelectTool/childStates/Crop/children/Cropping.ts +103 -18
- package/src/lib/ui/components/HelperButtons/BackToContent.tsx +49 -5
- package/src/lib/ui/version.ts +3 -3
- package/src/test/crop.test.ts +141 -0
- package/src/test/cropping.test.ts +102 -0
- package/src/test/dragAndDrop.test.ts +22 -0
- package/src/test/frames.test.ts +4 -3
- package/src/test/modifiers.test.ts +16 -0
- package/src/test/shapeutils.test.ts +70 -0
- package/src/test/spatialIndex.test.ts +128 -6
- package/src/test/ui/BackToContent.test.tsx +98 -19
package/DOCS.md
CHANGED
package/RELEASE_NOTES.md
CHANGED
|
@@ -1,13 +1,9 @@
|
|
|
1
1
|
# Releases
|
|
2
2
|
|
|
3
|
-
Version: `5.
|
|
3
|
+
Version: `5.3.0-canary.26ec89c1864b`
|
|
4
4
|
|
|
5
5
|
This file is generated during package publishing from the tldraw release notes content for this exact package version.
|
|
6
6
|
|
|
7
|
-
## v5.2.2
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
7
|
## v5.2.0
|
|
12
8
|
|
|
13
9
|
[View on GitHub](https://github.com/tldraw/tldraw/releases/tag/v5.2.0)
|
package/dist-cjs/index.js
CHANGED
|
@@ -648,7 +648,7 @@ var import_buildFromV1Document = require("./lib/utils/tldr/buildFromV1Document")
|
|
|
648
648
|
var import_file = require("./lib/utils/tldr/file");
|
|
649
649
|
(0, import_editor.registerTldrawLibraryVersion)(
|
|
650
650
|
"tldraw",
|
|
651
|
-
"5.
|
|
651
|
+
"5.3.0-canary.26ec89c1864b",
|
|
652
652
|
"cjs"
|
|
653
653
|
);
|
|
654
654
|
//# sourceMappingURL=index.js.map
|
|
@@ -97,7 +97,7 @@ function reparentArrow(editor, arrowId) {
|
|
|
97
97
|
if (!parentPageId) return;
|
|
98
98
|
let nextParentId;
|
|
99
99
|
if (startShape && endShape) {
|
|
100
|
-
nextParentId = editor.findCommonAncestor([startShape, endShape]) ?? parentPageId;
|
|
100
|
+
nextParentId = getCommonFrameLikeBindingAncestor(editor, startShape, endShape) ?? editor.findCommonAncestor([startShape, endShape]) ?? parentPageId;
|
|
101
101
|
} else if (startShape || endShape) {
|
|
102
102
|
const bindingParentId = (startShape || endShape)?.parentId;
|
|
103
103
|
if (bindingParentId && bindingParentId === arrow.parentId) {
|
|
@@ -144,6 +144,17 @@ function reparentArrow(editor, arrowId) {
|
|
|
144
144
|
editor.updateShapes([{ id: arrowId, type: "arrow", index: finalIndex }]);
|
|
145
145
|
}
|
|
146
146
|
}
|
|
147
|
+
function getCommonFrameLikeBindingAncestor(editor, startShape, endShape) {
|
|
148
|
+
let ancestor;
|
|
149
|
+
if (startShape.id === endShape.id) {
|
|
150
|
+
ancestor = startShape;
|
|
151
|
+
} else if (editor.hasAncestor(startShape, endShape.id)) {
|
|
152
|
+
ancestor = endShape;
|
|
153
|
+
} else if (editor.hasAncestor(endShape, startShape.id)) {
|
|
154
|
+
ancestor = startShape;
|
|
155
|
+
}
|
|
156
|
+
return ancestor && editor.isShapeFrameLike(ancestor) ? ancestor.id : void 0;
|
|
157
|
+
}
|
|
147
158
|
function arrowDidUpdate(editor, arrow) {
|
|
148
159
|
const bindings = (0, import_shared.getArrowBindings)(editor, arrow);
|
|
149
160
|
for (const handle of ["start", "end"]) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/lib/bindings/arrow/ArrowBindingUtil.ts"],
|
|
4
|
-
"sourcesContent": ["import {\n\tBindingOnChangeOptions,\n\tBindingOnCreateOptions,\n\tBindingOnShapeChangeOptions,\n\tBindingOnShapeIsolateOptions,\n\tBindingUtil,\n\tEditor,\n\tIndexKey,\n\tTLArrowBinding,\n\tTLArrowBindingProps,\n\tTLArrowShape,\n\tTLParentId,\n\tTLShape,\n\tTLShapeId,\n\tTLShapePartial,\n\tVec,\n\tapproximately,\n\tarrowBindingMigrations,\n\tarrowBindingProps,\n\tgetIndexAbove,\n\tgetIndexBetween,\n\tintersectLineSegmentCircle,\n} from '@tldraw/editor'\nimport { getArrowInfo } from '../../shapes/arrow/getArrowInfo'\nimport { getArrowBindings, removeArrowBinding } from '../../shapes/arrow/shared'\n\n/**\n * @public\n */\nexport class ArrowBindingUtil extends BindingUtil<TLArrowBinding> {\n\tstatic override type = 'arrow'\n\n\tstatic override props = arrowBindingProps\n\tstatic override migrations = arrowBindingMigrations\n\n\toverride getDefaultProps(): Partial<TLArrowBindingProps> {\n\t\treturn {\n\t\t\tisPrecise: false,\n\t\t\tisExact: false,\n\t\t\tnormalizedAnchor: { x: 0.5, y: 0.5 },\n\t\t\tsnap: 'none',\n\t\t}\n\t}\n\n\t// when the binding itself changes\n\toverride onAfterCreate({ binding }: BindingOnCreateOptions<TLArrowBinding>): void {\n\t\tconst arrow = this.editor.getShape(binding.fromId) as TLArrowShape | undefined\n\t\tif (!arrow) return\n\t\tarrowDidUpdate(this.editor, arrow)\n\t}\n\n\t// when the binding itself changes\n\toverride onAfterChange({ bindingAfter }: BindingOnChangeOptions<TLArrowBinding>): void {\n\t\tconst arrow = this.editor.getShape(bindingAfter.fromId) as TLArrowShape | undefined\n\t\tif (!arrow) return\n\t\tarrowDidUpdate(this.editor, arrow)\n\t}\n\n\t// when the arrow itself changes\n\toverride onAfterChangeFromShape({\n\t\tshapeBefore,\n\t\tshapeAfter,\n\t\treason,\n\t}: BindingOnShapeChangeOptions<TLArrowBinding>): void {\n\t\t// When translating arrows together with their bound shapes, only x/y changes.\n\t\t// In this case, bindings remain valid and no reparenting is needed.\n\t\t// This is a significant performance optimization when moving many bound shapes.\n\t\tif (\n\t\t\treason !== 'ancestry' &&\n\t\t\tshapeBefore.parentId === shapeAfter.parentId &&\n\t\t\tshapeBefore.index === shapeAfter.index\n\t\t) {\n\t\t\treturn\n\t\t}\n\t\tarrowDidUpdate(this.editor, shapeAfter as TLArrowShape)\n\t}\n\n\t// when the shape an arrow is bound to changes\n\toverride onAfterChangeToShape({\n\t\tbinding,\n\t\tshapeBefore,\n\t\tshapeAfter,\n\t\treason,\n\t}: BindingOnShapeChangeOptions<TLArrowBinding>): void {\n\t\tif (\n\t\t\treason !== 'ancestry' &&\n\t\t\tshapeBefore.parentId === shapeAfter.parentId &&\n\t\t\tshapeBefore.index === shapeAfter.index\n\t\t) {\n\t\t\treturn\n\t\t}\n\t\treparentArrow(this.editor, binding.fromId)\n\t}\n\n\t// when the arrow is isolated we need to update its (x,y) positions\n\toverride onBeforeIsolateFromShape({\n\t\tbinding,\n\t}: BindingOnShapeIsolateOptions<TLArrowBinding>): void {\n\t\t// during undo/redo the history diff already contains the arrow's correct\n\t\t// state, so adjusting the terminal here would corrupt the replay\n\t\tif (this.editor.isReplayingHistory()) return\n\n\t\tconst arrow = this.editor.getShape<TLArrowShape>(binding.fromId)\n\t\tif (!arrow) return\n\t\tupdateArrowTerminal({\n\t\t\teditor: this.editor,\n\t\t\tarrow,\n\t\t\tterminal: binding.props.terminal,\n\t\t})\n\t}\n}\n\nfunction reparentArrow(editor: Editor, arrowId: TLShapeId) {\n\tconst arrow = editor.getShape<TLArrowShape>(arrowId)\n\tif (!arrow) return\n\tconst bindings = getArrowBindings(editor, arrow)\n\tconst { start, end } = bindings\n\tconst startShape = start ? editor.getShape(start.toId) : undefined\n\tconst endShape = end ? editor.getShape(end.toId) : undefined\n\n\tconst parentPageId = editor.getAncestorPageId(arrow)\n\tif (!parentPageId) return\n\n\tlet nextParentId: TLParentId\n\tif (startShape && endShape) {\n\t\t// if arrow has two bindings, always parent arrow to closest common ancestor of the bindings\n\t\tnextParentId = editor.findCommonAncestor([startShape, endShape]) ?? parentPageId\n\t} else if (startShape || endShape) {\n\t\tconst bindingParentId = (startShape || endShape)?.parentId\n\t\t// If the arrow and the shape that it is bound to have the same parent, then keep that parent\n\t\tif (bindingParentId && bindingParentId === arrow.parentId) {\n\t\t\tnextParentId = arrow.parentId\n\t\t} else {\n\t\t\t// if arrow has one binding, keep arrow on its own page\n\t\t\tnextParentId = parentPageId\n\t\t}\n\t} else {\n\t\treturn\n\t}\n\n\tif (nextParentId && nextParentId !== arrow.parentId) {\n\t\teditor.reparentShapes([arrowId], nextParentId)\n\t}\n\n\tconst reparentedArrow = editor.getShape<TLArrowShape>(arrowId)\n\tif (!reparentedArrow) throw Error('no reparented arrow')\n\n\tconst startSibling = editor.getShapeNearestSibling(reparentedArrow, startShape)\n\tconst endSibling = editor.getShapeNearestSibling(reparentedArrow, endShape)\n\n\tlet highestSibling: TLShape | undefined\n\n\tif (startSibling && endSibling) {\n\t\thighestSibling = startSibling.index > endSibling.index ? startSibling : endSibling\n\t} else if (startSibling && !endSibling) {\n\t\thighestSibling = startSibling\n\t} else if (endSibling && !startSibling) {\n\t\thighestSibling = endSibling\n\t} else {\n\t\treturn\n\t}\n\n\tlet finalIndex: IndexKey\n\n\tconst higherSiblings = editor\n\t\t.getSortedChildIdsForParent(highestSibling.parentId)\n\t\t.map((id) => editor.getShape(id)!)\n\t\t.filter((sibling) => sibling.index > highestSibling!.index)\n\n\tif (higherSiblings.length) {\n\t\t// there are siblings above the highest bound sibling, we need to\n\t\t// insert between them.\n\n\t\t// if the next sibling is also a bound arrow though, we can end up\n\t\t// all fighting for the same indexes. so lets find the next\n\t\t// non-arrow sibling...\n\t\tconst nextHighestNonArrowSibling = higherSiblings.find((sibling) => sibling.type !== 'arrow')\n\n\t\tif (\n\t\t\t// ...then, if we're above the last shape we want to be above...\n\t\t\treparentedArrow.index > highestSibling.index &&\n\t\t\t// ...but below the next non-arrow sibling...\n\t\t\t(!nextHighestNonArrowSibling || reparentedArrow.index < nextHighestNonArrowSibling.index)\n\t\t) {\n\t\t\t// ...then we're already in the right place. no need to update!\n\t\t\treturn\n\t\t}\n\n\t\t// otherwise, we need to find the index between the highest sibling\n\t\t// we want to be above, and the next highest sibling we want to be\n\t\t// below:\n\t\tfinalIndex = getIndexBetween(highestSibling.index, higherSiblings[0].index)\n\t} else {\n\t\t// if there are no siblings above us, we can just get the next index:\n\t\tfinalIndex = getIndexAbove(highestSibling.index)\n\t}\n\n\tif (finalIndex !== reparentedArrow.index) {\n\t\teditor.updateShapes([{ id: arrowId, type: 'arrow', index: finalIndex }])\n\t}\n}\n\nfunction arrowDidUpdate(editor: Editor, arrow: TLArrowShape) {\n\tconst bindings = getArrowBindings(editor, arrow)\n\t// if the shape is an arrow and its bound shape is on another page\n\t// or was deleted, unbind it\n\tfor (const handle of ['start', 'end'] as const) {\n\t\tconst binding = bindings[handle]\n\t\tif (!binding) continue\n\t\tconst boundShape = editor.getShape(binding.toId)\n\t\tconst isShapeInSamePageAsArrow =\n\t\t\teditor.getAncestorPageId(arrow) === editor.getAncestorPageId(boundShape)\n\t\tif (!boundShape || !isShapeInSamePageAsArrow) {\n\t\t\tupdateArrowTerminal({ editor, arrow, terminal: handle, unbind: true })\n\t\t}\n\t}\n\n\t// always check the arrow parents\n\treparentArrow(editor, arrow.id)\n}\n\n/** @internal */\nexport function updateArrowTerminal({\n\teditor,\n\tarrow,\n\tterminal,\n\tunbind = false,\n\tuseHandle = false,\n}: {\n\teditor: Editor\n\tarrow: TLArrowShape\n\tterminal: 'start' | 'end'\n\tunbind?: boolean\n\tuseHandle?: boolean\n}) {\n\tconst info = getArrowInfo(editor, arrow)\n\tif (!info) {\n\t\tthrow new Error('expected arrow info')\n\t}\n\n\tconst startPoint = getValidTerminalPoint(\n\t\tuseHandle ? info.start.handle : info.start.point,\n\t\tarrow.props.start\n\t)\n\tconst endPoint = getValidTerminalPoint(\n\t\tuseHandle ? info.end.handle : info.end.point,\n\t\tarrow.props.end\n\t)\n\tconst point = terminal === 'start' ? startPoint : endPoint\n\n\tconst update = {\n\t\tid: arrow.id,\n\t\ttype: 'arrow',\n\t\tprops: {\n\t\t\t[terminal]: { x: point.x, y: point.y },\n\t\t\tbend: arrow.props.bend,\n\t\t},\n\t} satisfies TLShapePartial<TLArrowShape>\n\n\t// fix up the bend:\n\tif (info.type === 'arc') {\n\t\t// find the new start/end points of the resulting arrow\n\t\tconst newStart =\n\t\t\tterminal === 'start'\n\t\t\t\t? startPoint\n\t\t\t\t: getValidTerminalPoint(info.start.handle, arrow.props.start)\n\t\tconst newEnd =\n\t\t\tterminal === 'end' ? endPoint : getValidTerminalPoint(info.end.handle, arrow.props.end)\n\t\tconst newMidPoint = Vec.Med(newStart, newEnd)\n\t\tconst arrowDirection = Vec.Sub(newStart, newEnd)\n\t\tif (approximately(Vec.Len2(arrowDirection), 0)) {\n\t\t\teditor.updateShape(update)\n\t\t\tif (unbind) {\n\t\t\t\tremoveArrowBinding(editor, arrow, terminal)\n\t\t\t}\n\t\t\treturn\n\t\t}\n\n\t\t// intersect a line segment perpendicular to the new arrow with the old arrow arc to\n\t\t// find the new mid-point\n\t\tconst lineSegment = arrowDirection\n\t\t\t.per()\n\t\t\t.uni()\n\t\t\t.mul(info.handleArc.radius * 2 * Math.sign(arrow.props.bend))\n\t\tconst targetPoint = Vec.Add(newMidPoint, lineSegment)\n\t\tif (\n\t\t\t!Vec.IsFinite(info.handleArc.center) ||\n\t\t\t!Number.isFinite(info.handleArc.radius) ||\n\t\t\t!Vec.IsFinite(targetPoint)\n\t\t) {\n\t\t\teditor.updateShape(update)\n\t\t\tif (unbind) {\n\t\t\t\tremoveArrowBinding(editor, arrow, terminal)\n\t\t\t}\n\t\t\treturn\n\t\t}\n\n\t\t// find the intersections with the old arrow arc:\n\t\tconst intersections = intersectLineSegmentCircle(\n\t\t\tinfo.handleArc.center,\n\t\t\ttargetPoint,\n\t\t\tinfo.handleArc.center,\n\t\t\tinfo.handleArc.radius\n\t\t)\n\n\t\tif (intersections?.length) {\n\t\t\tconst intersection = intersections.reduce((closest, candidate) =>\n\t\t\t\tVec.Dist2(candidate, targetPoint) < Vec.Dist2(closest, targetPoint) ? candidate : closest\n\t\t\t)\n\t\t\tconst bend = Vec.Dist(newMidPoint, intersection) * Math.sign(arrow.props.bend)\n\t\t\t// use `approximately` to avoid endless update loops\n\t\t\tif (!approximately(bend, update.props.bend)) {\n\t\t\t\tupdate.props.bend = bend\n\t\t\t}\n\t\t}\n\t}\n\n\teditor.updateShape(update)\n\tif (unbind) {\n\t\tremoveArrowBinding(editor, arrow, terminal)\n\t}\n}\n\nfunction getValidTerminalPoint(\n\tpoint: { x: number; y: number },\n\tfallback: { x: number; y: number }\n) {\n\treturn Vec.From(Vec.IsFinite(point) ? point : fallback)\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAsBO;AACP,0BAA6B;AAC7B,oBAAqD;AAK9C,MAAM,yBAAyB,0BAA4B;AAAA,EACjE,OAAgB,OAAO;AAAA,EAEvB,OAAgB,QAAQ;AAAA,EACxB,OAAgB,aAAa;AAAA,EAEpB,kBAAgD;AACxD,WAAO;AAAA,MACN,WAAW;AAAA,MACX,SAAS;AAAA,MACT,kBAAkB,EAAE,GAAG,KAAK,GAAG,IAAI;AAAA,MACnC,MAAM;AAAA,IACP;AAAA,EACD;AAAA;AAAA,EAGS,cAAc,EAAE,QAAQ,GAAiD;AACjF,UAAM,QAAQ,KAAK,OAAO,SAAS,QAAQ,MAAM;AACjD,QAAI,CAAC,MAAO;AACZ,mBAAe,KAAK,QAAQ,KAAK;AAAA,EAClC;AAAA;AAAA,EAGS,cAAc,EAAE,aAAa,GAAiD;AACtF,UAAM,QAAQ,KAAK,OAAO,SAAS,aAAa,MAAM;AACtD,QAAI,CAAC,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BindingOnShapeChangeOptions,\n\tBindingOnShapeIsolateOptions,\n\tBindingUtil,\n\tEditor,\n\tIndexKey,\n\tTLArrowBinding,\n\tTLArrowBindingProps,\n\tTLArrowShape,\n\tTLParentId,\n\tTLShape,\n\tTLShapeId,\n\tTLShapePartial,\n\tVec,\n\tapproximately,\n\tarrowBindingMigrations,\n\tarrowBindingProps,\n\tgetIndexAbove,\n\tgetIndexBetween,\n\tintersectLineSegmentCircle,\n} from '@tldraw/editor'\nimport { getArrowInfo } from '../../shapes/arrow/getArrowInfo'\nimport { getArrowBindings, removeArrowBinding } from '../../shapes/arrow/shared'\n\n/**\n * @public\n */\nexport class ArrowBindingUtil extends BindingUtil<TLArrowBinding> {\n\tstatic override type = 'arrow'\n\n\tstatic override props = arrowBindingProps\n\tstatic override migrations = arrowBindingMigrations\n\n\toverride getDefaultProps(): Partial<TLArrowBindingProps> {\n\t\treturn {\n\t\t\tisPrecise: false,\n\t\t\tisExact: false,\n\t\t\tnormalizedAnchor: { x: 0.5, y: 0.5 },\n\t\t\tsnap: 'none',\n\t\t}\n\t}\n\n\t// when the binding itself changes\n\toverride onAfterCreate({ binding }: BindingOnCreateOptions<TLArrowBinding>): void {\n\t\tconst arrow = this.editor.getShape(binding.fromId) as TLArrowShape | undefined\n\t\tif (!arrow) return\n\t\tarrowDidUpdate(this.editor, arrow)\n\t}\n\n\t// when the binding itself changes\n\toverride onAfterChange({ bindingAfter }: BindingOnChangeOptions<TLArrowBinding>): void {\n\t\tconst arrow = this.editor.getShape(bindingAfter.fromId) as TLArrowShape | undefined\n\t\tif (!arrow) return\n\t\tarrowDidUpdate(this.editor, arrow)\n\t}\n\n\t// when the arrow itself changes\n\toverride onAfterChangeFromShape({\n\t\tshapeBefore,\n\t\tshapeAfter,\n\t\treason,\n\t}: BindingOnShapeChangeOptions<TLArrowBinding>): void {\n\t\t// When translating arrows together with their bound shapes, only x/y changes.\n\t\t// In this case, bindings remain valid and no reparenting is needed.\n\t\t// This is a significant performance optimization when moving many bound shapes.\n\t\tif (\n\t\t\treason !== 'ancestry' &&\n\t\t\tshapeBefore.parentId === shapeAfter.parentId &&\n\t\t\tshapeBefore.index === shapeAfter.index\n\t\t) {\n\t\t\treturn\n\t\t}\n\t\tarrowDidUpdate(this.editor, shapeAfter as TLArrowShape)\n\t}\n\n\t// when the shape an arrow is bound to changes\n\toverride onAfterChangeToShape({\n\t\tbinding,\n\t\tshapeBefore,\n\t\tshapeAfter,\n\t\treason,\n\t}: BindingOnShapeChangeOptions<TLArrowBinding>): void {\n\t\tif (\n\t\t\treason !== 'ancestry' &&\n\t\t\tshapeBefore.parentId === shapeAfter.parentId &&\n\t\t\tshapeBefore.index === shapeAfter.index\n\t\t) {\n\t\t\treturn\n\t\t}\n\t\treparentArrow(this.editor, binding.fromId)\n\t}\n\n\t// when the arrow is isolated we need to update its (x,y) positions\n\toverride onBeforeIsolateFromShape({\n\t\tbinding,\n\t}: BindingOnShapeIsolateOptions<TLArrowBinding>): void {\n\t\t// during undo/redo the history diff already contains the arrow's correct\n\t\t// state, so adjusting the terminal here would corrupt the replay\n\t\tif (this.editor.isReplayingHistory()) return\n\n\t\tconst arrow = this.editor.getShape<TLArrowShape>(binding.fromId)\n\t\tif (!arrow) return\n\t\tupdateArrowTerminal({\n\t\t\teditor: this.editor,\n\t\t\tarrow,\n\t\t\tterminal: binding.props.terminal,\n\t\t})\n\t}\n}\n\nfunction reparentArrow(editor: Editor, arrowId: TLShapeId) {\n\tconst arrow = editor.getShape<TLArrowShape>(arrowId)\n\tif (!arrow) return\n\tconst bindings = getArrowBindings(editor, arrow)\n\tconst { start, end } = bindings\n\tconst startShape = start ? editor.getShape(start.toId) : undefined\n\tconst endShape = end ? editor.getShape(end.toId) : undefined\n\n\tconst parentPageId = editor.getAncestorPageId(arrow)\n\tif (!parentPageId) return\n\n\tlet nextParentId: TLParentId\n\tif (startShape && endShape) {\n\t\t// If arrow has two bindings, parent it to the closest common ancestor of the\n\t\t// bound shapes. When one bound shape is a frame-like ancestor-or-self of the\n\t\t// other, use that frame-like shape itself instead of its parent.\n\t\tnextParentId =\n\t\t\tgetCommonFrameLikeBindingAncestor(editor, startShape, endShape) ??\n\t\t\teditor.findCommonAncestor([startShape, endShape]) ??\n\t\t\tparentPageId\n\t} else if (startShape || endShape) {\n\t\tconst bindingParentId = (startShape || endShape)?.parentId\n\t\t// If the arrow and the shape that it is bound to have the same parent, then keep that parent\n\t\tif (bindingParentId && bindingParentId === arrow.parentId) {\n\t\t\tnextParentId = arrow.parentId\n\t\t} else {\n\t\t\t// if arrow has one binding, keep arrow on its own page\n\t\t\tnextParentId = parentPageId\n\t\t}\n\t} else {\n\t\treturn\n\t}\n\n\tif (nextParentId && nextParentId !== arrow.parentId) {\n\t\teditor.reparentShapes([arrowId], nextParentId)\n\t}\n\n\tconst reparentedArrow = editor.getShape<TLArrowShape>(arrowId)\n\tif (!reparentedArrow) throw Error('no reparented arrow')\n\n\tconst startSibling = editor.getShapeNearestSibling(reparentedArrow, startShape)\n\tconst endSibling = editor.getShapeNearestSibling(reparentedArrow, endShape)\n\n\tlet highestSibling: TLShape | undefined\n\n\tif (startSibling && endSibling) {\n\t\thighestSibling = startSibling.index > endSibling.index ? startSibling : endSibling\n\t} else if (startSibling && !endSibling) {\n\t\thighestSibling = startSibling\n\t} else if (endSibling && !startSibling) {\n\t\thighestSibling = endSibling\n\t} else {\n\t\treturn\n\t}\n\n\tlet finalIndex: IndexKey\n\n\tconst higherSiblings = editor\n\t\t.getSortedChildIdsForParent(highestSibling.parentId)\n\t\t.map((id) => editor.getShape(id)!)\n\t\t.filter((sibling) => sibling.index > highestSibling!.index)\n\n\tif (higherSiblings.length) {\n\t\t// there are siblings above the highest bound sibling, we need to\n\t\t// insert between them.\n\n\t\t// if the next sibling is also a bound arrow though, we can end up\n\t\t// all fighting for the same indexes. so lets find the next\n\t\t// non-arrow sibling...\n\t\tconst nextHighestNonArrowSibling = higherSiblings.find((sibling) => sibling.type !== 'arrow')\n\n\t\tif (\n\t\t\t// ...then, if we're above the last shape we want to be above...\n\t\t\treparentedArrow.index > highestSibling.index &&\n\t\t\t// ...but below the next non-arrow sibling...\n\t\t\t(!nextHighestNonArrowSibling || reparentedArrow.index < nextHighestNonArrowSibling.index)\n\t\t) {\n\t\t\t// ...then we're already in the right place. no need to update!\n\t\t\treturn\n\t\t}\n\n\t\t// otherwise, we need to find the index between the highest sibling\n\t\t// we want to be above, and the next highest sibling we want to be\n\t\t// below:\n\t\tfinalIndex = getIndexBetween(highestSibling.index, higherSiblings[0].index)\n\t} else {\n\t\t// if there are no siblings above us, we can just get the next index:\n\t\tfinalIndex = getIndexAbove(highestSibling.index)\n\t}\n\n\tif (finalIndex !== reparentedArrow.index) {\n\t\teditor.updateShapes([{ id: arrowId, type: 'arrow', index: finalIndex }])\n\t}\n}\n\nfunction getCommonFrameLikeBindingAncestor(\n\teditor: Editor,\n\tstartShape: TLShape,\n\tendShape: TLShape\n): TLShapeId | undefined {\n\tlet ancestor: TLShape | undefined\n\tif (startShape.id === endShape.id) {\n\t\tancestor = startShape\n\t} else if (editor.hasAncestor(startShape, endShape.id)) {\n\t\tancestor = endShape\n\t} else if (editor.hasAncestor(endShape, startShape.id)) {\n\t\tancestor = startShape\n\t}\n\n\treturn ancestor && editor.isShapeFrameLike(ancestor) ? ancestor.id : undefined\n}\n\nfunction arrowDidUpdate(editor: Editor, arrow: TLArrowShape) {\n\tconst bindings = getArrowBindings(editor, arrow)\n\t// if the shape is an arrow and its bound shape is on another page\n\t// or was deleted, unbind it\n\tfor (const handle of ['start', 'end'] as const) {\n\t\tconst binding = bindings[handle]\n\t\tif (!binding) continue\n\t\tconst boundShape = editor.getShape(binding.toId)\n\t\tconst isShapeInSamePageAsArrow =\n\t\t\teditor.getAncestorPageId(arrow) === editor.getAncestorPageId(boundShape)\n\t\tif (!boundShape || !isShapeInSamePageAsArrow) {\n\t\t\tupdateArrowTerminal({ editor, arrow, terminal: handle, unbind: true })\n\t\t}\n\t}\n\n\t// always check the arrow parents\n\treparentArrow(editor, arrow.id)\n}\n\n/** @internal */\nexport function updateArrowTerminal({\n\teditor,\n\tarrow,\n\tterminal,\n\tunbind = false,\n\tuseHandle = false,\n}: {\n\teditor: Editor\n\tarrow: TLArrowShape\n\tterminal: 'start' | 'end'\n\tunbind?: boolean\n\tuseHandle?: boolean\n}) {\n\tconst info = getArrowInfo(editor, arrow)\n\tif (!info) {\n\t\tthrow new Error('expected arrow info')\n\t}\n\n\tconst startPoint = getValidTerminalPoint(\n\t\tuseHandle ? info.start.handle : info.start.point,\n\t\tarrow.props.start\n\t)\n\tconst endPoint = getValidTerminalPoint(\n\t\tuseHandle ? info.end.handle : info.end.point,\n\t\tarrow.props.end\n\t)\n\tconst point = terminal === 'start' ? startPoint : endPoint\n\n\tconst update = {\n\t\tid: arrow.id,\n\t\ttype: 'arrow',\n\t\tprops: {\n\t\t\t[terminal]: { x: point.x, y: point.y },\n\t\t\tbend: arrow.props.bend,\n\t\t},\n\t} satisfies TLShapePartial<TLArrowShape>\n\n\t// fix up the bend:\n\tif (info.type === 'arc') {\n\t\t// find the new start/end points of the resulting arrow\n\t\tconst newStart =\n\t\t\tterminal === 'start'\n\t\t\t\t? startPoint\n\t\t\t\t: getValidTerminalPoint(info.start.handle, arrow.props.start)\n\t\tconst newEnd =\n\t\t\tterminal === 'end' ? endPoint : getValidTerminalPoint(info.end.handle, arrow.props.end)\n\t\tconst newMidPoint = Vec.Med(newStart, newEnd)\n\t\tconst arrowDirection = Vec.Sub(newStart, newEnd)\n\t\tif (approximately(Vec.Len2(arrowDirection), 0)) {\n\t\t\teditor.updateShape(update)\n\t\t\tif (unbind) {\n\t\t\t\tremoveArrowBinding(editor, arrow, terminal)\n\t\t\t}\n\t\t\treturn\n\t\t}\n\n\t\t// intersect a line segment perpendicular to the new arrow with the old arrow arc to\n\t\t// find the new mid-point\n\t\tconst lineSegment = arrowDirection\n\t\t\t.per()\n\t\t\t.uni()\n\t\t\t.mul(info.handleArc.radius * 2 * Math.sign(arrow.props.bend))\n\t\tconst targetPoint = Vec.Add(newMidPoint, lineSegment)\n\t\tif (\n\t\t\t!Vec.IsFinite(info.handleArc.center) ||\n\t\t\t!Number.isFinite(info.handleArc.radius) ||\n\t\t\t!Vec.IsFinite(targetPoint)\n\t\t) {\n\t\t\teditor.updateShape(update)\n\t\t\tif (unbind) {\n\t\t\t\tremoveArrowBinding(editor, arrow, terminal)\n\t\t\t}\n\t\t\treturn\n\t\t}\n\n\t\t// find the intersections with the old arrow arc:\n\t\tconst intersections = intersectLineSegmentCircle(\n\t\t\tinfo.handleArc.center,\n\t\t\ttargetPoint,\n\t\t\tinfo.handleArc.center,\n\t\t\tinfo.handleArc.radius\n\t\t)\n\n\t\tif (intersections?.length) {\n\t\t\tconst intersection = intersections.reduce((closest, candidate) =>\n\t\t\t\tVec.Dist2(candidate, targetPoint) < Vec.Dist2(closest, targetPoint) ? candidate : closest\n\t\t\t)\n\t\t\tconst bend = Vec.Dist(newMidPoint, intersection) * Math.sign(arrow.props.bend)\n\t\t\t// use `approximately` to avoid endless update loops\n\t\t\tif (!approximately(bend, update.props.bend)) {\n\t\t\t\tupdate.props.bend = bend\n\t\t\t}\n\t\t}\n\t}\n\n\teditor.updateShape(update)\n\tif (unbind) {\n\t\tremoveArrowBinding(editor, arrow, terminal)\n\t}\n}\n\nfunction getValidTerminalPoint(\n\tpoint: { x: number; y: number },\n\tfallback: { x: number; y: number }\n) {\n\treturn Vec.From(Vec.IsFinite(point) ? point : fallback)\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAsBO;AACP,0BAA6B;AAC7B,oBAAqD;AAK9C,MAAM,yBAAyB,0BAA4B;AAAA,EACjE,OAAgB,OAAO;AAAA,EAEvB,OAAgB,QAAQ;AAAA,EACxB,OAAgB,aAAa;AAAA,EAEpB,kBAAgD;AACxD,WAAO;AAAA,MACN,WAAW;AAAA,MACX,SAAS;AAAA,M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AAI,aAAa,WAAW;AACpD,QACC,CAAC,kBAAI,SAAS,KAAK,UAAU,MAAM,KACnC,CAAC,OAAO,SAAS,KAAK,UAAU,MAAM,KACtC,CAAC,kBAAI,SAAS,WAAW,GACxB;AACD,aAAO,YAAY,MAAM;AACzB,UAAI,QAAQ;AACX,8CAAmB,QAAQ,OAAO,QAAQ;AAAA,MAC3C;AACA;AAAA,IACD;AAGA,UAAM,oBAAgB;AAAA,MACrB,KAAK,UAAU;AAAA,MACf;AAAA,MACA,KAAK,UAAU;AAAA,MACf,KAAK,UAAU;AAAA,IAChB;AAEA,QAAI,eAAe,QAAQ;AAC1B,YAAM,eAAe,cAAc;AAAA,QAAO,CAAC,SAAS,cACnD,kBAAI,MAAM,WAAW,WAAW,IAAI,kBAAI,MAAM,SAAS,WAAW,IAAI,YAAY;AAAA,MACnF;AACA,YAAM,OAAO,kBAAI,KAAK,aAAa,YAAY,IAAI,KAAK,KAAK,MAAM,MAAM,IAAI;AAE7E,UAAI,KAAC,6BAAc,MAAM,OAAO,MAAM,IAAI,GAAG;AAC5C,eAAO,MAAM,OAAO;AAAA,MACrB;AAAA,IACD;AAAA,EACD;AAEA,SAAO,YAAY,MAAM;AACzB,MAAI,QAAQ;AACX,0CAAmB,QAAQ,OAAO,QAAQ;AAAA,EAC3C;AACD;AAEA,SAAS,sBACR,OACA,UACC;AACD,SAAO,kBAAI,KAAK,kBAAI,SAAS,KAAK,IAAI,QAAQ,QAAQ;AACvD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -77,7 +77,7 @@ class Pointing extends import_editor.StateNode {
|
|
|
77
77
|
this.cancel();
|
|
78
78
|
}
|
|
79
79
|
onLongPress() {
|
|
80
|
-
|
|
80
|
+
if (this.editor.getInstanceState().isCoarsePointer) this.cancel();
|
|
81
81
|
}
|
|
82
82
|
onCancel() {
|
|
83
83
|
this.cancel();
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/lib/shapes/arrow/toolStates/Pointing.tsx"],
|
|
4
|
-
"sourcesContent": ["import {
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,
|
|
4
|
+
"sourcesContent": ["import { StateNode, TLArrowShape, createShapeId, maybeSnapToGrid } from '@tldraw/editor'\nimport { ArrowShapeUtil } from '../ArrowShapeUtil'\nimport { clearArrowTargetState, updateArrowTargetState } from '../arrowTargetState'\n\nexport class Pointing extends StateNode {\n\tstatic override id = 'pointing'\n\n\tshape?: TLArrowShape\n\n\tisPrecise = false\n\tisPreciseTimerId: number | null = null\n\n\tmarkId = ''\n\n\toverride onEnter(info: { isPrecise?: boolean }) {\n\t\tthis.markId = ''\n\t\tthis.isPrecise = !!info.isPrecise\n\n\t\tconst targetState = updateArrowTargetState({\n\t\t\teditor: this.editor,\n\t\t\tpointInPageSpace: this.editor.inputs.getCurrentPagePoint(),\n\t\t\tarrow: undefined,\n\t\t\tisPrecise: this.isPrecise,\n\t\t\tcurrentBinding: undefined,\n\t\t\toppositeBinding: undefined,\n\t\t})\n\n\t\tif (!targetState) {\n\t\t\tthis.createArrowShape()\n\t\t\tif (!this.shape) {\n\t\t\t\tthis.cancel()\n\t\t\t\treturn\n\t\t\t}\n\t\t}\n\n\t\tthis.startPreciseTimeout()\n\t}\n\n\toverride onExit() {\n\t\tthis.shape = undefined\n\t\tclearArrowTargetState(this.editor)\n\t\tthis.clearPreciseTimeout()\n\t}\n\n\toverride onPointerMove() {\n\t\tif (this.editor.inputs.getIsDragging()) {\n\t\t\tif (!this.shape) {\n\t\t\t\tthis.createArrowShape()\n\t\t\t}\n\n\t\t\tif (!this.shape) {\n\t\t\t\tthis.cancel()\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tthis.updateArrowShapeEndHandle()\n\n\t\t\tthis.editor.setCurrentTool('select.dragging_handle', {\n\t\t\t\tshape: this.shape,\n\t\t\t\thandle: { id: 'end', type: 'vertex', index: 'a3', x: 0, y: 0 },\n\t\t\t\tisCreating: true,\n\t\t\t\tcreatingMarkId: this.markId || undefined,\n\t\t\t\tonInteractionEnd: 'arrow',\n\t\t\t})\n\t\t}\n\t}\n\n\toverride onPointerUp() {\n\t\tthis.cancel()\n\t}\n\n\toverride onLongPress() {\n\t\t// On a touch (coarse pointer) long-press, cancel the pending shape so it leaves nothing behind.\n\t\tif (this.editor.getInstanceState().isCoarsePointer) this.cancel()\n\t}\n\n\toverride onCancel() {\n\t\tthis.cancel()\n\t}\n\n\toverride onComplete() {\n\t\tthis.cancel()\n\t}\n\n\toverride onInterrupt() {\n\t\tthis.cancel()\n\t}\n\n\tcancel() {\n\t\tif (this.shape) {\n\t\t\t// the arrow might not have been created yet!\n\t\t\tthis.editor.bailToMark(this.markId)\n\t\t}\n\t\tthis.parent.transition('idle')\n\t}\n\n\tcreateArrowShape() {\n\t\tconst originPagePoint = this.editor.inputs.getOriginPagePoint()\n\n\t\tconst id = createShapeId()\n\n\t\tthis.markId = this.editor.markHistoryStoppingPoint(`creating_arrow:${id}`)\n\t\tconst newPoint = maybeSnapToGrid(originPagePoint, this.editor)\n\t\tthis.editor.createShape({\n\t\t\tid,\n\t\t\ttype: 'arrow',\n\t\t\tx: newPoint.x,\n\t\t\ty: newPoint.y,\n\t\t\tprops: {\n\t\t\t\tscale: this.editor.getResizeScaleFactor(),\n\t\t\t},\n\t\t})\n\n\t\tconst shape = this.editor.getShape<TLArrowShape>(id)\n\t\tif (!shape) return\n\n\t\tconst handles = this.editor.getShapeHandles(shape)\n\t\tif (!handles) throw Error(`expected handles for arrow`)\n\n\t\tconst util = this.editor.getShapeUtil<TLArrowShape>('arrow')\n\t\tconst initial = this.shape\n\t\tconst startHandle = handles.find((h) => h.id === 'start')!\n\t\tconst change = util.onHandleDrag?.(shape, {\n\t\t\thandle: { ...startHandle, x: 0, y: 0 },\n\t\t\tisPrecise: true,\n\t\t\tisCreatingShape: true,\n\t\t\tinitial: initial,\n\t\t})\n\n\t\tif (change) {\n\t\t\tthis.editor.updateShapes([change])\n\t\t}\n\n\t\t// Cache the current shape after those changes\n\t\tthis.shape = this.editor.getShape(id)\n\t\tthis.editor.select(id)\n\t}\n\n\tupdateArrowShapeEndHandle() {\n\t\tconst shape = this.shape\n\t\tif (!shape) throw Error(`expected shape`)\n\n\t\tconst handles = this.editor.getShapeHandles(shape)\n\t\tif (!handles) throw Error(`expected handles for arrow`)\n\n\t\t// start update\n\t\t{\n\t\t\tconst util = this.editor.getShapeUtil<TLArrowShape>('arrow')\n\t\t\tconst initial = this.shape\n\t\t\tconst startHandle = handles.find((h) => h.id === 'start')!\n\t\t\tconst change = util.onHandleDrag?.(shape, {\n\t\t\t\thandle: { ...startHandle, x: 0, y: 0 },\n\t\t\t\tisPrecise: this.isPrecise,\n\t\t\t\tisCreatingShape: true,\n\t\t\t\tinitial: initial,\n\t\t\t})\n\n\t\t\tif (change) {\n\t\t\t\tthis.editor.updateShapes([change])\n\t\t\t}\n\t\t}\n\n\t\t// end update\n\t\t{\n\t\t\tconst util = this.editor.getShapeUtil<TLArrowShape>('arrow')\n\t\t\tconst initial = this.shape\n\t\t\tconst point = this.editor.getPointInShapeSpace(\n\t\t\t\tshape,\n\t\t\t\tthis.editor.inputs.getCurrentPagePoint()\n\t\t\t)\n\t\t\tconst endHandle = handles.find((h) => h.id === 'end')!\n\t\t\tconst change = util.onHandleDrag?.(this.editor.getShape(shape)!, {\n\t\t\t\thandle: { ...endHandle, x: point.x, y: point.y },\n\t\t\t\tisPrecise: this.isPrecise,\n\t\t\t\tisCreatingShape: true,\n\t\t\t\tinitial: initial,\n\t\t\t})\n\n\t\t\tif (change) {\n\t\t\t\tthis.editor.updateShapes([change])\n\t\t\t}\n\t\t}\n\n\t\t// Cache the current shape after those changes\n\t\tthis.shape = this.editor.getShape(shape.id)\n\t}\n\n\tprivate startPreciseTimeout() {\n\t\tconst arrowUtil = this.editor.getShapeUtil<ArrowShapeUtil>('arrow')\n\n\t\tthis.isPreciseTimerId = this.editor.timers.setTimeout(() => {\n\t\t\tif (!this.getIsActive()) return\n\t\t\tthis.isPrecise = true\n\t\t}, arrowUtil.options.pointingPreciseTimeout)\n\t}\n\n\tprivate clearPreciseTimeout() {\n\t\tif (this.isPreciseTimerId !== null) {\n\t\t\tclearTimeout(this.isPreciseTimerId)\n\t\t}\n\t}\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAwE;AAExE,8BAA8D;AAEvD,MAAM,iBAAiB,wBAAU;AAAA,EACvC,OAAgB,KAAK;AAAA,EAErB;AAAA,EAEA,YAAY;AAAA,EACZ,mBAAkC;AAAA,EAElC,SAAS;AAAA,EAEA,QAAQ,MAA+B;AAC/C,SAAK,SAAS;AACd,SAAK,YAAY,CAAC,CAAC,KAAK;AAExB,UAAM,kBAAc,gDAAuB;AAAA,MAC1C,QAAQ,KAAK;AAAA,MACb,kBAAkB,KAAK,OAAO,OAAO,oBAAoB;AAAA,MACzD,OAAO;AAAA,MACP,WAAW,KAAK;AAAA,MAChB,gBAAgB;AAAA,MAChB,iBAAiB;AAAA,IAClB,CAAC;AAED,QAAI,CAAC,aAAa;AACjB,WAAK,iBAAiB;AACtB,UAAI,CAAC,KAAK,OAAO;AAChB,aAAK,OAAO;AACZ;AAAA,MACD;AAAA,IACD;AAEA,SAAK,oBAAoB;AAAA,EAC1B;AAAA,EAES,SAAS;AACjB,SAAK,QAAQ;AACb,uDAAsB,KAAK,MAAM;AACjC,SAAK,oBAAoB;AAAA,EAC1B;AAAA,EAES,gBAAgB;AACxB,QAAI,KAAK,OAAO,OAAO,cAAc,GAAG;AACvC,UAAI,CAAC,KAAK,OAAO;AAChB,aAAK,iBAAiB;AAAA,MACvB;AAEA,UAAI,CAAC,KAAK,OAAO;AAChB,aAAK,OAAO;AACZ;AAAA,MACD;AAEA,WAAK,0BAA0B;AAE/B,WAAK,OAAO,eAAe,0BAA0B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,KAAK,GAAI;AAAA,QAChE,QAAQ,EAAE,GAAG,WAAW,GAAG,MAAM,GAAG,GAAG,MAAM,EAAE;AAAA,QAC/C,WAAW,KAAK;AAAA,QAChB,iBAAiB;AAAA,QACjB;AAAA,MACD,CAAC;AAED,UAAI,QAAQ;AACX,aAAK,OAAO,aAAa,CAAC,MAAM,CAAC;AAAA,MAClC;AAAA,IACD;AAGA,SAAK,QAAQ,KAAK,OAAO,SAAS,MAAM,EAAE;AAAA,EAC3C;AAAA,EAEQ,sBAAsB;AAC7B,UAAM,YAAY,KAAK,OAAO,aAA6B,OAAO;AAElE,SAAK,mBAAmB,KAAK,OAAO,OAAO,WAAW,MAAM;AAC3D,UAAI,CAAC,KAAK,YAAY,EAAG;AACzB,WAAK,YAAY;AAAA,IAClB,GAAG,UAAU,QAAQ,sBAAsB;AAAA,EAC5C;AAAA,EAEQ,sBAAsB;AAC7B,QAAI,KAAK,qBAAqB,MAAM;AACnC,mBAAa,KAAK,gBAAgB;AAAA,IACnC;AAAA,EACD;AACD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -29,7 +29,7 @@ class Pointing extends import_editor.StateNode {
|
|
|
29
29
|
this.complete();
|
|
30
30
|
}
|
|
31
31
|
onLongPress() {
|
|
32
|
-
|
|
32
|
+
if (this.editor.getInstanceState().isCoarsePointer) this.cancel();
|
|
33
33
|
}
|
|
34
34
|
onPointerMove(info) {
|
|
35
35
|
if (this.editor.inputs.getIsDragging()) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/lib/shapes/geo/toolStates/Pointing.ts"],
|
|
4
|
-
"sourcesContent": ["import {\n\tGeoShapeGeoStyle,\n\tStateNode,\n\tTLGeoShape,\n\tTLPointerEventInfo,\n\tVec,\n\tcreateShapeId,\n\
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,
|
|
4
|
+
"sourcesContent": ["import {\n\tGeoShapeGeoStyle,\n\tStateNode,\n\tTLGeoShape,\n\tTLPointerEventInfo,\n\tVec,\n\tcreateShapeId,\n\tmaybeSnapToGrid,\n} from '@tldraw/editor'\nimport { GeoShapeUtil } from '../GeoShapeUtil'\nimport { getGeoTypeDefinition } from '../getGeoShapePath'\n\nexport class Pointing extends StateNode {\n\tstatic override id = 'pointing'\n\n\toverride onPointerUp() {\n\t\tthis.complete()\n\t}\n\n\toverride onLongPress() {\n\t\t// On a touch (coarse pointer) long-press, cancel the pending shape so it leaves nothing behind.\n\t\tif (this.editor.getInstanceState().isCoarsePointer) this.cancel()\n\t}\n\n\toverride onPointerMove(info: TLPointerEventInfo) {\n\t\tif (this.editor.inputs.getIsDragging()) {\n\t\t\tconst originPagePoint = this.editor.inputs.getOriginPagePoint()\n\n\t\t\tconst id = createShapeId()\n\n\t\t\tconst creatingMarkId = this.editor.markHistoryStoppingPoint(`creating_geo:${id}`)\n\t\t\tconst newPoint = maybeSnapToGrid(originPagePoint, this.editor)\n\t\t\tthis.editor\n\t\t\t\t.createShapes([\n\t\t\t\t\t{\n\t\t\t\t\t\tid,\n\t\t\t\t\t\ttype: 'geo',\n\t\t\t\t\t\tx: newPoint.x,\n\t\t\t\t\t\ty: newPoint.y,\n\t\t\t\t\t\tprops: {\n\t\t\t\t\t\t\tw: 1,\n\t\t\t\t\t\t\th: 1,\n\t\t\t\t\t\t\tgeo: this.editor.getStyleForNextShape(GeoShapeGeoStyle),\n\t\t\t\t\t\t\tscale: this.editor.getResizeScaleFactor(),\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t])\n\t\t\t\t.select(id)\n\n\t\t\tconst shape = this.editor.getShape(id)\n\t\t\tif (!shape) {\n\t\t\t\tthis.cancel()\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tthis.editor.setCurrentTool('select.resizing', {\n\t\t\t\t...info,\n\t\t\t\ttarget: 'selection',\n\t\t\t\thandle: 'bottom_right',\n\t\t\t\tisCreating: true,\n\t\t\t\tcreatingMarkId,\n\t\t\t\tcreationCursorOffset: { x: 1, y: 1 },\n\t\t\t\tonInteractionEnd: 'geo',\n\t\t\t})\n\t\t}\n\t}\n\n\toverride onCancel() {\n\t\tthis.cancel()\n\t}\n\n\toverride onComplete() {\n\t\tthis.complete()\n\t}\n\n\toverride onInterrupt() {\n\t\tthis.cancel()\n\t}\n\n\tprivate complete() {\n\t\tconst originPagePoint = this.editor.inputs.getOriginPagePoint()\n\n\t\tconst id = createShapeId()\n\n\t\tthis.editor.markHistoryStoppingPoint(`creating_geo:${id}`)\n\n\t\tconst scale = this.editor.getResizeScaleFactor()\n\n\t\tconst geo = this.editor.getStyleForNextShape(GeoShapeGeoStyle)\n\t\tconst geoShapeUtil = this.editor.getShapeUtil<GeoShapeUtil>('geo')\n\n\t\tconst def = getGeoTypeDefinition(geo, geoShapeUtil.options.customGeoTypes)\n\t\tconst size = def?.defaultSize ?? { w: 200, h: 200 }\n\n\t\tthis.editor.createShapes([\n\t\t\t{\n\t\t\t\tid,\n\t\t\t\ttype: 'geo',\n\t\t\t\tx: originPagePoint.x,\n\t\t\t\ty: originPagePoint.y,\n\t\t\t\tprops: {\n\t\t\t\t\tgeo: this.editor.getStyleForNextShape(GeoShapeGeoStyle),\n\t\t\t\t\tscale,\n\t\t\t\t\t...size,\n\t\t\t\t},\n\t\t\t},\n\t\t])\n\n\t\tconst shape = this.editor.getShape<TLGeoShape>(id)!\n\t\tif (!shape) {\n\t\t\tthis.cancel()\n\t\t\treturn\n\t\t}\n\n\t\tconst { w, h } = shape.props\n\n\t\tconst delta = new Vec(w / 2, h / 2).mul(scale)\n\t\tconst parentTransform = this.editor.getShapeParentTransform(shape)\n\t\tif (parentTransform) delta.rot(-parentTransform.rotation())\n\t\tconst newPoint = maybeSnapToGrid(new Vec(shape.x - delta.x, shape.y - delta.y), this.editor)\n\t\tthis.editor.select(id)\n\t\tthis.editor.updateShape({\n\t\t\tid: shape.id,\n\t\t\ttype: 'geo',\n\t\t\tx: newPoint.x,\n\t\t\ty: newPoint.y,\n\t\t\tprops: {\n\t\t\t\tgeo: this.editor.getStyleForNextShape(GeoShapeGeoStyle),\n\t\t\t\tw: w * scale,\n\t\t\t\th: h * scale,\n\t\t\t},\n\t\t})\n\n\t\tif (this.editor.getInstanceState().isToolLocked) {\n\t\t\tthis.parent.transition('idle')\n\t\t} else {\n\t\t\tthis.editor.setCurrentTool('select', {})\n\t\t}\n\t}\n\n\tprivate cancel() {\n\t\t// we should not have created any shapes yet, so no need to bail\n\t\tthis.parent.transition('idle')\n\t}\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAQO;AAEP,6BAAqC;AAE9B,MAAM,iBAAiB,wBAAU;AAAA,EACvC,OAAgB,KAAK;AAAA,EAEZ,cAAc;AACtB,SAAK,SAAS;AAAA,EACf;AAAA,EAES,cAAc;AAEtB,QAAI,KAAK,OAAO,iBAAiB,EAAE,gBAAiB,MAAK,OAAO;AAAA,EACjE;AAAA,EAES,cAAc,MAA0B;AAChD,QAAI,KAAK,OAAO,OAAO,cAAc,GAAG;AACvC,YAAM,kBAAkB,KAAK,OAAO,OAAO,mBAAmB;AAE9D,YAAM,SAAK,6BAAc;AAEzB,YAAM,iBAAiB,KAAK,OAAO,yBAAyB,gBAAgB,EAAE,EAAE;AAChF,YAAM,eAAW,+BAAgB,iBAAiB,KAAK,MAAM;AAC7D,WAAK,OACH,aAAa;AAAA,QACb;AAAA,UACC;AAAA,UACA,MAAM;AAAA,UACN,GAAG,SAAS;AAAA,UACZ,GAAG,SAAS;AAAA,UACZ,OAAO;AAAA,YACN,GAAG;AAAA,YACH,GAAG;AAAA,YACH,KAAK,KAAK,OAAO,qBAAqB,8BAAgB;AAAA,YACtD,OAAO,KAAK,OAAO,qBAAqB;AAAA,UACzC;AAAA,QACD;AAAA,MACD,CAAC,EACA,OAAO,EAAE;AAE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,MAAM;AAEvB,UAAM,QAAQ,IAAI,kBAAI,IAAI,GAAG,IAAI,CAAC,EAAE,IAAI,KAAK;AAC7C,UAAM,kBAAkB,KAAK,OAAO,wBAAwB,KAAK;AACjE,QAAI,gBAAiB,OAAM,IAAI,CAAC,gBAAgB,SAAS,CAAC;AAC1D,UAAM,eAAW,+BAAgB,IAAI,kBAAI,MAAM,IAAI,MAAM,GAAG,MAAM,IAAI,MAAM,CAAC,GAAG,KAAK,MAAM;AAC3F,SAAK,OAAO,OAAO,EAAE;AACrB,SAAK,OAAO,YAAY;AAAA,MACvB,IAAI,MAAM;AAAA,MACV,MAAM;AAAA,MACN,GAAG,SAAS;AAAA,MACZ,GAAG,SAAS;AAAA,MACZ,OAAO;AAAA,QACN,KAAK,KAAK,OAAO,qBAAqB,8BAAgB;AAAA,QACtD,GAAG,IAAI;AAAA,QACP,GAAG,IAAI;AAAA,MACR;AAAA,IACD,CAAC;AAED,QAAI,KAAK,OAAO,iBAAiB,EAAE,cAAc;AAChD,WAAK,OAAO,WAAW,MAAM;AAAA,IAC9B,OAAO;AACN,WAAK,OAAO,eAAe,UAAU,CAAC,CAAC;AAAA,IACxC;AAAA,EACD;AAAA,EAEQ,SAAS;AAEhB,SAAK,OAAO,WAAW,MAAM;AAAA,EAC9B;AACD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -83,7 +83,10 @@ class LineShapeUtil extends import_editor.ShapeUtil {
|
|
|
83
83
|
const points = linePointsToArray(shape);
|
|
84
84
|
const results = points.map((point) => ({
|
|
85
85
|
...point,
|
|
86
|
-
id
|
|
86
|
+
// A vertex handle's id is the point's stable id (its map key), not its
|
|
87
|
+
// index. The index is only ever used for ordering (sortByIndex) and for
|
|
88
|
+
// computing the create-handle positions below.
|
|
89
|
+
id: point.id,
|
|
87
90
|
type: "vertex",
|
|
88
91
|
canSnap: true
|
|
89
92
|
}));
|
|
@@ -270,7 +273,8 @@ class LineShapeUtil extends import_editor.ShapeUtil {
|
|
|
270
273
|
}
|
|
271
274
|
}
|
|
272
275
|
function linePointsToArray(shape) {
|
|
273
|
-
|
|
276
|
+
const sorted = Object.values(shape.props.points).sort(import_editor.sortByIndex);
|
|
277
|
+
return sorted.filter((point, i) => i === 0 || point.index !== sorted[i - 1].index);
|
|
274
278
|
}
|
|
275
279
|
const pathCache = new import_editor.WeakCache();
|
|
276
280
|
function getPathForLineShape(shape) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/lib/shapes/line/LineShapeUtil.tsx"],
|
|
4
|
-
"sourcesContent": ["// oxlint-disable typescript/no-empty-object-type\nimport {\n\tGroup2d,\n\tHandleSnapGeometry,\n\tSVGContainer,\n\tShapeUtil,\n\tSvgExportContext,\n\tTLHandle,\n\tTLHandleDragInfo,\n\tTLLineShape,\n\tTLLineShapePoint,\n\tTLResizeInfo,\n\tVec,\n\tWeakCache,\n\tZERO_INDEX_KEY,\n\tassert,\n\tgetColorValue,\n\tgetIndexAbove,\n\tgetIndexBetween,\n\tgetIndices,\n\tlerp,\n\tlineShapeMigrations,\n\tlineShapeProps,\n\tmapObjectMapValues,\n\tmaybeSnapToGrid,\n\tsortByIndex,\n\tuseColorMode,\n} from '@tldraw/editor'\nimport { STROKE_SIZES } from '../shared/default-shape-constants'\nimport { ShapeOptionsWithDisplayValues, getDisplayValues } from '../shared/getDisplayValues'\nimport { PathBuilder, PathBuilderGeometry2d } from '../shared/PathBuilder'\n\nconst handlesCache = new WeakCache<TLLineShape['props'], TLHandle[]>()\n\n/** @public */\nexport interface LineShapeUtilDisplayValues {\n\tstrokeColor: string\n\tstrokeWidth: number\n}\n\n/** @public */\nexport interface LineShapeOptions extends ShapeOptionsWithDisplayValues<\n\tTLLineShape,\n\tLineShapeUtilDisplayValues\n> {}\n\n/** @public */\nexport class LineShapeUtil extends ShapeUtil<TLLineShape> {\n\tstatic override type = 'line' as const\n\tstatic override props = lineShapeProps\n\tstatic override migrations = lineShapeMigrations\n\n\toverride options: LineShapeOptions = {\n\t\tgetDefaultDisplayValues(_editor, shape, theme, colorMode): LineShapeUtilDisplayValues {\n\t\t\tconst { color, size } = shape.props\n\t\t\treturn {\n\t\t\t\tstrokeColor: getColorValue(theme.colors[colorMode], color, 'solid'),\n\t\t\t\tstrokeWidth: theme.strokeWidth * STROKE_SIZES[size],\n\t\t\t}\n\t\t},\n\t\tgetCustomDisplayValues(): Partial<LineShapeUtilDisplayValues> {\n\t\t\treturn {}\n\t\t},\n\t}\n\n\toverride hideResizeHandles(shape: TLLineShape) {\n\t\treturn true\n\t}\n\toverride hideRotateHandle(shape: TLLineShape) {\n\t\treturn true\n\t}\n\toverride hideSelectionBoundsFg(shape: TLLineShape) {\n\t\treturn true\n\t}\n\toverride hideSelectionBoundsBg(shape: TLLineShape) {\n\t\treturn true\n\t}\n\toverride hideInMinimap() {\n\t\treturn true\n\t}\n\n\toverride getDefaultProps(): TLLineShape['props'] {\n\t\tconst [start, end] = getIndices(2)\n\t\treturn {\n\t\t\tdash: 'draw',\n\t\t\tsize: 'm',\n\t\t\tcolor: 'black',\n\t\t\tspline: 'line',\n\t\t\tpoints: {\n\t\t\t\t[start]: { id: start, index: start, x: 0, y: 0 },\n\t\t\t\t[end]: { id: end, index: end, x: 0.1, y: 0.1 },\n\t\t\t},\n\t\t\tscale: 1,\n\t\t}\n\t}\n\n\tgetGeometry(shape: TLLineShape) {\n\t\t// todo: should we have min size?\n\t\tconst geometry = getPathForLineShape(shape).toGeometry()\n\t\tassert(geometry instanceof PathBuilderGeometry2d)\n\t\treturn geometry\n\t}\n\n\toverride getHandles(shape: TLLineShape) {\n\t\treturn handlesCache.get(shape.props, () => {\n\t\t\tconst spline = this.getGeometry(shape)\n\n\t\t\tconst points = linePointsToArray(shape)\n\t\t\tconst results: TLHandle[] = points.map((point) => ({\n\t\t\t\t...point,\n\t\t\t\tid: point.index,\n\t\t\t\ttype: 'vertex',\n\t\t\t\tcanSnap: true,\n\t\t\t}))\n\n\t\t\tfor (let i = 0; i < points.length - 1; i++) {\n\t\t\t\tconst index = getIndexBetween(points[i].index, points[i + 1].index)\n\t\t\t\tconst segment = spline.getSegments()[i]\n\t\t\t\tconst point = segment.interpolateAlongEdge(0.5)\n\t\t\t\tresults.push({\n\t\t\t\t\tid: index,\n\t\t\t\t\ttype: 'create',\n\t\t\t\t\tindex,\n\t\t\t\t\tx: point.x,\n\t\t\t\t\ty: point.y,\n\t\t\t\t\tcanSnap: true,\n\t\t\t\t})\n\t\t\t}\n\n\t\t\treturn results.sort(sortByIndex)\n\t\t})\n\t}\n\n\t// Events\n\n\toverride onResize(shape: TLLineShape, info: TLResizeInfo<TLLineShape>) {\n\t\tconst { scaleX, scaleY } = info\n\n\t\treturn {\n\t\t\tprops: {\n\t\t\t\tpoints: mapObjectMapValues(shape.props.points, (_, { id, index, x, y }) => ({\n\t\t\t\t\tid,\n\t\t\t\t\tindex,\n\t\t\t\t\tx: x * scaleX,\n\t\t\t\t\ty: y * scaleY,\n\t\t\t\t})),\n\t\t\t},\n\t\t}\n\t}\n\n\toverride onBeforeCreate(next: TLLineShape): void | TLLineShape {\n\t\tconst {\n\t\t\tprops: { points },\n\t\t} = next\n\t\tconst pointKeys = Object.keys(points)\n\n\t\tif (pointKeys.length < 2) {\n\t\t\treturn\n\t\t}\n\n\t\tconst firstPoint = points[pointKeys[0]]\n\t\tconst allSame = pointKeys.every((key) => {\n\t\t\tconst point = points[key]\n\t\t\treturn point.x === firstPoint.x && point.y === firstPoint.y\n\t\t})\n\t\tif (allSame) {\n\t\t\tconst lastKey = pointKeys[pointKeys.length - 1]\n\t\t\tpoints[lastKey] = {\n\t\t\t\t...points[lastKey],\n\t\t\t\tx: points[lastKey].x + 0.1,\n\t\t\t\ty: points[lastKey].y + 0.1,\n\t\t\t}\n\t\t\treturn next\n\t\t}\n\t\treturn\n\t}\n\n\toverride onHandleDrag(shape: TLLineShape, { handle }: TLHandleDragInfo<TLLineShape>) {\n\t\tconst newPoint = maybeSnapToGrid(new Vec(handle.x, handle.y), this.editor)\n\t\treturn {\n\t\t\t...shape,\n\t\t\tprops: {\n\t\t\t\t...shape.props,\n\t\t\t\tpoints: {\n\t\t\t\t\t...shape.props.points,\n\t\t\t\t\t[handle.id]: { id: handle.id, index: handle.index, x: newPoint.x, y: newPoint.y },\n\t\t\t\t},\n\t\t\t},\n\t\t}\n\t}\n\n\toverride onHandleDragStart(shape: TLLineShape, { handle }: TLHandleDragInfo<TLLineShape>) {\n\t\t// For line shapes, if we're dragging a \"create\" handle, then\n\t\t// create a new vertex handle at that point; and make this handle\n\t\t// the handle that we're dragging.\n\t\tif (handle.type === 'create') {\n\t\t\treturn {\n\t\t\t\t...shape,\n\t\t\t\tprops: {\n\t\t\t\t\t...shape.props,\n\t\t\t\t\tpoints: {\n\t\t\t\t\t\t...shape.props.points,\n\t\t\t\t\t\t[handle.index]: { id: handle.index, index: handle.index, x: handle.x, y: handle.y },\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t}\n\t\t}\n\t\treturn\n\t}\n\n\tcomponent(shape: TLLineShape) {\n\t\t// eslint-disable-next-line react-hooks/rules-of-hooks\n\t\tconst colorMode = useColorMode()\n\t\tconst dv = getDisplayValues(this, shape, colorMode)\n\t\treturn (\n\t\t\t<SVGContainer style={{ minWidth: 50, minHeight: 50 }}>\n\t\t\t\t<LineShapeSvg shape={shape} strokeColor={dv.strokeColor} strokeWidth={dv.strokeWidth} />\n\t\t\t</SVGContainer>\n\t\t)\n\t}\n\n\toverride getIndicatorPath(shape: TLLineShape): Path2D {\n\t\tconst strokeWidth = getDisplayValues(this, shape).strokeWidth * shape.props.scale\n\t\tconst path = getPathForLineShape(shape)\n\t\tconst { dash } = shape.props\n\n\t\treturn path.toPath2D({\n\t\t\tstyle: dash === 'draw' ? 'draw' : 'solid',\n\t\t\tstrokeWidth: 1,\n\t\t\tpasses: 1,\n\t\t\trandomSeed: shape.id,\n\t\t\toffset: 0,\n\t\t\troundness: strokeWidth * 2,\n\t\t})\n\t}\n\n\toverride toSvg(shape: TLLineShape, ctx: SvgExportContext) {\n\t\tconst dv = getDisplayValues(this, shape, ctx.colorMode)\n\t\treturn (\n\t\t\t<LineShapeSvg\n\t\t\t\tshouldScale\n\t\t\t\tshape={shape}\n\t\t\t\tstrokeColor={dv.strokeColor}\n\t\t\t\tstrokeWidth={dv.strokeWidth}\n\t\t\t/>\n\t\t)\n\t}\n\n\toverride getHandleSnapGeometry(shape: TLLineShape): HandleSnapGeometry {\n\t\tconst points = linePointsToArray(shape)\n\t\treturn {\n\t\t\tpoints,\n\t\t\tgetSelfSnapPoints: (handle) => {\n\t\t\t\tconst index = this.getHandles(shape)\n\t\t\t\t\t.filter((h) => h.type === 'vertex')\n\t\t\t\t\t.findIndex((h) => h.id === handle.id)!\n\n\t\t\t\t// We want to skip the current and adjacent handles\n\t\t\t\treturn points.filter((_, i) => Math.abs(i - index) > 1).map(Vec.From)\n\t\t\t},\n\t\t\tgetSelfSnapOutline: (handle) => {\n\t\t\t\t// We want to skip the segments that include the handle, so\n\t\t\t\t// find the index of the handle that shares the same index property\n\t\t\t\t// as the initial dragging handle; this catches a quirk of create handles\n\t\t\t\tconst index = this.getHandles(shape)\n\t\t\t\t\t.filter((h) => h.type === 'vertex')\n\t\t\t\t\t.findIndex((h) => h.id === handle.id)!\n\n\t\t\t\t// Get all the outline segments from the shape that don't include the handle\n\t\t\t\tconst segments = this.getGeometry(shape)\n\t\t\t\t\t.getSegments()\n\t\t\t\t\t.filter((_, i) => i !== index - 1 && i !== index)\n\n\t\t\t\tif (!segments.length) return null\n\t\t\t\treturn new Group2d({ children: segments })\n\t\t\t},\n\t\t}\n\t}\n\toverride getInterpolatedProps(\n\t\tstartShape: TLLineShape,\n\t\tendShape: TLLineShape,\n\t\tt: number\n\t): TLLineShape['props'] {\n\t\tconst startPoints = linePointsToArray(startShape)\n\t\tconst endPoints = linePointsToArray(endShape)\n\n\t\tconst pointsToUseStart: TLLineShapePoint[] = []\n\t\tconst pointsToUseEnd: TLLineShapePoint[] = []\n\n\t\tlet index = ZERO_INDEX_KEY\n\n\t\tif (startPoints.length > endPoints.length) {\n\t\t\t// we'll need to expand points\n\t\t\tfor (let i = 0; i < startPoints.length; i++) {\n\t\t\t\tpointsToUseStart[i] = { ...startPoints[i] }\n\t\t\t\tif (endPoints[i] === undefined) {\n\t\t\t\t\tpointsToUseEnd[i] = { ...endPoints[endPoints.length - 1], id: index }\n\t\t\t\t} else {\n\t\t\t\t\tpointsToUseEnd[i] = { ...endPoints[i], id: index }\n\t\t\t\t}\n\t\t\t\tindex = getIndexAbove(index)\n\t\t\t}\n\t\t} else if (endPoints.length > startPoints.length) {\n\t\t\t// we'll need to converge points\n\t\t\tfor (let i = 0; i < endPoints.length; i++) {\n\t\t\t\tpointsToUseEnd[i] = { ...endPoints[i] }\n\t\t\t\tif (startPoints[i] === undefined) {\n\t\t\t\t\tpointsToUseStart[i] = {\n\t\t\t\t\t\t...startPoints[startPoints.length - 1],\n\t\t\t\t\t\tid: index,\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tpointsToUseStart[i] = { ...startPoints[i], id: index }\n\t\t\t\t}\n\t\t\t\tindex = getIndexAbove(index)\n\t\t\t}\n\t\t} else {\n\t\t\t// noop, easy\n\t\t\tfor (let i = 0; i < endPoints.length; i++) {\n\t\t\t\tpointsToUseStart[i] = startPoints[i]\n\t\t\t\tpointsToUseEnd[i] = endPoints[i]\n\t\t\t}\n\t\t}\n\n\t\treturn {\n\t\t\t...(t > 0.5 ? endShape.props : startShape.props),\n\t\t\tpoints: Object.fromEntries(\n\t\t\t\tpointsToUseStart.map((point, i) => {\n\t\t\t\t\tconst endPoint = pointsToUseEnd[i]\n\t\t\t\t\treturn [\n\t\t\t\t\t\tpoint.id,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t...point,\n\t\t\t\t\t\t\tx: lerp(point.x, endPoint.x, t),\n\t\t\t\t\t\t\ty: lerp(point.y, endPoint.y, t),\n\t\t\t\t\t\t},\n\t\t\t\t\t]\n\t\t\t\t})\n\t\t\t),\n\t\t\tscale: lerp(startShape.props.scale, endShape.props.scale, t),\n\t\t}\n\t}\n}\n\nfunction linePointsToArray(shape: TLLineShape) {\n\treturn Object.values(shape.props.points).sort(sortByIndex)\n}\n\nconst pathCache = new WeakCache<TLLineShape, PathBuilder>()\nfunction getPathForLineShape(shape: TLLineShape): PathBuilder {\n\treturn pathCache.get(shape, () => {\n\t\tconst points = linePointsToArray(shape).map(Vec.From)\n\n\t\tswitch (shape.props.spline) {\n\t\t\tcase 'cubic': {\n\t\t\t\treturn PathBuilder.cubicSplineThroughPoints(points, { endOffsets: 0 })\n\t\t\t}\n\t\t\tcase 'line': {\n\t\t\t\treturn PathBuilder.lineThroughPoints(points, { endOffsets: 0 })\n\t\t\t}\n\t\t}\n\t})\n}\n\nfunction LineShapeSvg({\n\tshape,\n\tshouldScale = false,\n\tforceSolid = false,\n\tstrokeColor,\n\tstrokeWidth: baseStrokeWidth,\n}: {\n\tshape: TLLineShape\n\tshouldScale?: boolean\n\tforceSolid?: boolean\n\tstrokeColor: string\n\tstrokeWidth: number\n}) {\n\tconst path = getPathForLineShape(shape)\n\tconst { dash } = shape.props\n\n\tconst scaleFactor = 1 / shape.props.scale\n\n\tconst scale = shouldScale ? scaleFactor : 1\n\n\tconst strokeWidth = baseStrokeWidth * shape.props.scale\n\n\treturn path.toSvg({\n\t\tstyle: dash,\n\t\tstrokeWidth,\n\t\tforceSolid,\n\t\trandomSeed: shape.id,\n\t\tprops: {\n\t\t\ttransform: `scale(${scale})`,\n\t\t\tstroke: strokeColor,\n\t\t\tfill: 'none',\n\t\t},\n\t})\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
4
|
+
"sourcesContent": ["// oxlint-disable typescript/no-empty-object-type\nimport {\n\tGroup2d,\n\tHandleSnapGeometry,\n\tSVGContainer,\n\tShapeUtil,\n\tSvgExportContext,\n\tTLHandle,\n\tTLHandleDragInfo,\n\tTLLineShape,\n\tTLLineShapePoint,\n\tTLResizeInfo,\n\tVec,\n\tWeakCache,\n\tZERO_INDEX_KEY,\n\tassert,\n\tgetColorValue,\n\tgetIndexAbove,\n\tgetIndexBetween,\n\tgetIndices,\n\tlerp,\n\tlineShapeMigrations,\n\tlineShapeProps,\n\tmapObjectMapValues,\n\tmaybeSnapToGrid,\n\tsortByIndex,\n\tuseColorMode,\n} from '@tldraw/editor'\nimport { STROKE_SIZES } from '../shared/default-shape-constants'\nimport { ShapeOptionsWithDisplayValues, getDisplayValues } from '../shared/getDisplayValues'\nimport { PathBuilder, PathBuilderGeometry2d } from '../shared/PathBuilder'\n\nconst handlesCache = new WeakCache<TLLineShape['props'], TLHandle[]>()\n\n/** @public */\nexport interface LineShapeUtilDisplayValues {\n\tstrokeColor: string\n\tstrokeWidth: number\n}\n\n/** @public */\nexport interface LineShapeOptions extends ShapeOptionsWithDisplayValues<\n\tTLLineShape,\n\tLineShapeUtilDisplayValues\n> {}\n\n/** @public */\nexport class LineShapeUtil extends ShapeUtil<TLLineShape> {\n\tstatic override type = 'line' as const\n\tstatic override props = lineShapeProps\n\tstatic override migrations = lineShapeMigrations\n\n\toverride options: LineShapeOptions = {\n\t\tgetDefaultDisplayValues(_editor, shape, theme, colorMode): LineShapeUtilDisplayValues {\n\t\t\tconst { color, size } = shape.props\n\t\t\treturn {\n\t\t\t\tstrokeColor: getColorValue(theme.colors[colorMode], color, 'solid'),\n\t\t\t\tstrokeWidth: theme.strokeWidth * STROKE_SIZES[size],\n\t\t\t}\n\t\t},\n\t\tgetCustomDisplayValues(): Partial<LineShapeUtilDisplayValues> {\n\t\t\treturn {}\n\t\t},\n\t}\n\n\toverride hideResizeHandles(shape: TLLineShape) {\n\t\treturn true\n\t}\n\toverride hideRotateHandle(shape: TLLineShape) {\n\t\treturn true\n\t}\n\toverride hideSelectionBoundsFg(shape: TLLineShape) {\n\t\treturn true\n\t}\n\toverride hideSelectionBoundsBg(shape: TLLineShape) {\n\t\treturn true\n\t}\n\toverride hideInMinimap() {\n\t\treturn true\n\t}\n\n\toverride getDefaultProps(): TLLineShape['props'] {\n\t\tconst [start, end] = getIndices(2)\n\t\treturn {\n\t\t\tdash: 'draw',\n\t\t\tsize: 'm',\n\t\t\tcolor: 'black',\n\t\t\tspline: 'line',\n\t\t\tpoints: {\n\t\t\t\t[start]: { id: start, index: start, x: 0, y: 0 },\n\t\t\t\t[end]: { id: end, index: end, x: 0.1, y: 0.1 },\n\t\t\t},\n\t\t\tscale: 1,\n\t\t}\n\t}\n\n\tgetGeometry(shape: TLLineShape) {\n\t\t// todo: should we have min size?\n\t\tconst geometry = getPathForLineShape(shape).toGeometry()\n\t\tassert(geometry instanceof PathBuilderGeometry2d)\n\t\treturn geometry\n\t}\n\n\toverride getHandles(shape: TLLineShape) {\n\t\treturn handlesCache.get(shape.props, () => {\n\t\t\tconst spline = this.getGeometry(shape)\n\n\t\t\tconst points = linePointsToArray(shape)\n\t\t\tconst results: TLHandle[] = points.map((point) => ({\n\t\t\t\t...point,\n\t\t\t\t// A vertex handle's id is the point's stable id (its map key), not its\n\t\t\t\t// index. The index is only ever used for ordering (sortByIndex) and for\n\t\t\t\t// computing the create-handle positions below.\n\t\t\t\tid: point.id,\n\t\t\t\ttype: 'vertex',\n\t\t\t\tcanSnap: true,\n\t\t\t}))\n\n\t\t\tfor (let i = 0; i < points.length - 1; i++) {\n\t\t\t\tconst index = getIndexBetween(points[i].index, points[i + 1].index)\n\t\t\t\tconst segment = spline.getSegments()[i]\n\t\t\t\tconst point = segment.interpolateAlongEdge(0.5)\n\t\t\t\tresults.push({\n\t\t\t\t\tid: index,\n\t\t\t\t\ttype: 'create',\n\t\t\t\t\tindex,\n\t\t\t\t\tx: point.x,\n\t\t\t\t\ty: point.y,\n\t\t\t\t\tcanSnap: true,\n\t\t\t\t})\n\t\t\t}\n\n\t\t\treturn results.sort(sortByIndex)\n\t\t})\n\t}\n\n\t// Events\n\n\toverride onResize(shape: TLLineShape, info: TLResizeInfo<TLLineShape>) {\n\t\tconst { scaleX, scaleY } = info\n\n\t\treturn {\n\t\t\tprops: {\n\t\t\t\tpoints: mapObjectMapValues(shape.props.points, (_, { id, index, x, y }) => ({\n\t\t\t\t\tid,\n\t\t\t\t\tindex,\n\t\t\t\t\tx: x * scaleX,\n\t\t\t\t\ty: y * scaleY,\n\t\t\t\t})),\n\t\t\t},\n\t\t}\n\t}\n\n\toverride onBeforeCreate(next: TLLineShape): void | TLLineShape {\n\t\tconst {\n\t\t\tprops: { points },\n\t\t} = next\n\t\tconst pointKeys = Object.keys(points)\n\n\t\tif (pointKeys.length < 2) {\n\t\t\treturn\n\t\t}\n\n\t\tconst firstPoint = points[pointKeys[0]]\n\t\tconst allSame = pointKeys.every((key) => {\n\t\t\tconst point = points[key]\n\t\t\treturn point.x === firstPoint.x && point.y === firstPoint.y\n\t\t})\n\t\tif (allSame) {\n\t\t\tconst lastKey = pointKeys[pointKeys.length - 1]\n\t\t\tpoints[lastKey] = {\n\t\t\t\t...points[lastKey],\n\t\t\t\tx: points[lastKey].x + 0.1,\n\t\t\t\ty: points[lastKey].y + 0.1,\n\t\t\t}\n\t\t\treturn next\n\t\t}\n\t\treturn\n\t}\n\n\toverride onHandleDrag(shape: TLLineShape, { handle }: TLHandleDragInfo<TLLineShape>) {\n\t\tconst newPoint = maybeSnapToGrid(new Vec(handle.x, handle.y), this.editor)\n\t\t// handle.id is the point's key (== its id), so we update the point in place.\n\t\treturn {\n\t\t\t...shape,\n\t\t\tprops: {\n\t\t\t\t...shape.props,\n\t\t\t\tpoints: {\n\t\t\t\t\t...shape.props.points,\n\t\t\t\t\t[handle.id]: { id: handle.id, index: handle.index, x: newPoint.x, y: newPoint.y },\n\t\t\t\t},\n\t\t\t},\n\t\t}\n\t}\n\n\toverride onHandleDragStart(shape: TLLineShape, { handle }: TLHandleDragInfo<TLLineShape>) {\n\t\t// For line shapes, if we're dragging a \"create\" handle, then\n\t\t// create a new vertex handle at that point; and make this handle\n\t\t// the handle that we're dragging.\n\t\tif (handle.type === 'create') {\n\t\t\treturn {\n\t\t\t\t...shape,\n\t\t\t\tprops: {\n\t\t\t\t\t...shape.props,\n\t\t\t\t\tpoints: {\n\t\t\t\t\t\t...shape.props.points,\n\t\t\t\t\t\t[handle.index]: { id: handle.index, index: handle.index, x: handle.x, y: handle.y },\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t}\n\t\t}\n\t\treturn\n\t}\n\n\tcomponent(shape: TLLineShape) {\n\t\t// eslint-disable-next-line react-hooks/rules-of-hooks\n\t\tconst colorMode = useColorMode()\n\t\tconst dv = getDisplayValues(this, shape, colorMode)\n\t\treturn (\n\t\t\t<SVGContainer style={{ minWidth: 50, minHeight: 50 }}>\n\t\t\t\t<LineShapeSvg shape={shape} strokeColor={dv.strokeColor} strokeWidth={dv.strokeWidth} />\n\t\t\t</SVGContainer>\n\t\t)\n\t}\n\n\toverride getIndicatorPath(shape: TLLineShape): Path2D {\n\t\tconst strokeWidth = getDisplayValues(this, shape).strokeWidth * shape.props.scale\n\t\tconst path = getPathForLineShape(shape)\n\t\tconst { dash } = shape.props\n\n\t\treturn path.toPath2D({\n\t\t\tstyle: dash === 'draw' ? 'draw' : 'solid',\n\t\t\tstrokeWidth: 1,\n\t\t\tpasses: 1,\n\t\t\trandomSeed: shape.id,\n\t\t\toffset: 0,\n\t\t\troundness: strokeWidth * 2,\n\t\t})\n\t}\n\n\toverride toSvg(shape: TLLineShape, ctx: SvgExportContext) {\n\t\tconst dv = getDisplayValues(this, shape, ctx.colorMode)\n\t\treturn (\n\t\t\t<LineShapeSvg\n\t\t\t\tshouldScale\n\t\t\t\tshape={shape}\n\t\t\t\tstrokeColor={dv.strokeColor}\n\t\t\t\tstrokeWidth={dv.strokeWidth}\n\t\t\t/>\n\t\t)\n\t}\n\n\toverride getHandleSnapGeometry(shape: TLLineShape): HandleSnapGeometry {\n\t\tconst points = linePointsToArray(shape)\n\t\treturn {\n\t\t\tpoints,\n\t\t\tgetSelfSnapPoints: (handle) => {\n\t\t\t\tconst index = this.getHandles(shape)\n\t\t\t\t\t.filter((h) => h.type === 'vertex')\n\t\t\t\t\t.findIndex((h) => h.id === handle.id)!\n\n\t\t\t\t// We want to skip the current and adjacent handles\n\t\t\t\treturn points.filter((_, i) => Math.abs(i - index) > 1).map(Vec.From)\n\t\t\t},\n\t\t\tgetSelfSnapOutline: (handle) => {\n\t\t\t\t// We want to skip the segments that include the handle, so\n\t\t\t\t// find the index of the handle that shares the same index property\n\t\t\t\t// as the initial dragging handle; this catches a quirk of create handles\n\t\t\t\tconst index = this.getHandles(shape)\n\t\t\t\t\t.filter((h) => h.type === 'vertex')\n\t\t\t\t\t.findIndex((h) => h.id === handle.id)!\n\n\t\t\t\t// Get all the outline segments from the shape that don't include the handle\n\t\t\t\tconst segments = this.getGeometry(shape)\n\t\t\t\t\t.getSegments()\n\t\t\t\t\t.filter((_, i) => i !== index - 1 && i !== index)\n\n\t\t\t\tif (!segments.length) return null\n\t\t\t\treturn new Group2d({ children: segments })\n\t\t\t},\n\t\t}\n\t}\n\toverride getInterpolatedProps(\n\t\tstartShape: TLLineShape,\n\t\tendShape: TLLineShape,\n\t\tt: number\n\t): TLLineShape['props'] {\n\t\tconst startPoints = linePointsToArray(startShape)\n\t\tconst endPoints = linePointsToArray(endShape)\n\n\t\tconst pointsToUseStart: TLLineShapePoint[] = []\n\t\tconst pointsToUseEnd: TLLineShapePoint[] = []\n\n\t\tlet index = ZERO_INDEX_KEY\n\n\t\tif (startPoints.length > endPoints.length) {\n\t\t\t// we'll need to expand points\n\t\t\tfor (let i = 0; i < startPoints.length; i++) {\n\t\t\t\tpointsToUseStart[i] = { ...startPoints[i] }\n\t\t\t\tif (endPoints[i] === undefined) {\n\t\t\t\t\tpointsToUseEnd[i] = { ...endPoints[endPoints.length - 1], id: index }\n\t\t\t\t} else {\n\t\t\t\t\tpointsToUseEnd[i] = { ...endPoints[i], id: index }\n\t\t\t\t}\n\t\t\t\tindex = getIndexAbove(index)\n\t\t\t}\n\t\t} else if (endPoints.length > startPoints.length) {\n\t\t\t// we'll need to converge points\n\t\t\tfor (let i = 0; i < endPoints.length; i++) {\n\t\t\t\tpointsToUseEnd[i] = { ...endPoints[i] }\n\t\t\t\tif (startPoints[i] === undefined) {\n\t\t\t\t\tpointsToUseStart[i] = {\n\t\t\t\t\t\t...startPoints[startPoints.length - 1],\n\t\t\t\t\t\tid: index,\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tpointsToUseStart[i] = { ...startPoints[i], id: index }\n\t\t\t\t}\n\t\t\t\tindex = getIndexAbove(index)\n\t\t\t}\n\t\t} else {\n\t\t\t// noop, easy\n\t\t\tfor (let i = 0; i < endPoints.length; i++) {\n\t\t\t\tpointsToUseStart[i] = startPoints[i]\n\t\t\t\tpointsToUseEnd[i] = endPoints[i]\n\t\t\t}\n\t\t}\n\n\t\treturn {\n\t\t\t...(t > 0.5 ? endShape.props : startShape.props),\n\t\t\tpoints: Object.fromEntries(\n\t\t\t\tpointsToUseStart.map((point, i) => {\n\t\t\t\t\tconst endPoint = pointsToUseEnd[i]\n\t\t\t\t\treturn [\n\t\t\t\t\t\tpoint.id,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t...point,\n\t\t\t\t\t\t\tx: lerp(point.x, endPoint.x, t),\n\t\t\t\t\t\t\ty: lerp(point.y, endPoint.y, t),\n\t\t\t\t\t\t},\n\t\t\t\t\t]\n\t\t\t\t})\n\t\t\t),\n\t\t\tscale: lerp(startShape.props.scale, endShape.props.scale, t),\n\t\t}\n\t}\n}\n\nfunction linePointsToArray(shape: TLLineShape) {\n\tconst sorted = Object.values(shape.props.points).sort(sortByIndex)\n\t// Tolerate malformed data where two points share an index: keep only the first\n\t// point at each index, so getHandles' getIndexBetween never sees equal adjacent\n\t// indices (which would throw \"a2 >= a2\"). A no-op for well-formed lines.\n\treturn sorted.filter((point, i) => i === 0 || point.index !== sorted[i - 1].index)\n}\n\nconst pathCache = new WeakCache<TLLineShape, PathBuilder>()\nfunction getPathForLineShape(shape: TLLineShape): PathBuilder {\n\treturn pathCache.get(shape, () => {\n\t\tconst points = linePointsToArray(shape).map(Vec.From)\n\n\t\tswitch (shape.props.spline) {\n\t\t\tcase 'cubic': {\n\t\t\t\treturn PathBuilder.cubicSplineThroughPoints(points, { endOffsets: 0 })\n\t\t\t}\n\t\t\tcase 'line': {\n\t\t\t\treturn PathBuilder.lineThroughPoints(points, { endOffsets: 0 })\n\t\t\t}\n\t\t}\n\t})\n}\n\nfunction LineShapeSvg({\n\tshape,\n\tshouldScale = false,\n\tforceSolid = false,\n\tstrokeColor,\n\tstrokeWidth: baseStrokeWidth,\n}: {\n\tshape: TLLineShape\n\tshouldScale?: boolean\n\tforceSolid?: boolean\n\tstrokeColor: string\n\tstrokeWidth: number\n}) {\n\tconst path = getPathForLineShape(shape)\n\tconst { dash } = shape.props\n\n\tconst scaleFactor = 1 / shape.props.scale\n\n\tconst scale = shouldScale ? scaleFactor : 1\n\n\tconst strokeWidth = baseStrokeWidth * shape.props.scale\n\n\treturn path.toSvg({\n\t\tstyle: dash,\n\t\tstrokeWidth,\n\t\tforceSolid,\n\t\trandomSeed: shape.id,\n\t\tprops: {\n\t\t\ttransform: `scale(${scale})`,\n\t\t\tstroke: strokeColor,\n\t\t\tfill: 'none',\n\t\t},\n\t})\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA4NI;AA3NJ,oBA0BO;AACP,qCAA6B;AAC7B,8BAAgE;AAChE,yBAAmD;AAEnD,MAAM,eAAe,IAAI,wBAA4C;AAe9D,MAAM,sBAAsB,wBAAuB;AAAA,EACzD,OAAgB,OAAO;AAAA,EACvB,OAAgB,QAAQ;AAAA,EACxB,OAAgB,aAAa;AAAA,EAEpB,UAA4B;AAAA,IACpC,wBAAwB,SAAS,OAAO,OAAO,WAAuC;AACrF,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AAM;AAEvB,QAAM,cAAc,IAAI,MAAM,MAAM;AAEpC,QAAM,QAAQ,cAAc,cAAc;AAE1C,QAAM,cAAc,kBAAkB,MAAM,MAAM;AAElD,SAAO,KAAK,MAAM;AAAA,IACjB,OAAO;AAAA,IACP;AAAA,IACA;AAAA,IACA,YAAY,MAAM;AAAA,IAClB,OAAO;AAAA,MACN,WAAW,SAAS,KAAK;AAAA,MACzB,QAAQ;AAAA,MACR,MAAM;AAAA,IACP;AAAA,EACD,CAAC;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -119,7 +119,7 @@ class Pointing extends import_editor.StateNode {
|
|
|
119
119
|
this.complete();
|
|
120
120
|
}
|
|
121
121
|
onLongPress() {
|
|
122
|
-
|
|
122
|
+
if (this.editor.getInstanceState().isCoarsePointer) this.cancel();
|
|
123
123
|
}
|
|
124
124
|
onCancel() {
|
|
125
125
|
this.cancel();
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/lib/shapes/line/toolStates/Pointing.ts"],
|
|
4
|
-
"sourcesContent": ["import {\n\tMat,\n\tStateNode,\n\tTLLineShape,\n\tTLShapeId,\n\tVec,\n\tcreateShapeId,\n\tgetIndexAbove,\n\
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,
|
|
4
|
+
"sourcesContent": ["import {\n\tMat,\n\tStateNode,\n\tTLLineShape,\n\tTLShapeId,\n\tVec,\n\tcreateShapeId,\n\tgetIndexAbove,\n\tlast,\n\tmaybeSnapToGrid,\n\tsortByIndex,\n\tstructuredClone,\n} from '@tldraw/editor'\n\n// Minimum distance, in screen pixels, between two shift-clicked handles before we merge them\nconst MINIMUM_DISTANCE_BETWEEN_SHIFT_CLICKED_HANDLES = 2\n\nexport class Pointing extends StateNode {\n\tstatic override id = 'pointing'\n\n\tshape = {} as TLLineShape\n\n\tmarkId: string | undefined\n\n\toverride onEnter(info: { shapeId?: TLShapeId }) {\n\t\tconst { inputs } = this.editor\n\t\tconst currentPagePoint = inputs.getCurrentPagePoint()\n\n\t\tthis.markId = undefined\n\n\t\t// Previously created line shape that we might be extending\n\t\tconst shape = info.shapeId && this.editor.getShape<TLLineShape>(info.shapeId)\n\n\t\tif (shape && inputs.getShiftKey()) {\n\t\t\t// Extending a previous shape\n\t\t\tthis.markId = this.editor.markHistoryStoppingPoint(`creating_line:${shape.id}`)\n\t\t\tthis.shape = shape\n\n\t\t\tconst handles = this.editor.getShapeHandles(this.shape)\n\t\t\tif (!handles) return\n\n\t\t\tconst vertexHandles = handles.filter((h) => h.type === 'vertex').sort(sortByIndex)\n\t\t\tconst endHandle = vertexHandles[vertexHandles.length - 1]\n\t\t\tconst prevEndHandle = vertexHandles[vertexHandles.length - 2]\n\n\t\t\tconst shapePagePoint = Mat.applyToPoint(\n\t\t\t\tthis.editor.getShapeParentTransform(this.shape)!,\n\t\t\t\tnew Vec(this.shape.x, this.shape.y)\n\t\t\t)\n\t\t\t// nudge the point slightly to avoid zero-length lines\n\t\t\tconst nudgedPoint = Vec.Sub(currentPagePoint, shapePagePoint).addXY(0.1, 0.1)\n\t\t\tconst nextPoint = maybeSnapToGrid(nudgedPoint, this.editor)\n\t\t\tconst points = structuredClone(this.shape.props.points)\n\n\t\t\t// compare in screen space\n\t\t\tconst minDistance =\n\t\t\t\tMINIMUM_DISTANCE_BETWEEN_SHIFT_CLICKED_HANDLES / this.editor.getZoomLevel()\n\n\t\t\tif (\n\t\t\t\tVec.DistMin(endHandle, prevEndHandle, minDistance) ||\n\t\t\t\tVec.DistMin(nextPoint, endHandle, minDistance)\n\t\t\t) {\n\t\t\t\t// Don't add a new point if the distance between the last two points is too small\n\t\t\t\tpoints[endHandle.id] = {\n\t\t\t\t\tid: endHandle.id,\n\t\t\t\t\tindex: endHandle.index,\n\t\t\t\t\tx: nextPoint.x,\n\t\t\t\t\ty: nextPoint.y,\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// Add a new point\n\t\t\t\tconst nextIndex = getIndexAbove(endHandle.index)\n\t\t\t\tpoints[nextIndex] = {\n\t\t\t\t\tid: nextIndex,\n\t\t\t\t\tindex: nextIndex,\n\t\t\t\t\tx: nextPoint.x,\n\t\t\t\t\ty: nextPoint.y,\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tthis.editor.updateShapes([\n\t\t\t\t{\n\t\t\t\t\tid: this.shape.id,\n\t\t\t\t\ttype: this.shape.type,\n\t\t\t\t\tprops: {\n\t\t\t\t\t\tpoints,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t])\n\t\t} else {\n\t\t\tconst id = createShapeId()\n\n\t\t\tthis.markId = this.editor.markHistoryStoppingPoint(`creating_line:${id}`)\n\n\t\t\tconst newPoint = maybeSnapToGrid(currentPagePoint, this.editor)\n\n\t\t\tthis.editor.createShapes([\n\t\t\t\t{\n\t\t\t\t\tid,\n\t\t\t\t\ttype: 'line',\n\t\t\t\t\tx: newPoint.x,\n\t\t\t\t\ty: newPoint.y,\n\t\t\t\t\tprops: {\n\t\t\t\t\t\tscale: this.editor.getResizeScaleFactor(),\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t])\n\n\t\t\tif (!this.editor.getShape(id)) {\n\t\t\t\tthis.cancel()\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tthis.editor.select(id)\n\t\t\tthis.shape = this.editor.getShape(id)!\n\t\t}\n\t}\n\n\toverride onPointerMove() {\n\t\tif (!this.shape) return\n\n\t\tif (this.editor.inputs.getIsDragging()) {\n\t\t\tconst handles = this.editor.getShapeHandles(this.shape)\n\t\t\tif (!handles) {\n\t\t\t\tif (this.markId) this.editor.bailToMark(this.markId)\n\t\t\t\tthrow Error('No handles found')\n\t\t\t}\n\t\t\tconst lastHandle = last(handles)!\n\t\t\tthis.editor.setCurrentTool('select.dragging_handle', {\n\t\t\t\tshape: this.shape,\n\t\t\t\tisCreating: true,\n\t\t\t\tcreatingMarkId: this.markId,\n\t\t\t\t// remove the offset that we added to the handle when we created it\n\t\t\t\thandle: { ...lastHandle, x: lastHandle.x - 0.1, y: lastHandle.y - 0.1 },\n\t\t\t\tonInteractionEnd: 'line',\n\t\t\t})\n\t\t}\n\t}\n\n\toverride onPointerUp() {\n\t\tthis.complete()\n\t}\n\n\toverride onLongPress() {\n\t\t// On a touch (coarse pointer) long-press, cancel the pending shape so it leaves nothing behind.\n\t\tif (this.editor.getInstanceState().isCoarsePointer) this.cancel()\n\t}\n\n\toverride onCancel() {\n\t\tthis.cancel()\n\t}\n\n\toverride onComplete() {\n\t\tthis.complete()\n\t}\n\n\toverride onInterrupt() {\n\t\tthis.parent.transition('idle')\n\t\tif (this.markId) this.editor.bailToMark(this.markId)\n\t\tthis.editor.snaps.clearIndicators()\n\t}\n\n\tcomplete() {\n\t\tthis.parent.transition('idle', { shapeId: this.shape.id })\n\t\tthis.editor.snaps.clearIndicators()\n\t}\n\n\tcancel() {\n\t\tif (this.markId) this.editor.bailToMark(this.markId)\n\t\tthis.parent.transition('idle', { shapeId: this.shape.id })\n\t\tthis.editor.snaps.clearIndicators()\n\t}\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAYO;AAGP,MAAM,iDAAiD;AAEhD,MAAM,iBAAiB,wBAAU;AAAA,EACvC,OAAgB,KAAK;AAAA,EAErB,QAAQ,CAAC;AAAA,EAET;AAAA,EAES,QAAQ,MAA+B;AAC/C,UAAM,EAAE,OAAO,IAAI,KAAK;AACxB,UAAM,mBAAmB,OAAO,oBAAoB;AAEpD,SAAK,SAAS;AAGd,UAAM,QAAQ,KAAK,WAAW,KAAK,OAAO,SAAsB,KAAK,OAAO;AAE5E,QAAI,SAAS,OAAO,YAAY,GAAG;AAElC,WAAK,SAAS,KAAK,OAAO,yBAAyB,iBAAiB,MAAM,EAAE,EAAE;AAC9E,WAAK,QAAQ;AAEb,Y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;AAAA,EACf;AAAA,EAES,cAAc;AACtB,SAAK,OAAO,WAAW,MAAM;AAC7B,QAAI,KAAK,OAAQ,MAAK,OAAO,WAAW,KAAK,MAAM;AACnD,SAAK,OAAO,MAAM,gBAAgB;AAAA,EACnC;AAAA,EAEA,WAAW;AACV,SAAK,OAAO,WAAW,QAAQ,EAAE,SAAS,KAAK,MAAM,GAAG,CAAC;AACzD,SAAK,OAAO,MAAM,gBAAgB;AAAA,EACnC;AAAA,EAEA,SAAS;AACR,QAAI,KAAK,OAAQ,MAAK,OAAO,WAAW,KAAK,MAAM;AACnD,SAAK,OAAO,WAAW,QAAQ,EAAE,SAAS,KAAK,MAAM,GAAG,CAAC;AACzD,SAAK,OAAO,MAAM,gBAAgB;AAAA,EACnC;AACD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -93,7 +93,7 @@ class Pointing extends import_editor.StateNode {
|
|
|
93
93
|
this.complete();
|
|
94
94
|
}
|
|
95
95
|
onLongPress() {
|
|
96
|
-
|
|
96
|
+
if (this.editor.getInstanceState().isCoarsePointer) this.cancel();
|
|
97
97
|
}
|
|
98
98
|
onInterrupt() {
|
|
99
99
|
this.cancel();
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/lib/shapes/note/toolStates/Pointing.ts"],
|
|
4
|
-
"sourcesContent": ["import {\n\tEditor,\n\tStateNode,\n\tTLNoteShape,\n\tTLPointerEventInfo,\n\tTLShapeId,\n\tVec,\n\tcreateShapeId,\n\
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,
|
|
4
|
+
"sourcesContent": ["import {\n\tEditor,\n\tStateNode,\n\tTLNoteShape,\n\tTLPointerEventInfo,\n\tTLShapeId,\n\tVec,\n\tcreateShapeId,\n\tmaybeSnapToGrid,\n} from '@tldraw/editor'\nimport { startEditingShapeWithRichText } from '../../../tools/SelectTool/selectHelpers'\nimport { getDisplayValues } from '../../shared/getDisplayValues'\nimport {\n\tNOTE_ADJACENT_POSITION_SNAP_RADIUS,\n\tgetAvailableNoteAdjacentPositions,\n} from '../noteHelpers'\nimport type { NoteShapeUtil } from '../NoteShapeUtil'\n\nexport class Pointing extends StateNode {\n\tstatic override id = 'pointing'\n\n\tdragged = false\n\n\tinfo = {} as TLPointerEventInfo\n\n\tmarkId = ''\n\n\tshape = {} as TLNoteShape\n\n\tprivate shapeId!: TLShapeId\n\n\tprivate shapeCenter = new Vec()\n\n\tprivate hasCreatedShape = false\n\n\toverride onEnter() {\n\t\tconst { editor } = this\n\n\t\tthis.hasCreatedShape = false\n\t\tthis.shapeId = createShapeId()\n\t\tthis.markId = editor.markHistoryStoppingPoint(`creating_note:${this.shapeId}`)\n\n\t\t// Resolve note dimensions from the util's defaults\n\t\tconst noteUtil = editor.getShapeUtil('note') as NoteShapeUtil\n\t\tconst dv = getDisplayValues(noteUtil, { props: noteUtil.getDefaultProps() } as TLNoteShape)\n\n\t\t// Check for note pits; if the pointer is close to one, place the note centered on the pit\n\t\tconst center = editor.inputs.getOriginPagePoint().clone()\n\t\tconst offset = getNoteShapeAdjacentPositionOffset(\n\t\t\teditor,\n\t\t\tcenter,\n\t\t\teditor.getResizeScaleFactor(),\n\t\t\tdv.noteWidth,\n\t\t\tdv.noteHeight\n\t\t)\n\t\tif (offset) {\n\t\t\tcenter.sub(offset)\n\t\t}\n\t\tthis.shapeCenter = center\n\n\t\t// On a coarse pointer, defer creating the note until the gesture commits (a\n\t\t// drag or a release). The note is created on press, and a long-press cancels\n\t\t// the pending creation, so without deferral the note appears on press and\n\t\t// vanishes at the long-press mark \u2014 a visible flash. On a fine pointer there\n\t\t// is no long-press cancel, so create immediately to keep the press-and-drag feel.\n\t\tif (!editor.getInstanceState().isCoarsePointer) {\n\t\t\tthis.ensureShapeCreated()\n\t\t}\n\t}\n\n\t// Create the note now if it hasn't been created yet (idempotent). The deferred\n\t// drag and release paths route through here; a max-shapes failure cancels the\n\t// gesture, matching the original onEnter behaviour.\n\tprivate ensureShapeCreated() {\n\t\tif (this.hasCreatedShape) return\n\n\t\tconst shape = createNoteShape(this.editor, this.shapeId, this.shapeCenter)\n\t\tif (shape) {\n\t\t\tthis.shape = shape\n\t\t\tthis.hasCreatedShape = true\n\t\t} else {\n\t\t\tthis.cancel()\n\t\t}\n\t}\n\n\toverride onPointerMove(info: TLPointerEventInfo) {\n\t\tif (this.editor.inputs.getIsDragging()) {\n\t\t\tthis.ensureShapeCreated()\n\t\t\tif (!this.hasCreatedShape) return\n\t\t\tthis.editor.setCurrentTool('select.translating', {\n\t\t\t\t...info,\n\t\t\t\ttarget: 'shape',\n\t\t\t\tshape: this.shape,\n\t\t\t\tonInteractionEnd: 'note',\n\t\t\t\tisCreating: true,\n\t\t\t\tcreatingMarkId: this.markId,\n\t\t\t\tonCreate: () => {\n\t\t\t\t\tstartEditingShapeWithRichText(this.editor, this.shape.id)\n\t\t\t\t},\n\t\t\t})\n\t\t}\n\t}\n\n\toverride onPointerUp() {\n\t\tthis.complete()\n\t}\n\n\toverride onLongPress() {\n\t\t// On a touch (coarse pointer) long-press, cancel the pending shape so it leaves nothing behind.\n\t\tif (this.editor.getInstanceState().isCoarsePointer) this.cancel()\n\t}\n\n\toverride onInterrupt() {\n\t\tthis.cancel()\n\t}\n\n\toverride onComplete() {\n\t\tthis.complete()\n\t}\n\n\toverride onCancel() {\n\t\tthis.cancel()\n\t}\n\n\tprivate complete() {\n\t\tthis.ensureShapeCreated()\n\t\tif (!this.hasCreatedShape) return\n\t\tif (this.editor.getInstanceState().isToolLocked) {\n\t\t\tthis.parent.transition('idle')\n\t\t} else {\n\t\t\tstartEditingShapeWithRichText(this.editor, this.shape.id, { info: this.info })\n\t\t}\n\t}\n\n\tprivate cancel() {\n\t\tthis.editor.bailToMark(this.markId)\n\t\tthis.parent.transition('idle', this.info)\n\t}\n}\n\nexport function getNoteShapeAdjacentPositionOffset(\n\teditor: Editor,\n\tcenter: Vec,\n\tscale: number,\n\tnoteWidth: number,\n\tnoteHeight: number\n) {\n\tlet min = NOTE_ADJACENT_POSITION_SNAP_RADIUS / editor.getZoomLevel() // in screen space\n\tlet offset: Vec | undefined\n\tfor (const pit of getAvailableNoteAdjacentPositions(editor, {\n\t\trotation: 0,\n\t\tscale,\n\t\textraHeight: 0,\n\t\tnoteWidth,\n\t\tnoteHeight,\n\t})) {\n\t\t// only check page rotations of zero\n\t\tconst deltaToPit = Vec.Sub(center, pit)\n\t\tconst dist = deltaToPit.len()\n\t\tif (dist < min) {\n\t\t\tmin = dist\n\t\t\toffset = deltaToPit\n\t\t}\n\t}\n\treturn offset\n}\n\nexport function createNoteShape(editor: Editor, id: TLShapeId, center: Vec) {\n\teditor.createShape({\n\t\tid,\n\t\ttype: 'note',\n\t\tx: center.x,\n\t\ty: center.y,\n\t\tprops: {\n\t\t\tscale: editor.getResizeScaleFactor(),\n\t\t},\n\t})\n\n\tconst shape = editor.getShape<TLNoteShape>(id)\n\t// Should never happen since we just checked, but just in case\n\tif (!shape) return\n\n\teditor.select(id)\n\tconst bounds = editor.getShapeGeometry(shape).bounds\n\tconst newPoint = maybeSnapToGrid(\n\t\tnew Vec(shape.x - bounds.width / 2, shape.y - bounds.height / 2),\n\t\teditor\n\t)\n\n\t// Center the text around the created point\n\teditor.updateShapes([\n\t\t{\n\t\t\tid,\n\t\t\ttype: 'note',\n\t\t\tx: newPoint.x,\n\t\t\ty: newPoint.y,\n\t\t},\n\t])\n\n\treturn editor.getShape<TLNoteShape>(id)\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBASO;AACP,2BAA8C;AAC9C,8BAAiC;AACjC,yBAGO;AAGA,MAAM,iBAAiB,wBAAU;AAAA,EACvC,OAAgB,KAAK;AAAA,EAErB,UAAU;AAAA,EAEV,OAAO,CAAC;AAAA,EAER,S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AO;AAAA,IACV,GAAG,OAAO;AAAA,IACV,OAAO;AAAA,MACN,OAAO,OAAO,qBAAqB;AAAA,IACpC;AAAA,EACD,CAAC;AAED,QAAM,QAAQ,OAAO,SAAsB,EAAE;AAE7C,MAAI,CAAC,MAAO;AAEZ,SAAO,OAAO,EAAE;AAChB,QAAM,SAAS,OAAO,iBAAiB,KAAK,EAAE;AAC9C,QAAM,eAAW;AAAA,IAChB,IAAI,kBAAI,MAAM,IAAI,OAAO,QAAQ,GAAG,MAAM,IAAI,OAAO,SAAS,CAAC;AAAA,IAC/D;AAAA,EACD;AAGA,SAAO,aAAa;AAAA,IACnB;AAAA,MACC;AAAA,MACA,MAAM;AAAA,MACN,GAAG,SAAS;AAAA,MACZ,GAAG,SAAS;AAAA,IACb;AAAA,EACD,CAAC;AAED,SAAO,OAAO,SAAsB,EAAE;AACvC;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -83,7 +83,7 @@ function createCropAroundCenter(centerX, centerY, width, height, isCircle) {
|
|
|
83
83
|
};
|
|
84
84
|
}
|
|
85
85
|
function getCropBox(shape, info, opts = {}) {
|
|
86
|
-
const { handle, change, crop, aspectRatioLocked } = info;
|
|
86
|
+
const { handle, change, crop, aspectRatioLocked, isResizingFromCenter } = info;
|
|
87
87
|
const { w, h } = info.uncroppedSize;
|
|
88
88
|
const { minWidth = MIN_CROP_SIZE, minHeight = MIN_CROP_SIZE } = opts;
|
|
89
89
|
if (w < minWidth || h < minHeight || change.x === 0 && change.y === 0) {
|
|
@@ -97,21 +97,67 @@ function getCropBox(shape, info, opts = {}) {
|
|
|
97
97
|
);
|
|
98
98
|
const targetRatio = prevCropBox.aspectRatio;
|
|
99
99
|
const tempBox = prevCropBox.clone();
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
100
|
+
const movesLeft = handle === "top_left" || handle === "bottom_left" || handle === "left";
|
|
101
|
+
const movesRight = handle === "top_right" || handle === "bottom_right" || handle === "right";
|
|
102
|
+
const movesTop = handle === "top_left" || handle === "top_right" || handle === "top";
|
|
103
|
+
const movesBottom = handle === "bottom_left" || handle === "bottom_right" || handle === "bottom";
|
|
104
|
+
if (isResizingFromCenter) {
|
|
105
|
+
const cx = prevCropBox.midX;
|
|
106
|
+
const cy = prevCropBox.midY;
|
|
107
|
+
let halfW = prevCropBox.w / 2;
|
|
108
|
+
let halfH = prevCropBox.h / 2;
|
|
109
|
+
if (movesLeft) halfW = cx - (prevCropBox.x + change.x);
|
|
110
|
+
else if (movesRight) halfW = prevCropBox.maxX + change.x - cx;
|
|
111
|
+
if (movesTop) halfH = cy - (prevCropBox.y + change.y);
|
|
112
|
+
else if (movesBottom) halfH = prevCropBox.maxY + change.y - cy;
|
|
113
|
+
if (aspectRatioLocked) {
|
|
114
|
+
const isCorner = (movesLeft || movesRight) && (movesTop || movesBottom);
|
|
115
|
+
let drivingHalfW;
|
|
116
|
+
if (isCorner) {
|
|
117
|
+
drivingHalfW = halfW / halfH > targetRatio ? halfW : halfH * targetRatio;
|
|
118
|
+
} else if (movesLeft || movesRight) {
|
|
119
|
+
drivingHalfW = halfW;
|
|
120
|
+
} else {
|
|
121
|
+
drivingHalfW = halfH * targetRatio;
|
|
122
|
+
}
|
|
123
|
+
const minHalfW = Math.max(minWidth / 2, minHeight / 2 * targetRatio);
|
|
124
|
+
const maxHalfW = Math.min(cx, w - cx, cy * targetRatio, (h - cy) * targetRatio);
|
|
125
|
+
if (maxHalfW < minHalfW) return;
|
|
126
|
+
halfW = (0, import_editor.clamp)(drivingHalfW, minHalfW, maxHalfW);
|
|
127
|
+
halfH = halfW / targetRatio;
|
|
128
|
+
} else {
|
|
129
|
+
if (movesLeft || movesRight) {
|
|
130
|
+
const maxHalfW = Math.min(cx, w - cx);
|
|
131
|
+
if (maxHalfW < minWidth / 2) return;
|
|
132
|
+
halfW = (0, import_editor.clamp)(halfW, minWidth / 2, maxHalfW);
|
|
133
|
+
}
|
|
134
|
+
if (movesTop || movesBottom) {
|
|
135
|
+
const maxHalfH = Math.min(cy, h - cy);
|
|
136
|
+
if (maxHalfH < minHeight / 2) return;
|
|
137
|
+
halfH = (0, import_editor.clamp)(halfH, minHeight / 2, maxHalfH);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
tempBox.x = cx - halfW;
|
|
141
|
+
tempBox.y = cy - halfH;
|
|
142
|
+
tempBox.w = halfW * 2;
|
|
143
|
+
tempBox.h = halfH * 2;
|
|
144
|
+
} else {
|
|
145
|
+
if (movesLeft) {
|
|
146
|
+
tempBox.x = (0, import_editor.clamp)(tempBox.x + change.x, 0, prevCropBox.maxX - minWidth);
|
|
147
|
+
tempBox.w = prevCropBox.maxX - tempBox.x;
|
|
148
|
+
} else if (movesRight) {
|
|
149
|
+
const tempRight = (0, import_editor.clamp)(tempBox.maxX + change.x, prevCropBox.x + minWidth, w);
|
|
150
|
+
tempBox.w = tempRight - tempBox.x;
|
|
151
|
+
}
|
|
152
|
+
if (movesTop) {
|
|
153
|
+
tempBox.y = (0, import_editor.clamp)(tempBox.y + change.y, 0, prevCropBox.maxY - minHeight);
|
|
154
|
+
tempBox.h = prevCropBox.maxY - tempBox.y;
|
|
155
|
+
} else if (movesBottom) {
|
|
156
|
+
const tempBottom = (0, import_editor.clamp)(tempBox.maxY + change.y, prevCropBox.y + minHeight, h);
|
|
157
|
+
tempBox.h = tempBottom - tempBox.y;
|
|
158
|
+
}
|
|
113
159
|
}
|
|
114
|
-
if (aspectRatioLocked) {
|
|
160
|
+
if (aspectRatioLocked && !isResizingFromCenter) {
|
|
115
161
|
const isXLimiting = tempBox.aspectRatio > targetRatio;
|
|
116
162
|
if (isXLimiting) {
|
|
117
163
|
tempBox.h = tempBox.w / targetRatio;
|