@n-uf/motion 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 (46) hide show
  1. package/CHANGELOG.md +123 -0
  2. package/README.md +23 -30
  3. package/dist/browser.d.ts +79 -3
  4. package/dist/browser.js +49 -3
  5. package/dist/browser.js.map +1 -1
  6. package/dist/chunk-4XGH5367.js +379 -0
  7. package/dist/chunk-4XGH5367.js.map +1 -0
  8. package/dist/{chunk-SIAZRWYD.js → chunk-ALYH6YQK.js} +4 -7
  9. package/dist/chunk-ALYH6YQK.js.map +1 -0
  10. package/dist/{chunk-BVPVUJ42.js → chunk-G5EJSZ3B.js} +77 -30
  11. package/dist/chunk-G5EJSZ3B.js.map +1 -0
  12. package/dist/{chunk-V7DEXKBZ.js → chunk-NI7JLDWZ.js} +35 -8
  13. package/dist/chunk-NI7JLDWZ.js.map +1 -0
  14. package/dist/{chunk-7EAAKM6U.js → chunk-QMGPJ2FG.js} +37 -89
  15. package/dist/chunk-QMGPJ2FG.js.map +1 -0
  16. package/dist/chunk-RWDYRT3H.js +14 -0
  17. package/dist/chunk-RWDYRT3H.js.map +1 -0
  18. package/dist/chunk-W7YP7VB2.js +882 -0
  19. package/dist/chunk-W7YP7VB2.js.map +1 -0
  20. package/dist/clock.d.ts +40 -7
  21. package/dist/clock.js +3 -1
  22. package/dist/double-click-DBfbiP2U.d.ts +39 -0
  23. package/dist/drag.d.ts +227 -285
  24. package/dist/drag.js +23 -913
  25. package/dist/drag.js.map +1 -1
  26. package/dist/{frame-loop-C88dc9xw.d.ts → frame-loop-f0V4b464.d.ts} +11 -11
  27. package/dist/gestures.d.ts +40 -74
  28. package/dist/gestures.js +8 -7
  29. package/dist/index.d.ts +10 -6
  30. package/dist/index.js +58 -10
  31. package/dist/layout.d.ts +9 -233
  32. package/dist/layout.js +7 -427
  33. package/dist/layout.js.map +1 -1
  34. package/dist/motion-sElR1A_c.d.ts +163 -0
  35. package/dist/reveal-Dg5fqoWS.d.ts +51 -0
  36. package/dist/{reveal-C-ewJfFn.d.ts → settle-7C9xxbFg.d.ts} +7 -57
  37. package/dist/values.d.ts +15 -7
  38. package/dist/values.js +2 -2
  39. package/package.json +2 -2
  40. package/dist/chunk-7EAAKM6U.js.map +0 -1
  41. package/dist/chunk-BVPVUJ42.js.map +0 -1
  42. package/dist/chunk-IJSIYH2D.js +0 -7
  43. package/dist/chunk-IJSIYH2D.js.map +0 -1
  44. package/dist/chunk-SIAZRWYD.js.map +0 -1
  45. package/dist/chunk-V7DEXKBZ.js.map +0 -1
  46. package/dist/double-click-jtUSNuHL.d.ts +0 -16
package/dist/layout.d.ts CHANGED
@@ -1,162 +1,10 @@
1
- import { F as FrameInfo, a as FrameLoop, e as Phase } from './frame-loop-C88dc9xw.js';
2
- import { R as Rect, P as Point } from './shapes-EbQlwbCu.js';
3
- import { R as RevealFrame, P as PopIn, c as SettleConfig } from './reveal-C-ewJfFn.js';
1
+ import { L as LayoutItem } from './motion-sElR1A_c.js';
2
+ export { D as DrawEntry, a as DrawFrame, b as Drawable, c as LayoutMotion, d as LayoutMotionOptions, e as LayoutTask, f as createLayoutMotion } from './motion-sElR1A_c.js';
3
+ import { P as Point, R as Rect } from './shapes-EbQlwbCu.js';
4
+ import { c as SettleConfig } from './settle-7C9xxbFg.js';
5
+ import './frame-loop-f0V4b464.js';
4
6
  import './port-CmlUctqx.js';
