@marianmeres/stuic 1.0.3 → 1.2.0

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.
@@ -1,3 +1,13 @@
1
+ <script context="module">export const appShellSetHtmlBodyHeight = () => {
2
+ const _set = (flag) => {
3
+ document.body.style.height = flag ? "100vh" : "auto";
4
+ document.body.style.overflow = flag ? "hidden" : "visible";
5
+ };
6
+ _set(true);
7
+ return () => _set(false);
8
+ };
9
+ </script>
10
+
1
11
  <script>import { createEventDispatcher } from "svelte";
2
12
  import { twMerge } from "tailwind-merge";
3
13
  const dispatch = createEventDispatcher();
@@ -193,9 +203,4 @@ Then update your global stylesheet with the following. This will disable overflo
193
203
  html and body tags to prevent duplicate scroll bars.
194
204
 
195
205
  html, body { @apply h-full overflow-hidden; }
196
- */
197
- :global(html),
198
- :global(body) {
199
- height: 100vh !important;
200
- overflow: hidden !important;
201
- }</style>
206
+ */</style>
@@ -1,4 +1,5 @@
1
1
  import { SvelteComponent } from "svelte";
2
+ export declare const appShellSetHtmlBodyHeight: () => (() => any);
2
3
  declare const __propDef: {
3
4
  props: {
4
5
  class?: string | undefined;
@@ -0,0 +1,11 @@
1
+ <!--
2
+ Similar to PrefersColorScheme, except that it never reads window.matchMedia and only
3
+ relies on the local userland setting
4
+ -->
5
+ <svelte:head>
6
+ <script>
7
+ const KEY = 'color-scheme';
8
+ const cls = window.document.documentElement.classList;
9
+ localStorage.getItem(KEY) === 'dark' ? cls.add('dark') : cls.remove('dark');
10
+ </script>
11
+ </svelte:head>
@@ -0,0 +1,23 @@
1
+ /** @typedef {typeof __propDef.props} LocalColorSchemeProps */
2
+ /** @typedef {typeof __propDef.events} LocalColorSchemeEvents */
3
+ /** @typedef {typeof __propDef.slots} LocalColorSchemeSlots */
4
+ export default class LocalColorScheme extends SvelteComponent<{
5
+ [x: string]: never;
6
+ }, {
7
+ [evt: string]: CustomEvent<any>;
8
+ }, {}> {
9
+ }
10
+ export type LocalColorSchemeProps = typeof __propDef.props;
11
+ export type LocalColorSchemeEvents = typeof __propDef.events;
12
+ export type LocalColorSchemeSlots = typeof __propDef.slots;
13
+ import { SvelteComponent } from "svelte";
14
+ declare const __propDef: {
15
+ props: {
16
+ [x: string]: never;
17
+ };
18
+ events: {
19
+ [evt: string]: CustomEvent<any>;
20
+ };
21
+ slots: {};
22
+ };
23
+ export {};
@@ -0,0 +1,14 @@
1
+ <!--
2
+ If you do not wish to take the system preference into account use LocalColorScheme sibling
3
+ -->
4
+ <svelte:head>
5
+ <script>
6
+ const KEY = 'color-scheme';
7
+ const cls = window.document.documentElement.classList;
8
+ if (KEY in localStorage) {
9
+ localStorage.getItem(KEY) === 'dark' ? cls.add('dark') : cls.remove('dark');
10
+ } else if (window.matchMedia('(prefers-color-scheme: dark)').matches) {
11
+ cls.add('dark');
12
+ }
13
+ </script>
14
+ </svelte:head>
@@ -0,0 +1,23 @@
1
+ /** @typedef {typeof __propDef.props} SystemAwareColorSchemeProps */
2
+ /** @typedef {typeof __propDef.events} SystemAwareColorSchemeEvents */
3
+ /** @typedef {typeof __propDef.slots} SystemAwareColorSchemeSlots */
4
+ export default class SystemAwareColorScheme extends SvelteComponent<{
5
+ [x: string]: never;
6
+ }, {
7
+ [evt: string]: CustomEvent<any>;
8
+ }, {}> {
9
+ }
10
+ export type SystemAwareColorSchemeProps = typeof __propDef.props;
11
+ export type SystemAwareColorSchemeEvents = typeof __propDef.events;
12
+ export type SystemAwareColorSchemeSlots = typeof __propDef.slots;
13
+ import { SvelteComponent } from "svelte";
14
+ declare const __propDef: {
15
+ props: {
16
+ [x: string]: never;
17
+ };
18
+ events: {
19
+ [evt: string]: CustomEvent<any>;
20
+ };
21
+ slots: {};
22
+ };
23
+ export {};
@@ -0,0 +1,10 @@
1
+ export declare class ColorScheme {
2
+ static readonly KEY = "color-scheme";
3
+ static readonly DARK = "dark";
4
+ static readonly LIGHT = "light";
5
+ static getSystemValue: () => "dark" | "light";
6
+ static getLocalValue: (fallback?: string | null) => string | null;
7
+ static getValue: () => string | null;
8
+ static toggle: () => void;
9
+ static reset: () => void;
10
+ }
@@ -0,0 +1,18 @@
1
+ export class ColorScheme {
2
+ static KEY = 'color-scheme';
3
+ static DARK = 'dark';
4
+ static LIGHT = 'light';
5
+ static getSystemValue = () => window?.matchMedia(`(prefers-color-scheme: ${ColorScheme.DARK})`).matches
6
+ ? ColorScheme.DARK
7
+ : ColorScheme.LIGHT;
8
+ static getLocalValue = (fallback = null) => localStorage?.getItem(ColorScheme.KEY) || fallback;
9
+ static getValue = () => ColorScheme.getLocalValue(ColorScheme.getSystemValue());
10
+ static toggle = () => {
11
+ // returns bool, indicating whether token is in the list after the call or not.
12
+ const isDark = window?.document.documentElement.classList.toggle(ColorScheme.DARK);
13
+ localStorage?.setItem(ColorScheme.KEY, isDark ? ColorScheme.DARK : ColorScheme.LIGHT);
14
+ };
15
+ static reset = () => {
16
+ localStorage?.removeItem(ColorScheme.KEY);
17
+ };
18
+ }
@@ -1,11 +1,11 @@
1
1
  <script context="module">import { createClog } from "@marianmeres/clog";
2
2
  import { createSwitchStore } from "@marianmeres/switch-store";
3
3
  import { createEventDispatcher } from "svelte";
4
- import { slide, fly } from "svelte/transition";
4
+ import { fly } from "svelte/transition";
5
5
  import { twMerge } from "tailwind-merge";
6
+ import { clickOutside } from "../../actions/click-outside.js";
6
7
  import { prefersReducedMotionStore } from "../../utils/prefers-reduced-motion.js";
7
8
  import Backdrop from "../Backdrop/Backdrop.svelte";
8
- import { clickOutside } from "../../actions/click-outside.js";
9
9
  export const createDrawerStore = (open = false) => createSwitchStore(open);
10
10
  </script>
11
11
 
@@ -36,8 +36,8 @@ const _presetsClsBackdrop = {
36
36
  const _presetsCls = {
37
37
  left: `w-full sm:w-[66vw] h-full`,
38
38
  right: `w-full sm:w-[66vw] h-full`,
39
- top: `w-full h-full sm:h-[66vh]`,
40
- bottom: `w-full h-full sm:h-[66vh]`
39
+ top: `w-full h-full sm:h-[66vh]`,
40
+ bottom: `w-full h-full sm:h-[66vh]`
41
41
  };
42
42
  $:
43
43
  _presetsAnim = {
@@ -52,12 +52,9 @@ $:
52
52
  dispatch("element", { drawer: el });
53
53
  </script>
54
54
 
55
- <!-- prettier-ignore -->
56
55
  {#if $drawer.isOpen}
57
56
  <Backdrop
58
- class={twMerge(`
59
- ${_presetsClsBackdrop[position] || ''} ${backdropClass}
60
- `.trim())}
57
+ class={twMerge(`${_presetsClsBackdrop[position] || ''} ${backdropClass}`)}
61
58
  on:escape
62
59
  on:click={(e) => dispatch('click_backdrop')}
63
60
  {fadeInDuration}
@@ -72,7 +69,7 @@ $:
72
69
  <div
73
70
  bind:this={el}
74
71
  on:click|stopPropagation
75
- aria-modal="true"
72
+ aria-modal="true"
76
73
  role="dialog"
77
74
  aria-labelledby={labelledby}
78
75
  aria-describedby={describedby}
@@ -80,7 +77,7 @@ $:
80
77
  duration: transitionEnabled ? transitionDuration : 0,
81
78
  ...(_presetsAnim[position] || {}),
82
79
  }}
83
- class={twMerge(`overflow-y-auto ${_presetsCls[position] || ''} ${_class}`.trim())}
80
+ class={twMerge(`overflow-y-auto ${_presetsCls[position] || ''} ${_class}`)}
84
81
  use:clickOutside={() => dispatch('click_outside')}
85
82
  >
86
83
  <slot />
@@ -0,0 +1,54 @@
1
+ <script>import { createEventDispatcher } from "svelte";
2
+ import { twMerge } from "tailwind-merge";
3
+ import { prefersReducedMotionStore } from "../../utils/prefers-reduced-motion.js";
4
+ const dispatch = createEventDispatcher();
5
+ export let position = "left";
6
+ export let expandsOn = "hover";
7
+ export let force = false;
8
+ let _class = "";
9
+ export { _class as class };
10
+ export let expandedClass = "";
11
+ const _presetsCls = {
12
+ left: `left-0`,
13
+ right: `right-0`,
14
+ top: `top-0`,
15
+ bottom: `bottom-0`
16
+ };
17
+ $:
18
+ _isExpanded = !!force;
19
+ const click = "click";
20
+ const hover = "hover";
21
+ const both = "both";
22
+ const _onHover = (flag) => {
23
+ if (force)
24
+ return _isExpanded = true;
25
+ if ([hover, both].includes(expandsOn))
26
+ _isExpanded = !!flag;
27
+ };
28
+ const _onClick = (e) => {
29
+ if (force)
30
+ return _isExpanded = true;
31
+ if ([click, both].includes(expandsOn))
32
+ _isExpanded = !_isExpanded;
33
+ };
34
+ $:
35
+ dispatch("expanded", _isExpanded);
36
+ </script>
37
+
38
+ <!-- svelte-ignore a11y-click-events-have-key-events a11y-no-static-element-interactions -->
39
+ <div
40
+ on:mouseenter={() => _onHover(true)}
41
+ on:mouseleave={() => _onHover(false)}
42
+ on:click={_onClick}
43
+ on:click
44
+ aria-expanded={_isExpanded}
45
+ class={twMerge(`
46
+ absolute w-full h-full flex flex-col
47
+ ${$prefersReducedMotionStore ? '' : 'transition-all'}
48
+ ${_presetsCls[position] || ''}
49
+ ${_class}
50
+ ${_isExpanded ? expandedClass : ''}
51
+ `)}
52
+ >
53
+ <slot isExpanded={_isExpanded} />
54
+ </div>
@@ -0,0 +1,27 @@
1
+ import { SvelteComponent } from "svelte";
2
+ declare const __propDef: {
3
+ props: {
4
+ position?: "left" | "top" | "right" | "bottom" | undefined;
5
+ expandsOn?: "click" | "hover" | "both" | undefined;
6
+ force?: boolean | undefined;
7
+ class?: string | undefined;
8
+ expandedClass?: string | undefined;
9
+ };
10
+ events: {
11
+ click: MouseEvent;
12
+ expanded: CustomEvent<any>;
13
+ } & {
14
+ [evt: string]: CustomEvent<any>;
15
+ };
16
+ slots: {
17
+ default: {
18
+ isExpanded: boolean;
19
+ };
20
+ };
21
+ };
22
+ export type ExpandableProps = typeof __propDef.props;
23
+ export type ExpandableEvents = typeof __propDef.events;
24
+ export type ExpandableSlots = typeof __propDef.slots;
25
+ export default class Expandable extends SvelteComponent<ExpandableProps, ExpandableEvents, ExpandableSlots> {
26
+ }
27
+ export {};
package/dist/index.d.ts CHANGED
@@ -1,6 +1,9 @@
1
- export { default as AppShell } from './components/AppShell/AppShell.svelte';
1
+ export { default as AppShell, appShellSetHtmlBodyHeight, } from './components/AppShell/AppShell.svelte';
2
2
  export { default as Backdrop, BackdropConfig, } from './components/Backdrop/Backdrop.svelte';
3
3
  export { default as Button, ButtonConfig } from './components/Button/Button.svelte';
4
- export { default as PrefersColorScheme, ColorScheme, } from './components/PrefersColorScheme/PrefersColorScheme.svelte';
4
+ export { default as SystemAwareColorScheme } from './components/ColorScheme/SystemAwareColorScheme.svelte';
5
+ export { default as LocalColorScheme } from './components/ColorScheme/LocalColorScheme.svelte';
6
+ export { ColorScheme } from './components/ColorScheme/color-scheme.js';
5
7
  export { default as Drawer, createDrawerStore } from './components/Drawer/Drawer.svelte';
8
+ export { default as Expandable } from './components/Expandable/Expandable.svelte';
6
9
  export { default as X } from './components/X/X.svelte';
package/dist/index.js CHANGED
@@ -1,14 +1,17 @@
1
1
  // Reexport your entry components here
2
2
  //
3
- export { default as AppShell } from './components/AppShell/AppShell.svelte';
3
+ export { default as AppShell, appShellSetHtmlBodyHeight, } from './components/AppShell/AppShell.svelte';
4
4
  //
5
5
  export { default as Backdrop, BackdropConfig, } from './components/Backdrop/Backdrop.svelte';
6
- // export { BackdropConfig } from './components/Backdrop/backdrop.js';
7
6
  //
8
7
  export { default as Button, ButtonConfig } from './components/Button/Button.svelte';
9
8
  //
10
- export { default as PrefersColorScheme, ColorScheme, } from './components/PrefersColorScheme/PrefersColorScheme.svelte';
9
+ export { default as SystemAwareColorScheme } from './components/ColorScheme/SystemAwareColorScheme.svelte';
10
+ export { default as LocalColorScheme } from './components/ColorScheme/LocalColorScheme.svelte';
11
+ export { ColorScheme } from './components/ColorScheme/color-scheme.js';
11
12
  //
12
13
  export { default as Drawer, createDrawerStore } from './components/Drawer/Drawer.svelte';
13
14
  //
15
+ export { default as Expandable } from './components/Expandable/Expandable.svelte';
16
+ //
14
17
  export { default as X } from './components/X/X.svelte';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@marianmeres/stuic",
3
- "version": "1.0.3",
3
+ "version": "1.2.0",
4
4
  "scripts": {
5
5
  "dev": "vite dev",
6
6
  "build": "vite build && npm run package",
@@ -13,8 +13,8 @@
13
13
  "lint": "prettier --check .",
14
14
  "format": "prettier --write .",
15
15
  "prettier": "npm run format",
16
- "release:minor": "release -v minor",
17
- "release": "release -v patch"
16
+ "release:patch": "release -v patch",
17
+ "release": "release -v minor"
18
18
  },
19
19
  "exports": {
20
20
  ".": {
@@ -1,28 +0,0 @@
1
- <script context="module">export class ColorScheme {
2
- static KEY = "color-scheme";
3
- static getSystemValue = () => window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
4
- static getLocalValue = () => localStorage.getItem(ColorScheme.KEY);
5
- static getValue = () => {
6
- return ColorScheme.KEY in localStorage ? localStorage.getItem(ColorScheme.KEY) : ColorScheme.getSystemValue();
7
- };
8
- static toggle = () => {
9
- const isDark = window.document.documentElement.classList.toggle("dark");
10
- localStorage.setItem(ColorScheme.KEY, isDark ? "dark" : "light");
11
- };
12
- static reset = () => {
13
- localStorage.removeItem(ColorScheme.KEY);
14
- };
15
- }
16
- </script>
17
-
18
- <svelte:head>
19
- <script>
20
- const KEY = 'color-scheme';
21
- const cls = window.document.documentElement.classList;
22
- if (KEY in localStorage) {
23
- localStorage.getItem(KEY) === 'dark' ? cls.add('dark') : cls.remove('dark');
24
- } else if (window.matchMedia('(prefers-color-scheme: dark)').matches) {
25
- cls.add('dark');
26
- }
27
- </script>
28
- </svelte:head>
@@ -1,22 +0,0 @@
1
- import { SvelteComponent } from "svelte";
2
- export declare class ColorScheme {
3
- static readonly KEY = "color-scheme";
4
- static getSystemValue: () => "dark" | "light";
5
- static getLocalValue: () => string | null;
6
- static getValue: () => string | null;
7
- static toggle: () => void;
8
- static reset: () => void;
9
- }
10
- declare const __propDef: {
11
- props: Record<string, never>;
12
- events: {
13
- [evt: string]: CustomEvent<any>;
14
- };
15
- slots: {};
16
- };
17
- export type PrefersColorSchemeProps = typeof __propDef.props;
18
- export type PrefersColorSchemeEvents = typeof __propDef.events;
19
- export type PrefersColorSchemeSlots = typeof __propDef.slots;
20
- export default class PrefersColorScheme extends SvelteComponent<PrefersColorSchemeProps, PrefersColorSchemeEvents, PrefersColorSchemeSlots> {
21
- }
22
- export {};