@marianmeres/stuic 1.126.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 +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/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
@@ -1,53 +1,153 @@
1
- <script context="module">export class BackdropConfig {
2
- static class = "";
3
- static fadeInDuration = 50;
4
- static fadeOutDuration = 150;
5
- }
1
+ <script lang="ts" module>
2
+ const _instances = [];
6
3
  </script>
7
4
 
8
- <script>import { createEventDispatcher } from "svelte";
9
- import { fade } from "svelte/transition";
10
- import { focusTrap } from "../../actions/focus-trap.js";
11
- import { prefersReducedMotionStore } from "../../utils/prefers-reduced-motion.js";
12
- import { twMerge2 } from "../../utils/tw-merge2.js";
13
- const dispatch = createEventDispatcher();
14
- export let useFocusTrap = true;
15
- export let focusTrapOptions = {};
16
- let _class = "";
17
- export { _class as class };
18
- export let fadeInDuration = BackdropConfig.fadeInDuration;
19
- export let fadeOutDuration = BackdropConfig.fadeOutDuration;
20
- export let transitionEnabled = !$prefersReducedMotionStore;
21
- $:
22
- if (!transitionEnabled) {
23
- fadeInDuration = 0;
24
- fadeOutDuration = 0;
25
- }
26
- let el;
27
- $:
28
- if (el)
29
- dispatch("element", { backdrop: el });
5
+ <script lang="ts">
6
+ import {
7
+ focusTrap as focusTrapAction,
8
+ twMerge,
9
+ waitForNextRepaint,
10
+ type FocusTrapOptions,
11
+ } from "../../index.js";
12
+ import { createClog } from "@marianmeres/clog";
13
+ import { PressedKeys, watch } from "runed";
14
+ import { type Snippet } from "svelte";
15
+ import { fade } from "svelte/transition";
16
+
17
+ const clog = createClog("Backdrop").debug;
18
+
19
+ interface Props extends Record<string, any> {
20
+ class?: string;
21
+ focusTrap?: boolean | FocusTrapOptions;
22
+ fadeInDuration?: number;
23
+ fadeOutDuration?: number;
24
+ transitionEnabled?: boolean;
25
+ el?: HTMLDivElement;
26
+ children?: Snippet;
27
+ onEscape?: () => void;
28
+ visible?: boolean;
29
+ noScrollLock?: boolean;
30
+ }
31
+
32
+ let {
33
+ class: classProp,
34
+ focusTrap = true,
35
+ fadeInDuration = 50,
36
+ fadeOutDuration = 150,
37
+ transitionEnabled = true,
38
+ el = $bindable(),
39
+ children,
40
+ onEscape,
41
+ visible = $bindable(false),
42
+ noScrollLock,
43
+ ...rest
44
+ }: Props = $props();
45
+
46
+ let _opener: undefined | null | HTMLElement = $state();
47
+
48
+ // let keys = new PressedKeys();
49
+ // let isEscapePressed = $derived(keys.has("Escape"));
50
+ // $effect(() => {
51
+ // if (isEscapePressed && typeof onEscape === "function") {
52
+ // // clog("Executing onEscape...");
53
+ // onEscape();
54
+ // }
55
+ // });
56
+
57
+ $effect(() => {
58
+ if (!transitionEnabled) {
59
+ fadeInDuration = 0;
60
+ fadeOutDuration = 0;
61
+ }
62
+ });
63
+
64
+ export function close() {
65
+ visible = false;
66
+ }
67
+
68
+ export function open(openerOrEvent?: null | HTMLElement | MouseEvent) {
69
+ visible = true;
70
+ setOpener(
71
+ (openerOrEvent as any)?.currentTarget ?? openerOrEvent ?? document.activeElement
72
+ );
73
+ }
74
+
75
+ export function setOpener(opener?: null | HTMLElement) {
76
+ _opener = opener;
77
+ }
78
+
79
+ export function visibility() {
80
+ return {
81
+ get visible() {
82
+ return visible;
83
+ },
84
+ };
85
+ }
86
+
87
+ watch(
88
+ () => visible,
89
+ (isVisible, wasVisible) => {
90
+ if (wasVisible && !isVisible && _opener) {
91
+ _opener?.focus();
92
+ _opener = null;
93
+ }
94
+ }
95
+ );
96
+
97
+ // lock body scroll when open and restore back
98
+ let _original: any = {};
99
+ $effect(() => {
100
+ if (noScrollLock) return;
101
+ if (visible) {
102
+ _original = window.getComputedStyle(document.body);
103
+ const scrollY = window.scrollY;
104
+
105
+ document.body.style.position = "fixed";
106
+ document.body.style.top = `-${scrollY}px`;
107
+ document.body.style.width = "100%";
108
+ document.body.style.overflow = "hidden";
109
+ } else {
110
+ const scrollY = document.body.style.top;
111
+
112
+ document.body.style.position = _original.position;
113
+ document.body.style.position = "";
114
+ document.body.style.top = "";
115
+ document.body.style.width = "";
116
+ document.body.style.overflow = "";
117
+
118
+ // Restore scroll position
119
+ window.scrollTo(0, parseInt(scrollY || "0") * -1);
120
+ }
121
+ });
122
+
123
+ $effect(() => {
124
+ function onkeydown(e: KeyboardEvent) {
125
+ if (e.key === "Escape" && typeof onEscape === "function") {
126
+ e.stopPropagation();
127
+ e.stopImmediatePropagation();
128
+ e.preventDefault();
129
+ onEscape();
130
+ }
131
+ }
132
+ el?.addEventListener("keydown", onkeydown);
133
+ return () => el?.removeEventListener("keydown", onkeydown);
134
+ });
30
135
  </script>
