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

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.d.ts CHANGED
@@ -1,31 +1,54 @@
1
- import { onCleanup, createSignal, type Accessor, type AccessorArray, type EffectFunction, type NoInfer, type SignalOptions } from "solid-js";
2
- import { isServer } from "solid-js/web";
3
- import type { AnyClass, MaybeAccessor, MaybeAccessorValue, Noop, AnyObject, AnyFunction } from "./types.js";
1
+ import { onCleanup, createSignal, type Accessor, type ComputeFunction, type NoInfer, type Setter, type SignalOptions, type Signal, type Store, type StoreSetter } from "solid-js";
2
+ declare const isServer: boolean;
3
+ import type { AccessorArray, AnyClass, MaybeAccessor, MaybeAccessorValue, Noop, AnyObject, AnyFunction } from "./types.js";
4
4
  export * from "./types.js";
5
+ /** `true` on the server (SSR), `false` in the browser. */
5
6
  export { isServer };
7
+ /** `true` in the browser, `false` on the server. */
6
8
  export declare const isClient: boolean;
9
+ /** `true` in the browser with Solid's DEV mode active. */
7
10
  export declare const isDev: boolean;
11
+ /** `true` when DEV mode is off (i.e. production browser builds and all SSR). */
8
12
  export declare const isProd: boolean;
9
- /** no operation */
13
+ /** No-operation function — accepts any arguments and returns `undefined`. */
10
14
  export declare const noop: Noop;
15
+ /** A function that always returns `true`. Useful as a default predicate prop. */
11
16
  export declare const trueFn: () => boolean;
17
+ /** A function that always returns `false`. Useful as a default predicate prop. */
12
18
  export declare const falseFn: () => boolean;
13
19
  /** @deprecated use {@link equalFn} from "solid-js" */
14
- export declare const defaultEquals: <T>(a: T, b: T) => boolean;
20
+ export declare const defaultEquals: (value1: any, value2: any) => boolean;
21
+ /**
22
+ * Signal options that disable equality checking, causing the signal to always
23
+ * notify subscribers even when the value hasn't changed. Useful for signals
24
+ * holding mutable objects where structural equality cannot be assumed.
25
+ */
15
26
  export declare const EQUALS_FALSE_OPTIONS: {
16
27
  readonly equals: false;
17
28
  };
29
+ /**
30
+ * Signal options that allow writes from inside an owned reactive scope
31
+ * (component body, memo, or effect) without throwing `SIGNAL_WRITE_IN_OWNED_SCOPE`
32
+ * in Solid 2.0 dev mode.
33
+ *
34
+ * Use only for implementation-detail signals that genuinely need to be written
35
+ * from within a scope — not as a general escape hatch.
36
+ */
18
37
  export declare const INTERNAL_OPTIONS: {
19
- readonly internal: true;
38
+ readonly ownedWrite: true;
20
39
  };
21
40
  /**
22
- * Check if the value is an instance of ___
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.
23
43
  */
24
44
  export declare const ofClass: (v: any, c: AnyClass) => boolean;
25
45
  /** Check if value is typeof "object" or "function" */
26
46
  export declare function isObject(value: any): value is AnyObject;
47
+ /** Type guard: returns `true` when `i` is neither `null` nor `undefined`. */
27
48
  export declare const isNonNullable: <T>(i: T) => i is NonNullable<T>;
49
+ /** Returns a new array with all `null` and `undefined` items removed. */
28
50
  export declare const filterNonNullable: <T extends readonly unknown[]>(arr: T) => NonNullable<T[number]>[];
51
+ /** Three-way comparison: returns `-1` if `a < b`, `1` if `a > b`, `0` if equal. */
29
52
  export declare const compare: (a: any, b: any) => number;
30
53
  /**
31
54
  * Check shallow array equality
@@ -41,7 +64,10 @@ export declare function chain<Args extends [] | any[]>(callbacks: {
41
64
  * Returns a function that will call all functions in the reversed order with the same arguments.
42
65
  */
43
66
  export declare function reverseChain<Args extends [] | any[]>(callbacks: (((...args: Args) => any) | undefined)[]): (...args: Args) => void;
67
+ /** Clamps `n` to the inclusive range `[min, max]`. */
44
68
  export declare const clamp: (n: number, min: number, max: number) => number;
69
+ /** 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). */
70
+ export declare const createIdGenerator: () => (() => string);
45
71
  /**
46
72
  * Accesses the value of a MaybeAccessor
47
73
  * @example
@@ -51,6 +77,10 @@ export declare const clamp: (n: number, min: number, max: number) => number;
51
77
  * ```
52
78
  */
