fancy-ui-vue 0.3.0 → 0.4.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.
Files changed (102) hide show
  1. package/README.md +9 -6
  2. package/dist/components/animated-testimonials/AnimatedTestimonials.vue.js +23 -12
  3. package/dist/components/bg-falling-stars/FallingStarsBg.vue.js +10 -1
  4. package/dist/components/bg-falling-stars/bg-falling-stars-core.d.ts +6 -0
  5. package/dist/components/bg-falling-stars/bg-falling-stars-core.js +24 -2
  6. package/dist/components/bg-stars/StarsBackground.vue.js +1 -1
  7. package/dist/components/bg-stars/StarsBackground.vue2.js +13 -1
  8. package/dist/components/bg-stars/bg-stars-core.d.ts +6 -0
  9. package/dist/components/bg-stars/bg-stars-core.js +21 -1
  10. package/dist/components/book/Book.vue.js +5 -83
  11. package/dist/components/book/Book.vue2.js +82 -1
  12. package/dist/components/box-reveal/BoxReveal.vue.js +5 -47
  13. package/dist/components/box-reveal/BoxReveal.vue2.js +48 -1
  14. package/dist/components/compare/StarField.vue.js +1 -1
  15. package/dist/components/container-text-flip/ContainerTextFlip.vue.js +1 -1
  16. package/dist/components/container-text-flip/ContainerTextFlip.vue2.js +14 -5
  17. package/dist/components/flickering-grid/FlickeringGrid.vue.js +19 -1
  18. package/dist/components/flickering-grid/flickering-grid-core.d.ts +6 -0
  19. package/dist/components/flickering-grid/flickering-grid-core.js +30 -1
  20. package/dist/components/flip-words/FlipWords.vue.js +1 -1
  21. package/dist/components/flip-words/FlipWords.vue2.js +14 -7
  22. package/dist/components/hyper-text/HyperText.vue.js +6 -97
  23. package/dist/components/hyper-text/HyperText.vue2.js +101 -0
  24. package/dist/components/letter-pullup/LetterPullup.vue.js +6 -38
  25. package/dist/components/letter-pullup/LetterPullup.vue2.js +40 -0
  26. package/dist/components/logo-cloud/AnimatedLogoCloud.vue.js +1 -1
  27. package/dist/components/magnetic-field/MagnetPuck.vue.d.ts +51 -0
  28. package/dist/components/magnetic-field/MagnetPuck.vue.js +7 -0
  29. package/dist/components/magnetic-field/MagnetPuck.vue2.js +191 -0
  30. package/dist/components/magnetic-field/MagneticField.vue.d.ts +39 -0
  31. package/dist/components/magnetic-field/MagneticField.vue.js +7 -0
  32. package/dist/components/magnetic-field/MagneticField.vue2.js +157 -0
  33. package/dist/components/magnetic-field/MagneticItem.vue.d.ts +28 -0
  34. package/dist/components/magnetic-field/MagneticItem.vue.js +7 -0
  35. package/dist/components/magnetic-field/MagneticItem.vue2.js +72 -0
  36. package/dist/components/magnetic-field/index.d.ts +10 -0
  37. package/dist/components/magnetic-field/magnetic-field-core.d.ts +163 -0
  38. package/dist/components/magnetic-field/magnetic-field-core.js +534 -0
  39. package/dist/components/magnetic-field/magnetic-field-source.d.ts +58 -0
  40. package/dist/components/magnetic-field/magnetic-field-source.js +58 -0
  41. package/dist/components/magnetic-field/types.d.ts +14 -0
  42. package/dist/components/magnetic-field/types.js +5 -0
  43. package/dist/components/matrix-rain/MatrixRain.vue.js +20 -1
  44. package/dist/components/matrix-rain/matrix-rain-core.d.ts +6 -0
  45. package/dist/components/matrix-rain/matrix-rain-core.js +28 -6
  46. package/dist/components/noise-reveal/NoiseReveal.vue.js +7 -0
  47. package/dist/components/noise-reveal/noise-reveal-core.js +23 -7
  48. package/dist/components/pixel-scene/PixelScene.vue.d.ts +60 -0
  49. package/dist/components/pixel-scene/PixelScene.vue.js +184 -0
  50. package/dist/components/pixel-scene/PixelScene.vue2.js +4 -0
  51. package/dist/components/pixel-scene/index.d.ts +4 -0
  52. package/dist/components/pixel-scene/pixel-scene-core.d.ts +256 -0
  53. package/dist/components/pixel-scene/pixel-scene-core.js +878 -0
  54. package/dist/components/pixel-scene/pixel-scene-hdr.d.ts +68 -0
  55. package/dist/components/pixel-scene/pixel-scene-hdr.js +312 -0
  56. package/dist/components/pixel-scene/pixel-scene-scenes.d.ts +31 -0
  57. package/dist/components/pixel-scene/pixel-scene-scenes.js +1074 -0
  58. package/dist/components/ripple/Ripple.vue.js +1 -1
  59. package/dist/components/ripple/Ripple.vue2.js +6 -1
  60. package/dist/components/sparkles/Sparkles.vue.js +10 -1
  61. package/dist/components/sparkles/sparkles-core.d.ts +6 -0
  62. package/dist/components/sparkles/sparkles-core.js +26 -2
  63. package/dist/components/sparkles-text/SparklesText.vue.js +6 -88
  64. package/dist/components/sparkles-text/SparklesText.vue2.js +100 -0
  65. package/dist/components/story-thread/StoryNode.vue.d.ts +11 -0
  66. package/dist/components/story-thread/StoryNode.vue.js +7 -0
  67. package/dist/components/story-thread/StoryNode.vue2.js +23 -0
  68. package/dist/components/story-thread/StoryThread.vue.d.ts +56 -0
  69. package/dist/components/story-thread/StoryThread.vue.js +7 -0
  70. package/dist/components/story-thread/StoryThread.vue2.js +103 -0
  71. package/dist/components/story-thread/index.d.ts +5 -0
  72. package/dist/components/story-thread/story-thread-core.d.ts +119 -0
  73. package/dist/components/story-thread/story-thread-core.js +491 -0
  74. package/dist/components/story-thread/types.d.ts +1 -0
  75. package/dist/components/sun-switch/SunSwitch.vue.d.ts +61 -0
  76. package/dist/components/sun-switch/SunSwitch.vue.js +7 -0
  77. package/dist/components/sun-switch/SunSwitch.vue2.js +559 -0
  78. package/dist/components/sun-switch/index.d.ts +4 -0
  79. package/dist/components/sun-switch/pixel-wave-core.d.ts +82 -0
  80. package/dist/components/sun-switch/pixel-wave-core.js +508 -0
  81. package/dist/components/sun-switch/sun-switch-core.d.ts +251 -0
  82. package/dist/components/sun-switch/sun-switch-core.js +546 -0
  83. package/dist/components/sun-switch/sun-switch-hdr.d.ts +70 -0
  84. package/dist/components/sun-switch/sun-switch-hdr.js +311 -0
  85. package/dist/components/terminal-text/TerminalText.vue.js +1 -1
  86. package/dist/components/terminal-text/TerminalText.vue2.js +36 -4
  87. package/dist/components/text-generate-effect/TextGenerateEffect.vue.js +5 -72
  88. package/dist/components/text-generate-effect/TextGenerateEffect.vue2.js +74 -1
  89. package/dist/components/text-reveal-card/TextRevealCard.vue.js +5 -101
  90. package/dist/components/text-reveal-card/TextRevealCard.vue2.js +98 -1
  91. package/dist/components/text-reveal-card/TextRevealStars.vue.js +1 -1
  92. package/dist/components/text-reveal-card/TextRevealStars.vue2.js +29 -12
  93. package/dist/components/tracing-beam/TracingBeam.vue.d.ts +20 -1
  94. package/dist/components/tracing-beam/TracingBeam.vue.js +5 -164
  95. package/dist/components/tracing-beam/TracingBeam.vue2.js +168 -1
  96. package/dist/index.d.ts +4 -0
  97. package/dist/index.js +361 -338
  98. package/dist/styles.css +731 -89
  99. package/package.json +1 -1
  100. package/dist/components/hyper-text/HyperText.vue3.js +0 -5
  101. package/dist/components/letter-pullup/LetterPullup.vue3.js +0 -5
  102. package/dist/components/sparkles-text/SparklesText.vue3.js +0 -5
