solid-tiny-utils 0.2.0 → 0.4.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 (58) hide show
  1. package/README.md +0 -68
  2. package/dist/chunk-BGLY6NJK.js +111 -0
  3. package/dist/{chunk-WLQ64SAO.js → chunk-CSAKXWF3.js} +5 -1
  4. package/dist/{chunk-YJB637I2.js → chunk-HPKVQC7S.js} +4 -3
  5. package/dist/chunk-II6INKPZ.js +8 -0
  6. package/dist/chunk-KFWZFQMB.js +8 -0
  7. package/dist/chunk-KLRTXD4R.js +53 -0
  8. package/dist/chunk-OUAI75QC.js +55 -0
  9. package/dist/{chunk-RRYFZNKE.js → chunk-PBALVUKK.js} +1 -1
  10. package/dist/chunk-PNR5G432.js +85 -0
  11. package/dist/chunk-YXRZ2KMJ.js +0 -0
  12. package/dist/dom/css.js +5 -3
  13. package/dist/dom/index.js +5 -3
  14. package/dist/event/create-click-outside.js +8 -5
  15. package/dist/event/create-event-listener.d.ts +23 -0
  16. package/dist/event/create-event-listener.js +16 -0
  17. package/dist/event/index.d.ts +3 -0
  18. package/dist/event/index.js +17 -7
  19. package/dist/event/make-event-listener.d.ts +49 -0
  20. package/dist/event/make-event-listener.js +15 -0
  21. package/dist/fn/create-debounce.js +6 -5
  22. package/dist/fn/create-loop-exec.js +6 -5
  23. package/dist/fn/create-throttle.d.ts +6 -0
  24. package/dist/fn/create-throttle.js +14 -0
  25. package/dist/fn/index.d.ts +1 -0
  26. package/dist/fn/index.js +10 -11
  27. package/dist/index.d.ts +9 -1
  28. package/dist/index.js +50 -13
  29. package/dist/jsx/attrs.d.ts +22 -0
  30. package/dist/jsx/attrs.js +6 -0
  31. package/dist/jsx/index.d.ts +1 -0
  32. package/dist/jsx/index.js +7 -0
  33. package/dist/lodash/array.d.ts +5 -1
  34. package/dist/lodash/array.js +3 -1
  35. package/dist/lodash/async.d.ts +6 -0
  36. package/dist/lodash/async.js +6 -0
  37. package/dist/lodash/index.d.ts +3 -1
  38. package/dist/lodash/index.js +27 -3
  39. package/dist/lodash/random.js +2 -2
  40. package/dist/lodash/str.d.ts +75 -0
  41. package/dist/lodash/str.js +20 -0
  42. package/dist/reactive/access.js +5 -3
  43. package/dist/reactive/create-debounce-watch.d.ts +12 -0
  44. package/dist/reactive/create-debounce-watch.js +14 -0
  45. package/dist/reactive/index.d.ts +1 -0
  46. package/dist/reactive/index.js +9 -4
  47. package/dist/types/fn.d.ts +2 -1
  48. package/dist/types/fn.js +1 -0
  49. package/dist/types/index.d.ts +1 -0
  50. package/dist/types/index.js +2 -1
  51. package/package.json +1 -2
  52. package/dist/chunk-2BGAGVTR.js +0 -7
  53. package/dist/chunk-H6VUVMSF.js +0 -23
  54. package/dist/chunk-WY5G2PJM.js +0 -60
  55. /package/dist/{chunk-2BUPSB7O.js → chunk-AZAXMGEB.js} +0 -0
  56. /package/dist/{chunk-33ZRZ4S2.js → chunk-B6TZK2S5.js} +0 -0
  57. /package/dist/{chunk-M53KPXWR.js → chunk-OECLQ3OT.js} +0 -0
  58. /package/dist/{chunk-ZZNAXGNU.js → chunk-SK6Y2YH6.js} +0 -0
