@stacksjs/stx 0.2.189 → 0.2.191
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/dist/browser-composables.d.ts +24 -7
- package/dist/browser-composables.js +58 -17
- package/dist/cli.js +741 -722
- package/dist/component-library.js +1 -1
- package/dist/composable-loader.d.ts +21 -7
- package/dist/composable-loader.js +77 -8
- package/dist/composables/use-cookie.d.ts +8 -3
- package/dist/craft.js +334 -316
- package/dist/dev-server/crosswind.d.ts +26 -0
- package/dist/dev-server/crosswind.js +50 -34
- package/dist/process.js +12 -8
- package/dist/pwa.js +327 -309
- package/dist/signals.js +21 -3
- package/dist/ssg.d.ts +13 -0
- package/dist/ssg.js +354 -336
- package/dist/stx.d.ts +37 -6
- package/dist/typecheck.js +47 -1
- package/dist/types/config-types.d.ts +11 -0
- package/dist/utils.js +14 -1
- package/package.json +5 -5
- package/stx.d.ts +37 -6
|
@@ -153,19 +153,24 @@ export declare function useDebouncedValue<T>(getter: () => T, delay: number): {
|
|
|
153
153
|
*/
|
|
154
154
|
export declare function useThrottle<T extends (...args: any[]) => any>(fn: T, limit: number): (...args: Parameters<T>) => void;
|
|
155
155
|
/**
|
|
156
|
-
*
|
|
156
|
+
* Interval with controls, in both call forms.
|
|
157
|
+
*
|
|
158
|
+
* This is the module-import twin of the client runtime's `useInterval`, and the
|
|
159
|
+
* two must agree — a caller cannot tell which one their bundle resolved. It had
|
|
160
|
+
* drifted on three axes at once: no callback form (so `useInterval(fn, 1000)`
|
|
161
|
+
* passed the function as the delay, which coerces to `NaN`, which the platform
|
|
162
|
+
* clamps to 0 — a runaway timer incrementing a counter nobody could read); no
|
|
163
|
+
* `subscribe`; and `counter` wrapped in a `{ value }` object the runtime does
|
|
164
|
+
* not use. `immediate` was accepted, documented, and used as an initial "is
|
|
165
|
+
* paused" flag rather than "tick right away" (#1941).
|
|
157
166
|
*
|
|
158
167
|
* @example
|
|
159
168
|
* ```typescript
|
|
160
169
|
* const { counter, pause, resume, reset } = useInterval(1000)
|
|
170
|
+
* const poll = useInterval(() => refresh(), 60_000)
|
|
161
171
|
* ```
|
|
162
172
|
*/
|
|
163
|
-
export declare function useInterval(interval: number, options?:
|
|
164
|
-
counter: { readonly value: number }
|
|
165
|
-
pause: () => void
|
|
166
|
-
resume: () => void
|
|
167
|
-
reset: () => void
|
|
168
|
-
};
|
|
173
|
+
export declare function useInterval(interval?: number | ((count: number) => void), options?: number | IntervalOptions, thirdOptions?: IntervalOptions): IntervalControls;
|
|
169
174
|
/**
|
|
170
175
|
* One-time timeout with controls.
|
|
171
176
|
*
|
|
@@ -310,6 +315,18 @@ export declare interface BreakpointsRef {
|
|
|
310
315
|
isDesktop: { readonly value: boolean }
|
|
311
316
|
isLargeDesktop: { readonly value: boolean }
|
|
312
317
|
}
|
|
318
|
+
export declare interface IntervalOptions {
|
|
319
|
+
immediate?: boolean
|
|
320
|
+
enabled?: boolean | (() => boolean)
|
|
321
|
+
whileVisible?: boolean
|
|
322
|
+
}
|
|
323
|
+
export declare interface IntervalControls {
|
|
324
|
+
readonly counter: number
|
|
325
|
+
pause: () => void
|
|
326
|
+
resume: () => void
|
|
327
|
+
reset: () => void
|
|
328
|
+
subscribe: (fn: (count: number) => void) => () => void
|
|
329
|
+
}
|
|
313
330
|
// =============================================================================
|
|
314
331
|
// Async Composables
|
|
315
332
|
// =============================================================================
|
|
@@ -272,36 +272,77 @@ export function useThrottle(fn, limit) {
|
|
|
272
272
|
});
|
|
273
273
|
return throttledFn;
|
|
274
274
|
}
|
|
275
|
-
export function useInterval(interval, options
|
|
276
|
-
let
|
|
277
|
-
|
|
278
|
-
|
|
275
|
+
export function useInterval(interval, options, thirdOptions) {
|
|
276
|
+
let callback = null, delay, opts;
|
|
277
|
+
if (typeof interval === "function") {
|
|
278
|
+
callback = interval;
|
|
279
|
+
if (typeof options === "number") {
|
|
280
|
+
delay = options;
|
|
281
|
+
opts = thirdOptions || {};
|
|
282
|
+
} else {
|
|
283
|
+
delay = 1000;
|
|
284
|
+
opts = options && typeof options === "object" ? options : {};
|
|
285
|
+
}
|
|
286
|
+
} else {
|
|
287
|
+
delay = interval || 1000;
|
|
288
|
+
opts = typeof options === "object" && options ? options : {};
|
|
289
|
+
}
|
|
290
|
+
let count = 0, id = null, running = !1, listeners = [];
|
|
291
|
+
const shouldTick = () => {
|
|
292
|
+
if (opts.whileVisible && typeof document < "u" && document.hidden)
|
|
293
|
+
return !1;
|
|
294
|
+
const enabled = opts.enabled;
|
|
295
|
+
if (typeof enabled === "function")
|
|
296
|
+
return !!enabled();
|
|
297
|
+
return enabled !== !1;
|
|
298
|
+
}, tick = () => {
|
|
299
|
+
if (!shouldTick())
|
|
279
300
|
return;
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
count++;
|
|
283
|
-
}, interval);
|
|
284
|
-
}, pause = () => {
|
|
285
|
-
isActive = !1;
|
|
301
|
+
count++;
|
|
302
|
+
listeners.forEach((fn) => fn(count));
|
|
286
303
|
}, resume = () => {
|
|
287
|
-
|
|
304
|
+
if (running)
|
|
305
|
+
return;
|
|
306
|
+
running = !0;
|
|
307
|
+
id = setInterval(tick, delay);
|
|
308
|
+
if (opts.immediate)
|
|
309
|
+
tick();
|
|
310
|
+
}, pause = () => {
|
|
311
|
+
if (!running)
|
|
312
|
+
return;
|
|
313
|
+
running = !1;
|
|
314
|
+
if (id !== null) {
|
|
315
|
+
clearInterval(id);
|
|
316
|
+
id = null;
|
|
317
|
+
}
|
|
288
318
|
}, reset = () => {
|
|
319
|
+
pause();
|
|
289
320
|
count = 0;
|
|
321
|
+
listeners.forEach((fn) => fn(count));
|
|
322
|
+
resume();
|
|
290
323
|
};
|
|
324
|
+
if (callback)
|
|
325
|
+
listeners.push(callback);
|
|
291
326
|
if (typeof window < "u") {
|
|
292
|
-
|
|
327
|
+
resume();
|
|
293
328
|
onDestroy(() => {
|
|
294
|
-
|
|
295
|
-
|
|
329
|
+
pause();
|
|
330
|
+
listeners = [];
|
|
296
331
|
});
|
|
297
332
|
}
|
|
298
333
|
return {
|
|
299
|
-
|
|
334
|
+
get counter() {
|
|
300
335
|
return count;
|
|
301
|
-
}
|
|
336
|
+
},
|
|
302
337
|
pause,
|
|
303
338
|
resume,
|
|
304
|
-
reset
|
|
339
|
+
reset,
|
|
340
|
+
subscribe(fn) {
|
|
341
|
+
listeners.push(fn);
|
|
342
|
+
return () => {
|
|
343
|
+
listeners = listeners.filter((f) => f !== fn);
|
|
344
|
+
};
|
|
345
|
+
}
|
|
305
346
|
};
|
|
306
347
|
}
|
|
307
348
|
export function useTimeout(callback, delay) {
|