53
79
  export declare const access: <T extends MaybeAccessor<any>>(v: T) => MaybeAccessorValue<T>;
80
+ /**
81
+ * Wraps `value` in a single-element array. If `value` is already an array it is
82
+ * returned as-is. Falsy values (except `0` and `false`) produce an empty array.
83
+ */
54
84
  export declare const asArray: <T>(value: T) => (T extends any[] ? T[number] : NonNullable<T>)[];
55
85
  /**
56
86
  * Access an array of MaybeAccessors
@@ -65,18 +95,25 @@ export declare const accessArray: <A extends MaybeAccessor<any>>(list: readonly
65
95
  * @param fn
66
96
  */
67
97
  export declare const withAccess: <T, A extends MaybeAccessor<T>, V = MaybeAccessorValue<A>>(value: A, fn: (value: NonNullable<V>) => void) => void;
98
+ /**
99
+ * Wraps a plain value in a zero-argument accessor `() => value`.
100
+ * If `v` is already a function it is returned unchanged.
101
+ */
68
102
  export declare const asAccessor: <A extends MaybeAccessor<unknown>>(v: A) => Accessor<MaybeAccessorValue<A>>;
69
103
  /** If value is a function – call it with a given arguments – otherwise get the value as is */
70
104
  export declare function accessWith<T>(valueOrFn: T, ...args: T extends AnyFunction ? Parameters<T> : never): T extends AnyFunction ? ReturnType<T> : T;
71
105
  /**
72
- * Solid's `on` helper, but always defers and returns a provided initial value when if does instead of `undefined`.
106
+ * A deferred effect compute function. Skips the first reactive run and returns
107
+ * `initialValue` instead, then calls `fn` on subsequent dependency changes.
108
+ * Useful as the compute phase of `createEffect(defer(...), apply)` when the
109
+ * initial run should be suppressed.
73
110
  *
74
- * @param deps
75
- * @param fn
76
- * @param initialValue
111
+ * @param deps - a single accessor or an array of accessors to track
112
+ * @param fn - called with the current input, previous input, and previous return value
113
+ * @param initialValue - returned on the skipped first run (defaults to `undefined`)
77
114
  */
78
- export declare function defer<S, Next extends Prev, Prev = Next>(deps: AccessorArray<S> | Accessor<S>, fn: (input: S, prevInput: S, prev: undefined | NoInfer<Prev>) => Next, initialValue: Next): EffectFunction<undefined | NoInfer<Next>, NoInfer<Next>>;
79
- export declare function defer<S, Next extends Prev, Prev = Next>(deps: AccessorArray<S> | Accessor<S>, fn: (input: S, prevInput: S, prev: undefined | NoInfer<Prev>) => Next, initialValue?: undefined): EffectFunction<undefined | NoInfer<Next>>;
115
+ export declare function defer<S, Next extends Prev, Prev = Next>(deps: AccessorArray<S> | Accessor<S>, fn: (input: S, prevInput: S, prev: undefined | NoInfer<Prev>) => Next, initialValue: Next): ComputeFunction<undefined | NoInfer<Next>, NoInfer<Next>>;
116
+ export declare function defer<S, Next extends Prev, Prev = Next>(deps: AccessorArray<S> | Accessor<S>, fn: (input: S, prevInput: S, prev: undefined | NoInfer<Prev>) => Next, initialValue?: undefined): ComputeFunction<undefined | NoInfer<Next>>;
80
117
  /**
81
118
  * Get entries of an object
82
119
  */
@@ -89,15 +126,36 @@ export declare const keys: <T extends object>(object: T) => (keyof T)[];
89
126
  * Solid's `onCleanup` that doesn't warn in development if used outside of a component.
90
127
  */
91
128
  export declare const tryOnCleanup: typeof onCleanup;
129
+ /**
130
+ * Creates a stack of callbacks that can be pushed to, executed all at once, or cleared.
131
+ * All callbacks receive the same arguments when `execute` is called; the stack is
132
+ * automatically cleared after execution.
133
+ *
134
+ * @example
135
+ * ```ts
136
+ * const stack = createCallbackStack<string>();
137
+ * stack.push(s => console.log("a:", s));
138
+ * stack.push(s => console.log("b:", s));
139
+ * stack.execute("hello"); // logs "a: hello", "b: hello" — stack is now empty
140
+ * ```
141
+ */
92
142
  export declare const createCallbackStack: <A0 = void, A1 = void, A2 = void, A3 = void>() => {
93
143
  push: (...callbacks: ((arg0: A0, arg1: A1, arg2: A2, arg3: A3) => void)[]) => void;
94
144
  execute: (arg0: A0, arg1: A1, arg2: A2, arg3: A3) => void;
95
145
  clear: VoidFunction;
96
146
  };
