@n-uf/placement 26.11.15 → 26.11.16

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/dist/stack.d.ts CHANGED
@@ -1,206 +1,8 @@
1
+ import { d as StackInput, F as FitOptions, b as StackFit, e as StackItem } from './model-CMH_27_g.js';
2
+ export { C as CrossLimits, D as DEFAULT_MENU, f as DEFAULT_RAIL, G as GroupFormKind, M as MainSize, P as PanelFormKind, g as PlacedStackItem, h as StackAxis, S as StackForm, a as StackFormKind, i as StackMenu, c as StackNote, j as StackNoteCode, k as formSetsCross, w as withItem } from './model-CMH_27_g.js';
1
3
  import { R as Rect, P as Point, S as Size } from './geometry-mL-GTRti.js';
2
4
  import { T as Target } from './target-D3PiLg44.js';
3
5
 
4
- /**
5
- * The edge stack's shapes. A stack is the items along one edge of a stage: a column (vertical, a side region) or a
6
- * row (horizontal, a bar). An item is a panel or a control group; it declares its forms, largest first, and the
7
- * solver (`fitStack`) picks one per item. Plain data in and out: no words, no time, no DOM.
8
- *
9
- * The form kinds are structural labels the app draws by; the solver reads only `menu` (a form with no room of its own)
10
- * and, for the cross size, `open`. Panel and group kinds may be mixed on one item.
11
- */
12
-
13
- /** `"column"` runs the stack down (its main size is a height, its cross size a width); `"row"` runs it across. */
14
- type StackAxis = "column" | "row";
15
- /** How a panel draws: open (header and body), a header only, a rail icon, or an entry in the » menu. */
16
- type PanelFormKind = "open" | "header" | "rail" | "menu";
17
- /**
18
- * How a control group draws: a row of words, the words stacked, icons only, `fold` (the group's handle with its own »,
19
- * in line at its place and with its own length) or an entry in the shared » menu.
20
- */
21
- type GroupFormKind = "row" | "stacked" | "icons" | "fold" | "menu";
22
- type StackFormKind = PanelFormKind | GroupFormKind;
23
- /** Along the stack: `min` is the least it can be drawn, `natural` what it asks for; `grows` takes spare length. */
24
- interface MainSize {
25
- readonly min: number;
26
- readonly natural: number;
27
- readonly grows?: boolean;
28
- }
29
- /** One way to draw an item. A `menu` form takes no room in the stack (the » entry stands for it). */
30
- interface StackForm {
31
- readonly kind: StackFormKind;
32
- readonly main: MainSize;
33
- /**
34
- * Across the stack: `natural` is what this form asks for (it sets the stack's cross size when `setsCross`); `min`
35
- * is the least it can be drawn across (default `natural`). A form that doesn't set the cross size takes its next
36
- * form only when its `min` is over the stack's cross size, so a header stays in a column an open panel made
37
- * narrow when it has a small `min`.
38
- */
39
- readonly cross: {
40
- readonly natural: number;
41
- readonly min?: number;
42
- };
43
- /**
44
- * Whether this form sets the stack's cross size (the column's width, the bar's height). Default: true for a
45
- * panel's `open`, false for everything else (a group never sets a column's width).
46
- */
47
- readonly setsCross?: boolean;
48
- /**
49
- * Give-way order (default 0). When the stack is too long, the step taken is the one into the lowest-ranked next
50
- * form across all items (the form the item would take, not the one it leaves); ties go unkept before kept, then the
51
- * item used longest ago, then the later in the stack. A pinned primary's last forms get a higher rank, so every
52
- * other group collapses before it does.
53
- */
54
- readonly rank?: number;
55
- }
56
- interface StackItem {
57
- readonly id: string;
58
- /** Largest first. The solver starts at `from` and steps down one at a time. An item with none is left out. */
59
- readonly forms: readonly StackForm[];
60
- /** How recently it was used: the smaller, the longer ago, the sooner it gives way. */
61
- readonly used: number;
62
- /** Kept: gives way after every item that isn't. */
63
- readonly kept?: boolean;
64
- /**
65
- * The first form the item may take, an index into `forms` (default 0; a panel folded by hand starts at its header).
66
- * The solver never goes above it. `form` in the result and in the notes are indexes into `forms`, not into what is
67
- * left after `from`.
68
- */
69
- readonly from?: number;
70
- }
71
- /** The cross size a stack may take. With no form setting it, the stack is a `rail` wide (default {@link DEFAULT_RAIL}). */
72
- interface CrossLimits {
73
- readonly min: number;
74
- readonly max: number;
75
- readonly rail?: number;
76
- }
77
- interface StackInput {
78
- readonly axis: StackAxis;
79
- /** The stack's length along the axis. */
80
- readonly length: number;
81
- readonly cross: CrossLimits;
82
- /** In order, from the start of the stack. */
83
- readonly items: readonly StackItem[];
84
- /** The » menu entry's size along the stack, taken only while an item is in the menu (default {@link DEFAULT_MENU}). */
85
- readonly menu?: {
86
- readonly main: number;
87
- };
88
- /**
89
- * The space between neighbouring drawn items, px (default 0). The » entry is a neighbour of the last drawn item. It
90
- * counts toward the length and the rects include it, so an app draws at the solver's rects.
91
- */
92
- readonly gap?: number;
93
- /** Space before the first item and after the last (or after the » entry), px (default 0 each). Counts toward the length. */
94
- readonly pad?: {
95
- readonly start?: number;
96
- readonly end?: number;
97
- };
98
- /**
99
- * Strict cross sizes (default false): a form is never drawn thinner than its `cross.min` (default its `natural`), so a
100
- * form that sets the cross size and has a `cross.min` over `cross.max` steps down to its next form (never into the
101
- * menu: with only the menu left it keeps its last drawn form and a `too-wide` note says so). Without it such a form is
102
- * only clamped to `cross.max`, as it always was.
103
- */
104
- readonly strictCross?: boolean;
105
- }
106
- /** The width of a stack nothing open holds, px. */
107
- declare const DEFAULT_RAIL = 30;
108
- /** The » menu entry's size along the stack, px. */
109
- declare const DEFAULT_MENU = 28;
110
- /** Whether a form sets the stack's cross size: its own say, else true for a panel's `open`. */
111
- declare const formSetsCross: (f: StackForm) => boolean;
112
- /** `input` with `item` inserted at index `at` (clamped to the items' range). */
113
- declare function withItem(input: StackInput, item: StackItem, at: number): StackInput;
114
- /** An item drawn: the form it took, its kind and its rect (stack-local px). One in the menu has the menu entry's rect. */
115
- interface PlacedStackItem {
116
- readonly id: string;
117
- /** Index into the item's `forms`. */
118
- readonly form: number;
119
- readonly kind: StackFormKind;
120
- readonly rect: Rect;
121
- }
122
- interface StackMenu {
123
- /** The » entry's rect. */
124
- readonly rect: Rect;
125
- /** The items in it, in the stack's order: exactly the items whose kind is `menu`. */
126
- readonly items: readonly string[];
127
- }
128
- /**
129
- * Why a stack looks as it does:
130
- * - `form-down`: an item took a smaller form than the one it started in (`from`, an index into its forms), by length
131
- * or by cross size.
132
- * - `to-menu`: an item is in the » menu.
133
- * - `too-wide`: an item's form doesn't set the cross size and its `cross.min` is over the stack's, or (with `strictCross`)
134
- * it does and its `cross.min` is over the limits' `max`. Cross size never puts an item in the menu, so it keeps its last drawn form
135
- * and the app clips it.
136
- * - `no-forms`: an item with no forms, left out of `items`.
137
- * - `overflow`: no item can give more way and the stack is still `over` px too long (forms that don't end in a `menu`
138
- * form can't give more; neither can a stack where going into the menu would only make it longer).
139
- */
140
- type StackNote = {
141
- readonly code: "form-down";
142
- readonly id: string;
143
- readonly from: number;
144
- readonly to: number;
145
- } | {
146
- readonly code: "to-menu";
147
- readonly id: string;
148
- } | {
149
- readonly code: "too-wide";
150
- readonly id: string;
151
- } | {
152
- readonly code: "no-forms";
153
- readonly id: string;
154
- } | {
155
- readonly code: "overflow";
156
- readonly over: number;
157
- };
158
- type StackNoteCode = StackNote["code"];
159
- interface StackFit {
160
- readonly axis: StackAxis;
161
- readonly length: number;
162
- /** The stack's size across: the widest `open` (clamped to the limits), or the rail. */
163
- readonly cross: number;
164
- /** One per input item that has forms, in order. */
165
- readonly items: readonly PlacedStackItem[];
166
- /** The » entry, or null while no item is in the menu. */
167
- readonly menu: StackMenu | null;
168
- /** `no-forms` first, then `form-down` per item in the order they gave way, `to-menu`, `too-wide`, and `overflow`. */
169
- readonly notes: readonly StackNote[];
170
- /**
171
- * The length the chosen forms need at least: their smallest sizes, the » entry, the gaps and the padding. Over `length`
172
- * only when the stack overflows. `fitStack`'s `previous` reads it to tell room coming back from a change of ages.
173
- */
174
- readonly need?: number;
175
- }
176
- /** What `fitStack` and `stackTargets` take besides the input. */
177
- interface FitOptions {
178
- /**
179
- * The fit the stack had before. While the forms it chose still fit, they are kept: a change of `used` ages alone (a press
180
- * on a header) reshapes nothing. Ages decide only who gives way anew (the length shrank, an item was added or opened),
181
- * and room that came back is used, but growing never re-ranks: the fresh fit is taken only if it is a pure gain (no
182
- * item's form is further down, one is further up) or the stack got wider across; otherwise room comes back in the
183
- * reverse of give-way order, and growth stops at the first item that can't grow: the item that gave way most recently
184
- * (highest rank, then `kept`, then the newest used, then the earlier in the stack) goes back to the nearest larger form
185
- * the stack fits with, even when that makes the stack shorter (the last item out of the menu takes the » entry with
186
- * it), and so on; when it fits no larger form, nothing behind it grows. Items in the menu still come out, alone or
187
- * together when only their leaving together fits, but only when that keeps the order: an item leaves only with every
188
- * menu item ahead of it, and only for a form no fewer steps down (from its `from`) than every item ahead of it that
189
- * isn't in the menu.
190
- * One px of room moves nothing. Results under `previous` depend on history: a shrink then a grow may end at another
191
- * arrangement than a fresh solve of the same input, and more room never undoes a growth along successive solves.
192
- * Growing back is meant for stacks of up to about 50 items (60 small menu items take about 9 ms; the cost grows with
193
- * about the cube of the count). Items it doesn't know start from their largest form; an item whose `from` went down
194
- * since (a panel opened), or whose form at the kept index is of another kind, starts over. A form that was only
195
- * re-measured keeps its place: smaller, it frees room that grows the kept forms; larger, it gives way from the kept
196
- * forms.
197
- *
198
- * Not covered: a lowered `cross.min` (or any change of the forms' cross sizes) doesn't bring a form back under
199
- * `previous`. After changing cross sizes, solve once without `previous`.
200
- */
201
- readonly previous?: StackFit;
202
- }
203
-
204
6
  /**
205
7
  * `fitStack(input, options?)`. With `options.previous` (the fit the stack had before) the forms it chose are kept while
206
8
  * they still fit: the solve starts from them instead of from every item's largest form, so a change of ages alone
@@ -238,7 +40,10 @@ declare function fitStack(input: StackInput, options?: FitOptions): StackFit;
238
40
  *
239
41
  * The dragged item counts as just used: it is newer than every item in the stack, so the others give way before it.
240
42
  * A group lands in the form that fits; a panel that would set a wider column makes room by that solve too. A dragged
241
- * item with no forms has no targets.
43
+ * item with no forms has no targets, nor has a `fixed` one (it is never dragged). A fixed item in the stack has no slot
44
+ * inside it: the gaps before and after it stay, but the hit of a gap ends where the fixed item starts and the next one
45
+ * begins where it ends, so no hit overlaps it. Nor has one the stack doesn't accept (`input.accepts`); `options.allows` leaves out
46
+ * single gaps.
242
47
  */
