-
Notifications
You must be signed in to change notification settings - Fork 137
feat(svg-editor): Shift + side-edge resize aspect-locks about the opposite-edge center #865
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
softmarshmallow
merged 4 commits into
main
from
feat/svg-editor-shift-edge-aspect-resize
Jun 18, 2026
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
ef9927f
feat(svg-editor): Shift + side-edge resize aspect-locks about the opp…
softmarshmallow 4268943
fix(svg-editor): keep text-on-edge a no-op under Shift aspect-lock
softmarshmallow c5d0fcd
fix(hud): clamp aspect preview factors to match core resize floor
softmarshmallow 8276932
feat(hud): draw the aspect-ratio diagonal guide during Shift-resize
softmarshmallow File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
75 changes: 75 additions & 0 deletions
75
packages/grida-canvas-hud/__tests__/apply-resize-aspect.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| // `applyResize` — aspect-lock under `{ aspect: true }` (Shift). A corner takes | ||
| // the max-magnitude axis factor; a side edge drives the perpendicular axis by | ||
| // the same factor about the perpendicular center. This variant drives the | ||
| // dashed resize *preview* so it matches an aspect-locking host (the emitted | ||
| // intent stays opposite-anchored / free — see state.ts). Composes with | ||
| // `fromCenter` (Alt) for uniform-about-center. | ||
|
|
||
| import { describe, it, expect } from "vitest"; | ||
| import { applyResize } from "../event/gesture"; | ||
| import type { SelectionShape } from "../event"; | ||
|
|
||
| function rect(x: number, y: number, w: number, h: number): SelectionShape { | ||
| return { kind: "rect", rect: { x, y, width: w, height: h } }; | ||
| } | ||
| function bbox(s: SelectionShape) { | ||
| if (s.kind !== "rect") throw new Error("expected rect"); | ||
| return s.rect; | ||
| } | ||
| function center(r: { x: number; y: number; width: number; height: number }) { | ||
| return { x: r.x + r.width / 2, y: r.y + r.height / 2 }; | ||
| } | ||
|
|
||
| describe("applyResize — aspect off is unchanged (regression guard)", () => { | ||
| it("e edge stays free (perpendicular unchanged) without aspect", () => { | ||
| expect(bbox(applyResize(rect(0, 0, 100, 50), "e", 20, 0))).toEqual({ | ||
| x: 0, | ||
| y: 0, | ||
| width: 120, | ||
| height: 50, | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| describe("applyResize — aspect (Shift) on a side edge follows the perpendicular", () => { | ||
| it("e: left edge pinned, height scales with width about the vertical center", () => { | ||
| const r = bbox( | ||
| applyResize(rect(0, 0, 100, 50), "e", 20, 0, { aspect: true }) | ||
| ); | ||
| expect(r).toEqual({ x: 0, y: -5, width: 120, height: 60 }); // s = 1.2 | ||
| expect(r.y + r.height / 2).toBe(25); // vertical center preserved | ||
| expect(r.x).toBe(0); // left edge pinned | ||
| }); | ||
|
|
||
| it("n: bottom edge pinned, width scales with height about the horizontal center", () => { | ||
| const r = bbox( | ||
| applyResize(rect(0, 0, 100, 50), "n", 0, -10, { aspect: true }) | ||
| ); | ||
| expect(r).toEqual({ x: -10, y: -10, width: 120, height: 60 }); // s = 1.2 | ||
| expect(r.x + r.width / 2).toBe(50); // horizontal center preserved | ||
| expect(r.y + r.height).toBe(50); // bottom edge pinned | ||
| }); | ||
| }); | ||
|
|
||
| describe("applyResize — aspect (Shift) on a corner is max-magnitude uniform", () => { | ||
| it("se collapses to the larger axis factor, origin pinned", () => { | ||
| // sx = 1.2, sy = 1.1 → mag 1.2. | ||
| const r = bbox( | ||
| applyResize(rect(0, 0, 100, 50), "se", 20, 5, { aspect: true }) | ||
| ); | ||
| expect(r).toEqual({ x: 0, y: 0, width: 120, height: 60 }); | ||
| }); | ||
| }); | ||
|
|
||
| describe("applyResize — Shift+Alt is uniform about the bbox center", () => { | ||
| it("e edge: both opposite edges move, center stays put", () => { | ||
| const r = bbox( | ||
| applyResize(rect(0, 0, 100, 50), "e", 20, 0, { | ||
| fromCenter: true, | ||
| aspect: true, | ||
| }) | ||
| ); | ||
| expect(r).toEqual({ x: -20, y: -10, width: 140, height: 70 }); // s = 1.4 | ||
| expect(center(r)).toEqual({ x: 50, y: 25 }); // initial center | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.