PluginProbe
bBlocks – Essential Gutenberg Blocks & Patterns Collection / trunk
bBlocks – Essential Gutenberg Blocks & Patterns Collection vtrunk
2.1.6 2.1.5 2.1.4 2.1.3 2.1.2 2.1.1 2.1.0 2.0.43 2.0.42 2.0.41 2.0.40 2.0.39 2.0.38 trunk 1.0 1.1 1.2 1.3 1.4 1.5 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 All 106 releases
b-blocks / build / counters / view.js

view.js in bBlocks – Essential Gutenberg Blocks & Patterns Collection trunk, at build/counters/view.js

1 lines 7.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 (()=>{"use strict";const t=window.React,e=window.ReactDOM,n=t=>{try{const e=new URL(t);return["http:","https:"].includes(e.protocol)?e.toString():null}catch(e){return"string"==typeof t&&t.startsWith("/")&&!t.startsWith("//")?t:null}},r=t=>{const e=(new DOMParser).parseFromString(t,"text/html"),r=["b","strong","i","em","span","a","br"],o=["style","href","target","rel","class"];return e.body.querySelectorAll("*").forEach((t=>{r.includes(t.tagName.toLowerCase())?[...t.attributes].forEach((e=>{if(o.includes(e.name)||t.removeAttribute(e.name),"href"===e.name){const r=n(e.value);r?t.setAttribute("href",r):t.removeAttribute("href")}})):t.remove()})),e.body.innerHTML},o="linear-gradient(135deg, #0040E3, #18D4FD)",s=(t,e)=>{return null==(n=e)||""===n||Array.isArray(n)&&0===n.length||"object"==typeof n&&0===Object.keys(n).length||"string"==typeof n&&""===n.trim()||"number"==typeof n&&0===n?"":`${t}: ${e};`;var n},a=(t,e=!0,r=!0,a=!0)=>{const{type:c="solid",color:i="",gradient:l=o,image:u={},position:d="center center",attachment:$="",repeat:p="no-repeat",size:b="",overlayColor:m=""}=t||{};return"gradient"===c&&r?s("background",l):"image"===c&&a?`background: ${(t=>{const e=n(t);return e?`url('${e.replace(/['"()]/g,"")}')`:"none"})(u?.url)};\n\t\t\t\t${s("background-color",m)}\n\t\t\t\t${s("background-position",d)}\n\t\t\t\t${s("background-size",b)}\n\t\t\t\t${s("background-repeat",p)}\n\t\t\t\t${s("background-attachment",$)}\n\t\t\t\t${s("background-repeat",p)}\n\t\t\t\tbackground-blend-mode: overlay;`:e&&s("background",i)},c=t=>{const{width:e="",style:n="solid",color:r="",side:o="all",radius:a=""}=t||{},c=t=>{const e=o?.toLowerCase();return e?.includes("all")||e?.includes(t)},i=`${e} ${n} ${r}`,l=`\n\t\t${e&&0!==parseInt(e)?["top","right","bottom","left"].map((t=>c(t)?`border-${t}: ${i};`:"")).join(""):""}\n\t\t${s("border-radius",a)}\n\t`;return l},i=(t,e="box")=>{const{hOffset:n="0px",vOffset:r="0px",blur:o="0px",spreed:s="0px",color:a="#7090b0",isInset:c=!1}=t||{},i=`${n} ${r} ${o}`;return("text"===e?`${i} ${a}`:`${i} ${s} ${a} ${c?"inset":""}`)||"none"},l=t=>{const{side:e=2,vertical:n="0px",horizontal:r="0px",top:o="0px",right:s="0px",bottom:a="0px",left:c="0px"}=t||{};return 2===e?`${n} ${r}`:`${o} ${s} ${a} ${c}`},u=(t,e,n=!0)=>{const{fontFamily:r="Default",fontCategory:o="sans-serif",fontVariant:a=400,fontWeight:c,isUploadFont:i=!0,fontSize:l={desktop:null,tablet:null,mobile:null},fontStyle:u,textTransform:d,textDecoration:$,lineHeight:p,letterSpace:b}=e||{},m=!n||!r||"Default"===r,g=l?.desktop||l,x=l?.tablet||g,h=l?.mobile||x,f=t=>{const e=String(t);return["px","em","rem","%","vh","vw"].some((t=>e.endsWith(t)))?e:"number"==typeof t?`${e}px`:""},y=`\n\t\t${m?"":`font-family: '${r}', ${o};`}\n\t\t${s("font-weight",c)}\n\t\t${s("font-size",f(g))}\n\t\t${s("font-style",u)}\n\t\t${s("text-transform",d)}\n\t\t${s("text-decoration",$)}\n\t\t${s("line-height",p)}\n\t\t${s("letter-spacing",b)}\n\t`,k=a&&400!==a?"400i"===a?":ital@1":a?.includes("00i")?`: ital, wght@1, ${a?.replace("00i","00")} `:`: wght@${a} `:"",w=m?"":`https://fonts.googleapis.com/css2?family=${r?.split(" ").join("+")}${k.replace(/ /g,"")}&display=swap`;return{googleFontLink:!i||m?"":`@import url(${w});`,styles:`${t}{\n\t\t\t${y}\n\t\t}\n\t\t@media only screen and (max-width: 1024px) {\n\t\t\t${t}{\n\t\t\t\t${s("font-size",f(x))}\n\t\t\t}\n\t\t}\n\t\t@media only screen and (max-width: 640px) {\n\t\t\t${t}{\n\t\t\t\t${s("font-size",f(h))}\n\t\t\t}\n\t\t}`.replace(/\s+/g," ").trim()}},d="bBlocksCounters",$=window.ReactJSXRuntime,p=({attributes:t,id:e})=>{const{counters:n=[],columnGap:r,rowGap:p,background:b,padding:m,textAlign:g,counterWidth:x,counterHeight:h,iconSize:f,numberTypo:y,labelTypo:k,counterPadding:w,counterBorder:v,counterShadow:j}=t,I=`#${e}`,N=`${I} .${d}`,S=`${N} .counter`;return(0,$.jsx)("style",{dangerouslySetInnerHTML:{__html:`\n\t\t${u("",y)?.googleFontLink}\n\t\t${u("",k)?.googleFontLink}\n\t\t${u(`${S} .counterNumber`,y)?.styles}\n\t\t${u(`${S} .counterLabel`,k)?.styles}\n\t\t\n\t\t${N}{\n\t\t\tgrid-gap: ${p} ${r};\n\t\t\t${a(b)}\n\t\t\tpadding: ${l(m)};\n\t\t}\n\t\t${S}{\n\t\t\ttext-align: ${g};\n\t\t\twidth: ${"0px"===x||"0%"===x||"0em"===x?"250px":x};\n\t\t\theight: ${"0px"===h||"0%"===h||"0em"===h?"250px":h};\n\t\t\tpadding: ${l(w)};\n\t\t\t${c(v)}\n\t\t\tbox-shadow: ${i(j)};\n\t\t}\n\t\t${S} .counterIcon,\n\t\t${S} .counterIconLabel{\n\t\t\tfont-size: ${f||50}px;\n\t\t}\n\n\t\t${n?.map(((t,e)=>{const{background:n,icon:r,number:c,label:i}=t,l=`${I} #counter-${e}`;return`\n\t\t\t\t${l} .counter{\n\t\t\t\t\t${a(n)}\n\t\t\t\t}\n\t\t\t\t${l} .counterIcon i,\n\t\t\t\t${l} .counterIconLabel i{\n\t\t\t\t\t${((t,e=!0,n=!0)=>{const{fontSize:r=16,colorType:a="solid",color:c="inherit",gradient:i=o}=t||{},l="gradient"===a?`color: transparent; background-image: ${i}; -webkit-background-clip: text; background-clip: text;`:s("color",c);return`\n\t\t${r&&e?s("font-size",r?`${r}px`:""):""}\n\t\t${n?l:""}\n\t`})(r)}\n\t\t\t\t\tfont-size: inherit;\n\t\t\t\t}\n\t\t\t\t${l} .counterNumber{\n\t\t\t\t\tcolor: ${c.color};\n\t\t\t\t}\n\t\t\t\t${l} .counterLabel{\n\t\t\t\t\tcolor: ${i.color};\n\t\t\t\t}\n\t\t\t`})).join(" ")}\n\t\t`.replace(/\s+/g," ")}})},b=({attributes:t,counter:e,index:n,labelEl:r,isBackend:o=!1,custom:s={}})=>{const{isIcon:a,iconPosition:c}=t,{icon:i,number:l}=e,{start:u,end:d,prefix:p,suffix:b}=l,m=i?.class&&(0,$.jsx)("i",{className:i.class});return(0,$.jsx)("div",{onClick:()=>o?s.setActiveIndex(n):null,className:o&&n===s.activeIndex?"bPlNowEditing":"",id:`counter-${n}`,children:(0,$.jsxs)("div",{className:"counter",children:[a&&"top"===c&&(0,$.jsx)("div",{className:"counterIcon",children:m}),(0,$.jsxs)("div",{className:"counterNumber",children:[(0,$.jsx)("span",{className:"prefix",children:p}),(0,$.jsx)("span",{className:"number","data-count-start":u,"data-count-end":d,children:u}),(0,$.jsx)("span",{className:"suffix",children:b})]}),"label"===c?(0,$.jsxs)("div",{className:"counterIconLabel",children:[m,r]}):r]})})},m=(t,e)=>{const{char:n=""}=e;return n?t.toString().replace(/\B(?=(\d{3})+(?!\d))/g,n):t};document.addEventListener("DOMContentLoaded",(()=>{document.querySelectorAll(".wp-block-b-blocks-counters").forEach((t=>{const n=JSON.parse(t.dataset.attributes);(0,e.createRoot)(t).render((0,$.jsx)(g,{attributes:n,countersEl:t})),t?.removeAttribute("data-attributes")}))}));const g=({attributes:e,countersEl:n})=>{const{counters:o=[],columns:s,duration:a,separator:c={},isLabel:i}=e;return(0,t.useEffect)((()=>{const t=document.querySelectorAll(`#${n.id} .${d} .counterNumber .number`),e=new IntersectionObserver((n=>{n[0].intersectionRatio<=0||(((t,e,n={})=>{t?.forEach((t=>{const r=parseInt(t.dataset.countStart),o=parseInt(t.dataset.countEnd),s=Date.now(),a=setInterval((()=>{const c=Date.now()-s;c>=e?clearInterval(a):t.innerText=m(parseInt(c/(e/(o-r))+r),n)}),20);setTimeout((()=>{t.innerText=m(o,n)}),e)}))})(t,a,c),e.unobserve(n[0].target))}));e.observe(document.querySelector(`#${n.id} .${d} .counterNumber .number`))}),[]),(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(p,{attributes:e,id:n.id}),(0,$.jsx)("div",{className:`${d} columns-${s.desktop} columns-tablet-${s.tablet} columns-mobile-${s.mobile}`,children:o?.map(((t,n)=>{const{text:o}=t.label,s=i&&o&&(0,$.jsx)("p",{className:"counterLabel",dangerouslySetInnerHTML:{__html:r(o)}});return(0,$.jsx)(b,{attributes:e,counter:t,index:n,labelEl:s},n)}))})]})}})();