@tsogtoodev/shingen-metal 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/LICENSE +21 -0
- package/README.md +164 -0
- package/dist/index.cjs.js +421 -0
- package/dist/index.d.ts +321 -0
- package/dist/index.es.js +1605 -0
- package/package.json +60 -0
|
@@ -0,0 +1,421 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const w=require("vue");function qe(e){let t=e.replace("#","");return t.length===3&&(t=t[0]+t[0]+t[1]+t[1]+t[2]+t[2]),[parseInt(t.slice(0,2),16)/255,parseInt(t.slice(2,4),16)/255,parseInt(t.slice(4,6),16)/255]}function ht(e,t,a){e/=255,t/=255,a/=255;const n=Math.max(e,t,a),o=Math.min(e,t,a),r=n-o;let s=0;const c=n===0?0:r/n;return r!==0&&(n===e?s=((t-a)/r+6)%6:n===t?s=(a-e)/r+2:s=(e-t)/r+4,s/=6),[s,c,n]}function pt(e,t,a){const n=Math.floor(e*6),o=e*6-n,r=a*(1-t),s=a*(1-o*t),c=a*(1-(1-o)*t);let l=0,d=0,f=0;switch(n%6){case 0:l=a,d=c,f=r;break;case 1:l=s,d=a,f=r;break;case 2:l=r,d=a,f=c;break;case 3:l=r,d=s,f=a;break;case 4:l=c,d=r,f=a;break;case 5:l=a,d=r,f=s;break}return[Math.round(l*255),Math.round(d*255),Math.round(f*255)]}const mt=66,gt=66,xt=1500,vt=1,Te=16,bt=16,wt=8,yt=96,_t=2,Mt={name:"chromatic",modes:{dark:{colors:["#000000","#aae8ff","#c5fe9e","#f7888d","#0d0d0d","#fffdc3","#007cff"],alphas:[1,1,1,1,1,1,1],direction:80,speed:1.2,intensity:2,scale:1.6,softness:.18,distortion:.3,complexity:.68,shape:1,blur:1,vignette:.26,vigOpacity:.6,shaderOpacity:1},light:{colors:["#ffffff","#ffffff","#ffffff","#ffb3b3","#adadad","#f5ff70","#007cff"],alphas:[1,1,1,1,1,1,1],direction:80,speed:1.2,intensity:2,scale:2.5,softness:.18,distortion:.3,complexity:.68,shape:1,blur:1,vignette:.24,vigOpacity:.16,shaderOpacity:1}}},St={name:"silver",modes:{dark:{colors:["#000000","#dedede","#747270","#e5e5e5","#0d0d0d","#ffffff","#e6e6e6"],alphas:[1,1,1,1,1,1,1],direction:80,speed:1.2,intensity:2,scale:2.5,softness:.18,distortion:.3,complexity:.68,shape:1,blur:1,vignette:.26,vigOpacity:.6,shaderOpacity:.88},light:{colors:["#f6f6f6","#ffffff","#ffffff","#f7f7f7","#c9c9c9","#d0d0d0","#d1d1d1"],alphas:[1,1,1,1,1,1,1],direction:80,speed:1.2,intensity:2,scale:2.5,softness:.18,distortion:.3,complexity:.68,shape:1,blur:1,vignette:.2,vigOpacity:.26,shaderOpacity:1}}},Rt={name:"gold",modes:{dark:{colors:["#000000","#ffffff","#ffffff","#f7d488","#0d0d0d","#fffdc3","#ffffff"],alphas:[1,1,1,1,1,1,1],direction:80,speed:1,intensity:2,scale:2.5,softness:.18,distortion:.3,complexity:.68,shape:1,blur:1,vignette:.26,vigOpacity:.6,shaderOpacity:.92},light:{colors:["#fff8e1","#fffbe0","#ffffff","#fff6d6","#d2c7a7","#dcd2bc","#f9f7e5"],alphas:[1,1,1,1,1,1,1],direction:80,speed:1.2,intensity:2,scale:2.5,softness:.18,distortion:.3,complexity:.68,shape:1,blur:1,vignette:.22,vigOpacity:.24,shaderOpacity:1}}},ve={chromatic:Mt,silver:St,gold:Rt},Tt=`
|
|
2
|
+
attribute vec2 a_position;
|
|
3
|
+
void main() { gl_Position = vec4(a_position, 0.0, 1.0); }
|
|
4
|
+
`,At=`
|
|
5
|
+
precision highp float;
|
|
6
|
+
|
|
7
|
+
uniform vec2 u_resolution;
|
|
8
|
+
uniform float u_time;
|
|
9
|
+
uniform vec3 u_color1, u_color2, u_color3, u_color4, u_color5, u_color6, u_color7;
|
|
10
|
+
uniform float u_alpha1, u_alpha2, u_alpha3, u_alpha4, u_alpha5, u_alpha6, u_alpha7;
|
|
11
|
+
uniform float u_intensity, u_scale, u_direction;
|
|
12
|
+
uniform float u_softness, u_distortion, u_complexity, u_shape;
|
|
13
|
+
uniform float u_vignette, u_vigOpacity, u_blur, u_shaderOpacity;
|
|
14
|
+
|
|
15
|
+
vec3 mod289(vec3 x) { return x - floor(x * (1.0 / 289.0)) * 289.0; }
|
|
16
|
+
vec2 mod289v2(vec2 x) { return x - floor(x * (1.0 / 289.0)) * 289.0; }
|
|
17
|
+
vec3 permute(vec3 x) { return mod289((x * 34.0 + 1.0) * x); }
|
|
18
|
+
|
|
19
|
+
float snoise(vec2 v) {
|
|
20
|
+
const vec4 C = vec4(0.211324865405187, 0.366025403784439,
|
|
21
|
+
-0.577350269189626, 0.024390243902439);
|
|
22
|
+
vec2 i = floor(v + dot(v, C.yy));
|
|
23
|
+
vec2 x0 = v - i + dot(i, C.xx);
|
|
24
|
+
vec2 i1 = (x0.x > x0.y) ? vec2(1.0, 0.0) : vec2(0.0, 1.0);
|
|
25
|
+
vec4 x12 = x0.xyxy + C.xxzz;
|
|
26
|
+
x12.xy -= i1;
|
|
27
|
+
i = mod289v2(i);
|
|
28
|
+
vec3 p = permute(permute(i.y + vec3(0.0, i1.y, 1.0)) + i.x + vec3(0.0, i1.x, 1.0));
|
|
29
|
+
vec3 m = max(0.5 - vec3(dot(x0, x0), dot(x12.xy, x12.xy), dot(x12.zw, x12.zw)), 0.0);
|
|
30
|
+
m = m * m; m = m * m;
|
|
31
|
+
vec3 x_ = 2.0 * fract(p * C.www) - 1.0;
|
|
32
|
+
vec3 h = abs(x_) - 0.5;
|
|
33
|
+
vec3 ox = floor(x_ + 0.5);
|
|
34
|
+
vec3 a0 = x_ - ox;
|
|
35
|
+
m *= 1.79284291400159 - 0.85373472095314 * (a0 * a0 + h * h);
|
|
36
|
+
vec3 g;
|
|
37
|
+
g.x = a0.x * x0.x + h.x * x0.y;
|
|
38
|
+
g.yz = a0.yz * x12.xz + h.yz * x12.yw;
|
|
39
|
+
return 130.0 * dot(m, g);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
float fbm(vec2 p, float oct) {
|
|
43
|
+
float val = 0.0, amp = 0.5;
|
|
44
|
+
int n = int(oct);
|
|
45
|
+
for (int i = 0; i < 7; i++) {
|
|
46
|
+
if (i >= n) break;
|
|
47
|
+
val += amp * snoise(p);
|
|
48
|
+
p *= 2.0;
|
|
49
|
+
amp *= 0.5;
|
|
50
|
+
}
|
|
51
|
+
return val;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
float nfbm(vec2 p) { return fbm(p, 3.0 + u_complexity * 4.0); }
|
|
55
|
+
|
|
56
|
+
/* 5-stop palette used by effect 1 (Plasma) — direct port of \`palette\` from
|
|
57
|
+
* the canonical engine. Stops at t = 0, 0.25, 0.5, 0.75, 1.0. */
|
|
58
|
+
vec3 palette(float t) {
|
|
59
|
+
t = clamp(t, 0.0, 1.0);
|
|
60
|
+
t = t * t * (3.0 - 2.0 * t);
|
|
61
|
+
float k = 64.0;
|
|
62
|
+
float w1 = u_alpha1 * exp(-k * t * t);
|
|
63
|
+
float w2 = u_alpha2 * exp(-k * (t - 0.25) * (t - 0.25));
|
|
64
|
+
float w3 = u_alpha3 * exp(-k * (t - 0.5) * (t - 0.5));
|
|
65
|
+
float w4 = u_alpha4 * exp(-k * (t - 0.75) * (t - 0.75));
|
|
66
|
+
float w5 = u_alpha5 * exp(-k * (t - 1.0) * (t - 1.0));
|
|
67
|
+
float total = w1 + w2 + w3 + w4 + w5 + 0.0001;
|
|
68
|
+
return (u_color1 * w1 + u_color2 * w2 + u_color3 * w3 +
|
|
69
|
+
u_color4 * w4 + u_color5 * w5) / total;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/* Per-pixel alpha that re-introduces transparency when the user dials any
|
|
73
|
+
* palette stop's alpha below 1. Same \`paletteAlpha\` from the canonical
|
|
74
|
+
* engine. With every preset shipping all-1 alphas, this returns ~1 for every
|
|
75
|
+
* pixel — but mirroring it keeps custom-preset behaviour identical. */
|
|
76
|
+
float paletteAlpha(float t) {
|
|
77
|
+
t = clamp(t, 0.0, 1.0);
|
|
78
|
+
t = t * t * (3.0 - 2.0 * t);
|
|
79
|
+
float k = 64.0;
|
|
80
|
+
float w1 = u_alpha1 * exp(-k * t * t);
|
|
81
|
+
float w2 = u_alpha2 * exp(-k * (t - 0.25) * (t - 0.25));
|
|
82
|
+
float w3 = u_alpha3 * exp(-k * (t - 0.5) * (t - 0.5));
|
|
83
|
+
float w4 = u_alpha4 * exp(-k * (t - 0.75) * (t - 0.75));
|
|
84
|
+
float w5 = u_alpha5 * exp(-k * (t - 1.0) * (t - 1.0));
|
|
85
|
+
float totalW = w1 + w2 + w3 + w4 + w5 + 0.0001;
|
|
86
|
+
float rawW = exp(-k * t * t)
|
|
87
|
+
+ exp(-k * (t - 0.25) * (t - 0.25))
|
|
88
|
+
+ exp(-k * (t - 0.5) * (t - 0.5))
|
|
89
|
+
+ exp(-k * (t - 0.75) * (t - 0.75))
|
|
90
|
+
+ exp(-k * (t - 1.0) * (t - 1.0))
|
|
91
|
+
+ 0.0001;
|
|
92
|
+
return totalW / rawW;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
vec2 warp(vec2 p, float t) {
|
|
96
|
+
float str = u_distortion * 2.0;
|
|
97
|
+
return vec2(
|
|
98
|
+
nfbm(p + vec2(t * 0.1, 0.0)),
|
|
99
|
+
nfbm(p + vec2(0.0, t * 0.12) + 5.0)
|
|
100
|
+
) * str;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/* Plasma: four sine bands warped by an FBM field, mapped through the
|
|
104
|
+
* 5-stop palette. Identical to effect 1 in the canonical engine. */
|
|
105
|
+
vec3 computeEffect(vec2 uv, float aspect, float t, float dist, float cpx) {
|
|
106
|
+
vec2 p = (uv - 0.5) * u_scale;
|
|
107
|
+
p.x *= aspect;
|
|
108
|
+
p += vec2(cos(u_direction), sin(u_direction)) * t * 0.15;
|
|
109
|
+
|
|
110
|
+
float freq = 3.0 + cpx * 8.0;
|
|
111
|
+
float val = 0.0;
|
|
112
|
+
val += sin(p.x * freq + t);
|
|
113
|
+
val += sin(p.y * freq + t * 1.3);
|
|
114
|
+
val += sin((p.x + p.y) * freq * 0.7 + t * 0.7);
|
|
115
|
+
val += sin(length(p) * freq * 0.8 - t * 1.5);
|
|
116
|
+
vec2 w = warp(p, t);
|
|
117
|
+
val += (w.x + w.y) * dist;
|
|
118
|
+
val = val * 0.2 * u_intensity + 0.5;
|
|
119
|
+
|
|
120
|
+
return palette(clamp(val, 0.0, 1.0));
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
void main() {
|
|
124
|
+
vec2 uv = gl_FragCoord.xy / u_resolution;
|
|
125
|
+
float aspect = u_resolution.x / u_resolution.y;
|
|
126
|
+
float t = u_time; // JS already multiplied u_time by preset.speed.
|
|
127
|
+
float dist = u_distortion;
|
|
128
|
+
float cpx = u_complexity;
|
|
129
|
+
|
|
130
|
+
/* 5-tap cross blur (center + cardinal offsets). The chromatic/silver/gold
|
|
131
|
+
* presets all ship with blur=1 so this path is always active. 5 taps
|
|
132
|
+
* instead of the canonical engine's 9 saves ~44% fragment work; the
|
|
133
|
+
* perceptual difference is nil because the output is already soft from
|
|
134
|
+
* the plasma's low spatial frequency and CSS blur on reflections. */
|
|
135
|
+
vec3 col;
|
|
136
|
+
if (u_blur < 0.01) {
|
|
137
|
+
col = computeEffect(uv, aspect, t, dist, cpx);
|
|
138
|
+
} else {
|
|
139
|
+
float r = u_blur * 0.02;
|
|
140
|
+
col = computeEffect(uv, aspect, t, dist, cpx) * 0.4;
|
|
141
|
+
col += computeEffect(uv + vec2( r, 0.0), aspect, t, dist, cpx) * 0.15;
|
|
142
|
+
col += computeEffect(uv + vec2(-r, 0.0), aspect, t, dist, cpx) * 0.15;
|
|
143
|
+
col += computeEffect(uv + vec2(0.0, r), aspect, t, dist, cpx) * 0.15;
|
|
144
|
+
col += computeEffect(uv + vec2(0.0, -r), aspect, t, dist, cpx) * 0.15;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/* Gamma punch — adds the contrast pop that defines the chromatic
|
|
148
|
+
* highlights. From the canonical engine: \`col = pow(col, vec3(1.3))\`. */
|
|
149
|
+
col = pow(col, vec3(1.3));
|
|
150
|
+
|
|
151
|
+
/* Vignette — soft edge darkening so corners read as recessed. The 40-px
|
|
152
|
+
* scale at the bottom of the formula is hard-coded in the canonical
|
|
153
|
+
* engine; we keep it for visual parity. */
|
|
154
|
+
float edgeDist = min(min(uv.x, 1.0 - uv.x), min(uv.y, 1.0 - uv.y));
|
|
155
|
+
float vigPx = 40.0 / min(u_resolution.x, u_resolution.y);
|
|
156
|
+
float vigRange = vigPx * (1.0 + u_vignette * 3.0);
|
|
157
|
+
float vig = edgeDist * edgeDist / (vigRange * vigRange);
|
|
158
|
+
vig = smoothstep(0.0, 1.0, vig);
|
|
159
|
+
col *= mix(1.0, vig, u_vignette * u_vigOpacity);
|
|
160
|
+
|
|
161
|
+
/* Per-pixel alpha. With all-1 alphas the formula collapses to ~1 but the
|
|
162
|
+
* computation matches the canonical engine so custom presets behave the
|
|
163
|
+
* same. */
|
|
164
|
+
float colorAlpha = (u_alpha1 + u_alpha2 + u_alpha3 + u_alpha4 + u_alpha5) / 5.0;
|
|
165
|
+
if (colorAlpha < 0.999) {
|
|
166
|
+
vec3 c1d = col - u_color1, c2d = col - u_color2, c3d = col - u_color3,
|
|
167
|
+
c4d = col - u_color4, c5d = col - u_color5;
|
|
168
|
+
float prox1 = exp(-8.0 * dot(c1d, c1d));
|
|
169
|
+
float prox2 = exp(-8.0 * dot(c2d, c2d));
|
|
170
|
+
float prox3 = exp(-8.0 * dot(c3d, c3d));
|
|
171
|
+
float prox4 = exp(-8.0 * dot(c4d, c4d));
|
|
172
|
+
float prox5 = exp(-8.0 * dot(c5d, c5d));
|
|
173
|
+
float pTotal = prox1 + prox2 + prox3 + prox4 + prox5 + 0.0001;
|
|
174
|
+
colorAlpha = (prox1 * u_alpha1 + prox2 * u_alpha2 + prox3 * u_alpha3 +
|
|
175
|
+
prox4 * u_alpha4 + prox5 * u_alpha5) / pTotal;
|
|
176
|
+
}
|
|
177
|
+
float alpha = colorAlpha;
|
|
178
|
+
|
|
179
|
+
/* Touch the unused-at-effect-1 uniforms so GL drivers that complain about
|
|
180
|
+
* declared-but-unread uniforms (some Mali / Adreno builds do) keep them
|
|
181
|
+
* live. The contribution is provably zero. */
|
|
182
|
+
alpha += 0.0 * (u_softness + u_shape +
|
|
183
|
+
u_alpha6 + u_alpha7 +
|
|
184
|
+
u_color6.x + u_color7.x);
|
|
185
|
+
|
|
186
|
+
gl_FragColor = vec4(col, alpha * u_shaderOpacity);
|
|
187
|
+
}
|
|
188
|
+
`;function Ae(e,t,a){const n=e.createShader(t);if(!n)throw new Error("metal-fx: gl.createShader returned null");if(e.shaderSource(n,a),e.compileShader(n),!e.getShaderParameter(n,e.COMPILE_STATUS)){const o=e.getShaderInfoLog(n);throw e.deleteShader(n),new Error(`metal-fx: shader compile failed: ${o??"(no info log)"}`)}return n}function Ct(e,t,a){const n=e.createProgram();if(!n)throw new Error("metal-fx: gl.createProgram returned null");if(e.attachShader(n,t),e.attachShader(n,a),e.linkProgram(n),!e.getProgramParameter(n,e.LINK_STATUS)){const o=e.getProgramInfoLog(n);throw e.deleteProgram(n),new Error(`metal-fx: program link failed: ${o??"(no info log)"}`)}return n}const Ye=140,je=40,Ke=1.6,Qe=1.3;let i=null,te=null;function kt(e){te=e}const Et=["u_resolution","u_time","u_color1","u_color2","u_color3","u_color4","u_color5","u_color6","u_color7","u_alpha1","u_alpha2","u_alpha3","u_alpha4","u_alpha5","u_alpha6","u_alpha7","u_intensity","u_scale","u_direction","u_softness","u_distortion","u_complexity","u_shape","u_vignette","u_vigOpacity","u_blur","u_shaderOpacity"];function Ce(e){e.enable(e.BLEND),e.blendFunc(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA);const t=Ae(e,e.VERTEX_SHADER,Tt),a=Ae(e,e.FRAGMENT_SHADER,At),n=Ct(e,t,a);e.useProgram(n);const o=e.createBuffer();if(!o)throw new Error("metal-fx: gl.createBuffer returned null");e.bindBuffer(e.ARRAY_BUFFER,o),e.bufferData(e.ARRAY_BUFFER,new Float32Array([-1,-1,1,-1,-1,1,-1,1,1,-1,1,1]),e.STATIC_DRAW);const r=e.getAttribLocation(n,"a_position");e.enableVertexAttribArray(r),e.vertexAttribPointer(r,2,e.FLOAT,!1,0,0);const s={};for(const c of Et)s[c]=e.getUniformLocation(n,c);return{program:n,buffer:o,uniforms:s}}function Je(){if(i)return i;const e=Math.min(_t,typeof window<"u"&&window.devicePixelRatio||1),t=Math.round(yt*e),a=typeof OffscreenCanvas<"u";let n,o;if(a)n=new OffscreenCanvas(t,t),o=n.getContext("webgl",{alpha:!0,premultipliedAlpha:!1,antialias:!1});else{const f=document.createElement("canvas");f.width=t,f.height=t,o=f.getContext("webgl",{alpha:!0,premultipliedAlpha:!1,antialias:!1,preserveDrawingBuffer:!0})??f.getContext("experimental-webgl"),n=f}if(!o)throw new Error("metal-fx: WebGL not supported");const{program:r,buffer:s,uniforms:c}=Ce(o),l=f=>{f.preventDefault(),i&&(i.contextLost=!0)},d=()=>{if(!i)return;const f=Ce(i.gl);i.program=f.program,i.buffer=f.buffer,i.uniforms=f.uniforms,i.presetDirty=!0,i.contextLost=!1,te==null||te()};return n.addEventListener("webglcontextlost",l,!1),n.addEventListener("webglcontextrestored",d,!1),i={glCanvas:n,gl:o,program:r,buffer:s,uniforms:c,preset:ve.chromatic.modes.dark,presetDirty:!0,contextLost:!1,useOffscreen:a,frameBitmap:null,startMs:performance.now(),pausedMs:0,pausedAtMs:null,rafId:0,dpr:e,instances:new Set,frameCount:0,glowQueue:[],glowIdx:0,glowSkip:0,glowPixels:new Uint8Array(t*t*4),glowPixelsW:t,glowPixelsH:t},i}function It(){var o;if(!i)return;const{gl:e,program:t,buffer:a,frameBitmap:n}=i;try{n==null||n.close(),e.deleteBuffer(a),e.deleteProgram(t),(o=e.getExtension("WEBGL_lose_context"))==null||o.loseContext()}catch{}i=null}let ke=0;function oe(){if(!i)return;const e=performance.now();if(e-ke<xt)return;ke=e;const{gl:t,glCanvas:a}=i,n=a.width,o=a.height;(i.glowPixelsW!==n||i.glowPixelsH!==o)&&(i.glowPixelsW=n,i.glowPixelsH=o,i.glowPixels=new Uint8Array(n*o*4)),t.readPixels(0,0,n,o,t.RGBA,t.UNSIGNED_BYTE,i.glowPixels)}const X={bx:0,by:0};function be(e,t,a){if(!i)return X.bx=0,X.by=0,X;const{glCanvas:n}=i,o=n.width,r=n.height,s=e.dpr,c=e.cssWidth*s,l=e.cssHeight*s,d=Ye*s,f=je*s;let g=c*(o/d)/e.shaderScale,u=l*(r/f)/e.shaderScale;g>o&&(g=o),u>r&&(u=r);const p=(o-g)/2,h=(r-u)/2,m=p+t/e.cssWidth*g,A=h+a/e.cssHeight*u;return X.bx=Math.round(m),X.by=Math.round(r-1-A),X}const G={r:0,g:0,b:0,lum:0,count:0};function Ze(e,t,a,n,o,r){const s=Math.max(1,r|0),c=Math.max(0,n-s),l=Math.min(t,n+s+1),d=Math.max(0,o-s),f=Math.min(a,o+s+1);G.r=0,G.g=0,G.b=0,G.lum=0,G.count=0;for(let g=d;g<f;g++){const u=g*t;for(let p=c;p<l;p++){const h=(u+p)*4;G.r+=e[h],G.g+=e[h+1],G.b+=e[h+2],G.lum+=(.2126*e[h]+.7152*e[h+1]+.0722*e[h+2])/255,G.count++}}return G}const C={r:255,g:255,b:255};function Ee(e,t,a,n){if(!i)return 0;oe();const o=be(e,t,a),r=Ze(i.glowPixels,i.glowPixelsW,i.glowPixelsH,o.bx,o.by,n);return r.count>0?r.lum/r.count:0}function Ot(e,t,a,n){if(!i)return C.r=255,C.g=255,C.b=255,C;oe();const o=be(e,t,a),r=Ze(i.glowPixels,i.glowPixelsW,i.glowPixelsH,o.bx,o.by,n);return r.count===0?(C.r=255,C.g=255,C.b=255,C):(C.r=r.r/r.count,C.g=r.g/r.count,C.b=r.b/r.count,C)}function Lt(e,t,a,n){if(!i)return C.r=255,C.g=255,C.b=255,C;oe();const o=be(e,t,a),{glowPixels:r,glowPixelsW:s,glowPixelsH:c}=i,l=Math.max(1,n|0),d=Math.max(0,o.bx-l),f=Math.min(s,o.bx+l+1),g=Math.max(0,o.by-l),u=Math.min(c,o.by+l+1);let p=-1;C.r=255,C.g=255,C.b=255;for(let h=g;h<u;h++){const m=h*s;for(let A=d;A<f;A++){const x=(m+A)*4,I=r[x],S=r[x+1],L=r[x+2],F=Math.max(I,S,L),_=Math.min(I,S,L),R=(F>0?(F-_)/F:0)*(.35+.65*(F/255));R>p&&(p=R,C.r=I,C.g=S,C.b=L)}}return C}kt(()=>{i&&i.instances.size>0&&i.pausedAtMs===null&&K()});typeof document<"u"&&document.addEventListener("visibilitychange",()=>{!i||i.pausedAtMs!==null||i.contextLost||(document.hidden?we():i.instances.size>0&&K())});function et(e){const t=Je(),a=e.hostCanvas.getContext("2d",{alpha:!0});if(!a)throw new Error("metal-fx: canvas 2D context unavailable");const n=e.scale??1,o={canvas:e.hostCanvas,ctx:a,cssWidth:e.cssWidth,cssHeight:e.cssHeight,cornerRadius:e.cornerRadius,kind:e.kind,ringCssPx:e.ringCssPx??(e.kind==="circle"?2:1)*n,shaderScale:e.shaderScale??(e.kind==="circle"?Qe:Ke)*n,opacityMul:e.opacityMul??1,visible:!0,paused:e.paused??!1,everCopied:!1,dpr:typeof window<"u"&&window.devicePixelRatio||1,scale:n,onAfterFrame:e.onAfterFrame,onFirstCopy:e.onFirstCopy};return nt(o),t.instances.add(o),t.rafId===0&&t.pausedAtMs===null&&K(),o}function tt(e){if(!i)return;i.instances.delete(e);const t=i.glowQueue.indexOf(e);t!==-1&&i.glowQueue.splice(t,1),i.instances.size===0&&(we(),It())}function Pt(e){i&&(i.glowQueue.includes(e)||i.glowQueue.push(e))}function Ft(e){if(!i)return;const t=i.glowQueue.indexOf(e);t!==-1&&i.glowQueue.splice(t,1)}function Y(e,t){let a=!1;t.cssWidth!==void 0&&t.cssWidth!==e.cssWidth&&(e.cssWidth=t.cssWidth,a=!0),t.cssHeight!==void 0&&t.cssHeight!==e.cssHeight&&(e.cssHeight=t.cssHeight,a=!0),t.cornerRadius!==void 0&&(e.cornerRadius=t.cornerRadius),t.scale!==void 0&&(e.scale=t.scale),t.kind!==void 0&&t.kind!==e.kind&&(e.kind=t.kind,t.shaderScale===void 0&&(e.shaderScale=(t.kind==="circle"?Qe:Ke)*e.scale),t.ringCssPx===void 0&&(e.ringCssPx=(t.kind==="circle"?2:1)*e.scale)),t.shaderScale!==void 0&&(e.shaderScale=t.shaderScale),t.ringCssPx!==void 0&&(e.ringCssPx=t.ringCssPx),t.opacityMul!==void 0&&(e.opacityMul=t.opacityMul),t.paused!==void 0&&t.paused!==e.paused&&(e.paused=t.paused,!t.paused&&i&&i.rafId===0&&i.pausedAtMs===null&&!i.contextLost&&K()),a&&nt(e)}function $t(e,t){e.visible=t,t&&i&&i.rafId===0&&i.pausedAtMs===null&&!i.contextLost&&K()}function at(e,t){const a=Je();a.preset=ve[e].modes[t],a.presetDirty=!0}function Ht(){!i||i.pausedAtMs!==null||(i.pausedAtMs=performance.now(),we())}function Nt(){!i||i.pausedAtMs===null||(i.pausedMs+=performance.now()-i.pausedAtMs,i.pausedAtMs=null,i.instances.size>0&&K())}let ge=null;function Gt(e){ge=e}function nt(e){e.dpr=typeof window<"u"&&window.devicePixelRatio||1;const t=Math.max(1,Math.round(e.cssWidth*e.dpr)),a=Math.max(1,Math.round(e.cssHeight*e.dpr));e.canvas.width!==t&&(e.canvas.width=t),e.canvas.height!==a&&(e.canvas.height=a)}function Wt(e){const{ctx:t,dpr:a,canvas:n}=e,o=e.ringCssPx*a,r=n.width,s=n.height,c=Math.max(0,(e.cornerRadius-e.ringCssPx)*a);t.save(),t.globalCompositeOperation="destination-out",t.fillStyle="#000",t.beginPath(),t.roundRect(o,o,r-2*o,s-2*o,c),t.fill(),t.restore()}function zt(e){var p;if(!i)return;const t=i.frameBitmap??i.glCanvas,a=e.dpr,n=e.canvas.width,o=e.canvas.height;if(n<1||o<1)return;const r=i.glCanvas.width,s=i.glCanvas.height,c=Ye*a,l=je*a;let d=n*(r/c)/e.shaderScale,f=o*(s/l)/e.shaderScale;d>r&&(d=r),f>s&&(f=s);const g=Math.max(0,(r-d)/2),u=Math.max(0,(s-f)/2);if(e.ctx.clearRect(0,0,n,o),e.opacityMul<1&&(e.ctx.globalAlpha=e.opacityMul),e.ctx.drawImage(t,g,u,d,f,0,0,n,o),e.opacityMul<1&&(e.ctx.globalAlpha=1),Wt(e),e.onFirstCopy){const h=e.onFirstCopy;e.onFirstCopy=void 0,h()}(p=e.onAfterFrame)==null||p.call(e)}function Bt(){if(!i)return;const{gl:e,uniforms:t,preset:a,glCanvas:n}=i;t.u_resolution&&e.uniform2f(t.u_resolution,n.width,n.height);for(let o=0;o<7;o++){const r=t[`u_color${o+1}`];if(r){const[c,l,d]=qe(a.colors[o]);e.uniform3f(r,c,l,d)}const s=t[`u_alpha${o+1}`];s&&e.uniform1f(s,a.alphas[o])}t.u_intensity&&e.uniform1f(t.u_intensity,a.intensity),t.u_scale&&e.uniform1f(t.u_scale,a.scale),t.u_direction&&e.uniform1f(t.u_direction,a.direction*Math.PI/180),t.u_softness&&e.uniform1f(t.u_softness,a.softness),t.u_distortion&&e.uniform1f(t.u_distortion,a.distortion),t.u_complexity&&e.uniform1f(t.u_complexity,a.complexity),t.u_shape&&e.uniform1f(t.u_shape,a.shape),t.u_vignette&&e.uniform1f(t.u_vignette,a.vignette),t.u_vigOpacity&&e.uniform1f(t.u_vigOpacity,a.vigOpacity),t.u_blur&&e.uniform1f(t.u_blur,a.blur),t.u_shaderOpacity&&e.uniform1f(t.u_shaderOpacity,a.shaderOpacity),i.presetDirty=!1}function Dt(e){if(!i)return;const{gl:t,uniforms:a,preset:n,glCanvas:o}=i,r=(e-i.startMs-i.pausedMs)/1e3*n.speed;t.viewport(0,0,o.width,o.height),t.clearColor(0,0,0,0),t.clear(t.COLOR_BUFFER_BIT),i.presetDirty&&Bt(),a.u_time&&t.uniform1f(a.u_time,r),t.drawArrays(t.TRIANGLES,0,6),i.frameCount++}let Ie=0;function ot(e){var a;if(!i)return;if(i.contextLost){i.rafId=0;return}let t=!1;for(const n of i.instances)if(n.visible&&(!n.paused||!n.everCopied)){t=!0;break}if(!t){i.rafId=0;return}if(i.rafId=requestAnimationFrame(ot),!(e-Ie<mt)){Ie=e,Dt(e),i.useOffscreen&&(i.glowQueue.length>0&&oe(),(a=i.frameBitmap)==null||a.close(),i.frameBitmap=i.glCanvas.transferToImageBitmap());for(const n of i.instances)n.visible&&(n.paused&&n.everCopied||(zt(n),n.everCopied=!0));if(ge&&i.glowQueue.length>0&&++i.glowSkip%vt===0){const n=i.glowQueue;i.glowIdx>=n.length&&(i.glowIdx=0);const o=n[i.glowIdx];o.visible&&!o.paused&&ge(o,e),i.glowIdx++}}}function K(){!i||i.rafId!==0||(i.rafId=requestAnimationFrame(ot))}function we(){i&&(i.rafId!==0&&cancelAnimationFrame(i.rafId),i.rafId=0)}const ae={linear:e=>e,smoothstep:e=>e*e*(3-2*e)};function V(e,t,a,n=ae.linear){return{from:e,to:t,dur:a,ease:n,startMs:-1,val:e,done:!1}}function q(e,t){e.startMs=t,e.val=e.from,e.done=!1}function Oe(e,t){if(e.done||e.startMs<0)return e.val;const a=Math.min(1,(t-e.startMs)/e.dur);return e.val=e.from+(e.to-e.from)*e.ease(a),a>=1&&(e.done=!0),e.val}const Ut=1.5,Z=1/3,Xt=4*Z,Vt=2*Z,qt=2*Z,Yt=1.35*Z,jt=13*Z;function ye(e,t,a){const n=Math.max(0,Math.min(a,Math.min(e,t)/2));return 2*Math.max(0,e-2*n)+2*Math.max(0,t-2*n)+2*Math.PI*n}function _e(e,t,a,n){return n==="circle"?2*Math.PI*Math.max(0,Math.min(a,Math.min(e,t)/2)):ye(e,t,a)}function J(e,t,a,n,o,r,s,c){const l=c||{x:0,y:0},d=Math.max(0,Math.min(n,Math.min(t,a)/2));if(s==="circle"){const x=2*Math.PI*d;if(x<=1e-4)return l.x=t*.5,l.y=a*.5,l;e=(e%x+x)%x;const I=-Math.PI/2+e/x*Math.PI*2,S=Math.max(0,d-o+r);return l.x=t*.5+S*Math.cos(I),l.y=a*.5+S*Math.sin(I),l}const f=Math.max(0,t-2*d),g=Math.max(0,a-2*d),u=Math.PI*d/2,p=2*(f+g)+4*u;e=(e%p+p)%p;const h=Math.max(0,d-o+r);let m=e;if(m<f)return l.x=d+m,l.y=o-r,l;if(m-=f,m<u){const x=-Math.PI/2+(u>0?m/u:0)*(Math.PI/2);return l.x=t-d+h*Math.cos(x),l.y=d+h*Math.sin(x),l}if(m-=u,m<g)return l.x=t-o+r,l.y=d+m,l;if(m-=g,m<u){const x=(u>0?m/u:0)*(Math.PI/2);return l.x=t-d+h*Math.cos(x),l.y=a-d+h*Math.sin(x),l}if(m-=u,m<f)return l.x=t-d-m,l.y=a-o+r,l;if(m-=f,m<u){const x=Math.PI/2+(u>0?m/u:0)*(Math.PI/2);return l.x=d+h*Math.cos(x),l.y=a-d+h*Math.sin(x),l}if(m-=u,m<g)return l.x=o-r,l.y=a-d-m,l;m-=g;const A=Math.PI+(u>0?m/u:0)*(Math.PI/2);return l.x=d+h*Math.cos(A),l.y=d+h*Math.sin(A),l}function Le(e,t){const a=e*2/t;let n="";for(let o=0;o<=t;o++){const r=-e+o*a;n+=(o===0?"M ":"L ")+r.toFixed(3)+" 0 "}return n}const de={x:0,y:0},fe={x:0,y:0};function Kt(e,t,a,n,o,r){return J(e-.1,t,a,n,o,0,r,de),J(e+.1,t,a,n,o,0,r,fe),Math.atan2(fe.y-de.y,fe.x-de.x)}function Pe(e,t,a){const n=Math.max(0,Math.min(1,(a-e)/(t-e)));return n*n*(3-2*n)}function Qt(e){const t=_e(e.width,e.height,e.cornerRadius,e.kind),a=Ut*(e.scale??1),n=[];for(let o=0;o<Te;o++){const r=o/Te*t,s=J(r,e.width,e.height,e.cornerRadius,a,0,e.kind);n.push({x:s.x,y:s.y,arc:r})}return n}function Jt(e,t){const{width:a,height:n,cornerRadius:o}=e,r=e.scale??1,s=e.kind==="circle"?2:1,c=Math.max(0,o-s),l=(-200*r).toFixed(0),d=l,f=(540*r).toFixed(0),g=(440*r).toFixed(0),u=`x="${l}" y="${d}" width="${f}" height="${g}"`,p=`${u} filterUnits="userSpaceOnUse" color-interpolation-filters="sRGB"`,h=A=>(A*r).toFixed(3),m=A=>(A*r).toFixed(3);return["<defs>",`<filter id="${t}_bXl" ${p}><feGaussianBlur stdDeviation="${m(8.4)}"/></filter>`,`<filter id="${t}_bLg" ${p}><feGaussianBlur stdDeviation="${m(4.8)}"/></filter>`,`<filter id="${t}_bMd" ${p}><feGaussianBlur stdDeviation="${m(2.1)}"/></filter>`,`<filter id="${t}_bSm" ${p}><feGaussianBlur stdDeviation="${m(.9)}"/></filter>`,`<filter id="${t}_ebO" ${p}><feGaussianBlur stdDeviation="${m(qt)}"/></filter>`,`<filter id="${t}_ebC" ${p}><feGaussianBlur stdDeviation="${m(Yt)}"/></filter>`,`<radialGradient id="${t}_fg" cx="0.5" cy="0.5" r="0.5"><stop offset="0" stop-color="white"/><stop offset="0.30" stop-color="white"/><stop offset="0.65" stop-color="#404040"/><stop offset="1" stop-color="black"/></radialGradient>`,`<mask id="${t}_fm" maskUnits="userSpaceOnUse" ${u}><rect ${u} fill="black"/><circle id="${t}_fc" cx="0" cy="0" r="${(jt*r).toFixed(3)}" fill="url(#${t}_fg)"/></mask>`,`<mask id="${t}_rm" maskUnits="userSpaceOnUse" ${u}><rect ${u} fill="#808080"/><rect x="0" y="0" width="${a}" height="${n}" rx="${o}" ry="${o}" fill="white"/><rect x="${s}" y="${s}" width="${a-s*2}" height="${n-s*2}" rx="${c}" ry="${c}" fill="black"/></mask>`,"</defs>",`<g id="${t}_h" mask="url(#${t}_rm)" opacity="0">`,`<rect ${u} fill="none" pointer-events="none"/>`,`<g id="${t}_hI" stroke="white">`,`<path id="${t}_pXl" stroke-width="${h(26.4)}" stroke-linecap="round" stroke-linejoin="round" fill="none" opacity="0.385" filter="url(#${t}_bXl)"/>`,`<path id="${t}_pLg" stroke-width="${h(15.6)}" stroke-linecap="round" stroke-linejoin="round" fill="none" opacity="0.595" filter="url(#${t}_bLg)"/>`,`<path id="${t}_pMd" stroke-width="${h(7.2)}" stroke-linecap="round" stroke-linejoin="round" fill="none" opacity="0.70" filter="url(#${t}_bMd)"/>`,`<path id="${t}_pSm" stroke-width="${h(3)}" stroke-linecap="round" stroke-linejoin="round" fill="none" opacity="0.70" filter="url(#${t}_bSm)"/>`,"</g></g>",`<g id="${t}_e" mask="url(#${t}_rm)" opacity="0">`,`<rect ${u} fill="none" pointer-events="none"/>`,`<g mask="url(#${t}_fm)">`,`<g id="${t}_eI" stroke="white">`,`<path id="${t}_eO" stroke-width="${h(Xt)}" stroke-linecap="round" stroke-linejoin="round" fill="none" opacity="0.85" filter="url(#${t}_ebO)"/>`,`<path id="${t}_eC" stroke-width="${h(Vt)}" stroke-linecap="round" stroke-linejoin="round" fill="none" opacity="1.0" filter="url(#${t}_ebC)"/>`,"</g></g></g>"].join("")}const Zt=.00875,Fe=.08,$e=.32,ea=.05,ta=3e3,He=.85,ee=.34,ue=1500,aa=15,na=.0075,oa=120,ra=1.5,ia=7.8,sa=9.13952,la=1,ca=1/3,da=.8,fa=3.51,Ne=2e3,he=400,ua=2.625,ha=1.008,pa=.31,rt=140,it=40,st=20;let ma=0;const z={x:0,y:0};function Ge(e,t){const a=`mfxg_${++ma}`,n=document.createElementNS("http://www.w3.org/2000/svg","svg");n.setAttribute("class","metal-fx-glow-svg"),n.setAttribute("preserveAspectRatio","none"),n.setAttribute("viewBox",`0 0 ${t.width} ${t.height}`),n.innerHTML=Jt(t,a),e.appendChild(n);const o=x=>n.querySelector(`#${a}_${x}`),r=o("h"),s=o("hI"),c=o("e"),l=o("eI"),d=o("fc"),f=_e(t.width,t.height,t.cornerRadius,t.kind)/ye(rt,it,st),g=Math.max(1,ia*f),u=Math.max(.6,sa*ca*f),p=Le(g,bt),h=Le(u,wt),m=[o("pXl"),o("pLg"),o("pMd"),o("pSm")],A=[o("eO"),o("eC")];for(const x of m)x.setAttribute("d",p);for(const x of A)x.setAttribute("d",h);return s.style.transformOrigin="0 0",l.style.transformOrigin="0 0",s.style.willChange="transform",l.style.willChange="transform",s.style.transition="transform 100ms linear",l.style.transition="transform 100ms linear",r.style.willChange="opacity",c.style.willChange="opacity",r.style.transition="opacity 100ms linear",c.style.transition="opacity 100ms linear",d.style.willChange="transform",{svg:n,haloGroup:r,haloInner:s,extraGroup:c,extraInner:l,fadeCircle:d,width:t.width,height:t.height,cornerRadius:t.cornerRadius,kind:t.kind,scale:t.scale??1,perim:Qt(t),currentIdx:0,appearedAt:0,glowOpacity:0,relocTween:null,relocNextIdx:-1,wanderS:0,wanderTargetS:0,wanderFrames:0,tintFrom:{r:255,g:255,b:255},tintTarget:{r:255,g:255,b:255},tintTween:null,tintHoldUntil:0,lastHaloStroke:"",lastExtraStroke:""}}function ga(e,t,a,n,o="dark"){var B;const{width:r,height:s,cornerRadius:c,perim:l}=e;if(l.length===0)return;const d=2;let f=-1,g=e.currentIdx,u=0;for(let E=0;E<l.length;E++){const P=l[E],N=Ee(t,P.x,P.y,d);N>f&&(f=N,g=E),E===e.currentIdx&&(u=N)}const p=e.appearedAt>0&&a-e.appearedAt<ta,h=ee+(He-ee)*Pe(Fe,$e,u),m=!p&&f-u>ea;if(!e.relocTween||e.relocTween.done)if(e.appearedAt===0)e.currentIdx=g,e.appearedAt=a,e.wanderS=0,e.wanderTargetS=0,e.wanderFrames=0,e.relocTween=V(0,h,ue,ae.smoothstep),q(e.relocTween,a);else if((B=e.relocTween)!=null&&B.done&&e.relocTween.to===0){e.currentIdx=e.relocNextIdx,e.appearedAt=a,e.wanderS=0,e.wanderTargetS=0,e.wanderFrames=0;const E=l[e.currentIdx],P=Ee(t,E.x,E.y,d),N=ee+(He-ee)*Pe(Fe,$e,P);e.relocTween=V(0,N,ue,ae.smoothstep),q(e.relocTween,a)}else m?(e.relocNextIdx=g,e.relocTween=V(e.glowOpacity,0,ue,ae.smoothstep),q(e.relocTween,a)):e.glowOpacity+=(h-e.glowOpacity)*Zt;e.relocTween&&(e.glowOpacity=Oe(e.relocTween,a)),e.glowOpacity=Math.max(0,Math.min(1,e.glowOpacity));const A=_e(r,s,c,e.kind)/ye(rt,it,st),x=aa*A;e.wanderFrames++>=oa&&(e.wanderTargetS=(Math.random()*2-1)*x,e.wanderFrames=0),e.wanderS+=(e.wanderTargetS-e.wanderS)*na;const I=l[e.currentIdx].arc+e.wanderS,S=ra*e.scale;J(I,r,s,c,S,0,e.kind,z);const L=z.x,F=z.y,_=Kt(I,r,s,c,S,e.kind),y=`translate(${L.toFixed(3)}px,${F.toFixed(3)}px) rotate(${_.toFixed(4)}rad)`;e.haloInner.style.transform=y;const R=la*A*e.scale;J(I,r,s,c,S,R,e.kind,z),e.extraInner.style.transform=`translate(${z.x.toFixed(3)}px,${z.y.toFixed(3)}px) rotate(${_.toFixed(4)}rad)`,e.fadeCircle.style.transform=`translate(${z.x.toFixed(3)}px,${z.y.toFixed(3)}px)`;const T=o==="light",v=T?Lt(t,L,F,d):Ot(t,L,F,d);e.tintTween?e.tintTween.done&&(T?(e.tintFrom={r:e.tintFrom.r+(e.tintTarget.r-e.tintFrom.r)*e.tintTween.val,g:e.tintFrom.g+(e.tintTarget.g-e.tintFrom.g)*e.tintTween.val,b:e.tintFrom.b+(e.tintTarget.b-e.tintFrom.b)*e.tintTween.val},e.tintTarget={...v},e.tintTween=V(0,1,he),q(e.tintTween,a)):a>=e.tintHoldUntil&&(e.tintFrom={...e.tintTarget},e.tintTarget={...v},e.tintTween=V(0,1,he),q(e.tintTween,a),e.tintHoldUntil=a+Ne)):(e.tintFrom={...v},e.tintTarget={...v},e.tintTween=V(0,1,he),q(e.tintTween,a),e.tintHoldUntil=T?0:a+Ne),Oe(e.tintTween,a);const b=e.tintTween.val;let $,O,M;if(T)$=Math.round(e.tintFrom.r+(e.tintTarget.r-e.tintFrom.r)*b),O=Math.round(e.tintFrom.g+(e.tintTarget.g-e.tintFrom.g)*b),M=Math.round(e.tintFrom.b+(e.tintTarget.b-e.tintFrom.b)*b);else{const E=e.tintFrom.r+(e.tintTarget.r-e.tintFrom.r)*b,P=e.tintFrom.g+(e.tintTarget.g-e.tintFrom.g)*b,N=e.tintFrom.b+(e.tintTarget.b-e.tintFrom.b)*b,W=Math.max(E,P,N)||1;$=Math.round(255*(E/W)),O=Math.round(255*(P/W)),M=Math.round(255*(N/W))}const k=`rgb(${$},${O},${M})`;if(k!==e.lastHaloStroke&&(e.lastHaloStroke=k,e.haloInner.style.stroke=k),T){const E=ht($,O,M),[P,N,W]=pt(E[0],Math.min(1,E[1]*ua),Math.max(pa,E[2]*ha)),D=`rgb(${P},${N},${W})`;D!==e.lastExtraStroke&&(e.lastExtraStroke=D,e.extraInner.style.stroke=D)}else e.lastExtraStroke!=="#ffffff"&&(e.lastExtraStroke="#ffffff",e.extraInner.style.stroke="#ffffff");const H=Math.max(0,Math.min(1,n));e.haloGroup.style.opacity=(e.glowOpacity*da*H).toFixed(3),e.extraGroup.style.opacity=Math.min(1,e.glowOpacity*fa*H).toFixed(3)}const xe=12,We=32,ze=1,Be=.55,xa=1,va=1,ba=.85,wa=0,ya=1.3,De=3.6,_a=.7,Ma=1,Sa=.52,Ra=1,Ta=.044,Aa=235,Ca=2.535,ka=.7,Ea=.5,Ia=new Set(["INPUT","TEXTAREA","SELECT","OPTION"]);function Oa(e,t){const a=Math.max(e.left-t.right,t.left-e.right,0),n=Math.max(e.top-t.bottom,t.top-e.bottom,0);return Math.sqrt(a*a+n*n)}function La(e,t,a,n){return!(Math.min(e.bottom,t.bottom)-Math.max(e.top,t.top)<a||Math.max(e.left-t.right,t.left-e.right,0)>n)}function Pa(e,t,a,n){return Math.min(e.right,t.right)-Math.max(e.left,t.left)<a?!1:Math.max(e.top-t.bottom,t.top-e.bottom,0)<=n}function U(e,t,a,n,o,r){const s=Math.max(0,Math.min(r,n*.5,o*.5)),c=e.roundRect;if(typeof c=="function"){c.call(e,t,a,n,o,s);return}e.moveTo(t+s,a),e.lineTo(t+n-s,a),e.quadraticCurveTo(t+n,a,t+n,a+s),e.lineTo(t+n,a+o-s),e.quadraticCurveTo(t+n,a+o,t+n-s,a+o),e.lineTo(t+s,a+o),e.quadraticCurveTo(t,a+o,t,a+o-s),e.lineTo(t,a+s),e.quadraticCurveTo(t,a,t+s,a)}function lt(e,t,a,n,o){if(!o.flipX&&!o.flipY){e.drawImage(t,0,0,a,n,o.x,o.y,o.w,o.h);return}e.save(),o.flipX&&(e.translate(o.x+o.w,0),e.scale(-1,1)),o.flipY&&(e.translate(0,o.y+o.h),e.scale(1,-1)),e.drawImage(t,0,0,a,n,o.flipX?0:o.x,o.flipY?0:o.y,o.w,o.h),e.restore()}const Fa=4;function $a(e,t,a,n,o,r,s){if(n<=2*s||o<=2*s){e.beginPath(),U(e,t,a,n,o,r),e.clip();return}e.beginPath(),U(e,t,a,n,o,r),U(e,t+s,a+s,n-2*s,o-2*s,Math.max(0,r-s)),e.clip("evenodd")}function Ha(e,t,a,n,o,r,s,c,l,d,f){const g=Math.max(1,Math.round((xe+Fa*3)*f));let u=Math.max(0,s),p=!0;for(let h=0;h<3&&u>1e-4;h++){const m=Math.min(1,u);e.save(),$a(e,d.x,d.y,d.w,d.h,d.r,g),e.globalCompositeOperation=p?"source-over":"lighter",p=!1,e.globalAlpha=m,lt(e,t,a,n,l),e.globalAlpha=1,e.globalCompositeOperation="destination-in",e.fillStyle=c,e.fillRect(0,0,o,r),e.restore(),u-=m}}function ct(e,t,a,n,o,r,s){const c=s|0;if(c<1||n<=2*c||o<=2*c){e.beginPath(),U(e,t,a,n,o,r),e.clip();return}e.beginPath(),U(e,t,a,n,o,r),U(e,t+c,a+c,n-2*c,o-2*c,Math.max(0,r-c)),e.clip("evenodd")}function Na(e,t,a,n,o,r,s,c,l,d,f,g){let u=c*f,p=!0;for(let h=0;h<3&&u>1e-4;h++){const m=Math.min(1,u);e.save(),ct(e,s.x,s.y,s.w,s.h,s.r,l),e.globalCompositeOperation=p?"source-over":"lighter",p=!1,e.globalAlpha=m,lt(e,t,a,n,g),e.globalAlpha=1,e.globalCompositeOperation="destination-in",e.fillStyle=d,e.fillRect(0,0,o,r),e.restore(),u-=m}}function Ga(e,t,a,n,o,r,s,c){const l=e.createLinearGradient(n,o,r,s);l.addColorStop(0,`rgba(255,255,255,${c.toFixed(3)})`),l.addColorStop(.5,`rgba(255,255,255,${(c*.45).toFixed(3)})`),l.addColorStop(1,"rgba(255,255,255,0)"),e.save(),ct(e,t.x,t.y,t.w,t.h,t.r,a),e.globalCompositeOperation="lighter",e.lineWidth=a*2,e.strokeStyle=l,e.beginPath(),U(e,t.x,t.y,t.w,t.h,t.r),e.stroke(),e.restore()}function dt(e){const t=getComputedStyle(e),a=[parseFloat(t.borderTopLeftRadius)||0,parseFloat(t.borderTopRightRadius)||0,parseFloat(t.borderBottomRightRadius)||0,parseFloat(t.borderBottomLeftRadius)||0].filter(n=>n>0);return a.length?Math.min.apply(null,a):0}function ft(e){const t=getComputedStyle(e),a=Math.max(parseFloat(t.borderTopWidth)||0,parseFloat(t.borderRightWidth)||0,parseFloat(t.borderBottomWidth)||0,parseFloat(t.borderLeftWidth)||0);let n=0,o=0;const r=t.boxShadow;if(r&&r!=="none"){const d=r.replace(/rgba?\([^)]*\)/g,u=>u.replace(/,/g,"\0")).split(/,\s*/);let f=1/0,g=1/0;for(const u of d){const p=u.match(/-?\d+(?:\.\d+)?px/g);if(!p||p.length<4)continue;const h=parseFloat(p[3]);h>0&&(/\binset\b/.test(u)?h<f&&(f=h):h<g&&(g=h))}Number.isFinite(f)&&(n=f),Number.isFinite(g)&&(o=g)}const s=Math.max(a,o);return{width:Math.max(a,n,o)||1,outerCssPx:s}}function Ue(e){e.cornerRadius=dt(e.el);const t=ft(e.el);e.hairlineWidth=t.width,e.hairlineOuterCssPx=t.outerCssPx}function Wa(e){typeof ResizeObserver<"u"&&(e.resizeObserver=new ResizeObserver(()=>Ue(e)),e.resizeObserver.observe(e.el)),typeof MutationObserver<"u"&&(e.mutationObserver=new MutationObserver(()=>Ue(e)),e.mutationObserver.observe(e.el,{attributes:!0,attributeFilter:["style","class"]}))}function za(e){var t,a;(t=e.resizeObserver)==null||t.disconnect(),e.resizeObserver=null,(a=e.mutationObserver)==null||a.disconnect(),e.mutationObserver=null}const j=new Set;function Ba(e,t,a){if(typeof document>"u"||Ia.has(e.tagName))return null;for(const p of j)if(p.el===e)return p;const n=document.createElement("div");n.setAttribute("data-metal-fx-reflection",""),n.setAttribute("aria-hidden","true");const o=document.createElement("canvas");o.className="metal-fx-reflection-canvas";const r=o.getContext("2d",{alpha:!0});if(!r)return null;const s=document.createElement("canvas");s.className="metal-fx-reflection-stroke-canvas";const c=s.getContext("2d",{alpha:!0});if(!c)return null;n.appendChild(o),n.appendChild(s);const l=getComputedStyle(e);let d=!1;l.position==="static"&&(e.style.position="relative",d=!0);let f=!1;l.isolation!=="isolate"&&(e.style.isolation="isolate",f=!0),e.setAttribute("data-metal-fx-reflect-host",""),e.insertBefore(n,e.firstChild);const g=ft(e),u={el:e,anchor:t,anchorEl:a,wrap:n,canvas:o,ctx:r,strokeCanvas:s,strokeCtx:c,cornerRadius:dt(e),hairlineWidth:g.width,hairlineOuterCssPx:g.outerCssPx,appliedPositionRelative:d,appliedIsolation:f,resizeObserver:null,mutationObserver:null};return Wa(u),j.add(u),u}function Da(e){for(const t of j)if(t.el===e){za(t),t.canvas.width=0,t.canvas.height=0,t.strokeCanvas.width=0,t.strokeCanvas.height=0,t.wrap.parentNode===t.el&&t.el.removeChild(t.wrap),t.el.removeAttribute("data-metal-fx-reflect-host"),t.appliedPositionRelative&&(t.el.style.position=""),t.appliedIsolation&&(t.el.style.isolation=""),j.delete(t);return}}function Ua(){if(j.size===0)return;const e=typeof window<"u"&&window.devicePixelRatio||1,t=new Map;for(const a of j){const n=a.el.getBoundingClientRect();let o=t.get(a.anchorEl);if(o||(o=a.anchorEl.getBoundingClientRect(),t.set(a.anchorEl,o)),n.width<1||n.height<1||o.width<1||o.height<1)continue;if(!La(o,n,ze,We)&&!Pa(o,n,ze,We)){a.canvas.width!==1&&(a.canvas.width=1,a.canvas.height=1),a.strokeCanvas.width!==1&&(a.strokeCanvas.width=1,a.strokeCanvas.height=1);continue}const r=a.anchor.canvas,s=r.width|0,c=r.height|0;if(s<4||c<4)continue;const l=(o.left+o.right)*.5,d=(o.top+o.bottom)*.5,f=(n.left+n.right)*.5,g=(n.top+n.bottom)*.5,u=l-f,p=d-g,h=Math.max(o.left-n.right,n.left-o.right,0),m=Math.max(o.top-n.bottom,n.top-o.bottom,0),A=h>=m,x=Oa(o,n);let I=1-Math.min(1,x/xe);I=I*I*(3-2*I);const S=Be+(xa-Be)*I,L=Math.min(De,S*ya*_a),F=a.anchor.scale??1,_=Math.max(Ma*F,a.hairlineWidth),y=Math.max(1,Math.round(_*e)),R=Math.max(1,Math.round(Math.max(Ra*F,a.hairlineWidth)*e)),T=a.hairlineOuterCssPx;a.wrap.style.inset=`${-T}px`,a.wrap.style.borderRadius=`${Math.max(0,a.cornerRadius)}px`;const v=Math.max(1,Math.round((n.width+T*2)*e)),b=Math.max(1,Math.round((n.height+T*2)*e));a.canvas.width!==v&&(a.canvas.width=v),a.canvas.height!==b&&(a.canvas.height=b),a.strokeCanvas.width!==v&&(a.strokeCanvas.width=v),a.strokeCanvas.height!==b&&(a.strokeCanvas.height=b);const $=a.ctx;$.setTransform(1,0,0,1,0,0),$.clearRect(0,0,v,b);const O=a.strokeCtx;O.setTransform(1,0,0,1,0,0),O.clearRect(0,0,v,b);const M=Math.min(xe*e,Math.max(v,b));let k,H,B,E;A?(k=u>0?v:0,B=u>0?v-M:M,H=b*.5,E=b*.5):(H=p>0?b:0,E=p>0?b-M:M,k=v*.5,B=v*.5);const P=$.createLinearGradient(k,H,B,E);P.addColorStop(0,`rgba(0,0,0,${va})`),P.addColorStop(.5,`rgba(0,0,0,${ba})`),P.addColorStop(1,`rgba(0,0,0,${wa})`);const N=s/e,W=Math.max(1,Math.round(Aa*Math.max(.1,N/140)*e));let D,re,ie,se,Me=!1,Se=!1;if(A){const Q=Math.max(o.top,n.top),ce=Math.min(o.bottom,n.bottom);Me=!0,D=u>0?v-W:0,re=Math.round((Q-n.top+T)*e),ie=W,se=Math.max(1,Math.round((ce-Q)*e))}else{const Q=Math.max(o.left,n.left),ce=Math.min(o.right,n.right);Se=!0,D=Math.round((Q-n.left+T)*e),re=p>0?b-W:0,ie=Math.max(1,Math.round((ce-Q)*e)),se=W}const Re={x:D,y:re,w:ie,h:se,flipX:Me,flipY:Se},le={x:0,y:0,w:v,h:b,r:Math.max(0,a.cornerRadius*e)},ut=Math.min(De,L*Ca*ka*Ea);Ha($,r,s,c,v,b,ut,P,Re,le,e),Na(O,r,s,c,v,b,le,L,y,P,Sa,Re),Ga(O,le,R,k,H,B,E,Math.min(.85,Ta*L)),$.globalCompositeOperation="source-over",O.globalCompositeOperation="source-over"}}let pe=!1,Xe=0;function Xa(){pe||(pe=!0,!(typeof requestAnimationFrame>"u")&&requestAnimationFrame(e=>{pe=!1,!(e-Xe<gt)&&(Xe=e,Ua())}))}const Ve="metal-fx-styles",Va=`
|
|
189
|
+
.metal-fx-root {
|
|
190
|
+
position: relative;
|
|
191
|
+
display: inline-flex;
|
|
192
|
+
align-items: center;
|
|
193
|
+
justify-content: center;
|
|
194
|
+
isolation: isolate;
|
|
195
|
+
overflow: visible;
|
|
196
|
+
background: #272727;
|
|
197
|
+
color: #f8f8f8;
|
|
198
|
+
}
|
|
199
|
+
.metal-fx-root[data-theme='light'] {
|
|
200
|
+
background: #ffffff;
|
|
201
|
+
color: #1d1d1d;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
.metal-fx-root::before {
|
|
205
|
+
content: '';
|
|
206
|
+
position: absolute;
|
|
207
|
+
inset: 0;
|
|
208
|
+
border-radius: inherit;
|
|
209
|
+
pointer-events: none;
|
|
210
|
+
z-index: 2;
|
|
211
|
+
box-shadow: inset 0 0 50px 0 rgba(255, 255, 255, 0.02);
|
|
212
|
+
}
|
|
213
|
+
.metal-fx-root[data-theme='light']::before {
|
|
214
|
+
box-shadow: inset 0 0 50px 0 rgba(0, 0, 0, 0.02);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
.metal-fx-root::after {
|
|
218
|
+
content: '';
|
|
219
|
+
position: absolute;
|
|
220
|
+
inset: 0;
|
|
221
|
+
border-radius: inherit;
|
|
222
|
+
pointer-events: none;
|
|
223
|
+
z-index: 4;
|
|
224
|
+
box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.1);
|
|
225
|
+
}
|
|
226
|
+
.metal-fx-root[data-theme='light']::after {
|
|
227
|
+
box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.06);
|
|
228
|
+
}
|
|
229
|
+
/* Circle variant gets a thicker outer rim than the button variant. */
|
|
230
|
+
.metal-fx-root[data-variant='circle']::after {
|
|
231
|
+
box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.1);
|
|
232
|
+
}
|
|
233
|
+
.metal-fx-root[data-theme='light'][data-variant='circle']::after {
|
|
234
|
+
box-shadow: inset 0 0 0 2px rgba(0, 0, 0, 0.06);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
.metal-fx-canvas {
|
|
238
|
+
position: absolute;
|
|
239
|
+
inset: 0;
|
|
240
|
+
width: 100%;
|
|
241
|
+
height: 100%;
|
|
242
|
+
display: block;
|
|
243
|
+
z-index: 0;
|
|
244
|
+
pointer-events: none;
|
|
245
|
+
border-radius: inherit;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/* The inner spacer — defines the inset geometry where the metal ring meets
|
|
249
|
+
the interior (3 px for Button, 1-2 px for Circle) and carries the Circle dark
|
|
250
|
+
hairline ('box-shadow: inset' rules below). Intentionally transparent so
|
|
251
|
+
the wrapper's background propagates through to the punched shader centre,
|
|
252
|
+
giving consumers a single surface tone to override. See "Single-surface
|
|
253
|
+
background" in the file header for the rationale. */
|
|
254
|
+
.metal-fx-inner {
|
|
255
|
+
position: absolute;
|
|
256
|
+
inset: 3px;
|
|
257
|
+
border-radius: inherit;
|
|
258
|
+
z-index: 1;
|
|
259
|
+
pointer-events: none;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
.metal-fx-root[data-variant='button'][data-shape='pill'] .metal-fx-inner {
|
|
263
|
+
border-radius: calc(var(--mfx-radius, 20px) - 3px);
|
|
264
|
+
}
|
|
265
|
+
.metal-fx-root[data-variant='button'][data-shape='circle'] .metal-fx-inner {
|
|
266
|
+
border-radius: calc(var(--mfx-radius, 16px) - 3px);
|
|
267
|
+
}
|
|
268
|
+
.metal-fx-root[data-variant='circle'][data-shape='pill'] .metal-fx-inner {
|
|
269
|
+
inset: 0;
|
|
270
|
+
border-radius: var(--mfx-radius, 20px);
|
|
271
|
+
box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.45);
|
|
272
|
+
}
|
|
273
|
+
.metal-fx-root[data-variant='circle'][data-shape='circle'] .metal-fx-inner {
|
|
274
|
+
inset: 0;
|
|
275
|
+
border-radius: var(--mfx-radius, 16px);
|
|
276
|
+
box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.45);
|
|
277
|
+
}
|
|
278
|
+
/* Circle-variant hairline alpha — light mode.
|
|
279
|
+
Source-of-truth: index.html L2261-2267. The 0.45-alpha black inset that
|
|
280
|
+
reads as a single-pixel frame against the dark interior is too heavy
|
|
281
|
+
on a #ffffff inner: it ends up looking like a hard 2-px black ring
|
|
282
|
+
against the iridescent shader. Suppressed entirely (alpha 0) — the
|
|
283
|
+
shader's own iridescent rim already defines the silhouette in light
|
|
284
|
+
mode, so an extra dark hairline only competes with it. The rule is
|
|
285
|
+
kept (rather than deleted) as a tunable hook in case a future variant
|
|
286
|
+
wants to re-introduce a soft edge. NOTE: we keep the dark-mode inset
|
|
287
|
+
and border-radius values because — unlike index.html — our renderer
|
|
288
|
+
does NOT overscan the canvas in light mode, so there is no 1-px gap
|
|
289
|
+
between inner element and shader to compensate for. */
|
|
290
|
+
.metal-fx-root[data-theme='light'][data-variant='circle'][data-shape='pill'] .metal-fx-inner,
|
|
291
|
+
.metal-fx-root[data-theme='light'][data-variant='circle'][data-shape='circle'] .metal-fx-inner {
|
|
292
|
+
box-shadow: 0 0 0 1px rgba(0, 0, 0, 0);
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
/* ─── Combined glow SVG (z=3) ──────────────────────────────────────────────
|
|
296
|
+
Single SVG per instance that holds BOTH the wide-halo group
|
|
297
|
+
(#mfx_haloTravel) and the catch-light group (#mfx_extraTravel), exactly
|
|
298
|
+
mirroring canonical's _buildGlowSvgInner (index.html L8078). One
|
|
299
|
+
mix-blend-mode: screen lifts the combined composite onto the shader
|
|
300
|
+
ring; per-frame opacity attributes on each inner group still drive the
|
|
301
|
+
independent fade-in / fade-out cycles for the halo and the catch-light.
|
|
302
|
+
|
|
303
|
+
Why a single SVG: the circle variant anchors halo + catch-light at the same
|
|
304
|
+
perimeter point, so they overlap in the bright zone. Two separately-
|
|
305
|
+
screened SVGs would double-screen the overlap (A + B + C - AB - AC -
|
|
306
|
+
BC + ABC instead of A + B + C - AB - AC once both groups composite
|
|
307
|
+
in source-over inside one SVG and then screen against the host once).
|
|
308
|
+
That overlap looked muted versus canonical specifically on the circle
|
|
309
|
+
variant where both layers travel together.
|
|
310
|
+
|
|
311
|
+
Source-of-truth opacity: #btnGlowSvg drops to 0.7 in dark and 0.2746 in
|
|
312
|
+
light (index.html L632/L643). */
|
|
313
|
+
.metal-fx-glow-svg {
|
|
314
|
+
position: absolute;
|
|
315
|
+
inset: 0;
|
|
316
|
+
width: 100%;
|
|
317
|
+
height: 100%;
|
|
318
|
+
overflow: visible;
|
|
319
|
+
z-index: 3;
|
|
320
|
+
pointer-events: none;
|
|
321
|
+
opacity: 0.7;
|
|
322
|
+
}
|
|
323
|
+
.metal-fx-root[data-theme='light'] .metal-fx-glow-svg {
|
|
324
|
+
/* Light-mode 1-px overscan mirrors .btn-glow-svg in metal.html so the
|
|
325
|
+
halo stays glued to the visible silhouette (the shader ring there sits
|
|
326
|
+
1 px outside the host's padding box). */
|
|
327
|
+
inset: -1px;
|
|
328
|
+
width: calc(100% + 2px);
|
|
329
|
+
height: calc(100% + 2px);
|
|
330
|
+
mix-blend-mode: multiply;
|
|
331
|
+
/* Source-of-truth: html[data-theme="light"] #btnGlowSvg { opacity: 0.2746 }
|
|
332
|
+
→ −35 % from 0.4225 from the original 0.7 dark-mode opacity. */
|
|
333
|
+
opacity: 0.2746;
|
|
334
|
+
filter: saturate(5.355) brightness(0.78);
|
|
335
|
+
}
|
|
336
|
+
/* Circle light-mode small variants (e.g. 36×36 send button): the geometrically
|
|
337
|
+
shrunk halo loses density when multiplied against #ffffff. Mirror the
|
|
338
|
+
canonical override at index.html L2316 — bump saturation + drop brightness
|
|
339
|
+
so the small glow holds together visually. */
|
|
340
|
+
.metal-fx-root[data-variant='circle'][data-shape='circle'][data-theme='light'] .metal-fx-glow-svg {
|
|
341
|
+
filter: saturate(7.5) brightness(0.6);
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
/* The wrapped child — hoisted into z=5 so it sits above every overlay, with
|
|
345
|
+
normalized chrome so consumer button styles don't fight the metal frame. */
|
|
346
|
+
.metal-fx-content {
|
|
347
|
+
position: relative;
|
|
348
|
+
z-index: 5;
|
|
349
|
+
display: inline-flex;
|
|
350
|
+
align-items: center;
|
|
351
|
+
justify-content: center;
|
|
352
|
+
width: 100%;
|
|
353
|
+
pointer-events: none;
|
|
354
|
+
}
|
|
355
|
+
.metal-fx-content > * {
|
|
356
|
+
pointer-events: auto;
|
|
357
|
+
}
|
|
358
|
+
.metal-fx-root[data-normalize='true'] .metal-fx-content > * {
|
|
359
|
+
background: transparent !important;
|
|
360
|
+
border: 0 !important;
|
|
361
|
+
outline: 0 !important;
|
|
362
|
+
box-shadow: none !important;
|
|
363
|
+
/* Sizing: we deliberately DO NOT force \`width: 100%; height: 100%\` on the
|
|
364
|
+
child here. That used to be the contract ("the wrapper is the visible
|
|
365
|
+
button surface; the child stretches to fill it"), but it created a cyclic
|
|
366
|
+
percentage dependency: the wrapper is \`inline-flex\` with no intrinsic
|
|
367
|
+
size, .metal-fx-content is \`width/height: 100%\` of the wrapper, and the
|
|
368
|
+
child was \`100%\` of .metal-fx-content. With nothing breaking the cycle,
|
|
369
|
+
icon-only / class-sized children collapsed.
|
|
370
|
+
|
|
371
|
+
The new contract: the child sizes itself (intrinsic content, CSS class,
|
|
372
|
+
or inline style — all work), and the wrapper's \`inline-flex\` wraps it
|
|
373
|
+
tightly. Consumers who want a metal frame BIGGER than the child (e.g.
|
|
374
|
+
padding around an icon) size <MetalFx style={{ width, height }}> AND
|
|
375
|
+
explicitly set width/height on the child to fill (or accept that the
|
|
376
|
+
child renders at its intrinsic size, centered).
|
|
377
|
+
|
|
378
|
+
Typography is intentionally NOT touched. We used to apply
|
|
379
|
+
\`color: inherit; font: inherit;\` here to "match" the wrapper, but
|
|
380
|
+
\`font: inherit\` is a shorthand that overrides font-family, font-size,
|
|
381
|
+
font-weight, AND line-height on the child — which (a) shrank the
|
|
382
|
+
button height (line-height changes propagate through the flex
|
|
383
|
+
content box) and (b) scaled em-based icons / font-icons inside the
|
|
384
|
+
child to whatever the wrapper inherited. The wrapper now stays out
|
|
385
|
+
of the child's typography entirely; consumers who want typographic
|
|
386
|
+
normalization can apply it themselves on the child element. */
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
[data-metal-fx-reflection] {
|
|
390
|
+
position: absolute;
|
|
391
|
+
inset: 0;
|
|
392
|
+
pointer-events: none;
|
|
393
|
+
border-radius: inherit;
|
|
394
|
+
overflow: hidden;
|
|
395
|
+
z-index: 0;
|
|
396
|
+
isolation: isolate;
|
|
397
|
+
}
|
|
398
|
+
.metal-fx-reflection-canvas {
|
|
399
|
+
position: absolute;
|
|
400
|
+
inset: 0;
|
|
401
|
+
width: 100%;
|
|
402
|
+
height: 100%;
|
|
403
|
+
display: block;
|
|
404
|
+
filter: blur(4px) saturate(1.2) brightness(1.58);
|
|
405
|
+
}
|
|
406
|
+
.metal-fx-reflection-stroke-canvas {
|
|
407
|
+
position: absolute;
|
|
408
|
+
inset: 0;
|
|
409
|
+
width: 100%;
|
|
410
|
+
height: 100%;
|
|
411
|
+
display: block;
|
|
412
|
+
filter: saturate(1.35) brightness(1.75);
|
|
413
|
+
}
|
|
414
|
+
/* Hosts that participate as reflection targets need positioning + isolation
|
|
415
|
+
so the wrap composites only against the host (not the parent stack). The
|
|
416
|
+
wrap injects these inline as well, but stating them here keeps reflections
|
|
417
|
+
working on hosts that already have other inline styles applied. */
|
|
418
|
+
[data-metal-fx-reflect-host] {
|
|
419
|
+
isolation: isolate;
|
|
420
|
+
}
|
|
421
|
+
`;let me=!1;function qa(){if(me||typeof document>"u")return;if(document.getElementById(Ve)){me=!0;return}const e=document.createElement("style");e.id=Ve,e.textContent=Va,document.head.appendChild(e),me=!0}const Ya=["data-variant","data-shape","data-theme","data-paused","data-normalize"];qa();const ja={position:"absolute",inset:"0",width:"100%",height:"100%"},Ka={position:"absolute",inset:"3px"},Qa={position:"absolute",inset:"0",pointerEvents:"none",zIndex:3,borderRadius:"inherit"},ne=new Map;Gt((e,t)=>{const a=ne.get(e);a&&ga(a.handles,e,t,e.opacityMul,a.themeRef.current)});function Ja(e){const t=c=>c!=="auto"?c:typeof window>"u"||!window.matchMedia||window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light",a=w.ref(t(e()));let n=null;const o=()=>{n&&(a.value=n.matches?"dark":"light")},r=()=>{n==null||n.removeEventListener("change",o),n=null},s=()=>{if(r(),e()!=="auto"){a.value=e();return}typeof window>"u"||!window.matchMedia||(n=window.matchMedia("(prefers-color-scheme: dark)"),o(),n.addEventListener("change",o))};return w.onMounted(s),w.watch(e,s),w.onBeforeUnmount(r),a}const Za=w.defineComponent({__name:"MetalFx",props:{variant:{default:"button"},preset:{default:"chromatic"},theme:{default:"auto"},strength:{default:1},paused:{type:Boolean,default:!1},borderRadius:{},normalizeHostStyles:{type:Boolean,default:!0},reflectionTargets:{},disableGlow:{type:Boolean,default:!1},shaderScale:{},ringCssPx:{},scale:{default:1}},setup(e,{expose:t}){const a=e,n=w.ref(null),o=w.ref(null),r=w.ref(null),s=w.ref(null);let c=null,l=null,d=0;const f=w.ref(!1),g=Ja(()=>a.theme),u={get current(){return g.value}},p=w.computed(()=>a.variant==="circle"?"circle":"pill"),h=w.computed(()=>!a.disableGlow);t({rootEl:n});const m=(_,y)=>{if(p.value==="circle")return Math.min(_,y)/2;const R=typeof a.borderRadius=="number"?a.borderRadius:(()=>{var v;const T=(v=s.value)==null?void 0:v.firstElementChild;if(T){const b=parseFloat(getComputedStyle(T).borderTopLeftRadius);if(Number.isFinite(b)&&b>0)return b}return d})();return Math.min(R,Math.min(_,y)/2)};w.watch([()=>a.preset,g],([_,y])=>{at(_,y)},{immediate:!0}),w.watch(()=>a.paused,_=>{c&&Y(c,{paused:_})}),w.watch([()=>a.shaderScale,()=>a.ringCssPx,()=>a.scale],([_,y,R])=>{if(!c)return;const T={};_!==void 0&&(T.shaderScale=_),y!==void 0&&(T.ringCssPx=y),R!==void 0&&(T.scale=R),Object.keys(T).length>0&&Y(c,T)});const A=()=>{c&&Y(c,{opacityMul:Math.max(0,Math.min(1,a.strength))})};w.watch([()=>a.strength,()=>a.variant],A);let x=null;const I=()=>{const _=o.value,y=n.value,R=r.value;if(!_||!y)return;{const M=getComputedStyle(y),k=parseFloat(M.borderTopLeftRadius);d=Number.isFinite(k)?k:0}const T=()=>{const M=y.getBoundingClientRect(),k=Math.max(1,Math.round(M.width)),H=Math.max(1,Math.round(M.height));return{cssWidth:k,cssHeight:H,cornerRadius:m(k,H)}},v=T();c=et({hostCanvas:_,cssWidth:v.cssWidth,cssHeight:v.cssHeight,cornerRadius:v.cornerRadius,kind:p.value,paused:a.paused,shaderScale:a.shaderScale,ringCssPx:a.ringCssPx,scale:a.scale,onFirstCopy:()=>{f.value=!0}}),y.style.setProperty("--mfx-radius",`${v.cornerRadius}px`),y.style.borderRadius=`${v.cornerRadius}px`,A(),R&&(l=Ge(R,{width:v.cssWidth,height:v.cssHeight,cornerRadius:v.cornerRadius,kind:p.value,scale:a.scale}));let b=0;const $=new ResizeObserver(()=>{b===0&&(b=requestAnimationFrame(()=>{b=0;const M=T(),k=c;k&&(Y(k,{cssWidth:M.cssWidth,cssHeight:M.cssHeight,cornerRadius:M.cornerRadius}),y.style.setProperty("--mfx-radius",`${M.cornerRadius}px`),y.style.borderRadius=`${M.cornerRadius}px`,R&&(R.innerHTML="",l=Ge(R,{width:M.cssWidth,height:M.cssHeight,cornerRadius:M.cornerRadius,kind:p.value,scale:a.scale}),k&&l&&ne.set(k,{handles:l,themeRef:u})))}))});$.observe(y);let O=null;typeof IntersectionObserver<"u"&&(O=new IntersectionObserver(M=>{const k=c;if(k)for(const H of M)$t(k,H.isIntersecting)},{rootMargin:"64px"}),O.observe(y)),c&&l&&(ne.set(c,{handles:l,themeRef:u}),Pt(c)),x=()=>{$.disconnect(),O==null||O.disconnect(),b!==0&&cancelAnimationFrame(b);const M=c;M&&(ne.delete(M),Ft(M),tt(M)),c=null,l=null,R&&(R.innerHTML="")}};let S=null;const L=()=>{S==null||S(),S=null;const _=c,y=n.value,R=a.reflectionTargets;if(!_||!y||!R||g.value!=="dark")return;_.onAfterFrame=Xa;const T=R.flatMap(v=>{const b=w.toValue(v);return b?[b]:[]});for(const v of T)Ba(v,_,y);S=()=>{_.onAfterFrame=void 0;for(const v of T)Da(v)}};w.onMounted(()=>{I(),w.nextTick(L)}),w.watch(p,()=>{x==null||x(),x=null,S==null||S(),S=null,I(),w.nextTick(L)},{flush:"post"}),w.watch([()=>a.reflectionTargets,g],()=>{L()},{flush:"post"}),w.onBeforeUnmount(()=>{S==null||S(),S=null,x==null||x(),x=null}),w.watch([()=>a.borderRadius,g,()=>a.variant],()=>{const _=n.value,y=c;if(!_||!y)return;const R=m(y.cssWidth,y.cssHeight);Y(y,{cornerRadius:R}),_.style.setProperty("--mfx-radius",`${R}px`),_.style.borderRadius=`${R}px`},{flush:"post"});const F=w.computed(()=>({"--mfx-strength":String(Math.min(1,Math.max(0,a.strength))),opacity:f.value?1:0,visibility:f.value?"visible":"hidden",transition:f.value?"opacity 0.15s ease-out":"none"}));return(_,y)=>(w.openBlock(),w.createElementBlock("div",{ref_key:"rootRef",ref:n,class:"metal-fx-root","data-variant":e.variant,"data-shape":p.value,"data-theme":w.unref(g),"data-paused":e.paused?"true":void 0,"data-normalize":e.normalizeHostStyles?"true":"false",style:w.normalizeStyle(F.value)},[w.createElementVNode("canvas",{ref_key:"canvasRef",ref:o,class:"metal-fx-canvas",style:ja},null,512),w.createElementVNode("div",{class:"metal-fx-inner","aria-hidden":"true",style:Ka}),w.createElementVNode("div",{ref_key:"glowHostRef",ref:r,"aria-hidden":"true",style:w.normalizeStyle([Qa,h.value?null:{display:"none"}])},null,4),w.createElementVNode("div",{ref_key:"contentRef",ref:s,class:"metal-fx-content"},[w.renderSlot(_.$slots,"default")],512)],12,Ya))}});exports.MetalFx=Za;exports.PRESETS=ve;exports.createInstance=et;exports.destroyInstance=tt;exports.hexToRgb=qe;exports.pauseShared=Ht;exports.resumeShared=Nt;exports.setSharedPreset=at;exports.updateInstance=Y;
|