@egen-civitas/esm-styleguide 1.0.1 → 1.2.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 (47) hide show
  1. package/CHANGELOG.md +38 -0
  2. package/dist/content-section/content-section.component.d.ts +44 -0
  3. package/dist/content-section/content-section.component.d.ts.map +1 -0
  4. package/dist/content-section/content-section.component.js +90 -0
  5. package/dist/content-section/content-section.module.scss +70 -0
  6. package/dist/content-section/index.d.ts +2 -0
  7. package/dist/content-section/index.d.ts.map +1 -0
  8. package/dist/content-section/index.js +1 -0
  9. package/dist/hero-mosaic/hero-mosaic.component.d.ts +15 -0
  10. package/dist/hero-mosaic/hero-mosaic.component.d.ts.map +1 -0
  11. package/dist/hero-mosaic/hero-mosaic.component.js +37 -0
  12. package/dist/hero-mosaic/hero-mosaic.module.scss +124 -0
  13. package/dist/hero-mosaic/hero-tile-card.component.d.ts +23 -0
  14. package/dist/hero-mosaic/hero-tile-card.component.d.ts.map +1 -0
  15. package/dist/hero-mosaic/hero-tile-card.component.js +62 -0
  16. package/dist/hero-mosaic/index.d.ts +3 -0
  17. package/dist/hero-mosaic/index.d.ts.map +1 -0
  18. package/dist/hero-mosaic/index.js +2 -0
  19. package/dist/internal.d.ts +4 -0
  20. package/dist/internal.d.ts.map +1 -1
  21. package/dist/internal.js +4 -0
  22. package/dist/page-background/gradient-wave.component.d.ts +22 -0
  23. package/dist/page-background/gradient-wave.component.d.ts.map +1 -0
  24. package/dist/page-background/gradient-wave.component.js +751 -0
  25. package/dist/page-background/index.d.ts +5 -0
  26. package/dist/page-background/index.d.ts.map +1 -0
  27. package/dist/page-background/index.js +4 -0
  28. package/dist/page-background/page-background.component.d.ts +96 -0
  29. package/dist/page-background/page-background.component.d.ts.map +1 -0
  30. package/dist/page-background/page-background.component.js +287 -0
  31. package/dist/page-background/page-background.context.d.ts +24 -0
  32. package/dist/page-background/page-background.context.d.ts.map +1 -0
  33. package/dist/page-background/page-background.context.js +31 -0
  34. package/dist/page-background/page-background.stories.js +42 -0
  35. package/dist/page-background/page-background.utils.d.ts +12 -0
  36. package/dist/page-background/page-background.utils.d.ts.map +1 -0
  37. package/dist/page-background/page-background.utils.js +11 -0
  38. package/dist/public.d.ts +4 -0
  39. package/dist/public.d.ts.map +1 -1
  40. package/dist/public.js +4 -0
  41. package/dist/top-bar/index.d.ts +2 -0
  42. package/dist/top-bar/index.d.ts.map +1 -0
  43. package/dist/top-bar/index.js +1 -0
  44. package/dist/top-bar/top-bar.component.d.ts +58 -0
  45. package/dist/top-bar/top-bar.component.d.ts.map +1 -0
  46. package/dist/top-bar/top-bar.component.js +124 -0
  47. package/package.json +13 -12
