@grapesjs/studio-sdk-plugins 1.0.21-rc.1 → 1.0.21

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";const V="app.grapesjs.com",k="app-stage.grapesjs.com",I=[V,k,"localhost","127.0.0.1",".local-credentialless.webcontainer.io",".local.webcontainer.io","-sandpack.codesandbox.io"],X="license:check:start",j="license:check:end",F=()=>typeof window<"u",q=({isDev:e,isStage:a})=>`${e?"":`https://${a?k:V}`}/api`,J=()=>{const e=F()&&window.location.hostname;return!!e&&(I.includes(e)||I.some(a=>e.endsWith(a)))};function z(e){return typeof e=="function"}async function Q({path:e,baseApiUrl:a,method:u="GET",headers:l={},params:d,body:n}){const s=`${a||q({isDev:!1,isStage:!1})}${e}`,m={method:u,headers:{"Content-Type":"application/json",...l}};n&&(m.body=JSON.stringify(n));const h=d?new URLSearchParams(d).toString():"",t=h?`?${h}`:"",o=await fetch(`${s}${t}`,m);if(!o.ok)throw new Error(`HTTP error! status: ${o.status}`);return o.json()}var P=(e=>(e.free="free",e.startup="startup",e.business="business",e.enterprise="enterprise",e))(P||{});const W={[P.free]:0,[P.startup]:10,[P.business]:20,[P.enterprise]:30};function Z(e){const a=e;return a.init=u=>l=>e(l,u),a}const ee=e=>Z(e);async function te({editor:e,plan:a,pluginName:u,licenseKey:l,cleanup:d}){let n="",c=!1;const s=J(),m=t=>{console.warn("Cleanup plugin:",u,"Reason:",t),d()},h=(t={})=>{var E;const{error:o,sdkLicense:f}=t,i=(E=t.plan)==null?void 0:E.category;if(!(f||t.license)||o)m(o||"Invalid license");else if(i){const b=W[a],v=W[i];b>v&&m({pluginRequiredPlan:a,licensePlan:i})}};e.on(X,t=>{n=t==null?void 0:t.baseApiUrl,c=!0}),e.on(j,t=>{h(t)}),setTimeout(async()=>{if(!c){if(s)return;if(l){const t=await ne({licenseKey:l,pluginName:u,baseApiUrl:n});t&&h(t)}else m("The `licenseKey` option not provided")}},2e3)}async function ne(e){const{licenseKey:a,pluginName:u,baseApiUrl:l}=e;try{return(await Q({baseApiUrl:l,path:`/sdk/${a||"na"}`,method:"POST",params:{d:window.location.hostname,pn:u}})).result||{}}catch(d){return console.error("Error during SDK license check:",d),!1}}const se="canvasAbsoluteMode",oe=P.startup,ce=(e,a,u)=>{const l=u.enableAbsolute??(m=>m.hasAbsolute),n=(Array.isArray(a)?a:a?[a]:[...e.getSelectedAll()])[0];if(!n)return;const c=n.getEl();return{result:z(l)?l({component:n,hasAbsolute:!!c&&getComputedStyle(c).position==="absolute"}):!1,component:n,dmode:n.get("dmode")}};function B({guideMatched:e,canvasView:a}){var L;const u=e.guide.x===void 0?"y":"x";let l=0,d=0,n=0,c=0;const{guide:s,matched:m}=e,h=a.getElBoxRect(s.componentView.el),t=a.getElBoxRect(((L=m.componentView)==null?void 0:L.el)||m.componentEl),o=h.y,f=h.y+h.height,i=h.x,x=h.x+h.width,E=t.y,b=t.y+t.height,v=t.x,_=t.x+t.width,S=Math.max(0,o-b),p=Math.max(0,E-f),w=Math.max(0,i-_),A=Math.max(0,v-x),r=S>p,g=w>A,y=s.type;return u==="x"&&(y==="l"?(l=i,r?(d=b,n=S):(d=f,n=p)):y==="r"?(l=x,r?(d=b,n=S):(d=f,n=p)):y==="x"&&(l=i-(i-x)/2,r?(d=b,n=S):(d=f,n=p))),u==="y"&&(y==="t"?(d=o,g?(l=_,c=w):(l=x,c=A)):y==="b"?(d=f,g?(l=_,c=w):(l=x,c=A)):y==="y"&&(d=o-(o-f)/2,g?(l=_,c=w):(l=x,c=A))),{axis:u,x:l,y:d,width:c,height:n}}function ie({guideMatched:e,component:a,canvasView:u}){const l=e.guide.x===void 0?"x":"y",{guide:d,matched:n}=e,c=d.type,s=n.type,m=u.getElementPos(d.componentView.el).rect,h=u.getElementPos(n.componentView.el).rect;if(l==="x"){const t=m.height,o=h.top,f=h.top+h.height;let i=0;c==="t"?s==="t"?i=o-t:s==="b"?i=f-t:s==="y"&&(i=o-t-(o-f)/2):c==="b"?s==="t"?i=o-t*2:s==="b"?i=f-t*2:s==="y"&&(i=o-t*2-(o-f)/2):c==="y"&&(s==="t"?i=o-t*1.5:s==="b"?i=f-t*1.5:s==="y"&&(i=o-t*1.5-(o-f)/2)),a.addStyle({top:`${i-5}px`},{partial:!0})}if(l==="y"){const t=m.width,o=h.left,f=h.left+h.width;let i=0;c==="l"?s==="l"?i=o:s==="r"?i=f:s==="x"&&(i=o-(o-f)/2):c==="r"?s==="l"?i=o-t:s==="r"?i=f-t:s==="x"&&(i=o-t-(o-f)/2):c==="x"&&(s==="l"?i=o-t/2:s==="r"&&(i=f-t/2)),a.addStyle({left:`${i}px`},{partial:!0})}}function H({snapping:e,editor:a,props:u}){var R,O;const{command:l,guidesMatched:d}=u,n=u.component,c=n.getEl(),s=a.Canvas.getCanvasView(),{x:m,y:h}=e??{x:10,y:10},t=l.opts.event,o=t.clientX,f=t.clientY;if(!n.__lastSnappedPosition){const T=s.getElBoxRect(c),M=o-T.x,D=f-T.y;n.__lastSnappedPosition={left:T.x,top:T.y},n.__dragOffset={x:M,y:D}}const i=((R=n.__dragOffset)==null?void 0:R.x)||0,x=((O=n.__dragOffset)==null?void 0:O.y)||0,E=n.__lastSnappedPosition,b=o-E.left-i,v=f-E.top-x;let _=E.left,S=E.top;const p=d==null?void 0:d[0],w=(p==null?void 0:p.guide.type)==="l",A=(p==null?void 0:p.guide.type)==="x",r=(p==null?void 0:p.guide.type)==="r",g=(p==null?void 0:p.guide.type)==="t",y=(p==null?void 0:p.guide.type)==="b",L=(p==null?void 0:p.guide.type)==="y";if(p){const{x:T,y:M}=B({guideMatched:p,canvasView:s}),D=c.offsetWidth,G=c.offsetHeight;w?_=T:r?_=T-D:A?_=T-D/2:g?S=M:y?S=M-G:L&&(S=M-G/2),n.__lastSnappedGuideMatched=p}else Math.abs(b)>=m&&(_=Math.round((E.left+b)/m)*m,n.__lastSnappedGuideMatched=null),Math.abs(v)>=h&&(S=Math.round((E.top+v)/h)*h,n.__lastSnappedGuideMatched=null);return n.addStyle({left:`${_}px`,top:`${S}px`},{partial:!0}),n.__lastSnappedPosition={left:_,top:S},{x:_,y:S,guideMatched:n.__lastSnappedGuideMatched}}function ae({snapping:e,props:a,editor:u}){const{x:l,y:d}=H({snapping:e,props:a,editor:u}),n=a.component;n.addStyle({left:`${l}px`,top:`${d}px`}),delete n.__lastSnappedPosition,delete n.__lastSnappedGuideMatched}const le="core:component-drag",de="studio:setDragAbsolute",fe="dmode:start",Y="dmode:move",K="dmode:end",$="dragAbsolute",re="select",pe="hover",ue="spacing",he=function(e,a={}){const{Commands:u}=e,l=u.events,d=u.getConfig().defaultOptions??{},n=`${l.runBeforeCommand}tlb-move`;d[le]={run:r=>({...r,skipGuidesRender:!0})};const{snapping:c,locking:s,globalAbsolute:m=!0}=a;m&&e.setDragMode("absolute");const h=!!(c!=null&&c.x||c!=null&&c.y),t=!!(s!=null&&s.x||s!=null&&s.y),{Canvas:o}=e;let f=null;const i=r=>{const{component:g,guidesMatched:y,command:L}=r,R=g.view,O=e.Canvas.getCanvasView(),T=g.getEl();let M=y.map(C=>C.matched.componentEl),D=y.map(C=>B({guideMatched:C,canvasView:O}));if(h){const{guideMatched:C}=H({snapping:c,props:r,editor:e});C?(M=[C.matched.componentEl],D=[B({guideMatched:C,canvasView:O})]):(M=[],D=[])}if(t)if(L.opts.event.shiftKey)if(!f)f=y[0];else{const N=f,U=N.guide.x===void 0?"x":"y";(U==="x"&&(s==null?void 0:s.x)||U==="y"&&(s==null?void 0:s.y))&&(ie({guideMatched:N,component:g,canvasView:O}),M=[N.matched.componentEl],D=[B({guideMatched:N,canvasView:O})])}else f=null;const G={id:$,type:$,component:g,componentView:R,originComponent:T,matchedComponents:M,originMatchedDistances:D};o.addSpot(G)},x=({enabled:r})=>{e.runCommand(de,{enabled:r})},E=({type:r})=>{o.removeSpots({type:r})},b=()=>{E({type:re}),E({type:pe}),E({type:ue})},v=r=>{x({enabled:!0}),i(r),b()},_=r=>{i(r),b()},S=r=>{E({type:$}),h&&ae({snapping:c,props:r,editor:e}),x({enabled:!1})},A=[[fe,r=>{v(r),e.on(Y,_);const g=()=>{S(r),e.off(Y,_),e.off(K,g)};e.on(K,g)}],[n,r=>{if(m)return;const g=r.options.target,y=ce(e,g,a);y!=null&&y.result&&!y.dmode&&y.component.set({dmode:"absolute"})}]];A.forEach(([r,g])=>e.on(r,g)),te({editor:e,licenseKey:a.licenseKey,plan:oe,pluginName:se,cleanup:()=>{x({enabled:!1}),A.forEach(([r,g])=>e.off(r,g))}})},me=ee(he);module.exports=me;
1
+ "use strict";const V="app.grapesjs.com",k="app-stage.grapesjs.com",I=[V,k,"localhost","127.0.0.1",".local-credentialless.webcontainer.io",".local.webcontainer.io","-sandpack.codesandbox.io"],X="license:check:start",j="license:check:end",F=()=>typeof window<"u",q=({isDev:e,isStage:a})=>`${e?"":`https://${a?k:V}`}/api`,J=()=>{const e=F()&&window.location.hostname;return!!e&&(I.includes(e)||I.some(a=>e.endsWith(a)))};function z(e){return typeof e=="function"}async function Q({path:e,baseApiUrl:a,method:u="GET",headers:l={},params:d,body:n}){const o=`${a||q({isDev:!1,isStage:!1})}${e}`,m={method:u,headers:{"Content-Type":"application/json",...l}};n&&(m.body=JSON.stringify(n));const h=d?new URLSearchParams(d).toString():"",t=h?`?${h}`:"",s=await fetch(`${o}${t}`,m);if(!s.ok)throw new Error(`HTTP error! status: ${s.status}`);return s.json()}var P=(e=>(e.free="free",e.startup="startup",e.business="business",e.enterprise="enterprise",e))(P||{});const W={[P.free]:0,[P.startup]:10,[P.business]:20,[P.enterprise]:30};function Z(e){const a=e;return a.init=u=>l=>e(l,u),a}const ee=e=>Z(e);async function te({editor:e,plan:a,pluginName:u,licenseKey:l,cleanup:d}){let n="",c=!1;const o=J(),m=t=>{console.warn("Cleanup plugin:",u,"Reason:",t),d()},h=(t={})=>{var E;const{error:s,sdkLicense:r}=t,i=(E=t.plan)==null?void 0:E.category;if(!(r||t.license)||s)m(s||"Invalid license");else if(i){const b=W[a],v=W[i];b>v&&m({pluginRequiredPlan:a,licensePlan:i})}};e.on(X,t=>{n=t==null?void 0:t.baseApiUrl,c=!0}),e.on(j,t=>{h(t)}),setTimeout(async()=>{if(!c){if(o)return;if(l){const t=await ne({licenseKey:l,pluginName:u,baseApiUrl:n});t&&h(t)}else m("The `licenseKey` option not provided")}},2e3)}async function ne(e){const{licenseKey:a,pluginName:u,baseApiUrl:l}=e;try{return(await Q({baseApiUrl:l,path:`/sdk/${a||"na"}`,method:"POST",params:{d:window.location.hostname,pn:u}})).result||{}}catch(d){return console.error("Error during SDK license check:",d),!1}}const oe="canvasAbsoluteMode",se=P.startup,ce=(e,a,u)=>{const l=u.enableAbsolute??(m=>m.hasAbsolute),n=(Array.isArray(a)?a:a?[a]:[...e.getSelectedAll()])[0];if(!n)return;const c=n.getEl();return{result:z(l)?l({component:n,hasAbsolute:!!c&&getComputedStyle(c).position==="absolute"}):!1,component:n,dmode:n.get("dmode")}};function B({guideMatched:e,canvasView:a}){var L;const u=e.guide.x===void 0?"y":"x";let l=0,d=0,n=0,c=0;const{guide:o,matched:m}=e,h=a.getElBoxRect(o.componentView.el),t=a.getElBoxRect(((L=m.componentView)==null?void 0:L.el)||m.componentEl),s=h.y,r=h.y+h.height,i=h.x,x=h.x+h.width,E=t.y,b=t.y+t.height,v=t.x,_=t.x+t.width,S=Math.max(0,s-b),p=Math.max(0,E-r),w=Math.max(0,i-_),A=Math.max(0,v-x),f=S>p,g=w>A,y=o.type;return u==="x"&&(y==="l"?(l=i,f?(d=b,n=S):(d=r,n=p)):y==="r"?(l=x,f?(d=b,n=S):(d=r,n=p)):y==="x"&&(l=i-(i-x)/2,f?(d=b,n=S):(d=r,n=p))),u==="y"&&(y==="t"?(d=s,g?(l=_,c=w):(l=x,c=A)):y==="b"?(d=r,g?(l=_,c=w):(l=x,c=A)):y==="y"&&(d=s-(s-r)/2,g?(l=_,c=w):(l=x,c=A))),{axis:u,x:l,y:d,width:c,height:n}}function ie({guideMatched:e,component:a,canvasView:u}){const l=e.guide.x===void 0?"x":"y",{guide:d,matched:n}=e,c=d.type,o=n.type,m=u.getElementPos(d.componentView.el).rect,h=u.getElementPos(n.componentView.el).rect;if(l==="x"){const t=m.height,s=h.top,r=h.top+h.height;let i=0;c==="t"?o==="t"?i=s-t:o==="b"?i=r-t:o==="y"&&(i=s-t-(s-r)/2):c==="b"?o==="t"?i=s-t*2:o==="b"?i=r-t*2:o==="y"&&(i=s-t*2-(s-r)/2):c==="y"&&(o==="t"?i=s-t*1.5:o==="b"?i=r-t*1.5:o==="y"&&(i=s-t*1.5-(s-r)/2)),a.addStyle({top:`${i-5}px`},{partial:!0})}if(l==="y"){const t=m.width,s=h.left,r=h.left+h.width;let i=0;c==="l"?o==="l"?i=s:o==="r"?i=r:o==="x"&&(i=s-(s-r)/2):c==="r"?o==="l"?i=s-t:o==="r"?i=r-t:o==="x"&&(i=s-t-(s-r)/2):c==="x"&&(o==="l"?i=s-t/2:o==="r"&&(i=r-t/2)),a.addStyle({left:`${i}px`},{partial:!0})}}function H({snapping:e,editor:a,props:u}){var R,O;const{command:l,guidesMatched:d}=u,n=u.component,c=n.getEl(),o=a.Canvas.getCanvasView(),{x:m,y:h}=e??{x:10,y:10},t=l.opts.event,s=t.clientX,r=t.clientY;if(!n.__lastSnappedPosition){const T=o.getElBoxRect(c),M=s-T.x,D=r-T.y;n.__lastSnappedPosition={left:T.x,top:T.y},n.__dragOffset={x:M,y:D}}const i=((R=n.__dragOffset)==null?void 0:R.x)||0,x=((O=n.__dragOffset)==null?void 0:O.y)||0,E=n.__lastSnappedPosition,b=s-E.left-i,v=r-E.top-x;let _=E.left,S=E.top;const p=d==null?void 0:d[0],w=(p==null?void 0:p.guide.type)==="l",A=(p==null?void 0:p.guide.type)==="x",f=(p==null?void 0:p.guide.type)==="r",g=(p==null?void 0:p.guide.type)==="t",y=(p==null?void 0:p.guide.type)==="b",L=(p==null?void 0:p.guide.type)==="y";if(p){const{x:T,y:M}=B({guideMatched:p,canvasView:o}),D=c.offsetWidth,G=c.offsetHeight;w?_=T:f?_=T-D:A?_=T-D/2:g?S=M:y?S=M-G:L&&(S=M-G/2),n.__lastSnappedGuideMatched=p}else Math.abs(b)>=m&&(_=Math.round((E.left+b)/m)*m,n.__lastSnappedGuideMatched=null),Math.abs(v)>=h&&(S=Math.round((E.top+v)/h)*h,n.__lastSnappedGuideMatched=null);return n.addStyle({left:`${_}px`,top:`${S}px`},{partial:!0}),n.__lastSnappedPosition={left:_,top:S},{x:_,y:S,guideMatched:n.__lastSnappedGuideMatched}}function ae({snapping:e,props:a,editor:u}){const{x:l,y:d}=H({snapping:e,props:a,editor:u}),n=a.component;n.addStyle({left:`${l}px`,top:`${d}px`}),delete n.__lastSnappedPosition,delete n.__lastSnappedGuideMatched}const le="core:component-drag",de="studio:setDragAbsolute",fe="dmode:start",Y="dmode:move",K="dmode:end",$="dragAbsolute",re="select",pe="hover",ue="spacing",he=function(e,a={}){const{Commands:u}=e,l=u.events,d=u.getConfig().defaultOptions??{},n=`${l.runBeforeCommand}tlb-move`;d[le]={run:f=>({...f,skipGuidesRender:!0})};const{snapping:c,locking:o,globalAbsolute:m=!0}=a;m&&e.setDragMode("absolute");const h=!!(c!=null&&c.x||c!=null&&c.y),t=!!(o!=null&&o.x||o!=null&&o.y),{Canvas:s}=e;let r=null;const i=f=>{const{component:g,guidesMatched:y,command:L}=f,R=g.view,O=e.Canvas.getCanvasView(),T=g.getEl();let M=y.map(C=>C.matched.componentEl),D=y.map(C=>B({guideMatched:C,canvasView:O}));if(h){const{guideMatched:C}=H({snapping:c,props:f,editor:e});C?(M=[C.matched.componentEl],D=[B({guideMatched:C,canvasView:O})]):(M=[],D=[])}if(t)if(L.opts.event.shiftKey)if(!r)r=y[0];else{const N=r,U=N.guide.x===void 0?"x":"y";(U==="x"&&(o==null?void 0:o.x)||U==="y"&&(o==null?void 0:o.y))&&(ie({guideMatched:N,component:g,canvasView:O}),M=[N.matched.componentEl],D=[B({guideMatched:N,canvasView:O})])}else r=null;const G={id:$,type:$,component:g,componentView:R,originComponent:T,matchedComponents:M,originMatchedDistances:D};s.addSpot(G)},x=({enabled:f})=>{e.runCommand(de,{enabled:f})},E=({type:f})=>{s.removeSpots({type:f})},b=()=>{E({type:re}),E({type:pe}),E({type:ue})},v=f=>{x({enabled:!0}),i(f),b()},_=f=>{i(f),b()},S=f=>{E({type:$}),h&&ae({snapping:c,props:f,editor:e}),x({enabled:!1})},A=[[fe,f=>{v(f),e.on(Y,_);const g=()=>{S(f),e.off(Y,_),e.off(K,g)};e.on(K,g)}],[n,f=>{if(m)return;const g=f.options.target,y=ce(e,g,a);y!=null&&y.result&&!y.dmode&&(y.component.set({dmode:"absolute"}),f.options.mode="absolute")}]];A.forEach(([f,g])=>e.on(f,g)),te({editor:e,licenseKey:a.licenseKey,plan:se,pluginName:oe,cleanup:()=>{x({enabled:!1}),A.forEach(([f,g])=>e.off(f,g))}})},me=ee(he);module.exports=me;
@@ -61,8 +61,8 @@ async function te({
61
61
  console.warn("Cleanup plugin:", u, "Reason:", t), d();
62
62
  }, h = (t = {}) => {
63
63
  var E;
64
- const { error: s, sdkLicense: f } = t, i = (E = t.plan) == null ? void 0 : E.category;
65
- if (!(f || t.license) || s)
64
+ const { error: s, sdkLicense: r } = t, i = (E = t.plan) == null ? void 0 : E.category;
65
+ if (!(r || t.license) || s)
66
66
  m(s || "Invalid license");
67
67
  else if (i) {
68
68
  const b = W[a], v = W[i];
@@ -117,8 +117,8 @@ function B({
117
117
  var L;
118
118
  const u = e.guide.x === void 0 ? "y" : "x";
119
119
  let l = 0, d = 0, n = 0, c = 0;
120
- const { guide: o, matched: m } = e, h = a.getElBoxRect(o.componentView.el), t = a.getElBoxRect(((L = m.componentView) == null ? void 0 : L.el) || m.componentEl), s = h.y, f = h.y + h.height, i = h.x, x = h.x + h.width, E = t.y, b = t.y + t.height, v = t.x, _ = t.x + t.width, S = Math.max(0, s - b), p = Math.max(0, E - f), w = Math.max(0, i - _), A = Math.max(0, v - x), r = S > p, g = w > A, y = o.type;
121
- return u === "x" && (y === "l" ? (l = i, r ? (d = b, n = S) : (d = f, n = p)) : y === "r" ? (l = x, r ? (d = b, n = S) : (d = f, n = p)) : y === "x" && (l = i - (i - x) / 2, r ? (d = b, n = S) : (d = f, n = p))), u === "y" && (y === "t" ? (d = s, g ? (l = _, c = w) : (l = x, c = A)) : y === "b" ? (d = f, g ? (l = _, c = w) : (l = x, c = A)) : y === "y" && (d = s - (s - f) / 2, g ? (l = _, c = w) : (l = x, c = A))), { axis: u, x: l, y: d, width: c, height: n };
120
+ const { guide: o, matched: m } = e, h = a.getElBoxRect(o.componentView.el), t = a.getElBoxRect(((L = m.componentView) == null ? void 0 : L.el) || m.componentEl), s = h.y, r = h.y + h.height, i = h.x, x = h.x + h.width, E = t.y, b = t.y + t.height, v = t.x, _ = t.x + t.width, S = Math.max(0, s - b), p = Math.max(0, E - r), w = Math.max(0, i - _), A = Math.max(0, v - x), f = S > p, g = w > A, y = o.type;
121
+ return u === "x" && (y === "l" ? (l = i, f ? (d = b, n = S) : (d = r, n = p)) : y === "r" ? (l = x, f ? (d = b, n = S) : (d = r, n = p)) : y === "x" && (l = i - (i - x) / 2, f ? (d = b, n = S) : (d = r, n = p))), u === "y" && (y === "t" ? (d = s, g ? (l = _, c = w) : (l = x, c = A)) : y === "b" ? (d = r, g ? (l = _, c = w) : (l = x, c = A)) : y === "y" && (d = s - (s - r) / 2, g ? (l = _, c = w) : (l = x, c = A))), { axis: u, x: l, y: d, width: c, height: n };
122
122
  }
123
123
  function ie({
124
124
  guideMatched: e,
@@ -127,14 +127,14 @@ function ie({
127
127
  }) {
128
128
  const l = e.guide.x === void 0 ? "x" : "y", { guide: d, matched: n } = e, c = d.type, o = n.type, m = u.getElementPos(d.componentView.el).rect, h = u.getElementPos(n.componentView.el).rect;
129
129
  if (l === "x") {
130
- const t = m.height, s = h.top, f = h.top + h.height;
130
+ const t = m.height, s = h.top, r = h.top + h.height;
131
131
  let i = 0;
132
- c === "t" ? o === "t" ? i = s - t : o === "b" ? i = f - t : o === "y" && (i = s - t - (s - f) / 2) : c === "b" ? o === "t" ? i = s - t * 2 : o === "b" ? i = f - t * 2 : o === "y" && (i = s - t * 2 - (s - f) / 2) : c === "y" && (o === "t" ? i = s - t * 1.5 : o === "b" ? i = f - t * 1.5 : o === "y" && (i = s - t * 1.5 - (s - f) / 2)), a.addStyle({ top: `${i - 5}px` }, { partial: !0 });
132
+ c === "t" ? o === "t" ? i = s - t : o === "b" ? i = r - t : o === "y" && (i = s - t - (s - r) / 2) : c === "b" ? o === "t" ? i = s - t * 2 : o === "b" ? i = r - t * 2 : o === "y" && (i = s - t * 2 - (s - r) / 2) : c === "y" && (o === "t" ? i = s - t * 1.5 : o === "b" ? i = r - t * 1.5 : o === "y" && (i = s - t * 1.5 - (s - r) / 2)), a.addStyle({ top: `${i - 5}px` }, { partial: !0 });
133
133
  }
134
134
  if (l === "y") {
135
- const t = m.width, s = h.left, f = h.left + h.width;
135
+ const t = m.width, s = h.left, r = h.left + h.width;
136
136
  let i = 0;
137
- c === "l" ? o === "l" ? i = s : o === "r" ? i = f : o === "x" && (i = s - (s - f) / 2) : c === "r" ? o === "l" ? i = s - t : o === "r" ? i = f - t : o === "x" && (i = s - t - (s - f) / 2) : c === "x" && (o === "l" ? i = s - t / 2 : o === "r" && (i = f - t / 2)), a.addStyle({ left: `${i}px` }, { partial: !0 });
137
+ c === "l" ? o === "l" ? i = s : o === "r" ? i = r : o === "x" && (i = s - (s - r) / 2) : c === "r" ? o === "l" ? i = s - t : o === "r" ? i = r - t : o === "x" && (i = s - t - (s - r) / 2) : c === "x" && (o === "l" ? i = s - t / 2 : o === "r" && (i = r - t / 2)), a.addStyle({ left: `${i}px` }, { partial: !0 });
138
138
  }
139
139
  }
140
140
  function H({
@@ -143,17 +143,17 @@ function H({
143
143
  props: u
144
144
  }) {
145
145
  var R, O;
146
- const { command: l, guidesMatched: d } = u, n = u.component, c = n.getEl(), o = a.Canvas.getCanvasView(), { x: m, y: h } = e ?? { x: 10, y: 10 }, t = l.opts.event, s = t.clientX, f = t.clientY;
146
+ const { command: l, guidesMatched: d } = u, n = u.component, c = n.getEl(), o = a.Canvas.getCanvasView(), { x: m, y: h } = e ?? { x: 10, y: 10 }, t = l.opts.event, s = t.clientX, r = t.clientY;
147
147
  if (!n.__lastSnappedPosition) {
148
- const T = o.getElBoxRect(c), M = s - T.x, D = f - T.y;
148
+ const T = o.getElBoxRect(c), M = s - T.x, D = r - T.y;
149
149
  n.__lastSnappedPosition = { left: T.x, top: T.y }, n.__dragOffset = { x: M, y: D };
150
150
  }
151
- const i = ((R = n.__dragOffset) == null ? void 0 : R.x) || 0, x = ((O = n.__dragOffset) == null ? void 0 : O.y) || 0, E = n.__lastSnappedPosition, b = s - E.left - i, v = f - E.top - x;
151
+ const i = ((R = n.__dragOffset) == null ? void 0 : R.x) || 0, x = ((O = n.__dragOffset) == null ? void 0 : O.y) || 0, E = n.__lastSnappedPosition, b = s - E.left - i, v = r - E.top - x;
152
152
  let _ = E.left, S = E.top;
153
- const p = d == null ? void 0 : d[0], w = (p == null ? void 0 : p.guide.type) === "l", A = (p == null ? void 0 : p.guide.type) === "x", r = (p == null ? void 0 : p.guide.type) === "r", g = (p == null ? void 0 : p.guide.type) === "t", y = (p == null ? void 0 : p.guide.type) === "b", L = (p == null ? void 0 : p.guide.type) === "y";
153
+ const p = d == null ? void 0 : d[0], w = (p == null ? void 0 : p.guide.type) === "l", A = (p == null ? void 0 : p.guide.type) === "x", f = (p == null ? void 0 : p.guide.type) === "r", g = (p == null ? void 0 : p.guide.type) === "t", y = (p == null ? void 0 : p.guide.type) === "b", L = (p == null ? void 0 : p.guide.type) === "y";
154
154
  if (p) {
155
155
  const { x: T, y: M } = B({ guideMatched: p, canvasView: o }), D = c.offsetWidth, G = c.offsetHeight;
156
- w ? _ = T : r ? _ = T - D : A ? _ = T - D / 2 : g ? S = M : y ? S = M - G : L && (S = M - G / 2), n.__lastSnappedGuideMatched = p;
156
+ w ? _ = T : f ? _ = T - D : A ? _ = T - D / 2 : g ? S = M : y ? S = M - G : L && (S = M - G / 2), n.__lastSnappedGuideMatched = p;
157
157
  } else
158
158
  Math.abs(b) >= m && (_ = Math.round((E.left + b) / m) * m, n.__lastSnappedGuideMatched = null), Math.abs(v) >= h && (S = Math.round((E.top + v) / h) * h, n.__lastSnappedGuideMatched = null);
159
159
  return n.addStyle({ left: `${_}px`, top: `${S}px` }, { partial: !0 }), n.__lastSnappedPosition = { left: _, top: S }, { x: _, y: S, guideMatched: n.__lastSnappedGuideMatched };
@@ -169,32 +169,32 @@ function ae({
169
169
  const le = "core:component-drag", de = "studio:setDragAbsolute", fe = "dmode:start", Y = "dmode:move", K = "dmode:end", $ = "dragAbsolute", re = "select", pe = "hover", ue = "spacing", he = function(e, a = {}) {
170
170
  const { Commands: u } = e, l = u.events, d = u.getConfig().defaultOptions ?? {}, n = `${l.runBeforeCommand}tlb-move`;
171
171
  d[le] = {
172
- run: (r) => ({
173
- ...r,
172
+ run: (f) => ({
173
+ ...f,
174
174
  skipGuidesRender: !0
175
175
  })
176
176
  };
177
177
  const { snapping: c, locking: o, globalAbsolute: m = !0 } = a;
178
178
  m && e.setDragMode("absolute");
179
179
  const h = !!(c != null && c.x || c != null && c.y), t = !!(o != null && o.x || o != null && o.y), { Canvas: s } = e;
180
- let f = null;
181
- const i = (r) => {
182
- const { component: g, guidesMatched: y, command: L } = r, R = g.view, O = e.Canvas.getCanvasView(), T = g.getEl();
180
+ let r = null;
181
+ const i = (f) => {
182
+ const { component: g, guidesMatched: y, command: L } = f, R = g.view, O = e.Canvas.getCanvasView(), T = g.getEl();
183
183
  let M = y.map((C) => C.matched.componentEl), D = y.map((C) => B({ guideMatched: C, canvasView: O }));
184
184
  if (h) {
185
- const { guideMatched: C } = H({ snapping: c, props: r, editor: e });
185
+ const { guideMatched: C } = H({ snapping: c, props: f, editor: e });
186
186
  C ? (M = [C.matched.componentEl], D = [B({ guideMatched: C, canvasView: O })]) : (M = [], D = []);
187
187
  }
188
188
  if (t)
189
189
  if (L.opts.event.shiftKey)
190
- if (!f)
191
- f = y[0];
190
+ if (!r)
191
+ r = y[0];
192
192
  else {
193
- const N = f, U = N.guide.x === void 0 ? "x" : "y";
193
+ const N = r, U = N.guide.x === void 0 ? "x" : "y";
194
194
  (U === "x" && (o == null ? void 0 : o.x) || U === "y" && (o == null ? void 0 : o.y)) && (ie({ guideMatched: N, component: g, canvasView: O }), M = [N.matched.componentEl], D = [B({ guideMatched: N, canvasView: O })]);
195
195
  }
196
196
  else
197
- f = null;
197
+ r = null;
198
198
  const G = {
199
199
  id: $,
200
200
  type: $,
@@ -205,39 +205,39 @@ const le = "core:component-drag", de = "studio:setDragAbsolute", fe = "dmode:sta
205
205
  originMatchedDistances: D
206
206
  };
207
207
  s.addSpot(G);
208
- }, x = ({ enabled: r }) => {
209
- e.runCommand(de, { enabled: r });
210
- }, E = ({ type: r }) => {
211
- s.removeSpots({ type: r });
208
+ }, x = ({ enabled: f }) => {
209
+ e.runCommand(de, { enabled: f });
210
+ }, E = ({ type: f }) => {
211
+ s.removeSpots({ type: f });
212
212
  }, b = () => {
213
213
  E({ type: re }), E({ type: pe }), E({ type: ue });
214
- }, v = (r) => {
215
- x({ enabled: !0 }), i(r), b();
216
- }, _ = (r) => {
217
- i(r), b();
218
- }, S = (r) => {
219
- E({ type: $ }), h && ae({ snapping: c, props: r, editor: e }), x({ enabled: !1 });
214
+ }, v = (f) => {
215
+ x({ enabled: !0 }), i(f), b();
216
+ }, _ = (f) => {
217
+ i(f), b();
218
+ }, S = (f) => {
219
+ E({ type: $ }), h && ae({ snapping: c, props: f, editor: e }), x({ enabled: !1 });
220
220
  }, A = [
221
- [fe, (r) => {
222
- v(r), e.on(Y, _);
221
+ [fe, (f) => {
222
+ v(f), e.on(Y, _);
223
223
  const g = () => {
224
- S(r), e.off(Y, _), e.off(K, g);
224
+ S(f), e.off(Y, _), e.off(K, g);
225
225
  };
226
226
  e.on(K, g);
227
227
  }],
228
- [n, (r) => {
228
+ [n, (f) => {
229
229
  if (m) return;
230
- const g = r.options.target, y = ce(e, g, a);
231
- y != null && y.result && !y.dmode && y.component.set({ dmode: "absolute" });
230
+ const g = f.options.target, y = ce(e, g, a);
231
+ y != null && y.result && !y.dmode && (y.component.set({ dmode: "absolute" }), f.options.mode = "absolute");
232
232
  }]
233
233
  ];
234
- A.forEach(([r, g]) => e.on(r, g)), te({
234
+ A.forEach(([f, g]) => e.on(f, g)), te({
235
235
  editor: e,
236
236
  licenseKey: a.licenseKey,
237
237
  plan: se,
238
238
  pluginName: oe,
239
239
  cleanup: () => {
240
- x({ enabled: !1 }), A.forEach(([r, g]) => e.off(r, g));
240
+ x({ enabled: !1 }), A.forEach(([f, g]) => e.off(f, g));
241
241
  }
242
242
  });
243
243
  }, ge = ee(he);
@@ -1 +1 @@
1
- (function(P,L){typeof exports=="object"&&typeof module<"u"?module.exports=L():typeof define=="function"&&define.amd?define(L):(P=typeof globalThis<"u"?globalThis:P||self,P.StudioSdkPlugins_canvasAbsoluteMode=L())})(this,function(){"use strict";const P="app.grapesjs.com",L="app-stage.grapesjs.com",W=[P,L,"localhost","127.0.0.1",".local-credentialless.webcontainer.io",".local.webcontainer.io","-sandpack.codesandbox.io"],X="license:check:start",j="license:check:end",F=()=>typeof window<"u",q=({isDev:e,isStage:l})=>`${e?"":`https://${l?L:P}`}/api`,J=()=>{const e=F()&&window.location.hostname;return!!e&&(W.includes(e)||W.some(l=>e.endsWith(l)))};function z(e){return typeof e=="function"}async function Q({path:e,baseApiUrl:l,method:u="GET",headers:a={},params:d,body:n}){const o=`${l||q({isDev:!1,isStage:!1})}${e}`,m={method:u,headers:{"Content-Type":"application/json",...a}};n&&(m.body=JSON.stringify(n));const h=d?new URLSearchParams(d).toString():"",t=h?`?${h}`:"",s=await fetch(`${o}${t}`,m);if(!s.ok)throw new Error(`HTTP error! status: ${s.status}`);return s.json()}var R=(e=>(e.free="free",e.startup="startup",e.business="business",e.enterprise="enterprise",e))(R||{});const Y={[R.free]:0,[R.startup]:10,[R.business]:20,[R.enterprise]:30};function Z(e){const l=e;return l.init=u=>a=>e(a,u),l}const ee=e=>Z(e);async function te({editor:e,plan:l,pluginName:u,licenseKey:a,cleanup:d}){let n="",i=!1;const o=J(),m=t=>{console.warn("Cleanup plugin:",u,"Reason:",t),d()},h=(t={})=>{var E;const{error:s,sdkLicense:f}=t,c=(E=t.plan)==null?void 0:E.category;if(!(f||t.license)||s)m(s||"Invalid license");else if(c){const b=Y[l],v=Y[c];b>v&&m({pluginRequiredPlan:l,licensePlan:c})}};e.on(X,t=>{n=t==null?void 0:t.baseApiUrl,i=!0}),e.on(j,t=>{h(t)}),setTimeout(async()=>{if(!i){if(o)return;if(a){const t=await ne({licenseKey:a,pluginName:u,baseApiUrl:n});t&&h(t)}else m("The `licenseKey` option not provided")}},2e3)}async function ne(e){const{licenseKey:l,pluginName:u,baseApiUrl:a}=e;try{return(await Q({baseApiUrl:a,path:`/sdk/${l||"na"}`,method:"POST",params:{d:window.location.hostname,pn:u}})).result||{}}catch(d){return console.error("Error during SDK license check:",d),!1}}const oe="canvasAbsoluteMode",se=R.startup,ie=(e,l,u)=>{const a=u.enableAbsolute??(m=>m.hasAbsolute),n=(Array.isArray(l)?l:l?[l]:[...e.getSelectedAll()])[0];if(!n)return;const i=n.getEl();return{result:z(a)?a({component:n,hasAbsolute:!!i&&getComputedStyle(i).position==="absolute"}):!1,component:n,dmode:n.get("dmode")}};function N({guideMatched:e,canvasView:l}){var G;const u=e.guide.x===void 0?"y":"x";let a=0,d=0,n=0,i=0;const{guide:o,matched:m}=e,h=l.getElBoxRect(o.componentView.el),t=l.getElBoxRect(((G=m.componentView)==null?void 0:G.el)||m.componentEl),s=h.y,f=h.y+h.height,c=h.x,S=h.x+h.width,E=t.y,b=t.y+t.height,v=t.x,x=t.x+t.width,_=Math.max(0,s-b),p=Math.max(0,E-f),w=Math.max(0,c-x),A=Math.max(0,v-S),r=_>p,g=w>A,y=o.type;return u==="x"&&(y==="l"?(a=c,r?(d=b,n=_):(d=f,n=p)):y==="r"?(a=S,r?(d=b,n=_):(d=f,n=p)):y==="x"&&(a=c-(c-S)/2,r?(d=b,n=_):(d=f,n=p))),u==="y"&&(y==="t"?(d=s,g?(a=x,i=w):(a=S,i=A)):y==="b"?(d=f,g?(a=x,i=w):(a=S,i=A)):y==="y"&&(d=s-(s-f)/2,g?(a=x,i=w):(a=S,i=A))),{axis:u,x:a,y:d,width:i,height:n}}function ce({guideMatched:e,component:l,canvasView:u}){const a=e.guide.x===void 0?"x":"y",{guide:d,matched:n}=e,i=d.type,o=n.type,m=u.getElementPos(d.componentView.el).rect,h=u.getElementPos(n.componentView.el).rect;if(a==="x"){const t=m.height,s=h.top,f=h.top+h.height;let c=0;i==="t"?o==="t"?c=s-t:o==="b"?c=f-t:o==="y"&&(c=s-t-(s-f)/2):i==="b"?o==="t"?c=s-t*2:o==="b"?c=f-t*2:o==="y"&&(c=s-t*2-(s-f)/2):i==="y"&&(o==="t"?c=s-t*1.5:o==="b"?c=f-t*1.5:o==="y"&&(c=s-t*1.5-(s-f)/2)),l.addStyle({top:`${c-5}px`},{partial:!0})}if(a==="y"){const t=m.width,s=h.left,f=h.left+h.width;let c=0;i==="l"?o==="l"?c=s:o==="r"?c=f:o==="x"&&(c=s-(s-f)/2):i==="r"?o==="l"?c=s-t:o==="r"?c=f-t:o==="x"&&(c=s-t-(s-f)/2):i==="x"&&(o==="l"?c=s-t/2:o==="r"&&(c=f-t/2)),l.addStyle({left:`${c}px`},{partial:!0})}}function k({snapping:e,editor:l,props:u}){var B,O;const{command:a,guidesMatched:d}=u,n=u.component,i=n.getEl(),o=l.Canvas.getCanvasView(),{x:m,y:h}=e??{x:10,y:10},t=a.opts.event,s=t.clientX,f=t.clientY;if(!n.__lastSnappedPosition){const T=o.getElBoxRect(i),M=s-T.x,D=f-T.y;n.__lastSnappedPosition={left:T.x,top:T.y},n.__dragOffset={x:M,y:D}}const c=((B=n.__dragOffset)==null?void 0:B.x)||0,S=((O=n.__dragOffset)==null?void 0:O.y)||0,E=n.__lastSnappedPosition,b=s-E.left-c,v=f-E.top-S;let x=E.left,_=E.top;const p=d==null?void 0:d[0],w=(p==null?void 0:p.guide.type)==="l",A=(p==null?void 0:p.guide.type)==="x",r=(p==null?void 0:p.guide.type)==="r",g=(p==null?void 0:p.guide.type)==="t",y=(p==null?void 0:p.guide.type)==="b",G=(p==null?void 0:p.guide.type)==="y";if(p){const{x:T,y:M}=N({guideMatched:p,canvasView:o}),D=i.offsetWidth,$=i.offsetHeight;w?x=T:r?x=T-D:A?x=T-D/2:g?_=M:y?_=M-$:G&&(_=M-$/2),n.__lastSnappedGuideMatched=p}else Math.abs(b)>=m&&(x=Math.round((E.left+b)/m)*m,n.__lastSnappedGuideMatched=null),Math.abs(v)>=h&&(_=Math.round((E.top+v)/h)*h,n.__lastSnappedGuideMatched=null);return n.addStyle({left:`${x}px`,top:`${_}px`},{partial:!0}),n.__lastSnappedPosition={left:x,top:_},{x,y:_,guideMatched:n.__lastSnappedGuideMatched}}function le({snapping:e,props:l,editor:u}){const{x:a,y:d}=k({snapping:e,props:l,editor:u}),n=l.component;n.addStyle({left:`${a}px`,top:`${d}px`}),delete n.__lastSnappedPosition,delete n.__lastSnappedGuideMatched}const ae="core:component-drag",de="studio:setDragAbsolute",fe="dmode:start",K="dmode:move",V="dmode:end",I="dragAbsolute",re="select",pe="hover",ue="spacing";return ee(function(e,l={}){const{Commands:u}=e,a=u.events,d=u.getConfig().defaultOptions??{},n=`${a.runBeforeCommand}tlb-move`;d[ae]={run:r=>({...r,skipGuidesRender:!0})};const{snapping:i,locking:o,globalAbsolute:m=!0}=l;m&&e.setDragMode("absolute");const h=!!(i!=null&&i.x||i!=null&&i.y),t=!!(o!=null&&o.x||o!=null&&o.y),{Canvas:s}=e;let f=null;const c=r=>{const{component:g,guidesMatched:y,command:G}=r,B=g.view,O=e.Canvas.getCanvasView(),T=g.getEl();let M=y.map(C=>C.matched.componentEl),D=y.map(C=>N({guideMatched:C,canvasView:O}));if(h){const{guideMatched:C}=k({snapping:i,props:r,editor:e});C?(M=[C.matched.componentEl],D=[N({guideMatched:C,canvasView:O})]):(M=[],D=[])}if(t)if(G.opts.event.shiftKey)if(!f)f=y[0];else{const U=f,H=U.guide.x===void 0?"x":"y";(H==="x"&&(o==null?void 0:o.x)||H==="y"&&(o==null?void 0:o.y))&&(ce({guideMatched:U,component:g,canvasView:O}),M=[U.matched.componentEl],D=[N({guideMatched:U,canvasView:O})])}else f=null;const $={id:I,type:I,component:g,componentView:B,originComponent:T,matchedComponents:M,originMatchedDistances:D};s.addSpot($)},S=({enabled:r})=>{e.runCommand(de,{enabled:r})},E=({type:r})=>{s.removeSpots({type:r})},b=()=>{E({type:re}),E({type:pe}),E({type:ue})},v=r=>{S({enabled:!0}),c(r),b()},x=r=>{c(r),b()},_=r=>{E({type:I}),h&&le({snapping:i,props:r,editor:e}),S({enabled:!1})},A=[[fe,r=>{v(r),e.on(K,x);const g=()=>{_(r),e.off(K,x),e.off(V,g)};e.on(V,g)}],[n,r=>{if(m)return;const g=r.options.target,y=ie(e,g,l);y!=null&&y.result&&!y.dmode&&y.component.set({dmode:"absolute"})}]];A.forEach(([r,g])=>e.on(r,g)),te({editor:e,licenseKey:l.licenseKey,plan:se,pluginName:oe,cleanup:()=>{S({enabled:!1}),A.forEach(([r,g])=>e.off(r,g))}})})});
1
+ (function(P,L){typeof exports=="object"&&typeof module<"u"?module.exports=L():typeof define=="function"&&define.amd?define(L):(P=typeof globalThis<"u"?globalThis:P||self,P.StudioSdkPlugins_canvasAbsoluteMode=L())})(this,function(){"use strict";const P="app.grapesjs.com",L="app-stage.grapesjs.com",W=[P,L,"localhost","127.0.0.1",".local-credentialless.webcontainer.io",".local.webcontainer.io","-sandpack.codesandbox.io"],X="license:check:start",j="license:check:end",F=()=>typeof window<"u",q=({isDev:e,isStage:l})=>`${e?"":`https://${l?L:P}`}/api`,J=()=>{const e=F()&&window.location.hostname;return!!e&&(W.includes(e)||W.some(l=>e.endsWith(l)))};function z(e){return typeof e=="function"}async function Q({path:e,baseApiUrl:l,method:u="GET",headers:a={},params:d,body:n}){const o=`${l||q({isDev:!1,isStage:!1})}${e}`,m={method:u,headers:{"Content-Type":"application/json",...a}};n&&(m.body=JSON.stringify(n));const h=d?new URLSearchParams(d).toString():"",t=h?`?${h}`:"",s=await fetch(`${o}${t}`,m);if(!s.ok)throw new Error(`HTTP error! status: ${s.status}`);return s.json()}var R=(e=>(e.free="free",e.startup="startup",e.business="business",e.enterprise="enterprise",e))(R||{});const Y={[R.free]:0,[R.startup]:10,[R.business]:20,[R.enterprise]:30};function Z(e){const l=e;return l.init=u=>a=>e(a,u),l}const ee=e=>Z(e);async function te({editor:e,plan:l,pluginName:u,licenseKey:a,cleanup:d}){let n="",i=!1;const o=J(),m=t=>{console.warn("Cleanup plugin:",u,"Reason:",t),d()},h=(t={})=>{var E;const{error:s,sdkLicense:r}=t,c=(E=t.plan)==null?void 0:E.category;if(!(r||t.license)||s)m(s||"Invalid license");else if(c){const b=Y[l],v=Y[c];b>v&&m({pluginRequiredPlan:l,licensePlan:c})}};e.on(X,t=>{n=t==null?void 0:t.baseApiUrl,i=!0}),e.on(j,t=>{h(t)}),setTimeout(async()=>{if(!i){if(o)return;if(a){const t=await ne({licenseKey:a,pluginName:u,baseApiUrl:n});t&&h(t)}else m("The `licenseKey` option not provided")}},2e3)}async function ne(e){const{licenseKey:l,pluginName:u,baseApiUrl:a}=e;try{return(await Q({baseApiUrl:a,path:`/sdk/${l||"na"}`,method:"POST",params:{d:window.location.hostname,pn:u}})).result||{}}catch(d){return console.error("Error during SDK license check:",d),!1}}const oe="canvasAbsoluteMode",se=R.startup,ie=(e,l,u)=>{const a=u.enableAbsolute??(m=>m.hasAbsolute),n=(Array.isArray(l)?l:l?[l]:[...e.getSelectedAll()])[0];if(!n)return;const i=n.getEl();return{result:z(a)?a({component:n,hasAbsolute:!!i&&getComputedStyle(i).position==="absolute"}):!1,component:n,dmode:n.get("dmode")}};function N({guideMatched:e,canvasView:l}){var G;const u=e.guide.x===void 0?"y":"x";let a=0,d=0,n=0,i=0;const{guide:o,matched:m}=e,h=l.getElBoxRect(o.componentView.el),t=l.getElBoxRect(((G=m.componentView)==null?void 0:G.el)||m.componentEl),s=h.y,r=h.y+h.height,c=h.x,S=h.x+h.width,E=t.y,b=t.y+t.height,v=t.x,x=t.x+t.width,_=Math.max(0,s-b),p=Math.max(0,E-r),w=Math.max(0,c-x),A=Math.max(0,v-S),f=_>p,g=w>A,y=o.type;return u==="x"&&(y==="l"?(a=c,f?(d=b,n=_):(d=r,n=p)):y==="r"?(a=S,f?(d=b,n=_):(d=r,n=p)):y==="x"&&(a=c-(c-S)/2,f?(d=b,n=_):(d=r,n=p))),u==="y"&&(y==="t"?(d=s,g?(a=x,i=w):(a=S,i=A)):y==="b"?(d=r,g?(a=x,i=w):(a=S,i=A)):y==="y"&&(d=s-(s-r)/2,g?(a=x,i=w):(a=S,i=A))),{axis:u,x:a,y:d,width:i,height:n}}function ce({guideMatched:e,component:l,canvasView:u}){const a=e.guide.x===void 0?"x":"y",{guide:d,matched:n}=e,i=d.type,o=n.type,m=u.getElementPos(d.componentView.el).rect,h=u.getElementPos(n.componentView.el).rect;if(a==="x"){const t=m.height,s=h.top,r=h.top+h.height;let c=0;i==="t"?o==="t"?c=s-t:o==="b"?c=r-t:o==="y"&&(c=s-t-(s-r)/2):i==="b"?o==="t"?c=s-t*2:o==="b"?c=r-t*2:o==="y"&&(c=s-t*2-(s-r)/2):i==="y"&&(o==="t"?c=s-t*1.5:o==="b"?c=r-t*1.5:o==="y"&&(c=s-t*1.5-(s-r)/2)),l.addStyle({top:`${c-5}px`},{partial:!0})}if(a==="y"){const t=m.width,s=h.left,r=h.left+h.width;let c=0;i==="l"?o==="l"?c=s:o==="r"?c=r:o==="x"&&(c=s-(s-r)/2):i==="r"?o==="l"?c=s-t:o==="r"?c=r-t:o==="x"&&(c=s-t-(s-r)/2):i==="x"&&(o==="l"?c=s-t/2:o==="r"&&(c=r-t/2)),l.addStyle({left:`${c}px`},{partial:!0})}}function k({snapping:e,editor:l,props:u}){var B,O;const{command:a,guidesMatched:d}=u,n=u.component,i=n.getEl(),o=l.Canvas.getCanvasView(),{x:m,y:h}=e??{x:10,y:10},t=a.opts.event,s=t.clientX,r=t.clientY;if(!n.__lastSnappedPosition){const T=o.getElBoxRect(i),M=s-T.x,D=r-T.y;n.__lastSnappedPosition={left:T.x,top:T.y},n.__dragOffset={x:M,y:D}}const c=((B=n.__dragOffset)==null?void 0:B.x)||0,S=((O=n.__dragOffset)==null?void 0:O.y)||0,E=n.__lastSnappedPosition,b=s-E.left-c,v=r-E.top-S;let x=E.left,_=E.top;const p=d==null?void 0:d[0],w=(p==null?void 0:p.guide.type)==="l",A=(p==null?void 0:p.guide.type)==="x",f=(p==null?void 0:p.guide.type)==="r",g=(p==null?void 0:p.guide.type)==="t",y=(p==null?void 0:p.guide.type)==="b",G=(p==null?void 0:p.guide.type)==="y";if(p){const{x:T,y:M}=N({guideMatched:p,canvasView:o}),D=i.offsetWidth,$=i.offsetHeight;w?x=T:f?x=T-D:A?x=T-D/2:g?_=M:y?_=M-$:G&&(_=M-$/2),n.__lastSnappedGuideMatched=p}else Math.abs(b)>=m&&(x=Math.round((E.left+b)/m)*m,n.__lastSnappedGuideMatched=null),Math.abs(v)>=h&&(_=Math.round((E.top+v)/h)*h,n.__lastSnappedGuideMatched=null);return n.addStyle({left:`${x}px`,top:`${_}px`},{partial:!0}),n.__lastSnappedPosition={left:x,top:_},{x,y:_,guideMatched:n.__lastSnappedGuideMatched}}function le({snapping:e,props:l,editor:u}){const{x:a,y:d}=k({snapping:e,props:l,editor:u}),n=l.component;n.addStyle({left:`${a}px`,top:`${d}px`}),delete n.__lastSnappedPosition,delete n.__lastSnappedGuideMatched}const ae="core:component-drag",de="studio:setDragAbsolute",fe="dmode:start",K="dmode:move",V="dmode:end",I="dragAbsolute",re="select",pe="hover",ue="spacing";return ee(function(e,l={}){const{Commands:u}=e,a=u.events,d=u.getConfig().defaultOptions??{},n=`${a.runBeforeCommand}tlb-move`;d[ae]={run:f=>({...f,skipGuidesRender:!0})};const{snapping:i,locking:o,globalAbsolute:m=!0}=l;m&&e.setDragMode("absolute");const h=!!(i!=null&&i.x||i!=null&&i.y),t=!!(o!=null&&o.x||o!=null&&o.y),{Canvas:s}=e;let r=null;const c=f=>{const{component:g,guidesMatched:y,command:G}=f,B=g.view,O=e.Canvas.getCanvasView(),T=g.getEl();let M=y.map(C=>C.matched.componentEl),D=y.map(C=>N({guideMatched:C,canvasView:O}));if(h){const{guideMatched:C}=k({snapping:i,props:f,editor:e});C?(M=[C.matched.componentEl],D=[N({guideMatched:C,canvasView:O})]):(M=[],D=[])}if(t)if(G.opts.event.shiftKey)if(!r)r=y[0];else{const U=r,H=U.guide.x===void 0?"x":"y";(H==="x"&&(o==null?void 0:o.x)||H==="y"&&(o==null?void 0:o.y))&&(ce({guideMatched:U,component:g,canvasView:O}),M=[U.matched.componentEl],D=[N({guideMatched:U,canvasView:O})])}else r=null;const $={id:I,type:I,component:g,componentView:B,originComponent:T,matchedComponents:M,originMatchedDistances:D};s.addSpot($)},S=({enabled:f})=>{e.runCommand(de,{enabled:f})},E=({type:f})=>{s.removeSpots({type:f})},b=()=>{E({type:re}),E({type:pe}),E({type:ue})},v=f=>{S({enabled:!0}),c(f),b()},x=f=>{c(f),b()},_=f=>{E({type:I}),h&&le({snapping:i,props:f,editor:e}),S({enabled:!1})},A=[[fe,f=>{v(f),e.on(K,x);const g=()=>{_(f),e.off(K,x),e.off(V,g)};e.on(V,g)}],[n,f=>{if(m)return;const g=f.options.target,y=ie(e,g,l);y!=null&&y.result&&!y.dmode&&(y.component.set({dmode:"absolute"}),f.options.mode="absolute")}]];A.forEach(([f,g])=>e.on(f,g)),te({editor:e,licenseKey:l.licenseKey,plan:se,pluginName:oe,cleanup:()=>{S({enabled:!1}),A.forEach(([f,g])=>e.off(f,g))}})})});
@@ -1 +1 @@
1
- "use strict";var p=(e=>(e.free="free",e.startup="startup",e.business="business",e.enterprise="enterprise",e))(p||{}),y=(e=>(e.toastAdd="studio:toastAdd",e.dialogOpen="studio:dialogOpen",e.dialogClose="studio:dialogClose",e.sidebarLeftSet="studio:sidebarLeft:set",e.sidebarLeftGet="studio:sidebarLeft:get",e.sidebarLeftToggle="studio:sidebarLeft:toggle",e.sidebarRightSet="studio:sidebarRight:set",e.sidebarRightGet="studio:sidebarRight:get",e.sidebarRightToggle="studio:sidebarRight:toggle",e.sidebarTopSet="studio:sidebarTop:set",e.sidebarTopGet="studio:sidebarTop:get",e.sidebarTopToggle="studio:sidebarTop:toggle",e.sidebarBottomSet="studio:sidebarBottom:set",e.sidebarBottomGet="studio:sidebarBottom:get",e.sidebarBottomToggle="studio:sidebarBottom:toggle",e.symbolAdd="studio:symbolAdd",e.symbolDetach="studio:symbolDetach",e.symbolOverride="studio:symbolOverride",e.symbolPropagateStyles="studio:propagateStyles",e.getPagesConfig="studio:getPagesConfig",e.setPagesConfig="studio:setPagesConfig",e.getPageSettings="studio:getPageSettings",e.setPageSettings="studio:setPageSettings",e.projectFiles="studio:projectFiles",e.canvasReload="studio:canvasReload",e.getBlocksPanel="studio:getBlocksPanel",e.setBlocksPanel="studio:setBlocksPanel",e.getStateContextMenu="studio:getStateContextMenu",e.setStateContextMenu="studio:setStateContextMenu",e.contextMenuComponent="studio:contextMenuComponent",e.layoutAdd="studio:layoutAdd",e.layoutRemove="studio:layoutRemove",e.layoutToggle="studio:layoutToggle",e.layoutUpdate="studio:layoutUpdate",e.layoutGet="studio:layoutGet",e.layoutConfigGet="studio:layoutConfigGet",e.layoutConfigSet="studio:layoutConfigSet",e.getStateTheme="studio:getStateTheme",e.setStateTheme="studio:setStateTheme",e.assetProviderGet="studio:assetProviderGet",e.assetProviderAdd="studio:assetProviderAdd",e.assetProviderRemove="studio:assetProviderRemove",e.fontGet="studio:fontGet",e.fontAdd="studio:fontAdd",e.fontRemove="studio:fontRemove",e.fontManagerOpen="studio:fontManagerOpen",e.menuFontLoad="studio:menuFontLoad",e.toggleStateDataSource="studio:toggleStateDataSource",e.getStateDataSource="studio:getStateDataSource",e.setDragAbsolute="studio:setDragAbsolute",e))(y||{});const R="app.grapesjs.com",x="app-stage.grapesjs.com",A=[R,x,"localhost","127.0.0.1",".local-credentialless.webcontainer.io",".local.webcontainer.io","-sandpack.codesandbox.io"],$="license:check:start",G="license:check:end",I=()=>typeof window<"u",U=({isDev:e,isStage:t})=>`${e?"":`https://${t?x:R}`}/api`,M=()=>{const e=I()&&window.location.hostname;return!!e&&(A.includes(e)||A.some(t=>e.endsWith(t)))};async function j({path:e,baseApiUrl:t,method:s="GET",headers:n={},params:o,body:a}){const l=`${t||U({isDev:!1,isStage:!1})}${e}`,c={method:s,headers:{"Content-Type":"application/json",...n}};a&&(c.body=JSON.stringify(a));const u=o?new URLSearchParams(o).toString():"",r=u?`?${u}`:"",g=await fetch(`${l}${r}`,c);if(!g.ok)throw new Error(`HTTP error! status: ${g.status}`);return g.json()}const L={[p.free]:0,[p.startup]:10,[p.business]:20,[p.enterprise]:30};function B(e){const t=e;return t.init=s=>n=>e(n,s),t}const E=e=>B(e);async function W({editor:e,plan:t,pluginName:s,licenseKey:n,cleanup:o}){let a="",i=!1;const l=M(),c=r=>{console.warn("Cleanup plugin:",s,"Reason:",r),o()},u=(r={})=>{var w;const{error:g,sdkLicense:f}=r,d=(w=r.plan)==null?void 0:w.category;if(!(f||r.license)||g)c(g||"Invalid license");else if(d){const O=L[t],k=L[d];O>k&&c({pluginRequiredPlan:t,licensePlan:d})}};e.on($,r=>{a=r==null?void 0:r.baseApiUrl,i=!0}),e.on(G,r=>{u(r)}),setTimeout(async()=>{if(!i){if(l)return;if(n){const r=await N({licenseKey:n,pluginName:s,baseApiUrl:a});r&&u(r)}else c("The `licenseKey` option not provided")}},2e3)}async function N(e){const{licenseKey:t,pluginName:s,baseApiUrl:n}=e;try{return(await j({baseApiUrl:n,path:`/sdk/${t||"na"}`,method:"POST",params:{d:window.location.hostname,pn:s}})).result||{}}catch(o){return console.error("Error during SDK license check:",o),!1}}const b=e=>e.replaceAll('"',"").replaceAll("'",""),v=e=>e.includes(",")?e:/\s/.test(e)?`"${b(e)}"`:b(e),F=(e,t,s)=>({family:e,variant:t,...s}),D=(e,t)=>{e=v(e);const{menuVariant:s,variants:n}=t;return{family:e,familyLabel:b(e),menuVariant:s&&F(v(`menuFont-${b(e)}`),"regular",s),variants:Object.assign({},...Object.entries(n).map(([o,a])=>({[o]:F(e,o,a)})))}},T=(e,t)=>{var l;const s=D(e.family,e),n=s.menuVariant??((l=Object.values(s.variants))==null?void 0:l[0]);if(!n)return"Arial, Helvetica, sans-serif";const{source:o,descriptors:a}=n,i=b(n.family);if(!t){const c=new FontFace(i,`url("${o}")`,a),u=Array.from(document.fonts.values()).filter(r=>r.family===i);for(const r of u)document.fonts.delete(r);document.fonts.add(c),c.load().catch(()=>{})}return v(i)},K=e=>{const{family:t,menu:s,axes:n}=e,o=!!n,a=Object.assign({},...e.variants.map(i=>{var r,g;let l,c;if(o){const f=n.find(d=>d.tag==="wght");if(f){const{start:d,end:P}=f;l=`${d} ${P}`}}return l||(l=((r=i.match(/\d+/))==null?void 0:r[0])??"400"),c=((g=i.match(/[a-zA-Z]+/))==null?void 0:g[0])==="italic"?"italic":void 0,{[i]:{source:e.files[i],descriptors:{style:c,weight:l}}}}));return D(t,{menuVariant:{source:s},variants:a})},V=e=>({id:`${e.family}/${e.version}`,type:"font",src:e.menu,name:e.family,customData:{font:K(e),needsLoading:!0}}),_=e=>{const{font:t}=e.customData;return e.customData.needsLoading?(e.customData.needsLoading=!1,T(t)):T(t,!0)};let h;const H=e=>{const t=[];for(const s of Object.keys(e)){let n=e[s];n&&(Array.isArray(n)?t.push(...n.map(o=>[s,o.toString()])):(n=n.toString(),t.push([s,n])))}return new URLSearchParams(t)},z=e=>{const{apiKey:t,searchParams:s}=e,n=(o={})=>{const a="https://www.googleapis.com/webfonts/v1/webfonts",i=H(o);return`${a}?${i}`};return{id:"google-fonts",types:["font"],label:({editor:o})=>o.I18n.t("googleFontsAssetProvider.providerLabel"),search:{reloadOnInput:!1},async onLoad(){var u;if(h)return h;const o={key:t,sort:"alpha",subset:"latin",capability:["WOFF2","VF"]},a=s==null?void 0:s(),i={...o,...a},c=await(await fetch(n(i))).json();return(u=c.items)!=null&&u.length?(h=c.items.map(V),h):[]},itemLayout:o=>{const a=h.find(l=>l.id===o.assetProps.id),i=_(a);return{type:"column",onClick:()=>o.onSelect(a),htmlAttrs:{title:a.name},style:{borderWidth:"1px",borderRadius:8,overflow:"hidden",cursor:"pointer"},children:[{type:"text",content:a.name,style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontFamily:i,fontSize:"24px",paddingLeft:"8px",paddingRight:"8px"}},{type:"text",content:a.name,style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:"16px",paddingLeft:"8px",paddingRight:"8px"}}]}}}},q={googleFontsAssetProvider:{searchBtn:"Search on Google Fonts",modalTitle:"Select Font",providerLabel:"Google Fonts"}},J="googleFontsAssetProvider",Q=function(e,t){const{i18n:s={}}=t,n=z(t);e.runCommand(y.assetProviderAdd,{provider:n}),e.I18n.addMessages({en:q,...s}),W({editor:e,licenseKey:t.licenseKey,plan:p.startup,pluginName:J,cleanup:()=>{e.runCommand(y.assetProviderRemove,{id:n.id})}})},Z=E(Q);module.exports=Z;
1
+ "use strict";var p=(e=>(e.free="free",e.startup="startup",e.business="business",e.enterprise="enterprise",e))(p||{}),y=(e=>(e.toastAdd="studio:toastAdd",e.dialogOpen="studio:dialogOpen",e.dialogClose="studio:dialogClose",e.sidebarLeftSet="studio:sidebarLeft:set",e.sidebarLeftGet="studio:sidebarLeft:get",e.sidebarLeftToggle="studio:sidebarLeft:toggle",e.sidebarRightSet="studio:sidebarRight:set",e.sidebarRightGet="studio:sidebarRight:get",e.sidebarRightToggle="studio:sidebarRight:toggle",e.sidebarTopSet="studio:sidebarTop:set",e.sidebarTopGet="studio:sidebarTop:get",e.sidebarTopToggle="studio:sidebarTop:toggle",e.sidebarBottomSet="studio:sidebarBottom:set",e.sidebarBottomGet="studio:sidebarBottom:get",e.sidebarBottomToggle="studio:sidebarBottom:toggle",e.symbolAdd="studio:symbolAdd",e.symbolDetach="studio:symbolDetach",e.symbolOverride="studio:symbolOverride",e.symbolPropagateStyles="studio:propagateStyles",e.getPagesConfig="studio:getPagesConfig",e.setPagesConfig="studio:setPagesConfig",e.getPageSettings="studio:getPageSettings",e.setPageSettings="studio:setPageSettings",e.projectFiles="studio:projectFiles",e.canvasReload="studio:canvasReload",e.getBlocksPanel="studio:getBlocksPanel",e.setBlocksPanel="studio:setBlocksPanel",e.getStateContextMenu="studio:getStateContextMenu",e.setStateContextMenu="studio:setStateContextMenu",e.contextMenuComponent="studio:contextMenuComponent",e.layoutAdd="studio:layoutAdd",e.layoutRemove="studio:layoutRemove",e.layoutToggle="studio:layoutToggle",e.layoutUpdate="studio:layoutUpdate",e.layoutGet="studio:layoutGet",e.layoutConfigGet="studio:layoutConfigGet",e.layoutConfigSet="studio:layoutConfigSet",e.getStateTheme="studio:getStateTheme",e.setStateTheme="studio:setStateTheme",e.assetProviderGet="studio:assetProviderGet",e.assetProviderAdd="studio:assetProviderAdd",e.assetProviderRemove="studio:assetProviderRemove",e.fontGet="studio:fontGet",e.fontAdd="studio:fontAdd",e.fontRemove="studio:fontRemove",e.fontManagerOpen="studio:fontManagerOpen",e.menuFontLoad="studio:menuFontLoad",e.toggleStateDataSource="studio:toggleStateDataSource",e.getStateDataSource="studio:getStateDataSource",e.setDragAbsolute="studio:setDragAbsolute",e))(y||{});const R="app.grapesjs.com",x="app-stage.grapesjs.com",w=[R,x,"localhost","127.0.0.1",".local-credentialless.webcontainer.io",".local.webcontainer.io","-sandpack.codesandbox.io"],G="license:check:start",$="license:check:end",I=()=>typeof window<"u",U=({isDev:e,isStage:t})=>`${e?"":`https://${t?x:R}`}/api`,M=()=>{const e=I()&&window.location.hostname;return!!e&&(w.includes(e)||w.some(t=>e.endsWith(t)))};async function j({path:e,baseApiUrl:t,method:s="GET",headers:n={},params:o,body:a}){const l=`${t||U({isDev:!1,isStage:!1})}${e}`,c={method:s,headers:{"Content-Type":"application/json",...n}};a&&(c.body=JSON.stringify(a));const u=o?new URLSearchParams(o).toString():"",r=u?`?${u}`:"",g=await fetch(`${l}${r}`,c);if(!g.ok)throw new Error(`HTTP error! status: ${g.status}`);return g.json()}const L={[p.free]:0,[p.startup]:10,[p.business]:20,[p.enterprise]:30};function B(e){const t=e;return t.init=s=>n=>e(n,s),t}const E=e=>B(e);async function N({editor:e,plan:t,pluginName:s,licenseKey:n,cleanup:o}){let a="",i=!1;const l=M(),c=r=>{console.warn("Cleanup plugin:",s,"Reason:",r),o()},u=(r={})=>{var A;const{error:g,sdkLicense:f}=r,d=(A=r.plan)==null?void 0:A.category;if(!(f||r.license)||g)c(g||"Invalid license");else if(d){const O=L[t],k=L[d];O>k&&c({pluginRequiredPlan:t,licensePlan:d})}};e.on(G,r=>{a=r==null?void 0:r.baseApiUrl,i=!0}),e.on($,r=>{u(r)}),setTimeout(async()=>{if(!i){if(l)return;if(n){const r=await W({licenseKey:n,pluginName:s,baseApiUrl:a});r&&u(r)}else c("The `licenseKey` option not provided")}},2e3)}async function W(e){const{licenseKey:t,pluginName:s,baseApiUrl:n}=e;try{return(await j({baseApiUrl:n,path:`/sdk/${t||"na"}`,method:"POST",params:{d:window.location.hostname,pn:s}})).result||{}}catch(o){return console.error("Error during SDK license check:",o),!1}}const b=e=>e.replaceAll('"',"").replaceAll("'",""),v=e=>e.includes(",")?e:/\s/.test(e)?`"${b(e)}"`:b(e),F=(e,t,s)=>({family:e,variant:t,...s}),D=(e,t)=>{e=v(e);const{menuVariant:s,variants:n}=t;return{family:e,familyLabel:b(e),menuVariant:s&&F(v(`menuFont-${b(e)}`),"regular",s),variants:Object.assign({},...Object.entries(n).map(([o,a])=>({[o]:F(e,o,a)})))}},T=(e,t)=>{var l;const s=D(e.family,e),n=s.menuVariant??((l=Object.values(s.variants))==null?void 0:l[0]);if(!n)return"Arial, Helvetica, sans-serif";const{source:o,descriptors:a}=n,i=b(n.family);if(!t){const c=new FontFace(i,`url("${o}")`,a),u=Array.from(document.fonts.values()).filter(r=>r.family===i);for(const r of u)document.fonts.delete(r);document.fonts.add(c),c.load().catch(()=>{})}return v(i)},_=e=>{const{family:t,menu:s,axes:n}=e,o=!!n,a=Object.assign({},...e.variants.map(i=>{var r,g;let l,c;if(o){const f=n.find(d=>d.tag==="wght");if(f){const{start:d,end:P}=f;l=`${d} ${P}`}}return l||(l=((r=i.match(/\d+/))==null?void 0:r[0])??"400"),c=((g=i.match(/[a-zA-Z]+/))==null?void 0:g[0])==="italic"?"italic":void 0,{[i]:{source:e.files[i],descriptors:{style:c,weight:l}}}}));return D(t,{menuVariant:{source:s},variants:a})},K=e=>({id:`${e.family}/${e.version}`,type:"font",src:e.menu,name:e.family,customData:{font:_(e),needsLoading:!0}}),V=e=>{const{font:t}=e.customData;return e.customData.needsLoading?(e.customData.needsLoading=!1,T(t)):T(t,!0)};let h;const H=e=>{const t=[];for(const s of Object.keys(e)){let n=e[s];n&&(Array.isArray(n)?t.push(...n.map(o=>[s,o.toString()])):(n=n.toString(),t.push([s,n])))}return new URLSearchParams(t)},z=e=>{const{apiKey:t,searchParams:s}=e,n=(o={})=>{const a="https://www.googleapis.com/webfonts/v1/webfonts",i=H(o);return`${a}?${i}`};return{id:"google-fonts",types:["font"],label:({editor:o})=>o.I18n.t("googleFontsAssetProvider.providerLabel"),search:{reloadOnInput:!1},async onLoad(){var u;if(h)return h;const o={key:t,sort:"alpha",subset:"latin",capability:["WOFF2","VF"]},a=s==null?void 0:s(),i={...o,...a},c=await(await fetch(n(i))).json();return(u=c.items)!=null&&u.length?(h=c.items.map(K),h):[]},itemLayout:o=>{const a=h.find(l=>l.id===o.assetProps.id),i=V(a);return{type:"column",onClick:()=>o.onSelect(a),htmlAttrs:{title:a.name},style:{borderWidth:"1px",borderRadius:8,overflow:"hidden",cursor:"pointer"},children:[{type:"text",content:a.name,style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontFamily:i,fontSize:"24px",paddingLeft:"8px",paddingRight:"8px"}},{type:"text",content:a.name,style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:"16px",paddingLeft:"8px",paddingRight:"8px"}}]}}}},q={googleFontsAssetProvider:{searchBtn:"Search on Google Fonts",modalTitle:"Select Font",providerLabel:"Google Fonts"}},J="googleFontsAssetProvider",Q=p.startup,Z=function(e,t){const{i18n:s={}}=t,n=z(t);e.runCommand(y.assetProviderAdd,{provider:n}),e.I18n.addMessages({en:q,...s}),N({editor:e,licenseKey:t.licenseKey,plan:Q,pluginName:J,cleanup:()=>{e.runCommand(y.assetProviderRemove,{id:n.id})}})},S=E(Z);module.exports=S;
@@ -1,5 +1,5 @@
1
1
  var p = /* @__PURE__ */ ((e) => (e.free = "free", e.startup = "startup", e.business = "business", e.enterprise = "enterprise", e))(p || {}), y = /* @__PURE__ */ ((e) => (e.toastAdd = "studio:toastAdd", e.dialogOpen = "studio:dialogOpen", e.dialogClose = "studio:dialogClose", e.sidebarLeftSet = "studio:sidebarLeft:set", e.sidebarLeftGet = "studio:sidebarLeft:get", e.sidebarLeftToggle = "studio:sidebarLeft:toggle", e.sidebarRightSet = "studio:sidebarRight:set", e.sidebarRightGet = "studio:sidebarRight:get", e.sidebarRightToggle = "studio:sidebarRight:toggle", e.sidebarTopSet = "studio:sidebarTop:set", e.sidebarTopGet = "studio:sidebarTop:get", e.sidebarTopToggle = "studio:sidebarTop:toggle", e.sidebarBottomSet = "studio:sidebarBottom:set", e.sidebarBottomGet = "studio:sidebarBottom:get", e.sidebarBottomToggle = "studio:sidebarBottom:toggle", e.symbolAdd = "studio:symbolAdd", e.symbolDetach = "studio:symbolDetach", e.symbolOverride = "studio:symbolOverride", e.symbolPropagateStyles = "studio:propagateStyles", e.getPagesConfig = "studio:getPagesConfig", e.setPagesConfig = "studio:setPagesConfig", e.getPageSettings = "studio:getPageSettings", e.setPageSettings = "studio:setPageSettings", e.projectFiles = "studio:projectFiles", e.canvasReload = "studio:canvasReload", e.getBlocksPanel = "studio:getBlocksPanel", e.setBlocksPanel = "studio:setBlocksPanel", e.getStateContextMenu = "studio:getStateContextMenu", e.setStateContextMenu = "studio:setStateContextMenu", e.contextMenuComponent = "studio:contextMenuComponent", e.layoutAdd = "studio:layoutAdd", e.layoutRemove = "studio:layoutRemove", e.layoutToggle = "studio:layoutToggle", e.layoutUpdate = "studio:layoutUpdate", e.layoutGet = "studio:layoutGet", e.layoutConfigGet = "studio:layoutConfigGet", e.layoutConfigSet = "studio:layoutConfigSet", e.getStateTheme = "studio:getStateTheme", e.setStateTheme = "studio:setStateTheme", e.assetProviderGet = "studio:assetProviderGet", e.assetProviderAdd = "studio:assetProviderAdd", e.assetProviderRemove = "studio:assetProviderRemove", e.fontGet = "studio:fontGet", e.fontAdd = "studio:fontAdd", e.fontRemove = "studio:fontRemove", e.fontManagerOpen = "studio:fontManagerOpen", e.menuFontLoad = "studio:menuFontLoad", e.toggleStateDataSource = "studio:toggleStateDataSource", e.getStateDataSource = "studio:getStateDataSource", e.setDragAbsolute = "studio:setDragAbsolute", e))(y || {});
2
- const R = "app.grapesjs.com", x = "app-stage.grapesjs.com", A = [
2
+ const R = "app.grapesjs.com", x = "app-stage.grapesjs.com", w = [
3
3
  R,
4
4
  x,
5
5
  "localhost",
@@ -10,9 +10,9 @@ const R = "app.grapesjs.com", x = "app-stage.grapesjs.com", A = [
10
10
  // For stackblitz.com demos
11
11
  "-sandpack.codesandbox.io"
12
12
  // For Sandpack demos
13
- ], $ = "license:check:start", G = "license:check:end", I = () => typeof window < "u", U = ({ isDev: e, isStage: t }) => `${e ? "" : `https://${t ? x : R}`}/api`, M = () => {
13
+ ], G = "license:check:start", $ = "license:check:end", I = () => typeof window < "u", U = ({ isDev: e, isStage: t }) => `${e ? "" : `https://${t ? x : R}`}/api`, M = () => {
14
14
  const e = I() && window.location.hostname;
15
- return !!e && (A.includes(e) || A.some((t) => e.endsWith(t)));
15
+ return !!e && (w.includes(e) || w.some((t) => e.endsWith(t)));
16
16
  };
17
17
  async function j({
18
18
  path: e,
@@ -46,7 +46,7 @@ function B(e) {
46
46
  return t.init = (s) => (n) => e(n, s), t;
47
47
  }
48
48
  const E = (e) => /* @__PURE__ */ B(e);
49
- async function W({
49
+ async function N({
50
50
  editor: e,
51
51
  plan: t,
52
52
  pluginName: s,
@@ -57,8 +57,8 @@ async function W({
57
57
  const l = M(), c = (a) => {
58
58
  console.warn("Cleanup plugin:", s, "Reason:", a), o();
59
59
  }, u = (a = {}) => {
60
- var w;
61
- const { error: g, sdkLicense: f } = a, d = (w = a.plan) == null ? void 0 : w.category;
60
+ var A;
61
+ const { error: g, sdkLicense: f } = a, d = (A = a.plan) == null ? void 0 : A.category;
62
62
  if (!(f || a.license) || g)
63
63
  c(g || "Invalid license");
64
64
  else if (d) {
@@ -66,22 +66,22 @@ async function W({
66
66
  O > k && c({ pluginRequiredPlan: t, licensePlan: d });
67
67
  }
68
68
  };
69
- e.on($, (a) => {
69
+ e.on(G, (a) => {
70
70
  r = a == null ? void 0 : a.baseApiUrl, i = !0;
71
- }), e.on(G, (a) => {
71
+ }), e.on($, (a) => {
72
72
  u(a);
73
73
  }), setTimeout(async () => {
74
74
  if (!i) {
75
75
  if (l) return;
76
76
  if (n) {
77
- const a = await N({ licenseKey: n, pluginName: s, baseApiUrl: r });
77
+ const a = await W({ licenseKey: n, pluginName: s, baseApiUrl: r });
78
78
  a && u(a);
79
79
  } else
80
80
  c("The `licenseKey` option not provided");
81
81
  }
82
82
  }, 2e3);
83
83
  }
84
- async function N(e) {
84
+ async function W(e) {
85
85
  const { licenseKey: t, pluginName: s, baseApiUrl: n } = e;
86
86
  try {
87
87
  return (await j({
@@ -129,7 +129,7 @@ const b = (e) => e.replaceAll('"', "").replaceAll("'", ""), v = (e) => e.include
129
129
  });
130
130
  }
131
131
  return v(i);
132
- }, K = (e) => {
132
+ }, _ = (e) => {
133
133
  const { family: t, menu: s, axes: n } = e, o = !!n, r = Object.assign(
134
134
  {},
135
135
  ...e.variants.map((i) => {
@@ -159,13 +159,13 @@ const b = (e) => e.replaceAll('"', "").replaceAll("'", ""), v = (e) => e.include
159
159
  },
160
160
  variants: r
161
161
  });
162
- }, V = (e) => ({
162
+ }, K = (e) => ({
163
163
  id: `${e.family}/${e.version}`,
164
164
  type: "font",
165
165
  src: e.menu,
166
166
  name: e.family,
167
- customData: { font: K(e), needsLoading: !0 }
168
- }), _ = (e) => {
167
+ customData: { font: _(e), needsLoading: !0 }
168
+ }), V = (e) => {
169
169
  const { font: t } = e.customData;
170
170
  return e.customData.needsLoading ? (e.customData.needsLoading = !1, T(t)) : T(t, !0);
171
171
  };
@@ -200,10 +200,10 @@ const H = (e) => {
200
200
  ...o,
201
201
  ...r
202
202
  }, c = await (await fetch(n(i))).json();
203
- return (u = c.items) != null && u.length ? (h = c.items.map(V), h) : [];
203
+ return (u = c.items) != null && u.length ? (h = c.items.map(K), h) : [];
204
204
  },
205
205
  itemLayout: (o) => {
206
- const r = h.find((l) => l.id === o.assetProps.id), i = _(r);
206
+ const r = h.find((l) => l.id === o.assetProps.id), i = V(r);
207
207
  return {
208
208
  type: "column",
209
209
  onClick: () => o.onSelect(r),
@@ -252,21 +252,21 @@ const H = (e) => {
252
252
  modalTitle: "Select Font",
253
253
  providerLabel: "Google Fonts"
254
254
  }
255
- }, J = "googleFontsAssetProvider", Q = function(e, t) {
255
+ }, J = "googleFontsAssetProvider", Q = p.startup, Z = function(e, t) {
256
256
  const { i18n: s = {} } = t, n = z(t);
257
257
  e.runCommand(y.assetProviderAdd, { provider: n }), e.I18n.addMessages({
258
258
  en: q,
259
259
  ...s
260
- }), W({
260
+ }), N({
261
261
  editor: e,
262
262
  licenseKey: t.licenseKey,
263
- plan: p.startup,
263
+ plan: Q,
264
264
  pluginName: J,
265
265
  cleanup: () => {
266
266
  e.runCommand(y.assetProviderRemove, { id: n.id });
267
267
  }
268
268
  });
269
- }, Z = E(Q);
269
+ }, S = E(Z);
270
270
  export {
271
- Z as default
271
+ S as default
272
272
  };
@@ -1 +1 @@
1
- (function(d,p){typeof exports=="object"&&typeof module<"u"?module.exports=p():typeof define=="function"&&define.amd?define(p):(d=typeof globalThis<"u"?globalThis:d||self,d.StudioSdkPlugins_googleFontsAssetProvider=p())})(this,function(){"use strict";var d=(e=>(e.free="free",e.startup="startup",e.business="business",e.enterprise="enterprise",e))(d||{}),p=(e=>(e.toastAdd="studio:toastAdd",e.dialogOpen="studio:dialogOpen",e.dialogClose="studio:dialogClose",e.sidebarLeftSet="studio:sidebarLeft:set",e.sidebarLeftGet="studio:sidebarLeft:get",e.sidebarLeftToggle="studio:sidebarLeft:toggle",e.sidebarRightSet="studio:sidebarRight:set",e.sidebarRightGet="studio:sidebarRight:get",e.sidebarRightToggle="studio:sidebarRight:toggle",e.sidebarTopSet="studio:sidebarTop:set",e.sidebarTopGet="studio:sidebarTop:get",e.sidebarTopToggle="studio:sidebarTop:toggle",e.sidebarBottomSet="studio:sidebarBottom:set",e.sidebarBottomGet="studio:sidebarBottom:get",e.sidebarBottomToggle="studio:sidebarBottom:toggle",e.symbolAdd="studio:symbolAdd",e.symbolDetach="studio:symbolDetach",e.symbolOverride="studio:symbolOverride",e.symbolPropagateStyles="studio:propagateStyles",e.getPagesConfig="studio:getPagesConfig",e.setPagesConfig="studio:setPagesConfig",e.getPageSettings="studio:getPageSettings",e.setPageSettings="studio:setPageSettings",e.projectFiles="studio:projectFiles",e.canvasReload="studio:canvasReload",e.getBlocksPanel="studio:getBlocksPanel",e.setBlocksPanel="studio:setBlocksPanel",e.getStateContextMenu="studio:getStateContextMenu",e.setStateContextMenu="studio:setStateContextMenu",e.contextMenuComponent="studio:contextMenuComponent",e.layoutAdd="studio:layoutAdd",e.layoutRemove="studio:layoutRemove",e.layoutToggle="studio:layoutToggle",e.layoutUpdate="studio:layoutUpdate",e.layoutGet="studio:layoutGet",e.layoutConfigGet="studio:layoutConfigGet",e.layoutConfigSet="studio:layoutConfigSet",e.getStateTheme="studio:getStateTheme",e.setStateTheme="studio:setStateTheme",e.assetProviderGet="studio:assetProviderGet",e.assetProviderAdd="studio:assetProviderAdd",e.assetProviderRemove="studio:assetProviderRemove",e.fontGet="studio:fontGet",e.fontAdd="studio:fontAdd",e.fontRemove="studio:fontRemove",e.fontManagerOpen="studio:fontManagerOpen",e.menuFontLoad="studio:menuFontLoad",e.toggleStateDataSource="studio:toggleStateDataSource",e.getStateDataSource="studio:getStateDataSource",e.setDragAbsolute="studio:setDragAbsolute",e))(p||{});const P="app.grapesjs.com",A="app-stage.grapesjs.com",w=[P,A,"localhost","127.0.0.1",".local-credentialless.webcontainer.io",".local.webcontainer.io","-sandpack.codesandbox.io"],D="license:check:start",O="license:check:end",$=()=>typeof window<"u",G=({isDev:e,isStage:t})=>`${e?"":`https://${t?A:P}`}/api`,I=()=>{const e=$()&&window.location.hostname;return!!e&&(w.includes(e)||w.some(t=>e.endsWith(t)))};async function U({path:e,baseApiUrl:t,method:s="GET",headers:n={},params:o,body:a}){const l=`${t||G({isDev:!1,isStage:!1})}${e}`,c={method:s,headers:{"Content-Type":"application/json",...n}};a&&(c.body=JSON.stringify(a));const u=o?new URLSearchParams(o).toString():"",r=u?`?${u}`:"",g=await fetch(`${l}${r}`,c);if(!g.ok)throw new Error(`HTTP error! status: ${g.status}`);return g.json()}const F={[d.free]:0,[d.startup]:10,[d.business]:20,[d.enterprise]:30};function M(e){const t=e;return t.init=s=>n=>e(n,s),t}const j=e=>M(e);async function B({editor:e,plan:t,pluginName:s,licenseKey:n,cleanup:o}){let a="",i=!1;const l=I(),c=r=>{console.warn("Cleanup plugin:",s,"Reason:",r),o()},u=(r={})=>{var k;const{error:g,sdkLicense:y}=r,f=(k=r.plan)==null?void 0:k.category;if(!(y||r.license)||g)c(g||"Invalid license");else if(f){const q=F[t],S=F[f];q>S&&c({pluginRequiredPlan:t,licensePlan:f})}};e.on(D,r=>{a=r==null?void 0:r.baseApiUrl,i=!0}),e.on(O,r=>{u(r)}),setTimeout(async()=>{if(!i){if(l)return;if(n){const r=await E({licenseKey:n,pluginName:s,baseApiUrl:a});r&&u(r)}else c("The `licenseKey` option not provided")}},2e3)}async function E(e){const{licenseKey:t,pluginName:s,baseApiUrl:n}=e;try{return(await U({baseApiUrl:n,path:`/sdk/${t||"na"}`,method:"POST",params:{d:window.location.hostname,pn:s}})).result||{}}catch(o){return console.error("Error during SDK license check:",o),!1}}const h=e=>e.replaceAll('"',"").replaceAll("'",""),v=e=>e.includes(",")?e:/\s/.test(e)?`"${h(e)}"`:h(e),L=(e,t,s)=>({family:e,variant:t,...s}),T=(e,t)=>{e=v(e);const{menuVariant:s,variants:n}=t;return{family:e,familyLabel:h(e),menuVariant:s&&L(v(`menuFont-${h(e)}`),"regular",s),variants:Object.assign({},...Object.entries(n).map(([o,a])=>({[o]:L(e,o,a)})))}},x=(e,t)=>{var l;const s=T(e.family,e),n=s.menuVariant??((l=Object.values(s.variants))==null?void 0:l[0]);if(!n)return"Arial, Helvetica, sans-serif";const{source:o,descriptors:a}=n,i=h(n.family);if(!t){const c=new FontFace(i,`url("${o}")`,a),u=Array.from(document.fonts.values()).filter(r=>r.family===i);for(const r of u)document.fonts.delete(r);document.fonts.add(c),c.load().catch(()=>{})}return v(i)},W=e=>{const{family:t,menu:s,axes:n}=e,o=!!n,a=Object.assign({},...e.variants.map(i=>{var r,g;let l,c;if(o){const y=n.find(f=>f.tag==="wght");if(y){const{start:f,end:R}=y;l=`${f} ${R}`}}return l||(l=((r=i.match(/\d+/))==null?void 0:r[0])??"400"),c=((g=i.match(/[a-zA-Z]+/))==null?void 0:g[0])==="italic"?"italic":void 0,{[i]:{source:e.files[i],descriptors:{style:c,weight:l}}}}));return T(t,{menuVariant:{source:s},variants:a})},N=e=>({id:`${e.family}/${e.version}`,type:"font",src:e.menu,name:e.family,customData:{font:W(e),needsLoading:!0}}),_=e=>{const{font:t}=e.customData;return e.customData.needsLoading?(e.customData.needsLoading=!1,x(t)):x(t,!0)};let b;const K=e=>{const t=[];for(const s of Object.keys(e)){let n=e[s];n&&(Array.isArray(n)?t.push(...n.map(o=>[s,o.toString()])):(n=n.toString(),t.push([s,n])))}return new URLSearchParams(t)},V=e=>{const{apiKey:t,searchParams:s}=e,n=(o={})=>{const a="https://www.googleapis.com/webfonts/v1/webfonts",i=K(o);return`${a}?${i}`};return{id:"google-fonts",types:["font"],label:({editor:o})=>o.I18n.t("googleFontsAssetProvider.providerLabel"),search:{reloadOnInput:!1},async onLoad(){var u;if(b)return b;const o={key:t,sort:"alpha",subset:"latin",capability:["WOFF2","VF"]},a=s==null?void 0:s(),i={...o,...a},c=await(await fetch(n(i))).json();return(u=c.items)!=null&&u.length?(b=c.items.map(N),b):[]},itemLayout:o=>{const a=b.find(l=>l.id===o.assetProps.id),i=_(a);return{type:"column",onClick:()=>o.onSelect(a),htmlAttrs:{title:a.name},style:{borderWidth:"1px",borderRadius:8,overflow:"hidden",cursor:"pointer"},children:[{type:"text",content:a.name,style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontFamily:i,fontSize:"24px",paddingLeft:"8px",paddingRight:"8px"}},{type:"text",content:a.name,style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:"16px",paddingLeft:"8px",paddingRight:"8px"}}]}}}},H={googleFontsAssetProvider:{searchBtn:"Search on Google Fonts",modalTitle:"Select Font",providerLabel:"Google Fonts"}},z="googleFontsAssetProvider";return j(function(e,t){const{i18n:s={}}=t,n=V(t);e.runCommand(p.assetProviderAdd,{provider:n}),e.I18n.addMessages({en:H,...s}),B({editor:e,licenseKey:t.licenseKey,plan:d.startup,pluginName:z,cleanup:()=>{e.runCommand(p.assetProviderRemove,{id:n.id})}})})});
1
+ (function(d,p){typeof exports=="object"&&typeof module<"u"?module.exports=p():typeof define=="function"&&define.amd?define(p):(d=typeof globalThis<"u"?globalThis:d||self,d.StudioSdkPlugins_googleFontsAssetProvider=p())})(this,function(){"use strict";var d=(e=>(e.free="free",e.startup="startup",e.business="business",e.enterprise="enterprise",e))(d||{}),p=(e=>(e.toastAdd="studio:toastAdd",e.dialogOpen="studio:dialogOpen",e.dialogClose="studio:dialogClose",e.sidebarLeftSet="studio:sidebarLeft:set",e.sidebarLeftGet="studio:sidebarLeft:get",e.sidebarLeftToggle="studio:sidebarLeft:toggle",e.sidebarRightSet="studio:sidebarRight:set",e.sidebarRightGet="studio:sidebarRight:get",e.sidebarRightToggle="studio:sidebarRight:toggle",e.sidebarTopSet="studio:sidebarTop:set",e.sidebarTopGet="studio:sidebarTop:get",e.sidebarTopToggle="studio:sidebarTop:toggle",e.sidebarBottomSet="studio:sidebarBottom:set",e.sidebarBottomGet="studio:sidebarBottom:get",e.sidebarBottomToggle="studio:sidebarBottom:toggle",e.symbolAdd="studio:symbolAdd",e.symbolDetach="studio:symbolDetach",e.symbolOverride="studio:symbolOverride",e.symbolPropagateStyles="studio:propagateStyles",e.getPagesConfig="studio:getPagesConfig",e.setPagesConfig="studio:setPagesConfig",e.getPageSettings="studio:getPageSettings",e.setPageSettings="studio:setPageSettings",e.projectFiles="studio:projectFiles",e.canvasReload="studio:canvasReload",e.getBlocksPanel="studio:getBlocksPanel",e.setBlocksPanel="studio:setBlocksPanel",e.getStateContextMenu="studio:getStateContextMenu",e.setStateContextMenu="studio:setStateContextMenu",e.contextMenuComponent="studio:contextMenuComponent",e.layoutAdd="studio:layoutAdd",e.layoutRemove="studio:layoutRemove",e.layoutToggle="studio:layoutToggle",e.layoutUpdate="studio:layoutUpdate",e.layoutGet="studio:layoutGet",e.layoutConfigGet="studio:layoutConfigGet",e.layoutConfigSet="studio:layoutConfigSet",e.getStateTheme="studio:getStateTheme",e.setStateTheme="studio:setStateTheme",e.assetProviderGet="studio:assetProviderGet",e.assetProviderAdd="studio:assetProviderAdd",e.assetProviderRemove="studio:assetProviderRemove",e.fontGet="studio:fontGet",e.fontAdd="studio:fontAdd",e.fontRemove="studio:fontRemove",e.fontManagerOpen="studio:fontManagerOpen",e.menuFontLoad="studio:menuFontLoad",e.toggleStateDataSource="studio:toggleStateDataSource",e.getStateDataSource="studio:getStateDataSource",e.setDragAbsolute="studio:setDragAbsolute",e))(p||{});const P="app.grapesjs.com",A="app-stage.grapesjs.com",w=[P,A,"localhost","127.0.0.1",".local-credentialless.webcontainer.io",".local.webcontainer.io","-sandpack.codesandbox.io"],D="license:check:start",O="license:check:end",G=()=>typeof window<"u",$=({isDev:e,isStage:t})=>`${e?"":`https://${t?A:P}`}/api`,I=()=>{const e=G()&&window.location.hostname;return!!e&&(w.includes(e)||w.some(t=>e.endsWith(t)))};async function U({path:e,baseApiUrl:t,method:s="GET",headers:n={},params:o,body:a}){const l=`${t||$({isDev:!1,isStage:!1})}${e}`,c={method:s,headers:{"Content-Type":"application/json",...n}};a&&(c.body=JSON.stringify(a));const u=o?new URLSearchParams(o).toString():"",r=u?`?${u}`:"",g=await fetch(`${l}${r}`,c);if(!g.ok)throw new Error(`HTTP error! status: ${g.status}`);return g.json()}const L={[d.free]:0,[d.startup]:10,[d.business]:20,[d.enterprise]:30};function M(e){const t=e;return t.init=s=>n=>e(n,s),t}const j=e=>M(e);async function B({editor:e,plan:t,pluginName:s,licenseKey:n,cleanup:o}){let a="",i=!1;const l=I(),c=r=>{console.warn("Cleanup plugin:",s,"Reason:",r),o()},u=(r={})=>{var k;const{error:g,sdkLicense:y}=r,f=(k=r.plan)==null?void 0:k.category;if(!(y||r.license)||g)c(g||"Invalid license");else if(f){const S=L[t],J=L[f];S>J&&c({pluginRequiredPlan:t,licensePlan:f})}};e.on(D,r=>{a=r==null?void 0:r.baseApiUrl,i=!0}),e.on(O,r=>{u(r)}),setTimeout(async()=>{if(!i){if(l)return;if(n){const r=await E({licenseKey:n,pluginName:s,baseApiUrl:a});r&&u(r)}else c("The `licenseKey` option not provided")}},2e3)}async function E(e){const{licenseKey:t,pluginName:s,baseApiUrl:n}=e;try{return(await U({baseApiUrl:n,path:`/sdk/${t||"na"}`,method:"POST",params:{d:window.location.hostname,pn:s}})).result||{}}catch(o){return console.error("Error during SDK license check:",o),!1}}const h=e=>e.replaceAll('"',"").replaceAll("'",""),v=e=>e.includes(",")?e:/\s/.test(e)?`"${h(e)}"`:h(e),F=(e,t,s)=>({family:e,variant:t,...s}),T=(e,t)=>{e=v(e);const{menuVariant:s,variants:n}=t;return{family:e,familyLabel:h(e),menuVariant:s&&F(v(`menuFont-${h(e)}`),"regular",s),variants:Object.assign({},...Object.entries(n).map(([o,a])=>({[o]:F(e,o,a)})))}},x=(e,t)=>{var l;const s=T(e.family,e),n=s.menuVariant??((l=Object.values(s.variants))==null?void 0:l[0]);if(!n)return"Arial, Helvetica, sans-serif";const{source:o,descriptors:a}=n,i=h(n.family);if(!t){const c=new FontFace(i,`url("${o}")`,a),u=Array.from(document.fonts.values()).filter(r=>r.family===i);for(const r of u)document.fonts.delete(r);document.fonts.add(c),c.load().catch(()=>{})}return v(i)},N=e=>{const{family:t,menu:s,axes:n}=e,o=!!n,a=Object.assign({},...e.variants.map(i=>{var r,g;let l,c;if(o){const y=n.find(f=>f.tag==="wght");if(y){const{start:f,end:R}=y;l=`${f} ${R}`}}return l||(l=((r=i.match(/\d+/))==null?void 0:r[0])??"400"),c=((g=i.match(/[a-zA-Z]+/))==null?void 0:g[0])==="italic"?"italic":void 0,{[i]:{source:e.files[i],descriptors:{style:c,weight:l}}}}));return T(t,{menuVariant:{source:s},variants:a})},W=e=>({id:`${e.family}/${e.version}`,type:"font",src:e.menu,name:e.family,customData:{font:N(e),needsLoading:!0}}),_=e=>{const{font:t}=e.customData;return e.customData.needsLoading?(e.customData.needsLoading=!1,x(t)):x(t,!0)};let b;const K=e=>{const t=[];for(const s of Object.keys(e)){let n=e[s];n&&(Array.isArray(n)?t.push(...n.map(o=>[s,o.toString()])):(n=n.toString(),t.push([s,n])))}return new URLSearchParams(t)},V=e=>{const{apiKey:t,searchParams:s}=e,n=(o={})=>{const a="https://www.googleapis.com/webfonts/v1/webfonts",i=K(o);return`${a}?${i}`};return{id:"google-fonts",types:["font"],label:({editor:o})=>o.I18n.t("googleFontsAssetProvider.providerLabel"),search:{reloadOnInput:!1},async onLoad(){var u;if(b)return b;const o={key:t,sort:"alpha",subset:"latin",capability:["WOFF2","VF"]},a=s==null?void 0:s(),i={...o,...a},c=await(await fetch(n(i))).json();return(u=c.items)!=null&&u.length?(b=c.items.map(W),b):[]},itemLayout:o=>{const a=b.find(l=>l.id===o.assetProps.id),i=_(a);return{type:"column",onClick:()=>o.onSelect(a),htmlAttrs:{title:a.name},style:{borderWidth:"1px",borderRadius:8,overflow:"hidden",cursor:"pointer"},children:[{type:"text",content:a.name,style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontFamily:i,fontSize:"24px",paddingLeft:"8px",paddingRight:"8px"}},{type:"text",content:a.name,style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:"16px",paddingLeft:"8px",paddingRight:"8px"}}]}}}},H={googleFontsAssetProvider:{searchBtn:"Search on Google Fonts",modalTitle:"Select Font",providerLabel:"Google Fonts"}},z="googleFontsAssetProvider",q=d.startup;return j(function(e,t){const{i18n:s={}}=t,n=V(t);e.runCommand(p.assetProviderAdd,{provider:n}),e.I18n.addMessages({en:H,...s}),B({editor:e,licenseKey:t.licenseKey,plan:q,pluginName:z,cleanup:()=>{e.runCommand(p.assetProviderRemove,{id:n.id})}})})});
@@ -0,0 +1,3 @@
1
+ import { SdkPlanCategories } from '../utils';
2
+ export declare const PLUGIN_NAME = "googleFontsAssetProvider";
3
+ export declare const PLUGIN_PLAN = SdkPlanCategories.startup;
@@ -75,11 +75,11 @@ export interface BaseGoogleFontsSearchParams {
75
75
  }
76
76
  export interface BaseGoogleFontsAssetProviderOptions extends SDKPluginOptions {
77
77
  /**
78
- * A YouTube Data API v3 key. Get yours at https://console.cloud.google.com/
78
+ * Google font API key. Get yours at https://console.cloud.google.com/
79
79
  */
80
80
  apiKey?: string;
81
81
  /**
82
- * Override search params used for listing videos.
82
+ * Override search params used for the listing.
83
83
  */
84
84
  searchParams?: '__fn__';
85
85
  i18n?: Messages;