@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
@@ -1,88 +1,159 @@
1
- <script context="module">import { createClog } from "@marianmeres/clog";
2
- import { createSwitchStore } from "@marianmeres/switch-store";
3
- import { createEventDispatcher } from "svelte";
4
- import { fly } from "svelte/transition";
5
- import { onOutside } from "../../actions/on-outside.js";
6
- import { prefersReducedMotionStore } from "../../utils/prefers-reduced-motion.js";
7
- import { twMerge2 } from "../../utils/tw-merge2.js";
8
- import Backdrop from "../Backdrop/Backdrop.svelte";
9
- export const createDrawerStore = (open = false) => createSwitchStore(open);
10
- </script>
1
+ <script lang="ts">
2
+ import { fly } from "svelte/transition";
3
+ import { type FocusTrapOptions } from "../../actions/focus-trap.js";
4
+ import { prefersReducedMotion } from "../../utils/prefers-reduced-motion.svelte.js";
5
+ import { twMerge } from "../../utils/tw-merge.js";
6
+ import Backdrop from "../Backdrop/Backdrop.svelte";
7
+ import type { Snippet } from "svelte";
8
+ // import { onClickOutside } from "runed";
9
+
10
+ const prefersReduced = prefersReducedMotion();
11
+ const DEFAULT_POS = "left";
12
+
13
+ interface Props {
14
+ visible?: boolean;
15
+ position?: "left" | "top" | "right" | "bottom";
16
+ children: Snippet;
17
+ class?: string;
18
+ classBackdrop?: string;
19
+ labelledby?: string;
20
+ describedby?: string;
21
+ transitionDuration?: number;
22
+ // transitionEnabled?: boolean;
23
+ elBackdrop?: HTMLDivElement;
24
+ el?: HTMLDivElement;
25
+ focusTrap?: boolean | FocusTrapOptions;
26
+ // will be used in `fly` config. Ideally should match with the provided tw classes
27
+ // to make the animation optimal. May include ccs units (will be considered as pixels otherwise).
28
+ animOffset?: string | number;
29
+ onEscape?: () => void;
30
+ //
31
+ onOutside?: () => void;
32
+ // onOutsideEnabled?: boolean;
33
+ }
34
+
35
+ let {
36
+ visible = $bindable(false),
37
+ position = DEFAULT_POS,
38
+ children,
39
+ class: classProp,
40
+ classBackdrop,
41
+ labelledby,
42
+ describedby,
43
+ transitionDuration = 200,
44
+ // transitionEnabled = true,
45
+ elBackdrop = $bindable(),
46
+ el = $bindable(),
47
+ focusTrap,
48
+ animOffset = "75vw",
49
+ onEscape,
50
+ onOutside,
51
+ // onOutsideEnabled = true,
52
+ }: Props = $props();
53
+
54
+ $effect(() => {
55
+ if (prefersReduced.current) transitionDuration = 0;
56
+ });
57
+
58
+ // opinionated: make backdrop fade-in a little faster (but never longer than 200)... looks better
59
+ let fadeInDuration = $derived(Math.min(transitionDuration * 0.7, 200));
60
+
61
+ // prettier-ignore
62
+ const _classPresetsBackdrop = {
63
+ left: `justify-start`,
64
+ right: `justify-end`,
65
+ top: `items-start`,
66
+ bottom: `items-end`,
67
+ };
68
+
69
+ // prettier-ignore
70
+ const _classPresets = {
71
+ left: `w-full sm:w-[75vw] h-full`,
72
+ right: `w-full sm:w-[75vw] h-full`,
73
+ // top/bottom are full by default
74
+ top: `w-full h-full`, // sm:h-[75vh]
75
+ bottom: `w-full h-full`, // sm:h-[75vh]
76
+ };
77
+
78
+ // prettier-ignore
79
+ let _animPresets = $derived({
80
+ left: { x: `-${animOffset}`, y: 0 },
81
+ right: { x: animOffset, y: 0 },
82
+ top: { x: 0, y: `-${animOffset}`},
83
+ bottom: { x: 0, y: animOffset },
84
+ });
11
85
 
