uitheme-web 1.0.1 → 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,246 +1 @@
1
- // src/core/types.ts
2
- var ThemeAnimationType = /* @__PURE__ */ ((ThemeAnimationType2) => {
3
- ThemeAnimationType2["CIRCLE"] = "circle";
4
- ThemeAnimationType2["BLUR_CIRCLE"] = "blur-circle";
5
- ThemeAnimationType2["SLIDE"] = "slide";
6
- return ThemeAnimationType2;
7
- })(ThemeAnimationType || {});
8
-
9
- // src/core/constants.ts
10
- var STORAGE_KEY = "theme";
11
- var COLOR_STORAGE_KEY = "color-theme";
12
- var GLOBAL_CLASS_NAME = "dark";
13
- var COLOR_THEME_PREFIX = "theme-";
14
- var DEFAULT_DURATION = 750;
15
- var DEFAULT_EASING = "ease-in-out";
16
- var DEFAULT_BLUR_AMOUNT = 2;
17
- var DEFAULT_STYLE_ID = "ui-theme-style";
18
-
19
- // src/core/animations.ts
20
- var isBrowser = typeof window !== "undefined";
21
- var getIsHighResolution = () => {
22
- if (!isBrowser) return false;
23
- return window.innerWidth >= 3e3 || window.innerHeight >= 2e3;
24
- };
25
- var injectBaseStyles = () => {
26
- if (!isBrowser) return;
27
- const styleId = "ui-theme-base-style";
28
- if (document.getElementById(styleId)) return;
29
- const style = document.createElement("style");
30
- style.id = styleId;
31
- const isHighResolution = getIsHighResolution();
32
- style.textContent = `
33
- ::view-transition-old(root),
34
- ::view-transition-new(root) {
35
- animation: none;
36
- mix-blend-mode: normal;
37
- ${isHighResolution ? "transform: translateZ(0);" : ""}
38
- }
39
-
40
- ${isHighResolution ? `
41
- ::view-transition-group(root),
42
- ::view-transition-image-pair(root),
43
- ::view-transition-old(root),
44
- ::view-transition-new(root) {
45
- backface-visibility: hidden;
46
- perspective: 1000px;
47
- transform: translate3d(0, 0, 0);
48
- }
49
- ` : ""}
50
- `;
51
- document.head.appendChild(style);
52
- };
53
- var createBlurCircleMask = (blur) => {
54
- const isHighResolution = getIsHighResolution();
55
- const blurFilter = `<filter id="blur"><feGaussianBlur stdDeviation="${blur}" /></filter>`;
56
- const circleRadius = isHighResolution ? 20 : 25;
57
- return `url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="-50 -50 100 100"><defs>${blurFilter}</defs><circle cx="0" cy="0" r="${circleRadius}" fill="white" filter="url(%23blur)"/></svg>')`;
58
- };
59
- var getSystemTheme = () => {
60
- if (!isBrowser) return "light";
61
- return window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
62
- };
63
- var resolveTheme = (theme) => {
64
- if (theme === "system") {
65
- return getSystemTheme();
66
- }
67
- return theme === "dark" ? "dark" : "light";
68
- };
69
- var supportsViewTransitions = () => {
70
- return isBrowser && "startViewTransition" in document;
71
- };
72
- var prefersReducedMotion = () => {
73
- return isBrowser && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
74
- };
75
- var getSlideFromCoords = (direction) => {
76
- switch (direction) {
77
- case "left":
78
- return { a: -100, b: 0 };
79
- case "right":
80
- return { a: 100, b: 0 };
81
- case "top":
82
- return { a: 0, b: -100 };
83
- case "bottom":
84
- return { a: 0, b: 100 };
85
- case "top-left":
86
- return { a: -100, b: -100 };
87
- case "top-right":
88
- return { a: 100, b: -100 };
89
- case "bottom-left":
90
- return { a: -100, b: 100 };
91
- case "bottom-right":
92
- return { a: 100, b: 100 };
93
- default:
94
- return { a: -100, b: 0 };
95
- }
96
- };
97
- var createCircleAnimation = (config) => {
98
- const { x, y, duration, easing } = config;
99
- const topLeft = Math.hypot(x, y);
100
- const topRight = Math.hypot(window.innerWidth - x, y);
101
- const bottomLeft = Math.hypot(x, window.innerHeight - y);
102
- const bottomRight = Math.hypot(window.innerWidth - x, window.innerHeight - y);
103
- const maxRadius = Math.max(topLeft, topRight, bottomLeft, bottomRight);
104
- document.documentElement.animate(
105
- {
106
- clipPath: [
107
- `circle(0px at ${x}px ${y}px)`,
108
- `circle(${maxRadius}px at ${x}px ${y}px)`
109
- ]
110
- },
111
- {
112
- duration,
113
- easing,
114
- pseudoElement: "::view-transition-new(root)"
115
- }
116
- );
117
- };
118
- var createSlideAnimation = (config) => {
119
- const {
120
- a = -100,
121
- b = 0,
122
- x = 0,
123
- y = 0,
124
- duration,
125
- styleId = DEFAULT_STYLE_ID
126
- } = config;
127
- const styleElement = document.createElement("style");
128
- styleElement.id = styleId;
129
- styleElement.textContent = `
130
- ::view-transition-old(root) {
131
- animation-delay: ${duration}ms;
132
- }
133
-
134
- ::view-transition-new(root) {
135
- animation: move-in ${duration}ms;
136
- animation-timing-function: cubic-bezier(0.66, 0, 0.34, 1);
137
- }
138
-
139
- @keyframes move-in {
140
- from {
141
- translate: ${a}% ${b}%;
142
- }
143
- to {
144
- translate: ${x}% ${y}%;
145
- }
146
- }
147
- `;
148
- document.head.appendChild(styleElement);
149
- setTimeout(() => {
150
- const el = document.getElementById(styleId);
151
- if (el) {
152
- el.remove();
153
- }
154
- }, duration);
155
- };
156
- var createBlurCircleAnimation = (config) => {
157
- const {
158
- x,
159
- y,
160
- duration,
161
- easing,
162
- blurAmount,
163
- styleId = DEFAULT_STYLE_ID
164
- } = config;
165
- const existingStyle = document.getElementById(styleId);
166
- if (existingStyle) {
167
- existingStyle.remove();
168
- }
169
- const isHighResolution = getIsHighResolution();
170
- const viewportSize = Math.max(window.innerWidth, window.innerHeight) + 200;
171
- const scaleFactor = isHighResolution ? 2.5 : 4;
172
- const optimalMaskSize = isHighResolution ? Math.min(viewportSize * scaleFactor, 5e3) : viewportSize * scaleFactor;
173
- const topLeft = Math.hypot(x, y);
174
- const topRight = Math.hypot(window.innerWidth - x, y);
175
- const bottomLeft = Math.hypot(x, window.innerHeight - y);
176
- const bottomRight = Math.hypot(window.innerWidth - x, window.innerHeight - y);
177
- const maxRadius = Math.max(topLeft, topRight, bottomLeft, bottomRight);
178
- const styleElement = document.createElement("style");
179
- styleElement.id = styleId;
180
- const blurFactor = isHighResolution ? 1.5 : 1.2;
181
- const finalMaskSize = Math.max(optimalMaskSize, maxRadius * 2.5);
182
- styleElement.textContent = `
183
- ::view-transition-group(root) {
184
- animation-duration: ${duration}ms;
185
- animation-timing-function: ${isHighResolution ? "cubic-bezier(0.2, 0, 0.2, 1)" : "linear(0 0%, 0.2342 12.49%, 0.4374 24.99%,0.6093 37.49%, 0.6835 43.74%,0.7499 49.99%, 0.8086 56.25%,0.8593 62.5%, 0.9023 68.75%, 0.9375 75%,0.9648 81.25%, 0.9844 87.5%,0.9961 93.75%, 1 100%)"};
186
- will-change: transform;
187
- }
188
-
189
- ::view-transition-new(root) {
190
- mask: ${createBlurCircleMask(blurAmount * blurFactor)} 0 0 / 100% 100% no-repeat;
191
- mask-position: ${x}px ${y}px;
192
- animation: ui-theme-mask-scale ${duration}ms ${easing};
193
- transform-origin: ${x}px ${y}px;
194
- will-change: mask-size, mask-position;
195
- }
196
-
197
- ::view-transition-old(root),
198
- .dark::view-transition-old(root) {
199
- animation: ui-theme-mask-scale ${duration}ms ${easing};
200
- transform-origin: ${x}px ${y}px;
201
- z-index: -1;
202
- will-change: mask-size, mask-position;
203
- }
204
-
205
- @keyframes ui-theme-mask-scale {
206
- 0% {
207
- mask-size: 0px;
208
- mask-position: ${x}px ${y}px;
209
- }
210
- 100% {
211
- mask-size: ${finalMaskSize}px;
212
- mask-position: ${x - finalMaskSize / 2}px ${y - finalMaskSize / 2}px;
213
- }
214
- }
215
- `;
216
- document.head.appendChild(styleElement);
217
- setTimeout(() => {
218
- const el = document.getElementById(styleId);
219
- if (el) {
220
- el.remove();
221
- }
222
- }, duration);
223
- };
224
-
225
- // src/core/storage.ts
226
- var isBrowser2 = typeof window !== "undefined";
227
- var getStoredTheme = (key = STORAGE_KEY, validThemes = ["light", "dark", "system"], defaultTheme = "system") => {
228
- if (!isBrowser2) return defaultTheme;
229
- const saved = localStorage.getItem(key);
230
- return saved && validThemes.includes(saved) ? saved : defaultTheme;
231
- };
232
- var setStoredTheme = (theme, key = STORAGE_KEY) => {
233
- if (!isBrowser2) return;
234
- localStorage.setItem(key, theme);
235
- };
236
- var getStoredColorTheme = (key = COLOR_STORAGE_KEY, validColorThemes = ["default"], defaultColorTheme = "default") => {
237
- if (!isBrowser2) return defaultColorTheme;
238
- const saved = localStorage.getItem(key);
239
- return saved && validColorThemes.includes(saved) ? saved : defaultColorTheme;
240
- };
241
- var setStoredColorTheme = (colorTheme, key = COLOR_STORAGE_KEY) => {
242
- if (!isBrowser2) return;
243
- localStorage.setItem(key, colorTheme);
244
- };
245
-
246
- export { COLOR_STORAGE_KEY, COLOR_THEME_PREFIX, DEFAULT_BLUR_AMOUNT, DEFAULT_DURATION, DEFAULT_EASING, DEFAULT_STYLE_ID, GLOBAL_CLASS_NAME, STORAGE_KEY, ThemeAnimationType, createBlurCircleAnimation, createBlurCircleMask, createCircleAnimation, createSlideAnimation, getSlideFromCoords, getStoredColorTheme, getStoredTheme, getSystemTheme, injectBaseStyles, prefersReducedMotion, resolveTheme, setStoredColorTheme, setStoredTheme, supportsViewTransitions };
1
+ export{b as TRANSITION_DIRECTIONS,a as ThemeAnimationType,h as getStoredColorTheme,f as getStoredTheme,d as preloadThemeLogo,e as runThemeTransition,i as setStoredColorTheme,g as setStoredTheme}from'../chunk-DFJEYTIW.js';export{r as COLOR_STORAGE_KEY,t as COLOR_THEME_PREFIX,w as DEFAULT_BLUR_AMOUNT,u as DEFAULT_DURATION,v as DEFAULT_EASING,x as DEFAULT_STYLE_ID,s as GLOBAL_CLASS_NAME,q as STORAGE_KEY,p as createBlurCircleAnimation,b as createBlurCircleMask,n as createCircleAnimation,j as createClipPathAnimation,k as createPolygonGradientAnimation,o as createSlideAnimation,m as createSvgLogoAnimation,l as createTriangleAnimation,i as getAnimationPosition,h as getSlideFromCoords,c as getSystemTheme,a as injectBaseStyles,g as prefersReducedMotion,d as resolveTheme,f as supportsViewTransitions}from'../chunk-WFG34KG5.js';
@@ -0,0 +1,4 @@
1
+ /** Decode SVG assets before capture. A pending/failed asset never delays a toggle. */
2
+ declare const preloadThemeLogo: (url: string) => Promise<void>;
3
+
4
+ export { preloadThemeLogo as p };
@@ -0,0 +1,4 @@
1
+ /** Decode SVG assets before capture. A pending/failed asset never delays a toggle. */
2
+ declare const preloadThemeLogo: (url: string) => Promise<void>;
3
+
4
+ export { preloadThemeLogo as p };