@baybreezy/docd 0.3.3 → 0.3.5

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.
@@ -25,8 +25,33 @@
25
25
  <script lang="ts" setup>
26
26
  import { buttonStyles } from "../Ui/Button.vue";
27
27
 
28
+ type ThemeTransitionVariant =
29
+ | "circle"
30
+ | "square"
31
+ | "triangle"
32
+ | "diamond"
33
+ | "hexagon"
34
+ | "rectangle"
35
+ | "star";
36
+
37
+ const props = withDefaults(
38
+ defineProps<{
39
+ duration?: number;
40
+ variant?: ThemeTransitionVariant;
41
+ /** When true, the transition expands from the viewport center instead of the button center. */
42
+ fromCenter?: boolean;
43
+ }>(),
44
+ {
45
+ duration: 400,
46
+ variant: "circle",
47
+ fromCenter: false,
48
+ }
49
+ );
50
+
28
51
  const colorMode = useColorMode();
29
- const buttonRef = useTemplateRef("toggler");
52
+ const toggler = useTemplateRef("toggler");
53
+ const { width: viewportWidthRef, height: viewportHeightRef } = useWindowSize();
54
+
30
55
  const iconName = computed(() => {
31
56
  switch (colorMode.value) {
32
57
  case "light":
@@ -38,49 +63,214 @@
38
63
  }
39
64
  });
40
65
 
