@celestia-island/hikari 0.55.521 → 0.55.522
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/types/components/HkDirectionalSwap.d.ts +10 -6
- package/package.json +1 -1
- package/src/components/HkDirectionalSwap.scss +0 -4
- package/src/components/HkDirectionalSwap.test.tsx +251 -40
- package/src/components/HkDirectionalSwap.tsx +49 -17
- package/src/errorLandingStandalone/error-landing.html +1 -1
|
@@ -72,11 +72,12 @@
|
|
|
72
72
|
* the un-stretched read — the read returns the pin, and a pin at the
|
|
73
73
|
* row is the no-op again (see `readUnstretchedHeight`); hosts size
|
|
74
74
|
* the pane, the item's child. (b) The host is BORDER-BOX with no
|
|
75
|
-
* padding or border of its own:
|
|
76
|
-
* and
|
|
77
|
-
* is the content box — a padded
|
|
78
|
-
*
|
|
79
|
-
* neither, so the target
|
|
75
|
+
* padding or border of its own: the reads are `getBoundingClientRect`
|
|
76
|
+
* figures (border-box, fractional) and are written into `height`,
|
|
77
|
+
* which under `box-sizing: content-box` is the content box — a padded
|
|
78
|
+
* or bordered `.hk-dswap` would offset the tween by its box extra
|
|
79
|
+
* (the docs shell's host is border-box with neither, so the target
|
|
80
|
+
* path is exact).
|
|
80
81
|
*/
|
|
81
82
|
import { type PropType } from "vue";
|
|
82
83
|
import "./HkDirectionalSwap.scss";
|
|
@@ -110,7 +111,10 @@ export declare function resolveSwapDirection(order: ReadonlyArray<string | numbe
|
|
|
110
111
|
* 240px, stretched and un-stretched both read 240 while the content is
|
|
111
112
|
* 100). Hosts size the PANE (the item's child); that is where the docs
|
|
112
113
|
* shell's band-fill lives, and this read runs before its attribute
|
|
113
|
-
* exists.
|
|
114
|
+
* exists. The read is the FRACTIONAL layout height
|
|
115
|
+
* (`getBoundingClientRect`), not the integer-rounded `offsetHeight` —
|
|
116
|
+
* the tween then ends exactly where the released `auto` lands, with no
|
|
117
|
+
* sub-pixel step at the release frame.
|
|
114
118
|
*/
|
|
115
119
|
export declare function readUnstretchedHeight(item: HTMLElement): number;
|
|
116
120
|
declare const _default: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
package/package.json
CHANGED
|
@@ -65,10 +65,6 @@
|
|
|
65
65
|
--hk-dswap-leave-to: translateY(var(--hk-swap-travel, 24px));
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
-
// RTL mirrors the horizontal vocabulary: "forward" travels the other way on
|
|
69
|
-
// screen because the reading direction does.
|
|
70
|
-
|
|
71
|
-
|
|
72
68
|
// RTL mirrors the horizontal vocabulary: "forward" travels the other way on
|
|
73
69
|
// screen because the reading direction does.
|
|
74
70
|
[dir="rtl"] .hk-dswap[data-axis="horizontal"] {
|
|
@@ -73,21 +73,22 @@ describe("resolveSwapDirection", () => {
|
|
|
73
73
|
// no test can hand the component a prior inline style.
|
|
74
74
|
describe("readUnstretchedHeight", () => {
|
|
75
75
|
/** A grid item whose height depends on its own `align-self`, the way
|
|
76
|
-
* a real cell's does: the row's 100 while stretched, its own 40
|
|
77
|
-
* `start
|
|
76
|
+
* a real cell's does: the row's 100.5 while stretched, its own 40.25
|
|
77
|
+
* under `start` — fractional, the way a browser reports
|
|
78
|
+
* `getBoundingClientRect`. Returns the element. */
|
|
78
79
|
function gridItem(): HTMLElement {
|
|
79
80
|
const el = document.createElement("div");
|
|
80
81
|
document.body.appendChild(el);
|
|
81
|
-
Object.defineProperty(el, "
|
|
82
|
+
Object.defineProperty(el, "getBoundingClientRect", {
|
|
82
83
|
configurable: true,
|
|
83
|
-
|
|
84
|
+
value: () => ({ height: el.style.alignSelf === "start" ? 40.25 : 100.5 }) as DOMRect,
|
|
84
85
|
});
|
|
85
86
|
return el;
|
|
86
87
|
}
|
|
87
88
|
|
|
88
89
|
it("reads the un-stretched height and leaves no inline align-self behind", () => {
|
|
89
90
|
const el = gridItem();
|
|
90
|
-
expect(readUnstretchedHeight(el)).toBe(40);
|
|
91
|
+
expect(readUnstretchedHeight(el)).toBe(40.25);
|
|
91
92
|
expect(el.style.getPropertyValue("align-self")).toBe("");
|
|
92
93
|
expect(el.style.getPropertyPriority("align-self")).toBe("");
|
|
93
94
|
expect(el.style.length).toBe(0);
|
|
@@ -97,7 +98,7 @@ describe("readUnstretchedHeight", () => {
|
|
|
97
98
|
const el = gridItem();
|
|
98
99
|
el.style.setProperty("align-self", "center", "important");
|
|
99
100
|
expect(el.style.getPropertyPriority("align-self")).toBe("important"); // precondition
|
|
100
|
-
expect(readUnstretchedHeight(el)).toBe(40);
|
|
101
|
+
expect(readUnstretchedHeight(el)).toBe(40.25);
|
|
101
102
|
expect(el.style.getPropertyValue("align-self")).toBe("center");
|
|
102
103
|
expect(el.style.getPropertyPriority("align-self"), "priority must survive the restore").toBe("important");
|
|
103
104
|
});
|
|
@@ -210,39 +211,51 @@ describe("HkDirectionalSwap", () => {
|
|
|
210
211
|
});
|
|
211
212
|
|
|
212
213
|
// ── animateHeight (opt-in height tween) ─────────────────────────────
|
|
213
|
-
// happy-dom has no layout engine: every
|
|
214
|
+
// happy-dom has no layout engine: every height read is 0, so the
|
|
214
215
|
// tween (freeze a rendered height, step to a target) runs against
|
|
215
216
|
// STUBBED heights — without a stub the unreadable-height guard skips
|
|
216
217
|
// the whole tween and every assertion would pass for the wrong reason.
|
|
217
|
-
// The
|
|
218
|
-
//
|
|
219
|
-
//
|
|
220
|
-
//
|
|
218
|
+
// The stubs shadow `getBoundingClientRect` (the read the component
|
|
219
|
+
// makes — fractional, un-rounded) and NOT `offsetHeight`: a mutant
|
|
220
|
+
// that reverts ALL the tween's reads to the integer-rounded read hits
|
|
221
|
+
// the real (0) value, fails the unreadable-height guard, and never
|
|
222
|
+
// arms — the fractional pin goes red (MUT:swap-height-fractional-targets,
|
|
223
|
+
// below). (A partial revert of the flush read alone is not observable
|
|
224
|
+
// through the writes; the flush pin's read-count covers that one —
|
|
225
|
+
// MUT:swap-height-flush, below.) The tween's writes are SYNCHRONOUS inside the enter
|
|
226
|
+
// hook (no animation frames by design — frames starve in background
|
|
227
|
+
// tabs and automation), so armed-and-targeted is observable one tick
|
|
228
|
+
// after the swap and released after the exchange's settle.
|
|
221
229
|
|
|
222
|
-
/** The host's
|
|
223
|
-
*
|
|
224
|
-
*
|
|
225
|
-
* require it: R4's M-no-flush (deleting
|
|
230
|
+
/** The host's HEIGHT READ COUNT under the current stub — reset on
|
|
231
|
+
* every install. The tween's forced layout (the flush between its
|
|
232
|
+
* freeze and its target) is one extra host read, so a pin can
|
|
233
|
+
* require it: R4's M-no-flush (deleting the flush read) was
|
|
226
234
|
* invisible to every read-based pin because a constant stub reads the
|
|
227
235
|
* same however many times. */
|
|
228
236
|
const hostReads = { count: 0 };
|
|
229
237
|
|
|
230
|
-
/**
|
|
231
|
-
*
|
|
238
|
+
/** A DOMRect-like object carrying just `height` (all `getBoundingClientRect`
|
|
239
|
+
* consumers in this component read the height). */
|
|
240
|
+
const rectOf = (height: number): DOMRect => ({ height }) as DOMRect;
|
|
241
|
+
|
|
242
|
+
/** Shadow `getBoundingClientRect` for the swap's two element kinds
|
|
243
|
+
* (host reads are counted into `hostReads`). Returns restore. */
|
|
232
244
|
function stubLayout(hostH: () => number, itemH: () => number): () => void {
|
|
233
245
|
const proto = HTMLElement.prototype;
|
|
234
|
-
const shadow = Object.getOwnPropertyDescriptor(proto, "
|
|
246
|
+
const shadow = Object.getOwnPropertyDescriptor(proto, "getBoundingClientRect");
|
|
235
247
|
hostReads.count = 0;
|
|
236
|
-
Object.defineProperty(proto, "
|
|
248
|
+
Object.defineProperty(proto, "getBoundingClientRect", {
|
|
237
249
|
configurable: true,
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
250
|
+
value(this: HTMLElement) {
|
|
251
|
+
const isItem = this.classList.contains("hk-dswap-item");
|
|
252
|
+
if (!isItem) hostReads.count += 1;
|
|
253
|
+
return rectOf(isItem ? itemH() : hostH());
|
|
241
254
|
},
|
|
242
255
|
});
|
|
243
256
|
return () => {
|
|
244
|
-
if (shadow) Object.defineProperty(proto, "
|
|
245
|
-
else delete (proto as unknown as Record<string, unknown>).
|
|
257
|
+
if (shadow) Object.defineProperty(proto, "getBoundingClientRect", shadow);
|
|
258
|
+
else delete (proto as unknown as Record<string, unknown>).getBoundingClientRect;
|
|
246
259
|
};
|
|
247
260
|
}
|
|
248
261
|
|
|
@@ -300,10 +313,14 @@ describe("HkDirectionalSwap", () => {
|
|
|
300
313
|
* - while the host is ARMED (`data-height-anim`), a browser renders
|
|
301
314
|
* the tween's animated value, not the row: `rendered` supplies it
|
|
302
315
|
* (null/unset = no armed model, the row stands in).
|
|
316
|
+
* - an explicit inline `height` on the item WINS over both the row
|
|
317
|
+
* stretch and the content height (the documented host contract) —
|
|
318
|
+
* modelled here so the contract case runs through this same model
|
|
319
|
+
* instead of a bespoke closure.
|
|
303
320
|
* Host reads are counted into `hostReads` as above. Returns restore. */
|
|
304
321
|
function stubGrid(natural: Record<string, number>, rendered?: () => number | null): () => void {
|
|
305
322
|
const proto = HTMLElement.prototype;
|
|
306
|
-
const shadow = Object.getOwnPropertyDescriptor(proto, "
|
|
323
|
+
const shadow = Object.getOwnPropertyDescriptor(proto, "getBoundingClientRect");
|
|
307
324
|
hostReads.count = 0;
|
|
308
325
|
const row = (el: HTMLElement): number => {
|
|
309
326
|
const cell = el.classList.contains("hk-dswap-item") ? el.parentElement : el;
|
|
@@ -313,23 +330,26 @@ describe("HkDirectionalSwap", () => {
|
|
|
313
330
|
}
|
|
314
331
|
return tallest;
|
|
315
332
|
};
|
|
316
|
-
Object.defineProperty(proto, "
|
|
333
|
+
Object.defineProperty(proto, "getBoundingClientRect", {
|
|
317
334
|
configurable: true,
|
|
318
|
-
|
|
335
|
+
value(this: HTMLElement) {
|
|
319
336
|
if (this.classList.contains("hk-dswap-item")) {
|
|
320
|
-
|
|
337
|
+
// The pin wins over both the row and the content height.
|
|
338
|
+
const pinned = parseFloat(this.style.height);
|
|
339
|
+
if (!Number.isNaN(pinned)) return rectOf(pinned);
|
|
340
|
+
return rectOf(this.style.alignSelf === "start" ? (natural[this.dataset.swapKey ?? ""] ?? 0) : row(this));
|
|
321
341
|
}
|
|
322
342
|
hostReads.count += 1;
|
|
323
343
|
if (this.hasAttribute("data-height-anim") && rendered) {
|
|
324
344
|
const animated = rendered();
|
|
325
|
-
if (animated !== null) return animated;
|
|
345
|
+
if (animated !== null) return rectOf(animated);
|
|
326
346
|
}
|
|
327
|
-
return row(this);
|
|
347
|
+
return rectOf(row(this));
|
|
328
348
|
},
|
|
329
349
|
});
|
|
330
350
|
return () => {
|
|
331
|
-
if (shadow) Object.defineProperty(proto, "
|
|
332
|
-
else delete (proto as unknown as Record<string, unknown>).
|
|
351
|
+
if (shadow) Object.defineProperty(proto, "getBoundingClientRect", shadow);
|
|
352
|
+
else delete (proto as unknown as Record<string, unknown>).getBoundingClientRect;
|
|
333
353
|
};
|
|
334
354
|
}
|
|
335
355
|
|
|
@@ -408,25 +428,55 @@ describe("HkDirectionalSwap", () => {
|
|
|
408
428
|
const host = container.querySelector<HTMLElement>(".hk-dswap")!;
|
|
409
429
|
const item = (k: string) => [...container.querySelectorAll<HTMLElement>(".hk-dswap-item")].find((el) => el.dataset.swapKey === k)!;
|
|
410
430
|
// One generation: the host IS that generation's height.
|
|
411
|
-
expect(host.
|
|
412
|
-
expect(item("preview").
|
|
431
|
+
expect(host.getBoundingClientRect().height).toBe(240);
|
|
432
|
+
expect(item("preview").getBoundingClientRect().height).toBe(240);
|
|
413
433
|
// Two generations: the row is the taller one, and the shorter
|
|
414
434
|
// incoming copy reads stretched to it.
|
|
415
435
|
key.value = "source";
|
|
416
436
|
await nextTick();
|
|
417
437
|
await nextTick();
|
|
418
|
-
expect(host.
|
|
419
|
-
expect(item("source").
|
|
438
|
+
expect(host.getBoundingClientRect().height).toBe(240);
|
|
439
|
+
expect(item("source").getBoundingClientRect().height).toBe(240);
|
|
420
440
|
// …until un-stretched, when it reads its own content height.
|
|
421
441
|
item("source").style.alignSelf = "start";
|
|
422
|
-
expect(item("source").
|
|
442
|
+
expect(item("source").getBoundingClientRect().height).toBe(100);
|
|
423
443
|
item("source").style.removeProperty("align-self");
|
|
424
444
|
// Armed (and only armed): the host reads the animated value.
|
|
425
|
-
expect(host.
|
|
445
|
+
expect(host.getBoundingClientRect().height).toBe(240);
|
|
426
446
|
host.setAttribute("data-height-anim", "");
|
|
427
|
-
expect(host.
|
|
447
|
+
expect(host.getBoundingClientRect().height).toBe(170);
|
|
428
448
|
host.removeAttribute("data-height-anim");
|
|
429
|
-
expect(host.
|
|
449
|
+
expect(host.getBoundingClientRect().height).toBe(240);
|
|
450
|
+
} finally {
|
|
451
|
+
restore();
|
|
452
|
+
}
|
|
453
|
+
});
|
|
454
|
+
|
|
455
|
+
// MUT:swap-height-pinned-item-contract — a host that pins `height` on
|
|
456
|
+
// `.hk-dswap-item` reads its PIN, not its content: the pin wins over both
|
|
457
|
+
// the row stretch and the content height, so un-stretching cannot recover
|
|
458
|
+
// the content height and a pin AT THE ROW turns the tween back into the
|
|
459
|
+
// no-op #1661 fixed. That is why the contract says hosts size the pane.
|
|
460
|
+
// Driven through `stubGrid` (the same model every other height pin uses)
|
|
461
|
+
// rather than a bespoke closure, so the citation is re-derivable.
|
|
462
|
+
it("reads a pinned item's pin, not its content — the documented host contract", async () => {
|
|
463
|
+
const restore = stubGrid({ preview: 100.5, source: 100.5 });
|
|
464
|
+
try {
|
|
465
|
+
const key = ref("source");
|
|
466
|
+
const container = document.createElement("div");
|
|
467
|
+
document.body.appendChild(container);
|
|
468
|
+
const app = createApp({ render: () => h(HkDirectionalSwap, { swapKey: key.value, animateHeight: true }, () => [h("p", key.value)]) });
|
|
469
|
+
app.mount(container);
|
|
470
|
+
mounts.push({ app, container });
|
|
471
|
+
await settle();
|
|
472
|
+
const item = container.querySelector<HTMLElement>(".hk-dswap-item")!;
|
|
473
|
+
// Content and row are both 100.5; the pin is 40.25.
|
|
474
|
+
item.style.height = "40.25px";
|
|
475
|
+
expect(readUnstretchedHeight(item)).toBe(40.25);
|
|
476
|
+
// The read restores the item's own inline style (the pin survives).
|
|
477
|
+
expect(item.style.height).toBe("40.25px");
|
|
478
|
+
expect(item.style.getPropertyValue("align-self")).toBe("");
|
|
479
|
+
expect(item.style.getPropertyPriority("align-self")).toBe("");
|
|
430
480
|
} finally {
|
|
431
481
|
restore();
|
|
432
482
|
}
|
|
@@ -821,6 +871,167 @@ describe("HkDirectionalSwap", () => {
|
|
|
821
871
|
}
|
|
822
872
|
});
|
|
823
873
|
|
|
874
|
+
// MUT:swap-height-fractional-targets — the tween writes the FRACTIONAL
|
|
875
|
+
// layout height, not an integer-rounded figure: at the release the
|
|
876
|
+
// explicit height comes off and the cell resolves to that same natural
|
|
877
|
+
// height, so the release frame must land with NO sub-pixel step (the
|
|
878
|
+
// docs shell shipped a visible 189 → 188.73 jump at release because the
|
|
879
|
+
// first cut read the rounded `offsetHeight`). A mutant that reverts to
|
|
880
|
+
// `offsetHeight` reads the un-stubbed real value (0), fails the
|
|
881
|
+
// unreadable-height guard, never arms — and this pin goes red.
|
|
882
|
+
it("writes fractional heights so the release lands with no sub-pixel step", async () => {
|
|
883
|
+
const restore = stubGrid({ preview: 200, source: 188.7265625 }, () => 188.7265625);
|
|
884
|
+
try {
|
|
885
|
+
const key = ref("preview");
|
|
886
|
+
const container = document.createElement("div");
|
|
887
|
+
document.body.appendChild(container);
|
|
888
|
+
const app = createApp({
|
|
889
|
+
render: () => h(HkDirectionalSwap, { swapKey: key.value, animateHeight: true }, () => [h("p", key.value)]),
|
|
890
|
+
});
|
|
891
|
+
app.mount(container);
|
|
892
|
+
mounts.push({ app, container });
|
|
893
|
+
await settle();
|
|
894
|
+
const host = container.querySelector<HTMLElement>(".hk-dswap")!;
|
|
895
|
+
const { writes, restore: unspy } = spyHeightWrites(host);
|
|
896
|
+
key.value = "source";
|
|
897
|
+
await nextTick();
|
|
898
|
+
await nextTick();
|
|
899
|
+
// The freeze is the outgoing copy's exact height, the target the
|
|
900
|
+
// incoming copy's own — both fractional, neither rounded. (The spy
|
|
901
|
+
// records the set value verbatim; the real style store re-serialises
|
|
902
|
+
// on read-back, which is exactly the hazard the release guard below
|
|
903
|
+
// must tolerate.)
|
|
904
|
+
expect(writes).toEqual(["200px", "188.7265625px"]);
|
|
905
|
+
// The RELEASE side is what the first cut got wrong: its guard
|
|
906
|
+
// compared the read-back (re-serialised) height against the write
|
|
907
|
+
// exactly and never cleared, stranding the host at a fractional
|
|
908
|
+
// height for good. The guard must come off here — assert the
|
|
909
|
+
// outcome, not the armed state (MUT:swap-height-fractional-targets,
|
|
910
|
+
// which is this test's own id).
|
|
911
|
+
await vi.waitFor(() => expect(host.hasAttribute("data-height-anim")).toBe(false), { timeout: 1000 });
|
|
912
|
+
expect(host.style.height, "the release must come off at a genuine fractional height").toBe("");
|
|
913
|
+
unspy();
|
|
914
|
+
} finally {
|
|
915
|
+
restore();
|
|
916
|
+
}
|
|
917
|
+
});
|
|
918
|
+
|
|
919
|
+
// MUT:swap-height-no-tolerance — the release guard is an EXACT compare
|
|
920
|
+
// against the value the store itself reported for our own write at arm
|
|
921
|
+
// time, so the store's re-serialisation cancels on both sides and a
|
|
922
|
+
// host's own write is never swallowed. R3 of #1668: a 0.5px tolerance
|
|
923
|
+
// (a) was still ~20× wider than either serialiser needs and (b) DID
|
|
924
|
+
// swallow a host's write — at an armed 188.7265625, a host writing
|
|
925
|
+
// `189px` differs by 0.273 and was silently cleared. This pin sweeps the
|
|
926
|
+
// window: every offset inside ±0.5px must survive the release.
|
|
927
|
+
it("keeps a host write inside half a pixel of the armed height", async () => {
|
|
928
|
+
const natural = 188.7265625;
|
|
929
|
+
for (const hostWrite of ["189px", "188.5px", "188.25px", "189.25px"]) {
|
|
930
|
+
const restore = stubGrid({ preview: 200, source: natural }, () => natural);
|
|
931
|
+
try {
|
|
932
|
+
const key = ref("preview");
|
|
933
|
+
const container = document.createElement("div");
|
|
934
|
+
document.body.appendChild(container);
|
|
935
|
+
const app = createApp({
|
|
936
|
+
render: () => h(HkDirectionalSwap, { swapKey: key.value, animateHeight: true }, () => [h("p", key.value)]),
|
|
937
|
+
});
|
|
938
|
+
app.mount(container);
|
|
939
|
+
mounts.push({ app, container });
|
|
940
|
+
await settle();
|
|
941
|
+
const host = container.querySelector<HTMLElement>(".hk-dswap")!;
|
|
942
|
+
key.value = "source";
|
|
943
|
+
await nextTick();
|
|
944
|
+
await nextTick();
|
|
945
|
+
expect(host.hasAttribute("data-height-anim")).toBe(true);
|
|
946
|
+
host.style.height = hostWrite;
|
|
947
|
+
await vi.waitFor(() => expect(host.hasAttribute("data-height-anim")).toBe(false), { timeout: 1000 });
|
|
948
|
+
expect(host.style.height, `a host write of ${hostWrite} must not be swallowed`).toBe(hostWrite);
|
|
949
|
+
} finally {
|
|
950
|
+
restore();
|
|
951
|
+
}
|
|
952
|
+
}
|
|
953
|
+
});
|
|
954
|
+
|
|
955
|
+
// MUT:swap-height-readback-nonempty — the arm-time read-back premise,
|
|
956
|
+
// pinned through its CONSEQUENCE and not through the DOM the component
|
|
957
|
+
// already wrote: a `""`/stale `armedHeight` makes the release compare
|
|
958
|
+
// fail silently and keeps the explicit height, so THIS pin arms at a
|
|
959
|
+
// height happy-dom re-serialises and requires the release to come off.
|
|
960
|
+
// (Its first cut only asserted the DOM at arm time — never `armedHeight`
|
|
961
|
+
// — and stayed green under the very mutant it named; R5 caught that.)
|
|
962
|
+
it("arms with the store's own read-back of our write, not an empty value", async () => {
|
|
963
|
+
const restore = stubGrid({ preview: 200, source: 188.7265625 }, () => 188.7265625);
|
|
964
|
+
try {
|
|
965
|
+
const key = ref("preview");
|
|
966
|
+
const container = document.createElement("div");
|
|
967
|
+
document.body.appendChild(container);
|
|
968
|
+
const app = createApp({
|
|
969
|
+
render: () => h(HkDirectionalSwap, { swapKey: key.value, animateHeight: true }, () => [h("p", key.value)]),
|
|
970
|
+
});
|
|
971
|
+
app.mount(container);
|
|
972
|
+
mounts.push({ app, container });
|
|
973
|
+
await settle();
|
|
974
|
+
const host = container.querySelector<HTMLElement>(".hk-dswap")!;
|
|
975
|
+
key.value = "source";
|
|
976
|
+
await nextTick();
|
|
977
|
+
await nextTick();
|
|
978
|
+
expect(host.hasAttribute("data-height-anim")).toBe(true);
|
|
979
|
+
// The armed value IS the store's report of the write we just made.
|
|
980
|
+
expect(host.style.height).not.toBe("");
|
|
981
|
+
expect(host.style.height).toMatch(/^[\d.]+px$/);
|
|
982
|
+
// …and the premise must SUPPORT the release: a "" / stale
|
|
983
|
+
// `armedHeight` leaves this explicit height behind for good.
|
|
984
|
+
await vi.waitFor(() => expect(host.hasAttribute("data-height-anim")).toBe(false), { timeout: 1000 });
|
|
985
|
+
expect(host.style.height, "the arm-time read-back must let the release through").toBe("");
|
|
986
|
+
} finally {
|
|
987
|
+
restore();
|
|
988
|
+
}
|
|
989
|
+
});
|
|
990
|
+
|
|
991
|
+
// MUT:swap-height-release-order — "armed" and "carries our explicit
|
|
992
|
+
// height" must be observable together: the height comes off BEFORE the
|
|
993
|
+
// armed attribute does. A MutationObserver cannot see this (both writes
|
|
994
|
+
// land in one synchronous block and the callback is a microtask, so it
|
|
995
|
+
// only ever sees the end state — measured: the reversed order passed a
|
|
996
|
+
// MutationObserver pin). The order is therefore pinned at the SEAM: the
|
|
997
|
+
// attribute removal is observed synchronously via an own-property hook
|
|
998
|
+
// on `removeAttribute`, and at that instant the inline height must
|
|
999
|
+
// already be gone.
|
|
1000
|
+
it("clears the height before dropping the armed attribute", async () => {
|
|
1001
|
+
const restore = stubGrid({ preview: 200, source: 188.7265625 });
|
|
1002
|
+
try {
|
|
1003
|
+
const key = ref("preview");
|
|
1004
|
+
const container = document.createElement("div");
|
|
1005
|
+
document.body.appendChild(container);
|
|
1006
|
+
const app = createApp({
|
|
1007
|
+
render: () => h(HkDirectionalSwap, { swapKey: key.value, animateHeight: true }, () => [h("p", key.value)]),
|
|
1008
|
+
});
|
|
1009
|
+
app.mount(container);
|
|
1010
|
+
mounts.push({ app, container });
|
|
1011
|
+
await settle();
|
|
1012
|
+
const host = container.querySelector<HTMLElement>(".hk-dswap")!;
|
|
1013
|
+
const atDisarm: string[] = [];
|
|
1014
|
+
const realRemove = host.removeAttribute.bind(host);
|
|
1015
|
+
Object.defineProperty(host, "removeAttribute", {
|
|
1016
|
+
configurable: true,
|
|
1017
|
+
value(name: string) {
|
|
1018
|
+
if (name === "data-height-anim") atDisarm.push(host.style.height);
|
|
1019
|
+
return realRemove(name);
|
|
1020
|
+
},
|
|
1021
|
+
});
|
|
1022
|
+
key.value = "source";
|
|
1023
|
+
await nextTick();
|
|
1024
|
+
await nextTick();
|
|
1025
|
+
await vi.waitFor(() => expect(host.hasAttribute("data-height-anim")).toBe(false), { timeout: 1000 });
|
|
1026
|
+
delete (host as unknown as Record<string, unknown>).removeAttribute;
|
|
1027
|
+
expect(atDisarm.length, "the disarm must be observed").toBeGreaterThan(0);
|
|
1028
|
+
expect(atDisarm, "the height must already be cleared when the armed attribute goes").toEqual([""]);
|
|
1029
|
+
expect(host.style.height).toBe("");
|
|
1030
|
+
} finally {
|
|
1031
|
+
restore();
|
|
1032
|
+
}
|
|
1033
|
+
});
|
|
1034
|
+
|
|
824
1035
|
// MUT:swap-height-zero-skips — an unreadable height (hidden host, or
|
|
825
1036
|
// an incoming pane not yet laid out reports 0) skips the tween: a
|
|
826
1037
|
// 0px freeze would collapse the surface for the whole exchange and
|
|
@@ -72,11 +72,12 @@
|
|
|
72
72
|
* the un-stretched read — the read returns the pin, and a pin at the
|
|
73
73
|
* row is the no-op again (see `readUnstretchedHeight`); hosts size
|
|
74
74
|
* the pane, the item's child. (b) The host is BORDER-BOX with no
|
|
75
|
-
* padding or border of its own:
|
|
76
|
-
* and
|
|
77
|
-
* is the content box — a padded
|
|
78
|
-
*
|
|
79
|
-
* neither, so the target
|
|
75
|
+
* padding or border of its own: the reads are `getBoundingClientRect`
|
|
76
|
+
* figures (border-box, fractional) and are written into `height`,
|
|
77
|
+
* which under `box-sizing: content-box` is the content box — a padded
|
|
78
|
+
* or bordered `.hk-dswap` would offset the tween by its box extra
|
|
79
|
+
* (the docs shell's host is border-box with neither, so the target
|
|
80
|
+
* path is exact).
|
|
80
81
|
*/
|
|
81
82
|
|
|
82
83
|
import { defineComponent, onBeforeUnmount, ref, Transition, watch, type PropType, type VNode } from "vue";
|
|
@@ -141,13 +142,16 @@ export function resolveSwapDirection(
|
|
|
141
142
|
* 240px, stretched and un-stretched both read 240 while the content is
|
|
142
143
|
* 100). Hosts size the PANE (the item's child); that is where the docs
|
|
143
144
|
* shell's band-fill lives, and this read runs before its attribute
|
|
144
|
-
* exists.
|
|
145
|
+
* exists. The read is the FRACTIONAL layout height
|
|
146
|
+
* (`getBoundingClientRect`), not the integer-rounded `offsetHeight` —
|
|
147
|
+
* the tween then ends exactly where the released `auto` lands, with no
|
|
148
|
+
* sub-pixel step at the release frame.
|
|
145
149
|
*/
|
|
146
150
|
export function readUnstretchedHeight(item: HTMLElement): number {
|
|
147
151
|
const prior = item.style.getPropertyValue("align-self");
|
|
148
152
|
const priority = item.style.getPropertyPriority("align-self");
|
|
149
153
|
item.style.alignSelf = "start";
|
|
150
|
-
const height = item.
|
|
154
|
+
const height = item.getBoundingClientRect().height;
|
|
151
155
|
if (prior) item.style.setProperty("align-self", prior, priority);
|
|
152
156
|
else item.style.removeProperty("align-self");
|
|
153
157
|
return height;
|
|
@@ -244,7 +248,7 @@ export default defineComponent({
|
|
|
244
248
|
* the enter hook it is too late: the insertion has already grown
|
|
245
249
|
* the row to the taller generation (measured live: the host reads
|
|
246
250
|
* 189 at rest and 200 the instant the taller copy lands). With a
|
|
247
|
-
* leaving copy still in the cell the host's
|
|
251
|
+
* leaving copy still in the cell the host's rect height is the
|
|
248
252
|
* ROW (the taller copy), not the rendered height — so this read is
|
|
249
253
|
* only true while the tween is still ARMED (an interrupted exchange
|
|
250
254
|
* reads its animated mid-state here) or while the cell holds one
|
|
@@ -291,16 +295,29 @@ export default defineComponent({
|
|
|
291
295
|
// alignment does not move the row (content-sized), so the host
|
|
292
296
|
// read below is unaffected.
|
|
293
297
|
const target = readUnstretchedHeight(item);
|
|
294
|
-
const from = start ?? host.
|
|
298
|
+
const from = start ?? host.getBoundingClientRect().height;
|
|
295
299
|
if (from === 0 || target === 0) return;
|
|
296
300
|
host.style.height = `${from}px`;
|
|
297
301
|
// Flush so the frozen height is the transition's computed start
|
|
298
302
|
// (a same-frame change from auto would jump instead of tween).
|
|
299
|
-
void host.
|
|
303
|
+
void host.getBoundingClientRect().height;
|
|
300
304
|
armedHost = host;
|
|
301
|
-
armedHeight = `${target}px`;
|
|
302
305
|
host.setAttribute("data-height-anim", "");
|
|
303
|
-
host.style.height =
|
|
306
|
+
host.style.height = `${target}px`;
|
|
307
|
+
// Remember what the STORE says our own write is, not what we passed
|
|
308
|
+
// it: a style declaration parses and re-serialises at set time, so
|
|
309
|
+
// `${target}px` need not come back byte-identical (`188.7265625px`
|
|
310
|
+
// reads back as `188.726563px` under happy-dom; a browser's own
|
|
311
|
+
// re-serialisation is whatever it is — the point of reading the
|
|
312
|
+
// value BACK is that this code does not have to know which).
|
|
313
|
+
// The read is SYNCHRONOUS — a declaration list, not a computed
|
|
314
|
+
// style — so no layout or frame is involved. Comparing the release
|
|
315
|
+
// against the read-back puts BOTH sides through the same serialiser:
|
|
316
|
+
// exact, with no tolerance window a host write could hide in. (The
|
|
317
|
+
// synchronous read-back is an engine property, not something a
|
|
318
|
+
// happy-dom pin can prove; the pin below covers the CONSEQUENCE —
|
|
319
|
+
// that our own write is cleared and a host write is not.)
|
|
320
|
+
armedHeight = host.style.height;
|
|
304
321
|
}
|
|
305
322
|
|
|
306
323
|
/** Release the explicit height back to auto and disarm the
|
|
@@ -322,11 +339,26 @@ export default defineComponent({
|
|
|
322
339
|
const host = hostRef.value ?? armedHost;
|
|
323
340
|
if (!host) return;
|
|
324
341
|
if (!host.hasAttribute("data-height-anim")) return;
|
|
342
|
+
// ORDER IS LOAD-BEARING: the height comes off BEFORE the armed
|
|
343
|
+
// attribute does. `data-height-anim` is what the stylesheet keys the
|
|
344
|
+
// height transition on, and it is also what a host would query to
|
|
345
|
+
// ask "is the tween running?" — leaving the attribute on for one
|
|
346
|
+
// extra statement keeps "armed" and "carries our explicit height"
|
|
347
|
+
// true together, instead of opening a window where the host reads
|
|
348
|
+
// armed=false while the explicit height is still set (R7).
|
|
349
|
+
// Exact compare, against the value the STORE itself reported for our
|
|
350
|
+
// write at arm time (`armedHeight` is read back, not the string we
|
|
351
|
+
// passed): both sides come out of the same serialiser, so whatever
|
|
352
|
+
// the store does to our string cancels instead of making our own
|
|
353
|
+
// write look foreign. (The exact re-serialisation is engine-specific
|
|
354
|
+
// and unmeasured here by design — this code does not depend on it.) Equality is therefore
|
|
355
|
+
// the right test — a tolerance would silently swallow a host's own
|
|
356
|
+
// sub-pixel write. (An unreadable value — `""`, NaN — compares false
|
|
357
|
+
// and the explicit height stays; that branch is unreachable through
|
|
358
|
+
// this component's own hooks, since arming requires both ends
|
|
359
|
+
// non-zero and nothing here writes `height` again.)
|
|
360
|
+
if (host.style.height === armedHeight) host.style.height = "";
|
|
325
361
|
host.removeAttribute("data-height-anim");
|
|
326
|
-
// Compared by value: this component writes integer px (offsetHeight
|
|
327
|
-
// is an integer), and a numeric compare is immune to how a browser
|
|
328
|
-
// re-serialises either side on read-back.
|
|
329
|
-
if (parseFloat(host.style.height) === parseFloat(armedHeight)) host.style.height = "";
|
|
330
362
|
armedHost = null;
|
|
331
363
|
armedHeight = "";
|
|
332
364
|
}
|
|
@@ -527,7 +559,7 @@ export default defineComponent({
|
|
|
527
559
|
// The last read before the row changes (see `restHeight`):
|
|
528
560
|
// the rendered height — at rest, or the animated mid-state
|
|
529
561
|
// of an interrupted tween that is still armed.
|
|
530
|
-
if (props.animateHeight && hostRef.value) restHeight = hostRef.value.
|
|
562
|
+
if (props.animateHeight && hostRef.value) restHeight = hostRef.value.getBoundingClientRect().height;
|
|
531
563
|
}}
|
|
532
564
|
onAfterLeave={() => {
|
|
533
565
|
// Vue removes the leaving copy BEFORE this hook runs, so
|
|
@@ -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.522 <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" />
|