@verifiedinc-public/shared-ui-elements 9.4.0 → 9.4.1
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{forwardRef as z,useRef as G,useState as
|
|
1
|
+
"use strict";import{forwardRef as z,useRef as G,useState as p,useImperativeHandle as N,useEffect as v}from"react";import{Stack as y,Box as F,Button as W}from"@mui/material";import{AutoAwesome as $}from"@mui/icons-material";import*as u from"html-to-image";import{wrapPromise as j}from"../../utils/wrapPromise/index.mjs";import{useGoogleFont as A}from"../../hooks/useGoogleFont.mjs";import{jsxs as L,jsx as i}from"react/jsx-runtime";import{PoweredByVerified as H}from"../verified/powered-by-verified/index.mjs";function V({magicLink:g,magicText:c,buttonProps:l,renderAsImage:n,enablePoweredByVerified:b,poweredByVerifiedProps:d,fontFamily:s,enableGoogleFontLoad:h},R){const o=G(null),[C,S]=p(null),[P,E]=p(null),[m,x]=p(0),[k,T]=p(0),r=A(s,h),B=async e=>{if(!o.current)return;const a={png:u.toPng,svg:u.toSvg};let t=null;try{r.cssContent&&(t=document.createElement("style"),t.id="temp-font-style-for-download",t.textContent=r.cssContent,document.head.appendChild(t));const[f,I]=await j(a[e](o.current,{pixelRatio:4}));if(t&&(document.head.removeChild(t),t=null),I){console.error("Failed to generate magic button:",I);return}if(!f)return;const w=document.createElement("a");w.href=f,w.download=`magic-button-${c.replace(/\s+/g,"-")}.${e}`,w.click()}catch(f){t&&document.head.removeChild(t),console.error("Failed to generate magic button:",f)}};return N(R,()=>({download:B}),[B]),v(()=>{if(!n){x(0);return}if(!o.current||m>10)return;x(a=>a+1);const e=setInterval(()=>{x(a=>a+1)},m+1*500);return()=>clearInterval(e)},[m,n,r.isLoaded]),v(()=>{let e=null;return r.cssContent&&(e=document.createElement("style"),e.id="temp-font-style-for-image",e.textContent=r.cssContent,document.head.appendChild(e)),()=>{e&&document.head.removeChild(e)}},[r.cssContent]),v(()=>{!n||s&&h&&r.isLoading||(async()=>{if(o.current&&!(h&&!r.isLoaded))try{const e=await u.toPng(o.current,{pixelRatio:.5});if(e===P){k===0&&T(t=>t+1);return}if(E(e),!o.current)return;const a=await u.toPng(o.current,{pixelRatio:4});S(a)}catch(e){console.error("Failed to generate PNG:",e)}})()},[k,m,g,c,l,b,d,n,s,r.isLoaded,P]),L(y,{children:[i(F,{className:"button-preview-container",sx:{...n&&{position:"fixed",top:-9999,left:-9999,maxWidth:9999,overflow:"hidden",zIndex:-1}},children:L(y,{ref:o,className:"canvas-copiable",spacing:1,sx:{display:"inline-flex",minWidth:"fit-content",justifyContent:"center",alignItems:"center",alignSelf:"center",...n&&{pt:"3px",pb:"6px",px:"4px"}},children:[i(W,{href:g,target:"_blank",variant:"contained",size:"large",color:"primary",startIcon:i($,{}),...l,sx:{fontFamily:s?`"${s}" !important`:void 0,textTransform:"none",fontSize:16,p:1.5,m:1,"&, & > span":{wordBreak:"break-word",lineHeight:n?0:1.75},"& > span":{whiteSpace:n?"nowrap":void 0},...l?.sx},children:i("span",{children:c})}),b&&i(H,{...d,containerProps:{pt:.5,maxWidth:143,...d?.containerProps}})]})}),C&&n&&i(y,{component:"a",href:g,target:"_blank",rel:"noopener noreferrer",flex:1,sx:{overflow:"visible"},children:i(F,{component:"img",src:C,alt:c,draggable:!1,sx:{width:"100%",height:"auto"}})})]})}const _=z(V);export{_ as TTSMagicButton};
|