solid-tiny-utils 0.7.1 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (132) hide show
  1. package/LICENSE +21 -21
  2. package/dist/color/{hex-rgb.d.ts → hex-rgb.d.mts} +5 -3
  3. package/dist/color/hex-rgb.mjs +62 -0
  4. package/dist/color/{oklch-rgb.d.ts → oklch-rgb.d.mts} +9 -8
  5. package/dist/color/oklch-rgb.mjs +101 -0
  6. package/dist/color/{validation.d.ts → validation.d.mts} +5 -3
  7. package/dist/color/validation.mjs +35 -0
  8. package/dist/dom/{css.d.ts → css.d.mts} +5 -3
  9. package/dist/dom/css.mjs +51 -0
  10. package/dist/event/create-click-outside.d.mts +9 -0
  11. package/dist/event/create-click-outside.mjs +33 -0
  12. package/dist/event/{create-event-listener.d.ts → create-event-listener.d.mts} +7 -6
  13. package/dist/event/create-event-listener.mjs +34 -0
  14. package/dist/event/{create-intersection-observer.d.ts → create-intersection-observer.d.mts} +5 -4
  15. package/dist/event/create-intersection-observer.mjs +29 -0
  16. package/dist/event/{create-visibility-observer.d.ts → create-visibility-observer.d.mts} +7 -5
  17. package/dist/event/create-visibility-observer.mjs +46 -0
  18. package/dist/event/index.d.mts +11 -0
  19. package/dist/event/index.mjs +14 -0
  20. package/dist/event/{make-event-listener.d.ts → make-event-listener.d.mts} +8 -7
  21. package/dist/event/make-event-listener.mjs +35 -0
  22. package/dist/fn/create-debounce.d.mts +7 -0
  23. package/dist/fn/create-debounce.mjs +20 -0
  24. package/dist/fn/{create-loop-exec.d.ts → create-loop-exec.d.mts} +7 -6
  25. package/dist/fn/create-loop-exec.mjs +59 -0
  26. package/dist/fn/create-throttle.d.mts +7 -0
  27. package/dist/fn/create-throttle.mjs +21 -0
  28. package/dist/fn/index.d.mts +8 -0
  29. package/dist/fn/index.mjs +9 -0
  30. package/dist/index.d.mts +29 -0
  31. package/dist/index.mjs +26 -0
  32. package/dist/jsx/{attrs.d.ts → attrs.d.mts} +3 -2
  33. package/dist/jsx/attrs.mjs +26 -0
  34. package/dist/reactive/access.d.mts +6 -0
  35. package/dist/reactive/access.mjs +9 -0
  36. package/dist/reactive/{create-debounce-watch.d.ts → create-debounce-watch.d.mts} +6 -4
  37. package/dist/reactive/create-debounce-watch.mjs +15 -0
  38. package/dist/reactive/{create-watch.d.ts → create-watch.d.mts} +4 -3
  39. package/dist/reactive/create-watch.mjs +9 -0
  40. package/dist/reactive/index.d.mts +3 -0
  41. package/dist/types/{fn.d.ts → fn.d.mts} +3 -2
  42. package/dist/types/index.d.mts +2 -0
  43. package/dist/types/{maybe.d.ts → maybe.d.mts} +4 -3
  44. package/dist/utils/{array.d.ts → array.d.mts} +3 -2
  45. package/dist/utils/array.mjs +66 -0
  46. package/dist/utils/async.d.mts +8 -0
  47. package/dist/utils/async.mjs +17 -0
  48. package/dist/utils/{is.d.ts → is.d.mts} +3 -2
  49. package/dist/utils/is.mjs +72 -0
  50. package/dist/utils/{number.d.ts → number.d.mts} +3 -2
  51. package/dist/utils/number.mjs +127 -0
  52. package/dist/utils/{random.d.ts → random.d.mts} +3 -2
  53. package/dist/utils/random.mjs +33 -0
  54. package/dist/utils/{str.d.ts → str.d.mts} +4 -3
  55. package/dist/utils/str.mjs +120 -0
  56. package/package.json +25 -22
  57. package/dist/chunk-4L6FK7MF.js +0 -9
  58. package/dist/chunk-6G7GFZV2.js +0 -93
  59. package/dist/chunk-6OVLJ45M.js +0 -51
  60. package/dist/chunk-ACZGS7DG.js +0 -72
  61. package/dist/chunk-AZAXMGEB.js +0 -0
  62. package/dist/chunk-BLX3XSA6.js +0 -0
  63. package/dist/chunk-BT47ISVC.js +0 -36
  64. package/dist/chunk-EZML2DEC.js +0 -0
  65. package/dist/chunk-FFBJP5FE.js +0 -0
  66. package/dist/chunk-II6INKPZ.js +0 -8
  67. package/dist/chunk-KFLH3AZ6.js +0 -40
  68. package/dist/chunk-KKFGUHFR.js +0 -8
  69. package/dist/chunk-KM4Q6THD.js +0 -50
  70. package/dist/chunk-LEWF7QAQ.js +0 -47
  71. package/dist/chunk-LUFOWTRW.js +0 -0
  72. package/dist/chunk-PD6VHMH6.js +0 -26
  73. package/dist/chunk-QPEF6LHH.js +0 -111
  74. package/dist/chunk-QQVSG76Z.js +0 -36
  75. package/dist/chunk-S7U3LZNS.js +0 -23
  76. package/dist/chunk-SK6Y2YH6.js +0 -0
  77. package/dist/chunk-TDJLPDJF.js +0 -66
  78. package/dist/chunk-TGWWPUWD.js +0 -55
  79. package/dist/chunk-U5LQ2AS5.js +0 -0
  80. package/dist/chunk-WJHRONQU.js +0 -54
  81. package/dist/chunk-Y4GYGFIT.js +0 -85
  82. package/dist/chunk-YK5QQQ43.js +0 -12
  83. package/dist/chunk-YXRZ2KMJ.js +0 -0
  84. package/dist/color/hex-rgb.js +0 -15
  85. package/dist/color/index.d.ts +0 -3
  86. package/dist/color/index.js +0 -30
  87. package/dist/color/oklch-rgb.js +0 -15
  88. package/dist/color/validation.js +0 -18
  89. package/dist/dom/css.js +0 -19
  90. package/dist/dom/index.d.ts +0 -2
  91. package/dist/dom/index.js +0 -20
  92. package/dist/event/create-click-outside.d.ts +0 -8
  93. package/dist/event/create-click-outside.js +0 -17
  94. package/dist/event/create-event-listener.js +0 -17
  95. package/dist/event/create-intersection-observer.js +0 -16
  96. package/dist/event/create-visibility-observer.js +0 -16
  97. package/dist/event/index.d.ts +0 -8
  98. package/dist/event/index.js +0 -33
  99. package/dist/event/make-event-listener.js +0 -16
  100. package/dist/fn/create-debounce.d.ts +0 -6
  101. package/dist/fn/create-debounce.js +0 -15
  102. package/dist/fn/create-loop-exec.js +0 -15
  103. package/dist/fn/create-throttle.d.ts +0 -6
  104. package/dist/fn/create-throttle.js +0 -15
  105. package/dist/fn/index.d.ts +0 -9
  106. package/dist/fn/index.js +0 -21
  107. package/dist/index.d.ts +0 -27
  108. package/dist/index.js +0 -166
  109. package/dist/jsx/attrs.js +0 -6
  110. package/dist/jsx/index.d.ts +0 -1
  111. package/dist/jsx/index.js +0 -7
  112. package/dist/reactive/access.d.ts +0 -6
  113. package/dist/reactive/access.js +0 -13
  114. package/dist/reactive/create-debounce-watch.js +0 -15
  115. package/dist/reactive/create-watch.js +0 -6
  116. package/dist/reactive/index.d.ts +0 -5
  117. package/dist/reactive/index.js +0 -21
  118. package/dist/types/fn.js +0 -1
  119. package/dist/types/index.d.ts +0 -3
  120. package/dist/types/index.js +0 -3
  121. package/dist/types/maybe.js +0 -1
  122. package/dist/utils/array.js +0 -13
  123. package/dist/utils/async.d.ts +0 -6
  124. package/dist/utils/async.js +0 -6
  125. package/dist/utils/index.d.ts +0 -6
  126. package/dist/utils/index.js +0 -85
  127. package/dist/utils/is.js +0 -30
  128. package/dist/utils/number.js +0 -14
  129. package/dist/utils/object.d.ts +0 -10
  130. package/dist/utils/object.js +0 -7
  131. package/dist/utils/random.js +0 -14
  132. package/dist/utils/str.js +0 -20
