@f-ewald/components 1.40.3 → 1.41.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.
- package/README.md +11 -3
- package/custom-elements.json +788 -97
- package/dist/app-shell.js +1 -1
- package/dist/app-shell.js.map +1 -1
- package/dist/blink-cursor.d.ts +27 -0
- package/dist/blink-cursor.d.ts.map +1 -0
- package/dist/blink-cursor.js +78 -0
- package/dist/blink-cursor.js.map +1 -0
- package/dist/code-diff.d.ts +41 -0
- package/dist/code-diff.d.ts.map +1 -0
- package/dist/code-diff.js +161 -0
- package/dist/code-diff.js.map +1 -0
- package/dist/comment-label.d.ts +26 -0
- package/dist/comment-label.d.ts.map +1 -0
- package/dist/comment-label.js +81 -0
- package/dist/comment-label.js.map +1 -0
- package/dist/confirm-dialog.d.ts +12 -6
- package/dist/confirm-dialog.d.ts.map +1 -1
- package/dist/confirm-dialog.js +50 -88
- package/dist/confirm-dialog.js.map +1 -1
- package/dist/index.d.ts +8 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -1
- package/dist/index.js.map +1 -1
- package/dist/mcp-server.js +1 -1
- package/dist/mcp-server.js.map +1 -1
- package/dist/modal-dialog.d.ts +16 -13
- package/dist/modal-dialog.d.ts.map +1 -1
- package/dist/modal-dialog.js +69 -104
- package/dist/modal-dialog.js.map +1 -1
- package/dist/photo-gallery.js +1 -1
- package/dist/photo-gallery.js.map +1 -1
- package/dist/price-history-chart.js +1 -1
- package/dist/price-history-chart.js.map +1 -1
- package/dist/progress-bar.d.ts.map +1 -1
- package/dist/progress-bar.js +23 -17
- package/dist/progress-bar.js.map +1 -1
- package/dist/slide-panel.d.ts +3 -3
- package/dist/slide-panel.d.ts.map +1 -1
- package/dist/slide-panel.js +38 -22
- package/dist/slide-panel.js.map +1 -1
- package/dist/stat-strip.d.ts +30 -0
- package/dist/stat-strip.d.ts.map +1 -0
- package/dist/stat-strip.js +111 -0
- package/dist/stat-strip.js.map +1 -0
- package/dist/step-ladder.d.ts +46 -0
- package/dist/step-ladder.d.ts.map +1 -0
- package/dist/step-ladder.js +175 -0
- package/dist/step-ladder.js.map +1 -0
- package/dist/terminal-block.d.ts +45 -0
- package/dist/terminal-block.d.ts.map +1 -0
- package/dist/terminal-block.js +113 -0
- package/dist/terminal-block.js.map +1 -0
- package/dist/toast-notification.d.ts +7 -0
- package/dist/toast-notification.d.ts.map +1 -1
- package/dist/toast-notification.js +34 -0
- package/dist/toast-notification.js.map +1 -1
- package/dist/tokens.css +60 -1
- package/dist/tokens.d.ts +58 -0
- package/dist/tokens.d.ts.map +1 -1
- package/dist/tokens.js +135 -0
- package/dist/tokens.js.map +1 -1
- package/dist/ui-button.js +2 -2
- package/dist/ui-button.js.map +1 -1
- package/dist/window-chrome.d.ts +34 -0
- package/dist/window-chrome.d.ts.map +1 -0
- package/dist/window-chrome.js +141 -0
- package/dist/window-chrome.js.map +1 -0
- package/docs/app-shell.md +1 -1
- package/docs/blink-cursor.md +45 -0
- package/docs/code-diff.md +64 -0
- package/docs/comment-label.md +49 -0
- package/docs/confirm-dialog.md +4 -3
- package/docs/design-language.md +39 -20
- package/docs/layouts/marketing-landing.md +102 -0
- package/docs/modal-dialog.md +9 -9
- package/docs/photo-gallery.md +1 -1
- package/docs/price-history-chart.md +1 -0
- package/docs/slide-panel.md +2 -2
- package/docs/stat-strip.md +57 -0
- package/docs/step-ladder.md +63 -0
- package/docs/terminal-block.md +69 -0
- package/docs/ui-button.md +2 -0
- package/docs/window-chrome.md +64 -0
- package/llms.txt +225 -18
- package/package.json +1 -1
|
@@ -0,0 +1,175 @@
|
|
|
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
|
+
var StepLadder_1;
|
|
8
|
+
import { LitElement, css, html, nothing } from "lit";
|
|
9
|
+
import { customElement, property, state } from "lit/decorators.js";
|
|
10
|
+
import { repeat } from "lit/directives/repeat.js";
|
|
11
|
+
import { tokens } from "./tokens.js";
|
|
12
|
+
/**
|
|
13
|
+
* A flat ordered ladder of fallback steps — an escalating "try this first,
|
|
14
|
+
* then move to the next rung only if it does not solve it" list. Each rung
|
|
15
|
+
* shows a zero-padded ordinal, a bold title, and a muted description, with a
|
|
16
|
+
* hairline rule between rows.
|
|
17
|
+
*
|
|
18
|
+
* Feed it the `items` array for the plain data path, where each
|
|
19
|
+
* {@link StepLadderItem} supplies a `title` and `description`, or slot bare
|
|
20
|
+
* `<li>` steps when a rung needs links, emphasis, or other richer markup.
|
|
21
|
+
* Slotted content takes precedence over `items`; with neither, nothing is
|
|
22
|
+
* rendered. As with `spec-list`, richer wrapper elements are accepted too, but
|
|
23
|
+
* those own their own inner markup.
|
|
24
|
+
*
|
|
25
|
+
* @element step-ladder
|
|
26
|
+
* @slot - Optional `<li>` rungs or richer step markup; when present, they
|
|
27
|
+
* replace the `items` path.
|
|
28
|
+
*/
|
|
29
|
+
let StepLadder = class StepLadder extends LitElement {
|
|
30
|
+
constructor() {
|
|
31
|
+
super(...arguments);
|
|
32
|
+
/** The rungs for the data-driven path. Ignored when the default slot has content. */
|
|
33
|
+
this.items = [];
|
|
34
|
+
/** Whether the default slot currently has assigned content. */
|
|
35
|
+
this._hasSlotted = false;
|
|
36
|
+
}
|
|
37
|
+
static { StepLadder_1 = this; }
|
|
38
|
+
static { this.styles = [
|
|
39
|
+
tokens,
|
|
40
|
+
css `
|
|
41
|
+
:host {
|
|
42
|
+
display: block;
|
|
43
|
+
color: var(--ui-text, #0f172a);
|
|
44
|
+
font-family: var(
|
|
45
|
+
--ui-font,
|
|
46
|
+
ui-sans-serif,
|
|
47
|
+
system-ui,
|
|
48
|
+
sans-serif,
|
|
49
|
+
"Apple Color Emoji",
|
|
50
|
+
"Segoe UI Emoji",
|
|
51
|
+
"Segoe UI Symbol",
|
|
52
|
+
"Noto Color Emoji"
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
.ladder {
|
|
56
|
+
margin: 0;
|
|
57
|
+
padding: 0;
|
|
58
|
+
list-style: none;
|
|
59
|
+
counter-reset: rung;
|
|
60
|
+
}
|
|
61
|
+
.ladder.empty {
|
|
62
|
+
display: none;
|
|
63
|
+
}
|
|
64
|
+
.rung {
|
|
65
|
+
display: flex;
|
|
66
|
+
align-items: flex-start;
|
|
67
|
+
gap: 0.75rem;
|
|
68
|
+
padding: 0.75rem 0;
|
|
69
|
+
counter-increment: rung;
|
|
70
|
+
}
|
|
71
|
+
.rung + .rung {
|
|
72
|
+
border-top: var(--ui-border-width, 1px) solid var(--ui-border, #e2e8f0);
|
|
73
|
+
}
|
|
74
|
+
.rung::before {
|
|
75
|
+
content: counter(rung, decimal-leading-zero);
|
|
76
|
+
flex: 0 0 auto;
|
|
77
|
+
min-width: 2ch;
|
|
78
|
+
color: var(--ui-primary, #4f46e5);
|
|
79
|
+
font-size: var(--ui-font-size-sm, 0.75rem);
|
|
80
|
+
font-weight: var(--ui-font-weight-bold, 700);
|
|
81
|
+
line-height: var(--ui-line-height-normal, 1.5);
|
|
82
|
+
font-variant-numeric: var(--ui-numeric, normal);
|
|
83
|
+
}
|
|
84
|
+
.content {
|
|
85
|
+
display: flex;
|
|
86
|
+
flex: 1 1 auto;
|
|
87
|
+
flex-wrap: wrap;
|
|
88
|
+
align-items: baseline;
|
|
89
|
+
gap: 0.25rem 0.5rem;
|
|
90
|
+
min-width: 0;
|
|
91
|
+
}
|
|
92
|
+
.title {
|
|
93
|
+
color: var(--ui-text, #0f172a);
|
|
94
|
+
font-size: var(--ui-font-size, 0.875rem);
|
|
95
|
+
font-weight: var(--ui-font-weight-bold, 700);
|
|
96
|
+
line-height: var(--ui-line-height-normal, 1.5);
|
|
97
|
+
}
|
|
98
|
+
.description {
|
|
99
|
+
flex: 1 1 12rem;
|
|
100
|
+
min-width: 0;
|
|
101
|
+
color: var(--ui-text-muted, #64748b);
|
|
102
|
+
font-size: var(--ui-font-size, 0.875rem);
|
|
103
|
+
font-weight: var(--ui-font-weight-regular, 400);
|
|
104
|
+
line-height: var(--ui-line-height-normal, 1.5);
|
|
105
|
+
word-break: break-word;
|
|
106
|
+
}
|
|
107
|
+
::slotted(li) {
|
|
108
|
+
margin: 0;
|
|
109
|
+
padding: 0.75rem 0;
|
|
110
|
+
list-style: none;
|
|
111
|
+
border-bottom: var(--ui-border-width, 1px) solid var(--ui-border, #e2e8f0);
|
|
112
|
+
}
|
|
113
|
+
::slotted(li:last-of-type) {
|
|
114
|
+
border-bottom: none;
|
|
115
|
+
}
|
|
116
|
+
`,
|
|
117
|
+
]; }
|
|
118
|
+
/** Whether a slot node is real content, ignoring the whitespace ordinary indented markup leaves between children. */
|
|
119
|
+
static _isContent(node) {
|
|
120
|
+
return node.nodeType === Node.ELEMENT_NODE || (node.textContent ?? "").trim().length > 0;
|
|
121
|
+
}
|
|
122
|
+
/** Tracks whether the default slot has content so slotted markup can take precedence over `items`. */
|
|
123
|
+
_onSlotChange(event) {
|
|
124
|
+
const slot = event.target;
|
|
125
|
+
this._hasSlotted = slot.assignedNodes({ flatten: true }).some(StepLadder_1._isContent);
|
|
126
|
+
}
|
|
127
|
+
connectedCallback() {
|
|
128
|
+
super.connectedCallback();
|
|
129
|
+
// slotchange only fires after the first render, so without seeding from the
|
|
130
|
+
// light DOM here an element given both items and slotted markup renders
|
|
131
|
+
// both paths for its first update — visible to anything awaiting
|
|
132
|
+
// updateComplete, and contrary to the documented "slot wins" contract.
|
|
133
|
+
this._hasSlotted = Array.from(this.childNodes).some(StepLadder_1._isContent);
|
|
134
|
+
}
|
|
135
|
+
/** The rungs, defended against a non-array value assigned at runtime by a JS or HTML consumer. */
|
|
136
|
+
_rows() {
|
|
137
|
+
return Array.isArray(this.items) ? this.items.filter((item) => item != null) : [];
|
|
138
|
+
}
|
|
139
|
+
render() {
|
|
140
|
+
const rows = this._rows();
|
|
141
|
+
const showItems = !this._hasSlotted && rows.length > 0;
|
|
142
|
+
const empty = !this._hasSlotted && rows.length === 0;
|
|
143
|
+
return html `
|
|
144
|
+
<ol class="ladder ${empty ? "empty" : ""}">
|
|
145
|
+
${showItems
|
|
146
|
+
? repeat(rows,
|
|
147
|
+
// Ordered ladders are display-order driven and have no intrinsic
|
|
148
|
+
// item IDs, so the index is the deliberate stable key.
|
|
149
|
+
(_item, index) => index, (item) => html `
|
|
150
|
+
<li class="rung">
|
|
151
|
+
<span class="content">
|
|
152
|
+
<span class="title">${item.title}</span>
|
|
153
|
+
${item.description
|
|
154
|
+
? html `<span class="description">${item.description}</span>`
|
|
155
|
+
: nothing}
|
|
156
|
+
</span>
|
|
157
|
+
</li>
|
|
158
|
+
`)
|
|
159
|
+
: nothing}
|
|
160
|
+
<slot @slotchange=${this._onSlotChange}></slot>
|
|
161
|
+
</ol>
|
|
162
|
+
`;
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
__decorate([
|
|
166
|
+
property({ type: Array })
|
|
167
|
+
], StepLadder.prototype, "items", void 0);
|
|
168
|
+
__decorate([
|
|
169
|
+
state()
|
|
170
|
+
], StepLadder.prototype, "_hasSlotted", void 0);
|
|
171
|
+
StepLadder = StepLadder_1 = __decorate([
|
|
172
|
+
customElement("step-ladder")
|
|
173
|
+
], StepLadder);
|
|
174
|
+
export { StepLadder };
|
|
175
|
+
//# sourceMappingURL=step-ladder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"step-ladder.js","sourceRoot":"","sources":["../src/step-ladder.ts"],"names":[],"mappings":";;;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,GA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["import { LitElement, css, html, nothing } from \"lit\";\nimport { customElement, property, state } from \"lit/decorators.js\";\nimport { repeat } from \"lit/directives/repeat.js\";\nimport { tokens } from \"./tokens.js\";\n\n/** One rung of a {@link StepLadder} in the data-driven `items` path. */\nexport interface StepLadderItem {\n /** The bold step title, shown immediately after the ordinal. */\n title: string;\n /** The muted supporting line that explains the rung's fallback guidance. */\n description: string;\n}\n\n/**\n * A flat ordered ladder of fallback steps — an escalating \"try this first,\n * then move to the next rung only if it does not solve it\" list. Each rung\n * shows a zero-padded ordinal, a bold title, and a muted description, with a\n * hairline rule between rows.\n *\n * Feed it the `items` array for the plain data path, where each\n * {@link StepLadderItem} supplies a `title` and `description`, or slot bare\n * `<li>` steps when a rung needs links, emphasis, or other richer markup.\n * Slotted content takes precedence over `items`; with neither, nothing is\n * rendered. As with `spec-list`, richer wrapper elements are accepted too, but\n * those own their own inner markup.\n *\n * @element step-ladder\n * @slot - Optional `<li>` rungs or richer step markup; when present, they\n * replace the `items` path.\n */\n@customElement(\"step-ladder\")\nexport class StepLadder extends LitElement {\n /** The rungs for the data-driven path. Ignored when the default slot has content. */\n @property({ type: Array }) items: StepLadderItem[] = [];\n\n /** Whether the default slot currently has assigned content. */\n @state() private _hasSlotted = false;\n\n static override styles = [\n tokens,\n css`\n :host {\n display: block;\n color: var(--ui-text, #0f172a);\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 }\n .ladder {\n margin: 0;\n padding: 0;\n list-style: none;\n counter-reset: rung;\n }\n .ladder.empty {\n display: none;\n }\n .rung {\n display: flex;\n align-items: flex-start;\n gap: 0.75rem;\n padding: 0.75rem 0;\n counter-increment: rung;\n }\n .rung + .rung {\n border-top: var(--ui-border-width, 1px) solid var(--ui-border, #e2e8f0);\n }\n .rung::before {\n content: counter(rung, decimal-leading-zero);\n flex: 0 0 auto;\n min-width: 2ch;\n color: var(--ui-primary, #4f46e5);\n font-size: var(--ui-font-size-sm, 0.75rem);\n font-weight: var(--ui-font-weight-bold, 700);\n line-height: var(--ui-line-height-normal, 1.5);\n font-variant-numeric: var(--ui-numeric, normal);\n }\n .content {\n display: flex;\n flex: 1 1 auto;\n flex-wrap: wrap;\n align-items: baseline;\n gap: 0.25rem 0.5rem;\n min-width: 0;\n }\n .title {\n color: var(--ui-text, #0f172a);\n font-size: var(--ui-font-size, 0.875rem);\n font-weight: var(--ui-font-weight-bold, 700);\n line-height: var(--ui-line-height-normal, 1.5);\n }\n .description {\n flex: 1 1 12rem;\n min-width: 0;\n color: var(--ui-text-muted, #64748b);\n font-size: var(--ui-font-size, 0.875rem);\n font-weight: var(--ui-font-weight-regular, 400);\n line-height: var(--ui-line-height-normal, 1.5);\n word-break: break-word;\n }\n ::slotted(li) {\n margin: 0;\n padding: 0.75rem 0;\n list-style: none;\n border-bottom: var(--ui-border-width, 1px) solid var(--ui-border, #e2e8f0);\n }\n ::slotted(li:last-of-type) {\n border-bottom: none;\n }\n `,\n ];\n\n /** Whether a slot node is real content, ignoring the whitespace ordinary indented markup leaves between children. */\n private static _isContent(node: Node): boolean {\n return node.nodeType === Node.ELEMENT_NODE || (node.textContent ?? \"\").trim().length > 0;\n }\n\n /** Tracks whether the default slot has content so slotted markup can take precedence over `items`. */\n private _onSlotChange(event: Event): void {\n const slot = event.target as HTMLSlotElement;\n this._hasSlotted = slot.assignedNodes({ flatten: true }).some(StepLadder._isContent);\n }\n\n override connectedCallback(): void {\n super.connectedCallback();\n // slotchange only fires after the first render, so without seeding from the\n // light DOM here an element given both items and slotted markup renders\n // both paths for its first update — visible to anything awaiting\n // updateComplete, and contrary to the documented \"slot wins\" contract.\n this._hasSlotted = Array.from(this.childNodes).some(StepLadder._isContent);\n }\n\n /** The rungs, defended against a non-array value assigned at runtime by a JS or HTML consumer. */\n private _rows(): StepLadderItem[] {\n return Array.isArray(this.items) ? this.items.filter((item): item is StepLadderItem => item != null) : [];\n }\n\n override render() {\n const rows = this._rows();\n const showItems = !this._hasSlotted && rows.length > 0;\n const empty = !this._hasSlotted && rows.length === 0;\n\n return html`\n <ol class=\"ladder ${empty ? \"empty\" : \"\"}\">\n ${showItems\n ? repeat(\n rows,\n // Ordered ladders are display-order driven and have no intrinsic\n // item IDs, so the index is the deliberate stable key.\n (_item, index) => index,\n (item) => html`\n <li class=\"rung\">\n <span class=\"content\">\n <span class=\"title\">${item.title}</span>\n ${item.description\n ? html`<span class=\"description\">${item.description}</span>`\n : nothing}\n </span>\n </li>\n `,\n )\n : nothing}\n <slot @slotchange=${this._onSlotChange}></slot>\n </ol>\n `;\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n \"step-ladder\": StepLadder;\n }\n}\n"]}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { LitElement } from "lit";
|
|
2
|
+
/** The visual treatment applied to one terminal transcript line. */
|
|
3
|
+
export type TerminalLineType = "prompt" | "comment" | "output";
|
|
4
|
+
/** One ordered line in the terminal transcript. */
|
|
5
|
+
export interface TerminalLine {
|
|
6
|
+
type: TerminalLineType;
|
|
7
|
+
text: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* A headless, data-driven terminal transcript shell for short install or usage
|
|
11
|
+
* instructions. Callers provide a flat ordered `lines` array of
|
|
12
|
+
* `TerminalLine` objects, and the component renders each line exactly in that
|
|
13
|
+
* order with a type-driven visual treatment: `"prompt"` lines get a fixed
|
|
14
|
+
* leading `❯` marker in `--ui-primary`, `"comment"` lines render as dim italic
|
|
15
|
+
* guidance, and `"output"` lines render as plain terminal text.
|
|
16
|
+
*
|
|
17
|
+
* The panel deliberately stays dark regardless of the surrounding page theme:
|
|
18
|
+
* it reuses `--ui-tooltip` for the surface and `--ui-tooltip-text` for the
|
|
19
|
+
* main foreground (not `--ui-on-accent` — that token means "text on a solid
|
|
20
|
+
* *semantic* fill" and a theme is free to darken it for a light accent color,
|
|
21
|
+
* whereas `--ui-tooltip`'s own fill stays dark unconditionally), because this
|
|
22
|
+
* is meant to read as "the terminal" rather than as a normal page card that
|
|
23
|
+
* follows the ambient surface palette.
|
|
24
|
+
*
|
|
25
|
+
* An empty `lines` array still renders the bordered, padded shell so consumers
|
|
26
|
+
* can see that an instruction block is present but currently has no transcript
|
|
27
|
+
* content, rather than having the component silently disappear.
|
|
28
|
+
*
|
|
29
|
+
* @element terminal-block
|
|
30
|
+
*/
|
|
31
|
+
export declare class TerminalBlock extends LitElement {
|
|
32
|
+
static styles: import("lit").CSSResult[];
|
|
33
|
+
/**
|
|
34
|
+
* Ordered terminal transcript lines. Each entry is a `{ type, text }`
|
|
35
|
+
* object, and an empty array still renders the visible terminal shell.
|
|
36
|
+
*/
|
|
37
|
+
lines: TerminalLine[];
|
|
38
|
+
render(): import("lit-html").TemplateResult<1>;
|
|
39
|
+
}
|
|
40
|
+
declare global {
|
|
41
|
+
interface HTMLElementTagNameMap {
|
|
42
|
+
"terminal-block": TerminalBlock;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=terminal-block.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"terminal-block.d.ts","sourceRoot":"","sources":["../src/terminal-block.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAa,MAAM,KAAK,CAAC;AAK5C,oEAAoE;AACpE,MAAM,MAAM,gBAAgB,GAAG,QAAQ,GAAG,SAAS,GAAG,QAAQ,CAAC;AAE/D,mDAAmD;AACnD,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,gBAAgB,CAAC;IACvB,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,qBACa,aAAc,SAAQ,UAAU;IAC3C,OAAgB,MAAM,4BA2DpB;IAEF;;;OAGG;IACwB,KAAK,EAAE,YAAY,EAAE,CAAM;IAE7C,MAAM,yCAMd;CACF;AAED,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,qBAAqB;QAC7B,gBAAgB,EAAE,aAAa,CAAC;KACjC;CACF"}
|
|
@@ -0,0 +1,113 @@
|
|
|
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 } from "lit/decorators.js";
|
|
9
|
+
import { repeat } from "lit/directives/repeat.js";
|
|
10
|
+
import { tokens } from "./tokens.js";
|
|
11
|
+
/**
|
|
12
|
+
* A headless, data-driven terminal transcript shell for short install or usage
|
|
13
|
+
* instructions. Callers provide a flat ordered `lines` array of
|
|
14
|
+
* `TerminalLine` objects, and the component renders each line exactly in that
|
|
15
|
+
* order with a type-driven visual treatment: `"prompt"` lines get a fixed
|
|
16
|
+
* leading `❯` marker in `--ui-primary`, `"comment"` lines render as dim italic
|
|
17
|
+
* guidance, and `"output"` lines render as plain terminal text.
|
|
18
|
+
*
|
|
19
|
+
* The panel deliberately stays dark regardless of the surrounding page theme:
|
|
20
|
+
* it reuses `--ui-tooltip` for the surface and `--ui-tooltip-text` for the
|
|
21
|
+
* main foreground (not `--ui-on-accent` — that token means "text on a solid
|
|
22
|
+
* *semantic* fill" and a theme is free to darken it for a light accent color,
|
|
23
|
+
* whereas `--ui-tooltip`'s own fill stays dark unconditionally), because this
|
|
24
|
+
* is meant to read as "the terminal" rather than as a normal page card that
|
|
25
|
+
* follows the ambient surface palette.
|
|
26
|
+
*
|
|
27
|
+
* An empty `lines` array still renders the bordered, padded shell so consumers
|
|
28
|
+
* can see that an instruction block is present but currently has no transcript
|
|
29
|
+
* content, rather than having the component silently disappear.
|
|
30
|
+
*
|
|
31
|
+
* @element terminal-block
|
|
32
|
+
*/
|
|
33
|
+
let TerminalBlock = class TerminalBlock extends LitElement {
|
|
34
|
+
constructor() {
|
|
35
|
+
super(...arguments);
|
|
36
|
+
/**
|
|
37
|
+
* Ordered terminal transcript lines. Each entry is a `{ type, text }`
|
|
38
|
+
* object, and an empty array still renders the visible terminal shell.
|
|
39
|
+
*/
|
|
40
|
+
this.lines = [];
|
|
41
|
+
}
|
|
42
|
+
static { this.styles = [
|
|
43
|
+
tokens,
|
|
44
|
+
css `
|
|
45
|
+
:host {
|
|
46
|
+
display: block;
|
|
47
|
+
}
|
|
48
|
+
.panel {
|
|
49
|
+
box-sizing: border-box;
|
|
50
|
+
margin: 0;
|
|
51
|
+
display: grid;
|
|
52
|
+
gap: 0.25rem;
|
|
53
|
+
overflow-x: auto;
|
|
54
|
+
padding: 0.75rem 1rem;
|
|
55
|
+
border: var(--ui-border-width, 1px) solid var(--ui-border, #e2e8f0);
|
|
56
|
+
border-radius: var(--ui-radius, 0.5rem);
|
|
57
|
+
background: var(--ui-tooltip, #0f172a);
|
|
58
|
+
color: var(--ui-tooltip-text, #ffffff);
|
|
59
|
+
font-family: var(
|
|
60
|
+
--ui-font-mono,
|
|
61
|
+
ui-monospace,
|
|
62
|
+
SFMono-Regular,
|
|
63
|
+
Menlo,
|
|
64
|
+
Monaco,
|
|
65
|
+
Consolas,
|
|
66
|
+
monospace
|
|
67
|
+
);
|
|
68
|
+
font-size: var(--ui-font-size, 0.875rem);
|
|
69
|
+
line-height: var(--ui-line-height-normal, 1.5);
|
|
70
|
+
white-space: normal;
|
|
71
|
+
}
|
|
72
|
+
.line {
|
|
73
|
+
display: block;
|
|
74
|
+
min-width: 0;
|
|
75
|
+
white-space: pre-wrap;
|
|
76
|
+
}
|
|
77
|
+
.prompt::before {
|
|
78
|
+
content: "❯";
|
|
79
|
+
margin-right: 0.5rem;
|
|
80
|
+
color: var(--ui-primary, #4f46e5);
|
|
81
|
+
font-weight: var(--ui-font-weight-semibold, 600);
|
|
82
|
+
}
|
|
83
|
+
.comment {
|
|
84
|
+
color: rgb(255 255 255 / 0.55);
|
|
85
|
+
font-style: italic;
|
|
86
|
+
}
|
|
87
|
+
@media (forced-colors: active) {
|
|
88
|
+
.panel {
|
|
89
|
+
border: 1px solid CanvasText;
|
|
90
|
+
background: Canvas;
|
|
91
|
+
color: CanvasText;
|
|
92
|
+
}
|
|
93
|
+
.prompt::before {
|
|
94
|
+
color: LinkText;
|
|
95
|
+
}
|
|
96
|
+
.comment {
|
|
97
|
+
color: GrayText;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
`,
|
|
101
|
+
]; }
|
|
102
|
+
render() {
|
|
103
|
+
return html `<pre class="panel">${repeat(this.lines, (_line, index) => index, (line) => html `<span class=${`line ${line.type}`}>${line.text}</span>`)}</pre>`;
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
__decorate([
|
|
107
|
+
property({ type: Array })
|
|
108
|
+
], TerminalBlock.prototype, "lines", void 0);
|
|
109
|
+
TerminalBlock = __decorate([
|
|
110
|
+
customElement("terminal-block")
|
|
111
|
+
], TerminalBlock);
|
|
112
|
+
export { TerminalBlock };
|
|
113
|
+
//# sourceMappingURL=terminal-block.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"terminal-block.js","sourceRoot":"","sources":["../src/terminal-block.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,KAAK,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAClD,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAWrC;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEI,IAAM,aAAa,GAAnB,MAAM,aAAc,SAAQ,UAAU;IAAtC;;QA8DL;;;WAGG;QACwB,UAAK,GAAmB,EAAE,CAAC;IASxD,CAAC;aA1EiB,WAAM,GAAG;QACvB,MAAM;QACN,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAwDF;KACF,AA3DqB,CA2DpB;IAQO,MAAM;QACb,OAAO,IAAI,CAAA,sBAAsB,MAAM,CACrC,IAAI,CAAC,KAAK,EACV,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,KAAK,EACvB,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAA,eAAe,QAAQ,IAAI,CAAC,IAAI,EAAE,IAAI,IAAI,CAAC,IAAI,SAAS,CACvE,QAAQ,CAAC;IACZ,CAAC;CACF,CAAA;AAT4B;IAA1B,QAAQ,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;4CAA4B;AAlE3C,aAAa;IADzB,aAAa,CAAC,gBAAgB,CAAC;GACnB,aAAa,CA2EzB","sourcesContent":["import { LitElement, css, html } from \"lit\";\nimport { customElement, property } from \"lit/decorators.js\";\nimport { repeat } from \"lit/directives/repeat.js\";\nimport { tokens } from \"./tokens.js\";\n\n/** The visual treatment applied to one terminal transcript line. */\nexport type TerminalLineType = \"prompt\" | \"comment\" | \"output\";\n\n/** One ordered line in the terminal transcript. */\nexport interface TerminalLine {\n type: TerminalLineType;\n text: string;\n}\n\n/**\n * A headless, data-driven terminal transcript shell for short install or usage\n * instructions. Callers provide a flat ordered `lines` array of\n * `TerminalLine` objects, and the component renders each line exactly in that\n * order with a type-driven visual treatment: `\"prompt\"` lines get a fixed\n * leading `❯` marker in `--ui-primary`, `\"comment\"` lines render as dim italic\n * guidance, and `\"output\"` lines render as plain terminal text.\n *\n * The panel deliberately stays dark regardless of the surrounding page theme:\n * it reuses `--ui-tooltip` for the surface and `--ui-tooltip-text` for the\n * main foreground (not `--ui-on-accent` — that token means \"text on a solid\n * *semantic* fill\" and a theme is free to darken it for a light accent color,\n * whereas `--ui-tooltip`'s own fill stays dark unconditionally), because this\n * is meant to read as \"the terminal\" rather than as a normal page card that\n * follows the ambient surface palette.\n *\n * An empty `lines` array still renders the bordered, padded shell so consumers\n * can see that an instruction block is present but currently has no transcript\n * content, rather than having the component silently disappear.\n *\n * @element terminal-block\n */\n@customElement(\"terminal-block\")\nexport class TerminalBlock extends LitElement {\n static override styles = [\n tokens,\n css`\n :host {\n display: block;\n }\n .panel {\n box-sizing: border-box;\n margin: 0;\n display: grid;\n gap: 0.25rem;\n overflow-x: auto;\n padding: 0.75rem 1rem;\n border: var(--ui-border-width, 1px) solid var(--ui-border, #e2e8f0);\n border-radius: var(--ui-radius, 0.5rem);\n background: var(--ui-tooltip, #0f172a);\n color: var(--ui-tooltip-text, #ffffff);\n font-family: var(\n --ui-font-mono,\n ui-monospace,\n SFMono-Regular,\n Menlo,\n Monaco,\n Consolas,\n monospace\n );\n font-size: var(--ui-font-size, 0.875rem);\n line-height: var(--ui-line-height-normal, 1.5);\n white-space: normal;\n }\n .line {\n display: block;\n min-width: 0;\n white-space: pre-wrap;\n }\n .prompt::before {\n content: \"❯\";\n margin-right: 0.5rem;\n color: var(--ui-primary, #4f46e5);\n font-weight: var(--ui-font-weight-semibold, 600);\n }\n .comment {\n color: rgb(255 255 255 / 0.55);\n font-style: italic;\n }\n @media (forced-colors: active) {\n .panel {\n border: 1px solid CanvasText;\n background: Canvas;\n color: CanvasText;\n }\n .prompt::before {\n color: LinkText;\n }\n .comment {\n color: GrayText;\n }\n }\n `,\n ];\n\n /**\n * Ordered terminal transcript lines. Each entry is a `{ type, text }`\n * object, and an empty array still renders the visible terminal shell.\n */\n @property({ type: Array }) lines: TerminalLine[] = [];\n\n override render() {\n return html`<pre class=\"panel\">${repeat(\n this.lines,\n (_line, index) => index,\n (line) => html`<span class=${`line ${line.type}`}>${line.text}</span>`,\n )}</pre>`;\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n \"terminal-block\": TerminalBlock;\n }\n}\n"]}
|
|
@@ -67,11 +67,18 @@ export declare class ToastNotification extends LitElement {
|
|
|
67
67
|
* @returns The toast's id — pass to `dismiss()` to remove it early.
|
|
68
68
|
*/
|
|
69
69
|
show(message: string, options?: ToastOptions): number;
|
|
70
|
+
/**
|
|
71
|
+
* Moves the stack to the top of the browser's top layer, so it renders above any native
|
|
72
|
+
* modal `<dialog>` opened earlier (a `position: fixed; z-index` stack can't). Re-showing
|
|
73
|
+
* puts it above layers added since the last toast. No-op without Popover API support.
|
|
74
|
+
*/
|
|
75
|
+
private _promote;
|
|
70
76
|
/**
|
|
71
77
|
* Removes a toast immediately, cancelling its pending auto-dismiss timer if any.
|
|
72
78
|
* @param id The id returned by `show()`.
|
|
73
79
|
*/
|
|
74
80
|
dismiss(id: number): void;
|
|
81
|
+
connectedCallback(): void;
|
|
75
82
|
disconnectedCallback(): void;
|
|
76
83
|
/** Schedules (or reschedules) the real auto-dismiss timeout for a toast. */
|
|
77
84
|
private _scheduleTimer;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toast-notification.d.ts","sourceRoot":"","sources":["../src/toast-notification.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAa,OAAO,EAAE,MAAM,KAAK,CAAC;AAWrD,MAAM,MAAM,YAAY,GAAG,OAAO,GAAG,MAAM,GAAG,SAAS,GAAG,SAAS,CAAC;AAEpE,UAAU,YAAY;IACpB,uEAAuE;IACvE,OAAO,CAAC,EAAE,YAAY,CAAC;IACvB,oFAAoF;IACpF,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAsBD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,qBACa,iBAAkB,SAAQ,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AAM;IAiBd,0EAA0E;IAC1E,OAAO,CAAC,OAAO;IAYf,wGAAwG;IACxG,OAAO,CAAC,YAAY;IAUpB,wEAAwE;IACxE,OAAO,CAAC,iBAAiB;IASzB,OAAO,CAAC,aAAa;IAKrB,OAAO,CAAC,aAAa;IAMrB,OAAO,CAAC,UAAU;IAKlB,sGAAsG;IACtG,OAAO,CAAC,WAAW;IASnB,4EAA4E;IAC5E,OAAO,CAAC,YAAY;IAKpB;;;;OAIG;IACH,OAAO,CAAC,YAAY;IAaX,MAAM,0DAuCd;CACF;AAED,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,qBAAqB;QAC7B,oBAAoB,EAAE,iBAAiB,CAAC;KACzC;CACF;AAMD,wFAAwF;AACxF,wBAAgB,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM,QAEhE;AAED,6BAA6B;AAC7B,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM,QAElE;AAED,2BAA2B;AAC3B,wBAAgB,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM,QAE/D;AAED,6BAA6B;AAC7B,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM,QAElE"}
|
|
@@ -76,6 +76,20 @@ let ToastNotification = class ToastNotification extends LitElement {
|
|
|
76
76
|
gap: 0.5rem;
|
|
77
77
|
width: 22.5rem;
|
|
78
78
|
pointer-events: none;
|
|
79
|
+
/* Reset the UA [popover] box (the host is a manual popover, see _promote()). */
|
|
80
|
+
inset: auto;
|
|
81
|
+
inset-block-start: 1rem;
|
|
82
|
+
inset-inline-end: 1rem;
|
|
83
|
+
margin: 0;
|
|
84
|
+
padding: 0;
|
|
85
|
+
border: 0;
|
|
86
|
+
overflow: visible;
|
|
87
|
+
background: transparent;
|
|
88
|
+
color: inherit;
|
|
89
|
+
}
|
|
90
|
+
/* An author display value would otherwise defeat the UA's display:none for a closed popover. */
|
|
91
|
+
:host([popover]:not(:popover-open)) {
|
|
92
|
+
display: none;
|
|
79
93
|
}
|
|
80
94
|
.toast {
|
|
81
95
|
pointer-events: auto;
|
|
@@ -289,8 +303,21 @@ let ToastNotification = class ToastNotification extends LitElement {
|
|
|
289
303
|
if (duration > 0)
|
|
290
304
|
this._scheduleTimer(id, duration);
|
|
291
305
|
this._syncTicking();
|
|
306
|
+
this._promote();
|
|
292
307
|
return id;
|
|
293
308
|
}
|
|
309
|
+
/**
|
|
310
|
+
* Moves the stack to the top of the browser's top layer, so it renders above any native
|
|
311
|
+
* modal `<dialog>` opened earlier (a `position: fixed; z-index` stack can't). Re-showing
|
|
312
|
+
* puts it above layers added since the last toast. No-op without Popover API support.
|
|
313
|
+
*/
|
|
314
|
+
_promote() {
|
|
315
|
+
if (!this.isConnected || !this.popover)
|
|
316
|
+
return;
|
|
317
|
+
if (this.matches(":popover-open"))
|
|
318
|
+
this.hidePopover();
|
|
319
|
+
this.showPopover();
|
|
320
|
+
}
|
|
294
321
|
/**
|
|
295
322
|
* Removes a toast immediately, cancelling its pending auto-dismiss timer if any.
|
|
296
323
|
* @param id The id returned by `show()`.
|
|
@@ -304,6 +331,13 @@ let ToastNotification = class ToastNotification extends LitElement {
|
|
|
304
331
|
this._interaction.delete(id);
|
|
305
332
|
this._toasts = this._toasts.filter((t) => t.id !== id);
|
|
306
333
|
this._syncTicking();
|
|
334
|
+
if (this._toasts.length === 0 && this.matches(":popover-open"))
|
|
335
|
+
this.hidePopover();
|
|
336
|
+
}
|
|
337
|
+
connectedCallback() {
|
|
338
|
+
super.connectedCallback();
|
|
339
|
+
if ("popover" in HTMLElement.prototype)
|
|
340
|
+
this.popover = "manual";
|
|
307
341
|
}
|
|
308
342
|
disconnectedCallback() {
|
|
309
343
|
super.disconnectedCallback();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toast-notification.js","sourceRoot":"","sources":["../src/toast-notification.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a,CAAC,oBAAoB,CAAC;GACvB,iBAAiB,CA4Z7B;;AAQD,SAAS,QAAQ;IACf,OAAO,QAAQ,CAAC,aAAa,CAAC,oBAAoB,CAAC,CAAC;AACtD,CAAC;AAED,wFAAwF;AACxF,MAAM,UAAU,WAAW,CAAC,OAAe,EAAE,WAAoB;IAC/D,QAAQ,EAAE,EAAE,IAAI,CAAC,OAAO,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,CAAC,CAAC;AAC/D,CAAC;AAED,6BAA6B;AAC7B,MAAM,UAAU,aAAa,CAAC,OAAe,EAAE,WAAoB;IACjE,QAAQ,EAAE,EAAE,IAAI,CAAC,OAAO,EAAE,EAAE,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,CAAC,CAAC;AACjE,CAAC;AAED,2BAA2B;AAC3B,MAAM,UAAU,UAAU,CAAC,OAAe,EAAE,WAAoB;IAC9D,QAAQ,EAAE,EAAE,IAAI,CAAC,OAAO,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,CAAC,CAAC;AAC9D,CAAC;AAED,6BAA6B;AAC7B,MAAM,UAAU,aAAa,CAAC,OAAe,EAAE,WAAoB;IACjE,QAAQ,EAAE,EAAE,IAAI,CAAC,OAAO,EAAE,EAAE,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,CAAC,CAAC;AACjE,CAAC","sourcesContent":["import { LitElement, css, html, nothing } from \"lit\";\nimport { customElement, state } from \"lit/decorators.js\";\nimport {\n iconCheckCircle,\n iconExclamationCircle,\n iconExclamationTriangle,\n iconInfo,\n iconX,\n} from \"./icons.js\";\nimport { tokens } from \"./tokens.js\";\n\nexport type ToastVariant = \"error\" | \"info\" | \"success\" | \"warning\";\n\ninterface ToastOptions {\n /** Visual style; also selects the accent color. Defaults to \"info\". */\n variant?: ToastVariant;\n /** Auto-dismiss delay in ms. Pass 0 to require a manual close. Defaults to 5000. */\n duration?: number;\n /**\n * Optional secondary line shown beneath the headline in smaller, non-bold\n * type. Omit for a single-line toast.\n */\n description?: string;\n}\n\ninterface Toast {\n id: number;\n message: string;\n variant: ToastVariant;\n description?: string;\n /** Configured auto-dismiss delay in ms; 0 means manual dismiss only (no countdown). */\n duration: number;\n /** Timestamp (`Date.now()`-based) this toast will auto-dismiss at, while the countdown is running. */\n endTime: number;\n /** Milliseconds remaining, frozen at the instant hover/focus paused the countdown. */\n remaining: number;\n /** Whether hover or focus has paused the countdown. */\n paused: boolean;\n}\n\nconst DEFAULT_DURATION_MS = 5000;\n/** Radius of the countdown ring's SVG circle — used to derive its circumference. */\nconst RING_RADIUS = 9;\nconst RING_CIRCUMFERENCE = 2 * Math.PI * RING_RADIUS;\n\n/**\n * Fixed-position stack of dismissible notifications, anchored top-right\n * (top-full-width on mobile). Every toast shares one fixed width so entries\n * never appear narrower or wider than one another. Not wired to any app state\n * yet — callers add toasts imperatively via the `show()` method on a live\n * element reference,\n * e.g. `document.querySelector('toast-notification')?.show('Offline', { variant: 'error' })`,\n * or via the `notifySuccess`/`notifyError`/`notifyInfo` module-level helpers\n * exported from this file. The first argument is the required bold headline; an\n * optional `description` renders a smaller, non-bold second line. Each variant\n * leads with a matching status icon (success → check, error → exclamation\n * circle, info → information circle, warning → exclamation triangle). Each toast\n * auto-dismisses after `duration` ms and can also be dismissed via its ✕\n * button. Appears/disappears instantly — no slide/fade transitions.\n *\n * A toast with `duration > 0` replaces its ✕ button with a countdown: a\n * number of seconds remaining inside a ring that fills in clockwise over\n * `duration`. Hovering or keyboard-focusing the toast swaps the countdown\n * back for the ✕ and pauses the countdown (both the visual ring/number and\n * the underlying auto-dismiss timer) — the toast won't disappear while\n * someone's reading it or has tabbed to its close button — resuming from\n * where it left off once the pointer/focus leaves. A `duration: 0` toast has\n * no countdown to show, so its ✕ is always visible, exactly as before.\n *\n * Each variant's background reads a dedicated `--ui-toast-*-background` hook\n * (`success`/`error`/`info`/`warning`), which defaults to the flat\n * `--ui-success`/`--ui-danger`/`--ui-info`/`--ui-warning` tokens unchanged —\n * so those stay the single source of truth for every other component. A\n * consumer can override just these toast-specific tokens with a\n * `linear-gradient(...)` to opt every toast into a gradient look without\n * touching component markup — `gradientTokenValues` in `tokens.ts` ships\n * exactly this, wired up via `data-theme=\"gradient\"` (see `tokens.css`'s\n * \"Gradient theme\" section), the same mechanism `ui-button` uses.\n * `--ui-toast-highlight` (a glossy top-edge box-shadow, layered onto the\n * existing elevation shadow) and `--ui-toast-text-shadow` (legibility\n * against the gradient's lighter stop) round out the effect, mirroring\n * `ui-button`'s `--ui-button-highlight`/`--ui-button-text-shadow`.\n *\n * @element toast-notification\n */\n@customElement(\"toast-notification\")\nexport class ToastNotification extends LitElement {\n @state() private _toasts: Toast[] = [];\n\n private _nextId = 0;\n private _timers = new Map<number, ReturnType<typeof setTimeout>>();\n /** Per-toast hover/focus tracking, so leaving one doesn't resume while the other still applies. */\n private _interaction = new Map<number, { hovered: boolean; focusWithin: boolean }>();\n /** Ticks while any toast has a running countdown, purely to refresh the displayed seconds. */\n private _tickTimer: ReturnType<typeof setInterval> | null = null;\n\n static override styles = [\n tokens,\n css`\n :host {\n position: fixed;\n top: 1rem;\n right: 1rem;\n z-index: 200;\n display: flex;\n flex-direction: column;\n gap: 0.5rem;\n width: 22.5rem;\n pointer-events: none;\n }\n .toast {\n pointer-events: auto;\n display: flex;\n align-items: flex-start;\n gap: 0.5rem;\n border-radius: var(--ui-radius, 0.5rem);\n padding: 0.75rem;\n box-shadow: var(\n --ui-shadow-lg,\n 0 20px 25px -5px rgb(0 0 0 / 0.1),\n 0 8px 10px -6px rgb(0 0 0 / 0.1)\n ), var(--ui-toast-highlight, 0 0 0 0 transparent);\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, 0.875rem);\n line-height: var(--ui-line-height-normal, 1.5);\n color: var(--ui-on-accent, #ffffff);\n background: var(--ui-text, #0f172a);\n text-shadow: var(--ui-toast-text-shadow, none);\n }\n .toast.error {\n background: var(--ui-toast-error-background, var(--ui-danger, #dc2626));\n }\n .toast.success {\n background: var(--ui-toast-success-background, var(--ui-success, #16a34a));\n }\n .toast.info {\n background: var(--ui-toast-info-background, var(--ui-info, #0ea5e9));\n }\n .toast.warning {\n background: var(--ui-toast-warning-background, var(--ui-warning, #d97706));\n }\n .icon {\n flex: 0 0 auto;\n margin-top: 0.125rem;\n line-height: var(--ui-line-height-glyph, 1);\n }\n .content {\n flex: 1 1 auto;\n min-width: 0;\n display: flex;\n flex-direction: column;\n gap: 0.25rem;\n }\n .message {\n font-weight: var(--ui-font-weight-semibold, 600);\n word-break: break-word;\n }\n .description {\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-normal, 1.5);\n word-break: break-word;\n }\n /* .countdown and .close are stacked exactly on top of one another (both\n inset:0 inside this fixed-size box) rather than swapped via\n display:none, so toggling between them never shifts layout. */\n .actions {\n position: relative;\n flex: 0 0 auto;\n width: 2rem;\n height: 2rem;\n margin: -0.25rem -0.25rem -0.25rem 0;\n }\n .countdown {\n position: absolute;\n inset: 0;\n display: inline-flex;\n align-items: center;\n justify-content: center;\n pointer-events: none;\n }\n .ring {\n position: absolute;\n inset: 0;\n width: 100%;\n height: 100%;\n }\n .ring-track {\n fill: none;\n stroke: currentColor;\n stroke-width: 2;\n opacity: 0.3;\n }\n .ring-progress {\n fill: none;\n stroke: currentColor;\n stroke-width: 2;\n stroke-linecap: round;\n transform-origin: 50% 50%;\n transform: rotate(-90deg);\n stroke-dasharray: ${RING_CIRCUMFERENCE};\n stroke-dashoffset: ${RING_CIRCUMFERENCE};\n animation-name: toast-ring-fill;\n animation-duration: var(--toast-duration, 5000ms);\n animation-timing-function: linear;\n animation-fill-mode: forwards;\n }\n .toast.has-countdown:hover .ring-progress,\n .toast.has-countdown:focus-within .ring-progress {\n animation-play-state: paused;\n }\n @keyframes toast-ring-fill {\n to {\n stroke-dashoffset: 0;\n }\n }\n .countdown-number {\n position: relative;\n font-size: var(--ui-font-size-xs, 0.6875rem);\n font-weight: var(--ui-font-weight-semibold, 600);\n font-variant-numeric: tabular-nums;\n line-height: var(--ui-line-height-glyph, 1);\n }\n .close {\n position: absolute;\n inset: 0;\n width: 2rem;\n height: 2rem;\n display: inline-flex;\n align-items: center;\n justify-content: center;\n background: none;\n border: none;\n padding: 0;\n color: inherit;\n opacity: 0.8;\n cursor: pointer;\n line-height: var(--ui-line-height-glyph, 1);\n border-radius: var(--ui-radius-sm, 0.25rem);\n }\n /* Only hide the ✕ behind the countdown when there IS a countdown — a\n duration:0 toast has no .countdown sibling and keeps the ✕ always\n visible, unchanged from before this feature existed. */\n .toast.has-countdown .close {\n opacity: 0;\n }\n .toast.has-countdown:hover .close,\n .toast.has-countdown:focus-within .close {\n opacity: 1;\n }\n .toast.has-countdown:hover .countdown,\n .toast.has-countdown:focus-within .countdown {\n visibility: hidden;\n }\n .close:hover {\n opacity: 1;\n background: var(--ui-hover-overlay, rgb(255 255 255 / 0.32));\n }\n .close:focus-visible {\n outline: none;\n opacity: 1;\n box-shadow: var(--ui-focus-ring, 0 0 0 3px rgb(79 70 229 / 0.35));\n }\n @media (prefers-reduced-motion: reduce) {\n .ring-progress {\n animation: none;\n }\n }\n @media (forced-colors: active) {\n .toast {\n border: 1px solid CanvasText;\n forced-color-adjust: auto;\n }\n .close:focus-visible {\n outline: 2px solid CanvasText;\n outline-offset: 2px;\n box-shadow: none;\n }\n }\n @media (max-width: 48rem) {\n :host {\n top: 0.75rem;\n right: 0.75rem;\n left: 0.75rem;\n width: auto;\n }\n }\n `,\n ];\n\n /**\n * Queues a toast for display.\n * @param message Text to show.\n * @param options Variant + auto-dismiss duration (see {@link ToastOptions}).\n * @returns The toast's id — pass to `dismiss()` to remove it early.\n */\n show(message: string, options: ToastOptions = {}): number {\n const id = this._nextId++;\n const variant = options.variant ?? \"info\";\n const duration = options.duration ?? DEFAULT_DURATION_MS;\n const toast: Toast = {\n id,\n message,\n variant,\n description: options.description,\n duration,\n endTime: duration > 0 ? Date.now() + duration : 0,\n remaining: duration,\n paused: false,\n };\n this._toasts = [...this._toasts, toast];\n if (duration > 0) this._scheduleTimer(id, duration);\n this._syncTicking();\n return id;\n }\n\n /**\n * Removes a toast immediately, cancelling its pending auto-dismiss timer if any.\n * @param id The id returned by `show()`.\n */\n dismiss(id: number) {\n const timer = this._timers.get(id);\n if (timer) {\n clearTimeout(timer);\n this._timers.delete(id);\n }\n this._interaction.delete(id);\n this._toasts = this._toasts.filter((t) => t.id !== id);\n this._syncTicking();\n }\n\n override disconnectedCallback() {\n super.disconnectedCallback();\n for (const timer of this._timers.values()) clearTimeout(timer);\n this._timers.clear();\n if (this._tickTimer) clearInterval(this._tickTimer);\n this._tickTimer = null;\n }\n\n /** Schedules (or reschedules) the real auto-dismiss timeout for a toast. */\n private _scheduleTimer(id: number, ms: number): void {\n this._timers.set(\n id,\n setTimeout(() => this.dismiss(id), ms),\n );\n }\n\n /** Freezes a toast's countdown at its current remaining time. */\n private _pause(id: number): void {\n const index = this._toasts.findIndex((t) => t.id === id);\n if (index === -1) return;\n const toast = this._toasts[index];\n if (toast.duration === 0 || toast.paused) return;\n const timer = this._timers.get(id);\n if (timer) {\n clearTimeout(timer);\n this._timers.delete(id);\n }\n const remaining = Math.max(0, toast.endTime - Date.now());\n const next = [...this._toasts];\n next[index] = { ...toast, paused: true, remaining };\n this._toasts = next;\n this._syncTicking();\n }\n\n /** Resumes a paused toast's countdown for whatever time was remaining. */\n private _resume(id: number): void {\n const index = this._toasts.findIndex((t) => t.id === id);\n if (index === -1) return;\n const toast = this._toasts[index];\n if (toast.duration === 0 || !toast.paused) return;\n this._scheduleTimer(id, toast.remaining);\n const next = [...this._toasts];\n next[index] = { ...toast, paused: false, endTime: Date.now() + toast.remaining };\n this._toasts = next;\n this._syncTicking();\n }\n\n /** Starts or stops the shared display-only tick, matching whether any countdown is actually running. */\n private _syncTicking(): void {\n const needsTicking = this._toasts.some((t) => t.duration > 0 && !t.paused);\n if (needsTicking && !this._tickTimer) {\n this._tickTimer = setInterval(() => this.requestUpdate(), 250);\n } else if (!needsTicking && this._tickTimer) {\n clearInterval(this._tickTimer);\n this._tickTimer = null;\n }\n }\n\n /** Reads (creating if absent) a toast's hover/focus tracking record. */\n private _interactionState(id: number): { hovered: boolean; focusWithin: boolean } {\n let state = this._interaction.get(id);\n if (!state) {\n state = { hovered: false, focusWithin: false };\n this._interaction.set(id, state);\n }\n return state;\n }\n\n private _onMouseEnter(id: number): void {\n this._interactionState(id).hovered = true;\n this._pause(id);\n }\n\n private _onMouseLeave(id: number): void {\n const state = this._interactionState(id);\n state.hovered = false;\n if (!state.focusWithin) this._resume(id);\n }\n\n private _onFocusIn(id: number): void {\n this._interactionState(id).focusWithin = true;\n this._pause(id);\n }\n\n /** Rechecks focus-within on a microtask, since focusout fires before the new focus target settles. */\n private _onFocusOut(id: number, event: FocusEvent): void {\n const el = event.currentTarget as HTMLElement;\n queueMicrotask(() => {\n const state = this._interactionState(id);\n state.focusWithin = el.matches(\":focus-within\");\n if (!state.hovered && !state.focusWithin) this._resume(id);\n });\n }\n\n /** Whole seconds remaining until auto-dismiss, for the countdown number. */\n private _secondsLeft(t: Toast): number {\n const ms = t.paused ? t.remaining : Math.max(0, t.endTime - Date.now());\n return Math.max(0, Math.ceil(ms / 1000));\n }\n\n /**\n * Returns the decorative status icon for a variant, sized as a standalone\n * 18px glyph to match the dismiss button.\n * @param variant The toast variant.\n */\n private _variantIcon(variant: ToastVariant) {\n switch (variant) {\n case \"success\":\n return iconCheckCircle(18);\n case \"error\":\n return iconExclamationCircle(18);\n case \"warning\":\n return iconExclamationTriangle(18);\n default:\n return iconInfo(18);\n }\n }\n\n override render() {\n if (this._toasts.length === 0) return nothing;\n return html`\n ${this._toasts.map(\n (t) => html`\n <div\n class=\"toast ${t.variant} ${t.duration > 0 ? \"has-countdown\" : \"\"}\"\n role=${t.variant === \"error\" ? \"alert\" : \"status\"}\n aria-atomic=\"true\"\n @mouseenter=${() => this._onMouseEnter(t.id)}\n @mouseleave=${() => this._onMouseLeave(t.id)}\n @focusin=${() => this._onFocusIn(t.id)}\n @focusout=${(e: FocusEvent) => this._onFocusOut(t.id, e)}\n >\n <span class=\"icon\" aria-hidden=\"true\">${this._variantIcon(t.variant)}</span>\n <div class=\"content\">\n <span class=\"message\">${t.message}</span>\n ${t.description ? html`<span class=\"description\">${t.description}</span>` : nothing}\n </div>\n <div class=\"actions\">\n ${t.duration > 0\n ? html`\n <div class=\"countdown\" aria-hidden=\"true\" style=\"--toast-duration: ${t.duration}ms\">\n <svg class=\"ring\" viewBox=\"0 0 24 24\">\n <circle class=\"ring-track\" cx=\"12\" cy=\"12\" r=${RING_RADIUS}></circle>\n <circle class=\"ring-progress\" cx=\"12\" cy=\"12\" r=${RING_RADIUS}></circle>\n </svg>\n <span class=\"countdown-number\">${this._secondsLeft(t)}</span>\n </div>\n `\n : nothing}\n <button class=\"close\" aria-label=\"Dismiss notification\" @click=${() => this.dismiss(t.id)}>\n <span aria-hidden=\"true\">${iconX(18)}</span>\n </button>\n </div>\n </div>\n `,\n )}\n `;\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n \"toast-notification\": ToastNotification;\n }\n}\n\nfunction getToast(): ToastNotification | null {\n return document.querySelector(\"toast-notification\");\n}\n\n/** Shows an error toast. Use for connection/network failures, not validation errors. */\nexport function notifyError(message: string, description?: string) {\n getToast()?.show(message, { variant: \"error\", description });\n}\n\n/** Shows a success toast. */\nexport function notifySuccess(message: string, description?: string) {\n getToast()?.show(message, { variant: \"success\", description });\n}\n\n/** Shows an info toast. */\nexport function notifyInfo(message: string, description?: string) {\n getToast()?.show(message, { variant: \"info\", description });\n}\n\n/** Shows a warning toast. */\nexport function notifyWarning(message: string, description?: string) {\n getToast()?.show(message, { variant: \"warning\", description });\n}\n"]}
|
|
1
|
+
{"version":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OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,CAAC,CAAC;AAC9D,CAAC;AAED,6BAA6B;AAC7B,MAAM,UAAU,aAAa,CAAC,OAAe,EAAE,WAAoB;IACjE,QAAQ,EAAE,EAAE,IAAI,CAAC,OAAO,EAAE,EAAE,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,CAAC,CAAC;AACjE,CAAC","sourcesContent":["import { LitElement, css, html, nothing } from \"lit\";\nimport { customElement, state } from \"lit/decorators.js\";\nimport {\n iconCheckCircle,\n iconExclamationCircle,\n iconExclamationTriangle,\n iconInfo,\n iconX,\n} from \"./icons.js\";\nimport { tokens } from \"./tokens.js\";\n\nexport type ToastVariant = \"error\" | \"info\" | \"success\" | \"warning\";\n\ninterface ToastOptions {\n /** Visual style; also selects the accent color. Defaults to \"info\". */\n variant?: ToastVariant;\n /** Auto-dismiss delay in ms. Pass 0 to require a manual close. Defaults to 5000. */\n duration?: number;\n /**\n * Optional secondary line shown beneath the headline in smaller, non-bold\n * type. Omit for a single-line toast.\n */\n description?: string;\n}\n\ninterface Toast {\n id: number;\n message: string;\n variant: ToastVariant;\n description?: string;\n /** Configured auto-dismiss delay in ms; 0 means manual dismiss only (no countdown). */\n duration: number;\n /** Timestamp (`Date.now()`-based) this toast will auto-dismiss at, while the countdown is running. */\n endTime: number;\n /** Milliseconds remaining, frozen at the instant hover/focus paused the countdown. */\n remaining: number;\n /** Whether hover or focus has paused the countdown. */\n paused: boolean;\n}\n\nconst DEFAULT_DURATION_MS = 5000;\n/** Radius of the countdown ring's SVG circle — used to derive its circumference. */\nconst RING_RADIUS = 9;\nconst RING_CIRCUMFERENCE = 2 * Math.PI * RING_RADIUS;\n\n/**\n * Fixed-position stack of dismissible notifications, anchored top-right\n * (top-full-width on mobile). Every toast shares one fixed width so entries\n * never appear narrower or wider than one another. Not wired to any app state\n * yet — callers add toasts imperatively via the `show()` method on a live\n * element reference,\n * e.g. `document.querySelector('toast-notification')?.show('Offline', { variant: 'error' })`,\n * or via the `notifySuccess`/`notifyError`/`notifyInfo` module-level helpers\n * exported from this file. The first argument is the required bold headline; an\n * optional `description` renders a smaller, non-bold second line. Each variant\n * leads with a matching status icon (success → check, error → exclamation\n * circle, info → information circle, warning → exclamation triangle). Each toast\n * auto-dismisses after `duration` ms and can also be dismissed via its ✕\n * button. Appears/disappears instantly — no slide/fade transitions.\n *\n * A toast with `duration > 0` replaces its ✕ button with a countdown: a\n * number of seconds remaining inside a ring that fills in clockwise over\n * `duration`. Hovering or keyboard-focusing the toast swaps the countdown\n * back for the ✕ and pauses the countdown (both the visual ring/number and\n * the underlying auto-dismiss timer) — the toast won't disappear while\n * someone's reading it or has tabbed to its close button — resuming from\n * where it left off once the pointer/focus leaves. A `duration: 0` toast has\n * no countdown to show, so its ✕ is always visible, exactly as before.\n *\n * Each variant's background reads a dedicated `--ui-toast-*-background` hook\n * (`success`/`error`/`info`/`warning`), which defaults to the flat\n * `--ui-success`/`--ui-danger`/`--ui-info`/`--ui-warning` tokens unchanged —\n * so those stay the single source of truth for every other component. A\n * consumer can override just these toast-specific tokens with a\n * `linear-gradient(...)` to opt every toast into a gradient look without\n * touching component markup — `gradientTokenValues` in `tokens.ts` ships\n * exactly this, wired up via `data-theme=\"gradient\"` (see `tokens.css`'s\n * \"Gradient theme\" section), the same mechanism `ui-button` uses.\n * `--ui-toast-highlight` (a glossy top-edge box-shadow, layered onto the\n * existing elevation shadow) and `--ui-toast-text-shadow` (legibility\n * against the gradient's lighter stop) round out the effect, mirroring\n * `ui-button`'s `--ui-button-highlight`/`--ui-button-text-shadow`.\n *\n * @element toast-notification\n */\n@customElement(\"toast-notification\")\nexport class ToastNotification extends LitElement {\n @state() private _toasts: Toast[] = [];\n\n private _nextId = 0;\n private _timers = new Map<number, ReturnType<typeof setTimeout>>();\n /** Per-toast hover/focus tracking, so leaving one doesn't resume while the other still applies. */\n private _interaction = new Map<number, { hovered: boolean; focusWithin: boolean }>();\n /** Ticks while any toast has a running countdown, purely to refresh the displayed seconds. */\n private _tickTimer: ReturnType<typeof setInterval> | null = null;\n\n static override styles = [\n tokens,\n css`\n :host {\n position: fixed;\n top: 1rem;\n right: 1rem;\n z-index: 200;\n display: flex;\n flex-direction: column;\n gap: 0.5rem;\n width: 22.5rem;\n pointer-events: none;\n /* Reset the UA [popover] box (the host is a manual popover, see _promote()). */\n inset: auto;\n inset-block-start: 1rem;\n inset-inline-end: 1rem;\n margin: 0;\n padding: 0;\n border: 0;\n overflow: visible;\n background: transparent;\n color: inherit;\n }\n /* An author display value would otherwise defeat the UA's display:none for a closed popover. */\n :host([popover]:not(:popover-open)) {\n display: none;\n }\n .toast {\n pointer-events: auto;\n display: flex;\n align-items: flex-start;\n gap: 0.5rem;\n border-radius: var(--ui-radius, 0.5rem);\n padding: 0.75rem;\n box-shadow: var(\n --ui-shadow-lg,\n 0 20px 25px -5px rgb(0 0 0 / 0.1),\n 0 8px 10px -6px rgb(0 0 0 / 0.1)\n ), var(--ui-toast-highlight, 0 0 0 0 transparent);\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, 0.875rem);\n line-height: var(--ui-line-height-normal, 1.5);\n color: var(--ui-on-accent, #ffffff);\n background: var(--ui-text, #0f172a);\n text-shadow: var(--ui-toast-text-shadow, none);\n }\n .toast.error {\n background: var(--ui-toast-error-background, var(--ui-danger, #dc2626));\n }\n .toast.success {\n background: var(--ui-toast-success-background, var(--ui-success, #16a34a));\n }\n .toast.info {\n background: var(--ui-toast-info-background, var(--ui-info, #0ea5e9));\n }\n .toast.warning {\n background: var(--ui-toast-warning-background, var(--ui-warning, #d97706));\n }\n .icon {\n flex: 0 0 auto;\n margin-top: 0.125rem;\n line-height: var(--ui-line-height-glyph, 1);\n }\n .content {\n flex: 1 1 auto;\n min-width: 0;\n display: flex;\n flex-direction: column;\n gap: 0.25rem;\n }\n .message {\n font-weight: var(--ui-font-weight-semibold, 600);\n word-break: break-word;\n }\n .description {\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-normal, 1.5);\n word-break: break-word;\n }\n /* .countdown and .close are stacked exactly on top of one another (both\n inset:0 inside this fixed-size box) rather than swapped via\n display:none, so toggling between them never shifts layout. */\n .actions {\n position: relative;\n flex: 0 0 auto;\n width: 2rem;\n height: 2rem;\n margin: -0.25rem -0.25rem -0.25rem 0;\n }\n .countdown {\n position: absolute;\n inset: 0;\n display: inline-flex;\n align-items: center;\n justify-content: center;\n pointer-events: none;\n }\n .ring {\n position: absolute;\n inset: 0;\n width: 100%;\n height: 100%;\n }\n .ring-track {\n fill: none;\n stroke: currentColor;\n stroke-width: 2;\n opacity: 0.3;\n }\n .ring-progress {\n fill: none;\n stroke: currentColor;\n stroke-width: 2;\n stroke-linecap: round;\n transform-origin: 50% 50%;\n transform: rotate(-90deg);\n stroke-dasharray: ${RING_CIRCUMFERENCE};\n stroke-dashoffset: ${RING_CIRCUMFERENCE};\n animation-name: toast-ring-fill;\n animation-duration: var(--toast-duration, 5000ms);\n animation-timing-function: linear;\n animation-fill-mode: forwards;\n }\n .toast.has-countdown:hover .ring-progress,\n .toast.has-countdown:focus-within .ring-progress {\n animation-play-state: paused;\n }\n @keyframes toast-ring-fill {\n to {\n stroke-dashoffset: 0;\n }\n }\n .countdown-number {\n position: relative;\n font-size: var(--ui-font-size-xs, 0.6875rem);\n font-weight: var(--ui-font-weight-semibold, 600);\n font-variant-numeric: tabular-nums;\n line-height: var(--ui-line-height-glyph, 1);\n }\n .close {\n position: absolute;\n inset: 0;\n width: 2rem;\n height: 2rem;\n display: inline-flex;\n align-items: center;\n justify-content: center;\n background: none;\n border: none;\n padding: 0;\n color: inherit;\n opacity: 0.8;\n cursor: pointer;\n line-height: var(--ui-line-height-glyph, 1);\n border-radius: var(--ui-radius-sm, 0.25rem);\n }\n /* Only hide the ✕ behind the countdown when there IS a countdown — a\n duration:0 toast has no .countdown sibling and keeps the ✕ always\n visible, unchanged from before this feature existed. */\n .toast.has-countdown .close {\n opacity: 0;\n }\n .toast.has-countdown:hover .close,\n .toast.has-countdown:focus-within .close {\n opacity: 1;\n }\n .toast.has-countdown:hover .countdown,\n .toast.has-countdown:focus-within .countdown {\n visibility: hidden;\n }\n .close:hover {\n opacity: 1;\n background: var(--ui-hover-overlay, rgb(255 255 255 / 0.32));\n }\n .close:focus-visible {\n outline: none;\n opacity: 1;\n box-shadow: var(--ui-focus-ring, 0 0 0 3px rgb(79 70 229 / 0.35));\n }\n @media (prefers-reduced-motion: reduce) {\n .ring-progress {\n animation: none;\n }\n }\n @media (forced-colors: active) {\n .toast {\n border: 1px solid CanvasText;\n forced-color-adjust: auto;\n }\n .close:focus-visible {\n outline: 2px solid CanvasText;\n outline-offset: 2px;\n box-shadow: none;\n }\n }\n @media (max-width: 48rem) {\n :host {\n top: 0.75rem;\n right: 0.75rem;\n left: 0.75rem;\n width: auto;\n }\n }\n `,\n ];\n\n /**\n * Queues a toast for display.\n * @param message Text to show.\n * @param options Variant + auto-dismiss duration (see {@link ToastOptions}).\n * @returns The toast's id — pass to `dismiss()` to remove it early.\n */\n show(message: string, options: ToastOptions = {}): number {\n const id = this._nextId++;\n const variant = options.variant ?? \"info\";\n const duration = options.duration ?? DEFAULT_DURATION_MS;\n const toast: Toast = {\n id,\n message,\n variant,\n description: options.description,\n duration,\n endTime: duration > 0 ? Date.now() + duration : 0,\n remaining: duration,\n paused: false,\n };\n this._toasts = [...this._toasts, toast];\n if (duration > 0) this._scheduleTimer(id, duration);\n this._syncTicking();\n this._promote();\n return id;\n }\n\n /**\n * Moves the stack to the top of the browser's top layer, so it renders above any native\n * modal `<dialog>` opened earlier (a `position: fixed; z-index` stack can't). Re-showing\n * puts it above layers added since the last toast. No-op without Popover API support.\n */\n private _promote(): void {\n if (!this.isConnected || !this.popover) return;\n if (this.matches(\":popover-open\")) this.hidePopover();\n this.showPopover();\n }\n\n /**\n * Removes a toast immediately, cancelling its pending auto-dismiss timer if any.\n * @param id The id returned by `show()`.\n */\n dismiss(id: number) {\n const timer = this._timers.get(id);\n if (timer) {\n clearTimeout(timer);\n this._timers.delete(id);\n }\n this._interaction.delete(id);\n this._toasts = this._toasts.filter((t) => t.id !== id);\n this._syncTicking();\n if (this._toasts.length === 0 && this.matches(\":popover-open\")) this.hidePopover();\n }\n\n override connectedCallback() {\n super.connectedCallback();\n if (\"popover\" in HTMLElement.prototype) this.popover = \"manual\";\n }\n\n override disconnectedCallback() {\n super.disconnectedCallback();\n for (const timer of this._timers.values()) clearTimeout(timer);\n this._timers.clear();\n if (this._tickTimer) clearInterval(this._tickTimer);\n this._tickTimer = null;\n }\n\n /** Schedules (or reschedules) the real auto-dismiss timeout for a toast. */\n private _scheduleTimer(id: number, ms: number): void {\n this._timers.set(\n id,\n setTimeout(() => this.dismiss(id), ms),\n );\n }\n\n /** Freezes a toast's countdown at its current remaining time. */\n private _pause(id: number): void {\n const index = this._toasts.findIndex((t) => t.id === id);\n if (index === -1) return;\n const toast = this._toasts[index];\n if (toast.duration === 0 || toast.paused) return;\n const timer = this._timers.get(id);\n if (timer) {\n clearTimeout(timer);\n this._timers.delete(id);\n }\n const remaining = Math.max(0, toast.endTime - Date.now());\n const next = [...this._toasts];\n next[index] = { ...toast, paused: true, remaining };\n this._toasts = next;\n this._syncTicking();\n }\n\n /** Resumes a paused toast's countdown for whatever time was remaining. */\n private _resume(id: number): void {\n const index = this._toasts.findIndex((t) => t.id === id);\n if (index === -1) return;\n const toast = this._toasts[index];\n if (toast.duration === 0 || !toast.paused) return;\n this._scheduleTimer(id, toast.remaining);\n const next = [...this._toasts];\n next[index] = { ...toast, paused: false, endTime: Date.now() + toast.remaining };\n this._toasts = next;\n this._syncTicking();\n }\n\n /** Starts or stops the shared display-only tick, matching whether any countdown is actually running. */\n private _syncTicking(): void {\n const needsTicking = this._toasts.some((t) => t.duration > 0 && !t.paused);\n if (needsTicking && !this._tickTimer) {\n this._tickTimer = setInterval(() => this.requestUpdate(), 250);\n } else if (!needsTicking && this._tickTimer) {\n clearInterval(this._tickTimer);\n this._tickTimer = null;\n }\n }\n\n /** Reads (creating if absent) a toast's hover/focus tracking record. */\n private _interactionState(id: number): { hovered: boolean; focusWithin: boolean } {\n let state = this._interaction.get(id);\n if (!state) {\n state = { hovered: false, focusWithin: false };\n this._interaction.set(id, state);\n }\n return state;\n }\n\n private _onMouseEnter(id: number): void {\n this._interactionState(id).hovered = true;\n this._pause(id);\n }\n\n private _onMouseLeave(id: number): void {\n const state = this._interactionState(id);\n state.hovered = false;\n if (!state.focusWithin) this._resume(id);\n }\n\n private _onFocusIn(id: number): void {\n this._interactionState(id).focusWithin = true;\n this._pause(id);\n }\n\n /** Rechecks focus-within on a microtask, since focusout fires before the new focus target settles. */\n private _onFocusOut(id: number, event: FocusEvent): void {\n const el = event.currentTarget as HTMLElement;\n queueMicrotask(() => {\n const state = this._interactionState(id);\n state.focusWithin = el.matches(\":focus-within\");\n if (!state.hovered && !state.focusWithin) this._resume(id);\n });\n }\n\n /** Whole seconds remaining until auto-dismiss, for the countdown number. */\n private _secondsLeft(t: Toast): number {\n const ms = t.paused ? t.remaining : Math.max(0, t.endTime - Date.now());\n return Math.max(0, Math.ceil(ms / 1000));\n }\n\n /**\n * Returns the decorative status icon for a variant, sized as a standalone\n * 18px glyph to match the dismiss button.\n * @param variant The toast variant.\n */\n private _variantIcon(variant: ToastVariant) {\n switch (variant) {\n case \"success\":\n return iconCheckCircle(18);\n case \"error\":\n return iconExclamationCircle(18);\n case \"warning\":\n return iconExclamationTriangle(18);\n default:\n return iconInfo(18);\n }\n }\n\n override render() {\n if (this._toasts.length === 0) return nothing;\n return html`\n ${this._toasts.map(\n (t) => html`\n <div\n class=\"toast ${t.variant} ${t.duration > 0 ? \"has-countdown\" : \"\"}\"\n role=${t.variant === \"error\" ? \"alert\" : \"status\"}\n aria-atomic=\"true\"\n @mouseenter=${() => this._onMouseEnter(t.id)}\n @mouseleave=${() => this._onMouseLeave(t.id)}\n @focusin=${() => this._onFocusIn(t.id)}\n @focusout=${(e: FocusEvent) => this._onFocusOut(t.id, e)}\n >\n <span class=\"icon\" aria-hidden=\"true\">${this._variantIcon(t.variant)}</span>\n <div class=\"content\">\n <span class=\"message\">${t.message}</span>\n ${t.description ? html`<span class=\"description\">${t.description}</span>` : nothing}\n </div>\n <div class=\"actions\">\n ${t.duration > 0\n ? html`\n <div class=\"countdown\" aria-hidden=\"true\" style=\"--toast-duration: ${t.duration}ms\">\n <svg class=\"ring\" viewBox=\"0 0 24 24\">\n <circle class=\"ring-track\" cx=\"12\" cy=\"12\" r=${RING_RADIUS}></circle>\n <circle class=\"ring-progress\" cx=\"12\" cy=\"12\" r=${RING_RADIUS}></circle>\n </svg>\n <span class=\"countdown-number\">${this._secondsLeft(t)}</span>\n </div>\n `\n : nothing}\n <button class=\"close\" aria-label=\"Dismiss notification\" @click=${() => this.dismiss(t.id)}>\n <span aria-hidden=\"true\">${iconX(18)}</span>\n </button>\n </div>\n </div>\n `,\n )}\n `;\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n \"toast-notification\": ToastNotification;\n }\n}\n\nfunction getToast(): ToastNotification | null {\n return document.querySelector(\"toast-notification\");\n}\n\n/** Shows an error toast. Use for connection/network failures, not validation errors. */\nexport function notifyError(message: string, description?: string) {\n getToast()?.show(message, { variant: \"error\", description });\n}\n\n/** Shows a success toast. */\nexport function notifySuccess(message: string, description?: string) {\n getToast()?.show(message, { variant: \"success\", description });\n}\n\n/** Shows an info toast. */\nexport function notifyInfo(message: string, description?: string) {\n getToast()?.show(message, { variant: \"info\", description });\n}\n\n/** Shows a warning toast. */\nexport function notifyWarning(message: string, description?: string) {\n getToast()?.show(message, { variant: \"warning\", description });\n}\n"]}
|