package/README.md CHANGED
@@ -7,71 +7,3 @@ Tiny utilities for SolidJS applications.
7
7
  ```bash
8
8
  pnpm add solid-tiny-utils
9
9
  ```
10
-
11
- ## Usage
12
-
13
- ```typescript
14
- import { access, createWatch, CreateLoopExec, isFn, isArray } from 'solid-tiny-utils';
15
- ```
16
-
17
- ## API
18
-
19
- ### Reactive
20
-
21
- #### `access(value)`
22
- Safely access a value that might be an accessor function.
23
-
24
- ```typescript
25
- const value = access(maybeAccessor); // Returns the value directly or calls the accessor
26
- ```
27
-
28
- #### `createWatch(targets, fn, options?)`
29
- Create a watcher that runs when dependencies change.
30
-
31
- ```typescript
32
- createWatch(() => signal(), (value) => {
33
- console.log('Value changed:', value);
34
- });
35
- ```
36
-
37
- ### Functions
38
-
39
- #### `CreateLoopExec(fn, delay)`
40
- Execute a function in a loop with cleanup support.
41
-
42
- ```typescript
43
- CreateLoopExec(
44
- async () => {
45
- // Your async work here
46
- },
47
- 1000 // Delay in milliseconds
48
- );
49
- ```
50
-
51
- ### Type Guards
52
-
53
- #### `isFn(value)`
54
- Check if a value is a function.
55
-
56
- ```typescript
57
- if (isFn(value)) {
58
- value(); // TypeScript knows it's a function
59
- }
60
- ```
61
-
62
- #### `isArray(value)`
63
- Check if a value is an array.
64
-
65
- ```typescript
66
- if (isArray(value)) {
67
- value.forEach(...); // TypeScript knows it's an array
68
- }
69
- ```
70
-
71
- ### Types
72
-
73
- ```typescript
74
- type MaybeArray<T> = T | T[];
75
- type MaybePromise<T> = T | Promise<T>;
76
- type MaybeAccessor<T> = T | Accessor<T>;
77
- ```
@@ -0,0 +1,111 @@
1
+ import {
2
+ access
3
+ } from "./chunk-M5A3VVYI.js";
4
+ import {
5
+ createWatch
6
+ } from "./chunk-4L6FK7MF.js";
7
+ import {
8
+ isNumber
9
+ } from "./chunk-ZGYORUAX.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
+ };
@@ -24,9 +24,13 @@ function* range(startOrLength, end, valueOrMapper = (i) => i, step = 1) {
24
24
  var list = (startOrLength, end, valueOrMapper, step) => {
25
25
  return Array.from(range(startOrLength, end, valueOrMapper, step));
26
26
  };
27
+ function clearArray(arr) {
28
+ arr.length = 0;
29
+ }
27
30
 
28
31
  export {
29
32
  iterate,
30
33
  range,
31
- list
34
+ list,
35
+ clearArray
32
36
  };
@@ -1,9 +1,11 @@
1
+ import {
2
+ makeEventListener
3
+ } from "./chunk-OUAI75QC.js";
1
4
  import {
2
5
  access
3
6
  } from "./chunk-M5A3VVYI.js";
4
7
 
5
8
  // src/event/create-click-outside.ts
6
- import { makeEventListener } from "@solid-primitives/event-listener";
7
9
  function createClickOutside(target, handler, options) {
8
10
  const listener = (e) => {
9
11
  const el = access(target);
@@ -20,8 +22,7 @@ function createClickOutside(target, handler, options) {
20
22
  }
21
23
  handler(e);
22
24
  };
23
- makeEventListener(document, "click", listener);
24
- makeEventListener(document, "touchstart", listener);
25
+ makeEventListener(document, ["click", "touchstart"], listener);
25
26
  }
26
27
 
27
28
  export {
@@ -0,0 +1,8 @@
1
+ // src/jsx/attrs.ts
2
+ function dataIf(show) {
3
+ return show ? "" : void 0;
4
+ }
5
+
6
+ export {
7
+ dataIf
8
+ };
@@ -0,0 +1,8 @@
1
+ // src/lodash/async.ts
2
+ var sleep = (milliseconds) => {
3
+ return new Promise((res) => setTimeout(res, milliseconds));
4
+ };
5
+
6
+ export {
7
+ sleep
8
+ };
@@ -0,0 +1,53 @@
1
+ import {
2
+ makeEventListener
3
+ } from "./chunk-OUAI75QC.js";
4
+ import {
5
+ noop
6
+ } from "./chunk-BGLY6NJK.js";
7
+ import {
8
+ access
9
+ } from "./chunk-M5A3VVYI.js";
10
+ import {
11
+ createWatch
12
+ } from "./chunk-4L6FK7MF.js";
13
+ import {
14
+ clearArray
15
+ } from "./chunk-CSAKXWF3.js";
16
+ import {
17
+ isArray
18
+ } from "./chunk-ZGYORUAX.js";
19
+
20
+ // src/event/create-event-listener.ts
21
+ import { onCleanup } from "solid-js";
22
+ function createEventListener(...args) {
23
+ const target = args[0];
24
+ const events = args[1];
25
+ let listeners = args[2];
26
+ const options = args[3] ?? noop;
27
+ if (!isArray(listeners)) {
28
+ listeners = [listeners];
29
+ }
30
+ const cleanups = [];
31
+ const cleanup = () => {
32
+ for (const c of cleanups) {
33
+ c();
34
+ }
35
+ clearArray(cleanups);
36
+ };
37
+ createWatch(
38
+ () => [access(target), access(events), access(options)],
39
+ ([tars, evs, opts]) => {
40
+ cleanup();
41
+ if (!(tars && evs)) {
42
+ return;
43
+ }
44
+ cleanups.push(makeEventListener(tars, evs, listeners, opts));
45
+ }
46
+ );
47
+ onCleanup(cleanup);
48
+ return cleanup;
49
+ }
50
+
51
+ export {
52
+ createEventListener
53
+ };
@@ -0,0 +1,55 @@
1
+ import {
2
+ noop
3
+ } from "./chunk-BGLY6NJK.js";
4
+ import {
5
+ clearArray
6
+ } from "./chunk-CSAKXWF3.js";
7
+ import {
8
+ isArray
9
+ } from "./chunk-ZGYORUAX.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
+ };
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  iterate
3
- } from "./chunk-WLQ64SAO.js";
3
+ } from "./chunk-CSAKXWF3.js";
4
4
 
