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.
Files changed (35) hide show
  1. package/README.md +12 -12
  2. package/dist/components/frost-glass/FrostGlass.vue.d.ts +31 -0
  3. package/dist/components/frost-glass/FrostGlass.vue.js +90 -0
  4. package/dist/components/frost-glass/FrostGlass.vue2.js +4 -0
  5. package/dist/components/frost-glass/frost-glass-core.d.ts +155 -0
  6. package/dist/components/frost-glass/frost-glass-core.js +820 -0
  7. package/dist/components/frost-glass/index.d.ts +2 -0
  8. package/dist/components/gift-reveal/GiftReveal.vue.d.ts +50 -0
  9. package/dist/components/gift-reveal/GiftReveal.vue.js +7 -0
  10. package/dist/components/gift-reveal/GiftReveal.vue2.js +177 -0
  11. package/dist/components/gift-reveal/gift-reveal-core.d.ts +109 -0
  12. package/dist/components/gift-reveal/gift-reveal-core.js +116 -0
  13. package/dist/components/gift-reveal/index.d.ts +2 -0
  14. package/dist/components/ornament/Ornament.vue.d.ts +29 -0
  15. package/dist/components/ornament/Ornament.vue.js +112 -0
  16. package/dist/components/ornament/Ornament.vue2.js +4 -0
  17. package/dist/components/ornament/index.d.ts +2 -0
  18. package/dist/components/ornament/ornament-core.d.ts +177 -0
  19. package/dist/components/ornament/ornament-core.js +861 -0
  20. package/dist/components/snowfall/Snowfall.vue.d.ts +29 -0
  21. package/dist/components/snowfall/Snowfall.vue.js +81 -0
  22. package/dist/components/snowfall/Snowfall.vue2.js +4 -0
  23. package/dist/components/snowfall/index.d.ts +2 -0
  24. package/dist/components/snowfall/snowfall-core.d.ts +119 -0
  25. package/dist/components/snowfall/snowfall-core.js +483 -0
  26. package/dist/components/string-lights/StringLights.vue.d.ts +35 -0
  27. package/dist/components/string-lights/StringLights.vue.js +7 -0
  28. package/dist/components/string-lights/StringLights.vue2.js +98 -0
  29. package/dist/components/string-lights/index.d.ts +2 -0
  30. package/dist/components/string-lights/string-lights-core.d.ts +157 -0
  31. package/dist/components/string-lights/string-lights-core.js +228 -0
  32. package/dist/index.d.ts +5 -0
  33. package/dist/index.js +326 -316
  34. package/dist/styles.css +1341 -0
  35. package/package.json +2 -2
