@marianmeres/stuic 1.125.0 → 2.0.0-next.2

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 (252) hide show
  1. package/README.md +2 -8
  2. package/dist/_shared.css +2 -0
  3. package/dist/actions/autogrow.svelte.d.ts +6 -0
  4. package/dist/actions/autogrow.svelte.js +19 -0
  5. package/dist/actions/highlight-dragover.svelte.d.ts +7 -0
  6. package/dist/actions/highlight-dragover.svelte.js +38 -0
  7. package/dist/actions/index.d.ts +7 -0
  8. package/dist/actions/index.js +7 -0
  9. package/dist/actions/on-submit-validity-check.svelte.d.ts +15 -0
  10. package/dist/actions/on-submit-validity-check.svelte.js +58 -0
  11. package/dist/actions/tooltip/index.css +34 -0
  12. package/dist/actions/tooltip/tooltip.svelte.d.ts +13 -0
  13. package/dist/actions/tooltip/tooltip.svelte.js +203 -0
  14. package/dist/actions/trim.svelte.d.ts +4 -0
  15. package/dist/actions/trim.svelte.js +17 -0
  16. package/dist/actions/{validate.d.ts → validate.svelte.d.ts} +8 -8
  17. package/dist/actions/validate.svelte.js +90 -0
  18. package/dist/components/AlertConfirmPrompt/AlertConfirmPrompt.svelte +59 -385
  19. package/dist/components/AlertConfirmPrompt/AlertConfirmPrompt.svelte.d.ts +9 -101
  20. package/dist/components/AlertConfirmPrompt/Current.svelte +202 -0
  21. package/dist/components/AlertConfirmPrompt/Current.svelte.d.ts +22 -0
  22. package/dist/components/AlertConfirmPrompt/acp-icons.d.ts +7 -2
  23. package/dist/components/AlertConfirmPrompt/acp-icons.js +8 -8
  24. package/dist/components/AlertConfirmPrompt/alert-confirm-prompt-stack.svelte.d.ts +63 -0
  25. package/dist/components/AlertConfirmPrompt/alert-confirm-prompt-stack.svelte.js +144 -0
  26. package/dist/components/AlertConfirmPrompt/index.d.ts +2 -0
  27. package/dist/components/AlertConfirmPrompt/index.js +2 -0
  28. package/dist/components/AnimatedElipsis/AnimatedEllipsis.svelte +47 -0
  29. package/dist/components/AnimatedElipsis/AnimatedEllipsis.svelte.d.ts +7 -0
  30. package/dist/components/AnimatedElipsis/index.d.ts +1 -0
  31. package/dist/components/AnimatedElipsis/index.js +1 -0
  32. package/dist/components/AppShell/AppShell.svelte +188 -127
  33. package/dist/components/AppShell/AppShell.svelte.d.ts +62 -43
  34. package/dist/components/AppShell/index.d.ts +1 -0
  35. package/dist/components/AppShell/index.js +1 -0
  36. package/dist/components/Backdrop/Backdrop.svelte +149 -49
  37. package/dist/components/Backdrop/Backdrop.svelte.d.ts +22 -37
  38. package/dist/components/Backdrop/index.d.ts +1 -0
  39. package/dist/components/Backdrop/index.js +1 -0
  40. package/dist/components/Button/Button.svelte +122 -146
  41. package/dist/components/Button/Button.svelte.d.ts +22 -80
  42. package/dist/components/Button/index.css +16 -0
  43. package/dist/components/Button/index.d.ts +1 -0
  44. package/dist/components/Button/index.js +1 -0
  45. package/dist/components/ColResize/ColResize.svelte +0 -0
  46. package/dist/components/ColResize/ColResize.svelte.d.ts +26 -0
  47. package/dist/components/ColorScheme/{LocalColorScheme.svelte → ColorSchemeLocal.svelte} +2 -2
  48. package/dist/components/ColorScheme/ColorSchemeLocal.svelte.d.ts +26 -0
  49. package/dist/components/ColorScheme/{SystemAwareColorScheme.svelte → ColorSchemeSystemAware.svelte} +4 -4
  50. package/dist/components/ColorScheme/ColorSchemeSystemAware.svelte.d.ts +26 -0
  51. package/dist/components/ColorScheme/color-scheme.d.ts +26 -8
  52. package/dist/components/ColorScheme/color-scheme.js +40 -16
  53. package/dist/components/ColorScheme/index.d.ts +3 -0
  54. package/dist/components/ColorScheme/index.js +3 -0
  55. package/dist/components/DismissibleMessage/DismissibleMessage.svelte +76 -83
  56. package/dist/components/DismissibleMessage/DismissibleMessage.svelte.d.ts +16 -37
  57. package/dist/components/DismissibleMessage/index.css +13 -0
  58. package/dist/components/DismissibleMessage/index.d.ts +1 -0
  59. package/dist/components/DismissibleMessage/index.js +1 -0
  60. package/dist/components/Drawer/Drawer.svelte +155 -84
  61. package/dist/components/Drawer/Drawer.svelte.d.ts +24 -35
  62. package/dist/components/Drawer/index.d.ts +1 -0
  63. package/dist/components/Drawer/index.js +1 -0
  64. package/dist/components/HoverExpandableWidth/HoverExpandableWidth.svelte +150 -111
  65. package/dist/components/HoverExpandableWidth/HoverExpandableWidth.svelte.d.ts +16 -29
  66. package/dist/components/HoverExpandableWidth/index.d.ts +1 -0
  67. package/dist/components/HoverExpandableWidth/index.js +1 -0
  68. package/dist/components/Input/FieldCheckbox.svelte +174 -132
  69. package/dist/components/Input/FieldCheckbox.svelte.d.ts +28 -64
  70. package/dist/components/Input/FieldFile.svelte +166 -0
  71. package/dist/components/Input/FieldFile.svelte.d.ts +41 -0
  72. package/dist/components/Input/FieldInput.svelte +143 -0
  73. package/dist/components/Input/FieldInput.svelte.d.ts +41 -0
  74. package/dist/components/Input/FieldLikeButton.svelte +206 -0
  75. package/dist/components/Input/FieldLikeButton.svelte.d.ts +41 -0
  76. package/dist/components/Input/FieldOptions.svelte +646 -0
  77. package/dist/components/Input/FieldOptions.svelte.d.ts +58 -0
  78. package/dist/components/Input/FieldRadios.svelte +126 -77
  79. package/dist/components/Input/FieldRadios.svelte.d.ts +23 -61
  80. package/dist/components/Input/FieldSelect.svelte +160 -239
  81. package/dist/components/Input/FieldSelect.svelte.d.ts +40 -88
  82. package/dist/components/Input/FieldSwitch.svelte +132 -0
  83. package/dist/components/Input/FieldSwitch.svelte.d.ts +41 -0
  84. package/dist/components/Input/FieldTextarea.svelte +146 -0
  85. package/dist/components/Input/FieldTextarea.svelte.d.ts +44 -0
  86. package/dist/components/Input/Fieldset.svelte +21 -17
  87. package/dist/components/Input/Fieldset.svelte.d.ts +10 -27
  88. package/dist/components/Input/_internal/FieldRadioInternal.svelte +186 -0
  89. package/dist/components/Input/_internal/FieldRadioInternal.svelte.d.ts +30 -0
  90. package/dist/components/Input/_internal/InputWrap.svelte +216 -0
  91. package/dist/components/Input/_internal/InputWrap.svelte.d.ts +36 -0
  92. package/dist/components/Input/index.css +134 -0
  93. package/dist/components/Input/index.d.ts +11 -0
  94. package/dist/components/Input/index.js +11 -0
  95. package/dist/components/Input/types.d.ts +11 -0
  96. package/dist/components/KbdShortcut/KbdShortcut.svelte +89 -0
  97. package/dist/components/KbdShortcut/KbdShortcut.svelte.d.ts +17 -0
  98. package/dist/components/KbdShortcut/index.d.ts +1 -0
  99. package/dist/components/KbdShortcut/index.js +1 -0
  100. package/dist/components/Modal/Modal.svelte +127 -0
  101. package/dist/components/Modal/Modal.svelte.d.ts +32 -0
  102. package/dist/components/Modal/index.d.ts +1 -0
  103. package/dist/components/Modal/index.js +1 -0
  104. package/dist/components/ModalDialog/ModalDialog.svelte +137 -81
  105. package/dist/components/ModalDialog/ModalDialog.svelte.d.ts +17 -38
  106. package/dist/components/ModalDialog/index.d.ts +1 -0
  107. package/dist/components/ModalDialog/index.js +1 -0
  108. package/dist/components/Notifications/Notifications.svelte +259 -173
  109. package/dist/components/Notifications/Notifications.svelte.d.ts +32 -60
  110. package/dist/components/Notifications/index.css +12 -0
  111. package/dist/components/Notifications/index.d.ts +2 -0
  112. package/dist/components/Notifications/index.js +2 -0
  113. package/dist/components/Notifications/notifications-icons.d.ts +1 -1
  114. package/dist/components/Notifications/notifications-icons.js +4 -4
  115. package/dist/components/Notifications/notifications-stack.svelte.d.ts +89 -0
  116. package/dist/components/Notifications/notifications-stack.svelte.js +161 -0
  117. package/dist/components/Progress/Progress.svelte +26 -0
  118. package/dist/components/Progress/Progress.svelte.d.ts +10 -0
  119. package/dist/components/Progress/_internal/Bar.svelte +31 -0
  120. package/dist/components/Progress/_internal/Bar.svelte.d.ts +10 -0
  121. package/dist/components/Progress/_internal/Circle.svelte +10 -0
  122. package/dist/components/Progress/_internal/Circle.svelte.d.ts +7 -0
  123. package/dist/components/Progress/index.css +7 -0
  124. package/dist/components/Progress/index.d.ts +1 -0
  125. package/dist/components/Progress/index.js +1 -0
  126. package/dist/components/Spinner/Spinner.svelte +52 -37
  127. package/dist/components/Spinner/Spinner.svelte.d.ts +10 -22
  128. package/dist/components/Spinner/index.d.ts +1 -0
  129. package/dist/components/Spinner/index.js +1 -0
  130. package/dist/components/Switch/Switch.svelte +158 -118
  131. package/dist/components/Switch/Switch.svelte.d.ts +25 -66
  132. package/dist/components/Switch/SwitchButton.svelte +131 -0
  133. package/dist/components/Switch/SwitchButton.svelte.d.ts +21 -0
  134. package/dist/components/Switch/index.css +7 -0
  135. package/dist/components/Switch/index.d.ts +2 -0
  136. package/dist/components/Switch/index.js +2 -0
  137. package/dist/components/Thc/Thc.svelte +67 -10
  138. package/dist/components/Thc/Thc.svelte.d.ts +18 -22
  139. package/dist/components/Thc/index.d.ts +1 -0
  140. package/dist/components/Thc/index.js +1 -0
  141. package/dist/components/TwCheck/TwCheck.svelte +34 -0
  142. package/dist/components/TwCheck/TwCheck.svelte.d.ts +10 -0
  143. package/dist/components/TwCheck/index.css +5 -0
  144. package/dist/components/TwCheck/index.d.ts +1 -0
  145. package/dist/components/TwCheck/index.js +1 -0
  146. package/dist/components/X/X.svelte +12 -5
  147. package/dist/components/X/X.svelte.d.ts +6 -18
  148. package/dist/components/X/index.d.ts +1 -0
  149. package/dist/components/X/index.js +1 -0
  150. package/dist/index.css +26 -0
  151. package/dist/index.d.ts +21 -39
  152. package/dist/index.js +23 -54
  153. package/dist/types.d.ts +251 -2
  154. package/dist/types.js +248 -0
  155. package/dist/utils/breakpoint.svelte.d.ts +19 -0
  156. package/dist/utils/breakpoint.svelte.js +42 -0
  157. package/dist/utils/debounce.d.ts +13 -0
  158. package/dist/utils/debounce.js +22 -0
  159. package/dist/utils/device-pointer.svelte.d.ts +11 -0
  160. package/dist/utils/device-pointer.svelte.js +26 -0
  161. package/dist/utils/event-modifiers.d.ts +4 -0
  162. package/dist/utils/event-modifiers.js +29 -0
  163. package/dist/utils/get-id.d.ts +1 -1
  164. package/dist/utils/get-id.js +3 -1
  165. package/dist/utils/index.d.ts +21 -0
  166. package/dist/utils/index.js +21 -0
  167. package/dist/utils/is-browser.d.ts +1 -0
  168. package/dist/utils/is-browser.js +5 -0
  169. package/dist/utils/is-mac.d.ts +1 -0
  170. package/dist/utils/is-mac.js +11 -0
  171. package/dist/utils/maybe-json-parse.d.ts +1 -0
  172. package/dist/utils/maybe-json-parse.js +12 -0
  173. package/dist/utils/maybe-json-stringify.d.ts +1 -0
  174. package/dist/utils/maybe-json-stringify.js +11 -0
  175. package/dist/utils/move-array-item.d.ts +4 -0
  176. package/dist/utils/move-array-item.js +20 -0
  177. package/dist/utils/omit-pick.d.ts +2 -2
  178. package/dist/utils/omit-pick.js +10 -8
  179. package/dist/utils/paint.d.ts +18 -0
  180. package/dist/utils/paint.js +32 -0
  181. package/dist/utils/persistent-state.svelte.d.ts +23 -0
  182. package/dist/utils/persistent-state.svelte.js +48 -0
  183. package/dist/utils/prefers-reduced-motion.svelte.d.ts +2 -0
  184. package/dist/utils/prefers-reduced-motion.svelte.js +4 -0
  185. package/dist/utils/qsa.d.ts +1 -0
  186. package/dist/utils/qsa.js +3 -0
  187. package/dist/utils/sleep.d.ts +28 -0
  188. package/dist/utils/sleep.js +33 -0
  189. package/dist/utils/storage-abstraction.d.ts +35 -0
  190. package/dist/utils/storage-abstraction.js +136 -0
  191. package/dist/utils/str-hash.d.ts +7 -0
  192. package/dist/utils/str-hash.js +35 -0
  193. package/dist/utils/throttle.d.ts +1 -0
  194. package/dist/utils/throttle.js +47 -0
  195. package/dist/utils/to-integer.d.ts +1 -0
  196. package/dist/utils/to-integer.js +11 -0
  197. package/dist/utils/tr.d.ts +5 -0
  198. package/dist/utils/tr.js +13 -0
  199. package/dist/utils/tw-merge.d.ts +10 -0
  200. package/dist/utils/tw-merge.js +16 -0
  201. package/dist/utils/ucfirst.d.ts +1 -0
  202. package/dist/utils/ucfirst.js +6 -0
  203. package/package.json +66 -73
  204. package/dist/actions/autogrow.d.ts +0 -8
  205. package/dist/actions/autogrow.js +0 -22
  206. package/dist/actions/autoscroll.d.ts +0 -21
  207. package/dist/actions/autoscroll.js +0 -60
  208. package/dist/actions/drag-drop.d.ts +0 -28
  209. package/dist/actions/drag-drop.js +0 -152
  210. package/dist/actions/on-outside.d.ts +0 -9
  211. package/dist/actions/on-outside.js +0 -27
  212. package/dist/actions/pre-submit-validity-check.d.ts +0 -3
  213. package/dist/actions/pre-submit-validity-check.js +0 -21
  214. package/dist/actions/tooltip/_make-visible.d.ts +0 -3
  215. package/dist/actions/tooltip/_make-visible.js +0 -25
  216. package/dist/actions/tooltip/_maybe-pick-safe-placement.d.ts +0 -3
  217. package/dist/actions/tooltip/_maybe-pick-safe-placement.js +0 -86
  218. package/dist/actions/tooltip/_set-position.d.ts +0 -2
  219. package/dist/actions/tooltip/_set-position.js +0 -125
  220. package/dist/actions/tooltip/tooltip.d.ts +0 -42
  221. package/dist/actions/tooltip/tooltip.js +0 -299
  222. package/dist/actions/trim.d.ts +0 -4
  223. package/dist/actions/trim.js +0 -18
  224. package/dist/actions/validate.js +0 -80
  225. package/dist/components/AlertConfirmPrompt/alert-confirm-prompt.d.ts +0 -58
  226. package/dist/components/AlertConfirmPrompt/alert-confirm-prompt.js +0 -141
  227. package/dist/components/ColorScheme/LocalColorScheme.svelte.d.ts +0 -25
  228. package/dist/components/ColorScheme/SystemAwareColorScheme.svelte.d.ts +0 -25
  229. package/dist/components/Input/Field.svelte +0 -315
  230. package/dist/components/Input/Field.svelte.d.ts +0 -102
  231. package/dist/components/Input/PinInput.svelte +0 -151
  232. package/dist/components/Input/PinInput.svelte.d.ts +0 -51
  233. package/dist/components/Input/XFieldRadioInternal.svelte +0 -143
  234. package/dist/components/Input/XFieldRadioInternal.svelte.d.ts +0 -45
  235. package/dist/components/Notifications/notifications.d.ts +0 -78
  236. package/dist/components/Notifications/notifications.js +0 -215
  237. package/dist/components/Popover/Popover.svelte +0 -24
  238. package/dist/components/Popover/Popover.svelte.d.ts +0 -22
  239. package/dist/components/Spinner/Spinner.v5.svelte +0 -114
  240. package/dist/components/Spinner/Spinner.v5.svelte.d.ts +0 -16
  241. package/dist/utils/calculate-alignment.d.ts +0 -68
  242. package/dist/utils/calculate-alignment.js +0 -183
  243. package/dist/utils/device-pointer.d.ts +0 -5
  244. package/dist/utils/device-pointer.js +0 -10
  245. package/dist/utils/prefers-reduced-motion.d.ts +0 -6
  246. package/dist/utils/prefers-reduced-motion.js +0 -26
  247. package/dist/utils/tw-merge2.d.ts +0 -3
  248. package/dist/utils/tw-merge2.js +0 -9
  249. package/dist/utils/tw-types.d.ts +0 -1
  250. package/dist/utils/window-size.d.ts +0 -22
  251. package/dist/utils/window-size.js +0 -35
  252. /package/dist/{utils/tw-types.js → components/Input/types.js} +0 -0