5
5
  // src/lodash/random.ts
6
6
  var random = (min, max) => {
@@ -0,0 +1,85 @@
1
+ // src/lodash/str.ts
2
+ var capitalize = (str) => {
3
+ if (!str || str.length === 0) {
4
+ return "";
5
+ }
6
+ const lower = str.toLowerCase();
7
+ return lower.substring(0, 1).toUpperCase() + lower.substring(1, lower.length);
8
+ };
9
+ var splitRegexp = /(?=[A-Z])|[.\-\s_]/;
10
+ var camel = (str) => {
11
+ const parts = str?.replace(/([A-Z])+/g, capitalize)?.split(splitRegexp).map((x) => x.toLowerCase()) ?? [];
12
+ if (parts.length === 0) {
13
+ return "";
14
+ }
15
+ if (parts.length === 1) {
16
+ return parts[0];
17
+ }
18
+ return parts.reduce((acc, part) => {
19
+ return `${acc}${part.charAt(0).toUpperCase()}${part.slice(1)}`;
20
+ });
21
+ };
22
+ var splitOnNumberRegexp = /([A-Za-z]{1}[0-9]{1})/;
23
+ var snake = (str, options) => {
24
+ const parts = str?.replace(/([A-Z])+/g, capitalize).split(splitRegexp).map((x) => x.toLowerCase()) ?? [];
25
+ if (parts.length === 0) {
26
+ return "";
27
+ }
28
+ if (parts.length === 1) {
29
+ return parts[0];
30
+ }
31
+ const result = parts.reduce((acc, part) => {
32
+ return `${acc}_${part.toLowerCase()}`;
33
+ });
34
+ return options?.splitOnNumber === false ? result : result.replace(splitOnNumberRegexp, (val) => `${val[0]}_${val[1]}`);
35
+ };
36
+ var dash = (str) => {
37
+ const parts = str?.replace(/([A-Z])+/g, capitalize)?.split(splitRegexp).map((x) => x.toLowerCase()) ?? [];
38
+ if (parts.length === 0) {
39
+ return "";
40
+ }
41
+ if (parts.length === 1) {
42
+ return parts[0];
43
+ }
44
+ return parts.reduce((acc, part) => {
45
+ return `${acc}-${part.toLowerCase()}`;
46
+ });
47
+ };
48
+ var pascalSplitRegexp = /[.\-\s_]/;
49
+ var pascal = (str) => {
50
+ const parts = str?.split(pascalSplitRegexp).map((x) => x.toLowerCase()) ?? [];
51
+ if (parts.length === 0) {
52
+ return "";
53
+ }
54
+ return parts.map((s) => s.charAt(0).toUpperCase() + s.slice(1)).join("");
55
+ };
56
+ var title = (str) => {
57
+ if (!str) {
58
+ return "";
59
+ }
60
+ return str.split(splitRegexp).map((s) => s.trim()).filter((s) => !!s).map((s) => capitalize(s.toLowerCase())).join(" ");
61
+ };
62
+ var template = (str, data, regex = /\{\{(.+?)\}\}/g) => {
63
+ return Array.from(str.matchAll(regex)).reduce((acc, match) => {
64
+ return acc.replace(match[0], data[match[1]]);
65
+ }, str);
66
+ };
67
+ var trim = (str, charsToTrim = " ") => {
68
+ if (!str) {
69
+ return "";
70
+ }
71
+ const toTrim = charsToTrim.replace(/[\W]{1}/g, "\\$&");
72
+ const regex = new RegExp(`^[${toTrim}]+|[${toTrim}]+$`, "g");
73
+ return str.replace(regex, "");
74
+ };
75
+
76
+ export {
77
+ capitalize,
78
+ camel,
79
+ snake,
80
+ dash,
81
+ pascal,
82
+ title,
83
+ template,
84
+ trim
85
+ };
File without changes
package/dist/dom/css.js CHANGED
@@ -1,10 +1,12 @@
1
1
  import {
2
2
  mountStyle
3
3
  } from "../chunk-KVG6TCSE.js";
4
- import "../chunk-33ZRZ4S2.js";
5
- import "../chunk-RRYFZNKE.js";
6
- import "../chunk-WLQ64SAO.js";
4
+ import "../chunk-OECLQ3OT.js";
5
+ import "../chunk-PBALVUKK.js";
6
+ import "../chunk-PNR5G432.js";
7
+ import "../chunk-CSAKXWF3.js";
7
8
  import "../chunk-ZGYORUAX.js";
9
+ import "../chunk-KFWZFQMB.js";
8
10
  export {
9
11
  mountStyle
10
12
  };
package/dist/dom/index.js CHANGED
@@ -2,10 +2,12 @@ import "../chunk-FFBJP5FE.js";
2
2
  import {
3
3
  mountStyle
4
4
  } from "../chunk-KVG6TCSE.js";
5
- import "../chunk-33ZRZ4S2.js";
6
- import "../chunk-RRYFZNKE.js";
7
- import "../chunk-WLQ64SAO.js";
5
+ import "../chunk-OECLQ3OT.js";
6
+ import "../chunk-PBALVUKK.js";
7
+ import "../chunk-PNR5G432.js";
8
+ import "../chunk-CSAKXWF3.js";
8
9
  import "../chunk-ZGYORUAX.js";
10
+ import "../chunk-KFWZFQMB.js";
9
11
  export {
10
12
  mountStyle
11
13
  };
@@ -1,13 +1,16 @@
1
1
  import {
2
2
  createClickOutside
3
- } from "../chunk-YJB637I2.js";
4
- import "../chunk-ZZNAXGNU.js";
3
+ } from "../chunk-HPKVQC7S.js";
4
+ import "../chunk-OUAI75QC.js";
5
+ import "../chunk-BGLY6NJK.js";
5
6
  import "../chunk-M5A3VVYI.js";
