yummies 4.12.2 → 4.14.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 (76) hide show
  1. package/mobx/apply-observable.d.ts +4 -0
  2. package/mobx/apply-observable.d.ts.map +1 -0
  3. package/mobx/apply-observable.js +12 -0
  4. package/mobx/deep-observable-struct.js +1 -1
  5. package/package.json +128 -3
  6. package/react/hooks/index.d.ts +22 -0
  7. package/react/hooks/index.d.ts.map +1 -0
  8. package/react/hooks/index.js +21 -0
  9. package/react/hooks/use-abort-controller.d.ts +2 -0
  10. package/react/hooks/use-abort-controller.d.ts.map +1 -0
  11. package/react/hooks/use-abort-controller.js +11 -0
  12. package/react/hooks/use-abort-signal.d.ts +2 -0
  13. package/react/hooks/use-abort-signal.d.ts.map +1 -0
  14. package/react/hooks/use-abort-signal.js +4 -0
  15. package/react/hooks/use-click-outside.d.ts +9 -0
  16. package/react/hooks/use-click-outside.d.ts.map +1 -0
  17. package/react/hooks/use-click-outside.js +13 -0
  18. package/react/hooks/use-constant.d.ts +9 -0
  19. package/react/hooks/use-constant.d.ts.map +1 -0
  20. package/react/hooks/use-constant.js +15 -0
  21. package/react/hooks/use-define-ref.d.ts +10 -0
  22. package/react/hooks/use-define-ref.d.ts.map +1 -0
  23. package/react/hooks/use-define-ref.js +15 -0
  24. package/react/hooks/use-element-ref.d.ts +2 -0
  25. package/react/hooks/use-element-ref.d.ts.map +1 -0
  26. package/react/hooks/use-element-ref.js +8 -0
  27. package/react/hooks/use-event-listener.d.ts +8 -0
  28. package/react/hooks/use-event-listener.d.ts.map +1 -0
  29. package/react/hooks/use-event-listener.js +13 -0
  30. package/react/hooks/use-event.d.ts +3 -0
  31. package/react/hooks/use-event.d.ts.map +1 -0
  32. package/react/hooks/use-event.js +19 -0
  33. package/react/hooks/use-flag.d.ts +8 -0
  34. package/react/hooks/use-flag.d.ts.map +1 -0
  35. package/react/hooks/use-flag.js +15 -0
  36. package/react/hooks/use-force-update.d.ts +2 -0
  37. package/react/hooks/use-force-update.d.ts.map +1 -0
  38. package/react/hooks/use-force-update.js +7 -0
  39. package/react/hooks/use-initial-height.d.ts +5 -0
  40. package/react/hooks/use-initial-height.d.ts.map +1 -0
  41. package/react/hooks/use-initial-height.js +11 -0
  42. package/react/hooks/use-instance.d.ts +27 -0
  43. package/react/hooks/use-instance.d.ts.map +1 -0
  44. package/react/hooks/use-instance.js +27 -0
  45. package/react/hooks/use-intersection-observer.d.ts +2 -0
  46. package/react/hooks/use-intersection-observer.d.ts.map +1 -0
  47. package/react/hooks/use-intersection-observer.js +10 -0
  48. package/react/hooks/use-last-defined-value.d.ts +2 -0
  49. package/react/hooks/use-last-defined-value.d.ts.map +1 -0
  50. package/react/hooks/use-last-defined-value.js +8 -0
  51. package/react/hooks/use-last-value-ref.d.ts +2 -0
  52. package/react/hooks/use-last-value-ref.d.ts.map +1 -0
  53. package/react/hooks/use-last-value-ref.js +8 -0
  54. package/react/hooks/use-life-cycle.d.ts +5 -0
  55. package/react/hooks/use-life-cycle.d.ts.map +1 -0
  56. package/react/hooks/use-life-cycle.js +10 -0
  57. package/react/hooks/use-resize-observer.d.ts +2 -0
  58. package/react/hooks/use-resize-observer.d.ts.map +1 -0
  59. package/react/hooks/use-resize-observer.js +11 -0
  60. package/react/hooks/use-sync-ref.d.ts +2 -0
  61. package/react/hooks/use-sync-ref.d.ts.map +1 -0
  62. package/react/hooks/use-sync-ref.js +6 -0
  63. package/react/hooks/use-toggle.d.ts +2 -0
  64. package/react/hooks/use-toggle.d.ts.map +1 -0
  65. package/react/hooks/use-toggle.js +6 -0
  66. package/react/hooks/use-value.d.ts +5 -0
  67. package/react/hooks/use-value.d.ts.map +1 -0
  68. package/react/hooks/use-value.js +8 -0
  69. package/react/hooks/use-visibility-state.d.ts +2 -0
  70. package/react/hooks/use-visibility-state.d.ts.map +1 -0
  71. package/react/hooks/use-visibility-state.js +14 -0
  72. package/react/index.d.ts +2 -0
  73. package/react/index.d.ts.map +1 -0
  74. package/react/index.js +1 -0
  75. package/sound.js +1 -1
  76. package/type-guard/_exports.js +1 -1
