@solid-primitives/utils 7.0.0-next.1 → 7.0.0-next.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,372 +1,340 @@
1
- import { getOwner, onSettled, onCleanup, createSignal, untrack, sharedConfig, DEV, } from "solid-js";
2
- // isServer moved from solid-js/web (1.x) to @solidjs/web (2.x).
3
- // typeof window is a universal fallback compatible with both versions.
1
+ /* @ts-self-types="./index.d.ts" */
2
+ import { DEV, createSignal, getOwner, onCleanup, onSettled, sharedConfig, untrack } from "solid-js";
3
+ //#region src/index.ts
4
4
  const isServer = typeof window === "undefined";
5
- export * from "./types.js";
6
- //
7
- // GENERAL HELPERS:
8
- //
9
- /** `true` on the server (SSR), `false` in the browser. */
10
- export { isServer };
11
5
  /** `true` in the browser, `false` on the server. */
12
- export const isClient = !isServer;
6
+ const isClient = !isServer;
13
7
  /** `true` in the browser with Solid's DEV mode active. */
14
- export const isDev = isClient && !!DEV;
8
+ const isDev = isClient && !!DEV;
15
9
  /** `true` when DEV mode is off (i.e. production browser builds and all SSR). */
16
- export const isProd = !isDev;
10
+ const isProd = !isDev;
17
11
  /** No-operation function — accepts any arguments and returns `undefined`. */
18
- export const noop = (() => void 0);
12
+ const noop = (() => void 0);
19
13
  /** A function that always returns `true`. Useful as a default predicate prop. */
20
- export const trueFn = () => true;
14
+ const trueFn = () => true;
21
15
  /** A function that always returns `false`. Useful as a default predicate prop. */
22
- export const falseFn = () => false;
16
+ const falseFn = () => false;
23
17
  /** @deprecated use {@link equalFn} from "solid-js" */
24
- export const defaultEquals = Object.is.bind(Object);
18
+ const defaultEquals = Object.is.bind(Object);
25
19
  /**
26
- * Signal options that disable equality checking, causing the signal to always
27
- * notify subscribers even when the value hasn't changed. Useful for signals
28
- * holding mutable objects where structural equality cannot be assumed.
29
- */
30
- export const EQUALS_FALSE_OPTIONS = { equals: false };
20
+ * Signal options that disable equality checking, causing the signal to always
21
+ * notify subscribers even when the value hasn't changed. Useful for signals
22
+ * holding mutable objects where structural equality cannot be assumed.
23
+ */
24
+ const EQUALS_FALSE_OPTIONS = { equals: false };
31
25
  /**
32
- * Signal options that allow writes from inside an owned reactive scope
33
- * (component body, memo, or effect) without throwing `SIGNAL_WRITE_IN_OWNED_SCOPE`
34
- * in Solid 2.0 dev mode.
35
- *
36
- * Use only for implementation-detail signals that genuinely need to be written
37
- * from within a scope — not as a general escape hatch.
38
- */
39
- export const INTERNAL_OPTIONS = { ownedWrite: true };
26
+ * Signal options that allow writes from inside an owned reactive scope
27
+ * (component body, memo, or effect) without throwing `SIGNAL_WRITE_IN_OWNED_SCOPE`
28
+ * in Solid 2.0 dev mode.
29
+ *
30
+ * Use only for implementation-detail signals that genuinely need to be written
31
+ * from within a scope — not as a general escape hatch.
32
+ */
33
+ const INTERNAL_OPTIONS = { ownedWrite: true };
40
34
  /**
41
- * Returns `true` if `v` is an instance of `c`. Checks both `instanceof` and
42
- * `constructor` so that values created across different realms (e.g. iframes) match.
43
- */
44
- export const ofClass = (v, c) => v instanceof c || (v && v.constructor === c);
35
+ * Returns `true` if `v` is an instance of `c`. Checks both `instanceof` and
36
+ * `constructor` so that values created across different realms (e.g. iframes) match.
37
+ */
38
+ const ofClass = (v, c) => v instanceof c || v && v.constructor === c;
45
39
  /** Check if value is typeof "object" or "function" */
