@bereasoftware/time-guard 2.7.2 → 2.9.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.en.md +5 -1
- package/README.md +5 -1
- package/dist/adapters/temporal.adapter.d.ts +6 -2
- package/dist/angular/index.cjs +1 -148
- package/dist/angular/index.es.js +63 -112
- package/dist/calendars/index.cjs +1 -357
- package/dist/calendars/index.es.js +66 -99
- package/dist/chunk-C6qsp3rV.cjs +1 -0
- package/dist/core-BDQnStek.cjs +1 -0
- package/dist/core-GHK7isoa.js +1200 -0
- package/dist/core.d.ts +27 -1
- package/dist/index.d.ts +4 -2
- package/dist/locales/index.cjs +1 -7
- package/dist/locales/index.d.ts +11 -0
- package/dist/locales/index.es.js +3 -3
- package/dist/{locales-CGdn0DJN.cjs → locales-Dwe5oGoy.js} +201 -82
- package/dist/locales-bc-5kDuZ.cjs +1 -0
- package/dist/native/index.cjs +1 -48
- package/dist/native/index.es.js +8 -18
- package/dist/plugins/advanced-format/index.d.ts +8 -0
- package/dist/plugins/advanced-format.cjs +1 -105
- package/dist/plugins/advanced-format.es.js +48 -63
- package/dist/plugins/duration/index.d.ts +6 -0
- package/dist/plugins/duration.cjs +1 -258
- package/dist/plugins/duration.es.js +63 -165
- package/dist/plugins/manager.d.ts +6 -2
- package/dist/plugins/relative-time/index.d.ts +6 -0
- package/dist/plugins/relative-time.cjs +1 -166
- package/dist/plugins/relative-time.es.js +39 -74
- package/dist/qwik/index.cjs +1 -104
- package/dist/qwik/index.es.js +36 -94
- package/dist/qwik.d.ts +5 -1
- package/dist/react/index.cjs +1 -112
- package/dist/react/index.es.js +57 -91
- package/dist/solid/index.cjs +1 -127
- package/dist/solid/index.es.js +36 -116
- package/dist/solid.d.ts +5 -2
- package/dist/svelte/index.cjs +1 -398
- package/dist/svelte/index.es.js +85 -344
- package/dist/time-guard.cjs +3 -7359
- package/dist/time-guard.es.js +3412 -3625
- package/dist/time-guard.iife.js +3 -13549
- package/dist/time-guard.umd.js +3 -13550
- package/dist/types/index.d.ts +10 -0
- package/dist/vue/index.cjs +1 -143
- package/dist/vue/index.es.js +62 -116
- package/dist/vue.d.ts +5 -3
- package/package.json +3 -4
- package/dist/chunk-S8Y6Ng9i.cjs +0 -36
- package/dist/core-BIDjudpO.cjs +0 -1892
- package/dist/core-DWPXk3rz.js +0 -1809
- package/dist/locales-BUE_aq8K.js +0 -3514
package/dist/solid/index.es.js
CHANGED
|
@@ -1,122 +1,42 @@
|
|
|
1
|
-
/*! time-guard v2.
|
|
2
|
-
import {
|
|
3
|
-
import { createEffect, createSignal, onCleanup } from "solid-js";
|
|
1
|
+
/*! time-guard v2.9.0 | (c) 2026 Berea-Soft | MIT License | https://github.com/Berea-Soft/time-guard */
|
|
2
|
+
import { i as e, o as t, s as n } from "../core-GHK7isoa.js";
|
|
3
|
+
import { createEffect as r, createSignal as i, onCleanup as a } from "solid-js";
|
|
4
4
|
//#region src/solid.ts
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
* Provides reactive signal-based wrappers for TimeGuard using Solid's
|
|
9
|
-
* fine-grained reactivity system. All hooks return signals (`Accessor`)
|
|
10
|
-
* that automatically update without re-rendering the entire component tree.
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* ```tsx
|
|
14
|
-
* import { useCurrentTime, useRelativeTime } from '@bereasoftware/time-guard/solid';
|
|
15
|
-
*
|
|
16
|
-
* function Clock() {
|
|
17
|
-
* const now = useCurrentTime({ interval: 1000 });
|
|
18
|
-
* const relative = useRelativeTime('2026-05-20T08:00:00');
|
|
19
|
-
*
|
|
20
|
-
* return (
|
|
21
|
-
* <div>
|
|
22
|
-
* <h1>{now().format('HH:mm:ss')}</h1>
|
|
23
|
-
* <p>Published: {relative()}</p>
|
|
24
|
-
* </div>
|
|
25
|
-
* );
|
|
26
|
-
* }
|
|
27
|
-
* ```
|
|
28
|
-
*/
|
|
29
|
-
/**
|
|
30
|
-
* Context key for providing global TimeGuard configuration.
|
|
31
|
-
* Use Solid's `createContext` + `useContext` at the app level.
|
|
32
|
-
*/
|
|
33
|
-
var TimeGuardConfigContext = Symbol("TimeGuardConfig");
|
|
34
|
-
/**
|
|
35
|
-
* Creates a reactive signal of a TimeGuard instance.
|
|
36
|
-
* The signal updates reactively when `input` changes.
|
|
37
|
-
*
|
|
38
|
-
* ```tsx
|
|
39
|
-
* const tg = useTimeGuard('2026-05-20');
|
|
40
|
-
* return <p>{tg().format('dddd, DD MMMM YYYY')}</p>;
|
|
41
|
-
* ```
|
|
42
|
-
*/
|
|
43
|
-
function useTimeGuard(input, config) {
|
|
44
|
-
const [tg, setTg] = createSignal(TimeGuard.from(input, config));
|
|
45
|
-
createEffect(() => {
|
|
46
|
-
const _input = input;
|
|
47
|
-
setTg(() => TimeGuard.from(_input, config));
|
|
48
|
-
});
|
|
49
|
-
return tg;
|
|
5
|
+
var o = Symbol("TimeGuardConfig");
|
|
6
|
+
function s(e) {
|
|
7
|
+
return typeof e == "function" ? e() : e;
|
|
50
8
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
* const now = useCurrentTime({ interval: 1000 });
|
|
57
|
-
* return <p>{now().format('HH:mm:ss')}</p>;
|
|
58
|
-
* ```
|
|
59
|
-
*/
|
|
60
|
-
function useCurrentTime(options) {
|
|
61
|
-
const interval = options?.interval ?? 1e3;
|
|
62
|
-
const config = options?.config;
|
|
63
|
-
const [time, setTime] = createSignal(TimeGuard.now(config));
|
|
64
|
-
const timer = setInterval(() => {
|
|
65
|
-
setTime(TimeGuard.now(config));
|
|
66
|
-
}, interval);
|
|
67
|
-
onCleanup(() => {
|
|
68
|
-
clearInterval(timer);
|
|
69
|
-
});
|
|
70
|
-
return time;
|
|
9
|
+
function c(t, n) {
|
|
10
|
+
let [a, o] = i(e.from(s(t), n));
|
|
11
|
+
return r(() => {
|
|
12
|
+
o(() => e.from(s(t), n));
|
|
13
|
+
}), a;
|
|
71
14
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
* ```
|
|
80
|
-
*/
|
|
81
|
-
function useRelativeTime(date, options) {
|
|
82
|
-
const interval = options?.interval ?? 6e4;
|
|
83
|
-
const locale = options?.locale;
|
|
84
|
-
const numeric = options?.numeric;
|
|
85
|
-
const compute = () => {
|
|
86
|
-
const tgDate = TimeGuard.from(date);
|
|
87
|
-
const now = TimeGuard.now();
|
|
88
|
-
return tgDate.since(now).humanize({
|
|
89
|
-
locale,
|
|
90
|
-
numeric
|
|
91
|
-
});
|
|
92
|
-
};
|
|
93
|
-
const [relative, setRelative] = createSignal(compute());
|
|
94
|
-
const timer = setInterval(() => {
|
|
95
|
-
setRelative(compute());
|
|
96
|
-
}, interval);
|
|
97
|
-
onCleanup(() => {
|
|
98
|
-
clearInterval(timer);
|
|
99
|
-
});
|
|
100
|
-
return relative;
|
|
15
|
+
function l(t) {
|
|
16
|
+
let n = t?.interval ?? 1e3, r = t?.config, [o, s] = i(e.now(r)), c = setInterval(() => {
|
|
17
|
+
s(e.now(r));
|
|
18
|
+
}, n);
|
|
19
|
+
return a(() => {
|
|
20
|
+
clearInterval(c);
|
|
21
|
+
}), o;
|
|
101
22
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
});
|
|
119
|
-
return range;
|
|
23
|
+
function u(e, n) {
|
|
24
|
+
let r = n?.interval ?? 6e4, o = n?.locale, s = n?.numeric, c = () => t(e, {
|
|
25
|
+
locale: o,
|
|
26
|
+
numeric: s
|
|
27
|
+
}), [l, u] = i(c()), d = setInterval(() => {
|
|
28
|
+
u(c());
|
|
29
|
+
}, r);
|
|
30
|
+
return a(() => {
|
|
31
|
+
clearInterval(d);
|
|
32
|
+
}), l;
|
|
33
|
+
}
|
|
34
|
+
function d(e, t, a) {
|
|
35
|
+
let [o, s] = i(n(e, t, a));
|
|
36
|
+
return r(() => {
|
|
37
|
+
let r = e, i = t;
|
|
38
|
+
s(() => n(r, i, a));
|
|
39
|
+
}), o;
|
|
120
40
|
}
|
|
121
41
|
//#endregion
|
|
122
|
-
export { TimeGuardConfigContext, useCurrentTime, useRelativeTime, useTimeGuard, useTimeRange };
|
|
42
|
+
export { o as TimeGuardConfigContext, l as useCurrentTime, u as useRelativeTime, c as useTimeGuard, d as useTimeRange };
|
package/dist/solid.d.ts
CHANGED
|
@@ -7,10 +7,13 @@ import { TimeGuard, ITimeGuardConfig, TimeRange } from './core';
|
|
|
7
7
|
export declare const TimeGuardConfigContext: unique symbol;
|
|
8
8
|
/**
|
|
9
9
|
* Creates a reactive signal of a TimeGuard instance.
|
|
10
|
-
* The signal updates reactively when `input` changes
|
|
10
|
+
* The signal updates reactively when `input` changes — pass an Accessor
|
|
11
|
+
* (e.g. a signal getter) for `input` to make this actually track it; a
|
|
12
|
+
* plain value is used once and won't update on its own.
|
|
11
13
|
*
|
|
12
14
|
* ```tsx
|
|
13
|
-
* const
|
|
15
|
+
* const [dateStr, setDateStr] = createSignal('2026-05-20');
|
|
16
|
+
* const tg = useTimeGuard(dateStr); // note: dateStr, not dateStr()
|
|
14
17
|
* return <p>{tg().format('dddd, DD MMMM YYYY')}</p>;
|
|
15
18
|
* ```
|
|
16
19
|
*/
|
package/dist/svelte/index.cjs
CHANGED
|
@@ -1,398 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const require_core = require("../core-BIDjudpO.cjs");
|
|
4
|
-
Array.isArray;
|
|
5
|
-
Array.prototype.indexOf;
|
|
6
|
-
Array.prototype.includes;
|
|
7
|
-
Array.from;
|
|
8
|
-
Array.prototype;
|
|
9
|
-
var noop = () => {};
|
|
10
|
-
/** @param {Array<() => void>} arr */
|
|
11
|
-
function run_all(arr) {
|
|
12
|
-
for (var i = 0; i < arr.length; i++) arr[i]();
|
|
13
|
-
}
|
|
14
|
-
//#endregion
|
|
15
|
-
//#region node_modules/.pnpm/svelte@5.55.9_@typescript-eslint+types@8.59.4/node_modules/svelte/src/internal/client/constants.js
|
|
16
|
-
var CLEAN = 1024;
|
|
17
|
-
var DIRTY = 2048;
|
|
18
|
-
var MAYBE_DIRTY = 4096;
|
|
19
|
-
/**
|
|
20
|
-
* 'Transparent' effects do not create a transition boundary.
|
|
21
|
-
* This is on a block effect 99% of the time but may also be on a branch effect if its parent block effect was pruned
|
|
22
|
-
*/
|
|
23
|
-
var EFFECT_TRANSPARENT = 65536;
|
|
24
|
-
var EFFECT_PRESERVED = 1 << 19;
|
|
25
|
-
new class StaleReactionError extends Error {
|
|
26
|
-
name = "StaleReactionError";
|
|
27
|
-
message = "The reaction that called `getAbortSignal()` was re-run or destroyed";
|
|
28
|
-
}();
|
|
29
|
-
globalThis.document?.contentType;
|
|
30
|
-
//#endregion
|
|
31
|
-
//#region node_modules/.pnpm/svelte@5.55.9_@typescript-eslint+types@8.59.4/node_modules/svelte/src/internal/client/reactivity/equality.js
|
|
32
|
-
/**
|
|
33
|
-
* @param {unknown} a
|
|
34
|
-
* @param {unknown} b
|
|
35
|
-
* @returns {boolean}
|
|
36
|
-
*/
|
|
37
|
-
function safe_not_equal(a, b) {
|
|
38
|
-
return a != a ? b == b : a !== b || a !== null && typeof a === "object" || typeof a === "function";
|
|
39
|
-
}
|
|
40
|
-
~(DIRTY | MAYBE_DIRTY | CLEAN);
|
|
41
|
-
//#endregion
|
|
42
|
-
//#region node_modules/.pnpm/svelte@5.55.9_@typescript-eslint+types@8.59.4/node_modules/svelte/src/store/utils.js
|
|
43
|
-
/** @import { Readable } from './public' */
|
|
44
|
-
/**
|
|
45
|
-
* @template T
|
|
46
|
-
* @param {Readable<T> | null | undefined} store
|
|
47
|
-
* @param {(value: T) => void} run
|
|
48
|
-
* @param {(value: T) => void} [invalidate]
|
|
49
|
-
* @returns {() => void}
|
|
50
|
-
*/
|
|
51
|
-
function subscribe_to_store(store, run, invalidate) {
|
|
52
|
-
if (store == null) {
|
|
53
|
-
run(void 0);
|
|
54
|
-
if (invalidate) invalidate(void 0);
|
|
55
|
-
return noop;
|
|
56
|
-
}
|
|
57
|
-
const unsub = untrack(() => store.subscribe(run, invalidate));
|
|
58
|
-
return unsub.unsubscribe ? () => unsub.unsubscribe() : unsub;
|
|
59
|
-
}
|
|
60
|
-
//#endregion
|
|
61
|
-
//#region node_modules/.pnpm/svelte@5.55.9_@typescript-eslint+types@8.59.4/node_modules/svelte/src/store/shared/index.js
|
|
62
|
-
/** @import { Readable, StartStopNotifier, Subscriber, Unsubscriber, Updater, Writable } from '../public.js' */
|
|
63
|
-
/** @import { Stores, StoresValues, SubscribeInvalidateTuple } from '../private.js' */
|
|
64
|
-
/**
|
|
65
|
-
* @type {Array<SubscribeInvalidateTuple<any> | any>}
|
|
66
|
-
*/
|
|
67
|
-
var subscriber_queue = [];
|
|
68
|
-
/**
|
|
69
|
-
* Creates a `Readable` store that allows reading by subscription.
|
|
70
|
-
*
|
|
71
|
-
* @template T
|
|
72
|
-
* @param {T} [value] initial value
|
|
73
|
-
* @param {StartStopNotifier<T>} [start]
|
|
74
|
-
* @returns {Readable<T>}
|
|
75
|
-
*/
|
|
76
|
-
function readable(value, start) {
|
|
77
|
-
return { subscribe: writable(value, start).subscribe };
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Create a `Writable` store that allows both updating and reading by subscription.
|
|
81
|
-
*
|
|
82
|
-
* @template T
|
|
83
|
-
* @param {T} [value] initial value
|
|
84
|
-
* @param {StartStopNotifier<T>} [start]
|
|
85
|
-
* @returns {Writable<T>}
|
|
86
|
-
*/
|
|
87
|
-
function writable(value, start = noop) {
|
|
88
|
-
/** @type {Unsubscriber | null} */
|
|
89
|
-
let stop = null;
|
|
90
|
-
/** @type {Set<SubscribeInvalidateTuple<T>>} */
|
|
91
|
-
const subscribers = /* @__PURE__ */ new Set();
|
|
92
|
-
/**
|
|
93
|
-
* @param {T} new_value
|
|
94
|
-
* @returns {void}
|
|
95
|
-
*/
|
|
96
|
-
function set(new_value) {
|
|
97
|
-
if (safe_not_equal(value, new_value)) {
|
|
98
|
-
value = new_value;
|
|
99
|
-
if (stop) {
|
|
100
|
-
const run_queue = !subscriber_queue.length;
|
|
101
|
-
for (const subscriber of subscribers) {
|
|
102
|
-
subscriber[1]();
|
|
103
|
-
subscriber_queue.push(subscriber, value);
|
|
104
|
-
}
|
|
105
|
-
if (run_queue) {
|
|
106
|
-
for (let i = 0; i < subscriber_queue.length; i += 2) subscriber_queue[i][0](subscriber_queue[i + 1]);
|
|
107
|
-
subscriber_queue.length = 0;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
/**
|
|
113
|
-
* @param {Updater<T>} fn
|
|
114
|
-
* @returns {void}
|
|
115
|
-
*/
|
|
116
|
-
function update(fn) {
|
|
117
|
-
set(fn(value));
|
|
118
|
-
}
|
|
119
|
-
/**
|
|
120
|
-
* @param {Subscriber<T>} run
|
|
121
|
-
* @param {() => void} [invalidate]
|
|
122
|
-
* @returns {Unsubscriber}
|
|
123
|
-
*/
|
|
124
|
-
function subscribe(run, invalidate = noop) {
|
|
125
|
-
/** @type {SubscribeInvalidateTuple<T>} */
|
|
126
|
-
const subscriber = [run, invalidate];
|
|
127
|
-
subscribers.add(subscriber);
|
|
128
|
-
if (subscribers.size === 1) stop = start(set, update) || noop;
|
|
129
|
-
run(value);
|
|
130
|
-
return () => {
|
|
131
|
-
subscribers.delete(subscriber);
|
|
132
|
-
if (subscribers.size === 0 && stop) {
|
|
133
|
-
stop();
|
|
134
|
-
stop = null;
|
|
135
|
-
}
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
|
-
return {
|
|
139
|
-
set,
|
|
140
|
-
update,
|
|
141
|
-
subscribe
|
|
142
|
-
};
|
|
143
|
-
}
|
|
144
|
-
/**
|
|
145
|
-
* Derived value store by synchronizing one or more readable stores and
|
|
146
|
-
* applying an aggregation function over its input values.
|
|
147
|
-
*
|
|
148
|
-
* @template {Stores} S
|
|
149
|
-
* @template T
|
|
150
|
-
* @overload
|
|
151
|
-
* @param {S} stores
|
|
152
|
-
* @param {(values: StoresValues<S>, set: (value: T) => void, update: (fn: Updater<T>) => void) => Unsubscriber | void} fn
|
|
153
|
-
* @param {T} [initial_value]
|
|
154
|
-
* @returns {Readable<T>}
|
|
155
|
-
*/
|
|
156
|
-
/**
|
|
157
|
-
* Derived value store by synchronizing one or more readable stores and
|
|
158
|
-
* applying an aggregation function over its input values.
|
|
159
|
-
*
|
|
160
|
-
* @template {Stores} S
|
|
161
|
-
* @template T
|
|
162
|
-
* @overload
|
|
163
|
-
* @param {S} stores
|
|
164
|
-
* @param {(values: StoresValues<S>) => T} fn
|
|
165
|
-
* @param {T} [initial_value]
|
|
166
|
-
* @returns {Readable<T>}
|
|
167
|
-
*/
|
|
168
|
-
/**
|
|
169
|
-
* @template {Stores} S
|
|
170
|
-
* @template T
|
|
171
|
-
* @param {S} stores
|
|
172
|
-
* @param {Function} fn
|
|
173
|
-
* @param {T} [initial_value]
|
|
174
|
-
* @returns {Readable<T>}
|
|
175
|
-
*/
|
|
176
|
-
function derived(stores, fn, initial_value) {
|
|
177
|
-
const single = !Array.isArray(stores);
|
|
178
|
-
/** @type {Array<Readable<any>>} */
|
|
179
|
-
const stores_array = single ? [stores] : stores;
|
|
180
|
-
if (!stores_array.every(Boolean)) throw new Error("derived() expects stores as input, got a falsy value");
|
|
181
|
-
const auto = fn.length < 2;
|
|
182
|
-
return readable(initial_value, (set, update) => {
|
|
183
|
-
let started = false;
|
|
184
|
-
/** @type {T[]} */
|
|
185
|
-
const values = [];
|
|
186
|
-
let pending = 0;
|
|
187
|
-
let cleanup = noop;
|
|
188
|
-
const sync = () => {
|
|
189
|
-
if (pending) return;
|
|
190
|
-
cleanup();
|
|
191
|
-
const result = fn(single ? values[0] : values, set, update);
|
|
192
|
-
if (auto) set(result);
|
|
193
|
-
else cleanup = typeof result === "function" ? result : noop;
|
|
194
|
-
};
|
|
195
|
-
const unsubscribers = stores_array.map((store, i) => subscribe_to_store(store, (value) => {
|
|
196
|
-
values[i] = value;
|
|
197
|
-
pending &= ~(1 << i);
|
|
198
|
-
if (started) sync();
|
|
199
|
-
}, () => {
|
|
200
|
-
pending |= 1 << i;
|
|
201
|
-
}));
|
|
202
|
-
started = true;
|
|
203
|
-
sync();
|
|
204
|
-
return function stop() {
|
|
205
|
-
run_all(unsubscribers);
|
|
206
|
-
cleanup();
|
|
207
|
-
started = false;
|
|
208
|
-
};
|
|
209
|
-
});
|
|
210
|
-
}
|
|
211
|
-
EFFECT_TRANSPARENT | EFFECT_PRESERVED;
|
|
212
|
-
//#endregion
|
|
213
|
-
//#region node_modules/.pnpm/svelte@5.55.9_@typescript-eslint+types@8.59.4/node_modules/svelte/src/internal/client/runtime.js
|
|
214
|
-
var untracking = false;
|
|
215
|
-
/**
|
|
216
|
-
* When used inside a [`$derived`](https://svelte.dev/docs/svelte/$derived) or [`$effect`](https://svelte.dev/docs/svelte/$effect),
|
|
217
|
-
* any state read inside `fn` will not be treated as a dependency.
|
|
218
|
-
*
|
|
219
|
-
* ```ts
|
|
220
|
-
* $effect(() => {
|
|
221
|
-
* // this will run when `data` changes, but not when `time` changes
|
|
222
|
-
* save(data, {
|
|
223
|
-
* timestamp: untrack(() => time)
|
|
224
|
-
* });
|
|
225
|
-
* });
|
|
226
|
-
* ```
|
|
227
|
-
* @template T
|
|
228
|
-
* @param {() => T} fn
|
|
229
|
-
* @returns {T}
|
|
230
|
-
*/
|
|
231
|
-
function untrack(fn) {
|
|
232
|
-
var previous_untracking = untracking;
|
|
233
|
-
try {
|
|
234
|
-
untracking = true;
|
|
235
|
-
return fn();
|
|
236
|
-
} finally {
|
|
237
|
-
untracking = previous_untracking;
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
//#endregion
|
|
241
|
-
//#region src/svelte.ts
|
|
242
|
-
/**
|
|
243
|
-
* TimeGuard — Svelte 5 Integration
|
|
244
|
-
*
|
|
245
|
-
* Provides reactive stores and lifecycle-managed wrappers for TimeGuard.
|
|
246
|
-
* Compatible with both Svelte 4 (`$store` auto-subscription) and
|
|
247
|
-
* Svelte 5 (`$state` + `get()` from stores).
|
|
248
|
-
*
|
|
249
|
-
* @example
|
|
250
|
-
* ```svelte
|
|
251
|
-
* <script lang="ts">
|
|
252
|
-
* import { useCurrentTime, useRelativeTime } from '@bereasoftware/time-guard/svelte';
|
|
253
|
-
*
|
|
254
|
-
* const now = useCurrentTime({ interval: 1000 });
|
|
255
|
-
* const relative = useRelativeTime('2026-05-20T08:00:00');
|
|
256
|
-
* <\/script>
|
|
257
|
-
*
|
|
258
|
-
* <h1>{$now.format('HH:mm:ss')}</h1>
|
|
259
|
-
* <p>Published: {$relative}</p>
|
|
260
|
-
* ```
|
|
261
|
-
*/
|
|
262
|
-
/**
|
|
263
|
-
* Duck-type check: is this a Svelte store (has `subscribe`)?
|
|
264
|
-
*/
|
|
265
|
-
function isStore(val) {
|
|
266
|
-
return typeof val === "object" && val !== null && "subscribe" in val && typeof val.subscribe === "function";
|
|
267
|
-
}
|
|
268
|
-
/**
|
|
269
|
-
* Coerce a plain value or a store into a Readable store.
|
|
270
|
-
*/
|
|
271
|
-
function toStore(val) {
|
|
272
|
-
return isStore(val) ? val : readable(val);
|
|
273
|
-
}
|
|
274
|
-
/**
|
|
275
|
-
* Injection-key symbol to retrieve a global TimeGuard configuration
|
|
276
|
-
* provided at the app root. Consumers use `getContext(TimeGuardConfigKey)`.
|
|
277
|
-
*/
|
|
278
|
-
var TimeGuardConfigKey = Symbol("TimeGuardConfig");
|
|
279
|
-
/**
|
|
280
|
-
* Creates a reactive readable store of a TimeGuard instance.
|
|
281
|
-
* Automatically updates when `input` changes (supports both plain values
|
|
282
|
-
* and Svelte stores as input — pass a `Readable` for full reactivity).
|
|
283
|
-
* Integrates global config from `getContext(TimeGuardConfigKey)` as fallback.
|
|
284
|
-
*
|
|
285
|
-
* ```svelte
|
|
286
|
-
* <script>
|
|
287
|
-
* import { writable } from 'svelte/store';
|
|
288
|
-
* import { useTimeGuard } from '@bereasoftware/time-guard/svelte';
|
|
289
|
-
* import { TimeGuard } from '@bereasoftware/time-guard';
|
|
290
|
-
*
|
|
291
|
-
* // Static input — no reactivity needed
|
|
292
|
-
* const tg = useTimeGuard('2026-05-20');
|
|
293
|
-
*
|
|
294
|
-
* // Reactive input — pass a store
|
|
295
|
-
* const dateStore = writable('2026-05-20');
|
|
296
|
-
* const tg2 = useTimeGuard(dateStore);
|
|
297
|
-
* <\/script>
|
|
298
|
-
*
|
|
299
|
-
* <p>{$tg.format('dddd, DD MMMM YYYY')}</p>
|
|
300
|
-
* <p>{$tg2.format('dddd, DD MMMM YYYY')}</p>
|
|
301
|
-
* ```
|
|
302
|
-
*/
|
|
303
|
-
function useTimeGuard(input, config) {
|
|
304
|
-
if (isStore(input)) return derived(input, ($val) => require_core.TimeGuard.from($val, config));
|
|
305
|
-
return readable(require_core.TimeGuard.from(input, config));
|
|
306
|
-
}
|
|
307
|
-
/**
|
|
308
|
-
* Creates a readable store of the current time that ticks on a specified
|
|
309
|
-
* interval (default 1000ms). Automatically clears the interval on
|
|
310
|
-
* component destroy.
|
|
311
|
-
*
|
|
312
|
-
* ```svelte
|
|
313
|
-
* <script>
|
|
314
|
-
* import { useCurrentTime } from '@bereasoftware/time-guard/svelte';
|
|
315
|
-
* const now = useCurrentTime({ interval: 1000 });
|
|
316
|
-
* <\/script>
|
|
317
|
-
* <p>{$now.format('HH:mm:ss')}</p>
|
|
318
|
-
* ```
|
|
319
|
-
*/
|
|
320
|
-
function useCurrentTime(options) {
|
|
321
|
-
const interval = options?.interval ?? 1e3;
|
|
322
|
-
const config = options?.config;
|
|
323
|
-
const store = writable(require_core.TimeGuard.now(config), () => {
|
|
324
|
-
const timer = setInterval(() => {
|
|
325
|
-
store.set(require_core.TimeGuard.now(config));
|
|
326
|
-
}, interval);
|
|
327
|
-
return () => {
|
|
328
|
-
clearInterval(timer);
|
|
329
|
-
};
|
|
330
|
-
});
|
|
331
|
-
return { subscribe: store.subscribe };
|
|
332
|
-
}
|
|
333
|
-
/**
|
|
334
|
-
* Creates a readable store of a relative time string that recalculates
|
|
335
|
-
* periodically (default every 60s).
|
|
336
|
-
*
|
|
337
|
-
* ```svelte
|
|
338
|
-
* <script>
|
|
339
|
-
* import { useRelativeTime } from '@bereasoftware/time-guard/svelte';
|
|
340
|
-
* const relative = useRelativeTime('2026-05-20T08:00:00', { locale: 'es' });
|
|
341
|
-
* <\/script>
|
|
342
|
-
* <p>{$relative}</p>
|
|
343
|
-
* ```
|
|
344
|
-
*/
|
|
345
|
-
function useRelativeTime(date, options) {
|
|
346
|
-
const interval = options?.interval ?? 6e4;
|
|
347
|
-
const locale = options?.locale;
|
|
348
|
-
const numeric = options?.numeric;
|
|
349
|
-
const compute = () => {
|
|
350
|
-
const tgDate = require_core.TimeGuard.from(date);
|
|
351
|
-
const now = require_core.TimeGuard.now();
|
|
352
|
-
return tgDate.since(now).humanize({
|
|
353
|
-
locale,
|
|
354
|
-
numeric
|
|
355
|
-
});
|
|
356
|
-
};
|
|
357
|
-
const store = writable(compute(), () => {
|
|
358
|
-
const timer = setInterval(() => {
|
|
359
|
-
store.set(compute());
|
|
360
|
-
}, interval);
|
|
361
|
-
return () => {
|
|
362
|
-
clearInterval(timer);
|
|
363
|
-
};
|
|
364
|
-
});
|
|
365
|
-
return { subscribe: store.subscribe };
|
|
366
|
-
}
|
|
367
|
-
/**
|
|
368
|
-
* Creates a readable store of a TimeRange instance.
|
|
369
|
-
* Recalculates reactively when `start` or `end` change (supports both
|
|
370
|
-
* plain values and Svelte stores).
|
|
371
|
-
*
|
|
372
|
-
* ```svelte
|
|
373
|
-
* <script>
|
|
374
|
-
* import { writable } from 'svelte/store';
|
|
375
|
-
* import { useTimeRange } from '@bereasoftware/time-guard/svelte';
|
|
376
|
-
*
|
|
377
|
-
* // Static range
|
|
378
|
-
* const range = useTimeRange('2026-05-20', '2026-06-01');
|
|
379
|
-
*
|
|
380
|
-
* // Reactive range
|
|
381
|
-
* const start = writable('2026-05-20');
|
|
382
|
-
* const end = writable('2026-06-01');
|
|
383
|
-
* const range2 = useTimeRange(start, end);
|
|
384
|
-
* <\/script>
|
|
385
|
-
*
|
|
386
|
-
* <p>Duration: {$range.toDuration().humanize()}</p>
|
|
387
|
-
*/
|
|
388
|
-
function useTimeRange(start, end, config) {
|
|
389
|
-
return derived([toStore(start), toStore(end)], ([$start, $end]) => {
|
|
390
|
-
return new require_core.TimeRange(require_core.TimeGuard.from($start, config), require_core.TimeGuard.from($end, config));
|
|
391
|
-
});
|
|
392
|
-
}
|
|
393
|
-
//#endregion
|
|
394
|
-
exports.TimeGuardConfigKey = TimeGuardConfigKey;
|
|
395
|
-
exports.useCurrentTime = useCurrentTime;
|
|
396
|
-
exports.useRelativeTime = useRelativeTime;
|
|
397
|
-
exports.useTimeGuard = useTimeGuard;
|
|
398
|
-
exports.useTimeRange = useTimeRange;
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../core-BDQnStek.cjs");Array.isArray,Array.prototype.indexOf,Array.prototype.includes,Array.from,Array.prototype;var t=()=>{};function n(e){for(var t=0;t<e.length;t++)e[t]()}var r=1024,i=2048,a=4096,o=65536,s=1<<19;new class extends Error{name=`StaleReactionError`;message="The reaction that called `getAbortSignal()` was re-run or destroyed"},globalThis.document?.contentType;function c(e,t){return e==e?e!==t||typeof e==`object`&&!!e||typeof e==`function`:t==t}~(i|a|r);function l(e,n,r){if(e==null)return n(void 0),r&&r(void 0),t;let i=h(()=>e.subscribe(n,r));return i.unsubscribe?()=>i.unsubscribe():i}var u=[];function d(e,t){return{subscribe:f(e,t).subscribe}}function f(e,n=t){let r=null,i=new Set;function a(t){if(c(e,t)&&(e=t,r)){let t=!u.length;for(let t of i)t[1](),u.push(t,e);if(t){for(let e=0;e<u.length;e+=2)u[e][0](u[e+1]);u.length=0}}}function o(t){a(t(e))}function s(s,c=t){let l=[s,c];return i.add(l),i.size===1&&(r=n(a,o)||t),s(e),()=>{i.delete(l),i.size===0&&r&&(r(),r=null)}}return{set:a,update:o,subscribe:s}}function p(e,r,i){let a=!Array.isArray(e),o=a?[e]:e;if(!o.every(Boolean))throw Error(`derived() expects stores as input, got a falsy value`);let s=r.length<2;return d(i,(e,i)=>{let c=!1,u=[],d=0,f=t,p=()=>{if(d)return;f();let n=r(a?u[0]:u,e,i);s?e(n):f=typeof n==`function`?n:t},m=o.map((e,t)=>l(e,e=>{u[t]=e,d&=~(1<<t),c&&p()},()=>{d|=1<<t}));return c=!0,p(),function(){n(m),f(),c=!1}})}o|s;var m=!1;function h(e){var t=m;try{return m=!0,e()}finally{m=t}}function g(e){return typeof e==`object`&&!!e&&`subscribe`in e&&typeof e.subscribe==`function`}function _(e){return g(e)?e:d(e)}var v=Symbol(`TimeGuardConfig`);function y(t,n){return g(t)?p(t,t=>e.i.from(t,n)):d(e.i.from(t,n))}function b(t){let n=t?.interval??1e3,r=t?.config,i=f(e.i.now(r),()=>{let t=setInterval(()=>{i.set(e.i.now(r))},n);return()=>{clearInterval(t)}});return{subscribe:i.subscribe}}function x(t,n){let r=n?.interval??6e4,i=n?.locale,a=n?.numeric,o=()=>e.o(t,{locale:i,numeric:a}),s=f(o(),()=>{let e=setInterval(()=>{s.set(o())},r);return()=>{clearInterval(e)}});return{subscribe:s.subscribe}}function S(t,n,r){return p([_(t),_(n)],([t,n])=>e.s(t,n,r))}exports.TimeGuardConfigKey=v,exports.useCurrentTime=b,exports.useRelativeTime=x,exports.useTimeGuard=y,exports.useTimeRange=S;
|