97
147
  /**
98
- * Group synchronous function calls.
99
- * @param fn
100
- * @returns `fn`
148
+ * Returns a debounced wrapper around `fn` that batches rapid synchronous calls
149
+ * into a single invocation. Only the most-recently-passed arguments are forwarded.
150
+ * The counter resets on cleanup so stale microtasks are silently discarded.
151
+ *
152
+ * @example
153
+ * ```ts
154
+ * const flush = createMicrotask((value: string) => console.log(value));
155
+ * flush("a");
156
+ * flush("b");
157
+ * flush("c"); // only "c" is logged (in the next microtask)
158
+ * ```
101
159
  */
102
160
  export declare function createMicrotask<A extends any[] | []>(fn: (...a: A) => void): (...a: A) => void;
103
161
  /**
@@ -116,14 +174,20 @@ export declare function createHydratableSignal<T>(serverValue: T, update: () =>
116
174
  /** @deprecated use {@link createHydratableSignal} instead */
117
175
  export declare const createHydrateSignal: typeof createHydratableSignal;
118
176
  /**
119
- * Handle items removed and added to the array by diffing it by refference.
177
+ * Diffs two arrays by reference and calls `handleAdded` / `handleRemoved` for
178
+ * each item that appeared or disappeared. Items are compared with `===`.
120
179
  *
121
- * @param current new array instance
122
- * @param prev previous array copy
123
- * @param handleAdded called once for every added item to array
124
- * @param handleRemoved called once for every removed from array
180
+ * @param current - the new array
181
+ * @param prev - the previous array snapshot
182
+ * @param handleAdded - called once for each item present in `current` but not `prev`
183
+ * @param handleRemoved - called once for each item present in `prev` but not `current`
125
184
  */
126
185
  export declare function handleDiffArray<T>(current: readonly T[], prev: readonly T[], handleAdded: (item: T) => void, handleRemoved: (item: T) => void): void;
186
+ /**
187
+ * Schedules `fn` to run after the browser has painted by nesting two
188
+ * requestAnimationFrame calls. No-op in non-browser environments.
189
+ */
190
+ export declare const afterPaint: (fn: () => void) => void;
127
191
  /**
128
192
  * Parse a string as a single JSON value.
129
193
  *
@@ -184,3 +248,24 @@ export declare function safe<T>(transform: (raw: string) => T, fallback: T): (ra
184
248
  * ```
185
249
  */
186
250
  export declare function pipe<A, B>(a: (raw: string) => A, b: (a: A) => B): (raw: string) => B;
251
+ /**
252
+ * Check if a wrapper element contains a target element.
253
+ * Portal-aware: follows SolidJS `_$host` links so elements rendered inside
254
+ * a `<Portal>` are correctly treated as children of the portal's anchor.
255
+ */
256
+ export declare const contains: (wrapper: HTMLElement, target: HTMLElement) => boolean;
257
+ /**
258
+ * Wraps a setter function of any signal or store
259
+ *
260
+ * ```ts
261
+ * const [data, setData] = wrapSetter(
262
+ * createSignal(initialData),
263
+ * (setter) => (next) => { console.log(next); return setter(next); },
264
+ * );
265
+ * ```
266
+ * If you destructure signal or store in a longer tuple, you need to use a const assertion for the types to work.
267
+ */
268
+ export declare function wrapSetter<T>(signal: Signal<T>, wrapper: (setter: Setter<T>) => Setter<T>): Signal<T>;
269
+ export declare function wrapSetter<T>(store: [Store<T>, StoreSetter<T>], wrapper: (setter: StoreSetter<T>) => StoreSetter<T>): [Store<T>, StoreSetter<T>];
270
+ export declare function wrapSetter<T, S extends Signal<T> | [Store<T>, StoreSetter<T>] | [...Signal<T>, ...any[]] | [Store<T>, StoreSetter<T>, ...any[]]>(signalOrStore: S, wrapper: (setter: S[1]) => S[1]): S;
271
+ export declare function wrapSetter<T, S extends Signal<T> | [Store<T>, StoreSetter<T>] | readonly [...Signal<T>, ...any[]] | readonly [Store<T>, StoreSetter<T>, ...any[]]>(signalOrStore: S, wrapper: (setter: S[1]) => S[1]): S;
package/dist/index.js CHANGED
@@ -1,31 +1,56 @@
1
- import { getOwner, onCleanup, createSignal, untrack, sharedConfig, onMount, DEV, equalFn, } from "solid-js";
2
- import { isServer } from "solid-js/web";
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.
4
+ const isServer = typeof window === "undefined";
3
5
  export * from "./types.js";
