@liiift-studio/magnettype 1.1.4 → 1.1.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/README.md +4 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +34 -0
- package/dist/index.js +382 -285
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -86,6 +86,9 @@ import { MagnetBlock } from '@liiift-studio/magnettype'
|
|
|
86
86
|
| `spreadRadius` | — | Pixel distance from the cursor within which each **character's** weight rises to `maxWeight`. When omitted, per-character splitting is skipped |
|
|
87
87
|
| `proximityRadius` | — | Pixel distance from the element **edge** that gates the effect. Without `spreadRadius`, drives a whole-element weight ramp. With `spreadRadius`, acts as an outer gate — the spread only fires while the cursor is within this distance |
|
|
88
88
|
| `fixedAxes` | `{}` | Additional axis values to hold constant in every `font-variation-settings` string (e.g. `{ opsz: 144 }`) |
|
|
89
|
+
| `stabilizeLayout` | `true` | Apply compensating letter-spacing to prevent text reflow as weight rises. Measures the element's width at rest and peak weight via an off-screen probe and applies proportional negative letter-spacing per character. Disable if you want natural bold spacing, or if your font expands glyphs very unevenly (compensation is a per-element average) |
|
|
90
|
+
| `cachePositions` | `true` | Cache character centre positions in page-relative coordinates, eliminating `getBoundingClientRect` calls on every `mousemove`. Rebuilt on resize and after fonts load. Disable if the element is inside a custom scroll container (`overflow: scroll` on a non-window element) |
|
|
91
|
+
| `rafThrottle` | `true` | Throttle proximity updates to one per animation frame (≈ 60 fps on most displays). Disable for lowest input latency on 120 Hz displays or very fast-moving effects |
|
|
89
92
|
| `className` | — | Forwarded to the root element |
|
|
90
93
|
| `style` | — | Merged with the root element's style; `fontVariationSettings` at `minWeight` is set as the base |
|
|
91
94
|
|
|
@@ -244,4 +247,4 @@ The package itself has zero runtime dependencies. Do not remove this entry.
|
|
|
244
247
|
|
|
245
248
|
---
|
|
246
249
|
|
|
247
|
-
Current version: 1.1.
|
|
250
|
+
Current version: 1.1.6
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("react"),G=require("react/jsx-runtime"),tt={i:3,l:3,1:3,I:3,r:2,n:1,m:1,0:2,O:2,o:1,b:1,d:1,p:1,q:1,c:1,e:1},D={word:"mt-word",char:"mt-char",probe:"mt-probe"},j={axes:{wght:[300,500]},radius:120,falloff:"quadratic",magnetMode:"attract",wdthBoost:6,scope:"document"};function W(e,r=[]){return e.nodeType===Node.TEXT_NODE?r.push(e):e.childNodes.forEach(o=>W(o,r)),r}function K(e,r,o){if(!e||e==="normal")return`"${r}" ${o}`;const y=new RegExp(`(["'])${r}\\1\\s+[\\d.eE+-]+`),a=`"${r}" ${o}`;return y.test(e)?e.replace(y,a):`${e}, ${a}`}function et(e,r){let o=e;for(const[y,a]of Object.entries(r))o=K(o,y,a);return o}function nt(e,r,o){if(r.opacity!==void 0){const[y,a]=r.opacity;e.style.opacity=String(y+(a-y)*o)}r.italic===!0&&(e.style.fontStyle=o>.5?"italic":"")}function U(e,r){r.opacity!==void 0&&(e.style.opacity=String(r.opacity[0])),r.italic===!0&&(e.style.fontStyle="")}function rt(e){const r=e.cloneNode(!0),o=r.querySelectorAll(`.${D.word}, .${D.char}`);return Array.from(o).reverse().forEach(a=>{const l=a.parentNode;if(l){for(;a.firstChild;)l.insertBefore(a.firstChild,a);l.removeChild(a)}}),r.innerHTML}function lt(e,r){e.innerHTML=r}function ot(e,r,o={}){if(typeof window>"u")return()=>{};if(window.matchMedia("(prefers-reduced-motion: reduce)").matches)return e.innerHTML=r,()=>{};const y=o.wdthBoost??j.wdthBoost,a=o.radius??j.radius,l=o.falloff??j.falloff,x=o.scope??j.scope,E=o.props,f=o.transitionMs??0,w=window.scrollY;e.innerHTML=r;const L=getComputedStyle(e).fontVariationSettings,Y=L.match(/"wdth"\s+([\d.eE+-]+)/),T=Y?parseFloat(Y[1]):100,F=W(e),p=[];for(const s of F){const t=s.textContent??"";if(!t||!t.split("").some(n=>n in tt))continue;const c=document.createDocumentFragment();for(const n of t){const M=tt[n];if(M===void 0){const m=c.lastChild;m&&m.nodeType===Node.TEXT_NODE?m.textContent+=n:c.appendChild(document.createTextNode(n))}else{const m=document.createElement("span");m.className=D.char,m.style.fontVariationSettings=K(L,"wdth",T),m.textContent=n,c.appendChild(m),p.push({span:m,riskLevel:M})}}s.parentNode.replaceChild(c,s)}if(requestAnimationFrame(()=>{typeof window<"u"&&Math.abs(window.scrollY-w)>2&&window.scrollTo({top:w,behavior:"instant"})}),p.length===0)return()=>{};E&&p.forEach(({span:s})=>U(s,E));let g=-9999,V=-9999,S=!1,u=0,b=!0,N=null;function h(){if(!b)return;if(!S){p.forEach(({span:t})=>{f>0&&(t.style.transition=`font-variation-settings ${f}ms ease`),t.style.fontVariationSettings=K(L,"wdth",T),E&&U(t,E)}),f>0&&(N!==null&&clearTimeout(N),N=setTimeout(()=>{p.forEach(({span:t})=>{t.style.transition=""}),N=null},f)),u=0;return}const s=p.map(({span:t})=>t.getBoundingClientRect());p.forEach(({span:t,riskLevel:i},c)=>{t.style.transition="";const n=s[c],M=n.left+n.width/2,m=n.top+n.height/2,B=Math.sqrt((g-M)**2+(V-m)**2),A=Math.max(0,1-B/a),q=l==="quadratic"?A*A:A,H=y*(i/3)*q;t.style.fontVariationSettings=K(L,"wdth",T+H),E&&nt(t,E,q)}),u=requestAnimationFrame(h)}function X(s){g=s.clientX,V=s.clientY,S||(S=!0),u===0&&(u=requestAnimationFrame(h))}function R(){S=!1,u===0&&(u=requestAnimationFrame(h))}function k(s){s.touches.length!==0&&(g=s.touches[0].clientX,V=s.touches[0].clientY,S||(S=!0),u===0&&(u=requestAnimationFrame(h)))}function $(){S=!1,u===0&&(u=requestAnimationFrame(h))}const v=x==="document"?document:e;return v.addEventListener("mousemove",X),v.addEventListener("mouseleave",R),v.addEventListener("touchmove",k,{passive:!0}),v.addEventListener("touchend",$),()=>{b=!1,cancelAnimationFrame(u),N!==null&&clearTimeout(N),v.removeEventListener("mousemove",X),v.removeEventListener("mouseleave",R),v.removeEventListener("touchmove",k),v.removeEventListener("touchend",$),e.innerHTML=r}}function st(e,r,o={}){if(typeof window>"u")return()=>{};if(window.matchMedia("(prefers-reduced-motion: reduce)").matches)return e.innerHTML=r,()=>{};const y=o.axes??j.axes,a=o.radius??j.radius,l=o.falloff??j.falloff,x=o.magnetMode??j.magnetMode,E=o.scope??j.scope,f=o.props,w=o.transitionMs??0,L=window.scrollY;e.innerHTML=r;const Y=W(e),T=[];for(const s of Y){const t=s.textContent??"";if(!t.trim())continue;const i=t.split(/(\S+)/),c=document.createDocumentFragment();for(let n=0;n<i.length;n+=2){const M=i[n],m=i[n+1];if(!m)continue;const A=i[n+3]===void 0?i[n+2]??"":"",q=document.createElement("span");q.className=D.word,q.textContent=M+m+A,c.appendChild(q),T.push(q)}s.parentNode.replaceChild(c,s)}if(requestAnimationFrame(()=>{typeof window<"u"&&Math.abs(window.scrollY-L)>2&&window.scrollTo({top:L,behavior:"instant"})}),T.length===0)return()=>{};const F=getComputedStyle(e).fontVariationSettings,p=et(F,Object.fromEntries(Object.entries(y).map(([s,[t]])=>[s,t])));T.forEach(s=>{s.style.fontVariationSettings=p,f&&U(s,f)});let g=-9999,V=-9999,S=!1,u=0,b=!0,N=null;function h(){if(!b)return;if(!S){T.forEach(t=>{w>0&&(t.style.transition=`font-variation-settings ${w}ms ease`),t.style.fontVariationSettings=p,f&&U(t,f)}),w>0&&(N!==null&&clearTimeout(N),N=setTimeout(()=>{T.forEach(t=>{t.style.transition=""}),N=null},w)),u=0;return}const s=T.map(t=>t.getBoundingClientRect());T.forEach((t,i)=>{t.style.transition="";const c=s[i],n=c.left+c.width/2,M=c.top+c.height/2,m=Math.sqrt((g-n)**2+(V-M)**2),B=Math.max(0,1-m/a),A=l==="quadratic"?B*B:B,q=x==="repel"?1-A:A,H={};for(const _ of Object.keys(y)){const[J,O]=y[_]??[300,500];H[_]=J+(O-J)*q}t.style.fontVariationSettings=et(F,H),f&&nt(t,f,A)}),u=requestAnimationFrame(h)}function X(s){g=s.clientX,V=s.clientY,S||(S=!0),u===0&&(u=requestAnimationFrame(h))}function R(){S=!1,u===0&&(u=requestAnimationFrame(h))}function k(s){s.touches.length!==0&&(g=s.touches[0].clientX,V=s.touches[0].clientY,S||(S=!0),u===0&&(u=requestAnimationFrame(h)))}function $(){S=!1,u===0&&(u=requestAnimationFrame(h))}const v=E==="document"?document:e;return v.addEventListener("mousemove",X),v.addEventListener("mouseleave",R),v.addEventListener("touchmove",k,{passive:!0}),v.addEventListener("touchend",$),()=>{b=!1,cancelAnimationFrame(u),N!==null&&clearTimeout(N),v.removeEventListener("mousemove",X),v.removeEventListener("mouseleave",R),v.removeEventListener("touchmove",k),v.removeEventListener("touchend",$),e.innerHTML=r}}function ct(e){const r=d.useRef(null),o=d.useRef(null),y=d.useRef(e);y.current=e;const a=d.useRef(null),l=e.mode??"field",{axes:x,radius:E,falloff:f,magnetMode:w,wdthBoost:L,scope:Y}=e,T=x?JSON.stringify(x):void 0,F=e.props?JSON.stringify(e.props):void 0,p=d.useCallback(()=>{const g=r.current;if(!g)return;o.current===null&&(o.current=rt(g)),a.current&&(a.current(),a.current=null),(y.current.mode??"field")==="field"?a.current=st(g,o.current,y.current):a.current=ot(g,o.current,y.current)},[l,T,E,f,w,L,Y,F]);return d.useLayoutEffect(()=>(p(),()=>{a.current&&(a.current(),a.current=null)}),[p]),d.useEffect(()=>{document.fonts.ready.then(p)},[p]),r}const it=d.forwardRef(function({children:r,as:o="p",className:y,style:a,...l},x){const E=ct(l),f=d.useCallback(w=>{E.current=w,typeof x=="function"?x(w):x&&(x.current=w)},[x]);return G.jsx(o,{ref:f,className:y,style:a,children:r})});it.displayName="MagnetTypeText";const ut=d.forwardRef(function({children:r,as:o="p",className:y,style:a,minWeight:l=300,maxWeight:x=600,proximityRadius:E,spreadRadius:f,fixedAxes:w={},cachePositions:L=!0,rafThrottle:Y=!0},T){const F=d.useRef(null),p=d.useRef(null),g=d.useRef([]),V=d.useRef([]),S=d.useRef(null),u=d.useRef(!1),b=d.useRef(null),N=d.useCallback(t=>{F.current=t,typeof T=="function"?T(t):T&&(T.current=t)},[T]);function h(t){const i=[`'wght' ${t.toFixed(0)}`];for(const[c,n]of Object.entries(w))i.push(`'${c}' ${n}`);return i.join(", ")}function X(){const t=F.current;if(!t)return;const i=window.scrollX,c=window.scrollY,n=t.getBoundingClientRect();S.current={top:n.top+c,left:n.left+i,right:n.right+i,bottom:n.bottom+c},V.current=g.current.map(M=>{if(!M)return{cx:0,cy:0};const m=M.getBoundingClientRect();return{cx:(m.left+m.right)/2+i,cy:(m.top+m.bottom)/2+c}}),u.current=!0}function R(t,i){const c=F.current;if(!c)return;L&&!u.current&&X();let n,M,m,B,A,q;if(L&&S.current)A=t+window.scrollX,q=i+window.scrollY,{top:n,left:M,right:m,bottom:B}=S.current;else{const O=c.getBoundingClientRect();A=t,q=i,n=O.top,M=O.left,m=O.right,B=O.bottom}const H=Math.max(M-A,0,A-m),_=Math.max(n-q,0,q-B),J=Math.sqrt(H*H+_*_);if(E!==void 0&&!f){const C=1-(1-Math.max(0,1-J/E))**2;c.style.fontVariationSettings=h(l+(x-l)*C);return}if(f){if(E!==void 0&&J>E){c.style.fontVariationSettings=h(l);for(const C of g.current)C&&(C.style.fontVariationSettings=h(l));return}if(J>f){for(const C of g.current)C&&(C.style.fontVariationSettings=h(l));return}const O=g.current;if(L&&V.current.length===O.length)for(let C=0;C<O.length;C++){const I=O[C];if(!I)continue;const{cx:z,cy:P}=V.current[C],Q=Math.sqrt((A-z)**2+(q-P)**2),Z=1-(1-Math.max(0,1-Q/f))**2;I.style.fontVariationSettings=h(l+(x-l)*Z)}else for(const C of O){if(!C)continue;const I=C.getBoundingClientRect(),z=(I.left+I.right)/2,P=(I.top+I.bottom)/2,Q=Math.sqrt((t-z)**2+(i-P)**2),Z=1-(1-Math.max(0,1-Q/f))**2;C.style.fontVariationSettings=h(l+(x-l)*Z)}}}const k=d.useCallback(t=>{p.current={x:t.clientX,y:t.clientY},Y?b.current===null&&(b.current=requestAnimationFrame(()=>{b.current=null,p.current&&R(p.current.x,p.current.y)})):R(t.clientX,t.clientY)},[l,x,E,f,L,Y,JSON.stringify(w)]),$=d.useCallback(()=>{p.current&&R(p.current.x,p.current.y)},[l,x,E,f,L,JSON.stringify(w)]),v=d.useCallback(()=>{p.current=null,b.current!==null&&(cancelAnimationFrame(b.current),b.current=null);const t=F.current;t&&(t.style.fontVariationSettings=h(l));for(const i of g.current)i&&(i.style.fontVariationSettings=h(l))},[l,JSON.stringify(w)]);d.useEffect(()=>(window.addEventListener("mousemove",k,{passive:!0}),window.addEventListener("scroll",$,{passive:!0,capture:!0}),document.documentElement.addEventListener("mouseleave",v),()=>{window.removeEventListener("mousemove",k),window.removeEventListener("scroll",$,{capture:!0}),document.documentElement.removeEventListener("mouseleave",v),b.current!==null&&(cancelAnimationFrame(b.current),b.current=null)}),[k,$,v]),d.useEffect(()=>{if(!L||!f)return;u.current=!1;const t=F.current;if(!t)return;const i=new ResizeObserver(()=>{u.current=!1});return i.observe(t),document.fonts.ready.then(()=>{u.current=!1}),()=>i.disconnect()},[L,f]),d.useEffect(()=>{u.current=!1},[r,f]);const s=d.useMemo(()=>{if(!f)return r;g.current=[];let t=0;function i(c){if(typeof c=="string")return[...c].map(n=>{if(/\s/.test(n))return n;const M=t++;return G.jsx("span",{ref:m=>{g.current[M]=m},style:{fontVariationSettings:h(l)},children:n},M)});if(Array.isArray(c))return c.map((n,M)=>G.jsx(d.Fragment,{children:i(n)},M));if(d.isValidElement(c)){const n=c;if(n.props.children!==void 0)return d.cloneElement(n,{},i(n.props.children))}return c}return i(r)},[r,f,l,JSON.stringify(w)]);return G.jsx(o,{ref:N,className:y,style:{fontVariationSettings:h(l),...a},children:s})});ut.displayName="MagnetBlock";exports.MAGNET_TYPE_CLASSES=D;exports.MagnetBlock=ut;exports.MagnetTypeText=it;exports.applyMagnetType=ot;exports.getCleanHTML=rt;exports.removeMagnetType=lt;exports.startMagnetType=st;exports.useMagnetType=ct;
|
|
1
|
+
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const h=require("react"),W=require("react/jsx-runtime"),rt={i:3,l:3,1:3,I:3,r:2,n:1,m:1,0:2,O:2,o:1,b:1,d:1,p:1,q:1,c:1,e:1},z={word:"mt-word",char:"mt-char",probe:"mt-probe"},K={axes:{wght:[300,500]},radius:120,falloff:"quadratic",magnetMode:"attract",wdthBoost:6,scope:"document"};function ot(t,n=[]){return t.nodeType===Node.TEXT_NODE?n.push(t):t.childNodes.forEach(o=>ot(o,n)),n}function tt(t,n,o){if(!t||t==="normal")return`"${n}" ${o}`;const E=new RegExp(`(["'])${n}\\1\\s+[\\d.eE+-]+`),y=`"${n}" ${o}`;return E.test(t)?t.replace(E,y):`${t}, ${y}`}function nt(t,n){let o=t;for(const[E,y]of Object.entries(n))o=tt(o,E,y);return o}function st(t,n,o){if(n.opacity!==void 0){const[E,y]=n.opacity;t.style.opacity=String(E+(y-E)*o)}n.italic===!0&&(t.style.fontStyle=o>.5?"italic":"")}function et(t,n){n.opacity!==void 0&&(t.style.opacity=String(n.opacity[0])),n.italic===!0&&(t.style.fontStyle="")}function ct(t){const n=t.cloneNode(!0),o=n.querySelectorAll(`.${z.word}, .${z.char}`);return Array.from(o).reverse().forEach(y=>{const d=y.parentNode;if(d){for(;y.firstChild;)d.insertBefore(y.firstChild,y);d.removeChild(y)}}),n.innerHTML}function mt(t,n){t.innerHTML=n}function it(t,n,o={}){var p,r;if(typeof window>"u")return()=>{};if(window.matchMedia("(prefers-reduced-motion: reduce)").matches)return t.innerHTML=n,()=>{};const E=o.wdthBoost??K.wdthBoost,y=o.radius??K.radius,d=o.falloff??K.falloff,L=o.scope??K.scope,F=o.props,m=o.transitionMs??0,S=o.cachePositions??!0,V=window.scrollY;t.innerHTML=n;const j=getComputedStyle(t).fontVariationSettings,N=j.match(/"wdth"\s+([\d.eE+-]+)/),k=N?parseFloat(N[1]):100,T=ot(t),g=[];for(const a of T){const C=a.textContent??"";if(!C||!C.split("").some(v=>v in rt))continue;const e=document.createDocumentFragment();for(const v of C){const i=rt[v];if(i===void 0){const u=e.lastChild;u&&u.nodeType===Node.TEXT_NODE?u.textContent+=v:e.appendChild(document.createTextNode(v))}else{const u=document.createElement("span");u.className=z.char,u.style.fontVariationSettings=tt(j,"wdth",k),u.textContent=v,e.appendChild(u),g.push({span:u,riskLevel:i})}}a.parentNode.replaceChild(e,a)}if(requestAnimationFrame(()=>{typeof window<"u"&&Math.abs(window.scrollY-V)>2&&window.scrollTo({top:V,behavior:"instant"})}),g.length===0)return()=>{};F&&g.forEach(({span:a})=>et(a,F));let A=[],H=!1;function _(){const a=window.scrollX,C=window.scrollY;A=g.map(({span:c})=>{const e=c.getBoundingClientRect();return{cx:(e.left+e.right)/2+a,cy:(e.top+e.bottom)/2+C}}),H=!0}let R=null;S&&(_(),R=new ResizeObserver(()=>{H=!1}),R.observe(t),(r=(p=document.fonts)==null?void 0:p.ready)==null||r.then(()=>{H=!1}));let q=-9999,B=-9999,$=!1,w=0,P=!0,b=null;function D(){if(!P)return;if(!$){g.forEach(({span:e})=>{m>0&&(e.style.transition=`font-variation-settings ${m}ms ease`),e.style.fontVariationSettings=tt(j,"wdth",k),F&&et(e,F)}),m>0&&(b!==null&&clearTimeout(b),b=setTimeout(()=>{g.forEach(({span:e})=>{e.style.transition=""}),b=null},m)),w=0;return}S&&!H&&_();const a=S?q+window.scrollX:q,C=S?B+window.scrollY:B,c=S?null:g.map(({span:e})=>e.getBoundingClientRect());g.forEach(({span:e,riskLevel:v},i)=>{e.style.transition="";let u,O;if(S)({cx:u,cy:O}=A[i]);else{const I=c[i];u=I.left+I.width/2,O=I.top+I.height/2}const M=Math.sqrt((a-u)**2+(C-O)**2),f=Math.max(0,1-M/y),x=d==="quadratic"?f*f:f,Y=E*(v/3)*x;e.style.fontVariationSettings=tt(j,"wdth",k+Y),F&&st(e,F,x)}),w=requestAnimationFrame(D)}function X(a){q=a.clientX,B=a.clientY,$||($=!0),w===0&&(w=requestAnimationFrame(D))}function J(){$=!1,w===0&&(w=requestAnimationFrame(D))}function Q(a){a.touches.length!==0&&(q=a.touches[0].clientX,B=a.touches[0].clientY,$||($=!0),w===0&&(w=requestAnimationFrame(D)))}function l(){$=!1,w===0&&(w=requestAnimationFrame(D))}const s=L==="document"?document:t;return s.addEventListener("mousemove",X),s.addEventListener("mouseleave",J),s.addEventListener("touchmove",Q,{passive:!0}),s.addEventListener("touchend",l),()=>{P=!1,cancelAnimationFrame(w),b!==null&&clearTimeout(b),R&&R.disconnect(),s.removeEventListener("mousemove",X),s.removeEventListener("mouseleave",J),s.removeEventListener("touchmove",Q),s.removeEventListener("touchend",l),t.innerHTML=n}}function lt(t,n,o={}){var a,C;if(typeof window>"u")return()=>{};if(window.matchMedia("(prefers-reduced-motion: reduce)").matches)return t.innerHTML=n,()=>{};const E=o.axes??K.axes,y=o.radius??K.radius,d=o.falloff??K.falloff,L=o.magnetMode??K.magnetMode,F=o.scope??K.scope,m=o.props,S=o.transitionMs??0,V=o.cachePositions??!0,j=o.stabilizeLayout??!0,N=window.scrollY;t.innerHTML=n;const k=ot(t),T=[];for(const c of k){const e=c.textContent??"";if(!e.trim())continue;const v=e.split(/(\S+)/),i=document.createDocumentFragment();for(let u=0;u<v.length;u+=2){const O=v[u],M=v[u+1];if(!M)continue;const x=v[u+3]===void 0?v[u+2]??"":"",Y=document.createElement("span");Y.className=z.word,Y.textContent=O+M+x,i.appendChild(Y),T.push(Y)}c.parentNode.replaceChild(i,c)}if(requestAnimationFrame(()=>{typeof window<"u"&&Math.abs(window.scrollY-N)>2&&window.scrollTo({top:N,behavior:"instant"})}),T.length===0)return()=>{};const g=getComputedStyle(t).fontVariationSettings,A=nt(g,Object.fromEntries(Object.entries(E).map(([c,[e]])=>[c,e])));let H=0;if(j){const c=nt(g,Object.fromEntries(Object.entries(E).map(([f,[,x]])=>[f,x]))),e=t.style.fontVariationSettings,v=t.style.whiteSpace,i=t.style.overflow;t.style.whiteSpace="nowrap",t.style.overflow="visible",t.style.fontVariationSettings=c;const u=t.scrollWidth;t.style.fontVariationSettings=A;const O=t.scrollWidth;t.style.fontVariationSettings=e,t.style.whiteSpace=v,t.style.overflow=i;const M=T.reduce((f,x)=>{var Y;return f+(((Y=x.textContent)==null?void 0:Y.replace(/\s+/g,"").length)??0)},0);M>0&&u>O&&(H=(u-O)/M)}T.forEach(c=>{c.style.fontVariationSettings=A,m&&et(c,m)});let _=[],R=!1;function q(){const c=window.scrollX,e=window.scrollY;_=T.map(v=>{const i=v.getBoundingClientRect();return{cx:(i.left+i.right)/2+c,cy:(i.top+i.bottom)/2+e}}),R=!0}let B=null;V&&(q(),B=new ResizeObserver(()=>{R=!1}),B.observe(t),(C=(a=document.fonts)==null?void 0:a.ready)==null||C.then(()=>{R=!1}));let $=-9999,w=-9999,P=!1,b=0,D=!0,X=null;function J(){if(!D)return;if(!P){T.forEach(i=>{S>0&&(i.style.transition=`font-variation-settings ${S}ms ease`),i.style.fontVariationSettings=A,j&&(i.style.letterSpacing=""),m&&et(i,m)}),S>0&&(X!==null&&clearTimeout(X),X=setTimeout(()=>{T.forEach(i=>{i.style.transition=""}),X=null},S)),b=0;return}V&&!R&&q();const c=V?$+window.scrollX:$,e=V?w+window.scrollY:w,v=V?null:T.map(i=>i.getBoundingClientRect());T.forEach((i,u)=>{i.style.transition="";let O,M;if(V)({cx:O,cy:M}=_[u]);else{const G=v[u];O=G.left+G.width/2,M=G.top+G.height/2}const f=Math.sqrt((c-O)**2+(e-M)**2),x=Math.max(0,1-f/y),Y=d==="quadratic"?x*x:x,I=L==="repel"?1-Y:Y,Z={};for(const G of Object.keys(E)){const[U,dt]=E[G]??[300,500];Z[G]=U+(dt-U)*I}i.style.fontVariationSettings=nt(g,Z),j&&H!==0&&(i.style.letterSpacing=`${(-H*I).toFixed(3)}px`),m&&st(i,m,Y)}),b=requestAnimationFrame(J)}function Q(c){$=c.clientX,w=c.clientY,P||(P=!0),b===0&&(b=requestAnimationFrame(J))}function l(){P=!1,b===0&&(b=requestAnimationFrame(J))}function s(c){c.touches.length!==0&&($=c.touches[0].clientX,w=c.touches[0].clientY,P||(P=!0),b===0&&(b=requestAnimationFrame(J)))}function p(){P=!1,b===0&&(b=requestAnimationFrame(J))}const r=F==="document"?document:t;return r.addEventListener("mousemove",Q),r.addEventListener("mouseleave",l),r.addEventListener("touchmove",s,{passive:!0}),r.addEventListener("touchend",p),()=>{D=!1,cancelAnimationFrame(b),X!==null&&clearTimeout(X),B&&B.disconnect(),r.removeEventListener("mousemove",Q),r.removeEventListener("mouseleave",l),r.removeEventListener("touchmove",s),r.removeEventListener("touchend",p),t.innerHTML=n}}function at(t){const n=h.useRef(null),o=h.useRef(null),E=h.useRef(t);E.current=t;const y=h.useRef(null),d=t.mode??"field",{axes:L,radius:F,falloff:m,magnetMode:S,wdthBoost:V,scope:j}=t,N=L?JSON.stringify(L):void 0,k=t.props?JSON.stringify(t.props):void 0,T=h.useCallback(()=>{const g=n.current;if(!g)return;o.current===null&&(o.current=ct(g)),y.current&&(y.current(),y.current=null),(E.current.mode??"field")==="field"?y.current=lt(g,o.current,E.current):y.current=it(g,o.current,E.current)},[d,N,F,m,S,V,j,k]);return h.useLayoutEffect(()=>(T(),()=>{y.current&&(y.current(),y.current=null)}),[T]),h.useEffect(()=>{var g,A;(A=(g=document.fonts)==null?void 0:g.ready)==null||A.then(T)},[T]),n}const ut=h.forwardRef(function({children:n,as:o="p",className:E,style:y,...d},L){const F=at(d),m=h.useCallback(S=>{F.current=S,typeof L=="function"?L(S):L&&(L.current=S)},[L]);return W.jsx(o,{ref:m,className:E,style:y,children:n})});ut.displayName="MagnetTypeText";const ft=h.forwardRef(function({children:n,as:o="p",className:E,style:y,minWeight:d=300,maxWeight:L=600,proximityRadius:F,spreadRadius:m,fixedAxes:S={},cachePositions:V=!0,rafThrottle:j=!0,stabilizeLayout:N=!0},k){const T=h.useRef(null),g=h.useRef(null),A=h.useRef([]),H=h.useRef([]),_=h.useRef(null),R=h.useRef(!1),q=h.useRef(null),B=h.useRef(0),$=h.useCallback(l=>{T.current=l,typeof k=="function"?k(l):k&&(k.current=l)},[k]);function w(l){const s=[`'wght' ${l.toFixed(0)}`];for(const[p,r]of Object.entries(S))s.push(`'${p}' ${r}`);return s.join(", ")}function P(){const l=T.current;if(!l)return;const s=window.scrollX,p=window.scrollY,r=l.getBoundingClientRect();_.current={top:r.top+p,left:r.left+s,right:r.right+s,bottom:r.bottom+p},H.current=A.current.map(a=>{if(!a)return{cx:0,cy:0};const C=a.getBoundingClientRect();return{cx:(C.left+C.right)/2+s,cy:(C.top+C.bottom)/2+p}}),R.current=!0}function b(l,s){const p=T.current;if(!p)return;V&&!R.current&&P();let r,a,C,c,e,v;if(V&&_.current)e=l+window.scrollX,v=s+window.scrollY,{top:r,left:a,right:C,bottom:c}=_.current;else{const M=p.getBoundingClientRect();e=l,v=s,r=M.top,a=M.left,C=M.right,c=M.bottom}const i=Math.max(a-e,0,e-C),u=Math.max(r-v,0,v-c),O=Math.sqrt(i*i+u*u);if(F!==void 0&&!m){const f=1-(1-Math.max(0,1-O/F))**2;p.style.fontVariationSettings=w(d+(L-d)*f);return}if(m){if(F!==void 0&&O>F){p.style.fontVariationSettings=w(d);for(const f of A.current)f&&(f.style.fontVariationSettings=w(d),N&&(f.style.letterSpacing=""));return}if(O>m){for(const f of A.current)f&&(f.style.fontVariationSettings=w(d),N&&(f.style.letterSpacing=""));return}const M=A.current;if(V&&H.current.length===M.length)for(let f=0;f<M.length;f++){const x=M[f];if(!x)continue;const{cx:Y,cy:I}=H.current[f],Z=Math.sqrt((e-Y)**2+(v-I)**2),U=1-(1-Math.max(0,1-Z/m))**2;x.style.fontVariationSettings=w(d+(L-d)*U),N&&B.current!==0&&(x.style.letterSpacing=`${(-B.current*U).toFixed(3)}px`)}else for(const f of M){if(!f)continue;const x=f.getBoundingClientRect(),Y=(x.left+x.right)/2,I=(x.top+x.bottom)/2,Z=Math.sqrt((l-Y)**2+(s-I)**2),U=1-(1-Math.max(0,1-Z/m))**2;f.style.fontVariationSettings=w(d+(L-d)*U),N&&B.current!==0&&(f.style.letterSpacing=`${(-B.current*U).toFixed(3)}px`)}}}const D=h.useCallback(l=>{g.current={x:l.clientX,y:l.clientY},j?q.current===null&&(q.current=requestAnimationFrame(()=>{q.current=null,g.current&&b(g.current.x,g.current.y)})):b(l.clientX,l.clientY)},[d,L,F,m,V,j,N,JSON.stringify(S)]),X=h.useCallback(()=>{g.current&&b(g.current.x,g.current.y)},[d,L,F,m,V,N,JSON.stringify(S)]),J=h.useCallback(()=>{g.current=null,q.current!==null&&(cancelAnimationFrame(q.current),q.current=null);const l=T.current;l&&(l.style.fontVariationSettings=w(d));for(const s of A.current)s&&(s.style.fontVariationSettings=w(d),N&&(s.style.letterSpacing=""))},[d,N,JSON.stringify(S)]);h.useEffect(()=>(window.addEventListener("mousemove",D,{passive:!0}),window.addEventListener("scroll",X,{passive:!0,capture:!0}),document.documentElement.addEventListener("mouseleave",J),()=>{window.removeEventListener("mousemove",D),window.removeEventListener("scroll",X,{capture:!0}),document.documentElement.removeEventListener("mouseleave",J),q.current!==null&&(cancelAnimationFrame(q.current),q.current=null)}),[D,X,J]),h.useEffect(()=>{var p,r;if(!V||!m)return;R.current=!1;const l=T.current;if(!l)return;const s=new ResizeObserver(()=>{R.current=!1});return s.observe(l),(r=(p=document.fonts)==null?void 0:p.ready)==null||r.then(()=>{R.current=!1}),()=>s.disconnect()},[V,m]),h.useEffect(()=>{R.current=!1},[n,m]),h.useEffect(()=>{var s,p;if(!N||!m){B.current=0;return}function l(){const r=T.current;if(!r)return;const a=r.textContent??"",C=a.replace(/\s/g,"").length;if(C===0)return;const c=getComputedStyle(r),e=document.createElement("span");e.style.cssText="position:fixed;top:-9999px;left:-9999px;visibility:hidden;white-space:nowrap;pointer-events:none;",e.style.fontFamily=c.fontFamily,e.style.fontSize=c.fontSize,e.style.fontWeight=c.fontWeight,e.style.lineHeight=c.lineHeight,e.style.letterSpacing=c.letterSpacing,e.textContent=a,document.body.appendChild(e);const v=O=>{const M=[`'wght' ${O.toFixed(0)}`];for(const[f,x]of Object.entries(S))M.push(`'${f}' ${x}`);return M.join(", ")};e.style.fontVariationSettings=v(L);const i=e.scrollWidth;e.style.fontVariationSettings=v(d);const u=e.scrollWidth;document.body.removeChild(e),B.current=i>u?(i-u)/C:0}l(),(p=(s=document.fonts)==null?void 0:s.ready)==null||p.then(l)},[N,m,d,L,n,JSON.stringify(S)]);const Q=h.useMemo(()=>{if(!m)return n;A.current=[];let l=0;function s(p){if(typeof p=="string")return[...p].map(r=>{if(/\s/.test(r))return r;const a=l++;return W.jsx("span",{ref:C=>{A.current[a]=C},style:{fontVariationSettings:w(d)},children:r},a)});if(Array.isArray(p))return p.map((r,a)=>W.jsx(h.Fragment,{children:s(r)},a));if(h.isValidElement(p)){const r=p;if(r.props.children!==void 0)return h.cloneElement(r,{},s(r.props.children))}return p}return s(n)},[n,m,d,JSON.stringify(S)]);return W.jsx(o,{ref:$,className:E,style:{fontVariationSettings:w(d),...y},children:Q})});ft.displayName="MagnetBlock";exports.MAGNET_TYPE_CLASSES=z;exports.MagnetBlock=ft;exports.MagnetTypeText=ut;exports.applyMagnetType=it;exports.getCleanHTML=ct;exports.removeMagnetType=mt;exports.startMagnetType=lt;exports.useMagnetType=at;
|
package/dist/index.d.ts
CHANGED
|
@@ -69,6 +69,18 @@ export declare interface MagnetBlockProps {
|
|
|
69
69
|
* @default true
|
|
70
70
|
*/
|
|
71
71
|
rafThrottle?: boolean;
|
|
72
|
+
/**
|
|
73
|
+
* Apply compensating letter-spacing to keep line lengths stable as font weight changes.
|
|
74
|
+
* Measures the element's text width at rest and peak weight via an off-screen probe span,
|
|
75
|
+
* then applies proportional negative letter-spacing per character as weight rises,
|
|
76
|
+
* cancelling the advance-width increase that would otherwise cause text to reflow.
|
|
77
|
+
*
|
|
78
|
+
* Disable if you prefer natural bold letter-spacing, or if the font expands characters
|
|
79
|
+
* very unevenly across the weight axis (the compensation is a per-element average and
|
|
80
|
+
* may not perfectly cancel highly variable per-character expansion).
|
|
81
|
+
* @default true
|
|
82
|
+
*/
|
|
83
|
+
stabilizeLayout?: boolean;
|
|
72
84
|
}
|
|
73
85
|
|
|
74
86
|
/** Whether cursor proximity attracts toward peak or repels toward rest */
|
|
@@ -137,6 +149,28 @@ export declare interface MagnetTypeOptions {
|
|
|
137
149
|
* Risk 3 characters receive wdthBoost × (3/3) = full boost at peak.
|
|
138
150
|
*/
|
|
139
151
|
wdthBoost?: number;
|
|
152
|
+
/**
|
|
153
|
+
* Cache word/character centre positions in page-relative coordinates after setup,
|
|
154
|
+
* eliminating getBoundingClientRect calls during the active interaction loop.
|
|
155
|
+
* The cache is rebuilt on resize and after fonts load. Disable if the element lives
|
|
156
|
+
* inside a custom scroll container (overflow: scroll on a non-window element) —
|
|
157
|
+
* page coordinates are computed using window.scrollX/Y and will be incorrect when
|
|
158
|
+
* a nested element is the scroll parent.
|
|
159
|
+
* @default true
|
|
160
|
+
*/
|
|
161
|
+
cachePositions?: boolean;
|
|
162
|
+
/**
|
|
163
|
+
* Apply compensating letter-spacing to keep line lengths stable as font weight
|
|
164
|
+
* changes. Measures the element's text width at rest and peak weight, then applies
|
|
165
|
+
* proportional negative letter-spacing per word/character as weight rises, cancelling
|
|
166
|
+
* the advance-width increase that would otherwise cause text to reflow.
|
|
167
|
+
*
|
|
168
|
+
* Disable if you prefer natural bold letter-spacing, or if the font expands characters
|
|
169
|
+
* very unevenly across the weight axis (the compensation is a per-element average and
|
|
170
|
+
* may not perfectly cancel highly variable per-character expansion).
|
|
171
|
+
* @default true
|
|
172
|
+
*/
|
|
173
|
+
stabilizeLayout?: boolean;
|
|
140
174
|
/**
|
|
141
175
|
* Duration in milliseconds for the CSS transition back to rest values when the
|
|
142
176
|
* cursor leaves (mouseleave / touchend). Default: 0 (instant snap, no transition).
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import
|
|
3
|
-
import { jsx as
|
|
4
|
-
const
|
|
2
|
+
import rt, { useRef as I, useCallback as z, useLayoutEffect as ft, useEffect as W, forwardRef as lt, useMemo as dt } from "react";
|
|
3
|
+
import { jsx as tt } from "react/jsx-runtime";
|
|
4
|
+
const it = {
|
|
5
5
|
i: 3,
|
|
6
6
|
l: 3,
|
|
7
7
|
1: 3,
|
|
@@ -23,14 +23,14 @@ const rt = {
|
|
|
23
23
|
c: 1,
|
|
24
24
|
e: 1
|
|
25
25
|
// similar bowls
|
|
26
|
-
},
|
|
26
|
+
}, nt = {
|
|
27
27
|
/** Applied to each word span in field mode */
|
|
28
28
|
word: "mt-word",
|
|
29
29
|
/** Applied to each character span in legibility mode */
|
|
30
30
|
char: "mt-char",
|
|
31
31
|
/** Applied to measurement probe spans (never in final output) */
|
|
32
32
|
probe: "mt-probe"
|
|
33
|
-
},
|
|
33
|
+
}, U = {
|
|
34
34
|
axes: { wght: [300, 500] },
|
|
35
35
|
radius: 120,
|
|
36
36
|
falloff: "quadratic",
|
|
@@ -38,389 +38,486 @@ const rt = {
|
|
|
38
38
|
wdthBoost: 6,
|
|
39
39
|
scope: "document"
|
|
40
40
|
};
|
|
41
|
-
function
|
|
42
|
-
return
|
|
41
|
+
function ct(t, n = []) {
|
|
42
|
+
return t.nodeType === Node.TEXT_NODE ? n.push(t) : t.childNodes.forEach((o) => ct(o, n)), n;
|
|
43
43
|
}
|
|
44
|
-
function
|
|
45
|
-
if (!
|
|
46
|
-
const
|
|
47
|
-
return
|
|
44
|
+
function et(t, n, o) {
|
|
45
|
+
if (!t || t === "normal") return `"${n}" ${o}`;
|
|
46
|
+
const M = new RegExp(`(["'])${n}\\1\\s+[\\d.eE+-]+`), h = `"${n}" ${o}`;
|
|
47
|
+
return M.test(t) ? t.replace(M, h) : `${t}, ${h}`;
|
|
48
48
|
}
|
|
49
|
-
function
|
|
50
|
-
let o =
|
|
51
|
-
for (const [
|
|
52
|
-
o =
|
|
49
|
+
function st(t, n) {
|
|
50
|
+
let o = t;
|
|
51
|
+
for (const [M, h] of Object.entries(n))
|
|
52
|
+
o = et(o, M, h);
|
|
53
53
|
return o;
|
|
54
54
|
}
|
|
55
|
-
function
|
|
56
|
-
if (
|
|
57
|
-
const [
|
|
58
|
-
|
|
55
|
+
function at(t, n, o) {
|
|
56
|
+
if (n.opacity !== void 0) {
|
|
57
|
+
const [M, h] = n.opacity;
|
|
58
|
+
t.style.opacity = String(M + (h - M) * o);
|
|
59
59
|
}
|
|
60
|
-
|
|
60
|
+
n.italic === !0 && (t.style.fontStyle = o > 0.5 ? "italic" : "");
|
|
61
61
|
}
|
|
62
|
-
function
|
|
63
|
-
|
|
62
|
+
function ot(t, n) {
|
|
63
|
+
n.opacity !== void 0 && (t.style.opacity = String(n.opacity[0])), n.italic === !0 && (t.style.fontStyle = "");
|
|
64
64
|
}
|
|
65
|
-
function
|
|
66
|
-
const
|
|
67
|
-
`.${
|
|
65
|
+
function mt(t) {
|
|
66
|
+
const n = t.cloneNode(!0), o = n.querySelectorAll(
|
|
67
|
+
`.${nt.word}, .${nt.char}`
|
|
68
68
|
);
|
|
69
|
-
return Array.from(o).reverse().forEach((
|
|
70
|
-
const
|
|
71
|
-
if (
|
|
72
|
-
for (;
|
|
73
|
-
|
|
69
|
+
return Array.from(o).reverse().forEach((h) => {
|
|
70
|
+
const d = h.parentNode;
|
|
71
|
+
if (d) {
|
|
72
|
+
for (; h.firstChild; ) d.insertBefore(h.firstChild, h);
|
|
73
|
+
d.removeChild(h);
|
|
74
74
|
}
|
|
75
|
-
}),
|
|
75
|
+
}), n.innerHTML;
|
|
76
76
|
}
|
|
77
|
-
function
|
|
78
|
-
|
|
77
|
+
function Mt(t, n) {
|
|
78
|
+
t.innerHTML = n;
|
|
79
79
|
}
|
|
80
|
-
function
|
|
80
|
+
function pt(t, n, o = {}) {
|
|
81
|
+
var p, r;
|
|
81
82
|
if (typeof window > "u") return () => {
|
|
82
83
|
};
|
|
83
84
|
if (window.matchMedia("(prefers-reduced-motion: reduce)").matches)
|
|
84
|
-
return
|
|
85
|
+
return t.innerHTML = n, () => {
|
|
85
86
|
};
|
|
86
|
-
const
|
|
87
|
-
|
|
88
|
-
const
|
|
89
|
-
for (const
|
|
90
|
-
const
|
|
91
|
-
if (!
|
|
92
|
-
const
|
|
93
|
-
for (const
|
|
94
|
-
const
|
|
95
|
-
if (
|
|
96
|
-
const
|
|
97
|
-
|
|
87
|
+
const M = o.wdthBoost ?? U.wdthBoost, h = o.radius ?? U.radius, d = o.falloff ?? U.falloff, b = o.scope ?? U.scope, F = o.props, m = o.transitionMs ?? 0, w = o.cachePositions ?? !0, L = window.scrollY;
|
|
88
|
+
t.innerHTML = n;
|
|
89
|
+
const X = getComputedStyle(t).fontVariationSettings, V = X.match(/"wdth"\s+([\d.eE+-]+)/), j = V ? parseFloat(V[1]) : 100, x = ct(t), y = [];
|
|
90
|
+
for (const a of x) {
|
|
91
|
+
const E = a.textContent ?? "";
|
|
92
|
+
if (!E || !E.split("").some((g) => g in it)) continue;
|
|
93
|
+
const e = document.createDocumentFragment();
|
|
94
|
+
for (const g of E) {
|
|
95
|
+
const i = it[g];
|
|
96
|
+
if (i === void 0) {
|
|
97
|
+
const u = e.lastChild;
|
|
98
|
+
u && u.nodeType === Node.TEXT_NODE ? u.textContent += g : e.appendChild(document.createTextNode(g));
|
|
98
99
|
} else {
|
|
99
|
-
const
|
|
100
|
-
|
|
100
|
+
const u = document.createElement("span");
|
|
101
|
+
u.className = nt.char, u.style.fontVariationSettings = et(X, "wdth", j), u.textContent = g, e.appendChild(u), y.push({ span: u, riskLevel: i });
|
|
101
102
|
}
|
|
102
103
|
}
|
|
103
|
-
|
|
104
|
+
a.parentNode.replaceChild(e, a);
|
|
104
105
|
}
|
|
105
106
|
if (requestAnimationFrame(() => {
|
|
106
|
-
typeof window < "u" && Math.abs(window.scrollY -
|
|
107
|
-
}),
|
|
107
|
+
typeof window < "u" && Math.abs(window.scrollY - L) > 2 && window.scrollTo({ top: L, behavior: "instant" });
|
|
108
|
+
}), y.length === 0) return () => {
|
|
108
109
|
};
|
|
109
|
-
|
|
110
|
-
let
|
|
111
|
-
function
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
110
|
+
F && y.forEach(({ span: a }) => ot(a, F));
|
|
111
|
+
let N = [], H = !1;
|
|
112
|
+
function _() {
|
|
113
|
+
const a = window.scrollX, E = window.scrollY;
|
|
114
|
+
N = y.map(({ span: c }) => {
|
|
115
|
+
const e = c.getBoundingClientRect();
|
|
116
|
+
return { cx: (e.left + e.right) / 2 + a, cy: (e.top + e.bottom) / 2 + E };
|
|
117
|
+
}), H = !0;
|
|
118
|
+
}
|
|
119
|
+
let Y = null;
|
|
120
|
+
w && (_(), Y = new ResizeObserver(() => {
|
|
121
|
+
H = !1;
|
|
122
|
+
}), Y.observe(t), (r = (p = document.fonts) == null ? void 0 : p.ready) == null || r.then(() => {
|
|
123
|
+
H = !1;
|
|
124
|
+
}));
|
|
125
|
+
let A = -9999, $ = -9999, B = !1, v = 0, R = !0, T = null;
|
|
126
|
+
function D() {
|
|
127
|
+
if (!R) return;
|
|
128
|
+
if (!B) {
|
|
129
|
+
y.forEach(({ span: e }) => {
|
|
130
|
+
m > 0 && (e.style.transition = `font-variation-settings ${m}ms ease`), e.style.fontVariationSettings = et(X, "wdth", j), F && ot(e, F);
|
|
131
|
+
}), m > 0 && (T !== null && clearTimeout(T), T = setTimeout(() => {
|
|
132
|
+
y.forEach(({ span: e }) => {
|
|
133
|
+
e.style.transition = "";
|
|
134
|
+
}), T = null;
|
|
135
|
+
}, m)), v = 0;
|
|
121
136
|
return;
|
|
122
137
|
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
138
|
+
w && !H && _();
|
|
139
|
+
const a = w ? A + window.scrollX : A, E = w ? $ + window.scrollY : $, c = w ? null : y.map(({ span: e }) => e.getBoundingClientRect());
|
|
140
|
+
y.forEach(({ span: e, riskLevel: g }, i) => {
|
|
141
|
+
e.style.transition = "";
|
|
142
|
+
let u, O;
|
|
143
|
+
if (w)
|
|
144
|
+
({ cx: u, cy: O } = N[i]);
|
|
145
|
+
else {
|
|
146
|
+
const P = c[i];
|
|
147
|
+
u = P.left + P.width / 2, O = P.top + P.height / 2;
|
|
148
|
+
}
|
|
149
|
+
const S = Math.sqrt((a - u) ** 2 + (E - O) ** 2), f = Math.max(0, 1 - S / h), C = d === "quadratic" ? f * f : f, q = M * (g / 3) * C;
|
|
150
|
+
e.style.fontVariationSettings = et(X, "wdth", j + q), F && at(e, F, C);
|
|
151
|
+
}), v = requestAnimationFrame(D);
|
|
129
152
|
}
|
|
130
|
-
function
|
|
131
|
-
|
|
153
|
+
function k(a) {
|
|
154
|
+
A = a.clientX, $ = a.clientY, B || (B = !0), v === 0 && (v = requestAnimationFrame(D));
|
|
132
155
|
}
|
|
133
|
-
function
|
|
134
|
-
|
|
156
|
+
function J() {
|
|
157
|
+
B = !1, v === 0 && (v = requestAnimationFrame(D));
|
|
135
158
|
}
|
|
136
|
-
function
|
|
137
|
-
|
|
159
|
+
function Q(a) {
|
|
160
|
+
a.touches.length !== 0 && (A = a.touches[0].clientX, $ = a.touches[0].clientY, B || (B = !0), v === 0 && (v = requestAnimationFrame(D)));
|
|
138
161
|
}
|
|
139
|
-
function
|
|
140
|
-
|
|
162
|
+
function l() {
|
|
163
|
+
B = !1, v === 0 && (v = requestAnimationFrame(D));
|
|
141
164
|
}
|
|
142
|
-
const
|
|
143
|
-
return
|
|
144
|
-
|
|
165
|
+
const s = b === "document" ? document : t;
|
|
166
|
+
return s.addEventListener("mousemove", k), s.addEventListener("mouseleave", J), s.addEventListener("touchmove", Q, { passive: !0 }), s.addEventListener("touchend", l), () => {
|
|
167
|
+
R = !1, cancelAnimationFrame(v), T !== null && clearTimeout(T), Y && Y.disconnect(), s.removeEventListener("mousemove", k), s.removeEventListener("mouseleave", J), s.removeEventListener("touchmove", Q), s.removeEventListener("touchend", l), t.innerHTML = n;
|
|
145
168
|
};
|
|
146
169
|
}
|
|
147
|
-
function
|
|
170
|
+
function ht(t, n, o = {}) {
|
|
171
|
+
var a, E;
|
|
148
172
|
if (typeof window > "u") return () => {
|
|
149
173
|
};
|
|
150
174
|
if (window.matchMedia("(prefers-reduced-motion: reduce)").matches)
|
|
151
|
-
return
|
|
175
|
+
return t.innerHTML = n, () => {
|
|
152
176
|
};
|
|
153
|
-
const
|
|
154
|
-
|
|
155
|
-
const
|
|
156
|
-
for (const c of
|
|
157
|
-
const
|
|
158
|
-
if (!
|
|
159
|
-
const
|
|
160
|
-
for (let
|
|
161
|
-
const
|
|
162
|
-
if (!
|
|
163
|
-
const
|
|
164
|
-
|
|
177
|
+
const M = o.axes ?? U.axes, h = o.radius ?? U.radius, d = o.falloff ?? U.falloff, b = o.magnetMode ?? U.magnetMode, F = o.scope ?? U.scope, m = o.props, w = o.transitionMs ?? 0, L = o.cachePositions ?? !0, X = o.stabilizeLayout ?? !0, V = window.scrollY;
|
|
178
|
+
t.innerHTML = n;
|
|
179
|
+
const j = ct(t), x = [];
|
|
180
|
+
for (const c of j) {
|
|
181
|
+
const e = c.textContent ?? "";
|
|
182
|
+
if (!e.trim()) continue;
|
|
183
|
+
const g = e.split(/(\S+)/), i = document.createDocumentFragment();
|
|
184
|
+
for (let u = 0; u < g.length; u += 2) {
|
|
185
|
+
const O = g[u], S = g[u + 1];
|
|
186
|
+
if (!S) continue;
|
|
187
|
+
const C = g[u + 3] === void 0 ? g[u + 2] ?? "" : "", q = document.createElement("span");
|
|
188
|
+
q.className = nt.word, q.textContent = O + S + C, i.appendChild(q), x.push(q);
|
|
165
189
|
}
|
|
166
|
-
c.parentNode.replaceChild(
|
|
190
|
+
c.parentNode.replaceChild(i, c);
|
|
167
191
|
}
|
|
168
192
|
if (requestAnimationFrame(() => {
|
|
169
|
-
typeof window < "u" && Math.abs(window.scrollY -
|
|
170
|
-
}),
|
|
193
|
+
typeof window < "u" && Math.abs(window.scrollY - V) > 2 && window.scrollTo({ top: V, behavior: "instant" });
|
|
194
|
+
}), x.length === 0) return () => {
|
|
171
195
|
};
|
|
172
|
-
const
|
|
173
|
-
|
|
174
|
-
Object.fromEntries(Object.entries(
|
|
196
|
+
const y = getComputedStyle(t).fontVariationSettings, N = st(
|
|
197
|
+
y,
|
|
198
|
+
Object.fromEntries(Object.entries(M).map(([c, [e]]) => [c, e]))
|
|
175
199
|
);
|
|
176
|
-
|
|
177
|
-
|
|
200
|
+
let H = 0;
|
|
201
|
+
if (X) {
|
|
202
|
+
const c = st(
|
|
203
|
+
y,
|
|
204
|
+
Object.fromEntries(Object.entries(M).map(([f, [, C]]) => [f, C]))
|
|
205
|
+
), e = t.style.fontVariationSettings, g = t.style.whiteSpace, i = t.style.overflow;
|
|
206
|
+
t.style.whiteSpace = "nowrap", t.style.overflow = "visible", t.style.fontVariationSettings = c;
|
|
207
|
+
const u = t.scrollWidth;
|
|
208
|
+
t.style.fontVariationSettings = N;
|
|
209
|
+
const O = t.scrollWidth;
|
|
210
|
+
t.style.fontVariationSettings = e, t.style.whiteSpace = g, t.style.overflow = i;
|
|
211
|
+
const S = x.reduce(
|
|
212
|
+
(f, C) => {
|
|
213
|
+
var q;
|
|
214
|
+
return f + (((q = C.textContent) == null ? void 0 : q.replace(/\s+/g, "").length) ?? 0);
|
|
215
|
+
},
|
|
216
|
+
0
|
|
217
|
+
);
|
|
218
|
+
S > 0 && u > O && (H = (u - O) / S);
|
|
219
|
+
}
|
|
220
|
+
x.forEach((c) => {
|
|
221
|
+
c.style.fontVariationSettings = N, m && ot(c, m);
|
|
178
222
|
});
|
|
179
|
-
let
|
|
180
|
-
function
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
223
|
+
let _ = [], Y = !1;
|
|
224
|
+
function A() {
|
|
225
|
+
const c = window.scrollX, e = window.scrollY;
|
|
226
|
+
_ = x.map((g) => {
|
|
227
|
+
const i = g.getBoundingClientRect();
|
|
228
|
+
return { cx: (i.left + i.right) / 2 + c, cy: (i.top + i.bottom) / 2 + e };
|
|
229
|
+
}), Y = !0;
|
|
230
|
+
}
|
|
231
|
+
let $ = null;
|
|
232
|
+
L && (A(), $ = new ResizeObserver(() => {
|
|
233
|
+
Y = !1;
|
|
234
|
+
}), $.observe(t), (E = (a = document.fonts) == null ? void 0 : a.ready) == null || E.then(() => {
|
|
235
|
+
Y = !1;
|
|
236
|
+
}));
|
|
237
|
+
let B = -9999, v = -9999, R = !1, T = 0, D = !0, k = null;
|
|
238
|
+
function J() {
|
|
239
|
+
if (!D) return;
|
|
240
|
+
if (!R) {
|
|
241
|
+
x.forEach((i) => {
|
|
242
|
+
w > 0 && (i.style.transition = `font-variation-settings ${w}ms ease`), i.style.fontVariationSettings = N, X && (i.style.letterSpacing = ""), m && ot(i, m);
|
|
243
|
+
}), w > 0 && (k !== null && clearTimeout(k), k = setTimeout(() => {
|
|
244
|
+
x.forEach((i) => {
|
|
245
|
+
i.style.transition = "";
|
|
246
|
+
}), k = null;
|
|
247
|
+
}, w)), T = 0;
|
|
190
248
|
return;
|
|
191
249
|
}
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
250
|
+
L && !Y && A();
|
|
251
|
+
const c = L ? B + window.scrollX : B, e = L ? v + window.scrollY : v, g = L ? null : x.map((i) => i.getBoundingClientRect());
|
|
252
|
+
x.forEach((i, u) => {
|
|
253
|
+
i.style.transition = "";
|
|
254
|
+
let O, S;
|
|
255
|
+
if (L)
|
|
256
|
+
({ cx: O, cy: S } = _[u]);
|
|
257
|
+
else {
|
|
258
|
+
const K = g[u];
|
|
259
|
+
O = K.left + K.width / 2, S = K.top + K.height / 2;
|
|
199
260
|
}
|
|
200
|
-
|
|
201
|
-
|
|
261
|
+
const f = Math.sqrt((c - O) ** 2 + (e - S) ** 2), C = Math.max(0, 1 - f / h), q = d === "quadratic" ? C * C : C, P = b === "repel" ? 1 - q : q, Z = {};
|
|
262
|
+
for (const K of Object.keys(M)) {
|
|
263
|
+
const [G, ut] = M[K] ?? [300, 500];
|
|
264
|
+
Z[K] = G + (ut - G) * P;
|
|
265
|
+
}
|
|
266
|
+
i.style.fontVariationSettings = st(y, Z), X && H !== 0 && (i.style.letterSpacing = `${(-H * P).toFixed(3)}px`), m && at(i, m, q);
|
|
267
|
+
}), T = requestAnimationFrame(J);
|
|
202
268
|
}
|
|
203
|
-
function
|
|
204
|
-
|
|
269
|
+
function Q(c) {
|
|
270
|
+
B = c.clientX, v = c.clientY, R || (R = !0), T === 0 && (T = requestAnimationFrame(J));
|
|
205
271
|
}
|
|
206
|
-
function
|
|
207
|
-
|
|
272
|
+
function l() {
|
|
273
|
+
R = !1, T === 0 && (T = requestAnimationFrame(J));
|
|
208
274
|
}
|
|
209
|
-
function
|
|
210
|
-
c.touches.length !== 0 && (
|
|
275
|
+
function s(c) {
|
|
276
|
+
c.touches.length !== 0 && (B = c.touches[0].clientX, v = c.touches[0].clientY, R || (R = !0), T === 0 && (T = requestAnimationFrame(J)));
|
|
211
277
|
}
|
|
212
|
-
function
|
|
213
|
-
|
|
278
|
+
function p() {
|
|
279
|
+
R = !1, T === 0 && (T = requestAnimationFrame(J));
|
|
214
280
|
}
|
|
215
|
-
const
|
|
216
|
-
return
|
|
217
|
-
|
|
281
|
+
const r = F === "document" ? document : t;
|
|
282
|
+
return r.addEventListener("mousemove", Q), r.addEventListener("mouseleave", l), r.addEventListener("touchmove", s, { passive: !0 }), r.addEventListener("touchend", p), () => {
|
|
283
|
+
D = !1, cancelAnimationFrame(T), k !== null && clearTimeout(k), $ && $.disconnect(), r.removeEventListener("mousemove", Q), r.removeEventListener("mouseleave", l), r.removeEventListener("touchmove", s), r.removeEventListener("touchend", p), t.innerHTML = n;
|
|
218
284
|
};
|
|
219
285
|
}
|
|
220
|
-
function
|
|
221
|
-
const
|
|
222
|
-
|
|
223
|
-
const
|
|
224
|
-
const y =
|
|
286
|
+
function yt(t) {
|
|
287
|
+
const n = I(null), o = I(null), M = I(t);
|
|
288
|
+
M.current = t;
|
|
289
|
+
const h = I(null), d = t.mode ?? "field", { axes: b, radius: F, falloff: m, magnetMode: w, wdthBoost: L, scope: X } = t, V = b ? JSON.stringify(b) : void 0, j = t.props ? JSON.stringify(t.props) : void 0, x = z(() => {
|
|
290
|
+
const y = n.current;
|
|
225
291
|
if (!y) return;
|
|
226
|
-
o.current === null && (o.current =
|
|
227
|
-
}, [
|
|
228
|
-
return
|
|
229
|
-
|
|
230
|
-
}), [
|
|
231
|
-
|
|
232
|
-
|
|
292
|
+
o.current === null && (o.current = mt(y)), h.current && (h.current(), h.current = null), (M.current.mode ?? "field") === "field" ? h.current = ht(y, o.current, M.current) : h.current = pt(y, o.current, M.current);
|
|
293
|
+
}, [d, V, F, m, w, L, X, j]);
|
|
294
|
+
return ft(() => (x(), () => {
|
|
295
|
+
h.current && (h.current(), h.current = null);
|
|
296
|
+
}), [x]), W(() => {
|
|
297
|
+
var y, N;
|
|
298
|
+
(N = (y = document.fonts) == null ? void 0 : y.ready) == null || N.then(x);
|
|
299
|
+
}, [x]), n;
|
|
233
300
|
}
|
|
234
|
-
const
|
|
235
|
-
function({ children:
|
|
236
|
-
const
|
|
237
|
-
(
|
|
238
|
-
|
|
301
|
+
const gt = lt(
|
|
302
|
+
function({ children: n, as: o = "p", className: M, style: h, ...d }, b) {
|
|
303
|
+
const F = yt(d), m = z(
|
|
304
|
+
(w) => {
|
|
305
|
+
F.current = w, typeof b == "function" ? b(w) : b && (b.current = w);
|
|
239
306
|
},
|
|
240
307
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
241
|
-
[
|
|
308
|
+
[b]
|
|
242
309
|
);
|
|
243
|
-
return /* @__PURE__ */
|
|
310
|
+
return /* @__PURE__ */ tt(o, { ref: m, className: M, style: h, children: n });
|
|
244
311
|
}
|
|
245
312
|
);
|
|
246
|
-
|
|
247
|
-
const
|
|
313
|
+
gt.displayName = "MagnetTypeText";
|
|
314
|
+
const vt = lt(
|
|
248
315
|
function({
|
|
249
|
-
children:
|
|
316
|
+
children: n,
|
|
250
317
|
as: o = "p",
|
|
251
|
-
className:
|
|
252
|
-
style:
|
|
253
|
-
minWeight:
|
|
254
|
-
maxWeight:
|
|
255
|
-
proximityRadius:
|
|
256
|
-
spreadRadius:
|
|
257
|
-
fixedAxes:
|
|
318
|
+
className: M,
|
|
319
|
+
style: h,
|
|
320
|
+
minWeight: d = 300,
|
|
321
|
+
maxWeight: b = 600,
|
|
322
|
+
proximityRadius: F,
|
|
323
|
+
spreadRadius: m,
|
|
324
|
+
fixedAxes: w = {},
|
|
258
325
|
cachePositions: L = !0,
|
|
259
|
-
rafThrottle:
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
326
|
+
rafThrottle: X = !0,
|
|
327
|
+
stabilizeLayout: V = !0
|
|
328
|
+
}, j) {
|
|
329
|
+
const x = I(null), y = I(null), N = I([]), H = I([]), _ = I(null), Y = I(!1), A = I(null), $ = I(0), B = z(
|
|
330
|
+
(l) => {
|
|
331
|
+
x.current = l, typeof j == "function" ? j(l) : j && (j.current = l);
|
|
264
332
|
},
|
|
265
333
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
266
|
-
[
|
|
334
|
+
[j]
|
|
267
335
|
);
|
|
268
|
-
function
|
|
269
|
-
const
|
|
270
|
-
for (const [
|
|
271
|
-
return
|
|
336
|
+
function v(l) {
|
|
337
|
+
const s = [`'wght' ${l.toFixed(0)}`];
|
|
338
|
+
for (const [p, r] of Object.entries(w)) s.push(`'${p}' ${r}`);
|
|
339
|
+
return s.join(", ");
|
|
272
340
|
}
|
|
273
|
-
function
|
|
274
|
-
const
|
|
275
|
-
if (!
|
|
276
|
-
const
|
|
277
|
-
|
|
278
|
-
top:
|
|
279
|
-
left:
|
|
280
|
-
right:
|
|
281
|
-
bottom:
|
|
282
|
-
},
|
|
283
|
-
if (!
|
|
284
|
-
const
|
|
341
|
+
function R() {
|
|
342
|
+
const l = x.current;
|
|
343
|
+
if (!l) return;
|
|
344
|
+
const s = window.scrollX, p = window.scrollY, r = l.getBoundingClientRect();
|
|
345
|
+
_.current = {
|
|
346
|
+
top: r.top + p,
|
|
347
|
+
left: r.left + s,
|
|
348
|
+
right: r.right + s,
|
|
349
|
+
bottom: r.bottom + p
|
|
350
|
+
}, H.current = N.current.map((a) => {
|
|
351
|
+
if (!a) return { cx: 0, cy: 0 };
|
|
352
|
+
const E = a.getBoundingClientRect();
|
|
285
353
|
return {
|
|
286
|
-
cx: (
|
|
287
|
-
cy: (
|
|
354
|
+
cx: (E.left + E.right) / 2 + s,
|
|
355
|
+
cy: (E.top + E.bottom) / 2 + p
|
|
288
356
|
};
|
|
289
|
-
}),
|
|
357
|
+
}), Y.current = !0;
|
|
290
358
|
}
|
|
291
|
-
function
|
|
292
|
-
const
|
|
293
|
-
if (!
|
|
294
|
-
L && !
|
|
295
|
-
let
|
|
296
|
-
if (L &&
|
|
297
|
-
|
|
359
|
+
function T(l, s) {
|
|
360
|
+
const p = x.current;
|
|
361
|
+
if (!p) return;
|
|
362
|
+
L && !Y.current && R();
|
|
363
|
+
let r, a, E, c, e, g;
|
|
364
|
+
if (L && _.current)
|
|
365
|
+
e = l + window.scrollX, g = s + window.scrollY, { top: r, left: a, right: E, bottom: c } = _.current;
|
|
298
366
|
else {
|
|
299
|
-
const
|
|
300
|
-
|
|
367
|
+
const S = p.getBoundingClientRect();
|
|
368
|
+
e = l, g = s, r = S.top, a = S.left, E = S.right, c = S.bottom;
|
|
301
369
|
}
|
|
302
|
-
const
|
|
303
|
-
if (
|
|
304
|
-
const
|
|
305
|
-
|
|
370
|
+
const i = Math.max(a - e, 0, e - E), u = Math.max(r - g, 0, g - c), O = Math.sqrt(i * i + u * u);
|
|
371
|
+
if (F !== void 0 && !m) {
|
|
372
|
+
const f = 1 - (1 - Math.max(0, 1 - O / F)) ** 2;
|
|
373
|
+
p.style.fontVariationSettings = v(d + (b - d) * f);
|
|
306
374
|
return;
|
|
307
375
|
}
|
|
308
|
-
if (
|
|
309
|
-
if (
|
|
310
|
-
|
|
311
|
-
for (const
|
|
376
|
+
if (m) {
|
|
377
|
+
if (F !== void 0 && O > F) {
|
|
378
|
+
p.style.fontVariationSettings = v(d);
|
|
379
|
+
for (const f of N.current)
|
|
380
|
+
f && (f.style.fontVariationSettings = v(d), V && (f.style.letterSpacing = ""));
|
|
312
381
|
return;
|
|
313
382
|
}
|
|
314
|
-
if (
|
|
315
|
-
for (const
|
|
383
|
+
if (O > m) {
|
|
384
|
+
for (const f of N.current)
|
|
385
|
+
f && (f.style.fontVariationSettings = v(d), V && (f.style.letterSpacing = ""));
|
|
316
386
|
return;
|
|
317
387
|
}
|
|
318
|
-
const
|
|
319
|
-
if (L &&
|
|
320
|
-
for (let
|
|
321
|
-
const
|
|
322
|
-
if (!
|
|
323
|
-
const { cx:
|
|
324
|
-
|
|
388
|
+
const S = N.current;
|
|
389
|
+
if (L && H.current.length === S.length)
|
|
390
|
+
for (let f = 0; f < S.length; f++) {
|
|
391
|
+
const C = S[f];
|
|
392
|
+
if (!C) continue;
|
|
393
|
+
const { cx: q, cy: P } = H.current[f], Z = Math.sqrt((e - q) ** 2 + (g - P) ** 2), G = 1 - (1 - Math.max(0, 1 - Z / m)) ** 2;
|
|
394
|
+
C.style.fontVariationSettings = v(d + (b - d) * G), V && $.current !== 0 && (C.style.letterSpacing = `${(-$.current * G).toFixed(3)}px`);
|
|
325
395
|
}
|
|
326
396
|
else
|
|
327
|
-
for (const
|
|
328
|
-
if (!
|
|
329
|
-
const
|
|
330
|
-
|
|
397
|
+
for (const f of S) {
|
|
398
|
+
if (!f) continue;
|
|
399
|
+
const C = f.getBoundingClientRect(), q = (C.left + C.right) / 2, P = (C.top + C.bottom) / 2, Z = Math.sqrt((l - q) ** 2 + (s - P) ** 2), G = 1 - (1 - Math.max(0, 1 - Z / m)) ** 2;
|
|
400
|
+
f.style.fontVariationSettings = v(d + (b - d) * G), V && $.current !== 0 && (f.style.letterSpacing = `${(-$.current * G).toFixed(3)}px`);
|
|
331
401
|
}
|
|
332
402
|
}
|
|
333
403
|
}
|
|
334
|
-
const
|
|
335
|
-
(
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
})) :
|
|
404
|
+
const D = z(
|
|
405
|
+
(l) => {
|
|
406
|
+
y.current = { x: l.clientX, y: l.clientY }, X ? A.current === null && (A.current = requestAnimationFrame(() => {
|
|
407
|
+
A.current = null, y.current && T(y.current.x, y.current.y);
|
|
408
|
+
})) : T(l.clientX, l.clientY);
|
|
339
409
|
},
|
|
340
410
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
341
|
-
[
|
|
342
|
-
), k =
|
|
411
|
+
[d, b, F, m, L, X, V, JSON.stringify(w)]
|
|
412
|
+
), k = z(
|
|
343
413
|
() => {
|
|
344
|
-
|
|
414
|
+
y.current && T(y.current.x, y.current.y);
|
|
345
415
|
},
|
|
346
416
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
347
|
-
[
|
|
348
|
-
),
|
|
417
|
+
[d, b, F, m, L, V, JSON.stringify(w)]
|
|
418
|
+
), J = z(
|
|
349
419
|
() => {
|
|
350
|
-
|
|
351
|
-
const
|
|
352
|
-
|
|
353
|
-
for (const
|
|
420
|
+
y.current = null, A.current !== null && (cancelAnimationFrame(A.current), A.current = null);
|
|
421
|
+
const l = x.current;
|
|
422
|
+
l && (l.style.fontVariationSettings = v(d));
|
|
423
|
+
for (const s of N.current)
|
|
424
|
+
s && (s.style.fontVariationSettings = v(d), V && (s.style.letterSpacing = ""));
|
|
354
425
|
},
|
|
355
426
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
356
|
-
[
|
|
427
|
+
[d, V, JSON.stringify(w)]
|
|
357
428
|
);
|
|
358
|
-
|
|
359
|
-
window.removeEventListener("mousemove",
|
|
360
|
-
}), [
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
429
|
+
W(() => (window.addEventListener("mousemove", D, { passive: !0 }), window.addEventListener("scroll", k, { passive: !0, capture: !0 }), document.documentElement.addEventListener("mouseleave", J), () => {
|
|
430
|
+
window.removeEventListener("mousemove", D), window.removeEventListener("scroll", k, { capture: !0 }), document.documentElement.removeEventListener("mouseleave", J), A.current !== null && (cancelAnimationFrame(A.current), A.current = null);
|
|
431
|
+
}), [D, k, J]), W(() => {
|
|
432
|
+
var p, r;
|
|
433
|
+
if (!L || !m) return;
|
|
434
|
+
Y.current = !1;
|
|
435
|
+
const l = x.current;
|
|
436
|
+
if (!l) return;
|
|
437
|
+
const s = new ResizeObserver(() => {
|
|
438
|
+
Y.current = !1;
|
|
367
439
|
});
|
|
368
|
-
return
|
|
369
|
-
|
|
370
|
-
}), () =>
|
|
371
|
-
}, [L,
|
|
372
|
-
|
|
373
|
-
}, [
|
|
374
|
-
|
|
375
|
-
if (!
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
440
|
+
return s.observe(l), (r = (p = document.fonts) == null ? void 0 : p.ready) == null || r.then(() => {
|
|
441
|
+
Y.current = !1;
|
|
442
|
+
}), () => s.disconnect();
|
|
443
|
+
}, [L, m]), W(() => {
|
|
444
|
+
Y.current = !1;
|
|
445
|
+
}, [n, m]), W(() => {
|
|
446
|
+
var s, p;
|
|
447
|
+
if (!V || !m) {
|
|
448
|
+
$.current = 0;
|
|
449
|
+
return;
|
|
450
|
+
}
|
|
451
|
+
function l() {
|
|
452
|
+
const r = x.current;
|
|
453
|
+
if (!r) return;
|
|
454
|
+
const a = r.textContent ?? "", E = a.replace(/\s/g, "").length;
|
|
455
|
+
if (E === 0) return;
|
|
456
|
+
const c = getComputedStyle(r), e = document.createElement("span");
|
|
457
|
+
e.style.cssText = "position:fixed;top:-9999px;left:-9999px;visibility:hidden;white-space:nowrap;pointer-events:none;", e.style.fontFamily = c.fontFamily, e.style.fontSize = c.fontSize, e.style.fontWeight = c.fontWeight, e.style.lineHeight = c.lineHeight, e.style.letterSpacing = c.letterSpacing, e.textContent = a, document.body.appendChild(e);
|
|
458
|
+
const g = (O) => {
|
|
459
|
+
const S = [`'wght' ${O.toFixed(0)}`];
|
|
460
|
+
for (const [f, C] of Object.entries(w)) S.push(`'${f}' ${C}`);
|
|
461
|
+
return S.join(", ");
|
|
462
|
+
};
|
|
463
|
+
e.style.fontVariationSettings = g(b);
|
|
464
|
+
const i = e.scrollWidth;
|
|
465
|
+
e.style.fontVariationSettings = g(d);
|
|
466
|
+
const u = e.scrollWidth;
|
|
467
|
+
document.body.removeChild(e), $.current = i > u ? (i - u) / E : 0;
|
|
468
|
+
}
|
|
469
|
+
l(), (p = (s = document.fonts) == null ? void 0 : s.ready) == null || p.then(l);
|
|
470
|
+
}, [V, m, d, b, n, JSON.stringify(w)]);
|
|
471
|
+
const Q = dt(() => {
|
|
472
|
+
if (!m) return n;
|
|
473
|
+
N.current = [];
|
|
474
|
+
let l = 0;
|
|
475
|
+
function s(p) {
|
|
476
|
+
if (typeof p == "string")
|
|
477
|
+
return [...p].map((r) => {
|
|
478
|
+
if (/\s/.test(r)) return r;
|
|
479
|
+
const a = l++;
|
|
480
|
+
return /* @__PURE__ */ tt(
|
|
384
481
|
"span",
|
|
385
482
|
{
|
|
386
|
-
ref: (
|
|
387
|
-
|
|
483
|
+
ref: (E) => {
|
|
484
|
+
N.current[a] = E;
|
|
388
485
|
},
|
|
389
|
-
style: { fontVariationSettings:
|
|
390
|
-
children:
|
|
486
|
+
style: { fontVariationSettings: v(d) },
|
|
487
|
+
children: r
|
|
391
488
|
},
|
|
392
|
-
|
|
489
|
+
a
|
|
393
490
|
);
|
|
394
491
|
});
|
|
395
|
-
if (Array.isArray(
|
|
396
|
-
if (
|
|
397
|
-
const
|
|
398
|
-
if (
|
|
399
|
-
return
|
|
492
|
+
if (Array.isArray(p)) return p.map((r, a) => /* @__PURE__ */ tt(rt.Fragment, { children: s(r) }, a));
|
|
493
|
+
if (rt.isValidElement(p)) {
|
|
494
|
+
const r = p;
|
|
495
|
+
if (r.props.children !== void 0)
|
|
496
|
+
return rt.cloneElement(r, {}, s(r.props.children));
|
|
400
497
|
}
|
|
401
|
-
return
|
|
498
|
+
return p;
|
|
402
499
|
}
|
|
403
|
-
return
|
|
404
|
-
}, [
|
|
405
|
-
return /* @__PURE__ */
|
|
500
|
+
return s(n);
|
|
501
|
+
}, [n, m, d, JSON.stringify(w)]);
|
|
502
|
+
return /* @__PURE__ */ tt(
|
|
406
503
|
o,
|
|
407
504
|
{
|
|
408
|
-
ref:
|
|
409
|
-
className:
|
|
410
|
-
style: { fontVariationSettings:
|
|
411
|
-
children:
|
|
505
|
+
ref: B,
|
|
506
|
+
className: M,
|
|
507
|
+
style: { fontVariationSettings: v(d), ...h },
|
|
508
|
+
children: Q
|
|
412
509
|
}
|
|
413
510
|
);
|
|
414
511
|
}
|
|
415
512
|
);
|
|
416
|
-
|
|
513
|
+
vt.displayName = "MagnetBlock";
|
|
417
514
|
export {
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
515
|
+
nt as MAGNET_TYPE_CLASSES,
|
|
516
|
+
vt as MagnetBlock,
|
|
517
|
+
gt as MagnetTypeText,
|
|
518
|
+
pt as applyMagnetType,
|
|
519
|
+
mt as getCleanHTML,
|
|
520
|
+
Mt as removeMagnetType,
|
|
521
|
+
ht as startMagnetType,
|
|
522
|
+
yt as useMagnetType
|
|
426
523
|
};
|