vireuikit 0.1.0
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/LICENSE +202 -0
- package/NOTICE +11 -0
- package/README.md +81 -0
- package/dist/chunk-ZFX2MLKK.js +635 -0
- package/dist/chunk-ZFX2MLKK.js.map +1 -0
- package/dist/dynamics-BqBoj03x.d.cts +160 -0
- package/dist/dynamics-BqBoj03x.d.ts +160 -0
- package/dist/index.cjs +874 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +181 -0
- package/dist/index.d.ts +181 -0
- package/dist/index.js +188 -0
- package/dist/index.js.map +1 -0
- package/dist/web/index.cjs +967 -0
- package/dist/web/index.cjs.map +1 -0
- package/dist/web/index.d.cts +91 -0
- package/dist/web/index.d.ts +91 -0
- package/dist/web/index.js +443 -0
- package/dist/web/index.js.map +1 -0
- package/package.json +76 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
export { LINEAR_TO_LMS, LMS_TO_LINEAR, LMS_TO_OKLAB, MEDIUM_COMPOSITE_SHADER, MEDIUM_CONDENSATE_CORRECT_SHADER, MEDIUM_CONDENSATE_FORWARD_SHADER, MEDIUM_CONDENSATE_REACT_SHADER, MEDIUM_DEFAULTS, MEDIUM_DEFAULT_CELL_PX, MEDIUM_DRIFT_TURBULENCE, MEDIUM_EMISSION_BEATS, MEDIUM_EMISSION_PROBABILITY, MEDIUM_EMIT_SHADER, MEDIUM_MIN_EMISSION_INTERVAL, MEDIUM_NATURAL_INTERVAL, MEDIUM_NATURAL_JITTER, MEDIUM_PLAYING_TURBULENCE_RANGE, MEDIUM_PROBE_FLOOR_PX, MEDIUM_RESAMPLE_SHADER, MEDIUM_SEED_SHADER, MEDIUM_SENSITIVE_BOTTOM, MEDIUM_SENSITIVE_TOP, MEDIUM_SPECIES_HUE_SPREAD, MEDIUM_SPECIES_LIGHTNESS, MEDIUM_TIME_PERIOD, MEDIUM_TRACK_ADVECT_SHADER, MEDIUM_TRACK_PRESETS, MEDIUM_TURBULENCE_TAU, MEDIUM_VAPOR_CORRECT_SHADER, MEDIUM_VAPOR_FORWARD_SHADER, MEDIUM_VAPOR_REACT_SHADER, OKLAB_TO_LMS, VG_CURL_NOISE, VG_OKLAB_TO_SRGB, VG_VALUE_NOISE, characterOf, createMediumDynamics, neutralSpecies, oklabToSrgb, speciesFamily, srgbToOklab } from './chunk-ZFX2MLKK.js';
|
|
2
|
+
import { activeMaterial, halfMinDp } from 'vireglass';
|
|
3
|
+
|
|
4
|
+
var ATOM_AT_REST = {
|
|
5
|
+
pressed: 0,
|
|
6
|
+
hovered: 0,
|
|
7
|
+
selected: 0,
|
|
8
|
+
disabled: false
|
|
9
|
+
};
|
|
10
|
+
function atomLift(kind) {
|
|
11
|
+
switch (kind) {
|
|
12
|
+
case "iconButton":
|
|
13
|
+
case "switch":
|
|
14
|
+
case "slider":
|
|
15
|
+
return 1;
|
|
16
|
+
default:
|
|
17
|
+
return 0;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
var DISABLED_PRESENCE = 0.25;
|
|
21
|
+
var HOVER_GAIN = 0.35;
|
|
22
|
+
function atomMaterial(base, kind, state = ATOM_AT_REST) {
|
|
23
|
+
const clamp = (v) => v < 0 ? 0 : v > 1 ? 1 : v;
|
|
24
|
+
const on = Math.max(clamp(state.selected), clamp(state.pressed), clamp(state.hovered) * HOVER_GAIN);
|
|
25
|
+
const out = activeMaterial(base, state.disabled ? 0 : on);
|
|
26
|
+
if (!state.disabled) return out;
|
|
27
|
+
return { ...out, presence: out.presence * DISABLED_PRESENCE };
|
|
28
|
+
}
|
|
29
|
+
function atomAtRest(state) {
|
|
30
|
+
return state.pressed === 0 && state.hovered === 0 && state.selected === 0 && state.disabled === false;
|
|
31
|
+
}
|
|
32
|
+
function stepSpring(s, dt, response, damping, instant = false) {
|
|
33
|
+
if (instant) {
|
|
34
|
+
const moved = s.x !== s.target || s.v !== 0;
|
|
35
|
+
s.x = s.target;
|
|
36
|
+
s.v = 0;
|
|
37
|
+
return moved;
|
|
38
|
+
}
|
|
39
|
+
const stiffness = (2 * Math.PI / response) ** 2;
|
|
40
|
+
const friction = 4 * Math.PI * damping / response;
|
|
41
|
+
const h = 1 / 240;
|
|
42
|
+
for (let left = Math.min(dt, 0.05); left > 0; left -= h) {
|
|
43
|
+
const step = Math.min(left, h);
|
|
44
|
+
s.v += (stiffness * (s.target - s.x) - friction * s.v) * step;
|
|
45
|
+
s.x += s.v * step;
|
|
46
|
+
}
|
|
47
|
+
if (Math.abs(s.target - s.x) < 1e-3 && Math.abs(s.v) < 0.01) {
|
|
48
|
+
s.x = s.target;
|
|
49
|
+
s.v = 0;
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
var smoothstep = (e0, e1, x) => {
|
|
55
|
+
const t = Math.min(Math.max((x - e0) / (e1 - e0), 0), 1);
|
|
56
|
+
return t * t * (3 - 2 * t);
|
|
57
|
+
};
|
|
58
|
+
var mix = (a, b, t) => a + (b - a) * t;
|
|
59
|
+
var DROP_DIAMETER = 1.1;
|
|
60
|
+
var DROP_LIFT = 0.5;
|
|
61
|
+
var NECK_GAIN = 0.3;
|
|
62
|
+
var NECK_RAMP = 4;
|
|
63
|
+
var CORNER_EASE_START = 0.55;
|
|
64
|
+
var INK_OUT_END = 0.4;
|
|
65
|
+
var INK_IN_START = 0.45;
|
|
66
|
+
var INK_IN_END = 0.95;
|
|
67
|
+
function growthInk(phase) {
|
|
68
|
+
const a = Math.min(Math.max(phase.shrink, 0), 1);
|
|
69
|
+
const b = Math.max(phase.grow, 0);
|
|
70
|
+
return {
|
|
71
|
+
outgoing: 1 - smoothstep(0, INK_OUT_END, a),
|
|
72
|
+
incoming: smoothstep(INK_IN_START, INK_IN_END, b)
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
function largerOf(a, b) {
|
|
76
|
+
return halfMinDp(a.geometry) >= halfMinDp(b.geometry) ? { main: a, other: b } : { main: b, other: a };
|
|
77
|
+
}
|
|
78
|
+
function growthFrame(source, target, anchor, phase) {
|
|
79
|
+
const dx = target.center.x - source.center.x;
|
|
80
|
+
const dy = target.center.y - source.center.y;
|
|
81
|
+
const len = Math.hypot(dx, dy) || 1;
|
|
82
|
+
const sourceSize = halfMinDp(source.geometry) * 2;
|
|
83
|
+
const lift = DROP_LIFT * sourceSize;
|
|
84
|
+
const drop = {
|
|
85
|
+
x: source.center.x + dx / len * lift,
|
|
86
|
+
y: source.center.y + dy / len * lift
|
|
87
|
+
};
|
|
88
|
+
const a = Math.min(Math.max(phase.shrink, 0), 1);
|
|
89
|
+
const b = Math.max(phase.grow, 0);
|
|
90
|
+
const keep = Math.max(1 - b, 0);
|
|
91
|
+
const d = DROP_DIAMETER * sourceSize;
|
|
92
|
+
const shrunkGeometry = {
|
|
93
|
+
width: mix(source.geometry.width, 0.6 * d, a) * keep,
|
|
94
|
+
height: mix(source.geometry.height, 0.6 * d, a) * keep,
|
|
95
|
+
cornerRadius: 0
|
|
96
|
+
};
|
|
97
|
+
shrunkGeometry.cornerRadius = Math.min(
|
|
98
|
+
mix(source.geometry.cornerRadius, halfMinDp(shrunkGeometry), a),
|
|
99
|
+
halfMinDp(shrunkGeometry)
|
|
100
|
+
);
|
|
101
|
+
const shrunk = {
|
|
102
|
+
geometry: shrunkGeometry,
|
|
103
|
+
center: { x: mix(source.center.x, drop.x, a), y: mix(source.center.y, drop.y, a) }
|
|
104
|
+
};
|
|
105
|
+
const seed = d * Math.sqrt(a);
|
|
106
|
+
const cornerX = Math.sign(anchor.x - source.center.x);
|
|
107
|
+
const cornerY = Math.sign(anchor.y - source.center.y);
|
|
108
|
+
const edgeX = mix(drop.x + cornerX * (seed / 2), anchor.x, Math.min(b, 1));
|
|
109
|
+
const edgeY = mix(drop.y + cornerY * (seed / 2), anchor.y, Math.min(b, 1));
|
|
110
|
+
const width = mix(seed, target.geometry.width, b);
|
|
111
|
+
const height = mix(seed, target.geometry.height, b);
|
|
112
|
+
const grownGeometry = { width, height, cornerRadius: 0 };
|
|
113
|
+
grownGeometry.cornerRadius = Math.min(
|
|
114
|
+
mix(halfMinDp(grownGeometry), target.geometry.cornerRadius, smoothstep(CORNER_EASE_START, 1, b)),
|
|
115
|
+
halfMinDp(grownGeometry)
|
|
116
|
+
);
|
|
117
|
+
const grown = {
|
|
118
|
+
geometry: grownGeometry,
|
|
119
|
+
center: { x: edgeX - cornerX * (width / 2), y: edgeY - cornerY * (height / 2) }
|
|
120
|
+
};
|
|
121
|
+
const { main, other } = largerOf(grown, shrunk);
|
|
122
|
+
const neck = NECK_GAIN * sourceSize * Math.min(a * NECK_RAMP, 1) * keep;
|
|
123
|
+
const united = neck > 0.01 && other.geometry.width > 0.5 && other.geometry.height > 0.5;
|
|
124
|
+
return {
|
|
125
|
+
body: main,
|
|
126
|
+
grown,
|
|
127
|
+
merge: united ? {
|
|
128
|
+
offsetX: other.center.x - main.center.x,
|
|
129
|
+
offsetY: other.center.y - main.center.y,
|
|
130
|
+
width: other.geometry.width,
|
|
131
|
+
height: other.geometry.height,
|
|
132
|
+
cornerRadius: other.geometry.cornerRadius,
|
|
133
|
+
smoothing: neck
|
|
134
|
+
} : void 0,
|
|
135
|
+
ink: growthInk(phase)
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
var createGrowthState = () => ({
|
|
139
|
+
shrink: { x: 0, v: 0, target: 0 },
|
|
140
|
+
grow: { x: 0, v: 0, target: 0 }
|
|
141
|
+
});
|
|
142
|
+
var growthPhase = (state) => ({
|
|
143
|
+
shrink: state.shrink.x,
|
|
144
|
+
grow: state.grow.x
|
|
145
|
+
});
|
|
146
|
+
var DEFAULT_GROWTH_TIMING = {
|
|
147
|
+
shrinkOpen: 0.38,
|
|
148
|
+
shrinkClose: 0.3,
|
|
149
|
+
growOpen: 0.46,
|
|
150
|
+
growClose: 0.4,
|
|
151
|
+
growDampingOpen: 0.72
|
|
152
|
+
};
|
|
153
|
+
var GROW_DAMPING_CLOSE = 1;
|
|
154
|
+
var SHRINK_DAMPING = 1;
|
|
155
|
+
var GROW_STARTS_AT = 0.8;
|
|
156
|
+
var SHRINK_RETURNS_AT = 0.12;
|
|
157
|
+
function stepGrowth(state, dt, open, reduceMotion = false, timing = DEFAULT_GROWTH_TIMING) {
|
|
158
|
+
const { shrink, grow } = state;
|
|
159
|
+
if (reduceMotion) {
|
|
160
|
+
shrink.target = open ? 1 : 0;
|
|
161
|
+
grow.target = open ? 1 : 0;
|
|
162
|
+
} else if (open) {
|
|
163
|
+
shrink.target = 1;
|
|
164
|
+
if (shrink.x > GROW_STARTS_AT) grow.target = 1;
|
|
165
|
+
} else {
|
|
166
|
+
grow.target = 0;
|
|
167
|
+
if (grow.x < SHRINK_RETURNS_AT) shrink.target = 0;
|
|
168
|
+
}
|
|
169
|
+
const movedShrink = stepSpring(
|
|
170
|
+
shrink,
|
|
171
|
+
dt,
|
|
172
|
+
open ? timing.shrinkOpen : timing.shrinkClose,
|
|
173
|
+
SHRINK_DAMPING,
|
|
174
|
+
reduceMotion
|
|
175
|
+
);
|
|
176
|
+
const movedGrow = stepSpring(
|
|
177
|
+
grow,
|
|
178
|
+
dt,
|
|
179
|
+
open ? timing.growOpen : timing.growClose,
|
|
180
|
+
open ? timing.growDampingOpen : GROW_DAMPING_CLOSE,
|
|
181
|
+
reduceMotion
|
|
182
|
+
);
|
|
183
|
+
return movedShrink || movedGrow;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
export { ATOM_AT_REST, DEFAULT_GROWTH_TIMING, atomAtRest, atomLift, atomMaterial, createGrowthState, growthFrame, growthInk, growthPhase, smoothstep, stepGrowth, stepSpring };
|
|
187
|
+
//# sourceMappingURL=index.js.map
|
|
188
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/kit/atom.ts","../src/kit/morph.ts"],"names":[],"mappings":";;;AAuBO,IAAM,YAAA,GAA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GAAI,CAAA;AAC3B,IAAA,IAAA,CAAK,MAAA,GAAS,OAAO,CAAA,GAAI,CAAA;AAAA,EAC3B,WAAW,IAAA,EAAM;AACf,IAAA,MAAA,CAAO,MAAA,GAAS,CAAA;AAChB,IAAA,IAAI,MAAA,CAAO,CAAA,GAAI,cAAA,EAAgB,IAAA,CAAK,MAAA,GAAS,CAAA;AAAA,EAC/C,CAAA,MAAO;AACL,IAAA,IAAA,CAAK,MAAA,GAAS,CAAA;AACd,IAAA,IAAI,IAAA,CAAK,CAAA,GAAI,iBAAA,EAAmB,MAAA,CAAO,MAAA,GAAS,CAAA;AAAA,EAClD;AACA,EAAA,MAAM,WAAA,GAAc,UAAA;AAAA,IAClB,MAAA;AAAA,IACA,EAAA;AAAA,IACA,IAAA,GAAO,MAAA,CAAO,UAAA,GAAa,MAAA,CAAO,WAAA;AAAA,IAClC,cAAA;AAAA,IACA;AAAA,GACF;AACA,EAAA,MAAM,SAAA,GAAY,UAAA;AAAA,IAChB,IAAA;AAAA,IACA,EAAA;AAAA,IACA,IAAA,GAAO,MAAA,CAAO,QAAA,GAAW,MAAA,CAAO,SAAA;AAAA,IAChC,IAAA,GAAO,OAAO,eAAA,GAAkB,kBAAA;AAAA,IAChC;AAAA,GACF;AACA,EAAA,OAAO,WAAA,IAAe,SAAA;AACxB","file":"index.js","sourcesContent":["// Atom states — shared across every client: the set of states, what they mean, and what they do\n// to the material. Sizes, layout and per-input idioms are client-specific and live elsewhere.\nimport { activeMaterial, type VireGlassMaterial } from 'vireglass';\n\nexport type VireUIKitAtomKind =\n | 'button'\n | 'iconButton'\n | 'switch'\n | 'slider'\n | 'segment'\n | 'chip'\n | 'field'\n | 'menu';\n\n/** Hover and focus don't exist everywhere: touch has neither. The atom accepts them, but has to\n * look complete at zero too — otherwise a touch client gets an unfinished look. */\nexport type VireUIKitAtomState = {\n pressed: number;\n hovered: number;\n selected: number;\n disabled: boolean;\n};\n\nexport const ATOM_AT_REST: VireUIKitAtomState = {\n pressed: 0,\n hovered: 0,\n selected: 0,\n disabled: false,\n};\n\n/**\n * Whether the piece lifts INTO the glass under press (1) or sinks into the backing (0).\n *\n * Lift isn't decoration: a small target has the finger covering it entirely, and an enlarged\n * transparent lens underneath is the only sign of a hit. A large target stays visible past the\n * finger, so it reads more naturally sinking toward the backing instead.\n */\nexport function atomLift(kind: VireUIKitAtomKind): number {\n switch (kind) {\n case 'iconButton':\n case 'switch':\n case 'slider':\n return 1;\n default:\n return 0;\n }\n}\n\n/** A disabled piece stays glass but stops asserting itself: the legibility requirement is lifted\n * and tint turns off. Hiding it via transparency won't do — the material is already transparent. */\nconst DISABLED_PRESENCE = 0.25;\n/** Hover is halfway to a press: the cursor is already on the target, but nothing is chosen yet. */\nconst HOVER_GAIN = 0.35;\n\n/**\n * The atom's material for a given state. Press and selection go through `activeMaterial` — for\n * glass, state is a change in the MEDIUM itself (denser, thicker, clearer), not a highlight\n * drawn over it.\n */\nexport function atomMaterial(\n base: VireGlassMaterial,\n kind: VireUIKitAtomKind,\n state: VireUIKitAtomState = ATOM_AT_REST,\n): VireGlassMaterial {\n const clamp = (v: number) => (v < 0 ? 0 : v > 1 ? 1 : v);\n const on = Math.max(clamp(state.selected), clamp(state.pressed), clamp(state.hovered) * HOVER_GAIN);\n const out = activeMaterial(base, state.disabled ? 0 : on);\n if (!state.disabled) return out;\n return { ...out, presence: out.presence * DISABLED_PRESENCE };\n}\n\n/** Whether every field on the atom matches rest — lets a client skip redraws for states its own\n * input can never produce (hover on touch, focus on Android). */\nexport function atomAtRest(state: VireUIKitAtomState): boolean {\n return (\n state.pressed === 0 && state.hovered === 0 && state.selected === 0 && state.disabled === false\n );\n}\n","// Two-phase \"capsule → drop → target\" growth: atom behavior, not layout. The body contracts into\n// a drop, a neck grows from its side toward the target, the drop grows into the target with a\n// slight overshoot; closing retraces the same path in reverse, because the model holds no\n// direction, only the current phase. Source and target sizes are layout, supplied as parameters.\nimport { halfMinDp, type VireGlassGeometry, type VireGlassMorph } from 'vireglass';\n\n/** A spring with `response`-second settle time; `damping` < 1 overshoots. `instant` skips\n * integration entirely, for reduced motion. */\nexport type Spring = { x: number; v: number; target: number };\n\nexport function stepSpring(\n s: Spring,\n dt: number,\n response: number,\n damping: number,\n instant = false,\n): boolean {\n if (instant) {\n const moved = s.x !== s.target || s.v !== 0;\n s.x = s.target;\n s.v = 0;\n return moved;\n }\n const stiffness = ((2 * Math.PI) / response) ** 2;\n const friction = (4 * Math.PI * damping) / response;\n const h = 1 / 240;\n // Fixed step, but not a fixed frame budget: without this, a rare slow frame hands the spring a\n // huge dt and it diverges.\n for (let left = Math.min(dt, 0.05); left > 0; left -= h) {\n const step = Math.min(left, h);\n s.v += (stiffness * (s.target - s.x) - friction * s.v) * step;\n s.x += s.v * step;\n }\n if (Math.abs(s.target - s.x) < 1e-3 && Math.abs(s.v) < 1e-2) {\n s.x = s.target;\n s.v = 0;\n return false;\n }\n return true;\n}\n\nexport const smoothstep = (e0: number, e1: number, x: number): number => {\n const t = Math.min(Math.max((x - e0) / (e1 - e0), 0), 1);\n return t * t * (3 - 2 * t);\n};\n\nconst mix = (a: number, b: number, t: number) => a + (b - a) * t;\n\nexport type GrowthPoint = { x: number; y: number };\n\n/** A shape and its position — it has no role of its own; `growthFrame` assigns the role (body, or\n * what the body is merging into). */\nexport type GrowthShape = { geometry: VireGlassGeometry; center: GrowthPoint };\n\n/** `shrink` — capsule → drop, no overshoot. `grow` — drop → target; may exceed 1 for the\n * overshoot. Both are read as-is; `stepGrowth` owns the bounds and the handoff between them. */\nexport type GrowthPhase = { shrink: number; grow: number };\n\nexport type GrowthInk = {\n /** 0…1: how much of the source's ink is still visible (1) vs. already defocused into the drop (0). */\n outgoing: number;\n /** 0…1: how much of the target's ink has come into focus (0 = not yet, 1 = fully). */\n incoming: number;\n};\n\nexport type GrowthFrame = {\n /** The shape worth drawing as glass right now: the larger of the two, which supplies the\n * thickness and the bevel. */\n body: GrowthShape;\n /** The target shape as-is, regardless of role — it drives the response to finger/light while\n * the glass hasn't become it yet (while `body` is still the drop). */\n grown: GrowthShape;\n /** The second merge shape, ready for `toLensProps`/`toSurfaceUniforms`; `undefined` while the\n * neck hasn't grown yet or has already retracted. */\n merge: VireGlassMorph | undefined;\n ink: GrowthInk;\n};\n\n/** The drop's size — a fraction of the source's diameter, with headroom for the neck. */\nconst DROP_DIAMETER = 1.1;\n/** How far the drop travels from the source toward the target, as a fraction of the source's diameter. */\nconst DROP_LIFT = 0.5;\nconst NECK_GAIN = 0.3;\nconst NECK_RAMP = 4;\nconst CORNER_EASE_START = 0.55;\nconst INK_OUT_END = 0.4;\nconst INK_IN_START = 0.45;\nconst INK_IN_END = 0.95;\n\nexport function growthInk(phase: GrowthPhase): GrowthInk {\n const a = Math.min(Math.max(phase.shrink, 0), 1);\n const b = Math.max(phase.grow, 0);\n // Ink leaves and arrives by going out of focus, not by plain transparency — the blur amount is\n // the drawer's job, this only reports the fraction of focus.\n return {\n outgoing: 1 - smoothstep(0, INK_OUT_END, a),\n incoming: smoothstep(INK_IN_START, INK_IN_END, b),\n };\n}\n\n/** The main shape is the larger one by half-size: it supplies the thickness and the bevel, so the\n * roles swap exactly at equal half-sizes, which is invisible on screen. */\nfunction largerOf(a: GrowthShape, b: GrowthShape): { main: GrowthShape; other: GrowthShape } {\n return halfMinDp(a.geometry) >= halfMinDp(b.geometry) ? { main: a, other: b } : { main: b, other: a };\n}\n\n/** `anchor` is the corner shared by source and target: the body pins to it, otherwise the target\n * would grow out of the drop's center instead of the button's corner. */\nexport function growthFrame(\n source: GrowthShape,\n target: GrowthShape,\n anchor: GrowthPoint,\n phase: GrowthPhase,\n): GrowthFrame {\n const dx = target.center.x - source.center.x;\n const dy = target.center.y - source.center.y;\n const len = Math.hypot(dx, dy) || 1;\n const sourceSize = halfMinDp(source.geometry) * 2;\n const lift = DROP_LIFT * sourceSize;\n const drop: GrowthPoint = {\n x: source.center.x + (dx / len) * lift,\n y: source.center.y + (dy / len) * lift,\n };\n\n const a = Math.min(Math.max(phase.shrink, 0), 1);\n const b = Math.max(phase.grow, 0);\n const keep = Math.max(1 - b, 0);\n const d = DROP_DIAMETER * sourceSize;\n\n const shrunkGeometry: VireGlassGeometry = {\n width: mix(source.geometry.width, 0.6 * d, a) * keep,\n height: mix(source.geometry.height, 0.6 * d, a) * keep,\n cornerRadius: 0,\n };\n // The source's radius EASES into the drop's rather than being replaced by it outright —\n // otherwise a field with a partial corner radius at rest would render as a full pill.\n shrunkGeometry.cornerRadius = Math.min(\n mix(source.geometry.cornerRadius, halfMinDp(shrunkGeometry), a),\n halfMinDp(shrunkGeometry),\n );\n const shrunk: GrowthShape = {\n geometry: shrunkGeometry,\n center: { x: mix(source.center.x, drop.x, a), y: mix(source.center.y, drop.y, a) },\n };\n\n const seed = d * Math.sqrt(a);\n // The sign of the corner the body pins to. Zero means the anchor sits on the same axis as the\n // source's center, so growth along that axis centers instead of hugging an edge.\n const cornerX = Math.sign(anchor.x - source.center.x);\n const cornerY = Math.sign(anchor.y - source.center.y);\n const edgeX = mix(drop.x + cornerX * (seed / 2), anchor.x, Math.min(b, 1));\n const edgeY = mix(drop.y + cornerY * (seed / 2), anchor.y, Math.min(b, 1));\n const width = mix(seed, target.geometry.width, b);\n const height = mix(seed, target.geometry.height, b);\n const grownGeometry: VireGlassGeometry = { width, height, cornerRadius: 0 };\n grownGeometry.cornerRadius = Math.min(\n mix(halfMinDp(grownGeometry), target.geometry.cornerRadius, smoothstep(CORNER_EASE_START, 1, b)),\n halfMinDp(grownGeometry),\n );\n const grown: GrowthShape = {\n geometry: grownGeometry,\n center: { x: edgeX - cornerX * (width / 2), y: edgeY - cornerY * (height / 2) },\n };\n\n const { main, other } = largerOf(grown, shrunk);\n const neck = NECK_GAIN * sourceSize * Math.min(a * NECK_RAMP, 1) * keep;\n const united = neck > 0.01 && other.geometry.width > 0.5 && other.geometry.height > 0.5;\n\n return {\n body: main,\n grown,\n merge: united\n ? {\n offsetX: other.center.x - main.center.x,\n offsetY: other.center.y - main.center.y,\n width: other.geometry.width,\n height: other.geometry.height,\n cornerRadius: other.geometry.cornerRadius,\n smoothing: neck,\n }\n : undefined,\n ink: growthInk(phase),\n };\n}\n\nexport type GrowthState = { shrink: Spring; grow: Spring };\n\nexport const createGrowthState = (): GrowthState => ({\n shrink: { x: 0, v: 0, target: 0 },\n grow: { x: 0, v: 0, target: 0 },\n});\n\nexport const growthPhase = (state: GrowthState): GrowthPhase => ({\n shrink: state.shrink.x,\n grow: state.grow.x,\n});\n\n/** Durations are client-specific: this set is tuned for the capsule-to-menu transition, and an\n * atom at a different scale (an icon opening into a sheet) isn't obligated to match it. The\n * shape of the transition is shared regardless. */\nexport type GrowthTiming = {\n shrinkOpen: number;\n shrinkClose: number;\n growOpen: number;\n growClose: number;\n /** < 1 gives the target a slight overshoot on open; closing never overshoots. */\n growDampingOpen: number;\n};\n\nexport const DEFAULT_GROWTH_TIMING: GrowthTiming = {\n shrinkOpen: 0.38,\n shrinkClose: 0.3,\n growOpen: 0.46,\n growClose: 0.4,\n growDampingOpen: 0.72,\n};\n\nconst GROW_DAMPING_CLOSE = 1;\nconst SHRINK_DAMPING = 1;\nconst GROW_STARTS_AT = 0.8;\nconst SHRINK_RETURNS_AT = 0.12;\n\n/** Growth starts once the drop has gathered, and the reverse on close. `reduceMotion` turns off\n * the spring entirely: both phases jump straight to their target in one step, with no overshoot\n * and no defocus phase. */\nexport function stepGrowth(\n state: GrowthState,\n dt: number,\n open: boolean,\n reduceMotion = false,\n timing: GrowthTiming = DEFAULT_GROWTH_TIMING,\n): boolean {\n const { shrink, grow } = state;\n if (reduceMotion) {\n shrink.target = open ? 1 : 0;\n grow.target = open ? 1 : 0;\n } else if (open) {\n shrink.target = 1;\n if (shrink.x > GROW_STARTS_AT) grow.target = 1;\n } else {\n grow.target = 0;\n if (grow.x < SHRINK_RETURNS_AT) shrink.target = 0;\n }\n const movedShrink = stepSpring(\n shrink,\n dt,\n open ? timing.shrinkOpen : timing.shrinkClose,\n SHRINK_DAMPING,\n reduceMotion,\n );\n const movedGrow = stepSpring(\n grow,\n dt,\n open ? timing.growOpen : timing.growClose,\n open ? timing.growDampingOpen : GROW_DAMPING_CLOSE,\n reduceMotion,\n );\n return movedShrink || movedGrow;\n}\n"]}
|