@@ -0,0 +1,127 @@
1
+ //#region src/utils/number.ts
2
+ /**
3
+ * Returns the smallest of the given numbers.
4
+ *
5
+ * This is a convenience wrapper around `Math.min` that provides better type safety
6
+ * and consistency with other utility functions.
7
+ *
8
+ * @param numbers - The numbers to compare
9
+ * @returns The smallest number from the input
10
+ *
11
+ * @example
12
+ * ```typescript
13
+ * min(1, 2, 3) // => 1
14
+ * min(-5, 0, 10) // => -5
15
+ * min(3.14, 2.71, 1.41) // => 1.41
16
+ * ```
17
+ */
18
+ function min(...numbers) {
19
+ return Math.min(...numbers);
20
+ }
21
+ /**
22
+ * Returns the largest of the given numbers.
23
+ *
24
+ * This is a convenience wrapper around `Math.max` that provides better type safety
25
+ * and consistency with other utility functions.
26
+ *
27
+ * @param numbers - The numbers to compare
28
+ * @returns The largest number from the input
29
+ *
30
+ * @example
31
+ * ```typescript
32
+ * max(1, 2, 3) // => 3
33
+ * max(-5, 0, 10) // => 10
34
+ * max(3.14, 2.71, 1.41) // => 3.14
35
+ * ```
36
+ */
37
+ function max(...numbers) {
38
+ return Math.max(...numbers);
39
+ }
40
+ /**
41
+ * Clamps a number to within the specified bounds.
42
+ *
43
+ * If the number is less than the minimum, returns the minimum.
44
+ * If the number is greater than the maximum, returns the maximum.
45
+ * Otherwise, returns the number unchanged.
46
+ *
47
+ * @param x - The number to clamp
48
+ * @param minimum - The lower bound (inclusive)
49
+ * @param maximum - The upper bound (inclusive)
50
+ * @returns The clamped number
51
+ *
52
+ * @example
53
+ * ```typescript
54
+ * clamp(0.5) // => 0.5 (within default 0-1 range)
55
+ * clamp(-0.1) // => 0 (clamped to minimum)
56
+ * clamp(1.5) // => 1 (clamped to maximum)
57
+ * clamp(15, 10, 20) // => 15 (within range)
58
+ * clamp(5, 10, 20) // => 10 (clamped to minimum)
59
+ * clamp(25, 10, 20) // => 20 (clamped to maximum)
60
+ * ```
61
+ */
62
+ function clamp(x, minimum = 0, maximum = 1) {
63
+ return min(maximum, max(minimum, x));
64
+ }
65
+ /**
66
+ * Checks if a number is within a specified range.
67
+ *
68
+ * Supports different inclusivity modes:
69
+ * - `'[]'` - Both bounds inclusive (default): `minimum ≤ x ≤ maximum`
70
+ * - `'()'` - Both bounds exclusive: `minimum < x < maximum`
71
+ * - `'[)'` - Lower inclusive, upper exclusive: `minimum ≤ x < maximum`
72
+ * - `'(]'` - Lower exclusive, upper inclusive: `minimum < x ≤ maximum`
73
+ *
74
+ * @param x - The number to check
75
+ * @param minimum - The lower bound of the range
76
+ * @param maximum - The upper bound of the range
77
+ * @param inclusivity - Specifies whether the bounds are inclusive or exclusive
78
+ * @returns `true` if the number is within the range, `false` otherwise
79
+ *
80
+ * @example
81
+ * ```typescript
82
+ * // Default inclusive range [0, 1]
83
+ * inRange(0.5) // => true
84
+ * inRange(0) // => true (inclusive)
85
+ * inRange(1) // => true (inclusive)
86
+ * inRange(-0.1) // => false
87
+ * inRange(1.1) // => false
88
+ *
89
+ * // Custom range [10, 20]
90
+ * inRange(15, 10, 20) // => true
91
+ * inRange(10, 10, 20) // => true (inclusive)
92
+ * inRange(20, 10, 20) // => true (inclusive)
93
+ *
94
+ * // Exclusive bounds (10, 20)
95
+ * inRange(15, 10, 20, '()') // => true
96
+ * inRange(10, 10, 20, '()') // => false (exclusive)
97
+ * inRange(20, 10, 20, '()') // => false (exclusive)
98
+ *
99
+ * // Mixed inclusivity [10, 20)
100
+ * inRange(10, 10, 20, '[)') // => true (lower inclusive)
101
+ * inRange(20, 10, 20, '[)') // => false (upper exclusive)
102
+ * ```
103
+ */
104
+ function inRange(x, minimum = 0, maximum = 1, inclusivity = "[]") {
105
+ const minCheck = inclusivity[0] === "[" ? x >= minimum : x > minimum;
106
+ const maxCheck = inclusivity[1] === "]" ? x <= maximum : x < maximum;
107
+ return minCheck && maxCheck;
108
+ }
109
+ /**
110
+ * Converts a number to a hexadecimal string.
111
+ *
112
+ * @param x - The number to convert
113
+ * @param pad - The number of digits to pad the output with (default: 2)
114
+ * @returns The hexadecimal representation of the number
115
+ *
116
+ * @example
117
+ * ```typescript
118
+ * toHEX(255) // => "ff"
119
+ * toHEX(255, 4) // => "00ff"
120
+ * ```
121
+ */
122
+ function toHex(x, pad = 2) {
123
+ return x.toString(16).padStart(pad, "0");
124
+ }
125
+
126
+ //#endregion
127
+ export { clamp, inRange, max, min, toHex };
@@ -1,3 +1,4 @@
1
+ //#region src/utils/random.d.ts
1
2
  /**
2
3
  * Generates a random number between min and max
3
4
  */
