@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,104 @@
|
|
|
1
|
+
import { holdInPlace } from "./held.js";
|
|
2
|
+
import { commitRunOps, reduceBehaviorEnd } from "@weasel-js/core";
|
|
3
|
+
import { defaultCommitAdapter as defaultCommitAdapter$1 } from "@weasel-js/core/engine";
|
|
4
|
+
import { rectToRect } from "@weasel-js/geom";
|
|
5
|
+
import * as coreOps from "@weasel-js/core/ops";
|
|
6
|
+
|
|
7
|
+
// src/actions/resize/commit.ts
|
|
8
|
+
/** The op mapping a leaf's data-held geometry by the box→box affine its pose
|
|
9
|
+
* underwent, and the pose to commit beside it. Null when the projection
|
|
10
|
+
* leaves this node's data alone. */
|
|
11
|
+
function projectedGeometry(projection, g, node, from, next, label) {
|
|
12
|
+
const sb = g.getBounds(from);
|
|
13
|
+
const db = g.getBounds(next);
|
|
14
|
+
const m = rectToRect(sb.x, sb.y, sb.width, sb.height, db.x, db.y, db.width, db.height);
|
|
15
|
+
const dataOp = coreOps.geometryData(projection, {
|
|
16
|
+
id: node.id,
|
|
17
|
+
data: node.data,
|
|
18
|
+
pose: from
|
|
19
|
+
}, m, next, label);
|
|
20
|
+
if (!dataOp) return null;
|
|
21
|
+
if (!(db.width < 0 || db.height < 0)) return {
|
|
22
|
+
dataOp,
|
|
23
|
+
pose: next
|
|
24
|
+
};
|
|
25
|
+
const nb = {
|
|
26
|
+
...db,
|
|
27
|
+
x: db.width < 0 ? db.x + db.width : db.x,
|
|
28
|
+
y: db.height < 0 ? db.y + db.height : db.y,
|
|
29
|
+
width: Math.abs(db.width),
|
|
30
|
+
height: Math.abs(db.height)
|
|
31
|
+
};
|
|
32
|
+
return {
|
|
33
|
+
dataOp,
|
|
34
|
+
pose: g.remapBounds(next, db, nb)
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
/** One transform op per write id, `from` the pose stored at press and `to`
|
|
38
|
+
* its preview, each preceded by its data op when the geometry projection
|
|
39
|
+
* answers for the node. A node a written frame holds is posed against the
|
|
40
|
+
* pose its frame commits, which the projection may have normalized. A node no
|
|
41
|
+
* longer in the scene is skipped, as the move's commit skips it. */
|
|
42
|
+
function resizeOps(leaves, previews, label) {
|
|
43
|
+
const written = [];
|
|
44
|
+
const renormalized = /* @__PURE__ */ new Map();
|
|
45
|
+
for (const id of leaves.writeIds) {
|
|
46
|
+
const next = previews.get(id);
|
|
47
|
+
if (next === void 0) continue;
|
|
48
|
+
const from = leaves.startPoses.get(id);
|
|
49
|
+
const node = leaves.scene.get(id);
|
|
50
|
+
if (from === void 0 || !node) continue;
|
|
51
|
+
let to = next;
|
|
52
|
+
if (leaves.geometryProjection) {
|
|
53
|
+
const projected = projectedGeometry(leaves.geometryProjection, leaves.geometryOf(id), {
|
|
54
|
+
id,
|
|
55
|
+
data: node.data
|
|
56
|
+
}, from, next, label);
|
|
57
|
+
if (projected) {
|
|
58
|
+
written.push(projected.dataOp);
|
|
59
|
+
to = projected.pose;
|
|
60
|
+
if (to !== next) renormalized.set(id, to);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
written.push(coreOps.setPose({
|
|
64
|
+
id,
|
|
65
|
+
from,
|
|
66
|
+
to,
|
|
67
|
+
label
|
|
68
|
+
}));
|
|
69
|
+
}
|
|
70
|
+
const held = leaves.held ?? /* @__PURE__ */ new Map();
|
|
71
|
+
const heldPoses = renormalized.size > 0 && leaves.poseFrame ? holdInPlace(new Map([...previews, ...renormalized]), held, leaves.poseFrame) : previews;
|
|
72
|
+
const ops = [];
|
|
73
|
+
for (const [id, h] of held) {
|
|
74
|
+
if (!leaves.scene.get(id)) continue;
|
|
75
|
+
const to = heldPoses.get(id);
|
|
76
|
+
if (to !== void 0) ops.push(coreOps.setPose({
|
|
77
|
+
id,
|
|
78
|
+
from: h.from,
|
|
79
|
+
to,
|
|
80
|
+
label
|
|
81
|
+
}));
|
|
82
|
+
}
|
|
83
|
+
return [...ops, ...written];
|
|
84
|
+
}
|
|
85
|
+
/** Commit the drag as one batch, so one undo entry. */
|
|
86
|
+
function commitResize(session, frame) {
|
|
87
|
+
const { lifecycle } = session;
|
|
88
|
+
const target = {
|
|
89
|
+
scene: session.scene,
|
|
90
|
+
applyOps: session.applyOps,
|
|
91
|
+
finish: session.finish,
|
|
92
|
+
adapter: defaultCommitAdapter$1(session.scene, session.selectionMethods)
|
|
93
|
+
};
|
|
94
|
+
const r = reduceBehaviorEnd(session.constraints, session.gestureCtx);
|
|
95
|
+
if (r === null) return "none";
|
|
96
|
+
if (r !== void 0) return commitRunOps(target, lifecycle, r) ? "constraint" : "none";
|
|
97
|
+
if (frame.previews.size === 0) return "none";
|
|
98
|
+
const ops = resizeOps(session, frame.previews, lifecycle.label);
|
|
99
|
+
if (ops.length === 0) return "none";
|
|
100
|
+
return commitRunOps(target, lifecycle, ops) ? "box" : "none";
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export { commitResize, resizeOps };
|
|
104
|
+
//# sourceMappingURL=commit.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commit.js","names":["defaultCommitAdapter"],"sources":["../../../src/actions/resize/commit.ts"],"sourcesContent":["import { rectToRect, type Affine } from '@weasel-js/geom';\nimport type { Op, NodeId } from '@weasel-js/core';\nimport { defaultCommitAdapter, type GeometryProjection } from '@weasel-js/core/engine';\nimport { commitRunOps, reduceBehaviorEnd } from '@weasel-js/core';\nimport type { PoseDescriptor } from '@weasel-js/core/engine';\nimport type { ResizeFrame, ResizeSession } from './session';\nimport { holdInPlace, type HeldNode } from './held';\nimport * as coreOps from '@weasel-js/core/ops';\n\n/** The op mapping a leaf's data-held geometry by the box→box affine its pose\n * underwent, and the pose to commit beside it. Null when the projection\n * leaves this node's data alone. */\nfunction projectedGeometry(\n projection: GeometryProjection,\n g: PoseDescriptor<unknown>,\n node: { id: string; data: unknown },\n from: unknown,\n next: unknown,\n label: string,\n): { dataOp: Op; pose: unknown } | null {\n const sb = g.getBounds(from);\n const db = g.getBounds(next);\n const m: Affine = rectToRect(\n sb.x, sb.y, sb.width, sb.height,\n db.x, db.y, db.width, db.height,\n );\n const dataOp = coreOps.geometryData(projection, { id: node.id, data: node.data, pose: from }, m, next, label);\n if (!dataOp) return null;\n // The data absorbed the affine — including any mirror from a\n // drag past the opposite edge — so the pose must commit as a\n // normalized AABB. Leaving signed extents on the pose makes\n // the node unhittable (hit-testing assumes normalized boxes).\n // Without the seam the signed pose is kept: a bare-AABB pose\n // is the only carrier of the flip there.\n if (!(db.width < 0 || db.height < 0)) return { dataOp, pose: next };\n const nb = {\n ...db,\n x: db.width < 0 ? db.x + db.width : db.x,\n y: db.height < 0 ? db.y + db.height : db.y,\n width: Math.abs(db.width),\n height: Math.abs(db.height),\n };\n return { dataOp, pose: g.remapBounds(next, db, nb) };\n}\n\n/** One transform op per write id, `from` the pose stored at press and `to`\n * its preview, each preceded by its data op when the geometry projection\n * answers for the node. A node a written frame holds is posed against the\n * pose its frame commits, which the projection may have normalized. A node no\n * longer in the scene is skipped, as the move's commit skips it. */\nexport function resizeOps(\n leaves: Pick<ResizeSession, 'scene' | 'writeIds' | 'startPoses' | 'geometryOf' | 'geometryProjection'> & Partial<Pick<ResizeSession, 'held' | 'poseFrame'>>,\n previews: ReadonlyMap<NodeId, unknown>,\n label: string,\n): Op[] {\n const written: Op[] = [];\n const renormalized = new Map<NodeId, unknown>();\n for (const id of leaves.writeIds) {\n const next = previews.get(id);\n if (next === undefined) continue;\n const from = leaves.startPoses.get(id);\n const node = leaves.scene.get(id);\n if (from === undefined || !node) continue;\n let to: unknown = next;\n if (leaves.geometryProjection) {\n const projected = projectedGeometry(\n leaves.geometryProjection, leaves.geometryOf(id), { id: id as string, data: node.data }, from, next, label,\n );\n if (projected) {\n written.push(projected.dataOp);\n to = projected.pose;\n if (to !== next) renormalized.set(id, to);\n }\n }\n written.push(coreOps.setPose<unknown>({ id: id as string, from, to, label }));\n }\n const held = leaves.held ?? new Map<NodeId, HeldNode>();\n const heldPoses = renormalized.size > 0 && leaves.poseFrame\n ? holdInPlace(new Map([...previews, ...renormalized]), held, leaves.poseFrame)\n : previews;\n const ops: Op[] = [];\n for (const [id, h] of held) {\n if (!leaves.scene.get(id)) continue;\n const to = heldPoses.get(id);\n if (to !== undefined) ops.push(coreOps.setPose<unknown>({ id: id as string, from: h.from, to, label }));\n }\n return [...ops, ...written];\n}\n\n/** What {@link commitResize} put in the document: nothing, the resized box,\n * or the ops a constraint's `onEnd` answered in its place. */\nexport type ResizeCommit = 'none' | 'box' | 'constraint';\n\n/** Commit the drag as one batch, so one undo entry. */\nexport function commitResize(session: ResizeSession, frame: ResizeFrame): ResizeCommit {\n const { lifecycle } = session;\n const target = {\n scene: session.scene,\n applyOps: session.applyOps,\n finish: session.finish,\n adapter: defaultCommitAdapter(session.scene, session.selectionMethods),\n };\n const r = reduceBehaviorEnd(session.constraints, session.gestureCtx);\n if (r === null) return 'none';\n if (r !== undefined) return commitRunOps(target, lifecycle, r) ? 'constraint' : 'none';\n\n if (frame.previews.size === 0) return 'none';\n const ops = resizeOps(session, frame.previews, lifecycle.label);\n if (ops.length === 0) return 'none';\n return commitRunOps(target, lifecycle, ops) ? 'box' : 'none';\n}\n"],"mappings":";;;;;;;;;;AAYA,SAAS,kBACP,YACA,GACA,MACA,MACA,MACA,OACsC;CACtC,MAAM,KAAK,EAAE,UAAU,IAAI;CAC3B,MAAM,KAAK,EAAE,UAAU,IAAI;CAC3B,MAAM,IAAY,WAChB,GAAG,GAAG,GAAG,GAAG,GAAG,OAAO,GAAG,QACzB,GAAG,GAAG,GAAG,GAAG,GAAG,OAAO,GAAG,MAC3B;CACA,MAAM,SAAS,QAAQ,aAAa,YAAY;EAAE,IAAI,KAAK;EAAI,MAAM,KAAK;EAAM,MAAM;CAAK,GAAG,GAAG,MAAM,KAAK;CAC5G,IAAI,CAAC,QAAQ,OAAO;CAOpB,IAAI,EAAE,GAAG,QAAQ,KAAK,GAAG,SAAS,IAAI,OAAO;EAAE;EAAQ,MAAM;CAAK;CAClE,MAAM,KAAK;EACT,GAAG;EACH,GAAG,GAAG,QAAQ,IAAI,GAAG,IAAI,GAAG,QAAQ,GAAG;EACvC,GAAG,GAAG,SAAS,IAAI,GAAG,IAAI,GAAG,SAAS,GAAG;EACzC,OAAO,KAAK,IAAI,GAAG,KAAK;EACxB,QAAQ,KAAK,IAAI,GAAG,MAAM;CAC5B;CACA,OAAO;EAAE;EAAQ,MAAM,EAAE,YAAY,MAAM,IAAI,EAAE;CAAE;AACrD;;;;;;AAOA,SAAgB,UACd,QACA,UACA,OACM;CACN,MAAM,UAAgB,CAAC;CACvB,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,QAAQ;EAChB,SAASA,uBAAqB,QAAQ,OAAO,QAAQ,gBAAgB;CACvE;CACA,MAAM,IAAI,kBAAkB,QAAQ,aAAa,QAAQ,UAAU;CACnE,IAAI,MAAM,MAAM,OAAO;CACvB,IAAI,MAAM,QAAW,OAAO,aAAa,QAAQ,WAAW,CAAC,IAAI,eAAe;CAEhF,IAAI,MAAM,SAAS,SAAS,GAAG,OAAO;CACtC,MAAM,MAAM,UAAU,SAAS,MAAM,UAAU,UAAU,KAAK;CAC9D,IAAI,IAAI,WAAW,GAAG,OAAO;CAC7B,OAAO,aAAa,QAAQ,WAAW,GAAG,IAAI,QAAQ;AACxD"}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { holdInPlace } from "./held.js";
|
|
2
|
+
import { boundsForRules } from "./ruleBounds.js";
|
|
3
|
+
import { boxFrame } from "./boxFrame.js";
|
|
4
|
+
import { clampToMinSize, clampToMinSizeKeepingAspect } from "./behaviors/clampMinSize.js";
|
|
5
|
+
import { edgeAspect, onDiagonal } from "./aspect.js";
|
|
6
|
+
import { carryPose, fixedCornerOf, insetBox, localToWorld, movedEdges, outsetBox, planeOf, pointerStateOf, quantizedPreview, remapRotatedLeaf, translatePoseViaDescriptor, worldDeltaToLocal } from "@weasel-js/core";
|
|
7
|
+
import { snapMods } from "@weasel-js/core/engine";
|
|
8
|
+
import { poseFrameOf } from "@weasel-js/geom";
|
|
9
|
+
|
|
10
|
+
// src/actions/resize/frame.ts
|
|
11
|
+
/** `ob` with the edges `anchor` leaves free moved by the drag delta, which is
|
|
12
|
+
* taken into the axes of the frame the box is drawn in first. A frame nothing
|
|
13
|
+
* maps back through moves no edge. */
|
|
14
|
+
function computeProposedBounds(ob, anchor, worldDx, worldDy, frame) {
|
|
15
|
+
const { x: dx, y: dy } = worldDeltaToLocal(frame, worldDx, worldDy) ?? {
|
|
16
|
+
x: 0,
|
|
17
|
+
y: 0
|
|
18
|
+
};
|
|
19
|
+
return movedEdges(ob, anchor, dx, dy);
|
|
20
|
+
}
|
|
21
|
+
/** `proposed` as the constraints rewrite it, each seeing the one before's. */
|
|
22
|
+
function constrain(constraints, gctx, anchor, proposed) {
|
|
23
|
+
let bounds = proposed;
|
|
24
|
+
for (const b of constraints) {
|
|
25
|
+
const r = b.onMove?.(gctx, {
|
|
26
|
+
pose: bounds,
|
|
27
|
+
anchor
|
|
28
|
+
});
|
|
29
|
+
if (!r) continue;
|
|
30
|
+
if (r.pose !== void 0) bounds = {
|
|
31
|
+
x: r.pose.x,
|
|
32
|
+
y: r.pose.y,
|
|
33
|
+
width: r.pose.width,
|
|
34
|
+
height: r.pose.height
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
return bounds;
|
|
38
|
+
}
|
|
39
|
+
/** One write id's world pose with the box taken from `src` to `dst`.
|
|
40
|
+
*
|
|
41
|
+
* A turned or skewed leaf resized with others needs its own frame: `src`/`dst`
|
|
42
|
+
* are world-frame there, unlike the lone path where the drag delta
|
|
43
|
+
* was already projected into the leaf's frame, so the naive affine
|
|
44
|
+
* scales the wrong pair of extents. See `remapRotatedLeaf`. */
|
|
45
|
+
function leafPose(g, start, src, dst, sharedBox) {
|
|
46
|
+
if (sharedBox && poseFrameOf(start) !== null) return remapRotatedLeaf(start, src, dst);
|
|
47
|
+
return g.remapBounds(start, src, dst);
|
|
48
|
+
}
|
|
49
|
+
/** `pose` shifted so the corner opposite the dragged one stays where the
|
|
50
|
+
* press found it, which resizing a box whose frame is about its center moves. */
|
|
51
|
+
function pinFixedCorner(g, pose, box, proposed) {
|
|
52
|
+
const frame = boxFrame(box, proposed);
|
|
53
|
+
if (frame.identity) return pose;
|
|
54
|
+
const newFixedLocal = fixedCornerOf(proposed, box.anchor);
|
|
55
|
+
const newFixedWorld = localToWorld(frame, newFixedLocal.x, newFixedLocal.y);
|
|
56
|
+
return translatePoseViaDescriptor(pose, box.fixedWorld.x - newFixedWorld.x, box.fixedWorld.y - newFixedWorld.y, g);
|
|
57
|
+
}
|
|
58
|
+
/** A world result for `id`, as stored: `null` in a singular frame, where the node is left as it is. */
|
|
59
|
+
function storedPose(place, id, world) {
|
|
60
|
+
const layer = place.scene.get(id)?.layer;
|
|
61
|
+
return place.poseFrame.local(id, carryPose(place.geometryOf(id), world, layer === void 0 ? null : planeOf(place.view, layer)));
|
|
62
|
+
}
|
|
63
|
+
/** Every write id's stored pose with the box taken from where the press found
|
|
64
|
+
* it to `asked`, held to the place's minimum, scaling every axis alike when
|
|
65
|
+
* `aspect` locks them together, and put on the scene's output grid holding
|
|
66
|
+
* the anchored side. Each node a written frame holds is re-expressed in its
|
|
67
|
+
* frame's pose, so it stays where it draws. A lone target is also pinned at
|
|
68
|
+
* the fixed corner, and comes back with its world pose. `proposed` is the box
|
|
69
|
+
* they were put in. The drag and the command path both resize through it. */
|
|
70
|
+
function posesInBox(place, asked, opts = {}) {
|
|
71
|
+
const boxed = rawPosesInBox(place, asked, opts);
|
|
72
|
+
const quantized = new Map([...boxed.previews].map(([id, pose]) => [id, quantizedPreview(place.scene, id, pose, place.box.anchor)]));
|
|
73
|
+
return {
|
|
74
|
+
...boxed,
|
|
75
|
+
previews: holdInPlace(quantized, place.held, place.poseFrame)
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
/** {@link posesInBox} before the output grid and the held contents. */
|
|
79
|
+
function rawPosesInBox(place, asked, opts) {
|
|
80
|
+
const { box } = place;
|
|
81
|
+
const clamp = opts.aspect ? clampToMinSizeKeepingAspect : clampToMinSize;
|
|
82
|
+
const proposed = (place.minimum && clamp(asked, box.anchor, place.minimum, box.bounds)) ?? asked;
|
|
83
|
+
const previews = /* @__PURE__ */ new Map();
|
|
84
|
+
const worldOf = (id) => {
|
|
85
|
+
const start = place.startWorlds.get(id);
|
|
86
|
+
if (start === void 0) return void 0;
|
|
87
|
+
return leafPose(place.geometryOf(id), start, box.bounds, proposed, place.sharedBox);
|
|
88
|
+
};
|
|
89
|
+
if (place.sharedBox) {
|
|
90
|
+
for (const id of place.writeIds) {
|
|
91
|
+
const next = worldOf(id);
|
|
92
|
+
if (next === void 0) continue;
|
|
93
|
+
const stored = storedPose(place, id, next);
|
|
94
|
+
if (stored !== null) previews.set(id, stored);
|
|
95
|
+
}
|
|
96
|
+
return {
|
|
97
|
+
previews,
|
|
98
|
+
proposed
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
const id = place.writeIds[0];
|
|
102
|
+
const g = place.geometryOf(id);
|
|
103
|
+
const remapped = worldOf(id);
|
|
104
|
+
if (remapped === void 0) return {
|
|
105
|
+
previews,
|
|
106
|
+
proposed
|
|
107
|
+
};
|
|
108
|
+
const world = pinFixedCorner(g, remapped, box, proposed);
|
|
109
|
+
const stored = storedPose(place, id, world);
|
|
110
|
+
if (stored === null) return {
|
|
111
|
+
previews,
|
|
112
|
+
proposed
|
|
113
|
+
};
|
|
114
|
+
previews.set(id, stored);
|
|
115
|
+
return {
|
|
116
|
+
previews,
|
|
117
|
+
proposed,
|
|
118
|
+
lone: {
|
|
119
|
+
id,
|
|
120
|
+
g,
|
|
121
|
+
world
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
/** The pointer put on the box's diagonal, for an aspect-locked corner: the
|
|
126
|
+
* session's input subspace then leaves it where it is, and a target still
|
|
127
|
+
* lands it where the diagonal meets the target. */
|
|
128
|
+
function aspectPointer(session, frame, drawn, raw) {
|
|
129
|
+
const { startWorld: o, box } = session;
|
|
130
|
+
const local = worldDeltaToLocal(frame, raw.x - o.x, raw.y - o.y);
|
|
131
|
+
const d = local && onDiagonal(local, drawn, box.anchor);
|
|
132
|
+
if (!d) return raw;
|
|
133
|
+
const zero = localToWorld(frame, 0, 0);
|
|
134
|
+
const w = localToWorld(frame, d.x, d.y);
|
|
135
|
+
return {
|
|
136
|
+
x: o.x + w.x - zero.x,
|
|
137
|
+
y: o.y + w.y - zero.y
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
/** One move's previews: the box as the snapped drag and the constraints
|
|
141
|
+
* leave it, and every write id's stored pose inside it. A lone target also
|
|
142
|
+
* gets the rotated-resize pin; a shared box, resized in the AABB frame, does
|
|
143
|
+
* not.
|
|
144
|
+
* `moveCtx` must carry a drag. */
|
|
145
|
+
function nextFrame(session, readers, moveCtx) {
|
|
146
|
+
const raw = moveCtx.drag.current;
|
|
147
|
+
const { box, gestureCtx: gctx } = session;
|
|
148
|
+
gctx.modifiers = { ...moveCtx.modifiers };
|
|
149
|
+
gctx.pointer = pointerStateOf(raw, moveCtx);
|
|
150
|
+
gctx.view = readers.view();
|
|
151
|
+
gctx.plane = readers.plane();
|
|
152
|
+
const mods = snapMods(moveCtx);
|
|
153
|
+
const frame = boxFrame(box, box.bounds);
|
|
154
|
+
const drawnStart = outsetBox(box.bounds, box.extents);
|
|
155
|
+
const pointer = mods.constrain ? aspectPointer(session, frame, drawnStart, raw) : raw;
|
|
156
|
+
const at = session.snap.at(pointer, mods).point;
|
|
157
|
+
const moved = computeProposedBounds(box.bounds, box.anchor, at.x - session.startWorld.x, at.y - session.startWorld.y, frame);
|
|
158
|
+
const drawn = outsetBox(moved, box.extents);
|
|
159
|
+
const shaped = mods.constrain ? edgeAspect(drawn, drawnStart, box.anchor) : drawn;
|
|
160
|
+
const { previews, proposed, lone } = posesInBox(session, insetBox(constrain(session.constraints, gctx, box.anchor, shaped), box.extents), { aspect: mods.constrain });
|
|
161
|
+
const key = gctx.draggedIds[0];
|
|
162
|
+
const ruled = lone ? boundsForRules(lone.g, lone.world) : proposed;
|
|
163
|
+
gctx.current = /* @__PURE__ */ new Map([[key, outsetBox(ruled, box.extents)]]);
|
|
164
|
+
return {
|
|
165
|
+
previews,
|
|
166
|
+
proposed
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export { nextFrame, posesInBox };
|
|
171
|
+
//# sourceMappingURL=frame.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"frame.js","names":[],"sources":["../../../src/actions/resize/frame.ts"],"sourcesContent":["import { poseFrameOf } from '@weasel-js/geom';\nimport { holdInPlace } from './held';\nimport type { InvocationCtx } from '@weasel-js/routing';\nimport { pointerStateOf, localToWorld, worldDeltaToLocal, type TargetTransform, carryPose, planeOf, fixedCornerOf, movedEdges, remapRotatedLeaf, translatePoseViaDescriptor, type PoseDescriptor, insetBox, outsetBox, quantizedPreview } from '@weasel-js/core';\nimport type { NodeId, Bounds, GestureReaders, BoundsConstraint, GestureContext, ResizeAnchor, RotatedPose } from '@weasel-js/core';\nimport { boundsForRules } from './ruleBounds';\nimport { boxFrame } from './boxFrame';\nimport type { ResizeBox, ResizeFrame, ResizeSession } from './session';\nimport { clampToMinSize, clampToMinSizeKeepingAspect } from './behaviors/clampMinSize';\nimport { edgeAspect, onDiagonal } from './aspect';\nimport { snapMods } from '@weasel-js/core/engine';\n\n/** `ob` with the edges `anchor` leaves free moved by the drag delta, which is\n * taken into the axes of the frame the box is drawn in first. A frame nothing\n * maps back through moves no edge. */\nfunction computeProposedBounds(\n ob: Bounds,\n anchor: ResizeAnchor,\n worldDx: number,\n worldDy: number,\n frame: TargetTransform,\n): Bounds {\n const { x: dx, y: dy } = worldDeltaToLocal(frame, worldDx, worldDy) ?? { x: 0, y: 0 };\n return movedEdges(ob, anchor, dx, dy);\n}\n\n/** `proposed` as the constraints rewrite it, each seeing the one before's. */\nfunction constrain(\n constraints: readonly BoundsConstraint<Bounds>[],\n gctx: GestureContext<Bounds>,\n anchor: ResizeAnchor,\n proposed: Bounds,\n): Bounds {\n let bounds = proposed;\n for (const b of constraints) {\n const r = b.onMove?.(gctx, { pose: bounds, anchor });\n if (!r) continue;\n if (r.pose !== undefined) {\n bounds = { x: r.pose.x, y: r.pose.y, width: r.pose.width, height: r.pose.height };\n }\n }\n return bounds;\n}\n\n/** One write id's world pose with the box taken from `src` to `dst`.\n *\n * A turned or skewed leaf resized with others needs its own frame: `src`/`dst`\n * are world-frame there, unlike the lone path where the drag delta\n * was already projected into the leaf's frame, so the naive affine\n * scales the wrong pair of extents. See `remapRotatedLeaf`. */\nfunction leafPose(\n g: PoseDescriptor<unknown>,\n start: unknown,\n src: Bounds,\n dst: Bounds,\n sharedBox: boolean,\n): unknown {\n if (sharedBox && poseFrameOf(start) !== null) {\n return remapRotatedLeaf(start as RotatedPose, src, dst);\n }\n return g.remapBounds(start, src, dst);\n}\n\n/** `pose` shifted so the corner opposite the dragged one stays where the\n * press found it, which resizing a box whose frame is about its center moves. */\nfunction pinFixedCorner(\n g: PoseDescriptor<unknown>,\n pose: unknown,\n box: Pick<ResizeBox, 'anchor' | 'rotation' | 'transform' | 'fixedWorld'>,\n proposed: Bounds,\n): unknown {\n const frame = boxFrame(box, proposed);\n if (frame.identity) return pose;\n const newFixedLocal = fixedCornerOf(proposed, box.anchor);\n const newFixedWorld = localToWorld(frame, newFixedLocal.x, newFixedLocal.y);\n return translatePoseViaDescriptor(\n pose,\n box.fixedWorld.x - newFixedWorld.x,\n box.fixedWorld.y - newFixedWorld.y,\n g,\n );\n}\n\n/** A world result for `id`, as stored: `null` in a singular frame, where the node is left as it is. */\nfunction storedPose(\n place: Pick<ResizeSession, 'scene' | 'poseFrame' | 'view' | 'geometryOf'>,\n id: NodeId,\n world: unknown,\n): unknown {\n const layer = place.scene.get(id)?.layer;\n return place.poseFrame.local(\n id,\n carryPose(place.geometryOf(id), world, layer === undefined ? null : planeOf(place.view, layer)),\n );\n}\n\n/** Every write id's stored pose with the box taken from where the press found\n * it to `asked`, held to the place's minimum, scaling every axis alike when\n * `aspect` locks them together, and put on the scene's output grid holding\n * the anchored side. Each node a written frame holds is re-expressed in its\n * frame's pose, so it stays where it draws. A lone target is also pinned at\n * the fixed corner, and comes back with its world pose. `proposed` is the box\n * they were put in. The drag and the command path both resize through it. */\nexport function posesInBox(\n place: Pick<ResizeSession, 'scene' | 'poseFrame' | 'view' | 'geometryOf' | 'writeIds' | 'startWorlds' | 'box' | 'sharedBox' | 'minimum' | 'held'>,\n asked: Bounds,\n opts: { aspect?: boolean } = {},\n): BoxedPoses {\n const boxed = rawPosesInBox(place, asked, opts);\n // The output grid is the invariant, so it shapes the poses after the snap and the constraints.\n const quantized = new Map([...boxed.previews].map(([id, pose]) => [id, quantizedPreview(place.scene, id, pose, place.box.anchor)]));\n return { ...boxed, previews: holdInPlace(quantized, place.held, place.poseFrame) };\n}\n\ntype BoxedPoses = { previews: Map<NodeId, unknown>; proposed: Bounds; lone?: { id: NodeId; g: PoseDescriptor<unknown>; world: unknown } };\n\n/** {@link posesInBox} before the output grid and the held contents. */\nfunction rawPosesInBox(\n place: Pick<ResizeSession, 'scene' | 'poseFrame' | 'view' | 'geometryOf' | 'writeIds' | 'startWorlds' | 'box' | 'sharedBox' | 'minimum'>,\n asked: Bounds,\n opts: { aspect?: boolean },\n): BoxedPoses {\n const { box } = place;\n const clamp = opts.aspect ? clampToMinSizeKeepingAspect : clampToMinSize;\n const proposed = (place.minimum && clamp(asked, box.anchor, place.minimum, box.bounds)) ?? asked;\n const previews = new Map<NodeId, unknown>();\n const worldOf = (id: NodeId): unknown => {\n const start = place.startWorlds.get(id);\n if (start === undefined) return undefined;\n return leafPose(place.geometryOf(id), start, box.bounds, proposed, place.sharedBox);\n };\n\n if (place.sharedBox) {\n for (const id of place.writeIds) {\n const next = worldOf(id);\n if (next === undefined) continue;\n const stored = storedPose(place, id, next);\n if (stored !== null) previews.set(id, stored);\n }\n return { previews, proposed };\n }\n\n const id = place.writeIds[0];\n const g = place.geometryOf(id);\n const remapped = worldOf(id);\n if (remapped === undefined) return { previews, proposed };\n const world = pinFixedCorner(g, remapped, box, proposed);\n const stored = storedPose(place, id, world);\n if (stored === null) return { previews, proposed };\n previews.set(id, stored);\n return { previews, proposed, lone: { id, g, world } };\n}\n\n/** The pointer put on the box's diagonal, for an aspect-locked corner: the\n * session's input subspace then leaves it where it is, and a target still\n * lands it where the diagonal meets the target. */\nfunction aspectPointer(session: ResizeSession, frame: TargetTransform, drawn: Bounds, raw: { x: number; y: number }): { x: number; y: number } {\n const { startWorld: o, box } = session;\n const local = worldDeltaToLocal(frame, raw.x - o.x, raw.y - o.y);\n const d = local && onDiagonal(local, drawn, box.anchor);\n if (!d) return raw;\n const zero = localToWorld(frame, 0, 0);\n const w = localToWorld(frame, d.x, d.y);\n return { x: o.x + w.x - zero.x, y: o.y + w.y - zero.y };\n}\n\n/** One move's previews: the box as the snapped drag and the constraints\n * leave it, and every write id's stored pose inside it. A lone target also\n * gets the rotated-resize pin; a shared box, resized in the AABB frame, does\n * not.\n * `moveCtx` must carry a drag. */\nexport function nextFrame(session: ResizeSession, readers: GestureReaders, moveCtx: InvocationCtx): ResizeFrame {\n const raw = moveCtx.drag!.current;\n const { box, gestureCtx: gctx } = session;\n gctx.modifiers = { ...moveCtx.modifiers };\n gctx.pointer = pointerStateOf(raw, moveCtx);\n gctx.view = readers.view();\n gctx.plane = readers.plane();\n\n const mods = snapMods(moveCtx);\n const frame = boxFrame(box, box.bounds);\n const drawnStart = outsetBox(box.bounds, box.extents);\n const pointer = mods.constrain ? aspectPointer(session, frame, drawnStart, raw) : raw;\n const snapped = session.snap.at(pointer, mods);\n const at = snapped.point;\n // The constraints see the box as drawn; the stroke keeps its width, so the\n // extents come back off what they leave.\n const moved = computeProposedBounds(box.bounds, box.anchor, at.x - session.startWorld.x, at.y - session.startWorld.y, frame);\n const drawn = outsetBox(moved, box.extents);\n const shaped = mods.constrain ? edgeAspect(drawn, drawnStart, box.anchor) : drawn;\n const constrained = insetBox(constrain(session.constraints, gctx, box.anchor, shaped), box.extents);\n\n const { previews, proposed, lone } = posesInBox(session, constrained, { aspect: mods.constrain });\n const key = gctx.draggedIds[0]!;\n const ruled = lone ? boundsForRules(lone.g, lone.world) : proposed;\n gctx.current = new Map<string, Bounds>([[key, outsetBox(ruled, box.extents)]]);\n return { previews, proposed };\n}\n"],"mappings":";;;;;;;;;;;;;AAeA,SAAS,sBACP,IACA,QACA,SACA,SACA,OACQ;CACR,MAAM,EAAE,GAAG,IAAI,GAAG,OAAO,kB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AAS,KAAK,YAAY,WAAW,OAAO,YAAY,IAAI,MAAM,IAAI;CAG5E,MAAM,EAAE,UAAU,UAAU,SAAS,WAAW,SAF5B,SAAS,UAAU,QAAQ,aAAa,MAAM,IAAI,QAAQ,MAAM,GAAG,IAAI,OAElC,GAAa,EAAE,QAAQ,KAAK,UAAU,CAAC;CAChG,MAAM,MAAM,KAAK,WAAW;CAC5B,MAAM,QAAQ,OAAO,eAAe,KAAK,GAAG,KAAK,KAAK,IAAI;CAC1D,KAAK,0BAAU,IAAI,IAAoB,CAAC,CAAC,KAAK,UAAU,OAAO,IAAI,OAAO,CAAC,CAAC,CAAC;CAC7E,OAAO;EAAE;EAAU;CAAS;AAC9B"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { definesFrame, heldInFrame } from "@weasel-js/core/engine";
|
|
2
|
+
|
|
3
|
+
// src/actions/resize/held.ts
|
|
4
|
+
/**
|
|
5
|
+
* What a resized frame holds: a resize changes the box, not where the
|
|
6
|
+
* contents draw, so each node stored in a written frame and not written
|
|
7
|
+
* itself is re-expressed in the frame's new pose.
|
|
8
|
+
*/
|
|
9
|
+
/** The nodes stored in a frame among `writeIds` that the resize does not write. */
|
|
10
|
+
function captureHeld(scene, writeIds, poseFrame) {
|
|
11
|
+
const held = /* @__PURE__ */ new Map();
|
|
12
|
+
if (poseFrame.pc.closure === "identity") return held;
|
|
13
|
+
const writing = new Set(writeIds);
|
|
14
|
+
for (const frame of writeIds) {
|
|
15
|
+
const node = scene.get(frame);
|
|
16
|
+
if (!node || !definesFrame(node)) continue;
|
|
17
|
+
for (const id of heldInFrame(scene, frame)) {
|
|
18
|
+
if (writing.has(id) || held.has(id)) continue;
|
|
19
|
+
held.set(id, {
|
|
20
|
+
frame,
|
|
21
|
+
world: poseFrame.world(id),
|
|
22
|
+
from: scene.get(id).pose
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return held;
|
|
27
|
+
}
|
|
28
|
+
/** `previews` with each held node posed in its frame's previewed pose, so it
|
|
29
|
+
* stays where it drew. One in a frame that is singular, where it drew flat and
|
|
30
|
+
* no stored pose keeps it, keeps its stored pose. */
|
|
31
|
+
function holdInPlace(previews, held, poseFrame) {
|
|
32
|
+
const { compose, decompose } = poseFrame.pc;
|
|
33
|
+
for (const [id, h] of held) {
|
|
34
|
+
const stored = previews.get(h.frame);
|
|
35
|
+
if (stored === void 0) continue;
|
|
36
|
+
const above = poseFrame.parentWorld(h.frame);
|
|
37
|
+
const local = decompose(poseFrame.childFrame(h.frame, above === null ? stored : compose(above, stored)), h.world);
|
|
38
|
+
if (local !== null) previews.set(id, local);
|
|
39
|
+
}
|
|
40
|
+
return previews;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export { captureHeld, holdInPlace };
|
|
44
|
+
//# sourceMappingURL=held.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"held.js","names":[],"sources":["../../../src/actions/resize/held.ts"],"sourcesContent":["/**\n * What a resized frame holds: a resize changes the box, not where the\n * contents draw, so each node stored in a written frame and not written\n * itself is re-expressed in the frame's new pose.\n */\nimport { heldInFrame, definesFrame } from '@weasel-js/core/engine';\nimport type { NodeId, Scene } from '@weasel-js/core';\nimport type { PoseFrame } from '@weasel-js/core/engine';\n\n/** A node held in place: the frame it is stored in, where it draws, and its\n * stored pose at press. */\nexport interface HeldNode {\n readonly frame: NodeId;\n readonly world: unknown;\n readonly from: unknown;\n}\n\n/** The nodes stored in a frame among `writeIds` that the resize does not write. */\nexport function captureHeld(\n scene: Scene<unknown, string, unknown>,\n writeIds: readonly NodeId[],\n poseFrame: PoseFrame<unknown>,\n): Map<NodeId, HeldNode> {\n const held = new Map<NodeId, HeldNode>();\n if (poseFrame.pc.closure === 'identity') return held;\n const writing = new Set(writeIds);\n for (const frame of writeIds) {\n const node = scene.get(frame);\n if (!node || !definesFrame(node)) continue;\n for (const id of heldInFrame(scene, frame)) {\n if (writing.has(id) || held.has(id)) continue;\n held.set(id, { frame, world: poseFrame.world(id), from: scene.get(id)!.pose });\n }\n }\n return held;\n}\n\n/** `previews` with each held node posed in its frame's previewed pose, so it\n * stays where it drew. One in a frame that is singular, where it drew flat and\n * no stored pose keeps it, keeps its stored pose. */\nexport function holdInPlace(\n previews: Map<NodeId, unknown>,\n held: ReadonlyMap<NodeId, HeldNode>,\n poseFrame: PoseFrame<unknown>,\n): Map<NodeId, unknown> {\n const { compose, decompose } = poseFrame.pc;\n for (const [id, h] of held) {\n const stored = previews.get(h.frame);\n if (stored === undefined) continue;\n const above = poseFrame.parentWorld(h.frame);\n const local = decompose(poseFrame.childFrame(h.frame, above === null ? stored : compose(above, stored)), h.world);\n if (local !== null) previews.set(id, local);\n }\n return previews;\n}\n"],"mappings":";;;;;;;;;AAkBA,SAAgB,YACd,OACA,UACA,WACuB;CACvB,MAAM,uBAAO,IAAI,IAAsB;CACvC,IAAI,UAAU,GAAG,YAAY,YAAY,OAAO;CAChD,MAAM,UAAU,IAAI,IAAI,QAAQ;CAChC,KAAK,MAAM,SAAS,UAAU;EAC5B,MAAM,OAAO,MAAM,IAAI,KAAK;EAC5B,IAAI,CAAC,QAAQ,CAAC,aAAa,IAAI,GAAG;EAClC,KAAK,MAAM,MAAM,YAAY,OAAO,KAAK,GAAG;GAC1C,IAAI,QAAQ,IAAI,EAAE,KAAK,KAAK,IAAI,EAAE,GAAG;GACrC,KAAK,IAAI,IAAI;IAAE;IAAO,OAAO,UAAU,MAAM,EAAE;IAAG,MAAM,MAAM,IAAI,EAAE,CAAC,CAAE;GAAK,CAAC;EAC/E;CACF;CACA,OAAO;AACT;;;;AAKA,SAAgB,YACd,UACA,MACA,WACsB;CACtB,MAAM,EAAE,SAAS,cAAc,UAAU;CACzC,KAAK,MAAM,CAAC,IAAI,MAAM,MAAM;EAC1B,MAAM,SAAS,SAAS,IAAI,EAAE,KAAK;EACnC,IAAI,WAAW,QAAW;EAC1B,MAAM,QAAQ,UAAU,YAAY,EAAE,KAAK;EAC3C,MAAM,QAAQ,UAAU,UAAU,WAAW,EAAE,OAAO,UAAU,OAAO,SAAS,QAAQ,OAAO,MAAM,CAAC,GAAG,EAAE,KAAK;EAChH,IAAI,UAAU,MAAM,SAAS,IAAI,IAAI,KAAK;CAC5C;CACA,OAAO;AACT"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { minSizeOf } from "@weasel-js/core";
|
|
2
|
+
import { poseFrameOf } from "@weasel-js/geom";
|
|
3
|
+
|
|
4
|
+
// src/actions/resize/minimum.ts
|
|
5
|
+
/**
|
|
6
|
+
* The smallest the resized box may go, from each written node's
|
|
7
|
+
* `data.minSize`: a lone target's own, or, for a box several share, the box
|
|
8
|
+
* at which the first of them reaches its own. A turned member is held on
|
|
9
|
+
* both axes by the larger of its two ratios, since the box's axes are not
|
|
10
|
+
* its own. `null` when nothing written has a minimum.
|
|
11
|
+
*/
|
|
12
|
+
function boxMinimum(scene, writeIds, leafBounds, startWorlds, box, sharedBox) {
|
|
13
|
+
if (!sharedBox) return minSizeOf(scene.get(writeIds[0])?.data);
|
|
14
|
+
let sx = 0;
|
|
15
|
+
let sy = 0;
|
|
16
|
+
writeIds.forEach((id, i) => {
|
|
17
|
+
const min = minSizeOf(scene.get(id)?.data);
|
|
18
|
+
const leaf = leafBounds[i];
|
|
19
|
+
if (!min || !leaf) return;
|
|
20
|
+
const rx = leaf.width !== 0 ? min.width / Math.abs(leaf.width) : 0;
|
|
21
|
+
const ry = leaf.height !== 0 ? min.height / Math.abs(leaf.height) : 0;
|
|
22
|
+
const turned = poseFrameOf(startWorlds.get(id)) !== null;
|
|
23
|
+
sx = Math.max(sx, turned ? Math.max(rx, ry) : rx);
|
|
24
|
+
sy = Math.max(sy, turned ? Math.max(rx, ry) : ry);
|
|
25
|
+
});
|
|
26
|
+
if (sx === 0 && sy === 0) return null;
|
|
27
|
+
return {
|
|
28
|
+
width: sx * box.width,
|
|
29
|
+
height: sy * box.height
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export { boxMinimum };
|
|
34
|
+
//# sourceMappingURL=minimum.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"minimum.js","names":[],"sources":["../../../src/actions/resize/minimum.ts"],"sourcesContent":["import { poseFrameOf } from '@weasel-js/geom';\nimport { minSizeOf, type MinSize } from '@weasel-js/core';\nimport type { NodeId, Scene, Bounds } from '@weasel-js/core';\n\n/**\n * The smallest the resized box may go, from each written node's\n * `data.minSize`: a lone target's own, or, for a box several share, the box\n * at which the first of them reaches its own. A turned member is held on\n * both axes by the larger of its two ratios, since the box's axes are not\n * its own. `null` when nothing written has a minimum.\n */\nexport function boxMinimum(\n scene: Scene<unknown, string, unknown>,\n writeIds: readonly NodeId[],\n leafBounds: readonly Bounds[],\n startWorlds: ReadonlyMap<NodeId, unknown>,\n box: Bounds,\n sharedBox: boolean,\n): MinSize | null {\n if (!sharedBox) return minSizeOf(scene.get(writeIds[0])?.data);\n let sx = 0;\n let sy = 0;\n writeIds.forEach((id, i) => {\n const min = minSizeOf(scene.get(id)?.data);\n const leaf = leafBounds[i];\n if (!min || !leaf) return;\n // A member stored flipped is held by its size, as a lone one is.\n const rx = leaf.width !== 0 ? min.width / Math.abs(leaf.width) : 0;\n const ry = leaf.height !== 0 ? min.height / Math.abs(leaf.height) : 0;\n const turned = poseFrameOf(startWorlds.get(id)) !== null;\n sx = Math.max(sx, turned ? Math.max(rx, ry) : rx);\n sy = Math.max(sy, turned ? Math.max(rx, ry) : ry);\n });\n if (sx === 0 && sy === 0) return null;\n return { width: sx * box.width, height: sy * box.height };\n}\n"],"mappings":";;;;;;;;;;;AAWA,SAAgB,WACd,OACA,UACA,YACA,aACA,KACA,WACgB;CAChB,IAAI,CAAC,WAAW,OAAO,UAAU,MAAM,IAAI,SAAS,EAAE,CAAC,EAAE,IAAI;CAC7D,IAAI,KAAK;CACT,IAAI,KAAK;CACT,SAAS,SAAS,IAAI,MAAM;EAC1B,MAAM,MAAM,UAAU,MAAM,IAAI,EAAE,CAAC,EAAE,IAAI;EACzC,MAAM,OAAO,WAAW;EACxB,IAAI,CAAC,OAAO,CAAC,MAAM;EAEnB,MAAM,KAAK,KAAK,UAAU,IAAI,IAAI,QAAQ,KAAK,IAAI,KAAK,KAAK,IAAI;EACjE,MAAM,KAAK,KAAK,WAAW,IAAI,IAAI,SAAS,KAAK,IAAI,KAAK,MAAM,IAAI;EACpE,MAAM,SAAS,YAAY,YAAY,IAAI,EAAE,CAAC,MAAM;EACpD,KAAK,KAAK,IAAI,IAAI,SAAS,KAAK,IAAI,IAAI,EAAE,IAAI,EAAE;EAChD,KAAK,KAAK,IAAI,IAAI,SAAS,KAAK,IAAI,IAAI,EAAE,IAAI,EAAE;CAClD,CAAC;CACD,IAAI,OAAO,KAAK,OAAO,GAAG,OAAO;CACjC,OAAO;EAAE,OAAO,KAAK,IAAI;EAAO,QAAQ,KAAK,IAAI;CAAO;AAC1D"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { resizeOps } from "./commit.js";
|
|
2
|
+
import { posesInBox } from "./frame.js";
|
|
3
|
+
import { captureResize } from "./session.js";
|
|
4
|
+
|
|
5
|
+
// src/actions/resize/replay.ts
|
|
6
|
+
/** `to`, given in units of `from` (`{ x: 0, y: 0, width: 1, height: 1 }` is
|
|
7
|
+
* `from` itself), in `from`'s own coordinates. */
|
|
8
|
+
function boxInUnits(from, to) {
|
|
9
|
+
return {
|
|
10
|
+
x: from.x + to.x * from.width,
|
|
11
|
+
y: from.y + to.y * from.height,
|
|
12
|
+
width: to.width * from.width,
|
|
13
|
+
height: to.height * from.height
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
/** `to` in units of `from`: the inverse of `boxInUnits`. A zero extent
|
|
17
|
+
* reads as unscaled on that axis. */
|
|
18
|
+
function unitsOfBox(from, to) {
|
|
19
|
+
const ux = from.width === 0 ? {
|
|
20
|
+
x: 0,
|
|
21
|
+
width: 1
|
|
22
|
+
} : {
|
|
23
|
+
x: (to.x - from.x) / from.width,
|
|
24
|
+
width: to.width / from.width
|
|
25
|
+
};
|
|
26
|
+
const uy = from.height === 0 ? {
|
|
27
|
+
y: 0,
|
|
28
|
+
height: 1
|
|
29
|
+
} : {
|
|
30
|
+
y: (to.y - from.y) / from.height,
|
|
31
|
+
height: to.height / from.height
|
|
32
|
+
};
|
|
33
|
+
return {
|
|
34
|
+
x: ux.x,
|
|
35
|
+
y: uy.y,
|
|
36
|
+
width: ux.width,
|
|
37
|
+
height: uy.height
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
/** The ops that resize `selected` the way a handle drag would, taking the box
|
|
41
|
+
* it would resize to `units` of itself. The resize policy's expansion
|
|
42
|
+
* applies, and so do the scene's output grid and a written frame's contents
|
|
43
|
+
* held where they draw; its constraints and point snaps, which shape a
|
|
44
|
+
* pointer, do not. */
|
|
45
|
+
function resizeSelectionOps(scene, selected, anchor, units, deps, label) {
|
|
46
|
+
if (selected.length === 0) return [];
|
|
47
|
+
const captured = captureResize(scene, selected, anchor, deps);
|
|
48
|
+
if (!captured) return [];
|
|
49
|
+
const { place } = captured;
|
|
50
|
+
const { previews } = posesInBox(place, boxInUnits(place.box.bounds, units));
|
|
51
|
+
return resizeOps({
|
|
52
|
+
...place,
|
|
53
|
+
geometryProjection: deps.geometryProjection
|
|
54
|
+
}, previews, label);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export { boxInUnits, resizeSelectionOps, unitsOfBox };
|
|
58
|
+
//# sourceMappingURL=replay.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"replay.js","names":[],"sources":["../../../src/actions/resize/replay.ts"],"sourcesContent":["import type { ActionDeps, ResizeAnchor } from '@weasel-js/routing';\nimport type { Op, NodeId, Scene, Bounds } from '@weasel-js/core';\nimport { resizeOps } from './commit';\nimport { posesInBox } from './frame';\nimport { captureResize } from './session';\n\n/** `to`, given in units of `from` (`{ x: 0, y: 0, width: 1, height: 1 }` is\n * `from` itself), in `from`'s own coordinates. */\nexport function boxInUnits(from: Bounds, to: Bounds): Bounds {\n return {\n x: from.x + to.x * from.width,\n y: from.y + to.y * from.height,\n width: to.width * from.width,\n height: to.height * from.height,\n };\n}\n\n/** `to` in units of `from`: the inverse of `boxInUnits`. A zero extent\n * reads as unscaled on that axis. */\nexport function unitsOfBox(from: Bounds, to: Bounds): Bounds {\n const ux = from.width === 0 ? { x: 0, width: 1 } : { x: (to.x - from.x) / from.width, width: to.width / from.width };\n const uy = from.height === 0 ? { y: 0, height: 1 } : { y: (to.y - from.y) / from.height, height: to.height / from.height };\n return { x: ux.x, y: uy.y, width: ux.width, height: uy.height };\n}\n\n/** The ops that resize `selected` the way a handle drag would, taking the box\n * it would resize to `units` of itself. The resize policy's expansion\n * applies, and so do the scene's output grid and a written frame's contents\n * held where they draw; its constraints and point snaps, which shape a\n * pointer, do not. */\nexport function resizeSelectionOps(\n scene: Scene<unknown, string, unknown>,\n selected: readonly string[],\n anchor: ResizeAnchor,\n units: Bounds,\n deps: Pick<ActionDeps, 'poseDescriptor' | 'resizePolicy' | 'view' | 'geometryProjection'>,\n label: string,\n): Op[] {\n if (selected.length === 0) return [];\n const captured = captureResize(scene, selected as NodeId[], anchor, deps);\n if (!captured) return [];\n const { place } = captured;\n const { previews } = posesInBox(place, boxInUnits(place.box.bounds, units));\n return resizeOps({ ...place, geometryProjection: deps.geometryProjection }, previews, label);\n}\n"],"mappings":";;;;;;;AAQA,SAAgB,WAAW,MAAc,IAAoB;CAC3D,OAAO;EACL,GAAG,KAAK,IAAI,GAAG,IAAI,KAAK;EACxB,GAAG,KAAK,IAAI,GAAG,IAAI,KAAK;EACxB,OAAO,GAAG,QAAQ,KAAK;EACvB,QAAQ,GAAG,SAAS,KAAK;CAC3B;AACF;;;AAIA,SAAgB,WAAW,MAAc,IAAoB;CAC3D,MAAM,KAAK,KAAK,UAAU,IAAI;EAAE,GAAG;EAAG,OAAO;CAAE,IAAI;EAAE,IAAI,GAAG,IAAI,KAAK,KAAK,KAAK;EAAO,OAAO,GAAG,QAAQ,KAAK;CAAM;CACnH,MAAM,KAAK,KAAK,WAAW,IAAI;EAAE,GAAG;EAAG,QAAQ;CAAE,IAAI;EAAE,IAAI,GAAG,IAAI,KAAK,KAAK,KAAK;EAAQ,QAAQ,GAAG,SAAS,KAAK;CAAO;CACzH,OAAO;EAAE,GAAG,GAAG;EAAG,GAAG,GAAG;EAAG,OAAO,GAAG;EAAO,QAAQ,GAAG;CAAO;AAChE;;;;;;AAOA,SAAgB,mBACd,OACA,UACA,QACA,OACA,MACA,OACM;CACN,IAAI,SAAS,WAAW,GAAG,OAAO,CAAC;CACnC,MAAM,WAAW,cAAc,OAAO,UAAsB,QAAQ,IAAI;CACxE,IAAI,CAAC,UAAU,OAAO,CAAC;CACvB,MAAM,EAAE,UAAU;CAClB,MAAM,EAAE,aAAa,WAAW,OAAO,WAAW,MAAM,IAAI,QAAQ,KAAK,CAAC;CAC1E,OAAO,UAAU;EAAE,GAAG;EAAO,oBAAoB,KAAK;CAAmB,GAAG,UAAU,KAAK;AAC7F"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { isRectPose } from "@weasel-js/core/engine";
|
|
2
|
+
|
|
3
|
+
// src/actions/resize/ruleBounds.ts
|
|
4
|
+
/** `pose` as the bounds a constraint or a point snap reads. A pose that is
|
|
5
|
+
* already a box goes through whole, so a `rotation` on it rides along. */
|
|
6
|
+
function boundsForRules(geometry, pose) {
|
|
7
|
+
return isRectPose(pose) ? pose : geometry.getBounds(pose);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export { boundsForRules };
|
|
11
|
+
//# sourceMappingURL=ruleBounds.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ruleBounds.js","names":[],"sources":["../../../src/actions/resize/ruleBounds.ts"],"sourcesContent":["import { isRectPose } from '@weasel-js/core/engine';\nimport type { Bounds } from '@weasel-js/core';\nimport type { PoseDescriptor } from '@weasel-js/core/engine';\n\n/** `pose` as the bounds a constraint or a point snap reads. A pose that is\n * already a box goes through whole, so a `rotation` on it rides along. */\nexport function boundsForRules(geometry: PoseDescriptor<unknown>, pose: unknown): Bounds {\n return isRectPose(pose) ? pose : geometry.getBounds(pose);\n}\n"],"mappings":";;;;;AAMA,SAAgB,eAAe,UAAmC,MAAuB;CACvF,OAAO,WAAW,IAAI,IAAI,OAAO,SAAS,UAAU,IAAI;AAC1D"}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { buildGestureContext, captureBox, captureStarts, captureTargets, resolvePolicy } from "./capture.js";
|
|
2
|
+
import { derivedBoxOwner } from "../derivedBox.js";
|
|
3
|
+
import { boxMinimum } from "./minimum.js";
|
|
4
|
+
import { boxFrame } from "./boxFrame.js";
|
|
5
|
+
import { captureHeld } from "./held.js";
|
|
6
|
+
import { gestureReaders, localToWorld, outsetBox, readRunLifecycle, transformFinisher } from "@weasel-js/core";
|
|
7
|
+
import { createBareSnapSession, drawnBoxes as drawnBoxes$1, nodeDescriptors as nodeDescriptors$1, operandMethods as operandMethods$1, poseDescriptorOf as poseDescriptorOf$1, scenePoseFrame as scenePoseFrame$1 } from "@weasel-js/core/engine";
|
|
8
|
+
|
|
9
|
+
// src/actions/resize/session.ts
|
|
10
|
+
/** Capture what resizing `ids` from `anchor` acts on. Null when nothing it
|
|
11
|
+
* would write exists, or something it would rewrite is locked. */
|
|
12
|
+
function captureResize(scene, ids, anchor, deps) {
|
|
13
|
+
const geometry = poseDescriptorOf$1(deps.poseDescriptor);
|
|
14
|
+
const policy = deps.resizePolicy;
|
|
15
|
+
const { constraints, expandIds } = resolvePolicy(policy);
|
|
16
|
+
const geometryOf = nodeDescriptors$1(scene, geometry);
|
|
17
|
+
const targets = captureTargets(scene, ids, expandIds);
|
|
18
|
+
if (!targets) return null;
|
|
19
|
+
const { writeIds, isGroupPath } = targets;
|
|
20
|
+
const poseFrame = scenePoseFrame$1(scene);
|
|
21
|
+
const view = deps.view;
|
|
22
|
+
const boxes = drawnBoxes$1({
|
|
23
|
+
...deps,
|
|
24
|
+
scene
|
|
25
|
+
}, poseFrame);
|
|
26
|
+
const starts = captureStarts(scene, writeIds, geometryOf, poseFrame, view, boxes);
|
|
27
|
+
if (starts.startPoses.size === 0) return null;
|
|
28
|
+
const written = writeIds.filter((id) => starts.startPoses.has(id));
|
|
29
|
+
const held = captureHeld(scene, written, poseFrame);
|
|
30
|
+
if ([...written, ...held.keys()].some((id) => scene.isLocked?.(id) === true)) return null;
|
|
31
|
+
const { box, ruleOrigin } = captureBox(boxStarts(scene, ids, isGroupPath, starts, (owner) => captureStarts(scene, [owner], geometryOf, poseFrame, view, boxes)), writeIds, isGroupPath, anchor, geometry, geometryOf);
|
|
32
|
+
const sharedBox = isGroupPath || writeIds.length > 1;
|
|
33
|
+
return {
|
|
34
|
+
place: {
|
|
35
|
+
scene,
|
|
36
|
+
writeIds,
|
|
37
|
+
sharedBox,
|
|
38
|
+
minimum: boxMinimum(scene, written, starts.leafBounds, starts.startWorlds, box.bounds, sharedBox),
|
|
39
|
+
box,
|
|
40
|
+
startPoses: starts.startPoses,
|
|
41
|
+
startWorlds: starts.startWorlds,
|
|
42
|
+
held,
|
|
43
|
+
geometryOf,
|
|
44
|
+
poseFrame,
|
|
45
|
+
view
|
|
46
|
+
},
|
|
47
|
+
ruleOrigin,
|
|
48
|
+
policy,
|
|
49
|
+
constraints
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
/** What the box is measured from: the derived node's own start when one stands for what is written
|
|
53
|
+
* (`derivedBoxOwner`) and has an area, else the written ids'. */
|
|
54
|
+
function boxStarts(scene, ids, isGroupPath, written, startsOf) {
|
|
55
|
+
const owner = isGroupPath ? derivedBoxOwner(scene, ids) : null;
|
|
56
|
+
if (owner === null) return written;
|
|
57
|
+
const own = startsOf(owner);
|
|
58
|
+
const b = own.leafBounds[0];
|
|
59
|
+
return b !== void 0 && b.width > 0 && b.height > 0 ? own : written;
|
|
60
|
+
}
|
|
61
|
+
/** The drag's snap session, over the box as drawn in its own frame. Neither the selection nor what the drag
|
|
62
|
+
* writes offers targets: those move with it. */
|
|
63
|
+
function beginSnap(ctx, ids, writeIds, press, box) {
|
|
64
|
+
const frame = boxFrame(box, box.bounds);
|
|
65
|
+
const req = {
|
|
66
|
+
gesture: "resize",
|
|
67
|
+
ids,
|
|
68
|
+
exclude: [.../* @__PURE__ */ new Set([...ids, ...writeIds])],
|
|
69
|
+
press,
|
|
70
|
+
handle: box.anchor,
|
|
71
|
+
constrain: "aspect",
|
|
72
|
+
box: {
|
|
73
|
+
bounds: outsetBox(box.bounds, box.extents),
|
|
74
|
+
toWorld: (p) => localToWorld(frame, p.x, p.y)
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
return ctx.deps.snap?.begin(req) ?? createBareSnapSession(req);
|
|
78
|
+
}
|
|
79
|
+
/** Capture a resize at press. Null when nothing is selected, the press is not
|
|
80
|
+
* on a resize handle, or nothing it would write exists. Runs each
|
|
81
|
+
* constraint's `onStart`. */
|
|
82
|
+
function beginResize(ctx) {
|
|
83
|
+
const selection = ctx.deps.operands;
|
|
84
|
+
const scene = ctx.deps.scene;
|
|
85
|
+
if (!selection || !scene) return null;
|
|
86
|
+
const ids = selection.get();
|
|
87
|
+
if (ids.length === 0) return null;
|
|
88
|
+
const anchor = ctx.drag?.affordance?.anchor;
|
|
89
|
+
if (!anchor) return null;
|
|
90
|
+
const captured = captureResize(scene, ids, anchor, ctx.deps);
|
|
91
|
+
if (!captured) return null;
|
|
92
|
+
const { place, ruleOrigin, policy, constraints } = captured;
|
|
93
|
+
const startWorld = {
|
|
94
|
+
x: ctx.drag?.start.x ?? 0,
|
|
95
|
+
y: ctx.drag?.start.y ?? 0
|
|
96
|
+
};
|
|
97
|
+
const readers = gestureReaders(ctx.deps);
|
|
98
|
+
const gestureCtx = buildGestureContext(ctx, scene, ids, ruleOrigin, startWorld, readers);
|
|
99
|
+
for (const b of constraints) b.onStart?.(gestureCtx);
|
|
100
|
+
return {
|
|
101
|
+
session: {
|
|
102
|
+
...place,
|
|
103
|
+
startWorld,
|
|
104
|
+
constraints,
|
|
105
|
+
gestureCtx,
|
|
106
|
+
applyOps: ctx.deps.applyOps,
|
|
107
|
+
finish: transformFinisher(ctx.deps),
|
|
108
|
+
geometryProjection: ctx.deps.geometryProjection,
|
|
109
|
+
selectionMethods: operandMethods$1(selection),
|
|
110
|
+
lifecycle: readRunLifecycle(policy, "Resize", constraints),
|
|
111
|
+
snap: beginSnap(ctx, ids, place.writeIds, startWorld, place.box)
|
|
112
|
+
},
|
|
113
|
+
readers
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export { beginResize, captureResize };
|
|
118
|
+
//# sourceMappingURL=session.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session.js","names":["poseDescriptorOf","nodeDescriptors","scenePoseFrame","drawnBoxes","operandMethods"],"sources":["../../../src/actions/resize/session.ts"],"sourcesContent":["import type { PoseLinear } from '@weasel-js/geom';\nimport { operandMethods, nodeDescriptors, poseDescriptorOf, scenePoseFrame, type PoseFrame, drawnBoxes, createBareSnapSession } from '@weasel-js/core/engine';\nimport type { CommitSelectionMethods, GeometryProjection, PoseDescriptor, InkExtents, SnapBegin, SnapSession } from '@weasel-js/core/engine';\nimport type { ActionDeps, InvocationCtx } from '@weasel-js/routing';\nimport { transformFinisher, type TransformFinisher, gestureReaders, type GestureReaders, readRunLifecycle, type RunLifecycle, localToWorld, outsetBox } from '@weasel-js/core';\nimport type { Op, NodeId, Scene, Bounds, BoundsConstraint, GestureContext, ResizeAnchor, MinSize } from '@weasel-js/core';\nimport { buildGestureContext, captureBox, captureStarts, captureTargets, resolvePolicy, type ResizeStarts } from './capture';\nimport { derivedBoxOwner } from '../derivedBox';\nimport { boxMinimum } from './minimum';\nimport { boxFrame } from './boxFrame';\nimport { captureHeld, type HeldNode } from './held';\n\n/** The box the drag resizes, as the press found it. */\nexport interface ResizeBox {\n /** The union for a group or a multi-selection, a lone target's own bounds\n * otherwise. The `src` rect every write id is remapped from. */\n readonly bounds: Bounds;\n readonly anchor: ResizeAnchor;\n /** A lone target's rotation; 0 for a group. */\n readonly rotation: number;\n /** A lone target's `transform`; none for a group. */\n readonly transform?: PoseLinear;\n /** World position of the corner opposite the dragged one, which a resize\n * in a turned or skewed frame pins. */\n readonly fixedWorld: { x: number; y: number };\n /** How far the ink reaches past `bounds` in its own frame. The handles sit\n * on `bounds` grown by it, and the constraints see that box; the stroke\n * does not scale, so the same extents come off whatever box they return. */\n readonly extents: InkExtents;\n}\n\n/** What a resize captured at press. Nothing here changes during the drag. */\nexport interface ResizeSession {\n readonly scene: Scene<unknown, string, unknown>;\n /** The ids the gesture writes: the leaf set for a group, else the selection. */\n readonly writeIds: readonly NodeId[];\n /** Whether `box` stands for several write ids, each remapped inside it,\n * rather than being a lone target's own. */\n readonly sharedBox: boolean;\n readonly box: ResizeBox;\n /** Start poses as stored: the `from` of each op. */\n readonly startPoses: ReadonlyMap<NodeId, unknown>;\n /** Start poses in world, the frame the anchor math and the drag share. */\n readonly startWorlds: ReadonlyMap<NodeId, unknown>;\n /** What the written frames hold that the resize leaves where it draws. */\n readonly held: ReadonlyMap<NodeId, HeldNode>;\n /** Where the pointer pressed. */\n readonly startWorld: { x: number; y: number };\n readonly geometryOf: (id: NodeId) => PoseDescriptor<unknown>;\n /** World reads and local writes over the scene's composition strategy. */\n readonly poseFrame: PoseFrame<unknown>;\n readonly view: unknown;\n /** The smallest `box` may be resized to, from the written nodes' own\n * minimums: a floor under every constraint. `null` for none. */\n readonly minimum: MinSize | null;\n readonly constraints: readonly BoundsConstraint<Bounds>[];\n /** Reused across the drag; constraints mutate its `scratch`. */\n readonly gestureCtx: GestureContext<Bounds>;\n readonly applyOps?: (ops: Op[], label: string) => void;\n /** Finishes the committed batch with the other nodes that change with it. */\n readonly finish?: TransformFinisher;\n /** When present, the commit maps each leaf's data-held geometry by the\n * affine its pose underwent. */\n readonly geometryProjection?: GeometryProjection;\n readonly selectionMethods: CommitSelectionMethods | undefined;\n /** Label, history, and callbacks from the `resizePolicy` dep. */\n readonly lifecycle: RunLifecycle;\n /** The drag's snapping: the `snap` dep's session, else one that only holds\n * the handle to its axis and Shift to the aspect. */\n readonly snap: SnapSession;\n}\n\n/** What one `onMove` produced. Replaced, not mutated, by the next. */\nexport interface ResizeFrame {\n /** Stored-frame pose of every write id the move reached. */\n readonly previews: Map<NodeId, unknown>;\n /** The box the move resized `ResizeBox.bounds` to; absent before the first move. */\n readonly proposed?: Bounds;\n}\n\n/** The part of a resize that a box alone decides: what it writes, the box\n * they share, and where each starts. */\nexport type ResizePlace = Pick<\n ResizeSession,\n 'scene' | 'writeIds' | 'sharedBox' | 'box' | 'startPoses' | 'startWorlds' | 'held' | 'geometryOf' | 'poseFrame' | 'view' | 'minimum'\n>;\n\n/** Capture what resizing `ids` from `anchor` acts on. Null when nothing it\n * would write exists, or something it would rewrite is locked. */\nexport function captureResize(\n scene: Scene<unknown, string, unknown>,\n ids: readonly NodeId[],\n anchor: ResizeAnchor,\n deps: Pick<ActionDeps, 'poseDescriptor' | 'resizePolicy' | 'view' | 'boundsIncludeStroke' | 'drawnBoxes'>,\n): {\n place: ResizePlace;\n ruleOrigin: Bounds;\n policy: ActionDeps['resizePolicy'];\n constraints: BoundsConstraint<Bounds>[];\n} | null {\n const geometry = poseDescriptorOf(deps.poseDescriptor);\n const policy = deps.resizePolicy;\n const { constraints, expandIds } = resolvePolicy(policy);\n const geometryOf = nodeDescriptors(scene, geometry);\n\n const targets = captureTargets(scene, ids, expandIds);\n if (!targets) return null;\n const { writeIds, isGroupPath } = targets;\n\n // The drag delta is world, so the anchor math runs on world poses — carried\n // into the plane the edit is measured in — and each result is carried back\n // to its node's plane and stored in the node's own parent frame.\n const poseFrame = scenePoseFrame(scene);\n const view = deps.view;\n const boxes = drawnBoxes({ ...deps, scene }, poseFrame);\n const starts = captureStarts(scene, writeIds, geometryOf, poseFrame, view, boxes);\n if (starts.startPoses.size === 0) return null;\n\n const written = writeIds.filter((id) => starts.startPoses.has(id));\n const held = captureHeld(scene, written, poseFrame);\n // A resize rewrites what it holds as well as what it writes: one that would rewrite a locked node does not\n // start (ruled 2026-11-09 for the commands, 2026-11-11 for the drag).\n if ([...written, ...held.keys()].some((id) => scene.isLocked?.(id) === true)) return null;\n const { box, ruleOrigin } = captureBox(boxStarts(scene, ids, isGroupPath, starts, (owner) =>\n captureStarts(scene, [owner], geometryOf, poseFrame, view, boxes)), writeIds, isGroupPath, anchor, geometry, geometryOf);\n const sharedBox = isGroupPath || writeIds.length > 1;\n return {\n place: {\n scene,\n writeIds,\n sharedBox,\n minimum: boxMinimum(scene, written, starts.leafBounds, starts.startWorlds, box.bounds, sharedBox),\n box,\n startPoses: starts.startPoses,\n startWorlds: starts.startWorlds,\n held,\n geometryOf,\n poseFrame,\n view,\n },\n ruleOrigin,\n policy,\n constraints,\n };\n}\n\n/** What the box is measured from: the derived node's own start when one stands for what is written\n * (`derivedBoxOwner`) and has an area, else the written ids'. */\nfunction boxStarts(\n scene: Scene<unknown, string, unknown>,\n ids: readonly NodeId[],\n isGroupPath: boolean,\n written: ResizeStarts,\n startsOf: (owner: NodeId) => ResizeStarts,\n): ResizeStarts {\n const owner = isGroupPath ? derivedBoxOwner(scene, ids) : null;\n if (owner === null) return written;\n const own = startsOf(owner);\n const b = own.leafBounds[0];\n return b !== undefined && b.width > 0 && b.height > 0 ? own : written;\n}\n\n/** The drag's snap session, over the box as drawn in its own frame. Neither the selection nor what the drag\n * writes offers targets: those move with it. */\nfunction beginSnap(\n ctx: InvocationCtx, ids: readonly NodeId[], writeIds: readonly NodeId[], press: { x: number; y: number }, box: ResizeBox,\n): SnapSession {\n const frame = boxFrame(box, box.bounds);\n const req: SnapBegin = {\n gesture: 'resize',\n ids,\n exclude: [...new Set<string>([...ids, ...writeIds])],\n press,\n handle: box.anchor,\n constrain: 'aspect',\n box: { bounds: outsetBox(box.bounds, box.extents), toWorld: (p) => localToWorld(frame, p.x, p.y) },\n };\n return ctx.deps.snap?.begin(req) ?? createBareSnapSession(req);\n}\n\n/** Capture a resize at press. Null when nothing is selected, the press is not\n * on a resize handle, or nothing it would write exists. Runs each\n * constraint's `onStart`. */\nexport function beginResize(\n ctx: InvocationCtx,\n): { session: ResizeSession; readers: GestureReaders } | null {\n const selection = ctx.deps.operands;\n const scene = ctx.deps.scene;\n if (!selection || !scene) return null;\n\n const ids = selection.get() as NodeId[];\n if (ids.length === 0) return null;\n\n const anchor = ctx.drag?.affordance?.anchor;\n if (!anchor) return null;\n\n const captured = captureResize(scene, ids, anchor, ctx.deps);\n if (!captured) return null;\n const { place, ruleOrigin, policy, constraints } = captured;\n const startWorld = { x: ctx.drag?.start.x ?? 0, y: ctx.drag?.start.y ?? 0 };\n const readers = gestureReaders(ctx.deps);\n const gestureCtx = buildGestureContext(ctx, scene, ids, ruleOrigin, startWorld, readers);\n for (const b of constraints) b.onStart?.(gestureCtx);\n\n const session: ResizeSession = {\n ...place,\n startWorld,\n constraints,\n gestureCtx,\n applyOps: ctx.deps.applyOps,\n finish: transformFinisher(ctx.deps),\n geometryProjection: ctx.deps.geometryProjection,\n selectionMethods: operandMethods(selection),\n lifecycle: readRunLifecycle(policy, 'Resize', constraints),\n snap: beginSnap(ctx, ids, place.writeIds, startWorld, place.box),\n };\n return { session, readers };\n}\n"],"mappings":";;;;;;;;;;;AAyFA,SAAgB,cACd,OACA,KACA,QACA,MAMO;CACP,MAAM,WAAWA,mBAAiB,KAAK,cAAc;CACrD,MAAM,SAAS,KAAK;CACpB,MAAM,EAAE,aAAa,cAAc,cAAc,MAAM;CACvD,MAAM,aAAaC,kBAAgB,OAAO,QAAQ;CAElD,MAAM,UAAU,eAAe,OAAO,KAAK,SAAS;CACpD,IAAI,CAAC,SAAS,OAAO;CACrB,MAAM,EAAE,UAAU,gBAAgB;CAKlC,MAAM,YAAYC,iBAAe,KAAK;CACtC,MAAM,OAAO,KAAK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