4
6
  //
5
7
  // GENERAL HELPERS:
6
8
  //
9
+ /** `true` on the server (SSR), `false` in the browser. */
7
10
  export { isServer };
11
+ /** `true` in the browser, `false` on the server. */
8
12
  export const isClient = !isServer;
13
+ /** `true` in the browser with Solid's DEV mode active. */
9
14
  export const isDev = isClient && !!DEV;
15
+ /** `true` when DEV mode is off (i.e. production browser builds and all SSR). */
10
16
  export const isProd = !isDev;
11
- /** no operation */
17
+ /** No-operation function — accepts any arguments and returns `undefined`. */
12
18
  export const noop = (() => void 0);
19
+ /** A function that always returns `true`. Useful as a default predicate prop. */
13
20
  export const trueFn = () => true;
21
+ /** A function that always returns `false`. Useful as a default predicate prop. */
14
22
  export const falseFn = () => false;
15
23
  /** @deprecated use {@link equalFn} from "solid-js" */
16
- export const defaultEquals = equalFn;
24
+ export const defaultEquals = Object.is.bind(Object);
25
+ /**
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
+ */
17
30
  export const EQUALS_FALSE_OPTIONS = { equals: false };
18
- export const INTERNAL_OPTIONS = { internal: true };
19
31
  /**
20
- * Check if the value is an instance of ___
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 };
40
+ /**
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.
21
43
  */
22
44
  export const ofClass = (v, c) => v instanceof c || (v && v.constructor === c);
23
45
  /** Check if value is typeof "object" or "function" */
24
46
  export function isObject(value) {
25
47
  return value !== null && (typeof value === "object" || typeof value === "function");
26
48
  }
49
+ /** Type guard: returns `true` when `i` is neither `null` nor `undefined`. */
27
50
  export const isNonNullable = (i) => i != null;
51
+ /** Returns a new array with all `null` and `undefined` items removed. */
28
52
  export const filterNonNullable = (arr) => arr.filter(isNonNullable);
53
+ /** Three-way comparison: returns `-1` if `a < b`, `1` if `a > b`, `0` if equal. */
29
54
  export const compare = (a, b) => (a < b ? -1 : a > b ? 1 : 0);
30
55
  /**
31
56
  * Check shallow array equality
@@ -51,7 +76,14 @@ export function reverseChain(callbacks) {
51
76
  }
52
77
  };
53
78
  }
79
+ /** Clamps `n` to the inclusive range `[min, max]`. */
54
80
  export const clamp = (n, min, max) => Math.min(Math.max(n, min), max);
81
+ /** 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}`;
86
+ };
55
87
  /**
56
88
  * Accesses the value of a MaybeAccessor
57
89
  * @example
@@ -61,6 +93,10 @@ export const clamp = (n, min, max) => Math.min(Math.max(n, min), max);
61
93
  * ```
62
94
  */
63
95
  export const access = (v) => typeof v === "function" && !v.length ? v() : v;
96
+ /**
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
+ */
64
100
  export const asArray = (value) => Array.isArray(value) ? value : value ? [value] : [];
65
101
  /**
66
102
  * Access an array of MaybeAccessors
@@ -76,9 +112,13 @@ export const accessArray = (list) => list.map(v => access(v));
76
112
  */
77
113
  export const withAccess = (value, fn) => {
78
114
  const _value = access(value);
79
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
115
+ // oxlint-disable-next-line @typescript-eslint/no-unnecessary-condition
80
116
  typeof _value != null && fn(_value);
81
117
  };
118
+ /**
119
+ * Wraps a plain value in a zero-argument accessor `() => value`.
120
+ * If `v` is already a function it is returned unchanged.
121
+ */
82
122
  export const asAccessor = (v) => (typeof v === "function" ? v : () => v);
83
123
  /** If value is a function – call it with a given arguments – otherwise get the value as is */
