16 lines
30 KiB
JavaScript
16 lines
30 KiB
JavaScript
function Ee(e,t){let n=t.top<27,r=t.height>=54,i=t.width>=window.innerWidth-4,a=i?"8px":"-2px",m=i?"8px":"4px";n&&r?(e.style.top="2px",e.style.left=m):n?(e.style.top=`${t.height+2}px`,e.style.left=a):(e.style.top="-27px",e.style.left=a)}function q(e){let t=e;return!!(t.dataset?.sourceLocation||t.dataset?.visualSelectorId)}function _(e){let t=e;return t.dataset?.sourceLocation||t.dataset?.visualSelectorId||null}var j=["src"],M="data-vite-plugin-element";function H(e){if(!e)return[];let t=Array.from(document.querySelectorAll(`[data-source-location="${e}"]`));return t.length>0?t:Array.from(document.querySelectorAll(`[data-visual-selector-id="${e}"]`))}function ge(e,t){e.forEach(n=>{n.setAttribute("class",t)})}function he(e,t,n,r){if(!j.includes(t))return;let i=r!=null?String(r):null;e.forEach(a=>{(i===null||a.dataset.arrIndex===i)&&a.setAttribute(t,n)})}function ve(e,t){let n={};for(let r of t){let i=e.getAttribute(r);i!==null&&(n[r]=i)}return n}function ye(){if(document.getElementById("freeze-animations"))return;document.documentElement.setAttribute("data-visual-edit-active","");let e=document.createElement("style");e.id="freeze-animations",e.textContent=`
|
|
[data-visual-edit-active] *:not([${M}]):not([${M}] *),
|
|
[data-visual-edit-active] *:not([${M}]):not([${M}] *)::before,
|
|
[data-visual-edit-active] *:not([${M}]):not([${M}] *)::after {
|
|
animation-play-state: paused !important;
|
|
transition: none !important;
|
|
}
|
|
`;let t=document.createElement("style");t.id="freeze-pointer-events",t.textContent=`
|
|
[data-visual-edit-active] * { pointer-events: none !important; }
|
|
[${M}], [${M}] * { pointer-events: auto !important; }
|
|
`;let n=document.head||document.documentElement;n.appendChild(e),n.appendChild(t),document.getAnimations().forEach(r=>{let i=r.effect?.target;if(!(i instanceof Element&&i.closest(`[${M}]`)))try{r.finish()}catch{r.pause()}})}function be(){let e=document.getElementById("freeze-animations");e&&(e.remove(),document.getElementById("freeze-pointer-events")?.remove(),document.documentElement.removeAttribute("data-visual-edit-active"),document.getAnimations().forEach(t=>{if(t.playState==="paused")try{t.play()}catch{}}))}function Z(e,t){let n=document.getElementById("freeze-pointer-events");n&&(n.disabled=!0);let r=document.elementFromPoint(e,t);return n&&(n.disabled=!1),r?.closest("[data-source-location], [data-visual-selector-id]")??null}function Le(e,t,n){let r=Z(e,t);if(!r)return null;let i=_(r);return i===n?null:i}var dt="visual-edit-font-face-";function ct(e){let t=e.trim();if(!t.startsWith("@font-face")||t.includes("\\"))return!1;let n=(t.match(/{/g)||[]).length,r=(t.match(/}/g)||[]).length;if(n!==1||r!==1||!t.endsWith("}"))return!1;let i=t.split(/url\(/i);for(let a=1;a<i.length;a++){let m=i[a].indexOf(")");if(m===-1)return!1;let u=i[a].slice(0,m).trim().replace(/^['"]|['"]$/g,"").trim();if(!/^https:\/\//i.test(u))return!1}return!0}function Te(e,t){if(typeof e!="string"||!e.trim()||typeof t!="string"||!ct(t))return;let n=`${dt}${e}`;if(document.getElementById(n))return;let r=document.createElement("style");r.id=n,r.dataset.visualEditFontFace="true",r.textContent=t,document.head.appendChild(r)}var we={position:"absolute",backgroundColor:"#ffffff",border:"1px solid #e2e8f0",borderRadius:"6px",boxShadow:"0 4px 12px rgba(0, 0, 0, 0.15)",fontSize:"12px",minWidth:"120px",maxHeight:"200px",overflowY:"auto",zIndex:"10001",padding:"4px 0",pointerEvents:"auto"},Se={padding:"4px 12px",cursor:"pointer",color:"#334155",backgroundColor:"transparent",whiteSpace:"nowrap",lineHeight:"1.5",fontWeight:"400"},X="#526cff",Ie="#DBEAFE",Me="600",J="#f1f5f9",Ce=10,Q='<svg width="12" height="12" viewBox="0 0 24 24" style="vertical-align:middle;margin-left:4px"><path d="M6 9l6 6 6-6" stroke="currentColor" stroke-width="2" fill="none"/></svg>',Ae='<svg width="12" height="12" viewBox="0 0 24 24" style="vertical-align:middle;margin-left:4px"><path d="M18 15l-6-6-6 6" stroke="currentColor" stroke-width="2" fill="none"/></svg>',k="data-chevron",_e=12,V="data-layer-dropdown",De=2,xe=2;function ee(e,t){for(let n of Object.keys(t))e.style.setProperty(n.replace(/[A-Z]/g,r=>`-${r.toLowerCase()}`),t[n])}function He(e){return e.tagName}function te(e,t){let n={element:e,tagName:e.tagName.toLowerCase(),selectorId:_(e)};return t!==void 0&&(n.depth=t),n}function Oe(e,t,n){let r=[];function i(a,m){if(!(m>t))for(let u=0;u<a.children.length;u++){let v=a.children[u];if(q(v)){let f={element:v,tagName:v.tagName.toLowerCase(),selectorId:_(v)};n!==void 0&&(f.depth=n+m-1),r.push(f),i(v,m+1)}else i(v,m)}}return i(e,1),r}function ut(e){let t=[],n=e.parentElement;for(;n&&n!==document.documentElement&&n!==document.body&&t.length<De;)q(n)&&t.push(te(n)),n=n.parentElement;return t.reverse(),t}function ft(e,t){return t.forEach((n,r)=>{e.push({...n,depth:r})}),t.length}function Ne(e,t,n){e.push(te(t,n));let r=Oe(t,xe,n+1);e.push(...r)}function mt(e){return e.at(-1)?.element??null}function pt(e,t){let n=Oe(e,1);return n.some(r=>r.element===t)||n.push(te(t)),n}function Et(e,t,n,r){let i=_(n),a=new Set;for(let m of t)if(m.element===n)Ne(e,n,r),i&&a.add(i);else{let u=m.selectorId;if(u!=null){if(u===i||a.has(u))continue;a.add(u)}e.push({...m,depth:r})}}function Re(e){let t=ut(e),n=[],r=ft(n,t),i=mt(t);if(i){let a=pt(i,e);Et(n,a,e,r)}else Ne(n,e,r);return n}var P=null,ne=null,F=null,Y=null,W=null;function gt(e,t,{onSelect:n,onHover:r,onHoverEnd:i}){let a=document.createElement("div");a.textContent=He(e),ee(a,Se);let m=e.depth??0;return m>0&&(a.style.paddingLeft=`${_e+m*Ce}px`),t&&(a.style.color=X,a.style.backgroundColor=Ie,a.style.fontWeight=Me),a.addEventListener("mouseenter",()=>{t||(a.style.backgroundColor=J),r&&r(e)}),a.addEventListener("mouseleave",()=>{t||(a.style.backgroundColor="transparent"),i&&i()}),a.addEventListener("click",u=>{u.stopPropagation(),u.preventDefault(),n(e)}),a}function ht(e,t,n){let r=document.createElement("div");return r.setAttribute(V,"true"),r.setAttribute(M,"true"),ee(r,we),e.forEach(i=>{let a=i.element===t;r.appendChild(gt(i,a,n))}),r}function Pe(e){if(e.querySelector(`[${k}]`))return;let t=document.createElement("span");t.setAttribute(k,"true"),t.style.display="inline-flex",t.innerHTML=Q,e.appendChild(t),e.style.display="inline-flex",e.style.alignItems="center",e.style.cursor="pointer",e.style.userSelect="none",e.style.whiteSpace="nowrap",e.style.pointerEvents="auto",e.setAttribute(V,"true"),e.setAttribute(M,"true")}function vt(e,t,n,{onSelect:r,onHover:i,onHoverEnd:a}){let m=Array.from(e.children),u=t.findIndex(f=>f.element===n),v=f=>{if(u>=0&&u<m.length){let y=m[u];y.style.color!==X&&(y.style.backgroundColor="transparent")}if(u=f,u>=0&&u<m.length){let y=m[u];y.style.color!==X&&(y.style.backgroundColor=J),y.scrollIntoView({block:"nearest"}),i&&u>=0&&u<t.length&&i(t[u])}};W=f=>{f.key==="ArrowDown"?(f.preventDefault(),f.stopPropagation(),v(u<m.length-1?u+1:0)):f.key==="ArrowUp"?(f.preventDefault(),f.stopPropagation(),v(u>0?u-1:m.length-1)):f.key==="Enter"&&u>=0&&u<t.length&&(f.preventDefault(),f.stopPropagation(),a&&a(),r(t[u]),O())},document.addEventListener("keydown",W,!0)}function yt(e,t){let n=!0;F=r=>{if(n){n=!1;return}let i=r.target;!e.contains(i)&&i!==t&&O()},document.addEventListener("mousedown",F,!0)}function Be(e,t,n,r){O();let i=ht(t,n,{...r,onSelect:u=>{r.onHoverEnd&&r.onHoverEnd(),r.onSelect(u),O()}}),a=e.parentElement;if(!a)return;i.style.top=`${e.offsetTop+e.offsetHeight+2}px`,i.style.left=`${e.offsetLeft}px`,a.appendChild(i),P=i,ne=e;let m=e.querySelector(`[${k}]`);m&&(m.innerHTML=Ae),Y=r.onHoverEnd??null,vt(i,t,n,r),yt(i,e)}function O(){let e=ne?.querySelector(`[${k}]`);e&&(e.innerHTML=Q),ne=null,Y&&(Y(),Y=null),P&&P.parentNode&&P.remove(),P=null,F&&(document.removeEventListener("mousedown",F,!0),F=null),W&&(document.removeEventListener("keydown",W,!0),W=null)}function ke(){return P!==null}function Ve(e){let t=null,n=null,r=null,i=()=>{t&&t.parentNode&&t.remove(),t=null},a=L=>{i(),_(L.element)!==e.getSelectedElementId()&&(t=e.createPreviewOverlay(L.element))},m=L=>{i(),O(),n&&(document.removeEventListener("keydown",n,!0),n=null),r=null;let s=e.selectElement(L.element);f(s,L.element)},u=()=>{n&&(document.removeEventListener("keydown",n,!0),n=null),r&&(m(r),r=null)},v=(L,s,c,S,C)=>{L.stopPropagation(),L.preventDefault(),ke()?(O(),u()):(r={element:c,tagName:c.tagName.toLowerCase(),selectorId:C},e.onDeselect(),n=w=>{w.key==="Escape"&&(w.stopPropagation(),O(),u())},document.addEventListener("keydown",n,!0),Be(s,S,c,{onSelect:m,onHover:a,onHoverEnd:i}))},f=(L,s)=>{if(!L)return;let c=L.querySelector("div");if(!c)return;let S=Re(s);if(S.length<=1)return;let C=_(s);Pe(c),c.addEventListener("click",w=>{v(w,c,s,S,C)})};return{attachToOverlay:f,cleanup:()=>{i(),O()}}}var oe="visual-edit-focus-styles",bt=["div","p","h1","h2","h3","h4","h5","h6","span","li","td","a","button","label"],re=e=>!!e.dataset.arrField,Lt=e=>!(!bt.includes(e.tagName.toLowerCase())||!e.textContent?.trim()||e.querySelector("img, video, canvas, svg")||e.children?.length>0),Fe=()=>{if(document.getElementById(oe))return;let e=document.createElement("style");e.id=oe,e.textContent=`
|
|
[data-selected="true"][contenteditable="true"]:focus {
|
|
outline: none !important;
|
|
}
|
|
`,document.head.appendChild(e)},We=()=>{document.getElementById(oe)?.remove()},$e=e=>{let t=document.createRange();t.selectNodeContents(e);let n=window.getSelection();n?.removeAllRanges(),n?.addRange(t)},Tt=e=>!(e instanceof HTMLElement)||!Lt(e)?!1:re(e)?!0:e.dataset.dynamicContent!=="true",ie=e=>!(e instanceof HTMLElement)||e.dataset.selected!=="true"?!1:Tt(e);var wt=500;function se(e){let t=null,n=null,r=!1,i=new WeakMap,a=()=>{let s=e.getSelectedElementId();if(!s)return;let c=e.findElementsById(s);e.getSelectedOverlays().forEach((C,w)=>{w<c.length&&c[w]&&e.positionOverlay(C,c[w])})},m=s=>{let c=s.dataset.originalTextContent,S=s.textContent,C=s,w=s.getBoundingClientRect(),N={type:"inline-edit",elementInfo:{tagName:s.tagName,classes:C.className?.baseVal||s.className||"",visualSelectorId:e.getSelectedElementId(),content:S,dataSourceLocation:s.dataset.sourceLocation,isDynamicContent:s.dataset.dynamicContent==="true",linenumber:s.dataset.linenumber,filename:s.dataset.filename,position:{top:w.top,left:w.left,right:w.right,bottom:w.bottom,width:w.width,height:w.height,centerX:w.left+w.width/2,centerY:w.top+w.height/2}},originalContent:c,newContent:S};re(s)&&(N.arrIndex=s.dataset.arrIndex,N.arrVariableName=s.dataset.arrVariableName,N.arrField=s.dataset.arrField),window.parent.postMessage(N,"*"),s.dataset.originalTextContent=S||""},u=s=>{n&&clearTimeout(n),n=setTimeout(()=>m(s),wt)},v=s=>{a(),u(s)},f=function(){v(this)},y=s=>{Fe(),s.dataset.originalTextContent=s.textContent||"",s.dataset.originalCursor=s.style.cursor,s.contentEditable="true",s.setAttribute(M,"true");let c=new AbortController;i.set(s,c),s.addEventListener("input",f,{signal:c.signal}),s.style.cursor="text",$e(s),setTimeout(()=>{s.isConnected&&s.focus()},0)},L=s=>{let c=i.get(s);c&&(c.abort(),i.delete(s)),s.isConnected&&(We(),s.contentEditable="false",s.removeAttribute(M),delete s.dataset.originalTextContent,s.dataset.originalCursor!==void 0&&(s.style.cursor=s.dataset.originalCursor,delete s.dataset.originalCursor))};return{get enabled(){return r},set enabled(s){r=s},isEditing(){return t!==null},getCurrentElement(){return t},canEdit(s){return ie(s)},startEditing(s){t=s,e.getSelectedOverlays().forEach(c=>{c.style.display="none"}),y(s),window.parent.postMessage({type:"content-editing-started",visualSelectorId:e.getSelectedElementId()},"*")},stopEditing(){if(!t)return;n&&(clearTimeout(n),n=null),L(t),e.getSelectedOverlays().forEach(c=>{c.style.display=""}),a(),window.parent.postMessage({type:"content-editing-ended",visualSelectorId:e.getSelectedElementId()},"*"),t=null},markElementsSelected(s){s.forEach(c=>{c instanceof HTMLElement&&(c.dataset.selected="true")})},clearSelectedMarks(s){s&&e.findElementsById(s).forEach(c=>{c instanceof HTMLElement&&delete c.dataset.selected})},handleToggleMessage(s){if(!r)return;let c=e.findElementsById(s.dataSourceLocation);if(c.length===0||!(c[0]instanceof HTMLElement))return;let S=c[0];if(s.inlineEditingMode){if(!ie(S))return;e.getSelectedElementId()!==s.dataSourceLocation&&(this.stopEditing(),e.clearSelection(),this.markElementsSelected(c),e.createSelectionOverlays(c,s.dataSourceLocation)),this.startEditing(S)}else t===S&&this.stopEditing()},cleanup(){this.stopEditing()}}}var le="__theme-font-preview";function St(e){return e instanceof Element?e:e instanceof Node?e.parentElement:null}function It(e){return St(e)?.closest(`[${M}]`)!=null}function Xe(){let e=!1,t=i=>{if(It(i.target))return;if(i.preventDefault(),i.ctrlKey||i.metaKey){window.parent.postMessage({type:"canvas-wheel-zoom",data:{deltaY:i.deltaY,deltaMode:i.deltaMode,clientX:i.clientX,clientY:i.clientY,ctrlKey:i.ctrlKey,metaKey:i.metaKey}},"*");return}let a={deltaX:i.deltaX,deltaY:i.deltaY,deltaMode:i.deltaMode,clientX:i.clientX,clientY:i.clientY,shiftKey:i.shiftKey,ctrlKey:!1,metaKey:!1};window.parent.postMessage({type:"canvas-wheel-pan",data:a},"*")};return{enable:()=>{e||(e=!0,window.addEventListener("wheel",t,{capture:!0,passive:!1}))},disable:()=>{e&&(e=!1,window.removeEventListener("wheel",t,!0))}}}var ae="--base44-reference-vh-base";function ze(){let e=null,t=null,n,r,i="*",a=()=>{n!==void 0&&(window.clearTimeout(n),n=void 0),r!==void 0&&(window.clearTimeout(r),r=void 0)};return{freezeVhUnits:m=>{let u=Mt(m);if(Ct(u),e){t?.();return}e=[],t=At(e)},measurePageHeight:(m,u=2e3)=>{i=m,a(),n=window.setTimeout(()=>{n=void 0,t?.();let v=Ye()+1500,f=-1,y=0,L=c=>{r=void 0,window.parent.postMessage({type:"page-height-measured",height:c},i)},s=()=>{r=void 0;let c=Dt();if(c===f?y++:(y=1,f=c),y>=3||Ye()>=v){L(c);return}r=window.setTimeout(s,16)};s()},u)},teardown:()=>{if(e){for(let m of e)m();e=null,t=null}a()}}}function Ye(){return typeof performance<"u"&&typeof performance.now=="function"?performance.now():Date.now()}function Mt(e){if(e!==void 0)return e;let t=window.innerHeight||0;return t>=400?t:900}function Ct(e){document.documentElement.style.setProperty(ae,`${e}px`)}function At(e){let t=/(\d+(?:\.\d+)?)(?:d|s|l)?vh\b/g,n=new WeakSet,r=new WeakMap,i=new WeakSet,a=new Set,m=new WeakSet,u=p=>p.replace(t,(g,T)=>`calc(var(${ae}) * ${_t(T)})`),v=p=>{if(m.has(p))return;let T=window.getComputedStyle(p).overflowY;T!=="auto"&&T!=="scroll"||(m.add(p),p.style.setProperty("overflow-y","visible","important"))},f=p=>{v(p),p.querySelectorAll("*").forEach(v)},y=p=>{let g=p.style;if(!g||g.length===0)return;let T=[];for(let I=0;I<g.length;I++){let D=g[I];D&&T.push(D)}for(let I of T){let D=g.getPropertyValue(I);if(!D||D.indexOf("vh")===-1)continue;let B=u(D);B!==D&&g.setProperty(I,B,g.getPropertyPriority(I))}},s=kt(()=>{document.querySelectorAll("style").forEach(p=>{if(S(p),n.has(p))return;n.add(p);let g=p.textContent;if(!g||g.indexOf("vh")===-1)return;let T=u(g);T!==g&&(p.textContent=T)});for(let p=0;p<document.styleSheets.length;p++){let g=document.styleSheets[p];if(!g)continue;let T;try{T=g.cssRules}catch{continue}r.get(g)!==T.length&&(Ke(T,u),r.set(g,T.length))}document.querySelectorAll('[style*="vh"]').forEach(y),document.body&&f(document.body)},16),c=s.trigger;e.push(s.cancel);let S=p=>{if(i.has(p))return;i.add(p);let g=new MutationObserver(()=>{n.delete(p),c()});g.observe(p,{characterData:!0,childList:!0,subtree:!0}),a.add(g)};e.push(()=>{for(let p of a)p.disconnect();a.clear()}),c(),document.readyState==="loading"&&(document.addEventListener("DOMContentLoaded",c),e.push(()=>document.removeEventListener("DOMContentLoaded",c))),window.addEventListener("load",c),e.push(()=>window.removeEventListener("load",c));let C=new MutationObserver(p=>{for(let g of p)if(Ue(g.addedNodes)||Ue(g.removedNodes)){c();return}});e.push(()=>C.disconnect());let w=()=>{document.head&&C.observe(document.head,{childList:!0,subtree:!1})};document.head?w():(document.addEventListener("DOMContentLoaded",w),e.push(()=>document.removeEventListener("DOMContentLoaded",w)));let N=p=>{if(!(p instanceof Element))return;let g=p.getAttribute("style");g&&g.indexOf("vh")!==-1&&y(p),p.querySelectorAll('[style*="vh"]').forEach(y),f(p)},$=new MutationObserver(p=>{for(let g of p)if(g.type==="attributes"){let T=g.target;if(!(T instanceof Element))continue;let I=T.getAttribute("style");if(!I||I.indexOf("vh")===-1)continue;y(T)}else if(g.type==="childList")for(let T=0;T<g.addedNodes.length;T++){let I=g.addedNodes[T];I&&N(I)}});return e.push(()=>$.disconnect()),(()=>{let p=document.documentElement;p&&$.observe(p,{attributes:!0,attributeFilter:["style"],childList:!0,subtree:!0})})(),c}function _t(e){return String(Number((parseFloat(e)/100).toFixed(6)))}function Ke(e,t){for(let n=0;n<e.length;n++){let r=e[n];if(!r)continue;r.cssRules&&Ke(r.cssRules,t);let i=r.style;if(i)for(let a=0;a<i.length;a++){let m=i[a];if(!m)continue;let u=i.getPropertyValue(m);if(!u||u.indexOf("vh")===-1)continue;let v=t(u);v!==u&&i.setProperty(m,v,i.getPropertyPriority(m))}}}function Ue(e){for(let t=0;t<e.length;t++){let n=e[t];if(n instanceof HTMLStyleElement||n instanceof HTMLLinkElement)return!0}return!1}function Dt(){let e=Math.max(document.documentElement.scrollHeight,document.body?.scrollHeight??0),t=xt(),n=Math.max(window.innerHeight||0,document.documentElement.clientHeight,t),r=Ht(n);return r>0?Math.ceil(Math.max(r,t)):Math.ceil(Math.max(e,t))}function xt(){let e=document.documentElement.style.getPropertyValue(ae),t=parseFloat(e);return Number.isFinite(t)?t:0}function Ht(e){if(!document.body)return 0;let t=[document.body,...Array.from(document.body.querySelectorAll("*"))],n=new WeakMap,r=window.scrollY+e;for(let i=t.length-1;i>=0;i--){let a=t[i];if(!a)continue;let m=Ot(a,n),u=Nt(a),v=Bt(u,m,e,r)?0:u.bottom;n.set(a,Math.max(m,v))}return n.get(document.body)??0}function Ot(e,t){let n=0;for(let r=0;r<e.children.length;r++){let i=e.children[r];i&&(n=Math.max(n,t.get(i)??0))}return n}function Nt(e){let t=window.getComputedStyle(e);if(Pt(t))return{bottom:0,height:0};let n=e.getBoundingClientRect();return n.width===0&&n.height===0?{bottom:0,height:0}:{bottom:n.bottom+window.scrollY+Rt(t),height:n.height}}function Rt(e){let t=parseFloat(e.marginBottom);return Number.isFinite(t)?t:0}function Pt(e){return e.position==="fixed"?!0:e.position==="absolute"&&e.pointerEvents==="none"}function Bt(e,t,n,r){return t>0&&Math.abs(e.bottom-r)<=1&&Math.abs(e.height-n)<=1&&e.bottom-t>8}function kt(e,t){let n;return{trigger:()=>{n!==void 0&&window.clearTimeout(n),n=window.setTimeout(e,t)},cancel:()=>{n!==void 0&&(window.clearTimeout(n),n=void 0)}}}var R="data-base44-suppressed-popup",Vt="--base44-reference-vh-base";function qe(){let e=null,t=null,n=!1,r=!1,i=(f,y)=>{if(!(f instanceof HTMLElement)||f.hasAttribute(R))return;let L=window.getComputedStyle(f);if(L.position==="fixed"&&ue(L)){if($t(f,y)&&Xt(f,L)){a(f);return}r&&je(f,y)&&ce(f)}},a=f=>{f.hasAttribute(R)||(ce(f),r=!0,Ft(de()))},m=(f,y)=>{i(f,y);let L=f.querySelectorAll(`*:not([${R}])`);for(let s=0;s<L.length;s++){let c=L[s];c&&i(c,y)}},u=()=>{e||(e=new MutationObserver(f=>{let y=de();for(let L of f)if(L.type==="childList")for(let s=0;s<L.addedNodes.length;s++){let c=L.addedNodes[s];c instanceof Element&&m(c,y)}}),e.observe(document.documentElement,{childList:!0,subtree:!0}))},v=()=>{document.body&&(m(document.body,de()),u())};return{suppress:()=>{n||(n=!0,document.body?v():(t=()=>{t=null,v()},document.addEventListener("DOMContentLoaded",t)))},teardown:()=>{n=!1,r=!1,e&&(e.disconnect(),e=null),t&&(document.removeEventListener("DOMContentLoaded",t),t=null)}}}function Ft(e){if(!document.body||e.vw<=0||e.vh<=0)return;let t=document.body.querySelectorAll(`*:not([${R}])`);for(let n=0;n<t.length;n++){let r=t[n];r&&Wt(r,e)&&ce(r)}}function Wt(e,t){if(e.hasAttribute(R))return!1;let n=window.getComputedStyle(e);return n.position!=="fixed"||!ue(n)?!1:je(e,t)}function $t(e,t){if(t.vw<=0||t.vh<=0)return!1;let n=e.getBoundingClientRect();return n.width>=t.vw*.9&&n.height>=t.vh*.9}function je(e,t){let n=e.getBoundingClientRect();return n.width>=t.vw*.15&&n.height>=t.vh*.15&&n.width<=t.vw*.95&&n.height<=t.vh*.95}function ue(e){let t=parseInt(e.zIndex,10);return Number.isFinite(t)&&t>=40}function Xt(e,t){if(Ge(t.backgroundColor)||t.backdropFilter&&t.backdropFilter!=="none")return!0;let n=e.querySelectorAll("*");for(let r=0;r<n.length;r++){let i=n[r];if(!i)continue;let a=window.getComputedStyle(i);if(!(a.position!=="fixed"&&a.position!=="absolute")&&ue(a)&&(Ge(a.backgroundColor)||a.backdropFilter&&a.backdropFilter!=="none"))return!0}return!1}function Ge(e){let t=Yt(e);return t!==null&&t>0&&t<1}function Yt(e){if(!e)return null;let t=/^rgba?\(\s*\d+\s*,\s*\d+\s*,\s*\d+\s*(?:,\s*([0-9.]+)\s*)?\)$/.exec(e);if(t)return t[1]===void 0?1:parseFloat(t[1]);let n=/\/\s*([0-9.]+)(%?)\s*\)$/.exec(e);if(n){let r=parseFloat(n[1]);return n[2]==="%"?r/100:r}return/^[a-z]+\s*\(/.test(e)?1:null}function de(){let e=window.innerWidth||document.documentElement.clientWidth||0,t=document.documentElement.style.getPropertyValue(Vt),n=parseFloat(t),r=Number.isFinite(n)&&n>0?n:window.innerHeight||document.documentElement.clientHeight||0;return{vw:e,vh:r}}function ce(e){e.hasAttribute(R)||(e.setAttribute(R,"1"),e.style.setProperty("display","none","important"))}var U=50;function Ut(){let e=Xe(),t=ze(),n=qe(),r=!1,i=!1,a=!1,m=[],u=[],v=[],f=null,y=null,L=(l=!1)=>{let o=document.createElement("div");return o.style.position="absolute",o.style.pointerEvents="none",o.style.transition="all 0.1s ease-in-out",o.style.zIndex="9999",l?o.style.border="2px solid #2563EB":(o.style.border="2px solid #95a5fc",o.style.backgroundColor="rgba(99, 102, 241, 0.05)"),o},s=(l,o,d=!1)=>{if(!o||!r)return;o.offsetWidth;let h=o.getBoundingClientRect();l.style.top=`${h.top+window.scrollY}px`,l.style.left=`${h.left+window.scrollX}px`,l.style.width=`${h.width}px`,l.style.height=`${h.height}px`;let b=l.querySelector("div");b||(b=document.createElement("div"),b.textContent=o.tagName.toLowerCase(),b.style.position="absolute",b.style.left="-2px",b.style.padding="2px 8px",b.style.fontSize="11px",b.style.fontWeight=d?"500":"400",b.style.color=d?"#ffffff":"#526cff",b.style.backgroundColor=d?"#2563EB":"#DBEAFE",b.style.borderRadius="3px",b.style.minWidth="24px",b.style.textAlign="center",l.appendChild(b)),Ee(b,h)},c=se({findElementsById:H,getSelectedElementId:()=>f,getSelectedOverlays:()=>u,positionOverlay:s,clearSelection:()=>{c.clearSelectedMarks(f),w(),f=null,y=null},createSelectionOverlays:(l,o)=>{l.forEach(d=>{let E=L(!0);document.body.appendChild(E),u.push(E),s(E,d,!0)}),f=o}}),S=()=>{c.clearSelectedMarks(f),w(),f=null,y=null},C=()=>{m.forEach(l=>{l&&l.parentNode&&l.remove()}),m=[],v=[]},w=()=>{u.forEach(l=>{l&&l.parentNode&&l.remove()}),u=[]},N=["p","h1","h2","h3","h4","h5","h6","span","a","label"],$=l=>{let o=l,d=l.getBoundingClientRect(),E=l,h=N.includes(l.tagName?.toLowerCase()),b=o.closest("[data-arr-variable-name]"),A=b?.dataset?.arrVariableName||null,x=b?.dataset?.arrIndex,rt=x!=null?parseInt(x,10):null,it=o.dataset?.arrField||null,st=o.closest("[data-collection-id]"),lt=o.closest("[data-collection-item-field]"),at=o.closest("[data-collection-item-id]");window.parent.postMessage({type:"element-selected",tagName:l.tagName,classes:E.className?.baseVal||l.className||"",visualSelectorId:_(l),content:h?o.innerText:void 0,dataSourceLocation:o.dataset.sourceLocation,isDynamicContent:o.dataset.dynamicContent==="true",linenumber:o.dataset.linenumber,filename:o.dataset.filename,position:{top:d.top,left:d.left,right:d.right,bottom:d.bottom,width:d.width,height:d.height,centerX:d.left+d.width/2,centerY:d.top+d.height/2},attributes:ve(l,j),isTextElement:h,staticArrayName:A,staticArrayIndex:rt,staticArrayField:it,collectionId:st?.dataset?.collectionId||null,collectionItemField:lt?.dataset?.collectionItemField||null,collectionItemId:at?.dataset?.collectionItemId||null},"*")},z=l=>{let o=_(l);return w(),H(o||null).forEach(E=>{let h=L(!0);document.body.appendChild(h),u.push(h),s(h,E,!0)}),f=o||null,y=l,C(),$(l),u[0]},p=()=>{f=null,window.parent.postMessage({type:"unselect-element"},"*")},g=null,T=null,I=()=>{C(),g=null},D=l=>{let o=H(l);C(),o.forEach(d=>{let E=L(!1);document.body.appendChild(E),m.push(E),s(E,d)}),v=o,g=l},B=l=>{!r||i||c.isEditing()||T===null&&(T=requestAnimationFrame(()=>{if(T=null,a){I();return}let o=Le(l.clientX,l.clientY,f);if(!o){I();return}g!==o&&D(o)}))},K=()=>{T!==null&&(cancelAnimationFrame(T),T=null),I()},fe=l=>{if(!r)return;let o=l.target;if(o.closest(`[${V}]`)||c.enabled&&o instanceof HTMLElement&&o.contentEditable==="true")return;if(c.isEditing()){l.preventDefault(),l.stopPropagation(),l.stopImmediatePropagation(),c.stopEditing();return}if(a){l.preventDefault(),l.stopPropagation(),l.stopImmediatePropagation(),window.parent.postMessage({type:"close-dropdowns"},"*");return}l.preventDefault(),l.stopPropagation(),l.stopImmediatePropagation();let d=Z(l.clientX,l.clientY);if(!d)return;let E=d,h=_(d);if(f===h&&E.dataset.selected==="true"&&c.enabled&&c.canEdit(E)){c.startEditing(E);return}c.stopEditing(),c.enabled&&c.markElementsSelected(H(h));let A=z(d);me.attachToOverlay(A,d)},Ze=()=>{c.stopEditing(),S()},Je=(l,o)=>{let d=H(l);d.length!==0&&(ge(d,o),setTimeout(()=>{f===l&&u.forEach((E,h)=>{h<d.length&&s(E,d[h])}),v.length>0&&v[0]?.dataset?.visualSelectorId===l&&m.forEach((b,A)=>{A<v.length&&s(b,v[A])})},U))},Qe=(l,o,d,E)=>{let h=H(l);if(h.length===0)return;let b=E??(f===l?y?.dataset.arrIndex:void 0);he(h,o,d,b),setTimeout(()=>{f===l&&u.forEach((A,x)=>{x<h.length&&s(A,h[x])})},U)},et=(l,o,d)=>{let E=H(l);E.length!==0&&(d!=null&&(E=E.filter(h=>h.dataset.arrIndex===String(d))),E.forEach(h=>{h.innerText=o}),setTimeout(()=>{f===l&&u.forEach((h,b)=>{b<E.length&&s(h,E[b])})},U))},me=Ve({createPreviewOverlay:l=>{let o=L(!1);return o.style.zIndex="9998",document.body.appendChild(o),s(o,l),o},getSelectedElementId:()=>f,selectElement:z,onDeselect:p}),tt=l=>{r=l,l?(document.body.style.cursor="crosshair",ye(),document.addEventListener("mousemove",B),document.addEventListener("mouseleave",K),document.addEventListener("click",fe,!0)):(e.disable(),be(),c.stopEditing(),S(),me.cleanup(),K(),document.body.style.cursor="default",document.removeEventListener("mousemove",B),document.removeEventListener("mouseleave",K),document.removeEventListener("click",fe,!0))},pe=()=>{if(f){let l=y;if(l&&l.isConnected){let o=l.getBoundingClientRect(),d=window.innerHeight,E=window.innerWidth,h=o.top<d&&o.bottom>0&&o.left<E&&o.right>0,b={top:o.top,left:o.left,right:o.right,bottom:o.bottom,width:o.width,height:o.height,centerX:o.left+o.width/2,centerY:o.top+o.height/2};window.parent.postMessage({type:"element-position-update",position:b,isInViewport:h,visualSelectorId:f},"*")}}},nt=l=>{let o=l.data;switch(o.type){case"toggle-visual-edit-mode":tt(o.data.enabled),o.data.specs?.newInlineEditEnabled!==void 0&&(c.enabled=o.data.specs.newInlineEditEnabled);break;case"update-classes":o.data&&o.data.classes!==void 0?Je(o.data.visualSelectorId,o.data.classes):console.warn("[VisualEditAgent] Invalid update-classes message:",o);break;case"update-attribute":o.data&&o.data.visualSelectorId&&o.data.attribute!==void 0&&o.data.value!==void 0?Qe(o.data.visualSelectorId,o.data.attribute,o.data.value,o.data.arrIndex):console.warn("[VisualEditAgent] Invalid update-attribute message:",o);break;case"unselect-element":Ze();break;case"refresh-page":window.location.reload();break;case"update-content":o.data&&o.data.content!==void 0?et(o.data.visualSelectorId,o.data.content,o.data.arrIndex):console.warn("[VisualEditAgent] Invalid update-content message:",o);break;case"request-element-position":if(f&&y&&y.isConnected){let d=y.getBoundingClientRect(),E=window.innerHeight,h=window.innerWidth,b=d.top<E&&d.bottom>0&&d.left<h&&d.right>0,A={top:d.top,left:d.left,right:d.right,bottom:d.bottom,width:d.width,height:d.height,centerX:d.left+d.width/2,centerY:d.top+d.height/2};window.parent.postMessage({type:"element-position-update",position:A,isInViewport:b,visualSelectorId:f},"*")}break;case"popover-drag-state":o.data&&o.data.isDragging!==void 0&&(i=o.data.isDragging,o.data.isDragging&&C());break;case"dropdown-state":o.data&&o.data.isOpen!==void 0&&(a=o.data.isOpen,o.data.isOpen&&C());break;case"update-theme-variables":if(o.data?.variables){let d=o.data.mode==="dark"?document.querySelector(".dark"):document.documentElement;if(d)for(let[E,h]of Object.entries(o.data.variables))d.style.setProperty(E,h)}break;case"inject-font-import":if(o.data?.fontUrl){let d=document.getElementById(le);d||(d=document.createElement("style"),d.id=le,document.head.appendChild(d)),d.textContent=`@import url('${o.data.fontUrl}');`}break;case"inject-font-face":o.data&&Te(o.data.id,o.data.css);break;case"toggle-inline-edit-mode":o.data&&c.handleToggleMessage(o.data);break;case"freeze-vh-units":t.freezeVhUnits(typeof o.referenceVhBase=="number"?o.referenceVhBase:void 0);break;case"measure-page-height":t.measurePageHeight(l.origin&&l.origin!=="null"?l.origin:"*",typeof o.settleMs=="number"?o.settleMs:void 0);break;case"suppress-auto-popups":n.suppress();break;case"toggle-canvas-wheel-zoom-bridge":e.enable();break;default:break}},G=()=>{if(f){let l=H(f);u.forEach((o,d)=>{d<l.length&&s(o,l[d])})}v.length>0&&m.forEach((l,o)=>{o<v.length&&s(l,v[o])})};document.querySelectorAll("[data-linenumber]:not([data-visual-selector-id])").forEach((l,o)=>{let d=l,E=`visual-id-${d.dataset.filename}-${d.dataset.linenumber}-${o}`;d.dataset.visualSelectorId=E});let ot=new MutationObserver(l=>{l.some(d=>{let E=b=>{if(b.nodeType===Node.ELEMENT_NODE){let A=b;if(A.dataset&&A.dataset.visualSelectorId)return!0;for(let x=0;x<A.children.length;x++)if(E(A.children[x]))return!0}return!1};return d.type==="attributes"&&(d.attributeName==="style"||d.attributeName==="class"||d.attributeName==="width"||d.attributeName==="height")&&E(d.target)})&&setTimeout(G,U)});window.addEventListener("message",nt),window.addEventListener("scroll",pe,!0),document.addEventListener("scroll",pe,!0),window.addEventListener("resize",G),window.addEventListener("scroll",G),ot.observe(document.body,{attributes:!0,childList:!0,subtree:!0,attributeFilter:["style","class","width","height"]}),window.parent.postMessage({type:"visual-edit-agent-ready"},"*")}export{Ut as setupVisualEditAgent};
|
|
//# sourceMappingURL=index.mjs.map
|