@weasel-js/editing 1.19.1 → 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/README.md +23 -11
- package/dist/actionGroups.js +27 -0
- package/dist/actionGroups.js.map +1 -0
- package/dist/actions/align/action.js +12 -9
- package/dist/actions/align/action.js.map +1 -1
- package/dist/actions/align/align.js +5 -4
- package/dist/actions/align/align.js.map +1 -1
- package/dist/actions/clipboard/action.js +10 -7
- package/dist/actions/clipboard/action.js.map +1 -1
- 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 +6 -3
- package/dist/actions/distribute/action.js.map +1 -1
- package/dist/actions/distribute/distribute.js +3 -2
- package/dist/actions/distribute/distribute.js.map +1 -1
- package/dist/actions/distribute/plan.js.map +1 -1
- package/dist/actions/edit/createPaintAction.js +42 -13
- package/dist/actions/edit/createPaintAction.js.map +1 -1
- package/dist/actions/edit/{escape.js → deselect.js} +8 -8
- package/dist/actions/edit/deselect.js.map +1 -0
- package/dist/actions/edit/duplicate.js +9 -7
- package/dist/actions/edit/duplicate.js.map +1 -1
- package/dist/actions/edit/group.js +24 -20
- package/dist/actions/edit/group.js.map +1 -1
- package/dist/actions/edit/ingest.js +4 -2
- package/dist/actions/edit/ingest.js.map +1 -1
- package/dist/actions/edit/nudge.js +14 -10
- package/dist/actions/edit/nudge.js.map +1 -1
- package/dist/actions/edit/selectAll.js +1 -1
- package/dist/actions/edit/setFill.js +1 -1
- package/dist/actions/edit/setFill.js.map +1 -1
- package/dist/actions/edit/setFillOpacity.js +5 -5
- package/dist/actions/edit/setFillOpacity.js.map +1 -1
- package/dist/actions/edit/setStroke.js +1 -1
- package/dist/actions/edit/setStroke.js.map +1 -1
- package/dist/actions/edit/setStrokeOpacity.js +6 -6
- package/dist/actions/edit/setStrokeOpacity.js.map +1 -1
- package/dist/actions/edit/setStrokeWidth.js +13 -8
- package/dist/actions/edit/setStrokeWidth.js.map +1 -1
- package/dist/actions/edit/setVertexColor.js +13 -6
- package/dist/actions/edit/setVertexColor.js.map +1 -1
- package/dist/actions/flip/action.js +19 -14
- package/dist/actions/flip/action.js.map +1 -1
- package/dist/actions/flip/helpers.js.map +1 -1
- 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 +8 -6
- package/dist/actions/pathfinder/action.js.map +1 -1
- package/dist/actions/pathfinder/booleanGroupAction.js +16 -10
- package/dist/actions/pathfinder/booleanGroupAction.js.map +1 -1
- package/dist/actions/pathfinder/keymap.js +2 -2
- package/dist/actions/pathfinder/keymap.js.map +1 -1
- package/dist/actions/reorder/reorder.js +13 -11
- package/dist/actions/reorder/reorder.js.map +1 -1
- 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 +16 -14
- package/dist/actions/transformAgain/action.js.map +1 -1
- package/dist/actions/transformAgain/transformSelection.js +19 -5
- package/dist/actions/transformAgain/transformSelection.js.map +1 -1
- 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 +16 -7
- package/dist/engineStandardActions.js.map +1 -1
- 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 +1293 -105
- package/dist/index.js +61 -12
- 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 +23 -11
- package/dist/namedPresets.js.map +1 -1
- package/dist/presets/arrange.js +21 -7
- package/dist/presets/arrange.js.map +1 -1
- package/dist/presets/booleans.js +13 -0
- package/dist/presets/booleans.js.map +1 -0
- package/dist/presets/composites.js +8 -5
- package/dist/presets/composites.js.map +1 -1
- package/dist/presets/edit.js +25 -13
- package/dist/presets/edit.js.map +1 -1
- package/dist/presets/ingest.js +7 -3
- package/dist/presets/ingest.js.map +1 -1
- package/dist/presets/insert.js +28 -0
- package/dist/presets/insert.js.map +1 -0
- package/dist/presets/pathfinder.js +5 -2
- package/dist/presets/pathfinder.js.map +1 -1
- package/dist/presets/select.js +16 -3
- package/dist/presets/select.js.map +1 -1
- 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 +78 -9
- package/dist/presets/tools.js.map +1 -1
- package/dist/presets/transform.js +20 -7
- package/dist/presets/transform.js.map +1 -1
- 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/package.json +39 -11
- package/dist/actions/edit/escape.js.map +0 -1
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { clearedSelection } from "./session.js";
|
|
2
|
+
import { insertShape, isCommittableExtent } from "./shape.js";
|
|
3
|
+
import { commitRunOps, readRunLifecycle, reduceBehaviorEnd, runBehaviorCancel } from "@weasel-js/core";
|
|
4
|
+
import { resolveParams } from "@weasel-js/routing";
|
|
5
|
+
import { defaultCommitAdapter as defaultCommitAdapter$1, operandMethods as operandMethods$1 } from "@weasel-js/core/engine";
|
|
6
|
+
import * as ops from "@weasel-js/core/ops";
|
|
7
|
+
|
|
8
|
+
// src/actions/insert/commit.ts
|
|
9
|
+
/** Put back the selection the press cleared, for a draw that ends without
|
|
10
|
+
* committing. */
|
|
11
|
+
function restoreSelection(session) {
|
|
12
|
+
if (session.priorSelection.length > 0) session.selection?.set([...session.priorSelection]);
|
|
13
|
+
}
|
|
14
|
+
/** Cancel the insert: tell the behaviors, and put the selection the draw
|
|
15
|
+
* cleared back. */
|
|
16
|
+
function cancelInsert(session) {
|
|
17
|
+
runBehaviorCancel(session.behaviors, session.gestureCtx);
|
|
18
|
+
restoreSelection(session);
|
|
19
|
+
}
|
|
20
|
+
/** Commit the insert. Returns whether it committed: a behavior's ops reached
|
|
21
|
+
* the scene, or the `insert` dep minted a node. `points` is the pointer
|
|
22
|
+
* trail as the release left it. */
|
|
23
|
+
function commitInsert(session, frame, points, userRotation) {
|
|
24
|
+
const resolved = resolveParams(session.opts?.params);
|
|
25
|
+
if (session.behaviors.length > 0) {
|
|
26
|
+
const r = reduceBehaviorEnd(session.behaviors, session.gestureCtx);
|
|
27
|
+
if (r === null) return false;
|
|
28
|
+
if (r !== void 0) {
|
|
29
|
+
if (!session.scene) return false;
|
|
30
|
+
return commitRunOps({
|
|
31
|
+
scene: session.scene,
|
|
32
|
+
applyOps: session.applyOps,
|
|
33
|
+
adapter: defaultCommitAdapter$1(session.scene, operandMethods$1(session.selection))
|
|
34
|
+
}, readRunLifecycle(resolved, "Insert", session.behaviors), r.length > 0 ? [...r, ...selectionOps(session)] : r);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
const { bounds, extras, ends } = insertShape(resolved, frame, points, userRotation, session.snap.landingAt, session.place.site);
|
|
38
|
+
if (!isCommittableExtent(bounds, extras)) return false;
|
|
39
|
+
return session.dep.commit(bounds, extras, ends, clearedSelection(session.priorSelection)) !== null;
|
|
40
|
+
}
|
|
41
|
+
/** The press's selection clear, as ops for a behavior's batch. */
|
|
42
|
+
function selectionOps(session) {
|
|
43
|
+
const prior = session.priorSelection;
|
|
44
|
+
return prior.length > 0 ? [ops.setSelection({
|
|
45
|
+
from: prior,
|
|
46
|
+
to: [],
|
|
47
|
+
label: "Insert"
|
|
48
|
+
})] : [];
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export { cancelInsert, commitInsert, restoreSelection };
|
|
52
|
+
//# sourceMappingURL=commit.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commit.js","names":["defaultCommitAdapter","operandMethods"],"sources":["../../../src/actions/insert/commit.ts"],"sourcesContent":["import type { DragSample } from '@weasel-js/routing';\nimport { resolveParams } from '@weasel-js/routing';\nimport { defaultCommitAdapter, operandMethods } from '@weasel-js/core/engine';\nimport { commitRunOps, readRunLifecycle, reduceBehaviorEnd, runBehaviorCancel } from '@weasel-js/core';\nimport { clearedSelection, type InsertFrame, type InsertSession } from './session';\nimport { insertShape, isCommittableExtent } from './shape';\nimport * as ops from '@weasel-js/core/ops';\n\n/** Put back the selection the press cleared, for a draw that ends without\n * committing. */\nexport function restoreSelection(session: Pick<InsertSession, 'priorSelection' | 'selection'>): void {\n if (session.priorSelection.length > 0) session.selection?.set([...session.priorSelection]);\n}\n\n/** Cancel the insert: tell the behaviors, and put the selection the draw\n * cleared back. */\nexport function cancelInsert(\n session: Pick<InsertSession, 'behaviors' | 'gestureCtx' | 'priorSelection' | 'selection'>,\n): void {\n runBehaviorCancel(session.behaviors, session.gestureCtx);\n restoreSelection(session);\n}\n\n/** Commit the insert. Returns whether it committed: a behavior's ops reached\n * the scene, or the `insert` dep minted a node. `points` is the pointer\n * trail as the release left it. */\nexport function commitInsert(\n session: InsertSession,\n frame: Pick<InsertFrame, 'shaped' | 'altHeld'>,\n points: ReadonlyArray<DragSample> | null,\n userRotation: number,\n): boolean {\n // Resolve params at commit time so thunked params (polygon\n // `sides` adjusted mid-drag, etc.) see the latest tool state.\n const resolved = resolveParams(session.opts?.params);\n\n if (session.behaviors.length > 0) {\n const r = reduceBehaviorEnd(session.behaviors, session.gestureCtx);\n if (r === null) return false;\n if (r !== undefined) {\n if (!session.scene) return false;\n return commitRunOps(\n {\n scene: session.scene,\n applyOps: session.applyOps,\n adapter: defaultCommitAdapter(session.scene, operandMethods(session.selection)),\n },\n readRunLifecycle(resolved, 'Insert', session.behaviors),\n r.length > 0 ? [...r, ...selectionOps(session)] : r,\n );\n }\n }\n\n const { bounds, extras, ends } = insertShape(resolved, frame, points, userRotation, session.snap.landingAt, session.place.site);\n // Sub-threshold drag — no insert.\n if (!isCommittableExtent(bounds, extras)) return false;\n\n const id = session.dep.commit(bounds, extras, ends, clearedSelection(session.priorSelection));\n return id !== null;\n}\n\n/** The press's selection clear, as ops for a behavior's batch. */\nfunction selectionOps(session: Pick<InsertSession, 'priorSelection'>) {\n const prior = session.priorSelection;\n return prior.length > 0 ? [ops.setSelection({ from: prior, to: [], label: 'Insert' })] : [];\n}\n"],"mappings":";;;;;;;;;;AAUA,SAAgB,iBAAiB,SAAoE;CACnG,IAAI,QAAQ,eAAe,SAAS,GAAG,QAAQ,WAAW,IAAI,CAAC,GAAG,QAAQ,cAAc,CAAC;AAC3F;;;AAIA,SAAgB,aACd,SACM;CACN,kBAAkB,QAAQ,WAAW,QAAQ,UAAU;CACvD,iBAAiB,OAAO;AAC1B;;;;AAKA,SAAgB,aACd,SACA,OACA,QACA,cACS;CAGT,MAAM,WAAW,cAAc,QAAQ,MAAM,MAAM;CAEnD,IAAI,QAAQ,UAAU,SAAS,GAAG;EAChC,MAAM,IAAI,kBAAkB,QAAQ,WAAW,QAAQ,UAAU;EACjE,IAAI,MAAM,MAAM,OAAO;EACvB,IAAI,MAAM,QAAW;GACnB,IAAI,CAAC,QAAQ,OAAO,OAAO;GAC3B,OAAO,aACL;IACE,OAAO,QAAQ;IACf,UAAU,QAAQ;IAClB,SAASA,uBAAqB,QAAQ,OAAOC,iBAAe,QAAQ,SAAS,CAAC;GAChF,GACA,iBAAiB,UAAU,UAAU,QAAQ,SAAS,GACtD,EAAE,SAAS,IAAI,CAAC,GAAG,GAAG,GAAG,aAAa,OAAO,CAAC,IAAI,CACpD;EACF;CACF;CAEA,MAAM,EAAE,QAAQ,QAAQ,SAAS,YAAY,UAAU,OAAO,QAAQ,cAAc,QAAQ,KAAK,WAAW,QAAQ,MAAM,IAAI;CAE9H,IAAI,CAAC,oBAAoB,QAAQ,MAAM,GAAG,OAAO;CAGjD,OADW,QAAQ,IAAI,OAAO,QAAQ,QAAQ,MAAM,iBAAiB,QAAQ,cAAc,CACpF,MAAO;AAChB;;AAGA,SAAS,aAAa,SAAgD;CACpE,MAAM,QAAQ,QAAQ;CACtB,OAAO,MAAM,SAAS,IAAI,CAAC,IAAI,aAAa;EAAE,MAAM;EAAO,IAAI,CAAC;EAAG,OAAO;CAAS,CAAC,CAAC,IAAI,CAAC;AAC5F"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { SHAPE_DEFAULTS } from "@weasel-js/core";
|
|
2
|
+
|
|
3
|
+
// src/actions/insert/extras.ts
|
|
4
|
+
/** Build a typed `InsertExtras` from the static params + gesture context.
|
|
5
|
+
* Kit-built-in kinds (line / polygon / star / pencil) read kind-specific
|
|
6
|
+
* fields; unknown kinds pass the raw params through as `{ kind, ... }`. */
|
|
7
|
+
function buildExtras(params, startX, startY, currentX, currentY, points) {
|
|
8
|
+
const kind = params?.kind ?? "rect";
|
|
9
|
+
switch (kind) {
|
|
10
|
+
case "rect":
|
|
11
|
+
case "ellipse": return { kind };
|
|
12
|
+
case "line": return {
|
|
13
|
+
kind: "line",
|
|
14
|
+
a: {
|
|
15
|
+
x: startX,
|
|
16
|
+
y: startY
|
|
17
|
+
},
|
|
18
|
+
b: {
|
|
19
|
+
x: currentX,
|
|
20
|
+
y: currentY
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
case "polygon": {
|
|
24
|
+
const sides = Number(params?.["sides"] ?? SHAPE_DEFAULTS.sides);
|
|
25
|
+
const dragAngle = currentX === startX && currentY === startY ? 0 : Math.atan2(currentY - startY, currentX - startX);
|
|
26
|
+
const extras = {
|
|
27
|
+
kind: "polygon",
|
|
28
|
+
sides,
|
|
29
|
+
rotation: params?.["rotation"] !== void 0 ? Number(params["rotation"]) : dragAngle
|
|
30
|
+
};
|
|
31
|
+
if (params?.["originMode"] === "center") {
|
|
32
|
+
const dx = currentX - startX;
|
|
33
|
+
const dy = currentY - startY;
|
|
34
|
+
extras.center = {
|
|
35
|
+
x: startX,
|
|
36
|
+
y: startY
|
|
37
|
+
};
|
|
38
|
+
extras.radius = Math.hypot(dx, dy);
|
|
39
|
+
} else {
|
|
40
|
+
if (params?.["center"] !== void 0) extras.center = params["center"];
|
|
41
|
+
if (params?.["radius"] !== void 0) extras.radius = params["radius"];
|
|
42
|
+
}
|
|
43
|
+
return extras;
|
|
44
|
+
}
|
|
45
|
+
case "star": {
|
|
46
|
+
const pts = Number(params?.["points"] ?? SHAPE_DEFAULTS.points);
|
|
47
|
+
const ir = Number(params?.["innerRadiusRatio"] ?? SHAPE_DEFAULTS.innerRadiusRatio);
|
|
48
|
+
const dragAngle = currentX === startX && currentY === startY ? 0 : Math.atan2(currentY - startY, currentX - startX);
|
|
49
|
+
const extras = {
|
|
50
|
+
kind: "star",
|
|
51
|
+
points: pts,
|
|
52
|
+
innerRadiusRatio: ir,
|
|
53
|
+
rotation: params?.["rotation"] !== void 0 ? Number(params["rotation"]) : dragAngle
|
|
54
|
+
};
|
|
55
|
+
if (params?.["originMode"] === "center") {
|
|
56
|
+
const dx = currentX - startX;
|
|
57
|
+
const dy = currentY - startY;
|
|
58
|
+
extras.center = {
|
|
59
|
+
x: startX,
|
|
60
|
+
y: startY
|
|
61
|
+
};
|
|
62
|
+
extras.outerRadius = Math.hypot(dx, dy);
|
|
63
|
+
} else {
|
|
64
|
+
if (params?.["center"] !== void 0) extras.center = params["center"];
|
|
65
|
+
if (params?.["outerRadius"] !== void 0) extras.outerRadius = params["outerRadius"];
|
|
66
|
+
}
|
|
67
|
+
return extras;
|
|
68
|
+
}
|
|
69
|
+
case "pencil": return {
|
|
70
|
+
kind: "pencil",
|
|
71
|
+
samples: params?.samples ?? points ?? []
|
|
72
|
+
};
|
|
73
|
+
default: return {
|
|
74
|
+
...params ?? {},
|
|
75
|
+
kind
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/** Add a user-driven rotation offset onto kinds that carry rotation. Rect
|
|
80
|
+
* / ellipse / line / pencil don't expose a rotation field on their
|
|
81
|
+
* extras today, so they ignore the offset. */
|
|
82
|
+
function applyUserRotation(extras, userRotation) {
|
|
83
|
+
if (userRotation === 0) return;
|
|
84
|
+
if (extras.kind === "star" || extras.kind === "polygon") extras.rotation += userRotation;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export { applyUserRotation, buildExtras };
|
|
88
|
+
//# sourceMappingURL=extras.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extras.js","names":[],"sources":["../../../src/actions/insert/extras.ts"],"sourcesContent":["import type { DragSample } from '@weasel-js/routing';\nimport type { InsertExtras } from '@weasel-js/core/engine';\nimport { SHAPE_DEFAULTS, type InsertParams } from '@weasel-js/core';\n\n/** Build a typed `InsertExtras` from the static params + gesture context.\n * Kit-built-in kinds (line / polygon / star / pencil) read kind-specific\n * fields; unknown kinds pass the raw params through as `{ kind, ... }`. */\nexport function buildExtras(\n params: Readonly<Partial<InsertParams>> | undefined,\n startX: number,\n startY: number,\n currentX: number,\n currentY: number,\n points: ReadonlyArray<DragSample> | null,\n): InsertExtras {\n const kind = params?.kind ?? 'rect';\n switch (kind) {\n case 'rect':\n case 'ellipse':\n return { kind } as InsertExtras;\n case 'line':\n // Use the live drag endpoints (not AABB) so the line preserves the\n // user's drag direction — drag from bottom-left to top-right makes a\n // line that slopes up, not the bounds diagonal.\n return { kind: 'line', a: { x: startX, y: startY }, b: { x: currentX, y: currentY } };\n case 'polygon': {\n const sides = Number(params?.['sides'] ?? SHAPE_DEFAULTS.sides);\n // When the tool omits rotation, point the first vertex along the\n // drag vector so dragging in a direction orients the shape that\n // way. Sub-pixel drags (no direction yet) fall back to 0.\n const dragAngle = (currentX === startX && currentY === startY)\n ? 0\n : Math.atan2(currentY - startY, currentX - startX);\n const rotation = params?.['rotation'] !== undefined\n ? Number(params['rotation'])\n : dragAngle;\n const extras: InsertExtras = { kind: 'polygon', sides, rotation };\n // Drag-from-center: tool's Alt binding passes `originMode:'center'`.\n // Compute polygon center + radius from the drag vector so the shape\n // anchors on the click point. Without this, the dep falls back to\n // inscribing in the AABB (drag-from-corner default).\n if (params?.['originMode'] === 'center') {\n const dx = currentX - startX;\n const dy = currentY - startY;\n (extras as { center?: unknown }).center = { x: startX, y: startY };\n (extras as { radius?: unknown }).radius = Math.hypot(dx, dy);\n } else {\n if (params?.['center'] !== undefined) (extras as { center?: unknown }).center = params['center'];\n if (params?.['radius'] !== undefined) (extras as { radius?: unknown }).radius = params['radius'];\n }\n return extras;\n }\n case 'star': {\n const pts = Number(params?.['points'] ?? SHAPE_DEFAULTS.points);\n const ir = Number(params?.['innerRadiusRatio'] ?? SHAPE_DEFAULTS.innerRadiusRatio);\n const dragAngle = (currentX === startX && currentY === startY)\n ? 0\n : Math.atan2(currentY - startY, currentX - startX);\n const rotation = params?.['rotation'] !== undefined\n ? Number(params['rotation'])\n : dragAngle;\n const extras: InsertExtras = { kind: 'star', points: pts, innerRadiusRatio: ir, rotation };\n if (params?.['originMode'] === 'center') {\n const dx = currentX - startX;\n const dy = currentY - startY;\n (extras as { center?: unknown }).center = { x: startX, y: startY };\n (extras as { outerRadius?: unknown }).outerRadius = Math.hypot(dx, dy);\n } else {\n if (params?.['center'] !== undefined) (extras as { center?: unknown }).center = params['center'];\n if (params?.['outerRadius'] !== undefined) (extras as { outerRadius?: unknown }).outerRadius = params['outerRadius'];\n }\n return extras;\n }\n case 'pencil':\n // Prefer tool-supplied samples (param) when present — pencil tools may\n // capture richer per-sample data (pressure/tilt). Fall back to the\n // dispatcher's accumulated pointer trail.\n return {\n kind: 'pencil',\n samples: params?.samples\n ?? points\n ?? [],\n };\n default:\n // Consumer-defined kind: pass everything through so a custom insert\n // dep can read its own fields.\n return { ...(params ?? {}), kind } as InsertExtras;\n }\n}\n\n/** Add a user-driven rotation offset onto kinds that carry rotation. Rect\n * / ellipse / line / pencil don't expose a rotation field on their\n * extras today, so they ignore the offset. */\nexport function applyUserRotation(extras: InsertExtras, userRotation: number): void {\n if (userRotation === 0) return;\n if (extras.kind === 'star' || extras.kind === 'polygon') {\n (extras as { rotation: number }).rotation += userRotation;\n }\n}\n"],"mappings":";;;;;;AAOA,SAAgB,YACd,QACA,QACA,QACA,UACA,UACA,QACc;CACd,MAAM,OAAO,QAAQ,QAAQ;CAC7B,QAAQ,MAAR;EACE,KAAK;EACL,KAAK,WACH,OAAO,EAAE,KAAK;EAChB,KAAK,QAIH,OAAO;GAAE,MAAM;GAAQ,GAAG;IAAE,GAAG;IAAQ,GAAG;GAAO;GAAG,GAAG;IAAE,GAAG;IAAU,GAAG;GAAS;EAAE;EACtF,KAAK,WAAW;GACd,MAAM,QAAQ,OAAO,SAAS,YAAY,eAAe,KAAK;GAI9D,MAAM,YAAa,aAAa,UAAU,aAAa,SACnD,IACA,KAAK,MAAM,WAAW,QAAQ,WAAW,MAAM;GAInD,MAAM,SAAuB;IAAE,MAAM;IAAW;IAAO,UAHtC,SAAS,gBAAgB,SACtC,OAAO,OAAO,WAAW,IACzB;GAC4D;GAKhE,IAAI,SAAS,kBAAkB,UAAU;IACvC,MAAM,KAAK,WAAW;IACtB,MAAM,KAAK,WAAW;IACtB,OAAiC,SAAS;KAAE,GAAG;KAAQ,GAAG;IAAO;IACjE,OAAiC,SAAS,KAAK,MAAM,IAAI,EAAE;GAC7D,OAAO;IACL,IAAI,SAAS,cAAc,QAAW,OAAiC,SAAS,OAAO;IACvF,IAAI,SAAS,cAAc,QAAW,OAAiC,SAAS,OAAO;GACzF;GACA,OAAO;EACT;EACA,KAAK,QAAQ;GACX,MAAM,MAAM,OAAO,SAAS,aAAa,eAAe,MAAM;GAC9D,MAAM,KAAK,OAAO,SAAS,uBAAuB,eAAe,gBAAgB;GACjF,MAAM,YAAa,aAAa,UAAU,aAAa,SACnD,IACA,KAAK,MAAM,WAAW,QAAQ,WAAW,MAAM;GAInD,MAAM,SAAuB;IAAE,MAAM;IAAQ,QAAQ;IAAK,kBAAkB;IAAI,UAH/D,SAAS,gBAAgB,SACtC,OAAO,OAAO,WAAW,IACzB;GACqF;GACzF,IAAI,SAAS,kBAAkB,UAAU;IACvC,MAAM,KAAK,WAAW;IACtB,MAAM,KAAK,WAAW;IACtB,OAAiC,SAAS;KAAE,GAAG;KAAQ,GAAG;IAAO;IACjE,OAAsC,cAAc,KAAK,MAAM,IAAI,EAAE;GACvE,OAAO;IACL,IAAI,SAAS,cAAc,QAAW,OAAiC,SAAS,OAAO;IACvF,IAAI,SAAS,mBAAmB,QAAW,OAAsC,cAAc,OAAO;GACxG;GACA,OAAO;EACT;EACA,KAAK,UAIH,OAAO;GACL,MAAM;GACN,SAAS,QAAQ,WACZ,UACA,CAAC;EACR;EACF,SAGE,OAAO;GAAE,GAAI,UAAU,CAAC;GAAI;EAAK;CACrC;AACF;;;;AAKA,SAAgB,kBAAkB,QAAsB,cAA4B;CAClF,IAAI,iBAAiB,GAAG;CACxB,IAAI,OAAO,SAAS,UAAU,OAAO,SAAS,WAC5C,OAAiC,YAAY;AAEjD"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { effectiveOriginMode, insertRectFor } from "./geometry.js";
|
|
2
|
+
import { GESTURE_KEY } from "./session.js";
|
|
3
|
+
import { pointerStateOf } from "@weasel-js/core";
|
|
4
|
+
import { resolveParams } from "@weasel-js/routing";
|
|
5
|
+
import { snapMods } from "@weasel-js/core/engine";
|
|
6
|
+
|
|
7
|
+
// src/actions/insert/frame.ts
|
|
8
|
+
/**
|
|
9
|
+
* Shape the raw pointer into the drag's endpoints: the snap session (with
|
|
10
|
+
* the line kind's Shift step as its input subspace, about the snapped
|
|
11
|
+
* start), then each behavior's `onMove`, each seeing the points the one
|
|
12
|
+
* before it returned. A point a snap target holds is not moved by a
|
|
13
|
+
* behavior.
|
|
14
|
+
*/
|
|
15
|
+
function shapeEndpoints(session, readers, raw, moveCtx) {
|
|
16
|
+
const gctx = session.gestureCtx;
|
|
17
|
+
let start = gctx.origin.get(GESTURE_KEY);
|
|
18
|
+
const end = session.snap.end(raw.pointer, snapMods(moveCtx));
|
|
19
|
+
let current = end.point;
|
|
20
|
+
if (session.behaviors.length > 0) {
|
|
21
|
+
const resolved = resolveParams(session.opts?.params);
|
|
22
|
+
const startHeld = session.snap.startHeld();
|
|
23
|
+
gctx.modifiers = { ...moveCtx.modifiers };
|
|
24
|
+
gctx.pointer = pointerStateOf(raw.pointer, moveCtx);
|
|
25
|
+
gctx.view = readers.view();
|
|
26
|
+
gctx.plane = readers.plane();
|
|
27
|
+
gctx.current.set(GESTURE_KEY, current);
|
|
28
|
+
const mode = effectiveOriginMode(resolved?.["originMode"], raw.altHeld);
|
|
29
|
+
let shapedEnd = false;
|
|
30
|
+
for (const b of session.behaviors) {
|
|
31
|
+
const bounds = insertRectFor(start.x, start.y, current.x, current.y, mode);
|
|
32
|
+
const r = b.onMove?.(gctx, {
|
|
33
|
+
start,
|
|
34
|
+
current,
|
|
35
|
+
bounds,
|
|
36
|
+
pose: bounds
|
|
37
|
+
});
|
|
38
|
+
if (!r) continue;
|
|
39
|
+
if (r.start && !startHeld) start = r.start;
|
|
40
|
+
if (r.current && !end.held) {
|
|
41
|
+
current = r.current;
|
|
42
|
+
shapedEnd = true;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
if (!shapedEnd && session.snap.anchor(start)) current = session.snap.end(raw.pointer, snapMods(moveCtx)).point;
|
|
46
|
+
gctx.current.set(GESTURE_KEY, current);
|
|
47
|
+
}
|
|
48
|
+
return {
|
|
49
|
+
start,
|
|
50
|
+
current
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
/** Move the drag's start point by the pointer's step from `from` to `to`, so
|
|
54
|
+
* the shape travels with the pointer instead of resizing. The start is
|
|
55
|
+
* carried unsnapped and snapped where it lands, in the container its site
|
|
56
|
+
* is carried into. */
|
|
57
|
+
function carryStart(session, from, to, moveCtx) {
|
|
58
|
+
const dx = to.x - from.x;
|
|
59
|
+
const dy = to.y - from.y;
|
|
60
|
+
const { place } = session;
|
|
61
|
+
place.site = {
|
|
62
|
+
x: place.site.x + dx,
|
|
63
|
+
y: place.site.y + dy
|
|
64
|
+
};
|
|
65
|
+
place.parent = place.parentAt(place.site);
|
|
66
|
+
const landed = session.snap.carry(dx, dy, snapMods(moveCtx));
|
|
67
|
+
const shift = landed.held ? {
|
|
68
|
+
x: 0,
|
|
69
|
+
y: 0
|
|
70
|
+
} : session.startShift;
|
|
71
|
+
const origin = {
|
|
72
|
+
x: landed.point.x + shift.x,
|
|
73
|
+
y: landed.point.y + shift.y
|
|
74
|
+
};
|
|
75
|
+
session.gestureCtx.origin.set(GESTURE_KEY, origin);
|
|
76
|
+
session.snap.anchor(origin);
|
|
77
|
+
}
|
|
78
|
+
/** One pump event's pointer, modifiers, and trail, and the endpoints they
|
|
79
|
+
* shape to. Each behavior's `onMove` runs once per call. */
|
|
80
|
+
function nextFrame(session, readers, prev, moveCtx) {
|
|
81
|
+
const raw = {
|
|
82
|
+
pointer: {
|
|
83
|
+
x: moveCtx.world.x,
|
|
84
|
+
y: moveCtx.world.y
|
|
85
|
+
},
|
|
86
|
+
altHeld: moveCtx.modifiers.alt
|
|
87
|
+
};
|
|
88
|
+
return {
|
|
89
|
+
...raw,
|
|
90
|
+
points: moveCtx.drag?.points ? moveCtx.drag.points : prev.points,
|
|
91
|
+
shaped: shapeEndpoints(session, readers, raw, moveCtx)
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export { carryStart, nextFrame };
|
|
96
|
+
//# sourceMappingURL=frame.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"frame.js","names":[],"sources":["../../../src/actions/insert/frame.ts"],"sourcesContent":["import type { InvocationCtx } from '@weasel-js/routing';\nimport { pointerStateOf } from '@weasel-js/core';\nimport { resolveParams } from '@weasel-js/routing';\nimport { snapMods } from '@weasel-js/core/engine';\nimport type { GestureReaders } from '@weasel-js/core';\nimport type { InsertPoint } from '@weasel-js/core/engine';\nimport { insertRectFor, effectiveOriginMode } from './geometry';\nimport { GESTURE_KEY, type InsertFrame, type InsertSession } from './session';\n\n/**\n * Shape the raw pointer into the drag's endpoints: the snap session (with\n * the line kind's Shift step as its input subspace, about the snapped\n * start), then each behavior's `onMove`, each seeing the points the one\n * before it returned. A point a snap target holds is not moved by a\n * behavior.\n */\nfunction shapeEndpoints(\n session: Pick<InsertSession, 'opts' | 'snap' | 'behaviors' | 'gestureCtx'>,\n readers: GestureReaders,\n raw: Pick<InsertFrame, 'pointer' | 'altHeld'>,\n moveCtx: Pick<InvocationCtx, 'modifiers' | 'screen' | 'roles'>,\n): { start: InsertPoint; current: InsertPoint } {\n const gctx = session.gestureCtx;\n let start = gctx.origin.get(GESTURE_KEY) as InsertPoint;\n const end = session.snap.end(raw.pointer, snapMods(moveCtx));\n let current = end.point;\n\n if (session.behaviors.length > 0) {\n const resolved = resolveParams(session.opts?.params);\n const startHeld = session.snap.startHeld();\n gctx.modifiers = { ...moveCtx.modifiers };\n gctx.pointer = pointerStateOf(raw.pointer, moveCtx);\n gctx.view = readers.view();\n gctx.plane = readers.plane();\n gctx.current.set(GESTURE_KEY, current);\n const mode = effectiveOriginMode(resolved?.['originMode'], raw.altHeld);\n let shapedEnd = false;\n for (const b of session.behaviors) {\n const bounds = insertRectFor(start.x, start.y, current.x, current.y, mode);\n const r = b.onMove?.(gctx, { start, current, bounds, pose: bounds });\n if (!r) continue;\n if (r.start && !startHeld) start = r.start;\n if (r.current && !end.held) { current = r.current; shapedEnd = true; }\n }\n // The end the snap placed turns about the start as drawn, the behaviors' included.\n if (!shapedEnd && session.snap.anchor(start)) current = session.snap.end(raw.pointer, snapMods(moveCtx)).point;\n gctx.current.set(GESTURE_KEY, current);\n }\n return { start, current };\n}\n\n/** Move the drag's start point by the pointer's step from `from` to `to`, so\n * the shape travels with the pointer instead of resizing. The start is\n * carried unsnapped and snapped where it lands, in the container its site\n * is carried into. */\nexport function carryStart(\n session: Pick<InsertSession, 'snap' | 'gestureCtx' | 'place' | 'startShift'>,\n from: InsertPoint,\n to: InsertPoint,\n moveCtx: Pick<InvocationCtx, 'modifiers' | 'roles'>,\n): void {\n const dx = to.x - from.x;\n const dy = to.y - from.y;\n // The site travels with the shape, and the container under it is the one the start snaps in.\n const { place } = session;\n place.site = { x: place.site.x + dx, y: place.site.y + dy };\n place.parent = place.parentAt(place.site);\n const landed = session.snap.carry(dx, dy, snapMods(moveCtx));\n // A snap target holds the start where it put it; otherwise the start keeps the behaviors' shaping.\n const shift = landed.held ? { x: 0, y: 0 } : session.startShift;\n const origin = { x: landed.point.x + shift.x, y: landed.point.y + shift.y };\n session.gestureCtx.origin.set(GESTURE_KEY, origin);\n session.snap.anchor(origin);\n}\n\n/** One pump event's pointer, modifiers, and trail, and the endpoints they\n * shape to. Each behavior's `onMove` runs once per call. */\nexport function nextFrame(\n session: InsertSession,\n readers: GestureReaders,\n prev: Pick<InsertFrame, 'points'>,\n moveCtx: InvocationCtx,\n): InsertFrame {\n const raw = {\n pointer: { x: moveCtx.world.x, y: moveCtx.world.y },\n // Each pointermove carries fresh modifier state from the dispatcher;\n // releasing / pressing a key mid-drag takes effect on the next move tick\n // (true modifier-only events don't fire without a cursor change).\n altHeld: moveCtx.modifiers.alt,\n };\n return {\n ...raw,\n // The dispatcher mutates its own per-gesture trail in place but\n // attaches the array reference to each InvocationCtx.drag — keep\n // the latest reference in case the dispatcher swaps it.\n points: moveCtx.drag?.points ? moveCtx.drag.points : prev.points,\n shaped: shapeEndpoints(session, readers, raw, moveCtx),\n };\n}\n"],"mappings":";;;;;;;;;;;;;;AAgBA,SAAS,eACP,SACA,SACA,KACA,SAC8C;CAC9C,MAAM,OAAO,QAAQ;CACrB,IAAI,QAAQ,KAAK,OAAO,IAAI,WAAW;CACvC,MAAM,MAAM,QAAQ,KAAK,IAAI,IAAI,SAAS,SAAS,OAAO,CAAC;CAC3D,IAAI,UAAU,IAAI;CAElB,IAAI,QAAQ,UAAU,SAAS,GAAG;EAChC,MAAM,WAAW,cAAc,QAAQ,MAAM,MAAM;EACnD,MAAM,YAAY,QAAQ,KAAK,UAAU;EACzC,KAAK,YAAY,EAAE,GAAG,QAAQ,UAAU;EACxC,KAAK,UAAU,eAAe,IAAI,SAAS,OAAO;EAClD,KAAK,OAAO,QAAQ,KAAK;EACzB,KAAK,QAAQ,QAAQ,MAAM;EAC3B,KAAK,QAAQ,IAAI,aAAa,OAAO;EACrC,MAAM,OAAO,oBAAoB,WAAW,eAAe,IAAI,OAAO;EACtE,IAAI,YAAY;EAChB,KAAK,MAAM,KAAK,QAAQ,WAAW;GACjC,MAAM,SAAS,cAAc,MAAM,GAAG,MAAM,GAAG,QAAQ,GAAG,QAAQ,GAAG,IAAI;GACzE,MAAM,IAAI,EAAE,SAAS,MAAM;IAAE;IAAO;IAAS;IAAQ,MAAM;GAAO,CAAC;GACnE,IAAI,CAAC,GAAG;GACR,IAAI,EAAE,SAAS,CAAC,WAAW,QAAQ,EAAE;GACrC,IAAI,EAAE,WAAW,CAAC,IAAI,MAAM;IAAE,UAAU,EAAE;IAAS,YAAY;GAAM;EACvE;EAEA,IAAI,CAAC,aAAa,QAAQ,KAAK,OAAO,KAAK,GAAG,UAAU,QAAQ,KAAK,IAAI,IAAI,SAAS,SAAS,OAAO,CAAC,CAAC,CAAC;EACzG,KAAK,QAAQ,IAAI,aAAa,OAAO;CACvC;CACA,OAAO;EAAE;EAAO;CAAQ;AAC1B;;;;;AAMA,SAAgB,WACd,SACA,MACA,IACA,SACM;CACN,MAAM,KAAK,GAAG,IAAI,KAAK;CACvB,MAAM,KAAK,GAAG,IAAI,KAAK;CAEvB,MAAM,EAAE,UAAU;CAClB,MAAM,OAAO;EAAE,GAAG,MAAM,KAAK,IAAI;EAAI,GAAG,MAAM,KAAK,IAAI;CAAG;CAC1D,MAAM,SAAS,MAAM,SAAS,MAAM,IAAI;CACxC,MAAM,SAAS,QAAQ,KAAK,MAAM,IAAI,IAAI,SAAS,OAAO,CAAC;CAE3D,MAAM,QAAQ,OAAO,OAAO;EAAE,GAAG;EAAG,GAAG;CAAE,IAAI,QAAQ;CACrD,MAAM,SAAS;EAAE,GAAG,OAAO,MAAM,IAAI,MAAM;EAAG,GAAG,OAAO,MAAM,IAAI,MAAM;CAAE;CAC1E,QAAQ,WAAW,OAAO,IAAI,aAAa,MAAM;CACjD,QAAQ,KAAK,OAAO,MAAM;AAC5B;;;AAIA,SAAgB,UACd,SACA,SACA,MACA,SACa;CACb,MAAM,MAAM;EACV,SAAS;GAAE,GAAG,QAAQ,MAAM;GAAG,GAAG,QAAQ,MAAM;EAAE;EAIlD,SAAS,QAAQ,UAAU;CAC7B;CACA,OAAO;EACL,GAAG;EAIH,QAAQ,QAAQ,MAAM,SAAS,QAAQ,KAAK,SAAS,KAAK;EAC1D,QAAQ,eAAe,SAAS,SAAS,KAAK,OAAO;CACvD;AACF"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { rectBetween } from "@weasel-js/geom";
|
|
2
|
+
|
|
3
|
+
// src/actions/insert/geometry.ts
|
|
4
|
+
/** Resolve the effective origin mode from the binding's nominal opt
|
|
5
|
+
* and live Alt state. Alt inverts: `corner` ⇄ `center`. Applies to
|
|
6
|
+
* every shape kind — radial shapes (polygon/star) included; the
|
|
7
|
+
* overlay paints an `anchorPoint` dot at the click so corner mode
|
|
8
|
+
* reads as anchored even though no polygon vertex sits there.
|
|
9
|
+
*/
|
|
10
|
+
function effectiveOriginMode(paramsOrigin, altHeld) {
|
|
11
|
+
const nominal = paramsOrigin === "center" ? "center" : "corner";
|
|
12
|
+
if (!altHeld) return nominal;
|
|
13
|
+
return nominal === "center" ? "corner" : "center";
|
|
14
|
+
}
|
|
15
|
+
/** Compute the insert AABB from drag endpoints.
|
|
16
|
+
* - `'corner'` (default): bounds = drag rect (top-left → bottom-right of cursor sweep).
|
|
17
|
+
* - `'center'`: bounds = symmetric AABB anchored on the start point.
|
|
18
|
+
* Used when the tool's Alt-modifier binding passes
|
|
19
|
+
* `originMode: 'center'`. */
|
|
20
|
+
function insertRectFor(startX, startY, currentX, currentY, originMode) {
|
|
21
|
+
if (originMode === "center") {
|
|
22
|
+
const dx = Math.abs(currentX - startX);
|
|
23
|
+
const dy = Math.abs(currentY - startY);
|
|
24
|
+
return {
|
|
25
|
+
x: startX - dx,
|
|
26
|
+
y: startY - dy,
|
|
27
|
+
width: dx * 2,
|
|
28
|
+
height: dy * 2
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
return rectBetween(startX, startY, currentX, currentY);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export { effectiveOriginMode, insertRectFor };
|
|
35
|
+
//# sourceMappingURL=geometry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"geometry.js","names":[],"sources":["../../../src/actions/insert/geometry.ts"],"sourcesContent":["import { rectBetween, type Rect } from '@weasel-js/geom';\n\n/** Resolve the effective origin mode from the binding's nominal opt\n * and live Alt state. Alt inverts: `corner` ⇄ `center`. Applies to\n * every shape kind — radial shapes (polygon/star) included; the\n * overlay paints an `anchorPoint` dot at the click so corner mode\n * reads as anchored even though no polygon vertex sits there.\n */\nexport function effectiveOriginMode(\n paramsOrigin: unknown,\n altHeld: boolean,\n): 'corner' | 'center' {\n const nominal: 'corner' | 'center' = paramsOrigin === 'center' ? 'center' : 'corner';\n if (!altHeld) return nominal;\n return nominal === 'center' ? 'corner' : 'center';\n}\n\n/** Compute the insert AABB from drag endpoints.\n * - `'corner'` (default): bounds = drag rect (top-left → bottom-right of cursor sweep).\n * - `'center'`: bounds = symmetric AABB anchored on the start point.\n * Used when the tool's Alt-modifier binding passes\n * `originMode: 'center'`. */\nexport function insertRectFor(\n startX: number, startY: number,\n currentX: number, currentY: number,\n originMode: 'corner' | 'center',\n): Rect {\n if (originMode === 'center') {\n const dx = Math.abs(currentX - startX);\n const dy = Math.abs(currentY - startY);\n return { x: startX - dx, y: startY - dy, width: dx * 2, height: dy * 2 };\n }\n return rectBetween(startX, startY, currentX, currentY);\n}\n"],"mappings":";;;;;;;;;AAQA,SAAgB,oBACd,cACA,SACqB;CACrB,MAAM,UAA+B,iBAAiB,WAAW,WAAW;CAC5E,IAAI,CAAC,SAAS,OAAO;CACrB,OAAO,YAAY,WAAW,WAAW;AAC3C;;;;;;AAOA,SAAgB,cACd,QAAgB,QAChB,UAAkB,UAClB,YACM;CACN,IAAI,eAAe,UAAU;EAC3B,MAAM,KAAK,KAAK,IAAI,WAAW,MAAM;EACrC,MAAM,KAAK,KAAK,IAAI,WAAW,MAAM;EACrC,OAAO;GAAE,GAAG,SAAS;GAAI,GAAG,SAAS;GAAI,OAAO,KAAK;GAAG,QAAQ,KAAK;EAAE;CACzE;CACA,OAAO,YAAY,QAAQ,QAAQ,UAAU,QAAQ;AACvD"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { outputGridOf, quantizedNodePose } from "@weasel-js/core";
|
|
2
|
+
import { AUTO_POSE_DESCRIPTOR, composeChildFrame as composeChildFrame$1, composesFrames, insertPreviewExtent, sceneViewPoseAdapter } from "@weasel-js/core/engine";
|
|
3
|
+
|
|
4
|
+
// src/actions/insert/lands.ts
|
|
5
|
+
/**
|
|
6
|
+
* Where an insert's shape lands when the scene's quantize rule moves it off
|
|
7
|
+
* the box the drag made, for the preview's `lands`: the node the `insert` dep
|
|
8
|
+
* would make, as `stored` commits it. `undefined` when the rule changes
|
|
9
|
+
* nothing, the scene has no grid, or the dep cannot say what it would make.
|
|
10
|
+
*/
|
|
11
|
+
function insertLanding(scene, dep, bounds, extras, ends, parent = null) {
|
|
12
|
+
if (!scene.quantize?.stored || !outputGridOf(scene)) return void 0;
|
|
13
|
+
const node = dep.peek?.(bounds, extras, ends);
|
|
14
|
+
if (!node) return void 0;
|
|
15
|
+
const pose = quantizedNodePose(scene, node);
|
|
16
|
+
if (pose === node.pose) return void 0;
|
|
17
|
+
const world = worldOf(scene, parent);
|
|
18
|
+
const from = AUTO_POSE_DESCRIPTOR.getBounds(world(node.pose));
|
|
19
|
+
const to = AUTO_POSE_DESCRIPTOR.getBounds(world(pose));
|
|
20
|
+
const made = insertPreviewExtent({
|
|
21
|
+
shape: extras.kind,
|
|
22
|
+
bounds,
|
|
23
|
+
extras
|
|
24
|
+
}).bounds;
|
|
25
|
+
return {
|
|
26
|
+
x: made.x + to.x - from.x,
|
|
27
|
+
y: made.y + to.y - from.y,
|
|
28
|
+
width: made.width + to.width - from.width,
|
|
29
|
+
height: made.height + to.height - from.height
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
/** A pose stored under `parent`, as the world sees it. */
|
|
33
|
+
function worldOf(scene, parent) {
|
|
34
|
+
const composition = scene.composition;
|
|
35
|
+
if (parent === null || composition === void 0 || !composesFrames(composition)) return (p) => p;
|
|
36
|
+
const frame = composeChildFrame$1(sceneViewPoseAdapter(scene), parent, composition.compose);
|
|
37
|
+
return (p) => composition.compose(frame, p);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export { insertLanding };
|
|
41
|
+
//# sourceMappingURL=lands.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lands.js","names":["composeChildFrame"],"sources":["../../../src/actions/insert/lands.ts"],"sourcesContent":["import { AUTO_POSE_DESCRIPTOR, composeChildFrame, composesFrames, insertPreviewExtent, sceneViewPoseAdapter } from '@weasel-js/core/engine';\nimport { outputGridOf, quantizedNodePose } from '@weasel-js/core';\nimport type { Scene, InsertDep, InsertEnds, InsertExtras } from '@weasel-js/core/engine';\nimport type { Bounds, NodeId } from '@weasel-js/core';\n\n/**\n * Where an insert's shape lands when the scene's quantize rule moves it off\n * the box the drag made, for the preview's `lands`: the node the `insert` dep\n * would make, as `stored` commits it. `undefined` when the rule changes\n * nothing, the scene has no grid, or the dep cannot say what it would make.\n */\nexport function insertLanding(\n scene: Scene<unknown, string, unknown>,\n dep: Pick<InsertDep, 'peek'>,\n bounds: Bounds,\n extras: InsertExtras,\n ends?: InsertEnds,\n /** The container the node lands in, whose frame its stored pose is in. */\n parent: NodeId | null = null,\n): Bounds | undefined {\n if (!scene.quantize?.stored || !outputGridOf(scene)) return undefined;\n const node = dep.peek?.(bounds, extras, ends);\n if (!node) return undefined;\n const pose = quantizedNodePose(scene, node);\n if (pose === node.pose) return undefined;\n const world = worldOf(scene, parent);\n const from = AUTO_POSE_DESCRIPTOR.getBounds(world(node.pose));\n const to = AUTO_POSE_DESCRIPTOR.getBounds(world(pose));\n const made = insertPreviewExtent({ shape: extras.kind, bounds, extras }).bounds;\n return {\n x: made.x + to.x - from.x,\n y: made.y + to.y - from.y,\n width: made.width + to.width - from.width,\n height: made.height + to.height - from.height,\n };\n}\n\n/** A pose stored under `parent`, as the world sees it. */\nfunction worldOf(scene: Scene<unknown, string, unknown>, parent: NodeId | null): (local: unknown) => unknown {\n const composition = scene.composition;\n if (parent === null || composition === undefined || !composesFrames(composition)) return (p) => p;\n const frame = composeChildFrame(sceneViewPoseAdapter(scene), parent, composition.compose);\n return (p) => composition.compose(frame, p);\n}\n"],"mappings":";;;;;;;;;;AAWA,SAAgB,cACd,OACA,KACA,QACA,QACA,MAEA,SAAwB,MACJ;CACpB,IAAI,CAAC,MAAM,UAAU,UAAU,CAAC,aAAa,KAAK,GAAG,OAAO;CAC5D,MAAM,OAAO,IAAI,OAAO,QAAQ,QAAQ,IAAI;CAC5C,IAAI,CAAC,MAAM,OAAO;CAClB,MAAM,OAAO,kBAAkB,OAAO,IAAI;CAC1C,IAAI,SAAS,KAAK,MAAM,OAAO;CAC/B,MAAM,QAAQ,QAAQ,OAAO,MAAM;CACnC,MAAM,OAAO,qBAAqB,UAAU,MAAM,KAAK,IAAI,CAAC;CAC5D,MAAM,KAAK,qBAAqB,UAAU,MAAM,IAAI,CAAC;CACrD,MAAM,OAAO,oBAAoB;EAAE,OAAO,OAAO;EAAM;EAAQ;CAAO,CAAC,CAAC,CAAC;CACzE,OAAO;EACL,GAAG,KAAK,IAAI,GAAG,IAAI,KAAK;EACxB,GAAG,KAAK,IAAI,GAAG,IAAI,KAAK;EACxB,OAAO,KAAK,QAAQ,GAAG,QAAQ,KAAK;EACpC,QAAQ,KAAK,SAAS,GAAG,SAAS,KAAK;CACzC;AACF;;AAGA,SAAS,QAAQ,OAAwC,QAAoD;CAC3G,MAAM,cAAc,MAAM;CAC1B,IAAI,WAAW,QAAQ,gBAAgB,UAAa,CAAC,eAAe,WAAW,GAAG,QAAQ,MAAM;CAChG,MAAM,QAAQA,oBAAkB,qBAAqB,KAAK,GAAG,QAAQ,YAAY,OAAO;CACxF,QAAQ,MAAM,YAAY,QAAQ,OAAO,CAAC;AAC5C"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { insertKind } from "./shape.js";
|
|
2
|
+
import { SHAPE_COUNT_RANGE, SHAPE_DEFAULTS, STAR_RATIO_RANGE } from "@weasel-js/core";
|
|
3
|
+
import { pref } from "@weasel-js/prefs-schema";
|
|
4
|
+
|
|
5
|
+
// src/actions/insert/params.ts
|
|
6
|
+
/** A polygon insert's params as a form, for the last-operation panel. */
|
|
7
|
+
var POLYGON_INSERT_PARAMS = pref.group("Polygon", { sides: pref.number("Sides", SHAPE_DEFAULTS.sides, {
|
|
8
|
+
min: SHAPE_COUNT_RANGE.min,
|
|
9
|
+
max: SHAPE_COUNT_RANGE.max,
|
|
10
|
+
step: 1,
|
|
11
|
+
control: "slider"
|
|
12
|
+
}) });
|
|
13
|
+
/** A star insert's params as a form, for the last-operation panel. */
|
|
14
|
+
var STAR_INSERT_PARAMS = pref.group("Star", {
|
|
15
|
+
points: pref.number("Points", SHAPE_DEFAULTS.points, {
|
|
16
|
+
min: SHAPE_COUNT_RANGE.min,
|
|
17
|
+
max: SHAPE_COUNT_RANGE.max,
|
|
18
|
+
step: 1,
|
|
19
|
+
control: "slider"
|
|
20
|
+
}),
|
|
21
|
+
innerRadiusRatio: pref.number("Inner radius", SHAPE_DEFAULTS.innerRadiusRatio, {
|
|
22
|
+
description: "Inner radius as a fraction of the outer one.",
|
|
23
|
+
min: STAR_RATIO_RANGE.min,
|
|
24
|
+
max: STAR_RATIO_RANGE.max,
|
|
25
|
+
step: .01,
|
|
26
|
+
control: "slider",
|
|
27
|
+
unit: {
|
|
28
|
+
scale: .01,
|
|
29
|
+
suffix: "%",
|
|
30
|
+
places: 0
|
|
31
|
+
}
|
|
32
|
+
})
|
|
33
|
+
});
|
|
34
|
+
/** The form an insert of the kind `params` names shows: a polygon's sides, a star's points and inner radius, and
|
|
35
|
+
* none for any other kind. */
|
|
36
|
+
function insertParams(params) {
|
|
37
|
+
const kind = insertKind(params);
|
|
38
|
+
return kind === "polygon" ? POLYGON_INSERT_PARAMS : kind === "star" ? STAR_INSERT_PARAMS : null;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export { POLYGON_INSERT_PARAMS, STAR_INSERT_PARAMS, insertParams };
|
|
42
|
+
//# sourceMappingURL=params.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"params.js","names":[],"sources":["../../../src/actions/insert/params.ts"],"sourcesContent":["import { pref, type PrefGroup } from '@weasel-js/prefs-schema';\nimport { SHAPE_COUNT_RANGE, SHAPE_DEFAULTS, STAR_RATIO_RANGE } from '@weasel-js/core';\nimport { insertKind } from './shape';\n\n/** A polygon insert's params as a form, for the last-operation panel. */\nexport const POLYGON_INSERT_PARAMS = pref.group('Polygon', {\n sides: pref.number('Sides', SHAPE_DEFAULTS.sides, { min: SHAPE_COUNT_RANGE.min, max: SHAPE_COUNT_RANGE.max, step: 1, control: 'slider' }),\n});\n\n/** A star insert's params as a form, for the last-operation panel. */\nexport const STAR_INSERT_PARAMS = pref.group('Star', {\n points: pref.number('Points', SHAPE_DEFAULTS.points, { min: SHAPE_COUNT_RANGE.min, max: SHAPE_COUNT_RANGE.max, step: 1, control: 'slider' }),\n innerRadiusRatio: pref.number('Inner radius', SHAPE_DEFAULTS.innerRadiusRatio, {\n description: 'Inner radius as a fraction of the outer one.',\n min: STAR_RATIO_RANGE.min, max: STAR_RATIO_RANGE.max, step: 0.01, control: 'slider',\n unit: { scale: 0.01, suffix: '%', places: 0 },\n }),\n});\n\n/** The form an insert of the kind `params` names shows: a polygon's sides, a star's points and inner radius, and\n * none for any other kind. */\nexport function insertParams(params: Readonly<Record<string, unknown>>): PrefGroup | null {\n const kind = insertKind(params);\n return kind === 'polygon' ? POLYGON_INSERT_PARAMS : kind === 'star' ? STAR_INSERT_PARAMS : null;\n}\n"],"mappings":";;;;;;AAKA,IAAa,wBAAwB,KAAK,MAAM,WAAW,EACzD,OAAO,KAAK,OAAO,SAAS,eAAe,OAAO;CAAE,KAAK,kBAAkB;CAAK,KAAK,kBAAkB;CAAK,MAAM;CAAG,SAAS;AAAS,CAAC,EAC1I,CAAC;;AAGD,IAAa,qBAAqB,KAAK,MAAM,QAAQ;CACnD,QAAQ,KAAK,OAAO,UAAU,eAAe,QAAQ;EAAE,KAAK,kBAAkB;EAAK,KAAK,kBAAkB;EAAK,MAAM;EAAG,SAAS;CAAS,CAAC;CAC3I,kBAAkB,KAAK,OAAO,gBAAgB,eAAe,kBAAkB;EAC7E,aAAa;EACb,KAAK,iBAAiB;EAAK,KAAK,iBAAiB;EAAK,MAAM;EAAM,SAAS;EAC3E,MAAM;GAAE,OAAO;GAAM,QAAQ;GAAK,QAAQ;EAAE;CAC9C,CAAC;AACH,CAAC;;;AAID,SAAgB,aAAa,QAA6D;CACxF,MAAM,OAAO,WAAW,MAAM;CAC9B,OAAO,SAAS,YAAY,wBAAwB,SAAS,SAAS,qBAAqB;AAC7F"}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { restoreSelection } from "./commit.js";
|
|
2
|
+
import { insertShape } from "./shape.js";
|
|
3
|
+
import { clearedSelection } from "./session.js";
|
|
4
|
+
import { INSERT_GROUP } from "../../actionGroups.js";
|
|
5
|
+
import { inPlane, insertLayer, insertParent, minSizeOf } from "@weasel-js/core";
|
|
6
|
+
import { defineAction } from "@weasel-js/routing";
|
|
7
|
+
import { SNAP_ROLES, snapMods } from "@weasel-js/core/engine";
|
|
8
|
+
|
|
9
|
+
// src/actions/insert/placeAction.ts
|
|
10
|
+
/** What the dispatcher lays under an immediate action's params for a click. */
|
|
11
|
+
var CLICK_FIELDS = [
|
|
12
|
+
"world",
|
|
13
|
+
"press",
|
|
14
|
+
"affordance",
|
|
15
|
+
"mods",
|
|
16
|
+
"roles"
|
|
17
|
+
];
|
|
18
|
+
var NO_KEYS = {
|
|
19
|
+
alt: false,
|
|
20
|
+
ctrl: false,
|
|
21
|
+
meta: false,
|
|
22
|
+
shift: false
|
|
23
|
+
};
|
|
24
|
+
/** The keys a click held, and the roles the dispatcher resolved them to (`ImmediateParams`). */
|
|
25
|
+
function clickRoles(params) {
|
|
26
|
+
const p = params;
|
|
27
|
+
return {
|
|
28
|
+
modifiers: p?.mods ?? NO_KEYS,
|
|
29
|
+
...p?.roles ? { roles: p.roles } : {}
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Click-to-insert: the companion to `insertAction` for a click, which draws
|
|
34
|
+
* no box. It commits a node of `params.kind` at `params.size`, centered on the
|
|
35
|
+
* click, snapped through a `point` session of the `snap` dep unless the
|
|
36
|
+
* click held `snap.suspend` (Ctrl), and commits
|
|
37
|
+
* through the same `insert` dep a drag commits through. Its extras are the
|
|
38
|
+
* ones a drag out from the click's center to the size's corner makes
|
|
39
|
+
* (`insertShape`), built from the rest of the binding's params.
|
|
40
|
+
*
|
|
41
|
+
* A `minSize` in the params floors the size, and goes on to the node. Style
|
|
42
|
+
* params (a shape tool's fill, stroke, …) reach the dep as `extras.style`.
|
|
43
|
+
*
|
|
44
|
+
* A binding with no `size` places nothing: the kind's extent is the tool's to
|
|
45
|
+
* name, and a click has none of its own.
|
|
46
|
+
*/
|
|
47
|
+
var placeAction = inPlane(defineAction({
|
|
48
|
+
id: "place",
|
|
49
|
+
label: "Place",
|
|
50
|
+
group: INSERT_GROUP,
|
|
51
|
+
eligible: { capability: "creates-shapes" },
|
|
52
|
+
modifierRoles: SNAP_ROLES,
|
|
53
|
+
requires: [
|
|
54
|
+
"insert",
|
|
55
|
+
"insertInto",
|
|
56
|
+
"canDropInto",
|
|
57
|
+
"operands",
|
|
58
|
+
"snap",
|
|
59
|
+
"scene"
|
|
60
|
+
],
|
|
61
|
+
invoker: {
|
|
62
|
+
timing: "immediate",
|
|
63
|
+
run(deps, params) {
|
|
64
|
+
const dep = deps.insert;
|
|
65
|
+
const asked = params?.size;
|
|
66
|
+
const min = minSizeOf(params);
|
|
67
|
+
const size = asked && min ? {
|
|
68
|
+
width: Math.max(asked.width, min.width),
|
|
69
|
+
height: Math.max(asked.height, min.height)
|
|
70
|
+
} : asked;
|
|
71
|
+
const world = params?.world;
|
|
72
|
+
if (!dep || !size || !world) return;
|
|
73
|
+
const { x, y } = world;
|
|
74
|
+
if (!(size.width > 0 && size.height > 0)) return;
|
|
75
|
+
const prior = deps.operands ? [...deps.operands.get()] : [];
|
|
76
|
+
deps.operands?.set([]);
|
|
77
|
+
let committed = false;
|
|
78
|
+
try {
|
|
79
|
+
const parent = insertParent(deps.scene, deps.insertInto?.get(), deps.canDropInto, {
|
|
80
|
+
x,
|
|
81
|
+
y
|
|
82
|
+
});
|
|
83
|
+
const snap = deps.snap?.begin({
|
|
84
|
+
gesture: "point",
|
|
85
|
+
press: {
|
|
86
|
+
x,
|
|
87
|
+
y
|
|
88
|
+
},
|
|
89
|
+
...parent === null ? {} : { parent }
|
|
90
|
+
});
|
|
91
|
+
let out;
|
|
92
|
+
try {
|
|
93
|
+
out = snap?.at({
|
|
94
|
+
x,
|
|
95
|
+
y
|
|
96
|
+
}, snapMods(clickRoles(params)));
|
|
97
|
+
} finally {
|
|
98
|
+
snap?.end();
|
|
99
|
+
}
|
|
100
|
+
const at = out ? out.point : {
|
|
101
|
+
x,
|
|
102
|
+
y
|
|
103
|
+
};
|
|
104
|
+
const binding = {
|
|
105
|
+
...params,
|
|
106
|
+
originMode: "center"
|
|
107
|
+
};
|
|
108
|
+
for (const k of [...CLICK_FIELDS, "size"]) delete binding[k];
|
|
109
|
+
const landing = out?.landing;
|
|
110
|
+
const { bounds, extras, ends } = insertShape(binding, {
|
|
111
|
+
shaped: {
|
|
112
|
+
start: at,
|
|
113
|
+
current: {
|
|
114
|
+
x: at.x + size.width / 2,
|
|
115
|
+
y: at.y + size.height / 2
|
|
116
|
+
}
|
|
117
|
+
},
|
|
118
|
+
altHeld: false
|
|
119
|
+
}, null, 0, (p) => p === at ? landing : void 0, {
|
|
120
|
+
x,
|
|
121
|
+
y
|
|
122
|
+
});
|
|
123
|
+
committed = dep.commit(bounds, extras, ends, clearedSelection(prior)) !== null;
|
|
124
|
+
} finally {
|
|
125
|
+
if (!committed) restoreSelection({
|
|
126
|
+
priorSelection: prior,
|
|
127
|
+
selection: deps.operands
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
},
|
|
132
|
+
/** Like `insert`, needs no selection. */
|
|
133
|
+
enabled: () => true
|
|
134
|
+
}), insertLayer);
|
|
135
|
+
|
|
136
|
+
export { placeAction };
|
|
137
|
+
//# sourceMappingURL=placeAction.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"placeAction.js","names":[],"sources":["../../../src/actions/insert/placeAction.ts"],"sourcesContent":["import { defineAction, type Action, type ImmediateParams, type ModifierState } from '@weasel-js/routing';\nimport { SNAP_ROLES, snapMods } from '@weasel-js/core/engine';\nimport { inPlane, insertLayer, insertParent, minSizeOf } from '@weasel-js/core';\nimport { restoreSelection } from './commit';\nimport { insertShape } from './shape';\nimport { clearedSelection } from './session';\nimport type {} from '@weasel-js/core';\nimport { INSERT_GROUP } from '../../actionGroups';\n\n/** What the dispatcher lays under an immediate action's params for a click. */\nconst CLICK_FIELDS = ['world', 'press', 'affordance', 'mods', 'roles'] as const;\n\nconst NO_KEYS: ModifierState = { alt: false, ctrl: false, meta: false, shift: false };\n\n/** The keys a click held, and the roles the dispatcher resolved them to (`ImmediateParams`). */\nfunction clickRoles(params: Readonly<Record<string, unknown>> | undefined) {\n const p = params as ImmediateParams | undefined;\n return { modifiers: p?.mods ?? NO_KEYS, ...(p?.roles ? { roles: p.roles } : {}) };\n}\n\n/**\n * Click-to-insert: the companion to `insertAction` for a click, which draws\n * no box. It commits a node of `params.kind` at `params.size`, centered on the\n * click, snapped through a `point` session of the `snap` dep unless the\n * click held `snap.suspend` (Ctrl), and commits\n * through the same `insert` dep a drag commits through. Its extras are the\n * ones a drag out from the click's center to the size's corner makes\n * (`insertShape`), built from the rest of the binding's params.\n *\n * A `minSize` in the params floors the size, and goes on to the node. Style\n * params (a shape tool's fill, stroke, …) reach the dep as `extras.style`.\n *\n * A binding with no `size` places nothing: the kind's extent is the tool's to\n * name, and a click has none of its own.\n */\nexport const placeAction: Action = inPlane(defineAction({\n id: 'place',\n label: 'Place',\n group: INSERT_GROUP,\n eligible: { capability: 'creates-shapes' },\n modifierRoles: SNAP_ROLES,\n requires: ['insert', 'insertInto', 'canDropInto', 'operands', 'snap', 'scene'],\n invoker: {\n timing: 'immediate',\n run(deps, params) {\n const dep = deps.insert;\n const asked = params?.size;\n const min = minSizeOf(params);\n const size = asked && min\n ? { width: Math.max(asked.width, min.width), height: Math.max(asked.height, min.height) }\n : asked;\n const world = params?.world;\n if (!dep || !size || !world) return;\n const { x, y } = world;\n if (!(size.width > 0 && size.height > 0)) return;\n\n const prior = deps.operands ? [...deps.operands.get()] : [];\n deps.operands?.set([]);\n let committed = false;\n try {\n const parent = insertParent(deps.scene, deps.insertInto?.get(), deps.canDropInto, { x, y });\n const snap = deps.snap?.begin({ gesture: 'point', press: { x, y }, ...(parent === null ? {} : { parent }) });\n let out;\n try {\n out = snap?.at({ x, y }, snapMods(clickRoles(params)));\n } finally {\n snap?.end();\n }\n const at = out ? out.point : { x, y };\n const binding: Record<string, unknown> = { ...params, originMode: 'center' };\n for (const k of [...CLICK_FIELDS, 'size']) delete binding[k];\n const landing = out?.landing;\n const { bounds, extras, ends } = insertShape(\n binding,\n { shaped: { start: at, current: { x: at.x + size.width / 2, y: at.y + size.height / 2 } }, altHeld: false },\n null, 0,\n (p) => (p === at ? landing : undefined),\n { x, y },\n );\n committed = dep.commit(bounds, extras, ends, clearedSelection(prior)) !== null;\n } finally {\n if (!committed) restoreSelection({ priorSelection: prior, selection: deps.operands });\n }\n },\n },\n /** Like `insert`, needs no selection. */\n enabled: () => true as const,\n}), insertLayer);\n"],"mappings":";;;;;;;;;;AAUA,IAAM,eAAe;CAAC;CAAS;CAAS;CAAc;CAAQ;AAAO;AAErE,IAAM,UAAyB;CAAE,KAAK;CAAO,MAAM;CAAO,MAAM;CAAO,OAAO;AAAM;;AAGpF,SAAS,WAAW,QAAuD;CACzE,MAAM,IAAI;CACV,OAAO;EAAE,WAAW,GAAG,QAAQ;EAAS,GAAI,GAAG,QAAQ,EAAE,OAAO,EAAE,MAAM,IAAI,CAAC;CAAG;AAClF;;;;;;;;;;;;;;;;AAiBA,IAAa,cAAsB,QAAQ,aAAa;CACtD,IAAI;CACJ,OAAO;CACP,OAAO;CACP,UAAU,EAAE,YAAY,iBAAiB;CACzC,eAAe;CACf,UAAU;EAAC;EAAU;EAAc;EAAe;EAAY;EAAQ;CAAO;CAC7E,SAAS;EACP,QAAQ;EACR,IAAI,MAAM,QAAQ;GAChB,MAAM,MAAM,KAAK;GACjB,MAAM,QAAQ,QAAQ;GACtB,MAAM,MAAM,UAAU,MAAM;GAC5B,MAAM,OAAO,SAAS,MAClB;IAAE,OAAO,KAAK,IAAI,MAAM,OAAO,IAAI,KAAK;IAAG,QAAQ,KAAK,IAAI,MAAM,QAAQ,IAAI,MAAM;GAAE,IACtF;GACJ,MAAM,QAAQ,QAAQ;GACtB,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,OAAO;GAC7B,MAAM,EAAE,GAAG,MAAM;GACjB,IAAI,EAAE,KAAK,QAAQ,KAAK,KAAK,SAAS,IAAI;GAE1C,MAAM,QAAQ,KAAK,WAAW,CAAC,GAAG,KAAK,SAAS,IAAI,CAAC,IAAI,CAAC;GAC1D,KAAK,UAAU,IAAI,CAAC,CAAC;GACrB,IAAI,YAAY;GAChB,IAAI;IACF,MAAM,SAAS,aAAa,KAAK,OAAO,KAAK,YAAY,IAAI,GAAG,KAAK,aAAa;KAAE;KAAG;IAAE,CAAC;IAC1F,MAAM,OAAO,KAAK,MAAM,MAAM;KAAE,SAAS;KAAS,OAAO;MAAE;MAAG;KAAE;KAAG,GAAI,WAAW,OAAO,CAAC,IAAI,EAAE,OAAO;IAAG,CAAC;IAC3G,IAAI;IACJ,IAAI;KACF,MAAM,MAAM,GAAG;MAAE;MAAG;KAAE,GAAG,SAAS,WAAW,MAAM,CAAC,CAAC;IACvD,UAAU;KACR,MAAM,IAAI;IACZ;IACA,MAAM,KAAK,MAAM,IAAI,QAAQ;KAAE;KAAG;IAAE;IACpC,MAAM,UAAmC;KAAE,GAAG;KAAQ,YAAY;IAAS;IAC3E,KAAK,MAAM,KAAK,CAAC,GAAG,cAAc,MAAM,GAAG,OAAO,QAAQ;IAC1D,MAAM,UAAU,KAAK;IACrB,MAAM,EAAE,QAAQ,QAAQ,SAAS,YAC/B,SACA;KAAE,QAAQ;MAAE,OAAO;MAAI,SAAS;OAAE,GAAG,GAAG,IAAI,KAAK,QAAQ;OAAG,GAAG,GAAG,IAAI,KAAK,SAAS;MAAE;KAAE;KAAG,SAAS;IAAM,GAC1G,MAAM,IACL,MAAO,MAAM,KAAK,UAAU,QAC7B;KAAE;KAAG;IAAE,CACT;IACA,YAAY,IAAI,OAAO,QAAQ,QAAQ,MAAM,iBAAiB,KAAK,CAAC,MAAM;GAC5E,UAAU;IACR,IAAI,CAAC,WAAW,iBAAiB;KAAE,gBAAgB;KAAO,WAAW,KAAK;IAAS,CAAC;GACtF;EACF;CACF;;CAEA,eAAe;AACjB,CAAC,GAAG,WAAW"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { INSERT_GROUP } from "../../actionGroups.js";
|
|
2
|
+
import { heldKeySpec } from "@weasel-js/routing";
|
|
3
|
+
|
|
4
|
+
// src/actions/insert/repositionAction.ts
|
|
5
|
+
/**
|
|
6
|
+
* Companion to `insertAction`: while its key is held, dragging moves the
|
|
7
|
+
* shape being drawn instead of resizing it; letting go resumes resizing from
|
|
8
|
+
* where the shape now sits. No-op when no insert is in flight.
|
|
9
|
+
*/
|
|
10
|
+
var insertRepositionAction = {
|
|
11
|
+
id: "insert.reposition",
|
|
12
|
+
label: "Insert — reposition",
|
|
13
|
+
group: INSERT_GROUP,
|
|
14
|
+
eligible: { capability: "creates-shapes" },
|
|
15
|
+
invoker: {
|
|
16
|
+
timing: "ongoing",
|
|
17
|
+
start: (ctx) => {
|
|
18
|
+
const gesture = ctx.deps.insertLive?.gesture;
|
|
19
|
+
if (!gesture || !gesture.open) return {};
|
|
20
|
+
gesture.repositioning = true;
|
|
21
|
+
return {
|
|
22
|
+
kind: "insert.reposition",
|
|
23
|
+
onEnd: () => {
|
|
24
|
+
gesture.repositioning = false;
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
requires: ["insertLive"]
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* The binding a shape-drawing tool adds so holding Space mid-draw repositions
|
|
33
|
+
* the shape. Gated to the tool's own engaged phase, so Space between drags is
|
|
34
|
+
* left to the offhand hand tool. Shift and Alt may be down with it, so a
|
|
35
|
+
* constrained or from-center draw can be moved without letting go of them.
|
|
36
|
+
*/
|
|
37
|
+
var INSERT_REPOSITION_BINDING = {
|
|
38
|
+
spec: {
|
|
39
|
+
...heldKeySpec(" "),
|
|
40
|
+
phase: "engaged"
|
|
41
|
+
},
|
|
42
|
+
actionId: "insert.reposition",
|
|
43
|
+
opts: { id: "insert.reposition.held" }
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export { INSERT_REPOSITION_BINDING, insertRepositionAction };
|
|
47
|
+
//# sourceMappingURL=repositionAction.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"repositionAction.js","names":[],"sources":["../../../src/actions/insert/repositionAction.ts"],"sourcesContent":["import { heldKeySpec, type Action, type GestureBinding } from '@weasel-js/routing';\nimport type { InsertLiveGesture } from './live';\nimport type {} from '@weasel-js/core';\nimport { INSERT_GROUP } from '../../actionGroups';\n\n/**\n * Companion to `insertAction`: while its key is held, dragging moves the\n * shape being drawn instead of resizing it; letting go resumes resizing from\n * where the shape now sits. No-op when no insert is in flight.\n */\nexport const insertRepositionAction: Action = {\n id: 'insert.reposition',\n label: 'Insert — reposition',\n group: INSERT_GROUP,\n eligible: { capability: 'creates-shapes' },\n invoker: {\n timing: 'ongoing',\n start: (ctx) => {\n const gesture = ctx.deps.insertLive?.gesture as InsertLiveGesture | null | undefined;\n if (!gesture || !gesture.open) return {};\n gesture.repositioning = true;\n return {\n kind: 'insert.reposition',\n onEnd: () => { gesture.repositioning = false; },\n };\n },\n },\n requires: ['insertLive'],\n};\n\n/**\n * The binding a shape-drawing tool adds so holding Space mid-draw repositions\n * the shape. Gated to the tool's own engaged phase, so Space between drags is\n * left to the offhand hand tool. Shift and Alt may be down with it, so a\n * constrained or from-center draw can be moved without letting go of them.\n */\nexport const INSERT_REPOSITION_BINDING: GestureBinding = {\n spec: { ...heldKeySpec(' '), phase: 'engaged' },\n actionId: 'insert.reposition',\n opts: { id: 'insert.reposition.held' },\n};\n"],"mappings":";;;;;;;;;AAUA,IAAa,yBAAiC;CAC5C,IAAI;CACJ,OAAO;CACP,OAAO;CACP,UAAU,EAAE,YAAY,iBAAiB;CACzC,SAAS;EACP,QAAQ;EACR,QAAQ,QAAQ;GACd,MAAM,UAAU,IAAI,KAAK,YAAY;GACrC,IAAI,CAAC,WAAW,CAAC,QAAQ,MAAM,OAAO,CAAC;GACvC,QAAQ,gBAAgB;GACxB,OAAO;IACL,MAAM;IACN,aAAa;KAAE,QAAQ,gBAAgB;IAAO;GAChD;EACF;CACF;CACA,UAAU,CAAC,YAAY;AACzB;;;;;;;AAQA,IAAa,4BAA4C;CACvD,MAAM;EAAE,GAAG,YAAY,GAAG;EAAG,OAAO;CAAU;CAC9C,UAAU;CACV,MAAM,EAAE,IAAI,yBAAyB;AACvC"}
|