@n-uf/placement 26.11.53 → 26.11.54

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 +75 -1
  2. package/README.md +27 -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 +529 -228
  13. package/dist/stack.js +701 -28
  14. package/dist/stack.js.map +1 -1
  15. package/dist/tiling.d.ts +48 -5
  16. package/dist/tiling.js +198 -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,81 @@
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
+ ## 26.11.54
7
+
8
+ Breaking. Placement is the general layer: one edge, one area, one popup. The window's docking model leaves for its own
9
+ package, `@n-uf/docking`, and the replaced entries and deprecated parts go. Behavior is unchanged: every layout, target
10
+ and lane is the same for the same input.
11
+
12
+ Host notes: a host that imports `@n-uf/placement/scene` or `/scene/cases` moves to `@n-uf/docking` and
13
+ `@n-uf/docking/testing` with the renames in docking's CHANGELOG; one that imported a replaced entry moves to
14
+ `@n-uf/docking` or `./tiling`; one that imported `positionPopup` from the root imports it from `./popup`.
15
+
16
+ Added:
17
+ - `./stack`, **`cutEdges(stage, bands)`**: the stage cut into bands along its sides in list order (`EdgeBand`,
18
+ `EdgeCut`, `BandSide`); the order decides the corners, a `reserve` band shortens the leftover and an `over` band lies
19
+ over it (cut after every reserved band, so inside the final leftover, wherever it is listed). Band ids are unique (a
20
+ repeat throws), and a stage width or height that is negative or not finite is cut as 0.
21
+ - `./stack`, **form flags** `StackForm.body`, `.folded` and `.compact`, with `formBody`, `formFolded` and
22
+ `formCompact`: what an open panel, a folded form and an icons form stand for, each defaulting from the kind (`open`;
23
+ `header` and `fold`; `icons`). `formSetsCross` defaults to `formBody`. Nothing changes for a form that sets none.
24
+ - `./stack`, **`stackGaps(input, item, { previous?, allows? })`**: one edge's drop places, fit only: each gap with the
25
+ stack after the drop, its fit and the item's slot, or a refusal with its reason (`StackGap`, `StackGapOptions`,
26
+ `StackGapRefusal`).
27
+ - **`@n-uf/placement/popup`**: the popup positioner's own entry.
28
+ - `./stack`, **`controlLadder(spec)`** and **`StackForm.tiers`**: a group's forms generated from its controls, below.
29
+
30
+ Moved (one-line migration each):
31
+ - `@n-uf/placement/scene` → `@n-uf/docking`; `@n-uf/placement/scene/cases` → `@n-uf/docking/testing`. Install
32
+ `@n-uf/docking` and change the import; the names it renames are listed in docking's CHANGELOG.
33
+ - `positionPopup`, `PositionerRule`, `Positioned`, `Align`, `BELOW_LEFT`: root → `@n-uf/placement/popup`. Change the
34
+ import path.
35
+ - `fitFloat`, `FloatFit`: `./scene` → `./stack` (their one home). Import from `@n-uf/placement/stack`.
36
+ - `COLUMN_REACH`, `RAIL_EDGE`: out of the root into the docking model, unexported. Use your own constant if you drew
37
+ with them.
38
+
39
+ Renamed:
40
+ - `centre` → `center` (root). Rename the call.
41
+
42
+ Removed (one-line migration each):
43
+ - `./dock`, `./toolbar`, `./targets`, `./panels`, `./desk`, every export of each: use `@n-uf/docking` for docks,
44
+ toolbars and panels, `./tiling` for panes (`paneZone` → `paneRegion`, `paneCentre` → `paneCenter`, `PaneZone` →
45
+ `PaneRegion`, `PaneCentre` → `PaneCenter`, `PaneZoneOptions` → `PaneRegionOptions`, `PANE_EDGES` → `PANE_SIDES`,
46
+ `PANE_ZONE_DEFAULTS` → `PANE_REGION_DEFAULTS`), and the root for `Target`.
47
+ - `./stack`: `stackTargets`, `StackTarget`, `StackPlace`, `StackTargetOptions` → `stackGaps` (fit only; hit zones are the
48
+ host's), or `@n-uf/docking`'s `targets` for a window.
49
+ - `./stack`: `createStack`, `storeStack`, `readStack`, `StackState`, `StoredStack`, `StackRead` → `@n-uf/docking`'s
50
+ `storeDockState` / `readDockState`.
51
+ - `./stack`: `stackFloatTarget`, `StackFloatTargetInput`, `FloatTarget`, `FloatDrop`, `storeFloats`, `readFloats`,
52
+ `StoredFloats`, `FloatsRead`, `StackFloat` → `@n-uf/docking`'s float target (`float:<id>`) and stored form;
53
+ `fitFloat` stays.
54
+ - The `@n-uf/motion` development dependency: placement's tests no longer use it.
55
+
56
+ The control ladder, in full (additive, listed under Added above):
57
+
58
+ - `./stack`, **`controlLadder(spec)`: a group's forms generated from its controls** (additive). A host declares a group
59
+ by its controls (`{ id, tiers, foldOrder? }`, the lengths per tier longest first, plus `gap`, `grip`, `more` (the
60
+ group's own » cell) and `cross`), and gets the ordered `StackForm[]` with `rank` and `hides` set: the tier steps one
61
+ 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
62
+ in tier order, so tier steps stay under 400 for any tier count), the partial folds at the last tier that hide the
63
+ first `k` controls in fold order (rank `400 + k / n`, so the group with the fewest hidden controls folds next), then
64
+ `fold` (`hides` every control, rank 500) and `menu` (600). The bands are fixed, so groups of different tier counts
65
+ keep the order across a bar. A bar of such groups runs short control by control: every group's
66
+ tier steps, then every partial fold, then folds, and a growing fixed title gives way only after every group's `row`
67
+ steps. There is no new solver rule: `fitStack` takes the lowest-ranked next form, passes over a form that doesn't
68
+ shorten the stack, and grows back in the exact reverse. The shape is fixed (`n * T + 2` forms for `n` controls and
69
+ `T` tiers; a form no shorter than the one before is still emitted), so form indexes in `previous` stay valid when a
70
+ length changes; when the control set changes, solve the group without `previous`. `keep` lifts a pinned primary's
71
+ last forms; `column: { icons }` adds the group's column forms. The result is `{ row, column? }`, assignable to
72
+ `@n-uf/docking`'s `DockItem.forms`. Hosts that hand-write forms are unchanged.
73
+ - `./stack`, **`StackForm.tiers`: each shown control's tier** (additive, part of `controlLadder`). `controlLadder` sets
74
+ `tiers` (control id to tier index, 0 the longest) on every row form it generates, for the controls the form shows,
75
+ always a valid index into the control's own `tiers` (a control with fewer tiers than its group stays on its last);
76
+ `fold` and `menu` leave it out, and so does every hand-written form. `@n-uf/docking` reports the chosen form's
77
+ `tiers` on the item's layout (`DockItemLayout.tiers`) beside `hidden`, so a host draws each control at `tiers[id]`
78
+ and leaves out `hidden` without knowing the ladder's order.
5
79
 
6
80
  ## 26.11.53
7
81
 
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`, `dropOnPane`) and their 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
@@ -91,12 +60,12 @@ console.log(paneTargets(layoutSplit(tree, area)).map((t) => t.id)); // [ 'pane:a
91
60
 
92
61
  ## Documentation
93
62
 
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)
63
+ - [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.
64
+ - [Reference](https://github.com/n-uf/motion/blob/main/docs/placement-reference.md): every entry point's rules, options and longer examples.
65
+ - [CHANGELOG](https://github.com/n-uf/motion/blob/main/packages/placement/CHANGELOG.md): what changed, and where the window model went.
97
66
  - Site and live demos: [motion.n-uf.com](https://motion.n-uf.com)
98
67
 
99
- Its sibling [`@n-uf/motion`](https://www.npmjs.com/package/@n-uf/motion) owns how things move.
68
+ 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
69
 
101
70
  ## License
102
71
 
@@ -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,SAA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I,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,I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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
  };
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/positioner.ts"],"sourcesContent":["/**\n * Placing a popup (a drop label, a menu, a tooltip) the way Wayland's xdg-positioner does: an anchor point on the\n * anchor rect, a gravity, an offset, then the constraint adjustments in order per axis: flip, slide, resize.\n */\nimport type { Point, Rect, Size } from \"./geometry\";\n\n/** -1: the start edge (left or top), 0: the center, 1: the end edge. */\nexport type Align = -1 | 0 | 1;\n\n/**\n * A rule: the popup's anchor point on the anchor rect, the direction it extends from there (gravity), an offset,\n * and which adjustments are allowed: flip (mirror anchor, gravity and offset; kept only if that fits), then slide\n * (move inside, the start edge winning), then resize (cut to the bounds).\n */\nexport interface PositionerRule {\n readonly anchor: { readonly x: Align; readonly y: Align };\n readonly gravity: { readonly x: Align; readonly y: Align };\n readonly offset: Point;\n readonly flip: boolean;\n readonly slide: boolean;\n readonly resize: boolean;\n}\n\nexport interface Positioned {\n readonly rect: Rect;\n readonly flipped: { readonly x: boolean; readonly y: boolean };\n readonly slid: { readonly x: boolean; readonly y: boolean };\n readonly resized: boolean;\n}\n\nfunction placeAxis(a0: number, alen: number, anchor: Align, gravity: Align, offset: number, size: number): number {\n const point = a0 + ((anchor + 1) / 2) * alen + offset;\n return gravity === 1 ? point : gravity === -1 ? point - size : point - size / 2;\n}\n\n/** Where a popup of `size` goes for `anchorRect` by `rule`, kept inside `bounds` as far as the rule allows. */\nexport function positionPopup(anchorRect: Rect, size: Size, bounds: Rect, rule: PositionerRule): Positioned {\n const axes = [\n { 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 },\n { 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 },\n ];\n const out = axes.map((ax) => {\n const fits = (start: number, len: number): boolean => start >= ax.b0 - 0.01 && start + len <= ax.b0 + ax.blen + 0.01;\n let start = placeAxis(ax.a0, ax.alen, ax.anchor, ax.gravity, ax.offset, ax.size);\n let len = ax.size;\n let flipped = false;\n let slid = false;\n let resized = false;\n if (!fits(start, len) && rule.flip && (ax.anchor !== 0 || ax.gravity !== 0)) {\n const mirrored = placeAxis(ax.a0, ax.alen, -ax.anchor as Align, -ax.gravity as Align, -ax.offset, ax.size);\n if (fits(mirrored, len)) {\n start = mirrored;\n flipped = true;\n }\n }\n if (!fits(start, len) && rule.slide) {\n if (start + len > ax.b0 + ax.blen) start = ax.b0 + ax.blen - len;\n if (start < ax.b0) start = ax.b0;\n slid = true;\n }\n if (!fits(start, len) && rule.resize) {\n const end = Math.min(start + len, ax.b0 + ax.blen);\n start = Math.max(start, ax.b0);\n len = Math.max(0, end - start);\n resized = true;\n }\n return { start, len, flipped, slid, resized };\n });\n const [x, y] = out as [(typeof out)[0], (typeof out)[0]];\n return {\n rect: { x: x.start, y: y.start, width: x.len, height: y.len },\n flipped: { x: x.flipped, y: y.flipped },\n slid: { x: x.slid, y: y.slid },\n resized: x.resized || y.resized,\n };\n}\n\n/** Below the anchor's bottom-left corner, extending right and down, 6 px apart; flips, slides and resizes. */\nexport const BELOW_LEFT: PositionerRule = {\n anchor: { x: -1, y: 1 },\n gravity: { x: 1, y: 1 },\n offset: { x: 0, y: 6 },\n flip: true,\n slide: true,\n resize: true,\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AA8BA,SAAS,UAAU,IAAY,MAAc,QAAe,SAAgB,QAAgB,MAAsB;AAChH,QAAM,QAAQ,MAAO,SAAS,KAAK,IAAK,OAAO;AAC/C,SAAO,YAAY,IAAI,QAAQ,YAAY,KAAK,QAAQ,OAAO,QAAQ,OAAO;AAChF;AAGO,SAAS,cAAc,YAAkB,MAAY,QAAc,MAAkC;AAC1G,QAAM,OAAO;AAAA,IACX,EAAE,IAAI,WAAW,GAAG,MAAM,WAAW,OAAO,QAAQ,KAAK,OAAO,GAAG,SAAS,KAAK,QAAQ,GAAG,QAAQ,KAAK,OAAO,GAAG,MAAM,KAAK,OAAO,IAAI,OAAO,GAAG,MAAM,OAAO,MAAM;AAAA,IACtK,EAAE,IAAI,WAAW,GAAG,MAAM,WAAW,QAAQ,QAAQ,KAAK,OAAO,GAAG,SAAS,KAAK,QAAQ,GAAG,QAAQ,KAAK,OAAO,GAAG,MAA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AA,IACL,MAAM,EAAE,GAAG,EAAE,OAAO,GAAG,EAAE,OAAO,OAAO,EAAE,KAAK,QAAQ,EAAE,IAAI;AAAA,IAC5D,SAAS,EAAE,GAAG,EAAE,SAAS,GAAG,EAAE,QAAQ;AAAA,IACtC,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,EAAE,KAAK;AAAA,IAC7B,SAAS,EAAE,WAAW,EAAE;AAAA,EAC1B;AACF;AAGO,IAAM,aAA6B;AAAA,EACxC,QAAQ,EAAE,GAAG,IAAI,GAAG,EAAE;AAAA,EACtB,SAAS,EAAE,GAAG,GAAG,GAAG,EAAE;AAAA,EACtB,QAAQ,EAAE,GAAG,GAAG,GAAG,EAAE;AAAA,EACrB,MAAM;AAAA,EACN,OAAO;AAAA,EACP,QAAQ;AACV;","names":["start","len"]}
1
+ {"version":3,"sources":["../src/target.ts"],"sourcesContent":["import type { Rect } from \"./geometry\";\n\n/**\n * A drop target in the shape @n-uf/motion/drag takes: an id, a priority (1 most precise: a rail or a tab strip;\n * 2 a slot; 3 a broad area such as floating anywhere), the zone the pointer hits, and optionally where the item\n * lands, a label and whether it lands freely (no room is made for it). `hits`, when given, is the whole zone as several\n * 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.\n * `arm: \"dwell\"` marks a spring-loaded target (the drag intent arms it once the pointer dwells in it), `armedHit` its\n * zone once armed.\n */\nexport interface Target {\n readonly id: string;\n readonly priority: 1 | 2 | 3;\n readonly hit: Rect;\n readonly hits?: readonly Rect[];\n /** Spring-loaded: no target until the pointer dwells in it. */\n readonly arm?: \"dwell\";\n /** Its zone once armed (the strip grown by its magnet). */\n readonly armedHit?: Rect;\n readonly slot?: Rect;\n readonly label?: string;\n readonly free?: boolean;\n /**\n * A refusal, not a target: it takes part in the pick under the pointer, ranked after every target of priority 1 and 2\n * and before priority 3 (`REFUSAL_RANK`, whatever its `priority`), but nothing lands on it (`refusalTargets`).\n */\n readonly refuse?: true;\n /**\n * The drawn space the zone belongs to (the window's stage): the zone, and a drag intent's band and gap grace about\n * it, hold only points strictly inside it. The window's boundary belongs only to the targets drawn against it: the\n * docking model gives `bounds` to every refusal and to the float (whole-plane), never to a gap or a slot, so a pointer clamped\n * onto the window's edge picks a gap that reaches it, else nothing. That relies on the host clamping exactly onto the\n * stage's edge (`x + width`, `y + height`): a host that clamps to `width - 0.5` still picks inside the window.\n */\n readonly bounds?: Rect;\n /**\n * 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\n * a column, a new-column line, a bar's strip over the columns), and on a rail drop strip's targets, whose room opens\n * once armed. The drag intent then shows it and makes its room in one frame. Until it shows, a release still lands on\n * it.\n */\n readonly opensRoom?: true;\n /**\n * With `opensRoom`, how long it holds before it shows with its room, ms, in place of the drag intent's `roomAfter`. The\n * 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.\n */\n readonly roomHold?: number;\n /**\n * With `opensRoom`, the zone it holds once its room is open: while the target shows with its room open, a drag intent\n * holds it wherever the pointer is in this rect. The docking model sets it to the smallest rect holding `hit` and the slot (the\n * landing rect) on every target whose drop changes an edge's thickness (a side's width or a bar's height): strips,\n * new-column lines, rails and gaps. A rail drop strip (`armedHit`) doesn't carry it.\n */\n readonly roomHit?: Rect;\n}\n\n/**\n * Where a refusal ranks in the pick (the drag intent's `REFUSAL_RANK`, the same value): an ordering rank, not a\n * priority. Priorities stay the integers 1, 2 and 3; a refusal's tier is `refuse: true`, ordered by this rank on the\n * same scale: after every target of priority 1 and 2, so a real target wins wherever the two meet or overlap, and\n * before priority 3 (the float).\n */\nexport const REFUSAL_RANK = 2.5;\n\n/** A target's rank in the pick: its `priority`, a refusal's {@link REFUSAL_RANK}. Lower wins. */\nexport const pickRank = (t: { readonly priority: number; readonly refuse?: true }): number => (t.refuse === true ? REFUSAL_RANK : t.priority);\n"],"mappings":";;;;;;;;;;;;;;;AA8DO,IAAM,eAAe;AAGrB,IAAM,WAAW,CAAC,MAAsE,EAAE,WAAW,OAAO,eAAe,EAAE;","names":[]}
@@ -0,0 +1,49 @@
1
+ import { P as Point, R as Rect, S as Size } from './geometry-L5gCoiZV.js';
2
+
3
+ /**
4
+ * @n-uf/placement/popup: placing a popup (a drop label, a menu, a tooltip) the way Wayland's xdg-positioner does: an
5
+ * anchor point on the anchor rect, a gravity, an offset, then the constraint adjustments in order per axis: flip,
6
+ * slide, resize.
7
+ *
8
+ * See docs/placement.md, Entry: popup.
9
+ */
10
+
11
+ /** -1: the start edge (left or top), 0: the center, 1: the end edge. */
12
+ type Align = -1 | 0 | 1;
13
+ /**
14
+ * A rule: the popup's anchor point on the anchor rect, the direction it extends from there (gravity), an offset,
15
+ * and which adjustments are allowed: flip (mirror anchor, gravity and offset; kept only if that fits), then slide
16
+ * (move inside, the start edge winning), then resize (cut to the bounds).
17
+ */
18
+ interface PositionerRule {
19
+ readonly anchor: {
20
+ readonly x: Align;
21
+ readonly y: Align;
22
+ };
23
+ readonly gravity: {
24
+ readonly x: Align;
25
+ readonly y: Align;
26
+ };
27
+ readonly offset: Point;
28
+ readonly flip: boolean;
29
+ readonly slide: boolean;
30
+ readonly resize: boolean;
31
+ }
32
+ interface Positioned {
33
+ readonly rect: Rect;
34
+ readonly flipped: {
35
+ readonly x: boolean;
36
+ readonly y: boolean;
37
+ };
38
+ readonly slid: {
39
+ readonly x: boolean;
40
+ readonly y: boolean;
41
+ };
42
+ readonly resized: boolean;
43
+ }
44
+ /** Where a popup of `size` goes for `anchorRect` by `rule`, kept inside `bounds` as far as the rule allows. */
45
+ declare function positionPopup(anchorRect: Rect, size: Size, bounds: Rect, rule: PositionerRule): Positioned;
46
+ /** Below the anchor's bottom-left corner, extending right and down, 6 px apart; flips, slides and resizes. */
47
+ declare const BELOW_LEFT: PositionerRule;
48
+
49
+ export { type Align, BELOW_LEFT, type Positioned, type PositionerRule, positionPopup };