@glasshome/ui 1.35.0 → 1.35.1

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.
@@ -4,4 +4,5 @@ declare const RadioGroup: Component<ComponentProps<typeof RadioGroupPrimitive>>;
4
4
  declare const RadioGroupItem: Component<ComponentProps<typeof RadioGroupPrimitive.Item> & {
5
5
  showControl?: boolean;
6
6
  }>;
7
- export { RadioGroup, RadioGroupItem };
7
+ declare function isItemActivation(event: MouseEvent): boolean;
8
+ export { isItemActivation, RadioGroup, RadioGroupItem };
@@ -16,9 +16,13 @@ export declare function RowActions(props: {
16
16
  deleteDisabled?: boolean;
17
17
  deleteTitle?: string;
18
18
  showDelete?: boolean;
19
+ /** What the row is, so each button is named for it: "Edit Kitchen", "Delete Kitchen". */
20
+ name?: string;
19
21
  }): JSX.Element;
22
+ /** `for` names one control by the label; without it the label names the group of controls. */
20
23
  export declare function LabeledField(props: {
21
24
  label: string;
25
+ for?: string;
22
26
  children: JSX.Element;
23
27
  }): JSX.Element;
24
28
  export declare function LabeledIconPicker(props: {
@@ -0,0 +1,2 @@
1
+ export declare function installHappyDomFidelity(): void;
2
+ export declare function shadowOf(host: Element | null | undefined): ShadowRoot | undefined;
@@ -1,3 +1,4 @@
1
1
  export { installSettledAnimations } from "./animations.js";
2
2
  export { useFakeTime, useSystemTime } from "./fake-time.js";
3
3
  export { installDenyFetch } from "./deny-fetch.js";
4
+ export { installHappyDomFidelity, shadowOf } from "./happy-dom-fidelity.js";
@@ -36,4 +36,67 @@ function o() {
36
36
  });
37
37
  }
38
38
  //#endregion
39
- export { o as installDenyFetch, r as installSettledAnimations, i as useFakeTime, a as useSystemTime };
39
+ //#region src/testing/happy-dom-fidelity.ts
40
+ var s = Symbol.for("glasshome.happyDomFidelity"), c = Symbol.for("glasshome.shadowRoots");
41
+ function l(e, t) {
42
+ let n = Reflect.getOwnPropertyDescriptor(e, t)?.get;
43
+ if (typeof n != "function") throw Error(`happy-dom's Event has no ${t} getter`);
44
+ return (e) => Reflect.apply(n, e, []);
45
+ }
46
+ function u(e) {
47
+ let t = [];
48
+ for (let n = e instanceof Node ? e.getRootNode() : void 0; n instanceof ShadowRoot; n = n.host.getRootNode()) t.push(n);
49
+ return t;
50
+ }
51
+ function d(e, t) {
52
+ let n = u(t), r = e;
53
+ for (; r instanceof Node;) {
54
+ let e = r.getRootNode();
55
+ if (!(e instanceof ShadowRoot) || n.includes(e)) return r;
56
+ r = e.host;
57
+ }
58
+ return r;
59
+ }
60
+ function f(e, t) {
61
+ let n = u(t);
62
+ return u(e).some((e) => e.mode === "closed" && !n.includes(e));
63
+ }
64
+ function p() {
65
+ let e = Object.getOwnPropertySymbols(new Event("probe")).find((e) => e.description === "dispatching");
66
+ if (!e) throw Error("happy-dom's Event has no dispatching flag");
67
+ return (t) => Reflect.get(t, e) === !0;
68
+ }
69
+ function m() {
70
+ let e = Event.prototype, t = Reflect.get(e, "composedPath"), n = l(e, "target"), r = l(e, "currentTarget"), i = p();
71
+ e.composedPath = function() {
72
+ if (!i(this)) return [];
73
+ let e = t.call(this), n = r(this);
74
+ return n ? e.filter((e) => !f(e, n)) : e;
75
+ }, Object.defineProperty(e, "target", {
76
+ configurable: !0,
77
+ get() {
78
+ let e = n(this), t = r(this);
79
+ return t ? d(e, t) : i(this) ? e : !this.composed && u(e).length > 0 ? null : d(e, null);
80
+ }
81
+ });
82
+ }
83
+ function h() {
84
+ let e = /* @__PURE__ */ new WeakMap();
85
+ Element.prototype[c] = e;
86
+ let t = Reflect.get(Element.prototype, "attachShadow");
87
+ Element.prototype.attachShadow = function(n) {
88
+ let r = t.call(this, n);
89
+ return e.set(this, r), r;
90
+ };
91
+ }
92
+ function g() {
93
+ let e = Event.prototype;
94
+ e[s] || (e[s] = !0, m(), h());
95
+ }
96
+ function _(e) {
97
+ let t = Element.prototype[c];
98
+ if (!t) throw Error("shadowOf needs installHappyDomFidelity() in the suite's setup");
99
+ return e ? t.get(e) : void 0;
100
+ }
101
+ //#endregion
102
+ export { o as installDenyFetch, g as installHappyDomFidelity, r as installSettledAnimations, _ as shadowOf, i as useFakeTime, a as useSystemTime };
@@ -181,6 +181,7 @@ function xe() {
181
181
  return typeof ClipboardItem < "u" && typeof navigator.clipboard?.write == "function";
182
182
  }
