@marianmeres/stuic 1.126.0 → 2.0.0-next.3

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 (250) 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 +56 -41
  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/drag-drop.d.ts +0 -28
  207. package/dist/actions/drag-drop.js +0 -152
  208. package/dist/actions/on-outside.d.ts +0 -9
  209. package/dist/actions/on-outside.js +0 -27
  210. package/dist/actions/pre-submit-validity-check.d.ts +0 -3
  211. package/dist/actions/pre-submit-validity-check.js +0 -21
  212. package/dist/actions/tooltip/_make-visible.d.ts +0 -3
  213. package/dist/actions/tooltip/_make-visible.js +0 -25
  214. package/dist/actions/tooltip/_maybe-pick-safe-placement.d.ts +0 -3
  215. package/dist/actions/tooltip/_maybe-pick-safe-placement.js +0 -86
  216. package/dist/actions/tooltip/_set-position.d.ts +0 -2
  217. package/dist/actions/tooltip/_set-position.js +0 -125
  218. package/dist/actions/tooltip/tooltip.d.ts +0 -42
  219. package/dist/actions/tooltip/tooltip.js +0 -299
  220. package/dist/actions/trim.d.ts +0 -4
  221. package/dist/actions/trim.js +0 -18
  222. package/dist/actions/validate.js +0 -80
  223. package/dist/components/AlertConfirmPrompt/alert-confirm-prompt.d.ts +0 -58
  224. package/dist/components/AlertConfirmPrompt/alert-confirm-prompt.js +0 -141
  225. package/dist/components/ColorScheme/LocalColorScheme.svelte.d.ts +0 -25
  226. package/dist/components/ColorScheme/SystemAwareColorScheme.svelte.d.ts +0 -25
  227. package/dist/components/Input/Field.svelte +0 -315
  228. package/dist/components/Input/Field.svelte.d.ts +0 -102
  229. package/dist/components/Input/PinInput.svelte +0 -151
  230. package/dist/components/Input/PinInput.svelte.d.ts +0 -51
  231. package/dist/components/Input/XFieldRadioInternal.svelte +0 -143
  232. package/dist/components/Input/XFieldRadioInternal.svelte.d.ts +0 -45
  233. package/dist/components/Notifications/notifications.d.ts +0 -78
  234. package/dist/components/Notifications/notifications.js +0 -215
  235. package/dist/components/Popover/Popover.svelte +0 -24
  236. package/dist/components/Popover/Popover.svelte.d.ts +0 -22
  237. package/dist/components/Spinner/Spinner.v5.svelte +0 -114
  238. package/dist/components/Spinner/Spinner.v5.svelte.d.ts +0 -16
  239. package/dist/utils/calculate-alignment.d.ts +0 -68
  240. package/dist/utils/calculate-alignment.js +0 -183
  241. package/dist/utils/device-pointer.d.ts +0 -5
  242. package/dist/utils/device-pointer.js +0 -10
  243. package/dist/utils/prefers-reduced-motion.d.ts +0 -6
  244. package/dist/utils/prefers-reduced-motion.js +0 -26
  245. package/dist/utils/tw-merge2.d.ts +0 -3
  246. package/dist/utils/tw-merge2.js +0 -9
  247. package/dist/utils/tw-types.d.ts +0 -1
  248. package/dist/utils/window-size.d.ts +0 -22
  249. package/dist/utils/window-size.js +0 -35
  250. /package/dist/{utils/tw-types.js → components/Input/types.js} +0 -0