12
- <script>const clog = createClog("Drawer");
13
- const dispatch = createEventDispatcher();
14
- export let drawer;
15
- export let position = "left";
16
- const _whitelist = ["left", "top", "right", "bottom"];
17
- $:
18
- if (!_whitelist.includes(position))
19
- position = "left";
20
- let _class = "";
21
- export { _class as class };
22
- export let backdropClass = "";
23
- export let labelledby = "";
24
- export let describedby = "";
25
- export let transitionDuration = 250;
26
- export let transitionEnabled = !$prefersReducedMotionStore;
27
- export let animOffset = "66vw";
28
- export let backdropFocusTrapOptions = {};
29
- $:
30
- fadeInDuration = transitionEnabled ? Math.min(transitionDuration * 0.66, 200) : 0;
31
- const _presetsClsBackdrop = {
32
- left: `justify-start`,
33
- right: `justify-end`,
34
- top: `items-start`,
35
- bottom: `items-end`
36
- };
37
- const _presetsCls = {
38
- left: `w-full sm:w-[66vw] h-full`,
39
- right: `w-full sm:w-[66vw] h-full`,
40
- top: `w-full h-full sm:h-[66vh]`,
41
- bottom: `w-full h-full sm:h-[66vh]`
42
- };
43
- $:
44
- _presetsAnim = {
45
- left: { x: `-${animOffset}`, y: 0 },
46
- right: { x: animOffset, y: 0 },
47
- top: { x: 0, y: `-${animOffset}` },
48
- bottom: { x: 0, y: animOffset }
49
- };
50
- let el;
51
- $:
52
- if (el)
53
- dispatch("element", { drawer: el });
86
+ // onClickOutside(
87
+ // () => el,
88
+ // () => {
89
+ // // noop if not enabled
90
+ // if (!onOutsideEnabled) return;
91
+ // // explicit false means ignoring outside click
92
+ // if (typeof onOutside === "function") onOutside();
93
+ // else if (onOutside !== false) visible = false;
94
+ // }
95
+ // );
96
+
97
+ let _classBackdrop = $derived(
98
+ _classPresetsBackdrop[position] ?? _classPresetsBackdrop[DEFAULT_POS]
99
+ );
100
+
101
+ let _class = $derived(_classPresets[position] ?? _classPresets[DEFAULT_POS]);
102
+
103
+ let flyOptions = $derived({
104
+ duration: transitionDuration,
105
+ ...(_animPresets[position] ?? _animPresets[DEFAULT_POS]),
106
+ });
107
+
108
+ let backdrop: Backdrop = $state()!;
109
+
110
+ export function close() {
111
+ backdrop.close();
112
+ }
113
+
114
+ export function open(openerOrEvent?: null | HTMLElement | MouseEvent) {
115
+ // setOpener(openerOrEvent ?? (document.activeElement as any));
116
+ backdrop.open(openerOrEvent);
117
+ }
118
+
119
+ export function setOpener(opener?: null | HTMLElement) {
120
+ backdrop.setOpener(opener);
121
+ }
54
122
  </script>
55
123
 