@@ -0,0 +1,751 @@
1
+ /** @module @category UI */ /**
2
+ * Fond animé WebGL de type "gradient wave" (portage du gradient historique
3
+ * Stripe/Vercel). Composant bas niveau utilisé par `page-background` pour
4
+ * habiller la page d'accueil par défaut ; peut aussi être utilisé seul.
5
+ *
6
+ * Zéro dépendance externe (pas de three.js) : un mini moteur WebGL maison
7
+ * (`MiniGl`) gère buffers, uniforms et shaders. Le canvas est créé et détruit
8
+ * manuellement dans `useEffect` pour garder l'animation fluide et éviter de
9
+ * la relancer à chaque re-render de React.
10
+ */ "use client";
11
+ function _define_property(obj, key, value) {
12
+ if (key in obj) {
13
+ Object.defineProperty(obj, key, {
14
+ value: value,
15
+ enumerable: true,
16
+ configurable: true,
17
+ writable: true
18
+ });
19
+ } else {
20
+ obj[key] = value;
21
+ }
22
+ return obj;
23
+ }
24
+ import { jsx as _jsx } from "react/jsx-runtime";
25
+ import React, { useEffect, useRef } from "react";
26
+ function normalizeColor(hexCode) {
27
+ return [
28
+ (hexCode >> 16 & 255) / 255,
29
+ (hexCode >> 8 & 255) / 255,
30
+ (255 & hexCode) / 255
31
+ ];
32
+ }
33
+ class MiniGl {
34
+ setSize(w = 640, h = 480) {
35
+ this.width = w;
36
+ this.height = h;
37
+ this.canvas.width = w;
38
+ this.canvas.height = h;
39
+ this.gl.viewport(0, 0, w, h);
40
+ this.commonUniforms.resolution.value = [
41
+ w,
42
+ h
43
+ ];
44
+ this.commonUniforms.aspectRatio.value = w / h;
45
+ }
46
+ setOrthographicCamera() {
47
+ this.commonUniforms.projectionMatrix.value = [
48
+ 2 / this.width,
49
+ 0,
50
+ 0,
51
+ 0,
52
+ 0,
53
+ 2 / this.height,
54
+ 0,
55
+ 0,
56
+ 0,
57
+ 0,
58
+ -0.001,
59
+ 0,
60
+ 0,
61
+ 0,
62
+ 0,
63
+ 1
64
+ ];
65
+ }
66
+ render() {
67
+ this.gl.clearColor(0, 0, 0, 0);
68
+ this.gl.clearDepth(1);
69
+ this.meshes.forEach((m)=>m.draw());
70
+ }
71
+ constructor(canvas){
72
+ _define_property(this, "canvas", void 0);
73
+ _define_property(this, "gl", void 0);
74
+ _define_property(this, "meshes", []);
75
+ _define_property(this, "commonUniforms", void 0);
76
+ _define_property(this, "width", void 0);
77
+ _define_property(this, "height", void 0);
78
+ _define_property(this, "Material", void 0);
79
+ _define_property(this, "Uniform", void 0);
80
+ _define_property(this, "PlaneGeometry", void 0);
81
+ _define_property(this, "Mesh", void 0);
82
+ _define_property(this, "Attribute", void 0);
83
+ this.canvas = canvas;
84
+ const gl = this.canvas.getContext("webgl", {
85
+ antialias: true
86
+ });
87
+ if (!gl) throw new Error("WebGL not supported");
88
+ this.gl = gl;
89
+ const context = this.gl;
90
+ const _miniGl = this;
91
+ this.Uniform = class {
92
+ update(location) {
93
+ if (this.value === undefined || location === null) return;
94
+ const isMatrix = this.typeFn.indexOf("Matrix") === 0;
95
+ const fn = `uniform${this.typeFn}`;
96
+ if (isMatrix) {
97
+ context[fn](location, this.transpose || false, this.value);
98
+ } else {
99
+ context[fn](location, this.value);
100
+ }
101
+ }
102
+ getDeclaration(name, type, length) {
103
+ if (this.excludeFrom === type) return "";
104
+ if (this.type === "array") {
105
+ return this.value[0].getDeclaration(name, type, this.value.length) + `\nconst int ${name}_length = ${this.value.length};`;
106
+ }
107
+ if (this.type === "struct") {
108
+ let nameNoPrefix = name.replace("u_", "");
109
+ nameNoPrefix = nameNoPrefix.charAt(0).toUpperCase() + nameNoPrefix.slice(1);
110
+ const fields = Object.entries(this.value).map(([n, u])=>u.getDeclaration(n, type).replace(/^uniform/, "")).join("");
111
+ return `uniform struct ${nameNoPrefix} \n{\n${fields}\n} ${name}${length ? `[${length}]` : ""};`;
112
+ }
113
+ return `uniform ${this.type} ${name}${length ? `[${length}]` : ""};`;
114
+ }
115
+ constructor(e){
116
+ _define_property(this, "type", "float");
117
+ _define_property(this, "value", void 0);
118
+ _define_property(this, "typeFn", void 0);
119
+ _define_property(this, "excludeFrom", void 0);
120
+ _define_property(this, "transpose", void 0);
121
+ Object.assign(this, e);
122
+ const typeMap = {
123
+ float: "1f",
124
+ int: "1i",
125
+ vec2: "2fv",
126
+ vec3: "3fv",
127
+ vec4: "4fv",
128
+ mat4: "Matrix4fv"
129
+ };
130
+ this.typeFn = typeMap[this.type] || "1f";
131
+ }
132
+ };
133
+ this.Attribute = class {
134
+ update() {
135
+ if (this.values) {
136
+ context.bindBuffer(this.target, this.buffer);
137
+ context.bufferData(this.target, this.values, context.STATIC_DRAW);
138
+ }
139
+ }
140
+ attach(e, t) {
141
+ const n = context.getAttribLocation(t, e);
142
+ if (this.target === context.ARRAY_BUFFER) {
143
+ context.bindBuffer(this.target, this.buffer);
144
+ context.enableVertexAttribArray(n);
145
+ context.vertexAttribPointer(n, this.size, this.type, this.normalized, 0, 0);
146
+ }
147
+ return n;
148
+ }
149
+ use(e) {
150
+ context.bindBuffer(this.target, this.buffer);
151
+ if (this.target === context.ARRAY_BUFFER) {
152
+ context.enableVertexAttribArray(e);
153
+ context.vertexAttribPointer(e, this.size, this.type, this.normalized, 0, 0);
154
+ }
155
+ }
156
+ constructor(e){
157
+ _define_property(this, "type", context.FLOAT);
158
+ _define_property(this, "normalized", false);
159
+ _define_property(this, "buffer", void 0);
160
+ _define_property(this, "target", void 0);
161
+ _define_property(this, "size", void 0);
162
+ _define_property(this, "values", void 0);
163
+ this.buffer = context.createBuffer();
164
+ Object.assign(this, e);
165
+ }
166
+ };
167
+ this.Material = class {
168
+ attachUniforms(name, uniforms) {
169
+ if (name === undefined) {
170
+ Object.entries(uniforms).forEach(([n, u])=>this.attachUniforms(n, u));
171
+ } else if (uniforms.type === "array") {
172
+ uniforms.value.forEach((u, i)=>this.attachUniforms(`${name}[${i}]`, u));
173
+ } else if (uniforms.type === "struct") {
174
+ Object.entries(uniforms.value).forEach(([u, i])=>this.attachUniforms(`${name}.${u}`, i));
175
+ } else {
176
+ this.uniformInstances.push({
177
+ uniform: uniforms,
178
+ location: context.getUniformLocation(this.program, name)
179
+ });
180
+ }
181
+ }
182
+ constructor(vertexShaders, fragments, uniforms = {}){
183
+ _define_property(this, "uniforms", void 0);
184
+ _define_property(this, "uniformInstances", []);
185
+ _define_property(this, "program", void 0);
186
+ const material = this;
187
+ function getShader(type, source) {
188
+ const shader = context.createShader(type);
189
+ context.shaderSource(shader, source);
190
+ context.compileShader(shader);
191
+ if (!context.getShaderParameter(shader, context.COMPILE_STATUS)) {
192
+ console.error(context.getShaderInfoLog(shader));
193
+ throw new Error("Shader compilation error");
194
+ }
195
+ return shader;
196
+ }
197
+ function getUniformDeclarations(uniforms, type) {
198
+ return Object.entries(uniforms).map(([uniform, value])=>value.getDeclaration(uniform, type)).join("\n");
199
+ }
200
+ material.uniforms = uniforms;
201
+ const prefix = "precision highp float;";
202
+ const vertexSource = `
203
+ ${prefix}
204
+ attribute vec4 position;
205
+ attribute vec2 uv;
206
+ attribute vec2 uvNorm;
207
+ ${getUniformDeclarations(_miniGl.commonUniforms, "vertex")}
208
+ ${getUniformDeclarations(uniforms, "vertex")}
209
+ ${vertexShaders}
210
+ `;
211
+ const fragmentSource = `
212
+ ${prefix}
213
+ ${getUniformDeclarations(_miniGl.commonUniforms, "fragment")}
214
+ ${getUniformDeclarations(uniforms, "fragment")}
215
+ ${fragments}
216
+ `;
217
+ material.program = context.createProgram();
218
+ context.attachShader(material.program, getShader(context.VERTEX_SHADER, vertexSource));
219
+ context.attachShader(material.program, getShader(context.FRAGMENT_SHADER, fragmentSource));
220
+ context.linkProgram(material.program);
221
+ if (!context.getProgramParameter(material.program, context.LINK_STATUS)) {
222
+ console.error(context.getProgramInfoLog(material.program));
223
+ throw new Error("Program linking error");
224
+ }
225
+ context.useProgram(material.program);
226
+ material.attachUniforms(undefined, _miniGl.commonUniforms);
227
+ material.attachUniforms(undefined, material.uniforms);
228
+ }
229
+ };
230
+ this.PlaneGeometry = class {
231
+ setTopology(xSegs = 1, ySegs = 1) {
232
+ this.xSegCount = xSegs;
233
+ this.ySegCount = ySegs;
234
+ this.vertexCount = (this.xSegCount + 1) * (this.ySegCount + 1);
235
+ const quadCount = this.xSegCount * this.ySegCount * 2;
236
+ this.attributes.uv.values = new Float32Array(2 * this.vertexCount);
237
+ this.attributes.uvNorm.values = new Float32Array(2 * this.vertexCount);
238
+ this.attributes.index.values = new Uint16Array(3 * quadCount);
239
+ for(let y = 0; y <= this.ySegCount; y++){
240
+ for(let x = 0; x <= this.xSegCount; x++){
241
+ const i = y * (this.xSegCount + 1) + x;
242
+ this.attributes.uv.values[2 * i] = x / this.xSegCount;
243
+ this.attributes.uv.values[2 * i + 1] = 1 - y / this.ySegCount;
244
+ this.attributes.uvNorm.values[2 * i] = x / this.xSegCount * 2 - 1;
245
+ this.attributes.uvNorm.values[2 * i + 1] = 1 - y / this.ySegCount * 2;
246
+ if (x < this.xSegCount && y < this.ySegCount) {
247
+ const s = y * this.xSegCount + x;
248
+ this.attributes.index.values[6 * s] = i;
249
+ this.attributes.index.values[6 * s + 1] = i + 1 + this.xSegCount;
250
+ this.attributes.index.values[6 * s + 2] = i + 1;
251
+ this.attributes.index.values[6 * s + 3] = i + 1;
252
+ this.attributes.index.values[6 * s + 4] = i + 1 + this.xSegCount;
253
+ this.attributes.index.values[6 * s + 5] = i + 2 + this.xSegCount;
254
+ }
255
+ }
256
+ }
257
+ this.attributes.uv.update();
258
+ this.attributes.uvNorm.update();
259
+ this.attributes.index.update();
260
+ }
261
+ setSize(width = 1, height = 1) {
262
+ this.width = width;
263
+ this.height = height;
264
+ this.attributes.position.values = new Float32Array(3 * this.vertexCount);
265
+ const offsetX = width / -2;
266
+ const offsetY = height / -2;
267
+ const segWidth = width / this.xSegCount;
268
+ const segHeight = height / this.ySegCount;
269
+ for(let y = 0; y <= this.ySegCount; y++){
270
+ const posY = offsetY + y * segHeight;
271
+ for(let x = 0; x <= this.xSegCount; x++){
272
+ const posX = offsetX + x * segWidth;
273
+ const idx = y * (this.xSegCount + 1) + x;
274
+ this.attributes.position.values[3 * idx] = posX;
275
+ this.attributes.position.values[3 * idx + 1] = -posY;
276
+ this.attributes.position.values[3 * idx + 2] = 0;
277
+ }
278
+ }
279
+ this.attributes.position.update();
280
+ }
281
+ constructor(){
282
+ _define_property(this, "width", 1);
283
+ _define_property(this, "height", 1);
284
+ _define_property(this, "attributes", void 0);
285
+ _define_property(this, "vertexCount", 0);
286
+ _define_property(this, "xSegCount", 0);
287
+ _define_property(this, "ySegCount", 0);
288
+ this.attributes = {
289
+ position: new _miniGl.Attribute({
290
+ target: context.ARRAY_BUFFER,
291
+ size: 3
292
+ }),
293
+ uv: new _miniGl.Attribute({
294
+ target: context.ARRAY_BUFFER,
295
+ size: 2
296
+ }),
297
+ uvNorm: new _miniGl.Attribute({
298
+ target: context.ARRAY_BUFFER,
299
+ size: 2
300
+ }),
301
+ index: new _miniGl.Attribute({
302
+ target: context.ELEMENT_ARRAY_BUFFER,
303
+ size: 3,
304
+ type: context.UNSIGNED_SHORT
305
+ })
306
+ };
307
+ }
308
+ };
309
+ this.Mesh = class {
310
+ draw() {
311
+ context.useProgram(this.material.program);
312
+ this.material.uniformInstances.forEach(({ uniform, location })=>uniform.update(location));
313
+ this.attributeInstances.forEach(({ attribute, location })=>attribute.use(location));
314
+ context.drawElements(context.TRIANGLES, this.geometry.attributes.index.values.length, context.UNSIGNED_SHORT, 0);
315
+ }
316
+ constructor(geometry, material){
317
+ _define_property(this, "geometry", void 0);
318
+ _define_property(this, "material", void 0);
319
+ _define_property(this, "attributeInstances", []);
320
+ this.geometry = geometry;
321
+ this.material = material;
322
+ Object.entries(this.geometry.attributes).forEach(([e, attribute])=>{
323
+ this.attributeInstances.push({
324
+ attribute: attribute,
325
+ location: attribute.attach(e, this.material.program)
326
+ });
327
+ });
328
+ _miniGl.meshes.push(this);
329
+ }
330
+ };
331
+ const identityMatrix = [
332
+ 1,
333
+ 0,
334
+ 0,
335
+ 0,
336
+ 0,
337
+ 1,
338
+ 0,
339
+ 0,
340
+ 0,
341
+ 0,
342
+ 1,
343
+ 0,
344
+ 0,
345
+ 0,
346
+ 0,
347
+ 1
348
+ ];
349
+ this.commonUniforms = {
350
+ projectionMatrix: new this.Uniform({
351
+ type: "mat4",
352
+ value: identityMatrix
353
+ }),
354
+ modelViewMatrix: new this.Uniform({
355
+ type: "mat4",
356
+ value: identityMatrix
357
+ }),
358
+ resolution: new this.Uniform({
359
+ type: "vec2",
360
+ value: [
361
+ 1,
362
+ 1
363
+ ]
364
+ }),
365
+ aspectRatio: new this.Uniform({
366
+ type: "float",
367
+ value: 1
368
+ })
369
+ };
370
+ }
371
+ }
372
+ class Gradient {
373
+ init() {
374
+ const sectionColors = this.colors.map((hex)=>normalizeColor(parseInt(hex.replace("#", "0x"), 16)));
375
+ const uniforms = {
376
+ u_time: new this.minigl.Uniform({
377
+ value: 0
378
+ }),
379
+ u_shadow_power: new this.minigl.Uniform({
380
+ value: 5
381
+ }),
382
+ u_darken_top: new this.minigl.Uniform({
383
+ value: 0
384
+ }),
385
+ u_active_colors: new this.minigl.Uniform({
386
+ value: [
387
+ 1,
388
+ 1,
389
+ 1,
390
+ 1
391
+ ],
392
+ type: "vec4"
393
+ }),
394
+ u_global: new this.minigl.Uniform({
395
+ value: {
396
+ noiseFreq: new this.minigl.Uniform({
397
+ value: [
398
+ 0.00014,
399
+ 0.00029
400
+ ],
401
+ type: "vec2"
402
+ }),
403
+ noiseSpeed: new this.minigl.Uniform({
404
+ value: 0.000005
405
+ })
406
+ },
407
+ type: "struct"
408
+ }),
409
+ u_vertDeform: new this.minigl.Uniform({
410
+ value: {
411
+ incline: new this.minigl.Uniform({
412
+ value: 0
413
+ }),
414
+ offsetTop: new this.minigl.Uniform({
415
+ value: -0.5
416
+ }),
417
+ offsetBottom: new this.minigl.Uniform({
418
+ value: -0.5
419
+ }),
420
+ noiseFreq: new this.minigl.Uniform({
421
+ value: [
422
+ 3,
423
+ 4
424
+ ],
425
+ type: "vec2"
426
+ }),
427
+ noiseAmp: new this.minigl.Uniform({
428
+ value: 320
429
+ }),
430
+ noiseSpeed: new this.minigl.Uniform({
431
+ value: 10
432
+ }),
433
+ noiseFlow: new this.minigl.Uniform({
434
+ value: 3
435
+ }),
436
+ noiseSeed: new this.minigl.Uniform({
437
+ value: 5
438
+ })
439
+ },
440
+ type: "struct",
441
+ excludeFrom: "fragment"
442
+ }),
443
+ u_baseColor: new this.minigl.Uniform({
444
+ value: sectionColors[0],
445
+ type: "vec3",
446
+ excludeFrom: "fragment"
447
+ }),
448
+ u_waveLayers: new this.minigl.Uniform({
449
+ value: [],
450
+ excludeFrom: "fragment",
451
+ type: "array"
452
+ })
453
+ };
454
+ for(let i = 1; i < sectionColors.length; i++){
455
+ uniforms.u_waveLayers.value.push(new this.minigl.Uniform({
456
+ value: {
457
+ color: new this.minigl.Uniform({
458
+ value: sectionColors[i],
459
+ type: "vec3"
460
+ }),
461
+ noiseFreq: new this.minigl.Uniform({
462
+ value: [
463
+ 2 + i / sectionColors.length,
464
+ 3 + i / sectionColors.length
465
+ ],
466
+ type: "vec2"
467
+ }),
468
+ noiseSpeed: new this.minigl.Uniform({
469
+ value: 11 + 0.3 * i
470
+ }),
471
+ noiseFlow: new this.minigl.Uniform({
472
+ value: 6.5 + 0.3 * i
473
+ }),
474
+ noiseSeed: new this.minigl.Uniform({
475
+ value: 5 + 10 * i
476
+ }),
477
+ noiseFloor: new this.minigl.Uniform({
478
+ value: 0.1
479
+ }),
480
+ noiseCeil: new this.minigl.Uniform({
481
+ value: 0.63 + 0.07 * i
482
+ })
483
+ },
484
+ type: "struct"
485
+ }));
486
+ }
487
+ const vertexShader = `
488
+ vec3 mod289(vec3 x) { return x - floor(x * (1.0 / 289.0)) * 289.0; }
489
+ vec4 mod289(vec4 x) { return x - floor(x * (1.0 / 289.0)) * 289.0; }
490
+ vec4 permute(vec4 x) { return mod289(((x*34.0)+1.0)*x); }
491
+ vec4 taylorInvSqrt(vec4 r) { return 1.79284291400159 - 0.85373472095314 * r; }
492
+
493
+ float snoise(vec3 v) {
494
+ const vec2 C = vec2(1.0/6.0, 1.0/3.0);
495
+ const vec4 D = vec4(0.0, 0.5, 1.0, 2.0);
496
+ vec3 i = floor(v + dot(v, C.yyy));
497
+ vec3 x0 = v - i + dot(i, C.xxx);
498
+ vec3 g = step(x0.yzx, x0.xyz);
499
+ vec3 l = 1.0 - g;
500
+ vec3 i1 = min(g.xyz, l.zxy);
501
+ vec3 i2 = max(g.xyz, l.zxy);
502
+ vec3 x1 = x0 - i1 + C.xxx;
503
+ vec3 x2 = x0 - i2 + C.yyy;
504
+ vec3 x3 = x0 - D.yyy;
505
+ i = mod289(i);
506
+ vec4 p = permute(permute(permute(i.z + vec4(0.0, i1.z, i2.z, 1.0)) + i.y + vec4(0.0, i1.y, i2.y, 1.0)) + i.x + vec4(0.0, i1.x, i2.x, 1.0));
507
+ float n_ = 0.142857142857;
508
+ vec3 ns = n_ * D.wyz - D.xzx;
509
+ vec4 j = p - 49.0 * floor(p * ns.z * ns.z);
510
+ vec4 x_ = floor(j * ns.z);
511
+ vec4 y_ = floor(j - 7.0 * x_);
512
+ vec4 x = x_ *ns.x + ns.yyyy;
513
+ vec4 y = y_ *ns.x + ns.yyyy;
514
+ vec4 h = 1.0 - abs(x) - abs(y);
515
+ vec4 b0 = vec4(x.xy, y.xy);
516
+ vec4 b1 = vec4(x.zw, y.zw);
517
+ vec4 s0 = floor(b0)*2.0 + 1.0;
518
+ vec4 s1 = floor(b1)*2.0 + 1.0;
519
+ vec4 sh = -step(h, vec4(0.0));
520
+ vec4 a0 = b0.xzyw + s0.xzyw*sh.xxyy;
521
+ vec4 a1 = b1.xzyw + s1.xzyw*sh.zzww;
522
+ vec3 p0 = vec3(a0.xy,h.x);
523
+ vec3 p1 = vec3(a0.zw,h.y);
524
+ vec3 p2 = vec3(a1.xy,h.z);
525
+ vec3 p3 = vec3(a1.zw,h.w);
526
+ vec4 norm = taylorInvSqrt(vec4(dot(p0,p0), dot(p1,p1), dot(p2, p2), dot(p3,p3)));
527
+ p0 *= norm.x; p1 *= norm.y; p2 *= norm.z; p3 *= norm.w;
528
+ vec4 m = max(0.6 - vec4(dot(x0,x0), dot(x1,x1), dot(x2,x2), dot(x3,x3)), 0.0);
529
+ m = m * m;
530
+ return 42.0 * dot(m*m, vec4(dot(p0,x0), dot(p1,x1), dot(p2,x2), dot(p3,x3)));
531
+ }
532
+
533
+ vec3 blendNormal(vec3 base, vec3 blend) { return blend; }
534
+ vec3 blendNormal(vec3 base, vec3 blend, float opacity) { return (blend * opacity + base * (1.0 - opacity)); }
535
+
536
+ varying vec3 v_color;
537
+
538
+ void main() {
539
+ float time = u_time * u_global.noiseSpeed;
540
+ vec2 noiseCoord = resolution * uvNorm * u_global.noiseFreq;
541
+ float tilt = resolution.y / 2.0 * uvNorm.y;
542
+ float incline = resolution.x * uvNorm.x / 2.0 * u_vertDeform.incline;
543
+ float offset = resolution.x / 2.0 * u_vertDeform.incline * mix(u_vertDeform.offsetBottom, u_vertDeform.offsetTop, uv.y);
544
+
545
+ float noise = snoise(vec3(
546
+ noiseCoord.x * u_vertDeform.noiseFreq.x + time * u_vertDeform.noiseFlow,
547
+ noiseCoord.y * u_vertDeform.noiseFreq.y,
548
+ time * u_vertDeform.noiseSpeed + u_vertDeform.noiseSeed
549
+ )) * u_vertDeform.noiseAmp;
550
+
551
+ noise *= 1.0 - pow(abs(uvNorm.y), 2.0);
552
+ noise = max(0.0, noise);
553
+
554
+ vec3 pos = vec3(position.x, position.y + tilt + incline + noise - offset, position.z);
555
+
556
+ v_color = u_baseColor;
557
+
558
+ for (int i = 0; i < u_waveLayers_length; i++) {
559
+ if (u_active_colors[i + 1] == 1.) {
560
+ WaveLayers layer = u_waveLayers[i];
561
+ float layerNoise = smoothstep(
562
+ layer.noiseFloor,
563
+ layer.noiseCeil,
564
+ snoise(vec3(
565
+ noiseCoord.x * layer.noiseFreq.x + time * layer.noiseFlow,
566
+ noiseCoord.y * layer.noiseFreq.y,
567
+ time * layer.noiseSpeed + layer.noiseSeed
568
+ )) / 2.0 + 0.5
569
+ );
570
+ v_color = blendNormal(v_color, layer.color, pow(layerNoise, 4.));
571
+ }
572
+ }
573
+
574
+ gl_Position = projectionMatrix * modelViewMatrix * vec4(pos, 1.0);
575
+ }`;
576
+ const fragmentShader = `
577
+ varying vec3 v_color;
578
+
579
+ void main() {
580
+ vec3 color = v_color;
581
+ if (u_darken_top == 1.0) {
582
+ vec2 st = gl_FragCoord.xy/resolution.xy;
583
+ color.g -= pow(st.y + sin(-12.0) * st.x, u_shadow_power) * 0.4;
584
+ }
585
+ gl_FragColor = vec4(color, 1.0);
586
+ }`;
587
+ const material = new this.minigl.Material(vertexShader, fragmentShader, uniforms);
588
+ const geometry = new this.minigl.PlaneGeometry();
589
+ this.mesh = new this.minigl.Mesh(geometry, material);
590
+ this.resize();
591
+ // Bug corrigé : la version d'origine attachait ici une arrow function
592
+ // anonyme, différente de `this.handleResize` retirée dans destroy() —
593
+ // le listener n'était donc JAMAIS désinscrit (fuite mémoire à chaque
594
+ // montage/démontage du composant). On attache maintenant la même
595
+ // référence liée que celle utilisée par destroy().
596
+ window.addEventListener("resize", this.handleResize);
597
+ }
598
+ resize() {
599
+ const width = window.innerWidth;
600
+ const height = window.innerHeight;
601
+ this.minigl.setSize(width, height);
602
+ this.minigl.setOrthographicCamera();
603
+ const xSegCount = Math.ceil(width * 0.02);
604
+ const ySegCount = Math.ceil(height * 0.05);
605
+ this.mesh.geometry.setTopology(xSegCount, ySegCount);
606
+ this.mesh.geometry.setSize(width, height);
607
+ this.mesh.material.uniforms.u_shadow_power.value = width < 600 ? 5 : 6;
608
+ }
609
+ start() {
610
+ if (this.isPlaying) return;
611
+ this.isPlaying = true;
612
+ this.last = performance.now();
613
+ this.animationId = requestAnimationFrame(this.animate);
614
+ }
615
+ stop() {
616
+ this.isPlaying = false;
617
+ if (this.animationId) {
618
+ cancelAnimationFrame(this.animationId);
619
+ this.animationId = undefined;
620
+ }
621
+ }
622
+ destroy() {
623
+ this.stop();
624
+ window.removeEventListener("resize", this.handleResize);
625
+ }
626
+ constructor(canvas, colors){
627
+ _define_property(this, "canvas", void 0);
628
+ _define_property(this, "colors", void 0);
629
+ _define_property(this, "minigl", void 0);
630
+ _define_property(this, "mesh", void 0);
631
+ _define_property(this, "time", 0);
632
+ _define_property(this, "last", 0);
633
+ _define_property(this, "animationId", void 0);
634
+ _define_property(this, "isPlaying", false);
635
+ _define_property(this, "animate", (timestamp)=>{
636
+ if (!this.isPlaying) return;
637
+ if (!this.last) {
638
+ this.last = timestamp;
639
+ }
640
+ const delta = timestamp - this.last;
641
+ this.last = timestamp;
642
+ this.time += Math.min(delta, 1000 / 15);
643
+ this.mesh.material.uniforms.u_time.value = this.time;
644
+ this.minigl.render();
645
+ this.animationId = requestAnimationFrame(this.animate);
646
+ });
647
+ _define_property(this, "handleResize", ()=>{
648
+ this.resize();
649
+ });
650
+ this.canvas = canvas;
651
+ this.colors = colors;
652
+ this.minigl = new MiniGl(canvas);
653
+ this.init();
654
+ }
655
+ }
656
+ export function GradientWave({ colors = [
657
+ "#008080",
658
+ "#0b192c",
659
+ "#0ea5e9",
660
+ "#042f2e",
661
+ "#0284c7",
662
+ "#064e3b"
663
+ ], isPlaying = true, className = "", shadowPower = 8, darkenTop = false, noiseSpeed = 0.00001, noiseFrequency = [
664
+ 0.0001,
665
+ 0.0009
666
+ ], deform = {
667
+ incline: 0.5,
668
+ noiseAmp: 250,
669
+ noiseFlow: 5
670
+ } }) {
671
+ const containerRef = useRef(null);
672
+ const gradientRef = useRef(null);
673
+ // Mount canvas and gradient ONCE to keep animation running smoothly forever
674
+ useEffect(()=>{
675
+ if (!containerRef.current) return;
676
+ const canvas = document.createElement("canvas");
677
+ Object.assign(canvas.style, {
678
+ position: "absolute",
679
+ top: "0",
680
+ left: "0",
681
+ width: "100%",
682
+ height: "100%",
683
+ display: "block"
684
+ });
685
+ containerRef.current.appendChild(canvas);
686
+ try {
687
+ const gradient = new Gradient(canvas, colors);
688
+ gradientRef.current = gradient;
689
+ gradient.mesh.material.uniforms.u_shadow_power.value = shadowPower;
690
+ gradient.mesh.material.uniforms.u_darken_top.value = darkenTop ? 1 : 0;
691
+ gradient.mesh.material.uniforms.u_global.value.noiseFreq.value = noiseFrequency;
692
+ gradient.mesh.material.uniforms.u_global.value.noiseSpeed.value = noiseSpeed;
693
+ Object.assign(gradient.mesh.material.uniforms.u_vertDeform.value, {
694
+ ...gradient.mesh.material.uniforms.u_vertDeform.value,
695
+ ...deform
696
+ });
697
+ if (isPlaying) {
698
+ gradient.start();
699
+ }
700
+ } catch (error) {
701
+ console.error("Failed to initialize gradient:", error);
702
+ }
703
+ return ()=>{
704
+ if (gradientRef.current) {
705
+ gradientRef.current.destroy();
706
+ gradientRef.current = null;
707
+ }
708
+ if (canvas.parentNode) {
709
+ canvas.parentNode.removeChild(canvas);
710
+ }
711
+ };
712
+ }, []); // Run only on mount
713
+ // Sync isPlaying state without rebuilding WebGL
714
+ useEffect(()=>{
715
+ if (!gradientRef.current) return;
716
+ if (isPlaying) {
717
+ gradientRef.current.start();
718
+ } else {
719
+ gradientRef.current.stop();
720
+ }
721
+ }, [
722
+ isPlaying
723
+ ]);
724
+ return /*#__PURE__*/ _jsx("div", {
725
+ ref: containerRef,
726
+ className: `absolute inset-0 z-0 w-full h-full overflow-hidden ${className}`
727
+ });
728
+ } /* ============================================================================
729
+ * GUIDE D'UTILISATION — GradientWave
730
+ * ============================================================================
731
+ * <GradientWave /> pose un canvas WebGL en `absolute inset-0` : le parent
732
+ * DOIT être positionné (`relative`/`fixed`/`absolute`) et avoir une taille
733
+ * définie, sinon le fond n'occupe aucun espace visible.
734
+ *
735
+ * <div className="relative h-64 w-full overflow-hidden">
736
+ * <GradientWave colors={['#4f46e5', '#0ea5e9', '#064e3b']} />
737
+ * </div>
738
+ *
739
+ * - `colors` : dégradé de base + couches de vagues (1 couleur = fond uni
740
+ * animé, 2+ = vagues superposées).
741
+ * - `isPlaying` : seule prop réactive après montage (start()/stop() sans
742
+ * reconstruire le contexte WebGL) — toutes les autres props ne sont
743
+ * lues qu'AU MONTAGE. Pour changer `colors`/`deform`/`shadowPower` à
744
+ * chaud, démonter/remonter via une prop `key` qui change.
745
+ * - Le composant crée/détruit son propre `<canvas>` en `useEffect` et
746
+ * nettoie proprement listener resize + frame d'animation au démontage
747
+ * (bug corrigé lors du portage : le listener resize d'origine n'était
748
+ * jamais désinscrit, cf. commentaire sur `handleResize` plus haut).
749
+ * - Coûteux en GPU/CPU : éviter d'en monter plusieurs instances en même
750
+ * temps sur une même page.
751
+ * ==========================================================================*/