@n-uf/placement 26.11.52 → 26.11.54

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.
Files changed (62) hide show
  1. package/CHANGELOG.md +89 -1
  2. package/README.md +27 -58
  3. package/dist/{chunk-VLTYJHUA.js → chunk-2UVUFEBP.js} +4 -8
  4. package/dist/{chunk-VLTYJHUA.js.map → chunk-2UVUFEBP.js.map} +1 -1
  5. package/dist/{geometry-Bf37LbCT.d.ts → geometry-L5gCoiZV.d.ts} +2 -8
  6. package/dist/index.d.ts +64 -42
  7. package/dist/index.js +6 -66
  8. package/dist/index.js.map +1 -1
  9. package/dist/popup.d.ts +49 -0
  10. package/dist/popup.js +58 -0
  11. package/dist/popup.js.map +1 -0
  12. package/dist/stack.d.ts +529 -228
  13. package/dist/stack.js +701 -28
  14. package/dist/stack.js.map +1 -1
  15. package/dist/tiling.d.ts +48 -5
  16. package/dist/tiling.js +198 -19
  17. package/dist/tiling.js.map +1 -1
  18. package/package.json +9 -36
  19. package/dist/chunk-2GGJ4GVR.js +0 -9
  20. package/dist/chunk-2GGJ4GVR.js.map +0 -1
  21. package/dist/chunk-3ZICYLWL.js +0 -791
  22. package/dist/chunk-3ZICYLWL.js.map +0 -1
  23. package/dist/chunk-67D32MZ4.js +0 -4178
  24. package/dist/chunk-67D32MZ4.js.map +0 -1
  25. package/dist/chunk-AE3BWTAE.js +0 -838
  26. package/dist/chunk-AE3BWTAE.js.map +0 -1
  27. package/dist/chunk-JVAR67OL.js +0 -172
  28. package/dist/chunk-JVAR67OL.js.map +0 -1
  29. package/dist/chunk-NF7RYK3U.js +0 -429
  30. package/dist/chunk-NF7RYK3U.js.map +0 -1
  31. package/dist/chunk-R3AAANRY.js +0 -220
  32. package/dist/chunk-R3AAANRY.js.map +0 -1
  33. package/dist/chunk-TWI644JK.js +0 -221
  34. package/dist/chunk-TWI644JK.js.map +0 -1
  35. package/dist/constructions-Cbz7uEAZ.d.ts +0 -251
  36. package/dist/desk.d.ts +0 -51
  37. package/dist/desk.js +0 -111
  38. package/dist/desk.js.map +0 -1
  39. package/dist/dock.d.ts +0 -25
  40. package/dist/dock.js +0 -397
  41. package/dist/dock.js.map +0 -1
  42. package/dist/float-fit-DCYxRMru.d.ts +0 -37
  43. package/dist/lanes-DIwUqchd.d.ts +0 -1321
  44. package/dist/model-X7eUaKlA.d.ts +0 -337
  45. package/dist/panels.d.ts +0 -60
  46. package/dist/panels.js +0 -99
  47. package/dist/panels.js.map +0 -1
  48. package/dist/regions-Db_RyT4P.d.ts +0 -48
  49. package/dist/scene-cases.d.ts +0 -888
  50. package/dist/scene-cases.js +0 -3149
  51. package/dist/scene-cases.js.map +0 -1
  52. package/dist/scene.d.ts +0 -290
  53. package/dist/scene.js +0 -128
  54. package/dist/scene.js.map +0 -1
  55. package/dist/target-BBOCeez2.d.ts +0 -69
  56. package/dist/targets-C9ZVhmCl.d.ts +0 -621
  57. package/dist/targets.d.ts +0 -212
  58. package/dist/targets.js +0 -447
  59. package/dist/targets.js.map +0 -1
  60. package/dist/toolbar.d.ts +0 -167
  61. package/dist/toolbar.js +0 -55
  62. package/dist/toolbar.js.map +0 -1