@@ -0,0 +1,4 @@
1
+ import type { AnyObject } from '../utils/types.js';
2
+ export type ObservableAnnotationsArray = [string, any][];
3
+ export declare const applyObservable: (context: AnyObject, annotationsArray: ObservableAnnotationsArray, useDecorators?: boolean) => void;
4
+ //# sourceMappingURL=apply-observable.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"apply-observable.d.ts","sourceRoot":"","sources":["../../src/mobx/apply-observable.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAEnD,MAAM,MAAM,0BAA0B,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,CAAC;AAEzD,eAAO,MAAM,eAAe,GAC1B,SAAS,SAAS,EAClB,kBAAkB,0BAA0B,EAC5C,gBAAgB,OAAO,SAWxB,CAAC"}
@@ -0,0 +1,12 @@
1
+ import { makeObservable } from 'mobx';
2
+ export const applyObservable = (context, annotationsArray, useDecorators) => {
3
+ if (useDecorators) {
4
+ annotationsArray.forEach(([field, annotation]) => {
5
+ annotation(context, field);
6
+ });
7
+ makeObservable(context);
8
+ }
9
+ else {
10
+ makeObservable(context, Object.fromEntries(annotationsArray));
11
+ }
12
+ };
@@ -49,7 +49,7 @@ export class DeepObservableStruct {
49
49
  }