@@ -0,0 +1,177 @@
1
+ /**
2
+ * Ornament engine: one fragment shader that draws a glass bauble hanging from
3
+ * a thread, and a small damped pendulum that swings it.
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; `createOrnament` is the only entry that needs a browser.
8
+ *
9
+ * The sphere is analytic: every pixel inside its circle knows its normal
10
+ * exactly, so the shader shades it like a lit object rather than a picture.
11
+ * What it reflects is a small studio built from a few lines of maths (two
12
+ * soft boxes, a window, two rim strips and a warm floor), so nothing has to be
13
+ * downloaded. The thread, the cap and its loop are drawn in the pendulum's own
14
+ * frame, which makes the whole ornament swing as one piece.
15
+ */
16
+ export type OrnamentFinish = "gloss" | "matte" | "glitter";
17
+ export type OrnamentBand = "none" | "stripe" | "dots";
18
+ export interface OrnamentElements {
19
+ canvas: HTMLCanvasElement;
20
+ /** Element that receives arrow keys, Enter and Space. Usually the focusable wrapper root. */
21
+ root?: HTMLElement | null;
22
+ }
23
+ export interface OrnamentLiveOptions {
24
+ /** Colour of the glass, `#rgb` or `#rrggbb`. */
25
+ color?: string;
26
+ /** Surface: clear glass, soft velvet or fine glitter. */
27
+ finish?: OrnamentFinish;
28
+ /** Metallic band around the equator. */
29
+ band?: OrnamentBand;
30
+ /** Diameter of the sphere, in CSS pixels. */
31
+ size?: number;
32
+ /** Length of the thread above the cap, in CSS pixels. */
33
+ threadLength?: number;
34
+ /** Idle sway, 0..1. 0 hangs perfectly still at rest. */
35
+ swing?: number;
36
+ /** Hover nudges, drag and arrow keys move the ornament. */
37
+ interactive?: boolean;
38
+ /** Strength of the soft halo behind the sphere, 0..1. */
39
+ glow?: number;
40
+ /** Draw one still frame, hanging straight, and ignore input. */
41
+ reducedMotion?: boolean;
42
+ }
43
+ export interface OrnamentInitOptions extends OrnamentLiveOptions {
44
+ /** Seed for the glitter, the starting turn and the sway phase. */
45
+ seed?: number;
46
+ /**
47
+ * Lose the WebGL context on destroy. Leave on unless the same canvas element
48
+ * is handed to a second engine afterwards (a context cannot be un-lost).
49
+ */
50
+ releaseContext?: boolean;
51
+ }
52
+ export interface OrnamentEngine {
53
+ setOptions(options: OrnamentLiveOptions): void;
54
+ /** Current swing angle in radians (positive swings right), for tests. */
55
+ getAngle(): number;
56
+ destroy(): void;
57
+ }
58
+ export declare const ORNAMENT_DEFAULTS: {
59
+ readonly color: "#b9c0cc";
60
+ readonly finish: "gloss";
61
+ readonly band: "none";
62
+ readonly size: 120;
63
+ readonly threadLength: 96;
64
+ readonly swing: 0.2;
65
+ readonly glow: 0.5;
66
+ readonly seed: 1;
67
+ };
68
+ /** Device pixel ratio above this is not worth its fill cost. */
69
+ export declare const MAX_PIXEL_RATIO = 2;
70
+ /** Longest step the motion integrates, so a background tab does not teleport. */
71
+ export declare const MAX_STEP: number;
72
+ /** Integration sub-step: the pendulum is stiff enough to want small steps. */
73
+ export declare const SUB_STEP: number;
74
+ /** "Gravity" in CSS pixels per second squared: sets how slow a long thread swings. */
75
+ export declare const GRAVITY = 2600;
76
+ /** Damping ratio of the swing. Small, so a release rocks a few times. */
77
+ export declare const SWING_DAMPING = 0.085;
78
+ /** Natural frequency of the twist around the thread, radians per second. */
79
+ export declare const TWIST_FREQUENCY = 2.1;
80
+ /** Damping ratio of the twist. */
81
+ export declare const TWIST_DAMPING = 0.14;
82
+ /** How much the swing speed winds the thread. */
83
+ export declare const TWIST_COUPLING = 1.4;
84
+ /** Idle sway at `swing: 1`, radians either side of straight down. */
85
+ export declare const IDLE_AMPLITUDE = 0.16;
86
+ /** Below these the pendulum counts as settled and the loop may sleep. */
87
+ export declare const REST_EPSILON = 0.0015;
88
+ /** Where everything sits, in CSS pixels, inside the canvas box. */
89
+ export interface OrnamentGeometry {
90
+ /** Canvas box. */
91
+ width: number;
92
+ height: number;
93
+ /** Sphere radius. */
94
+ radius: number;
95
+ /** Distances down the thread from the pivot at the top centre of the box. */
96
+ loopRadius: number;
97
+ loopTube: number;
98
+ capTop: number;
99
+ capHeight: number;
100
+ capWidth: number;
101
+ /** Pivot to sphere centre: the pendulum arm. */
102
+ arm: number;
103
+ /** Largest swing that keeps the sphere inside the box, radians. */
104
+ maxAngle: number;
105
+ }
106
+ /**
107
+ * The box the canvas needs. It is twice the sphere wide (swing room and the
108
+ * halo), and tall enough for the thread, the loop, the cap, the sphere and a
109
+ * little room below it.
110
+ */
111
+ export declare function ornamentGeometry(size: number, threadLength: number): OrnamentGeometry;
112
+ /**
113
+ * CSS background of the flat stand-in shown on the server, before the first
114
+ * frame and without WebGL: a lit sphere from a radial gradient.
115
+ */
116
+ export declare function fallbackSphere(color: string): string;
117
+ /** Parse `#rgb` / `#rrggbb` to 0..1 components; anything else gives the fallback. */
118
+ export declare function parseHexColor(value: string | undefined, fallback: readonly [number, number, number]): [number, number, number];
119
+ /**
120
+ * The metal of the cap and the band: gold, unless the glass itself is already
121
+ * a warm yellow, where silver is the contrasting tone.
122
+ */
123
+ export declare function metalFor(color: readonly [number, number, number]): [number, number, number];
124
+ /** Small, fast, seedable PRNG: the same seed gives the same ornament. */
125
+ export declare function mulberry32(seed: number): () => number;
126
+ export interface PendulumState {
127
+ /** Swing angle from straight down, radians, positive to the right. */
128
+ angle: number;
129
+ /** Swing speed, radians per second. */
130
+ velocity: number;
131
+ /** Turn around the thread away from the resting turn, radians. */
132
+ twist: number;
133
+ /** Twist speed, radians per second. */
134
+ twistVelocity: number;
135
+ /** Seconds of idle sway so far: the breeze is a function of it. */
136
+ time: number;
137
+ }
138
+ export interface PendulumParams {
139
+ /** Pivot to sphere centre, CSS pixels. */
140
+ arm: number;
141
+ /** Largest angle the box allows, radians. */
142
+ maxAngle: number;
143
+ /** Idle sway, 0..1. */
144
+ swing: number;
145
+ /** Phase offset of the breeze, so a row of ornaments does not sway in step. */
146
+ phase: number;
147
+ /** While held, the swing is set by the pointer and only the twist moves. */
148
+ dragging: boolean;
149
+ }
150
+ export declare const PENDULUM_REST: PendulumState;
151
+ /** Natural swing frequency for an arm, radians per second. */
152
+ export declare function swingFrequency(arm: number): number;
153
+ /**
154
+ * Where the idle breeze would hold the ornament at `time`: two slow,
155
+ * unrelated sines, both well below the swing's own frequency so the pendulum
156
+ * follows them smoothly instead of ringing.
157
+ */
158
+ export declare function breeze(time: number, swing: number, phase: number, maxAngle: number): number;
159
+ /** Squash an angle into the box: linear near 0, never past `limit`. */
160
+ export declare function softLimit(angle: number, limit: number): number;
161
+ /**
162
+ * Advance the pendulum by `dt` seconds. Pure, so the feel is unit-tested
163
+ * without a clock: a damped swing toward the breeze, a twist the swing winds
164
+ * up, and a hard wall at the edge of the box.
165
+ */
166
+ export declare function stepPendulum(state: PendulumState, dt: number, params: PendulumParams): PendulumState;
167
+ /** True when nothing would visibly move without input. */
168
+ export declare function isSettled(state: PendulumState): boolean;
169
+ /** True while another frame would look different from the current one. */
170
+ export declare function isMoving(state: PendulumState, swing: number, dragging: boolean): boolean;
171
+ export declare const VERTEX_SHADER = "\nattribute vec2 aPos;\nvoid main() { gl_Position = vec4(aPos, 0.0, 1.0); }\n";
172
+ export declare const FRAGMENT_SHADER = "\nprecision highp float;\n\nuniform vec2 uRes;\nuniform float uScale;\nuniform float uAngle;\nuniform float uTwist;\nuniform float uRadius;\nuniform float uArm;\nuniform float uThread;\nuniform float uLoopR;\nuniform float uLoopTube;\nuniform float uCapTop;\nuniform float uCapH;\nuniform float uCapW;\nuniform vec3 uColor;\nuniform vec3 uMetal;\nuniform float uFinish;\nuniform float uBand;\nuniform float uGlow;\nuniform float uSeed;\n\nconst vec3 KEY = vec3(-0.5, 0.62, 0.6);\nconst vec3 VIEW = vec3(0.0, 0.0, 1.0);\n\nfloat box(vec2 p, vec2 c, vec2 h, float soft) {\n\tvec2 d = abs(p - c) - h;\n\tfloat outside = length(max(d, 0.0)) + min(max(d.x, d.y), 0.0);\n\treturn 1.0 - smoothstep(-soft, soft, outside);\n}\n\n// The studio the sphere reflects. dir is in world space: y up, z toward the viewer.\nvec3 studio(vec3 dir) {\n\tfloat up = dir.y;\n\t// Ambient: dark charcoal walls, a little lighter overhead.\n\tvec3 c = mix(vec3(0.045, 0.047, 0.055), vec3(0.11, 0.115, 0.13), smoothstep(-0.2, 0.9, up));\n\t// Warm floor bounce.\n\tc += vec3(0.34, 0.27, 0.21) * smoothstep(-0.05, -0.75, up);\n\tvec2 f = dir.xy / max(0.35, dir.z + 0.65);\n\t// The front lights fade out smoothly as the direction turns away from the\n\t// viewer. A hard cut here left a sharp wedge in reflections near the cut,\n\t// and the fade ends before the projection below starts to stretch.\n\tfloat front = smoothstep(-0.25, 0.05, dir.z);\n\tif (front > 0.0) {\n\t\tvec3 lit = vec3(0.0);\n\t\t// Key soft box, upper left, with a brighter centre.\n\t\tfloat key = box(f, vec2(-0.46, 0.5), vec2(0.2, 0.15), 0.06);\n\t\tlit += vec3(2.6, 2.5, 2.35) * key * (0.75 + 0.25 * box(f, vec2(-0.46, 0.5), vec2(0.08, 0.05), 0.08));\n\t\t// A window, upper right: four panes and their bars.\n\t\tvec2 w = f - vec2(0.52, 0.42);\n\t\tfloat pane = box(w, vec2(0.0), vec2(0.15, 0.17), 0.025);\n\t\tfloat bars = max(1.0 - smoothstep(0.006, 0.016, abs(w.x)), 1.0 - smoothstep(0.006, 0.016, abs(w.y)));\n\t\tlit += vec3(1.05, 1.12, 1.25) * pane * (1.0 - bars * 0.9);\n\t\t// A low fill card on the right.\n\t\tlit += vec3(0.32, 0.33, 0.36) * box(f, vec2(0.7, -0.15), vec2(0.1, 0.25), 0.12);\n\t\tc += lit * front;\n\t}\n\t// Two strip lights behind, which is where the rim catches.\n\tfloat back = smoothstep(0.1, -0.5, dir.z);\n\tc += vec3(1.15, 1.12, 1.08) * back * (1.0 - smoothstep(0.08, 0.2, abs(dir.x + 0.72))) * smoothstep(-0.6, 0.2, up);\n\tc += vec3(0.75, 0.8, 0.9) * back * (1.0 - smoothstep(0.06, 0.18, abs(dir.x - 0.78))) * smoothstep(-0.5, 0.3, up);\n\treturn c;\n}\n\n// Light arriving from a whole hemisphere around n: a blurred studio, for velvet.\nvec3 studioDiffuse(vec3 n) {\n\tfloat key = max(dot(n, normalize(KEY)), 0.0);\n\tfloat window = max(dot(n, normalize(vec3(0.55, 0.45, 0.7))), 0.0);\n\tfloat bounce = max(-n.y, 0.0);\n\treturn vec3(0.06) + vec3(1.0, 0.97, 0.93) * key * 0.9 + vec3(0.42, 0.45, 0.52) * window * 0.5 +\n\t\tvec3(0.3, 0.24, 0.18) * bounce * 0.6;\n}\n\n// The studio seen in brushed metal: the same lights as smooth lobes, with no\n// hard-edged panes. A narrow band that mirrored the sharp window would show a\n// clipped sliver of it at its edge, which reads as a seam rather than a light.\nvec3 studioSoft(vec3 dir) {\n\tvec3 c = mix(vec3(0.05, 0.052, 0.06), vec3(0.12, 0.125, 0.14), smoothstep(-0.2, 0.9, dir.y));\n\tc += vec3(0.3, 0.24, 0.18) * smoothstep(-0.05, -0.75, dir.y);\n\tc += vec3(1.6, 1.55, 1.45) * pow(max(dot(dir, normalize(KEY)), 0.0), 10.0);\n\tc += vec3(0.7, 0.75, 0.85) * pow(max(dot(dir, normalize(vec3(0.55, 0.45, 0.7))), 0.0), 12.0);\n\tc += vec3(0.55, 0.55, 0.55) * pow(max(dot(dir, normalize(vec3(-0.72, 0.2, -0.65))), 0.0), 6.0);\n\treturn c;\n}\n\nfloat hash31(vec3 p) {\n\tp = fract(p * vec3(0.1031, 0.1030, 0.0973) + uSeed * 0.013);\n\tp += dot(p, p.yxz + 33.33);\n\treturn fract((p.x + p.y) * p.z);\n}\n\nvec3 hash33(vec3 p) {\n\treturn vec3(hash31(p), hash31(p + 17.1), hash31(p + 41.7));\n}\n\n// Premultiplied \"over\".\nvec4 over(vec4 top, vec4 under) {\n\treturn top + under * (1.0 - top.a);\n}\n\nvec3 metal(vec3 n, vec3 tone) {\n\tvec3 r = reflect(-VIEW, n);\n\tvec3 env = studio(r);\n\tfloat spec = pow(max(dot(r, normalize(KEY)), 0.0), 60.0);\n\t// Polished metal: the tone multiplies what it reflects, plus a floor of\n\t// its own colour so a dark corner of the studio does not turn it brown.\n\tfloat face = n.z;\n\treturn tone * (0.42 + 0.25 * face + env * 0.9) + vec3(spec * 1.4);\n}\n\nvec3 shadeSphere(vec3 n, vec3 nw, vec3 obj, float px) {\n\tvec3 r = reflect(-VIEW, nw);\n\tfloat facing = n.z;\n\tfloat fresnel = 0.05 + 0.95 * pow(1.0 - facing, 5.0);\n\tvec3 L = normalize(KEY);\n\tvec3 col;\n\n\tif (uFinish < 0.5) {\n\t\t// Gloss: coloured glass over a silvered inside. The body is the colour,\n\t\t// deepened toward the core; the inside throws light back out on the far\n\t\t// side, opposite the key; a clear coat reflects the studio on top.\n\t\tvec3 deep = uColor * uColor;\n\t\tvec3 body = mix(deep * 0.45, uColor * 0.85, pow(1.0 - facing, 1.6));\n\t\tvec3 silvered = studio(r) * uColor * 0.55;\n\t\tfloat inner = pow(max(dot(nw, normalize(vec3(0.5, -0.62, 0.6))), 0.0), 2.5);\n\t\tvec3 glow = mix(uColor, vec3(1.0), 0.12) * inner * 0.72;\n\t\tcol = body + silvered + glow;\n\t\tcol = mix(col, studio(r), fresnel * 0.85);\n\t\tcol += vec3(1.0, 0.98, 0.95) * pow(max(dot(r, L), 0.0), 900.0) * 3.0;\n\t} else if (uFinish < 1.5) {\n\t\t// Matte: velvet. Soft light from the whole room, a sheen that grows toward\n\t\t// the edge instead of a mirror, and a broad, faint highlight.\n\t\tvec3 diffuse = studioDiffuse(nw);\n\t\tfloat sheen = pow(1.0 - facing, 2.2);\n\t\tcol = uColor * diffuse * 0.82;\n\t\tcol += mix(uColor, vec3(1.0), 0.45) * sheen * 0.42;\n\t\tcol += vec3(1.0, 0.97, 0.92) * pow(max(dot(r, L), 0.0), 7.0) * 0.12;\n\t\tcol *= 0.85 + 0.15 * smoothstep(-0.9, 0.4, nw.y);\n\t} else {\n\t\t// Glitter: a dark lacquer under thousands of tiny tilted flakes. Each\n\t\t// flake lives on the turning sphere, so as it turns, a different few line\n\t\t// up between the lights and the viewer.\n\t\tfloat cells = max(8.0, uRadius / (2.6 * px));\n\t\tvec3 g = obj * cells;\n\t\tvec3 cell = floor(g);\n\t\tvec3 jitter = hash33(cell) * 2.0 - 1.0;\n\t\tvec3 nf = normalize(nw + jitter * 0.6);\n\t\tvec3 rf = reflect(-VIEW, nf);\n\t\tfloat lit = hash31(cell + 7.0);\n\t\t// Each flake is a round dot of random size somewhere in its cell, not the cell itself.\n\t\tvec3 centre = 0.25 + 0.5 * hash33(cell + 3.0);\n\t\tfloat flakeR = 0.18 + 0.22 * lit;\n\t\tfloat soft = 0.5 * px * cells / uRadius + 0.04;\n\t\tfloat dotMask = 1.0 - smoothstep(flakeR - soft, flakeR + soft, length(g - cell - centre));\n\t\tfloat glint = smoothstep(0.86, 0.99, dot(rf, L)) * 3.0;\n\t\tglint += smoothstep(0.86, 0.985, dot(rf, normalize(vec3(0.55, 0.45, 0.7)))) * 1.6;\n\t\tglint += smoothstep(0.8, 0.97, dot(rf, normalize(vec3(-0.75, 0.25, -0.4)))) * 1.1;\n\t\tvec3 flake = mix(uColor, vec3(1.0), 0.3) * (0.3 + 0.7 * lit) * studio(rf) * 0.9;\n\t\tvec3 lacquer = uColor * uColor * 0.4 + uColor * studioDiffuse(nw) * 0.4;\n\t\tcol = lacquer + flake * (0.35 + 0.65 * dotMask);\n\t\tcol += mix(uColor, vec3(1.0), 0.65) * glint * dotMask * step(0.3, lit);\n\t\tcol = mix(col, studio(r) * 0.6, fresnel * 0.5);\n\t}\n\n\tif (uBand > 0.5) {\n\t\t// The band lives on the turning sphere: a metal stripe on the equator,\n\t\t// or a ring of studs that shows the turn.\n\t\tfloat half_ = 0.11;\n\t\tfloat edge = 1.5 * px / uRadius;\n\t\tfloat stripe = 1.0 - smoothstep(half_ - edge, half_ + edge, abs(obj.y));\n\t\tfloat mask = stripe;\n\t\tif (uBand > 1.5) {\n\t\t\tfloat a = atan(obj.x, obj.z);\n\t\t\tfloat slots = 18.0;\n\t\t\tfloat s = (fract(a / 6.2831853 * slots) - 0.5) * 6.2831853 / slots;\n\t\t\tvec2 d = vec2(s, obj.y / max(0.2, length(obj.xz)));\n\t\t\tfloat rDot = 0.075;\n\t\t\tmask = 1.0 - smoothstep(rDot - edge * 1.5, rDot + edge * 1.5, length(d));\n\t\t} else {\n\t\t\tfloat groove = 1.0 - smoothstep(0.0, edge * 1.2, abs(abs(obj.y) - half_ * 0.62));\n\t\t\tmask *= 1.0 - 0.35 * groove;\n\t\t}\n\t\tvec3 rb = reflect(-VIEW, nw);\n\t\tvec3 band = uMetal * (0.42 + 0.25 * facing + studioSoft(rb) * 0.9);\n\t\tband += vec3(0.6) * pow(max(dot(rb, L), 0.0), 24.0);\n\t\tband *= mix(0.85, 1.0, facing);\n\t\tcol = mix(col, band, mask * smoothstep(0.0, 0.08, facing));\n\t}\n\n\treturn col;\n}\n\nvec4 shade(vec2 frag) {\n\t// Screen pixels with y down, then the pendulum's frame: pivot at the top\n\t// centre, x across the thread, y down it.\n\tvec2 p = vec2(frag.x, uRes.y - frag.y);\n\tvec2 d = p - vec2(0.5 * uRes.x, 0.0);\n\tfloat ca = cos(uAngle), sa = sin(uAngle);\n\tvec2 l = vec2(d.x * ca - d.y * sa, d.x * sa + d.y * ca);\n\tfloat px = uScale;\n\tvec4 acc = vec4(0.0);\n\n\t// Halo, behind everything.\n\tvec2 fromCentre = l - vec2(0.0, uArm);\n\tfloat dist = length(fromCentre) / uRadius;\n\tif (uGlow > 0.0 && dist > 0.9) {\n\t\t// Falls to exactly zero well inside the box, so no canvas edge ever shows.\n\t\tfloat halo = exp(-(dist - 1.0) * 3.0) * smoothstep(0.9, 1.02, dist) * (1.0 - smoothstep(1.05, 1.6, dist));\n\t\t// A whisper of noise breaks the 8-bit banding of a faint gradient on a light page.\n\t\tfloat grain = fract(sin(dot(frag, vec2(12.9898, 78.233))) * 43758.5453) - 0.5;\n\t\tfloat a = clamp(uGlow * 0.28 * halo + grain / 255.0, 0.0, 1.0);\n\t\tvec3 tint = mix(uColor, vec3(1.0), 0.15);\n\t\tacc = vec4(tint * a, a);\n\t}\n\n\t// Thread, about one CSS pixel wide.\n\tif (l.y > -px && l.y < uThread + px) {\n\t\tfloat w = 0.5 * px;\n\t\tfloat cover = 1.0 - smoothstep(w - 0.5, w + 0.5, abs(l.x));\n\t\tcover *= smoothstep(-0.5, 0.5, l.y) * (1.0 - smoothstep(uThread - 0.5, uThread + 0.5, l.y));\n\t\tfloat a = cover * 0.8;\n\t\tacc = over(vec4(vec3(0.6, 0.6, 0.62) * a, a), acc);\n\t}\n\n\t// The loop the thread goes through.\n\tvec2 lc = vec2(0.0, uThread + uLoopR);\n\tfloat ring = abs(length(l - lc) - uLoopR + 0.5 * uLoopTube);\n\tif (ring < uLoopTube + 1.0) {\n\t\tfloat cover = 1.0 - smoothstep(0.5 * uLoopTube - 0.5, 0.5 * uLoopTube + 0.5, ring);\n\t\t// Tube normal: across the tube in the plane, out of it at the crest.\n\t\tvec2 rn = normalize(l - lc + 1e-4);\n\t\tfloat across = clamp((length(l - lc) - (uLoopR - 0.5 * uLoopTube)) / max(0.5, 0.5 * uLoopTube), -1.0, 1.0);\n\t\tvec2 up = vec2(rn.x, -rn.y) * across;\n\t\tvec3 nw = vec3(up.x * ca - up.y * sa, up.x * sa + up.y * ca, sqrt(max(0.0, 1.0 - across * across)));\n\t\tacc = over(vec4(metal(nw, uMetal) * cover, cover), acc);\n\t}\n\n\t// The sphere.\n\tvec2 q = vec2(fromCentre.x, -fromCentre.y) / uRadius;\n\tfloat r2 = dot(q, q);\n\tfloat edge = px / uRadius;\n\tif (r2 < (1.0 + edge) * (1.0 + edge)) {\n\t\tfloat cover = 1.0 - smoothstep(1.0 - edge, 1.0 + edge * 0.5, sqrt(r2));\n\t\tvec2 qc = q * min(1.0, 0.999 / max(sqrt(r2), 1e-4));\n\t\tvec3 n = vec3(qc, sqrt(max(0.0, 1.0 - dot(qc, qc))));\n\t\t// World normal: the local frame is turned by the swing.\n\t\tvec3 nw = vec3(n.x * ca - n.y * sa, n.x * sa + n.y * ca, n.z);\n\t\t// Object space: the sphere also turns around its thread.\n\t\tfloat ct = cos(uTwist), st = sin(uTwist);\n\t\tvec3 obj = vec3(n.x * ct - n.z * st, n.y, n.x * st + n.z * ct);\n\t\tvec3 col = shadeSphere(n, nw, obj, px);\n\t\t// The cap shades the very top of the sphere.\n\t\tfloat neck = smoothstep(0.86, 1.0, n.y) * (1.0 - smoothstep(0.0, 0.45, abs(n.x)));\n\t\tcol *= 1.0 - 0.45 * neck;\n\t\tacc = over(vec4(col * cover, cover), acc);\n\t}\n\n\t// The cap: a short fluted metal cylinder with a crown of prongs.\n\tfloat halfW = 0.5 * uCapW;\n\tif (abs(l.x) < halfW + 1.0 && l.y > uCapTop - 1.0 && l.y < uCapTop + uCapH * 1.4) {\n\t\tfloat u = clamp(l.x / halfW, -1.0, 1.0);\n\t\tfloat prong = 0.5 + 0.5 * cos(u * 3.14159 * 4.0);\n\t\tfloat bottom = uCapTop + uCapH * (0.82 + 0.38 * prong * prong);\n\t\tfloat cover = (1.0 - smoothstep(halfW - 0.5, halfW + 0.5, abs(l.x)));\n\t\tcover *= smoothstep(uCapTop - 0.5, uCapTop + 0.5, l.y) * (1.0 - smoothstep(bottom - 0.6, bottom + 0.6, l.y));\n\t\tvec3 n = vec3(u, 0.0, sqrt(max(0.0, 1.0 - u * u)));\n\t\tvec3 nw = vec3(n.x * ca, n.x * sa, n.z);\n\t\tvec3 col = metal(normalize(nw), uMetal);\n\t\tfloat flute = 0.5 + 0.5 * cos(u * 3.14159 * 9.0);\n\t\tcol *= 0.78 + 0.22 * flute;\n\t\tfloat rim = 1.0 - smoothstep(0.0, uCapH * 0.22, l.y - uCapTop);\n\t\tcol *= 1.0 - 0.3 * rim;\n\t\tacc = over(vec4(col * cover, cover), acc);\n\t}\n\n\treturn acc;\n}\n\nvoid main() {\n\t// Four rotated-grid taps: every edge is analytic, so this is the antialiasing.\n\tvec4 acc = shade(gl_FragCoord.xy + vec2(-0.375, -0.125));\n\tacc += shade(gl_FragCoord.xy + vec2(0.125, -0.375));\n\tacc += shade(gl_FragCoord.xy + vec2(0.375, 0.125));\n\tacc += shade(gl_FragCoord.xy + vec2(-0.125, 0.375));\n\tacc *= 0.25;\n\t// Gentle filmic shoulder so the soft boxes do not clip flat.\n\tacc.rgb = acc.rgb / (1.0 + max(vec3(0.0), acc.rgb - acc.a) * 0.6);\n\tgl_FragColor = vec4(min(acc.rgb, vec3(acc.a)), acc.a);\n}\n";
173
+ /**
174
+ * Start the ornament on `canvas`. Returns `null` when WebGL is unavailable or
175
+ * the shader does not compile, so a wrapper can leave its fallback showing.
176
+ */
177
+ export declare function createOrnament(elements: OrnamentElements, options?: OrnamentInitOptions): OrnamentEngine | null;