@luna-park/plugin-gradient 0.0.0-stage → 1.0.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 CHANGED
@@ -1,3 +1,33 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
1
+ # Luna Park Gradient plugin
2
+
3
+ Animated, grainy WebGL2 gradient backgrounds for Luna Park. Raw WebGL2, no runtime dependencies.
4
+
5
+ Adds one component, **Gradient/Gradient** (`LpgGradient`): a container whose background is the gradient. Its slot content is rendered on top.
6
+
7
+ | Prop | Values |
8
+ |---|---|
9
+ | `type` | `flow`, `irregular`, `edgy`, `multicolor`, `radial`, `banding`, `duotone` |
10
+ | `palette` | `ember`, `aurora`, `sunset`, `dusk`, `citrus`, `coral`, `ocean`, `mono`, `custom` |
11
+ | `colors` | 2–6 colours, used when `palette` is `custom` |
12
+ | `motion` | `random`, `cursor`, `scroll`, `none` |
13
+ | `speed` | 0–100 %, default 20 |
14
+ | `cursorEffect` | lens, pinch, smear (cursor motion) |
15
+ | `cursorRadius`, `cursorStrength` | size (% of short side) and intensity (%) of the cursor effect |
16
+ | `animateGrain` | `true` = film-like moving grain, `false` = static grain |
17
+ | `grain`, `seed`, `angle`, `bands` | optional fine-tuning |
18
+
19
+ ## Scripts
20
+ ```bash
21
+ pnpm install
22
+ pnpm dev:story # Histoire playground on http://localhost:1980
23
+ pnpm build # dist/index.js (editor) + dist/runtime.js (generated apps)
24
+ pnpm preview # serve dist/ on http://127.0.0.1:2084 for the editor
25
+ pnpm typecheck && pnpm lint
26
+ ```
27
+
28
+ ## How it works
29
+ - `src/engine/shaders/fragment.glsl`: one fragment shader, one branch per type. Each branch domain-warps the position with 3D simplex noise, computes a colour field and adds screen-space grain (static, or re-rolled at 24 fps with `animateGrain`). In cursor mode, a local lens, pinch or smear is applied around the pointer before the colour field is computed.
30
+ - `src/engine/renderer.ts`: WebGL2 setup (full-screen triangle, context loss handling).
31
+ - `src/engine/motion.ts`: random, cursor and scroll drivers that animate `time`, `offset` and the cursor uniforms (position, strength, velocity).
32
+ - `src/components/LpgGradient.vue`: render loop. It pauses off screen and in hidden tabs, respects `prefers-reduced-motion`, caps DPR at 1.5 and falls back to a CSS gradient without WebGL2.
33
+ - `src/engine/presets.ts` / `palettes.ts`: per-type shader settings and colour presets.
@@ -0,0 +1,466 @@
1
+ import { computed as e, createElementBlock as t, createElementVNode as n, defineComponent as r, normalizeStyle as i, onBeforeUnmount as a, onMounted as o, openBlock as s, ref as c, renderSlot as l, useTemplateRef as u, vShow as d, watch as f, withDirectives as p } from "vue";
2
+ //#region src/engine/motion.ts
3
+ var m = {
4
+ cursor: "Cursor",
5
+ none: "Static",
6
+ random: "Random",
7
+ scroll: "Scroll"
8
+ }, h = {
9
+ lens: {
10
+ index: 0,
11
+ label: "Lens"
12
+ },
13
+ pinch: {
14
+ index: 1,
15
+ label: "Pinch"
16
+ },
17
+ smear: {
18
+ index: 2,
19
+ label: "Smear"
20
+ }
21
+ }, g = Object.fromEntries(Object.entries(h).map(([e, { label: t }]) => [e, t])), _ = .5;
22
+ function v(e, t, n, r) {
23
+ return e + (t - e) * (1 - Math.exp(-n * r));
24
+ }
25
+ function y(e, t, n, r) {
26
+ let i = {
27
+ offset: [0, 0],
28
+ pointer: [0, 0],
29
+ pointerStrength: 0,
30
+ pointerVelocity: [0, 0],
31
+ time: r?.time ?? 0
32
+ };
33
+ if (e === "random") return {
34
+ animated: !0,
35
+ dispose: () => {},
36
+ state: i,
37
+ update: (e) => (i.time += e * n() * _, i.offset[0] = Math.sin(i.time * .21) * .12, i.offset[1] = Math.cos(i.time * .17) * .12, i)
38
+ };
39
+ if (e === "cursor") {
40
+ let e = [0, 0], r = !1, a = (n) => {
41
+ let i = t.getBoundingClientRect(), a = Math.min(i.width, i.height) || 1;
42
+ e[0] = (n.clientX - i.left - i.width / 2) / a, e[1] = (i.height / 2 - (n.clientY - i.top)) / a, r = n.clientX >= i.left && n.clientX <= i.right && n.clientY >= i.top && n.clientY <= i.bottom;
43
+ }, o = () => {
44
+ r = !1;
45
+ };
46
+ return window.addEventListener("pointermove", a, { passive: !0 }), document.documentElement.addEventListener("pointerleave", o), {
47
+ animated: !0,
48
+ dispose: () => {
49
+ window.removeEventListener("pointermove", a), document.documentElement.removeEventListener("pointerleave", o);
50
+ },
51
+ state: i,
52
+ update: (t) => {
53
+ if (!t) return i;
54
+ let a = n();
55
+ i.time += t * a * _ * .5, i.pointerStrength < .01 && (i.pointer = [...e]);
56
+ let o = [...i.pointer], s = 4 + a * 8;
57
+ i.pointer[0] = v(i.pointer[0], e[0], s, t), i.pointer[1] = v(i.pointer[1], e[1], s, t), i.pointerStrength = v(i.pointerStrength, +!!r, 3, t);
58
+ for (let e of [0, 1]) {
59
+ let n = Math.max(-3, Math.min(3, (i.pointer[e] - o[e]) / t));
60
+ i.pointerVelocity[e] = v(i.pointerVelocity[e], n, 6, t);
61
+ }
62
+ return i;
63
+ }
64
+ };
65
+ }
66
+ if (e === "scroll") {
67
+ let e = i.time;
68
+ return {
69
+ animated: !0,
70
+ dispose: () => {},
71
+ state: i,
72
+ update: (r) => {
73
+ if (!r) return i;
74
+ let a = t.getBoundingClientRect(), o = window.innerHeight || 1, s = Math.max(0, Math.min(1, (o - a.top) / (o + a.height))), c = n();
75
+ return i.time = v(i.time, e + s * 6 * c, 6, r), i.offset[1] = v(i.offset[1], (s - .5) * .5 * c, 6, r), i;
76
+ }
77
+ };
78
+ }
79
+ return {
80
+ animated: !1,
81
+ dispose: () => {},
82
+ state: i,
83
+ update: () => i
84
+ };
85
+ }
86
+ var b;
87
+ function x(e) {
88
+ let t = /^#?([\da-f]{3,8})$/i.exec(e.trim())?.[1];
89
+ if (t && (t.length === 3 || t.length === 4)) return [
90
+ 0,
91
+ 1,
92
+ 2
93
+ ].map((e) => parseInt(t[e] + t[e], 16) / 255);
94
+ if (t && (t.length === 6 || t.length === 8)) return [
95
+ 0,
96
+ 2,
97
+ 4
98
+ ].map((e) => parseInt(t.slice(e, e + 2), 16) / 255);
99
+ if (b ??= document.createElement("canvas").getContext("2d"), !b) return [
100
+ 0,
101
+ 0,
102
+ 0
103
+ ];
104
+ b.fillStyle = "#000000", b.fillStyle = e;
105
+ let n = String(b.fillStyle);
106
+ if (n.startsWith("#")) return x(n);
107
+ let r = n.match(/[\d.]+/g)?.slice(0, 3).map((e) => Number(e) / 255);
108
+ return r?.length === 3 ? r : [
109
+ 0,
110
+ 0,
111
+ 0
112
+ ];
113
+ }
114
+ function S(e) {
115
+ let t = /* @__PURE__ */ new Float32Array(18);
116
+ return e.slice(0, 6).forEach((e, n) => t.set(x(e), n * 3)), t;
117
+ }
118
+ //#endregion
119
+ //#region src/engine/palettes.ts
120
+ var C = {
121
+ aurora: {
122
+ colors: [
123
+ "#8338ec",
124
+ "#3a86ff",
125
+ "#00f5d4",
126
+ "#ff5f6d"
127
+ ],
128
+ label: "Aurora"
129
+ },
130
+ citrus: {
131
+ colors: ["#fff27a", "#ff7b00"],
132
+ label: "Citrus"
133
+ },
134
+ coral: {
135
+ colors: [
136
+ "#c44d58",
137
+ "#ff6b6b",
138
+ "#ffb3b3",
139
+ "#ffe5e5"
140
+ ],
141
+ label: "Coral"
142
+ },
143
+ dusk: {
144
+ colors: [
145
+ "#2b0a3d",
146
+ "#8e3b6b",
147
+ "#f28482",
148
+ "#f6bd60",
149
+ "#00a6a6"
150
+ ],
151
+ label: "Dusk"
152
+ },
153
+ ember: {
154
+ colors: [
155
+ "#0b1026",
156
+ "#23418a",
157
+ "#aadfd9",
158
+ "#e64f0f"
159
+ ],
160
+ label: "Ember"
161
+ },
162
+ mono: {
163
+ colors: [
164
+ "#0d0d0d",
165
+ "#4a4a4a",
166
+ "#e0e0e0"
167
+ ],
168
+ label: "Mono"
169
+ },
170
+ ocean: {
171
+ colors: [
172
+ "#03045e",
173
+ "#0077b6",
174
+ "#00b4d8",
175
+ "#caf0f8"
176
+ ],
177
+ label: "Ocean"
178
+ },
179
+ sunset: {
180
+ colors: [
181
+ "#3a0ca3",
182
+ "#f72585",
183
+ "#ff8fab",
184
+ "#ffc8a2"
185
+ ],
186
+ label: "Sunset"
187
+ }
188
+ }, w = "ember", T = {
189
+ ...Object.fromEntries(Object.entries(C).map(([e, { label: t }]) => [e, t])),
190
+ custom: "Custom"
191
+ };
192
+ function E(e, t) {
193
+ return e === "custom" && t && t.length >= 2 ? t.slice(0, 6) : e === "custom" && t?.length === 1 ? [t[0], t[0]] : (C[e] ?? C.ember).colors;
194
+ }
195
+ //#endregion
196
+ //#region src/engine/presets.ts
197
+ var D = {
198
+ banding: {
199
+ angle: -90,
200
+ index: 5,
201
+ label: "Banding",
202
+ palette: "coral",
203
+ scale: .8,
204
+ sharpness: 1,
205
+ spread: 1,
206
+ warp: .03
207
+ },
208
+ duotone: {
209
+ angle: -135,
210
+ index: 6,
211
+ label: "Duotone",
212
+ palette: "citrus",
213
+ scale: .7,
214
+ sharpness: 1,
215
+ spread: 1.4,
216
+ warp: .1
217
+ },
218
+ edgy: {
219
+ angle: 0,
220
+ index: 2,
221
+ label: "Edgy",
222
+ palette: "sunset",
223
+ scale: 1.3,
224
+ sharpness: 6,
225
+ spread: 1,
226
+ warp: .35
227
+ },
228
+ flow: {
229
+ angle: -22,
230
+ index: 0,
231
+ label: "Flow",
232
+ palette: "ember",
233
+ scale: .9,
234
+ sharpness: 1,
235
+ spread: 2.6,
236
+ warp: .9
237
+ },
238
+ irregular: {
239
+ angle: 0,
240
+ index: 1,
241
+ label: "Irregular",
242
+ palette: "aurora",
243
+ scale: .9,
244
+ sharpness: 1.4,
245
+ spread: 1,
246
+ warp: .35
247
+ },
248
+ multicolor: {
249
+ angle: -65,
250
+ index: 3,
251
+ label: "Multicolor",
252
+ palette: "dusk",
253
+ scale: .8,
254
+ sharpness: 1,
255
+ spread: 1.1,
256
+ warp: .25
257
+ },
258
+ radial: {
259
+ angle: 0,
260
+ index: 4,
261
+ label: "Radial",
262
+ palette: "ocean",
263
+ scale: 1,
264
+ sharpness: 1,
265
+ spread: .75,
266
+ warp: .25
267
+ }
268
+ }, O = "flow", k = Object.fromEntries(Object.entries(D).map(([e, { label: t }]) => [e, t]));
269
+ function A(e) {
270
+ return D[e] ?? D.flow;
271
+ }
272
+ //#endregion
273
+ //#region src/engine/shaders/fragment.glsl?raw
274
+ var j = "// Prepended by renderer.ts: `#version 300 es`, precision, MAX_COLORS and noise.glsl.\r\n\r\nuniform vec3 uColors[MAX_COLORS];\r\nuniform int uColorCount;\r\nuniform int uType;\r\nuniform vec2 uResolution;\r\nuniform float uTime;\r\nuniform vec2 uOffset;\r\nuniform float uSeed;\r\nuniform float uAngle;\r\nuniform float uWarp;\r\nuniform float uScale;\r\nuniform float uSpread;\r\nuniform float uSharpness;\r\nuniform float uBands;\r\nuniform float uGrain;\r\nuniform float uGrainSeed;\r\nuniform vec2 uPointer;\r\nuniform float uPointerStrength;\r\nuniform vec2 uPointerVelocity;\r\nuniform int uCursorEffect;\r\nuniform float uCursorRadius;\r\nuniform float uCursorStrength;\r\n\r\nout vec4 fragColor;\r\n\r\nconst int CURSOR_LENS = 0;\r\nconst int CURSOR_PINCH = 1;\r\nconst int CURSOR_SMEAR = 2;\r\n\r\nconst int TYPE_FLOW = 0;\r\nconst int TYPE_IRREGULAR = 1;\r\nconst int TYPE_EDGY = 2;\r\nconst int TYPE_MULTICOLOR = 3;\r\nconst int TYPE_RADIAL = 4;\r\nconst int TYPE_BANDING = 5;\r\nconst int TYPE_DUOTONE = 6;\r\n\r\nvec2 rotate(vec2 v, float a) {\r\n float s = sin(a);\r\n float c = cos(a);\r\n return mat2(c, s, -s, c) * v;\r\n}\r\n\r\n// Samples the colours as an evenly spaced ramp, t in [0, 1].\r\nvec3 ramp(float t) {\r\n float f = clamp(t, 0.0, 1.0) * float(uColorCount - 1);\r\n int i = min(int(floor(f)), uColorCount - 2);\r\n return mix(uColors[i], uColors[i + 1], smoothstep(0.0, 1.0, f - float(i)));\r\n}\r\n\r\n// Domain warping: pushes the position along a slowly evolving noise field.\r\nvec2 warp(vec2 p, float amount, float scale, float z) {\r\n vec3 q = vec3(p * scale, uTime + uSeed * 7.31 + z);\r\n return p + vec2(snoise(q), snoise(q + vec3(17.3, 5.1, 3.7))) * amount;\r\n}\r\n\r\n// Position of the i-th moving blob.\r\nvec2 blob(int i) {\r\n float k = float(i) * 1.618 + uSeed * 3.1;\r\n float t = uTime * 0.35;\r\n return vec2(snoise(vec3(k, t, 0.0)), snoise(vec3(t, k, 11.0))) * 0.55;\r\n}\r\n\r\n// Blobs blended by inverse distance. Higher sharpness gives harder edges.\r\nvec3 blobs(vec2 p) {\r\n vec3 sum = vec3(0.0);\r\n float total = 0.0;\r\n for (int i = 0; i < MAX_COLORS; i++) {\r\n if (i >= uColorCount) break;\r\n float d = distance(p, blob(i));\r\n float w = 1.0 / pow(d * d + 0.0005, uSharpness);\r\n sum += uColors[i] * w;\r\n total += w;\r\n }\r\n return sum / total;\r\n}\r\n\r\n// Signed position along the gradient axis, remapped to [0, 1] by uSpread.\r\nfloat linear(vec2 p) {\r\n return dot(p, vec2(cos(uAngle), sin(uAngle))) / uSpread + 0.5;\r\n}\r\n\r\nvec3 flow(vec2 p) {\r\n vec2 q = warp(p, uWarp, uScale, 0.0);\r\n q = rotate(q, -uAngle);\r\n q.x /= uSpread;\r\n\r\n // The first colour is the background. The others are soft, stretched bands stacked on y.\r\n float radius = 0.6 / uSharpness;\r\n float spacing = 0.32;\r\n float first = -0.5 * float(uColorCount - 2) * spacing;\r\n vec3 color = uColors[0];\r\n for (int i = 1; i < MAX_COLORS; i++) {\r\n if (i >= uColorCount) break;\r\n vec2 center = vec2(0.0, first + float(i - 1) * spacing);\r\n color = mix(uColors[i], color, smoothstep(0.0, radius, distance(q, center)));\r\n }\r\n return color;\r\n}\r\n\r\n// Local distortion around the cursor. Fades out with distance (Gaussian of radius uCursorRadius).\r\nvec2 cursor(vec2 p) {\r\n float strength = uPointerStrength * uCursorStrength;\r\n if (strength < 0.001) return p;\r\n\r\n vec2 d = p - uPointer;\r\n float falloff = exp(-dot(d, d) / (uCursorRadius * uCursorRadius));\r\n float amount = falloff * strength;\r\n\r\n if (uCursorEffect == CURSOR_LENS) {\r\n // Sampling closer to the cursor magnifies the colours under it.\r\n return uPointer + d * (1.0 - min(amount * 0.6, 0.95));\r\n }\r\n if (uCursorEffect == CURSOR_PINCH) {\r\n // Sampling further away shrinks the colours towards the cursor.\r\n return uPointer + d * (1.0 + amount * 0.8);\r\n }\r\n // Smear: colours trail behind the cursor like a brush stroke.\r\n return p - uPointerVelocity * amount * 0.35;\r\n}\r\n\r\nvoid main() {\r\n vec2 p = (gl_FragCoord.xy - 0.5 * uResolution) / min(uResolution.x, uResolution.y);\r\n p = cursor(p) + uOffset;\r\n\r\n vec3 color;\r\n if (uType == TYPE_FLOW) {\r\n color = flow(p);\r\n } else if (uType == TYPE_IRREGULAR) {\r\n color = blobs(warp(p, uWarp, uScale, 0.0));\r\n } else if (uType == TYPE_EDGY) {\r\n // Two warp passes fold the field. Sharp weights turn the folds into creases.\r\n vec2 q = warp(p, uWarp, uScale, 0.0);\r\n q = warp(q, uWarp * 0.6, uScale * 2.0, 31.0);\r\n color = blobs(q);\r\n } else if (uType == TYPE_MULTICOLOR) {\r\n color = ramp(linear(warp(p, uWarp, uScale, 0.0)));\r\n } else if (uType == TYPE_RADIAL) {\r\n vec2 center = vec2(snoise(vec3(uTime * 0.3, uSeed, 3.0)), snoise(vec3(uSeed, uTime * 0.3, 9.0))) * 0.2;\r\n color = ramp(length(warp(p, uWarp, uScale, 0.0) - center) / uSpread);\r\n } else if (uType == TYPE_BANDING) {\r\n float t = clamp(linear(warp(p, uWarp, uScale, 0.0)), 0.0, 0.9999);\r\n color = ramp(floor(t * uBands) / max(uBands - 1.0, 1.0));\r\n } else {\r\n float t = smoothstep(0.0, 1.0, linear(warp(p, uWarp, uScale, 0.0)));\r\n color = mix(uColors[0], uColors[uColorCount - 1], t);\r\n }\r\n\r\n // Film grain in screen pixels (static unless uGrainSeed changes). It also hides banding.\r\n color += (hash12(gl_FragCoord.xy + uGrainSeed) - 0.5) * uGrain;\r\n\r\n fragColor = vec4(clamp(color, 0.0, 1.0), 1.0);\r\n}\r\n", M = "// 3D simplex noise.\n// Ian McEwan, Stefan Gustavson (Ashima Arts), MIT License: https://github.com/ashima/webgl-noise\nvec3 mod289(vec3 x) { return x - floor(x * (1.0 / 289.0)) * 289.0; }\nvec4 mod289(vec4 x) { return x - floor(x * (1.0 / 289.0)) * 289.0; }\nvec4 permute(vec4 x) { return mod289(((x * 34.0) + 10.0) * x); }\nvec4 taylorInvSqrt(vec4 r) { return 1.79284291400159 - 0.85373472095314 * r; }\n\nfloat snoise(vec3 v) {\n const vec2 C = vec2(1.0 / 6.0, 1.0 / 3.0);\n const vec4 D = vec4(0.0, 0.5, 1.0, 2.0);\n\n vec3 i = floor(v + dot(v, C.yyy));\n vec3 x0 = v - i + dot(i, C.xxx);\n\n vec3 g = step(x0.yzx, x0.xyz);\n vec3 l = 1.0 - g;\n vec3 i1 = min(g.xyz, l.zxy);\n vec3 i2 = max(g.xyz, l.zxy);\n\n vec3 x1 = x0 - i1 + C.xxx;\n vec3 x2 = x0 - i2 + C.yyy;\n vec3 x3 = x0 - D.yyy;\n\n i = mod289(i);\n vec4 p = permute(permute(permute(\n i.z + vec4(0.0, i1.z, i2.z, 1.0))\n + i.y + vec4(0.0, i1.y, i2.y, 1.0))\n + i.x + vec4(0.0, i1.x, i2.x, 1.0));\n\n float n_ = 0.142857142857;\n vec3 ns = n_ * D.wyz - D.xzx;\n\n vec4 j = p - 49.0 * floor(p * ns.z * ns.z);\n\n vec4 x_ = floor(j * ns.z);\n vec4 y_ = floor(j - 7.0 * x_);\n\n vec4 x = x_ * ns.x + ns.yyyy;\n vec4 y = y_ * ns.x + ns.yyyy;\n vec4 h = 1.0 - abs(x) - abs(y);\n\n vec4 b0 = vec4(x.xy, y.xy);\n vec4 b1 = vec4(x.zw, y.zw);\n\n vec4 s0 = floor(b0) * 2.0 + 1.0;\n vec4 s1 = floor(b1) * 2.0 + 1.0;\n vec4 sh = -step(h, vec4(0.0));\n\n vec4 a0 = b0.xzyw + s0.xzyw * sh.xxyy;\n vec4 a1 = b1.xzyw + s1.xzyw * sh.zzww;\n\n vec3 p0 = vec3(a0.xy, h.x);\n vec3 p1 = vec3(a0.zw, h.y);\n vec3 p2 = vec3(a1.xy, h.z);\n vec3 p3 = vec3(a1.zw, h.w);\n\n vec4 norm = taylorInvSqrt(vec4(dot(p0, p0), dot(p1, p1), dot(p2, p2), dot(p3, p3)));\n p0 *= norm.x;\n p1 *= norm.y;\n p2 *= norm.z;\n p3 *= norm.w;\n\n vec4 m = max(0.5 - vec4(dot(x0, x0), dot(x1, x1), dot(x2, x2), dot(x3, x3)), 0.0);\n m = m * m;\n return 105.0 * dot(m * m, vec4(dot(p0, x0), dot(p1, x1), dot(p2, x2), dot(p3, x3)));\n}\n\n// Hash without sine. David Hoskins, MIT License: https://www.shadertoy.com/view/4djSRW\nfloat hash12(vec2 p) {\n vec3 p3 = fract(vec3(p.xyx) * 0.1031);\n p3 += dot(p3, p3.yzx + 33.33);\n return fract((p3.x + p3.y) * p3.z);\n}\n", N = "#version 300 es\n\n// Full-screen triangle generated from gl_VertexID: no vertex buffer needed.\nvoid main() {\n vec2 position = vec2((gl_VertexID << 1) & 2, gl_VertexID & 2);\n gl_Position = vec4(position * 2.0 - 1.0, 0.0, 1.0);\n}\n", P = `#version 300 es
275
+ precision highp float;
276
+ #define MAX_COLORS 6
277
+ ${M}
278
+ ${j}`, F = [
279
+ "uColors",
280
+ "uColorCount",
281
+ "uType",
282
+ "uResolution",
283
+ "uTime",
284
+ "uOffset",
285
+ "uSeed",
286
+ "uAngle",
287
+ "uWarp",
288
+ "uScale",
289
+ "uSpread",
290
+ "uSharpness",
291
+ "uBands",
292
+ "uGrain",
293
+ "uGrainSeed",
294
+ "uPointer",
295
+ "uPointerStrength",
296
+ "uPointerVelocity",
297
+ "uCursorEffect",
298
+ "uCursorRadius",
299
+ "uCursorStrength"
300
+ ], I = class {
301
+ supported;
302
+ canvas;
303
+ gl;
304
+ program = null;
305
+ vao = null;
306
+ locations = null;
307
+ uniforms;
308
+ colors;
309
+ lost = !1;
310
+ onRestore;
311
+ constructor(e, t, n) {
312
+ this.canvas = e, this.onRestore = n, this.uniforms = t, this.colors = S(t.colors), this.gl = e.getContext("webgl2", {
313
+ alpha: !1,
314
+ antialias: !1,
315
+ depth: !1,
316
+ premultipliedAlpha: !1
317
+ }), this.supported = !!this.gl && this.init(), e.addEventListener("webglcontextlost", this.handleLost), e.addEventListener("webglcontextrestored", this.handleRestored);
318
+ }
319
+ setUniforms(e) {
320
+ e.colors && e.colors !== this.uniforms.colors && (this.colors = S(e.colors)), Object.assign(this.uniforms, e);
321
+ }
322
+ resize(e, t, n) {
323
+ this.canvas.width = Math.max(1, Math.round(e * n)), this.canvas.height = Math.max(1, Math.round(t * n));
324
+ }
325
+ render() {
326
+ let { gl: e, locations: t, uniforms: n } = this;
327
+ e && t && this.program && !this.lost && (e.viewport(0, 0, e.drawingBufferWidth, e.drawingBufferHeight), e.useProgram(this.program), e.uniform3fv(t.uColors, this.colors), e.uniform1i(t.uColorCount, Math.max(2, Math.min(n.colors.length, 6))), e.uniform1i(t.uType, n.type), e.uniform2f(t.uResolution, e.drawingBufferWidth, e.drawingBufferHeight), e.uniform1f(t.uTime, n.time), e.uniform2f(t.uOffset, n.offset[0], n.offset[1]), e.uniform1f(t.uSeed, n.seed), e.uniform1f(t.uAngle, n.angle * Math.PI / 180), e.uniform1f(t.uWarp, n.warp), e.uniform1f(t.uScale, n.scale), e.uniform1f(t.uSpread, n.spread), e.uniform1f(t.uSharpness, n.sharpness), e.uniform1f(t.uBands, n.bands), e.uniform1f(t.uGrain, n.grain), e.uniform1f(t.uGrainSeed, n.grainSeed), e.uniform2f(t.uPointer, n.pointer[0], n.pointer[1]), e.uniform1f(t.uPointerStrength, n.pointerStrength), e.uniform2f(t.uPointerVelocity, n.pointerVelocity[0], n.pointerVelocity[1]), e.uniform1i(t.uCursorEffect, n.cursorEffect), e.uniform1f(t.uCursorRadius, n.cursorRadius), e.uniform1f(t.uCursorStrength, n.cursorStrength), e.bindVertexArray(this.vao), e.drawArrays(e.TRIANGLES, 0, 3));
328
+ }
329
+ dispose() {
330
+ this.canvas.removeEventListener("webglcontextlost", this.handleLost), this.canvas.removeEventListener("webglcontextrestored", this.handleRestored), this.gl?.deleteProgram(this.program), this.gl?.deleteVertexArray(this.vao), this.gl?.getExtension("WEBGL_lose_context")?.loseContext();
331
+ }
332
+ init() {
333
+ let e = this.gl;
334
+ if (!e) return !1;
335
+ let t = L(e, e.VERTEX_SHADER, N), n = L(e, e.FRAGMENT_SHADER, P), r = e.createProgram();
336
+ return !t || !n ? !1 : (e.attachShader(r, t), e.attachShader(r, n), e.linkProgram(r), e.deleteShader(t), e.deleteShader(n), e.getProgramParameter(r, e.LINK_STATUS) ? (this.program = r, this.vao = e.createVertexArray(), this.locations = Object.fromEntries(F.map((t) => [t, e.getUniformLocation(r, t)])), !0) : (console.error("[gradient] program link failed:", e.getProgramInfoLog(r)), !1));
337
+ }
338
+ handleLost = (e) => {
339
+ e.preventDefault(), this.lost = !0;
340
+ };
341
+ handleRestored = () => {
342
+ this.lost = !1, this.init(), this.onRestore?.();
343
+ };
344
+ };
345
+ function L(e, t, n) {
346
+ let r = e.createShader(t);
347
+ return r ? (e.shaderSource(r, n), e.compileShader(r), e.getShaderParameter(r, e.COMPILE_STATUS) ? r : (console.error("[gradient] shader compile failed:", e.getShaderInfoLog(r)), e.deleteShader(r), null)) : null;
348
+ }
349
+ //#endregion
350
+ //#region src/components/LpgGradient.vue?vue&type=script&setup=true&lang.ts
351
+ var R = { class: "lpg-content" }, z = 1.5, B = 24, V = /*#__PURE__*/ ((e, t) => {
352
+ let n = e.__vccOpts || e;
353
+ for (let [e, r] of t) n[e] = r;
354
+ return n;
355
+ })(/* @__PURE__ */ r({
356
+ __name: "LpgGradient",
357
+ props: {
358
+ angle: { default: void 0 },
359
+ animateGrain: {
360
+ type: Boolean,
361
+ default: !1
362
+ },
363
+ bands: { default: 8 },
364
+ colors: { default: () => [] },
365
+ cursorEffect: { default: "lens" },
366
+ cursorRadius: { default: 30 },
367
+ cursorStrength: { default: 100 },
368
+ forceFallback: {
369
+ type: Boolean,
370
+ default: !1
371
+ },
372
+ grain: { default: .04 },
373
+ motion: { default: "random" },
374
+ palette: { default: "ember" },
375
+ seed: { default: 0 },
376
+ speed: { default: 20 },
377
+ type: { default: "flow" }
378
+ },
379
+ setup(r) {
380
+ let m = r, g = u("root"), _ = u("canvas"), v = c(!1), b = e(() => m.forceFallback || v.value), x = e(() => E(m.palette, m.colors)), S = e(() => A(m.type)), C = e(() => m.angle ?? S.value.angle), w = e(() => `linear-gradient(${90 - C.value}deg, ${x.value.join(", ")})`), T = e(() => ({
381
+ angle: C.value,
382
+ bands: Math.max(2, Math.round(m.bands)),
383
+ colors: x.value,
384
+ cursorEffect: (h[m.cursorEffect] ?? h.lens).index,
385
+ cursorRadius: Math.max(1, m.cursorRadius) / 100,
386
+ cursorStrength: Math.max(0, m.cursorStrength) / 100,
387
+ grain: m.grain,
388
+ scale: S.value.scale,
389
+ seed: m.seed,
390
+ sharpness: S.value.sharpness,
391
+ spread: S.value.spread,
392
+ type: S.value.index,
393
+ warp: S.value.warp
394
+ })), D, O, k = 0, j = 0, M = 0, N = !0, P, F, L = typeof window > "u" ? void 0 : window.matchMedia("(prefers-reduced-motion: reduce)");
395
+ function V(e) {
396
+ if (!D || !O) return;
397
+ M += e;
398
+ let { offset: t, pointer: n, pointerStrength: r, pointerVelocity: i, time: a } = O.update(e), o = m.animateGrain && !L?.matches ? Math.floor(M * B) % 1e3 * 7.13 : 0;
399
+ D.setUniforms({
400
+ grainSeed: o,
401
+ offset: t,
402
+ pointer: n,
403
+ pointerStrength: r,
404
+ pointerVelocity: i,
405
+ time: a
406
+ }), D.render();
407
+ }
408
+ function H() {
409
+ return !!O?.animated || m.animateGrain && !L?.matches;
410
+ }
411
+ function U(e) {
412
+ k = 0;
413
+ let t = Math.min((e - j) / 1e3, .1);
414
+ j = e, V(t), W();
415
+ }
416
+ function W() {
417
+ !k && N && !document.hidden && H() && (j ||= performance.now(), k = requestAnimationFrame(U));
418
+ }
419
+ function G() {
420
+ cancelAnimationFrame(k), k = 0, j = 0;
421
+ }
422
+ function K() {
423
+ k || V(0);
424
+ }
425
+ function q() {
426
+ let e = O?.state;
427
+ O?.dispose(), G(), g.value && (O = y(L?.matches ? "none" : m.motion, g.value, () => Math.max(0, Math.min(100, m.speed)) / 100, e), K(), W());
428
+ }
429
+ function J() {
430
+ document.hidden ? G() : W();
431
+ }
432
+ return o(() => {
433
+ g.value && _.value && !m.forceFallback && (D = new I(_.value, {
434
+ ...T.value,
435
+ grainSeed: 0,
436
+ offset: [0, 0],
437
+ pointer: [0, 0],
438
+ pointerStrength: 0,
439
+ pointerVelocity: [0, 0],
440
+ time: 0
441
+ }, K), D.supported ? (P = new ResizeObserver(([e]) => {
442
+ D?.resize(e.contentRect.width, e.contentRect.height, Math.min(window.devicePixelRatio || 1, z)), K();
443
+ }), P.observe(g.value), F = new IntersectionObserver(([e]) => {
444
+ N = e.isIntersecting, N ? W() : G();
445
+ }), F.observe(g.value), document.addEventListener("visibilitychange", J), L?.addEventListener("change", q), q()) : (v.value = !0, D.dispose(), D = void 0));
446
+ }), a(() => {
447
+ G(), O?.dispose(), P?.disconnect(), F?.disconnect(), document.removeEventListener("visibilitychange", J), L?.removeEventListener("change", q), D?.dispose();
448
+ }), f(T, (e) => {
449
+ D?.setUniforms(e), K();
450
+ }), f(() => m.motion, q), f(() => m.animateGrain, () => {
451
+ H() ? W() : (G(), K());
452
+ }), (e, r) => (s(), t("div", {
453
+ ref_key: "root",
454
+ ref: g,
455
+ class: "lpg-gradient",
456
+ style: i({ background: w.value })
457
+ }, [p(n("canvas", {
458
+ ref_key: "canvas",
459
+ ref: _,
460
+ "aria-hidden": "true",
461
+ class: "lpg-canvas"
462
+ }, null, 512), [[d, !b.value]]), n("div", R, [l(e.$slots, "default", {}, void 0, !0)])], 4));
463
+ }
464
+ }), [["__scopeId", "data-v-d6eac249"]]);
465
+ //#endregion
466
+ export { k as a, C as c, g as d, m as f, D as i, E as l, I as n, w as o, O as r, T as s, V as t, y as u };