@celestia-island/hikari 0.41.1 → 0.41.3
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 +1 -1
- package/src/components/HkButton.scss +56 -0
- package/src/components/HkButton.test.tsx +81 -0
- package/src/components/HkButton.tsx +42 -28
- package/src/components/HkIconButton.test.tsx +15 -0
- package/src/components/HkIconButton.tsx +18 -5
- package/src/errorReporting/index.test.tsx +42 -0
- package/src/errorReporting/index.ts +15 -0
package/package.json
CHANGED
|
@@ -64,6 +64,62 @@
|
|
|
64
64
|
min-height: 2.75rem;
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
+
/* ---- Prefix / suffix icon boxes ---- */
|
|
68
|
+
/* Standard-part contract (2026-09-10 user direction): a button glyph
|
|
69
|
+
renders inside a FIXED SQUARE box — flex:none so host flex rows can
|
|
70
|
+
never squeeze it into a squat sliver, centered on both axes so the
|
|
71
|
+
icon rides the button's vertical midline at any button height, and
|
|
72
|
+
the box (not the bare svg) owns the rhythm so the glyph keeps a
|
|
73
|
+
consistent margin from the adjacent label via the button's own gap.
|
|
74
|
+
The 1rem box matches the 16px glyph HkButton renders for the
|
|
75
|
+
icon/suffix props. */
|
|
76
|
+
.hk-btn-icon,
|
|
77
|
+
.hk-btn-suffix {
|
|
78
|
+
display: inline-flex;
|
|
79
|
+
align-items: center;
|
|
80
|
+
justify-content: center;
|
|
81
|
+
flex: none;
|
|
82
|
+
inline-size: 1rem;
|
|
83
|
+
block-size: 1rem;
|
|
84
|
+
line-height: 0;
|
|
85
|
+
|
|
86
|
+
svg {
|
|
87
|
+
display: block;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/* ---- Icon-only square ---- */
|
|
92
|
+
/* An icon-only HkButton (glyph, no label) occupies a SQUARE footprint
|
|
93
|
+
by default: padding collapses fully and width locks to the size
|
|
94
|
+
variant's min-height, so it reads as the same standard square the
|
|
95
|
+
HIconButton family guarantees. box-sizing is self-declared (house
|
|
96
|
+
convention — geometry rules never rely on a host-side reset reaching
|
|
97
|
+
the component): with zero padding the min-height governs the height
|
|
98
|
+
on every size, an exact square under border-box AND content-box.
|
|
99
|
+
Hosts may still override with an explicit width when a design
|
|
100
|
+
genuinely calls for another shape. */
|
|
101
|
+
.hk-btn-icon-only {
|
|
102
|
+
padding: 0;
|
|
103
|
+
box-sizing: border-box;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
.hk-btn-sm.hk-btn-icon-only {
|
|
107
|
+
width: 1.75rem;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
.hk-btn-md.hk-btn-icon-only {
|
|
111
|
+
width: 2.5rem;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
.hk-btn-lg.hk-btn-icon-only {
|
|
115
|
+
width: 2.75rem;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/* The first-class block prop wins over the square width. */
|
|
119
|
+
.hk-btn-block.hk-btn-icon-only {
|
|
120
|
+
width: 100%;
|
|
121
|
+
}
|
|
122
|
+
|
|
67
123
|
/* ---- Primary ---- */
|
|
68
124
|
|
|
69
125
|
.hk-btn-primary {
|
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
import { afterEach, describe, expect, it } from "vitest";
|
|
2
2
|
import { createApp, h } from "vue";
|
|
3
|
+
import { readFileSync } from "node:fs";
|
|
4
|
+
import { dirname, join } from "node:path";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
3
6
|
|
|
4
7
|
import HkButton from "./HkButton";
|
|
5
8
|
|
|
9
|
+
const here = dirname(fileURLToPath(import.meta.url));
|
|
10
|
+
|
|
6
11
|
/**
|
|
7
12
|
* HkButton contract tests:
|
|
8
13
|
* - variant / size / block / loading class mapping on the root <button>
|
|
@@ -142,6 +147,82 @@ describe("HkButton content slots", () => {
|
|
|
142
147
|
});
|
|
143
148
|
});
|
|
144
149
|
|
|
150
|
+
describe("HkButton icon-only square contract", () => {
|
|
151
|
+
it("flags the icon-only square class for a glyph with no label", () => {
|
|
152
|
+
const iconOnly = mount(h(HkButton, { icon: "close", ariaLabel: "Close" }));
|
|
153
|
+
const btn = button(iconOnly);
|
|
154
|
+
expect(btn.className).toContain("hk-btn-icon-only");
|
|
155
|
+
expect(iconOnly.querySelector(".hk-btn-icon")).not.toBeNull();
|
|
156
|
+
|
|
157
|
+
const suffixOnly = mount(h(HkButton, { suffix: "close", ariaLabel: "Next" }));
|
|
158
|
+
expect(button(suffixOnly).className).toContain("hk-btn-icon-only");
|
|
159
|
+
|
|
160
|
+
// Glyph + text stays a normal text button — no square collapse.
|
|
161
|
+
const withText = mount(h(HkButton, { icon: "close" }, () => "Close"));
|
|
162
|
+
expect(button(withText).className).not.toContain("hk-btn-icon-only");
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
it("keeps the square footprint while an icon-only button loads", () => {
|
|
166
|
+
const c = mount(h(HkButton, { icon: "close", loading: true, ariaLabel: "Busy" }));
|
|
167
|
+
// The spinner replaces the glyph, but the button still carries no
|
|
168
|
+
// label — the square footprint must hold through the swap.
|
|
169
|
+
expect(button(c).className).toContain("hk-btn-icon-only");
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
it("keeps the block class alongside the icon-only square class", () => {
|
|
173
|
+
// CSS precedence lives in the SCSS contract test below; this pins the
|
|
174
|
+
// class composition so both rules can actually apply.
|
|
175
|
+
const c = mount(h(HkButton, { icon: "close", block: true, ariaLabel: "Go" }));
|
|
176
|
+
const cls = button(c).className;
|
|
177
|
+
expect(cls).toContain("hk-btn-block");
|
|
178
|
+
expect(cls).toContain("hk-btn-icon-only");
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
it("does not square-collapse when a shortcut chip rides along", () => {
|
|
182
|
+
// The HKbd chip is an extra flex child — the fixed square width would
|
|
183
|
+
// visibly clip it, so icon + shortcut stays a padded button.
|
|
184
|
+
const c = mount(h(HkButton, { icon: "close", shortcut: "Ctrl+W", ariaLabel: "Close" }));
|
|
185
|
+
expect(button(c).className).not.toContain("hk-btn-icon-only");
|
|
186
|
+
});
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
// SCSS geometry contract (house pattern, cf. HkNumberInput.affix.test.ts):
|
|
190
|
+
// the square is a CSS fact — padding fully collapsed + self-declared
|
|
191
|
+
// border-box (survives hosts without a reset) + the block prop winning
|
|
192
|
+
// over the square width. Textual assertions because happy-dom does not
|
|
193
|
+
// lay out.
|
|
194
|
+
describe("HkButton icon-only SCSS contract", () => {
|
|
195
|
+
const scss = readFileSync(join(here, "HkButton.scss"), "utf-8");
|
|
196
|
+
|
|
197
|
+
it("self-declares the collapsed square geometry", () => {
|
|
198
|
+
const rule = scss.match(/\.hk-btn-icon-only\s*{[^}]*}/)?.[0] ?? "";
|
|
199
|
+
expect(rule, "icon-only rule must exist").toBeTruthy();
|
|
200
|
+
expect(rule).toContain("padding: 0");
|
|
201
|
+
expect(rule).toContain("box-sizing: border-box");
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
it("lets the block prop win over the square width", () => {
|
|
205
|
+
const rule = scss.match(/\.hk-btn-block\.hk-btn-icon-only\s*{[^}]*}/)?.[0] ?? "";
|
|
206
|
+
expect(rule, "block override rule must exist").toBeTruthy();
|
|
207
|
+
expect(rule).toContain("width: 100%");
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
it("locks each size variant width to its min-height", () => {
|
|
211
|
+
const cases: Array<[string, string]> = [
|
|
212
|
+
["sm", "1.75rem"],
|
|
213
|
+
["md", "2.5rem"],
|
|
214
|
+
["lg", "2.75rem"],
|
|
215
|
+
];
|
|
216
|
+
for (const [size, width] of cases) {
|
|
217
|
+
const rule = scss.match(new RegExp(`\\.hk-btn-${size}\\.hk-btn-icon-only\\s*{[^}]*}`))?.[0] ?? "";
|
|
218
|
+
expect(rule, `${size} icon-only rule must exist`).toBeTruthy();
|
|
219
|
+
expect(rule).toContain(`width: ${width}`);
|
|
220
|
+
const minH = scss.match(new RegExp(`\\.hk-btn-${size}\\s*{[^}]*}`))?.[0] ?? "";
|
|
221
|
+
expect(minH).toContain(`min-height: ${width}`);
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
});
|
|
225
|
+
|
|
145
226
|
describe("HkButton attr fallthrough (inheritAttrs: false)", () => {
|
|
146
227
|
it("spreads extra attrs and honors an explicit type", () => {
|
|
147
228
|
const c = mount(h(HkButton, { type: "submit", "data-test": "probe" }, () => "Save"));
|
|
@@ -42,33 +42,47 @@ export default defineComponent({
|
|
|
42
42
|
props.shortcut ? "hk-btn-has-shortcut" : "",
|
|
43
43
|
]);
|
|
44
44
|
|
|
45
|
-
return () =>
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
45
|
+
return () => {
|
|
46
|
+
// Icon-only contract (2026-09-10 user direction): a button carrying
|
|
47
|
+
// just a prefix/suffix glyph and no text collapses to the same
|
|
48
|
+
// square footprint the HIconButton family guarantees — a bare icon
|
|
49
|
+
// in a padded text button reads as a squat rectangle otherwise.
|
|
50
|
+
// Re-evaluated per render, NOT a computed: slots.default is not
|
|
51
|
+
// reactive, so a cached flag would go stale when a parent toggles
|
|
52
|
+
// the label slot without touching the icon props. A shortcut chip
|
|
53
|
+
// is excluded: it renders as an extra flex child the fixed square
|
|
54
|
+
// width would visibly clip.
|
|
55
|
+
const iconOnly =
|
|
56
|
+
!slots.default && Boolean(props.icon || props.suffix) && !props.shortcut;
|
|
57
|
+
|
|
58
|
+
return (
|
|
59
|
+
<button
|
|
60
|
+
{...attrs}
|
|
61
|
+
type={(attrs.type as "button" | "submit" | "reset") || "button"}
|
|
62
|
+
disabled={props.disabled || props.loading}
|
|
63
|
+
class={[buttonClass.value, iconOnly ? "hk-btn-icon-only" : "", attrs.class]}
|
|
64
|
+
style={attrs.style || undefined}
|
|
65
|
+
aria-label={props.ariaLabel}
|
|
66
|
+
aria-busy={props.loading || undefined}
|
|
67
|
+
onClick={(e) => emit("click", e)}
|
|
68
|
+
>
|
|
69
|
+
{props.loading ? <HSpinner size="xs" tone="current" /> : null}
|
|
70
|
+
{!props.loading && props.icon ? (
|
|
71
|
+
<span class="hk-btn-icon">
|
|
72
|
+
<HIcon name={props.icon} size={16} />
|
|
73
|
+
</span>
|
|
74
|
+
) : null}
|
|
75
|
+
{slots.default?.()}
|
|
76
|
+
{props.suffix ? (
|
|
77
|
+
<span class="hk-btn-suffix">
|
|
78
|
+
<HIcon name={props.suffix} size={16} />
|
|
79
|
+
</span>
|
|
80
|
+
) : null}
|
|
81
|
+
{props.shortcut ? (
|
|
82
|
+
<HKbd keys={props.shortcut!} size="sm" />
|
|
83
|
+
) : null}
|
|
84
|
+
</button>
|
|
85
|
+
);
|
|
86
|
+
};
|
|
73
87
|
},
|
|
74
88
|
});
|
|
@@ -102,4 +102,19 @@ describe("HkIconButton", () => {
|
|
|
102
102
|
const c = mountComp(() => h(HkIconButton, { "aria-label": "probe" }));
|
|
103
103
|
expect(c.querySelector("circle")).not.toBeNull();
|
|
104
104
|
});
|
|
105
|
+
|
|
106
|
+
// Named-icon contract (2026-09-10): the icon prop resolves through HIcon
|
|
107
|
+
// (functional keys ride the host material pack) — slot content still
|
|
108
|
+
// wins over it, and the placeholder circle only shows with neither.
|
|
109
|
+
it("renders the icon prop through HIcon, below slot precedence", () => {
|
|
110
|
+
const propOnly = mountComp(() => h(HkIconButton, { icon: "close", "aria-label": "close" }));
|
|
111
|
+
expect(propOnly.querySelector(".hk-icon")).not.toBeNull();
|
|
112
|
+
expect(propOnly.querySelector("circle")).toBeNull();
|
|
113
|
+
|
|
114
|
+
const propAndSlot = mountComp(() =>
|
|
115
|
+
h(HkIconButton, { icon: "close", "aria-label": "close" }, { icon: () => h("span", { class: "slot-probe" }) }),
|
|
116
|
+
);
|
|
117
|
+
expect(propAndSlot.querySelector(".slot-probe")).not.toBeNull();
|
|
118
|
+
expect(propAndSlot.querySelector(".hk-icon")).toBeNull();
|
|
119
|
+
});
|
|
105
120
|
});
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { computed, defineComponent, type PropType } from "vue";
|
|
2
2
|
import "./HkIconButton.scss";
|
|
3
3
|
import "./HkIconButtonVars.scss";
|
|
4
|
+
import HIcon from "./HkIcon";
|
|
4
5
|
|
|
5
6
|
export default defineComponent({
|
|
6
7
|
name: "HkIconButton",
|
|
@@ -21,6 +22,14 @@ export default defineComponent({
|
|
|
21
22
|
`hk-icon-button-${props.variant}`,
|
|
22
23
|
]);
|
|
23
24
|
|
|
25
|
+
// Named-icon contract (2026-09-10 user direction): the icon prop is a
|
|
26
|
+
// first-class way to draw the glyph — it resolves through HIcon so
|
|
27
|
+
// functional keys ("close", "back") keep riding the host material-pack
|
|
28
|
+
// family exactly like the slot composition does. The rendered size is
|
|
29
|
+
// pinned by --hi-icon-button-icon-size; the HIcon size prop only picks
|
|
30
|
+
// the matching box class. Slot content still wins over the prop.
|
|
31
|
+
const glyphSize = computed(() => (props.size >= 32 ? 20 : 16));
|
|
32
|
+
|
|
24
33
|
return () => (
|
|
25
34
|
<button
|
|
26
35
|
class={cls.value}
|
|
@@ -35,11 +44,15 @@ export default defineComponent({
|
|
|
35
44
|
? // Natural children usage: <HIconButton><HIcon .../></HIconButton>
|
|
36
45
|
// renders the child as the icon (unified window-close wave).
|
|
37
46
|
slots.default()
|
|
38
|
-
:
|
|
39
|
-
|
|
40
|
-
<
|
|
41
|
-
|
|
42
|
-
|
|
47
|
+
: props.icon
|
|
48
|
+
? (
|
|
49
|
+
<HIcon name={props.icon} size={glyphSize.value} />
|
|
50
|
+
)
|
|
51
|
+
: (
|
|
52
|
+
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
53
|
+
<circle cx="12" cy="12" r="10" />
|
|
54
|
+
</svg>
|
|
55
|
+
)}
|
|
43
56
|
</span>
|
|
44
57
|
</button>
|
|
45
58
|
);
|
|
@@ -125,6 +125,48 @@ describe("createErrorReporting", () => {
|
|
|
125
125
|
expect(overlayHost()).toBeNull();
|
|
126
126
|
});
|
|
127
127
|
|
|
128
|
+
it("stays up for cross-origin-masked window errors", async () => {
|
|
129
|
+
const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
|
|
130
|
+
const error = vi.spyOn(console, "error").mockImplementation(() => {});
|
|
131
|
+
// Earlier tests in this file spy the same methods without restoring;
|
|
132
|
+
// clear the accumulated calls so the assertions see only this test's.
|
|
133
|
+
warn.mockClear();
|
|
134
|
+
error.mockClear();
|
|
135
|
+
installPlugin();
|
|
136
|
+
|
|
137
|
+
// The masking signature: details withheld (error == null) because the
|
|
138
|
+
// thrower is foreign-origin code (extension / userscript), message
|
|
139
|
+
// pinned to "Script error." by every Chromium/Gecko/WebKit build.
|
|
140
|
+
window.dispatchEvent(new ErrorEvent("error", { message: "Script error.", error: null }));
|
|
141
|
+
await nextTick();
|
|
142
|
+
expect(overlayHost()).toBeNull();
|
|
143
|
+
expect(warn).toHaveBeenCalled();
|
|
144
|
+
expect(error).not.toHaveBeenCalled();
|
|
145
|
+
|
|
146
|
+
// The bare-spelling variant is masked the same way.
|
|
147
|
+
window.dispatchEvent(new ErrorEvent("error", { message: "Script error", error: null }));
|
|
148
|
+
await nextTick();
|
|
149
|
+
expect(overlayHost()).toBeNull();
|
|
150
|
+
|
|
151
|
+
clearGlobalError();
|
|
152
|
+
warn.mockRestore();
|
|
153
|
+
error.mockRestore();
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
it("still reports detail-less window errors that are not masked", async () => {
|
|
157
|
+
vi.spyOn(console, "error").mockImplementation(() => {});
|
|
158
|
+
installPlugin();
|
|
159
|
+
|
|
160
|
+
// error == null with a real message is a script error the browser DID
|
|
161
|
+
// describe — that stays reportable.
|
|
162
|
+
window.dispatchEvent(
|
|
163
|
+
new ErrorEvent("error", { message: "Uncaught SyntaxError: unexpected token", error: null }),
|
|
164
|
+
);
|
|
165
|
+
await nextTick();
|
|
166
|
+
expect(overlayHost()!.querySelector(".hk-error-landing__desc")!.textContent)
|
|
167
|
+
.toBe("Uncaught SyntaxError: unexpected token");
|
|
168
|
+
});
|
|
169
|
+
|
|
128
170
|
it("chains a pre-existing app errorHandler", () => {
|
|
129
171
|
vi.spyOn(console, "error").mockImplementation(() => {});
|
|
130
172
|
const previous = vi.fn();
|
|
@@ -87,6 +87,21 @@ function installWindowHooks(options: HkErrorReportingOptions): void {
|
|
|
87
87
|
const onError = (event: ErrorEvent) => {
|
|
88
88
|
// Resource-load failures never reach here (no capture phase); script
|
|
89
89
|
// errors always carry `error` or at least a `message`.
|
|
90
|
+
//
|
|
91
|
+
// Cross-origin-masked script errors arrive as `message: "Script
|
|
92
|
+
// error."` with a null `error` object: the browser withholds the
|
|
93
|
+
// details precisely because the thrower is NOT this origin's code
|
|
94
|
+
// (browser extensions / userscripts are the usual sources). A
|
|
95
|
+
// synthetic record for one would carry zero actionable detail and a
|
|
96
|
+
// stack pointing at this very handler, while the takeover rips the
|
|
97
|
+
// host app away from the user for noise it did not produce — log
|
|
98
|
+
// and stay up instead (chest demo report 2026-09-10: tapping the
|
|
99
|
+
// wallpaper preview in a userscript-capable mobile browser nuked
|
|
100
|
+
// the session with such a masked event).
|
|
101
|
+
if (event.error == null && /^script error\.?$/i.test(event.message)) {
|
|
102
|
+
console.warn("[hikari:error-reporting] ignored a cross-origin-masked script error");
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
90
105
|
const err = event.error ?? new Error(event.message || "Unknown script error");
|
|
91
106
|
if (reportError(err, "window")) ensureOverlayMounted();
|
|
92
107
|
};
|