@f-ewald/components 1.12.0 → 1.14.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 +6 -0
- package/custom-elements.json +1376 -49
- package/dist/auto-scroll.d.ts +37 -0
- package/dist/auto-scroll.d.ts.map +1 -0
- package/dist/auto-scroll.js +100 -0
- package/dist/auto-scroll.js.map +1 -0
- package/dist/form-field.d.ts +39 -0
- package/dist/form-field.d.ts.map +1 -0
- package/dist/form-field.js +145 -0
- package/dist/form-field.js.map +1 -0
- package/dist/icons.d.ts +1 -0
- package/dist/icons.d.ts.map +1 -1
- package/dist/icons.js +1 -0
- package/dist/icons.js.map +1 -1
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -1
- package/dist/load-more.d.ts +33 -0
- package/dist/load-more.d.ts.map +1 -0
- package/dist/load-more.js +82 -0
- package/dist/load-more.js.map +1 -0
- package/dist/map-circle.d.ts +12 -9
- package/dist/map-circle.d.ts.map +1 -1
- package/dist/map-circle.js +26 -12
- package/dist/map-circle.js.map +1 -1
- package/dist/map-pin.d.ts +7 -5
- package/dist/map-pin.d.ts.map +1 -1
- package/dist/map-pin.js +14 -8
- package/dist/map-pin.js.map +1 -1
- package/dist/percent-bar-chart.d.ts +32 -3
- package/dist/percent-bar-chart.d.ts.map +1 -1
- package/dist/percent-bar-chart.js +101 -36
- package/dist/percent-bar-chart.js.map +1 -1
- package/dist/scroll-to-bottom.d.ts +41 -0
- package/dist/scroll-to-bottom.d.ts.map +1 -0
- package/dist/scroll-to-bottom.js +189 -0
- package/dist/scroll-to-bottom.js.map +1 -0
- package/dist/scroll-to-top.d.ts +41 -0
- package/dist/scroll-to-top.d.ts.map +1 -0
- package/dist/scroll-to-top.js +189 -0
- package/dist/scroll-to-top.js.map +1 -0
- package/dist/ui-checkbox.d.ts +49 -0
- package/dist/ui-checkbox.d.ts.map +1 -0
- package/dist/ui-checkbox.js +228 -0
- package/dist/ui-checkbox.js.map +1 -0
- package/dist/utils/scroll.d.ts +9 -0
- package/dist/utils/scroll.d.ts.map +1 -0
- package/dist/utils/scroll.js +30 -0
- package/dist/utils/scroll.js.map +1 -0
- package/docs/auto-scroll.md +52 -0
- package/docs/form-field.md +63 -0
- package/docs/layouts/form-page.md +8 -4
- package/docs/load-more.md +43 -0
- package/docs/map-circle.md +11 -9
- package/docs/map-pin.md +6 -5
- package/docs/percent-bar-chart.md +19 -5
- package/docs/scroll-to-bottom.md +68 -0
- package/docs/scroll-to-top.md +59 -0
- package/docs/ui-checkbox.md +58 -0
- package/llms.txt +199 -20
- package/package.json +1 -1
|
@@ -0,0 +1,189 @@
|
|
|
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, state } from "lit/decorators.js";
|
|
9
|
+
import { iconChevronUp } from "./icons.js";
|
|
10
|
+
import { distanceFromTop, scrollToEdge } from "./utils/scroll.js";
|
|
11
|
+
import { tokens } from "./tokens.js";
|
|
12
|
+
/**
|
|
13
|
+
* Overlay button that appears once the page (or a given `target` container)
|
|
14
|
+
* has scrolled more than `threshold` pixels away from the top edge, and
|
|
15
|
+
* scrolls back to the top on click.
|
|
16
|
+
*
|
|
17
|
+
* With no `target` (default), the button is `position: fixed` to the
|
|
18
|
+
* viewport. When `target` is set, the button switches to `position:
|
|
19
|
+
* absolute` and expects to be placed as a descendant of a `position:
|
|
20
|
+
* relative` (or otherwise positioned) ancestor that establishes the visual
|
|
21
|
+
* bounds to float within — typically `target` itself, given `overflow-y:
|
|
22
|
+
* auto; position: relative`, so the button stays pinned to that container's
|
|
23
|
+
* own visible corner as its content scrolls, rather than floating over the
|
|
24
|
+
* whole page.
|
|
25
|
+
*
|
|
26
|
+
* @element scroll-to-top
|
|
27
|
+
* @fires scroll-to-top-triggered - The button was clicked, just before
|
|
28
|
+
* scrolling; detail: `{ target }`.
|
|
29
|
+
*/
|
|
30
|
+
let ScrollToTop = class ScrollToTop extends LitElement {
|
|
31
|
+
constructor() {
|
|
32
|
+
super(...arguments);
|
|
33
|
+
/** Scrollable container to control; `null` (default) scrolls `window`. */
|
|
34
|
+
this.target = null;
|
|
35
|
+
/** Pixels scrolled away from the top before the button appears. */
|
|
36
|
+
this.threshold = 200;
|
|
37
|
+
/** Visible button text, and its accessible name. */
|
|
38
|
+
this.label = "Scroll to top";
|
|
39
|
+
this._visible = false;
|
|
40
|
+
this.#listenedTo = null;
|
|
41
|
+
this.#onScroll = () => {
|
|
42
|
+
this._visible = distanceFromTop(this.target ?? window) > this.threshold;
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
static { this.styles = [
|
|
46
|
+
tokens,
|
|
47
|
+
css `
|
|
48
|
+
:host {
|
|
49
|
+
position: fixed;
|
|
50
|
+
bottom: 0.75rem;
|
|
51
|
+
right: 0.75rem;
|
|
52
|
+
z-index: 40;
|
|
53
|
+
pointer-events: none;
|
|
54
|
+
opacity: 0;
|
|
55
|
+
visibility: hidden;
|
|
56
|
+
transition:
|
|
57
|
+
opacity 150ms ease,
|
|
58
|
+
visibility 0s linear 150ms;
|
|
59
|
+
}
|
|
60
|
+
:host([contained]) {
|
|
61
|
+
position: absolute;
|
|
62
|
+
}
|
|
63
|
+
:host([visible]) {
|
|
64
|
+
opacity: 1;
|
|
65
|
+
visibility: visible;
|
|
66
|
+
transition:
|
|
67
|
+
opacity 150ms ease,
|
|
68
|
+
visibility 0s linear 0s;
|
|
69
|
+
}
|
|
70
|
+
button {
|
|
71
|
+
pointer-events: auto;
|
|
72
|
+
display: inline-flex;
|
|
73
|
+
align-items: center;
|
|
74
|
+
gap: 0.25rem;
|
|
75
|
+
height: 2rem;
|
|
76
|
+
box-sizing: border-box;
|
|
77
|
+
padding: 0 0.75rem;
|
|
78
|
+
color: var(--ui-text, #0f172a);
|
|
79
|
+
background: var(--ui-surface, #ffffff);
|
|
80
|
+
border: 1px solid var(--ui-border, #e2e8f0);
|
|
81
|
+
border-radius: 999px;
|
|
82
|
+
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));
|
|
83
|
+
cursor: pointer;
|
|
84
|
+
font-family: var(
|
|
85
|
+
--ui-font,
|
|
86
|
+
ui-sans-serif,
|
|
87
|
+
system-ui,
|
|
88
|
+
sans-serif,
|
|
89
|
+
"Apple Color Emoji",
|
|
90
|
+
"Segoe UI Emoji",
|
|
91
|
+
"Segoe UI Symbol",
|
|
92
|
+
"Noto Color Emoji"
|
|
93
|
+
);
|
|
94
|
+
font-size: var(--ui-font-size-sm, 0.75rem);
|
|
95
|
+
font-weight: var(--ui-font-weight-medium, 500);
|
|
96
|
+
line-height: var(--ui-line-height-tight, 1.25);
|
|
97
|
+
white-space: nowrap;
|
|
98
|
+
}
|
|
99
|
+
button:hover {
|
|
100
|
+
background: var(--ui-surface-muted, #f8fafc);
|
|
101
|
+
}
|
|
102
|
+
button:focus-visible {
|
|
103
|
+
outline: none;
|
|
104
|
+
box-shadow: var(--ui-focus-ring, 0 0 0 3px rgb(79 70 229 / 0.35));
|
|
105
|
+
}
|
|
106
|
+
@media (prefers-reduced-motion: reduce) {
|
|
107
|
+
:host {
|
|
108
|
+
transition: none;
|
|
109
|
+
}
|
|
110
|
+
:host([visible]) {
|
|
111
|
+
transition: none;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
@media (forced-colors: active) {
|
|
115
|
+
button:focus-visible {
|
|
116
|
+
outline: 2px solid CanvasText;
|
|
117
|
+
outline-offset: 2px;
|
|
118
|
+
box-shadow: none;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
`,
|
|
122
|
+
]; }
|
|
123
|
+
#listenedTo;
|
|
124
|
+
connectedCallback() {
|
|
125
|
+
super.connectedCallback();
|
|
126
|
+
this.#subscribe();
|
|
127
|
+
}
|
|
128
|
+
disconnectedCallback() {
|
|
129
|
+
super.disconnectedCallback();
|
|
130
|
+
this.#unsubscribe();
|
|
131
|
+
}
|
|
132
|
+
willUpdate(changed) {
|
|
133
|
+
if (changed.has("target")) {
|
|
134
|
+
this.toggleAttribute("contained", this.target !== null);
|
|
135
|
+
// Resubscribing here (not in `updated()`) lets `#onScroll()`'s
|
|
136
|
+
// `_visible` write fold into the update already in progress instead of
|
|
137
|
+
// scheduling a new one. Guarded against the initial update, where
|
|
138
|
+
// `target` is always in `changed` too, but `connectedCallback` already
|
|
139
|
+
// subscribed to it.
|
|
140
|
+
if (this.#listenedTo !== (this.target ?? window))
|
|
141
|
+
this.#subscribe();
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
updated(changed) {
|
|
145
|
+
if (changed.has("_visible"))
|
|
146
|
+
this.toggleAttribute("visible", this._visible);
|
|
147
|
+
}
|
|
148
|
+
#subscribe() {
|
|
149
|
+
this.#unsubscribe();
|
|
150
|
+
this.#listenedTo = this.target ?? window;
|
|
151
|
+
this.#listenedTo.addEventListener("scroll", this.#onScroll, { passive: true });
|
|
152
|
+
this.#onScroll();
|
|
153
|
+
}
|
|
154
|
+
#unsubscribe() {
|
|
155
|
+
this.#listenedTo?.removeEventListener("scroll", this.#onScroll);
|
|
156
|
+
this.#listenedTo = null;
|
|
157
|
+
}
|
|
158
|
+
#onScroll;
|
|
159
|
+
#onClick() {
|
|
160
|
+
const target = this.target ?? window;
|
|
161
|
+
this.dispatchEvent(new CustomEvent("scroll-to-top-triggered", { detail: { target }, bubbles: true, composed: true }));
|
|
162
|
+
scrollToEdge(target, "top");
|
|
163
|
+
}
|
|
164
|
+
render() {
|
|
165
|
+
return html `
|
|
166
|
+
<button type="button" @click=${() => this.#onClick()}>
|
|
167
|
+
${iconChevronUp(14)}
|
|
168
|
+
<span>${this.label}</span>
|
|
169
|
+
</button>
|
|
170
|
+
`;
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
__decorate([
|
|
174
|
+
property({ attribute: false })
|
|
175
|
+
], ScrollToTop.prototype, "target", void 0);
|
|
176
|
+
__decorate([
|
|
177
|
+
property({ type: Number })
|
|
178
|
+
], ScrollToTop.prototype, "threshold", void 0);
|
|
179
|
+
__decorate([
|
|
180
|
+
property()
|
|
181
|
+
], ScrollToTop.prototype, "label", void 0);
|
|
182
|
+
__decorate([
|
|
183
|
+
state()
|
|
184
|
+
], ScrollToTop.prototype, "_visible", void 0);
|
|
185
|
+
ScrollToTop = __decorate([
|
|
186
|
+
customElement("scroll-to-top")
|
|
187
|
+
], ScrollToTop);
|
|
188
|
+
export { ScrollToTop };
|
|
189
|
+
//# sourceMappingURL=scroll-to-top.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scroll-to-top.js","sourceRoot":"","sources":["../src/scroll-to-top.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,GAAG,EAAE,IAAI,EAAuB,MAAM,KAAK,CAAC;AACjE,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AACnE,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAClE,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC;;;;;;;;;;;;;;;;;GAiBG;AAEI,IAAM,WAAW,GAAjB,MAAM,WAAY,SAAQ,UAAU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E;6CAA0B;AAvFvB,WAAW;IADvB,aAAa,CAAC,eAAe,CAAC;GAClB,WAAW,CAqJvB","sourcesContent":["import { LitElement, css, html, type PropertyValues } from \"lit\";\nimport { customElement, property, state } from \"lit/decorators.js\";\nimport { iconChevronUp } from \"./icons.js\";\nimport { distanceFromTop, scrollToEdge } from \"./utils/scroll.js\";\nimport { tokens } from \"./tokens.js\";\n\n/**\n * Overlay button that appears once the page (or a given `target` container)\n * has scrolled more than `threshold` pixels away from the top edge, and\n * scrolls back to the top on click.\n *\n * With no `target` (default), the button is `position: fixed` to the\n * viewport. When `target` is set, the button switches to `position:\n * absolute` and expects to be placed as a descendant of a `position:\n * relative` (or otherwise positioned) ancestor that establishes the visual\n * bounds to float within — typically `target` itself, given `overflow-y:\n * auto; position: relative`, so the button stays pinned to that container's\n * own visible corner as its content scrolls, rather than floating over the\n * whole page.\n *\n * @element scroll-to-top\n * @fires scroll-to-top-triggered - The button was clicked, just before\n * scrolling; detail: `{ target }`.\n */\n@customElement(\"scroll-to-top\")\nexport class ScrollToTop extends LitElement {\n static override styles = [\n tokens,\n css`\n :host {\n position: fixed;\n bottom: 0.75rem;\n right: 0.75rem;\n z-index: 40;\n pointer-events: none;\n opacity: 0;\n visibility: hidden;\n transition:\n opacity 150ms ease,\n visibility 0s linear 150ms;\n }\n :host([contained]) {\n position: absolute;\n }\n :host([visible]) {\n opacity: 1;\n visibility: visible;\n transition:\n opacity 150ms ease,\n visibility 0s linear 0s;\n }\n button {\n pointer-events: auto;\n display: inline-flex;\n align-items: center;\n gap: 0.25rem;\n height: 2rem;\n box-sizing: border-box;\n padding: 0 0.75rem;\n color: var(--ui-text, #0f172a);\n background: var(--ui-surface, #ffffff);\n border: 1px solid var(--ui-border, #e2e8f0);\n border-radius: 999px;\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 cursor: pointer;\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-medium, 500);\n line-height: var(--ui-line-height-tight, 1.25);\n white-space: nowrap;\n }\n button:hover {\n background: var(--ui-surface-muted, #f8fafc);\n }\n button:focus-visible {\n outline: none;\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 :host {\n transition: none;\n }\n :host([visible]) {\n transition: none;\n }\n }\n @media (forced-colors: active) {\n button:focus-visible {\n outline: 2px solid CanvasText;\n outline-offset: 2px;\n box-shadow: none;\n }\n }\n `,\n ];\n\n /** Scrollable container to control; `null` (default) scrolls `window`. */\n @property({ attribute: false }) target: HTMLElement | null = null;\n /** Pixels scrolled away from the top before the button appears. */\n @property({ type: Number }) threshold = 200;\n /** Visible button text, and its accessible name. */\n @property() label = \"Scroll to top\";\n\n @state() private _visible = false;\n\n #listenedTo: HTMLElement | Window | null = null;\n\n override connectedCallback(): void {\n super.connectedCallback();\n this.#subscribe();\n }\n\n override disconnectedCallback(): void {\n super.disconnectedCallback();\n this.#unsubscribe();\n }\n\n protected override willUpdate(changed: PropertyValues): void {\n if (changed.has(\"target\")) {\n this.toggleAttribute(\"contained\", this.target !== null);\n // Resubscribing here (not in `updated()`) lets `#onScroll()`'s\n // `_visible` write fold into the update already in progress instead of\n // scheduling a new one. Guarded against the initial update, where\n // `target` is always in `changed` too, but `connectedCallback` already\n // subscribed to it.\n if (this.#listenedTo !== (this.target ?? window)) this.#subscribe();\n }\n }\n\n protected override updated(changed: PropertyValues): void {\n if (changed.has(\"_visible\")) this.toggleAttribute(\"visible\", this._visible);\n }\n\n #subscribe(): void {\n this.#unsubscribe();\n this.#listenedTo = this.target ?? window;\n this.#listenedTo.addEventListener(\"scroll\", this.#onScroll, { passive: true });\n this.#onScroll();\n }\n\n #unsubscribe(): void {\n this.#listenedTo?.removeEventListener(\"scroll\", this.#onScroll);\n this.#listenedTo = null;\n }\n\n #onScroll = (): void => {\n this._visible = distanceFromTop(this.target ?? window) > this.threshold;\n };\n\n #onClick(): void {\n const target = this.target ?? window;\n this.dispatchEvent(\n new CustomEvent(\"scroll-to-top-triggered\", { detail: { target }, bubbles: true, composed: true }),\n );\n scrollToEdge(target, \"top\");\n }\n\n override render() {\n return html`\n <button type=\"button\" @click=${() => this.#onClick()}>\n ${iconChevronUp(14)}\n <span>${this.label}</span>\n </button>\n `;\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n \"scroll-to-top\": ScrollToTop;\n }\n}\n"]}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { LitElement, type PropertyValues } from "lit";
|
|
2
|
+
/**
|
|
3
|
+
* A form-associated boolean checkbox, usable standalone or inside a native
|
|
4
|
+
* `<form>`. Submits `name=on` when checked (matching native
|
|
5
|
+
* `<input type="checkbox">` semantics) and participates fully in form
|
|
6
|
+
* `reset()`, ancestor `<fieldset disabled>`, and `required` validity.
|
|
7
|
+
*
|
|
8
|
+
* Renders a native `<input type="checkbox">` wrapped in a `<label>`, styled
|
|
9
|
+
* via `:has()` on the wrapping label (matching `radio-pills`/`radio-cards`)
|
|
10
|
+
* rather than styling the native input directly; the checkbox itself renders
|
|
11
|
+
* at `1rem`, matching the existing radio-input convention.
|
|
12
|
+
*
|
|
13
|
+
* @element ui-checkbox
|
|
14
|
+
* @fires change - The checkbox was toggled by the user, in either direction;
|
|
15
|
+
* detail: `{ checked }`. Programmatic `checked` assignments do not fire it.
|
|
16
|
+
*/
|
|
17
|
+
export declare class UiCheckbox extends LitElement {
|
|
18
|
+
#private;
|
|
19
|
+
static formAssociated: boolean;
|
|
20
|
+
static styles: import("lit").CSSResult[];
|
|
21
|
+
/** Whether the box is checked. */
|
|
22
|
+
checked: boolean;
|
|
23
|
+
/** Visual "partial selection" state; cleared on the next user interaction. */
|
|
24
|
+
indeterminate: boolean;
|
|
25
|
+
/** Disables interaction; merged with an ancestor `<fieldset disabled>`. */
|
|
26
|
+
disabled: boolean;
|
|
27
|
+
/** Marks the control invalid via `ElementInternals` while unchecked. */
|
|
28
|
+
required: boolean;
|
|
29
|
+
/** Form field name; submitted as `name=on` only while checked. */
|
|
30
|
+
name: string;
|
|
31
|
+
/** Visible label text rendered next to the box. */
|
|
32
|
+
label: string;
|
|
33
|
+
private _formDisabled;
|
|
34
|
+
protected willUpdate(_changed: PropertyValues): void;
|
|
35
|
+
protected updated(changed: PropertyValues): void;
|
|
36
|
+
/** Restores the checked state captured at first render, per the form contract. */
|
|
37
|
+
formResetCallback(): void;
|
|
38
|
+
/** Mirrors an ancestor fieldset's disabled state. */
|
|
39
|
+
formDisabledCallback(disabled: boolean): void;
|
|
40
|
+
/** Restores the checked state from saved form state (bfcache/autofill). */
|
|
41
|
+
formStateRestoreCallback(state: string | File | FormData | null): void;
|
|
42
|
+
render(): import("lit-html").TemplateResult<1>;
|
|
43
|
+
}
|
|
44
|
+
declare global {
|
|
45
|
+
interface HTMLElementTagNameMap {
|
|
46
|
+
"ui-checkbox": UiCheckbox;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=ui-checkbox.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ui-checkbox.d.ts","sourceRoot":"","sources":["../src/ui-checkbox.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAa,KAAK,cAAc,EAAE,MAAM,KAAK,CAAC;AAKjE;;;;;;;;;;;;;;GAcG;AACH,qBACa,UAAW,SAAQ,UAAU;;IACxC,MAAM,CAAC,cAAc,UAAQ;IAE7B,OAAgB,MAAM,4BAkEpB;IAEF,kCAAkC;IACL,OAAO,UAAS;IAC7C,8EAA8E;IACjD,aAAa,UAAS;IACnD,2EAA2E;IAC9C,QAAQ,UAAS;IAC9C,wEAAwE;IAC3C,QAAQ,UAAS;IAC9C,kEAAkE;IACtD,IAAI,SAAM;IACtB,mDAAmD;IACvC,KAAK,SAAM;IAEd,OAAO,CAAC,aAAa,CAAS;IAWvC,UAAmB,UAAU,CAAC,QAAQ,EAAE,cAAc,GAAG,IAAI,CAE5D;IAED,UAAmB,OAAO,CAAC,OAAO,EAAE,cAAc,GAAG,IAAI,CAQxD;IAED,kFAAkF;IAClF,iBAAiB,IAAI,IAAI,CAGxB;IAED,qDAAqD;IACrD,oBAAoB,CAAC,QAAQ,EAAE,OAAO,GAAG,IAAI,CAE5C;IAED,2EAA2E;IAC3E,wBAAwB,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,QAAQ,GAAG,IAAI,GAAG,IAAI,CAGrE;IAwCQ,MAAM,yCAoBd;CACF;AAED,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,qBAAqB;QAC7B,aAAa,EAAE,UAAU,CAAC;KAC3B;CACF"}
|
|
@@ -0,0 +1,228 @@
|
|
|
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, state } from "lit/decorators.js";
|
|
9
|
+
import { ref } from "lit/directives/ref.js";
|
|
10
|
+
import { tokens } from "./tokens.js";
|
|
11
|
+
/**
|
|
12
|
+
* A form-associated boolean checkbox, usable standalone or inside a native
|
|
13
|
+
* `<form>`. Submits `name=on` when checked (matching native
|
|
14
|
+
* `<input type="checkbox">` semantics) and participates fully in form
|
|
15
|
+
* `reset()`, ancestor `<fieldset disabled>`, and `required` validity.
|
|
16
|
+
*
|
|
17
|
+
* Renders a native `<input type="checkbox">` wrapped in a `<label>`, styled
|
|
18
|
+
* via `:has()` on the wrapping label (matching `radio-pills`/`radio-cards`)
|
|
19
|
+
* rather than styling the native input directly; the checkbox itself renders
|
|
20
|
+
* at `1rem`, matching the existing radio-input convention.
|
|
21
|
+
*
|
|
22
|
+
* @element ui-checkbox
|
|
23
|
+
* @fires change - The checkbox was toggled by the user, in either direction;
|
|
24
|
+
* detail: `{ checked }`. Programmatic `checked` assignments do not fire it.
|
|
25
|
+
*/
|
|
26
|
+
let UiCheckbox = class UiCheckbox extends LitElement {
|
|
27
|
+
constructor() {
|
|
28
|
+
super(...arguments);
|
|
29
|
+
/** Whether the box is checked. */
|
|
30
|
+
this.checked = false;
|
|
31
|
+
/** Visual "partial selection" state; cleared on the next user interaction. */
|
|
32
|
+
this.indeterminate = false;
|
|
33
|
+
/** Disables interaction; merged with an ancestor `<fieldset disabled>`. */
|
|
34
|
+
this.disabled = false;
|
|
35
|
+
/** Marks the control invalid via `ElementInternals` while unchecked. */
|
|
36
|
+
this.required = false;
|
|
37
|
+
/** Form field name; submitted as `name=on` only while checked. */
|
|
38
|
+
this.name = "";
|
|
39
|
+
/** Visible label text rendered next to the box. */
|
|
40
|
+
this.label = "";
|
|
41
|
+
this._formDisabled = false;
|
|
42
|
+
this.#internals = this.attachInternals();
|
|
43
|
+
this.#defaultChecked = false;
|
|
44
|
+
this.#inputEl = null;
|
|
45
|
+
this.#onInputRef = (el) => {
|
|
46
|
+
this.#inputEl = el ?? null;
|
|
47
|
+
if (this.#inputEl)
|
|
48
|
+
this.#inputEl.indeterminate = this.indeterminate;
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
static { this.formAssociated = true; }
|
|
52
|
+
static { this.styles = [
|
|
53
|
+
tokens,
|
|
54
|
+
css `
|
|
55
|
+
:host {
|
|
56
|
+
display: inline-block;
|
|
57
|
+
}
|
|
58
|
+
.checkbox {
|
|
59
|
+
display: inline-flex;
|
|
60
|
+
align-items: center;
|
|
61
|
+
gap: 0.5rem;
|
|
62
|
+
min-height: 2rem;
|
|
63
|
+
cursor: pointer;
|
|
64
|
+
font-family: var(--ui-font, ui-sans-serif, system-ui, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji");
|
|
65
|
+
font-size: var(--ui-font-size-sm, 0.75rem);
|
|
66
|
+
line-height: var(--ui-line-height-tight, 1.25);
|
|
67
|
+
color: var(--ui-text, #0f172a);
|
|
68
|
+
}
|
|
69
|
+
.checkbox input {
|
|
70
|
+
width: 1rem;
|
|
71
|
+
height: 1rem;
|
|
72
|
+
margin: 0;
|
|
73
|
+
accent-color: var(--ui-primary, #4f46e5);
|
|
74
|
+
cursor: pointer;
|
|
75
|
+
}
|
|
76
|
+
.checkbox:has(input:focus-visible) {
|
|
77
|
+
outline: none;
|
|
78
|
+
}
|
|
79
|
+
.checkbox:has(input:focus-visible) input {
|
|
80
|
+
outline: none;
|
|
81
|
+
box-shadow: var(--ui-focus-ring, 0 0 0 3px rgb(79 70 229 / 0.35));
|
|
82
|
+
border-radius: var(--ui-radius-sm, 0.25rem);
|
|
83
|
+
}
|
|
84
|
+
.checkbox:has(input:disabled) {
|
|
85
|
+
cursor: not-allowed;
|
|
86
|
+
opacity: 0.6;
|
|
87
|
+
}
|
|
88
|
+
.checkbox:has(input:disabled) input {
|
|
89
|
+
cursor: not-allowed;
|
|
90
|
+
}
|
|
91
|
+
.required-mark {
|
|
92
|
+
color: var(--ui-danger, #dc2626);
|
|
93
|
+
}
|
|
94
|
+
.sr-only {
|
|
95
|
+
position: absolute;
|
|
96
|
+
width: 1px;
|
|
97
|
+
height: 1px;
|
|
98
|
+
margin: -1px;
|
|
99
|
+
padding: 0;
|
|
100
|
+
overflow: hidden;
|
|
101
|
+
clip: rect(0 0 0 0);
|
|
102
|
+
clip-path: inset(50%);
|
|
103
|
+
white-space: nowrap;
|
|
104
|
+
border: 0;
|
|
105
|
+
}
|
|
106
|
+
@media (forced-colors: active) {
|
|
107
|
+
.checkbox:has(input:focus-visible) input {
|
|
108
|
+
outline: 2px solid CanvasText;
|
|
109
|
+
outline-offset: 2px;
|
|
110
|
+
box-shadow: none;
|
|
111
|
+
}
|
|
112
|
+
.checkbox:has(input:disabled) {
|
|
113
|
+
color: GrayText;
|
|
114
|
+
opacity: 1;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
`,
|
|
118
|
+
]; }
|
|
119
|
+
#internals;
|
|
120
|
+
#defaultChecked;
|
|
121
|
+
#inputEl;
|
|
122
|
+
/** Whether the host or an ancestor fieldset currently disables the control. */
|
|
123
|
+
get #isDisabled() {
|
|
124
|
+
return this.disabled || this._formDisabled;
|
|
125
|
+
}
|
|
126
|
+
willUpdate(_changed) {
|
|
127
|
+
if (!this.hasUpdated)
|
|
128
|
+
this.#defaultChecked = this.checked;
|
|
129
|
+
}
|
|
130
|
+
updated(changed) {
|
|
131
|
+
if (changed.has("checked") || changed.has("name"))
|
|
132
|
+
this.#syncFormValue();
|
|
133
|
+
if (changed.has("checked") || changed.has("required") || changed.has("disabled") || changed.has("_formDisabled")) {
|
|
134
|
+
this.#syncValidity();
|
|
135
|
+
}
|
|
136
|
+
if (changed.has("indeterminate") && this.#inputEl) {
|
|
137
|
+
this.#inputEl.indeterminate = this.indeterminate;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
/** Restores the checked state captured at first render, per the form contract. */
|
|
141
|
+
formResetCallback() {
|
|
142
|
+
this.checked = this.#defaultChecked;
|
|
143
|
+
this.indeterminate = false;
|
|
144
|
+
}
|
|
145
|
+
/** Mirrors an ancestor fieldset's disabled state. */
|
|
146
|
+
formDisabledCallback(disabled) {
|
|
147
|
+
this._formDisabled = disabled;
|
|
148
|
+
}
|
|
149
|
+
/** Restores the checked state from saved form state (bfcache/autofill). */
|
|
150
|
+
formStateRestoreCallback(state) {
|
|
151
|
+
if (typeof state !== "string")
|
|
152
|
+
return;
|
|
153
|
+
this.checked = state === "on";
|
|
154
|
+
}
|
|
155
|
+
#syncFormValue() {
|
|
156
|
+
if (!this.name || !this.checked) {
|
|
157
|
+
this.#internals.setFormValue(null);
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
this.#internals.setFormValue("on");
|
|
161
|
+
}
|
|
162
|
+
#syncValidity() {
|
|
163
|
+
if (this.#isDisabled) {
|
|
164
|
+
this.#internals.setValidity({});
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
if (this.required && !this.checked) {
|
|
168
|
+
this.#internals.setValidity({ valueMissing: true }, "Please check this box to continue.", this.#inputEl ?? undefined);
|
|
169
|
+
}
|
|
170
|
+
else {
|
|
171
|
+
this.#internals.setValidity({});
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
#onChange(e) {
|
|
175
|
+
const input = e.target;
|
|
176
|
+
this.checked = input.checked;
|
|
177
|
+
this.indeterminate = false;
|
|
178
|
+
this.dispatchEvent(new CustomEvent("change", { detail: { checked: this.checked }, bubbles: true, composed: true }));
|
|
179
|
+
}
|
|
180
|
+
#onInputRef;
|
|
181
|
+
render() {
|
|
182
|
+
return html `
|
|
183
|
+
<label class="checkbox">
|
|
184
|
+
<input
|
|
185
|
+
${ref(this.#onInputRef)}
|
|
186
|
+
type="checkbox"
|
|
187
|
+
.checked=${this.checked}
|
|
188
|
+
?disabled=${this.#isDisabled}
|
|
189
|
+
?required=${this.required}
|
|
190
|
+
@change=${(e) => this.#onChange(e)}
|
|
191
|
+
/>
|
|
192
|
+
<span
|
|
193
|
+
>${this.label}${this.required
|
|
194
|
+
? html `<span class="required-mark" aria-hidden="true"> *</span><span class="sr-only">
|
|
195
|
+
(required)</span
|
|
196
|
+
>`
|
|
197
|
+
: ""}</span
|
|
198
|
+
>
|
|
199
|
+
</label>
|
|
200
|
+
`;
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
__decorate([
|
|
204
|
+
property({ type: Boolean })
|
|
205
|
+
], UiCheckbox.prototype, "checked", void 0);
|
|
206
|
+
__decorate([
|
|
207
|
+
property({ type: Boolean })
|
|
208
|
+
], UiCheckbox.prototype, "indeterminate", void 0);
|
|
209
|
+
__decorate([
|
|
210
|
+
property({ type: Boolean })
|
|
211
|
+
], UiCheckbox.prototype, "disabled", void 0);
|
|
212
|
+
__decorate([
|
|
213
|
+
property({ type: Boolean })
|
|
214
|
+
], UiCheckbox.prototype, "required", void 0);
|
|
215
|
+
__decorate([
|
|
216
|
+
property()
|
|
217
|
+
], UiCheckbox.prototype, "name", void 0);
|
|
218
|
+
__decorate([
|
|
219
|
+
property()
|
|
220
|
+
], UiCheckbox.prototype, "label", void 0);
|
|
221
|
+
__decorate([
|
|
222
|
+
state()
|
|
223
|
+
], UiCheckbox.prototype, "_formDisabled", void 0);
|
|
224
|
+
UiCheckbox = __decorate([
|
|
225
|
+
customElement("ui-checkbox")
|
|
226
|
+
], UiCheckbox);
|
|
227
|
+
export { UiCheckbox };
|
|
228
|
+
//# sourceMappingURL=ui-checkbox.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ui-checkbox.js","sourceRoot":"","sources":["../src/ui-checkbox.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,GAAG,EAAE,IAAI,EAAuB,MAAM,KAAK,CAAC;AACjE,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AACnE,OAAO,EAAE,GAAG,EAAE,MAAM,uBAAuB,CAAC;AAC5C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC;;;;;;;;;;;;;;GAcG;AAEI,IAAM,UAAU,GAAhB,MAAM,UAAW,SAAQ,UAAU;IAAnC;;QAuEL,kCAAkC;QACL,YAAO,GAAG,KAAK,CAAC;QAC7C,8EAA8E;QACjD,kBAAa,GAAG,K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E,CAAC;4CAAkB;AAEjB;IAA5B,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;4CAAkB;AAElC;IAAX,QAAQ,EAAE;wCAAW;AAEV;IAAX,QAAQ,EAAE;yCAAY;AAEN;IAAhB,KAAK,EAAE;iDAA+B;AApF5B,UAAU;IADtB,aAAa,CAAC,aAAa,CAAC;GAChB,UAAU,CAyLtB","sourcesContent":["import { LitElement, css, html, type PropertyValues } from \"lit\";\nimport { customElement, property, state } from \"lit/decorators.js\";\nimport { ref } from \"lit/directives/ref.js\";\nimport { tokens } from \"./tokens.js\";\n\n/**\n * A form-associated boolean checkbox, usable standalone or inside a native\n * `<form>`. Submits `name=on` when checked (matching native\n * `<input type=\"checkbox\">` semantics) and participates fully in form\n * `reset()`, ancestor `<fieldset disabled>`, and `required` validity.\n *\n * Renders a native `<input type=\"checkbox\">` wrapped in a `<label>`, styled\n * via `:has()` on the wrapping label (matching `radio-pills`/`radio-cards`)\n * rather than styling the native input directly; the checkbox itself renders\n * at `1rem`, matching the existing radio-input convention.\n *\n * @element ui-checkbox\n * @fires change - The checkbox was toggled by the user, in either direction;\n * detail: `{ checked }`. Programmatic `checked` assignments do not fire it.\n */\n@customElement(\"ui-checkbox\")\nexport class UiCheckbox extends LitElement {\n static formAssociated = true;\n\n static override styles = [\n tokens,\n css`\n :host {\n display: inline-block;\n }\n .checkbox {\n display: inline-flex;\n align-items: center;\n gap: 0.5rem;\n min-height: 2rem;\n cursor: pointer;\n font-family: var(--ui-font, ui-sans-serif, system-ui, sans-serif, \"Apple Color Emoji\", \"Segoe UI Emoji\", \"Segoe UI Symbol\", \"Noto Color Emoji\");\n font-size: var(--ui-font-size-sm, 0.75rem);\n line-height: var(--ui-line-height-tight, 1.25);\n color: var(--ui-text, #0f172a);\n }\n .checkbox input {\n width: 1rem;\n height: 1rem;\n margin: 0;\n accent-color: var(--ui-primary, #4f46e5);\n cursor: pointer;\n }\n .checkbox:has(input:focus-visible) {\n outline: none;\n }\n .checkbox:has(input:focus-visible) input {\n outline: none;\n box-shadow: var(--ui-focus-ring, 0 0 0 3px rgb(79 70 229 / 0.35));\n border-radius: var(--ui-radius-sm, 0.25rem);\n }\n .checkbox:has(input:disabled) {\n cursor: not-allowed;\n opacity: 0.6;\n }\n .checkbox:has(input:disabled) input {\n cursor: not-allowed;\n }\n .required-mark {\n color: var(--ui-danger, #dc2626);\n }\n .sr-only {\n position: absolute;\n width: 1px;\n height: 1px;\n margin: -1px;\n padding: 0;\n overflow: hidden;\n clip: rect(0 0 0 0);\n clip-path: inset(50%);\n white-space: nowrap;\n border: 0;\n }\n @media (forced-colors: active) {\n .checkbox:has(input:focus-visible) input {\n outline: 2px solid CanvasText;\n outline-offset: 2px;\n box-shadow: none;\n }\n .checkbox:has(input:disabled) {\n color: GrayText;\n opacity: 1;\n }\n }\n `,\n ];\n\n /** Whether the box is checked. */\n @property({ type: Boolean }) checked = false;\n /** Visual \"partial selection\" state; cleared on the next user interaction. */\n @property({ type: Boolean }) indeterminate = false;\n /** Disables interaction; merged with an ancestor `<fieldset disabled>`. */\n @property({ type: Boolean }) disabled = false;\n /** Marks the control invalid via `ElementInternals` while unchecked. */\n @property({ type: Boolean }) required = false;\n /** Form field name; submitted as `name=on` only while checked. */\n @property() name = \"\";\n /** Visible label text rendered next to the box. */\n @property() label = \"\";\n\n @state() private _formDisabled = false;\n\n #internals = this.attachInternals();\n #defaultChecked = false;\n #inputEl: HTMLInputElement | null = null;\n\n /** Whether the host or an ancestor fieldset currently disables the control. */\n get #isDisabled(): boolean {\n return this.disabled || this._formDisabled;\n }\n\n protected override willUpdate(_changed: PropertyValues): void {\n if (!this.hasUpdated) this.#defaultChecked = this.checked;\n }\n\n protected override updated(changed: PropertyValues): void {\n if (changed.has(\"checked\") || changed.has(\"name\")) this.#syncFormValue();\n if (changed.has(\"checked\") || changed.has(\"required\") || changed.has(\"disabled\") || changed.has(\"_formDisabled\")) {\n this.#syncValidity();\n }\n if (changed.has(\"indeterminate\") && this.#inputEl) {\n this.#inputEl.indeterminate = this.indeterminate;\n }\n }\n\n /** Restores the checked state captured at first render, per the form contract. */\n formResetCallback(): void {\n this.checked = this.#defaultChecked;\n this.indeterminate = false;\n }\n\n /** Mirrors an ancestor fieldset's disabled state. */\n formDisabledCallback(disabled: boolean): void {\n this._formDisabled = disabled;\n }\n\n /** Restores the checked state from saved form state (bfcache/autofill). */\n formStateRestoreCallback(state: string | File | FormData | null): void {\n if (typeof state !== \"string\") return;\n this.checked = state === \"on\";\n }\n\n #syncFormValue(): void {\n if (!this.name || !this.checked) {\n this.#internals.setFormValue(null);\n return;\n }\n this.#internals.setFormValue(\"on\");\n }\n\n #syncValidity(): void {\n if (this.#isDisabled) {\n this.#internals.setValidity({});\n return;\n }\n if (this.required && !this.checked) {\n this.#internals.setValidity(\n { valueMissing: true },\n \"Please check this box to continue.\",\n this.#inputEl ?? undefined,\n );\n } else {\n this.#internals.setValidity({});\n }\n }\n\n #onChange(e: Event): void {\n const input = e.target as HTMLInputElement;\n this.checked = input.checked;\n this.indeterminate = false;\n this.dispatchEvent(\n new CustomEvent(\"change\", { detail: { checked: this.checked }, bubbles: true, composed: true }),\n );\n }\n\n #onInputRef = (el: Element | undefined): void => {\n this.#inputEl = (el as HTMLInputElement | undefined) ?? null;\n if (this.#inputEl) this.#inputEl.indeterminate = this.indeterminate;\n };\n\n override render() {\n return html`\n <label class=\"checkbox\">\n <input\n ${ref(this.#onInputRef)}\n type=\"checkbox\"\n .checked=${this.checked}\n ?disabled=${this.#isDisabled}\n ?required=${this.required}\n @change=${(e: Event) => this.#onChange(e)}\n />\n <span\n >${this.label}${this.required\n ? html`<span class=\"required-mark\" aria-hidden=\"true\"> *</span><span class=\"sr-only\">\n (required)</span\n >`\n : \"\"}</span\n >\n </label>\n `;\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n \"ui-checkbox\": UiCheckbox;\n }\n}\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** A scrollable region: either `window`/document scrolling, or an element with its own scrollbox. */
|
|
2
|
+
export type ScrollableTarget = HTMLElement | Window;
|
|
3
|
+
/** Pixels between the current scroll position and the top edge. */
|
|
4
|
+
export declare function distanceFromTop(target: ScrollableTarget): number;
|
|
5
|
+
/** Pixels between the current scroll position and the bottom edge. */
|
|
6
|
+
export declare function distanceFromBottom(target: ScrollableTarget): number;
|
|
7
|
+
/** Scrolls `target` to its top or bottom edge, honoring `prefers-reduced-motion`. */
|
|
8
|
+
export declare function scrollToEdge(target: ScrollableTarget, edge: "top" | "bottom"): void;
|
|
9
|
+
//# sourceMappingURL=scroll.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scroll.d.ts","sourceRoot":"","sources":["../../src/utils/scroll.ts"],"names":[],"mappings":"AAAA,qGAAqG;AACrG,MAAM,MAAM,gBAAgB,GAAG,WAAW,GAAG,MAAM,CAAC;AAUpD,mEAAmE;AACnE,wBAAgB,eAAe,CAAC,MAAM,EAAE,gBAAgB,GAAG,MAAM,CAEhE;AAED,sEAAsE;AACtE,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,gBAAgB,GAAG,MAAM,CAGnE;AAED,qFAAqF;AACrF,wBAAgB,YAAY,CAAC,MAAM,EAAE,gBAAgB,EAAE,IAAI,EAAE,KAAK,GAAG,QAAQ,GAAG,IAAI,CAUnF"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
function metrics(target) {
|
|
2
|
+
if (target instanceof Window) {
|
|
3
|
+
const doc = document.documentElement;
|
|
4
|
+
return { scrollTop: window.scrollY, scrollHeight: doc.scrollHeight, clientHeight: window.innerHeight };
|
|
5
|
+
}
|
|
6
|
+
return { scrollTop: target.scrollTop, scrollHeight: target.scrollHeight, clientHeight: target.clientHeight };
|
|
7
|
+
}
|
|
8
|
+
/** Pixels between the current scroll position and the top edge. */
|
|
9
|
+
export function distanceFromTop(target) {
|
|
10
|
+
return metrics(target).scrollTop;
|
|
11
|
+
}
|
|
12
|
+
/** Pixels between the current scroll position and the bottom edge. */
|
|
13
|
+
export function distanceFromBottom(target) {
|
|
14
|
+
const { scrollTop, scrollHeight, clientHeight } = metrics(target);
|
|
15
|
+
return scrollHeight - scrollTop - clientHeight;
|
|
16
|
+
}
|
|
17
|
+
/** Scrolls `target` to its top or bottom edge, honoring `prefers-reduced-motion`. */
|
|
18
|
+
export function scrollToEdge(target, edge) {
|
|
19
|
+
const behavior = window.matchMedia("(prefers-reduced-motion: reduce)").matches
|
|
20
|
+
? "instant"
|
|
21
|
+
: "smooth";
|
|
22
|
+
const top = edge === "top" ? 0 : metrics(target).scrollHeight;
|
|
23
|
+
if (target instanceof Window) {
|
|
24
|
+
window.scrollTo({ top, behavior });
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
target.scrollTo({ top, behavior });
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=scroll.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scroll.js","sourceRoot":"","sources":["../../src/utils/scroll.ts"],"names":[],"mappings":"AAGA,SAAS,OAAO,CAAC,MAAwB;IACvC,IAAI,MAAM,YAAY,MAAM,EAAE,CAAC;QAC7B,MAAM,GAAG,GAAG,QAAQ,CAAC,eAAe,CAAC;QACrC,OAAO,EAAE,SAAS,EAAE,MAAM,CAAC,OAAO,EAAE,YAAY,EAAE,GAAG,CAAC,YAAY,EAAE,YAAY,EAAE,MAAM,CAAC,WAAW,EAAE,CAAC;IACzG,CAAC;IACD,OAAO,EAAE,SAAS,EAAE,MAAM,CAAC,SAAS,EAAE,YAAY,EAAE,MAAM,CAAC,YAAY,EAAE,YAAY,EAAE,MAAM,CAAC,YAAY,EAAE,CAAC;AAC/G,CAAC;AAED,mEAAmE;AACnE,MAAM,UAAU,eAAe,CAAC,MAAwB;IACtD,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,SAAS,CAAC;AACnC,CAAC;AAED,sEAAsE;AACtE,MAAM,UAAU,kBAAkB,CAAC,MAAwB;IACzD,MAAM,EAAE,SAAS,EAAE,YAAY,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAClE,OAAO,YAAY,GAAG,SAAS,GAAG,YAAY,CAAC;AACjD,CAAC;AAED,qFAAqF;AACrF,MAAM,UAAU,YAAY,CAAC,MAAwB,EAAE,IAAsB;IAC3E,MAAM,QAAQ,GAAmB,MAAM,CAAC,UAAU,CAAC,kCAAkC,CAAC,CAAC,OAAO;QAC5F,CAAC,CAAC,SAAS;QACX,CAAC,CAAC,QAAQ,CAAC;IACb,MAAM,GAAG,GAAG,IAAI,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,YAAY,CAAC;IAC9D,IAAI,MAAM,YAAY,MAAM,EAAE,CAAC;QAC7B,MAAM,CAAC,QAAQ,CAAC,EAAE,GAAG,EAAE,QAAQ,EAAE,CAAC,CAAC;IACrC,CAAC;SAAM,CAAC;QACN,MAAM,CAAC,QAAQ,CAAC,EAAE,GAAG,EAAE,QAAQ,EAAE,CAAC,CAAC;IACrC,CAAC;AACH,CAAC","sourcesContent":["/** A scrollable region: either `window`/document scrolling, or an element with its own scrollbox. */\nexport type ScrollableTarget = HTMLElement | Window;\n\nfunction metrics(target: ScrollableTarget): { scrollTop: number; scrollHeight: number; clientHeight: number } {\n if (target instanceof Window) {\n const doc = document.documentElement;\n return { scrollTop: window.scrollY, scrollHeight: doc.scrollHeight, clientHeight: window.innerHeight };\n }\n return { scrollTop: target.scrollTop, scrollHeight: target.scrollHeight, clientHeight: target.clientHeight };\n}\n\n/** Pixels between the current scroll position and the top edge. */\nexport function distanceFromTop(target: ScrollableTarget): number {\n return metrics(target).scrollTop;\n}\n\n/** Pixels between the current scroll position and the bottom edge. */\nexport function distanceFromBottom(target: ScrollableTarget): number {\n const { scrollTop, scrollHeight, clientHeight } = metrics(target);\n return scrollHeight - scrollTop - clientHeight;\n}\n\n/** Scrolls `target` to its top or bottom edge, honoring `prefers-reduced-motion`. */\nexport function scrollToEdge(target: ScrollableTarget, edge: \"top\" | \"bottom\"): void {\n const behavior: ScrollBehavior = window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches\n ? \"instant\"\n : \"smooth\";\n const top = edge === \"top\" ? 0 : metrics(target).scrollHeight;\n if (target instanceof Window) {\n window.scrollTo({ top, behavior });\n } else {\n target.scrollTo({ top, behavior });\n }\n}\n"]}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# `<auto-scroll>`
|
|
2
|
+
|
|
3
|
+
Wraps arbitrary slotted content (e.g. `timeline-container`) and keeps it
|
|
4
|
+
scrolled to the bottom as new children are appended — but only while the
|
|
5
|
+
user is already scrolled near the bottom ("stick to bottom", a chat/log-
|
|
6
|
+
viewer convention). If the user has scrolled up to read earlier content,
|
|
7
|
+
new content does not yank the scroll position back down.
|
|
8
|
+
|
|
9
|
+
New content is detected via a `MutationObserver`, so no cooperation from
|
|
10
|
+
whatever is slotted in is required. The host itself is the scrollable
|
|
11
|
+
region (`overflow-y: auto`) and needs a consumer-supplied bounded height to
|
|
12
|
+
have anything to scroll, e.g. `auto-scroll { height: 24rem; }`.
|
|
13
|
+
|
|
14
|
+
## Install
|
|
15
|
+
|
|
16
|
+
```js
|
|
17
|
+
import "@f-ewald/components/auto-scroll.js";
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Usage
|
|
21
|
+
|
|
22
|
+
```html
|
|
23
|
+
<auto-scroll style="height: 24rem">
|
|
24
|
+
<timeline-container>
|
|
25
|
+
<timeline-entry datetime="2026-07-23T09:00:00Z">
|
|
26
|
+
<span slot="headline">Deployment started</span>
|
|
27
|
+
Release v1.4.0 is rolling out.
|
|
28
|
+
</timeline-entry>
|
|
29
|
+
</timeline-container>
|
|
30
|
+
</auto-scroll>
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Attributes / properties
|
|
34
|
+
|
|
35
|
+
| Property | Attribute | Type | Default | Description |
|
|
36
|
+
| --- | --- | --- | --- | --- |
|
|
37
|
+
| `threshold` | `threshold` | `number` | `24` | Pixels of tolerance from the bottom edge counted as "still at the bottom". |
|
|
38
|
+
| `pinned` | _(JS property only)_ | `boolean` | `—` | Whether the view is currently stuck to the bottom. Read-only; see `scrollToBottom()`. _(read-only)_ |
|
|
39
|
+
|
|
40
|
+
## Events
|
|
41
|
+
|
|
42
|
+
| Event | Description |
|
|
43
|
+
| --- | --- |
|
|
44
|
+
| `pinned-change` | The stick-to-bottom state toggled; detail: `{ pinned }`. |
|
|
45
|
+
|
|
46
|
+
## Slots
|
|
47
|
+
|
|
48
|
+
_None._
|
|
49
|
+
|
|
50
|
+
## CSS custom properties
|
|
51
|
+
|
|
52
|
+
_None._
|