5
-
6
- /**
7
- * What a {@link Drawable} draws on a frame: where the item is drawn, the box its content is laid out in, how to draw
8
- * the one at the other without stretching ({@link reveal}), and its appearance ({@link popIn}).
9
- */
10
- interface DrawFrame {
11
- /** Where the item is drawn this frame (its frame: background, border, shadow). */
12
- readonly drawn: Rect;
13
- /** The box its content is laid out in: where it is heading, or (held) where it was laid out last. */
14
- readonly box: Rect;
15
- /** How to draw `box`'s content at `drawn`: a move, the frame at the drawn size, the content clipped. */
16
- readonly reveal: RevealFrame;
17
- /** Its uniform appearance: scale about its center and opacity. */
18
- readonly pop: PopIn;
19
- /** How shown it is, 0 (gone) to 1. */
20
- readonly shown: number;
21
- /** All the way gone: hidden and at rest (out of sight and out of the way of the pointer). */
22
- readonly gone: boolean;
23
- }
24
- /**
25
- * How an item reaches the screen. The layout motion never measures or touches anything itself: it lays an item's
26
- * content out once per new box and draws it once per frame through this. {@link domDrawable} writes an element's
27
- * style; a canvas or a test can draw anything else.
28
- */
29
- interface Drawable {
30
- /** Lay the content out in `box` (its position and size): called once per new box, never per frame. */
31
- layOut(box: Rect): void;
32
- /** Draw the item for this frame. */
33
- draw(frame: DrawFrame): void;
34
- }
35
- /**
36
- * One item the layout motion moves: give it a new place and it settles there from wherever it is drawn.
37
- *
38
- * - {@link LayoutItem.moveTo}: a settle to the new place, retargeted from the drawn rect (no jump, no overshoot);
39
- * the content is laid out at the new box at once and the item redrawn at once, so no frame shows the old offset
40
- * from the new box.
41
- * - A size change is revealed: the content is laid out at the target size and the frame clipped, never scaled.
42
- * - {@link LayoutItem.show}: appear or disappear with a uniform-scale fade.
43
- */
44
- interface LayoutItem {
45
- readonly id: string;
46
- /** Where it is drawn now. */
47
- readonly drawn: Rect;
48
- /** Where it is heading (its settle's target). */
49
- readonly target: Rect;
50
- /** The box its content is laid out in. */
51
- readonly box: Rect;
52
- /** At rest on its target. */
53
- readonly settled: boolean;
54
- /** How shown it is, 0 to 1, and whether it is heading for shown. */
55
- readonly shown: number;
56
- readonly showing: boolean;
57
- /** Its appearance is at rest (fully shown, or gone). */
58
- readonly shownSettled: boolean;
59
- /** Settle to `to` from where it is drawn; lays the content out at `to` and redraws at once. */
60
- moveTo(to: Rect): void;
61
- /**
62
- * Settle to `to` from where it is drawn, like {@link LayoutItem.moveTo}, but keep the content laid out in its box
63
- * while `to` is the box's size: for chasing a moving point (a pointer), which would otherwise lay the content out
64
- * again on every frame. A new size lays it out at `to`, as `moveTo` does. Optional, so an item from before it (or
65
- * a test double) still works where it is used: {@link holdItem} falls back to `moveTo`. `createLayoutMotion`'s
66
- * items always have it.
67
- */
68
- retarget?(to: Rect): void;
69
- /** Be at `to` now, at rest: no glide. */
70
- jumpTo(to: Rect): void;
71
- /** Drawn at `from` now, then settle to `to` (a FLIP's invert and play: `from` in the item's own coordinates). */
72
- glideFrom(from: Rect, to: Rect): void;
73
- /** Exactly at `r`, at rest (what a pointer holds); the content stays laid out in its box, moved with it. */
74
- hold(r: Rect): void;
75
- /** Appear (true) or disappear (false) with a uniform-scale fade; `now`: without the fade. */
76
- show(on: boolean, options?: {
77
- readonly now?: boolean;
78
- }): void;
79
- /** Draw it again now (after its drawable's element was laid out anew from outside). */
80
- redraw(): void;
81
- }
82
- /** A task the layout motion runs on every frame before it steps the items; true keeps the frames coming. */
83
- type LayoutTask = (frame: FrameInfo) => boolean | void;
84
- /** One item's frame in a batch ({@link LayoutMotionOptions.onDraw}). */
85
- interface DrawEntry {
86
- readonly id: string;
87
- readonly frame: DrawFrame;
88
- }
89
- interface LayoutMotionOptions {
90
- /** The frame loop every item steps on (one loop for all of them). */
91
- readonly loop: FrameLoop;
92
- /** The settle tempo, per second ({@link SETTLE_TEMPO}); default `SETTLE_TEMPO.default`. */
93
- readonly omega?: number;
94
- /** The frame phase the items step and draw in; default `"layout"`. */
95
- readonly phase?: Phase;
96
- /** Where an appearing item grows from, as a share of its size ({@link popIn}'s `from`); default 0.87. */
97
- readonly popFrom?: number;
98
- /**
99
- * Reduced motion: read on every new target and every show or hide. While true an item is placed on its new
100
- * target at once (no glide) and appears or disappears at once (no fade). A boolean, or the host's query (such as
101
- * the reduced-motion media query). Default false.
102
- */
103
- readonly reducedMotion?: boolean | (() => boolean);
104
- /**
105
- * Batched drawing: every item that changed is drawn in one pass per frame, after the items step: each one's
106
- * drawable, then this, once, with all of their frames. Changes made between frames (a new target, a hold) are
107
- * drawn on the next frame, or now by {@link LayoutMotion.flush}. Without it, each item is drawn as it changes.
108
- */
109
- readonly onDraw?: (batch: readonly DrawEntry[]) => void;
110
- /** Called when frames start running (true) and when they stop (false), once per change. */
111
- readonly onActiveChange?: (active: boolean) => void;
112
- }
113
- /**
114
- * Layout motion: items with an id and a target rect, each settled to its place on one shared frame loop.
115
- *
116
- * Give an item a new place ({@link LayoutItem.moveTo}) and it glides there from wherever it is drawn: the window
117
- * motion rules of `values/` (settle, reveal, popIn) applied to every item at once. The loop runs only while
118
- * something moves, or a task asks for frames, and stops by itself.
119
- *
120
- * It only animates the rects it is given: which items move where, and when, is the caller's layout.
121
- */
122
- interface LayoutMotion {
123
- /** Add an item drawn by `drawable`, at `at`, shown (or gone: `{ shown: false }`). Its content is laid out at once. */
124
- add(id: string, drawable: Drawable, at: Rect, options?: {
125
- readonly shown?: boolean;
126
- }): LayoutItem;
127
- get(id: string): LayoutItem | undefined;
128
- /** Stop moving an item (its drawable is not touched again). */
129
- remove(id: string): void;
130
- /** Remove every item whose id is not in `ids` (the ones that left the layout). */
131
- retain(ids: Iterable<string>): void;
132
- /**
133
- * With {@link LayoutMotionOptions.onDraw}: draw the items changed since the last frame now, outside the loop. A
134
- * host calls it right after it commits a new layout, so the next paint shows every item where it is drawn, not a
135
- * frame at its new box. Without batching each item is already drawn as it changes, and it does nothing.
136
- */
137
- flush(): void;
138
- readonly items: ReadonlyMap<string, LayoutItem>;
139
- /** Run `task` on every frame, before the items step; returns how to stop it. */
140
- task(task: LayoutTask): () => void;
141
- /** Call `listener` on every frame, after the items have stepped and been drawn; returns how to stop it. */
142
- onFrame(listener: (frame: FrameInfo) => void): () => void;
143
- /** Call `listener` each time the frames stop (nothing moves); returns how to stop it. */
144
- onIdle(listener: () => void): () => void;
145
- /** Make sure at least one more frame runs (a task has something to do). */
146
- wake(): void;
147
- /** Frames are running. */
148
- readonly running: boolean;
149
- /** Set the tempo for every item (and the ones added later). */
150
- configure(config: {
151
- readonly omega?: number;
152
- }): void;
153
- /** Resolves once nothing moves (at once if nothing does). */
154
- idle(): Promise<void>;
155
- /** Stop the frames and forget every item. */
156
- dispose(): void;
157
- }
158
- /** Create the {@link LayoutMotion} for one surface. */
159
- declare function createLayoutMotion(options: LayoutMotionOptions): LayoutMotion;
7
+ import './reveal-Dg5fqoWS.js';
160
8
 
