@sessile/presets 0.0.0-stage → 0.2.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 +373 -0
- package/dist/dragMerge.d.ts +114 -0
- package/dist/dragMerge.js +619 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +9 -0
- package/dist/popover.d.ts +252 -0
- package/dist/popover.js +1144 -0
- package/dist/segmented.d.ts +70 -0
- package/dist/segmented.js +396 -0
- package/package.json +33 -3
- package/README.md +0 -3
package/dist/popover.js
ADDED
|
@@ -0,0 +1,1144 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Morphing Popover / Menu preset for Sessile.
|
|
3
|
+
*
|
|
4
|
+
* Computes viewport-clamped placement, spring-coupled open/close/interrupt motion
|
|
5
|
+
* trajectories, synchronized platter/droplet SDF field geometry, and content/glyph
|
|
6
|
+
* transforms without host-specific CSS variable coupling.
|
|
7
|
+
*
|
|
8
|
+
* SPDX-License-Identifier: MPL-2.0
|
|
9
|
+
*/
|
|
10
|
+
import { DEFAULT_SPRINGS, clamp, computePairMergeStatus, cubicBezier, easeInOutCubic, easeInQuad, easeOutCubic, evaluateSpring, lerp, riseAndFall, smoothstep, } from '@sessile/core';
|
|
11
|
+
/** Default timing, geometry, and spring constants for morphing popovers and menus. */
|
|
12
|
+
export const POPOVER_MORPH_DEFAULTS = {
|
|
13
|
+
openDurationSec: 0.45,
|
|
14
|
+
closeDurationSec: 0.5,
|
|
15
|
+
pointCloseDurationSec: 0.2,
|
|
16
|
+
reducedMotionDurationSec: 0.15,
|
|
17
|
+
cornerDelaySec: 0.07,
|
|
18
|
+
dropletBlendK: 28,
|
|
19
|
+
mergeRimFadeDepth: 8,
|
|
20
|
+
itemRadius: 16,
|
|
21
|
+
panelInset: 8,
|
|
22
|
+
restingRadius: 24,
|
|
23
|
+
anchorOverlapY: 8,
|
|
24
|
+
avoidGap: 8,
|
|
25
|
+
screenMargin: 16,
|
|
26
|
+
bareAnchorInflateX: 12,
|
|
27
|
+
bareAnchorInflateY: 6,
|
|
28
|
+
bareSourceFadeInSec: 0.1,
|
|
29
|
+
minPlatterScaleRatio: 0.41,
|
|
30
|
+
dropletTargetScale: 0.25,
|
|
31
|
+
pointCloseEndScale: 0.8,
|
|
32
|
+
openCornerWidthFactor: 0.48,
|
|
33
|
+
closeBlendRampSec: 0.05,
|
|
34
|
+
closeRingingStartSec: 0.4,
|
|
35
|
+
closeRingingEndSec: 0.5,
|
|
36
|
+
closeContentOutSec: 0.1,
|
|
37
|
+
closeGlyphBackSec: 0.47,
|
|
38
|
+
closeAbsorptionStart: 0.6,
|
|
39
|
+
closeAbsorptionEnd: 0.9,
|
|
40
|
+
openSettledGlyphEnd: 0.25,
|
|
41
|
+
openGlyphBlurMaxPx: 4,
|
|
42
|
+
openContentBlurBasePx: 4,
|
|
43
|
+
closeContentBlurMaxPx: 8,
|
|
44
|
+
closeGlyphStartOpacity: 0.2,
|
|
45
|
+
openDipPeakSec: 0.098,
|
|
46
|
+
openDipSharpness: 3.3,
|
|
47
|
+
openDipBasePx: 23,
|
|
48
|
+
openDipDyScale: 0.124,
|
|
49
|
+
openDipDyCap: 30,
|
|
50
|
+
openBlurBumpPeakSec: 0.069,
|
|
51
|
+
openBlurBumpSharpness: 2.1,
|
|
52
|
+
openBlurBumpAmpPx: 1.9,
|
|
53
|
+
closePlatterDipPeakSec: 0.072,
|
|
54
|
+
closePlatterDipSharpness: 2.4,
|
|
55
|
+
closePlatterDipRatio: 0.21,
|
|
56
|
+
closePlatterDipCapPx: 22,
|
|
57
|
+
closeDropletOvershootPeakSec: 0.176,
|
|
58
|
+
closeDropletOvershootSharpness: 4.9,
|
|
59
|
+
closeDropletOvershootRatio: 0.25,
|
|
60
|
+
closeDropletOvershootCapPx: 19,
|
|
61
|
+
springs: {
|
|
62
|
+
open: DEFAULT_SPRINGS.standard,
|
|
63
|
+
corners: DEFAULT_SPRINGS.corners,
|
|
64
|
+
droplet: DEFAULT_SPRINGS.soft,
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
function lerpPoint(a, b, t) {
|
|
68
|
+
return {
|
|
69
|
+
x: lerp(a.x, b.x, t),
|
|
70
|
+
y: lerp(a.y, b.y, t),
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
function rectCenter(rect) {
|
|
74
|
+
return {
|
|
75
|
+
x: rect.x + rect.width * 0.5,
|
|
76
|
+
y: rect.y + rect.height * 0.5,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
function deflateRect(rect, inset) {
|
|
80
|
+
return {
|
|
81
|
+
x: rect.x + inset,
|
|
82
|
+
y: rect.y + inset,
|
|
83
|
+
width: rect.width - inset * 2,
|
|
84
|
+
height: rect.height - inset * 2,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
function clampPointToRect(point, rect) {
|
|
88
|
+
return {
|
|
89
|
+
x: clamp(point.x, rect.x, rect.x + rect.width),
|
|
90
|
+
y: clamp(point.y, rect.y, rect.y + rect.height),
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
function normalizeOrZero(v) {
|
|
94
|
+
const len = Math.hypot(v.x, v.y);
|
|
95
|
+
if (len <= 1e-5) {
|
|
96
|
+
return { dir: { x: 0, y: 0 }, len: 0 };
|
|
97
|
+
}
|
|
98
|
+
return { dir: { x: v.x / len, y: v.y / len }, len };
|
|
99
|
+
}
|
|
100
|
+
function beyondRound(size) {
|
|
101
|
+
return {
|
|
102
|
+
w: Math.max(0, size.width - size.height),
|
|
103
|
+
h: Math.max(0, size.height - size.width),
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
function externalTugEnvelope(progress) {
|
|
107
|
+
const u = clamp(progress, 0, 1);
|
|
108
|
+
if (u <= 0 || u >= 1)
|
|
109
|
+
return 0;
|
|
110
|
+
return Math.pow(u / 0.35, 1.4) * Math.pow((1 - u) / 0.65, 2.6);
|
|
111
|
+
}
|
|
112
|
+
function getEffectiveAnchorRect(anchor) {
|
|
113
|
+
const rect = anchor.anchorRect;
|
|
114
|
+
if (!anchor.bareSource || anchor.inflateBareAnchor === false) {
|
|
115
|
+
return rect;
|
|
116
|
+
}
|
|
117
|
+
const ix = POPOVER_MORPH_DEFAULTS.bareAnchorInflateX;
|
|
118
|
+
const iy = POPOVER_MORPH_DEFAULTS.bareAnchorInflateY;
|
|
119
|
+
return {
|
|
120
|
+
x: rect.x - ix,
|
|
121
|
+
y: rect.y - iy,
|
|
122
|
+
width: rect.width + ix * 2,
|
|
123
|
+
height: rect.height + iy * 2,
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
function resolveRestingRadius(panel) {
|
|
127
|
+
if (panel.restingRadius !== undefined) {
|
|
128
|
+
return panel.restingRadius;
|
|
129
|
+
}
|
|
130
|
+
if (panel.itemRadius !== undefined || panel.panelInset !== undefined) {
|
|
131
|
+
return ((panel.itemRadius ?? POPOVER_MORPH_DEFAULTS.itemRadius) +
|
|
132
|
+
(panel.panelInset ?? POPOVER_MORPH_DEFAULTS.panelInset));
|
|
133
|
+
}
|
|
134
|
+
return POPOVER_MORPH_DEFAULTS.restingRadius;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Computes the resting popover panel rect for the requested placement mode,
|
|
138
|
+
* flipping vertically when space is constrained and clamping inside `viewportSize`
|
|
139
|
+
* minus `screenMargin + safeInsets`.
|
|
140
|
+
*/
|
|
141
|
+
export function computePopoverTargetRect(anchor, panel) {
|
|
142
|
+
if (panel.targetRectOverride) {
|
|
143
|
+
return { ...panel.targetRectOverride };
|
|
144
|
+
}
|
|
145
|
+
const panelW = Math.max(0, panel.size.width);
|
|
146
|
+
const panelH = Math.max(0, panel.size.height);
|
|
147
|
+
const overlapY = panel.overlapY ?? POPOVER_MORPH_DEFAULTS.anchorOverlapY;
|
|
148
|
+
const avoidGap = panel.avoidGap ?? POPOVER_MORPH_DEFAULTS.avoidGap;
|
|
149
|
+
const screenMargin = panel.screenMargin ?? POPOVER_MORPH_DEFAULTS.screenMargin;
|
|
150
|
+
const safe = anchor.safeInsets ?? { top: 0, right: 0, bottom: 0, left: 0 };
|
|
151
|
+
const minX = screenMargin + safe.left;
|
|
152
|
+
const maxX = anchor.viewportSize.width - screenMargin - safe.right - panelW;
|
|
153
|
+
const minY = screenMargin + safe.top;
|
|
154
|
+
const maxBottom = anchor.viewportSize.height - screenMargin - safe.bottom;
|
|
155
|
+
const maxY = maxBottom - panelH;
|
|
156
|
+
const a = anchor.anchorRect;
|
|
157
|
+
let rawX = a.x;
|
|
158
|
+
let rawY = a.y;
|
|
159
|
+
if (anchor.placement === 'overAnchorEnd') {
|
|
160
|
+
rawX = a.x + a.width - panelW;
|
|
161
|
+
rawY = a.y - overlapY;
|
|
162
|
+
}
|
|
163
|
+
else if (anchor.placement === 'overAnchorStart') {
|
|
164
|
+
rawX = a.x;
|
|
165
|
+
rawY = a.y - overlapY;
|
|
166
|
+
}
|
|
167
|
+
else if (anchor.placement === 'abovePoint') {
|
|
168
|
+
rawX = a.x;
|
|
169
|
+
const refRect = anchor.avoidRect ?? a;
|
|
170
|
+
const aboveY = refRect.y - avoidGap - panelH;
|
|
171
|
+
const belowY = refRect.y + refRect.height + avoidGap;
|
|
172
|
+
if (aboveY >= minY) {
|
|
173
|
+
rawY = aboveY;
|
|
174
|
+
}
|
|
175
|
+
else {
|
|
176
|
+
const spaceAbove = refRect.y - avoidGap - minY;
|
|
177
|
+
const spaceBelow = maxBottom - belowY;
|
|
178
|
+
rawY = spaceBelow >= panelH || spaceBelow >= spaceAbove ? belowY : aboveY;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
rawX = a.x;
|
|
183
|
+
const refRect = anchor.avoidRect ?? a;
|
|
184
|
+
const belowY = refRect.y + refRect.height + avoidGap;
|
|
185
|
+
const aboveY = refRect.y - avoidGap - panelH;
|
|
186
|
+
if (belowY + panelH <= maxBottom) {
|
|
187
|
+
rawY = belowY;
|
|
188
|
+
}
|
|
189
|
+
else {
|
|
190
|
+
const spaceBelow = maxBottom - belowY;
|
|
191
|
+
const spaceAbove = refRect.y - avoidGap - minY;
|
|
192
|
+
rawY = spaceAbove >= panelH || spaceAbove >= spaceBelow ? aboveY : belowY;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
return {
|
|
196
|
+
x: clamp(rawX, minX, maxX),
|
|
197
|
+
y: clamp(rawY, minY, maxY),
|
|
198
|
+
width: panelW,
|
|
199
|
+
height: panelH,
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
/** Returns the transition duration in seconds for the given phase and capabilities. */
|
|
203
|
+
export function getPopoverPhaseDurationSec(phase, hasControlSource = true, reducedMotion = false) {
|
|
204
|
+
if (phase === 'closed' || phase === 'open') {
|
|
205
|
+
return 0;
|
|
206
|
+
}
|
|
207
|
+
if (reducedMotion) {
|
|
208
|
+
return POPOVER_MORPH_DEFAULTS.reducedMotionDurationSec;
|
|
209
|
+
}
|
|
210
|
+
if (phase === 'opening') {
|
|
211
|
+
return POPOVER_MORPH_DEFAULTS.openDurationSec;
|
|
212
|
+
}
|
|
213
|
+
return hasControlSource
|
|
214
|
+
? POPOVER_MORPH_DEFAULTS.closeDurationSec
|
|
215
|
+
: POPOVER_MORPH_DEFAULTS.pointCloseDurationSec;
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Pure deterministic motion evaluator for any popover phase and normalized progress in `[0, 1]`.
|
|
219
|
+
*/
|
|
220
|
+
export function evaluatePopoverMotion(phase, normalizedT, options = {}) {
|
|
221
|
+
const hasControlSource = options.hasControlSource ?? true;
|
|
222
|
+
const reducedMotion = options.reducedMotion ?? false;
|
|
223
|
+
const u = clamp(Number.isFinite(normalizedT) ? normalizedT : 0, 0, 1);
|
|
224
|
+
if (phase === 'closed') {
|
|
225
|
+
return {
|
|
226
|
+
phase: 'closed',
|
|
227
|
+
hasControlSource,
|
|
228
|
+
elapsedSec: 0,
|
|
229
|
+
normalizedT: 0,
|
|
230
|
+
morphProgress: 1,
|
|
231
|
+
cornerProgress: 1,
|
|
232
|
+
ringing: 0,
|
|
233
|
+
absorbed: 1,
|
|
234
|
+
closeBlendRamp: 1,
|
|
235
|
+
platterDipEnvelope: 0,
|
|
236
|
+
dropletOvershootEnvelope: 0,
|
|
237
|
+
blurBumpPx: 0,
|
|
238
|
+
settled: 0,
|
|
239
|
+
contentOpacity: 0,
|
|
240
|
+
contentBlurPx: 0,
|
|
241
|
+
triggerGlyphOpacity: 1,
|
|
242
|
+
triggerGlyphBlurPx: 0,
|
|
243
|
+
bareGlassOpacity: 0,
|
|
244
|
+
pointScale: 1,
|
|
245
|
+
isAnimating: false,
|
|
246
|
+
reducedMotion,
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
if (phase === 'open') {
|
|
250
|
+
return {
|
|
251
|
+
phase: 'open',
|
|
252
|
+
hasControlSource,
|
|
253
|
+
elapsedSec: getPopoverPhaseDurationSec('opening', hasControlSource, reducedMotion),
|
|
254
|
+
normalizedT: 1,
|
|
255
|
+
morphProgress: 1,
|
|
256
|
+
cornerProgress: 0,
|
|
257
|
+
ringing: 0,
|
|
258
|
+
absorbed: 0,
|
|
259
|
+
closeBlendRamp: 0,
|
|
260
|
+
platterDipEnvelope: 0,
|
|
261
|
+
dropletOvershootEnvelope: 0,
|
|
262
|
+
blurBumpPx: 0,
|
|
263
|
+
settled: 1,
|
|
264
|
+
contentOpacity: 1,
|
|
265
|
+
contentBlurPx: 0,
|
|
266
|
+
triggerGlyphOpacity: 0,
|
|
267
|
+
triggerGlyphBlurPx: reducedMotion ? 0 : POPOVER_MORPH_DEFAULTS.openGlyphBlurMaxPx,
|
|
268
|
+
bareGlassOpacity: 1,
|
|
269
|
+
pointScale: 1,
|
|
270
|
+
isAnimating: false,
|
|
271
|
+
reducedMotion,
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
if (phase === 'opening') {
|
|
275
|
+
const duration = getPopoverPhaseDurationSec('opening', hasControlSource, reducedMotion);
|
|
276
|
+
const elapsedSec = u * duration;
|
|
277
|
+
const interrupt = options.interruptStart;
|
|
278
|
+
if (reducedMotion) {
|
|
279
|
+
const fade = easeOutCubic(u);
|
|
280
|
+
let settled = fade;
|
|
281
|
+
let contentOpacity = fade;
|
|
282
|
+
let triggerGlyphOpacity = 1 - fade;
|
|
283
|
+
let bareGlassOpacity = fade;
|
|
284
|
+
if (interrupt) {
|
|
285
|
+
const startU = clamp(interrupt.startNormalizedT ?? 0, 0, 1 - 1e-6);
|
|
286
|
+
const remT = clamp((u - startU) / (1 - startU), 0, 1);
|
|
287
|
+
const ramp = easeOutCubic(remT);
|
|
288
|
+
settled = lerp(interrupt.startSettled ?? fade, 1, ramp);
|
|
289
|
+
contentOpacity = lerp(interrupt.contentOpacity ?? fade, 1, ramp);
|
|
290
|
+
triggerGlyphOpacity = lerp(interrupt.triggerGlyphOpacity ?? 1 - fade, 0, ramp);
|
|
291
|
+
bareGlassOpacity = lerp(interrupt.bareGlassOpacity ?? fade, 1, ramp);
|
|
292
|
+
}
|
|
293
|
+
return {
|
|
294
|
+
phase: 'opening',
|
|
295
|
+
hasControlSource,
|
|
296
|
+
elapsedSec,
|
|
297
|
+
normalizedT: u,
|
|
298
|
+
morphProgress: 1,
|
|
299
|
+
cornerProgress: 0,
|
|
300
|
+
ringing: 0,
|
|
301
|
+
absorbed: 0,
|
|
302
|
+
closeBlendRamp: 0,
|
|
303
|
+
platterDipEnvelope: 0,
|
|
304
|
+
dropletOvershootEnvelope: 0,
|
|
305
|
+
blurBumpPx: 0,
|
|
306
|
+
settled,
|
|
307
|
+
contentOpacity,
|
|
308
|
+
contentBlurPx: 0,
|
|
309
|
+
triggerGlyphOpacity,
|
|
310
|
+
triggerGlyphBlurPx: 0,
|
|
311
|
+
bareGlassOpacity,
|
|
312
|
+
pointScale: 1,
|
|
313
|
+
isAnimating: u < 1,
|
|
314
|
+
reducedMotion: true,
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
const morphProgress = evaluateSpring(elapsedSec, POPOVER_MORPH_DEFAULTS.springs.open);
|
|
318
|
+
const cornerDelay = POPOVER_MORPH_DEFAULTS.cornerDelaySec;
|
|
319
|
+
const cornerProgress = elapsedSec <= cornerDelay
|
|
320
|
+
? 1
|
|
321
|
+
: 1 - evaluateSpring(elapsedSec - cornerDelay, POPOVER_MORPH_DEFAULTS.springs.corners);
|
|
322
|
+
const platterDipEnvelope = hasControlSource
|
|
323
|
+
? riseAndFall(elapsedSec, POPOVER_MORPH_DEFAULTS.openDipPeakSec, POPOVER_MORPH_DEFAULTS.openDipSharpness)
|
|
324
|
+
: 0;
|
|
325
|
+
const blurBumpPx = POPOVER_MORPH_DEFAULTS.openBlurBumpAmpPx *
|
|
326
|
+
riseAndFall(elapsedSec, POPOVER_MORPH_DEFAULTS.openBlurBumpPeakSec, POPOVER_MORPH_DEFAULTS.openBlurBumpSharpness);
|
|
327
|
+
const settled = clamp(morphProgress, 0, 1);
|
|
328
|
+
const glyphT = clamp(settled / POPOVER_MORPH_DEFAULTS.openSettledGlyphEnd, 0, 1);
|
|
329
|
+
const normalContentBlurPx = Math.hypot(POPOVER_MORPH_DEFAULTS.openContentBlurBasePx * (1 - settled), blurBumpPx);
|
|
330
|
+
const normalBareGlassOpacity = clamp(elapsedSec / POPOVER_MORPH_DEFAULTS.bareSourceFadeInSec, 0, 1);
|
|
331
|
+
let contentOpacity = settled;
|
|
332
|
+
let contentBlurPx = normalContentBlurPx;
|
|
333
|
+
let triggerGlyphOpacity = 1 - glyphT;
|
|
334
|
+
let triggerGlyphBlurPx = POPOVER_MORPH_DEFAULTS.openGlyphBlurMaxPx * glyphT;
|
|
335
|
+
let bareGlassOpacity = normalBareGlassOpacity;
|
|
336
|
+
if (interrupt) {
|
|
337
|
+
const startSettled = clamp(interrupt.startSettled ?? 0, 0, 0.999);
|
|
338
|
+
const settledRamp = clamp((settled - startSettled) / (1 - startSettled), 0, 1);
|
|
339
|
+
contentOpacity = lerp(interrupt.contentOpacity ?? settled, 1, settledRamp);
|
|
340
|
+
contentBlurPx = lerp(interrupt.contentBlurPx ?? normalContentBlurPx, normalContentBlurPx, settledRamp);
|
|
341
|
+
const glyphSpan = Math.max(1e-4, Math.min(POPOVER_MORPH_DEFAULTS.openSettledGlyphEnd, 1 - startSettled));
|
|
342
|
+
const interruptGlyphT = clamp((settled - startSettled) / glyphSpan, 0, 1);
|
|
343
|
+
triggerGlyphOpacity = lerp(interrupt.triggerGlyphOpacity ?? 1, 0, interruptGlyphT);
|
|
344
|
+
triggerGlyphBlurPx = lerp(interrupt.triggerGlyphBlurPx ?? 0, POPOVER_MORPH_DEFAULTS.openGlyphBlurMaxPx, interruptGlyphT);
|
|
345
|
+
const startElapsedSec = clamp(interrupt.startNormalizedT ?? 0, 0, 1) * duration;
|
|
346
|
+
const bareRamp = clamp((elapsedSec - startElapsedSec) / POPOVER_MORPH_DEFAULTS.bareSourceFadeInSec, 0, 1);
|
|
347
|
+
bareGlassOpacity = lerp(interrupt.bareGlassOpacity ?? normalBareGlassOpacity, 1, bareRamp);
|
|
348
|
+
}
|
|
349
|
+
return {
|
|
350
|
+
phase: 'opening',
|
|
351
|
+
hasControlSource,
|
|
352
|
+
elapsedSec,
|
|
353
|
+
normalizedT: u,
|
|
354
|
+
morphProgress,
|
|
355
|
+
cornerProgress,
|
|
356
|
+
ringing: 0,
|
|
357
|
+
absorbed: 0,
|
|
358
|
+
closeBlendRamp: 0,
|
|
359
|
+
platterDipEnvelope,
|
|
360
|
+
dropletOvershootEnvelope: 0,
|
|
361
|
+
blurBumpPx,
|
|
362
|
+
settled,
|
|
363
|
+
contentOpacity,
|
|
364
|
+
contentBlurPx,
|
|
365
|
+
triggerGlyphOpacity,
|
|
366
|
+
triggerGlyphBlurPx,
|
|
367
|
+
bareGlassOpacity,
|
|
368
|
+
pointScale: 1,
|
|
369
|
+
isAnimating: u < 1,
|
|
370
|
+
reducedMotion: false,
|
|
371
|
+
reopenFrom: interrupt?.reopenFrom,
|
|
372
|
+
};
|
|
373
|
+
}
|
|
374
|
+
const duration = getPopoverPhaseDurationSec('closing', hasControlSource, reducedMotion);
|
|
375
|
+
const elapsedSec = u * duration;
|
|
376
|
+
const startContentOpacity = options.interruptStart?.contentOpacity ?? 1;
|
|
377
|
+
const startContentBlurPx = options.interruptStart?.contentBlurPx ?? 0;
|
|
378
|
+
const startBareGlassOpacity = options.interruptStart?.bareGlassOpacity ?? 1;
|
|
379
|
+
if (reducedMotion) {
|
|
380
|
+
const fade = easeOutCubic(u);
|
|
381
|
+
const startGlyphOpacity = options.interruptStart?.triggerGlyphOpacity ?? 0;
|
|
382
|
+
return {
|
|
383
|
+
phase: 'closing',
|
|
384
|
+
hasControlSource,
|
|
385
|
+
elapsedSec,
|
|
386
|
+
normalizedT: u,
|
|
387
|
+
morphProgress: 0,
|
|
388
|
+
cornerProgress: 0,
|
|
389
|
+
ringing: 0,
|
|
390
|
+
absorbed: 1,
|
|
391
|
+
closeBlendRamp: 0,
|
|
392
|
+
platterDipEnvelope: 0,
|
|
393
|
+
dropletOvershootEnvelope: 0,
|
|
394
|
+
blurBumpPx: 0,
|
|
395
|
+
settled: 1 - fade,
|
|
396
|
+
contentOpacity: startContentOpacity * (1 - fade),
|
|
397
|
+
contentBlurPx: 0,
|
|
398
|
+
triggerGlyphOpacity: lerp(startGlyphOpacity, 1, fade),
|
|
399
|
+
triggerGlyphBlurPx: 0,
|
|
400
|
+
bareGlassOpacity: startBareGlassOpacity * (1 - fade),
|
|
401
|
+
pointScale: 1,
|
|
402
|
+
isAnimating: u < 1,
|
|
403
|
+
reducedMotion: true,
|
|
404
|
+
};
|
|
405
|
+
}
|
|
406
|
+
if (!hasControlSource) {
|
|
407
|
+
const eased = easeOutCubic(u);
|
|
408
|
+
return {
|
|
409
|
+
phase: 'closing',
|
|
410
|
+
hasControlSource: false,
|
|
411
|
+
elapsedSec,
|
|
412
|
+
normalizedT: u,
|
|
413
|
+
morphProgress: eased,
|
|
414
|
+
cornerProgress: 0,
|
|
415
|
+
ringing: 0,
|
|
416
|
+
absorbed: eased,
|
|
417
|
+
closeBlendRamp: 0,
|
|
418
|
+
platterDipEnvelope: 0,
|
|
419
|
+
dropletOvershootEnvelope: 0,
|
|
420
|
+
blurBumpPx: 0,
|
|
421
|
+
settled: 1 - eased,
|
|
422
|
+
contentOpacity: startContentOpacity * (1 - eased),
|
|
423
|
+
contentBlurPx: 0,
|
|
424
|
+
triggerGlyphOpacity: 1,
|
|
425
|
+
triggerGlyphBlurPx: 0,
|
|
426
|
+
bareGlassOpacity: startBareGlassOpacity * (1 - eased),
|
|
427
|
+
pointScale: lerp(1, POPOVER_MORPH_DEFAULTS.pointCloseEndScale, eased),
|
|
428
|
+
isAnimating: u < 1,
|
|
429
|
+
reducedMotion: false,
|
|
430
|
+
};
|
|
431
|
+
}
|
|
432
|
+
const ringingSpan = POPOVER_MORPH_DEFAULTS.closeRingingEndSec - POPOVER_MORPH_DEFAULTS.closeRingingStartSec;
|
|
433
|
+
const ringing = 1 -
|
|
434
|
+
easeInQuad(clamp((elapsedSec - POPOVER_MORPH_DEFAULTS.closeRingingStartSec) / ringingSpan, 0, 1));
|
|
435
|
+
const dropletSpring = evaluateSpring(elapsedSec, POPOVER_MORPH_DEFAULTS.springs.droplet);
|
|
436
|
+
const morphProgress = 1 + (dropletSpring - 1) * ringing;
|
|
437
|
+
const closeBlendRamp = clamp(elapsedSec / POPOVER_MORPH_DEFAULTS.closeBlendRampSec, 0, 1);
|
|
438
|
+
const absStartSec = POPOVER_MORPH_DEFAULTS.closeAbsorptionStart * duration;
|
|
439
|
+
const absSpanSec = (POPOVER_MORPH_DEFAULTS.closeAbsorptionEnd - POPOVER_MORPH_DEFAULTS.closeAbsorptionStart) *
|
|
440
|
+
duration;
|
|
441
|
+
const absorbed = easeInOutCubic(clamp((elapsedSec - absStartSec) / absSpanSec, 0, 1));
|
|
442
|
+
const platterDipEnvelope = riseAndFall(elapsedSec, POPOVER_MORPH_DEFAULTS.closePlatterDipPeakSec, POPOVER_MORPH_DEFAULTS.closePlatterDipSharpness) * ringing;
|
|
443
|
+
const dropletOvershootEnvelope = riseAndFall(elapsedSec, POPOVER_MORPH_DEFAULTS.closeDropletOvershootPeakSec, POPOVER_MORPH_DEFAULTS.closeDropletOvershootSharpness) * ringing;
|
|
444
|
+
const contentOut = easeOutCubic(clamp(elapsedSec / POPOVER_MORPH_DEFAULTS.closeContentOutSec, 0, 1));
|
|
445
|
+
const startGlyphOpacity = options.interruptStart?.triggerGlyphOpacity ?? POPOVER_MORPH_DEFAULTS.closeGlyphStartOpacity;
|
|
446
|
+
const glyphCurveT = cubicBezier(0.25, 0.1, 0.25, 1, clamp(elapsedSec / POPOVER_MORPH_DEFAULTS.closeGlyphBackSec, 0, 1));
|
|
447
|
+
return {
|
|
448
|
+
phase: 'closing',
|
|
449
|
+
hasControlSource: true,
|
|
450
|
+
elapsedSec,
|
|
451
|
+
normalizedT: u,
|
|
452
|
+
morphProgress,
|
|
453
|
+
cornerProgress: 0,
|
|
454
|
+
ringing,
|
|
455
|
+
absorbed,
|
|
456
|
+
closeBlendRamp,
|
|
457
|
+
platterDipEnvelope,
|
|
458
|
+
dropletOvershootEnvelope,
|
|
459
|
+
blurBumpPx: 0,
|
|
460
|
+
settled: clamp(1 - morphProgress, 0, 1),
|
|
461
|
+
contentOpacity: startContentOpacity * (1 - contentOut),
|
|
462
|
+
contentBlurPx: lerp(startContentBlurPx, POPOVER_MORPH_DEFAULTS.closeContentBlurMaxPx, contentOut),
|
|
463
|
+
triggerGlyphOpacity: lerp(startGlyphOpacity, 1, glyphCurveT),
|
|
464
|
+
triggerGlyphBlurPx: 0,
|
|
465
|
+
bareGlassOpacity: startBareGlassOpacity * (1 - absorbed),
|
|
466
|
+
pointScale: 1,
|
|
467
|
+
isAnimating: u < 1,
|
|
468
|
+
reducedMotion: false,
|
|
469
|
+
};
|
|
470
|
+
}
|
|
471
|
+
function computeDropletRestingTarget(anchorCenter, panelCenter, targetRect, anchorLongest, blendK) {
|
|
472
|
+
const deflateInset = anchorLongest * 0.125 + blendK + POPOVER_MORPH_DEFAULTS.mergeRimFadeDepth;
|
|
473
|
+
const deflated = deflateRect(targetRect, deflateInset);
|
|
474
|
+
if (deflated.width <= 0 || deflated.height <= 0) {
|
|
475
|
+
return panelCenter;
|
|
476
|
+
}
|
|
477
|
+
const biasPoint = lerpPoint(anchorCenter, panelCenter, POPOVER_MORPH_DEFAULTS.dropletTargetScale);
|
|
478
|
+
return clampPointToRect(biasPoint, deflated);
|
|
479
|
+
}
|
|
480
|
+
function computeContentTransform(platter, targetRect) {
|
|
481
|
+
const panelCenter = rectCenter(targetRect);
|
|
482
|
+
const scale = targetRect.width > 0 ? platter.size.width / targetRect.width : 1;
|
|
483
|
+
const halfW = platter.size.width * 0.5;
|
|
484
|
+
const halfH = platter.size.height * 0.5;
|
|
485
|
+
return {
|
|
486
|
+
originX: targetRect.width * 0.5,
|
|
487
|
+
originY: targetRect.height * 0.5,
|
|
488
|
+
scale,
|
|
489
|
+
translateX: platter.center.x - panelCenter.x,
|
|
490
|
+
translateY: platter.center.y - panelCenter.y,
|
|
491
|
+
clipLeft: platter.center.x - halfW,
|
|
492
|
+
clipTop: platter.center.y - halfH,
|
|
493
|
+
clipRight: platter.center.x + halfW,
|
|
494
|
+
clipBottom: platter.center.y + halfH,
|
|
495
|
+
clipRadius: platter.radius,
|
|
496
|
+
};
|
|
497
|
+
}
|
|
498
|
+
function computeGlyphTransform(droplet, effectiveAnchor, externalTrigger) {
|
|
499
|
+
let scale = 0;
|
|
500
|
+
if (effectiveAnchor.width > 0) {
|
|
501
|
+
scale =
|
|
502
|
+
externalTrigger && effectiveAnchor.height > 0
|
|
503
|
+
? Math.min(droplet.size.width / effectiveAnchor.width, droplet.size.height / effectiveAnchor.height)
|
|
504
|
+
: droplet.size.width / effectiveAnchor.width;
|
|
505
|
+
}
|
|
506
|
+
return {
|
|
507
|
+
centerX: droplet.center.x,
|
|
508
|
+
centerY: droplet.center.y,
|
|
509
|
+
scale,
|
|
510
|
+
};
|
|
511
|
+
}
|
|
512
|
+
/**
|
|
513
|
+
* Evaluates the complete per-frame SDF field, merge metrics, optical style mix,
|
|
514
|
+
* and synchronized DOM content/glyph transforms for a morphing popover/menu.
|
|
515
|
+
*/
|
|
516
|
+
export function computePopoverMorphGeometry(motion, anchor, panel, closeSnapshot) {
|
|
517
|
+
const targetRect = computePopoverTargetRect(anchor, panel);
|
|
518
|
+
const restingRadius = resolveRestingRadius(panel);
|
|
519
|
+
const targetRadius = Math.max(0, Math.min(restingRadius, targetRect.width * 0.5, targetRect.height * 0.5));
|
|
520
|
+
const configuredBlendK = panel.blendK ?? POPOVER_MORPH_DEFAULTS.dropletBlendK;
|
|
521
|
+
const effectiveAnchor = getEffectiveAnchorRect(anchor);
|
|
522
|
+
const anchorCenter = rectCenter(effectiveAnchor);
|
|
523
|
+
const panelCenter = rectCenter(targetRect);
|
|
524
|
+
const anchorShortest = Math.min(effectiveAnchor.width, effectiveAnchor.height);
|
|
525
|
+
const anchorLongest = Math.max(effectiveAnchor.width, effectiveAnchor.height);
|
|
526
|
+
const beyond = beyondRound({
|
|
527
|
+
width: effectiveAnchor.width,
|
|
528
|
+
height: effectiveAnchor.height,
|
|
529
|
+
});
|
|
530
|
+
const openDropletTarget = computeDropletRestingTarget(anchorCenter, panelCenter, targetRect, anchorLongest, configuredBlendK);
|
|
531
|
+
let platter;
|
|
532
|
+
let droplet;
|
|
533
|
+
let blendK;
|
|
534
|
+
let styleMix;
|
|
535
|
+
let mergeDepth;
|
|
536
|
+
let isMerged;
|
|
537
|
+
let rimOpacity;
|
|
538
|
+
if (motion.reducedMotion && (motion.phase === 'opening' || motion.phase === 'closing')) {
|
|
539
|
+
platter = {
|
|
540
|
+
id: 'platter',
|
|
541
|
+
center: panelCenter,
|
|
542
|
+
size: { width: targetRect.width, height: targetRect.height },
|
|
543
|
+
radius: targetRadius,
|
|
544
|
+
};
|
|
545
|
+
droplet = motion.hasControlSource
|
|
546
|
+
? {
|
|
547
|
+
id: 'droplet',
|
|
548
|
+
center: anchorCenter,
|
|
549
|
+
size: { width: effectiveAnchor.width, height: effectiveAnchor.height },
|
|
550
|
+
radius: Math.min(effectiveAnchor.width, effectiveAnchor.height) * 0.5,
|
|
551
|
+
}
|
|
552
|
+
: {
|
|
553
|
+
id: 'droplet',
|
|
554
|
+
center: clampPointToRect(anchorCenter, targetRect),
|
|
555
|
+
size: { width: 0, height: 0 },
|
|
556
|
+
radius: 0,
|
|
557
|
+
};
|
|
558
|
+
blendK = 0;
|
|
559
|
+
styleMix = 1;
|
|
560
|
+
mergeDepth = POPOVER_MORPH_DEFAULTS.mergeRimFadeDepth;
|
|
561
|
+
isMerged = !anchor.externalTrigger || !motion.hasControlSource;
|
|
562
|
+
rimOpacity = 1;
|
|
563
|
+
}
|
|
564
|
+
else if (motion.phase === 'opening' || motion.phase === 'open') {
|
|
565
|
+
const progress = motion.phase === 'open' ? 1 : motion.morphProgress;
|
|
566
|
+
const panelW = targetRect.width;
|
|
567
|
+
const panelH = targetRect.height;
|
|
568
|
+
const scale = panelW > 0
|
|
569
|
+
? lerp((POPOVER_MORPH_DEFAULTS.minPlatterScaleRatio * anchorShortest) / panelW, 1, progress)
|
|
570
|
+
: 1;
|
|
571
|
+
const height = lerp(panelW, panelH, progress);
|
|
572
|
+
const beyondWeight = clamp(1 - progress, 0, 1);
|
|
573
|
+
const platterW = Math.max(0, panelW * scale + beyond.w * beyondWeight);
|
|
574
|
+
const platterH = Math.max(0, height * scale + beyond.h * beyondWeight);
|
|
575
|
+
const dy = panelCenter.y - anchorCenter.y;
|
|
576
|
+
const absDy = Math.abs(dy);
|
|
577
|
+
const dip = motion.hasControlSource && absDy > 1e-5
|
|
578
|
+
? Math.sign(dy) *
|
|
579
|
+
(Math.min(1, absDy / POPOVER_MORPH_DEFAULTS.openDipDyCap) *
|
|
580
|
+
POPOVER_MORPH_DEFAULTS.openDipBasePx +
|
|
581
|
+
POPOVER_MORPH_DEFAULTS.openDipDyScale * absDy) *
|
|
582
|
+
motion.platterDipEnvelope
|
|
583
|
+
: 0;
|
|
584
|
+
const baseCenter = lerpPoint(anchorCenter, panelCenter, progress);
|
|
585
|
+
const platterCenter = {
|
|
586
|
+
x: baseCenter.x,
|
|
587
|
+
y: baseCenter.y + dip,
|
|
588
|
+
};
|
|
589
|
+
const corners = restingRadius +
|
|
590
|
+
panelW * POPOVER_MORPH_DEFAULTS.openCornerWidthFactor * motion.cornerProgress;
|
|
591
|
+
const platterRadius = Math.max(0, Math.min(Math.min(height * 0.5, corners) * scale, platterW * 0.5, platterH * 0.5));
|
|
592
|
+
platter = {
|
|
593
|
+
id: 'platter',
|
|
594
|
+
center: platterCenter,
|
|
595
|
+
size: { width: platterW, height: platterH },
|
|
596
|
+
radius: platterRadius,
|
|
597
|
+
};
|
|
598
|
+
if (motion.hasControlSource) {
|
|
599
|
+
if (anchor.externalTrigger) {
|
|
600
|
+
const dropletProgress = clamp(progress, 0, 1);
|
|
601
|
+
const tug = motion.phase === 'open' ? 0 : externalTugEnvelope(dropletProgress);
|
|
602
|
+
const { dir: towardPanel, len: distToPanel } = normalizeOrZero({
|
|
603
|
+
x: panelCenter.x - anchorCenter.x,
|
|
604
|
+
y: panelCenter.y - anchorCenter.y,
|
|
605
|
+
});
|
|
606
|
+
const tugDist = Math.min(22, distToPanel * 0.22) * tug;
|
|
607
|
+
const stretchW = 1 + (0.1 * Math.abs(towardPanel.x) - 0.05 * Math.abs(towardPanel.y)) * tug;
|
|
608
|
+
const stretchH = 1 + (0.1 * Math.abs(towardPanel.y) - 0.05 * Math.abs(towardPanel.x)) * tug;
|
|
609
|
+
const dropletW = Math.max(0, effectiveAnchor.width * stretchW);
|
|
610
|
+
const dropletH = Math.max(0, effectiveAnchor.height * stretchH);
|
|
611
|
+
droplet = {
|
|
612
|
+
id: 'droplet',
|
|
613
|
+
center: {
|
|
614
|
+
x: anchorCenter.x + towardPanel.x * tugDist,
|
|
615
|
+
y: anchorCenter.y + towardPanel.y * tugDist,
|
|
616
|
+
},
|
|
617
|
+
size: { width: dropletW, height: dropletH },
|
|
618
|
+
radius: Math.min(dropletW, dropletH) * 0.5,
|
|
619
|
+
};
|
|
620
|
+
const pinch = motion.phase === 'open' ? 0 : 1 - smoothstep(0.38, 0.68, dropletProgress);
|
|
621
|
+
blendK = configuredBlendK * pinch;
|
|
622
|
+
styleMix = clamp(progress, 0, 1);
|
|
623
|
+
isMerged = false;
|
|
624
|
+
rimOpacity = motion.phase === 'open' ? 1 : smoothstep(0.35, 0.72, dropletProgress);
|
|
625
|
+
mergeDepth =
|
|
626
|
+
motion.phase === 'open'
|
|
627
|
+
? POPOVER_MORPH_DEFAULTS.mergeRimFadeDepth
|
|
628
|
+
: computePairMergeStatus(platter, droplet, blendK, POPOVER_MORPH_DEFAULTS.mergeRimFadeDepth).mergeDepth;
|
|
629
|
+
}
|
|
630
|
+
else {
|
|
631
|
+
const dropletProgress = clamp(progress, 0, 1);
|
|
632
|
+
const dropletScale = lerp(1, POPOVER_MORPH_DEFAULTS.dropletTargetScale, dropletProgress);
|
|
633
|
+
const dropletW = Math.max(0, effectiveAnchor.width * dropletScale);
|
|
634
|
+
const dropletH = Math.max(0, effectiveAnchor.height * dropletScale);
|
|
635
|
+
droplet = {
|
|
636
|
+
id: 'droplet',
|
|
637
|
+
center: lerpPoint(anchorCenter, openDropletTarget, dropletProgress),
|
|
638
|
+
size: { width: dropletW, height: dropletH },
|
|
639
|
+
radius: Math.min(dropletW, dropletH) * 0.5,
|
|
640
|
+
};
|
|
641
|
+
blendK = configuredBlendK;
|
|
642
|
+
styleMix = clamp(progress, 0, 1);
|
|
643
|
+
const merge = computePairMergeStatus(platter, droplet, blendK, POPOVER_MORPH_DEFAULTS.mergeRimFadeDepth);
|
|
644
|
+
mergeDepth = merge.mergeDepth;
|
|
645
|
+
isMerged = merge.isMerged;
|
|
646
|
+
rimOpacity = merge.rimOpacity;
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
else {
|
|
650
|
+
droplet = {
|
|
651
|
+
id: 'droplet',
|
|
652
|
+
center: anchorCenter,
|
|
653
|
+
size: { width: 0, height: 0 },
|
|
654
|
+
radius: 0,
|
|
655
|
+
};
|
|
656
|
+
blendK = 0;
|
|
657
|
+
styleMix = 1;
|
|
658
|
+
mergeDepth = POPOVER_MORPH_DEFAULTS.mergeRimFadeDepth;
|
|
659
|
+
isMerged = true;
|
|
660
|
+
rimOpacity = 1;
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
else if (!motion.hasControlSource) {
|
|
664
|
+
// Point-anchored close fallback: uniform shrink from current bounds toward clamped anchor point.
|
|
665
|
+
const fromPlatter = closeSnapshot?.platter ?? {
|
|
666
|
+
id: 'platter',
|
|
667
|
+
center: panelCenter,
|
|
668
|
+
size: { width: targetRect.width, height: targetRect.height },
|
|
669
|
+
radius: targetRadius,
|
|
670
|
+
};
|
|
671
|
+
const fromRadius = closeSnapshot?.platterRadius ?? targetRadius;
|
|
672
|
+
const pointScale = motion.phase === 'closed' ? POPOVER_MORPH_DEFAULTS.pointCloseEndScale : motion.pointScale;
|
|
673
|
+
const pivot = clampPointToRect(anchorCenter, targetRect);
|
|
674
|
+
const platterW = Math.max(0, fromPlatter.size.width * pointScale);
|
|
675
|
+
const platterH = Math.max(0, fromPlatter.size.height * pointScale);
|
|
676
|
+
platter = {
|
|
677
|
+
id: 'platter',
|
|
678
|
+
center: {
|
|
679
|
+
x: pivot.x + (fromPlatter.center.x - pivot.x) * pointScale,
|
|
680
|
+
y: pivot.y + (fromPlatter.center.y - pivot.y) * pointScale,
|
|
681
|
+
},
|
|
682
|
+
size: {
|
|
683
|
+
width: platterW,
|
|
684
|
+
height: platterH,
|
|
685
|
+
},
|
|
686
|
+
radius: Math.max(0, Math.min(fromRadius * pointScale, platterW * 0.5, platterH * 0.5)),
|
|
687
|
+
};
|
|
688
|
+
droplet = {
|
|
689
|
+
id: 'droplet',
|
|
690
|
+
center: pivot,
|
|
691
|
+
size: { width: 0, height: 0 },
|
|
692
|
+
radius: 0,
|
|
693
|
+
};
|
|
694
|
+
blendK = 0;
|
|
695
|
+
styleMix = 1;
|
|
696
|
+
mergeDepth = POPOVER_MORPH_DEFAULTS.mergeRimFadeDepth;
|
|
697
|
+
isMerged = true;
|
|
698
|
+
rimOpacity = 1;
|
|
699
|
+
}
|
|
700
|
+
else {
|
|
701
|
+
// Control-anchored close (or resting closed state).
|
|
702
|
+
const openDropletW = effectiveAnchor.width * POPOVER_MORPH_DEFAULTS.dropletTargetScale;
|
|
703
|
+
const openDropletH = effectiveAnchor.height * POPOVER_MORPH_DEFAULTS.dropletTargetScale;
|
|
704
|
+
const fromPlatter = closeSnapshot?.platter ?? {
|
|
705
|
+
id: 'platter',
|
|
706
|
+
center: panelCenter,
|
|
707
|
+
size: { width: targetRect.width, height: targetRect.height },
|
|
708
|
+
radius: targetRadius,
|
|
709
|
+
};
|
|
710
|
+
const defaultDroplet = anchor.externalTrigger
|
|
711
|
+
? {
|
|
712
|
+
id: 'droplet',
|
|
713
|
+
center: anchorCenter,
|
|
714
|
+
size: { width: effectiveAnchor.width, height: effectiveAnchor.height },
|
|
715
|
+
radius: Math.min(effectiveAnchor.width, effectiveAnchor.height) * 0.5,
|
|
716
|
+
}
|
|
717
|
+
: {
|
|
718
|
+
id: 'droplet',
|
|
719
|
+
center: openDropletTarget,
|
|
720
|
+
size: { width: openDropletW, height: openDropletH },
|
|
721
|
+
radius: Math.min(openDropletW, openDropletH) * 0.5,
|
|
722
|
+
};
|
|
723
|
+
const fromDroplet = closeSnapshot?.droplet ?? defaultDroplet;
|
|
724
|
+
const fromRadius = closeSnapshot?.platterRadius ?? targetRadius;
|
|
725
|
+
const progress = motion.phase === 'closed' ? 1 : motion.morphProgress;
|
|
726
|
+
const fromW = fromPlatter.size.width;
|
|
727
|
+
const fromH = fromPlatter.size.height;
|
|
728
|
+
const fromMaxDim = Math.max(fromW, fromH);
|
|
729
|
+
const scale = fromMaxDim > 0
|
|
730
|
+
? lerp(1, (POPOVER_MORPH_DEFAULTS.minPlatterScaleRatio * anchorShortest) / fromMaxDim, progress)
|
|
731
|
+
: 0;
|
|
732
|
+
const height = lerp(fromH, fromW, progress);
|
|
733
|
+
const beyondWeight = clamp(progress, 0, 1);
|
|
734
|
+
const platterW = Math.max(0, fromW * scale + beyond.w * beyondWeight);
|
|
735
|
+
const platterH = Math.max(0, height * scale + beyond.h * beyondWeight);
|
|
736
|
+
const toPanel = {
|
|
737
|
+
x: fromPlatter.center.x - anchorCenter.x,
|
|
738
|
+
y: fromPlatter.center.y - anchorCenter.y,
|
|
739
|
+
};
|
|
740
|
+
const { dir: awayFromAnchor, len: toPanelLen } = normalizeOrZero(toPanel);
|
|
741
|
+
const dipMag = Math.min(POPOVER_MORPH_DEFAULTS.closePlatterDipRatio * toPanelLen, POPOVER_MORPH_DEFAULTS.closePlatterDipCapPx) * motion.platterDipEnvelope;
|
|
742
|
+
const basePlatterCenter = lerpPoint(fromPlatter.center, anchorCenter, progress);
|
|
743
|
+
const platterCenter = {
|
|
744
|
+
x: basePlatterCenter.x + awayFromAnchor.x * dipMag,
|
|
745
|
+
y: basePlatterCenter.y + awayFromAnchor.y * dipMag,
|
|
746
|
+
};
|
|
747
|
+
const platterRadius = Math.max(0, Math.min(lerp(fromRadius, fromW * 0.5, progress) * scale, platterW * 0.5, platterH * 0.5));
|
|
748
|
+
platter = {
|
|
749
|
+
id: 'platter',
|
|
750
|
+
center: platterCenter,
|
|
751
|
+
size: { width: platterW, height: platterH },
|
|
752
|
+
radius: platterRadius,
|
|
753
|
+
};
|
|
754
|
+
const dropletSizeT = clamp(progress, 0, 1);
|
|
755
|
+
const overshootMag = Math.min(POPOVER_MORPH_DEFAULTS.closeDropletOvershootRatio * toPanelLen, POPOVER_MORPH_DEFAULTS.closeDropletOvershootCapPx) * motion.dropletOvershootEnvelope;
|
|
756
|
+
if (anchor.externalTrigger) {
|
|
757
|
+
const catchT = clamp(dropletSizeT / 0.65, 0, 1);
|
|
758
|
+
const catchSin = Math.sin(Math.PI * catchT);
|
|
759
|
+
const catchBell = motion.phase === 'closed' ? 0 : catchSin * catchSin;
|
|
760
|
+
const catchMag = Math.min(18, toPanelLen * 0.16) * catchBell;
|
|
761
|
+
const stretchW = 1 + (0.06 * Math.abs(awayFromAnchor.x) - 0.04 * Math.abs(awayFromAnchor.y)) * catchBell;
|
|
762
|
+
const stretchH = 1 + (0.06 * Math.abs(awayFromAnchor.y) - 0.04 * Math.abs(awayFromAnchor.x)) * catchBell;
|
|
763
|
+
const targetW = effectiveAnchor.width * stretchW;
|
|
764
|
+
const targetH = effectiveAnchor.height * stretchH;
|
|
765
|
+
const dropletW = Math.max(0, lerp(fromDroplet.size.width, targetW, dropletSizeT));
|
|
766
|
+
const dropletH = Math.max(0, lerp(fromDroplet.size.height, targetH, dropletSizeT));
|
|
767
|
+
const baseDropletCenter = lerpPoint(fromDroplet.center, anchorCenter, dropletSizeT);
|
|
768
|
+
droplet = {
|
|
769
|
+
id: 'droplet',
|
|
770
|
+
center: {
|
|
771
|
+
x: baseDropletCenter.x + awayFromAnchor.x * (catchMag - overshootMag),
|
|
772
|
+
y: baseDropletCenter.y + awayFromAnchor.y * (catchMag - overshootMag),
|
|
773
|
+
},
|
|
774
|
+
size: { width: dropletW, height: dropletH },
|
|
775
|
+
radius: Math.min(dropletW, dropletH) * 0.5,
|
|
776
|
+
};
|
|
777
|
+
}
|
|
778
|
+
else {
|
|
779
|
+
const dropletW = Math.max(0, lerp(fromDroplet.size.width, effectiveAnchor.width, dropletSizeT));
|
|
780
|
+
const dropletH = Math.max(0, lerp(fromDroplet.size.height, effectiveAnchor.height, dropletSizeT));
|
|
781
|
+
const baseDropletCenter = lerpPoint(fromDroplet.center, anchorCenter, progress);
|
|
782
|
+
droplet = {
|
|
783
|
+
id: 'droplet',
|
|
784
|
+
center: {
|
|
785
|
+
x: baseDropletCenter.x - awayFromAnchor.x * overshootMag,
|
|
786
|
+
y: baseDropletCenter.y - awayFromAnchor.y * overshootMag,
|
|
787
|
+
},
|
|
788
|
+
size: { width: dropletW, height: dropletH },
|
|
789
|
+
radius: Math.min(dropletW, dropletH) * 0.5,
|
|
790
|
+
};
|
|
791
|
+
}
|
|
792
|
+
const startBlendK = closeSnapshot?.blendK ?? 0;
|
|
793
|
+
blendK =
|
|
794
|
+
motion.phase === 'closed'
|
|
795
|
+
? 0
|
|
796
|
+
: lerp(startBlendK, configuredBlendK, motion.closeBlendRamp) * (1 - motion.absorbed);
|
|
797
|
+
const minClosedW = POPOVER_MORPH_DEFAULTS.minPlatterScaleRatio * anchorShortest;
|
|
798
|
+
const startMix = closeSnapshot
|
|
799
|
+
? clamp((fromW - minClosedW) / Math.max(1, targetRect.width - minClosedW), 0, 1)
|
|
800
|
+
: 1;
|
|
801
|
+
styleMix = motion.phase === 'closed' ? 0 : startMix * (1 - clamp(progress, 0, 1));
|
|
802
|
+
if (anchor.externalTrigger) {
|
|
803
|
+
isMerged = false;
|
|
804
|
+
mergeDepth = computePairMergeStatus(platter, droplet, blendK, POPOVER_MORPH_DEFAULTS.mergeRimFadeDepth).mergeDepth;
|
|
805
|
+
rimOpacity =
|
|
806
|
+
motion.phase === 'closed' ? 0 : startMix * (1 - smoothstep(0, 0.45, dropletSizeT));
|
|
807
|
+
}
|
|
808
|
+
else {
|
|
809
|
+
const merge = computePairMergeStatus(platter, droplet, blendK, POPOVER_MORPH_DEFAULTS.mergeRimFadeDepth);
|
|
810
|
+
mergeDepth = merge.mergeDepth;
|
|
811
|
+
isMerged = merge.isMerged;
|
|
812
|
+
rimOpacity = merge.rimOpacity;
|
|
813
|
+
}
|
|
814
|
+
}
|
|
815
|
+
if (motion.phase === 'opening' && motion.reopenFrom) {
|
|
816
|
+
const reopen = motion.reopenFrom;
|
|
817
|
+
const blendT = clamp((motion.elapsedSec - reopen.startElapsedSec) / Math.max(1e-4, reopen.blendDurationSec), 0, 1);
|
|
818
|
+
const blend = smoothstep(0, 1, blendT);
|
|
819
|
+
if (blend < 1) {
|
|
820
|
+
const originGeom = computePopoverMorphGeometry(reopen.motion, anchor, panel, reopen.closeSnapshot);
|
|
821
|
+
if (blend <= 0) {
|
|
822
|
+
return originGeom;
|
|
823
|
+
}
|
|
824
|
+
const nextPlatterW = Math.max(0, lerp(originGeom.platter.size.width, platter.size.width, blend));
|
|
825
|
+
const nextPlatterH = Math.max(0, lerp(originGeom.platter.size.height, platter.size.height, blend));
|
|
826
|
+
platter = {
|
|
827
|
+
id: 'platter',
|
|
828
|
+
center: lerpPoint(originGeom.platter.center, platter.center, blend),
|
|
829
|
+
size: { width: nextPlatterW, height: nextPlatterH },
|
|
830
|
+
radius: Math.max(0, Math.min(lerp(originGeom.platter.radius, platter.radius, blend), nextPlatterW * 0.5, nextPlatterH * 0.5)),
|
|
831
|
+
};
|
|
832
|
+
const nextDropletW = Math.max(0, lerp(originGeom.droplet.size.width, droplet.size.width, blend));
|
|
833
|
+
const nextDropletH = Math.max(0, lerp(originGeom.droplet.size.height, droplet.size.height, blend));
|
|
834
|
+
droplet = {
|
|
835
|
+
id: 'droplet',
|
|
836
|
+
center: lerpPoint(originGeom.droplet.center, droplet.center, blend),
|
|
837
|
+
size: { width: nextDropletW, height: nextDropletH },
|
|
838
|
+
radius: Math.max(0, Math.min(lerp(originGeom.droplet.radius, droplet.radius, blend), nextDropletW * 0.5, nextDropletH * 0.5)),
|
|
839
|
+
};
|
|
840
|
+
blendK = Math.max(0, lerp(originGeom.blendK, blendK, blend));
|
|
841
|
+
styleMix = clamp(lerp(originGeom.styleMix, styleMix, blend), 0, 1);
|
|
842
|
+
if (anchor.externalTrigger || !motion.hasControlSource) {
|
|
843
|
+
rimOpacity = clamp(lerp(originGeom.rimOpacity, rimOpacity, blend), 0, 1);
|
|
844
|
+
isMerged = blend >= 0.5 ? isMerged : originGeom.isMerged;
|
|
845
|
+
mergeDepth = lerp(originGeom.mergeDepth, mergeDepth, blend);
|
|
846
|
+
}
|
|
847
|
+
else {
|
|
848
|
+
const merge = computePairMergeStatus(platter, droplet, blendK, POPOVER_MORPH_DEFAULTS.mergeRimFadeDepth);
|
|
849
|
+
mergeDepth = merge.mergeDepth;
|
|
850
|
+
isMerged = merge.isMerged;
|
|
851
|
+
rimOpacity = merge.rimOpacity;
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
}
|
|
855
|
+
const primitives = droplet.size.width > 0 && droplet.size.height > 0 ? [platter, droplet] : [platter];
|
|
856
|
+
return {
|
|
857
|
+
targetRect,
|
|
858
|
+
targetRadius,
|
|
859
|
+
platter,
|
|
860
|
+
droplet,
|
|
861
|
+
blendK,
|
|
862
|
+
mergeDepth,
|
|
863
|
+
isMerged,
|
|
864
|
+
rimOpacity,
|
|
865
|
+
styleMix,
|
|
866
|
+
field: {
|
|
867
|
+
primitives,
|
|
868
|
+
blendK,
|
|
869
|
+
rimOpacity,
|
|
870
|
+
styleMix,
|
|
871
|
+
},
|
|
872
|
+
contentTransform: computeContentTransform(platter, targetRect),
|
|
873
|
+
glyphTransform: computeGlyphTransform(droplet, effectiveAnchor, Boolean(anchor.externalTrigger && motion.hasControlSource)),
|
|
874
|
+
};
|
|
875
|
+
}
|
|
876
|
+
/**
|
|
877
|
+
* Captures a mid-flight geometry snapshot so closing an interrupted opening morph
|
|
878
|
+
* retracts smoothly from the instantaneous platter/droplet bounds.
|
|
879
|
+
*/
|
|
880
|
+
export function createPopoverMorphSnapshot(geometry, motion) {
|
|
881
|
+
return {
|
|
882
|
+
platter: {
|
|
883
|
+
id: geometry.platter.id,
|
|
884
|
+
center: { ...geometry.platter.center },
|
|
885
|
+
size: { ...geometry.platter.size },
|
|
886
|
+
radius: geometry.platter.radius,
|
|
887
|
+
},
|
|
888
|
+
droplet: {
|
|
889
|
+
id: geometry.droplet.id,
|
|
890
|
+
center: { ...geometry.droplet.center },
|
|
891
|
+
size: { ...geometry.droplet.size },
|
|
892
|
+
radius: geometry.droplet.radius,
|
|
893
|
+
},
|
|
894
|
+
platterRadius: geometry.platter.radius,
|
|
895
|
+
blurPx: motion.contentBlurPx,
|
|
896
|
+
elapsedFraction: motion.normalizedT,
|
|
897
|
+
blendK: geometry.blendK,
|
|
898
|
+
};
|
|
899
|
+
}
|
|
900
|
+
function solveOpenElapsedForProgress(targetProgress) {
|
|
901
|
+
const target = clamp(targetProgress, 0, 0.999);
|
|
902
|
+
if (target <= 0)
|
|
903
|
+
return 0;
|
|
904
|
+
// Primary open spring rises monotonically on [0, ~0.185s] before peaking.
|
|
905
|
+
let lo = 0;
|
|
906
|
+
let hi = Math.min(0.2, POPOVER_MORPH_DEFAULTS.openDurationSec);
|
|
907
|
+
while (hi < POPOVER_MORPH_DEFAULTS.openDurationSec &&
|
|
908
|
+
evaluateSpring(hi, POPOVER_MORPH_DEFAULTS.springs.open) < target) {
|
|
909
|
+
hi = Math.min(POPOVER_MORPH_DEFAULTS.openDurationSec, hi + 0.05);
|
|
910
|
+
}
|
|
911
|
+
for (let i = 0; i < 24; i += 1) {
|
|
912
|
+
const mid = 0.5 * (lo + hi);
|
|
913
|
+
if (evaluateSpring(mid, POPOVER_MORPH_DEFAULTS.springs.open) < target) {
|
|
914
|
+
lo = mid;
|
|
915
|
+
}
|
|
916
|
+
else {
|
|
917
|
+
hi = mid;
|
|
918
|
+
}
|
|
919
|
+
}
|
|
920
|
+
return 0.5 * (lo + hi);
|
|
921
|
+
}
|
|
922
|
+
/**
|
|
923
|
+
* Creates a stateful, interruptible controller for the morphing popover/menu preset.
|
|
924
|
+
*/
|
|
925
|
+
export function createPopoverMorphController(options = {}) {
|
|
926
|
+
let reducedMotion = options.reducedMotion ?? false;
|
|
927
|
+
let phase = 'closed';
|
|
928
|
+
let hasControlSource = true;
|
|
929
|
+
let elapsedSec = 0;
|
|
930
|
+
let closeSnapshot = null;
|
|
931
|
+
let interruptStart;
|
|
932
|
+
let disposed = false;
|
|
933
|
+
const listeners = new Set();
|
|
934
|
+
function buildState() {
|
|
935
|
+
const duration = getPopoverPhaseDurationSec(phase, hasControlSource, reducedMotion);
|
|
936
|
+
const normalizedT = duration > 0 ? clamp(elapsedSec / duration, 0, 1) : phase === 'open' ? 1 : 0;
|
|
937
|
+
return evaluatePopoverMotion(phase, normalizedT, {
|
|
938
|
+
hasControlSource,
|
|
939
|
+
reducedMotion,
|
|
940
|
+
interruptStart: phase === 'opening' || phase === 'closing' ? interruptStart : undefined,
|
|
941
|
+
});
|
|
942
|
+
}
|
|
943
|
+
function notify() {
|
|
944
|
+
if (disposed || listeners.size === 0)
|
|
945
|
+
return;
|
|
946
|
+
const snapshot = buildState();
|
|
947
|
+
for (const listener of [...listeners]) {
|
|
948
|
+
listener(snapshot);
|
|
949
|
+
}
|
|
950
|
+
}
|
|
951
|
+
return {
|
|
952
|
+
getState() {
|
|
953
|
+
return buildState();
|
|
954
|
+
},
|
|
955
|
+
getCloseSnapshot() {
|
|
956
|
+
return closeSnapshot;
|
|
957
|
+
},
|
|
958
|
+
evaluateGeometry(anchor, panel) {
|
|
959
|
+
const motion = buildState();
|
|
960
|
+
const snapshot = motion.phase === 'closing' ? closeSnapshot : null;
|
|
961
|
+
return computePopoverMorphGeometry(motion, anchor, panel, snapshot);
|
|
962
|
+
},
|
|
963
|
+
setReducedMotion(reduced) {
|
|
964
|
+
if (disposed || reducedMotion === reduced)
|
|
965
|
+
return;
|
|
966
|
+
reducedMotion = reduced;
|
|
967
|
+
if (phase === 'opening' || phase === 'closing') {
|
|
968
|
+
const nextDuration = getPopoverPhaseDurationSec(phase, hasControlSource, reducedMotion);
|
|
969
|
+
interruptStart = undefined;
|
|
970
|
+
if (elapsedSec >= nextDuration) {
|
|
971
|
+
if (phase === 'opening') {
|
|
972
|
+
phase = 'open';
|
|
973
|
+
elapsedSec = nextDuration;
|
|
974
|
+
}
|
|
975
|
+
else {
|
|
976
|
+
phase = 'closed';
|
|
977
|
+
elapsedSec = 0;
|
|
978
|
+
closeSnapshot = null;
|
|
979
|
+
}
|
|
980
|
+
}
|
|
981
|
+
}
|
|
982
|
+
notify();
|
|
983
|
+
},
|
|
984
|
+
open(controlSource = true) {
|
|
985
|
+
if (disposed)
|
|
986
|
+
return;
|
|
987
|
+
if (phase === 'open' || phase === 'opening') {
|
|
988
|
+
return;
|
|
989
|
+
}
|
|
990
|
+
let nextElapsedSec = 0;
|
|
991
|
+
let nextInterruptStart;
|
|
992
|
+
if (phase === 'closing') {
|
|
993
|
+
const current = buildState();
|
|
994
|
+
const originDuration = POPOVER_MORPH_DEFAULTS.openDurationSec;
|
|
995
|
+
const snapshotOpenProgress = closeSnapshot
|
|
996
|
+
? clamp(evaluateSpring(clamp(closeSnapshot.elapsedFraction, 0, 1) * originDuration, POPOVER_MORPH_DEFAULTS.springs.open), 0, 1)
|
|
997
|
+
: 1;
|
|
998
|
+
const openFraction = reducedMotion
|
|
999
|
+
? clamp(current.settled, 0, 0.95)
|
|
1000
|
+
: clamp(snapshotOpenProgress * (1 - current.morphProgress), 0, 0.95);
|
|
1001
|
+
if (openFraction > 0) {
|
|
1002
|
+
if (reducedMotion) {
|
|
1003
|
+
const u = 1 - Math.cbrt(1 - openFraction);
|
|
1004
|
+
nextElapsedSec = u * POPOVER_MORPH_DEFAULTS.reducedMotionDurationSec;
|
|
1005
|
+
}
|
|
1006
|
+
else {
|
|
1007
|
+
nextElapsedSec = solveOpenElapsedForProgress(openFraction);
|
|
1008
|
+
}
|
|
1009
|
+
}
|
|
1010
|
+
if (current.normalizedT < 1) {
|
|
1011
|
+
const nextDuration = getPopoverPhaseDurationSec('opening', controlSource, reducedMotion);
|
|
1012
|
+
const startNormalizedT = nextDuration > 0 ? clamp(nextElapsedSec / nextDuration, 0, 1) : 0;
|
|
1013
|
+
const startSettled = reducedMotion
|
|
1014
|
+
? easeOutCubic(startNormalizedT)
|
|
1015
|
+
: clamp(evaluateSpring(nextElapsedSec, POPOVER_MORPH_DEFAULTS.springs.open), 0, 1);
|
|
1016
|
+
const blendDurationSec = reducedMotion
|
|
1017
|
+
? 0
|
|
1018
|
+
: Math.min(0.22, Math.max(1e-4, nextDuration - nextElapsedSec));
|
|
1019
|
+
nextInterruptStart = {
|
|
1020
|
+
contentOpacity: current.contentOpacity,
|
|
1021
|
+
contentBlurPx: current.contentBlurPx,
|
|
1022
|
+
triggerGlyphOpacity: current.triggerGlyphOpacity,
|
|
1023
|
+
triggerGlyphBlurPx: current.triggerGlyphBlurPx,
|
|
1024
|
+
bareGlassOpacity: current.bareGlassOpacity,
|
|
1025
|
+
startNormalizedT,
|
|
1026
|
+
startSettled,
|
|
1027
|
+
reopenFrom: reducedMotion
|
|
1028
|
+
? undefined
|
|
1029
|
+
: {
|
|
1030
|
+
motion: current,
|
|
1031
|
+
closeSnapshot,
|
|
1032
|
+
startElapsedSec: nextElapsedSec,
|
|
1033
|
+
blendDurationSec,
|
|
1034
|
+
},
|
|
1035
|
+
};
|
|
1036
|
+
}
|
|
1037
|
+
}
|
|
1038
|
+
hasControlSource = controlSource;
|
|
1039
|
+
closeSnapshot = null;
|
|
1040
|
+
interruptStart = nextInterruptStart;
|
|
1041
|
+
phase = 'opening';
|
|
1042
|
+
elapsedSec = nextElapsedSec;
|
|
1043
|
+
notify();
|
|
1044
|
+
},
|
|
1045
|
+
close(snapshot) {
|
|
1046
|
+
if (disposed)
|
|
1047
|
+
return;
|
|
1048
|
+
if (phase === 'closed' || phase === 'closing') {
|
|
1049
|
+
return;
|
|
1050
|
+
}
|
|
1051
|
+
const current = buildState();
|
|
1052
|
+
closeSnapshot = snapshot ?? null;
|
|
1053
|
+
if (phase === 'opening' && current.normalizedT < 1) {
|
|
1054
|
+
interruptStart = {
|
|
1055
|
+
contentOpacity: current.contentOpacity,
|
|
1056
|
+
contentBlurPx: snapshot ? snapshot.blurPx : current.contentBlurPx,
|
|
1057
|
+
triggerGlyphOpacity: Math.max(reducedMotion ? 0 : POPOVER_MORPH_DEFAULTS.closeGlyphStartOpacity, current.triggerGlyphOpacity),
|
|
1058
|
+
bareGlassOpacity: current.bareGlassOpacity,
|
|
1059
|
+
};
|
|
1060
|
+
}
|
|
1061
|
+
else {
|
|
1062
|
+
interruptStart = undefined;
|
|
1063
|
+
}
|
|
1064
|
+
phase = 'closing';
|
|
1065
|
+
elapsedSec = 0;
|
|
1066
|
+
notify();
|
|
1067
|
+
},
|
|
1068
|
+
reset(toPhase = 'closed') {
|
|
1069
|
+
if (disposed)
|
|
1070
|
+
return;
|
|
1071
|
+
phase = toPhase;
|
|
1072
|
+
hasControlSource = true;
|
|
1073
|
+
elapsedSec =
|
|
1074
|
+
toPhase === 'open'
|
|
1075
|
+
? getPopoverPhaseDurationSec('opening', hasControlSource, reducedMotion)
|
|
1076
|
+
: 0;
|
|
1077
|
+
closeSnapshot = null;
|
|
1078
|
+
interruptStart = undefined;
|
|
1079
|
+
notify();
|
|
1080
|
+
},
|
|
1081
|
+
seek(targetPhase, normalizedT, controlSource) {
|
|
1082
|
+
if (disposed)
|
|
1083
|
+
return buildState();
|
|
1084
|
+
if (controlSource !== undefined) {
|
|
1085
|
+
hasControlSource = controlSource;
|
|
1086
|
+
}
|
|
1087
|
+
phase = targetPhase;
|
|
1088
|
+
interruptStart = undefined;
|
|
1089
|
+
if (targetPhase === 'closed' || targetPhase === 'open') {
|
|
1090
|
+
elapsedSec =
|
|
1091
|
+
targetPhase === 'open'
|
|
1092
|
+
? getPopoverPhaseDurationSec('opening', hasControlSource, reducedMotion)
|
|
1093
|
+
: 0;
|
|
1094
|
+
if (targetPhase === 'closed') {
|
|
1095
|
+
closeSnapshot = null;
|
|
1096
|
+
}
|
|
1097
|
+
}
|
|
1098
|
+
else {
|
|
1099
|
+
const duration = getPopoverPhaseDurationSec(targetPhase, hasControlSource, reducedMotion);
|
|
1100
|
+
elapsedSec = clamp(normalizedT, 0, 1) * duration;
|
|
1101
|
+
}
|
|
1102
|
+
const next = buildState();
|
|
1103
|
+
notify();
|
|
1104
|
+
return next;
|
|
1105
|
+
},
|
|
1106
|
+
step(dtSec) {
|
|
1107
|
+
if (disposed || !Number.isFinite(dtSec) || dtSec <= 0) {
|
|
1108
|
+
return buildState();
|
|
1109
|
+
}
|
|
1110
|
+
if (phase === 'opening' || phase === 'closing') {
|
|
1111
|
+
const duration = getPopoverPhaseDurationSec(phase, hasControlSource, reducedMotion);
|
|
1112
|
+
elapsedSec += dtSec;
|
|
1113
|
+
if (elapsedSec >= duration) {
|
|
1114
|
+
if (phase === 'opening') {
|
|
1115
|
+
phase = 'open';
|
|
1116
|
+
elapsedSec = duration;
|
|
1117
|
+
interruptStart = undefined;
|
|
1118
|
+
}
|
|
1119
|
+
else {
|
|
1120
|
+
phase = 'closed';
|
|
1121
|
+
elapsedSec = 0;
|
|
1122
|
+
closeSnapshot = null;
|
|
1123
|
+
interruptStart = undefined;
|
|
1124
|
+
}
|
|
1125
|
+
}
|
|
1126
|
+
notify();
|
|
1127
|
+
}
|
|
1128
|
+
return buildState();
|
|
1129
|
+
},
|
|
1130
|
+
subscribe(listener) {
|
|
1131
|
+
if (disposed) {
|
|
1132
|
+
return () => { };
|
|
1133
|
+
}
|
|
1134
|
+
listeners.add(listener);
|
|
1135
|
+
return () => {
|
|
1136
|
+
listeners.delete(listener);
|
|
1137
|
+
};
|
|
1138
|
+
},
|
|
1139
|
+
dispose() {
|
|
1140
|
+
disposed = true;
|
|
1141
|
+
listeners.clear();
|
|
1142
|
+
},
|
|
1143
|
+
};
|
|
1144
|
+
}
|