solid-tiny-utils 0.7.1 → 0.8.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 (134) hide show
  1. package/README.md +9 -9
  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 +12 -0
  19. package/dist/event/index.mjs +15 -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/event/on-motion-end.d.mts +63 -0
  23. package/dist/event/on-motion-end.mjs +96 -0
  24. package/dist/fn/create-debounce.d.mts +7 -0
  25. package/dist/fn/create-debounce.mjs +20 -0
  26. package/dist/fn/{create-loop-exec.d.ts → create-loop-exec.d.mts} +7 -6
  27. package/dist/fn/create-loop-exec.mjs +59 -0
  28. package/dist/fn/create-throttle.d.mts +7 -0
  29. package/dist/fn/create-throttle.mjs +21 -0
  30. package/dist/fn/index.d.mts +8 -0
  31. package/dist/fn/index.mjs +9 -0
  32. package/dist/index.d.mts +30 -0
  33. package/dist/index.mjs +27 -0
  34. package/dist/jsx/{attrs.d.ts → attrs.d.mts} +3 -2
  35. package/dist/jsx/attrs.mjs +26 -0
  36. package/dist/reactive/access.d.mts +6 -0
  37. package/dist/reactive/access.mjs +9 -0
  38. package/dist/reactive/{create-debounce-watch.d.ts → create-debounce-watch.d.mts} +6 -4
  39. package/dist/reactive/create-debounce-watch.mjs +15 -0
  40. package/dist/reactive/{create-watch.d.ts → create-watch.d.mts} +4 -3
  41. package/dist/reactive/create-watch.mjs +9 -0
  42. package/dist/reactive/index.d.mts +3 -0
  43. package/dist/types/{fn.d.ts → fn.d.mts} +3 -2
  44. package/dist/types/index.d.mts +2 -0
  45. package/dist/types/{maybe.d.ts → maybe.d.mts} +4 -3
  46. package/dist/utils/{array.d.ts → array.d.mts} +3 -2
  47. package/dist/utils/array.mjs +66 -0
  48. package/dist/utils/async.d.mts +8 -0
  49. package/dist/utils/async.mjs +17 -0
  50. package/dist/utils/{is.d.ts → is.d.mts} +3 -2
  51. package/dist/utils/is.mjs +72 -0
  52. package/dist/utils/{number.d.ts → number.d.mts} +3 -2
  53. package/dist/utils/number.mjs +127 -0
  54. package/dist/utils/{random.d.ts → random.d.mts} +3 -2
  55. package/dist/utils/random.mjs +33 -0
  56. package/dist/utils/{str.d.ts → str.d.mts} +4 -3
  57. package/dist/utils/str.mjs +120 -0
  58. package/package.json +22 -19
  59. package/dist/chunk-4L6FK7MF.js +0 -9
  60. package/dist/chunk-6G7GFZV2.js +0 -93
  61. package/dist/chunk-6OVLJ45M.js +0 -51
  62. package/dist/chunk-ACZGS7DG.js +0 -72
  63. package/dist/chunk-AZAXMGEB.js +0 -0
  64. package/dist/chunk-BLX3XSA6.js +0 -0
  65. package/dist/chunk-BT47ISVC.js +0 -36
  66. package/dist/chunk-EZML2DEC.js +0 -0
  67. package/dist/chunk-FFBJP5FE.js +0 -0
  68. package/dist/chunk-II6INKPZ.js +0 -8
  69. package/dist/chunk-KFLH3AZ6.js +0 -40
  70. package/dist/chunk-KKFGUHFR.js +0 -8
  71. package/dist/chunk-KM4Q6THD.js +0 -50
  72. package/dist/chunk-LEWF7QAQ.js +0 -47
  73. package/dist/chunk-LUFOWTRW.js +0 -0
  74. package/dist/chunk-PD6VHMH6.js +0 -26
  75. package/dist/chunk-QPEF6LHH.js +0 -111
  76. package/dist/chunk-QQVSG76Z.js +0 -36
  77. package/dist/chunk-S7U3LZNS.js +0 -23
  78. package/dist/chunk-SK6Y2YH6.js +0 -0
  79. package/dist/chunk-TDJLPDJF.js +0 -66
  80. package/dist/chunk-TGWWPUWD.js +0 -55
  81. package/dist/chunk-U5LQ2AS5.js +0 -0
  82. package/dist/chunk-WJHRONQU.js +0 -54
  83. package/dist/chunk-Y4GYGFIT.js +0 -85
  84. package/dist/chunk-YK5QQQ43.js +0 -12
  85. package/dist/chunk-YXRZ2KMJ.js +0 -0
  86. package/dist/color/hex-rgb.js +0 -15
  87. package/dist/color/index.d.ts +0 -3
  88. package/dist/color/index.js +0 -30
  89. package/dist/color/oklch-rgb.js +0 -15
  90. package/dist/color/validation.js +0 -18
  91. package/dist/dom/css.js +0 -19
  92. package/dist/dom/index.d.ts +0 -2
  93. package/dist/dom/index.js +0 -20
  94. package/dist/event/create-click-outside.d.ts +0 -8
  95. package/dist/event/create-click-outside.js +0 -17
  96. package/dist/event/create-event-listener.js +0 -17
  97. package/dist/event/create-intersection-observer.js +0 -16
  98. package/dist/event/create-visibility-observer.js +0 -16
  99. package/dist/event/index.d.ts +0 -8
  100. package/dist/event/index.js +0 -33
  101. package/dist/event/make-event-listener.js +0 -16
  102. package/dist/fn/create-debounce.d.ts +0 -6
  103. package/dist/fn/create-debounce.js +0 -15
  104. package/dist/fn/create-loop-exec.js +0 -15
  105. package/dist/fn/create-throttle.d.ts +0 -6
  106. package/dist/fn/create-throttle.js +0 -15
  107. package/dist/fn/index.d.ts +0 -9
  108. package/dist/fn/index.js +0 -21
  109. package/dist/index.d.ts +0 -27
  110. package/dist/index.js +0 -166
  111. package/dist/jsx/attrs.js +0 -6
  112. package/dist/jsx/index.d.ts +0 -1
  113. package/dist/jsx/index.js +0 -7
  114. package/dist/reactive/access.d.ts +0 -6
  115. package/dist/reactive/access.js +0 -13
  116. package/dist/reactive/create-debounce-watch.js +0 -15
  117. package/dist/reactive/create-watch.js +0 -6
  118. package/dist/reactive/index.d.ts +0 -5
  119. package/dist/reactive/index.js +0 -21
  120. package/dist/types/fn.js +0 -1
  121. package/dist/types/index.d.ts +0 -3
  122. package/dist/types/index.js +0 -3
  123. package/dist/types/maybe.js +0 -1
  124. package/dist/utils/array.js +0 -13
  125. package/dist/utils/async.d.ts +0 -6
  126. package/dist/utils/async.js +0 -6
  127. package/dist/utils/index.d.ts +0 -6
  128. package/dist/utils/index.js +0 -85
  129. package/dist/utils/is.js +0 -30
  130. package/dist/utils/number.js +0 -14
  131. package/dist/utils/object.d.ts +0 -10
  132. package/dist/utils/object.js +0 -7
  133. package/dist/utils/random.js +0 -14
  134. package/dist/utils/str.js +0 -20