84
124
  export function accessWith(valueOrFn, ...args) {
@@ -88,7 +128,7 @@ export function defer(deps, fn, initialValue) {
88
128
  const isArray = Array.isArray(deps);
89
129
  let prevInput;
90
130
  let shouldDefer = true;
91
- return prevValue => {
131
+ return ((prevValue) => {
92
132
  let input;
93
133
  if (isArray) {
94
134
  input = Array(deps.length);
@@ -105,7 +145,7 @@ export function defer(deps, fn, initialValue) {
105
145
  const result = untrack(() => fn(input, prevInput, prevValue));
106
146
  prevInput = input;
107
147
  return result;
108
- };
148
+ });
109
149
  }
110
150
  /**
111
151
  * Get entries of an object
@@ -121,6 +161,19 @@ export const keys = Object.keys;
121
161
  export const tryOnCleanup = isDev
122
162
  ? fn => (getOwner() ? onCleanup(fn) : fn)
123
163
  : onCleanup;
164
+ /**
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
+ */
124
177
  export const createCallbackStack = () => {
125
178
  let stack = [];
126
179
  const clear = () => (stack = []);
@@ -134,9 +187,17 @@ export const createCallbackStack = () => {
134
187
  };
135
188
  };
136
189
  /**
137
- * Group synchronous function calls.
138
- * @param fn
139
- * @returns `fn`
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
+ * ```
140
201
  */
141
202
  export function createMicrotask(fn) {
142
203
  let calls = 0;
@@ -163,9 +224,11 @@ export function createHydratableSignal(serverValue, update, options) {
163
224
  if (isServer) {
164
225
  return createSignal(serverValue, options);
165
226
  }
166
- if (sharedConfig.context) {
227
+ if (sharedConfig.hydrating) {
167
228
  const [state, setState] = createSignal(serverValue, options);
168
- onMount(() => setState(() => update()));
229
+ onSettled(() => {
230
+ setState(() => update());
231
+ });
169
232
  return [state, setState];
170
233
  }
171
234
  return createSignal(update(), options);
@@ -173,12 +236,13 @@ export function createHydratableSignal(serverValue, update, options) {
173
236
  /** @deprecated use {@link createHydratableSignal} instead */
174
237
  export const createHydrateSignal = createHydratableSignal;
175
238
  /**
176
- * Handle items removed and added to the array by diffing it by refference.
239
+ * Diffs two arrays by reference and calls `handleAdded` / `handleRemoved` for
240
+ * each item that appeared or disappeared. Items are compared with `===`.
177
241
  *
178
- * @param current new array instance
179
- * @param prev previous array copy
180
- * @param handleAdded called once for every added item to array
181
- * @param handleRemoved called once for every removed from array
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`
182
246
  */
183
247
  export function handleDiffArray(current, prev, handleAdded, handleRemoved) {
184
248
  const currLength = current.length;
@@ -211,6 +275,15 @@ export function handleDiffArray(current, prev, handleAdded, handleRemoved) {
211
275
  handleAdded(currEl);
212
276
  }
213
277
  }
278
+ /**
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
+ }
286
+ };
214
287
  // ─── String transforms ────────────────────────────────────────────────────────
215
288
  /**
216
289
  * Parse a string as a single JSON value.
@@ -276,3 +349,24 @@ export function safe(transform, fallback) {
276
349
  export function pipe(a, b) {
277
350
  return (raw) => b(a(raw));
278
351
  }
352
+ // ─── DOM helpers ─────────────────────────────────────────────────────────────
353
+ /**
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;
369
+ };
370
+ export function wrapSetter(signalOrStore, wrapper) {
371
+ return [signalOrStore[0], wrapper(signalOrStore[1]), ...signalOrStore.slice(2)];
372
+ }
package/dist/types.d.ts CHANGED
@@ -1,6 +1,4 @@
1
1
  import type { Accessor, Setter } from "solid-js";
2
- export type { EffectOptions, OnOptions } from "solid-js";
3
- export type { ResolvedJSXElement, ResolvedChildren } from "solid-js/types/reactive/signal.js";
4
2
  /**
5
3
  * Can be single or in an array
6
4
  */
@@ -31,6 +29,9 @@ export type MaybeAccessor<T> = T | Accessor<T>;
31
29
  * ```
32
30
  */
33
31
  export type MaybeAccessorValue<T extends MaybeAccessor<any>> = T extends () => any ? ReturnType<T> : T;
32
+ export type AccessorArray<T> = [...Extract<{
33
+ [K in keyof T]: Accessor<T[K]>;
34
+ }, readonly unknown[]>];
34
35
  export type OnAccessEffectFunction<S, Prev, Next extends Prev = Prev> = (input: AccessReturnTypes<S>, prevInput: AccessReturnTypes<S>, v: Prev) => Next;
35
36
  export type AccessReturnTypes<S> = S extends MaybeAccessor<any>[] ? {
36
37
  [I in keyof S]: AccessReturnTypes<S[I]>;
@@ -87,3 +88,4 @@ type RawNarrow<T> = (T extends [] ? [] : never) | (T extends string | number | b
87
88
  };
88
89
  export type Narrow<T> = T extends [] ? T : RawNarrow<T>;
89
90
  export type NoInfer<T> = [T][T extends any ? 0 : never];
91
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solid-primitives/utils",
3
- "version": "6.4.1",
3
+ "version": "7.0.0-next.1",
4
4
  "description": "A bunch of reactive utility types and functions, for building primitives with Solid.js",
5
5
  "author": "Damian Tarnawski @thetarnav <gthetarnav@gmail.com>",
6
6
  "contributors": [
@@ -38,12 +38,22 @@
38
38
  "types": "./dist/immutable/index.d.ts",
39
39
  "default": "./dist/immutable/index.js"
40
40
  }
41
+ },
42
+ "./colors": {
43
+ "import": {
44
+ "@solid-primitives/source": "./src/colors/index.ts",
45
+ "types": "./dist/colors/index.d.ts",
46
+ "default": "./dist/colors/index.js"
47
+ }
41
48
  }
42
49
  },
43
50
  "typesVersions": {
44
51
  "*": {
45
52
  "immutable": [
46
53
  "./dist/immutable/index.d.ts"
54
+ ],
55
+ "colors": [
56
+ "./dist/colors/index.d.ts"
47
57
  ]
48
58
  }
49
59
  },
@@ -53,11 +63,82 @@
53
63
  "solid",
54
64
  "primitives"
55
65
  ],
66
+ "primitive": {
67
+ "name": "utils",
68
+ "stage": 3,
69
+ "list": [
70
+ "shallowArrayCopy",
71
+ "shallowObjectCopy",
72
+ "shallowCopy",
73
+ "withArrayCopy",
74
+ "withObjectCopy",
75
+ "withCopy",
76
+ "push",
77
+ "drop",
78
+ "dropRight",
79
+ "filterOut",
80
+ "filter",
81
+ "sort",
82
+ "sortBy",
83
+ "map",
84
+ "slice",
85
+ "splice",
86
+ "fill",
87
+ "concat",
88
+ "remove",
89
+ "removeItems",
90
+ "flatten",
91
+ "filterInstance",
92
+ "filterOutInstance",
93
+ "omit",
94
+ "pick",
95
+ "split",
96
+ "merge",
97
+ "get",
98
+ "update",
99
+ "add",
100
+ "substract",
101
+ "multiply",
102
+ "divide",
103
+ "power",
104
+ "clamp",
105
+ "json",
106
+ "ndjson",
107
+ "lines",
108
+ "number",
109
+ "safe",
110
+ "pipe",
111
+ "wrapSetter",
112
+ "parseColor",
113
+ "normalizeColor",
114
+ "tryParseColor",
115
+ "isValidColor",
116
+ "detectColorFormat",
117
+ "getColorChannels",
118
+ "normalizeHue",
119
+ "colorToOKLCH",
120
+ "lighten",
121
+ "darken",
122
+ "saturate",
123
+ "desaturate",
124
+ "complement",
125
+ "mix",
126
+ "contrastRatio",
127
+ "isReadable",
128
+ "colorScale",
129
+ "perceptualColorScale",
130
+ "COLOR_INTL_TRANSLATIONS"
131
+ ],
132
+ "category": "Utilities",
133
+ "gzip": 1399
134
+ },
56
135
  "peerDependencies": {
57
- "solid-js": "^1.6.12"
136
+ "@solidjs/web": "^2.0.0-beta.15",
137
+ "solid-js": "^2.0.0-beta.15"
58
138
  },
59
139
  "devDependencies": {
60
- "solid-js": "^1.9.7"
140
+ "@solidjs/web": "2.0.0-beta.15",
141
+ "solid-js": "2.0.0-beta.15"
61
142
  },
62
143
  "scripts": {
63
144
  "dev": "node --import=@nothing-but/node-resolve-ts --experimental-transform-types ../../scripts/dev.ts",