6
7
  import "../chunk-4L6FK7MF.js";
7
- import "../chunk-33ZRZ4S2.js";
8
- import "../chunk-RRYFZNKE.js";
9
- import "../chunk-WLQ64SAO.js";
8
+ import "../chunk-OECLQ3OT.js";
9
+ import "../chunk-PBALVUKK.js";
10
+ import "../chunk-PNR5G432.js";
11
+ import "../chunk-CSAKXWF3.js";
10
12
  import "../chunk-ZGYORUAX.js";
13
+ import "../chunk-KFWZFQMB.js";
11
14
  export {
12
15
  createClickOutside
13
16
  };
@@ -0,0 +1,23 @@
1
+ import { Fn } from '../types/fn.js';
2
+ import { MaybeAccessor, MaybeArray } from '../types/maybe.js';
3
+ import { WindowEventName, DocumentEventName, GeneralEventListener } from './make-event-listener.js';
4
+ import 'solid-js';
5
+
6
+ /**
7
+ * Overload 2: Explicitly Window target
8
+ */
9
+ declare function createEventListener<E extends WindowEventName>(target: MaybeAccessor<Window | undefined | null>, event: MaybeAccessor<MaybeArray<E>>, listener: MaybeArray<(this: Window, ev: WindowEventMap[E]) => void>, options?: MaybeAccessor<boolean | AddEventListenerOptions | undefined>): Fn;
10
+ /**
11
+ * Overload 3: Explicitly Document target
12
+ */
13
+ declare function createEventListener<E extends DocumentEventName>(target: MaybeAccessor<DocumentOrShadowRoot | undefined | null>, event: MaybeAccessor<MaybeArray<E>>, listener: MaybeArray<(this: Document, ev: DocumentEventMap[E]) => void>, options?: MaybeAccessor<boolean | AddEventListenerOptions | undefined>): Fn;
14
+ /**
15
+ * Overload 4: Explicitly HTMLElement target
16
+ */
17
+ declare function createEventListener<T extends HTMLElement, E extends keyof HTMLElementEventMap>(target: MaybeAccessor<T | undefined | null>, event: MaybeAccessor<MaybeArray<E>>, listener: MaybeArray<(this: T, ev: HTMLElementEventMap[E]) => void>, options?: MaybeAccessor<boolean | AddEventListenerOptions | undefined>): Fn;
18
+ /**
19
+ * Overload 6: Custom event target fallback
20
+ */
21
+ declare function createEventListener<EventType = Event>(target: MaybeAccessor<EventTarget | undefined | null>, event: MaybeAccessor<MaybeArray<string>>, listener: MaybeArray<GeneralEventListener<EventType>>, options?: MaybeAccessor<boolean | AddEventListenerOptions | undefined>): Fn;
22
+
23
+ export { createEventListener };
@@ -0,0 +1,16 @@
1
+ import {
2
+ createEventListener
3
+ } from "../chunk-KLRTXD4R.js";
4
+ import "../chunk-OUAI75QC.js";
5
+ import "../chunk-BGLY6NJK.js";
6
+ import "../chunk-M5A3VVYI.js";
7
+ import "../chunk-4L6FK7MF.js";
8
+ import "../chunk-OECLQ3OT.js";
9
+ import "../chunk-PBALVUKK.js";
10
+ import "../chunk-PNR5G432.js";
11
+ import "../chunk-CSAKXWF3.js";
12
+ import "../chunk-ZGYORUAX.js";
13
+ import "../chunk-KFWZFQMB.js";
14
+ export {
15
+ createEventListener
16
+ };
@@ -1,3 +1,6 @@
1
1
  export { createClickOutside } from './create-click-outside.js';
