@n-uf/placement 26.11.17 → 26.11.18

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.
@@ -0,0 +1,595 @@
1
+ import { R as Rect, S as Size, P as Point } from './geometry-mL-GTRti.js';
2
+ import { T as Target } from './target-D3PiLg44.js';
3
+ import { C as CrossLimits, a as StackForm, b as StackNote, S as StackFormKind, c as StackFit } from './model-irGEua8T.js';
4
+
5
+ /**
6
+ * The scene's shapes: one model of a whole window. A scene is a stage (the window's inner rect), the edges along its
7
+ * sides (bars and columns, each a stack of items), the items, the floats above the content, and the chrome that
8
+ * floats and drop zones keep clear of. `solve(scene)` turns it into a `SceneLayout`: every rect a host draws.
9
+ *
10
+ * Plain data in and out, nothing module-global: two windows on one page are two scenes. No words, no time, no DOM.
11
+ */
12
+
13
+ /** The host's kinds of item, such as "panel" and "group". An edge takes only the kinds it lists. */
14
+ type Kind = string;
15
+ /** A side of the stage. Left and right edges are columns (they run down); top and bottom edges are bars (they run across). */
16
+ type Side = "top" | "right" | "bottom" | "left";
17
+ declare const SIDES: readonly Side[];
18
+ /** Where an item sits along its edge: packed from the start, centred in the spare length, or packed from the end. */
19
+ type Zone = "start" | "center" | "end";
20
+ declare const ZONES: readonly Zone[];
21
+ /** A float that follows the content: flush with that side or corner of `layout.content` until a drop gives it a real rect. */
22
+ type FloatAnchor = "content-top-left" | "content-top" | "content-top-right" | "content-right" | "content-bottom-right" | "content-bottom" | "content-bottom-left" | "content-left";
23
+ /** Along which axis an item lies: a column runs down, a row (a bar) runs across. */
24
+ type Orient = "column" | "row";
25
+ interface SceneItem {
26
+ readonly id: string;
27
+ readonly kind: Kind;
28
+ /**
29
+ * Its forms along a column and along a row (a bar), largest first, as `./stack` takes them. An item with no forms for
30
+ * an axis can't be laid out along it (`no-forms`).
31
+ */
32
+ readonly forms: {
33
+ readonly column?: readonly StackForm[];
34
+ readonly row?: readonly StackForm[];
35
+ };
36
+ /** How recently it was used: the smaller, the longer ago, the sooner it gives way. */
37
+ readonly used: number;
38
+ /** Kept: gives way after every item that isn't. */
39
+ readonly kept?: boolean;
40
+ /**
41
+ * The first form it may take, an index into the forms of the axis it lies along (default 0). Folding by hand sets it
42
+ * (`fold`). A float with `from` over 0 is drawn as its bar: that form's natural length, at the float's place.
43
+ */
44
+ readonly from?: number;
45
+ /**
46
+ * Reserved room: a title, window controls, a page readout. It never changes form (it keeps `forms[from]`), is never
47
+ * reordered, never dragged, and no hit or slot covers it. Its length may shrink to its form's `main.min` and grow
48
+ * with spare room when the form `grows`; window controls have `min` equal to `natural`.
49
+ */
50
+ readonly fixed?: boolean;
51
+ /** Closed: it keeps its place in its edge (or its float rect) but takes no room and has no targets. */
52
+ readonly closed?: boolean;
53
+ /** Its zone in its edge (default start). */
54
+ readonly align?: Zone;
55
+ /** Its size as a float: `floatAt` with no rect uses it, and a float drop sets it. */
56
+ readonly floatSize?: Size;
57
+ }
58
+ interface Edge {
59
+ readonly id: string;
60
+ readonly side: Side;
61
+ /** 0 is the outermost on its side (a title bar outside a toolbar). */
62
+ readonly ring: number;
63
+ /**
64
+ * Top and bottom bars only: across the whole stage (`"full"`, the default) or between the side columns
65
+ * (`"between"`). Left and right edges ignore it.
66
+ */
67
+ readonly span?: "full" | "between";
68
+ /** The kinds a drop may bring here. Deny by default: an empty list takes nothing (an anchor). */
69
+ readonly accepts: readonly Kind[];
70
+ /** Ids in order, fixed and closed items included. */
71
+ readonly items: readonly string[];
72
+ /** The size it may take across (a column's width, a bar's height), and the rail width when nothing sets it. */
73
+ readonly cross: CrossLimits;
74
+ /** `"overlay"` lies over the content instead of shortening it (default `"reserved"`). */
75
+ readonly mode?: "reserved" | "overlay";
76
+ readonly gap?: number;
77
+ readonly pad?: {
78
+ readonly start?: number;
79
+ readonly end?: number;
80
+ };
81
+ /** The » entry's length along the edge. */
82
+ readonly menu?: {
83
+ readonly main: number;
84
+ };
85
+ /**
86
+ * The user's size across (a column dragged wider), clamped to `[max(cross.min, the widest open setter's cross.min),
87
+ * cross.max]`, so an open item's `cross.min` wins over a smaller size. Used only while an item sets the cross size.
88
+ */
89
+ readonly size?: number;
90
+ /** A column drawn as a rail (nothing in it sets its width) shows its closed items too, as tabs marked `closed`. */
91
+ readonly railShowsClosed?: boolean;
92
+ /**
93
+ * An icons-only edge (a thin rail of vertical toolbars along a window side): its items take only their `icons` form
94
+ * (and the » menu after it), stacked, each grip the divider. An item with no `icons` form is left out
95
+ * (`no-icons-form`).
96
+ */
97
+ readonly compact?: boolean;
98
+ /**
99
+ * The kinds each zone takes, narrowing `accepts`: with it, a zone not listed takes nothing. A panel column with
100
+ * `{ start: ["panel"], end: ["group"] }` has its panels at the top and a tray of toolbars at its foot (the end zone, one
101
+ * toolbar per row): a toolbar in the tray takes only its `wrap` or `icons` form (never the menu), and the panels give
102
+ * way first. A group never opens such a column on its own: an empty edge offers its strip only to the kinds its start
103
+ * zone takes.
104
+ */
105
+ readonly zoneAccepts?: ZoneAccepts;
106
+ /** The drop strip's depth while the edge is empty, px (default {@link DEFAULT_STRIP}). */
107
+ readonly strip?: number;
108
+ /**
109
+ * How a gap's hit runs along the edge. The gaps always split the edge halfway between neighbouring insertion lines, so
110
+ * free space and short items (a toolbar, a closed or folded panel) are covered end to end. A number: over an open
111
+ * item's body only (a panel), the hit narrows to a band that many px around the line, so the middle of a panel is no
112
+ * gap and the pointer falls through to the float target, or to none. `"middle"`: no band, so panels are split too.
113
+ * Default {@link DEFAULT_HIT_BAND}.
114
+ */
115
+ readonly hitBand?: number | "middle";
116
+ /**
117
+ * A dynamic column (left and right only): made by a drop on a column line, deleted when it holds no item, folded whole
118
+ * into its side's rail by give-way (`Scene.contentMin`) or when every member is folded by hand. Its `accepts`,
119
+ * `cross`, `gap`, `pad` and `menu` come from `Scene.columns[side]` when the changes make it.
120
+ */
121
+ readonly column?: boolean;
122
+ }
123
+ /** What a side's new columns are made from. */
124
+ interface ColumnTemplate {
125
+ readonly accepts: readonly Kind[];
126
+ readonly cross: CrossLimits;
127
+ readonly gap?: number;
128
+ readonly pad?: {
129
+ readonly start?: number;
130
+ readonly end?: number;
131
+ };
132
+ readonly menu?: {
133
+ readonly main: number;
134
+ };
135
+ /** The kinds each zone takes in the columns made from it (`Edge.zoneAccepts`). */
136
+ readonly zoneAccepts?: ZoneAccepts;
137
+ }
138
+ /** Per zone, the kinds it takes. */
139
+ type ZoneAccepts = Readonly<Partial<Record<Zone, readonly Kind[]>>>;
140
+ /** Whether `edge` takes kind `kind` in `zone`: its `accepts`, narrowed by `zoneAccepts` when given (a zone not listed takes nothing). */
141
+ declare const zoneTakes: (edge: {
142
+ readonly accepts: readonly Kind[];
143
+ readonly zoneAccepts?: ZoneAccepts;
144
+ }, zone: Zone, kind: Kind) => boolean;
145
+ /** The zones of `edge` that take `kind`, in order. */
146
+ declare const zonesTaking: (edge: {
147
+ readonly accepts: readonly Kind[];
148
+ readonly zoneAccepts?: ZoneAccepts;
149
+ }, kind: Kind) => Zone[];
150
+ /** A side's one rail strip: folded columns show in it as segments, in ring order. */
151
+ interface RailSpec {
152
+ /** Its width, px. */
153
+ readonly width: number;
154
+ /** The kinds a drop on the rail may bring (it docks folded). */
155
+ readonly accepts: readonly Kind[];
156
+ }
157
+ interface SceneFloat {
158
+ readonly id: string;
159
+ /** Its rect in stage px (it never scrolls with the content). With `anchor`, only its size counts. */
160
+ readonly rect: Rect;
161
+ /** Follow the content's side or corner until a drop gives it a real rect. */
162
+ readonly anchor?: FloatAnchor;
163
+ /** Which of the item's forms it uses (default `"column"`). */
164
+ readonly orient?: Orient;
165
+ }
166
+ interface Scene {
167
+ /** The window's inner rect. */
168
+ readonly stage: Rect;
169
+ readonly edges: readonly Edge[];
170
+ readonly items: Readonly<Record<string, SceneItem>>;
171
+ /** Stacking order: the last is on top. */
172
+ readonly floats: readonly SceneFloat[];
173
+ /** The kinds that may float. Deny by default. */
174
+ readonly floatKinds: readonly Kind[];
175
+ /** Rects that floats and drop zones keep clear of (a title the host draws itself, a status line). */
176
+ readonly chrome?: readonly Rect[];
177
+ /** Spots where a release cancels: `targets` gives a `none` target over each. */
178
+ readonly blocked?: readonly Rect[];
179
+ /** Per side (left, right): what a new column is made from. A side without one gets no new columns. */
180
+ readonly columns?: Partial<Record<"left" | "right", ColumnTemplate>>;
181
+ /** Per side (left, right): its rail. A side without one keeps folded columns as columns. */
182
+ readonly rails?: Partial<Record<"left" | "right", RailSpec>>;
183
+ /**
184
+ * The least the content may be. While the content is narrower than `width`, dynamic columns shrink toward their
185
+ * minimum, then fold whole into their side's rail: unkept before kept, the one whose newest use is oldest first, the
186
+ * outer first, the left first. Under `height`, a `content-short` note.
187
+ */
188
+ readonly contentMin?: {
189
+ readonly width: number;
190
+ readonly height: number;
191
+ };
192
+ /**
193
+ * How a one-panel column folded by hand shows (default `"bar"`): `"bar"` sends it to its side's rail; `"ride"` draws it
194
+ * as a title bar over the first open column of its side, at that column's width, taking no width of its own.
195
+ */
196
+ readonly handFold?: "bar" | "ride";
197
+ /** Space kept clear inside the stage's edges, px (default 0 each). */
198
+ readonly inset?: {
199
+ readonly top?: number;
200
+ readonly right?: number;
201
+ readonly bottom?: number;
202
+ readonly left?: number;
203
+ };
204
+ /** Space after each left or right edge and each rail that takes room, toward the content, px (default 0). */
205
+ readonly gutter?: number;
206
+ }
207
+ /** An item as laid out. */
208
+ interface SceneItemLayout {
209
+ /** Stage px. An item in the » menu has the menu entry's rect. */
210
+ readonly rect: Rect;
211
+ readonly kind: Kind;
212
+ /** The form it took: an index into the forms of its axis. */
213
+ readonly form: number;
214
+ readonly formKind: StackFormKind;
215
+ /** Docked: its edge and zone. */
216
+ readonly edge?: string;
217
+ readonly zone?: Zone;
218
+ readonly floating?: boolean;
219
+ readonly inMenu?: boolean;
220
+ /** A rail tab (its column is a rail). */
221
+ readonly tab?: boolean;
222
+ /** A closed item shown as a rail tab (`railShowsClosed`). */
223
+ readonly closed?: boolean;
224
+ readonly fixed?: boolean;
225
+ /** Drawn as a segment of this side's rail (its column is folded). */
226
+ readonly rail?: "left" | "right";
227
+ /** Drawn as a title bar riding on this column (`handFold: "ride"`). */
228
+ readonly rides?: string;
229
+ /** Its column folded: by hand (every member folded) or by give-way. */
230
+ readonly folded?: "hand" | "auto";
231
+ /** A `wrap` form: the word indexes per row (the words wrap beside the grip, a hanging indent). */
232
+ readonly rows?: readonly (readonly number[])[];
233
+ /** Its grip: a `wrap` form's lead cell at the start of row one, or a form's `grip` strip (an icons strip's, on top). */
234
+ readonly grip?: Rect;
235
+ }
236
+ /** An edge as laid out. */
237
+ interface SceneEdgeLayout {
238
+ readonly side: Side;
239
+ readonly ring: number;
240
+ /** Stage px: the strip it takes (zero across when nothing is drawn in it). */
241
+ readonly rect: Rect;
242
+ /** Its size across. */
243
+ readonly cross: number;
244
+ /** Its » entry and the items in it, or null. */
245
+ readonly menu: {
246
+ readonly rect: Rect;
247
+ readonly items: readonly string[];
248
+ } | null;
249
+ /** The ids drawn as rail tabs, in order (empty unless the column is a rail). */
250
+ readonly tabs: readonly string[];
251
+ /**
252
+ * The stack fits behind it, in stack-local px: `stack` is the one drawn, `free` the first fit (before `size` or the
253
+ * rail re-solved it). `solve`'s `previous` reads both; a host needs neither.
254
+ */
255
+ readonly stack: StackFit;
256
+ readonly free: StackFit;
257
+ /** A dynamic column folded into its side's rail (its rect is zero wide there): by hand or by give-way. */
258
+ readonly folded?: "hand" | "auto";
259
+ /** Shrunk by give-way below the width it asks for. */
260
+ readonly shrunk?: boolean;
261
+ /** Riding on this column (its rect is the bars'). */
262
+ readonly rides?: string;
263
+ }
264
+ /** A side's rail as laid out. */
265
+ interface SceneRailLayout {
266
+ readonly rect: Rect;
267
+ /** One per member of each folded column, in ring order. */
268
+ readonly segments: readonly {
269
+ readonly id: string;
270
+ readonly edge: string;
271
+ readonly rect: Rect;
272
+ }[];
273
+ }
274
+ /**
275
+ * Why the layout looks as it does:
276
+ * - a stack's note with its `edge` (`form-down`, `to-menu`, `too-wide`, `no-forms`, `overflow`);
277
+ * - `unknown-item`: an id in an edge or a float that `items` lacks (left out);
278
+ * - `twice`: an item placed in two places (the first in cut order wins, edges before floats);
279
+ * - `float-clamped`, `float-moved`: a float was moved into the stage, or clear of what it would cover;
280
+ * - `float-covers`: no clear place exists, and it covers the least it can.
281
+ * - `column-shrunk`, `column-folded`, `kept-folded`: give-way by `contentMin.width`, in give-way order;
282
+ * - `content-narrow`, `content-short`: the content is still under `contentMin` (overlay bars count against the height).
283
+ * - `content-changed`: under `previous`, `content` is not the rect `previous.content` was (`from`, `to`). A host refits
284
+ * its zoom only on this note.
285
+ * - `no-vertical-form`: an item left out of a vertical place (a rail, a vertical float) because only `wrap` forms are
286
+ * left to it (vertical means icons: give a word group an `icons` form).
287
+ */
288
+ type SceneNote = ({
289
+ readonly edge: string;
290
+ } & StackNote) | {
291
+ readonly code: "unknown-item";
292
+ readonly id: string;
293
+ } | {
294
+ readonly code: "twice";
295
+ readonly id: string;
296
+ } | {
297
+ readonly code: "float-clamped" | "float-moved" | "float-covers";
298
+ readonly id: string;
299
+ } | {
300
+ readonly code: "column-shrunk";
301
+ readonly edge: string;
302
+ readonly from: number;
303
+ readonly to: number;
304
+ } | {
305
+ readonly code: "column-folded" | "kept-folded";
306
+ readonly edge: string;
307
+ } | {
308
+ readonly code: "content-narrow";
309
+ readonly width: number;
310
+ readonly min: number;
311
+ } | {
312
+ readonly code: "content-short";
313
+ readonly height: number;
314
+ readonly min: number;
315
+ } | {
316
+ readonly code: "content-changed";
317
+ readonly from: Rect;
318
+ readonly to: Rect;
319
+ } | {
320
+ readonly code: "no-vertical-form";
321
+ readonly id: string;
322
+ readonly edge?: string;
323
+ } | {
324
+ readonly code: "no-icons-form";
325
+ readonly id: string;
326
+ readonly edge: string;
327
+ };
328
+ type SceneNoteCode = SceneNote["code"];
329
+ interface SceneLayout {
330
+ /** Every item drawn (closed items only when shown as rail tabs). */
331
+ readonly items: Readonly<Record<string, SceneItemLayout>>;
332
+ readonly edges: Readonly<Record<string, SceneEdgeLayout>>;
333
+ /** What is left for the content (the pages). Overlay edges lie over it. */
334
+ readonly content: Rect;
335
+ /** The floats drawn, in stacking order (the last on top). */
336
+ readonly floats: readonly string[];
337
+ /** The rails shown (a side with a folded column). */
338
+ readonly rails: Readonly<Partial<Record<"left" | "right", SceneRailLayout>>>;
339
+ readonly notes: readonly SceneNote[];
340
+ }
341
+ interface SolveOptions {
342
+ /**
343
+ * The layout the scene had before: each edge's fit goes to `fitStack` as `previous`, so a press reshapes nothing. An
344
+ * item docked now that was closed or absent then has just opened: it counts as the newest (its largest form while it
345
+ * fits; the others give way by the usual rules), and its column is weighed anew by give-way.
346
+ */
347
+ readonly previous?: SceneLayout;
348
+ /** Edge or item ids solved without `previous` (an edge, or the edges holding the item; a column weighed anew). */
349
+ readonly fresh?: readonly string[];
350
+ }
351
+ /** A drop strip's depth inside the content while an edge is empty, px. */
352
+ declare const DEFAULT_STRIP = 24;
353
+ /** A gap's hit over an open item's body (a panel): a band this many px around the gap's insertion line. */
354
+ declare const DEFAULT_HIT_BAND = 24;
355
+ /** A float's size when neither the item nor the call gives one, px. */
356
+ declare const DEFAULT_FLOAT_SIZE: Size;
357
+
358
+ /**
359
+ * The scene's pure changes. Each returns a new scene and leaves the one it was given as it was; a change that can't
360
+ * apply (an unknown item or edge, a fixed item, a kind the edge or the float layer doesn't take) returns the scene
361
+ * given, the same object, so `after === before` says nothing changed.
362
+ *
363
+ * - `moveTo(scene, id, { edge, zone?, at })`: docks the item in that edge, before the `at`-th item of the zone (counting
364
+ * the zone's items without it, closed ones included), or at the zone's end. The zone becomes the item's `align`.
365
+ * `{ kind: "column", side, ring }` makes a new column from `scene.columns[side]` at that ring (`Infinity`: the side's
366
+ * inner end, "Move to › Dock left"); `{ kind: "rail", side, ring }` does the same with the item folded by hand, so it
367
+ * shows in the rail; `{ kind: "float", rect?, anchor? }` floats it. A dynamic column an item leaves empty is deleted
368
+ * and its side's rings are closed up.
369
+ * - `homeFor(scene, id, start)`: the place a start scene gives the item, for `moveTo`.
370
+ * - `floatAt(scene, id, rect?, orient?)`: floats it on top at `rect` (its size becomes `floatSize`); with no rect, at
371
+ * its `floatSize` (or the default size) anchored to the content's top-right corner.
372
+ * - `fold(scene, id, on)`: folded by hand starts it at its second form (`from: 1`); unfolding clears `from`.
373
+ * - `use(scene, id)`: the newest age. Under `previous` it reshapes nothing.
374
+ * - `keep(scene, id, on)`, `open(scene, id)`, `close(scene, id)`.
375
+ * - `raise(scene, id)`: a float to the top of the stack; no use, no reshape.
376
+ * - `orient(scene, id, orient)`: a float's axis.
377
+ * - `resize(scene, edge, size)`: the user's size across; a size that isn't a finite number clears it.
378
+ */
379
+
380
+ /** Where a docked item goes: before the `at`-th item of `zone` (default the item's own zone) in `edge`. */
381
+ interface DockPlace {
382
+ readonly kind?: "gap";
383
+ readonly edge: string;
384
+ readonly zone?: Zone;
385
+ readonly at: number;
386
+ }
387
+ /** A new column on `side` at `ring` (the edges at that ring and inward move in one); `Infinity` is the side's inner end. */
388
+ interface ColumnPlace {
389
+ readonly kind: "column";
390
+ readonly side: "left" | "right";
391
+ readonly ring: number;
392
+ }
393
+ /** Docked folded: a new column at `ring` holding the item folded by hand, so it shows in the side's rail. */
394
+ interface RailPlace {
395
+ readonly kind: "rail";
396
+ readonly side: "left" | "right";
397
+ readonly ring: number;
398
+ }
399
+ /** Floating at `rect` (or, with none, at its last size anchored to the content). */
400
+ interface FloatPlace {
401
+ readonly kind: "float";
402
+ readonly rect?: Rect;
403
+ /** Following the content (only its size counts then). */
404
+ readonly anchor?: FloatAnchor;
405
+ }
406
+ type Place = DockPlace | ColumnPlace | RailPlace | FloatPlace;
407
+ /** The scene with the item out of every edge and every float (a dynamic column it leaves empty is deleted). */
408
+ declare function lift(scene: Scene, id: string): Scene;
409
+ declare function moveTo(scene: Scene, id: string, place: Place): Scene;
410
+ declare function floatAt(scene: Scene, id: string, at?: Rect, orient?: Orient): Scene;
411
+ declare function fold(scene: Scene, id: string, on: boolean): Scene;
412
+ declare function use(scene: Scene, id: string): Scene;
413
+ declare function keep(scene: Scene, id: string, on: boolean): Scene;
414
+ declare function open(scene: Scene, id: string): Scene;
415
+ declare function close(scene: Scene, id: string): Scene;
416
+ declare function raise(scene: Scene, id: string): Scene;
417
+ declare function orient(scene: Scene, id: string, to: Orient): Scene;
418
+ declare function resize(scene: Scene, edgeId: string, size: number): Scene;
419
+ /**
420
+ * The place `start` (a scene as it began: the host's start or reset scene) gives an item, for Dock, Put back and Reset
421
+ * position: its zone and place in the same edge (before the first item that followed it there and is still there), a
422
+ * new column at its ring when its column is gone, or its float rect (and anchor). Null when `start` places it nowhere
423
+ * or in an edge `scene` no longer has that isn't a column. `moveTo(scene, id, place)` puts it there.
424
+ */
425
+ declare function homeFor(scene: Scene, id: string, start: Scene): Place | null;
426
+ /**
427
+ * Dock, Put back and Reset position: the item where `start` (the loaded scene) has it, fold included. It goes to
428
+ * `homeFor`'s place and takes `start`'s `from` (unfolded when `start` has none), so a "Move to › rail" (which folds it)
429
+ * followed by Dock brings it back open. The scene given back unchanged when `start` places it nowhere.
430
+ */
431
+ declare function dockHome(scene: Scene, id: string, start: Scene): Scene;
432
+
433
+ /**
434
+ * The scene's stored form. `storeScene(scene)` gives plain JSON-safe data; `readScene(data, base)` reads it back over
435
+ * `base` (the host's scene as it starts: its item definitions, edges, kinds and stage) and never throws.
436
+ *
437
+ * ```ts
438
+ * interface StoredScene {
439
+ * v: 1;
440
+ * edges: { id: string; side: Side; ring: number; items: string[]; size?: number; column?: true }[];
441
+ * floats: { id: string; x: number; y: number; width: number; height: number; orient?: "row" | "column"; anchor?: FloatAnchor }[];
442
+ * items: Record<string, { used: number; kept?: true; from?: number; closed?: true; align?: "center" | "end"; floatSize?: { width: number; height: number } }>;
443
+ * }
444
+ * ```
445
+ *
446
+ * Nothing about kinds, forms or limits is stored: those are the host's (`base`). An edge is matched by its id: its
447
+ * side, ring and limits come from `base`, its order of items and its `size` from the store. Dynamic columns
448
+ * (`column: true`) are the store's: one `base` lacks is made from `base.columns[side]`, its ring is the stored one, and
449
+ * columns left empty are deleted, the rings closed up. No float has a pinned field: one an old store has is listed and
450
+ * ignored.
451
+ *
452
+ * Reading is lenient: anything but an object of version 1 gives `base` back with the reason in `error`. Inside one,
453
+ * whatever can't be used is dropped and listed in `dropped` (an unknown edge `edge:<id>`, an unknown or repeated item,
454
+ * an item an edge doesn't accept `edge:<edge>:<id>`, a fixed item in another edge than `base`'s `edge:<edge>:<id>`, a
455
+ * float of a kind that doesn't float `float:<id>`, a bad field `item:<id>:<field>`, an unknown top-level field
456
+ * `<field>`). A stored edge's order is kept exactly, fixed items where the store put them (in their own edge); a fixed
457
+ * item the store lacks goes back to its base place (trailing ones last). An item the store places nowhere goes where
458
+ * `base` has it, before a stored trailing run of fixed items.
459
+ * A float's rect is clamped into the stage on read.
460
+ */
461
+
462
+ interface StoredSceneEdge {
463
+ readonly id: string;
464
+ readonly side: Side;
465
+ readonly ring: number;
466
+ readonly items: readonly string[];
467
+ readonly size?: number;
468
+ /** A dynamic column: read back from `base.columns[side]` even when `base` doesn't have it. */
469
+ readonly column?: true;
470
+ }
471
+ interface StoredSceneFloat {
472
+ readonly id: string;
473
+ readonly x: number;
474
+ readonly y: number;
475
+ readonly width: number;
476
+ readonly height: number;
477
+ readonly orient?: Orient;
478
+ readonly anchor?: FloatAnchor;
479
+ }
480
+ interface StoredSceneItem {
481
+ readonly used: number;
482
+ readonly kept?: true;
483
+ readonly from?: number;
484
+ readonly closed?: true;
485
+ readonly align?: "center" | "end";
486
+ readonly floatSize?: Size;
487
+ }
488
+ interface StoredScene {
489
+ readonly v: 1;
490
+ readonly edges: readonly StoredSceneEdge[];
491
+ readonly floats: readonly StoredSceneFloat[];
492
+ readonly items: Readonly<Record<string, StoredSceneItem>>;
493
+ }
494
+ interface SceneRead {
495
+ readonly scene: Scene;
496
+ /** What was left out, as listed in the module's docs. */
497
+ readonly dropped: readonly string[];
498
+ /** Set when nothing could be read: `scene` is `base`. */
499
+ readonly error?: string;
500
+ }
501
+ declare function storeScene(scene: Scene): StoredScene;
502
+ declare function readScene(data: unknown, base: Scene): SceneRead;
503
+
504
+ /**
505
+ * `targets(scene, dragged, { previous, endReach, floatSize })`: every drop target for one dragged item, in the shape
506
+ * `@n-uf/motion/drag` takes (`id`, `priority`, `hit`, `slot?`, `free?`). Each target's `after(point, grab)` is the scene
507
+ * a release there commits and its layout, `solve(after.scene, { previous })`: the host draws every item from that layout
508
+ * during the preview (C22), so the preview is the result by construction.
509
+ *
510
+ * - `gap:<edge>:<zone>:<at>` (priority 2): for every edge whose `accepts` lists the dragged item's kind (deny by
511
+ * default, C25), a target before the `at`-th item of each zone (start, center, end) and at each zone's end, so an
512
+ * empty center or end zone can be opened. Only where the item fits (C29): after the drop it isn't in the » menu, the
513
+ * edge doesn't overflow, nothing in the edge is newly `too-wide`, every fixed item of the edge keeps its form and its
514
+ * place (a growing one may give up its spare length), and its slot covers no chrome. The hit is the edge's stretch
515
+ * between the neighbouring gaps (split halfway between their insertion lines; over an open item's body only a
516
+ * `hitBand` around the line), across the larger of the edge's thickness before and after the drop (a compact edge's
517
+ * reaching `RAIL_REACH` further inward), the first and last reaching `endReach` px past the edge's ends. Other edges'
518
+ * rects, as they are now and with the item lifted, trim it: one across from the edge at its end along the edge, one
519
+ * beside it at its side. It is cut clear of every fixed item that doesn't grow and of the chrome rects (a gap whose
520
+ * line lies inside one has no target); a growing fixed item (a title) is not cut out, so a pointer over it picks the
521
+ * nearest gap. `marker` is the insertion line after the drop, across the edge; `slot` the item's rect after the drop.
522
+ * - `strip:<edge>` (2): an empty edge that accepts the kind (its start zone takes it): a strip `Edge.strip` px (default
523
+ * 24) deep along its side, inside the content and clear of overlay edges, so never over a docked edge or a panel's
524
+ * body (a compact rail's strip alone stays at the window edge, its own place); a gap hit that spans it trims its ends,
525
+ * and with nothing left it has no target. `after` shows the edge holding the item.
526
+ * - `float:<id>` (3, free): when `floatKinds` lists the kind. The hit covers the whole plane; the landing is the float
527
+ * with the pointer holding it at `grab` (default its middle), in the stage and clear of the docked items, the bars
528
+ * and the chrome. Its size: `options.floatSize`, else its float's size, else the item's `floatSize`, else the default.
529
+ * - `column:<side>:<ring>` (2): a new column on each column line of a side whose `scene.columns[side]` takes the kind
530
+ * (outside the outermost open column, between two, inside the innermost; on a side with none, at the content's
531
+ * edge), `COLUMN_REACH` px each way, only where the new column shows open.
532
+ * - `rail:<side>:<ring>` (1): docking folded into a side's rail (its rail and its template take the kind), before each
533
+ * folded column's segments and after the last, or a strip `RAIL_EDGE` px deep at the side's outer edge when no rail
534
+ * shows.
535
+ * - `none:<i>` (1): over each `scene.blocked` rect. It takes the pointer, and a release there commits nothing.
536
+ * - `home:<id>` (1): over a docked item's own rect (or its » entry); a floating item has none, so a move inside its own
537
+ * rect is a float move. A release there commits nothing. A gap, column line or rail drop that
538
+ * would put the item back where it is (the gap beside it, its own column's line, its own side's rail) keeps its id but
539
+ * is a home too: place `home`, no slot, nothing committed.
540
+ *
541
+ * `stops(scene, id)` orders the same targets (no home, no none) for "Move to ›" and the arrow keys.
542
+ *
543
+ * A dropped item counts as just used (`use`). An unknown, fixed or closed item has no targets.
544
+ */
545
+
546
+ type ScenePlace = {
547
+ readonly kind: "gap";
548
+ readonly edge: string;
549
+ readonly zone: Zone;
550
+ readonly at: number;
551
+ } | ColumnPlace | RailPlace | {
552
+ readonly kind: "float";
553
+ } | {
554
+ readonly kind: "home";
555
+ } | {
556
+ readonly kind: "none";
557
+ };
558
+ interface SceneAfter {
559
+ readonly scene: Scene;
560
+ readonly layout: SceneLayout;
561
+ }
562
+ interface SceneTarget extends Target {
563
+ /** The item dragged. */
564
+ readonly item: string;
565
+ readonly place: ScenePlace;
566
+ /** Gaps and strips: the line where the item's leading edge lands, zero thick, across the edge after the drop. */
567
+ readonly marker?: Rect;
568
+ /** The scene a release here commits and its layout. Only a float's depends on the pointer. */
569
+ after(point: Point, grab?: Point): SceneAfter;
570
+ }
571
+ interface SceneTargetOptions {
572
+ /** The layout before the drag: every `after` is solved with it, as the drop will be. */
573
+ readonly previous?: SceneLayout;
574
+ /** How far the first and last gaps of an edge reach past its ends, px (default 0). */
575
+ readonly endReach?: number;
576
+ /** The float's size for the float target. */
577
+ readonly floatSize?: Size;
578
+ /** As `solve`'s: edge or item ids solved without `previous`, in every `after` too. */
579
+ readonly fresh?: readonly string[];
580
+ }
581
+ declare function targets(scene: Scene, dragged: string, options?: SceneTargetOptions): SceneTarget[];
582
+ /**
583
+ * What a fixed item reserves in `l`: its drawn rect, or for a form that grows only its natural length, placed by its
584
+ * zone (from its start, from its end in the end zone, centred in the centre zone). No hit or slot ever lies there, so a
585
+ * host that draws "no drop" areas reads them from here.
586
+ */
587
+ declare function reservedRect(scene: Scene, l: SceneLayout, id: string): Rect;
588
+ /**
589
+ * `stops(scene, id, options?)`: the places for "Move to ›" and the arrow keys, in reading order, from the same targets
590
+ * (`home` and `none` left out): the left side outer to inner, the top bars, the bottom bars, the right side inner to
591
+ * outer, floating last. Each stop is a target, so its `after` is the move.
592
+ */
593
+ declare function stops(scene: Scene, dragged: string, options?: SceneTargetOptions): SceneTarget[];
594
+
595
+ export { storeScene as $, ZONES as A, type ZoneAccepts as B, type ColumnPlace as C, DEFAULT_FLOAT_SIZE as D, type Edge as E, type FloatAnchor as F, close as G, dockHome as H, floatAt as I, fold as J, type Kind as K, homeFor as L, keep as M, lift as N, type Orient as O, type Place as P, moveTo as Q, type RailPlace as R, type Scene as S, open as T, orient as U, raise as V, readScene as W, reservedRect as X, resize as Y, type Zone as Z, stops as _, type ScenePlace as a, targets as a0, use as a1, zoneTakes as a2, zonesTaking as a3, type Side as b, type SceneNoteCode as c, type SceneLayout as d, type StoredScene as e, type SceneTarget as f, type SolveOptions as g, type ColumnTemplate as h, DEFAULT_HIT_BAND as i, DEFAULT_STRIP as j, type DockPlace as k, type FloatPlace as l, type RailSpec as m, SIDES as n, type SceneAfter as o, type SceneEdgeLayout as p, type SceneFloat as q, type SceneItem as r, type SceneItemLayout as s, type SceneNote as t, type SceneRailLayout as u, type SceneRead as v, type SceneTargetOptions as w, type StoredSceneEdge as x, type StoredSceneFloat as y, type StoredSceneItem as z };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@n-uf/placement",
3
- "version": "26.11.17",
3
+ "version": "26.11.18",
4
4
  "description": "Where things go: desk docks, rails and palettes, panel columns, toolbar groups, and the drop targets for each. Pure state in, rects out. No DOM, no framework, no motion.",
5
5
  "keywords": [
6
6
  "layout",
@@ -60,6 +60,10 @@
60
60
  "types": "./dist/scene.d.ts",
61
61
  "default": "./dist/scene.js"
62
62
  },
63
+ "./scene/cases": {
64
+ "types": "./dist/scene-cases.d.ts",
65
+ "default": "./dist/scene-cases.js"
66
+ },
63
67
  "./package.json": "./package.json"
64
68
  },
65
69
  "publishConfig": {