@celestia-island/hikari 0.55.383 → 0.55.388

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,111 +1,111 @@
1
1
  {
2
- "name": "@celestia-island/hikari",
3
- "version": "0.55.383",
4
- "private": false,
5
- "type": "module",
6
- "description": "Hikari UI library, Vue 3 runtime — one design system for Vue 3 and Rust/WASM applications",
7
- "license": "SySL-1.0",
8
- "repository": {
9
- "type": "git",
10
- "url": "https://github.com/celestia-island/hikari"
2
+ "name": "@celestia-island/hikari",
3
+ "version": "0.55.388",
4
+ "private": false,
5
+ "type": "module",
6
+ "description": "Hikari UI library, Vue 3 runtime — one design system for Vue 3 and Rust/WASM applications",
7
+ "license": "SySL-1.0",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "https://github.com/celestia-island/hikari"
11
+ },
12
+ "homepage": "https://github.com/celestia-island/hikari",
13
+ "keywords": [
14
+ "vue3",
15
+ "ui-components",
16
+ "design-system",
17
+ "hikari",
18
+ "celestia-island"
19
+ ],
20
+ "main": "./src/index.ts",
21
+ "types": "./src/index.ts",
22
+ "exports": {
23
+ ".": {
24
+ "import": "./src/index.ts",
25
+ "types": "./src/index.ts"
11
26
  },
12
- "homepage": "https://github.com/celestia-island/hikari",
13
- "keywords": [
14
- "vue3",
15
- "ui-components",
16
- "design-system",
17
- "hikari",
18
- "celestia-island"
19
- ],
20
- "main": "./src/index.ts",
21
- "types": "./src/index.ts",
22
- "exports": {
23
- ".": {
24
- "import": "./src/index.ts",
25
- "types": "./src/index.ts"
26
- },
27
- "./mermaid": {
28
- "import": "./src/mermaid/index.ts",
29
- "types": "./src/mermaid/index.ts"
30
- },
31
- "./runtime": {
32
- "import": "./src/runtime/index.ts",
33
- "types": "./src/runtime/index.ts"
34
- },
35
- "./styles": {
36
- "import": "./src/styles/index.scss"
37
- },
38
- "./styles/*": "./src/styles/*",
39
- "./theme/*": "./src/theme/*",
40
- "./components/*": "./src/components/*",
41
- "./plugins": {
42
- "import": "./src/plugins/index.ts",
43
- "types": "./src/plugins/index.ts"
44
- },
45
- "./plugins/boot-chrome": {
46
- "import": "./src/plugins/boot-chrome.js",
47
- "types": "./src/plugins/boot-chrome.d.ts"
48
- },
49
- "./plugins/boot-recovery": {
50
- "import": "./src/plugins/boot-recovery.js",
51
- "types": "./src/plugins/boot-recovery.d.ts"
52
- },
53
- "./shared": {
54
- "import": "./src/shared.ts",
55
- "types": "./src/shared.ts"
56
- }
27
+ "./mermaid": {
28
+ "import": "./src/mermaid/index.ts",
29
+ "types": "./src/mermaid/index.ts"
57
30
  },
58
- "files": [
59
- "src/",
60
- "package.json"
61
- ],
62
- "scripts": {
63
- "dev": "vite",
64
- "build": "vue-tsc --noEmit",
65
- "build:docs": "vite build",
66
- "lint": "vue-tsc --noEmit",
67
- "test": "vitest run",
68
- "test:watch": "vitest",
69
- "gen:boot-landing-css": "node scripts/gen-boot-landing-css.js",
70
- "prepublishOnly": "vue-tsc --noEmit"
31
+ "./runtime": {
32
+ "import": "./src/runtime/index.ts",
33
+ "types": "./src/runtime/index.ts"
71
34
  },
72
- "peerDependencies": {
73
- "@types/three": "^0.185",
74
- "pinia": "^3",
75
- "three": "^0.185",
76
- "vue": "^3"
35
+ "./styles": {
36
+ "import": "./src/styles/index.scss"
77
37
  },
78
- "dependencies": {
79
- "@bytecodealliance/preview2-shim": "^0.31",
80
- "@celestia-island/tairitsu-transport": "^0.2",
81
- "@xterm/addon-fit": "^0.11",
82
- "@xterm/addon-image": "^0.10.0-beta.301",
83
- "@xterm/xterm": "^6.1.0-beta.304",
84
- "dompurify": "^3",
85
- "lucide-vue-next": "^1",
86
- "marked": "^18"
38
+ "./styles/*": "./src/styles/*",
39
+ "./theme/*": "./src/theme/*",
40
+ "./components/*": "./src/components/*",
41
+ "./plugins": {
42
+ "import": "./src/plugins/index.ts",
43
+ "types": "./src/plugins/index.ts"
87
44
  },
88
- "devDependencies": {
89
- "@types/node": "^*",
90
- "@types/three": "^0.185",
91
- "@vitejs/plugin-vue": "^*",
92
- "@vitejs/plugin-vue-jsx": "^*",
93
- "@vue/server-renderer": "^*",
94
- "happy-dom": "^*",
95
- "sass": "^*",
96
- "three": "^0.185",
97
- "typescript": "^*",
98
- "vite": "^*",
99
- "vitest": "^*",
100
- "vue-tsc": "^*"
45
+ "./plugins/boot-chrome": {
46
+ "import": "./src/plugins/boot-chrome.js",
47
+ "types": "./src/plugins/boot-chrome.d.ts"
101
48
  },
102
- "sideEffects": [
103
- "**/*.scss",
104
- "**/*.css"
105
- ],
106
- "peerDependenciesMeta": {
107
- "pinia": {
108
- "optional": true
109
- }
49
+ "./plugins/boot-recovery": {
50
+ "import": "./src/plugins/boot-recovery.js",
51
+ "types": "./src/plugins/boot-recovery.d.ts"
52
+ },
53
+ "./shared": {
54
+ "import": "./src/shared.ts",
55
+ "types": "./src/shared.ts"
56
+ }
57
+ },
58
+ "files": [
59
+ "src/",
60
+ "package.json"
61
+ ],
62
+ "scripts": {
63
+ "dev": "vite",
64
+ "build": "vue-tsc --noEmit",
65
+ "build:docs": "vite build",
66
+ "lint": "vue-tsc --noEmit",
67
+ "test": "vitest run",
68
+ "test:watch": "vitest",
69
+ "gen:boot-landing-css": "node scripts/gen-boot-landing-css.js",
70
+ "prepublishOnly": "vue-tsc --noEmit"
71
+ },
72
+ "peerDependencies": {
73
+ "@types/three": "^0.185",
74
+ "pinia": "^3",
75
+ "three": "^0.185",
76
+ "vue": "^3"
77
+ },
78
+ "dependencies": {
79
+ "@bytecodealliance/preview2-shim": "^0.31",
80
+ "@celestia-island/tairitsu-transport": "^0.2",
81
+ "@xterm/addon-fit": "^0.11",
82
+ "@xterm/addon-image": "^0.10.0-beta.301",
83
+ "@xterm/xterm": "^6.1.0-beta.304",
84
+ "dompurify": "^3",
85
+ "lucide-vue-next": "^1",
86
+ "marked": "^18"
87
+ },
88
+ "devDependencies": {
89
+ "@types/node": "^*",
90
+ "@types/three": "^0.185",
91
+ "@vitejs/plugin-vue": "^*",
92
+ "@vitejs/plugin-vue-jsx": "^*",
93
+ "@vue/server-renderer": "^*",
94
+ "happy-dom": "^*",
95
+ "sass": "^*",
96
+ "three": "^0.185",
97
+ "typescript": "^*",
98
+ "vite": "^*",
99
+ "vitest": "^*",
100
+ "vue-tsc": "^*"
101
+ },
102
+ "sideEffects": [
103
+ "**/*.scss",
104
+ "**/*.css"
105
+ ],
106
+ "peerDependenciesMeta": {
107
+ "pinia": {
108
+ "optional": true
110
109
  }
110
+ }
111
111
  }
@@ -136,6 +136,19 @@ describe("HkAboutModal branding", () => {
136
136
  expect(chips[0]!.getAttribute("href")).toBe("https://github.com/celestia-island");
137
137
  });
138
138
 
139
+ it("neutralizes a script scheme in the anchor itself (audit PS-18)", async () => {
140
+ mountAbout({
141
+ credits: [{ text: "来自 " }, { name: "恶意", href: "javascript:alert(1)" }],
142
+ });
143
+ await flushModal();
144
+ const anchor = document.body.querySelector<HTMLAnchorElement>(".s-about-modal-credit-link");
145
+ expect(anchor).not.toBeNull();
146
+ // The coordinator refuses script schemes on activation, but the ATTRIBUTE
147
+ // still has to be inert: a middle-click or "open link in new tab" bypasses
148
+ // the click handler entirely.
149
+ expect(anchor!.getAttribute("href")).toBe("#");
150
+ });
151
+
139
152
  it("renders a credit name as a plain text link when the entry asks for it", async () => {
140
153
  mountAbout({
141
154
  credits: [
@@ -4,6 +4,7 @@ import { HBadge, HModal } from "@celestia-island/hikari";
4
4
 
5
5
  import { useI18n } from "../i18n/context";
6
6
  import { openHyperlink } from "../runtime/hyperlink";
7
+ import { safeHref } from "../utils/safeHref";
7
8
 
8
9
  import "./HkAboutModal.scss";
9
10
 
@@ -175,7 +176,7 @@ export const HkAboutBody = defineComponent({
175
176
  key={key}
176
177
  class={classes}
177
178
  data-face={item.face ?? "chip"}
178
- href={item.href}
179
+ href={safeHref(item.href)}
179
180
  target="_blank"
180
181
  rel="noopener noreferrer"
181
182
  // The activation rides the hyperlink coordinator (runtime/
@@ -0,0 +1,17 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import * as barrel from "../index";
3
+ import { asIndexable } from "../utils/typing";
4
+
5
+ /**
6
+ * The public barrel guard (HkAddTile.barrel.test.ts shape): the
7
+ * component's own tests reach it through "./HkAdaptiveTabs" — only an
8
+ * external consumer would notice a dropped export line.
9
+ */
10
+ describe("the public barrel", () => {
11
+ it("exports the adaptive tabs under both family names", () => {
12
+ const hk = asIndexable(barrel.HkAdaptiveTabs);
13
+ expect(hk, "HkAdaptiveTabs must be re-exported").toBeTruthy();
14
+ expect(hk.name).toBe("HkAdaptiveTabs");
15
+ expect(barrel.HAdaptiveTabs).toBe(barrel.HkAdaptiveTabs);
16
+ });
17
+ });
@@ -0,0 +1,62 @@
1
+ import { describe, expect, it } from "vitest";
2
+
3
+ import componentSource from "./HkAdaptiveTabs.tsx?raw";
4
+
5
+ /**
6
+ * Composition contract for the adaptive tabs (the
7
+ * HkNotificationBell.contract.test.ts shape): the component owns ONLY
8
+ * the breakpoint branch and the option rows — every surface is a
9
+ * shared family member, so a second popup grammar cannot grow here.
10
+ */
11
+ function body(): string {
12
+ return componentSource.replace(/\/\*[\s\S]*?\*\//g, "").replace(/\/\/.*$/gm, "");
13
+ }
14
+
15
+ describe("HkAdaptiveTabs composition contract", () => {
16
+ it("the desktop arm IS HkTabs; the mobile arm IS HkButton + HkSelectPanel", () => {
17
+ const src = body();
18
+ expect(src).toContain("HkTabs");
19
+ expect(src).toContain("HkButton");
20
+ expect(src).toContain("HkSelectPanel");
21
+ // The sheet pin is exact (a sheetOnMobile={false} mutant must fail
22
+ // here AND the behavioral .hk-select-sheet-panel assertion).
23
+ expect(src).toContain("sheetOnMobile={true}"); // — sheet on phones
24
+ // No hand-rolled overlay machinery in this component.
25
+ expect(src).not.toContain("Teleport");
26
+ expect(src).not.toContain("ensureOverlayRoot");
27
+ expect(src).not.toContain("scrim");
28
+ });
29
+
30
+ it("the branch threshold is the family's isMobile — no private width math", () => {
31
+ const src = body();
32
+ expect(src).toContain("useBreakpoint");
33
+ expect(src).toContain("isMobile");
34
+ expect(src).not.toContain("innerWidth");
35
+ expect(src).not.toContain("matchMedia");
36
+ expect(src).not.toContain("768");
37
+ });
38
+
39
+ it("mobile rows reuse the shared option-row grammar — no second family", () => {
40
+ const src = body();
41
+ expect(src).toContain("hk-select-option");
42
+ expect(src).toContain("hk-menu-item-icon");
43
+ expect(src).toContain("hk-menu-label");
44
+ });
45
+
46
+ it("the value contract never changes shape across the branch", () => {
47
+ const src = body();
48
+ // Both arms emit the same update; no mobile-only state shadow.
49
+ expect(src).toContain("update:modelValue");
50
+ expect(src).not.toContain("innerModel");
51
+ });
52
+
53
+ it("badges anchor labels — never a floating mark", () => {
54
+ const src = body();
55
+ // The HkCornerBadge wraps the label span (HkTabs contract), so the
56
+ // badge JSX must contain the hk-menu-label class in its subtree.
57
+ const badgeIdx = src.indexOf("<HkCornerBadge");
58
+ expect(badgeIdx).toBeGreaterThan(-1);
59
+ const badgeBlock = src.slice(badgeIdx, badgeIdx + 500);
60
+ expect(badgeBlock).toContain("hk-menu-label");
61
+ });
62
+ });
@@ -0,0 +1,52 @@
1
+ /**
2
+ * HkAdaptiveTabs chrome: the mobile trigger row and the option rows
3
+ * inside the HkSelectPanel surface. The rows reuse the shared
4
+ * `hk-select-option` / `hk-menu-*` grammar (HkSelect's own option
5
+ * voice, including its checked/disabled faces from the shared
6
+ * menu-item mixin) — this sheet only adds the trigger's caret
7
+ * geometry and open-state flip, never a second option-row family.
8
+ */
9
+
10
+ .hk-adaptive-tabs {
11
+ position: relative;
12
+ display: inline-flex;
13
+ align-items: center;
14
+ }
15
+
16
+ .hk-adaptive-tabs-trigger-icon {
17
+ display: inline-flex;
18
+ align-items: center;
19
+ }
20
+
21
+ .hk-adaptive-tabs-trigger-label {
22
+ max-width: 9rem;
23
+ overflow: hidden;
24
+ text-overflow: ellipsis;
25
+ white-space: nowrap;
26
+ }
27
+
28
+ .hk-adaptive-tabs-caret {
29
+ margin-left: var(--space-4, 0.25rem);
30
+ color: rgb(var(--color-text) / 55%);
31
+ }
32
+
33
+ .hk-adaptive-tabs-options {
34
+ display: flex;
35
+ flex-direction: column;
36
+ min-width: 12rem;
37
+ }
38
+
39
+ .hk-adaptive-tabs-option {
40
+ text-align: left;
41
+
42
+ /* Checked AND disabled faces come from the shared menu-item mixin the
43
+ `hk-select-option` grammar already composes — nothing re-styled
44
+ here (one emphasis, one implementation). */
45
+ }
46
+
47
+ /* Open-state feedback for the trigger (the data-active hook the
48
+ component sets while the picker is up): the caret flips — the same
49
+ voice as a select field. */
50
+ .hk-adaptive-tabs .hk-btn[data-active] .hk-adaptive-tabs-caret {
51
+ transform: rotate(180deg);
52
+ }
@@ -0,0 +1,281 @@
1
+ import { afterEach, describe, expect, it, vi } from "vitest";
2
+ import { createApp, h, nextTick } from "vue";
3
+ import { FileText, History, Network } from "lucide-vue-next";
4
+
5
+ import HkAdaptiveTabs from "./HkAdaptiveTabs";
6
+ import { setLocale } from "../i18n/context";
7
+ import type { TabItem } from "./HkTabs";
8
+
9
+ /**
10
+ * HkAdaptiveTabs behavior tests (user direction 2026-11-15):
11
+ * - desktop arm renders the HkTabs strip and forwards picks
12
+ * - mobile arm (<768 via window.innerWidth + resize) collapses into a
13
+ * trigger showing the ACTIVE item; opening it surfaces the option
14
+ * rows in an HkSelectPanel surface; picking emits and closes
15
+ * - the `icon-${key}` slot vocabulary renders in BOTH arms
16
+ * - TabItem.badge anchors the row LABEL (not a floating mark)
17
+ * (Repo test convention: raw createApp + document queries.)
18
+ */
19
+
20
+ const TABS: TabItem[] = [
21
+ { key: "reports", label: "报告审阅" },
22
+ { key: "nodes", label: "节点概览" },
23
+ { key: "history", label: "历史记录" },
24
+ ];
25
+
26
+ const mounts: Array<{ app: ReturnType<typeof createApp>; container: HTMLElement }> = [];
27
+
28
+ interface Harness {
29
+ values: string[];
30
+ container: HTMLElement;
31
+ }
32
+
33
+ function mountTabs(opts: {
34
+ tabs?: TabItem[];
35
+ slots?: Record<string, () => unknown>;
36
+ modelValue?: string;
37
+ } = {}): Harness {
38
+ const values: string[] = [];
39
+ const container = document.createElement("div");
40
+ document.body.appendChild(container);
41
+ let current = opts.modelValue ?? "reports";
42
+ const app = createApp({
43
+ render: () =>
44
+ h(HkAdaptiveTabs, {
45
+ modelValue: current,
46
+ tabs: opts.tabs ?? TABS,
47
+ ariaLabel: "面板",
48
+ "onUpdate:modelValue": (v: string) => {
49
+ current = v;
50
+ values.push(v);
51
+ },
52
+ }, opts.slots as never),
53
+ });
54
+ mounts.push({ app, container });
55
+ app.mount(container);
56
+ return { values, container };
57
+ }
58
+
59
+ async function settle() {
60
+ await nextTick();
61
+ await new Promise((r) => setTimeout(r, 30));
62
+ await nextTick();
63
+ }
64
+
65
+ function setMobile(mobile: boolean) {
66
+ (window as unknown as { innerWidth: number }).innerWidth = mobile ? 500 : 1280;
67
+ window.dispatchEvent(new Event("resize"));
68
+ }
69
+
70
+ function strip(): HTMLElement | null {
71
+ return document.querySelector<HTMLElement>(".hk-tabs");
72
+ }
73
+
74
+ function trigger(): HTMLButtonElement {
75
+ return document.querySelector<HTMLButtonElement>(".hk-adaptive-tabs .hk-btn")!;
76
+ }
77
+
78
+ function optionRows(): HTMLElement[] {
79
+ return Array.from(document.querySelectorAll<HTMLElement>(".hk-adaptive-tabs-option"));
80
+ }
81
+
82
+ afterEach(() => {
83
+ for (const { app, container } of mounts) {
84
+ app.unmount();
85
+ container.remove();
86
+ }
87
+ mounts.length = 0;
88
+ document.body
89
+ .querySelectorAll(".hk-select-sheet-scrim, .hk-select-panel, .hk-popover-panel")
90
+ .forEach((el) => el.remove());
91
+ setMobile(false);
92
+ });
93
+
94
+ describe("desktop arm", () => {
95
+ it("renders the HkTabs strip and forwards picks", async () => {
96
+ const { values } = mountTabs();
97
+ await settle();
98
+ expect(strip()).toBeTruthy();
99
+ const history = Array.from(document.querySelectorAll<HTMLButtonElement>(".hk-tabs button"))
100
+ .find((b) => b.textContent?.includes("历史记录"));
101
+ history!.dispatchEvent(new MouseEvent("click", { bubbles: true }));
102
+ await settle();
103
+ expect(values).toEqual(["history"]);
104
+ });
105
+
106
+ it("renders named icon slots in the strip", async () => {
107
+ mountTabs({ slots: { "icon-reports": () => h(FileText, { size: 14 }) } });
108
+ await settle();
109
+ expect(strip()?.querySelector("svg")).toBeTruthy();
110
+ });
111
+ });
112
+
113
+ describe("mobile arm", () => {
114
+ it("collapses into a trigger showing the ACTIVE item's label", async () => {
115
+ setMobile(true);
116
+ mountTabs({ modelValue: "nodes" });
117
+ await settle();
118
+ expect(strip()).toBeFalsy();
119
+ expect(trigger().textContent).toContain("节点概览");
120
+ });
121
+
122
+ it("opening the trigger surfaces the option rows; picking emits and closes", async () => {
123
+ setMobile(true);
124
+ const { values } = mountTabs();
125
+ await settle();
126
+ trigger().dispatchEvent(new MouseEvent("click", { bubbles: true }));
127
+ await settle();
128
+ // The sheet pin (R2 S3): phones must get the BOTTOM SHEET surface,
129
+ // not a desktop-style popout — a sheetOnMobile={false} mutant fails
130
+ // this line.
131
+ expect(document.querySelector(".hk-select-sheet-panel")).toBeTruthy();
132
+ const rows = optionRows();
133
+ expect(rows).toHaveLength(3);
134
+ const checked = rows.find((r) => r.hasAttribute("data-checked"));
135
+ expect(checked?.textContent).toContain("报告审阅");
136
+
137
+ rows.find((r) => r.textContent?.includes("历史记录"))!
138
+ .dispatchEvent(new MouseEvent("click", { bubbles: true }));
139
+ await settle();
140
+ expect(values).toEqual(["history"]);
141
+ // Picking closes the popup (the surface leaves the document).
142
+ expect(document.querySelector(".hk-adaptive-tabs-option")).toBeFalsy();
143
+ });
144
+
145
+ it("crossing the breakpoint while open resets the picker — no self-reopen", async () => {
146
+ // R2 S2 (PR #1323): the branch swap unmounts the panel before its
147
+ // own isMobile close watcher can run; without a reset here the next
148
+ // mobile mount would come up open=true and the sheet would reopen
149
+ // itself unbidden.
150
+ setMobile(true);
151
+ mountTabs();
152
+ await settle();
153
+ trigger().dispatchEvent(new MouseEvent("click", { bubbles: true }));
154
+ await settle();
155
+ expect(document.querySelector(".hk-select-sheet-panel")).toBeTruthy();
156
+
157
+ setMobile(false);
158
+ await settle();
159
+ expect(document.querySelector(".hk-select-sheet-panel")).toBeFalsy();
160
+
161
+ setMobile(true);
162
+ await settle();
163
+ // Back on the phone arm: the sheet must stay SHUT until the user
164
+ // taps the trigger again.
165
+ expect(document.querySelector(".hk-select-sheet-panel")).toBeFalsy();
166
+ expect(optionRows()).toHaveLength(0);
167
+ });
168
+
169
+ it("a disabled row swallows the click — no emit, sheet stays open", async () => {
170
+ setMobile(true);
171
+ const { values } = mountTabs({
172
+ tabs: [
173
+ { key: "a", label: "甲" },
174
+ { key: "b", label: "乙", disabled: true },
175
+ ],
176
+ });
177
+ await settle();
178
+ trigger().dispatchEvent(new MouseEvent("click", { bubbles: true }));
179
+ await settle();
180
+ const disabledRow = optionRows().find((r) => r.textContent?.includes("乙"))!;
181
+ // A REAL disabled attribute: the click never reaches the handler
182
+ // (the row is not actionable at all) — no emit, no close.
183
+ expect(disabledRow.hasAttribute("disabled")).toBe(true);
184
+ disabledRow.dispatchEvent(new MouseEvent("click", { bubbles: true }));
185
+ await settle();
186
+ expect(values).toEqual([]);
187
+ expect(document.querySelector(".hk-adaptive-tabs-option")).toBeTruthy();
188
+ });
189
+
190
+ it("renders named icon slots in the sheet rows", async () => {
191
+ setMobile(true);
192
+ mountTabs({
193
+ slots: {
194
+ "icon-reports": () => h(FileText, { size: 14 }),
195
+ "icon-nodes": () => h(Network, { size: 14 }),
196
+ "icon-history": () => h(History, { size: 14 }),
197
+ },
198
+ });
199
+ await settle();
200
+ trigger().dispatchEvent(new MouseEvent("click", { bubbles: true }));
201
+ await settle();
202
+ expect(optionRows().filter((r) => r.querySelector("svg"))).toHaveLength(3);
203
+ });
204
+
205
+ it("a TabItem.badge anchors the row LABEL, not a floating mark", async () => {
206
+ setMobile(true);
207
+ mountTabs({
208
+ tabs: [
209
+ { key: "a", label: "甲", badge: { count: 3, max: 9, label: "3 条" } },
210
+ { key: "b", label: "乙" },
211
+ ],
212
+ });
213
+ await settle();
214
+ trigger().dispatchEvent(new MouseEvent("click", { bubbles: true }));
215
+ await settle();
216
+ const rowWithBadge = optionRows().find((r) => r.textContent?.includes("甲"))!;
217
+ // The badge ANCHOR wrapper holds label + mark together (placement
218
+ // "right" = beside the label, never covering it).
219
+ const anchor = rowWithBadge.querySelector<HTMLElement>(".hk-corner-badge-anchor")!;
220
+ expect(anchor.textContent).toContain("甲");
221
+ expect(anchor.querySelector(".hk-corner-badge")?.textContent).toContain("3");
222
+ expect(anchor.querySelector(".hk-corner-badge")?.textContent).not.toContain("甲");
223
+ });
224
+
225
+ it("a count-0 badge STAYS VISIBLE on the row (presence information)", async () => {
226
+ // The HkTabs contract (R2 S2, PR #1323): zero is presence, not
227
+ // noise — showZero passes through to the mobile rows too.
228
+ await setLocale("en");
229
+ setMobile(true);
230
+ mountTabs({
231
+ tabs: [{ key: "a", label: "甲", badge: { count: 0, label: "0 条" } }],
232
+ });
233
+ await settle();
234
+ trigger().dispatchEvent(new MouseEvent("click", { bubbles: true }));
235
+ await settle();
236
+ const anchor = optionRows()[0].querySelector<HTMLElement>(".hk-corner-badge-anchor")!;
237
+ expect(anchor.querySelector(".hk-corner-badge")?.textContent).toContain("0");
238
+ });
239
+
240
+ it("an empty-label badge renders no mark (a badge anchors a LABEL)", async () => {
241
+ // R3 mutation-d pin (PR #1323): dropping the `&& tab.label` guard
242
+ // must fail here — a badge without a label is a floating mark.
243
+ await setLocale("en");
244
+ setMobile(true);
245
+ mountTabs({
246
+ tabs: [{ key: "a", label: "", badge: { count: 2, label: "2 条" } }],
247
+ });
248
+ await settle();
249
+ trigger().dispatchEvent(new MouseEvent("click", { bubbles: true }));
250
+ await settle();
251
+ expect(optionRows()[0].querySelector(".hk-corner-badge")).toBeFalsy();
252
+ });
253
+
254
+ it("the trigger declares the popup it actually opens", async () => {
255
+ // R3 mutation-e pin (PR #1323): the sheet surface is a dialog —
256
+ // the trigger must not claim a listbox that never renders.
257
+ await setLocale("en");
258
+ setMobile(true);
259
+ mountTabs();
260
+ await settle();
261
+ expect(trigger().getAttribute("aria-haspopup")).toBe("dialog");
262
+ });
263
+
264
+ it("warns in DEV when a badge lacks an accessible label", async () => {
265
+ // R4 pin (PR #1323): the mobile rows mirror HkTabs' second a11y
266
+ // alarm — a label-less badge is announced nowhere on the sheet.
267
+ const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
268
+ try {
269
+ setMobile(true);
270
+ mountTabs({
271
+ tabs: [{ key: "a", label: "甲", badge: { count: 3 } }],
272
+ });
273
+ await settle();
274
+ const alarms = warn.mock.calls.filter((c) => String(c[0]).includes("badge without a label"));
275
+ expect(alarms.length, "the a11y drift alarm must fire").toBeGreaterThan(0);
276
+ expect(alarms[0]![1]).toBe("a");
277
+ } finally {
278
+ warn.mockRestore();
279
+ }
280
+ });
281
+ });