@@ -0,0 +1,89 @@
1
+ import type { Component } from "svelte";
2
+ import { type THC } from "../Thc/Thc.svelte";
3
+ export interface ComponentWrap {
4
+ component: Component;
5
+ props?: any;
6
+ }
7
+ export type NotificationsSortOrder = "asc" | "desc";
8
+ export type NotificationType = "info" | "success" | "warn" | "error" | string;
9
+ export interface NotificationInput extends Record<string, any> {
10
+ /** Unique id of the notification. If not provided, will be calculated from content.
11
+ Multiple notifications with the same id will be ignored (but the `count` will be increased). */
12
+ id: any;
13
+ /** Optional UI rendering well known hint (has no effect on the functionality, can be
14
+ any string), defaults to "info". */
15
+ type: NotificationType;
16
+ /** The actual notification message (either plain text, html or component)
17
+ notifications without any content will be ignored. */
18
+ content: THC;
19
+ onClick: (self: Notification, all: Notification[], data: any) => void;
20
+ /** Notification specific time-to-live in milliseconds (after which notif will be auto discarded)
21
+ use 0 to disable auto disposal */
22
+ ttl: number;
23
+ /** Number of notifications in the queue with the same `id`. If you do not provide your
24
+ own id, it will be calculated from content. */
25
+ count: number;
26
+ /** Optional, in shape `{ component, props }` */
27
+ component?: Component | ComponentWrap;
28
+ iconFn: (() => string) | boolean;
29
+ forceAsHtml?: boolean;
30
+ }
31
+ export interface Notification extends NotificationInput {
32
+ /** For sorting the queue, will default to now. */
33
+ created: Date;
34
+ /** State progress or living time in percents. A hint for UI to maybe display some progress bar...
35
+ * Will be update by the dispose checker... (so the update frequency is equal to `disposeInterval`) */
36
+ _ttlProgress: number;
37
+ }
38
+ export type NotificationCreateParam = string | Partial<NotificationInput>;
39
+ export interface NotificationsStackOptions {
40
+ /** Maximum number of notifications kept in the queue, if exceeded, older ones (by `created`)
41
+ will be discarded. Use 0 (zero) to disable capacity check. */
42
+ maxCapacity: number;
43
+ /** Default value for Notification.type, defaults to "info". */
44
+ defaultType: string;
45
+ /** Global time-to-live in milliseconds (after which notifs will be auto discarded).
46
+ Use 0 to disable default auto disposal. */
47
+ defaultTtl: number;
48
+ /** Will prolong the defaultTtl with some extra (in milliseconds) based on the content
49
+ * length. Use 0 to disable. */
50
+ extraTtlPerChar: number;
51
+ /** How to sort the queue, "asc" (default) or "desc".
52
+ Sorting is always done by the `created` prop. */
53
+ sortOrder?: NotificationsSortOrder;
54
+ /** How often to check for disposed ones? (milliseconds). Note that this interval
55
+ * also effects how often the progress is updated. The higher the more precise...
56
+ * (which may have visual implications if used with progress bar). Reasonable value
57
+ * would be between 100ms and 1_000ms. */
58
+ disposeInterval?: number;
59
+ }
60
+ /**
61
+ *
62
+ */
63
+ export declare class NotificationsStack {
64
+ #private;
65
+ readonly options: NotificationsStackOptions;
66
+ constructor(initial?: NotificationCreateParam[], opts?: Partial<NotificationsStackOptions>);
67
+ /** Will remove the notification from stack */
68
+ removeById: (id: string) => this;
69
+ /** Will cleanup the stack. */
70
+ reset: () => this;
71
+ /**
72
+ * Will get the first in stack (for testing mostly)
73
+ */
74
+ get head(): Notification | undefined;
75
+ /** Will return clone (intentionally) of internal data. */
76
+ get stack(): Notification[];
77
+ /** Will get the current stack size */
78
+ get length(): number;
79
+ /** Will do internal cleanups. */
80
+ destroy: () => void;
81
+ /** Main api. */
82
+ info: (content: THC, n?: Partial<NotificationInput>) => this | undefined;
83
+ /** Main api. */
84
+ success: (content: THC, n?: Partial<NotificationInput>) => this | undefined;
85
+ /** Main api. */
86
+ warn: (content: THC, n?: Partial<NotificationInput>) => this | undefined;
87
+ /** Main api. */
88
+ error: (content: THC, n?: Partial<NotificationInput>) => this | undefined;
89
+ }
@@ -0,0 +1,161 @@
1
+ import { createTicker } from "@marianmeres/ticker";
2
+ import { strHash } from "../../utils/str-hash.js";
3
+ import { getTHCStringContent } from "../Thc/Thc.svelte";
4
+ const DEFAULT_OPTIONS = {
5
+ maxCapacity: 5,
6
+ defaultTtl: 3_000,
7
+ extraTtlPerChar: 20,
8
+ defaultType: "info",
9
+ sortOrder: "asc",
10
+ disposeInterval: 500,
11
+ };
12
+ const isFn = (v) => typeof v === "function";
13
+ const _id = (type, content) => {
14
+ const str = content?.component
15
+ ? "component"
16
+ : content?.html || content?.text || content;
17
+ return ["id", type, strHash(str)].join("-");
18
+ };
19
+ /**
20
+ *
21
+ */
22
+ export class NotificationsStack {
23
+ #stack = $state([]);
24
+ options = $state();
25
+ #ticker;
26
+ #unsubs = [];
27
+ constructor(initial = [], opts = {}) {
28
+ this.options = { ...DEFAULT_OPTIONS, ...(opts || {}) };
29
+ initial.forEach((n) => this.#add(n));
30
+ // auto dispose feature
31
+ this.#ticker = createTicker(this.options.disposeInterval, true);
32
+ const _tickerUnsub = this.#ticker.subscribe(this.#onTick);
33
+ this.#unsubs.push(() => {
34
+ this.#ticker.stop();
35
+ _tickerUnsub();
36
+ });
37
+ }
38
+ #onTick = (ts) => {
39
+ if (!ts)
40
+ return;
41
+ const updated = this.#stack.reduce((memo, n) => {
42
+ if (n.ttl) {
43
+ const start = n.created.valueOf();
44
+ const end = start + n.ttl;
45
+ const now = Date.now();
46
+ const expired = end < now;
47
+ if (!expired) {
48
+ // we can't know exactly the offset here, but using full is good enough...
49
+ const offset = this.options.disposeInterval || 0;
50
+ n._ttlProgress = (now - start + offset) / (end - start);
51
+ memo.push(n);
52
+ }
53
+ }
54
+ else {
55
+ memo.push(n);
56
+ }
57
+ return memo;
58
+ }, []);
59
+ // since we're updating progress, we must reassign every time, not just if disposed
60
+ this.#stack = updated;
61
+ };
62
+ #maybeTtlExtra(content) {
63
+ return getTHCStringContent(content).length * this.options.extraTtlPerChar;
64
+ }
65
+ /** Will normalize item to internal shape. */
66
+ #normalize = (n) => {
67
+ let o = typeof n === "string" ? { id: 0, content: n } : n;
68
+ if (!o.content)
69
+ return null;
70
+ o.type ||= this.options.defaultType;
71
+ o.id ||= _id(o.type, o.content);
72
+ o.created = new Date(o.created || Date.now());
73
+ o.count ??= 1;
74
+ o.ttl ??= this.options.defaultTtl + this.#maybeTtlExtra(o.content);
75
+ o._ttlProgress = 0;
76
+ return o;
77
+ };
78
+ #findIndexById = (id) => {
79
+ return this.#stack.findIndex((n) => n.id === id);
80
+ };
81
+ #removeByIndex = (idx) => {
82
+ if (idx > -1)
83
+ this.#stack.splice(idx, 1);
84
+ };
85
+ /** Will add to stack */
86
+ #add = (n) => {
87
+ const notif = this.#normalize(n);
88
+ // return early on invalid
89
+ if (!notif)
90
+ return;
91
+ const { maxCapacity, sortOrder } = this.options;
92
+ const idx = this.#findIndexById(notif.id);
93
+ let stack = this.#stack;
94
+ if (idx > -1) {
95
+ stack[idx].count++;
96
+ stack[idx].created = new Date(Math.max(stack[idx].created.valueOf(), notif.created.valueOf()));
97
+ }
98
+ else {
99
+ stack.push(notif);
100
+ stack.sort((a, b) => {
101
+ let _a = a.created.valueOf();
102
+ let _b = b.created.valueOf();
103
+ return sortOrder === "desc" ? _b - _a : _a - _b;
104
+ });
105
+ }
106
+ // keep only `maxCapacity`
107
+ if (maxCapacity && stack.length > maxCapacity) {
108
+ stack =
109
+ sortOrder === "desc"
110
+ ? stack.slice(0, maxCapacity)
111
+ : stack.slice(-1 * maxCapacity);
112
+ }
113
+ this.#stack = stack;
114
+ return this;
115
+ };
116
+ /** Will remove the notification from stack */
117
+ removeById = (id) => {
118
+ this.#removeByIndex(this.#findIndexById(id));
119
+ return this;
120
+ };
121
+ /** Will cleanup the stack. */
122
+ reset = () => {
123
+ this.#stack = [];
124
+ return this;
125
+ };
126
+ /**
127
+ * Will get the first in stack (for testing mostly)
128
+ */
129
+ get head() {
130
+ return this.#stack.at(0);
131
+ }
132
+ /** Will return clone (intentionally) of internal data. */
133
+ get stack() {
134
+ return [...this.#stack];
135
+ }
136
+ /** Will get the current stack size */
137
+ get length() {
138
+ return this.#stack.length;
139
+ }
140
+ /** Will do internal cleanups. */
141
+ destroy = () => {
142
+ this.reset();
143
+ this.#unsubs.forEach((fn) => fn());
144
+ };
145
+ /** Main api. */
146
+ info = (content, n) => {
147
+ return this.#add({ ...(n || {}), type: "info", content });
148
+ };
149
+ /** Main api. */
150
+ success = (content, n) => {
151
+ return this.#add({ ...(n || {}), type: "success", content });
152
+ };
153
+ /** Main api. */
154
+ warn = (content, n) => {
155
+ return this.#add({ ...(n || {}), type: "warn", content });
156
+ };
157
+ /** Main api. */
158
+ error = (content, n) => {
159
+ return this.#add({ ...(n || {}), type: "error", content });
160
+ };
161
+ }
@@ -0,0 +1,26 @@
1
+ <script lang="ts">
2
+ import Bar from "./_internal/Bar.svelte";
3
+ import Circle from "./_internal/Circle.svelte";
4
+
5
+ interface Props {
6
+ type?: "bar" | "circle";
7
+ progress?: number;
8
+ class?: string;
9
+ classBar?: string;
10
+ styleBar?: string;
11
+ }
12
+
13
+ let {
14
+ type = "bar",
15
+ progress = 0,
16
+ class: classProp,
17
+ classBar,
18
+ styleBar,
19
+ }: Props = $props();
20
+ </script>
21
+
22
+ {#if type === "bar"}
23
+ <Bar {progress} class={classProp} {classBar} {styleBar} />
24
+ {:else if type === "circle"}
25
+ <Circle {progress} class={classProp} />
26
+ {/if}
@@ -0,0 +1,10 @@
1
+ interface Props {
2
+ type?: "bar" | "circle";
3
+ progress?: number;
4
+ class?: string;
5
+ classBar?: string;
6
+ styleBar?: string;
7
+ }
8
+ declare const Progress: import("svelte").Component<Props, {}, "">;
9
+ type Progress = ReturnType<typeof Progress>;
10
+ export default Progress;
@@ -0,0 +1,31 @@
1
+ <script lang="ts">
2
+ import { twMerge } from "../../../utils/tw-merge.js";
3
+
4
+ import "../index.css";
5
+
6
+ interface Props {
7
+ progress: number;
8
+ class?: string;
9
+ classBar?: string;
10
+ styleBar?: string;
11
+ }
12
+
13
+ let { progress = 0, class: classProp, classBar, styleBar = "" }: Props = $props();
14
+ </script>
15
+
16
+ <div
17
+ class={twMerge(
18
+ "stuic-progress-bar",
19
+ "w-full h-2 bg-progress-bg flex justify-start pointer-events-none",
20
+ classProp
21
+ )}
22
+ >
23
+ <div
24
+ class={twMerge(
25
+ "bar",
26
+ "w-full h-full bg-progress-accent transition-[width] ease-linear duration-1000",
27
+ classBar
28
+ )}
29
+ style="width:{Math.min(100, Math.max(0, progress))}%; {styleBar}"
30
+ ></div>
31
+ </div>
@@ -0,0 +1,10 @@
1
+ import "../index.css";
2
+ interface Props {
3
+ progress: number;
4
+ class?: string;
5
+ classBar?: string;
6
+ styleBar?: string;
7
+ }
8
+ declare const Bar: import("svelte").Component<Props, {}, "">;
9
+ type Bar = ReturnType<typeof Bar>;
10
+ export default Bar;
@@ -0,0 +1,10 @@
1
+ <script lang="ts">
2
+ interface Props {
3
+ progress: number;
4
+ class?: string;
5
+ }
6
+
7
+ let { progress = 0, class: classProp }: Props = $props();
8
+ </script>
9
+
10
+ todo
@@ -0,0 +1,7 @@
1
+ interface Props {
2
+ progress: number;
3
+ class?: string;
4
+ }
5
+ declare const Circle: import("svelte").Component<Props, {}, "">;
6
+ type Circle = ReturnType<typeof Circle>;
7
+ export default Circle;
@@ -0,0 +1,7 @@
1
+ @import "../../_shared.css";
2
+
3
+ /* prettier-ignore */
4
+ @theme inline {
5
+ --color-progress-bg: var(--color-progress-bg, var(--color-neutral-200));
6
+ --color-progress-accent: var(--color-progress-accent, var(--color-neutral-600));
7
+ }
@@ -0,0 +1 @@
1
+ export { default as Progress } from "./Progress.svelte";
@@ -0,0 +1 @@
1
+ export { default as Progress } from "./Progress.svelte";
@@ -1,43 +1,58 @@
1
- <script>import { twMerge2 } from "../../utils/tw-merge2.js";
2
- let _class = "";
3
- export { _class as class };
4
- export let duration = 1e3;
5
- export let count = 8;
6
- export let thickness = "normal";
7
- export let height = "normal";
8
- export let direction = "cw";
9
- $:
10
- _count = Math.max(3, Math.min(12, count));
11
- let _id = 0;
12
- const _calcSegs = (c, d) => {
13
- const id = _id++;
14
- let out = [];
15
- for (let i = 0; i < c; i++) {
16
- out.push({
17
- id: `${id}_${i}`,
18
- rotate: 360 / c * i,
19
- delay: (direction === "ccw" ? 1 : -1) * (d - d / c * (i + 1)),
20
- duration: d
21
- });
22
- }
23
- return out;
24
- };
25
- $:
26
- _segments = _calcSegs(_count, duration);
27
- $:
28
- _thickness = "thickness-" + (["normal", "thin", "thick"].includes(thickness) ? thickness : "normal");
29
- $:
30
- _height = "height-" + (["normal", "tall", "short"].includes(height) ? height : "normal");
1
+ <script lang="ts">
2
+ import { twMerge } from "../../utils/tw-merge.js";
3
+
4
+ // this is quite verbose, but very straight forward implementation,
5
+ // and always rendered without any issues (opposed to linear-gradient hackish stuff)
6
+
7
+ let {
8
+ class: _class,
9
+ duration = 750, // one "loop" duration (in ms)
10
+ count = 8, // "hands" count
11
+ thickness = "thick", // looks better in small size
12
+ height = "normal",
13
+ direction = "cw",
14
+ }: {
15
+ class?: string;
16
+ duration?: number;
17
+ count?: number;
18
+ thickness?: "normal" | "thin" | "thick";
19
+ height?: "normal" | "tall" | "short";
20
+ direction?: "cw" | "ccw";
21
+ } = $props();
22
+
23
+ let _count = $derived(Math.max(3, Math.min(12, count)));
24
+
25
+ let _segments = $derived.by(() => {
26
+ let out = [];
27
+ for (let i = 0; i < _count; i++) {
28
+ out.push({
29
+ rotate: (360 / _count) * i,
30
+ delay:
31
+ (direction === "ccw" ? 1 : -1) * (duration - (duration / _count) * (i + 1)),
32
+ duration,
33
+ });
34
+ }
35
+ return out;
36
+ });
37
+
38
+ let _thickness = $derived(
39
+ "thickness-" +
40
+ (["normal", "thin", "thick"].includes(thickness) ? thickness : "normal")
41
+ );
42
+
43
+ let _height = $derived(
44
+ "height-" + (["normal", "tall", "short"].includes(height) ? height : "normal")
45
+ );
31
46
  </script>
32
47
 
33
- <div class="spinner {_thickness} {_height} {twMerge2('inline-block w-4', _class)}">
34
- {#each _segments as s (s.id)}
48
+ <div class="spinner {_thickness} {_height} {twMerge('inline-block w-5', _class)}">
49
+ {#each _segments as s}
35
50
  <div
36
51
  style={[
37
- `transform:rotate(${s.rotate}deg);`,
38
- `animation-delay:${s.delay}ms;`,
39
- `animation-duration:${s.duration}ms;`,
40
- ].join('')}
52
+ `transform: rotate(${s.rotate}deg);`,
53
+ `animation-delay: ${s.delay}ms;`,
54
+ `animation-duration: ${s.duration}ms;`,
55
+ ].join("")}
41
56
  ></div>
42
57
  {/each}
43
58
  </div>
@@ -68,7 +83,7 @@ $:
68
83
  }
