@karan4/frostjs 0.0.0-stage → 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Frost contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,305 @@
1
- # Temporary Holding Version
1
+ # Frost
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ [![CI](https://github.com/karan4/FrostJS/actions/workflows/ci.yml/badge.svg)](https://github.com/karan4/FrostJS/actions/workflows/ci.yml)
4
+ [![npm](https://img.shields.io/npm/v/@karan4/frostjs.svg)](https://www.npmjs.com/package/@karan4/frostjs)
5
+ [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
6
+
7
+ **Loading masks that never get stuck and never double up.**
8
+
9
+ Frost puts a frosted-glass loading overlay on any element or the whole page and
10
+ ties it to the work it is waiting for. One mask per element stays up until the
11
+ last operation finishes, even if requests complete out of order, fail, or get
12
+ canceled. It has no dependencies and works with plain JavaScript, React, Vue,
13
+ and Angular.
14
+
15
+ ![Two requests share one mask until both finish](docs/demo.gif)
16
+
17
+ [Try the live demo](https://karan4.github.io/FrostJS/)
18
+
19
+ ```ts
20
+ import { mask } from '@karan4/frostjs';
21
+
22
+ mask('#results', fetch('/api/search')); // removed on success, error, or abort
23
+ ```
24
+
25
+ It is useful when independent operations share a loading region and a global
26
+ progress indicator or a single `isLoading` boolean isn't enough.
27
+
28
+ | Alternative | When it fits |
29
+ | --- | --- |
30
+ | Pace.js | A page-level progress indicator that automatically tracks activity. |
31
+ | NProgress | An explicitly controlled, top-of-page progress bar. |
32
+ | jQuery BlockUI | Blocking a page or element in a jQuery application. |
33
+ | ng-block-ui | Application or element overlays in Angular. |
34
+ | vue-loading-overlay | Declarative loading overlays in Vue. |
35
+ | Frost | Per-target concurrency and opt-in request tracking across frameworks. |
36
+
37
+ ## Getting started
38
+
39
+ ```sh
40
+ npm install @karan4/frostjs
41
+ ```
42
+
43
+ ```ts
44
+ import { mask, show } from '@karan4/frostjs';
45
+
46
+ // Returns the same promise; its success, error, and cancellation still belong to you.
47
+ const response = await mask('#results', fetch('/api/search'), {
48
+ text: 'Searching…',
49
+ delay: 150,
50
+ minDuration: 250,
51
+ });
52
+
53
+ // Manual usage, including non-network work:
54
+ const release = show(document.querySelector<HTMLElement>('#editor') ?? undefined);
55
+ try {
56
+ await saveDraft();
57
+ } finally {
58
+ release();
59
+ }
60
+ ```
61
+
62
+ Use a container that can host an overlay (not a void element such as an
63
+ `<input>`). Frost sets `aria-busy`, makes child content inert, and adds an
64
+ overlay to catch pointer input. A section with static positioning gets temporary
65
+ relative positioning; Frost restores the styles, attributes, and keyboard focus
66
+ it changed. The overlay follows the target's rounded corners, stays on the
67
+ visible area of a scrolled container, and gives an empty target enough height
68
+ to show the indicator. Mask a table or its wrapper rather than a `<tbody>` or
69
+ `<tr>`. Targets inside an open shadow root work when you pass the element (not
70
+ a selector).
71
+
72
+ For full-page masks, pass `'body'` or `document`. An unresolved selector, empty
73
+ framework ref, `null`, or `undefined` is a no-op, so a lookup that finds nothing
74
+ never blocks the whole page.
75
+
76
+ ## Opt-in request adapters
77
+
78
+ No network APIs are modified on import. Install only the adapters your app
79
+ needs. Install each once at app startup and call its uninstall function during
80
+ teardown. Passing `frost` metadata opts in; it is never sent to the server.
81
+
82
+ ### Fetch and XHR
83
+
84
+ ```ts
85
+ import { installFetch, installXHR } from '@karan4/frostjs';
86
+
87
+ const uninstallFetch = installFetch();
88
+ const uninstallXHR = installXHR();
89
+
90
+ await fetch('/api/search', {
91
+ frost: { target: '#results', theme: 'dots', text: 'Searching…' },
92
+ });
93
+
94
+ const xhr = new XMLHttpRequest();
95
+ xhr.open('GET', '/api/search');
96
+ xhr.frost = 'xpath://section[@id="results"]';
97
+ xhr.send();
98
+ ```
99
+
100
+ Fetch tracks the fetch promise, which resolves once the response is available,
101
+ not after a streamed body has been consumed. Use `mask(target, work())` instead
102
+ if you also need to cover body parsing or downstream processing.
103
+
104
+ Use `installXHR()` for clients that actually use XMLHttpRequest. It wraps
105
+ `XMLHttpRequest.prototype.send`, not the constructor. Fetch is a separate browser
106
+ API and does not go through XHR. Axios and Angular can use either transport,
107
+ depending on configuration; their own adapters avoid patching browser globals.
108
+
109
+ ### Axios
110
+
111
+ Pass the public `axios.getAdapter` resolver (Axios 1.x with `getAdapter`). The
112
+ request interceptor wraps only opted-in adapters and releases even if an error
113
+ doesn't have an Axios request config attached.
114
+
115
+ ```ts
116
+ import axios from 'axios';
117
+ import { installAxios, type RequestMask } from '@karan4/frostjs';
118
+
119
+ declare module 'axios' {
120
+ interface AxiosRequestConfig {
121
+ frost?: RequestMask;
122
+ }
123
+ }
124
+
125
+ const api = axios.create();
126
+ const uninstallAxios = installAxios(api, axios.getAdapter);
127
+ await api.get('/api/search', { frost: '#results' });
128
+ ```
129
+
130
+ ### Angular
131
+
132
+ `HttpContext` is local request metadata: it doesn't travel as a header or a
133
+ query parameter. Register either interceptor, not both.
134
+
135
+ ```ts
136
+ import { HttpContext, provideHttpClient, withInterceptors } from '@angular/common/http';
137
+ import { FROST, frostInterceptor } from '@karan4/frostjs/angular';
138
+
139
+ // In application providers:
140
+ provideHttpClient(withInterceptors([frostInterceptor]));
141
+
142
+ // In a component or service (results can be an ElementRef<HTMLElement>):
143
+ this.http.get('/api/search', {
144
+ context: new HttpContext().set(FROST, { target: this.results, theme: 'bar' }),
145
+ }).subscribe({ next: renderResults, error: reportError });
146
+ ```
147
+
148
+ In a module-based app, use the same `provideHttpClient(withInterceptors([frostInterceptor]))`
149
+ call in the module's `providers`.
150
+
151
+ ### React
152
+
153
+ ```tsx
154
+ import { useRef } from 'react';
155
+ import { Frost, useFrost } from '@karan4/frostjs/react';
156
+
157
+ const options = { theme: 'dots', text: 'Loading…' } as const;
158
+
159
+ function Results({ loading }: { loading: boolean }) {
160
+ const ref = useRef<HTMLElement>(null);
161
+ useFrost(ref, loading, options);
162
+ return <section ref={ref}>Search results</section>;
163
+ }
164
+
165
+ // Or render a wrapper div:
166
+ // <Frost loading={loading} options={options}>Search results</Frost>
167
+ ```
168
+
169
+ Options are read when loading starts, so an inline options object is fine.
170
+
171
+ ### Vue
172
+
173
+ Use `vFrost` as a local directive in `<script setup>`, or register it
174
+ globally with `app.directive('frost', vFrost)`.
175
+
176
+ ```vue
177
+ <script setup>
178
+ import { ref } from 'vue'
179
+ import { vFrost } from '@karan4/frostjs/vue'
180
+
181
+ const loading = ref(false)
182
+ </script>
183
+
184
+ <template>
185
+ <section v-frost="{ loading, theme: 'pulse' }">Search results</section>
186
+ </template>
187
+ ```
188
+
189
+ ## API
190
+
191
+ | Function | What it does |
192
+ | --- | --- |
193
+ | `show(target, options?)` | Acquires one mask reference; returns an idempotent release callback. |
194
+ | `hide(target)` | Releases the oldest active reference. Prefer the callback when pairing with a specific operation. |
195
+ | `clear(target)` | Force-clears every reference and timer immediately. Old release callbacks cannot affect a new mask. |
196
+ | `mask(target, promise, options?)` | Acquires a mask until the promise settles and returns that same promise. |
197
+ | `resolveTarget(target)` | Resolves independently of showing a mask. |
198
+ | `configure(options)` | Merges defaults for subsequent calls; pass an option as `undefined` to reset it. |
199
+
200
+ Targets may be an `HTMLElement`, a CSS selector, an XPath prefixed with
201
+ `xpath:`, or a ref exposing `.nativeElement` (Angular), `.current` (React),
202
+ `.value` or `.$el` (Vue). For manual control with a dynamic selector or ref,
203
+ use the release callback returned by `show`; it remains tied to the original
204
+ element even if the selector or ref changes.
205
+
206
+ Options are optional. The first acquisition determines the overlay's
207
+ appearance and display timing for its whole lifetime; `timeout` is per
208
+ acquisition.
209
+
210
+ | Option | Meaning |
211
+ | --- | --- |
212
+ | `theme` | `material-circular` (default), `material-linear`, `skeleton`, `spinner`, `dots`, `bar`, or `pulse`. |
213
+ | `text`, `label` | Visible text and accessible label. If unset the accessible label is “Loading”. |
214
+ | `size` | `small`, `medium` (default), or `large`. |
215
+ | `minHeight` | Temporary minimum height for section targets, as pixels (number) or a CSS value. |
216
+ | `delay` | Milliseconds to wait before showing. Work that finishes sooner won't flash a mask. |
217
+ | `minDuration` | Minimum milliseconds the mask remains visible once shown. |
218
+ | `timeout` | Safety timeout in milliseconds for this reference. Does not cancel the operation. |
219
+ | `scrollIntoView` | Scrolls a section into view when it does not intersect the visible viewport or its scroll container. |
220
+ | `className` | Extra CSS classes for the wrapper. |
221
+ | `render` | Function returning a DOM element or trusted HTML string to replace built-in contents. |
222
+ | `injectStyles` | Set to `false` to supply your own CSS. Configure this before showing the first mask. |
223
+ | `nonce` | CSP nonce for the injected stylesheet. Set it before the first mask appears. |
224
+
225
+ The Material circular indicator uses a growing and shrinking arc. The Material
226
+ linear indicator runs along the top edge, and the skeleton shows three
227
+ shimmering placeholder lines.
228
+
229
+ Styles are injected on first display by default and respect reduced-motion
230
+ preferences. Colours follow the page's own `color-scheme`, so a light page stays
231
+ light on a device set to dark mode. To avoid inline style injection, import or serve
232
+ `@karan4/frostjs/style.css` and call `configure({ injectStyles: false })`. Override
233
+ `--frost-color`, `--frost-backdrop`, `--frost-blur`, or `--frost-z-index` on
234
+ the target or a parent. Browsers without backdrop filters get a solid backdrop.
235
+
236
+ ```ts
237
+ const release = show('#results', {
238
+ label: 'Preparing the report',
239
+ className: 'report-mask',
240
+ render: (target) => {
241
+ const message = target.ownerDocument.createElement('strong');
242
+ message.textContent = 'Preparing the report…';
243
+ return message;
244
+ },
245
+ });
246
+ ```
247
+
248
+ Prefer returning a DOM element and setting `textContent` for dynamic text.
249
+ Never use untrusted data as renderer HTML.
250
+
251
+ ## Security
252
+
253
+ - **Opt in to interception.** Importing the library does not change browser APIs.
254
+ Use `mask(target, promise)` or a client-specific interceptor if you don't
255
+ want a global patch. Frost is UI, not a network security control.
256
+ - **Metadata stays local.** Fetch strips `frost` and its legacy alias from the
257
+ options passed downstream; Axios removes both from its config. XHR keeps it as a property of
258
+ the request object, and Angular uses `HttpContext`. No metadata is added to
259
+ the URL, headers, or body, so it does not trigger a CORS preflight. The
260
+ adapters do not read or rewrite request or response bodies. The core has no
261
+ runtime dependencies.
262
+ - **Global wrappers still share the page.** Fetch and XHR call the implementation
263
+ installed when their adapter was enabled, including existing wrappers.
264
+ Uninstall restores the prior implementation if Frost is still outermost;
265
+ otherwise it disables its own wrapper without overwriting a newer patch.
266
+ Installation order matters, and code that saved the original function can
267
+ bypass the wrapper. Install each adapter once.
268
+ - **Content Security Policy.** Before the first mask, use
269
+ `configure({ nonce: pageStyleNonce })` with the server-generated nonce
270
+ permitted by the page's CSP. It is applied to the injected `<style>` element
271
+ before insertion; styles are injected only once per document. Alternatively,
272
+ import `@karan4/frostjs/style.css` from a CSP-allowed source and use
273
+ `configure({ injectStyles: false })`.
274
+ - **Renderer trust.** Built-in text and accessible labels are treated as plain
275
+ strings. HTML from custom renderers is inserted as-is, not sanitized. Never
276
+ pass user input or network content as renderer HTML. For dynamic text or under
277
+ Trusted Types enforcement, return a DOM element and use `textContent`.
278
+
279
+ ## Demo and development
280
+
281
+ ```sh
282
+ npm ci
283
+ npm run lint
284
+ npm test
285
+ npm run build
286
+ npm run demo
287
+ ```
288
+
289
+ Open `/demo/` at the local URL Vite prints. The demo uses a deterministic
290
+ simulated transport, so success, failure, and concurrent completion don't
291
+ depend on a public API.
292
+
293
+ ## Roadmap
294
+
295
+ Frost stays small: one job, no runtime dependencies. Planned, in order:
296
+
297
+ 1. **Releases from CI** with npm provenance.
298
+ 2. **`onShow` / `onHide` hooks** for analytics and logging.
299
+ 3. **Determinate progress** when the caller can measure it.
300
+ 4. **Svelte action and Solid directive**, each a few lines over `show()`.
301
+ 5. **1.0** once the API has been stable through real use.
302
+
303
+ Out of scope: error UI, retries, response parsing, a global "any request"
304
+ progress bar, and state-library integrations. These belong to the application
305
+ or to tools such as NProgress.
@@ -0,0 +1,21 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+ var _chunkBQNHIAZGcjs = require('./chunk-BQNHIAZG.cjs');
4
+ require('./chunk-4YG4GVLN.cjs');
5
+
6
+ // src/angular.ts
7
+ var _http = require('@angular/common/http');
8
+ var _rxjs = require('rxjs');
9
+ var FROST = new (0, _http.HttpContextToken)(() => void 0);
10
+ var frostInterceptor = (request, next) => {
11
+ const metadata = request.context.get(FROST);
12
+ if (metadata === void 0) return next(request);
13
+ return _rxjs.defer.call(void 0, () => {
14
+ const done = _chunkBQNHIAZGcjs.showRequest.call(void 0, metadata);
15
+ return _rxjs.defer.call(void 0, () => next(request)).pipe(_rxjs.finalize.call(void 0, done));
16
+ });
17
+ };
18
+
19
+
20
+
21
+ exports.FROST = FROST; exports.frostInterceptor = frostInterceptor;
@@ -0,0 +1,8 @@
1
+ import { HttpContextToken, HttpInterceptorFn } from '@angular/common/http';
2
+ import { RequestMask } from './index.cjs';
3
+ import './core-BfyKRh3F.cjs';
4
+
5
+ declare const FROST: HttpContextToken<RequestMask>;
6
+ declare const frostInterceptor: HttpInterceptorFn;
7
+
8
+ export { FROST, frostInterceptor };
@@ -0,0 +1,8 @@
1
+ import { HttpContextToken, HttpInterceptorFn } from '@angular/common/http';
2
+ import { RequestMask } from './index.js';
3
+ import './core-BfyKRh3F.js';
4
+
5
+ declare const FROST: HttpContextToken<RequestMask>;
6
+ declare const frostInterceptor: HttpInterceptorFn;
7
+
8
+ export { FROST, frostInterceptor };
@@ -0,0 +1,21 @@
1
+ import {
2
+ showRequest
3
+ } from "./chunk-LUZ2RD2S.js";
4
+ import "./chunk-M4BLR4QM.js";
5
+
6
+ // src/angular.ts
7
+ import { HttpContextToken } from "@angular/common/http";
8
+ import { defer, finalize } from "rxjs";
9
+ var FROST = new HttpContextToken(() => void 0);
10
+ var frostInterceptor = (request, next) => {
11
+ const metadata = request.context.get(FROST);
12
+ if (metadata === void 0) return next(request);
13
+ return defer(() => {
14
+ const done = showRequest(metadata);
15
+ return defer(() => next(request)).pipe(finalize(done));
16
+ });
17
+ };
18
+ export {
19
+ FROST,
20
+ frostInterceptor
21
+ };
@@ -0,0 +1,273 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// src/target.ts
2
+ function resolveTarget(target) {
3
+ if (typeof document === "undefined") return;
4
+ if (target === document || target === "body") {
5
+ return _nullishCoalesce(document.body, () => ( void 0));
6
+ }
7
+ const seen = /* @__PURE__ */ new Set();
8
+ while (target != null) {
9
+ if (typeof target === "string") {
10
+ try {
11
+ if (target.startsWith("xpath:")) {
12
+ target = document.evaluate(target.slice(6), document, null, 9, null).singleNodeValue;
13
+ } else {
14
+ target = document.querySelector(target);
15
+ }
16
+ } catch (e) {
17
+ return;
18
+ }
19
+ continue;
20
+ }
21
+ if (typeof target !== "object" || seen.has(target)) return;
22
+ if ("nodeType" in target) {
23
+ if (target.nodeType === 9) return _nullishCoalesce(target.body, () => ( void 0));
24
+ const el = target;
25
+ const HTML = _optionalChain([el, 'access', _ => _.ownerDocument, 'optionalAccess', _2 => _2.defaultView, 'optionalAccess', _3 => _3.HTMLElement]);
26
+ if (HTML && el instanceof HTML) return el;
27
+ return;
28
+ }
29
+ seen.add(target);
30
+ if ("nativeElement" in target) target = target.nativeElement;
31
+ else if ("current" in target) target = target.current;
32
+ else if ("$el" in target) target = target.$el;
33
+ else if ("value" in target) target = target.value;
34
+ else return;
35
+ }
36
+ }
37
+
38
+ // src/style.css?inline
39
+ var style_default = '.frost {\n --frost-unit: 2.25rem;\n --frost-solid: #f5f7ff;\n --frost-tint: rgb(245 247 255 / 65%);\n position: absolute;\n inset: 0;\n border-radius: inherit;\n z-index: var(--frost-z-index, 1000);\n display: flex;\n align-items: center;\n justify-content: center;\n flex-direction: column;\n gap: 0.75rem;\n background: var(--frost-backdrop, var(--frost-solid));\n color: var(--frost-color, #3431a6);\n font: 600 0.875rem/1.4 system-ui, sans-serif;\n cursor: progress;\n}\n.frost--page { position: fixed; touch-action: none; }\n.frost--small { --frost-unit: 1.5rem; }\n.frost--large { --frost-unit: 3.25rem; }\n.frost__indicator {\n box-sizing: border-box;\n display: block;\n width: var(--frost-unit);\n height: var(--frost-unit);\n}\n.frost__indicator--spinner {\n border: 0.2rem solid;\n border-right-color: transparent;\n border-radius: 50%;\n animation: frost-spin 0.8s linear infinite;\n}\n.frost__indicator--dots {\n display: flex;\n align-items: center;\n justify-content: center;\n gap: calc(var(--frost-unit) / 6);\n}\n.frost__indicator--dots > span {\n flex: 0 0 25%;\n aspect-ratio: 1;\n border-radius: 50%;\n background: currentColor;\n animation: frost-pulse 0.9s ease-in-out infinite alternate;\n}\n.frost__indicator--dots > span:nth-child(2) { animation-delay: 0.15s; }\n.frost__indicator--dots > span:nth-child(3) { animation-delay: 0.3s; }\n.frost__indicator--bar {\n width: calc(var(--frost-unit) * 2.5);\n height: 0.35rem;\n overflow: hidden;\n border-radius: 1rem;\n background: color-mix(in srgb, currentColor 18%, transparent);\n}\n.frost__indicator--bar::before {\n content: "";\n display: block;\n height: 100%;\n width: 45%;\n border-radius: inherit;\n background: currentColor;\n animation: frost-slide 0.95s ease-in-out infinite alternate;\n}\n.frost__indicator--pulse {\n border-radius: 50%;\n background: currentColor;\n animation: frost-pulse 0.85s ease-in-out infinite alternate;\n}\n.frost__indicator--material-circular {\n animation: frost-spin 1.5s linear infinite;\n}\n.frost__indicator--material-circular > svg {\n display: block;\n width: 100%;\n height: 100%;\n}\n.frost__indicator--material-circular circle {\n fill: none;\n stroke: currentColor;\n stroke-width: 4;\n stroke-linecap: round;\n stroke-dasharray: 28 72;\n animation: frost-arc 1.5s ease-in-out infinite;\n}\n.frost__indicator--material-linear {\n position: absolute;\n inset: 0 0 auto;\n width: auto;\n height: calc(var(--frost-unit) / 8);\n overflow: hidden;\n background: color-mix(in srgb, currentColor 18%, transparent);\n}\n.frost__indicator--material-linear::before,\n.frost__indicator--material-linear::after {\n content: "";\n position: absolute;\n inset-block: 0;\n left: 0;\n width: 42%;\n border-radius: 999px;\n background: currentColor;\n animation: frost-sweep 1.9s cubic-bezier(0.4, 0, 0.2, 1) infinite;\n}\n.frost__indicator--material-linear::after {\n width: 24%;\n animation-delay: 0.65s;\n}\n.frost__indicator--skeleton {\n display: flex;\n flex-direction: column;\n justify-content: space-between;\n width: min(75%, calc(var(--frost-unit) * 4));\n}\n.frost__indicator--skeleton > span {\n position: relative;\n height: 22%;\n overflow: hidden;\n border-radius: 999px;\n background: color-mix(in srgb, currentColor 16%, transparent);\n}\n.frost__indicator--skeleton > span:last-child { width: 62%; }\n.frost__indicator--skeleton > span::after {\n content: "";\n position: absolute;\n inset: 0;\n background: linear-gradient(90deg, transparent, color-mix(in srgb, currentColor 22%, transparent), transparent);\n animation: frost-shimmer 1.45s ease-in-out infinite;\n}\n@keyframes frost-spin { to { transform: rotate(1turn); } }\n@keyframes frost-pulse { from { opacity: 0.4; transform: scale(0.65); } }\n@keyframes frost-slide { to { transform: translateX(122%); } }\n@keyframes frost-arc {\n from { stroke-dasharray: 5 95; stroke-dashoffset: 0; }\n 50% { stroke-dasharray: 72 28; stroke-dashoffset: -18; }\n to { stroke-dasharray: 5 95; stroke-dashoffset: -100; }\n}\n@keyframes frost-sweep {\n from { left: 0; transform: translateX(-100%) scaleX(0.55); }\n 45% { transform: translateX(0) scaleX(1); }\n 85%, to { left: 100%; transform: translateX(0) scaleX(0.55); }\n}\n@keyframes frost-shimmer {\n from { transform: translateX(-100%); }\n to { transform: translateX(100%); }\n}\n@supports (color: light-dark(#000, #fff)) {\n .frost {\n --frost-solid: light-dark(#f5f7ff, #151627);\n --frost-tint: light-dark(rgb(245 247 255 / 65%), rgb(21 22 39 / 66%));\n color: var(--frost-color, light-dark(#3431a6, #c5c3ff));\n }\n}\n@supports (backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px)) {\n .frost {\n background: var(--frost-backdrop, var(--frost-tint));\n -webkit-backdrop-filter: blur(var(--frost-blur, 8px));\n backdrop-filter: blur(var(--frost-blur, 8px));\n }\n}\n@media (prefers-reduced-motion: reduce) {\n .frost__indicator,\n .frost__indicator > span,\n .frost__indicator::before,\n .frost__indicator::after,\n .frost__indicator--material-circular circle { animation: none; }\n .frost__indicator--material-linear::before { left: 29%; }\n .frost__indicator--material-linear::after,\n .frost__indicator--skeleton > span::after { display: none; }\n}\n';
40
+
41
+ // src/core.ts
42
+ var active = /* @__PURE__ */ new WeakMap();
43
+ var styles = /* @__PURE__ */ new WeakSet();
44
+ var defaults = {};
45
+ var noop = () => {
46
+ };
47
+ function configure(options) {
48
+ defaults = { ...defaults, ...options };
49
+ }
50
+ function visible(el) {
51
+ const view = el.ownerDocument.defaultView;
52
+ let { left, top, right, bottom } = el.getBoundingClientRect();
53
+ left = Math.max(0, left);
54
+ top = Math.max(0, top);
55
+ right = Math.min(view.innerWidth, right);
56
+ bottom = Math.min(view.innerHeight, bottom);
57
+ for (let parent = el.parentElement; parent; parent = parent.parentElement) {
58
+ const style = view.getComputedStyle(parent);
59
+ const rect = parent.getBoundingClientRect();
60
+ if (/auto|scroll|hidden|clip/.test(style.overflowX || style.overflow)) {
61
+ left = Math.max(left, rect.left);
62
+ right = Math.min(right, rect.right);
63
+ }
64
+ if (/auto|scroll|hidden|clip/.test(style.overflowY || style.overflow)) {
65
+ top = Math.max(top, rect.top);
66
+ bottom = Math.min(bottom, rect.bottom);
67
+ }
68
+ }
69
+ return right > left && bottom > top;
70
+ }
71
+ function createIndicator(doc, theme) {
72
+ const indicator = doc.createElement("span");
73
+ indicator.className = "frost__indicator frost__indicator--" + theme;
74
+ indicator.setAttribute("aria-hidden", "true");
75
+ if (theme === "material-circular") {
76
+ const svgNamespace = "http://www.w3.org/2000/svg";
77
+ const svg = doc.createElementNS(svgNamespace, "svg");
78
+ svg.setAttribute("viewBox", "0 0 48 48");
79
+ const arc = doc.createElementNS(svgNamespace, "circle");
80
+ arc.setAttribute("cx", "24");
81
+ arc.setAttribute("cy", "24");
82
+ arc.setAttribute("r", "20");
83
+ arc.setAttribute("pathLength", "100");
84
+ svg.append(arc);
85
+ indicator.append(svg);
86
+ } else if (theme === "dots" || theme === "skeleton") {
87
+ for (let i = 0; i < 3; i++) indicator.append(doc.createElement("span"));
88
+ }
89
+ return indicator;
90
+ }
91
+ function mount(el, options) {
92
+ const doc = el.ownerDocument;
93
+ const fullPage = el === doc.body || el === doc.documentElement;
94
+ const overlay = doc.createElement("div");
95
+ overlay.className = [
96
+ "frost",
97
+ fullPage && "frost--page",
98
+ "frost--" + (_nullishCoalesce(options.size, () => ( "medium"))),
99
+ options.className
100
+ ].filter(Boolean).join(" ");
101
+ overlay.setAttribute("role", "status");
102
+ overlay.setAttribute("aria-label", _nullishCoalesce(options.label, () => ( (options.text || "Loading"))));
103
+ const custom = _optionalChain([options, 'access', _4 => _4.render, 'optionalCall', _5 => _5(el)]);
104
+ if (typeof custom === "string") overlay.innerHTML = custom;
105
+ else if (custom) overlay.append(custom);
106
+ else {
107
+ overlay.append(createIndicator(doc, _nullishCoalesce(options.theme, () => ( "material-circular"))));
108
+ if (options.text) {
109
+ const text = doc.createElement("span");
110
+ text.textContent = options.text;
111
+ overlay.append(text);
112
+ }
113
+ }
114
+ const root = el.getRootNode();
115
+ const styleHost = "host" in root ? root : doc.head;
116
+ if (options.injectStyles !== false && !styles.has(styleHost)) {
117
+ const style = doc.createElement("style");
118
+ if (options.nonce !== void 0) style.nonce = options.nonce;
119
+ style.textContent = style_default;
120
+ styleHost.append(style);
121
+ styles.add(styleHost);
122
+ }
123
+ const restore = [];
124
+ const hadStyle = el.hasAttribute("style");
125
+ function setStyle(name, value) {
126
+ const old = el.style.getPropertyValue(name);
127
+ const priority = el.style.getPropertyPriority(name);
128
+ restore.unshift(() => {
129
+ if (old) el.style.setProperty(name, old, priority);
130
+ else el.style.removeProperty(name);
131
+ });
132
+ el.style.setProperty(name, value);
133
+ }
134
+ if (!fullPage) {
135
+ const position = _optionalChain([doc, 'access', _6 => _6.defaultView, 'optionalAccess', _7 => _7.getComputedStyle, 'call', _8 => _8(el), 'access', _9 => _9.position]);
136
+ if (!position || position === "static") setStyle("position", "relative");
137
+ if (options.minHeight !== void 0) {
138
+ const value = options.minHeight;
139
+ setStyle("min-height", typeof value === "number" ? value + "px" : value);
140
+ }
141
+ }
142
+ const focused = root.activeElement;
143
+ const busy = el.getAttribute("aria-busy");
144
+ el.setAttribute("aria-busy", "true");
145
+ const inert = /* @__PURE__ */ new Map();
146
+ const block = (child) => {
147
+ if (child === overlay || inert.has(child)) return;
148
+ inert.set(child, child.getAttribute("inert"));
149
+ child.setAttribute("inert", "");
150
+ };
151
+ for (const child of el.children) block(child);
152
+ const observer = new doc.defaultView.MutationObserver((records) => {
153
+ for (const record of records) {
154
+ for (const node of record.removedNodes) {
155
+ const child = node;
156
+ if (child.parentNode !== el && inert.has(child)) restoreInert(child);
157
+ }
158
+ for (const node of record.addedNodes) {
159
+ if (node.nodeType === 1 && node.parentNode === el) block(node);
160
+ }
161
+ }
162
+ });
163
+ function restoreInert(child) {
164
+ const original = inert.get(child);
165
+ if (original == null) child.removeAttribute("inert");
166
+ else child.setAttribute("inert", original);
167
+ inert.delete(child);
168
+ }
169
+ observer.observe(el, { childList: true });
170
+ el.append(overlay);
171
+ const place = () => {
172
+ const { scrollTop: top, scrollLeft: left } = el;
173
+ overlay.style.inset = top || left ? `${top}px ${-left}px ${-top}px ${left}px` : "";
174
+ };
175
+ if (!fullPage) {
176
+ place();
177
+ el.addEventListener("scroll", place, { passive: true });
178
+ if (options.minHeight === void 0 && overlay.firstElementChild) {
179
+ const first = overlay.firstElementChild.getBoundingClientRect();
180
+ const last = overlay.lastElementChild.getBoundingClientRect();
181
+ const needed = Math.ceil(last.bottom - first.top) + 16;
182
+ if (needed > 16 && needed > el.clientHeight) setStyle("min-height", needed + "px");
183
+ }
184
+ }
185
+ if (!fullPage && options.scrollIntoView && !visible(el)) {
186
+ _optionalChain([el, 'access', _10 => _10.scrollIntoView, 'optionalCall', _11 => _11({ block: "nearest", inline: "nearest" })]);
187
+ }
188
+ return () => {
189
+ observer.disconnect();
190
+ el.removeEventListener("scroll", place);
191
+ overlay.remove();
192
+ for (const child of inert.keys()) restoreInert(child);
193
+ if (busy === null) el.removeAttribute("aria-busy");
194
+ else el.setAttribute("aria-busy", busy);
195
+ for (const fn of restore) fn();
196
+ if (!hadStyle && !el.style.length) el.removeAttribute("style");
197
+ const current = root.activeElement;
198
+ if (focused instanceof doc.defaultView.HTMLElement && focused !== el && el.contains(focused) && (!current || current === doc.body)) {
199
+ focused.focus({ preventScroll: true });
200
+ }
201
+ };
202
+ }
203
+ function clearElement(el, state) {
204
+ if (active.get(el) !== state) return;
205
+ active.delete(el);
206
+ clearTimeout(state.delay);
207
+ clearTimeout(state.removal);
208
+ for (const ticket of state.tickets) clearTimeout(ticket.timer);
209
+ _optionalChain([state, 'access', _12 => _12.cleanup, 'optionalCall', _13 => _13()]);
210
+ }
211
+ function release(el, state, ticket) {
212
+ if (active.get(el) !== state || !state.tickets.delete(ticket)) return;
213
+ clearTimeout(ticket.timer);
214
+ if (state.tickets.size) return;
215
+ const remaining = state.shownAt === void 0 ? 0 : (_nullishCoalesce(state.options.minDuration, () => ( 0))) - (Date.now() - state.shownAt);
216
+ if (remaining > 0) state.removal = setTimeout(() => clearElement(el, state), remaining);
217
+ else clearElement(el, state);
218
+ }
219
+ function show(target, options) {
220
+ const el = resolveTarget(target);
221
+ if (!el) return noop;
222
+ const opts = { ...defaults, ...options };
223
+ let state = active.get(el);
224
+ const first = !state;
225
+ state ??= { tickets: /* @__PURE__ */ new Set(), options: opts };
226
+ active.set(el, state);
227
+ clearTimeout(state.removal);
228
+ const ticket = {};
229
+ state.tickets.add(ticket);
230
+ const entry = state;
231
+ const done = () => release(el, entry, ticket);
232
+ if (opts.timeout && opts.timeout > 0) ticket.timer = setTimeout(done, opts.timeout);
233
+ if (first) {
234
+ const start = () => {
235
+ if (active.get(el) !== entry) return;
236
+ try {
237
+ entry.cleanup = mount(el, opts);
238
+ } catch (error) {
239
+ clearElement(el, entry);
240
+ throw error;
241
+ }
242
+ entry.shownAt = Date.now();
243
+ };
244
+ if (opts.delay && opts.delay > 0) entry.delay = setTimeout(start, opts.delay);
245
+ else start();
246
+ }
247
+ return done;
248
+ }
249
+ function hide(target) {
250
+ const el = resolveTarget(target);
251
+ const state = el && active.get(el);
252
+ const ticket = _optionalChain([state, 'optionalAccess', _14 => _14.tickets, 'access', _15 => _15.values, 'call', _16 => _16(), 'access', _17 => _17.next, 'call', _18 => _18(), 'access', _19 => _19.value]);
253
+ if (el && state && ticket) release(el, state, ticket);
254
+ }
255
+ function clear(target) {
256
+ const el = resolveTarget(target);
257
+ const state = el && active.get(el);
258
+ if (el && state) clearElement(el, state);
259
+ }
260
+ function mask(target, promise, options) {
261
+ const done = show(target, options);
262
+ void promise.then(done, done);
263
+ return promise;
264
+ }
265
+
266
+
267
+
268
+
269
+
270
+
271
+
272
+
273
+ exports.resolveTarget = resolveTarget; exports.configure = configure; exports.show = show; exports.hide = hide; exports.clear = clear; exports.mask = mask;