package/dist/targets.d.ts DELETED
@@ -1,212 +0,0 @@
1
- import { T as Target } from './target-BBOCeez2.js';
2
- import { R as Rect, P as Point, S as Size } from './geometry-Bf37LbCT.js';
3
- import { D as DeskState, g as Layout, a as Construction, O as Options } from './constructions-Cbz7uEAZ.js';
4
- import { Place, Arrangement, HostId, HostSpec, GroupSize } from './toolbar.js';
5
- import { d as PanelTarget, s as PanelStopsOptions, r as PanelStop } from './targets-C9ZVhmCl.js';
6
- import { P as PaneSide, a as PaneCenter, b as PaneRegion } from './regions-Db_RyT4P.js';
7
-
8
- /**
9
- * Each desk construction's drop targets, as pure functions: from the state with the dragged item lifted out, a list
10
- * of zones with a priority, each able to make the state with the item dropped there.
11
- *
12
- * - Edge docks (`docks`, `docksFull`, `dockTear`): a rail (priority 1) takes the panel at the end of its dock (a
13
- * folded dock keeps it in the rail); a slot between sections (2) and the bottom dock (2) take it at that place;
14
- * with tear-off, the documents area (3) tears it off to float there.
15
- * - Tiling tree (`tree`): each slot an insertion produces (2), a side column's row or a dwindle region of the
16
- * center; an empty side column's edge (2).
17
- * - Strip (`strip`): between two columns (2) makes a new column; a gap inside a column (2) puts it there.
18
- * - Navigator, drawers (`navigator`, `drawers`): a tab strip (1) at the tab under the pointer, a folded side's rail
19
- * (1), a side's panel (3); the panel becomes the side's showing one.
20
- * - Palettes (`floatOver`, `floatAround`): a corner stack's column (2) at the place under the pointer; anywhere
21
- * else in the area (3), snapped to the area's edges (over the documents, also to other palettes' edges).
22
- */
23
-
24
- /** A target's drop for a pointer: the state with the item there, a label, and a key (same key, same place). */
25
- interface Made {
26
- readonly state: DeskState;
27
- readonly label: string;
28
- readonly key: string;
29
- }
30
- interface DeskTarget extends Target {
31
- /** The drop with the pointer at `p`, holding the item at `grab` from its top-left corner. */
32
- readonly make: (p: Point, grab: Point) => Made;
33
- /** Where the keyboard stops in this target, in order (default: its zone's center). */
34
- readonly stops?: readonly Point[];
35
- }
36
- /** A made drop, laid out. */
37
- interface DeskDrop extends Made {
38
- readonly target: string;
39
- readonly layout: Layout;
40
- /** Where the item lands. */
41
- readonly slot: Rect;
42
- /** It lands hidden (folded into a rail). */
43
- readonly hidden: boolean;
44
- /** It floats where it is dropped: no room is made for it. */
45
- readonly free: boolean;
46
- }
47
- interface DeskTargetInput {
48
- readonly c: Construction;
49
- /** The state with the dragged item lifted out (`liftOut`). */
50
- readonly s0: DeskState;
51
- readonly key: string;
52
- readonly size: Size;
53
- readonly opt: Options;
54
- }
55
- /** How close (stage px) a free drop has to come to an edge to snap to it. */
56
- declare const SNAP = 18;
57
- /** The drop targets for dragging `key` in construction `c`, in a fixed order (the keyboard's). */
58
- declare function deskTargets(input: DeskTargetInput): DeskTarget[];
59
- /** A target's drop for a pointer at `p` holding the item at `grab`, laid out: where the item lands. */
60
- declare function deskDrop(input: DeskTargetInput, target: DeskTarget, p: Point, grab: Point): DeskDrop;
61
-
62
- /**
63
- * Toolbar group targets: a host's insertion points (lines between groups, priority 2) and empty zones (priority 1),
64
- * and floating over the content (priority 3). A group's own place is home, never a target: its stretch comes back
65
- * in `own`, for the consumer to join to the drag's home. A place `allows` forbids is no host target either.
66
- */
67
-
68
- /** How far a line's hit reaches beyond the host's thickness on each side; an empty zone's. */
69
- declare const LINE_REACH = 12;
70
- declare const ZONE_REACH = 4;
71
- interface ToolbarTarget<G extends string = string> extends Target {
72
- readonly label: string;
73
- readonly kind: "line" | "zone";
74
- readonly place: Place;
75
- /** It lands in a side edge's column. */
76
- readonly vertical: boolean;
77
- /** The insertion line (3 px, inset 4 px from the host's sides) in stage coordinates; for an empty zone, at its middle. */
78
- readonly line: Rect;
79
- /** Where the group lands, in stage coordinates: its rect in the host once the drop is made. */
80
- readonly slot: Rect;
81
- /** The arrangement a drop here makes. */
82
- readonly arrangement: Arrangement<G>;
83
- }
84
- /**
85
- * Where a group may go: a host's place, or floating. `hostTargets` leaves out a place it refuses; for floating, the
86
- * consumer adds `floatTarget` only when `allows(group, "float")`, so one rule covers both. `place.index` counts the
87
- * groups in that zone without the dragged one (as `insertGroup` does): 0 is before all of the others.
88
- */
89
- type Allows<G extends string> = (group: G, place: Place | "float") => boolean;
90
- interface HostTargetsInput<G extends string> {
91
- readonly group: G;
92
- /** The arrangement as it is, the group still in its place. */
93
- readonly arrangement: Arrangement<G>;
94
- readonly host: HostId;
95
- /** The host's top-left corner in stage coordinates. */
96
- readonly origin: Point;
97
- readonly spec: HostSpec<G>;
98
- readonly size: GroupSize<G>;
99
- /** A group's name in the labels (default: its id). */
100
- readonly label?: (g: G) => string;
101
- /** Where the group may go (default: anywhere). A place it may not go is left out. */
102
- readonly allows?: Allows<G>;
103
- /**
104
- * Where this host is, and how long, once a drop has made `arrangement` (a host may grow or appear when it gets a
105
- * group); default: where it is now. The targets' `slot`s are laid out there.
106
- */
107
- readonly hostAfter?: (arrangement: Arrangement<G>) => {
108
- readonly origin: Point;
109
- readonly spec: HostSpec<G>;
110
- };
111
- }
112
- /** The targets a host offers a dragged group, zone by zone in order, and the stretches that are its own place. */
113
- declare function hostTargets<G extends string>(input: HostTargetsInput<G>): {
114
- targets: ToolbarTarget<G>[];
115
- own: Rect[];
116
- };
117
- interface ToolbarFloatTarget<G extends string = string> extends Target {
118
- readonly label: string;
119
- readonly kind: "float";
120
- /** The group's top-left corner relative to the stage, and the arrangement, for a drop with the pointer at `p`. */
121
- readonly make: (p: Point, grab: Point) => Arrangement<G>;
122
- }
123
- interface FloatTargetInput<G extends string> {
124
- readonly group: G;
125
- readonly arrangement: Arrangement<G>;
126
- /** The content the group floats over, in stage coordinates. */
127
- readonly stage: Rect;
128
- /** The group's size as it floats. */
129
- readonly width: number;
130
- readonly height: number;
131
- }
132
- /**
133
- * Floating over the content (`stage`, in stage coordinates): the group's top-left corner kept on the stage. A
134
- * group that may not float simply gets no float target: add it only when your rule allows it, with the same
135
- * `allows` you give `hostTargets`: `...(allows(group, "float") ? [floatTarget(input)] : [])`.
136
- */
137
- declare function floatTarget<G extends string>(input: FloatTargetInput<G>): ToolbarFloatTarget<G>;
138
-
139
- /**
140
- * Keyboard stops: every place a toolbar group can go, in one list in reading order, for the arrow keys and a
141
- * "Move to" menu alike. A consumer steps through the list; it never parses target ids.
142
- */
143
-
144
- /** The hosts in reading order: the title bar, the top bar, the left edge, the right edge, the bottom bar. */
145
- declare const HOST_READING_ORDER: readonly HostId[];
146
- interface KeyboardStop<G extends string = string> {
147
- /** The target's id ("home" for the group's own place). */
148
- readonly id: string;
149
- readonly label: string;
150
- /** Where in a host it is; null for floating. */
151
- readonly place: Place | null;
152
- /** The arrangement a move here makes (the current one for home). */
153
- readonly arrangement: Arrangement<G>;
154
- /** The group's own place: where the keyboard starts, and a move there changes nothing. */
155
- readonly home: boolean;
156
- }
157
- interface KeyboardStopsOptions<G extends string> {
158
- /** The group's own place, as a stop of its own in its reading-order position (the targets leave it out). */
159
- readonly home?: {
160
- readonly place: Place;
161
- readonly arrangement: Arrangement<G>;
162
- readonly label?: string;
163
- };
164
- /**
165
- * Floating targets as stops at the end (default: left out). `at` is where the pointer would drop it and `grab`
166
- * where it holds the group (default: the float target's middle, the group's top-left corner).
167
- */
168
- readonly floats?: boolean | {
169
- readonly at: Point;
170
- readonly grab?: Point;
171
- };
172
- }
173
- /**
174
- * The places a group can go, in reading order: toolbar areas title → top → left → right → bottom, zones start → center →
175
- * end, then each insertion point in order; the group's own place among them when `home` is given; floating targets
176
- * at the end only when `floats` asks for them. One list serves the arrow keys and a "Move to" menu.
177
- *
178
- * Given panel targets (`@n-uf/placement/panels`' `panelTargets`), the same for a panel: left to right across the
179
- * stage (the left rail, the left side's lines and columns outer to inner, the right side's inner to outer, the right
180
- * rail), floating last when asked; each stop carries the state a move there makes (`panelStops`).
181
- */
182
- declare function keyboardStops(targets: readonly PanelTarget[], options?: PanelStopsOptions): PanelStop[];
183
- declare function keyboardStops<G extends string>(targets: readonly (ToolbarTarget<G> | ToolbarFloatTarget<G>)[], options?: KeyboardStopsOptions<G>): KeyboardStop<G>[];
184
-
185
- /**
186
- * A pane's drop zones, the old names of `@n-uf/placement/tiling`'s pane drop regions. Each wraps the tiling function
187
- * and maps the old option names; all are deprecated and go when this entry does.
188
- */
189
-
190
- /** @deprecated Use `PaneRegion` from `@n-uf/placement/tiling`. */
191
- type PaneZone = PaneRegion;
192
- /** @deprecated Use `PANE_SIDES` from `@n-uf/placement/tiling`. */
193
- declare const PANE_EDGES: readonly PaneSide[];
194
- /** @deprecated Use `PaneRegionOptions` from `@n-uf/placement/tiling` (`center`, `centerX`, `centerY`, `centerMin`). */
195
- interface PaneZoneOptions {
196
- readonly centre?: number;
197
- readonly centreX?: number;
198
- readonly centreY?: number;
199
- readonly centreMin?: number;
200
- readonly hysteresis?: number;
201
- readonly pixelRatio?: number;
202
- }
203
- /** @deprecated Use `PANE_REGION_DEFAULTS` from `@n-uf/placement/tiling`. */
204
- declare const PANE_ZONE_DEFAULTS: Required<Omit<PaneZoneOptions, "centreX" | "centreY">>;
205
- /** @deprecated Use `PaneCenter` from `@n-uf/placement/tiling`. */
206
- type PaneCentre = PaneCenter;
207
- /** @deprecated Use `paneCenter` from `@n-uf/placement/tiling`. */
208
- declare const paneCentre: (size: Size, options?: PaneZoneOptions) => PaneCenter;
209
- /** @deprecated Use `paneRegion` from `@n-uf/placement/tiling`. */
210
- declare const paneZone: (rect: Rect, point: Point, previous?: PaneZone | null, options?: PaneZoneOptions) => PaneZone;
211
-
212
- export { type Allows, type DeskDrop, type DeskTarget, type DeskTargetInput, type FloatTargetInput, HOST_READING_ORDER, type HostTargetsInput, type KeyboardStop, type KeyboardStopsOptions, LINE_REACH, type Made, PANE_EDGES, PANE_ZONE_DEFAULTS, type PaneCentre, type PaneZone, type PaneZoneOptions, SNAP, Target, type ToolbarFloatTarget, type ToolbarTarget, ZONE_REACH, deskDrop, deskTargets, floatTarget, hostTargets, keyboardStops, paneCentre, paneZone };
package/dist/targets.js DELETED
@@ -1,447 +0,0 @@
1
- import {
2
- BAR,
3
- DOCK,
4
- G,
5
- OVER_MARGIN,
6
- PALETTE_NARROW,
7
- RAIL,
8
- TITLE,
9
- TORN_W,
10
- TREE_COLUMN,
11
- dockGeometry,
12
- idOf,
13
- isDocKey,
14
- isPanelKey,
15
- paletteArea,
16
- paletteWidth,
17
- panelKey,
18
- stripColumns,
19
- stripGeometry,
20
- touch,
21
- treeArea,
22
- treeFloats,
23
- treeRails,
24
- treeShown,
25
- treeTiles
26
- } from "./chunk-NF7RYK3U.js";
27
- import {
28
- PANE_REGION_DEFAULTS,
29
- PANE_SIDES,
30
- paneCenter,
31
- paneRegion
32
- } from "./chunk-R3AAANRY.js";
33
- import {
34
- HOST_LABEL,
35
- ZONES,
36
- floatGroup,
37
- insertGroup,
38
- insertions,
39
- isOwnPlace,
40
- layoutHost,
41
- vertical,
42
- withoutGroup,
43
- zoneLabel
44
- } from "./chunk-TWI644JK.js";
45
- import {
46
- panelStops
47
- } from "./chunk-3ZICYLWL.js";
48
- import {
49
- centre,
50
- clamp,
51
- overlap,
52
- rect
53
- } from "./chunk-VLTYJHUA.js";
54
-
55
- // src/targets/desk.ts
56
- var SNAP = 18;
57
- var insert = (list, i, x) => [...list.slice(0, i), x, ...list.slice(i)];
58
- var Cap = (s) => s === "left" ? "Left" : "Right";
59
- var fixed = (state, label) => () => ({ state, label, key: label });
60
- var slotSpan = (mids, lo, hi, i) => [i === 0 ? lo : mids[i - 1], i === mids.length ? hi : mids[i]];
61
- function dockTargets({ c, s0, key, size, opt }) {
62
- const cat = c.desk.catalog;
63
- const out = [];
64
- const id = idOf(key);
65
- const mode = c.id === "docksFull" ? "full" : "between";
66
- const d = dockGeometry(cat, s0, size, opt, mode);
67
- const l0 = c.layout(s0, size, opt);
68
- const W = size.width;
69
- const H = size.height;
70
- for (const side of ["left", "right"]) {
71
- const railed = l0.items.get(`rail:${side}`);
72
- if (!railed) continue;
73
- const label = `${Cap(side)} rail: into the ${side} dock`;
74
- out.push({ id: `rail:${side}`, priority: 1, hit: railed.rect, make: fixed(touch({ ...s0, [side]: [...s0[side], id] }, id), label) });
75
- if (side === "left" ? !d.lOpen : !d.rOpen) continue;
76
- const shown = side === "left" ? s0.left : d.right;
77
- const mids = shown.map((p) => centre(l0.items.get(panelKey(p)).rect).y);
78
- const x = side === "left" ? RAIL : W - RAIL - DOCK;
79
- for (let i = 0; i <= shown.length; i++) {
80
- const [y0, y1] = slotSpan(mids, 0, d.h, i);
81
- const state = i <= s0[side].length ? { ...s0, [side]: insert(s0[side], i, id) } : { ...s0, bottom: insert(s0.bottom, i - s0[side].length, id) };
82
- out.push({ id: `dock:${side}:${i}`, priority: 2, hit: rect(x, y0, DOCK, y1 - y0), make: fixed(touch(state, id), `${Cap(side)} dock \xB7 slot ${i + 1}`) });
83
- }
84
- }
85
- if (opt.bottom !== "off") {
86
- const b = d.bottomRect ?? rect(d.x0, H - 40 - G, d.x1 - d.x0, 40);
87
- const mids = s0.bottom.map((p) => centre(l0.items.get(panelKey(p)).rect).x);
88
- for (let i = 0; i <= s0.bottom.length; i++) {
89
- const [x0, x1] = slotSpan(mids, b.x, b.x + b.width, i);
90
- out.push({ id: `bottom:${i}`, priority: 2, hit: rect(x0, b.y - 24, x1 - x0, H - b.y + 24), make: fixed(touch({ ...s0, bottom: insert(s0.bottom, i, id) }, id), `Bottom dock \xB7 slot ${i + 1}`) });
91
- }
92
- }
93
- if (c.id === "dockTear") {
94
- out.push({
95
- id: "float",
96
- priority: 3,
97
- free: true,
98
- hit: rect(d.x0, 0, d.x1 - d.x0, H),
99
- make: (p, grab) => {
100
- let x = p.x - grab.x;
101
- let y = p.y - grab.y;
102
- if (Math.abs(x - d.x0) < SNAP) x = d.x0;
103
- if (Math.abs(x + TORN_W - d.x1) < SNAP) x = d.x1 - TORN_W;
104
- if (Math.abs(y - G) < SNAP) y = G;
105
- x = clamp(x, 0, W - TORN_W);
106
- y = clamp(y, 0, H - Math.min(cat.natural(id), H));
107
- return { state: touch({ ...s0, torn: [...s0.torn, { id, at: { x, y } }] }, id), label: "Float here", key: `float:${Math.round(x)},${Math.round(y)}` };
108
- }
109
- });
110
- }
111
- return out;
112
- }
113
- function treeTargets({ c, s0, key, size }) {
114
- const cat = c.desk.catalog;
115
- const out = [];
116
- const area = treeArea(size, s0);
117
- const t = treeShown(s0);
118
- const rails = treeRails(s0);
119
- const sides = !isDocKey(key);
120
- for (const [side, group] of [["left", "L"], ["right", "R"]]) {
121
- if (!sides || !rails[side]) continue;
122
- const hit = rect(side === "left" ? 0 : size.width - RAIL, BAR, RAIL, size.height - BAR);
123
- out.push({ id: `rail:${side}`, priority: 1, hit, make: fixed({ ...s0, tree: { ...s0.tree, [group]: [...s0.tree[group], key] } }, `${Cap(side)} rail: into the ${side} column`) });
124
- }
125
- if (sides && s0.tree.L.length === 0) out.push({ id: "edge:L", priority: 2, hit: rect(area.x, area.y, 30, area.height), make: fixed({ ...s0, tree: { ...s0.tree, L: [key] } }, "New left column") });
126
- if (sides && s0.tree.R.length === 0) out.push({ id: "edge:R", priority: 2, hit: rect(area.x + area.width - 30, area.y, 30, area.height), make: fixed({ ...s0, tree: { ...s0.tree, R: [key] } }, "New right column") });
127
- const x0 = area.x + (t.L.length ? TREE_COLUMN + G : 0);
128
- const x1 = area.x + area.width - (t.R.length ? TREE_COLUMN + G : 0);
129
- const middle = rect(x0, area.y, x1 - x0, area.height);
130
- const NAME = { L: "Left column", R: "Right column", C: "Centre" };
131
- const seen = [];
132
- const sameZone = (a, b) => Math.max(Math.abs(a.x - b.x), Math.abs(a.y - b.y), Math.abs(a.width - b.width), Math.abs(a.height - b.height)) < 0.5;
133
- for (const group of ["L", "R", "C"]) {
134
- const list = t[group];
135
- if (group !== "C" && list.length === 0) continue;
136
- if (group !== "C" && !sides) continue;
137
- for (let i = 0; i <= list.length; i++) {
138
- const state = { ...s0, tree: { ...s0.tree, [group]: insert(list, i, key) } };
139
- const shown = treeShown(state);
140
- const tiled = treeFloats(cat, shown, area);
141
- const zone = treeTiles(cat, tiled.floats.includes(key) ? shown : tiled.tree, area).get(key);
142
- const label = `${NAME[group]}, ${landing(c, shown, area, key, group, middle)}`;
143
- if (seen.some((o) => o.label === label && sameZone(o.hit, zone))) continue;
144
- seen.push({ label, hit: zone });
145
- out.push({ id: `tile:${group}:${i}`, priority: 2, hit: zone, make: fixed(state, label) });
146
- }
147
- }
148
- return out;
149
- }
150
- function landing(c, tree, area, key, group, middle) {
151
- const cat = c.desk.catalog;
152
- const { tree: tiled, floats } = treeFloats(cat, tree, area);
153
- if (floats.includes(key)) return "it floats there (too small)";
154
- const others = floats.length ? `; ${floats.map(cat.title).join(", ")} ${floats.length > 1 ? "float" : "floats"}` : "";
155
- if (group !== "C") return `row ${tiled[group].indexOf(key) + 1} of ${tiled[group].length}${others}`;
156
- const x0 = tiled.L.length ? middle.x : area.x;
157
- const x1 = tiled.R.length ? middle.x + middle.width : area.x + area.width;
158
- return `${regionName(treeTiles(cat, tiled, area).get(key), rect(x0, area.y, x1 - x0, area.height))}${others}`;
159
- }
160
- function regionName(r, whole) {
161
- const near = (a, b) => Math.abs(a - b) < 1;
162
- const h = near(r.width, whole.width) ? "" : near(r.x, whole.x) ? "left" : near(r.x + r.width, whole.x + whole.width) ? "right" : "middle";
163
- const v = near(r.height, whole.height) ? "" : near(r.y, whole.y) ? "top" : near(r.y + r.height, whole.y + whole.height) ? "bottom" : "middle";
164
- if (!h && !v) return "all of it";
165
- if (!v) return `${h} part`;
166
- if (!h) return `${v} part`;
167
- return `${v} ${h}`;
168
- }
169
- function stripTargets({ c, s0, key, size, opt }) {
170
- const cat = c.desk.catalog;
171
- const out = [];
172
- const g = stripGeometry(cat, s0, size);
173
- const l0 = c.layout(s0, size, opt);
174
- const parts = [];
175
- s0.cols.forEach((col, owner) => {
176
- let start = 0;
177
- for (const keys of stripColumns(cat, [col], g.h)) {
178
- parts.push({ owner, start, keys });
179
- start += keys.length;
180
- }
181
- });
182
- const newColumn = (at, label) => ({ state: { ...s0, cols: insert(s0.cols, at, [key]) }, label, key: label });
183
- if (parts.length === 0) return [{ id: "strip", priority: 3, hit: rect(0, g.y, size.width, g.h), make: () => newColumn(0, "The strip") }];
184
- for (let k = 0; k <= parts.length; k++) {
185
- if (k < parts.length && parts[k].start !== 0) continue;
186
- const x = k < parts.length ? g.xs[k] - G / 2 : g.xs[parts.length - 1] + g.widths[parts.length - 1] + G / 2;
187
- const at = k < parts.length ? parts[k].owner : s0.cols.length;
188
- const label = k === 0 ? "New column at the start" : k === parts.length ? "New column at the end" : `New column before ${cat.title(parts[k].keys[0])}`;
189
- out.push({ id: `between:${at}`, priority: 2, hit: rect(x - 28, g.y, 56, g.h), make: () => newColumn(at, label) });
190
- }
191
- parts.forEach((part, k) => {
192
- const mids = part.keys.map((pk) => centre(l0.items.get(pk).rect).y);
193
- for (let j = 0; j <= part.keys.length; j++) {
194
- const [y0, y1] = slotSpan(mids, g.y, g.y + g.h, j);
195
- const at = part.start + j;
196
- const cols = s0.cols.map((col, ci) => ci === part.owner ? insert(col, at, key) : col);
197
- const label = `Into the column with ${cat.title(s0.cols[part.owner][0])} \xB7 ${at + 1}`;
198
- out.push({ id: `into:${part.owner}:${at}`, priority: 2, hit: rect(g.xs[k], y0, g.widths[k], y1 - y0), make: fixed({ ...s0, cols }, label) });
199
- }
200
- });
201
- return out;
202
- }
203
- function tabTargets({ c, s0, key, size, opt }) {
204
- const out = [];
205
- const id = idOf(key);
206
- const l0 = c.layout(s0, size, opt);
207
- const onSide = (side, i) => touch({ ...s0, [side]: insert(s0[side], i, id), active: { ...s0.active, [side]: id } }, id);
208
- for (const side of ["left", "right"]) {
209
- const list = s0[side];
210
- const tabs = l0.items.get(`tabs:${side}`);
211
- const railed = l0.items.get(`rail:${side}`);
212
- if (tabs && !tabs.hidden) {
213
- const r = tabs.rect;
214
- const tw = r.width / (list.length + 1);
215
- out.push({
216
- id: `tabs:${side}`,
217
- priority: 1,
218
- hit: rect(r.x, r.y - 4, r.width, r.height + 8),
219
- make: (p) => {
220
- const i = clamp(Math.floor((p.x - r.x) / tw), 0, list.length);
221
- const label = `${Cap(side)} tab strip \xB7 tab ${i + 1}`;
222
- return { state: onSide(side, i), label, key: label };
223
- },
224
- stops: Array.from({ length: list.length + 1 }, (_, i) => ({ x: r.x + tw * (i + 0.5), y: r.y + r.height / 2 }))
225
- });
226
- const panel = list.map((p) => l0.items.get(panelKey(p))).find((pl) => pl && !pl.hidden);
227
- if (panel) out.push({ id: `side:${side}`, priority: 3, hit: panel.rect, make: fixed(onSide(side, list.length), `${Cap(side)} side`) });
228
- }
229
- if (railed && !railed.hidden) out.push({ id: `rail:${side}`, priority: 1, hit: railed.rect, make: fixed(onSide(side, list.length), `${Cap(side)} rail`) });
230
- if (list.length === 0 && (!railed || railed.hidden)) {
231
- const hit = side === "left" ? rect(0, 0, 40, size.height) : rect(size.width - 40, 0, 40, size.height);
232
- out.push({ id: `edge:${side}`, priority: 2, hit, make: fixed(onSide(side, 0), `${Cap(side)} side`) });
233
- }
234
- }
235
- return out;
236
- }
237
- function paletteTargets({ c, s0, key, size, opt }) {
238
- const cat = c.desk.catalog;
239
- const out = [];
240
- const id = idOf(key);
241
- const { area } = paletteArea(size, opt);
242
- const m = c.id === "floatOver" ? OVER_MARGIN : 0;
243
- const pw = paletteWidth(size.width);
244
- const ph = s0.folded.includes(id) ? TITLE : cat.natural(id);
245
- const narrow = size.width < PALETTE_NARROW;
246
- const anchor = { left: area.x + m, right: area.x + area.width - m - pw };
247
- const l0 = c.layout(s0, size, opt);
248
- const rectOf = (pid) => l0.items.get(panelKey(pid)).rect;
249
- const tb = l0.items.get("toolbar");
250
- const pillRect = tb?.look === "pill" ? tb.rect : null;
251
- for (const side of narrow ? ["right"] : ["left", "right"]) {
252
- const ids = narrow ? [...s0.stacks.left, ...s0.stacks.right] : [...s0.stacks[side]];
253
- const bottom = ids.length ? Math.max(...ids.map((pid) => rectOf(pid).y + rectOf(pid).height)) : area.y + m;
254
- const at = (y) => ids.filter((pid) => centre(rectOf(pid)).y < y).length;
255
- const join = (i) => {
256
- let stacks = s0.stacks;
257
- if (!narrow) stacks = { ...stacks, [side]: insert(stacks[side], i, id) };
258
- else if (i <= s0.stacks.left.length) stacks = { ...stacks, left: insert(stacks.left, i, id) };
259
- else stacks = { ...stacks, right: insert(stacks.right, i - s0.stacks.left.length, id) };
260
- const label = `${narrow ? "The" : Cap(side)} corner stack \xB7 ${i + 1}`;
261
- return { state: touch({ ...s0, stacks }, id), label, key: label };
262
- };
263
- out.push({
264
- id: `stack:${side}`,
265
- priority: 2,
266
- hit: rect(anchor[side], area.y, pw, bottom + 30 - area.y),
267
- make: (p) => join(at(p.y)),
268
- stops: [area.y + m, ...ids.map((pid) => rectOf(pid).y + rectOf(pid).height + G / 2)].map((y) => ({ x: anchor[side] + pw / 2, y }))
269
- });
270
- }
271
- out.push({
272
- id: "free",
273
- priority: 3,
274
- free: true,
275
- hit: area,
276
- make: (p, grab) => {
277
- let x = p.x - grab.x;
278
- let y = p.y - grab.y;
279
- const snaps = [];
280
- if (Math.abs(x - anchor.left) < SNAP) [x, snaps[0]] = [anchor.left, "left edge"];
281
- else if (Math.abs(x - anchor.right) < SNAP) [x, snaps[0]] = [anchor.right, "right edge"];
282
- if (Math.abs(y - (area.y + m)) < SNAP) [y, snaps[1]] = [area.y + m, "top"];
283
- else if (Math.abs(y + ph - (area.y + area.height - m)) < SNAP) [y, snaps[1]] = [area.y + area.height - m - ph, "bottom"];
284
- if (c.id === "floatOver") {
285
- for (const [k, pl] of l0.items) {
286
- if (!isPanelKey(k) || pl.hidden) continue;
287
- const o = pl.rect;
288
- if (snaps[0] === void 0 && Math.abs(x - o.x) < SNAP) [x, snaps[0]] = [o.x, `${cat.title(k)}'s edge`];
289
- if (snaps[1] === void 0 && Math.abs(y - (o.y + o.height + G)) < SNAP && x < o.x + o.width && x + pw > o.x) [y, snaps[1]] = [o.y + o.height + G, `under ${cat.title(k)}`];
290
- }
291
- }
292
- x = clamp(x, area.x, area.x + area.width - pw);
293
- y = clamp(y, area.y, area.y + area.height - ph);
294
- if (pillRect && overlap(rect(x, y, pw, ph), pillRect) > 0) {
295
- y = pillRect.y < size.height / 2 ? pillRect.y + pillRect.height + G : pillRect.y - G - ph;
296
- y = clamp(y, 0, size.height - ph);
297
- snaps[1] = "clear of the toolbar";
298
- }
299
- const how = snaps.filter(Boolean).join(", ");
300
- return { state: touch({ ...s0, free: [...s0.free, { id, at: { x, y } }] }, id), label: how ? `Here \xB7 snapped to the ${how}` : "Here", key: `free:${Math.round(x)},${Math.round(y)}` };
301
- }
302
- });
303
- return out;
304
- }
305
- function deskTargets(input) {
306
- switch (input.c.id) {
307
- case "docks":
308
- case "docksFull":
309
- case "dockTear":
310
- return dockTargets(input);
311
- case "tree":
312
- return treeTargets(input);
313
- case "strip":
314
- return stripTargets(input);
315
- case "navigator":
316
- case "drawers":
317
- return tabTargets(input);
318
- case "floatOver":
319
- case "floatAround":
320
- return paletteTargets(input);
321
- }
322
- }
323
- function deskDrop(input, target, p, grab) {
324
- const made = target.make(p, grab);
325
- const layout = input.c.layout(made.state, input.size, input.opt);
326
- const placed = layout.items.get(input.key);
327
- return { ...made, key: `${target.id}|${made.key}`, target: target.id, layout, slot: placed.rect, hidden: !!placed.hidden, free: !!target.free };
328
- }
329
-
330
- // src/targets/toolbar.ts
331
- var LINE_REACH = 12;
332
- var ZONE_REACH = 4;
333
- function hostTargets(input) {
334
- const { group, arrangement: a, host: h, origin: o, spec } = input;
335
- const slotIn = (after) => {
336
- const at = input.hostAfter?.(after) ?? { origin: o, spec };
337
- const r = layoutHost(after[h], h, at.spec, input.size, after.collapsed).slots.get(group);
338
- return rect(at.origin.x + r.x, at.origin.y + r.y, r.width, r.height);
339
- };
340
- const a0 = withoutGroup(a, group);
341
- const l = layoutHost(a0[h], h, spec, input.size, a0.collapsed);
342
- const v = vertical(h);
343
- const T = spec.thickness;
344
- const across = (s0, s1, reach) => v ? rect(o.x - reach, o.y + s0, T + 2 * reach, s1 - s0) : rect(o.x + s0, o.y - reach, s1 - s0, T + 2 * reach);
345
- const targets = [];
346
- const own = [];
347
- const pts = insertions(a0[h], h, spec, l, input.label).sort((p, q) => ZONES.indexOf(p.zone) - ZONES.indexOf(q.zone) || p.index - q.index);
348
- for (const p of pts) {
349
- const [s0, s1] = p.span;
350
- const place = { host: h, zone: p.zone, index: p.index };
351
- if (isOwnPlace(a, group, place)) {
352
- own.push(across(s0, s1, LINE_REACH));
353
- continue;
354
- }
355
- if (input.allows && !input.allows(group, place)) continue;
356
- const after = insertGroup(a, group, h, p.zone, p.index);
357
- targets.push({
358
- id: `g:${h}:${p.zone}:${p.index}`,
359
- priority: p.empty ? 1 : 2,
360
- hit: p.empty ? across(s0, s1, ZONE_REACH) : across(s0, s1, LINE_REACH),
361
- label: p.label,
362
- kind: p.empty ? "zone" : "line",
363
- place,
364
- vertical: v,
365
- line: v ? rect(o.x + 4, o.y + p.at - 1.5, T - 8, 3) : rect(o.x + p.at - 1.5, o.y + 4, 3, T - 8),
366
- slot: slotIn(after),
367
- arrangement: after
368
- });
369
- }
370
- return { targets, own };
371
- }
372
- function floatTarget(input) {
373
- const { group, arrangement, stage } = input;
374
- return {
375
- id: "g:float",
376
- priority: 3,
377
- free: true,
378
- hit: stage,
379
- label: "Float here",
380
- kind: "float",
381
- // Kept on the stage; a group larger than the stage keeps its top-left corner on the stage's.
382
- make: (p, grab) => {
383
- const x = Math.max(0, Math.min(p.x - grab.x - stage.x, stage.width - input.width));
384
- const y = Math.max(0, Math.min(p.y - grab.y - stage.y, stage.height - input.height));
385
- return floatGroup(arrangement, group, x, y);
386
- }
387
- };
388
- }
389
-
390
- // src/targets/stops.ts
391
- var HOST_READING_ORDER = ["title", "top", "left", "right", "bottom"];
392
- var isFloat = (t) => t.kind === "float";
393
- var rank = (p) => HOST_READING_ORDER.indexOf(p.host) * 3e3 + ZONES.indexOf(p.zone) * 1e3 + p.index;
394
- var isPanelTargets = (targets, options) => targets.some((t) => "panel" in t) || targets.length === 0 && !!options.home && "state" in options.home;
395
- function keyboardStops(targets, options = {}) {
396
- if (isPanelTargets(targets, options)) return panelStops(targets, options);
397
- return toolbarStops(targets, options);
398
- }
399
- function toolbarStops(targets, options) {
400
- const placed = [];
401
- const floating = [];
402
- for (const t of targets) {
403
- if (!isFloat(t)) {
404
- placed.push({ id: t.id, label: t.label, place: t.place, arrangement: t.arrangement, home: false });
405
- continue;
406
- }
407
- if (!options.floats) continue;
408
- const at = options.floats === true ? centre(t.hit) : options.floats.at;
409
- const grab = options.floats === true ? { x: 0, y: 0 } : options.floats.grab ?? { x: 0, y: 0 };
410
- floating.push({ id: t.id, label: t.label, place: null, arrangement: t.make(at, grab), home: false });
411
- }
412
- const h = options.home;
413
- if (h) placed.push({ id: "home", label: h.label ?? `${HOST_LABEL[h.place.host]} \xB7 ${zoneLabel(h.place.host, h.place.zone)} \xB7 current place`, place: h.place, arrangement: h.arrangement, home: true });
414
- placed.sort((a, b) => rank(a.place) - rank(b.place));
415
- return [...placed, ...floating];
416
- }
417
-
418
- // src/targets/zones.ts
419
- var PANE_EDGES = PANE_SIDES;
420
- var R = PANE_REGION_DEFAULTS;
421
- var PANE_ZONE_DEFAULTS = { centre: R.center, centreMin: R.centerMin, hysteresis: R.hysteresis, pixelRatio: R.pixelRatio };
422
- var regionOptions = (o) => ({
423
- ...o.centre === void 0 ? {} : { center: o.centre },
424
- ...o.centreX === void 0 ? {} : { centerX: o.centreX },
425
- ...o.centreY === void 0 ? {} : { centerY: o.centreY },
426
- ...o.centreMin === void 0 ? {} : { centerMin: o.centreMin },
427
- ...o.hysteresis === void 0 ? {} : { hysteresis: o.hysteresis },
428
- ...o.pixelRatio === void 0 ? {} : { pixelRatio: o.pixelRatio }
429
- });
430
- var paneCentre = (size, options = {}) => paneCenter(size, regionOptions(options));
431
- var paneZone = (rect2, point, previous = null, options = {}) => paneRegion(rect2, point, previous, regionOptions(options));
432
- export {
433
- HOST_READING_ORDER,
434
- LINE_REACH,
435
- PANE_EDGES,
436
- PANE_ZONE_DEFAULTS,
437
- SNAP,
438
- ZONE_REACH,
439
- deskDrop,
440
- deskTargets,
441
- floatTarget,
442
- hostTargets,
443
- keyboardStops,
444
- paneCentre,
445
- paneZone
446
- };
447
- //# sourceMappingURL=targets.js.map