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