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.
- package/README.md +9 -6
- package/dist/components/animated-testimonials/AnimatedTestimonials.vue.js +23 -12
- package/dist/components/bg-falling-stars/FallingStarsBg.vue.js +10 -1
- package/dist/components/bg-falling-stars/bg-falling-stars-core.d.ts +6 -0
- package/dist/components/bg-falling-stars/bg-falling-stars-core.js +24 -2
- package/dist/components/bg-stars/StarsBackground.vue.js +1 -1
- package/dist/components/bg-stars/StarsBackground.vue2.js +13 -1
- package/dist/components/bg-stars/bg-stars-core.d.ts +6 -0
- package/dist/components/bg-stars/bg-stars-core.js +21 -1
- package/dist/components/book/Book.vue.js +5 -83
- package/dist/components/book/Book.vue2.js +82 -1
- package/dist/components/box-reveal/BoxReveal.vue.js +5 -47
- package/dist/components/box-reveal/BoxReveal.vue2.js +48 -1
- package/dist/components/compare/StarField.vue.js +1 -1
- package/dist/components/container-text-flip/ContainerTextFlip.vue.js +1 -1
- package/dist/components/container-text-flip/ContainerTextFlip.vue2.js +14 -5
- package/dist/components/flickering-grid/FlickeringGrid.vue.js +19 -1
- package/dist/components/flickering-grid/flickering-grid-core.d.ts +6 -0
- package/dist/components/flickering-grid/flickering-grid-core.js +30 -1
- package/dist/components/flip-words/FlipWords.vue.js +1 -1
- package/dist/components/flip-words/FlipWords.vue2.js +14 -7
- package/dist/components/hyper-text/HyperText.vue.js +6 -97
- package/dist/components/hyper-text/HyperText.vue2.js +101 -0
- package/dist/components/letter-pullup/LetterPullup.vue.js +6 -38
- package/dist/components/letter-pullup/LetterPullup.vue2.js +40 -0
- package/dist/components/logo-cloud/AnimatedLogoCloud.vue.js +1 -1
- package/dist/components/magnetic-field/MagnetPuck.vue.d.ts +51 -0
- package/dist/components/magnetic-field/MagnetPuck.vue.js +7 -0
- package/dist/components/magnetic-field/MagnetPuck.vue2.js +191 -0
- package/dist/components/magnetic-field/MagneticField.vue.d.ts +39 -0
- package/dist/components/magnetic-field/MagneticField.vue.js +7 -0
- package/dist/components/magnetic-field/MagneticField.vue2.js +157 -0
- package/dist/components/magnetic-field/MagneticItem.vue.d.ts +28 -0
- package/dist/components/magnetic-field/MagneticItem.vue.js +7 -0
- package/dist/components/magnetic-field/MagneticItem.vue2.js +72 -0
- package/dist/components/magnetic-field/index.d.ts +10 -0
- package/dist/components/magnetic-field/magnetic-field-core.d.ts +163 -0
- package/dist/components/magnetic-field/magnetic-field-core.js +534 -0
- package/dist/components/magnetic-field/magnetic-field-source.d.ts +58 -0
- package/dist/components/magnetic-field/magnetic-field-source.js +58 -0
- package/dist/components/magnetic-field/types.d.ts +14 -0
- package/dist/components/magnetic-field/types.js +5 -0
- package/dist/components/matrix-rain/MatrixRain.vue.js +20 -1
- package/dist/components/matrix-rain/matrix-rain-core.d.ts +6 -0
- package/dist/components/matrix-rain/matrix-rain-core.js +28 -6
- package/dist/components/noise-reveal/NoiseReveal.vue.js +7 -0
- package/dist/components/noise-reveal/noise-reveal-core.js +23 -7
- package/dist/components/pixel-scene/PixelScene.vue.d.ts +60 -0
- package/dist/components/pixel-scene/PixelScene.vue.js +184 -0
- package/dist/components/pixel-scene/PixelScene.vue2.js +4 -0
- package/dist/components/pixel-scene/index.d.ts +4 -0
- package/dist/components/pixel-scene/pixel-scene-core.d.ts +256 -0
- package/dist/components/pixel-scene/pixel-scene-core.js +878 -0
- package/dist/components/pixel-scene/pixel-scene-hdr.d.ts +68 -0
- package/dist/components/pixel-scene/pixel-scene-hdr.js +312 -0
- package/dist/components/pixel-scene/pixel-scene-scenes.d.ts +31 -0
- package/dist/components/pixel-scene/pixel-scene-scenes.js +1074 -0
- package/dist/components/ripple/Ripple.vue.js +1 -1
- package/dist/components/ripple/Ripple.vue2.js +6 -1
- package/dist/components/sparkles/Sparkles.vue.js +10 -1
- package/dist/components/sparkles/sparkles-core.d.ts +6 -0
- package/dist/components/sparkles/sparkles-core.js +26 -2
- package/dist/components/sparkles-text/SparklesText.vue.js +6 -88
- package/dist/components/sparkles-text/SparklesText.vue2.js +100 -0
- package/dist/components/story-thread/StoryNode.vue.d.ts +11 -0
- package/dist/components/story-thread/StoryNode.vue.js +7 -0
- package/dist/components/story-thread/StoryNode.vue2.js +23 -0
- package/dist/components/story-thread/StoryThread.vue.d.ts +56 -0
- package/dist/components/story-thread/StoryThread.vue.js +7 -0
- package/dist/components/story-thread/StoryThread.vue2.js +103 -0
- package/dist/components/story-thread/index.d.ts +5 -0
- package/dist/components/story-thread/story-thread-core.d.ts +119 -0
- package/dist/components/story-thread/story-thread-core.js +491 -0
- package/dist/components/story-thread/types.d.ts +1 -0
- package/dist/components/sun-switch/SunSwitch.vue.d.ts +61 -0
- package/dist/components/sun-switch/SunSwitch.vue.js +7 -0
- package/dist/components/sun-switch/SunSwitch.vue2.js +559 -0
- package/dist/components/sun-switch/index.d.ts +4 -0
- package/dist/components/sun-switch/pixel-wave-core.d.ts +82 -0
- package/dist/components/sun-switch/pixel-wave-core.js +508 -0
- package/dist/components/sun-switch/sun-switch-core.d.ts +251 -0
- package/dist/components/sun-switch/sun-switch-core.js +546 -0
- package/dist/components/sun-switch/sun-switch-hdr.d.ts +70 -0
- package/dist/components/sun-switch/sun-switch-hdr.js +311 -0
- package/dist/components/terminal-text/TerminalText.vue.js +1 -1
- package/dist/components/terminal-text/TerminalText.vue2.js +36 -4
- package/dist/components/text-generate-effect/TextGenerateEffect.vue.js +5 -72
- package/dist/components/text-generate-effect/TextGenerateEffect.vue2.js +74 -1
- package/dist/components/text-reveal-card/TextRevealCard.vue.js +5 -101
- package/dist/components/text-reveal-card/TextRevealCard.vue2.js +98 -1
- package/dist/components/text-reveal-card/TextRevealStars.vue.js +1 -1
- package/dist/components/text-reveal-card/TextRevealStars.vue2.js +29 -12
- package/dist/components/tracing-beam/TracingBeam.vue.d.ts +20 -1
- package/dist/components/tracing-beam/TracingBeam.vue.js +5 -164
- package/dist/components/tracing-beam/TracingBeam.vue2.js +168 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.js +361 -338
- package/dist/styles.css +731 -89
- package/package.json +1 -1
- package/dist/components/hyper-text/HyperText.vue3.js +0 -5
- package/dist/components/letter-pullup/LetterPullup.vue3.js +0 -5
- package/dist/components/sparkles-text/SparklesText.vue3.js +0 -5
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MagneticField input adapters — framework-free, byte-identical in the Svelte,
|
|
3
|
+
* React and Vue trees (listed explicitly in shared-cores.json).
|
|
4
|
+
*
|
|
5
|
+
* The core (`magnetic-field-core.ts`) never listens to anything: it is fed a
|
|
6
|
+
* magnet position per channel and told when the layout may have moved. This
|
|
7
|
+
* module owns the two listener sets that do the feeding:
|
|
8
|
+
*
|
|
9
|
+
* - `attachPointerSource` turns a mouse or pen anywhere on the page into the
|
|
10
|
+
* `"pointer"` channel. It listens on the DOCUMENT, not the field root: the
|
|
11
|
+
* pull reaches `radius` px beyond every item, so most of the approach
|
|
12
|
+
* happens outside the root's box. The component gates the attachment with an
|
|
13
|
+
* in-view observer whose margin is that radius, so an off-screen field costs
|
|
14
|
+
* nothing.
|
|
15
|
+
* - `attachLayoutInvalidation` tells the core that rects may be stale after a
|
|
16
|
+
* scroll (of the page or of any scrolling ancestor) or a window resize.
|
|
17
|
+
*
|
|
18
|
+
* Handlers never compute anything: they store the latest client position in
|
|
19
|
+
* the core, which coalesces to at most one target pass per frame.
|
|
20
|
+
*
|
|
21
|
+
* Both functions return their own teardown and are safe to call during SSR
|
|
22
|
+
* (they attach nothing and return a no-op). No browser global is touched at
|
|
23
|
+
* import time.
|
|
24
|
+
*/
|
|
25
|
+
import type { MagneticFieldCore } from "./magnetic-field-core.js";
|
|
26
|
+
/**
|
|
27
|
+
* Feeds the core's `"pointer"` channel from a mouse or pen moving anywhere on
|
|
28
|
+
* `target` (the current document by default).
|
|
29
|
+
*
|
|
30
|
+
* - Touch is ignored: a finger has no hover, and a tap would yank the items
|
|
31
|
+
* toward it for one frame and drop them. Touch users drive the field with a
|
|
32
|
+
* `MagnetPuck` instead.
|
|
33
|
+
* - Only the primary pointer counts, so a second pen or mouse cannot fight the
|
|
34
|
+
* first.
|
|
35
|
+
* - A pointer over a `MagnetPuck` (hovering it, or dragging it with pointer
|
|
36
|
+
* capture) clears the channel instead of feeding it: the puck is the magnet
|
|
37
|
+
* there. Otherwise, letting go of a puck would release nothing, since the
|
|
38
|
+
* cursor resting on it would take over at the very same point. The channel
|
|
39
|
+
* comes back as soon as the pointer moves off the puck. With a `root`, only
|
|
40
|
+
* a puck inside it counts: another field's puck is that field's magnet.
|
|
41
|
+
* - The channel is cleared when the pointer leaves the page (to the browser
|
|
42
|
+
* chrome, another window, or a pen lifted out of hover range), when the
|
|
43
|
+
* window loses focus (a keyboard tab switch moves no pointer), and when the
|
|
44
|
+
* page is hidden. Without these, the last pull would freeze on screen until
|
|
45
|
+
* the pointer came back.
|
|
46
|
+
*/
|
|
47
|
+
export declare function attachPointerSource(core: Pick<MagneticFieldCore, "setClientSource" | "clearSource">, target?: Document, root?: Element): () => void;
|
|
48
|
+
/**
|
|
49
|
+
* Calls `core.invalidate()` whenever the field may have moved on screen
|
|
50
|
+
* without resizing: a scroll of the page or of any scrolling ancestor
|
|
51
|
+
* (captured on the window, since `scroll` does not bubble), or a window
|
|
52
|
+
* resize. Size changes of the root and the items themselves are the core's
|
|
53
|
+
* own `ResizeObserver`'s job.
|
|
54
|
+
*
|
|
55
|
+
* `invalidate()` only marks the cached rects dirty and wakes the loop when
|
|
56
|
+
* something is engaged, so a fast scroll costs one rect read per frame at most.
|
|
57
|
+
*/
|
|
58
|
+
export declare function attachLayoutInvalidation(core: Pick<MagneticFieldCore, "invalidate">): () => void;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
const NOOP = () => {
|
|
2
|
+
};
|
|
3
|
+
const PUCK_SELECTOR = ".ft-magnet-puck";
|
|
4
|
+
function attachPointerSource(core, target, root) {
|
|
5
|
+
const doc = target ?? (typeof document === "undefined" ? void 0 : document);
|
|
6
|
+
if (!doc) return NOOP;
|
|
7
|
+
const win = doc.defaultView;
|
|
8
|
+
const clear = () => core.clearSource("pointer");
|
|
9
|
+
const onMove = (event) => {
|
|
10
|
+
if (event.pointerType === "touch" || !event.isPrimary) return;
|
|
11
|
+
const target2 = event.target;
|
|
12
|
+
const puck = typeof target2?.closest === "function" ? target2.closest(PUCK_SELECTOR) : null;
|
|
13
|
+
if (puck && (!root || root.contains(puck))) {
|
|
14
|
+
clear();
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
core.setClientSource(event.clientX, event.clientY, "pointer");
|
|
18
|
+
};
|
|
19
|
+
const onOut = (event) => {
|
|
20
|
+
if (event.pointerType === "touch" || !event.isPrimary) return;
|
|
21
|
+
if (event.relatedTarget === null) clear();
|
|
22
|
+
};
|
|
23
|
+
const onLeave = (event) => {
|
|
24
|
+
if (event.pointerType === "touch" || !event.isPrimary) return;
|
|
25
|
+
clear();
|
|
26
|
+
};
|
|
27
|
+
const onVisibility = () => {
|
|
28
|
+
if (doc.visibilityState === "hidden") clear();
|
|
29
|
+
};
|
|
30
|
+
doc.addEventListener("pointermove", onMove, { passive: true });
|
|
31
|
+
doc.addEventListener("pointerout", onOut, { passive: true });
|
|
32
|
+
doc.addEventListener("pointerleave", onLeave, { passive: true });
|
|
33
|
+
doc.addEventListener("visibilitychange", onVisibility);
|
|
34
|
+
win?.addEventListener("blur", clear);
|
|
35
|
+
return () => {
|
|
36
|
+
doc.removeEventListener("pointermove", onMove);
|
|
37
|
+
doc.removeEventListener("pointerout", onOut);
|
|
38
|
+
doc.removeEventListener("pointerleave", onLeave);
|
|
39
|
+
doc.removeEventListener("visibilitychange", onVisibility);
|
|
40
|
+
win?.removeEventListener("blur", clear);
|
|
41
|
+
clear();
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
function attachLayoutInvalidation(core) {
|
|
45
|
+
if (typeof window === "undefined") return NOOP;
|
|
46
|
+
const win = window;
|
|
47
|
+
const onChange = () => core.invalidate();
|
|
48
|
+
win.addEventListener("scroll", onChange, { capture: true, passive: true });
|
|
49
|
+
win.addEventListener("resize", onChange, { passive: true });
|
|
50
|
+
return () => {
|
|
51
|
+
win.removeEventListener("scroll", onChange, { capture: true });
|
|
52
|
+
win.removeEventListener("resize", onChange);
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
export {
|
|
56
|
+
attachLayoutInvalidation,
|
|
57
|
+
attachPointerSource
|
|
58
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The contract between a `MagneticField` and the `MagneticItem`s and
|
|
3
|
+
* `MagnetPuck`s inside it.
|
|
4
|
+
*
|
|
5
|
+
* The context value is the field's registration hub (see
|
|
6
|
+
* `createMagneticFieldHub` in `magnetic-field-core.ts`): a stable object,
|
|
7
|
+
* created once per field, that buffers registrations until the field's core
|
|
8
|
+
* exists and replays them into it. Children only ever see these three methods.
|
|
9
|
+
*/
|
|
10
|
+
import { type InternalContext } from "../../internals/dom/context.js";
|
|
11
|
+
import type { MagneticFieldHub } from "./magnetic-field-core.js";
|
|
12
|
+
/** What a field publishes to its items and pucks. */
|
|
13
|
+
export type MagneticFieldContext = Pick<MagneticFieldHub, "register" | "updateItem" | "setSource">;
|
|
14
|
+
export declare const MAGNETIC_FIELD_KEY: InternalContext<MagneticFieldContext>;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { defineComponent, useTemplateRef, onMounted, onBeforeUnmount, watch, createElementBlock, openBlock, normalizeClass, unref } from "vue";
|
|
2
2
|
import { cn } from "../../utils.js";
|
|
3
|
+
import { useReducedMotion } from "../../internals/motion/use-media-query.js";
|
|
3
4
|
import { createMatrixRain } from "./matrix-rain-core.js";
|
|
4
5
|
const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
5
6
|
...{ name: "MatrixRain", inheritAttrs: false },
|
|
@@ -16,10 +17,21 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
16
17
|
const canvasRef = useTemplateRef("canvas");
|
|
17
18
|
let engine = null;
|
|
18
19
|
let observer = null;
|
|
20
|
+
const reducedMotion = useReducedMotion();
|
|
19
21
|
onMounted(() => {
|
|
20
22
|
const canvas = canvasRef.value;
|
|
21
23
|
if (!canvas) return;
|
|
22
|
-
engine = createMatrixRain(
|
|
24
|
+
engine = createMatrixRain(
|
|
25
|
+
{ canvas },
|
|
26
|
+
{
|
|
27
|
+
color: __props.color,
|
|
28
|
+
speed: __props.speed,
|
|
29
|
+
density: __props.density,
|
|
30
|
+
glyphSize: __props.glyphSize,
|
|
31
|
+
fadeOpacity: __props.fadeOpacity,
|
|
32
|
+
reducedMotion: reducedMotion.value
|
|
33
|
+
}
|
|
34
|
+
);
|
|
23
35
|
if (!engine) return;
|
|
24
36
|
observer = new ResizeObserver(() => engine?.resize());
|
|
25
37
|
observer.observe(canvas);
|
|
@@ -44,6 +56,13 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
44
56
|
},
|
|
45
57
|
{ flush: "post" }
|
|
46
58
|
);
|
|
59
|
+
watch(
|
|
60
|
+
reducedMotion,
|
|
61
|
+
(next) => {
|
|
62
|
+
engine?.setOptions({ reducedMotion: next });
|
|
63
|
+
},
|
|
64
|
+
{ flush: "post" }
|
|
65
|
+
);
|
|
47
66
|
return (_ctx, _cache) => {
|
|
48
67
|
return openBlock(), createElementBlock("canvas", {
|
|
49
68
|
ref: "canvas",
|
|
@@ -18,6 +18,12 @@ export interface MatrixRainLiveOptions {
|
|
|
18
18
|
glyphSize?: number;
|
|
19
19
|
/** Alpha of the per-frame fade-trail rectangle. Per-frame. */
|
|
20
20
|
fadeOpacity?: number;
|
|
21
|
+
/**
|
|
22
|
+
* Reduced-motion preference, owned by the wrapper (the core stays free of
|
|
23
|
+
* `matchMedia`). When true the engine paints one still frame and idles; a
|
|
24
|
+
* flip back to false resumes the loop.
|
|
25
|
+
*/
|
|
26
|
+
reducedMotion?: boolean;
|
|
21
27
|
}
|
|
22
28
|
export interface MatrixRainEngine {
|
|
23
29
|
setOptions(next: Partial<MatrixRainLiveOptions>): void;
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
const GLYPHS = "アイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワヲンABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789@#$%&";
|
|
2
|
+
const STILL_PRE_ROLL_STEPS = 80;
|
|
2
3
|
const DEFAULTS = {
|
|
3
4
|
color: "#00ff41",
|
|
4
5
|
speed: 1,
|
|
5
6
|
density: 1,
|
|
6
7
|
glyphSize: 16,
|
|
7
|
-
fadeOpacity: 0.05
|
|
8
|
+
fadeOpacity: 0.05,
|
|
9
|
+
reducedMotion: false
|
|
8
10
|
};
|
|
9
11
|
function merge(base, next) {
|
|
10
12
|
return {
|
|
@@ -12,7 +14,8 @@ function merge(base, next) {
|
|
|
12
14
|
speed: next.speed ?? base.speed,
|
|
13
15
|
density: next.density ?? base.density,
|
|
14
16
|
glyphSize: next.glyphSize ?? base.glyphSize,
|
|
15
|
-
fadeOpacity: next.fadeOpacity ?? base.fadeOpacity
|
|
17
|
+
fadeOpacity: next.fadeOpacity ?? base.fadeOpacity,
|
|
18
|
+
reducedMotion: next.reducedMotion ?? base.reducedMotion
|
|
16
19
|
};
|
|
17
20
|
}
|
|
18
21
|
function createMatrixRain(elements, options, random = Math.random) {
|
|
@@ -47,9 +50,12 @@ function createMatrixRain(elements, options, random = Math.random) {
|
|
|
47
50
|
ctx.fillStyle = "black";
|
|
48
51
|
ctx.fillRect(0, 0, canvasW, canvasH);
|
|
49
52
|
initColumns(canvasW, canvasH);
|
|
53
|
+
if (opts.reducedMotion && rafId === null) paintStill();
|
|
50
54
|
}
|
|
51
|
-
function
|
|
52
|
-
|
|
55
|
+
function paintStill() {
|
|
56
|
+
for (let i = 0; i < STILL_PRE_ROLL_STEPS; i++) step(true);
|
|
57
|
+
}
|
|
58
|
+
function step(advanceNow = false) {
|
|
53
59
|
const w = canvasW;
|
|
54
60
|
const h = canvasH;
|
|
55
61
|
ctx.fillStyle = `rgba(0, 0, 0, ${opts.fadeOpacity})`;
|
|
@@ -59,7 +65,7 @@ function createMatrixRain(elements, options, random = Math.random) {
|
|
|
59
65
|
ctx.shadowColor = opts.color;
|
|
60
66
|
const rowsPerFrame = Math.max(1, opts.speed);
|
|
61
67
|
frameCount++;
|
|
62
|
-
const shouldAdvance = opts.speed >= 1 || frameCount % Math.round(1 / opts.speed) === 0;
|
|
68
|
+
const shouldAdvance = advanceNow || opts.speed >= 1 || frameCount % Math.round(1 / opts.speed) === 0;
|
|
63
69
|
if (shouldAdvance) {
|
|
64
70
|
for (let i = 0; i < columns.length; i++) {
|
|
65
71
|
const column = columns[i];
|
|
@@ -79,10 +85,18 @@ function createMatrixRain(elements, options, random = Math.random) {
|
|
|
79
85
|
}
|
|
80
86
|
}
|
|
81
87
|
ctx.shadowBlur = 0;
|
|
88
|
+
}
|
|
89
|
+
function draw() {
|
|
90
|
+
if (destroyed) return;
|
|
91
|
+
step();
|
|
92
|
+
if (opts.reducedMotion) {
|
|
93
|
+
rafId = null;
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
82
96
|
rafId = requestAnimationFrame(draw);
|
|
83
97
|
}
|
|
84
98
|
resize();
|
|
85
|
-
rafId = requestAnimationFrame(draw);
|
|
99
|
+
if (!opts.reducedMotion) rafId = requestAnimationFrame(draw);
|
|
86
100
|
return {
|
|
87
101
|
setOptions(next) {
|
|
88
102
|
if (destroyed) return;
|
|
@@ -90,6 +104,14 @@ function createMatrixRain(elements, options, random = Math.random) {
|
|
|
90
104
|
opts = merge(opts, next);
|
|
91
105
|
if (opts.glyphSize !== prev.glyphSize || opts.density !== prev.density) {
|
|
92
106
|
resize();
|
|
107
|
+
} else if (opts.reducedMotion && rafId === null && (opts.color !== prev.color || opts.fadeOpacity !== prev.fadeOpacity)) {
|
|
108
|
+
ctx.fillStyle = "black";
|
|
109
|
+
ctx.fillRect(0, 0, canvasW, canvasH);
|
|
110
|
+
initColumns(canvasW, canvasH);
|
|
111
|
+
paintStill();
|
|
112
|
+
}
|
|
113
|
+
if (prev.reducedMotion && !opts.reducedMotion && rafId === null) {
|
|
114
|
+
rafId = requestAnimationFrame(draw);
|
|
93
115
|
}
|
|
94
116
|
},
|
|
95
117
|
resize,
|
|
@@ -76,6 +76,13 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
76
76
|
},
|
|
77
77
|
{ flush: "post" }
|
|
78
78
|
);
|
|
79
|
+
watch(
|
|
80
|
+
[engine, reducedMotion],
|
|
81
|
+
([currentEngine, currentReduced]) => {
|
|
82
|
+
currentEngine?.setOptions({ reducedMotion: currentReduced });
|
|
83
|
+
},
|
|
84
|
+
{ flush: "post" }
|
|
85
|
+
);
|
|
79
86
|
watch(
|
|
80
87
|
[() => __props.trigger, engine, () => __props.revealed],
|
|
81
88
|
([currentTrigger, currentEngine, currentRevealed]) => {
|
|
@@ -196,6 +196,7 @@ function createNoiseReveal(el, options) {
|
|
|
196
196
|
uniforms.uTexture.value = loaded;
|
|
197
197
|
const image = loaded.image;
|
|
198
198
|
uniforms.uImageRes.value.set(image.naturalWidth || 1, image.naturalHeight || 1);
|
|
199
|
+
wake();
|
|
199
200
|
});
|
|
200
201
|
let destroyed = false;
|
|
201
202
|
let reducedMotion = options.reducedMotion ?? false;
|
|
@@ -207,11 +208,12 @@ function createNoiseReveal(el, options) {
|
|
|
207
208
|
if (reducedMotion) {
|
|
208
209
|
progress = value;
|
|
209
210
|
tween.active = false;
|
|
210
|
-
|
|
211
|
+
} else {
|
|
212
|
+
tween.from = progress;
|
|
213
|
+
tween.start = performance.now();
|
|
214
|
+
tween.active = true;
|
|
211
215
|
}
|
|
212
|
-
|
|
213
|
-
tween.start = performance.now();
|
|
214
|
-
tween.active = true;
|
|
216
|
+
wake();
|
|
215
217
|
};
|
|
216
218
|
const handleResize = () => {
|
|
217
219
|
if (destroyed) return;
|
|
@@ -221,27 +223,41 @@ function createNoiseReveal(el, options) {
|
|
|
221
223
|
camera.updateProjectionMatrix();
|
|
222
224
|
renderer.setSize(r.width, r.height, false);
|
|
223
225
|
fitPlane(r.width, r.height);
|
|
226
|
+
wake();
|
|
224
227
|
};
|
|
225
228
|
window.addEventListener("resize", handleResize);
|
|
226
229
|
const clock = new THREE.Clock();
|
|
227
230
|
let animationId = 0;
|
|
228
|
-
|
|
231
|
+
function wake() {
|
|
232
|
+
if (destroyed || animationId !== 0) return;
|
|
229
233
|
animationId = requestAnimationFrame(animate);
|
|
234
|
+
}
|
|
235
|
+
const animate = () => {
|
|
236
|
+
animationId = 0;
|
|
230
237
|
if (tween.active) {
|
|
231
238
|
const t = getProgress(performance.now() - tween.start, duration * 1e3);
|
|
232
239
|
progress = lerp(tween.from, tween.to, easeInOutCubic(t));
|
|
233
240
|
if (t >= 1) tween.active = false;
|
|
234
241
|
}
|
|
235
242
|
uniforms.uProgress.value = progress;
|
|
236
|
-
uniforms.uTime.value = clock.getElapsedTime();
|
|
243
|
+
if (!reducedMotion) uniforms.uTime.value = clock.getElapsedTime();
|
|
237
244
|
renderer.render(scene, camera);
|
|
245
|
+
if (reducedMotion && !tween.active) return;
|
|
246
|
+
animationId = requestAnimationFrame(animate);
|
|
238
247
|
};
|
|
239
248
|
animate();
|
|
240
249
|
if (options.target !== void 0) setTarget(options.target);
|
|
241
250
|
return {
|
|
242
251
|
setOptions(next) {
|
|
243
252
|
if (destroyed) return;
|
|
244
|
-
if (next.reducedMotion !== void 0
|
|
253
|
+
if (next.reducedMotion !== void 0 && next.reducedMotion !== reducedMotion) {
|
|
254
|
+
reducedMotion = next.reducedMotion;
|
|
255
|
+
if (reducedMotion && tween.active) {
|
|
256
|
+
progress = tween.to;
|
|
257
|
+
tween.active = false;
|
|
258
|
+
}
|
|
259
|
+
wake();
|
|
260
|
+
}
|
|
245
261
|
if (next.target !== void 0) setTarget(next.target);
|
|
246
262
|
},
|
|
247
263
|
resize: handleResize,
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { HTMLAttributes } from "vue";
|
|
2
|
+
import type { PixelSceneName } from "./pixel-scene-scenes.js";
|
|
3
|
+
import type { PixelSceneHdrLook } from "./pixel-scene-hdr.js";
|
|
4
|
+
export type { PixelSceneName };
|
|
5
|
+
/**
|
|
6
|
+
* PixelScene — an animated pixel-art landscape on a dot grid.
|
|
7
|
+
*
|
|
8
|
+
* At rest only sparse ink dots and the lit cells show; a round lens that
|
|
9
|
+
* follows the pointer reveals the picture in full colour, with a dithered
|
|
10
|
+
* rim. Day and night are two complete palettes. On HDR displays the lit
|
|
11
|
+
* cells (sun, moon, windows, stars, fireflies, the lens field) are redrawn
|
|
12
|
+
* as hard squares brighter than SDR white in a WebGPU layer.
|
|
13
|
+
*
|
|
14
|
+
* The engine, the scenes and the HDR layer live in three framework-free
|
|
15
|
+
* cores; this file owns the markup and pushes props into the engine. The
|
|
16
|
+
* engine owns its observers, the reduced-motion query and the pointer
|
|
17
|
+
* listeners.
|
|
18
|
+
*/
|
|
19
|
+
export interface PixelSceneProps {
|
|
20
|
+
/** Which landscape to paint */
|
|
21
|
+
scene?: PixelSceneName;
|
|
22
|
+
/** Night palette (stars, moon, lit windows) instead of day. Never changed by the component. */
|
|
23
|
+
night?: boolean;
|
|
24
|
+
/** Grid pitch in CSS px (clamped 4–32; grows on very large boxes) */
|
|
25
|
+
cell?: number;
|
|
26
|
+
/** Square dot edge in CSS px, at most `cell` */
|
|
27
|
+
dot?: number;
|
|
28
|
+
/** Show full colour under a round lens that follows the pointer */
|
|
29
|
+
lens?: boolean;
|
|
30
|
+
/** Lens radius in cells */
|
|
31
|
+
lensRadius?: number;
|
|
32
|
+
/** On HDR displays, draw lit cells brighter than SDR white in a WebGPU layer */
|
|
33
|
+
hdr?: boolean;
|
|
34
|
+
/** HDR rendering: `calibrated` (glow 1 = the SDR dot, sRGB) or `vivid` (the prototype's hotter, display-p3 look) */
|
|
35
|
+
hdrLook?: PixelSceneHdrLook;
|
|
36
|
+
/** Colour of the resting dots; any CSS colour, `currentColor` resolved on the host */
|
|
37
|
+
ink?: string;
|
|
38
|
+
/** Freeze the scene's animations (the lens still follows the pointer) */
|
|
39
|
+
paused?: boolean;
|
|
40
|
+
/** Animate a change of `night` as a dithered wave from the sun (never under reduced motion) */
|
|
41
|
+
wave?: boolean;
|
|
42
|
+
/** `[day, night]` background painted by the scene itself; the wave carries it. Default: transparent */
|
|
43
|
+
surfaces?: readonly [day: string, night: string];
|
|
44
|
+
/** `[day, night]` dot colours, swapped by the wave; overrides `ink` */
|
|
45
|
+
inks?: readonly [day: string, night: string];
|
|
46
|
+
/** Additional classes on the host — give it a height */
|
|
47
|
+
class?: HTMLAttributes["class"];
|
|
48
|
+
}
|
|
49
|
+
declare const _default: typeof __VLS_export;
|
|
50
|
+
export default _default;
|
|
51
|
+
declare const __VLS_export: __VLS_WithSlots<import("vue").DefineComponent<PixelSceneProps, {
|
|
52
|
+
ref: Readonly<import("vue").ShallowRef<HTMLDivElement | null>>;
|
|
53
|
+
}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<PixelSceneProps> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>, {
|
|
54
|
+
default?(): unknown;
|
|
55
|
+
}>;
|
|
56
|
+
type __VLS_WithSlots<T, S> = T & {
|
|
57
|
+
new (): {
|
|
58
|
+
$slots: S;
|
|
59
|
+
};
|
|
60
|
+
};
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import { defineComponent, useAttrs, useTemplateRef, ref, onMounted, onBeforeUnmount, watch, createElementBlock, openBlock, mergeProps, unref, createElementVNode, createCommentVNode, renderSlot } from "vue";
|
|
2
|
+
import { cn } from "../../utils.js";
|
|
3
|
+
import { createPixelScene } from "./pixel-scene-core.js";
|
|
4
|
+
import { getScenePainter } from "./pixel-scene-scenes.js";
|
|
5
|
+
import { pixelSceneHdrAvailable, startPixelSceneHdr, PIXEL_SCENE_HDR_RESTARTS, PIXEL_SCENE_HDR_RESTART_MS } from "./pixel-scene-hdr.js";
|
|
6
|
+
const _hoisted_1 = ["data-scene", "data-night", "data-hdr"];
|
|
7
|
+
const _hoisted_2 = {
|
|
8
|
+
ref: "canvas",
|
|
9
|
+
class: "pointer-events-none absolute inset-0 block h-full w-full",
|
|
10
|
+
"aria-hidden": "true"
|
|
11
|
+
};
|
|
12
|
+
const _hoisted_3 = {
|
|
13
|
+
key: 1,
|
|
14
|
+
class: "pixel-scene__content relative z-[1] h-full w-full"
|
|
15
|
+
};
|
|
16
|
+
const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
17
|
+
...{ name: "PixelScene", inheritAttrs: false },
|
|
18
|
+
__name: "PixelScene",
|
|
19
|
+
props: {
|
|
20
|
+
scene: { default: "alpine" },
|
|
21
|
+
night: { type: Boolean, default: false },
|
|
22
|
+
cell: { default: 5 },
|
|
23
|
+
dot: { default: 4 },
|
|
24
|
+
lens: { type: Boolean, default: true },
|
|
25
|
+
lensRadius: { default: 21 },
|
|
26
|
+
hdr: { type: Boolean, default: true },
|
|
27
|
+
hdrLook: { default: "calibrated" },
|
|
28
|
+
ink: { default: "currentColor" },
|
|
29
|
+
paused: { type: Boolean, default: false },
|
|
30
|
+
wave: { type: Boolean, default: true },
|
|
31
|
+
surfaces: {},
|
|
32
|
+
inks: {},
|
|
33
|
+
class: { type: [Boolean, null, String, Object, Array] }
|
|
34
|
+
},
|
|
35
|
+
setup(__props, { expose: __expose }) {
|
|
36
|
+
const attrs = useAttrs();
|
|
37
|
+
const hostEl = useTemplateRef("host");
|
|
38
|
+
const canvasEl = useTemplateRef("canvas");
|
|
39
|
+
const hdrCanvas = useTemplateRef("hdrCanvas");
|
|
40
|
+
const mounted = ref(false);
|
|
41
|
+
const hdrCapable = ref(false);
|
|
42
|
+
const hdrOn = ref(false);
|
|
43
|
+
const hdrRun = ref(0);
|
|
44
|
+
let hdrRestarts = 0;
|
|
45
|
+
const engineReady = ref(false);
|
|
46
|
+
let engine = null;
|
|
47
|
+
__expose({ ref: hostEl });
|
|
48
|
+
onMounted(() => {
|
|
49
|
+
mounted.value = true;
|
|
50
|
+
hdrCapable.value = __props.hdr && pixelSceneHdrAvailable();
|
|
51
|
+
const host = hostEl.value;
|
|
52
|
+
const canvas = canvasEl.value;
|
|
53
|
+
if (!host || !canvas) return;
|
|
54
|
+
engine = createPixelScene(
|
|
55
|
+
{ host, canvas },
|
|
56
|
+
{
|
|
57
|
+
painter: getScenePainter(__props.scene),
|
|
58
|
+
night: __props.night,
|
|
59
|
+
cell: __props.cell,
|
|
60
|
+
dot: __props.dot,
|
|
61
|
+
lens: __props.lens,
|
|
62
|
+
lensRadius: __props.lensRadius,
|
|
63
|
+
ink: __props.ink,
|
|
64
|
+
paused: __props.paused,
|
|
65
|
+
wave: __props.wave,
|
|
66
|
+
surfaces: __props.surfaces ?? null,
|
|
67
|
+
inks: __props.inks ?? null
|
|
68
|
+
}
|
|
69
|
+
);
|
|
70
|
+
engineReady.value = engine !== null;
|
|
71
|
+
});
|
|
72
|
+
onBeforeUnmount(() => {
|
|
73
|
+
engine?.destroy();
|
|
74
|
+
engine = null;
|
|
75
|
+
engineReady.value = false;
|
|
76
|
+
mounted.value = false;
|
|
77
|
+
});
|
|
78
|
+
watch(
|
|
79
|
+
() => ({ painter: getScenePainter(__props.scene), night: __props.night }),
|
|
80
|
+
(next) => engine?.setOptions(next),
|
|
81
|
+
{ flush: "post" }
|
|
82
|
+
);
|
|
83
|
+
watch(
|
|
84
|
+
() => ({ cell: __props.cell, dot: __props.dot }),
|
|
85
|
+
(next) => engine?.setOptions(next),
|
|
86
|
+
{ flush: "post" }
|
|
87
|
+
);
|
|
88
|
+
watch(
|
|
89
|
+
() => ({
|
|
90
|
+
lens: __props.lens,
|
|
91
|
+
lensRadius: __props.lensRadius,
|
|
92
|
+
ink: __props.ink,
|
|
93
|
+
paused: __props.paused,
|
|
94
|
+
wave: __props.wave,
|
|
95
|
+
surfaces: __props.surfaces ?? null,
|
|
96
|
+
inks: __props.inks ?? null
|
|
97
|
+
}),
|
|
98
|
+
(next) => engine?.setOptions(next),
|
|
99
|
+
{ flush: "post" }
|
|
100
|
+
);
|
|
101
|
+
watch(
|
|
102
|
+
() => __props.hdr,
|
|
103
|
+
(on) => {
|
|
104
|
+
hdrCapable.value = mounted.value && on && pixelSceneHdrAvailable();
|
|
105
|
+
}
|
|
106
|
+
);
|
|
107
|
+
watch(
|
|
108
|
+
[hdrCanvas, engineReady, hdrCapable, hdrRun, () => __props.hdrLook],
|
|
109
|
+
([canvas, ready, capable], _old, onCleanup) => {
|
|
110
|
+
if (!canvas || !ready || !capable) return;
|
|
111
|
+
let cancelled = false;
|
|
112
|
+
let stop = null;
|
|
113
|
+
let retry = null;
|
|
114
|
+
const restart = () => {
|
|
115
|
+
if (hdrRestarts >= PIXEL_SCENE_HDR_RESTARTS) {
|
|
116
|
+
hdrCapable.value = false;
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
hdrRestarts++;
|
|
120
|
+
retry = setTimeout(() => {
|
|
121
|
+
retry = null;
|
|
122
|
+
hdrRun.value++;
|
|
123
|
+
}, PIXEL_SCENE_HDR_RESTART_MS * hdrRestarts);
|
|
124
|
+
};
|
|
125
|
+
void startPixelSceneHdr(canvas, __props.hdrLook).then((layer) => {
|
|
126
|
+
if (cancelled || !engine) {
|
|
127
|
+
layer?.destroy();
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
if (!layer) {
|
|
131
|
+
if (hdrRestarts === 0) hdrCapable.value = false;
|
|
132
|
+
else restart();
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
const target = engine;
|
|
136
|
+
target.setOptions({ onFrame: (frame) => layer.render(frame) });
|
|
137
|
+
hdrOn.value = true;
|
|
138
|
+
stop = () => {
|
|
139
|
+
target.setOptions({ onFrame: null });
|
|
140
|
+
layer.destroy();
|
|
141
|
+
hdrOn.value = false;
|
|
142
|
+
};
|
|
143
|
+
void layer.lost.then(() => {
|
|
144
|
+
if (cancelled) return;
|
|
145
|
+
stop?.();
|
|
146
|
+
stop = null;
|
|
147
|
+
restart();
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
onCleanup(() => {
|
|
151
|
+
cancelled = true;
|
|
152
|
+
stop?.();
|
|
153
|
+
stop = null;
|
|
154
|
+
if (retry !== null) clearTimeout(retry);
|
|
155
|
+
});
|
|
156
|
+
},
|
|
157
|
+
{ flush: "post" }
|
|
158
|
+
);
|
|
159
|
+
return (_ctx, _cache) => {
|
|
160
|
+
return openBlock(), createElementBlock("div", mergeProps({
|
|
161
|
+
ref: "host",
|
|
162
|
+
class: unref(cn)("pixel-scene relative overflow-hidden", __props.class),
|
|
163
|
+
"data-scene": __props.scene,
|
|
164
|
+
"data-night": __props.night ? "" : void 0,
|
|
165
|
+
"data-hdr": hdrOn.value ? "" : void 0
|
|
166
|
+
}, unref(attrs)), [
|
|
167
|
+
createElementVNode("canvas", _hoisted_2, null, 512),
|
|
168
|
+
hdrCapable.value ? (openBlock(), createElementBlock("canvas", {
|
|
169
|
+
key: 0,
|
|
170
|
+
ref_key: "hdrCanvas",
|
|
171
|
+
ref: hdrCanvas,
|
|
172
|
+
class: "pixel-scene__hdr pointer-events-none absolute inset-0 block h-full w-full",
|
|
173
|
+
"aria-hidden": "true"
|
|
174
|
+
}, null, 512)) : createCommentVNode("", true),
|
|
175
|
+
_ctx.$slots.default ? (openBlock(), createElementBlock("div", _hoisted_3, [
|
|
176
|
+
renderSlot(_ctx.$slots, "default")
|
|
177
|
+
])) : createCommentVNode("", true)
|
|
178
|
+
], 16, _hoisted_1);
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
export {
|
|
183
|
+
_sfc_main as default
|
|
184
|
+
};
|