@oh-just-another/state 0.62.0 → 0.64.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/CHANGELOG.md +83 -0
- package/dist/.tsbuildinfo +1 -1
- package/dist/actions/registry.js +1 -1
- package/dist/actions/registry.js.map +1 -1
- package/dist/constants.d.ts +162 -8
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +132 -8
- package/dist/constants.js.map +1 -1
- package/dist/editor/animation-scene.d.ts.map +1 -1
- package/dist/editor/animation-scene.js +27 -39
- package/dist/editor/animation-scene.js.map +1 -1
- package/dist/editor/animation.js +1 -1
- package/dist/editor/animation.js.map +1 -1
- package/dist/editor/applies/arrange-units.d.ts +24 -0
- package/dist/editor/applies/arrange-units.d.ts.map +1 -0
- package/dist/editor/applies/arrange-units.js +56 -0
- package/dist/editor/applies/arrange-units.js.map +1 -0
- package/dist/editor/applies/arrange.d.ts +16 -15
- package/dist/editor/applies/arrange.d.ts.map +1 -1
- package/dist/editor/applies/arrange.js +33 -48
- package/dist/editor/applies/arrange.js.map +1 -1
- package/dist/editor/applies/create.d.ts +16 -10
- package/dist/editor/applies/create.d.ts.map +1 -1
- package/dist/editor/applies/create.js +32 -12
- package/dist/editor/applies/create.js.map +1 -1
- package/dist/editor/applies/edge.d.ts +1 -1
- package/dist/editor/applies/edge.d.ts.map +1 -1
- package/dist/editor/applies/object-snap.d.ts +87 -0
- package/dist/editor/applies/object-snap.d.ts.map +1 -0
- package/dist/editor/applies/object-snap.js +198 -0
- package/dist/editor/applies/object-snap.js.map +1 -0
- package/dist/editor/applies/resize.d.ts +1 -1
- package/dist/editor/applies/resize.d.ts.map +1 -1
- package/dist/editor/applies/resize.js +6 -4
- package/dist/editor/applies/resize.js.map +1 -1
- package/dist/editor/applies/selection.d.ts +5 -5
- package/dist/editor/applies/selection.d.ts.map +1 -1
- package/dist/editor/applies/selection.js +15 -7
- package/dist/editor/applies/selection.js.map +1 -1
- package/dist/editor/applies/snap-grid.d.ts +1 -1
- package/dist/editor/applies/snap-grid.d.ts.map +1 -1
- package/dist/editor/container-ops.d.ts +1 -1
- package/dist/editor/container-ops.d.ts.map +1 -1
- package/dist/{editor-events.d.ts → editor/editor-events.d.ts} +2 -2
- package/dist/editor/editor-events.d.ts.map +1 -0
- package/dist/{editor-events.js.map → editor/editor-events.js.map} +1 -1
- package/dist/editor/event-fanout.d.ts +3 -3
- package/dist/editor/event-fanout.d.ts.map +1 -1
- package/dist/editor/gesture-tx.d.ts +1 -1
- package/dist/editor/gesture-tx.d.ts.map +1 -1
- package/dist/editor/hit-test.d.ts +5 -3
- package/dist/editor/hit-test.d.ts.map +1 -1
- package/dist/editor/hit-test.js +18 -10
- package/dist/editor/hit-test.js.map +1 -1
- package/dist/editor/interaction-state.d.ts +29 -2
- package/dist/editor/interaction-state.d.ts.map +1 -1
- package/dist/editor/interaction-state.js +34 -0
- package/dist/editor/interaction-state.js.map +1 -1
- package/dist/editor/link-handle-drag.d.ts +1 -1
- package/dist/editor/link-handle-drag.d.ts.map +1 -1
- package/dist/editor/link-handle-drag.js +1 -1
- package/dist/editor/link-handle-drag.js.map +1 -1
- package/dist/editor/pointer-binding.d.ts.map +1 -1
- package/dist/editor/pointer-binding.js +86 -24
- package/dist/editor/pointer-binding.js.map +1 -1
- package/dist/editor/public/arrange-group.d.ts +6 -5
- package/dist/editor/public/arrange-group.d.ts.map +1 -1
- package/dist/editor/public/arrange-group.js +39 -23
- package/dist/editor/public/arrange-group.js.map +1 -1
- package/dist/editor/public/clipboard.d.ts +1 -1
- package/dist/editor/public/clipboard.d.ts.map +1 -1
- package/dist/editor/public/clipboard.js +2 -2
- package/dist/editor/public/clipboard.js.map +1 -1
- package/dist/editor/public/cursor.js +1 -1
- package/dist/editor/public/cursor.js.map +1 -1
- package/dist/editor/public/eraser.js +1 -1
- package/dist/editor/public/eraser.js.map +1 -1
- package/dist/editor/public/image-insert.d.ts.map +1 -1
- package/dist/editor/public/image-insert.js +4 -1
- package/dist/editor/public/image-insert.js.map +1 -1
- package/dist/editor/public/label-seed.d.ts +12 -0
- package/dist/editor/public/label-seed.d.ts.map +1 -0
- package/dist/editor/public/label-seed.js +20 -0
- package/dist/editor/public/label-seed.js.map +1 -0
- package/dist/editor/public/layers.d.ts +1 -1
- package/dist/editor/public/layers.d.ts.map +1 -1
- package/dist/editor/public/placement.d.ts +6 -1
- package/dist/editor/public/placement.d.ts.map +1 -1
- package/dist/editor/public/placement.js +47 -17
- package/dist/editor/public/placement.js.map +1 -1
- package/dist/editor/public/selection-ops.d.ts +1 -1
- package/dist/editor/public/selection-ops.d.ts.map +1 -1
- package/dist/editor/public/selection-ops.js +31 -2
- package/dist/editor/public/selection-ops.js.map +1 -1
- package/dist/editor/public/stroke-eraser-coverage.js +1 -1
- package/dist/editor/public/stroke-eraser-coverage.js.map +1 -1
- package/dist/editor/public/stroke-eraser.js +1 -1
- package/dist/editor/public/stroke-eraser.js.map +1 -1
- package/dist/editor/public/text-edit.d.ts +4 -2
- package/dist/editor/public/text-edit.d.ts.map +1 -1
- package/dist/editor/public/text-edit.js +8 -4
- package/dist/editor/public/text-edit.js.map +1 -1
- package/dist/editor/public/tool-ops.d.ts +10 -7
- package/dist/editor/public/tool-ops.d.ts.map +1 -1
- package/dist/editor/public/tool-ops.js +141 -14
- package/dist/editor/public/tool-ops.js.map +1 -1
- package/dist/editor/public/zoom-pan.d.ts +10 -1
- package/dist/editor/public/zoom-pan.d.ts.map +1 -1
- package/dist/editor/public/zoom-pan.js +49 -0
- package/dist/editor/public/zoom-pan.js.map +1 -1
- package/dist/editor/render-orchestrator.d.ts +17 -11
- package/dist/editor/render-orchestrator.d.ts.map +1 -1
- package/dist/editor/render-orchestrator.js +45 -31
- package/dist/editor/render-orchestrator.js.map +1 -1
- package/dist/editor/resize-helpers.d.ts +1 -1
- package/dist/editor/resize-helpers.d.ts.map +1 -1
- package/dist/editor/shape-traits.d.ts +1 -1
- package/dist/editor/shape-traits.d.ts.map +1 -1
- package/dist/editor/shape-traits.js +1 -1
- package/dist/editor/shape-traits.js.map +1 -1
- package/dist/editor/text-edit.d.ts +24 -11
- package/dist/editor/text-edit.d.ts.map +1 -1
- package/dist/editor/text-edit.js +225 -45
- package/dist/editor/text-edit.js.map +1 -1
- package/dist/editor.d.ts +320 -20
- package/dist/editor.d.ts.map +1 -1
- package/dist/editor.js +1324 -73
- package/dist/editor.js.map +1 -1
- package/dist/features/built-in-handlers.d.ts.map +1 -0
- package/dist/{built-in-handlers.js → features/built-in-handlers.js} +7 -1
- package/dist/features/built-in-handlers.js.map +1 -0
- package/dist/{clipboard.d.ts → features/clipboard.d.ts} +14 -0
- package/dist/features/clipboard.d.ts.map +1 -0
- package/dist/{clipboard.js → features/clipboard.js} +1 -1
- package/dist/features/clipboard.js.map +1 -0
- package/dist/{file-drop.d.ts → features/file-drop.d.ts} +20 -1
- package/dist/features/file-drop.d.ts.map +1 -0
- package/dist/{file-drop.js → features/file-drop.js} +47 -19
- package/dist/features/file-drop.js.map +1 -0
- package/dist/features/insert-scene.d.ts +19 -0
- package/dist/features/insert-scene.d.ts.map +1 -0
- package/dist/features/insert-scene.js +145 -0
- package/dist/features/insert-scene.js.map +1 -0
- package/dist/features/search.d.ts.map +1 -0
- package/dist/features/search.js.map +1 -0
- package/dist/helpers/auto-compact.d.ts.map +1 -0
- package/dist/{auto-compact.js → helpers/auto-compact.js} +1 -1
- package/dist/helpers/auto-compact.js.map +1 -0
- package/dist/helpers/auto-layout-scheduler.d.ts.map +1 -0
- package/dist/helpers/auto-layout-scheduler.js.map +1 -0
- package/dist/helpers/frame-helpers.d.ts.map +1 -0
- package/dist/helpers/frame-helpers.js.map +1 -0
- package/dist/helpers/group-helpers.d.ts.map +1 -0
- package/dist/helpers/group-helpers.js.map +1 -0
- package/dist/helpers/util.d.ts.map +1 -0
- package/dist/helpers/util.js.map +1 -0
- package/dist/index.d.ts +23 -21
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -12
- package/dist/index.js.map +1 -1
- package/dist/input/dom-events.d.ts.map +1 -0
- package/dist/input/dom-events.js.map +1 -0
- package/dist/{hotkeys-binding.d.ts → input/hotkeys-binding.d.ts} +2 -2
- package/dist/input/hotkeys-binding.d.ts.map +1 -0
- package/dist/{hotkeys-binding.js → input/hotkeys-binding.js} +1 -1
- package/dist/input/hotkeys-binding.js.map +1 -0
- package/dist/input/platform.d.ts.map +1 -0
- package/dist/input/platform.js.map +1 -0
- package/dist/{handle.d.ts → interaction/handle.d.ts} +1 -1
- package/dist/interaction/handle.d.ts.map +1 -0
- package/dist/{handle.js → interaction/handle.js} +1 -1
- package/dist/interaction/handle.js.map +1 -0
- package/dist/interaction/interactive.d.ts.map +1 -0
- package/dist/interaction/interactive.js.map +1 -0
- package/dist/interaction/machine.d.ts.map +1 -0
- package/dist/interaction/machine.js.map +1 -0
- package/dist/interaction/modes.d.ts.map +1 -0
- package/dist/interaction/modes.js.map +1 -0
- package/dist/render/animation-tick.d.ts.map +1 -0
- package/dist/render/animation-tick.js.map +1 -0
- package/dist/{overlay.d.ts → render/overlay.d.ts} +42 -38
- package/dist/render/overlay.d.ts.map +1 -0
- package/dist/{overlay.js → render/overlay.js} +174 -59
- package/dist/render/overlay.js.map +1 -0
- package/dist/selection/link-selection.d.ts.map +1 -0
- package/dist/{link-selection.js → selection/link-selection.js} +1 -1
- package/dist/selection/link-selection.js.map +1 -0
- package/dist/selection/selection.d.ts.map +1 -0
- package/dist/{selection.js → selection/selection.js} +1 -1
- package/dist/selection/selection.js.map +1 -0
- package/package.json +5 -5
- package/dist/animation-tick.d.ts.map +0 -1
- package/dist/animation-tick.js.map +0 -1
- package/dist/auto-compact.d.ts.map +0 -1
- package/dist/auto-compact.js.map +0 -1
- package/dist/auto-layout-scheduler.d.ts.map +0 -1
- package/dist/auto-layout-scheduler.js.map +0 -1
- package/dist/built-in-handlers.d.ts.map +0 -1
- package/dist/built-in-handlers.js.map +0 -1
- package/dist/clipboard.d.ts.map +0 -1
- package/dist/clipboard.js.map +0 -1
- package/dist/dom-events.d.ts.map +0 -1
- package/dist/dom-events.js.map +0 -1
- package/dist/editor-events.d.ts.map +0 -1
- package/dist/file-drop.d.ts.map +0 -1
- package/dist/file-drop.js.map +0 -1
- package/dist/frame-helpers.d.ts.map +0 -1
- package/dist/frame-helpers.js.map +0 -1
- package/dist/group-helpers.d.ts.map +0 -1
- package/dist/group-helpers.js.map +0 -1
- package/dist/handle.d.ts.map +0 -1
- package/dist/handle.js.map +0 -1
- package/dist/hotkeys-binding.d.ts.map +0 -1
- package/dist/hotkeys-binding.js.map +0 -1
- package/dist/interactive.d.ts.map +0 -1
- package/dist/interactive.js.map +0 -1
- package/dist/link-selection.d.ts.map +0 -1
- package/dist/link-selection.js.map +0 -1
- package/dist/machine.d.ts.map +0 -1
- package/dist/machine.js.map +0 -1
- package/dist/modes.d.ts.map +0 -1
- package/dist/modes.js.map +0 -1
- package/dist/overlay.d.ts.map +0 -1
- package/dist/overlay.js.map +0 -1
- package/dist/platform.d.ts.map +0 -1
- package/dist/platform.js.map +0 -1
- package/dist/search.d.ts.map +0 -1
- package/dist/search.js.map +0 -1
- package/dist/selection.d.ts.map +0 -1
- package/dist/selection.js.map +0 -1
- package/dist/util.d.ts.map +0 -1
- package/dist/util.js.map +0 -1
- /package/dist/{editor-events.js → editor/editor-events.js} +0 -0
- /package/dist/{built-in-handlers.d.ts → features/built-in-handlers.d.ts} +0 -0
- /package/dist/{search.d.ts → features/search.d.ts} +0 -0
- /package/dist/{search.js → features/search.js} +0 -0
- /package/dist/{auto-compact.d.ts → helpers/auto-compact.d.ts} +0 -0
- /package/dist/{auto-layout-scheduler.d.ts → helpers/auto-layout-scheduler.d.ts} +0 -0
- /package/dist/{auto-layout-scheduler.js → helpers/auto-layout-scheduler.js} +0 -0
- /package/dist/{frame-helpers.d.ts → helpers/frame-helpers.d.ts} +0 -0
- /package/dist/{frame-helpers.js → helpers/frame-helpers.js} +0 -0
- /package/dist/{group-helpers.d.ts → helpers/group-helpers.d.ts} +0 -0
- /package/dist/{group-helpers.js → helpers/group-helpers.js} +0 -0
- /package/dist/{util.d.ts → helpers/util.d.ts} +0 -0
- /package/dist/{util.js → helpers/util.js} +0 -0
- /package/dist/{dom-events.d.ts → input/dom-events.d.ts} +0 -0
- /package/dist/{dom-events.js → input/dom-events.js} +0 -0
- /package/dist/{platform.d.ts → input/platform.d.ts} +0 -0
- /package/dist/{platform.js → input/platform.js} +0 -0
- /package/dist/{interactive.d.ts → interaction/interactive.d.ts} +0 -0
- /package/dist/{interactive.js → interaction/interactive.js} +0 -0
- /package/dist/{machine.d.ts → interaction/machine.d.ts} +0 -0
- /package/dist/{machine.js → interaction/machine.js} +0 -0
- /package/dist/{modes.d.ts → interaction/modes.d.ts} +0 -0
- /package/dist/{modes.js → interaction/modes.js} +0 -0
- /package/dist/{animation-tick.d.ts → render/animation-tick.d.ts} +0 -0
- /package/dist/{animation-tick.js → render/animation-tick.js} +0 -0
- /package/dist/{link-selection.d.ts → selection/link-selection.d.ts} +0 -0
- /package/dist/{selection.d.ts → selection/selection.d.ts} +0 -0
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type Element, type Patch, type Scene } from "@oh-just-another/scene";
|
|
2
|
+
import type { Bounds, ElementId } from "@oh-just-another/types";
|
|
3
|
+
/**
|
|
4
|
+
* One "thing" a multi-element command arranges: a selection root plus
|
|
5
|
+
* everything it carries. A plain shape is a unit of itself; a selected
|
|
6
|
+
* group is ONE unit — its whole subtree moves together and its footprint
|
|
7
|
+
* is the union of the descendants (the group shell has no geometry).
|
|
8
|
+
* Descendants whose ancestor is also selected are folded into that unit
|
|
9
|
+
* instead of being arranged twice.
|
|
10
|
+
*/
|
|
11
|
+
export interface ArrangeUnit {
|
|
12
|
+
readonly root: Element;
|
|
13
|
+
/** The root and its descendants (group shells included, so they move too). */
|
|
14
|
+
readonly members: readonly Element[];
|
|
15
|
+
/** World AABB of the unit's visible members. */
|
|
16
|
+
readonly bounds: Bounds;
|
|
17
|
+
}
|
|
18
|
+
/** Build the arrange units of `selection` (units without geometry are dropped). */
|
|
19
|
+
export declare const arrangeUnits: (scene: Scene, selection: Iterable<ElementId>) => ArrangeUnit[];
|
|
20
|
+
/** Translate every member of `unit` by `(dx, dy)` — one patch per member. */
|
|
21
|
+
export declare const translateUnit: (unit: ArrangeUnit, dx: number, dy: number) => Patch[];
|
|
22
|
+
/** World AABB enclosing every unit (assumes `units` is non-empty). */
|
|
23
|
+
export declare const unitsBounds: (units: readonly ArrangeUnit[]) => Bounds;
|
|
24
|
+
//# sourceMappingURL=arrange-units.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"arrange-units.d.ts","sourceRoot":"","sources":["../../../src/editor/applies/arrange-units.ts"],"names":[],"mappings":"AACA,OAAO,EAKL,KAAK,OAAO,EACZ,KAAK,KAAK,EACV,KAAK,KAAK,EACX,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAEhE;;;;;;;GAOG;AACH,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB,8EAA8E;IAC9E,QAAQ,CAAC,OAAO,EAAE,SAAS,OAAO,EAAE,CAAC;IACrC,gDAAgD;IAChD,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAsBD,mFAAmF;AACnF,eAAO,MAAM,YAAY,GAAI,OAAO,KAAK,EAAE,WAAW,QAAQ,CAAC,SAAS,CAAC,KAAG,WAAW,EAetF,CAAC;AAEF,6EAA6E;AAC7E,eAAO,MAAM,aAAa,GAAI,MAAM,WAAW,EAAE,IAAI,MAAM,EAAE,IAAI,MAAM,KAAG,KAAK,EAQ9E,CAAC;AAEF,sEAAsE;AACtE,eAAO,MAAM,WAAW,GAAI,OAAO,SAAS,WAAW,EAAE,KAAG,MACI,CAAC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { bounds as B } from "@oh-just-another/math";
|
|
2
|
+
import { getDescendantsOf, getElement, getElementWorldBounds, isGroup, } from "@oh-just-another/scene";
|
|
3
|
+
/** Selection roots: selected elements with no selected ancestor. */
|
|
4
|
+
const roots = (scene, selection) => {
|
|
5
|
+
const out = [];
|
|
6
|
+
for (const id of selection) {
|
|
7
|
+
const shape = getElement(scene, id);
|
|
8
|
+
if (!shape)
|
|
9
|
+
continue;
|
|
10
|
+
let cursor = shape;
|
|
11
|
+
let covered = false;
|
|
12
|
+
for (let i = 0; cursor?.parentId && i < 64; i++) {
|
|
13
|
+
if (selection.has(cursor.parentId)) {
|
|
14
|
+
covered = true;
|
|
15
|
+
break;
|
|
16
|
+
}
|
|
17
|
+
cursor = getElement(scene, cursor.parentId);
|
|
18
|
+
}
|
|
19
|
+
if (!covered)
|
|
20
|
+
out.push(shape);
|
|
21
|
+
}
|
|
22
|
+
return out;
|
|
23
|
+
};
|
|
24
|
+
/** Build the arrange units of `selection` (units without geometry are dropped). */
|
|
25
|
+
export const arrangeUnits = (scene, selection) => {
|
|
26
|
+
const ids = selection instanceof Set ? selection : new Set(selection);
|
|
27
|
+
const units = [];
|
|
28
|
+
for (const root of roots(scene, ids)) {
|
|
29
|
+
// `getDescendantsOf` returns the root itself plus its subtree.
|
|
30
|
+
const members = isGroup(root) ? getDescendantsOf(scene, root.id) : [root];
|
|
31
|
+
let bounds = null;
|
|
32
|
+
for (const m of members) {
|
|
33
|
+
if (isGroup(m))
|
|
34
|
+
continue;
|
|
35
|
+
const b = getElementWorldBounds(m);
|
|
36
|
+
bounds = bounds ? B.union(bounds, b) : b;
|
|
37
|
+
}
|
|
38
|
+
if (bounds)
|
|
39
|
+
units.push({ root, members, bounds });
|
|
40
|
+
}
|
|
41
|
+
return units;
|
|
42
|
+
};
|
|
43
|
+
/** Translate every member of `unit` by `(dx, dy)` — one patch per member. */
|
|
44
|
+
export const translateUnit = (unit, dx, dy) => {
|
|
45
|
+
if (dx === 0 && dy === 0)
|
|
46
|
+
return [];
|
|
47
|
+
return unit.members.map((el) => ({
|
|
48
|
+
kind: "element",
|
|
49
|
+
id: el.id,
|
|
50
|
+
before: el,
|
|
51
|
+
after: { ...el, position: { x: el.position.x + dx, y: el.position.y + dy } },
|
|
52
|
+
}));
|
|
53
|
+
};
|
|
54
|
+
/** World AABB enclosing every unit (assumes `units` is non-empty). */
|
|
55
|
+
export const unitsBounds = (units) => units.map((u) => u.bounds).reduce((acc, b) => B.union(acc, b));
|
|
56
|
+
//# sourceMappingURL=arrange-units.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"arrange-units.js","sourceRoot":"","sources":["../../../src/editor/applies/arrange-units.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EACL,gBAAgB,EAChB,UAAU,EACV,qBAAqB,EACrB,OAAO,GAIR,MAAM,wBAAwB,CAAC;AAmBhC,oEAAoE;AACpE,MAAM,KAAK,GAAG,CAAC,KAAY,EAAE,SAAiC,EAAa,EAAE;IAC3E,MAAM,GAAG,GAAc,EAAE,CAAC;IAC1B,KAAK,MAAM,EAAE,IAAI,SAAS,EAAE,CAAC;QAC3B,MAAM,KAAK,GAAG,UAAU,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QACpC,IAAI,CAAC,KAAK;YAAE,SAAS;QACrB,IAAI,MAAM,GAAwB,KAAK,CAAC;QACxC,IAAI,OAAO,GAAG,KAAK,CAAC;QACpB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,MAAM,EAAE,QAAQ,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC;YAChD,IAAI,SAAS,CAAC,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC;gBACnC,OAAO,GAAG,IAAI,CAAC;gBACf,MAAM;YACR,CAAC;YACD,MAAM,GAAG,UAAU,CAAC,KAAK,EAAE,MAAM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AAW,EAAE;IAClF,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC;QAAE,OAAO,EAAE,CAAC;IACpC,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;QAC/B,IAAI,EAAE,SAAS;QACf,EAAE,EAAE,EAAE,CAAC,EAAE;QACT,MAAM,EAAE,EAAE;QACV,KAAK,EAAE,EAAE,GAAG,EAAE,EAAE,QAAQ,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,QAAQ,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,QAAQ,CAAC,CAAC,GAAG,EAAE,EAAE,EAAE;KAC7E,CAAC,CAAC,CAAC;AACN,CAAC,CAAC;AAEF,sEAAsE;AACtE,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,KAA6B,EAAU,EAAE,CACnE,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC"}
|
|
@@ -11,27 +11,28 @@ export type RotateOrigin = ReadonlyMap<ElementId, {
|
|
|
11
11
|
rotation: number;
|
|
12
12
|
}>;
|
|
13
13
|
/**
|
|
14
|
-
* Pure: mirror
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
14
|
+
* Pure: mirror the selection about its combined centre on the given axis.
|
|
15
|
+
* Every visible member of every unit (a selected group mirrors as a whole:
|
|
16
|
+
* its descendants reflect about the shared centre) has its position
|
|
17
|
+
* reflected across the centre and its scale sign flipped on that axis, so
|
|
18
|
+
* the content mirrors in place; size is unchanged. Mirroring a single
|
|
19
|
+
* element flips it about its own centre. Edges bound to the moved elements
|
|
20
|
+
* re-route from their endpoints; free links are left untouched.
|
|
20
21
|
*/
|
|
21
22
|
export declare const computeFlipPatches: (scene: Scene, ids: Iterable<ElementId>, axis: FlipAxis) => Patch[];
|
|
22
23
|
/**
|
|
23
|
-
* Pure: align every
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
24
|
+
* Pure: align every unit of the selection (a selected group counts as one
|
|
25
|
+
* unit and moves as a whole) to the given edge / centre line of the
|
|
26
|
+
* combined bounding box (e.g. `left` moves each unit so its left edge meets
|
|
27
|
+
* the box's left edge; `h-center` lines up horizontal centres). Only the
|
|
28
|
+
* relevant axis moves; sizes are unchanged. A no-op below two units.
|
|
28
29
|
*/
|
|
29
30
|
export declare const computeAlignPatches: (scene: Scene, ids: Iterable<ElementId>, edge: AlignEdge) => Patch[];
|
|
30
31
|
/**
|
|
31
|
-
* Pure: evenly space the selection along the given axis so the gaps
|
|
32
|
-
* adjacent
|
|
33
|
-
* shift to balance the gaps (accounting for
|
|
34
|
-
* three
|
|
32
|
+
* Pure: evenly space the selection's units along the given axis so the gaps
|
|
33
|
+
* between adjacent units are equal (a selected group is one unit). The
|
|
34
|
+
* outermost two stay put; the rest shift to balance the gaps (accounting for
|
|
35
|
+
* differing sizes). A no-op below three units.
|
|
35
36
|
*/
|
|
36
37
|
export declare const computeDistributePatches: (scene: Scene, ids: Iterable<ElementId>, axis: DistributeAxis) => Patch[];
|
|
37
38
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"arrange.d.ts","sourceRoot":"","sources":["../../../src/editor/applies/arrange.ts"],"names":[],"mappings":"AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"arrange.d.ts","sourceRoot":"","sources":["../../../src/editor/applies/arrange.ts"],"names":[],"mappings":"AACA,OAAO,EAIL,KAAK,OAAO,EACZ,KAAK,KAAK,EACV,KAAK,KAAK,EACX,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,EAAU,SAAS,EAAE,IAAI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, ids) => {
|
|
5
|
-
const out = [];
|
|
6
|
-
for (const id of ids) {
|
|
7
|
-
const el = getElement(scene, id);
|
|
8
|
-
if (el)
|
|
9
|
-
out.push(el);
|
|
10
|
-
}
|
|
11
|
-
return out;
|
|
12
|
-
};
|
|
2
|
+
import { getElement, getElementWorldBounds, isGroup, } from "@oh-just-another/scene";
|
|
3
|
+
import { arrangeUnits, translateUnit, unitsBounds } from "./arrange-units.js";
|
|
13
4
|
/** World-space AABB enclosing every element in `elements` (assumed non-empty). */
|
|
14
5
|
const enclosingBounds = (elements) => elements.map((el) => getElementWorldBounds(el)).reduce((acc, b) => B.union(acc, b));
|
|
15
6
|
/**
|
|
16
|
-
* Pure: mirror
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
7
|
+
* Pure: mirror the selection about its combined centre on the given axis.
|
|
8
|
+
* Every visible member of every unit (a selected group mirrors as a whole:
|
|
9
|
+
* its descendants reflect about the shared centre) has its position
|
|
10
|
+
* reflected across the centre and its scale sign flipped on that axis, so
|
|
11
|
+
* the content mirrors in place; size is unchanged. Mirroring a single
|
|
12
|
+
* element flips it about its own centre. Edges bound to the moved elements
|
|
13
|
+
* re-route from their endpoints; free links are left untouched.
|
|
22
14
|
*/
|
|
23
15
|
export const computeFlipPatches = (scene, ids, axis) => {
|
|
24
|
-
const
|
|
25
|
-
if (
|
|
16
|
+
const units = arrangeUnits(scene, ids);
|
|
17
|
+
if (units.length === 0)
|
|
26
18
|
return [];
|
|
27
|
-
const box =
|
|
19
|
+
const box = unitsBounds(units);
|
|
28
20
|
const cx = box.x + box.width / 2;
|
|
29
21
|
const cy = box.y + box.height / 2;
|
|
30
22
|
const horizontal = axis === "horizontal";
|
|
31
23
|
const patches = [];
|
|
24
|
+
const elements = units.flatMap((u) => u.members).filter((el) => !isGroup(el));
|
|
32
25
|
for (const el of elements) {
|
|
33
26
|
const after = horizontal
|
|
34
27
|
? {
|
|
@@ -46,20 +39,20 @@ export const computeFlipPatches = (scene, ids, axis) => {
|
|
|
46
39
|
return patches;
|
|
47
40
|
};
|
|
48
41
|
/**
|
|
49
|
-
* Pure: align every
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
42
|
+
* Pure: align every unit of the selection (a selected group counts as one
|
|
43
|
+
* unit and moves as a whole) to the given edge / centre line of the
|
|
44
|
+
* combined bounding box (e.g. `left` moves each unit so its left edge meets
|
|
45
|
+
* the box's left edge; `h-center` lines up horizontal centres). Only the
|
|
46
|
+
* relevant axis moves; sizes are unchanged. A no-op below two units.
|
|
54
47
|
*/
|
|
55
48
|
export const computeAlignPatches = (scene, ids, edge) => {
|
|
56
|
-
const
|
|
57
|
-
if (
|
|
49
|
+
const units = arrangeUnits(scene, ids);
|
|
50
|
+
if (units.length < 2)
|
|
58
51
|
return [];
|
|
59
|
-
const box =
|
|
52
|
+
const box = unitsBounds(units);
|
|
60
53
|
const patches = [];
|
|
61
|
-
for (const
|
|
62
|
-
const b =
|
|
54
|
+
for (const unit of units) {
|
|
55
|
+
const b = unit.bounds;
|
|
63
56
|
let dx = 0;
|
|
64
57
|
let dy = 0;
|
|
65
58
|
switch (edge) {
|
|
@@ -82,28 +75,25 @@ export const computeAlignPatches = (scene, ids, edge) => {
|
|
|
82
75
|
dy = box.y + box.height / 2 - (b.y + b.height / 2);
|
|
83
76
|
break;
|
|
84
77
|
}
|
|
85
|
-
|
|
86
|
-
continue;
|
|
87
|
-
const after = { ...el, position: { x: el.position.x + dx, y: el.position.y + dy } };
|
|
88
|
-
patches.push({ kind: "element", id: el.id, before: el, after });
|
|
78
|
+
patches.push(...translateUnit(unit, dx, dy));
|
|
89
79
|
}
|
|
90
80
|
return patches;
|
|
91
81
|
};
|
|
92
82
|
/**
|
|
93
|
-
* Pure: evenly space the selection along the given axis so the gaps
|
|
94
|
-
* adjacent
|
|
95
|
-
* shift to balance the gaps (accounting for
|
|
96
|
-
* three
|
|
83
|
+
* Pure: evenly space the selection's units along the given axis so the gaps
|
|
84
|
+
* between adjacent units are equal (a selected group is one unit). The
|
|
85
|
+
* outermost two stay put; the rest shift to balance the gaps (accounting for
|
|
86
|
+
* differing sizes). A no-op below three units.
|
|
97
87
|
*/
|
|
98
88
|
export const computeDistributePatches = (scene, ids, axis) => {
|
|
99
|
-
const
|
|
100
|
-
if (
|
|
89
|
+
const units = arrangeUnits(scene, ids);
|
|
90
|
+
if (units.length < 3)
|
|
101
91
|
return [];
|
|
102
92
|
const horizontal = axis === "horizontal";
|
|
103
93
|
const start = (b) => (horizontal ? b.x : b.y);
|
|
104
94
|
const size = (b) => (horizontal ? b.width : b.height);
|
|
105
|
-
const sorted =
|
|
106
|
-
.map((
|
|
95
|
+
const sorted = units
|
|
96
|
+
.map((unit) => ({ unit, b: unit.bounds }))
|
|
107
97
|
.sort((p, q) => start(p.b) - start(q.b));
|
|
108
98
|
const first = sorted[0];
|
|
109
99
|
const last = sorted[sorted.length - 1];
|
|
@@ -119,12 +109,7 @@ export const computeDistributePatches = (scene, ids, axis) => {
|
|
|
119
109
|
if (!p)
|
|
120
110
|
continue;
|
|
121
111
|
const delta = cursor - start(p.b);
|
|
122
|
-
|
|
123
|
-
const after = horizontal
|
|
124
|
-
? { ...p.el, position: { x: p.el.position.x + delta, y: p.el.position.y } }
|
|
125
|
-
: { ...p.el, position: { x: p.el.position.x, y: p.el.position.y + delta } };
|
|
126
|
-
patches.push({ kind: "element", id: p.el.id, before: p.el, after });
|
|
127
|
-
}
|
|
112
|
+
patches.push(...translateUnit(p.unit, horizontal ? delta : 0, horizontal ? 0 : delta));
|
|
128
113
|
cursor += size(p.b) + gap;
|
|
129
114
|
}
|
|
130
115
|
return patches;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"arrange.js","sourceRoot":"","sources":["../../../src/editor/applies/arrange.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC,EAAE,MAAM,uBAAuB,CAAC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,EAAE,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC,KAAK,GAAG,CAAC,EAAE,CAAC,EAAE,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;AACjE,CAAC,CAAC"}
|
|
@@ -1,14 +1,20 @@
|
|
|
1
1
|
import { type Link, type LinkEndpoint, type Scene, type Element, type Patch } from "@oh-just-another/scene";
|
|
2
2
|
import type { Bounds, LinkId, LayerId, ElementId, Vec2 } from "@oh-just-another/types";
|
|
3
|
+
export declare const buildElementForCreate: (scene: Scene, kind: "rect" | "ellipse" | "frame" | "diamond" | "triangle", bounds: Bounds, id: ElementId, layerId: LayerId, nextFrameName: () => string) => Element;
|
|
3
4
|
/**
|
|
4
|
-
* Build the `
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
*
|
|
5
|
+
* Build the `Link` object for a CREATE_EDGE emit. Endpoints are
|
|
6
|
+
* pre-resolved (snapped) by the caller — we just compose them with the
|
|
7
|
+
* layer / order / style boilerplate.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Per-draw overrides for new connectors (the "Shapes and lines" line
|
|
11
|
+
* presets): routing and the end arrowhead (`null` = no arrowhead).
|
|
12
|
+
* Omitted fields fall back to the defaults.
|
|
10
13
|
*/
|
|
11
|
-
export
|
|
14
|
+
export interface LinkCreateOverrides {
|
|
15
|
+
readonly routing?: "straight" | "orthogonal";
|
|
16
|
+
readonly arrowheadTo?: "triangle" | null;
|
|
17
|
+
}
|
|
12
18
|
/**
|
|
13
19
|
* Build the throwaway `Link` for the live draw-edge connector preview.
|
|
14
20
|
* Same default object as {@link buildLinkForCreate} (so the dragged preview is
|
|
@@ -21,7 +27,7 @@ export declare const buildEdgePreviewLink: (scene: Scene, preview: {
|
|
|
21
27
|
readonly from: Vec2;
|
|
22
28
|
readonly to: Vec2;
|
|
23
29
|
readonly points?: readonly Vec2[];
|
|
24
|
-
}, id: LinkId, layerId: LayerId) => Link;
|
|
30
|
+
}, id: LinkId, layerId: LayerId, overrides?: LinkCreateOverrides) => Link;
|
|
25
31
|
/**
|
|
26
32
|
* Composite helper for `applyCreate` — builds the shape and runs
|
|
27
33
|
* `addElement` against the scene. Returns the scene + patch so the
|
|
@@ -31,7 +37,7 @@ export declare const buildEdgePreviewLink: (scene: Scene, preview: {
|
|
|
31
37
|
* `width` / `height`; the parameter is kept on the signature only
|
|
32
38
|
* to document intent at the call site.
|
|
33
39
|
*/
|
|
34
|
-
export declare const computeCreateElement: (scene: Scene, kind: "rect" | "ellipse" | "frame", bounds: Bounds, id: ElementId, layerId: LayerId, nextFrameName: () => string) => {
|
|
40
|
+
export declare const computeCreateElement: (scene: Scene, kind: "rect" | "ellipse" | "frame" | "diamond" | "triangle", bounds: Bounds, id: ElementId, layerId: LayerId, nextFrameName: () => string) => {
|
|
35
41
|
readonly scene: Scene;
|
|
36
42
|
readonly patch: Patch;
|
|
37
43
|
readonly elementId: ElementId;
|
|
@@ -42,7 +48,7 @@ export declare const computeCreateElement: (scene: Scene, kind: "rect" | "ellips
|
|
|
42
48
|
* to the snap engine in Editor); pre-resolved `from`/`to` are
|
|
43
49
|
* threaded in as parameters.
|
|
44
50
|
*/
|
|
45
|
-
export declare const computeCreateLink: (scene: Scene, from: LinkEndpoint, to: LinkEndpoint, id: LinkId, layerId: LayerId) => {
|
|
51
|
+
export declare const computeCreateLink: (scene: Scene, from: LinkEndpoint, to: LinkEndpoint, id: LinkId, layerId: LayerId, overrides?: LinkCreateOverrides) => {
|
|
46
52
|
readonly scene: Scene;
|
|
47
53
|
readonly patch: Patch;
|
|
48
54
|
readonly linkId: LinkId;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../../../src/editor/applies/create.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,KAAK,IAAI,EACT,KAAK,YAAY,EACjB,KAAK,KAAK,EACV,KAAK,OAAO,EACZ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,MAAM,MAAM,GAAG,SAAS,GAAG,OAAO,GAAG,SAAS,GAAG,UAAU,EAC3D,QAAQ,MAAM,EACd,IAAI,SAAS,EACb,SAAS,OAAO,EAChB,eAAe,MAAM,MAAM,KAC1B;IAAE,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC;IAAC,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAA;CAI/E,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,GAC5B,OAAO,KAAK,EACZ,MAAM,YAAY,EAClB,IAAI,YAAY,EAChB,IAAI,MAAM,EACV,SAAS,OAAO,EAChB,YAAY,mBAAmB,KAC9B;IAAE,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CAIzE,CAAC;AAEF,uEAAuE;AACvE,eAAO,MAAM,YAAY,GAAI,MAAM,MAAM,KAAG,SACa,CAAC;AAE1D,sEAAsE;AACtE,eAAO,MAAM,SAAS,GAAI,MAAM,MAAM,KAAG,MACY,CAAC"}
|
|
@@ -16,6 +16,19 @@ const DEFAULT_ELLIPSE_STYLE = DEFAULT_ELEMENT_STYLES.ellipse;
|
|
|
16
16
|
* them still receive clicks; rect / ellipse go to the top of the
|
|
17
17
|
* stack as usual.
|
|
18
18
|
*/
|
|
19
|
+
/** Inscribed polygon rings for the draw-shape kinds beyond rect/ellipse. */
|
|
20
|
+
const inscribedPoints = (kind, w, h) => kind === "diamond"
|
|
21
|
+
? [
|
|
22
|
+
{ x: w / 2, y: 0 },
|
|
23
|
+
{ x: w, y: h / 2 },
|
|
24
|
+
{ x: w / 2, y: h },
|
|
25
|
+
{ x: 0, y: h / 2 },
|
|
26
|
+
]
|
|
27
|
+
: [
|
|
28
|
+
{ x: w / 2, y: 0 },
|
|
29
|
+
{ x: w, y: h },
|
|
30
|
+
{ x: 0, y: h },
|
|
31
|
+
];
|
|
19
32
|
export const buildElementForCreate = (scene, kind, bounds, id, layerId, nextFrameName) => {
|
|
20
33
|
const orders = Array.from(scene.elements.values())
|
|
21
34
|
.filter((s) => s.layerId === layerId)
|
|
@@ -37,28 +50,35 @@ export const buildElementForCreate = (scene, kind, bounds, id, layerId, nextFram
|
|
|
37
50
|
if (kind === "ellipse") {
|
|
38
51
|
return { ...common, type: "ellipse", style: { ...DEFAULT_ELLIPSE_STYLE } };
|
|
39
52
|
}
|
|
53
|
+
if (kind === "diamond" || kind === "triangle") {
|
|
54
|
+
const { width: _w, height: _h, ...polyCommon } = common;
|
|
55
|
+
void _w;
|
|
56
|
+
void _h;
|
|
57
|
+
return {
|
|
58
|
+
...polyCommon,
|
|
59
|
+
type: "polygon",
|
|
60
|
+
points: inscribedPoints(kind, bounds.width, bounds.height),
|
|
61
|
+
style: { ...DEFAULT_RECT_STYLE },
|
|
62
|
+
};
|
|
63
|
+
}
|
|
40
64
|
// Frame: white body fill (configurable from the panel; border is fixed
|
|
41
65
|
// chrome). Auto-numbered name.
|
|
42
66
|
return { ...common, type: "frame", style: { fill: FRAME_DEFAULT_FILL }, name: nextFrameName() };
|
|
43
67
|
};
|
|
44
|
-
|
|
45
|
-
* Build the `Link` object for a CREATE_EDGE emit. Endpoints are
|
|
46
|
-
* pre-resolved (snapped) by the caller — we just compose them with the
|
|
47
|
-
* layer / order / style boilerplate.
|
|
48
|
-
*/
|
|
49
|
-
const buildLinkForCreate = (scene, from, to, id, layerId) => {
|
|
68
|
+
const buildLinkForCreate = (scene, from, to, id, layerId, overrides) => {
|
|
50
69
|
const order = orderForTop(Array.from(scene.links.values())
|
|
51
70
|
.filter((e) => e.layerId === layerId)
|
|
52
71
|
.map((e) => e.order));
|
|
72
|
+
const arrowheadTo = overrides?.arrowheadTo === undefined ? DEFAULT_LINK_ARROWHEAD : overrides.arrowheadTo;
|
|
53
73
|
return {
|
|
54
74
|
id,
|
|
55
75
|
layerId,
|
|
56
76
|
from,
|
|
57
77
|
to,
|
|
58
78
|
order,
|
|
59
|
-
routing: DEFAULT_LINK_ROUTING,
|
|
79
|
+
routing: overrides?.routing ?? DEFAULT_LINK_ROUTING,
|
|
60
80
|
style: { ...DEFAULT_EDGE_STYLE },
|
|
61
|
-
arrowheads: { to:
|
|
81
|
+
...(arrowheadTo === null ? {} : { arrowheads: { to: arrowheadTo } }),
|
|
62
82
|
};
|
|
63
83
|
};
|
|
64
84
|
/**
|
|
@@ -69,8 +89,8 @@ const buildLinkForCreate = (scene, from, to, id, layerId) => {
|
|
|
69
89
|
* routed the polyline (`points` = `[from, ...corners, to]`), its interior
|
|
70
90
|
* corners are reused as `routedPoints` so the elbow geometry matches exactly.
|
|
71
91
|
*/
|
|
72
|
-
export const buildEdgePreviewLink = (scene, preview, id, layerId) => {
|
|
73
|
-
const base = buildLinkForCreate(scene, { kind: "point", position: preview.from }, { kind: "point", position: preview.to }, id, layerId);
|
|
92
|
+
export const buildEdgePreviewLink = (scene, preview, id, layerId, overrides) => {
|
|
93
|
+
const base = buildLinkForCreate(scene, { kind: "point", position: preview.from }, { kind: "point", position: preview.to }, id, layerId, overrides);
|
|
74
94
|
return preview.points && preview.points.length > 2
|
|
75
95
|
? { ...base, routedPoints: preview.points.slice(1, -1) }
|
|
76
96
|
: base;
|
|
@@ -95,8 +115,8 @@ export const computeCreateElement = (scene, kind, bounds, id, layerId, nextFrame
|
|
|
95
115
|
* to the snap engine in Editor); pre-resolved `from`/`to` are
|
|
96
116
|
* threaded in as parameters.
|
|
97
117
|
*/
|
|
98
|
-
export const computeCreateLink = (scene, from, to, id, layerId) => {
|
|
99
|
-
const edge = buildLinkForCreate(scene, from, to, id, layerId);
|
|
118
|
+
export const computeCreateLink = (scene, from, to, id, layerId, overrides) => {
|
|
119
|
+
const edge = buildLinkForCreate(scene, from, to, id, layerId, overrides);
|
|
100
120
|
const result = addLink(scene, edge);
|
|
101
121
|
return { scene: result.scene, patch: result.patch, linkId: id };
|
|
102
122
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create.js","sourceRoot":"","sources":["../../../src/editor/applies/create.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EACP,UAAU,EACV,cAAc,EACd,WAAW,GAMZ,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AAErF,OAAO,EACL,sBAAsB,EACtB,oBAAoB,EACpB,kBAAkB,GACnB,MAAM,oBAAoB,CAAC;AAE5B;;;;GAIG;AACH,MAAM,kBAAkB,GAAG,sBAAsB,CAAC,SAAS,CAAC;AAC5D,MAAM,qBAAqB,GAAG,sBAAsB,CAAC,OAAO,CAAC;AAE7D;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,CACnC,KAAY,EACZ,
|
|
1
|
+
{"version":3,"file":"create.js","sourceRoot":"","sources":["../../../src/editor/applies/create.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EACP,UAAU,EACV,cAAc,EACd,WAAW,GAMZ,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AAErF,OAAO,EACL,sBAAsB,EACtB,oBAAoB,EACpB,kBAAkB,GACnB,MAAM,oBAAoB,CAAC;AAE5B;;;;GAIG;AACH,MAAM,kBAAkB,GAAG,sBAAsB,CAAC,SAAS,CAAC;AAC5D,MAAM,qBAAqB,GAAG,sBAAsB,CAAC,OAAO,CAAC;AAE7D;;;;;;;GAOG;AACH,4EAA4E;AAC5E,MAAM,eAAe,GAAG,CAAC,IAA4B,EAAE,CAAS,EAAE,CAAS,EAAE,EAAE,CAC7E,IAAI,KAAK,SAAS;IAChB,CAAC,CAAC;QACE,EAAE,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE;QAClB,EAAE,CAAC,EAAE,C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
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type Link, type LinkEndpoint, type Scene, type Patch } from "@oh-just-another/scene";
|
|
2
2
|
import type { ElementId, Vec2 } from "@oh-just-another/types";
|
|
3
3
|
import type { LinkId } from "@oh-just-another/types";
|
|
4
|
-
import type { InteractionEmit } from "../../machine.js";
|
|
4
|
+
import type { InteractionEmit } from "../../interaction/machine.js";
|
|
5
5
|
/**
|
|
6
6
|
* Compute the visible (snapped) endpoints for an in-progress
|
|
7
7
|
* draw-edge preview. Both ends snap to the nearest anchor on
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"edge.d.ts","sourceRoot":"","sources":["../../../src/editor/applies/edge.ts"],"names":[],"mappings":"AAAA,OAAO,EAQL,KAAK,IAAI,EACT,KAAK,YAAY,EACjB,KAAK,KAAK,EACV,KAAK,KAAK,EACX,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"edge.d.ts","sourceRoot":"","sources":["../../../src/editor/applies/edge.ts"],"names":[],"mappings":"AAAA,OAAO,EAQL,KAAK,IAAI,EACT,KAAK,YAAY,EACjB,KAAK,KAAK,EACV,KAAK,KAAK,EACX,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAEpE;;;;;;;;GAQG;AACH,eAAO,MAAM,2BAA2B,GACtC,OAAO,KAAK,EACZ,aAAa,SAAS,GAAG,IAAI,EAC7B,WAAW,IAAI,EACf,SAAS,IAAI,KACZ;IAAE,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC;IAAC,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAA;CAc1C,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,yBAAyB,GACpC,OAAO,KAAK,EACZ,MAAM,OAAO,CAAC,eAAe,EAAE;IAAE,IAAI,EAAE,sBAAsB,CAAA;CAAE,CAAC,EAChE,MAAM,CAAC,SAAS,EAAE,SAAS,GAAG,IAAI,EAAE,OAAO,EAAE,IAAI,KAAK,YAAY,KACjE;IAAE,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAAG,IAS9E,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,cAAc,GAAI,OAAO,KAAK,EAAE,MAAM,IAAI,KAAG,MAuBzD,CAAC"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import type { Bounds, Vec2 } from "@oh-just-another/types";
|
|
2
|
+
import type { HandleId } from "../../interaction/handle.js";
|
|
3
|
+
/**
|
|
4
|
+
* Object snapping — pure math shared by the move / resize gestures.
|
|
5
|
+
*
|
|
6
|
+
* While a shape (or group frame) is dragged, its left / centre / right and
|
|
7
|
+
* top / centre / bottom lines are compared with the same lines of every
|
|
8
|
+
* nearby shape ("others"). The closest pair within `threshold` (world
|
|
9
|
+
* units — the caller divides the screen threshold by zoom) wins per axis
|
|
10
|
+
* and the delta is corrected so the lines coincide. Each snap also yields a
|
|
11
|
+
* {@link SnapGuide} for the overlay: the shared line, spanning both shapes.
|
|
12
|
+
*
|
|
13
|
+
* Resizing snaps only the edge(s) the handle drags (like grid snapping) and
|
|
14
|
+
* can additionally "suggest" a size: the dragged edge lands where the
|
|
15
|
+
* shape's width / height equals a nearby shape's, and that shape is
|
|
16
|
+
* reported as `sizeMatch` so the overlay can highlight it.
|
|
17
|
+
*/
|
|
18
|
+
/** One alignment guide: a vertical (`axis: "x"`) or horizontal line. */
|
|
19
|
+
export interface SnapGuide {
|
|
20
|
+
readonly axis: "x" | "y";
|
|
21
|
+
/** World coordinate of the line (x for vertical, y for horizontal). */
|
|
22
|
+
readonly at: number;
|
|
23
|
+
/** Extent along the other axis — covers both snapped shapes. */
|
|
24
|
+
readonly from: number;
|
|
25
|
+
readonly to: number;
|
|
26
|
+
/**
|
|
27
|
+
* `edge` — an edge of the moved shape met an edge / centre of `other`;
|
|
28
|
+
* `center` — the moved shape's centre line snapped. Only edge guides get
|
|
29
|
+
* distance segments (the gap between the two shapes along the guide).
|
|
30
|
+
*/
|
|
31
|
+
readonly kind: "edge" | "center";
|
|
32
|
+
/** World AABB of the moved / resized shape where it landed. */
|
|
33
|
+
readonly moving: Bounds;
|
|
34
|
+
/** World AABB of the shape it aligned with. */
|
|
35
|
+
readonly other: Bounds;
|
|
36
|
+
}
|
|
37
|
+
export interface ObjectSnapResult {
|
|
38
|
+
readonly delta: Vec2;
|
|
39
|
+
readonly guides: readonly SnapGuide[];
|
|
40
|
+
}
|
|
41
|
+
/** The shape whose size a resize now matches, and on which axis. */
|
|
42
|
+
export interface SizeMatch {
|
|
43
|
+
readonly bounds: Bounds;
|
|
44
|
+
readonly axis: "width" | "height" | "both";
|
|
45
|
+
}
|
|
46
|
+
export interface ResizeSnapResult extends ObjectSnapResult {
|
|
47
|
+
readonly sizeMatch: SizeMatch | null;
|
|
48
|
+
}
|
|
49
|
+
export interface ResizeSnapOptions {
|
|
50
|
+
/** Snap the dragged edges to other shapes' edges / centres. */
|
|
51
|
+
readonly alignEdges: boolean;
|
|
52
|
+
/** Snap the width / height to other shapes' sizes. */
|
|
53
|
+
readonly matchSizes: boolean;
|
|
54
|
+
}
|
|
55
|
+
export interface MoveSnapOptions {
|
|
56
|
+
/**
|
|
57
|
+
* Offer the moved shape's centre lines (default `true`). A multi-shape
|
|
58
|
+
* selection snaps by its frame edges only, like the reference.
|
|
59
|
+
*/
|
|
60
|
+
readonly centerLines?: boolean;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Correct a move delta so the moved shape's edges / centres coincide with
|
|
64
|
+
* a nearby shape's — edge to edge, centre to centre. `moving` is the
|
|
65
|
+
* press-time world AABB; `others` are the candidate AABBs (not the moving
|
|
66
|
+
* shapes themselves).
|
|
67
|
+
*/
|
|
68
|
+
export declare const snapMoveDeltaToObjects: (moving: Bounds, delta: Vec2, others: readonly Bounds[], threshold: number, opts?: MoveSnapOptions) => ObjectSnapResult;
|
|
69
|
+
/**
|
|
70
|
+
* Correct a resize delta so the dragged edge(s) align with nearby shapes'
|
|
71
|
+
* edges / centres (`alignEdges`) or so the width / height matches a nearby
|
|
72
|
+
* shape's (`matchSizes`). Per axis the smaller correction wins; the
|
|
73
|
+
* stationary edges never move. `original` is the press-time world AABB.
|
|
74
|
+
*/
|
|
75
|
+
export declare const snapResizeDeltaToObjects: (original: Bounds, handle: HandleId, delta: Vec2, others: readonly Bounds[], threshold: number, opts: ResizeSnapOptions) => ResizeSnapResult;
|
|
76
|
+
/**
|
|
77
|
+
* Gaps between two extents along a guide (reference "distance" intervals):
|
|
78
|
+
* `[a1, a2]` is the aligned-with shape's extent, `[b1, b2]` the moved
|
|
79
|
+
* shape's. Disjoint extents yield the single gap between them; partially
|
|
80
|
+
* overlapping ones yield the two non-shared stretches; identical or nested
|
|
81
|
+
* extents yield nothing.
|
|
82
|
+
*/
|
|
83
|
+
export declare const gapIntervals: (a1: number, a2: number, b1: number, b2: number) => readonly {
|
|
84
|
+
readonly start: number;
|
|
85
|
+
readonly end: number;
|
|
86
|
+
}[];
|
|
87
|
+
//# sourceMappingURL=object-snap.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"object-snap.d.ts","sourceRoot":"","sources":["../../../src/editor/applies/object-snap.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,wBAAwB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