69
84
 
70
85
  .spinner div:after {
71
- content: ' ';
86
+ content: " ";
72
87
  display: block;
73
88
  position: absolute;
74
89
 
@@ -81,16 +96,16 @@ $:
81
96
  }
82
97
  /* thickness */
83
98
  .spinner.thickness-thin div:after {
84
- left: 48%;
85
- width: 4%;
99
+ left: 47.5%;
100
+ width: 5%;
86
101
  }
87
102
  .spinner.thickness-normal div:after {
88
103
  left: 46%;
89
104
  width: 8%;
90
105
  }
91
106
  .spinner.thickness-thick div:after {
92
- left: 43%;
93
- width: 14%;
107
+ left: 44.5%;
108
+ width: 11%;
94
109
  }
95
110
 
96
111
  /* height */
@@ -1,23 +1,11 @@
1
- import { SvelteComponent } from "svelte";
2
- declare const __propDef: {
3
- props: {
4
- class?: string;
5
- duration?: number;
6
- count?: number;
7
- thickness?: "normal" | "thin" | "thick";
8
- height?: "normal" | "tall" | "short";
9
- direction?: "cw" | "ccw";
10
- };
11
- events: {
12
- [evt: string]: CustomEvent<any>;
13
- };
14
- slots: {};
15
- exports?: {} | undefined;
16
- bindings?: string | undefined;
1
+ type $$ComponentProps = {
2
+ class?: string;
3
+ duration?: number;
4
+ count?: number;
5
+ thickness?: "normal" | "thin" | "thick";
6
+ height?: "normal" | "tall" | "short";
7
+ direction?: "cw" | "ccw";
17
8
  };
18
- export type SpinnerProps = typeof __propDef.props;
19
- export type SpinnerEvents = typeof __propDef.events;
20
- export type SpinnerSlots = typeof __propDef.slots;
21
- export default class Spinner extends SvelteComponent<SpinnerProps, SpinnerEvents, SpinnerSlots> {
22
- }
23
- export {};
9
+ declare const Spinner: import("svelte").Component<$$ComponentProps, {}, "">;
10
+ type Spinner = ReturnType<typeof Spinner>;
11
+ export default Spinner;
@@ -0,0 +1 @@
1
+ export { default as Spinner } from "./Spinner.svelte";
@@ -0,0 +1 @@
1
+ export { default as Spinner } from "./Spinner.svelte";