@@ -9,5 +10,5 @@ declare const random: (min: number, max: number) => number;
9
10
  declare const draw: <T>(array: readonly T[]) => T | null;
10
11
  declare const shuffle: <T>(array: readonly T[]) => T[];
11
12
  declare const uid: (length: number, specials?: string) => string;
12
-
13
- export { draw, random, shuffle, uid };
13
+ //#endregion
14
+ export { draw, random, shuffle, uid };
@@ -0,0 +1,33 @@
1
+ import { iterate } from "./array.mjs";
2
+
3
+ //#region src/utils/random.ts
4
+ /**
5
+ * Generates a random number between min and max
6
+ */
7
+ const random = (min, max) => {
8
+ return Math.floor(Math.random() * (max - min + 1) + min);
9
+ };
10
+ /**
11
+ * Draw a random item from a list. Returns
12
+ * null if the list is empty
13
+ */
14
+ const draw = (array) => {
15
+ const max = array.length;
16
+ if (max === 0) return null;
17
+ return array[random(0, max - 1)];
18
+ };
19
+ const shuffle = (array) => {
20
+ return array.map((a) => ({
21
+ rand: Math.random(),
22
+ value: a
23
+ })).sort((a, b) => a.rand - b.rand).map((a) => a.value);
24
+ };
25
+ const uid = (length, specials = "") => {
26
+ const characters = `ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789${specials}`;
27
+ return iterate(length, (acc) => {
28
+ return acc + characters.charAt(random(0, characters.length - 1));
29
+ }, "");
30
+ };
31
+
32
+ //#endregion
33
+ export { draw, random, shuffle, uid };
@@ -1,3 +1,4 @@
1
+ //#region src/utils/str.d.ts
1
2
  /**
2
3
  * Capitalize the first word of the string
3
4
  *
@@ -23,7 +24,7 @@ declare const camel: (str: string) => string;
23
24
  * snake('helloWord') -> 'hello_world'
24
25
  */
