@weasel-js/editing 0.0.0-stage → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +60 -2
- package/dist/actionGroups.js +27 -0
- package/dist/actionGroups.js.map +1 -0
- package/dist/actions/align/action.js +105 -0
- package/dist/actions/align/action.js.map +1 -0
- package/dist/actions/align/align.js +115 -0
- package/dist/actions/align/align.js.map +1 -0
- package/dist/actions/clipboard/action.js +133 -0
- package/dist/actions/clipboard/action.js.map +1 -0
- package/dist/actions/clone/action.js +217 -0
- package/dist/actions/clone/action.js.map +1 -0
- package/dist/actions/clone/behaviors.js +65 -0
- package/dist/actions/clone/behaviors.js.map +1 -0
- package/dist/actions/delete/delete.js +123 -0
- package/dist/actions/delete/delete.js.map +1 -0
- package/dist/actions/derivedBox.js +16 -0
- package/dist/actions/derivedBox.js.map +1 -0
- package/dist/actions/distribute/action.js +96 -0
- package/dist/actions/distribute/action.js.map +1 -0
- package/dist/actions/distribute/distribute.js +61 -0
- package/dist/actions/distribute/distribute.js.map +1 -0
- package/dist/actions/distribute/plan.js +55 -0
- package/dist/actions/distribute/plan.js.map +1 -0
- package/dist/actions/edit/createPaintAction.js +138 -0
- package/dist/actions/edit/createPaintAction.js.map +1 -0
- package/dist/actions/edit/deselect.js +34 -0
- package/dist/actions/edit/deselect.js.map +1 -0
- package/dist/actions/edit/duplicate.js +93 -0
- package/dist/actions/edit/duplicate.js.map +1 -0
- package/dist/actions/edit/group.js +281 -0
- package/dist/actions/edit/group.js.map +1 -0
- package/dist/actions/edit/ingest.js +114 -0
- package/dist/actions/edit/ingest.js.map +1 -0
- package/dist/actions/edit/nudge.js +97 -0
- package/dist/actions/edit/nudge.js.map +1 -0
- package/dist/actions/edit/selectAll.js +48 -0
- package/dist/actions/edit/selectAll.js.map +1 -0
- package/dist/actions/edit/setFill.js +52 -0
- package/dist/actions/edit/setFill.js.map +1 -0
- package/dist/actions/edit/setFillOpacity.js +26 -0
- package/dist/actions/edit/setFillOpacity.js.map +1 -0
- package/dist/actions/edit/setStroke.js +57 -0
- package/dist/actions/edit/setStroke.js.map +1 -0
- package/dist/actions/edit/setStrokeOpacity.js +28 -0
- package/dist/actions/edit/setStrokeOpacity.js.map +1 -0
- package/dist/actions/edit/setStrokeWidth.js +53 -0
- package/dist/actions/edit/setStrokeWidth.js.map +1 -0
- package/dist/actions/edit/setVertexColor.js +45 -0
- package/dist/actions/edit/setVertexColor.js.map +1 -0
- package/dist/actions/flip/action.js +209 -0
- package/dist/actions/flip/action.js.map +1 -0
- package/dist/actions/flip/helpers.js +80 -0
- package/dist/actions/flip/helpers.js.map +1 -0
- package/dist/actions/group/enterGroup.js +81 -0
- package/dist/actions/group/enterGroup.js.map +1 -0
- package/dist/actions/insert/action.js +152 -0
- package/dist/actions/insert/action.js.map +1 -0
- package/dist/actions/insert/commit.js +52 -0
- package/dist/actions/insert/commit.js.map +1 -0
- package/dist/actions/insert/extras.js +88 -0
- package/dist/actions/insert/extras.js.map +1 -0
- package/dist/actions/insert/frame.js +96 -0
- package/dist/actions/insert/frame.js.map +1 -0
- package/dist/actions/insert/geometry.js +35 -0
- package/dist/actions/insert/geometry.js.map +1 -0
- package/dist/actions/insert/lands.js +41 -0
- package/dist/actions/insert/lands.js.map +1 -0
- package/dist/actions/insert/params.js +42 -0
- package/dist/actions/insert/params.js.map +1 -0
- package/dist/actions/insert/placeAction.js +137 -0
- package/dist/actions/insert/placeAction.js.map +1 -0
- package/dist/actions/insert/repositionAction.js +47 -0
- package/dist/actions/insert/repositionAction.js.map +1 -0
- package/dist/actions/insert/rotateAction.js +34 -0
- package/dist/actions/insert/rotateAction.js.map +1 -0
- package/dist/actions/insert/session.js +99 -0
- package/dist/actions/insert/session.js.map +1 -0
- package/dist/actions/insert/shape.js +117 -0
- package/dist/actions/insert/shape.js.map +1 -0
- package/dist/actions/insert/style.js +23 -0
- package/dist/actions/insert/style.js.map +1 -0
- package/dist/actions/lassoSelect/action.js +201 -0
- package/dist/actions/lassoSelect/action.js.map +1 -0
- package/dist/actions/lassoSelect/behaviors/selectFromLasso.js +61 -0
- package/dist/actions/lassoSelect/behaviors/selectFromLasso.js.map +1 -0
- package/dist/actions/lockedWrites.js +20 -0
- package/dist/actions/lockedWrites.js.map +1 -0
- package/dist/actions/move/action.js +138 -0
- package/dist/actions/move/action.js.map +1 -0
- package/dist/actions/move/behaviors/clampMove.js +42 -0
- package/dist/actions/move/behaviors/clampMove.js.map +1 -0
- package/dist/actions/move/behaviors/layoutDrop.js +84 -0
- package/dist/actions/move/behaviors/layoutDrop.js.map +1 -0
- package/dist/actions/move/behaviors/pageDrop.js +30 -0
- package/dist/actions/move/behaviors/pageDrop.js.map +1 -0
- package/dist/actions/move/behaviors/reparentOnDrop.js +44 -0
- package/dist/actions/move/behaviors/reparentOnDrop.js.map +1 -0
- package/dist/actions/move/behaviors/snapBackOrDelete.js +52 -0
- package/dist/actions/move/behaviors/snapBackOrDelete.js.map +1 -0
- package/dist/actions/move/behaviors/snapToContainer.js +214 -0
- package/dist/actions/move/behaviors/snapToContainer.js.map +1 -0
- package/dist/actions/move/behaviors/swapOnDrop.js +180 -0
- package/dist/actions/move/behaviors/swapOnDrop.js.map +1 -0
- package/dist/actions/move/capture.js +116 -0
- package/dist/actions/move/capture.js.map +1 -0
- package/dist/actions/move/commit/index.js +47 -0
- package/dist/actions/move/commit/index.js.map +1 -0
- package/dist/actions/move/commit/layoutDrop.js +68 -0
- package/dist/actions/move/commit/layoutDrop.js.map +1 -0
- package/dist/actions/move/commit/layoutRelease.js +146 -0
- package/dist/actions/move/commit/layoutRelease.js.map +1 -0
- package/dist/actions/move/commit/pageDrop.js +162 -0
- package/dist/actions/move/commit/pageDrop.js.map +1 -0
- package/dist/actions/move/commit/rebase.js +24 -0
- package/dist/actions/move/commit/rebase.js.map +1 -0
- package/dist/actions/move/commit/reparent.js +157 -0
- package/dist/actions/move/commit/reparent.js.map +1 -0
- package/dist/actions/move/delta.js +127 -0
- package/dist/actions/move/delta.js.map +1 -0
- package/dist/actions/move/dragSnap.js +55 -0
- package/dist/actions/move/dragSnap.js.map +1 -0
- package/dist/actions/move/frame.js +67 -0
- package/dist/actions/move/frame.js.map +1 -0
- package/dist/actions/move/gestureAdapter.js +36 -0
- package/dist/actions/move/gestureAdapter.js.map +1 -0
- package/dist/actions/move/landedDescendants.js +50 -0
- package/dist/actions/move/landedDescendants.js.map +1 -0
- package/dist/actions/move/layout/container.js +119 -0
- package/dist/actions/move/layout/container.js.map +1 -0
- package/dist/actions/move/layout/dragged.js +75 -0
- package/dist/actions/move/layout/dragged.js.map +1 -0
- package/dist/actions/move/layout/dropPass.js +205 -0
- package/dist/actions/move/layout/dropPass.js.map +1 -0
- package/dist/actions/move/layout/exits.js +62 -0
- package/dist/actions/move/layout/exits.js.map +1 -0
- package/dist/actions/move/layout/glide.js +70 -0
- package/dist/actions/move/layout/glide.js.map +1 -0
- package/dist/actions/move/layout/view.js +60 -0
- package/dist/actions/move/layout/view.js.map +1 -0
- package/dist/actions/move/refusal.js +49 -0
- package/dist/actions/move/refusal.js.map +1 -0
- package/dist/actions/move/session.js +105 -0
- package/dist/actions/move/session.js.map +1 -0
- package/dist/actions/move/sessionOf.js +27 -0
- package/dist/actions/move/sessionOf.js.map +1 -0
- package/dist/actions/move/translate.js +49 -0
- package/dist/actions/move/translate.js.map +1 -0
- package/dist/actions/pathfinder/action.js +109 -0
- package/dist/actions/pathfinder/action.js.map +1 -0
- package/dist/actions/pathfinder/booleanGroupAction.js +117 -0
- package/dist/actions/pathfinder/booleanGroupAction.js.map +1 -0
- package/dist/actions/pathfinder/keymap.js +51 -0
- package/dist/actions/pathfinder/keymap.js.map +1 -0
- package/dist/actions/reorder/reorder.js +245 -0
- package/dist/actions/reorder/reorder.js.map +1 -0
- package/dist/actions/resize/action.js +105 -0
- package/dist/actions/resize/action.js.map +1 -0
- package/dist/actions/resize/aspect.js +42 -0
- package/dist/actions/resize/aspect.js.map +1 -0
- package/dist/actions/resize/behaviors/clampMinSize.js +100 -0
- package/dist/actions/resize/behaviors/clampMinSize.js.map +1 -0
- package/dist/actions/resize/boxFrame.js +19 -0
- package/dist/actions/resize/boxFrame.js.map +1 -0
- package/dist/actions/resize/capture.js +121 -0
- package/dist/actions/resize/capture.js.map +1 -0
- package/dist/actions/resize/commit.js +104 -0
- package/dist/actions/resize/commit.js.map +1 -0
- package/dist/actions/resize/frame.js +171 -0
- package/dist/actions/resize/frame.js.map +1 -0
- package/dist/actions/resize/held.js +44 -0
- package/dist/actions/resize/held.js.map +1 -0
- package/dist/actions/resize/minimum.js +34 -0
- package/dist/actions/resize/minimum.js.map +1 -0
- package/dist/actions/resize/replay.js +58 -0
- package/dist/actions/resize/replay.js.map +1 -0
- package/dist/actions/resize/ruleBounds.js +11 -0
- package/dist/actions/resize/ruleBounds.js.map +1 -0
- package/dist/actions/resize/session.js +118 -0
- package/dist/actions/resize/session.js.map +1 -0
- package/dist/actions/rotate/action.js +99 -0
- package/dist/actions/rotate/action.js.map +1 -0
- package/dist/actions/rotate/commit.js +48 -0
- package/dist/actions/rotate/commit.js.map +1 -0
- package/dist/actions/rotate/frame.js +96 -0
- package/dist/actions/rotate/frame.js.map +1 -0
- package/dist/actions/rotate/replay.js +25 -0
- package/dist/actions/rotate/replay.js.map +1 -0
- package/dist/actions/rotate/session.js +135 -0
- package/dist/actions/rotate/session.js.map +1 -0
- package/dist/actions/select/areaSelect.js +83 -0
- package/dist/actions/select/areaSelect.js.map +1 -0
- package/dist/actions/select/clearSelection.js +33 -0
- package/dist/actions/select/clearSelection.js.map +1 -0
- package/dist/actions/swap/action.js +63 -0
- package/dist/actions/swap/action.js.map +1 -0
- package/dist/actions/swap/swapOps.js +160 -0
- package/dist/actions/swap/swapOps.js.map +1 -0
- package/dist/actions/transformAgain/action.js +90 -0
- package/dist/actions/transformAgain/action.js.map +1 -0
- package/dist/actions/transformAgain/transformSelection.js +49 -0
- package/dist/actions/transformAgain/transformSelection.js.map +1 -0
- package/dist/booleans/booleans.js +130 -0
- package/dist/booleans/booleans.js.map +1 -0
- package/dist/booleans/commit.js +45 -0
- package/dist/booleans/commit.js.map +1 -0
- package/dist/booleans/custom.js +48 -0
- package/dist/booleans/custom.js.map +1 -0
- package/dist/booleans/operands.js +50 -0
- package/dist/booleans/operands.js.map +1 -0
- package/dist/booleans/pieces.js +43 -0
- package/dist/booleans/pieces.js.map +1 -0
- package/dist/booleans/placement.js +37 -0
- package/dist/booleans/placement.js.map +1 -0
- package/dist/booleans/useBooleans.js +34 -0
- package/dist/booleans/useBooleans.js.map +1 -0
- package/dist/booleans/useBooleansAdapter.js +11 -0
- package/dist/booleans/useBooleansAdapter.js.map +1 -0
- package/dist/chrome/affordances/cornerResize.js +123 -0
- package/dist/chrome/affordances/cornerResize.js.map +1 -0
- package/dist/chrome/affordances/rotateCursor.js +17 -0
- package/dist/chrome/affordances/rotateCursor.js.map +1 -0
- package/dist/chrome/affordances/rotationHandle.js +117 -0
- package/dist/chrome/affordances/rotationHandle.js.map +1 -0
- package/dist/chrome/handleCommands.js +110 -0
- package/dist/chrome/handleCommands.js.map +1 -0
- package/dist/chrome/overlay.js +271 -0
- package/dist/chrome/overlay.js.map +1 -0
- package/dist/chrome/rotationBadge.js +132 -0
- package/dist/chrome/rotationBadge.js.map +1 -0
- package/dist/chrome/rotationHandleGeometry.js +49 -0
- package/dist/chrome/rotationHandleGeometry.js.map +1 -0
- package/dist/chrome/selectionChrome.js +25 -0
- package/dist/chrome/selectionChrome.js.map +1 -0
- package/dist/chrome/selectionPose.js +112 -0
- package/dist/chrome/selectionPose.js.map +1 -0
- package/dist/chrome/shapeOutline.js +137 -0
- package/dist/chrome/shapeOutline.js.map +1 -0
- package/dist/clipboard/clipboardOps.js +48 -0
- package/dist/clipboard/clipboardOps.js.map +1 -0
- package/dist/clipboard/materializePaste.js +34 -0
- package/dist/clipboard/materializePaste.js.map +1 -0
- package/dist/clipboard/osClipboard.js +67 -0
- package/dist/clipboard/osClipboard.js.map +1 -0
- package/dist/clipboard/useClipboard.js +64 -0
- package/dist/clipboard/useClipboard.js.map +1 -0
- package/dist/clipboard/wireFormat.js +108 -0
- package/dist/clipboard/wireFormat.js.map +1 -0
- package/dist/deps/areaSelect.js +42 -0
- package/dist/deps/areaSelect.js.map +1 -0
- package/dist/deps/booleans.js +99 -0
- package/dist/deps/booleans.js.map +1 -0
- package/dist/deps/insert.js +260 -0
- package/dist/deps/insert.js.map +1 -0
- package/dist/deps/lassoSelect.js +37 -0
- package/dist/deps/lassoSelect.js.map +1 -0
- package/dist/deps/presetDeps.js +40 -0
- package/dist/deps/presetDeps.js.map +1 -0
- package/dist/deps/resizePolicy.js +41 -0
- package/dist/deps/resizePolicy.js.map +1 -0
- package/dist/engine-BV9RDHOL.d.ts +339 -0
- package/dist/engine.d.ts +6 -0
- package/dist/engine.js +10 -0
- package/dist/engineStandardActions.js +54 -0
- package/dist/engineStandardActions.js.map +1 -0
- package/dist/groups.d.ts +27 -0
- package/dist/groups.js +4 -0
- package/dist/icons.gen.js +8 -0
- package/dist/icons.gen.js.map +1 -0
- package/dist/icons.table.d.ts +6 -0
- package/dist/icons.table.js +8 -0
- package/dist/icons.table.js.map +1 -0
- package/dist/icons.table.json +156 -0
- package/dist/icons2.table.js +163 -0
- package/dist/icons2.table.js.map +1 -0
- package/dist/index.d.ts +1867 -0
- package/dist/index.js +86 -0
- package/dist/ingest/ghost.js +58 -0
- package/dist/ingest/ghost.js.map +1 -0
- package/dist/ingest/imageHandler.js +80 -0
- package/dist/ingest/imageHandler.js.map +1 -0
- package/dist/ingest/kitHandlers.js +15 -0
- package/dist/ingest/kitHandlers.js.map +1 -0
- package/dist/ingest/svgHandler.js +97 -0
- package/dist/ingest/svgHandler.js.map +1 -0
- package/dist/ingest/weaselJsonHandler.js +68 -0
- package/dist/ingest/weaselJsonHandler.js.map +1 -0
- package/dist/namedPresets.js +83 -0
- package/dist/namedPresets.js.map +1 -0
- package/dist/presets/arrange.js +65 -0
- package/dist/presets/arrange.js.map +1 -0
- package/dist/presets/booleans.js +13 -0
- package/dist/presets/booleans.js.map +1 -0
- package/dist/presets/composites.js +46 -0
- package/dist/presets/composites.js.map +1 -0
- package/dist/presets/edit.js +125 -0
- package/dist/presets/edit.js.map +1 -0
- package/dist/presets/ingest.js +17 -0
- package/dist/presets/ingest.js.map +1 -0
- package/dist/presets/insert.js +28 -0
- package/dist/presets/insert.js.map +1 -0
- package/dist/presets/pathfinder.js +26 -0
- package/dist/presets/pathfinder.js.map +1 -0
- package/dist/presets/select.js +31 -0
- package/dist/presets/select.js.map +1 -0
- package/dist/presets/selection.js +13 -0
- package/dist/presets/selection.js.map +1 -0
- package/dist/presets/selectionChrome.js +15 -0
- package/dist/presets/selectionChrome.js.map +1 -0
- package/dist/presets/tools.js +84 -0
- package/dist/presets/tools.js.map +1 -0
- package/dist/presets/transform.js +52 -0
- package/dist/presets/transform.js.map +1 -0
- package/dist/presets.d.ts +104 -0
- package/dist/presets.js +15 -0
- package/dist/selection/useSelection.js +127 -0
- package/dist/selection/useSelection.js.map +1 -0
- package/dist/test-seams.d.ts +50 -0
- package/dist/test-seams.js +4 -0
- package/dist/tools/ellipse/useEllipseTool.js +72 -0
- package/dist/tools/ellipse/useEllipseTool.js.map +1 -0
- package/dist/tools/eyedropper/useEyedropperTool.js +100 -0
- package/dist/tools/eyedropper/useEyedropperTool.js.map +1 -0
- package/dist/tools/image/useImageTool.js +57 -0
- package/dist/tools/image/useImageTool.js.map +1 -0
- package/dist/tools/lasso/useLassoTool.js +96 -0
- package/dist/tools/lasso/useLassoTool.js.map +1 -0
- package/dist/tools/line/useLineTool.js +67 -0
- package/dist/tools/line/useLineTool.js.map +1 -0
- package/dist/tools/polygon/usePolygonTool.js +149 -0
- package/dist/tools/polygon/usePolygonTool.js.map +1 -0
- package/dist/tools/rect/useRectTool.js +74 -0
- package/dist/tools/rect/useRectTool.js.map +1 -0
- package/dist/tools/select/adapterPointQuery.js +56 -0
- package/dist/tools/select/adapterPointQuery.js.map +1 -0
- package/dist/tools/select/collapseDeferred.js +35 -0
- package/dist/tools/select/collapseDeferred.js.map +1 -0
- package/dist/tools/select/extendPressLocked.js +17 -0
- package/dist/tools/select/extendPressLocked.js.map +1 -0
- package/dist/tools/select/groupEntry.js +73 -0
- package/dist/tools/select/groupEntry.js.map +1 -0
- package/dist/tools/select/pressDecision.js +39 -0
- package/dist/tools/select/pressDecision.js.map +1 -0
- package/dist/tools/select/selectDeep.js +39 -0
- package/dist/tools/select/selectDeep.js.map +1 -0
- package/dist/tools/select/selectPick.js +60 -0
- package/dist/tools/select/selectPick.js.map +1 -0
- package/dist/tools/select/selectionContributions.js +191 -0
- package/dist/tools/select/selectionContributions.js.map +1 -0
- package/dist/tools/select/usePickerSelectTool.js +145 -0
- package/dist/tools/select/usePickerSelectTool.js.map +1 -0
- package/dist/tools/select/useSelectTool.js +54 -0
- package/dist/tools/select/useSelectTool.js.map +1 -0
- package/dist/tools/shared/countOption.js +24 -0
- package/dist/tools/shared/countOption.js.map +1 -0
- package/dist/tools/shared/insertToolOptions.js +8 -0
- package/dist/tools/shared/insertToolOptions.js.map +1 -0
- package/dist/tools/shared/pointerFollower.js +23 -0
- package/dist/tools/shared/pointerFollower.js.map +1 -0
- package/dist/tools/shared/styleOptions.js +76 -0
- package/dist/tools/shared/styleOptions.js.map +1 -0
- package/dist/tools/star/useStarTool.js +149 -0
- package/dist/tools/star/useStarTool.js.map +1 -0
- package/dist/tools/toolSets.js +26 -0
- package/dist/tools/toolSets.js.map +1 -0
- package/dist/useStandardActions.js +26 -0
- package/dist/useStandardActions.js.map +1 -0
- package/package.json +87 -4
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
import { composeSelectionPose, containerAwareBoundsResolver } from "./selectionPose.js";
|
|
2
|
+
import { DEFAULT_ROTATION_HANDLE_DISTANCE, targetCanRotate } from "./rotationHandleGeometry.js";
|
|
3
|
+
import { rotationHandleCommands } from "./rotationBadge.js";
|
|
4
|
+
import { createShapeOutliner, shapeOutlineCommands, viewScaleOf } from "./shapeOutline.js";
|
|
5
|
+
import { handleCommandsFor, rectPathFor, resolveHandles } from "./handleCommands.js";
|
|
6
|
+
import { MULTI_RESIZE_TARGET_ID, effectivePoseFrom, previewPoseIn, previewSourcesFrom, targetCorners, targetTransformOf } from "@weasel-js/core";
|
|
7
|
+
import { resolveScreenLength } from "@weasel-js/paint";
|
|
8
|
+
import { AUTO_POSE_DESCRIPTOR, viewToTransform, worldToScreen } from "@weasel-js/core/engine";
|
|
9
|
+
import { PATH_L, PATH_M, PATH_Z } from "@weasel-js/geom";
|
|
10
|
+
|
|
11
|
+
// src/chrome/overlay.ts
|
|
12
|
+
/** Project world AABB into screen-space AABB using the active view. */
|
|
13
|
+
function projectBounds(b, view) {
|
|
14
|
+
const t = viewToTransform(view);
|
|
15
|
+
const [sx, sy] = worldToScreen(b.x, b.y, t);
|
|
16
|
+
const [w, h] = [b.width * view.scale.x, b.height * view.scale.y];
|
|
17
|
+
return {
|
|
18
|
+
...b,
|
|
19
|
+
x: Math.min(sx, sx + w),
|
|
20
|
+
y: Math.min(sy, sy + h),
|
|
21
|
+
width: Math.abs(w),
|
|
22
|
+
height: Math.abs(h)
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
var DEFAULT_OUTLINE = {
|
|
26
|
+
paint: {
|
|
27
|
+
kind: "solid",
|
|
28
|
+
color: "#f0e0a8"
|
|
29
|
+
},
|
|
30
|
+
width: 2,
|
|
31
|
+
pad: 1
|
|
32
|
+
};
|
|
33
|
+
function resolveOutlineStroke(opts) {
|
|
34
|
+
const { pad, follow: _follow, ...rest } = opts ?? {};
|
|
35
|
+
return {
|
|
36
|
+
stroke: {
|
|
37
|
+
...rest,
|
|
38
|
+
paint: rest.paint ?? DEFAULT_OUTLINE.paint,
|
|
39
|
+
width: rest.width ?? DEFAULT_OUTLINE.width
|
|
40
|
+
},
|
|
41
|
+
pad: pad ?? DEFAULT_OUTLINE.pad
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
/** GL helper: emit an outline command for one bounds entry. */
|
|
45
|
+
function outlineCommandsFor(ids, resolveBounds, stroke, pad, view) {
|
|
46
|
+
const out = [];
|
|
47
|
+
const align = stroke.align ?? "center";
|
|
48
|
+
const width = resolveScreenLength(stroke.width ?? 1, 1);
|
|
49
|
+
for (const id of ids) {
|
|
50
|
+
const worldB = resolveBounds(id);
|
|
51
|
+
if (!worldB) continue;
|
|
52
|
+
const b = projectBounds(worldB, view);
|
|
53
|
+
const padded = {
|
|
54
|
+
x: b.x - pad,
|
|
55
|
+
y: b.y - pad,
|
|
56
|
+
width: b.width + pad * 2,
|
|
57
|
+
height: b.height + pad * 2
|
|
58
|
+
};
|
|
59
|
+
const xf = targetTransformOf(worldB);
|
|
60
|
+
if (xf.identity) {
|
|
61
|
+
out.push({
|
|
62
|
+
kind: "path",
|
|
63
|
+
path: rectPathFor(padded.x, padded.y, padded.width, padded.height),
|
|
64
|
+
stroke
|
|
65
|
+
});
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
const q = screenCorners(worldB, xf, view, pad + (align === "outer" ? width / 2 : align === "inner" ? -width / 2 : 0));
|
|
69
|
+
out.push({
|
|
70
|
+
kind: "path",
|
|
71
|
+
path: {
|
|
72
|
+
kind: "polygon",
|
|
73
|
+
commands: new Uint8Array([
|
|
74
|
+
PATH_M,
|
|
75
|
+
PATH_L,
|
|
76
|
+
PATH_L,
|
|
77
|
+
PATH_L,
|
|
78
|
+
PATH_Z
|
|
79
|
+
]),
|
|
80
|
+
coords: new Float32Array([
|
|
81
|
+
q[0].x,
|
|
82
|
+
q[0].y,
|
|
83
|
+
q[1].x,
|
|
84
|
+
q[1].y,
|
|
85
|
+
q[2].x,
|
|
86
|
+
q[2].y,
|
|
87
|
+
q[3].x,
|
|
88
|
+
q[3].y
|
|
89
|
+
]),
|
|
90
|
+
fillRule: "nonzero"
|
|
91
|
+
},
|
|
92
|
+
stroke: {
|
|
93
|
+
...stroke,
|
|
94
|
+
align: "center"
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
return out;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* A framed target's corners on screen, TL/TR/BR/BL, each pushed `pad` screen
|
|
102
|
+
* pixels out from both edges that meet there.
|
|
103
|
+
*/
|
|
104
|
+
function screenCorners(worldB, xf, view, pad) {
|
|
105
|
+
const t = viewToTransform(view);
|
|
106
|
+
const q = targetCorners(worldB, xf).map((w) => {
|
|
107
|
+
const [x, y] = worldToScreen(w.x, w.y, t);
|
|
108
|
+
return {
|
|
109
|
+
x,
|
|
110
|
+
y
|
|
111
|
+
};
|
|
112
|
+
});
|
|
113
|
+
if (pad === 0) return q;
|
|
114
|
+
const [ccx, ccy] = worldToScreen(worldB.x + worldB.width / 2, worldB.y + worldB.height / 2, t);
|
|
115
|
+
const normal = (a, b) => {
|
|
116
|
+
let nx = -(b.y - a.y), ny = b.x - a.x;
|
|
117
|
+
const l = Math.hypot(nx, ny) || 1;
|
|
118
|
+
nx /= l;
|
|
119
|
+
ny /= l;
|
|
120
|
+
const mx = (a.x + b.x) / 2 - ccx, my = (a.y + b.y) / 2 - ccy;
|
|
121
|
+
return nx * mx + ny * my < 0 ? {
|
|
122
|
+
x: -nx,
|
|
123
|
+
y: -ny
|
|
124
|
+
} : {
|
|
125
|
+
x: nx,
|
|
126
|
+
y: ny
|
|
127
|
+
};
|
|
128
|
+
};
|
|
129
|
+
return q.map((c, i) => {
|
|
130
|
+
const n1 = normal(q[(i + 3) % 4], c);
|
|
131
|
+
const n2 = normal(c, q[(i + 1) % 4]);
|
|
132
|
+
const k = pad / (1 + n1.x * n2.x + n1.y * n2.y);
|
|
133
|
+
return {
|
|
134
|
+
x: c.x + (n1.x + n2.x) * k,
|
|
135
|
+
y: c.y + (n1.y + n2.y) * k
|
|
136
|
+
};
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
function buildSelectionLayer(opts, passes) {
|
|
140
|
+
const { stroke, pad } = resolveOutlineStroke(opts.outline);
|
|
141
|
+
const handles = passes.handles && opts.handles !== false ? resolveHandles(opts.handles || void 0) : null;
|
|
142
|
+
const { handlesOf, resizeHandles } = opts;
|
|
143
|
+
const d = opts.poseDescriptor ?? AUTO_POSE_DESCRIPTOR;
|
|
144
|
+
const getPose = opts.getPose;
|
|
145
|
+
const poseBounds = getPose ? containerAwareBoundsResolver(getPose, d, opts.getChildren, opts.isContainer, opts.scene) : null;
|
|
146
|
+
const shapeOutliner = opts.outline?.follow === "shape" && opts.scene ? createShapeOutliner() : null;
|
|
147
|
+
const rotationHandleDistance = passes.handles ? rotationBadgeOf(opts)?.distancePx ?? null : null;
|
|
148
|
+
return {
|
|
149
|
+
id: passes.id,
|
|
150
|
+
label: passes.label,
|
|
151
|
+
space: "screen",
|
|
152
|
+
draw: (data, view) => {
|
|
153
|
+
const chromeState = asChromeState(data);
|
|
154
|
+
const allIds = opts.getSelection ? opts.getSelection() : chromeSelectionIds(chromeState);
|
|
155
|
+
if (allIds.length === 0) return [];
|
|
156
|
+
const suppressed = opts.getSuppressedIds?.();
|
|
157
|
+
const ids = suppressed && suppressed.size > 0 ? allIds.filter((id) => !suppressed.has(id)) : allIds;
|
|
158
|
+
if (ids.length === 0) return [];
|
|
159
|
+
const isVisible = asIsVisible(data);
|
|
160
|
+
const showOutline = passes.outline && (isVisible ? isVisible("selection.outline") : true);
|
|
161
|
+
const showHandles = isVisible ? isVisible("selection.resize-handles") : true;
|
|
162
|
+
const showRotation = isVisible ? isVisible("selection.rotation-handle") : true;
|
|
163
|
+
const resolveBounds = poseBounds ? (id) => poseBounds(id, view.scale) : (id) => chromeState?.boundsOf(id) ?? null;
|
|
164
|
+
const resolveTargetBounds = (id) => {
|
|
165
|
+
if (id === MULTI_RESIZE_TARGET_ID && chromeState?.unionBounds != null) return chromeState.unionBounds;
|
|
166
|
+
return resolveBounds(id);
|
|
167
|
+
};
|
|
168
|
+
const out = [];
|
|
169
|
+
if (showOutline) {
|
|
170
|
+
const outlineIdsRaw = opts.getOutlineIds ? opts.getOutlineIds() : opts.getSelection ? ids : chromeState?.selection ?? ids;
|
|
171
|
+
let boxed = suppressed && suppressed.size > 0 ? outlineIdsRaw.filter((id) => !suppressed.has(id)) : outlineIdsRaw;
|
|
172
|
+
if (shapeOutliner && opts.scene) {
|
|
173
|
+
const previews = previewSourcesFrom(data);
|
|
174
|
+
const traced = shapeOutliner.outline(boxed, {
|
|
175
|
+
scene: opts.scene,
|
|
176
|
+
poseOf: (id) => effectivePoseFrom(data, id) ?? getPose?.(id) ?? opts.scene.get(id)?.pose,
|
|
177
|
+
inFlight: (id) => previewPoseIn(previews, id) != null
|
|
178
|
+
}, viewScaleOf(view));
|
|
179
|
+
for (const cmd of shapeOutlineCommands(traced.paths, stroke, view)) out.push(cmd);
|
|
180
|
+
boxed = traced.boxed;
|
|
181
|
+
}
|
|
182
|
+
for (const cmd of outlineCommandsFor(boxed, resolveTargetBounds, stroke, pad, view)) out.push(cmd);
|
|
183
|
+
}
|
|
184
|
+
if (!handles) return out;
|
|
185
|
+
if (showHandles) for (const cmd of handleCommandsFor(ids, resolveTargetBounds, handles, handlesOf, resizeHandles, view)) out.push(cmd);
|
|
186
|
+
if (showRotation && rotationHandleDistance !== null) for (const id of ids) {
|
|
187
|
+
if (!targetCanRotate(chromeState, id)) continue;
|
|
188
|
+
const b = resolveTargetBounds(id);
|
|
189
|
+
if (!b) continue;
|
|
190
|
+
for (const cmd of rotationHandleCommands(b, handles, rotationHandleDistance, view)) out.push(cmd);
|
|
191
|
+
}
|
|
192
|
+
return out;
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
/** Where the overlay paints its rotate badge and how big it is, in screen
|
|
197
|
+
* pixels, or `null` when it paints none. The badge's grab region and its
|
|
198
|
+
* slops halo read this too, so all three agree on it. */
|
|
199
|
+
function rotationBadgeOf(opts) {
|
|
200
|
+
const r = opts.rotationHandle;
|
|
201
|
+
if (!r || opts.handles === false) return null;
|
|
202
|
+
return {
|
|
203
|
+
distancePx: r === true ? DEFAULT_ROTATION_HANDLE_DISTANCE : r.distance ?? DEFAULT_ROTATION_HANDLE_DISTANCE,
|
|
204
|
+
sizePx: resolveHandles(opts.handles || void 0).size
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* `RenderLayer` that draws selection outlines only. Stack alongside
|
|
209
|
+
* `createSelectionHandlesLayer` (or use `createSelectionOverlayLayer`, which
|
|
210
|
+
* runs both passes in one layer) when both are wanted.
|
|
211
|
+
*/
|
|
212
|
+
function createSelectionOutlineLayer(opts) {
|
|
213
|
+
return buildSelectionLayer(opts, {
|
|
214
|
+
id: "selection-outline",
|
|
215
|
+
label: "Selection outline",
|
|
216
|
+
outline: true,
|
|
217
|
+
handles: false
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* `RenderLayer` that draws selection handles only. Stack on top of
|
|
222
|
+
* `createSelectionOutlineLayer` (handles render on top of the outline).
|
|
223
|
+
*/
|
|
224
|
+
function createSelectionHandlesLayer(opts) {
|
|
225
|
+
return buildSelectionLayer(opts, {
|
|
226
|
+
id: "selection-handles",
|
|
227
|
+
label: "Selection handles",
|
|
228
|
+
outline: false,
|
|
229
|
+
handles: true
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Draws outlines then handles in a single layer. Exactly equivalent to
|
|
234
|
+
* stacking `createSelectionOutlineLayer` and `createSelectionHandlesLayer` —
|
|
235
|
+
* all three run the same body. Pass `handles: false` to render outlines only.
|
|
236
|
+
*/
|
|
237
|
+
function createSelectionOverlayLayer(opts) {
|
|
238
|
+
return buildSelectionLayer(opts, {
|
|
239
|
+
id: "selection-overlay",
|
|
240
|
+
label: "Selection",
|
|
241
|
+
outline: true,
|
|
242
|
+
handles: true
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
/** Pull a chrome-caps visibility predicate off the draw `data` envelope.
|
|
246
|
+
* Returns `null` when the caller passed bare data (no `getIsVisible`
|
|
247
|
+
* thunk) — the layer then renders unconditionally. */
|
|
248
|
+
function asIsVisible(data) {
|
|
249
|
+
const maybe = data;
|
|
250
|
+
if (typeof maybe?.getIsVisible === "function") return maybe.getIsVisible();
|
|
251
|
+
return null;
|
|
252
|
+
}
|
|
253
|
+
/** The ids the handle pass works against when the layer takes its selection
|
|
254
|
+
* from the envelope: the synthetic union id for a multi-selection, the
|
|
255
|
+
* selection itself otherwise. */
|
|
256
|
+
function chromeSelectionIds(state) {
|
|
257
|
+
if (!state) return [];
|
|
258
|
+
if (state.multiActive) return [MULTI_RESIZE_TARGET_ID];
|
|
259
|
+
return state.selection;
|
|
260
|
+
}
|
|
261
|
+
/** Pull live `ChromeState` off the draw `data` envelope. Returns `null` for
|
|
262
|
+
* callers that pass plain data with no `getChromeState` thunk — the layer
|
|
263
|
+
* then resolves the multi-union via the supplied `getPose` resolver. */
|
|
264
|
+
function asChromeState(data) {
|
|
265
|
+
const maybe = data;
|
|
266
|
+
if (typeof maybe?.getChromeState === "function") return maybe.getChromeState();
|
|
267
|
+
return null;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
export { composeSelectionPose, createSelectionHandlesLayer, createSelectionOutlineLayer, createSelectionOverlayLayer, rotationBadgeOf };
|
|
271
|
+
//# sourceMappingURL=overlay.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"overlay.js","names":[],"sources":["../../src/chrome/overlay.ts"],"sourcesContent":["/**\n * Selection overlay primitives — render layers for drawing selection\n * outlines and resize handles.\n *\n * **Pose shape:** TPose is generic; callers pass `poseDescriptor` for poses\n * `AUTO_POSE_DESCRIPTOR` can't read. Container ids reduce via `unionAabb`\n * over the projected AABBs.\n */\n\nimport type { DrawCommand } from '@weasel-js/renderer';\nimport { resolveScreenLength } from '@weasel-js/paint';\nimport type {\n SelectionHandlesLayerOptions, SelectionOutlineLayerOptions, SelectionOverlayLayerOptions,\n} from '@weasel-js/core';\nimport type { NodeId } from '@weasel-js/core';\nimport type { RenderLayer } from '@weasel-js/core';\nimport type { PoseDescriptor } from '@weasel-js/core/engine';\nimport { containerAwareBoundsResolver } from './selectionPose';\nimport { targetCorners, targetTransformOf, type TargetTransform } from '@weasel-js/core';\nimport { AUTO_POSE_DESCRIPTOR } from '@weasel-js/core/engine';\nimport type { CommandStroke } from '@weasel-js/paint';\nimport { DEFAULT_ROTATION_HANDLE_DISTANCE, targetCanRotate } from './rotationHandleGeometry';\nimport type { Bounds } from '@weasel-js/core';\nimport type { ChromeState } from '@weasel-js/core';\nimport { MULTI_RESIZE_TARGET_ID } from '@weasel-js/core';\nimport type { View } from '@weasel-js/core';\nimport { viewToTransform } from '@weasel-js/core/engine';\nimport { worldToScreen } from '@weasel-js/core/engine';\nimport { PATH_L, PATH_M, PATH_Z } from '@weasel-js/geom';\nimport { effectivePoseFrom, previewPoseIn, previewSourcesFrom } from '@weasel-js/core';\nimport { rotationHandleCommands } from './rotationBadge';\nimport { createShapeOutliner, shapeOutlineCommands, viewScaleOf } from './shapeOutline';\nimport {\n handleCommandsFor, rectPathFor, resolveHandles,\n} from './handleCommands';\n\nexport { composeSelectionPose, type ComposeSelectionPoseOptions } from './selectionPose';\n\n/** Project world AABB into screen-space AABB using the active view. */\nfunction projectBounds<B extends Bounds>(b: B, view: View): B {\n const t = viewToTransform(view);\n const [sx, sy] = worldToScreen(b.x, b.y, t);\n const [w, h] = [b.width * view.scale.x, b.height * view.scale.y];\n return { ...b, x: Math.min(sx, sx + w), y: Math.min(sy, sy + h), width: Math.abs(w), height: Math.abs(h) };\n}\n\nconst DEFAULT_OUTLINE: Required<Pick<CommandStroke, 'paint' | 'width'>> & { pad: number } = {\n paint: { kind: 'solid', color: '#f0e0a8' },\n width: 2,\n pad: 1,\n};\nfunction resolveOutlineStroke(opts?: CommandStroke & { pad?: number; follow?: unknown }): {\n stroke: CommandStroke;\n pad: number;\n} {\n // Everything the consumer set on the stroke reaches the renderer; only the\n // paint and width take a default, and the layer's own `pad` / `follow` stay out.\n const { pad, follow: _follow, ...rest } = opts ?? {};\n return {\n stroke: {\n ...rest,\n paint: rest.paint ?? DEFAULT_OUTLINE.paint,\n width: rest.width ?? DEFAULT_OUTLINE.width,\n },\n pad: pad ?? DEFAULT_OUTLINE.pad,\n };\n}\n\n/** GL helper: emit an outline command for one bounds entry. */\nfunction outlineCommandsFor(\n ids: readonly string[],\n resolveBounds: (id: string) => Bounds | null,\n stroke: CommandStroke,\n pad: number,\n view: View,\n): DrawCommand[] {\n const out: DrawCommand[] = [];\n const align = stroke.align ?? 'center';\n const width = resolveScreenLength(stroke.width ?? 1, 1);\n for (const id of ids) {\n const worldB = resolveBounds(id);\n if (!worldB) continue;\n const b = projectBounds(worldB, view);\n const padded = {\n x: b.x - pad,\n y: b.y - pad,\n width: b.width + pad * 2,\n height: b.height + pad * 2,\n };\n const xf = targetTransformOf(worldB);\n if (xf.identity) {\n // Upright, the renderer aligns the stroke on the rect itself.\n out.push({ kind: 'path', path: rectPathFor(padded.x, padded.y, padded.width, padded.height), stroke });\n continue;\n }\n // Turned or skewed, the target lands on screen as a parallelogram, so the\n // outline is traced through its projected corners, with the alignment's\n // half-width shift folded into the offset.\n const shift = align === 'outer' ? width / 2 : align === 'inner' ? -width / 2 : 0;\n const q = screenCorners(worldB, xf, view, pad + shift);\n out.push({\n kind: 'path',\n path: {\n kind: 'polygon',\n commands: new Uint8Array([PATH_M, PATH_L, PATH_L, PATH_L, PATH_Z]),\n coords: new Float32Array([q[0].x, q[0].y, q[1].x, q[1].y, q[2].x, q[2].y, q[3].x, q[3].y]),\n fillRule: 'nonzero',\n },\n stroke: { ...stroke, align: 'center' },\n });\n }\n return out;\n}\n\n/**\n * A framed target's corners on screen, TL/TR/BR/BL, each pushed `pad` screen\n * pixels out from both edges that meet there.\n */\nfunction screenCorners(\n worldB: Bounds,\n xf: TargetTransform,\n view: View,\n pad: number,\n): { x: number; y: number }[] {\n const t = viewToTransform(view);\n const q = targetCorners(worldB, xf).map((w) => {\n const [x, y] = worldToScreen(w.x, w.y, t);\n return { x, y };\n });\n if (pad === 0) return q;\n const [ccx, ccy] = worldToScreen(worldB.x + worldB.width / 2, worldB.y + worldB.height / 2, t);\n const normal = (a: { x: number; y: number }, b: { x: number; y: number }) => {\n let nx = -(b.y - a.y), ny = b.x - a.x;\n const l = Math.hypot(nx, ny) || 1;\n nx /= l; ny /= l;\n const mx = (a.x + b.x) / 2 - ccx, my = (a.y + b.y) / 2 - ccy;\n return nx * mx + ny * my < 0 ? { x: -nx, y: -ny } : { x: nx, y: ny };\n };\n return q.map((c, i) => {\n const n1 = normal(q[(i + 3) % 4], c);\n const n2 = normal(c, q[(i + 1) % 4]);\n // The point `pad` off both edge lines.\n const k = pad / (1 + n1.x * n2.x + n1.y * n2.y);\n return { x: c.x + (n1.x + n2.x) * k, y: c.y + (n1.y + n2.y) * k };\n });\n}\n\n/** Which passes a selection layer runs. The three exported factories differ\n * only in this — everything else they do is shared, so a fix to one is a fix\n * to all three. */\ninterface SelectionPasses {\n readonly id: string;\n readonly label: string;\n readonly outline: boolean;\n readonly handles: boolean;\n}\n\nfunction buildSelectionLayer<TPose>(\n opts: SelectionOverlayLayerOptions<TPose>,\n passes: SelectionPasses,\n): RenderLayer<unknown> {\n const { stroke, pad } = resolveOutlineStroke(opts.outline);\n const handlesEnabled = passes.handles && opts.handles !== false;\n const handles = handlesEnabled ? resolveHandles(opts.handles || undefined) : null;\n const { handlesOf, resizeHandles } = opts;\n const d = (opts.poseDescriptor ?? AUTO_POSE_DESCRIPTOR) as PoseDescriptor<TPose>;\n const getPose = opts.getPose;\n const poseBounds = getPose\n ? containerAwareBoundsResolver(getPose, d, opts.getChildren, opts.isContainer, opts.scene)\n : null;\n const shapeOutliner = opts.outline?.follow === 'shape' && opts.scene ? createShapeOutliner() : null;\n const rotationHandleDistance = passes.handles\n ? rotationBadgeOf(opts)?.distancePx ?? null\n : null;\n\n return {\n id: passes.id,\n label: passes.label,\n space: 'screen',\n draw: (data, view) => {\n // The synthetic multi-resize id resolves to `ChromeState.unionBounds`,\n // the same value the affordance hit-tester reads, so painted chrome\n // and its hit region stay in agreement. With no chromeState on the\n // draw envelope, fall through to the supplied resolver.\n const chromeState = asChromeState(data);\n const allIds = opts.getSelection\n ? opts.getSelection()\n : chromeSelectionIds(chromeState);\n if (allIds.length === 0) return [];\n const suppressed = opts.getSuppressedIds?.();\n const ids = suppressed && suppressed.size > 0\n ? allIds.filter((id) => !suppressed.has(id as unknown as string))\n : allIds;\n if (ids.length === 0) return [];\n // Chrome-caps: gate each pass on its canonical id. When no\n // `getIsVisible` is wired, every pass runs.\n const isVisible = asIsVisible(data);\n const showOutline = passes.outline && (isVisible ? isVisible('selection.outline') : true);\n const showHandles = isVisible ? isVisible('selection.resize-handles') : true;\n const showRotation = isVisible ? isVisible('selection.rotation-handle') : true;\n\n const resolveBounds = poseBounds\n ? (id: string) => poseBounds(id, view.scale)\n : (id: string) => chromeState?.boundsOf(id) ?? null;\n const resolveTargetBounds = (id: string): Bounds | null => {\n if (id === MULTI_RESIZE_TARGET_ID && chromeState?.unionBounds != null) {\n return chromeState.unionBounds;\n }\n return resolveBounds(id);\n };\n\n const out: DrawCommand[] = [];\n if (showOutline) {\n const outlineIdsRaw = opts.getOutlineIds\n ? opts.getOutlineIds()\n : (opts.getSelection ? ids : (chromeState?.selection ?? ids));\n const outlineIds = suppressed && suppressed.size > 0\n ? outlineIdsRaw.filter((id) => !suppressed.has(id as unknown as string))\n : outlineIdsRaw;\n let boxed = outlineIds as readonly string[];\n if (shapeOutliner && opts.scene) {\n const previews = previewSourcesFrom(data);\n const traced = shapeOutliner.outline(boxed, {\n scene: opts.scene,\n poseOf: (id) => effectivePoseFrom(data, id) ?? getPose?.(id as never) ?? opts.scene!.get(id as NodeId)?.pose,\n inFlight: (id) => previewPoseIn(previews, id) != null,\n }, viewScaleOf(view));\n for (const cmd of shapeOutlineCommands(traced.paths, stroke, view)) out.push(cmd);\n boxed = traced.boxed;\n }\n for (const cmd of outlineCommandsFor(boxed, resolveTargetBounds, stroke, pad, view)) out.push(cmd);\n }\n if (!handles) return out;\n if (showHandles) {\n for (const cmd of handleCommandsFor(ids, resolveTargetBounds, handles, handlesOf, resizeHandles, view)) out.push(cmd);\n }\n if (showRotation && rotationHandleDistance !== null) {\n for (const id of ids) {\n // Paint the badge only where the rotate affordance offers its grab region.\n if (!targetCanRotate(chromeState, id)) continue;\n const b = resolveTargetBounds(id);\n if (!b) continue;\n for (const cmd of rotationHandleCommands(b, handles, rotationHandleDistance, view)) {\n out.push(cmd);\n }\n }\n }\n return out;\n },\n };\n}\n\n/** Where the overlay paints its rotate badge and how big it is, in screen\n * pixels, or `null` when it paints none. The badge's grab region and its\n * slops halo read this too, so all three agree on it. */\nexport function rotationBadgeOf(\n opts: Pick<SelectionOverlayLayerOptions<unknown>, 'handles' | 'rotationHandle'>,\n): { distancePx: number; sizePx: number } | null {\n const r = opts.rotationHandle;\n if (!r || opts.handles === false) return null;\n return {\n distancePx: r === true ? DEFAULT_ROTATION_HANDLE_DISTANCE : r.distance ?? DEFAULT_ROTATION_HANDLE_DISTANCE,\n sizePx: resolveHandles(opts.handles || undefined).size,\n };\n}\n/**\n * `RenderLayer` that draws selection outlines only. Stack alongside\n * `createSelectionHandlesLayer` (or use `createSelectionOverlayLayer`, which\n * runs both passes in one layer) when both are wanted.\n */\nexport function createSelectionOutlineLayer<TPose>(\n opts: SelectionOutlineLayerOptions<TPose>,\n): RenderLayer<unknown> {\n return buildSelectionLayer(opts, {\n id: 'selection-outline',\n label: 'Selection outline',\n outline: true,\n handles: false,\n });\n}\n\n/**\n * `RenderLayer` that draws selection handles only. Stack on top of\n * `createSelectionOutlineLayer` (handles render on top of the outline).\n */\nexport function createSelectionHandlesLayer<TPose>(\n opts: SelectionHandlesLayerOptions<TPose>,\n): RenderLayer<unknown> {\n return buildSelectionLayer(opts, {\n id: 'selection-handles',\n label: 'Selection handles',\n outline: false,\n handles: true,\n });\n}\n\n/**\n * Draws outlines then handles in a single layer. Exactly equivalent to\n * stacking `createSelectionOutlineLayer` and `createSelectionHandlesLayer` —\n * all three run the same body. Pass `handles: false` to render outlines only.\n */\nexport function createSelectionOverlayLayer<TPose>(\n opts: SelectionOverlayLayerOptions<TPose>,\n): RenderLayer<unknown> {\n return buildSelectionLayer(opts, {\n id: 'selection-overlay',\n label: 'Selection',\n outline: true,\n handles: true,\n });\n}\n\n/** Pull a chrome-caps visibility predicate off the draw `data` envelope.\n * Returns `null` when the caller passed bare data (no `getIsVisible`\n * thunk) — the layer then renders unconditionally. */\nfunction asIsVisible(data: unknown): ((id: string) => boolean) | null {\n const maybe = data as { getIsVisible?: () => (id: string) => boolean };\n if (typeof maybe?.getIsVisible === 'function') return maybe.getIsVisible();\n return null;\n}\n\n/** The ids the handle pass works against when the layer takes its selection\n * from the envelope: the synthetic union id for a multi-selection, the\n * selection itself otherwise. */\nfunction chromeSelectionIds(state: ChromeState | null): readonly NodeId[] {\n if (!state) return [];\n if (state.multiActive) return [MULTI_RESIZE_TARGET_ID as NodeId];\n return state.selection;\n}\n\n/** Pull live `ChromeState` off the draw `data` envelope. Returns `null` for\n * callers that pass plain data with no `getChromeState` thunk — the layer\n * then resolves the multi-union via the supplied `getPose` resolver. */\nfunction asChromeState(data: unknown): ChromeState | null {\n const maybe = data as { getChromeState?: () => ChromeState };\n if (typeof maybe?.getChromeState === 'function') return maybe.getChromeState();\n return null;\n}\n"],"mappings":";;;;;;;;;;;;AAuCA,SAAS,cAAgC,GAAM,MAAe;CAC5D,MAAM,IAAI,gBAAgB,IAAI;CAC9B,MAAM,CAAC,IAAI,MAAM,cAAc,EAAE,GAAG,EAAE,GAAG,CAAC;CAC1C,MAAM,CAAC,GAAG,KAAK,CAAC,EAAE,QAAQ,KAAK,MAAM,GAAG,EAAE,SAAS,KAAK,MAAM,CAAC;CAC/D,OAAO;EAAE,GAAG;EAAG,GAAG,KAAK,IAAI,IAAI,KAA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
import { resolveScreenLength } from "@weasel-js/paint";
|
|
3
|
+
import { viewToTransform, worldToScreen } from "@weasel-js/core/engine";
|
|
4
|
+
import { PATH_L, PATH_M } from "@weasel-js/geom";
|
|
5
|
+
import { mat3 } from "@weasel-js/renderer";
|
|
6
|
+
|
|
7
|
+
// src/chrome/rotationBadge.ts
|
|
8
|
+
/** GL helper: emit a curved double-headed arrow, the rotate badge above the
|
|
9
|
+
* rect. The arc opens *toward* the object (apex on top, mouth pointing
|
|
10
|
+
* down), with an arrowhead at each endpoint pointing along the tangent. */
|
|
11
|
+
function rotationHandleCommands(worldB, handles, distance, view) {
|
|
12
|
+
const hWorld = rotationHandle(worldB, distance, view.scale);
|
|
13
|
+
const rotation = hWorld.angle;
|
|
14
|
+
const t = viewToTransform(view);
|
|
15
|
+
const [scx, scy] = worldToScreen(hWorld.cx, hWorld.cy, t);
|
|
16
|
+
const size = handles.size;
|
|
17
|
+
const arcRadius = size;
|
|
18
|
+
const ARC_HALF_ANGLE = Math.PI * 240 / 360 / 2;
|
|
19
|
+
const N_SEGS = 18;
|
|
20
|
+
const arcWidth = resolveScreenLength(handles.outline.width ?? 1, 1) * 1.5;
|
|
21
|
+
const stroke = {
|
|
22
|
+
paint: handles.fill.paint,
|
|
23
|
+
width: arcWidth,
|
|
24
|
+
cap: "round",
|
|
25
|
+
join: "round"
|
|
26
|
+
};
|
|
27
|
+
const cmds = [PATH_M];
|
|
28
|
+
const xs = [];
|
|
29
|
+
const ys = [];
|
|
30
|
+
for (let i = 0; i <= N_SEGS; i++) {
|
|
31
|
+
const angle = ARC_HALF_ANGLE - i / N_SEGS * ARC_HALF_ANGLE * 2;
|
|
32
|
+
xs.push(arcRadius * Math.sin(angle));
|
|
33
|
+
ys.push(-arcRadius * Math.cos(angle));
|
|
34
|
+
if (i > 0) cmds.push(PATH_L);
|
|
35
|
+
}
|
|
36
|
+
const arcCoords = [];
|
|
37
|
+
for (let i = 0; i < xs.length; i++) arcCoords.push(xs[i], ys[i]);
|
|
38
|
+
const arcPath = {
|
|
39
|
+
kind: "polygon",
|
|
40
|
+
commands: new Uint8Array(cmds),
|
|
41
|
+
coords: new Float32Array(arcCoords),
|
|
42
|
+
fillRule: "nonzero"
|
|
43
|
+
};
|
|
44
|
+
const headLen = size * .6;
|
|
45
|
+
const headWidth = size * .4;
|
|
46
|
+
const arrowHead = (endX, endY, tx, ty) => {
|
|
47
|
+
const len = Math.hypot(tx, ty) || 1;
|
|
48
|
+
const ux = tx / len;
|
|
49
|
+
const uy = ty / len;
|
|
50
|
+
const px = -uy;
|
|
51
|
+
const py = ux;
|
|
52
|
+
const tipX = endX + ux * headLen;
|
|
53
|
+
const tipY = endY + uy * headLen;
|
|
54
|
+
const baseLeftX = endX + px * (headWidth / 2);
|
|
55
|
+
const baseLeftY = endY + py * (headWidth / 2);
|
|
56
|
+
const baseRightX = endX - px * (headWidth / 2);
|
|
57
|
+
const baseRightY = endY - py * (headWidth / 2);
|
|
58
|
+
return {
|
|
59
|
+
kind: "polygon",
|
|
60
|
+
commands: new Uint8Array([
|
|
61
|
+
PATH_M,
|
|
62
|
+
PATH_L,
|
|
63
|
+
PATH_L,
|
|
64
|
+
PATH_L
|
|
65
|
+
]),
|
|
66
|
+
coords: new Float32Array([
|
|
67
|
+
tipX,
|
|
68
|
+
tipY,
|
|
69
|
+
baseLeftX,
|
|
70
|
+
baseLeftY,
|
|
71
|
+
baseRightX,
|
|
72
|
+
baseRightY,
|
|
73
|
+
tipX,
|
|
74
|
+
tipY
|
|
75
|
+
]),
|
|
76
|
+
fillRule: "nonzero"
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
const angleA = ARC_HALF_ANGLE;
|
|
80
|
+
const endAX = arcRadius * Math.sin(angleA);
|
|
81
|
+
const endAY = -arcRadius * Math.cos(angleA);
|
|
82
|
+
const tangentAX = Math.cos(angleA);
|
|
83
|
+
const tangentAY = Math.sin(angleA);
|
|
84
|
+
const angleB = -ARC_HALF_ANGLE;
|
|
85
|
+
const endBX = arcRadius * Math.sin(angleB);
|
|
86
|
+
const endBY = -arcRadius * Math.cos(angleB);
|
|
87
|
+
const tangentBX = -Math.cos(angleB);
|
|
88
|
+
const tangentBY = -Math.sin(angleB);
|
|
89
|
+
const headA = arrowHead(endAX, endAY, tangentAX, tangentAY);
|
|
90
|
+
const headB = arrowHead(endBX, endBY, tangentBX, tangentBY);
|
|
91
|
+
let transform = mat3.translated(mat3.identity(), scx, scy);
|
|
92
|
+
if (rotation !== 0) {
|
|
93
|
+
const c = Math.cos(rotation);
|
|
94
|
+
const s = Math.sin(rotation);
|
|
95
|
+
const rot = new Float32Array([
|
|
96
|
+
c,
|
|
97
|
+
s,
|
|
98
|
+
0,
|
|
99
|
+
-s,
|
|
100
|
+
c,
|
|
101
|
+
0,
|
|
102
|
+
0,
|
|
103
|
+
0,
|
|
104
|
+
1
|
|
105
|
+
]);
|
|
106
|
+
transform = mat3.multiply(transform, rot);
|
|
107
|
+
}
|
|
108
|
+
return [{
|
|
109
|
+
kind: "group",
|
|
110
|
+
transform,
|
|
111
|
+
children: [
|
|
112
|
+
{
|
|
113
|
+
kind: "path",
|
|
114
|
+
path: arcPath,
|
|
115
|
+
stroke
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
kind: "path",
|
|
119
|
+
path: headA,
|
|
120
|
+
fill: handles.fill
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
kind: "path",
|
|
124
|
+
path: headB,
|
|
125
|
+
fill: handles.fill
|
|
126
|
+
}
|
|
127
|
+
]
|
|
128
|
+
}];
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export { rotationHandleCommands };
|
|
132
|
+
//# sourceMappingURL=rotationBadge.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rotationBadge.js","names":[],"sources":["../../src/chrome/rotationBadge.ts"],"sourcesContent":["import type { DrawCommand } from '@weasel-js/renderer';\nimport { resolveScreenLength } from '@weasel-js/paint';\nimport { mat3, type GlMat3 } from '@weasel-js/renderer';\nimport type { CommandStroke } from '@weasel-js/paint';\nimport { PATH_L, PATH_M, type PolygonPath } from '@weasel-js/geom';\nimport { rotationHandle } from './rotationHandleGeometry';\nimport type { Bounds } from '@weasel-js/core';\nimport type { View } from '@weasel-js/core';\nimport { viewToTransform } from '@weasel-js/core/engine';\nimport { worldToScreen } from '@weasel-js/core/engine';\nimport type { ResolvedHandles } from './handleCommands';\n\n/** GL helper: emit a curved double-headed arrow, the rotate badge above the\n * rect. The arc opens *toward* the object (apex on top, mouth pointing\n * down), with an arrowhead at each endpoint pointing along the tangent. */\nexport function rotationHandleCommands(\n worldB: Bounds,\n handles: ResolvedHandles,\n distance: number,\n view: View,\n): DrawCommand[] {\n const hWorld = rotationHandle(worldB, distance, view.scale);\n const rotation = hWorld.angle;\n const t = viewToTransform(view);\n const [scx, scy] = worldToScreen(hWorld.cx, hWorld.cy, t);\n const size = handles.size;\n const arcRadius = size;\n const ARC_HALF_ANGLE = (Math.PI * 240) / 360 / 2; // 120°\n const N_SEGS = 18;\n const arcWidth = resolveScreenLength(handles.outline.width ?? 1, 1) * 1.5;\n const stroke: CommandStroke = {\n paint: handles.fill.paint,\n width: arcWidth,\n cap: 'round',\n join: 'round',\n };\n // The arc as a polyline in handle-local coords, centered on the handle\n // anchor: apex at -y, endpoints at +y near the rect side.\n const cmds: number[] = [PATH_M];\n const xs: number[] = [];\n const ys: number[] = [];\n for (let i = 0; i <= N_SEGS; i++) {\n const t = i / N_SEGS;\n const angle = ARC_HALF_ANGLE - t * ARC_HALF_ANGLE * 2;\n xs.push(arcRadius * Math.sin(angle));\n ys.push(-arcRadius * Math.cos(angle));\n if (i > 0) cmds.push(PATH_L);\n }\n const arcCoords: number[] = [];\n for (let i = 0; i < xs.length; i++) {\n arcCoords.push(xs[i], ys[i]);\n }\n const arcPath: PolygonPath = {\n kind: 'polygon',\n commands: new Uint8Array(cmds),\n coords: new Float32Array(arcCoords),\n fillRule: 'nonzero',\n };\n // Arrowheads: small filled triangles at each endpoint, pointing along\n // the tangent (away from the arc body).\n const headLen = size * 0.6;\n const headWidth = size * 0.4;\n const arrowHead = (endX: number, endY: number, tx: number, ty: number): PolygonPath => {\n // Normalize tangent.\n const len = Math.hypot(tx, ty) || 1;\n const ux = tx / len;\n const uy = ty / len;\n // Perpendicular (rotate tangent 90° CCW).\n const px = -uy;\n const py = ux;\n // Triangle: tip is endX+ux*headLen, base is endX (with +/- headWidth/2 along p).\n const tipX = endX + ux * headLen;\n const tipY = endY + uy * headLen;\n const baseLeftX = endX + px * (headWidth / 2);\n const baseLeftY = endY + py * (headWidth / 2);\n const baseRightX = endX - px * (headWidth / 2);\n const baseRightY = endY - py * (headWidth / 2);\n return {\n kind: 'polygon',\n commands: new Uint8Array([PATH_M, PATH_L, PATH_L, PATH_L]),\n coords: new Float32Array([tipX, tipY, baseLeftX, baseLeftY, baseRightX, baseRightY, tipX, tipY]),\n fillRule: 'nonzero',\n };\n };\n // Endpoint A (right side, angle = +ARC_HALF_ANGLE). Arc point:\n // (sin(a)·R, -cos(a)·R). Tangent (d/da) = (cos(a)·R, sin(a)·R).\n const angleA = ARC_HALF_ANGLE;\n const endAX = arcRadius * Math.sin(angleA);\n const endAY = -arcRadius * Math.cos(angleA);\n const tangentAX = Math.cos(angleA);\n const tangentAY = Math.sin(angleA);\n // Endpoint B (left side, angle = -ARC_HALF_ANGLE): tangent in the\n // outward direction is the negation of the above.\n const angleB = -ARC_HALF_ANGLE;\n const endBX = arcRadius * Math.sin(angleB);\n const endBY = -arcRadius * Math.cos(angleB);\n const tangentBX = -Math.cos(angleB);\n const tangentBY = -Math.sin(angleB);\n const headA = arrowHead(endAX, endAY, tangentAX, tangentAY);\n const headB = arrowHead(endBX, endBY, tangentBX, tangentBY);\n // Build transform: translate(scx, scy) [* rotate(rotation)].\n let transform = mat3.translated(mat3.identity(), scx, scy);\n if (rotation !== 0) {\n const c = Math.cos(rotation);\n const s = Math.sin(rotation);\n const rot = new Float32Array([c, s, 0, -s, c, 0, 0, 0, 1]) as GlMat3;\n transform = mat3.multiply(transform, rot);\n }\n return [\n {\n kind: 'group',\n transform,\n children: [\n { kind: 'path', path: arcPath, stroke },\n { kind: 'path', path: headA, fill: handles.fill },\n { kind: 'path', path: headB, fill: handles.fill },\n ],\n },\n ];\n}\n"],"mappings":";;;;;;;;;;AAeA,SAAgB,uBACd,QACA,SACA,UACA,MACe;CACf,MAAM,SAAS,eAAe,QAAQ,UAAU,KAAK,KAAK;CAC1D,MAAM,WAAW,OAAO;CACxB,MAAM,IAAI,gBAAgB,IAAI;CAC9B,MAAM,CAAC,KAAK,OAAO,cAAc,OAAO,IAAI,OAAO,IAAI,CAAC;CACxD,MAAM,OAAO,QAAQ;CACrB,MAAM,YAAY;CAClB,MAAM,iBAAkB,KAAK,KAAK,MAAO,MAAM;CAC/C,MAAM,SAAS;CACf,MAAM,WAAW,oBAAoB,QAAQ,QAAQ,SAAS,GAAG,CAAC,IAAI;CACtE,MAAM,SAAwB;EAC5B,OAAO,QAAQ,KAAK;EACpB,OAAO;EACP,KAAK;EACL,MAAM;CACR;CAGA,MAAM,OAAiB,CAAC,MAAM;CAC9B,MAAM,KAAe,CAAC;CACtB,MAAM,KAAe,CAAC;CACtB,KAAK,IAAI,IAAI,GAAG,KAAK,QAAQ,KAAK;EAEhC,MAAM,QAAQ,iBADJ,IAAI,SACqB,iBAAiB;EACpD,GAAG,KAAK,YAAY,KAAK,IAAI,KAAK,CAAC;EACnC,GAAG,KAAK,CAAC,YAAY,KAAK,IAAI,KAAK,CAAC;EACpC,IAAI,IAAI,GAAG,KAAK,KAAK,MAAM;CAC7B;CACA,MAAM,YAAsB,CAAC;CAC7B,KAAK,IAAI,IAAI,GAAG,IAAI,GAAG,QAAQ,KAC7B,UAAU,KAAK,GAAG,IAAI,GAAG,EAAE;CAE7B,MAAM,UAAuB;EAC3B,MAAM;EACN,UAAU,IAAI,WAAW,IAAI;EAC7B,QAAQ,IAAI,aAAa,SAAS;EAClC,UAAU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KAAK,IAAI,QAAQ;EAC3B,MAAM,IAAI,KAAK,IAAI,QAAQ;EAC3B,MAAM,MAAM,IAAI,aAAa;GAAC;GAAG;GAAG;GAAG,CAAC;GAAG;GAAG;GAAG;GAAG;GAAG;EAAC,CAAC;EACzD,YAAY,KAAK,SAAS,WAAW,GAAG;CAC1C;CACA,OAAO,CACL;EACE,MAAM;EACN;EACA,UAAU;GACR;IAAE,MAAM;IAAQ,MAAM;IAAS;GAAO;GACtC;IAAE,MAAM;IAAQ,MAAM;IAAO,MAAM,QAAQ;GAAK;GAChD;IAAE,MAAM;IAAQ,MAAM;IAAO,MAAM,QAAQ;GAAK;EAClD;CACF,CACF;AACF"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { MULTI_RESIZE_TARGET_ID, ROTATION_HANDLE_BASE_PX, localToWorld, normalToWorld, targetTransformOf } from "@weasel-js/core";
|
|
2
|
+
import { standoff } from "@weasel-js/geom";
|
|
3
|
+
|
|
4
|
+
// src/chrome/rotationHandleGeometry.ts
|
|
5
|
+
/** Default world-space distance from the rect's top edge to the rotation
|
|
6
|
+
* handle's center. Matches the demo's visual default; consumers can
|
|
7
|
+
* override per-call. Unscaled — kit-internal use sites multiply by
|
|
8
|
+
* `DeviceProfile.targetScale`. */
|
|
9
|
+
var DEFAULT_ROTATION_HANDLE_DISTANCE = ROTATION_HANDLE_BASE_PX;
|
|
10
|
+
/** Rotation handle for a box as its frame draws it: `distance` pixels off the
|
|
11
|
+
* top edge's midpoint, along that edge's outward normal as it lands on a
|
|
12
|
+
* screen whose per-axis zoom is `scale`. With no `scale`, a pixel is a world
|
|
13
|
+
* unit. */
|
|
14
|
+
function rotationHandle(pose, distance = DEFAULT_ROTATION_HANDLE_DISTANCE, scale = UNIT_SCALE) {
|
|
15
|
+
const xf = targetTransformOf(pose);
|
|
16
|
+
const top = localToWorld(xf, pose.x + pose.width / 2, pose.y);
|
|
17
|
+
const p = standoff(top, normalToWorld(xf, {
|
|
18
|
+
x: 0,
|
|
19
|
+
y: -1
|
|
20
|
+
}), distance, scale);
|
|
21
|
+
return {
|
|
22
|
+
cx: p.x,
|
|
23
|
+
cy: p.y,
|
|
24
|
+
angle: Math.atan2(p.nx, -p.ny)
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
var UNIT_SCALE = {
|
|
28
|
+
x: 1,
|
|
29
|
+
y: 1
|
|
30
|
+
};
|
|
31
|
+
/** Square hit-test: returns true if `(px, py)` is within `radius` of the
|
|
32
|
+
* handle's center on both axes. Mirrors `hitCornerHandle`. */
|
|
33
|
+
function hitRotationHandle(handle, px, py, radius) {
|
|
34
|
+
return Math.abs(px - handle.cx) <= radius && Math.abs(py - handle.cy) <= radius;
|
|
35
|
+
}
|
|
36
|
+
/** Whether a selection target can take a rotation: a node whose pose carries
|
|
37
|
+
* one, or the synthetic multi id when every selected member can. The rotate
|
|
38
|
+
* ring, its badge's grab region and the painted badge all ask this, so a
|
|
39
|
+
* badge is painted only where it can be grabbed. With no `canRotate` on the
|
|
40
|
+
* state, everything can. */
|
|
41
|
+
function targetCanRotate(state, id) {
|
|
42
|
+
const can = state?.canRotate;
|
|
43
|
+
if (!can) return true;
|
|
44
|
+
if (id === MULTI_RESIZE_TARGET_ID) return state.selection.every((m) => can.call(state, m));
|
|
45
|
+
return can.call(state, id);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export { DEFAULT_ROTATION_HANDLE_DISTANCE, hitRotationHandle, rotationHandle, targetCanRotate };
|
|
49
|
+
//# sourceMappingURL=rotationHandleGeometry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rotationHandleGeometry.js","names":[],"sources":["../../src/chrome/rotationHandleGeometry.ts"],"sourcesContent":["import { localToWorld, normalToWorld, targetTransformOf } from '@weasel-js/core';\nimport { MULTI_RESIZE_TARGET_ID, ROTATION_HANDLE_BASE_PX, type ChromeState } from '@weasel-js/core';\nimport { standoff, type PoseLinear, type Scale2 } from '@weasel-js/geom';\n\n/** Default world-space distance from the rect's top edge to the rotation\n * handle's center. Matches the demo's visual default; consumers can\n * override per-call. Unscaled — kit-internal use sites multiply by\n * `DeviceProfile.targetScale`. */\nexport const DEFAULT_ROTATION_HANDLE_DISTANCE = ROTATION_HANDLE_BASE_PX;\n\n/** Rotation handle position in world coords. */\nexport interface RotationHandle {\n /** Handle center in world coords. */\n cx: number;\n cy: number;\n /** How far the handle is turned on screen, radians: the angle from screen\n * up to the top edge's outward normal as it lands there. Equals the pose\n * rotation under uniform zoom. */\n angle: number;\n}\n\n/** Rotation handle for a box as its frame draws it: `distance` pixels off the\n * top edge's midpoint, along that edge's outward normal as it lands on a\n * screen whose per-axis zoom is `scale`. With no `scale`, a pixel is a world\n * unit. */\nexport function rotationHandle(\n pose: { x: number; y: number; width: number; height: number; rotation?: number; transform?: PoseLinear },\n distance: number = DEFAULT_ROTATION_HANDLE_DISTANCE,\n scale: Scale2 = UNIT_SCALE,\n): RotationHandle {\n const xf = targetTransformOf(pose);\n const top = localToWorld(xf, pose.x + pose.width / 2, pose.y);\n const p = standoff(top, normalToWorld(xf, { x: 0, y: -1 }), distance, scale);\n return { cx: p.x, cy: p.y, angle: Math.atan2(p.nx, -p.ny) };\n}\n\nconst UNIT_SCALE: Scale2 = { x: 1, y: 1 };\n\n/** Square hit-test: returns true if `(px, py)` is within `radius` of the\n * handle's center on both axes. Mirrors `hitCornerHandle`. */\nexport function hitRotationHandle(\n handle: Pick<RotationHandle, 'cx' | 'cy'>,\n px: number,\n py: number,\n radius: number,\n): boolean {\n return Math.abs(px - handle.cx) <= radius && Math.abs(py - handle.cy) <= radius;\n}\n\n/** Whether a selection target can take a rotation: a node whose pose carries\n * one, or the synthetic multi id when every selected member can. The rotate\n * ring, its badge's grab region and the painted badge all ask this, so a\n * badge is painted only where it can be grabbed. With no `canRotate` on the\n * state, everything can. */\nexport function targetCanRotate(\n state: Pick<ChromeState, 'canRotate' | 'selection'> | null,\n id: string,\n): boolean {\n const can = state?.canRotate;\n if (!can) return true;\n if (id === MULTI_RESIZE_TARGET_ID) return state.selection.every((m) => can.call(state, m));\n return can.call(state, id);\n}\n"],"mappings":";;;;;;;;AAQA,IAAa,mCAAmC;;;;;AAiBhD,SAAgB,eACd,MACA,WAAmB,kCACnB,QAAgB,YACA;CAChB,MAAM,KAAK,kBAAkB,IAAI;CACjC,MAAM,MAAM,aAAa,IAAI,KAAK,IAAI,KAAK,QAAQ,GAAG,KAAK,CAAC;CAC5D,MAAM,IAAI,SAAS,KAAK,cAAc,IAAI;EAAE,GAAG;EAAG,GAAG;CAAG,CAAC,GAAG,UAAU,KAAK;CAC3E,OAAO;EAAE,IAAI,EAAE;EAAG,IAAI,EAAE;EAAG,OAAO,KAAK,MAAM,EAAE,IAAI,CAAC,EAAE,EAAE;CAAE;AAC5D;AAEA,IAAM,aAAqB;CAAE,GAAG;CAAG,GAAG;AAAE;;;AAIxC,SAAgB,kBACd,QACA,IACA,IACA,QACS;CACT,OAAO,KAAK,IAAI,KAAK,OAAO,EAAE,KAAK,UAAU,KAAK,IAAI,KAAK,OAAO,EAAE,KAAK;AAC3E;;;;;;AAOA,SAAgB,gBACd,OACA,IACS;CACT,MAAM,MAAM,OAAO;CACnB,IAAI,CAAC,KAAK,OAAO;CACjB,IAAI,OAAO,wBAAwB,OAAO,MAAM,UAAU,OAAO,MAAM,IAAI,KAAK,OAAO,CAAC,CAAC;CACzF,OAAO,IAAI,KAAK,OAAO,EAAE;AAC3B"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { createCornerResizeAffordance } from "./affordances/cornerResize.js";
|
|
2
|
+
import { createRotationAffordance } from "./affordances/rotationHandle.js";
|
|
3
|
+
import { createSelectionOverlayLayer, rotationBadgeOf } from "./overlay.js";
|
|
4
|
+
|
|
5
|
+
// src/chrome/selectionChrome.ts
|
|
6
|
+
/** The kit's selection chrome: the outline, resize handles and rotate badge it paints, and the rotate ring and
|
|
7
|
+
* handles a press grabs, beneath the canvas's anchors. */
|
|
8
|
+
var SELECTION_CHROME = {
|
|
9
|
+
overlay: (options) => createSelectionOverlayLayer(options),
|
|
10
|
+
rotationBadgeOf,
|
|
11
|
+
affordances: ({ handleHitRadius, rotateBandPx, rotationBadge, edgeHandles }) => [createRotationAffordance({
|
|
12
|
+
bandPx: rotateBandPx,
|
|
13
|
+
paint: null,
|
|
14
|
+
...rotationBadge ? { handle: {
|
|
15
|
+
distancePx: rotationBadge.distancePx,
|
|
16
|
+
hitRadiusPx: rotationBadge.sizePx
|
|
17
|
+
} } : {}
|
|
18
|
+
}), createCornerResizeAffordance({
|
|
19
|
+
handleHitRadius,
|
|
20
|
+
edges: edgeHandles
|
|
21
|
+
})]
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export { SELECTION_CHROME };
|
|
25
|
+
//# sourceMappingURL=selectionChrome.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"selectionChrome.js","names":[],"sources":["../../src/chrome/selectionChrome.ts"],"sourcesContent":["import type { SelectionChrome } from '@weasel-js/core';\nimport { createCornerResizeAffordance } from './affordances/cornerResize';\nimport { createRotationAffordance } from './affordances/rotationHandle';\nimport { createSelectionOverlayLayer, rotationBadgeOf } from './overlay';\n\n/** The kit's selection chrome: the outline, resize handles and rotate badge it paints, and the rotate ring and\n * handles a press grabs, beneath the canvas's anchors. */\nexport const SELECTION_CHROME: SelectionChrome = {\n overlay: (options) => createSelectionOverlayLayer(options),\n rotationBadgeOf,\n affordances: ({ handleHitRadius, rotateBandPx, rotationBadge, edgeHandles }) => [\n createRotationAffordance({\n bandPx: rotateBandPx,\n paint: null,\n ...(rotationBadge ? { handle: { distancePx: rotationBadge.distancePx, hitRadiusPx: rotationBadge.sizePx } } : {}),\n }),\n createCornerResizeAffordance({ handleHitRadius, edges: edgeHandles }),\n ],\n};\n"],"mappings":";;;;;;;AAOA,IAAa,mBAAoC;CAC/C,UAAU,YAAY,4BAA4B,OAAO;CACzD;CACA,cAAc,EAAE,iBAAiB,cAAc,eAAe,kBAAkB,CAC9E,yBAAyB;EACvB,QAAQ;EACR,OAAO;EACP,GAAI,gBAAgB,EAAE,QAAQ;GAAE,YAAY,cAAc;GAAY,aAAa,cAAc;EAAO,EAAE,IAAI,CAAC;CACjH,CAAC,GACD,6BAA6B;EAAE;EAAiB,OAAO;CAAY,CAAC,CACtE;AACF"}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { drawnAabbOf, drawnBoundsOf, framedBounds, visualBoundsViaDescriptor } from "@weasel-js/core";
|
|
2
|
+
import { AUTO_POSE_DESCRIPTOR, unionAabb as unionAabb$1 } from "@weasel-js/core/engine";
|
|
3
|
+
|
|
4
|
+
// src/chrome/selectionPose.ts
|
|
5
|
+
/**
|
|
6
|
+
* Transitive leaf ids under `id`. A childless node is a leaf only if it is not
|
|
7
|
+
* itself a container: an empty container contributes no bounds, and its own
|
|
8
|
+
* stored pose is at its most stale when no children are left to have moved it.
|
|
9
|
+
*/
|
|
10
|
+
function leavesOf(id, getChildren, isContainer) {
|
|
11
|
+
if (!isContainer(id)) return [id];
|
|
12
|
+
const out = [];
|
|
13
|
+
const visit = (nid) => {
|
|
14
|
+
const kids = getChildren(nid);
|
|
15
|
+
if (kids.length === 0) {
|
|
16
|
+
if (!isContainer(nid)) out.push(nid);
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
for (const k of kids) visit(k);
|
|
20
|
+
};
|
|
21
|
+
visit(id);
|
|
22
|
+
return out;
|
|
23
|
+
}
|
|
24
|
+
/** How one id's pose becomes a box: the pose box, or with a scene the box the
|
|
25
|
+
* node is drawn with. Each id is read as a leaf — the pose already says where
|
|
26
|
+
* a container is, so its members' stored poses are not consulted again. */
|
|
27
|
+
function boxReader(d, scene) {
|
|
28
|
+
if (!scene) return {
|
|
29
|
+
framed: (_id, pose) => framedBounds(pose, d),
|
|
30
|
+
aabb: (_id, pose) => visualBoundsViaDescriptor(pose, d)
|
|
31
|
+
};
|
|
32
|
+
const leaves = {
|
|
33
|
+
get: (id) => scene.get(id),
|
|
34
|
+
...scene.derivedPathOf ? { derivedPathOf: (id) => scene.derivedPathOf(id) } : {},
|
|
35
|
+
get shapes() {
|
|
36
|
+
return scene.shapes;
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
const opts = (scale) => ({
|
|
40
|
+
descriptor: d,
|
|
41
|
+
...scale !== void 0 ? { scale } : {}
|
|
42
|
+
});
|
|
43
|
+
return {
|
|
44
|
+
framed: (id, pose, scale) => drawnBoundsOf(leaves, id, pose, opts(scale)),
|
|
45
|
+
aabb: (id, pose, scale) => drawnAabbOf(leaves, id, pose, opts(scale))
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Build a pose resolver for a selection. Precedence per id:
|
|
50
|
+
* move overlay > resize overlay > stored. When `getChildren`/`isContainer`
|
|
51
|
+
* are supplied and the id resolves to a container, the resolver returns the
|
|
52
|
+
* union AABB of all transitive leaf poses (each leaf still subject to the
|
|
53
|
+
* precedence rules). Containers with no leaves resolve to `null`.
|
|
54
|
+
*/
|
|
55
|
+
function composeSelectionPose(opts) {
|
|
56
|
+
const { moveOverlay, resizeOverlay, getStoredPose, getChildren, isContainer } = opts;
|
|
57
|
+
const d = opts.poseDescriptor ?? AUTO_POSE_DESCRIPTOR;
|
|
58
|
+
const boxes = boxReader(d, opts.scene);
|
|
59
|
+
const selectionLeaves = (id) => getChildren && isContainer ? leavesOf(id, getChildren, isContainer) : [id];
|
|
60
|
+
const resolveLeaf = (id) => {
|
|
61
|
+
const moved = moveOverlay?.poses.get(id);
|
|
62
|
+
if (moved !== void 0) return moved;
|
|
63
|
+
if (resizeOverlay && resizeOverlay.id === id) return resizeOverlay.currentPose;
|
|
64
|
+
return getStoredPose(id);
|
|
65
|
+
};
|
|
66
|
+
return (id) => {
|
|
67
|
+
if (isContainer?.(id)) {
|
|
68
|
+
const leaves = selectionLeaves(id);
|
|
69
|
+
if (leaves.length === 0) return null;
|
|
70
|
+
const containerResizeLeafPoses = resizeOverlay && resizeOverlay.id === id ? resizeOverlay.leafPoses : void 0;
|
|
71
|
+
const scale = opts.viewScale?.();
|
|
72
|
+
const leafBounds = [];
|
|
73
|
+
for (const leafId of leaves) {
|
|
74
|
+
const pose = moveOverlay?.poses.get(leafId) ?? containerResizeLeafPoses?.get(leafId) ?? resolveLeaf(leafId);
|
|
75
|
+
leafBounds.push(boxes.aabb(leafId, pose, scale));
|
|
76
|
+
}
|
|
77
|
+
const u = unionAabb$1(leafBounds);
|
|
78
|
+
if (u === null) return null;
|
|
79
|
+
return d.fromBounds(u, getStoredPose(leaves[0]));
|
|
80
|
+
}
|
|
81
|
+
return resolveLeaf(id);
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Build a bounds resolver that handles container ids by computing the union
|
|
86
|
+
* AABB of every leaf's bounds. Non-container ids pass through directly. When
|
|
87
|
+
* `getChildren`/`isContainer` are omitted, every id is treated as a leaf.
|
|
88
|
+
* With a scene, each leaf is boxed as drawn at the view's scale.
|
|
89
|
+
*/
|
|
90
|
+
function containerAwareBoundsResolver(getPose, d, getChildren, isContainer, scene) {
|
|
91
|
+
const boxes = boxReader(d, scene);
|
|
92
|
+
const leaf = (id, scale) => {
|
|
93
|
+
const p = getPose(id);
|
|
94
|
+
return p === null ? null : boxes.framed(id, p, scale);
|
|
95
|
+
};
|
|
96
|
+
if (getChildren === void 0 || isContainer === void 0) return leaf;
|
|
97
|
+
return (id, scale) => {
|
|
98
|
+
if (!isContainer(id)) return leaf(id, scale);
|
|
99
|
+
const leaves = leavesOf(id, getChildren, isContainer);
|
|
100
|
+
if (leaves.length === 0) return null;
|
|
101
|
+
const leafBounds = [];
|
|
102
|
+
for (const leafId of leaves) {
|
|
103
|
+
const p = getPose(leafId);
|
|
104
|
+
if (p !== null) leafBounds.push(boxes.aabb(leafId, p, scale));
|
|
105
|
+
}
|
|
106
|
+
if (leafBounds.length === 0) return null;
|
|
107
|
+
return unionAabb$1(leafBounds);
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export { composeSelectionPose, containerAwareBoundsResolver };
|
|
112
|
+
//# sourceMappingURL=selectionPose.js.map
|