41
- const props = withDefaults(
42
- defineProps<{
43
- duration?: number;
44
- }>(),
45
- {
46
- duration: 400,
66
+ // CSS custom properties driving the ::view-transition-group/new(root) rules below.
67
+ const vtDuration = useCssVar("--theme-toggle-vt-duration");
68
+ const vtClipFrom = useCssVar("--theme-vt-clip-from");
69
+
70
+ let isTransitioning = false;
71
+ let activeAnimation: Animation | null = null;
72
+
73
+ function cancelAnimation() {
74
+ activeAnimation?.cancel();
75
+ activeAnimation = null;
76
+ }
77
+
78
+ function resetTransitionState() {
79
+ isTransitioning = false;
80
+ delete document.documentElement.dataset.themeVt;
81
+ vtDuration.value = null;
82
+ vtClipFrom.value = null;
83
+ cancelAnimation();
84
+ }
85
+
86
+ tryOnScopeDispose(() => {
87
+ cancelAnimation();
88
+ if (document.documentElement.dataset.themeVt !== "active") return;
89
+ delete document.documentElement.dataset.themeVt;
90
+ vtDuration.value = null;
91
+ vtClipFrom.value = null;
92
+ });
93
+
94
+ function polygonCollapsed(point: string, vertexCount: number): string {
95
+ return `polygon(${Array.from({ length: vertexCount }, () => point).join(", ")})`;
96
+ }
97
+
98
+ // All coordinates are percentages of the snapshot reference box: Chrome renders absolute px
99
+ // clip-path coordinates on ::view-transition-new(root) unscaled on fractional display scales
100
+ // for the first transition after load, so px values land at the wrong position.
101
+ function getThemeTransitionClipPaths(
102
+ variant: ThemeTransitionVariant,
103
+ cx: number,
104
+ cy: number,
105
+ maxRadius: number,
106
+ viewportWidth: number,
107
+ viewportHeight: number
108
+ ): [string, string] {
109
+ const toX = (x: number) => `${(x / viewportWidth) * 100}%`;
110
+ const toY = (y: number) => `${(y / viewportHeight) * 100}%`;
111
+ const point = (x: number, y: number) => `${toX(x)} ${toY(y)}`;
112
+ // circle() percentage radii resolve against hypot(w, h) / sqrt(2) of the reference box.
113
+ const toRadius = (r: number) =>
114
+ `${(r / (Math.hypot(viewportWidth, viewportHeight) / Math.SQRT2)) * 100}%`;
115
+
116
+ switch (variant) {
117
+ case "circle":
118
+ return [
119
+ `circle(0% at ${point(cx, cy)})`,
120
+ `circle(${toRadius(maxRadius)} at ${point(cx, cy)})`,
121
+ ];
122
+ case "square": {
123
+ const halfW = Math.max(cx, viewportWidth - cx);
124
+ const halfH = Math.max(cy, viewportHeight - cy);
125
+ const halfSide = Math.max(halfW, halfH) * 1.05;
126
+ const end = [
127
+ point(cx - halfSide, cy - halfSide),
128
+ point(cx + halfSide, cy - halfSide),
129
+ point(cx + halfSide, cy + halfSide),
130
+ point(cx - halfSide, cy + halfSide),
131
+ ].join(", ");
132
+ return [polygonCollapsed(point(cx, cy), 4), `polygon(${end})`];
133
+ }
134
+ case "triangle": {
135
+ const scale = maxRadius * 2.2;
136
+ const dx = (Math.sqrt(3) / 2) * scale;
137
+ const verts = [
138
+ point(cx, cy - scale),
139
+ point(cx + dx, cy + 0.5 * scale),
140
+ point(cx - dx, cy + 0.5 * scale),
141
+ ].join(", ");
142
+ return [polygonCollapsed(point(cx, cy), 3), `polygon(${verts})`];
143
+ }
144
+ case "diamond": {
145
+ // Slightly larger than the view-transition circle radius so axis-aligned coverage matches the circle reveal.
146
+ const R = maxRadius * Math.SQRT2;
147
+ const end = [
148
+ point(cx, cy - R),
149
+ point(cx + R, cy),
150
+ point(cx, cy + R),
151
+ point(cx - R, cy),
152
+ ].join(", ");
153
+ return [polygonCollapsed(point(cx, cy), 4), `polygon(${end})`];
154
+ }
155
+ case "hexagon": {
156
+ const R = maxRadius * Math.SQRT2;
157
+ const verts: string[] = [];
158
+ for (let i = 0; i < 6; i++) {
159
+ const a = -Math.PI / 2 + (i * Math.PI) / 3;
160
+ verts.push(point(cx + R * Math.cos(a), cy + R * Math.sin(a)));
161
+ }
162
+ return [polygonCollapsed(point(cx, cy), 6), `polygon(${verts.join(", ")})`];
163
+ }
164
+ case "rectangle": {
165
+ const halfW = Math.max(cx, viewportWidth - cx);
166
+ const halfH = Math.max(cy, viewportHeight - cy);
167
+ const end = [
168
+ point(cx - halfW, cy - halfH),
169
+ point(cx + halfW, cy - halfH),
170
+ point(cx + halfW, cy + halfH),
171
+ point(cx - halfW, cy + halfH),
172
+ ].join(", ");
173
+ return [polygonCollapsed(point(cx, cy), 4), `polygon(${end})`];
174
+ }
175
+ case "star": {
176
+ // Small overscan so the last frames never leave a 1px seam before the transition group ends.
177
+ const R = maxRadius * Math.SQRT2 * 1.03;
178
+ const innerRatio = 0.42;
179
+ const starPolygon = (radius: number) => {
180
+ const verts: string[] = [];
181
+ for (let i = 0; i < 5; i++) {
182
+ const outerA = -Math.PI / 2 + (i * 2 * Math.PI) / 5;
183
+ verts.push(point(cx + radius * Math.cos(outerA), cy + radius * Math.sin(outerA)));
184
+ const innerA = outerA + Math.PI / 5;
185
+ verts.push(
186
+ point(
187
+ cx + radius * innerRatio * Math.cos(innerA),
188
+ cy + radius * innerRatio * Math.sin(innerA)
189
+ )
190
+ );
191
+ }
192
+ return `polygon(${verts.join(", ")})`;
193
+ };
194
+ const startR = Math.max(2, R * 0.025);
195
+ return [starPolygon(startR), starPolygon(R)];
196
+ }
197
+ default:
198
+ return [
199
+ `circle(0% at ${point(cx, cy)})`,
200
+ `circle(${toRadius(maxRadius)} at ${point(cx, cy)})`,
201
+ ];
47
202
  }
48
- );
203
+ }
49
204
 
50
205
  const toggleTheme = () => {
51
- const button = buttonRef.value;
52
- if (!button) return;
53
- const { top, left, width, height } = button.getBoundingClientRect();
54
- const x = left + width / 2;
55
- const y = top + height / 2;
56
- const viewportWidth = window.visualViewport?.width ?? window.innerWidth;
57
- const viewportHeight = window.visualViewport?.height ?? window.innerHeight;
206
+ const button = toggler.value;
207
+ if (!button || isTransitioning || document.documentElement.dataset.themeVt === "active") return;
208
+
209
+ // innerWidth/innerHeight (not visualViewport): percentages must resolve against the
210
+ // snapshot reference box, which includes classic scrollbars.
211
+ const viewportWidth = viewportWidthRef.value;
212
+ const viewportHeight = viewportHeightRef.value;
213
+
214
+ let x: number;
215
+ let y: number;
216
+ if (props.fromCenter) {
217
+ x = viewportWidth / 2;
218
+ y = viewportHeight / 2;
219
+ } else {
220
+ const { top, left, width, height } = button.getBoundingClientRect();
221
+ x = left + width / 2;
222
+ y = top + height / 2;
223
+ }
224
+
58
225
  const maxRadius = Math.hypot(Math.max(x, viewportWidth - x), Math.max(y, viewportHeight - y));
59
- const newTheme = colorMode.value === "light" ? "dark" : "light";
226
+
227
+ const newTheme = colorMode.value === "dark" ? "light" : "dark";
60
228
  const applyTheme = () => {
229
+ // Toggle the class synchronously so the View Transitions API snapshots the new theme
230
+ // inside the startViewTransition callback, then hand persistence to color-mode.
61
231
  document.documentElement.classList.toggle("dark", newTheme === "dark");
232
+ document.documentElement.classList.toggle("light", newTheme === "light");
62
233
  colorMode.preference = newTheme;
63
234
  };
235
+
64
236
  if (typeof document.startViewTransition !== "function") {
65
237
  applyTheme();
66
238
  return;
67
239
  }
240
+
241
+ const clipPath = getThemeTransitionClipPaths(
242
+ props.variant,
243
+ x,
244
+ y,
245
+ maxRadius,
246
+ viewportWidth,
247
+ viewportHeight
248
+ );
249
+
250
+ document.documentElement.dataset.themeVt = "active";
251
+ vtDuration.value = `${props.duration}ms`;
252
+ // Pin the collapsed clip-path via CSS so Firefox does not paint the new theme unclipped
253
+ // between snapshot and the ready.then() JS animation.
254
+ vtClipFrom.value = clipPath[0];
255
+
256
+ isTransitioning = true;
68
257
  const transition = document.startViewTransition(applyTheme);
69
- const ready = transition?.ready;
70
- if (ready && typeof ready.then === "function") {
71
- ready.then(() => {
72
- document.documentElement.animate(
73
- {
74
- clipPath: [`circle(0px at ${x}px ${y}px)`, `circle(${maxRadius}px at ${x}px ${y}px)`],
75
- },
258
+ transition.finished.finally(resetTransitionState).catch(() => {});
259
+
260
+ transition.ready
261
+ .then(() => {
262
+ activeAnimation = document.documentElement.animate(
263
+ { clipPath },
76
264
  {
77
265
  duration: props.duration,
78
- easing: "ease-in-out",
266
+ // Star: linear avoids easing overshoot that fights polygon interpolation at t→1.
267
+ easing: props.variant === "star" ? "linear" : "ease-in-out",
268
+ fill: "forwards",
79
269
  pseudoElement: "::view-transition-new(root)",
80
270
  }
81
271
  );
82
- });
83
- }
272
+ })
273
+ .catch(() => {});
84
274
  };
85
275
  </script>
86
276
  <style>
@@ -95,4 +285,10 @@
95
285
  ::view-transition-old(root) {
96
286
  z-index: 1;
97
287
  }
288
+ html[data-theme-vt="active"]::view-transition-group(root) {
289
+ animation-duration: var(--theme-toggle-vt-duration, 400ms);
290
+ }
291
+ html[data-theme-vt="active"]::view-transition-new(root) {
292
+ clip-path: var(--theme-vt-clip-from);
293
+ }
98
294
  </style>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@baybreezy/docd",
3
- "version": "0.3.3",
3
+ "version": "0.3.5",
4
4
  "description": "A Nuxt layer for building documentation sites with UI Thing.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -31,9 +31,9 @@
31
31
  },
32
32
  "dependencies": {
33
33
  "@baybreezy/file-extension-icon": "^0.0.5",
34
- "@iconify/utils": "^3.1.4",
34
+ "@iconify/utils": "^3.1.7",
35
35
  "@morev/vue-transitions": "^3.0.5",
36
- "@nuxt/content": "3.15.2",
36
+ "@nuxt/content": "3.16.0",
37
37
  "@nuxt/fonts": "^0.14.0",
38
38
  "@nuxt/icon": "^2.5.1",
39
39
  "@nuxt/image": "2.1.0",
@@ -41,25 +41,25 @@
41
41
  "@nuxtjs/color-mode": "^4.0.1",
42
42
  "@nuxtjs/mcp-toolkit": "^0.19.0",
43
43
  "@nuxtjs/mdc": "^0.23.1",
44
- "@nuxtjs/robots": "^6.2.0",
44
+ "@nuxtjs/robots": "^6.2.1",
45
45
  "@tailwindcss/forms": "^0.5.11",
46
46
  "@tailwindcss/typography": "^0.5.20",
47
47
  "@tailwindcss/vite": "^4.3.3",
48
- "@takumi-rs/core": "^2.12.0",
48
+ "@takumi-rs/core": "^2.13.7",
49
49
  "@vueuse/core": "^14.4.0",
50
50
  "@vueuse/nuxt": "^14.4.0",
51
51
  "better-sqlite3": "^13.0.3",
52
52
  "defu": "^6.1.7",
53
53
  "git-url-parse": "^16.1.0",
54
54
  "lodash-es": "^4.18.1",
55
- "mermaid": "^11.17.1",
56
- "motion-v": "^2.4.0",
55
+ "mermaid": "^11.17.2",
56
+ "motion-v": "^2.4.2",
57
57
  "nuxt-component-meta": "^0.18.0",
58
58
  "nuxt-gtag": "5.0.0",
59
59
  "nuxt-llms": "^0.2.0",
60
60
  "nuxt-og-image": "^6.7.8",
61
- "pkg-types": "^2.3.1",
62
- "reka-ui": "^2.10.3",
61
+ "pkg-types": "^2.3.3",
62
+ "reka-ui": "^2.10.4",
63
63
  "shiki": "^4.4.3",
64
64
  "tailwind-merge": "^3.6.0",
65
65
  "tailwind-variants": "^3.3.1",
@@ -69,14 +69,14 @@
69
69
  "vaul-vue": "^0.4.1",
70
70
  "vue-sonner": "^2.0.9",
71
71
  "yaml": "^2.9.0",
72
- "zod": "^4.4.3"
72
+ "zod": "^4.6.2"
73
73
  },
74
74
  "devDependencies": {
75
75
  "@types/lodash-es": "^4.17.12",
76
76
  "nuxt": "^4.5.2",
77
77
  "typescript": "6.0.3",
78
78
  "vue": "latest",
79
- "vue-router": "^5.2.0"
79
+ "vue-router": "^5.3.1"
80
80
  },
81
81
  "packageManager": "bun@1.4.0",
82
82
  "trustedDependencies": [