"use strict";(globalThis.webpackChunkextendify=globalThis.webpackChunkextendify||[]).push([[788],{6266:(e,t,n)=>{var a=n(9196),r=n(9307),o=n(8817),l=n(5736),s=n(1984),i=n(6993);const c=(0,a.createElement)("svg",{fill:"none",viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg"},(0,a.createElement)("path",{clipRule:"evenodd",d:"m13.505 4h3.3044c.936 0 1.2747.10161 1.6171.29127.3424.19042.6102.46965.7934.82489.1831.356.2801.70824.2801 1.6814v3.43584c0 .9731-.0977 1.3254-.2801 1.6814-.1832.356-.4517.6344-.7934.8248-.153.0852-.3057.1552-.5112.2054v2.7344c0 1.503-.151 2.047-.4327 2.5968-.2828.5498-.6976.9799-1.2252 1.274-.5288.294-1.052.4498-2.4975.4498h-5.10341c-1.44549 0-1.96869-.1569-2.49747-.4498-.52878-.2941-.94242-.7254-1.22526-1.274-.28284-.5487-.43376-1.0938-.43376-2.5968v-5.3051c0-1.50301.15092-2.04701.43264-2.59682.28284-.54981.6976-.98106 1.22638-1.27514.52767-.29293 1.05198-.44985 2.49747-.44985h2.18511c.041-.44652.1265-.69015.2522-.93557.1832-.356.4517-.63523.7941-.82565.3417-.18966.6812-.29127 1.6171-.29127zm-1.6984 2.18698c0-.63769.4973-1.15464 1.1106-1.15464h4.4793c.6133 0 1.1106.51695 1.1106 1.15464v4.65692c0 .6377-.4973 1.1547-1.1106 1.1547h-4.4793c-.6133 0-1.1106-.517-1.1106-1.1547z",fill:"currentColor",fillRule:"evenodd"}));var d=n(270),m=n(782);const u=e=>({open:!1,setOpen:t=>e({open:t}),missingCSSVars:[],addMissingCSSVar:t=>e((e=>e.missingCSSVars.includes(t)?e:{missingCSSVars:[...e.missingCSSVars,t]}))}),p=(0,d.Ue)((0,m.mW)(u,{name:"Extendify Library Globals"}),u),y=()=>{const{setOpen:e}=p(),{incrementActivity:t}=(0,i.j)();return(0,a.createElement)("div",{role:"button",onClick:()=>{window.dispatchEvent(new CustomEvent("extendify-hc:minimize")),e(!0),t("library-button-click")},className:"components-button has-icon is-primary h-8 min-w-0 cursor-pointer px-1 xs:h-9 xs:pl-2 xs:pr-3 sm:ml-2"},(0,a.createElement)(s.Z,{icon:c,size:24}),(0,a.createElement)("span",{className:"ml-1 hidden xs:inline"},(0,l.__)("Design Library","extendify-local")))};var f=n(9818),w=n(6409),g=n(3773),x=n(6989),h=n.n(x),b=n(7403);const v="/extendify/v1/library/settings",E={getItem:async()=>await h()({path:v}),setItem:async(e,t)=>await h()({path:v,method:"POST",data:{state:t}})},S={siteType:{slug:"0default",name:"Default"},category:"",totalImports:0},k=(0,b.a)(window.extLibraryData.siteInfo),C=(0,d.Ue)((0,m.tJ)((e=>{var t,n,a;return{...S,...null!==(t=k?.state)&&void 0!==t?t:{},siteType:null!==(n=null!==(a=window.extSharedData?.siteType)&&void 0!==a?a:k.siteType)&&void 0!==n?n:{},setCategory:t=>e({category:t}),incrementImports:()=>e((e=>({totalImports:Number(e.totalImports)+1})))}}),{name:"extendify_library_site_data",storage:(0,m.FL)((()=>E)),skipHydration:!0})),N={getItem:async()=>await h()({path:"/wp/v2/users/me"}),setItem:async(e,t)=>await h()({path:"/wp/v2/users/me",method:"PUT",data:{extendify_library_user:t}})},_=(0,d.Ue)((0,m.tJ)(((e,t)=>{var n;return{openOnNewPage:!0,updateUserOption:(n,a)=>{Object.keys(t()).includes(n)&&e({[n]:a})},...null!==(n=(0,b.a)(window.extLibraryData.userInfo)?.state)&&void 0!==n?n:{}}}),{name:"extendify_library_user",storage:(0,m.FL)((()=>N)),partialize:e=>({...e,ready:!1}),skipHydration:!0})),P={"--wp--preset--spacing--30":"clamp(1.5rem, 5vw, 2rem)","--wp--preset--spacing--40":"clamp(1.8rem, 1.8rem + ((1vw - 0.48rem) * 2.885), 3rem)","--wp--preset--spacing--50":"clamp(2.5rem, 8vw, 4rem)","--wp--preset--spacing--60":"clamp(2.5rem, 8vw, 6rem)","--wp--preset--spacing--70":"clamp(3.75rem, 10vw, 7rem)","--wp--preset--spacing--80":"clamp(5rem, 5.25rem + ((1vw - 0.48rem) * 9.096), 8rem)"};var L=n(5609),D=n(8357),O=n(827),T=n(2200),F=n(6607);const R=e=>fetch(e).then((e=>e.json()));var I=n(2175),A=n(4981),z=n(3967),V=n.n(z),q=n(2819);const j=(e,t=[])=>Array.from(t).some((t=>!!t.style&&Array.from(t.style).some((t=>t&&t.includes(e))))),B=new WeakMap,U=({insertPattern:e,code:t})=>{const[n,o]=(0,r.useState)(!1),s=(0,r.useRef)(),i=(0,r.useMemo)((()=>(0,A.rawHandler)({HTML:$(t)})),[t]),{ready:c}=(({container:e,onIFrameLoaded:t,ready:n,loadDelay:a})=>{const o=(()=>{const e=(0,r.useRef)(!1);return(0,r.useEffect)((()=>(e.current=!0,()=>e.current=!1))),e})(),[l,s]=(0,r.useState)(0),[i,c]=(0,r.useState)(null),[d,m]=(0,r.useState)(!1),u=(0,r.useRef)(!1),{addMissingCSSVar:y}=p(),f=(0,r.useCallback)((e=>{if(!e?.contentDocument)return;const t=getComputedStyle(e.contentDocument.documentElement),n=e.contentDocument.styleSheets;for(let a in P)t.getPropertyValue(a)||Array.from(n).filter((e=>{try{return e.cssRules}catch(e){return!1}})).some((e=>j(a,e.cssRules)))||(y(a),e.contentDocument.documentElement.style.setProperty(a,P[a]))}),[y]),w=(0,r.useCallback)((async(e,t)=>{var n;if(e.getBoundingClientRect().toprequestAnimationFrame(e))),await new Promise((e=>requestAnimationFrame(e)));for(const t of o){if(!e.contentDocument?.defaultView)return;const n=parseFloat(e.contentDocument.defaultView.getComputedStyle(t).height);t.offsetHeight,t.style.minHeight=n>500?"500px":n+"px"}e.style.setProperty("max-height","none","important"),u.current=!1}),[]);return(0,r.useEffect)((()=>{if(!n)return;const a=setTimeout((()=>{if(i)return;const n=e?.querySelector("iframe[title]");if(!n)return s((e=>e+1));c(n),requestAnimationFrame((()=>t(n,e)))}),100);return()=>clearTimeout(a)}),[i,n,l,e,t]),(0,r.useEffect)((()=>{if(m(!1),!i?.contentDocument)return;const t={attributes:!1,childList:!0,subtree:!0};requestAnimationFrame((()=>n(i,e)));const n=(0,q.debounce)((async()=>{o.current&&!u.current&&(r.disconnect(),await w(i,e),"extendable"!==window.extSharedData.themeSlug&&await f(i,e),setTimeout((()=>m(!0)),a),o.current&&r.observe(i.contentDocument,t))}),300),r=new MutationObserver(n);return r.observe(i.contentDocument,t),()=>{n.cancel(),r?.disconnect()}}),[i,e,o,n,w,f,a]),{loading:!i,ready:d}})({container:s.current,ready:n,onIFrameLoaded:()=>{},loadDelay:50});return(0,r.useEffect)((()=>o(!0)),[]),(0,a.createElement)("button",{ref:s,type:"button","aria-label":(0,l.__)("Insert Pattern","extendify-local"),className:V()("library-pattern relative z-10 m-0 mb-8 inline-block w-full cursor-pointer border bg-transparent p-0 focus:shadow-sm focus:outline-none focus:ring-wp focus:ring-design-main focus:ring-offset-2 focus:ring-offset-[#FAFAFA]",{"border-transparent opacity-0":!c,"border-gray-400 opacity-100":c}),onClick:()=>e(i)},(0,a.createElement)(I.BlockPreview,{blocks:i,live:!1,viewportWidth:1400,additionalStyles:[{css:'.rich-text [data-rich-text-placeholder]:after { content: "" }'}]}))},$=e=>e.replace(/(https?:\/\/\S+\?w=\d+)/gi,"$1&q=10&auto=format,compress&fm=avif"),H=({insertPattern:e,siteType:t,category:n})=>{const{data:o,isLoading:s,setSize:i}=(e=>{const t={siteType:void 0,category:void 0,wpVersion:window.extSharedData.wpVersion,lang:window.extSharedData.wpLanguage||null,showLocalizedCopy:window.extSharedData.showLocalizedCopy||null,...e},{data:n,error:a,isLoading:r,isValidating:o,mutate:l,size:s,setSize:i}=(0,F.ZP)(((e,n)=>{if(!t.category)return null;if(n&&!n.length)return null;const a=new URLSearchParams({page:e+1});return Object.entries(t).filter((([,e])=>void 0!==e)).forEach((([e,t])=>{a.append(e,t)})),`${T.kE}/api/patterns?${a.toString()}`}),R,{initialSize:2,revalidateFirstPage:!1,revalidateIfStale:!1,revalidateOnFocus:!1,revalidateOnReconnect:!1});return{data:n,error:a,isLoading:r,isValidating:o,mutate:l,size:s,setSize:i}})({siteType:t?.slug,category:n}),[c,d]=(0,r.useState)(!0),[m,u]=(0,D.YD)(),p=o?.at(-1)?.length<9;return(0,r.useEffect)((()=>{if(s)return d(!0);const e=setTimeout((()=>{d(!1)}),750);return()=>clearTimeout(e)}),[s]),(0,r.useEffect)((()=>{u&&!s&&i((e=>e+1))}),[u,s,i]),s||!o?.length?(0,a.createElement)("div",{className:"absolute inset-0 flex flex-col items-center justify-center text-center"},(0,a.createElement)(L.Spinner,null),(0,a.createElement)("span",{className:"sr-only"},(0,l.__)("Loading Patterns...","extendify-local"))):(0,a.createElement)(a.Fragment,null,(0,a.createElement)(O.Z,{breakpointCols:{default:3,1600:2,1e3:1,783:2,600:1},columnClassName:"",className:"relative flex w-full gap-6 p-8 pt-2"},o.map((t=>t.map((({id:t,code:n,patternReplacementCode:r})=>(0,a.createElement)(U,{key:t,insertPattern:e,code:null!=r?r:n})))))),c?(0,a.createElement)("div",{className:"absolute inset-0 z-0 flex flex-col items-center justify-center text-center"},(0,a.createElement)(L.Spinner,null),(0,a.createElement)("span",{className:"sr-only"},(0,l.__)("Loading Patterns...","extendify-local"))):null,c||p?null:(0,a.createElement)("div",{ref:m,className:"mb-6 mt-6 flex w-full justify-center md:mt-2"},(0,a.createElement)(L.Spinner,null),(0,a.createElement)("span",{className:"sr-only"},(0,l.__)("Loading more patterns...","extendify-local"))))};var M=n(9870);const Z=async()=>{const e=new URLSearchParams({wpVersion:window.extSharedData.wpVersion||null,lang:window.extSharedData.wpLanguage||null});return await fetch(`${T.kE}/api/categories?${e.toString()}`).then((e=>e.json()))},J=(0,d.Ue)((0,m.tJ)((e=>({categories:[],setCategories:t=>e({categories:t})})),{name:"extendify-library-cache"})),W=()=>{const{category:e,siteType:t,setCategory:n}=C(),{data:o,isLoading:s,errorCount:i}=(()=>{var e;const[t,n]=(0,r.useState)(0),a=null!==(e=window.extSharedData?.wpLanguage)&&void 0!==e?e:"en_US",{data:o,error:l,isLoading:s}=(0,M.Z)(`categories-${a}`,Z,{onError:()=>n((e=>e+1)),onSuccess:()=>n(0)});return{data:o,errorCount:t>1?t:l?1:0,isLoading:s}})(),{categories:c,setCategories:d}=J();return(0,r.useEffect)((()=>{s||i||d(o)}),[o,s,d,i]),(0,r.useEffect)((()=>{const a=e=>t?.name&&document.querySelector(`#extendify-library-category-${e}`)?.focus();if(c?.length){if(e){if("all"===e)return a("all");if(c?.find((({slug:t})=>t===e)))return a(e)}n("all"),a("all")}}),[e,n,c,t?.name]),(0,a.createElement)(L.PanelBody,{title:(0,l.__)("Design Type","extendify-local"),className:"ext-type-control p-0",initialOpen:!!t?.name},(0,a.createElement)(L.PanelRow,null,(0,a.createElement)(G,{categories:c,errorCount:i,current:e,setCurrent:n})))},G=({categories:e,errorCount:t,current:n,setCurrent:r})=>{const o=e=>V()("text-sm w-full text-left rtl:text-right px-3 py-1 mb-0.5 block cursor-pointer rounded",{"bg-design-main text-design-text":n===e,"bg-transparent text-gray-900 hover:bg-gray-100":n!==e});return e?.length?(0,a.createElement)("ul",{className:"m-0 -mt-1.5 max-h-half w-full overflow-y-auto rounded-b border border-gray-300 px-1 py-2"},(0,a.createElement)("li",{className:"m-0 p-0"},(0,a.createElement)("button",{type:"button",id:"extendify-library-category-all",onClick:()=>r("all"),className:o("all")},(0,l.__)("All","extendify-local"))),e.map((({slug:e,id:t,name:n})=>(0,a.createElement)("li",{key:t,className:"m-0 p-0"},(0,a.createElement)("button",{type:"button",id:`extendify-library-category-${e}`,onClick:()=>r(e),className:o(e)},n))))):t>1?(0,a.createElement)("div",{className:"-mt-1 flex w-full flex-col items-center justify-center gap-2 border-t border-gray-300 p-2"},(0,a.createElement)("span",null,(0,l.__)("Retrying...","extendify-local")),(0,a.createElement)(L.Spinner,null)):(0,a.createElement)("div",{className:"-mt-1 flex w-full justify-center border-t border-gray-300 p-2"},(0,a.createElement)("span",{className:"sr-only"},(0,l.__)("Fetching...","extendify-local")),(0,a.createElement)(L.Spinner,null))},{partnerLogo:Y,partnerName:K}=window.extSharedData,Q=()=>(0,a.createElement)("div",{className:"hidden flex-shrink-0 flex-col gap-6 md:flex md:w-80"},Y?(0,a.createElement)("div",{className:"flex justify-center bg-banner-main p-6 py-0"},(0,a.createElement)("div",{className:"flex h-20 w-40 items-center justify-center py-3"},(0,a.createElement)("img",{className:"max-h-full max-w-full",src:Y,alt:K}))):(0,a.createElement)("div",{className:"-mb-5 hidden px-5 py-3 text-extendify-black sm:flex sm:pt-5"},(0,a.createElement)(s.Z,{icon:c,size:40})),(0,a.createElement)("div",{className:"flex flex-col gap-4 overflow-y-auto pb-16"},(0,a.createElement)("div",{id:"extendify-library-category-control","data-test":"category-control",className:"hidden flex-col overflow-x-hidden px-4 md:flex"},(0,a.createElement)(W,null)))),X=({onClose:e})=>(0,a.createElement)("button",{className:"block h-6 w-6 cursor-pointer bg-transparent p-px text-inherit outline-none focus:shadow-none focus:ring-wp focus:ring-design-main",type:"button",onClick:e,"data-test":"modal-close-button","aria-label":(0,l.__)("Close","extendify-local")},(0,a.createElement)("svg",{style:{fill:"currentColor"},xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,a.createElement)("path",{d:"M13 11.8l6.1-6.3-1-1-6.1 6.2-6.1-6.2-1 1 6.1 6.3-6.5 6.7 1 1 6.5-6.6 6.5 6.6 1-1z"}))),ee=({openOnNewPage:e,updateUserOption:t,onClose:n})=>(0,a.createElement)("div",{className:"mb-2 flex h-16 flex-shrink-0 items-center justify-end gap-6 px-8"},(0,a.createElement)("label",{className:"mt-4 flex items-center gap-2",htmlFor:"extendify-open-on-new-pages",title:(0,l.sprintf)( // translators: %s: Extendify Library term (0,l.__)("Toggle %s on new pages","extendify-local"),"Extendify Library")},(0,a.createElement)("input",{id:"extendify-open-on-new-pages",className:"m-0 rounded-sm border border-solid border-gray-900",type:"checkbox",checked:e,onChange:e=>t("openOnNewPage",e.target.checked)}),(0,a.createElement)("span",null,(0,l.__)("Open for new pages","extendify-local"))),(0,a.createElement)("div",{className:"mt-4"},(0,a.createElement)(X,{onClose:n}))),te=window?.location?.pathname?.includes("post-new.php"),ne=()=>{const{incrementActivity:e}=(0,i.j)(),{open:t,setOpen:n}=p(),{updateUserOption:o,openOnNewPage:s}=_(),{category:c,siteType:d,incrementImports:m}=C(),{createNotice:u}=(0,f.dispatch)("core/notices"),y=(0,r.useRef)(!1),x=()=>{n(!1)};return(0,r.useLayoutEffect)((()=>{if(!t&&!y.current)return y.current=!0,s&&te?(window.dispatchEvent(new CustomEvent("extendify-hc:minimize")),e("library-auto-open"),void n(!0)):void(new URLSearchParams(window.location.search).has("ext-open")&&(n(!0),e("library-search-param-auto-open")))}),[s,n,e,t]),(0,r.useEffect)((()=>{const e=new URLSearchParams(window.location.search);e.has("ext-close")&&(n(!1),e.delete("ext-close"),window.history.replaceState({},"",window.location.pathname+"?"+e.toString()))}),[n,e]),(0,r.useEffect)((()=>{const e=()=>n(!0),t=()=>n(!1);return window.addEventListener("extendify::open-library",e),window.addEventListener("extendify::close-library",t),()=>{window.removeEventListener("extendify::open-library",e),window.removeEventListener("extendify::close-library",t)}}),[n,t]),t?(0,a.createElement)(w.Vq,{className:"extendify-library extendify-library-modal",open:t,static:!0,onClose:()=>{}},(0,a.createElement)("div",{className:"absolute mx-auto h-full w-full md:p-8"},(0,a.createElement)("div",{className:"fixed inset-0 bg-black/30",style:{backdropFilter:"blur(2px)"},"aria-hidden":"true"}),(0,a.createElement)(g.E.div,{key:"library-modal",initial:{y:30,opacity:0},animate:{y:0,opacity:1},exit:{y:0,opacity:0},transition:{duration:.3},className:"relative mx-auto h-full w-full max-w-screen-3xl bg-white shadow-2xl sm:flex sm:overflow-hidden"},(0,a.createElement)(w.Vq.Title,{className:"sr-only"},(0,l.__)("Design Patterns","extendify-local")),(0,a.createElement)(Q,null),(0,a.createElement)("div",{className:"relative flex w-full flex-col bg-[#FAFAFA]"},(0,a.createElement)(ee,{openOnNewPage:s,updateUserOption:o,onClose:x}),(0,a.createElement)("div",{id:"extendify-library-patterns-list",className:"flex-grow overflow-y-auto"},(0,a.createElement)(H,{insertPattern:async e=>{await(async e=>{const{insertBlocks:t,replaceBlock:n}=(0,f.dispatch)("core/block-editor"),{getSelectedBlock:a,getBlockHierarchyRootClientId:r,getBlockIndex:o,getGlobalBlockCount:l}=(0,f.select)("core/block-editor"),{clientId:s,name:i,attributes:c}=a()||{},d=s?r(s):"",m=(d?o(d):l())+1,{missingCSSVars:u}=p.getState();return u.forEach((e=>{document?.documentElement?.style?.setProperty(e,P[e]),document.querySelector('iframe[name="editor-canvas"]')?.contentDocument?.documentElement?.style?.setProperty(e,P[e])})),u.length&&(async e=>{var t;const n=window.extSharedData.globalStylesPostID,{styles:a,settings:r}=await h()({path:`/wp/v2/global-styles/${n}`});if(!(e=e.filter((e=>!a?.css?.includes(`${e}:`)))).length)return;const o=e.reduce(((e,t)=>e+`${t}: ${P[t]};\n`),":root {\n")+"\n}";h()({path:`/wp/v2/global-styles/${n}`,method:"PATCH",data:{id:n,settings:r,styles:{...a,css:(null!==(t=a?.css)&&void 0!==t?t:"")+(a?.css?"\n":"")+o}}})})(u),"core/paragraph"===i&&""===c?.content?await n(s,e):await t(e,m)})(e),m(),x(),u("info",(0,l.__)("Pattern added","extendify-local"),{isDismissible:!0,type:"snackbar"}),await(async(e,t)=>await h()({path:"/extendify/v1/library/settings/single",method:"POST",data:{key:"extendify_check_for_image_imports",value:!0}}))()},category:c,siteType:d})))))):null};(0,o.registerPlugin)("extendify-library",{render:()=>{if("function"!=typeof r.createRoot)return;const e="extendify-library-btn",t="extendify-library",n=".edit-post-header-toolbar",o=".edit-site-header-edit-mode__start";(document.querySelector(n)||document.querySelector(o))&&requestAnimationFrame((()=>{if(document.getElementById(e))return;const l=document.createElement("div"),s=Object.assign(l,{id:e,className:t});document.querySelector(n)?.append(s),document.querySelector(o)?.append(s),(0,r.createRoot)(s).render((0,a.createElement)(y,null));const i="extendify-library-modal";if(document.getElementById(i))return;const c=document.createElement("div"),d=Object.assign(c,{id:i,className:t});document.body.append(d),(0,r.createRoot)(d).render((0,a.createElement)(ne,null))}))}})},9196:e=>{e.exports=window.React},1850:e=>{e.exports=window.ReactDOM},2819:e=>{e.exports=window.lodash},6989:e=>{e.exports=window.wp.apiFetch},2175:e=>{e.exports=window.wp.blockEditor},4981:e=>{e.exports=window.wp.blocks},5609:e=>{e.exports=window.wp.components},9818:e=>{e.exports=window.wp.data},9307:e=>{e.exports=window.wp.element},5736:e=>{e.exports=window.wp.i18n},8817:e=>{e.exports=window.wp.plugins}},e=>{e.O(0,[746,857],(()=>(6266,e(e.s=6266)))),e.O()}]);