solid-tiny-utils 0.11.0 → 0.12.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/LICENSE +21 -21
- package/README.md +9 -9
- package/dist/color/hex-rgb.d.mts +0 -1
- package/dist/color/hex-rgb.mjs +1 -3
- package/dist/color/oklch-rgb.d.mts +3 -3
- package/dist/color/oklch-rgb.mjs +1 -3
- package/dist/color/validation.d.mts +0 -1
- package/dist/color/validation.mjs +1 -3
- package/dist/dom/animation.mjs +1 -2
- package/dist/dom/attrs.mjs +1 -2
- package/dist/dom/css.d.mts +1 -2
- package/dist/dom/css.mjs +4 -5
- package/dist/dom/index.d.mts +3 -0
- package/dist/index.d.mts +2 -4
- package/dist/index.mjs +2 -3
- package/dist/solidjs/create-click-outside.d.mts +0 -2
- package/dist/solidjs/create-click-outside.mjs +2 -6
- package/dist/solidjs/create-debounce-watch.d.mts +0 -1
- package/dist/solidjs/create-debounce-watch.mjs +1 -3
- package/dist/solidjs/create-debounce.d.mts +0 -2
- package/dist/solidjs/create-debounce.mjs +1 -3
- package/dist/solidjs/create-event-listener.d.mts +0 -1
- package/dist/solidjs/create-event-listener.mjs +1 -3
- package/dist/solidjs/create-intersection-observer.d.mts +0 -2
- package/dist/solidjs/create-intersection-observer.mjs +1 -3
- package/dist/solidjs/create-list.mjs +2 -6
- package/dist/solidjs/create-loop-exec.d.mts +0 -1
- package/dist/solidjs/create-loop-exec.mjs +1 -3
- package/dist/solidjs/create-presence.d.mts +16 -6
- package/dist/solidjs/create-presence.mjs +77 -19
- package/dist/solidjs/create-throttle.d.mts +0 -2
- package/dist/solidjs/create-throttle.mjs +1 -3
- package/dist/solidjs/create-visibility-observer.d.mts +0 -1
- package/dist/solidjs/create-visibility-observer.mjs +1 -3
- package/dist/solidjs/create-watch.mjs +1 -3
- package/dist/solidjs/index.d.mts +1 -1
- package/dist/solidjs/make-event-listener.d.mts +0 -2
- package/dist/solidjs/make-event-listener.mjs +1 -3
- package/dist/solidjs/utils.mjs +11 -6
- package/dist/utils/array.mjs +2 -6
- package/dist/utils/async.mjs +6 -11
- package/dist/utils/constant.mjs +1 -2
- package/dist/utils/is.mjs +9 -27
- package/dist/utils/number.mjs +1 -2
- package/dist/utils/random.mjs +7 -15
- package/dist/utils/str.mjs +6 -17
- package/package.json +40 -34
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2025 g-mero
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 g-mero
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
# solid-tiny-utils
|
|
2
|
-
|
|
3
|
-
Tiny utilities for SolidJS applications.
|
|
4
|
-
|
|
5
|
-
## Installation
|
|
6
|
-
|
|
7
|
-
```bash
|
|
8
|
-
pnpm add solid-tiny-utils
|
|
9
|
-
```
|
|
1
|
+
# solid-tiny-utils
|
|
2
|
+
|
|
3
|
+
Tiny utilities for SolidJS applications.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add solid-tiny-utils
|
|
9
|
+
```
|
package/dist/color/hex-rgb.d.mts
CHANGED
package/dist/color/hex-rgb.mjs
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { isArray } from "../utils/is.mjs";
|
|
2
2
|
import { clamp, toHex } from "../utils/number.mjs";
|
|
3
|
-
|
|
4
3
|
//#region src/color/hex-rgb.ts
|
|
5
4
|
const HEX_PREFIX_REGEX = /^#/;
|
|
6
5
|
const HEX_VALIDATION_REGEX = /^[0-9a-fA-F]{6}$/;
|
|
@@ -57,6 +56,5 @@ function rgbToHex(rgb) {
|
|
|
57
56
|
const b = c(rgb_[2]);
|
|
58
57
|
return `#${toHex(r)}${toHex(g)}${toHex(b)}`;
|
|
59
58
|
}
|
|
60
|
-
|
|
61
59
|
//#endregion
|
|
62
|
-
export { hexToRgb, rgbToHex };
|
|
60
|
+
export { hexToRgb, rgbToHex };
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
//#region src/color/oklch-rgb.d.ts
|
|
2
2
|
interface RGB {
|
|
3
|
-
r: number;
|
|
4
|
-
g: number;
|
|
5
3
|
b: number;
|
|
4
|
+
g: number;
|
|
5
|
+
r: number;
|
|
6
6
|
}
|
|
7
7
|
interface OKLCH {
|
|
8
|
-
l: number;
|
|
9
8
|
c: number;
|
|
10
9
|
h: number;
|
|
10
|
+
l: number;
|
|
11
11
|
}
|
|
12
12
|
/**
|
|
13
13
|
* Converts OKLCH color to RGB color space.
|
package/dist/color/oklch-rgb.mjs
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { clamp, max } from "../utils/number.mjs";
|
|
2
|
-
|
|
3
2
|
//#region src/color/oklch-rgb.ts
|
|
4
3
|
const PI_180 = Math.PI / 180;
|
|
5
4
|
const INV_PI_180 = 180 / Math.PI;
|
|
@@ -96,6 +95,5 @@ function rgbToOklch(rgb) {
|
|
|
96
95
|
h
|
|
97
96
|
};
|
|
98
97
|
}
|
|
99
|
-
|
|
100
98
|
//#endregion
|
|
101
|
-
export { oklchToRgb, rgbToOklch };
|
|
99
|
+
export { oklchToRgb, rgbToOklch };
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { inRange } from "../utils/number.mjs";
|
|
2
2
|
import { hexToRgb } from "./hex-rgb.mjs";
|
|
3
|
-
|
|
4
3
|
//#region src/color/validation.ts
|
|
5
4
|
/**
|
|
6
5
|
* Checks if RGB values are in valid range (0-255)
|
|
@@ -30,6 +29,5 @@ function isValidOKLCH(oklch) {
|
|
|
30
29
|
function isValidHex(hex) {
|
|
31
30
|
return hexToRgb(hex) !== null;
|
|
32
31
|
}
|
|
33
|
-
|
|
34
32
|
//#endregion
|
|
35
|
-
export { isValidHex, isValidOKLCH, isValidRGB };
|
|
33
|
+
export { isValidHex, isValidOKLCH, isValidRGB };
|
package/dist/dom/animation.mjs
CHANGED
package/dist/dom/attrs.mjs
CHANGED
package/dist/dom/css.d.mts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { JSX } from "solid-js/jsx-runtime";
|
|
2
2
|
|
|
3
3
|
//#region src/dom/css.d.ts
|
|
4
|
-
|
|
5
4
|
/**
|
|
6
5
|
* Mounts a style element to the document head.
|
|
7
6
|
* If the style element with the given id already exists, it updates its content.
|
|
@@ -12,7 +11,7 @@ import { JSX } from "solid-js/jsx-runtime";
|
|
|
12
11
|
* @param id - The id of the style element.
|
|
13
12
|
* @param refresh - Whether to refresh the style if it already exists. Defaults to **false**.
|
|
14
13
|
*/
|
|
15
|
-
declare function mountStyle(style: string, id: string, refresh?: boolean): void;
|
|
14
|
+
declare function mountStyle(style: string | (() => string), id: string, refresh?: boolean): void;
|
|
16
15
|
declare function stringStyleToObject(style: string): JSX.CSSProperties;
|
|
17
16
|
declare function combineStyle(a: JSX.CSSProperties, b: JSX.CSSProperties | string | undefined): JSX.CSSProperties | string;
|
|
18
17
|
declare function combineClass(defaultClass: string, ...otherClass: (string | undefined | null)[]): string;
|
package/dist/dom/css.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { isClient } from "../utils/is.mjs";
|
|
2
|
-
|
|
2
|
+
import { access } from "../solidjs/utils.mjs";
|
|
3
3
|
//#region src/dom/css.ts
|
|
4
4
|
const alreadyInjected = [];
|
|
5
5
|
/**
|
|
@@ -17,12 +17,12 @@ function mountStyle(style, id, refresh = false) {
|
|
|
17
17
|
if (alreadyInjected.includes(id) && !refresh) return;
|
|
18
18
|
let styleElement = document.querySelector(`style#${id}`);
|
|
19
19
|
if (styleElement) {
|
|
20
|
-
styleElement.
|
|
20
|
+
styleElement.textContent = access(style);
|
|
21
21
|
return;
|
|
22
22
|
}
|
|
23
23
|
styleElement = document.createElement("style");
|
|
24
24
|
styleElement.id = id;
|
|
25
|
-
styleElement.
|
|
25
|
+
styleElement.textContent = access(style);
|
|
26
26
|
document.head.appendChild(styleElement);
|
|
27
27
|
alreadyInjected.push(id);
|
|
28
28
|
}
|
|
@@ -46,6 +46,5 @@ function combineStyle(a, b) {
|
|
|
46
46
|
function combineClass(defaultClass, ...otherClass) {
|
|
47
47
|
return [defaultClass, ...otherClass].filter(Boolean).join(" ");
|
|
48
48
|
}
|
|
49
|
-
|
|
50
49
|
//#endregion
|
|
51
|
-
export { combineClass, combineStyle, mountStyle, stringStyleToObject };
|
|
50
|
+
export { combineClass, combineStyle, mountStyle, stringStyleToObject };
|
package/dist/index.d.mts
CHANGED
|
@@ -6,7 +6,6 @@ import { dataIf } from "./dom/attrs.mjs";
|
|
|
6
6
|
import { combineClass, combineStyle, mountStyle, stringStyleToObject } from "./dom/css.mjs";
|
|
7
7
|
import { AnyFn, Fn } from "./types/fn.mjs";
|
|
8
8
|
import { MaybeAccessor, MaybeArray, MaybeNullableAccessor, MaybePromise } from "./types/maybe.mjs";
|
|
9
|
-
import "./types/index.mjs";
|
|
10
9
|
import { createClickOutside } from "./solidjs/create-click-outside.mjs";
|
|
11
10
|
import { createDebounce } from "./solidjs/create-debounce.mjs";
|
|
12
11
|
import { createDebouncedWatch } from "./solidjs/create-debounce-watch.mjs";
|
|
@@ -15,12 +14,11 @@ import { createEventListener } from "./solidjs/create-event-listener.mjs";
|
|
|
15
14
|
import { createIntersectionObserver } from "./solidjs/create-intersection-observer.mjs";
|
|
16
15
|
import { createList } from "./solidjs/create-list.mjs";
|
|
17
16
|
import { createLoopExec } from "./solidjs/create-loop-exec.mjs";
|
|
18
|
-
import {
|
|
17
|
+
import { MakePresenceOptions, PresencePhase, createPresence } from "./solidjs/create-presence.mjs";
|
|
19
18
|
import { createThrottle } from "./solidjs/create-throttle.mjs";
|
|
20
19
|
import { CreateVisibilityObserverOption, EntryCallback, UseVisibilityObserverFn, createVisibilityObserver } from "./solidjs/create-visibility-observer.mjs";
|
|
21
20
|
import { createWatch } from "./solidjs/create-watch.mjs";
|
|
22
21
|
import { MaybeCallableChild, access, callMaybeCallableChild, runSolidEventHandler } from "./solidjs/utils.mjs";
|
|
23
|
-
import "./solidjs/index.mjs";
|
|
24
22
|
import { clearArray, iterate, list, range } from "./utils/array.mjs";
|
|
25
23
|
import { runAtNextAnimationFrame, sleep } from "./utils/async.mjs";
|
|
26
24
|
import { noop } from "./utils/constant.mjs";
|
|
@@ -28,4 +26,4 @@ import { isArray, isClient, isDate, isDefined, isEmpty, isFloat, isFn, isInt, is
|
|
|
28
26
|
import { clamp, inRange, max, min, toHex } from "./utils/number.mjs";
|
|
29
27
|
import { draw, random, shuffle, uid } from "./utils/random.mjs";
|
|
30
28
|
import { camel, capitalize, dash, pascal, snake, template, title, trim } from "./utils/str.mjs";
|
|
31
|
-
export { AnyFn, CreateVisibilityObserverOption, DocumentEventName, EntryCallback, Fn, GeneralEventListener, MaybeAccessor, MaybeArray, MaybeCallableChild, MaybeNullableAccessor, MaybePromise, OKLCH,
|
|
29
|
+
export { AnyFn, CreateVisibilityObserverOption, DocumentEventName, EntryCallback, Fn, GeneralEventListener, MakePresenceOptions, MaybeAccessor, MaybeArray, MaybeCallableChild, MaybeNullableAccessor, MaybePromise, OKLCH, PresencePhase, RGB, UseVisibilityObserverFn, WindowEventName, access, callMaybeCallableChild, camel, capitalize, clamp, clearArray, combineClass, combineStyle, createClickOutside, createDebounce, createDebouncedWatch, createEventListener, createIntersectionObserver, createList, createLoopExec, createPresence, createThrottle, createVisibilityObserver, createWatch, dash, dataIf, draw, hasAnimation, hexToRgb, inRange, isArray, isClient, isDate, isDefined, isEmpty, isFloat, isFn, isInt, isNumber, isObject, isPrimitive, isPromise, isString, isSymbol, isUndefined, isValidHex, isValidOKLCH, isValidRGB, iterate, list, makeEventListener, max, min, mountStyle, noop, oklchToRgb, pascal, random, range, rgbToHex, rgbToOklch, runAtNextAnimationFrame, runSolidEventHandler, shuffle, sleep, snake, stringStyleToObject, template, title, toHex, trim, uid };
|
package/dist/index.mjs
CHANGED
|
@@ -10,7 +10,6 @@ import { oklchToRgb, rgbToOklch } from "./color/oklch-rgb.mjs";
|
|
|
10
10
|
import { isValidHex, isValidOKLCH, isValidRGB } from "./color/validation.mjs";
|
|
11
11
|
import { hasAnimation } from "./dom/animation.mjs";
|
|
12
12
|
import { dataIf } from "./dom/attrs.mjs";
|
|
13
|
-
import { combineClass, combineStyle, mountStyle, stringStyleToObject } from "./dom/css.mjs";
|
|
14
13
|
import { makeEventListener } from "./solidjs/make-event-listener.mjs";
|
|
15
14
|
import { access, callMaybeCallableChild, runSolidEventHandler } from "./solidjs/utils.mjs";
|
|
16
15
|
import { createClickOutside } from "./solidjs/create-click-outside.mjs";
|
|
@@ -24,5 +23,5 @@ import { createLoopExec } from "./solidjs/create-loop-exec.mjs";
|
|
|
24
23
|
import { createPresence } from "./solidjs/create-presence.mjs";
|
|
25
24
|
import { createThrottle } from "./solidjs/create-throttle.mjs";
|
|
26
25
|
import { createVisibilityObserver } from "./solidjs/create-visibility-observer.mjs";
|
|
27
|
-
|
|
28
|
-
export { access, callMaybeCallableChild, camel, capitalize, clamp, clearArray, combineClass, combineStyle, createClickOutside, createDebounce, createDebouncedWatch, createEventListener, createIntersectionObserver, createList, createLoopExec, createPresence, createThrottle, createVisibilityObserver, createWatch, dash, dataIf, draw, hasAnimation, hexToRgb, inRange, isArray, isClient, isDate, isDefined, isEmpty, isFloat, isFn, isInt, isNumber, isObject, isPrimitive, isPromise, isString, isSymbol, isUndefined, isValidHex, isValidOKLCH, isValidRGB, iterate, list, makeEventListener, max, min, mountStyle, noop, oklchToRgb, pascal, random, range, rgbToHex, rgbToOklch, runAtNextAnimationFrame, runSolidEventHandler, shuffle, sleep, snake, stringStyleToObject, template, title, toHex, trim, uid };
|
|
26
|
+
import { combineClass, combineStyle, mountStyle, stringStyleToObject } from "./dom/css.mjs";
|
|
27
|
+
export { access, callMaybeCallableChild, camel, capitalize, clamp, clearArray, combineClass, combineStyle, createClickOutside, createDebounce, createDebouncedWatch, createEventListener, createIntersectionObserver, createList, createLoopExec, createPresence, createThrottle, createVisibilityObserver, createWatch, dash, dataIf, draw, hasAnimation, hexToRgb, inRange, isArray, isClient, isDate, isDefined, isEmpty, isFloat, isFn, isInt, isNumber, isObject, isPrimitive, isPromise, isString, isSymbol, isUndefined, isValidHex, isValidOKLCH, isValidRGB, iterate, list, makeEventListener, max, min, mountStyle, noop, oklchToRgb, pascal, random, range, rgbToHex, rgbToOklch, runAtNextAnimationFrame, runSolidEventHandler, shuffle, sleep, snake, stringStyleToObject, template, title, toHex, trim, uid };
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import { MaybeAccessor } from "../types/maybe.mjs";
|
|
2
|
-
import "../types/index.mjs";
|
|
3
|
-
|
|
4
2
|
//#region src/solidjs/create-click-outside.d.ts
|
|
5
3
|
declare function createClickOutside(target: MaybeAccessor<HTMLElement | null | undefined>, handler: (event: PointerEvent) => void, options?: {
|
|
6
4
|
ignore?: MaybeAccessor<HTMLElement | null | undefined>[];
|
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
import { makeEventListener } from "./make-event-listener.mjs";
|
|
2
2
|
import { access } from "./utils.mjs";
|
|
3
|
-
|
|
4
3
|
//#region src/solidjs/create-click-outside.ts
|
|
5
4
|
function createClickOutside(target, handler, options) {
|
|
6
5
|
let shouldListen = false;
|
|
7
6
|
const shouldIgnore = (event) => {
|
|
8
|
-
return (options?.ignore ? options.ignore : []).map(access).some((el) =>
|
|
9
|
-
return el && (event.target === el || event.composedPath().includes(el));
|
|
10
|
-
});
|
|
7
|
+
return (options?.ignore ? options.ignore : []).map(access).some((el) => el && (event.target === el || event.composedPath().includes(el)));
|
|
11
8
|
};
|
|
12
9
|
const listener = (e) => {
|
|
13
10
|
const el = access(target);
|
|
@@ -28,6 +25,5 @@ function createClickOutside(target, handler, options) {
|
|
|
28
25
|
};
|
|
29
26
|
return stop;
|
|
30
27
|
}
|
|
31
|
-
|
|
32
28
|
//#endregion
|
|
33
|
-
export { createClickOutside };
|
|
29
|
+
export { createClickOutside };
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { createDebounce } from "./create-debounce.mjs";
|
|
2
2
|
import { createWatch } from "./create-watch.mjs";
|
|
3
|
-
|
|
4
3
|
//#region src/solidjs/create-debounce-watch.ts
|
|
5
4
|
/**
|
|
6
5
|
* Creates a debounced watch effect.
|
|
@@ -10,6 +9,5 @@ import { createWatch } from "./create-watch.mjs";
|
|
|
10
9
|
function createDebouncedWatch(targets, fn, opt) {
|
|
11
10
|
createWatch(targets, createDebounce(fn, opt?.delay ?? 10), opt);
|
|
12
11
|
}
|
|
13
|
-
|
|
14
12
|
//#endregion
|
|
15
|
-
export { createDebouncedWatch };
|
|
13
|
+
export { createDebouncedWatch };
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import { MaybeAccessor } from "../types/maybe.mjs";
|
|
2
|
-
import "../types/index.mjs";
|
|
3
|
-
|
|
4
2
|
//#region src/solidjs/create-debounce.d.ts
|
|
5
3
|
declare function createDebounce<Args extends unknown[]>(callback: (...args: Args) => void, delay: MaybeAccessor<number>): (...args: Args) => void;
|
|
6
4
|
//#endregion
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { access } from "./utils.mjs";
|
|
2
2
|
import { onCleanup } from "solid-js";
|
|
3
|
-
|
|
4
3
|
//#region src/solidjs/create-debounce.ts
|
|
5
4
|
function createDebounce(callback, delay) {
|
|
6
5
|
let timeoutId;
|
|
@@ -15,6 +14,5 @@ function createDebounce(callback, delay) {
|
|
|
15
14
|
};
|
|
16
15
|
return run;
|
|
17
16
|
}
|
|
18
|
-
|
|
19
17
|
//#endregion
|
|
20
|
-
export { createDebounce };
|
|
18
|
+
export { createDebounce };
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Fn } from "../types/fn.mjs";
|
|
2
2
|
import { MaybeAccessor, MaybeArray } from "../types/maybe.mjs";
|
|
3
|
-
import "../types/index.mjs";
|
|
4
3
|
import { DocumentEventName, GeneralEventListener, WindowEventName } from "./make-event-listener.mjs";
|
|
5
4
|
|
|
6
5
|
//#region src/solidjs/create-event-listener.d.ts
|
|
@@ -4,7 +4,6 @@ import { noop } from "../utils/constant.mjs";
|
|
|
4
4
|
import { makeEventListener } from "./make-event-listener.mjs";
|
|
5
5
|
import { access } from "./utils.mjs";
|
|
6
6
|
import { createWatch } from "./create-watch.mjs";
|
|
7
|
-
|
|
8
7
|
//#region src/solidjs/create-event-listener.ts
|
|
9
8
|
function createEventListener(...args) {
|
|
10
9
|
const target = args[0];
|
|
@@ -28,6 +27,5 @@ function createEventListener(...args) {
|
|
|
28
27
|
});
|
|
29
28
|
return cleanup;
|
|
30
29
|
}
|
|
31
|
-
|
|
32
30
|
//#endregion
|
|
33
|
-
export { createEventListener };
|
|
31
|
+
export { createEventListener };
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import { MaybeAccessor } from "../types/maybe.mjs";
|
|
2
|
-
import "../types/index.mjs";
|
|
3
|
-
|
|
4
2
|
//#region src/solidjs/create-intersection-observer.d.ts
|
|
5
3
|
declare function createIntersectionObserver(targets: MaybeAccessor<HTMLElement | null | undefined>[], callback: IntersectionObserverCallback, options?: IntersectionObserverInit): () => void;
|
|
6
4
|
//#endregion
|
|
@@ -4,7 +4,6 @@ import { access } from "./utils.mjs";
|
|
|
4
4
|
import { createWatch } from "./create-watch.mjs";
|
|
5
5
|
import { isServer } from "solid-js/web";
|
|
6
6
|
import { onCleanup } from "solid-js";
|
|
7
|
-
|
|
8
7
|
//#region src/solidjs/create-intersection-observer.ts
|
|
9
8
|
function createIntersectionObserver(targets, callback, options = {}) {
|
|
10
9
|
if (isServer) return noop;
|
|
@@ -24,6 +23,5 @@ function createIntersectionObserver(targets, callback, options = {}) {
|
|
|
24
23
|
});
|
|
25
24
|
return () => io.disconnect();
|
|
26
25
|
}
|
|
27
|
-
|
|
28
26
|
//#endregion
|
|
29
|
-
export { createIntersectionObserver };
|
|
27
|
+
export { createIntersectionObserver };
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { inRange } from "../utils/number.mjs";
|
|
2
2
|
import { createStore, unwrap } from "solid-js/store";
|
|
3
|
-
|
|
4
3
|
//#region src/solidjs/create-list.ts
|
|
5
4
|
function createInsertHelper(setList) {
|
|
6
5
|
return (item, at) => {
|
|
@@ -67,11 +66,8 @@ function createList(initialValue) {
|
|
|
67
66
|
swap: createSwapHelper(setList),
|
|
68
67
|
move: createMoveHelper(setList),
|
|
69
68
|
sort: createSortHelper(setList),
|
|
70
|
-
isSortedBy: (compareFn) =>
|
|
71
|
-
return createIsSortedHelper(list, compareFn);
|
|
72
|
-
}
|
|
69
|
+
isSortedBy: (compareFn) => createIsSortedHelper(list, compareFn)
|
|
73
70
|
}];
|
|
74
71
|
}
|
|
75
|
-
|
|
76
72
|
//#endregion
|
|
77
|
-
export { createList };
|
|
73
|
+
export { createList };
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { MaybeAccessor, MaybePromise } from "../types/maybe.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/solidjs/create-loop-exec.d.ts
|
|
4
|
-
|
|
5
4
|
/**
|
|
6
5
|
* Repeatedly executes an asynchronous function with a specified delay between each execution.
|
|
7
6
|
* The loop continues until the surrounding SolidJS effect is cleaned up.
|
|
@@ -2,7 +2,6 @@ import { isNumber } from "../utils/is.mjs";
|
|
|
2
2
|
import { access } from "./utils.mjs";
|
|
3
3
|
import { createWatch } from "./create-watch.mjs";
|
|
4
4
|
import { onCleanup } from "solid-js";
|
|
5
|
-
|
|
6
5
|
//#region src/solidjs/create-loop-exec.ts
|
|
7
6
|
/**
|
|
8
7
|
* Repeatedly executes an asynchronous function with a specified delay between each execution.
|
|
@@ -54,6 +53,5 @@ function createLoopExec(fn, delay) {
|
|
|
54
53
|
start
|
|
55
54
|
};
|
|
56
55
|
}
|
|
57
|
-
|
|
58
56
|
//#endregion
|
|
59
|
-
export { createLoopExec };
|
|
57
|
+
export { createLoopExec };
|
|
@@ -2,10 +2,20 @@ import { MaybeAccessor } from "../types/maybe.mjs";
|
|
|
2
2
|
import { Accessor } from "solid-js";
|
|
3
3
|
|
|
4
4
|
//#region src/solidjs/create-presence.d.ts
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
5
|
+
interface MakePresenceOptions {
|
|
6
|
+
enterDuration: MaybeAccessor<number>;
|
|
7
|
+
exitDuration: MaybeAccessor<number>;
|
|
8
|
+
initialEnter?: boolean;
|
|
9
|
+
}
|
|
10
|
+
type PresencePhase = "idle" | "pre-enter" | "entering" | "entered" | "exiting" | "exited";
|
|
11
|
+
declare function createPresence<TItem>(item: Accessor<TItem | undefined>, options: MakePresenceOptions): {
|
|
12
|
+
isMounted: () => boolean;
|
|
13
|
+
mountedItem: Accessor<TItem | undefined>;
|
|
14
|
+
isVisible: Accessor<boolean>;
|
|
15
|
+
isAnimating: Accessor<boolean>;
|
|
16
|
+
isEntering: Accessor<boolean>;
|
|
17
|
+
isExiting: Accessor<boolean>;
|
|
18
|
+
phase: Accessor<PresencePhase>;
|
|
19
|
+
};
|
|
10
20
|
//#endregion
|
|
11
|
-
export {
|
|
21
|
+
export { MakePresenceOptions, PresencePhase, createPresence };
|
|
@@ -1,29 +1,87 @@
|
|
|
1
|
+
import { isDefined } from "../utils/is.mjs";
|
|
2
|
+
import { runAtNextAnimationFrame } from "../utils/async.mjs";
|
|
1
3
|
import { noop } from "../utils/constant.mjs";
|
|
2
|
-
import { hasAnimation } from "../dom/animation.mjs";
|
|
3
|
-
import { makeEventListener } from "./make-event-listener.mjs";
|
|
4
4
|
import { access } from "./utils.mjs";
|
|
5
5
|
import { createWatch } from "./create-watch.mjs";
|
|
6
|
-
import { createMemo, createSignal } from "solid-js";
|
|
7
|
-
|
|
6
|
+
import { createEffect, createMemo, createSignal, onCleanup, untrack } from "solid-js";
|
|
8
7
|
//#region src/solidjs/create-presence.ts
|
|
9
|
-
function
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
8
|
+
function makeTimeout(ms, fn) {
|
|
9
|
+
if (ms() <= 0) {
|
|
10
|
+
fn();
|
|
11
|
+
return noop;
|
|
12
|
+
}
|
|
13
|
+
const timeoutId = setTimeout(() => {
|
|
14
|
+
fn();
|
|
15
|
+
}, ms());
|
|
16
|
+
return () => clearTimeout(timeoutId);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Animates the appearance of its children.
|
|
20
|
+
*
|
|
21
|
+
* @internal - to be combined with `createPresence` in the future
|
|
22
|
+
*/
|
|
23
|
+
function createPresenceBase(source, options) {
|
|
24
|
+
const enterDuration = () => access(options.enterDuration);
|
|
25
|
+
const exitDuration = () => access(options.exitDuration);
|
|
26
|
+
const initialSource = untrack(source);
|
|
27
|
+
let initialPhase = "idle";
|
|
28
|
+
if (initialSource) initialPhase = options.initialEnter ? "pre-enter" : "entered";
|
|
29
|
+
const [phase, setPhase] = createSignal(initialPhase);
|
|
15
30
|
let clear = noop;
|
|
16
|
-
|
|
31
|
+
onCleanup(clear);
|
|
32
|
+
createWatch(source, (visible) => {
|
|
33
|
+
setPhase((prev) => {
|
|
34
|
+
if (visible) {
|
|
35
|
+
if (prev === "idle" || prev === "exited") return "pre-enter";
|
|
36
|
+
return prev;
|
|
37
|
+
}
|
|
38
|
+
if (prev === "entered" || prev === "entering") return "exiting";
|
|
39
|
+
return prev;
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
createWatch(phase, (currentPhase) => {
|
|
17
43
|
clear();
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
if (current.endsWith("ing")) if (hasAnimation(el)) clear = makeEventListener(el, "animationend", () => {
|
|
21
|
-
setState(current === "opening" ? "opened" : "closed");
|
|
44
|
+
if (currentPhase === "pre-enter") runAtNextAnimationFrame(() => {
|
|
45
|
+
setPhase("entering");
|
|
22
46
|
});
|
|
23
|
-
|
|
47
|
+
if (currentPhase === "entering") clear = makeTimeout(enterDuration, () => setPhase("entered"));
|
|
48
|
+
if (currentPhase === "exiting") clear = makeTimeout(exitDuration, () => setPhase("exited"));
|
|
49
|
+
if (currentPhase === "exited") setPhase("idle");
|
|
50
|
+
});
|
|
51
|
+
const isVisible = createMemo(() => ["entering", "entered"].includes(phase()));
|
|
52
|
+
const isMounted = createMemo(() => phase() !== "idle");
|
|
53
|
+
const isExiting = createMemo(() => phase() === "exiting");
|
|
54
|
+
const isEntering = createMemo(() => phase() === "entering");
|
|
55
|
+
return {
|
|
56
|
+
isMounted,
|
|
57
|
+
isVisible,
|
|
58
|
+
isAnimating: createMemo(() => isEntering() || isExiting()),
|
|
59
|
+
isEntering,
|
|
60
|
+
isExiting,
|
|
61
|
+
phase
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
const itemShouldBeMounted = (item) => item !== false && item != null;
|
|
65
|
+
function createPresence(item, options) {
|
|
66
|
+
const initial = untrack(item);
|
|
67
|
+
const [mountedItem, setMountedItem] = createSignal(initial);
|
|
68
|
+
const [shouldBeMounted, setShouldBeMounted] = createSignal(itemShouldBeMounted(initial));
|
|
69
|
+
const { isMounted, ...rest } = createPresenceBase(shouldBeMounted, options);
|
|
70
|
+
createEffect(() => {
|
|
71
|
+
if (mountedItem() !== item()) {
|
|
72
|
+
if (isMounted()) setShouldBeMounted(false);
|
|
73
|
+
else if (itemShouldBeMounted(item())) {
|
|
74
|
+
setMountedItem(() => item());
|
|
75
|
+
setShouldBeMounted(true);
|
|
76
|
+
}
|
|
77
|
+
} else if (!itemShouldBeMounted(item())) setShouldBeMounted(false);
|
|
78
|
+
else if (itemShouldBeMounted(item())) setShouldBeMounted(true);
|
|
24
79
|
});
|
|
25
|
-
return
|
|
80
|
+
return {
|
|
81
|
+
...rest,
|
|
82
|
+
isMounted: () => isMounted() && isDefined(mountedItem()),
|
|
83
|
+
mountedItem
|
|
84
|
+
};
|
|
26
85
|
}
|
|
27
|
-
|
|
28
86
|
//#endregion
|
|
29
|
-
export { createPresence };
|
|
87
|
+
export { createPresence };
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import { MaybeAccessor } from "../types/maybe.mjs";
|
|
2
|
-
import "../types/index.mjs";
|
|
3
|
-
|
|
4
2
|
//#region src/solidjs/create-throttle.d.ts
|
|
5
3
|
declare function createThrottle<Args extends unknown[]>(callback: (...args: Args) => void, delay: MaybeAccessor<number>): (...args: Args) => void;
|
|
6
4
|
//#endregion
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { access } from "./utils.mjs";
|
|
2
2
|
import { onCleanup } from "solid-js";
|
|
3
|
-
|
|
4
3
|
//#region src/solidjs/create-throttle.ts
|
|
5
4
|
function createThrottle(callback, delay) {
|
|
6
5
|
let timeoutId;
|
|
@@ -16,6 +15,5 @@ function createThrottle(callback, delay) {
|
|
|
16
15
|
};
|
|
17
16
|
return run;
|
|
18
17
|
}
|
|
19
|
-
|
|
20
18
|
//#endregion
|
|
21
|
-
export { createThrottle };
|
|
19
|
+
export { createThrottle };
|
|
@@ -2,7 +2,6 @@ import { isObject } from "../utils/is.mjs";
|
|
|
2
2
|
import { access } from "./utils.mjs";
|
|
3
3
|
import { createWatch } from "./create-watch.mjs";
|
|
4
4
|
import { createSignal, onCleanup } from "solid-js";
|
|
5
|
-
|
|
6
5
|
//#region src/solidjs/create-visibility-observer.ts
|
|
7
6
|
function createVisibilityObserver(arg1, arg2) {
|
|
8
7
|
let target;
|
|
@@ -41,6 +40,5 @@ function createVisibilityObserver(arg1, arg2) {
|
|
|
41
40
|
if (target) return useVisibilityObserverFn(target);
|
|
42
41
|
return useVisibilityObserverFn;
|
|
43
42
|
}
|
|
44
|
-
|
|
45
43
|
//#endregion
|
|
46
|
-
export { createVisibilityObserver };
|
|
44
|
+
export { createVisibilityObserver };
|
package/dist/solidjs/index.d.mts
CHANGED
|
@@ -6,7 +6,7 @@ import { createEventListener } from "./create-event-listener.mjs";
|
|
|
6
6
|
import { createIntersectionObserver } from "./create-intersection-observer.mjs";
|
|
7
7
|
import { createList } from "./create-list.mjs";
|
|
8
8
|
import { createLoopExec } from "./create-loop-exec.mjs";
|
|
9
|
-
import {
|
|
9
|
+
import { MakePresenceOptions, PresencePhase, createPresence } from "./create-presence.mjs";
|
|
10
10
|
import { createThrottle } from "./create-throttle.mjs";
|
|
11
11
|
import { CreateVisibilityObserverOption, EntryCallback, UseVisibilityObserverFn, createVisibilityObserver } from "./create-visibility-observer.mjs";
|
|
12
12
|
import { createWatch } from "./create-watch.mjs";
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { Fn } from "../types/fn.mjs";
|
|
2
2
|
import { MaybeArray } from "../types/maybe.mjs";
|
|
3
|
-
import "../types/index.mjs";
|
|
4
|
-
|
|
5
3
|
//#region src/solidjs/make-event-listener.d.ts
|
|
6
4
|
interface InferEventTarget<Events> {
|
|
7
5
|
addEventListener: (event: Events, fn?: any, options?: any) => any;
|
|
@@ -2,7 +2,6 @@ import { isArray } from "../utils/is.mjs";
|
|
|
2
2
|
import { clearArray } from "../utils/array.mjs";
|
|
3
3
|
import { noop } from "../utils/constant.mjs";
|
|
4
4
|
import { onCleanup } from "solid-js";
|
|
5
|
-
|
|
6
5
|
//#region src/solidjs/make-event-listener.ts
|
|
7
6
|
/** biome-ignore-all lint/suspicious/noExplicitAny: I need any */
|
|
8
7
|
function makeEventListener(...args) {
|
|
@@ -30,6 +29,5 @@ function makeEventListener(...args) {
|
|
|
30
29
|
onCleanup(cleanup);
|
|
31
30
|
return cleanup;
|
|
32
31
|
}
|
|
33
|
-
|
|
34
32
|
//#endregion
|
|
35
|
-
export { makeEventListener };
|
|
33
|
+
export { makeEventListener };
|
package/dist/solidjs/utils.mjs
CHANGED
|
@@ -1,16 +1,21 @@
|
|
|
1
|
-
import { isFn } from "../utils/is.mjs";
|
|
2
|
-
|
|
1
|
+
import { isArray, isFn } from "../utils/is.mjs";
|
|
3
2
|
//#region src/solidjs/utils.ts
|
|
4
3
|
function access(value) {
|
|
5
4
|
return isFn(value) ? value() : value;
|
|
6
5
|
}
|
|
7
6
|
function runSolidEventHandler(event, handler) {
|
|
8
|
-
if (
|
|
9
|
-
|
|
7
|
+
if (isFn(handler)) {
|
|
8
|
+
handler(event);
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
if (isArray(handler)) {
|
|
12
|
+
const h = handler[0];
|
|
13
|
+
const data = handler[1];
|
|
14
|
+
h(data, event);
|
|
15
|
+
}
|
|
10
16
|
}
|
|
11
17
|
function callMaybeCallableChild(children, ...args) {
|
|
12
18
|
return isFn(children) ? children(...args) : children;
|
|
13
19
|
}
|
|
14
|
-
|
|
15
20
|
//#endregion
|
|
16
|
-
export { access, callMaybeCallableChild, runSolidEventHandler };
|
|
21
|
+
export { access, callMaybeCallableChild, runSolidEventHandler };
|
package/dist/utils/array.mjs
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { isFn } from "./is.mjs";
|
|
2
|
-
|
|
3
2
|
//#region src/utils/array.ts
|
|
4
3
|
/**
|
|
5
4
|
* Like a reduce but does not require an array.
|
|
@@ -52,15 +51,12 @@ function* range(startOrLength, end, valueOrMapper = (i) => i, step = 1) {
|
|
|
52
51
|
* list(0, 3, obj) // obj, obj, obj, obj
|
|
53
52
|
* list(0, 6, i => i, 2) // 0, 2, 4, 6
|
|
54
53
|
*/
|
|
55
|
-
const list = (startOrLength, end, valueOrMapper, step) =>
|
|
56
|
-
return Array.from(range(startOrLength, end, valueOrMapper, step));
|
|
57
|
-
};
|
|
54
|
+
const list = (startOrLength, end, valueOrMapper, step) => Array.from(range(startOrLength, end, valueOrMapper, step));
|
|
58
55
|
/**
|
|
59
56
|
* set arr.length to 0
|
|
60
57
|
*/
|
|
61
58
|
function clearArray(arr) {
|
|
62
59
|
arr.length = 0;
|
|
63
60
|
}
|
|
64
|
-
|
|
65
61
|
//#endregion
|
|
66
|
-
export { clearArray, iterate, list, range };
|
|
62
|
+
export { clearArray, iterate, list, range };
|
package/dist/utils/async.mjs
CHANGED
|
@@ -2,16 +2,11 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* Async wait
|
|
4
4
|
*/
|
|
5
|
-
const sleep = (milliseconds) =>
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
return requestAnimationFrame(() => {
|
|
10
|
-
requestAnimationFrame(() => {
|
|
11
|
-
cb();
|
|
12
|
-
});
|
|
5
|
+
const sleep = (milliseconds) => new Promise((res) => setTimeout(res, milliseconds));
|
|
6
|
+
const runAtNextAnimationFrame = (cb) => requestAnimationFrame(() => {
|
|
7
|
+
requestAnimationFrame(() => {
|
|
8
|
+
cb();
|
|
13
9
|
});
|
|
14
|
-
};
|
|
15
|
-
|
|
10
|
+
});
|
|
16
11
|
//#endregion
|
|
17
|
-
export { runAtNextAnimationFrame, sleep };
|
|
12
|
+
export { runAtNextAnimationFrame, sleep };
|
package/dist/utils/constant.mjs
CHANGED
package/dist/utils/is.mjs
CHANGED
|
@@ -1,14 +1,9 @@
|
|
|
1
1
|
import { isServer } from "solid-js/web";
|
|
2
|
-
|
|
3
2
|
//#region src/utils/is.ts
|
|
4
3
|
/** biome-ignore-all lint/suspicious/noExplicitAny: need any */
|
|
5
|
-
const isSymbol = (value) =>
|
|
6
|
-
return !!value && value.constructor === Symbol;
|
|
7
|
-
};
|
|
4
|
+
const isSymbol = (value) => !!value && value.constructor === Symbol;
|
|
8
5
|
const isArray = Array.isArray;
|
|
9
|
-
const isObject = (value) =>
|
|
10
|
-
return !!value && value.constructor === Object;
|
|
11
|
-
};
|
|
6
|
+
const isObject = (value) => !!value && value.constructor === Object;
|
|
12
7
|
/**
|
|
13
8
|
* Checks if the given value is primitive.
|
|
14
9
|
*
|
|
@@ -17,21 +12,11 @@ const isObject = (value) => {
|
|
|
17
12
|
* @param {*} value value to check
|
|
18
13
|
* @returns {boolean} result
|
|
19
14
|
*/
|
|
20
|
-
const isPrimitive = (value) =>
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
};
|
|
26
|
-
const isString = (value) => {
|
|
27
|
-
return typeof value === "string" || value instanceof String;
|
|
28
|
-
};
|
|
29
|
-
const isInt = (value) => {
|
|
30
|
-
return isNumber(value) && value % 1 === 0;
|
|
31
|
-
};
|
|
32
|
-
const isFloat = (value) => {
|
|
33
|
-
return isNumber(value) && value % 1 !== 0;
|
|
34
|
-
};
|
|
15
|
+
const isPrimitive = (value) => value === void 0 || value === null || typeof value !== "object" && typeof value !== "function";
|
|
16
|
+
const isFn = (value) => typeof value === "function";
|
|
17
|
+
const isString = (value) => typeof value === "string" || value instanceof String;
|
|
18
|
+
const isInt = (value) => isNumber(value) && value % 1 === 0;
|
|
19
|
+
const isFloat = (value) => isNumber(value) && value % 1 !== 0;
|
|
35
20
|
const isNumber = (value) => {
|
|
36
21
|
try {
|
|
37
22
|
return Number(value) === value;
|
|
@@ -39,9 +24,7 @@ const isNumber = (value) => {
|
|
|
39
24
|
return false;
|
|
40
25
|
}
|
|
41
26
|
};
|
|
42
|
-
const isDate = (value) =>
|
|
43
|
-
return Object.prototype.toString.call(value) === "[object Date]";
|
|
44
|
-
};
|
|
27
|
+
const isDate = (value) => Object.prototype.toString.call(value) === "[object Date]";
|
|
45
28
|
/**
|
|
46
29
|
* This is really a _best guess_ promise checking. You
|
|
47
30
|
* should probably use Promise.resolve(value) to be 100%
|
|
@@ -73,6 +56,5 @@ function isUndefined(value) {
|
|
|
73
56
|
function isDefined(value) {
|
|
74
57
|
return !isUndefined(value);
|
|
75
58
|
}
|
|
76
|
-
|
|
77
59
|
//#endregion
|
|
78
|
-
export { isArray, isClient, isDate, isDefined, isEmpty, isFloat, isFn, isInt, isNumber, isObject, isPrimitive, isPromise, isString, isSymbol, isUndefined };
|
|
60
|
+
export { isArray, isClient, isDate, isDefined, isEmpty, isFloat, isFn, isInt, isNumber, isObject, isPrimitive, isPromise, isString, isSymbol, isUndefined };
|
package/dist/utils/number.mjs
CHANGED
|
@@ -122,6 +122,5 @@ function inRange(x, minimum = 0, maximum = 1, inclusivity = "[]") {
|
|
|
122
122
|
function toHex(x, pad = 2) {
|
|
123
123
|
return x.toString(16).padStart(pad, "0");
|
|
124
124
|
}
|
|
125
|
-
|
|
126
125
|
//#endregion
|
|
127
|
-
export { clamp, inRange, max, min, toHex };
|
|
126
|
+
export { clamp, inRange, max, min, toHex };
|
package/dist/utils/random.mjs
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
import { iterate } from "./array.mjs";
|
|
2
|
-
|
|
3
2
|
//#region src/utils/random.ts
|
|
4
3
|
/**
|
|
5
4
|
* Generates a random number between min and max
|
|
6
5
|
*/
|
|
7
|
-
const random = (min, max) =>
|
|
8
|
-
return Math.floor(Math.random() * (max - min + 1) + min);
|
|
9
|
-
};
|
|
6
|
+
const random = (min, max) => Math.floor(Math.random() * (max - min + 1) + min);
|
|
10
7
|
/**
|
|
11
8
|
* Draw a random item from a list. Returns
|
|
12
9
|
* null if the list is empty
|
|
@@ -16,18 +13,13 @@ const draw = (array) => {
|
|
|
16
13
|
if (max === 0) return null;
|
|
17
14
|
return array[random(0, max - 1)];
|
|
18
15
|
};
|
|
19
|
-
const shuffle = (array) => {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
})).sort((a, b) => a.rand - b.rand).map((a) => a.value);
|
|
24
|
-
};
|
|
16
|
+
const shuffle = (array) => array.map((a) => ({
|
|
17
|
+
rand: Math.random(),
|
|
18
|
+
value: a
|
|
19
|
+
})).sort((a, b) => a.rand - b.rand).map((a) => a.value);
|
|
25
20
|
const uid = (length, specials = "") => {
|
|
26
21
|
const characters = `ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789${specials}`;
|
|
27
|
-
return iterate(length, (acc) =>
|
|
28
|
-
return acc + characters.charAt(random(0, characters.length - 1));
|
|
29
|
-
}, "");
|
|
22
|
+
return iterate(length, (acc) => acc + characters.charAt(random(0, characters.length - 1)), "");
|
|
30
23
|
};
|
|
31
|
-
|
|
32
24
|
//#endregion
|
|
33
|
-
export { draw, random, shuffle, uid };
|
|
25
|
+
export { draw, random, shuffle, uid };
|
package/dist/utils/str.mjs
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
const capitalize = (str) => {
|
|
9
9
|
if (!str || str.length === 0) return "";
|
|
10
10
|
const lower = str.toLowerCase();
|
|
11
|
-
return lower.
|
|
11
|
+
return lower.slice(0, 1).toUpperCase() + lower.slice(1, lower.length);
|
|
12
12
|
};
|
|
13
13
|
const splitRegexp = /(?=[A-Z])|[.\-\s_]/;
|
|
14
14
|
/**
|
|
@@ -22,9 +22,7 @@ const camel = (str) => {
|
|
|
22
22
|
const parts = str?.replace(/([A-Z])+/g, capitalize)?.split(splitRegexp).map((x) => x.toLowerCase()) ?? [];
|
|
23
23
|
if (parts.length === 0) return "";
|
|
24
24
|
if (parts.length === 1) return parts[0];
|
|
25
|
-
return parts.reduce((acc, part) => {
|
|
26
|
-
return `${acc}${part.charAt(0).toUpperCase()}${part.slice(1)}`;
|
|
27
|
-
});
|
|
25
|
+
return parts.reduce((acc, part) => `${acc}${part.charAt(0).toUpperCase()}${part.slice(1)}`);
|
|
28
26
|
};
|
|
29
27
|
const splitOnNumberRegexp = /([A-Za-z]{1}[0-9]{1})/;
|
|
30
28
|
/**
|
|
@@ -40,9 +38,7 @@ const snake = (str, options) => {
|
|
|
40
38
|
const parts = str?.replace(/([A-Z])+/g, capitalize).split(splitRegexp).map((x) => x.toLowerCase()) ?? [];
|
|
41
39
|
if (parts.length === 0) return "";
|
|
42
40
|
if (parts.length === 1) return parts[0];
|
|
43
|
-
const result = parts.reduce((acc, part) => {
|
|
44
|
-
return `${acc}_${part.toLowerCase()}`;
|
|
45
|
-
});
|
|
41
|
+
const result = parts.reduce((acc, part) => `${acc}_${part.toLowerCase()}`);
|
|
46
42
|
return options?.splitOnNumber === false ? result : result.replace(splitOnNumberRegexp, (val) => `${val[0]}_${val[1]}`);
|
|
47
43
|
};
|
|
48
44
|
/**
|
|
@@ -56,9 +52,7 @@ const dash = (str) => {
|
|
|
56
52
|
const parts = str?.replace(/([A-Z])+/g, capitalize)?.split(splitRegexp).map((x) => x.toLowerCase()) ?? [];
|
|
57
53
|
if (parts.length === 0) return "";
|
|
58
54
|
if (parts.length === 1) return parts[0];
|
|
59
|
-
return parts.reduce((acc, part) => {
|
|
60
|
-
return `${acc}-${part.toLowerCase()}`;
|
|
61
|
-
});
|
|
55
|
+
return parts.reduce((acc, part) => `${acc}-${part.toLowerCase()}`);
|
|
62
56
|
};
|
|
63
57
|
const pascalSplitRegexp = /[.\-\s_]/;
|
|
64
58
|
/**
|
|
@@ -91,11 +85,7 @@ const title = (str) => {
|
|
|
91
85
|
* Ex. template('Hello, {{name}}', { name: 'ray' })
|
|
92
86
|
* Ex. template('Hello, <name>', { name: 'ray' }, /<(.+?)>/g)
|
|
93
87
|
*/
|
|
94
|
-
const template = (str, data, regex = /\{\{(.+?)\}\}/g) =>
|
|
95
|
-
return Array.from(str.matchAll(regex)).reduce((acc, match) => {
|
|
96
|
-
return acc.replace(match[0], data[match[1]]);
|
|
97
|
-
}, str);
|
|
98
|
-
};
|
|
88
|
+
const template = (str, data, regex = /\{\{(.+?)\}\}/g) => Array.from(str.matchAll(regex)).reduce((acc, match) => acc.replace(match[0], data[match[1]]), str);
|
|
99
89
|
/**
|
|
100
90
|
* Trims all prefix and suffix characters from the given
|
|
101
91
|
* string. Like the builtin trim function but accepts
|
|
@@ -115,6 +105,5 @@ const trim = (str, charsToTrim = " ") => {
|
|
|
115
105
|
const regex = new RegExp(`^[${toTrim}]+|[${toTrim}]+$`, "g");
|
|
116
106
|
return str.replace(regex, "");
|
|
117
107
|
};
|
|
118
|
-
|
|
119
108
|
//#endregion
|
|
120
|
-
export { camel, capitalize, dash, pascal, snake, template, title, trim };
|
|
109
|
+
export { camel, capitalize, dash, pascal, snake, template, title, trim };
|
package/package.json
CHANGED
|
@@ -1,39 +1,48 @@
|
|
|
1
1
|
{
|
|
2
|
-
"name": "solid-tiny-utils",
|
|
3
|
-
"version": "0.11.0",
|
|
4
|
-
"description": "A collection of tiny utilities for SolidJS applications",
|
|
5
|
-
"main": "./dist/index.mjs",
|
|
6
|
-
"type": "module",
|
|
7
|
-
"files": [
|
|
8
|
-
"dist"
|
|
9
|
-
],
|
|
10
|
-
"sideEffects": false,
|
|
11
|
-
"peerDependencies": {
|
|
12
|
-
"solid-js": "^1.9.7"
|
|
13
|
-
},
|
|
14
2
|
"devDependencies": {
|
|
15
|
-
"@biomejs/biome": "2.
|
|
3
|
+
"@biomejs/biome": "2.4.15",
|
|
16
4
|
"@formkit/auto-animate": "^0.9.0",
|
|
17
|
-
"@solidjs/router": "^0.
|
|
5
|
+
"@solidjs/router": "^0.16.1",
|
|
18
6
|
"@solidjs/testing-library": "^0.8.10",
|
|
19
7
|
"@testing-library/jest-dom": "^6.9.1",
|
|
20
8
|
"@testing-library/user-event": "^14.6.1",
|
|
21
9
|
"@types/culori": "^4.0.0",
|
|
22
10
|
"@types/node": "^25.0.3",
|
|
23
|
-
"@typescript/native-preview": "7.0.0-dev.
|
|
11
|
+
"@typescript/native-preview": "7.0.0-dev.20260421.2",
|
|
24
12
|
"@vitest/ui": "^4.0.16",
|
|
25
|
-
"bumpp": "^
|
|
13
|
+
"bumpp": "^11.1.0",
|
|
26
14
|
"culori": "^4.0.2",
|
|
27
|
-
"jsdom": "^
|
|
28
|
-
"solid-tiny-context": "0.
|
|
29
|
-
"tsdown": "^0.
|
|
30
|
-
"ultracite": "7.0
|
|
31
|
-
"unocss": "^66.
|
|
32
|
-
"vite": "^
|
|
33
|
-
"vite-plugin-solid": "^2.11.
|
|
34
|
-
"vite-plugin-solid-pages": "^0.3
|
|
15
|
+
"jsdom": "^29.1.1",
|
|
16
|
+
"solid-tiny-context": "0.3.1",
|
|
17
|
+
"tsdown": "^0.22.0",
|
|
18
|
+
"ultracite": "7.7.0",
|
|
19
|
+
"unocss": "^66.7.0",
|
|
20
|
+
"vite": "^8.0.14",
|
|
21
|
+
"vite-plugin-solid": "^2.11.12",
|
|
22
|
+
"vite-plugin-solid-pages": "^0.4.3",
|
|
35
23
|
"vitest": "^4.0.16"
|
|
36
24
|
},
|
|
25
|
+
"name": "solid-tiny-utils",
|
|
26
|
+
"peerDependencies": {
|
|
27
|
+
"solid-js": "^1.9.7"
|
|
28
|
+
},
|
|
29
|
+
"type": "module",
|
|
30
|
+
"version": "0.12.1",
|
|
31
|
+
"description": "A collection of tiny utilities for SolidJS applications",
|
|
32
|
+
"author": "solid tiny",
|
|
33
|
+
"license": "MIT",
|
|
34
|
+
"homepage": "https://github.com/sxl-cc/solid-tiny-utils#readme",
|
|
35
|
+
"repository": {
|
|
36
|
+
"type": "git",
|
|
37
|
+
"url": "git+https://github.com/sxl-cc/solid-tiny-utils.git"
|
|
38
|
+
},
|
|
39
|
+
"bugs": {
|
|
40
|
+
"url": "https://github.com/sxl-cc/solid-tiny-utils/issues"
|
|
41
|
+
},
|
|
42
|
+
"files": [
|
|
43
|
+
"dist"
|
|
44
|
+
],
|
|
45
|
+
"sideEffects": false,
|
|
37
46
|
"keywords": [
|
|
38
47
|
"solidjs",
|
|
39
48
|
"solid",
|
|
@@ -41,9 +50,6 @@
|
|
|
41
50
|
"typescript",
|
|
42
51
|
"utils"
|
|
43
52
|
],
|
|
44
|
-
"author": "",
|
|
45
|
-
"license": "MIT",
|
|
46
|
-
"module": "./dist/index.mjs",
|
|
47
53
|
"types": "./dist/index.d.mts",
|
|
48
54
|
"exports": {
|
|
49
55
|
".": "./dist/index.mjs",
|
|
@@ -52,14 +58,14 @@
|
|
|
52
58
|
"scripts": {
|
|
53
59
|
"build": "tsdown",
|
|
54
60
|
"dev": "vite -c ./playground/vite.config.ts",
|
|
55
|
-
"test": "vitest
|
|
61
|
+
"test": "vitest run",
|
|
56
62
|
"clean": "rimraf dist node_modules pnpm-lock.yaml",
|
|
57
63
|
"test:ui": "vitest --ui",
|
|
58
|
-
"
|
|
59
|
-
"
|
|
60
|
-
"
|
|
61
|
-
"
|
|
62
|
-
"
|
|
63
|
-
"
|
|
64
|
+
"tc": "tsgo --noEmit --skipLibCheck",
|
|
65
|
+
"bump": "pnpm bumpp --no-push",
|
|
66
|
+
"prepublish": "pnpm build",
|
|
67
|
+
"check": "ultracite check",
|
|
68
|
+
"check:error": "ultracite check --diagnostic-level error",
|
|
69
|
+
"fix": "ultracite fix"
|
|
64
70
|
}
|
|
65
71
|
}
|