@celestia-island/hikari 0.55.521 → 0.55.523
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/dist/types/index.d.ts +1 -1
- package/dist/types/runtime/clipboardHub.d.ts +87 -0
- package/dist/types/runtime/index.d.ts +1 -0
- package/dist/types/runtime/useClipboard.d.ts +5 -4
- package/package.json +1 -1
- package/src/components/HkCopyBadge.test.tsx +5 -2
- package/src/components/HkDirectionalSwap.scss +0 -4
- package/src/components/HkDirectionalSwap.test.tsx +251 -40
- package/src/components/HkDirectionalSwap.tsx +49 -17
- package/src/components/HkTable.interactions.test.tsx +5 -2
- package/src/errorLandingStandalone/error-landing.html +5 -5
- package/src/index.ts +8 -0
- package/src/runtime/clipboardHub.test.ts +234 -0
- package/src/runtime/clipboardHub.ts +183 -0
- package/src/runtime/index.ts +10 -0
- package/src/runtime/useClipboard.test.ts +57 -1
- package/src/runtime/useClipboard.ts +18 -30
- package/src/wasm/highlight/hikari_wasm_highlight.js +2140 -4514
- package/src/wasm/mermaid/hikari_wasm_mermaid.js +2153 -4540
- package/src/wasm/qr/hikari_wasm_qr.js +2152 -4479
- package/src/wasm/scene3d/hikari_wasm_scene3d.js +2223 -4697
|
@@ -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/dist/types/index.d.ts
CHANGED
|
@@ -177,7 +177,7 @@ export type { SemanticPalette, SemanticFills, OKLCH } from "./theme/semanticPale
|
|
|
177
177
|
export { FALLBACK_WALLPAPER_ID, DEFAULT_WALLPAPER_ID, DEFAULT_PRESETS, DEFAULT_DISPLAY_SETTINGS, DEFAULT_WALLPAPER_STORAGE_PREFIX, registerWallpaperPack, configureWallpaperStorage, wallpaperStorageKey, isWallpaperSource, isTimeAware, loadActiveWallpaperId, hasStoredWallpaperId, saveActiveWallpaperId, loadCustomWallpapers, saveCustomWallpapers, addCustomWallpaper, removeCustomWallpaper, updateCustomWallpaper, loadCachedGeolocation, saveCachedGeolocation, loadDisplaySettings, saveDisplaySettings, getDisplaySettings, setDisplaySettings, buildWallpaperFilter, initWallpaper, destroyWallpaper, useWallpaper, ensureWallpaperState, configureWallpaper, registerWallpaperBrandDefaults, registerServerThemeWallpaper, brandDefaultWallpaperFor, resolveThemeFollowSwitch, setWallpaperPipelineLookup, geo, currentPeriod, hasStorage, readStorageItem, writeStorageItem, removeStorageItem, type WallpaperType, type SolidSource, type ImageSource, type VideoSource, type PipelineSource, type WallpaperSource, type TimeAwareWallpaper, type WallpaperPreset, type WallpaperPackEntry, type CustomWallpaper, type WallpaperPosition, type WallpaperScale, type WallpaperEffect, type WallpaperDisplaySettings, type WallpaperStorageSlot, type WallpaperStorageConfig, type WallpaperInitConfig, type WallpaperPipelineLookup, type WallpaperPipelinePreset, } from "./theme";
|
|
178
178
|
export { registerShaderPresets, getShaderPreset, listShaderPresetIds, SHADER_VERTEX, WallpaperShaderPipeline, createWallpaperShaderSurface, type WallpaperShaderPreset, type WallpaperShaderPresetInput, type WallpaperShaderScaleConfig, type WallpaperShaderScaleInput, type WallpaperShaderOverlayConfig, } from "./theme";
|
|
179
179
|
export { default as HkWallpaperBackdrop, WALLPAPER_REDUCED_MOTION_QUERY, type HkWallpaperBackdropMode, type HkWallpaperSurface, type HkWallpaperSurfaceContext, type HkWallpaperSurfaceFactory, } from "./components/HkWallpaperBackdrop";
|
|
180
|
-
export { onFrame, onceFrame, scheduleFrame, scheduleEvery, scheduleAfter, scheduleCron, scheduleCronAfter, scheduleInterval, scheduleIntervalAfter, reportTransition, setReducedMotion, notifyScrollStart, useOverlay, hasLiveWindow, isWindowEntry, topWindowZ, usePopupManager, POPUP_Z_BANDS, POPUP_Z_STEP, useToast, useConfirm, useBlockingToast, showBlockingToast, resolveBlockingToast, clearBlockingToasts, useEmergencyAlert, raiseEmergencyAlert, clearEmergencyAlert, snoozeEmergencyAlert, unsnoozeEmergencyAlert, resetEmergencyAlerts, emergencySeverityRank, useNotificationCenter, recordNotification, setNotificationState, forgetNotification, markAllNotificationsRead, resetNotifications, MAX_NOTIFICATION_ENTRIES, type HkNotificationEntry, type HkNotificationKind, type HkNotificationRecordInput, type HkNotificationState, type HkNotificationTone, type EmergencyAlertItem, type EmergencyAlertOptions, type EmergencyAction, type EmergencySeverity, type BlockingToastItem, type BlockingToastOptions, type BlockingToastVariant, useScreenIdentify, showScreenIdentify, dismissScreenIdentify, SCREEN_IDENTIFY_DEFAULT_MS, SCREEN_IDENTIFY_TICK_MS, type ScreenIdentifyRequest, type ScreenIdentifyContext, useBreakpoint, useClipboard, useClipboardWithToast, useMediaQuery, releaseMediaQuery, usePageLifecycle, onPageLifecycle, pageLifecycleState, useSafeArea, applyViewportPolicy, parseViewportContent, type ApplyViewportPolicyOptions, type ViewportPolicyResult, closeAll, isOverlayOpen, TOAST_DURATION, createBackGuard, BACK_GUARD_MARKER, BACK_GUARD_DEPTH, type AnimationHandle, useReportedTransition, type ReportedTransition, type ReportedTransitionTrack, type CronHandle, type IntervalHandle, type FrameContext, type OverlayHandle, type PopupHandle, type PopupKind, type ToastAction, type ToastItem, type ToastMessage, type ToastType, type PageLifecycleState, type PageLifecycleListener, type SafeAreaInsets, type BackGuard, type BackGuardOptions, installHkTooltipBridge, type HkTooltipBridgeOptions, installHkImageFallback, type HkImageFallbackOptions, installHkTapHighlight, type HkTapHighlightOptions, type HkTapHighlightColor, installHkTouchHintBridge, showHkTouchHintBar, armTouchHint, type HkTouchHintOptions, type HkTouchHintArmOptions, reportHkRuntime, getHkRuntimeEntry, listHkRuntime, readHkRuntime, writeHkRuntime, hkRuntimeSnapshot, useHkRegistry, type HkRuntimeKind, type HkRuntimeStatus, type HkRuntimeMeta, type HkRuntimeEntryState, type HkRuntimeReport, type HkRuntimeHandle, type HkRuntimeWriteOp, type HkRuntimeSnapshot, type HkRuntimeSnapshotEntry, } from "./runtime";
|
|
180
|
+
export { onFrame, onceFrame, scheduleFrame, scheduleEvery, scheduleAfter, scheduleCron, scheduleCronAfter, scheduleInterval, scheduleIntervalAfter, reportTransition, setReducedMotion, notifyScrollStart, useOverlay, hasLiveWindow, isWindowEntry, topWindowZ, usePopupManager, POPUP_Z_BANDS, POPUP_Z_STEP, useToast, useConfirm, useBlockingToast, showBlockingToast, resolveBlockingToast, clearBlockingToasts, useEmergencyAlert, raiseEmergencyAlert, clearEmergencyAlert, snoozeEmergencyAlert, unsnoozeEmergencyAlert, resetEmergencyAlerts, emergencySeverityRank, useNotificationCenter, recordNotification, setNotificationState, forgetNotification, markAllNotificationsRead, resetNotifications, MAX_NOTIFICATION_ENTRIES, type HkNotificationEntry, type HkNotificationKind, type HkNotificationRecordInput, type HkNotificationState, type HkNotificationTone, type EmergencyAlertItem, type EmergencyAlertOptions, type EmergencyAction, type EmergencySeverity, type BlockingToastItem, type BlockingToastOptions, type BlockingToastVariant, useScreenIdentify, showScreenIdentify, dismissScreenIdentify, SCREEN_IDENTIFY_DEFAULT_MS, SCREEN_IDENTIFY_TICK_MS, type ScreenIdentifyRequest, type ScreenIdentifyContext, useBreakpoint, useClipboard, useClipboardWithToast, useMediaQuery, releaseMediaQuery, usePageLifecycle, onPageLifecycle, pageLifecycleState, useSafeArea, applyViewportPolicy, parseViewportContent, type ApplyViewportPolicyOptions, type ViewportPolicyResult, closeAll, isOverlayOpen, TOAST_DURATION, createBackGuard, BACK_GUARD_MARKER, BACK_GUARD_DEPTH, type AnimationHandle, useReportedTransition, type ReportedTransition, type ReportedTransitionTrack, type CronHandle, type IntervalHandle, type FrameContext, type OverlayHandle, type PopupHandle, type PopupKind, type ToastAction, type ToastItem, type ToastMessage, type ToastType, type PageLifecycleState, type PageLifecycleListener, type SafeAreaInsets, type BackGuard, type BackGuardOptions, installHkTooltipBridge, type HkTooltipBridgeOptions, installHkImageFallback, type HkImageFallbackOptions, installHkTapHighlight, type HkTapHighlightOptions, type HkTapHighlightColor, installHkTouchHintBridge, showHkTouchHintBar, armTouchHint, type HkTouchHintOptions, type HkTouchHintArmOptions, reportHkRuntime, getHkRuntimeEntry, listHkRuntime, readHkRuntime, writeHkRuntime, hkRuntimeSnapshot, useHkRegistry, type HkRuntimeKind, type HkRuntimeStatus, type HkRuntimeMeta, type HkRuntimeEntryState, type HkRuntimeReport, type HkRuntimeHandle, type HkRuntimeWriteOp, type HkRuntimeSnapshot, type HkRuntimeSnapshotEntry, configureClipboardHub, clipboardHubConfig, getClipboardHub, writeClipboardText, type ClipboardCopyOptions, type ClipboardEntry, type ClipboardHub, type ClipboardHubConfig, } from "./runtime";
|
|
181
181
|
export { useI18n, setLocale, activeLocale, mergeMessages, } from "./i18n/context";
|
|
182
182
|
export { HK_LOCALE_CATALOG, type HkLocaleCatalogEntry } from "./i18n/localeCatalog";
|
|
183
183
|
export { fuzzyScore, fuzzyScoreFields, fuzzySearch } from "./utils/fuzzy";
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The family's ONE clipboard context (user direction 2026-12-01: copy paths
|
|
3
|
+
* converge here — hosts stop owning private `navigator.clipboard` /
|
|
4
|
+
* `execCommand` sequences and consume this hub instead).
|
|
5
|
+
*
|
|
6
|
+
* Framework-free on purpose: the Vue hooks (`useClipboard`,
|
|
7
|
+
* `useClipboardWithToast`) wrap it, and non-Vue consumers (the lagrange docs
|
|
8
|
+
* shell's delegated DOM handlers today; any future host runtime) import the
|
|
9
|
+
* same module-scoped singleton, so every writer on a page shares one
|
|
10
|
+
* implementation, one history, one place to fix browser quirks in.
|
|
11
|
+
*
|
|
12
|
+
* The write core NEVER reports success it did not observe:
|
|
13
|
+
*
|
|
14
|
+
* - `navigator.clipboard.writeText` is awaited; only a fulfilled promise
|
|
15
|
+
* means "the clipboard now holds the text" (the browser contract).
|
|
16
|
+
* - Outside secure contexts (and wherever the async API refuses), the
|
|
17
|
+
* textarea + `execCommand("copy")` fallback runs, and `execCommand`
|
|
18
|
+
* reports failure by RETURNING false — treating that falsy return as
|
|
19
|
+
* success is exactly the defect that surfaced "Copied" toasts for writes
|
|
20
|
+
* that never landed (hikari #409, lagrange #211 follow-ups).
|
|
21
|
+
*
|
|
22
|
+
* History is the first of the hub's fine-grained management features: an
|
|
23
|
+
* in-memory ring of recent writes (newest first) with a subscribe hook, so
|
|
24
|
+
* hosts can surface "what did I copy" UI or audit writes without each
|
|
25
|
+
* consumer rolling its own log. Recording is on by default and can be turned
|
|
26
|
+
* off globally (`configureClipboardHub`) — e.g. on pages where clipboard
|
|
27
|
+
* content is sensitive enough that keeping it in memory is wrong.
|
|
28
|
+
*/
|
|
29
|
+
export interface ClipboardEntry {
|
|
30
|
+
/** The text that was written. */
|
|
31
|
+
text: string;
|
|
32
|
+
/** Epoch milliseconds at the moment the write was confirmed. */
|
|
33
|
+
at: number;
|
|
34
|
+
/**
|
|
35
|
+
* Optional call-site label (`copy(text, { source: "code-block" })`) —
|
|
36
|
+
* lets a history surface distinguish code blocks, badges, modals…
|
|
37
|
+
*/
|
|
38
|
+
source?: string;
|
|
39
|
+
}
|
|
40
|
+
export interface ClipboardCopyOptions {
|
|
41
|
+
/** Call-site label recorded into history alongside the text. */
|
|
42
|
+
source?: string;
|
|
43
|
+
/** Skip the history ring for this one write (defaults to recording). */
|
|
44
|
+
record?: boolean;
|
|
45
|
+
}
|
|
46
|
+
export interface ClipboardHubConfig {
|
|
47
|
+
/**
|
|
48
|
+
* Ring capacity; the oldest entry falls off. Default 50, 0 disables.
|
|
49
|
+
* **Zero is the global off switch**: with a zero limit nothing is recorded,
|
|
50
|
+
* and a per-call `record: true` cannot bypass it — a page that decided its
|
|
51
|
+
* clipboard contents must not sit in memory must not be undone by an
|
|
52
|
+
* individual writer.
|
|
53
|
+
*/
|
|
54
|
+
historyLimit?: number;
|
|
55
|
+
/** Master switch for history recording. Default true. */
|
|
56
|
+
recordHistory?: boolean;
|
|
57
|
+
}
|
|
58
|
+
export interface ClipboardHub {
|
|
59
|
+
/**
|
|
60
|
+
* The single write path. Resolves to whether the clipboard verifiably
|
|
61
|
+
* received the text; a confirmed write is appended to history.
|
|
62
|
+
*/
|
|
63
|
+
copy(text: string, options?: ClipboardCopyOptions): Promise<boolean>;
|
|
64
|
+
/** Recent confirmed writes, newest first (a readonly snapshot). */
|
|
65
|
+
history(): readonly ClipboardEntry[];
|
|
66
|
+
/** Drops every recorded entry. */
|
|
67
|
+
clearHistory(): void;
|
|
68
|
+
/**
|
|
69
|
+
* Notified after every confirmed write and every clear. Returns the
|
|
70
|
+
* unsubscribe function.
|
|
71
|
+
*/
|
|
72
|
+
subscribe(listener: () => void): () => void;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* The one write sequence every consumer shares. Never returns true unless a
|
|
76
|
+
* write verifiably landed. Exported for tests and for the rare caller that
|
|
77
|
+
* wants the raw write without touching the hub's history.
|
|
78
|
+
*/
|
|
79
|
+
export declare function writeClipboardText(text: string): Promise<boolean>;
|
|
80
|
+
export declare function configureClipboardHub(config: ClipboardHubConfig): void;
|
|
81
|
+
/** Read-mostly view of the active config (tests assert against it). */
|
|
82
|
+
export declare function clipboardHubConfig(): Required<ClipboardHubConfig>;
|
|
83
|
+
/**
|
|
84
|
+
* The page-wide clipboard context. Every caller in the same bundle gets the
|
|
85
|
+
* same instance — that is the whole point of the convergence.
|
|
86
|
+
*/
|
|
87
|
+
export declare function getClipboardHub(): ClipboardHub;
|
|
@@ -28,6 +28,7 @@ export { useEmergencyAlert, raiseEmergencyAlert, clearEmergencyAlert, snoozeEmer
|
|
|
28
28
|
export { useScreenIdentify, showScreenIdentify, dismissScreenIdentify, SCREEN_IDENTIFY_DEFAULT_MS, SCREEN_IDENTIFY_TICK_MS, type ScreenIdentifyRequest, type ScreenIdentifyContext, } from "./useScreenIdentify";
|
|
29
29
|
export { useBreakpoint } from "./useBreakpoint";
|
|
30
30
|
export { useClipboard, useClipboardWithToast } from "./useClipboard";
|
|
31
|
+
export { configureClipboardHub, clipboardHubConfig, getClipboardHub, writeClipboardText, type ClipboardCopyOptions, type ClipboardEntry, type ClipboardHub, type ClipboardHubConfig, } from "./clipboardHub";
|
|
31
32
|
export { provideScrollWindow, useScrollWindow, type ScrollWindowContext } from "../composables/useScrollWindow";
|
|
32
33
|
export { useReportedTransition, type ReportedTransition, type ReportedTransitionTrack } from "../composables/useReportedTransition";
|
|
33
34
|
export { showProgressDialog, useProgressDialog, type ProgressDialogHandle, type ProgressDialogState } from "../composables/useProgressDialog";
|
|
@@ -6,10 +6,11 @@ export declare function useClipboard(): {
|
|
|
6
6
|
* Clipboard copy with a toast on success/failure.
|
|
7
7
|
* (Upstreamed from shittim-chest's plana-legacy layer.)
|
|
8
8
|
*
|
|
9
|
-
* Wraps the base `useClipboard` above (which
|
|
10
|
-
*
|
|
11
|
-
* `copied` reflects the 2s copied
|
|
12
|
-
* hikari's `useToast()` surface
|
|
9
|
+
* Wraps the base `useClipboard` above (which now delegates to the shared
|
|
10
|
+
* clipboard hub — the write sequence and the history ring are family-wide,
|
|
11
|
+
* not per-hook) and adds toast feedback; `copied` reflects the 2s copied
|
|
12
|
+
* state. The `toast` argument matches hikari's `useToast()` surface
|
|
13
|
+
* (`success` / `error` message pushers).
|
|
13
14
|
*
|
|
14
15
|
* Default toast messages come from hikari's own i18n
|
|
15
16
|
* (`hikari::clipboard.copied` / `hikari::clipboard.copyFailed`) so a
|
package/package.json
CHANGED
|
@@ -68,8 +68,11 @@ describe("HkCopyBadge", () => {
|
|
|
68
68
|
it("copies the rendered text on click and toasts the localized default", async () => {
|
|
69
69
|
const c = mount(() => h(HkCopyBadge, null, () => "#demiurge.132"));
|
|
70
70
|
(c.querySelector(".hk-badge") as HTMLElement).click();
|
|
71
|
-
|
|
72
|
-
|
|
71
|
+
// The copy write runs through the shared clipboard hub (user direction
|
|
72
|
+
// 2026-12-01): more promise hops between the click and the toast —
|
|
73
|
+
// still zero-milliseconds in real time, so flush to a settled state
|
|
74
|
+
// instead of counting microtasks.
|
|
75
|
+
for (let i = 0; i < 10; i++) await Promise.resolve();
|
|
73
76
|
|
|
74
77
|
expect(writeText).toHaveBeenCalledWith("#demiurge.132");
|
|
75
78
|
const success = useToast().toasts.find((t) => t.type === "success");
|
|
@@ -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
|