@k2b/ui 0.61.0 → 0.62.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/dist/browser/actions/FilterChip.js +3 -0
- package/dist/browser/actions/FilterChip.js.map +1 -1
- package/dist/browser/content/ActivityList.js +379 -290
- package/dist/browser/content/ActivityList.js.map +1 -1
- package/dist/browser/content/FileView.js +0 -12
- package/dist/browser/content/FileView.js.map +1 -1
- package/dist/browser/content/activity-messages.js +2 -2
- package/dist/browser/content/activity-messages.js.map +1 -1
- package/dist/browser/content/file-view-preview.js +13 -0
- package/dist/browser/content/file-view-preview.js.map +1 -1
- package/dist/browser/content/index.js +4 -4
- package/dist/browser/content/index.js.map +1 -1
- package/dist/browser/feedback/dialog-core.js +24 -27
- package/dist/browser/feedback/dialog-core.js.map +1 -1
- package/dist/browser/feedback/dialog-frame-motion.js +506 -15
- package/dist/browser/feedback/dialog-frame-motion.js.map +1 -1
- package/dist/browser/feedback/prompt-sheet.js +1 -0
- package/dist/browser/feedback/prompt-sheet.js.map +1 -1
- package/dist/browser/feedback/prompts.js +5 -1
- package/dist/browser/feedback/prompts.js.map +1 -1
- package/dist/browser/layout/sheet-motion.js +3 -3
- package/dist/browser/layout/sheet-motion.js.map +1 -1
- package/dist/ssr/actions/FilterChip.js +3 -0
- package/dist/ssr/actions/FilterChip.js.map +1 -1
- package/dist/ssr/content/ActivityList.js +199 -114
- package/dist/ssr/content/ActivityList.js.map +1 -1
- package/dist/ssr/content/FileView.js +0 -12
- package/dist/ssr/content/FileView.js.map +1 -1
- package/dist/ssr/content/activity-messages.js +2 -2
- package/dist/ssr/content/activity-messages.js.map +1 -1
- package/dist/ssr/content/file-view-preview.js +13 -0
- package/dist/ssr/content/file-view-preview.js.map +1 -1
- package/dist/ssr/content/index.js +4 -4
- package/dist/ssr/content/index.js.map +1 -1
- package/dist/ssr/feedback/dialog-core.js +24 -27
- package/dist/ssr/feedback/dialog-core.js.map +1 -1
- package/dist/ssr/feedback/dialog-frame-motion.js +506 -15
- package/dist/ssr/feedback/dialog-frame-motion.js.map +1 -1
- package/dist/ssr/feedback/prompt-sheet.js +1 -0
- package/dist/ssr/feedback/prompt-sheet.js.map +1 -1
- package/dist/ssr/feedback/prompts.js +5 -1
- package/dist/ssr/feedback/prompts.js.map +1 -1
- package/dist/ssr/layout/sheet-motion.js +3 -3
- package/dist/ssr/layout/sheet-motion.js.map +1 -1
- package/dist/styles.css +1 -1
- package/dist/types/actions/FilterChip.d.ts +9 -0
- package/dist/types/content/ActivityList.d.ts +24 -6
- package/dist/types/content/FileView.d.ts +0 -5
- package/dist/types/content/file-view-preview.d.ts +5 -0
- package/dist/types/content/index.d.ts +3 -3
- package/dist/types/feedback/dialog-core.d.ts +3 -1
- package/dist/types/feedback/dialog-frame-motion.d.ts +26 -1
- package/dist/types/feedback/prompt-sheet.d.ts +1 -0
- package/dist/types/feedback/prompts.d.ts +4 -0
- package/dist/types/layout/sheet-motion.d.ts +2 -2
- package/package.json +1 -1
|
@@ -5,6 +5,13 @@
|
|
|
5
5
|
* first frame so it never rewraps; the frame clips meanwhile. Anything that interrupts a change turns around from the
|
|
6
6
|
* values the eye sees; the endings of the interrupted change are dropped, not run. Reduced motion swaps in one frame.
|
|
7
7
|
*
|
|
8
|
+
* An opted-in frame also follows its content's height while it is open: when a notice comes or goes, fields appear, or text
|
|
9
|
+
* grows, the frame goes from the height the eye sees to the new one over `--k2b-motion-fold` with `--k2b-ease-glide`,
|
|
10
|
+
* and new content fades in over `--k2b-motion-fast` from 40 % of that time. Its top edge stays where it is: it grows
|
|
11
|
+
* downwards and moves up together with growth only when the room below runs out; a sheet grows from the bottom edge. Frames with a size of
|
|
12
|
+
* their own (fixed, workspace, full, sheets with detents) never follow. Neither the first open, the close, a window
|
|
13
|
+
* resize, nor the on-screen keyboard starts an animation; a resize during a fold retargets it.
|
|
14
|
+
*
|
|
8
15
|
* The frame's own size is animated, a named exception to "transform and opacity only" (see the motion guide): the
|
|
9
16
|
* frame stands alone above the page, so nothing beside it moves.
|
|
10
17
|
*/
|
|
@@ -12,6 +19,11 @@
|
|
|
12
19
|
import { restoreScroll } from "../internal/scroll-places";
|
|
13
20
|
export { afterExitTransitions } from "../internal/exit-motion";
|
|
14
21
|
|
|
22
|
+
/** New content fades in from this share of the fold. */
|
|
23
|
+
const FOLD_DELAY_SHARE = 0.4;
|
|
24
|
+
/** Frames whose size is their own: they never follow their content. A sheet with detents only while it is a sheet. */
|
|
25
|
+
const OWN_SIZE = ".is-fixed, .is-workspace, .k2b-dialog--full";
|
|
26
|
+
|
|
15
27
|
/** Shares of the morph: the old content fades out in the first 80 of 280 ms, the new one waits 110 ms, then fades in 140 ms. */
|
|
16
28
|
const LEAVE_SHARE = 80 / 280;
|
|
17
29
|
const ARRIVE_DELAY_SHARE = 110 / 280;
|
|
@@ -30,6 +42,8 @@ export const createFrameMotion = dialog => {
|
|
|
30
42
|
fresh = false;
|
|
31
43
|
});
|
|
32
44
|
let frame;
|
|
45
|
+
/** Whether the running frame animation is a morph between levels or a fold to new content. */
|
|
46
|
+
let frameKind;
|
|
33
47
|
const fades = new Map();
|
|
34
48
|
|
|
35
49
|
/** A time token in milliseconds; the stylesheet may hand it over as `280ms` or, registered, as `0.28s`. */
|
|
@@ -48,12 +62,22 @@ export const createFrameMotion = dialog => {
|
|
|
48
62
|
const asDialog = dialog.classList.contains("is-adaptive") && typeof matchMedia === "function" && matchMedia("(min-width: 48rem)").matches;
|
|
49
63
|
return asDialog ? "center" : "bottom";
|
|
50
64
|
};
|
|
51
|
-
/**
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
65
|
+
/** Following content also respects a caller's stylesheet that anchors the top edge (translateX only), as setPosition does inline. */
|
|
66
|
+
const followAnchor = () => {
|
|
67
|
+
const where = anchor();
|
|
68
|
+
if (where !== "center" || dialog.classList.contains("k2b-bottom-sheet-frame")) return where;
|
|
69
|
+
const transform = getComputedStyle(dialog).transform;
|
|
70
|
+
return !transform || transform === "none" || new DOMMatrixReadOnly(transform).m42 === 0 ? "fixed" : "center";
|
|
71
|
+
};
|
|
72
|
+
/** Frames use border-box sizing. Read their fractional CSS dimensions, before zoom or transforms are applied. */
|
|
73
|
+
const seen = () => {
|
|
74
|
+
const style = getComputedStyle(dialog);
|
|
75
|
+
return {
|
|
76
|
+
width: Number.parseFloat(style.width) || 0,
|
|
77
|
+
height: Number.parseFloat(style.height) || 0,
|
|
78
|
+
top: Number.parseFloat(style.top) || 0
|
|
79
|
+
};
|
|
80
|
+
};
|
|
57
81
|
|
|
58
82
|
/** Its exact laid-out size: `offsetWidth` rounds, and a content a fraction narrower can wrap differently. */
|
|
59
83
|
const laidOut = element => {
|
|
@@ -129,12 +153,436 @@ export const createFrameMotion = dialog => {
|
|
|
129
153
|
const endFrame = () => {
|
|
130
154
|
frame?.cancel();
|
|
131
155
|
frame = undefined;
|
|
156
|
+
frameKind = undefined;
|
|
132
157
|
delete dialog.dataset.k2bFrameMotion;
|
|
133
158
|
};
|
|
159
|
+
|
|
160
|
+
// ---- Following the content's height ----
|
|
161
|
+
|
|
162
|
+
let level;
|
|
163
|
+
/** Between measurements the frame holds its height; content never grows it ahead of a fold. */
|
|
164
|
+
let rested = 0;
|
|
165
|
+
let placed = false;
|
|
166
|
+
let followingAnchor;
|
|
167
|
+
let initialMeasure = false;
|
|
168
|
+
let viewportHeight = window.innerHeight;
|
|
169
|
+
let queued = 0;
|
|
170
|
+
let resized = false;
|
|
171
|
+
let firstRest = false;
|
|
172
|
+
let restFrame = 0;
|
|
173
|
+
let busy = false;
|
|
174
|
+
let loadingChange = false;
|
|
175
|
+
let arrived = new Set();
|
|
176
|
+
let arrivalFrame = 0;
|
|
177
|
+
const pointers = new Set();
|
|
178
|
+
let deferredFold = false;
|
|
179
|
+
const ownSize = () => dialog.matches(OWN_SIZE) || dialog.matches("[data-sheet-detents]") && anchor() === "bottom";
|
|
180
|
+
const BUSY_CONTENT = '[aria-busy="true"]:not(button, [role="button"])';
|
|
181
|
+
const isBusyNode = node => node.matches(BUSY_CONTENT) || Boolean(node.querySelector(BUSY_CONTENT));
|
|
182
|
+
const isBusy = () => Boolean(level && isBusyNode(level));
|
|
183
|
+
const textFocused = () => {
|
|
184
|
+
const active = document.activeElement;
|
|
185
|
+
if (!(active instanceof HTMLElement) || !level?.contains(active)) return false;
|
|
186
|
+
if (active instanceof HTMLInputElement) return /^(text|search|email|url|tel|password|number)$/.test(active.type);
|
|
187
|
+
return active instanceof HTMLTextAreaElement || active.isContentEditable;
|
|
188
|
+
};
|
|
189
|
+
const place = offset => {
|
|
190
|
+
placed = offset !== 0;
|
|
191
|
+
if (placed) dialog.style.top = `${window.innerHeight / 2 + offset}px`;else dialog.style.removeProperty("top");
|
|
192
|
+
};
|
|
193
|
+
/** Keep the top edge, moving up with growth only as far as the new height needs. */
|
|
194
|
+
const edgeFor = (shown, height) => {
|
|
195
|
+
const viewport = window.visualViewport?.scale === 1 ? window.visualViewport : null;
|
|
196
|
+
const bottom = viewport ? viewport.offsetTop + viewport.height : window.innerHeight;
|
|
197
|
+
const cap = Number.parseFloat(getComputedStyle(dialog).maxHeight);
|
|
198
|
+
const margin = Number.isFinite(cap) ? Math.max(0, ((viewport?.height ?? window.innerHeight) - cap) / 2) : 0;
|
|
199
|
+
return Math.max((viewport?.offsetTop ?? 0) + margin, Math.min(shown.top - shown.height / 2, bottom - margin - height));
|
|
200
|
+
};
|
|
201
|
+
const holdHeight = height => {
|
|
202
|
+
// CSSOM decimal serialization can fall just below the actual layout unit (e.g. 284.984 instead of
|
|
203
|
+
// 284.984375). Writing it back verbatim loses a unit and can give a flex body a 1 px scroll overflow.
|
|
204
|
+
// A thousandth of a pixel restores that unit without rounding the frame to a whole CSS pixel.
|
|
205
|
+
dialog.style.height = `${height + 0.001}px`;
|
|
206
|
+
rested = height;
|
|
207
|
+
};
|
|
208
|
+
const changed = () => {
|
|
209
|
+
if (!level || queued) return;
|
|
210
|
+
queued = requestAnimationFrame(() => {
|
|
211
|
+
queued = 0;
|
|
212
|
+
fold();
|
|
213
|
+
});
|
|
214
|
+
};
|
|
215
|
+
const fold = () => {
|
|
216
|
+
if (!level || started || frameKind === "morph") return;
|
|
217
|
+
const loading = busy || loadingChange || isBusy();
|
|
218
|
+
const where = followAnchor();
|
|
219
|
+
const anchorChanged = followingAnchor !== where;
|
|
220
|
+
// A pressed control stays under the pointer even when a size report, rather than focusout, starts the fold.
|
|
221
|
+
// Viewport/anchor corrections and loading still take their natural size immediately.
|
|
222
|
+
if (pointers.size && firstRest && !initialMeasure && !loading && !resized && !anchorChanged) {
|
|
223
|
+
deferredFold = true;
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
deferredFold = false;
|
|
227
|
+
// A child already animating its height owns that motion. Measure its final height once, rather than folding
|
|
228
|
+
// the frame towards intermediate samples and then folding it a second time.
|
|
229
|
+
const heightMotion = dialog.getAnimations({
|
|
230
|
+
subtree: true
|
|
231
|
+
}).filter(animation => animation !== frame && animation.timeline === document.timeline && Number.isFinite(animation.effect?.getComputedTiming().endTime) && animation.playState === "running" && animation.effect instanceof KeyframeEffect && animation.effect.target !== dialog && animation.effect.getKeyframes().some(keyframe => "height" in keyframe || "maxHeight" in keyframe || "minHeight" in keyframe || "gridTemplateRows" in keyframe));
|
|
232
|
+
if (heightMotion.length && !resized && !anchorChanged) {
|
|
233
|
+
for (const animation of heightMotion) if (!waiting.has(animation)) {
|
|
234
|
+
waiting.add(animation);
|
|
235
|
+
void animation.finished.catch(() => {}).then(changed);
|
|
236
|
+
}
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
if (refreshShells) {
|
|
240
|
+
refreshShells = false;
|
|
241
|
+
observeContent(level);
|
|
242
|
+
}
|
|
243
|
+
const added = arrived;
|
|
244
|
+
arrived = new Set();
|
|
245
|
+
busy = isBusy();
|
|
246
|
+
loadingChange = false;
|
|
247
|
+
const wasResize = resized;
|
|
248
|
+
resized = false;
|
|
249
|
+
// Release only the top owned here, before own-size/detent handling and natural-height measurement.
|
|
250
|
+
if (anchorChanged) {
|
|
251
|
+
if (placed) place(0);
|
|
252
|
+
followingAnchor = where;
|
|
253
|
+
}
|
|
254
|
+
const shown = seen();
|
|
255
|
+
if (wasResize && where === "center" && !placed && !anchorChanged) shown.top -= (window.innerHeight - viewportHeight) / 2;
|
|
256
|
+
viewportHeight = window.innerHeight;
|
|
257
|
+
const interrupted = Boolean(frame);
|
|
258
|
+
if (interrupted) endFrame();
|
|
259
|
+
// All measurement and layout writes run here, in a frame, never inside an observer delivery.
|
|
260
|
+
dialog.style.removeProperty("height");
|
|
261
|
+
if (ownSize()) {
|
|
262
|
+
rested = seen().height;
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
const natural = seen().height;
|
|
266
|
+
const canFold = firstRest && !initialMeasure && !loading;
|
|
267
|
+
const height = canFold && !wasResize && textFocused() ? Math.max(natural, shown.height) : natural;
|
|
268
|
+
const from = interrupted ? shown.height : rested;
|
|
269
|
+
const edge = edgeFor({
|
|
270
|
+
...shown,
|
|
271
|
+
height: from
|
|
272
|
+
}, height);
|
|
273
|
+
const offset = edge + height / 2 - window.innerHeight / 2;
|
|
274
|
+
const moving = dialog.getAnimations().filter(animation => animation.playState === "running" || animation.playState === "paused");
|
|
275
|
+
const duration = canFold && (!wasResize || interrupted) && !moving.length && animatable() ? token("--k2b-motion-fold") : 0;
|
|
276
|
+
initialMeasure = false;
|
|
277
|
+
holdHeight(height);
|
|
278
|
+
if (!duration || Math.abs(height - from) < 1) {
|
|
279
|
+
if (where === "center") place(firstRest && !anchorChanged ? offset : 0);
|
|
280
|
+
if (Math.abs(height - from) >= 1 || wasResize) dialog.dispatchEvent(new Event("k2b-frame-resize"));
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
// Both edges begin where the eye sees them. Top and height share one curve, so the bottom stays in view.
|
|
284
|
+
const top = shown.top - from / 2;
|
|
285
|
+
if (where === "center") place(offset);
|
|
286
|
+
const keyframes = where === "center" ? [{
|
|
287
|
+
height: `${from}px`,
|
|
288
|
+
top: `${top + from / 2}px`
|
|
289
|
+
}, {
|
|
290
|
+
height: `${height}px`,
|
|
291
|
+
top: `${window.innerHeight / 2 + offset}px`
|
|
292
|
+
}] : [{
|
|
293
|
+
height: `${from}px`
|
|
294
|
+
}, {
|
|
295
|
+
height: `${height}px`
|
|
296
|
+
}];
|
|
297
|
+
dialog.dataset.k2bFrameMotion = "";
|
|
298
|
+
const animation = dialog.animate(keyframes, {
|
|
299
|
+
duration,
|
|
300
|
+
easing: curve("--k2b-ease-glide", "ease-out")
|
|
301
|
+
});
|
|
302
|
+
frame = animation;
|
|
303
|
+
frameKind = "fold";
|
|
304
|
+
animation.onfinish = () => {
|
|
305
|
+
if (frame !== animation) return;
|
|
306
|
+
if (where === "center") place(offset);
|
|
307
|
+
endFrame();
|
|
308
|
+
dialog.dispatchEvent(new Event("k2b-frame-resize"));
|
|
309
|
+
// An image or font can change intrinsic size while the frame clips its content.
|
|
310
|
+
changed();
|
|
311
|
+
};
|
|
312
|
+
if (height > from) {
|
|
313
|
+
const fast = token("--k2b-motion-fast");
|
|
314
|
+
const active = document.activeElement;
|
|
315
|
+
const inFlow = element => {
|
|
316
|
+
for (let node = element; node && node !== level; node = node.parentElement) if (node.getAttribute("aria-hidden") === "true" || /^(absolute|fixed)$/.test(getComputedStyle(node).position)) return false;
|
|
317
|
+
return true;
|
|
318
|
+
};
|
|
319
|
+
for (const element of added) if (element.isConnected && !element.contains(active) && !active?.contains(element) && inFlow(element)) fade(element, 1, fast, duration * FOLD_DELAY_SHARE, () => {});
|
|
320
|
+
}
|
|
321
|
+
};
|
|
322
|
+
const waiting = new WeakSet();
|
|
323
|
+
const known = new WeakSet();
|
|
324
|
+
let firstDelivery = true;
|
|
325
|
+
let followingMorph = false;
|
|
326
|
+
const measured = new WeakMap();
|
|
327
|
+
const watched = new Set();
|
|
328
|
+
const shells = new WeakSet();
|
|
329
|
+
let refreshShells = false;
|
|
330
|
+
let sizes;
|
|
331
|
+
const createSizes = () => typeof ResizeObserver === "function" ? new ResizeObserver(entries => {
|
|
332
|
+
let resized = false;
|
|
333
|
+
const initial = firstDelivery;
|
|
334
|
+
firstDelivery = false;
|
|
335
|
+
for (const {
|
|
336
|
+
target,
|
|
337
|
+
borderBoxSize,
|
|
338
|
+
contentRect
|
|
339
|
+
} of entries) {
|
|
340
|
+
const box = borderBoxSize?.[0];
|
|
341
|
+
const width = box?.inlineSize ?? contentRect.width;
|
|
342
|
+
const height = box?.blockSize ?? contentRect.height;
|
|
343
|
+
const previous = measured.get(target);
|
|
344
|
+
measured.set(target, {
|
|
345
|
+
width,
|
|
346
|
+
height
|
|
347
|
+
});
|
|
348
|
+
const changedSize = previous === undefined || !Number.isFinite(previous.width) || !Number.isFinite(previous.height) || Math.abs(width - previous.width) >= 0.01 || Math.abs(height - previous.height) >= 0.01;
|
|
349
|
+
resized ||= changedSize && (frameKind !== "fold" || !shells.has(target));
|
|
350
|
+
}
|
|
351
|
+
initialMeasure ||= initial && resized && !followingMorph;
|
|
352
|
+
if (resized) changed();
|
|
353
|
+
}) : undefined;
|
|
354
|
+
|
|
355
|
+
// Watch the structural shells down to natural-flow content, not every rendered row, word, or editor overlay.
|
|
356
|
+
// A flex/grid or scrolling shell can be stretched by the held frame, so its children report intrinsic changes.
|
|
357
|
+
// This traversal runs once per level; a preview replacing hundreds of descendants needs no observe/unobserve calls.
|
|
358
|
+
const observeContent = (element, pending = [], stretched = true) => {
|
|
359
|
+
const style = getComputedStyle(element);
|
|
360
|
+
// Positioned overlays (for example MarkdownEditor's highlighted copy) do not contribute to the frame's height.
|
|
361
|
+
if (element !== level && (element.getAttribute("aria-hidden") === "true" || style.position === "absolute" || style.position === "fixed")) return;
|
|
362
|
+
if (!watched.has(element)) {
|
|
363
|
+
watched.add(element);
|
|
364
|
+
// Intrinsic padding and borders change the height the frame needs even when the content box stays put.
|
|
365
|
+
// Match the observer's border box before its first delivery, preserving fractional layout dimensions.
|
|
366
|
+
const inset = axis => style.boxSizing === "border-box" ? 0 : axis === "width" ? Number.parseFloat(style.paddingLeft) + Number.parseFloat(style.paddingRight) + Number.parseFloat(style.borderLeftWidth) + Number.parseFloat(style.borderRightWidth) : Number.parseFloat(style.paddingTop) + Number.parseFloat(style.paddingBottom) + Number.parseFloat(style.borderTopWidth) + Number.parseFloat(style.borderBottomWidth);
|
|
367
|
+
measured.set(element, {
|
|
368
|
+
width: Number.parseFloat(style.width) + inset("width"),
|
|
369
|
+
height: Number.parseFloat(style.height) + inset("height")
|
|
370
|
+
});
|
|
371
|
+
pending.push(element);
|
|
372
|
+
}
|
|
373
|
+
// Only boxes stretched by the held frame need another observation level. A natural row already reports
|
|
374
|
+
// all its descendants, even when it happens to use flex or grid internally.
|
|
375
|
+
if (stretched && (element === level || /flex|grid|contents/.test(style.display) || /auto|scroll/.test(style.overflowY))) {
|
|
376
|
+
shells.add(element);
|
|
377
|
+
for (const child of element.children) {
|
|
378
|
+
const childStyle = getComputedStyle(child);
|
|
379
|
+
const grows = childStyle.flexGrow !== "0";
|
|
380
|
+
const crossStretch = /flex/.test(style.display) && !style.flexDirection.startsWith("column") && (childStyle.alignSelf === "stretch" || childStyle.alignSelf === "auto" && /normal|stretch/.test(style.alignItems));
|
|
381
|
+
observeContent(child, pending, grows || crossStretch || /grid|contents/.test(style.display));
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
if (element === level) for (const target of pending) sizes?.observe(target, {
|
|
385
|
+
box: "border-box"
|
|
386
|
+
});
|
|
387
|
+
};
|
|
388
|
+
let changes;
|
|
389
|
+
const createChanges = () => typeof MutationObserver === "function" ? new MutationObserver(records => {
|
|
390
|
+
// Once per batch, keep only live observation targets. Losing an observed root (including the last
|
|
391
|
+
// body child) is itself a size signal; the held shells cannot report that removal for us.
|
|
392
|
+
for (const target of watched) if (!target.isConnected || !level?.contains(target)) {
|
|
393
|
+
changed();
|
|
394
|
+
sizes?.unobserve(target);
|
|
395
|
+
watched.delete(target);
|
|
396
|
+
}
|
|
397
|
+
for (const record of records) for (const node of record.removedNodes) if (node instanceof Element) known.add(node);
|
|
398
|
+
const eligible = node => {
|
|
399
|
+
for (let parent = node; parent && parent !== level; parent = parent.parentElement) if (parent.getAttribute("aria-hidden") === "true" || /^(absolute|fixed)$/.test(parent.style.position)) return false;
|
|
400
|
+
return Boolean(level?.contains(node));
|
|
401
|
+
};
|
|
402
|
+
for (const record of records) {
|
|
403
|
+
if (record.type === "childList") {
|
|
404
|
+
for (const node of record.removedNodes) if (node instanceof Element) loadingChange ||= isBusyNode(node);
|
|
405
|
+
for (const node of record.addedNodes) if (node instanceof HTMLElement) {
|
|
406
|
+
const inFlow = eligible(node);
|
|
407
|
+
if (!known.has(node) && inFlow) arrived.add(node);
|
|
408
|
+
known.add(node);
|
|
409
|
+
loadingChange ||= isBusyNode(node);
|
|
410
|
+
if (inFlow && record.target instanceof Element && shells.has(record.target)) {
|
|
411
|
+
// Registration has no layout read. The first report schedules structural discovery in a frame.
|
|
412
|
+
watched.add(node);
|
|
413
|
+
sizes?.observe(node, {
|
|
414
|
+
box: "border-box"
|
|
415
|
+
});
|
|
416
|
+
refreshShells = true;
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
} else if (record.type === "attributes" && record.target instanceof HTMLElement) {
|
|
420
|
+
if (record.attributeName === "aria-busy" && record.oldValue === "true" && !record.target.matches('button, [role="button"]')) loadingChange = true;
|
|
421
|
+
if (record.attributeName === "hidden") {
|
|
422
|
+
if (!record.target.hidden && eligible(record.target)) arrived.add(record.target);
|
|
423
|
+
changed();
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
for (const node of arrived) {
|
|
428
|
+
if (!eligible(node)) {
|
|
429
|
+
arrived.delete(node);
|
|
430
|
+
continue;
|
|
431
|
+
}
|
|
432
|
+
// Fade the outer arrival once, rather than fading every inserted descendant as well.
|
|
433
|
+
for (let parent = node.parentElement; parent && parent !== level; parent = parent.parentElement) if (arrived.has(parent)) {
|
|
434
|
+
arrived.delete(node);
|
|
435
|
+
break;
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
if (arrivalFrame) cancelAnimationFrame(arrivalFrame);
|
|
439
|
+
// Let this batch's layout/ResizeObserver wave enqueue its measurement first. Unchanged previews
|
|
440
|
+
// expire after that frame, without forcing layout or waiting for an unrelated later fold.
|
|
441
|
+
arrivalFrame = requestAnimationFrame(() => {
|
|
442
|
+
arrivalFrame = requestAnimationFrame(() => {
|
|
443
|
+
arrivalFrame = 0;
|
|
444
|
+
if (!queued && frameKind !== "fold") arrived.clear();
|
|
445
|
+
});
|
|
446
|
+
});
|
|
447
|
+
}) : undefined;
|
|
448
|
+
const onFocusOut = () => {
|
|
449
|
+
deferredFold = true;
|
|
450
|
+
if (!pointers.size) changed();
|
|
451
|
+
};
|
|
452
|
+
const onFocusIn = () => {
|
|
453
|
+
if (!textFocused() || frameKind !== "fold") return;
|
|
454
|
+
const shown = seen();
|
|
455
|
+
if (rested >= shown.height) return;
|
|
456
|
+
holdHeight(shown.height);
|
|
457
|
+
if (followAnchor() === "center") place(shown.top - window.innerHeight / 2);
|
|
458
|
+
endFrame();
|
|
459
|
+
};
|
|
460
|
+
const onPointerDown = event => {
|
|
461
|
+
pointers.add(event.pointerId);
|
|
462
|
+
if (frameKind !== "fold") return;
|
|
463
|
+
const shown = seen();
|
|
464
|
+
holdHeight(shown.height);
|
|
465
|
+
if (followAnchor() === "center") place(shown.top - window.innerHeight / 2);
|
|
466
|
+
endFrame();
|
|
467
|
+
deferredFold = true;
|
|
468
|
+
};
|
|
469
|
+
const onPointerEnd = event => {
|
|
470
|
+
if (event.buttons === 0) {
|
|
471
|
+
releasePointers();
|
|
472
|
+
return;
|
|
473
|
+
}
|
|
474
|
+
pointers.delete(event.pointerId);
|
|
475
|
+
if (!pointers.size && deferredFold) changed();
|
|
476
|
+
};
|
|
477
|
+
// A release in an iframe or outside this window need not deliver pointerup here. Recover on the next
|
|
478
|
+
// trustworthy signal, without a timeout that could move a control underneath a real held press.
|
|
479
|
+
const releasePointers = () => {
|
|
480
|
+
if (!pointers.size) return;
|
|
481
|
+
pointers.clear();
|
|
482
|
+
changed();
|
|
483
|
+
};
|
|
484
|
+
const onPointer = event => {
|
|
485
|
+
if (event.buttons === 0) releasePointers();
|
|
486
|
+
};
|
|
487
|
+
const pointerEvents = ["pointerdown", "pointermove", "pointerover", "pointerout", "pointerenter", "pointerleave", "gotpointercapture"];
|
|
488
|
+
const onVisibility = () => {
|
|
489
|
+
if (document.visibilityState === "hidden") releasePointers();
|
|
490
|
+
};
|
|
491
|
+
const onResize = () => {
|
|
492
|
+
resized = true;
|
|
493
|
+
changed();
|
|
494
|
+
};
|
|
495
|
+
const onVisualResize = () => {
|
|
496
|
+
if (window.visualViewport?.scale === 1) onResize();
|
|
497
|
+
};
|
|
498
|
+
const follow = (next, enabled = false) => {
|
|
499
|
+
dialog.toggleAttribute("data-k2b-follow-content", enabled);
|
|
500
|
+
if (!enabled) return;
|
|
501
|
+
sizes ??= createSizes();
|
|
502
|
+
changes ??= createChanges();
|
|
503
|
+
sizes?.disconnect();
|
|
504
|
+
watched.clear();
|
|
505
|
+
changes?.disconnect();
|
|
506
|
+
if (queued) cancelAnimationFrame(queued);
|
|
507
|
+
queued = 0;
|
|
508
|
+
level = next;
|
|
509
|
+
firstDelivery = true;
|
|
510
|
+
followingMorph = frameKind === "morph";
|
|
511
|
+
initialMeasure = false;
|
|
512
|
+
followingAnchor = followAnchor();
|
|
513
|
+
viewportHeight = window.innerHeight;
|
|
514
|
+
arrived = new Set();
|
|
515
|
+
busy = isBusy();
|
|
516
|
+
loadingChange = busy;
|
|
517
|
+
// A morph's pinned content has its final size already. Its observer begins measuring after the morph releases it.
|
|
518
|
+
if (frameKind !== "morph") {
|
|
519
|
+
rested = seen().height;
|
|
520
|
+
if (!ownSize()) holdHeight(rested);
|
|
521
|
+
}
|
|
522
|
+
known.add(next);
|
|
523
|
+
for (const child of next.querySelectorAll("*")) known.add(child);
|
|
524
|
+
observeContent(next);
|
|
525
|
+
changes?.observe(next, {
|
|
526
|
+
subtree: true,
|
|
527
|
+
childList: true,
|
|
528
|
+
attributes: true,
|
|
529
|
+
attributeOldValue: true,
|
|
530
|
+
attributeFilter: ["hidden", "aria-busy"]
|
|
531
|
+
});
|
|
532
|
+
next.addEventListener("focusout", onFocusOut);
|
|
533
|
+
next.addEventListener("focusin", onFocusIn);
|
|
534
|
+
dialog.addEventListener("pointerdown", onPointerDown, true);
|
|
535
|
+
window.addEventListener("pointerup", onPointerEnd, true);
|
|
536
|
+
window.addEventListener("pointercancel", onPointerEnd, true);
|
|
537
|
+
for (const type of pointerEvents) window.addEventListener(type, onPointer, true);
|
|
538
|
+
window.addEventListener("lostpointercapture", releasePointers, true);
|
|
539
|
+
window.addEventListener("blur", releasePointers);
|
|
540
|
+
document.addEventListener("visibilitychange", onVisibility);
|
|
541
|
+
window.addEventListener("resize", onResize);
|
|
542
|
+
window.visualViewport?.addEventListener("resize", onVisualResize);
|
|
543
|
+
if (!firstRest) {
|
|
544
|
+
const markRest = () => {
|
|
545
|
+
restFrame = 0;
|
|
546
|
+
if (level !== next) return;
|
|
547
|
+
const moving = dialog.getAnimations().filter(animation => animation.playState === "running" || animation.playState === "paused");
|
|
548
|
+
if (!moving.length) firstRest = true;else void Promise.allSettled(moving.map(animation => animation.finished)).then(() => {
|
|
549
|
+
if (level === next) restFrame = requestAnimationFrame(markRest);
|
|
550
|
+
});
|
|
551
|
+
};
|
|
552
|
+
restFrame = requestAnimationFrame(markRest);
|
|
553
|
+
}
|
|
554
|
+
};
|
|
555
|
+
const unfollow = () => {
|
|
556
|
+
sizes?.disconnect();
|
|
557
|
+
watched.clear();
|
|
558
|
+
changes?.disconnect();
|
|
559
|
+
if (queued) cancelAnimationFrame(queued);
|
|
560
|
+
if (restFrame) cancelAnimationFrame(restFrame);
|
|
561
|
+
restFrame = 0;
|
|
562
|
+
queued = 0;
|
|
563
|
+
level?.removeEventListener("focusout", onFocusOut);
|
|
564
|
+
level?.removeEventListener("focusin", onFocusIn);
|
|
565
|
+
dialog.removeEventListener("pointerdown", onPointerDown, true);
|
|
566
|
+
window.removeEventListener("pointerup", onPointerEnd, true);
|
|
567
|
+
window.removeEventListener("pointercancel", onPointerEnd, true);
|
|
568
|
+
for (const type of pointerEvents) window.removeEventListener(type, onPointer, true);
|
|
569
|
+
window.removeEventListener("lostpointercapture", releasePointers, true);
|
|
570
|
+
window.removeEventListener("blur", releasePointers);
|
|
571
|
+
document.removeEventListener("visibilitychange", onVisibility);
|
|
572
|
+
pointers.clear();
|
|
573
|
+
deferredFold = false;
|
|
574
|
+
if (arrivalFrame) cancelAnimationFrame(arrivalFrame);
|
|
575
|
+
arrivalFrame = 0;
|
|
576
|
+
arrived.clear();
|
|
577
|
+
level = undefined;
|
|
578
|
+
window.removeEventListener("resize", onResize);
|
|
579
|
+
window.visualViewport?.removeEventListener("resize", onVisualResize);
|
|
580
|
+
};
|
|
134
581
|
let started;
|
|
135
582
|
/** The frame scrolls its contents itself, as unstructured content does. */
|
|
136
583
|
const scrolled = () => dialog.scrollTop > 0 || dialog.scrollLeft > 0;
|
|
137
584
|
const begin = (leaving, back) => {
|
|
585
|
+
unfollow();
|
|
138
586
|
started = {
|
|
139
587
|
from: seen(),
|
|
140
588
|
anchor: anchor(),
|
|
@@ -142,11 +590,14 @@ export const createFrameMotion = dialog => {
|
|
|
142
590
|
scrolled: scrolled()
|
|
143
591
|
};
|
|
144
592
|
endFrame();
|
|
593
|
+
dialog.style.removeProperty("height");
|
|
145
594
|
hold(leaving);
|
|
146
595
|
// The frame clips from now on: the held content, larger than the new one, must not give it a scrollbar while the
|
|
147
596
|
// new content is measured and pinned (a classic scrollbar would narrow it until the old content has gone). A frame
|
|
148
597
|
// that scrolls itself swaps at once and keeps its scroll place instead.
|
|
149
598
|
if (!started.scrolled) dialog.dataset.k2bFrameMotion = "";
|
|
599
|
+
// A level that replaces another stands in the centre again.
|
|
600
|
+
place(0);
|
|
150
601
|
if (!back) return;
|
|
151
602
|
// The shown level stays the dialog's last child, as sheets and tone rules expect; the closed one moves before it,
|
|
152
603
|
// with the scroll places the dialog core kept for it.
|
|
@@ -163,10 +614,11 @@ export const createFrameMotion = dialog => {
|
|
|
163
614
|
};
|
|
164
615
|
requestAnimationFrame(() => fresh ? requestAnimationFrame(say) : say());
|
|
165
616
|
};
|
|
166
|
-
const arrive = (arriving, left) => {
|
|
617
|
+
const arrive = (arriving, left, followContent = false) => {
|
|
167
618
|
const change = started;
|
|
168
619
|
started = undefined;
|
|
169
620
|
if (!change) return;
|
|
621
|
+
dialog.toggleAttribute("data-k2b-follow-content", followContent);
|
|
170
622
|
const {
|
|
171
623
|
from,
|
|
172
624
|
leaving
|
|
@@ -194,6 +646,7 @@ export const createFrameMotion = dialog => {
|
|
|
194
646
|
delete dialog.dataset.k2bFrameMotion;
|
|
195
647
|
fade(leaving, 0, 0, 0, leave);
|
|
196
648
|
fade(arriving, 1, 0, 0, () => {});
|
|
649
|
+
follow(arriving, followContent);
|
|
197
650
|
return;
|
|
198
651
|
}
|
|
199
652
|
const to = seen();
|
|
@@ -216,19 +669,29 @@ export const createFrameMotion = dialog => {
|
|
|
216
669
|
easing: curve("--k2b-ease-morph", "ease-out")
|
|
217
670
|
});
|
|
218
671
|
frame = animation;
|
|
672
|
+
frameKind = "morph";
|
|
219
673
|
// The new content keeps its final size until the frame has arrived there too, so it never rewraps; its fade
|
|
220
674
|
// ends earlier (at 250 of 280 ms).
|
|
221
675
|
animation.onfinish = () => {
|
|
222
676
|
if (frame !== animation) return;
|
|
223
677
|
endFrame();
|
|
224
678
|
for (const property of ["width", "height", "flex"]) arriving.style.removeProperty(property);
|
|
225
|
-
// A sheet measures its rests again at the
|
|
679
|
+
// A sheet measures its rests again at the size the morph reached.
|
|
226
680
|
dialog.dispatchEvent(new Event("k2b-frame-resize"));
|
|
681
|
+
// Content that changed during the morph gets a fold from the size the morph reached.
|
|
682
|
+
if (followContent) {
|
|
683
|
+
holdHeight(to.height);
|
|
684
|
+
firstRest = true;
|
|
685
|
+
changed();
|
|
686
|
+
}
|
|
227
687
|
};
|
|
688
|
+
follow(arriving, followContent);
|
|
689
|
+
rested = to.height;
|
|
228
690
|
fade(leaving, 0, duration * LEAVE_SHARE, 0, leave);
|
|
229
691
|
fade(arriving, 1, duration * ARRIVE_SHARE, duration * ARRIVE_DELAY_SHARE, () => {});
|
|
230
692
|
};
|
|
231
693
|
const stop = () => {
|
|
694
|
+
unfollow();
|
|
232
695
|
started = undefined;
|
|
233
696
|
endFrame();
|
|
234
697
|
const pending = [...fades.values()];
|
|
@@ -242,6 +705,7 @@ export const createFrameMotion = dialog => {
|
|
|
242
705
|
}
|
|
243
706
|
};
|
|
244
707
|
const freeze = () => {
|
|
708
|
+
unfollow();
|
|
245
709
|
started = undefined;
|
|
246
710
|
// What the eye sees stays: the running values become the frame's and the contents' own styles.
|
|
247
711
|
if (frame) {
|
|
@@ -249,26 +713,53 @@ export const createFrameMotion = dialog => {
|
|
|
249
713
|
frame.cancel();
|
|
250
714
|
frame = undefined;
|
|
251
715
|
}
|
|
252
|
-
const pending = [...fades
|
|
716
|
+
const pending = [...fades];
|
|
253
717
|
fades.clear();
|
|
254
|
-
for (const {
|
|
718
|
+
for (const [element, {
|
|
255
719
|
animation
|
|
256
|
-
} of pending) {
|
|
257
|
-
animation.commitStyles();
|
|
720
|
+
}] of pending) {
|
|
721
|
+
if (element.getClientRects().length) animation.commitStyles();
|
|
258
722
|
animation.cancel();
|
|
259
723
|
}
|
|
260
724
|
return () => {
|
|
261
|
-
for (const {
|
|
725
|
+
for (const [, {
|
|
262
726
|
done
|
|
263
|
-
} of pending) done();
|
|
727
|
+
}] of pending) done();
|
|
264
728
|
};
|
|
265
729
|
};
|
|
730
|
+
const position = (previous, next) => {
|
|
731
|
+
if (previous?.x === next?.x && previous?.y === next?.y) return false;
|
|
732
|
+
const folding = frameKind === "fold";
|
|
733
|
+
if (folding) {
|
|
734
|
+
holdHeight(seen().height);
|
|
735
|
+
endFrame();
|
|
736
|
+
}
|
|
737
|
+
dialog.style.inset = "";
|
|
738
|
+
placed = false;
|
|
739
|
+
followingAnchor = undefined;
|
|
740
|
+
// A fold stopped by the move resumes from the held height once the new place applies.
|
|
741
|
+
if (folding) changed();
|
|
742
|
+
return true;
|
|
743
|
+
};
|
|
266
744
|
return {
|
|
267
745
|
begin,
|
|
268
746
|
arrive,
|
|
269
747
|
announce,
|
|
748
|
+
follow,
|
|
270
749
|
stop,
|
|
271
|
-
freeze
|
|
750
|
+
freeze,
|
|
751
|
+
position
|
|
272
752
|
};
|
|
273
753
|
};
|
|
754
|
+
|
|
755
|
+
/** Every successful import, including retries, joins the current frame once and follows its current level. */
|
|
756
|
+
export const connectFrameMotion = (state, announced) => {
|
|
757
|
+
if (!state.element?.isConnected) return;
|
|
758
|
+
const top = state.stack.at(-1);
|
|
759
|
+
if (!state.motion) {
|
|
760
|
+
state.motion = createFrameMotion(state.element);
|
|
761
|
+
if (top) state.motion.follow(top.container, top.follow);
|
|
762
|
+
}
|
|
763
|
+
if (top && top === announced) state.motion.announce(top.role);
|
|
764
|
+
};
|
|
274
765
|
//# sourceMappingURL=dialog-frame-motion.js.map
|