lapikit 0.1.8 → 0.1.9

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,18 +1,36 @@
1
1
  <script lang="ts">
2
2
  import { BROWSER } from 'esm-env';
3
- import { modalOpen, setOpenModal, updateThemeStore } from '../../stores/index.js';
3
+ import {
4
+ colorSchemeSystem,
5
+ modalOpen,
6
+ setOpenModal,
7
+ updateThemeStore
8
+ } from '../../stores/index.js';
4
9
  import type { Snippet } from 'svelte';
5
10
  let { children }: { children: Snippet } = $props();
6
11
 
7
12
  $effect.pre(() => {
8
13
  if (!BROWSER) return;
14
+ // system
15
+ if (window.matchMedia) {
16
+ colorSchemeSystem.set(
17
+ window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light'
18
+ );
19
+ }
20
+
21
+ // listener
22
+ window
23
+ .matchMedia('(prefers-color-scheme: dark)')
24
+ .addEventListener('change', (event: MediaQueryListEvent) => {
25
+ colorSchemeSystem.set(event.matches ? 'dark' : 'light');
26
+ });
27
+
28
+ // local
9
29
  const local = localStorage.getItem('@lapikit/theme');
10
- if (local !== null) updateThemeStore(local as 'dark' | 'light' | 'auto');
30
+ if (local !== null) updateThemeStore(local as 'dark' | 'light' | 'system');
11
31
  });
12
32
  </script>
13
33
 
14
- {$modalOpen ? ($modalOpen === 'persistent' ? 'persistent' : 'true') : 'false'}
15
-
16
34
  {@render children?.()}
17
35
 
18
36
  <!-- svelte-ignore a11y_no_static_element_interactions -->
package/dist/preset.js CHANGED
@@ -35,7 +35,7 @@ export const config = {
35
35
  breakpoints: {
36
36
  mobileBreakpoint: 'sm',
37
37
  tabletBreakpoint: 'md',
38
- laptopBreakpoint: 'xl',
38
+ laptopBreakpoint: 'lg',
39
39
  thresholds: {
40
40
  _default: 0, // 0px
41
41
  xs: '28rem', //448px
@@ -1,9 +1,10 @@
1
1
  import { type Writable } from 'svelte/store';
2
- export declare const colorScheme: Writable<'auto' | 'dark' | 'light'>;
2
+ export declare const colorScheme: Writable<'system' | 'dark' | 'light'>;
3
+ export declare const colorSchemeSystem: Writable<'dark' | 'light'>;
3
4
  export declare const modalOpen: Writable<boolean | 'persistent'>;
4
5
  export declare const modalStack: Writable<string[]>;
5
- export declare function updateThemeStore(update: 'auto' | 'dark' | 'light'): void;
6
- export declare function setColorScheme(scheme: 'auto' | 'dark' | 'light'): void;
6
+ export declare function updateThemeStore(update: 'system' | 'dark' | 'light'): void;
7
+ export declare function setColorScheme(scheme: 'system' | 'dark' | 'light'): void;
7
8
  export declare function setOpenModal(state: boolean | 'persistent'): void;
8
9
  export declare const pushModal: (id: string) => void;
9
10
  export declare const popModal: (id: string) => void;
@@ -1,17 +1,18 @@
1
1
  import { disabledScroll } from '../internal/scroll.js';
2
2
  import { writable } from 'svelte/store';
3
3
  // states
4
- const colorScheme_default = 'light';
4
+ const colorScheme_default = 'system';
5
5
  const modalOpen_default = false;
6
6
  const isBrowser = typeof window !== 'undefined';
7
7
  export const colorScheme = writable(colorScheme_default);
8
+ export const colorSchemeSystem = writable('light');
8
9
  export const modalOpen = writable(modalOpen_default);
9
10
  export const modalStack = writable([]);
10
11
  export function updateThemeStore(update) {
11
12
  colorScheme.update(() => {
12
13
  if (isBrowser) {
13
14
  const ref = document.documentElement.classList;
14
- if (update === 'auto')
15
+ if (update === 'system')
15
16
  ref.remove('light', 'dark');
16
17
  else {
17
18
  ref.remove(update === 'dark' ? 'light' : 'dark');
@@ -6,12 +6,12 @@ export const devices = (config) => {
6
6
  tablet: config.breakpoints.tabletBreakpoint,
7
7
  laptop: config.breakpoints.laptopBreakpoint
8
8
  };
9
- css += `@media screen and (max-width: ${setUnit(config.breakpoints.thresholds[list.tablet])}) {\n`;
9
+ css += `@media screen and (max-width: ${setUnit(config.breakpoints.thresholds[list.mobile])}) {\n`;
10
10
  css += `.hidden-mobile {\n`;
11
11
  css += `display: none !important;\n`;
12
12
  css += `}\n`;
13
13
  css += `}\n`;
14
- css += `@media screen and (min-width: ${setUnit(config.breakpoints.thresholds[list.tablet])}) {\n`;
14
+ css += `@media screen and (min-width: ${setUnit(config.breakpoints.thresholds[list.mobile])}) {\n`;
15
15
  css += `.display-mobile {\n`;
16
16
  css += `display: none !important;\n`;
17
17
  css += `}\n`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lapikit",
3
- "version": "0.1.8",
3
+ "version": "0.1.9",
4
4
  "license": "MIT",
5
5
  "publishConfig": {
6
6
  "access": "public"