@@ -0,0 +1,559 @@
1
+ import { defineComponent, mergeModels, useModel, useTemplateRef, useAttrs, shallowRef, onMounted, watch, onBeforeUnmount, createElementBlock, openBlock, mergeProps, unref, createElementVNode, createCommentVNode, normalizeStyle, nextTick } from "vue";
2
+ import { cn } from "../../utils.js";
3
+ import { inView } from "../../internals/motion/in-view.js";
4
+ import { useReducedMotion } from "../../internals/motion/use-media-query.js";
5
+ import { sound } from "../../sound/sound.js";
6
+ import { flipWait, markFlip, isWaving, pixelWave } from "./pixel-wave-core.js";
7
+ import { createSunPainter, SUN_PALETTE } from "./sun-switch-core.js";
8
+ import { sunHdrAvailable, startSunHdr, SUN_HDR_RESTARTS, SUN_HDR_RESTART_MS } from "./sun-switch-hdr.js";
9
+ const _hoisted_1 = ["aria-checked", "aria-label", "aria-busy", "data-state", "data-waving", "data-hdr", "disabled"];
10
+ const _sfc_main = /* @__PURE__ */ defineComponent({
11
+ ...{ name: "SunSwitch", inheritAttrs: false },
12
+ __name: "SunSwitch",
13
+ props: /* @__PURE__ */ mergeModels({
14
+ checked: { type: Boolean },
15
+ onCheckedChange: { type: Function },
16
+ radius: { default: 10 },
17
+ cell: { default: 5 },
18
+ dot: { default: 4 },
19
+ palette: { default: () => SUN_PALETTE },
20
+ ink: { default: "currentColor" },
21
+ nightAlpha: { default: 0.42 },
22
+ horizon: { type: Boolean, default: true },
23
+ lens: { type: Boolean, default: true },
24
+ lensRadius: { default: 7 },
25
+ mode: { default: "document" },
26
+ scope: { default: null },
27
+ fill: {},
28
+ duration: { default: 1300 },
29
+ haloCells: { default: 9 },
30
+ hdr: { type: Boolean, default: true },
31
+ sound: { type: Boolean, default: false },
32
+ label: { default: "Day mode" },
33
+ disabled: { type: Boolean, default: false },
34
+ class: { type: [Boolean, null, String, Object, Array] }
35
+ }, {
36
+ "checked": { type: Boolean, ...{ default: true } },
37
+ "checkedModifiers": {}
38
+ }),
39
+ emits: ["update:checked"],
40
+ setup(__props, { expose: __expose }) {
41
+ const checked = useModel(__props, "checked");
42
+ const el = useTemplateRef("ref");
43
+ const canvasEl = useTemplateRef("canvas");
44
+ const hdrCanvas = useTemplateRef("hdrCanvas");
45
+ __expose({ ref: el });
46
+ const attrs = useAttrs();
47
+ const CHAINED = [
48
+ "onClick",
49
+ "onPointerenter",
50
+ "onPointermove",
51
+ "onPointerdown",
52
+ "onPointerup",
53
+ "onPointerleave",
54
+ "onPointercancel",
55
+ "onFocus",
56
+ "onBlur",
57
+ "onKeydown"
58
+ ];
59
+ function forwardedAttrs() {
60
+ const out = { ...attrs };
61
+ for (const key of CHAINED) delete out[key];
62
+ return out;
63
+ }
64
+ function chain(key, event) {
65
+ const listener = attrs[key];
66
+ if (Array.isArray(listener)) {
67
+ for (const fn of listener) if (typeof fn === "function") fn(event);
68
+ } else if (typeof listener === "function") {
69
+ listener(event);
70
+ }
71
+ }
72
+ const reduced = useReducedMotion();
73
+ let painter = null;
74
+ const painterReady = shallowRef(false);
75
+ const mounted = shallowRef(false);
76
+ const hdrCapable = shallowRef(false);
77
+ const hdrOn = shallowRef(false);
78
+ const hdrRun = shallowRef(0);
79
+ let hdrRestarts = 0;
80
+ const waving = shallowRef(false);
81
+ function sunRadius() {
82
+ return Math.max(1, Math.round(__props.radius));
83
+ }
84
+ let asleep = false;
85
+ let inkStale = false;
86
+ let inkFrame = 0;
87
+ function readInk() {
88
+ inkStale = false;
89
+ const canvas = canvasEl.value;
90
+ if (!painter || !canvas) return;
91
+ painter.setInk(getComputedStyle(canvas).color);
92
+ }
93
+ function scheduleInk() {
94
+ if (asleep) {
95
+ inkStale = true;
96
+ return;
97
+ }
98
+ if (inkFrame || typeof requestAnimationFrame !== "function") return;
99
+ inkFrame = requestAnimationFrame(() => {
100
+ inkFrame = 0;
101
+ readInk();
102
+ });
103
+ }
104
+ let teardown = null;
105
+ onMounted(() => {
106
+ mounted.value = true;
107
+ hdrCapable.value = __props.hdr && sunHdrAvailable();
108
+ const canvas = canvasEl.value;
109
+ if (!canvas) return;
110
+ const p = createSunPainter(canvas, {
111
+ radius: __props.radius,
112
+ cell: __props.cell,
113
+ dot: __props.dot,
114
+ palette: __props.palette,
115
+ nightAlpha: __props.nightAlpha,
116
+ horizon: __props.horizon,
117
+ lens: __props.lens,
118
+ lensRadius: __props.lensRadius,
119
+ checked: checked.value,
120
+ reducedMotion: reduced.value
121
+ });
122
+ if (!p) return;
123
+ painter = p;
124
+ painterReady.value = true;
125
+ readInk();
126
+ let visible = true;
127
+ let hidden = document.visibilityState === "hidden";
128
+ const sync = () => {
129
+ asleep = !(visible && !hidden);
130
+ if (asleep) {
131
+ p.sleep();
132
+ return;
133
+ }
134
+ if (inkStale) readInk();
135
+ p.wake();
136
+ };
137
+ let ro;
138
+ if (typeof ResizeObserver !== "undefined") {
139
+ ro = new ResizeObserver(() => p.resize());
140
+ try {
141
+ ro.observe(canvas, { box: "device-pixel-content-box" });
142
+ } catch {
143
+ ro.observe(canvas);
144
+ }
145
+ }
146
+ const io = inView(canvas, {
147
+ once: false,
148
+ threshold: 0,
149
+ onChange: (intersecting) => {
150
+ visible = intersecting;
151
+ sync();
152
+ }
153
+ });
154
+ const onVisibility = () => {
155
+ hidden = document.visibilityState === "hidden";
156
+ sync();
157
+ };
158
+ document.addEventListener("visibilitychange", onVisibility);
159
+ let mo;
160
+ if (typeof MutationObserver !== "undefined") {
161
+ mo = new MutationObserver(scheduleInk);
162
+ const attributeFilter = ["class", "style", "data-theme", "data-mode"];
163
+ mo.observe(document.documentElement, { attributes: true, attributeFilter });
164
+ mo.observe(document.body, { attributes: true, attributeFilter });
165
+ }
166
+ const scheme = typeof window.matchMedia === "function" ? window.matchMedia("(prefers-color-scheme: dark)") : null;
167
+ scheme?.addEventListener("change", scheduleInk);
168
+ const onColorSettled = (event) => {
169
+ const target = event.target;
170
+ if (event.propertyName !== "color" || !(target instanceof Node)) return;
171
+ if (target.contains(canvas)) scheduleInk();
172
+ };
173
+ document.addEventListener("transitionend", onColorSettled, true);
174
+ document.addEventListener("transitioncancel", onColorSettled, true);
175
+ sync();
176
+ teardown = () => {
177
+ ro?.disconnect();
178
+ io?.destroy?.();
179
+ mo?.disconnect();
180
+ scheme?.removeEventListener("change", scheduleInk);
181
+ document.removeEventListener("transitionend", onColorSettled, true);
182
+ document.removeEventListener("transitioncancel", onColorSettled, true);
183
+ document.removeEventListener("visibilitychange", onVisibility);
184
+ if (inkFrame && typeof cancelAnimationFrame === "function") cancelAnimationFrame(inkFrame);
185
+ inkFrame = 0;
186
+ p.destroy();
187
+ painter = null;
188
+ painterReady.value = false;
189
+ };
190
+ });
191
+ watch(
192
+ () => __props.hdr,
193
+ (on) => {
194
+ hdrCapable.value = mounted.value && on && sunHdrAvailable();
195
+ }
196
+ );
197
+ watch(
198
+ [hdrCanvas, painterReady, hdrCapable, hdrRun],
199
+ ([canvas, ready, capable], _old, onCleanup) => {
200
+ const p = painter;
201
+ if (!canvas || !ready || !capable || !p) return;
202
+ let cancelled = false;
203
+ let stop = null;
204
+ let retry = null;
205
+ const restart = () => {
206
+ if (hdrRestarts >= SUN_HDR_RESTARTS) {
207
+ hdrCapable.value = false;
208
+ return;
209
+ }
210
+ hdrRestarts++;
211
+ retry = setTimeout(() => {
212
+ retry = null;
213
+ hdrRun.value++;
214
+ }, SUN_HDR_RESTART_MS * hdrRestarts);
215
+ };
216
+ void startSunHdr(canvas).then((layer) => {
217
+ if (cancelled || painter !== p) {
218
+ layer?.destroy();
219
+ return;
220
+ }
221
+ if (!layer) {
222
+ if (hdrRestarts === 0) hdrCapable.value = false;
223
+ else restart();
224
+ return;
225
+ }
226
+ p.setGlowTarget(layer);
227
+ hdrOn.value = true;
228
+ stop = () => {
229
+ p.setGlowTarget(null);
230
+ layer.destroy();
231
+ hdrOn.value = false;
232
+ };
233
+ void layer.lost.then(() => {
234
+ if (cancelled) return;
235
+ stop?.();
236
+ stop = null;
237
+ restart();
238
+ });
239
+ });
240
+ onCleanup(() => {
241
+ cancelled = true;
242
+ stop?.();
243
+ stop = null;
244
+ if (retry !== null) clearTimeout(retry);
245
+ });
246
+ },
247
+ { flush: "post" }
248
+ );
249
+ onBeforeUnmount(() => {
250
+ clearTimeout(closeTimer);
251
+ clearTimeout(pendingTimer);
252
+ pendingTimer = void 0;
253
+ pending = null;
254
+ disarm?.();
255
+ disarm = null;
256
+ teardown?.();
257
+ teardown = null;
258
+ });
259
+ watch(
260
+ () => ({ radius: __props.radius, cell: __props.cell, dot: __props.dot, horizon: __props.horizon }),
261
+ (next) => painter?.setOptions(next),
262
+ { flush: "post" }
263
+ );
264
+ watch(
265
+ () => ({ palette: __props.palette, nightAlpha: __props.nightAlpha, lens: __props.lens, lensRadius: __props.lensRadius }),
266
+ (next) => painter?.setOptions(next),
267
+ { flush: "post" }
268
+ );
269
+ watch(checked, (value) => painter?.setOptions({ checked: value }), { flush: "post" });
270
+ watch(reduced, (value) => painter?.setOptions({ reducedMotion: value }), { flush: "post" });
271
+ watch(() => __props.ink, readInk, { flush: "post" });
272
+ let hovering = false;
273
+ let focused = false;
274
+ let lensOpen = false;
275
+ let targetX = 0;
276
+ let targetY = 0;
277
+ let closeTimer;
278
+ function sizeCells() {
279
+ return 2 * sunRadius() + 1;
280
+ }
281
+ function centreCells() {
282
+ return sunRadius() + 0.5;
283
+ }
284
+ function trackPointer(event) {
285
+ const canvas = canvasEl.value;
286
+ if (!canvas) return;
287
+ const r = canvas.getBoundingClientRect();
288
+ const size = sizeCells();
289
+ const sx = r.width > 0 ? size / r.width : 1 / __props.cell;
290
+ const sy = r.height > 0 ? size / r.height : 1 / __props.cell;
291
+ targetX = (event.clientX - r.left) * sx;
292
+ targetY = (event.clientY - r.top) * sy;
293
+ }
294
+ function syncLens() {
295
+ const want = __props.lens && !__props.disabled && (hovering || focused);
296
+ lensOpen = want || waving.value && lensOpen;
297
+ if (focused && !hovering) {
298
+ targetX = centreCells();
299
+ targetY = centreCells();
300
+ }
301
+ painter?.pointer(targetX, targetY, lensOpen);
302
+ }
303
+ function syncLensSoon() {
304
+ clearTimeout(closeTimer);
305
+ closeTimer = setTimeout(() => {
306
+ closeTimer = void 0;
307
+ syncLens();
308
+ }, 0);
309
+ }
310
+ watch(
311
+ () => [__props.lens, __props.disabled],
312
+ () => syncLens()
313
+ );
314
+ function onPointerEnter(event) {
315
+ hovering = true;
316
+ trackPointer(event);
317
+ syncLens();
318
+ chain("onPointerenter", event);
319
+ }
320
+ function onPointerMove(event) {
321
+ hovering = true;
322
+ trackPointer(event);
323
+ syncLens();
324
+ chain("onPointermove", event);
325
+ }
326
+ function onPointerDown(event) {
327
+ hovering = true;
328
+ trackPointer(event);
329
+ syncLens();
330
+ chain("onPointerdown", event);
331
+ }
332
+ function onPointerUp(event) {
333
+ if (event.pointerType === "touch") {
334
+ hovering = false;
335
+ syncLensSoon();
336
+ }
337
+ chain("onPointerup", event);
338
+ }
339
+ function onPointerLeave(event) {
340
+ hovering = false;
341
+ syncLensSoon();
342
+ chain("onPointerleave", event);
343
+ }
344
+ function onPointerCancel(event) {
345
+ hovering = false;
346
+ syncLensSoon();
347
+ chain("onPointercancel", event);
348
+ }
349
+ function onFocus(event) {
350
+ let visible = false;
351
+ try {
352
+ visible = event.currentTarget.matches(":focus-visible");
353
+ } catch {
354
+ visible = false;
355
+ }
356
+ focused = visible;
357
+ syncLens();
358
+ chain("onFocus", event);
359
+ }
360
+ function onBlur(event) {
361
+ focused = false;
362
+ syncLensSoon();
363
+ chain("onBlur", event);
364
+ }
365
+ let intent = null;
366
+ let token = 0;
367
+ let pending = null;
368
+ let pendingTimer;
369
+ let disarm = null;
370
+ function toggle() {
371
+ if (__props.disabled) return;
372
+ const next = !(pending ?? intent ?? checked.value);
373
+ const wait = flipWait(window.performance.now());
374
+ if (wait > 0) {
375
+ pending = next;
376
+ pendingTimer ??= setTimeout(flushPending, wait);
377
+ return;
378
+ }
379
+ pending = null;
380
+ startWave(next);
381
+ }
382
+ function flushPending() {
383
+ pendingTimer = void 0;
384
+ const wait = flipWait(window.performance.now());
385
+ if (wait > 0 && pending !== null) {
386
+ pendingTimer = setTimeout(flushPending, wait);
387
+ return;
388
+ }
389
+ const next = pending;
390
+ pending = null;
391
+ if (next === null || __props.disabled || next === (intent ?? checked.value)) return;
392
+ startWave(next);
393
+ }
394
+ function overButton(x, y) {
395
+ const r = el.value?.getBoundingClientRect();
396
+ return !!r && x >= r.left && x < r.right && y >= r.top && y < r.bottom;
397
+ }
398
+ function armReentry() {
399
+ if (disarm || __props.mode !== "document") return;
400
+ const root = document.documentElement;
401
+ const onDown = (event) => {
402
+ if (event.target === root && overButton(event.clientX, event.clientY)) {
403
+ event.preventDefault();
404
+ }
405
+ };
406
+ const onMove = (event) => {
407
+ if (event.target !== root || !overButton(event.clientX, event.clientY)) return;
408
+ hovering = true;
409
+ trackPointer(event);
410
+ syncLens();
411
+ };
412
+ const onDocClick = (event) => {
413
+ if (event.target === root && overButton(event.clientX, event.clientY)) el.value?.click();
414
+ };
415
+ document.addEventListener("pointerdown", onDown, true);
416
+ document.addEventListener("pointermove", onMove, true);
417
+ document.addEventListener("click", onDocClick, true);
418
+ disarm = () => {
419
+ document.removeEventListener("pointerdown", onDown, true);
420
+ document.removeEventListener("pointermove", onMove, true);
421
+ document.removeEventListener("click", onDocClick, true);
422
+ };
423
+ }
424
+ function onKeyDown(event) {
425
+ if (event.repeat && (event.key === "Enter" || event.key === " ")) event.preventDefault();
426
+ chain("onKeydown", event);
427
+ }
428
+ function isHovered() {
429
+ try {
430
+ return !!el.value?.matches(":hover");
431
+ } catch {
432
+ return false;
433
+ }
434
+ }
435
+ function onClick(event) {
436
+ toggle();
437
+ chain("onClick", event);
438
+ }
439
+ function writeState(value) {
440
+ const button = el.value;
441
+ if (!button) return;
442
+ button.setAttribute("aria-checked", value ? "true" : "false");
443
+ button.setAttribute("data-state", value ? "day" : "night");
444
+ }
445
+ function startWave(next) {
446
+ markFlip(window.performance.now());
447
+ intent = next;
448
+ const id = ++token;
449
+ if (__props.sound) sound.play(next ? "toggle-on" : "toggle-off");
450
+ const canvas = canvasEl.value;
451
+ const instant = reduced.value || isWaving();
452
+ const rect = canvas?.getBoundingClientRect();
453
+ const centre = centreCells() * __props.cell;
454
+ const sx = rect && rect.width > 0 ? rect.width / (sizeCells() * __props.cell) : 1;
455
+ const sy = rect && rect.height > 0 ? rect.height / (sizeCells() * __props.cell) : 1;
456
+ let origin = { x: (rect?.left ?? 0) + centre * sx, y: (rect?.top ?? 0) + centre * sy };
457
+ if (__props.mode === "contained" && __props.scope) {
458
+ const sr = __props.scope.getBoundingClientRect();
459
+ origin = {
460
+ x: origin.x - sr.left - __props.scope.clientLeft,
461
+ y: origin.y - sr.top - __props.scope.clientTop
462
+ };
463
+ }
464
+ const oldInk = canvas ? getComputedStyle(canvas).color : "";
465
+ const front = (outer) => ({
466
+ cx: centre,
467
+ cy: centre,
468
+ R: Math.max(0, outer - __props.haloCells + 0.5) * __props.cell,
469
+ nextChecked: next,
470
+ oldInk
471
+ });
472
+ waving.value = !instant;
473
+ if (!instant) armReentry();
474
+ painter?.setFront(instant ? null : front(0));
475
+ void pixelWave({
476
+ origin,
477
+ mode: __props.mode,
478
+ scope: __props.scope,
479
+ live: canvas ?? null,
480
+ liveHdr: hdrCanvas.value,
481
+ hdr: __props.hdr,
482
+ fill: __props.fill,
483
+ cell: __props.cell,
484
+ dot: __props.dot,
485
+ haloCells: __props.haloCells,
486
+ duration: __props.duration,
487
+ palette: __props.palette,
488
+ reducedMotion: reduced.value,
489
+ apply: () => {
490
+ checked.value = next;
491
+ __props.onCheckedChange?.(next);
492
+ writeState(next);
493
+ painter?.setOptions({ checked: next });
494
+ readInk();
495
+ scheduleInk();
496
+ },
497
+ onFront: (outer) => {
498
+ if (id === token) painter?.setFront(front(outer));
499
+ }
500
+ }).then(() => {
501
+ void nextTick(() => {
502
+ writeState(checked.value);
503
+ painter?.setOptions({ checked: checked.value });
504
+ });
505
+ if (id !== token) return;
506
+ intent = null;
507
+ waving.value = false;
508
+ disarm?.();
509
+ disarm = null;
510
+ painter?.setFront(null);
511
+ hovering = isHovered();
512
+ syncLens();
513
+ });
514
+ }
515
+ return (_ctx, _cache) => {
516
+ return openBlock(), createElementBlock("button", mergeProps(forwardedAttrs(), {
517
+ ref: "ref",
518
+ type: "button",
519
+ role: "switch",
520
+ "aria-checked": checked.value ? "true" : "false",
521
+ "aria-label": __props.label,
522
+ "aria-busy": waving.value ? "true" : void 0,
523
+ "data-state": checked.value ? "day" : "night",
524
+ "data-waving": waving.value ? "" : void 0,
525
+ "data-hdr": hdrOn.value ? "" : void 0,
526
+ disabled: __props.disabled,
527
+ class: unref(cn)("ft-sun-switch", __props.class),
528
+ style: { "--ft-sun-r": String(sunRadius()), "--ft-sun-cell": `${__props.cell}px` },
529
+ onClick,
530
+ onPointerenter: onPointerEnter,
531
+ onPointermove: onPointerMove,
532
+ onPointerdown: onPointerDown,
533
+ onPointerup: onPointerUp,
534
+ onPointerleave: onPointerLeave,
535
+ onPointercancel: onPointerCancel,
536
+ onFocus,
537
+ onBlur,
538
+ onKeydown: onKeyDown
539
+ }), [
540
+ createElementVNode("canvas", {
541
+ ref: "canvas",
542
+ class: "ft-sun-switch-canvas",
543
+ "aria-hidden": "true",
544
+ style: normalizeStyle({ color: __props.ink })
545
+ }, null, 4),
546
+ hdrCapable.value ? (openBlock(), createElementBlock("canvas", {
547
+ key: 0,
548
+ ref_key: "hdrCanvas",
549
+ ref: hdrCanvas,
550
+ class: "ft-sun-switch-hdr",
551
+ "aria-hidden": "true"
552
+ }, null, 512)) : createCommentVNode("", true)
553
+ ], 16, _hoisted_1);
554
+ };
555
+ }
556
+ });
557
+ export {
558
+ _sfc_main as default
559
+ };
@@ -0,0 +1,4 @@
1
+ export { default as SunSwitch } from "./SunSwitch.vue";
2
+ export type { SunSwitchProps } from "./SunSwitch.vue";
3
+ export { SUN_PALETTE, type SunPalette } from "./sun-switch-core.js";
4
+ export { pixelWave, isWaving, WAVE_CSS, type PixelWaveOptions, type PixelWaveMode, } from "./pixel-wave-core.js";
@@ -0,0 +1,82 @@
1
+ import { type SunPalette } from "./sun-switch-core.js";
2
+ export declare const WAVE_ATTR = "data-fancy-sun-waving";
3
+ export declare const WAVE_NAME = "fancy-sun-wave";
4
+ export declare const LIVE_NAME = "fancy-sun-live";
5
+ export declare const WAVE_HDR_NAME = "fancy-sun-wave-hdr";
6
+ export declare const LIVE_HDR_NAME = "fancy-sun-live-hdr";
7
+ export declare const WAVE_STYLE_ID = "fancy-sun-wave-styles";
8
+ export declare const HALO_ATTR = "data-fancy-sun-halo";
9
+ export declare const HALO_HDR_ATTR = "data-fancy-sun-halo-hdr";
10
+ export declare const SHEET_ATTR = "data-fancy-sun-sheet";
11
+ export declare const GHOST_ATTR = "data-fancy-sun-ghost";
12
+ /** Largest backing store (device px) the wave canvas may use; some engines refuse
13
+ * bigger canvases (no context at all). */
14
+ export declare const MAX_WAVE_CANVAS_PIXELS = 16000000;
15
+ /** Backing-store scale of the halo / sheet canvas: an integer from 1 to 2 (the dots
16
+ * are whole cells, drawn crisp with `image-rendering: pixelated`), dropping to 1 when
17
+ * the canvas would exceed `MAX_WAVE_CANVAS_PIXELS`. */
18
+ export declare function waveCanvasDpr(devicePixelRatio: number, W: number, H: number): number;
19
+ /** View-transition rules, scoped to `html[data-fancy-sun-waving]` so other view
20
+ * transitions on the page keep their own animations. */
21
+ export declare const WAVE_CSS = "html[data-fancy-sun-waving]::view-transition-group(root),\nhtml[data-fancy-sun-waving]::view-transition-old(root),\nhtml[data-fancy-sun-waving]::view-transition-new(root),\nhtml[data-fancy-sun-waving]::view-transition-group(fancy-sun-wave),\nhtml[data-fancy-sun-waving]::view-transition-new(fancy-sun-wave),\nhtml[data-fancy-sun-waving]::view-transition-group(fancy-sun-live),\nhtml[data-fancy-sun-waving]::view-transition-new(fancy-sun-live),\nhtml[data-fancy-sun-waving]::view-transition-group(fancy-sun-wave-hdr),\nhtml[data-fancy-sun-waving]::view-transition-new(fancy-sun-wave-hdr),\nhtml[data-fancy-sun-waving]::view-transition-group(fancy-sun-live-hdr),\nhtml[data-fancy-sun-waving]::view-transition-new(fancy-sun-live-hdr) {\n\tanimation: none;\n\tmix-blend-mode: normal;\n}\nhtml[data-fancy-sun-waving]::view-transition-old(fancy-sun-wave),\nhtml[data-fancy-sun-waving]::view-transition-old(fancy-sun-live),\nhtml[data-fancy-sun-waving]::view-transition-old(fancy-sun-wave-hdr),\nhtml[data-fancy-sun-waving]::view-transition-old(fancy-sun-live-hdr) {\n\tdisplay: none;\n}\nhtml[data-fancy-sun-waving]::view-transition-new(root) {\n\tclip-path: polygon(0 0, 0 0, 0 0);\n}\n";
22
+ export type PixelWaveMode = "document" | "contained";
23
+ export interface PixelWaveOptions {
24
+ /** Wave origin: viewport px (document) or scope-local px (contained). */
25
+ origin: {
26
+ x: number;
27
+ y: number;
28
+ };
29
+ /** Flips the state synchronously. Called exactly once; errors are reported, not thrown. */
30
+ apply: () => void;
31
+ mode?: PixelWaveMode;
32
+ /** The element the wave covers in contained mode (positioned, overflow hidden). */
33
+ scope?: HTMLElement | null;
34
+ /** Element kept live during the wave (named `fancy-sun-live`, kept out of the sheet). */
35
+ live?: HTMLElement | null;
36
+ /** A second live element, drawn above `live` (the switch's HDR canvas), named
37
+ * `fancy-sun-live-hdr` during a view transition. */
38
+ liveHdr?: HTMLElement | null;
39
+ /** HDR displays: the halo also glows above SDR white on a WebGPU canvas. Default true. */
40
+ hdr?: boolean;
41
+ /** Colour of the old-state sheet. Default: first opaque background from scope/body up. */
42
+ fill?: string;
43
+ cell?: number;
44
+ dot?: number;
45
+ haloCells?: number;
46
+ duration?: number;
47
+ palette?: SunPalette;
48
+ ease?: (t: number) => number;
49
+ /** Default: `prefers-reduced-motion` read at call time. */
50
+ reducedMotion?: boolean;
51
+ /** Called every frame with the outer halo radius (cells) and progress t in [0, 1]. */
52
+ onFront?: (R: number, t: number) => void;
53
+ /** Clock in ms (tests). Default `performance.now()`. */
54
+ now?: () => number;
55
+ }
56
+ /** Injects `WAVE_CSS` once per document: adopted style sheet when supported,
57
+ * otherwise a `<style id="fancy-sun-wave-styles">` in `<head>`. */
58
+ export declare function ensureWaveStyles(doc: Document): void;
59
+ /** Whether `doc.startViewTransition` exists. A function, never a module constant. */
60
+ export declare function supportsViewTransition(doc: Document): boolean;
61
+ /**
62
+ * The colour `el` visibly sits on: computed backgrounds from `el` up to `<html>`,
63
+ * translucent layers composited over the first opaque one (white if none).
64
+ * A colour that cannot be parsed counts as opaque.
65
+ */
66
+ export declare function firstOpaqueBackground(el: Element): string;
67
+ /** Minimum time between two theme flips: at most 3 full-page flips a second
68
+ * (photosensitivity). Shared by every switch on the page. */
69
+ export declare const MIN_FLIP_MS = 334;
70
+ /** Milliseconds before the next flip may start, page-wide (0 = now). */
71
+ export declare function flipWait(now: number): number;
72
+ /** Records that a flip started at `now`. */
73
+ export declare function markFlip(now: number): void;
74
+ /** Forgets the last flip (tests). */
75
+ export declare function resetFlipGate(): void;
76
+ /** Whether a wave is running (waves are global: one at a time). */
77
+ export declare function isWaving(): boolean;
78
+ /**
79
+ * Runs one wave. Always calls `apply` exactly once and never rejects; the promise
80
+ * resolves once every canvas, attribute and view-transition name is cleaned up.
81
+ */
82
+ export declare function pixelWave(o: PixelWaveOptions): Promise<void>;