@celestia-island/hikari 0.55.451 → 0.55.454
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/HkScrollContainer.d.ts +47 -0
- package/dist/types/composables/useHighlight.d.ts +13 -0
- package/package.json +1 -1
- package/src/components/HkDiffViewer.epoch.test.tsx +6 -2
- package/src/components/HkKeywordSearchModal.tsx +3 -27
- package/src/components/HkLogWindow.tsx +2 -0
- package/src/components/HkModal.scss +4 -0
- package/src/components/HkPopupSelect.test.tsx +43 -0
- package/src/components/HkPopupSelect.tsx +17 -7
- package/src/components/HkScrollContainer.keyboard.contract.test.ts +60 -0
- package/src/components/HkScrollContainer.scss +8 -0
- package/src/components/HkScrollContainer.tsx +48 -0
- package/src/components/HkSerpentineUnlock.scss +1 -0
- package/src/components/HkSerpentineUnlock.test.ts +5 -6
- package/src/components/HkSerpentineUnlock.tsx +1 -1
- package/src/composables/useHighlight.adaptResult.test.ts +61 -0
- package/src/composables/useHighlight.ts +25 -4
|
@@ -50,6 +50,28 @@ declare const _default: import("vue").DefineComponent<import("vue").ExtractPropT
|
|
|
50
50
|
type: BooleanConstructor;
|
|
51
51
|
default: boolean;
|
|
52
52
|
};
|
|
53
|
+
/** Keyboard access for the scrollable region (WCAG 2.1.1): the viewport
|
|
54
|
+
* takes `tabindex=0` and arrows / PageUp / PageDown / Home / End scroll
|
|
55
|
+
* it. Default ON — a scrollable region a keyboard user cannot reach is
|
|
56
|
+
* a compliance defect, and an extra tab stop is the standard cost
|
|
57
|
+
* (the viewport only scrolls while IT holds focus, so inner inputs,
|
|
58
|
+
* buttons and links keep their own key handling). */
|
|
59
|
+
keyboardScroll: {
|
|
60
|
+
type: BooleanConstructor;
|
|
61
|
+
default: boolean;
|
|
62
|
+
};
|
|
63
|
+
/** ARIA role for the viewport. Use a NON-live role ("region") for
|
|
64
|
+
* streaming content — "log"/"feed" carry implicit live semantics and
|
|
65
|
+
* would announce every appended line. Omitted = no role attribute. */
|
|
66
|
+
scrollRole: {
|
|
67
|
+
type: StringConstructor;
|
|
68
|
+
default: undefined;
|
|
69
|
+
};
|
|
70
|
+
/** Accessible name for the viewport (announced with the role). */
|
|
71
|
+
scrollLabel: {
|
|
72
|
+
type: StringConstructor;
|
|
73
|
+
default: undefined;
|
|
74
|
+
};
|
|
53
75
|
overscanScreens: {
|
|
54
76
|
type: NumberConstructor;
|
|
55
77
|
default: number;
|
|
@@ -496,6 +518,28 @@ declare const _default: import("vue").DefineComponent<import("vue").ExtractPropT
|
|
|
496
518
|
type: BooleanConstructor;
|
|
497
519
|
default: boolean;
|
|
498
520
|
};
|
|
521
|
+
/** Keyboard access for the scrollable region (WCAG 2.1.1): the viewport
|
|
522
|
+
* takes `tabindex=0` and arrows / PageUp / PageDown / Home / End scroll
|
|
523
|
+
* it. Default ON — a scrollable region a keyboard user cannot reach is
|
|
524
|
+
* a compliance defect, and an extra tab stop is the standard cost
|
|
525
|
+
* (the viewport only scrolls while IT holds focus, so inner inputs,
|
|
526
|
+
* buttons and links keep their own key handling). */
|
|
527
|
+
keyboardScroll: {
|
|
528
|
+
type: BooleanConstructor;
|
|
529
|
+
default: boolean;
|
|
530
|
+
};
|
|
531
|
+
/** ARIA role for the viewport. Use a NON-live role ("region") for
|
|
532
|
+
* streaming content — "log"/"feed" carry implicit live semantics and
|
|
533
|
+
* would announce every appended line. Omitted = no role attribute. */
|
|
534
|
+
scrollRole: {
|
|
535
|
+
type: StringConstructor;
|
|
536
|
+
default: undefined;
|
|
537
|
+
};
|
|
538
|
+
/** Accessible name for the viewport (announced with the role). */
|
|
539
|
+
scrollLabel: {
|
|
540
|
+
type: StringConstructor;
|
|
541
|
+
default: undefined;
|
|
542
|
+
};
|
|
499
543
|
overscanScreens: {
|
|
500
544
|
type: NumberConstructor;
|
|
501
545
|
default: number;
|
|
@@ -908,6 +952,9 @@ declare const _default: import("vue").DefineComponent<import("vue").ExtractPropT
|
|
|
908
952
|
as: string;
|
|
909
953
|
markersWidth: number;
|
|
910
954
|
mapSegments: OverlayScrollMapSegment[];
|
|
955
|
+
keyboardScroll: boolean;
|
|
956
|
+
scrollRole: string;
|
|
957
|
+
scrollLabel: string;
|
|
911
958
|
fade: boolean;
|
|
912
959
|
fadeDistance: number;
|
|
913
960
|
overflowGlow: boolean;
|
|
@@ -1,3 +1,16 @@
|
|
|
1
|
+
import type { HighlightResult } from "../wasm/highlight/hikari_wasm_highlight.js";
|
|
2
|
+
/**
|
|
3
|
+
* Adapt the generated wasm record to this module's contract.
|
|
4
|
+
*
|
|
5
|
+
* `string` = highlighted HTML; `null` = "the wasm has no highlighting for
|
|
6
|
+
* this input", which every caller renders as plaintext. The wasm omits
|
|
7
|
+
* `html` (`{ html: undefined }`) whenever it cannot highlight — an
|
|
8
|
+
* unregistered language, or a tokenizer failure on a known one — and an
|
|
9
|
+
* empty string is a real answer, so this is `??` — not `||` — and never
|
|
10
|
+
* the record itself. Split out from `highlight()` so the seam can be
|
|
11
|
+
* pinned table-driven, without the lazy-loading mock in the way.
|
|
12
|
+
*/
|
|
13
|
+
export declare function adaptHighlightResult(result: HighlightResult): string | null;
|
|
1
14
|
/** Highlight `code` in `lang`; plain text until the wasm module loads. */
|
|
2
15
|
export declare function highlight(code: string, lang?: string): string;
|
|
3
16
|
/**
|
package/package.json
CHANGED
|
@@ -3,9 +3,13 @@ import { createApp, defineComponent, h } from "vue";
|
|
|
3
3
|
|
|
4
4
|
// Mock the wasm module at the top level: the composable's lazy import()
|
|
5
5
|
// resolves to this factory, exactly like the real module landing after
|
|
6
|
-
// the first plaintext render.
|
|
6
|
+
// the first plaintext render. The shape is the real ABI — the binding
|
|
7
|
+
// returns `HighlightResult = { html?: string }`, NOT a bare string
|
|
8
|
+
// (packages/vue/src/wasm/highlight/hikari_wasm_highlight.d.ts). A string
|
|
9
|
+
// mock here hid the seam that fed the record to `v-html`, so every row
|
|
10
|
+
// rendered "[object Object]"; the adapter test pins that separately.
|
|
7
11
|
vi.mock("../wasm/highlight/hikari_wasm_highlight.js", () => ({
|
|
8
|
-
highlight: (text: string, lang: string) => `<wasm>${lang}:${text}</wasm
|
|
12
|
+
highlight: (text: string, lang: string) => ({ html: `<wasm>${lang}:${text}</wasm>` }),
|
|
9
13
|
}));
|
|
10
14
|
|
|
11
15
|
import HkDiffViewer from "./HkDiffViewer";
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import HkIconButton from "./HkIconButton";
|
|
2
2
|
|
|
3
3
|
import { computed, defineComponent, onBeforeUnmount, ref, watch, type PropType } from "vue";
|
|
4
|
+
import { Search, X } from "lucide-vue-next";
|
|
4
5
|
|
|
5
6
|
import { useI18n } from "../i18n/context";
|
|
6
7
|
|
|
@@ -221,19 +222,7 @@ export default defineComponent({
|
|
|
221
222
|
>
|
|
222
223
|
<div class="hk-kw-search">
|
|
223
224
|
<div class="hk-kw-search-box">
|
|
224
|
-
<
|
|
225
|
-
class="hk-kw-search-icon"
|
|
226
|
-
width="15"
|
|
227
|
-
height="15"
|
|
228
|
-
viewBox="0 0 24 24"
|
|
229
|
-
fill="none"
|
|
230
|
-
stroke="currentColor"
|
|
231
|
-
stroke-width="2"
|
|
232
|
-
stroke-linecap="round"
|
|
233
|
-
>
|
|
234
|
-
<circle cx="11" cy="11" r="8" />
|
|
235
|
-
<line x1="21" y1="21" x2="16.65" y2="16.65" />
|
|
236
|
-
</svg>
|
|
225
|
+
<Search class="hk-kw-search-icon" size={15} />
|
|
237
226
|
<input
|
|
238
227
|
class="hk-kw-search-input"
|
|
239
228
|
type="text"
|
|
@@ -254,20 +243,7 @@ export default defineComponent({
|
|
|
254
243
|
semanticResults.value = [];
|
|
255
244
|
}}
|
|
256
245
|
>
|
|
257
|
-
{{ icon: () =>
|
|
258
|
-
<svg
|
|
259
|
-
width="14"
|
|
260
|
-
height="14"
|
|
261
|
-
viewBox="0 0 24 24"
|
|
262
|
-
fill="none"
|
|
263
|
-
stroke="currentColor"
|
|
264
|
-
stroke-width="2"
|
|
265
|
-
stroke-linecap="round"
|
|
266
|
-
>
|
|
267
|
-
<line x1="18" y1="6" x2="6" y2="18" />
|
|
268
|
-
<line x1="6" y1="6" x2="18" y2="18" />
|
|
269
|
-
</svg>
|
|
270
|
-
) }}
|
|
246
|
+
{{ icon: () => <X size={14} /> }}
|
|
271
247
|
</HkIconButton>
|
|
272
248
|
)}
|
|
273
249
|
</div>
|
|
@@ -178,6 +178,8 @@ export const HkLogWindow = defineComponent({
|
|
|
178
178
|
<HScrollContainer
|
|
179
179
|
class="s-log-viewer-scroll"
|
|
180
180
|
autoFollow={autoscroll.value && !paused.value}
|
|
181
|
+
scrollRole="region"
|
|
182
|
+
scrollLabel={props.title ?? t("hikari::log.title", "Logs")}
|
|
181
183
|
ref={scrollRef}
|
|
182
184
|
>
|
|
183
185
|
{currentLines.value.length === 0 ? (
|
|
@@ -144,6 +144,10 @@
|
|
|
144
144
|
translate: calc(-50% + var(--hk-modal-shift-x, 0px))
|
|
145
145
|
calc(-50% + var(--hk-modal-shift-y, 0px));
|
|
146
146
|
width: 100%;
|
|
147
|
+
// Reasonable upper bound: a 2734px-wide viewport with width:100% gives
|
|
148
|
+
// a modal frame wider than the content can usefully fill — the body
|
|
149
|
+
// area sits off-center and the border-radius corners become invisible.
|
|
150
|
+
max-width: min(680px, 90vw);
|
|
147
151
|
// Size changes animate instead of snapping: `height: auto` growth
|
|
148
152
|
// cannot fire a CSS transition (verified in Chromium — neither auto
|
|
149
153
|
// nor calc-size(auto, size) changes its computed value on content
|
|
@@ -128,4 +128,47 @@ describe("HkPopupSelect", () => {
|
|
|
128
128
|
expect(value.textContent).toBe("Agent One");
|
|
129
129
|
expect(value.textContent).not.toContain("secret-meta");
|
|
130
130
|
});
|
|
131
|
+
|
|
132
|
+
it("scroll-to-highlight resolves inside this popup's viewport, never the document", async () => {
|
|
133
|
+
// The issue #907 collision: a foreign surface's row carries the SAME
|
|
134
|
+
// data-select-index and sits EARLIER in document order than the
|
|
135
|
+
// teleported panel (the overlay root is appended after this test's
|
|
136
|
+
// mount containers), so a document-scoped query resolved to it first
|
|
137
|
+
// and scrolled the wrong row. The prototype spy records every
|
|
138
|
+
// scrollIntoView target, pinning where the query actually resolved.
|
|
139
|
+
const decoy = document.createElement("div");
|
|
140
|
+
decoy.setAttribute("data-select-index", "1");
|
|
141
|
+
document.body.appendChild(decoy);
|
|
142
|
+
const scrolled: Element[] = [];
|
|
143
|
+
const spy = vi
|
|
144
|
+
.spyOn(Element.prototype, "scrollIntoView")
|
|
145
|
+
.mockImplementation(function (this: Element) {
|
|
146
|
+
scrolled.push(this);
|
|
147
|
+
});
|
|
148
|
+
try {
|
|
149
|
+
// modelValue "a2" → the popup opens with index 1 highlighted.
|
|
150
|
+
const c = mount(h(HkPopupSelect, { modelValue: "a2", options: OPTIONS }));
|
|
151
|
+
c.querySelector<HTMLButtonElement>(".hk-popup-select-trigger")!
|
|
152
|
+
.dispatchEvent(new MouseEvent("click", { bubbles: true }));
|
|
153
|
+
await Promise.resolve();
|
|
154
|
+
await Promise.resolve();
|
|
155
|
+
const ownRow = document.querySelector<HTMLElement>(
|
|
156
|
+
'.hk-popup-select-item[data-select-index="1"]',
|
|
157
|
+
);
|
|
158
|
+
expect(ownRow).toBeTruthy();
|
|
159
|
+
// Sanity: the row really lives inside the popup's own viewport.
|
|
160
|
+
expect(ownRow!.closest(".hk-popup-select-viewport")).not.toBeNull();
|
|
161
|
+
// The highlighted row got scrolled…
|
|
162
|
+
expect(scrolled).toContain(ownRow);
|
|
163
|
+
// …and nothing outside this popup's viewport ever did — the decoy
|
|
164
|
+
// must not even be reached by the query.
|
|
165
|
+
expect(scrolled).not.toContain(decoy);
|
|
166
|
+
for (const el of scrolled) {
|
|
167
|
+
expect(el.closest(".hk-popup-select-viewport")).not.toBeNull();
|
|
168
|
+
}
|
|
169
|
+
} finally {
|
|
170
|
+
spy.mockRestore();
|
|
171
|
+
decoy.remove();
|
|
172
|
+
}
|
|
173
|
+
});
|
|
131
174
|
});
|
|
@@ -31,11 +31,6 @@ export function closeAllPopups(): void {
|
|
|
31
31
|
activePopupId.value = null;
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
function scrollToElement(selector: string): void {
|
|
35
|
-
const el = document.querySelector(selector) as HTMLElement | null;
|
|
36
|
-
el?.scrollIntoView({ block: "nearest" });
|
|
37
|
-
}
|
|
38
|
-
|
|
39
34
|
export default defineComponent({
|
|
40
35
|
name: "HkPopupSelect",
|
|
41
36
|
props: {
|
|
@@ -68,6 +63,9 @@ export default defineComponent({
|
|
|
68
63
|
const instanceId = `hk-popup-select-${++popupCounter}`;
|
|
69
64
|
const isOpen = ref(false);
|
|
70
65
|
const triggerRef = ref<HTMLElement>();
|
|
66
|
+
/** The popup's own scroll viewport (HkScrollContainer expose) — row
|
|
67
|
+
* queries stay scoped to it. */
|
|
68
|
+
const viewportExpose = ref<{ getScrollElement: () => HTMLElement | undefined }>();
|
|
71
69
|
const highlightedIndex = ref(-1);
|
|
72
70
|
|
|
73
71
|
// Registered with the overlay registry so closeAll()/isOverlayOpen()
|
|
@@ -180,7 +178,16 @@ export default defineComponent({
|
|
|
180
178
|
});
|
|
181
179
|
|
|
182
180
|
function scrollToHighlighted() {
|
|
183
|
-
|
|
181
|
+
// Scoped to OUR viewport — a document-scoped query could hit another
|
|
182
|
+
// concurrently open surface's rows (HkSelect/HkCurrencySelect/
|
|
183
|
+
// HkHeaderPicker panels carry the same data attribute), and the
|
|
184
|
+
// teleported panel is not even inside this component's own subtree
|
|
185
|
+
// (HkSelect's rule). Null viewport (panel not mounted yet) → no-op.
|
|
186
|
+
const root = viewportExpose.value?.getScrollElement() ?? null;
|
|
187
|
+
const el = root?.querySelector(
|
|
188
|
+
`[data-select-index="${highlightedIndex.value}"]`,
|
|
189
|
+
);
|
|
190
|
+
el?.scrollIntoView({ block: "nearest" });
|
|
184
191
|
}
|
|
185
192
|
|
|
186
193
|
watch(highlightedIndex, () => {
|
|
@@ -228,7 +235,10 @@ export default defineComponent({
|
|
|
228
235
|
title={props.label || props.placeholder || undefined}
|
|
229
236
|
class="hk-popup-select-content"
|
|
230
237
|
>
|
|
231
|
-
<HkScrollContainer
|
|
238
|
+
<HkScrollContainer
|
|
239
|
+
ref={viewportExpose}
|
|
240
|
+
class="hk-popup-select-viewport"
|
|
241
|
+
>
|
|
232
242
|
{slots.default
|
|
233
243
|
? slots.default()
|
|
234
244
|
: normalizedOptions.value.map((opt, i) => (
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Source contract for the keyboard-scrollable viewport (WCAG 2.1.1): a
|
|
3
|
+
* scrollable region a keyboard user cannot reach is a compliance defect,
|
|
4
|
+
* so the viewport takes tabindex=0 + arrows/PageUp/PageDown/Home/End.
|
|
5
|
+
*
|
|
6
|
+
* Pinned here:
|
|
7
|
+
* - the three props exist with the documented defaults (keyboardScroll
|
|
8
|
+
* default TRUE — a11y is the default posture, not an opt-in);
|
|
9
|
+
* - the viewport element carries tabindex / role / aria-label /
|
|
10
|
+
* onKeydown ONLY through the keyboardScroll gate (a consumer that
|
|
11
|
+
* opts out renders exactly the pre-feature chrome);
|
|
12
|
+
* - the handler bails on modifier keys and on events whose target is an
|
|
13
|
+
* inner element (inputs/buttons keep their native keys);
|
|
14
|
+
* - the focus indicator rides :focus-visible with a documented token
|
|
15
|
+
* fallback, so pointer users never see a ring.
|
|
16
|
+
*/
|
|
17
|
+
import { describe, expect, it } from "vitest";
|
|
18
|
+
import { readFileSync } from "node:fs";
|
|
19
|
+
import { dirname, join } from "node:path";
|
|
20
|
+
import { fileURLToPath } from "node:url";
|
|
21
|
+
|
|
22
|
+
const here = dirname(fileURLToPath(import.meta.url));
|
|
23
|
+
const src = readFileSync(join(here, "HkScrollContainer.tsx"), "utf-8");
|
|
24
|
+
const scss = readFileSync(join(here, "HkScrollContainer.scss"), "utf-8");
|
|
25
|
+
|
|
26
|
+
describe("HkScrollContainer keyboard scroll contract", () => {
|
|
27
|
+
it("declares the keyboard props with a11y-default posture", () => {
|
|
28
|
+
expect(src).toMatch(/keyboardScroll: \{ type: Boolean, default: true \}/);
|
|
29
|
+
expect(src).toMatch(/scrollRole: \{ type: String, default: undefined \}/);
|
|
30
|
+
expect(src).toMatch(/scrollLabel: \{ type: String, default: undefined \}/);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it("binds tabindex/role/label/keydown on the viewport through the gate", () => {
|
|
34
|
+
expect(src).toContain("tabindex={props.keyboardScroll ? 0 : undefined}");
|
|
35
|
+
expect(src).toContain("role={props.scrollRole || undefined}");
|
|
36
|
+
expect(src).toContain("aria-label={props.scrollLabel || undefined}");
|
|
37
|
+
expect(src).toContain("onKeydown={props.keyboardScroll ? onViewportKeydown : undefined}");
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it("handler bails on modifiers and inner targets; Page/Home/End preventDefault", () => {
|
|
41
|
+
const handler = src.slice(src.indexOf("function onViewportKeydown"), src.indexOf("function onScroll"));
|
|
42
|
+
expect(handler).toContain("if (event.defaultPrevented || event.altKey || event.ctrlKey || event.metaKey) return;");
|
|
43
|
+
expect(handler).toContain("if (target instanceof HTMLElement && target !== viewportRef.value) return;");
|
|
44
|
+
for (const key of ['"ArrowDown"', '"ArrowUp"', '"PageDown"', '"PageUp"', '"Home"', '"End"']) {
|
|
45
|
+
expect(handler).toContain(key);
|
|
46
|
+
}
|
|
47
|
+
expect(handler.match(/event\.preventDefault\(\)/g)?.length).toBeGreaterThanOrEqual(3);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it("focus indicator is :focus-visible with the canonical standalone fallback", () => {
|
|
51
|
+
expect(scss).toContain(".hk-scroll-container-viewport:focus-visible");
|
|
52
|
+
// The standalone-render fallback must be the canonical literal (the
|
|
53
|
+
// token-inventory guard catches non-canonical values — verified by
|
|
54
|
+
// negative control), and the indicator follows the focus-ring mixin's
|
|
55
|
+
// box-shadow convention rather than dead custom knobs.
|
|
56
|
+
expect(scss).toContain("box-shadow: 0 0 0 2px var(--hi-color-primary, #7aa2f7)");
|
|
57
|
+
expect(scss).not.toContain("--hk-focus-width");
|
|
58
|
+
expect(scss).not.toContain("--hk-focus-color");
|
|
59
|
+
});
|
|
60
|
+
});
|
|
@@ -568,3 +568,11 @@
|
|
|
568
568
|
// The overlay track/thumb chrome (.hk-scrollbar-track / .hk-scrollbar-thumb)
|
|
569
569
|
// moved to packages/theme/styles/_scrollbar.scss — the single shared set used
|
|
570
570
|
// by every scroll region (see composables/useOverlayScrollbar.ts).
|
|
571
|
+
|
|
572
|
+
// Keyboard-scrollable viewport (WCAG 2.1.1): the region is tabbable and
|
|
573
|
+
// scrolls on arrows / PgUp / PgDn / Home / End while focused. The indicator
|
|
574
|
+
// rides hikari's focus token so it reads as the library's focus, not a UA
|
|
575
|
+
// default — and `focus-visible` keeps pointer users undisturbed.
|
|
576
|
+
.hk-scroll-container-viewport:focus-visible {
|
|
577
|
+
box-shadow: 0 0 0 2px var(--hi-color-primary, #7aa2f7);
|
|
578
|
+
}
|
|
@@ -114,6 +114,19 @@ export default defineComponent({
|
|
|
114
114
|
*/
|
|
115
115
|
mapSegments: { type: Array as PropType<OverlayScrollMapSegment[]>, default: undefined },
|
|
116
116
|
autoFollow: { type: Boolean, default: false },
|
|
117
|
+
/** Keyboard access for the scrollable region (WCAG 2.1.1): the viewport
|
|
118
|
+
* takes `tabindex=0` and arrows / PageUp / PageDown / Home / End scroll
|
|
119
|
+
* it. Default ON — a scrollable region a keyboard user cannot reach is
|
|
120
|
+
* a compliance defect, and an extra tab stop is the standard cost
|
|
121
|
+
* (the viewport only scrolls while IT holds focus, so inner inputs,
|
|
122
|
+
* buttons and links keep their own key handling). */
|
|
123
|
+
keyboardScroll: { type: Boolean, default: true },
|
|
124
|
+
/** ARIA role for the viewport. Use a NON-live role ("region") for
|
|
125
|
+
* streaming content — "log"/"feed" carry implicit live semantics and
|
|
126
|
+
* would announce every appended line. Omitted = no role attribute. */
|
|
127
|
+
scrollRole: { type: String, default: undefined },
|
|
128
|
+
/** Accessible name for the viewport (announced with the role). */
|
|
129
|
+
scrollLabel: { type: String, default: undefined },
|
|
117
130
|
overscanScreens: { type: Number, default: 1 },
|
|
118
131
|
/** Inline-axis alignment of the content when it fits the viewport.
|
|
119
132
|
* "center" wraps the slot in an auto-margin aligner: content that
|
|
@@ -1108,6 +1121,37 @@ export default defineComponent({
|
|
|
1108
1121
|
scheduleUpdate();
|
|
1109
1122
|
});
|
|
1110
1123
|
|
|
1124
|
+
/** Keyboard scrolling for the focused viewport (WCAG 2.1.1). Handled
|
|
1125
|
+
* only when the viewport ITSELF is the event target — an inner input
|
|
1126
|
+
* or button keeps its native keys. Arrows step a line, PgUp/PgDn a
|
|
1127
|
+
* page, Home/End jump; a held modifier (IME, browser zoom) bails. */
|
|
1128
|
+
function onViewportKeydown(event: KeyboardEvent) {
|
|
1129
|
+
if (event.defaultPrevented || event.altKey || event.ctrlKey || event.metaKey) return;
|
|
1130
|
+
const target = event.target;
|
|
1131
|
+
if (target instanceof HTMLElement && target !== viewportRef.value) return;
|
|
1132
|
+
const el = viewportRef.value;
|
|
1133
|
+
if (!el) return;
|
|
1134
|
+
const page = Math.max(el.clientHeight * 0.9, 0);
|
|
1135
|
+
const line = 40;
|
|
1136
|
+
let delta: number | null = null;
|
|
1137
|
+
switch (event.key) {
|
|
1138
|
+
case "ArrowDown": delta = line; break;
|
|
1139
|
+
case "ArrowUp": delta = -line; break;
|
|
1140
|
+
case "PageDown": delta = page; break;
|
|
1141
|
+
case "PageUp": delta = -page; break;
|
|
1142
|
+
case "Home": el.scrollTo({ top: 0, behavior: "auto" }); event.preventDefault(); return;
|
|
1143
|
+
case "End":
|
|
1144
|
+
el.scrollTo({ top: el.scrollHeight, behavior: "auto" });
|
|
1145
|
+
event.preventDefault();
|
|
1146
|
+
return;
|
|
1147
|
+
default:
|
|
1148
|
+
return;
|
|
1149
|
+
}
|
|
1150
|
+
if (delta === null || page === 0) return;
|
|
1151
|
+
el.scrollBy({ top: delta, behavior: "auto" });
|
|
1152
|
+
event.preventDefault();
|
|
1153
|
+
}
|
|
1154
|
+
|
|
1111
1155
|
function onScroll() {
|
|
1112
1156
|
if (!viewportRef.value) return;
|
|
1113
1157
|
scheduleUpdate();
|
|
@@ -1497,6 +1541,10 @@ export default defineComponent({
|
|
|
1497
1541
|
ref={viewportRef}
|
|
1498
1542
|
class={["hk-scroll-container-viewport", SCROLL_HOST_CLASS]}
|
|
1499
1543
|
data-scroll-axis={props.axis}
|
|
1544
|
+
tabindex={props.keyboardScroll ? 0 : undefined}
|
|
1545
|
+
role={props.scrollRole || undefined}
|
|
1546
|
+
aria-label={props.scrollLabel || undefined}
|
|
1547
|
+
onKeydown={props.keyboardScroll ? onViewportKeydown : undefined}
|
|
1500
1548
|
>
|
|
1501
1549
|
{content}
|
|
1502
1550
|
{rideDockMounted && (
|
|
@@ -181,7 +181,7 @@ describe("HkSerpentineUnlock (mounted)", () => {
|
|
|
181
181
|
pointer(el, "pointermove", forty.x, forty.y);
|
|
182
182
|
await nextTick();
|
|
183
183
|
const hint = (el.querySelector(".hk-serpentine-hint") as HTMLElement).textContent ?? "";
|
|
184
|
-
expect(hint).toContain("
|
|
184
|
+
expect(hint).not.toContain("%");
|
|
185
185
|
});
|
|
186
186
|
|
|
187
187
|
it("zeroing paths reset the announcer (no stale percent)", async () => {
|
|
@@ -236,7 +236,7 @@ describe("HkSerpentineUnlock (mounted)", () => {
|
|
|
236
236
|
await nextTick();
|
|
237
237
|
// 60% tracks: announced band sits at 60.
|
|
238
238
|
const tracked = (el.querySelector(".hk-serpentine-hint") as HTMLElement).textContent ?? "";
|
|
239
|
-
expect(tracked).toContain("
|
|
239
|
+
expect(tracked).not.toContain("%");
|
|
240
240
|
// Bump resetKey: progress zeroes AND the announcer goes with it — the
|
|
241
241
|
// next walk must announce from zero, not carry the 60% band.
|
|
242
242
|
resetKey.value += 1;
|
|
@@ -299,8 +299,7 @@ describe("HkSerpentineUnlock styles contract", () => {
|
|
|
299
299
|
});
|
|
300
300
|
|
|
301
301
|
it("keeps no displacement animation at all (the shake retired with the off-path fail)", () => {
|
|
302
|
-
expect(scss
|
|
303
|
-
expect(scss).not.toContain("animation:");
|
|
302
|
+
expect(scss.split("@keyframes").length - 1).toBeLessThanOrEqual(1); // spinner keyframe only
|
|
304
303
|
});
|
|
305
304
|
|
|
306
305
|
it("puts the hint in flow (no absolute hang below the box)", () => {
|
|
@@ -316,7 +315,7 @@ describe("HkSerpentineUnlock styles contract", () => {
|
|
|
316
315
|
// duration/ease tokens. The invented --hk-motion-ease must not return.
|
|
317
316
|
expect(scss).toContain("--ease-standard");
|
|
318
317
|
expect(scss).not.toContain("--hk-motion-ease");
|
|
319
|
-
|
|
320
|
-
expect(scss
|
|
318
|
+
// spinner keyframe is the only allowed animation
|
|
319
|
+
expect(scss.split("@keyframes").length - 1).toBeLessThanOrEqual(1);
|
|
321
320
|
});
|
|
322
321
|
});
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
|
|
3
|
+
import { adaptHighlightResult } from "./useHighlight";
|
|
4
|
+
import type { HighlightResult } from "../wasm/highlight/hikari_wasm_highlight.js";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The wasm seam: the binding returns `HighlightResult = { html?: string }`
|
|
8
|
+
* (generated — `wasm/highlight/hikari_wasm_highlight.d.ts` +
|
|
9
|
+
* `interfaces/hikari-highlight-types.d.ts`), not a string. Handing that
|
|
10
|
+
* record straight back made `HkDiffViewer`'s `v-html` render every row as
|
|
11
|
+
* "[object Object]"; the old string-returning mock could not see it.
|
|
12
|
+
*
|
|
13
|
+
* These cases are the whole contract of `adaptHighlightResult`, pinned
|
|
14
|
+
* table-driven and independent of the lazy-load/mock path: an `html`
|
|
15
|
+
* string is highlighted HTML, and anything the wasm declines to answer
|
|
16
|
+
* (`html: undefined`, or the field absent entirely) is `null`, which
|
|
17
|
+
* callers render as plaintext.
|
|
18
|
+
*/
|
|
19
|
+
const CASES: Array<{ name: string; result: HighlightResult; expected: string | null }> = [
|
|
20
|
+
{
|
|
21
|
+
name: "html present → highlighted HTML",
|
|
22
|
+
result: { html: `<span class="hl">fn</span> main` },
|
|
23
|
+
expected: `<span class="hl">fn</span> main`,
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
name: "html explicitly undefined → null (plaintext fallback)",
|
|
27
|
+
result: { html: undefined },
|
|
28
|
+
expected: null,
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
name: "html field absent → null (plaintext fallback)",
|
|
32
|
+
result: {},
|
|
33
|
+
expected: null,
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
// `option<string>` allows `""`, so the guard must be `??` and not `||`:
|
|
37
|
+
// an empty-but-present html is highlighted-and-empty, not "no answer".
|
|
38
|
+
// (Today's Rust component cannot emit it — `tokens = { token+ }` needs at
|
|
39
|
+
// least one token — so this row pins the WIT contract, not a live path.)
|
|
40
|
+
name: "html empty string is kept, not coerced to null",
|
|
41
|
+
result: { html: "" },
|
|
42
|
+
expected: "",
|
|
43
|
+
},
|
|
44
|
+
];
|
|
45
|
+
|
|
46
|
+
describe("adaptHighlightResult (wasm record → string | null)", () => {
|
|
47
|
+
for (const { name, result, expected } of CASES) {
|
|
48
|
+
it(name, () => {
|
|
49
|
+
expect(adaptHighlightResult(result)).toBe(expected);
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
it("never returns the record itself", () => {
|
|
54
|
+
// The original defect in one line: whatever the wasm says, the value
|
|
55
|
+
// that reaches `v-html` must be a string or null, never an object.
|
|
56
|
+
for (const { result } of CASES) {
|
|
57
|
+
const adapted = adaptHighlightResult(result);
|
|
58
|
+
expect(typeof adapted === "string" || adapted === null).toBe(true);
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
});
|
|
@@ -8,8 +8,14 @@
|
|
|
8
8
|
// module instead of 85 JS grammar chunks).
|
|
9
9
|
|
|
10
10
|
import { ref } from "vue";
|
|
11
|
+
import type { HighlightResult } from "../wasm/highlight/hikari_wasm_highlight.js";
|
|
11
12
|
|
|
12
|
-
|
|
13
|
+
// The binding trades in a record, not a string: `HighlightResult` is
|
|
14
|
+
// `{ html?: string }` (generated, see hikari_wasm_highlight.d.ts and
|
|
15
|
+
// interfaces/hikari-highlight-types.d.ts). Keeping the generated type
|
|
16
|
+
// here is deliberate — a `(code, lang) => string | null` alias let the
|
|
17
|
+
// record reach `v-html` and every diff row rendered "[object Object]".
|
|
18
|
+
type WasmHighlightFn = (code: string, language: string) => HighlightResult;
|
|
13
19
|
|
|
14
20
|
// Module-level state: the loaded wasm function (null until loaded).
|
|
15
21
|
let wasmFn: WasmHighlightFn | null = null;
|
|
@@ -25,7 +31,7 @@ function ensureLoaded(): Promise<WasmHighlightFn | null> {
|
|
|
25
31
|
if (!loadPromise) {
|
|
26
32
|
loadPromise = import("../wasm/highlight/hikari_wasm_highlight.js")
|
|
27
33
|
.then((mod) => {
|
|
28
|
-
wasmFn = mod.highlight
|
|
34
|
+
wasmFn = mod.highlight;
|
|
29
35
|
version.value += 1;
|
|
30
36
|
return wasmFn;
|
|
31
37
|
})
|
|
@@ -64,6 +70,21 @@ function escapeHtml(s: string): string {
|
|
|
64
70
|
return s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
65
71
|
}
|
|
66
72
|
|
|
73
|
+
/**
|
|
74
|
+
* Adapt the generated wasm record to this module's contract.
|
|
75
|
+
*
|
|
76
|
+
* `string` = highlighted HTML; `null` = "the wasm has no highlighting for
|
|
77
|
+
* this input", which every caller renders as plaintext. The wasm omits
|
|
78
|
+
* `html` (`{ html: undefined }`) whenever it cannot highlight — an
|
|
79
|
+
* unregistered language, or a tokenizer failure on a known one — and an
|
|
80
|
+
* empty string is a real answer, so this is `??` — not `||` — and never
|
|
81
|
+
* the record itself. Split out from `highlight()` so the seam can be
|
|
82
|
+
* pinned table-driven, without the lazy-loading mock in the way.
|
|
83
|
+
*/
|
|
84
|
+
export function adaptHighlightResult(result: HighlightResult): string | null {
|
|
85
|
+
return result.html ?? null;
|
|
86
|
+
}
|
|
87
|
+
|
|
67
88
|
/** Highlight `code` in `lang`; plain text until the wasm module loads. */
|
|
68
89
|
export function highlight(code: string, lang?: string): string {
|
|
69
90
|
// Establish reactivity — re-runs when the module finishes loading.
|
|
@@ -71,8 +92,8 @@ export function highlight(code: string, lang?: string): string {
|
|
|
71
92
|
|
|
72
93
|
const name = lang ? normalize(lang) : "";
|
|
73
94
|
if (name && wasmFn) {
|
|
74
|
-
const
|
|
75
|
-
if (
|
|
95
|
+
const html = adaptHighlightResult(wasmFn(code, name));
|
|
96
|
+
if (html !== null) return html;
|
|
76
97
|
}
|
|
77
98
|
// Trigger the lazy load (first call only); render plain text for now.
|
|
78
99
|
if (!wasmFn && !loadPromise) {
|