183
183
  async function Se(e, t) {
184
+ t.catch(() => {});
184
185
  try {
185
186
  return await navigator.clipboard.write([new ClipboardItem({ [e]: t })]), !0;
186
187
  } catch {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@glasshome/ui",
3
- "version": "1.35.0",
3
+ "version": "1.35.1",
4
4
  "description": "SolidJS component library for GlassHome, built on Kobalte",
5
5
  "keywords": [
6
6
  "components",
@@ -112,19 +112,20 @@
112
112
  "@tailwindcss/vite": "^4.1.13",
113
113
  "@types/bun": "^1.4.0",
114
114
  "@types/node": "^25.2.2",
115
+ "@vitest/browser-playwright": "4.1.11",
115
116
  "fallow": "3.17.0",
116
117
  "happy-dom": "^20.14.0",
117
118
  "oxfmt": "0.65.0",
118
119
  "oxlint": "1.81.0",
119
120
  "oxlint-tsgolint": "7.0.2001",
120
- "playwright": "^1.60.0",
121
+ "playwright": "1.63.0",
121
122
  "publint": "^0.3.21",
122
123
  "tailwindcss": "^4.1.13",
123
124
  "tw-animate-css": "^1.4.0",
124
125
  "typescript": "^7.0.2",
125
126
  "vite": "^8.1.0",
126
127
  "vite-plugin-solid": "^2.11.12",
127
- "vitest": "^4.1.10"
128
+ "vitest": "4.1.11"
128
129
  },
129
130
  "peerDependencies": {
130
131
  "solid-js": "^1.9.9",
@@ -41,6 +41,8 @@ function canWriteItems(): boolean {
41
41
  }
42
42
 
43
43
  async function writeItem(type: string, data: Promise<Blob>): Promise<boolean> {
44
+ // A write refused before it reads the data leaves a rejecting data promise unhandled.
45
+ data.catch(() => {});
44
46
  try {
45
47
  await navigator.clipboard.write([new ClipboardItem({ [type]: data })]);
46
48
  return true;
@@ -42,6 +42,7 @@ export function AreaPicker(props: AreaPickerProps) {
42
42
  const data = useEntityData();
43
43
  const [open, setOpen] = createSignal(false);
44
44
  const [search, setSearch] = createSignal("");
45
+ let searchRef: HTMLInputElement | undefined;
45
46
 
46
47
  const areas = data.useAreas();
47
48
 
@@ -171,11 +172,18 @@ export function AreaPicker(props: AreaPickerProps) {
171
172
  </PickerTrigger>
172
173
  </PopoverAnchor>
173
174
  <PopoverContent
174
- onOpenAutoFocus={(e) => e.preventDefault()}
175
+ onOpenAutoFocus={(e) => {
176
+ e.preventDefault();
177
+ // preventScroll: the panel is portalled at (0,0) until the popper places it.
178
+ searchRef?.focus({ preventScroll: true });
179
+ }}
175
180
  onInteractOutside={() => setOpen(false)}
176
181
  >
177
182
  <div class="flex flex-col">
178
183
  <PickerSearch
184
+ inputRef={(el) => {
185
+ searchRef = el;
186
+ }}
179
187
  value={search()}
180
188
  onValueChange={setSearch}
181
189
  placeholder="Search areas..."
@@ -20,6 +20,7 @@ export function acquireScrollLock(): void {
20
20
  if (refcount > 1) return;
21
21
  if (typeof document === "undefined") return;
22
22
 
23
+ document.documentElement.setAttribute("data-page-covered", "");
23
24
  const body = document.body;
24
25
  savedBodyStyles = {
25
26
  position: body.style.position,
@@ -47,6 +48,7 @@ export function releaseScrollLock(): void {
47
48
  if (refcount > 0) return;
48
49
  if (typeof document === "undefined" || !savedBodyStyles) return;
49
50
 
51
+ document.documentElement.removeAttribute("data-page-covered");
50
52
  const body = document.body;
51
53
  const wasIOS = body.style.position === "fixed";
52
54
 
@@ -277,7 +277,14 @@ function ImageGallery(props: ImagePickerProps & { store: MediaStore | undefined
277
277
  </Show>
278
278
  </PickerTrigger>
279
279
  </PopoverAnchor>
280
- <PopoverContent class="min-w-72" onInteractOutside={() => setOpen(false)}>
280
+ <PopoverContent
281
+ class="min-w-72"
282
+ onInteractOutside={(event) => {
283
+ // The delete confirmation takes focus; the gallery stays open to show the result.
284
+ if (pendingDelete()) event.preventDefault();
285
+ else setOpen(false);
286
+ }}
287
+ >
281
288
  {/* The panel owns no padding: the gallery body owns its own inset. */}
282
289
  <div data-slot="image-picker-body" class="flex flex-col gap-3 p-3">
283
290
  <Show when={error()}>
@@ -15,7 +15,7 @@ import { cn } from "../lib/utils.js";
15
15
  import { Icon } from "./icon.js";
16
16
  import { Ornament } from "./ornament.js";
17
17
  import { PickerRow } from "./picker-row.js";
18
- import { RadioGroup, RadioGroupItem } from "./radio-group.js";
18
+ import { isItemActivation, RadioGroup, RadioGroupItem } from "./radio-group.js";
19
19
 
20
20
  /* Tone without .glass-tint: the card holds body copy, which must stay foreground-coloured. */
21
21
  const OPTION_CARD_CHROME = `${CARD_SURFACE} group/option-card relative cursor-pointer overflow-hidden rounded-xl transition-glass duration-200 [&:not([style*=--glass-tone])]:[--glass-tone:var(--primary)] [--glass-wash:9%] hover:[--glass-wash:16%] has-[:focus-visible]:[--glass-edge:var(--ring)] has-[:focus-visible]:ring-[3px] has-[:focus-visible]:ring-ring/50 data-[checked]:[--glass-wash:30%] data-[checked]:[--glass-edge:oklch(from_var(--glass-tone)_l_c_h/0.75)] data-[disabled]:cursor-not-allowed data-[disabled]:opacity-50`;
@@ -146,7 +146,9 @@ export function OptionCard(props: {
146
146
  value={props.value}
147
147
  disabled={props.disabled}
148
148
  showControl={false}
149
- onClick={() => !props.disabled && props.onPick?.()}
149
+ onClick={(event: MouseEvent) =>
150
+ !props.disabled && isItemActivation(event) && props.onPick?.()
151
+ }
150
152
  class="relative w-full cursor-pointer overflow-hidden rounded-[inherit] text-left"
151
153
  >
152
154
  {/* On the header row, not the card: a grown card keeps its rows clear. */}
@@ -36,6 +36,7 @@ export function PickerSearch(props: PickerSearchProps) {
36
36
  "inputRef",
37
37
  "size",
38
38
  ]);
39
+ let input: HTMLInputElement | undefined;
39
40
  return (
40
41
  <div
41
42
  data-slot="picker-search"
@@ -53,7 +54,10 @@ export function PickerSearch(props: PickerSearchProps) {
53
54
  aria-hidden="true"
54
55
  />
55
56
  <input
56
- ref={local.inputRef}
57
+ ref={(el) => {
58
+ input = el;
59
+ local.inputRef?.(el);
60
+ }}
57
61
  data-slot="picker-search-input"
58
62
  type="text"
59
63
  value={local.value ?? ""}
@@ -70,7 +74,10 @@ export function PickerSearch(props: PickerSearchProps) {
70
74
  data-slot="picker-search-clear"
71
75
  aria-label={local.clearLabel}
72
76
  class="text-muted-foreground hover:text-foreground shrink-0 rounded-sm p-1 transition-colors"
73
- onClick={() => local.onValueChange?.("")}
77
+ onClick={() => {
78
+ local.onValueChange?.("");
79
+ input?.focus();
80
+ }}
74
81
  >
75
82
  <Icon icon="mdi:close-circle" width={16} height={16} />
76
83
  </button>
@@ -2,7 +2,7 @@ import type { JSX } from "solid-js";
2
2
  import { Show } from "solid-js";
3
3
  import { cn } from "../lib/utils.js";
4
4
  import { Icon } from "./icon.js";
5
- import { RadioGroup, RadioGroupItem } from "./radio-group.js";
5
+ import { isItemActivation, RadioGroup, RadioGroupItem } from "./radio-group.js";
6
6
 
7
7
  const COLUMNS = { 2: "grid-cols-2", 3: "grid-cols-3", 4: "grid-cols-4" } as const;
8
8
 
@@ -59,7 +59,9 @@ export function PreviewTile(props: {
59
59
  value={props.value}
60
60
  disabled={props.disabled}
61
61
  showControl={false}
62
- onClick={() => !props.disabled && props.onPick?.()}
62
+ onClick={(event: MouseEvent) =>
63
+ !props.disabled && isItemActivation(event) && props.onPick?.()
64
+ }
63
65
  class={cn(
64
66
  "group/preview-tile min-w-0 [&_[data-slot=radio-group-item-content]]:flex [&_[data-slot=radio-group-item-content]]:flex-col [&_[data-slot=radio-group-item-content]]:gap-1.5 [&_[data-slot=radio-group-item-label]]:min-w-0",
65
67
  props.class,
@@ -77,4 +77,9 @@ const RadioGroupItem: Component<
77
77
  );
78
78
  };
79
79
 
80
- export { RadioGroup, RadioGroupItem };
80
+ // A press on the label reaches the item twice: once itself, once as the input click it forwards.
81
+ function isItemActivation(event: MouseEvent): boolean {
82
+ return event.target instanceof HTMLInputElement;
83
+ }
84
+
85
+ export { isItemActivation, RadioGroup, RadioGroupItem };
@@ -1,5 +1,14 @@
1
1
  import type { JSONSchema7 } from "json-schema";
2
- import { createMemo, createSignal, For, Index, Match, Show, Switch as SwitchFlow } from "solid-js";
2
+ import {
3
+ createMemo,
4
+ createSignal,
5
+ createUniqueId,
6
+ For,
7
+ Index,
8
+ Match,
9
+ Show,
10
+ Switch as SwitchFlow,
11
+ } from "solid-js";
3
12
  import { FIELD_CHROME } from "../lib/input-classes.js";
4
13
  import { SETTLE_MOTION } from "../lib/motion-classes.js";
5
14
  import { cn } from "../lib/utils.js";
@@ -205,13 +214,14 @@ export function SchemaForm(props: SchemaFormProps) {
205
214
  const updateField = (key: string, value: unknown) => {
206
215
  props.onChange({ ...props.data, [key]: value });
207
216
  };
217
+ const formId = createUniqueId();
208
218
 
209
219
  return (
210
220
  <div class={cn("flex w-full min-w-0 flex-col gap-6", props.class)} data-slot="schema-form">
211
221
  <For each={properties()}>
212
222
  {([key, prop]) => (
213
223
  <LabeledField
214
- id={key}
224
+ id={`${formId}-${key}`}
215
225
  name={key}
216
226
  prop={prop}
217
227
  value={props.data[key]}
@@ -671,7 +681,10 @@ function ListControl(props: FieldProps) {
671
681
  alt=""
672
682
  decoding="async"
673
683
  class="absolute inset-0 h-full w-full object-cover"
674
- onError={() => setBrokenThumbs((broken) => new Set(broken).add(url()))}
684
+ onError={(event) => {
685
+ const failed = event.currentTarget.getAttribute("src");
686
+ if (failed) setBrokenThumbs((broken) => new Set(broken).add(failed));
687
+ }}
675
688
  />
676
689
  )}
677
690
  </Show>
@@ -34,10 +34,19 @@ export function RowActions(props: {
34
34
  deleteDisabled?: boolean;
35
35
  deleteTitle?: string;
36
36
  showDelete?: boolean;
37
+ /** What the row is, so each button is named for it: "Edit Kitchen", "Delete Kitchen". */
38
+ name?: string;
37
39
  }) {
40
+ const named = (verb: string) => (props.name ? `${verb} ${props.name}` : verb);
38
41
  return (
39
42
  <div data-slot="row-actions" class="flex items-center gap-1">
40
- <Button variant="ghost" size="icon" class="size-8" onClick={props.onEdit}>
43
+ <Button
44
+ variant="ghost"
45
+ size="icon"
46
+ class="size-8"
47
+ onClick={props.onEdit}
48
+ aria-label={named("Edit")}
49
+ >
41
50
  <Icon icon="lucide:pencil" width={14} height={14} />
42
51
  </Button>
43
52
  <Show when={props.showDelete ?? true}>
@@ -48,6 +57,7 @@ export function RowActions(props: {
48
57
  onClick={props.onDelete}
49
58
  disabled={props.deleteDisabled}
50
59
  title={props.deleteTitle}
60
+ aria-label={named("Delete")}
51
61
  >
52
62
  <Icon icon="lucide:trash-2" width={14} height={14} />
53
63
  </Button>
@@ -56,12 +66,14 @@ export function RowActions(props: {
56
66
  );
57
67
  }
58
68
 
59
- export function LabeledField(props: { label: string; children: JSX.Element }) {
69
+ /** `for` names one control by the label; without it the label names the group of controls. */
70
+ export function LabeledField(props: { label: string; for?: string; children: JSX.Element }) {
71
+ const id = createUniqueId();
60
72
  return (
61
- <div data-slot="labeled-field" class="flex flex-col gap-1">
62
- <p data-slot="labeled-field-label" class="text-sm font-medium">
73
+ <div data-slot="labeled-field" role="group" aria-labelledby={id} class="flex flex-col gap-1">
74
+ <label id={id} for={props.for} data-slot="labeled-field-label" class="text-sm font-medium">
63
75
  {props.label}
64
- </p>
76
+ </label>
65
77
  {props.children}
66
78
  </div>
67
79
  );
@@ -93,9 +105,11 @@ export function LabeledInput(props: {
93
105
  onInput: (value: string) => void;
94
106
  placeholder?: string;
95
107
  }) {
108
+ const id = createUniqueId();
96
109
  return (
97
- <LabeledField label={props.label}>
110
+ <LabeledField label={props.label} for={id}>
98
111
  <Input
112
+ id={id}
99
113
  value={props.value}
100
114
  onInput={(e) => props.onInput(e.currentTarget.value)}
101
115
  placeholder={props.placeholder}
@@ -9,6 +9,34 @@
9
9
 
10
10
  @custom-variant dark (&:is(.dark *));
11
11
 
12
+ /* tw-animate's enter and exit, with the filter's open end written out: WebKit 26 on Linux kills a page animating a filter into an implicit none. */
13
+ @theme inline {
14
+ @keyframes enter {
15
+ from {
16
+ opacity: var(--tw-enter-opacity, 1);
17
+ transform: translate3d(var(--tw-enter-translate-x, 0), var(--tw-enter-translate-y, 0), 0)
18
+ scale3d(var(--tw-enter-scale, 1), var(--tw-enter-scale, 1), var(--tw-enter-scale, 1))
19
+ rotate(var(--tw-enter-rotate, 0));
20
+ filter: blur(var(--tw-enter-blur, 0));
21
+ }
22
+ to {
23
+ filter: blur(0);
24
+ }
25
+ }
26
+ @keyframes exit {
27
+ from {
28
+ filter: blur(0);
29
+ }
30
+ to {
31
+ opacity: var(--tw-exit-opacity, 1);
32
+ transform: translate3d(var(--tw-exit-translate-x, 0), var(--tw-exit-translate-y, 0), 0)
33
+ scale3d(var(--tw-exit-scale, 1), var(--tw-exit-scale, 1), var(--tw-exit-scale, 1))
34
+ rotate(var(--tw-exit-rotate, 0));
35
+ filter: blur(var(--tw-exit-blur, 0));
36
+ }
37
+ }
38
+ }
39
+
12
40
  /* Typed + inherits:false: a knob never leaks into a nested glass element, each
13
41
  * element's calc() resolves against its own value, and typed knobs animate. */
14
42
  @property --glass-tone {
@@ -639,6 +667,10 @@
639
667
  animation: none;
640
668
  }
641
669
  }
670
+ /* Ambient loops under a modal's blurred scrim would make the browser re-blur the whole page every frame. */
671
+ :root[data-page-covered] :is(:where(.glass-edge-orbit) > *, .animate-spin-slow, .animate-float) {
672
+ animation-play-state: paused;
673
+ }
642
674
 
643
675
  /**
644
676
  * Consistent, theme-aware overlay scrollbar across browsers. Firefox uses
@@ -0,0 +1,105 @@
1
+ const INSTALLED = Symbol.for("glasshome.happyDomFidelity");
2
+ const RECORDED = Symbol.for("glasshome.shadowRoots");
3
+
4
+ type Recorder = { [RECORDED]?: WeakMap<Element, ShadowRoot> };
5
+
6
+ function getterOf(proto: object, name: string): (event: Event) => unknown {
7
+ const get: unknown = Reflect.getOwnPropertyDescriptor(proto, name)?.get;
8
+ if (typeof get !== "function") throw new Error(`happy-dom's Event has no ${name} getter`);
9
+ return (event) => Reflect.apply(get, event, []);
10
+ }
11
+
12
+ function rootsAround(target: unknown): ShadowRoot[] {
13
+ const roots: ShadowRoot[] = [];
14
+ for (
15
+ let root = target instanceof Node ? target.getRootNode() : undefined;
16
+ root instanceof ShadowRoot;
17
+ root = root.host.getRootNode()
18
+ ) {
19
+ roots.push(root);
20
+ }
21
+ return roots;
22
+ }
23
+
24
+ function retarget(target: unknown, viewer: unknown): unknown {
25
+ const viewerRoots = rootsAround(viewer);
26
+ let node = target;
27
+ while (node instanceof Node) {
28
+ const root = node.getRootNode();
29
+ if (!(root instanceof ShadowRoot) || viewerRoots.includes(root)) return node;
30
+ node = root.host;
31
+ }
32
+ return node;
33
+ }
34
+
35
+ function hiddenFrom(node: unknown, viewer: unknown): boolean {
36
+ const viewerRoots = rootsAround(viewer);
37
+ return rootsAround(node).some((root) => root.mode === "closed" && !viewerRoots.includes(root));
38
+ }
39
+
40
+ function dispatchFlag(): (event: Event) => boolean {
41
+ const symbol = Object.getOwnPropertySymbols(new Event("probe")).find(
42
+ (key) => key.description === "dispatching",
43
+ );
44
+ if (!symbol) throw new Error("happy-dom's Event has no dispatching flag");
45
+ return (event) => Reflect.get(event, symbol) === true;
46
+ }
47
+
48
+ function installEventRetargeting(): void {
49
+ const proto = Event.prototype;
50
+ const composedPath = Reflect.get(proto, "composedPath") as (this: Event) => EventTarget[];
51
+ const rawTarget = getterOf(proto, "target");
52
+ // Solid redefines `currentTarget` on the events it delegates; the listener's own is on the prototype.
53
+ const rawCurrentTarget = getterOf(proto, "currentTarget");
54
+ const dispatching = dispatchFlag();
55
+
56
+ proto.composedPath = function (this: Event): EventTarget[] {
57
+ if (!dispatching(this)) return [];
58
+ const path = composedPath.call(this);
59
+ const viewer = rawCurrentTarget(this);
60
+ // happy-dom builds its dispatch path from this before the first listener runs.
61
+ if (!viewer) return path;
62
+ return path.filter((node) => !hiddenFrom(node, viewer));
63
+ };
64
+
65
+ Object.defineProperty(proto, "target", {
66
+ configurable: true,
67
+ get(this: Event) {
68
+ const target = rawTarget(this);
69
+ const viewer = rawCurrentTarget(this);
70
+ if (viewer) return retarget(target, viewer);
71
+ if (dispatching(this)) return target;
72
+ if (!this.composed && rootsAround(target).length > 0) return null;
73
+ return retarget(target, null);
74
+ },
75
+ });
76
+ }
77
+
78
+ function installShadowRecorder(): void {
79
+ const recorded = new WeakMap<Element, ShadowRoot>();
80
+ (Element.prototype as Recorder)[RECORDED] = recorded;
81
+ const attach = Reflect.get(Element.prototype, "attachShadow") as (
82
+ this: Element,
83
+ init: ShadowRootInit,
84
+ ) => ShadowRoot;
85
+ Element.prototype.attachShadow = function (this: Element, init: ShadowRootInit) {
86
+ const root = attach.call(this, init);
87
+ recorded.set(this, root);
88
+ return root;
89
+ };
90
+ }
91
+
92
+ export function installHappyDomFidelity(): void {
93
+ // A shared-module suite runs every file's setup against the same window.
94
+ const marked = Event.prototype as { [INSTALLED]?: true };
95
+ if (marked[INSTALLED]) return;
96
+ marked[INSTALLED] = true;
97
+ installEventRetargeting();
98
+ installShadowRecorder();
99
+ }
100
+
101
+ export function shadowOf(host: Element | null | undefined): ShadowRoot | undefined {
102
+ const recorded = (Element.prototype as Recorder)[RECORDED];
103
+ if (!recorded) throw new Error("shadowOf needs installHappyDomFidelity() in the suite's setup");
104
+ return host ? recorded.get(host) : undefined;
105
+ }
@@ -1,3 +1,4 @@
1
1
  export { installSettledAnimations } from "./animations.js";
2
2
  export { useFakeTime, useSystemTime } from "./fake-time.js";
3
3
  export { installDenyFetch } from "./deny-fetch.js";
4
+ export { installHappyDomFidelity, shadowOf } from "./happy-dom-fidelity.js";