2
+ export { createEventListener } from './create-event-listener.js';
3
+ export { DocumentEventName, GeneralEventListener, WindowEventName, makeEventListener } from './make-event-listener.js';
2
4
  import '../types/maybe.js';
3
5
  import 'solid-js';
6
+ import '../types/fn.js';
@@ -1,14 +1,24 @@
1
- import "../chunk-M53KPXWR.js";
1
+ import "../chunk-B6TZK2S5.js";
2
2
  import {
3
3
  createClickOutside
4
- } from "../chunk-YJB637I2.js";
5
- import "../chunk-ZZNAXGNU.js";
4
+ } from "../chunk-HPKVQC7S.js";
5
+ import {
6
+ createEventListener
7
+ } from "../chunk-KLRTXD4R.js";
8
+ import {
9
+ makeEventListener
10
+ } from "../chunk-OUAI75QC.js";
11
+ import "../chunk-BGLY6NJK.js";
6
12
  import "../chunk-M5A3VVYI.js";
7
13
  import "../chunk-4L6FK7MF.js";
8
- import "../chunk-33ZRZ4S2.js";
9
- import "../chunk-RRYFZNKE.js";
10
- import "../chunk-WLQ64SAO.js";
14
+ import "../chunk-OECLQ3OT.js";
15
+ import "../chunk-PBALVUKK.js";
16
+ import "../chunk-PNR5G432.js";
17
+ import "../chunk-CSAKXWF3.js";
11
18
  import "../chunk-ZGYORUAX.js";