@@ -0,0 +1,48 @@
1
+ import { localStorageValue, sessionStorageValue } from "./storage-abstraction.js";
2
+ /**
3
+ * Mirroring $state to local or session storage.
4
+ */
5
+ class PersistentState {
6
+ key;
7
+ initialValue;
8
+ type;
9
+ #current = $state();
10
+ constructor(key, initialValue, type = "session") {
11
+ this.key = key;
12
+ this.initialValue = initialValue;
13
+ this.type = type;
14
+ this.current = this.#stored().get() ?? this.initialValue;
15
+ }
16
+ #stored() {
17
+ const strg = this.type === "local" ? localStorageValue : sessionStorageValue;
18
+ return strg(this.key, this.initialValue);
19
+ }
20
+ #save() {
21
+ this.#stored().set(this.#current);
22
+ }
23
+ get current() {
24
+ return this.#current;
25
+ }
26
+ set current(val) {
27
+ this.#current = val;
28
+ this.#save();
29
+ }
30
+ reset() {
31
+ this.current = this.initialValue;
32
+ }
33
+ remove() {
34
+ this.#stored().remove();
35
+ }
36
+ }
37
+ /**
38
+ *
39
+ */
40
+ export function localStorageState(key, initialValue) {
41
+ return new PersistentState(key, initialValue, "local");
42
+ }
43
+ /**
44
+ *
45
+ */
46
+ export function sessionStorageState(key, initialValue) {
47
+ return new PersistentState(key, initialValue, "session");
48
+ }
@@ -0,0 +1,2 @@
1
+ import { MediaQuery } from "svelte/reactivity";
2
+ export declare function prefersReducedMotion(): MediaQuery;
@@ -0,0 +1,4 @@
1
+ import { MediaQuery } from "svelte/reactivity";
2
+ export function prefersReducedMotion() {
3
+ return new MediaQuery("(prefers-reduced-motion: reduce)");
4
+ }
@@ -0,0 +1 @@
1
+ export declare function qsa(selector: string, context?: HTMLElement | Document): Element[];
@@ -0,0 +1,3 @@
1
+ export function qsa(selector, context) {
2
+ return Array.from((context ?? document)?.querySelectorAll(selector) || []);
3
+ }
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Delays execution for `timeout` milliseconds.
3
+ *
4
+ * @example
5
+ * ```ts
6
+ * await sleep(100);
7
+ * ```
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * // Usage with timer reference
12
+ * let ref = { id: -1 };
13
+ * some(() => sleep(100, ref))
14
+ * // ...
15
+ * clearTimeout(ref.id)
16
+ * ```
17
+ */
18
+ export declare function sleep(timeout: number,
19
+ /**
20
+ * Deno.test is quite strict and reports every non-cleared timeout... so we have to
21
+ * be able to pass in some object ref if needed (eg when sleep is not resolved via Promise.race)
22
+ * to be able to do the clearing eventually.
23
+ *
24
+ * If calling directly `await sleep(x)` in a top level flow, this dance is not needed.
25
+ */
26
+ __timeout_ref__?: {
27
+ id: any;
28
+ }): Promise<void>;
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Delays execution for `timeout` milliseconds.
3
+ *
4
+ * @example
5
+ * ```ts
6
+ * await sleep(100);
7
+ * ```
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * // Usage with timer reference
12
+ * let ref = { id: -1 };
13
+ * some(() => sleep(100, ref))
14
+ * // ...
15
+ * clearTimeout(ref.id)
16
+ * ```
17
+ */
18
+ export function sleep(timeout,
19
+ /**
20
+ * Deno.test is quite strict and reports every non-cleared timeout... so we have to
21
+ * be able to pass in some object ref if needed (eg when sleep is not resolved via Promise.race)
22
+ * to be able to do the clearing eventually.
23
+ *
24
+ * If calling directly `await sleep(x)` in a top level flow, this dance is not needed.
25
+ */
26
+ __timeout_ref__ = { id: -1 }) {
27
+ return new Promise((resolve) => {
28
+ __timeout_ref__.id = setTimeout(() => {
29
+ clearTimeout(__timeout_ref__.id);
30
+ resolve(undefined);
31
+ }, timeout);
32
+ });
33
+ }
@@ -0,0 +1,35 @@
1
+ export declare class MemoryStorage {
2
+ #private;
3
+ setItem(key: string, value: any): void;
4
+ getItem(key: string): any;
5
+ removeItem(key: string): void;
6
+ clear(): void;
7
+ get length(): number;
8
+ entries(): [any, any][];
9
+ }
10
+ export declare class StorageAbstraction {
11
+ #private;
12
+ constructor(storageType?: "local" | "session" | "memory", serializer?: (v: any) => string, deserializer?: (v: string) => any);
13
+ set(key: string, value: any): this;
14
+ get(key: string): any;
15
+ remove(key: string): boolean;
16
+ clear(): boolean;
17
+ has(key: string): boolean;
18
+ entries(): any;
19
+ get length(): number;
20
+ }
21
+ export declare function localStorageValue(key: string, initial: any): {
22
+ get(): any;
23
+ set(v: any): StorageAbstraction;
24
+ remove(): void;
25
+ };
26
+ export declare function sessionStorageValue(key: string, initial: any): {
27
+ get(): any;
28
+ set(v: any): StorageAbstraction;
29
+ remove(): void;
30
+ };
31
+ export declare function memoryStorageValue(key: string, initial: any): {
32
+ get(): any;
33
+ set(v: any): StorageAbstraction;
34
+ remove(): void;
35
+ };
@@ -0,0 +1,136 @@
1
+ import { isBrowser } from "./is-browser.js";
2
+ export class MemoryStorage {
3
+ #storage = new Map();
4
+ setItem(key, value) {
5
+ this.#storage.set(key, value);
6
+ }
7
+ getItem(key) {
8
+ return this.#storage.get(key) ?? null;
9
+ }
10
+ removeItem(key) {
11
+ this.#storage.delete(key);
12
+ }
13
+ clear() {
14
+ this.#storage.clear();
15
+ }
16
+ get length() {
17
+ return this.#storage.size;
18
+ }
19
+ entries() {
20
+ return [...this.#storage.entries()];
21
+ }
22
+ }
23
+ export class StorageAbstraction {
24
+ #type;
25
+ #storage;
26
+ #serializer = JSON.stringify;
27
+ #deserializer = JSON.parse;
28
+ constructor(storageType = "local", serializer, deserializer) {
29
+ this.#type = `${storageType}`.toLowerCase();
30
+ if (!isBrowser() || this.#type === "memory") {
31
+ this.#storage = new MemoryStorage();
32
+ }
33
+ else if (this.#type === "local") {
34
+ this.#storage = localStorage;
35
+ }
36
+ else {
37
+ this.#storage = sessionStorage;
38
+ }
39
+ if (serializer)
40
+ this.#serializer = serializer;
41
+ if (deserializer)
42
+ this.#deserializer = deserializer;
43
+ }
44
+ #serialize(value) {
45
+ return this.#serializer(value);
46
+ }
47
+ #deserialize(value) {
48
+ try {
49
+ return this.#deserializer(value);
50
+ }
51
+ catch (e) {
52
+ console.error(`Unable to deserialize value "${value}". Details: ${e}`);
53
+ return value;
54
+ }
55
+ }
56
+ set(key, value) {
57
+ try {
58
+ this.#storage.setItem(key, this.#serialize(value));
59
+ }
60
+ catch (e) {
61
+ console.error(`Unable to set "${key}". Details: ${e}`);
62
+ }
63
+ return this;
64
+ }
65
+ get(key) {
66
+ try {
67
+ const value = this.#storage.getItem(key);
68
+ return this.#deserialize(value);
69
+ }
70
+ catch (e) {
71
+ console.error(`Unable to get "${key}". Details: ${e}`);
72
+ }
73
+ }
74
+ remove(key) {
75
+ try {
76
+ this.#storage.removeItem(key);
77
+ return true;
78
+ }
79
+ catch (e) {
80
+ console.error(`Unable to remove "${key}". Details: ${e}`);
81
+ return false;
82
+ }
83
+ }
84
+ clear() {
85
+ try {
86
+ this.#storage.clear();
87
+ return true;
88
+ }
89
+ catch (e) {
90
+ console.error(`Unable to clear. Details: ${e}`);
91
+ return false;
92
+ }
93
+ }
94
+ has(key) {
95
+ return this.#storage.getItem(key) !== null;
96
+ }
97
+ entries() {
98
+ if (this.#type === "memory")
99
+ return this.#storage.entries();
100
+ const out = [];
101
+ for (let i = 0; i < this.#storage.length; i++) {
102
+ const key = this.#storage.key(i);
103
+ const value = this.#storage.getItem(key);
104
+ out.push([key, value]);
105
+ }
106
+ return out;
107
+ }
108
+ get length() {
109
+ return this.#storage.length;
110
+ }
111
+ }
112
+ function storage_value(type, key, initial) {
113
+ const s = new StorageAbstraction(type);
114
+ if (!s.has(key))
115
+ s.set(key, initial);
116
+ return {
117
+ get() {
118
+ return s.get(key);
119
+ },
120
+ set(v) {
121
+ return s.set(key, v);
122
+ },
123
+ remove() {
124
+ s.remove(key);
125
+ },
126
+ };
127
+ }
128
+ export function localStorageValue(key, initial) {
129
+ return storage_value("local", key, initial);
130
+ }
131
+ export function sessionStorageValue(key, initial) {
132
+ return storage_value("session", key, initial);
133
+ }
134
+ export function memoryStorageValue(key, initial) {
135
+ return storage_value("memory", key, initial);
136
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * a.k.a. "djb2"
3
+ * It ensures a consistent, positive numerical representation.
4
+ * It preserves all 32 bits of information, maintaining the full collision space.
5
+ * The resulting values are always within the range 0 to 4,294,967,295 (2^32 - 1)
6
+ */
7
+ export declare function strHash(str: string): string;
@@ -0,0 +1,35 @@
1
+ /**
2
+ * a.k.a. "djb2"
3
+ * It ensures a consistent, positive numerical representation.
4
+ * It preserves all 32 bits of information, maintaining the full collision space.
5
+ * The resulting values are always within the range 0 to 4,294,967,295 (2^32 - 1)
6
+ */
7
+ export function strHash(str) {
8
+ /**
9
+ * the expression ((hash << 5) - hash) is a common optimization that equals hash * 31
10
+ * (since (hash * 32) - hash = hash * 31).
11
+ *
12
+ * This multiplication by 31 is used because:
13
+ *
14
+ * 31 is a prime number, which helps with distributing hash values
15
+ * The computation (hash << 5) - hash is typically faster than direct multiplication
16
+ * It creates a good avalanche effect where small changes in input create significant changes in the hash
17
+ *
18
+ * So that line hash = ((hash << 5) - hash) + char; is effectively doing:
19
+ * hash = (hash * 31) + char;
20
+ *
21
+ * This is a core part of the djb2 hash algorithm, creating a strong dependency between
22
+ * each character's contribution to the final hash value.
23
+ */
24
+ let hash = 0;
25
+ for (let i = 0; i < str.length; i++) {
26
+ hash = (hash << 5) - hash + str.charCodeAt(i);
27
+ hash = hash & hash; // Convert to 32bit integer
28
+ }
29
+ // ">>> 0" zero-fill right shift
30
+ // 1. it forces the value to be treated as an unsigned 32-bit integer
31
+ // 2. converts any negative value to its corresponding positive value in the 32-bit unsigned range
32
+ // (For a negative number like -10, >>> 0 converts it to 4,294,967,286 (which is 2^32 - 10).)
33
+ // so, this step is just a cosmetic and reversible one...
34
+ return (hash >>> 0).toString(16);
35
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ /**
3
+ * A simple throttle function that limits how often a function can be called.
4
+ * The function will be called at most once in the specified time period.
5
+ *
6
+ * Example:
7
+ *
8
+ * ```js
9
+ * const scroll = (e: Event) => { console.log('Handling scroll event'); };
10
+ * const throttledScroll = throttle(scroll, 300);
11
+ * window.addEventListener('scroll', throttledScroll);
12
+ * ```
13
+ */
14
+ function throttle(func, limit) {
15
+ let lastCall = 0;
16
+ let timeout = null;
17
+ let lastArgs = null;
18
+ return function (...args) {
19
+ // @ts-ignore
20
+ const context = this;
21
+ const now = Date.now();
22
+ // If enough time has passed since the last call
23
+ if (now - lastCall >= limit) {
24
+ if (timeout !== null) {
25
+ clearTimeout(timeout);
26
+ timeout = null;
27
+ }
28
+ lastCall = now;
29
+ func.apply(context, args);
30
+ }
31
+ else {
32
+ // Save the latest arguments
33
+ lastArgs = args;
34
+ // If there's no pending execution scheduled
35
+ if (timeout === null) {
36
+ timeout = setTimeout(() => {
37
+ lastCall = Date.now();
38
+ timeout = null;
39
+ if (lastArgs !== null) {
40
+ func.apply(context, lastArgs);
41
+ lastArgs = null;
42
+ }
43
+ }, limit - (now - lastCall));
44
+ }
45
+ }
46
+ };
47
+ }
@@ -0,0 +1 @@
1
+ export declare function toInteger(value: any, fallback?: number): number;
@@ -0,0 +1,11 @@
1
+ export function toInteger(value, fallback = 1) {
2
+ if (typeof value === "number" && !isNaN(value)) {
3
+ return Math.floor(value);
4
+ }
5
+ if (typeof value === "string") {
6
+ const parsed = parseFloat(value);
7
+ if (!isNaN(parsed))
8
+ return Math.floor(parsed);
9
+ }
10
+ return fallback;
11
+ }
@@ -0,0 +1,5 @@
1
+ export type MaybeLocalized = string | Record<string, string>;
2
+ /**
3
+ * Conventional translate lookup on given value
4
+ */
5
+ export declare function tr(val: MaybeLocalized | undefined | null, locale?: string, fallback?: string): string;
@@ -0,0 +1,13 @@
1
+ import { maybeJsonParse } from "./maybe-json-parse.js";
2
+ /**
3
+ * Conventional translate lookup on given value
4
+ */
5
+ export function tr(val, locale, fallback) {
6
+ if (!locale)
7
+ return `${val ?? fallback ?? ""}`;
8
+ val = maybeJsonParse(val);
9
+ // if string - no translation support
10
+ if (typeof val === "string")
11
+ return val;
12
+ return `${val?.[locale] ?? fallback ?? val ?? ""}`;
13
+ }
@@ -0,0 +1,10 @@
1
+ import { type ClassNameValue } from "tailwind-merge";
2
+ /**
3
+ * Normalizes and dedupes whitespaces
4
+ */
5
+ export declare function clsClean(s: ClassNameValue): string;
6
+ /**
7
+ * twMerge does not seem to handle "\r", "\n" and/or "\t" within the input strings correctly,
8
+ * so we need to do the cleanup ourselves
9
+ */
10
+ export declare function twMerge(...args: ClassNameValue[]): string;
@@ -0,0 +1,16 @@
1
+ import { twMerge as _twMerge } from "tailwind-merge";
2
+ /**
3
+ * Normalizes and dedupes whitespaces
4
+ */
5
+ export function clsClean(s) {
6
+ if (Array.isArray(s))
7
+ s = s.filter(Boolean).join(" ");
8
+ return `${s || ""}`.replace(/\s+/g, " ").trim();
9
+ }
10
+ /**
11
+ * twMerge does not seem to handle "\r", "\n" and/or "\t" within the input strings correctly,
12
+ * so we need to do the cleanup ourselves
13
+ */
14
+ export function twMerge(...args) {
15
+ return _twMerge(...args.map(clsClean));
16
+ }
@@ -0,0 +1 @@
1
+ export declare function ucfirst(s: string): string;
@@ -0,0 +1,6 @@
1
+ export function ucfirst(s) {
2
+ s = `${s}`;
3
+ if (!s.length)
4
+ return s;
5
+ return s[0].toUpperCase() + (s.slice(1) || "");
6
+ }
package/package.json CHANGED
@@ -1,74 +1,67 @@
1
1
  {
2
- "name": "@marianmeres/stuic",
3
- "version": "1.125.0",
4
- "scripts": {
5
- "dev": "vite dev",
6
- "build": "vite build && npm run package && node ./scripts/date.js",
7
- "build:watch": "fswatch -o src | xargs -n1 -I{} npm run build",
8
- "preview": "vite preview",
9
- "package": "svelte-kit sync && svelte-package && publint",
10
- "prepublishOnly": "npm run package",
11
- "check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
12
- "check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
13
- "lint": "prettier --check .",
14
- "format": "prettier --write .",
15
- "prettier": "npm run format",
16
- "release:patch": "release -v patch",
17
- "release": "release -v minor",
18
- "test": "vitest"
19
- },
20
- "exports": {
21
- ".": {
22
- "types": "./dist/index.d.ts",
23
- "svelte": "./dist/index.js"
24
- }
25
- },
26
- "files": [
27
- "dist",
28
- "!dist/**/*.test.*",
29
- "!dist/**/*.spec.*"
30
- ],
31
- "peerDependencies": {
32
- "svelte": "^4.0.0 || ^5.0.0-next.1"
33
- },
34
- "devDependencies": {
35
- "@marianmeres/parse-boolean": "^1.1.7",
36
- "@marianmeres/random-human-readable": "^1.6.1",
37
- "@marianmeres/release": "^1.1.2",
38
- "@sveltejs/adapter-auto": "^2.0.0",
39
- "@sveltejs/kit": "^1.27.4",
40
- "@sveltejs/package": "^2.0.0",
41
- "@tailwindcss/forms": "^0.5.7",
42
- "@types/node": "^20.11.0",
43
- "autoprefixer": "^10.4.16",
44
- "clsx": "^2.0.0",
45
- "nodemon": "^3.0.2",
46
- "postcss": "^8.4.32",
47
- "prettier": "^3.0.0",
48
- "prettier-plugin-svelte": "^3.0.0",
49
- "publint": "^0.1.9",
50
- "sass": "^1.69.5",
51
- "svelte": "^4.2.7",
52
- "svelte-check": "^3.6.0",
53
- "tailwindcss": "^3.3.6",
54
- "ts-node": "^10.9.2",
55
- "tslib": "^2.4.1",
56
- "typescript": "^5.0.0",
57
- "vite": "^4.4.2",
58
- "vitest": "^1.1.3"
59
- },
60
- "svelte": "./dist/index.js",
61
- "types": "./dist/index.d.ts",
62
- "type": "module",
63
- "dependencies": {
64
- "@marianmeres/clog": "^1.0.1",
65
- "@marianmeres/icons-fns": "^4.0.4",
66
- "@marianmeres/store": "^1.5.0",
67
- "@marianmeres/switch-store": "^1.3.1",
68
- "@marianmeres/ticker": "^1.5.0",
69
- "dset": "^3.1.3",
70
- "esm-env": "^1.0.0",
71
- "klona": "^2.0.6",
72
- "tailwind-merge": "^2.1.0"
73
- }
74
- }
2
+ "name": "@marianmeres/stuic",
3
+ "version": "2.0.0-next.2",
4
+ "files": [
5
+ "dist",
6
+ "!dist/**/*.test.*",
7
+ "!dist/**/*.spec.*"
8
+ ],
9
+ "sideEffects": [
10
+ "**/*.css"
11
+ ],
12
+ "svelte": "./dist/index.js",
13
+ "types": "./dist/index.d.ts",
14
+ "type": "module",
15
+ "exports": {
16
+ ".": {
17
+ "types": "./dist/index.d.ts",
18
+ "svelte": "./dist/index.js"
19
+ }
20
+ },
21
+ "peerDependencies": {
22
+ "svelte": "^5.0.0"
23
+ },
24
+ "devDependencies": {
25
+ "@marianmeres/icons-fns": "^4.3.1",
26
+ "@marianmeres/random-human-readable": "^1.6.1",
27
+ "@sveltejs/adapter-auto": "^4.0.0",
28
+ "@sveltejs/kit": "^2.21.1",
29
+ "@sveltejs/package": "^2.3.11",
30
+ "@sveltejs/vite-plugin-svelte": "^5.0.3",
31
+ "@tailwindcss/cli": "^4.1.8",
32
+ "@tailwindcss/forms": "^0.5.10",
33
+ "@tailwindcss/typography": "^0.5.16",
34
+ "@tailwindcss/vite": "^4.1.8",
35
+ "dotenv": "^16.5.0",
36
+ "prettier": "^3.5.3",
37
+ "prettier-plugin-svelte": "^3.4.0",
38
+ "publint": "^0.3.12",
39
+ "svelte": "^5.33.10",
40
+ "svelte-check": "^4.2.1",
41
+ "tailwindcss": "^4.1.8",
42
+ "typescript": "^5.8.3",
43
+ "vite": "^6.3.5",
44
+ "vitest": "^3.1.4"
45
+ },
46
+ "dependencies": {
47
+ "@marianmeres/clog": "^2.2.3",
48
+ "@marianmeres/item-collection": "^1.2.14",
49
+ "@marianmeres/parse-boolean": "^1.1.7",
50
+ "@marianmeres/ticker": "^1.15.0",
51
+ "esm-env": "^1.2.2",
52
+ "runed": "^0.23.4",
53
+ "tailwind-merge": "^3.3.0"
54
+ },
55
+ "scripts": {
56
+ "dev": "vite dev",
57
+ "build": "vite build && npm run prepack",
58
+ "preview": "vite preview",
59
+ "package": "npm run prepack",
60
+ "package:watch": "svelte-kit sync && svelte-package --watch && publint",
61
+ "check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
62
+ "check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
63
+ "format": "prettier --write .",
64
+ "lint": "prettier --check .",
65
+ "test": "vitest --dir src/"
66
+ }
67
+ }
@@ -1,8 +0,0 @@
1
- export declare function increaseHeightToScrollHeight(el: HTMLElement, max?: number, min?: number): void;
2
- export declare function autogrow(el: HTMLTextAreaElement, options?: Partial<{
3
- max: number;
4
- min: number;
5
- allowed: boolean;
6
- }> | null): {
7
- destroy: () => void;
8
- } | undefined;
@@ -1,22 +0,0 @@
1
- // actual worker
2
- export function increaseHeightToScrollHeight(el, max = 0, min = 0) {
3
- //
4
- let h = max ? Math.min(max, el.scrollHeight) : el.scrollHeight;
5
- h = Math.max(min, h);
6
- // only increase size
7
- if (el.getBoundingClientRect().height < h) {
8
- el.style.height = `${h}px`;
9
- }
10
- }
11
- // action wrap
12
- export function autogrow(el, options = null) {
13
- const { max, min, allowed } = { max: 250, min: 0, allowed: true, ...(options || {}) };
14
- if (!allowed)
15
- return;
16
- const _doGrow = () => increaseHeightToScrollHeight(el, max, min);
17
- _doGrow(); // resize asap (on mount) as well...
18
- el.addEventListener('input', _doGrow);
19
- return {
20
- destroy: () => el.removeEventListener('input', _doGrow),
21
- };
22
- }