@tempots/dom 31.6.0 → 32.0.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/index.js CHANGED
@@ -1,66 +1,33 @@
1
- var We = Object.defineProperty;
2
- var me = (s) => {
3
- throw TypeError(s);
4
- };
5
- var Ue = (s, e, t) => e in s ? We(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t;
6
- var o = (s, e, t) => Ue(s, typeof e != "symbol" ? e + "" : e, t), ge = (s, e, t) => e.has(s) || me("Cannot " + t);
7
- var U = (s, e, t) => (ge(s, e, "read from private field"), t ? t.call(s) : e.get(s)), ye = (s, e, t) => e.has(s) ? me("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(s) : e.set(s, t), le = (s, e, t, r) => (ge(s, e, "write to private field"), r ? r.call(s, t) : e.set(s, t), t);
8
- const Je = (s, e, t) => s + (e - s) * t;
9
- const Ge = (s, e, t) => {
10
- const r = Math.max(s.length, e.length);
11
- let n = "";
12
- for (let i = 0; i < r; i++) {
13
- let l = s.charCodeAt(i);
14
- isNaN(l) && (l = 97);
15
- let c = e.charCodeAt(i);
16
- isNaN(c) && (c = 97), n += String.fromCharCode(l + (c - l) * t);
1
+ const _ = [], qe = (t) => {
2
+ _.push(t);
3
+ }, Fe = () => {
4
+ if (_.length === 0)
5
+ throw new Error("Cannot pop from empty scope stack");
6
+ _.pop();
7
+ }, ge = () => _[_.length - 1] ?? null, Bt = () => _, Wt = () => _[_.length - 2] ?? null, L = (t, e) => {
8
+ qe(t);
9
+ try {
10
+ return e();
11
+ } finally {
12
+ Fe();
17
13
  }
18
- return n;
19
- }, Xe = (s, e, t) => new Date(s.getTime() + (e.getTime() - s.getTime()) * t), Ye = (s, e) => e, Qe = (s) => typeof s == "number" ? Je : typeof s == "string" ? Ge : s instanceof Date ? Xe : Ye;
20
- var M;
21
- class ce {
22
- /**
23
- * Creates a new instance of `ElementPosition`.
24
- * @param index - The index of the element.
25
- * @param total - The total number of elements in the collection.
26
- */
27
- constructor(e, t) {
28
- /**
29
- * The counter of the element starting from 1.
30
- */
31
- o(this, "counter");
32
- /**
33
- * Checks if the element is the first element in the collection.
34
- * @returns `true` if the element is the first element, `false` otherwise.
35
- */
36
- o(this, "isFirst");
37
- /**
38
- * Checks if the counter of the element is even.
39
- * @returns `true` if the counter is even, `false` otherwise.
40
- */
41
- o(this, "isEven");
42
- /**
43
- * Checks if the counter of the element is odd.
44
- * @returns `true` if the counter is odd, `false` otherwise.
45
- */
46
- o(this, "isOdd");
47
- ye(this, M);
48
- o(this, "dispose", () => {
49
- var e;
50
- (e = U(this, M)) == null || e.dispose(), le(this, M, void 0);
51
- });
52
- this.index = e, this.total = t, this.counter = e + 1, this.isFirst = e === 0, this.isEven = e % 2 === 1, this.isOdd = e % 2 === 0;
14
+ }, Ut = (t) => {
15
+ const e = new q();
16
+ try {
17
+ return L(e, () => t(e));
18
+ } finally {
19
+ e.dispose();
53
20
  }
54
- /**
55
- * Checks if the element is the last element in the collection.
56
- * @returns `true` if the element is the last element, `false` otherwise.
57
- */
58
- get isLast() {
59
- return U(this, M) == null && le(this, M, this.total.map((e) => this.counter === e)), U(this, M);
21
+ }, oe = (t) => {
22
+ const e = _.slice();
23
+ _.length = 0;
24
+ try {
25
+ return t();
26
+ } finally {
27
+ _.length = 0, _.push(...e);
60
28
  }
61
- }
62
- M = new WeakMap();
63
- const B = class B {
29
+ };
30
+ class g {
64
31
  /**
65
32
  * Represents a signal with a value of type T.
66
33
  *
@@ -68,316 +35,94 @@ const B = class B {
68
35
  * @param equals - A function that determines whether two values of type T are equal.
69
36
  * @public
70
37
  */
71
- constructor(e, t) {
72
- /**
73
- * @internal
74
- */
75
- o(this, "$__signal__", !0);
76
- /**
77
- * @internal
78
- */
79
- o(this, "_value");
80
- /**
81
- * @internal
82
- */
83
- o(this, "_derivatives", []);
84
- /**
85
- * @internal
86
- */
87
- o(this, "_onValueListeners", []);
88
- /**
89
- * @internal
90
- */
91
- o(this, "_onDisposeListeners", []);
92
- /**
93
- * Gets the current value of the signal.
94
- * @returns The current value of the signal.
95
- */
96
- o(this, "get", () => this._value);
97
- /**
98
- * Checks if the signal has any registered listeners.
99
- * @returns `true` if the signal has listeners, `false` otherwise.
100
- */
101
- o(this, "hasListeners", () => this._onValueListeners.length > 0);
102
- /**
103
- * Registers a listener function to be called whenever the value of the signal changes.
104
- * The listener function will be immediately called with the current value of the signal.
105
- * Returns a function that can be called to unregister the listener.
106
- *
107
- * @param listener - The listener function to be called when the value of the signal changes.
108
- * @param options - Options for the listener.
109
- */
110
- o(this, "on", (e, t = {}) => {
111
- t.skipInitial || e(this.get(), void 0);
112
- const r = t.once ? (i, l) => {
113
- n(), e(i, l);
114
- } : e;
115
- this._onValueListeners.push(r);
116
- const n = () => {
117
- this._onValueListeners.splice(
118
- this._onValueListeners.indexOf(r),
119
- 1
120
- ), t.abortSignal != null && t.abortSignal.removeEventListener("abort", n);
121
- };
122
- return t.abortSignal != null && t.abortSignal.addEventListener("abort", n), n;
123
- });
124
- /**
125
- * @internal
126
- */
127
- o(this, "_setAndNotify", (e) => {
128
- if (this._disposed) return;
129
- const t = this._value;
130
- this.equals(t, e) || (this._value = e, this._onValueListeners.forEach((n) => n(e, t)));
131
- });
132
- /**
133
- * @internal
134
- */
135
- o(this, "_disposed", !1);
136
- /**
137
- * Checks whether the signal is disposed.
138
- * @returns True if the signal is disposed, false otherwise.
139
- */
140
- o(this, "isDisposed", () => this._disposed);
141
- /**
142
- * Adds a listener function to be called when the object is disposed.
143
- * @param listener - The listener function to be called when the object is disposed.
144
- * @returns A function that can be called to remove the listener.
145
- */
146
- o(this, "onDispose", (e) => {
147
- this._onDisposeListeners.push(e);
148
- });
149
- /**
150
- * Disposes the signal, releasing any resources associated with it.
151
- */
152
- o(this, "dispose", () => {
153
- this._disposed || (this._disposed = !0, this._onDisposeListeners.forEach((e) => e()), this._onDisposeListeners.length = 0, this._derivatives.length = 0);
154
- });
155
- /**
156
- * Creates a new computed signal by applying a transformation function to this signal's value.
157
- *
158
- * The `map` method is one of the most commonly used signal operations. It creates a new
159
- * computed signal that automatically updates whenever the source signal changes. The
160
- * transformation function is called with the current value and should return the new value.
161
- *
162
- * @example
163
- * ```typescript
164
- * const count = prop(5)
165
- *
166
- * // Transform to different types
167
- * const doubled = count.map(n => n * 2)
168
- * const message = count.map(n => `Count is ${n}`)
169
- * const isEven = count.map(n => n % 2 === 0)
170
- *
171
- * // Use in UI
172
- * html.div(
173
- * html.div('Original: ', count.map(String)),
174
- * html.div('Doubled: ', doubled.map(String)),
175
- * html.div('Message: ', message),
176
- * html.div('Is even: ', isEven.map(String))
177
- * )
178
- * ```
179
- *
180
- * @example
181
- * ```typescript
182
- * // Chain multiple transformations
183
- * const user = prop({ name: 'John', age: 30 })
184
- * const greeting = user
185
- * .map(u => u.name)
186
- * .map(name => name.toUpperCase())
187
- * .map(name => `Hello, ${name}!`)
188
- * ```
189
- *
190
- * @example
191
- * ```typescript
192
- * // With custom equality function for objects
193
- * const items = prop([{ id: 1, name: 'Item 1' }])
194
- * const itemNames = items.map(
195
- * items => items.map(item => item.name),
196
- * (a, b) => JSON.stringify(a) === JSON.stringify(b) // deep equality
197
- * )
198
- * ```
199
- *
200
- * @typeParam O - The type of the transformed value
201
- * @param fn - Function that transforms the signal's value to a new value
202
- * @param equals - Optional function to determine if two transformed values are equal (defaults to strict equality)
203
- * @returns A new computed signal with the transformed value
204
- */
205
- o(this, "map", (e, t = (r, n) => r === n) => {
206
- const r = new N(() => {
207
- try {
208
- return e(this.get());
209
- } catch (n) {
210
- throw console.error("Error in Signal.map:", n), n;
211
- }
212
- }, t);
213
- return this.setDerivative(r), r;
214
- });
215
- /**
216
- * Returns a new Signal that applies the given function to the value of the current Signal,
217
- * and then flattens the resulting Signal.
218
- *
219
- * @typeParam O - The type of the value emitted by the resulting Signal.
220
- * @param fn - The function to apply to the value of the current Signal.
221
- * @param equals - A function that determines whether two values of type O are equal.
222
- * Defaults to a strict equality check (===).
223
- * @returns A new Signal that emits the values of the resulting Signal.
224
- */
225
- o(this, "flatMap", (e, t = (r, n) => r === n) => {
226
- const r = new N(() => {
227
- try {
228
- return e(this.get()).get();
229
- } catch (n) {
230
- throw console.error("Error in Signal.flatMap:", n), n;
231
- }
232
- }, t);
233
- return this.setDerivative(r), r;
234
- });
235
- /**
236
- * Invokes a callback function with the current value of the signal, without modifying the signal.
237
- *
238
- * @param fn - The callback function to be invoked with the current value of the signal.
239
- * @returns A new signal that emits the same value as the original signal and invokes the callback function.
240
- */
241
- o(this, "tap", (e) => this.map((t) => (e(t), t)));
242
- /**
243
- * Returns a new Signal that emits the value at the specified key of the current value.
244
- *
245
- * @param key - The key of the value to retrieve.
246
- * @returns A new Signal that emits the value at the specified key.
247
- */
248
- o(this, "at", (e) => this.map((t) => t[e]));
249
- /**
250
- * @internal
251
- */
252
- o(this, "_$");
253
- o(this, "filter", (e, t) => {
254
- let r = t ?? this.get();
255
- const n = new N(() => {
256
- try {
257
- const i = this.get();
258
- return r = e(i) ? i : r;
259
- } catch (i) {
260
- throw console.error("Error in Signal.filter:", i), i;
261
- }
262
- }, this.equals);
263
- return this.setDerivative(n), n;
264
- });
265
- /**
266
- * Returns a new Computed object that applies the provided mapping function to the value of this Signal,
267
- * and filters out values that are `undefined` or `null`.
268
- *
269
- * @typeParam O - The type of the mapped value.
270
- * @param fn - The mapping function to apply to the value of this Signal.
271
- * @param startValue - The initial value for the Computed object.
272
- * @param equals - Optional equality function to determine if two values are equal.
273
- * @returns - A new Computed object with the mapped and filtered values.
274
- */
275
- o(this, "filterMap", (e, t, r = (n, i) => n === i) => {
276
- let n = t;
277
- const i = new N(() => {
278
- try {
279
- const l = this.get(), c = e(l);
280
- return n = c ?? n;
281
- } catch (l) {
282
- throw console.error("Error in Signal.filterMap:", l), l;
283
- }
284
- }, r);
285
- return this.setDerivative(i), i;
286
- });
287
- /**
288
- * Maps the values emitted by the signal to a new value asynchronously using the provided function.
289
- * If the function throws an error, it will be caught and logged.
290
- * If a recovery function is provided, it will be called with the error and its return value will be used as the mapped value.
291
- * If no recovery function is provided, the error will be logged as an unhandled promise rejection.
292
- *
293
- * @typeParam O - The type of the mapped value.
294
- * @param fn - The function to map the values emitted by the signal. The second argument to this function allows to cancel the previously running mapping function if it has not completed by the time a new value is emitted.
295
- * @param alt - The alternate value to use if the signal is disposed or the mapping function throws an error.
296
- * @param recover - The recovery function to handle errors thrown by the mapping function.
297
- * @param equals - The equality function to compare the mapped values for equality.
298
- * @returns A property that holds the mapped value and can be observed for changes.
299
- */
300
- o(this, "mapAsync", (e, t, r, n = (i, l) => i === l) => {
301
- const i = w(t, n);
302
- let l = 0, c = new AbortController();
303
- return i.onDispose(
304
- this.on(async (a) => {
305
- const u = ++l;
306
- c.abort(), c = new AbortController();
307
- try {
308
- const h = await e(a, { abortSignal: c.signal });
309
- u === l && i.set(h);
310
- } catch (h) {
311
- if (u === l)
312
- if (r != null)
313
- i.set(r(h));
314
- else
315
- throw h;
316
- }
317
- })
318
- ), i;
319
- });
320
- /**
321
- * Maps the values of the signal using the provided function `fn`, and returns a new signal
322
- * containing the mapped values. If the mapped value is `undefined` or `null`, it is replaced
323
- * with the provided `alt` value.
324
- *
325
- * @typeParam O - The type of the mapped value.
326
- * @param fn - The function used to map the values of the signal.
327
- * @param alt - The alternative value to use when the mapped value is `undefined` or `null`.
328
- * @returns A new signal containing the mapped values.
329
- */
330
- o(this, "mapMaybe", (e, t) => this.map((r) => e(r) ?? t));
331
- /**
332
- * Feeds a property into the signal and sets up disposal behavior.
333
- * @param prop - The property to feed into the signal.
334
- * @param autoDisposeProp - Determines whether the property should be automatically disposed when the signal is disposed.
335
- * @returns The input property.
336
- */
337
- o(this, "feedProp", (e, t = !1) => {
338
- const r = this.on(e.set);
339
- return e.onDispose(r), t ? this.onDispose(e.dispose) : this.onDispose(r), e;
340
- });
341
- /**
342
- * Derives a new property from the current signal.
343
- * @param options - The options for the derived property.
344
- * @param options.autoDisposeProp - Determines whether the derived property should be automatically disposed.
345
- * @param options.equals - A function that determines if two values are equal.
346
- * @returns The derived property.
347
- */
348
- o(this, "deriveProp", ({
349
- autoDisposeProp: e = !0,
350
- equals: t
351
- } = {}) => this.feedProp(w(this.get(), t), e));
352
- /**
353
- * Derives a new signal from the current signal. Useful to create a new signal that emits the same values as the current signal but can be disposed independently.
354
- * @returns A new signal that emits the same values as the current signal.
355
- */
356
- o(this, "derive", () => this.map((e) => e));
357
- /**
358
- * Returns a signal that emits the count of values received so far.
359
- * @returns A signal that emits the count of values received so far.
360
- */
361
- o(this, "count", () => {
362
- let e = 0;
363
- return this.map(() => ++e);
364
- });
365
- /**
366
- * Adds a computed value as a derivative of the signal.
367
- * When the computed value is disposed, it is automatically removed from the derivatives list.
368
- * Additionally, when the computed value is disposed, it sets the signal as dirty.
369
- * @param computed - The computed value to add as a derivative.
370
- */
371
- o(this, "setDerivative", (e) => {
372
- this._derivatives.push(e), e.onDispose(() => {
373
- this._derivatives.splice(
374
- this._derivatives.indexOf(e),
375
- 1
376
- );
377
- }), e.onDispose(this.on(e.setDirty)), this.onDispose(e.dispose);
378
- });
379
- this.equals = t, this._value = e;
38
+ constructor(e, s) {
39
+ this.equals = s, this._value = e;
380
40
  }
41
+ /**
42
+ * Creates a Signal that holds the result of a Promise, with proper error handling.
43
+ *
44
+ * This static method creates a signal that starts with an initial value and updates
45
+ * when the promise resolves. If the promise rejects, an optional recovery function
46
+ * can provide a fallback value.
47
+ *
48
+ * @example
49
+ * ```typescript
50
+ * // Basic usage with API call
51
+ * const userData = Signal.ofPromise(
52
+ * fetch('/api/user').then(r => r.json()),
53
+ * { loading: true }, // initial state
54
+ * error => ({ error: error.message, loading: false }) // error recovery
55
+ * )
56
+ *
57
+ * // Use in UI
58
+ * Ensure(userData,
59
+ * (user) => html.div('Welcome, ', user.map(u => u.name)),
60
+ * () => html.div('Loading...')
61
+ * )
62
+ * ```
63
+ *
64
+ * @example
65
+ * ```typescript
66
+ * // With custom equality function
67
+ * const config = Signal.ofPromise(
68
+ * loadConfig(),
69
+ * {},
70
+ * () => ({}),
71
+ * (a, b) => JSON.stringify(a) === JSON.stringify(b) // deep equality
72
+ * )
73
+ * ```
74
+ *
75
+ * @typeParam O - The type of the value returned by the Promise
76
+ * @param promise - The Promise to use to feed the Signal
77
+ * @param init - The initial value of the Signal before the Promise resolves
78
+ * @param recover - Optional function to recover from Promise rejection and provide an alternative value
79
+ * @param equals - Function to compare two values for equality (defaults to strict equality)
80
+ * @returns A Signal that represents the result of the Promise
81
+ */
82
+ static ofPromise = (e, s, r, n = (i, o) => i === o) => {
83
+ const i = new g(s, n);
84
+ return e.then((o) => i._setAndNotify(o)).catch((o) => {
85
+ r != null ? i._setAndNotify(r(o)) : console.error(
86
+ "Unhandled promise rejection in Signal.ofPromise:",
87
+ o
88
+ );
89
+ }), i;
90
+ };
91
+ /**
92
+ * Checks if a value is a Signal.
93
+ *
94
+ * @param value - The value to check.
95
+ * @returns `true` if the value is a Signal, `false` otherwise.
96
+ */
97
+ static is = (e) => (
98
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
99
+ e != null && e.$__signal__ === !0
100
+ );
101
+ /**
102
+ * @internal
103
+ */
104
+ $__signal__ = !0;
105
+ /**
106
+ * @internal
107
+ */
108
+ _value;
109
+ /**
110
+ * @internal
111
+ */
112
+ _derivatives = [];
113
+ /**
114
+ * @internal
115
+ */
116
+ _onValueListeners = [];
117
+ /**
118
+ * @internal
119
+ */
120
+ _onDisposeListeners = [];
121
+ /**
122
+ * Gets the current value of the signal.
123
+ * @returns The current value of the signal.
124
+ */
125
+ get = () => this._value;
381
126
  /**
382
127
  * Gets the value of the signal.
383
128
  * @returns The current value of the signal.
@@ -385,119 +130,355 @@ const B = class B {
385
130
  get value() {
386
131
  return this._value;
387
132
  }
133
+ /**
134
+ * Checks if the signal has any registered listeners.
135
+ * @returns `true` if the signal has listeners, `false` otherwise.
136
+ */
137
+ hasListeners = () => this._onValueListeners.length > 0;
138
+ /**
139
+ * Registers a listener function to be called whenever the value of the signal changes.
140
+ * The listener function will be immediately called with the current value of the signal.
141
+ * Returns a function that can be called to unregister the listener.
142
+ *
143
+ * @param listener - The listener function to be called when the value of the signal changes.
144
+ * @param options - Options for the listener.
145
+ */
146
+ on = (e, s = {}) => {
147
+ s.skipInitial || e(this.get(), void 0);
148
+ const r = s.once ? (i, o) => {
149
+ n(), e(i, o);
150
+ } : e;
151
+ this._onValueListeners.push(r);
152
+ const n = () => {
153
+ this._onValueListeners.splice(
154
+ this._onValueListeners.indexOf(r),
155
+ 1
156
+ ), s.abortSignal != null && s.abortSignal.removeEventListener("abort", n);
157
+ };
158
+ return s.abortSignal != null && s.abortSignal.addEventListener("abort", n), n;
159
+ };
160
+ /**
161
+ * Registers a listener function to be called whenever the value of the signal changes.
162
+ * The listener function will not be called with the current value of the signal.
163
+ * Returns a function that can be called to unregister the listener.
164
+ *
165
+ * @param listener - The listener function to be called when the value of the signal changes.
166
+ * @param options - Options for the listener.
167
+ */
168
+ onChange = (e, s = {}) => {
169
+ let r = 0;
170
+ const n = (i, o) => {
171
+ r++ > 0 && e(i, o);
172
+ };
173
+ return this.on(n, s);
174
+ };
175
+ /**
176
+ * @internal
177
+ */
178
+ _setAndNotify = (e) => {
179
+ if (this._disposed) return;
180
+ const s = this._value;
181
+ this.equals(s, e) || (this._value = e, this._onValueListeners.forEach((n) => n(e, s)));
182
+ };
183
+ /**
184
+ * @internal
185
+ */
186
+ _disposed = !1;
187
+ /**
188
+ * Checks whether the signal is disposed.
189
+ * @returns True if the signal is disposed, false otherwise.
190
+ */
191
+ isDisposed = () => this._disposed;
192
+ /**
193
+ * Adds a listener function to be called when the object is disposed.
194
+ * @param listener - The listener function to be called when the object is disposed.
195
+ * @returns A function that can be called to remove the listener.
196
+ */
197
+ onDispose = (e) => {
198
+ this._onDisposeListeners.push(e);
199
+ };
200
+ /**
201
+ * Disposes the signal, releasing any resources associated with it.
202
+ */
203
+ dispose = () => {
204
+ this._disposed || (this._disposed = !0, this._onDisposeListeners.forEach((e) => e()), this._onDisposeListeners.length = 0, this._derivatives.length = 0);
205
+ };
206
+ /**
207
+ * Creates a new computed signal by applying a transformation function to this signal's value.
208
+ *
209
+ * The `map` method is one of the most commonly used signal operations. It creates a new
210
+ * computed signal that automatically updates whenever the source signal changes. The
211
+ * transformation function is called with the current value and should return the new value.
212
+ *
213
+ * @example
214
+ * ```typescript
215
+ * const count = prop(5)
216
+ *
217
+ * // Transform to different types
218
+ * const doubled = count.map(n => n * 2)
219
+ * const message = count.map(n => `Count is ${n}`)
220
+ * const isEven = count.map(n => n % 2 === 0)
221
+ *
222
+ * // Use in UI
223
+ * html.div(
224
+ * html.div('Original: ', count.map(String)),
225
+ * html.div('Doubled: ', doubled.map(String)),
226
+ * html.div('Message: ', message),
227
+ * html.div('Is even: ', isEven.map(String))
228
+ * )
229
+ * ```
230
+ *
231
+ * @example
232
+ * ```typescript
233
+ * // Chain multiple transformations
234
+ * const user = prop({ name: 'John', age: 30 })
235
+ * const greeting = user
236
+ * .map(u => u.name)
237
+ * .map(name => name.toUpperCase())
238
+ * .map(name => `Hello, ${name}!`)
239
+ * ```
240
+ *
241
+ * @example
242
+ * ```typescript
243
+ * // With custom equality function for objects
244
+ * const items = prop([{ id: 1, name: 'Item 1' }])
245
+ * const itemNames = items.map(
246
+ * items => items.map(item => item.name),
247
+ * (a, b) => JSON.stringify(a) === JSON.stringify(b) // deep equality
248
+ * )
249
+ * ```
250
+ *
251
+ * **Auto-Disposal:** The returned computed signal is automatically registered with the current
252
+ * disposal scope (if one exists). When used within a renderable or `WithScope()`, the signal
253
+ * will be automatically disposed when the component unmounts. No manual `OnDispose()` needed!
254
+ *
255
+ * ```typescript
256
+ * const MyComponent: Renderable = (ctx) => {
257
+ * const count = prop(0);
258
+ * const doubled = count.map(x => x * 2); // ✅ Auto-disposed
259
+ * return html.div(doubled);
260
+ * };
261
+ * ```
262
+ *
263
+ * @typeParam O - The type of the transformed value
264
+ * @param fn - Function that transforms the signal's value to a new value
265
+ * @param equals - Optional function to determine if two transformed values are equal (defaults to strict equality)
266
+ * @returns A new computed signal with the transformed value (auto-registered with current scope)
267
+ */
268
+ map = (e, s = (r, n) => r === n) => {
269
+ const r = new $(() => {
270
+ try {
271
+ return e(this.get());
272
+ } catch (n) {
273
+ throw console.error("Error in Signal.map:", n), n;
274
+ }
275
+ }, s);
276
+ return this.setDerivative(r), r;
277
+ };
278
+ /**
279
+ * Returns a new Signal that applies the given function to the value of the current Signal,
280
+ * and then flattens the resulting Signal.
281
+ *
282
+ * @typeParam O - The type of the value emitted by the resulting Signal.
283
+ * @param fn - The function to apply to the value of the current Signal.
284
+ * @param equals - A function that determines whether two values of type O are equal.
285
+ * Defaults to a strict equality check (===).
286
+ * @returns A new Signal that emits the values of the resulting Signal.
287
+ */
288
+ flatMap = (e, s = (r, n) => r === n) => {
289
+ const r = new $(() => {
290
+ try {
291
+ return e(this.get()).get();
292
+ } catch (n) {
293
+ throw console.error("Error in Signal.flatMap:", n), n;
294
+ }
295
+ }, s);
296
+ return this.setDerivative(r), r;
297
+ };
298
+ /**
299
+ * Invokes a callback function with the current value of the signal, without modifying the signal.
300
+ *
301
+ * @param fn - The callback function to be invoked with the current value of the signal.
302
+ * @returns A new signal that emits the same value as the original signal and invokes the callback function.
303
+ */
304
+ tap = (e) => this.map((s) => (e(s), s));
305
+ /**
306
+ * Returns a new Signal that emits the value at the specified key of the current value.
307
+ *
308
+ * @param key - The key of the value to retrieve.
309
+ * @returns A new Signal that emits the value at the specified key.
310
+ */
311
+ at = (e) => this.map((s) => s[e]);
312
+ /**
313
+ * @internal
314
+ */
315
+ _$;
388
316
  /**
389
317
  * Represents a collection of signals mapping to each key/field in the wrapped value.
390
318
  * @typeParam T - The type of the signals.
391
319
  */
392
320
  get $() {
393
321
  return this._$ !== void 0 ? this._$ : this._$ = new Proxy(this, {
394
- get: (e, t) => this.at(t)
322
+ get: (e, s) => this.at(s)
395
323
  });
396
324
  }
397
- };
398
- /**
399
- * Creates a Signal that holds the result of a Promise, with proper error handling.
400
- *
401
- * This static method creates a signal that starts with an initial value and updates
402
- * when the promise resolves. If the promise rejects, an optional recovery function
403
- * can provide a fallback value.
404
- *
405
- * @example
406
- * ```typescript
407
- * // Basic usage with API call
408
- * const userData = Signal.ofPromise(
409
- * fetch('/api/user').then(r => r.json()),
410
- * { loading: true }, // initial state
411
- * error => ({ error: error.message, loading: false }) // error recovery
412
- * )
413
- *
414
- * // Use in UI
415
- * Ensure(userData,
416
- * (user) => html.div('Welcome, ', user.map(u => u.name)),
417
- * () => html.div('Loading...')
418
- * )
419
- * ```
420
- *
421
- * @example
422
- * ```typescript
423
- * // With custom equality function
424
- * const config = Signal.ofPromise(
425
- * loadConfig(),
426
- * {},
427
- * () => ({}),
428
- * (a, b) => JSON.stringify(a) === JSON.stringify(b) // deep equality
429
- * )
430
- * ```
431
- *
432
- * @typeParam O - The type of the value returned by the Promise
433
- * @param promise - The Promise to use to feed the Signal
434
- * @param init - The initial value of the Signal before the Promise resolves
435
- * @param recover - Optional function to recover from Promise rejection and provide an alternative value
436
- * @param equals - Function to compare two values for equality (defaults to strict equality)
437
- * @returns A Signal that represents the result of the Promise
438
- */
439
- o(B, "ofPromise", (e, t, r, n = (i, l) => i === l) => {
440
- const i = new B(t, n);
441
- return e.then((l) => i._setAndNotify(l)).catch((l) => {
442
- r != null ? i._setAndNotify(r(l)) : console.error(
443
- "Unhandled promise rejection in Signal.ofPromise:",
444
- l
445
- );
446
- }), i;
447
- }), /**
448
- * Checks if a value is a Signal.
449
- *
450
- * @param value - The value to check.
451
- * @returns `true` if the value is a Signal, `false` otherwise.
452
- */
453
- o(B, "is", (e) => (
454
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
455
- e != null && e.$__signal__ === !0
456
- ));
457
- let y = B;
458
- const Ze = typeof queueMicrotask == "function" ? queueMicrotask : (s) => Promise.resolve().then(s);
459
- class N extends y {
460
- /**
461
- * Represents a Signal object.
462
- * @param _fn - The function that returns the value of the signal.
325
+ filter = (e, s) => {
326
+ let r = s ?? this.get();
327
+ const n = new $(() => {
328
+ try {
329
+ const i = this.get();
330
+ return r = e(i) ? i : r;
331
+ } catch (i) {
332
+ throw console.error("Error in Signal.filter:", i), i;
333
+ }
334
+ }, this.equals);
335
+ return this.setDerivative(n), n;
336
+ };
337
+ /**
338
+ * Returns a new Computed object that applies the provided mapping function to the value of this Signal,
339
+ * and filters out values that are `undefined` or `null`.
340
+ *
341
+ * @typeParam O - The type of the mapped value.
342
+ * @param fn - The mapping function to apply to the value of this Signal.
343
+ * @param startValue - The initial value for the Computed object.
344
+ * @param equals - Optional equality function to determine if two values are equal.
345
+ * @returns - A new Computed object with the mapped and filtered values.
346
+ */
347
+ filterMap = (e, s, r = (n, i) => n === i) => {
348
+ let n = s;
349
+ const i = new $(() => {
350
+ try {
351
+ const o = this.get(), l = e(o);
352
+ return n = l ?? n;
353
+ } catch (o) {
354
+ throw console.error("Error in Signal.filterMap:", o), o;
355
+ }
356
+ }, r);
357
+ return this.setDerivative(i), i;
358
+ };
359
+ /**
360
+ * Maps the values emitted by the signal to a new value asynchronously using the provided function.
361
+ * If the function throws an error, it will be caught and logged.
362
+ * If a recovery function is provided, it will be called with the error and its return value will be used as the mapped value.
363
+ * If no recovery function is provided, the error will be logged as an unhandled promise rejection.
364
+ *
365
+ * @typeParam O - The type of the mapped value.
366
+ * @param fn - The function to map the values emitted by the signal. The second argument to this function allows to cancel the previously running mapping function if it has not completed by the time a new value is emitted.
367
+ * @param alt - The alternate value to use if the signal is disposed or the mapping function throws an error.
368
+ * @param recover - The recovery function to handle errors thrown by the mapping function.
369
+ * @param equals - The equality function to compare the mapped values for equality.
370
+ * @returns A property that holds the mapped value and can be observed for changes.
371
+ */
372
+ mapAsync = (e, s, r, n = (i, o) => i === o) => {
373
+ const i = T(s, n);
374
+ let o = 0, l = new AbortController();
375
+ return i.onDispose(
376
+ this.on(async (c) => {
377
+ const a = ++o;
378
+ l.abort(), l = new AbortController();
379
+ try {
380
+ const u = await e(c, { abortSignal: l.signal });
381
+ a === o && i.set(u);
382
+ } catch (u) {
383
+ if (a === o)
384
+ if (r != null)
385
+ i.set(r(u));
386
+ else
387
+ throw u;
388
+ }
389
+ })
390
+ ), i;
391
+ };
392
+ /**
393
+ * Maps the values of the signal using the provided function `fn`, and returns a new signal
394
+ * containing the mapped values. If the mapped value is `undefined` or `null`, it is replaced
395
+ * with the provided `alt` value.
396
+ *
397
+ * @typeParam O - The type of the mapped value.
398
+ * @param fn - The function used to map the values of the signal.
399
+ * @param alt - The alternative value to use when the mapped value is `undefined` or `null`.
400
+ * @returns A new signal containing the mapped values.
401
+ */
402
+ mapMaybe = (e, s) => this.map((r) => e(r) ?? s);
403
+ /**
404
+ * Feeds a property into the signal and sets up disposal behavior.
405
+ * @param prop - The property to feed into the signal.
406
+ * @param autoDisposeProp - Determines whether the property should be automatically disposed when the signal is disposed.
407
+ * @returns The input property.
408
+ */
409
+ feedProp = (e, s = !1) => {
410
+ const r = this.on(e.set);
411
+ return e.onDispose(r), s ? this.onDispose(e.dispose) : this.onDispose(r), e;
412
+ };
413
+ /**
414
+ * Derives a new property from the current signal.
415
+ * @param options - The options for the derived property.
416
+ * @param options.autoDisposeProp - Determines whether the derived property should be automatically disposed.
417
+ * @param options.equals - A function that determines if two values are equal.
418
+ * @returns The derived property.
419
+ */
420
+ deriveProp = ({
421
+ autoDisposeProp: e = !0,
422
+ equals: s
423
+ } = {}) => this.feedProp(T(this.get(), s), e);
424
+ /**
425
+ * Derives a new signal from the current signal. Useful to create a new signal that emits the same values as the current signal but can be disposed independently.
426
+ * @returns A new signal that emits the same values as the current signal.
427
+ */
428
+ derive = () => this.map((e) => e);
429
+ /**
430
+ * Returns a signal that emits the count of values received so far.
431
+ * @returns A signal that emits the count of values received so far.
432
+ */
433
+ count = () => {
434
+ let e = 0;
435
+ return this.map(() => ++e);
436
+ };
437
+ /**
438
+ * Adds a computed value as a derivative of the signal.
439
+ * When the computed value is disposed, it is automatically removed from the derivatives list.
440
+ * Additionally, when the computed value is disposed, it sets the signal as dirty.
441
+ * @param computed - The computed value to add as a derivative.
442
+ */
443
+ setDerivative = (e) => {
444
+ this._derivatives.push(e), e.onDispose(() => {
445
+ this._derivatives.splice(
446
+ this._derivatives.indexOf(e),
447
+ 1
448
+ );
449
+ }), e.onDispose(this.on(e.setDirty)), this.onDispose(e.dispose);
450
+ };
451
+ }
452
+ const Be = typeof queueMicrotask == "function" ? queueMicrotask : (t) => Promise.resolve().then(t);
453
+ class $ extends g {
454
+ /**
455
+ * Creates a new Computed signal.
456
+ *
457
+ * **Auto-Registration:** This constructor automatically registers the signal with the current
458
+ * disposal scope (if one exists). This ensures that computed signals created by methods like
459
+ * `.map()`, `.flatMap()`, `.filter()`, etc. are automatically tracked and disposed.
460
+ *
461
+ * When a computed signal is created within a renderable or `WithScope()`, it will be
462
+ * automatically disposed when the component unmounts or the scope is disposed.
463
+ *
464
+ * To create a computed signal that outlives the current scope, use `untracked()`:
465
+ * ```typescript
466
+ * const globalSignal = untracked(() => mySignal.map(x => x * 2));
467
+ * // Remember to dispose manually: globalSignal.dispose()
468
+ * ```
469
+ *
470
+ * @param _fn - The function that computes the value of the signal.
463
471
  * @param equals - The function used to compare two values of type T for equality.
472
+ *
473
+ * @see {@link computed} - Factory function for creating computed signals with explicit dependencies
474
+ * @see {@link Signal.map} - Creates a computed signal by transforming values
475
+ * @see {@link getCurrentScope} - Get the current disposal scope
476
+ * @see {@link untracked} - Create signals outside of scope tracking
464
477
  */
465
- constructor(t, r) {
466
- super(void 0, r);
467
- /**
468
- * @internal
469
- */
470
- o(this, "$__computed__", !0);
471
- /**
472
- * @internal
473
- */
474
- o(this, "_isDirty", !1);
475
- /**
476
- * Marks the signal as dirty, indicating that its value has changed and needs to be recalculated.
477
- * If the signal is already dirty or disposed, this method does nothing.
478
- * It also marks all dependent signals as dirty and schedules a notification to update their values.
479
- */
480
- o(this, "setDirty", () => {
481
- this._isDirty || this._disposed || (this._isDirty = !0, this._derivatives.forEach((t) => t.setDirty()), this._scheduleNotify());
482
- });
483
- /**
484
- * @internal
485
- */
486
- o(this, "_scheduleCount", 0);
487
- /**
488
- * Schedules a notification to be executed asynchronously.
489
- * If the signal is dirty, it will be updated and notified.
490
- * @internal
491
- */
492
- o(this, "_scheduleNotify", () => {
493
- const t = ++this._scheduleCount;
494
- Ze(() => {
495
- this._scheduleCount !== t || this._disposed || this._isDirty && (this._isDirty = !1, this._setAndNotify(this._fn()));
496
- });
497
- });
498
- /** {@inheritDoc Signal.get} */
499
- o(this, "get", () => (this._isDirty && (this._isDirty = !1, this._setAndNotify(this._fn())), this._value));
500
- this._fn = t, this.setDirty();
478
+ constructor(e, s) {
479
+ super(void 0, s), this._fn = e, this.setDirty();
480
+ const r = ge();
481
+ r?.track(this);
501
482
  }
502
483
  /**
503
484
  * Checks if a value is an instance of `Computed`.
@@ -505,137 +486,174 @@ class N extends y {
505
486
  * @param value - The value to check.
506
487
  * @returns `true` if the value is an instance of `Computed`, `false` otherwise.
507
488
  */
508
- static is(t) {
509
- return t != null && t.$__computed__ === !0;
510
- }
489
+ static is(e) {
490
+ return e != null && e.$__computed__ === !0;
491
+ }
492
+ /**
493
+ * @internal
494
+ */
495
+ $__computed__ = !0;
496
+ /**
497
+ * @internal
498
+ */
499
+ _isDirty = !1;
500
+ /**
501
+ * Marks the signal as dirty, indicating that its value has changed and needs to be recalculated.
502
+ * If the signal is already dirty or disposed, this method does nothing.
503
+ * It also marks all dependent signals as dirty and schedules a notification to update their values.
504
+ */
505
+ setDirty = () => {
506
+ this._isDirty || this._disposed || (this._isDirty = !0, this._derivatives.forEach((e) => e.setDirty()), this._scheduleNotify());
507
+ };
508
+ /**
509
+ * @internal
510
+ */
511
+ _scheduleCount = 0;
512
+ /**
513
+ * Schedules a notification to be executed asynchronously.
514
+ * If the signal is dirty, it will be updated and notified.
515
+ * @internal
516
+ */
517
+ _scheduleNotify = () => {
518
+ const e = ++this._scheduleCount;
519
+ Be(() => {
520
+ this._scheduleCount !== e || this._disposed || this._isDirty && (this._isDirty = !1, this._setAndNotify(this._fn()));
521
+ });
522
+ };
523
+ /** {@inheritDoc Signal.get} */
524
+ get = () => (this._isDirty && (this._isDirty = !1, this._setAndNotify(this._fn())), this._value);
511
525
  /** {@inheritDoc Signal.value} */
512
526
  get value() {
513
527
  return this.get();
514
528
  }
529
+ /**
530
+ * Disposes the computed signal and cancels any pending recomputations.
531
+ * This override increments the schedule count to invalidate all pending
532
+ * microtasks before disposing the signal.
533
+ */
534
+ dispose = () => {
535
+ this._disposed || (this._scheduleCount++, this._disposed = !0, this._onDisposeListeners.forEach((e) => e()), this._onDisposeListeners.length = 0, this._derivatives.length = 0);
536
+ };
515
537
  }
516
- const ee = class ee extends y {
517
- constructor() {
518
- super(...arguments);
519
- /**
520
- * @internal
521
- */
522
- o(this, "$__prop__", !0);
523
- /**
524
- * Changes the value of the property and notifies its listeners.
525
- *
526
- * @param value - The new value of the property.
527
- */
528
- o(this, "set", (t) => {
529
- this._setAndNotify(t);
530
- });
531
- /**
532
- * Updates the value of the signal by applying the provided function to the current value.
533
- * @param fn - The function to apply to the current value.
534
- */
535
- o(this, "update", (t) => {
536
- this._setAndNotify(t(this.get()));
537
- });
538
- /**
539
- * Creates a reducer function that combines the provided reducer function and effects.
540
- * @param fn - The reducer function that takes the current state and an action, and returns the new state.
541
- * @param effects - An array of effects to be executed after the state is updated.
542
- * @returns A dispatch function that can be used to update the state and trigger the effects.
543
- */
544
- o(this, "reducer", (t, ...r) => {
545
- const n = this;
546
- return function i(l) {
547
- const c = n.value;
548
- n.update((a) => t(a, l)), !n.equals(c, n.value) && r.forEach(
549
- (a) => a({
550
- previousState: c,
551
- state: n.value,
552
- action: l,
553
- dispatch: i
554
- })
555
- );
556
- };
557
- });
558
- /**
559
- * Creates an isomorphism for the Signal.
560
- * An isomorphism is a pair of functions that convert values between two types,
561
- * along with an equality function to compare values of the second type.
562
- *
563
- * @param to - A function that converts values from type T to type O.
564
- * @param from - A function that converts values from type O to type T.
565
- * @param equals - An optional function that compares values of type O for equality.
566
- * Defaults to a strict equality check (===).
567
- * @returns A Prop object representing the isomorphism.
568
- */
569
- o(this, "iso", (t, r, n = (i, l) => i === l) => {
570
- const i = new ee(t(this.get()), n);
571
- return i.onDispose(this.on((l) => i.set(t(l)))), i.on((l) => this._setAndNotify(r(l))), i;
572
- });
573
- /**
574
- * Returns a `Prop` that represents the value at the specified key of the current value.
575
- *
576
- * @param key - The key of the value to access.
577
- * @returns A `Prop` that represents the value at the specified key.
578
- */
579
- o(this, "atProp", (t) => this.iso(
580
- (r) => r[t],
581
- (r) => ({ ...this.value, [t]: r })
582
- ));
583
- }
538
+ class Z extends g {
539
+ /**
540
+ * Checks if a value is a Prop.
541
+ * @param value - The value to check.
542
+ * @returns `true` if the value is a Prop, `false` otherwise.
543
+ */
544
+ static is = (e) => (
545
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
546
+ e != null && e.$__prop__ === !0
547
+ );
548
+ /**
549
+ * @internal
550
+ */
551
+ $__prop__ = !0;
552
+ /**
553
+ * Changes the value of the property and notifies its listeners.
554
+ *
555
+ * @param value - The new value of the property.
556
+ */
557
+ set = (e) => {
558
+ this._setAndNotify(e);
559
+ };
560
+ /**
561
+ * Updates the value of the signal by applying the provided function to the current value.
562
+ * @param fn - The function to apply to the current value.
563
+ */
564
+ update = (e) => {
565
+ this._setAndNotify(e(this.get()));
566
+ };
567
+ /**
568
+ * Creates a reducer function that combines the provided reducer function and effects.
569
+ * @param fn - The reducer function that takes the current state and an action, and returns the new state.
570
+ * @param effects - An array of effects to be executed after the state is updated.
571
+ * @returns A dispatch function that can be used to update the state and trigger the effects.
572
+ */
573
+ reducer = (e, ...s) => {
574
+ const r = this;
575
+ return function n(i) {
576
+ const o = r.value;
577
+ r.update((l) => e(l, i)), !r.equals(o, r.value) && s.forEach(
578
+ (l) => l({
579
+ previousState: o,
580
+ state: r.value,
581
+ action: i,
582
+ dispatch: n
583
+ })
584
+ );
585
+ };
586
+ };
587
+ /**
588
+ * Creates an isomorphism for the Signal.
589
+ * An isomorphism is a pair of functions that convert values between two types,
590
+ * along with an equality function to compare values of the second type.
591
+ *
592
+ * @param to - A function that converts values from type T to type O.
593
+ * @param from - A function that converts values from type O to type T.
594
+ * @param equals - An optional function that compares values of type O for equality.
595
+ * Defaults to a strict equality check (===).
596
+ * @returns A Prop object representing the isomorphism.
597
+ */
598
+ iso = (e, s, r = (n, i) => n === i) => {
599
+ const n = new Z(e(this.get()), r);
600
+ return n.onDispose(this.on((i) => n.set(e(i)))), n.on((i) => this._setAndNotify(s(i))), n;
601
+ };
602
+ /**
603
+ * Returns a `Prop` that represents the value at the specified key of the current value.
604
+ *
605
+ * @param key - The key of the value to access.
606
+ * @returns A `Prop` that represents the value at the specified key.
607
+ */
608
+ atProp = (e) => this.iso(
609
+ (s) => s[e],
610
+ (s) => ({ ...this.value, [e]: s })
611
+ );
584
612
  /**
585
613
  * Access for the current value of the property.
586
614
  */
587
615
  get value() {
588
616
  return this.get();
589
617
  }
590
- set value(t) {
591
- this._setAndNotify(t);
618
+ set value(e) {
619
+ this._setAndNotify(e);
592
620
  }
593
- };
594
- /**
595
- * Checks if a value is a Prop.
596
- * @param value - The value to check.
597
- * @returns `true` if the value is a Prop, `false` otherwise.
598
- */
599
- o(ee, "is", (t) => (
600
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
601
- t != null && t.$__prop__ === !0
602
- ));
603
- let G = ee;
604
- const ae = (s, e, t = (r, n) => r === n) => {
605
- const r = new N(s, t);
621
+ }
622
+ const z = (t, e, s = (r, n) => r === n) => {
623
+ const r = new $(t, s);
606
624
  return e.forEach((n) => n.setDerivative(r)), r;
607
- }, ze = (s, e, t = {}) => {
608
- let r = t.once ? () => {
609
- i(), s();
610
- } : s;
611
- if (t.skipInitial) {
612
- let l = !1;
613
- const c = r;
625
+ }, me = (t, e, s = {}) => {
626
+ let r = s.once ? () => {
627
+ i(), t();
628
+ } : t;
629
+ if (s.skipInitial) {
630
+ let o = !1;
631
+ const l = r;
614
632
  r = () => {
615
- l ? c() : l = !0;
633
+ o ? l() : o = !0;
616
634
  };
617
635
  }
618
- const n = ae(r, e), i = () => {
619
- n.dispose(), t.abortSignal != null && t.abortSignal.removeEventListener("abort", i);
636
+ const n = z(r, e), i = () => {
637
+ n.dispose(), s.abortSignal != null && s.abortSignal.removeEventListener("abort", i);
620
638
  };
621
- return t.abortSignal != null && t.abortSignal.addEventListener("abort", i), i;
622
- }, w = (s, e = (t, r) => t === r) => new G(s, e), te = (s, e = (t, r) => t === r) => new y(s, e), ue = () => (
623
- /* c8 ignore next */
624
- typeof window < "u" ? window : void 0
625
- );
626
- function Se(s) {
627
- return s != null && s !== !1 && s !== 0 && s !== "";
639
+ return s.abortSignal != null && s.abortSignal.addEventListener("abort", i), i;
640
+ }, T = (t, e = (s, r) => s === r) => {
641
+ const s = new Z(t, e), r = ge();
642
+ return r?.track(s), s;
643
+ }, K = (t, e = (s, r) => s === r) => new g(t, e);
644
+ function ye(t) {
645
+ return t != null && t !== !1 && t !== 0 && t !== "";
628
646
  }
629
- function Ke(s) {
630
- return !Se(s);
647
+ function We(t) {
648
+ return !ye(t);
631
649
  }
632
- function et(s) {
633
- return s == null;
650
+ function Ue(t) {
651
+ return t == null;
634
652
  }
635
- function tt(s) {
636
- return s != null;
653
+ function Je(t) {
654
+ return t != null;
637
655
  }
638
- const b = {
656
+ const y = {
639
657
  /**
640
658
  * Maps a value or a Signal to a new value.
641
659
  * If the value is a Signal, it returns a new Signal with the mapped value.
@@ -647,7 +665,7 @@ const b = {
647
665
  * @param fn - The function to map the value.
648
666
  * @returns The mapped value.
649
667
  */
650
- map: (s, e) => y.is(s) ? s.map(e) : e(s),
668
+ map: (t, e) => g.is(t) ? t.map(e) : e(t),
651
669
  /**
652
670
  * Wraps a value or a Signal instance into a Signal.
653
671
  * If the value is already a Signal, it returns the value itself.
@@ -658,30 +676,30 @@ const b = {
658
676
  * @param equals - A function that determines if two values are equal. Defaults to strict equality (===).
659
677
  * @returns A Signal instance.
660
678
  */
661
- toSignal: (s, e) => y.is(s) ? s : te(s, e),
679
+ toSignal: (t, e) => g.is(t) ? t.derive() : K(t, e),
662
680
  /**
663
681
  * Wraps a value in a `Signal` if it is not already a `Signal`.
664
682
  * If the value is `null` or `undefined`, it returns `null` or `undefined` respectively.
665
683
  * @param value - The value to wrap or check.
666
684
  * @returns The wrapped value if it is not `null` or `undefined`, otherwise `null` or `undefined`.
667
685
  */
668
- maybeToSignal: (s, e) => {
669
- if (s != null)
670
- return b.toSignal(s, e);
686
+ maybeToSignal: (t, e) => {
687
+ if (t != null)
688
+ return y.toSignal(t, e);
671
689
  },
672
690
  /**
673
691
  * Gets the value from a `Signal` or the value itself if it is not a `Signal`.
674
692
  * @param value - The value or Signal instance to get the value from.
675
693
  * @returns The value.
676
694
  */
677
- get: (s) => y.is(s) ? s.get() : s,
695
+ get: (t) => g.is(t) ? t.get() : t,
678
696
  /**
679
697
  * Adds a listener to a `Signal` or calls the listener immediately if it is not a `Signal`.
680
698
  * @param value - The value or Signal instance to add the listener to.
681
699
  * @param listener - The listener to call when the value changes.
682
700
  * @returns A function to remove the listener.
683
701
  */
684
- on: (s, e) => y.is(s) ? s.on(e) : (e(s), () => {
702
+ on: (t, e) => g.is(t) ? t.on(e) : (e(t), () => {
685
703
  }),
686
704
  /**
687
705
  * Disposes of a value or a Signal.
@@ -689,9 +707,17 @@ const b = {
689
707
  * If the value is not a Signal, it does nothing.
690
708
  * @param value - The value or Signal instance to dispose of.
691
709
  */
692
- dispose: (s) => {
693
- y.is(s) && s.dispose();
710
+ dispose: (t) => {
711
+ g.is(t) && t.dispose();
694
712
  },
713
+ /**
714
+ * Returns a function that disposes of a value or a Signal.
715
+ * If the value is a Signal, it returns a function that disposes of the Signal.
716
+ * If the value is not a Signal, it returns a function that does nothing.
717
+ * @param value - The value or Signal instance to dispose of.
718
+ * @returns A function to dispose of the value or Signal.
719
+ */
720
+ disposeFn: (t) => () => y.dispose(t),
695
721
  /**
696
722
  * Derives a Prop from a Signal.
697
723
  * If the value is a Signal, it returns a new Prop with the derived value.
@@ -702,522 +728,463 @@ const b = {
702
728
  * @param options.equals - A function that determines if two values are equal.
703
729
  * @returns A Prop instance.
704
730
  */
705
- deriveProp: (s, {
731
+ deriveProp: (t, {
706
732
  autoDisposeProp: e = !0,
707
- equals: t
708
- } = {}) => y.is(s) ? s.deriveProp({ autoDisposeProp: e, equals: t }) : w(s, t),
733
+ equals: s
734
+ } = {}) => g.is(t) ? t.deriveProp({ autoDisposeProp: e, equals: s }) : T(t, s),
709
735
  /**
710
736
  * Creates a new signal that emits `true` if the value is truthy, `false` otherwise.
711
737
  * @param value - The value or signal to check.
712
738
  * @returns A signal that emits `true` if the value is truthy, `false` otherwise.
713
739
  */
714
- truthy: (s) => b.map(s, Se),
740
+ truthy: (t) => y.map(t, ye),
715
741
  /**
716
742
  * Creates a new signal that emits `true` if the value is falsy, `false` otherwise.
717
743
  * @param value - The value or signal to check.
718
744
  * @returns A signal that emits `true` if the value is falsy, `false` otherwise.
719
745
  */
720
- falsy: (s) => b.map(s, Ke),
746
+ falsy: (t) => y.map(t, We),
721
747
  /**
722
748
  * Creates a new signal that emits `true` if the value is null or undefined, `false` otherwise.
723
749
  * @param value - The value or signal to check.
724
750
  * @returns A signal that emits `true` if the value is null or undefined, `false` otherwise.
725
751
  */
726
- nil: (s) => b.map(s, et),
752
+ nil: (t) => y.map(t, Ue),
727
753
  /**
728
754
  * Creates a new signal that emits `true` if the value is not null or undefined, `false` otherwise.
729
755
  * @param value - The value or signal to check.
730
756
  * @returns A signal that emits `true` if the value is not null or undefined, `false` otherwise.
731
757
  */
732
- defined: (s) => b.map(s, tt)
733
- }, he = (...s) => (e, t) => {
734
- if (s.length === 1)
735
- return b.toSignal(s[0]).map(e);
736
- const r = s.filter((n) => y.is(n));
737
- return ae(
738
- () => e(...s.map((n) => b.get(n))),
758
+ defined: (t) => y.map(t, Je)
759
+ }, ee = (...t) => (e, s) => {
760
+ if (t.length === 1)
761
+ return y.toSignal(t[0]).map(e);
762
+ const r = t.filter((n) => g.is(n));
763
+ return z(
764
+ () => e(...t.map((n) => y.get(n))),
739
765
  r,
740
- t
766
+ s
741
767
  );
742
- }, Jt = (s) => {
743
- const e = Object.keys(s);
744
- return he(...Object.values(s))(
745
- (...t) => Object.fromEntries(e.map((r, n) => [r, t[n]]))
768
+ }, Jt = (t) => {
769
+ const e = Object.keys(t);
770
+ return ee(...Object.values(t))(
771
+ (...s) => Object.fromEntries(e.map((r, n) => [r, s[n]]))
746
772
  );
747
- }, Gt = (...s) => (e, t = {}) => {
748
- const r = s.filter((n) => y.is(n));
749
- return ze(
750
- () => e(...s.map(b.get)),
773
+ }, Ge = (...t) => (e, s = {}) => {
774
+ const r = t.filter((n) => g.is(n));
775
+ return me(
776
+ () => e(...t.map(y.get)),
751
777
  r,
752
- t
778
+ s
753
779
  );
754
780
  };
755
- class ve {
756
- constructor() {
757
- o(this, "_store", /* @__PURE__ */ new Map());
758
- /**
759
- * Retrieves the value associated with the specified key from the memory store.
760
- * @param key - The key to retrieve the value for.
761
- * @returns The value associated with the key, or `null` if the key is not found.
762
- */
763
- o(this, "getItem", (e) => this._store.get(e) ?? null);
764
- /**
765
- * Sets the value associated with the specified key in the memory store.
766
- * @param key - The key to set the value for.
767
- * @param value - The value to set.
768
- */
769
- o(this, "setItem", (e, t) => {
770
- this._store.set(e, t);
771
- });
781
+ class q {
782
+ _signals = /* @__PURE__ */ new Set();
783
+ _callbacks = [];
784
+ _disposed = !1;
785
+ /**
786
+ * Register a signal with this scope for automatic disposal.
787
+ *
788
+ * @param signal - The signal to track
789
+ * @throws Error if the scope has already been disposed
790
+ * @throws Error if the signal has already been disposed
791
+ * @public
792
+ */
793
+ track(e) {
794
+ if (this._disposed)
795
+ throw new Error("Cannot track signal in disposed scope");
796
+ if (e.isDisposed())
797
+ throw new Error("Cannot track already disposed signal");
798
+ this._signals.add(e);
799
+ }
800
+ /**
801
+ * Register a disposal callback to be called when this scope is disposed.
802
+ * Callbacks are called before signals are disposed.
803
+ * Use this for cleanup that doesn't need the `removeTree` parameter.
804
+ *
805
+ * @param callback - The callback to call on disposal
806
+ * @throws Error if the scope has already been disposed
807
+ * @public
808
+ */
809
+ onDispose(e) {
810
+ if (this._disposed)
811
+ throw new Error("Cannot register callback in disposed scope");
812
+ this._callbacks.push(e);
813
+ }
814
+ /**
815
+ * Dispose all signals tracked by this scope.
816
+ * This method is idempotent - calling it multiple times is safe.
817
+ *
818
+ * @public
819
+ */
820
+ dispose() {
821
+ if (!this._disposed) {
822
+ this._disposed = !0;
823
+ for (const e of this._callbacks)
824
+ try {
825
+ e();
826
+ } catch (s) {
827
+ console.error("Error in disposal callback:", s);
828
+ }
829
+ this._callbacks.length = 0;
830
+ for (const e of this._signals)
831
+ e.dispose();
832
+ this._signals.clear();
833
+ }
834
+ }
835
+ /**
836
+ * Check if this scope has been disposed.
837
+ *
838
+ * @returns true if the scope has been disposed
839
+ * @public
840
+ */
841
+ get disposed() {
842
+ return this._disposed;
843
+ }
844
+ /**
845
+ * Creates a prop signal and tracks it in this scope.
846
+ * Use this method in async contexts where automatic tracking doesn't work.
847
+ *
848
+ * @param value - The initial value
849
+ * @param equals - Optional equality function
850
+ * @returns A tracked Prop signal
851
+ * @public
852
+ */
853
+ prop(e, s) {
854
+ const r = oe(() => T(e, s));
855
+ return this.track(r), r;
856
+ }
857
+ /**
858
+ * Creates a computed signal and tracks it in this scope.
859
+ * Use this method in async contexts where automatic tracking doesn't work.
860
+ *
861
+ * @param fn - The computation function
862
+ * @param dependencies - Array of signals this computed depends on
863
+ * @param equals - Optional equality function
864
+ * @returns A tracked Computed signal
865
+ * @public
866
+ */
867
+ computed(e, s, r) {
868
+ const n = oe(() => z(e, s, r));
869
+ return this.track(n), n;
870
+ }
871
+ /**
872
+ * Creates an effect and tracks it in this scope.
873
+ * Use this method in async contexts where automatic tracking doesn't work.
874
+ *
875
+ * @param fn - The effect function
876
+ * @param signals - Array of signals to listen to
877
+ * @param options - Optional listener options
878
+ * @returns A clear function (the effect itself is tracked in the scope)
879
+ * @public
880
+ */
881
+ effect(e, s, r) {
882
+ return L(this, () => me(e, s, r));
883
+ }
884
+ /**
885
+ * Creates a computed signal with curried signature and tracks it in this scope.
886
+ * Use this method in async contexts where automatic tracking doesn't work.
887
+ *
888
+ * @param args - Values or signals to compute from
889
+ * @returns A function that takes the computation function and returns a tracked Computed signal
890
+ * @public
891
+ */
892
+ computedOf(...e) {
893
+ return (s, r) => {
894
+ const n = oe(() => ee(...e)(s, r));
895
+ return this.track(n), n;
896
+ };
897
+ }
898
+ /**
899
+ * Creates an effect with curried signature and tracks it in this scope.
900
+ * Use this method in async contexts where automatic tracking doesn't work.
901
+ *
902
+ * @param args - Values or signals to listen to
903
+ * @returns A function that takes the effect function and returns a clear function
904
+ * @public
905
+ */
906
+ effectOf(...e) {
907
+ return (s, r) => L(this, () => Ge(...e)(s, r));
908
+ }
909
+ }
910
+ const Xe = (t, e, s) => t + (e - t) * s, de = 97, Ye = (t, e, s) => {
911
+ const r = Math.max(t.length, e.length);
912
+ let n = "";
913
+ for (let i = 0; i < r; i++) {
914
+ let o = t.charCodeAt(i);
915
+ isNaN(o) && (o = de);
916
+ let l = e.charCodeAt(i);
917
+ isNaN(l) && (l = de), n += String.fromCharCode(o + (l - o) * s);
918
+ }
919
+ return n;
920
+ }, Qe = (t, e, s) => new Date(t.getTime() + (e.getTime() - t.getTime()) * s), Ze = (t, e) => e, ze = (t) => typeof t == "number" ? Xe : typeof t == "string" ? Ye : t instanceof Date ? Qe : Ze;
921
+ class le {
922
+ /**
923
+ * Creates a new instance of `ElementPosition`.
924
+ * @param index - The index of the element.
925
+ * @param total - The total number of elements in the collection.
926
+ */
927
+ constructor(e, s) {
928
+ this.index = e, this.total = s, this.counter = e + 1, this.isFirst = e === 0, this.isEven = e % 2 === 1, this.isOdd = e % 2 === 0;
929
+ }
930
+ /**
931
+ * The counter of the element starting from 1.
932
+ */
933
+ counter;
934
+ /**
935
+ * Checks if the element is the first element in the collection.
936
+ * @returns `true` if the element is the first element, `false` otherwise.
937
+ */
938
+ isFirst;
939
+ /**
940
+ * Checks if the counter of the element is even.
941
+ * @returns `true` if the counter is even, `false` otherwise.
942
+ */
943
+ isEven;
944
+ /**
945
+ * Checks if the counter of the element is odd.
946
+ * @returns `true` if the counter is odd, `false` otherwise.
947
+ */
948
+ isOdd;
949
+ #e;
950
+ /**
951
+ * Checks if the element is the last element in the collection.
952
+ * @returns `true` if the element is the last element, `false` otherwise.
953
+ */
954
+ get isLast() {
955
+ return this.#e == null && (this.#e = this.total.map((e) => this.counter === e)), this.#e;
772
956
  }
957
+ /**
958
+ * Disposes the internal signal created by `isLast`.
959
+ *
960
+ * **Note:** With automatic signal disposal, this method is now a no-op when used within
961
+ * a disposal scope (e.g., inside a renderable). The signal created by `isLast` is
962
+ * automatically tracked and disposed when the scope ends. This method is kept for
963
+ * backward compatibility and for cases where ElementPosition is used outside a scope.
964
+ */
965
+ dispose = () => {
966
+ this.#e?.dispose(), this.#e = void 0;
967
+ };
968
+ }
969
+ const ce = () => (
970
+ /* c8 ignore next */
971
+ typeof window < "u" ? window : void 0
972
+ );
973
+ class be {
974
+ _store = /* @__PURE__ */ new Map();
975
+ /**
976
+ * Retrieves the value associated with the specified key from the memory store.
977
+ * @param key - The key to retrieve the value for.
978
+ * @returns The value associated with the key, or `null` if the key is not found.
979
+ */
980
+ getItem = (e) => this._store.get(e) ?? null;
981
+ /**
982
+ * Sets the value associated with the specified key in the memory store.
983
+ * @param key - The key to set the value for.
984
+ * @param value - The value to set.
985
+ */
986
+ setItem = (e, s) => {
987
+ this._store.set(e, s);
988
+ };
773
989
  }
774
- const Ae = ({
775
- key: s,
990
+ const Se = ({
991
+ key: t,
776
992
  defaultValue: e,
777
- store: t,
993
+ store: s,
778
994
  serialize: r = JSON.stringify,
779
995
  deserialize: n = JSON.parse,
780
- equals: i = (u, h) => u === h,
781
- onLoad: l = (u) => u,
782
- syncTabs: c = !0,
783
- onKeyChange: a = "load"
996
+ equals: i = (a, u) => a === u,
997
+ onLoad: o = (a) => a,
998
+ syncTabs: l = !0,
999
+ onKeyChange: c = "load"
784
1000
  }) => {
785
- let u = b.get(s);
786
- const h = t.getItem(u), d = new G(
787
- h != null ? l(n(h)) : typeof e == "function" ? e() : e,
1001
+ let a = y.get(t);
1002
+ const u = s.getItem(a), h = new Z(
1003
+ u != null ? o(n(u)) : typeof e == "function" ? e() : e,
788
1004
  i
789
- ), p = ue(), m = c && typeof (p == null ? void 0 : p.BroadcastChannel) == "function";
790
- let g = !1, S = null, P = null;
791
- const A = (T) => {
792
- if (!m) return null;
793
- const H = `tempo:storedProp:${T}`, v = new p.BroadcastChannel(H), k = `${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`, O = (W) => {
794
- const E = W.data;
795
- if (!(E == null || typeof E != "object" || E.key !== T || typeof E.value != "string" || E.sourceId != null && E.sourceId === k))
1005
+ ), p = ce(), f = l && typeof p?.BroadcastChannel == "function";
1006
+ let m = !1, S = null, D = null;
1007
+ const w = (b) => {
1008
+ if (!f) return null;
1009
+ const k = `tempo:storedProp:${b}`, A = new p.BroadcastChannel(k), M = `${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`, x = (F) => {
1010
+ const v = F.data;
1011
+ if (!(v == null || typeof v != "object" || v.key !== b || typeof v.value != "string" || v.sourceId != null && v.sourceId === M))
796
1012
  try {
797
- g = !0;
798
- const oe = l(n(E.value));
799
- d.set(oe);
800
- } catch (oe) {
1013
+ m = !0;
1014
+ const ie = o(n(v.value));
1015
+ h.set(ie);
1016
+ } catch (ie) {
801
1017
  console.warn(
802
- `Failed to sync storedProp for key "${T}" via BroadcastChannel`,
803
- oe
1018
+ `Failed to sync storedProp for key "${b}" via BroadcastChannel`,
1019
+ ie
804
1020
  );
805
1021
  } finally {
806
- g = !1;
1022
+ m = !1;
807
1023
  }
808
1024
  };
809
- return v.addEventListener("message", O), d.onDispose(() => {
810
- v == null || v.removeEventListener("message", O), v == null || v.close();
811
- }), { channel: v, instanceId: k, handleMessage: O };
812
- }, L = A(u);
813
- L && (S = L.channel, P = L.instanceId);
814
- const ie = (T) => {
815
- const H = u;
816
- if (H === T) return;
817
- const v = d.get(), k = r(v);
818
- if (t.setItem(H, k), S != null && (S.close(), S = null, P = null), u = T, a === "load") {
819
- const W = t.getItem(T);
820
- if (W != null)
1025
+ return A.addEventListener("message", x), h.onDispose(() => {
1026
+ A?.removeEventListener("message", x), A?.close();
1027
+ }), { channel: A, instanceId: M, handleMessage: x };
1028
+ }, P = w(a);
1029
+ P && (S = P.channel, D = P.instanceId);
1030
+ const ne = (b) => {
1031
+ const k = a;
1032
+ if (k === b) return;
1033
+ const A = h.get(), M = r(A);
1034
+ if (s.setItem(k, M), S != null && (S.close(), S = null, D = null), a = b, c === "load") {
1035
+ const F = s.getItem(b);
1036
+ if (F != null)
821
1037
  try {
822
- const E = l(n(W));
823
- d.set(E);
824
- } catch (E) {
1038
+ const v = o(n(F));
1039
+ h.set(v);
1040
+ } catch (v) {
825
1041
  console.warn(
826
- `Failed to load storedProp from new key "${T}"`,
827
- E
1042
+ `Failed to load storedProp from new key "${b}"`,
1043
+ v
828
1044
  );
829
1045
  }
830
1046
  else
831
- t.setItem(T, k);
832
- } else a === "migrate" && t.setItem(T, k);
833
- const O = A(T);
834
- O && (S = O.channel, P = O.instanceId);
835
- };
836
- return y.is(s) && d.onDispose(s.on(ie)), d.on((T, H) => {
837
- const v = r(T);
838
- t.setItem(u, v), S != null && !g && H !== void 0 && P != null && S.postMessage({
839
- key: u,
840
- value: v,
841
- sourceId: P
1047
+ s.setItem(b, M);
1048
+ } else c === "migrate" && s.setItem(b, M);
1049
+ const x = w(b);
1050
+ x && (S = x.channel, D = x.instanceId);
1051
+ };
1052
+ return g.is(t) && h.onDispose(t.on(ne)), h.on((b, k) => {
1053
+ const A = r(b);
1054
+ s.setItem(a, A), S != null && !m && k !== void 0 && D != null && S.postMessage({
1055
+ key: a,
1056
+ value: A,
1057
+ sourceId: D
842
1058
  });
843
- }), d;
844
- }, Xt = (s) => {
845
- var e;
846
- return Ae({
847
- ...s,
848
- /* c8 ignore next 3 */
849
- store: ((e = ue()) == null ? void 0 : e.localStorage) ?? new ve()
850
- });
851
- }, Yt = (s) => {
852
- var e;
853
- return Ae({
854
- ...s,
855
- /* c8 ignore next 3 */
856
- store: ((e = ue()) == null ? void 0 : e.sessionStorage) ?? new ve()
857
- });
858
- };
859
- function be(s) {
860
- return typeof requestAnimationFrame == "function" ? requestAnimationFrame(s) : setTimeout(s, 0);
1059
+ }), h;
1060
+ }, Gt = (t) => Se({
1061
+ ...t,
1062
+ /* c8 ignore next 3 */
1063
+ store: ce()?.localStorage ?? new be()
1064
+ }), Xt = (t) => Se({
1065
+ ...t,
1066
+ /* c8 ignore next 3 */
1067
+ store: ce()?.sessionStorage ?? new be()
1068
+ });
1069
+ function fe(t) {
1070
+ return typeof requestAnimationFrame == "function" ? requestAnimationFrame(t) : setTimeout(t, 0);
861
1071
  }
862
- const st = (s, e, t, r) => {
863
- const n = (r == null ? void 0 : r.duration) ?? 300, i = (r == null ? void 0 : r.easing) ?? ((A) => A), l = (r == null ? void 0 : r.equals) ?? ((A, L) => A === L);
864
- let c = r == null ? void 0 : r.interpolate, a = s, u = e(), h = performance.now(), d = null, p = !0;
865
- const m = new N(e, l), g = w(s, l);
866
- g.onDispose(() => {
867
- d !== null && cancelAnimationFrame(d);
868
- }), g.onDispose(m.dispose), t.forEach((A) => {
869
- A.setDerivative(m), A.onDispose(g.dispose);
1072
+ const Ke = (t, e, s, r) => {
1073
+ const n = r?.duration ?? 300, i = r?.easing ?? ((w) => w), o = r?.equals ?? ((w, P) => w === P);
1074
+ let l = r?.interpolate, c = t, a = e(), u = performance.now(), h = null, p = !0;
1075
+ const f = new $(e, o), m = T(t, o);
1076
+ m.onDispose(() => {
1077
+ h !== null && cancelAnimationFrame(h);
1078
+ }), m.onDispose(f.dispose), s.forEach((w) => {
1079
+ w.setDerivative(f), w.onDispose(m.dispose);
870
1080
  });
871
- const S = (A) => {
872
- u = A, h = performance.now(), a = g.value, p && (p = !1, d = be(P));
873
- }, P = () => {
874
- const L = (performance.now() - h) / b.get(n), ie = i(L);
875
- c == null && (c = Qe(a));
876
- let T = c(a, u, ie);
877
- L >= 1 ? (p = !0, T = u) : d = be(P), g.set(T);
878
- };
879
- return m.on(S), g;
880
- }, Qt = (s, e) => {
881
- const { initialValue: t, ...r } = e ?? {};
882
- return st(
1081
+ const S = (w) => {
1082
+ a = w, u = performance.now(), c = m.value, p && (p = !1, h = fe(D));
1083
+ }, D = () => {
1084
+ const P = (performance.now() - u) / y.get(n), ne = i(P);
1085
+ l == null && (l = ze(c));
1086
+ let b = l(c, a, ne);
1087
+ P >= 1 ? (p = !0, b = a) : h = fe(D), m.set(b);
1088
+ };
1089
+ return f.on(S), m;
1090
+ }, Yt = (t, e) => {
1091
+ const { initialValue: s, ...r } = e ?? {};
1092
+ return Ke(
883
1093
  /* c8 ignore next 2 */
884
- t ?? s.get(),
885
- s.get,
886
- [s],
1094
+ s ?? t.get(),
1095
+ t.get,
1096
+ [t],
887
1097
  r
888
1098
  );
889
- }, rt = (s, e) => {
890
- const t = Object.values(s).filter(y.is), r = Object.keys(s);
891
- return ae(() => {
1099
+ }, et = (t, e) => {
1100
+ const s = Object.values(t).filter(g.is), r = Object.keys(t);
1101
+ return z(() => {
892
1102
  const n = {};
893
1103
  for (const i of r)
894
- n[i] = b.get(s[i]);
1104
+ n[i] = y.get(t[i]);
895
1105
  return e(n);
896
- }, t);
897
- }, Zt = (s) => rt(s, (e) => e), zt = (s, e) => {
898
- const t = w(s.get());
1106
+ }, s);
1107
+ }, Qt = (t) => et(t, (e) => e), Zt = (t, e) => {
1108
+ const s = T(t.get());
899
1109
  let r = null;
900
- const n = s.on((i) => {
1110
+ const n = t.on((i) => {
901
1111
  r != null && clearTimeout(r), r = setTimeout(
902
1112
  () => {
903
- r = null, t.set(i);
1113
+ r = null, s.set(i);
904
1114
  },
905
1115
  typeof e == "function" ? e(i) : e
906
1116
  );
907
1117
  });
908
- return t.onDispose(() => {
1118
+ return s.onDispose(() => {
909
1119
  n(), r != null && clearTimeout(r);
910
- }), t;
911
- }, Kt = (s) => {
1120
+ }), s;
1121
+ }, zt = (t) => {
912
1122
  let e;
913
- return s.map((t) => {
1123
+ return t.map((s) => {
914
1124
  const r = e;
915
- return e = t, r;
1125
+ return e = s, r;
916
1126
  });
917
- }, es = ({
918
- size: s = void 0,
1127
+ }, Kt = ({
1128
+ size: t = void 0,
919
1129
  signal: e
920
1130
  }) => {
921
- const t = [];
922
- return e.map((r) => (t.push(r), s != null && t.length > s && t.shift(), t.slice()));
923
- }, ts = (s) => (...e) => he(
924
- s,
1131
+ const s = [];
1132
+ return e.map((r) => (s.push(r), t != null && s.length > t && s.shift(), s.slice()));
1133
+ }, es = (t) => (...e) => ee(
1134
+ t,
925
1135
  ...e
926
- )((t, ...r) => t(...r));
927
- function ss(...s) {
928
- return he(...s)((...e) => {
929
- for (const t of e) if (t != null) return t;
1136
+ )((s, ...r) => s(...r));
1137
+ function ts(...t) {
1138
+ return ee(...t)((...e) => {
1139
+ for (const s of e) if (s != null) return s;
930
1140
  });
931
1141
  }
932
- const _e = /* @__PURE__ */ new Set(["checked", "disabled", "hidden"]), Ee = /* @__PURE__ */ new Set(["selected"]), Ce = /* @__PURE__ */ new Set([
1142
+ const we = /* @__PURE__ */ new Set(["checked", "disabled", "hidden"]), _e = /* @__PURE__ */ new Set(["selected"]), ve = /* @__PURE__ */ new Set([
933
1143
  "rowSpan",
934
1144
  "colSpan",
935
1145
  "tabIndex",
936
1146
  "valueAsNumber"
937
- ]), we = /* @__PURE__ */ new Set(["valueAsDate"]), xe = /* @__PURE__ */ new Set([
1147
+ ]), Te = /* @__PURE__ */ new Set(["valueAsDate"]), Ae = /* @__PURE__ */ new Set([
938
1148
  "value",
939
1149
  "textContent",
940
1150
  "innerText",
941
1151
  "innerHTML",
942
- "outerHTML",
943
- "className",
944
- "classList"
945
- ]), nt = (s, e) => Ee.has(s) ? (t) => {
946
- t == null || t !== !0 ? e.removeAttribute(s) : e.setAttribute(s, "");
947
- } : _e.has(s) ? (t) => {
948
- t == null ? e[s] = null : e[s] = !!t;
949
- } : Ce.has(s) ? (t) => {
950
- t == null ? e[s] = null : e[s] = Number(t);
951
- } : we.has(s) ? (t) => {
952
- t == null ? e[s] = null : e[s] = t;
953
- } : xe.has(s) ? (t) => {
954
- t == null ? e[s] = null : e[s] = String(t);
955
- } : (t) => {
956
- t == null ? e.removeAttribute(s) : e.setAttribute(s, t);
957
- }, it = (s, e) => Ee.has(s) ? () => e.hasAttribute(s) : _e.has(s) ? () => !!e[s] : Ce.has(s) ? () => Number(e[s]) : we.has(s) ? () => e[s] : xe.has(s) ? () => String(e[s]) : () => e.getAttribute(s), X = (s) => {
958
- const e = s;
959
- e && e.onblur && (e.onblur = null), !(!s || s.ownerDocument === void 0) && s.parentElement && s.parentElement.removeChild(s);
960
- }, ot = (s) => Pe(s) ? s : s.parentElement, Pe = (s) => s.nodeType === 1;
961
- class Le extends Error {
962
- constructor(e) {
963
- super(`Provider not found: ${e.description}`);
964
- }
965
- }
966
- class R {
967
- /**
968
- * Constructs a new `DOMContext` instance.
969
- *
970
- * @param document - The `Document` instance associated with this context.
971
- * @param element - The `Element` instance associated with this context.
972
- * @param reference - An optional `Node` instance that serves as a reference for this context.
973
- * @param providers - The `Providers` instance associated with this context.
974
- * @param isFirstLevel - A boolean value indicating whether this context is at the first level, meaning the outermost node in the generated DOM.
975
- */
976
- constructor(e, t, r, n) {
977
- /**
978
- * Creates a new DOM element (eg: HTML or SVG) with the specified tag name and namespace.
979
- *
980
- * @param tagName - The tag name of the element to create.
981
- * @param namespace - The namespace URI to create the element in, or `undefined` to create a standard HTML element.
982
- * @returns The newly created element.
983
- */
984
- o(this, "createElement", (e, t) => t !== void 0 ? this.document.createElementNS(t, e) : this.document.createElement(e));
985
- /**
986
- * Creates a new child element and appends it to the current element, returning a new context.
987
- *
988
- * This method creates a new DOM element with the specified tag name and namespace,
989
- * appends it to the current element, and returns a new DOMContext focused on the
990
- * newly created child element. This is the primary method for building DOM trees.
991
- *
992
- * @example
993
- * ```typescript
994
- * // Create HTML elements
995
- * const divCtx = ctx.makeChildElement('div', undefined)
996
- * const spanCtx = divCtx.makeChildElement('span', undefined)
997
- *
998
- * // Create SVG elements
999
- * const svgCtx = ctx.makeChildElement('svg', 'http://www.w3.org/2000/svg')
1000
- * const circleCtx = svgCtx.makeChildElement('circle', 'http://www.w3.org/2000/svg')
1001
- * ```
1002
- *
1003
- * @param tagName - The tag name of the element to create (e.g., 'div', 'span', 'svg')
1004
- * @param namespace - The namespace URI for the element, or undefined for HTML elements
1005
- * @returns A new DOMContext focused on the newly created child element
1006
- */
1007
- o(this, "makeChildElement", (e, t) => {
1008
- const r = this.createElement(e, t);
1009
- return this.appendOrInsert(r), this.withElement(r);
1010
- });
1011
- /**
1012
- * Creates a new text node with the specified text content.
1013
- * @param text - The text content for the new text node.
1014
- * @returns A new `Text` node with the specified text content.
1015
- */
1016
- o(this, "createText", (e) => this.document.createTextNode(e));
1017
- /**
1018
- * Creates a new text node with the specified text content and appends it to the current element.
1019
- * @param text - The text content for the new text node.
1020
- * @returns A new `DOMContext` with a reference to the new text node.
1021
- */
1022
- o(this, "makeChildText", (e) => {
1023
- const t = this.createText(e);
1024
- return this.appendOrInsert(t), this.withReference(t);
1025
- });
1026
- /**
1027
- * Sets the text content of the current element.
1028
- * @param text - The text content to set.
1029
- */
1030
- o(this, "setText", (e) => {
1031
- this.reference.nodeValue = e;
1032
- });
1033
- /**
1034
- * Gets the text content of the current element or text node.
1035
- * @returns The text content of the current element or text node.
1036
- */
1037
- o(this, "getText", () => {
1038
- var e;
1039
- return ((e = this.reference) == null ? void 0 : e.nodeValue) ?? this.element.textContent ?? "";
1040
- });
1041
- /**
1042
- * Creates a new `DOMContext` with a reference to a newly created text node.
1043
- * The text node is appended or inserted to the current `DOMContext`.
1044
- * The new `DOMContext` with the reference is returned.
1045
- */
1046
- o(this, "makeRef", () => {
1047
- const e = this.createText("");
1048
- return this.appendOrInsert(e), this.withReference(e);
1049
- });
1050
- /**
1051
- * Appends or inserts a child node to the element, depending on whether a reference node is provided.
1052
- *
1053
- * @param child - The child node to append or insert.
1054
- */
1055
- o(this, "appendOrInsert", (e) => {
1056
- this.reference === void 0 ? this.element.appendChild(e) : this.element.insertBefore(e, this.reference);
1057
- });
1058
- /**
1059
- * Creates a new `DOMContext` instance with the provided `element`.
1060
- * @param element - The DOM element to use in the new `DOMContext` instance.
1061
- * @returns A new `DOMContext` instance with the provided `element`.
1062
- */
1063
- o(this, "withElement", (e) => new R(this.document, e, void 0, this.providers));
1064
- /**
1065
- * Creates a portal to render content in a different part of the DOM tree.
1066
- *
1067
- * Portals allow you to render child components into a DOM node that exists outside
1068
- * the parent component's DOM hierarchy. This is useful for modals, tooltips,
1069
- * dropdowns, and other UI elements that need to break out of their container's
1070
- * styling or z-index context.
1071
- *
1072
- * @example
1073
- * ```typescript
1074
- * // Portal to a modal container
1075
- * const modalCtx = ctx.makePortal('#modal-root')
1076
- * const modal = modalCtx.makeChildElement('div', undefined)
1077
- *
1078
- * // Add modal content
1079
- * modal.makeChildText('This renders in #modal-root')
1080
- * ```
1081
- *
1082
- * @example
1083
- * ```typescript
1084
- * // Portal to an existing element reference
1085
- * const tooltipContainer = document.getElementById('tooltip-container')!
1086
- * const tooltipCtx = ctx.makePortal(tooltipContainer)
1087
- *
1088
- * // Render tooltip content
1089
- * const tooltip = tooltipCtx.makeChildElement('div', undefined)
1090
- * tooltip.addClasses(['tooltip', 'tooltip-top'])
1091
- * ```
1092
- *
1093
- * @example
1094
- * ```typescript
1095
- * // Portal for dropdown menu
1096
- * const dropdownCtx = ctx.makePortal('body') // Render at body level
1097
- * const dropdown = dropdownCtx.makeChildElement('div', undefined)
1098
- * dropdown.addClasses(['dropdown-menu'])
1099
- * dropdown.setStyle('position', 'absolute')
1100
- * dropdown.setStyle('top', '100px')
1101
- * dropdown.setStyle('left', '50px')
1102
- * ```
1103
- *
1104
- * @param selector - CSS selector string or HTMLElement reference for the portal target
1105
- * @returns A new DOMContext focused on the portal target element
1106
- * @throws {Error} When the selector doesn't match any element in the document
1107
- */
1108
- o(this, "makePortal", (e) => {
1109
- const t = typeof e == "string" ? this.document.querySelector(e) : e;
1110
- if (t == null)
1111
- throw new Error(`Cannot find element by selector for portal: ${e}`);
1112
- return this.withElement(t);
1113
- });
1114
- /**
1115
- * Creates a new `DOMContext` instance with the specified reference.
1116
- *
1117
- * @param reference - The optional `Text` node to use as the reference for the new `DOMContext`.
1118
- * @returns A new `DOMContext` instance with the specified reference.
1119
- */
1120
- o(this, "withReference", (e) => new R(this.document, this.element, e, this.providers));
1121
- /**
1122
- * Sets a provider for the given provider mark.
1123
- *
1124
- * @param mark - The provider mark to set the provider for.
1125
- * @param value - The provider to set for the given mark.
1126
- * @returns A new `DOMContext` instance with the specified provider.
1127
- */
1128
- o(this, "setProvider", (e, t, r) => new R(this.document, this.element, this.reference, {
1129
- ...this.providers,
1130
- [e]: [t, r]
1131
- }));
1132
- /**
1133
- * Retrieves a provider for the given provider mark.
1134
- *
1135
- * @param mark - The provider mark to retrieve the provider for.
1136
- * @returns The provider for the given mark.
1137
- * @throws Throws `ProviderNotFoundError` if the provider for the given mark is not found.
1138
- */
1139
- o(this, "getProvider", (e) => {
1140
- if (this.providers[e] === void 0)
1141
- throw new Le(e);
1142
- const [t, r] = this.providers[e];
1143
- return { value: t, onUse: r };
1144
- });
1145
- o(this, "clear", (e) => {
1146
- e && (this.reference !== void 0 ? X(this.reference) : X(this.element));
1147
- });
1148
- /**
1149
- * Adds classes to the element.
1150
- * @param tokens - The class names to add.
1151
- */
1152
- o(this, "addClasses", (e) => {
1153
- this.element.classList.add(...e);
1154
- });
1155
- /**
1156
- * Removes classes from the element.
1157
- * @param tokens - The class names to remove.
1158
- */
1159
- o(this, "removeClasses", (e) => {
1160
- this.element.classList.remove(...e);
1161
- });
1162
- /**
1163
- * Gets the classes of the element.
1164
- * @returns The classes of the element.
1165
- */
1166
- o(this, "getClasses", () => Array.from(this.element.classList));
1167
- /**
1168
- * Adds an event listener to the element.
1169
- * @param event - The event to listen for.
1170
- * @param listener - The listener to call when the event occurs.
1171
- * @param options - The options for the event listener.
1172
- * @returns A function to remove the event listener.
1173
- */
1174
- o(this, "on", (e, t, r) => {
1175
- const n = (i) => t(i, this);
1176
- return this.element.addEventListener(e, n, r), (i) => {
1177
- i && this.element.removeEventListener(e, n, r);
1178
- };
1179
- });
1180
- /**
1181
- * Returns `true` if the context is a browser DOM context.
1182
- * @returns `true` if the context is a browser DOM context.
1183
- * @deprecated Use `isBrowser()` instead.
1184
- */
1185
- o(this, "isBrowserDOM", () => !0);
1186
- /**
1187
- * Returns `true` if the context is a browser context.
1188
- * @returns `true` if the context is a browser context.
1189
- */
1190
- o(this, "isBrowser", () => !0);
1191
- /**
1192
- * Returns `true` if the context is a headless DOM context.
1193
- * @returns `true` if the context is a headless DOM context.
1194
- */
1195
- o(this, "isHeadlessDOM", () => !1);
1196
- /**
1197
- * Returns `true` if the context is a headless context.
1198
- * @returns `true` if the context is a headless context.
1199
- */
1200
- o(this, "isHeadless", () => !1);
1201
- /**
1202
- * Sets the style of the element.
1203
- * @param name - The name of the style to set.
1204
- * @param value - The value of the style to set.
1205
- */
1206
- o(this, "setStyle", (e, t) => {
1207
- this.element.style[e] = t;
1208
- });
1209
- /**
1210
- * Gets the style of the element.
1211
- * @param name - The name of the style to get.
1212
- * @returns The value of the style.
1213
- */
1214
- o(this, "getStyle", (e) => this.element.style[e]);
1215
- o(this, "makeAccessors", (e) => ({
1216
- get: it(e, this.element),
1217
- set: nt(e, this.element)
1218
- }));
1219
- o(this, "getWindow", () => this.document.defaultView);
1220
- this.document = e, this.element = t, this.reference = r, this.providers = n;
1152
+ "outerHTML",
1153
+ "className",
1154
+ "classList"
1155
+ ]), tt = (t, e) => _e.has(t) ? (s) => {
1156
+ s == null || s !== !0 ? e.removeAttribute(t) : e.setAttribute(t, "");
1157
+ } : we.has(t) ? (s) => {
1158
+ s == null ? e[t] = null : e[t] = !!s;
1159
+ } : ve.has(t) ? (s) => {
1160
+ s == null ? e[t] = null : e[t] = Number(s);
1161
+ } : Te.has(t) ? (s) => {
1162
+ s == null ? e[t] = null : e[t] = s;
1163
+ } : Ae.has(t) ? (s) => {
1164
+ s == null ? e[t] = null : e[t] = String(s);
1165
+ } : (s) => {
1166
+ s == null ? e.removeAttribute(t) : e.setAttribute(t, s);
1167
+ }, st = (t, e) => _e.has(t) ? () => e.hasAttribute(t) : we.has(t) ? () => !!e[t] : ve.has(t) ? () => Number(e[t]) : Te.has(t) ? () => e[t] : Ae.has(t) ? () => String(e[t]) : () => e.getAttribute(t), U = (t) => {
1168
+ const e = t;
1169
+ e && e.onblur && (e.onblur = null), !(!t || t.ownerDocument === void 0) && t.parentElement && t.parentElement.removeChild(t);
1170
+ }, rt = (t) => Ee(t) ? t : t.parentElement, Ee = (t) => t.nodeType === 1;
1171
+ class Ce extends Error {
1172
+ constructor(e) {
1173
+ super(`Provider not found: ${e.description}`);
1174
+ }
1175
+ }
1176
+ class N {
1177
+ /**
1178
+ * Constructs a new `DOMContext` instance.
1179
+ *
1180
+ * @param document - The `Document` instance associated with this context.
1181
+ * @param element - The `Element` instance associated with this context.
1182
+ * @param reference - An optional `Node` instance that serves as a reference for this context.
1183
+ * @param providers - The `Providers` instance associated with this context.
1184
+ * @param isFirstLevel - A boolean value indicating whether this context is at the first level, meaning the outermost node in the generated DOM.
1185
+ */
1186
+ constructor(e, s, r, n) {
1187
+ this.document = e, this.element = s, this.reference = r, this.providers = n;
1221
1188
  }
1222
1189
  /**
1223
1190
  * Creates a new `DOMContext` instance for the given `Element` and optional reference `Node`.
@@ -1227,512 +1194,741 @@ class R {
1227
1194
  * @param providers - The providers to associate with the `DOMContext`.
1228
1195
  * @returns A new `DOMContext` instance.
1229
1196
  */
1230
- static of(e, t, r) {
1231
- return new R(e.ownerDocument, e, t, r);
1197
+ static of(e, s, r) {
1198
+ return new N(e.ownerDocument, e, s, r);
1232
1199
  }
1200
+ /**
1201
+ * Creates a new DOM element (eg: HTML or SVG) with the specified tag name and namespace.
1202
+ *
1203
+ * @param tagName - The tag name of the element to create.
1204
+ * @param namespace - The namespace URI to create the element in, or `undefined` to create a standard HTML element.
1205
+ * @returns The newly created element.
1206
+ */
1207
+ createElement = (e, s) => s !== void 0 ? this.document.createElementNS(s, e) : this.document.createElement(e);
1208
+ /**
1209
+ * Creates a new child element and appends it to the current element, returning a new context.
1210
+ *
1211
+ * This method creates a new DOM element with the specified tag name and namespace,
1212
+ * appends it to the current element, and returns a new DOMContext focused on the
1213
+ * newly created child element. This is the primary method for building DOM trees.
1214
+ *
1215
+ * @example
1216
+ * ```typescript
1217
+ * // Create HTML elements
1218
+ * const divCtx = ctx.makeChildElement('div', undefined)
1219
+ * const spanCtx = divCtx.makeChildElement('span', undefined)
1220
+ *
1221
+ * // Create SVG elements
1222
+ * const svgCtx = ctx.makeChildElement('svg', 'http://www.w3.org/2000/svg')
1223
+ * const circleCtx = svgCtx.makeChildElement('circle', 'http://www.w3.org/2000/svg')
1224
+ * ```
1225
+ *
1226
+ * @param tagName - The tag name of the element to create (e.g., 'div', 'span', 'svg')
1227
+ * @param namespace - The namespace URI for the element, or undefined for HTML elements
1228
+ * @returns A new DOMContext focused on the newly created child element
1229
+ */
1230
+ makeChildElement = (e, s) => {
1231
+ const r = this.createElement(e, s);
1232
+ return this.appendOrInsert(r), this.withElement(r);
1233
+ };
1234
+ /**
1235
+ * Creates a new text node with the specified text content.
1236
+ * @param text - The text content for the new text node.
1237
+ * @returns A new `Text` node with the specified text content.
1238
+ */
1239
+ createText = (e) => this.document.createTextNode(e);
1240
+ /**
1241
+ * Creates a new text node with the specified text content and appends it to the current element.
1242
+ * @param text - The text content for the new text node.
1243
+ * @returns A new `DOMContext` with a reference to the new text node.
1244
+ */
1245
+ makeChildText = (e) => {
1246
+ const s = this.createText(e);
1247
+ return this.appendOrInsert(s), this.withReference(s);
1248
+ };
1249
+ /**
1250
+ * Sets the text content of the current element.
1251
+ * @param text - The text content to set.
1252
+ */
1253
+ setText = (e) => {
1254
+ this.reference.nodeValue = e;
1255
+ };
1256
+ /**
1257
+ * Gets the text content of the current element or text node.
1258
+ * @returns The text content of the current element or text node.
1259
+ */
1260
+ getText = () => this.reference?.nodeValue ?? this.element.textContent ?? "";
1261
+ /**
1262
+ * Creates a new `DOMContext` with a reference to a newly created text node.
1263
+ * The text node is appended or inserted to the current `DOMContext`.
1264
+ * The new `DOMContext` with the reference is returned.
1265
+ */
1266
+ makeRef = () => {
1267
+ const e = this.createText("");
1268
+ return this.appendOrInsert(e), this.withReference(e);
1269
+ };
1270
+ /**
1271
+ * Appends or inserts a child node to the element, depending on whether a reference node is provided.
1272
+ *
1273
+ * @param child - The child node to append or insert.
1274
+ */
1275
+ appendOrInsert = (e) => {
1276
+ this.reference === void 0 ? this.element.appendChild(e) : this.element.insertBefore(e, this.reference);
1277
+ };
1278
+ /**
1279
+ * Creates a new `DOMContext` instance with the provided `element`.
1280
+ * @param element - The DOM element to use in the new `DOMContext` instance.
1281
+ * @returns A new `DOMContext` instance with the provided `element`.
1282
+ */
1283
+ withElement = (e) => new N(this.document, e, void 0, this.providers);
1284
+ /**
1285
+ * Creates a portal to render content in a different part of the DOM tree.
1286
+ *
1287
+ * Portals allow you to render child components into a DOM node that exists outside
1288
+ * the parent component's DOM hierarchy. This is useful for modals, tooltips,
1289
+ * dropdowns, and other UI elements that need to break out of their container's
1290
+ * styling or z-index context.
1291
+ *
1292
+ * @example
1293
+ * ```typescript
1294
+ * // Portal to a modal container
1295
+ * const modalCtx = ctx.makePortal('#modal-root')
1296
+ * const modal = modalCtx.makeChildElement('div', undefined)
1297
+ *
1298
+ * // Add modal content
1299
+ * modal.makeChildText('This renders in #modal-root')
1300
+ * ```
1301
+ *
1302
+ * @example
1303
+ * ```typescript
1304
+ * // Portal to an existing element reference
1305
+ * const tooltipContainer = document.getElementById('tooltip-container')!
1306
+ * const tooltipCtx = ctx.makePortal(tooltipContainer)
1307
+ *
1308
+ * // Render tooltip content
1309
+ * const tooltip = tooltipCtx.makeChildElement('div', undefined)
1310
+ * tooltip.addClasses(['tooltip', 'tooltip-top'])
1311
+ * ```
1312
+ *
1313
+ * @example
1314
+ * ```typescript
1315
+ * // Portal for dropdown menu
1316
+ * const dropdownCtx = ctx.makePortal('body') // Render at body level
1317
+ * const dropdown = dropdownCtx.makeChildElement('div', undefined)
1318
+ * dropdown.addClasses(['dropdown-menu'])
1319
+ * dropdown.setStyle('position', 'absolute')
1320
+ * dropdown.setStyle('top', '100px')
1321
+ * dropdown.setStyle('left', '50px')
1322
+ * ```
1323
+ *
1324
+ * @param selector - CSS selector string or HTMLElement reference for the portal target
1325
+ * @returns A new DOMContext focused on the portal target element
1326
+ * @throws {Error} When the selector doesn't match any element in the document
1327
+ */
1328
+ makePortal = (e) => {
1329
+ const s = typeof e == "string" ? this.document.querySelector(e) : e;
1330
+ if (s == null)
1331
+ throw new Error(`Cannot find element by selector for portal: ${e}`);
1332
+ return this.withElement(s);
1333
+ };
1334
+ /**
1335
+ * Creates a new `DOMContext` instance with the specified reference.
1336
+ *
1337
+ * @param reference - The optional `Text` node to use as the reference for the new `DOMContext`.
1338
+ * @returns A new `DOMContext` instance with the specified reference.
1339
+ */
1340
+ withReference = (e) => new N(this.document, this.element, e, this.providers);
1341
+ /**
1342
+ * Sets a provider for the given provider mark.
1343
+ *
1344
+ * @param mark - The provider mark to set the provider for.
1345
+ * @param value - The provider to set for the given mark.
1346
+ * @returns A new `DOMContext` instance with the specified provider.
1347
+ */
1348
+ setProvider = (e, s, r) => new N(this.document, this.element, this.reference, {
1349
+ ...this.providers,
1350
+ [e]: [s, r]
1351
+ });
1352
+ /**
1353
+ * Retrieves a provider for the given provider mark.
1354
+ *
1355
+ * @param mark - The provider mark to retrieve the provider for.
1356
+ * @returns The provider for the given mark.
1357
+ * @throws Throws `ProviderNotFoundError` if the provider for the given mark is not found.
1358
+ */
1359
+ getProvider = (e) => {
1360
+ if (this.providers[e] === void 0)
1361
+ throw new Ce(e);
1362
+ const [s, r] = this.providers[e];
1363
+ return { value: s, onUse: r };
1364
+ };
1365
+ clear = (e) => {
1366
+ e && (this.reference !== void 0 ? U(this.reference) : U(this.element));
1367
+ };
1368
+ /**
1369
+ * Adds classes to the element.
1370
+ * @param tokens - The class names to add.
1371
+ */
1372
+ addClasses = (e) => {
1373
+ this.element.classList.add(...e);
1374
+ };
1375
+ /**
1376
+ * Removes classes from the element.
1377
+ * @param tokens - The class names to remove.
1378
+ */
1379
+ removeClasses = (e) => {
1380
+ this.element.classList.remove(...e);
1381
+ };
1382
+ /**
1383
+ * Gets the classes of the element.
1384
+ * @returns The classes of the element.
1385
+ */
1386
+ getClasses = () => Array.from(this.element.classList);
1387
+ /**
1388
+ * Adds an event listener to the element.
1389
+ * @param event - The event to listen for.
1390
+ * @param listener - The listener to call when the event occurs.
1391
+ * @param options - The options for the event listener.
1392
+ * @returns A function to remove the event listener.
1393
+ */
1394
+ on = (e, s, r) => {
1395
+ const n = (i) => s(i, this);
1396
+ return this.element.addEventListener(e, n, r), (i) => {
1397
+ i && this.element.removeEventListener(e, n, r);
1398
+ };
1399
+ };
1400
+ /**
1401
+ * Returns `true` if the context is a browser DOM context.
1402
+ * @returns `true` if the context is a browser DOM context.
1403
+ * @deprecated Use `isBrowser()` instead.
1404
+ */
1405
+ isBrowserDOM = () => !0;
1406
+ /**
1407
+ * Returns `true` if the context is a browser context.
1408
+ * @returns `true` if the context is a browser context.
1409
+ */
1410
+ isBrowser = () => !0;
1411
+ /**
1412
+ * Returns `true` if the context is a headless DOM context.
1413
+ * @returns `true` if the context is a headless DOM context.
1414
+ */
1415
+ isHeadlessDOM = () => !1;
1416
+ /**
1417
+ * Returns `true` if the context is a headless context.
1418
+ * @returns `true` if the context is a headless context.
1419
+ */
1420
+ isHeadless = () => !1;
1421
+ /**
1422
+ * Sets the style of the element.
1423
+ * @param name - The name of the style to set.
1424
+ * @param value - The value of the style to set.
1425
+ */
1426
+ setStyle = (e, s) => {
1427
+ this.element.style[e] = s;
1428
+ };
1429
+ /**
1430
+ * Gets the style of the element.
1431
+ * @param name - The name of the style to get.
1432
+ * @returns The value of the style.
1433
+ */
1434
+ getStyle = (e) => this.element.style[e];
1435
+ makeAccessors = (e) => ({
1436
+ get: st(e, this.element),
1437
+ set: tt(e, this.element)
1438
+ });
1439
+ getWindow = () => this.document.defaultView;
1233
1440
  }
1234
- const lt = (s) => Symbol(s), fe = (s, e) => {
1235
- const t = s(e);
1236
- return (r = !0) => t(r);
1237
- }, rs = (s, e, { doc: t, clear: r, disposeWithParent: n = !0, providers: i = {} } = {}) => {
1238
- const l = typeof e == "string" ? (t ?? document).querySelector(e) : e;
1239
- if (l === null)
1240
- throw new ct(
1441
+ const nt = (t) => Symbol(t), ae = (t, e) => {
1442
+ const s = new q(), r = L(s, () => t(e));
1443
+ return (n = !0) => {
1444
+ s.dispose(), r(n);
1445
+ };
1446
+ }, ss = (t, e, { doc: s, clear: r, disposeWithParent: n = !0, providers: i = {} } = {}) => {
1447
+ const o = typeof e == "string" ? (s ?? document).querySelector(e) : e;
1448
+ if (o === null)
1449
+ throw new it(
1241
1450
  `Cannot find element by selector for render: ${e}`
1242
1451
  );
1243
- r !== !1 && (t ?? l.ownerDocument) != null && l.nodeType === 1 && (l.innerHTML = "");
1244
- const c = ot(l), a = Pe(l) ? void 0 : l, u = R.of(c, a, i), h = fe(s, u);
1245
- let d;
1246
- return n && (d = new MutationObserver((p) => {
1247
- var m;
1248
- (m = p[0]) == null || m.removedNodes.forEach((g) => {
1249
- g === l && (d == null || d.disconnect(), h(l.nodeType !== 1));
1452
+ r !== !1 && (s ?? o.ownerDocument) != null && o.nodeType === 1 && (o.innerHTML = "");
1453
+ const l = rt(o), c = Ee(o) ? void 0 : o, a = N.of(l, c, i), u = ae(t, a);
1454
+ let h;
1455
+ return n && (h = new MutationObserver((p) => {
1456
+ p[0]?.removedNodes.forEach((f) => {
1457
+ f === o && (h?.disconnect(), u(o.nodeType !== 1));
1250
1458
  });
1251
- }), d.observe(l.parentElement, {
1459
+ }), h.observe(o.parentElement, {
1252
1460
  childList: !0,
1253
1461
  subtree: !1,
1254
1462
  attributes: !1
1255
1463
  })), () => {
1256
- d == null || d.disconnect(), h(!0);
1464
+ h?.disconnect(), u(!0);
1257
1465
  };
1258
- }, ns = (s, {
1466
+ }, rs = (t, {
1259
1467
  startUrl: e = "https://example.com",
1260
- selector: t,
1468
+ selector: s,
1261
1469
  providers: r = {}
1262
1470
  } = {
1263
1471
  selector: "body"
1264
1472
  }) => {
1265
- const n = b.toSignal(e).deriveProp(), i = new He(t, void 0), l = new V(i, void 0, { currentURL: n }, r);
1473
+ const n = y.toSignal(e).deriveProp(), i = new Oe(s, void 0), o = new R(i, void 0, { currentURL: n }, r);
1266
1474
  return {
1267
- clear: fe(s(), l),
1475
+ clear: ae(t(), o),
1268
1476
  root: i,
1269
1477
  currentURL: n
1270
1478
  };
1271
1479
  };
1272
- class ct extends Error {
1480
+ class it extends Error {
1273
1481
  constructor(e) {
1274
1482
  super(e);
1275
1483
  }
1276
1484
  }
1277
- const De = "data-tts-node", Y = "data-tts-class", Q = "data-tts-style", Z = "data-tts-html", z = "data-tts-text", K = "data-tts-attrs";
1278
- class is {
1485
+ const De = "data-tts-node", J = "data-tts-class", G = "data-tts-style", X = "data-tts-html", Y = "data-tts-text", Q = "data-tts-attrs";
1486
+ class ns {
1487
+ /**
1488
+ * Selects elements from the headless environment.
1489
+ * @param selector - The selector to select elements from. The supported selectors are CSS selectors whose complexity depends on the adapter implementation.
1490
+ * @returns An array of elements.
1491
+ */
1492
+ select;
1493
+ /**
1494
+ * Gets the value of an attribute from an element.
1495
+ * @param el - The element to get the attribute from.
1496
+ * @param attr - The attribute to get the value from.
1497
+ * @returns The value of the attribute or null if the attribute is not set.
1498
+ */
1499
+ getAttribute;
1500
+ /**
1501
+ * Sets the value of an attribute on an element.
1502
+ * @param el - The element to set the attribute on.
1503
+ * @param attr - The attribute to set the value of.
1504
+ * @param value - The value to set the attribute to.
1505
+ */
1506
+ setAttribute;
1507
+ /**
1508
+ * Gets the class of an element.
1509
+ * @param el - The element to get the class from.
1510
+ * @returns The class of the element or an empty string if the class is not set.
1511
+ */
1512
+ getClass;
1513
+ /**
1514
+ * Sets the class of an element.
1515
+ * @param el - The element to set the class on.
1516
+ * @param cls - The class to set.
1517
+ */
1518
+ setClass;
1519
+ /**
1520
+ * Gets the styles of an element.
1521
+ * @param el - The element to get the styles from.
1522
+ * @returns The styles of the element.
1523
+ */
1524
+ getStyles;
1525
+ /**
1526
+ * Sets the styles of an element.
1527
+ * @param el - The element to set the styles on.
1528
+ */
1529
+ setStyles;
1530
+ /**
1531
+ * Appends HTML to an element.
1532
+ * @param el - The element to append the HTML to.
1533
+ * @param html - The HTML to append.
1534
+ */
1535
+ appendHTML;
1536
+ /**
1537
+ * Gets the inner HTML of an element.
1538
+ * @param el - The element to get the inner HTML from.
1539
+ * @returns The inner HTML of the element or an empty string if the inner HTML is not set.
1540
+ */
1541
+ getInnerHTML;
1542
+ /**
1543
+ * Sets the inner HTML of an element.
1544
+ * @param el - The element to set the inner HTML on.
1545
+ * @param html - The inner HTML to set.
1546
+ */
1547
+ setInnerHTML;
1548
+ /**
1549
+ * Gets the inner text of an element.
1550
+ * @param el - The element to get the inner text from.
1551
+ * @returns The inner text of the element or an empty string if the inner text is not set.
1552
+ */
1553
+ getInnerText;
1554
+ /**
1555
+ * Sets the inner text of an element.
1556
+ * @param el - The element to set the inner text on.
1557
+ * @param text - The inner text to set.
1558
+ */
1559
+ setInnerText;
1279
1560
  constructor({
1280
1561
  select: e,
1281
- getAttribute: t,
1562
+ getAttribute: s,
1282
1563
  setAttribute: r,
1283
1564
  getClass: n,
1284
1565
  setClass: i,
1285
- getStyles: l,
1286
- setStyles: c,
1287
- appendHTML: a,
1288
- getInnerHTML: u,
1289
- setInnerHTML: h,
1290
- getInnerText: d,
1566
+ getStyles: o,
1567
+ setStyles: l,
1568
+ appendHTML: c,
1569
+ getInnerHTML: a,
1570
+ setInnerHTML: u,
1571
+ getInnerText: h,
1291
1572
  setInnerText: p
1292
1573
  }) {
1293
- /**
1294
- * Selects elements from the headless environment.
1295
- * @param selector - The selector to select elements from. The supported selectors are CSS selectors whose complexity depends on the adapter implementation.
1296
- * @returns An array of elements.
1297
- */
1298
- o(this, "select");
1299
- /**
1300
- * Gets the value of an attribute from an element.
1301
- * @param el - The element to get the attribute from.
1302
- * @param attr - The attribute to get the value from.
1303
- * @returns The value of the attribute or null if the attribute is not set.
1304
- */
1305
- o(this, "getAttribute");
1306
- /**
1307
- * Sets the value of an attribute on an element.
1308
- * @param el - The element to set the attribute on.
1309
- * @param attr - The attribute to set the value of.
1310
- * @param value - The value to set the attribute to.
1311
- */
1312
- o(this, "setAttribute");
1313
- /**
1314
- * Gets the class of an element.
1315
- * @param el - The element to get the class from.
1316
- * @returns The class of the element or an empty string if the class is not set.
1317
- */
1318
- o(this, "getClass");
1319
- /**
1320
- * Sets the class of an element.
1321
- * @param el - The element to set the class on.
1322
- * @param cls - The class to set.
1323
- */
1324
- o(this, "setClass");
1325
- /**
1326
- * Gets the styles of an element.
1327
- * @param el - The element to get the styles from.
1328
- * @returns The styles of the element.
1329
- */
1330
- o(this, "getStyles");
1331
- /**
1332
- * Sets the styles of an element.
1333
- * @param el - The element to set the styles on.
1334
- */
1335
- o(this, "setStyles");
1336
- /**
1337
- * Appends HTML to an element.
1338
- * @param el - The element to append the HTML to.
1339
- * @param html - The HTML to append.
1340
- */
1341
- o(this, "appendHTML");
1342
- /**
1343
- * Gets the inner HTML of an element.
1344
- * @param el - The element to get the inner HTML from.
1345
- * @returns The inner HTML of the element or an empty string if the inner HTML is not set.
1346
- */
1347
- o(this, "getInnerHTML");
1348
- /**
1349
- * Sets the inner HTML of an element.
1350
- * @param el - The element to set the inner HTML on.
1351
- * @param html - The inner HTML to set.
1352
- */
1353
- o(this, "setInnerHTML");
1354
- /**
1355
- * Gets the inner text of an element.
1356
- * @param el - The element to get the inner text from.
1357
- * @returns The inner text of the element or an empty string if the inner text is not set.
1358
- */
1359
- o(this, "getInnerText");
1360
- /**
1361
- * Sets the inner text of an element.
1362
- * @param el - The element to set the inner text on.
1363
- * @param text - The inner text to set.
1364
- */
1365
- o(this, "setInnerText");
1366
- /**
1367
- * Sets the content of the root element from a HeadlessPortal. Generally this will be the same instance that is
1368
- * returned by `runHeadless`.
1369
- *
1370
- * @param root - The HeadlessPortal containing the content to set.
1371
- * @param setPlaceholders - Whether to set placeholders for the content. This allows you to restore the original content
1372
- * when you render on the server and then hydrate on the client.
1373
- */
1374
- o(this, "setFromRoot", (e, t) => {
1375
- e.getPortals().forEach((n) => {
1376
- const i = typeof n.selector == "string" ? this.select(n.selector) : [n.selector];
1377
- for (const l of i) {
1378
- if (l == null)
1379
- throw new Error(
1380
- `Cannot find element by selector for render: ${n.selector}`
1381
- );
1382
- if (n.hasChildren() && this.appendHTML(l, n.contentToHTML(t)), n.hasInnerHTML()) {
1383
- if (t) {
1384
- const c = this.getInnerHTML(l);
1385
- c != null && this.setAttribute(l, Z, c);
1386
- }
1387
- this.setInnerHTML(l, n.getInnerHTML());
1574
+ this.select = e, this.getAttribute = s, this.setAttribute = r, this.getClass = n, this.setClass = i, this.getStyles = o, this.setStyles = l, this.appendHTML = c, this.getInnerHTML = a, this.setInnerHTML = u, this.getInnerText = h, this.setInnerText = p;
1575
+ }
1576
+ /**
1577
+ * Sets the content of the root element from a HeadlessPortal. Generally this will be the same instance that is
1578
+ * returned by `runHeadless`.
1579
+ *
1580
+ * @param root - The HeadlessPortal containing the content to set.
1581
+ * @param setPlaceholders - Whether to set placeholders for the content. This allows you to restore the original content
1582
+ * when you render on the server and then hydrate on the client.
1583
+ */
1584
+ setFromRoot = (e, s) => {
1585
+ e.getPortals().forEach((n) => {
1586
+ const i = typeof n.selector == "string" ? this.select(n.selector) : [n.selector];
1587
+ for (const o of i) {
1588
+ if (o == null)
1589
+ throw new Error(
1590
+ `Cannot find element by selector for render: ${n.selector}`
1591
+ );
1592
+ if (n.hasChildren() && this.appendHTML(o, n.contentToHTML(s)), n.hasInnerHTML()) {
1593
+ if (s) {
1594
+ const l = this.getInnerHTML(o);
1595
+ l != null && this.setAttribute(o, X, l);
1388
1596
  }
1389
- if (n.hasInnerText()) {
1390
- if (t) {
1391
- const c = this.getInnerText(l);
1392
- c != null && this.setAttribute(l, z, c);
1393
- }
1394
- this.setInnerText(l, n.getInnerText());
1597
+ this.setInnerHTML(o, n.getInnerHTML());
1598
+ }
1599
+ if (n.hasInnerText()) {
1600
+ if (s) {
1601
+ const l = this.getInnerText(o);
1602
+ l != null && this.setAttribute(o, Y, l);
1395
1603
  }
1396
- if (n.hasClasses()) {
1397
- if (t) {
1398
- const c = this.getClass(l);
1399
- c != null && this.setAttribute(l, Y, c);
1400
- }
1401
- this.setClass(l, n.getClasses().join(" "));
1604
+ this.setInnerText(o, n.getInnerText());
1605
+ }
1606
+ if (n.hasClasses()) {
1607
+ if (s) {
1608
+ const l = this.getClass(o);
1609
+ l != null && this.setAttribute(o, J, l);
1402
1610
  }
1403
- if (n.hasStyles()) {
1404
- if (t) {
1405
- const c = this.getStyles(l);
1406
- Object.keys(c).length > 0 && this.setAttribute(
1407
- l,
1408
- Q,
1409
- JSON.stringify(c)
1410
- );
1411
- }
1412
- this.setStyles(l, n.getStyles());
1611
+ this.setClass(o, n.getClasses().join(" "));
1612
+ }
1613
+ if (n.hasStyles()) {
1614
+ if (s) {
1615
+ const l = this.getStyles(o);
1616
+ Object.keys(l).length > 0 && this.setAttribute(
1617
+ o,
1618
+ G,
1619
+ JSON.stringify(l)
1620
+ );
1413
1621
  }
1414
- if (n.hasAttributes()) {
1415
- const c = n.getAttributes();
1416
- if (t) {
1417
- const a = [];
1418
- c.forEach(([u]) => {
1419
- const h = this.getAttribute(l, u);
1420
- h != null && a.push([u, h]);
1421
- }), a.length > 0 && this.setAttribute(
1422
- l,
1423
- K,
1424
- JSON.stringify(Object.fromEntries(a))
1425
- );
1426
- }
1427
- c.forEach(([a, u]) => {
1428
- this.setAttribute(l, a, u);
1429
- });
1622
+ this.setStyles(o, n.getStyles());
1623
+ }
1624
+ if (n.hasAttributes()) {
1625
+ const l = n.getAttributes();
1626
+ if (s) {
1627
+ const c = [];
1628
+ l.forEach(([a]) => {
1629
+ const u = this.getAttribute(o, a);
1630
+ u != null && c.push([a, u]);
1631
+ }), c.length > 0 && this.setAttribute(
1632
+ o,
1633
+ Q,
1634
+ JSON.stringify(Object.fromEntries(c))
1635
+ );
1430
1636
  }
1637
+ l.forEach(([c, a]) => {
1638
+ this.setAttribute(o, c, a);
1639
+ });
1431
1640
  }
1432
- });
1641
+ }
1433
1642
  });
1434
- this.select = e, this.getAttribute = t, this.setAttribute = r, this.getClass = n, this.setClass = i, this.getStyles = l, this.setStyles = c, this.appendHTML = a, this.getInnerHTML = u, this.setInnerHTML = h, this.getInnerText = d, this.setInnerText = p;
1435
- }
1643
+ };
1436
1644
  }
1437
- const at = () => {
1438
- document.querySelectorAll(`[${De}]`).forEach(X);
1439
- }, ut = (s) => {
1440
- const e = s.getAttribute(Y);
1441
- s.removeAttribute(Y), e != null && s.setAttribute("class", e);
1442
- }, ht = () => {
1443
- document.querySelectorAll(`[${Y}]`).forEach((e) => ut(e));
1444
- }, ft = (s) => {
1445
- const e = s.getAttribute(Z);
1446
- s.removeAttribute(Z), e != null && (s.innerHTML = e);
1645
+ const ot = () => {
1646
+ document.querySelectorAll(`[${De}]`).forEach(U);
1647
+ }, lt = (t) => {
1648
+ const e = t.getAttribute(J);
1649
+ t.removeAttribute(J), e != null && t.setAttribute("class", e);
1650
+ }, ct = () => {
1651
+ document.querySelectorAll(`[${J}]`).forEach((e) => lt(e));
1652
+ }, at = (t) => {
1653
+ const e = t.getAttribute(X);
1654
+ t.removeAttribute(X), e != null && (t.innerHTML = e);
1655
+ }, ut = () => {
1656
+ document.querySelectorAll(`[${X}]`).forEach((e) => at(e));
1657
+ }, ht = (t) => {
1658
+ const e = t.getAttribute(Y);
1659
+ t.removeAttribute(Y), e != null && (t.innerText = e);
1447
1660
  }, dt = () => {
1448
- document.querySelectorAll(`[${Z}]`).forEach((e) => ft(e));
1449
- }, pt = (s) => {
1450
- const e = s.getAttribute(z);
1451
- s.removeAttribute(z), e != null && (s.innerText = e);
1452
- }, mt = () => {
1453
- document.querySelectorAll(`[${z}]`).forEach((e) => pt(e));
1454
- }, Me = (s) => JSON.parse(s.replace(/&quot;/g, '"')), gt = (s) => {
1455
- const e = s.getAttribute(Q);
1456
- if (s.removeAttribute(Q), e != null) {
1457
- const t = Me(e);
1458
- Object.entries(t).forEach(([r, n]) => {
1459
- s.style.setProperty(r, n);
1661
+ document.querySelectorAll(`[${Y}]`).forEach((e) => ht(e));
1662
+ }, Pe = (t) => JSON.parse(t.replace(/&quot;/g, '"')), ft = (t) => {
1663
+ const e = t.getAttribute(G);
1664
+ if (t.removeAttribute(G), e != null) {
1665
+ const s = Pe(e);
1666
+ Object.entries(s).forEach(([r, n]) => {
1667
+ t.style.setProperty(r, n);
1460
1668
  });
1461
1669
  }
1462
- }, yt = () => {
1463
- document.querySelectorAll(`[${Q}]`).forEach((e) => gt(e));
1464
- }, bt = (s) => {
1465
- const e = s.getAttribute(K);
1466
- if (s.removeAttribute(K), e != null) {
1467
- const t = Me(e);
1468
- Object.entries(t).forEach(([r, n]) => {
1469
- n == null ? s.removeAttribute(r) : s.setAttribute(r, n);
1670
+ }, pt = () => {
1671
+ document.querySelectorAll(`[${G}]`).forEach((e) => ft(e));
1672
+ }, gt = (t) => {
1673
+ const e = t.getAttribute(Q);
1674
+ if (t.removeAttribute(Q), e != null) {
1675
+ const s = Pe(e);
1676
+ Object.entries(s).forEach(([r, n]) => {
1677
+ n == null ? t.removeAttribute(r) : t.setAttribute(r, n);
1470
1678
  });
1471
1679
  }
1472
- }, Tt = () => {
1473
- document.querySelectorAll(`[${K}]`).forEach((e) => bt(e));
1474
- }, os = () => {
1475
- at(), ht(), mt(), dt(), yt(), Tt();
1476
- }, C = Symbol("class"), D = Symbol("style"), $ = Symbol("handler"), Oe = () => Math.random().toString(36).substring(2, 15), St = (s) => s.replace(/<[^>]*>?/g, "");
1477
- class Ie {
1680
+ }, mt = () => {
1681
+ document.querySelectorAll(`[${Q}]`).forEach((e) => gt(e));
1682
+ }, is = () => {
1683
+ ot(), ct(), dt(), ut(), pt(), mt();
1684
+ }, I = Symbol("class"), H = Symbol("style"), B = Symbol("handler"), xe = () => Math.random().toString(36).substring(2, 15), yt = (t) => t.replace(/<[^>]*>?/g, "");
1685
+ class Le {
1478
1686
  constructor(e) {
1479
- o(this, "id", Oe());
1480
- o(this, "properties", {});
1481
- o(this, "children", []);
1482
- o(this, "isElement", () => !0);
1483
- o(this, "isText", () => !1);
1484
- o(this, "getText", () => this.properties.innerText != null ? this.properties.innerText : this.properties.innerHTML != null ? St(this.properties.innerHTML) : this.children.map((e) => e.getText()).join(""));
1485
- o(this, "removeChild", (e) => {
1486
- const t = this.children.indexOf(e);
1487
- t !== -1 && this.children.splice(t, 1);
1488
- });
1489
- o(this, "remove", () => {
1490
- if (this.parent != null)
1491
- this.parent.removeChild(this);
1492
- else
1493
- throw new Error("Parent is undefined");
1494
- });
1495
- o(this, "getPortals", () => {
1496
- const e = this.elements().flatMap((t) => t.isPortal() ? [t, ...t.getPortals()] : t.getPortals());
1497
- return this.isPortal() && e.unshift(this), e;
1498
- });
1499
- o(this, "elements", () => this.children.filter((e) => e.isElement()));
1500
- o(this, "hasInnerHTML", () => this.properties.innerHTML != null);
1501
- o(this, "getInnerHTML", () => this.properties.innerHTML ?? "");
1502
- o(this, "getInnerText", () => this.properties.innerText ?? "");
1503
- o(this, "hasInnerText", () => this.properties.innerText != null);
1504
- o(this, "hasChildren", () => this.children.length > 0);
1505
- o(this, "hasClasses", () => this.properties[C] != null);
1506
- o(this, "hasStyles", () => this.properties[D] != null);
1507
- o(this, "hasAttributes", () => Object.keys(this.properties).length > 0);
1508
- o(this, "hasHandlers", () => this.properties[$] != null);
1509
- o(this, "hasRenderableProperties", () => this.hasClasses() || this.hasAttributes() || this.hasStyles());
1510
- o(this, "getById", (e) => {
1511
- if (this.properties.id === e)
1512
- return this;
1513
- for (const t of this.elements()) {
1514
- const r = t.getById(e);
1515
- if (r != null)
1516
- return r;
1517
- }
1518
- });
1519
- o(this, "trigger", (e, t) => {
1520
- ((this.properties[$] ?? {})[e] ?? []).forEach((n) => n(t));
1521
- });
1522
- o(this, "click", () => {
1523
- this.trigger("click", {});
1524
- });
1525
- o(this, "on", (e, t, r, n) => {
1526
- var a;
1527
- const i = (a = this.properties)[$] ?? (a[$] = {}), l = n != null && n.once ? (u) => {
1528
- c(), t(u, r);
1529
- } : (u) => t(u, r);
1530
- i[e] = [...i[e] ?? [], l];
1531
- const c = () => {
1532
- const u = i[e] ?? [], h = u.indexOf(l);
1533
- h !== -1 && (u.splice(h, 1), u.length === 0 ? (delete i[e], Object.keys(i).length === 0 && delete this.properties[$]) : i[e] = u, (n == null ? void 0 : n.signal) != null && n.signal.removeEventListener("abort", c));
1534
- };
1535
- return (n == null ? void 0 : n.signal) != null && n.signal.addEventListener("abort", c), c;
1536
- });
1537
- o(this, "addClasses", (e) => {
1538
- var r;
1539
- if (e.length === 0)
1540
- return;
1541
- const t = (r = this.properties)[C] ?? (r[C] = []);
1542
- e.forEach((n) => {
1543
- t.includes(n) || t.push(n);
1544
- });
1545
- });
1546
- o(this, "removeClasses", (e) => {
1547
- var r;
1548
- if (e.length === 0)
1549
- return;
1550
- const t = (r = this.properties)[C] ?? (r[C] = []);
1551
- e.forEach((n) => {
1552
- const i = t.indexOf(n);
1553
- i !== -1 && t.splice(i, 1);
1554
- }), t.length === 0 && delete this.properties[C];
1555
- });
1556
- o(this, "getClasses", () => this.properties[C] ?? []);
1557
- o(this, "getAttributes", () => Object.entries(this.properties).filter(
1558
- ([e]) => !["innerText", "innerHTML"].includes(e)
1559
- ));
1560
- o(this, "getVisibleAttributes", () => Reflect.ownKeys(this.properties).flatMap(
1561
- (e) => e === C ? [["class", this.getClasses()]] : e === D ? [["style", this.getStyles()]] : typeof e == "string" ? [[e, String(this.properties[e])]] : []
1562
- ));
1563
- o(this, "setStyle", (e, t) => {
1564
- var n;
1565
- const r = (n = this.properties)[D] ?? (n[D] = {});
1566
- r[e] = t, t === "" && (delete r[e], Object.keys(r).length === 0 && delete this.properties[D]);
1567
- });
1568
- o(this, "getStyle", (e) => {
1569
- var t;
1570
- return ((t = this.properties[D]) == null ? void 0 : t[e]) ?? "";
1571
- });
1572
- o(this, "getStyles", () => this.properties[D] ?? {});
1573
- o(this, "makeAccessors", (e) => {
1574
- const t = this.properties;
1575
- return {
1576
- get: () => t[e],
1577
- set: (r) => t[e] = r
1578
- };
1579
- });
1580
1687
  this.parent = e;
1581
1688
  }
1582
- }
1583
- const vt = (s) => s.replace(/"/g, "&quot;"), At = (s) => s.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
1584
- class _t extends Ie {
1585
- constructor(t, r, n) {
1586
- super(n);
1587
- o(this, "isPortal", () => !1);
1588
- o(this, "toHTML", (t = !1) => {
1589
- const r = this.children.map((a) => a.toHTML()).join(""), n = this.namespace ? ` xmlns="${this.namespace}"` : "";
1590
- let i = null;
1591
- const l = this.getVisibleAttributes().map(([a, u]) => a === "class" ? ` class="${u.join(" ")}"` : a === "style" ? typeof u == "string" ? ` style="${u}"` : ` style="${Object.entries(u).map(([h, d]) => `${h}: ${d};`).join(" ")}"` : Ct.has(a) ? ` ${a}` : a === "innerHTML" ? (i = u, "") : a === "innerText" ? (i = At(u), "") : ` ${a}="${vt(u)}"`).join(""), c = t ? ` ${De}` : "";
1592
- return wt.has(this.tagName) && r === "" ? `<${this.tagName}${n}${l}${c} />` : `<${this.tagName}${n}${l}${c}>${i ?? r}</${this.tagName}>`;
1689
+ id = xe();
1690
+ properties = {};
1691
+ children = [];
1692
+ isElement = () => !0;
1693
+ isText = () => !1;
1694
+ getText = () => this.properties.innerText != null ? this.properties.innerText : this.properties.innerHTML != null ? yt(this.properties.innerHTML) : this.children.map((e) => e.getText()).join("");
1695
+ removeChild = (e) => {
1696
+ const s = this.children.indexOf(e);
1697
+ s !== -1 && this.children.splice(s, 1);
1698
+ };
1699
+ remove = () => {
1700
+ if (this.parent != null)
1701
+ this.parent.removeChild(this);
1702
+ else
1703
+ throw new Error("Parent is undefined");
1704
+ };
1705
+ getPortals = () => {
1706
+ const e = this.elements().flatMap((s) => s.isPortal() ? [s, ...s.getPortals()] : s.getPortals());
1707
+ return this.isPortal() && e.unshift(this), e;
1708
+ };
1709
+ elements = () => this.children.filter((e) => e.isElement());
1710
+ hasInnerHTML = () => this.properties.innerHTML != null;
1711
+ getInnerHTML = () => this.properties.innerHTML ?? "";
1712
+ getInnerText = () => this.properties.innerText ?? "";
1713
+ hasInnerText = () => this.properties.innerText != null;
1714
+ hasChildren = () => this.children.length > 0;
1715
+ hasClasses = () => this.properties[I] != null;
1716
+ hasStyles = () => this.properties[H] != null;
1717
+ hasAttributes = () => Object.keys(this.properties).length > 0;
1718
+ hasHandlers = () => this.properties[B] != null;
1719
+ hasRenderableProperties = () => this.hasClasses() || this.hasAttributes() || this.hasStyles();
1720
+ getById = (e) => {
1721
+ if (this.properties.id === e)
1722
+ return this;
1723
+ for (const s of this.elements()) {
1724
+ const r = s.getById(e);
1725
+ if (r != null)
1726
+ return r;
1727
+ }
1728
+ };
1729
+ trigger = (e, s) => {
1730
+ ((this.properties[B] ?? {})[e] ?? []).forEach((n) => n(s));
1731
+ };
1732
+ click = () => {
1733
+ this.trigger("click", {});
1734
+ };
1735
+ on = (e, s, r, n) => {
1736
+ const i = this.properties[B] ??= {}, o = n?.once ? (c) => {
1737
+ l(), s(c, r);
1738
+ } : (c) => s(c, r);
1739
+ i[e] = [...i[e] ?? [], o];
1740
+ const l = () => {
1741
+ const c = i[e] ?? [], a = c.indexOf(o);
1742
+ a !== -1 && (c.splice(a, 1), c.length === 0 ? (delete i[e], Object.keys(i).length === 0 && delete this.properties[B]) : i[e] = c, n?.signal != null && n.signal.removeEventListener("abort", l));
1743
+ };
1744
+ return n?.signal != null && n.signal.addEventListener("abort", l), l;
1745
+ };
1746
+ addClasses = (e) => {
1747
+ if (e.length === 0)
1748
+ return;
1749
+ const s = this.properties[I] ??= [];
1750
+ e.forEach((r) => {
1751
+ s.includes(r) || s.push(r);
1593
1752
  });
1594
- this.tagName = t, this.namespace = r;
1753
+ };
1754
+ removeClasses = (e) => {
1755
+ if (e.length === 0)
1756
+ return;
1757
+ const s = this.properties[I] ??= [];
1758
+ e.forEach((r) => {
1759
+ const n = s.indexOf(r);
1760
+ n !== -1 && s.splice(n, 1);
1761
+ }), s.length === 0 && delete this.properties[I];
1762
+ };
1763
+ getClasses = () => this.properties[I] ?? [];
1764
+ getAttributes = () => Object.entries(this.properties).filter(
1765
+ ([e]) => !["innerText", "innerHTML"].includes(e)
1766
+ );
1767
+ getVisibleAttributes = () => Reflect.ownKeys(this.properties).flatMap(
1768
+ (e) => e === I ? [["class", this.getClasses()]] : e === H ? [["style", this.getStyles()]] : typeof e == "string" ? [[e, String(this.properties[e])]] : []
1769
+ );
1770
+ setStyle = (e, s) => {
1771
+ const r = this.properties[H] ??= {};
1772
+ r[e] = s, s === "" && (delete r[e], Object.keys(r).length === 0 && delete this.properties[H]);
1773
+ };
1774
+ getStyle = (e) => this.properties[H]?.[e] ?? "";
1775
+ getStyles = () => this.properties[H] ?? {};
1776
+ makeAccessors = (e) => {
1777
+ const s = this.properties;
1778
+ return {
1779
+ get: () => s[e],
1780
+ set: (r) => s[e] = r
1781
+ };
1782
+ };
1783
+ }
1784
+ const bt = (t) => t.replace(/"/g, "&quot;"), St = (t) => t.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
1785
+ class wt extends Le {
1786
+ constructor(e, s, r) {
1787
+ super(r), this.tagName = e, this.namespace = s;
1595
1788
  }
1789
+ isPortal = () => !1;
1790
+ toHTML = (e = !1) => {
1791
+ const s = this.children.map((l) => l.toHTML()).join(""), r = this.namespace ? ` xmlns="${this.namespace}"` : "";
1792
+ let n = null;
1793
+ const i = this.getVisibleAttributes().map(([l, c]) => l === "class" ? ` class="${c.join(" ")}"` : l === "style" ? typeof c == "string" ? ` style="${c}"` : ` style="${Object.entries(c).map(([a, u]) => `${a}: ${u};`).join(" ")}"` : vt.has(l) ? ` ${l}` : l === "innerHTML" ? (n = c, "") : l === "innerText" ? (n = St(c), "") : ` ${l}="${bt(c)}"`).join(""), o = e ? ` ${De}` : "";
1794
+ return Tt.has(this.tagName) && s === "" ? `<${this.tagName}${r}${i}${o} />` : `<${this.tagName}${r}${i}${o}>${n ?? s}</${this.tagName}>`;
1795
+ };
1596
1796
  }
1597
- class He extends Ie {
1598
- constructor(t, r) {
1599
- super(r);
1600
- o(this, "isPortal", () => !0);
1601
- o(this, "toHTML", () => "");
1602
- o(this, "contentToHTML", (t = !1) => this.children.map((r) => r.toHTML(t)).join(""));
1603
- this.selector = t;
1797
+ class Oe extends Le {
1798
+ constructor(e, s) {
1799
+ super(s), this.selector = e;
1604
1800
  }
1801
+ isPortal = () => !0;
1802
+ toHTML = () => "";
1803
+ contentToHTML = (e = !1) => this.children.map((s) => s.toHTML(e)).join("");
1605
1804
  }
1606
- class Et {
1805
+ class _t {
1607
1806
  constructor(e) {
1608
- o(this, "id", Oe());
1609
- o(this, "isElement", () => !1);
1610
- o(this, "isText", () => !0);
1611
- o(this, "getText", () => this.text);
1612
- o(this, "toHTML", () => this.text);
1613
1807
  this.text = e;
1614
1808
  }
1809
+ id = xe();
1810
+ isElement = () => !1;
1811
+ isText = () => !0;
1812
+ getText = () => this.text;
1813
+ toHTML = () => this.text;
1615
1814
  }
1616
- class V {
1617
- constructor(e, t, r, n) {
1618
- o(this, "appendOrInsert", (e) => {
1619
- if (this.reference != null) {
1620
- const t = this.element.children.indexOf(this.reference);
1621
- this.element.children.splice(t, 0, e);
1622
- } else
1623
- this.element.children.push(e);
1624
- });
1625
- o(this, "makeChildElement", (e, t) => {
1626
- const r = new _t(e, t, this.element);
1627
- return this.appendOrInsert(r), new V(
1628
- r,
1629
- void 0,
1630
- this.container,
1631
- this.providers
1632
- );
1633
- });
1634
- o(this, "makeChildText", (e) => {
1635
- const t = new Et(e);
1636
- return this.appendOrInsert(t), new V(
1637
- this.element,
1638
- t,
1639
- this.container,
1640
- this.providers
1641
- );
1642
- });
1643
- o(this, "setText", (e) => {
1644
- this.reference && this.reference.isText() && (this.reference.text = e);
1645
- });
1646
- o(this, "getText", () => {
1647
- var e;
1648
- return ((e = this.reference) == null ? void 0 : e.getText()) ?? this.element.getText();
1649
- });
1650
- o(this, "makeRef", () => this.makeChildText(""));
1651
- o(this, "makePortal", (e) => {
1652
- const t = new He(e, this.element);
1653
- return this.appendOrInsert(t), new V(
1654
- t,
1655
- void 0,
1656
- this.container,
1657
- this.providers
1658
- );
1659
- });
1660
- /**
1661
- * Sets a provider for the given provider mark.
1662
- *
1663
- * @param mark - The provider mark to set the provider for.
1664
- * @param value - The provider to set for the given mark.
1665
- * @returns A new `DOMContext` instance with the specified provider.
1666
- */
1667
- o(this, "setProvider", (e, t, r) => new V(this.element, this.reference, this.container, {
1668
- ...this.providers,
1669
- [e]: [t, r]
1670
- }));
1671
- o(this, "getProvider", (e) => {
1672
- if (this.providers[e] === void 0)
1673
- throw new Le(e);
1674
- const [t, r] = this.providers[e];
1675
- return { value: t, onUse: r };
1676
- });
1677
- o(this, "clear", (e) => {
1678
- e && (this.reference !== void 0 ? this.element.removeChild(this.reference) : this.element.remove());
1679
- });
1680
- o(this, "on", (e, t) => this.element.on(e, t, this));
1681
- o(this, "addClasses", (e) => this.element.addClasses(e));
1682
- o(this, "removeClasses", (e) => this.element.removeClasses(e));
1683
- o(this, "getClasses", () => this.element.getClasses());
1684
- o(this, "isBrowserDOM", () => !1);
1685
- o(this, "isBrowser", () => !1);
1686
- o(this, "isHeadlessDOM", () => !0);
1687
- o(this, "isHeadless", () => !0);
1688
- o(this, "setStyle", (e, t) => this.element.setStyle(e, t));
1689
- o(this, "getStyle", (e) => this.element.getStyle(e));
1690
- o(this, "makeAccessors", (e) => this.element.makeAccessors(e));
1691
- this.element = e, this.reference = t, this.container = r, this.providers = n;
1815
+ class R {
1816
+ constructor(e, s, r, n) {
1817
+ this.element = e, this.reference = s, this.container = r, this.providers = n;
1692
1818
  }
1819
+ appendOrInsert = (e) => {
1820
+ if (this.reference != null) {
1821
+ const s = this.element.children.indexOf(this.reference);
1822
+ this.element.children.splice(s, 0, e);
1823
+ } else
1824
+ this.element.children.push(e);
1825
+ };
1826
+ makeChildElement = (e, s) => {
1827
+ const r = new wt(e, s, this.element);
1828
+ return this.appendOrInsert(r), new R(
1829
+ r,
1830
+ void 0,
1831
+ this.container,
1832
+ this.providers
1833
+ );
1834
+ };
1835
+ makeChildText = (e) => {
1836
+ const s = new _t(e);
1837
+ return this.appendOrInsert(s), new R(
1838
+ this.element,
1839
+ s,
1840
+ this.container,
1841
+ this.providers
1842
+ );
1843
+ };
1844
+ setText = (e) => {
1845
+ this.reference && this.reference.isText() && (this.reference.text = e);
1846
+ };
1847
+ getText = () => this.reference?.getText() ?? this.element.getText();
1848
+ makeRef = () => this.makeChildText("");
1849
+ makePortal = (e) => {
1850
+ const s = new Oe(e, this.element);
1851
+ return this.appendOrInsert(s), new R(
1852
+ s,
1853
+ void 0,
1854
+ this.container,
1855
+ this.providers
1856
+ );
1857
+ };
1858
+ /**
1859
+ * Sets a provider for the given provider mark.
1860
+ *
1861
+ * @param mark - The provider mark to set the provider for.
1862
+ * @param value - The provider to set for the given mark.
1863
+ * @returns A new `DOMContext` instance with the specified provider.
1864
+ */
1865
+ setProvider = (e, s, r) => new R(this.element, this.reference, this.container, {
1866
+ ...this.providers,
1867
+ [e]: [s, r]
1868
+ });
1869
+ getProvider = (e) => {
1870
+ if (this.providers[e] === void 0)
1871
+ throw new Ce(e);
1872
+ const [s, r] = this.providers[e];
1873
+ return { value: s, onUse: r };
1874
+ };
1875
+ clear = (e) => {
1876
+ e && (this.reference !== void 0 ? this.element.removeChild(this.reference) : this.element.remove());
1877
+ };
1878
+ on = (e, s) => this.element.on(e, s, this);
1879
+ addClasses = (e) => this.element.addClasses(e);
1880
+ removeClasses = (e) => this.element.removeClasses(e);
1881
+ getClasses = () => this.element.getClasses();
1882
+ isBrowserDOM = () => !1;
1883
+ isBrowser = () => !1;
1884
+ isHeadlessDOM = () => !0;
1885
+ isHeadless = () => !0;
1886
+ setStyle = (e, s) => this.element.setStyle(e, s);
1887
+ getStyle = (e) => this.element.getStyle(e);
1888
+ makeAccessors = (e) => this.element.makeAccessors(e);
1693
1889
  }
1694
- const Ct = /* @__PURE__ */ new Set([
1890
+ const vt = /* @__PURE__ */ new Set([
1695
1891
  "checked",
1696
1892
  "disabled",
1697
1893
  "multiple",
1698
1894
  "readonly",
1699
1895
  "required",
1700
1896
  "selected"
1701
- ]), wt = /* @__PURE__ */ new Set(["img", "br", "hr", "input", "link", "meta"]), ke = (s) => (e) => e.makeChildText(s).clear, $e = (s) => (e) => {
1702
- const t = e.makeChildText(s.value), r = s.on(t.setText);
1897
+ ]), Tt = /* @__PURE__ */ new Set(["img", "br", "hr", "input", "link", "meta"]), ke = (t) => (e) => e.makeChildText(t).clear, Me = (t) => (e) => {
1898
+ const s = e.makeChildText(t.value), r = t.on(s.setText);
1703
1899
  return (n) => {
1704
- r(), t.clear(n);
1900
+ r(), s.clear(n);
1705
1901
  };
1706
- }, ls = (s) => y.is(s) ? $e(s) : ke(s), _ = (...s) => (e) => {
1707
- const t = s.map((r) => f(r)(e));
1902
+ }, os = (t) => g.is(t) ? Me(t) : ke(t), E = (...t) => (e) => {
1903
+ const s = t.map((r) => d(r)(e));
1708
1904
  return (r) => {
1709
- t.forEach((n) => n(r));
1710
- };
1711
- }, x = () => () => {
1712
- }, xt = (s) => (e) => (e.addClasses(s), (t) => {
1713
- t && e.removeClasses(s);
1714
- }), Pt = (s) => (e) => {
1715
- let t = [];
1716
- const r = s.on((n) => {
1717
- e.removeClasses(t), t = (n ?? "").split(" ").filter((i) => i.length > 0), e.addClasses(t);
1905
+ s.forEach((n) => n(r));
1906
+ };
1907
+ }, C = () => () => {
1908
+ }, At = (t) => (e) => (e.addClasses(t), (s) => {
1909
+ s && e.removeClasses(t);
1910
+ }), Et = (t) => (e) => {
1911
+ let s = [];
1912
+ const r = t.on((n) => {
1913
+ e.removeClasses(s), s = (n ?? "").split(" ").filter((i) => i.length > 0), e.addClasses(s);
1718
1914
  });
1719
1915
  return (n) => {
1720
- r(), n && e.removeClasses(t), t.length = 0;
1721
- };
1722
- }, Lt = (s, e) => (t) => {
1723
- const { get: r, set: n } = t.makeAccessors(s), i = r();
1724
- return n(e), (l) => {
1725
- l && n(i);
1726
- };
1727
- }, Dt = (s, e) => (t) => {
1728
- const { get: r, set: n } = t.makeAccessors(s), i = r(), l = e.on(n);
1729
- return (c) => {
1730
- l(), c && n(i);
1731
- };
1732
- }, j = (s, e) => y.is(e) ? Dt(s, e) : Lt(s, e), se = (s = "") => (e, t) => {
1733
- const r = s ? `${s}${e}` : e;
1734
- return j(r, t);
1735
- }, q = new Proxy(
1916
+ r(), n && e.removeClasses(s), s.length = 0;
1917
+ };
1918
+ }, Ct = (t, e) => (s) => {
1919
+ const { get: r, set: n } = s.makeAccessors(t), i = r();
1920
+ return n(e), (o) => {
1921
+ o && n(i);
1922
+ };
1923
+ }, Dt = (t, e) => (s) => {
1924
+ const { get: r, set: n } = s.makeAccessors(t), i = r(), o = e.on(n);
1925
+ return (l) => {
1926
+ o(), l && n(i);
1927
+ };
1928
+ }, V = (t, e) => g.is(e) ? Dt(t, e) : Ct(t, e), te = (t = "") => (e, s) => {
1929
+ const r = t ? `${t}${e}` : e;
1930
+ return V(r, s);
1931
+ }, j = new Proxy(
1736
1932
  {},
1737
1933
  {
1738
1934
  /**
@@ -1746,12 +1942,12 @@ const Ct = /* @__PURE__ */ new Set([
1746
1942
  * @returns The renderable component for the specified attribute.
1747
1943
  *
1748
1944
  */
1749
- get: (s, e) => e === "class" ? (t) => y.is(t) ? Pt(t) : xt(
1945
+ get: (t, e) => e === "class" ? (s) => g.is(s) ? Et(s) : At(
1750
1946
  /* c8 ignore next */
1751
- (t ?? "").split(" ").filter((r) => r.length > 0)
1752
- ) : e === "set" ? se() : (t) => j(e, t)
1947
+ (s ?? "").split(" ").filter((r) => r.length > 0)
1948
+ ) : e === "set" ? te() : (s) => V(e, s)
1753
1949
  }
1754
- ), cs = new Proxy(
1950
+ ), ls = new Proxy(
1755
1951
  {},
1756
1952
  {
1757
1953
  /**
@@ -1762,9 +1958,9 @@ const Ct = /* @__PURE__ */ new Set([
1762
1958
  * @returns The renderable component for the specified attribute.
1763
1959
  *
1764
1960
  */
1765
- get: (s, e) => e === "set" ? se("data-") : (t) => j(`data-${e}`, t)
1961
+ get: (t, e) => e === "set" ? te("data-") : (s) => V(`data-${e}`, s)
1766
1962
  }
1767
- ), as = new Proxy(
1963
+ ), cs = new Proxy(
1768
1964
  {},
1769
1965
  {
1770
1966
  /**
@@ -1775,9 +1971,9 @@ const Ct = /* @__PURE__ */ new Set([
1775
1971
  * @returns The renderable component for the specified attribute.
1776
1972
  *
1777
1973
  */
1778
- get: (s, e) => e === "set" ? se("aria-") : (t) => j(`aria-${e}`, t)
1974
+ get: (t, e) => e === "set" ? te("aria-") : (s) => V(`aria-${e}`, s)
1779
1975
  }
1780
- ), us = new Proxy(
1976
+ ), as = new Proxy(
1781
1977
  {},
1782
1978
  {
1783
1979
  /**
@@ -1788,9 +1984,9 @@ const Ct = /* @__PURE__ */ new Set([
1788
1984
  * @returns The renderable component for the specified attribute.
1789
1985
  *
1790
1986
  */
1791
- get: (s, e) => e === "set" ? se() : (t) => j(e, t)
1987
+ get: (t, e) => e === "set" ? te() : (s) => V(e, s)
1792
1988
  }
1793
- ), hs = new Proxy(
1989
+ ), us = new Proxy(
1794
1990
  {},
1795
1991
  {
1796
1992
  /**
@@ -1800,31 +1996,31 @@ const Ct = /* @__PURE__ */ new Set([
1800
1996
  * @returns The renderable component for the specified attribute.
1801
1997
  *
1802
1998
  */
1803
- get: (s, e) => (t) => j(e, t)
1999
+ get: (t, e) => (s) => V(e, s)
1804
2000
  }
1805
- ), f = (s) => {
1806
- if (s == null)
1807
- return x;
1808
- if (Array.isArray(s))
1809
- return _(...s.map(f));
1810
- if (typeof s == "string")
1811
- return ke(s);
1812
- if (y.is(s))
1813
- return $e(s);
1814
- if (typeof s == "function")
1815
- return s;
1816
- throw new Error(`Unknown type: '${typeof s}' for child: ${s}`);
1817
- }, Ne = (s, ...e) => (t) => {
1818
- const r = t.makeChildElement(s, void 0), n = e.map((i) => f(i)(r));
2001
+ ), d = (t) => {
2002
+ if (t == null)
2003
+ return C;
2004
+ if (Array.isArray(t))
2005
+ return E(...t.map(d));
2006
+ if (typeof t == "string")
2007
+ return ke(t);
2008
+ if (g.is(t))
2009
+ return Me(t);
2010
+ if (typeof t == "function")
2011
+ return t;
2012
+ throw new Error(`Unknown type: '${typeof t}' for child: ${t}`);
2013
+ }, Ie = (t, ...e) => (s) => {
2014
+ const r = s.makeChildElement(t, void 0), n = e.map((i) => d(i)(r));
1819
2015
  return (i) => {
1820
- n.forEach((l) => l(!1)), r.clear(i);
2016
+ n.forEach((o) => o(!1)), r.clear(i);
1821
2017
  };
1822
- }, Re = (s, e, ...t) => (r) => {
1823
- const n = r.makeChildElement(s, e), i = t.map((l) => f(l)(n));
1824
- return (l) => {
1825
- i.forEach((c) => c(!1)), n.clear(l);
2018
+ }, He = (t, e, ...s) => (r) => {
2019
+ const n = r.makeChildElement(t, e), i = s.map((o) => d(o)(n));
2020
+ return (o) => {
2021
+ i.forEach((l) => l(!1)), n.clear(o);
1826
2022
  };
1827
- }, fs = new Proxy(
2023
+ }, hs = new Proxy(
1828
2024
  {},
1829
2025
  {
1830
2026
  /**
@@ -1832,7 +2028,7 @@ const Ct = /* @__PURE__ */ new Set([
1832
2028
  * @param tagName - The HTML tag name.
1833
2029
  * @returns A renderable function that creates and appends the HTML element to the DOM.
1834
2030
  */
1835
- get: (s, e) => (...t) => Ne(e, t.flatMap(f))
2031
+ get: (t, e) => (...s) => Ie(e, s.flatMap(d))
1836
2032
  }
1837
2033
  ), ds = new Proxy(
1838
2034
  {},
@@ -1842,9 +2038,9 @@ const Ct = /* @__PURE__ */ new Set([
1842
2038
  * @param type - The input type name.
1843
2039
  * @returns A renderable function that creates and appends the HTMLInput element to the DOM.
1844
2040
  */
1845
- get: (s, e) => (...t) => Ne("input", q.type(e), ...t)
2041
+ get: (t, e) => (...s) => Ie("input", j.type(e), ...s)
1846
2042
  }
1847
- ), Mt = "http://www.w3.org/2000/svg", ps = new Proxy(
2043
+ ), Pt = "http://www.w3.org/2000/svg", fs = new Proxy(
1848
2044
  {},
1849
2045
  {
1850
2046
  /**
@@ -1852,9 +2048,9 @@ const Ct = /* @__PURE__ */ new Set([
1852
2048
  * @param tagName - The SVG tag name.
1853
2049
  * @returns A renderable function that creates and appends the SVG element to the DOM.
1854
2050
  */
1855
- get: (s, e) => (...t) => Re(e, Mt, t.flatMap(f))
2051
+ get: (t, e) => (...s) => He(e, Pt, s.flatMap(d))
1856
2052
  }
1857
- ), Ot = "http://www.w3.org/1998/Math/MathML", ms = new Proxy(
2053
+ ), xt = "http://www.w3.org/1998/Math/MathML", ps = new Proxy(
1858
2054
  {},
1859
2055
  {
1860
2056
  /**
@@ -1862,35 +2058,35 @@ const Ct = /* @__PURE__ */ new Set([
1862
2058
  * @param tagName - The Math tag name.
1863
2059
  * @returns A renderable function that creates and appends the Math element to the DOM.
1864
2060
  */
1865
- get: (s, e) => (...t) => Re(e, Ot, t.flatMap(f))
2061
+ get: (t, e) => (...s) => He(e, xt, s.flatMap(d))
1866
2062
  }
1867
- ), Ve = (s, e) => {
2063
+ ), $e = (t, e) => {
1868
2064
  if (typeof e == "function")
1869
- return Ve(s, { then: e });
1870
- const t = e.pending != null ? f(e.pending()) : x, r = e.then, n = e.error != null ? (i) => f(e.error(i)) : () => x;
2065
+ return $e(t, { then: e });
2066
+ const s = e.pending != null ? d(e.pending()) : C, r = e.then, n = e.error != null ? (i) => d(e.error(i)) : () => C;
1871
2067
  return (i) => {
1872
- let l = !0;
1873
- const c = s(), a = i.makeRef();
1874
- let u = f(t)(a);
1875
- return c.then(
1876
- (h) => {
1877
- l && (u(!0), u = f(r(h))(a));
2068
+ let o = !0;
2069
+ const l = t(), c = i.makeRef();
2070
+ let a = d(s)(c);
2071
+ return l.then(
2072
+ (u) => {
2073
+ o && (a(!0), a = d(r(u))(c));
1878
2074
  },
1879
- (h) => {
1880
- l && (u(!0), u = f(n(h))(a));
2075
+ (u) => {
2076
+ o && (a(!0), a = d(n(u))(c));
1881
2077
  }
1882
- ), (h) => {
1883
- l = !1, u(h), a.clear(h);
2078
+ ), (u) => {
2079
+ o = !1, a(u), c.clear(u);
1884
2080
  };
1885
2081
  };
1886
- }, gs = (s, e) => Ve(() => s, e), je = (s, e, t) => (r) => r.on(s, e, t), It = (s) => je("click", (e, t) => {
2082
+ }, gs = (t, e) => $e(() => t, e), Ne = (t, e, s) => (r) => r.on(t, e, s), Lt = (t) => Ne("click", (e, s) => {
1887
2083
  e.preventDefault();
1888
2084
  const r = e.target;
1889
2085
  setTimeout(() => {
1890
- const n = r.ownerDocument != null ? r == null ? void 0 : r.checked : void 0;
1891
- n != null && s(!n, t);
2086
+ const n = r.ownerDocument != null ? r?.checked : void 0;
2087
+ n != null && t(!n, s);
1892
2088
  }, 0);
1893
- }), re = new Proxy(
2089
+ }), se = new Proxy(
1894
2090
  {},
1895
2091
  {
1896
2092
  /**
@@ -1898,332 +2094,331 @@ const Ct = /* @__PURE__ */ new Set([
1898
2094
  * @param fn - The function to call when the event is triggered.
1899
2095
  * @returns A `Renderable` function that adds the event listener to the element.
1900
2096
  */
1901
- get: (s, e) => (t) => je(e, t)
2097
+ get: (t, e) => (s) => Ne(e, s)
1902
2098
  }
1903
- ), Ht = (s, e) => (t) => {
1904
- (e == null ? void 0 : e.preventDefault) === !0 && t.preventDefault(), (e == null ? void 0 : e.stopPropagation) === !0 && t.stopPropagation(), (e == null ? void 0 : e.stopImmediatePropagation) === !0 && t.stopImmediatePropagation(), s(t);
1905
- }, I = (s, e) => Ht((t) => {
1906
- const r = t.target;
1907
- s(r, t);
1908
- }, e), kt = (s, e) => I(
1909
- (t, r) => s(t.value, r),
2099
+ ), Ot = (t, e) => (s) => {
2100
+ e?.preventDefault === !0 && s.preventDefault(), e?.stopPropagation === !0 && s.stopPropagation(), e?.stopImmediatePropagation === !0 && s.stopImmediatePropagation(), t(s);
2101
+ }, O = (t, e) => Ot((s) => {
2102
+ const r = s.target;
2103
+ t(r, s);
2104
+ }, e), kt = (t, e) => O(
2105
+ (s, r) => t(s.value, r),
1910
2106
  e
1911
- ), $t = (s, e) => I(
1912
- (t, r) => s(t.valueAsNumber, r),
2107
+ ), Mt = (t, e) => O(
2108
+ (s, r) => t(s.valueAsNumber, r),
1913
2109
  e
1914
- ), Nt = (s, e) => I((t, r) => {
1915
- if (t.value === "")
2110
+ ), It = (t, e) => O((s, r) => {
2111
+ if (s.value === "")
1916
2112
  return;
1917
- const n = t.value.split("-"), i = new Date(
2113
+ const n = s.value.split("-"), i = new Date(
1918
2114
  Number(n[0]),
1919
2115
  Number(n[1]) - 1,
1920
2116
  Number(n[2].substring(0, 2))
1921
2117
  );
1922
- s(i, r);
1923
- }, e), ys = (s, e) => I((t, r) => {
1924
- if (t.value === "") {
1925
- s(null, r);
2118
+ t(i, r);
2119
+ }, e), ms = (t, e) => O((s, r) => {
2120
+ if (s.value === "") {
2121
+ t(null, r);
1926
2122
  return;
1927
2123
  }
1928
- const n = t.value.split("-"), i = new Date(
2124
+ const n = s.value.split("-"), i = new Date(
1929
2125
  Number(n[0]),
1930
2126
  Number(n[1]) - 1,
1931
2127
  Number(n[2].substring(0, 2))
1932
2128
  );
1933
- s(i, r);
1934
- }, e), Rt = (s, e) => I((t, r) => {
1935
- if (t.value === "")
2129
+ t(i, r);
2130
+ }, e), Ht = (t, e) => O((s, r) => {
2131
+ if (s.value === "")
1936
2132
  return;
1937
- const n = t.value.split("T"), i = n[0].split("-"), l = new Date(
2133
+ const n = s.value.split("T"), i = n[0].split("-"), o = new Date(
1938
2134
  Number(i[0]),
1939
2135
  Number(i[1]) - 1,
1940
2136
  Number(i[2])
1941
- ), c = n[1].split(":");
1942
- l.setHours(Number(c[0])), l.setMinutes(Number(c[1])), l.setSeconds(Number(c[2])), s(l, r);
1943
- }, e), bs = (s, e) => I((t, r) => {
1944
- if (t.value === "") {
1945
- s(null, r);
2137
+ ), l = n[1].split(":");
2138
+ o.setHours(Number(l[0])), o.setMinutes(Number(l[1])), o.setSeconds(Number(l[2])), t(o, r);
2139
+ }, e), ys = (t, e) => O((s, r) => {
2140
+ if (s.value === "") {
2141
+ t(null, r);
1946
2142
  return;
1947
2143
  }
1948
- const n = t.value.split("T");
2144
+ const n = s.value.split("T");
1949
2145
  if (n.length !== 2) {
1950
- s(null, r);
2146
+ t(null, r);
1951
2147
  return;
1952
2148
  }
1953
- const i = n[0].split("-"), l = new Date(
2149
+ const i = n[0].split("-"), o = new Date(
1954
2150
  Number(i[0]),
1955
2151
  Number(i[1]) - 1,
1956
2152
  Number(i[2])
1957
- ), c = n[1].split(":");
1958
- l.setHours(Number(c[0] ?? 0)), l.setMinutes(Number(c[1] ?? 0)), l.setSeconds(Number(c[2] ?? 0)), s(l, r);
1959
- }, e), Ts = (s, e) => I((t, r) => {
1960
- s(t.checked, r);
1961
- }, e), Ss = (s, e = "input") => _(q.valueAsDate(s), re[e](Nt(s.set))), vs = (s, e = "input") => _(q.valueAsDate(s), re[e](Rt(s.set))), As = (s, e = "input") => _(q.valueAsNumber(s), re[e]($t(s.set))), _s = (s, e = "input") => _(q.value(s), re[e](kt(s.set))), Es = (s) => _(q.checked(s), It(s.set)), de = (s, e, t) => y.is(s) ? e(s) : t(s), Vt = (s, e, t) => {
1962
- const r = s.makeRef();
2153
+ ), l = n[1].split(":");
2154
+ o.setHours(Number(l[0] ?? 0)), o.setMinutes(Number(l[1] ?? 0)), o.setSeconds(Number(l[2] ?? 0)), t(o, r);
2155
+ }, e), bs = (t, e) => O((s, r) => {
2156
+ t(s.checked, r);
2157
+ }, e), Ss = (t, e = "input") => E(j.valueAsDate(t), se[e](It(t.set))), ws = (t, e = "input") => E(j.valueAsDate(t), se[e](Ht(t.set))), _s = (t, e = "input") => E(j.valueAsNumber(t), se[e](Mt(t.set))), vs = (t, e = "input") => E(j.value(t), se[e](kt(t.set))), Ts = (t) => E(j.checked(t), Lt(t.set)), ue = (t, e, s) => g.is(t) ? e(t) : s(t), $t = (t, e, s) => {
2158
+ const r = t.makeRef();
1963
2159
  let n = () => {
1964
- };
1965
- const i = e.on((l) => {
1966
- n(!0), n = f(t(l))(r);
2160
+ }, i = null;
2161
+ const o = e.on((l) => {
2162
+ i?.dispose(), n(!0), i = new q(), n = L(
2163
+ i,
2164
+ () => d(s(l))(r)
2165
+ );
1967
2166
  });
1968
2167
  return (l) => {
1969
- n(l), i(), r.clear(l);
2168
+ i?.dispose(), n(l), o(), r.clear(l);
1970
2169
  };
1971
- }, ne = (s, e) => {
1972
- function t(n) {
2170
+ }, re = (t, e) => {
2171
+ function s(n) {
1973
2172
  return (i) => {
1974
- const l = i.makeRef();
1975
- let c, a;
1976
- const u = n.map((p) => Object.keys(p)[0]);
1977
- let h;
1978
- const d = u.on((p) => {
1979
- if (p !== h) {
1980
- h = p, a == null || a.dispose(), c == null || c(!0), a = n.map((g) => g[p]);
1981
- const m = e[p](a);
1982
- c = f(m)(l);
2173
+ const o = i.makeRef();
2174
+ let l, c;
2175
+ const a = n.map((p) => Object.keys(p)[0]);
2176
+ let u;
2177
+ const h = a.on((p) => {
2178
+ if (p !== u) {
2179
+ u = p, c?.dispose(), l?.(!0), c = n.map((m) => m[p]);
2180
+ const f = e[p](c);
2181
+ l = d(f)(o);
1983
2182
  }
1984
2183
  });
1985
2184
  return (p) => {
1986
- a == null || a.dispose(), d(), l.clear(p), c == null || c(p);
2185
+ c?.dispose(), h(), o.clear(p), l?.(p);
1987
2186
  };
1988
2187
  };
1989
2188
  }
1990
2189
  function r(n) {
1991
2190
  const i = Object.keys(n)[0];
1992
- return f(e[i](te(n[i])));
2191
+ return d(e[i](K(n[i])));
1993
2192
  }
1994
- return de(s, t, r);
1995
- }, qe = (s, e, t) => ne(
1996
- b.map(s, (r) => ({ [r[e]]: r })),
2193
+ return ue(t, s, r);
2194
+ }, Re = (t, e, s) => re(
2195
+ y.map(t, (r) => ({ [r[e]]: r })),
1997
2196
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
1998
- t
1999
- ), Cs = (s, e) => qe(s, "kind", e), ws = (s, e) => {
2000
- const t = b.map(s, ([r, n]) => ({ [r]: n }));
2001
- return ne(t, e);
2002
- }, xs = (s, e) => qe(s, "type", e), jt = (s, e) => ne(
2003
- b.map(s, (t) => ({ [t]: !0 })),
2197
+ s
2198
+ ), As = (t, e) => Re(t, "kind", e), Es = (t, e) => {
2199
+ const s = y.map(t, ([r, n]) => ({ [r]: n }));
2200
+ return re(s, e);
2201
+ }, Cs = (t, e) => Re(t, "type", e), Nt = (t, e) => re(
2202
+ y.map(t, (s) => ({ [s]: !0 })),
2004
2203
  e
2005
- ), Ps = (s, e = {}) => (t) => {
2006
- const r = (e == null ? void 0 : e.firstSeparator) ?? s, n = (e == null ? void 0 : e.lastSeparator) ?? s;
2007
- return jt(
2008
- t.map((i) => i.isFirst ? "first" : i.isLast ? "last" : "other"),
2204
+ ), Ds = (t, e = {}) => (s) => {
2205
+ const r = e?.firstSeparator ?? t, n = e?.lastSeparator ?? t;
2206
+ return Nt(
2207
+ s.map((i) => i.isFirst ? "first" : i.isLast ? "last" : "other"),
2009
2208
  {
2010
2209
  first: r,
2011
2210
  last: n,
2012
- other: s
2211
+ other: t
2013
2212
  }
2014
2213
  );
2015
- }, Ls = (s) => (e) => (e.appendOrInsert(s), (t) => {
2016
- t && X(s);
2017
- }), Ds = (s, e, t) => {
2214
+ }, Ps = (t) => (e) => (e.appendOrInsert(t), (s) => {
2215
+ s && U(t);
2216
+ }), xs = (t, e, s) => {
2018
2217
  function r(i) {
2019
- return (l) => {
2020
- const c = l.makeRef();
2021
- let a = () => {
2022
- }, u = !1, h = null;
2023
- const d = i.on((p) => {
2024
- p == null ? (a(!0), a = f(t == null ? void 0 : t())(c), u = !1, h == null || h.dispose(), h = null) : u ? h.set(p) : (h = w(p), a(!0), a = f(e(h))(
2025
- c
2026
- ), u = !0);
2218
+ return (o) => {
2219
+ const l = o.makeRef();
2220
+ let c = () => {
2221
+ }, a = !1, u = null;
2222
+ const h = i.on((p) => {
2223
+ p == null ? (c(!0), c = d(s?.())(l), a = !1, u?.dispose(), u = null) : a ? u.set(p) : (u = T(p), c(!0), c = d(e(u))(
2224
+ l
2225
+ ), a = !0);
2027
2226
  });
2028
2227
  return (p) => {
2029
- h == null || h.dispose(), d(), a == null || a(p), c.clear(p);
2228
+ u?.dispose(), h(), c?.(p), l.clear(p);
2030
2229
  };
2031
2230
  };
2032
2231
  }
2033
2232
  function n(i) {
2034
2233
  if (i == null) {
2035
- const l = t == null ? void 0 : t();
2036
- return l != null ? f(l) : x;
2234
+ const o = s?.();
2235
+ return o != null ? d(o) : C;
2037
2236
  }
2038
- return f(e(te(i)));
2237
+ return d(e(K(i)));
2039
2238
  }
2040
- return de(
2041
- s,
2239
+ return ue(
2240
+ t,
2042
2241
  r,
2043
2242
  n
2044
2243
  );
2045
- }, Ms = (...s) => (e, t) => (r) => {
2244
+ }, Ls = (...t) => (e, s) => (r) => {
2046
2245
  const n = r.makeRef();
2047
- if (s.some(
2048
- (m) => !y.is(m) && m == null
2246
+ if (t.some(
2247
+ (f) => !g.is(f) && f == null
2049
2248
  ))
2050
- return (t != null ? f(t == null ? void 0 : t()) : x)(
2249
+ return (s != null ? d(s?.()) : C)(
2051
2250
  n
2052
2251
  );
2053
- const l = s.map(() => null), c = s.map(
2054
- (m) => y.is(m) ? m.value != null : m != null
2252
+ const o = t.map(() => null), l = t.map(
2253
+ (f) => g.is(f) ? f.value != null : f != null
2055
2254
  );
2056
- let a = null;
2057
- const u = w(c.every((m) => m)), h = (m, g) => {
2058
- if (m.value != null) {
2059
- if (l[g] == null) {
2060
- const S = w(m.value);
2061
- l[g] = S;
2255
+ let c = null;
2256
+ const a = T(l.every((f) => f)), u = (f, m) => {
2257
+ if (f.value != null) {
2258
+ if (o[m] == null) {
2259
+ const S = T(f.value);
2260
+ o[m] = S;
2062
2261
  } else
2063
- l[g].value = m.value;
2064
- c[g] = !0;
2262
+ o[m].value = f.value;
2263
+ l[m] = !0;
2065
2264
  } else
2066
- c[g] = !1;
2265
+ l[m] = !1;
2067
2266
  };
2068
- let d = s.length - 1;
2069
- const p = s.map((m, g) => {
2070
- if (!y.is(m)) {
2071
- const S = w(m);
2072
- return l[g] = S, () => {
2267
+ let h = t.length - 1;
2268
+ const p = t.map((f, m) => {
2269
+ if (!g.is(f)) {
2270
+ const S = T(f);
2271
+ return o[m] = S, () => {
2073
2272
  };
2074
2273
  }
2075
- return m.on(() => {
2076
- h(m, g), d === 0 ? u.value = c.every((S) => S) : d--;
2274
+ return f.on(() => {
2275
+ u(f, m), h === 0 ? a.value = l.every((S) => S) : h--;
2077
2276
  });
2078
2277
  });
2079
- return u.on((m) => {
2080
- a == null || a(!0), a = null, m ? a = f(e(...l))(n) : a = f((t == null ? void 0 : t()) ?? x)(n);
2081
- }), (m) => {
2082
- l.forEach((g) => g == null ? void 0 : g.dispose()), u.dispose(), p.forEach((g) => g()), a == null || a(m), n.clear(m);
2083
- };
2084
- }, F = (...s) => (e) => (t) => s.forEach((r) => r(t, e)), Fe = (s, e, t) => de(
2085
- s,
2086
- (r) => (n) => Vt(
2278
+ return a.on((f) => {
2279
+ c?.(!0), c = null, f ? c = d(e(...o))(n) : c = d(s?.() ?? C)(n);
2280
+ }), (f) => {
2281
+ o.forEach((m) => m?.dispose()), a.dispose(), p.forEach((m) => m()), c?.(f), n.clear(f);
2282
+ };
2283
+ }, Ve = (t, e, s) => ue(
2284
+ t,
2285
+ (r) => (n) => $t(
2087
2286
  n,
2088
2287
  r,
2089
- (i) => i ? e() : t == null ? void 0 : t()
2288
+ (i) => i ? e() : s?.()
2090
2289
  ),
2091
2290
  (r) => {
2092
2291
  if (r) {
2093
2292
  const n = e();
2094
- return n != null ? f(n) : x;
2293
+ return n != null ? d(n) : C;
2095
2294
  }
2096
- return f(t == null ? void 0 : t());
2295
+ return d(s?.());
2097
2296
  }
2098
- ), Os = (s, e, t) => Fe(
2099
- b.map(s, (r) => !r),
2297
+ ), Os = (t, e, s) => Ve(
2298
+ y.map(t, (r) => !r),
2100
2299
  e,
2101
- t
2102
- ), Be = (s, e, t) => {
2103
- if (t != null)
2104
- return Be(s, (r) => {
2105
- const n = new ce(
2300
+ s
2301
+ ), je = (t, e, s) => {
2302
+ if (s != null)
2303
+ return je(t, (r) => {
2304
+ const n = new le(
2106
2305
  r.index,
2107
2306
  r.total.map((i) => i - 1)
2108
2307
  );
2109
- return _(
2110
- F(n.dispose),
2111
- f(e(r)),
2112
- Fe(
2308
+ return E(
2309
+ d(e(r)),
2310
+ Ve(
2113
2311
  r.isLast,
2114
- () => x,
2115
- () => t(n)
2312
+ () => C,
2313
+ () => s(n)
2116
2314
  )
2117
2315
  );
2118
2316
  });
2119
- if (y.is(s))
2317
+ if (g.is(t))
2120
2318
  return (r) => {
2121
- const n = s.derive(), i = r.makeRef(), l = [];
2319
+ const n = t.derive(), i = r.makeRef(), o = [], l = [];
2122
2320
  return n.on((c) => {
2123
- const a = l.splice(c);
2124
- for (const u of a)
2125
- u(!0);
2126
- for (let u = l.length; u < c; u++) {
2127
- const h = new ce(u, n);
2128
- l.push(
2129
- _(
2130
- F(h.dispose),
2131
- f(e(h))
2132
- )(i)
2321
+ const a = o.splice(c), u = l.splice(c);
2322
+ for (const h of u)
2323
+ h.dispose();
2324
+ for (const h of a)
2325
+ h(!0);
2326
+ for (let h = o.length; h < c; h++) {
2327
+ const p = new le(h, n), f = new q();
2328
+ l.push(f), o.push(
2329
+ L(f, () => d(e(p))(i))
2133
2330
  );
2134
2331
  }
2135
2332
  }), (c) => {
2136
- n.dispose();
2137
2333
  for (const a of l)
2334
+ a.dispose();
2335
+ l.length = 0, n.dispose();
2336
+ for (const a of o)
2138
2337
  a(c);
2139
- l.length = 0, i.clear(c);
2338
+ o.length = 0, i.clear(c);
2140
2339
  };
2141
2340
  };
2142
2341
  {
2143
- const r = te(s);
2144
- return _(
2145
- ...Array.from({ length: s }, (n, i) => i).map((n) => {
2146
- const i = new ce(n, r);
2147
- return _(
2148
- F(i.dispose),
2149
- f(e(i))
2150
- );
2342
+ const r = K(t);
2343
+ return E(
2344
+ ...Array.from({ length: t }, (n, i) => i).map((n) => {
2345
+ const i = new le(n, r);
2346
+ return d(e(i));
2151
2347
  })
2152
2348
  );
2153
2349
  }
2154
- }, Is = (s, e, t) => {
2155
- const r = b.map(s, (i) => i.length), n = b.toSignal(s);
2156
- return Be(
2350
+ }, ks = (t, e, s) => {
2351
+ const r = y.map(t, (i) => i.length), n = y.toSignal(t);
2352
+ return je(
2157
2353
  r,
2158
2354
  (i) => {
2159
- const l = n.map((c) => c[i.index]);
2160
- return _(
2161
- F(l.dispose),
2162
- f(e(l, i))
2163
- );
2355
+ const o = n.map((l) => l[i.index]);
2356
+ return d(e(o, i));
2164
2357
  },
2165
- t
2358
+ s
2166
2359
  );
2167
- }, Hs = (s, e) => {
2168
- if (y.is(s)) {
2169
- const t = s;
2360
+ }, Rt = (...t) => (e) => (s) => t.forEach((r) => {
2361
+ typeof r == "function" ? r(s, e) : r.dispose(s, e);
2362
+ }), Ms = (t, e) => {
2363
+ if (g.is(t)) {
2364
+ const s = t;
2170
2365
  return (r) => {
2171
2366
  r = r.makeRef();
2172
- const n = t.map((c) => f(e(c)));
2367
+ const n = s.map((l) => d(e(l)));
2173
2368
  let i = () => {
2174
2369
  };
2175
- const l = n.on((c) => {
2176
- i(!0), i = c(r);
2370
+ const o = n.on((l) => {
2371
+ i(!0), i = l(r);
2177
2372
  });
2178
- return (c) => {
2179
- l(), i(c);
2373
+ return (l) => {
2374
+ o(), i(l);
2180
2375
  };
2181
2376
  };
2182
2377
  }
2183
- return f(e(s));
2184
- }, ks = (s, e, t = () => x) => ne(
2185
- b.map(
2186
- s,
2378
+ return d(e(t));
2379
+ }, Is = (t, e, s = () => C) => re(
2380
+ y.map(
2381
+ t,
2187
2382
  (r) => r.length > 0 ? { notEmpty: r } : { whenEmpty: null }
2188
2383
  ),
2189
2384
  {
2190
2385
  notEmpty: (r) => e(r),
2191
- whenEmpty: () => t()
2386
+ whenEmpty: () => s()
2192
2387
  }
2193
- ), $s = (s, e) => (t) => {
2194
- const r = t.makePortal(s), n = fe(f(e), r);
2388
+ ), Hs = (t, e) => (s) => {
2389
+ const r = s.makePortal(t), n = ae(d(e), r);
2195
2390
  return () => n(!0);
2196
- }, J = /* @__PURE__ */ new Map(), qt = (s) => ({
2197
- mark: lt(`Probe(${s.description})`),
2391
+ }, W = /* @__PURE__ */ new Map(), Vt = (t) => ({
2392
+ mark: nt(`Probe(${t.description})`),
2198
2393
  create: ({ callback: e = () => {
2199
- }, timeout: t = 10 } = {}) => {
2200
- const r = (c) => {
2201
- clearTimeout(n), J.delete(s), e(c);
2394
+ }, timeout: s = 10 } = {}) => {
2395
+ const r = (l) => {
2396
+ clearTimeout(n), W.delete(t), e(l);
2202
2397
  };
2203
- if (J.has(s))
2204
- throw new Error(`Probe already exists: ${s.description}`);
2205
- const n = setTimeout(() => r("timeout"), t), i = { counter: 0, timeoutId: n };
2206
- return J.set(s, i), {
2398
+ if (W.has(t))
2399
+ throw new Error(`Probe already exists: ${t.description}`);
2400
+ const n = setTimeout(() => r("timeout"), s), i = { counter: 0, timeoutId: n };
2401
+ return W.set(t, i), {
2207
2402
  value: () => {
2208
2403
  clearTimeout(n);
2209
- const c = J.get(s);
2210
- c != null && --c.counter === 0 && r("resolved");
2404
+ const l = W.get(t);
2405
+ l != null && --l.counter === 0 && r("resolved");
2211
2406
  },
2212
2407
  dispose: () => r("disposed"),
2213
2408
  onUse: () => i.counter++
2214
2409
  };
2215
2410
  }
2216
- }), Ns = qt(Symbol("GlobalProbe")), Ft = (s, e) => (t) => {
2217
- const r = t.getStyle(s);
2218
- return t.setStyle(s, e), (n) => {
2219
- n && t.setStyle(s, r);
2411
+ }), $s = Vt(Symbol("GlobalProbe")), jt = (t, e) => (s) => {
2412
+ const r = s.getStyle(t);
2413
+ return s.setStyle(t, e), (n) => {
2414
+ n && s.setStyle(t, r);
2220
2415
  };
2221
- }, Bt = (s, e) => (t) => {
2222
- const r = t.getStyle(s), n = e.on((i) => t.setStyle(s, i));
2416
+ }, qt = (t, e) => (s) => {
2417
+ const r = s.getStyle(t), n = e.on((i) => s.setStyle(t, i));
2223
2418
  return (i) => {
2224
- n(), i && t.setStyle(s, r);
2419
+ n(), i && s.setStyle(t, r);
2225
2420
  };
2226
- }, Te = (s, e) => y.is(e) ? Bt(s, e) : Ft(s, e), Rs = new Proxy({}, {
2421
+ }, pe = (t, e) => g.is(e) ? qt(t, e) : jt(t, e), Ns = new Proxy({}, {
2227
2422
  /**
2228
2423
  * Creates a renderable component for the specified `style` property.
2229
2424
  *
@@ -2232,168 +2427,184 @@ const Ct = /* @__PURE__ */ new Set([
2232
2427
  * @returns The renderable component for the specified attribute.
2233
2428
  *
2234
2429
  */
2235
- get: (s, e) => e === "variable" ? (t, r) => Te(t, r) : (t) => Te(e, t)
2236
- }), Wt = (s) => (e) => {
2430
+ get: (t, e) => e === "variable" ? (s, r) => pe(s, r) : (s) => pe(e, s)
2431
+ }), Ft = (t) => (e) => {
2237
2432
  if (e.isBrowser()) {
2238
- const t = s(e);
2239
- if (t != null)
2240
- return f(t)(e);
2433
+ const s = t(e);
2434
+ if (s != null)
2435
+ return d(s)(e);
2241
2436
  }
2242
2437
  return () => {
2243
2438
  };
2244
- }, Vs = (s) => (e) => {
2245
- const t = s(e);
2246
- return t == null ? () => {
2247
- } : f(t)(e);
2248
- }, js = (s) => Wt((e) => s(e.element)), qs = (s) => (e) => {
2439
+ }, Rs = (t) => (e) => {
2440
+ const s = t(e);
2441
+ return s == null ? () => {
2442
+ } : d(s)(e);
2443
+ }, Vs = (t) => Ft((e) => t(e.element)), js = (t) => (e) => {
2249
2444
  if (e.isHeadlessDOM()) {
2250
- const t = s(e);
2251
- if (t)
2252
- return f(t)(e);
2445
+ const s = t(e);
2446
+ if (s)
2447
+ return d(s)(e);
2253
2448
  }
2254
2449
  return () => {
2255
2450
  };
2256
- }, pe = (s) => (e) => {
2257
- let t = e;
2451
+ }, qs = (t) => (e) => {
2452
+ const s = new q(), r = L(s, () => d(t(s))(e));
2453
+ return (n) => {
2454
+ s.dispose(), r(n);
2455
+ };
2456
+ }, he = (t) => (e) => {
2457
+ let s = e;
2258
2458
  function r() {
2259
- return t;
2459
+ return s;
2260
2460
  }
2261
- function n(c) {
2262
- t = c;
2461
+ function n(l) {
2462
+ s = l;
2263
2463
  }
2264
- const i = [], l = s({
2265
- use: ({ mark: c }) => {
2266
- const { value: a, onUse: u } = r().getProvider(c);
2267
- return u == null || u(), a;
2464
+ const i = [], o = t({
2465
+ use: ({ mark: l }) => {
2466
+ const { value: c, onUse: a } = r().getProvider(l);
2467
+ return a?.(), c;
2268
2468
  },
2269
- set: ({ mark: c, create: a }, u) => {
2270
- const { value: h, dispose: d, onUse: p } = a(u, r());
2271
- i.push(d), n(r().setProvider(c, h, p));
2469
+ set: ({ mark: l, create: c }, a) => {
2470
+ const { value: u, dispose: h, onUse: p } = c(a, r());
2471
+ i.push(h), n(r().setProvider(l, u, p));
2272
2472
  }
2273
2473
  });
2274
- return l == null ? () => {
2275
- } : _(
2276
- f(l),
2277
- F(() => i.forEach((c) => c()))
2474
+ return o == null ? () => {
2475
+ } : E(
2476
+ d(o),
2477
+ Rt(() => i.forEach((l) => l()))
2278
2478
  )(r());
2279
- }, Fs = (s, e, t) => pe(({ set: r }) => (r(s, e), t())), Bs = (s, e) => pe(({ use: t }) => e(t(s))), Ws = (...s) => (e) => pe(({ use: t }) => {
2280
- const r = s.map(t);
2479
+ }, Fs = (t, e, s) => he(({ set: r }) => (r(t, e), s())), Bs = (t, e) => he(({ use: s }) => e(s(t))), Ws = (...t) => (e) => he(({ use: s }) => {
2480
+ const r = t.map(s);
2281
2481
  return e(...r);
2282
2482
  });
2283
2483
  export {
2284
2484
  gs as Async,
2285
- Es as BindChecked,
2485
+ Ts as BindChecked,
2286
2486
  Ss as BindDate,
2287
- vs as BindDateTime,
2288
- As as BindNumber,
2289
- _s as BindText,
2290
- R as BrowserContext,
2291
- Y as CLASS_PLACEHOLDER_ATTR,
2292
- N as Computed,
2293
- Ps as Conjunction,
2294
- Ls as DOMNode,
2295
- Ne as El,
2296
- Re as ElNS,
2297
- ce as ElementPosition,
2298
- x as Empty,
2299
- Ds as Ensure,
2300
- Ms as EnsureAll,
2301
- Is as ForEach,
2302
- _ as Fragment,
2303
- Ns as GlobalProbe,
2304
- is as HeadlessAdapter,
2305
- V as HeadlessContext,
2306
- _t as HeadlessElement,
2307
- He as HeadlessPortal,
2308
- Et as HeadlessText,
2309
- Hs as MapSignal,
2310
- ve as MemoryStore,
2311
- ks as NotEmpty,
2312
- It as OnChecked,
2313
- F as OnDispose,
2314
- ne as OneOf,
2315
- qe as OneOfField,
2316
- Cs as OneOfKind,
2317
- ws as OneOfTuple,
2318
- xs as OneOfType,
2319
- jt as OneOfValue,
2320
- $s as Portal,
2321
- G as Prop,
2487
+ ws as BindDateTime,
2488
+ _s as BindNumber,
2489
+ vs as BindText,
2490
+ N as BrowserContext,
2491
+ J as CLASS_PLACEHOLDER_ATTR,
2492
+ $ as Computed,
2493
+ Ds as Conjunction,
2494
+ Ps as DOMNode,
2495
+ q as DisposalScope,
2496
+ Ie as El,
2497
+ He as ElNS,
2498
+ le as ElementPosition,
2499
+ C as Empty,
2500
+ xs as Ensure,
2501
+ Ls as EnsureAll,
2502
+ ks as ForEach,
2503
+ E as Fragment,
2504
+ $s as GlobalProbe,
2505
+ ns as HeadlessAdapter,
2506
+ R as HeadlessContext,
2507
+ wt as HeadlessElement,
2508
+ Oe as HeadlessPortal,
2509
+ _t as HeadlessText,
2510
+ Ms as MapSignal,
2511
+ be as MemoryStore,
2512
+ Is as NotEmpty,
2513
+ Lt as OnChecked,
2514
+ Rt as OnDispose,
2515
+ re as OneOf,
2516
+ Re as OneOfField,
2517
+ As as OneOfKind,
2518
+ Es as OneOfTuple,
2519
+ Cs as OneOfType,
2520
+ Nt as OneOfValue,
2521
+ Hs as Portal,
2522
+ Z as Prop,
2322
2523
  Fs as Provide,
2323
- Le as ProviderNotFoundError,
2324
- ct as RenderingError,
2325
- Be as Repeat,
2326
- y as Signal,
2327
- Ve as Task,
2328
- ls as TextNode,
2524
+ Ce as ProviderNotFoundError,
2525
+ it as RenderingError,
2526
+ je as Repeat,
2527
+ g as Signal,
2528
+ $e as Task,
2529
+ os as TextNode,
2329
2530
  Os as Unless,
2330
2531
  Bs as Use,
2331
2532
  Ws as UseMany,
2332
- b as Value,
2333
- Fe as When,
2334
- Wt as WithBrowserCtx,
2335
- Vs as WithCtx,
2336
- js as WithElement,
2337
- qs as WithHeadlessCtx,
2338
- pe as WithProvider,
2533
+ y as Value,
2534
+ Ve as When,
2535
+ Ft as WithBrowserCtx,
2536
+ Rs as WithCtx,
2537
+ Vs as WithElement,
2538
+ js as WithHeadlessCtx,
2539
+ he as WithProvider,
2540
+ qs as WithScope,
2339
2541
  De as _NODE_PLACEHOLDER_ATTR,
2340
- ot as _getSelfOrParentElement,
2341
- Pe as _isElement,
2342
- it as _makeGetter,
2343
- nt as _makeSetter,
2344
- X as _removeDOMNode,
2345
- $e as _signalText,
2542
+ rt as _getSelfOrParentElement,
2543
+ Ee as _isElement,
2544
+ st as _makeGetter,
2545
+ tt as _makeSetter,
2546
+ U as _removeDOMNode,
2547
+ Me as _signalText,
2346
2548
  ke as _staticText,
2347
- Qt as animateSignal,
2348
- st as animateSignals,
2349
- as as aria,
2350
- q as attr,
2351
- ts as bind,
2352
- ss as coalesce,
2353
- ae as computed,
2354
- he as computedOf,
2355
- rt as computedRecord,
2356
- cs as dataAttr,
2357
- zt as delaySignal,
2358
- ze as effect,
2359
- Gt as effectOf,
2360
- Ht as emit,
2361
- Ts as emitChecked,
2362
- I as emitTarget,
2549
+ Yt as animateSignal,
2550
+ Ke as animateSignals,
2551
+ cs as aria,
2552
+ j as attr,
2553
+ es as bind,
2554
+ ts as coalesce,
2555
+ z as computed,
2556
+ ee as computedOf,
2557
+ et as computedRecord,
2558
+ ls as dataAttr,
2559
+ Zt as delaySignal,
2560
+ me as effect,
2561
+ Ge as effectOf,
2562
+ Ot as emit,
2563
+ bs as emitChecked,
2564
+ O as emitTarget,
2363
2565
  kt as emitValue,
2364
- Nt as emitValueAsDate,
2365
- Rt as emitValueAsDateTime,
2366
- ys as emitValueAsNullableDate,
2367
- bs as emitValueAsNullableDateTime,
2368
- $t as emitValueAsNumber,
2369
- Ye as endInterpolate,
2370
- ue as getWindow,
2371
- Qe as guessInterpolate,
2372
- fs as html,
2566
+ It as emitValueAsDate,
2567
+ Ht as emitValueAsDateTime,
2568
+ ms as emitValueAsNullableDate,
2569
+ ys as emitValueAsNullableDateTime,
2570
+ Mt as emitValueAsNumber,
2571
+ Ze as endInterpolate,
2572
+ ge as getCurrentScope,
2573
+ Wt as getParentScope,
2574
+ Bt as getScopeStack,
2575
+ ce as getWindow,
2576
+ ze as guessInterpolate,
2577
+ hs as html,
2373
2578
  ds as input,
2374
- Xe as interpolateDate,
2375
- Je as interpolateNumber,
2376
- Ge as interpolateString,
2579
+ Qe as interpolateDate,
2580
+ Xe as interpolateNumber,
2581
+ Ye as interpolateString,
2377
2582
  Jt as joinSignals,
2378
- Xt as localStorageProp,
2379
- qt as makeProbe,
2380
- lt as makeProviderMark,
2381
- ms as math,
2382
- hs as mathAttr,
2383
- Zt as merge,
2384
- re as on,
2385
- Kt as previousSignal,
2386
- w as prop,
2387
- rs as render,
2388
- fe as renderWithContext,
2389
- f as renderableOfTNode,
2390
- os as restoreTempoPlaceholders,
2391
- ns as runHeadless,
2392
- Yt as sessionStorageProp,
2393
- te as signal,
2394
- es as slidingWindowSignal,
2395
- Ae as storedProp,
2396
- Rs as style,
2397
- ps as svg,
2398
- us as svgAttr
2583
+ Gt as localStorageProp,
2584
+ Vt as makeProbe,
2585
+ nt as makeProviderMark,
2586
+ ps as math,
2587
+ us as mathAttr,
2588
+ Qt as merge,
2589
+ se as on,
2590
+ Fe as popScope,
2591
+ zt as previousSignal,
2592
+ T as prop,
2593
+ qe as pushScope,
2594
+ ss as render,
2595
+ ae as renderWithContext,
2596
+ d as renderableOfTNode,
2597
+ is as restoreTempoPlaceholders,
2598
+ rs as runHeadless,
2599
+ _ as scopeStack,
2600
+ Ut as scoped,
2601
+ Xt as sessionStorageProp,
2602
+ K as signal,
2603
+ Kt as slidingWindowSignal,
2604
+ Se as storedProp,
2605
+ Ns as style,
2606
+ fs as svg,
2607
+ as as svgAttr,
2608
+ oe as untracked,
2609
+ L as withScope
2399
2610
  };