19
+ import "../chunk-KFWZFQMB.js";
12
20
  export {
13
- createClickOutside
21
+ createClickOutside,
22
+ createEventListener,
23
+ makeEventListener
14
24
  };
@@ -0,0 +1,49 @@
1
+ import { Fn } from '../types/fn.js';
2
+ import { MaybeArray } from '../types/maybe.js';
3
+ import 'solid-js';
4
+
5
+ interface InferEventTarget<Events> {
6
+ addEventListener: (event: Events, fn?: any, options?: any) => any;
7
+ removeEventListener: (event: Events, fn?: any, options?: any) => any;
8
+ }
9
+ type WindowEventName = keyof WindowEventMap;
10
+ type DocumentEventName = keyof DocumentEventMap;
11
+ type GeneralEventListener<E = Event> = (evt: E) => void;
12
+ /**
13
+ * Overload 1: Omitted Window target
14
+ */
15
+ declare function makeEventListener<E extends WindowEventName>(event: MaybeArray<E>, listener: MaybeArray<(this: Window, ev: WindowEventMap[E]) => void>, options?: boolean | AddEventListenerOptions): Fn;
16
+ /**
17
+ * Overload 2: Explicitly Window target
18
+ */
19
+ declare function makeEventListener<E extends WindowEventName>(target: Window, event: E, listener: MaybeArray<(this: Window, ev: WindowEventMap[E]) => void>, options?: boolean | AddEventListenerOptions): Fn;
20
+ /**
21
+ * Overload 2.1: Explicitly Window target
22
+ */
23
+ declare function makeEventListener<EventType = Event>(target: Window, event: WindowEventName[], listener: MaybeArray<(this: Window, ev: EventType) => void>, options?: boolean | AddEventListenerOptions): Fn;
24
+ /**
25
+ * Overload 3: Explicitly Document target
26
+ */
27
+ declare function makeEventListener<E extends DocumentEventName>(target: DocumentOrShadowRoot, event: E, listener: MaybeArray<(this: Document, ev: DocumentEventMap[E]) => void>, options?: boolean | AddEventListenerOptions): Fn;
28
+ /**
29
+ * Overload 3.1: Explicitly Document target
30
+ */
31
+ declare function makeEventListener<EventType = Event>(target: DocumentOrShadowRoot, event: DocumentEventName[], listener: MaybeArray<(this: Document, ev: EventType) => void>, options?: boolean | AddEventListenerOptions): Fn;
32
+ /**
33
+ * Overload 4: Explicitly HTMLElement target
34
+ */
35
+ declare function makeEventListener<T extends HTMLElement, E extends keyof HTMLElementEventMap>(target: T, event: E | (keyof HTMLElementEventMap)[], listener: MaybeArray<(this: T, ev: HTMLElementEventMap[E]) => void>, options?: boolean | AddEventListenerOptions): Fn;
36
+ /**
37
+ * Overload 4.1: Explicitly HTMLElement target
38
+ */
39
+ declare function makeEventListener<T extends HTMLElement, EventType = Event>(target: T, event: (keyof HTMLElementEventMap)[], listener: MaybeArray<(this: T, ev: EventType) => void>, options?: boolean | AddEventListenerOptions): Fn;
40
+ /**
41
+ * Overload 5: Custom event target with event type infer
42
+ */
43
+ declare function makeEventListener<Names extends string, EventType = Event>(target: InferEventTarget<Names>, event: MaybeArray<Names>, listener: MaybeArray<GeneralEventListener<EventType>>, options?: boolean | AddEventListenerOptions): Fn;
44
+ /**
45
+ * Overload 6: Custom event target fallback
46
+ */
47
+ declare function makeEventListener<EventType = Event>(target: EventTarget, event: MaybeArray<string>, listener: MaybeArray<GeneralEventListener<EventType>>, options?: boolean | AddEventListenerOptions): Fn;
48
+
49
+ export { type DocumentEventName, type GeneralEventListener, type WindowEventName, makeEventListener };
@@ -0,0 +1,15 @@
1
+ import {
2
+ makeEventListener
3
+ } from "../chunk-OUAI75QC.js";
4
+ import "../chunk-BGLY6NJK.js";
5
+ import "../chunk-M5A3VVYI.js";
6
+ import "../chunk-4L6FK7MF.js";
7
+ import "../chunk-OECLQ3OT.js";
8
+ import "../chunk-PBALVUKK.js";
9
+ import "../chunk-PNR5G432.js";
10
+ import "../chunk-CSAKXWF3.js";
11
+ import "../chunk-ZGYORUAX.js";
12
+ import "../chunk-KFWZFQMB.js";
13
+ export {
14
+ makeEventListener
15
+ };
@@ -1,13 +1,14 @@
1
1
  import {
2
2
  createDebounce
3
- } from "../chunk-H6VUVMSF.js";
4
- import "../chunk-ZZNAXGNU.js";
3
+ } from "../chunk-BGLY6NJK.js";
5
4
  import "../chunk-M5A3VVYI.js";
6
5
  import "../chunk-4L6FK7MF.js";
7
- import "../chunk-33ZRZ4S2.js";
8
- import "../chunk-RRYFZNKE.js";
9
- import "../chunk-WLQ64SAO.js";
6
+ import "../chunk-OECLQ3OT.js";
7
+ import "../chunk-PBALVUKK.js";
8
+ import "../chunk-PNR5G432.js";
9
+ import "../chunk-CSAKXWF3.js";
10
10
  import "../chunk-ZGYORUAX.js";
11
+ import "../chunk-KFWZFQMB.js";
11
12
  export {
12
13
  createDebounce
13
14
  };