yummies 7.11.0 → 7.13.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 (159) hide show
  1. package/README.md +5 -87
  2. package/async.cjs +179 -48
  3. package/async.cjs.map +1 -1
  4. package/async.d.ts +125 -7
  5. package/async.js +180 -54
  6. package/async.js.map +1 -1
  7. package/chunk-CVq3Gv4J.cjs +50 -0
  8. package/chunk-YKewjYmz.js +37 -0
  9. package/common.cjs +48 -8
  10. package/common.cjs.map +1 -1
  11. package/common.d.ts +53 -2
  12. package/common.js +49 -11
  13. package/common.js.map +1 -1
  14. package/complex.cjs +275 -128
  15. package/complex.cjs.map +1 -1
  16. package/complex.d.ts +66 -0
  17. package/complex.js +275 -133
  18. package/complex.js.map +1 -1
  19. package/cookie.cjs +17 -7
  20. package/cookie.cjs.map +1 -1
  21. package/cookie.d.ts +26 -0
  22. package/cookie.js +18 -9
  23. package/cookie.js.map +1 -1
  24. package/css.cjs +163 -39
  25. package/css.cjs.map +1 -1
  26. package/css.d.ts +115 -6
  27. package/css.js +159 -41
  28. package/css.js.map +1 -1
  29. package/data.cjs +90 -55
  30. package/data.cjs.map +1 -1
  31. package/data.d.ts +50 -0
  32. package/data.js +91 -61
  33. package/data.js.map +1 -1
  34. package/date-time.cjs +594 -412
  35. package/date-time.cjs.map +1 -1
  36. package/date-time.d.ts +105 -0
  37. package/date-time.js +591 -421
  38. package/date-time.js.map +1 -1
  39. package/device.cjs +65 -23
  40. package/device.cjs.map +1 -1
  41. package/device.d.ts +49 -0
  42. package/device.js +66 -31
  43. package/device.js.map +1 -1
  44. package/encodings.cjs +275 -266
  45. package/encodings.cjs.map +1 -1
  46. package/encodings.d.ts +25 -0
  47. package/encodings.js +276 -268
  48. package/encodings.js.map +1 -1
  49. package/errors.cjs +36 -18
  50. package/errors.cjs.map +1 -1
  51. package/errors.d.ts +17 -0
  52. package/errors.js +35 -19
  53. package/errors.js.map +1 -1
  54. package/file.cjs +58 -24
  55. package/file.cjs.map +1 -1
  56. package/file.d.ts +32 -0
  57. package/file.js +59 -27
  58. package/file.js.map +1 -1
  59. package/format.cjs +125 -83
  60. package/format.cjs.map +1 -1
  61. package/format.d.ts +18 -0
  62. package/format.js +118 -82
  63. package/format.js.map +1 -1
  64. package/html.cjs +242 -137
  65. package/html.cjs.map +1 -1
  66. package/html.d.ts +81 -0
  67. package/html.js +239 -150
  68. package/html.js.map +1 -1
  69. package/id.cjs +90 -17
  70. package/id.cjs.map +1 -1
  71. package/id.d.ts +16 -0
  72. package/id.js +89 -24
  73. package/id.js.map +1 -1
  74. package/imports.cjs +57 -29
  75. package/imports.cjs.map +1 -1
  76. package/imports.d.ts +24 -0
  77. package/imports.js +56 -31
  78. package/imports.js.map +1 -1
  79. package/math.cjs +32 -6
  80. package/math.cjs.map +1 -1
  81. package/math.d.ts +33 -0
  82. package/math.js +33 -10
  83. package/math.js.map +1 -1
  84. package/media.cjs +291 -84
  85. package/media.cjs.map +1 -1
  86. package/media.d.ts +204 -2
  87. package/media.js +290 -93
  88. package/media.js.map +1 -1
  89. package/mobx.cjs +449 -193
  90. package/mobx.cjs.map +1 -1
  91. package/mobx.d.ts +108 -0
  92. package/mobx.js +447 -200
  93. package/mobx.js.map +1 -1
  94. package/ms.cjs +37 -10
  95. package/ms.cjs.map +1 -1
  96. package/ms.d.ts +16 -0
  97. package/ms.js +38 -13
  98. package/ms.js.map +1 -1
  99. package/number.cjs +29 -7
  100. package/number.cjs.map +1 -1
  101. package/number.d.ts +16 -0
  102. package/number.js +30 -9
  103. package/number.js.map +1 -1
  104. package/package.json +11 -3
  105. package/parser.cjs +117 -64
  106. package/parser.cjs.map +1 -1
  107. package/parser.d.ts +17 -0
  108. package/parser.js +111 -64
  109. package/parser.js.map +1 -1
  110. package/price.cjs +24 -18
  111. package/price.cjs.map +1 -1
  112. package/price.d.ts +24 -0
  113. package/price.js +25 -20
  114. package/price.js.map +1 -1
  115. package/random.cjs +95 -13
  116. package/random.cjs.map +1 -1
  117. package/random.d.ts +80 -0
  118. package/random.js +96 -22
  119. package/random.js.map +1 -1
  120. package/react.cjs +673 -214
  121. package/react.cjs.map +1 -1
  122. package/react.d.ts +21 -0
  123. package/react.js +674 -239
  124. package/react.js.map +1 -1
  125. package/sound.cjs +30 -9
  126. package/sound.cjs.map +1 -1
  127. package/sound.d.ts +16 -0
  128. package/sound.js +31 -11
  129. package/sound.js.map +1 -1
  130. package/storage.cjs +49 -50
  131. package/storage.cjs.map +1 -1
  132. package/storage.d.ts +24 -0
  133. package/storage.js +50 -53
  134. package/storage.js.map +1 -1
  135. package/text.cjs +67 -34
  136. package/text.cjs.map +1 -1
  137. package/text.d.ts +16 -0
  138. package/text.js +68 -37
  139. package/text.js.map +1 -1
  140. package/type-guard.cjs +292 -72
  141. package/type-guard.cjs.map +1 -1
  142. package/type-guard.d.ts +18 -0
  143. package/type-guard.js +288 -73
  144. package/type-guard.js.map +1 -1
  145. package/types.cjs +0 -2
  146. package/types.d.ts +41 -0
  147. package/types.global.cjs +0 -2
  148. package/types.global.d.ts +41 -0
  149. package/types.global.js +0 -2
  150. package/types.js +0 -2
  151. package/vibrate.cjs +47 -6
  152. package/vibrate.cjs.map +1 -1
  153. package/vibrate.d.ts +39 -1
  154. package/vibrate.js +48 -8
  155. package/vibrate.js.map +1 -1
  156. package/types.cjs.map +0 -1
  157. package/types.global.cjs.map +0 -1
  158. package/types.global.js.map +0 -1
  159. package/types.js.map +0 -1
