fancy-ui-vue 0.4.1 → 0.5.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.
- package/README.md +12 -12
- package/dist/components/frost-glass/FrostGlass.vue.d.ts +31 -0
- package/dist/components/frost-glass/FrostGlass.vue.js +90 -0
- package/dist/components/frost-glass/FrostGlass.vue2.js +4 -0
- package/dist/components/frost-glass/frost-glass-core.d.ts +155 -0
- package/dist/components/frost-glass/frost-glass-core.js +820 -0
- package/dist/components/frost-glass/index.d.ts +2 -0
- package/dist/components/gift-reveal/GiftReveal.vue.d.ts +50 -0
- package/dist/components/gift-reveal/GiftReveal.vue.js +7 -0
- package/dist/components/gift-reveal/GiftReveal.vue2.js +177 -0
- package/dist/components/gift-reveal/gift-reveal-core.d.ts +109 -0
- package/dist/components/gift-reveal/gift-reveal-core.js +116 -0
- package/dist/components/gift-reveal/index.d.ts +2 -0
- package/dist/components/ornament/Ornament.vue.d.ts +29 -0
- package/dist/components/ornament/Ornament.vue.js +112 -0
- package/dist/components/ornament/Ornament.vue2.js +4 -0
- package/dist/components/ornament/index.d.ts +2 -0
- package/dist/components/ornament/ornament-core.d.ts +177 -0
- package/dist/components/ornament/ornament-core.js +861 -0
- package/dist/components/snowfall/Snowfall.vue.d.ts +29 -0
- package/dist/components/snowfall/Snowfall.vue.js +81 -0
- package/dist/components/snowfall/Snowfall.vue2.js +4 -0
- package/dist/components/snowfall/index.d.ts +2 -0
- package/dist/components/snowfall/snowfall-core.d.ts +119 -0
- package/dist/components/snowfall/snowfall-core.js +483 -0
- package/dist/components/string-lights/StringLights.vue.d.ts +35 -0
- package/dist/components/string-lights/StringLights.vue.js +7 -0
- package/dist/components/string-lights/StringLights.vue2.js +98 -0
- package/dist/components/string-lights/index.d.ts +2 -0
- package/dist/components/string-lights/string-lights-core.d.ts +157 -0
- package/dist/components/string-lights/string-lights-core.js +228 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +326 -316
- package/dist/styles.css +1341 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@ Animated UI components for **Vue 3.5+**, styled with Tailwind CSS v4 — the
|
|
|
10
10
|

|
|
11
11
|

|
|
12
12
|

|
|
13
|
-

|
|
14
14
|

