@n-uf/placement 26.11.53 → 26.11.55

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. package/CHANGELOG.md +149 -1
  2. package/README.md +38 -58
  3. package/dist/{chunk-VLTYJHUA.js → chunk-2UVUFEBP.js} +4 -8
  4. package/dist/{chunk-VLTYJHUA.js.map → chunk-2UVUFEBP.js.map} +1 -1
  5. package/dist/{geometry-Bf37LbCT.d.ts → geometry-L5gCoiZV.d.ts} +2 -8
  6. package/dist/index.d.ts +64 -42
  7. package/dist/index.js +6 -66
  8. package/dist/index.js.map +1 -1
  9. package/dist/popup.d.ts +49 -0
  10. package/dist/popup.js +58 -0
  11. package/dist/popup.js.map +1 -0
  12. package/dist/stack.d.ts +611 -225
  13. package/dist/stack.js +843 -28
  14. package/dist/stack.js.map +1 -1
  15. package/dist/tiling.d.ts +239 -18
  16. package/dist/tiling.js +372 -19
  17. package/dist/tiling.js.map +1 -1
  18. package/package.json +9 -36
  19. package/dist/chunk-2GGJ4GVR.js +0 -9
  20. package/dist/chunk-2GGJ4GVR.js.map +0 -1
  21. package/dist/chunk-3ZICYLWL.js +0 -791
  22. package/dist/chunk-3ZICYLWL.js.map +0 -1
  23. package/dist/chunk-AE3BWTAE.js +0 -838
  24. package/dist/chunk-AE3BWTAE.js.map +0 -1
  25. package/dist/chunk-JVAR67OL.js +0 -172
  26. package/dist/chunk-JVAR67OL.js.map +0 -1
  27. package/dist/chunk-NF7RYK3U.js +0 -429
  28. package/dist/chunk-NF7RYK3U.js.map +0 -1
  29. package/dist/chunk-R3AAANRY.js +0 -220
  30. package/dist/chunk-R3AAANRY.js.map +0 -1
  31. package/dist/chunk-TWI644JK.js +0 -221
  32. package/dist/chunk-TWI644JK.js.map +0 -1
  33. package/dist/chunk-ZTH5FCUO.js +0 -4190
  34. package/dist/chunk-ZTH5FCUO.js.map +0 -1
  35. package/dist/constructions-Cbz7uEAZ.d.ts +0 -251
  36. package/dist/desk.d.ts +0 -51
  37. package/dist/desk.js +0 -111
  38. package/dist/desk.js.map +0 -1
  39. package/dist/dock.d.ts +0 -25
  40. package/dist/dock.js +0 -397
  41. package/dist/dock.js.map +0 -1
  42. package/dist/float-fit-DCYxRMru.d.ts +0 -37
  43. package/dist/lanes-DIwUqchd.d.ts +0 -1321
  44. package/dist/model-X7eUaKlA.d.ts +0 -337
  45. package/dist/panels.d.ts +0 -60
  46. package/dist/panels.js +0 -99
  47. package/dist/panels.js.map +0 -1
  48. package/dist/regions-Db_RyT4P.d.ts +0 -48
  49. package/dist/scene-cases.d.ts +0 -888
  50. package/dist/scene-cases.js +0 -3149
  51. package/dist/scene-cases.js.map +0 -1
  52. package/dist/scene.d.ts +0 -290
  53. package/dist/scene.js +0 -128
  54. package/dist/scene.js.map +0 -1
  55. package/dist/target-BBOCeez2.d.ts +0 -69
  56. package/dist/targets-C9ZVhmCl.d.ts +0 -621
  57. package/dist/targets.d.ts +0 -212
  58. package/dist/targets.js +0 -447
  59. package/dist/targets.js.map +0 -1
  60. package/dist/toolbar.d.ts +0 -167
  61. package/dist/toolbar.js +0 -55
  62. package/dist/toolbar.js.map +0 -1
package/CHANGELOG.md CHANGED
@@ -1,7 +1,155 @@
1
1
  # @n-uf/placement
2
2
 
3
3
  Versions are calendar versions, `YY.M.R` (year, month of the release, counter within the month), shared with