@@ -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
- };
@@ -1,40 +0,0 @@
1
- import {
2
- isArray
3
- } from "./chunk-6G7GFZV2.js";
4
- import {
5
- clamp,
6
- toHex
7
- } from "./chunk-PD6VHMH6.js";
8
-
9
- // src/color/hex-rgb.ts
10
- var HEX_PREFIX_REGEX = /^#/;
11
- var HEX_VALIDATION_REGEX = /^[0-9a-fA-F]{6}$/;
12
- function hexToRgb(hex) {
13
- if (!hex || typeof hex !== "string") {
14
- return null;
15
- }
16
- let value = hex.trim().replace(HEX_PREFIX_REGEX, "");
17
- if (value.length === 3) {
18
- value = value.split("").map((c) => c + c).join("");
19
- }
20
- if (!HEX_VALIDATION_REGEX.test(value)) {
21
- return null;
22
- }
23
- const r = Number.parseInt(value.slice(0, 2), 16);
24
- const g = Number.parseInt(value.slice(2, 4), 16);
25
- const b = Number.parseInt(value.slice(4, 6), 16);
26
- return { r, g, b };
27
- }
28
- function rgbToHex(rgb) {
29
- const c = (v) => Math.round(clamp(v, 0, 255));
30
- const rgb_ = isArray(rgb) ? rgb : [rgb.r, rgb.g, rgb.b];
31
- const r = c(rgb_[0]);
32
- const g = c(rgb_[1]);
33
- const b = c(rgb_[2]);
34
- return `#${toHex(r)}${toHex(g)}${toHex(b)}`;
35
- }
36
-
37
- export {
38
- hexToRgb,
39
- rgbToHex
40
- };
@@ -1,8 +0,0 @@
1
- // src/utils/async.ts
2
- var sleep = (milliseconds) => {
3
- return new Promise((res) => setTimeout(res, milliseconds));
4
- };
5
-
6
- export {
7
- sleep
8
- };
@@ -1,50 +0,0 @@
1
- import {
2
- isClient
3
- } from "./chunk-6G7GFZV2.js";
4
-
5
- // src/dom/css.ts
6
- var alreadyInjected = [];
7
- function mountStyle(style, id, refresh = false) {
8
- if (!isClient) {
9
- return;
10
- }
11
- if (alreadyInjected.includes(id) && !refresh) {
12
- return;
13
- }
14
- let styleElement = document.querySelector(`style#${id}`);
15
- if (styleElement) {
16
- styleElement.innerHTML = style;
17
- return;
18
- }
19
- styleElement = document.createElement("style");
20
- styleElement.id = id;
21
- styleElement.innerHTML = style;
22
- document.head.appendChild(styleElement);
23
- alreadyInjected.push(id);
24
- }
25
- var extractCSSregex = /((?:--)?(?:\w+-?)+)\s*:\s*([^;]*)/g;
26
- function stringStyleToObject(style) {
27
- const object = {};
28
- let match = extractCSSregex.exec(style);
29
- while (match) {
30
- if (match[1] && match[2]) {
31
- object[match[1]] = match[2];
32
- }
33
- match = extractCSSregex.exec(style);
34
- }
35
- return object;
36
- }
37
- function combineStyle(a, b) {
38
- const bb = typeof b === "string" ? stringStyleToObject(b) : b;
39
- return { ...a, ...bb };
40
- }
41
- function combineClass(defaultClass, ...otherClass) {
42
- return [defaultClass, ...otherClass].filter(Boolean).join(" ");
43
- }
44
-
45
- export {
46
- mountStyle,
47
- stringStyleToObject,
48
- combineStyle,
49
- combineClass
50
- };
@@ -1,47 +0,0 @@
1
- import {
2
- noop
3
- } from "./chunk-QPEF6LHH.js";
4
- import {
5
- access
6
- } from "./chunk-YK5QQQ43.js";
7
- import {
8
- createWatch
9
- } from "./chunk-4L6FK7MF.js";
10
- import {
11
- clearArray
12
- } from "./chunk-BT47ISVC.js";
13
-
14
- // src/event/create-intersection-observer.ts
15
- import { onCleanup } from "solid-js";
16
- import { isServer } from "solid-js/web";
17
- function createIntersectionObserver(targets, callback, options = {}) {
18
- if (isServer) {
19
- return noop;
20
- }
21
- const io = new IntersectionObserver(callback, options);
22
- onCleanup(() => io.disconnect());
23
- const cleanups = [];
24
- const cleanup = () => {
25
- for (const c of cleanups) {
26
- c();
27
- }
28
- clearArray(cleanups);
29
- };
30
- createWatch(
31
- () => targets.map(access),
32
- (elements) => {
33
- cleanup();
34
- for (const element of elements) {
35
- if (element) {
36
- io.observe(element);
37
- cleanups.push(() => io.unobserve(element));
38
- }
39
- }
40
- }
41
- );
42
- return () => io.disconnect();
43
- }
44
-
45
- export {
46
- createIntersectionObserver
47
- };
File without changes
@@ -1,26 +0,0 @@
1
- // src/utils/number.ts
2
- function min(...numbers) {
3
- return Math.min(...numbers);
4
- }
5
- function max(...numbers) {
6
- return Math.max(...numbers);
7
- }
8
- function clamp(x, minimum = 0, maximum = 1) {
9
- return min(maximum, max(minimum, x));
10
- }
11
- function inRange(x, minimum = 0, maximum = 1, inclusivity = "[]") {
12
- const minCheck = inclusivity[0] === "[" ? x >= minimum : x > minimum;
13
- const maxCheck = inclusivity[1] === "]" ? x <= maximum : x < maximum;
14
- return minCheck && maxCheck;
15
- }
16
- function toHex(x, pad = 2) {
17
- return x.toString(16).padStart(pad, "0");
18
- }
19
-
20
- export {
21
- min,
22
- max,
23
- clamp,
24
- inRange,
25
- toHex
26
- };
@@ -1,111 +0,0 @@
1
- import {
2
- access
3
- } from "./chunk-YK5QQQ43.js";
4
- import {
5
- createWatch
6
- } from "./chunk-4L6FK7MF.js";
7
- import {
8
- isNumber
9
- } from "./chunk-6G7GFZV2.js";
10
-
11
- // src/fn/create-debounce.ts
12
- import { onCleanup as onCleanup3 } from "solid-js";
13
-
14
- // src/fn/create-loop-exec.ts
15
- import { onCleanup } from "solid-js";
16
- function createLoopExec(fn, delay) {
17
- let shouldStop = false;
18
- let isCleanedUp = false;
19
- let timer;
20
- const execFn = async () => {
21
- clearTimeout(timer);
22
- const d = access(delay);
23
- if (shouldStop || !isNumber(d) || d < 0) {
24
- return;
25
- }
26
- try {
27
- await fn();
28
- } finally {
29
- timer = setTimeout(() => {
30
- execFn();
31
- }, d);
32
- }
33
- };
34
- createWatch(
35
- () => access(delay),
36
- () => {
37
- execFn();
38
- }
39
- );
40
- const stop = () => {
41
- shouldStop = true;
42
- clearTimeout(timer);
43
- };
44
- const start = () => {
45
- if (isCleanedUp) {
46
- return;
47
- }
48
- shouldStop = false;
49
- execFn();
50
- };
51
- onCleanup(() => {
52
- isCleanedUp = true;
53
- stop();
54
- });
55
- return {
56
- stop,
57
- start
58
- };
59
- }
60
-
61
- // src/fn/create-throttle.ts
62
- import { onCleanup as onCleanup2 } from "solid-js";
63
- function createThrottle(callback, delay) {
64
- let timeoutId;
65
- onCleanup2(() => {
66
- clearTimeout(timeoutId);
67
- });
68
- const run = (...args) => {
69
- if (timeoutId) {
70
- return;
71
- }
72
- timeoutId = setTimeout(() => {
73
- callback(...args);
74
- timeoutId = void 0;
75
- }, access(delay));
76
- };
77
- return run;
78
- }
79
-
80
- // src/fn/index.ts
81
- var noop = () => {
82
- };
83
-
84
- // src/reactive/create-debounce-watch.ts
85
- function createDebouncedWatch(targets, fn, opt) {
86
- const debounceFn = createDebounce(fn, opt?.delay ?? 10);
87
- createWatch(targets, debounceFn, opt);
88
- }
89
-
90
- // src/fn/create-debounce.ts
91
- function createDebounce(callback, delay) {
92
- let timeoutId;
93
- onCleanup3(() => {
94
- clearTimeout(timeoutId);
95
- });
96
- const run = (...args) => {
97
- clearTimeout(timeoutId);
98
- timeoutId = setTimeout(() => {
99
- callback(...args);
100
- }, access(delay));
101
- };
102
- return run;
103
- }
104
-
105
- export {
106
- createDebounce,
107
- createLoopExec,
108
- createThrottle,
109
- noop,
110
- createDebouncedWatch
111
- };
@@ -1,36 +0,0 @@
1
- import {
2
- iterate
3
- } from "./chunk-BT47ISVC.js";
4
-
5
- // src/utils/random.ts
6
- var random = (min, max) => {
7
- return Math.floor(Math.random() * (max - min + 1) + min);
8
- };
9
- var draw = (array) => {
10
- const max = array.length;
11
- if (max === 0) {
12
- return null;
13
- }
14
- const index = random(0, max - 1);
15
- return array[index];
16
- };
17
- var shuffle = (array) => {
18
- return array.map((a) => ({ rand: Math.random(), value: a })).sort((a, b) => a.rand - b.rand).map((a) => a.value);
19
- };
20
- var uid = (length, specials = "") => {
21
- const characters = `ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789${specials}`;
22
- return iterate(
23
- length,
24
- (acc) => {
25
- return acc + characters.charAt(random(0, characters.length - 1));
26
- },
27
- ""
28
- );
29
- };
30
-
31
- export {
32
- random,
33
- draw,
34
- shuffle,
35
- uid
36
- };
@@ -1,23 +0,0 @@
1
- import {
2
- hexToRgb
3
- } from "./chunk-KFLH3AZ6.js";
4
- import {
5
- inRange
6
- } from "./chunk-PD6VHMH6.js";
7
-
8
- // src/color/validation.ts
9
- function isValidRGB(rgb) {
10
- return Object.values(rgb).every((x) => inRange(x, 0, 255));
11
- }
12
- function isValidOKLCH(oklch) {
13
- return inRange(oklch.l) && oklch.c >= 0 && inRange(oklch.h, 0, 360);
14
- }
15
- function isValidHex(hex) {
16
- return hexToRgb(hex) !== null;
17
- }
18
-
19
- export {
20
- isValidRGB,
21
- isValidOKLCH,
22
- isValidHex
23
- };
File without changes
@@ -1,66 +0,0 @@
1
- import {
2
- access
3
- } from "./chunk-YK5QQQ43.js";
4
- import {
5
- createWatch
6
- } from "./chunk-4L6FK7MF.js";
7
- import {
8
- isObject
9
- } from "./chunk-6G7GFZV2.js";
10
-
11
- // src/event/create-visibility-observer.ts
12
- import { createSignal, onCleanup } from "solid-js";
13
- function createVisibilityObserver(arg1, arg2) {
14
- let target;
15
- let options;
16
- if (arg1 && !isObject(arg1)) {
17
- target = arg1;
18
- options = arg2 ?? {};
19
- } else {
20
- options = arg1 ?? {};
21
- }
22
- const callbacks = /* @__PURE__ */ new WeakMap();
23
- const io = new IntersectionObserver((entries, instance) => {
24
- for (const entry of entries) {
25
- callbacks.get(entry.target)?.(entry, instance);
26
- }
27
- }, options);
28
- onCleanup(() => io.disconnect());
29
- const addEntry = (el, callback) => {
30
- io.observe(el);
31
- callbacks.set(el, callback);
32
- };
33
- const removeEntry = (el) => {
34
- io.unobserve(el);
35
- callbacks.delete(el);
36
- };
37
- const useVisibilityObserverFn = (element) => {
38
- const [isVisible, setVisible] = createSignal(
39
- options?.initialValue ?? false
40
- );
41
- let prevEl;
42
- createWatch(
43
- () => access(element),
44
- (el) => {
45
- if (prevEl) {
46
- removeEntry(prevEl);
47
- }
48
- if (el) {
49
- addEntry(el, (entry) => {
50
- setVisible(entry.isIntersecting);
51
- });
52
- prevEl = el;
53
- }
54
- }
55
- );
56
- return isVisible;
57
- };
58
- if (target) {
59
- return useVisibilityObserverFn(target);
60
- }
61
- return useVisibilityObserverFn;
62
- }
63
-
64
- export {
65
- createVisibilityObserver
66
- };
@@ -1,55 +0,0 @@
1
- import {
2
- noop
3
- } from "./chunk-QPEF6LHH.js";
4
- import {
5
- clearArray
6
- } from "./chunk-BT47ISVC.js";
7
- import {
8
- isArray
9
- } from "./chunk-6G7GFZV2.js";
10
-
11
- // src/event/make-event-listener.ts
12
- import { onCleanup } from "solid-js";
13
- function makeEventListener(...args) {
14
- let target;
15
- let events;
16
- let listeners;
17
- let options;
18
- if (typeof args[0] === "string" || isArray(args[0])) {
19
- [events, listeners, options] = args;
20
- target = window;
21
- } else {
22
- [target, events, listeners, options] = args;
23
- }
24
- if (!target) {
25
- return noop;
26
- }
27
- if (!isArray(events)) {
28
- events = [events];
29
- }
30
- if (!isArray(listeners)) {
31
- listeners = [listeners];
32
- }
33
- const cleanups = [];
34
- const cleanup = () => {
35
- for (const c of cleanups) {
36
- c();
37
- }
38
- clearArray(cleanups);
39
- };
40
- const register = (el, event, listener, opts) => {
41
- el.addEventListener(event, listener, opts);
42
- return () => el.removeEventListener(event, listener, opts);
43
- };
44
- cleanups.push(
45
- ...events.flatMap(
46
- (event) => listeners.map((listener) => register(target, event, listener, options))
47
- )
48
- );
49
- onCleanup(cleanup);
50
- return cleanup;
51
- }
52
-
53
- export {
54
- makeEventListener
55
- };
File without changes
@@ -1,54 +0,0 @@
1
- import {
2
- makeEventListener
3
- } from "./chunk-TGWWPUWD.js";
4
- import {
5
- access
6
- } from "./chunk-YK5QQQ43.js";
7
-
8
- // src/event/create-click-outside.ts
9
- function createClickOutside(target, handler, options) {
10
- let shouldListen = false;
11
- const shouldIgnore = (event) => {
12
- const ignore = (options?.ignore ? options.ignore : []).map(access);
13
- return ignore.some((el) => {
14
- return el && (event.target === el || event.composedPath().includes(el));
15
- });
16
- };
17
- const listener = (e) => {
18
- const el = access(target);
19
- if (!el || el === e.target || e.composedPath().includes(el)) {
20
- return;
21
- }
22
- if (e.detail === 0) {
23
- shouldListen = !shouldIgnore(e);
24
- }
25
- if (!shouldListen) {
26
- shouldListen = true;
27
- return;
28
- }
29
- handler(e);
30
- };
31
- const cleanups = [
32
- makeEventListener("click", listener, { passive: true }),
33
- makeEventListener(
34
- "pointerdown",
35
- (e) => {
36
- const el = access(target);
37
- if (el) {
38
- shouldListen = !(e.composedPath().includes(el) || shouldIgnore(e));
39
- }
40
- },
41
- { passive: true }
42
- )
43
- ];
44
- const stop = () => {
45
- for (const cleanup of cleanups) {
46
- cleanup();
47
- }
48
- };
49
- return stop;
50
- }
51
-
52
- export {
53
- createClickOutside
54
- };