31
136
 
32
- <!-- svelte-ignore a11y-no-static-element-interactions -->
33
- <!-- prettier-ignore -->
34
- <div
35
- bind:this={el}
36
- class={twMerge2(`
37
- fixed inset-0 flex z-10
38
- ${BackdropConfig.class} ${_class}
39
- `.trim())}
40
- on:click
41
- on:mousedown
42
- on:mouseup
43
- on:touchstart|passive
44
- on:touchend|passive
45
- on:keydown={(e) => e.code === 'Escape' && dispatch('escape')}
46
- in:fade={{ duration: fadeInDuration }}
47
- out:fade={{ duration: fadeOutDuration }}
48
- use:focusTrap={{ enabled: useFocusTrap, ...(focusTrapOptions || {}) }}
49
- role="presentation"
50
- tabindex="-1"
51
- >
52
- <slot />
53
- </div>
137
+ {#if visible}
138
+ <div
139
+ bind:this={el}
140
+ role="presentation"
141
+ tabindex="-1"
142
+ class={twMerge("fixed inset-0 flex z-10", classProp)}
143
+ in:fade={{ duration: fadeInDuration }}
144
+ out:fade={{ duration: fadeOutDuration }}
145
+ use:focusTrapAction={{
146
+ ...(typeof focusTrap === "object" ? focusTrap : {}),
147
+ enabled: typeof focusTrap === "boolean" ? focusTrap : !!focusTrap.enabled,
148
+ }}
149
+ {...rest}
150
+ >
151
+ {@render children?.()}
152
+ </div>
153
+ {/if}
@@ -1,39 +1,24 @@
1
- import { SvelteComponent } from "svelte";
2
- export declare class BackdropConfig {
3
- static class: string;
4
- static fadeInDuration: number;
5
- static fadeOutDuration: number;
1
+ import { type FocusTrapOptions } from "../../index.js";
2
+ import { type Snippet } from "svelte";
3
+ interface Props extends Record<string, any> {
4
+ class?: string;
5
+ focusTrap?: boolean | FocusTrapOptions;
6
+ fadeInDuration?: number;
7
+ fadeOutDuration?: number;
8
+ transitionEnabled?: boolean;
9
+ el?: HTMLDivElement;
10
+ children?: Snippet;
11
+ onEscape?: () => void;
12
+ visible?: boolean;
13
+ noScrollLock?: boolean;
6
14
  }
7
- import { type FocusTrapOptions } from '../../actions/focus-trap.js';
8
- declare const __propDef: {
9
- props: {
10
- useFocusTrap?: boolean;
11
- focusTrapOptions?: Partial<FocusTrapOptions>;
12
- class?: string;
13
- fadeInDuration?: number;
14
- fadeOutDuration?: number;
15
- transitionEnabled?: boolean;
15
+ declare const Backdrop: import("svelte").Component<Props, {
16
+ close: () => void;
17
+ open: (openerOrEvent?: null | HTMLElement | MouseEvent) => void;
18
+ setOpener: (opener?: null | HTMLElement) => void;
19
+ visibility: () => {
20
+ readonly visible: boolean;
16
21
  };
17
- events: {
18
- click: MouseEvent;
19
- mousedown: MouseEvent;
20
- mouseup: MouseEvent;
21
- touchstart: TouchEvent;
22
- touchend: TouchEvent;
23
- escape: CustomEvent<any>;
24
- element: CustomEvent<any>;
25
- } & {
26
- [evt: string]: CustomEvent<any>;
27
- };
28
- slots: {
29
- default: {};
30
- };
31
- exports?: {} | undefined;
32
- bindings?: string | undefined;
33
- };
34
- export type BackdropProps = typeof __propDef.props;
35
- export type BackdropEvents = typeof __propDef.events;
36
- export type BackdropSlots = typeof __propDef.slots;
37
- export default class Backdrop extends SvelteComponent<BackdropProps, BackdropEvents, BackdropSlots> {
38
- }
39
- export {};
22
+ }, "el" | "visible">;
23
+ type Backdrop = ReturnType<typeof Backdrop>;
24
+ export default Backdrop;
@@ -0,0 +1 @@
1
+ export { default as Backdrop } from "./Backdrop.svelte";
@@ -0,0 +1 @@
1
+ export { default as Backdrop } from "./Backdrop.svelte";
@@ -1,155 +1,131 @@
1
- <script context="module">import { twMerge2 } from "../../utils/tw-merge2.js";
2
- export class ButtonConfig {
3
- static defaultSize = "md";
4
- static defaultShadow = false;
5
- static defaultRounded = true;
6
- static defaultVariant = void 0;
7
- static presetBase = `
8
- text-center
9
- inline-flex items-center gap-x-2
10
- hover:brightness-[1.05]
11
- active:brightness-[0.95]
12
- disabled:!cursor-not-allowed disabled:!opacity-50 disabled:hover:brightness-100
13
- no-underline
14
- border border-neutral-300 dark:border-neutral-500
15
-
16
- bg-neutral-200 text-neutral-950
17
- dark:bg-neutral-600 dark:text-neutral-50
18
- `.trim();
19
- static presetSquare = "p-0 aspect-square justify-center";
20
- static presetsRounded = {
21
- xs: "rounded",
22
- sm: "rounded",
23
- md: "rounded",
24
- lg: "rounded-md",
25
- xl: "rounded-lg"
26
- };
27
- static presetsShadow = {
28
- xs: "shadow-sm dark:shadow-neutral-950",
29
- sm: "shadow dark:shadow-neutral-950",
30
- md: "shadow dark:shadow-neutral-950",
31
- lg: "shadow-md dark:shadow-neutral-950",
32
- xl: "shadow-md dark:shadow-neutral-950"
33
- };
34
- static presetsSize = {
35
- xs: "px-2 py-0.5 leading-tight text-xs",
36
- sm: "px-2.5 py-0.5 leading-normal text-sm",
37
- md: "px-3 py-1 leading-normal text-sm",
38
- lg: "px-4 py-1.5 leading-normal text-base",
39
- xl: "px-4 py-2 leading-normal text-lg"
40
- };
41
- static classBySize = {
42
- xs: "",
43
- sm: "",
44
- md: "",
45
- lg: "",
46
- xl: ""
47
- };
48
- static class = "";
49
- // to be defined at consumer level...
50
- static variant = {
51
- primary: `
52
- bg-stuic-primary text-stuic-on-primary
53
- dark:bg-stuic-primary-dark dark:text-stuic-on-primary-dark
54
- `.trim(),
55
- secondary: `
56
- bg-stuic-secondary text-stuic-on-secondary
57
- dark:bg-stuic-secondary-dark dark:text-stuic-on-secondary-dark
58
- `.trim()
59
- };
60
- }
1
+ <script lang="ts" module>
2
+ export const BUTTON_STUIC_BASE_CLASSES = `
3
+ bg-button-bg text-button-text
4
+ dark:bg-button-bg-dark dark:text-button-text-dark
5
+ font-mono text-sm text-center
6
+ leading-4
7
+ border-1
8
+ border-button-border dark:border-button-border-dark
9
+ rounded-md
10
+ inline-flex items-center justify-center gap-x-2
11
+ px-3 py-1.5
12
+
13
+ hover:brightness-[1.05]
14
+ active:brightness-[0.95]
15
+ disabled:hover:brightness-100
16
+
17
+ focus:brightness-[1.05]
18
+ focus:border-button-border-focus focus:dark:border-button-border-focus-dark
19
+
20
+ focus:outline-4 focus:outline-black/10 focus:dark:outline-white/20
21
+ focus-visible:outline-4 focus-visible:outline-black/10 focus-visible:dark:outline-white/20
22
+ `;
23
+
24
+ export const BUTTON_STUIC_PRESET_CLASSES: any = {
25
+ size: {
26
+ sm: `text-xs rounded-sm px-2 py-0.5`,
27
+ lg: `text-base rounded-md`,
28
+ },
29
+ variant: {
30
+ primary: `font-medium`,
31
+ secondary: `
32
+ bg-neutral-100 dark:bg-neutral-600
33
+ text-black/60 dark:text-white/80
34
+ shadow-[1px_1px_0_0_rgba(0_0_0_/_.2)]
35
+ active:shadow-none active:translate-[1px]
36
+ focus:shadow-black/30
37
+ `,
38
+ },
39
+ muted: `text-black/70 dark:text-white/70`,
40
+ shadow: `
41
+ shadow-[1px_1px_0_0_rgba(0_0_0_/_.4)]
42
+ active:shadow-none active:translate-[1px]
43
+ disabled:shadow-none disabled:active:shadow-none disabled:active:translate-none
44
+ `,
45
+ };
61
46
  </script>
62
47
 
63
- <script>let _class = "";
64
- export { _class as class };
65
- export let href = "";
66
- export let type = "button";
67
- export let shadow = ButtonConfig.defaultShadow;
68
- export let rounded = ButtonConfig.defaultRounded;
69
- export let variant = ButtonConfig.defaultVariant;
70
- export let square = false;
71
- export let disabled = false;
72
- export let value = void 0;
73
- const _whitelist = ["xs", "sm", "md", "lg", "xl"];
74
- export let size = ButtonConfig.defaultSize;
75
- $:
76
- if (!_whitelist.includes(size))
77
- size = ButtonConfig.defaultSize;
78
- let buttonClass;
79
- $:
80
- buttonClass = twMerge2(
81
- ButtonConfig.presetBase,
82
- // either full, or config, or none
83
- rounded ? rounded === "full" || square ? "rounded-full" : ButtonConfig.presetsRounded[size] : "",
84
- //
85
- shadow && ButtonConfig.presetsShadow[size],
86
- //
87
- ButtonConfig.presetsSize[size],
88
- //
89
- ButtonConfig.classBySize[size],
90
- //
91
- ButtonConfig.class,
92
- //
93
- variant && `${variant || ""}`.split(" ").reduce((m, v) => {
94
- m += ButtonConfig.variant?.[v] + " ";
95
- return m;
96
- }, " "),
97
- //
98
- square && ButtonConfig.presetSquare,
99
- //
100
- _class
101
- );
48
+ <script lang="ts">
49
+ import type { Snippet } from "svelte";
50
+ import type { HTMLButtonAttributes } from "svelte/elements";
51
+ import { twMerge } from "../../utils/tw-merge.js";
52
+ //
53
+ import "./index.css";
54
+
55
+ // interface Props extends DataAttributes, Partial<Omit<HTMLButtonElement, 'children'>> {
56
+ interface Props extends HTMLButtonAttributes {
57
+ variant?: "primary" | "secondary" | string;
58
+ size?: "sm" | "md" | "lg" | string;
59
+ muted?: boolean;
60
+ noshadow?: boolean;
61
+ unstyled?: boolean;
62
+ class?: string;
63
+ href?: string;
64
+ children?: Snippet<[{ checked?: boolean }]>;
65
+ // support for switch
66
+ roleSwitch?: boolean;
67
+ checked?: boolean;
68
+ el?: Element;
69
+ }
70
+
71
+ let {
72
+ variant,
73
+ size,
74
+ class: classProp,
75
+ muted,
76
+ noshadow,
77
+ unstyled,
78
+ href,
79
+ children,
80
+ //
81
+ roleSwitch = false,
82
+ checked = $bindable(false),
83
+ el = $bindable(),
84
+ //
85
+ ...rest
86
+ }: Props = $props();
87
+
88
+ // let button: HTMLButtonElement | undefined = $state();
89
+
90
+ $effect(() => {
91
+ const toggle = () => (checked = !checked);
92
+ if (!href && roleSwitch && el) {
93
+ el?.addEventListener("click", toggle);
94
+ }
95
+ return () => el?.removeEventListener("click", toggle);
96
+ });
97
+
98
+ const _base = BUTTON_STUIC_BASE_CLASSES;
99
+ const _preset: any = BUTTON_STUIC_PRESET_CLASSES;
100
+
101
+ // see button.css
102
+ let _class = $derived(
103
+ [
104
+ // "namespace" (so we can target it in css files when customizing)
105
+ "stuic-button",
106
+ // pass all styling props as classnames as well
107
+ variant,
108
+ size,
109
+ muted && "muted",
110
+ noshadow && "no-shadow",
111
+ // now, attach the default tw classes (unless not explicitly forbidden)
112
+ !unstyled && _base,
113
+ !unstyled && size && _preset.size[size],
114
+ !unstyled && variant && _preset.variant[variant],
115
+ !unstyled && muted && _preset.muted,
116
+ !unstyled && !noshadow && _preset.shadow,
117
+ ]
118
+ .filter(Boolean)
119
+ .join(" ")
120
+ );
102
121
  </script>
103
122
 
104
123
  {#if href}
105
- <a
106
- {href}
107
- class={buttonClass}
108
- {...$$restProps}
109
- role="button"
110
- data-button-size={size}
111
- data-button-shadow={shadow}
112
- data-button-rounded={rounded}
113
- data-button-variant={variant}
114
- on:focus
115
- on:blur
116
- on:click
117
- on:change
118
- on:keydown
119
- on:keyup
120
- on:touchstart|passive
121
- on:touchend|passive
122
- on:touchmove|passive
123
- on:touchcancel
124
- on:mouseenter
125
- on:mouseleave
126
- >
127
- <slot />
124
+ <a {href} bind:this={el} class={twMerge(_class, classProp)} {...rest as any}>
125
+ {@render children?.({})}
128
126
  </a>
129
127
  {:else}
130
- <button
131
- {type}
132
- {disabled}
133
- class={buttonClass}
134
- {value}
135
- data-button-size={size}
136
- data-button-shadow={shadow}
137
- data-button-rounded={rounded}
138
- data-button-variant={variant}
139
- {...$$restProps}
140
- on:focus
141
- on:blur
142
- on:click
143
- on:change
144
- on:keydown
145
- on:keyup
146
- on:touchstart|passive
147
- on:touchend|passive
148
- on:touchmove|passive
149
- on:touchcancel
150
- on:mouseenter
151
- on:mouseleave
152
- >
153
- <slot />
128
+ <button bind:this={el} class={twMerge(_class, classProp)} {...rest}>
129
+ {@render children?.({ checked })}
154
130
  </button>
155
131
  {/if}
@@ -1,81 +1,23 @@
1
- import { SvelteComponent } from "svelte";
2
- export declare class ButtonConfig {
3
- static defaultSize: 'xs' | 'sm' | 'md' | 'lg' | 'xl';
4
- static defaultShadow: boolean;
5
- static defaultRounded: boolean;
6
- static defaultVariant: string | undefined;
7
- static presetBase: string;
8
- static presetSquare: string;
9
- static presetsRounded: {
10
- xs: string;
11
- sm: string;
12
- md: string;
13
- lg: string;
14
- xl: string;
15
- };
16
- static presetsShadow: {
17
- xs: string;
18
- sm: string;
19
- md: string;
20
- lg: string;
21
- xl: string;
22
- };
23
- static presetsSize: {
24
- xs: string;
25
- sm: string;
26
- md: string;
27
- lg: string;
28
- xl: string;
29
- };
30
- static classBySize: {
31
- xs: string;
32
- sm: string;
33
- md: string;
34
- lg: string;
35
- xl: string;
36
- };
37
- static class: string;
38
- static variant: Record<string, string>;
1
+ export declare const BUTTON_STUIC_BASE_CLASSES = "\n\t\tbg-button-bg text-button-text \n\t\tdark:bg-button-bg-dark dark:text-button-text-dark\n\t\tfont-mono text-sm text-center \n\t\tleading-4\n\t\tborder-1\n\t\tborder-button-border dark:border-button-border-dark\n\t\trounded-md\n\t\tinline-flex items-center justify-center gap-x-2\n\t\tpx-3 py-1.5\n\n\t\thover:brightness-[1.05]\n\t\tactive:brightness-[0.95]\n\t\tdisabled:hover:brightness-100\n\n\t\tfocus:brightness-[1.05] \n\t\tfocus:border-button-border-focus focus:dark:border-button-border-focus-dark\n\n\t\t focus:outline-4 focus:outline-black/10 focus:dark:outline-white/20\n\t\tfocus-visible:outline-4 focus-visible:outline-black/10 focus-visible:dark:outline-white/20\n\t";
2
+ export declare const BUTTON_STUIC_PRESET_CLASSES: any;
3
+ import type { Snippet } from "svelte";
4
+ import type { HTMLButtonAttributes } from "svelte/elements";
5
+ import "./index.css";
6
+ interface Props extends HTMLButtonAttributes {
7
+ variant?: "primary" | "secondary" | string;
8
+ size?: "sm" | "md" | "lg" | string;
9
+ muted?: boolean;
10
+ noshadow?: boolean;
11
+ unstyled?: boolean;
12
+ class?: string;
13
+ href?: string;
14
+ children?: Snippet<[{
15
+ checked?: boolean;
16
+ }]>;
17
+ roleSwitch?: boolean;
18
+ checked?: boolean;
19
+ el?: Element;
39
20
  }
40
- declare const __propDef: {
41
- props: {
42
- [x: string]: any;
43
- class?: string | undefined;
44
- href?: string | undefined;
45
- type?: "reset" | "submit" | "button" | null | undefined;
46
- shadow?: boolean | undefined;
47
- rounded?: boolean | "full" | undefined;
48
- variant?: string | undefined | undefined;
49
- square?: boolean | undefined;
50
- disabled?: boolean | undefined;
51
- value?: string | undefined | undefined;
52
- size?: "xs" | "sm" | "md" | "lg" | "xl" | undefined;
53
- };
54
- events: {
55
- focus: FocusEvent;
56
- blur: FocusEvent;
57
- click: MouseEvent;
58
- change: Event;
59
- keydown: KeyboardEvent;
60
- keyup: KeyboardEvent;
61
- touchstart: TouchEvent;
62
- touchend: TouchEvent;
63
- touchmove: TouchEvent;
64
- touchcancel: TouchEvent;
65
- mouseenter: MouseEvent;
66
- mouseleave: MouseEvent;
67
- } & {
68
- [evt: string]: CustomEvent<any>;
69
- };
70
- slots: {
71
- default: {};
72
- };
73
- exports?: undefined;
74
- bindings?: undefined;
75
- };
76
- export type ButtonProps = typeof __propDef.props;
77
- export type ButtonEvents = typeof __propDef.events;
78
- export type ButtonSlots = typeof __propDef.slots;
79
- export default class Button extends SvelteComponent<ButtonProps, ButtonEvents, ButtonSlots> {
80
- }
81
- export {};
21
+ declare const Button: import("svelte").Component<Props, {}, "checked" | "el">;
22
+ type Button = ReturnType<typeof Button>;
23
+ export default Button;
@@ -0,0 +1,16 @@
1
+ @import "../../_shared.css";
2
+
3
+ /* prettier-ignore */
4
+ @theme inline {
5
+ --color-button-bg: var(--color-button-bg, var(--color-neutral-200));
6
+ --color-button-bg-dark: var(--color-button-bg-dark, var(--color-neutral-500));
7
+
8
+ --color-button-text: var(--color-button-text, var(--color-black));
9
+ --color-button-text-dark: var(--color-button-text-dark, var(--color-white));
10
+
11
+ --color-button-border: var(--color-button-border, var(--color-neutral-400));
12
+ --color-button-border-dark: var(--color-button-border-dark, var(--color-neutral-800));
13
+
14
+ --color-button-border-focus: var(--color-button-border-focus, var(--color-neutral-500));
15
+ --color-button-border-focus-dark: var(--color-button-border-focus-dark, var(--color-neutral-500));
16
+ }
@@ -0,0 +1 @@
1
+ export { default as Button } from './Button.svelte';