@celestia-island/hikari 0.55.514 → 0.55.515
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/package.json
CHANGED
|
@@ -45,8 +45,8 @@ afterEach(() => {
|
|
|
45
45
|
container.remove();
|
|
46
46
|
}
|
|
47
47
|
vi.useRealTimers();
|
|
48
|
-
// The
|
|
49
|
-
//
|
|
48
|
+
// The net for spies whose finally did not run (an assertion throwing
|
|
49
|
+
// first): restore every mock left behind.
|
|
50
50
|
vi.restoreAllMocks();
|
|
51
51
|
});
|
|
52
52
|
|
|
@@ -172,22 +172,31 @@ describe("HkDirectionalSwap", () => {
|
|
|
172
172
|
// ── animateHeight (opt-in height tween) ─────────────────────────────
|
|
173
173
|
// happy-dom has no layout engine: every offsetHeight reads 0, so the
|
|
174
174
|
// tween (freeze a rendered height, step to a target) runs against
|
|
175
|
-
// STUBBED heights — without a stub the
|
|
176
|
-
// tween and every assertion would pass for the wrong reason.
|
|
177
|
-
//
|
|
178
|
-
//
|
|
179
|
-
//
|
|
180
|
-
//
|
|
181
|
-
|
|
182
|
-
/**
|
|
183
|
-
*
|
|
184
|
-
*
|
|
175
|
+
// STUBBED heights — without a stub the unreadable-height guard skips
|
|
176
|
+
// the whole tween and every assertion would pass for the wrong reason.
|
|
177
|
+
// The tween's writes are SYNCHRONOUS inside the enter hook (no
|
|
178
|
+
// animation frames by design — frames starve in background tabs and
|
|
179
|
+
// automation), so armed-and-targeted is observable one tick after the
|
|
180
|
+
// swap and released after the exchange's settle.
|
|
181
|
+
|
|
182
|
+
/** The host's offsetHeight READ COUNT under the current stubLayout —
|
|
183
|
+
* reset on every install. The tween's forced layout (the flush between
|
|
184
|
+
* its freeze and its target) is one extra host read, so a pin can
|
|
185
|
+
* require it: R4's M-no-flush (deleting `void host.offsetHeight`) was
|
|
186
|
+
* invisible to every read-based pin because a constant stub reads the
|
|
187
|
+
* same however many times. */
|
|
188
|
+
const hostReads = { count: 0 };
|
|
189
|
+
|
|
190
|
+
/** Shadow offsetHeight for the swap's two element kinds (host reads are
|
|
191
|
+
* counted into `hostReads`). Returns the restore thunk. */
|
|
185
192
|
function stubLayout(hostH: () => number, itemH: () => number): () => void {
|
|
186
193
|
const proto = HTMLElement.prototype;
|
|
187
194
|
const shadow = Object.getOwnPropertyDescriptor(proto, "offsetHeight");
|
|
195
|
+
hostReads.count = 0;
|
|
188
196
|
Object.defineProperty(proto, "offsetHeight", {
|
|
189
197
|
configurable: true,
|
|
190
198
|
get(this: HTMLElement) {
|
|
199
|
+
if (!this.classList.contains("hk-dswap-item")) hostReads.count += 1;
|
|
191
200
|
return this.classList.contains("hk-dswap-item") ? itemH() : hostH();
|
|
192
201
|
},
|
|
193
202
|
});
|
|
@@ -197,11 +206,43 @@ describe("HkDirectionalSwap", () => {
|
|
|
197
206
|
};
|
|
198
207
|
}
|
|
199
208
|
|
|
200
|
-
/**
|
|
201
|
-
*
|
|
202
|
-
*
|
|
203
|
-
*
|
|
204
|
-
*
|
|
209
|
+
/** Shadow the STYLE object's height setter on one element and record
|
|
210
|
+
* every write. happy-dom's height reads are all-equivalent (no
|
|
211
|
+
* layout), so "did the tween actually write the freeze and the
|
|
212
|
+
* target" is observable ONLY through the writes themselves — the R1
|
|
213
|
+
* M10 killer: an implementation that arms the attribute and never
|
|
214
|
+
* writes a single height passed every read-based pin. Returns
|
|
215
|
+
* { writes, restore }. */
|
|
216
|
+
function spyHeightWrites(
|
|
217
|
+
el: HTMLElement,
|
|
218
|
+
onWrite?: () => void,
|
|
219
|
+
): { writes: string[]; restore: () => void } {
|
|
220
|
+
const writes: string[] = [];
|
|
221
|
+
const desc = Object.getOwnPropertyDescriptor(CSSStyleDeclaration.prototype, "height")!;
|
|
222
|
+
Object.defineProperty(el.style, "height", {
|
|
223
|
+
configurable: true,
|
|
224
|
+
get() {
|
|
225
|
+
return desc.get!.call(this);
|
|
226
|
+
},
|
|
227
|
+
set(v: string) {
|
|
228
|
+
writes.push(v);
|
|
229
|
+
onWrite?.();
|
|
230
|
+
desc.set!.call(this, v);
|
|
231
|
+
},
|
|
232
|
+
});
|
|
233
|
+
return {
|
|
234
|
+
writes,
|
|
235
|
+
restore: () => {
|
|
236
|
+
delete (el.style as unknown as Record<string, unknown>).height;
|
|
237
|
+
},
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
const descGet = Object.getOwnPropertyDescriptor(CSSStyleDeclaration.prototype, "height")!.get!;
|
|
242
|
+
const descSet = Object.getOwnPropertyDescriptor(CSSStyleDeclaration.prototype, "height")!.set!;
|
|
243
|
+
|
|
244
|
+
/** Drive microtasks/frames until `cond` holds; assert on failure so a
|
|
245
|
+
* stuck wait names itself instead of timing out silently. */
|
|
205
246
|
async function until(cond: () => boolean, label: string): Promise<void> {
|
|
206
247
|
for (let i = 0; i < 5 && !cond(); i += 1) {
|
|
207
248
|
await new Promise((r) => requestAnimationFrame(() => r(null)));
|
|
@@ -217,6 +258,12 @@ describe("HkDirectionalSwap", () => {
|
|
|
217
258
|
// armed-guard in endHeightAnimation (R1 S1-1: an unconditional release
|
|
218
259
|
// erased a host's own inline height on a default-off instance).
|
|
219
260
|
it("keeps the snap and preserves a host-set height when animateHeight is off (default)", async () => {
|
|
261
|
+
// Bare fake timers (rAF included): the exchange resolves through
|
|
262
|
+
// them deterministically — a REAL settle yields to the event loop and
|
|
263
|
+
// lets real rAF frames race the erase, which R2 N2 measured at a
|
|
264
|
+
// ~36% miss. We inject a real resolve point into the exchange via
|
|
265
|
+
// the fake clock instead.
|
|
266
|
+
vi.useFakeTimers();
|
|
220
267
|
const restore = stubLayout(() => 100, () => 240);
|
|
221
268
|
try {
|
|
222
269
|
const key = ref("preview");
|
|
@@ -225,7 +272,7 @@ describe("HkDirectionalSwap", () => {
|
|
|
225
272
|
const app = createApp({ render: () => h(HkDirectionalSwap, { swapKey: key.value }, () => [h("p", key.value)]) });
|
|
226
273
|
app.mount(container);
|
|
227
274
|
mounts.push({ app, container });
|
|
228
|
-
await
|
|
275
|
+
await vi.advanceTimersByTimeAsync(0);
|
|
229
276
|
const host = container.querySelector<HTMLElement>(".hk-dswap")!;
|
|
230
277
|
// The host's own inline height (its business, not ours).
|
|
231
278
|
host.style.height = "42px";
|
|
@@ -233,21 +280,29 @@ describe("HkDirectionalSwap", () => {
|
|
|
233
280
|
await nextTick();
|
|
234
281
|
await nextTick();
|
|
235
282
|
expect(host.hasAttribute("data-height-anim")).toBe(false);
|
|
236
|
-
|
|
283
|
+
// Advance past the exchange's resolution timer: the after-hooks
|
|
284
|
+
// fire (they fire on every exchange, prop on or off) — with the
|
|
285
|
+
// armed-guard deleted the release erases the host's own height
|
|
286
|
+
// HERE, after the wait, and this pin goes red.
|
|
287
|
+
await vi.advanceTimersByTimeAsync(1600);
|
|
288
|
+
expect(host.hasAttribute("data-height-anim")).toBe(false);
|
|
237
289
|
expect(host.style.height).toBe("42px");
|
|
238
290
|
} finally {
|
|
239
291
|
restore();
|
|
292
|
+
vi.useRealTimers();
|
|
240
293
|
}
|
|
241
294
|
});
|
|
242
295
|
|
|
243
|
-
// MUT:swap-height-anim-arms — with the prop the exchange
|
|
244
|
-
// the
|
|
245
|
-
//
|
|
246
|
-
//
|
|
247
|
-
//
|
|
248
|
-
//
|
|
249
|
-
//
|
|
250
|
-
|
|
296
|
+
// MUT:swap-height-anim-arms — with the prop the exchange arms the tween
|
|
297
|
+
// and lands the incoming generation's height SYNCHRONOUSLY (the forced
|
|
298
|
+
// layout between the freeze and this write is what makes them a
|
|
299
|
+
// before/after pair — the freeze itself is same-tick and
|
|
300
|
+
// unobservable from outside), then releases to auto on settle. A
|
|
301
|
+
// regression that never writes the target leaves the frozen start
|
|
302
|
+
// value behind and turns the mid assertion red; a regression that
|
|
303
|
+
// skips the freeze turns the release semantics red (nothing armed →
|
|
304
|
+
// nothing to release → the host keeps whatever it had).
|
|
305
|
+
it("arms the tween, lands the incoming height, and releases on settle", async () => {
|
|
251
306
|
const restore = stubLayout(() => 100, () => 240);
|
|
252
307
|
try {
|
|
253
308
|
const key = ref("preview");
|
|
@@ -260,39 +315,49 @@ describe("HkDirectionalSwap", () => {
|
|
|
260
315
|
mounts.push({ app, container });
|
|
261
316
|
await settle();
|
|
262
317
|
const host = container.querySelector<HTMLElement>(".hk-dswap")!;
|
|
318
|
+
const readsAtWrite: number[] = [];
|
|
319
|
+
const { writes, restore: unspy } = spyHeightWrites(host, () => {
|
|
320
|
+
readsAtWrite.push(hostReads.count);
|
|
321
|
+
});
|
|
322
|
+
expect(host.hasAttribute("data-height-anim")).toBe(false);
|
|
323
|
+
hostReads.count = 0;
|
|
263
324
|
key.value = "source";
|
|
264
325
|
await nextTick();
|
|
265
326
|
await nextTick();
|
|
266
|
-
//
|
|
327
|
+
// Mid-exchange: the tween armed and BOTH writes landed, in order:
|
|
328
|
+
// freeze at the current height (100px), then the target (240px).
|
|
329
|
+
// An implementation that arms but never writes (R1 M10: both
|
|
330
|
+
// writes deleted, every read-based pin green) writes nothing and
|
|
331
|
+
// turns this red; freeze-only writes one entry (R1 M2).
|
|
267
332
|
expect(host.hasAttribute("data-height-anim")).toBe(true);
|
|
268
|
-
expect(
|
|
269
|
-
//
|
|
270
|
-
|
|
333
|
+
expect(writes).toEqual(["100px", "240px"]);
|
|
334
|
+
// MUT:swap-height-flush — the forced layout BETWEEN the two writes
|
|
335
|
+
// is what establishes the freeze as the transition's before-value.
|
|
336
|
+
// The two writes are synchronous neighbours, so nothing else can
|
|
337
|
+
// read the host between them: the read count MUST advance between
|
|
338
|
+
// the freeze and the target. R4's M-no-flush (deleting the flush)
|
|
339
|
+
// left the two counts equal and passed every read-based pin.
|
|
340
|
+
expect(readsAtWrite).toHaveLength(2);
|
|
341
|
+
expect(
|
|
342
|
+
readsAtWrite[1],
|
|
343
|
+
"the host must be re-read between the freeze and the target (the forced layout)",
|
|
344
|
+
).toBeGreaterThan(readsAtWrite[0]);
|
|
271
345
|
await until(() => !host.hasAttribute("data-height-anim"), "released on settle");
|
|
272
346
|
expect(host.style.height).toBe("");
|
|
273
|
-
//
|
|
274
|
-
await until(() => !host.hasAttribute("data-height-anim") && host.style.height === "", "release holds
|
|
347
|
+
// The released state holds across further ticks.
|
|
348
|
+
await until(() => !host.hasAttribute("data-height-anim") && host.style.height === "", "release holds");
|
|
349
|
+
unspy();
|
|
275
350
|
} finally {
|
|
276
351
|
restore();
|
|
277
352
|
}
|
|
278
353
|
});
|
|
279
354
|
|
|
280
|
-
// MUT:swap-height-
|
|
281
|
-
//
|
|
282
|
-
//
|
|
283
|
-
//
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
// (150) turns the mid assertion red. Frames are held so the window is
|
|
287
|
-
// deterministic.
|
|
288
|
-
it("freezes a follow-up exchange at the current rendered height, not the old start", async () => {
|
|
289
|
-
let current = 100;
|
|
290
|
-
const frames: FrameRequestCallback[] = [];
|
|
291
|
-
const raf = vi.spyOn(globalThis, "requestAnimationFrame").mockImplementation((cb: FrameRequestCallback) => {
|
|
292
|
-
frames.push(cb);
|
|
293
|
-
return frames.length;
|
|
294
|
-
});
|
|
295
|
-
const restore = stubLayout(() => current, () => 240);
|
|
355
|
+
// MUT:swap-height-zero-skips — an unreadable height (hidden host, or
|
|
356
|
+
// an incoming pane not yet laid out reports 0) skips the tween: a
|
|
357
|
+
// 0px freeze would collapse the surface for the whole exchange and
|
|
358
|
+
// the release would depend on a frame. The snap is the safe face.
|
|
359
|
+
it("does not arm when either height is unreadable (0)", async () => {
|
|
360
|
+
const restore = stubLayout(() => 0, () => 240);
|
|
296
361
|
try {
|
|
297
362
|
const key = ref("preview");
|
|
298
363
|
const container = document.createElement("div");
|
|
@@ -304,41 +369,31 @@ describe("HkDirectionalSwap", () => {
|
|
|
304
369
|
mounts.push({ app, container });
|
|
305
370
|
await settle();
|
|
306
371
|
const host = container.querySelector<HTMLElement>(".hk-dswap")!;
|
|
307
|
-
// First exchange: frozen at 100, no frame runs yet.
|
|
308
372
|
key.value = "source";
|
|
309
373
|
await nextTick();
|
|
310
374
|
await nextTick();
|
|
311
|
-
expect(host.hasAttribute("data-height-anim")).toBe(
|
|
312
|
-
expect(host.style.height).toBe("
|
|
313
|
-
// Mid-flight: the rendered height has tweened partway (the CSS
|
|
314
|
-
// tween this DOM cannot express). The follow-up swap must freeze
|
|
315
|
-
// HERE — the frames are still held, so the first exchange cannot
|
|
316
|
-
// have released and masked the re-freeze.
|
|
317
|
-
current = 150;
|
|
318
|
-
key.value = "preview";
|
|
319
|
-
await nextTick();
|
|
320
|
-
await nextTick();
|
|
321
|
-
expect(host.hasAttribute("data-height-anim")).toBe(true);
|
|
322
|
-
expect(host.style.height).toBe("150px");
|
|
323
|
-
// The world resumes: frames flush, the second exchange reaches
|
|
324
|
-
// its own target.
|
|
325
|
-
for (let round = 0; round < 6 && host.style.height !== "240px"; round += 1) {
|
|
326
|
-
for (const cb of frames.splice(0)) cb(performance.now());
|
|
327
|
-
await nextTick();
|
|
328
|
-
}
|
|
329
|
-
expect(host.style.height).toBe("240px");
|
|
375
|
+
expect(host.hasAttribute("data-height-anim")).toBe(false);
|
|
376
|
+
expect(host.style.height).toBe("");
|
|
330
377
|
} finally {
|
|
331
|
-
raf.mockRestore();
|
|
332
378
|
restore();
|
|
333
379
|
}
|
|
334
380
|
});
|
|
335
381
|
|
|
336
|
-
// MUT:swap-height-
|
|
337
|
-
//
|
|
338
|
-
//
|
|
339
|
-
// the
|
|
340
|
-
|
|
341
|
-
|
|
382
|
+
// MUT:swap-height-reduced-snap — reduced motion (duration 0) skips the
|
|
383
|
+
// freeze entirely: the instant change is the preference, so the tween
|
|
384
|
+
// never arms and never writes a single height (R2 N1: this pin was
|
|
385
|
+
// lost in the sync-write rewrite and a deletion of the reduced-motion
|
|
386
|
+
// early-return passed the whole suite). The stub keeps the heights
|
|
387
|
+
// readable so the skip is attributable to the DURATION path alone.
|
|
388
|
+
it("does not arm or write any height under reduced motion", async () => {
|
|
389
|
+
const restore = stubLayout(() => 100, () => 240);
|
|
390
|
+
const writes: string[] = [];
|
|
391
|
+
const original = window.matchMedia;
|
|
392
|
+
Object.defineProperty(window, "matchMedia", {
|
|
393
|
+
configurable: true,
|
|
394
|
+
value: (q: string) => ({ matches: q.includes("reduced"), media: q, addEventListener() {}, removeEventListener() {}, addListener() {}, removeListener() {}, dispatchEvent: () => false, onchange: null }),
|
|
395
|
+
});
|
|
396
|
+
const desc = Object.getOwnPropertyDescriptor(CSSStyleDeclaration.prototype, "height")!;
|
|
342
397
|
try {
|
|
343
398
|
const key = ref("preview");
|
|
344
399
|
const container = document.createElement("div");
|
|
@@ -350,27 +405,47 @@ describe("HkDirectionalSwap", () => {
|
|
|
350
405
|
mounts.push({ app, container });
|
|
351
406
|
await settle();
|
|
352
407
|
const host = container.querySelector<HTMLElement>(".hk-dswap")!;
|
|
408
|
+
Object.defineProperty(host.style, "height", {
|
|
409
|
+
configurable: true,
|
|
410
|
+
get() {
|
|
411
|
+
return desc.get!.call(this);
|
|
412
|
+
},
|
|
413
|
+
set(v: string) {
|
|
414
|
+
writes.push(v);
|
|
415
|
+
desc.set!.call(this, v);
|
|
416
|
+
},
|
|
417
|
+
});
|
|
353
418
|
key.value = "source";
|
|
354
419
|
await nextTick();
|
|
355
420
|
await nextTick();
|
|
421
|
+
// The swap itself must not write a height. This write pin speaks
|
|
422
|
+
// FIRST — defensive ordering, so it always runs before an armed-attr
|
|
423
|
+
// assertion that could shadow it; on the current implementation the
|
|
424
|
+
// order does not change the outcome (a duration-0 fallback would
|
|
425
|
+
// fail both), the front position just keeps the write pin audible
|
|
426
|
+
// if that ever changes.
|
|
427
|
+
expect(writes, "no height write at the swap").toEqual([]);
|
|
356
428
|
expect(host.hasAttribute("data-height-anim")).toBe(false);
|
|
357
|
-
|
|
429
|
+
await settle();
|
|
430
|
+
expect(writes, "the reduced-motion path writes nothing").toEqual([]);
|
|
358
431
|
} finally {
|
|
432
|
+
Object.defineProperty(window, "matchMedia", { configurable: true, value: original });
|
|
359
433
|
restore();
|
|
360
434
|
}
|
|
361
435
|
});
|
|
362
436
|
|
|
363
|
-
// MUT:swap-height-
|
|
364
|
-
//
|
|
365
|
-
//
|
|
366
|
-
//
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
437
|
+
// MUT:swap-height-followup-current — a faster follow-up swap arrives
|
|
438
|
+
// AFTER Vue cancelled the interrupted enter (the release runs, then the
|
|
439
|
+
// fresh exchange begins): its freeze must read the cell's CURRENT
|
|
440
|
+
// rendered height via offsetHeight — never a remembered start value.
|
|
441
|
+
// The moving `current` stub stands in for the live layout height this
|
|
442
|
+
// DOM cannot compute; the write sequence pins it exactly: the second
|
|
443
|
+
// exchange writes [150px (its own freeze), 240px (its target)] — a
|
|
444
|
+
// regression that remembers the old start writes [100px, ...] first.
|
|
445
|
+
it("a follow-up exchange freezes at the current rendered height, not the old start", async () => {
|
|
446
|
+
let current = 100;
|
|
447
|
+
const restore = stubLayout(() => current, () => 240);
|
|
448
|
+
const writes: string[] = [];
|
|
374
449
|
try {
|
|
375
450
|
const key = ref("preview");
|
|
376
451
|
const container = document.createElement("div");
|
|
@@ -381,38 +456,41 @@ describe("HkDirectionalSwap", () => {
|
|
|
381
456
|
app.mount(container);
|
|
382
457
|
mounts.push({ app, container });
|
|
383
458
|
await settle();
|
|
459
|
+
const host = container.querySelector<HTMLElement>(".hk-dswap")!;
|
|
460
|
+
Object.defineProperty(host.style, "height", {
|
|
461
|
+
configurable: true,
|
|
462
|
+
get: descGet,
|
|
463
|
+
set(v: string) {
|
|
464
|
+
writes.push(v);
|
|
465
|
+
descSet.call(host.style, v);
|
|
466
|
+
},
|
|
467
|
+
});
|
|
468
|
+
// First exchange.
|
|
384
469
|
key.value = "source";
|
|
385
470
|
await nextTick();
|
|
386
471
|
await nextTick();
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
472
|
+
// Follow-up swap: Vue cancels the interrupted enter — the release
|
|
473
|
+
// writes "" — then the fresh exchange freezes at the CURRENT
|
|
474
|
+
// stubbed height before its target. The full sequence pins all of
|
|
475
|
+
// it: freeze, target, cancel-release, re-freeze, re-target.
|
|
476
|
+
current = 150;
|
|
477
|
+
key.value = "preview";
|
|
478
|
+
await nextTick();
|
|
479
|
+
await nextTick();
|
|
480
|
+
expect(host.hasAttribute("data-height-anim")).toBe(true);
|
|
481
|
+
expect(writes).toEqual(["100px", "240px", "", "150px", "240px"]);
|
|
390
482
|
} finally {
|
|
391
|
-
Object.defineProperty(window, "matchMedia", { configurable: true, value: original });
|
|
392
483
|
restore();
|
|
393
484
|
}
|
|
394
485
|
});
|
|
395
486
|
|
|
396
|
-
// MUT:swap-height-watchdog-releases — a wedged engine (
|
|
397
|
-
// wedges the tween with it: the watchdog must sweep the
|
|
398
|
-
// exchange AND release the explicit height, or the surface
|
|
399
|
-
// frozen at a stale size forever. setTimeout is faked so the
|
|
400
|
-
// fires on advance
|
|
401
|
-
|
|
402
|
-
// resurrection there (stale target written onto a released host)
|
|
403
|
-
// means the release's cancellation and the frame's armed-guard both
|
|
404
|
-
// failed together.
|
|
405
|
-
it("watchdog releases a wedged height tween, and no stale frame resurrects it", async () => {
|
|
487
|
+
// MUT:swap-height-watchdog-releases — a wedged engine (the exchange
|
|
488
|
+
// never settles) wedges the tween with it: the watchdog must sweep the
|
|
489
|
+
// frozen exchange AND release the explicit height, or the surface
|
|
490
|
+
// stays frozen at a stale size forever. setTimeout is faked so the
|
|
491
|
+
// watchdog fires on advance.
|
|
492
|
+
it("watchdog releases a wedged height tween", async () => {
|
|
406
493
|
vi.useFakeTimers({ toFake: ["setTimeout", "clearTimeout"] });
|
|
407
|
-
// Queue EVERY rAF request: Vue's own transition frames and the
|
|
408
|
-
// tween's target frame all ride rAF, and the last request is not
|
|
409
|
-
// necessarily ours — flushing the whole queue post-release is what
|
|
410
|
-
// makes a resurrection observable.
|
|
411
|
-
const frames: FrameRequestCallback[] = [];
|
|
412
|
-
const raf = vi.spyOn(globalThis, "requestAnimationFrame").mockImplementation((cb: FrameRequestCallback) => {
|
|
413
|
-
frames.push(cb);
|
|
414
|
-
return frames.length;
|
|
415
|
-
});
|
|
416
494
|
const restore = stubLayout(() => 100, () => 240);
|
|
417
495
|
try {
|
|
418
496
|
const key = ref("preview");
|
|
@@ -423,30 +501,18 @@ describe("HkDirectionalSwap", () => {
|
|
|
423
501
|
});
|
|
424
502
|
app.mount(container);
|
|
425
503
|
mounts.push({ app, container });
|
|
426
|
-
// Fake timers: `settle()`'s setTimeout would never fire on its own.
|
|
427
504
|
await vi.advanceTimersByTimeAsync(0);
|
|
428
505
|
const host = container.querySelector<HTMLElement>(".hk-dswap")!;
|
|
429
506
|
key.value = "source";
|
|
430
507
|
await nextTick();
|
|
431
508
|
await nextTick();
|
|
432
509
|
expect(host.hasAttribute("data-height-anim")).toBe(true);
|
|
433
|
-
// No
|
|
434
|
-
// WATCHDOG_MS + duration and must sweep + release.
|
|
510
|
+
// No settle ever runs (the engine is wedged): the watchdog fires
|
|
511
|
+
// at WATCHDOG_MS + duration and must sweep + release.
|
|
435
512
|
vi.advanceTimersByTime(1200 + 300 + 100);
|
|
436
513
|
expect(host.hasAttribute("data-height-anim")).toBe(false);
|
|
437
514
|
expect(host.style.height).toBe("");
|
|
438
|
-
// Now every frame queued before the cleanup lands anyway (a
|
|
439
|
-
// browser can fire a rAF queued before a release): the released
|
|
440
|
-
// state must hold. Flush repeatedly — each flush may schedule
|
|
441
|
-
// new frames (Vue's resolution chain), all of which must stay
|
|
442
|
-
// inert against the released host.
|
|
443
|
-
for (let round = 0; round < 3; round += 1) {
|
|
444
|
-
for (const cb of frames.splice(0)) cb(performance.now());
|
|
445
|
-
expect(host.hasAttribute("data-height-anim")).toBe(false);
|
|
446
|
-
expect(host.style.height).toBe("");
|
|
447
|
-
}
|
|
448
515
|
} finally {
|
|
449
|
-
raf.mockRestore();
|
|
450
516
|
restore();
|
|
451
517
|
vi.useRealTimers();
|
|
452
518
|
}
|
|
@@ -170,27 +170,29 @@ export default defineComponent({
|
|
|
170
170
|
let watchdog: ReturnType<typeof setTimeout> | null = null;
|
|
171
171
|
|
|
172
172
|
// ── height animation (`animateHeight`) ──────────────────────────────
|
|
173
|
-
// Direct DOM on purpose: the freeze must land
|
|
174
|
-
//
|
|
175
|
-
//
|
|
176
|
-
//
|
|
177
|
-
//
|
|
178
|
-
//
|
|
179
|
-
//
|
|
180
|
-
//
|
|
181
|
-
//
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
let targetFrame: number | null = null;
|
|
186
|
-
|
|
173
|
+
// Direct DOM on purpose: the freeze and the target must land around a
|
|
174
|
+
// FORCED LAYOUT, in the same tick the incoming item inserts — a
|
|
175
|
+
// reactive attr would arrive with the patch, collapsing the freeze and
|
|
176
|
+
// the target into one style recalc (no transition). NO animation
|
|
177
|
+
// frames anywhere: a frame-gated target write starves in background
|
|
178
|
+
// tabs, automation and throttled pages (measured — the tween then
|
|
179
|
+
// silently degrades to a snap), while the forced-layout sandwich
|
|
180
|
+
// tweens identically everywhere, on the clock CSS transitions already
|
|
181
|
+
// run on. NOTE for future edits: keep `height` OUT of the
|
|
182
|
+
// `hostProps.style` object above — Vue patches style keys it rendered
|
|
183
|
+
// and would silently reset our inline tween height on the next render;
|
|
184
|
+
// these writes live outside the vnode on purpose.
|
|
187
185
|
/** Freeze the wrapper at its rendered height, arm the height
|
|
188
|
-
* transition,
|
|
189
|
-
*
|
|
190
|
-
*
|
|
191
|
-
* is
|
|
192
|
-
*
|
|
193
|
-
*
|
|
186
|
+
* transition, and step to the incoming generation's height — the
|
|
187
|
+
* forced layout between the two writes is what makes them a
|
|
188
|
+
* before/after pair. No-ops when the prop is off, the effective
|
|
189
|
+
* duration is zero (reduced motion keeps the snap by design), or
|
|
190
|
+
* either height is unreadable (a hidden or not-yet-laid-out surface
|
|
191
|
+
* reports 0 — animating to/from 0 would collapse the card; the snap
|
|
192
|
+
* is the safe face there, same as reduced motion). A faster
|
|
193
|
+
* follow-up swap arrives after Vue cancelled the interrupted enter
|
|
194
|
+
* (the release runs), so its freeze reads the cell's CURRENT layout
|
|
195
|
+
* height — the interrupted tween's mid-state — never the old start. */
|
|
194
196
|
function beginHeightAnimation(incoming: Element): void {
|
|
195
197
|
if (!props.animateHeight) return;
|
|
196
198
|
if (motionDuration() === 0) return;
|
|
@@ -199,42 +201,25 @@ export default defineComponent({
|
|
|
199
201
|
const from = host.offsetHeight;
|
|
200
202
|
const target = (incoming as HTMLElement).offsetHeight;
|
|
201
203
|
if (from === 0 || target === 0) return;
|
|
202
|
-
// A faster follow-up swap arrives here AFTER Vue cancelled the
|
|
203
|
-
// interrupted enter (onEnterCancelled → release), so this freeze
|
|
204
|
-
// reads the layout height the released cell sits at RIGHT NOW —
|
|
205
|
-
// the interrupted tween's mid-state, never the old start.
|
|
206
204
|
host.style.height = `${from}px`;
|
|
207
205
|
// Flush so the frozen height is the transition's computed start
|
|
208
206
|
// (a same-frame change from auto would jump instead of tween).
|
|
209
207
|
void host.offsetHeight;
|
|
210
208
|
host.setAttribute("data-height-anim", "");
|
|
211
|
-
|
|
212
|
-
targetFrame = requestAnimationFrame(() => {
|
|
213
|
-
targetFrame = null;
|
|
214
|
-
// The host may have been released within this frame (settle,
|
|
215
|
-
// watchdog, a disabled swap); re-freezing then would fight the
|
|
216
|
-
// cleanup — the armed attribute is that cleanup's commit marker.
|
|
217
|
-
if (!host.hasAttribute("data-height-anim")) return;
|
|
218
|
-
host.style.height = `${target}px`;
|
|
219
|
-
});
|
|
209
|
+
host.style.height = `${target}px`;
|
|
220
210
|
}
|
|
221
211
|
|
|
222
212
|
/** Release the explicit height back to auto and disarm the
|
|
223
213
|
* transition. Guarded on the armed attribute so it only ever
|
|
224
214
|
* unwinds THIS component's own writes: an unarmed call (default-off
|
|
225
215
|
* host, or a second after-hook) must leave a host's own inline
|
|
226
|
-
* height alone
|
|
227
|
-
* height the release already cleared. */
|
|
216
|
+
* height alone. */
|
|
228
217
|
function endHeightAnimation(): void {
|
|
229
218
|
const host = hostRef.value;
|
|
230
219
|
if (!host) return;
|
|
231
220
|
if (!host.hasAttribute("data-height-anim")) return;
|
|
232
221
|
host.removeAttribute("data-height-anim");
|
|
233
222
|
host.style.height = "";
|
|
234
|
-
if (targetFrame !== null) {
|
|
235
|
-
cancelAnimationFrame(targetFrame);
|
|
236
|
-
targetFrame = null;
|
|
237
|
-
}
|
|
238
223
|
}
|
|
239
224
|
|
|
240
225
|
function armWatchdog(): void {
|
|
@@ -300,12 +285,6 @@ export default defineComponent({
|
|
|
300
285
|
onBeforeUnmount(() => {
|
|
301
286
|
if (watchdog !== null) clearTimeout(watchdog);
|
|
302
287
|
watchdog = null;
|
|
303
|
-
// A pending target frame would write to a host that is leaving the
|
|
304
|
-
// document; cancel it with the rest of the machinery.
|
|
305
|
-
if (targetFrame !== null) {
|
|
306
|
-
cancelAnimationFrame(targetFrame);
|
|
307
|
-
targetFrame = null;
|
|
308
|
-
}
|
|
309
288
|
});
|
|
310
289
|
|
|
311
290
|
function item(): VNode {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<!doctype html>
|
|
2
2
|
<html lang="en">
|
|
3
3
|
<head>
|
|
4
|
-
<meta name="hk-error-landing" content="v1 0.55.
|
|
4
|
+
<meta name="hk-error-landing" content="v1 0.55.515 <dev>">
|
|
5
5
|
<meta charset="utf-8" />
|
|
6
6
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
7
7
|
<meta name="robots" content="noindex" />
|