@weasel-js/editing 0.0.0-stage → 2.0.0
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/LICENSE +21 -0
- package/README.md +60 -2
- package/dist/actionGroups.js +27 -0
- package/dist/actionGroups.js.map +1 -0
- package/dist/actions/align/action.js +105 -0
- package/dist/actions/align/action.js.map +1 -0
- package/dist/actions/align/align.js +115 -0
- package/dist/actions/align/align.js.map +1 -0
- package/dist/actions/clipboard/action.js +133 -0
- package/dist/actions/clipboard/action.js.map +1 -0
- package/dist/actions/clone/action.js +217 -0
- package/dist/actions/clone/action.js.map +1 -0
- package/dist/actions/clone/behaviors.js +65 -0
- package/dist/actions/clone/behaviors.js.map +1 -0
- package/dist/actions/delete/delete.js +123 -0
- package/dist/actions/delete/delete.js.map +1 -0
- package/dist/actions/derivedBox.js +16 -0
- package/dist/actions/derivedBox.js.map +1 -0
- package/dist/actions/distribute/action.js +96 -0
- package/dist/actions/distribute/action.js.map +1 -0
- package/dist/actions/distribute/distribute.js +61 -0
- package/dist/actions/distribute/distribute.js.map +1 -0
- package/dist/actions/distribute/plan.js +55 -0
- package/dist/actions/distribute/plan.js.map +1 -0
- package/dist/actions/edit/createPaintAction.js +138 -0
- package/dist/actions/edit/createPaintAction.js.map +1 -0
- package/dist/actions/edit/deselect.js +34 -0
- package/dist/actions/edit/deselect.js.map +1 -0
- package/dist/actions/edit/duplicate.js +93 -0
- package/dist/actions/edit/duplicate.js.map +1 -0
- package/dist/actions/edit/group.js +281 -0
- package/dist/actions/edit/group.js.map +1 -0
- package/dist/actions/edit/ingest.js +114 -0
- package/dist/actions/edit/ingest.js.map +1 -0
- package/dist/actions/edit/nudge.js +97 -0
- package/dist/actions/edit/nudge.js.map +1 -0
- package/dist/actions/edit/selectAll.js +48 -0
- package/dist/actions/edit/selectAll.js.map +1 -0
- package/dist/actions/edit/setFill.js +52 -0
- package/dist/actions/edit/setFill.js.map +1 -0
- package/dist/actions/edit/setFillOpacity.js +26 -0
- package/dist/actions/edit/setFillOpacity.js.map +1 -0
- package/dist/actions/edit/setStroke.js +57 -0
- package/dist/actions/edit/setStroke.js.map +1 -0
- package/dist/actions/edit/setStrokeOpacity.js +28 -0
- package/dist/actions/edit/setStrokeOpacity.js.map +1 -0
- package/dist/actions/edit/setStrokeWidth.js +53 -0
- package/dist/actions/edit/setStrokeWidth.js.map +1 -0
- package/dist/actions/edit/setVertexColor.js +45 -0
- package/dist/actions/edit/setVertexColor.js.map +1 -0
- package/dist/actions/flip/action.js +209 -0
- package/dist/actions/flip/action.js.map +1 -0
- package/dist/actions/flip/helpers.js +80 -0
- package/dist/actions/flip/helpers.js.map +1 -0
- package/dist/actions/group/enterGroup.js +81 -0
- package/dist/actions/group/enterGroup.js.map +1 -0
- package/dist/actions/insert/action.js +152 -0
- package/dist/actions/insert/action.js.map +1 -0
- package/dist/actions/insert/commit.js +52 -0
- package/dist/actions/insert/commit.js.map +1 -0
- package/dist/actions/insert/extras.js +88 -0
- package/dist/actions/insert/extras.js.map +1 -0
- package/dist/actions/insert/frame.js +96 -0
- package/dist/actions/insert/frame.js.map +1 -0
- package/dist/actions/insert/geometry.js +35 -0
- package/dist/actions/insert/geometry.js.map +1 -0
- package/dist/actions/insert/lands.js +41 -0
- package/dist/actions/insert/lands.js.map +1 -0
- package/dist/actions/insert/params.js +42 -0
- package/dist/actions/insert/params.js.map +1 -0
- package/dist/actions/insert/placeAction.js +137 -0
- package/dist/actions/insert/placeAction.js.map +1 -0
- package/dist/actions/insert/repositionAction.js +47 -0
- package/dist/actions/insert/repositionAction.js.map +1 -0
- package/dist/actions/insert/rotateAction.js +34 -0
- package/dist/actions/insert/rotateAction.js.map +1 -0
- package/dist/actions/insert/session.js +99 -0
- package/dist/actions/insert/session.js.map +1 -0
- package/dist/actions/insert/shape.js +117 -0
- package/dist/actions/insert/shape.js.map +1 -0
- package/dist/actions/insert/style.js +23 -0
- package/dist/actions/insert/style.js.map +1 -0
- package/dist/actions/lassoSelect/action.js +201 -0
- package/dist/actions/lassoSelect/action.js.map +1 -0
- package/dist/actions/lassoSelect/behaviors/selectFromLasso.js +61 -0
- package/dist/actions/lassoSelect/behaviors/selectFromLasso.js.map +1 -0
- package/dist/actions/lockedWrites.js +20 -0
- package/dist/actions/lockedWrites.js.map +1 -0
- package/dist/actions/move/action.js +138 -0
- package/dist/actions/move/action.js.map +1 -0
- package/dist/actions/move/behaviors/clampMove.js +42 -0
- package/dist/actions/move/behaviors/clampMove.js.map +1 -0
- package/dist/actions/move/behaviors/layoutDrop.js +84 -0
- package/dist/actions/move/behaviors/layoutDrop.js.map +1 -0
- package/dist/actions/move/behaviors/pageDrop.js +30 -0
- package/dist/actions/move/behaviors/pageDrop.js.map +1 -0
- package/dist/actions/move/behaviors/reparentOnDrop.js +44 -0
- package/dist/actions/move/behaviors/reparentOnDrop.js.map +1 -0
- package/dist/actions/move/behaviors/snapBackOrDelete.js +52 -0
- package/dist/actions/move/behaviors/snapBackOrDelete.js.map +1 -0
- package/dist/actions/move/behaviors/snapToContainer.js +214 -0
- package/dist/actions/move/behaviors/snapToContainer.js.map +1 -0
- package/dist/actions/move/behaviors/swapOnDrop.js +180 -0
- package/dist/actions/move/behaviors/swapOnDrop.js.map +1 -0
- package/dist/actions/move/capture.js +116 -0
- package/dist/actions/move/capture.js.map +1 -0
- package/dist/actions/move/commit/index.js +47 -0
- package/dist/actions/move/commit/index.js.map +1 -0
- package/dist/actions/move/commit/layoutDrop.js +68 -0
- package/dist/actions/move/commit/layoutDrop.js.map +1 -0
- package/dist/actions/move/commit/layoutRelease.js +146 -0
- package/dist/actions/move/commit/layoutRelease.js.map +1 -0
- package/dist/actions/move/commit/pageDrop.js +162 -0
- package/dist/actions/move/commit/pageDrop.js.map +1 -0
- package/dist/actions/move/commit/rebase.js +24 -0
- package/dist/actions/move/commit/rebase.js.map +1 -0
- package/dist/actions/move/commit/reparent.js +157 -0
- package/dist/actions/move/commit/reparent.js.map +1 -0
- package/dist/actions/move/delta.js +127 -0
- package/dist/actions/move/delta.js.map +1 -0
- package/dist/actions/move/dragSnap.js +55 -0
- package/dist/actions/move/dragSnap.js.map +1 -0
- package/dist/actions/move/frame.js +67 -0
- package/dist/actions/move/frame.js.map +1 -0
- package/dist/actions/move/gestureAdapter.js +36 -0
- package/dist/actions/move/gestureAdapter.js.map +1 -0
- package/dist/actions/move/landedDescendants.js +50 -0
- package/dist/actions/move/landedDescendants.js.map +1 -0
- package/dist/actions/move/layout/container.js +119 -0
- package/dist/actions/move/layout/container.js.map +1 -0
- package/dist/actions/move/layout/dragged.js +75 -0
- package/dist/actions/move/layout/dragged.js.map +1 -0
- package/dist/actions/move/layout/dropPass.js +205 -0
- package/dist/actions/move/layout/dropPass.js.map +1 -0
- package/dist/actions/move/layout/exits.js +62 -0
- package/dist/actions/move/layout/exits.js.map +1 -0
- package/dist/actions/move/layout/glide.js +70 -0
- package/dist/actions/move/layout/glide.js.map +1 -0
- package/dist/actions/move/layout/view.js +60 -0
- package/dist/actions/move/layout/view.js.map +1 -0
- package/dist/actions/move/refusal.js +49 -0
- package/dist/actions/move/refusal.js.map +1 -0
- package/dist/actions/move/session.js +105 -0
- package/dist/actions/move/session.js.map +1 -0
- package/dist/actions/move/sessionOf.js +27 -0
- package/dist/actions/move/sessionOf.js.map +1 -0
- package/dist/actions/move/translate.js +49 -0
- package/dist/actions/move/translate.js.map +1 -0
- package/dist/actions/pathfinder/action.js +109 -0
- package/dist/actions/pathfinder/action.js.map +1 -0
- package/dist/actions/pathfinder/booleanGroupAction.js +117 -0
- package/dist/actions/pathfinder/booleanGroupAction.js.map +1 -0
- package/dist/actions/pathfinder/keymap.js +51 -0
- package/dist/actions/pathfinder/keymap.js.map +1 -0
- package/dist/actions/reorder/reorder.js +245 -0
- package/dist/actions/reorder/reorder.js.map +1 -0
- package/dist/actions/resize/action.js +105 -0
- package/dist/actions/resize/action.js.map +1 -0
- package/dist/actions/resize/aspect.js +42 -0
- package/dist/actions/resize/aspect.js.map +1 -0
- package/dist/actions/resize/behaviors/clampMinSize.js +100 -0
- package/dist/actions/resize/behaviors/clampMinSize.js.map +1 -0
- package/dist/actions/resize/boxFrame.js +19 -0
- package/dist/actions/resize/boxFrame.js.map +1 -0
- package/dist/actions/resize/capture.js +121 -0
- package/dist/actions/resize/capture.js.map +1 -0
- package/dist/actions/resize/commit.js +104 -0
- package/dist/actions/resize/commit.js.map +1 -0
- package/dist/actions/resize/frame.js +171 -0
- package/dist/actions/resize/frame.js.map +1 -0
- package/dist/actions/resize/held.js +44 -0
- package/dist/actions/resize/held.js.map +1 -0
- package/dist/actions/resize/minimum.js +34 -0
- package/dist/actions/resize/minimum.js.map +1 -0
- package/dist/actions/resize/replay.js +58 -0
- package/dist/actions/resize/replay.js.map +1 -0
- package/dist/actions/resize/ruleBounds.js +11 -0
- package/dist/actions/resize/ruleBounds.js.map +1 -0
- package/dist/actions/resize/session.js +118 -0
- package/dist/actions/resize/session.js.map +1 -0
- package/dist/actions/rotate/action.js +99 -0
- package/dist/actions/rotate/action.js.map +1 -0
- package/dist/actions/rotate/commit.js +48 -0
- package/dist/actions/rotate/commit.js.map +1 -0
- package/dist/actions/rotate/frame.js +96 -0
- package/dist/actions/rotate/frame.js.map +1 -0
- package/dist/actions/rotate/replay.js +25 -0
- package/dist/actions/rotate/replay.js.map +1 -0
- package/dist/actions/rotate/session.js +135 -0
- package/dist/actions/rotate/session.js.map +1 -0
- package/dist/actions/select/areaSelect.js +83 -0
- package/dist/actions/select/areaSelect.js.map +1 -0
- package/dist/actions/select/clearSelection.js +33 -0
- package/dist/actions/select/clearSelection.js.map +1 -0
- package/dist/actions/swap/action.js +63 -0
- package/dist/actions/swap/action.js.map +1 -0
- package/dist/actions/swap/swapOps.js +160 -0
- package/dist/actions/swap/swapOps.js.map +1 -0
- package/dist/actions/transformAgain/action.js +90 -0
- package/dist/actions/transformAgain/action.js.map +1 -0
- package/dist/actions/transformAgain/transformSelection.js +49 -0
- package/dist/actions/transformAgain/transformSelection.js.map +1 -0
- package/dist/booleans/booleans.js +130 -0
- package/dist/booleans/booleans.js.map +1 -0
- package/dist/booleans/commit.js +45 -0
- package/dist/booleans/commit.js.map +1 -0
- package/dist/booleans/custom.js +48 -0
- package/dist/booleans/custom.js.map +1 -0
- package/dist/booleans/operands.js +50 -0
- package/dist/booleans/operands.js.map +1 -0
- package/dist/booleans/pieces.js +43 -0
- package/dist/booleans/pieces.js.map +1 -0
- package/dist/booleans/placement.js +37 -0
- package/dist/booleans/placement.js.map +1 -0
- package/dist/booleans/useBooleans.js +34 -0
- package/dist/booleans/useBooleans.js.map +1 -0
- package/dist/booleans/useBooleansAdapter.js +11 -0
- package/dist/booleans/useBooleansAdapter.js.map +1 -0
- package/dist/chrome/affordances/cornerResize.js +123 -0
- package/dist/chrome/affordances/cornerResize.js.map +1 -0
- package/dist/chrome/affordances/rotateCursor.js +17 -0
- package/dist/chrome/affordances/rotateCursor.js.map +1 -0
- package/dist/chrome/affordances/rotationHandle.js +117 -0
- package/dist/chrome/affordances/rotationHandle.js.map +1 -0
- package/dist/chrome/handleCommands.js +110 -0
- package/dist/chrome/handleCommands.js.map +1 -0
- package/dist/chrome/overlay.js +271 -0
- package/dist/chrome/overlay.js.map +1 -0
- package/dist/chrome/rotationBadge.js +132 -0
- package/dist/chrome/rotationBadge.js.map +1 -0
- package/dist/chrome/rotationHandleGeometry.js +49 -0
- package/dist/chrome/rotationHandleGeometry.js.map +1 -0
- package/dist/chrome/selectionChrome.js +25 -0
- package/dist/chrome/selectionChrome.js.map +1 -0
- package/dist/chrome/selectionPose.js +112 -0
- package/dist/chrome/selectionPose.js.map +1 -0
- package/dist/chrome/shapeOutline.js +137 -0
- package/dist/chrome/shapeOutline.js.map +1 -0
- package/dist/clipboard/clipboardOps.js +48 -0
- package/dist/clipboard/clipboardOps.js.map +1 -0
- package/dist/clipboard/materializePaste.js +34 -0
- package/dist/clipboard/materializePaste.js.map +1 -0
- package/dist/clipboard/osClipboard.js +67 -0
- package/dist/clipboard/osClipboard.js.map +1 -0
- package/dist/clipboard/useClipboard.js +64 -0
- package/dist/clipboard/useClipboard.js.map +1 -0
- package/dist/clipboard/wireFormat.js +108 -0
- package/dist/clipboard/wireFormat.js.map +1 -0
- package/dist/deps/areaSelect.js +42 -0
- package/dist/deps/areaSelect.js.map +1 -0
- package/dist/deps/booleans.js +99 -0
- package/dist/deps/booleans.js.map +1 -0
- package/dist/deps/insert.js +260 -0
- package/dist/deps/insert.js.map +1 -0
- package/dist/deps/lassoSelect.js +37 -0
- package/dist/deps/lassoSelect.js.map +1 -0
- package/dist/deps/presetDeps.js +40 -0
- package/dist/deps/presetDeps.js.map +1 -0
- package/dist/deps/resizePolicy.js +41 -0
- package/dist/deps/resizePolicy.js.map +1 -0
- package/dist/engine-BV9RDHOL.d.ts +339 -0
- package/dist/engine.d.ts +6 -0
- package/dist/engine.js +10 -0
- package/dist/engineStandardActions.js +54 -0
- package/dist/engineStandardActions.js.map +1 -0
- package/dist/groups.d.ts +27 -0
- package/dist/groups.js +4 -0
- package/dist/icons.gen.js +8 -0
- package/dist/icons.gen.js.map +1 -0
- package/dist/icons.table.d.ts +6 -0
- package/dist/icons.table.js +8 -0
- package/dist/icons.table.js.map +1 -0
- package/dist/icons.table.json +156 -0
- package/dist/icons2.table.js +163 -0
- package/dist/icons2.table.js.map +1 -0
- package/dist/index.d.ts +1867 -0
- package/dist/index.js +86 -0
- package/dist/ingest/ghost.js +58 -0
- package/dist/ingest/ghost.js.map +1 -0
- package/dist/ingest/imageHandler.js +80 -0
- package/dist/ingest/imageHandler.js.map +1 -0
- package/dist/ingest/kitHandlers.js +15 -0
- package/dist/ingest/kitHandlers.js.map +1 -0
- package/dist/ingest/svgHandler.js +97 -0
- package/dist/ingest/svgHandler.js.map +1 -0
- package/dist/ingest/weaselJsonHandler.js +68 -0
- package/dist/ingest/weaselJsonHandler.js.map +1 -0
- package/dist/namedPresets.js +83 -0
- package/dist/namedPresets.js.map +1 -0
- package/dist/presets/arrange.js +65 -0
- package/dist/presets/arrange.js.map +1 -0
- package/dist/presets/booleans.js +13 -0
- package/dist/presets/booleans.js.map +1 -0
- package/dist/presets/composites.js +46 -0
- package/dist/presets/composites.js.map +1 -0
- package/dist/presets/edit.js +125 -0
- package/dist/presets/edit.js.map +1 -0
- package/dist/presets/ingest.js +17 -0
- package/dist/presets/ingest.js.map +1 -0
- package/dist/presets/insert.js +28 -0
- package/dist/presets/insert.js.map +1 -0
- package/dist/presets/pathfinder.js +26 -0
- package/dist/presets/pathfinder.js.map +1 -0
- package/dist/presets/select.js +31 -0
- package/dist/presets/select.js.map +1 -0
- package/dist/presets/selection.js +13 -0
- package/dist/presets/selection.js.map +1 -0
- package/dist/presets/selectionChrome.js +15 -0
- package/dist/presets/selectionChrome.js.map +1 -0
- package/dist/presets/tools.js +84 -0
- package/dist/presets/tools.js.map +1 -0
- package/dist/presets/transform.js +52 -0
- package/dist/presets/transform.js.map +1 -0
- package/dist/presets.d.ts +104 -0
- package/dist/presets.js +15 -0
- package/dist/selection/useSelection.js +127 -0
- package/dist/selection/useSelection.js.map +1 -0
- package/dist/test-seams.d.ts +50 -0
- package/dist/test-seams.js +4 -0
- package/dist/tools/ellipse/useEllipseTool.js +72 -0
- package/dist/tools/ellipse/useEllipseTool.js.map +1 -0
- package/dist/tools/eyedropper/useEyedropperTool.js +100 -0
- package/dist/tools/eyedropper/useEyedropperTool.js.map +1 -0
- package/dist/tools/image/useImageTool.js +57 -0
- package/dist/tools/image/useImageTool.js.map +1 -0
- package/dist/tools/lasso/useLassoTool.js +96 -0
- package/dist/tools/lasso/useLassoTool.js.map +1 -0
- package/dist/tools/line/useLineTool.js +67 -0
- package/dist/tools/line/useLineTool.js.map +1 -0
- package/dist/tools/polygon/usePolygonTool.js +149 -0
- package/dist/tools/polygon/usePolygonTool.js.map +1 -0
- package/dist/tools/rect/useRectTool.js +74 -0
- package/dist/tools/rect/useRectTool.js.map +1 -0
- package/dist/tools/select/adapterPointQuery.js +56 -0
- package/dist/tools/select/adapterPointQuery.js.map +1 -0
- package/dist/tools/select/collapseDeferred.js +35 -0
- package/dist/tools/select/collapseDeferred.js.map +1 -0
- package/dist/tools/select/extendPressLocked.js +17 -0
- package/dist/tools/select/extendPressLocked.js.map +1 -0
- package/dist/tools/select/groupEntry.js +73 -0
- package/dist/tools/select/groupEntry.js.map +1 -0
- package/dist/tools/select/pressDecision.js +39 -0
- package/dist/tools/select/pressDecision.js.map +1 -0
- package/dist/tools/select/selectDeep.js +39 -0
- package/dist/tools/select/selectDeep.js.map +1 -0
- package/dist/tools/select/selectPick.js +60 -0
- package/dist/tools/select/selectPick.js.map +1 -0
- package/dist/tools/select/selectionContributions.js +191 -0
- package/dist/tools/select/selectionContributions.js.map +1 -0
- package/dist/tools/select/usePickerSelectTool.js +145 -0
- package/dist/tools/select/usePickerSelectTool.js.map +1 -0
- package/dist/tools/select/useSelectTool.js +54 -0
- package/dist/tools/select/useSelectTool.js.map +1 -0
- package/dist/tools/shared/countOption.js +24 -0
- package/dist/tools/shared/countOption.js.map +1 -0
- package/dist/tools/shared/insertToolOptions.js +8 -0
- package/dist/tools/shared/insertToolOptions.js.map +1 -0
- package/dist/tools/shared/pointerFollower.js +23 -0
- package/dist/tools/shared/pointerFollower.js.map +1 -0
- package/dist/tools/shared/styleOptions.js +76 -0
- package/dist/tools/shared/styleOptions.js.map +1 -0
- package/dist/tools/star/useStarTool.js +149 -0
- package/dist/tools/star/useStarTool.js.map +1 -0
- package/dist/tools/toolSets.js +26 -0
- package/dist/tools/toolSets.js.map +1 -0
- package/dist/useStandardActions.js +26 -0
- package/dist/useStandardActions.js.map +1 -0
- package/package.json +87 -4
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { applyUserRotation, buildExtras } from "./extras.js";
|
|
2
|
+
import { effectiveOriginMode, insertRectFor } from "./geometry.js";
|
|
3
|
+
import { insertStyleOf } from "./style.js";
|
|
4
|
+
import { minSizeOf } from "@weasel-js/core";
|
|
5
|
+
import { insertPreviewExtent } from "@weasel-js/core/engine";
|
|
6
|
+
|
|
7
|
+
// src/actions/insert/shape.ts
|
|
8
|
+
/** The node kind a binding's resolved params ask for. */
|
|
9
|
+
function insertKind(resolved) {
|
|
10
|
+
return resolved?.kind ?? "rect";
|
|
11
|
+
}
|
|
12
|
+
/** The effective endpoints: `shaped`, plus — for the `line` kind only — the
|
|
13
|
+
* alt/center reading as "mirror the start around the pointer" rather than
|
|
14
|
+
* "grow a symmetric AABB". */
|
|
15
|
+
function resolveEndpoints(shaped, kind, mode) {
|
|
16
|
+
let { start } = shaped;
|
|
17
|
+
const { current } = shaped;
|
|
18
|
+
if (kind === "line" && mode === "center") start = {
|
|
19
|
+
x: start.x - (current.x - start.x),
|
|
20
|
+
y: start.y - (current.y - start.y)
|
|
21
|
+
};
|
|
22
|
+
return {
|
|
23
|
+
start,
|
|
24
|
+
current
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
/** `current` moved out from `start` until the box they make is no smaller
|
|
28
|
+
* than `min`, along the way the drag went (rightward and down when it has
|
|
29
|
+
* not gone either way). */
|
|
30
|
+
function reachMinimum(start, current, min, mode) {
|
|
31
|
+
const k = mode === "center" ? .5 : 1;
|
|
32
|
+
const reach = (d, m) => Math.abs(d) >= m * k ? d : (d < 0 ? -1 : 1) * m * k;
|
|
33
|
+
return {
|
|
34
|
+
...current,
|
|
35
|
+
x: start.x + reach(current.x - start.x, min.width),
|
|
36
|
+
y: start.y + reach(current.y - start.y, min.height)
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
/** Kinds a minimum size does not apply to: a line has no area, and a pencil
|
|
40
|
+
* trail is drawn where the pointer went. */
|
|
41
|
+
var NO_MINIMUM = /* @__PURE__ */ new Set(["line", "pencil"]);
|
|
42
|
+
/** The shape an insert has at `frame`. The live overlay and the commit both
|
|
43
|
+
* read it from here, so they can't disagree. Extras are derived with the
|
|
44
|
+
* effective origin mode, so polygon/star center+radius follow the live Alt
|
|
45
|
+
* toggle and not the binding's nominal `originMode`. */
|
|
46
|
+
function insertShape(resolved, frame, points, userRotation, landingAt, site) {
|
|
47
|
+
const mode = effectiveOriginMode(resolved?.["originMode"], frame.altHeld);
|
|
48
|
+
const kind = insertKind(resolved);
|
|
49
|
+
const ends = resolveEndpoints(frame.shaped, kind, mode);
|
|
50
|
+
const { start } = ends;
|
|
51
|
+
const min = NO_MINIMUM.has(kind) ? null : minSizeOf(resolved);
|
|
52
|
+
const current = min ? reachMinimum(start, ends.current, min, mode) : ends.current;
|
|
53
|
+
const bounds = insertRectFor(start.x, start.y, current.x, current.y, mode);
|
|
54
|
+
const extras = buildExtras({
|
|
55
|
+
...resolved ?? {},
|
|
56
|
+
originMode: mode
|
|
57
|
+
}, start.x, start.y, current.x, current.y, points);
|
|
58
|
+
applyUserRotation(extras, userRotation);
|
|
59
|
+
if (min) extras.minSize = min;
|
|
60
|
+
const style = insertStyleOf(resolved);
|
|
61
|
+
if (style) extras.style = style;
|
|
62
|
+
const from = mode === "center" ? frame.shaped.start : start;
|
|
63
|
+
const landings = landingAt && endLandings(landingAt(from), landingAt(current));
|
|
64
|
+
return {
|
|
65
|
+
bounds,
|
|
66
|
+
extras,
|
|
67
|
+
start,
|
|
68
|
+
ends: {
|
|
69
|
+
start: {
|
|
70
|
+
x: from.x,
|
|
71
|
+
y: from.y
|
|
72
|
+
},
|
|
73
|
+
end: {
|
|
74
|
+
x: current.x,
|
|
75
|
+
y: current.y
|
|
76
|
+
},
|
|
77
|
+
...mode === "center" ? { fromCenter: true } : {},
|
|
78
|
+
...landings ? { landings } : {},
|
|
79
|
+
...site ? { site: {
|
|
80
|
+
x: site.x,
|
|
81
|
+
y: site.y
|
|
82
|
+
} } : {}
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
function endLandings(start, end) {
|
|
87
|
+
if (start === void 0 && end === void 0) return void 0;
|
|
88
|
+
return {
|
|
89
|
+
...start !== void 0 ? { start } : {},
|
|
90
|
+
...end !== void 0 ? { end } : {}
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
/** Whether a drag produced enough extent to be worth committing. The test
|
|
94
|
+
* is kind-aware because "zero size" isn't one shape:
|
|
95
|
+
* - pencil: a sample trail can be meaningful even when start ≈ end
|
|
96
|
+
* (a closed loop), so no guard at all.
|
|
97
|
+
* - line: has no area by construction. An axis-aligned line has a
|
|
98
|
+
* zero-height (or zero-width) AABB and is perfectly valid — only
|
|
99
|
+
* a zero-LENGTH drag is degenerate. (Shift-constrain makes
|
|
100
|
+
* axis-aligned the common case, which is how this surfaced.)
|
|
101
|
+
* - everything else: a zero extent in either axis is degenerate, the
|
|
102
|
+
* extent being the shape the preview draws and the dep mints
|
|
103
|
+
* (`insertPreviewExtent`): a from-center polygon's is its radius, not the box. */
|
|
104
|
+
function isCommittableExtent(bounds, extras) {
|
|
105
|
+
const kind = extras.kind;
|
|
106
|
+
if (kind === "pencil") return true;
|
|
107
|
+
if (kind === "line") return bounds.width !== 0 || bounds.height !== 0;
|
|
108
|
+
const { width, height } = insertPreviewExtent({
|
|
109
|
+
shape: kind,
|
|
110
|
+
bounds,
|
|
111
|
+
extras
|
|
112
|
+
}).bounds;
|
|
113
|
+
return width !== 0 && height !== 0;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export { insertKind, insertShape, isCommittableExtent };
|
|
117
|
+
//# sourceMappingURL=shape.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shape.js","names":[],"sources":["../../../src/actions/insert/shape.ts"],"sourcesContent":["import type { DragSample } from '@weasel-js/routing';\nimport { insertPreviewExtent, type InsertPoint, type InsertEnds, type InsertExtras } from '@weasel-js/core/engine';\nimport { applyUserRotation, buildExtras } from './extras';\nimport { insertRectFor, effectiveOriginMode } from './geometry';\nimport type { InsertFrame } from './session';\nimport { minSizeOf, type MinSize } from '@weasel-js/core';\nimport { insertStyleOf, type InsertStyle } from './style';\nimport type { InsertParams } from '@weasel-js/core';\nimport type { Rect } from '@weasel-js/geom';\n\n/** The node kind a binding's resolved params ask for. */\nexport function insertKind(resolved: Readonly<Partial<InsertParams>> | undefined): string {\n return resolved?.kind ?? 'rect';\n}\n\n/** The effective endpoints: `shaped`, plus — for the `line` kind only — the\n * alt/center reading as \"mirror the start around the pointer\" rather than\n * \"grow a symmetric AABB\". */\nfunction resolveEndpoints(\n shaped: InsertFrame['shaped'],\n kind: string,\n mode: 'corner' | 'center',\n): { start: InsertPoint; current: InsertPoint } {\n let { start } = shaped;\n const { current } = shaped;\n\n // A line has no area, so \"from center\" means the drag is a half-line:\n // mirror the start to the far side of the pointer.\n if (kind === 'line' && mode === 'center') {\n start = { x: start.x - (current.x - start.x), y: start.y - (current.y - start.y) };\n }\n return { start, current };\n}\n\n/** `current` moved out from `start` until the box they make is no smaller\n * than `min`, along the way the drag went (rightward and down when it has\n * not gone either way). */\nfunction reachMinimum(\n start: InsertPoint,\n current: InsertPoint,\n min: MinSize,\n mode: 'corner' | 'center',\n): InsertPoint {\n // A center drag makes a box twice its reach.\n const k = mode === 'center' ? 0.5 : 1;\n const reach = (d: number, m: number) => (Math.abs(d) >= m * k ? d : (d < 0 ? -1 : 1) * m * k);\n return {\n ...current,\n x: start.x + reach(current.x - start.x, min.width),\n y: start.y + reach(current.y - start.y, min.height),\n };\n}\n\n/** Kinds a minimum size does not apply to: a line has no area, and a pencil\n * trail is drawn where the pointer went. */\nconst NO_MINIMUM = new Set(['line', 'pencil']);\n\nexport interface InsertShape {\n bounds: Rect;\n extras: InsertExtras;\n /** Where the drag started, after the endpoints were resolved. */\n start: InsertPoint;\n /** The drag `bounds` came from. */\n ends: InsertEnds;\n}\n\n/** The shape an insert has at `frame`. The live overlay and the commit both\n * read it from here, so they can't disagree. Extras are derived with the\n * effective origin mode, so polygon/star center+radius follow the live Alt\n * toggle and not the binding's nominal `originMode`. */\nexport function insertShape(\n resolved: Readonly<Partial<InsertParams>> | undefined,\n frame: Pick<InsertFrame, 'shaped' | 'altHeld'>,\n points: ReadonlyArray<DragSample> | null,\n userRotation: number,\n /** The snap's landing for an end at `p` (`SpanSnap.landingAt`). */\n landingAt?: (p: InsertPoint) => unknown,\n /** The point that picked the container (`InsertEnds.site`). */\n site?: InsertPoint,\n): InsertShape {\n const mode = effectiveOriginMode(resolved?.['originMode'], frame.altHeld);\n const kind = insertKind(resolved);\n const ends = resolveEndpoints(frame.shaped, kind, mode);\n const { start } = ends;\n const min = NO_MINIMUM.has(kind) ? null : minSizeOf(resolved);\n const current = min ? reachMinimum(start, ends.current, min, mode) : ends.current;\n const bounds = insertRectFor(start.x, start.y, current.x, current.y, mode);\n const extras = buildExtras(\n { ...(resolved ?? {}), originMode: mode },\n start.x, start.y, current.x, current.y,\n points,\n );\n applyUserRotation(extras, userRotation);\n // The node keeps the minimum it was drawn to, whatever its kind's extras hold.\n if (min) (extras as { minSize?: MinSize }).minSize = min;\n const style = insertStyleOf(resolved);\n if (style) (extras as { style?: InsertStyle }).style = style;\n // A from-center drag's start is its center, a line's too, not the end mirrored from the pointer.\n const from = mode === 'center' ? frame.shaped.start : start;\n const landings = landingAt && endLandings(landingAt(from), landingAt(current));\n const drag: InsertEnds = {\n start: { x: from.x, y: from.y },\n end: { x: current.x, y: current.y },\n ...(mode === 'center' ? { fromCenter: true } : {}),\n ...(landings ? { landings } : {}),\n ...(site ? { site: { x: site.x, y: site.y } } : {}),\n };\n return { bounds, extras, start, ends: drag };\n}\n\nfunction endLandings(start: unknown, end: unknown): InsertEnds['landings'] | undefined {\n if (start === undefined && end === undefined) return undefined;\n return { ...(start !== undefined ? { start } : {}), ...(end !== undefined ? { end } : {}) };\n}\n\n/** Whether a drag produced enough extent to be worth committing. The test\n * is kind-aware because \"zero size\" isn't one shape:\n * - pencil: a sample trail can be meaningful even when start ≈ end\n * (a closed loop), so no guard at all.\n * - line: has no area by construction. An axis-aligned line has a\n * zero-height (or zero-width) AABB and is perfectly valid — only\n * a zero-LENGTH drag is degenerate. (Shift-constrain makes\n * axis-aligned the common case, which is how this surfaced.)\n * - everything else: a zero extent in either axis is degenerate, the\n * extent being the shape the preview draws and the dep mints\n * (`insertPreviewExtent`): a from-center polygon's is its radius, not the box. */\nexport function isCommittableExtent(bounds: Rect, extras: InsertExtras): boolean {\n const kind = extras.kind;\n if (kind === 'pencil') return true;\n if (kind === 'line') return bounds.width !== 0 || bounds.height !== 0;\n const { width, height } = insertPreviewExtent({ shape: kind, bounds, extras }).bounds;\n return width !== 0 && height !== 0;\n}\n"],"mappings":"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"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// src/actions/insert/style.ts
|
|
2
|
+
/** The style params an insert reads, each a shape tool's option of the same name. */
|
|
3
|
+
var STYLE_OPTION_KEYS = [
|
|
4
|
+
"fill",
|
|
5
|
+
"stroke",
|
|
6
|
+
"strokeWidth",
|
|
7
|
+
"fillRule"
|
|
8
|
+
];
|
|
9
|
+
/** The stroke width a new shape is drawn with, in world units, when nothing names one. */
|
|
10
|
+
var DEFAULT_STROKE_WIDTH = 2;
|
|
11
|
+
/** The style `params` carry, or `undefined` when they carry none. */
|
|
12
|
+
function insertStyleOf(params) {
|
|
13
|
+
if (!params) return void 0;
|
|
14
|
+
let style;
|
|
15
|
+
for (const key of STYLE_OPTION_KEYS) {
|
|
16
|
+
if (!Object.hasOwn(params, key) || params[key] === void 0) continue;
|
|
17
|
+
(style ??= {})[key] = params[key];
|
|
18
|
+
}
|
|
19
|
+
return style;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export { DEFAULT_STROKE_WIDTH, STYLE_OPTION_KEYS, insertStyleOf };
|
|
23
|
+
//# sourceMappingURL=style.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"style.js","names":[],"sources":["../../../src/actions/insert/style.ts"],"sourcesContent":["import type { Paint } from '@weasel-js/paint';\nimport type { PathFillRule } from '@weasel-js/geom';\n\n/** The style params an insert reads, each a shape tool's option of the same name. */\nexport const STYLE_OPTION_KEYS = ['fill', 'stroke', 'strokeWidth', 'fillRule'] as const;\n/** One of {@link STYLE_OPTION_KEYS}. */\nexport type StyleOptionKey = (typeof STYLE_OPTION_KEYS)[number];\n\n/** The stroke width a new shape is drawn with, in world units, when nothing names one. */\nexport const DEFAULT_STROKE_WIDTH = 2;\n\n/** The style an insert is drawn with, as `extras.style` hands it to the `insert` dep. A key left out is the dep's\n * own choice; `null` paints none of it. */\nexport interface InsertStyle {\n fill?: Paint | null;\n stroke?: Paint | null;\n strokeWidth?: number;\n fillRule?: PathFillRule;\n}\n\n/** The style `params` carry, or `undefined` when they carry none. */\nexport function insertStyleOf(params: Readonly<Record<string, unknown>> | undefined): InsertStyle | undefined {\n if (!params) return undefined;\n let style: InsertStyle | undefined;\n for (const key of STYLE_OPTION_KEYS) {\n if (!Object.hasOwn(params, key) || params[key] === undefined) continue;\n (style ??= {})[key] = params[key] as never;\n }\n return style;\n}\n"],"mappings":";;AAIA,IAAa,oBAAoB;CAAC;CAAQ;CAAU;CAAe;AAAU;;AAK7E,IAAa,uBAAuB;;AAYpC,SAAgB,cAAc,QAAgF;CAC5G,IAAI,CAAC,QAAQ,OAAO;CACpB,IAAI;CACJ,KAAK,MAAM,OAAO,mBAAmB;EACnC,IAAI,CAAC,OAAO,OAAO,QAAQ,GAAG,KAAK,OAAO,SAAS,QAAW;EAC9D,CAAC,UAAU,CAAC,EAAA,CAAG,OAAO,OAAO;CAC/B;CACA,OAAO;AACT"}
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import { LASSO_VERTICES, isTinyLasso } from "./behaviors/selectFromLasso.js";
|
|
2
|
+
import { applyOpsTo, finiteThroughout, gestureViewReader, pointerStateOf, reduceBehaviorEnd, runBehaviorCancel, runBehaviorSettled, selectionFromHits, targetsOf } from "@weasel-js/core";
|
|
3
|
+
import { defineAction, resolveParams, setScratch } from "@weasel-js/routing";
|
|
4
|
+
|
|
5
|
+
// src/actions/lassoSelect/action.ts
|
|
6
|
+
/**
|
|
7
|
+
* `lassoSelectAction` — ongoing Action descriptor for polygon lasso selection.
|
|
8
|
+
*
|
|
9
|
+
* A move adds a vertex unless it is closer than the binding's
|
|
10
|
+
* `params.minVertexSpacing` (default 2 world-px) to the last one. The commit
|
|
11
|
+
* hit-tests the polygon with `dep.hitTestLasso(polygon, mode)` — `mode` from
|
|
12
|
+
* the binding's `params.mode`, default `'intersect'` — falling back to the
|
|
13
|
+
* polygon's AABB via `dep.hitTestArea(bounds)`. Shift extends the selection.
|
|
14
|
+
* Always transient: no undo entry.
|
|
15
|
+
*
|
|
16
|
+
* `opts.behaviors` (`LassoSelectBehavior[]`) run over a `GestureContext`
|
|
17
|
+
* whose `origin.get('gesture')` is the start pose, whose scratch holds the
|
|
18
|
+
* vertices under `LASSO_VERTICES`, and whose adapter answers selection and
|
|
19
|
+
* hit-testing from the `lassoSelect` dep. `onEnd` is first-non-undefined-wins:
|
|
20
|
+
* `Op[]` is applied in place of the default selection, `null` aborts, and
|
|
21
|
+
* all-`undefined` falls through to it. A behavior's ops are applied
|
|
22
|
+
* transiently too.
|
|
23
|
+
*/
|
|
24
|
+
/** Compute AABB of a polygon (for fallback hit-test when hitTestLasso is absent). */
|
|
25
|
+
function polygonAabb(pts) {
|
|
26
|
+
if (pts.length === 0) return null;
|
|
27
|
+
let minX = pts[0].x, minY = pts[0].y, maxX = pts[0].x, maxY = pts[0].y;
|
|
28
|
+
for (const p of pts) {
|
|
29
|
+
if (p.x < minX) minX = p.x;
|
|
30
|
+
if (p.y < minY) minY = p.y;
|
|
31
|
+
if (p.x > maxX) maxX = p.x;
|
|
32
|
+
if (p.y > maxY) maxY = p.y;
|
|
33
|
+
}
|
|
34
|
+
return {
|
|
35
|
+
x: minX,
|
|
36
|
+
y: minY,
|
|
37
|
+
width: maxX - minX,
|
|
38
|
+
height: maxY - minY
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
/** The dep's polygon test, or its rect test over the polygon's AABB when it
|
|
42
|
+
* has none, each hit taken at the depth a click selects. What both the
|
|
43
|
+
* default commit and a behavior's adapter ask. */
|
|
44
|
+
function hitTestPolygon(dep, vertices, mode, view) {
|
|
45
|
+
if (dep.hitTestLasso) return targetsOf(dep.hitTestLasso(vertices, mode, view), dep.targetOf);
|
|
46
|
+
const aabb = polygonAabb(vertices);
|
|
47
|
+
return aabb ? targetsOf(dep.hitTestArea(aabb, view), dep.targetOf) : [];
|
|
48
|
+
}
|
|
49
|
+
/** The adapter a behavior sees: selection and hit-testing from the dep,
|
|
50
|
+
* scoped to the view the lasso started in. */
|
|
51
|
+
function behaviorAdapter(dep, view) {
|
|
52
|
+
const adapter = {
|
|
53
|
+
getSelection: () => dep.getSelection(),
|
|
54
|
+
setSelection: (ids) => dep.setSelection(ids),
|
|
55
|
+
hitTestArea: (rect) => targetsOf(dep.hitTestArea(rect, view), dep.targetOf),
|
|
56
|
+
hitTestLasso: (polygon, mode) => hitTestPolygon(dep, polygon, mode, view),
|
|
57
|
+
applyOps: (ops) => applyOpsTo(adapter, ops)
|
|
58
|
+
};
|
|
59
|
+
return adapter;
|
|
60
|
+
}
|
|
61
|
+
var DEFAULT_MIN_VERTEX_SPACING = 2;
|
|
62
|
+
/**
|
|
63
|
+
* Static descriptor for the `lassoSelect` Action.
|
|
64
|
+
*/
|
|
65
|
+
var lassoSelectAction = defineAction({
|
|
66
|
+
id: "lassoSelect",
|
|
67
|
+
label: "Lasso Select",
|
|
68
|
+
eligible: { capability: "creates-selection" },
|
|
69
|
+
requires: ["lassoSelect", "view"],
|
|
70
|
+
invoker: {
|
|
71
|
+
timing: "ongoing",
|
|
72
|
+
start(ctx, opts) {
|
|
73
|
+
const dep = ctx.deps.lassoSelect;
|
|
74
|
+
if (!dep || !finiteThroughout(ctx.world)) return {};
|
|
75
|
+
const params = resolveParams(opts?.params);
|
|
76
|
+
const view = ctx.deps.view;
|
|
77
|
+
const vertices = [{
|
|
78
|
+
x: ctx.world.x,
|
|
79
|
+
y: ctx.world.y
|
|
80
|
+
}];
|
|
81
|
+
const behaviors = opts?.behaviors ?? [];
|
|
82
|
+
let gesture = null;
|
|
83
|
+
const readView = gestureViewReader(ctx.deps);
|
|
84
|
+
if (behaviors.length > 0) {
|
|
85
|
+
const pose = {
|
|
86
|
+
worldX: ctx.world.x,
|
|
87
|
+
worldY: ctx.world.y,
|
|
88
|
+
shiftHeld: ctx.modifiers.shift
|
|
89
|
+
};
|
|
90
|
+
gesture = {
|
|
91
|
+
draggedIds: ["gesture"],
|
|
92
|
+
origin: /* @__PURE__ */ new Map([["gesture", pose]]),
|
|
93
|
+
current: /* @__PURE__ */ new Map([["gesture", { ...pose }]]),
|
|
94
|
+
snap: null,
|
|
95
|
+
modifiers: { ...ctx.modifiers },
|
|
96
|
+
pointer: pointerStateOf(ctx.world, ctx),
|
|
97
|
+
view: readView(),
|
|
98
|
+
adapter: behaviorAdapter(dep, view),
|
|
99
|
+
scratch: {}
|
|
100
|
+
};
|
|
101
|
+
setScratch(gesture.scratch, LASSO_VERTICES, vertices);
|
|
102
|
+
for (const b of behaviors) b.onStart?.(gesture);
|
|
103
|
+
}
|
|
104
|
+
const scratch = {
|
|
105
|
+
dep,
|
|
106
|
+
mode: params?.mode ?? "intersect",
|
|
107
|
+
minVertexSpacing: params?.minVertexSpacing ?? DEFAULT_MIN_VERTEX_SPACING,
|
|
108
|
+
view,
|
|
109
|
+
vertices,
|
|
110
|
+
shiftHeld: ctx.modifiers.shift,
|
|
111
|
+
currentX: ctx.world.x,
|
|
112
|
+
currentY: ctx.world.y,
|
|
113
|
+
open: true,
|
|
114
|
+
behaviors,
|
|
115
|
+
gesture
|
|
116
|
+
};
|
|
117
|
+
return {
|
|
118
|
+
kind: "lasso",
|
|
119
|
+
autoPan: true,
|
|
120
|
+
onMove(moveCtx) {
|
|
121
|
+
if (!finiteThroughout(moveCtx.world)) return;
|
|
122
|
+
const { x, y } = moveCtx.world;
|
|
123
|
+
scratch.currentX = x;
|
|
124
|
+
scratch.currentY = y;
|
|
125
|
+
const last = scratch.vertices[scratch.vertices.length - 1];
|
|
126
|
+
const dx = x - last.x;
|
|
127
|
+
const dy = y - last.y;
|
|
128
|
+
const min = scratch.minVertexSpacing;
|
|
129
|
+
if (dx * dx + dy * dy >= min * min) scratch.vertices.push({
|
|
130
|
+
x,
|
|
131
|
+
y
|
|
132
|
+
});
|
|
133
|
+
const g = scratch.gesture;
|
|
134
|
+
if (g) {
|
|
135
|
+
g.modifiers = { ...moveCtx.modifiers };
|
|
136
|
+
g.pointer = pointerStateOf(moveCtx.world, moveCtx);
|
|
137
|
+
g.view = readView();
|
|
138
|
+
g.current.set("gesture", {
|
|
139
|
+
worldX: x,
|
|
140
|
+
worldY: y,
|
|
141
|
+
shiftHeld: scratch.shiftHeld
|
|
142
|
+
});
|
|
143
|
+
const proposed = {
|
|
144
|
+
vertices: scratch.vertices,
|
|
145
|
+
shiftHeld: scratch.shiftHeld
|
|
146
|
+
};
|
|
147
|
+
for (const b of scratch.behaviors) b.onMove?.(g, proposed);
|
|
148
|
+
}
|
|
149
|
+
},
|
|
150
|
+
overlay() {
|
|
151
|
+
if (!scratch.open) return null;
|
|
152
|
+
return {
|
|
153
|
+
kind: "lasso",
|
|
154
|
+
vertices: scratch.vertices,
|
|
155
|
+
current: {
|
|
156
|
+
x: scratch.currentX,
|
|
157
|
+
y: scratch.currentY
|
|
158
|
+
},
|
|
159
|
+
shiftHeld: scratch.shiftHeld
|
|
160
|
+
};
|
|
161
|
+
},
|
|
162
|
+
onEnd(_endCtx, reason) {
|
|
163
|
+
let committed = false;
|
|
164
|
+
try {
|
|
165
|
+
committed = endLasso(scratch, reason);
|
|
166
|
+
} finally {
|
|
167
|
+
if (scratch.gesture) runBehaviorSettled(scratch.behaviors, scratch.gesture, committed);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
},
|
|
173
|
+
enabled: () => true
|
|
174
|
+
});
|
|
175
|
+
/** Close the lasso. Returns whether it committed: a behavior's ops were
|
|
176
|
+
* applied, or the lasso set the selection. */
|
|
177
|
+
function endLasso(scratch, reason) {
|
|
178
|
+
scratch.open = false;
|
|
179
|
+
if (reason === "cancel") {
|
|
180
|
+
if (scratch.gesture) runBehaviorCancel(scratch.behaviors, scratch.gesture);
|
|
181
|
+
return false;
|
|
182
|
+
}
|
|
183
|
+
const { dep: d, mode, view, vertices, shiftHeld, gesture: g } = scratch;
|
|
184
|
+
if (g) {
|
|
185
|
+
const r = reduceBehaviorEnd(scratch.behaviors, g);
|
|
186
|
+
if (r !== void 0) {
|
|
187
|
+
if (r !== null) g.adapter.applyOps(r);
|
|
188
|
+
return r !== null;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
if (isTinyLasso(vertices)) {
|
|
192
|
+
if (!shiftHeld) d.setSelection([]);
|
|
193
|
+
return !shiftHeld;
|
|
194
|
+
}
|
|
195
|
+
const hits = hitTestPolygon(d, vertices, mode, view);
|
|
196
|
+
d.setSelection(selectionFromHits(d.getSelection(), hits, shiftHeld));
|
|
197
|
+
return true;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
export { lassoSelectAction };
|
|
201
|
+
//# sourceMappingURL=action.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"action.js","names":[],"sources":["../../../src/actions/lassoSelect/action.ts"],"sourcesContent":["/**\n * `lassoSelectAction` — ongoing Action descriptor for polygon lasso selection.\n *\n * A move adds a vertex unless it is closer than the binding's\n * `params.minVertexSpacing` (default 2 world-px) to the last one. The commit\n * hit-tests the polygon with `dep.hitTestLasso(polygon, mode)` — `mode` from\n * the binding's `params.mode`, default `'intersect'` — falling back to the\n * polygon's AABB via `dep.hitTestArea(bounds)`. Shift extends the selection.\n * Always transient: no undo entry.\n *\n * `opts.behaviors` (`LassoSelectBehavior[]`) run over a `GestureContext`\n * whose `origin.get('gesture')` is the start pose, whose scratch holds the\n * vertices under `LASSO_VERTICES`, and whose adapter answers selection and\n * hit-testing from the `lassoSelect` dep. `onEnd` is first-non-undefined-wins:\n * `Op[]` is applied in place of the default selection, `null` aborts, and\n * all-`undefined` falls through to it. A behavior's ops are applied\n * transiently too.\n */\n\nimport { gestureViewReader, pointerStateOf, applyOpsTo, reduceBehaviorEnd, runBehaviorCancel, runBehaviorSettled, targetsOf, selectionFromHits, finiteThroughout } from '@weasel-js/core';\nimport { defineAction, resolveParams, setScratch } from '@weasel-js/routing';\nimport type { InvocationCtx, OngoingHandle, OngoingOverlay, Point2 } from '@weasel-js/routing';\nimport type { LassoSelectDep, ViewApi, LassoHitMode, LassoSelectAdapter, GestureContext, LassoSelectBehavior, LassoSelectPose } from '@weasel-js/core/engine';\nimport type { Op } from '@weasel-js/core';\nimport { LASSO_VERTICES, isTinyLasso } from './behaviors/selectFromLasso';\nimport type {} from '@weasel-js/core';\nimport type { Rect } from '@weasel-js/geom';\n\n/** Compute AABB of a polygon (for fallback hit-test when hitTestLasso is absent). */\nfunction polygonAabb(\n pts: Point2[],\n): Rect | null {\n if (pts.length === 0) return null;\n let minX = pts[0].x, minY = pts[0].y, maxX = pts[0].x, maxY = pts[0].y;\n for (const p of pts) {\n if (p.x < minX) minX = p.x;\n if (p.y < minY) minY = p.y;\n if (p.x > maxX) maxX = p.x;\n if (p.y > maxY) maxY = p.y;\n }\n return { x: minX, y: minY, width: maxX - minX, height: maxY - minY };\n}\n\n/** The dep's polygon test, or its rect test over the polygon's AABB when it\n * has none, each hit taken at the depth a click selects. What both the\n * default commit and a behavior's adapter ask. */\nfunction hitTestPolygon(\n dep: LassoSelectDep,\n vertices: ReadonlyArray<Point2>,\n mode: LassoHitMode,\n view: ViewApi | undefined,\n): string[] {\n if (dep.hitTestLasso) return targetsOf(dep.hitTestLasso(vertices, mode, view), dep.targetOf);\n const aabb = polygonAabb(vertices as Point2[]);\n return aabb ? targetsOf(dep.hitTestArea(aabb, view), dep.targetOf) : [];\n}\n\n/** The adapter a behavior sees: selection and hit-testing from the dep,\n * scoped to the view the lasso started in. */\nfunction behaviorAdapter(dep: LassoSelectDep, view: ViewApi | undefined): LassoSelectAdapter {\n const adapter: LassoSelectAdapter = {\n getSelection: () => dep.getSelection(),\n setSelection: (ids) => dep.setSelection(ids),\n hitTestArea: (rect) => targetsOf(dep.hitTestArea(rect, view), dep.targetOf),\n hitTestLasso: (polygon, mode) => hitTestPolygon(dep, polygon, mode, view),\n applyOps: (ops: Op[]) => applyOpsTo(adapter, ops),\n };\n return adapter;\n}\n\nconst DEFAULT_MIN_VERTEX_SPACING = 2; // world-px\n\ninterface LassoScratch {\n dep: LassoSelectDep;\n mode: LassoHitMode;\n minVertexSpacing: number;\n /** The view the lasso started in: what it does not paint is not taken. */\n view: ViewApi | undefined;\n vertices: Point2[];\n shiftHeld: boolean;\n /** Current pointer position — paint the live \"close-line\" from the last\n * vertex back to the start while the gesture is open. Tracked separately\n * from `vertices` because we throttle vertex insertion. */\n currentX: number;\n currentY: number;\n /** Cleared by `onEnd` so post-commit `overlay()` returns null. */\n open: boolean;\n behaviors: LassoSelectBehavior[];\n /** Built only when there are behaviors to hand it to. */\n gesture: GestureContext<LassoSelectPose> | null;\n}\n\n/**\n * Static descriptor for the `lassoSelect` Action.\n */\nexport const lassoSelectAction = defineAction({\n id: 'lassoSelect',\n label: 'Lasso Select',\n eligible: { capability: 'creates-selection' },\n requires: ['lassoSelect', 'view'],\n invoker: {\n timing: 'ongoing',\n start(ctx, opts): OngoingHandle {\n const dep = ctx.deps.lassoSelect;\n // A press that is no finite number lands nowhere, as a move that is not does below.\n if (!dep || !finiteThroughout(ctx.world)) return {};\n\n const params = resolveParams(opts?.params);\n const view = ctx.deps.view;\n const vertices: Point2[] = [{ x: ctx.world.x, y: ctx.world.y }];\n const behaviors = (opts?.behaviors ?? []) as LassoSelectBehavior[];\n let gesture: GestureContext<LassoSelectPose> | null = null;\n const readView = gestureViewReader(ctx.deps);\n if (behaviors.length > 0) {\n const pose: LassoSelectPose = {\n worldX: ctx.world.x, worldY: ctx.world.y, shiftHeld: ctx.modifiers.shift,\n };\n gesture = {\n draggedIds: ['gesture'],\n origin: new Map([['gesture', pose]]),\n current: new Map([['gesture', { ...pose }]]),\n snap: null,\n modifiers: { ...ctx.modifiers },\n pointer: pointerStateOf(ctx.world, ctx),\n view: readView(),\n adapter: behaviorAdapter(dep, view) as unknown as GestureContext<LassoSelectPose>['adapter'],\n scratch: {},\n };\n // The live array, so a behavior reads every vertex added since.\n setScratch(gesture.scratch, LASSO_VERTICES, vertices);\n for (const b of behaviors) b.onStart?.(gesture);\n }\n const scratch: LassoScratch = {\n dep,\n mode: params?.mode ?? 'intersect',\n minVertexSpacing: params?.minVertexSpacing ?? DEFAULT_MIN_VERTEX_SPACING,\n view,\n vertices,\n shiftHeld: ctx.modifiers.shift,\n currentX: ctx.world.x,\n currentY: ctx.world.y,\n open: true,\n behaviors,\n gesture,\n };\n\n return {\n kind: 'lasso',\n autoPan: true,\n onMove(moveCtx: InvocationCtx): void {\n if (!finiteThroughout(moveCtx.world)) return;\n const { x, y } = moveCtx.world;\n scratch.currentX = x;\n scratch.currentY = y;\n const last = scratch.vertices[scratch.vertices.length - 1];\n const dx = x - last.x;\n const dy = y - last.y;\n const min = scratch.minVertexSpacing;\n if (dx * dx + dy * dy >= min * min) {\n scratch.vertices.push({ x, y });\n }\n const g = scratch.gesture;\n if (g) {\n g.modifiers = { ...moveCtx.modifiers };\n g.pointer = pointerStateOf(moveCtx.world, moveCtx);\n g.view = readView();\n g.current.set('gesture', { worldX: x, worldY: y, shiftHeld: scratch.shiftHeld });\n const proposed = { vertices: scratch.vertices, shiftHeld: scratch.shiftHeld };\n for (const b of scratch.behaviors) b.onMove?.(g, proposed);\n }\n },\n overlay(): OngoingOverlay | null {\n if (!scratch.open) return null;\n return {\n kind: 'lasso',\n vertices: scratch.vertices,\n current: { x: scratch.currentX, y: scratch.currentY },\n shiftHeld: scratch.shiftHeld,\n };\n },\n onEnd(_endCtx: InvocationCtx, reason: 'commit' | 'cancel'): void {\n let committed = false;\n try {\n committed = endLasso(scratch, reason);\n } finally {\n if (scratch.gesture) runBehaviorSettled(scratch.behaviors, scratch.gesture, committed);\n }\n },\n };\n },\n },\n enabled: () => true,\n});\n\n/** Close the lasso. Returns whether it committed: a behavior's ops were\n * applied, or the lasso set the selection. */\nfunction endLasso(scratch: LassoScratch, reason: 'commit' | 'cancel'): boolean {\n scratch.open = false;\n if (reason === 'cancel') {\n if (scratch.gesture) runBehaviorCancel(scratch.behaviors, scratch.gesture);\n return false;\n }\n\n const { dep: d, mode, view, vertices, shiftHeld, gesture: g } = scratch;\n\n if (g) {\n const r = reduceBehaviorEnd(scratch.behaviors, g);\n if (r !== undefined) {\n if (r !== null) (g.adapter as unknown as LassoSelectAdapter).applyOps!(r);\n return r !== null;\n }\n }\n\n if (isTinyLasso(vertices)) {\n if (!shiftHeld) d.setSelection([]);\n return !shiftHeld;\n }\n\n const hits = hitTestPolygon(d, vertices, mode, view);\n\n d.setSelection(selectionFromHits(d.getSelection(), hits, shiftHeld));\n return true;\n}\n"],"mappings":"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"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { selectionFromHits } from "@weasel-js/core";
|
|
2
|
+
import { getScratch, scratchKey } from "@weasel-js/routing";
|
|
3
|
+
import * as ops from "@weasel-js/core/ops";
|
|
4
|
+
|
|
5
|
+
// src/actions/lassoSelect/behaviors/selectFromLasso.ts
|
|
6
|
+
/** Typed scratch slot the lasso tool's gesture writes into for this behavior
|
|
7
|
+
* to consume. Shared identity: tools producing the polygon for a lasso
|
|
8
|
+
* selection write under this same key. */
|
|
9
|
+
var LASSO_VERTICES = scratchKey("lassoSelect.vertices");
|
|
10
|
+
var MIN_AREA = 4;
|
|
11
|
+
/** Whether a lasso through `vertices` is too small to enclose anything, so it reads as a click: fewer than
|
|
12
|
+
* three vertices, or a box under 4 world px². */
|
|
13
|
+
function isTinyLasso(vertices) {
|
|
14
|
+
return vertices.length < 3 || polygonAabbArea(vertices) < MIN_AREA;
|
|
15
|
+
}
|
|
16
|
+
/** A lasso behavior (`useLassoTool({ behaviors })`): replace selection with
|
|
17
|
+
* polygon hits in its own `mode`, or extend the existing selection when shift
|
|
18
|
+
* is held at gesture start. Tiny / degenerate lassos behave like a click —
|
|
19
|
+
* clear (or preserve, with shift). Hits come from the gesture adapter's
|
|
20
|
+
* `hitTestLasso`, which under `lassoSelectAction` is the `lassoSelect` dep. */
|
|
21
|
+
function selectFromLasso(opts) {
|
|
22
|
+
const mode = opts?.mode ?? "intersect";
|
|
23
|
+
return {
|
|
24
|
+
defaultTransient: true,
|
|
25
|
+
onEnd(ctx) {
|
|
26
|
+
const adapter = ctx.adapter;
|
|
27
|
+
if (!adapter.getSelection || !adapter.hitTestLasso) return null;
|
|
28
|
+
const vertices = getScratch(ctx.scratch, LASSO_VERTICES) ?? [];
|
|
29
|
+
const startPose = ctx.origin.get("gesture");
|
|
30
|
+
const shiftHeld = startPose ? startPose.shiftHeld === true : false;
|
|
31
|
+
const from = adapter.getSelection();
|
|
32
|
+
if (isTinyLasso(vertices)) {
|
|
33
|
+
const to = shiftHeld ? from : [];
|
|
34
|
+
return [ops.setSelection({
|
|
35
|
+
from,
|
|
36
|
+
to
|
|
37
|
+
})];
|
|
38
|
+
}
|
|
39
|
+
const hits = adapter.hitTestLasso(vertices, mode);
|
|
40
|
+
const to = selectionFromHits(from, hits, shiftHeld);
|
|
41
|
+
return [ops.setSelection({
|
|
42
|
+
from,
|
|
43
|
+
to
|
|
44
|
+
})];
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
function polygonAabbArea(vertices) {
|
|
49
|
+
if (vertices.length === 0) return 0;
|
|
50
|
+
let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;
|
|
51
|
+
for (const v of vertices) {
|
|
52
|
+
if (v.x < minX) minX = v.x;
|
|
53
|
+
if (v.y < minY) minY = v.y;
|
|
54
|
+
if (v.x > maxX) maxX = v.x;
|
|
55
|
+
if (v.y > maxY) maxY = v.y;
|
|
56
|
+
}
|
|
57
|
+
return (maxX - minX) * (maxY - minY);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export { LASSO_VERTICES, isTinyLasso, selectFromLasso };
|
|
61
|
+
//# sourceMappingURL=selectFromLasso.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"selectFromLasso.js","names":[],"sources":["../../../../src/actions/lassoSelect/behaviors/selectFromLasso.ts"],"sourcesContent":["import type { Op, NodeId } from '@weasel-js/core';\nimport type {\n LassoHitMode,\n LassoSelectAdapter,\n} from '@weasel-js/core/engine';\nimport type { LassoSelectBehavior } from '@weasel-js/core/engine';\nimport { scratchKey, getScratch } from '@weasel-js/routing';\nimport { selectionFromHits } from '@weasel-js/core';\nimport * as ops from '@weasel-js/core/ops';\n\n/** Typed scratch slot the lasso tool's gesture writes into for this behavior\n * to consume. Shared identity: tools producing the polygon for a lasso\n * selection write under this same key. */\nexport const LASSO_VERTICES = scratchKey<ReadonlyArray<{ x: number; y: number }>>('lassoSelect.vertices');\n\nconst MIN_AREA = 4;\n\n/** Whether a lasso through `vertices` is too small to enclose anything, so it reads as a click: fewer than\n * three vertices, or a box under 4 world px². */\nexport function isTinyLasso(vertices: ReadonlyArray<{ x: number; y: number }>): boolean {\n return vertices.length < 3 || polygonAabbArea(vertices) < MIN_AREA;\n}\n\n/** Options for `selectFromLasso`. */\nexport interface SelectFromLassoOptions {\n /** Hit mode for `hitTestLasso`. Default 'intersect'. */\n mode?: LassoHitMode;\n}\n\n/** A lasso behavior (`useLassoTool({ behaviors })`): replace selection with\n * polygon hits in its own `mode`, or extend the existing selection when shift\n * is held at gesture start. Tiny / degenerate lassos behave like a click —\n * clear (or preserve, with shift). Hits come from the gesture adapter's\n * `hitTestLasso`, which under `lassoSelectAction` is the `lassoSelect` dep. */\nexport function selectFromLasso(opts?: SelectFromLassoOptions): LassoSelectBehavior {\n const mode: LassoHitMode = opts?.mode ?? 'intersect';\n return {\n defaultTransient: true,\n onEnd(ctx) {\n const adapter = ctx.adapter as unknown as LassoSelectAdapter;\n if (!adapter.getSelection || !adapter.hitTestLasso) return null;\n\n const vertices = getScratch(ctx.scratch, LASSO_VERTICES) ?? [];\n const startPose = ctx.origin.get('gesture');\n const shiftHeld = startPose ? (startPose as { shiftHeld?: boolean }).shiftHeld === true : false;\n const from = adapter.getSelection();\n\n // Tiny / degenerate lassos behave like a click: clear (or preserve on shift).\n if (isTinyLasso(vertices)) {\n const to = shiftHeld ? from : [];\n const op: Op = ops.setSelection({ from: from as NodeId[], to: to as NodeId[] });\n return [op];\n }\n\n const hits = adapter.hitTestLasso(vertices, mode);\n const to = selectionFromHits(from, hits, shiftHeld);\n const op: Op = ops.setSelection({ from: from as NodeId[], to: to as NodeId[] });\n return [op];\n },\n };\n}\n\nfunction polygonAabbArea(vertices: ReadonlyArray<{ x: number; y: number }>): number {\n if (vertices.length === 0) return 0;\n let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;\n for (const v of vertices) {\n if (v.x < minX) minX = v.x;\n if (v.y < minY) minY = v.y;\n if (v.x > maxX) maxX = v.x;\n if (v.y > maxY) maxY = v.y;\n }\n return (maxX - minX) * (maxY - minY);\n}\n"],"mappings":";;;;;;;;AAaA,IAAa,iBAAiB,WAAoD,sBAAsB;AAExG,IAAM,WAAW;;;AAIjB,SAAgB,YAAY,UAA4D;CACtF,OAAO,SAAS,SAAS,KAAK,gBAAgB,QAAQ,IAAI;AAC5D;;;;;;AAaA,SAAgB,gBAAgB,MAAoD;CAClF,MAAM,OAAqB,MAAM,QAAQ;CACzC,OAAO;EACL,kBAAkB;EAClB,MAAM,KAAK;GACT,MAAM,UAAU,IAAI;GACpB,IAAI,CAAC,QAAQ,gBAAgB,CAAC,QAAQ,cAAc,OAAO;GAE3D,MAAM,WAAW,WAAW,IAAI,SAAS,cAAc,KAAK,CAAC;GAC7D,MAAM,YAAY,IAAI,OAAO,IAAI,SAAS;GAC1C,MAAM,YAAY,YAAa,UAAsC,cAAc,OAAO;GAC1F,MAAM,OAAO,QAAQ,aAAa;GAGlC,IAAI,YAAY,QAAQ,GAAG;IACzB,MAAM,KAAK,YAAY,OAAO,CAAC;IAE/B,OAAO,CADQ,IAAI,aAAa;KAAQ;KAAsB;IAAe,CACrE,CAAE;GACZ;GAEA,MAAM,OAAO,QAAQ,aAAa,UAAU,IAAI;GAChD,MAAM,KAAK,kBAAkB,MAAM,MAAM,SAAS;GAElD,OAAO,CADQ,IAAI,aAAa;IAAQ;IAAsB;GAAe,CACrE,CAAE;EACZ;CACF;AACF;AAEA,SAAS,gBAAgB,UAA2D;CAClF,IAAI,SAAS,WAAW,GAAG,OAAO;CAClC,IAAI,OAAO,UAAU,OAAO,UAAU,OAAO,WAAW,OAAO;CAC/D,KAAK,MAAM,KAAK,UAAU;EACxB,IAAI,EAAE,IAAI,MAAM,OAAO,EAAE;EACzB,IAAI,EAAE,IAAI,MAAM,OAAO,EAAE;EACzB,IAAI,EAAE,IAAI,MAAM,OAAO,EAAE;EACzB,IAAI,EAAE,IAAI,MAAM,OAAO,EAAE;CAC3B;CACA,QAAQ,OAAO,SAAS,OAAO;AACjC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { writtenBy } from "@weasel-js/core";
|
|
2
|
+
import { ActionDisabledReason } from "@weasel-js/routing";
|
|
3
|
+
|
|
4
|
+
// src/actions/lockedWrites.ts
|
|
5
|
+
/** Whether committing `ops` would write the pose or data of a locked node, which the scene's lock guard refuses:
|
|
6
|
+
* an envelope moves, turns, or mirrors by rewriting its sources, and one of them may be locked. */
|
|
7
|
+
function writesLocked(scene, ops) {
|
|
8
|
+
if (ops.length === 0 || typeof scene.isLocked !== "function") return false;
|
|
9
|
+
const written = writtenBy(scene, ops);
|
|
10
|
+
return written !== null && [...written.keys()].some((id) => scene.isLocked(id));
|
|
11
|
+
}
|
|
12
|
+
/** `enabled`'s answer for a command that would commit `ops` (ruled 2026-11-09 and 2026-11-10): not applicable when
|
|
13
|
+
* they change nothing, locked when they would rewrite a locked node. */
|
|
14
|
+
function opsAnswer(scene, ops) {
|
|
15
|
+
if (ops.length === 0) return ActionDisabledReason.NotApplicable;
|
|
16
|
+
return writesLocked(scene, ops) ? ActionDisabledReason.Locked : true;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export { opsAnswer, writesLocked };
|
|
20
|
+
//# sourceMappingURL=lockedWrites.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lockedWrites.js","names":[],"sources":["../../src/actions/lockedWrites.ts"],"sourcesContent":["import type { NodeId, Op, Scene } from '@weasel-js/core';\nimport { writtenBy } from '@weasel-js/core';\nimport { ActionDisabledReason } from '@weasel-js/routing';\n\n/** Whether committing `ops` would write the pose or data of a locked node, which the scene's lock guard refuses:\n * an envelope moves, turns, or mirrors by rewriting its sources, and one of them may be locked. */\nexport function writesLocked(scene: Scene<unknown, string, unknown>, ops: readonly Op[]): boolean {\n if (ops.length === 0 || typeof scene.isLocked !== 'function') return false;\n const written = writtenBy(scene, ops);\n return written !== null && [...written.keys()].some((id) => scene.isLocked(id as NodeId));\n}\n\n/** `enabled`'s answer for a command that would commit `ops` (ruled 2026-11-09 and 2026-11-10): not applicable when\n * they change nothing, locked when they would rewrite a locked node. */\nexport function opsAnswer(scene: Scene<unknown, string, unknown>, ops: readonly Op[]): true | ActionDisabledReason {\n if (ops.length === 0) return ActionDisabledReason.NotApplicable;\n return writesLocked(scene, ops) ? ActionDisabledReason.Locked : true;\n}\n"],"mappings":";;;;;;AAMA,SAAgB,aAAa,OAAwC,KAA6B;CAChG,IAAI,IAAI,WAAW,KAAK,OAAO,MAAM,aAAa,YAAY,OAAO;CACrE,MAAM,UAAU,UAAU,OAAO,GAAG;CACpC,OAAO,YAAY,QAAQ,CAAC,GAAG,QAAQ,KAAK,CAAC,CAAC,CAAC,MAAM,OAAO,MAAM,SAAS,EAAY,CAAC;AAC1F;;;AAIA,SAAgB,UAAU,OAAwC,KAAiD;CACjH,IAAI,IAAI,WAAW,GAAG,OAAO,qBAAqB;CAClD,OAAO,aAAa,OAAO,GAAG,IAAI,qBAAqB,SAAS;AAClE"}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { beginMove } from "./session.js";
|
|
2
|
+
import { nextFrame } from "./frame.js";
|
|
3
|
+
import { commitMove } from "./commit/index.js";
|
|
4
|
+
import { closeRun, createTransformPreview, finiteFrame, inPlane, recordTransform, runBehaviorCancel, selectionLayer } from "@weasel-js/core";
|
|
5
|
+
import { defineAction } from "@weasel-js/routing";
|
|
6
|
+
import { SNAP_ROLES } from "@weasel-js/core/engine";
|
|
7
|
+
import { createEmitter } from "@weasel-js/registry";
|
|
8
|
+
|
|
9
|
+
// src/actions/move/action.ts
|
|
10
|
+
/**
|
|
11
|
+
* Drag-translates the selection.
|
|
12
|
+
*
|
|
13
|
+
* Each frame's poses go to the scene's ephemeral override table, not the
|
|
14
|
+
* document: `Scene.setPose` records an undo entry per call, and the overrides
|
|
15
|
+
* are what let a node deriving its geometry from a dragged one follow the
|
|
16
|
+
* drag. Release commits one batch — at most one undo entry, none when the
|
|
17
|
+
* binding's params make it transient — and cancel drops the overrides.
|
|
18
|
+
*
|
|
19
|
+
* Behaviors from the binding's `opts.behaviors` fold into each frame; on
|
|
20
|
+
* release the first non-`undefined` answer wins (`Op[]` commits, `null`
|
|
21
|
+
* aborts). `beginMove` appends the action's own: a layout drop, a page drop
|
|
22
|
+
* in a paged scene, and reparent-on-drop.
|
|
23
|
+
*/
|
|
24
|
+
var moveAction = inPlane(defineAction({
|
|
25
|
+
id: "move",
|
|
26
|
+
label: "Move",
|
|
27
|
+
activeCursor: "move",
|
|
28
|
+
defaultBinding: [{
|
|
29
|
+
spec: {
|
|
30
|
+
kind: "drag",
|
|
31
|
+
target: "selected-body"
|
|
32
|
+
},
|
|
33
|
+
opts: { id: "move.drag" }
|
|
34
|
+
}],
|
|
35
|
+
eligible: { capability: "transforms-selection" },
|
|
36
|
+
modifierRoles: SNAP_ROLES,
|
|
37
|
+
requires: [
|
|
38
|
+
"operands",
|
|
39
|
+
"scene",
|
|
40
|
+
"poseDescriptor",
|
|
41
|
+
"layout",
|
|
42
|
+
"applyOps",
|
|
43
|
+
"geometryProjection",
|
|
44
|
+
"nodeAtPoint",
|
|
45
|
+
"canDropInto",
|
|
46
|
+
"canSwap",
|
|
47
|
+
"view",
|
|
48
|
+
"boundsIncludeStroke",
|
|
49
|
+
"drawnBoxes",
|
|
50
|
+
"kitSettings",
|
|
51
|
+
"snap",
|
|
52
|
+
"transformFollowers"
|
|
53
|
+
],
|
|
54
|
+
invoker: {
|
|
55
|
+
timing: "ongoing",
|
|
56
|
+
start(ctx, opts) {
|
|
57
|
+
let frame = {
|
|
58
|
+
delta: {
|
|
59
|
+
dx: 0,
|
|
60
|
+
dy: 0
|
|
61
|
+
},
|
|
62
|
+
previews: /* @__PURE__ */ new Map(),
|
|
63
|
+
opaque: /* @__PURE__ */ new Set(),
|
|
64
|
+
overlays: []
|
|
65
|
+
};
|
|
66
|
+
const begun = beginMove(ctx, opts, () => frame);
|
|
67
|
+
if (!begun) return {};
|
|
68
|
+
const { session, readers } = begun;
|
|
69
|
+
const subject = [...ctx.deps.operands?.get() ?? []];
|
|
70
|
+
const hold = session.scene.overrides.hold();
|
|
71
|
+
const preview = createTransformPreview(ctx.deps, session.scene, () => frame.previews);
|
|
72
|
+
let engaged = null;
|
|
73
|
+
let lastMove = null;
|
|
74
|
+
const shown = createEmitter();
|
|
75
|
+
const show = (moveCtx) => {
|
|
76
|
+
frame = finiteFrame(frame, moveCtx, () => nextFrame(session, readers, moveCtx), (f) => f.previews);
|
|
77
|
+
hold.set(preview.poses());
|
|
78
|
+
};
|
|
79
|
+
session.gestureCtx.refresh = () => {
|
|
80
|
+
if (!lastMove) return;
|
|
81
|
+
show(lastMove);
|
|
82
|
+
shown.emit();
|
|
83
|
+
};
|
|
84
|
+
return {
|
|
85
|
+
kind: "move",
|
|
86
|
+
autoPan: true,
|
|
87
|
+
onMove(moveCtx) {
|
|
88
|
+
if (!moveCtx.drag) return;
|
|
89
|
+
if (!engaged) session.lifecycle.start(session.ids);
|
|
90
|
+
engaged = moveCtx.world;
|
|
91
|
+
lastMove = moveCtx;
|
|
92
|
+
show(moveCtx);
|
|
93
|
+
},
|
|
94
|
+
subscribe: (changed) => shown.subscribe(changed),
|
|
95
|
+
cursor: () => frame.cursor,
|
|
96
|
+
onEnd(endCtx, reason) {
|
|
97
|
+
let committed = false;
|
|
98
|
+
try {
|
|
99
|
+
if (reason === "commit" && engaged) {
|
|
100
|
+
committed = commitMove({
|
|
101
|
+
session,
|
|
102
|
+
delta: frame.delta,
|
|
103
|
+
at: endCtx.drag ? endCtx.world : engaged
|
|
104
|
+
});
|
|
105
|
+
if (committed) recordTransform(session.scene, {
|
|
106
|
+
kind: "translate",
|
|
107
|
+
...frame.delta
|
|
108
|
+
}, subject);
|
|
109
|
+
} else runBehaviorCancel(session.behaviors, session.gestureCtx);
|
|
110
|
+
} finally {
|
|
111
|
+
session.snap?.end();
|
|
112
|
+
closeRun({
|
|
113
|
+
hold,
|
|
114
|
+
previews: frame.previews,
|
|
115
|
+
behaviors: session.behaviors,
|
|
116
|
+
ctx: session.gestureCtx,
|
|
117
|
+
lifecycle: session.lifecycle
|
|
118
|
+
}, committed);
|
|
119
|
+
}
|
|
120
|
+
},
|
|
121
|
+
previewIds: preview.previewIds,
|
|
122
|
+
previewData: preview.previewData,
|
|
123
|
+
previewOpaqueIds: () => frame.opaque.size === 0 ? null : frame.opaque,
|
|
124
|
+
overlay: () => frame.overlays.length === 0 ? null : frame.overlays
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
},
|
|
128
|
+
/**
|
|
129
|
+
* Always enabled: the dispatcher treats anything `!== true` as "fall
|
|
130
|
+
* through to the next-best match", so a disabled reason here loses every
|
|
131
|
+
* drag-on-selected-body to a lower-specificity binding (a shape tool's
|
|
132
|
+
* insert drag).
|
|
133
|
+
*/
|
|
134
|
+
enabled: () => true
|
|
135
|
+
}), selectionLayer);
|
|
136
|
+
|
|
137
|
+
export { moveAction };
|
|
138
|
+
//# sourceMappingURL=action.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"action.js","names":[],"sources":["../../../src/actions/move/action.ts"],"sourcesContent":["import { defineAction, type Action } from '@weasel-js/routing';\nimport { createEmitter } from '@weasel-js/registry';\nimport type { InvocationCtx } from '@weasel-js/routing';\nimport { createTransformPreview, finiteFrame, closeRun, runBehaviorCancel, inPlane, selectionLayer, recordTransform } from '@weasel-js/core';\nimport { beginMove, type MoveFrame } from './session';\nimport type { ReparentOnDrop } from '@weasel-js/core';\nimport { nextFrame } from './frame';\nimport { commitMove } from './commit';\nimport { SNAP_ROLES } from '@weasel-js/core/engine';\nimport type {} from '@weasel-js/core';\nexport type { ReparentOnDrop };\n\n/**\n * Drag-translates the selection.\n *\n * Each frame's poses go to the scene's ephemeral override table, not the\n * document: `Scene.setPose` records an undo entry per call, and the overrides\n * are what let a node deriving its geometry from a dragged one follow the\n * drag. Release commits one batch — at most one undo entry, none when the\n * binding's params make it transient — and cancel drops the overrides.\n *\n * Behaviors from the binding's `opts.behaviors` fold into each frame; on\n * release the first non-`undefined` answer wins (`Op[]` commits, `null`\n * aborts). `beginMove` appends the action's own: a layout drop, a page drop\n * in a paged scene, and reparent-on-drop.\n */\nexport const moveAction: Action = inPlane(defineAction({\n id: 'move',\n label: 'Move',\n // No hover `cursor`: pointing at a node shouldn't preemptively promise a move.\n activeCursor: 'move',\n // Ambient default targets `selected-body`, not a bare `{ kind: 'drag' }`,\n // which catches every drag in ambient scope and bleeds the move into\n // drawing-tool gestures wherever the higher-priority active match falls\n // through.\n defaultBinding: [{ spec: { kind: 'drag', target: 'selected-body' }, opts: { id: 'move.drag' } }],\n eligible: { capability: 'transforms-selection' },\n modifierRoles: SNAP_ROLES,\n requires: ['operands', 'scene', 'poseDescriptor', 'layout', 'applyOps', 'geometryProjection', 'nodeAtPoint', 'canDropInto', 'canSwap', 'view', 'boundsIncludeStroke', 'drawnBoxes', 'kitSettings', 'snap', 'transformFollowers'],\n invoker: {\n timing: 'ongoing',\n start(ctx, opts) {\n let frame: MoveFrame = { delta: { dx: 0, dy: 0 }, previews: new Map(), opaque: new Set(), overlays: [] };\n const begun = beginMove(ctx, opts, () => frame);\n if (!begun) return {};\n const { session, readers } = begun;\n const subject = [...(ctx.deps.operands?.get() ?? [])] as string[];\n const hold = session.scene.overrides.hold();\n const preview = createTransformPreview(ctx.deps, session.scene, () => frame.previews);\n // Where the last move put the pointer; null until the first.\n let engaged: { x: number; y: number } | null = null;\n let lastMove: InvocationCtx | null = null;\n const shown = createEmitter();\n const show = (moveCtx: InvocationCtx): void => {\n frame = finiteFrame(frame, moveCtx, () => nextFrame(session, readers, moveCtx), (f) => f.previews);\n hold.set(preview.poses());\n };\n session.gestureCtx.refresh = () => {\n if (!lastMove) return;\n show(lastMove);\n shown.emit();\n };\n return {\n kind: 'move',\n autoPan: true,\n onMove(moveCtx: InvocationCtx): void {\n if (!moveCtx.drag) return;\n if (!engaged) session.lifecycle.start(session.ids as unknown as string[]);\n engaged = moveCtx.world;\n lastMove = moveCtx;\n show(moveCtx);\n },\n subscribe: (changed) => shown.subscribe(changed),\n cursor: () => frame.cursor,\n onEnd(endCtx: InvocationCtx, reason: 'commit' | 'cancel'): void {\n let committed = false;\n try {\n // A press that never moved was never a move: its behaviors\n // started, so they are canceled, not asked to commit.\n if (reason === 'commit' && engaged) {\n committed = commitMove({\n session,\n delta: frame.delta,\n at: endCtx.drag ? endCtx.world : engaged,\n });\n if (committed) recordTransform(session.scene, { kind: 'translate', ...frame.delta }, subject);\n } else runBehaviorCancel(session.behaviors, session.gestureCtx);\n } finally {\n session.snap?.end();\n // After the commit, so no frame can paint the pre-drag pose between\n // the override going away and the document catching up.\n closeRun({ hold, previews: frame.previews, behaviors: session.behaviors, ctx: session.gestureCtx, lifecycle: session.lifecycle }, committed);\n }\n },\n previewIds: preview.previewIds,\n previewData: preview.previewData,\n previewOpaqueIds: () => (frame.opaque.size === 0 ? null : frame.opaque),\n overlay: () => (frame.overlays.length === 0 ? null : frame.overlays),\n };\n },\n },\n /**\n * Always enabled: the dispatcher treats anything `!== true` as \"fall\n * through to the next-best match\", so a disabled reason here loses every\n * drag-on-selected-body to a lower-specificity binding (a shape tool's\n * insert drag).\n */\n enabled: () => true,\n}), selectionLayer);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AA0BA,IAAa,aAAqB,QAAQ,aAAa;CACrD,IAAI;CACJ,OAAO;CAEP,cAAc;CAKd,gBAAgB,CAAC;EAAE,MAAM;GAAE,MAAM;GAAQ,QAAQ;EAAgB;EAAG,MAAM,EAAE,IAAI,YAAY;CAAE,CAAC;CAC/F,UAAU,EAAE,YAAY,uBAAuB;CAC/C,eAAe;CACf,UAAU;EAAC;EAAY;EAAS;EAAkB;EAAU;EAAY;EAAsB;EAAe;EAAe;EAAW;EAAQ;EAAuB;EAAc;EAAe;EAAQ;CAAoB;CAC/N,SAAS;EACP,QAAQ;EACR,MAAM,KAAK,MAAM;GACf,IAAI,QAAmB;IAAE,OAAO;KAAE,IAAI;KAAG,IAAI;IAAE;IAAG,0BAAU,IAAI,IAAI;IAAG,wBAAQ,IAAI,IAAI;IAAG,UAAU,CAAC;GAAE;GACvG,MAAM,QAAQ,UAAU,KAAK,YAAY,KAAK;GAC9C,IAAI,CAAC,OAAO,OAAO,CAAC;GACpB,MAAM,EAAE,SAAS,YAAY;GAC7B,MAAM,UAAU,CAAC,GAAI,IAAI,KAAK,UAAU,IAAI,KAAK,CAAC,CAAE;GACpD,MAAM,OAAO,QAAQ,MAAM,UAAU,KAAK;GAC1C,MAAM,UAAU,uBAAuB,IAAI,MAAM,QAAQ,aAAa,MAAM,QAAQ;GAEpF,IAAI,UAA2C;GAC/C,IAAI,WAAiC;GACrC,MAAM,QAAQ,cAAc;GAC5B,MAAM,QAAQ,YAAiC;IAC7C,QAAQ,YAAY,OAAO,eAAe,UAAU,SAAS,SAAS,OAAO,IAAI,MAAM,EAAE,QAAQ;IACjG,KAAK,IAAI,QAAQ,MAAM,CAAC;GAC1B;GACA,QAAQ,WAAW,gBAAgB;IACjC,IAAI,CAAC,UAAU;IACf,KAAK,QAAQ;IACb,MAAM,KAAK;GACb;GACA,OAAO;IACL,MAAM;IACN,SAAS;IACT,OAAO,SAA8B;KACnC,IAAI,CAAC,QAAQ,MAAM;KACnB,IAAI,CAAC,SAAS,QAAQ,UAAU,MAAM,QAAQ,GAA0B;KACxE,UAAU,QAAQ;KAClB,WAAW;KACX,KAAK,OAAO;IACd;IACA,YAAY,YAAY,MAAM,UAAU,OAAO;IAC/C,cAAc,MAAM;IACpB,MAAM,QAAuB,QAAmC;KAC9D,IAAI,YAAY;KAChB,IAAI;MAGF,IAAI,WAAW,YAAY,SAAS;OAClC,YAAY,WAAW;QACrB;QACA,OAAO,MAAM;QACb,IAAI,OAAO,OAAO,OAAO,QAAQ;OACnC,CAAC;OACD,IAAI,WAAW,gBAAgB,QAAQ,OAAO;QAAE,MAAM;QAAa,GAAG,MAAM;OAAM,GAAG,OAAO;MAC9F,OAAO,kBAAkB,QAAQ,WAAW,QAAQ,UAAU;KAChE,UAAU;MACR,QAAQ,MAAM,IAAI;MAGlB,SAAS;OAAE;OAAM,UAAU,MAAM;OAAU,WAAW,QAAQ;OAAW,KAAK,QAAQ;OAAY,WAAW,QAAQ;MAAU,GAAG,SAAS;KAC7I;IACF;IACA,YAAY,QAAQ;IACpB,aAAa,QAAQ;IACrB,wBAAyB,MAAM,OAAO,SAAS,IAAI,OAAO,MAAM;IAChE,eAAgB,MAAM,SAAS,WAAW,IAAI,OAAO,MAAM;GAC7D;EACF;CACF;;;;;;;CAOA,eAAe;AACjB,CAAC,GAAG,cAAc"}
|