243
48
 
244
49
  interface StackTargetOptions {
@@ -252,6 +57,22 @@ interface StackTargetOptions {
252
57
  * they still fit, so it is the fit the drop makes when the app solves with the same `previous`.
253
58
  */
254
59
  readonly previous?: StackFit;
60
+ /**
61
+ * Whether a gap takes the dragged item (default: every gap does). Called with the dragged item and the gap's `at`
62
+ * (`place.at`: the gap before the k-th item of the input with the dragged one lifted out). A gap it refuses has no
63
+ * target; the others keep their ids, places and hits. The stack's own `accepts` is asked first, for the whole stack.
64
+ */
65
+ readonly allows?: (dragged: StackItem, at: number) => boolean;
66
+ /**
67
+ * Offer a gap only where the dragged item fits beside the others (default false: every gap is offered, the dragged item
68
+ * landing in the » menu or the stack overflowing if need be). With it a gap has no target when its fit puts the dragged
69
+ * item into the menu, has an `overflow` note, has a `too-wide` note that the stack without the dragged item didn't have,
70
+ * or squeezes a `fixed` item: it is in another form, shorter along the stack than its form's `main.min`, or narrower
71
+ * across than before the drop. A fixed item may shrink down to its `main.min` to make room, so the room for the others
72
+ * is the length less the fixed items' minimum sizes. The gaps left keep their ids, hits and fits. With no room anywhere
73
+ * the result is `[]`.
74
+ */
75
+ readonly onlyFits?: boolean;
255
76
  }
256
77
  type StackPlace = {
257
78
  readonly kind: "gap";
@@ -435,4 +256,4 @@ declare function storeFloats(floats: readonly StackFloat[]): StoredFloats;
435
256
  */
436
257
  declare function readFloats(data: unknown, known?: readonly string[]): FloatsRead;
437
258
 
438
- export { type CrossLimits, DEFAULT_MENU, DEFAULT_RAIL, type FitOptions, type FloatDrop, type FloatFit, type FloatTarget, type FloatsRead, type GroupFormKind, type MainSize, type PanelFormKind, type PlacedStackItem, type StackAxis, type StackFit, type StackFloat, type StackFloatTargetInput, type StackForm, type StackFormKind, type StackInput, type StackItem, type StackMenu, type StackNote, type StackNoteCode, type StackPlace, type StackRead, type StackState, type StackTarget, type StackTargetOptions, type StoredFloats, type StoredStack, createStack, fitFloat, fitStack, formSetsCross, readFloats, readStack, stackFloatTarget, stackTargets, storeFloats, storeStack, withItem };
259
+ export { FitOptions, type FloatDrop, type FloatFit, type FloatTarget, type FloatsRead, StackFit, type StackFloat, type StackFloatTargetInput, StackInput, StackItem, type StackPlace, type StackRead, type StackState, type StackTarget, type StackTargetOptions, type StoredFloats, type StoredStack, createStack, fitFloat, fitStack, readFloats, readStack, stackFloatTarget, stackTargets, storeFloats, storeStack };