@n-uf/motion 26.11.22 → 26.11.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +10 -0
- package/README.md +1 -0
- package/dist/index.d.ts +2 -2
- package/dist/layout.d.ts +49 -2
- package/dist/layout.js +52 -0
- package/dist/layout.js.map +1 -1
- package/dist/reveal-CywgKUWx.d.ts +146 -0
- package/dist/values.d.ts +3 -97
- package/package.json +1 -1
- package/dist/reveal-my7U6UyE.d.ts +0 -51
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,16 @@
|
|
|
3
3
|
Versions are calendar versions, `YY.M.R` (year, month of the release, counter
|
|
4
4
|
within the month), the same scheme as `@n-uf/hypr-tiling`.
|
|
5
5
|
|
|
6
|
+
## 26.11.23
|
|
7
|
+
|
|
8
|
+
- `./layout`, **`anchoredMorph(size, anchor, config?)`** (additive): a box held at a point that changes size about an
|
|
9
|
+
anchor. `to(size, anchor)` settles the size and the anchor together, interruptible (a retarget mid-flight turns from
|
|
10
|
+
where it is drawn: no jump, no overshoot), at `MORPH_TEMPO` (90 % in about 60 ms, within 1 % in about 125 ms; the
|
|
11
|
+
last pixels take longer for large size changes) unless the settle config says otherwise;
|
|
12
|
+
`rectAt(point)` keeps the anchor exactly on the point every frame, and `progress` (0 to 1 since the last retarget)
|
|
13
|
+
drives a fade between the content it came from and the target's. Types `AnchoredMorph`, `BoxSize`. For a held item
|
|
14
|
+
that takes another form mid-drag with its grip kept under the pointer: the caller anchors each form at its grip.
|
|
15
|
+
|
|
6
16
|
## 26.11.22
|
|
7
17
|
|
|
8
18
|
- No change in `@n-uf/motion`. Released together with `@n-uf/placement` 26.11.22 (static edges keep their place, outside
|
package/README.md
CHANGED
|
@@ -210,6 +210,7 @@ drop targets) is the caller's layout.
|
|
|
210
210
|
| `item.show(on, { now? })` | Appear or disappear with a uniform-scale fade (`popIn`); folding is a `moveTo` to the folded size, revealed. |
|
|
211
211
|
| `item.drawn`, `target`, `box`, `settled`, `shown`, `showing`, `shownSettled` | Where it is drawn, where it is heading, where its content is laid out. |
|
|
212
212
|
| `holdItem(item, grab)` | A held drag of the real item, no copy: `move(pointer)` holds it 1:1 from the grab offset; `snapTo(slot)` glides into a slot, `snapTo(null)` back to the pointer (`follow()` once a frame until it is under it again); `land(slot)` and `cancel(home)` settle from the release rect, which they return. `preview(plan, slot)` once a frame plays a drop preview (`plan` from `@n-uf/motion/drag`'s `previewPlan`): indicator and gap keep the item under the pointer (gap with the caller's room open), snap glides it into the slot, and a release there finishes that glide. `resize(size)` holds it at a new size from now on (the caller laid its content out for it): the grab point keeps its share of the item, and it settles there from where it is drawn, revealed, never stretched (in a slot it stays put and takes the size when it leaves). |
|
|
213
|
+
| `anchoredMorph(size, anchor, config?)` | A box held at a point that changes size about an anchor (its spot that sits on the point). `to(size, anchor)` settles the size and the anchor together from where they are drawn (at `MORPH_TEMPO`, which is `SETTLE_TEMPO.quick`: 90 % in about 60 ms, within 1 % in about 125 ms, the last pixels longer for large size changes, unless `config` says otherwise; a retarget mid-flight turns at once, no jump, no overshoot; true when the target changed); `jumpTo(size, anchor)` is there at once; `step(dt)` once a frame; `size`, `anchor`, `target` and `settled` read where it is drawn, heading and at rest; `rectAt(point)` is the box with its anchor exactly on the point, every frame; `progress` (0 to 1 since the last retarget) fades the content it came from out and the target's in. Draw each content with its own anchor on the point and neither moves from under the pointer. |
|
|
213
214
|
| `flip(entries, change)` | FLIP for DOM groups on settle: record where each node is drawn, run `change` (the DOM moves), then each item glides from its old rect. |
|
|
214
215
|
| `domDrawable({ node, frame?, content? })`, `layOutBox`, `drawBox` | Draw onto DOM styles: the node laid out at the box, moved by one transform, the frame at the drawn size, the content (or the node) clipped; hidden when gone. Any `{ layOut, draw }` drawable works (a canvas, a test). |
|
|
215
216
|
|
package/dist/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ export { C as ClockPort, F as FrameSource, T as TimerSource } from './port-CmlUc
|
|
|
2
2
|
export { FakeClock, FakeClockOptions, createFakeClock } from './clock.js';
|
|
3
3
|
export { F as FrameInfo, a as FrameLoop, b as FrameLoopOptions, c as FrameStats, d as FrameTask, P as PHASES, e as Phase, R as RepeatingTask, S as ScheduleOptions, f as createFrameLoop } from './frame-loop-C88dc9xw.js';
|
|
4
4
|
export { EffectCleanup, EffectOptions, Equals, ReadonlySignal, Signal, SignalOptions, batch, computed, effect, isSignal, signal, untracked } from './signals.js';
|
|
5
|
-
export {
|
|
6
|
-
export {
|
|
5
|
+
export { A as Animator, P as PopIn, R as RevealFrame, S as SETTLE_DEFAULTS, a as SETTLE_TEMPO, b as Settle, c as SettleConfig, d as createSettle, p as popIn, r as reveal } from './reveal-CywgKUWx.js';
|
|
6
|
+
export { AnimatorValue, Easing, MotionOptions, MotionValue, SPRING_DEFAULTS, SetOptions, Spring, SpringConfig, SpringParams, SpringState, Tween, TweenConfig, createSpring, createTween, cubicBezier, ease, easeIn, easeInOut, easeInOutCubic, easeOut, easeOutCubic, linear, motionValue, resolveSpring, settleValue, springStep, springValue, tweenValue } from './values.js';
|
|
7
7
|
export { CancelReason, CoalescerOptions, DWELL_DEFAULTS, DWELL_IDLE, Deadline, DwellConfig, DwellInput, DwellMachineOptions, DwellState, FrameCoalescer, InputGesture, InputGestureType, Machine, MachineOptions, ModifierDrag, ModifierKey, Modifiers, NO_MODIFIERS, PAGED_SWIPE_DEFAULTS, PAGED_SWIPE_EMPTY_CONTEXT, PAGED_SWIPE_IDLE, PagedSwipeConfig, PagedSwipeContext, PagedSwipeInput, PagedSwipeOptions, PagedSwipeState, Platform, PointerKind, RECOGNIZER_DEFAULTS, RawInputEvent, RawPointerEvent, RawPointerType, RawSafariGestureEvent, RawWheelEvent, Recognizer, RecognizerOptions, RecognizerTimers, SurfacePointer, SwipeSide, TOUCH_PRESS_DEFAULTS, TOUCH_PRESS_IDLE, TouchPressConfig, TouchPressInput, TouchPressOptions, TouchPressState, WHEEL_DEFAULTS, WHEEL_PAN_DEFAULTS, WheelIntent, WheelOptions, WheelPanOptions, classifyWheel, createDwellMachine, createFrameCoalescer, createMachine, createPagedSwipe, createRecognizer, createTouchPress, dampWheelPan, defaultDragModifier, dwellDeadline, dwellReducer, isHeld, modHeld, pagedSwipeDeadline, pagedSwipeReducer, platformButton, resolveDragModifier, swipeProgress, toModifiers, touchPressDeadline, touchPressReducer, wheelDeltaPx } from './gestures.js';
|
|
8
8
|
export { A as Animatable, P as Point, R as Rect, V as Vector, W as Widen, s as shapeEquals } from './shapes-EbQlwbCu.js';
|
package/dist/layout.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { F as FrameInfo, a as FrameLoop, e as Phase } from './frame-loop-C88dc9xw.js';
|
|
2
2
|
import { R as Rect, P as Point } from './shapes-EbQlwbCu.js';
|
|
3
|
-
import { R as RevealFrame, P as PopIn } from './reveal-
|
|
3
|
+
import { R as RevealFrame, P as PopIn, c as SettleConfig } from './reveal-CywgKUWx.js';
|
|
4
4
|
import './port-CmlUctqx.js';
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -218,6 +218,53 @@ interface HeldDrag {
|
|
|
218
218
|
/** Hold `item` from the pointer at `grab` (the pointer's offset from its top-left corner), at its drawn size now. */
|
|
219
219
|
declare function holdItem(item: LayoutItem, grab: Point): HeldDrag;
|
|
220
220
|
|
|
221
|
+
/** A width and a height, px. */
|
|
222
|
+
interface BoxSize {
|
|
223
|
+
readonly width: number;
|
|
224
|
+
readonly height: number;
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* A box held at a point that changes size about an anchor: the anchor is the spot of the box that sits on the point
|
|
228
|
+
* (a pointer's offset from the box's top-left corner). Its size and its anchor settle together to a new size and the
|
|
229
|
+
* new box's anchor ({@link AnchoredMorph.to}), from wherever they are drawn, so a retarget mid-flight turns at once,
|
|
230
|
+
* with no jump and no overshoot. At every step the anchor lies exactly on the point ({@link AnchoredMorph.rectAt}): a
|
|
231
|
+
* caller who draws the old and the new content each with its own anchor on the point never moves either from under
|
|
232
|
+
* the pointer, and fades between them by {@link AnchoredMorph.progress}.
|
|
233
|
+
*/
|
|
234
|
+
interface AnchoredMorph {
|
|
235
|
+
/** The size now. */
|
|
236
|
+
readonly size: BoxSize;
|
|
237
|
+
/** The anchor now: its offset from the box's top-left corner. */
|
|
238
|
+
readonly anchor: Point;
|
|
239
|
+
/** Where it is heading. */
|
|
240
|
+
readonly target: {
|
|
241
|
+
readonly size: BoxSize;
|
|
242
|
+
readonly anchor: Point;
|
|
243
|
+
};
|
|
244
|
+
/** At rest on the target. */
|
|
245
|
+
readonly settled: boolean;
|
|
246
|
+
/**
|
|
247
|
+
* How far along the way from where the last retarget started to the target, 0 to 1 (1 at rest): to fade the content
|
|
248
|
+
* it came from out and the target's in.
|
|
249
|
+
*/
|
|
250
|
+
readonly progress: number;
|
|
251
|
+
/** Head for `size` with `anchor` from where it is drawn. The same target again does nothing; true on a change. */
|
|
252
|
+
to(size: BoxSize, anchor: Point): boolean;
|
|
253
|
+
/** Be at `size` with `anchor` now, at rest. */
|
|
254
|
+
jumpTo(size: BoxSize, anchor: Point): void;
|
|
255
|
+
/** Advance by `dtMs` milliseconds; true while still moving. */
|
|
256
|
+
step(dtMs: number): boolean;
|
|
257
|
+
/** The box now with its anchor on `point`. */
|
|
258
|
+
rectAt(point: Point): Rect;
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* The default tempo, a quick settle (`SETTLE_TEMPO.quick`): 90 % of the way in about 60 ms, within 1 % in about
|
|
262
|
+
* 125 ms; the last pixels take longer for large size changes (a 300 px change rests after about 225 ms).
|
|
263
|
+
*/
|
|
264
|
+
declare const MORPH_TEMPO: 37;
|
|
265
|
+
/** A box of `size` held at `anchor`, at rest; `config` is the settle's (default tempo {@link MORPH_TEMPO}). */
|
|
266
|
+
declare function anchoredMorph(size: BoxSize, anchor: Point, config?: SettleConfig): AnchoredMorph;
|
|
267
|
+
|
|
221
268
|
/** A rect as a DOM rect reports it (`getBoundingClientRect()`): left, top, width, height. */
|
|
222
269
|
interface RectLike {
|
|
223
270
|
readonly left: number;
|
|
@@ -290,4 +337,4 @@ declare function drawBox(nodes: BoxNodes, frame: DrawFrame): void;
|
|
|
290
337
|
/** A {@link Drawable} for DOM nodes: {@link layOutBox} on a new box, {@link drawBox} on every frame. */
|
|
291
338
|
declare function domDrawable(nodes: BoxNodes): Drawable;
|
|
292
339
|
|
|
293
|
-
export { type BoxNodes, type DrawEntry, type DrawFrame, type Drawable, type FlipEntry, type HeldDrag, type LayoutItem, type LayoutMotion, type LayoutMotionOptions, type LayoutTask, type Measurable, type RectLike, type StyleLike, type Styled, createLayoutMotion, domDrawable, drawBox, flip, holdItem, layOutBox, rectOf };
|
|
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 };
|
package/dist/layout.js
CHANGED
|
@@ -330,6 +330,56 @@ function holdItem(item, grab) {
|
|
|
330
330
|
};
|
|
331
331
|
}
|
|
332
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
|
+
|
|
333
383
|
// src/layout/flip.ts
|
|
334
384
|
var rectOf = (r) => ({ x: r.left, y: r.top, width: r.width, height: r.height });
|
|
335
385
|
function flip(entries, change) {
|
|
@@ -371,6 +421,8 @@ function domDrawable(nodes) {
|
|
|
371
421
|
};
|
|
372
422
|
}
|
|
373
423
|
export {
|
|
424
|
+
MORPH_TEMPO,
|
|
425
|
+
anchoredMorph,
|
|
374
426
|
createLayoutMotion,
|
|
375
427
|
domDrawable,
|
|
376
428
|
drawBox,
|
package/dist/layout.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/layout/motion.ts","../src/layout/held.ts","../src/layout/flip.ts","../src/layout/dom.ts"],"sourcesContent":["import type { FrameInfo, FrameLoop, Phase } from \"../clock/frame-loop\";\nimport type { Rect } from \"../shapes\";\nimport { popIn, reveal, type PopIn, type RevealFrame } from \"../values/reveal\";\nimport { createSettle, SETTLE_TEMPO, type Settle } from \"../values/settle\";\n\n/**\n * What a {@link Drawable} draws on a frame: where the item is drawn, the box its content is laid out in, how to draw\n * the one at the other without stretching ({@link reveal}), and its appearance ({@link popIn}).\n */\nexport interface DrawFrame {\n /** Where the item is drawn this frame (its frame: background, border, shadow). */\n readonly drawn: Rect;\n /** The box its content is laid out in: where it is heading, or (held) where it was laid out last. */\n readonly box: Rect;\n /** How to draw `box`'s content at `drawn`: a move, the frame at the drawn size, the content clipped. */\n readonly reveal: RevealFrame;\n /** Its uniform appearance: scale about its centre and opacity. */\n readonly pop: PopIn;\n /** How shown it is, 0 (gone) to 1. */\n readonly shown: number;\n /** All the way gone: hidden and at rest (out of sight and out of the way of the pointer). */\n readonly gone: boolean;\n}\n\n/**\n * How an item reaches the screen. The layout motion never measures or touches anything itself: it lays an item's\n * content out once per new box and draws it once per frame through this. {@link domDrawable} writes an element's\n * style; a canvas or a test can draw anything else.\n */\nexport interface Drawable {\n /** Lay the content out in `box` (its position and size): called once per new box, never per frame. */\n layOut(box: Rect): void;\n /** Draw the item for this frame. */\n draw(frame: DrawFrame): void;\n}\n\n/**\n * One item the layout motion moves: give it a new place and it settles there from wherever it is drawn.\n *\n * - {@link LayoutItem.moveTo}: a settle to the new place, retargeted from the drawn rect (no jump, no overshoot);\n * the content is laid out at the new box at once and the item redrawn at once, so no frame shows the old offset\n * from the new box.\n * - A size change is revealed: the content is laid out at the target size and the frame clipped, never scaled.\n * - {@link LayoutItem.show}: appear or disappear with a uniform-scale fade.\n */\nexport interface LayoutItem {\n readonly id: string;\n /** Where it is drawn now. */\n readonly drawn: Rect;\n /** Where it is heading (its settle's target). */\n readonly target: Rect;\n /** The box its content is laid out in. */\n readonly box: Rect;\n /** At rest on its target. */\n readonly settled: boolean;\n /** How shown it is, 0 to 1, and whether it is heading for shown. */\n readonly shown: number;\n readonly showing: boolean;\n /** Its appearance is at rest (fully shown, or gone). */\n readonly shownSettled: boolean;\n /** Settle to `to` from where it is drawn; lays the content out at `to` and redraws at once. */\n moveTo(to: Rect): void;\n /**\n * Settle to `to` from where it is drawn, like {@link LayoutItem.moveTo}, but keep the content laid out in its box\n * while `to` is the box's size: for chasing a moving point (a pointer), which would otherwise lay the content out\n * again on every frame. A new size lays it out at `to`, as `moveTo` does. Optional, so an item from before it (or\n * a test double) still works where it is used: {@link holdItem} falls back to `moveTo`. `createLayoutMotion`'s\n * items always have it.\n */\n retarget?(to: Rect): void;\n /** Be at `to` now, at rest: no glide. */\n jumpTo(to: Rect): void;\n /** Drawn at `from` now, then settle to `to` (a FLIP's invert and play: `from` in the item's own coordinates). */\n glideFrom(from: Rect, to: Rect): void;\n /** Exactly at `r`, at rest (what a pointer holds); the content stays laid out in its box, moved with it. */\n hold(r: Rect): void;\n /** Appear (true) or disappear (false) with a uniform-scale fade; `now`: without the fade. */\n show(on: boolean, options?: { readonly now?: boolean }): void;\n /** Draw it again now (after its drawable's element was laid out anew from outside). */\n redraw(): void;\n}\n\n/** A task the layout motion runs on every frame before it steps the items; true keeps the frames coming. */\nexport type LayoutTask = (frame: FrameInfo) => boolean | void;\n\n/** One item's frame in a batch ({@link LayoutMotionOptions.onDraw}). */\nexport interface DrawEntry {\n readonly id: string;\n readonly frame: DrawFrame;\n}\n\nexport interface LayoutMotionOptions {\n /** The frame loop every item steps on (one loop for all of them). */\n readonly loop: FrameLoop;\n /** The settle tempo, per second ({@link SETTLE_TEMPO}); default `SETTLE_TEMPO.default`. */\n readonly omega?: number;\n /** The frame phase the items step and draw in; default `\"layout\"`. */\n readonly phase?: Phase;\n /** Where an appearing item grows from, as a share of its size ({@link popIn}'s `from`); default 0.87. */\n readonly popFrom?: number;\n /**\n * Reduced motion: read on every new target and every show or hide. While true an item is placed on its new\n * target at once (no glide) and appears or disappears at once (no fade). A boolean, or the host's query (such as\n * the reduced-motion media query). Default false.\n */\n readonly reducedMotion?: boolean | (() => boolean);\n /**\n * Batched drawing: every item that changed is drawn in one pass per frame, after the items step: each one's\n * drawable, then this, once, with all of their frames. Changes made between frames (a new target, a hold) are\n * drawn on the next frame, or now by {@link LayoutMotion.flush}. Without it, each item is drawn as it changes.\n */\n readonly onDraw?: (batch: readonly DrawEntry[]) => void;\n /** Called when frames start running (true) and when they stop (false), once per change. */\n readonly onActiveChange?: (active: boolean) => void;\n}\n\n/**\n * Layout motion: items with an id and a target rect, each settled to its place on one shared frame loop.\n *\n * Give an item a new place ({@link LayoutItem.moveTo}) and it glides there from wherever it is drawn: the window\n * motion rules of `values/` (settle, reveal, popIn) applied to every item at once. The loop runs only while\n * something moves, or a task asks for frames, and stops by itself.\n *\n * It only animates the rects it is given: which items move where, and when, is the caller's layout.\n */\nexport interface LayoutMotion {\n /** Add an item drawn by `drawable`, at `at`, shown (or gone: `{ shown: false }`). Its content is laid out at once. */\n add(id: string, drawable: Drawable, at: Rect, options?: { readonly shown?: boolean }): LayoutItem;\n get(id: string): LayoutItem | undefined;\n /** Stop moving an item (its drawable is not touched again). */\n remove(id: string): void;\n /** Remove every item whose id is not in `ids` (the ones that left the layout). */\n retain(ids: Iterable<string>): void;\n /**\n * With {@link LayoutMotionOptions.onDraw}: draw the items changed since the last frame now, outside the loop. A\n * host calls it right after it commits a new layout, so the next paint shows every item where it is drawn, not a\n * frame at its new box. Without batching each item is already drawn as it changes, and it does nothing.\n */\n flush(): void;\n readonly items: ReadonlyMap<string, LayoutItem>;\n /** Run `task` on every frame, before the items step; returns how to stop it. */\n task(task: LayoutTask): () => void;\n /** Call `listener` on every frame, after the items have stepped and been drawn; returns how to stop it. */\n onFrame(listener: (frame: FrameInfo) => void): () => void;\n /** Call `listener` each time the frames stop (nothing moves); returns how to stop it. */\n onIdle(listener: () => void): () => void;\n /** Make sure at least one more frame runs (a task has something to do). */\n wake(): void;\n /** Frames are running. */\n readonly running: boolean;\n /** Set the tempo for every item (and the ones added later). */\n configure(config: { readonly omega?: number }): void;\n /** Resolves once nothing moves (at once if nothing does). */\n idle(): Promise<void>;\n /** Stop the frames and forget every item. */\n dispose(): void;\n}\n\n/** Two rects the same within a hundredth of a pixel. */\nconst same = (a: Rect, b: Rect): boolean =>\n 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;\nconst copy = (r: Rect): Rect => ({ x: r.x, y: r.y, width: r.width, height: r.height });\n\n/** Create the {@link LayoutMotion} for one surface. */\nexport function createLayoutMotion(options: LayoutMotionOptions): LayoutMotion {\n const { loop } = options;\n const phase = options.phase ?? \"layout\";\n const popFrom = options.popFrom ?? 0.87;\n let omega = options.omega ?? SETTLE_TEMPO.default;\n const items = new Map<string, LayoutItem>();\n const steps = new Map<string, (dt: number) => boolean>();\n const tasks = new Set<LayoutTask>();\n const frames = new Set<(frame: FrameInfo) => void>();\n const idles = new Set<() => void>();\n const tempos = new Set<() => void>();\n /** What removing an item undoes besides its entry (its tempo hook). */\n const removers = new Map<string, () => void>();\n let waiters: (() => void)[] = [];\n let stop: (() => void) | null = null;\n let woken = false;\n let ticking = false;\n let active = false;\n const reduced = (): boolean => (typeof options.reducedMotion === \"function\" ? options.reducedMotion() : options.reducedMotion === true);\n const { onDraw, onActiveChange } = options;\n /** Batched drawing: how to draw each item, and the ones that changed since the last batch. */\n const drawers = new Map<string, () => DrawEntry>();\n const dirty = new Set<string>();\n\n const setActive = (on: boolean): void => {\n if (on === active) return;\n active = on;\n onActiveChange?.(on);\n };\n\n const wake = (): void => {\n woken = true;\n if (stop) return;\n stop = loop.repeat(phase, tick);\n setActive(true);\n };\n\n /** Draw every item that changed, then hand the batch over once. */\n function writeBatch(): void {\n if (!onDraw || dirty.size === 0) return;\n const batch: DrawEntry[] = [];\n for (const id of dirty) {\n const entry = drawers.get(id)?.();\n if (entry) batch.push(entry);\n }\n dirty.clear();\n if (batch.length > 0) onDraw(batch);\n }\n\n function tick(frame: FrameInfo): boolean {\n let moving = woken;\n woken = false;\n ticking = true;\n for (const task of [...tasks]) if (task(frame)) moving = true;\n for (const step of [...steps.values()]) if (step(frame.delta)) moving = true;\n writeBatch();\n ticking = false;\n for (const listener of [...frames]) listener(frame);\n if (moving || woken) return true;\n stop = null;\n setActive(false);\n const resolve = waiters;\n waiters = [];\n for (const r of resolve) r();\n for (const listener of [...idles]) listener();\n return false;\n }\n\n function add(id: string, drawable: Drawable, at: Rect, opts: { readonly shown?: boolean } = {}): LayoutItem {\n if (items.has(id)) throw new Error(`layout motion: item \"${id}\" is already added (remove it first)`);\n const rect: Settle<Rect> = createSettle<Rect>(copy(at), { omega });\n // A number from 0 to 1: rest within a thousandth, not the default tenth (tuned for pixels).\n const pop: Settle<number> = createSettle(opts.shown === false ? 0 : 1, { omega, restDelta: 0.001 });\n let box = copy(at);\n const frameOf = (): DrawFrame => {\n const drawn = rect.value;\n return { drawn, box, reveal: reveal(drawn, box), pop: popIn(pop.value, popFrom), shown: pop.value, gone: pop.settled && pop.value === 0 };\n };\n const drawNow = (): DrawEntry => {\n const frame = frameOf();\n drawable.draw(frame);\n return { id, frame };\n };\n // Batched: mark it changed (the batch draws it); a change between frames asks for a frame to draw it in.\n const draw = (): void => {\n if (!onDraw) {\n drawNow();\n return;\n }\n dirty.add(id);\n if (!ticking) wake();\n };\n const layOut = (to: Rect): void => {\n box = copy(to);\n drawable.layOut(box);\n };\n /** Head for `to`: a settle from the drawn rect, or (reduced motion) there at once. */\n const aim = (to: Rect): void => {\n if (reduced()) {\n rect.jumpTo(copy(to));\n draw();\n return;\n }\n rect.setTarget(copy(to));\n wake();\n };\n /** It moved on the last step (so the step that brings it to rest still draws it, batched). */\n let moved = false;\n const tempo = (): void => {\n rect.configure({ omega });\n pop.configure({ omega });\n };\n const item: LayoutItem = {\n id,\n get drawn() {\n return rect.value;\n },\n get target() {\n return rect.target;\n },\n get box() {\n return box;\n },\n get settled() {\n return rect.settled;\n },\n get shown() {\n return pop.value;\n },\n get showing() {\n return pop.target === 1;\n },\n get shownSettled() {\n return pop.settled;\n },\n moveTo(to) {\n if (same(box, to) && same(rect.target, to)) return;\n layOut(to);\n // Laid out in the new box now: draw it at once at the drawn rect, else until the next frame it would show\n // the old offset from the new box (a dropped item would flash a frame away from where it was let go).\n draw();\n if (same(rect.target, to)) return;\n aim(to);\n },\n retarget(to) {\n if (to.width !== box.width || to.height !== box.height) {\n item.moveTo(to);\n return;\n }\n if (same(rect.target, to)) return;\n aim(to);\n },\n jumpTo(to) {\n layOut(to);\n rect.jumpTo(copy(to));\n draw();\n },\n glideFrom(from, to) {\n rect.jumpTo(copy(from));\n layOut(to);\n draw();\n aim(to);\n },\n hold(r) {\n rect.hold(copy(r));\n draw();\n },\n show(on, o = {}) {\n const want = on ? 1 : 0;\n if (o.now || reduced()) pop.jumpTo(want);\n else if (pop.target !== want) {\n pop.setTarget(want);\n wake();\n }\n draw();\n },\n redraw: draw,\n };\n drawers.set(id, drawNow);\n drawable.layOut(box);\n draw();\n items.set(id, item);\n tempos.add(tempo);\n steps.set(id, (dt) => {\n const a = rect.step(dt);\n const b = pop.step(dt);\n // Batched, only an item that moved is drawn; else every item, every frame.\n if (!onDraw || a || b || moved) draw();\n moved = a || b;\n return a || b;\n });\n removers.set(id, () => {\n tempos.delete(tempo);\n drawers.delete(id);\n dirty.delete(id);\n });\n return item;\n }\n\n function remove(id: string): void {\n items.delete(id);\n steps.delete(id);\n removers.get(id)?.();\n removers.delete(id);\n }\n\n return {\n add,\n get: (id) => items.get(id),\n remove,\n retain(ids) {\n const keep = new Set(ids);\n for (const id of [...items.keys()]) if (!keep.has(id)) remove(id);\n },\n flush: writeBatch,\n items,\n task(task) {\n tasks.add(task);\n wake();\n return () => tasks.delete(task);\n },\n onFrame(listener) {\n frames.add(listener);\n return () => frames.delete(listener);\n },\n onIdle(listener) {\n idles.add(listener);\n return () => idles.delete(listener);\n },\n wake,\n get running() {\n return stop !== null;\n },\n configure(config) {\n if (config.omega !== undefined) omega = config.omega;\n for (const t of tempos) t();\n },\n idle: () => (stop ? new Promise<void>((r) => waiters.push(r)) : Promise.resolve()),\n dispose() {\n stop?.();\n stop = null;\n setActive(false);\n items.clear();\n steps.clear();\n drawers.clear();\n dirty.clear();\n tasks.clear();\n frames.clear();\n idles.clear();\n tempos.clear();\n removers.clear();\n const resolve = waiters;\n waiters = [];\n for (const r of resolve) r();\n },\n };\n}\n","import type { Point, Rect } from \"../shapes\";\nimport type { LayoutItem } from \"./motion\";\n\n/**\n * An item held by a pointer: the real item (no copy) follows the pointer 1:1 from where it was grabbed, at the size\n * it was lifted at; its place stays reserved (that is the caller's layout). Then:\n *\n * - {@link HeldDrag.snapTo}: glide into a slot (a snap preview); `null` leaves the slot and glides back to the\n * pointer, following it as it moves ({@link HeldDrag.follow} once a frame), until it is under it again.\n * - {@link HeldDrag.land}: let go into a slot: the landing settles from where it was let go (the release rect), never\n * from its old home. Snapped into that slot already, it simply finishes that glide.\n * - {@link HeldDrag.cancel}: let go with no drop: it glides home from where it was let go.\n * - {@link HeldDrag.preview}: the three drop previews, per frame: indicator and gap keep the item under the pointer\n * (gap with the caller's room open), snap glides it into the slot; leaving glides it back to the pointer.\n * - {@link HeldDrag.resize}: the item takes a new size mid-drag (its content laid out anew by the caller): it settles\n * to it from where it is drawn, the size revealed (never stretched), and is held 1:1 again once there.\n */\nexport interface HeldDrag {\n /** Where the pointer is (null before the first move). */\n readonly pointer: Point | null;\n /** Where the pointer holds the item: the pointer less the grab offset, at the held size (lifted, or resized). */\n readonly held: Rect | null;\n /** The slot it sits in (a snap), or null. */\n readonly snapped: Rect | null;\n /** It left a slot (or took a new size) and is gliding back to the pointer. */\n readonly returning: boolean;\n /** The pointer moved: held 1:1 (unless it sits in a slot or is on its way back). */\n move(pointer: Point): void;\n /**\n * Into `slot` (a glide from where it is drawn; the same slot again does nothing), or out of the slot it sits in\n * (`null`: back to the pointer). Returns what changed: `\"snapped\"`, `\"left\"`, or null.\n */\n snapTo(slot: Rect | null): \"snapped\" | \"left\" | null;\n /** Once a frame: on its way back, retarget to the pointer; true on the frame it is under the pointer again. */\n follow(): boolean;\n /**\n * Once a frame, a drop preview's part for the item (`plan`: `@n-uf/motion/drag`'s `previewPlan`, or any\n * `{ snapItem }`): with `snapItem` it glides into `slot` (snap); else it stays under the pointer, or glides back to\n * it from a slot it left (indicator, gap). The room, if the plan makes any, is the caller's layout. In place of\n * {@link HeldDrag.snapTo} and {@link HeldDrag.follow}; returns what changed.\n */\n preview(plan: { readonly snapItem: boolean }, slot: Rect | null): \"snapped\" | \"left\" | null;\n /**\n * Hold it at `size` from now on (the caller has laid its content out for that size). The grab point keeps its share\n * of the item, so the pointer stays on the same spot of it; the item settles from where it is drawn to its new held\n * rect (its size revealed, never stretched), then is held 1:1 again ({@link HeldDrag.follow} once a frame). In a\n * slot it stays there, taking the new size when it leaves. The same size again does nothing; returns true on a\n * change.\n */\n resize(size: { readonly width: number; readonly height: number }): boolean;\n /** Let go into `slot`: returns the release rect, where the landing starts. */\n land(slot: Rect): Rect;\n /** Let go with no drop: glides `home` from the release rect, which it returns. */\n cancel(home: Rect): Rect;\n}\n\n/** How close (px, every component) the way back has to come to count as under the pointer again. */\nconst CAUGHT = 0.5;\n\n/** Hold `item` from the pointer at `grab` (the pointer's offset from its top-left corner), at its drawn size now. */\nexport function holdItem(item: LayoutItem, grab: Point): HeldDrag {\n let size = { width: item.drawn.width, height: item.drawn.height };\n let at = { x: grab.x, y: grab.y };\n let pointer: Point | null = null;\n let snapped: Rect | null = null;\n let returning = false;\n const heldRect = (): Rect | null => (pointer ? { x: pointer.x - at.x, y: pointer.y - at.y, width: size.width, height: size.height } : null);\n const same = (a: Rect, b: Rect): boolean => 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;\n const snapTo = (slot: Rect | null): \"snapped\" | \"left\" | null => {\n if (slot) {\n if (snapped && same(snapped, slot)) return null;\n snapped = { ...slot };\n returning = false;\n item.moveTo(slot);\n return \"snapped\";\n }\n if (!snapped) return null;\n snapped = null;\n returning = true;\n return \"left\";\n };\n const follow = (): boolean => {\n const goal = heldRect();\n if (!returning || !goal) return false;\n // A chase of the pointer: retargeted every frame, laid out again only when its size changes (an item without\n // retarget, from before it or a test double, moves to it).\n if (item.retarget) item.retarget(goal);\n else item.moveTo(goal);\n const d = item.drawn;\n 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;\n returning = false;\n item.hold(goal);\n return true;\n };\n const letGo = (to: Rect): Rect => {\n const release = { ...item.drawn };\n snapped = null;\n returning = false;\n item.moveTo(to);\n return release;\n };\n return {\n get pointer() {\n return pointer;\n },\n get held() {\n return heldRect();\n },\n get snapped() {\n return snapped;\n },\n get returning() {\n return returning;\n },\n move(p) {\n pointer = { x: p.x, y: p.y };\n if (snapped || returning) return;\n item.hold(heldRect()!);\n },\n snapTo,\n follow,\n preview(plan, slot) {\n const change = snapTo(plan.snapItem && slot ? slot : null);\n follow();\n return change;\n },\n resize(next) {\n if (Math.abs(next.width - size.width) < 0.01 && Math.abs(next.height - size.height) < 0.01) return false;\n at = { x: size.width ? (at.x / size.width) * next.width : 0, y: size.height ? (at.y / size.height) * next.height : 0 };\n size = { width: next.width, height: next.height };\n if (!snapped && pointer) {\n returning = true;\n follow();\n }\n return true;\n },\n land: letGo,\n cancel: letGo,\n };\n}\n","import type { Rect } from \"../shapes\";\nimport type { LayoutItem } from \"./motion\";\n\n/** A rect as a DOM rect reports it (`getBoundingClientRect()`): left, top, width, height. */\nexport interface RectLike {\n readonly left: number;\n readonly top: number;\n readonly width: number;\n readonly height: number;\n}\n\n/** Anything that can say where it is drawn: a DOM node, or a test's stand-in. */\nexport interface Measurable {\n getBoundingClientRect(): RectLike;\n}\n\n/** A {@link RectLike} as a {@link Rect}. */\nexport const rectOf = (r: RectLike): Rect => ({ x: r.left, y: r.top, width: r.width, height: r.height });\n\n/** One member of a {@link flip}: an item, the node it draws, and where it goes once the DOM has changed. */\nexport interface FlipEntry {\n readonly item: LayoutItem;\n readonly node: Measurable;\n /**\n * Once the DOM has changed: the old rect (as measured before, in page coordinates) in the item's own coordinates\n * now, and its new place there.\n */\n readonly place: (before: Rect) => { readonly from: Rect; readonly to: Rect };\n}\n\n/**\n * FLIP for DOM groups, on settle: record where each node is drawn (first), change the DOM (`change`: move nodes to\n * other parents, reorder them), then each item is drawn at its old rect and settles to its new place (last, invert,\n * play). No transform tween: a settle from the rect it was drawn at, so it never jumps or overshoots, and its size\n * changes through reveal.\n */\nexport function flip(entries: readonly FlipEntry[], change: () => void): void {\n const before = entries.map((e) => rectOf(e.node.getBoundingClientRect()));\n change();\n entries.forEach((e, i) => {\n const { from, to } = e.place(before[i]!);\n e.item.glideFrom(from, to);\n });\n}\n","import type { Rect } from \"../shapes\";\nimport type { Drawable, DrawFrame } from \"./motion\";\n\n/**\n * The style properties the layout motion writes, as strings (a DOM node's `style` has them all). Structural: the\n * library needs no DOM types.\n */\nexport interface StyleLike {\n left: string;\n top: string;\n width: string;\n height: string;\n transform: string;\n opacity: string;\n clipPath: string;\n visibility: string;\n}\n\n/** Something with a writable {@link StyleLike} `style`: a DOM node. */\nexport interface Styled {\n readonly style: StyleLike;\n}\n\n/**\n * The nodes of a drawn box: `node` is laid out at the box and moved to the drawn rect; `frame` (background, border,\n * shadow) is drawn at the drawn size; `content` is clipped to it. With no `frame` and `content`, `node` itself is\n * clipped (its content laid out at the box, never stretched).\n */\nexport interface BoxNodes {\n readonly node: Styled;\n readonly frame?: Styled;\n readonly content?: Styled;\n}\n\n/** Lay `node` out at `box`: its position and size, in its offset parent's coordinates. */\nexport function layOutBox(node: Styled, box: Rect): void {\n const s = node.style;\n s.left = `${box.x}px`;\n s.top = `${box.y}px`;\n s.width = `${box.width}px`;\n s.height = `${box.height}px`;\n}\n\n/**\n * Draw one frame of a box laid out by {@link layOutBox}: one transform (the move to the drawn rect, and the uniform\n * appearance about its centre), the frame at the drawn size, the content clipped (reveal); hidden when gone.\n */\nexport function drawBox(nodes: BoxNodes, frame: DrawFrame): void {\n const { reveal: r, pop } = frame;\n const cx = frame.drawn.width / 2;\n const cy = frame.drawn.height / 2;\n const s = nodes.node.style;\n s.transform =\n 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)`;\n s.opacity = pop.opacity === 1 ? \"\" : String(pop.opacity);\n if (nodes.frame) {\n nodes.frame.style.width = `${r.width}px`;\n nodes.frame.style.height = `${r.height}px`;\n }\n const clipped = nodes.content ?? (nodes.frame ? null : nodes.node);\n if (clipped) clipped.style.clipPath = r.clipRight || r.clipBottom ? `inset(0 ${r.clipRight}px ${r.clipBottom}px 0)` : \"\";\n // All the way gone: out of sight and out of the way of the pointer.\n s.visibility = frame.gone ? \"hidden\" : \"\";\n}\n\n/** A {@link Drawable} for DOM nodes: {@link layOutBox} on a new box, {@link drawBox} on every frame. */\nexport function domDrawable(nodes: BoxNodes): Drawable {\n return {\n layOut: (box) => layOutBox(nodes.node, box),\n draw: (frame) => drawBox(nodes, frame),\n };\n}\n"],"mappings":";;;;;;;;AA+JA,IAAM,OAAO,CAAC,GAAS,MACrB,KAAK,IAAI,EAAE,IAAI,EAAE,CAAC,IAAI,QAAQ,KAAK,IAAI,EAAE,IAAI,EAAE,CAAC,IAAI,QAAQ,KAAK,IAAI,EAAE,QAAQ,EAAE,KAAK,IAAI,QAAQ,KAAK,IAAI,EAAE,SAAS,EAAE,M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aAAa,WAAW,EAAE,SAAS,MAAM,EAAE,UAAU,UAAU;AAEtH,IAAE,aAAa,MAAM,OAAO,WAAW;AACzC;AAGO,SAAS,YAAY,OAA2B;AACrD,SAAO;AAAA,IACL,QAAQ,CAAC,QAAQ,UAAU,MAAM,MAAM,GAAG;AAAA,IAC1C,MAAM,CAAC,UAAU,QAAQ,OAAO,KAAK;AAAA,EACvC;AACF;","names":["same"]}
|
|
1
|
+
{"version":3,"sources":["../src/layout/motion.ts","../src/layout/held.ts","../src/layout/anchored.ts","../src/layout/flip.ts","../src/layout/dom.ts"],"sourcesContent":["import type { FrameInfo, FrameLoop, Phase } from \"../clock/frame-loop\";\nimport type { Rect } from \"../shapes\";\nimport { popIn, reveal, type PopIn, type RevealFrame } from \"../values/reveal\";\nimport { createSettle, SETTLE_TEMPO, type Settle } from \"../values/settle\";\n\n/**\n * What a {@link Drawable} draws on a frame: where the item is drawn, the box its content is laid out in, how to draw\n * the one at the other without stretching ({@link reveal}), and its appearance ({@link popIn}).\n */\nexport interface DrawFrame {\n /** Where the item is drawn this frame (its frame: background, border, shadow). */\n readonly drawn: Rect;\n /** The box its content is laid out in: where it is heading, or (held) where it was laid out last. */\n readonly box: Rect;\n /** How to draw `box`'s content at `drawn`: a move, the frame at the drawn size, the content clipped. */\n readonly reveal: RevealFrame;\n /** Its uniform appearance: scale about its centre and opacity. */\n readonly pop: PopIn;\n /** How shown it is, 0 (gone) to 1. */\n readonly shown: number;\n /** All the way gone: hidden and at rest (out of sight and out of the way of the pointer). */\n readonly gone: boolean;\n}\n\n/**\n * How an item reaches the screen. The layout motion never measures or touches anything itself: it lays an item's\n * content out once per new box and draws it once per frame through this. {@link domDrawable} writes an element's\n * style; a canvas or a test can draw anything else.\n */\nexport interface Drawable {\n /** Lay the content out in `box` (its position and size): called once per new box, never per frame. */\n layOut(box: Rect): void;\n /** Draw the item for this frame. */\n draw(frame: DrawFrame): void;\n}\n\n/**\n * One item the layout motion moves: give it a new place and it settles there from wherever it is drawn.\n *\n * - {@link LayoutItem.moveTo}: a settle to the new place, retargeted from the drawn rect (no jump, no overshoot);\n * the content is laid out at the new box at once and the item redrawn at once, so no frame shows the old offset\n * from the new box.\n * - A size change is revealed: the content is laid out at the target size and the frame clipped, never scaled.\n * - {@link LayoutItem.show}: appear or disappear with a uniform-scale fade.\n */\nexport interface LayoutItem {\n readonly id: string;\n /** Where it is drawn now. */\n readonly drawn: Rect;\n /** Where it is heading (its settle's target). */\n readonly target: Rect;\n /** The box its content is laid out in. */\n readonly box: Rect;\n /** At rest on its target. */\n readonly settled: boolean;\n /** How shown it is, 0 to 1, and whether it is heading for shown. */\n readonly shown: number;\n readonly showing: boolean;\n /** Its appearance is at rest (fully shown, or gone). */\n readonly shownSettled: boolean;\n /** Settle to `to` from where it is drawn; lays the content out at `to` and redraws at once. */\n moveTo(to: Rect): void;\n /**\n * Settle to `to` from where it is drawn, like {@link LayoutItem.moveTo}, but keep the content laid out in its box\n * while `to` is the box's size: for chasing a moving point (a pointer), which would otherwise lay the content out\n * again on every frame. A new size lays it out at `to`, as `moveTo` does. Optional, so an item from before it (or\n * a test double) still works where it is used: {@link holdItem} falls back to `moveTo`. `createLayoutMotion`'s\n * items always have it.\n */\n retarget?(to: Rect): void;\n /** Be at `to` now, at rest: no glide. */\n jumpTo(to: Rect): void;\n /** Drawn at `from` now, then settle to `to` (a FLIP's invert and play: `from` in the item's own coordinates). */\n glideFrom(from: Rect, to: Rect): void;\n /** Exactly at `r`, at rest (what a pointer holds); the content stays laid out in its box, moved with it. */\n hold(r: Rect): void;\n /** Appear (true) or disappear (false) with a uniform-scale fade; `now`: without the fade. */\n show(on: boolean, options?: { readonly now?: boolean }): void;\n /** Draw it again now (after its drawable's element was laid out anew from outside). */\n redraw(): void;\n}\n\n/** A task the layout motion runs on every frame before it steps the items; true keeps the frames coming. */\nexport type LayoutTask = (frame: FrameInfo) => boolean | void;\n\n/** One item's frame in a batch ({@link LayoutMotionOptions.onDraw}). */\nexport interface DrawEntry {\n readonly id: string;\n readonly frame: DrawFrame;\n}\n\nexport interface LayoutMotionOptions {\n /** The frame loop every item steps on (one loop for all of them). */\n readonly loop: FrameLoop;\n /** The settle tempo, per second ({@link SETTLE_TEMPO}); default `SETTLE_TEMPO.default`. */\n readonly omega?: number;\n /** The frame phase the items step and draw in; default `\"layout\"`. */\n readonly phase?: Phase;\n /** Where an appearing item grows from, as a share of its size ({@link popIn}'s `from`); default 0.87. */\n readonly popFrom?: number;\n /**\n * Reduced motion: read on every new target and every show or hide. While true an item is placed on its new\n * target at once (no glide) and appears or disappears at once (no fade). A boolean, or the host's query (such as\n * the reduced-motion media query). Default false.\n */\n readonly reducedMotion?: boolean | (() => boolean);\n /**\n * Batched drawing: every item that changed is drawn in one pass per frame, after the items step: each one's\n * drawable, then this, once, with all of their frames. Changes made between frames (a new target, a hold) are\n * drawn on the next frame, or now by {@link LayoutMotion.flush}. Without it, each item is drawn as it changes.\n */\n readonly onDraw?: (batch: readonly DrawEntry[]) => void;\n /** Called when frames start running (true) and when they stop (false), once per change. */\n readonly onActiveChange?: (active: boolean) => void;\n}\n\n/**\n * Layout motion: items with an id and a target rect, each settled to its place on one shared frame loop.\n *\n * Give an item a new place ({@link LayoutItem.moveTo}) and it glides there from wherever it is drawn: the window\n * motion rules of `values/` (settle, reveal, popIn) applied to every item at once. The loop runs only while\n * something moves, or a task asks for frames, and stops by itself.\n *\n * It only animates the rects it is given: which items move where, and when, is the caller's layout.\n */\nexport interface LayoutMotion {\n /** Add an item drawn by `drawable`, at `at`, shown (or gone: `{ shown: false }`). Its content is laid out at once. */\n add(id: string, drawable: Drawable, at: Rect, options?: { readonly shown?: boolean }): LayoutItem;\n get(id: string): LayoutItem | undefined;\n /** Stop moving an item (its drawable is not touched again). */\n remove(id: string): void;\n /** Remove every item whose id is not in `ids` (the ones that left the layout). */\n retain(ids: Iterable<string>): void;\n /**\n * With {@link LayoutMotionOptions.onDraw}: draw the items changed since the last frame now, outside the loop. A\n * host calls it right after it commits a new layout, so the next paint shows every item where it is drawn, not a\n * frame at its new box. Without batching each item is already drawn as it changes, and it does nothing.\n */\n flush(): void;\n readonly items: ReadonlyMap<string, LayoutItem>;\n /** Run `task` on every frame, before the items step; returns how to stop it. */\n task(task: LayoutTask): () => void;\n /** Call `listener` on every frame, after the items have stepped and been drawn; returns how to stop it. */\n onFrame(listener: (frame: FrameInfo) => void): () => void;\n /** Call `listener` each time the frames stop (nothing moves); returns how to stop it. */\n onIdle(listener: () => void): () => void;\n /** Make sure at least one more frame runs (a task has something to do). */\n wake(): void;\n /** Frames are running. */\n readonly running: boolean;\n /** Set the tempo for every item (and the ones added later). */\n configure(config: { readonly omega?: number }): void;\n /** Resolves once nothing moves (at once if nothing does). */\n idle(): Promise<void>;\n /** Stop the frames and forget every item. */\n dispose(): void;\n}\n\n/** Two rects the same within a hundredth of a pixel. */\nconst same = (a: Rect, b: Rect): boolean =>\n 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;\nconst copy = (r: Rect): Rect => ({ x: r.x, y: r.y, width: r.width, height: r.height });\n\n/** Create the {@link LayoutMotion} for one surface. */\nexport function createLayoutMotion(options: LayoutMotionOptions): LayoutMotion {\n const { loop } = options;\n const phase = options.phase ?? \"layout\";\n const popFrom = options.popFrom ?? 0.87;\n let omega = options.omega ?? SETTLE_TEMPO.default;\n const items = new Map<string, LayoutItem>();\n const steps = new Map<string, (dt: number) => boolean>();\n const tasks = new Set<LayoutTask>();\n const frames = new Set<(frame: FrameInfo) => void>();\n const idles = new Set<() => void>();\n const tempos = new Set<() => void>();\n /** What removing an item undoes besides its entry (its tempo hook). */\n const removers = new Map<string, () => void>();\n let waiters: (() => void)[] = [];\n let stop: (() => void) | null = null;\n let woken = false;\n let ticking = false;\n let active = false;\n const reduced = (): boolean => (typeof options.reducedMotion === \"function\" ? options.reducedMotion() : options.reducedMotion === true);\n const { onDraw, onActiveChange } = options;\n /** Batched drawing: how to draw each item, and the ones that changed since the last batch. */\n const drawers = new Map<string, () => DrawEntry>();\n const dirty = new Set<string>();\n\n const setActive = (on: boolean): void => {\n if (on === active) return;\n active = on;\n onActiveChange?.(on);\n };\n\n const wake = (): void => {\n woken = true;\n if (stop) return;\n stop = loop.repeat(phase, tick);\n setActive(true);\n };\n\n /** Draw every item that changed, then hand the batch over once. */\n function writeBatch(): void {\n if (!onDraw || dirty.size === 0) return;\n const batch: DrawEntry[] = [];\n for (const id of dirty) {\n const entry = drawers.get(id)?.();\n if (entry) batch.push(entry);\n }\n dirty.clear();\n if (batch.length > 0) onDraw(batch);\n }\n\n function tick(frame: FrameInfo): boolean {\n let moving = woken;\n woken = false;\n ticking = true;\n for (const task of [...tasks]) if (task(frame)) moving = true;\n for (const step of [...steps.values()]) if (step(frame.delta)) moving = true;\n writeBatch();\n ticking = false;\n for (const listener of [...frames]) listener(frame);\n if (moving || woken) return true;\n stop = null;\n setActive(false);\n const resolve = waiters;\n waiters = [];\n for (const r of resolve) r();\n for (const listener of [...idles]) listener();\n return false;\n }\n\n function add(id: string, drawable: Drawable, at: Rect, opts: { readonly shown?: boolean } = {}): LayoutItem {\n if (items.has(id)) throw new Error(`layout motion: item \"${id}\" is already added (remove it first)`);\n const rect: Settle<Rect> = createSettle<Rect>(copy(at), { omega });\n // A number from 0 to 1: rest within a thousandth, not the default tenth (tuned for pixels).\n const pop: Settle<number> = createSettle(opts.shown === false ? 0 : 1, { omega, restDelta: 0.001 });\n let box = copy(at);\n const frameOf = (): DrawFrame => {\n const drawn = rect.value;\n return { drawn, box, reveal: reveal(drawn, box), pop: popIn(pop.value, popFrom), shown: pop.value, gone: pop.settled && pop.value === 0 };\n };\n const drawNow = (): DrawEntry => {\n const frame = frameOf();\n drawable.draw(frame);\n return { id, frame };\n };\n // Batched: mark it changed (the batch draws it); a change between frames asks for a frame to draw it in.\n const draw = (): void => {\n if (!onDraw) {\n drawNow();\n return;\n }\n dirty.add(id);\n if (!ticking) wake();\n };\n const layOut = (to: Rect): void => {\n box = copy(to);\n drawable.layOut(box);\n };\n /** Head for `to`: a settle from the drawn rect, or (reduced motion) there at once. */\n const aim = (to: Rect): void => {\n if (reduced()) {\n rect.jumpTo(copy(to));\n draw();\n return;\n }\n rect.setTarget(copy(to));\n wake();\n };\n /** It moved on the last step (so the step that brings it to rest still draws it, batched). */\n let moved = false;\n const tempo = (): void => {\n rect.configure({ omega });\n pop.configure({ omega });\n };\n const item: LayoutItem = {\n id,\n get drawn() {\n return rect.value;\n },\n get target() {\n return rect.target;\n },\n get box() {\n return box;\n },\n get settled() {\n return rect.settled;\n },\n get shown() {\n return pop.value;\n },\n get showing() {\n return pop.target === 1;\n },\n get shownSettled() {\n return pop.settled;\n },\n moveTo(to) {\n if (same(box, to) && same(rect.target, to)) return;\n layOut(to);\n // Laid out in the new box now: draw it at once at the drawn rect, else until the next frame it would show\n // the old offset from the new box (a dropped item would flash a frame away from where it was let go).\n draw();\n if (same(rect.target, to)) return;\n aim(to);\n },\n retarget(to) {\n if (to.width !== box.width || to.height !== box.height) {\n item.moveTo(to);\n return;\n }\n if (same(rect.target, to)) return;\n aim(to);\n },\n jumpTo(to) {\n layOut(to);\n rect.jumpTo(copy(to));\n draw();\n },\n glideFrom(from, to) {\n rect.jumpTo(copy(from));\n layOut(to);\n draw();\n aim(to);\n },\n hold(r) {\n rect.hold(copy(r));\n draw();\n },\n show(on, o = {}) {\n const want = on ? 1 : 0;\n if (o.now || reduced()) pop.jumpTo(want);\n else if (pop.target !== want) {\n pop.setTarget(want);\n wake();\n }\n draw();\n },\n redraw: draw,\n };\n drawers.set(id, drawNow);\n drawable.layOut(box);\n draw();\n items.set(id, item);\n tempos.add(tempo);\n steps.set(id, (dt) => {\n const a = rect.step(dt);\n const b = pop.step(dt);\n // Batched, only an item that moved is drawn; else every item, every frame.\n if (!onDraw || a || b || moved) draw();\n moved = a || b;\n return a || b;\n });\n removers.set(id, () => {\n tempos.delete(tempo);\n drawers.delete(id);\n dirty.delete(id);\n });\n return item;\n }\n\n function remove(id: string): void {\n items.delete(id);\n steps.delete(id);\n removers.get(id)?.();\n removers.delete(id);\n }\n\n return {\n add,\n get: (id) => items.get(id),\n remove,\n retain(ids) {\n const keep = new Set(ids);\n for (const id of [...items.keys()]) if (!keep.has(id)) remove(id);\n },\n flush: writeBatch,\n items,\n task(task) {\n tasks.add(task);\n wake();\n return () => tasks.delete(task);\n },\n onFrame(listener) {\n frames.add(listener);\n return () => frames.delete(listener);\n },\n onIdle(listener) {\n idles.add(listener);\n return () => idles.delete(listener);\n },\n wake,\n get running() {\n return stop !== null;\n },\n configure(config) {\n if (config.omega !== undefined) omega = config.omega;\n for (const t of tempos) t();\n },\n idle: () => (stop ? new Promise<void>((r) => waiters.push(r)) : Promise.resolve()),\n dispose() {\n stop?.();\n stop = null;\n setActive(false);\n items.clear();\n steps.clear();\n drawers.clear();\n dirty.clear();\n tasks.clear();\n frames.clear();\n idles.clear();\n tempos.clear();\n removers.clear();\n const resolve = waiters;\n waiters = [];\n for (const r of resolve) r();\n },\n };\n}\n","import type { Point, Rect } from \"../shapes\";\nimport type { LayoutItem } from \"./motion\";\n\n/**\n * An item held by a pointer: the real item (no copy) follows the pointer 1:1 from where it was grabbed, at the size\n * it was lifted at; its place stays reserved (that is the caller's layout). Then:\n *\n * - {@link HeldDrag.snapTo}: glide into a slot (a snap preview); `null` leaves the slot and glides back to the\n * pointer, following it as it moves ({@link HeldDrag.follow} once a frame), until it is under it again.\n * - {@link HeldDrag.land}: let go into a slot: the landing settles from where it was let go (the release rect), never\n * from its old home. Snapped into that slot already, it simply finishes that glide.\n * - {@link HeldDrag.cancel}: let go with no drop: it glides home from where it was let go.\n * - {@link HeldDrag.preview}: the three drop previews, per frame: indicator and gap keep the item under the pointer\n * (gap with the caller's room open), snap glides it into the slot; leaving glides it back to the pointer.\n * - {@link HeldDrag.resize}: the item takes a new size mid-drag (its content laid out anew by the caller): it settles\n * to it from where it is drawn, the size revealed (never stretched), and is held 1:1 again once there.\n */\nexport interface HeldDrag {\n /** Where the pointer is (null before the first move). */\n readonly pointer: Point | null;\n /** Where the pointer holds the item: the pointer less the grab offset, at the held size (lifted, or resized). */\n readonly held: Rect | null;\n /** The slot it sits in (a snap), or null. */\n readonly snapped: Rect | null;\n /** It left a slot (or took a new size) and is gliding back to the pointer. */\n readonly returning: boolean;\n /** The pointer moved: held 1:1 (unless it sits in a slot or is on its way back). */\n move(pointer: Point): void;\n /**\n * Into `slot` (a glide from where it is drawn; the same slot again does nothing), or out of the slot it sits in\n * (`null`: back to the pointer). Returns what changed: `\"snapped\"`, `\"left\"`, or null.\n */\n snapTo(slot: Rect | null): \"snapped\" | \"left\" | null;\n /** Once a frame: on its way back, retarget to the pointer; true on the frame it is under the pointer again. */\n follow(): boolean;\n /**\n * Once a frame, a drop preview's part for the item (`plan`: `@n-uf/motion/drag`'s `previewPlan`, or any\n * `{ snapItem }`): with `snapItem` it glides into `slot` (snap); else it stays under the pointer, or glides back to\n * it from a slot it left (indicator, gap). The room, if the plan makes any, is the caller's layout. In place of\n * {@link HeldDrag.snapTo} and {@link HeldDrag.follow}; returns what changed.\n */\n preview(plan: { readonly snapItem: boolean }, slot: Rect | null): \"snapped\" | \"left\" | null;\n /**\n * Hold it at `size` from now on (the caller has laid its content out for that size). The grab point keeps its share\n * of the item, so the pointer stays on the same spot of it; the item settles from where it is drawn to its new held\n * rect (its size revealed, never stretched), then is held 1:1 again ({@link HeldDrag.follow} once a frame). In a\n * slot it stays there, taking the new size when it leaves. The same size again does nothing; returns true on a\n * change.\n */\n resize(size: { readonly width: number; readonly height: number }): boolean;\n /** Let go into `slot`: returns the release rect, where the landing starts. */\n land(slot: Rect): Rect;\n /** Let go with no drop: glides `home` from the release rect, which it returns. */\n cancel(home: Rect): Rect;\n}\n\n/** How close (px, every component) the way back has to come to count as under the pointer again. */\nconst CAUGHT = 0.5;\n\n/** Hold `item` from the pointer at `grab` (the pointer's offset from its top-left corner), at its drawn size now. */\nexport function holdItem(item: LayoutItem, grab: Point): HeldDrag {\n let size = { width: item.drawn.width, height: item.drawn.height };\n let at = { x: grab.x, y: grab.y };\n let pointer: Point | null = null;\n let snapped: Rect | null = null;\n let returning = false;\n const heldRect = (): Rect | null => (pointer ? { x: pointer.x - at.x, y: pointer.y - at.y, width: size.width, height: size.height } : null);\n const same = (a: Rect, b: Rect): boolean => 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;\n const snapTo = (slot: Rect | null): \"snapped\" | \"left\" | null => {\n if (slot) {\n if (snapped && same(snapped, slot)) return null;\n snapped = { ...slot };\n returning = false;\n item.moveTo(slot);\n return \"snapped\";\n }\n if (!snapped) return null;\n snapped = null;\n returning = true;\n return \"left\";\n };\n const follow = (): boolean => {\n const goal = heldRect();\n if (!returning || !goal) return false;\n // A chase of the pointer: retargeted every frame, laid out again only when its size changes (an item without\n // retarget, from before it or a test double, moves to it).\n if (item.retarget) item.retarget(goal);\n else item.moveTo(goal);\n const d = item.drawn;\n 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;\n returning = false;\n item.hold(goal);\n return true;\n };\n const letGo = (to: Rect): Rect => {\n const release = { ...item.drawn };\n snapped = null;\n returning = false;\n item.moveTo(to);\n return release;\n };\n return {\n get pointer() {\n return pointer;\n },\n get held() {\n return heldRect();\n },\n get snapped() {\n return snapped;\n },\n get returning() {\n return returning;\n },\n move(p) {\n pointer = { x: p.x, y: p.y };\n if (snapped || returning) return;\n item.hold(heldRect()!);\n },\n snapTo,\n follow,\n preview(plan, slot) {\n const change = snapTo(plan.snapItem && slot ? slot : null);\n follow();\n return change;\n },\n resize(next) {\n if (Math.abs(next.width - size.width) < 0.01 && Math.abs(next.height - size.height) < 0.01) return false;\n at = { x: size.width ? (at.x / size.width) * next.width : 0, y: size.height ? (at.y / size.height) * next.height : 0 };\n size = { width: next.width, height: next.height };\n if (!snapped && pointer) {\n returning = true;\n follow();\n }\n return true;\n },\n land: letGo,\n cancel: letGo,\n };\n}\n","import type { Point, Rect } from \"../shapes\";\nimport { createSettle, SETTLE_TEMPO, type SettleConfig } from \"../values/settle\";\n\n/** A width and a height, px. */\nexport interface BoxSize {\n readonly width: number;\n readonly height: number;\n}\n\n/**\n * A box held at a point that changes size about an anchor: the anchor is the spot of the box that sits on the point\n * (a pointer's offset from the box's top-left corner). Its size and its anchor settle together to a new size and the\n * new box's anchor ({@link AnchoredMorph.to}), from wherever they are drawn, so a retarget mid-flight turns at once,\n * with no jump and no overshoot. At every step the anchor lies exactly on the point ({@link AnchoredMorph.rectAt}): a\n * caller who draws the old and the new content each with its own anchor on the point never moves either from under\n * the pointer, and fades between them by {@link AnchoredMorph.progress}.\n */\nexport interface AnchoredMorph {\n /** The size now. */\n readonly size: BoxSize;\n /** The anchor now: its offset from the box's top-left corner. */\n readonly anchor: Point;\n /** Where it is heading. */\n readonly target: { readonly size: BoxSize; readonly anchor: Point };\n /** At rest on the target. */\n readonly settled: boolean;\n /**\n * How far along the way from where the last retarget started to the target, 0 to 1 (1 at rest): to fade the content\n * it came from out and the target's in.\n */\n readonly progress: number;\n /** Head for `size` with `anchor` from where it is drawn. The same target again does nothing; true on a change. */\n to(size: BoxSize, anchor: Point): boolean;\n /** Be at `size` with `anchor` now, at rest. */\n jumpTo(size: BoxSize, anchor: Point): void;\n /** Advance by `dtMs` milliseconds; true while still moving. */\n step(dtMs: number): boolean;\n /** The box now with its anchor on `point`. */\n rectAt(point: Point): Rect;\n}\n\n/**\n * The default tempo, a quick settle (`SETTLE_TEMPO.quick`): 90 % of the way in about 60 ms, within 1 % in about\n * 125 ms; the last pixels take longer for large size changes (a 300 px change rests after about 225 ms).\n */\nexport const MORPH_TEMPO = SETTLE_TEMPO.quick;\n\n/** A box of `size` held at `anchor`, at rest; `config` is the settle's (default tempo {@link MORPH_TEMPO}). */\nexport function anchoredMorph(size: BoxSize, anchor: Point, config: SettleConfig = {}): AnchoredMorph {\n // One settle over the four numbers, as a rect: x, y the anchor, width and height the size.\n const pack = (s: BoxSize, a: Point): Rect => ({ x: finite(a.x), y: finite(a.y), width: Math.max(0, finite(s.width)), height: Math.max(0, finite(s.height)) });\n const settle = createSettle<Rect>(pack(size, anchor), { omega: MORPH_TEMPO, ...config });\n let from: Rect = settle.value;\n const gap = (a: Rect, b: Rect): number => 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));\n return {\n get size() {\n const v = settle.value;\n return { width: v.width, height: v.height };\n },\n get anchor() {\n const v = settle.value;\n return { x: v.x, y: v.y };\n },\n get target() {\n const t = settle.target;\n return { size: { width: t.width, height: t.height }, anchor: { x: t.x, y: t.y } };\n },\n get settled() {\n return settle.settled;\n },\n get progress() {\n const whole = gap(from, settle.target);\n if (settle.settled || whole < 1e-9) return 1;\n return Math.min(1, Math.max(0, 1 - gap(settle.value, settle.target) / whole));\n },\n to(s, a) {\n const goal = pack(s, a);\n if (gap(goal, settle.target) < 0.01) return false;\n from = settle.value;\n settle.setTarget(goal);\n return true;\n },\n jumpTo(s, a) {\n settle.jumpTo(pack(s, a));\n from = settle.value;\n },\n step(dt) {\n return settle.step(dt);\n },\n rectAt(p) {\n const v = settle.value;\n return { x: p.x - v.x, y: p.y - v.y, width: v.width, height: v.height };\n },\n };\n}\n\nconst finite = (v: number): number => (Number.isFinite(v) ? v : 0);\n","import type { Rect } from \"../shapes\";\nimport type { LayoutItem } from \"./motion\";\n\n/** A rect as a DOM rect reports it (`getBoundingClientRect()`): left, top, width, height. */\nexport interface RectLike {\n readonly left: number;\n readonly top: number;\n readonly width: number;\n readonly height: number;\n}\n\n/** Anything that can say where it is drawn: a DOM node, or a test's stand-in. */\nexport interface Measurable {\n getBoundingClientRect(): RectLike;\n}\n\n/** A {@link RectLike} as a {@link Rect}. */\nexport const rectOf = (r: RectLike): Rect => ({ x: r.left, y: r.top, width: r.width, height: r.height });\n\n/** One member of a {@link flip}: an item, the node it draws, and where it goes once the DOM has changed. */\nexport interface FlipEntry {\n readonly item: LayoutItem;\n readonly node: Measurable;\n /**\n * Once the DOM has changed: the old rect (as measured before, in page coordinates) in the item's own coordinates\n * now, and its new place there.\n */\n readonly place: (before: Rect) => { readonly from: Rect; readonly to: Rect };\n}\n\n/**\n * FLIP for DOM groups, on settle: record where each node is drawn (first), change the DOM (`change`: move nodes to\n * other parents, reorder them), then each item is drawn at its old rect and settles to its new place (last, invert,\n * play). No transform tween: a settle from the rect it was drawn at, so it never jumps or overshoots, and its size\n * changes through reveal.\n */\nexport function flip(entries: readonly FlipEntry[], change: () => void): void {\n const before = entries.map((e) => rectOf(e.node.getBoundingClientRect()));\n change();\n entries.forEach((e, i) => {\n const { from, to } = e.place(before[i]!);\n e.item.glideFrom(from, to);\n });\n}\n","import type { Rect } from \"../shapes\";\nimport type { Drawable, DrawFrame } from \"./motion\";\n\n/**\n * The style properties the layout motion writes, as strings (a DOM node's `style` has them all). Structural: the\n * library needs no DOM types.\n */\nexport interface StyleLike {\n left: string;\n top: string;\n width: string;\n height: string;\n transform: string;\n opacity: string;\n clipPath: string;\n visibility: string;\n}\n\n/** Something with a writable {@link StyleLike} `style`: a DOM node. */\nexport interface Styled {\n readonly style: StyleLike;\n}\n\n/**\n * The nodes of a drawn box: `node` is laid out at the box and moved to the drawn rect; `frame` (background, border,\n * shadow) is drawn at the drawn size; `content` is clipped to it. With no `frame` and `content`, `node` itself is\n * clipped (its content laid out at the box, never stretched).\n */\nexport interface BoxNodes {\n readonly node: Styled;\n readonly frame?: Styled;\n readonly content?: Styled;\n}\n\n/** Lay `node` out at `box`: its position and size, in its offset parent's coordinates. */\nexport function layOutBox(node: Styled, box: Rect): void {\n const s = node.style;\n s.left = `${box.x}px`;\n s.top = `${box.y}px`;\n s.width = `${box.width}px`;\n s.height = `${box.height}px`;\n}\n\n/**\n * Draw one frame of a box laid out by {@link layOutBox}: one transform (the move to the drawn rect, and the uniform\n * appearance about its centre), the frame at the drawn size, the content clipped (reveal); hidden when gone.\n */\nexport function drawBox(nodes: BoxNodes, frame: DrawFrame): void {\n const { reveal: r, pop } = frame;\n const cx = frame.drawn.width / 2;\n const cy = frame.drawn.height / 2;\n const s = nodes.node.style;\n s.transform =\n 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)`;\n s.opacity = pop.opacity === 1 ? \"\" : String(pop.opacity);\n if (nodes.frame) {\n nodes.frame.style.width = `${r.width}px`;\n nodes.frame.style.height = `${r.height}px`;\n }\n const clipped = nodes.content ?? (nodes.frame ? null : nodes.node);\n if (clipped) clipped.style.clipPath = r.clipRight || r.clipBottom ? `inset(0 ${r.clipRight}px ${r.clipBottom}px 0)` : \"\";\n // All the way gone: out of sight and out of the way of the pointer.\n s.visibility = frame.gone ? \"hidden\" : \"\";\n}\n\n/** A {@link Drawable} for DOM nodes: {@link layOutBox} on a new box, {@link drawBox} on every frame. */\nexport function domDrawable(nodes: BoxNodes): Drawable {\n return {\n layOut: (box) => layOutBox(nodes.node, box),\n draw: (frame) => drawBox(nodes, frame),\n };\n}\n"],"mappings":";;;;;;;;AA+JA,IAAM,OAAO,CAAC,GAAS,MACrB,KAAK,IAAI,EAAE,IAAI,EAAE,CAAC,IAAI,QAAQ,KAAK,IAAI,EAAE,IAAI,EAAE,CAAC,IAAI,QAAQ,KAAK,IAAI,EAAE,QAAQ,EAAE,KAAK,IAAI,QAAQ,KAAK,IAAI,EAAE,SAAS,EAAE,MAAM,IAAI;AACpI,IAAM,OAAO,CAAC,OAAmB,EAAE,GAAG,EAAE,GAAG,GAAG,EAAE,GAAG,OAAO,EAAE,OAAO,QAAQ,EAAE,OAAO;AAG7E,SAAS,mBAAmB,SAA4C;AAC7E,QAAM,EAAE,KAAK,IAAI;AACjB,QAAM,QAAQ,QAAQ,SA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A,IAAI,UAAU,IAAI,aAAa,EAAE,EAAE,OAAO,EAAE,EAAE,QAAQ,aAAa,EAAE,EAAE,OAAO,EAAE,EAAE,iBAAiB,EAAE,OAAO,EAAE,aAAa,IAAI,KAAK,eAAe,CAAC,EAAE,OAAO,CAAC,EAAE;AAClK,IAAE,UAAU,IAAI,YAAY,IAAI,KAAK,OAAO,IAAI,OAAO;AACvD,MAAI,MAAM,OAAO;AACf,UAAM,MAAM,MAAM,QAAQ,GAAG,EAAE,KAAK;AACpC,UAAM,MAAM,MAAM,SAAS,GAAG,EAAE,MAAM;AAAA,EACxC;AACA,QAAM,UAAU,MAAM,YAAY,MAAM,QAAQ,OAAO,MAAM;AAC7D,MAAI,QAAS,SAAQ,MAAM,WAAW,EAAE,aAAa,EAAE,aAAa,WAAW,EAAE,SAAS,MAAM,EAAE,UAAU,UAAU;AAEtH,IAAE,aAAa,MAAM,OAAO,WAAW;AACzC;AAGO,SAAS,YAAY,OAA2B;AACrD,SAAO;AAAA,IACL,QAAQ,CAAC,QAAQ,UAAU,MAAM,MAAM,GAAG;AAAA,IAC1C,MAAM,CAAC,UAAU,QAAQ,OAAO,KAAK;AAAA,EACvC;AACF;","names":["same"]}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { A as Animatable, W as Widen, R as Rect } from './shapes-EbQlwbCu.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* What springs and tweens have in common. An animator holds a value, a target
|
|
5
|
+
* and a velocity, and moves when it is stepped; it knows nothing about frames
|
|
6
|
+
* or clocks. `motionValue` steps one on a frame loop.
|
|
7
|
+
*/
|
|
8
|
+
interface Animator<T> {
|
|
9
|
+
/** The current value: a fresh plain value after every change. */
|
|
10
|
+
readonly value: T;
|
|
11
|
+
/** The current velocity in units per second, same shape as the value. */
|
|
12
|
+
readonly velocity: T;
|
|
13
|
+
/** Where the value is heading. */
|
|
14
|
+
readonly target: T;
|
|
15
|
+
/** At rest on the target. */
|
|
16
|
+
readonly settled: boolean;
|
|
17
|
+
/** Head for `target` from where the value is now. */
|
|
18
|
+
setTarget(target: T): void;
|
|
19
|
+
/** Set the velocity (units per second), e.g. a gesture's release velocity. Tweens ignore it. */
|
|
20
|
+
setVelocity?(velocity: T): void;
|
|
21
|
+
/** Put the value at `value`, make it the target, and stop. */
|
|
22
|
+
jumpTo(value: T): void;
|
|
23
|
+
/** Put the value on the target and stop. */
|
|
24
|
+
snap(): void;
|
|
25
|
+
/** Advance by `dtMs` milliseconds. Returns `true` while still moving. */
|
|
26
|
+
step(dtMs: number): boolean;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Tempos for {@link createSettle}, in 1/s: a settle covers 90 % of the way in
|
|
31
|
+
* ln(10)/omega seconds and is within 1 % in twice that.
|
|
32
|
+
*
|
|
33
|
+
* - `calm` 20: 90 % in 115 ms, done in 230 ms.
|
|
34
|
+
* - `default` 25: 90 % in 92 ms, done in 184 ms.
|
|
35
|
+
* - `quick` 37: 90 % in 62 ms, done in 124 ms (a fast Hyprland setup).
|
|
36
|
+
*/
|
|
37
|
+
declare const SETTLE_TEMPO: {
|
|
38
|
+
readonly calm: 20;
|
|
39
|
+
readonly default: 25;
|
|
40
|
+
readonly quick: 37;
|
|
41
|
+
};
|
|
42
|
+
/** Settings of {@link createSettle}. */
|
|
43
|
+
interface SettleConfig {
|
|
44
|
+
/** The tempo in 1/s (see {@link SETTLE_TEMPO}). Higher is faster. Default 25. */
|
|
45
|
+
readonly omega?: number;
|
|
46
|
+
/** Distance from the target that counts as arrived. Default 0.1 (tuned for pixels). */
|
|
47
|
+
readonly restDelta?: number;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* The one curve for things that move to a new place: a window's rect between
|
|
51
|
+
* layout targets, a drawer, a camera. Fast at the start, gentle at the end,
|
|
52
|
+
* and it never passes its target.
|
|
53
|
+
*
|
|
54
|
+
* It is a critically damped spring (stiffness omega², damping 2·omega) with
|
|
55
|
+
* one rule on its velocity, per component:
|
|
56
|
+
*
|
|
57
|
+
* - **Launch.** On a new target, each component gets the velocity
|
|
58
|
+
* omega · distance toward it, from wherever it is drawn: standing still,
|
|
59
|
+
* moving toward it, or moving away (it turns at once rather than drifting
|
|
60
|
+
* further first). From there the spring follows `distance · e^(−omega·t)`
|
|
61
|
+
* exactly: most of the move happens at once, the rest eases in.
|
|
62
|
+
* - **Clamp.** That speed is also the most it may have toward the target, so a
|
|
63
|
+
* velocity set by hand (`setVelocity`, a fling) toward the target is capped
|
|
64
|
+
* there instead of shooting past.
|
|
65
|
+
* - **Carry.** A velocity set by hand away from the target is kept, and the
|
|
66
|
+
* value turns around; a critically damped spring turning around never
|
|
67
|
+
* crosses the target either.
|
|
68
|
+
*
|
|
69
|
+
* So after a new target every component goes straight from where it is drawn
|
|
70
|
+
* to the target and never past it: no overshoot on position, no wobble on
|
|
71
|
+
* size, whatever the retargets. A new target starts from the drawn value,
|
|
72
|
+
* never from the old start.
|
|
73
|
+
*
|
|
74
|
+
* Holding (a pointer owns the value): call `hold(value)` on each move. The
|
|
75
|
+
* value sits exactly there, at rest; the next `setTarget` launches from it.
|
|
76
|
+
*/
|
|
77
|
+
interface Settle<T> extends Animator<T> {
|
|
78
|
+
/** The tempo in 1/s. */
|
|
79
|
+
readonly omega: number;
|
|
80
|
+
/** Put the value at `value`, at rest, with it as the target: a held value follows its owner 1:1. Same as `jumpTo`. */
|
|
81
|
+
hold(value: T): void;
|
|
82
|
+
/** Set the velocity (units per second); a component moving toward the target is clamped as in the launch rule. */
|
|
83
|
+
setVelocity(velocity: T): void;
|
|
84
|
+
/** Change the tempo or rest distance mid-flight; the value and velocity carry on, re-clamped. */
|
|
85
|
+
configure(config: SettleConfig): void;
|
|
86
|
+
}
|
|
87
|
+
/** Defaults of {@link SettleConfig}. */
|
|
88
|
+
declare const SETTLE_DEFAULTS: {
|
|
89
|
+
readonly omega: 25;
|
|
90
|
+
readonly restDelta: 0.1;
|
|
91
|
+
};
|
|
92
|
+
/**
|
|
93
|
+
* A settle starting at rest on `initial` (a number, a vector, a point or a
|
|
94
|
+
* rect; targets and velocities must have the same shape). See {@link Settle}.
|
|
95
|
+
*/
|
|
96
|
+
declare function createSettle<T extends Animatable>(initial: T, config?: SettleConfig): Settle<Widen<T>>;
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* How to draw a window whose rect is gliding without stretching its content.
|
|
100
|
+
*
|
|
101
|
+
* The content is laid out once at the target size and never scaled. The
|
|
102
|
+
* window's element sits at its target in the layout; to draw it at the
|
|
103
|
+
* gliding rect:
|
|
104
|
+
*
|
|
105
|
+
* - move the element by (`dx`, `dy`), so its top-left corner is the drawn rect's;
|
|
106
|
+
* - draw the frame (background, border, shadow) at `width` × `height`: the drawn size;
|
|
107
|
+
* - clip the content by `clipRight` and `clipBottom` so it fits a frame
|
|
108
|
+
* smaller than the target (CSS: `clip-path: inset(0 clipRight clipBottom 0)`).
|
|
109
|
+
*
|
|
110
|
+
* A window that shrinks shows a band of its own background closing in at the
|
|
111
|
+
* right and bottom; one that grows reveals content already laid out at its
|
|
112
|
+
* new size. Text is never stretched. One transform and one clip per frame, no
|
|
113
|
+
* layout per frame.
|
|
114
|
+
*/
|
|
115
|
+
interface RevealFrame {
|
|
116
|
+
/** Move the element (laid out at the target) right by this much. */
|
|
117
|
+
readonly dx: number;
|
|
118
|
+
/** Move the element (laid out at the target) down by this much. */
|
|
119
|
+
readonly dy: number;
|
|
120
|
+
/** The frame's width: the drawn rect's. */
|
|
121
|
+
readonly width: number;
|
|
122
|
+
/** The frame's height: the drawn rect's. */
|
|
123
|
+
readonly height: number;
|
|
124
|
+
/** Clip this much off the content's right edge (0 when the frame is at least as wide as the target). */
|
|
125
|
+
readonly clipRight: number;
|
|
126
|
+
/** Clip this much off the content's bottom edge (0 when the frame is at least as tall as the target). */
|
|
127
|
+
readonly clipBottom: number;
|
|
128
|
+
}
|
|
129
|
+
/** The {@link RevealFrame} for content laid out at `target` and drawn at `drawn`. */
|
|
130
|
+
declare function reveal(drawn: Rect, target: Rect): RevealFrame;
|
|
131
|
+
/** A uniform pop-in (or pop-out, run backwards): scale about the centre and opacity. */
|
|
132
|
+
interface PopIn {
|
|
133
|
+
/** Scale about the window's centre: the same on both axes, so nothing is stretched. */
|
|
134
|
+
readonly scale: number;
|
|
135
|
+
readonly opacity: number;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Opening and closing: the window grows from `from` of its size to full, about
|
|
139
|
+
* its centre, while fading in. `progress` runs 0 to 1 (take it from a settle
|
|
140
|
+
* on a number with `{ restDelta: 0.001 }`, since the default 0.1 is tuned for
|
|
141
|
+
* pixels and would snap the last 10 %; or from a tween); closing runs it from
|
|
142
|
+
* 1 to 0. Hyprland's default is `popin 87%`.
|
|
143
|
+
*/
|
|
144
|
+
declare function popIn(progress: number, from?: number): PopIn;
|
|
145
|
+
|
|
146
|
+
export { type Animator as A, type PopIn as P, type RevealFrame as R, SETTLE_DEFAULTS as S, SETTLE_TEMPO as a, type Settle as b, type SettleConfig as c, createSettle as d, popIn as p, reveal as r };
|
package/dist/values.d.ts
CHANGED
|
@@ -1,35 +1,10 @@
|
|
|
1
|
+
import { A as Animator, c as SettleConfig, b as Settle } from './reveal-CywgKUWx.js';
|
|
2
|
+
export { P as PopIn, R as RevealFrame, S as SETTLE_DEFAULTS, a as SETTLE_TEMPO, d as createSettle, p as popIn, r as reveal } from './reveal-CywgKUWx.js';
|
|
1
3
|
import { A as Animatable, W as Widen } from './shapes-EbQlwbCu.js';
|
|
2
|
-
export { P as PopIn, R as RevealFrame, p as popIn, r as reveal } from './reveal-my7U6UyE.js';
|
|
3
4
|
import { e as Phase, a as FrameLoop } from './frame-loop-C88dc9xw.js';
|
|
4
5
|
import { ReadonlySignal } from './signals.js';
|
|
5
6
|
import './port-CmlUctqx.js';
|
|
6
7
|
|
|
7
|
-
/**
|
|
8
|
-
* What springs and tweens have in common. An animator holds a value, a target
|
|
9
|
-
* and a velocity, and moves when it is stepped; it knows nothing about frames
|
|
10
|
-
* or clocks. `motionValue` steps one on a frame loop.
|
|
11
|
-
*/
|
|
12
|
-
interface Animator<T> {
|
|
13
|
-
/** The current value: a fresh plain value after every change. */
|
|
14
|
-
readonly value: T;
|
|
15
|
-
/** The current velocity in units per second, same shape as the value. */
|
|
16
|
-
readonly velocity: T;
|
|
17
|
-
/** Where the value is heading. */
|
|
18
|
-
readonly target: T;
|
|
19
|
-
/** At rest on the target. */
|
|
20
|
-
readonly settled: boolean;
|
|
21
|
-
/** Head for `target` from where the value is now. */
|
|
22
|
-
setTarget(target: T): void;
|
|
23
|
-
/** Set the velocity (units per second), e.g. a gesture's release velocity. Tweens ignore it. */
|
|
24
|
-
setVelocity?(velocity: T): void;
|
|
25
|
-
/** Put the value at `value`, make it the target, and stop. */
|
|
26
|
-
jumpTo(value: T): void;
|
|
27
|
-
/** Put the value on the target and stop. */
|
|
28
|
-
snap(): void;
|
|
29
|
-
/** Advance by `dtMs` milliseconds. Returns `true` while still moving. */
|
|
30
|
-
step(dtMs: number): boolean;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
8
|
/** Maps progress in [0, 1] to eased progress (0 at 0, 1 at 1). */
|
|
34
9
|
type Easing = (progress: number) => number;
|
|
35
10
|
/** No easing. */
|
|
@@ -134,75 +109,6 @@ interface Tween<T> extends Animator<T> {
|
|
|
134
109
|
*/
|
|
135
110
|
declare function createTween<T extends Animatable>(initial: T, config?: TweenConfig): Tween<Widen<T>>;
|
|
136
111
|
|
|
137
|
-
/**
|
|
138
|
-
* Tempos for {@link createSettle}, in 1/s: a settle covers 90 % of the way in
|
|
139
|
-
* ln(10)/omega seconds and is within 1 % in twice that.
|
|
140
|
-
*
|
|
141
|
-
* - `calm` 20: 90 % in 115 ms, done in 230 ms.
|
|
142
|
-
* - `default` 25: 90 % in 92 ms, done in 184 ms.
|
|
143
|
-
* - `quick` 37: 90 % in 62 ms, done in 124 ms (a fast Hyprland setup).
|
|
144
|
-
*/
|
|
145
|
-
declare const SETTLE_TEMPO: {
|
|
146
|
-
readonly calm: 20;
|
|
147
|
-
readonly default: 25;
|
|
148
|
-
readonly quick: 37;
|
|
149
|
-
};
|
|
150
|
-
/** Settings of {@link createSettle}. */
|
|
151
|
-
interface SettleConfig {
|
|
152
|
-
/** The tempo in 1/s (see {@link SETTLE_TEMPO}). Higher is faster. Default 25. */
|
|
153
|
-
readonly omega?: number;
|
|
154
|
-
/** Distance from the target that counts as arrived. Default 0.1 (tuned for pixels). */
|
|
155
|
-
readonly restDelta?: number;
|
|
156
|
-
}
|
|
157
|
-
/**
|
|
158
|
-
* The one curve for things that move to a new place: a window's rect between
|
|
159
|
-
* layout targets, a drawer, a camera. Fast at the start, gentle at the end,
|
|
160
|
-
* and it never passes its target.
|
|
161
|
-
*
|
|
162
|
-
* It is a critically damped spring (stiffness omega², damping 2·omega) with
|
|
163
|
-
* one rule on its velocity, per component:
|
|
164
|
-
*
|
|
165
|
-
* - **Launch.** On a new target, each component gets the velocity
|
|
166
|
-
* omega · distance toward it, from wherever it is drawn: standing still,
|
|
167
|
-
* moving toward it, or moving away (it turns at once rather than drifting
|
|
168
|
-
* further first). From there the spring follows `distance · e^(−omega·t)`
|
|
169
|
-
* exactly: most of the move happens at once, the rest eases in.
|
|
170
|
-
* - **Clamp.** That speed is also the most it may have toward the target, so a
|
|
171
|
-
* velocity set by hand (`setVelocity`, a fling) toward the target is capped
|
|
172
|
-
* there instead of shooting past.
|
|
173
|
-
* - **Carry.** A velocity set by hand away from the target is kept, and the
|
|
174
|
-
* value turns around; a critically damped spring turning around never
|
|
175
|
-
* crosses the target either.
|
|
176
|
-
*
|
|
177
|
-
* So after a new target every component goes straight from where it is drawn
|
|
178
|
-
* to the target and never past it: no overshoot on position, no wobble on
|
|
179
|
-
* size, whatever the retargets. A new target starts from the drawn value,
|
|
180
|
-
* never from the old start.
|
|
181
|
-
*
|
|
182
|
-
* Holding (a pointer owns the value): call `hold(value)` on each move. The
|
|
183
|
-
* value sits exactly there, at rest; the next `setTarget` launches from it.
|
|
184
|
-
*/
|
|
185
|
-
interface Settle<T> extends Animator<T> {
|
|
186
|
-
/** The tempo in 1/s. */
|
|
187
|
-
readonly omega: number;
|
|
188
|
-
/** Put the value at `value`, at rest, with it as the target: a held value follows its owner 1:1. Same as `jumpTo`. */
|
|
189
|
-
hold(value: T): void;
|
|
190
|
-
/** Set the velocity (units per second); a component moving toward the target is clamped as in the launch rule. */
|
|
191
|
-
setVelocity(velocity: T): void;
|
|
192
|
-
/** Change the tempo or rest distance mid-flight; the value and velocity carry on, re-clamped. */
|
|
193
|
-
configure(config: SettleConfig): void;
|
|
194
|
-
}
|
|
195
|
-
/** Defaults of {@link SettleConfig}. */
|
|
196
|
-
declare const SETTLE_DEFAULTS: {
|
|
197
|
-
readonly omega: 25;
|
|
198
|
-
readonly restDelta: 0.1;
|
|
199
|
-
};
|
|
200
|
-
/**
|
|
201
|
-
* A settle starting at rest on `initial` (a number, a vector, a point or a
|
|
202
|
-
* rect; targets and velocities must have the same shape). See {@link Settle}.
|
|
203
|
-
*/
|
|
204
|
-
declare function createSettle<T extends Animatable>(initial: T, config?: SettleConfig): Settle<Widen<T>>;
|
|
205
|
-
|
|
206
112
|
/** Options of {@link motionValue}. */
|
|
207
113
|
interface MotionOptions {
|
|
208
114
|
/**
|
|
@@ -274,4 +180,4 @@ declare function settleValue<T extends Animatable>(loop: FrameLoop, initial: T,
|
|
|
274
180
|
/** A tween-driven {@link MotionValue}: `createTween` plus `motionValue`. */
|
|
275
181
|
declare function tweenValue<T extends Animatable>(loop: FrameLoop, initial: T, options?: TweenConfig & MotionOptions): MotionValue<Widen<T>, Tween<Widen<T>>>;
|
|
276
182
|
|
|
277
|
-
export {
|
|
183
|
+
export { Animator, type AnimatorValue, type Easing, type MotionOptions, type MotionValue, SPRING_DEFAULTS, type SetOptions, Settle, SettleConfig, type Spring, type SpringConfig, type SpringParams, type SpringState, type Tween, type TweenConfig, createSpring, createTween, cubicBezier, ease, easeIn, easeInOut, easeInOutCubic, easeOut, easeOutCubic, linear, motionValue, resolveSpring, settleValue, springStep, springValue, tweenValue };
|
package/package.json
CHANGED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { R as Rect } from './shapes-EbQlwbCu.js';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* How to draw a window whose rect is gliding without stretching its content.
|
|
5
|
-
*
|
|
6
|
-
* The content is laid out once at the target size and never scaled. The
|
|
7
|
-
* window's element sits at its target in the layout; to draw it at the
|
|
8
|
-
* gliding rect:
|
|
9
|
-
*
|
|
10
|
-
* - move the element by (`dx`, `dy`), so its top-left corner is the drawn rect's;
|
|
11
|
-
* - draw the frame (background, border, shadow) at `width` × `height`: the drawn size;
|
|
12
|
-
* - clip the content by `clipRight` and `clipBottom` so it fits a frame
|
|
13
|
-
* smaller than the target (CSS: `clip-path: inset(0 clipRight clipBottom 0)`).
|
|
14
|
-
*
|
|
15
|
-
* A window that shrinks shows a band of its own background closing in at the
|
|
16
|
-
* right and bottom; one that grows reveals content already laid out at its
|
|
17
|
-
* new size. Text is never stretched. One transform and one clip per frame, no
|
|
18
|
-
* layout per frame.
|
|
19
|
-
*/
|
|
20
|
-
interface RevealFrame {
|
|
21
|
-
/** Move the element (laid out at the target) right by this much. */
|
|
22
|
-
readonly dx: number;
|
|
23
|
-
/** Move the element (laid out at the target) down by this much. */
|
|
24
|
-
readonly dy: number;
|
|
25
|
-
/** The frame's width: the drawn rect's. */
|
|
26
|
-
readonly width: number;
|
|
27
|
-
/** The frame's height: the drawn rect's. */
|
|
28
|
-
readonly height: number;
|
|
29
|
-
/** Clip this much off the content's right edge (0 when the frame is at least as wide as the target). */
|
|
30
|
-
readonly clipRight: number;
|
|
31
|
-
/** Clip this much off the content's bottom edge (0 when the frame is at least as tall as the target). */
|
|
32
|
-
readonly clipBottom: number;
|
|
33
|
-
}
|
|
34
|
-
/** The {@link RevealFrame} for content laid out at `target` and drawn at `drawn`. */
|
|
35
|
-
declare function reveal(drawn: Rect, target: Rect): RevealFrame;
|
|
36
|
-
/** A uniform pop-in (or pop-out, run backwards): scale about the centre and opacity. */
|
|
37
|
-
interface PopIn {
|
|
38
|
-
/** Scale about the window's centre: the same on both axes, so nothing is stretched. */
|
|
39
|
-
readonly scale: number;
|
|
40
|
-
readonly opacity: number;
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Opening and closing: the window grows from `from` of its size to full, about
|
|
44
|
-
* its centre, while fading in. `progress` runs 0 to 1 (take it from a settle
|
|
45
|
-
* on a number with `{ restDelta: 0.001 }`, since the default 0.1 is tuned for
|
|
46
|
-
* pixels and would snap the last 10 %; or from a tween); closing runs it from
|
|
47
|
-
* 1 to 0. Hyprland's default is `popin 87%`.
|
|
48
|
-
*/
|
|
49
|
-
declare function popIn(progress: number, from?: number): PopIn;
|
|
50
|
-
|
|
51
|
-
export { type PopIn as P, type RevealFrame as R, popIn as p, reveal as r };
|