25
26
  declare const snake: (str: string, options?: {
26
- splitOnNumber?: boolean;
27
+ splitOnNumber?: boolean;
27
28
  }) => string;
28
29
  /**
29
30
  * Formats the given string in dash case fashion
@@ -71,5 +72,5 @@ declare const template: (str: string, data: Record<string, any>, regex?: RegExp)
71
72
  * ```
72
73
  */
73
74
  declare const trim: (str: string | null | undefined, charsToTrim?: string) => string;
74
-
75
- export { camel, capitalize, dash, pascal, snake, template, title, trim };
75
+ //#endregion
76
+ export { camel, capitalize, dash, pascal, snake, template, title, trim };
@@ -0,0 +1,120 @@
1
+ //#region src/utils/str.ts
2
+ /**
3
+ * Capitalize the first word of the string
4
+ *
5
+ * capitalize('hello') -> 'Hello'
6
+ * capitalize('va va voom') -> 'Va va voom'
7
+ */
8
+ const capitalize = (str) => {
9
+ if (!str || str.length === 0) return "";
10
+ const lower = str.toLowerCase();
11
+ return lower.substring(0, 1).toUpperCase() + lower.substring(1, lower.length);
12
+ };
13
+ const splitRegexp = /(?=[A-Z])|[.\-\s_]/;
14
+ /**
15
+ * Formats the given string in camel case fashion
16
+ *
17
+ * camel('hello world') -> 'helloWorld'
18
+ * camel('va va-VOOM') -> 'vaVaVoom'
19
+ * camel('helloWorld') -> 'helloWorld'
20
+ */
21
+ const camel = (str) => {
22
+ const parts = str?.replace(/([A-Z])+/g, capitalize)?.split(splitRegexp).map((x) => x.toLowerCase()) ?? [];
23
+ if (parts.length === 0) return "";
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
+ });
28
+ };
29
+ const splitOnNumberRegexp = /([A-Za-z]{1}[0-9]{1})/;
30
+ /**
31
+ * Formats the given string in snake case fashion
32
+ *
33
+ * splitOnNumber? Treat number as capital, default is true
34
+ *
35
+ * snake('hello world') -> 'hello_world'
36
+ * snake('va va-VOOM') -> 'va_va_voom'
37
+ * snake('helloWord') -> 'hello_world'
38
+ */
39
+ const snake = (str, options) => {
40
+ const parts = str?.replace(/([A-Z])+/g, capitalize).split(splitRegexp).map((x) => x.toLowerCase()) ?? [];
41
+ if (parts.length === 0) return "";
42
+ if (parts.length === 1) return parts[0];
43
+ const result = parts.reduce((acc, part) => {
44
+ return `${acc}_${part.toLowerCase()}`;
45
+ });
46
+ return options?.splitOnNumber === false ? result : result.replace(splitOnNumberRegexp, (val) => `${val[0]}_${val[1]}`);
47
+ };
48
+ /**
49
+ * Formats the given string in dash case fashion
50
+ *
51
+ * dash('hello world') -> 'hello-world'
52
+ * dash('va va_VOOM') -> 'va-va-voom'
53
+ * dash('helloWord') -> 'hello-word'
54
+ */
55
+ const dash = (str) => {
56
+ const parts = str?.replace(/([A-Z])+/g, capitalize)?.split(splitRegexp).map((x) => x.toLowerCase()) ?? [];
57
+ if (parts.length === 0) return "";
58
+ if (parts.length === 1) return parts[0];
59
+ return parts.reduce((acc, part) => {
60
+ return `${acc}-${part.toLowerCase()}`;
61
+ });
62
+ };
63
+ const pascalSplitRegexp = /[.\-\s_]/;
64
+ /**
65
+ * Formats the given string in pascal case fashion
66
+ *
67
+ * pascal('hello world') -> 'HelloWorld'
68
+ * pascal('va va boom') -> 'VaVaBoom'
69
+ */
70
+ const pascal = (str) => {
71
+ const parts = str?.split(pascalSplitRegexp).map((x) => x.toLowerCase()) ?? [];
72
+ if (parts.length === 0) return "";
73
+ return parts.map((s) => s.charAt(0).toUpperCase() + s.slice(1)).join("");
74
+ };
75
+ /**
76
+ * Formats the given string in title case fashion
77
+ *
78
+ * title('hello world') -> 'Hello World'
79
+ * title('va_va_boom') -> 'Va Va Boom'
80
+ * title('root-hook') -> 'Root Hook'
81
+ * title('queryItems') -> 'Query Items'
82
+ */
83
+ const title = (str) => {
84
+ if (!str) return "";
85
+ return str.split(splitRegexp).map((s) => s.trim()).filter((s) => !!s).map((s) => capitalize(s.toLowerCase())).join(" ");
86
+ };
87
+ /**
88
+ * template is used to replace data by name in template strings.
89
+ * The default expression looks for {{name}} to identify names.
90
+ *
91
+ * Ex. template('Hello, {{name}}', { name: 'ray' })
92
+ * Ex. template('Hello, <name>', { name: 'ray' }, /<(.+?)>/g)
93
+ */
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
+ };
99
+ /**
100
+ * Trims all prefix and suffix characters from the given
101
+ * string. Like the builtin trim function but accepts
102
+ * other characters you would like to trim and trims
103
+ * multiple characters.
104
+ *
105
+ * ```typescript
106
+ * trim(' hello ') // => 'hello'
107
+ * trim('__hello__', '_') // => 'hello'
108
+ * trim('/repos/:owner/:repo/', '/') // => 'repos/:owner/:repo'
109
+ * trim('222222__hello__1111111', '12_') // => 'hello'
110
+ * ```
111
+ */
112
+ const trim = (str, charsToTrim = " ") => {
113
+ if (!str) return "";
114
+ const toTrim = charsToTrim.replace(/[\W]{1}/g, "\\$&");
115
+ const regex = new RegExp(`^[${toTrim}]+|[${toTrim}]+$`, "g");
116
+ return str.replace(regex, "");
117
+ };
118
+
119
+ //#endregion
120
+ export { camel, capitalize, dash, pascal, snake, template, title, trim };
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "solid-tiny-utils",
3
- "version": "0.7.1",
3
+ "version": "0.9.0",
4
4
  "description": "A collection of tiny utilities for SolidJS applications",
