@space-man/react-theme-animation 2.1.0 → 2.3.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.
Files changed (68) hide show
  1. package/README.md +72 -142
  2. package/dist/core/index.cjs +74 -0
  3. package/dist/core/index.cjs.map +1 -0
  4. package/dist/{esm/types/index.d.ts → core/index.d.cts} +26 -8
  5. package/dist/{cjs/types → core}/index.d.ts +26 -8
  6. package/dist/core/index.js +66 -0
  7. package/dist/core/index.js.map +1 -0
  8. package/dist/index.cjs +1756 -0
  9. package/dist/index.cjs.map +1 -0
  10. package/dist/index.d.cts +4 -0
  11. package/dist/index.d.ts +4 -0
  12. package/dist/index.js +1706 -0
  13. package/dist/index.js.map +1 -0
  14. package/dist/react/index.cjs +1742 -0
  15. package/dist/react/index.cjs.map +1 -0
  16. package/dist/react/index.d.cts +224 -0
  17. package/dist/react/index.d.ts +224 -0
  18. package/dist/react/index.js +1697 -0
  19. package/dist/react/index.js.map +1 -0
  20. package/dist/tanstack/index.cjs +34 -0
  21. package/dist/tanstack/index.cjs.map +1 -0
  22. package/dist/tanstack/index.d.cts +20 -0
  23. package/dist/tanstack/index.d.ts +20 -0
  24. package/dist/tanstack/index.js +27 -0
  25. package/dist/tanstack/index.js.map +1 -0
  26. package/package.json +66 -37
  27. package/dist/cjs/components/NextThemeProvider.d.ts +0 -81
  28. package/dist/cjs/components/NextThemeProvider.js +0 -223
  29. package/dist/cjs/components/SpacemanThemeProvider.d.ts +0 -57
  30. package/dist/cjs/components/SpacemanThemeProvider.js +0 -113
  31. package/dist/cjs/components/TanStackThemeProvider.d.ts +0 -68
  32. package/dist/cjs/components/TanStackThemeProvider.js +0 -183
  33. package/dist/cjs/components/ThemeSelector.d.ts +0 -3
  34. package/dist/cjs/components/ThemeSelector.js +0 -39
  35. package/dist/cjs/components/ThemeSwitcher.d.ts +0 -3
  36. package/dist/cjs/components/ThemeSwitcher.js +0 -81
  37. package/dist/cjs/components/ViteThemeProvider.d.ts +0 -61
  38. package/dist/cjs/components/ViteThemeProvider.js +0 -140
  39. package/dist/cjs/components/ui/select.d.ts +0 -15
  40. package/dist/cjs/components/ui/select.js +0 -83
  41. package/dist/cjs/hooks/use-theme-animation.d.ts +0 -2
  42. package/dist/cjs/hooks/use-theme-animation.js +0 -234
  43. package/dist/cjs/index.d.ts +0 -10
  44. package/dist/cjs/index.js +0 -30
  45. package/dist/cjs/types/index.js +0 -9
  46. package/dist/cjs/utils/animations.d.ts +0 -21
  47. package/dist/cjs/utils/animations.js +0 -189
  48. package/dist/esm/components/NextThemeProvider.d.ts +0 -81
  49. package/dist/esm/components/NextThemeProvider.js +0 -185
  50. package/dist/esm/components/SpacemanThemeProvider.d.ts +0 -57
  51. package/dist/esm/components/SpacemanThemeProvider.js +0 -108
  52. package/dist/esm/components/TanStackThemeProvider.d.ts +0 -68
  53. package/dist/esm/components/TanStackThemeProvider.js +0 -178
  54. package/dist/esm/components/ThemeSelector.d.ts +0 -3
  55. package/dist/esm/components/ThemeSelector.js +0 -35
  56. package/dist/esm/components/ThemeSwitcher.d.ts +0 -3
  57. package/dist/esm/components/ThemeSwitcher.js +0 -77
  58. package/dist/esm/components/ViteThemeProvider.d.ts +0 -61
  59. package/dist/esm/components/ViteThemeProvider.js +0 -135
  60. package/dist/esm/components/ui/select.d.ts +0 -15
  61. package/dist/esm/components/ui/select.js +0 -39
  62. package/dist/esm/hooks/use-theme-animation.d.ts +0 -2
  63. package/dist/esm/hooks/use-theme-animation.js +0 -230
  64. package/dist/esm/index.d.ts +0 -10
  65. package/dist/esm/index.js +0 -10
  66. package/dist/esm/types/index.js +0 -6
  67. package/dist/esm/utils/animations.d.ts +0 -21
  68. package/dist/esm/utils/animations.js +0 -177