50
50
  Object.keys(newData).forEach((newDataKey) => {
51
51
  if (!this.data[newDataKey]) {
52
- // @ts-ignore
52
+ // @ts-expect-error
53
53
  this.data[newDataKey] = newData[newDataKey];
54
54
  }
55
55
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yummies",
3
- "version": "4.12.2",
3
+ "version": "4.14.0",
4
4
  "keywords": [],
5
5
  "author": "js2me",
6
6
  "license": "MIT",
@@ -15,11 +15,15 @@
15
15
  "url": "git://github.com/js2me/yummies"
16
16
  },
17
17
  "peerDependencies": {
18
- "mobx": "^6.12.4"
18
+ "mobx": "^6.12.4",
19
+ "react": "^18 || ^19"
19
20
  },
20
21
  "peerDependenciesMeta": {
21
22
  "mobx": {
22
23
  "optional": true
24
+ },
25
+ "react": {
26
+ "optional": true
23
27
  }
24
28
  },
25
29
  "dependencies": {
@@ -32,10 +36,11 @@
32
36
  "tailwind-merge": "^3.3.1"
33
37
  },
34
38
  "devDependencies": {
39
+ "@biomejs/biome": "2.2.2",
35
40
  "@changesets/changelog-github": "^0.5.1",
36
41
  "@changesets/cli": "^2.29.5",
37
- "@biomejs/biome": "2.1.4",
38
42
  "@types/node": "^20.17.30",
43
+ "@types/react": "^18",
39
44
  "@vitejs/plugin-react-swc": "^3.9.0",
40
45
  "@vitest/coverage-istanbul": "^3.1.2",
41
46
  "commitfmt": "^1.0.4",
@@ -194,6 +199,11 @@
194
199
  "default": "./media.js",
195
200
  "types": "./media.d.ts"
196
201
  },
202
+ "./mobx/apply-observable": {
203
+ "import": "./mobx/apply-observable.js",
204
+ "default": "./mobx/apply-observable.js",
205
+ "types": "./mobx/apply-observable.d.ts"
206
+ },
197
207
  "./mobx/deep-observable-struct.test": {
198
208
  "import": "./mobx/deep-observable-struct.test.js",
199
209
  "default": "./mobx/deep-observable-struct.test.js",
@@ -269,6 +279,121 @@
269
279
  "default": "./random.js",
270
280
  "types": "./random.d.ts"
271
281
  },
282
+ "./react/hooks": {
283
+ "import": "./react/hooks/index.js",
284
+ "default": "./react/hooks/index.js",
285
+ "types": "./react/hooks/index.d.ts"
286
+ },
287
+ "./react/hooks/use-abort-controller": {
288
+ "import": "./react/hooks/use-abort-controller.js",
289
+ "default": "./react/hooks/use-abort-controller.js",
290
+ "types": "./react/hooks/use-abort-controller.d.ts"
291
+ },
292
+ "./react/hooks/use-abort-signal": {
293
+ "import": "./react/hooks/use-abort-signal.js",
294
+ "default": "./react/hooks/use-abort-signal.js",
295
+ "types": "./react/hooks/use-abort-signal.d.ts"
296
+ },
297
+ "./react/hooks/use-click-outside": {
298
+ "import": "./react/hooks/use-click-outside.js",
299
+ "default": "./react/hooks/use-click-outside.js",
300
+ "types": "./react/hooks/use-click-outside.d.ts"
301
+ },
302
+ "./react/hooks/use-constant": {
303
+ "import": "./react/hooks/use-constant.js",
304
+ "default": "./react/hooks/use-constant.js",
305
+ "types": "./react/hooks/use-constant.d.ts"
306
+ },
307
+ "./react/hooks/use-define-ref": {
308
+ "import": "./react/hooks/use-define-ref.js",
309
+ "default": "./react/hooks/use-define-ref.js",
310
+ "types": "./react/hooks/use-define-ref.d.ts"
311
+ },
312
+ "./react/hooks/use-element-ref": {
313
+ "import": "./react/hooks/use-element-ref.js",
314
+ "default": "./react/hooks/use-element-ref.js",
315
+ "types": "./react/hooks/use-element-ref.d.ts"
316
+ },
317
+ "./react/hooks/use-event-listener": {
318
+ "import": "./react/hooks/use-event-listener.js",
319
+ "default": "./react/hooks/use-event-listener.js",
320
+ "types": "./react/hooks/use-event-listener.d.ts"
321
+ },
322
+ "./react/hooks/use-event": {
323
+ "import": "./react/hooks/use-event.js",
324
+ "default": "./react/hooks/use-event.js",
325
+ "types": "./react/hooks/use-event.d.ts"
326
+ },
327
+ "./react/hooks/use-flag": {
328
+ "import": "./react/hooks/use-flag.js",
329
+ "default": "./react/hooks/use-flag.js",
330
+ "types": "./react/hooks/use-flag.d.ts"
331
+ },
332
+ "./react/hooks/use-force-update": {
333
+ "import": "./react/hooks/use-force-update.js",
334
+ "default": "./react/hooks/use-force-update.js",
335
+ "types": "./react/hooks/use-force-update.d.ts"
336
+ },
337
+ "./react/hooks/use-initial-height": {
338
+ "import": "./react/hooks/use-initial-height.js",
339
+ "default": "./react/hooks/use-initial-height.js",
340
+ "types": "./react/hooks/use-initial-height.d.ts"
341
+ },
342
+ "./react/hooks/use-instance": {
343
+ "import": "./react/hooks/use-instance.js",
344
+ "default": "./react/hooks/use-instance.js",
345
+ "types": "./react/hooks/use-instance.d.ts"
346
+ },
347
+ "./react/hooks/use-intersection-observer": {
348
+ "import": "./react/hooks/use-intersection-observer.js",
349
+ "default": "./react/hooks/use-intersection-observer.js",
350
+ "types": "./react/hooks/use-intersection-observer.d.ts"
351
+ },
352
+ "./react/hooks/use-last-defined-value": {
353
+ "import": "./react/hooks/use-last-defined-value.js",
354
+ "default": "./react/hooks/use-last-defined-value.js",
355
+ "types": "./react/hooks/use-last-defined-value.d.ts"
356
+ },
357
+ "./react/hooks/use-last-value-ref": {
358
+ "import": "./react/hooks/use-last-value-ref.js",
359
+ "default": "./react/hooks/use-last-value-ref.js",
360
+ "types": "./react/hooks/use-last-value-ref.d.ts"
361
+ },
362
+ "./react/hooks/use-life-cycle": {
363
+ "import": "./react/hooks/use-life-cycle.js",
364
+ "default": "./react/hooks/use-life-cycle.js",
365
+ "types": "./react/hooks/use-life-cycle.d.ts"
366
+ },
367
+ "./react/hooks/use-resize-observer": {
368
+ "import": "./react/hooks/use-resize-observer.js",
369
+ "default": "./react/hooks/use-resize-observer.js",
370
+ "types": "./react/hooks/use-resize-observer.d.ts"
371
+ },
372
+ "./react/hooks/use-sync-ref": {
373
+ "import": "./react/hooks/use-sync-ref.js",
374
+ "default": "./react/hooks/use-sync-ref.js",
375
+ "types": "./react/hooks/use-sync-ref.d.ts"
376
+ },
377
+ "./react/hooks/use-toggle": {
378
+ "import": "./react/hooks/use-toggle.js",
379
+ "default": "./react/hooks/use-toggle.js",
380
+ "types": "./react/hooks/use-toggle.d.ts"
381
+ },
382
+ "./react/hooks/use-value": {
383
+ "import": "./react/hooks/use-value.js",
384
+ "default": "./react/hooks/use-value.js",
385
+ "types": "./react/hooks/use-value.d.ts"
386
+ },
387
+ "./react/hooks/use-visibility-state": {
388
+ "import": "./react/hooks/use-visibility-state.js",
389
+ "default": "./react/hooks/use-visibility-state.js",
390
+ "types": "./react/hooks/use-visibility-state.d.ts"
391
+ },
392
+ "./react": {
393
+ "import": "./react/index.js",
394
+ "default": "./react/index.js",
395
+ "types": "./react/index.d.ts"
396
+ },
272
397
  "./sound": {
273
398
  "import": "./sound.js",
274
399
  "default": "./sound.js",
@@ -0,0 +1,22 @@
1
+ export * from './use-abort-controller.js';
2
+ export * from './use-abort-signal.js';
3
+ export * from './use-click-outside.js';
4
+ export * from './use-constant.js';
5
+ export * from './use-define-ref.js';
6
+ export * from './use-element-ref.js';
7
+ export * from './use-event.js';
8
+ export * from './use-event-listener.js';
9
+ export * from './use-flag.js';
10
+ export * from './use-force-update.js';
11
+ export * from './use-initial-height.js';
12
+ export * from './use-instance.js';
13
+ export * from './use-intersection-observer.js';
14
+ export * from './use-last-defined-value.js';
15
+ export * from './use-last-value-ref.js';
16
+ export * from './use-life-cycle.js';
17
+ export * from './use-resize-observer.js';
18
+ export * from './use-sync-ref.js';
19
+ export * from './use-toggle.js';
20
+ export * from './use-value.js';
21
+ export * from './use-visibility-state.js';
22
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/react/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAC;AAC1C,cAAc,uBAAuB,CAAC;AACtC,cAAc,wBAAwB,CAAC;AACvC,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AACrC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,yBAAyB,CAAC;AACxC,cAAc,eAAe,CAAC;AAC9B,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,mBAAmB,CAAC;AAClC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,yBAAyB,CAAC;AACxC,cAAc,qBAAqB,CAAC;AACpC,cAAc,0BAA0B,CAAC;AACzC,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,2BAA2B,CAAC"}
@@ -0,0 +1,21 @@
1
+ export * from './use-abort-controller.js';
2
+ export * from './use-abort-signal.js';
3
+ export * from './use-click-outside.js';
4
+ export * from './use-constant.js';
5
+ export * from './use-define-ref.js';
6
+ export * from './use-element-ref.js';
7
+ export * from './use-event.js';
8
+ export * from './use-event-listener.js';
9
+ export * from './use-flag.js';
10
+ export * from './use-force-update.js';
11
+ export * from './use-initial-height.js';
12
+ export * from './use-instance.js';
13
+ export * from './use-intersection-observer.js';
14
+ export * from './use-last-defined-value.js';
15
+ export * from './use-last-value-ref.js';
16
+ export * from './use-life-cycle.js';
17
+ export * from './use-resize-observer.js';
18
+ export * from './use-sync-ref.js';
19
+ export * from './use-toggle.js';
20
+ export * from './use-value.js';
21
+ export * from './use-visibility-state.js';
@@ -0,0 +1,2 @@
1
+ export declare const useAbortController: () => AbortController;
2
+ //# sourceMappingURL=use-abort-controller.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-abort-controller.d.ts","sourceRoot":"","sources":["../../../src/react/hooks/use-abort-controller.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,kBAAkB,uBAU9B,CAAC"}
@@ -0,0 +1,11 @@
1
+ import { useEffect } from 'react';
2
+ import { useConstant } from './use-constant.js';
3
+ export const useAbortController = () => {
4
+ const controller = useConstant(() => new AbortController());
5
+ useEffect(() => {
6
+ return () => {
7
+ controller.abort();
8
+ };
9
+ }, []);
10
+ return controller;
11
+ };
@@ -0,0 +1,2 @@
1
+ export declare const useAbortSignal: () => AbortSignal;
2
+ //# sourceMappingURL=use-abort-signal.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-abort-signal.d.ts","sourceRoot":"","sources":["../../../src/react/hooks/use-abort-signal.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,cAAc,mBAE1B,CAAC"}
@@ -0,0 +1,4 @@
1
+ import { useAbortController } from './use-abort-controller.js';
2
+ export const useAbortSignal = () => {
3
+ return useAbortController().signal;
4
+ };
@@ -0,0 +1,9 @@
1
+ import type { MutableRefObject } from 'react';
2
+ type ClickOutsideInput = {
3
+ contentRef: MutableRefObject<HTMLElement | null>;
4
+ onClick: VoidFunction;
5
+ options?: AddEventListenerOptions;
6
+ };
7
+ export declare const useClickOutside: ({ contentRef, onClick, options, }: ClickOutsideInput) => void;
8
+ export {};
9
+ //# sourceMappingURL=use-click-outside.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-click-outside.d.ts","sourceRoot":"","sources":["../../../src/react/hooks/use-click-outside.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,OAAO,CAAC;AAG9C,KAAK,iBAAiB,GAAG;IACvB,UAAU,EAAE,gBAAgB,CAAC,WAAW,GAAG,IAAI,CAAC,CAAC;IACjD,OAAO,EAAE,YAAY,CAAC;IACtB,OAAO,CAAC,EAAE,uBAAuB,CAAC;CACnC,CAAC;AAEF,eAAO,MAAM,eAAe,GAAI,mCAI7B,iBAAiB,SAanB,CAAC"}
@@ -0,0 +1,13 @@
1
+ import { useEventListener } from './use-event-listener.js';
2
+ export const useClickOutside = ({ contentRef, onClick, options, }) => {
3
+ useEventListener({
4
+ event: 'mousedown',
5
+ handler: (event) => {
6
+ if (contentRef.current &&
7
+ !contentRef.current.contains(event.target)) {
8
+ onClick();
9
+ }
10
+ },
11
+ options,
12
+ });
13
+ };
@@ -0,0 +1,9 @@
1
+ /**
2
+ * React hook for creating a value exactly once.
3
+ * useMemo doesn't give this guarantee unfortunately -
4
+ * https://reactjs.org/docs/hooks-faq.html#how-to-create-expensive-objects-lazily
5
+ * https://reactjs.org/docs/hooks-reference.html#usememo
6
+ * @param defineValue Function which returns defined value.
7
+ */
8
+ export declare const useConstant: <T>(defineValue: () => T) => T;
9
+ //# sourceMappingURL=use-constant.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-constant.d.ts","sourceRoot":"","sources":["../../../src/react/hooks/use-constant.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,eAAO,MAAM,WAAW,GAAI,CAAC,EAAE,aAAa,MAAM,CAAC,KAAG,CAQrD,CAAC"}
@@ -0,0 +1,15 @@
1
+ import { useRef } from 'react';
2
+ /**
3
+ * React hook for creating a value exactly once.
4
+ * useMemo doesn't give this guarantee unfortunately -
5
+ * https://reactjs.org/docs/hooks-faq.html#how-to-create-expensive-objects-lazily
6
+ * https://reactjs.org/docs/hooks-reference.html#usememo
7
+ * @param defineValue Function which returns defined value.
8
+ */
9
+ export const useConstant = (defineValue) => {
10
+ const ref = useRef();
11
+ if (!ref.current) {
12
+ ref.current = { value: defineValue() };
13
+ }
14
+ return ref.current.value;
15
+ };
@@ -0,0 +1,10 @@
1
+ import { type MutableRefObject } from 'react';
2
+ /**
3
+ * React hook for creating a value exactly once.
4
+ * useMemo doesn't give this guarantee unfortunately -
5
+ * https://reactjs.org/docs/hooks-faq.html#how-to-create-expensive-objects-lazily
6
+ * https://reactjs.org/docs/hooks-reference.html#usememo
7
+ * @param defineFn Function which returns defined value.
8
+ */
9
+ export declare const useDefineRef: <T>(defineFn: () => T) => MutableRefObject<T>;
10
+ //# sourceMappingURL=use-define-ref.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-define-ref.d.ts","sourceRoot":"","sources":["../../../src/react/hooks/use-define-ref.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,gBAAgB,EAAU,MAAM,OAAO,CAAC;AAEtD;;;;;;GAMG;AACH,eAAO,MAAM,YAAY,GAAI,CAAC,EAAE,UAAU,MAAM,CAAC,KAAG,gBAAgB,CAAC,CAAC,CAQrE,CAAC"}
@@ -0,0 +1,15 @@
1
+ import { useRef } from 'react';
2
+ /**
3
+ * React hook for creating a value exactly once.
4
+ * useMemo doesn't give this guarantee unfortunately -
5
+ * https://reactjs.org/docs/hooks-faq.html#how-to-create-expensive-objects-lazily
6
+ * https://reactjs.org/docs/hooks-reference.html#usememo
7
+ * @param defineFn Function which returns defined value.
8
+ */
9
+ export const useDefineRef = (defineFn) => {
10
+ const ref = useRef(void 0);
11
+ if (!ref.current) {
12
+ ref.current = defineFn();
13
+ }
14
+ return ref;
15
+ };
@@ -0,0 +1,2 @@
1
+ export declare const useElementRef: <T extends HTMLElement>(selector: () => T) => import("react").MutableRefObject<T | undefined>;
2
+ //# sourceMappingURL=use-element-ref.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-element-ref.d.ts","sourceRoot":"","sources":["../../../src/react/hooks/use-element-ref.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,aAAa,GAAI,CAAC,SAAS,WAAW,EAAE,UAAU,MAAM,CAAC,oDAQrE,CAAC"}
@@ -0,0 +1,8 @@
1
+ import { useLayoutEffect, useRef } from 'react';
2
+ export const useElementRef = (selector) => {
3
+ const ref = useRef();
4
+ useLayoutEffect(() => {
5
+ ref.current = selector();
6
+ }, []);
7
+ return ref;
8
+ };
@@ -0,0 +1,8 @@
1
+ export declare const useEventListener: <EventName extends keyof HTMLElementEventMap>({ event, handler, options, deps, node, }: {
2
+ event: EventName;
3
+ handler: (e: HTMLElementEventMap[EventName]) => void;
4
+ options?: boolean | AddEventListenerOptions;
5
+ deps?: unknown[];
6
+ node?: HTMLElement | Document | Window;
7
+ }) => void;
8
+ //# sourceMappingURL=use-event-listener.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-event-listener.d.ts","sourceRoot":"","sources":["../../../src/react/hooks/use-event-listener.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,gBAAgB,GAAI,SAAS,SAAS,MAAM,mBAAmB,EAAE,0CAM3E;IACD,KAAK,EAAE,SAAS,CAAC;IACjB,OAAO,EAAE,CAAC,CAAC,EAAE,mBAAmB,CAAC,SAAS,CAAC,KAAK,IAAI,CAAC;IACrD,OAAO,CAAC,EAAE,OAAO,GAAG,uBAAuB,CAAC;IAC5C,IAAI,CAAC,EAAE,OAAO,EAAE,CAAC;IACjB,IAAI,CAAC,EAAE,WAAW,GAAG,QAAQ,GAAG,MAAM,CAAC;CACxC,SAYA,CAAC"}
@@ -0,0 +1,13 @@
1
+ /* eslint-disable @typescript-eslint/ban-ts-comment */
2
+ import { useEffect } from 'react';
3
+ import { useSyncRef } from './use-sync-ref.js';
4
+ export const useEventListener = ({ event, handler, options, deps = [], node = document, }) => {
5
+ const handlerRef = useSyncRef(handler);
6
+ useEffect(() => {
7
+ const handleEvent = (e) => handlerRef.current(e);
8
+ // @ts-expect-error
9
+ node.addEventListener(event, handleEvent, options);
10
+ // @ts-expect-error
11
+ return () => node.removeEventListener(event, handleEvent, options);
12
+ }, deps);
13
+ };
@@ -0,0 +1,3 @@
1
+ import type { AnyFunction } from '../../utils/types.js';
2
+ export declare const useEvent: <H extends AnyFunction>(handler: H) => H;
3
+ //# sourceMappingURL=use-event.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-event.d.ts","sourceRoot":"","sources":["../../../src/react/hooks/use-event.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAExD,eAAO,MAAM,QAAQ,GAAI,CAAC,SAAS,WAAW,EAAE,SAAS,CAAC,KAAG,CAa5D,CAAC"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * A Hook to define an event handler with an always-stable function identity.
3
+ *
4
+ * borrowed from @gaeron
5
+ * https://github.com/reactjs/rfcs/blob/useevent/text/0000-useevent.md
6
+ */
7
+ import { useCallback, useLayoutEffect, useRef } from 'react';
8
+ export const useEvent = (handler) => {
9
+ const handlerRef = useRef(handler);
10
+ // In a real implementation, this would run before layout effects
11
+ useLayoutEffect(() => {
12
+ handlerRef.current = handler;
13
+ });
14
+ return useCallback((...args) => {
15
+ // In a real implementation, this would throw if called during render
16
+ const fn = handlerRef.current;
17
+ return fn(...args);
18
+ }, []);
19
+ };
@@ -0,0 +1,8 @@
1
+ export interface FlagHook {
2
+ enabled: boolean;
3
+ toggle: VoidFunction;
4
+ enable: VoidFunction;
5
+ disable: VoidFunction;
6
+ }
7
+ export declare const useFlag: (defaultValue?: boolean) => FlagHook;
8
+ //# sourceMappingURL=use-flag.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-flag.d.ts","sourceRoot":"","sources":["../../../src/react/hooks/use-flag.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,QAAQ;IACvB,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,YAAY,CAAC;IACrB,MAAM,EAAE,YAAY,CAAC;IACrB,OAAO,EAAE,YAAY,CAAC;CACvB;AAED,eAAO,MAAM,OAAO,GAAI,sBAAoB,KAAG,QAiB9C,CAAC"}
@@ -0,0 +1,15 @@
1
+ import { useCallback, useRef, useState } from 'react';
2
+ export const useFlag = (defaultValue = false) => {
3
+ const [enabled, setEnabled] = useState(defaultValue);
4
+ const toggle = useCallback(() => setEnabled((value) => !value), []);
5
+ const enable = useCallback(() => setEnabled(true), []);
6
+ const disable = useCallback(() => setEnabled(false), []);
7
+ const flagObjRef = useRef({
8
+ enabled,
9
+ toggle,
10
+ enable,
11
+ disable,
12
+ });
13
+ flagObjRef.current.enabled = enabled;
14
+ return flagObjRef.current;
15
+ };
@@ -0,0 +1,2 @@
1
+ export declare const useForceUpdate: () => () => void;
2
+ //# sourceMappingURL=use-force-update.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-force-update.d.ts","sourceRoot":"","sources":["../../../src/react/hooks/use-force-update.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,cAAc,kBAM1B,CAAC"}
@@ -0,0 +1,7 @@
1
+ import { useCallback, useState } from 'react';
2
+ export const useForceUpdate = () => {
3
+ const [, setState] = useState(null);
4
+ return useCallback(() => {
5
+ setState({});
6
+ }, []);
7
+ };
@@ -0,0 +1,5 @@
1
+ export declare const useInitialHeight: <T extends HTMLElement>() => {
2
+ ref: import("react").MutableRefObject<T | null>;
3
+ initialHeight: number | undefined;
4
+ };
5
+ //# sourceMappingURL=use-initial-height.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-initial-height.d.ts","sourceRoot":"","sources":["../../../src/react/hooks/use-initial-height.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,gBAAgB,GAAI,CAAC,SAAS,WAAW;;;CAarD,CAAC"}
@@ -0,0 +1,11 @@
1
+ import { useEffect, useRef, useState } from 'react';
2
+ export const useInitialHeight = () => {
3
+ const ref = useRef(null);
4
+ const [initialHeight, setInitialHeight] = useState(undefined);
5
+ useEffect(() => {
6
+ if (ref.current && !initialHeight) {
7
+ setInitialHeight(ref.current.offsetHeight);
8
+ }
9
+ }, [initialHeight]);
10
+ return { ref, initialHeight };
11
+ };
@@ -0,0 +1,27 @@
1
+ export type InstanceCreateConfig<TPayload, TExtension = {}> = TExtension & {
2
+ abortSignal: AbortSignal;
3
+ payload: TPayload;
4
+ };
5
+ export declare const createUseInstanceHook: <TExtension = {}>(extension?: TExtension) => <TInstance, TPayload>(factory: (config: InstanceCreateConfig<NoInfer<TPayload>, TExtension>) => TInstance, config?: {
6
+ payload?: TPayload;
7
+ onUpdate?: (payload: TPayload) => void;
8
+ }) => TInstance;
9
+ /**
10
+ * The `useInstance` hook is used to create and manage an instance of an object
11
+ * that requires access to the root store and an abort signal.
12
+ *
13
+ * You can create YOUR OWN CUSTOM `useInstance` hook using `createUseInstanceHook` if you need
14
+ * to provide some specific data
15
+ *
16
+ * @param factory - A factory function that takes a configuration and returns an instance.
17
+ * @param config - An optional configuration containing additional input parameters and an update function.
18
+ * @returns An instance created by the factory function.
19
+ */
20
+ export declare const useInstance: <TInstance, TPayload>(factory: (config: {
21
+ abortSignal: AbortSignal;
22
+ payload: NoInfer<TPayload>;
23
+ }) => TInstance, config?: {
24
+ payload?: TPayload | undefined;
25
+ onUpdate?: ((payload: TPayload) => void) | undefined;
26
+ } | undefined) => TInstance;
27
+ //# sourceMappingURL=use-instance.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-instance.d.ts","sourceRoot":"","sources":["../../../src/react/hooks/use-instance.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,oBAAoB,CAAC,QAAQ,EAAE,UAAU,GAAG,EAAE,IAAI,UAAU,GAAG;IACzE,WAAW,EAAE,WAAW,CAAC;IACzB,OAAO,EAAE,QAAQ,CAAC;CACnB,CAAC;AAEF,eAAO,MAAM,qBAAqB,GAC/B,UAAU,GAAG,EAAE,EAAE,YAAY,UAAU,MACvC,SAAS,EAAE,QAAQ,EAClB,SAAS,CACP,MAAM,EAAE,oBAAoB,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,UAAU,CAAC,KACxD,SAAS,EACd,SAAS;IACP,OAAO,CAAC,EAAE,QAAQ,CAAC;IACnB,QAAQ,CAAC,EAAE,CAAC,OAAO,EAAE,QAAQ,KAAK,IAAI,CAAC;CACxC,cAiBF,CAAC;AAEJ;;;;;;;;;;GAUG;AACH,eAAO,MAAM,WAAW,GArCrB,SAAS,EAAE,QAAQ;iBANP,WAAW;;;;uCAYc,IAAI;2BA+BM,CAAC"}
@@ -0,0 +1,27 @@
1
+ import { useLayoutEffect } from 'react';
2
+ import { useAbortSignal } from './use-abort-signal.js';
3
+ import { useConstant } from './use-constant.js';
4
+ export const createUseInstanceHook = (extension) => (factory, config) => {
5
+ const abortSignal = useAbortSignal();
6
+ const instance = useConstant(() => factory({
7
+ ...extension,
8
+ abortSignal,
9
+ payload: config?.payload,
10
+ }));
11
+ useLayoutEffect(() => {
12
+ config?.onUpdate?.(config.payload);
13
+ }, [config?.payload]);
14
+ return instance;
15
+ };
16
+ /**
17
+ * The `useInstance` hook is used to create and manage an instance of an object
18
+ * that requires access to the root store and an abort signal.
19
+ *
20
+ * You can create YOUR OWN CUSTOM `useInstance` hook using `createUseInstanceHook` if you need
21
+ * to provide some specific data
22
+ *
23
+ * @param factory - A factory function that takes a configuration and returns an instance.
24
+ * @param config - An optional configuration containing additional input parameters and an update function.
25
+ * @returns An instance created by the factory function.
26
+ */
27
+ export const useInstance = createUseInstanceHook();
@@ -0,0 +1,2 @@
1
+ export declare const useIntersectionObserver: (callback: IntersectionObserverCallback, options?: IntersectionObserverInit) => IntersectionObserver;
2
+ //# sourceMappingURL=use-intersection-observer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-intersection-observer.d.ts","sourceRoot":"","sources":["../../../src/react/hooks/use-intersection-observer.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,uBAAuB,GAClC,UAAU,4BAA4B,EACtC,UAAU,wBAAwB,yBAanC,CAAC"}
@@ -0,0 +1,10 @@
1
+ import { useEffect, useState } from 'react';
2
+ export const useIntersectionObserver = (callback, options) => {
3
+ const [intersectionObserver] = useState(() => new IntersectionObserver(callback, options));
4
+ useEffect(() => {
5
+ return () => {
6
+ intersectionObserver.disconnect();
7
+ };
8
+ }, []);
9
+ return intersectionObserver;
10
+ };
@@ -0,0 +1,2 @@
1
+ export declare const useLastDefinedValue: <T>(value: T) => T;
2
+ //# sourceMappingURL=use-last-defined-value.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-last-defined-value.d.ts","sourceRoot":"","sources":["../../../src/react/hooks/use-last-defined-value.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,mBAAmB,GAAI,CAAC,EAAE,OAAO,CAAC,MAM9C,CAAC"}
@@ -0,0 +1,8 @@
1
+ import { useRef } from 'react';
2
+ export const useLastDefinedValue = (value) => {
3
+ const ref = useRef(value);
4
+ if (value != null) {
5
+ ref.current = value;
6
+ }
7
+ return ref.current;
8
+ };
@@ -0,0 +1,2 @@
1
+ export declare const useLastValueRef: <T>(value: T | null | undefined) => import("react").MutableRefObject<T | null | undefined>;
2
+ //# sourceMappingURL=use-last-value-ref.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-last-value-ref.d.ts","sourceRoot":"","sources":["../../../src/react/hooks/use-last-value-ref.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,eAAe,GAAI,CAAC,EAAE,OAAO,CAAC,GAAG,IAAI,GAAG,SAAS,2DAQ7D,CAAC"}
@@ -0,0 +1,8 @@
1
+ import { useRef } from 'react';
2
+ export const useLastValueRef = (value) => {
3
+ const ref = useRef(value);
4
+ if (value != null) {
5
+ ref.current = value;
6
+ }
7
+ return ref;
8
+ };
@@ -0,0 +1,5 @@
1
+ export declare const useLifeCycle: (fn: () => {
2
+ mount?: VoidFunction;
3
+ unmount?: VoidFunction;
4
+ }) => void;
5
+ //# sourceMappingURL=use-life-cycle.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-life-cycle.d.ts","sourceRoot":"","sources":["../../../src/react/hooks/use-life-cycle.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,YAAY,GACvB,IAAI,MAAM;IACR,KAAK,CAAC,EAAE,YAAY,CAAC;IACrB,OAAO,CAAC,EAAE,YAAY,CAAC;CACxB,SASF,CAAC"}
@@ -0,0 +1,10 @@
1
+ import { useEffect } from 'react';
2
+ import { useSyncRef } from './use-sync-ref.js';
3
+ export const useLifeCycle = (fn) => {
4
+ const fnRef = useSyncRef(fn);
5
+ useEffect(() => {
6
+ const fnOperation = fnRef.current();
7
+ fnOperation.mount?.();
8
+ return fnOperation.unmount?.();
9
+ }, []);
10
+ };
@@ -0,0 +1,2 @@
1
+ export declare const useResizeObserver: (callback: ResizeObserverCallback) => import("react").MutableRefObject<ResizeObserver>;
2
+ //# sourceMappingURL=use-resize-observer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-resize-observer.d.ts","sourceRoot":"","sources":["../../../src/react/hooks/use-resize-observer.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,iBAAiB,GAAI,UAAU,sBAAsB,qDAUjE,CAAC"}
@@ -0,0 +1,11 @@
1
+ import { useLayoutEffect } from 'react';
2
+ import { useDefineRef } from './use-define-ref.js';
3
+ export const useResizeObserver = (callback) => {
4
+ const resizeObserverRef = useDefineRef(() => new ResizeObserver(callback));
5
+ useLayoutEffect(() => {
6
+ return () => {
7
+ resizeObserverRef.current.disconnect();
8
+ };
9
+ }, []);
10
+ return resizeObserverRef;
11
+ };
@@ -0,0 +1,2 @@
1
+ export declare const useSyncRef: <T>(value: T) => import("react").MutableRefObject<T>;
2
+ //# sourceMappingURL=use-sync-ref.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-sync-ref.d.ts","sourceRoot":"","sources":["../../../src/react/hooks/use-sync-ref.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,UAAU,GAAI,CAAC,EAAE,OAAO,CAAC,wCAIrC,CAAC"}
@@ -0,0 +1,6 @@
1
+ import { useRef } from 'react';
2
+ export const useSyncRef = (value) => {
3
+ const ref = useRef(value);
4
+ ref.current = value;
5
+ return ref;
6
+ };
@@ -0,0 +1,2 @@
1
+ export declare const useToggle: (initialState?: boolean) => readonly [boolean, () => void, import("react").Dispatch<import("react").SetStateAction<boolean>>];
2
+ //# sourceMappingURL=use-toggle.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-toggle.d.ts","sourceRoot":"","sources":["../../../src/react/hooks/use-toggle.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,SAAS,GAAI,eAAe,OAAO,sGAM/C,CAAC"}
@@ -0,0 +1,6 @@
1
+ import { useCallback, useState } from 'react';
2
+ export const useToggle = (initialState) => {
3
+ const [toggled, setToggled] = useState(!!initialState);
4
+ const toggle = useCallback(() => setToggled((toggled) => !toggled), []);
5
+ return [toggled, toggle, setToggled];
6
+ };
@@ -0,0 +1,5 @@
1
+ export declare const useValue: <T>(defaults: T | (() => T)) => {
2
+ value: T;
3
+ set: import("react").Dispatch<import("react").SetStateAction<T>>;
4
+ };
5
+ //# sourceMappingURL=use-value.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-value.d.ts","sourceRoot":"","sources":["../../../src/react/hooks/use-value.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,QAAQ,GAAI,CAAC,EAAE,UAAU,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;;;CAOlD,CAAC"}
@@ -0,0 +1,8 @@
1
+ import { useState } from 'react';
2
+ export const useValue = (defaults) => {
3
+ const [value, setValue] = useState(defaults);
4
+ return {
5
+ value,
6
+ set: setValue,
7
+ };
8
+ };
@@ -0,0 +1,2 @@
1
+ export declare const useVisibilityState: () => DocumentVisibilityState | undefined;
2
+ //# sourceMappingURL=use-visibility-state.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-visibility-state.d.ts","sourceRoot":"","sources":["../../../src/react/hooks/use-visibility-state.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,kBAAkB,2CAgB9B,CAAC"}
@@ -0,0 +1,14 @@
1
+ import { useEffect, useState } from 'react';
2
+ export const useVisibilityState = () => {
3
+ const [state, setState] = useState();
4
+ useEffect(() => {
5
+ const handleVisibilityChange = () => {
6
+ setState(document.visibilityState);
7
+ };
8
+ document.addEventListener('visibilitychange', handleVisibilityChange);
9
+ return () => {
10
+ document.removeEventListener('visibilitychange', handleVisibilityChange);
11
+ };
12
+ }, []);
13
+ return state;
14
+ };
@@ -0,0 +1,2 @@
1
+ export * from './hooks/index.js';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC"}
package/react/index.js ADDED
@@ -0,0 +1 @@
1
+ export * from './hooks/index.js';
package/sound.js CHANGED
@@ -7,6 +7,6 @@ export const playSound = async (file, { volume = 1 } = {}) => {
7
7
  audio.muted = !volume;
8
8
  await audio.play();
9
9
  audio.remove();
10
- // @ts-ignore
10
+ // @ts-expect-error
11
11
  audio = null;
12
12
  };
@@ -22,7 +22,7 @@ function getType(value) {
22
22
  return Type.Null;
23
23
  }
24
24
  // handle DOM elements
25
- // @ts-ignore
25
+ // @ts-expect-error
26
26
  if (value && (value.nodeType === 1 || value.nodeType === 9)) {
27
27
  return Type.Element;
28
28
  }