5
- "main": "./dist/index.js",
5
+ "main": "./dist/index.mjs",
6
6
  "type": "module",
7
7
  "files": [
8
8
  "dist"
@@ -12,49 +12,52 @@
12
12
  "solid-js": "^1.9.7"
13
13
  },
14
14
  "devDependencies": {
15
- "@biomejs/biome": "2.2.2",
16
- "@solidjs/router": "^0.15.3",
15
+ "@biomejs/biome": "2.3.10",
16
+ "@solidjs/router": "^0.15.4",
17
17
  "@solidjs/testing-library": "^0.8.10",
18
- "@testing-library/jest-dom": "^6.6.4",
18
+ "@testing-library/jest-dom": "^6.9.1",
19
19
  "@testing-library/user-event": "^14.6.1",
20
20
  "@types/culori": "^4.0.0",
21
- "@types/node": "^24.2.1",
22
- "@vitest/ui": "^3.2.4",
21
+ "@types/node": "^25.0.3",
22
+ "@typescript/native-preview": "7.0.0-dev.20251226.1",
23
+ "@vitest/ui": "^4.0.16",
23
24
  "bumpp": "^10.2.3",
24
25
  "culori": "^4.0.2",
25
- "husky": "^9.1.7",
26
- "jsdom": "^26.1.0",
27
- "tsup": "^8.5.0",
28
- "typescript": "^5.8.3",
29
- "ultracite": "5.3.3",
26
+ "jsdom": "^27.3.0",
27
+ "solid-tiny-context": "0.2.3",
28
+ "tsdown": "^0.18.3",
29
+ "ultracite": "6.5.0",
30
30
  "unocss": "^66.3.3",
31
- "vite": "^6.2.1",
31
+ "vite": "^7.3.0",
32
32
  "vite-plugin-solid": "^2.11.0",
33
- "vite-plugin-solid-pages": "^0.3.4",
34
- "vitest": "^3.2.4"
33
+ "vite-plugin-solid-pages": "^0.3.5",
34
+ "vitest": "^4.0.16"
35
35
  },
