svelte-os-themes 3.0.0 → 4.0.1

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 CHANGED
@@ -24,8 +24,7 @@ npm install svelte-os-themes
24
24
  storageKey="theme"
25
25
  colorScheme={true}
26
26
  system={true}
27
- styleNonce=""
28
- scriptNonce=""
27
+ nonce=""
29
28
  >
30
29
  {@render children()}
31
30
  </ThemeProvider>
@@ -108,16 +107,9 @@ npm install svelte-os-themes
108
107
  accepted values: `true`, `false`<br/>
109
108
  default value: `true`
110
109
 
111
- - `scriptNonce`
110
+ - `nonce`
112
111
 
113
- The nonce to use for the injected script.
114
-
115
- accepted values: `<string>`<br/>
116
- default value: `undefined`
117
-
118
- - `styleNonce`
119
-
120
- The nonce to use for the injected style.
112
+ The nonce to use for the injected script and transition-suppression style.
121
113
 
122
114
  accepted values: `<string>`<br/>
123
115
  default value: `undefined`
@@ -14,14 +14,10 @@ let {children, ...props}: ThemeProviderProps = $props();
14
14
 
15
15
  let theme = createTheme(() => props);
16
16
  let script = createTheme.script(() => props);
17
- let style = createTheme.style(() => props);
18
17
 
19
18
  setThemeContext(theme);
20
19
  </script>
21
20
 
22
- <svelte:head>
23
- {@html style.value}
24
- {@html script.value}
25
- </svelte:head>
21
+ <svelte:head>{@html script.current}</svelte:head>
26
22
 
27
23
  {@render children?.()}
@@ -25,8 +25,7 @@ export interface CreateThemeOptions {
25
25
  * @default true
26
26
  */
27
27
  colorScheme?: boolean;
28
- styleNonce?: string;
29
- scriptNonce?: string;
28
+ nonce?: string;
30
29
  }
31
30
  export interface CreateThemeReturn {
32
31
  get current(): Theme;
@@ -34,10 +33,7 @@ export interface CreateThemeReturn {
34
33
  }
35
34
  export declare function createTheme(options: CreateThemeOptions | (() => CreateThemeOptions)): CreateThemeReturn;
36
35
  export declare namespace createTheme {
37
- var style: (props: CreateThemeOptions | (() => CreateThemeOptions)) => {
38
- readonly value: string;
39
- };
40
36
  var script: (props: CreateThemeOptions | (() => CreateThemeOptions)) => {
41
- readonly value: string;
37
+ readonly current: string;
42
38
  };
43
39
  }
@@ -14,13 +14,19 @@ export function createTheme(options) {
14
14
  ...userOptions,
15
15
  };
16
16
  });