56
- {#if $drawer.isOpen}
57
- <Backdrop
58
- class={twMerge2(`${_presetsClsBackdrop[position] || ''} ${backdropClass}`)}
59
- on:escape
60
- on:mousedown={(e) => dispatch('click_backdrop')}
61
- {fadeInDuration}
62
- fadeOutDuration={transitionEnabled ? transitionDuration : 0}
63
- on:element
64
- focusTrapOptions={backdropFocusTrapOptions}
124
+ <!--
125
+ Using `onmousedown` not `onclick` intentionally. Otherwise drag inside + release outside
126
+ (eg selecting text and accidentally release outside) would trigger close.
127
+ -->
128
+
129
+ <Backdrop
130
+ bind:this={backdrop}
131
+ bind:el={elBackdrop}
132
+ bind:visible
133
+ class={twMerge(_classBackdrop, classBackdrop)}
134
+ {focusTrap}
135
+ {fadeInDuration}
136
+ fadeOutDuration={transitionDuration}
137
+ {onEscape}
138
+ onmousedown={() => onOutside?.()}
139
+ >
140
+ <!-- svelte-ignore a11y_interactive_supports_focus -->
141
+ <!-- svelte-ignore a11y_click_events_have_key_events -->
142
+ <div
143
+ bind:this={el}
144
+ aria-modal="true"
145
+ role="dialog"
146
+ aria-labelledby={labelledby}
147
+ aria-describedby={describedby}
148
+ class={twMerge("overflow-y-auto", _class, classProp)}
149
+ transition:fly={flyOptions}
150
+ onmousedown={(e) => {
151
+ if (onOutside) {
152
+ e.stopImmediatePropagation();
153
+ e.stopPropagation();
154
+ }
155
+ }}
65
156
  >
66
- <!--
67
- svelte-ignore
68
- a11y-click-events-have-key-events
69
- a11y-no-noninteractive-element-interactions
70
- -->
71
- <div
72
- bind:this={el}
73
- on:mousedown|stopPropagation
74
- aria-modal="true"
75
- role="dialog"
76
- aria-labelledby={labelledby}
77
- aria-describedby={describedby}
78
- transition:fly={{
79
- duration: transitionEnabled ? transitionDuration : 0,
80
- ...(_presetsAnim[position] || {}),
81
- }}
82
- class={twMerge2(`overflow-y-auto ${_presetsCls[position] || ''} ${_class}`)}
83
- use:onOutside
84
- >
85
- <slot />
86
- </div>
87
- </Backdrop>
88
- {/if}
157
+ {@render children()}
158
+ </div>
159
+ </Backdrop>
@@ -1,36 +1,25 @@
1
- import { SvelteComponent } from "svelte";
2
- import type { FocusTrapOptions } from '../../actions/focus-trap.js';
3
- export type DrawerStore = ReturnType<typeof createDrawerStore>;
4
- export declare const createDrawerStore: (open?: boolean) => import("@marianmeres/switch-store").SwitchStore<any>;
5
- declare const __propDef: {
6
- props: {
7
- drawer: DrawerStore;
8
- position?: "left" | "top" | "right" | "bottom";
9
- class?: string;
10
- backdropClass?: string;
11
- labelledby?: string;
12
- describedby?: string;
13
- transitionDuration?: number;
14
- transitionEnabled?: boolean;
15
- animOffset?: string | number;
16
- backdropFocusTrapOptions?: Partial<FocusTrapOptions>;
17
- };
18
- events: {
19
- escape: CustomEvent<any>;
20
- element: CustomEvent<any>;
21
- mousedown: MouseEvent;
22
- } & {
23
- [evt: string]: CustomEvent<any>;
24
- };
25
- slots: {
26
- default: {};
27
- };
28
- exports?: {} | undefined;
29
- bindings?: string | undefined;
30
- };
31
- export type DrawerProps = typeof __propDef.props;
32
- export type DrawerEvents = typeof __propDef.events;
33
- export type DrawerSlots = typeof __propDef.slots;
34
- export default class Drawer extends SvelteComponent<DrawerProps, DrawerEvents, DrawerSlots> {
1
+ import { type FocusTrapOptions } from "../../actions/focus-trap.js";
2
+ import type { Snippet } from "svelte";
3
+ interface Props {
4
+ visible?: boolean;
5
+ position?: "left" | "top" | "right" | "bottom";
6
+ children: Snippet;
7
+ class?: string;
8
+ classBackdrop?: string;
9
+ labelledby?: string;
10
+ describedby?: string;
11
+ transitionDuration?: number;
12
+ elBackdrop?: HTMLDivElement;
13
+ el?: HTMLDivElement;
14
+ focusTrap?: boolean | FocusTrapOptions;
15
+ animOffset?: string | number;
16
+ onEscape?: () => void;
17
+ onOutside?: () => void;
35
18
  }
36
- export {};
19
+ declare const Drawer: import("svelte").Component<Props, {
20
+ close: () => void;
21
+ open: (openerOrEvent?: null | HTMLElement | MouseEvent) => void;
22
+ setOpener: (opener?: null | HTMLElement) => void;
23
+ }, "el" | "visible" | "elBackdrop">;
24
+ type Drawer = ReturnType<typeof Drawer>;
25
+ export default Drawer;
@@ -0,0 +1 @@
1
+ export { default as Drawer } from "./Drawer.svelte";
@@ -0,0 +1 @@
1
+ export { default as Drawer } from "./Drawer.svelte";
@@ -1,117 +1,156 @@
1
- <script>import { createClog } from "@marianmeres/clog";
2
- import { createEventDispatcher } from "svelte";
3
- import { get } from "svelte/store";
4
- import { DevicePointer } from "../../utils/device-pointer.js";
5
- import { prefersReducedMotionStore } from "../../utils/prefers-reduced-motion.js";
6
- import { twMerge2 } from "../../utils/tw-merge2.js";
7
- import { windowSize } from "../../utils/window-size.js";
8
- const clog = createClog("HoverExpandableWidth");
9
- const dispatch = createEventDispatcher();
10
- export let enabled = DevicePointer.isFine;
11
- export let shadowOpacity = 0.5;
12
- export let duration = 150;
13
- export let targetWidth = 256;
14
- export let delayIn = 400;
15
- export let delayOut = 100;
16
- let _class = "";
17
- export { _class as class };
18
- let _isExpanded = false;
19
- let _isShrinking = false;
20
- let _isExpanding = false;
21
- let el;
22
- let _delayTimer;
23
- const _resetDelayTimer = () => {
24
- if (_delayTimer)
25
- clearTimeout(_delayTimer);
26
- _delayTimer = null;
27
- };
28
- const _planDelayedExec = (_fn, _delay) => {
29
- _resetDelayTimer();
30
- _delayTimer = setTimeout(() => {
31
- _fn();
32
- _resetDelayTimer();
33
- }, _delay);
34
- };
35
- let box;
36
- const _expand = () => {
37
- if (!enabled)
38
- return;
39
- if (_isExpanding || _isShrinking || _isExpanded)
40
- return;
41
- _isExpanded = true;
42
- _isExpanding = true;
43
- box = el.getBoundingClientRect();
44
- const win = get(windowSize);
45
- const pos = {
46
- top: box.top,
47
- bottom: win.height - box.bottom,
48
- left: box.left,
49
- right: win.width - box.right
50
- };
51
- el.style.boxShadow = `16px 0 24px -16px rgb(0 0 0 / ${shadowOpacity})`;
52
- el.style.top = `${pos.top}px`;
53
- el.style.right = `${pos.right}px`;
54
- el.style.bottom = `${pos.bottom}px`;
55
- el.style.left = `${pos.left}px`;
56
- el.style.width = "auto";
57
- el.style.height = "auto";
58
- el.style.zIndex = "1";
59
- setTimeout(
60
- () => _isExpanding = false,
61
- duration + 1e3 / 60 * 3
62
- // 3 x raf
63
- );
64
- requestAnimationFrame(() => {
65
- el.style.position = `fixed`;
66
- requestAnimationFrame(() => {
67
- el.style.width = `${box.width}px`;
68
- requestAnimationFrame(() => {
69
- !$prefersReducedMotionStore && (el.style.transitionProperty = "all");
70
- el.style.width = `${targetWidth}px`;
71
- });
72
- });
73
- });
74
- };
75
- const _shrink = () => {
76
- if (!enabled)
77
- return;
78
- if (_isExpanding || _isShrinking || !_isExpanded)
79
- return;
80
- _isExpanded = false;
81
- _isShrinking = true;
82
- el.style.boxShadow = "none";
83
- el.style.width = `${box.width}px`;
84
- setTimeout(() => {
85
- _isShrinking = false;
86
- el.style.position = `static`;
87
- el.style.top = "auto";
88
- el.style.right = "auto";
89
- el.style.bottom = "auto";
90
- el.style.left = "auto";
91
- el.style.width = "100%";
92
- el.style.height = "100%";
93
- el.style.zIndex = "0";
94
- el.style.transitionProperty = "none";
95
- }, duration);
96
- };
97
- $:
98
- dispatch("change", _isExpanded);
1
+ <script lang="ts">
2
+ import type { Snippet } from "svelte";
3
+ import { innerHeight, innerWidth } from "svelte/reactivity/window";
4
+ import { DevicePointer } from "../../utils/device-pointer.svelte.js";
5
+ import { waitForNextRepaint, waitForTransitionEnd } from "../../utils/paint.js";
6
+ import { prefersReducedMotion } from "../../utils/prefers-reduced-motion.svelte.js";
7
+ import { twMerge } from "../../utils/tw-merge.js";
8
+
9
+ const dp = new DevicePointer();
10
+
11
+ interface Props {
12
+ enabled?: boolean;
13
+ class?: string;
14
+ shadowOpacity?: number;
15
+ duration?: number;
16
+ targetWidth?: number;
17
+ delayIn?: number;
18
+ delayOut?: number;
19
+ children: Snippet<
20
+ [
21
+ {
22
+ isExpanded: boolean;
23
+ isExpanding: boolean;
24
+ isShrinking: boolean;
25
+ inTransition: boolean;
26
+ },
27
+ ]
28
+ >;
29
+ }
30
+
31
+ let {
32
+ enabled = dp.isFine,
33
+ shadowOpacity = 0.5,
34
+ duration: _duration = 150,
35
+ targetWidth = 256,
36
+ delayIn = 500,
37
+ delayOut = 300,
38
+ class: classProp,
39
+ children,
40
+ ...rest
41
+ }: Props = $props();
42
+
43
+ //
44
+ const prefersReduced = prefersReducedMotion();
45
+ let el = $state<HTMLDivElement>()!;
46
+ let isExpanded = $state(false);
47
+ let isShrinking = $state(false);
48
+ let isExpanding = $state(false);
49
+ let inTransition = $derived(isExpanding || isShrinking);
50
+ let _timer: any;
51
+ let box = $state<DOMRect>();
52
+ let duration = $derived(prefersReduced.current ? 0 : _duration);
53
+
54
+ function clear() {
55
+ clearTimeout(_timer);
56
+ _timer = null;
57
+ }
58
+
59
+ function schedule(fn: CallableFunction, delay: number) {
60
+ clear();
61
+ _timer = setTimeout(() => {
62
+ fn?.();
63
+ clear();
64
+ }, delay);
65
+ }
66
+
67
+ function expand() {
68
+ if (!enabled) return;
69
+ if (isExpanding || isShrinking || isExpanded) return;
70
+
71
+ // asap
72
+ isExpanded = true;
73
+ isExpanding = true;
74
+
75
+ box = el.getBoundingClientRect();
76
+ const pos = {
77
+ top: box.top,
78
+ bottom: innerHeight.current! - box.bottom,
79
+ left: box.left,
80
+ right: innerWidth.current! - box.right,
81
+ };
82
+
83
+ // <offset-x>, <offset-y>, <blur-radius>, <spread-radius>
84
+ el.style.boxShadow = `16px 0 24px -16px rgb(0 0 0 / ${shadowOpacity})`;
85
+
86
+ // no transition yet
87
+ el.style.top = `${pos.top}px`;
88
+ el.style.right = `${pos.right}px`;
89
+ el.style.bottom = `${pos.bottom}px`;
90
+ el.style.left = `${pos.left}px`;
91
+
92
+ el.style.width = "auto";
93
+ el.style.height = "auto";
94
+
95
+ el.style.zIndex = "1";
96
+
97
+ // kind of ugly - need to set props in multiple steps...
98
+ (async () => {
99
+ await waitForNextRepaint();
100
+ el.style.position = `fixed`;
101
+
102
+ await waitForNextRepaint();
103
+ el.style.width = `${box!.width}px`;
104
+
105
+ await waitForNextRepaint();
106
+ el.style.transitionProperty = "all";
107
+ el.style.width = `${targetWidth}px`;
108
+
109
+ await waitForTransitionEnd(el);
110
+ isExpanding = false;
111
+ })();
112
+ }
113
+
114
+ function shrink() {
115
+ if (!enabled) return;
116
+ if (isExpanding || isShrinking || !isExpanded) return;
117
+
118
+ // asap
119
+ isExpanded = false;
120
+ isShrinking = true;
121
+
122
+ el.style.boxShadow = "none";
123
+ el.style.width = `${box!.width}px`;
124
+
125
+ (async () => {
126
+ await waitForTransitionEnd(el);
127
+ isShrinking = false;
128
+
129
+ // now reset all back to defaults
130
+ el.style.position = `static`;
131
+
132
+ el.style.top = "auto";
133
+ el.style.right = "auto";
134
+ el.style.bottom = "auto";
135
+ el.style.left = "auto";
136
+
137
+ el.style.width = "100%";
138
+ el.style.height = "100%";
139
+
140
+ el.style.zIndex = "0";
141
+ el.style.transitionProperty = "none";
142
+ })();
143
+ }
99
144
  </script>
100
145
 
101
- <!-- svelte-ignore a11y-click-events-have-key-events a11y-no-static-element-interactions -->
102
146
  <div
103
147
  bind:this={el}
104
- on:mouseenter={() => _planDelayedExec(_expand, delayIn)}
105
- on:mouseleave={() => _planDelayedExec(_shrink, delayOut)}
106
- on:click
107
- aria-expanded={_isExpanded}
108
- class={twMerge2(`overflow-x-hidden overflow-y-auto ${_class}`)}
109
- style="width: 100%; height: 100%; transition-duration: {duration}ms;"
148
+ onmouseenter={() => schedule(expand, delayIn)}
149
+ onmouseleave={() => schedule(shrink, delayOut)}
150
+ class={twMerge("stuic-expandable", "overflow-x-hidden overflow-y-auto", classProp)}
151
+ style="width: 100%; height: 100%; transition-timing-function: ease-in; transition-duration: {duration}ms;"
152
+ aria-expanded={isExpanded}
153
+ {...rest}
110
154
  >
111
- <slot
112
- isExpanded={_isExpanded}
113
- isExpanding={_isExpanding}
114
- isShrinking={_isShrinking}
115
- inTransition={_isExpanding || _isShrinking}
116
- />
155
+ {@render children({ isExpanded, isShrinking, isExpanding, inTransition })}
117
156
  </div>
@@ -1,34 +1,21 @@
1
- import { SvelteComponent } from "svelte";
2
- declare const __propDef: {
3
- props: {
4
- enabled?: boolean | undefined;
5
- shadowOpacity?: number;
6
- duration?: number;
7
- targetWidth?: number;
8
- delayIn?: number;
9
- delayOut?: number;
10
- class?: string;
11
- };
12
- events: {
13
- click: MouseEvent;
14
- change: CustomEvent<any>;
15
- } & {
16
- [evt: string]: CustomEvent<any>;
17
- };
18
- slots: {
19
- default: {
1
+ import type { Snippet } from "svelte";
2
+ interface Props {
3
+ enabled?: boolean;
4
+ class?: string;
5
+ shadowOpacity?: number;
6
+ duration?: number;
7
+ targetWidth?: number;
8
+ delayIn?: number;
9
+ delayOut?: number;
10
+ children: Snippet<[
11
+ {
20
12
  isExpanded: boolean;
21
13
  isExpanding: boolean;
22
14
  isShrinking: boolean;
23
15
  inTransition: boolean;
24
- };
25
- };
26
- exports?: {} | undefined;
27
- bindings?: string | undefined;
28
- };
29
- export type HoverExpandableWidthProps = typeof __propDef.props;
30
- export type HoverExpandableWidthEvents = typeof __propDef.events;
31
- export type HoverExpandableWidthSlots = typeof __propDef.slots;
32
- export default class HoverExpandableWidth extends SvelteComponent<HoverExpandableWidthProps, HoverExpandableWidthEvents, HoverExpandableWidthSlots> {
16
+ }
17
+ ]>;
33
18
  }
34
- export {};
19
+ declare const HoverExpandableWidth: import("svelte").Component<Props, {}, "">;
20
+ type HoverExpandableWidth = ReturnType<typeof HoverExpandableWidth>;
21
+ export default HoverExpandableWidth;
@@ -0,0 +1 @@
1
+ export { default as HoverExpandableWidth } from "./HoverExpandableWidth.svelte";
@@ -0,0 +1 @@
1
+ export { default as HoverExpandableWidth } from "./HoverExpandableWidth.svelte";