36
36
  "keywords": [
37
37
  "solidjs",
38
38
  "solid",
39
- "utilities",
40
39
  "reactive",
41
40
  "typescript",
42
41
  "utils"
43
42
  ],
44
43
  "author": "",
45
44
  "license": "MIT",
46
- "dependencies": {
47
- "solid-tiny-context": "0.2.3"
45
+ "module": "./dist/index.mjs",
46
+ "types": "./dist/index.d.mts",
47
+ "exports": {
48
+ ".": "./dist/index.mjs",
49
+ "./package.json": "./package.json"
48
50
  },
49
51
  "scripts": {
50
- "build": "tsup",
52
+ "build": "tsdown",
51
53
  "dev": "vite -c ./playground/vite.config.ts",
52
54
  "test": "vitest --run",
53
55
  "clean": "rimraf dist node_modules pnpm-lock.yaml",
54
56
  "test:ui": "vitest --ui",
55
- "lint": "pnpm dlx ultracite check",
56
- "lint:fix": "pnpm dlx ultracite fix",
57
- "type-check": "tsc --noEmit --skipLibCheck",
57
+ "lint": "pnpm dlx ultracite@latest check",
58
+ "lint:error": "pnpm dlx ultracite@latest check --diagnostic-level error",
59
+ "lint:fix": "pnpm dlx ultracite@latest fix",
60
+ "type-check": "tsgo --noEmit --skipLibCheck",
58
61
  "bump": "pnpm type-check && pnpm lint:fix && pnpm test && pnpm bumpp --no-push",
59
62
  "prepublish": "pnpm build"
60
63
  }
@@ -1,9 +0,0 @@
1
- // src/reactive/create-watch.ts
2
- import { createEffect, on } from "solid-js";
3
- function createWatch(targets, fn, opt) {
4
- createEffect(on(targets, fn, opt));
5
- }
6
-
7
- export {
8
- createWatch
9
- };
@@ -1,93 +0,0 @@
1
- // src/utils/is.ts
2
- import { isServer } from "solid-js/web";
3
- var isSymbol = (value) => {
4
- return !!value && value.constructor === Symbol;
5
- };
6
- var isArray = Array.isArray;
7
- var isObject = (value) => {
8
- return !!value && value.constructor === Object;
9
- };
10
- var isPrimitive = (value) => {
11
- return value === void 0 || value === null || typeof value !== "object" && typeof value !== "function";
12
- };
13
- var isFn = (value) => {
14
- return !!(value && value.constructor && value.call && value.apply);
15
- };
16
- var isString = (value) => {
17
- return typeof value === "string" || value instanceof String;
18
- };
19
- var isInt = (value) => {
20
- return isNumber(value) && value % 1 === 0;
21
- };
22
- var isFloat = (value) => {
23
- return isNumber(value) && value % 1 !== 0;
24
- };
25
- var isNumber = (value) => {
26
- try {
27
- return Number(value) === value;
28
- } catch {
29
- return false;
30
- }
31
- };
32
- var isDate = (value) => {
33
- return Object.prototype.toString.call(value) === "[object Date]";
34
- };
35
- var isPromise = (value) => {
36
- if (!value) {
37
- return false;
38
- }
39
- if (!value.then) {
40
- return false;
41
- }
42
- if (!isFn(value.then)) {
43
- return false;
44
- }
45
- return true;
46
- };
47
- var isEmpty = (value) => {
48
- if (value === true || value === false) {
49
- return true;
50
- }
51
- if (value === null || value === void 0) {
52
- return true;
53
- }
54
- if (isNumber(value)) {
55
- return value === 0;
56
- }
57
- if (isDate(value)) {
58
- return isNaN(value.getTime());
59
- }
60
- if (isFn(value)) {
61
- return false;
62
- }
63
- if (isSymbol(value)) {
64
- return false;
65
- }
66
- const length = value.length;
67
- if (isNumber(length)) {
68
- return length === 0;
69
- }
70
- const size = value.size;
71
- if (isNumber(size)) {
72
- return size === 0;
73
- }
74
- const keys = Object.keys(value).length;
75
- return keys === 0;
76
- };
77
- var isClient = !isServer;
78
-
79
- export {
80
- isSymbol,
81
- isArray,
82
- isObject,
83
- isPrimitive,
84
- isFn,
85
- isString,
86
- isInt,
87
- isFloat,
88
- isNumber,
89
- isDate,
90
- isPromise,
91
- isEmpty,
92
- isClient
93
- };
@@ -1,51 +0,0 @@
1
- import {
2
- makeEventListener
3
- } from "./chunk-TGWWPUWD.js";
4
- import {
5
- noop
6
- } from "./chunk-QPEF6LHH.js";
7
- import {
8
- access
9
- } from "./chunk-YK5QQQ43.js";
10
- import {
11
- createWatch
12
- } from "./chunk-4L6FK7MF.js";
13
- import {
14
- clearArray
15
- } from "./chunk-BT47ISVC.js";
16
- import {
17
- isArray
18
- } from "./chunk-6G7GFZV2.js";
19
-
20
- // src/event/create-event-listener.ts
21
- function createEventListener(...args) {
22
- const target = args[0];
23
- const events = args[1];
24
- let listeners = args[2];
25
- const options = args[3] ?? noop;
26
- if (!isArray(listeners)) {
27
- listeners = [listeners];
28
- }
29
- const cleanups = [];
30
- const cleanup = () => {
31
- for (const c of cleanups) {
32
- c();
33
- }
34
- clearArray(cleanups);
35
- };
36
- createWatch(
37
- () => [access(target), access(events), access(options)],
38
- ([tars, evs, opts]) => {
39
- cleanup();
40
- if (!(tars && evs)) {
41
- return;
42
- }
43
- cleanups.push(makeEventListener(tars, evs, listeners, opts));
44
- }
45
- );
46
- return cleanup;
47
- }
48
-
49
- export {
50
- createEventListener
51
- };
@@ -1,72 +0,0 @@
1
- import {
2
- clamp,
3
- max
4
- } from "./chunk-PD6VHMH6.js";
5
-
6
- // src/color/oklch-rgb.ts
7
- var PI_180 = Math.PI / 180;
8
- var INV_PI_180 = 180 / Math.PI;
9
- var linearToSRGB = (x) => x <= 31308e-7 ? 12.92 * x : 1.055 * x ** (1 / 2.4) - 0.055;
10
- var sRGBToLinear = (x) => x <= 0.04045 ? x / 12.92 : ((x + 0.055) / 1.055) ** 2.4;
11
- function normalizeHue(hue) {
12
- return (hue % 360 + 360) % 360;
13
- }
14
- function oklchToRgb(oklch) {
15
- const { l, c, h } = oklch;
16
- const clampedL = clamp(l, 0, 1);
17
- const clampedC = max(0, c);
18
- const normalizedH = normalizeHue(h);
19
- const a_ = clampedC * Math.cos(normalizedH * PI_180);
20
- const b_ = clampedC * Math.sin(normalizedH * PI_180);
21
- const L = clampedL;
22
- const A = a_;
23
- const B = b_;
24
- const l_ = L + 0.3963377774 * A + 0.2158037573 * B;
25
- const m_ = L - 0.1055613458 * A - 0.0638541728 * B;
26
- const s_ = L - 0.0894841775 * A - 1.291485548 * B;
27
- const l3 = l_ ** 3;
28
- const m3 = m_ ** 3;
29
- const s3 = s_ ** 3;
30
- let r = 4.0767416621 * l3 - 3.3077115913 * m3 + 0.2309699292 * s3;
31
- let g = -1.2684380046 * l3 + 2.6097574011 * m3 - 0.3413193965 * s3;
32
- let b = -0.0041960863 * l3 - 0.7034186147 * m3 + 1.707614701 * s3;
33
- r = linearToSRGB(r);
34
- g = linearToSRGB(g);
35
- b = linearToSRGB(b);
36
- return {
37
- r: Math.round(clamp(r) * 255),
38
- g: Math.round(clamp(g) * 255),
39
- b: Math.round(clamp(b) * 255)
40
- };
41
- }
42
- function rgbToOklch(rgb) {
43
- const r = clamp(rgb.r, 0, 255);
44
- const g = clamp(rgb.g, 0, 255);
45
- const b = clamp(rgb.b, 0, 255);
46
- const rLinear = sRGBToLinear(r / 255);
47
- const gLinear = sRGBToLinear(g / 255);
48
- const bLinear = sRGBToLinear(b / 255);
49
- const l_ = Math.cbrt(
50
- 0.4122214708 * rLinear + 0.5363325363 * gLinear + 0.0514459929 * bLinear
51
- );
52
- const m_ = Math.cbrt(
53
- 0.2119034982 * rLinear + 0.6806995451 * gLinear + 0.1073969566 * bLinear
54
- );
55
- const s_ = Math.cbrt(
56
- 0.0883024619 * rLinear + 0.2817188376 * gLinear + 0.6299787005 * bLinear
57
- );
58
- const L = 0.2104542553 * l_ + 0.793617785 * m_ - 0.0040720468 * s_;
59
- const A = 1.9779984951 * l_ - 2.428592205 * m_ + 0.4505937099 * s_;
60
- const B = 0.0259040371 * l_ + 0.7827717662 * m_ - 0.808675766 * s_;
61
- const c = Math.sqrt(A * A + B * B);
62
- let h = Math.atan2(B, A) * INV_PI_180;
63
- if (h < 0) {
64
- h += 360;
65
- }
66
- return { l: L, c, h };
67
- }
68
-
69
- export {
70
- oklchToRgb,
71
- rgbToOklch
72
- };
File without changes
File without changes
@@ -1,36 +0,0 @@
1
- import {
2
- isFn
3
- } from "./chunk-6G7GFZV2.js";
4
-
5
- // src/utils/array.ts
6
- var iterate = (count, func, initValue) => {
7
- let value = initValue;
8
- for (let i = 1; i <= count; i++) {
9
- value = func(value, i);
10
- }
11
- return value;
12
- };
13
- function* range(startOrLength, end, valueOrMapper = (i) => i, step = 1) {
14
- const mapper = isFn(valueOrMapper) ? valueOrMapper : () => valueOrMapper;
15
- const start = end ? startOrLength : 0;
16
- const final = end ?? startOrLength;
17
- for (let i = start; i <= final; i += step) {
18
- yield mapper(i);
19
- if (i + step > final) {
20
- break;
21
- }
22
- }
23
- }
24
- var list = (startOrLength, end, valueOrMapper, step) => {
25
- return Array.from(range(startOrLength, end, valueOrMapper, step));
26
- };
27
- function clearArray(arr) {
28
- arr.length = 0;
29
- }
30
-
31
- export {
32
- iterate,
33
- range,
34
- list,
35
- clearArray
36
- };
File without changes
File without changes
@@ -1,8 +0,0 @@
1
- // src/jsx/attrs.ts
2
- function dataIf(show) {
3
- return show ? "" : void 0;
4
- }
5
-
6
- export {
7
- dataIf
8
- };