46
- export function isObject(value) {
47
- return value !== null && (typeof value === "object" || typeof value === "function");
40
+ function isObject(value) {
41
+ return value !== null && (typeof value === "object" || typeof value === "function");
48
42
  }
49
43
  /** Type guard: returns `true` when `i` is neither `null` nor `undefined`. */
50
- export const isNonNullable = (i) => i != null;
44
+ const isNonNullable = (i) => i != null;
51
45
  /** Returns a new array with all `null` and `undefined` items removed. */
52
- export const filterNonNullable = (arr) => arr.filter(isNonNullable);
46
+ const filterNonNullable = (arr) => arr.filter(isNonNullable);
53
47
  /** Three-way comparison: returns `-1` if `a < b`, `1` if `a > b`, `0` if equal. */
54
- export const compare = (a, b) => (a < b ? -1 : a > b ? 1 : 0);
48
+ const compare = (a, b) => a < b ? -1 : a > b ? 1 : 0;
55
49
  /**
56
- * Check shallow array equality
57
- */
58
- export const arrayEquals = (a, b) => a === b || (a.length === b.length && a.every((e, i) => e === b[i]));
50
+ * Check shallow array equality
51
+ */
52
+ const arrayEquals = (a, b) => a === b || a.length === b.length && a.every((e, i) => e === b[i]);
59
53
  /**
60
- * Returns a function that will call all functions in the order they were chained with the same arguments.
61
- */
62
- export function chain(callbacks) {
63
- return (...args) => {
64
- for (const callback of callbacks)
65
- callback && callback(...args);
66
- };
54
+ * Returns a function that will call all functions in the order they were chained with the same arguments.
55
+ */
56
+ function chain(callbacks) {
57
+ return (...args) => {
58
+ for (const callback of callbacks) callback && callback(...args);
59
+ };
67
60
  }
68
61
  /**
69
- * Returns a function that will call all functions in the reversed order with the same arguments.
70
- */
71
- export function reverseChain(callbacks) {
72
- return (...args) => {
73
- for (let i = callbacks.length - 1; i >= 0; i--) {
74
- const callback = callbacks[i];
75
- callback && callback(...args);
76
- }
77
- };
62
+ * Returns a function that will call all functions in the reversed order with the same arguments.
63
+ */
64
+ function reverseChain(callbacks) {
65
+ return (...args) => {
66
+ for (let i = callbacks.length - 1; i >= 0; i--) {
67
+ const callback = callbacks[i];
68
+ callback && callback(...args);
69
+ }
70
+ };
78
71
  }
79
72
  /** Clamps `n` to the inclusive range `[min, max]`. */
80
- export const clamp = (n, min, max) => Math.min(Math.max(n, min), max);
73
+ const clamp = (n, min, max) => Math.min(Math.max(n, min), max);
81
74
  /** Creates an ID generator with its own isolated counter and per-generator random segment. Each call to the returned function produces a `timestamp-sequence-random` string that is unique within the generator and with high probability unique across independent generators (e.g. separate processes or SSR requests). */
82
- export const createIdGenerator = () => {
83
- let seq = 0;
84
- const rand = Math.random().toString(36).slice(2, 8);
85
- return () => `${Date.now().toString(36)}-${(++seq).toString(36)}-${rand}`;
75
+ const createIdGenerator = () => {
76
+ let seq = 0;
77
+ const rand = Math.random().toString(36).slice(2, 8);
78
+ return () => `${Date.now().toString(36)}-${(++seq).toString(36)}-${rand}`;
86
79
  };
87
80
  /**
88
- * Accesses the value of a MaybeAccessor
89
- * @example
90
- * ```ts
91
- * access("foo") // => "foo"
92
- * access(() => "foo") // => "foo"
93
- * ```
94
- */
95
- export const access = (v) => typeof v === "function" && !v.length ? v() : v;
81
+ * Accesses the value of a MaybeAccessor
82
+ * @example
83
+ * ```ts
84
+ * access("foo") // => "foo"
85
+ * access(() => "foo") // => "foo"
86
+ * ```
87
+ */
88
+ const access = (v) => typeof v === "function" && !v.length ? v() : v;
96
89
  /**
97
- * Wraps `value` in a single-element array. If `value` is already an array it is
98
- * returned as-is. Falsy values (except `0` and `false`) produce an empty array.
99
- */
100
- export const asArray = (value) => Array.isArray(value) ? value : value ? [value] : [];
90
+ * Wraps `value` in a single-element array. If `value` is already an array it is
91
+ * returned as-is. Falsy values (except `0` and `false`) produce an empty array.
92
+ */
93
+ const asArray = (value) => Array.isArray(value) ? value : value ? [value] : [];
101
94
  /**
102
- * Access an array of MaybeAccessors
103
- * @example
104
- * const list = [1, 2, () => 3)] // T: MaybeAccessor<number>[]
105
- * const newList = accessArray(list) // T: number[]
106
- */
107
- export const accessArray = (list) => list.map(v => access(v));
95
+ * Access an array of MaybeAccessors
96
+ * @example
97
+ * const list = [1, 2, () => 3)] // T: MaybeAccessor<number>[]
98
+ * const newList = accessArray(list) // T: number[]
99
+ */
100
+ const accessArray = (list) => list.map((v) => access(v));
108
101
  /**
109
- * Run the function if the accessed value is not `undefined` nor `null`
110
- * @param value
111
- * @param fn
112
- */
113
- export const withAccess = (value, fn) => {
114
- const _value = access(value);
115
- // oxlint-disable-next-line @typescript-eslint/no-unnecessary-condition
116
- typeof _value != null && fn(_value);
102
+ * Run the function if the accessed value is not `undefined` nor `null`
103
+ * @param value
104
+ * @param fn
105
+ */
106
+ const withAccess = (value, fn) => {
107
+ fn(access(value));
117
108
  };
118
109
  /**
119
- * Wraps a plain value in a zero-argument accessor `() => value`.
120
- * If `v` is already a function it is returned unchanged.
121
- */
122
- export const asAccessor = (v) => (typeof v === "function" ? v : () => v);
110
+ * Wraps a plain value in a zero-argument accessor `() => value`.
111
+ * If `v` is already a function it is returned unchanged.
112
+ */
113
+ const asAccessor = (v) => typeof v === "function" ? v : () => v;
123
114
  /** If value is a function – call it with a given arguments – otherwise get the value as is */
124
- export function accessWith(valueOrFn, ...args) {
125
- return typeof valueOrFn === "function" ? valueOrFn(...args) : valueOrFn;
115
+ function accessWith(valueOrFn, ...args) {
116
+ return typeof valueOrFn === "function" ? valueOrFn(...args) : valueOrFn;
126
117
  }
127
- export function defer(deps, fn, initialValue) {
128
- const isArray = Array.isArray(deps);
129
- let prevInput;
130
- let shouldDefer = true;
131
- return ((prevValue) => {
132
- let input;
133
- if (isArray) {
134
- input = Array(deps.length);
135
- for (let i = 0; i < deps.length; i++)
136
- input[i] = deps[i]();
137
- }
138
- else
139
- input = deps();
140
- if (shouldDefer) {
141
- shouldDefer = false;
142
- prevInput = input;
143
- return initialValue;
144
- }
145
- const result = untrack(() => fn(input, prevInput, prevValue));
146
- prevInput = input;
147
- return result;
148
- });
118
+ function defer(deps, fn, initialValue) {
119
+ const isArray = Array.isArray(deps);
120
+ let prevInput;
121
+ let shouldDefer = true;
122
+ return ((prevValue) => {
123
+ let input;
124
+ if (isArray) {
125
+ input = Array(deps.length);
126
+ for (let i = 0; i < deps.length; i++) input[i] = deps[i]();
127
+ } else input = deps();
128
+ if (shouldDefer) {
129
+ shouldDefer = false;
130
+ prevInput = input;
131
+ return initialValue;
132
+ }
133
+ const result = untrack(() => fn(input, prevInput, prevValue));
134
+ prevInput = input;
135
+ return result;
136
+ });
149
137
  }
150
138
  /**
151
- * Get entries of an object
152
- */
153
- export const entries = Object.entries;
139
+ * Get entries of an object
140
+ */
141
+ const entries = Object.entries;
154
142
  /**
155
- * Get keys of an object
156
- */
157
- export const keys = Object.keys;
143
+ * Get keys of an object
144
+ */
145
+ const keys = Object.keys;
158
146
  /**
159
- * Solid's `onCleanup` that doesn't warn in development if used outside of a component.
160
- */
161
- export const tryOnCleanup = isDev
162
- ? fn => (getOwner() ? onCleanup(fn) : fn)
163
- : onCleanup;
147
+ * Solid's `onCleanup` that doesn't warn in development if used outside of a component.
148
+ */
149
+ const tryOnCleanup = isDev ? (fn) => getOwner() ? onCleanup(fn) : fn : onCleanup;
164
150
  /**
165
- * Creates a stack of callbacks that can be pushed to, executed all at once, or cleared.
166
- * All callbacks receive the same arguments when `execute` is called; the stack is
167
- * automatically cleared after execution.
168
- *
169
- * @example
170
- * ```ts
171
- * const stack = createCallbackStack<string>();
172
- * stack.push(s => console.log("a:", s));
173
- * stack.push(s => console.log("b:", s));
174
- * stack.execute("hello"); // logs "a: hello", "b: hello" — stack is now empty
175
- * ```
176
- */
177
- export const createCallbackStack = () => {
178
- let stack = [];
179
- const clear = () => (stack = []);
180
- return {
181
- push: (...callbacks) => stack.push(...callbacks),
182
- execute(arg0, arg1, arg2, arg3) {
183
- stack.forEach(cb => cb(arg0, arg1, arg2, arg3));
184
- clear();
185
- },
186
- clear,
187
- };
151
+ * Creates a stack of callbacks that can be pushed to, executed all at once, or cleared.
152
+ * All callbacks receive the same arguments when `execute` is called; the stack is
153
+ * automatically cleared after execution.
154
+ *
155
+ * @example
156
+ * ```ts
157
+ * const stack = createCallbackStack<string>();
158
+ * stack.push(s => console.log("a:", s));
159
+ * stack.push(s => console.log("b:", s));
160
+ * stack.execute("hello"); // logs "a: hello", "b: hello" — stack is now empty
161
+ * ```
162
+ */
163
+ const createCallbackStack = () => {
164
+ let stack = [];
165
+ const clear = () => stack = [];
166
+ return {
167
+ push: (...callbacks) => stack.push(...callbacks),
168
+ execute(arg0, arg1, arg2, arg3) {
169
+ stack.forEach((cb) => cb(arg0, arg1, arg2, arg3));
170
+ clear();
171
+ },
172
+ clear
173
+ };
188
174
  };
189
175
  /**
190
- * Returns a debounced wrapper around `fn` that batches rapid synchronous calls
191
- * into a single invocation. Only the most-recently-passed arguments are forwarded.
192
- * The counter resets on cleanup so stale microtasks are silently discarded.
193
- *
194
- * @example
195
- * ```ts
196
- * const flush = createMicrotask((value: string) => console.log(value));
197
- * flush("a");
198
- * flush("b");
199
- * flush("c"); // only "c" is logged (in the next microtask)
200
- * ```
201
- */
202
- export function createMicrotask(fn) {
203
- let calls = 0;
204
- let args;
205
- onCleanup(() => (calls = 0));
206
- return (...a) => {
207
- (args = a), calls++;
208
- queueMicrotask(() => --calls === 0 && fn(...args));
209
- };
176
+ * Returns a debounced wrapper around `fn` that batches rapid synchronous calls
177
+ * into a single invocation. Only the most-recently-passed arguments are forwarded.
178
+ * The counter resets on cleanup so stale microtasks are silently discarded.
179
+ *
180
+ * @example
181
+ * ```ts
182
+ * const flush = createMicrotask((value: string) => console.log(value));
183
+ * flush("a");
184
+ * flush("b");
185
+ * flush("c"); // only "c" is logged (in the next microtask)
186
+ * ```
187
+ */
188
+ function createMicrotask(fn) {
189
+ let calls = 0;
190
+ let args;
191
+ onCleanup(() => calls = 0);
192
+ return (...a) => {
193
+ args = a, calls++;
194
+ queueMicrotask(() => --calls === 0 && fn(...args));
195
+ };
210
196
  }
211
197
  /**
212
- * A hydratable version of the {@link createSignal}. It will use the serverValue on the server and the update function on the client. If initialized during hydration it will use serverValue as the initial value and update it once hydration is complete.
213
- *
214
- * @param serverValue initial value of the state on the server
215
- * @param update called once on the client or on hydration to initialize the value
216
- * @param options {@link SignalOptions}
217
- * @returns
218
- * ```ts
219
- * [state: Accessor<T>, setState: Setter<T>]
220
- * ```
221
- * @see {@link createSignal}
222
- */
223
- export function createHydratableSignal(serverValue, update, options) {
224
- if (isServer) {
225
- return createSignal(serverValue, options);
226
- }
227
- if (sharedConfig.hydrating) {
228
- const [state, setState] = createSignal(serverValue, options);
229
- onSettled(() => {
230
- setState(() => update());
231
- });
232
- return [state, setState];
233
- }
234
- return createSignal(update(), options);
198
+ * A hydratable version of the {@link createSignal}. It will use the serverValue on the server and the update function on the client. If initialized during hydration it will use serverValue as the initial value and update it once hydration is complete.
199
+ *
200
+ * @param serverValue initial value of the state on the server
201
+ * @param update called once on the client or on hydration to initialize the value
202
+ * @param options {@link SignalOptions}
203
+ * @returns
204
+ * ```ts
205
+ * [state: Accessor<T>, setState: Setter<T>]
206
+ * ```
207
+ * @see {@link createSignal}
208
+ */
209
+ function createHydratableSignal(serverValue, update, options) {
210
+ if (isServer) return createSignal(serverValue, options);
211
+ if (sharedConfig.hydrating) {
212
+ const [state, setState] = createSignal(serverValue, options);
213
+ onSettled(() => {
214
+ setState(() => update());
215
+ });
216
+ return [state, setState];
217
+ }
218
+ return createSignal(update(), options);
235
219
  }
236
220
  /** @deprecated use {@link createHydratableSignal} instead */
237
- export const createHydrateSignal = createHydratableSignal;
221
+ const createHydrateSignal = createHydratableSignal;
238
222
  /**
239
- * Diffs two arrays by reference and calls `handleAdded` / `handleRemoved` for
240
- * each item that appeared or disappeared. Items are compared with `===`.
241
- *
242
- * @param current - the new array
243
- * @param prev - the previous array snapshot
244
- * @param handleAdded - called once for each item present in `current` but not `prev`
245
- * @param handleRemoved - called once for each item present in `prev` but not `current`
246
- */
247
- export function handleDiffArray(current, prev, handleAdded, handleRemoved) {
248
- const currLength = current.length;
249
- const prevLength = prev.length;
250
- let i = 0;
251
- if (!prevLength) {
252
- for (; i < currLength; i++)
253
- handleAdded(current[i]);
254
- return;
255
- }
256
- if (!currLength) {
257
- for (; i < prevLength; i++)
258
- handleRemoved(prev[i]);
259
- return;
260
- }
261
- for (; i < prevLength; i++) {
262
- if (prev[i] !== current[i])
263
- break;
264
- }
265
- let prevEl;
266
- let currEl;
267
- prev = prev.slice(i);
268
- current = current.slice(i);
269
- for (prevEl of prev) {
270
- if (!current.includes(prevEl))
271
- handleRemoved(prevEl);
272
- }
273
- for (currEl of current) {
274
- if (!prev.includes(currEl))
275
- handleAdded(currEl);
276
- }
223
+ * Diffs two arrays by reference and calls `handleAdded` / `handleRemoved` for
224
+ * each item that appeared or disappeared. Items are compared with `===`.
225
+ *
226
+ * @param current - the new array
227
+ * @param prev - the previous array snapshot
228
+ * @param handleAdded - called once for each item present in `current` but not `prev`
229
+ * @param handleRemoved - called once for each item present in `prev` but not `current`
230
+ */
231
+ function handleDiffArray(current, prev, handleAdded, handleRemoved) {
232
+ const currLength = current.length;
233
+ const prevLength = prev.length;
234
+ let i = 0;
235
+ if (!prevLength) {
236
+ for (; i < currLength; i++) handleAdded(current[i]);
237
+ return;
238
+ }
239
+ if (!currLength) {
240
+ for (; i < prevLength; i++) handleRemoved(prev[i]);
241
+ return;
242
+ }
243
+ for (; i < prevLength; i++) if (prev[i] !== current[i]) break;
244
+ let prevEl;
245
+ let currEl;
246
+ prev = prev.slice(i);
247
+ current = current.slice(i);
248
+ for (prevEl of prev) if (!current.includes(prevEl)) handleRemoved(prevEl);
249
+ for (currEl of current) if (!prev.includes(currEl)) handleAdded(currEl);
277
250
  }
278
251
  /**
279
- * Schedules `fn` to run after the browser has painted by nesting two
280
- * requestAnimationFrame calls. No-op in non-browser environments.
281
- */
282
- export const afterPaint = (fn) => {
283
- if (typeof requestAnimationFrame === "function") {
284
- requestAnimationFrame(() => requestAnimationFrame(fn));
285
- }
252
+ * Schedules `fn` to run after the browser has painted by nesting two
253
+ * requestAnimationFrame calls. No-op in non-browser environments.
254
+ */
255
+ const afterPaint = (fn) => {
256
+ if (typeof requestAnimationFrame === "function") requestAnimationFrame(() => requestAnimationFrame(fn));
286
257
  };
287
- // ─── String transforms ────────────────────────────────────────────────────────
288
258
  /**
289
- * Parse a string as a single JSON value.
290
- *
291
- * ```ts
292
- * const { data } = createSSE<{ status: string }>(url, { transform: json });
293
- * ```
294
- */
295
- export const json = (raw) => JSON.parse(raw);
259
+ * Parse a string as a single JSON value.
260
+ *
261
+ * ```ts
262
+ * const { data } = createSSE<{ status: string }>(url, { transform: json });
263
+ * ```
264
+ */
265
+ const json = (raw) => JSON.parse(raw);
296
266
  /**
297
- * Parse a string as newline-delimited JSON (NDJSON / JSON Lines).
298
- *
299
- * Each non-empty line is parsed as a separate JSON value and returned as an array.
300
- *
301
- * ```ts
302
- * const { data } = createSSE<TickEvent[]>(url, { transform: ndjson });
303
- * // data() === [{ id: 1, type: "tick" }, { id: 2, type: "tick" }]
304
- * ```
305
- */
306
- export const ndjson = (raw) => raw
307
- .split("\n")
308
- .filter(line => line !== "")
309
- .map(line => JSON.parse(line));
267
+ * Parse a string as newline-delimited JSON (NDJSON / JSON Lines).
268
+ *
269
+ * Each non-empty line is parsed as a separate JSON value and returned as an array.
270
+ *
271
+ * ```ts
272
+ * const { data } = createSSE<TickEvent[]>(url, { transform: ndjson });
273
+ * // data() === [{ id: 1, type: "tick" }, { id: 2, type: "tick" }]
274
+ * ```
275
+ */
276
+ const ndjson = (raw) => raw.split("\n").filter((line) => line !== "").map((line) => JSON.parse(line));
310
277
  /**
311
- * Split a string into individual lines, returning a `string[]`. Empty lines are filtered out.
312
- *
313
- * ```ts
314
- * const { data } = createSSE<string[]>(url, { transform: lines });
315
- * // data() === ["line one", "line two"]
316
- * ```
317
- */
318
- export const lines = (raw) => raw.split("\n").filter(line => line !== "");
278
+ * Split a string into individual lines, returning a `string[]`. Empty lines are filtered out.
279
+ *
280
+ * ```ts
281
+ * const { data } = createSSE<string[]>(url, { transform: lines });
282
+ * // data() === ["line one", "line two"]
283
+ * ```
284
+ */
285
+ const lines = (raw) => raw.split("\n").filter((line) => line !== "");
319
286
  /**
320
- * Parse a string as a number using `Number()` semantics.
321
- *
322
- * Note: `""` → `0`, non-numeric strings → `NaN`.
323
- *
324
- * ```ts
325
- * const { data } = createSSE<number>(url, { transform: number });
326
- * // data() === 42
327
- * ```
328
- */
329
- export const number = (raw) => Number(raw);
330
- export function safe(transform, fallback) {
331
- return (raw) => {
332
- try {
333
- return transform(raw);
334
- }
335
- catch {
336
- return fallback;
337
- }
338
- };
287
+ * Parse a string as a number using `Number()` semantics.
288
+ *
289
+ * Note: `""` → `0`, non-numeric strings → `NaN`.
290
+ *
291
+ * ```ts
292
+ * const { data } = createSSE<number>(url, { transform: number });
293
+ * // data() === 42
294
+ * ```
295
+ */
296
+ const number = (raw) => Number(raw);
297
+ function safe(transform, fallback) {
298
+ return (raw) => {
299
+ try {
300
+ return transform(raw);
301
+ } catch {
302
+ return fallback;
303
+ }
304
+ };
339
305
  }
340
306
  /**
341
- * Compose two transforms into one: the output of `a` is passed as the input of `b`.
342
- *
343
- * ```ts
344
- * const { data } = createSSE<RawEvent[]>(url, {
345
- * transform: pipe(ndjson<RawEvent>, rows => rows.filter(r => r.type === "tick")),
346
- * });
347
- * ```
348
- */
349
- export function pipe(a, b) {
350
- return (raw) => b(a(raw));
307
+ * Compose two transforms into one: the output of `a` is passed as the input of `b`.
308
+ *
309
+ * ```ts
310
+ * const { data } = createSSE<RawEvent[]>(url, {
311
+ * transform: pipe(ndjson<RawEvent>, rows => rows.filter(r => r.type === "tick")),
312
+ * });
313
+ * ```
314
+ */
315
+ function pipe(a, b) {
316
+ return (raw) => b(a(raw));
351
317
  }
352
- // ─── DOM helpers ─────────────────────────────────────────────────────────────
353
318
  /**
354
- * Check if a wrapper element contains a target element.
355
- * Portal-aware: follows SolidJS `_$host` links so elements rendered inside
356
- * a `<Portal>` are correctly treated as children of the portal's anchor.
357
- */
358
- export const contains = (wrapper, target) => {
359
- if (wrapper.contains(target))
360
- return true;
361
- let current = target;
362
- while (current) {
363
- if (current === wrapper)
364
- return true;
365
- // @ts-expect-error: _$host is a SolidJS-internal property set on portal roots
366
- current = current._$host ?? current.parentElement;
367
- }
368
- return false;
319
+ * Check if a wrapper element contains a target element.
320
+ * Portal-aware: follows SolidJS `_$host` links so elements rendered inside
321
+ * a `<Portal>` are correctly treated as children of the portal's anchor.
322
+ */
323
+ const contains = (wrapper, target) => {
324
+ if (wrapper.contains(target)) return true;
325
+ let current = target;
326
+ while (current) {
327
+ if (current === wrapper) return true;
328
+ current = current._$host ?? current.parentElement;
329
+ }
330
+ return false;
369
331
  };
370
- export function wrapSetter(signalOrStore, wrapper) {
371
- return [signalOrStore[0], wrapper(signalOrStore[1]), ...signalOrStore.slice(2)];
332
+ function wrapSetter(signalOrStore, wrapper) {
333
+ return [
334
+ signalOrStore[0],
335
+ wrapper(signalOrStore[1]),
336
+ ...signalOrStore.slice(2)
337
+ ];
372
338
  }
339
+ //#endregion
340
+ export { EQUALS_FALSE_OPTIONS, INTERNAL_OPTIONS, access, accessArray, accessWith, afterPaint, arrayEquals, asAccessor, asArray, chain, clamp, compare, contains, createCallbackStack, createHydratableSignal, createHydrateSignal, createIdGenerator, createMicrotask, defaultEquals, defer, entries, falseFn, filterNonNullable, handleDiffArray, isClient, isDev, isNonNullable, isObject, isProd, isServer, json, keys, lines, ndjson, noop, number, ofClass, pipe, reverseChain, safe, trueFn, tryOnCleanup, withAccess, wrapSetter };