161
9
  /**
162
10
  * An item held by a pointer: the real item (no copy) follows the pointer 1:1 from where it was grabbed, at the size
@@ -252,8 +100,8 @@ interface AnchoredMorph {
252
100
  to(size: BoxSize, anchor: Point): boolean;
253
101
  /** Be at `size` with `anchor` now, at rest. */
254
102
  jumpTo(size: BoxSize, anchor: Point): void;
255
- /** Advance by `dtMs` milliseconds; true while still moving. */
256
- step(dtMs: number): boolean;
103
+ /** Advance by `dt` ms; true while still moving. */
104
+ step(dt: number): boolean;
257
105
  /** The box now with its anchor on `point`. */
258
106
  rectAt(point: Point): Rect;
259
107
  }
@@ -265,76 +113,4 @@ declare const MORPH_TEMPO: 37;
265
113
  /** A box of `size` held at `anchor`, at rest; `config` is the settle's (default tempo {@link MORPH_TEMPO}). */
266
114
  declare function anchoredMorph(size: BoxSize, anchor: Point, config?: SettleConfig): AnchoredMorph;
267
115
 
268
- /** A rect as a DOM rect reports it (`getBoundingClientRect()`): left, top, width, height. */
269
- interface RectLike {
270
- readonly left: number;
271
- readonly top: number;
272
- readonly width: number;
273
- readonly height: number;
274
- }
275
- /** Anything that can say where it is drawn: a DOM node, or a test's stand-in. */
276
- interface Measurable {
277
- getBoundingClientRect(): RectLike;
278
- }
279
- /** A {@link RectLike} as a {@link Rect}. */
280
- declare const rectOf: (r: RectLike) => Rect;
281
- /** One member of a {@link flip}: an item, the node it draws, and where it goes once the DOM has changed. */
282
- interface FlipEntry {
283
- readonly item: LayoutItem;
284
- readonly node: Measurable;
285
- /**
286
- * Once the DOM has changed: the old rect (as measured before, in page coordinates) in the item's own coordinates
287
- * now, and its new place there.
288
- */
289
- readonly place: (before: Rect) => {
290
- readonly from: Rect;
291
- readonly to: Rect;
292
- };
293
- }
294
- /**
295
- * FLIP for DOM groups, on settle: record where each node is drawn (first), change the DOM (`change`: move nodes to
296
- * other parents, reorder them), then each item is drawn at its old rect and settles to its new place (last, invert,
297
- * play). No transform tween: a settle from the rect it was drawn at, so it never jumps or overshoots, and its size
298
- * changes through reveal.
299
- */
300
- declare function flip(entries: readonly FlipEntry[], change: () => void): void;
301
-
302
- /**
303
- * The style properties the layout motion writes, as strings (a DOM node's `style` has them all). Structural: the
304
- * library needs no DOM types.
305
- */
306
- interface StyleLike {
307
- left: string;
308
- top: string;
309
- width: string;
310
- height: string;
311
- transform: string;
312
- opacity: string;
313
- clipPath: string;
314
- visibility: string;
315
- }
316
- /** Something with a writable {@link StyleLike} `style`: a DOM node. */
317
- interface Styled {
318
- readonly style: StyleLike;
319
- }
320
- /**
321
- * The nodes of a drawn box: `node` is laid out at the box and moved to the drawn rect; `frame` (background, border,
322
- * shadow) is drawn at the drawn size; `content` is clipped to it. With no `frame` and `content`, `node` itself is
323
- * clipped (its content laid out at the box, never stretched).
324
- */
325
- interface BoxNodes {
326
- readonly node: Styled;
327
- readonly frame?: Styled;
328
- readonly content?: Styled;
329
- }
330
- /** Lay `node` out at `box`: its position and size, in its offset parent's coordinates. */
331
- declare function layOutBox(node: Styled, box: Rect): void;
332
- /**
333
- * Draw one frame of a box laid out by {@link layOutBox}: one transform (the move to the drawn rect, and the uniform
334
- * appearance about its center), the frame at the drawn size, the content clipped (reveal); hidden when gone.
335
- */
336
- declare function drawBox(nodes: BoxNodes, frame: DrawFrame): void;
337
- /** A {@link Drawable} for DOM nodes: {@link layOutBox} on a new box, {@link drawBox} on every frame. */
338
- declare function domDrawable(nodes: BoxNodes): Drawable;
339
-
340
- export { type AnchoredMorph, type BoxNodes, type BoxSize, type DrawEntry, type DrawFrame, type Drawable, type FlipEntry, type HeldDrag, type LayoutItem, type LayoutMotion, type LayoutMotionOptions, type LayoutTask, MORPH_TEMPO, type Measurable, type RectLike, type StyleLike, type Styled, anchoredMorph, createLayoutMotion, domDrawable, drawBox, flip, holdItem, layOutBox, rectOf };
116
+ export { type AnchoredMorph, type BoxSize, type HeldDrag, LayoutItem, MORPH_TEMPO, Point, Rect, anchoredMorph, holdItem };
package/dist/layout.js CHANGED
@@ -1,434 +1,14 @@
1
1
  import {
2
- SETTLE_TEMPO,
3
- createSettle,
4
- popIn,
5
- reveal
6
- } from "./chunk-SIAZRWYD.js";
7
-
8
- // src/layout/motion.ts
9
- var same = (a, b) => Math.abs(a.x - b.x) < 0.01 && Math.abs(a.y - b.y) < 0.01 && Math.abs(a.width - b.width) < 0.01 && Math.abs(a.height - b.height) < 0.01;
10
- var copy = (r) => ({ x: r.x, y: r.y, width: r.width, height: r.height });
11
- function createLayoutMotion(options) {
12
- const { loop } = options;
13
- const phase = options.phase ?? "layout";
14
- const popFrom = options.popFrom ?? 0.87;
15
- let omega = options.omega ?? SETTLE_TEMPO.default;
16
- const items = /* @__PURE__ */ new Map();
17
- const steps = /* @__PURE__ */ new Map();
18
- const tasks = /* @__PURE__ */ new Set();
19
- const frames = /* @__PURE__ */ new Set();
20
- const idles = /* @__PURE__ */ new Set();
21
- const tempos = /* @__PURE__ */ new Set();
22
- const removers = /* @__PURE__ */ new Map();
23
- let waiters = [];
24
- let stop = null;
25
- let woken = false;
26
- let ticking = false;
27
- let active = false;
28
- const reduced = () => typeof options.reducedMotion === "function" ? options.reducedMotion() : options.reducedMotion === true;
29
- const { onDraw, onActiveChange } = options;
30
- const drawers = /* @__PURE__ */ new Map();
31
- const dirty = /* @__PURE__ */ new Set();
32
- const setActive = (on) => {
33
- if (on === active) return;
34
- active = on;
35
- onActiveChange?.(on);
36
- };
37
- const wake = () => {
38
- woken = true;
39
- if (stop) return;
40
- stop = loop.repeat(phase, tick);
41
- setActive(true);
42
- };
43
- function writeBatch() {
44
- if (!onDraw || dirty.size === 0) return;
45
- const batch = [];
46
- for (const id of dirty) {
47
- const entry = drawers.get(id)?.();
48
- if (entry) batch.push(entry);
49
- }
50
- dirty.clear();
51
- if (batch.length > 0) onDraw(batch);
52
- }
53
- function tick(frame) {
54
- let moving = woken;
55
- woken = false;
56
- ticking = true;
57
- for (const task of [...tasks]) if (task(frame)) moving = true;
58
- for (const step of [...steps.values()]) if (step(frame.delta)) moving = true;
59
- writeBatch();
60
- ticking = false;
61
- for (const listener of [...frames]) listener(frame);
62
- if (moving || woken) return true;
63
- stop = null;
64
- setActive(false);
65
- const resolve = waiters;
66
- waiters = [];
67
- for (const r of resolve) r();
68
- for (const listener of [...idles]) listener();
69
- return false;
70
- }
71
- function add(id, drawable, at, opts = {}) {
72
- if (items.has(id)) throw new Error(`layout motion: item "${id}" is already added (remove it first)`);
73
- const rect = createSettle(copy(at), { omega });
74
- const pop = createSettle(opts.shown === false ? 0 : 1, { omega, restDelta: 1e-3 });
75
- let box = copy(at);
76
- const frameOf = () => {
77
- const drawn = rect.value;
78
- return { drawn, box, reveal: reveal(drawn, box), pop: popIn(pop.value, popFrom), shown: pop.value, gone: pop.settled && pop.value === 0 };
79
- };
80
- const drawNow = () => {
81
- const frame = frameOf();
82
- drawable.draw(frame);
83
- return { id, frame };
84
- };
85
- const draw = () => {
86
- if (!onDraw) {
87
- drawNow();
88
- return;
89
- }
90
- dirty.add(id);
91
- if (!ticking) wake();
92
- };
93
- const layOut = (to) => {
94
- box = copy(to);
95
- drawable.layOut(box);
96
- };
97
- const aim = (to) => {
98
- if (reduced()) {
99
- rect.jumpTo(copy(to));
100
- draw();
101
- return;
102
- }
103
- rect.setTarget(copy(to));
104
- wake();
105
- };
106
- let moved = false;
107
- const tempo = () => {
108
- rect.configure({ omega });
109
- pop.configure({ omega });
110
- };
111
- const item = {
112
- id,
113
- get drawn() {
114
- return rect.value;
115
- },
116
- get target() {
117
- return rect.target;
118
- },
119
- get box() {
120
- return box;
121
- },
122
- get settled() {
123
- return rect.settled;
124
- },
125
- get shown() {
126
- return pop.value;
127
- },
128
- get showing() {
129
- return pop.target === 1;
130
- },
131
- get shownSettled() {
132
- return pop.settled;
133
- },
134
- moveTo(to) {
135
- if (same(box, to) && same(rect.target, to)) return;
136
- layOut(to);
137
- draw();
138
- if (same(rect.target, to)) return;
139
- aim(to);
140
- },
141
- retarget(to) {
142
- if (to.width !== box.width || to.height !== box.height) {
143
- item.moveTo(to);
144
- return;
145
- }
146
- if (same(rect.target, to)) return;
147
- aim(to);
148
- },
149
- jumpTo(to) {
150
- layOut(to);
151
- rect.jumpTo(copy(to));
152
- draw();
153
- },
154
- glideFrom(from, to) {
155
- rect.jumpTo(copy(from));
156
- layOut(to);
157
- draw();
158
- aim(to);
159
- },
160
- hold(r) {
161
- rect.hold(copy(r));
162
- draw();
163
- },
164
- show(on, o = {}) {
165
- const want = on ? 1 : 0;
166
- if (o.now || reduced()) pop.jumpTo(want);
167
- else if (pop.target !== want) {
168
- pop.setTarget(want);
169
- wake();
170
- }
171
- draw();
172
- },
173
- redraw: draw
174
- };
175
- drawers.set(id, drawNow);
176
- drawable.layOut(box);
177
- draw();
178
- items.set(id, item);
179
- tempos.add(tempo);
180
- steps.set(id, (dt) => {
181
- const a = rect.step(dt);
182
- const b = pop.step(dt);
183
- if (!onDraw || a || b || moved) draw();
184
- moved = a || b;
185
- return a || b;
186
- });
187
- removers.set(id, () => {
188
- tempos.delete(tempo);
189
- drawers.delete(id);
190
- dirty.delete(id);
191
- });
192
- return item;
193
- }
194
- function remove(id) {
195
- items.delete(id);
196
- steps.delete(id);
197
- removers.get(id)?.();
198
- removers.delete(id);
199
- }
200
- return {
201
- add,
202
- get: (id) => items.get(id),
203
- remove,
204
- retain(ids) {
205
- const keep = new Set(ids);
206
- for (const id of [...items.keys()]) if (!keep.has(id)) remove(id);
207
- },
208
- flush: writeBatch,
209
- items,
210
- task(task) {
211
- tasks.add(task);
212
- wake();
213
- return () => tasks.delete(task);
214
- },
215
- onFrame(listener) {
216
- frames.add(listener);
217
- return () => frames.delete(listener);
218
- },
219
- onIdle(listener) {
220
- idles.add(listener);
221
- return () => idles.delete(listener);
222
- },
223
- wake,
224
- get running() {
225
- return stop !== null;
226
- },
227
- configure(config) {
228
- if (config.omega !== void 0) omega = config.omega;
229
- for (const t of tempos) t();
230
- },
231
- idle: () => stop ? new Promise((r) => waiters.push(r)) : Promise.resolve(),
232
- dispose() {
233
- stop?.();
234
- stop = null;
235
- setActive(false);
236
- items.clear();
237
- steps.clear();
238
- drawers.clear();
239
- dirty.clear();
240
- tasks.clear();
241
- frames.clear();
242
- idles.clear();
243
- tempos.clear();
244
- removers.clear();
245
- const resolve = waiters;
246
- waiters = [];
247
- for (const r of resolve) r();
248
- }
249
- };
250
- }
251
-
252
- // src/layout/held.ts
253
- var CAUGHT = 0.5;
254
- function holdItem(item, grab) {
255
- let size = { width: item.drawn.width, height: item.drawn.height };
256
- let at = { x: grab.x, y: grab.y };
257
- let pointer = null;
258
- let snapped = null;
259
- let returning = false;
260
- const heldRect = () => pointer ? { x: pointer.x - at.x, y: pointer.y - at.y, width: size.width, height: size.height } : null;
261
- const same2 = (a, b) => Math.max(Math.abs(a.x - b.x), Math.abs(a.y - b.y), Math.abs(a.width - b.width), Math.abs(a.height - b.height)) < 0.01;
262
- const snapTo = (slot) => {
263
- if (slot) {
264
- if (snapped && same2(snapped, slot)) return null;
265
- snapped = { ...slot };
266
- returning = false;
267
- item.moveTo(slot);
268
- return "snapped";
269
- }
270
- if (!snapped) return null;
271
- snapped = null;
272
- returning = true;
273
- return "left";
274
- };
275
- const follow = () => {
276
- const goal = heldRect();
277
- if (!returning || !goal) return false;
278
- if (item.retarget) item.retarget(goal);
279
- else item.moveTo(goal);
280
- const d = item.drawn;
281
- if (Math.max(Math.abs(d.x - goal.x), Math.abs(d.y - goal.y), Math.abs(d.width - goal.width), Math.abs(d.height - goal.height)) >= CAUGHT) return false;
282
- returning = false;
283
- item.hold(goal);
284
- return true;
285
- };
286
- const letGo = (to) => {
287
- const release = { ...item.drawn };
288
- snapped = null;
289
- returning = false;
290
- item.moveTo(to);
291
- return release;
292
- };
293
- return {
294
- get pointer() {
295
- return pointer;
296
- },
297
- get held() {
298
- return heldRect();
299
- },
300
- get snapped() {
301
- return snapped;
302
- },
303
- get returning() {
304
- return returning;
305
- },
306
- move(p) {
307
- pointer = { x: p.x, y: p.y };
308
- if (snapped || returning) return;
309
- item.hold(heldRect());
310
- },
311
- snapTo,
312
- follow,
313
- preview(plan, slot) {
314
- const change = snapTo(plan.snapItem && slot ? slot : null);
315
- follow();
316
- return change;
317
- },
318
- resize(next) {
319
- if (Math.abs(next.width - size.width) < 0.01 && Math.abs(next.height - size.height) < 0.01) return false;
320
- at = { x: size.width ? at.x / size.width * next.width : 0, y: size.height ? at.y / size.height * next.height : 0 };
321
- size = { width: next.width, height: next.height };
322
- if (!snapped && pointer) {
323
- returning = true;
324
- follow();
325
- }
326
- return true;
327
- },
328
- land: letGo,
329
- cancel: letGo
330
- };
331
- }
332
-
333
- // src/layout/anchored.ts
334
- var MORPH_TEMPO = SETTLE_TEMPO.quick;
335
- function anchoredMorph(size, anchor, config = {}) {
336
- const pack = (s, a) => ({ x: finite(a.x), y: finite(a.y), width: Math.max(0, finite(s.width)), height: Math.max(0, finite(s.height)) });
337
- const settle = createSettle(pack(size, anchor), { omega: MORPH_TEMPO, ...config });
338
- let from = settle.value;
339
- const gap = (a, b) => Math.max(Math.abs(a.x - b.x), Math.abs(a.y - b.y), Math.abs(a.width - b.width), Math.abs(a.height - b.height));
340
- return {
341
- get size() {
342
- const v = settle.value;
343
- return { width: v.width, height: v.height };
344
- },
345
- get anchor() {
346
- const v = settle.value;
347
- return { x: v.x, y: v.y };
348
- },
349
- get target() {
350
- const t = settle.target;
351
- return { size: { width: t.width, height: t.height }, anchor: { x: t.x, y: t.y } };
352
- },
353
- get settled() {
354
- return settle.settled;
355
- },
356
- get progress() {
357
- const whole = gap(from, settle.target);
358
- if (settle.settled || whole < 1e-9) return 1;
359
- return Math.min(1, Math.max(0, 1 - gap(settle.value, settle.target) / whole));
360
- },
361
- to(s, a) {
362
- const goal = pack(s, a);
363
- if (gap(goal, settle.target) < 0.01) return false;
364
- from = settle.value;
365
- settle.setTarget(goal);
366
- return true;
367
- },
368
- jumpTo(s, a) {
369
- settle.jumpTo(pack(s, a));
370
- from = settle.value;
371
- },
372
- step(dt) {
373
- return settle.step(dt);
374
- },
375
- rectAt(p) {
376
- const v = settle.value;
377
- return { x: p.x - v.x, y: p.y - v.y, width: v.width, height: v.height };
378
- }
379
- };
380
- }
381
- var finite = (v) => Number.isFinite(v) ? v : 0;
382
-
383
- // src/layout/flip.ts
384
- var rectOf = (r) => ({ x: r.left, y: r.top, width: r.width, height: r.height });
385
- function flip(entries, change) {
386
- const before = entries.map((e) => rectOf(e.node.getBoundingClientRect()));
387
- change();
388
- entries.forEach((e, i) => {
389
- const { from, to } = e.place(before[i]);
390
- e.item.glideFrom(from, to);
391
- });
392
- }
393
-
394
- // src/layout/dom.ts
395
- function layOutBox(node, box) {
396
- const s = node.style;
397
- s.left = `${box.x}px`;
398
- s.top = `${box.y}px`;
399
- s.width = `${box.width}px`;
400
- s.height = `${box.height}px`;
401
- }
402
- function drawBox(nodes, frame) {
403
- const { reveal: r, pop } = frame;
404
- const cx = frame.drawn.width / 2;
405
- const cy = frame.drawn.height / 2;
406
- const s = nodes.node.style;
407
- s.transform = pop.scale === 1 ? `translate(${r.dx}px, ${r.dy}px)` : `translate(${r.dx}px, ${r.dy}px) translate(${cx}px, ${cy}px) scale(${pop.scale}) translate(${-cx}px, ${-cy}px)`;
408
- s.opacity = pop.opacity === 1 ? "" : String(pop.opacity);
409
- if (nodes.frame) {
410
- nodes.frame.style.width = `${r.width}px`;
411
- nodes.frame.style.height = `${r.height}px`;
412
- }
413
- const clipped = nodes.content ?? (nodes.frame ? null : nodes.node);
414
- if (clipped) clipped.style.clipPath = r.clipRight || r.clipBottom ? `inset(0 ${r.clipRight}px ${r.clipBottom}px 0)` : "";
415
- s.visibility = frame.gone ? "hidden" : "";
416
- }
417
- function domDrawable(nodes) {
418
- return {
419
- layOut: (box) => layOutBox(nodes.node, box),
420
- draw: (frame) => drawBox(nodes, frame)
421
- };
422
- }
2
+ MORPH_TEMPO,
3
+ anchoredMorph,
4
+ createLayoutMotion,
5
+ holdItem
6
+ } from "./chunk-4XGH5367.js";
7
+ import "./chunk-ALYH6YQK.js";
423
8
  export {
424
9
  MORPH_TEMPO,
425
10
  anchoredMorph,
426
11
  createLayoutMotion,
427
- domDrawable,
428
- drawBox,
429
- flip,
430
- holdItem,
431
- layOutBox,
432
- rectOf
12
+ holdItem
433
13
  };
434
14
  //# sourceMappingURL=layout.js.map