@n-uf/placement 26.11.64 → 26.12.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 +61 -0
- package/dist/stack.d.ts +18 -6
- package/dist/stack.js +61 -21
- package/dist/stack.js.map +1 -1
- package/dist/tiling.d.ts +122 -29
- package/dist/tiling.js +192 -68
- package/dist/tiling.js.map +1 -1
- package/package.json +1 -1
package/dist/tiling.d.ts
CHANGED
|
@@ -157,37 +157,110 @@ declare function splitFromOrder<K>(panes: readonly K[]): Split<K> | null;
|
|
|
157
157
|
declare function dropOnPane<K>(tree: Split<K> | null, dragged: K, at: K, region: PaneRegion): Split<K>;
|
|
158
158
|
|
|
159
159
|
/**
|
|
160
|
-
*
|
|
161
|
-
*
|
|
160
|
+
* One split's decision: given its extent, its gutter, its stored ratio and what each side needs, how long each side
|
|
161
|
+
* is along the split, and the ratio in effect. `layoutSplit` makes it for every split; a host that draws or stores a
|
|
162
|
+
* split itself makes the same one. See docs/placement.md, Entry: tiling.
|
|
163
|
+
*/
|
|
164
|
+
/**
|
|
165
|
+
* A side's fixed length along its split. A **kept** length (`keep`) is exact: it is cut only by its box, the extent
|
|
166
|
+
* less the gutter, never by its sibling's need, it decides its split over a fixed length that is not kept, and it is
|
|
167
|
+
* its pane's need. A fixed length that is not kept is taken as far as its box allows: the extent less the gutter and
|
|
168
|
+
* its sibling's need.
|
|
162
169
|
*/
|
|
163
|
-
|
|
164
|
-
/** A split child's fixed length along its split. `keep` marks one that holds its length even beside another. */
|
|
165
170
|
interface FixedLength {
|
|
166
171
|
readonly length: number;
|
|
167
172
|
readonly keep?: boolean;
|
|
168
173
|
}
|
|
169
|
-
/**
|
|
174
|
+
/** Which step of the ladder decided a split. */
|
|
175
|
+
type SplitStep = "no-room" | "kept" | "fixed" | "ratio" | "squeezed";
|
|
176
|
+
/** One side of a split as its decision reads it: the layout's own inputs. */
|
|
177
|
+
interface SplitSide {
|
|
178
|
+
/**
|
|
179
|
+
* The least length the side lands at where its split fits: a layout's own number is `SplitGeometry.needs` (the
|
|
180
|
+
* side's floor as this split measures it, its kept length, or a nested split's need). Leave it out on both sides of
|
|
181
|
+
* a split with no floors. `splitNeed` is a tree's need laid out alone, which is not a side's. A need that is not
|
|
182
|
+
* finite and above 0 counts as 0, but a side that has one (NaN included) makes the split one with floors: the gap
|
|
183
|
+
* rule no longer applies.
|
|
184
|
+
*/
|
|
185
|
+
readonly need?: number;
|
|
186
|
+
/** False where the side's floor said `net: false`; either side's false takes the net off the split. */
|
|
187
|
+
readonly net?: boolean;
|
|
188
|
+
/** The side's fixed length along the split. */
|
|
189
|
+
readonly fixed?: FixedLength;
|
|
190
|
+
}
|
|
191
|
+
/** What one split does: each side's length along it, the ratio in effect, the step that decided, whether it has a divider. */
|
|
192
|
+
interface SplitDecision {
|
|
193
|
+
readonly a: number;
|
|
194
|
+
readonly b: number;
|
|
195
|
+
/** The ratio in effect: the middle of the gutter lies at the split's start plus the extent times this. */
|
|
196
|
+
readonly ratio: number;
|
|
197
|
+
readonly step: SplitStep;
|
|
198
|
+
/** True where no fixed length decides the split: its gutter is a divider. */
|
|
199
|
+
readonly divider: boolean;
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* One split's decision, the ladder, tested in this order (E the extent, g the gutter, room = E − g):
|
|
203
|
+
*
|
|
204
|
+
* 0. **No floors and no fixed length** (no side has a `need` or a usable `fixed`): the gap rule. The middle of the
|
|
205
|
+
* gutter sits at `E × ratio`; a side too short for half the gutter is 0, and a 0-long second side may start up to
|
|
206
|
+
* half a gutter past the end.
|
|
207
|
+
* 1. **No room** (E under g): both sides are 0, and the ratio is 0.5.
|
|
208
|
+
* 2. **Kept**: a kept length decides over one that is not kept (the first kept side, else the second). It takes
|
|
209
|
+
* `min(length, room)`, whatever its sibling needs; the other side takes the rest. Two kept lengths take
|
|
210
|
+
* `min(first, room)` and `min(second, room − first)`, and what is left stays empty.
|
|
211
|
+
* 3. **Fixed**: else the first side with a usable fixed length (above 0, finite; an unusable first lets the second
|
|
212
|
+
* decide) takes `min(length, room − need of its sibling)`; the sibling takes the rest. Where its own need (at most
|
|
213
|
+
* its length) and its sibling's don't fit the room, both are squeezed in proportion (step 5). The stored ratio is
|
|
214
|
+
* never read.
|
|
215
|
+
* 4. **Ratio**: else the ratio is clamped so each side lands at its need: within
|
|
216
|
+
* `[(needA + g/2) / E, 1 − (needB + g/2) / E]`. Where the net is on (neither side's `net` is false), each need is
|
|
217
|
+
* first raised to `0.05 × E − g/2`, which is the 0.05..0.95 bound while the needs fit.
|
|
218
|
+
* 5. **Squeezed**: where the needs (raised by the net, in step 4 only) and the gutter don't fit the extent, both sides
|
|
219
|
+
* share the room in proportion to their needs.
|
|
220
|
+
*
|
|
221
|
+
* Every step is continuous in the extent: changing it by d changes no side by more than d. At `E = g` both sides are
|
|
222
|
+
* 0; the step is the ratio, or the squeeze where a side needs more than 0.
|
|
223
|
+
*/
|
|
224
|
+
declare function decideSplit(extent: number, gutter: number, ratio: number | undefined, a: SplitSide, b: SplitSide): SplitDecision;
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* The split tree laid out: the rect of every pane of a `Split` tree in an area, and the geometry of the splits that
|
|
228
|
+
* have an id. See docs/placement.md, Entry: tiling.
|
|
229
|
+
*/
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* A node's own least length along a split. `net` (default true): where neither side of a split says false, each side
|
|
233
|
+
* needs at least 5 % of the extent less half the gutter where a ratio decides the split, which is the 0.05..0.95 bound
|
|
234
|
+
* while the needs fit.
|
|
235
|
+
*/
|
|
170
236
|
interface MinLength {
|
|
171
237
|
readonly min: number;
|
|
172
238
|
readonly net?: boolean;
|
|
173
239
|
}
|
|
174
240
|
/**
|
|
175
|
-
* What a split tree's layout reads of its host
|
|
241
|
+
* What a split tree's layout reads of its host. Each split is decided by `decideSplit` from its two sides' needs
|
|
242
|
+
* (`splitNeed` and `SplitGeometry.needs`), fixed lengths and nets; see docs/placement.md, Entry: tiling.
|
|
176
243
|
*
|
|
177
|
-
* - `fixed(child, axis)`:
|
|
178
|
-
*
|
|
179
|
-
*
|
|
180
|
-
*
|
|
181
|
-
*
|
|
182
|
-
*
|
|
183
|
-
*
|
|
184
|
-
*
|
|
185
|
-
*
|
|
186
|
-
*
|
|
187
|
-
*
|
|
188
|
-
*
|
|
189
|
-
*
|
|
190
|
-
*
|
|
244
|
+
* - `fixed(child, axis)`: a direct child's fixed length along its split, asked once per child and axis. A kept
|
|
245
|
+
* length (`keep`) is exact: cut only by its box (the extent less the gutter), it decides over a length that is not
|
|
246
|
+
* kept, and it is its pane's need; two kept lengths keep their own and the room left stays empty, the second cut at
|
|
247
|
+
* the split's end. Else the first side with a usable length (above 0, finite; an unusable first lets the second
|
|
248
|
+
* decide) takes it as far as its box allows, the extent less the gutter and its sibling's need, and returns with the
|
|
249
|
+
* room; where the needs don't fit, the split is squeezed. A split a fixed length decides has no divider; its stored
|
|
250
|
+
* ratio is never read.
|
|
251
|
+
* - `fixedAcross(child, axis)`: the child's fixed length across the split; the child takes it, when positive, finite
|
|
252
|
+
* and shorter than the cross extent, from the start of the cross axis instead of the whole cross extent; a longer
|
|
253
|
+
* one takes the cross extent. It never enters a need.
|
|
254
|
+
* - `floor(child, axis, split)`: a node's own least length along `axis`, asked at most once per node, axis and
|
|
255
|
+
* measuring split in a layout. `split` is the nearest split above `child` that runs along `axis`, which may be its
|
|
256
|
+
* parent or a split above a split across; where no split above a node runs along `axis`, it is not asked and its
|
|
257
|
+
* own floor is 0. A side's need is its own floor, or its kept length, or for a nested split with an axis the larger
|
|
258
|
+
* of its own floor and its sides' needs (along: both and the gutter, and where a ratio decides it with its net on,
|
|
259
|
+
* room for the net's 5 % as well; across: the larger). Each side lands at its
|
|
260
|
+
* need where the split's needs fit its extent; where they don't, both sides are squeezed in proportion. A master
|
|
261
|
+
* split and a split with no axis report their own floor only. With no `floor` there are no needs, and a split with
|
|
262
|
+
* no fixed length keeps the gap rule (`layoutSplit`). `giveWay` is the other policy of the same minimum: it floats
|
|
263
|
+
* the newest pane instead of squeezing the ratio, and a host chooses one for a pane.
|
|
191
264
|
*/
|
|
192
265
|
interface SplitOptions<K> extends TileOptions {
|
|
193
266
|
readonly fixed?: (child: Split<K>, axis: Axis) => FixedLength | undefined;
|
|
@@ -207,20 +280,40 @@ interface SplitGeometry {
|
|
|
207
280
|
readonly ratio: number;
|
|
208
281
|
/** The gutter between the two sides, as a rect inside `rect`; null where the split has none. */
|
|
209
282
|
readonly divider: Rect | null;
|
|
283
|
+
/** The step of `decideSplit` that decided the split; `"ratio"` for a master split. */
|
|
284
|
+
readonly step: SplitStep;
|
|
285
|
+
/**
|
|
286
|
+
* The two sides' needs as this split read them (each side's floor as it measures it, its kept length, or a nested
|
|
287
|
+
* split's need): what a host passes to `decideSplit` for this split. Null without `floor`, and for a master split.
|
|
288
|
+
*/
|
|
289
|
+
readonly needs: readonly [number, number] | null;
|
|
210
290
|
}
|
|
211
291
|
/** A tree laid out: every pane's rect, and the geometry of each split that has an `id`. */
|
|
212
292
|
interface SplitLayout<K> {
|
|
213
293
|
readonly panes: Map<K, Rect>;
|
|
214
294
|
readonly splits: Map<string, SplitGeometry>;
|
|
215
295
|
}
|
|
296
|
+
/**
|
|
297
|
+
* The least length `tree` lands at along `axis`, laid out alone in an area with `options`: where the area is at
|
|
298
|
+
* least this long (allowing 1e-9 of it) along `axis`, no split on the way is squeezed by its needs, the net on or
|
|
299
|
+
* off (a split a ratio decides with its net on needs room for the net's 5 % of its extent too). Except where the host
|
|
300
|
+
* gives a split node its own fixed, kept or across length shorter than its need: that length is taken as it is, the
|
|
301
|
+
* splits inside it along that axis are squeezed at any size, and its panes may land under their floors. It reads `floor`
|
|
302
|
+
* and `fixed` as the layout does; no split measures the root, so a pane alone needs 0, and a split's own floor
|
|
303
|
+
* counts only where a split above it measures it. 0 without `floor`. Not a side's need inside a tree: that is
|
|
304
|
+
* `SplitGeometry.needs`, measured by its split. Not `StackFit.need` (what a stack's forms need).
|
|
305
|
+
*/
|
|
306
|
+
declare function splitNeed<K>(tree: Split<K> | null, axis: Axis, options?: SplitOptions<K>): number;
|
|
216
307
|
/**
|
|
217
308
|
* The rect of every pane of `tree` in `area`. Each split's gutter is its gap (its own `gap`, else `options.gap`) plus
|
|
218
309
|
* `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
|
|
219
310
|
* sits at `extent * ratio`: the first side is `extent * ratio` less half the gutter, the second starts half a gutter
|
|
220
311
|
* 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
|
|
221
312
|
* 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.
|
|
222
|
-
* At ratio 0.5 both sides are equal
|
|
223
|
-
*
|
|
313
|
+
* At ratio 0.5 both sides are equal: that is the gap rule, for a split with no floors and no fixed length.
|
|
314
|
+
* `options.floor`, `fixed` and `fixedAcross` (see `SplitOptions`) read the host's minimums and fixed lengths, and each
|
|
315
|
+
* split is then decided by `decideSplit`: with them every pane lies inside the area, at every size (a split under
|
|
316
|
+
* its gutter lays both sides at no size, the second at its end). A negative or non-finite `gap` or `handle` is 0. The area is taken as given:
|
|
224
317
|
* with a negative width or height every length along that axis is 0 and a pane's size across it is copied as it
|
|
225
318
|
* is, so pass an area with no negative side.
|
|
226
319
|
*/
|
|
@@ -277,8 +370,9 @@ interface DropFitsOptions {
|
|
|
277
370
|
}
|
|
278
371
|
/**
|
|
279
372
|
* The fit rule: in `projected`, the rect of every pane in the layout the drop makes (the host's own projection of
|
|
280
|
-
* `dropOnPane`'s tree), whether `dragged` and `at` are both there and at least `options.min` wide and high
|
|
281
|
-
* when `area` has no width or no height (there is
|
|
373
|
+
* `dropOnPane`'s tree), whether `dragged` and `at` are both there and at least `options.min` wide and high, to within
|
|
374
|
+
* `EPS` (a floor of `min` lands at `min` up to float error). Fine when `area` has no width or no height (there is
|
|
375
|
+
* nothing to measure). `canDropOnPane`'s last rule.
|
|
282
376
|
*/
|
|
283
377
|
declare function dropFits<K>(projected: ReadonlyMap<K, Rect>, dragged: K, at: K, area: Rect, options: DropFitsOptions): DropVerdict;
|
|
284
378
|
|
|
@@ -792,11 +886,10 @@ type Direction = "left" | "right" | "up" | "down";
|
|
|
792
886
|
* the lowest score wins, ties to the first in the map's order. A pane that is not in `rects` has no neighbor.
|
|
793
887
|
*
|
|
794
888
|
* The host chooses which rects to pass. One option: lay the tree out in a unit square (`{ x: 0, y: 0, width: 1,
|
|
795
|
-
* height: 1 }`) with
|
|
796
|
-
*
|
|
797
|
-
*
|
|
798
|
-
* they still apply in a unit square, and a host leaves `fixedAcross` out there. The rects of the real layout work too.
|
|
889
|
+
* height: 1 }`) with no `floor`, `fixed` or `fixedAcross`, and no gap, so the choice follows the tree's shape and its
|
|
890
|
+
* ratios. px floors cannot fit a unit square: every split would be squeezed by its floors, and a px fixed length would
|
|
891
|
+
* take the whole room. The rects of the real layout work too.
|
|
799
892
|
*/
|
|
800
893
|
declare function neighbor<K>(rects: ReadonlyMap<K, Rect>, from: K, direction: Direction): K | null;
|
|
801
894
|
|
|
802
|
-
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 PaneTarget, type PaneTargetsOptions, Rect, type Split, type SplitGeometry, type SplitLayout, type SplitOptions, type SplitRoomOptions, type SplitTreeOpsOptions, type StackedSplit, TILING_HIT_DEFAULTS, TILING_HIT_PROPERTIES, TILING_PROPERTIES, type TileOptions, type TilingAfter, type TilingBasis, type TilingConformance, type TilingDrag, type TilingDragOptions, type TilingHeld, type TilingHit, type TilingHitConformance, type TilingHitFrame, type TilingHitIntent, type TilingHitOptions, type TilingHitProperty, type TilingHitRead, type TilingHitRegions, type TilingHitTarget, type TilingHold, type TilingLaidOut, type TilingMark, type TilingMove, type TilingPart, type TilingProperty, type TilingRefusal, type TilingSize, type TilingStack, type TilingSubject, type TilingTree, canDropOnPane, canSplitPane, columns, dropFits, dropOnPane, giveWay, grid, layoutSplit, layoutSplitTree, masterCount, masterRatio, masterStack, neighbor, orderTargets, paneCenter, paneRegion, paneRegionShapes, paneTargets, panesOf, removePane, splitFromOrder, splitPane, splitTreeOps, swapPanes, tilingConformance, tilingDrag, tilingHitConformance, tilingSubjects };
|
|
895
|
+
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 PaneTarget, type PaneTargetsOptions, Rect, type Split, type SplitDecision, type SplitGeometry, type SplitLayout, type SplitOptions, type SplitRoomOptions, type SplitSide, type SplitStep, type SplitTreeOpsOptions, type StackedSplit, TILING_HIT_DEFAULTS, TILING_HIT_PROPERTIES, TILING_PROPERTIES, type TileOptions, type TilingAfter, type TilingBasis, type TilingConformance, type TilingDrag, type TilingDragOptions, type TilingHeld, type TilingHit, type TilingHitConformance, type TilingHitFrame, type TilingHitIntent, type TilingHitOptions, type TilingHitProperty, type TilingHitRead, type TilingHitRegions, type TilingHitTarget, type TilingHold, type TilingLaidOut, type TilingMark, type TilingMove, type TilingPart, type TilingProperty, type TilingRefusal, type TilingSize, type TilingStack, type TilingSubject, type TilingTree, canDropOnPane, canSplitPane, columns, decideSplit, dropFits, dropOnPane, giveWay, grid, layoutSplit, layoutSplitTree, masterCount, masterRatio, masterStack, neighbor, orderTargets, paneCenter, paneRegion, paneRegionShapes, paneTargets, panesOf, removePane, splitFromOrder, splitNeed, splitPane, splitTreeOps, swapPanes, tilingConformance, tilingDrag, tilingHitConformance, tilingSubjects };
|
package/dist/tiling.js
CHANGED
|
@@ -124,19 +124,165 @@ function dropOnPane(tree, dragged, at, region) {
|
|
|
124
124
|
return mapPanes(tree, (p) => p === at ? { a: { pane: dragged }, b: { pane: p } } : { pane: p });
|
|
125
125
|
}
|
|
126
126
|
|
|
127
|
-
// src/tiling/
|
|
127
|
+
// src/tiling/split-decision.ts
|
|
128
128
|
var px = (v) => v !== void 0 && Number.isFinite(v) && v > 0 ? v : 0;
|
|
129
129
|
var unit = (v) => v === void 0 || !Number.isFinite(v) ? 0.5 : Math.min(1, Math.max(0, v));
|
|
130
|
+
var NET_SHARE = 0.05;
|
|
131
|
+
var FIT = 1e-9;
|
|
132
|
+
var usableFixed = (f) => f && Number.isFinite(f.length) && f.length > 0 ? f : void 0;
|
|
133
|
+
function ratioFitExtent(needA, needB, gutter, net) {
|
|
134
|
+
const g = px(gutter);
|
|
135
|
+
const lower = Math.min(px(needA), px(needB));
|
|
136
|
+
const upper = Math.max(px(needA), px(needB));
|
|
137
|
+
const plain = lower + upper + g;
|
|
138
|
+
if (!net || NET_SHARE * plain - g / 2 <= lower) return plain;
|
|
139
|
+
return (upper + g / 2) / (1 - NET_SHARE);
|
|
140
|
+
}
|
|
141
|
+
function decideSplit(extent, gutter, ratio, a, b) {
|
|
142
|
+
const g = px(gutter);
|
|
143
|
+
const E = Number.isFinite(extent) ? extent : 0;
|
|
144
|
+
const fa = usableFixed(a.fixed);
|
|
145
|
+
const fb = usableFixed(b.fixed);
|
|
146
|
+
const floors = a.need !== void 0 || b.need !== void 0;
|
|
147
|
+
const lead = fa?.keep ? fa : fb?.keep ? fb : fa ?? fb;
|
|
148
|
+
if (!lead && !floors) {
|
|
149
|
+
const r2 = unit(ratio);
|
|
150
|
+
return { a: Math.max(0, extent * r2 - g / 2), b: Math.max(0, extent * (1 - r2) - g / 2), ratio: r2, step: "ratio", divider: true };
|
|
151
|
+
}
|
|
152
|
+
if (E < g * (1 - FIT)) return { a: 0, b: 0, ratio: 0.5, step: "no-room", divider: !lead };
|
|
153
|
+
const needA = px(a.need);
|
|
154
|
+
const needB = px(b.need);
|
|
155
|
+
if (!(E > 0)) {
|
|
156
|
+
const step = lead ? lead.keep ? "kept" : "fixed" : needA + needB > 0 ? "squeezed" : "ratio";
|
|
157
|
+
return { a: 0, b: 0, ratio: 0.5, step, divider: !lead };
|
|
158
|
+
}
|
|
159
|
+
const room = Math.max(0, E - g);
|
|
160
|
+
const at = (lengthA) => (lengthA + g / 2) / E;
|
|
161
|
+
const sides = (lengthA, step, divider) => {
|
|
162
|
+
const la = Math.min(room, Math.max(0, lengthA));
|
|
163
|
+
return { a: la, b: Math.max(0, room - la), ratio: at(la), step, divider };
|
|
164
|
+
};
|
|
165
|
+
const squeeze = (nA2, nB2, divider) => sides(room * nA2 / (nA2 + nB2), "squeezed", divider);
|
|
166
|
+
if (lead) {
|
|
167
|
+
const first = lead === fa;
|
|
168
|
+
if (fa?.keep && fb?.keep) {
|
|
169
|
+
const la = Math.min(fa.length, room);
|
|
170
|
+
return { a: la, b: Math.min(fb.length, room - la), ratio: at(la), step: "kept", divider: false };
|
|
171
|
+
}
|
|
172
|
+
if (lead.keep) {
|
|
173
|
+
const length2 = Math.min(lead.length, room);
|
|
174
|
+
return sides(first ? length2 : room - length2, "kept", false);
|
|
175
|
+
}
|
|
176
|
+
const own = Math.min(lead.length, first ? needA : needB);
|
|
177
|
+
const other = first ? needB : needA;
|
|
178
|
+
if (own + other > room + FIT * E) return first ? squeeze(own, other, false) : squeeze(other, own, false);
|
|
179
|
+
const length = Math.min(lead.length, room - other);
|
|
180
|
+
return sides(first ? length : room - length, "fixed", false);
|
|
181
|
+
}
|
|
182
|
+
const net = a.net !== false && b.net !== false ? Math.max(0, NET_SHARE * E - g / 2) : 0;
|
|
183
|
+
const nA = Math.max(needA, net);
|
|
184
|
+
const nB = Math.max(needB, net);
|
|
185
|
+
if (nA + nB > room + FIT * E) return squeeze(nA, nB, true);
|
|
186
|
+
const lo = (nA + g / 2) / E;
|
|
187
|
+
const hi = Math.max(lo, 1 - (nB + g / 2) / E);
|
|
188
|
+
const r = Math.min(Math.max(unit(ratio), lo), hi);
|
|
189
|
+
return { a: Math.max(0, E * r - g / 2), b: Math.max(0, E * (1 - r) - g / 2), ratio: r, step: "ratio", divider: true };
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// src/tiling/layout.ts
|
|
193
|
+
var px2 = (v) => v !== void 0 && Number.isFinite(v) && v > 0 ? v : 0;
|
|
130
194
|
var usable = (v) => v !== void 0 && Number.isFinite(v) && v > 0;
|
|
131
|
-
var
|
|
195
|
+
var slot = (maps, node) => {
|
|
196
|
+
let m = maps.get(node);
|
|
197
|
+
if (!m) maps.set(node, m = /* @__PURE__ */ new Map());
|
|
198
|
+
return m;
|
|
199
|
+
};
|
|
200
|
+
var Needs = class {
|
|
201
|
+
options;
|
|
202
|
+
gap;
|
|
203
|
+
handle;
|
|
204
|
+
floors = /* @__PURE__ */ new Map();
|
|
205
|
+
fixeds = /* @__PURE__ */ new Map();
|
|
206
|
+
found = /* @__PURE__ */ new Map();
|
|
207
|
+
ids = /* @__PURE__ */ new Map();
|
|
208
|
+
constructor(options, gap, handle) {
|
|
209
|
+
this.options = options;
|
|
210
|
+
this.gap = gap;
|
|
211
|
+
this.handle = handle;
|
|
212
|
+
}
|
|
213
|
+
/** The key of an axis and a measuring split. */
|
|
214
|
+
key(axis, split) {
|
|
215
|
+
if (split === null) return axis;
|
|
216
|
+
let id = this.ids.get(split);
|
|
217
|
+
if (id === void 0) this.ids.set(split, id = this.ids.size);
|
|
218
|
+
return `${axis} ${id}`;
|
|
219
|
+
}
|
|
220
|
+
/** A split's gutter: its own gap, else the layout's, plus the handle. */
|
|
221
|
+
gutter(split) {
|
|
222
|
+
return (split.gap === void 0 ? this.gap : px2(split.gap)) + this.handle;
|
|
223
|
+
}
|
|
224
|
+
/** The host's floor of `node` along `axis`, as `split` measures it. */
|
|
225
|
+
floor(node, axis, split) {
|
|
226
|
+
const m = slot(this.floors, node);
|
|
227
|
+
const k = this.key(axis, split);
|
|
228
|
+
let f = m.get(k);
|
|
229
|
+
if (f === void 0) m.set(k, f = this.options.floor(node, axis, split));
|
|
230
|
+
return f;
|
|
231
|
+
}
|
|
232
|
+
/** The host's fixed length of `child` along a split on `axis`. */
|
|
233
|
+
fixed(child, axis) {
|
|
234
|
+
const m = slot(this.fixeds, child);
|
|
235
|
+
if (!m.has(axis)) m.set(axis, this.options.fixed?.(child, axis));
|
|
236
|
+
return m.get(axis);
|
|
237
|
+
}
|
|
238
|
+
/** The need of `child`, a direct child of `split`, which runs along `axis`: its kept length, or its own need. */
|
|
239
|
+
side(child, axis, split) {
|
|
240
|
+
const f = this.fixed(child, axis);
|
|
241
|
+
if (f?.keep && usable(f.length)) return f.length;
|
|
242
|
+
return this.of(child, axis, split);
|
|
243
|
+
}
|
|
244
|
+
/** The need of `node` along `axis`, measured by `split` (null: no split above it runs along `axis`). */
|
|
245
|
+
of(node, axis, split) {
|
|
246
|
+
const m = slot(this.found, node);
|
|
247
|
+
const k = this.key(axis, split);
|
|
248
|
+
const known = m.get(k);
|
|
249
|
+
if (known !== void 0) return known;
|
|
250
|
+
const own = split === null ? 0 : px2(this.floor(node, axis, split).min);
|
|
251
|
+
let need = own;
|
|
252
|
+
if (!("pane" in node) && !node.master && node.axis !== void 0) {
|
|
253
|
+
need = node.axis === axis ? Math.max(own, this.along(node, axis)) : Math.max(own, this.of(node.a, axis, split), this.of(node.b, axis, split));
|
|
254
|
+
}
|
|
255
|
+
m.set(k, need);
|
|
256
|
+
return need;
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* The need of `split` along its own axis: both sides' needs and its gutter; where a ratio decides it (no usable fixed
|
|
260
|
+
* length on either side) and its net is on, the least extent at which the net's 5 % fits as well.
|
|
261
|
+
*/
|
|
262
|
+
along(split, axis) {
|
|
263
|
+
const a = this.side(split.a, axis, split);
|
|
264
|
+
const b = this.side(split.b, axis, split);
|
|
265
|
+
const led = [split.a, split.b].some((c) => usable(this.fixed(c, axis)?.length));
|
|
266
|
+
const net = !led && this.floor(split.a, axis, split).net !== false && this.floor(split.b, axis, split).net !== false;
|
|
267
|
+
return ratioFitExtent(a, b, this.gutter(split), net);
|
|
268
|
+
}
|
|
269
|
+
};
|
|
270
|
+
function splitNeed(tree, axis, options = {}) {
|
|
271
|
+
if (!tree || !options.floor) return 0;
|
|
272
|
+
return new Needs(options, px2(options.gap), px2(options.handle)).of(tree, axis, null);
|
|
273
|
+
}
|
|
132
274
|
function layoutSplit(tree, area, options = {}) {
|
|
133
|
-
const
|
|
275
|
+
const gap = px2(options.gap);
|
|
276
|
+
const handle = px2(options.handle);
|
|
277
|
+
const ctx = { options, gap, handle, panes: /* @__PURE__ */ new Map(), splits: null, needs: new Needs(options, gap, handle) };
|
|
134
278
|
lay(tree, area, ctx, false);
|
|
135
279
|
return ctx.panes;
|
|
136
280
|
}
|
|
137
281
|
function layoutSplitTree(tree, area, options = {}) {
|
|
138
282
|
const splits = /* @__PURE__ */ new Map();
|
|
139
|
-
const
|
|
283
|
+
const gap = px2(options.gap);
|
|
284
|
+
const handle = px2(options.handle);
|
|
285
|
+
const ctx = { options, gap, handle, panes: /* @__PURE__ */ new Map(), splits, needs: new Needs(options, gap, handle) };
|
|
140
286
|
lay(tree, area, ctx, false);
|
|
141
287
|
return { panes: ctx.panes, splits };
|
|
142
288
|
}
|
|
@@ -146,14 +292,8 @@ function strip(box, x, mid, gutter) {
|
|
|
146
292
|
const length = Math.max(0, hi - lo);
|
|
147
293
|
return x ? { x: lo, y: box.y, width: length, height: box.height } : { x: box.x, y: lo, width: box.width, height: length };
|
|
148
294
|
}
|
|
149
|
-
function clampByMin(ratio, extent, gutter, minA, minB, net) {
|
|
150
|
-
const room = Math.max(extent - gutter, 1);
|
|
151
|
-
const boundedMin = Math.min(Math.max(minA / room, net[0]), net[1]);
|
|
152
|
-
const boundedMax = Math.max(Math.min(1 - minB / room, net[1]), net[0]);
|
|
153
|
-
return boundedMin > boundedMax ? 0.5 : Math.min(Math.max(ratio, boundedMin), boundedMax);
|
|
154
|
-
}
|
|
155
295
|
function layMaster(tree, master, area, ctx, owned) {
|
|
156
|
-
const gap = tree.gap === void 0 ? ctx.gap :
|
|
296
|
+
const gap = tree.gap === void 0 ? ctx.gap : px2(tree.gap);
|
|
157
297
|
const panes = panesOf(tree);
|
|
158
298
|
const ratio = masterRatio(tree.ratio);
|
|
159
299
|
const side = master.side ?? "left";
|
|
@@ -164,7 +304,7 @@ function layMaster(tree, master, area, ctx, owned) {
|
|
|
164
304
|
const room = Math.max(0, (x ? area.width : area.height) - gap);
|
|
165
305
|
const first = side === "left" || side === "top" ? room * ratio : room * (1 - ratio);
|
|
166
306
|
const mid = (x ? area.x : area.y) + first + gap / 2;
|
|
167
|
-
ctx.splits.set(tree.id, { rect: owned ? area : { ...area }, axis: x ? "x" : "y", ratio, divider: stacked ? strip(area, x, mid, gap) : null });
|
|
307
|
+
ctx.splits.set(tree.id, { rect: owned ? area : { ...area }, axis: x ? "x" : "y", ratio, divider: stacked ? strip(area, x, mid, gap) : null, step: "ratio", needs: null });
|
|
168
308
|
}
|
|
169
309
|
function lay(tree, area, ctx, owned) {
|
|
170
310
|
if (!tree) return;
|
|
@@ -181,47 +321,29 @@ function lay(tree, area, ctx, owned) {
|
|
|
181
321
|
const extent = x ? area.width : area.height;
|
|
182
322
|
const origin = x ? area.x : area.y;
|
|
183
323
|
const cross2 = x ? area.height : area.width;
|
|
184
|
-
const gutter =
|
|
185
|
-
const {
|
|
324
|
+
const gutter = ctx.needs.gutter(tree);
|
|
325
|
+
const { fixedAcross, floor } = ctx.options;
|
|
186
326
|
const lenA = fixedAcross?.(tree.a, axis);
|
|
187
327
|
const lenB = fixedAcross?.(tree.b, axis);
|
|
188
|
-
const acrossA = usable(lenA) ? lenA : cross2;
|
|
189
|
-
const acrossB = usable(lenB) ? lenB : cross2;
|
|
190
|
-
const
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
const
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
lengthB = fixedB.length;
|
|
201
|
-
startB = origin + lengthA + gutter;
|
|
202
|
-
ratio = extent > 0 ? (lengthA + gutter / 2) / extent : ratio;
|
|
203
|
-
} else if (lead && usable(lead.length) && lead.length + gutter < extent) {
|
|
204
|
-
const rest = Math.max(0, extent - lead.length - gutter);
|
|
205
|
-
lengthA = lead === fixedA ? lead.length : rest;
|
|
206
|
-
lengthB = lead === fixedA ? rest : lead.length;
|
|
207
|
-
startB = origin + lengthA + gutter;
|
|
208
|
-
ratio = (lengthA + gutter / 2) / extent;
|
|
209
|
-
} else {
|
|
210
|
-
if (floor) {
|
|
211
|
-
const a = floor(tree.a, axis, tree);
|
|
212
|
-
const b = floor(tree.b, axis, tree);
|
|
213
|
-
const net = a.net === false || b.net === false ? [0, 1] : NET;
|
|
214
|
-
ratio = clampByMin(Number.isFinite(tree.ratio ?? 0.5) ? tree.ratio ?? 0.5 : 0.5, extent, gutter, px(a.min), px(b.min), net);
|
|
215
|
-
}
|
|
216
|
-
lengthA = Math.max(0, extent * ratio - gutter / 2);
|
|
217
|
-
lengthB = Math.max(0, extent * (1 - ratio) - gutter / 2);
|
|
218
|
-
startB = origin + extent * ratio + gutter / 2;
|
|
219
|
-
ruled = true;
|
|
220
|
-
}
|
|
328
|
+
const acrossA = usable(lenA) && lenA < cross2 ? lenA : cross2;
|
|
329
|
+
const acrossB = usable(lenB) && lenB < cross2 ? lenB : cross2;
|
|
330
|
+
const sideOf = (child) => {
|
|
331
|
+
const fixed = ctx.needs.fixed(child, axis);
|
|
332
|
+
if (!floor) return { fixed };
|
|
333
|
+
const kept = !!fixed?.keep && usable(fixed.length);
|
|
334
|
+
return { fixed, need: ctx.needs.side(child, axis, tree), net: kept || ctx.needs.floor(child, axis, tree).net !== false };
|
|
335
|
+
};
|
|
336
|
+
const a = sideOf(tree.a);
|
|
337
|
+
const b = sideOf(tree.b);
|
|
338
|
+
const d = decideSplit(extent, gutter, tree.ratio, a, b);
|
|
339
|
+
const startB = d.step === "no-room" ? origin + Math.max(0, extent) : d.step === "ratio" ? origin + extent * d.ratio + gutter / 2 : origin + d.a + gutter;
|
|
221
340
|
if (tree.id !== void 0 && ctx.splits !== null) {
|
|
222
|
-
const divider =
|
|
223
|
-
|
|
341
|
+
const divider = d.divider ? strip(area, x, origin + extent * d.ratio, gutter) : null;
|
|
342
|
+
const needs = floor ? [a.need, b.need] : null;
|
|
343
|
+
ctx.splits.set(tree.id, { rect: owned ? area : { ...area }, axis, ratio: d.ratio, divider, step: d.step, needs });
|
|
224
344
|
}
|
|
345
|
+
const lengthA = d.a;
|
|
346
|
+
const lengthB = d.b;
|
|
225
347
|
if (x) {
|
|
226
348
|
lay(tree.a, { x: area.x, y: area.y, width: lengthA, height: acrossA }, ctx, true);
|
|
227
349
|
lay(tree.b, { x: startB, y: area.y, width: lengthB, height: acrossB }, ctx, true);
|
|
@@ -232,7 +354,7 @@ function lay(tree, area, ctx, owned) {
|
|
|
232
354
|
}
|
|
233
355
|
|
|
234
356
|
// src/tiling/drop.ts
|
|
235
|
-
var
|
|
357
|
+
var px3 = (v) => v !== void 0 && Number.isFinite(v) && v > 0 ? v : 0;
|
|
236
358
|
function canDropOnPane(tree, dragged, at, region, area, options) {
|
|
237
359
|
if (region === "center") {
|
|
238
360
|
if (dragged === at) return { ok: false, reason: "center swap blocked: a pane dropped on itself" };
|
|
@@ -245,8 +367,8 @@ function canDropOnPane(tree, dragged, at, region, area, options) {
|
|
|
245
367
|
return dropFits(layoutSplit(dropOnPane(tree, dragged, at, region), area, options), dragged, at, area, { min: options.min, side: region });
|
|
246
368
|
}
|
|
247
369
|
function canSplitPane(target, side, options) {
|
|
248
|
-
const min =
|
|
249
|
-
const gutter =
|
|
370
|
+
const min = px3(options.min);
|
|
371
|
+
const gutter = px3(options.gap) + px3(options.handle);
|
|
250
372
|
const horizontal = side === "left" || side === "right";
|
|
251
373
|
const along = horizontal ? target.width : target.height;
|
|
252
374
|
const across = horizontal ? target.height : target.width;
|
|
@@ -257,8 +379,8 @@ function canSplitPane(target, side, options) {
|
|
|
257
379
|
}
|
|
258
380
|
function dropFits(projected, dragged, at, area, options) {
|
|
259
381
|
if (!(area.width > 0 && area.height > 0)) return { ok: true };
|
|
260
|
-
const min =
|
|
261
|
-
const fits = (r) => !!r && r.width >= min && r.height >= min;
|
|
382
|
+
const min = px3(options.min);
|
|
383
|
+
const fits = (r) => !!r && r.width >= min - EPS && r.height >= min - EPS;
|
|
262
384
|
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` };
|
|
263
385
|
}
|
|
264
386
|
|
|
@@ -449,9 +571,9 @@ function createTilingHit(ctx, basis, options = {}) {
|
|
|
449
571
|
const byId = /* @__PURE__ */ new Map();
|
|
450
572
|
const homePlace = { id: "home", held: HOME, pane: null, pieces: home ? [{ poly: rectPoly(home), box: home, cuts: () => [] }] : [], owners: /* @__PURE__ */ new Set(["home"]), slot: null };
|
|
451
573
|
byId.set("home", homePlace);
|
|
452
|
-
const placeFor = (id, held, pane, owner, piece,
|
|
574
|
+
const placeFor = (id, held, pane, owner, piece, slot2 = null) => {
|
|
453
575
|
let p = byId.get(id);
|
|
454
|
-
if (!p) byId.set(id, p = { id, held, pane, pieces: [], owners: /* @__PURE__ */ new Set(), slot });
|
|
576
|
+
if (!p) byId.set(id, p = { id, held, pane, pieces: [], owners: /* @__PURE__ */ new Set(), slot: slot2 });
|
|
455
577
|
p.pieces.push(piece);
|
|
456
578
|
p.owners.add(owner);
|
|
457
579
|
return p;
|
|
@@ -598,10 +720,10 @@ function createTilingHit(ctx, basis, options = {}) {
|
|
|
598
720
|
let refused = null;
|
|
599
721
|
for (const part of pane.parts) {
|
|
600
722
|
if (!inside(part.target.hit, p)) continue;
|
|
601
|
-
const
|
|
602
|
-
if (
|
|
603
|
-
if (live(
|
|
604
|
-
refused ??=
|
|
723
|
+
const slot2 = part.slots.find((s) => inside(s.rect, p));
|
|
724
|
+
if (slot2) {
|
|
725
|
+
if (live(slot2.place)) return { place: slot2.place, refused: null };
|
|
726
|
+
refused ??= slot2.place;
|
|
605
727
|
}
|
|
606
728
|
if (live(part.place)) return { place: part.place, refused: null };
|
|
607
729
|
refused ??= part.place;
|
|
@@ -616,7 +738,7 @@ function createTilingHit(ctx, basis, options = {}) {
|
|
|
616
738
|
homeLikeAll ??= [...byId.values()].filter((p) => p !== homePlace && homeLike(p));
|
|
617
739
|
return [...homePlace.pieces, ...homeLikeAll.flatMap((p) => p.pieces)];
|
|
618
740
|
};
|
|
619
|
-
const capped = (
|
|
741
|
+
const capped = (px5, extent) => Math.min(px5, cap * extent);
|
|
620
742
|
const visibleMemo = /* @__PURE__ */ new Map();
|
|
621
743
|
const visibleOf = (piece) => {
|
|
622
744
|
let v = visibleMemo.get(piece);
|
|
@@ -693,7 +815,7 @@ function createTilingHit(ctx, basis, options = {}) {
|
|
|
693
815
|
}
|
|
694
816
|
|
|
695
817
|
// src/tiling/targets.ts
|
|
696
|
-
var tilingTarget = (id, hit,
|
|
818
|
+
var tilingTarget = (id, hit, slot2) => ({ id, priority: 2, hit, ...slot2 ? { slot: slot2 } : {} });
|
|
697
819
|
function paneTargets(layout, options = {}) {
|
|
698
820
|
const key = options.key ?? String;
|
|
699
821
|
return [...layout].filter(([k]) => k !== options.except).map(([pane, r]) => ({ ...tilingTarget(`pane:${key(pane)}`, r), pane }));
|
|
@@ -701,8 +823,8 @@ function paneTargets(layout, options = {}) {
|
|
|
701
823
|
function orderTargets(arrange, panes, dragged, area, options) {
|
|
702
824
|
return Array.from({ length: panes.length + 1 }, (_, index) => {
|
|
703
825
|
const layout = arrange([...panes.slice(0, index), dragged, ...panes.slice(index)], area, options);
|
|
704
|
-
const
|
|
705
|
-
return { ...tilingTarget(`at:${index}`,
|
|
826
|
+
const slot2 = layout.get(dragged);
|
|
827
|
+
return { ...tilingTarget(`at:${index}`, slot2, slot2), index, layout };
|
|
706
828
|
});
|
|
707
829
|
}
|
|
708
830
|
|
|
@@ -722,7 +844,7 @@ function giveWay(panes, layout, min, age) {
|
|
|
722
844
|
|
|
723
845
|
// src/tiling/drag.ts
|
|
724
846
|
var sameRect = (a, b) => Math.abs(a.x - b.x) <= EPS && Math.abs(a.y - b.y) <= EPS && Math.abs(a.width - b.width) <= EPS && Math.abs(a.height - b.height) <= EPS;
|
|
725
|
-
var
|
|
847
|
+
var px4 = (v) => v !== void 0 && Number.isFinite(v) && v > 0 ? v : 0;
|
|
726
848
|
function tilingDrag(tree, subject, options) {
|
|
727
849
|
const { ops, area } = options;
|
|
728
850
|
const normalize = (t) => ops.normalize ? ops.normalize(t) : t;
|
|
@@ -770,8 +892,8 @@ function tilingDrag(tree, subject, options) {
|
|
|
770
892
|
const r = base.layout.get(at);
|
|
771
893
|
if (canSplitPane(r, side, options).ok) return null;
|
|
772
894
|
const along = side === "left" || side === "right";
|
|
773
|
-
const gutter =
|
|
774
|
-
const min =
|
|
895
|
+
const gutter = px4(options.gap) + px4(options.handle);
|
|
896
|
+
const min = px4(options.min);
|
|
775
897
|
const span = along ? r.width : r.height;
|
|
776
898
|
return span < min * 2 + gutter ? { code: "room-along", need: min * 2 + gutter, have: span } : { code: "room-across", need: min, have: along ? r.height : r.width };
|
|
777
899
|
};
|
|
@@ -784,7 +906,7 @@ function tilingDrag(tree, subject, options) {
|
|
|
784
906
|
const own = drawnAs(laid.tree, subjectKey);
|
|
785
907
|
const partner = drawnAs(laid.tree, held.at);
|
|
786
908
|
if (!dropFits(laid.layout, own, partner, area, { min: options.min, side: held.kind === "beside" ? held.side : "left" }).ok) {
|
|
787
|
-
const small = (r) => !r || r.width <
|
|
909
|
+
const small = (r) => !r || r.width < px4(options.min) || r.height < px4(options.min);
|
|
788
910
|
return refused(held, { code: "fit", pane: small(laid.layout.get(own)) ? own : partner });
|
|
789
911
|
}
|
|
790
912
|
return { ...laid, held, refusal: null, landing: laid.layout.get(own) ?? null, moved: movedIn(laid) };
|
|
@@ -1621,6 +1743,7 @@ export {
|
|
|
1621
1743
|
canDropOnPane,
|
|
1622
1744
|
canSplitPane,
|
|
1623
1745
|
columns,
|
|
1746
|
+
decideSplit,
|
|
1624
1747
|
dropFits,
|
|
1625
1748
|
dropOnPane,
|
|
1626
1749
|
giveWay,
|
|
@@ -1639,6 +1762,7 @@ export {
|
|
|
1639
1762
|
panesOf,
|
|
1640
1763
|
removePane,
|
|
1641
1764
|
splitFromOrder,
|
|
1765
|
+
splitNeed,
|
|
1642
1766
|
splitPane,
|
|
1643
1767
|
splitTreeOps,
|
|
1644
1768
|
swapPanes,
|