@cos-design/ripple-water 3.5.4 → 3.5.6

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/dist/index.cjs CHANGED
@@ -90,4 +90,4 @@ void main() {
90
90
 
91
91
  gl_FragColor = vec4(water, 1.0);
92
92
  }
93
- `,m=e=>{let t=e.replace(`#`,``),n=t.length===3?t.split(``).map(e=>e+e).join(``):t,r=Number.parseInt(n,16);return Number.isNaN(r)?[.22,.74,.97]:[(r>>16&255)/255,(r>>8&255)/255,(r&255)/255]},h=(e,t,n)=>{let r=e.createShader(t);return r?(e.shaderSource(r,n),e.compileShader(r),e.getShaderParameter(r,e.COMPILE_STATUS)?r:(e.deleteShader(r),null)):null},g=(e,t,n)=>{let r=h(e,e.VERTEX_SHADER,t),i=h(e,e.FRAGMENT_SHADER,n);if(!r||!i)return null;let a=e.createProgram();return a?(e.attachShader(a,r),e.attachShader(a,i),e.linkProgram(a),e.deleteShader(r),e.deleteShader(i),e.getProgramParameter(a,e.LINK_STATUS)?a:(e.deleteProgram(a),null)):null},_=192,v=e=>({from:m(e.fromColor),to:m(e.toColor),tint:m(e.color),waveAmplitude:e.waveAmplitude,waveSpeed:e.waveSpeed,shimmer:e.shimmer,reflection:e.reflection,rippleStrength:e.rippleStrength,rippleRadius:e.rippleRadius,damping:e.damping,spread:e.spread,interactive:e.interactive}),y=({width:e=800,height:t=500,fromColor:n=`#52ade3`,toColor:r=`#013565`,color:i=`#a8d8f5`,waveAmplitude:a=1,waveSpeed:o=1,shimmer:s=1,reflection:m=.38,rippleStrength:h=1,rippleRadius:y=6,damping:b=.985,spread:x=.5,interactive:S=!0,showHint:C=!0,hint:w=`点击水面产生涟漪`})=>{let T=(0,c.useRef)(null),E=(0,c.useRef)(0),D=(0,c.useRef)(null),O=(0,c.useRef)(v({fromColor:n,toColor:r,color:i,waveAmplitude:a,waveSpeed:o,shimmer:s,reflection:m,rippleStrength:h,rippleRadius:y,damping:b,spread:x,interactive:S}));(0,c.useEffect)(()=>{O.current=v({fromColor:n,toColor:r,color:i,waveAmplitude:a,waveSpeed:o,shimmer:s,reflection:m,rippleStrength:h,rippleRadius:y,damping:b,spread:x,interactive:S})},[n,r,i,a,o,s,m,h,y,b,x,S]);let k=(0,c.useCallback)((e,t)=>{if(!O.current.interactive)return;let n=T.current;if(!n)return;let r=n.getBoundingClientRect();D.current={x:(e-r.left)/r.width,y:1-(t-r.top)/r.height,strength:O.current.rippleStrength}},[]);return(0,c.useEffect)(()=>{let e=T.current;if(!e)return;let t=e=>{e.pointerType===`mouse`&&e.button!==0||k(e.clientX,e.clientY)};return e.addEventListener(`pointerdown`,t),()=>e.removeEventListener(`pointerdown`,t)},[k]),(0,c.useEffect)(()=>{let n=T.current;if(!n)return;let r=Math.min(window.devicePixelRatio||1,2);n.width=Math.floor(e*r),n.height=Math.floor(t*r);let i=n.getContext(`webgl`,{alpha:!1,antialias:!1,depth:!1,stencil:!1,premultipliedAlpha:!1});if(!i)return;let a=g(i,f,p);if(!a)return;let o=i.createBuffer();i.bindBuffer(i.ARRAY_BUFFER,o),i.bufferData(i.ARRAY_BUFFER,new Float32Array([-1,-1,1,-1,-1,1,1,1]),i.STATIC_DRAW);let s=i.getAttribLocation(a,`a_pos`),c=i.getUniformLocation(a,`u_time`),u=i.getUniformLocation(a,`u_res`),d=i.getUniformLocation(a,`u_tint`),m=i.getUniformLocation(a,`u_from`),h=i.getUniformLocation(a,`u_to`),v=i.getUniformLocation(a,`u_height`),y=i.getUniformLocation(a,`u_sim`),b=i.getUniformLocation(a,`u_waveAmp`),x=i.getUniformLocation(a,`u_waveSpeed`),S=i.getUniformLocation(a,`u_shimmer`),C=i.getUniformLocation(a,`u_reflection`),w=_*_,k=new Float32Array(w),A=new Float32Array(w),j=new Float32Array(w),M=i.createTexture();i.bindTexture(i.TEXTURE_2D,M),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MIN_FILTER,i.LINEAR),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MAG_FILTER,i.LINEAR),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_S,i.CLAMP_TO_EDGE),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_T,i.CLAMP_TO_EDGE);let N=new Uint8Array(w*4),P=()=>{for(let e=0;e<w;e++){let t=Math.max(0,Math.min(255,Math.floor((A[e]*.5+.5)*255))),n=e*4;N[n]=t,N[n+1]=t,N[n+2]=t,N[n+3]=255}i.bindTexture(i.TEXTURE_2D,M),i.texImage2D(i.TEXTURE_2D,0,i.RGBA,_,_,0,i.RGBA,i.UNSIGNED_BYTE,N)},F=(e,t,n,r)=>{let i=e*(_-1),a=t*(_-1),o=(0,l.clamp)(r,2,12);for(let e=-o-1;e<=o+1;e++)for(let t=-o-1;t<=o+1;t++){let r=Math.round(i+t),s=Math.round(a+e);if(r<=0||r>=_-1||s<=0||s>=_-1)continue;let c=Math.sqrt(t*t+e*e),l=Math.exp(-c*c*.55)*-.35,u=Math.exp(-((c-o*.55)**2)*.9);A[s*_+r]+=n*(l+u*1.1)}},I=(e,t)=>{let n=(0,l.clamp)(e,.9,.999),r=(0,l.clamp)(t,.3,.7);for(let e=0;e<2;e++){for(let e=1;e<_-1;e++){let t=e*_;for(let e=1;e<_-1;e++){let i=t+e,a=A[i-1]+A[i+1]+A[i-_]+A[i+_];j[i]=(a*r-k[i])*n,j[i]>1.5?j[i]=1.5:j[i]<-1.5&&(j[i]=-1.5)}}let e=k;k=A,A=j,j=e,j.fill(0)}},L=e=>{let t=O.current;i.viewport(0,0,n.width,n.height),i.useProgram(a),i.bindBuffer(i.ARRAY_BUFFER,o),i.enableVertexAttribArray(s),i.vertexAttribPointer(s,2,i.FLOAT,!1,0,0),i.activeTexture(i.TEXTURE0),i.bindTexture(i.TEXTURE_2D,M),i.uniform1i(v,0),i.uniform1f(c,e),i.uniform2f(u,n.width,n.height),i.uniform3f(d,t.tint[0],t.tint[1],t.tint[2]),i.uniform3f(m,t.from[0],t.from[1],t.from[2]),i.uniform3f(h,t.to[0],t.to[1],t.to[2]),i.uniform2f(y,_,_),i.uniform1f(b,(0,l.clamp)(t.waveAmplitude,0,2)),i.uniform1f(x,(0,l.clamp)(t.waveSpeed,0,3)),i.uniform1f(S,(0,l.clamp)(t.shimmer,0,2)),i.uniform1f(C,(0,l.clamp)(t.reflection,0,1)),i.drawArrays(i.TRIANGLE_STRIP,0,4)};if(P(),typeof window<`u`&&window.matchMedia(`(prefers-reduced-motion: reduce)`).matches)return L(0),()=>{i.deleteTexture(M),i.deleteBuffer(o),i.deleteProgram(a)};let R=document.hidden,z=(0,l.bindVisibilityPause)(e=>{R=e}),B=performance.now(),V=e=>{if(E.current=requestAnimationFrame(V),R)return;let t=O.current;if(D.current){let e=D.current,n=(0,l.clamp)(e.strength,0,3),r=t.rippleRadius;F(e.x,e.y,n,r),F(e.x+.004,e.y-.003,n*.35,r),D.current=null}I(t.damping,t.spread),P(),L((e-B)/1e3)};return E.current=requestAnimationFrame(V),()=>{cancelAnimationFrame(E.current),z(),i.deleteTexture(M),i.deleteBuffer(o),i.deleteProgram(a)}},[t,e]),(0,u.jsxs)(`div`,{className:d.rippleWater,style:{width:e,height:t},children:[(0,u.jsx)(`canvas`,{ref:T,className:d.canvas,style:{width:e,height:t,cursor:S?`pointer`:`default`},role:`img`,"aria-label":w||`涟漪水面`}),C?(0,u.jsx)(`span`,{className:d.hint,"aria-hidden":!0,children:w}):null]})};exports.RippleWater=y,exports.default=y;
93
+ `,m=e=>{let t=e.replace(`#`,``),n=t.length===3?t.split(``).map(e=>e+e).join(``):t,r=Number.parseInt(n,16);return Number.isNaN(r)?[.22,.74,.97]:[(r>>16&255)/255,(r>>8&255)/255,(r&255)/255]},h=(e,t,n)=>{let r=e.createShader(t);return r?(e.shaderSource(r,n),e.compileShader(r),e.getShaderParameter(r,e.COMPILE_STATUS)?r:(e.deleteShader(r),null)):null},g=(e,t,n)=>{let r=h(e,e.VERTEX_SHADER,t),i=h(e,e.FRAGMENT_SHADER,n);if(!r||!i)return null;let a=e.createProgram();return a?(e.attachShader(a,r),e.attachShader(a,i),e.linkProgram(a),e.deleteShader(r),e.deleteShader(i),e.getProgramParameter(a,e.LINK_STATUS)?a:(e.deleteProgram(a),null)):null},_=192,v=e=>({from:m(e.fromColor),to:m(e.toColor),tint:m(e.color),waveAmplitude:e.waveAmplitude,waveSpeed:e.waveSpeed,shimmer:e.shimmer,reflection:e.reflection,rippleStrength:e.rippleStrength,rippleRadius:e.rippleRadius,damping:e.damping,spread:e.spread,interactive:e.interactive}),y=({width:e,height:t,fill:n=!1,fromColor:r=`#52ade3`,toColor:i=`#013565`,color:a=`#a8d8f5`,waveAmplitude:o=1,waveSpeed:s=1,shimmer:m=1,reflection:h=.38,rippleStrength:y=1,rippleRadius:b=6,damping:x=.985,spread:S=.5,interactive:C=!0,showHint:w=!0,hint:T=`点击水面产生涟漪`})=>{let{hostRef:E,width:D,height:O,hostStyle:k}=(0,l.useCanvasBox)({fill:n,width:e,height:t,defaultWidth:800,defaultHeight:500}),A=(0,c.useRef)(null),j=(0,c.useRef)(0),M=(0,c.useRef)(null),N=(0,c.useRef)(v({fromColor:r,toColor:i,color:a,waveAmplitude:o,waveSpeed:s,shimmer:m,reflection:h,rippleStrength:y,rippleRadius:b,damping:x,spread:S,interactive:C}));(0,c.useEffect)(()=>{N.current=v({fromColor:r,toColor:i,color:a,waveAmplitude:o,waveSpeed:s,shimmer:m,reflection:h,rippleStrength:y,rippleRadius:b,damping:x,spread:S,interactive:C})},[r,i,a,o,s,m,h,y,b,x,S,C]);let P=(0,c.useCallback)((e,t)=>{if(!N.current.interactive)return;let n=A.current;if(!n)return;let r=n.getBoundingClientRect();M.current={x:(e-r.left)/r.width,y:1-(t-r.top)/r.height,strength:N.current.rippleStrength}},[]);return(0,c.useEffect)(()=>{let e=A.current;if(!e)return;let t=e=>{e.pointerType===`mouse`&&e.button!==0||P(e.clientX,e.clientY)};return e.addEventListener(`pointerdown`,t),()=>e.removeEventListener(`pointerdown`,t)},[P]),(0,c.useEffect)(()=>{let e=A.current;if(!e)return;let t=Math.min(window.devicePixelRatio||1,2);e.width=Math.floor(D*t),e.height=Math.floor(O*t);let n=e.getContext(`webgl`,{alpha:!1,antialias:!1,depth:!1,stencil:!1,premultipliedAlpha:!1});if(!n)return;let r=g(n,f,p);if(!r)return;let i=n.createBuffer();n.bindBuffer(n.ARRAY_BUFFER,i),n.bufferData(n.ARRAY_BUFFER,new Float32Array([-1,-1,1,-1,-1,1,1,1]),n.STATIC_DRAW);let a=n.getAttribLocation(r,`a_pos`),o=n.getUniformLocation(r,`u_time`),s=n.getUniformLocation(r,`u_res`),c=n.getUniformLocation(r,`u_tint`),u=n.getUniformLocation(r,`u_from`),d=n.getUniformLocation(r,`u_to`),m=n.getUniformLocation(r,`u_height`),h=n.getUniformLocation(r,`u_sim`),v=n.getUniformLocation(r,`u_waveAmp`),y=n.getUniformLocation(r,`u_waveSpeed`),b=n.getUniformLocation(r,`u_shimmer`),x=n.getUniformLocation(r,`u_reflection`),S=_*_,C=new Float32Array(S),w=new Float32Array(S),T=new Float32Array(S),E=n.createTexture();n.bindTexture(n.TEXTURE_2D,E),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,n.LINEAR),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MAG_FILTER,n.LINEAR),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,n.CLAMP_TO_EDGE);let k=new Uint8Array(S*4),P=()=>{for(let e=0;e<S;e++){let t=Math.max(0,Math.min(255,Math.floor((w[e]*.5+.5)*255))),n=e*4;k[n]=t,k[n+1]=t,k[n+2]=t,k[n+3]=255}n.bindTexture(n.TEXTURE_2D,E),n.texImage2D(n.TEXTURE_2D,0,n.RGBA,_,_,0,n.RGBA,n.UNSIGNED_BYTE,k)},F=(e,t,n,r)=>{let i=e*(_-1),a=t*(_-1),o=(0,l.clamp)(r,2,12);for(let e=-o-1;e<=o+1;e++)for(let t=-o-1;t<=o+1;t++){let r=Math.round(i+t),s=Math.round(a+e);if(r<=0||r>=_-1||s<=0||s>=_-1)continue;let c=Math.sqrt(t*t+e*e),l=Math.exp(-c*c*.55)*-.35,u=Math.exp(-((c-o*.55)**2)*.9);w[s*_+r]+=n*(l+u*1.1)}},I=(e,t)=>{let n=(0,l.clamp)(e,.9,.999),r=(0,l.clamp)(t,.3,.7);for(let e=0;e<2;e++){for(let e=1;e<_-1;e++){let t=e*_;for(let e=1;e<_-1;e++){let i=t+e,a=w[i-1]+w[i+1]+w[i-_]+w[i+_];T[i]=(a*r-C[i])*n,T[i]>1.5?T[i]=1.5:T[i]<-1.5&&(T[i]=-1.5)}}let e=C;C=w,w=T,T=e,T.fill(0)}},L=t=>{let f=N.current;n.viewport(0,0,e.width,e.height),n.useProgram(r),n.bindBuffer(n.ARRAY_BUFFER,i),n.enableVertexAttribArray(a),n.vertexAttribPointer(a,2,n.FLOAT,!1,0,0),n.activeTexture(n.TEXTURE0),n.bindTexture(n.TEXTURE_2D,E),n.uniform1i(m,0),n.uniform1f(o,t),n.uniform2f(s,e.width,e.height),n.uniform3f(c,f.tint[0],f.tint[1],f.tint[2]),n.uniform3f(u,f.from[0],f.from[1],f.from[2]),n.uniform3f(d,f.to[0],f.to[1],f.to[2]),n.uniform2f(h,_,_),n.uniform1f(v,(0,l.clamp)(f.waveAmplitude,0,2)),n.uniform1f(y,(0,l.clamp)(f.waveSpeed,0,3)),n.uniform1f(b,(0,l.clamp)(f.shimmer,0,2)),n.uniform1f(x,(0,l.clamp)(f.reflection,0,1)),n.drawArrays(n.TRIANGLE_STRIP,0,4)};P();let R=document.hidden,z=(0,l.prefersReducedMotion)(),B=(0,l.bindVisibilityPause)(e=>{R=e}),V=(0,l.bindPrefersReducedMotion)(e=>{z=e});if(z)return L(0),()=>{B(),V(),n.deleteTexture(E),n.deleteBuffer(i),n.deleteProgram(r)};let H=performance.now(),U=e=>{if(j.current=requestAnimationFrame(U),R||z)return;let t=N.current;if(M.current){let e=M.current,n=(0,l.clamp)(e.strength,0,3),r=t.rippleRadius;F(e.x,e.y,n,r),F(e.x+.004,e.y-.003,n*.35,r),M.current=null}I(t.damping,t.spread),P(),L((e-H)/1e3)};return j.current=requestAnimationFrame(U),()=>{cancelAnimationFrame(j.current),B(),V(),n.deleteTexture(E),n.deleteBuffer(i),n.deleteProgram(r)}},[O,D]),(0,u.jsxs)(`div`,{ref:E,className:d.rippleWater,style:k,children:[(0,u.jsx)(`canvas`,{ref:A,className:d.canvas,style:{width:D,height:O,cursor:C?`pointer`:`default`},role:`img`,"aria-label":T||`涟漪水面`}),w?(0,u.jsx)(`span`,{className:d.hint,"aria-hidden":!0,children:T}):null]})};exports.RippleWater=y,exports.default=y;
package/dist/index.js CHANGED
@@ -1,11 +1,11 @@
1
1
  import { useCallback as e, useEffect as t, useRef as n } from "react";
