@f-ewald/components 1.42.2 → 1.43.0

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.
@@ -0,0 +1,87 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ import { LitElement, css, html, nothing } from "lit";
8
+ import { customElement, property } from "lit/decorators.js";
9
+ import { tokens } from "./tokens.js";
10
+ /**
11
+ * Inline icon for a named kind (e.g. a service, a library, an external
12
+ * package), looked up in a shared `kinds` map so tables, lists, and search
13
+ * results show the same icon and color as a `dag-graph` legend. With
14
+ * `show-label` the kind's label follows the icon as text; otherwise the
15
+ * icon alone is exposed as an image named by the label. Renders nothing for
16
+ * a kind missing from `kinds`.
17
+ *
18
+ * @element kind-icon
19
+ */
20
+ let KindIcon = class KindIcon extends LitElement {
21
+ constructor() {
22
+ super(...arguments);
23
+ /** Key of the kind to show, looked up in `kinds`. */
24
+ this.kind = "";
25
+ /** Presentation per kind: label, color, and icon. Shareable with `dag-graph`'s `kinds`. */
26
+ this.kinds = {};
27
+ /** Square icon size in pixels: 14 inline, 18 standalone. */
28
+ this.size = 14;
29
+ /** Shows the kind's label as text after the icon. */
30
+ this.showLabel = false;
31
+ }
32
+ static { this.styles = [
33
+ tokens,
34
+ css `
35
+ :host {
36
+ display: inline-flex;
37
+ align-items: center;
38
+ gap: 0.25rem;
39
+ vertical-align: middle;
40
+ }
41
+ :host([hidden]) {
42
+ display: none;
43
+ }
44
+ .icon {
45
+ display: inline-flex;
46
+ flex: 0 0 auto;
47
+ line-height: 0;
48
+ color: var(--kind-icon-color, var(--ui-primary, #4f46e5));
49
+ }
50
+ `,
51
+ ]; }
52
+ render() {
53
+ const style = this.kinds[this.kind];
54
+ if (!style)
55
+ return nothing;
56
+ const label = style.label ?? "";
57
+ const visibleLabel = this.showLabel && label;
58
+ const named = !visibleLabel && label;
59
+ return html `${style.icon
60
+ ? html `<span
61
+ class="icon"
62
+ style=${style.color ? `--kind-icon-color: ${style.color}` : nothing}
63
+ role=${named ? "img" : nothing}
64
+ aria-label=${named ? label : nothing}
65
+ aria-hidden=${named ? nothing : "true"}
66
+ >${style.icon(this.size)}</span
67
+ >`
68
+ : nothing}${visibleLabel ? html `<span class="label">${label}</span>` : nothing}`;
69
+ }
70
+ };
71
+ __decorate([
72
+ property({ reflect: true })
73
+ ], KindIcon.prototype, "kind", void 0);
74
+ __decorate([
75
+ property({ attribute: false })
76
+ ], KindIcon.prototype, "kinds", void 0);
77
+ __decorate([
78
+ property({ type: Number })
79
+ ], KindIcon.prototype, "size", void 0);
80
+ __decorate([
81
+ property({ type: Boolean, reflect: true, attribute: "show-label" })
82
+ ], KindIcon.prototype, "showLabel", void 0);
83
+ KindIcon = __decorate([
84
+ customElement("kind-icon")
85
+ ], KindIcon);
86
+ export { KindIcon };
87
+ //# sourceMappingURL=kind-icon.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"kind-icon.js","sourceRoot":"","sources":["../src/kind-icon.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,GAAG,EAAE,IAAI,EAAE,OAAO,EAA0B,MAAM,KAAK,CAAC;AAC7E,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAYrC;;;;;;;;;GASG;AAEI,IAAM,QAAQ,GAAd,MAAM,QAAS,SAAQ,UAAU;IAAjC;;QAsBL,qDAAqD;QACxB,SAAI,GA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B,QAAQ,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;uCAA2C;AAE9C;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;sCAAoB;AAEsB;IAApE,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,YAAY,EAAE,CAAC;2CAAmB;AA7B5E,QAAQ;IADpB,aAAa,CAAC,WAAW,CAAC;GACd,QAAQ,CAgDpB","sourcesContent":["import { LitElement, css, html, nothing, type SVGTemplateResult } from \"lit\";\nimport { customElement, property } from \"lit/decorators.js\";\nimport { tokens } from \"./tokens.js\";\n\n/** Presentation of one kind. `dag-graph`'s `DagNodeKind` satisfies this, so one map can drive both. */\nexport interface KindIconStyle {\n /** Name of the kind: the visible label with `show-label`, otherwise the icon's accessible name. */\n label?: string;\n /** Icon color (any CSS color); defaults to `--ui-primary`. */\n color?: string;\n /** Icon factory, called with `size` — e.g. one of the package's `icon*` exports. */\n icon?: (size: number) => SVGTemplateResult;\n}\n\n/**\n * Inline icon for a named kind (e.g. a service, a library, an external\n * package), looked up in a shared `kinds` map so tables, lists, and search\n * results show the same icon and color as a `dag-graph` legend. With\n * `show-label` the kind's label follows the icon as text; otherwise the\n * icon alone is exposed as an image named by the label. Renders nothing for\n * a kind missing from `kinds`.\n *\n * @element kind-icon\n */\n@customElement(\"kind-icon\")\nexport class KindIcon extends LitElement {\n static override styles = [\n tokens,\n css`\n :host {\n display: inline-flex;\n align-items: center;\n gap: 0.25rem;\n vertical-align: middle;\n }\n :host([hidden]) {\n display: none;\n }\n .icon {\n display: inline-flex;\n flex: 0 0 auto;\n line-height: 0;\n color: var(--kind-icon-color, var(--ui-primary, #4f46e5));\n }\n `,\n ];\n\n /** Key of the kind to show, looked up in `kinds`. */\n @property({ reflect: true }) kind = \"\";\n /** Presentation per kind: label, color, and icon. Shareable with `dag-graph`'s `kinds`. */\n @property({ attribute: false }) kinds: Record<string, KindIconStyle> = {};\n /** Square icon size in pixels: 14 inline, 18 standalone. */\n @property({ type: Number }) size: 14 | 18 = 14;\n /** Shows the kind's label as text after the icon. */\n @property({ type: Boolean, reflect: true, attribute: \"show-label\" }) showLabel = false;\n\n override render() {\n const style = this.kinds[this.kind];\n if (!style) return nothing;\n const label = style.label ?? \"\";\n const visibleLabel = this.showLabel && label;\n const named = !visibleLabel && label;\n return html`${style.icon\n ? html`<span\n class=\"icon\"\n style=${style.color ? `--kind-icon-color: ${style.color}` : nothing}\n role=${named ? \"img\" : nothing}\n aria-label=${named ? label : nothing}\n aria-hidden=${named ? nothing : \"true\"}\n >${style.icon(this.size)}</span\n >`\n : nothing}${visibleLabel ? html`<span class=\"label\">${label}</span>` : nothing}`;\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n \"kind-icon\": KindIcon;\n }\n}\n"]}
@@ -0,0 +1,49 @@
1
+ import { LitElement, type PropertyValues } from "lit";
2
+ /** Preferred side of the trigger; the tooltip flips when that side lacks room. */
3
+ export type UiTooltipPlacement = "top" | "bottom";
4
+ /**
5
+ * Hover and focus tooltip for its default-slot trigger. The `content` slot
6
+ * holds the tooltip body — plain text or rich markup such as a list. It
7
+ * appears after `show-delay` on hover and at once on keyboard focus, stays
8
+ * open while the pointer is over the tooltip itself, and closes on Escape,
9
+ * blur, or when the pointer leaves. It renders in the top layer, so
10
+ * scrolling or `overflow: hidden` ancestors never clip it.
11
+ *
12
+ * The trigger is described by the content (`aria-describedby`). A trigger
13
+ * with nothing focusable inside (e.g. plain text) makes the tooltip host
14
+ * focusable so keyboard users can reach the description too. ARIA references
15
+ * can't cross shadow roots, so when the trigger is a custom element whose
16
+ * focusable control lives in its own shadow root, screen readers won't
17
+ * announce the description on focus; prefer a native trigger such as
18
+ * `<button>` when that matters.
19
+ *
20
+ * @element ui-tooltip
21
+ * @slot - The trigger the tooltip describes.
22
+ * @slot content - The tooltip body.
23
+ * @csspart tooltip - The floating tooltip surface.
24
+ */
25
+ export declare class UiTooltip extends LitElement {
26
+ #private;
27
+ static styles: import("lit").CSSResult[];
28
+ /** Preferred side of the trigger; flips to the other side when this one lacks room. */
29
+ placement: UiTooltipPlacement;
30
+ /** Hover delay in milliseconds before the tooltip appears; keyboard focus shows it at once. */
31
+ showDelay: number;
32
+ /** Suppresses the tooltip and closes it if open. */
33
+ disabled: boolean;
34
+ private _open;
35
+ private _tooltip;
36
+ constructor();
37
+ /** Whether the tooltip is currently showing. */
38
+ get open(): boolean;
39
+ disconnectedCallback(): void;
40
+ protected willUpdate(changed: PropertyValues<this>): void;
41
+ protected updated(changed: PropertyValues): void;
42
+ render(): import("lit-html").TemplateResult<1>;
43
+ }
44
+ declare global {
45
+ interface HTMLElementTagNameMap {
46
+ "ui-tooltip": UiTooltip;
47
+ }
48
+ }
49
+ //# sourceMappingURL=ui-tooltip.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ui-tooltip.d.ts","sourceRoot":"","sources":["../src/ui-tooltip.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAa,KAAK,cAAc,EAAE,MAAM,KAAK,CAAC;AAMjE,kFAAkF;AAClF,MAAM,MAAM,kBAAkB,GAAG,KAAK,GAAG,QAAQ,CAAC;AAmBlD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,qBACa,SAAU,SAAQ,UAAU;;IACvC,OAAgB,MAAM,4BAoDpB;IAEF,uFAAuF;IAC1D,SAAS,EAAE,kBAAkB,CAAS;IACnE,+FAA+F;IAC1C,SAAS,SAAO;IACrE,oDAAoD;IACR,QAAQ,UAAS;IAEpD,OAAO,CAAC,KAAK,CAAS;IAEZ,OAAO,CAAC,QAAQ,CAAe;IAUlD,cAMC;IAED,gDAAgD;IAChD,IAAI,IAAI,IAAI,OAAO,CAElB;IAEQ,oBAAoB,IAAI,IAAI,CAIpC;IAED,UAAmB,UAAU,CAAC,OAAO,EAAE,cAAc,CAAC,IAAI,CAAC,GAAG,IAAI,CAKjE;IAED,UAAmB,OAAO,CAAC,OAAO,EAAE,cAAc,GAAG,IAAI,CAQxD;IAoIQ,MAAM,yCAOd;CACF;AAED,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,qBAAqB;QAC7B,YAAY,EAAE,SAAS,CAAC;KACzB;CACF"}
@@ -0,0 +1,317 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ import { LitElement, css, html } from "lit";
8
+ import { customElement, property, query, state } from "lit/decorators.js";
9
+ import { tokens } from "./tokens.js";
10
+ let instanceCount = 0;
11
+ /** Space kept between the trigger, the tooltip, and the viewport edges, in pixels. */
12
+ const GAP = 6;
13
+ const EDGE = 4;
14
+ /** Grace period that lets the pointer cross from the trigger onto the tooltip. */
15
+ const HIDE_DELAY = 100;
16
+ const FOCUSABLE = "a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), summary, [contenteditable], [tabindex]:not([tabindex='-1'])";
17
+ /** Whether `root` is or contains a focusable element, looking inside open shadow roots. */
18
+ function containsFocusable(root) {
19
+ if (root instanceof Element && root.matches(FOCUSABLE))
20
+ return true;
21
+ if (root.querySelector(FOCUSABLE))
22
+ return true;
23
+ const hosts = root instanceof Element ? [root, ...root.querySelectorAll("*")] : [...root.querySelectorAll("*")];
24
+ return hosts.some((el) => el.shadowRoot !== null && containsFocusable(el.shadowRoot));
25
+ }
26
+ /**
27
+ * Hover and focus tooltip for its default-slot trigger. The `content` slot
28
+ * holds the tooltip body — plain text or rich markup such as a list. It
29
+ * appears after `show-delay` on hover and at once on keyboard focus, stays
30
+ * open while the pointer is over the tooltip itself, and closes on Escape,
31
+ * blur, or when the pointer leaves. It renders in the top layer, so
32
+ * scrolling or `overflow: hidden` ancestors never clip it.
33
+ *
34
+ * The trigger is described by the content (`aria-describedby`). A trigger
35
+ * with nothing focusable inside (e.g. plain text) makes the tooltip host
36
+ * focusable so keyboard users can reach the description too. ARIA references
37
+ * can't cross shadow roots, so when the trigger is a custom element whose
38
+ * focusable control lives in its own shadow root, screen readers won't
39
+ * announce the description on focus; prefer a native trigger such as
40
+ * `<button>` when that matters.
41
+ *
42
+ * @element ui-tooltip
43
+ * @slot - The trigger the tooltip describes.
44
+ * @slot content - The tooltip body.
45
+ * @csspart tooltip - The floating tooltip surface.
46
+ */
47
+ let UiTooltip = class UiTooltip extends LitElement {
48
+ static { this.styles = [
49
+ tokens,
50
+ css `
51
+ :host {
52
+ display: inline-block;
53
+ }
54
+ :host(:focus-visible) {
55
+ outline: none;
56
+ border-radius: var(--ui-radius-sm, 0.25rem);
57
+ box-shadow: var(--ui-focus-ring, 0 0 0 3px rgb(79 70 229 / 0.35));
58
+ }
59
+ .tooltip {
60
+ position: fixed;
61
+ inset: auto;
62
+ margin: 0;
63
+ box-sizing: border-box;
64
+ max-width: min(20rem, calc(100vw - 0.5rem));
65
+ padding: 0.25rem 0.5rem;
66
+ border: 0;
67
+ border-radius: var(--ui-radius-sm, 0.25rem);
68
+ background: var(--ui-tooltip, #0f172a);
69
+ color: var(--ui-tooltip-text, #ffffff);
70
+ box-shadow: var(--ui-shadow, 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1));
71
+ font-family: var(
72
+ --ui-font,
73
+ ui-sans-serif,
74
+ system-ui,
75
+ sans-serif,
76
+ "Apple Color Emoji",
77
+ "Segoe UI Emoji",
78
+ "Segoe UI Symbol",
79
+ "Noto Color Emoji"
80
+ );
81
+ font-size: var(--ui-font-size-sm, 0.75rem);
82
+ font-weight: var(--ui-font-weight-regular, 400);
83
+ line-height: var(--ui-line-height-tight, 1.25);
84
+ text-align: start;
85
+ overflow-wrap: anywhere;
86
+ }
87
+ @media (forced-colors: active) {
88
+ :host(:focus-visible) {
89
+ outline: 2px solid CanvasText;
90
+ outline-offset: 2px;
91
+ box-shadow: none;
92
+ }
93
+ .tooltip {
94
+ border: 1px solid CanvasText;
95
+ background: Canvas;
96
+ color: CanvasText;
97
+ }
98
+ }
99
+ `,
100
+ ]; }
101
+ #showTimer;
102
+ #hideTimer;
103
+ #describedTarget;
104
+ #describedId;
105
+ #content;
106
+ #madeFocusable;
107
+ #contentId;
108
+ constructor() {
109
+ super();
110
+ /** Preferred side of the trigger; flips to the other side when this one lacks room. */
111
+ this.placement = "top";
112
+ /** Hover delay in milliseconds before the tooltip appears; keyboard focus shows it at once. */
113
+ this.showDelay = 300;
114
+ /** Suppresses the tooltip and closes it if open. */
115
+ this.disabled = false;
116
+ this._open = false;
117
+ this.#showTimer = null;
118
+ this.#hideTimer = null;
119
+ this.#describedTarget = null;
120
+ this.#describedId = null;
121
+ this.#content = null;
122
+ this.#madeFocusable = false;
123
+ this.#contentId = `ui-tooltip-content-${++instanceCount}`;
124
+ /** Escape closes the tooltip without dismissing anything else (WCAG 1.4.13). */
125
+ this.#onDocumentKeydown = (event) => {
126
+ if (event.key !== "Escape" || !this._open)
127
+ return;
128
+ event.preventDefault();
129
+ event.stopPropagation();
130
+ this.#clearTimers();
131
+ this.#setOpen(false);
132
+ };
133
+ this.#onViewportChange = () => {
134
+ if (this._open)
135
+ this.#position();
136
+ };
137
+ this.addEventListener("pointerenter", () => this.#scheduleShow(this.showDelay));
138
+ this.addEventListener("pointerleave", () => this.#scheduleHide(HIDE_DELAY, ":focus-within"));
139
+ this.addEventListener("focusin", () => this.#scheduleShow(0));
140
+ this.addEventListener("focusout", () => this.#scheduleHide(0, ":hover"));
141
+ }
142
+ /** Whether the tooltip is currently showing. */
143
+ get open() {
144
+ return this._open;
145
+ }
146
+ disconnectedCallback() {
147
+ super.disconnectedCallback();
148
+ this.#clearTimers();
149
+ this.#setOpen(false);
150
+ }
151
+ willUpdate(changed) {
152
+ if (changed.has("disabled") && this.disabled) {
153
+ this.#clearTimers();
154
+ this.#setOpen(false);
155
+ }
156
+ }
157
+ updated(changed) {
158
+ if (!changed.has("_open"))
159
+ return;
160
+ if (this._open) {
161
+ this._tooltip.showPopover();
162
+ this.#position();
163
+ return;
164
+ }
165
+ if (this._tooltip.matches(":popover-open"))
166
+ this._tooltip.hidePopover();
167
+ }
168
+ #scheduleShow(delay) {
169
+ if (this.disabled || !this.#content)
170
+ return;
171
+ this.#clearTimers();
172
+ if (this._open)
173
+ return;
174
+ if (delay <= 0) {
175
+ this.#setOpen(true);
176
+ return;
177
+ }
178
+ this.#showTimer = setTimeout(() => this.#setOpen(true), delay);
179
+ }
180
+ /** Hides after `delay` unless the host still matches `keepOpenWhile` (still hovered or focused). */
181
+ #scheduleHide(delay, keepOpenWhile) {
182
+ this.#clearTimers();
183
+ if (!this._open)
184
+ return;
185
+ const hide = () => {
186
+ if (!this.matches(keepOpenWhile))
187
+ this.#setOpen(false);
188
+ };
189
+ if (delay <= 0) {
190
+ hide();
191
+ return;
192
+ }
193
+ this.#hideTimer = setTimeout(hide, delay);
194
+ }
195
+ #clearTimers() {
196
+ if (this.#showTimer)
197
+ clearTimeout(this.#showTimer);
198
+ if (this.#hideTimer)
199
+ clearTimeout(this.#hideTimer);
200
+ this.#showTimer = null;
201
+ this.#hideTimer = null;
202
+ }
203
+ #setOpen(open) {
204
+ if (this._open === open)
205
+ return;
206
+ this._open = open;
207
+ if (open) {
208
+ document.addEventListener("keydown", this.#onDocumentKeydown, true);
209
+ window.addEventListener("scroll", this.#onViewportChange, true);
210
+ window.addEventListener("resize", this.#onViewportChange);
211
+ return;
212
+ }
213
+ document.removeEventListener("keydown", this.#onDocumentKeydown, true);
214
+ window.removeEventListener("scroll", this.#onViewportChange, true);
215
+ window.removeEventListener("resize", this.#onViewportChange);
216
+ }
217
+ /** Escape closes the tooltip without dismissing anything else (WCAG 1.4.13). */
218
+ #onDocumentKeydown;
219
+ #onViewportChange;
220
+ /** Places the tooltip beside the host, flipping sides and clamping it inside the viewport. */
221
+ #position() {
222
+ const anchor = this.getBoundingClientRect();
223
+ const tip = this._tooltip.getBoundingClientRect();
224
+ const above = anchor.top - GAP - tip.height;
225
+ const below = anchor.bottom + GAP;
226
+ const fitsAbove = above >= EDGE;
227
+ const fitsBelow = below + tip.height <= window.innerHeight - EDGE;
228
+ const top = this.placement === "top" ? (fitsAbove || !fitsBelow ? above : below) : fitsBelow || !fitsAbove ? below : above;
229
+ const centered = anchor.left + anchor.width / 2 - tip.width / 2;
230
+ const left = Math.min(Math.max(centered, EDGE), Math.max(EDGE, window.innerWidth - EDGE - tip.width));
231
+ this._tooltip.style.top = `${Math.round(top)}px`;
232
+ this._tooltip.style.left = `${Math.round(left)}px`;
233
+ this._tooltip.dataset.side = top === above ? "top" : "bottom";
234
+ }
235
+ async #onTriggerSlotChange(event) {
236
+ const slot = event.target;
237
+ const trigger = slot.assignedElements()[0];
238
+ // A Lit trigger renders its (possibly focusable) shadow content after it is slotted.
239
+ await trigger?.updateComplete;
240
+ if (trigger !== slot.assignedElements()[0])
241
+ return;
242
+ const target = trigger && containsFocusable(trigger) ? trigger : this;
243
+ this.#updateFocusability(target === this);
244
+ this.#describe(target);
245
+ }
246
+ #onContentSlotChange(event) {
247
+ const content = event.target.assignedElements()[0];
248
+ this.#content = content ?? null;
249
+ if (content && !content.id)
250
+ content.id = this.#contentId;
251
+ if (!content)
252
+ this.#setOpen(false);
253
+ this.#describe(this.#describedTarget);
254
+ }
255
+ /** Points the trigger's `aria-describedby` at the content, replacing this tooltip's previous reference. */
256
+ #describe(target) {
257
+ if (this.#describedTarget && this.#describedId) {
258
+ this.#setDescribedBy(this.#describedTarget, this.#describedIds(this.#describedTarget));
259
+ }
260
+ this.#describedTarget = target;
261
+ this.#describedId = this.#content?.id ?? null;
262
+ if (!target || !this.#describedId)
263
+ return;
264
+ this.#setDescribedBy(target, [...this.#describedIds(target), this.#describedId]);
265
+ }
266
+ /** The target's `aria-describedby` ids, minus the one this tooltip added. */
267
+ #describedIds(target) {
268
+ return (target.getAttribute("aria-describedby") ?? "")
269
+ .split(/\s+/)
270
+ .filter((value) => value && value !== this.#describedId);
271
+ }
272
+ #setDescribedBy(target, ids) {
273
+ if (ids.length)
274
+ target.setAttribute("aria-describedby", ids.join(" "));
275
+ else
276
+ target.removeAttribute("aria-describedby");
277
+ }
278
+ #updateFocusability(needed) {
279
+ if (needed && !this.hasAttribute("tabindex")) {
280
+ this.tabIndex = 0;
281
+ this.#madeFocusable = true;
282
+ return;
283
+ }
284
+ if (!needed && this.#madeFocusable) {
285
+ this.removeAttribute("tabindex");
286
+ this.#madeFocusable = false;
287
+ }
288
+ }
289
+ render() {
290
+ return html `
291
+ <slot @slotchange=${this.#onTriggerSlotChange}></slot>
292
+ <div class="tooltip" part="tooltip" role="tooltip" popover="manual">
293
+ <slot name="content" @slotchange=${this.#onContentSlotChange}></slot>
294
+ </div>
295
+ `;
296
+ }
297
+ };
298
+ __decorate([
299
+ property({ reflect: true })
300
+ ], UiTooltip.prototype, "placement", void 0);
301
+ __decorate([
302
+ property({ type: Number, attribute: "show-delay" })
303
+ ], UiTooltip.prototype, "showDelay", void 0);
304
+ __decorate([
305
+ property({ type: Boolean, reflect: true })
306
+ ], UiTooltip.prototype, "disabled", void 0);
307
+ __decorate([
308
+ state()
309
+ ], UiTooltip.prototype, "_open", void 0);
310
+ __decorate([
311
+ query(".tooltip")
312
+ ], UiTooltip.prototype, "_tooltip", void 0);
313
+ UiTooltip = __decorate([
314
+ customElement("ui-tooltip")
315
+ ], UiTooltip);
316
+ export { UiTooltip };
317
+ //# sourceMappingURL=ui-tooltip.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ui-tooltip.js","sourceRoot":"","sources":["../src/ui-tooltip.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,UAA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AAC;IAC7D,CAAC;IAED,eAAe,CAAC,MAAmB,EAAE,GAAa;QAChD,IAAI,GAAG,CAAC,MAAM;YAAE,MAAM,CAAC,YAAY,CAAC,kBAAkB,EAAE,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;;YAClE,MAAM,CAAC,eAAe,CAAC,kBAAkB,CAAC,CAAC;IAClD,CAAC;IAED,mBAAmB,CAAC,MAAe;QACjC,IAAI,MAAM,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,EAAE,CAAC;YAC7C,IAAI,CAAC,QAAQ,GAAG,CAAC,CAAC;YAClB,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC;YAC3B,OAAO;QACT,CAAC;QACD,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,cAAc,EAAE,CAAC;YACnC,IAAI,CAAC,eAAe,CAAC,UAAU,CAAC,CAAC;YACjC,IAAI,CAAC,cAAc,GAAG,KAAK,CAAC;QAC9B,CAAC;IACH,CAAC;IAEQ,MAAM;QACb,OAAO,IAAI,CAAA;0BACW,IAAI,CAAC,oBAAoB;;2CAER,IAAI,CAAC,oBAAoB;;KAE/D,CAAC;IACJ,CAAC;CACF,CAAA;AAhM8B;IAA5B,QAAQ,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;4CAAuC;AAEd;IAApD,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,YAAY,EAAE,CAAC;4CAAiB;AAEzB;IAA3C,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;2CAAkB;AAE5C;IAAhB,KAAK,EAAE;wCAAuB;AAEJ;IAA1B,KAAK,CAAC,UAAU,CAAC;2CAAgC;AAhEvC,SAAS;IADrB,aAAa,CAAC,YAAY,CAAC;GACf,SAAS,CAwPrB","sourcesContent":["import { LitElement, css, html, type PropertyValues } from \"lit\";\nimport { customElement, property, query, state } from \"lit/decorators.js\";\nimport { tokens } from \"./tokens.js\";\n\nlet instanceCount = 0;\n\n/** Preferred side of the trigger; the tooltip flips when that side lacks room. */\nexport type UiTooltipPlacement = \"top\" | \"bottom\";\n\n/** Space kept between the trigger, the tooltip, and the viewport edges, in pixels. */\nconst GAP = 6;\nconst EDGE = 4;\n/** Grace period that lets the pointer cross from the trigger onto the tooltip. */\nconst HIDE_DELAY = 100;\n\nconst FOCUSABLE =\n \"a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), summary, [contenteditable], [tabindex]:not([tabindex='-1'])\";\n\n/** Whether `root` is or contains a focusable element, looking inside open shadow roots. */\nfunction containsFocusable(root: Element | ShadowRoot): boolean {\n if (root instanceof Element && root.matches(FOCUSABLE)) return true;\n if (root.querySelector(FOCUSABLE)) return true;\n const hosts = root instanceof Element ? [root, ...root.querySelectorAll(\"*\")] : [...root.querySelectorAll(\"*\")];\n return hosts.some((el) => el.shadowRoot !== null && containsFocusable(el.shadowRoot));\n}\n\n/**\n * Hover and focus tooltip for its default-slot trigger. The `content` slot\n * holds the tooltip body — plain text or rich markup such as a list. It\n * appears after `show-delay` on hover and at once on keyboard focus, stays\n * open while the pointer is over the tooltip itself, and closes on Escape,\n * blur, or when the pointer leaves. It renders in the top layer, so\n * scrolling or `overflow: hidden` ancestors never clip it.\n *\n * The trigger is described by the content (`aria-describedby`). A trigger\n * with nothing focusable inside (e.g. plain text) makes the tooltip host\n * focusable so keyboard users can reach the description too. ARIA references\n * can't cross shadow roots, so when the trigger is a custom element whose\n * focusable control lives in its own shadow root, screen readers won't\n * announce the description on focus; prefer a native trigger such as\n * `<button>` when that matters.\n *\n * @element ui-tooltip\n * @slot - The trigger the tooltip describes.\n * @slot content - The tooltip body.\n * @csspart tooltip - The floating tooltip surface.\n */\n@customElement(\"ui-tooltip\")\nexport class UiTooltip extends LitElement {\n static override styles = [\n tokens,\n css`\n :host {\n display: inline-block;\n }\n :host(:focus-visible) {\n outline: none;\n border-radius: var(--ui-radius-sm, 0.25rem);\n box-shadow: var(--ui-focus-ring, 0 0 0 3px rgb(79 70 229 / 0.35));\n }\n .tooltip {\n position: fixed;\n inset: auto;\n margin: 0;\n box-sizing: border-box;\n max-width: min(20rem, calc(100vw - 0.5rem));\n padding: 0.25rem 0.5rem;\n border: 0;\n border-radius: var(--ui-radius-sm, 0.25rem);\n background: var(--ui-tooltip, #0f172a);\n color: var(--ui-tooltip-text, #ffffff);\n box-shadow: var(--ui-shadow, 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1));\n font-family: var(\n --ui-font,\n ui-sans-serif,\n system-ui,\n sans-serif,\n \"Apple Color Emoji\",\n \"Segoe UI Emoji\",\n \"Segoe UI Symbol\",\n \"Noto Color Emoji\"\n );\n font-size: var(--ui-font-size-sm, 0.75rem);\n font-weight: var(--ui-font-weight-regular, 400);\n line-height: var(--ui-line-height-tight, 1.25);\n text-align: start;\n overflow-wrap: anywhere;\n }\n @media (forced-colors: active) {\n :host(:focus-visible) {\n outline: 2px solid CanvasText;\n outline-offset: 2px;\n box-shadow: none;\n }\n .tooltip {\n border: 1px solid CanvasText;\n background: Canvas;\n color: CanvasText;\n }\n }\n `,\n ];\n\n /** Preferred side of the trigger; flips to the other side when this one lacks room. */\n @property({ reflect: true }) placement: UiTooltipPlacement = \"top\";\n /** Hover delay in milliseconds before the tooltip appears; keyboard focus shows it at once. */\n @property({ type: Number, attribute: \"show-delay\" }) showDelay = 300;\n /** Suppresses the tooltip and closes it if open. */\n @property({ type: Boolean, reflect: true }) disabled = false;\n\n @state() private _open = false;\n\n @query(\".tooltip\") private _tooltip!: HTMLElement;\n\n #showTimer: ReturnType<typeof setTimeout> | null = null;\n #hideTimer: ReturnType<typeof setTimeout> | null = null;\n #describedTarget: HTMLElement | null = null;\n #describedId: string | null = null;\n #content: HTMLElement | null = null;\n #madeFocusable = false;\n readonly #contentId = `ui-tooltip-content-${++instanceCount}`;\n\n constructor() {\n super();\n this.addEventListener(\"pointerenter\", () => this.#scheduleShow(this.showDelay));\n this.addEventListener(\"pointerleave\", () => this.#scheduleHide(HIDE_DELAY, \":focus-within\"));\n this.addEventListener(\"focusin\", () => this.#scheduleShow(0));\n this.addEventListener(\"focusout\", () => this.#scheduleHide(0, \":hover\"));\n }\n\n /** Whether the tooltip is currently showing. */\n get open(): boolean {\n return this._open;\n }\n\n override disconnectedCallback(): void {\n super.disconnectedCallback();\n this.#clearTimers();\n this.#setOpen(false);\n }\n\n protected override willUpdate(changed: PropertyValues<this>): void {\n if (changed.has(\"disabled\") && this.disabled) {\n this.#clearTimers();\n this.#setOpen(false);\n }\n }\n\n protected override updated(changed: PropertyValues): void {\n if (!changed.has(\"_open\")) return;\n if (this._open) {\n this._tooltip.showPopover();\n this.#position();\n return;\n }\n if (this._tooltip.matches(\":popover-open\")) this._tooltip.hidePopover();\n }\n\n #scheduleShow(delay: number): void {\n if (this.disabled || !this.#content) return;\n this.#clearTimers();\n if (this._open) return;\n if (delay <= 0) {\n this.#setOpen(true);\n return;\n }\n this.#showTimer = setTimeout(() => this.#setOpen(true), delay);\n }\n\n /** Hides after `delay` unless the host still matches `keepOpenWhile` (still hovered or focused). */\n #scheduleHide(delay: number, keepOpenWhile: string): void {\n this.#clearTimers();\n if (!this._open) return;\n const hide = () => {\n if (!this.matches(keepOpenWhile)) this.#setOpen(false);\n };\n if (delay <= 0) {\n hide();\n return;\n }\n this.#hideTimer = setTimeout(hide, delay);\n }\n\n #clearTimers(): void {\n if (this.#showTimer) clearTimeout(this.#showTimer);\n if (this.#hideTimer) clearTimeout(this.#hideTimer);\n this.#showTimer = null;\n this.#hideTimer = null;\n }\n\n #setOpen(open: boolean): void {\n if (this._open === open) return;\n this._open = open;\n if (open) {\n document.addEventListener(\"keydown\", this.#onDocumentKeydown, true);\n window.addEventListener(\"scroll\", this.#onViewportChange, true);\n window.addEventListener(\"resize\", this.#onViewportChange);\n return;\n }\n document.removeEventListener(\"keydown\", this.#onDocumentKeydown, true);\n window.removeEventListener(\"scroll\", this.#onViewportChange, true);\n window.removeEventListener(\"resize\", this.#onViewportChange);\n }\n\n /** Escape closes the tooltip without dismissing anything else (WCAG 1.4.13). */\n #onDocumentKeydown = (event: KeyboardEvent): void => {\n if (event.key !== \"Escape\" || !this._open) return;\n event.preventDefault();\n event.stopPropagation();\n this.#clearTimers();\n this.#setOpen(false);\n };\n\n #onViewportChange = (): void => {\n if (this._open) this.#position();\n };\n\n /** Places the tooltip beside the host, flipping sides and clamping it inside the viewport. */\n #position(): void {\n const anchor = this.getBoundingClientRect();\n const tip = this._tooltip.getBoundingClientRect();\n const above = anchor.top - GAP - tip.height;\n const below = anchor.bottom + GAP;\n const fitsAbove = above >= EDGE;\n const fitsBelow = below + tip.height <= window.innerHeight - EDGE;\n const top =\n this.placement === \"top\" ? (fitsAbove || !fitsBelow ? above : below) : fitsBelow || !fitsAbove ? below : above;\n const centered = anchor.left + anchor.width / 2 - tip.width / 2;\n const left = Math.min(Math.max(centered, EDGE), Math.max(EDGE, window.innerWidth - EDGE - tip.width));\n this._tooltip.style.top = `${Math.round(top)}px`;\n this._tooltip.style.left = `${Math.round(left)}px`;\n this._tooltip.dataset.side = top === above ? \"top\" : \"bottom\";\n }\n\n async #onTriggerSlotChange(event: Event): Promise<void> {\n const slot = event.target as HTMLSlotElement;\n const trigger = slot.assignedElements()[0] as (HTMLElement & { updateComplete?: Promise<unknown> }) | undefined;\n // A Lit trigger renders its (possibly focusable) shadow content after it is slotted.\n await trigger?.updateComplete;\n if (trigger !== slot.assignedElements()[0]) return;\n const target = trigger && containsFocusable(trigger) ? trigger : this;\n this.#updateFocusability(target === this);\n this.#describe(target);\n }\n\n #onContentSlotChange(event: Event): void {\n const content = (event.target as HTMLSlotElement).assignedElements()[0] as HTMLElement | undefined;\n this.#content = content ?? null;\n if (content && !content.id) content.id = this.#contentId;\n if (!content) this.#setOpen(false);\n this.#describe(this.#describedTarget);\n }\n\n /** Points the trigger's `aria-describedby` at the content, replacing this tooltip's previous reference. */\n #describe(target: HTMLElement | null): void {\n if (this.#describedTarget && this.#describedId) {\n this.#setDescribedBy(this.#describedTarget, this.#describedIds(this.#describedTarget));\n }\n this.#describedTarget = target;\n this.#describedId = this.#content?.id ?? null;\n if (!target || !this.#describedId) return;\n this.#setDescribedBy(target, [...this.#describedIds(target), this.#describedId]);\n }\n\n /** The target's `aria-describedby` ids, minus the one this tooltip added. */\n #describedIds(target: HTMLElement): string[] {\n return (target.getAttribute(\"aria-describedby\") ?? \"\")\n .split(/\\s+/)\n .filter((value) => value && value !== this.#describedId);\n }\n\n #setDescribedBy(target: HTMLElement, ids: string[]): void {\n if (ids.length) target.setAttribute(\"aria-describedby\", ids.join(\" \"));\n else target.removeAttribute(\"aria-describedby\");\n }\n\n #updateFocusability(needed: boolean): void {\n if (needed && !this.hasAttribute(\"tabindex\")) {\n this.tabIndex = 0;\n this.#madeFocusable = true;\n return;\n }\n if (!needed && this.#madeFocusable) {\n this.removeAttribute(\"tabindex\");\n this.#madeFocusable = false;\n }\n }\n\n override render() {\n return html`\n <slot @slotchange=${this.#onTriggerSlotChange}></slot>\n <div class=\"tooltip\" part=\"tooltip\" role=\"tooltip\" popover=\"manual\">\n <slot name=\"content\" @slotchange=${this.#onContentSlotChange}></slot>\n </div>\n `;\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n \"ui-tooltip\": UiTooltip;\n }\n}\n"]}
@@ -18,6 +18,10 @@ Supports two suggestion sources:
18
18
  request. Useful for small/fixed lists, offline use, or tests. Takes
19
19
  priority over `endpoint` whenever it's non-null.
20
20
 
21
+ Each option may also carry a pre-rendered `icon` (shown before the value)
22
+ and a `description` (a smaller, muted line under the value); options
23
+ without them render as a plain value.
24
+
21
25
  Set `clearable` to show an in-field clear action whenever a value is
22
26
  present.
23
27
 
@@ -34,9 +38,12 @@ import "@f-ewald/components/autocomplete-input.js";
34
38
  <autocomplete-input clearable name="language" placeholder="Start typing a language…"></autocomplete-input>
35
39
  </form>
36
40
  <script type="module">
37
- // Local mode: filters client-side, no network request.
41
+ import { iconGlobeAlt } from "@f-ewald/components/icons.js";
42
+
43
+ // Local mode: filters client-side, no network request. `icon` and
44
+ // `description` are optional.
38
45
  document.querySelector("autocomplete-input").options = [
39
- { key: "ts", value: "TypeScript" },
46
+ { key: "ts", value: "TypeScript", icon: iconGlobeAlt(14), description: "Typed superset of JavaScript" },
40
47
  { key: "py", value: "Python" },
41
48
  ];
42
49
 
@@ -5,6 +5,9 @@ and one `<tr>` per entry in `rows`, with each cell's content produced by
5
5
  `renderCell` (default: plain property lookup on the row object). Knows
6
6
  nothing about what a "row" means — callers own the data shape entirely.
7
7
 
8
+ Each column may add a decorative header `icon` and an `align` for its
9
+ header and cells (`end` right-aligns numbers, with tabular figures).
10
+
8
11
  Optional `rowHref` makes whole rows clickable (navigating via `location.hash`),
9
12
  without hijacking clicks on nested interactive elements (links/buttons) a
10
13
  cell's rendered content might contain.
@@ -31,6 +34,21 @@ import "@f-ewald/components/data-table.js";
31
34
  ];
32
35
  table.rowHref = (row) => `#/tasks/${row.id}`;
33
36
  </script>
37
+ <data-table id="packages"></data-table>
38
+ <script type="module">
39
+ import { iconArrowLongRight } from "@f-ewald/components/icons.js";
40
+
41
+ // Header icons and alignment, e.g. right-aligned numbers.
42
+ const packages = document.getElementById("packages");
43
+ packages.columns = [
44
+ { key: "name", label: "Package" },
45
+ { key: "dependents", label: "Dependents", icon: iconArrowLongRight(14), align: "end" },
46
+ ];
47
+ packages.rows = [
48
+ { name: "requests", dependents: 1204 },
49
+ { name: "attrs", dependents: 87 },
50
+ ];
51
+ </script>
34
52
  ```
35
53
 
36
54
  ## Attributes / properties
@@ -0,0 +1,53 @@
1
+ # `<kind-icon>`
2
+
3
+ Inline icon for a named kind (e.g. a service, a library, an external
4
+ package), looked up in a shared `kinds` map so tables, lists, and search
5
+ results show the same icon and color as a `dag-graph` legend. With
6
+ `show-label` the kind's label follows the icon as text; otherwise the
7
+ icon alone is exposed as an image named by the label. Renders nothing for
8
+ a kind missing from `kinds`.
9
+
10
+ ## Install
11
+
12
+ ```js
13
+ import "@f-ewald/components/kind-icon.js";
14
+ ```
15
+
16
+ ## Usage
17
+
18
+ ```html
19
+ <kind-icon kind="service" show-label></kind-icon>
20
+ <kind-icon kind="package" size="18"></kind-icon>
21
+ <script type="module">
22
+ import { iconCube, iconServer } from "@f-ewald/components/icons.js";
23
+
24
+ const kinds = {
25
+ service: { label: "Service", icon: iconServer, color: "#4269d0" },
26
+ package: { label: "External package", icon: iconCube, color: "#9498a0" },
27
+ };
28
+ for (const el of document.querySelectorAll("kind-icon")) el.kinds = kinds;
29
+ </script>
30
+ ```
31
+
32
+ ## Attributes / properties
33
+
34
+ | Property | Attribute | Type | Default | Description |
35
+ | --- | --- | --- | --- | --- |
36
+ | `kind` | `kind` | `string` | `""` | Key of the kind to show, looked up in `kinds`. |
37
+ | `kinds` | _(JS property only)_ | `Record<string, KindIconStyle>` | `{}` | Presentation per kind: label, color, and icon. Shareable with `dag-graph`'s `kinds`. |
38
+ | `size` | `size` | `14 | 18` | `14` | Square icon size in pixels: 14 inline, 18 standalone. |
39
+ | `showLabel` | `show-label` | `boolean` | `false` | Shows the kind's label as text after the icon. |
40
+
41
+ ## Events
42
+
43
+ _None._
44
+
45
+ ## Slots
46
+
47
+ _None._
48
+
49
+ ## CSS custom properties
50
+
51
+ | Custom property |
52
+ | --- |
53
+ | `--ui-primary` |