|
|
15
15
|
|
|
16
16
|
<p align="center">
|
|
@@ -40,10 +40,10 @@ Animated UI components for **Vue 3.5+**, styled with Tailwind CSS v4 — the
|
|
|
40
40
|
|
|
41
41
|
## Features
|
|
42
42
|
|
|
43
|
-
- **
|
|
43
|
+
- **160 components** — core primitives (forms, navigation, overlays) alongside buttons, text animations, backgrounds, cursors, AI/chat building blocks and a micro-interactions collection
|
|
44
44
|
- **Motion that feels physical** — beams of light, liquid-metal and neon borders, a physical flip card, a before/after slider with a motion trail, a datamosh page transition; springs and WebGL where they earn their keep
|
|
45
45
|
- **Idiomatic Vue 3.5** — `<script setup>` single-file components, reactive props destructuring, `defineModel` for every bindable (`v-model:<name>`), snippets as named and scoped slots, `defineExpose` wherever the Svelte source exposes a `ref`; every other prop keeps its Svelte name
|
|
46
|
-
- **Same components, three frameworks** — All
|
|
46
|
+
- **Same components, three frameworks** — All 160 components of `fancy-ui-svelte` are ported, under the same names and with the same visual contract; the [Svelte package](https://github.com/RamaHerbin/fancy-ui#readme) is the reference, [`fancy-ui-react`](https://github.com/RamaHerbin/fancy-ui/tree/main/react#readme) the React edition, and parity is checked in CI
|
|
47
47
|
- **Tailwind CSS v4** — one CSS import, semantic colour tokens, light and dark themes that follow the OS or a `.dark` class
|
|
48
48
|
- **Accessible and SSR-safe** — keyboard support where it applies, `prefers-reduced-motion` respected, a `seed` prop wherever the source randomises in render so server and client agree, clean hydration under Nuxt, canvas and WebGL work deferred to mount
|
|
49
49
|
- **Opt-in sound** — eleven synthesised interface cues, a `SoundToggle` switch and the `useSound` / `useSoundFeedback` composables; silent until the user turns it on
|
|
@@ -148,7 +148,7 @@ Those two imports are the whole setup. `tailwind.css` also declares every semant
|
|
|
148
148
|
Out of the box the package follows the operating-system preference: `dark:` utilities and the components' `light-dark()` colours both switch with `prefers-color-scheme`, so an app that never touches dark mode already looks right on a dark desktop. To control it yourself, put `dark` or `light` on `<html>` (or on any ancestor of the subtree you want to force) and both halves follow the class instead:
|
|
149
149
|
|
|
150
150
|
```html
|
|
151
|
-
<html class="dark">
|
|
151
|
+
<html class="dark"></html>
|
|
152
152
|
```
|
|
153
153
|
|
|
154
154
|
`tailwind.css` is what makes that work, in three parts: it declares the `.dark` token block, it declares a `dark` variant that matches a `.dark` ancestor OR the media query (unless a `.light` ancestor opts out), and it sets `color-scheme: light dark` on `:root` with `.dark` / `.light` overrides so the components' `light-dark()` colours — and the browser's own form controls, scrollbars and caret — resolve the same way. An app that declares its own `@custom-variant dark` after the import keeps its own definition.
|
|
@@ -225,14 +225,14 @@ The consumer app under `examples/` is `nuxt-app`, which resolves `fancy-ui-vue`
|
|
|
225
225
|
|
|
226
226
|
`build` does more than build. After Vite and `vue-tsc` it runs six scripts in `vue/scripts/`, each guarding something no other gate can see:
|
|
227
227
|
|
|
228
|
-
| Script | What it stops
|
|
229
|
-
| --------------------------- |
|
|
228
|
+
| Script | What it stops |
|
|
229
|
+
| --------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
230
230
|
| `strip-dts-css-imports.mjs` | `vue-tsc` copies each component's `import "./x.css"` into its `.d.ts`, naming a file dist does not ship — one TS2307 per component for any consumer without `skipLibCheck` |
|
|
231
|
-
| `check-dist-names.mjs` | a minified build shipping `AnimatedBeam` as `const ut = ...` in every consumer's devtools tree and stack traces
|
|
232
|
-
| `prune-orphan-dts.mjs` | a declaration under `dist/internals/` with no runtime module behind it, typing an import that cannot load
|
|
233
|
-
| `check-dist-shape.mjs` | a test rig reaching the tarball, a declaration pointing at a file that is not there, an SFC without `<script setup>`, a bare import of a package nobody declared
|
|
234
|
-
| `smoke-dist.mjs` | the built artifact never being executed: it imports every module with no DOM, server-renders each component export, and holds a gzip budget over the emitted JS and CSS
|
|
235
|
-
| `ensure-styles-css.mjs` | the `./styles.css` subpath being declared while no stylesheet was emitted
|
|
231
|
+
| `check-dist-names.mjs` | a minified build shipping `AnimatedBeam` as `const ut = ...` in every consumer's devtools tree and stack traces |
|
|
232
|
+
| `prune-orphan-dts.mjs` | a declaration under `dist/internals/` with no runtime module behind it, typing an import that cannot load |
|
|
233
|
+
| `check-dist-shape.mjs` | a test rig reaching the tarball, a declaration pointing at a file that is not there, an SFC without `<script setup>`, a bare import of a package nobody declared |
|
|
234
|
+
| `smoke-dist.mjs` | the built artifact never being executed: it imports every module with no DOM, server-renders each component export, and holds a gzip budget over the emitted JS and CSS |
|
|
235
|
+
| `ensure-styles-css.mjs` | the `./styles.css` subpath being declared while no stylesheet was emitted |
|
|
236
236
|
|
|
237
237
|
`test:scripts` runs `dist-gates.test.mjs`, which tests the gates' own logic (what counts as a component, what the sweep counts) so a gate cannot go quiet without a test noticing. `check-matrix.mjs` (`check:matrix`) holds the migration matrix to the Svelte reference, and `vue-floor-consumer.mjs` is the CI-only floor check above; neither is part of `build`.
|
|
238
238
|
|
|
@@ -407,7 +407,7 @@ Components are named by their exported Vue name.
|
|
|
407
407
|
|
|
408
408
|
| Technology | Version | Purpose |
|
|
409
409
|
| -------------------------------------------- | ------- | ------------------- |
|
|
410
|
-
| [Vue](https://vuejs.org)
|
|
410
|
+
| [Vue](https://vuejs.org) | 3.5 | UI framework |
|
|
411
411
|
| [Tailwind CSS](https://tailwindcss.com) | 4 | Styling |
|
|
412
412
|
| [TypeScript](https://www.typescriptlang.org) | 5 | Type safety |
|
|
413
413
|
| [Vite](https://vite.dev) | 7 | Library build |
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { HTMLAttributes } from "vue";
|
|
2
|
+
export interface FrostGlassProps {
|
|
3
|
+
/** How far the frost reaches toward the centre, 0..1 of the half short side. */
|
|
4
|
+
coverage?: number;
|
|
5
|
+
/** Seconds the frost takes to grow in from the edges on mount. 0 shows it grown. */
|
|
6
|
+
growth?: number;
|
|
7
|
+
/** The pointer melts a trail through the frost. */
|
|
8
|
+
melt?: boolean;
|
|
9
|
+
/** Seconds a fully melted spot takes to freeze over again. */
|
|
10
|
+
refreeze?: number;
|
|
11
|
+
/** Cold tint of the ice, `#rgb` or `#rrggbb`. */
|
|
12
|
+
tint?: string;
|
|
13
|
+
/** Strength of the slow glints on the crystal ridges, 0..1. */
|
|
14
|
+
sparkle?: number;
|
|
15
|
+
/** Blur behind the frost, in pixels. 0 turns it off. */
|
|
16
|
+
blur?: number;
|
|
17
|
+
/** Picks the crystal layout. The same seed always grows the same frost. */
|
|
18
|
+
seed?: number;
|
|
19
|
+
/** Additional CSS classes */
|
|
20
|
+
class?: HTMLAttributes["class"];
|
|
21
|
+
}
|
|
22
|
+
declare const _default: typeof __VLS_export;
|
|
23
|
+
export default _default;
|
|
24
|
+
declare const __VLS_export: __VLS_WithSlots<import("vue").DefineComponent<FrostGlassProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<FrostGlassProps> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>, {
|
|
25
|
+
default?: () => unknown;
|
|
26
|
+
}>;
|
|
27
|
+
type __VLS_WithSlots<T, S> = T & {
|
|
28
|
+
new (): {
|
|
29
|
+
$slots: S;
|
|
30
|
+
};
|
|
31
|
+
};
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { defineComponent, useTemplateRef, computed, shallowRef, onMounted, onBeforeUnmount, watch, createElementBlock, openBlock, mergeProps, unref, renderSlot, createElementVNode, createCommentVNode, normalizeStyle } from "vue";
|
|
2
|
+
import { cn } from "../../utils.js";
|
|
3
|
+
import { useReducedMotion } from "../../internals/motion/use-media-query.js";
|
|
4
|
+
import { FROST_GLASS_DEFAULTS, blurLayerDeclarations, createFrostGlass, fallbackBackground } from "./frost-glass-core.js";
|
|
5
|
+
const _hoisted_1 = ["data-ready"];
|
|
6
|
+
const _hoisted_2 = {
|
|
7
|
+
ref: "canvas",
|
|
8
|
+
class: "pointer-events-none absolute inset-0 block h-full w-full rounded-[inherit]",
|
|
9
|
+
"aria-hidden": "true"
|
|
10
|
+
};
|
|
11
|
+
const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
12
|
+
...{ name: "FrostGlass", inheritAttrs: false },
|
|
13
|
+
__name: "FrostGlass",
|
|
14
|
+
props: {
|
|
15
|
+
coverage: { default: () => FROST_GLASS_DEFAULTS.coverage },
|
|
16
|
+
growth: { default: () => FROST_GLASS_DEFAULTS.growth },
|
|
17
|
+
melt: { type: Boolean, default: () => FROST_GLASS_DEFAULTS.melt },
|
|
18
|
+
refreeze: { default: () => FROST_GLASS_DEFAULTS.refreeze },
|
|
19
|
+
tint: { default: () => FROST_GLASS_DEFAULTS.tint },
|
|
20
|
+
sparkle: { default: () => FROST_GLASS_DEFAULTS.sparkle },
|
|
21
|
+
blur: { default: () => FROST_GLASS_DEFAULTS.blur },
|
|
22
|
+
seed: { default: () => FROST_GLASS_DEFAULTS.seed },
|
|
23
|
+
class: { type: [Boolean, null, String, Object, Array], default: "" }
|
|
24
|
+
},
|
|
25
|
+
setup(__props) {
|
|
26
|
+
const rootRef = useTemplateRef("root");
|
|
27
|
+
const canvasRef = useTemplateRef("canvas");
|
|
28
|
+
const blurRef = useTemplateRef("blurLayer");
|
|
29
|
+
const blurStyle = computed(() => Object.fromEntries(blurLayerDeclarations(__props.blur, __props.coverage)));
|
|
30
|
+
const engine = shallowRef(null);
|
|
31
|
+
const reducedMotion = useReducedMotion();
|
|
32
|
+
function liveOptions() {
|
|
33
|
+
return {
|
|
34
|
+
coverage: __props.coverage,
|
|
35
|
+
growth: __props.growth,
|
|
36
|
+
melt: __props.melt,
|
|
37
|
+
refreeze: __props.refreeze,
|
|
38
|
+
tint: __props.tint,
|
|
39
|
+
sparkle: __props.sparkle,
|
|
40
|
+
reducedMotion: reducedMotion.value
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
onMounted(() => {
|
|
44
|
+
const canvas = canvasRef.value;
|
|
45
|
+
const root = rootRef.value;
|
|
46
|
+
if (!canvas || !root) return;
|
|
47
|
+
engine.value = createFrostGlass(
|
|
48
|
+
{ canvas, root, blurLayer: blurRef.value },
|
|
49
|
+
{ ...liveOptions(), seed: __props.seed }
|
|
50
|
+
);
|
|
51
|
+
});
|
|
52
|
+
onBeforeUnmount(() => {
|
|
53
|
+
const instance = engine.value;
|
|
54
|
+
if (!instance) return;
|
|
55
|
+
engine.value = null;
|
|
56
|
+
instance.destroy();
|
|
57
|
+
});
|
|
58
|
+
watch(
|
|
59
|
+
[engine, liveOptions],
|
|
60
|
+
([currentEngine, options]) => {
|
|
61
|
+
currentEngine?.setOptions(options);
|
|
62
|
+
},
|
|
63
|
+
{ flush: "post" }
|
|
64
|
+
);
|
|
65
|
+
return (_ctx, _cache) => {
|
|
66
|
+
return openBlock(), createElementBlock("div", mergeProps({ ref: "root" }, _ctx.$attrs, {
|
|
67
|
+
class: unref(cn)("fancy-frost-glass relative isolate overflow-hidden", __props.class),
|
|
68
|
+
"data-ready": engine.value ? "" : void 0
|
|
69
|
+
}), [
|
|
70
|
+
renderSlot(_ctx.$slots, "default"),
|
|
71
|
+
createElementVNode("div", {
|
|
72
|
+
ref: "blurLayer",
|
|
73
|
+
class: "fancy-frost-glass-blur pointer-events-none absolute inset-0 rounded-[inherit]",
|
|
74
|
+
style: normalizeStyle(blurStyle.value),
|
|
75
|
+
"aria-hidden": "true"
|
|
76
|
+
}, null, 4),
|
|
77
|
+
!engine.value ? (openBlock(), createElementBlock("div", {
|
|
78
|
+
key: 0,
|
|
79
|
+
class: "fancy-frost-glass-fallback pointer-events-none absolute inset-0 rounded-[inherit]",
|
|
80
|
+
style: normalizeStyle({ background: unref(fallbackBackground)(__props.tint, __props.coverage) }),
|
|
81
|
+
"aria-hidden": "true"
|
|
82
|
+
}, null, 4)) : createCommentVNode("", true),
|
|
83
|
+
createElementVNode("canvas", _hoisted_2, null, 512)
|
|
84
|
+
], 16, _hoisted_1);
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
export {
|
|
89
|
+
_sfc_main as default
|
|
90
|
+
};
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* FrostGlass engine: ice crystals growing inward from the edges of a pane,
|
|
3
|
+
* drawn by one WebGL fragment shader over whatever the pane holds.
|
|
4
|
+
*
|
|
5
|
+
* Framework-free and shared byte-for-byte by the Svelte, React and Vue
|
|
6
|
+
* wrappers (see shared-cores.json). Nothing here touches the DOM at import
|
|
7
|
+
* time; `createFrostGlass` is the only entry that needs a browser.
|
|
8
|
+
*
|
|
9
|
+
* The ice has a thickness: 1 at the border, 0 at a lobed front (the distance
|
|
10
|
+
* to the edge, warped by noise). Where it is thick, fine grains of rime merge
|
|
11
|
+
* into a continuous translucent crust; toward the front they break up into
|
|
12
|
+
* specks. Dendrites are rooted on the border at three spacings and grow along
|
|
13
|
+
* the edge normal, branching at about 60 degrees; each family only exists
|
|
14
|
+
* where the ice is thick enough, so every crystal stays attached to the frozen
|
|
15
|
+
* zone and growth simply moves the front inward.
|
|
16
|
+
*
|
|
17
|
+
* Warmth from the pointer is kept in a small grid of cells on the CPU and
|
|
18
|
+
* uploaded as a byte texture. Warmth subtracts from the thickness, so a warm
|
|
19
|
+
* trail is clear glass with a wet rim, and as it cools the ice creeps back in
|
|
20
|
+
* from the trail's edges.
|
|
21
|
+
*/
|
|
22
|
+
export interface FrostGlassElements {
|
|
23
|
+
/** The canvas the frost is drawn on. It should cover `root`. */
|
|
24
|
+
canvas: HTMLCanvasElement;
|
|
25
|
+
/** The element that hears the pointer. Usually the pane itself. */
|
|
26
|
+
root: HTMLElement;
|
|
27
|
+
/**
|
|
28
|
+
* Optional layer carrying `backdrop-filter: blur()`. The engine writes the
|
|
29
|
+
* frost's shape into its `--fancy-frost-mask` custom property, so the blur
|
|
30
|
+
* follows the frost, including melted trails.
|
|
31
|
+
*/
|
|
32
|
+
blurLayer?: HTMLElement | null;
|
|
33
|
+
}
|
|
34
|
+
export interface FrostGlassLiveOptions {
|
|
35
|
+
/** How far the frost reaches toward the centre, 0..1 of the half short side. */
|
|
36
|
+
coverage?: number;
|
|
37
|
+
/** Seconds the frost takes to grow from the edges on mount. 0 shows it grown. */
|
|
38
|
+
growth?: number;
|
|
39
|
+
/** The pointer melts a trail through the frost. */
|
|
40
|
+
melt?: boolean;
|
|
41
|
+
/** Seconds a fully melted spot takes to freeze over again. */
|
|
42
|
+
refreeze?: number;
|
|
43
|
+
/** Cold tint of the ice, `#rgb` or `#rrggbb`. */
|
|
44
|
+
tint?: string;
|
|
45
|
+
/** Strength of the slow glints on the crystal ridges, 0..1. 0 lets the loop sleep. */
|
|
46
|
+
sparkle?: number;
|
|
47
|
+
/** Frost fully grown and still: no growth, no glints, no melting. */
|
|
48
|
+
reducedMotion?: boolean;
|
|
49
|
+
}
|
|
50
|
+
export interface FrostGlassInitOptions extends FrostGlassLiveOptions {
|
|
51
|
+
/** Picks the crystal layout. The same seed always grows the same frost. */
|
|
52
|
+
seed?: number;
|
|
53
|
+
/**
|
|
54
|
+
* Lose the WebGL context on destroy. Leave on unless the same canvas element
|
|
55
|
+
* is handed to a second engine afterwards (a context cannot be un-lost).
|
|
56
|
+
*/
|
|
57
|
+
releaseContext?: boolean;
|
|
58
|
+
}
|
|
59
|
+
export interface FrostGlassEngine {
|
|
60
|
+
setOptions(options: FrostGlassLiveOptions): void;
|
|
61
|
+
/** Growth progress 0..1 and whether any warmth is left, for tests. */
|
|
62
|
+
getState(): {
|
|
63
|
+
grown: number;
|
|
64
|
+
warm: boolean;
|
|
65
|
+
};
|
|
66
|
+
destroy(): void;
|
|
67
|
+
}
|
|
68
|
+
export declare const FROST_GLASS_DEFAULTS: {
|
|
69
|
+
readonly coverage: 0.45;
|
|
70
|
+
readonly growth: 2.4;
|
|
71
|
+
readonly melt: true;
|
|
72
|
+
readonly refreeze: 4;
|
|
73
|
+
readonly tint: "#cfe6ff";
|
|
74
|
+
readonly sparkle: 0.5;
|
|
75
|
+
readonly blur: 3;
|
|
76
|
+
readonly seed: 7;
|
|
77
|
+
};
|
|
78
|
+
/** Device pixel ratio above this is not worth its fill cost for a soft effect. */
|
|
79
|
+
export declare const MAX_PIXEL_RATIO = 2;
|
|
80
|
+
/** Longest step the clock integrates, so a background tab does not jump ahead. */
|
|
81
|
+
export declare const MAX_STEP: number;
|
|
82
|
+
/** Side of one warmth cell, in CSS pixels. */
|
|
83
|
+
export declare const HEAT_CELL = 6;
|
|
84
|
+
/** Most warmth cells along the longer side of the pane. */
|
|
85
|
+
export declare const HEAT_MAX_CELLS = 128;
|
|
86
|
+
/** Radius of the warm spot the pointer leaves, in CSS pixels. */
|
|
87
|
+
export declare const MELT_RADIUS = 26;
|
|
88
|
+
/** Shortest wait between two updates of the blur mask, in milliseconds. */
|
|
89
|
+
export declare const MASK_INTERVAL = 66;
|
|
90
|
+
/** Frames per second while only the glints move. They are slow; 30 is plenty. */
|
|
91
|
+
export declare const SPARKLE_FPS = 30;
|
|
92
|
+
/** Parse `#rgb` / `#rrggbb` to 0..1 components; anything else gives the fallback. */
|
|
93
|
+
export declare function parseHexColor(value: string | undefined, fallback: readonly [number, number, number]): [number, number, number];
|
|
94
|
+
/** The `coverage` prop as used: clamped to 0..1, NaN as 0. */
|
|
95
|
+
export declare function clampCoverage(coverage: number): number;
|
|
96
|
+
/**
|
|
97
|
+
* Frost front after `elapsed` seconds of a `growth`-second spread, 0..1.
|
|
98
|
+
* Fast at first and settling at the end, the way frost slows as the pane cools.
|
|
99
|
+
*/
|
|
100
|
+
export declare function growthProgress(elapsed: number, growth: number): number;
|
|
101
|
+
/**
|
|
102
|
+
* The CSS stand-in for the frost, shown on the server, before the first frame
|
|
103
|
+
* and without WebGL: a cold vignette reaching `coverage` toward the centre.
|
|
104
|
+
*/
|
|
105
|
+
export declare function fallbackBackground(tint: string, coverage: number): string;
|
|
106
|
+
/** The CSS mask that shapes the blur layer until the engine draws a real one. */
|
|
107
|
+
export declare function fallbackMask(coverage: number): string;
|
|
108
|
+
/**
|
|
109
|
+
* CSS declarations for the blur layer, as `[property, value]` pairs in
|
|
110
|
+
* kebab-case. The mask reads `--fancy-frost-mask`, which the engine fills with
|
|
111
|
+
* the live frost shape; until then the CSS mask above stands in. `blur` of 0
|
|
112
|
+
* (or less) hides the layer.
|
|
113
|
+
*/
|
|
114
|
+
export declare function blurLayerDeclarations(blur: number, coverage: number): Array<[string, string]>;
|
|
115
|
+
/** `blurLayerDeclarations` as one inline style string. */
|
|
116
|
+
export declare function blurLayerStyle(blur: number, coverage: number): string;
|
|
117
|
+
/**
|
|
118
|
+
* How frosted a point is, 0..1, from its distance to the nearest edge as a
|
|
119
|
+
* fraction of the half short side, for a front that has reached `reach`.
|
|
120
|
+
* The broad shape the shader's crystals fill; the blur mask uses it directly.
|
|
121
|
+
*/
|
|
122
|
+
export declare function frostAmount(edgeDistance: number, reach: number): number;
|
|
123
|
+
/** Smooth value noise in 0..1, for the ragged edge of the blur mask. */
|
|
124
|
+
export declare function valueNoise(x: number, y: number, seed: number): number;
|
|
125
|
+
/** Warmth left by the pointer, one value per cell, 0 (frozen) to 1 (melted). */
|
|
126
|
+
export interface HeatGrid {
|
|
127
|
+
cols: number;
|
|
128
|
+
rows: number;
|
|
129
|
+
/** Side of one cell in CSS pixels. */
|
|
130
|
+
cell: number;
|
|
131
|
+
data: Float32Array;
|
|
132
|
+
}
|
|
133
|
+
/** A cold grid sized for a `width` × `height` pane in CSS pixels. */
|
|
134
|
+
export declare function createHeatGrid(width: number, height: number): HeatGrid;
|
|
135
|
+
/**
|
|
136
|
+
* Warm the grid along the segment from (x0, y0) to (x1, y1), CSS pixels, with
|
|
137
|
+
* a soft round brush of `radius`. Warmth adds up to 1 and never beyond, so a
|
|
138
|
+
* slow pointer clears the frost while a quick swipe only thins it.
|
|
139
|
+
*/
|
|
140
|
+
export declare function depositHeat(grid: HeatGrid, x0: number, y0: number, x1: number, y1: number, radius: number, amount: number): void;
|
|
141
|
+
/**
|
|
142
|
+
* Cool the grid by `dt` seconds: a fully melted cell takes `refreeze` seconds
|
|
143
|
+
* to freeze again. Returns true while any warmth is left.
|
|
144
|
+
*/
|
|
145
|
+
export declare function coolHeat(grid: HeatGrid, dt: number, refreeze: number): boolean;
|
|
146
|
+
/** Seeded generator, so a `seed` always lays out the same frost. */
|
|
147
|
+
export declare function mulberry32(seed: number): () => number;
|
|
148
|
+
export declare const VERTEX_SHADER = "\nattribute vec2 aPos;\nvoid main() { gl_Position = vec4(aPos, 0.0, 1.0); }\n";
|
|
149
|
+
export declare const FRAGMENT_SHADER = "\nprecision highp float;\n\nuniform vec2 uRes;\nuniform float uScale;\nuniform float uReach;\nuniform float uTime;\nuniform float uSparkle;\nuniform vec3 uTint;\nuniform vec2 uSeed;\nuniform sampler2D uHeat;\nuniform vec2 uHeatSpan;\nuniform vec2 uHeatCells;\nuniform float uRadius;\n\nvec2 size;\nfloat halfSide;\n\nfloat hash(vec2 p) {\n\tp = fract(p * vec2(123.34, 456.21) + uSeed);\n\tp += dot(p, p + 45.32);\n\treturn fract(p.x * p.y);\n}\n\nfloat noise(vec2 p) {\n\tvec2 i = floor(p);\n\tvec2 f = fract(p);\n\tvec2 u = f * f * (3.0 - 2.0 * f);\n\treturn mix(mix(hash(i), hash(i + vec2(1.0, 0.0)), u.x),\n\t\tmix(hash(i + vec2(0.0, 1.0)), hash(i + vec2(1.0, 1.0)), u.x), u.y);\n}\n\nfloat fbm(vec2 p) {\n\tfloat v = 0.0;\n\tfloat a = 0.5;\n\tfor (int i = 0; i < 4; i++) {\n\t\tv += a * noise(p);\n\t\tp = mat2(1.6, 1.2, -1.2, 1.6) * p;\n\t\ta *= 0.5;\n\t}\n\treturn v;\n}\n\n// Distance to the nearest edge, as a fraction of the half short side.\n// Distance inside the pane's rounded rectangle, in CSS pixels, so the ice\n// follows the corners instead of piling up in the clipped-off square ones.\nfloat inset(vec2 p) {\n\tvec2 h = size * 0.5;\n\tfloat r = min(uRadius, min(h.x, h.y));\n\tvec2 q = abs(p - h) - (h - r);\n\treturn r - length(max(q, 0.0)) - min(max(q.x, q.y), 0.0);\n}\n\nfloat edgeDistance(vec2 p) {\n\treturn inset(p) / halfSide;\n}\n\n// Unit vector pointing away from the nearest edge.\nvec2 inward(vec2 p) {\n\tfloat dx = min(p.x, size.x - p.x);\n\tfloat dy = min(p.y, size.y - p.y);\n\tif (dx < dy) return vec2(p.x < size.x * 0.5 ? 1.0 : -1.0, 0.0);\n\treturn vec2(0.0, p.y < size.y * 0.5 ? 1.0 : -1.0);\n}\n\n// Warmth between cell centres, blended with a smoothstep weight instead of the\n// hardware's straight line, so a warm spot is round rather than octagonal.\nfloat heatAt(vec2 p) {\n\tvec2 g = p / (uHeatSpan / uHeatCells) - 0.5;\n\tvec2 i = floor(g);\n\tvec2 f = g - i;\n\tf = f * f * (3.0 - 2.0 * f);\n\tvec2 inv = 1.0 / uHeatCells;\n\tfloat a = texture2D(uHeat, (i + 0.5) * inv).r;\n\tfloat b = texture2D(uHeat, (i + vec2(1.5, 0.5)) * inv).r;\n\tfloat c = texture2D(uHeat, (i + vec2(0.5, 1.5)) * inv).r;\n\tfloat d = texture2D(uHeat, (i + 1.5) * inv).r;\n\treturn mix(mix(a, b, f.x), mix(c, d, f.x), f.y);\n}\n\n// Where p sits relative to its nearest edge: x runs along that edge, y is the\n// distance into the pane in CSS pixels. Each edge gets its own stretch of x so\n// the four borders do not repeat one another.\nvec2 edgeFrame(vec2 p) {\n\tfloat left = p.x;\n\tfloat right = size.x - p.x;\n\tfloat top = p.y;\n\tfloat bottom = size.y - p.y;\n\tfloat m = min(min(left, right), min(top, bottom));\n\tfloat r = inset(p);\n\tif (m == left) return vec2(p.y, r);\n\tif (m == right) return vec2(p.y + 3000.0, r);\n\tif (m == top) return vec2(p.x + 6000.0, r);\n\treturn vec2(p.x + 9000.0, r);\n}\n\n// One family of dendrites rooted on the border, every `spacing` pixels along\n// it. Each has a spine growing inward (bent by noise, leaning a little), and\n// side branches leaving it at about 60 degrees, longest where the ice is\n// thick. `reachT` is how thick the ice must be for this family to exist, so\n// small growth only fills in behind the big dendrites.\n// x: bright ridge, y: shadow beside it (the side away from the light).\nvec2 dendrites(vec2 f, float spacing, float salt, float thick, float lead, float width) {\n\tvec2 acc = vec2(0.0);\n\tfloat aa = 0.8 / uScale;\n\tfloat k0 = floor(f.x / spacing);\n\tfor (int i = -1; i <= 1; i++) {\n\t\tfloat k = k0 + float(i);\n\t\tfloat h1 = hash(vec2(k, salt));\n\t\tfloat h2 = hash(vec2(k, salt + 7.0));\n\t\tfloat h3 = hash(vec2(k, salt + 13.0));\n\t\t// Some roots never sprout, so the border is not a comb.\n\t\tif (h3 < 0.18) continue;\n\t\tfloat h4 = hash(vec2(k, salt + 19.0));\n\t\t// Some dendrites stop short near the border; others run past the haze\n\t\t// front by up to `lead`.\n\t\tfloat alive = thick - (1.0 - h4) * 0.4 + lead * h2;\n\t\tif (alive <= 0.0) continue;\n\t\tfloat r = f.y;\n\t\tfloat centre = (k + 0.2 + 0.6 * h1) * spacing;\n\t\tfloat lean = (h2 - 0.5) * 0.7;\n\t\tfloat bend = (noise(vec2(r * 0.02, k * 3.1 + salt)) - 0.5) * spacing * 0.28;\n\t\t// A slow curve on top of the lean, different for every dendrite.\n\t\tfloat curve = (h4 - 0.5) * 0.004 * r * r;\n\t\tfloat x = f.x - centre - r * lean - bend - curve;\n\t\tfloat ax = abs(x);\n\t\tfloat tipFade = smoothstep(0.0, 0.12, alive);\n\t\tfloat w = width * mix(0.45, 1.0, clamp(thick, 0.0, 1.0));\n\t\tfloat spine = 1.0 - smoothstep(w, w + aa * 2.0, ax);\n\t\t// Shadow on one side of the spine only: that is what reads as relief.\n\t\tfloat sx = x * sign(lean + 1e-3);\n\t\tfloat spineShade = smoothstep(w, w + aa, sx) * (1.0 - smoothstep(w + 0.8, w + 2.0, sx));\n\t\t// Side branches, swept toward the growth direction.\n\t\tfloat gap = spacing * (0.09 + 0.05 * h1);\n\t\t// The two sides alternate, and some branches never grow.\n\t\tfloat side = x > 0.0 ? 0.5 : 0.0;\n\t\tfloat b = (r - ax * 0.58) / gap + side;\n\t\tfloat bi = floor(b);\n\t\tfloat hb = hash(vec2(bi + side * 2.0, k + salt));\n\t\tfloat hb2 = hash(vec2(bi + side * 2.0, k + salt + 5.0));\n\t\tfloat reach = spacing * (0.12 + 0.4 * hb * hb) * smoothstep(-0.05, 0.7, thick);\n\t\tfloat branch = 0.0;\n\t\tfloat branchShade = 0.0;\n\t\tif (ax < reach && hb > 0.22) {\n\t\t\t// Each branch sits off-centre in its slot and leaves at its own angle.\n\t\t\tfloat at = 0.5 + (hb2 - 0.5) * 0.5 + ax * (hb - 0.5) * 0.12 / gap;\n\t\t\tfloat fb = (fract(b) - at) * gap * 0.86;\n\t\t\tfloat bw = width * 0.55 * (1.0 - 0.6 * ax / reach);\n\t\t\tfloat fade = 1.0 - ax / reach;\n\t\t\tbranch = (1.0 - smoothstep(bw, bw + aa * 2.0, abs(fb))) * fade;\n\t\t\tbranchShade = smoothstep(bw, bw + aa, fb) * (1.0 - smoothstep(bw + 0.7, bw + 1.6, fb)) * fade;\n\t\t}\n\t\tacc.x = max(acc.x, max(spine, branch * 0.85) * tipFade);\n\t\tacc.y = max(acc.y, max(spineShade, branchShade * 0.7) * tipFade);\n\t}\n\treturn acc;\n}\n\nvoid main() {\n\tsize = uRes / uScale;\n\thalfSide = 0.5 * min(size.x, size.y);\n\tvec2 p = vec2(gl_FragCoord.x, uRes.y - gl_FragCoord.y) / uScale;\n\n\tfloat heat = heatAt(p);\n\n\t// Thickness of the ice: 1 at the border, 0 at the front. The front is lobed:\n\t// the distance to the edge is warped by two octaves of noise.\n\tfloat d = edgeDistance(p) + (fbm(p * 0.006) - 0.5) * 0.5 + (fbm(p * 0.03 + 5.0) - 0.5) * 0.08;\n\tfloat thick = (uReach - d) / 0.45;\n\t// Warmth thins the ice. A warm spot loses its edge first on the way in and\n\t// gets it back last, so refreezing creeps in from the rim of the trail.\n\t// The melt edge wanders like the frost front, so a trail is never a clean blob.\n\tfloat melted = max(0.0, heat * 2.2 + (fbm(p * 0.035 + 7.0) - 0.5) * 0.9 * smoothstep(0.0, 0.2, heat));\n\tfloat t = thick - melted;\n\n\t// Dendrites follow the edge normal, with a light warp so no spine is straight.\n\tvec2 warp = vec2(fbm(p * 0.013 + 3.1), fbm(p * 0.013 + 8.7)) - 0.5;\n\tvec2 f = edgeFrame(p + warp * 18.0);\n\tvec2 big = dendrites(f, 96.0, 1.0, t, 0.22, 0.85);\n\tvec2 mid = dendrites(f + vec2(31.0, 0.0), 41.0, 2.0, t - 0.25, 0.08, 0.6);\n\tvec2 fine = dendrites(f + vec2(13.0, 0.0), 17.0, 3.0, t - 0.5, 0.0, 0.42);\n\tfloat ridge = max(big.x, max(mid.x * 0.75, fine.x * 0.5));\n\t// Shadow only where there is ice, so no grey halo forms past the front.\n\tfloat shade = max(big.y, max(mid.y * 0.7, fine.y * 0.45)) * (1.0 - ridge) * smoothstep(0.0, 0.3, t);\n\t// Roots fade into the rime right at the border, so no crystal is cut off\n\t// as a bright sliver where the rounded corner clips the pane.\n\t// Corners are left to the rime: there the two edge frames meet and a\n\t// leaning spine would be stretched into a bright wedge.\n\tvec2 toCorner = min(p, size - p);\n\tfloat corner = smoothstep(8.0, 30.0 + uRadius, length(toCorner));\n\tfloat rooted = smoothstep(0.5, 6.0, inset(p)) * corner;\n\tridge *= rooted;\n\tshade *= rooted;\n\t// Thin ice is faint and cool; thick ice is bright.\n\tfloat body = clamp(t, 0.0, 1.0);\n\tridge *= 0.35 + 0.65 * body;\n\n\t// Rime: fine grains, thresholded by thickness, so the ice is a continuous\n\t// granular crust at the border that breaks up into specks toward the front.\n\tfloat grain = noise(p * 1.1 + 11.0) * 0.55 + noise(p * 2.6 + 4.0) * 0.45;\n\tfloat rime = smoothstep(0.98 - body * 0.8, 1.2 - body * 0.8, grain) * smoothstep(0.0, 0.08, t);\n\tfloat haze = smoothstep(0.02, 0.45, t) * (0.55 + 0.45 * fbm(p * 0.03 + 2.0));\n\n\t// Three inks: a cold blue-grey for the haze and rime, white for the ridges,\n\t// and a deeper blue-grey for their shadow side. The greys are what make the\n\t// ice read on a white pane; the whites carry it on a dark one.\n\tvec3 frostInk = mix(vec3(0.80, 0.86, 0.93), uTint, 0.5);\n\tvec3 deep = mix(vec3(0.34, 0.43, 0.56), uTint * 0.5, 0.35);\n\tfloat aHaze = haze * 0.2 + rime * (0.06 + 0.12 * body);\n\tfloat aRidge = ridge * 0.8;\n\tfloat aShade = shade * (0.3 + 0.2 * body);\n\n\t// The melted trail: clear glass inside, a thin bright meniscus where the\n\t// water meets the ice, and a slightly darker water edge just inside it.\n\tfloat e = 3.0;\n\tvec2 grad = vec2(heatAt(p + vec2(e, 0.0)) - heatAt(p - vec2(e, 0.0)),\n\t\theatAt(p + vec2(0.0, e)) - heatAt(p - vec2(0.0, e))) / (2.0 * e);\n\tfloat slope = max(length(grad) * 2.2, 1e-3);\n\t// Pixels from the line where the trail just clears the ice.\n\tfloat edge = (melted - thick) / slope;\n\tfloat wetZone = step(0.02, heat) * smoothstep(0.05, 0.25, thick);\n\tfloat meniscus = (1.0 - smoothstep(0.0, 1.1, abs(edge))) * wetZone;\n\tfloat waterEdge = (1.0 - smoothstep(0.0, 2.5, abs(edge - 3.0))) * wetZone;\n\t// The rim is not a drawn outline: it comes and goes along its length.\n\tfloat along = smoothstep(0.3, 0.75, fbm(p * 0.045 + 13.0));\n\tfloat aMeniscus = meniscus * 0.4 * along;\n\tfloat aWater = waterEdge * 0.14 * (0.4 + 0.6 * along);\n\n\tvec3 col = frostInk * aHaze + vec3(1.0) * aRidge + deep * aShade\n\t\t+ vec3(1.0) * aMeniscus + deep * aWater;\n\tfloat alpha = aHaze + aRidge + aShade + aMeniscus + aWater;\n\n\t// Slow glints, only on thick ridges: a tiny four-pointed star in a few cells.\n\tvec2 sc = floor(p / 13.0);\n\tfloat sh = hash(sc + 71.0);\n\tif (uSparkle > 0.0 && sh > 0.9 && ridge > 0.45) {\n\t\tvec2 sp = (sc + 0.5) * 13.0;\n\t\tvec2 dd = abs(p - sp);\n\t\tfloat star = exp(-dot(dd, dd) / 2.0) + (exp(-dd.x * dd.x / 0.35) * exp(-dd.y / 3.0) + exp(-dd.y * dd.y / 0.35) * exp(-dd.x / 3.0)) * 0.5;\n\t\tfloat phase = sh * 91.0 + uTime * (0.35 + 0.5 * hash(sc + 3.0));\n\t\tfloat glint = pow(max(0.0, sin(phase)), 18.0) * uSparkle * body;\n\t\tcol += vec3(1.0) * star * glint;\n\t\talpha += star * glint;\n\t}\n\n\talpha = clamp(alpha, 0.0, 0.94);\n\tcol = min(col, vec3(alpha));\n\tgl_FragColor = vec4(col, alpha);\n}\n";
|
|
150
|
+
/**
|
|
151
|
+
* Start the frost on `canvas`, listening to the pointer on `root`. Returns
|
|
152
|
+
* `null` when WebGL is unavailable or the shader does not compile, so a
|
|
153
|
+
* wrapper can leave its fallback showing.
|
|
154
|
+
*/
|
|
155
|
+
export declare function createFrostGlass(elements: FrostGlassElements, options?: FrostGlassInitOptions): FrostGlassEngine | null;
|