17
- let theme = $state(options_.fallback);
18
- $effect(() => {
17
+ let theme = $derived(options_.fallback);
18
+ $effect.pre(() => {
19
19
  theme = parseTheme(window.localStorage.getItem(options_.storageKey), options_.fallback);
20
20
  });
21
21
  $effect(() => {
22
22
  const html = document.documentElement;
23
- html.classList.add('svelte-os-themes__no-transition');
23
+ const head = document.head;
24
+ const style = document.createElement('style');
25
+ if (options_.nonce) {
26
+ style.setAttribute('nonce', options_.nonce);
27
+ }
28
+ style.appendChild(document.createTextNode(`*,*::before,*::after{-webkit-transition:none!important;-moz-transition:none!important;-o-transition:none!important;-ms-transition:none!important;transition:none!important}`));
29
+ head.appendChild(style);
24
30
  const originalTheme = theme;
25
31
  const resolvedTheme = originalTheme === 'system'
26
32
  ? window.matchMedia('(prefers-color-scheme: dark)').matches
@@ -35,11 +41,12 @@ export function createTheme(options) {
35
41
  else {
36
42
  html.setAttribute(options_.attribute, resolvedTheme);
37
43
  }
38
- if (options_.colorScheme)
44
+ if (options_.colorScheme) {
39
45
  html.style.colorScheme = resolvedTheme;
46
+ }
40
47
  window.localStorage.setItem(options_.storageKey, originalTheme);
41
48
  setTimeout(() => {
42
- html.classList.remove('svelte-os-themes__no-transition');
49
+ head.removeChild(style);
43
50
  }, 1);
44
51
  });
45
52
  $effect(() => {
@@ -79,33 +86,6 @@ export function createTheme(options) {
79
86
  },
80
87
  };
81
88
  }
82
- createTheme.style = (props) => {
83
- const options_ = $derived.by(() => {
84
- const userOptions = typeof props === 'function' ? props() : props;
85
- return {
86
- ...defaultOptions,
87
- ...userOptions,
88
- };
89
- });
90
- const value = $derived(`
91
- <style ${assignNonce(options_.styleNonce)}>
92
- .svelte-os-themes__no-transition,
93
- .svelte-os-themes__no-transition *,
94
- .svelte-os-themes__no-transition *::after,
95
- .svelte-os-themes__no-transition *::before {
96
- -webkit-transition: none !important;
97
- -moz-transition: none !important;
98
- -o-transition: none !important;
99
- transition: none !important;
100
- }
101
- </style>
102
- `);
103
- return {
104
- get value() {
105
- return value;
106
- },
107
- };
108
- };
109
89
  createTheme.script = (props) => {
110
90
  const options_ = $derived.by(() => {
111
91
  const userOptions = typeof props === 'function' ? props() : props;
@@ -115,10 +95,9 @@ createTheme.script = (props) => {
115
95
  };
116
96
  });
117
97
  const value = $derived(`
118
- <script ${assignNonce(options_.scriptNonce)}>
119
- (function(k, a, f, c) {
98
+ <script ${options_.nonce ? `nonce="${options_.nonce}"` : ''}>(function(k, a, f, c) {
120
99
  const h = document.documentElement;
121
- const q = window.matchMedia('(prefers-color-scheme: dark)')
100
+ const q = window.matchMedia('(prefers-color-scheme: dark)');
122
101
  const s = window.localStorage.getItem(k)?.toLowerCase().trim();
123
102
 
124
103
  const l = [
@@ -144,14 +123,16 @@ createTheme.script = (props) => {
144
123
  '${options_.storageKey}',
145
124
  '${options_.attribute}',
146
125
  '${options_.fallback}',
147
- ${options_.colorScheme},
126
+ ${options_.colorScheme}
148
127
  );
149
128
  </script>
150
- `);
129
+ `
130
+ .replace(/\n+/g, '')
131
+ .replace(/\s+/g, ' ')
132
+ .trim());
151
133
  return {
152
- get value() {
134
+ get current() {
153
135
  return value;
154
136
  },
155
137
  };
156
138
  };
157
- const assignNonce = (nonce) => (nonce ? `nonce="${nonce}"` : '');
package/dist/types.d.ts CHANGED
@@ -1 +1 @@
1
- export type Theme = "dark" | "light" | "system";
1
+ export type Theme = 'dark' | 'light' | 'system';
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "svelte-os-themes",
3
3
  "type": "module",
4
4
  "license": "MIT",
5
- "version": "3.0.0",
5
+ "version": "4.0.1",
6
6
  "main": "./dist/index.js",
7
7
  "svelte": "./dist/index.js",
8
8
  "types": "./dist/index.d.ts",
@@ -37,7 +37,7 @@
37
37
  "name": "John Paul Calvo",
38
38
  "email": "looselytiedshoelace@gmail.com"
39
39
  },
40
- "packageManager": "pnpm@10.30.3",
40
+ "packageManager": "pnpm@10.32.1",
41
41
  "scripts": {
42
42
  "dev": "vite dev",
43
43
  "build": "vite build && npm run package",
@@ -49,24 +49,24 @@
49
49
  "release": "release-it"
50
50
  },
51
51
  "devDependencies": {
52
- "@biomejs/biome": "^2.4.6",
52
+ "@biomejs/biome": "^2.4.8",
53
53
  "@eslint/js": "^10.0.1",
54
54
  "@sveltejs/adapter-vercel": "^6.3.3",
55
- "@sveltejs/kit": "^2.53.4",
55
+ "@sveltejs/kit": "^2.55.0",
56
56
  "@sveltejs/package": "^2.5.7",
57
- "@sveltejs/vite-plugin-svelte": "^6.2.4",
58
- "@tailwindcss/vite": "^4.2.1",
57
+ "@sveltejs/vite-plugin-svelte": "^7.0.0",
58
+ "@tailwindcss/vite": "^4.2.2",
59
59
  "publint": "^0.3.18",
60
60
  "release-it": "^19.2.4",
61
- "svelte": "^5.53.7",
62
- "svelte-check": "^4.4.4",
63
- "tailwindcss": "^4.2.1",
61
+ "svelte": "^5.55.0",
62
+ "svelte-check": "^4.4.5",
63
+ "tailwindcss": "^4.2.2",
64
64
  "tslib": "^2.8.1",
65
- "typescript": "^5.9.3",
66
- "vite": "^7.3.1"
65
+ "typescript": "^6.0.2",
66
+ "vite": "^8.0.2"
67
67
  },
68
68
  "peerDependencies": {
69
- "svelte": "^5.0.0"
69
+ "svelte": "^5.40.0"
70
70
  },
71
71
  "release-it": {
72
72
  "git": {