2
- import { bindVisibilityPause as r, clamp as i } from "@cos-design/shared";
3
- import { jsx as a, jsxs as o } from "react/jsx-runtime";
4
- import './index.css';var s = {
2
+ import { bindPrefersReducedMotion as r, bindVisibilityPause as i, clamp as a, prefersReducedMotion as o, useCanvasBox as s } from "@cos-design/shared";
3
+ import { jsx as c, jsxs as l } from "react/jsx-runtime";
4
+ import './index.css';var u = {
5
5
  rippleWater: "cos-rippleWater-wsinI",
6
6
  canvas: "cos-canvas-XOdSF",
7
7
  hint: "cos-hint-0JH5D"
8
- }, c = "\nattribute vec2 a_pos;\nvarying vec2 v_uv;\nvoid main() {\n v_uv = a_pos * 0.5 + 0.5;\n gl_Position = vec4(a_pos, 0.0, 1.0);\n}\n", l = "\nprecision highp float;\n\nuniform float u_time;\nuniform vec2 u_res;\nuniform vec3 u_tint;\nuniform vec3 u_from;\nuniform vec3 u_to;\nuniform sampler2D u_height;\nuniform vec2 u_sim;\nuniform float u_waveAmp;\nuniform float u_waveSpeed;\nuniform float u_shimmer;\nuniform float u_reflection;\n\nvarying vec2 v_uv;\n\nfloat hash(vec2 p) {\n return fract(sin(dot(p, vec2(127.1, 311.7))) * 43758.5453);\n}\n\nfloat ambientH(vec2 p, float t) {\n float h = 0.0;\n h += sin(p.x * 3.2 + t * 1.3) * cos(p.y * 2.4 - t * 0.9) * 0.45;\n h += sin(p.x * 6.8 - t * 1.7 + p.y * 1.1) * 0.22;\n h += sin(p.x * 12.0 + p.y * 9.0 + t * 2.4) * 0.08;\n h += sin(p.x * 1.4 + p.y * 1.8 + t * 0.55) * 0.35;\n return h;\n}\n\nfloat sampleHeight(vec2 uv) {\n float rip = texture2D(u_height, uv).r * 2.0 - 1.0;\n vec2 p = uv * vec2(u_res.x / u_res.y, 1.0) * 2.8;\n float amb = ambientH(p, u_time * u_waveSpeed) * 0.035 * u_waveAmp;\n return rip * 0.55 + amb;\n}\n\nvec3 calcNormal(vec2 uv) {\n vec2 e = vec2(1.5 / u_sim.x, 1.5 / u_sim.y);\n float hL = sampleHeight(uv - vec2(e.x, 0.0));\n float hR = sampleHeight(uv + vec2(e.x, 0.0));\n float hD = sampleHeight(uv - vec2(0.0, e.y));\n float hU = sampleHeight(uv + vec2(0.0, e.y));\n return normalize(vec3((hL - hR) * 14.0, (hD - hU) * 14.0, 1.0));\n}\n\nvoid main() {\n vec2 uv = v_uv;\n vec3 n = calcNormal(uv);\n float h = sampleHeight(uv);\n\n vec3 V = normalize(vec3(0.0, 0.25, 1.0));\n vec3 L = normalize(vec3(0.45, 0.75, 0.55));\n\n float ndotl = max(dot(n, L), 0.0);\n float fresnel = pow(1.0 - max(dot(n, V), 0.0), 3.2);\n\n float g = clamp((uv.x + (1.0 - uv.y)) * 0.5, 0.0, 1.0);\n vec3 water = mix(u_from, u_to, g);\n water = mix(water, u_from, clamp(h * 1.8 + ndotl * 0.12, 0.0, 0.28));\n water *= 0.92 + n.y * 0.1;\n\n vec3 sky = mix(u_from * 1.15, vec3(0.85, 0.92, 1.0), 0.45);\n vec3 reflectCol = mix(sky, vec3(0.9, 0.95, 1.0), pow(max(n.y, 0.0), 2.0));\n water = mix(water, reflectCol, fresnel * u_reflection);\n\n vec3 H = normalize(L + V);\n float spec = pow(max(dot(n, H), 0.0), 180.0);\n float glitter = pow(max(dot(n, H), 0.0), 48.0);\n float sparkThresh = step(0.992, glitter) * glitter;\n vec3 sparkle = u_tint * (spec * 1.8 + sparkThresh * 2.5) * u_shimmer\n + vec3(1.0) * sparkThresh * 0.8 * u_shimmer;\n\n float softSpec = pow(max(dot(n, H), 0.0), 16.0) * 0.22 * u_shimmer;\n water += u_tint * softSpec + sparkle;\n\n float crest = smoothstep(0.02, 0.12, abs(h)) * fresnel;\n water += mix(u_tint, vec3(1.0), 0.4) * crest * 0.35;\n\n float vig = smoothstep(1.15, 0.35, length((uv - 0.5) * vec2(1.1, 1.0)));\n water *= 0.88 + 0.12 * vig;\n water += (hash(uv * u_res + u_time) - 0.5) * 0.015;\n\n gl_FragColor = vec4(water, 1.0);\n}\n", u = (e) => {
8
+ }, d = "\nattribute vec2 a_pos;\nvarying vec2 v_uv;\nvoid main() {\n v_uv = a_pos * 0.5 + 0.5;\n gl_Position = vec4(a_pos, 0.0, 1.0);\n}\n", f = "\nprecision highp float;\n\nuniform float u_time;\nuniform vec2 u_res;\nuniform vec3 u_tint;\nuniform vec3 u_from;\nuniform vec3 u_to;\nuniform sampler2D u_height;\nuniform vec2 u_sim;\nuniform float u_waveAmp;\nuniform float u_waveSpeed;\nuniform float u_shimmer;\nuniform float u_reflection;\n\nvarying vec2 v_uv;\n\nfloat hash(vec2 p) {\n return fract(sin(dot(p, vec2(127.1, 311.7))) * 43758.5453);\n}\n\nfloat ambientH(vec2 p, float t) {\n float h = 0.0;\n h += sin(p.x * 3.2 + t * 1.3) * cos(p.y * 2.4 - t * 0.9) * 0.45;\n h += sin(p.x * 6.8 - t * 1.7 + p.y * 1.1) * 0.22;\n h += sin(p.x * 12.0 + p.y * 9.0 + t * 2.4) * 0.08;\n h += sin(p.x * 1.4 + p.y * 1.8 + t * 0.55) * 0.35;\n return h;\n}\n\nfloat sampleHeight(vec2 uv) {\n float rip = texture2D(u_height, uv).r * 2.0 - 1.0;\n vec2 p = uv * vec2(u_res.x / u_res.y, 1.0) * 2.8;\n float amb = ambientH(p, u_time * u_waveSpeed) * 0.035 * u_waveAmp;\n return rip * 0.55 + amb;\n}\n\nvec3 calcNormal(vec2 uv) {\n vec2 e = vec2(1.5 / u_sim.x, 1.5 / u_sim.y);\n float hL = sampleHeight(uv - vec2(e.x, 0.0));\n float hR = sampleHeight(uv + vec2(e.x, 0.0));\n float hD = sampleHeight(uv - vec2(0.0, e.y));\n float hU = sampleHeight(uv + vec2(0.0, e.y));\n return normalize(vec3((hL - hR) * 14.0, (hD - hU) * 14.0, 1.0));\n}\n\nvoid main() {\n vec2 uv = v_uv;\n vec3 n = calcNormal(uv);\n float h = sampleHeight(uv);\n\n vec3 V = normalize(vec3(0.0, 0.25, 1.0));\n vec3 L = normalize(vec3(0.45, 0.75, 0.55));\n\n float ndotl = max(dot(n, L), 0.0);\n float fresnel = pow(1.0 - max(dot(n, V), 0.0), 3.2);\n\n float g = clamp((uv.x + (1.0 - uv.y)) * 0.5, 0.0, 1.0);\n vec3 water = mix(u_from, u_to, g);\n water = mix(water, u_from, clamp(h * 1.8 + ndotl * 0.12, 0.0, 0.28));\n water *= 0.92 + n.y * 0.1;\n\n vec3 sky = mix(u_from * 1.15, vec3(0.85, 0.92, 1.0), 0.45);\n vec3 reflectCol = mix(sky, vec3(0.9, 0.95, 1.0), pow(max(n.y, 0.0), 2.0));\n water = mix(water, reflectCol, fresnel * u_reflection);\n\n vec3 H = normalize(L + V);\n float spec = pow(max(dot(n, H), 0.0), 180.0);\n float glitter = pow(max(dot(n, H), 0.0), 48.0);\n float sparkThresh = step(0.992, glitter) * glitter;\n vec3 sparkle = u_tint * (spec * 1.8 + sparkThresh * 2.5) * u_shimmer\n + vec3(1.0) * sparkThresh * 0.8 * u_shimmer;\n\n float softSpec = pow(max(dot(n, H), 0.0), 16.0) * 0.22 * u_shimmer;\n water += u_tint * softSpec + sparkle;\n\n float crest = smoothstep(0.02, 0.12, abs(h)) * fresnel;\n water += mix(u_tint, vec3(1.0), 0.4) * crest * 0.35;\n\n float vig = smoothstep(1.15, 0.35, length((uv - 0.5) * vec2(1.1, 1.0)));\n water *= 0.88 + 0.12 * vig;\n water += (hash(uv * u_res + u_time) - 0.5) * 0.015;\n\n gl_FragColor = vec4(water, 1.0);\n}\n", p = (e) => {
9
9
  let t = e.replace("#", ""), n = t.length === 3 ? t.split("").map((e) => e + e).join("") : t, r = Number.parseInt(n, 16);
10
10
  return Number.isNaN(r) ? [
11
11
  .22,
@@ -16,18 +16,18 @@ import './index.css';var s = {
16
16
  (r >> 8 & 255) / 255,
17
17
  (r & 255) / 255
18
18
  ];
19
- }, d = (e, t, n) => {
19
+ }, m = (e, t, n) => {
20
20
  let r = e.createShader(t);
21
21
  return r ? (e.shaderSource(r, n), e.compileShader(r), e.getShaderParameter(r, e.COMPILE_STATUS) ? r : (e.deleteShader(r), null)) : null;
22
- }, f = (e, t, n) => {
23
- let r = d(e, e.VERTEX_SHADER, t), i = d(e, e.FRAGMENT_SHADER, n);
22
+ }, h = (e, t, n) => {
23
+ let r = m(e, e.VERTEX_SHADER, t), i = m(e, e.FRAGMENT_SHADER, n);
24
24
  if (!r || !i) return null;
25
25
  let a = e.createProgram();
26
26
  return a ? (e.attachShader(a, r), e.attachShader(a, i), e.linkProgram(a), e.deleteShader(r), e.deleteShader(i), e.getProgramParameter(a, e.LINK_STATUS) ? a : (e.deleteProgram(a), null)) : null;
27
- }, p = 192, m = (e) => ({
28
- from: u(e.fromColor),
29
- to: u(e.toColor),
30
- tint: u(e.color),
27
+ }, g = 192, _ = (e) => ({
28
+ from: p(e.fromColor),
29
+ to: p(e.toColor),
30
+ tint: p(e.color),
31
31
  waveAmplitude: e.waveAmplitude,
32
32
  waveSpeed: e.waveSpeed,
33
33
  shimmer: e.shimmer,
@@ -37,41 +37,43 @@ import './index.css';var s = {
37
37
  damping: e.damping,
38
38
  spread: e.spread,
39
39
  interactive: e.interactive
40
- }), h = ({ width: u = 800, height: d = 500, fromColor: h = "#52ade3", toColor: g = "#013565", color: _ = "#a8d8f5", waveAmplitude: v = 1, waveSpeed: y = 1, shimmer: b = 1, reflection: x = .38, rippleStrength: S = 1, rippleRadius: C = 6, damping: w = .985, spread: T = .5, interactive: E = !0, showHint: D = !0, hint: O = "点击水面产生涟漪" }) => {
41
- let k = n(null), A = n(0), j = n(null), M = n(m({
42
- fromColor: h,
43
- toColor: g,
44
- color: _,
45
- waveAmplitude: v,
46
- waveSpeed: y,
47
- shimmer: b,
48
- reflection: x,
49
- rippleStrength: S,
50
- rippleRadius: C,
51
- damping: w,
52
- spread: T,
53
- interactive: E
40
+ }), v = ({ width: p, height: m, fill: v = !1, fromColor: y = "#52ade3", toColor: b = "#013565", color: x = "#a8d8f5", waveAmplitude: S = 1, waveSpeed: C = 1, shimmer: w = 1, reflection: T = .38, rippleStrength: E = 1, rippleRadius: D = 6, damping: O = .985, spread: k = .5, interactive: A = !0, showHint: j = !0, hint: M = "点击水面产生涟漪" }) => {
41
+ let { hostRef: N, width: P, height: F, hostStyle: I } = s({
42
+ fill: v,
43
+ width: p,
44
+ height: m,
45
+ defaultWidth: 800,
46
+ defaultHeight: 500
47
+ }), L = n(null), R = n(0), z = n(null), B = n(_({
48
+ fromColor: y,
49
+ toColor: b,
50
+ color: x,
51
+ waveAmplitude: S,
52
+ waveSpeed: C,
53
+ shimmer: w,
54
+ reflection: T,
55
+ rippleStrength: E,
56
+ rippleRadius: D,
57
+ damping: O,
58
+ spread: k,
59
+ interactive: A
54
60
  }));
55
61
  t(() => {
56
- M.current = m({
57
- fromColor: h,
58
- toColor: g,
59
- color: _,
60
- waveAmplitude: v,
61
- waveSpeed: y,
62
- shimmer: b,
63
- reflection: x,
64
- rippleStrength: S,
65
- rippleRadius: C,
66
- damping: w,
67
- spread: T,
68
- interactive: E
62
+ B.current = _({
63
+ fromColor: y,
64
+ toColor: b,
65
+ color: x,
66
+ waveAmplitude: S,
67
+ waveSpeed: C,
68
+ shimmer: w,
69
+ reflection: T,
70
+ rippleStrength: E,
71
+ rippleRadius: D,
72
+ damping: O,
73
+ spread: k,
74
+ interactive: A
69
75
  });
70
76
  }, [
71
- h,
72
- g,
73
- _,
74
- v,
75
77
  y,
76
78
  b,
77
79
  x,
@@ -79,31 +81,35 @@ import './index.css';var s = {
79
81
  C,
80
82
  w,
81
83
  T,
82
- E
84
+ E,
85
+ D,
86
+ O,
87
+ k,
88
+ A
83
89
  ]);
84
- let N = e((e, t) => {
85
- if (!M.current.interactive) return;
86
- let n = k.current;
90
+ let V = e((e, t) => {
91
+ if (!B.current.interactive) return;
92
+ let n = L.current;
87
93
  if (!n) return;
88
94
  let r = n.getBoundingClientRect();
89
- j.current = {
95
+ z.current = {
90
96
  x: (e - r.left) / r.width,
91
97
  y: 1 - (t - r.top) / r.height,
92
- strength: M.current.rippleStrength
98
+ strength: B.current.rippleStrength
93
99
  };
94
100
  }, []);
95
101
  return t(() => {
96
- let e = k.current;
102
+ let e = L.current;
97
103
  if (!e) return;
98
104
  let t = (e) => {
99
- e.pointerType === "mouse" && e.button !== 0 || N(e.clientX, e.clientY);
105
+ e.pointerType === "mouse" && e.button !== 0 || V(e.clientX, e.clientY);
100
106
  };
101
107
  return e.addEventListener("pointerdown", t), () => e.removeEventListener("pointerdown", t);
102
- }, [N]), t(() => {
103
- let e = k.current;
108
+ }, [V]), t(() => {
109
+ let e = L.current;
104
110
  if (!e) return;
105
111
  let t = Math.min(window.devicePixelRatio || 1, 2);
106
- e.width = Math.floor(u * t), e.height = Math.floor(d * t);
112
+ e.width = Math.floor(P * t), e.height = Math.floor(F * t);
107
113
  let n = e.getContext("webgl", {
108
114
  alpha: !1,
109
115
  antialias: !1,
@@ -112,10 +118,10 @@ import './index.css';var s = {
112
118
  premultipliedAlpha: !1
113
119
  });
114
120
  if (!n) return;
115
- let a = f(n, c, l);
116
- if (!a) return;
117
- let o = n.createBuffer();
118
- n.bindBuffer(n.ARRAY_BUFFER, o), n.bufferData(n.ARRAY_BUFFER, new Float32Array([
121
+ let s = h(n, d, f);
122
+ if (!s) return;
123
+ let c = n.createBuffer();
124
+ n.bindBuffer(n.ARRAY_BUFFER, c), n.bufferData(n.ARRAY_BUFFER, new Float32Array([
119
125
  -1,
120
126
  -1,
121
127
  1,
@@ -125,78 +131,80 @@ import './index.css';var s = {
125
131
  1,
126
132
  1
127
133
  ]), n.STATIC_DRAW);
128
- let s = n.getAttribLocation(a, "a_pos"), m = n.getUniformLocation(a, "u_time"), h = n.getUniformLocation(a, "u_res"), g = n.getUniformLocation(a, "u_tint"), _ = n.getUniformLocation(a, "u_from"), v = n.getUniformLocation(a, "u_to"), y = n.getUniformLocation(a, "u_height"), b = n.getUniformLocation(a, "u_sim"), x = n.getUniformLocation(a, "u_waveAmp"), S = n.getUniformLocation(a, "u_waveSpeed"), C = n.getUniformLocation(a, "u_shimmer"), w = n.getUniformLocation(a, "u_reflection"), T = p * p, E = new Float32Array(T), D = new Float32Array(T), O = new Float32Array(T), N = n.createTexture();
129
- n.bindTexture(n.TEXTURE_2D, N), n.texParameteri(n.TEXTURE_2D, n.TEXTURE_MIN_FILTER, n.LINEAR), n.texParameteri(n.TEXTURE_2D, n.TEXTURE_MAG_FILTER, n.LINEAR), n.texParameteri(n.TEXTURE_2D, n.TEXTURE_WRAP_S, n.CLAMP_TO_EDGE), n.texParameteri(n.TEXTURE_2D, n.TEXTURE_WRAP_T, n.CLAMP_TO_EDGE);
130
- let P = new Uint8Array(T * 4), F = () => {
134
+ let l = n.getAttribLocation(s, "a_pos"), u = n.getUniformLocation(s, "u_time"), p = n.getUniformLocation(s, "u_res"), m = n.getUniformLocation(s, "u_tint"), _ = n.getUniformLocation(s, "u_from"), v = n.getUniformLocation(s, "u_to"), y = n.getUniformLocation(s, "u_height"), b = n.getUniformLocation(s, "u_sim"), x = n.getUniformLocation(s, "u_waveAmp"), S = n.getUniformLocation(s, "u_waveSpeed"), C = n.getUniformLocation(s, "u_shimmer"), w = n.getUniformLocation(s, "u_reflection"), T = g * g, E = new Float32Array(T), D = new Float32Array(T), O = new Float32Array(T), k = n.createTexture();
135
+ n.bindTexture(n.TEXTURE_2D, k), n.texParameteri(n.TEXTURE_2D, n.TEXTURE_MIN_FILTER, n.LINEAR), n.texParameteri(n.TEXTURE_2D, n.TEXTURE_MAG_FILTER, n.LINEAR), n.texParameteri(n.TEXTURE_2D, n.TEXTURE_WRAP_S, n.CLAMP_TO_EDGE), n.texParameteri(n.TEXTURE_2D, n.TEXTURE_WRAP_T, n.CLAMP_TO_EDGE);
136
+ let A = new Uint8Array(T * 4), j = () => {
131
137
  for (let e = 0; e < T; e++) {
132
138
  let t = Math.max(0, Math.min(255, Math.floor((D[e] * .5 + .5) * 255))), n = e * 4;
133
- P[n] = t, P[n + 1] = t, P[n + 2] = t, P[n + 3] = 255;
139
+ A[n] = t, A[n + 1] = t, A[n + 2] = t, A[n + 3] = 255;
134
140
  }
135
- n.bindTexture(n.TEXTURE_2D, N), n.texImage2D(n.TEXTURE_2D, 0, n.RGBA, p, p, 0, n.RGBA, n.UNSIGNED_BYTE, P);
136
- }, I = (e, t, n, r) => {
137
- let a = e * (p - 1), o = t * (p - 1), s = i(r, 2, 12);
141
+ n.bindTexture(n.TEXTURE_2D, k), n.texImage2D(n.TEXTURE_2D, 0, n.RGBA, g, g, 0, n.RGBA, n.UNSIGNED_BYTE, A);
142
+ }, M = (e, t, n, r) => {
143
+ let i = e * (g - 1), o = t * (g - 1), s = a(r, 2, 12);
138
144
  for (let e = -s - 1; e <= s + 1; e++) for (let t = -s - 1; t <= s + 1; t++) {
139
- let r = Math.round(a + t), i = Math.round(o + e);
140
- if (r <= 0 || r >= p - 1 || i <= 0 || i >= p - 1) continue;
145
+ let r = Math.round(i + t), a = Math.round(o + e);
146
+ if (r <= 0 || r >= g - 1 || a <= 0 || a >= g - 1) continue;
141
147
  let c = Math.sqrt(t * t + e * e), l = Math.exp(-c * c * .55) * -.35, u = Math.exp(-((c - s * .55) ** 2) * .9);
142
- D[i * p + r] += n * (l + u * 1.1);
148
+ D[a * g + r] += n * (l + u * 1.1);
143
149
  }
144
- }, L = (e, t) => {
145
- let n = i(e, .9, .999), r = i(t, .3, .7);
150
+ }, N = (e, t) => {
151
+ let n = a(e, .9, .999), r = a(t, .3, .7);
146
152
  for (let e = 0; e < 2; e++) {
147
- for (let e = 1; e < p - 1; e++) {
148
- let t = e * p;
149
- for (let e = 1; e < p - 1; e++) {
150
- let i = t + e, a = D[i - 1] + D[i + 1] + D[i - p] + D[i + p];
153
+ for (let e = 1; e < g - 1; e++) {
154
+ let t = e * g;
155
+ for (let e = 1; e < g - 1; e++) {
156
+ let i = t + e, a = D[i - 1] + D[i + 1] + D[i - g] + D[i + g];
151
157
  O[i] = (a * r - E[i]) * n, O[i] > 1.5 ? O[i] = 1.5 : O[i] < -1.5 && (O[i] = -1.5);
152
158
  }
153
159
  }
154
160
  let e = E;
155
161
  E = D, D = O, O = e, O.fill(0);
156
162
  }
157
- }, R = (t) => {
158
- let r = M.current;
159
- n.viewport(0, 0, e.width, e.height), n.useProgram(a), n.bindBuffer(n.ARRAY_BUFFER, o), n.enableVertexAttribArray(s), n.vertexAttribPointer(s, 2, n.FLOAT, !1, 0, 0), n.activeTexture(n.TEXTURE0), n.bindTexture(n.TEXTURE_2D, N), n.uniform1i(y, 0), n.uniform1f(m, t), n.uniform2f(h, e.width, e.height), n.uniform3f(g, r.tint[0], r.tint[1], r.tint[2]), n.uniform3f(_, r.from[0], r.from[1], r.from[2]), n.uniform3f(v, r.to[0], r.to[1], r.to[2]), n.uniform2f(b, p, p), n.uniform1f(x, i(r.waveAmplitude, 0, 2)), n.uniform1f(S, i(r.waveSpeed, 0, 3)), n.uniform1f(C, i(r.shimmer, 0, 2)), n.uniform1f(w, i(r.reflection, 0, 1)), n.drawArrays(n.TRIANGLE_STRIP, 0, 4);
163
+ }, I = (t) => {
164
+ let r = B.current;
165
+ n.viewport(0, 0, e.width, e.height), n.useProgram(s), n.bindBuffer(n.ARRAY_BUFFER, c), n.enableVertexAttribArray(l), n.vertexAttribPointer(l, 2, n.FLOAT, !1, 0, 0), n.activeTexture(n.TEXTURE0), n.bindTexture(n.TEXTURE_2D, k), n.uniform1i(y, 0), n.uniform1f(u, t), n.uniform2f(p, e.width, e.height), n.uniform3f(m, r.tint[0], r.tint[1], r.tint[2]), n.uniform3f(_, r.from[0], r.from[1], r.from[2]), n.uniform3f(v, r.to[0], r.to[1], r.to[2]), n.uniform2f(b, g, g), n.uniform1f(x, a(r.waveAmplitude, 0, 2)), n.uniform1f(S, a(r.waveSpeed, 0, 3)), n.uniform1f(C, a(r.shimmer, 0, 2)), n.uniform1f(w, a(r.reflection, 0, 1)), n.drawArrays(n.TRIANGLE_STRIP, 0, 4);
160
166
  };
161
- if (F(), typeof window < "u" && window.matchMedia("(prefers-reduced-motion: reduce)").matches) return R(0), () => {
162
- n.deleteTexture(N), n.deleteBuffer(o), n.deleteProgram(a);
167
+ j();
168
+ let V = document.hidden, H = o(), U = i((e) => {
169
+ V = e;
170
+ }), W = r((e) => {
171
+ H = e;
172
+ });
173
+ if (H) return I(0), () => {
174
+ U(), W(), n.deleteTexture(k), n.deleteBuffer(c), n.deleteProgram(s);
163
175
  };
164
- let z = document.hidden, B = r((e) => {
165
- z = e;
166
- }), V = performance.now(), H = (e) => {
167
- if (A.current = requestAnimationFrame(H), z) return;
168
- let t = M.current;
169
- if (j.current) {
170
- let e = j.current, n = i(e.strength, 0, 3), r = t.rippleRadius;
171
- I(e.x, e.y, n, r), I(e.x + .004, e.y - .003, n * .35, r), j.current = null;
176
+ let G = performance.now(), K = (e) => {
177
+ if (R.current = requestAnimationFrame(K), V || H) return;
178
+ let t = B.current;
179
+ if (z.current) {
180
+ let e = z.current, n = a(e.strength, 0, 3), r = t.rippleRadius;
181
+ M(e.x, e.y, n, r), M(e.x + .004, e.y - .003, n * .35, r), z.current = null;
172
182
  }
173
- L(t.damping, t.spread), F(), R((e - V) / 1e3);
183
+ N(t.damping, t.spread), j(), I((e - G) / 1e3);
174
184
  };
175
- return A.current = requestAnimationFrame(H), () => {
176
- cancelAnimationFrame(A.current), B(), n.deleteTexture(N), n.deleteBuffer(o), n.deleteProgram(a);
185
+ return R.current = requestAnimationFrame(K), () => {
186
+ cancelAnimationFrame(R.current), U(), W(), n.deleteTexture(k), n.deleteBuffer(c), n.deleteProgram(s);
177
187
  };
178
- }, [d, u]), /* @__PURE__ */ o("div", {
179
- className: s.rippleWater,
180
- style: {
181
- width: u,
182
- height: d
183
- },
184
- children: [/* @__PURE__ */ a("canvas", {
185
- ref: k,
186
- className: s.canvas,
188
+ }, [F, P]), /* @__PURE__ */ l("div", {
189
+ ref: N,
190
+ className: u.rippleWater,
191
+ style: I,
192
+ children: [/* @__PURE__ */ c("canvas", {
193
+ ref: L,
194
+ className: u.canvas,
187
195
  style: {
188
- width: u,
189
- height: d,
190
- cursor: E ? "pointer" : "default"
196
+ width: P,
197
+ height: F,
198
+ cursor: A ? "pointer" : "default"
191
199
  },
192
200
  role: "img",
193
- "aria-label": O || "涟漪水面"
194
- }), D ? /* @__PURE__ */ a("span", {
195
- className: s.hint,
201
+ "aria-label": M || "涟漪水面"
202
+ }), j ? /* @__PURE__ */ c("span", {
203
+ className: u.hint,
196
204
  "aria-hidden": !0,
197
- children: O
205
+ children: M
198
206
  }) : null]
199
207
  });
200
208
  };
201
209
  //#endregion
202
- export { h as RippleWater, h as default };
210
+ export { v as RippleWater, v as default };
@@ -1,3 +1,10 @@
1
- /** 注册 visibilitychange,页面隐藏时暂停动画循环 */
2
- export declare const bindVisibilityPause: (onChange: (paused: boolean) => void) => () => void;
3
- export declare const clamp: (value: number, min: number, max: number) => number;
1
+ export { clamp } from './math';
2
+ export { bindVisibilityPause } from './visibility';
3
+ export { prefersReducedMotion, bindPrefersReducedMotion } from './reduced-motion';
4
+ export { observeElementSize } from './size';
5
+ export type { ElementSize } from './size';
6
+ export { getRelativePointerPosition } from './pointer';
7
+ export type { PointerPosition } from './pointer';
8
+ export type { PhotoItem, PhotoIndexChangeHandler, PhotoFaceChangeHandler } from './photo';
9
+ export { useElementSize, resolveCanvasBoxSize, useCanvasBox } from './use-element-size';
10
+ export type { UseElementSizeOptions, CanvasBoxSizeInput, CanvasBoxSize, UseCanvasBoxOptions, UseCanvasBoxResult } from './use-element-size';
@@ -0,0 +1 @@
1
+ export declare const clamp: (value: number, min: number, max: number) => number;
@@ -0,0 +1,15 @@
1
+ /** 图片预览组件通用照片项 */
2
+ export interface PhotoItem {
3
+ /** 图片地址 */
4
+ src: string;
5
+ /** 图片替代文本 */
6
+ alt?: string;
7
+ /** 照片标题 */
8
+ title?: string;
9
+ /** 照片说明 */
10
+ description?: string;
11
+ }
12
+ /** 线性浏览:当前索引变化(相册 / 胶卷 / 晾绳等) */
13
+ export type PhotoIndexChangeHandler<T = PhotoItem> = (index: number, photo: T) => void;
14
+ /** 环形浏览:正对镜头的面变化(走马灯 / 旋转木马等) */
15
+ export type PhotoFaceChangeHandler<T = PhotoItem> = (index: number, photo?: T) => void;
@@ -0,0 +1,14 @@
1
+ export interface PointerPosition {
2
+ x: number;
3
+ y: number;
4
+ }
5
+ type PointLike = {
6
+ clientX: number;
7
+ clientY: number;
8
+ };
9
+ /** 相对元素左上角的指针坐标(兼容 mouse / touch / pointer) */
10
+ export declare const getRelativePointerPosition: (element: Element, event: PointLike | {
11
+ touches?: ArrayLike<PointLike>;
12
+ changedTouches?: ArrayLike<PointLike>;
13
+ }) => PointerPosition | null;
14
+ export {};
@@ -0,0 +1,4 @@
1
+ /** 当前是否偏好减少动效 */
2
+ export declare const prefersReducedMotion: () => boolean;
3
+ /** 监听 prefers-reduced-motion 变化;返回取消订阅函数 */
4
+ export declare const bindPrefersReducedMotion: (onChange: (reduced: boolean) => void) => () => void;
@@ -0,0 +1,8 @@
1
+ export interface ElementSize {
2
+ width: number;
3
+ height: number;
4
+ }
5
+ /** 观察元素内容尺寸;返回取消订阅函数 */
6
+ export declare const observeElementSize: (element: Element, onChange: (size: ElementSize) => void, options?: {
7
+ box?: ResizeObserverBoxOptions;
8
+ }) => () => void;
@@ -0,0 +1,45 @@
1
+ import { CSSProperties, RefObject } from 'react';
2
+ import { ElementSize } from './size';
3
+ export interface UseElementSizeOptions {
4
+ /** 为 false 时不观察 */
5
+ enabled?: boolean;
6
+ }
7
+ /** 观察元素尺寸(clientWidth / clientHeight) */
8
+ export declare const useElementSize: <T extends Element>(ref: RefObject<T | null>, options?: UseElementSizeOptions) => ElementSize;
9
+ export interface CanvasBoxSizeInput {
10
+ /** 为 true 时跟随父容器尺寸(需父级有明确高度) */
11
+ fill?: boolean;
12
+ width?: number;
13
+ height?: number;
14
+ defaultWidth: number;
15
+ defaultHeight: number;
16
+ measured: ElementSize;
17
+ }
18
+ export interface CanvasBoxSize {
19
+ width: number;
20
+ height: number;
21
+ /** 是否处于 fill 模式且尚未量到有效尺寸 */
22
+ pending: boolean;
23
+ }
24
+ /** 根据 fill / 显式宽高 / 测量结果解析画布逻辑尺寸 */
25
+ export declare const resolveCanvasBoxSize: ({ fill, width, height, defaultWidth, defaultHeight, measured }: CanvasBoxSizeInput) => CanvasBoxSize;
26
+ export interface UseCanvasBoxOptions {
27
+ /** 为 true 时铺满父容器(父级需有明确高度) */
28
+ fill?: boolean;
29
+ width?: number;
30
+ height?: number;
31
+ defaultWidth: number;
32
+ defaultHeight: number;
33
+ }
34
+ export interface UseCanvasBoxResult {
35
+ hostRef: RefObject<HTMLDivElement | null>;
36
+ width: number;
37
+ height: number;
38
+ /** 挂到宿主容器的样式(fill 时为 100%×100%) */
39
+ hostStyle: CSSProperties;
40
+ fill: boolean;
41
+ /** 是否处于 fill 模式且尚未量到有效尺寸 */
42
+ pending: boolean;
43
+ }
44
+ /** 画布/效果宿主尺寸:fill 时跟随父容器,否则用显式宽高或默认值 */
45
+ export declare const useCanvasBox: ({ fill, width: widthProp, height: heightProp, defaultWidth, defaultHeight }: UseCanvasBoxOptions) => UseCanvasBoxResult;
@@ -0,0 +1,2 @@
1
+ /** 注册 visibilitychange,页面隐藏时暂停动画循环 */
2
+ export declare const bindVisibilityPause: (onChange: (paused: boolean) => void) => () => void;
@@ -2,6 +2,8 @@ import { default as React } from 'react';
2
2
  export interface RippleWaterProps {
3
3
  width?: number;
4
4
  height?: number;
5
+ /** 为 true 时铺满父容器(父级需有明确高度) */
6
+ fill?: boolean;
5
7
  /** 水面渐变浅端(左上) */
6
8
  fromColor?: string;
7
9
  /** 水面渐变深端(右下) */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cos-design/ripple-water",
3
- "version": "3.5.4",
3
+ "version": "3.5.6",
4
4
  "description": "RippleWater component from cos-design",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -52,6 +52,6 @@
52
52
  "registry": "https://registry.npmjs.org"
53
53
  },
54
54
  "dependencies": {
55
- "@cos-design/shared": "3.5.3"
55
+ "@cos-design/shared": "3.5.6"
56
56
  }
57
57
  }