@@ -1,177 +0,0 @@
1
- const isBrowser = typeof window !== 'undefined';
2
- export const injectBaseStyles = () => {
3
- if (isBrowser) {
4
- const styleId = 'spaceman-theme-base-style';
5
- if (!document.getElementById(styleId)) {
6
- const style = document.createElement('style');
7
- style.id = styleId;
8
- const isHighResolution = window.innerWidth >= 3000 || window.innerHeight >= 2000;
9
- style.textContent = `
10
- ::view-transition-old(root),
11
- ::view-transition-new(root) {
12
- animation: none;
13
- mix-blend-mode: normal;
14
- ${isHighResolution ? 'transform: translateZ(0);' : ''}
15
- }
16
-
17
- ${isHighResolution
18
- ? `
19
- ::view-transition-group(root),
20
- ::view-transition-image-pair(root),
21
- ::view-transition-old(root),
22
- ::view-transition-new(root) {
23
- backface-visibility: hidden;
24
- perspective: 1000px;
25
- transform: translate3d(0, 0, 0);
26
- }
27
- `
28
- : ''}
29
- `;
30
- document.head.appendChild(style);
31
- }
32
- }
33
- };
34
- export const createBlurCircleMask = (blur) => {
35
- const isHighResolution = isBrowser && (window.innerWidth >= 3000 || window.innerHeight >= 2000);
36
- const blurFilter = `<filter id="blur"><feGaussianBlur stdDeviation="${blur}" /></filter>`;
37
- const circleRadius = isHighResolution ? 20 : 25;
38
- 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>')`;
39
- };
40
- export const getSystemTheme = () => {
41
- if (!isBrowser)
42
- return 'light';
43
- return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
44
- };
45
- export const resolveTheme = (theme) => {
46
- if (theme === 'system') {
47
- return getSystemTheme();
48
- }
49
- return theme === 'dark' ? 'dark' : 'light';
50
- };
51
- export const supportsViewTransitions = () => {
52
- return isBrowser && 'startViewTransition' in document;
53
- };
54
- export const prefersReducedMotion = () => {
55
- return isBrowser && window.matchMedia('(prefers-reduced-motion: reduce)').matches;
56
- };
57
- export const createCircleAnimation = (config) => {
58
- const { x, y, duration, easing } = config;
59
- // Calculate the distance to each corner of the viewport
60
- const topLeft = Math.hypot(x, y);
61
- const topRight = Math.hypot(window.innerWidth - x, y);
62
- const bottomLeft = Math.hypot(x, window.innerHeight - y);
63
- const bottomRight = Math.hypot(window.innerWidth - x, window.innerHeight - y);
64
- // Find the maximum distance to ensure animation covers the entire viewport
65
- const maxRadius = Math.max(topLeft, topRight, bottomLeft, bottomRight);
66
- document.documentElement.animate({
67
- clipPath: [`circle(0px at ${x}px ${y}px)`, `circle(${maxRadius}px at ${x}px ${y}px)`],
68
- }, {
69
- duration,
70
- easing,
71
- pseudoElement: '::view-transition-new(root)',
72
- });
73
- };
74
- export const createSlideAnimation = (config) => {
75
- const { a = -100, b = 0, x = 0, y = 0, duration, styleId } = config;
76
- const styleElement = document.createElement('style');
77
- styleElement.id = styleId;
78
- styleElement.textContent = `
79
- ::view-transition-old(root) {
80
- animation-delay: ${duration}ms;
81
- }
82
-
83
- ::view-transition-new(root) {
84
- animation: move-in ${duration}ms;
85
- animation-timing-function: cubic-bezier(0.66, 0, 0.34, 1);
86
- }
87
-
88
- @keyframes move-in {
89
- from {
90
- translate: ${a}% ${b}%;
91
- }
92
- to {
93
- translate: ${x}% ${y}%;
94
- }
95
- }
96
- `;
97
- document.head.appendChild(styleElement);
98
- // Clean up after animation
99
- setTimeout(() => {
100
- const styleElement = document.getElementById(styleId);
101
- if (styleElement) {
102
- styleElement.remove();
103
- }
104
- }, duration);
105
- };
106
- export const createBlurCircleAnimation = (config) => {
107
- const { x, y, duration, easing, blurAmount, styleId } = config;
108
- const existingStyle = document.getElementById(styleId);
109
- if (existingStyle) {
110
- existingStyle.remove();
111
- }
112
- const viewportSize = Math.max(window.innerWidth, window.innerHeight) + 200;
113
- const isHighResolution = window.innerWidth >= 3000 || window.innerHeight >= 2000;
114
- const scaleFactor = isHighResolution ? 2.5 : 4;
115
- const optimalMaskSize = isHighResolution
116
- ? Math.min(viewportSize * scaleFactor, 5000)
117
- : viewportSize * scaleFactor;
118
- const topLeft = Math.hypot(x, y);
119
- const topRight = Math.hypot(window.innerWidth - x, y);
120
- const bottomLeft = Math.hypot(x, window.innerHeight - y);
121
- const bottomRight = Math.hypot(window.innerWidth - x, window.innerHeight - y);
122
- const maxRadius = Math.max(topLeft, topRight, bottomLeft, bottomRight);
123
- const styleElement = document.createElement('style');
124
- styleElement.id = styleId;
125
- const blurFactor = isHighResolution ? 1.5 : 1.2;
126
- const finalMaskSize = Math.max(optimalMaskSize, maxRadius * 2.5);
127
- styleElement.textContent = `
128
- ::view-transition-group(root) {
129
- animation-duration: ${duration}ms;
130
- animation-timing-function: ${isHighResolution
131
- ? 'cubic-bezier(0.2, 0, 0.2, 1)'
132
- : 'linear(' +
133
- '0 0%, 0.2342 12.49%, 0.4374 24.99%,' +
134
- '0.6093 37.49%, 0.6835 43.74%,' +
135
- '0.7499 49.99%, 0.8086 56.25%,' +
136
- '0.8593 62.5%, 0.9023 68.75%, 0.9375 75%,' +
137
- '0.9648 81.25%, 0.9844 87.5%,' +
138
- '0.9961 93.75%, 1 100%' +
139
- ')'};
140
- will-change: transform;
141
- }
142
-
143
- ::view-transition-new(root) {
144
- mask: ${createBlurCircleMask(blurAmount * blurFactor)} 0 0 / 100% 100% no-repeat;
145
- mask-position: ${x}px ${y}px;
146
- animation: spaceman-mask-scale ${duration}ms ${easing};
147
- transform-origin: ${x}px ${y}px;
148
- will-change: mask-size, mask-position;
149
- }
150
-
151
- ::view-transition-old(root),
152
- .dark::view-transition-old(root) {
153
- animation: spaceman-mask-scale ${duration}ms ${easing};
154
- transform-origin: ${x}px ${y}px;
155
- z-index: -1;
156
- will-change: mask-size, mask-position;
157
- }
158
-
159
- @keyframes spaceman-mask-scale {
160
- 0% {
161
- mask-size: 0px;
162
- mask-position: ${x}px ${y}px;
163
- }
164
- 100% {
165
- mask-size: ${finalMaskSize}px;
166
- mask-position: ${x - finalMaskSize / 2}px ${y - finalMaskSize / 2}px;
167
- }
168
- }
169
- `;
170
- document.head.appendChild(styleElement);
171
- setTimeout(() => {
172
- const styleElement = document.getElementById(styleId);
173
- if (styleElement) {
174
- styleElement.remove();
175
- }
176
- }, duration);
177
- };