4
- `@n-uf/motion`: both packages carry the same version, and a release bumps both.
4
+ `@n-uf/motion` and `@n-uf/docking`: the packages carry the same version, and a release bumps them all.
5
+
6
+ Unreleased entries live in `changes/` until a release joins them.
7
+
8
+ ## 26.11.55
9
+
10
+ - `./tiling`, **added: canSplitPane, dropFits, paneRegion's paneCenter option, master clamps, Rect**, for a host with its own
11
+ projected layout. `canSplitPane(target, side, { min, gap?, handle? })` is the room rule (along the split `2 * min`
12
+ plus the gutter, across it `min`, for the rect of a pane) and `dropFits(projected, dragged, at, area, { min, side })`
13
+ the fit rule (both panes at least `min` in a layout the host already projected) (`SplitRoomOptions`,
14
+ `DropFitsOptions`); `canDropOnPane` is now exactly the two in turn, with the same verdicts and reasons.
15
+ `paneRegion` takes a center the host measured as `options.paneCenter` (a `PaneCenter`), the same region for the same
16
+ center. `masterRatio` and `masterCount`, the clamps `masterStack` applies, and the `Rect` type (the root's) are
17
+ exported.
18
+ - `./tiling`, **behavior change: the gap rule**. A split of extent `W` at ratio `r` with a gutter `g` now puts the
19
+ middle of the gutter at `W * r`: the first side is `max(0, W * r - g / 2)` long, the second starts at
20
+ `start + W * r + g / 2` and is `max(0, W * (1 - r) - g / 2)` long. It replaces `(W - g) * r`. At ratio 0.5 both rules
21
+ agree (to the last bits), at any other ratio a split with a gap lays out differently. The promise that the second
22
+ side never starts past the rect's end goes: no size is ever negative, and a split with no room may start its second
23
+ side up to half a gutter past the end. Order layouts (`columns`, `grid`) keep their rule.
24
+ - `./tiling`, **fixed: a ratio or gap that is not finite**. A NaN or infinite `ratio` gave NaN rects; it is now 0.5.
25
+ A NaN `gap` did too; `layoutSplit` now treats a negative or non-finite `gap` (and `handle`) as 0.
26
+ - `./tiling`, **`masterStack` count and side**: `count` (rounded, within 1 to n, default 1) and `side` (`"left"` by
27
+ default, `"right"`, `"top"`, `"bottom"`). Left and right make the areas columns of stacked panes, top and bottom
28
+ rows of panes side by side, right and bottom put the stack first in space, and with no stack the panes fill the area
29
+ along the side's cross axis. Its `ratio` is now clamped to 0.05..0.95 (not finite: 0.5), and a negative or non-finite
30
+ `gap` is 0. With the defaults the rects are the earlier ones, to the last bits of the stack's width. The two live in
31
+ `MasterOptions`; the order layouts and `orderTargets` take `OrderOptions` (`TileOptions` and `MasterOptions`), and a
32
+ split tree's options do not accept them.
33
+ - `./tiling`, **gutters, split ids and `layoutSplitTree`**: `TileOptions.handle` (px, default 0) is the extra room a
34
+ split's divider takes beside the gap, so a split's gutter is its gap plus the handle. A split may carry its own
35
+ `gap` (the handle stays global) and an `id`. `layoutSplitTree(tree, area, options)` gives `{ panes, splits }`, and for
36
+ each split with an `id` its `rect`, `axis`, `ratio` in effect and `divider` (`SplitLayout`, `SplitGeometry`);
37
+ `layoutSplit` is its `panes`.
38
+ - `./tiling`, **master splits**: a split with `master: { count?, side? }` lays its subtree out flat, its panes in
39
+ order through `masterStack` by its ratio and gap (never the handle). The splits under it are not laid out or
40
+ reported.
41
+ - `./tiling`, **floors and fixed lengths**: the layout options `floor(child, axis, split)` (`{ min, net? }`, the least
42
+ length along the split; the ratio is clamped to keep it within 0.05..0.95 unless a side says `net: false`, and is
43
+ 0.5 where both floors cannot fit), `fixed(child, axis)` (`{ length, keep? }`, a length along the split: the first
44
+ that fits takes it and the other side fills the rest; with `keep` on both, each keeps its own) and
45
+ `fixedAcross(child, axis)` (a length across the split) (`SplitOptions`, `MinLength`, `FixedLength`). With none of
46
+ them a layout is as before.
47
+ - `./tiling`, **`canDropOnPane(tree, dragged, at, region, area, options)`**: `{ ok, reason? }` whether a drop leaves
48
+ room: a side needs `2 * min` plus the gutter along the split and `min` across, in the layout without the dragged
49
+ pane, and both panes at least `min` wide and high in the layout the drop makes (`DropOptions`, `DropVerdict`).
50
+ - `./tiling`, **`neighbor(rects, from, direction)`**: the nearest pane in a direction from a map of rects, by the
51
+ distance between centers (a candidate's center strictly on that side; the lowest score wins, ties to the first)
52
+ (`Direction`).
53
+ - `./stack`, **asked lengths and dividers**: `StackItem.lengths` (`{ column?, row? }`, px along the stack, per axis) is read
54
+ in place of the `main.natural` of a growing form, the least staying its `main.min`, and `dividers(input, fit)`,
55
+ `resizeBetween`, `resetBetween` and `resetLengths` trade length between the nearest open growing items (a collapsed
56
+ item between two open ones gives one divider, on its far edge; `StackDivider`, `StackLengths`). Additive: a stack that
57
+ declares no length is laid out exactly as before.
58
+ - `./stack`, **a divider drag writes the pair's lengths only, in ask units**: `resizeBetween` writes `lengths` for the
59
+ two items of the dragged pair and for no other item, so a bystander moved to another stack is laid out as an item nobody
60
+ resized. A length in `lengths` is in ask units, not drawn px; with room to spare a drawn size is the ask times the shared scale, or
61
+ its least when that is more, so the pair's ask is its drawn size over that scale (short of room,
62
+ `least + (drawn - least) / share`), which leaves the scale and every other drawn size as they were. A collapsed item no
63
+ longer gets a length from a drag of its neighbors: reopened, it keeps its proportion unless an end of the pair is held
64
+ at its least (its ask under the least and its share of the column too); then it gives up that end's excess in
65
+ proportion. An item nobody sized asks its natural, so when that changes it re-shares the column with the sized ones,
66
+ which keep their proportion to one another, not their px. `resetBetween` writes the pair only, too. An end dragged to its
67
+ least asks `least / scale`, under its least, and is still drawn at it.
68
+ - `./stack`, **behavior change: a length under its least now reads as a weight with room**. The least is a floor on the
69
+ drawn size, not on the ask: with room to spare, an item whose share of the length (its ask times the scale) would be
70
+ under its least is drawn at its least and the others share the rest in proportion to their asks. Before, a length under
71
+ the least was read as the least. Short of room an ask under the least still reads as the least. A length of 0 (or under
72
+ `EPS`) is no length: the item asks its natural, so an item a stored state holds at 0 (dragged fully shut when its least
73
+ is 0) opens at its natural when that state is read again. A stack that declares no length, or none under its least, is laid out
74
+ exactly as before.
75
+ - Docs only: **the design page names the three places the solver reads a form's `kind`** (`menu`, the group kinds for
76
+ `ownCross`, and kind equality under `previous`), says the root's `Target` carries the docking model's drag fields as
77
+ plain data, and says `fitFloat` finds a clear place unless its search is capped (`FloatFit.searchCapped`). No
78
+ behavior, type or export change.
79
+
80
+ ## 26.11.54
81
+
82
+ Breaking. Placement is the general layer: one edge, one area, one popup. The window's docking model leaves for its own
83
+ package, `@n-uf/docking`, and the replaced entries and deprecated parts go. Behavior is unchanged: every layout, target
84
+ and lane is the same for the same input.
85
+
86
+ Host notes: a host that imports `@n-uf/placement/scene` or `/scene/cases` moves to `@n-uf/docking` and
87
+ `@n-uf/docking/testing` with the renames in docking's CHANGELOG; one that imported a replaced entry moves to
88
+ `@n-uf/docking` or `./tiling`; one that imported `positionPopup` from the root imports it from `./popup`.
89
+
90
+ Added:
91
+ - `./stack`, **`cutEdges(stage, bands)`**: the stage cut into bands along its sides in list order (`EdgeBand`,
92
+ `EdgeCut`, `BandSide`); the order decides the corners, a `reserve` band shortens the leftover and an `over` band lies
93
+ over it (cut after every reserved band, so inside the final leftover, wherever it is listed). Band ids are unique (a
94
+ repeat throws), and a stage width or height that is negative or not finite is cut as 0.
95
+ - `./stack`, **form flags** `StackForm.body`, `.folded` and `.compact`, with `formBody`, `formFolded` and
96
+ `formCompact`: what an open panel, a folded form and an icons form stand for, each defaulting from the kind (`open`;
97
+ `header` and `fold`; `icons`). `formSetsCross` defaults to `formBody`. Nothing changes for a form that sets none.
98
+ - `./stack`, **`stackGaps(input, item, { previous?, allows? })`**: one edge's drop places, fit only: each gap with the
99
+ stack after the drop, its fit and the item's slot, or a refusal with its reason (`StackGap`, `StackGapOptions`,
100
+ `StackGapRefusal`).
101
+ - **`@n-uf/placement/popup`**: the popup positioner's own entry.
102
+ - `./stack`, **`controlLadder(spec)`** and **`StackForm.tiers`**: a group's forms generated from its controls, below.
103
+
104
+ Moved (one-line migration each):
105
+ - `@n-uf/placement/scene` → `@n-uf/docking`; `@n-uf/placement/scene/cases` → `@n-uf/docking/testing`. Install
106
+ `@n-uf/docking` and change the import; the names it renames are listed in docking's CHANGELOG.
107
+ - `positionPopup`, `PositionerRule`, `Positioned`, `Align`, `BELOW_LEFT`: root → `@n-uf/placement/popup`. Change the
108
+ import path.
109
+ - `fitFloat`, `FloatFit`: `./scene` → `./stack` (their one home). Import from `@n-uf/placement/stack`.
110
+ - `COLUMN_REACH`, `RAIL_EDGE`: out of the root into the docking model, unexported. Use your own constant if you drew
111
+ with them.
112
+
113
+ Renamed:
114
+ - `centre` → `center` (root). Rename the call.
115
+
116
+ Removed (one-line migration each):
117
+ - `./dock`, `./toolbar`, `./targets`, `./panels`, `./desk`, every export of each: use `@n-uf/docking` for docks,
118
+ toolbars and panels, `./tiling` for panes (`paneZone` → `paneRegion`, `paneCentre` → `paneCenter`, `PaneZone` →
119
+ `PaneRegion`, `PaneCentre` → `PaneCenter`, `PaneZoneOptions` → `PaneRegionOptions`, `PANE_EDGES` → `PANE_SIDES`,
120
+ `PANE_ZONE_DEFAULTS` → `PANE_REGION_DEFAULTS`), and the root for `Target`.
121
+ - `./stack`: `stackTargets`, `StackTarget`, `StackPlace`, `StackTargetOptions` → `stackGaps` (fit only; hit zones are the
122
+ host's), or `@n-uf/docking`'s `targets` for a window.
123
+ - `./stack`: `createStack`, `storeStack`, `readStack`, `StackState`, `StoredStack`, `StackRead` → `@n-uf/docking`'s
124
+ `storeDockState` / `readDockState`.
125
+ - `./stack`: `stackFloatTarget`, `StackFloatTargetInput`, `FloatTarget`, `FloatDrop`, `storeFloats`, `readFloats`,
126
+ `StoredFloats`, `FloatsRead`, `StackFloat` → `@n-uf/docking`'s float target (`float:<id>`) and stored form;
127
+ `fitFloat` stays.
128
+ - The `@n-uf/motion` development dependency: placement's tests no longer use it.
129
+
130
+ The control ladder, in full (additive, listed under Added above):
131
+
132
+ - `./stack`, **`controlLadder(spec)`: a group's forms generated from its controls** (additive). A host declares a group
133
+ by its controls (`{ id, tiers, foldOrder? }`, the lengths per tier longest first, plus `gap`, `grip`, `more` (the
134
+ group's own » cell) and `cross`), and gets the ordered `StackForm[]` with `rank` and `hides` set: the tier steps one
135
+ control at a time in fold order (rank `100 * t + i / n` for tiers 1 and 2; every later tier shares the band from 300
136
+ in tier order, so tier steps stay under 400 for any tier count), the partial folds at the last tier that hide the
137
+ first `k` controls in fold order (rank `400 + k / n`, so the group with the fewest hidden controls folds next), then
138
+ `fold` (`hides` every control, rank 500) and `menu` (600). The bands are fixed, so groups of different tier counts
139
+ keep the order across a bar. A bar of such groups runs short control by control: every group's
140
+ tier steps, then every partial fold, then folds, and a growing fixed title gives way only after every group's `row`
141
+ steps. There is no new solver rule: `fitStack` takes the lowest-ranked next form, passes over a form that doesn't
142
+ shorten the stack, and grows back in the exact reverse. The shape is fixed (`n * T + 2` forms for `n` controls and
143
+ `T` tiers; a form no shorter than the one before is still emitted), so form indexes in `previous` stay valid when a
144
+ length changes; when the control set changes, solve the group without `previous`. `keep` lifts a pinned primary's
145
+ last forms; `column: { icons }` adds the group's column forms. The result is `{ row, column? }`, assignable to
146
+ `@n-uf/docking`'s `DockItem.forms`. Hosts that hand-write forms are unchanged.
147
+ - `./stack`, **`StackForm.tiers`: each shown control's tier** (additive, part of `controlLadder`). `controlLadder` sets
148
+ `tiers` (control id to tier index, 0 the longest) on every row form it generates, for the controls the form shows,
149
+ always a valid index into the control's own `tiers` (a control with fewer tiers than its group stays on its last);
150
+ `fold` and `menu` leave it out, and so does every hand-written form. `@n-uf/docking` reports the chosen form's
151
+ `tiers` on the item's layout (`DockItemLayout.tiers`) beside `hidden`, so a host draws each control at `tiers[id]`
152
+ and leaves out `hidden` without knowing the ladder's order.
5
153
 
6
154
  ## 26.11.53
7
155
 
package/README.md CHANGED
@@ -3,11 +3,13 @@
3
3
  > [!CAUTION]
4
4
  > ## Not yet stable
5
5
  >
6
- > **@n-uf/placement is young and still changing. Its API (the scene and its solver, the drop targets and lanes, and tiling) is not final.**
6
+ > **@n-uf/placement is young and still changing. Its API (the edge cut and fit, the form vocabulary, one edge's drop places, tiling and the popup positioner) is not final.**
7
7
  >
8
8
  > Version numbers are dates (YY.M.R), not semantic versions, so any release may break things. Pin an exact version and read the [CHANGELOG](https://github.com/n-uf/motion/blob/main/packages/placement/CHANGELOG.md) before you upgrade.
9
9
 
10
- Where things go. A window's edges (bars, rails and columns), items and floats are solved into a layout, and every drag gets its drop targets, refusals and lanes, each target carrying the layout a release there makes, so the preview is the result. State in, rects and drop targets out: pure functions over plain data, with no DOM, no framework, no motion and no dependencies. Rendering stays in the app: it draws the rects, measures its items and feeds pointer samples to a drag intent.
10
+ Where things fit. The stage cut into bands along its sides, the items along one band fitted with their forms (an open panel folds to a header, then a rail icon, then the » menu, and comes back in exact reverse), one band's drop places with the fit each drop makes, floats kept clear of what is docked, panes tiled and popups positioned. Geometry in, rects out: pure functions over plain data, with no DOM, no framework, no motion and no dependencies.
11
+
12
+ A whole window's docking model (edges, rails, floats, drop targets, lanes and a stored form) is built on this layer in [`@n-uf/docking`](https://www.npmjs.com/package/@n-uf/docking).
11
13
 
12
14
  ```sh
13
15
  npm i @n-uf/placement
@@ -17,62 +19,29 @@ npm i @n-uf/placement
17
19
 
18
20
  | Entry | What it gives |
19
21
  |---|---|
20
- | `@n-uf/placement/scene` | **The main entry.** One model of a whole window: `solve` for every rect, `targets` and `refusals` for every drag, `lanes` for a landing model, pure changes (`moveTo`, `fold`, `floatAt`, ...) and a stored form (`storeScene`, `readScene`). |
21
- | `@n-uf/placement/stack` | A building block: the solver of one edge (`fitStack`) and the form vocabulary every item declares its forms in (`StackForm`). `./scene` lays out each of its edges with it. |
22
- | `@n-uf/placement/scene/cases` | A building block: conformance rows (`CASES`, `LANDING_CASES`) and runners (`runCase`, `createSceneHost`) that a host's test suite plays against `./scene`. |
23
- | `@n-uf/placement/tiling` | A building block: panes that divide an area. Order layouts (`masterStack`, `columns`, `grid`), the split tree (`layoutSplit`, `dropOnPane`) and their drop targets. |
24
- | `@n-uf/placement` | The shared shapes (`Rect`, `Size`, `Point`), the geometry, the `Target` shape and the popup positioner (`positionPopup`). |
25
-
26
- `./dock`, `./toolbar`, `./targets`, `./panels` and `./desk` are older entries, replaced by `./scene` and `./tiling`, to be removed.
22
+ | `@n-uf/placement/stack` | One edge: the cut of the stage into bands (`cutEdges`), the fit of its items (`fitStack`) in the form vocabulary every item declares its forms in (`StackForm`, with the flags `body`, `folded`, `compact`), its drop places (`stackGaps`) and the float fit (`fitFloat`). |
23
+ | `@n-uf/placement/tiling` | Panes that divide an area. Order layouts (`masterStack`, `columns`, `grid`), the split tree (`layoutSplit`, `layoutSplitTree`, with gaps, handles, floors and fixed lengths, `dropOnPane`, `canDropOnPane`), `neighbor` and the drop targets. |
24
+ | `@n-uf/placement/popup` | A popup positioned as Wayland's xdg-positioner does (`positionPopup`). |
25
+ | `@n-uf/placement` | The shared shapes (`Rect`, `Size`, `Point`), the geometry and the `Target` shape. |
27
26
 
28
- ## A window
27
+ ## One edge
29
28
 
30
- A scene is the stage, its edges, the items with their forms, the floats and the chrome they keep clear of. `solve` gives every rect to draw; `targets` gives every drop target for one item, and a drop's `after()` is the scene to store and the layout to draw.
29
+ `fitStack` picks one form per item for the length it gets; `stackGaps` gives every gap where a dragged item fits, each with the fit its drop makes, and the reason where it doesn't.
31
30
 
32
31
  ```ts
33
- import { readScene, solve, storeScene, targets, type Scene, type SceneItem } from "@n-uf/placement/scene";
34
- import type { StackForm } from "@n-uf/placement/stack";
35
-
36
- const f = (kind: StackForm["kind"], min: number, natural: number, cross: number, more: Partial<StackForm> = {}): StackForm => ({ kind, main: { min, natural }, cross: { natural: cross }, ...more });
37
- const panel = (id: string, used: number): SceneItem => ({
38
- id, kind: "panel", used,
39
- forms: { column: [f("open", 120, 240, 260, { main: { min: 120, natural: 240, grows: true }, cross: { natural: 260, min: 180 } }), f("header", 28, 28, 260, { cross: { natural: 260, min: 60 } }), f("rail", 28, 28, 30), f("menu", 0, 0, 0)] },
40
- });
41
- const group = (id: string, used: number, align?: "end"): SceneItem => ({
42
- id, kind: "group", used, ...(align ? { align } : {}),
43
- forms: { row: [f("row", 180, 200, 28), f("icons", 84, 84, 28), f("menu", 0, 0, 0)], column: [f("stacked", 96, 96, 84), f("icons", 84, 84, 28), f("menu", 0, 0, 0)] },
44
- });
45
- const fixed = (id: string, kind: string, form: StackForm, align?: "center" | "end"): SceneItem => ({ id, kind, used: 0, fixed: true, forms: { row: [form] }, ...(align ? { align } : {}) });
46
- const bar = { accepts: ["group"], cross: { min: 36, max: 36, rail: 36 }, gap: 4, pad: { start: 8, end: 8 } };
47
- const column = { accepts: ["panel", "group"], cross: { min: 160, max: 480, rail: 30 } };
48
- const items = [
49
- fixed("title", "title", f("row", 80, 160, 32, { main: { min: 80, natural: 160, grows: true } })),
50
- fixed("controls", "controls", f("row", 84, 84, 32), "end"),
51
- fixed("readout", "readout", f("row", 72, 72, 28), "center"),
52
- panel("pages", 1), panel("findings", 2), panel("notes", 3),
53
- group("views", 4), group("tools", 5), group("zoom", 6, "end"), group("search", 7, "end"), group("marks", 8),
54
- ];
55
- const scene: Scene = {
56
- stage: { x: 0, y: 0, width: 1200, height: 800 },
57
- edges: [
58
- { id: "titlebar", side: "top", ring: 0, accepts: ["group"], items: ["title", "controls"], cross: { min: 32, max: 32, rail: 32 } },
59
- { id: "toolbar", side: "top", ring: 1, items: ["views", "tools", "zoom"], ...bar },
60
- { id: "status", side: "bottom", ring: 0, span: "between", items: ["readout", "search"], ...bar, cross: { min: 28, max: 28, rail: 28 } },
61
- { id: "left", side: "left", ring: 0, items: ["pages"], ...column },
62
- { id: "right", side: "right", ring: 0, items: ["findings", "marks"], ...column },
63
- ],
64
- items: Object.fromEntries(items.map((it) => [it.id, it])),
65
- floats: [{ id: "notes", rect: { x: 500, y: 200, width: 280, height: 320 } }],
66
- floatKinds: ["panel", "group"],
67
- };
68
- const layout = solve(scene);
69
- console.log(layout.content); // { x: 260, y: 68, width: 680, height: 704 }
70
- console.log(layout.items.title!.rect.width, layout.items.controls!.rect.x, layout.items.marks!.rect.width); // 1116 1116 84
71
- const drops = targets(scene, "views", { previous: layout });
72
- console.log(drops.filter((t) => t.id.startsWith("gap:status")).map((t) => t.id)); // [ 'gap:status:start:0' ]
73
- const drop = drops.find((t) => t.id === "gap:right:start:2")!.after({ x: 0, y: 0 });
74
- console.log(JSON.stringify(solve(drop.scene, { previous: layout })) === JSON.stringify(drop.layout)); // true
75
- console.log(readScene(JSON.parse(JSON.stringify(storeScene(drop.scene))), scene).dropped); // []
32
+ import { fitStack, stackGaps, type StackForm, type StackItem } from "@n-uf/placement/stack";
33
+
34
+ const form = (kind: StackForm["kind"], min: number, natural: number, cross: number): StackForm => ({ kind, main: { min, natural }, cross: { natural: cross } });
35
+ const group = (id: string, used: number): StackItem => ({ id, used, forms: [form("row", 100, 100, 26), form("fold", 36, 36, 26), form("menu", 0, 0, 0)] });
36
+ const title: StackItem = { id: "title", used: 0, fixed: true, forms: [{ kind: "row", main: { min: 80, natural: 160, grows: true }, cross: { natural: 26 } }] };
37
+ const controls: StackItem = { id: "controls", used: 0, fixed: true, forms: [form("row", 72, 72, 26)] };
38
+ const bar = { axis: "row", length: 400, cross: { min: 36, max: 40 }, items: [title, group("views", 1), group("tools", 2), controls] } as const;
39
+
40
+ console.log(fitStack(bar).items.map((p) => [p.id, p.kind, p.rect.width]));
41
+ // [ [ 'title', 'row', 128 ], [ 'views', 'row', 100 ], [ 'tools', 'row', 100 ], [ 'controls', 'row', 72 ] ] (the title grows into the spare room)
42
+ const gaps = stackGaps(bar, group("marks", 4));
43
+ console.log(gaps.map((g) => (g.fits ? [g.at, g.slot.x] : [g.at, g.reason])));
44
+ // [ [ 0, 0 ], [ 1, 92 ], [ 2, 128 ], [ 3, 228 ], [ 4, 300 ] ] (the title gives back what it grew into; Views folds)
76
45
  ```
77
46
 
78
47
  ## Panes
@@ -89,14 +58,25 @@ console.log(layoutSplit(after, area).get("c")); // { x: 400, y: 0, width: 400, h
89
58
  console.log(paneTargets(layoutSplit(tree, area)).map((t) => t.id)); // [ 'pane:a', 'pane:b' ]
90
59
  ```
91
60
 
61
+ A split puts the middle of its gutter (its gap plus its handle) at its ratio. `layoutSplitTree` also reports the box, ratio and divider of each split that has an `id`. The `floor`, `fixed` and `fixedAcross` options read a host's minimums and fixed lengths, `canDropOnPane` says whether a drop leaves room, and `neighbor` finds the nearest pane in a direction.
62
+
63
+ ```ts
64
+ import { layoutSplitTree } from "@n-uf/placement/tiling";
65
+
66
+ const split = { id: "main", a: { pane: "a" }, b: { pane: "b" }, axis: "x" as const, ratio: 0.3 };
67
+ const { panes, splits } = layoutSplitTree(split, { x: 0, y: 0, width: 1000, height: 600 }, { gap: 6, handle: 4 });
68
+ console.log(panes.get("a")?.width, panes.get("b")?.x); // 295 305
69
+ console.log(splits.get("main")?.divider); // { x: 295, y: 0, width: 10, height: 600 }
70
+ ```
71
+
92
72
  ## Documentation
93
73
 
94
- - [Design page](https://github.com/n-uf/motion/blob/main/docs/placement.md): the concept, the parts, the rules a consumer relies on, and the SDK entry by entry.
95
- - [Reference](https://github.com/n-uf/motion/blob/main/docs/placement-reference.md): every entry point's rules, ids, options and longer examples.
96
- - [CHANGELOG](https://github.com/n-uf/motion/blob/main/packages/placement/CHANGELOG.md)
74
+ - [Design page](https://github.com/n-uf/motion/blob/main/docs/placement.md): the concept, the rules a consumer relies on, and the SDK entry by entry.
75
+ - [Reference](https://github.com/n-uf/motion/blob/main/docs/placement-reference.md): every entry point's rules, options and longer examples.
76
+ - [CHANGELOG](https://github.com/n-uf/motion/blob/main/packages/placement/CHANGELOG.md): what changed, and where the window model went.
97
77
  - Site and live demos: [motion.n-uf.com](https://motion.n-uf.com)
98
78
 
99
- Its sibling [`@n-uf/motion`](https://www.npmjs.com/package/@n-uf/motion) owns how things move.
79
+ Its siblings: [`@n-uf/docking`](https://www.npmjs.com/package/@n-uf/docking) is the window's docking model built on it, [`@n-uf/motion`](https://www.npmjs.com/package/@n-uf/motion) owns how things move.
100
80
 
101
81
  ## License
102
82
 
@@ -6,7 +6,7 @@ var clampInto = (r, area2) => ({
6
6
  x: Math.min(Math.max(r.x, area2.x), Math.max(area2.x, area2.x + area2.width - r.width)),
7
7
  y: Math.min(Math.max(r.y, area2.y), Math.max(area2.y, area2.y + area2.height - r.height))
8
8
  });
9
- var centre = (r) => ({ x: r.x + r.width / 2, y: r.y + r.height / 2 });
9
+ var center = (r) => ({ x: r.x + r.width / 2, y: r.y + r.height / 2 });
10
10
  var EPS = 1e-6;
11
11
  var PLANE = rect(-1e9, -1e9, 2e9, 2e9);
12
12
  var area = (r) => Math.max(0, r.width) * Math.max(0, r.height);
@@ -26,22 +26,18 @@ function subtract(r, cut) {
26
26
  rect(x0, Math.max(r.y, cut.y + cut.height), x1 - x0, bottom - Math.max(r.y, cut.y + cut.height))
27
27
  ].filter((p) => area(p) > EPS);
28
28
  }
29
- var COLUMN_REACH = 22;
30
- var RAIL_EDGE = 10;
31
29
 
32
30
  export {
33
31
  rect,
34
32
  overlap,
35
33
  clampInto,
36
- centre,
34
+ center,
37
35
  EPS,
38
36
  PLANE,
39
37
  area,
40
38
  overlaps,
41
39
  contains,
42
40
  clamp,
43
- subtract,
44
- COLUMN_REACH,
45
- RAIL_EDGE
41
+ subtract
46
42
  };
47
- //# sourceMappingURL=chunk-VLTYJHUA.js.map
43
+ //# sourceMappingURL=chunk-2UVUFEBP.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/geometry.ts"],"sourcesContent":["/**\n * The shapes every entry shares. Plain data: a rect is a top-left corner and a size, in whatever px the consumer\n * lays out in (stage, window or host coordinates). The same shape as @n-uf/motion's, so the two compose without\n * either importing the other.\n */\n\nexport interface Rect {\n x: number;\n y: number;\n width: number;\n height: number;\n}\n\nexport interface Size {\n readonly width: number;\n readonly height: number;\n}\n\nexport interface Point {\n readonly x: number;\n readonly y: number;\n}\n\nexport const rect = (x: number, y: number, width: number, height: number): Rect => ({ x, y, width, height });\n\n/** The area two rects share (0 when apart). */\nexport const overlap = (a: Rect, b: Rect): number =>\n Math.max(0, Math.min(a.x + a.width, b.x + b.width) - Math.max(a.x, b.x)) * Math.max(0, Math.min(a.y + a.height, b.y + b.height) - Math.max(a.y, b.y));\n\n/** `r` moved (not resized) to lie inside `area`; one larger than the area keeps its top-left corner on the area's. */\nexport const clampInto = (r: Rect, area: Rect): Rect => ({\n ...r,\n x: Math.min(Math.max(r.x, area.x), Math.max(area.x, area.x + area.width - r.width)),\n y: Math.min(Math.max(r.y, area.y), Math.max(area.y, area.y + area.height - r.height)),\n});\n\n/** The center of a rect. */\nexport const centre = (r: Rect): Point => ({ x: r.x + r.width / 2, y: r.y + r.height / 2 });\n\n/** The tolerance the geometry compares with, px. */\nexport const EPS = 1e-6;\n\n/** A rect that covers any point a page can see (a float target's hit). */\nexport const PLANE: Rect = rect(-1e9, -1e9, 2e9, 2e9);\n\n/** A rect's area (a negative side counts as 0). */\nexport const area = (r: Rect): number => Math.max(0, r.width) * Math.max(0, r.height);\n\n/** Whether two rects share more than `eps` each way (touching edges don't overlap). */\nexport const overlaps = (a: Rect, b: Rect, eps = EPS): boolean =>\n Math.min(a.x + a.width, b.x + b.width) - Math.max(a.x, b.x) > eps && Math.min(a.y + a.height, b.y + b.height) - Math.max(a.y, b.y) > eps;\n\n/** Whether `p` lies in `r`, its edges included (within `eps`). */\nexport const contains = (r: Rect, p: Point, eps = EPS): boolean => p.x >= r.x - eps && p.x <= r.x + r.width + eps && p.y >= r.y - eps && p.y <= r.y + r.height + eps;\n\n/** `v` within `lo..hi` (`lo` wins when `hi` is under it). */\nexport const clamp = (v: number, lo: number, hi: number): number => Math.min(Math.max(v, lo), Math.max(lo, hi));\n\n/** `r` less `cut`, as disjoint rects: the parts beside the cut whole, then above and below it within its width. */\nexport function subtract(r: Rect, cut: Rect): Rect[] {\n if (!overlaps(r, cut)) return [r];\n const right = r.x + r.width;\n const bottom = r.y + r.height;\n const x0 = Math.max(r.x, cut.x);\n const x1 = Math.min(right, cut.x + cut.width);\n return [\n rect(r.x, r.y, x0 - r.x, r.height),\n rect(x1, r.y, right - x1, r.height),\n rect(x0, r.y, x1 - x0, Math.min(bottom, cut.y) - r.y),\n rect(x0, Math.max(r.y, cut.y + cut.height), x1 - x0, bottom - Math.max(r.y, cut.y + cut.height)),\n ].filter((p) => area(p) > EPS);\n}\n\n/**\n * Hit sizes the targets share: how far a column line's hit reaches on each side of the line, and how deep a side takes\n * a rail drop while it shows no rail, px.\n */\nexport const COLUMN_REACH = 22;\nexport const RAIL_EDGE = 10;\n"],"mappings":";AAuBO,IAAM,OAAO,CAAC,GAAW,GAAW,OAAe,YAA0B,EAAE,GAAG,GAAG,OAAO,OAAO;AAGnG,IAAM,UAAU,CAAC,GAAS,MAC/B,KAAK,IAAI,GAAG,KAAK,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,IAAI,KAAK,IAAI,EAAE,GAAG,EAAE,CAAC,CAAC,IAAI,KAAK,IAAI,GAAG,KAAK,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,IAAI,KAAK,IAAI,EAAE,GAAG,EAAE,CAAC,CAAC;AAG/I,IAAM,YAAY,CAAC,GAASA,WAAsB;AAAA,EACvD,GAAG;AAAA,EACH,GAAG,KAAK,IAAI,KAAK,IAAI,EAAE,GAAGA,MAAK,CAAC,GAAG,KAAK,IAAIA,MAAK,GAAGA,MAAK,IAAIA,MAAK,QAAQ,EAAE,KAAK,CAAC;AAAA,EAClF,GAAG,KAAK,IAAI,KAAK,IAAI,EAAE,GAAGA,MAAK,CAAC,GAAG,KAAK,IAAIA,MAAK,GAAGA,MAAK,IAAIA,MAAK,SAAS,EAAE,MAAM,CAAC;AACtF;AAGO,IAAM,SAAS,CAAC,OAAoB,EAAE,GAAG,EAAE,IAAI,EAAE,QAAQ,GAAG,GAAG,EAAE,IAAI,EAAE,SAAS,EAAE;AAGlF,IAAM,MAAM;AAGZ,IAAM,QAAc,KAAK,MAAM,MAAM,KAAK,GAAG;AAG7C,IAAM,OAAO,CAAC,MAAoB,KAAK,IAAI,GAAG,EAAE,KAAK,IAAI,KAAK,IAAI,GAAG,EAAE,MAAM;AAG7E,IAAM,WAAW,CAAC,GAAS,GAAS,MAAM,QAC/C,KAAK,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,IAAI,KAAK,IAAI,EAAE,GAAG,EAAE,CAAC,IAAI,OAAO,KAAK,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,IAAI,KAAK,IAAI,EAAE,GAAG,EAAE,CAAC,IAAI;AAGhI,IAAM,WAAW,CAAC,GAAS,GAAU,MAAM,QAAiB,EAAE,KAAK,EAAE,IAAI,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,OAAO,EAAE,KAAK,EAAE,IAAI,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,SAAS;AAG1J,IAAM,QAAQ,CAAC,GAAW,IAAY,OAAuB,KAAK,IAAI,KAAK,IAAI,GAAG,EAAE,GAAG,KAAK,IAAI,IAAI,EAAE,CAAC;AAGvG,SAAS,SAAS,GAAS,KAAmB;AACnD,MAAI,CAAC,SAAS,GAAG,GAAG,EAAG,QAAO,CAAC,CAAC;AAChC,QAAM,QAAQ,EAAE,IAAI,EAAE;AACtB,QAAM,SAAS,EAAE,IAAI,EAAE;AACvB,QAAM,KAAK,KAAK,IAAI,EAAE,GAAG,IAAI,CAAC;AAC9B,QAAM,KAAK,KAAK,IAAI,OAAO,IAAI,IAAI,IAAI,KAAK;AAC5C,SAAO;AAAA,IACL,KAAK,EAAE,GAAG,EAAE,GAAG,KAAK,EAAE,GAAG,EAAE,MAAM;AAAA,IACjC,KAAK,IAAI,EAAE,GAAG,QAAQ,IAAI,EAAE,MAAM;AAAA,IAClC,KAAK,IAAI,EAAE,GAAG,KAAK,IAAI,KAAK,IAAI,QAAQ,IAAI,CAAC,IAAI,EAAE,CAAC;AAAA,IACpD,KAAK,IAAI,KAAK,IAAI,EAAE,GAAG,IAAI,IAAI,IAAI,MAAM,GAAG,KAAK,IAAI,SAAS,KAAK,IAAI,EAAE,GAAG,IAAI,IAAI,IAAI,MAAM,CAAC;AAAA,EACjG,EAAE,OAAO,CAAC,MAAM,KAAK,CAAC,IAAI,GAAG;AAC/B;AAMO,IAAM,eAAe;AACrB,IAAM,YAAY;","names":["area"]}
1
+ {"version":3,"sources":["../src/geometry.ts"],"sourcesContent":["/**\n * The shapes every entry shares. Plain data: a rect is a top-left corner and a size, in whatever px the consumer\n * lays out in (stage, window or host coordinates). The same shape as @n-uf/motion's, so the two compose without\n * either importing the other.\n */\n\nexport interface Rect {\n x: number;\n y: number;\n width: number;\n height: number;\n}\n\nexport interface Size {\n readonly width: number;\n readonly height: number;\n}\n\nexport interface Point {\n readonly x: number;\n readonly y: number;\n}\n\nexport const rect = (x: number, y: number, width: number, height: number): Rect => ({ x, y, width, height });\n\n/** The area two rects share (0 when apart). */\nexport const overlap = (a: Rect, b: Rect): number =>\n Math.max(0, Math.min(a.x + a.width, b.x + b.width) - Math.max(a.x, b.x)) * Math.max(0, Math.min(a.y + a.height, b.y + b.height) - Math.max(a.y, b.y));\n\n/** `r` moved (not resized) to lie inside `area`; one larger than the area keeps its top-left corner on the area's. */\nexport const clampInto = (r: Rect, area: Rect): Rect => ({\n ...r,\n x: Math.min(Math.max(r.x, area.x), Math.max(area.x, area.x + area.width - r.width)),\n y: Math.min(Math.max(r.y, area.y), Math.max(area.y, area.y + area.height - r.height)),\n});\n\n/** The center of a rect. */\nexport const center = (r: Rect): Point => ({ x: r.x + r.width / 2, y: r.y + r.height / 2 });\n\n/** The tolerance the geometry compares with, px. */\nexport const EPS = 1e-6;\n\n/** A rect that covers any point a page can see (a float target's hit). */\nexport const PLANE: Rect = rect(-1e9, -1e9, 2e9, 2e9);\n\n/** A rect's area (a negative side counts as 0). */\nexport const area = (r: Rect): number => Math.max(0, r.width) * Math.max(0, r.height);\n\n/** Whether two rects share more than `eps` each way (touching edges don't overlap). */\nexport const overlaps = (a: Rect, b: Rect, eps = EPS): boolean =>\n Math.min(a.x + a.width, b.x + b.width) - Math.max(a.x, b.x) > eps && Math.min(a.y + a.height, b.y + b.height) - Math.max(a.y, b.y) > eps;\n\n/** Whether `p` lies in `r`, its edges included (within `eps`). */\nexport const contains = (r: Rect, p: Point, eps = EPS): boolean => p.x >= r.x - eps && p.x <= r.x + r.width + eps && p.y >= r.y - eps && p.y <= r.y + r.height + eps;\n\n/** `v` within `lo..hi` (`lo` wins when `hi` is under it). */\nexport const clamp = (v: number, lo: number, hi: number): number => Math.min(Math.max(v, lo), Math.max(lo, hi));\n\n/** `r` less `cut`, as disjoint rects: the parts beside the cut whole, then above and below it within its width. */\nexport function subtract(r: Rect, cut: Rect): Rect[] {\n if (!overlaps(r, cut)) return [r];\n const right = r.x + r.width;\n const bottom = r.y + r.height;\n const x0 = Math.max(r.x, cut.x);\n const x1 = Math.min(right, cut.x + cut.width);\n return [\n rect(r.x, r.y, x0 - r.x, r.height),\n rect(x1, r.y, right - x1, r.height),\n rect(x0, r.y, x1 - x0, Math.min(bottom, cut.y) - r.y),\n rect(x0, Math.max(r.y, cut.y + cut.height), x1 - x0, bottom - Math.max(r.y, cut.y + cut.height)),\n ].filter((p) => area(p) > EPS);\n}\n"],"mappings":";AAuBO,IAAM,OAAO,CAAC,GAAW,GAAW,OAAe,YAA0B,EAAE,GAAG,GAAG,OAAO,OAAO;AAGnG,IAAM,UAAU,CAAC,GAAS,MAC/B,KAAK,IAAI,GAAG,KAAK,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,IAAI,KAAK,IAAI,EAAE,GAAG,EAAE,CAAC,CAAC,IAAI,KAAK,IAAI,GAAG,KAAK,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,IAAI,KAAK,IAAI,EAAE,GAAG,EAAE,CAAC,CAAC;AAG/I,IAAM,YAAY,CAAC,GAASA,WAAsB;AAAA,EACvD,GAAG;AAAA,EACH,GAAG,KAAK,IAAI,KAAK,IAAI,EAAE,GAAGA,MAAK,CAAC,GAAG,KAAK,IAAIA,MAAK,GAAGA,MAAK,IAAIA,MAAK,QAAQ,EAAE,KAAK,CAAC;AAAA,EAClF,GAAG,KAAK,IAAI,KAAK,IAAI,EAAE,GAAGA,MAAK,CAAC,GAAG,KAAK,IAAIA,MAAK,GAAGA,MAAK,IAAIA,MAAK,SAAS,EAAE,MAAM,CAAC;AACtF;AAGO,IAAM,SAAS,CAAC,OAAoB,EAAE,GAAG,EAAE,IAAI,EAAE,QAAQ,GAAG,GAAG,EAAE,IAAI,EAAE,SAAS,EAAE;AAGlF,IAAM,MAAM;AAGZ,IAAM,QAAc,KAAK,MAAM,MAAM,KAAK,GAAG;AAG7C,IAAM,OAAO,CAAC,MAAoB,KAAK,IAAI,GAAG,EAAE,KAAK,IAAI,KAAK,IAAI,GAAG,EAAE,MAAM;AAG7E,IAAM,WAAW,CAAC,GAAS,GAAS,MAAM,QAC/C,KAAK,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,IAAI,KAAK,IAAI,EAAE,GAAG,EAAE,CAAC,IAAI,OAAO,KAAK,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,IAAI,KAAK,IAAI,EAAE,GAAG,EAAE,CAAC,IAAI;AAGhI,IAAM,WAAW,CAAC,GAAS,GAAU,MAAM,QAAiB,EAAE,KAAK,EAAE,IAAI,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,OAAO,EAAE,KAAK,EAAE,IAAI,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,SAAS;AAG1J,IAAM,QAAQ,CAAC,GAAW,IAAY,OAAuB,KAAK,IAAI,KAAK,IAAI,GAAG,EAAE,GAAG,KAAK,IAAI,IAAI,EAAE,CAAC;AAGvG,SAAS,SAAS,GAAS,KAAmB;AACnD,MAAI,CAAC,SAAS,GAAG,GAAG,EAAG,QAAO,CAAC,CAAC;AAChC,QAAM,QAAQ,EAAE,IAAI,EAAE;AACtB,QAAM,SAAS,EAAE,IAAI,EAAE;AACvB,QAAM,KAAK,KAAK,IAAI,EAAE,GAAG,IAAI,CAAC;AAC9B,QAAM,KAAK,KAAK,IAAI,OAAO,IAAI,IAAI,IAAI,KAAK;AAC5C,SAAO;AAAA,IACL,KAAK,EAAE,GAAG,EAAE,GAAG,KAAK,EAAE,GAAG,EAAE,MAAM;AAAA,IACjC,KAAK,IAAI,EAAE,GAAG,QAAQ,IAAI,EAAE,MAAM;AAAA,IAClC,KAAK,IAAI,EAAE,GAAG,KAAK,IAAI,KAAK,IAAI,QAAQ,IAAI,CAAC,IAAI,EAAE,CAAC;AAAA,IACpD,KAAK,IAAI,KAAK,IAAI,EAAE,GAAG,IAAI,IAAI,IAAI,MAAM,GAAG,KAAK,IAAI,SAAS,KAAK,IAAI,EAAE,GAAG,IAAI,IAAI,IAAI,MAAM,CAAC;AAAA,EACjG,EAAE,OAAO,CAAC,MAAM,KAAK,CAAC,IAAI,GAAG;AAC/B;","names":["area"]}
@@ -23,7 +23,7 @@ declare const overlap: (a: Rect, b: Rect) => number;
23
23
  /** `r` moved (not resized) to lie inside `area`; one larger than the area keeps its top-left corner on the area's. */
24
24
  declare const clampInto: (r: Rect, area: Rect) => Rect;
25
25
  /** The center of a rect. */
26
- declare const centre: (r: Rect) => Point;
26
+ declare const center: (r: Rect) => Point;
27
27
  /** The tolerance the geometry compares with, px. */
28
28
  declare const EPS = 0.000001;
29
29
  /** A rect that covers any point a page can see (a float target's hit). */
@@ -38,11 +38,5 @@ declare const contains: (r: Rect, p: Point, eps?: number) => boolean;
38
38
  declare const clamp: (v: number, lo: number, hi: number) => number;
39
39
  /** `r` less `cut`, as disjoint rects: the parts beside the cut whole, then above and below it within its width. */
40
40
  declare function subtract(r: Rect, cut: Rect): Rect[];
41
- /**
42
- * Hit sizes the targets share: how far a column line's hit reaches on each side of the line, and how deep a side takes
43
- * a rail drop while it shows no rail, px.
44
- */
45
- declare const COLUMN_REACH = 22;
46
- declare const RAIL_EDGE = 10;
47
41
 
48
- export { COLUMN_REACH as C, EPS as E, type Point as P, type Rect as R, type Size as S, PLANE as a, RAIL_EDGE as b, area as c, centre as d, clamp as e, clampInto as f, contains as g, overlaps as h, overlap as o, rect as r, subtract as s };
42
+ export { EPS as E, type Point as P, type Rect as R, type Size as S, PLANE as a, area as b, center as c, clamp as d, clampInto as e, contains as f, overlaps as g, overlap as o, rect as r, subtract as s };
package/dist/index.d.ts CHANGED
@@ -1,48 +1,70 @@
1
- import { P as Point, R as Rect, S as Size } from './geometry-Bf37LbCT.js';
2
- export { C as COLUMN_REACH, E as EPS, a as PLANE, b as RAIL_EDGE, c as area, d as centre, e as clamp, f as clampInto, g as contains, o as overlap, h as overlaps, r as rect, s as subtract } from './geometry-Bf37LbCT.js';
3
- export { R as REFUSAL_RANK, T as Target, p as pickRank } from './target-BBOCeez2.js';
1
+ import { R as Rect } from './geometry-L5gCoiZV.js';
2
+ export { E as EPS, a as PLANE, P as Point, S as Size, b as area, c as center, d as clamp, e as clampInto, f as contains, o as overlap, g as overlaps, r as rect, s as subtract } from './geometry-L5gCoiZV.js';
4
3
 
5
4
  /**
6
- * Placing a popup (a drop label, a menu, a tooltip) the way Wayland's xdg-positioner does: an anchor point on the
7
- * anchor rect, a gravity, an offset, then the constraint adjustments in order per axis: flip, slide, resize.
5
+ * A drop target in the shape @n-uf/motion/drag takes: an id, a priority (1 most precise: a rail or a tab strip;
6
+ * 2 a slot; 3 a broad area such as floating anywhere), the zone the pointer hits, and optionally where the item
7
+ * lands, a label and whether it lands freely (no room is made for it). `hits`, when given, is the whole zone as several
8
+ * rects (a zone that isn't one rect), `hit` the largest of them: the pointer is in the zone when it is in any of them.
9
+ * `arm: "dwell"` marks a spring-loaded target (the drag intent arms it once the pointer dwells in it), `armedHit` its
10
+ * zone once armed.
8
11
  */
9
-
10
- /** -1: the start edge (left or top), 0: the center, 1: the end edge. */
11
- type Align = -1 | 0 | 1;
12
+ interface Target {
13
+ readonly id: string;
14
+ readonly priority: 1 | 2 | 3;
15
+ readonly hit: Rect;
16
+ readonly hits?: readonly Rect[];
17
+ /** Spring-loaded: no target until the pointer dwells in it. */
18
+ readonly arm?: "dwell";
19
+ /** Its zone once armed (the strip grown by its magnet). */
20
+ readonly armedHit?: Rect;
21
+ readonly slot?: Rect;
22
+ readonly label?: string;
23
+ readonly free?: boolean;
24
+ /**
25
+ * A refusal, not a target: it takes part in the pick under the pointer, ranked after every target of priority 1 and 2
26
+ * and before priority 3 (`REFUSAL_RANK`, whatever its `priority`), but nothing lands on it (`refusalTargets`).
27
+ */
28
+ readonly refuse?: true;
29
+ /**
30
+ * The drawn space the zone belongs to (the window's stage): the zone, and a drag intent's band and gap grace about
31
+ * it, hold only points strictly inside it. The window's boundary belongs only to the targets drawn against it: the
32
+ * docking model gives `bounds` to every refusal and to the float (whole-plane), never to a gap or a slot, so a pointer clamped
33
+ * onto the window's edge picks a gap that reaches it, else nothing. That relies on the host clamping exactly onto the
34
+ * stage's edge (`x + width`, `y + height`): a host that clamps to `width - 0.5` still picks inside the window.
35
+ */
36
+ readonly bounds?: Rect;
37
+ /**
38
+ * Its room opens as it shows: the docking model sets it on a target whose slot overlaps an item its drop moves (a rail pushing
39
+ * a column, a new-column line, a bar's strip over the columns), and on a rail drop strip's targets, whose room opens
40
+ * once armed. The drag intent then shows it and makes its room in one frame. Until it shows, a release still lands on
41
+ * it.
42
+ */
43
+ readonly opensRoom?: true;
44
+ /**
45
+ * With `opensRoom`, how long it holds before it shows with its room, ms, in place of the drag intent's `roomAfter`. The
46
+ * docking model sets it to `EDGE_ROOM_HOLD` on a rail target or a new-column line against the window's left or right edge.
47
+ */
48
+ readonly roomHold?: number;
49
+ /**
50
+ * With `opensRoom`, the zone it holds once its room is open: while the target shows with its room open, a drag intent
51
+ * holds it wherever the pointer is in this rect. The docking model sets it to the smallest rect holding `hit` and the slot (the
52
+ * landing rect) on every target whose drop changes an edge's thickness (a side's width or a bar's height): strips,
53
+ * new-column lines, rails and gaps. A rail drop strip (`armedHit`) doesn't carry it.
54
+ */
55
+ readonly roomHit?: Rect;
56
+ }
12
57
  /**
13
- * A rule: the popup's anchor point on the anchor rect, the direction it extends from there (gravity), an offset,
14
- * and which adjustments are allowed: flip (mirror anchor, gravity and offset; kept only if that fits), then slide
15
- * (move inside, the start edge winning), then resize (cut to the bounds).
58
+ * Where a refusal ranks in the pick (the drag intent's `REFUSAL_RANK`, the same value): an ordering rank, not a
59
+ * priority. Priorities stay the integers 1, 2 and 3; a refusal's tier is `refuse: true`, ordered by this rank on the
60
+ * same scale: after every target of priority 1 and 2, so a real target wins wherever the two meet or overlap, and
61
+ * before priority 3 (the float).
16
62
  */
17
- interface PositionerRule {
18
- readonly anchor: {
19
- readonly x: Align;
20
- readonly y: Align;
21
- };
22
- readonly gravity: {
23
- readonly x: Align;
24
- readonly y: Align;
25
- };
26
- readonly offset: Point;
27
- readonly flip: boolean;
28
- readonly slide: boolean;
29
- readonly resize: boolean;
30
- }
31
- interface Positioned {
32
- readonly rect: Rect;
33
- readonly flipped: {
34
- readonly x: boolean;
35
- readonly y: boolean;
36
- };
37
- readonly slid: {
38
- readonly x: boolean;
39
- readonly y: boolean;
40
- };
41
- readonly resized: boolean;
42
- }
43
- /** Where a popup of `size` goes for `anchorRect` by `rule`, kept inside `bounds` as far as the rule allows. */
44
- declare function positionPopup(anchorRect: Rect, size: Size, bounds: Rect, rule: PositionerRule): Positioned;
45
- /** Below the anchor's bottom-left corner, extending right and down, 6 px apart; flips, slides and resizes. */
46
- declare const BELOW_LEFT: PositionerRule;
63
+ declare const REFUSAL_RANK = 2.5;
64
+ /** A target's rank in the pick: its `priority`, a refusal's {@link REFUSAL_RANK}. Lower wins. */
65
+ declare const pickRank: (t: {
66
+ readonly priority: number;
67
+ readonly refuse?: true;
68
+ }) => number;
47
69
 
48
- export { type Align, BELOW_LEFT, Point, type Positioned, type PositionerRule, Rect, Size, positionPopup };
70
+ export { REFUSAL_RANK, Rect, type Target, pickRank };
package/dist/index.js CHANGED
@@ -1,14 +1,8 @@
1
1
  import {
2
- REFUSAL_RANK,
3
- pickRank
4
- } from "./chunk-2GGJ4GVR.js";
5
- import {
6
- COLUMN_REACH,
7
2
  EPS,
8
3
  PLANE,
9
- RAIL_EDGE,
10
4
  area,
11
- centre,
5
+ center,
12
6
  clamp,
13
7
  clampInto,
14
8
  contains,
@@ -16,77 +10,23 @@ import {
16
10
  overlaps,
17
11
  rect,
18
12
  subtract
19
- } from "./chunk-VLTYJHUA.js";
13
+ } from "./chunk-2UVUFEBP.js";
20
14
 
21
- // src/positioner.ts
22
- function placeAxis(a0, alen, anchor, gravity, offset, size) {
23
- const point = a0 + (anchor + 1) / 2 * alen + offset;
24
- return gravity === 1 ? point : gravity === -1 ? point - size : point - size / 2;
25
- }
26
- function positionPopup(anchorRect, size, bounds, rule) {
27
- const axes = [
28
- { a0: anchorRect.x, alen: anchorRect.width, anchor: rule.anchor.x, gravity: rule.gravity.x, offset: rule.offset.x, size: size.width, b0: bounds.x, blen: bounds.width },
29
- { a0: anchorRect.y, alen: anchorRect.height, anchor: rule.anchor.y, gravity: rule.gravity.y, offset: rule.offset.y, size: size.height, b0: bounds.y, blen: bounds.height }
30
- ];
31
- const out = axes.map((ax) => {
32
- const fits = (start2, len2) => start2 >= ax.b0 - 0.01 && start2 + len2 <= ax.b0 + ax.blen + 0.01;
33
- let start = placeAxis(ax.a0, ax.alen, ax.anchor, ax.gravity, ax.offset, ax.size);
34
- let len = ax.size;
35
- let flipped = false;
36
- let slid = false;
37
- let resized = false;
38
- if (!fits(start, len) && rule.flip && (ax.anchor !== 0 || ax.gravity !== 0)) {
39
- const mirrored = placeAxis(ax.a0, ax.alen, -ax.anchor, -ax.gravity, -ax.offset, ax.size);
40
- if (fits(mirrored, len)) {
41
- start = mirrored;
42
- flipped = true;
43
- }
44
- }
45
- if (!fits(start, len) && rule.slide) {
46
- if (start + len > ax.b0 + ax.blen) start = ax.b0 + ax.blen - len;
47
- if (start < ax.b0) start = ax.b0;
48
- slid = true;
49
- }
50
- if (!fits(start, len) && rule.resize) {
51
- const end = Math.min(start + len, ax.b0 + ax.blen);
52
- start = Math.max(start, ax.b0);
53
- len = Math.max(0, end - start);
54
- resized = true;
55
- }
56
- return { start, len, flipped, slid, resized };
57
- });
58
- const [x, y] = out;
59
- return {
60
- rect: { x: x.start, y: y.start, width: x.len, height: y.len },
61
- flipped: { x: x.flipped, y: y.flipped },
62
- slid: { x: x.slid, y: y.slid },
63
- resized: x.resized || y.resized
64
- };
65
- }
66
- var BELOW_LEFT = {
67
- anchor: { x: -1, y: 1 },
68
- gravity: { x: 1, y: 1 },
69
- offset: { x: 0, y: 6 },
70
- flip: true,
71
- slide: true,
72
- resize: true
73
- };
15
+ // src/target.ts
16
+ var REFUSAL_RANK = 2.5;
17
+ var pickRank = (t) => t.refuse === true ? REFUSAL_RANK : t.priority;
74
18
  export {
75
- BELOW_LEFT,
76
- COLUMN_REACH,
77
19
  EPS,
78
20
  PLANE,
79
- RAIL_EDGE,
80
21
  REFUSAL_RANK,
81
22
  area,
82
- centre,
23
+ center,
83
24
  clamp,
84
25
  clampInto,
85
26
  contains,
86
27
  overlap,
87
28
  overlaps,
88
29
  pickRank,
89
- positionPopup,
90
30
  rect,
91
31
  subtract
92
32
  };