package/async.js CHANGED
@@ -1,60 +1,186 @@
1
- const sleep = (time = 0, signal) => new Promise((resolve, reject) => {
2
- if (signal) {
3
- const abortListener = () => {
4
- clearTimeout(timerId);
5
- reject(signal?.reason);
6
- };
7
- const timerId = setTimeout(() => {
8
- signal.removeEventListener("abort", abortListener);
9
- resolve();
10
- }, time);
11
- signal.addEventListener("abort", abortListener, { once: true });
12
- } else {
13
- setTimeout(resolve, time);
14
- }
1
+ //#region src/async.ts
2
+ /**
3
+ * ---header-docs-section---
4
+ * # yummies/async
5
+ *
6
+ * ## Description
7
+ *
8
+ * Helpers for asynchronous control flow: delays, cancellable waits, scheduling on the next frame,
9
+ * and small utilities around `requestAnimationFrame` and `queueMicrotask`. They complement native
10
+ * `Promise`/`AbortSignal` patterns and keep timing logic easy to test and tree-shake per call site.
11
+ * Import only what you need from `yummies/async` so bundlers can drop unused helpers.
12
+ *
13
+ * ## Usage
14
+ *
15
+ * ```ts
16
+ * import { sleep } from "yummies/async";
17
+ * ```
18
+ */
19
+ /**
20
+ * Returns a promise that resolves after `time` milliseconds.
21
+ *
22
+ * When `signal` is passed and becomes aborted before the delay elapses, the promise
23
+ * rejects with `signal.reason` (same as native `fetch` / `AbortController` usage).
24
+ * The timeout is cleared on abort so no resolve happens after cancellation.
25
+ *
26
+ * @param time - Delay in milliseconds. Defaults to `0` (next macrotask tick, same idea as `setTimeout(0)`).
27
+ * @param signal - Optional `AbortSignal` to cancel the wait early.
28
+ * @returns A promise that resolves with `void` when the delay completes, or rejects if aborted.
29
+ *
30
+ * @example
31
+ * Basic pause in an async function:
32
+ * ```ts
33
+ * await sleep(250);
34
+ * console.log('after 250ms');
35
+ * ```
36
+ *
37
+ * @example
38
+ * Cancellable delay tied to component unmount or user action:
39
+ * ```ts
40
+ * const ac = new AbortController();
41
+ * try {
42
+ * await sleep(5000, ac.signal);
43
+ * } catch (e) {
44
+ * // aborted — e is signal.reason
45
+ * }
46
+ * ac.abort('user cancelled');
47
+ * ```
48
+ */
49
+ var sleep = (time = 0, signal) => new Promise((resolve, reject) => {
50
+ if (signal) {
51
+ const abortListener = () => {
52
+ clearTimeout(timerId);
53
+ reject(signal?.reason);
54
+ };
55
+ const timerId = setTimeout(() => {
56
+ signal.removeEventListener("abort", abortListener);
57
+ resolve();
58
+ }, time);
59
+ signal.addEventListener("abort", abortListener, { once: true });
60
+ } else setTimeout(resolve, time);
15
61
  });
16
- const waitAsync = async (ms = 1e3) => new Promise((resolve) => setTimeout(resolve, ms));
17
- const endlessRAF = (quitFunction, asMicrotask) => {
18
- if (quitFunction()) return;
19
- const raf = () => requestAnimationFrame(() => endlessRAF(quitFunction, asMicrotask));
20
- if (asMicrotask) {
21
- queueMicrotask(raf);
22
- } else {
23
- raf();
24
- }
62
+ /**
63
+ * Creates a promise that resolves after the specified number of milliseconds.
64
+ *
65
+ * @deprecated Use `sleep` instead.
66
+ * @param ms Delay in milliseconds.
67
+ * @returns Promise
68
+ */
69
+ var waitAsync = async (ms = 1e3) => new Promise((resolve) => setTimeout(resolve, ms));
70
+ /**
71
+ * Runs a loop driven by `requestAnimationFrame`: on each frame, `quitFunction` is called first.
72
+ * If it returns a truthy value, the loop stops and no further frames are scheduled.
73
+ * If it returns falsy or nothing, the next frame is scheduled recursively.
74
+ *
75
+ * Use this for per-frame work (animations, layout reads after paint) without managing
76
+ * `cancelAnimationFrame` manually — returning `true` from `quitFunction` is the exit condition.
77
+ *
78
+ * When `asMicrotask` is `true`, scheduling the next RAF is deferred with `queueMicrotask`
79
+ * so other microtasks can run before the frame is requested (useful when you need to
80
+ * batch DOM updates or let reactive frameworks flush first).
81
+ *
82
+ * @param quitFunction - Invoked each animation frame. Return `true` to stop the loop.
83
+ * @param asMicrotask - If `true`, wrap the `requestAnimationFrame` call in `queueMicrotask`.
84
+ *
85
+ * @example
86
+ * Stop after 60 frames (~1s at 60Hz):
87
+ * ```ts
88
+ * let frames = 0;
89
+ * endlessRAF(() => {
90
+ * frames++;
91
+ * updateSomething(frames);
92
+ * return frames >= 60;
93
+ * });
94
+ * ```
95
+ *
96
+ * @example
97
+ * Run until an element is removed or a flag is set:
98
+ * ```ts
99
+ * let running = true;
100
+ * endlessRAF(() => {
101
+ * if (!running || !document.body.contains(el)) return true;
102
+ * draw(el);
103
+ * }, true);
104
+ * ```
105
+ */
106
+ var endlessRAF = (quitFunction, asMicrotask) => {
107
+ if (quitFunction()) return;
108
+ const raf = () => requestAnimationFrame(() => endlessRAF(quitFunction, asMicrotask));
109
+ if (asMicrotask) queueMicrotask(raf);
110
+ else raf();
25
111
  };
112
+ /**
113
+ * Like `setTimeout`, but if `signal` aborts before the delay fires, the timer is cleared
114
+ * and `callback` is never run. If the callback runs normally, the abort listener is removed.
115
+ *
116
+ * Does nothing special if `signal` is omitted — behaves like a plain timeout.
117
+ *
118
+ * @param callback - Function to run once after `delayInMs` (same as `setTimeout` callback).
119
+ * @param delayInMs - Milliseconds to wait. Passed through to `setTimeout` (browser/Node semantics apply).
120
+ * @param signal - When aborted, clears the pending timeout so `callback` is not invoked.
121
+ *
122
+ * @example
123
+ * ```ts
124
+ * const controller = new AbortController();
125
+ * setAbortableTimeout(() => console.log('done'), 500, controller.signal);
126
+ * // later: controller.abort(); // timeout cancelled, log never runs
127
+ * ```
128
+ *
129
+ * @example
130
+ * Zero-delay scheduling that can still be cancelled before the macrotask runs:
131
+ * ```ts
132
+ * const ac = new AbortController();
133
+ * setAbortableTimeout(() => startIntro(), 0, ac.signal);
134
+ * // e.g. on teardown: ac.abort();
135
+ * ```
136
+ */
26
137
  function setAbortableTimeout(callback, delayInMs, signal) {
27
- let internalTimer = null;
28
- const handleAbort = () => {
29
- if (internalTimer == null) {
30
- return;
31
- }
32
- clearTimeout(internalTimer);
33
- internalTimer = null;
34
- };
35
- signal?.addEventListener("abort", handleAbort, { once: true });
36
- internalTimer = setTimeout(() => {
37
- signal?.removeEventListener("abort", handleAbort);
38
- callback();
39
- }, delayInMs);
138
+ let internalTimer = null;
139
+ const handleAbort = () => {
140
+ if (internalTimer == null) return;
141
+ clearTimeout(internalTimer);
142
+ internalTimer = null;
143
+ };
144
+ signal?.addEventListener("abort", handleAbort, { once: true });
145
+ internalTimer = setTimeout(() => {
146
+ signal?.removeEventListener("abort", handleAbort);
147
+ callback();
148
+ }, delayInMs);
40
149
  }
150
+ /**
151
+ * Like `setInterval`, but when `signal` aborts, the interval is cleared with `clearInterval`
152
+ * and `callback` stops being called. If `signal` is omitted, behaves like a normal interval
153
+ * (you must clear it yourself).
154
+ *
155
+ * @param callback - Invoked every `delayInMs` milliseconds until aborted or cleared.
156
+ * @param delayInMs - Interval period in milliseconds (same as `setInterval`).
157
+ * @param signal - Aborting stops the interval and removes the abort listener path from keeping work alive.
158
+ *
159
+ * @example
160
+ * ```ts
161
+ * const controller = new AbortController();
162
+ * setAbortableInterval(() => console.log('tick'), 1000, controller.signal);
163
+ * // stop: controller.abort();
164
+ * ```
165
+ *
166
+ * @example
167
+ * ```ts
168
+ * const ac = new AbortController();
169
+ * setAbortableInterval(syncStatus, 30_000, ac.signal);
170
+ * window.addEventListener('beforeunload', () => ac.abort());
171
+ * ```
172
+ */
41
173
  function setAbortableInterval(callback, delayInMs, signal) {
42
- let timer = null;
43
- const handleAbort = () => {
44
- if (timer == null) {
45
- return;
46
- }
47
- clearInterval(timer);
48
- timer = null;
49
- };
50
- signal?.addEventListener("abort", handleAbort, { once: true });
51
- timer = setInterval(callback, delayInMs);
174
+ let timer = null;
175
+ const handleAbort = () => {
176
+ if (timer == null) return;
177
+ clearInterval(timer);
178
+ timer = null;
179
+ };
180
+ signal?.addEventListener("abort", handleAbort, { once: true });
181
+ timer = setInterval(callback, delayInMs);
52
182
  }
53
- export {
54
- endlessRAF,
55
- setAbortableInterval,
56
- setAbortableTimeout,
57
- sleep,
58
- waitAsync
59
- };
60
- //# sourceMappingURL=async.js.map
183
+ //#endregion
184
+ export { endlessRAF, setAbortableInterval, setAbortableTimeout, sleep, waitAsync };
185
+
186
+ //# sourceMappingURL=async.js.map
package/async.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"async.js","sources":["../src/async.ts"],"sourcesContent":["/**\n * Creates a promise that resolves after the specified number of milliseconds.\n *\n * @param time Delay in milliseconds.\n * @returns Promise\n */\nexport const sleep = (time: number = 0, signal?: AbortSignal) =>\n new Promise<void>((resolve, reject) => {\n if (signal) {\n const abortListener = () => {\n clearTimeout(timerId);\n reject(signal?.reason);\n };\n const timerId = setTimeout(() => {\n signal.removeEventListener('abort', abortListener);\n resolve();\n }, time);\n signal.addEventListener('abort', abortListener, { once: true });\n } else {\n setTimeout(resolve, time);\n }\n });\n\n/**\n * Creates a promise that resolves after the specified number of milliseconds.\n *\n * @deprecated Use `sleep` instead.\n * @param ms Delay in milliseconds.\n * @returns Promise\n */\nexport const waitAsync = async (ms = 1000) =>\n new Promise((resolve) => setTimeout(resolve, ms));\n\n/**\n * Repeatedly schedules `requestAnimationFrame` until `quitFunction` returns `true`.\n *\n * @param quitFunction Function executed on each animation frame.\n * @param asMicrotask Additionally wraps the RAF scheduling in `queueMicrotask`.\n * @returns void\n */\nexport const endlessRAF = (\n quitFunction: () => boolean | void,\n asMicrotask?: boolean,\n) => {\n if (quitFunction()) return;\n\n const raf = () =>\n requestAnimationFrame(() => endlessRAF(quitFunction, asMicrotask));\n\n if (asMicrotask) {\n queueMicrotask(raf);\n } else {\n raf();\n }\n};\n\nexport function setAbortableTimeout(\n callback: VoidFunction,\n delayInMs?: number,\n signal?: AbortSignal,\n) {\n let internalTimer: number | null = null;\n\n const handleAbort = () => {\n if (internalTimer == null) {\n return;\n }\n clearTimeout(internalTimer);\n internalTimer = null;\n };\n\n signal?.addEventListener('abort', handleAbort, { once: true });\n\n internalTimer = setTimeout(() => {\n signal?.removeEventListener('abort', handleAbort);\n callback();\n }, delayInMs);\n}\n\nexport function setAbortableInterval(\n callback: VoidFunction,\n delayInMs?: number,\n signal?: AbortSignal,\n) {\n let timer: number | null = null;\n\n const handleAbort = () => {\n if (timer == null) {\n return;\n }\n clearInterval(timer);\n timer = null;\n };\n\n signal?.addEventListener('abort', handleAbort, { once: true });\n\n timer = setInterval(callback, delayInMs);\n}\n"],"names":[],"mappings":"AAMO,MAAM,QAAQ,CAAC,OAAe,GAAG,WACtC,IAAI,QAAc,CAAC,SAAS,WAAW;AACrC,MAAI,QAAQ;AACV,UAAM,gBAAgB,MAAM;AAC1B,mBAAa,OAAO;AACpB,aAAO,QAAQ,MAAM;AAAA,IACvB;AACA,UAAM,UAAU,WAAW,MAAM;AAC/B,aAAO,oBAAoB,SAAS,aAAa;AACjD,cAAA;AAAA,IACF,GAAG,IAAI;AACP,WAAO,iBAAiB,SAAS,eAAe,EAAE,MAAM,MAAM;AAAA,EAChE,OAAO;AACL,eAAW,SAAS,IAAI;AAAA,EAC1B;AACF,CAAC;AASI,MAAM,YAAY,OAAO,KAAK,QACnC,IAAI,QAAQ,CAAC,YAAY,WAAW,SAAS,EAAE,CAAC;AAS3C,MAAM,aAAa,CACxB,cACA,gBACG;AACH,MAAI,eAAgB;AAEpB,QAAM,MAAM,MACV,sBAAsB,MAAM,WAAW,cAAc,WAAW,CAAC;AAEnE,MAAI,aAAa;AACf,mBAAe,GAAG;AAAA,EACpB,OAAO;AACL,QAAA;AAAA,EACF;AACF;AAEO,SAAS,oBACd,UACA,WACA,QACA;AACA,MAAI,gBAA+B;AAEnC,QAAM,cAAc,MAAM;AACxB,QAAI,iBAAiB,MAAM;AACzB;AAAA,IACF;AACA,iBAAa,aAAa;AAC1B,oBAAgB;AAAA,EAClB;AAEA,UAAQ,iBAAiB,SAAS,aAAa,EAAE,MAAM,MAAM;AAE7D,kBAAgB,WAAW,MAAM;AAC/B,YAAQ,oBAAoB,SAAS,WAAW;AAChD,aAAA;AAAA,EACF,GAAG,SAAS;AACd;AAEO,SAAS,qBACd,UACA,WACA,QACA;AACA,MAAI,QAAuB;AAE3B,QAAM,cAAc,MAAM;AACxB,QAAI,SAAS,MAAM;AACjB;AAAA,IACF;AACA,kBAAc,KAAK;AACnB,YAAQ;AAAA,EACV;AAEA,UAAQ,iBAAiB,SAAS,aAAa,EAAE,MAAM,MAAM;AAE7D,UAAQ,YAAY,UAAU,SAAS;AACzC;"}
1
+ {"version":3,"file":"async.js","names":[],"sources":["../src/async.ts"],"sourcesContent":["/**\n * ---header-docs-section---\n * # yummies/async\n *\n * ## Description\n *\n * Helpers for asynchronous control flow: delays, cancellable waits, scheduling on the next frame,\n * and small utilities around `requestAnimationFrame` and `queueMicrotask`. They complement native\n * `Promise`/`AbortSignal` patterns and keep timing logic easy to test and tree-shake per call site.\n * Import only what you need from `yummies/async` so bundlers can drop unused helpers.\n *\n * ## Usage\n *\n * ```ts\n * import { sleep } from \"yummies/async\";\n * ```\n */\n\n/**\n * Returns a promise that resolves after `time` milliseconds.\n *\n * When `signal` is passed and becomes aborted before the delay elapses, the promise\n * rejects with `signal.reason` (same as native `fetch` / `AbortController` usage).\n * The timeout is cleared on abort so no resolve happens after cancellation.\n *\n * @param time - Delay in milliseconds. Defaults to `0` (next macrotask tick, same idea as `setTimeout(0)`).\n * @param signal - Optional `AbortSignal` to cancel the wait early.\n * @returns A promise that resolves with `void` when the delay completes, or rejects if aborted.\n *\n * @example\n * Basic pause in an async function:\n * ```ts\n * await sleep(250);\n * console.log('after 250ms');\n * ```\n *\n * @example\n * Cancellable delay tied to component unmount or user action:\n * ```ts\n * const ac = new AbortController();\n * try {\n * await sleep(5000, ac.signal);\n * } catch (e) {\n * // aborted — e is signal.reason\n * }\n * ac.abort('user cancelled');\n * ```\n */\nexport const sleep = (time: number = 0, signal?: AbortSignal) =>\n new Promise<void>((resolve, reject) => {\n if (signal) {\n const abortListener = () => {\n clearTimeout(timerId);\n reject(signal?.reason);\n };\n const timerId = setTimeout(() => {\n signal.removeEventListener('abort', abortListener);\n resolve();\n }, time);\n signal.addEventListener('abort', abortListener, { once: true });\n } else {\n setTimeout(resolve, time);\n }\n });\n\n/**\n * Creates a promise that resolves after the specified number of milliseconds.\n *\n * @deprecated Use `sleep` instead.\n * @param ms Delay in milliseconds.\n * @returns Promise\n */\nexport const waitAsync = async (ms = 1000) =>\n new Promise((resolve) => setTimeout(resolve, ms));\n\n/**\n * Runs a loop driven by `requestAnimationFrame`: on each frame, `quitFunction` is called first.\n * If it returns a truthy value, the loop stops and no further frames are scheduled.\n * If it returns falsy or nothing, the next frame is scheduled recursively.\n *\n * Use this for per-frame work (animations, layout reads after paint) without managing\n * `cancelAnimationFrame` manually — returning `true` from `quitFunction` is the exit condition.\n *\n * When `asMicrotask` is `true`, scheduling the next RAF is deferred with `queueMicrotask`\n * so other microtasks can run before the frame is requested (useful when you need to\n * batch DOM updates or let reactive frameworks flush first).\n *\n * @param quitFunction - Invoked each animation frame. Return `true` to stop the loop.\n * @param asMicrotask - If `true`, wrap the `requestAnimationFrame` call in `queueMicrotask`.\n *\n * @example\n * Stop after 60 frames (~1s at 60Hz):\n * ```ts\n * let frames = 0;\n * endlessRAF(() => {\n * frames++;\n * updateSomething(frames);\n * return frames >= 60;\n * });\n * ```\n *\n * @example\n * Run until an element is removed or a flag is set:\n * ```ts\n * let running = true;\n * endlessRAF(() => {\n * if (!running || !document.body.contains(el)) return true;\n * draw(el);\n * }, true);\n * ```\n */\nexport const endlessRAF = (\n quitFunction: () => boolean | void,\n asMicrotask?: boolean,\n) => {\n if (quitFunction()) return;\n\n const raf = () =>\n requestAnimationFrame(() => endlessRAF(quitFunction, asMicrotask));\n\n if (asMicrotask) {\n queueMicrotask(raf);\n } else {\n raf();\n }\n};\n\n/**\n * Like `setTimeout`, but if `signal` aborts before the delay fires, the timer is cleared\n * and `callback` is never run. If the callback runs normally, the abort listener is removed.\n *\n * Does nothing special if `signal` is omitted — behaves like a plain timeout.\n *\n * @param callback - Function to run once after `delayInMs` (same as `setTimeout` callback).\n * @param delayInMs - Milliseconds to wait. Passed through to `setTimeout` (browser/Node semantics apply).\n * @param signal - When aborted, clears the pending timeout so `callback` is not invoked.\n *\n * @example\n * ```ts\n * const controller = new AbortController();\n * setAbortableTimeout(() => console.log('done'), 500, controller.signal);\n * // later: controller.abort(); // timeout cancelled, log never runs\n * ```\n *\n * @example\n * Zero-delay scheduling that can still be cancelled before the macrotask runs:\n * ```ts\n * const ac = new AbortController();\n * setAbortableTimeout(() => startIntro(), 0, ac.signal);\n * // e.g. on teardown: ac.abort();\n * ```\n */\nexport function setAbortableTimeout(\n callback: VoidFunction,\n delayInMs?: number,\n signal?: AbortSignal,\n) {\n let internalTimer: number | null = null;\n\n const handleAbort = () => {\n if (internalTimer == null) {\n return;\n }\n clearTimeout(internalTimer);\n internalTimer = null;\n };\n\n signal?.addEventListener('abort', handleAbort, { once: true });\n\n internalTimer = setTimeout(() => {\n signal?.removeEventListener('abort', handleAbort);\n callback();\n }, delayInMs);\n}\n\n/**\n * Like `setInterval`, but when `signal` aborts, the interval is cleared with `clearInterval`\n * and `callback` stops being called. If `signal` is omitted, behaves like a normal interval\n * (you must clear it yourself).\n *\n * @param callback - Invoked every `delayInMs` milliseconds until aborted or cleared.\n * @param delayInMs - Interval period in milliseconds (same as `setInterval`).\n * @param signal - Aborting stops the interval and removes the abort listener path from keeping work alive.\n *\n * @example\n * ```ts\n * const controller = new AbortController();\n * setAbortableInterval(() => console.log('tick'), 1000, controller.signal);\n * // stop: controller.abort();\n * ```\n *\n * @example\n * ```ts\n * const ac = new AbortController();\n * setAbortableInterval(syncStatus, 30_000, ac.signal);\n * window.addEventListener('beforeunload', () => ac.abort());\n * ```\n */\nexport function setAbortableInterval(\n callback: VoidFunction,\n delayInMs?: number,\n signal?: AbortSignal,\n) {\n let timer: number | null = null;\n\n const handleAbort = () => {\n if (timer == null) {\n return;\n }\n clearInterval(timer);\n timer = null;\n };\n\n signal?.addEventListener('abort', handleAbort, { once: true });\n\n timer = setInterval(callback, delayInMs);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgDA,IAAa,SAAS,OAAe,GAAG,WACtC,IAAI,SAAe,SAAS,WAAW;AACrC,KAAI,QAAQ;EACV,MAAM,sBAAsB;AAC1B,gBAAa,QAAQ;AACrB,UAAO,QAAQ,OAAO;;EAExB,MAAM,UAAU,iBAAiB;AAC/B,UAAO,oBAAoB,SAAS,cAAc;AAClD,YAAS;KACR,KAAK;AACR,SAAO,iBAAiB,SAAS,eAAe,EAAE,MAAM,MAAM,CAAC;OAE/D,YAAW,SAAS,KAAK;EAE3B;;;;;;;;AASJ,IAAa,YAAY,OAAO,KAAK,QACnC,IAAI,SAAS,YAAY,WAAW,SAAS,GAAG,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsCnD,IAAa,cACX,cACA,gBACG;AACH,KAAI,cAAc,CAAE;CAEpB,MAAM,YACJ,4BAA4B,WAAW,cAAc,YAAY,CAAC;AAEpE,KAAI,YACF,gBAAe,IAAI;KAEnB,MAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BT,SAAgB,oBACd,UACA,WACA,QACA;CACA,IAAI,gBAA+B;CAEnC,MAAM,oBAAoB;AACxB,MAAI,iBAAiB,KACnB;AAEF,eAAa,cAAc;AAC3B,kBAAgB;;AAGlB,SAAQ,iBAAiB,SAAS,aAAa,EAAE,MAAM,MAAM,CAAC;AAE9D,iBAAgB,iBAAiB;AAC/B,UAAQ,oBAAoB,SAAS,YAAY;AACjD,YAAU;IACT,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;AA0Bf,SAAgB,qBACd,UACA,WACA,QACA;CACA,IAAI,QAAuB;CAE3B,MAAM,oBAAoB;AACxB,MAAI,SAAS,KACX;AAEF,gBAAc,MAAM;AACpB,UAAQ;;AAGV,SAAQ,iBAAiB,SAAS,aAAa,EAAE,MAAM,MAAM,CAAC;AAE9D,SAAQ,YAAY,UAAU,UAAU"}
@@ -0,0 +1,50 @@
1
+ //#region \0rolldown/runtime.js
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __commonJSMin = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
9
+ var __exportAll = (all, no_symbols) => {
10
+ let target = {};
11
+ for (var name in all) __defProp(target, name, {
12
+ get: all[name],
13
+ enumerable: true
14
+ });
15
+ if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
16
+ return target;
17
+ };
18
+ var __copyProps = (to, from, except, desc) => {
19
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
20
+ key = keys[i];
21
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
22
+ get: ((k) => from[k]).bind(null, key),
23
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
24
+ });
25
+ }
26
+ return to;
27
+ };
28
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
29
+ value: mod,
30
+ enumerable: true
31
+ }) : target, mod));
32
+ //#endregion
33
+ Object.defineProperty(exports, "__commonJSMin", {
34
+ enumerable: true,
35
+ get: function() {
36
+ return __commonJSMin;
37
+ }
38
+ });
39
+ Object.defineProperty(exports, "__exportAll", {
40
+ enumerable: true,
41
+ get: function() {
42
+ return __exportAll;
43
+ }
44
+ });
45
+ Object.defineProperty(exports, "__toESM", {
46
+ enumerable: true,
47
+ get: function() {
48
+ return __toESM;
49
+ }
50
+ });
@@ -0,0 +1,37 @@
1
+ //#region \0rolldown/runtime.js
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __commonJSMin = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
9
+ var __exportAll = (all, no_symbols) => {
10
+ let target = {};
11
+ for (var name in all) __defProp(target, name, {
12
+ get: all[name],
13
+ enumerable: true
14
+ });
15
+ if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
16
+ return target;
17
+ };
18
+ var __copyProps = (to, from, except, desc) => {
19
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
20
+ key = keys[i];
21
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
22
+ get: ((k) => from[k]).bind(null, key),
23
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
24
+ });
25
+ }
26
+ return to;
27
+ };
28
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
29
+ value: mod,
30
+ enumerable: true
31
+ }) : target, mod));
32
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, { get: (a, b) => (typeof require !== "undefined" ? require : a)[b] }) : x)(function(x) {
33
+ if (typeof require !== "undefined") return require.apply(this, arguments);
34
+ throw Error("Calling `require` for \"" + x + "\" in an environment that doesn't expose the `require` function. See https://rolldown.rs/in-depth/bundling-cjs#require-external-modules for more details.");
35
+ });
36
+ //#endregion
37
+ export { __toESM as i, __exportAll as n, __require as r, __commonJSMin as t };
package/common.cjs CHANGED
@@ -1,12 +1,52 @@
1
- "use strict";
2
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const callFunction = (fn, ...args) => {
4
- if (typeof fn === "function") {
5
- return fn(...args);
6
- }
7
- return fn;
2
+ //#region src/common.ts
3
+ /**
4
+ * Normalizes a {@link MaybeFn} — a value that may be either a plain `TValue` or a function
5
+ * `(...args: TArgs) => TValue`. If `fn` is callable, it is invoked with `args` and the return
6
+ * value is returned; otherwise `fn` is returned as-is (treated as the resolved value).
7
+ *
8
+ * Typical uses: config fields that accept a static value or a lazy/computed factory, theme
9
+ * tokens, labels, or callbacks where the caller should not branch on `typeof fn` themselves.
10
+ *
11
+ * @template TValue - Result type when `fn` is not a function, or return type when it is.
12
+ * @template TArgs - Tuple of argument types passed through when `fn` is invoked.
13
+ *
14
+ * @param fn - Either a `TValue` or a function producing `TValue` from `args`.
15
+ * @param args - Arguments forwarded to `fn` only when `fn` is a function.
16
+ * @returns The resolved `TValue`.
17
+ *
18
+ * @example
19
+ * Plain value — returned unchanged (no call):
20
+ * ```ts
21
+ * const n = callFunction(42); // 42
22
+ * const label = callFunction('Hello'); // 'Hello'
23
+ * ```
24
+ *
25
+ * @example
26
+ * Function — called with the given arguments:
27
+ * ```ts
28
+ * const sum = callFunction((a: number, b: number) => a + b, 2, 3); // 5
29
+ * ```
30
+ *
31
+ * @example
32
+ * Same API for “static or factory” props:
33
+ * ```ts
34
+ * type Title = MaybeFn<string, [locale: string]>;
35
+ * const title: Title = (loc) => (loc === 'ru' ? 'Привет' : 'Hi');
36
+ * const text = callFunction(title, 'ru'); // 'Привет'
37
+ * const fixed = callFunction('Hi', 'ru'); // 'Hi' — args ignored
38
+ * ```
39
+ */
40
+ var callFunction = (fn, ...args) => {
41
+ if (typeof fn === "function") return fn(...args);
42
+ return fn;
8
43
  };
9
- const resolveFnValue = callFunction;
44
+ /**
45
+ * @deprecated use {callFunction}
46
+ */
47
+ var resolveFnValue = callFunction;
48
+ //#endregion
10
49
  exports.callFunction = callFunction;
11
50
  exports.resolveFnValue = resolveFnValue;
12
- //# sourceMappingURL=common.cjs.map
51
+
52
+ //# sourceMappingURL=common.cjs.map
package/common.cjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"common.cjs","sources":["../src/common.ts"],"sourcesContent":["import type { MaybeFn } from 'yummies/types';\n\n/**\n * @deprecated use {MaybeFn} type\n */\nexport type FnValue<TValue, TArgs extends any[] = []> = MaybeFn<TValue, TArgs>;\n\n/**\n * Calls the provided function with the given arguments if it is a function;\n * otherwise, returns the value directly.\n */\nexport const callFunction = <TValue, TArgs extends any[] = []>(\n fn: MaybeFn<TValue, TArgs>,\n ...args: TArgs\n) => {\n if (typeof fn === 'function') {\n return (fn as any)(...args) as TValue;\n }\n\n return fn;\n};\n\n/**\n * @deprecated use {callFunction}\n */\nexport const resolveFnValue = callFunction;\n"],"names":[],"mappings":";;AAWO,MAAM,eAAe,CAC1B,OACG,SACA;AACH,MAAI,OAAO,OAAO,YAAY;AAC5B,WAAQ,GAAW,GAAG,IAAI;AAAA,EAC5B;AAEA,SAAO;AACT;AAKO,MAAM,iBAAiB;;;"}
1
+ {"version":3,"file":"common.cjs","names":[],"sources":["../src/common.ts"],"sourcesContent":["/**\n * ---header-docs-section---\n * # yummies/common\n *\n * ## Description\n *\n * Small helpers for values that may be either plain data or callables (`MaybeFn` pattern). Use them\n * when a prop or config can be a static value or a factory, without forcing callers to branch on\n * `typeof` everywhere. The module also keeps a thin compatibility layer for older `FnValue` naming.\n * Everything is typed to preserve argument tuples and return types through `callFunction`.\n *\n * ## Usage\n *\n * ```ts\n * import { callFunction } from \"yummies/common\";\n * ```\n */\n\nimport type { MaybeFn } from 'yummies/types';\n\n/**\n * @deprecated use {MaybeFn} type\n */\nexport type FnValue<TValue, TArgs extends any[] = []> = MaybeFn<TValue, TArgs>;\n\n/**\n * Normalizes a {@link MaybeFn} — a value that may be either a plain `TValue` or a function\n * `(...args: TArgs) => TValue`. If `fn` is callable, it is invoked with `args` and the return\n * value is returned; otherwise `fn` is returned as-is (treated as the resolved value).\n *\n * Typical uses: config fields that accept a static value or a lazy/computed factory, theme\n * tokens, labels, or callbacks where the caller should not branch on `typeof fn` themselves.\n *\n * @template TValue - Result type when `fn` is not a function, or return type when it is.\n * @template TArgs - Tuple of argument types passed through when `fn` is invoked.\n *\n * @param fn - Either a `TValue` or a function producing `TValue` from `args`.\n * @param args - Arguments forwarded to `fn` only when `fn` is a function.\n * @returns The resolved `TValue`.\n *\n * @example\n * Plain value — returned unchanged (no call):\n * ```ts\n * const n = callFunction(42); // 42\n * const label = callFunction('Hello'); // 'Hello'\n * ```\n *\n * @example\n * Function — called with the given arguments:\n * ```ts\n * const sum = callFunction((a: number, b: number) => a + b, 2, 3); // 5\n * ```\n *\n * @example\n * Same API for “static or factory” props:\n * ```ts\n * type Title = MaybeFn<string, [locale: string]>;\n * const title: Title = (loc) => (loc === 'ru' ? 'Привет' : 'Hi');\n * const text = callFunction(title, 'ru'); // 'Привет'\n * const fixed = callFunction('Hi', 'ru'); // 'Hi' — args ignored\n * ```\n */\nexport const callFunction = <TValue, TArgs extends any[] = []>(\n fn: MaybeFn<TValue, TArgs>,\n ...args: TArgs\n) => {\n if (typeof fn === 'function') {\n return (fn as any)(...args) as TValue;\n }\n\n return fn;\n};\n\n/**\n * @deprecated use {callFunction}\n */\nexport const resolveFnValue = callFunction;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8DA,IAAa,gBACX,IACA,GAAG,SACA;AACH,KAAI,OAAO,OAAO,WAChB,QAAQ,GAAW,GAAG,KAAK;AAG7B,QAAO;;;;;AAMT,IAAa,iBAAiB"}
package/common.d.ts CHANGED
@@ -1,12 +1,63 @@
1
1
  import { MaybeFn } from 'yummies/types';
2
2
 
3
+ /**
4
+ * ---header-docs-section---
5
+ * # yummies/common
6
+ *
7
+ * ## Description
8
+ *
9
+ * Small helpers for values that may be either plain data or callables (`MaybeFn` pattern). Use them
10
+ * when a prop or config can be a static value or a factory, without forcing callers to branch on
11
+ * `typeof` everywhere. The module also keeps a thin compatibility layer for older `FnValue` naming.
12
+ * Everything is typed to preserve argument tuples and return types through `callFunction`.
13
+ *
14
+ * ## Usage
15
+ *
16
+ * ```ts
17
+ * import { callFunction } from "yummies/common";
18
+ * ```
19
+ */
20
+
3
21
  /**
4
22
  * @deprecated use {MaybeFn} type
5
23
  */
6
24
  type FnValue<TValue, TArgs extends any[] = []> = MaybeFn<TValue, TArgs>;
7
25
  /**
8
- * Calls the provided function with the given arguments if it is a function;
9
- * otherwise, returns the value directly.
26
+ * Normalizes a {@link MaybeFn} a value that may be either a plain `TValue` or a function
27
+ * `(...args: TArgs) => TValue`. If `fn` is callable, it is invoked with `args` and the return
28
+ * value is returned; otherwise `fn` is returned as-is (treated as the resolved value).
29
+ *
30
+ * Typical uses: config fields that accept a static value or a lazy/computed factory, theme
31
+ * tokens, labels, or callbacks where the caller should not branch on `typeof fn` themselves.
32
+ *
33
+ * @template TValue - Result type when `fn` is not a function, or return type when it is.
34
+ * @template TArgs - Tuple of argument types passed through when `fn` is invoked.
35
+ *
36
+ * @param fn - Either a `TValue` or a function producing `TValue` from `args`.
37
+ * @param args - Arguments forwarded to `fn` only when `fn` is a function.
38
+ * @returns The resolved `TValue`.
39
+ *
40
+ * @example
41
+ * Plain value — returned unchanged (no call):
42
+ * ```ts
43
+ * const n = callFunction(42); // 42
44
+ * const label = callFunction('Hello'); // 'Hello'
45
+ * ```
46
+ *
47
+ * @example
48
+ * Function — called with the given arguments:
49
+ * ```ts
50
+ * const sum = callFunction((a: number, b: number) => a + b, 2, 3); // 5
51
+ * ```
52
+ *
53
+ * @example
54
+ * Same API for “static or factory” props:
55
+ * ```ts
56
+ * type Title = MaybeFn<string, [locale: string]>;
57
+ * const title: Title = (loc) => (loc === 'ru' ? 'Привет' : 'Hi');
58
+ * const text = callFunction(title, 'ru'); // 'Привет'
59
+ * const fixed = callFunction('Hi', 'ru'); // 'Hi' — args ignored
60
+ * ```
10
61
  */
11
62
  declare const callFunction: <TValue, TArgs extends any[] = []>(fn: MaybeFn<TValue, TArgs>, ...args: TArgs) => TValue;
12
63
  /**
package/common.js CHANGED
@@ -1,12 +1,50 @@
1
- const callFunction = (fn, ...args) => {
2
- if (typeof fn === "function") {
3
- return fn(...args);
4
- }
5
- return fn;
1
+ //#region src/common.ts
2
+ /**
3
+ * Normalizes a {@link MaybeFn} — a value that may be either a plain `TValue` or a function
4
+ * `(...args: TArgs) => TValue`. If `fn` is callable, it is invoked with `args` and the return
5
+ * value is returned; otherwise `fn` is returned as-is (treated as the resolved value).
6
+ *
7
+ * Typical uses: config fields that accept a static value or a lazy/computed factory, theme
8
+ * tokens, labels, or callbacks where the caller should not branch on `typeof fn` themselves.
9
+ *
10
+ * @template TValue - Result type when `fn` is not a function, or return type when it is.
11
+ * @template TArgs - Tuple of argument types passed through when `fn` is invoked.
12
+ *
13
+ * @param fn - Either a `TValue` or a function producing `TValue` from `args`.
14
+ * @param args - Arguments forwarded to `fn` only when `fn` is a function.
15
+ * @returns The resolved `TValue`.
16
+ *
17
+ * @example
18
+ * Plain value — returned unchanged (no call):
19
+ * ```ts
20
+ * const n = callFunction(42); // 42
21
+ * const label = callFunction('Hello'); // 'Hello'
22
+ * ```
23
+ *
24
+ * @example
25
+ * Function — called with the given arguments:
26
+ * ```ts
27
+ * const sum = callFunction((a: number, b: number) => a + b, 2, 3); // 5
28
+ * ```
29
+ *
30
+ * @example
31
+ * Same API for “static or factory” props:
32
+ * ```ts
33
+ * type Title = MaybeFn<string, [locale: string]>;
34
+ * const title: Title = (loc) => (loc === 'ru' ? 'Привет' : 'Hi');
35
+ * const text = callFunction(title, 'ru'); // 'Привет'
36
+ * const fixed = callFunction('Hi', 'ru'); // 'Hi' — args ignored
37
+ * ```
38
+ */
39
+ var callFunction = (fn, ...args) => {
40
+ if (typeof fn === "function") return fn(...args);
41
+ return fn;
6
42
  };
7
- const resolveFnValue = callFunction;
8
- export {
9
- callFunction,
10
- resolveFnValue
11
- };
12
- //# sourceMappingURL=common.js.map
43
+ /**
44
+ * @deprecated use {callFunction}
45
+ */
46
+ var resolveFnValue = callFunction;
47
+ //#endregion
48
+ export { callFunction, resolveFnValue };
49
+
50
+ //# sourceMappingURL=common.js.map
package/common.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"common.js","sources":["../src/common.ts"],"sourcesContent":["import type { MaybeFn } from 'yummies/types';\n\n/**\n * @deprecated use {MaybeFn} type\n */\nexport type FnValue<TValue, TArgs extends any[] = []> = MaybeFn<TValue, TArgs>;\n\n/**\n * Calls the provided function with the given arguments if it is a function;\n * otherwise, returns the value directly.\n */\nexport const callFunction = <TValue, TArgs extends any[] = []>(\n fn: MaybeFn<TValue, TArgs>,\n ...args: TArgs\n) => {\n if (typeof fn === 'function') {\n return (fn as any)(...args) as TValue;\n }\n\n return fn;\n};\n\n/**\n * @deprecated use {callFunction}\n */\nexport const resolveFnValue = callFunction;\n"],"names":[],"mappings":"AAWO,MAAM,eAAe,CAC1B,OACG,SACA;AACH,MAAI,OAAO,OAAO,YAAY;AAC5B,WAAQ,GAAW,GAAG,IAAI;AAAA,EAC5B;AAEA,SAAO;AACT;AAKO,MAAM,iBAAiB;"}
1
+ {"version":3,"file":"common.js","names":[],"sources":["../src/common.ts"],"sourcesContent":["/**\n * ---header-docs-section---\n * # yummies/common\n *\n * ## Description\n *\n * Small helpers for values that may be either plain data or callables (`MaybeFn` pattern). Use them\n * when a prop or config can be a static value or a factory, without forcing callers to branch on\n * `typeof` everywhere. The module also keeps a thin compatibility layer for older `FnValue` naming.\n * Everything is typed to preserve argument tuples and return types through `callFunction`.\n *\n * ## Usage\n *\n * ```ts\n * import { callFunction } from \"yummies/common\";\n * ```\n */\n\nimport type { MaybeFn } from 'yummies/types';\n\n/**\n * @deprecated use {MaybeFn} type\n */\nexport type FnValue<TValue, TArgs extends any[] = []> = MaybeFn<TValue, TArgs>;\n\n/**\n * Normalizes a {@link MaybeFn} — a value that may be either a plain `TValue` or a function\n * `(...args: TArgs) => TValue`. If `fn` is callable, it is invoked with `args` and the return\n * value is returned; otherwise `fn` is returned as-is (treated as the resolved value).\n *\n * Typical uses: config fields that accept a static value or a lazy/computed factory, theme\n * tokens, labels, or callbacks where the caller should not branch on `typeof fn` themselves.\n *\n * @template TValue - Result type when `fn` is not a function, or return type when it is.\n * @template TArgs - Tuple of argument types passed through when `fn` is invoked.\n *\n * @param fn - Either a `TValue` or a function producing `TValue` from `args`.\n * @param args - Arguments forwarded to `fn` only when `fn` is a function.\n * @returns The resolved `TValue`.\n *\n * @example\n * Plain value — returned unchanged (no call):\n * ```ts\n * const n = callFunction(42); // 42\n * const label = callFunction('Hello'); // 'Hello'\n * ```\n *\n * @example\n * Function — called with the given arguments:\n * ```ts\n * const sum = callFunction((a: number, b: number) => a + b, 2, 3); // 5\n * ```\n *\n * @example\n * Same API for “static or factory” props:\n * ```ts\n * type Title = MaybeFn<string, [locale: string]>;\n * const title: Title = (loc) => (loc === 'ru' ? 'Привет' : 'Hi');\n * const text = callFunction(title, 'ru'); // 'Привет'\n * const fixed = callFunction('Hi', 'ru'); // 'Hi' — args ignored\n * ```\n */\nexport const callFunction = <TValue, TArgs extends any[] = []>(\n fn: MaybeFn<TValue, TArgs>,\n ...args: TArgs\n) => {\n if (typeof fn === 'function') {\n return (fn as any)(...args) as TValue;\n }\n\n return fn;\n};\n\n/**\n * @deprecated use {callFunction}\n */\nexport const resolveFnValue = callFunction;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8DA,IAAa,gBACX,IACA,GAAG,SACA;AACH,KAAI,OAAO,OAAO,WAChB,QAAQ,GAAW,GAAG,KAAK;AAG7B,QAAO;;;;;AAMT,IAAa,iBAAiB"}