@weasel-js/core 1.10.0 → 1.10.1
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/CHANGELOG.md +168 -0
- package/README.md +33 -0
- package/dist/affordances/composeAffordanceLayer.js +21 -21
- package/dist/affordances/composeAffordanceLayer.js.map +1 -1
- package/dist/affordances/hitAffordanceRegions.js +48 -32
- package/dist/affordances/hitAffordanceRegions.js.map +1 -1
- package/dist/affordances/pathAnchors.js +50 -28
- package/dist/affordances/pathAnchors.js.map +1 -1
- package/dist/affordances/rotateCursor.js +12 -0
- package/dist/affordances/rotateCursor.js.map +1 -0
- package/dist/affordances/rotationHandle.js +40 -43
- package/dist/affordances/rotationHandle.js.map +1 -1
- package/dist/animation/rig/rigNode.js +9 -3
- package/dist/animation/rig/rigNode.js.map +1 -1
- package/dist/animation/rig/rigSeat.js +46 -13
- package/dist/animation/rig/rigSeat.js.map +1 -1
- package/dist/animation/rig/skinBinding.js +22 -14
- package/dist/animation/rig/skinBinding.js.map +1 -1
- package/dist/barrel/canvas.js +29 -28
- package/dist/barrel/interactions.js +33 -32
- package/dist/barrel/paths.js +11 -10
- package/dist/barrel/routing.js +49 -48
- package/dist/barrel/scene.js +10 -10
- package/dist/barrel/viewport.js +24 -21
- package/dist/canvas/Canvas.js +6 -17
- package/dist/canvas/Canvas.js.map +1 -1
- package/dist/canvas/CanvasView.js +34 -37
- package/dist/canvas/CanvasView.js.map +1 -1
- package/dist/canvas/CursorCoordsHud.js +3 -3
- package/dist/canvas/CursorCoordsHud.js.map +1 -1
- package/dist/canvas/DrawCanvas.js +3 -3
- package/dist/canvas/DrawCanvas.js.map +1 -1
- package/dist/canvas/SceneCanvas/PointerProviderIfRoot.js +24 -23
- package/dist/canvas/SceneCanvas/PointerProviderIfRoot.js.map +1 -1
- package/dist/canvas/SceneCanvas/StandardActionsRegistrar.js +40 -49
- package/dist/canvas/SceneCanvas/StandardActionsRegistrar.js.map +1 -1
- package/dist/canvas/SceneCanvas/defaultNodeProperties.js +297 -259
- package/dist/canvas/SceneCanvas/defaultNodeProperties.js.map +1 -1
- package/dist/canvas/SceneCanvas/features.js +3 -24
- package/dist/canvas/SceneCanvas/features.js.map +1 -1
- package/dist/canvas/SceneCanvas/insertPreviewCommands.js +97 -0
- package/dist/canvas/SceneCanvas/insertPreviewCommands.js.map +1 -0
- package/dist/canvas/SceneCanvas/poseGeometry.js.map +1 -1
- package/dist/canvas/SceneCanvas/props.js.map +1 -1
- package/dist/canvas/SceneCanvas/scenePointQuery.js +50 -0
- package/dist/canvas/SceneCanvas/scenePointQuery.js.map +1 -0
- package/dist/canvas/SceneCanvas/shapeGeneratorProperties.js +52 -0
- package/dist/canvas/SceneCanvas/shapeGeneratorProperties.js.map +1 -0
- package/dist/canvas/SceneCanvas/useActionTunings.js +17 -0
- package/dist/canvas/SceneCanvas/useActionTunings.js.map +1 -0
- package/dist/canvas/SceneCanvas/useCanvasCamera.js +37 -29
- package/dist/canvas/SceneCanvas/useCanvasCamera.js.map +1 -1
- package/dist/canvas/SceneCanvas/useCanvasDispatcher.js +11 -11
- package/dist/canvas/SceneCanvas/useCanvasDispatcher.js.map +1 -1
- package/dist/canvas/SceneCanvas/useDispatcherOverlayLayer.js +45 -109
- package/dist/canvas/SceneCanvas/useDispatcherOverlayLayer.js.map +1 -1
- package/dist/canvas/SceneCanvas/usePreviewGhostLayer.js +49 -41
- package/dist/canvas/SceneCanvas/usePreviewGhostLayer.js.map +1 -1
- package/dist/canvas/SceneCanvas/useSceneSelectTool.js +64 -96
- package/dist/canvas/SceneCanvas/useSceneSelectTool.js.map +1 -1
- package/dist/canvas/SceneCanvas/worldPointAt.js +3 -4
- package/dist/canvas/SceneCanvas/worldPointAt.js.map +1 -1
- package/dist/canvas/SceneCanvas.js +77 -80
- package/dist/canvas/SceneCanvas.js.map +1 -1
- package/dist/canvas/SceneViewCanvas.js +3 -3
- package/dist/canvas/SceneViewCanvas.js.map +1 -1
- package/dist/canvas/SurfaceCanvas.js +40 -0
- package/dist/canvas/SurfaceCanvas.js.map +1 -0
- package/dist/canvas/adapterDerivedPath.js +13 -13
- package/dist/canvas/adapterDerivedPath.js.map +1 -1
- package/dist/canvas/adapterPickSource.js +34 -0
- package/dist/canvas/adapterPickSource.js.map +1 -0
- package/dist/canvas/affordanceAt.js +1 -1
- package/dist/canvas/affordanceAt.js.map +1 -1
- package/dist/canvas/buildSceneLayer.js.map +1 -1
- package/dist/canvas/buildSceneTree.js +56 -34
- package/dist/canvas/buildSceneTree.js.map +1 -1
- package/dist/canvas/copiesAbove.js +27 -0
- package/dist/canvas/copiesAbove.js.map +1 -0
- package/dist/canvas/defaultDrawOne.js +24 -23
- package/dist/canvas/defaultDrawOne.js.map +1 -1
- package/dist/canvas/deps/editAnchors.js +45 -50
- package/dist/canvas/deps/editAnchors.js.map +1 -1
- package/dist/canvas/deps/hitTestArea.js +30 -15
- package/dist/canvas/deps/hitTestArea.js.map +1 -1
- package/dist/canvas/deps/insert.js +134 -100
- package/dist/canvas/deps/insert.js.map +1 -1
- package/dist/canvas/deps/layout.js +9 -15
- package/dist/canvas/deps/layout.js.map +1 -1
- package/dist/canvas/derivedPath.js +53 -29
- package/dist/canvas/derivedPath.js.map +1 -1
- package/dist/canvas/insertPreviewExtent.js +33 -31
- package/dist/canvas/insertPreviewExtent.js.map +1 -1
- package/dist/canvas/overChildren.js +29 -0
- package/dist/canvas/overChildren.js.map +1 -0
- package/dist/canvas/paintedCursorLayer.js.map +1 -1
- package/dist/canvas/pickReach.js +23 -0
- package/dist/canvas/pickReach.js.map +1 -0
- package/dist/canvas/pickWalk.js +51 -80
- package/dist/canvas/pickWalk.js.map +1 -1
- package/dist/canvas/sceneAdapter.js +14 -35
- package/dist/canvas/sceneAdapter.js.map +1 -1
- package/dist/canvas/sceneSlotWiring.js +11 -10
- package/dist/canvas/sceneSlotWiring.js.map +1 -1
- package/dist/canvas/sceneViewRender.js +38 -44
- package/dist/canvas/sceneViewRender.js.map +1 -1
- package/dist/canvas/useCanvasView.js +42 -44
- package/dist/canvas/useCanvasView.js.map +1 -1
- package/dist/canvas/useSceneAdapter.js +22 -0
- package/dist/canvas/useSceneAdapter.js.map +1 -0
- package/dist/canvas/useSurfaceInput.js +13 -16
- package/dist/canvas/useSurfaceInput.js.map +1 -1
- package/dist/canvas/viewRegistry.js +31 -23
- package/dist/canvas/viewRegistry.js.map +1 -1
- package/dist/canvas/wrapNodeOutput.js +7 -2
- package/dist/canvas/wrapNodeOutput.js.map +1 -1
- package/dist/clipboard.d.ts +1 -1
- package/dist/{clone-2a5hVbBd.d.ts → clone-C0eADtS0.d.ts} +13 -13
- package/dist/clone.d.ts +2 -2
- package/dist/core/geometry/poseDescriptor.js +49 -23
- package/dist/core/geometry/poseDescriptor.js.map +1 -1
- package/dist/core/geometry/regionHit.js +2 -2
- package/dist/core/geometry/regionHit.js.map +1 -1
- package/dist/core/geometry/targetFrame.js.map +1 -1
- package/dist/core/layers/children.js +1 -3
- package/dist/core/layers/children.js.map +1 -1
- package/dist/core/ops/create.js +2 -2
- package/dist/core/ops/create.js.map +1 -1
- package/dist/core/ops/delete.js +19 -23
- package/dist/core/ops/delete.js.map +1 -1
- package/dist/core/ops/reorder/index.js +3 -7
- package/dist/core/ops/reorder/index.js.map +1 -1
- package/dist/core/ops/reorder/setChildOrder.js +2 -4
- package/dist/core/ops/reorder/setChildOrder.js.map +1 -1
- package/dist/core/ops/reparent.js +0 -1
- package/dist/core/ops/reparent.js.map +1 -1
- package/dist/core/ops/slot.js +3 -6
- package/dist/core/ops/slot.js.map +1 -1
- package/dist/core/pages/fitViewToPage.js +15 -0
- package/dist/core/pages/fitViewToPage.js.map +1 -0
- package/dist/core/pages/pages.js +65 -0
- package/dist/core/pages/pages.js.map +1 -0
- package/dist/core/pages/pagesLayer.js +27 -0
- package/dist/core/pages/pagesLayer.js.map +1 -0
- package/dist/core/paint/meshKindLazy.js +2 -2
- package/dist/core/paint/meshKindLazy.js.map +1 -1
- package/dist/core/scene/NodeProperties.js.map +1 -1
- package/dist/core/scene/composeFrame.js.map +1 -1
- package/dist/core/scene/composePose.js +58 -20
- package/dist/core/scene/composePose.js.map +1 -1
- package/dist/core/scene/effectivePose.js +5 -1
- package/dist/core/scene/effectivePose.js.map +1 -1
- package/dist/core/scene/historyFacade.js +19 -13
- package/dist/core/scene/historyFacade.js.map +1 -1
- package/dist/core/scene/nodeFnFields.js +7 -0
- package/dist/core/scene/nodeFnFields.js.map +1 -1
- package/dist/core/scene/outerOps.js +2 -1
- package/dist/core/scene/outerOps.js.map +1 -1
- package/dist/core/scene/reconcileSpecs.js +1 -1
- package/dist/core/scene/reconcileSpecs.js.map +1 -1
- package/dist/core/scene/sceneRecording.js +2 -1
- package/dist/core/scene/sceneRecording.js.map +1 -1
- package/dist/core/scene/types.js.map +1 -1
- package/dist/core/viewport/screenSlop.js.map +1 -1
- package/dist/core/viewport/useDecayLoop.js +28 -30
- package/dist/core/viewport/useDecayLoop.js.map +1 -1
- package/dist/core/viewport/useNodeOverlayFrame.js.map +1 -1
- package/dist/core/viewport/useViewAnimation.js +70 -69
- package/dist/core/viewport/useViewAnimation.js.map +1 -1
- package/dist/core/viewport/view.js +8 -5
- package/dist/core/viewport/view.js.map +1 -1
- package/dist/core/viewport/zoomAt.js +11 -2
- package/dist/core/viewport/zoomAt.js.map +1 -1
- package/dist/{cornerHandles-BEshc4z3.d.ts → cornerHandles-BSKbyuvQ.d.ts} +1 -1
- package/dist/features/paths/editablePath.js +24 -8
- package/dist/features/paths/editablePath.js.map +1 -1
- package/dist/features/paths/index.js +4 -4
- package/dist/features/paths/shapeGenerator.js +89 -0
- package/dist/features/paths/shapeGenerator.js.map +1 -0
- package/dist/features/paths/usePathEdit.js +13 -13
- package/dist/features/poseRun/usePoseRun.js +25 -25
- package/dist/features/poseRun/usePoseRun.js.map +1 -1
- package/dist/features/text/useSceneTextEdit.js +82 -64
- package/dist/features/text/useSceneTextEdit.js.map +1 -1
- package/dist/features/viewports/viewResolver.js +28 -24
- package/dist/features/viewports/viewResolver.js.map +1 -1
- package/dist/icons/SliceIcon.js +24 -0
- package/dist/icons/SliceIcon.js.map +1 -0
- package/dist/index.d.ts +956 -581
- package/dist/index.js +260 -251
- package/dist/interactions/actions/align/align.js +9 -9
- package/dist/interactions/actions/align/align.js.map +1 -1
- package/dist/interactions/actions/booleans/booleans.js +18 -18
- package/dist/interactions/actions/booleans/booleans.js.map +1 -1
- package/dist/interactions/actions/booleans/operands.js.map +1 -1
- package/dist/interactions/actions/clone/action.js +35 -30
- package/dist/interactions/actions/clone/action.js.map +1 -1
- package/dist/interactions/actions/defaults/anchorEditing.js +56 -59
- package/dist/interactions/actions/defaults/anchorEditing.js.map +1 -1
- package/dist/interactions/actions/defaults/anchorHandles.js +42 -0
- package/dist/interactions/actions/defaults/anchorHandles.js.map +1 -0
- package/dist/interactions/actions/defaults/anchorJoin.js +92 -0
- package/dist/interactions/actions/defaults/anchorJoin.js.map +1 -0
- package/dist/interactions/actions/defaults/bendSegment.js +46 -0
- package/dist/interactions/actions/defaults/bendSegment.js.map +1 -0
- package/dist/interactions/actions/defaults/copySubtree.js +1 -1
- package/dist/interactions/actions/defaults/copySubtree.js.map +1 -1
- package/dist/interactions/actions/defaults/duplicate.js +32 -17
- package/dist/interactions/actions/defaults/duplicate.js.map +1 -1
- package/dist/interactions/actions/defaults/enterPathEdit.js +19 -7
- package/dist/interactions/actions/defaults/enterPathEdit.js.map +1 -1
- package/dist/interactions/actions/defaults/icons/anchorIcons.js +75 -0
- package/dist/interactions/actions/defaults/icons/anchorIcons.js.map +1 -0
- package/dist/interactions/actions/defaults/icons/editIcons.js +35 -8
- package/dist/interactions/actions/defaults/icons/editIcons.js.map +1 -1
- package/dist/interactions/actions/defaults/insertPathAnchor.js +16 -31
- package/dist/interactions/actions/defaults/insertPathAnchor.js.map +1 -1
- package/dist/interactions/actions/defaults/nudge.js +28 -23
- package/dist/interactions/actions/defaults/nudge.js.map +1 -1
- package/dist/interactions/actions/defaults/pinchZoom.js +29 -29
- package/dist/interactions/actions/defaults/pinchZoom.js.map +1 -1
- package/dist/interactions/actions/defaults/segmentUnder.js +22 -0
- package/dist/interactions/actions/defaults/segmentUnder.js.map +1 -0
- package/dist/interactions/actions/defaults/viewportZoom.js +82 -79
- package/dist/interactions/actions/defaults/viewportZoom.js.map +1 -1
- package/dist/interactions/actions/distribute/distribute.js +8 -8
- package/dist/interactions/actions/distribute/distribute.js.map +1 -1
- package/dist/interactions/actions/edit-anchors/action.js +58 -55
- package/dist/interactions/actions/edit-anchors/action.js.map +1 -1
- package/dist/interactions/actions/edit-anchors/preview.js +26 -0
- package/dist/interactions/actions/edit-anchors/preview.js.map +1 -0
- package/dist/interactions/actions/edit-anchors/symmetry.js +11 -0
- package/dist/interactions/actions/edit-anchors/symmetry.js.map +1 -0
- package/dist/interactions/actions/flip/action.js.map +1 -1
- package/dist/interactions/actions/geometryProjection.js.map +1 -1
- package/dist/interactions/actions/insert/action.js +37 -30
- package/dist/interactions/actions/insert/action.js.map +1 -1
- package/dist/interactions/actions/insert/frame.js +9 -2
- package/dist/interactions/actions/insert/frame.js.map +1 -1
- package/dist/interactions/actions/insert/repositionAction.js +31 -0
- package/dist/interactions/actions/insert/repositionAction.js.map +1 -0
- package/dist/interactions/actions/lasso-select/action.js +32 -32
- package/dist/interactions/actions/move/action.js +29 -25
- package/dist/interactions/actions/move/action.js.map +1 -1
- package/dist/interactions/actions/move/behaviors/snapToContainer.js +12 -6
- package/dist/interactions/actions/move/behaviors/snapToContainer.js.map +1 -1
- package/dist/interactions/actions/move/capture.js +32 -23
- package/dist/interactions/actions/move/capture.js.map +1 -1
- package/dist/interactions/actions/move/frame.js +2 -14
- package/dist/interactions/actions/move/frame.js.map +1 -1
- package/dist/interactions/actions/move/session.js +1 -1
- package/dist/interactions/actions/move/session.js.map +1 -1
- package/dist/interactions/actions/move/translate.js.map +1 -1
- package/dist/interactions/actions/outlines/createOutlines.js.map +1 -1
- package/dist/interactions/actions/outlines/replaceWithPaths.js +13 -13
- package/dist/interactions/actions/outlines/replaceWithPaths.js.map +1 -1
- package/dist/interactions/actions/outlines/strokeRegion.js.map +1 -1
- package/dist/interactions/actions/pathCommands/cutJoin.js +102 -0
- package/dist/interactions/actions/pathCommands/cutJoin.js.map +1 -0
- package/dist/interactions/actions/pathCommands/livePathEdit.js +64 -0
- package/dist/interactions/actions/pathCommands/livePathEdit.js.map +1 -0
- package/dist/interactions/actions/pathCommands/pathNodes.js +99 -0
- package/dist/interactions/actions/pathCommands/pathNodes.js.map +1 -0
- package/dist/interactions/actions/pathCommands/simplifyOffset.js +42 -0
- package/dist/interactions/actions/pathCommands/simplifyOffset.js.map +1 -0
- package/dist/interactions/actions/resize/action.js +31 -20
- package/dist/interactions/actions/resize/action.js.map +1 -1
- package/dist/interactions/actions/resize/commit.js.map +1 -1
- package/dist/interactions/actions/resize/frame.js +29 -15
- package/dist/interactions/actions/resize/frame.js.map +1 -1
- package/dist/interactions/actions/resize/replay.js +47 -0
- package/dist/interactions/actions/resize/replay.js.map +1 -0
- package/dist/interactions/actions/resize/session.js +49 -35
- package/dist/interactions/actions/resize/session.js.map +1 -1
- package/dist/interactions/actions/resolveOverlays.js +2 -1
- package/dist/interactions/actions/resolveOverlays.js.map +1 -1
- package/dist/interactions/actions/rotate/action.js +40 -25
- package/dist/interactions/actions/rotate/action.js.map +1 -1
- package/dist/interactions/actions/rotate/frame.js +1 -1
- package/dist/interactions/actions/rotate/frame.js.map +1 -1
- package/dist/interactions/actions/rotate/replay.js +22 -0
- package/dist/interactions/actions/rotate/replay.js.map +1 -0
- package/dist/interactions/actions/rotate/session.js +42 -32
- package/dist/interactions/actions/rotate/session.js.map +1 -1
- package/dist/interactions/actions/transform-again/action.js +63 -0
- package/dist/interactions/actions/transform-again/action.js.map +1 -0
- package/dist/interactions/actions/transform-again/memory.js +35 -0
- package/dist/interactions/actions/transform-again/memory.js.map +1 -0
- package/dist/interactions/actions/useStandardActions.js +101 -83
- package/dist/interactions/actions/useStandardActions.js.map +1 -1
- package/dist/move.d.ts +4 -4
- package/dist/{originProjection-PPT88jZv.d.ts → originProjection-CoNVpITV.d.ts} +1 -1
- package/dist/resize.d.ts +3 -3
- package/dist/style.css +1 -1
- package/dist/tools/builtin/ellipse/useEllipseTool.js +16 -15
- package/dist/tools/builtin/ellipse/useEllipseTool.js.map +1 -1
- package/dist/tools/builtin/line/useLineTool.js +16 -15
- package/dist/tools/builtin/line/useLineTool.js.map +1 -1
- package/dist/tools/builtin/pen/usePenTool.js +111 -111
- package/dist/tools/builtin/pen/usePenTool.js.map +1 -1
- package/dist/tools/builtin/pickTopMostHit.js +11 -14
- package/dist/tools/builtin/pickTopMostHit.js.map +1 -1
- package/dist/tools/builtin/polygon/usePolygonTool.js +17 -15
- package/dist/tools/builtin/polygon/usePolygonTool.js.map +1 -1
- package/dist/tools/builtin/rect/useRectTool.js +15 -14
- package/dist/tools/builtin/rect/useRectTool.js.map +1 -1
- package/dist/tools/builtin/select/adapterPointQuery.js +22 -18
- package/dist/tools/builtin/select/adapterPointQuery.js.map +1 -1
- package/dist/tools/builtin/select/selectionContributions.js +1 -1
- package/dist/tools/builtin/select/selectionContributions.js.map +1 -1
- package/dist/tools/builtin/select/useSelectTool.js +2 -1
- package/dist/tools/builtin/select/useSelectTool.js.map +1 -1
- package/dist/tools/builtin/slice/useSliceTool.js +42 -40
- package/dist/tools/builtin/slice/useSliceTool.js.map +1 -1
- package/dist/tools/builtin/star/useStarTool.js +18 -16
- package/dist/tools/builtin/star/useStarTool.js.map +1 -1
- package/dist/tools/builtin/text/useTextTool.js +2 -2
- package/dist/tools/builtin/text/useTextTool.js.map +1 -1
- package/dist/{types-CIKDwlsP.d.ts → types-DBbbCy0i.d.ts} +22 -15
- package/dist/version.js +1 -1
- package/package.json +22 -22
- package/dist/canvas/surface.module.js +0 -6
- package/dist/canvas/surface.module.js.map +0 -1
- package/dist/canvas/surfaceBox.js +0 -16
- package/dist/canvas/surfaceBox.js.map +0 -1
- package/dist/layout/arrivals.js +0 -33
- package/dist/layout/arrivals.js.map +0 -1
package/dist/clipboard.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { NodeId } from '@weasel-js/routing';
|
|
2
|
-
import { d as PasteOmission, j as ClipboardSnapshot, I as InsertAdapter } from './types-
|
|
2
|
+
import { d as PasteOmission, j as ClipboardSnapshot, I as InsertAdapter } from './types-DBbbCy0i.js';
|
|
3
3
|
import '@weasel-js/history';
|
|
4
4
|
import '@weasel-js/geom';
|
|
5
5
|
import './poseDescriptor-Bqk-11Rl.js';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as PlaneMap, S as SnapTarget, M as MoveAdapter } from './types-
|
|
1
|
+
import { a as PlaneMap, S as SnapTarget, M as MoveAdapter } from './types-DBbbCy0i.js';
|
|
2
2
|
import { Op } from '@weasel-js/history';
|
|
3
3
|
import { Bounds, ModifierState, View, ResizeAnchor } from '@weasel-js/routing';
|
|
4
4
|
|
|
@@ -66,6 +66,15 @@ interface GestureContext<TPose, TNode extends {
|
|
|
66
66
|
* the gesture's poses: an insert's points, a lasso's.
|
|
67
67
|
*/
|
|
68
68
|
frames?: GestureFrames<TPose>;
|
|
69
|
+
/**
|
|
70
|
+
* The translation that carries one pose's bounds onto another's, measured by
|
|
71
|
+
* the canvas's pose descriptor. Set by move; a behavior that knows where a
|
|
72
|
+
* node should land returns it as its `transform`.
|
|
73
|
+
*/
|
|
74
|
+
offset?: (from: TPose, to: TPose) => {
|
|
75
|
+
dx: number;
|
|
76
|
+
dy: number;
|
|
77
|
+
};
|
|
69
78
|
adapter: MoveAdapter<TNode, TPose>;
|
|
70
79
|
/**
|
|
71
80
|
* Per-gesture mutable store. Keys should be namespaced by behavior name to avoid
|
|
@@ -150,19 +159,12 @@ type GroupTransform = {
|
|
|
150
159
|
angle: number;
|
|
151
160
|
};
|
|
152
161
|
/**
|
|
153
|
-
* Per-frame result a `MoveBehavior.onMove` can return.
|
|
154
|
-
*
|
|
155
|
-
* `pose` is the legacy channel: a primary-id-only override, routed through
|
|
156
|
-
* a back-compat shim that derives a `translate` transform from the pose diff
|
|
157
|
-
* against `origin.get(primaryId)`. Prefer `transform`.
|
|
158
|
-
*
|
|
159
|
-
* `snap` announces a visual snap target.
|
|
162
|
+
* Per-frame result a `MoveBehavior.onMove` can return. `snap` announces a
|
|
163
|
+
* visual snap target.
|
|
160
164
|
*/
|
|
161
165
|
interface BehaviorResult<TPose> {
|
|
162
166
|
/** Replace the proposed transform. Applied uniformly to every id. */
|
|
163
167
|
transform?: GroupTransform;
|
|
164
|
-
/** @deprecated Return `transform` instead. Legacy primary-only pose override; supported via internal shim. */
|
|
165
|
-
pose?: TPose;
|
|
166
168
|
/** Preview poses for individual ids, each in its node's stored frame. For
|
|
167
169
|
* a dragged id the pose replaces the group transform this frame: a
|
|
168
170
|
* behavior that will commit its nodes where one translation cannot put
|
|
@@ -178,8 +180,6 @@ interface BehaviorResult<TPose> {
|
|
|
178
180
|
opaque?: Iterable<string>;
|
|
179
181
|
snap?: SnapTarget<TPose> | null;
|
|
180
182
|
}
|
|
181
|
-
/** @deprecated Renamed to `BehaviorResult`. Kept as an alias for one release cycle. */
|
|
182
|
-
type BehaviorMoveResult<TPose> = BehaviorResult<TPose>;
|
|
183
183
|
/** What a move behavior's `onEnd` is told. */
|
|
184
184
|
interface MoveEnd extends BehaviorEnd {
|
|
185
185
|
/** The action's default translate commit for the dragged roots in `ids`
|
|
@@ -379,4 +379,4 @@ type CloneBehaviorResult<TPose> = Pick<BehaviorResult<TPose>, 'transform' | 'sna
|
|
|
379
379
|
*/
|
|
380
380
|
type CloneBehavior<TPose> = ActionBehavior<TPose, GroupTransform, CloneBehaviorResult<TPose>>;
|
|
381
381
|
|
|
382
|
-
export type { ActionBehavior as A, BoundsConstraint as B, CloneBehavior as C, GestureContext as G, InsertBehavior as I, LassoSelectBehavior as L, MoveBehavior as M, PointSnapBehavior as P, RotateBehavior as R, SnapStrategy as S, AreaSelectOverlay as a, BehaviorEnd as b,
|
|
382
|
+
export type { ActionBehavior as A, BoundsConstraint as B, CloneBehavior as C, GestureContext as G, InsertBehavior as I, LassoSelectBehavior as L, MoveBehavior as M, PointSnapBehavior as P, RotateBehavior as R, SnapStrategy as S, AreaSelectOverlay as a, BehaviorEnd as b, BehaviorResult as c, CloneBehaviorResult as d, GestureFrames as e, GroupTransform as f, InsertMoveResult as g, InsertOverlay as h, InsertPoint as i, InsertProposed as j, LassoSelectMoveResult as k, LassoSelectOverlay as l, LassoSelectPose as m, LassoSelectProposed as n, MoveEnd as o, PointSnapContext as p, PointSnapFrame as q, PointSnapResult as r, PointerState as s, ResizeMoveResult as t, ResizeOverlay as u, ResizeProposed as v, RotateMoveResult as w, RotateOverlay as x, RotateProposed as y };
|
package/dist/clone.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { C as CloneBehavior,
|
|
2
|
-
import './types-
|
|
1
|
+
export { C as CloneBehavior, d as CloneBehaviorResult } from './clone-C0eADtS0.js';
|
|
2
|
+
import './types-DBbbCy0i.js';
|
|
3
3
|
import '@weasel-js/history';
|
|
4
4
|
import '@weasel-js/geom';
|
|
5
5
|
import '@weasel-js/routing';
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { axisAlignedBounds as e } from "./unionBounds.js";
|
|
2
|
-
import {
|
|
2
|
+
import { multiply as t, poseLinearOf as n, rotate as r } from "@weasel-js/geom";
|
|
3
3
|
//#region src/core/geometry/poseDescriptor.ts
|
|
4
|
-
function
|
|
4
|
+
function i(e, t) {
|
|
5
5
|
return e.forNode?.(t) ?? e;
|
|
6
6
|
}
|
|
7
|
-
var
|
|
7
|
+
var a = {
|
|
8
8
|
getBounds: (e) => e,
|
|
9
9
|
remapBounds: (e, t, n) => {
|
|
10
10
|
let r = t.width === 0 ? 1 : n.width / t.width, i = t.height === 0 ? 1 : n.height / t.height;
|
|
@@ -85,12 +85,12 @@ var r = {
|
|
|
85
85
|
...e,
|
|
86
86
|
rotation: t
|
|
87
87
|
})
|
|
88
|
-
},
|
|
89
|
-
getBounds:
|
|
90
|
-
remapBounds:
|
|
91
|
-
translate:
|
|
92
|
-
lerp:
|
|
93
|
-
axes:
|
|
88
|
+
}, o = {
|
|
89
|
+
getBounds: a.getBounds,
|
|
90
|
+
remapBounds: a.remapBounds,
|
|
91
|
+
translate: a.translate,
|
|
92
|
+
lerp: a.lerp,
|
|
93
|
+
axes: a.axes,
|
|
94
94
|
fromBounds: (e) => ({
|
|
95
95
|
x: e.x,
|
|
96
96
|
y: e.y,
|
|
@@ -104,29 +104,55 @@ var r = {
|
|
|
104
104
|
rotation: t
|
|
105
105
|
})
|
|
106
106
|
};
|
|
107
|
-
function
|
|
108
|
-
let
|
|
109
|
-
return {
|
|
107
|
+
function s(e, i, a) {
|
|
108
|
+
let o = i.width === 0 ? 1 : a.width / i.width, s = i.height === 0 ? 1 : a.height / i.height, c = e.rotation ?? 0, l = Math.cos(c), u = Math.sin(c), d = o * l, f = s * u, p = -o * u, m = s * l, h = Math.hypot(d, f), g = Math.hypot(p, m), _ = e.width * h, v = e.height * g, y = Math.atan2(f, d), b = a.x + (e.x + e.width / 2 - i.x) * o, x = a.y + (e.y + e.height / 2 - i.y) * s, S = {
|
|
110
109
|
...e,
|
|
111
|
-
x:
|
|
112
|
-
y:
|
|
113
|
-
width:
|
|
114
|
-
height:
|
|
115
|
-
rotation:
|
|
110
|
+
x: b - _ / 2,
|
|
111
|
+
y: x - v / 2,
|
|
112
|
+
width: _,
|
|
113
|
+
height: v,
|
|
114
|
+
rotation: y
|
|
116
115
|
};
|
|
116
|
+
if (h === 0 || g === 0) return S;
|
|
117
|
+
let [C, w, T, E] = n(e) ?? [
|
|
118
|
+
1,
|
|
119
|
+
0,
|
|
120
|
+
0,
|
|
121
|
+
1
|
|
122
|
+
], [D, O, k, A] = t(t(r(-y), [
|
|
123
|
+
d,
|
|
124
|
+
f,
|
|
125
|
+
p,
|
|
126
|
+
m,
|
|
127
|
+
0,
|
|
128
|
+
0
|
|
129
|
+
]), [
|
|
130
|
+
C / h,
|
|
131
|
+
w / h,
|
|
132
|
+
T / g,
|
|
133
|
+
E / g,
|
|
134
|
+
0,
|
|
135
|
+
0
|
|
136
|
+
]);
|
|
137
|
+
return Math.abs(D - 1) < 1e-12 && Math.abs(O) < 1e-12 && Math.abs(k) < 1e-12 && Math.abs(A - 1) < 1e-12 ? delete S.transform : S.transform = [
|
|
138
|
+
D,
|
|
139
|
+
O,
|
|
140
|
+
k,
|
|
141
|
+
A
|
|
142
|
+
], S;
|
|
117
143
|
}
|
|
118
|
-
function
|
|
119
|
-
return e(
|
|
144
|
+
function c(t, n) {
|
|
145
|
+
return e(l(t, n));
|
|
120
146
|
}
|
|
121
|
-
function
|
|
122
|
-
let r =
|
|
147
|
+
function l(e, t) {
|
|
148
|
+
let r = t.getBounds(e), i = t.getRotation?.(e) ?? r.rotation ?? 0, a = n(e) ?? n(r);
|
|
123
149
|
return !i && !a ? r : {
|
|
124
150
|
...r,
|
|
125
151
|
...i ? { rotation: i } : {},
|
|
126
152
|
...a ? { transform: a } : {}
|
|
127
153
|
};
|
|
128
154
|
}
|
|
129
|
-
function
|
|
155
|
+
function u(e, t, n, r) {
|
|
130
156
|
if (r.translate) return r.translate(e, t, n);
|
|
131
157
|
let i = r.getBounds(e), a = {
|
|
132
158
|
x: i.x + t,
|
|
@@ -137,6 +163,6 @@ function c(e, t, n, r) {
|
|
|
137
163
|
return r.remapBounds(e, i, a);
|
|
138
164
|
}
|
|
139
165
|
//#endregion
|
|
140
|
-
export {
|
|
166
|
+
export { a as RECT_POSE_DESCRIPTOR, o as ROTATED_POSE_DESCRIPTOR, l as framedBounds, i as poseDescriptorForNode, s as remapRotatedLeaf, u as translatePoseViaDescriptor, c as visualBoundsViaDescriptor };
|
|
141
167
|
|
|
142
168
|
//# sourceMappingURL=poseDescriptor.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"poseDescriptor.js","names":["poseDescriptorForNode","descriptor","node","RECT_POSE_DESCRIPTOR","p","sx","src","dst","sy","b","dx","dy","a","t","like","n","pose","d","rotation","at","ROTATED_POSE_DESCRIPTOR","remapRotatedLeaf","theta","cos","sin","ux","uy","vx","vy","width","height","cxNew","cyNew","visualBoundsViaDescriptor","axisAlignedBounds","framedBounds","geometry","transform","poseLinearOf","translatePoseViaDescriptor"],"sources":["../../../src/core/geometry/poseDescriptor.ts"],"sourcesContent":["import type { Bounds } from 'core/viewport/fitViewToBounds';\nimport { axisAlignedBounds } from 'core/geometry/unionBounds';\nimport { poseLinearOf } from '@weasel-js/geom';\nimport type { TargetAxes } from '@weasel-js/animator';\n\n/** `Bounds` with a required rotation angle (radians). Pivot is the AABB\n * center of the unrotated `{x, y, width, height}`. */\nexport interface RotatedPose extends Bounds {\n rotation: number;\n}\n\n/**\n * Bridges arbitrary `TPose` shapes into the kit's bounds-driven math: bounds\n * are read via `getBounds`, and `remapBounds` projects a result back into\n * TPose.\n *\n * `remapBounds(pose, src, dst)` subsumes both \"set my own AABB to dst\"\n * (single-leaf resize) and \"scale me as a leaf inside parent's src→dst rect\"\n * (group resize) — they're the same affine map.\n */\nexport interface PoseDescriptor<TPose, TNode = unknown> {\n getBounds(pose: TPose): Bounds;\n remapBounds(pose: TPose, src: Bounds, dst: Bounds): TPose;\n /** A pose occupying `bounds`, of the same kind as `template`. Unlike\n * `remapBounds`, the result carries none of the template's shape. */\n fromBounds(bounds: Bounds, template: TPose): TPose;\n /** Translate the pose by (dx, dy). Optional — when omitted, callers fall\n * back to a translation derived from `remapBounds` (origin shifted, no\n * scale). Path-shaped poses should provide this for performance. */\n translate?(pose: TPose, dx: number, dy: number): TPose;\n /** Interpolate between two poses. Optional — animation helpers fall back to\n * rect-shape lerp when omitted (which fails for non-rect poses). */\n lerp?(a: TPose, b: TPose, t: number): TPose;\n /** How a pose of `like`'s kind maps to the flat numbers an animation moves, and which of them\n * are angles. `from` keeps the fields of `like` that are not axes. Null for a pose this\n * descriptor cannot map; absent, a pose animates by its flat numeric fields. */\n axes?(like: TPose): TargetAxes<TPose> | null;\n /** Read the pose's rotation in radians. Pivot is the AABB center\n * (`getBounds(pose)` center). Default 0 when omitted. */\n getRotation?(pose: TPose): number;\n /** True iff this pose shape can carry a rotation; the rotation affordance\n * hides when it is `false`. When omitted, the kit assumes `true`, so a\n * descriptor whose poses cannot rotate (e.g. polygon Paths) should\n * return `false`. */\n supportsRotation?(pose: TPose): boolean;\n /** Write a rotation (radians) into the pose, bounds unchanged. Absent means\n * the pose cannot carry one, and the rotate action leaves it alone. */\n withRotation?(pose: TPose, rotation: number): TPose;\n /**\n * A descriptor specialized to one node. Every other method here sees only\n * the pose, so shapes sharing a pose type are indistinguishable to them.\n * Implement this to read `node.data` once and hand back a descriptor that\n * knows which shape it is describing. Callers reach it through\n * {@link poseDescriptorForNode}; sites with only an id keep using the\n * unspecialized descriptor.\n */\n forNode?(node: TNode): PoseDescriptor<TPose, TNode>;\n}\n\n/** The descriptor `node` should be read through: its own specialization when\n * it declares one, and otherwise the descriptor unchanged. */\nexport function poseDescriptorForNode<TPose, TNode>(\n descriptor: PoseDescriptor<TPose, TNode>,\n node: TNode,\n): PoseDescriptor<TPose, TNode> {\n return descriptor.forNode?.(node) ?? descriptor;\n}\n\n/** Identity geometry for `TPose extends Bounds`. Treats the pose as its\n * own bounds and remaps via affine scale against `src`/`dst`. */\nexport const RECT_POSE_DESCRIPTOR: PoseDescriptor<Bounds> = {\n getBounds: (p) => p,\n remapBounds: (p, src, dst) => {\n const sx = src.width === 0 ? 1 : dst.width / src.width;\n const sy = src.height === 0 ? 1 : dst.height / src.height;\n return {\n ...p,\n x: dst.x + (p.x - src.x) * sx,\n y: dst.y + (p.y - src.y) * sy,\n width: p.width * sx,\n height: p.height * sy,\n };\n },\n fromBounds: (b) => ({ x: b.x, y: b.y, width: b.width, height: b.height }),\n translate: (p, dx, dy) => ({ ...p, x: p.x + dx, y: p.y + dy }),\n lerp: (a, b, t) => ({\n ...a,\n x: a.x + (b.x - a.x) * t,\n y: a.y + (b.y - a.y) * t,\n width: a.width + (b.width - a.width) * t,\n height: a.height + (b.height - a.height) * t,\n }),\n axes: (like) => {\n const flat = [like.x, like.y, like.width, like.height];\n if (!flat.every((n) => typeof n === 'number')) return null;\n return {\n count: 5,\n names: ['x', 'y', 'width', 'height', 'rotation'],\n angles: [4],\n to: (p) => [p.x, p.y, p.width, p.height, p.rotation ?? 0],\n from: (a) => {\n const pose = { ...like, x: a[0]!, y: a[1]!, width: a[2]!, height: a[3]! };\n if (like.rotation !== undefined || a[4] !== 0) pose.rotation = a[4]!;\n return pose;\n },\n add: (p, d) => {\n const pose = { ...p, x: p.x + d[0]!, y: p.y + d[1]!, width: p.width + d[2]!, height: p.height + d[3]! };\n const rotation = (p.rotation ?? 0) + d[4]!;\n if (p.rotation !== undefined || rotation !== 0) pose.rotation = rotation;\n return pose;\n },\n write: (p, out, at) => {\n out[at] = p.x;\n out[at + 1] = p.y;\n out[at + 2] = p.width;\n out[at + 3] = p.height;\n out[at + 4] = p.rotation ?? 0;\n },\n };\n },\n // `withRotation` writes into `Bounds`' optional `rotation`, so this reads\n // the same channel, or a pose reports itself unrotated while painting rotated.\n getRotation: (p) => p.rotation ?? 0,\n withRotation: (p, rotation) => ({ ...p, rotation }),\n};\n\n/** Identity geometry for `RotatedPose`: `RECT_POSE_DESCRIPTOR`'s projection,\n * with a required `rotation`. */\nexport const ROTATED_POSE_DESCRIPTOR: PoseDescriptor<RotatedPose> = {\n getBounds: RECT_POSE_DESCRIPTOR.getBounds as PoseDescriptor<RotatedPose>['getBounds'],\n remapBounds: RECT_POSE_DESCRIPTOR.remapBounds as PoseDescriptor<RotatedPose>['remapBounds'],\n translate: RECT_POSE_DESCRIPTOR.translate as PoseDescriptor<RotatedPose>['translate'],\n lerp: RECT_POSE_DESCRIPTOR.lerp as PoseDescriptor<RotatedPose>['lerp'],\n axes: RECT_POSE_DESCRIPTOR.axes as PoseDescriptor<RotatedPose>['axes'],\n fromBounds: (b) => ({ x: b.x, y: b.y, width: b.width, height: b.height, rotation: 0 }),\n getRotation: (p) => p.rotation,\n withRotation: (p, rotation) => ({ ...p, rotation }),\n};\n\n/**\n * Remap a **rotated** leaf inside a group resize.\n *\n * The naive `remapBounds` scales a leaf's axis-aligned `width`/`height` by the\n * group's per-axis factors and carries `rotation` through untouched. That is\n * right when `src`/`dst` are expressed in the leaf's own frame. In a group\n * resize they are world-frame: at 90° a horizontal stretch should grow the\n * leaf's `height`, and the naive map grows its `width`.\n *\n * What this computes is the group affine applied to the leaf's local frame,\n * with the shear dropped — the pose model cannot represent the parallelogram\n * a non-uniform scale of a rotated box produces. The center moves exactly;\n * each local axis takes the length of its own image; the rotation follows the\n * image of the local x-axis.\n */\nexport function remapRotatedLeaf<TPose extends RotatedPose>(\n pose: TPose,\n src: Bounds,\n dst: Bounds,\n): TPose {\n const sx = src.width === 0 ? 1 : dst.width / src.width;\n const sy = src.height === 0 ? 1 : dst.height / src.height;\n const theta = pose.rotation ?? 0;\n const cos = Math.cos(theta);\n const sin = Math.sin(theta);\n\n // Images of the leaf's local unit axes under the group's diagonal scale.\n const ux = sx * cos, uy = sy * sin;\n const vx = -sx * sin, vy = sy * cos;\n\n const width = pose.width * Math.hypot(ux, uy);\n const height = pose.height * Math.hypot(vx, vy);\n const rotation = Math.atan2(uy, ux);\n\n // The center is a point, so it takes the group affine directly.\n const cxNew = dst.x + (pose.x + pose.width / 2 - src.x) * sx;\n const cyNew = dst.y + (pose.y + pose.height / 2 - src.y) * sy;\n\n return {\n ...pose,\n x: cxNew - width / 2,\n y: cyNew - height / 2,\n width,\n height,\n rotation,\n };\n}\n\n/** The pose's visual bounds: its box expanded to cover the box as drawn\n * under its rotation and `transform`, so a turned or skewed shape reports\n * the extent of its ink. */\nexport function visualBoundsViaDescriptor<TPose>(\n pose: TPose,\n geometry: PoseDescriptor<TPose>,\n): Bounds {\n return axisAlignedBounds(framedBounds(pose, geometry));\n}\n\n/** The pose's box with the rotation and `transform` it is drawn in: what\n * `poseFrameOf` reads, for a pose only its descriptor can read. */\nexport function framedBounds<TPose>(pose: TPose, geometry: PoseDescriptor<TPose>): Bounds {\n const b = geometry.getBounds(pose);\n const rotation = geometry.getRotation?.(pose) ?? b.rotation ?? 0;\n const transform = poseLinearOf(pose) ?? poseLinearOf(b);\n if (!rotation && !transform) return b;\n return { ...b, ...(rotation ? { rotation } : {}), ...(transform ? { transform } : {}) };\n}\n\n/** Translate through `geometry.translate`, or via `remapBounds` onto a shifted\n * copy of the pose's own bounds when the descriptor has none. */\nexport function translatePoseViaDescriptor<TPose>(\n pose: TPose,\n dx: number,\n dy: number,\n geometry: PoseDescriptor<TPose>,\n): TPose {\n if (geometry.translate) return geometry.translate(pose, dx, dy);\n const src = geometry.getBounds(pose);\n const dst = { x: src.x + dx, y: src.y + dy, width: src.width, height: src.height };\n return geometry.remapBounds(pose, src, dst);\n}\n"],"mappings":";;;AA6DA,SAAgBA,EACd,GACA,GAC8B;CAC9B,OAAOC,EAAW,UAAUC,CAAI,KAAKD;AACvC;AAIA,IAAaE,IAA+C;CAC1D,YAAY,MAAMC;CAClB,cAAc,GAAG,GAAK,MAAQ;EAC5B,IAAMC,IAAKC,EAAI,UAAU,IAAI,IAAIC,EAAI,QAAQD,EAAI,OAC3CE,IAAKF,EAAI,WAAW,IAAI,IAAIC,EAAI,SAASD,EAAI;EACnD,OAAO;GACL,GAAGF;GACH,GAAGG,EAAI,KAAKH,EAAE,IAAIE,EAAI,KAAKD;GAC3B,GAAGE,EAAI,KAAKH,EAAE,IAAIE,EAAI,KAAKE;GAC3B,OAAOJ,EAAE,QAAQC;GACjB,QAAQD,EAAE,SAASI;EACrB;CACF;CACA,aAAa,OAAO;EAAE,GAAGC,EAAE;EAAG,GAAGA,EAAE;EAAG,OAAOA,EAAE;EAAO,QAAQA,EAAE;CAAO;CACvE,YAAY,GAAG,GAAI,OAAQ;EAAE,GAAGL;EAAG,GAAGA,EAAE,IAAIM;EAAI,GAAGN,EAAE,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ACA;EACA;CACF;AACF;AAKA,SAAgBG,EACd,GACA,GACQ;CACR,OAAOC,EAAkBC,EAAanB,GAAMoB,CAAQ,CAAC;AACvD;AAIA,SAAgBD,EAAoB,GAAa,GAAyC;CACxF,IAAM1B,IAAI2B,EAAS,UAAUpB,CAAI,GAC3BE,IAAWkB,EAAS,cAAcpB,CAAI,KAAKP,EAAE,YAAY,GACzD4B,IAAYC,EAAatB,CAAI,KAAKsB,EAAa7B,CAAC;CAEtD,OADI,CAACS,KAAY,CAACmB,IAAkB5B,IAC7B;EAAE,GAAGA;EAAG,GAAIS,IAAW,EAAE,YAAS,IAAI,CAAC;EAAI,GAAImB,IAAY,EAAE,aAAU,IAAI,CAAC;CAAG;AACxF;AAIA,SAAgBE,EACd,GACA,GACA,GACA,GACO;CACP,IAAIH,EAAS,WAAW,OAAOA,EAAS,UAAUpB,GAAMN,GAAIC,CAAE;CAC9D,IAAML,IAAM8B,EAAS,UAAUpB,CAAI,GAC7BT,IAAM;EAAE,GAAGD,EAAI,IAAII;EAAI,GAAGJ,EAAI,IAAIK;EAAI,OAAOL,EAAI;EAAO,QAAQA,EAAI;CAAO;CACjF,OAAO8B,EAAS,YAAYpB,GAAMV,GAAKC,CAAG;AAC5C"}
|
|
1
|
+
{"version":3,"file":"poseDescriptor.js","names":["poseDescriptorForNode","descriptor","node","RECT_POSE_DESCRIPTOR","p","sx","src","dst","sy","b","dx","dy","a","t","like","n","pose","d","rotation","at","ROTATED_POSE_DESCRIPTOR","remapRotatedLeaf","theta","cos","sin","ux","uy","vx","vy","kx","ky","width","height","cxNew","cyNew","next","ta","tb","tc","td","poseLinearOf","c","multiply","rotate","visualBoundsViaDescriptor","axisAlignedBounds","framedBounds","geometry","transform","translatePoseViaDescriptor"],"sources":["../../../src/core/geometry/poseDescriptor.ts"],"sourcesContent":["import type { Bounds } from 'core/viewport/fitViewToBounds';\nimport { axisAlignedBounds } from 'core/geometry/unionBounds';\nimport { multiply, poseLinearOf, rotate } from '@weasel-js/geom';\nimport type { TargetAxes } from '@weasel-js/animator';\n\n/** `Bounds` with a required rotation angle (radians). Pivot is the AABB\n * center of the unrotated `{x, y, width, height}`. */\nexport interface RotatedPose extends Bounds {\n rotation: number;\n}\n\n/**\n * Bridges arbitrary `TPose` shapes into the kit's bounds-driven math: bounds\n * are read via `getBounds`, and `remapBounds` projects a result back into\n * TPose.\n *\n * `remapBounds(pose, src, dst)` subsumes both \"set my own AABB to dst\"\n * (single-leaf resize) and \"scale me as a leaf inside parent's src→dst rect\"\n * (group resize) — they're the same affine map.\n */\nexport interface PoseDescriptor<TPose, TNode = unknown> {\n getBounds(pose: TPose): Bounds;\n remapBounds(pose: TPose, src: Bounds, dst: Bounds): TPose;\n /** A pose occupying `bounds`, of the same kind as `template`. Unlike\n * `remapBounds`, the result carries none of the template's shape. */\n fromBounds(bounds: Bounds, template: TPose): TPose;\n /** Translate the pose by (dx, dy). Optional — when omitted, callers fall\n * back to a translation derived from `remapBounds` (origin shifted, no\n * scale). Path-shaped poses should provide this for performance. */\n translate?(pose: TPose, dx: number, dy: number): TPose;\n /** Interpolate between two poses. Optional — animation helpers fall back to\n * rect-shape lerp when omitted (which fails for non-rect poses). */\n lerp?(a: TPose, b: TPose, t: number): TPose;\n /** How a pose of `like`'s kind maps to the flat numbers an animation moves, and which of them\n * are angles. `from` keeps the fields of `like` that are not axes. Null for a pose this\n * descriptor cannot map; absent, a pose animates by its flat numeric fields. */\n axes?(like: TPose): TargetAxes<TPose> | null;\n /** Read the pose's rotation in radians. Pivot is the AABB center\n * (`getBounds(pose)` center). Default 0 when omitted. */\n getRotation?(pose: TPose): number;\n /** True iff this pose shape can carry a rotation; the rotation affordance\n * hides when it is `false`. When omitted, the kit assumes `true`, so a\n * descriptor whose poses cannot rotate (e.g. polygon Paths) should\n * return `false`. */\n supportsRotation?(pose: TPose): boolean;\n /** Write a rotation (radians) into the pose, bounds unchanged. Absent means\n * the pose cannot carry one, and the rotate action leaves it alone. */\n withRotation?(pose: TPose, rotation: number): TPose;\n /**\n * A descriptor specialized to one node. Every other method here sees only\n * the pose, so shapes sharing a pose type are indistinguishable to them.\n * Implement this to read `node.data` once and hand back a descriptor that\n * knows which shape it is describing. Callers reach it through\n * {@link poseDescriptorForNode}; sites with only an id keep using the\n * unspecialized descriptor.\n */\n forNode?(node: TNode): PoseDescriptor<TPose, TNode>;\n}\n\n/** The descriptor `node` should be read through: its own specialization when\n * it declares one, and otherwise the descriptor unchanged. */\nexport function poseDescriptorForNode<TPose, TNode>(\n descriptor: PoseDescriptor<TPose, TNode>,\n node: TNode,\n): PoseDescriptor<TPose, TNode> {\n return descriptor.forNode?.(node) ?? descriptor;\n}\n\n/** Identity geometry for `TPose extends Bounds`. Treats the pose as its\n * own bounds and remaps via affine scale against `src`/`dst`. */\nexport const RECT_POSE_DESCRIPTOR: PoseDescriptor<Bounds> = {\n getBounds: (p) => p,\n remapBounds: (p, src, dst) => {\n const sx = src.width === 0 ? 1 : dst.width / src.width;\n const sy = src.height === 0 ? 1 : dst.height / src.height;\n return {\n ...p,\n x: dst.x + (p.x - src.x) * sx,\n y: dst.y + (p.y - src.y) * sy,\n width: p.width * sx,\n height: p.height * sy,\n };\n },\n fromBounds: (b) => ({ x: b.x, y: b.y, width: b.width, height: b.height }),\n translate: (p, dx, dy) => ({ ...p, x: p.x + dx, y: p.y + dy }),\n lerp: (a, b, t) => ({\n ...a,\n x: a.x + (b.x - a.x) * t,\n y: a.y + (b.y - a.y) * t,\n width: a.width + (b.width - a.width) * t,\n height: a.height + (b.height - a.height) * t,\n }),\n axes: (like) => {\n const flat = [like.x, like.y, like.width, like.height];\n if (!flat.every((n) => typeof n === 'number')) return null;\n return {\n count: 5,\n names: ['x', 'y', 'width', 'height', 'rotation'],\n angles: [4],\n to: (p) => [p.x, p.y, p.width, p.height, p.rotation ?? 0],\n from: (a) => {\n const pose = { ...like, x: a[0]!, y: a[1]!, width: a[2]!, height: a[3]! };\n if (like.rotation !== undefined || a[4] !== 0) pose.rotation = a[4]!;\n return pose;\n },\n add: (p, d) => {\n const pose = { ...p, x: p.x + d[0]!, y: p.y + d[1]!, width: p.width + d[2]!, height: p.height + d[3]! };\n const rotation = (p.rotation ?? 0) + d[4]!;\n if (p.rotation !== undefined || rotation !== 0) pose.rotation = rotation;\n return pose;\n },\n write: (p, out, at) => {\n out[at] = p.x;\n out[at + 1] = p.y;\n out[at + 2] = p.width;\n out[at + 3] = p.height;\n out[at + 4] = p.rotation ?? 0;\n },\n };\n },\n // `withRotation` writes into `Bounds`' optional `rotation`, so this reads\n // the same channel, or a pose reports itself unrotated while painting rotated.\n getRotation: (p) => p.rotation ?? 0,\n withRotation: (p, rotation) => ({ ...p, rotation }),\n};\n\n/** Identity geometry for `RotatedPose`: `RECT_POSE_DESCRIPTOR`'s projection,\n * with a required `rotation`. */\nexport const ROTATED_POSE_DESCRIPTOR: PoseDescriptor<RotatedPose> = {\n getBounds: RECT_POSE_DESCRIPTOR.getBounds as PoseDescriptor<RotatedPose>['getBounds'],\n remapBounds: RECT_POSE_DESCRIPTOR.remapBounds as PoseDescriptor<RotatedPose>['remapBounds'],\n translate: RECT_POSE_DESCRIPTOR.translate as PoseDescriptor<RotatedPose>['translate'],\n lerp: RECT_POSE_DESCRIPTOR.lerp as PoseDescriptor<RotatedPose>['lerp'],\n axes: RECT_POSE_DESCRIPTOR.axes as PoseDescriptor<RotatedPose>['axes'],\n fromBounds: (b) => ({ x: b.x, y: b.y, width: b.width, height: b.height, rotation: 0 }),\n getRotation: (p) => p.rotation,\n withRotation: (p, rotation) => ({ ...p, rotation }),\n};\n\n/**\n * Remap a leaf drawn in a frame of its own, turned or skewed, inside a group\n * resize.\n *\n * The naive `remapBounds` scales a leaf's axis-aligned `width`/`height` by the\n * group's per-axis factors and carries `rotation` through untouched. That is\n * right when `src`/`dst` are expressed in the leaf's own frame. In a group\n * resize they are world-frame: at 90° a horizontal stretch should grow the\n * leaf's `height`, and the naive map grows its `width`.\n *\n * What this computes is the group affine applied to the leaf's frame. The\n * center moves exactly; each box axis takes the length of its own image under\n * the turn; the rotation follows the image of the box's x-axis; and the\n * parallelogram a non-uniform scale makes of a turned box, which those cannot\n * hold, is written to the leaf's `transform`.\n */\nexport function remapRotatedLeaf<TPose extends RotatedPose>(\n pose: TPose,\n src: Bounds,\n dst: Bounds,\n): TPose {\n const sx = src.width === 0 ? 1 : dst.width / src.width;\n const sy = src.height === 0 ? 1 : dst.height / src.height;\n const theta = pose.rotation ?? 0;\n const cos = Math.cos(theta);\n const sin = Math.sin(theta);\n\n // Images of the leaf's local unit axes under the group's diagonal scale.\n const ux = sx * cos, uy = sy * sin;\n const vx = -sx * sin, vy = sy * cos;\n const kx = Math.hypot(ux, uy);\n const ky = Math.hypot(vx, vy);\n\n const width = pose.width * kx;\n const height = pose.height * ky;\n const rotation = Math.atan2(uy, ux);\n\n // The center is a point, so it takes the group affine directly.\n const cxNew = dst.x + (pose.x + pose.width / 2 - src.x) * sx;\n const cyNew = dst.y + (pose.y + pose.height / 2 - src.y) * sy;\n\n const next: RotatedPose = { ...pose, x: cxNew - width / 2, y: cyNew - height / 2, width, height, rotation };\n // A collapsed axis leaves no frame to solve for; the leaf keeps the transform it had.\n if (kx === 0 || ky === 0) return next as TPose;\n const [ta, tb, tc, td] = poseLinearOf(pose) ?? [1, 0, 0, 1];\n // The linear part the leaf must draw with, less what the new box and rotation already hold.\n const [a, b, c, d] = multiply(\n multiply(rotate(-rotation), [ux, uy, vx, vy, 0, 0]),\n [ta / kx, tb / kx, tc / ky, td / ky, 0, 0],\n );\n if (Math.abs(a - 1) < 1e-12 && Math.abs(b) < 1e-12 && Math.abs(c) < 1e-12 && Math.abs(d - 1) < 1e-12) {\n delete next.transform;\n } else {\n next.transform = [a, b, c, d];\n }\n return next as TPose;\n}\n\n/** The pose's visual bounds: its box expanded to cover the box as drawn\n * under its rotation and `transform`, so a turned or skewed shape reports\n * the extent of its ink. */\nexport function visualBoundsViaDescriptor<TPose>(\n pose: TPose,\n geometry: PoseDescriptor<TPose>,\n): Bounds {\n return axisAlignedBounds(framedBounds(pose, geometry));\n}\n\n/** The pose's box with the rotation and `transform` it is drawn in: what\n * `poseFrameOf` reads, for a pose only its descriptor can read. */\nexport function framedBounds<TPose>(pose: TPose, geometry: PoseDescriptor<TPose>): Bounds {\n const b = geometry.getBounds(pose);\n const rotation = geometry.getRotation?.(pose) ?? b.rotation ?? 0;\n const transform = poseLinearOf(pose) ?? poseLinearOf(b);\n if (!rotation && !transform) return b;\n return { ...b, ...(rotation ? { rotation } : {}), ...(transform ? { transform } : {}) };\n}\n\n/** Translate through `geometry.translate`, or via `remapBounds` onto a shifted\n * copy of the pose's own bounds when the descriptor has none. */\nexport function translatePoseViaDescriptor<TPose>(\n pose: TPose,\n dx: number,\n dy: number,\n geometry: PoseDescriptor<TPose>,\n): TPose {\n if (geometry.translate) return geometry.translate(pose, dx, dy);\n const src = geometry.getBounds(pose);\n const dst = { x: src.x + dx, y: src.y + dy, width: src.width, height: src.height };\n return geometry.remapBounds(pose, src, dst);\n}\n"],"mappings":";;;AA6DA,SAAgBA,EACd,GACA,GAC8B;CAC9B,OAAOC,EAAW,UAAUC,CAAI,KAAKD;AACvC;AAIA,IAAaE,IAA+C;CAC1D,YAAY,MAAMC;CAClB,cAAc,GAAG,GAAK,MAAQ;EAC5B,IAAMC,IAAKC,EAAI,UAAU,IAAI,IAAIC,EAAI,QAAQD,EAAI,OAC3CE,IAAKF,EAAI,WAAW,IAAI,IAAIC,EAAI,SAASD,EAAI;EACnD,OAAO;GACL,GAAGF;GACH,GAAGG,EAAI,KAAKH,EAAE,IAAIE,EAAI,KAAKD;GAC3B,GAAGE,EAAI,KAAKH,EAAE,IAAIE,EAAI,KAAKE;GAC3B,OAAOJ,EAAE,QAAQC;GACjB,QAAQD,EAAE,SAASI;EACrB;CACF;CACA,aAAa,OAAO;EAAE,GAAGC,EAAE;EAAG,GAAGA,EAAE;EAAG,OAAOA,EAAE;EAAO,QAAQA,EAAE;CAAO;CACvE,YAAY,GAAG,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AS,WAAW,OAAOA,EAAS,UAAU/B,GAAMN,GAAIC,CAAE;CAC9D,IAAML,IAAMyC,EAAS,UAAU/B,CAAI,GAC7BT,IAAM;EAAE,GAAGD,EAAI,IAAII;EAAI,GAAGJ,EAAI,IAAIK;EAAI,OAAOL,EAAI;EAAO,QAAQA,EAAI;CAAO;CACjF,OAAOyC,EAAS,YAAY/B,GAAMV,GAAKC,CAAG;AAC5C"}
|
|
@@ -88,10 +88,10 @@ function m(e, t, r, s, c, l = () => !0) {
|
|
|
88
88
|
s.x + s.width,
|
|
89
89
|
s.y + s.height
|
|
90
90
|
]), p = d(r);
|
|
91
|
-
if (t === "enclosed") return f ? a(e.verts, p ? r : c())
|
|
91
|
+
if (t === "enclosed") return p && !f ? !1 : a(e.verts, p ? r : c());
|
|
92
92
|
if (e.isRect && f) return !0;
|
|
93
93
|
let m = p ? r : c();
|
|
94
|
-
return l() ? m.kind === "rect" && e.isRect ?
|
|
94
|
+
return l() ? m.kind === "rect" && e.isRect ? m.x < u.x + u.width && m.x + m.width > u.x && m.y < u.y + u.height && m.y + m.height > u.y : o(e.verts, m) : o(e.verts, m, { filled: !1 });
|
|
95
95
|
}
|
|
96
96
|
//#endregion
|
|
97
97
|
export { d as isSilhouettePose, u as polygonRegion, p as poseOutline, c as rectRegion, f as regionBoundsOf, l as regionOf, m as regionTakes };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"regionHit.js","names":["rectRegion","w","h","r","regionOf","x","y","verts","flat","minX","minY","maxX","maxY","i","coords","bounds","polygonRegion","polygon","p","isSilhouettePose","pose","regionBoundsOf","nodeMemo","node","g","visualBoundsViaDescriptor","poseOutline","poseFrameOf","pathThroughPoseFrame","b","regionTakes","ab","region","mode","pointInPolygon","inBox","boxContainsBox","silhouette","polygonContainsPath","outline","drawn","filled","polygonIntersectsPath"],"sources":["../../../src/core/geometry/regionHit.ts"],"sourcesContent":["/**\n * Whether a marquee or a lasso takes one node: the per-node decision the\n * scene's area walk (`canvas/deps/hitTestArea`) makes.\n *\n * What a node draws is not knowable here — the painters sit above `core/` — so\n * the caller hands in the node's outline as a thunk, asked for only when the\n * bounds cannot decide. A pose that is itself a polygon path is its own\n * outline and never asks.\n */\nimport {\n boxContainsBox,\n pointInPolygon,\n polygonContainsPath,\n polygonIntersectsPath,\n type Path,\n type PolygonPath,\n} from '@weasel-js/geom';\nimport type { Bounds } from 'core/viewport/fitViewToBounds';\nimport type { LassoHitMode } from 'core/adapters/types';\nimport { nodeMemo } from 'core/scene/nodeMemo';\nimport type { Vec2 } from './vec2';\nimport { pathThroughPoseFrame, poseFrameOf } from '@weasel-js/geom';\nimport { visualBoundsViaDescriptor, type PoseDescriptor } from './poseDescriptor';\n\n/** A closed selection area: a marquee rect or a lasso polygon. */\nexport interface SelectRegion {\n /** The area's vertices; the closing edge back to the first is implicit. */\n readonly verts: readonly Vec2[];\n /** `verts` interleaved as `[x0, y0, x1, y1, …]`. */\n readonly coords: readonly number[];\n readonly bounds: Bounds;\n /** True when the area is its own bounding rect, so a node inside `bounds`\n * is inside the area without further work. Never true for a lasso: a node\n * inside the hull's box can still miss the hull. */\n readonly isRect: boolean;\n}\n\n/** A marquee's region. */\nexport function rectRegion(r: Bounds): SelectRegion {\n const { x, y, width: w, height: h } = r;\n return regionOf([x, y, x + w, y, x + w, y + h, x, y + h], { x, y, width: w, height: h }, true)!;\n}\n\n/** A region from interleaved coords. `bounds` is derived when omitted; `null`\n * when there are no coords to bound. */\nexport function regionOf(\n coords: ArrayLike<number>,\n bounds?: Bounds,\n isRect = false,\n): SelectRegion | null {\n const verts: Vec2[] = [];\n const flat: number[] = [];\n let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;\n for (let i = 0; i + 1 < coords.length; i += 2) {\n const x = coords[i], y = coords[i + 1];\n verts.push({ x, y });\n flat.push(x, y);\n if (x < minX) minX = x;\n if (y < minY) minY = y;\n if (x > maxX) maxX = x;\n if (y > maxY) maxY = y;\n }\n if (verts.length === 0) return null;\n return {\n verts,\n coords: flat,\n bounds: bounds ?? { x: minX, y: minY, width: maxX - minX, height: maxY - minY },\n isRect,\n };\n}\n\n/** A lasso's region, or `null` for fewer than three vertices. */\nexport function polygonRegion(polygon: ReadonlyArray<Vec2>): SelectRegion | null {\n if (polygon.length < 3) return null;\n const coords: number[] = [];\n for (const p of polygon) coords.push(p.x, p.y);\n return regionOf(coords);\n}\n\n/** A pose that is its own drawn outline. */\nexport function isSilhouettePose(pose: unknown): pose is PolygonPath {\n return pose !== null && typeof pose === 'object' && (pose as Path).kind === 'polygon';\n}\n\n/**\n * The box a region fast-rejects a node against: a silhouette pose's own bounds,\n * else the pose's visual bounds — which for a rotated pose is the box of its\n * rotated ink, reaching past the pose box. `g` is the node's descriptor.\n */\nexport function regionBoundsOf(node: object, pose: unknown, g: PoseDescriptor<unknown>): Bounds {\n // Memo is silhouettes-only: a rect pose's bounds are the pose itself, and\n // memoizing it costs more than it saves. The result may be shared; never mutate it.\n return isSilhouettePose(pose)\n ? nodeMemo(node, 'aabb', pose, () => g.getBounds(pose))\n : visualBoundsViaDescriptor(pose, g);\n}\n\n/** The outline of a node nothing paints: its pose rect through the pose's\n * frame, else its visual bounds `b`. */\nexport function poseOutline(pose: unknown, b: Bounds): Path {\n if (poseFrameOf(pose)) {\n const p = pose as Bounds;\n return pathThroughPoseFrame({ kind: 'rect', x: p.x, y: p.y, width: p.width, height: p.height }, pose);\n }\n return { kind: 'rect', x: b.x, y: b.y, width: b.width, height: b.height };\n}\n\n/**\n * Whether `region` takes a node under `mode`, given its pose, its bounds `b`\n * from {@link regionBoundsOf}, and its drawn outline on demand.\n *\n * - `intersect` — the outline meets the region anywhere: its interior too,\n * unless `filled` says nothing paints it.\n * - `enclosed` — the whole outline lies inside it.\n * - `centers` — the center of `b` lies inside it.\n *\n * A node without finite bounds is never taken.\n */\nexport function regionTakes(\n region: SelectRegion,\n mode: LassoHitMode,\n pose: unknown,\n b: Bounds,\n outline: () => Path,\n filled: () => boolean = () => true,\n): boolean {\n if (\n !Number.isFinite(b.x) || !Number.isFinite(b.y) ||\n !Number.isFinite(b.width) || !Number.isFinite(b.height)\n ) {\n return false;\n }\n const ab = region.bounds;\n if (\n b.x >= ab.x + ab.width || b.x + b.width <= ab.x ||\n b.y >= ab.y + ab.height || b.y + b.height <= ab.y\n ) {\n return false;\n }\n if (mode === 'centers') {\n return pointInPolygon(region.coords, b.x + b.width / 2, b.y + b.height / 2);\n }\n const inBox = boxContainsBox(\n [ab.x, ab.y, ab.x + ab.width, ab.y + ab.height],\n [b.x, b.y, b.x + b.width, b.y + b.height],\n );\n const silhouette = isSilhouettePose(pose);\n if (mode === 'enclosed') {\n // A
|
|
1
|
+
{"version":3,"file":"regionHit.js","names":["rectRegion","w","h","r","regionOf","x","y","verts","flat","minX","minY","maxX","maxY","i","coords","bounds","polygonRegion","polygon","p","isSilhouettePose","pose","regionBoundsOf","nodeMemo","node","g","visualBoundsViaDescriptor","poseOutline","poseFrameOf","pathThroughPoseFrame","b","regionTakes","ab","region","mode","pointInPolygon","inBox","boxContainsBox","silhouette","polygonContainsPath","outline","drawn","filled","polygonIntersectsPath"],"sources":["../../../src/core/geometry/regionHit.ts"],"sourcesContent":["/**\n * Whether a marquee or a lasso takes one node: the per-node decision the\n * scene's area walk (`canvas/deps/hitTestArea`) makes.\n *\n * What a node draws is not knowable here — the painters sit above `core/` — so\n * the caller hands in the node's outline as a thunk, asked for only when the\n * bounds cannot decide. A pose that is itself a polygon path is its own\n * outline and never asks.\n */\nimport {\n boxContainsBox,\n pointInPolygon,\n polygonContainsPath,\n polygonIntersectsPath,\n type Path,\n type PolygonPath,\n} from '@weasel-js/geom';\nimport type { Bounds } from 'core/viewport/fitViewToBounds';\nimport type { LassoHitMode } from 'core/adapters/types';\nimport { nodeMemo } from 'core/scene/nodeMemo';\nimport type { Vec2 } from './vec2';\nimport { pathThroughPoseFrame, poseFrameOf } from '@weasel-js/geom';\nimport { visualBoundsViaDescriptor, type PoseDescriptor } from './poseDescriptor';\n\n/** A closed selection area: a marquee rect or a lasso polygon. */\nexport interface SelectRegion {\n /** The area's vertices; the closing edge back to the first is implicit. */\n readonly verts: readonly Vec2[];\n /** `verts` interleaved as `[x0, y0, x1, y1, …]`. */\n readonly coords: readonly number[];\n readonly bounds: Bounds;\n /** True when the area is its own bounding rect, so a node inside `bounds`\n * is inside the area without further work. Never true for a lasso: a node\n * inside the hull's box can still miss the hull. */\n readonly isRect: boolean;\n}\n\n/** A marquee's region. */\nexport function rectRegion(r: Bounds): SelectRegion {\n const { x, y, width: w, height: h } = r;\n return regionOf([x, y, x + w, y, x + w, y + h, x, y + h], { x, y, width: w, height: h }, true)!;\n}\n\n/** A region from interleaved coords. `bounds` is derived when omitted; `null`\n * when there are no coords to bound. */\nexport function regionOf(\n coords: ArrayLike<number>,\n bounds?: Bounds,\n isRect = false,\n): SelectRegion | null {\n const verts: Vec2[] = [];\n const flat: number[] = [];\n let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;\n for (let i = 0; i + 1 < coords.length; i += 2) {\n const x = coords[i], y = coords[i + 1];\n verts.push({ x, y });\n flat.push(x, y);\n if (x < minX) minX = x;\n if (y < minY) minY = y;\n if (x > maxX) maxX = x;\n if (y > maxY) maxY = y;\n }\n if (verts.length === 0) return null;\n return {\n verts,\n coords: flat,\n bounds: bounds ?? { x: minX, y: minY, width: maxX - minX, height: maxY - minY },\n isRect,\n };\n}\n\n/** A lasso's region, or `null` for fewer than three vertices. */\nexport function polygonRegion(polygon: ReadonlyArray<Vec2>): SelectRegion | null {\n if (polygon.length < 3) return null;\n const coords: number[] = [];\n for (const p of polygon) coords.push(p.x, p.y);\n return regionOf(coords);\n}\n\n/** A pose that is its own drawn outline. */\nexport function isSilhouettePose(pose: unknown): pose is PolygonPath {\n return pose !== null && typeof pose === 'object' && (pose as Path).kind === 'polygon';\n}\n\n/**\n * The box a region fast-rejects a node against: a silhouette pose's own bounds,\n * else the pose's visual bounds — which for a rotated pose is the box of its\n * rotated ink, reaching past the pose box. `g` is the node's descriptor.\n */\nexport function regionBoundsOf(node: object, pose: unknown, g: PoseDescriptor<unknown>): Bounds {\n // Memo is silhouettes-only: a rect pose's bounds are the pose itself, and\n // memoizing it costs more than it saves. The result may be shared; never mutate it.\n return isSilhouettePose(pose)\n ? nodeMemo(node, 'aabb', pose, () => g.getBounds(pose))\n : visualBoundsViaDescriptor(pose, g);\n}\n\n/** The outline of a node nothing paints: its pose rect through the pose's\n * frame, else its visual bounds `b`. */\nexport function poseOutline(pose: unknown, b: Bounds): Path {\n if (poseFrameOf(pose)) {\n const p = pose as Bounds;\n return pathThroughPoseFrame({ kind: 'rect', x: p.x, y: p.y, width: p.width, height: p.height }, pose);\n }\n return { kind: 'rect', x: b.x, y: b.y, width: b.width, height: b.height };\n}\n\n/**\n * Whether `region` takes a node under `mode`, given its pose, its bounds `b`\n * from {@link regionBoundsOf}, and its drawn outline on demand.\n *\n * - `intersect` — the outline meets the region anywhere: its interior too,\n * unless `filled` says nothing paints it.\n * - `enclosed` — the whole outline lies inside it.\n * - `centers` — the center of `b` lies inside it.\n *\n * `b` only rejects: it encloses the outline and may reach past it, so a node\n * is taken by the outline alone. A node without finite bounds is never taken.\n */\nexport function regionTakes(\n region: SelectRegion,\n mode: LassoHitMode,\n pose: unknown,\n b: Bounds,\n outline: () => Path,\n filled: () => boolean = () => true,\n): boolean {\n if (\n !Number.isFinite(b.x) || !Number.isFinite(b.y) ||\n !Number.isFinite(b.width) || !Number.isFinite(b.height)\n ) {\n return false;\n }\n const ab = region.bounds;\n if (\n b.x >= ab.x + ab.width || b.x + b.width <= ab.x ||\n b.y >= ab.y + ab.height || b.y + b.height <= ab.y\n ) {\n return false;\n }\n if (mode === 'centers') {\n return pointInPolygon(region.coords, b.x + b.width / 2, b.y + b.height / 2);\n }\n const inBox = boxContainsBox(\n [ab.x, ab.y, ab.x + ab.width, ab.y + ab.height],\n [b.x, b.y, b.x + b.width, b.y + b.height],\n );\n const silhouette = isSilhouettePose(pose);\n if (mode === 'enclosed') {\n // A silhouette pose's bounds are its outline's: sticking out of the\n // region's box, it cannot be inside the region.\n if (silhouette && !inBox) return false;\n return polygonContainsPath(region.verts, silhouette ? pose : outline());\n }\n // Swallowed whole by a marquee: no outline can change the answer.\n if (region.isRect && inBox) return true;\n const drawn = silhouette ? pose : outline();\n if (!filled()) return polygonIntersectsPath(region.verts, drawn, { filled: false });\n // Two axis-aligned rects meet exactly when their boxes overlap.\n if (drawn.kind === 'rect' && region.isRect) {\n return (\n drawn.x < ab.x + ab.width && drawn.x + drawn.width > ab.x &&\n drawn.y < ab.y + ab.height && drawn.y + drawn.height > ab.y\n );\n }\n return polygonIntersectsPath(region.verts, drawn);\n}\n"],"mappings":";;;;AAsCA,SAAgBA,EAAW,GAAyB;CAClD,IAAM,EAAE,MAAG,MAAG,OAAOC,GAAG,QAAQC,MAAMC;CACtC,OAAOC,EAAS;EAACC;EAAGC;EAAGD,IAAIJ;EAAGK;EAAGD,IAAIJ;EAAGK,IAAIJ;EAAGG;EAAGC,IAAIJ;CAAC,GAAG;EAAE;EAAG;EAAG,OAAOD;EAAG,QAAQC;CAAE,GAAG,EAAI;AAC/F;AAIA,SAAgBE,EACd,GACA,GACA,IAAS,IACY;CACrB,IAAMG,IAAgB,CAAC,GACjBC,IAAiB,CAAC,GACpBC,IAAO,UAAUC,IAAO,UAAUC,IAAO,WAAWC,IAAO;CAC/D,KAAK,IAAIC,IAAI,GAAGA,IAAI,IAAIC,EAAO,QAAQ,KAAK,GAAG;EAC7C,IAAMT,IAAIS,EAAOD,IAAIP,IAAIQ,EAAOD,IAAI;EAMpC,AALAN,EAAM,KAAK;GAAE;GAAG;EAAE,CAAC,GACnBC,EAAK,KAAKH,GAAGC,CAAC,GACVD,IAAII,MAAM,IAAOJ,IACjBC,IAAII,MAAM,IAAOJ,IACjBD,IAAIM,MAAM,IAAON,IACjBC,IAAIM,MAAM,IAAON;CACvB;CAEA,OADIC,EAAM,WAAW,IAAU,OACxB;EAC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E,EAAG,KAC9CF,EAAE,KAAKE,EAAG,IAAIA,EAAG,UAAUF,EAAE,IAAIA,EAAE,UAAUE,EAAG,GAEhD,OAAO;CAET,IAAIE,MAAS,WACX,OAAOC,EAAeF,EAAO,QAAQH,EAAE,IAAIA,EAAE,QAAQ,GAAGA,EAAE,IAAIA,EAAE,SAAS,CAAC;CAE5E,IAAMM,IAAQC,EACZ;EAACL,EAAG;EAAGA,EAAG;EAAGA,EAAG,IAAIA,EAAG;EAAOA,EAAG,IAAIA,EAAG;CAAM,GAC9C;EAACF,EAAE;EAAGA,EAAE;EAAGA,EAAE,IAAIA,EAAE;EAAOA,EAAE,IAAIA,EAAE;CAAM,CAC1C,GACMQ,IAAalB,EAAiBC,CAAI;CACxC,IAAIa,MAAS,YAIX,OADII,KAAc,CAACF,IAAc,KAC1BG,EAAoBN,EAAO,OAAOK,IAAajB,IAAOmB,EAAQ,CAAC;CAGxE,IAAIP,EAAO,UAAUG,GAAO,OAAO;CACnC,IAAMK,IAAQH,IAAajB,IAAOmB,EAAQ;CAS1C,OARKE,EAAO,IAERD,EAAM,SAAS,UAAUR,EAAO,SAEhCQ,EAAM,IAAIT,EAAG,IAAIA,EAAG,SAASS,EAAM,IAAIA,EAAM,QAAQT,EAAG,KACxDS,EAAM,IAAIT,EAAG,IAAIA,EAAG,UAAUS,EAAM,IAAIA,EAAM,SAAST,EAAG,IAGvDW,EAAsBV,EAAO,OAAOQ,CAAK,IAR1BE,EAAsBV,EAAO,OAAOQ,GAAO,EAAE,QAAQ,GAAM,CAAC;AASpF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"targetFrame.js","names":["IDENTITY","IDENTITY_TARGET","targetTransformOf","toWorld","poseFrameOf","bounds","invert","angleOf","xf","isRigid","a","b","c","d","localToWorld","lx","ly","x","y","applyToPoint","worldToLocal","wx","wy","worldDeltaToLocal","dx","dy","m","normalToWorld","n","k","pxExtentIn","ux","scale","uy","vx","vy","det","px","targetCorners"],"sources":["../../../src/core/geometry/targetFrame.ts"],"sourcesContent":["/**\n * The frame selection chrome reads a target in: `poseFrameOf` over the\n * target's bounds, with the helpers the outline, the handles, their hit\n * regions, and the resize and rotate actions all place themselves by.\n */\nimport { applyToPoint, invert, poseFrameOf, type
|
|
1
|
+
{"version":3,"file":"targetFrame.js","names":["IDENTITY","IDENTITY_TARGET","targetTransformOf","toWorld","poseFrameOf","bounds","invert","angleOf","xf","isRigid","a","b","c","d","localToWorld","lx","ly","x","y","applyToPoint","worldToLocal","wx","wy","worldDeltaToLocal","dx","dy","m","normalToWorld","n","k","pxExtentIn","ux","scale","uy","vx","vy","det","px","targetCorners"],"sources":["../../../src/core/geometry/targetFrame.ts"],"sourcesContent":["/**\n * The frame selection chrome reads a target in: `poseFrameOf` over the\n * target's bounds, with the helpers the outline, the handles, their hit\n * regions, and the resize and rotate actions all place themselves by.\n */\nimport { applyToPoint, invert, poseFrameOf, type Affine, type Scale2 } from '@weasel-js/geom';\n\n/** Local↔world maps for a chrome target. Local is the target's unrotated box\n * frame; world is where the node is drawn. */\nexport interface TargetTransform {\n /** No rotation and no `transform`: local is world. */\n identity: boolean;\n /** Target box frame → world. */\n toWorld: Affine;\n /** World → target box frame. `null` when the target's `transform` is\n * singular: it draws nothing, and no world point maps back. */\n toLocal: Affine | null;\n}\n\nconst IDENTITY: Affine = [1, 0, 0, 1, 0, 0];\n\nexport const IDENTITY_TARGET: TargetTransform = { identity: true, toWorld: IDENTITY, toLocal: IDENTITY };\n\n/** The frame `bounds` is drawn in: its `rotation`, its `transform`, or both. */\nexport function targetTransformOf(bounds: unknown): TargetTransform {\n const toWorld = poseFrameOf(bounds);\n if (!toWorld) return IDENTITY_TARGET;\n return { identity: false, toWorld, toLocal: invert(toWorld) };\n}\n\n/** How far the target's x axis is turned from world's, radians. */\nexport function angleOf(xf: TargetTransform): number {\n return xf.identity ? 0 : Math.atan2(xf.toWorld[1], xf.toWorld[0]);\n}\n\n/** Whether the frame only turns the target: no skew, no stretch, no flip. */\nexport function isRigid(xf: TargetTransform): boolean {\n if (xf.identity) return true;\n const [a, b, c, d] = xf.toWorld;\n return Math.abs(a - d) < 1e-9 && Math.abs(b + c) < 1e-9 && Math.abs(a * a + b * b - 1) < 1e-9;\n}\n\n/** local point → world point. */\nexport function localToWorld(xf: TargetTransform, lx: number, ly: number): { x: number; y: number } {\n if (xf.identity) return { x: lx, y: ly };\n const [x, y] = applyToPoint(xf.toWorld, lx, ly);\n return { x, y };\n}\n\n/** world point → local point; `null` where nothing maps back. */\nexport function worldToLocal(xf: TargetTransform, wx: number, wy: number): { x: number; y: number } | null {\n if (xf.identity) return { x: wx, y: wy };\n if (!xf.toLocal) return null;\n const [x, y] = applyToPoint(xf.toLocal, wx, wy);\n return { x, y };\n}\n\n/** A world delta in the target's own axes; `null` where nothing maps back. */\nexport function worldDeltaToLocal(xf: TargetTransform, dx: number, dy: number): { x: number; y: number } | null {\n if (xf.identity) return { x: dx, y: dy };\n const m = xf.toLocal;\n return m && { x: m[0] * dx + m[2] * dy, y: m[1] * dx + m[3] * dy };\n}\n\n/** A local edge's outward normal as a world direction, unnormalized. A normal\n * goes through the inverse transpose, so it stays square to a skewed edge. */\nexport function normalToWorld(xf: TargetTransform, n: { x: number; y: number }): { x: number; y: number } {\n if (xf.identity) return n;\n const [a, b, c, d] = xf.toWorld;\n const k = Math.sign(a * d - b * c) || 1;\n return { x: (d * n.x - b * n.y) * k, y: (a * n.y - c * n.x) * k };\n}\n\n/** `pxExtent` along the target's own axes: how far along each an edge across\n * it must move to move `px` on screen. */\nexport function pxExtentIn(px: number, scale: Scale2, xf: TargetTransform): { x: number; y: number } {\n const [a, b, c, d] = xf.toWorld;\n const ux = a * scale.x, uy = b * scale.y;\n const vx = c * scale.x, vy = d * scale.y;\n const det = Math.abs(ux * vy - uy * vx);\n if (det === 0) return { x: 0, y: 0 };\n return { x: (px * Math.hypot(vx, vy)) / det, y: (px * Math.hypot(ux, uy)) / det };\n}\n\n/** The target's box corners in world, TL/TR/BR/BL. */\nexport function targetCorners(\n b: { x: number; y: number; width: number; height: number },\n xf: TargetTransform,\n): { x: number; y: number }[] {\n return [\n localToWorld(xf, b.x, b.y),\n localToWorld(xf, b.x + b.width, b.y),\n localToWorld(xf, b.x + b.width, b.y + b.height),\n localToWorld(xf, b.x, b.y + b.height),\n ];\n}\n"],"mappings":";;AAmBA,IAAMA,IAAmB;CAAC;CAAG;CAAG;CAAG;CAAG;CAAG;AAAC,GAE7BC,IAAmC;CAAE,UAAU;CAAM,SAASD;CAAU,SAASA;AAAS;AAGvG,SAAgBE,EAAkB,GAAkC;CAClE,IAAMC,IAAUC,EAAYC,CAAM;CAElC,OADKF,IACE;EAAE,UAAU;EAAO;EAAS,SAASG,EAAOH,CAAO;CAAE,IADvCF;AAEvB;AAGA,SAAgBM,EAAQ,GAA6B;CACnD,OAAOC,EAAG,WAAW,IAAI,KAAK,MAAMA,EAAG,QAAQ,IAAIA,EAAG,QAAQ,EAAE;AAClE;AAGA,SAAgBC,EAAQ,GAA8B;CACpD,IAAID,EAAG,UAAU,OAAO;CACxB,IAAM,CAACE,GAAGC,GAAGC,GAAGC,KAAKL,EAAG;CACxB,OAAO,KAAK,IAAIE,IAAIG,CAAC,IAAI,QAAQ,KAAK,IAAIF,IAAIC,CAAC,IAAI,QAAQ,KAAK,IAAIF,IAAIA,IAAIC,IAAIA,IAAI,CAAC,IAAI;AAC3F;AAGA,SAAgBG,EAAa,GAAqB,GAAY,GAAsC;CAClG,IAAIN,EAAG,UAAU,OAAO;EAAE,GAAGO;EAAI,GAAGC;CAAG;CACvC,IAAM,CAACC,GAAGC,KAAKC,EAAaX,EAAG,SAASO,GAAIC,CAAE;CAC9C,OAAO;EAAE;EAAG;CAAE;AAChB;AAGA,SAAgBI,EAAa,GAAqB,GAAY,GAA6C;CACzG,IAAIZ,EAAG,UAAU,OAAO;EAAE,GAAGa;EAAI,GAAGC;CAAG;CACvC,IAAI,CAACd,EAAG,SAAS,OAAO;CACxB,IAAM,CAACS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,EAAE,IAAIA,EAAE,OAAOA,EAAE,CAAC;EACnCG,EAAaN,GAAIG,EAAE,IAAIA,EAAE,OAAOA,EAAE,IAAIA,EAAE,MAAM;EAC9CG,EAAaN,GAAIG,EAAE,GAAGA,EAAE,IAAIA,EAAE,MAAM;CACtC;AACF"}
|
|
@@ -6,9 +6,7 @@ function e(e) {
|
|
|
6
6
|
defaultVisible: e.defaultVisible,
|
|
7
7
|
alwaysOn: e.alwaysOn,
|
|
8
8
|
draw: (t, n) => {
|
|
9
|
-
let r = e.adapter.getChildren;
|
|
10
|
-
if (!r) return [];
|
|
11
|
-
let i = r(typeof e.parentId == "function" ? e.parentId() : e.parentId ?? null), a = [];
|
|
9
|
+
let r = typeof e.parentId == "function" ? e.parentId() : e.parentId ?? null, i = e.adapter.getChildren(r), a = [];
|
|
12
10
|
for (let r of i) {
|
|
13
11
|
let i = e.drawChild(r, t, n);
|
|
14
12
|
for (let e of i) a.push(e);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"children.js","names":["createChildrenLayer","opts","
|
|
1
|
+
{"version":3,"file":"children.js","names":["createChildrenLayer","opts","parent","ids","out","id","sub","data","view","cmd"],"sources":["../../../src/core/layers/children.ts"],"sourcesContent":["/**\n * Z-ordered child renderer: a `RenderLayer` factory over an `OrderedAdapter`.\n * Children are drawn in z-order (index 0 = bottom).\n */\n\nimport type { DrawCommand } from '@weasel-js/renderer';\nimport type { RenderLayer } from 'core/layers/render';\nimport type { View } from 'core/viewport/view';\nimport type { OrderedAdapter } from 'core/adapters/types';\n\n/** Options for `createChildrenLayer`. */\nexport interface CreateChildrenLayerOpts<TData> {\n /** Layer id for the visibility/order map. Default `'children'`. */\n id?: string;\n /** Human-readable label. Default `'Children'`. */\n label?: string;\n /** Source of `getChildren`. Only the read side is used. */\n adapter: Pick<OrderedAdapter, 'getChildren'>;\n /** Parent id (null = root). Function form lets the layer follow a moving\n * selection or focus. Default `null`. */\n parentId?: string | null | (() => string | null);\n /** Draw one child. Called once per id in z-order (bottom → top). The\n * per-child outputs are concatenated into the layer's `DrawCommand[]`. */\n drawChild(id: string, data: TData, view: View): DrawCommand[];\n /** Forwarded to the produced `RenderLayer`. */\n defaultVisible?: boolean;\n /** Forwarded to the produced `RenderLayer`. */\n alwaysOn?: boolean;\n}\n\n/** Build a `RenderLayer` that draws an `OrderedAdapter`'s children in z-order. */\nexport function createChildrenLayer<TData = unknown>(\n opts: CreateChildrenLayerOpts<TData>,\n): RenderLayer<TData> {\n return {\n id: opts.id ?? 'children',\n label: opts.label ?? 'Children',\n defaultVisible: opts.defaultVisible,\n alwaysOn: opts.alwaysOn,\n draw: (data, view) => {\n const parent =\n typeof opts.parentId === 'function'\n ? opts.parentId()\n : opts.parentId ?? null;\n const ids = opts.adapter.getChildren(parent);\n const out: DrawCommand[] = [];\n for (const id of ids) {\n const sub = opts.drawChild(id, data, view);\n for (const cmd of sub) out.push(cmd);\n }\n return out;\n },\n };\n}\n"],"mappings":";AA+BA,SAAgBA,EACd,GACoB;CACpB,OAAO;EACL,IAAIC,EAAK,MAAM;EACf,OAAOA,EAAK,SAAS;EACrB,gBAAgBA,EAAK;EACrB,UAAUA,EAAK;EACf,OAAO,GAAM,MAAS;GACpB,IAAMC,IACJ,OAAOD,EAAK,YAAa,aACrBA,EAAK,SAAS,IACdA,EAAK,YAAY,MACjBE,IAAMF,EAAK,QAAQ,YAAYC,CAAM,GACrCE,IAAqB,CAAC;GAC5B,KAAK,IAAMC,KAAMF,GAAK;IACpB,IAAMG,IAAML,EAAK,UAAUI,GAAIE,GAAMC,CAAI;IACzC,KAAK,IAAMC,KAAOH,GAAK,EAAI,KAAKG,CAAG;GACrC;GACA,OAAOL;EACT;CACF;AACF"}
|
package/dist/core/ops/create.js
CHANGED
|
@@ -15,10 +15,10 @@ function a(e) {
|
|
|
15
15
|
label: o,
|
|
16
16
|
apply(e) {
|
|
17
17
|
let r = e, i = () => {
|
|
18
|
-
r.insertNode(a, n(r.getChildren
|
|
18
|
+
r.insertNode(a, n(r.getChildren(t(a)), c));
|
|
19
19
|
};
|
|
20
20
|
if (!s || s.length === 0) return i();
|
|
21
|
-
for (let e of s) r.getNode
|
|
21
|
+
for (let e of s) r.getNode(e.node.id) || (e.node.id === a.id ? i() : r.insertNode(e.node, e.index));
|
|
22
22
|
},
|
|
23
23
|
invert() {
|
|
24
24
|
return i({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create.js","names":["createInsertOp","args","slot","slotFromIndex","cascaded","a","adapter","insertRoot","node","resolveSlot","parentOf","entry","createDeleteOp","registerOpFactory"],"sources":["../../../src/core/ops/create.ts"],"sourcesContent":["import type { Op } from './types';\nimport { createDeleteOp, type PlacedNode } from './delete';\nimport { registerOpFactory } from './registry';\nimport { parentOf, resolveSlot, slotFromIndex, type OrderedReader, type SiblingSlot } from './slot';\n\ninterface InsertAdapter<TNode> extends OrderedReader {\n getNode
|
|
1
|
+
{"version":3,"file":"create.js","names":["createInsertOp","args","slot","slotFromIndex","cascaded","a","adapter","insertRoot","node","resolveSlot","parentOf","entry","createDeleteOp","registerOpFactory"],"sources":["../../../src/core/ops/create.ts"],"sourcesContent":["import type { Op } from './types';\nimport { createDeleteOp, type PlacedNode } from './delete';\nimport { registerOpFactory } from './registry';\nimport { parentOf, resolveSlot, slotFromIndex, type OrderedReader, type SiblingSlot } from './slot';\n\ninterface InsertAdapter<TNode> extends OrderedReader {\n getNode(id: string): TNode | undefined;\n /** When `index` is supplied, insert at that position; an adapter that\n * ignores the second arg falls back to its default placement (typically\n * append-to-end). */\n insertNode(node: TNode, index?: number): void;\n}\n\n/** Type alias for ops produced by `createInsertOp`. Carries no extra type info today;\n * exists so consumers can name the op type when needed. */\nexport type InsertOp = Op;\n\n/** Arguments to {@link createInsertOp}: the node to insert and where among its siblings. */\nexport interface InsertArgs<TNode extends { id: string }> {\n node: TNode;\n label?: string;\n /** Sibling ordinal to insert at. Sugar for `slot: { index }` — the weaker\n * of the two forms, and all a fresh-insert callsite can know. */\n index?: number;\n /** Full slot, anchor included. Produced only by `captureSlot` (via a\n * delete op's `invert`), and supersedes `index` when present. */\n slot?: SiblingSlot;\n /** Every node to insert, `node` itself included, each at its ordinal among\n * its own parent's children and ordered so a parent precedes its children.\n * What a delete's `cascaded` captures, and how its inverse brings the whole\n * set back; `node` still goes in at `slot`. One already present is skipped. */\n cascaded?: PlacedNode<TNode>[];\n}\n\n/** Op: insert `node`, and the rest of `cascaded` with it; inverts to a delete\n * of `node`. */\nexport function createInsertOp<TNode extends { id: string }>(args: InsertArgs<TNode>): InsertOp {\n const { node, label, cascaded } = args;\n const slot: SiblingSlot = args.slot ?? slotFromIndex(args.index);\n return {\n name: 'insert',\n args: { node, label, slot, ...(cascaded ? { cascaded } : {}) },\n label,\n apply(adapter) {\n const a = adapter as InsertAdapter<TNode>;\n const insertRoot = (): void => {\n a.insertNode(node, resolveSlot(a.getChildren(parentOf(node)), slot));\n };\n if (!cascaded || cascaded.length === 0) return insertRoot();\n for (const entry of cascaded) {\n // An adapter whose removeNode doesn't cascade never lost the\n // children — re-inserting them would duplicate them.\n if (a.getNode(entry.node.id)) continue;\n if (entry.node.id === node.id) insertRoot();\n else a.insertNode(entry.node, entry.index);\n }\n },\n invert() {\n return createDeleteOp({ node, label, slot, ...(cascaded ? { cascaded } : {}) });\n },\n };\n}\n\nregisterOpFactory<InsertArgs<{ id: string }>>('insert', (args) => createInsertOp(args));\n"],"mappings":";;;;AAoCA,SAAgBA,EAA6C,GAAmC;CAC9F,IAAM,EAAE,SAAM,UAAO,gBAAaC,GAC5BC,IAAoBD,EAAK,QAAQE,EAAcF,EAAK,KAAK;CAC/D,OAAO;EACL,MAAM;EACN,MAAM;GAAE;GAAM;GAAO;GAAM,GAAIG,IAAW,EAAE,YAAS,IAAI,CAAC;EAAG;EAC7D;EACA,MAAM,GAAS;GACb,IAAMC,IAAIC,GACJC,UAAyB;IAC7B,EAAE,WAAWC,GAAMC,EAAYJ,EAAE,YAAYK,EAASF,CAAI,CAAC,GAAGN,CAAI,CAAC;GACrE;GACA,IAAI,CAACE,KAAYA,EAAS,WAAW,GAAG,OAAOG,EAAW;GAC1D,KAAK,IAAMI,KAASP,GAGlB,AAAIC,EAAE,QAAQM,EAAM,KAAK,EAAE,MACvBA,EAAM,KAAK,OAAOH,EAAK,KAAID,EAAW,IACrCF,EAAE,WAAWM,EAAM,MAAMA,EAAM,KAAK;EAE7C;EACA,SAAS;GACP,OAAOC,EAAe;IAAE;IAAM;IAAO;IAAM,GAAIR,IAAW,EAAE,YAAS,IAAI,CAAC;GAAG,CAAC;EAChF;CACF;AACF;AAEAS,EAA8C,WAAW,MAASb,EAAeC,CAAI,CAAC"}
|
package/dist/core/ops/delete.js
CHANGED
|
@@ -3,45 +3,43 @@ import { captureSlot as t, parentOf as n, slotFromIndex as r } from "./slot.js";
|
|
|
3
3
|
import { createInsertOp as i } from "./create.js";
|
|
4
4
|
//#region src/core/ops/delete.ts
|
|
5
5
|
function a(e, t, n) {
|
|
6
|
-
return e.getChildren
|
|
6
|
+
return e.getChildren(t).indexOf(n);
|
|
7
7
|
}
|
|
8
8
|
function o(e, t) {
|
|
9
|
-
let
|
|
10
|
-
if (
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
let n = i.call(e, t);
|
|
14
|
-
n && s.set(t, n);
|
|
9
|
+
let r = e.getRemovalClosure?.([t]), i = /* @__PURE__ */ new Map();
|
|
10
|
+
if (r) for (let t of r) {
|
|
11
|
+
let n = e.getNode(t);
|
|
12
|
+
n && i.set(t, n);
|
|
15
13
|
}
|
|
16
14
|
else {
|
|
17
15
|
let n = (t) => {
|
|
18
|
-
let
|
|
19
|
-
if (
|
|
20
|
-
|
|
21
|
-
for (let
|
|
16
|
+
let r = e.getNode(t);
|
|
17
|
+
if (r) {
|
|
18
|
+
i.set(t, r);
|
|
19
|
+
for (let r of e.getChildren(t)) n(r);
|
|
22
20
|
}
|
|
23
21
|
};
|
|
24
22
|
n(t);
|
|
25
23
|
}
|
|
26
|
-
let
|
|
24
|
+
let o = [...i.values()].filter((e) => {
|
|
27
25
|
let t = n(e);
|
|
28
|
-
return t === null || !
|
|
26
|
+
return t === null || !i.has(t);
|
|
29
27
|
}).map((t) => ({
|
|
30
28
|
node: t,
|
|
31
29
|
index: a(e, n(t), t.id)
|
|
32
|
-
})).sort((e, t) => e.index - t.index),
|
|
33
|
-
|
|
34
|
-
let n =
|
|
30
|
+
})).sort((e, t) => e.index - t.index), s = [], c = (t) => {
|
|
31
|
+
s.push(t);
|
|
32
|
+
let n = e.getChildren(t.node.id);
|
|
35
33
|
for (let e = 0; e < n.length; e++) {
|
|
36
|
-
let t =
|
|
37
|
-
t &&
|
|
34
|
+
let t = i.get(n[e]);
|
|
35
|
+
t && c({
|
|
38
36
|
node: t,
|
|
39
37
|
index: e
|
|
40
38
|
});
|
|
41
39
|
}
|
|
42
40
|
};
|
|
43
|
-
for (let e of
|
|
44
|
-
return
|
|
41
|
+
for (let e of o) c(e);
|
|
42
|
+
return s;
|
|
45
43
|
}
|
|
46
44
|
function s(e) {
|
|
47
45
|
let { node: a, label: s } = e, c = e.slot ?? r(e.index), l = {
|
|
@@ -56,9 +54,7 @@ function s(e) {
|
|
|
56
54
|
label: s,
|
|
57
55
|
apply(e) {
|
|
58
56
|
let r = e, i = t(r, n(a), a.id);
|
|
59
|
-
i && (c = i, l.slot = i);
|
|
60
|
-
let s = o(r, a.id);
|
|
61
|
-
s && (u = s, l.cascaded = s), r.removeNode(a.id);
|
|
57
|
+
i && (c = i, l.slot = i), u = o(r, a.id), l.cascaded = u, r.removeNode(a.id);
|
|
62
58
|
},
|
|
63
59
|
invert() {
|
|
64
60
|
return i({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"delete.js","names":["indexIn","a","parentId","id","captureCascade","
|
|
1
|
+
{"version":3,"file":"delete.js","names":["indexIn","a","parentId","id","captureCascade","closure","rootId","taken","node","walk","kid","detachRoots","p","parentOf","n","l","r","out","emitSubtree","entry","kids","i","child","createDeleteOp","args","slot","slotFromIndex","argsForSerial","captured","adapter","observed","captureSlot","createInsertOp","registerOpFactory"],"sources":["../../../src/core/ops/delete.ts"],"sourcesContent":["import type { Op } from './types';\nimport { createInsertOp } from './create';\nimport { registerOpFactory } from './registry';\nimport { captureSlot, parentOf, slotFromIndex, type OrderedReader, type SiblingSlot } from './slot';\n\ninterface DeleteAdapter<TNode> extends OrderedReader {\n removeNode(id: string): void;\n /** With `getChildren`, the subtree reads that snapshot the cascade before\n * it runs. */\n getNode(id: string): TNode | undefined;\n /** Every id `removeNode` would take with this one. A store whose removal\n * cascades past the subtree — the kit's scene takes a deleted node's\n * dependents too — must answer here, or those nodes are absent from the\n * snapshot and undo does not bring them back. */\n getRemovalClosure?(ids: readonly string[]): readonly string[];\n}\n\n/** A captured node plus its slot in its own parent's child list. */\nexport interface PlacedNode<TNode> {\n node: TNode;\n index: number;\n}\n\n/** Arguments to {@link createDeleteOp}: the node to remove, plus what undo needs to put it back. */\nexport interface DeleteArgs<TNode extends { id: string }> {\n node: TNode;\n label?: string;\n /** Sibling ordinal the node occupies at the moment of delete. Sugar for\n * `slot: { index }`, and only a seed: `apply` re-observes the node's full\n * slot through the adapter, and that supersedes this. */\n index?: number;\n /** Full slot, anchor included. Written by `apply`; supersedes `index`. */\n slot?: SiblingSlot;\n /** Everything `removeNode` takes, `node` itself included — its subtree, and\n * whatever else the adapter cascades. Ordered so a node's parent precedes\n * it, which is the order they have to be re-inserted in. Captured on apply;\n * mirrored into the serialized args so a rebuilt op can invert without\n * having run. */\n cascaded?: PlacedNode<TNode>[];\n}\n\n/** `id`'s ordinal among `parentId`'s children, or `-1` when it is not one. */\nfunction indexIn(a: OrderedReader, parentId: string | null, id: string): number {\n return a.getChildren(parentId).indexOf(id);\n}\n\n/**\n * Snapshot everything removing `rootId` takes with it, `rootId` included.\n *\n * A cascade unlinks several disjoint subtrees, so the captured set is walked\n * as a forest: a node whose parent is not also going is a detach root, and\n * each one is emitted — ascending sibling index first, so every slot still\n * means what it meant — followed by its captured descendants preorder. The\n * closure's own order will not do: it can reach a dependent before the parent\n * it sits under, and re-inserting a child under a parent that is not back yet\n * puts it in the wrong place.\n */\nfunction captureCascade<TNode extends { id: string }>(\n a: DeleteAdapter<TNode>,\n rootId: string,\n): PlacedNode<TNode>[] {\n const closure = a.getRemovalClosure?.([rootId]);\n const taken = new Map<string, TNode>();\n if (closure) {\n for (const id of closure) {\n const node = a.getNode(id);\n if (node) taken.set(id, node);\n }\n } else {\n // No closure read: the cascade is the subtree, discovered here.\n const walk = (id: string): void => {\n const node = a.getNode(id);\n if (!node) return;\n taken.set(id, node);\n for (const kid of a.getChildren(id)) walk(kid);\n };\n walk(rootId);\n }\n\n const detachRoots = [...taken.values()]\n .filter((n) => { const p = parentOf(n); return p === null || !taken.has(p); })\n .map((n) => ({ node: n, index: indexIn(a, parentOf(n), n.id) }))\n .sort((l, r) => l.index - r.index);\n\n const out: PlacedNode<TNode>[] = [];\n const emitSubtree = (entry: PlacedNode<TNode>): void => {\n out.push(entry);\n const kids = a.getChildren(entry.node.id);\n for (let i = 0; i < kids.length; i++) {\n const child = taken.get(kids[i]!);\n if (child) emitSubtree({ node: child, index: i });\n }\n };\n for (const entry of detachRoots) emitSubtree(entry);\n return out;\n}\n\n/** Op: remove `node` and everything the adapter cascades with it; inverts to a\n * re-insert of the whole set at its captured slots. */\nexport function createDeleteOp<TNode extends { id: string }>(args: DeleteArgs<TNode>): Op {\n const { node, label } = args;\n let slot: SiblingSlot = args.slot ?? slotFromIndex(args.index);\n const argsForSerial: DeleteArgs<TNode> = { node, label, slot, cascaded: args.cascaded };\n let captured: PlacedNode<TNode>[] = args.cascaded ?? [];\n return {\n name: 'delete',\n args: argsForSerial,\n label,\n apply(adapter) {\n const a = adapter as DeleteAdapter<TNode>;\n const observed = captureSlot(a, parentOf(node), node.id);\n if (observed) {\n slot = observed;\n argsForSerial.slot = observed;\n }\n captured = captureCascade(a, node.id);\n argsForSerial.cascaded = captured;\n a.removeNode(node.id);\n },\n invert() {\n // The root's own placement keeps the anchor-bearing slot; the rest have\n // only an ordinal, which is all `getChildren` can observe of them.\n return createInsertOp<TNode>({\n node, label, slot,\n ...(captured.length > 0 ? { cascaded: captured } : {}),\n });\n },\n };\n}\n\nregisterOpFactory<DeleteArgs<{ id: string }>>('delete', (args) => createDeleteOp(args));\n"],"mappings":";;;;AA0CA,SAASA,EAAQ,GAAkB,GAAyB,GAAoB;CAC9E,OAAOC,EAAE,YAAYC,CAAQ,CAAC,CAAC,QAAQC,CAAE;AAC3C;AAaA,SAASC,EACP,GACA,GACqB;CACrB,IAAMC,IAAUJ,EAAE,oBAAoB,CAACK,CAAM,CAAC,GACxCC,oBAAQ,IAAI,IAAmB;CACrC,IAAIF,GACF,KAAK,IAAMF,KAAME,GAAS;EACxB,IAAMG,IAAOP,EAAE,QAAQE,CAAE;EACzB,AAAIK,KAAMD,EAAM,IAAIJ,GAAIK,CAAI;CAC9B;MACK;EAEL,IAAMC,KAAQ,MAAqB;GACjC,IAAMD,IAAOP,EAAE,QAAQE,CAAE;GACzB,IAAKK,GACL;MAAM,IAAIL,GAAIK,CAAI;IAClB,KAAK,IAAME,KAAOT,EAAE,YAAYE,CAAE,GAAG,EAAKO,CAAG;GAD3B;EAEpB;EACA,EAAKJ,CAAM;CACb;CAEA,IAAMK,IAAc,CAAC,GAAGJ,EAAM,OAAO,CAAC,CAAC,CACpC,QAAQ,MAAM;EAAE,IAAMK,IAAIC,EAASC,CAAC;EAAG,OAAOF,MAAM,QAAQ,CAACL,EAAM,IAAIK,CAAC;CAAG,CAAC,CAAC,CAC7E,KAAK,OAAO;EAAE,MAAME;EAAG,OAAOd,EAAQC,GAAGY,EAASC,CAAC,GAAGA,EAAE,EAAE;CAAE,EAAE,CAAC,CAC/D,MAAM,GAAG,MAAMC,EAAE,QAAQC,EAAE,KAAK,GAE7BC,IAA2B,CAAC,GAC5BC,KAAe,MAAmC;EACtD,EAAI,KAAKC,CAAK;EACd,IAAMC,IAAOnB,EAAE,YAAYkB,EAAM,KAAK,EAAE;EACxC,KAAK,IAAIE,IAAI,GAAGA,IAAID,EAAK,QAAQ,KAAK;GACpC,IAAME,IAAQf,EAAM,IAAIa,EAAKC,EAAG;GAChC,AAAIC,KAAOJ,EAAY;IAAE,MAAMI;IAAO,OAAOD;GAAE,CAAC;EAClD;CACF;CACA,KAAK,IAAMF,KAASR,GAAa,EAAYQ,CAAK;CAClD,OAAOF;AACT;AAIA,SAAgBM,EAA6C,GAA6B;CACxF,IAAM,EAAE,SAAM,aAAUC,GACpBC,IAAoBD,EAAK,QAAQE,EAAcF,EAAK,KAAK,GACvDG,IAAmC;EAAE;EAAM;EAAO;EAAM,UAAUH,EAAK;CAAS,GAClFI,IAAgCJ,EAAK,YAAY,CAAC;CACtD,OAAO;EACL,MAAM;EACN,MAAMG;EACN;EACA,MAAM,GAAS;GACb,IAAM1B,IAAI4B,GACJC,IAAWC,EAAY9B,GAAGY,EAASL,CAAI,GAAGA,EAAK,EAAE;GAOvD,AANIsB,MACF,IAAOA,GACP,EAAc,OAAOA,IAEvB,IAAW1B,EAAeH,GAAGO,EAAK,EAAE,GACpC,EAAc,WAAWoB,GACzB3B,EAAE,WAAWO,EAAK,EAAE;EACtB;EACA,SAAS;GAGP,OAAOwB,EAAsB;IAC3B;IAAM;IAAO;IACb,GAAIJ,EAAS,SAAS,IAAI,EAAE,UAAUA,EAAS,IAAI,CAAC;GACtD,CAAC;EACH;CACF;AACF;AAEAK,EAA8C,WAAW,MAASV,EAAeC,CAAI,CAAC"}
|
|
@@ -25,11 +25,9 @@ function u(e) {
|
|
|
25
25
|
args: o,
|
|
26
26
|
label: i,
|
|
27
27
|
apply(e) {
|
|
28
|
-
let n = e;
|
|
29
|
-
if (!n.getChildren || !n.setChildOrder) return !1;
|
|
30
|
-
let i = /* @__PURE__ */ new Map();
|
|
28
|
+
let n = e, i = /* @__PURE__ */ new Map();
|
|
31
29
|
for (let e of t) {
|
|
32
|
-
let t = n.getParent
|
|
30
|
+
let t = n.getParent(e), r = i.get(t) ?? [];
|
|
33
31
|
r.push(e), i.set(t, r);
|
|
34
32
|
}
|
|
35
33
|
let a = [], c = !1;
|
|
@@ -108,9 +106,7 @@ function p(e) {
|
|
|
108
106
|
args: o,
|
|
109
107
|
label: i ?? "Move to index",
|
|
110
108
|
apply(e) {
|
|
111
|
-
let i = e;
|
|
112
|
-
if (!i.getChildren || !i.setChildOrder) return;
|
|
113
|
-
let c = t.filter((e) => (i.getParent ? i.getParent(e) : null) === n), l = i.getChildren(n);
|
|
109
|
+
let i = e, c = t.filter((e) => i.getParent(e) === n), l = i.getChildren(n);
|
|
114
110
|
s === null && (s = l.slice(), o.prevPositions = s.slice());
|
|
115
111
|
let u = a(l, c, r);
|
|
116
112
|
i.setChildOrder(n, u);
|