@n-uf/placement 26.11.54 → 26.11.56
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 +108 -0
- package/README.md +12 -1
- package/dist/index.d.ts +5 -39
- package/dist/index.js +0 -6
- package/dist/index.js.map +1 -1
- package/dist/stack.d.ts +146 -9
- package/dist/stack.js +176 -23
- package/dist/stack.js.map +1 -1
- package/dist/tiling.d.ts +212 -34
- package/dist/tiling.js +215 -36
- package/dist/tiling.js.map +1 -1
- package/package.json +2 -1
package/dist/tiling.d.ts
CHANGED
|
@@ -1,28 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { S as Size, R as Rect, P as Point } from './geometry-L5gCoiZV.js';
|
|
2
2
|
import { Target } from './index.js';
|
|
3
3
|
|
|
4
|
-
/**
|
|
5
|
-
* The order layouts: panes in order and an area in, a rect per pane out. Pure rect functions; a drop on one reorders
|
|
6
|
-
* (the dragged pane inserted at an index, see `orderTargets`).
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
/** How a layout spaces its panes: `gap` px between neighbors (default 0), `ratio` the master's share (default 0.5). */
|
|
10
|
-
interface TileOptions {
|
|
11
|
-
readonly gap?: number;
|
|
12
|
-
readonly ratio?: number;
|
|
13
|
-
}
|
|
14
|
-
/** An order layout: `masterStack`, `columns`, `grid`, or the app's own of the same shape. */
|
|
15
|
-
type OrderLayout = <K>(panes: readonly K[], area: Rect, options?: TileOptions) => Map<K, Rect>;
|
|
16
|
-
/**
|
|
17
|
-
* Master and stack: the first pane takes the left part (`ratio` of the width less the gap), the rest stack on the
|
|
18
|
-
* right in equal rows. One pane takes the whole area.
|
|
19
|
-
*/
|
|
20
|
-
declare function masterStack<K>(panes: readonly K[], area: Rect, options?: TileOptions): Map<K, Rect>;
|
|
21
|
-
/** Equal columns, full height. */
|
|
22
|
-
declare function columns<K>(panes: readonly K[], area: Rect, options?: TileOptions): Map<K, Rect>;
|
|
23
|
-
/** A grid as square as the count allows; the last row's cells widen to fill it. */
|
|
24
|
-
declare function grid<K>(panes: readonly K[], area: Rect, options?: TileOptions): Map<K, Rect>;
|
|
25
|
-
|
|
26
4
|
/**
|
|
27
5
|
* A pane's drop regions: a center rectangle (a drop there swaps with the pane) and four side trapezoids (a drop there
|
|
28
6
|
* splits the pane on that side), formed by the diagonals from each pane corner to the nearest corner of the center.
|
|
@@ -48,8 +26,14 @@ interface PaneRegionOptions {
|
|
|
48
26
|
readonly hysteresis?: number;
|
|
49
27
|
/** Device pixels per px: the center's edges snap to that grid, as the browser draws them. */
|
|
50
28
|
readonly pixelRatio?: number;
|
|
29
|
+
/**
|
|
30
|
+
* The pane's center rectangle as the host already has it (pane-local px, as `paneCenter` gives), used as it is in
|
|
31
|
+
* place of measuring: `center`, `centerX`, `centerY`, `centerMin` and `pixelRatio` are not read. Only `paneRegion`
|
|
32
|
+
* reads it; its `width` and `height` are the pane's own size for the hold toward the middle.
|
|
33
|
+
*/
|
|
34
|
+
readonly paneCenter?: PaneCenter;
|
|
51
35
|
}
|
|
52
|
-
declare const PANE_REGION_DEFAULTS: Required<Omit<PaneRegionOptions, "centerX" | "centerY">>;
|
|
36
|
+
declare const PANE_REGION_DEFAULTS: Required<Omit<PaneRegionOptions, "centerX" | "centerY" | "paneCenter">>;
|
|
53
37
|
/** The center rectangle of a pane of `size`, in pane-local px (origin at the pane's top-left corner). */
|
|
54
38
|
interface PaneCenter {
|
|
55
39
|
readonly width: number;
|
|
@@ -64,16 +48,68 @@ declare function paneCenter(size: Size, options?: PaneRegionOptions): PaneCenter
|
|
|
64
48
|
/**
|
|
65
49
|
* The drop region of `pane` (in the same coordinates as `point`) the point is in. With a `previous` region, the point
|
|
66
50
|
* has to be `hysteresis` px past that region's boundary before the region changes: no time-based debounce, only
|
|
67
|
-
* geometry.
|
|
51
|
+
* geometry. A host that has measured the center itself passes it as `options.paneCenter`; the same center gives the
|
|
52
|
+
* same region as the one measured here.
|
|
68
53
|
*/
|
|
69
54
|
declare function paneRegion(pane: Rect, point: Point, previous?: PaneRegion | null, options?: PaneRegionOptions): PaneRegion;
|
|
70
55
|
|
|
56
|
+
/**
|
|
57
|
+
* The order layouts: panes in order and an area in, a rect per pane out. Pure rect functions; a drop on one reorders
|
|
58
|
+
* (the dragged pane inserted at an index, see `orderTargets`).
|
|
59
|
+
*/
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* How a layout spaces its panes: `gap` px between neighbors (default 0), `ratio` the master's share (default 0.5),
|
|
63
|
+
* `handle` px a split's divider takes beside the gap (default 0; only a split tree reads it).
|
|
64
|
+
*/
|
|
65
|
+
interface TileOptions {
|
|
66
|
+
readonly gap?: number;
|
|
67
|
+
readonly ratio?: number;
|
|
68
|
+
readonly handle?: number;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* The master area: `count` panes (rounded, kept within 1..n; default 1) on `side` (default `"left"`). Left and right
|
|
72
|
+
* make it a column of panes stacked vertically; top and bottom a row of panes side by side. The one home of the
|
|
73
|
+
* concept: `masterStack` takes it in its options (`OrderOptions`), a split that lays out as master and stack in its
|
|
74
|
+
* `master` field.
|
|
75
|
+
*/
|
|
76
|
+
interface MasterOptions {
|
|
77
|
+
readonly count?: number;
|
|
78
|
+
readonly side?: PaneSide;
|
|
79
|
+
}
|
|
80
|
+
/** What the order layouts take: `TileOptions` and the master area's `count` and `side` (`columns` and `grid` ignore them). */
|
|
81
|
+
type OrderOptions = TileOptions & MasterOptions;
|
|
82
|
+
/** An order layout: `masterStack`, `columns`, `grid`, or the app's own of the same shape. */
|
|
83
|
+
type OrderLayout = <K>(panes: readonly K[], area: Rect, options?: OrderOptions) => Map<K, Rect>;
|
|
84
|
+
/** The master's share in effect: clamped to 0.05..0.95; one that is not finite is 0.5. */
|
|
85
|
+
declare const masterRatio: (v: number | undefined) => number;
|
|
86
|
+
/** How many of `n` panes are masters for a requested `count`: rounded, within 1..n; NaN is 1. */
|
|
87
|
+
declare function masterCount(count: number | undefined, n: number): number;
|
|
88
|
+
/**
|
|
89
|
+
* Master and stack: the first `count` panes are the masters, in an area on `side` that takes `ratio` of the room the
|
|
90
|
+
* gap leaves (clamped to 0.05..0.95; default 0.5); the rest are the stack, in the other area. Left and right make
|
|
91
|
+
* each area a column of panes stacked vertically; top and bottom a row of panes side by side. Right and bottom put
|
|
92
|
+
* the stack first in space. With no stack (n at most `count`) all the panes fill the area, stacked along the side's
|
|
93
|
+
* cross axis. Each area divides its length equally between its panes, the gap between them.
|
|
94
|
+
*/
|
|
95
|
+
declare function masterStack<K>(panes: readonly K[], area: Rect, options?: OrderOptions): Map<K, Rect>;
|
|
96
|
+
/** Equal columns, full height. */
|
|
97
|
+
declare function columns<K>(panes: readonly K[], area: Rect, options?: TileOptions): Map<K, Rect>;
|
|
98
|
+
/** A grid as square as the count allows; the last row's cells widen to fill it. */
|
|
99
|
+
declare function grid<K>(panes: readonly K[], area: Rect, options?: TileOptions): Map<K, Rect>;
|
|
100
|
+
|
|
71
101
|
/**
|
|
72
102
|
* The split tree: how panes divide an area. A node is a pane, or a split of its rect in two (`a` then `b`). A split
|
|
73
103
|
* with an `axis` divides along it (`"x"`: `a` left of `b`; `"y"`: `a` above `b`) at `ratio`; one without divides
|
|
74
104
|
* along the rect's longer side in halves, which is dwindle (split along the longer side). Pure: trees in, trees out.
|
|
75
105
|
*/
|
|
76
106
|
|
|
107
|
+
/**
|
|
108
|
+
* A pane, or a split of its rect in two, `a` then `b`. A split takes its `axis` and its `ratio` (the first side's
|
|
109
|
+
* share); `gap` replaces the layout's gap for this split (the handle stays global); `id` names the split so
|
|
110
|
+
* `layoutSplitTree` reports its geometry. With `master`, the split lays its subtree out flat: its panes, in order,
|
|
111
|
+
* as master and stack (`masterStack`) in its rect, by its `ratio` and gap; the splits under it are not laid out.
|
|
112
|
+
*/
|
|
77
113
|
type Split<K> = {
|
|
78
114
|
readonly pane: K;
|
|
79
115
|
} | {
|
|
@@ -81,14 +117,10 @@ type Split<K> = {
|
|
|
81
117
|
readonly b: Split<K>;
|
|
82
118
|
readonly axis?: "x" | "y";
|
|
83
119
|
readonly ratio?: number;
|
|
120
|
+
readonly gap?: number;
|
|
121
|
+
readonly id?: string;
|
|
122
|
+
readonly master?: MasterOptions;
|
|
84
123
|
};
|
|
85
|
-
/**
|
|
86
|
-
* The rect of every pane of `tree` in `area`, `gap` px between the two sides of each split. A split's `ratio` is
|
|
87
|
-
* clamped to 0..1; each side gets its share of the room the gap leaves (none when the gap is wider than the rect), so
|
|
88
|
-
* no size is ever negative, and at ratio 0.5 both sides are exactly equal. A split with no room lays both sides at no
|
|
89
|
-
* size inside its rect: the first at its start, the second at its end, never past it.
|
|
90
|
-
*/
|
|
91
|
-
declare function layoutSplit<K>(tree: Split<K> | null, area: Rect, options?: TileOptions): Map<K, Rect>;
|
|
92
124
|
/** The panes of `tree` in order (`a` before `b`). */
|
|
93
125
|
declare const panesOf: <K>(tree: Split<K> | null) => K[];
|
|
94
126
|
/**
|
|
@@ -111,6 +143,132 @@ declare function splitFromOrder<K>(panes: readonly K[]): Split<K> | null;
|
|
|
111
143
|
*/
|
|
112
144
|
declare function dropOnPane<K>(tree: Split<K> | null, dragged: K, at: K, region: PaneRegion): Split<K>;
|
|
113
145
|
|
|
146
|
+
/**
|
|
147
|
+
* The split tree laid out: the rect of every pane of a `Split` tree in an area, and the geometry of the splits that
|
|
148
|
+
* have an id. See docs/placement.md, Entry: tiling.
|
|
149
|
+
*/
|
|
150
|
+
|
|
151
|
+
/** A split child's fixed length along its split. `keep` marks one that holds its length even beside another. */
|
|
152
|
+
interface FixedLength {
|
|
153
|
+
readonly length: number;
|
|
154
|
+
readonly keep?: boolean;
|
|
155
|
+
}
|
|
156
|
+
/** A split child's least length along its split. `net` (default true) keeps the split's ratio within 5..95 %. */
|
|
157
|
+
interface MinLength {
|
|
158
|
+
readonly min: number;
|
|
159
|
+
readonly net?: boolean;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* What a split tree's layout reads of its host, each per split, of the split's two direct children.
|
|
163
|
+
*
|
|
164
|
+
* - `fixed(child, axis)`: the child's fixed length along the split, if it has one. The first child that reports one
|
|
165
|
+
* decides: it takes its length when the length is above 0 and, with the gutter, less than the extent, and the other
|
|
166
|
+
* side fills the rest (the gutter between). Otherwise, or with a length that does not fit, the split falls back to
|
|
167
|
+
* its ratio, and the other child's length is not read. When both report a length with `keep`, each keeps its own,
|
|
168
|
+
* in order, and the room left over stays empty; if the two (and the gutter) do not fit the extent, the second runs
|
|
169
|
+
* past the end. A split a fixed length decides has no divider and no floor.
|
|
170
|
+
* - `fixedAcross(child, axis)`: the child's fixed length across the split; the child takes it, when positive and
|
|
171
|
+
* finite, from the start of the cross axis instead of the whole cross extent. It is not checked against the cross
|
|
172
|
+
* extent: a length larger than the cross extent makes a pane larger than the split's box.
|
|
173
|
+
* - `floor(child, axis, split)`: the child's least length along the split. The ratio is clamped so each side keeps
|
|
174
|
+
* its floor of the room less the gutter, within the net (5..95 %) unless either side says `net: false`; where the
|
|
175
|
+
* two floors cannot both fit, the ratio is 0.5. With no `floor`, the ratio is only clamped to 0..1. `giveWay` is
|
|
176
|
+
* the other policy of the same minimum: it floats the newest pane instead of squeezing the ratio, and a host
|
|
177
|
+
* chooses one for a pane.
|
|
178
|
+
*/
|
|
179
|
+
interface SplitOptions<K> extends TileOptions {
|
|
180
|
+
readonly fixed?: (child: Split<K>, axis: "x" | "y") => FixedLength | undefined;
|
|
181
|
+
readonly fixedAcross?: (child: Split<K>, axis: "x" | "y") => number | undefined;
|
|
182
|
+
readonly floor?: (child: Split<K>, axis: "x" | "y", split: Split<K>) => MinLength;
|
|
183
|
+
}
|
|
184
|
+
/** A laid-out split: the box it divides, its axis and ratio in effect, and the strip between its two sides. */
|
|
185
|
+
interface SplitGeometry {
|
|
186
|
+
readonly rect: Rect;
|
|
187
|
+
readonly axis: "x" | "y";
|
|
188
|
+
/**
|
|
189
|
+
* The first side's share in effect: the middle of the gutter lies at the box's start plus its extent times this
|
|
190
|
+
* (for a fixed-length child, the middle of the gutter after the first side over the extent). For a master split
|
|
191
|
+
* it is the master area's share (clamped to 0.05..0.95) of the room less the gap, measured from the master's own
|
|
192
|
+
* side: with the master on the right, ratio 0.3 in 1000 with a gap of 10, the divider lies at 693..703.
|
|
193
|
+
*/
|
|
194
|
+
readonly ratio: number;
|
|
195
|
+
/** The gutter between the two sides, as a rect inside `rect`; null where the split has none. */
|
|
196
|
+
readonly divider: Rect | null;
|
|
197
|
+
}
|
|
198
|
+
/** A tree laid out: every pane's rect, and the geometry of each split that has an `id`. */
|
|
199
|
+
interface SplitLayout<K> {
|
|
200
|
+
readonly panes: Map<K, Rect>;
|
|
201
|
+
readonly splits: Map<string, SplitGeometry>;
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* The rect of every pane of `tree` in `area`. Each split's gutter is its gap (its own `gap`, else `options.gap`) plus
|
|
205
|
+
* `options.handle`. A split's `ratio` is clamped to 0..1 (one that is not finite is 0.5), and the middle of the gutter
|
|
206
|
+
* sits at `extent * ratio`: the first side is `extent * ratio` less half the gutter, the second starts half a gutter
|
|
207
|
+
* past it and is the rest less half the gutter. No size is ever negative: a side too short for half the gutter is 0
|
|
208
|
+
* along the axis, and the second side of a split with no room may then start up to half a gutter past the rect's end.
|
|
209
|
+
* At ratio 0.5 both sides are equal. `options.floor`, `fixed` and `fixedAcross` (see `SplitOptions`) read the host's
|
|
210
|
+
* minimums and fixed lengths per split. A negative or non-finite `gap` or `handle` is 0. The area is taken as given:
|
|
211
|
+
* with a negative width or height every length along that axis is 0 and a pane's size across it is copied as it
|
|
212
|
+
* is, so pass an area with no negative side.
|
|
213
|
+
*/
|
|
214
|
+
declare function layoutSplit<K>(tree: Split<K> | null, area: Rect, options?: SplitOptions<K>): Map<K, Rect>;
|
|
215
|
+
/**
|
|
216
|
+
* `layoutSplit` and the geometry of every split that has an `id` (a repeated id keeps the one laid out last: a split under another, or a later one beside it): the box it divides,
|
|
217
|
+
* its axis and ratio in effect (after the floors), and its divider, the gutter strip between its two sides. A split
|
|
218
|
+
* that lays out as master and stack is reported too, its nested splits are not.
|
|
219
|
+
*/
|
|
220
|
+
declare function layoutSplitTree<K>(tree: Split<K> | null, area: Rect, options?: SplitOptions<K>): SplitLayout<K>;
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Whether a drop on a pane leaves room: the rule a host asks before it offers a side of a pane as a drop place. See
|
|
224
|
+
* docs/placement.md, Entry: tiling.
|
|
225
|
+
*/
|
|
226
|
+
|
|
227
|
+
/** The layout options a drop is judged under, and `min`: the least width and height, px, a pane must keep. */
|
|
228
|
+
interface DropOptions<K> extends SplitOptions<K> {
|
|
229
|
+
readonly min: number;
|
|
230
|
+
}
|
|
231
|
+
/** A drop's verdict: `ok`, or not, with its `reason`. */
|
|
232
|
+
interface DropVerdict {
|
|
233
|
+
readonly ok: boolean;
|
|
234
|
+
readonly reason?: string;
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Whether dropping `dragged` on pane `at`'s `region` leaves both at least `options.min` wide and high.
|
|
238
|
+
*
|
|
239
|
+
* - The center is fine unless `dragged` is `at`, or `at` is not in the tree (nothing to swap with).
|
|
240
|
+
* - A side needs, in the layout of the tree without `dragged` (so `at` is measured where it will be when `dragged` is
|
|
241
|
+
* lifted out), a span of `at` along the split of at least `2 * min` plus the gutter (the options' gap plus handle)
|
|
242
|
+
* and across it of at least `min`; and in the layout of `dropOnPane(tree, dragged, at, region)` both `dragged` and
|
|
243
|
+
* `at` at least `min` wide and high. That check is skipped when `area` has no width or no height. A pane that is
|
|
244
|
+
* not in the tree counts as one being added; an `at` that is not in it (or is `dragged`) has no place to split.
|
|
245
|
+
*/
|
|
246
|
+
declare function canDropOnPane<K>(tree: Split<K> | null, dragged: K, at: K, region: PaneRegion, area: Rect, options: DropOptions<K>): DropVerdict;
|
|
247
|
+
/** What `canSplitPane` reads: `min` (as in `DropOptions`) and the gutter's parts, `gap` and `handle`, px. */
|
|
248
|
+
interface SplitRoomOptions {
|
|
249
|
+
readonly min: number;
|
|
250
|
+
readonly gap?: number;
|
|
251
|
+
readonly handle?: number;
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* The room rule: whether a pane of rect `target` can take another on `side`, both at least `options.min` wide and
|
|
255
|
+
* high. Along the split (width for left and right, height for top and bottom) the pane needs `2 * min` plus the
|
|
256
|
+
* gutter (`gap` plus `handle`), across it `min`. The rect is the pane's as the host measures it, where it will be
|
|
257
|
+
* when the dragged pane is lifted out. `canDropOnPane`'s first rule, for a side.
|
|
258
|
+
*/
|
|
259
|
+
declare function canSplitPane(target: Rect, side: PaneSide, options: SplitRoomOptions): DropVerdict;
|
|
260
|
+
/** What `dropFits` reads: the `min` (as in `DropOptions`) and the `side` of `at` the drop is on, for the reason. */
|
|
261
|
+
interface DropFitsOptions {
|
|
262
|
+
readonly min: number;
|
|
263
|
+
readonly side: PaneSide;
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* The fit rule: in `projected`, the rect of every pane in the layout the drop makes (the host's own projection of
|
|
267
|
+
* `dropOnPane`'s tree), whether `dragged` and `at` are both there and at least `options.min` wide and high. Fine
|
|
268
|
+
* when `area` has no width or no height (there is nothing to measure). `canDropOnPane`'s last rule.
|
|
269
|
+
*/
|
|
270
|
+
declare function dropFits<K>(projected: ReadonlyMap<K, Rect>, dragged: K, at: K, area: Rect, options: DropFitsOptions): DropVerdict;
|
|
271
|
+
|
|
114
272
|
/**
|
|
115
273
|
* Drop targets for tiling, in the root `Target` shape (what `@n-uf/motion/drag` takes). Both kinds come from one
|
|
116
274
|
* helper: a pane target (`pane:<id>`, its hit the pane, the place in it its drop region) for the split tree, and an
|
|
@@ -142,7 +300,7 @@ declare function paneTargets<K>(layout: ReadonlyMap<K, Rect>, options?: PaneTarg
|
|
|
142
300
|
* `area`. Each target's hit and slot is `dragged`'s rect with it there, so the targets cover the area as the layout
|
|
143
301
|
* does. Ids are `at:<index>`, unique whatever the panes are.
|
|
144
302
|
*/
|
|
145
|
-
declare function orderTargets<K>(arrange: OrderLayout, panes: readonly K[], dragged: K, area: Rect, options?:
|
|
303
|
+
declare function orderTargets<K>(arrange: OrderLayout, panes: readonly K[], dragged: K, area: Rect, options?: OrderOptions): OrderTarget<K>[];
|
|
146
304
|
|
|
147
305
|
/**
|
|
148
306
|
* The minimum-size give-way: while a pane is laid out below its minimum, the newest pane (highest `age`) floats and
|
|
@@ -154,4 +312,24 @@ declare function giveWay<K>(panes: readonly K[], layout: (kept: readonly K[]) =>
|
|
|
154
312
|
floats: K[];
|
|
155
313
|
};
|
|
156
314
|
|
|
157
|
-
|
|
315
|
+
/**
|
|
316
|
+
* The nearest pane in a direction: the rule a host moves focus by. See docs/placement.md, Entry: tiling.
|
|
317
|
+
*/
|
|
318
|
+
|
|
319
|
+
/** A direction on the plane: `"up"` is toward smaller y. */
|
|
320
|
+
type Direction = "left" | "right" | "up" | "down";
|
|
321
|
+
/**
|
|
322
|
+
* The pane nearest `from` in `direction`, or null when none lies that way. A candidate's center has to be strictly on
|
|
323
|
+
* that side of `from`'s center. Its score is the center distance along the direction, plus a quarter of the center
|
|
324
|
+
* distance across it, plus 100 when it does not overlap `from` across the direction (the overlap strictly above 0);
|
|
325
|
+
* the lowest score wins, ties to the first in the map's order. A pane that is not in `rects` has no neighbor.
|
|
326
|
+
*
|
|
327
|
+
* The host chooses which rects to pass. One option: lay the tree out in a unit square (`{ x: 0, y: 0, width: 1,
|
|
328
|
+
* height: 1 }`) with the host's px floors. A floor of tens of px cannot fit in a unit square, so a split's two floors
|
|
329
|
+
* cannot both fit and it lays out at 0.5 whatever its ratio; fixed lengths in px along a split do not fit either, and
|
|
330
|
+
* the area's size and the gap drop out. Fixed lengths across a split are not checked against the cross extent, so
|
|
331
|
+
* they still apply in a unit square, and a host leaves `fixedAcross` out there. The rects of the real layout work too.
|
|
332
|
+
*/
|
|
333
|
+
declare function neighbor<K>(rects: ReadonlyMap<K, Rect>, from: K, direction: Direction): K | null;
|
|
334
|
+
|
|
335
|
+
export { type Direction, type DropFitsOptions, type DropOptions, type DropVerdict, type FixedLength, type MasterOptions, type MinLength, type OrderLayout, type OrderOptions, type OrderTarget, PANE_REGION_DEFAULTS, PANE_SIDES, type PaneCenter, type PaneRegion, type PaneRegionOptions, type PaneSide, type PaneTarget, type PaneTargetsOptions, Rect, type Split, type SplitGeometry, type SplitLayout, type SplitOptions, type SplitRoomOptions, type TileOptions, canDropOnPane, canSplitPane, columns, dropFits, dropOnPane, giveWay, grid, layoutSplit, layoutSplitTree, masterCount, masterRatio, masterStack, neighbor, orderTargets, paneCenter, paneRegion, paneTargets, panesOf, removePane, splitFromOrder, splitPane, swapPanes };
|
package/dist/tiling.js
CHANGED
|
@@ -3,19 +3,51 @@ import {
|
|
|
3
3
|
} from "./chunk-2UVUFEBP.js";
|
|
4
4
|
|
|
5
5
|
// src/tiling/order.ts
|
|
6
|
+
var masterRatio = (v) => v === void 0 || !Number.isFinite(v) ? 0.5 : Math.min(0.95, Math.max(0.05, v));
|
|
7
|
+
function masterCount(count, n) {
|
|
8
|
+
const c = Math.round(count ?? 1);
|
|
9
|
+
return Math.min(Math.max(Number.isNaN(c) ? 1 : c, 1), Math.max(n, 1));
|
|
10
|
+
}
|
|
11
|
+
function divide(items, x, y, width, height, vertical, gap, out) {
|
|
12
|
+
const n = items.length;
|
|
13
|
+
const total = gap * (n - 1);
|
|
14
|
+
if (vertical) {
|
|
15
|
+
const each = Math.max(0, (height - total) / n);
|
|
16
|
+
items.forEach((pane, i) => out.set(pane, { x, y: y + i * (each + gap), width, height: each }));
|
|
17
|
+
} else {
|
|
18
|
+
const each = Math.max(0, (width - total) / n);
|
|
19
|
+
items.forEach((pane, i) => out.set(pane, { x: x + i * (each + gap), y, width: each, height }));
|
|
20
|
+
}
|
|
21
|
+
}
|
|
6
22
|
function masterStack(panes, area, options = {}) {
|
|
7
|
-
const gap = options.gap
|
|
23
|
+
const gap = options.gap !== void 0 && Number.isFinite(options.gap) && options.gap > 0 ? options.gap : 0;
|
|
8
24
|
const out = /* @__PURE__ */ new Map();
|
|
9
25
|
if (panes.length === 0) return out;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
26
|
+
const side = options.side ?? "left";
|
|
27
|
+
const ratio = masterRatio(options.ratio);
|
|
28
|
+
const count = masterCount(options.count, panes.length);
|
|
29
|
+
const masters = panes.slice(0, count);
|
|
30
|
+
const stack = panes.slice(count);
|
|
31
|
+
const column = side === "left" || side === "right";
|
|
32
|
+
if (stack.length === 0) {
|
|
33
|
+
divide(masters, area.x, area.y, area.width, area.height, column, gap, out);
|
|
34
|
+
} else if (column) {
|
|
35
|
+
const room = Math.max(0, area.width - gap);
|
|
36
|
+
const masterWidth = room * ratio;
|
|
37
|
+
const stackWidth = room * (1 - ratio);
|
|
38
|
+
const masterX = side === "left" ? area.x : area.x + stackWidth + gap;
|
|
39
|
+
const stackX = side === "left" ? area.x + masterWidth + gap : area.x;
|
|
40
|
+
divide(masters, masterX, area.y, masterWidth, area.height, true, gap, out);
|
|
41
|
+
divide(stack, stackX, area.y, stackWidth, area.height, true, gap, out);
|
|
42
|
+
} else {
|
|
43
|
+
const room = Math.max(0, area.height - gap);
|
|
44
|
+
const masterHeight = room * ratio;
|
|
45
|
+
const stackHeight = room * (1 - ratio);
|
|
46
|
+
const masterY = side === "top" ? area.y : area.y + stackHeight + gap;
|
|
47
|
+
const stackY = side === "top" ? area.y + masterHeight + gap : area.y;
|
|
48
|
+
divide(masters, area.x, masterY, area.width, masterHeight, false, gap, out);
|
|
49
|
+
divide(stack, area.x, stackY, area.width, stackHeight, false, gap, out);
|
|
13
50
|
}
|
|
14
|
-
const mw = (area.width - gap) * (options.ratio ?? 0.5);
|
|
15
|
-
out.set(panes[0], { x: area.x, y: area.y, width: mw, height: area.height });
|
|
16
|
-
const k = panes.length - 1;
|
|
17
|
-
const sh = (area.height - gap * (k - 1)) / k;
|
|
18
|
-
panes.slice(1).forEach((id, i) => out.set(id, { x: area.x + mw + gap, y: area.y + i * (sh + gap), width: area.width - mw - gap, height: sh }));
|
|
19
51
|
return out;
|
|
20
52
|
}
|
|
21
53
|
function columns(panes, area, options = {}) {
|
|
@@ -45,32 +77,6 @@ function grid(panes, area, options = {}) {
|
|
|
45
77
|
}
|
|
46
78
|
|
|
47
79
|
// src/tiling/split.ts
|
|
48
|
-
function layoutSplit(tree, area, options = {}) {
|
|
49
|
-
const out = /* @__PURE__ */ new Map();
|
|
50
|
-
lay(tree, area, Math.max(0, options.gap ?? 0), out);
|
|
51
|
-
return out;
|
|
52
|
-
}
|
|
53
|
-
function lay(tree, area, gap, out) {
|
|
54
|
-
if (!tree) return;
|
|
55
|
-
if ("pane" in tree) {
|
|
56
|
-
out.set(tree.pane, { ...area });
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
const ratio = Math.min(1, Math.max(0, tree.ratio ?? 0.5));
|
|
60
|
-
if ((tree.axis ?? (area.width >= area.height ? "x" : "y")) === "x") {
|
|
61
|
-
const room = Math.max(0, area.width - gap);
|
|
62
|
-
const w = room * ratio;
|
|
63
|
-
lay(tree.a, { x: area.x, y: area.y, width: w, height: area.height }, gap, out);
|
|
64
|
-
const bx = room > 0 ? area.x + w + gap : area.x + Math.max(0, area.width);
|
|
65
|
-
lay(tree.b, { x: bx, y: area.y, width: room * (1 - ratio), height: area.height }, gap, out);
|
|
66
|
-
} else {
|
|
67
|
-
const room = Math.max(0, area.height - gap);
|
|
68
|
-
const h = room * ratio;
|
|
69
|
-
lay(tree.a, { x: area.x, y: area.y, width: area.width, height: h }, gap, out);
|
|
70
|
-
const by = room > 0 ? area.y + h + gap : area.y + Math.max(0, area.height);
|
|
71
|
-
lay(tree.b, { x: area.x, y: by, width: area.width, height: room * (1 - ratio) }, gap, out);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
80
|
var panesOf = (tree) => !tree ? [] : "pane" in tree ? [tree.pane] : [...panesOf(tree.a), ...panesOf(tree.b)];
|
|
75
81
|
var has = (tree, pane) => panesOf(tree).includes(pane);
|
|
76
82
|
function mapPanes(tree, fn) {
|
|
@@ -115,6 +121,144 @@ function dropOnPane(tree, dragged, at, region) {
|
|
|
115
121
|
return mapPanes(tree, (p) => p === at ? { a: { pane: dragged }, b: { pane: p } } : { pane: p });
|
|
116
122
|
}
|
|
117
123
|
|
|
124
|
+
// src/tiling/layout.ts
|
|
125
|
+
var px = (v) => v !== void 0 && Number.isFinite(v) && v > 0 ? v : 0;
|
|
126
|
+
var unit = (v) => v === void 0 || !Number.isFinite(v) ? 0.5 : Math.min(1, Math.max(0, v));
|
|
127
|
+
var usable = (v) => v !== void 0 && Number.isFinite(v) && v > 0;
|
|
128
|
+
var NET = [0.05, 0.95];
|
|
129
|
+
function layoutSplit(tree, area, options = {}) {
|
|
130
|
+
const ctx = { options, gap: px(options.gap), handle: px(options.handle), panes: /* @__PURE__ */ new Map(), splits: null };
|
|
131
|
+
lay(tree, area, ctx, false);
|
|
132
|
+
return ctx.panes;
|
|
133
|
+
}
|
|
134
|
+
function layoutSplitTree(tree, area, options = {}) {
|
|
135
|
+
const splits = /* @__PURE__ */ new Map();
|
|
136
|
+
const ctx = { options, gap: px(options.gap), handle: px(options.handle), panes: /* @__PURE__ */ new Map(), splits };
|
|
137
|
+
lay(tree, area, ctx, false);
|
|
138
|
+
return { panes: ctx.panes, splits };
|
|
139
|
+
}
|
|
140
|
+
function strip(box, x, mid, gutter) {
|
|
141
|
+
const lo = Math.max(x ? box.x : box.y, mid - gutter / 2);
|
|
142
|
+
const hi = Math.min(x ? box.x + box.width : box.y + box.height, mid + gutter / 2);
|
|
143
|
+
const length = Math.max(0, hi - lo);
|
|
144
|
+
return x ? { x: lo, y: box.y, width: length, height: box.height } : { x: box.x, y: lo, width: box.width, height: length };
|
|
145
|
+
}
|
|
146
|
+
function clampByMin(ratio, extent, gutter, minA, minB, net) {
|
|
147
|
+
const room = Math.max(extent - gutter, 1);
|
|
148
|
+
const boundedMin = Math.min(Math.max(minA / room, net[0]), net[1]);
|
|
149
|
+
const boundedMax = Math.max(Math.min(1 - minB / room, net[1]), net[0]);
|
|
150
|
+
return boundedMin > boundedMax ? 0.5 : Math.min(Math.max(ratio, boundedMin), boundedMax);
|
|
151
|
+
}
|
|
152
|
+
function layMaster(tree, master, area, ctx, owned) {
|
|
153
|
+
const gap = tree.gap === void 0 ? ctx.gap : px(tree.gap);
|
|
154
|
+
const panes = panesOf(tree);
|
|
155
|
+
const ratio = masterRatio(tree.ratio);
|
|
156
|
+
const side = master.side ?? "left";
|
|
157
|
+
for (const [pane, r] of masterStack(panes, area, { gap, ratio, count: master.count, side })) ctx.panes.set(pane, r);
|
|
158
|
+
if (tree.id === void 0 || ctx.splits === null) return;
|
|
159
|
+
const x = side === "left" || side === "right";
|
|
160
|
+
const stacked = panes.length > masterCount(master.count, panes.length);
|
|
161
|
+
const room = Math.max(0, (x ? area.width : area.height) - gap);
|
|
162
|
+
const first = side === "left" || side === "top" ? room * ratio : room * (1 - ratio);
|
|
163
|
+
const mid = (x ? area.x : area.y) + first + gap / 2;
|
|
164
|
+
ctx.splits.set(tree.id, { rect: owned ? area : { ...area }, axis: x ? "x" : "y", ratio, divider: stacked ? strip(area, x, mid, gap) : null });
|
|
165
|
+
}
|
|
166
|
+
function lay(tree, area, ctx, owned) {
|
|
167
|
+
if (!tree) return;
|
|
168
|
+
if ("pane" in tree) {
|
|
169
|
+
ctx.panes.set(tree.pane, owned ? area : { ...area });
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
if (tree.master) {
|
|
173
|
+
layMaster(tree, tree.master, area, ctx, owned);
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
const axis = tree.axis ?? (area.width >= area.height ? "x" : "y");
|
|
177
|
+
const x = axis === "x";
|
|
178
|
+
const extent = x ? area.width : area.height;
|
|
179
|
+
const origin = x ? area.x : area.y;
|
|
180
|
+
const cross = x ? area.height : area.width;
|
|
181
|
+
const gutter = (tree.gap === void 0 ? ctx.gap : px(tree.gap)) + ctx.handle;
|
|
182
|
+
const { fixed, fixedAcross, floor } = ctx.options;
|
|
183
|
+
const lenA = fixedAcross?.(tree.a, axis);
|
|
184
|
+
const lenB = fixedAcross?.(tree.b, axis);
|
|
185
|
+
const acrossA = usable(lenA) ? lenA : cross;
|
|
186
|
+
const acrossB = usable(lenB) ? lenB : cross;
|
|
187
|
+
const fixedA = fixed?.(tree.a, axis);
|
|
188
|
+
const fixedB = fixed?.(tree.b, axis);
|
|
189
|
+
let lengthA;
|
|
190
|
+
let lengthB;
|
|
191
|
+
let startB;
|
|
192
|
+
let ratio = unit(tree.ratio);
|
|
193
|
+
let ruled = false;
|
|
194
|
+
const lead = fixedA ?? fixedB;
|
|
195
|
+
if (fixedA && fixedB && fixedA.keep && fixedB.keep && usable(fixedA.length) && usable(fixedB.length)) {
|
|
196
|
+
lengthA = fixedA.length;
|
|
197
|
+
lengthB = fixedB.length;
|
|
198
|
+
startB = origin + lengthA + gutter;
|
|
199
|
+
ratio = extent > 0 ? (lengthA + gutter / 2) / extent : ratio;
|
|
200
|
+
} else if (lead && usable(lead.length) && lead.length + gutter < extent) {
|
|
201
|
+
const rest = Math.max(0, extent - lead.length - gutter);
|
|
202
|
+
lengthA = lead === fixedA ? lead.length : rest;
|
|
203
|
+
lengthB = lead === fixedA ? rest : lead.length;
|
|
204
|
+
startB = origin + lengthA + gutter;
|
|
205
|
+
ratio = (lengthA + gutter / 2) / extent;
|
|
206
|
+
} else {
|
|
207
|
+
if (floor) {
|
|
208
|
+
const a = floor(tree.a, axis, tree);
|
|
209
|
+
const b = floor(tree.b, axis, tree);
|
|
210
|
+
const net = a.net === false || b.net === false ? [0, 1] : NET;
|
|
211
|
+
ratio = clampByMin(Number.isFinite(tree.ratio ?? 0.5) ? tree.ratio ?? 0.5 : 0.5, extent, gutter, px(a.min), px(b.min), net);
|
|
212
|
+
}
|
|
213
|
+
lengthA = Math.max(0, extent * ratio - gutter / 2);
|
|
214
|
+
lengthB = Math.max(0, extent * (1 - ratio) - gutter / 2);
|
|
215
|
+
startB = origin + extent * ratio + gutter / 2;
|
|
216
|
+
ruled = true;
|
|
217
|
+
}
|
|
218
|
+
if (tree.id !== void 0 && ctx.splits !== null) {
|
|
219
|
+
const divider = ruled ? strip(area, x, origin + extent * ratio, gutter) : null;
|
|
220
|
+
ctx.splits.set(tree.id, { rect: owned ? area : { ...area }, axis, ratio, divider });
|
|
221
|
+
}
|
|
222
|
+
if (x) {
|
|
223
|
+
lay(tree.a, { x: area.x, y: area.y, width: lengthA, height: acrossA }, ctx, true);
|
|
224
|
+
lay(tree.b, { x: startB, y: area.y, width: lengthB, height: acrossB }, ctx, true);
|
|
225
|
+
} else {
|
|
226
|
+
lay(tree.a, { x: area.x, y: area.y, width: acrossA, height: lengthA }, ctx, true);
|
|
227
|
+
lay(tree.b, { x: area.x, y: startB, width: acrossB, height: lengthB }, ctx, true);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
// src/tiling/drop.ts
|
|
232
|
+
var px2 = (v) => v !== void 0 && Number.isFinite(v) && v > 0 ? v : 0;
|
|
233
|
+
function canDropOnPane(tree, dragged, at, region, area, options) {
|
|
234
|
+
if (region === "center") {
|
|
235
|
+
if (dragged === at) return { ok: false, reason: "center swap blocked: a pane dropped on itself" };
|
|
236
|
+
return panesOf(tree).includes(at) ? { ok: true } : { ok: false, reason: "center rejected: no pane to swap" };
|
|
237
|
+
}
|
|
238
|
+
const target = layoutSplit(removePane(tree, dragged), area, options).get(at);
|
|
239
|
+
if (!target) return { ok: false, reason: `${region} rejected: no pane to split` };
|
|
240
|
+
const room = canSplitPane(target, region, options);
|
|
241
|
+
if (!room.ok) return room;
|
|
242
|
+
return dropFits(layoutSplit(dropOnPane(tree, dragged, at, region), area, options), dragged, at, area, { min: options.min, side: region });
|
|
243
|
+
}
|
|
244
|
+
function canSplitPane(target, side, options) {
|
|
245
|
+
const min = px2(options.min);
|
|
246
|
+
const gutter = px2(options.gap) + px2(options.handle);
|
|
247
|
+
const horizontal = side === "left" || side === "right";
|
|
248
|
+
const along = horizontal ? target.width : target.height;
|
|
249
|
+
const across = horizontal ? target.height : target.width;
|
|
250
|
+
const need = min * 2 + gutter;
|
|
251
|
+
if (along < need) return { ok: false, reason: `${side} rejected: axis span ${along.toFixed(1)}px < min ${need.toFixed(1)}px (2 panes + gutter ${gutter}px)` };
|
|
252
|
+
if (across < min) return { ok: false, reason: `${side} rejected: cross span ${across.toFixed(1)}px < min ${min.toFixed(1)}px` };
|
|
253
|
+
return { ok: true };
|
|
254
|
+
}
|
|
255
|
+
function dropFits(projected, dragged, at, area, options) {
|
|
256
|
+
if (!(area.width > 0 && area.height > 0)) return { ok: true };
|
|
257
|
+
const min = px2(options.min);
|
|
258
|
+
const fits = (r) => !!r && r.width >= min && r.height >= min;
|
|
259
|
+
return fits(projected.get(dragged)) && fits(projected.get(at)) ? { ok: true } : { ok: false, reason: `${options.side} rejected: projected footprint of the two panes violates min ${min}px` };
|
|
260
|
+
}
|
|
261
|
+
|
|
118
262
|
// src/tiling/regions.ts
|
|
119
263
|
var PANE_SIDES = ["top", "right", "bottom", "left"];
|
|
120
264
|
var PANE_REGION_DEFAULTS = { center: 0.34, centerMin: 24, hysteresis: 6, pixelRatio: 1 };
|
|
@@ -162,7 +306,7 @@ function toward(p, region, by, c) {
|
|
|
162
306
|
return { x: p.x + dx / len * by, y: p.y + dy / len * by };
|
|
163
307
|
}
|
|
164
308
|
function paneRegion(pane, point, previous = null, options = {}) {
|
|
165
|
-
const c = paneCenter(pane, options);
|
|
309
|
+
const c = options.paneCenter ?? paneCenter(pane, options);
|
|
166
310
|
const p = { x: point.x - pane.x, y: point.y - pane.y };
|
|
167
311
|
const raw = rawRegion(p, c);
|
|
168
312
|
const by = Math.max(0, options.hysteresis ?? PANE_REGION_DEFAULTS.hysteresis);
|
|
@@ -197,15 +341,50 @@ function giveWay(panes, layout, min, age) {
|
|
|
197
341
|
floats.push(newest);
|
|
198
342
|
}
|
|
199
343
|
}
|
|
344
|
+
|
|
345
|
+
// src/tiling/neighbor.ts
|
|
346
|
+
function neighbor(rects, from, direction) {
|
|
347
|
+
const origin = rects.get(from);
|
|
348
|
+
if (!origin) return null;
|
|
349
|
+
const horizontal = direction === "left" || direction === "right";
|
|
350
|
+
const center = (r, x) => x ? (r.x + (r.x + r.width)) / 2 : (r.y + (r.y + r.height)) / 2;
|
|
351
|
+
const reach = (r, x) => x ? [r.x, r.x + r.width] : [r.y, r.y + r.height];
|
|
352
|
+
const fromAlong = center(origin, horizontal);
|
|
353
|
+
const fromAcross = center(origin, !horizontal);
|
|
354
|
+
const [originStart, originEnd] = reach(origin, !horizontal);
|
|
355
|
+
const sign = direction === "left" || direction === "up" ? -1 : 1;
|
|
356
|
+
let best = null;
|
|
357
|
+
let bestScore = Number.POSITIVE_INFINITY;
|
|
358
|
+
for (const [key, r] of rects) {
|
|
359
|
+
if (key === from) continue;
|
|
360
|
+
const along = center(r, horizontal);
|
|
361
|
+
if (sign < 0 ? along >= fromAlong : along <= fromAlong) continue;
|
|
362
|
+
const [start, end] = reach(r, !horizontal);
|
|
363
|
+
const overlap = Math.max(0, Math.min(originEnd, end) - Math.max(originStart, start));
|
|
364
|
+
const score = Math.abs(along - fromAlong) + Math.abs(center(r, !horizontal) - fromAcross) * 0.25 + (overlap > 0 ? 0 : 100);
|
|
365
|
+
if (score < bestScore) {
|
|
366
|
+
bestScore = score;
|
|
367
|
+
best = key;
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
return best;
|
|
371
|
+
}
|
|
200
372
|
export {
|
|
201
373
|
PANE_REGION_DEFAULTS,
|
|
202
374
|
PANE_SIDES,
|
|
375
|
+
canDropOnPane,
|
|
376
|
+
canSplitPane,
|
|
203
377
|
columns,
|
|
378
|
+
dropFits,
|
|
204
379
|
dropOnPane,
|
|
205
380
|
giveWay,
|
|
206
381
|
grid,
|
|
207
382
|
layoutSplit,
|
|
383
|
+
layoutSplitTree,
|
|
384
|
+
masterCount,
|
|
385
|
+
masterRatio,
|
|
208
386
|
masterStack,
|
|
387
|
+
neighbor,
|
|
209
388
|
orderTargets,
|
|
210
389
|
paneCenter,
|
|
211
390
|
paneRegion,
|