@celestia-island/hikari 0.55.406 → 0.55.408
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
|
@@ -21,6 +21,15 @@
|
|
|
21
21
|
* the centered line sits; only an explicit data-align="start"/
|
|
22
22
|
* "end" (HkInput's `align` prop) restores the per-side
|
|
23
23
|
* reservation.
|
|
24
|
+
* 4. Narrow-box auto-degrade (2026-11-17 chest report): when the box
|
|
25
|
+
* is too narrow for the symmetric trade — the pure predicate in
|
|
26
|
+
* inputAffixGeometry.ts: boxW < 3·max(startW,endW) + 2·base, i.e.
|
|
27
|
+
* the line would come out narrower than the widest affix itself —
|
|
28
|
+
* a CENTERED non-textarea box stamps data-affix-cramped and the
|
|
29
|
+
* sheet switches element padding + marquee window to the per-side
|
|
30
|
+
* geometry. Explicit alignments and textareas never carry the
|
|
31
|
+
* marker; text-align stays centered; the reservation is the only
|
|
32
|
+
* thing that degrades.
|
|
24
33
|
*/
|
|
25
34
|
import { afterEach, describe, expect, it } from "vitest";
|
|
26
35
|
import { readFileSync } from "node:fs";
|
|
@@ -160,6 +169,44 @@ describe("HkInput affix reservation contract", () => {
|
|
|
160
169
|
expect(textarea).toContain("padding: var(--space-8) var(--space-12)");
|
|
161
170
|
});
|
|
162
171
|
|
|
172
|
+
it("switches to per-side reservations under data-affix-cramped", () => {
|
|
173
|
+
// The degrade rules must carry the per-side arithmetic verbatim —
|
|
174
|
+
// the exact geometry of the data-align rules above — and stay
|
|
175
|
+
// reservation-only (no text-align flip: the line re-centers inside
|
|
176
|
+
// the now-asymmetric content box).
|
|
177
|
+
const elementRule = scss.match(
|
|
178
|
+
/\.hk-input-box\[data-affix-cramped\] \.hk-input-element:not\(\.hk-input-textarea\)\s*{[^}]*}/,
|
|
179
|
+
)?.[0] ?? "";
|
|
180
|
+
expect(elementRule, "cramped element rule must exist").toBeTruthy();
|
|
181
|
+
expect(elementRule).toContain(
|
|
182
|
+
"padding-inline-start: calc(var(--space-12) + var(--hk-input-affix-start-w, 0px))",
|
|
183
|
+
);
|
|
184
|
+
expect(elementRule).toContain(
|
|
185
|
+
"padding-inline-end: calc(var(--space-12) + var(--hk-input-affix-end-w, 0px))",
|
|
186
|
+
);
|
|
187
|
+
expect(elementRule).not.toContain("text-align");
|
|
188
|
+
|
|
189
|
+
const marqueeRule = scss.match(
|
|
190
|
+
/\.hk-input-box\[data-affix-cramped\] \.hk-placeholder-marquee\s*{[^}]*}/,
|
|
191
|
+
)?.[0] ?? "";
|
|
192
|
+
expect(marqueeRule, "cramped marquee rule must exist").toBeTruthy();
|
|
193
|
+
expect(marqueeRule).toContain(
|
|
194
|
+
"inset-inline-start: calc(var(--space-12) + var(--hk-input-affix-start-w, 0px))",
|
|
195
|
+
);
|
|
196
|
+
expect(marqueeRule).toContain(
|
|
197
|
+
"inset-inline-end: calc(var(--space-12) + var(--hk-input-affix-end-w, 0px))",
|
|
198
|
+
);
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
it("keys the sheet on the same marker the component stamps", () => {
|
|
202
|
+
// Source pairing: a rename on either side must red here before it
|
|
203
|
+
// can ship a rule that never matches (the Sort-family failure mode).
|
|
204
|
+
const tsx = readFileSync(join(here, "HkInput.tsx"), "utf-8");
|
|
205
|
+
expect(tsx).toContain("data-affix-cramped={");
|
|
206
|
+
expect(tsx).toContain('isAffixLineCramped');
|
|
207
|
+
expect(scss).toContain(".hk-input-box[data-affix-cramped]");
|
|
208
|
+
});
|
|
209
|
+
|
|
163
210
|
it("publishes the measured affix width on the box", async () => {
|
|
164
211
|
// happy-dom lays out nothing — pin the affix width the ref callback
|
|
165
212
|
// would measure in a real browser and read the published custom
|
|
@@ -250,4 +297,114 @@ describe("HkInput affix reservation contract", () => {
|
|
|
250
297
|
}
|
|
251
298
|
}
|
|
252
299
|
});
|
|
300
|
+
|
|
301
|
+
// ── narrow-box auto-degrade (guarantee 4) ─────────────────────────
|
|
302
|
+
// happy-dom lays out nothing: stub the measured accessors the same
|
|
303
|
+
// way the width tests above do, pairing the affix width with a box
|
|
304
|
+
// width to walk the predicate through its report geometry.
|
|
305
|
+
async function withMeasuredBox<T>(
|
|
306
|
+
boxW: number,
|
|
307
|
+
affixW: number,
|
|
308
|
+
run: () => Promise<T> | T,
|
|
309
|
+
): Promise<T> {
|
|
310
|
+
const offset = Object.getOwnPropertyDescriptor(
|
|
311
|
+
HTMLElement.prototype,
|
|
312
|
+
"offsetWidth",
|
|
313
|
+
);
|
|
314
|
+
const client = Object.getOwnPropertyDescriptor(
|
|
315
|
+
HTMLElement.prototype,
|
|
316
|
+
"clientWidth",
|
|
317
|
+
);
|
|
318
|
+
expect(offset, "offsetWidth accessor exists on HTMLElement").toBeTruthy();
|
|
319
|
+
expect(client, "clientWidth accessor exists on HTMLElement").toBeTruthy();
|
|
320
|
+
Object.defineProperty(HTMLElement.prototype, "offsetWidth", {
|
|
321
|
+
configurable: true,
|
|
322
|
+
get: () => affixW,
|
|
323
|
+
});
|
|
324
|
+
Object.defineProperty(HTMLElement.prototype, "clientWidth", {
|
|
325
|
+
configurable: true,
|
|
326
|
+
get: () => boxW,
|
|
327
|
+
});
|
|
328
|
+
try {
|
|
329
|
+
return await run();
|
|
330
|
+
} finally {
|
|
331
|
+
if (offset) Object.defineProperty(HTMLElement.prototype, "offsetWidth", offset);
|
|
332
|
+
if (client) Object.defineProperty(HTMLElement.prototype, "clientWidth", client);
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
it("auto-degrades the centered reservation on a narrow box", async () => {
|
|
337
|
+
// The report geometry: 330px drawer box, 120px platform chip.
|
|
338
|
+
await withMeasuredBox(330, 120, async () => {
|
|
339
|
+
const { container } = mountInput({
|
|
340
|
+
slots: { prefix: () => h("span", "CHIP") },
|
|
341
|
+
});
|
|
342
|
+
await nextTick();
|
|
343
|
+
const box = container.querySelector<HTMLElement>(".hk-input-box")!;
|
|
344
|
+
expect(box.getAttribute("data-affix-cramped")).toBe("");
|
|
345
|
+
// The measured vars stay published — the sheet consumes them per
|
|
346
|
+
// side under the marker; zeroing them would strand the geometry.
|
|
347
|
+
expect(box.style.getPropertyValue("--hk-input-affix-start-w")).toBe("120px");
|
|
348
|
+
expect(box.style.getPropertyValue("--hk-input-affix-end-w")).toBe("0px");
|
|
349
|
+
});
|
|
350
|
+
});
|
|
351
|
+
|
|
352
|
+
it("keeps the centered reservation on a wide box", async () => {
|
|
353
|
+
await withMeasuredBox(528, 110, async () => {
|
|
354
|
+
const { container } = mountInput({
|
|
355
|
+
slots: { prefix: () => h("span", "CHIP") },
|
|
356
|
+
});
|
|
357
|
+
await nextTick();
|
|
358
|
+
const box = container.querySelector<HTMLElement>(".hk-input-box")!;
|
|
359
|
+
expect(box.getAttribute("data-affix-cramped")).toBeNull();
|
|
360
|
+
// The centered-default vars are the only geometry signal present.
|
|
361
|
+
expect(box.getAttribute("data-align")).toBeNull();
|
|
362
|
+
});
|
|
363
|
+
});
|
|
364
|
+
|
|
365
|
+
it("never degrades an explicit alignment, even on a narrow box", async () => {
|
|
366
|
+
await withMeasuredBox(330, 120, async () => {
|
|
367
|
+
const start = mountInput({
|
|
368
|
+
props: { align: "start" },
|
|
369
|
+
slots: { prefix: () => h("span", "CHIP") },
|
|
370
|
+
});
|
|
371
|
+
await nextTick();
|
|
372
|
+
const startBox = start.container.querySelector<HTMLElement>(".hk-input-box")!;
|
|
373
|
+
expect(startBox.getAttribute("data-align")).toBe("start");
|
|
374
|
+
expect(startBox.getAttribute("data-affix-cramped")).toBeNull();
|
|
375
|
+
|
|
376
|
+
const end = mountInput({
|
|
377
|
+
props: { align: "end" },
|
|
378
|
+
slots: { prefix: () => h("span", "CHIP") },
|
|
379
|
+
});
|
|
380
|
+
await nextTick();
|
|
381
|
+
const endBox = end.container.querySelector<HTMLElement>(".hk-input-box")!;
|
|
382
|
+
expect(endBox.getAttribute("data-align")).toBe("end");
|
|
383
|
+
expect(endBox.getAttribute("data-affix-cramped")).toBeNull();
|
|
384
|
+
});
|
|
385
|
+
});
|
|
386
|
+
|
|
387
|
+
it("never degrades textareas or affix-less boxes", async () => {
|
|
388
|
+
await withMeasuredBox(330, 120, async () => {
|
|
389
|
+
// A textarea's affixes flow BESIDE the element — the marker would
|
|
390
|
+
// only strand its marquee window with the per-side insets.
|
|
391
|
+
const ta = mountInput({
|
|
392
|
+
props: { type: "textarea" },
|
|
393
|
+
slots: { prefix: () => h("span", "CHIP") },
|
|
394
|
+
});
|
|
395
|
+
await nextTick();
|
|
396
|
+
expect(
|
|
397
|
+
ta.container.querySelector<HTMLElement>(".hk-input-box")!
|
|
398
|
+
.getAttribute("data-affix-cramped"),
|
|
399
|
+
).toBeNull();
|
|
400
|
+
|
|
401
|
+
// No affixes → nothing to degrade, whatever the box width.
|
|
402
|
+
const bare = mountInput();
|
|
403
|
+
await nextTick();
|
|
404
|
+
expect(
|
|
405
|
+
bare.container.querySelector<HTMLElement>(".hk-input-box")!
|
|
406
|
+
.getAttribute("data-affix-cramped"),
|
|
407
|
+
).toBeNull();
|
|
408
|
+
});
|
|
409
|
+
});
|
|
253
410
|
});
|
|
@@ -243,6 +243,40 @@
|
|
|
243
243
|
inset-inline-end: calc(var(--space-12) + var(--hk-input-affix-end-w, 0px));
|
|
244
244
|
}
|
|
245
245
|
|
|
246
|
+
/* ── Narrow-box auto-degrade (centered default only) ──────────────────
|
|
247
|
+
* The symmetric reservation above is an optical-centering trade paid in
|
|
248
|
+
* dead line width on the affix-less side. When the box is too narrow to
|
|
249
|
+
* fit three widest-affix widths plus the base paddings, the trade stops
|
|
250
|
+
* paying: the usable line drops below ONE affix width and the whole
|
|
251
|
+
* affix-less side turns permanently dead — no caret, no placeholder
|
|
252
|
+
* (2026-11-17 chest report: a near-full-width phone bottom drawer with
|
|
253
|
+
* a ~120px platform chip in the #prefix slot left the right third of
|
|
254
|
+
* the repository-URL line unreachable; the caller had passed no
|
|
255
|
+
* `align`, so the centered default owned the geometry).
|
|
256
|
+
*
|
|
257
|
+
* HkInput measures the box itself alongside the affixes (one shared
|
|
258
|
+
* ResizeObserver) and stamps `data-affix-cramped` on the box when the
|
|
259
|
+
* pure predicate (inputAffixGeometry.ts) fires. The marker switches
|
|
260
|
+
* BOTH reservations to the per-side arithmetic — exactly the
|
|
261
|
+
* data-align rules' math, each side reserving only its own affix plus
|
|
262
|
+
* the base padding — so the line, the placeholder and the marquee
|
|
263
|
+
* window reclaim the dead side. The marker is stamped on CENTERED
|
|
264
|
+
* non-textarea boxes only, so these rules can never fight the
|
|
265
|
+
* explicit-alignment rules above; text-align stays centered (the line
|
|
266
|
+
* re-centers inside the now-asymmetric content box), and the marquee
|
|
267
|
+
* re-measures its wider window through its own ResizeObserver. Only
|
|
268
|
+
* logical properties — the per-side math is inset/padding-inline, so
|
|
269
|
+
* RTL keeps mirroring. */
|
|
270
|
+
.hk-input-box[data-affix-cramped] .hk-input-element:not(.hk-input-textarea) {
|
|
271
|
+
padding-inline-start: calc(var(--space-12) + var(--hk-input-affix-start-w, 0px));
|
|
272
|
+
padding-inline-end: calc(var(--space-12) + var(--hk-input-affix-end-w, 0px));
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
.hk-input-box[data-affix-cramped] .hk-placeholder-marquee {
|
|
276
|
+
inset-inline-start: calc(var(--space-12) + var(--hk-input-affix-start-w, 0px));
|
|
277
|
+
inset-inline-end: calc(var(--space-12) + var(--hk-input-affix-end-w, 0px));
|
|
278
|
+
}
|
|
279
|
+
|
|
246
280
|
.hk-input-error-msg {
|
|
247
281
|
margin-top: var(--space-4);
|
|
248
282
|
font-size: var(--text-xs);
|
|
@@ -5,6 +5,7 @@ import type { PasswordStrengthEvaluator } from "../utils/password";
|
|
|
5
5
|
import { HkPlaceholderMarquee } from "./HkPlaceholderMarquee";
|
|
6
6
|
import HkPasswordSurface from "./HkPasswordSurface";
|
|
7
7
|
import HkNumberSteppers from "./HkNumberSteppers";
|
|
8
|
+
import { isAffixLineCramped } from "./inputAffixGeometry";
|
|
8
9
|
import "./HkInput.scss";
|
|
9
10
|
|
|
10
11
|
export default defineComponent({
|
|
@@ -246,19 +247,41 @@ export default defineComponent({
|
|
|
246
247
|
// about the box axis (a lone prefix icon must not push the
|
|
247
248
|
// centered line off-center), while an explicit data-align="start"
|
|
248
249
|
// / "end" pads each side only by its own affix.
|
|
250
|
+
//
|
|
251
|
+
// Narrow-box auto-degrade: the symmetric reservation is an
|
|
252
|
+
// optical-centering trade paid in dead line width on the
|
|
253
|
+
// affix-less side. When the box is too narrow to fit three
|
|
254
|
+
// widest-affix widths plus the base paddings, the trade stops
|
|
255
|
+
// paying — the usable line drops below one affix width and the
|
|
256
|
+
// affix-less side becomes permanently dead (2026-11-17 chest
|
|
257
|
+
// report: a near-full-width phone drawer with a ~120px platform
|
|
258
|
+
// chip left a third of the repository-URL line unreachable). The
|
|
259
|
+
// box is therefore measured TOO (same observer), the pure
|
|
260
|
+
// predicate in inputAffixGeometry.ts judges it, and a CENTERED
|
|
261
|
+
// box that fails stamps data-affix-cramped; the sheet then switches
|
|
262
|
+
// the element padding and the marquee window to the per-side
|
|
263
|
+
// reservation — the exact geometry of data-align — while
|
|
264
|
+
// text-align stays centered. Explicit alignments and textareas
|
|
265
|
+
// never carry the marker, so their geometry is untouched.
|
|
249
266
|
const prefixEl = ref<HTMLElement | null>(null);
|
|
250
267
|
const suffixEl = ref<HTMLElement | null>(null);
|
|
251
268
|
/* The number steppers' column — measured INTO the end-side clearance
|
|
252
269
|
(summed with the suffix span) so centered text and the marquee
|
|
253
270
|
window always end short of the buttons. */
|
|
254
271
|
const steppersEl = ref<HTMLElement | null>(null);
|
|
272
|
+
/* The box itself — its clientWidth is the third input of the
|
|
273
|
+
cramped judgment (the element spans the box's padding box, so
|
|
274
|
+
clientWidth IS the space the padded line lives in). */
|
|
275
|
+
const boxEl = ref<HTMLElement | null>(null);
|
|
255
276
|
const affixStartW = ref(0);
|
|
256
277
|
const affixEndW = ref(0);
|
|
278
|
+
const boxW = ref(0);
|
|
257
279
|
|
|
258
280
|
function measureAffixes() {
|
|
259
281
|
affixStartW.value = prefixEl.value?.offsetWidth ?? 0;
|
|
260
282
|
affixEndW.value =
|
|
261
283
|
(suffixEl.value?.offsetWidth ?? 0) + (steppersEl.value?.offsetWidth ?? 0);
|
|
284
|
+
boxW.value = boxEl.value?.clientWidth ?? 0;
|
|
262
285
|
}
|
|
263
286
|
|
|
264
287
|
const affixRO: ResizeObserver | null =
|
|
@@ -306,6 +329,15 @@ export default defineComponent({
|
|
|
306
329
|
const prefixAffixRef = bindMeasured(() => prefixEl);
|
|
307
330
|
const suffixAffixRef = bindMeasured(() => suffixEl);
|
|
308
331
|
const steppersRootRef = bindMeasured(() => steppersEl);
|
|
332
|
+
/* The box rides the SAME observer as the affixes: resizing the host
|
|
333
|
+
(a bottom drawer dragging up, a window snap) re-runs the cramped
|
|
334
|
+
judgment with no consumer involvement — the marker follows the
|
|
335
|
+
geometry, not the mount. Same deferred-unbind safety net. */
|
|
336
|
+
const boxRootRef = bindMeasured(() => boxEl);
|
|
337
|
+
|
|
338
|
+
const affixCramped = computed(() =>
|
|
339
|
+
isAffixLineCramped(affixStartW.value, affixEndW.value, boxW.value),
|
|
340
|
+
);
|
|
309
341
|
|
|
310
342
|
const boxVars = computed(
|
|
311
343
|
() =>
|
|
@@ -487,6 +519,7 @@ export default defineComponent({
|
|
|
487
519
|
</HkPasswordSurface>
|
|
488
520
|
) : (
|
|
489
521
|
<div
|
|
522
|
+
ref={boxRootRef}
|
|
490
523
|
class={boxClass.value}
|
|
491
524
|
style={boxVars.value}
|
|
492
525
|
data-autogrow={isAutoGrow.value || undefined}
|
|
@@ -500,6 +533,18 @@ export default defineComponent({
|
|
|
500
533
|
data-align={
|
|
501
534
|
!isTextarea.value && props.align !== "center" ? props.align : undefined
|
|
502
535
|
}
|
|
536
|
+
// Narrow-box auto-degrade: only the CENTERED non-textarea box
|
|
537
|
+
// may degrade (same stamping rule as data-align) — explicit
|
|
538
|
+
// alignments keep their geometry verbatim, and the password
|
|
539
|
+
// surface never renders this box at all. Empty string = the
|
|
540
|
+
// boolean-marker convention the SCSS presence selectors key on.
|
|
541
|
+
data-affix-cramped={
|
|
542
|
+
!isTextarea.value &&
|
|
543
|
+
props.align === "center" &&
|
|
544
|
+
affixCramped.value
|
|
545
|
+
? ""
|
|
546
|
+
: undefined
|
|
547
|
+
}
|
|
503
548
|
>
|
|
504
549
|
{slots.prefix && (
|
|
505
550
|
<span ref={prefixAffixRef} class="hk-input-affix hk-input-prefix">
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pin for HkInput's narrow-box auto-degrade predicate (2026-11-17
|
|
3
|
+
* chest report: a near-full-width phone bottom drawer with a ~120px
|
|
4
|
+
* platform chip in the #prefix slot left the right third of the
|
|
5
|
+
* repository-URL line permanently empty under the centered default).
|
|
6
|
+
*
|
|
7
|
+
* The threshold has an exact reading, pinned here so a refactor cannot
|
|
8
|
+
* quietly move it: the symmetric centered reservation leaves a usable
|
|
9
|
+
* line of `boxW − 2·base − 2·widest`, which is strictly narrower than
|
|
10
|
+
* the widest affix itself exactly when `boxW < 3·widest + 2·base`.
|
|
11
|
+
* Below that line the optical-centering trade stops paying and the
|
|
12
|
+
* box degrades to the per-side reservation.
|
|
13
|
+
*
|
|
14
|
+
* Mutation note: flipping the comparison, the 3× factor, the base
|
|
15
|
+
* constant, or deleting a non-case guard must red these tests.
|
|
16
|
+
*/
|
|
17
|
+
import { describe, expect, it } from "vitest";
|
|
18
|
+
|
|
19
|
+
import { AFFIX_BASE_PAD_PX, isAffixLineCramped } from "./inputAffixGeometry";
|
|
20
|
+
|
|
21
|
+
describe("isAffixLineCramped", () => {
|
|
22
|
+
it("fires on the reported mobile geometry (330px box, 120px chip)", () => {
|
|
23
|
+
expect(isAffixLineCramped(120, 0, 330)).toBe(true);
|
|
24
|
+
// The dead side follows the widest affix — a suffix-carried chip
|
|
25
|
+
// starves the line identically.
|
|
26
|
+
expect(isAffixLineCramped(0, 120, 330)).toBe(true);
|
|
27
|
+
// Both sides affixed: only the widest feeds the judgment.
|
|
28
|
+
expect(isAffixLineCramped(110, 120, 330)).toBe(true);
|
|
29
|
+
expect(isAffixLineCramped(120, 110, 330)).toBe(true);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it("keeps desktop geometry centered (36rem window, 110–130px chip)", () => {
|
|
33
|
+
expect(isAffixLineCramped(110, 0, 528)).toBe(false);
|
|
34
|
+
expect(isAffixLineCramped(110, 0, 576)).toBe(false);
|
|
35
|
+
expect(isAffixLineCramped(130, 0, 576)).toBe(false);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it("fires exactly when the usable line drops below one widest affix", () => {
|
|
39
|
+
const widest = 120;
|
|
40
|
+
// Boundary: symmetric reservation leaves EXACTLY one affix width of
|
|
41
|
+
// line — tight, but the centered default still owns the geometry.
|
|
42
|
+
const boundary = 3 * widest + 2 * AFFIX_BASE_PAD_PX; // 384
|
|
43
|
+
expect(boundary).toBe(384);
|
|
44
|
+
expect(isAffixLineCramped(widest, 0, boundary)).toBe(false);
|
|
45
|
+
expect(isAffixLineCramped(widest, 0, boundary - 1)).toBe(true);
|
|
46
|
+
expect(isAffixLineCramped(widest, 0, boundary + 1)).toBe(false);
|
|
47
|
+
// Same boundary from the end side and from a both-side pair.
|
|
48
|
+
expect(isAffixLineCramped(0, widest, boundary)).toBe(false);
|
|
49
|
+
expect(isAffixLineCramped(0, widest, boundary - 1)).toBe(true);
|
|
50
|
+
expect(isAffixLineCramped(widest, widest, boundary - 1)).toBe(true);
|
|
51
|
+
// A 1px-wider chip moves the boundary by exactly 3px — the 3×
|
|
52
|
+
// factor is load-bearing.
|
|
53
|
+
expect(isAffixLineCramped(widest + 1, 0, boundary - 1)).toBe(true);
|
|
54
|
+
expect(isAffixLineCramped(widest + 1, 0, boundary + 2)).toBe(true);
|
|
55
|
+
expect(isAffixLineCramped(widest + 1, 0, boundary + 3)).toBe(false);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it("never fires without affixes, even on a degenerate box", () => {
|
|
59
|
+
expect(isAffixLineCramped(0, 0, 330)).toBe(false);
|
|
60
|
+
expect(isAffixLineCramped(0, 0, 24)).toBe(false);
|
|
61
|
+
expect(isAffixLineCramped(0, 0, 0)).toBe(false);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it("never fires before a real box width is measured", () => {
|
|
65
|
+
// SSR, the pre-mount ref window and display:none all report zero;
|
|
66
|
+
// speculative geometry must not beat the published default.
|
|
67
|
+
expect(isAffixLineCramped(120, 0, 0)).toBe(false);
|
|
68
|
+
expect(isAffixLineCramped(0, 120, 0)).toBe(false);
|
|
69
|
+
expect(isAffixLineCramped(120, 0, -5)).toBe(false);
|
|
70
|
+
expect(isAffixLineCramped(Number.NaN, 0, 330)).toBe(false);
|
|
71
|
+
expect(isAffixLineCramped(0, Number.NaN, 330)).toBe(false);
|
|
72
|
+
expect(isAffixLineCramped(120, 0, Number.NaN)).toBe(false);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it("keeps the base constant mirroring the sheet's --space-12", () => {
|
|
76
|
+
// 0.75rem at the default 16px root. The predicate's doc and the
|
|
77
|
+
// SCSS both read "base padding = 12px"; drift here shifts every
|
|
78
|
+
// boundary by 2px per drifted pixel.
|
|
79
|
+
expect(AFFIX_BASE_PAD_PX).toBe(12);
|
|
80
|
+
});
|
|
81
|
+
});
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Geometry predicate for HkInput's narrow-box affix auto-degrade.
|
|
3
|
+
*
|
|
4
|
+
* The centered default reserves the WIDER of the two measured affix
|
|
5
|
+
* widths on BOTH sides (`--hk-input-affix-*-w` → symmetric
|
|
6
|
+
* padding-inline), so the centered caret, typed text and placeholder
|
|
7
|
+
* stay on the box axis no matter which side carries an affix. That
|
|
8
|
+
* reservation is an optical-centering trade paid in dead line width on
|
|
9
|
+
* the affix-less side. While the box is wide the trade is invisible;
|
|
10
|
+
* once the box can no longer fit three widest-affix widths plus the
|
|
11
|
+
* base paddings, it stops paying: the symmetric reservation leaves a
|
|
12
|
+
* usable line of `boxW - 2·base - 2·widest`, which is narrower than
|
|
13
|
+
* ONE widest affix exactly when `boxW < 3·widest + 2·base` — and the
|
|
14
|
+
* whole affix-less side turns into permanently dead space no caret or
|
|
15
|
+
* placeholder can enter (2026-11-17 chest report: the new-workspace
|
|
16
|
+
* remote-URL field in a near-full-width phone bottom drawer with a
|
|
17
|
+
* ~120px platform chip in the #prefix slot left the right third of the
|
|
18
|
+
* line empty; the caller had passed no `align`, so the centered
|
|
19
|
+
* default owned the geometry).
|
|
20
|
+
*
|
|
21
|
+
* `isAffixLineCramped` is that judgment as a pure function — unit-test
|
|
22
|
+
* pin, mutation target. HkInput re-runs it from its shared
|
|
23
|
+
* ResizeObserver (affix widths + the box's own clientWidth) and stamps
|
|
24
|
+
* `data-affix-cramped` on CENTERED non-textarea boxes when it fires;
|
|
25
|
+
* the sheet then switches the element padding and the
|
|
26
|
+
* placeholder-marquee window to the per-side reservation — byte-for-
|
|
27
|
+
* byte the arithmetic of an explicit `align="start"` / `align="end"`
|
|
28
|
+
* box. Only the RESERVATION degrades: `text-align` stays centered, and
|
|
29
|
+
* explicit alignments never carry the marker, so their behavior is
|
|
30
|
+
* untouched.
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Base horizontal padding of the input element, mirroring the sheet's
|
|
35
|
+
* `var(--space-12)` (0.75rem at the default 16px root). The predicate
|
|
36
|
+
* is a coarse threshold, not a layout measurement — the nominal pixel
|
|
37
|
+
* value is all it needs, so rem drift under a non-default root size
|
|
38
|
+
* (a few px) cannot flip a desktop-scale box.
|
|
39
|
+
*/
|
|
40
|
+
export const AFFIX_BASE_PAD_PX = 12;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Whether the symmetric centered affix reservation would crush the
|
|
44
|
+
* input line. Fires exactly when the box cannot fit
|
|
45
|
+
* `3 × max(startW, endW) + 2 × base` — i.e. when the line the
|
|
46
|
+
* symmetric reservation leaves would be strictly narrower than the
|
|
47
|
+
* widest affix that caused it. Two deliberate non-cases:
|
|
48
|
+
* - no affixes (`widest <= 0`): the reservation is zero either way,
|
|
49
|
+
* there is nothing to degrade;
|
|
50
|
+
* - no measured box width (`boxW <= 0`, NaN included): SSR, the pre-
|
|
51
|
+
* mount window and `display:none` all report zero, and speculative
|
|
52
|
+
* geometry must not win over the published default — the shared
|
|
53
|
+
* ResizeObserver delivers a real width before first paint, and the
|
|
54
|
+
* marker follows it.
|
|
55
|
+
*/
|
|
56
|
+
export function isAffixLineCramped(
|
|
57
|
+
startW: number,
|
|
58
|
+
endW: number,
|
|
59
|
+
boxW: number,
|
|
60
|
+
): boolean {
|
|
61
|
+
const widest = Math.max(startW, endW);
|
|
62
|
+
if (!(widest > 0) || !(boxW > 0)) return false;
|
|
63
|
+
return boxW < 3 * widest + 2 * AFFIX_BASE_PAD_PX;
|
|
64
|
+
}
|