@solid-primitives/utils 7.0.0-next.0 → 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,366 +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);
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). */
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}`;
79
+ };
81
80
  /**
82
- * Accesses the value of a MaybeAccessor
83
- * @example
84
- * ```ts
85
- * access("foo") // => "foo"
86
- * access(() => "foo") // => "foo"
87
- * ```
88
- */
89
- 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;
90
89
  /**
91
- * Wraps `value` in a single-element array. If `value` is already an array it is
92
- * returned as-is. Falsy values (except `0` and `false`) produce an empty array.
93
- */
94
- 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] : [];
95
94
  /**
96
- * Access an array of MaybeAccessors
97
- * @example
98
- * const list = [1, 2, () => 3)] // T: MaybeAccessor<number>[]
99
- * const newList = accessArray(list) // T: number[]
100
- */
101
- 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));
102
101
  /**
103
- * Run the function if the accessed value is not `undefined` nor `null`
104
- * @param value
105
- * @param fn
106
- */
107
- export const withAccess = (value, fn) => {
108
- const _value = access(value);
109
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
110
- 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));
111
108
  };
112
109
  /**
113
- * Wraps a plain value in a zero-argument accessor `() => value`.
114
- * If `v` is already a function it is returned unchanged.
115
- */
116
- 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;
117
114
  /** If value is a function – call it with a given arguments – otherwise get the value as is */
118
- export function accessWith(valueOrFn, ...args) {
119
- return typeof valueOrFn === "function" ? valueOrFn(...args) : valueOrFn;
115
+ function accessWith(valueOrFn, ...args) {
116
+ return typeof valueOrFn === "function" ? valueOrFn(...args) : valueOrFn;
120
117
  }
121
- export function defer(deps, fn, initialValue) {
122
- const isArray = Array.isArray(deps);
123
- let prevInput;
124
- let shouldDefer = true;
125
- return ((prevValue) => {
126
- let input;
127
- if (isArray) {
128
- input = Array(deps.length);
129
- for (let i = 0; i < deps.length; i++)
130
- input[i] = deps[i]();
131
- }
132
- else
133
- input = deps();
134
- if (shouldDefer) {
135
- shouldDefer = false;
136
- prevInput = input;
137
- return initialValue;
138
- }
139
- const result = untrack(() => fn(input, prevInput, prevValue));
140
- prevInput = input;
141
- return result;
142
- });
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
+ });
143
137
  }
144
138
  /**
145
- * Get entries of an object
146
- */
147
- export const entries = Object.entries;
139
+ * Get entries of an object
140
+ */
141
+ const entries = Object.entries;
148
142
  /**
149
- * Get keys of an object
150
- */
151
- export const keys = Object.keys;
143
+ * Get keys of an object
144
+ */
145
+ const keys = Object.keys;
152
146
  /**
153
- * Solid's `onCleanup` that doesn't warn in development if used outside of a component.
154
- */
155
- export const tryOnCleanup = isDev
156
- ? fn => (getOwner() ? onCleanup(fn) : fn)
157
- : 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;
158
150
  /**
159
- * Creates a stack of callbacks that can be pushed to, executed all at once, or cleared.
160
- * All callbacks receive the same arguments when `execute` is called; the stack is
161
- * automatically cleared after execution.
162
- *
163
- * @example
164
- * ```ts
165
- * const stack = createCallbackStack<string>();
166
- * stack.push(s => console.log("a:", s));
167
- * stack.push(s => console.log("b:", s));
168
- * stack.execute("hello"); // logs "a: hello", "b: hello" — stack is now empty
169
- * ```
170
- */
171
- export const createCallbackStack = () => {
172
- let stack = [];
173
- const clear = () => (stack = []);
174
- return {
175
- push: (...callbacks) => stack.push(...callbacks),
176
- execute(arg0, arg1, arg2, arg3) {
177
- stack.forEach(cb => cb(arg0, arg1, arg2, arg3));
178
- clear();
179
- },
180
- clear,
181
- };
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
+ };
182
174
  };
183
175
  /**
184
- * Returns a debounced wrapper around `fn` that batches rapid synchronous calls
185
- * into a single invocation. Only the most-recently-passed arguments are forwarded.
186
- * The counter resets on cleanup so stale microtasks are silently discarded.
187
- *
188
- * @example
189
- * ```ts
190
- * const flush = createMicrotask((value: string) => console.log(value));
191
- * flush("a");
192
- * flush("b");
193
- * flush("c"); // only "c" is logged (in the next microtask)
194
- * ```
195
- */
196
- export function createMicrotask(fn) {
197
- let calls = 0;
198
- let args;
199
- onCleanup(() => (calls = 0));
200
- return (...a) => {
201
- (args = a), calls++;
202
- queueMicrotask(() => --calls === 0 && fn(...args));
203
- };
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
+ };
204
196
  }
205
197
  /**
206
- * 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.
207
- *
208
- * @param serverValue initial value of the state on the server
209
- * @param update called once on the client or on hydration to initialize the value
210
- * @param options {@link SignalOptions}
211
- * @returns
212
- * ```ts
213
- * [state: Accessor<T>, setState: Setter<T>]
214
- * ```
215
- * @see {@link createSignal}
216
- */
217
- export function createHydratableSignal(serverValue, update, options) {
218
- if (isServer) {
219
- return createSignal(serverValue, options);
220
- }
221
- if (sharedConfig.hydrating) {
222
- const [state, setState] = createSignal(serverValue, options);
223
- onSettled(() => {
224
- setState(() => update());
225
- });
226
- return [state, setState];
227
- }
228
- 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);
229
219
  }
230
220
  /** @deprecated use {@link createHydratableSignal} instead */
231
- export const createHydrateSignal = createHydratableSignal;
221
+ const createHydrateSignal = createHydratableSignal;
232
222
  /**
233
- * Diffs two arrays by reference and calls `handleAdded` / `handleRemoved` for
234
- * each item that appeared or disappeared. Items are compared with `===`.
235
- *
236
- * @param current - the new array
237
- * @param prev - the previous array snapshot
238
- * @param handleAdded - called once for each item present in `current` but not `prev`
239
- * @param handleRemoved - called once for each item present in `prev` but not `current`
240
- */
241
- export function handleDiffArray(current, prev, handleAdded, handleRemoved) {
242
- const currLength = current.length;
243
- const prevLength = prev.length;
244
- let i = 0;
245
- if (!prevLength) {
246
- for (; i < currLength; i++)
247
- handleAdded(current[i]);
248
- return;
249
- }
250
- if (!currLength) {
251
- for (; i < prevLength; i++)
252
- handleRemoved(prev[i]);
253
- return;
254
- }
255
- for (; i < prevLength; i++) {
256
- if (prev[i] !== current[i])
257
- break;
258
- }
259
- let prevEl;
260
- let currEl;
261
- prev = prev.slice(i);
262
- current = current.slice(i);
263
- for (prevEl of prev) {
264
- if (!current.includes(prevEl))
265
- handleRemoved(prevEl);
266
- }
267
- for (currEl of current) {
268
- if (!prev.includes(currEl))
269
- handleAdded(currEl);
270
- }
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);
271
250
  }
272
251
  /**
273
- * Schedules `fn` to run after the browser has painted by nesting two
274
- * requestAnimationFrame calls. No-op in non-browser environments.
275
- */
276
- export const afterPaint = (fn) => {
277
- if (typeof requestAnimationFrame === "function") {
278
- requestAnimationFrame(() => requestAnimationFrame(fn));
279
- }
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));
280
257
  };
281
- // ─── String transforms ────────────────────────────────────────────────────────
282
258
  /**
283
- * Parse a string as a single JSON value.
284
- *
285
- * ```ts
286
- * const { data } = createSSE<{ status: string }>(url, { transform: json });
287
- * ```
288
- */
289
- 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);
290
266
  /**
291
- * Parse a string as newline-delimited JSON (NDJSON / JSON Lines).
292
- *
293
- * Each non-empty line is parsed as a separate JSON value and returned as an array.
294
- *
295
- * ```ts
296
- * const { data } = createSSE<TickEvent[]>(url, { transform: ndjson });
297
- * // data() === [{ id: 1, type: "tick" }, { id: 2, type: "tick" }]
298
- * ```
299
- */
300
- export const ndjson = (raw) => raw
301
- .split("\n")
302
- .filter(line => line !== "")
303
- .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));
304
277
  /**
305
- * Split a string into individual lines, returning a `string[]`. Empty lines are filtered out.
306
- *
307
- * ```ts
308
- * const { data } = createSSE<string[]>(url, { transform: lines });
309
- * // data() === ["line one", "line two"]
310
- * ```
311
- */
312
- 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 !== "");
313
286
  /**
314
- * Parse a string as a number using `Number()` semantics.
315
- *
316
- * Note: `""` → `0`, non-numeric strings → `NaN`.
317
- *
318
- * ```ts
319
- * const { data } = createSSE<number>(url, { transform: number });
320
- * // data() === 42
321
- * ```
322
- */
323
- export const number = (raw) => Number(raw);
324
- export function safe(transform, fallback) {
325
- return (raw) => {
326
- try {
327
- return transform(raw);
328
- }
329
- catch {
330
- return fallback;
331
- }
332
- };
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
+ };
333
305
  }
334
306
  /**
335
- * Compose two transforms into one: the output of `a` is passed as the input of `b`.
336
- *
337
- * ```ts
338
- * const { data } = createSSE<RawEvent[]>(url, {
339
- * transform: pipe(ndjson<RawEvent>, rows => rows.filter(r => r.type === "tick")),
340
- * });
341
- * ```
342
- */
343
- export function pipe(a, b) {
344
- 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));
345
317
  }
346
- // ─── DOM helpers ─────────────────────────────────────────────────────────────
347
318
  /**
348
- * Check if a wrapper element contains a target element.
349
- * Portal-aware: follows SolidJS `_$host` links so elements rendered inside
350
- * a `<Portal>` are correctly treated as children of the portal's anchor.
351
- */
352
- export const contains = (wrapper, target) => {
353
- if (wrapper.contains(target))
354
- return true;
355
- let current = target;
356
- while (current) {
357
- if (current === wrapper)
358
- return true;
359
- // @ts-expect-error: _$host is a SolidJS-internal property set on portal roots
360
- current = current._$host ?? current.parentElement;
361
- }
362
- 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;
363
331
  };
364
- export function wrapSetter(signalOrStore, wrapper) {
365
- 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
+ ];
366
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 };