Optimized the root .gitignore to exclude virtual environments, node modules, and temp folders to ensure clean and lightweight version tracking. Co-authored-by: Cursor <cursoragent@cursor.com>
461 lines
255 KiB
JavaScript
461 lines
255 KiB
JavaScript
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/chunks/index.js","assets/chunks/index2.js","assets/chunks/vendor-common.js","assets/chunks/vendor-react.js","assets/chunks/_commonjsHelpers.js","assets/chunks/preload-helper.js","assets/chunks/_commonjs-dynamic-modules.js"])))=>i.map(i=>d[i]);
|
||
import{i as mt,D as zt,f as Wi,W as Rr,a as Ut,b as En,u as Xi,n as Pr,p as Yi,c as ji,P as Ji,d as Qi,e as Zi,g as es,s as Mr,h as ts,j as ns}from"./use-feedback-bridge.js?v=1775123024591";import{j as Re,R as de,c as rs}from"./vendor-react.js?v=1775123024591";import{N as os,O as is,C as ss,A as as}from"./vendor-antd.js?v=1775123024591";import{_ as cs}from"./preload-helper.js?v=1775123024591";const ls=2,Ke="[WebEditorV2]",_r="__mcp_web_editor_v2_host__",Xo="__mcp_web_editor_v2_overlay__",Yo="__mcp_web_editor_v2_ui__",us=2147483647,Me={hover:"#008F5D",selected:"#008F5D",selectionBorder:"#008F5D",dragGhost:"rgba(0, 143, 93, 0.22)",insertionLine:"#008F5D",guideLine:"rgba(0, 143, 93, 0.72)",distanceLabelBg:"rgba(18, 18, 18, 0.94)",distanceLabelBorder:"rgba(0, 143, 93, 0.24)",distanceLabelText:"rgba(255, 255, 255, 0.98)"},ds=5,fs=3,hs=6,ms=2,gs=30,Lr=300,ps=1,ys=1,bs=1,ws=4,Ss='600 11px system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif',Es=6,vs=3,Ts=4,Cs=8,vn=15,xs=40;function at(t){return t&&typeof t=="object"?t:null}function ct(t){if(typeof t=="string")return t.trim()||void 0}function en(t){if(typeof t=="number"&&Number.isFinite(t))return t;const e=Number.parseInt(String(t),10);return Number.isFinite(e)?e:void 0}function tn(t){if(!t)return;if(typeof t=="function"){const n=t;return ct(n.displayName)??ct(n.name)}const e=at(t);if(e)return ct(e.displayName)??ct(e.name)}function As(t){let e=t;for(let n=0;n<xs&&e;n++){const r=at(e);if(!r)break;const o=at(r._debugSource),s=ct(o==null?void 0:o.fileName);if(s){const m=tn(r.elementType)??tn(r.type);return{file:s,line:en(o==null?void 0:o.lineNumber),column:en(o==null?void 0:o.columnNumber),componentName:m}}const i=at(r._debugOwner),a=at(i==null?void 0:i._debugSource),l=ct(a==null?void 0:a.fileName);if(l){const m=tn(i==null?void 0:i.elementType)??tn(i==null?void 0:i.type);return{file:l,line:en(a==null?void 0:a.lineNumber),column:en(a==null?void 0:a.columnNumber),componentName:m}}e=r.return}return null}function Is(t){try{let e=t;for(let n=0;n<vn&&e;n++){const r=e;for(const o of Object.keys(r))if(o.startsWith("__reactFiber$")||o.startsWith("__reactInternalInstance$")){const s=As(r[o]);if(s)return s}e=e.parentElement}}catch{}return null}function ks(t){if(typeof t!="string")return null;const e=t.trim();if(!e)return null;const n=e.match(/:(\d+)(?::(\d+))?$/);if(!n)return{file:e};const r=e.slice(0,n.index).trim();if(!r)return null;const o=Number.parseInt(n[1],10),s=n[2]?Number.parseInt(n[2],10):void 0;return{file:r,line:Number.isFinite(o)&&o>0?o:void 0,column:s!==void 0&&Number.isFinite(s)&&s>0?s:void 0}}function Ns(t){try{let e=t;for(let n=0;n<vn&&e;n++){if(typeof e.getAttribute=="function"){const r=e.getAttribute("data-v-inspector");if(r){const o=ks(r);if(o!=null&&o.file)return o}}e=e.parentElement}}catch{}return null}function Rs(t){try{const e=Ns(t);if(e!=null&&e.file){let r,o=t;for(let s=0;s<vn&&o;s++){const a=at(o.__vueParentComponent),l=at(a==null?void 0:a.type);if(r=ct(l==null?void 0:l.name),r)break;o=o.parentElement}return{...e,componentName:r}}let n=t;for(let r=0;r<vn&&n;r++){const s=at(n.__vueParentComponent),i=at(s==null?void 0:s.type),a=ct(i==null?void 0:i.__file);if(a)return{file:a,componentName:ct(i==null?void 0:i.name)};n=n.parentElement}}catch{}return null}function Ps(t){const e=Is(t);if(e)return e;const n=Rs(t);return n||null}const Zn=5,Ms=32,_s=8,Ls=["data-testid","data-test-id","data-test","data-qa","data-cy","name","title","alt","aria-label"],Ds=3,Bs=["data-testid","data-test-id","data-test","data-qa","data-cy"],Fs=24,jo=20;function nt(t){if(typeof CSS<"u"&&typeof CSS.escape=="function")return CSS.escape(t);const e=String(t),n=e.length;if(n===0)return"";let r="";const o=e.charCodeAt(0);for(let s=0;s<n;s++){const i=e.charCodeAt(s);if(i===0){r+="<22>";continue}if(i>=1&&i<=31||i===127||s===0&&i>=48&&i<=57||s===1&&i>=48&&i<=57&&o===45){r+=`\\${i.toString(16)} `;continue}if(s===0&&n===1&&i===45){r+=`\\${e.charAt(s)}`;continue}i>=48&&i<=57||i>=65&&i<=90||i>=97&&i<=122||i===45||i===95?r+=e.charAt(s):r+=`\\${e.charAt(s)}`}return r}function fr(t){var n;const e=(n=t.getRootNode)==null?void 0:n.call(t);return e instanceof ShadowRoot?e:document}function wn(t,e){try{return t.querySelector(e)}catch{return null}}function Ve(t,e){try{return t.querySelectorAll(e).length===1}catch{return!1}}function Jo(t,e){var o;const n=(o=t.id)==null?void 0:o.trim();if(!n)return null;const r=`#${nt(n)}`;return Ve(e,r)?r:null}function Ks(t,e,n){var s;const r=[];if(n<=0)return r;const o=t.tagName.toLowerCase();for(const i of Ls){if(r.length>=n)break;const a=(s=t.getAttribute(i))==null?void 0:s.trim();if(!a)continue;const l=`[${i}="${nt(a)}"]`;if(Ve(e,l)){r.push(l);continue}const m=`${o}${l}`;Ve(e,m)&&r.push(m)}return r}function Hs(t,e,n){const r=[];if(n<=0)return r;const o=t.tagName.toLowerCase(),s=Array.from(t.classList).filter(l=>l&&/^[a-zA-Z_][a-zA-Z0-9_-]*$/.test(l)).slice(0,Fs);if(s.length===0)return r;const i=new Map;for(const l of s){if(r.length>=n)return r;const m=`.${nt(l)}`,P=Ve(e,m);i.set(l,P),P&&r.push(m)}for(const l of s){if(r.length>=n)return r;if(i.get(l)===!0)continue;const m=`${o}.${nt(l)}`;Ve(e,m)&&r.push(m)}const a=Math.min(s.length,Ds);for(let l=0;l<a;l++)for(let m=l+1;m<a;m++){if(r.length>=n)return r;const P=s[l],L=s[m],S=`.${nt(P)}.${nt(L)}`;if(Ve(e,S)){r.push(S);continue}const R=`${o}${S}`;Ve(e,R)&&r.push(R)}if(a>=3&&r.length<n){const l=`.${nt(s[0])}.${nt(s[1])}.${nt(s[2])}`;if(Ve(e,l))r.push(l);else{const m=`${o}${l}`;r.length<n&&Ve(e,m)&&r.push(m)}}return r}function $s(t,e){const n=[];let r=t;const o=e instanceof Document;for(;r&&r.nodeType===Node.ELEMENT_NODE;){const i=r.tagName.toLowerCase();if(o&&i==="body")break;let a=i;const l=r.parentElement,m=r.parentNode;let P;l?P=Array.from(l.children):m instanceof ShadowRoot||m instanceof Document?P=Array.from(m.children):P=[];const L=P.filter(S=>S.tagName===r.tagName);if(L.length>1){const S=L.indexOf(r)+1;a+=`:nth-of-type(${S})`}if(n.unshift(a),r=l,!l&&m===e)break}const s=n.join(" > ");return o?`body > ${s}`:s||"*"}function Us(t,e,n){const r=[];let o=e;for(let s=0;o&&o!==t&&s<jo;s++){let a=o.tagName.toLowerCase();const l=o.parentElement,m=o.parentNode;let P;l?P=Array.from(l.children):m instanceof ShadowRoot||m instanceof Document?P=Array.from(m.children):P=[];const L=P.filter(S=>S.tagName===o.tagName);if(L.length>1){const S=L.indexOf(o)+1;a+=`:nth-of-type(${S})`}if(r.unshift(a),!l){if(m===n)break;break}o=l}return o!==t?null:r.join(" > ")||null}function Os(t,e){var o;const n=Jo(t,e);if(n)return n;const r=t.tagName.toLowerCase();for(const s of Bs){const i=(o=t.getAttribute(s))==null?void 0:o.trim();if(!i)continue;const a=`[${s}="${nt(i)}"]`;if(Ve(e,a))return a;const l=`${r}${a}`;if(Ve(e,l))return l}return null}function qs(t,e){let n=t.parentElement;for(let r=0;n&&r<jo;r++){const o=n.tagName.toUpperCase();if(o==="HTML"||o==="BODY")break;const s=Os(n,e);if(s){const i=Us(n,t,e);if(!i){n=n.parentElement;continue}const a=`${s} ${i}`;if(!Ve(e,a)){n=n.parentElement;continue}if(wn(e,a)===t)return a}n=n.parentElement}return null}function Gs(t){var r;const e=[];let n=t;for(;;){const o=(r=n.getRootNode)==null?void 0:r.call(n);if(!(o instanceof ShadowRoot))break;const s=o.host;if(!(s instanceof Element))break;const i=fr(s),a=Ws(s,{root:i});if(!a)break;e.unshift(a),n=s}return e.length>0?e:void 0}function Vs(t,e){return t.replace(/\s+/g," ").trim().slice(0,e)}function Qo(t){var i,a;const e=[],n=((i=t.tagName)==null?void 0:i.toLowerCase())??"unknown";e.push(n);const r=(a=t.id)==null?void 0:a.trim();r&&e.push(`id=${r}`);const o=Array.from(t.classList).slice(0,_s);o.length>0&&e.push(`class=${o.join(".")}`);const s=Vs(t.textContent??"",Ms);return s&&e.push(`text=${s}`),e.join("|")}function zs(t){const e=[];let n=t;for(;n;){const r=n.parentElement;if(r){const i=Array.from(r.children).indexOf(n);i>=0&&e.unshift(i),n=r;continue}const o=n.parentNode;if(o instanceof ShadowRoot||o instanceof Document){const i=Array.from(o.children).indexOf(n);i>=0&&e.unshift(i)}break}return e}function Zo(t,e={}){const n=e.root??fr(t),r=Math.max(1,e.maxCandidates??Zn),o=[],s=(m,P=r)=>{if(!m||o.length>=P)return;const L=m.trim();!L||o.includes(L)||o.push(L)},i=r>=Zn?qs(t,n):null,a=1+(i?1:0),l=Math.max(1,r-a);s(Jo(t,n),l);for(const m of Ks(t,n,l-o.length))s(m,l);for(const m of Hs(t,n,l-o.length))s(m,l);return s($s(t,n)),s(i),o.slice(0,r)}function Ws(t,e={}){return Zo(t,e)[0]??""}function Se(t){const e=fr(t),n=Ps(t)??void 0;return{selectors:Zo(t,{root:e,maxCandidates:Zn}),fingerprint:Qo(t),path:zs(t),shadowHostChain:Gs(t),debugSource:n}}function Dr(t,e){try{return t.querySelectorAll(e).length===1}catch{return!1}}function Xs(t,e){const n=Qo(t),r=e.split("|"),o=n.split("|");if(r[0]!==o[0])return!1;const s=r.find(a=>a.startsWith("id=")),i=o.find(a=>a.startsWith("id="));return!(s&&s!==i)}function we(t,e=document){var o,s;let n=e;if((o=t.frameChain)!=null&&o.length)for(const i of t.frameChain){const a=wn(n,i);if(!(a instanceof HTMLIFrameElement))return null;const l=a.contentDocument;if(!l)return null;n=l}let r=n;if((s=t.shadowHostChain)!=null&&s.length)for(const i of t.shadowHostChain){if(!Dr(r,i))return null;const a=wn(r,i);if(!a)return null;const l=a.shadowRoot;if(!l)return null;r=l}for(const i of t.selectors){if(!Dr(r,i))continue;const a=wn(r,i);if(a&&!(t.fingerprint&&!Xs(a,t.fingerprint)))return a}return null}function Oe(t){var o,s;const e=t.selectors.join("|"),n=((o=t.shadowHostChain)==null?void 0:o.join(">"))??"";return`frame:${((s=t.frameChain)==null?void 0:s.join(">"))??""}|shadow:${n}|sel:${e}`}const Br=new WeakMap,Fr=new WeakMap;let Ys=0,js=0,Fn;const Js=["data-testid","data-test-id","data-test","data-qa","data-cy","name","aria-label","title","alt"],It=48,Qs=64;function In(t){return(t!=null&&t.tagName?String(t.tagName):"").toLowerCase().trim()||"unknown"}function Qe(t){return typeof t=="string"?t.trim():""}function Zs(t){return String(t??"").replace(/\s+/g," ").trim()}function ht(t,e){const n=String(t??"");return n.length<=e?n:n.slice(0,Math.max(0,e-1)).trimEnd()+"…"}function ea(){if(Fn!==void 0)return Fn;let t="";try{const e=window.frameElement;if(e instanceof HTMLIFrameElement){const n=In(e),r=Qe(e.id||e.getAttribute("id"));if(r)t=`${n}#${r}`;else{const o=Qe(e.name||e.getAttribute("name"));if(o)t=`${n}[name="${ht(o,It)}"]`;else{const s=Qe(e.getAttribute("src")||e.src);t=s?`${n}[src="${ht(s,It)}"]`:n}}}}catch{t=""}return Fn=t,t}function ta(t){const e=Fr.get(t);if(e)return e;const n=In(t),r=Qe(t.id||t.getAttribute("id")),o=r?`${n}#${r}`:`${n}_h${++js}`;return Fr.set(t,o),o}function ei(t,e){var i;const n=typeof ShadowRoot<"u",r=typeof Element<"u",o=[];let s=t;for(;;){let a;try{a=(i=s.getRootNode)==null?void 0:i.call(s)}catch{a=null}if(!n||!(a instanceof ShadowRoot))break;const l=a.host;if(!r||!(l instanceof Element))break;o.unshift(ta(l)),s=l}return o.length>0?o.join(">"):""}function na(t){for(const e of Js){const n=Qe(t.getAttribute(e));if(n)return{attr:e,value:n}}return null}function Ne(t,e){const n=Br.get(t);if(n)return n;const r=In(t),o=Qe(t.id||t.getAttribute("id")),s=o?`${r}#${o}`:`${r}_${++Ys}`,i=[],a=ea();a&&i.push(`frame:${a}`);const l=ei(t);l&&i.push(`shadow:${l}`),i.push(s);const m=i.join("|");return Br.set(t,m),m}function ti(t){const e=In(t),n=typeof HTMLInputElement<"u",r=typeof HTMLIFrameElement<"u",o=Qe(t.id||t.getAttribute("id"));if(o)return`${e}#${o}`;const s=na(t);if(s)return`${e}[${s.attr}="${ht(s.value,It)}"]`;const i=Qe(t.getAttribute("role"));if(i)return`${e}[role="${ht(i,It)}"]`;if(n&&t instanceof HTMLInputElement){const l=Qe(t.getAttribute("type")||t.type);if(l&&l!=="text")return`${e}[type="${ht(l,It)}"]`;const m=Qe(t.getAttribute("placeholder")||t.placeholder);if(m)return`${e}[placeholder="${ht(m,It)}"]`}if(r&&t instanceof HTMLIFrameElement){const l=Qe(t.getAttribute("src")||t.src);if(l)return`${e}[src="${ht(l,It)}"]`}const a=Zs(t.textContent??"");return a?`${e}("${ht(a,Qs)}")`:e}function bt(t,e){const n=ti(t),r=ei(t);return r?`${r} >> ${n}`:n}const Kr=96,Hr=64,ra=new Set(["style","text","class"]);function er(t){return String(t??"").trim()}function Ot(t){return String(t??"").trim()}function $r(t){return String(t??"").replace(/\s+/g," ").trim()}function Tn(t,e){const n=String(t??"");return n.length<=e?n:n.slice(0,Math.max(0,e-1)).trimEnd()+"…"}function Ur(t){const e=[],n=new Set;for(const r of t??[]){const o=String(r??"").trim();o&&(n.has(o)||(n.add(o),e.push(o)))}return e}function oa(t){if(typeof document>"u")return null;try{return we(t)}catch{return null}}function ia(t,e){let n="";const r=er(t.fingerprint);if(r){const l=r.split("|").map(S=>S.trim()).filter(Boolean),m=l[0]??"element",P=l.find(S=>S.startsWith("id=")),L=P?P.slice(3).trim():"";n=L?`${m}#${L}`:m}else Array.isArray(t.selectors)&&t.selectors.length>0?n=Tn(er(t.selectors[0]),Hr)||"element":n=Tn(e,Hr)||"element";const o=[],s=(t.frameChain??[]).join(">").trim(),i=(t.shadowHostChain??[]).join(">").trim();s&&o.push(s),i&&o.push(i);const a=o.length?`${o.join(">")} >> ${n}`:n;return{label:n,fullLabel:a}}function sa(t,e){const n=oa(t);return n?{label:ti(n),fullLabel:bt(n,t.shadowHostChain)}:ia(t,e)}function aa(t,e,n){return Number(t)+Number(e)+Number(n)>1?"mixed":t?"style":e?"text":n?"class":"mixed"}function ca(t){const e=new Map,n=new Map,r=new Map;for(const L of t){if(L.type!=="style")continue;const S=L.before.styles??{},R=L.before.computedStyles??{},I=L.after.styles??{},h=new Set([...Object.keys(S),...Object.keys(I)]);for(const T of h){const x=String(T??"").trim();if(!x)continue;const B=Ot(S[x]),K=Ot(R[x]),_=B||K,v=Ot(I[x]);e.has(x)||(e.set(x,B),n.set(x,_)),r.set(x,v)}}if(e.size===0&&r.size===0)return null;const o={},s={},i=new Set([...e.keys(),...r.keys()]);for(const L of i){const S=e.get(L)??"",R=r.get(L)??"";if(S===R)continue;const I=n.get(L)??S;o[L]=I,s[L]=R}const a=Array.from(new Set([...Object.keys(o),...Object.keys(s)])).sort();if(a.length===0)return null;let l=0,m=0,P=0;for(const L of a){const S=Ot(o[L]),R=Ot(s[L]);!S&&R?l+=1:S&&!R?m+=1:P+=1}return{before:o,after:s,added:l,removed:m,modified:P,details:a}}function la(t){let e,n;for(const s of t)s.type==="text"&&(e===void 0&&(e=String(s.before.text??"")),n=String(s.after.text??""));if(e===void 0||n===void 0||e===n)return null;const r=Tn($r(e),Kr),o=Tn($r(n),Kr);return{before:e,after:n,beforePreview:r,afterPreview:o}}function ua(t){let e,n;for(const m of t)m.type==="class"&&(e||(e=Ur(m.before.classes)),n=Ur(m.after.classes));if(!e||!n)return null;const r=new Set(e),o=new Set(n),s=Array.from(o).filter(m=>!r.has(m)).sort(),i=Array.from(r).filter(m=>!o.has(m)).sort();if(s.length===0&&i.length===0)return null;const a=Array.from(r).sort(),l=Array.from(o).sort();return{before:a,after:l,added:s,removed:i}}function tt(t){var o;const e=t.map((s,i)=>({tx:s,index:i}));e.sort((s,i)=>{const a=Number(s.tx.timestamp??0),l=Number(i.tx.timestamp??0);return a!==l?a-l:s.index-i.index});const n=new Map;for(const{tx:s}of e){if(!ra.has(s.type))continue;const i=er(s.elementKey);let a;if(i)a=i;else try{a=Oe(s.targetLocator)}catch{a=`unknown:${s.id}`}const l=n.get(a);l?l.push(s):n.set(a,[s])}const r=[];for(const[s,i]of n.entries()){if(i.length===0)continue;const a=i[i.length-1],l=((o=a.after)==null?void 0:o.locator)??a.targetLocator,m=ca(i),P=la(i),L=ua(i),S=m!==null,R=P!==null,I=L!==null;if(!S&&!R&&!I)continue;const{label:h,fullLabel:T}=sa(l,s),x={elementKey:s,locator:l};m&&(x.styleChanges={before:m.before,after:m.after}),P&&(x.textChange={before:P.before,after:P.after}),L&&(x.classChanges={before:L.before,after:L.after});const B={};m&&(B.style={added:m.added,removed:m.removed,modified:m.modified,details:m.details}),P&&(B.text={beforePreview:P.beforePreview,afterPreview:P.afterPreview}),L&&(B.class={added:L.added,removed:L.removed});const K=i.reduce((v,H)=>{const q=Number(H.timestamp??0);return Number.isFinite(q)?Math.max(v,q):v},0),_=aa(S,R,I);r.push({elementKey:s,label:h,fullLabel:T,locator:l,type:_,changes:B,transactionIds:i.map(v=>v.id),netEffect:x,updatedAt:K,debugSource:l.debugSource})}return r.sort((s,i)=>i.updatedAt-s.updatedAt||s.label.localeCompare(i.label)),r}function _e(t,e=0){const n=Number(t);return Number.isFinite(n)?n:e}function tr(t,e,n){return n<e?e:Math.min(n,Math.max(e,t))}function ni(t,e){const n=_e(e,0);return n<=0?0:tr(_e(t,0)/n*100,0,100)}function ri(t){const e=_e(t.clientX,0),n=_e(t.clientY,0),r=_e(t.scrollX,0),o=_e(t.scrollY,0),s=!!t.isFixed;return{clientX:e,clientY:n,documentX:e+r,documentY:n+o,xPercent:ni(e,t.viewportWidth),y:s?n:n+o,isFixed:s,offsetX:Number.isFinite(Number(t.offsetX))?Number(t.offsetX):void 0,offsetY:Number.isFinite(Number(t.offsetY))?Number(t.offsetY):void 0}}function hr(t){if(!t)return null;const e=_e(t.clientX,0),n=_e(t.clientY,0),r=_e(t.documentX,e),o=_e(t.documentY,n),s=!!t.isFixed,i=Number.isFinite(Number(t.xPercent))?_e(t.xPercent,0):ni(e,typeof window<"u"?window.innerWidth:0),a=Number.isFinite(Number(t.y))?_e(t.y,0):s?n:o;return{clientX:e,clientY:n,documentX:r,documentY:o,xPercent:i,y:a,isFixed:s,offsetX:Number.isFinite(Number(t.offsetX))?Number(t.offsetX):void 0,offsetY:Number.isFinite(Number(t.offsetY))?Number(t.offsetY):void 0}}function oi(t,e){const n=hr(t)??t,r=_e(e.viewportWidth,0),o=_e(e.scrollX,0),s=_e(e.scrollY,0),i=Number.isFinite(Number(n.xPercent))?_e(n.xPercent,0)/100*r:n.isFixed?n.clientX:n.documentX-o,a=Number.isFinite(Number(n.y))?n.isFixed?_e(n.y,0):_e(n.y,0)-s:n.isFixed?n.clientY:n.documentY-s;return{left:i,top:a}}function da(t,e){const n=hr(t);if(!n)return null;const{liveRect:r}=e,o=Number(n.offsetX),s=Number(n.offsetY);if(r&&Number.isFinite(r.left)&&Number.isFinite(r.top)&&Number.isFinite(o)&&Number.isFinite(s))return{left:r.left+tr(o,0,Math.max(0,r.width)),top:r.top+tr(s,0,Math.max(0,r.height)),width:1,height:1};const i=oi(n,e);return!Number.isFinite(i.left)||!Number.isFinite(i.top)?null:{left:i.left,top:i.top,width:1,height:1}}const ii="data-we-text-annotation-target",fa="weTextAnnotationId";function ha(t){return{selectors:[],fingerprint:String(t??"").slice(0,80),path:[]}}function si(t){return t instanceof HTMLElement&&t.getAttribute(ii)==="true"}function ai(t){const e=String(t??"").trim();return`「${e.slice(0,30)}${e.length>30?"…":""}」`}function Xt(t,e){var s,i,a,l;if(!si(e))return null;const n=String(e.dataset[fa]??"").trim()||String(((s=t.activeTextAnnotation)==null?void 0:s.id)??"").trim();if(!n)return null;const r=((i=t.activeTextAnnotation)==null?void 0:i.id)===n?t.activeTextAnnotation:((a=t.textAnnotationManager)==null?void 0:a.getAnnotations().get(n))??null;if(r){const m=(l=r.sourceElement)!=null&&l.isConnected?r.sourceElement:null;return{elementKey:r.id,locator:m?Se(m):ha(r.selectedText),label:ai(r.selectedText),sourceElement:m}}const o=t.editMetaByKey.get(n)??null;return o?{elementKey:o.elementKey,locator:o.locator,label:o.label,sourceElement:null}:null}const wt={genieAgent:null,genieAwake:!1,designAdjustmentTool:null,styleDesignEnabled:!1,darkMode:!1},ma=new Set(["claude","codex","gemini","opencode"]),ga=new Set(["figma","axure","pencil"]);function Or(t){return typeof t=="string"?t.trim().toLowerCase():""}function Lt(t){if(!t||typeof t!="object")return{...wt};const e=t,n=Or(e.genieAgent),r=Or(e.designAdjustmentTool);return{genieAgent:ma.has(n)?n:null,genieAwake:!!e.genieAwake,designAdjustmentTool:ga.has(r)?r:null,styleDesignEnabled:e.styleDesignEnabled===void 0?wt.styleDesignEnabled:!!e.styleDesignEnabled,darkMode:!!e.darkMode}}function nn(t,e){return e!=="text-annotation"?t:{...t,designAdjustmentTool:null,styleDesignEnabled:!1}}function qr(t){return mt()?{...t,designAdjustmentTool:null,styleDesignEnabled:!1}:t}const Cn={alt:!1,shift:!1,ctrl:!1,meta:!1},pa=5e3;function ya(){const t="web-editor-v2";if(typeof crypto<"u"&&typeof crypto.randomUUID=="function")return`${t}-${crypto.randomUUID()}`;const e=Math.random().toString(36).slice(2,10);return`${t}-${Date.now().toString(36)}-${e}`}function ba(t={}){var e,n,r,o,s;return{ui:{breadcrumbs:!0,propertyPanel:!0,showCopyPromptAction:!0,...t.ui??{}},host:{getResourceContext:((e=t.host)==null?void 0:e.getResourceContext)??(()=>null),buildCopyPrompt:((n=t.host)==null?void 0:n.buildCopyPrompt)??void 0},genieBridge:{enabled:!1,enableContextAppend:!0,targetOrigin:"*",preferCurrentSession:!1,apiBaseUrl:"",integrationChannel:"",targetClientId:"",externalClientId:ya(),apiKey:"",probeOnStart:!0,probeTimeoutMs:pa,projectPath:"",provider:"codex",onRequestWake:async()=>{},...t.genieBridge??{}},promptContext:{workspacePaths:((r=t.promptContext)==null?void 0:r.workspacePaths)??[],relatedFiles:((o=t.promptContext)==null?void 0:o.relatedFiles)??[],extraContext:((s=t.promptContext)==null?void 0:s.extraContext)??[]},integrationWs:{enabled:!1,apiBaseUrl:"",channel:"",clientId:"",sessionId:"",pageUrl:"",apiKey:"",...t.integrationWs??{}},interactionProfile:t.interactionProfile??"design"}}function wa(){return{active:!1,shadowHost:null,canvasOverlay:null,handlesController:null,parentSelectController:null,eventController:null,positionTracker:null,selectionEngine:null,dragReorderController:null,transactionManager:null,breadcrumbs:null,propertyPanel:null,tokensService:null,perfMonitor:null,perfHotkeyCleanup:null,annotationShortcutCleanup:null,hoveredElement:null,pendingHoverTransition:!1,selectedElement:null,selectionAnchor:null,annotationEntryMode:"bubble-card",annotationShortcutSettings:{...zt},annotationShortcutDialogOpen:!1,propertyPanelPosition:null,uiResizeCleanup:null,editMetaByKey:new Map,processedEditTimestampsByKey:new Map,pendingMarkerAnchors:new Map,markerLayer:null,changeMarkersVisible:!0,selectionChromeVisible:!0,promptCardVisible:!1,uiSettings:{...wt},genieConversationByScopeKey:new Map,genieTaskByElementKey:new Map,genieTaskByRequestId:new Map,externalEditingTaskByElementKey:new Map,textAnnotationManager:null,textAnnotationTargetElement:null,activeTextAnnotation:null}}function Sa(t){t.editMetaByKey.clear(),t.processedEditTimestampsByKey.clear(),t.pendingMarkerAnchors.clear(),t.markerLayer=null,t.hoveredElement=null,t.selectedElement=null,t.selectionAnchor=null,t.pendingHoverTransition=!1,t.annotationShortcutDialogOpen=!1,t.promptCardVisible=!1,t.genieConversationByScopeKey.clear(),t.genieTaskByElementKey.clear(),t.genieTaskByRequestId.clear(),t.externalEditingTaskByElementKey.clear(),t.textAnnotationTargetElement=null,t.activeTextAnnotation=null}function Ea(t){t.shadowHost=null,t.canvasOverlay=null,t.handlesController=null,t.parentSelectController=null,t.eventController=null,t.positionTracker=null,t.selectionEngine=null,t.dragReorderController=null,t.transactionManager=null,t.breadcrumbs=null,t.propertyPanel=null,t.tokensService=null,t.perfMonitor=null,t.perfHotkeyCleanup=null,t.annotationShortcutCleanup=null,t.uiResizeCleanup=null,t.markerLayer=null,t.hoveredElement=null,t.selectedElement=null,t.selectionAnchor=null,t.pendingHoverTransition=!1,t.annotationShortcutDialogOpen=!1,t.promptCardVisible=!1,t.genieConversationByScopeKey.clear(),t.genieTaskByElementKey.clear(),t.genieTaskByRequestId.clear(),t.externalEditingTaskByElementKey.clear(),t.textAnnotationManager=null,t.textAnnotationTargetElement=null,t.activeTextAnnotation=null,t.pendingMarkerAnchors.clear(),t.editMetaByKey.clear(),t.processedEditTimestampsByKey.clear()}function va(t,e){const n=t.processedEditTimestampsByKey.get(e);return Number.isFinite(Number(n))?Number(n):null}function Ta(t,e,n){const r=va(t,e);if(r===null)return!1;const o=Number(n??0);return Number.isFinite(o)?o<=r:!1}function kn(t,e){return e.filter(n=>{const r=String(n.elementKey??Oe(n.targetLocator)).trim();return r?!Ta(t,r,Number(n.timestamp??0)):!0})}function Ca(t,e){return e?t.filter(n=>n.elementKey!==e):t.slice()}function xa(t){const{state:e}=t;function n(N){return String(N??"").replace(/\r\n/g,`
|
||
`)}function r(N){var E;if(!N)return"";const b=(N.selectors??[]).map(O=>String(O??"").trim()).filter(Boolean);return b.length>0?b.join(" | "):(E=N.path)!=null&&E.length?N.path.join(">"):""}function o(N){let b=N instanceof HTMLElement?N:null;for(;b&&b!==document.body;){try{const E=window.getComputedStyle(b).position;if(E==="fixed"||E==="sticky")return!0}catch{return!1}b=b.parentElement}return!1}function s(N,b,E){const O=o(N),d=N instanceof HTMLElement?N.getBoundingClientRect():null,M=d&&Number.isFinite(d.left)&&Number.isFinite(b)?b-d.left:void 0,j=d&&Number.isFinite(d.top)&&Number.isFinite(E)?E-d.top:void 0;return ri({clientX:b,clientY:E,scrollX:window.scrollX,scrollY:window.scrollY,viewportWidth:window.innerWidth,isFixed:O,offsetX:M,offsetY:j})}function i(N){if(!(N instanceof HTMLElement))return null;const b=N.getBoundingClientRect();return!Number.isFinite(b.left)||!Number.isFinite(b.top)?null:s(N,b.left+b.width/2,b.top+Math.min(18,Math.max(10,b.height/2)))}function a(N,b,E){const O=e.editMetaByKey.get(N);if(O)return O.locator=b,O.label=E,O;const d={elementKey:N,locator:b,label:E,note:"",images:[],anchor:null,dirtySince:null,changeKinds:[],styleSummaryLines:[],textSummary:null,classSummaryLines:[]};return e.editMetaByKey.set(N,d),d}function l(N){if(!N)return null;const b=Xt(e,N);if(b)return e.editMetaByKey.get(b.elementKey)??a(b.elementKey,b.locator,b.label);if(si(N))return null;const E=Se(N),O=Ne(N,E.shadowHostChain);return e.editMetaByKey.get(O)??a(O,E,bt(N,E.shadowHostChain))}function m(N){return oi(N,{scrollX:window.scrollX,scrollY:window.scrollY,viewportWidth:window.innerWidth})}function P(N,b){var O;let E=we(N);if(!E||!E.isConnected){const d=(O=e.activeTextAnnotation)==null?void 0:O.sourceElement;d&&d.isConnected&&(E=d)}if(E&&E.isConnected){const d=E instanceof HTMLElement?E.getBoundingClientRect():null,M=Number(b==null?void 0:b.offsetX),j=Number(b==null?void 0:b.offsetY);if(d&&Number.isFinite(d.left)&&Number.isFinite(d.top)&&Number.isFinite(M)&&Number.isFinite(j)){const ee=Math.min(Math.max(0,M),Math.max(0,d.width)),oe=Math.min(Math.max(0,j),Math.max(0,d.height));return s(E,d.left+ee,d.top+oe)}return b?i(E)??b:i(E)}return b}function L(N,b){if(b)return s(N,b.clientX,b.clientY);const E=Se(N),O=Ne(N,E.shadowHostChain),d=e.editMetaByKey.get(O);return e.pendingMarkerAnchors.get(O)??null??(d==null?void 0:d.anchor)??i(N)}function S(N){return String(N??"").trim()||"已清除"}function R(N,b){const O=Array.from(new Set([...Object.keys(N??{}),...Object.keys(b??{})])).map(d=>String(d??"").trim()).filter(Boolean).sort((d,M)=>d.localeCompare(M)).map(d=>{const M=String((N==null?void 0:N[d])??"").trim(),j=String((b==null?void 0:b[d])??"").trim();return M&&j?`样式 ${d}: ${M} -> ${j}`:j?`样式 ${d}: ${j}`:`样式 ${d}: 已清除(原值 ${S(M)})`});return O.length<=5?O:[...O.slice(0,5),`还有 ${O.length-5} 项样式修改...`]}function I(N){const b=[],E=n(N.note).trim();return E?b.push(E):N.images.length>0?b.push(`已附加 ${N.images.length} 张参考图片`):N.changeKinds.length>0?b.push(`已修改:${N.changeKinds.join(" / ")}`):b.push("已记录修改"),N.textSummary&&b.push(N.textSummary),N.styleSummaryLines.length>0&&b.push(...N.styleSummaryLines),N.classSummaryLines.length>0&&b.push(...N.classSummaryLines),b}function h(N){const b=e.editMetaByKey.get(N);!b||n(b.note).trim()||b.images.length>0||b.dirtySince===null&&(b.changeKinds.length>0||e.editMetaByKey.delete(N))}function T(){const N=e.markerLayer;if(!N)return;if(!e.changeMarkersVisible||e.promptCardVisible){N.hidden=!0,N.replaceChildren();return}const b=Array.from(e.editMetaByKey.values()).filter(M=>M.dirtySince!==null&&M.anchor).sort((M,j)=>{const ee=Number(M.dirtySince??0),oe=Number(j.dirtySince??0);return ee!==oe?ee-oe:M.label.localeCompare(j.label)}),E=(()=>{if(e.annotationEntryMode!=="bubble-card")return null;const M=e.selectedElement;if(!M||!M.isConnected)return null;const j=Se(M);return Ne(M,j.shadowHostChain)})(),O=Ca(b,E);if(N.hidden=O.length===0,O.length===0){N.replaceChildren();return}const d=O.map((M,j)=>{const ee=P(M.locator,M.anchor);if(!ee)return null;const oe=m(ee),ie=document.createElement("div");ie.className="we-change-marker",ie.style.left=`${oe.left}px`,ie.style.top=`${oe.top}px`,ie.textContent=String(j+1),ie.setAttribute("role","button"),ie.tabIndex=0,ie.setAttribute("aria-label",`定位到 ${M.label}`);const me=document.createElement("div");me.className="we-change-marker__tooltip";const ce=document.createElement("span");ce.className="we-change-marker__label",ce.textContent=M.label;const pe=document.createElement("div");pe.className="we-change-marker__details";for(const ae of I(M)){const V=document.createElement("span");V.className="we-change-marker__note",V.textContent=ae,pe.append(V)}const ge=()=>{var V;const ae=we(M.locator);!ae||!ae.isConnected||(V=t.onSelectMarkedElement)==null||V.call(t,ae,ee)};return ie.addEventListener("click",ae=>{ae.preventDefault(),ae.stopPropagation(),ge()}),ie.addEventListener("keydown",ae=>{ae.key!=="Enter"&&ae.key!==" "||(ae.preventDefault(),ae.stopPropagation(),ge())}),me.append(ce,pe),ie.append(me),ie}).filter(M=>M!==null);N.replaceChildren(...d)}function x(){var O,d;const N=e.transactionManager;if(!N){T();return}const b=tt(kn(e,N.getUndoStack())),E=new Set;for(const M of b){const j=M.elementKey;e.processedEditTimestampsByKey.delete(j),E.add(j);const ee=a(j,M.netEffect.locator,M.fullLabel||M.label);ee.locator=M.netEffect.locator,ee.label=M.fullLabel||M.label,ee.dirtySince===null&&(ee.dirtySince=Number(M.updatedAt??Date.now()));const oe=[];M.netEffect.textChange&&oe.push("text"),M.netEffect.styleChanges&&oe.push("style"),M.netEffect.classChanges&&oe.push("class"),ee.changeKinds=oe,ee.styleSummaryLines=R((O=M.netEffect.styleChanges)==null?void 0:O.before,(d=M.netEffect.styleChanges)==null?void 0:d.after),ee.textSummary=M.changes.text?`文本:${M.changes.text.beforePreview} -> ${M.changes.text.afterPreview}`:null,ee.classSummaryLines=M.changes.class?[...M.changes.class.added.length>0?[`类名新增:${M.changes.class.added.join(", ")}`]:[],...M.changes.class.removed.length>0?[`类名移除:${M.changes.class.removed.join(", ")}`]:[]]:[];const ie=e.pendingMarkerAnchors.get(j)??null;if(ie)ee.anchor=ie;else if(!ee.anchor){const me=we(M.netEffect.locator);ee.anchor=me?i(me):null}e.pendingMarkerAnchors.delete(j)}for(const M of e.editMetaByKey.values())if(!E.has(M.elementKey)){if(n(M.note).trim()){if(M.dirtySince===null&&(M.dirtySince=Date.now()),!M.anchor){const j=we(M.locator);M.anchor=j?i(j):null}M.changeKinds=[],M.styleSummaryLines=[],M.textSummary=null,M.classSummaryLines=[];continue}M.dirtySince=null,M.changeKinds=[],M.anchor=null,M.styleSummaryLines=[],M.textSummary=null,M.classSummaryLines=[]}for(const M of Array.from(e.editMetaByKey.keys()))h(M);T()}function B(N){var M;if(!N||!N.isConnected)return;const b=Se(N),E=Ne(N,b.shadowHostChain),O=Date.now(),d=a(E,b,bt(N,b.shadowHostChain));d.locator=b,d.label=bt(N,b.shadowHostChain),d.note="",d.images=[],d.dirtySince=null,d.changeKinds=[],d.anchor=null,d.styleSummaryLines=[],d.textSummary=null,d.classSummaryLines=[],e.processedEditTimestampsByKey.set(E,O),e.pendingMarkerAnchors.delete(E),e.selectedElement===N&&(e.selectionAnchor=null),h(E),t.scheduleCacheWrite(),(M=e.propertyPanel)==null||M.refresh(),T()}function K(N,b){const E=l(N);if(!E)return;E.note=n(b);const O=e.pendingMarkerAnchors.get(E.elementKey);if(O)E.anchor=O,e.pendingMarkerAnchors.delete(E.elementKey);else if(!E.anchor&&n(E.note).trim()){const d=N&&N.isConnected?N:we(E.locator);E.anchor=d?i(d):null}n(E.note).trim()?E.dirtySince===null&&(E.dirtySince=Date.now()):E.changeKinds.length===0&&E.images.length===0&&(E.dirtySince=null,E.anchor=null,E.styleSummaryLines=[],E.textSummary=null,E.classSummaryLines=[]),h(E.elementKey),t.scheduleCacheWrite(),T()}function _(N){var b;return((b=l(N))==null?void 0:b.images.slice())??[]}function v(N,b){const E=l(N);if(!E)return;E.images=b.map(d=>({...d}));const O=e.pendingMarkerAnchors.get(E.elementKey);if(O)E.anchor=O,e.pendingMarkerAnchors.delete(E.elementKey);else if(!E.anchor&&E.images.length>0){const d=N&&N.isConnected?N:we(E.locator);E.anchor=d?i(d):null}E.images.length>0?E.dirtySince===null&&(E.dirtySince=Date.now()):!n(E.note).trim()&&E.changeKinds.length===0&&(E.dirtySince=null,E.anchor=null,E.styleSummaryLines=[],E.textSummary=null,E.classSummaryLines=[]),h(E.elementKey),t.scheduleCacheWrite(),T()}function H(){var N;e.editMetaByKey.clear(),e.processedEditTimestampsByKey.clear(),e.pendingMarkerAnchors.clear(),e.selectionAnchor=null,t.scheduleCacheWrite(),T(),(N=t.onStatusChange)==null||N.call(t)}function q(){var N;return((N=l(e.selectedElement??e.textAnnotationTargetElement))==null?void 0:N.note)??""}function Y(N,b={}){var E,O;e.changeMarkersVisible=N,b.persist!==!1&&(t.persistMarkerVisibility(N),t.scheduleCacheWrite()),(E=e.propertyPanel)==null||E.refresh(),T(),(O=t.onStatusChange)==null||O.call(t)}function F(){return Array.from(e.editMetaByKey.values()).filter(b=>b.dirtySince!==null).sort((b,E)=>Number(b.dirtySince??0)-Number(E.dirtySince??0)).map((b,E)=>({selector:r(b.locator),label:b.label,note:b.note,changeKinds:b.changeKinds.slice(),marker:b.anchor?{index:E+1,clientX:b.anchor.clientX,clientY:b.anchor.clientY,documentX:b.anchor.documentX,documentY:b.anchor.documentY,isFixed:b.anchor.isFixed}:null}))}function A(N,b){const E=Se(N),O=Ne(N,E.shadowHostChain),d=L(N,b);e.selectionAnchor=d,e.pendingMarkerAnchors.clear(),d&&e.pendingMarkerAnchors.set(O,d);const M=e.editMetaByKey.get(O);M&&d&&(M.anchor=d,T())}function X(){e.selectionAnchor=null,e.pendingMarkerAnchors.size!==0&&(e.pendingMarkerAnchors.clear(),T())}return{normalizeNote:n,getOrCreateEditMeta:a,getMetaForElement:l,rememberSelectionAnchor:A,clearPendingSelectionAnchor:X,renderChangeMarkers:T,syncEditMetaWithTransactions:x,setNoteForElement:K,getImagesForElement:_,setImagesForElement:v,markElementEditsHandled:B,clearAllEditMeta:H,getSelectedElementNote:q,setChangeMarkersVisible:Y,buildModifiedElementsContext:F}}const Aa=3e3,Kn=5e3,Ia=3e5,Gr=5,ka=1500,Vr=3,Na=8e3,Ra=6e3,zr=6e3,Wr="/api/assistant/runtime",Pa="/health",Xr="@axhub/genie",Ma="make",ci="make",li="Genie 页面未在线,请先打开对应 Genie 页面。",ui="Genie 连接配置不完整。",Yr="Genie 连接未建立,请稍后重试。",_a="Genie 执行配置不完整。",jr="[WebEditorV2][GenieBridge]",La=10,Da=24*60*60*1e3,Ba=1800,Fa=3e3,Ka=new Set(["SESSION_NOT_FOUND","INVALID_SESSION","AGENT_SESSION_NOT_FOUND","ACTIVE_SESSION_NOT_FOUND"]);function it(t){const e=Math.random().toString(36).slice(2,10);return`${t}_${Date.now().toString(36)}_${e}`}function qt(t,e){return typeof t!="number"||!Number.isFinite(t)||t<=0?e:Math.max(100,Math.round(t))}function Ae(t){return typeof t=="string"?t.trim():""}function Rt(t){const e=Ae(t);if(!e)return"";try{return new URL(e).toString().replace(/\/+$/u,"")}catch{return""}}function di(...t){const e=[],n=new Set;for(const r of t){const o=Ae(r);!o||n.has(o)||(n.add(o),e.push(o))}return e}function fi(...t){if(typeof window>"u")return"";try{const e=new URL(window.location.href);for(const n of t){const r=Ae(e.searchParams.get(n));if(r)return r}}catch{}return""}function Ha(t,e){var o;const n=Ae((o=t==null?void 0:t.service)==null?void 0:o.id),r=Ae((e==null?void 0:e.get("X-App-Identifier"))??(e==null?void 0:e.get("x-app-identifier")));return n===Xr||r===Xr}function $a(t){return(Array.isArray(t==null?void 0:t.items)?t.items:[]).map(n=>{if(!xn(n))return null;const r=Ae(n.channel),o=Ae(n.clientId);return!r||!o?null:{channel:r,clientId:o,sessionId:Ae(n.sessionId)||null,pageUrl:Ae(n.pageUrl)||null,lastSeenAt:rr(n.lastSeenAt,0),connectedAt:rr(n.connectedAt,0),capabilities:Array.isArray(n.capabilities)?n.capabilities.map(s=>Ae(s)).filter(Boolean):[]}}).filter(n=>n!==null)}function Ua(t,e){for(const o of e){const s=t.find(i=>i.clientId===o);if(s)return s}const n=t.slice().sort((o,s)=>{const i=Math.max(o.lastSeenAt,o.connectedAt);return Math.max(s.lastSeenAt,s.connectedAt)-i}),r=n.find(o=>o.clientId===ci);return r||(n.length===1,n[0]??null)}function Jr(t){return di(t,fi("genieIntegrationChannel","integrationChannel"),Ma)}function Qr(t){return di(t,fi("genieTargetClientId","integrationClientId"),ci)}function nr(t,e){const n=String(t??"").trim();if(!n)throw new Error(ui);const r=new URL(n);r.protocol=r.protocol==="https:"?"wss:":"ws:",r.pathname=`${r.pathname.replace(/\/+$/,"")}/agent/ws`;const o=String(e??"").trim();return o?r.searchParams.set("apiKey",o):r.searchParams.delete("apiKey"),r.toString()}function xn(t){return!!t&&typeof t=="object"}function Oa(t,e){const n=t.payload;if(!n||typeof n!="object")return!1;const r=n.frontend;if(!xn(r))return!1;const o=r.connected;if(typeof o=="boolean")return o;const s=r.clients;return Array.isArray(s)?s.some(i=>xn(i)?i.clientId===e:!1):!1}function qa(t,e){if(t==="FRONTEND_NOT_ONLINE")return li;const n=typeof e=="string"?e.trim():"";return n||(typeof t=="string"&&t.trim()?`Genie 集成失败:${t.trim()}`:"Genie 集成失败,请稍后重试。")}function Hn(t){const e=typeof t=="string"?t.trim():"";return e||"Genie 执行失败,请稍后重试。"}function $n(t){var e,n;return typeof t.errorCode=="string"&&t.errorCode.trim()?t.errorCode.trim():typeof((e=t.payload)==null?void 0:e.code)=="string"&&t.payload.code.trim()?t.payload.code.trim():typeof((n=t.result)==null?void 0:n.errorCode)=="string"&&t.result.errorCode.trim()?t.result.errorCode.trim():null}function Xe(t,e={}){const n=new Error(t);return n.code=e.code,n.silentToast=e.silentToast,n}function Zr(t){return!!(t&&typeof t=="object"&&"silentToast"in t&&t.silentToast)}function Ga(t,e){var s;if(typeof window<"u")try{const a=((s=new URL(window.location.href).searchParams.get("axhubDisplayName"))==null?void 0:s.trim())??"";if(a)return a}catch{}const n=String(t??"").trim();if(n){const i=n.split("/").filter(Boolean).pop()??"";if(i)return i}const r=String(e??"").trim();return r?(r.split("/").filter(Boolean).pop()??"").replace(/\.[^/.]+$/u,""):""}function rr(t,e=0){if(typeof t=="number"&&Number.isFinite(t))return t;if(typeof t=="string"&&t.trim()){const n=Date.parse(t);if(Number.isFinite(n))return n}return e}function eo(t){if(!xn(t))return null;const e=typeof t.sessionId=="string"?t.sessionId.trim():"",n=typeof t.provider=="string"?t.provider.trim():"",r=typeof t.phase=="string"?t.phase.trim():"";return!e||!n||!r?null:{sessionId:e,provider:n,phase:r,isLoading:!!t.isLoading,canAbortSession:!!t.canAbortSession,hasPendingApproval:!!t.hasPendingApproval,updatedAt:rr(t.updatedAt,Date.now()),subscriptionKey:typeof t.subscriptionKey=="string"&&t.subscriptionKey.trim()?t.subscriptionKey.trim():null}}function Va(t){let e=!1,n=!1,r=!1,o=!1,s=null,i=null,a=null,l=null,m=null,P=null,L=0,S=0,R=null;const I=new Map,h=new Map,T=new Map,x=new Map,B=new Map,K=new Map,{state:_}=t;let v=Rt(t.bridgeOptions.apiBaseUrl);const H=Ae(t.bridgeOptions.apiKey);let q=!!t.bridgeOptions.enabled;const Y=Ae(t.bridgeOptions.externalClientId);let F=Ae(t.bridgeOptions.integrationChannel),A=Ae(t.bridgeOptions.projectPath);const X=t.bridgeOptions.provider,N=t.bridgeOptions.probeOnStart,b=t.bridgeOptions.probeTimeoutMs;let E=Ae(t.bridgeOptions.targetClientId);q=q||!!(v&&F&&E);function O(){const f=r;o!==f&&(o=f,W())}function d(f){const c=Rt(f.apiBaseUrl??v),w=Ae(f.integrationChannel??F),z=Ae(f.targetClientId??E);v=c,F=w,E=z,q=q||!!(v&&F&&E)}async function M(f){var z;if(typeof window>"u"||typeof fetch!="function")return{apiBaseUrl:"",projectPath:""};const c=f?Wr:`${Wr}?autoStart=false`;let w="";try{const ne=await fetch(c,{method:"GET"});if(ne.ok){const Q=await ne.json().catch(()=>null),he=Ae((z=Q==null?void 0:Q.health)==null?void 0:z.status),Ce=Rt(Q==null?void 0:Q.apiBaseUrl);if(w=Ae(Q==null?void 0:Q.projectPath),Ce&&(he==="ready"||f))return{apiBaseUrl:Ce,projectPath:w}}}catch{}try{const ne=await fetch(Pa,{method:"GET"});if(!ne.ok)return{apiBaseUrl:"",projectPath:w};const Q=await ne.json().catch(()=>null);return!Q||!Ha(Q,ne.headers)||Q.status!=="ok"?{apiBaseUrl:"",projectPath:w}:{apiBaseUrl:new URL("/api",window.location.origin).toString().replace(/\/+$/u,""),projectPath:w}}catch{return{apiBaseUrl:"",projectPath:w}}}async function j(f,c){const w=Rt(f),z=Ae(c);if(!w||!z||typeof window>"u"||typeof WebSocket>"u")return[];const ne=qt(b,Ra);return new Promise(Q=>{let he=null,Ce=!1,Fe=null,Ie=null;const Pe=(be=[])=>{if(!Ce){if(Ce=!0,he){he.onopen=null,he.onmessage=null,he.onerror=null,he.onclose=null;try{he.close()}catch{}}Q(be)}},$=window.setTimeout(()=>{Pe([])},ne);try{he=new WebSocket(nr(w,H))}catch{window.clearTimeout($),Pe([]);return}he.onopen=()=>{Fe=it("genie_discover_connect");try{he==null||he.send(JSON.stringify({type:"integration.connect",requestId:Fe,payload:{role:"external-client",channel:z,clientId:Y,capabilities:["presence.query","editor.query"]}}))}catch{window.clearTimeout($),Pe([])}},he.onmessage=be=>{let xe=null;try{xe=JSON.parse(be.data)}catch{return}if(xe!=null&&xe.type){if(xe.type==="integration.connected"&&xe.requestId===Fe){Ie=it("genie_discover_clients");try{he==null||he.send(JSON.stringify({type:"integration.editor.clients.list",requestId:Ie,payload:{channel:z}}))}catch{window.clearTimeout($),Pe([])}return}if(xe.type==="integration.editor.clients.result"&&xe.requestId===Ie){window.clearTimeout($),Pe($a(xe.payload));return}xe.type==="integration.error"&&xe.requestId===Ie&&(window.clearTimeout($),Pe([]))}},he.onerror=()=>{window.clearTimeout($),Pe([])},he.onclose=()=>{window.clearTimeout($),Pe([])}})}async function ee(f){const c=Jr(F),w=Qr(E);for(const z of c){const ne=await j(f,z);if(ne.length===0)continue;const Q=Ua(ne,w);if(Q)return Q}return null}async function oe(f){const c=Rt(v);if(!c)return!1;const w=await ee(c);if(!w)return!1;const z=Ae(w.channel),ne=Ae(w.clientId);return!z||!ne||!(z!==F||ne!==E)?!1:(d({apiBaseUrl:c,integrationChannel:z,targetClientId:ne}),!0)}async function ie(f){if(R)return R;R=(async()=>{const c=await M(f.autoStartRuntime),w=Rt(v)||c.apiBaseUrl;if(!A&&c.projectPath&&(A=c.projectPath),!w)return!1;const z=await ee(w);if(q&&v&&F&&E)return z&&d({apiBaseUrl:w,integrationChannel:Ae(z.channel),targetClientId:Ae(z.clientId)}),!0;const ne=Ae(z==null?void 0:z.channel)||Jr(F)[0]||"",Q=Ae(z==null?void 0:z.clientId)||Qr(E)[0]||"";return d({apiBaseUrl:w,integrationChannel:ne,targetClientId:Q}),q&&!!(v&&F&&E)})();try{return await R}finally{R=null}}async function me(){if(Nn()){const w=ce();w&&!K.has(w)&&await pe(w);return}const f=await M(!1);!A&&f.projectPath&&(A=f.projectPath);const c=ce();c&&await pe(c)}function ce(){return String(_.uiSettings.genieAgent??X??"codex").trim()}async function pe(f){if(!f||!v)return;const w=`${String(v).replace(/\/+$/u,"")}/session-core/providers/${encodeURIComponent(f)}`;try{const z=typeof AbortController<"u"?new AbortController:null,ne=z&&typeof window<"u"?window.setTimeout(()=>z.abort(),Fa):void 0,Q=await fetch(w,{method:"GET",...z?{signal:z.signal}:{}});if(ne!==void 0&&(typeof window<"u"?window:globalThis).clearTimeout(ne),!Q.ok){J("Provider availability check returned non-OK",{provider:f,status:Q.status});return}let he=null;try{he=await Q.json()}catch{return}he&&K.set(f,{installed:he.installed!==!1,installHint:typeof he.installHint=="string"?he.installHint.trim():void 0,checkedAt:Date.now()})}catch(z){J("Provider availability check failed (graceful degradation)",{provider:f,error:z instanceof Error?z.message:String(z)})}}function ge(f){const c=K.get(f);if(!c||c.installed)return;const w=c.installHint?`
|
||
安装命令:${c.installHint}`:"";throw Xe(`当前选择的 AI 工具(${f})不可用,请确认已安装或切换其他工具。${w}`,{code:"PROVIDER_NOT_AVAILABLE"})}function ae(){return String(t.summaries.resolveTargetPath()??"").trim()||(typeof window<"u"?String(window.location.pathname??"").trim():"")||"unknown"}function V(){const f=ae();return["web-editor-v2",String(A??"").trim()||"unknown-project",f].join("::")}function p(f){const c=String(ce()??"").trim()||"unknown";return[V(),c,String(F??"").trim()||"unknown-channel",String(E??"").trim()||"unknown-client"].join("::")}function u(f){return _.genieConversationByScopeKey.get(f)??null}function k(f){const c=V(),w=p(),z=u(c)??(w!==c?u(w):null);return z?z.scopeKey===c?z:{...z,scopeKey:c}:null}function y(){return k()}function D(){return g(y())}function U(f){const c=u(f);if(!c){t.persistence.clearGenieConversationState(f);return}t.persistence.writeGenieConversationState(f,c)}function C(f,c){return c?(_.genieConversationByScopeKey.set(f,c),U(f),fe(),c):(_.genieConversationByScopeKey.delete(f),t.persistence.clearGenieConversationState(f),fe(),null)}function g(f){return!(f!=null&&f.sessionId)||f.invalidated||f.sentCount>=La?!1:Number.isFinite(f.expiresAt)&&f.expiresAt>Date.now()}function G(f,c){const w=u(f),z=Date.now(),ne=Number.isFinite(Number(c.createdAt))?Number(c.createdAt):(w==null?void 0:w.createdAt)??z,Q=Number.isFinite(Number(c.lastUsedAt))?Number(c.lastUsedAt):(w==null?void 0:w.lastUsedAt)??ne,he={scopeKey:f,sessionId:String(c.sessionId??(w==null?void 0:w.sessionId)??"").trim(),provider:typeof c.provider=="string"&&c.provider.trim()?c.provider.trim():(w==null?void 0:w.provider)??null,projectPath:typeof c.projectPath=="string"&&c.projectPath.trim()?c.projectPath.trim():(w==null?void 0:w.projectPath)??(String(A??"").trim()||null),createdAt:ne,lastUsedAt:Q,sentCount:Math.max(0,Math.floor(Number(c.sentCount??(w==null?void 0:w.sentCount)??0))),expiresAt:Number.isFinite(Number(c.expiresAt))?Number(c.expiresAt):ne+Da,invalidated:typeof c.invalidated=="boolean"?c.invalidated:(w==null?void 0:w.invalidated)??!1,sessionPath:typeof c.sessionPath=="string"&&c.sessionPath.trim()?c.sessionPath.trim():c.sessionPath===null?null:(w==null?void 0:w.sessionPath)??null,sessionUrl:typeof c.sessionUrl=="string"&&c.sessionUrl.trim()?c.sessionUrl.trim():c.sessionUrl===null?null:(w==null?void 0:w.sessionUrl)??null};return C(f,he)}function se(f,c){}function J(f,c){if(c===void 0){console.warn(`${jr} ${f}`);return}console.warn(`${jr} ${f}`,c)}function W(){var f;(f=t.onAvailabilityChange)==null||f.call(t,o)}function Z(f){n!==f&&(n=f,W())}function re(f){r!==f&&(r=f,O())}function fe(){var f,c,w;(f=_.breadcrumbs)==null||f.refresh(),(c=_.propertyPanel)==null||c.refresh(),(w=_.positionTracker)==null||w.forceUpdate(!0)}function ue(f){const c=String(f??"").trim();if(!c)return;const w=B.get(c);w!==void 0&&(window.clearTimeout(w),B.delete(c))}function Ee(f){ue(f);const c=Ge(f).filter(z=>z.status==="completed"&&!z.dismissed);if(c.length===0)return;const w=Date.now();for(const z of c)Kt({...z,dismissed:!0,updatedAt:w,lastEventAt:z.lastEventAt})}function Te(f){const c=String(f??"").trim();if(!c)return;const w=Ge(c);if(w.length===0||w.some(ne=>ne.dismissed||ne.status!=="completed")){ue(c);return}if(B.has(c))return;const z=window.setTimeout(()=>{Ee(c)},Ba);B.set(c,z)}function De(f){const c=Array.from(_.genieTaskByElementKey.values()).filter(w=>w.scopeKey===f&&!w.dismissed&&He(w)&&typeof w.sessionId=="string"&&w.sessionId.trim().length>0&&typeof w.provider=="string"&&w.provider.trim().length>0).map(w=>({scopeKey:w.scopeKey,elementKey:w.elementKey,locator:w.locator,label:w.label,requestId:w.requestId,sessionId:w.sessionId,sessionPath:w.sessionPath,sessionUrl:w.sessionUrl,provider:w.provider,status:w.status,message:w.message,startedAt:w.startedAt,updatedAt:w.updatedAt,dismissed:w.dismissed,recoveryPending:w.recoveryPending,lastEventAt:w.lastEventAt,errorCode:w.errorCode}));t.persistence.writeGenieTaskStates(f,c)}function We(f){if(!f){x.clear(),W();return}x.set(f.requestId,f),W()}function Ue(f,c){const w=x.get(f);if(!w)return null;const z={...w,...c};return x.set(f,z),W(),z}function te(f){const c=x.get(f)??null;return c?(x.delete(f),W(),c):null}function le(f){return!!(f&&!f.dismissed)}function ye(f){if(!f)return null;const c=_.externalEditingTaskByElementKey.get(f)??null;return le(c)?c:null}function ke(f){return qe(f)??ye(f)}function ve(f){if(!f||!f.isConnected)return null;const c=Xt(_,f);if(c)return ke(c.elementKey);const w=Se(f),z=Ne(f,w.shadowHostChain);return ke(z)}function qe(f){if(!f)return null;const c=_.genieTaskByElementKey.get(f)??null;return c!=null&&c.dismissed?null:c}function Et(f){return f?_.genieTaskByRequestId.get(f)??Array.from(_.genieTaskByElementKey.values()).find(c=>c.requestId===f)??null:null}function Ge(f){return f?Array.from(_.genieTaskByElementKey.values()).filter(c=>c.requestId===f).sort((c,w)=>c.startedAt-w.startedAt):[]}function Nt(f){if(!f)return;const c=Array.from(_.genieTaskByElementKey.values()).find(w=>w.requestId===f);if(c){_.genieTaskByRequestId.set(f,c);return}_.genieTaskByRequestId.delete(f)}function Ze(f){const c=Xt(_,f);if(c)return{elementKey:c.elementKey,locator:c.locator,label:c.label};const w=Se(f),z=Ne(f,w.shadowHostChain),ne=bt(f,w.shadowHostChain);return{elementKey:z,locator:w,label:ne}}function Yt(f){return f.flatMap(c=>t.changes.getImagesForElement(c).slice(0,3).map(w=>({name:w.name,data:w.data,mimeType:w.mimeType,size:w.size})))}function He(f){return(f==null?void 0:f.status)==="pending"||(f==null?void 0:f.status)==="created"}function pr(f){return!f||f.dismissed?!1:He(f)||f.status==="error"}function yr(f,c){var ne;if(!f||!f.isConnected)return!1;const w=typeof ShadowRoot<"u";let z=f;for(;z;){if(z===c)return!0;const Q=(ne=z.getRootNode)==null?void 0:ne.call(z);w&&Q instanceof ShadowRoot&&Q.host instanceof Element&&Q.host!==z?z=Q.host:z=z.parentElement}return!1}function br(f){var ne,Q,he,Ce,Fe,Ie;if(!pr(f))return;let c=null;try{c=we(f.locator)}catch{c=null}if(!(c!=null&&c.isConnected))return;const w=_.selectedElement;w&&w!==c&&yr(w,c)&&(_.selectedElement=c,(ne=_.positionTracker)==null||ne.setSelectionElement(c),(Q=_.breadcrumbs)==null||Q.setTarget(c),(he=_.propertyPanel)==null||he.setTarget(c),(Ce=_.handlesController)==null||Ce.setTarget(c),(Fe=_.parentSelectController)==null||Fe.setTarget(c));const z=_.hoveredElement;z&&z!==c&&yr(z,c)&&(_.hoveredElement=null,(Ie=_.positionTracker)==null||Ie.setHoverElement(null))}function Ti(f){var z;if(!f||!f.isConnected)return null;const c=typeof ShadowRoot<"u";let w=f;for(;w;){const ne=ve(w);if(pr(ne))return w;const Q=(z=w.getRootNode)==null?void 0:z.call(w);c&&Q instanceof ShadowRoot&&Q.host instanceof Element&&Q.host!==w?w=Q.host:w=w.parentElement}return f}function Ci(f){var z;const c=typeof ShadowRoot<"u";let w=f;for(;w;){const ne=ve(w);if(He(ne)&&!(ne!=null&&ne.dismissed))return!0;const Q=(z=w.getRootNode)==null?void 0:z.call(w);c&&Q instanceof ShadowRoot&&Q.host instanceof Element&&Q.host!==w?w=Q.host:w=w.parentElement}return!1}function Kt(f,c={}){const w=_.genieTaskByElementKey.get(f.elementKey);return _.genieTaskByElementKey.set(f.elementKey,f),_.genieTaskByRequestId.set(f.requestId,f),w&&w.requestId!==f.requestId&&Nt(w.requestId),c.clearPreviousRequestId&&c.clearPreviousRequestId!==f.requestId&&Nt(c.clearPreviousRequestId),br(f),De(f.scopeKey),fe(),Te(f.requestId),f}function wr(f){var z;const c=Ge(f);if(c.length===0)return null;for(const ne of c)((z=_.genieTaskByElementKey.get(ne.elementKey))==null?void 0:z.requestId)===f&&_.genieTaskByElementKey.delete(ne.elementKey);const w=Array.from(new Set(c.map(ne=>ne.scopeKey)));Nt(f);for(const ne of w)De(ne);return fe(),ue(f),c[0]??null}function ot(f,c){const w=Ge(f);if(w.length===0)return null;let z=null;for(const ne of w){const Q=c.requestId??ne.requestId,he={...ne,...c,requestId:Q,updatedAt:Number.isFinite(Number(c.updatedAt))?Number(c.updatedAt):Date.now(),lastEventAt:Number.isFinite(Number(c.lastEventAt))?Number(c.lastEventAt):ne.lastEventAt},Ce=Kt(he,{clearPreviousRequestId:Q!==ne.requestId?ne.requestId:null});z||(z=Ce)}return z}function xi(f){const c=ve(f);!c||He(c)||c.dismissed||Kt({...c,dismissed:!0,updatedAt:Date.now(),lastEventAt:c.lastEventAt})}function Ai(){const f=new Map;for(const c of Array.from(_.genieTaskByElementKey.values()).filter(le))f.set(c.elementKey,c);for(const c of Array.from(_.externalEditingTaskByElementKey.values()).filter(le))f.has(c.elementKey)||f.set(c.elementKey,c);return Array.from(f.values()).sort((c,w)=>c.startedAt-w.startedAt)}function Ii(f){return f?{provider:typeof f.provider=="string"&&f.provider.trim()?f.provider.trim():null,sessionId:typeof f.sessionId=="string"&&f.sessionId.trim()?f.sessionId.trim():null,requestId:typeof f.requestId=="string"&&f.requestId.trim()?f.requestId.trim():null}:null}function ki(f,c){if(!(f!=null&&f.isConnected))return null;const w=Ze(f),z=Ii(c),ne=_.externalEditingTaskByElementKey.get(w.elementKey)??null,Q=Date.now(),he=String(ce()||"").trim()||null,Ce={scopeKey:V(),elementKey:w.elementKey,locator:w.locator,label:w.label,requestId:(z==null?void 0:z.requestId)??(ne==null?void 0:ne.requestId)??`external_editing_${w.elementKey}`,sessionId:(z==null?void 0:z.sessionId)??(ne==null?void 0:ne.sessionId)??null,sessionPath:null,sessionUrl:null,provider:(z==null?void 0:z.provider)??(ne==null?void 0:ne.provider)??he,status:"created",message:"AI 编辑中",startedAt:(ne==null?void 0:ne.startedAt)??Q,updatedAt:Q,dismissed:!1,recovery:"live",recoveryPending:!1,lastEventAt:Q,errorCode:null,origin:"external-editing",taskRef:z};return _.externalEditingTaskByElementKey.set(w.elementKey,Ce),br(Ce),fe(),Ce}function Ni(f,c){if(!(f!=null&&f.isConnected))return!1;const w=Ze(f),z=_.externalEditingTaskByElementKey.delete(w.elementKey);return z&&(t.changes.markElementEditsHandled(f),fe()),z}function vt(){return q&&String(v).trim().length>0&&String(F).trim().length>0&&String(E).trim().length>0}function Nn(){return String(A).trim().length>0&&ce().length>0}function Rn(){if(!vt())throw new Error(ui);if(!n||!s||s.readyState!==WebSocket.OPEN)throw new Error(Yr)}function Ri(){if(Rn(),!o)throw new Error(li)}function Pi(){if(Rn(),!Nn())throw new Error(_a)}function Mi(f){return f.isLoading?{taskStatus:"created",recovery:"snapshot",message:"Genie 正在修改"}:f.phase==="completed"?{taskStatus:"completed",recovery:"snapshot",message:"Genie 修改完成"}:{taskStatus:"error",recovery:"snapshot",message:f.phase==="aborted"?"已中断":"Genie 修改失败"}}function Sr(f){!He(f)||!f.requestId||x.set(f.requestId,{requestId:f.requestId,scopeKey:f.scopeKey,provider:f.provider,sessionId:f.sessionId,sessionPath:f.sessionPath,sessionUrl:f.sessionUrl,abortRequestId:null,interruptRequested:!1,elementKey:f.elementKey,locator:f.locator,label:f.label})}function _i(){const f=new Map;for(const c of _.genieTaskByRequestId.values()){if(c.dismissed||!He(c)||!c.recoveryPending||typeof c.sessionId!="string"||!c.sessionId.trim()||typeof c.provider!="string"||!c.provider.trim())continue;const w=c.sessionId.trim(),z=c.provider.trim(),ne=`${z}::${w}`,Q=f.get(ne);if(Q){Q.taskRequestIds.push(c.requestId);continue}f.set(ne,{sessionId:w,provider:z,taskRequestIds:[c.requestId]})}return Array.from(f.values())}function Li(){const f=_i();if(f.length===0||!s||s.readyState!==WebSocket.OPEN){f.length,f.length;return}for(const c of f){const w=it("genie_agent_state_query");c.sessionId,c.provider,c.taskRequestIds,Tt({type:"agent.state.query",requestId:w,payload:{sessionId:c.sessionId,provider:c.provider}});const z=window.setTimeout(()=>{const ne=I.get(w);if(ne){I.delete(w);for(const Q of ne.taskRequestIds){const he=wr(Q);he&&(J("Dropped restored Genie task after state sync timeout",{requestId:Q,sessionId:he.sessionId,scopeKey:he.scopeKey}),te(Q))}}},Na);I.set(w,{...c,timeoutId:z})}}function Di(f,c){if(!s||s.readyState!==WebSocket.OPEN){J("Skipping Genie state subscribe because socket is not open",{sessionId:f,provider:c});return}const w=it("genie_agent_state_subscribe");h.set(w,{sessionId:f,provider:c}),Tt({type:"agent.state.subscribe",requestId:w,payload:{sessionId:f,provider:c}})}function Er(f,c){const w=Mi(f),z=c!=null&&c.length?c:Array.from(_.genieTaskByRequestId.values()).filter(Q=>!Q.dismissed&&He(Q)&&Q.sessionId===f.sessionId&&Q.provider===f.provider).map(Q=>Q.requestId),ne=[];for(const Q of z){const he=ot(Q,{provider:f.provider,status:w.taskStatus,message:w.message,updatedAt:f.updatedAt,recovery:w.recovery,recoveryPending:!1,lastEventAt:f.updatedAt,errorCode:f.phase==="aborted"?"GENIE_ABORTED":null});he&&(ne.push(he),w.taskStatus==="pending"||w.taskStatus==="created"?Sr(he):te(he.requestId))}return f.sessionId,f.provider,f.phase,f.updatedAt,ne.map(Q=>Q.requestId),ne}function vr(f,c){if(!f||!c||!Ka.has(c))return;const w=u(f.scopeKey);w!=null&&w.sessionId&&C(f.scopeKey,{...w,invalidated:!0})}function Tr(f){const c=String(f??"").trim();if(!c)return;const w=u(c);w!=null&&w.sessionId&&C(c,{...w,invalidated:!0})}function Cr(f,c){const w=Ge(f);if(w.length!==0){for(const z of w){const ne=we(z.locator);ne!=null&&ne.isConnected&&t.changes.markElementEditsHandled(ne)}t.persistence.flushPendingWrite()}}function Bi(){const f=V(),c=p(),w=t.persistence.readGenieConversationState(f)??(c!==f?t.persistence.readGenieConversationState(c):null);w&&(C(f,{...w,scopeKey:f}),c!==f&&t.persistence.clearGenieConversationState(c),w.sessionId,w.provider,w.sentCount,w.expiresAt,w.invalidated,void 0),t.persistence.pruneExpiredGenieTaskStates(f);const z=t.persistence.readGenieTaskStates(f),ne=z.length===0&&c!==f?t.persistence.readGenieTaskStates(c):[];z.length+ne.length,[...z,...ne].map(Q=>({requestId:Q.requestId,sessionId:Q.sessionId,provider:Q.provider,status:Q.status}));for(const Q of[...z,...ne]){if(!He(Q)||typeof Q.sessionId!="string"||Q.sessionId.trim().length===0||typeof Q.provider!="string"||Q.provider.trim().length===0){J("Skipping persisted Genie task restore",{requestId:Q.requestId,sessionId:Q.sessionId,provider:Q.provider,status:Q.status,reason:"task-not-running-or-missing-session"});continue}let he=Q.elementKey,Ce=Q.locator,Fe=Q.label;try{const Pe=we(Q.locator);if(Pe!=null&&Pe.isConnected){const $=Ze(Pe);he=$.elementKey,Ce=$.locator,Fe=$.label}}catch{}const Ie={...Q,scopeKey:f,elementKey:he,locator:Ce,label:Fe,recovery:"storage",recoveryPending:He(Q)};Kt(Ie),He(Ie)&&Sr(Ie),Ie.requestId,Ie.sessionId,Ie.provider,Ie.status,Ie.recoveryPending,Ie.elementKey}}function Ht(){l!==null&&(window.clearTimeout(l),l=null)}function jt(){m!==null&&(window.clearTimeout(m),m=null)}function xr(){P!==null&&(window.clearTimeout(P),P=null)}function Pn(f){const c=T.get(f);c&&(window.clearTimeout(c.timeoutId),T.delete(f))}function $t(f,c,w){const z=T.get(f);z&&(window.clearTimeout(z.timeoutId),T.delete(f),w==="FRONTEND_NOT_ONLINE"&&re(!1),z.reject(typeof c=="string"?Xe(c):c))}function Jt(f){const c=T.get(f);c&&(window.clearTimeout(c.timeoutId),T.delete(f),c.resolve())}function Ar(f){for(const[c,w]of T.entries())window.clearTimeout(w.timeoutId),w.reject(Xe(f)),T.delete(c)}function Mn(f,c,w,z="等待 Genie 响应超时,请稍后重试。",ne={}){return new Promise((Q,he)=>{const Ce=window.setTimeout(()=>{T.delete(f),he(Xe(z))},c);T.set(f,{kind:w,resolve:Q,reject:he,timeoutId:Ce,timeoutMessage:z,...ne})})}function Tt(f){if(!s||s.readyState!==WebSocket.OPEN)throw new Error(Yr);s.send(JSON.stringify(f))}function Ir(){if(!(!e||!vt()||P!==null)){if(L>=Gr){J("Reconnect aborted: retry limit reached",{attempts:L,maxAttempts:Gr,integrationChannel:F,targetClientId:E});return}L+=1,P=window.setTimeout(()=>{P=null,Zt()},Aa)}}function _n(){S=0,jt()}function Qt(f){if(!(!e||!vt()||m!==null)&&!(!s||s.readyState!==WebSocket.OPEN)){if(S>=Vr){J("Probe retry aborted: retry limit reached",{reason:f,attempts:S,maxAttempts:Vr,integrationChannel:F,targetClientId:E});return}S+=1,m=window.setTimeout(()=>{m=null,oe().catch(()=>!1).then(()=>{Ln()})},ka)}}function Fi(f){if(s===f){J("Socket closed",{integrationChannel:F,targetClientId:E}),s=null,i=null,a=null;for(const{timeoutId:c}of I.values())window.clearTimeout(c);I.clear(),h.clear(),Ht(),jt(),Z(!1),re(!1);for(const c of Array.from(x.keys())){const w=Et(c);!w||!He(w)||ot(c,{recoveryPending:!0,recovery:"storage",updatedAt:Date.now()})}We(null),Ar("Genie 连接已断开,请稍后重试。"),Ir()}}function Ki(f){var z,ne,Q,he,Ce,Fe,Ie,Pe;let c=null;try{c=JSON.parse(f.data)}catch{J("Received non-JSON WS message",f.data);return}if(!(c!=null&&c.type))return;if(c.type==="integration.connected"){L=0,_n(),Z(!0),c.requestId,c.requestId===i&&N&&Ln(),Li();return}if(c.type==="integration.pong"){if(c.requestId!==a)return;a=null,Ht();const $=Oa(c,E);c.requestId,re($),$?_n():Qt("frontend_offline");return}if(c.type==="integration.presence"){const $=c.payload;if(!$||$.channel!==F||$.clientId!==E)return;$.event==="frontend-online"?(_n(),re(!0)):$.event==="frontend-offline"&&re(!1);return}if(c.type==="integration.ack"&&c.requestId){c.requestId,c.payload,Jt(c.requestId);return}if(c.type==="agent.state.snapshot"&&c.requestId){const $=I.get(c.requestId);if(!$)return;window.clearTimeout($.timeoutId),I.delete(c.requestId);const be=eo(c.payload);if(!be)return;c.requestId,$.sessionId,$.provider,$.taskRequestIds,Er(be,$.taskRequestIds),be.isLoading&&Di($.sessionId,$.provider);return}if(c.type==="agent.state.subscribed"&&c.requestId){if(!h.has(c.requestId))return;c.requestId,h.delete(c.requestId);return}if(c.type==="agent.state.changed"){const $=eo(c.payload);if(!$)return;Er($);return}if(c.type==="agent.error"&&c.requestId){const $=I.get(c.requestId);if($){window.clearTimeout($.timeoutId),I.delete(c.requestId),J("State sync query rejected by Genie",{requestId:c.requestId,sessionId:$.sessionId,provider:$.provider,error:c.error,errorCode:$n(c)});for(const xe of $.taskRequestIds)wr(xe)&&te(xe);return}const be=h.get(c.requestId);if(be){h.delete(c.requestId),J("State sync subscribe rejected by Genie",{requestId:c.requestId,sessionId:be.sessionId,provider:be.provider,error:c.error,errorCode:$n(c)});return}}const w=c.requestId?T.get(c.requestId):void 0;if(c.type==="agent.accepted"&&(w==null?void 0:w.kind)==="agent-run"){const $=Ue(c.requestId??"",{provider:typeof c.provider=="string"&&c.provider.trim()?c.provider:((z=x.get(c.requestId??""))==null?void 0:z.provider)??ce()});ot(c.requestId??"",{status:"pending",provider:($==null?void 0:$.provider)??ce(),message:"Genie 准备中",recovery:"live",recoveryPending:!1,lastEventAt:Date.now(),errorCode:null}),$!=null&&$.sessionId&&Cr(c.requestId??""),w.acceptedNotified||(w.acceptedNotified=!0);return}if(c.type==="agent.session.created"&&(w==null?void 0:w.kind)==="agent-run"){const $=Ue(c.requestId??"",{provider:typeof c.provider=="string"&&c.provider.trim()?c.provider:((ne=x.get(c.requestId??""))==null?void 0:ne.provider)??ce(),sessionId:typeof c.sessionId=="string"&&c.sessionId.trim()?c.sessionId:null,sessionPath:typeof c.sessionPath=="string"&&c.sessionPath.trim()?c.sessionPath:null,sessionUrl:typeof c.sessionUrl=="string"&&c.sessionUrl.trim()?c.sessionUrl:null});ot(c.requestId??"",{status:"created",provider:($==null?void 0:$.provider)??ce(),sessionId:($==null?void 0:$.sessionId)??null,sessionPath:($==null?void 0:$.sessionPath)??null,sessionUrl:($==null?void 0:$.sessionUrl)??null,message:"Genie 正在修改",recovery:"live",recoveryPending:!1,lastEventAt:Date.now(),errorCode:null}),$!=null&&$.scopeKey&&$.sessionId&&G($.scopeKey,{sessionId:$.sessionId,provider:$.provider,projectPath:A,createdAt:Date.now(),lastUsedAt:Date.now(),sentCount:Math.max(1,((Q=u($.scopeKey))==null?void 0:Q.sentCount)??0),sessionPath:$.sessionPath,sessionUrl:$.sessionUrl,invalidated:!1}),Cr(c.requestId??""),w.sessionCreatedNotified||(w.sessionCreatedNotified=!0);return}if(c.type==="agent.completed"&&(w==null?void 0:w.kind)==="agent-run"&&c.requestId){const $=te(c.requestId),be=ot(c.requestId,{status:"completed",provider:typeof c.provider=="string"&&c.provider.trim()?c.provider:($==null?void 0:$.provider)??ce(),sessionId:typeof c.sessionId=="string"&&c.sessionId.trim()?c.sessionId:typeof((he=c.result)==null?void 0:he.sessionId)=="string"&&c.result.sessionId.trim()?c.result.sessionId:($==null?void 0:$.sessionId)??null,sessionPath:typeof c.sessionPath=="string"&&c.sessionPath.trim()?c.sessionPath:typeof((Ce=c.result)==null?void 0:Ce.sessionPath)=="string"&&c.result.sessionPath.trim()?c.result.sessionPath:($==null?void 0:$.sessionPath)??null,sessionUrl:typeof c.sessionUrl=="string"&&c.sessionUrl.trim()?c.sessionUrl:typeof((Fe=c.result)==null?void 0:Fe.sessionUrl)=="string"&&c.result.sessionUrl.trim()?c.result.sessionUrl:($==null?void 0:$.sessionUrl)??null,message:"Genie 修改完成",recovery:"live",recoveryPending:!1,lastEventAt:Date.now(),errorCode:null});$!=null&&$.scopeKey&&(be!=null&&be.sessionId)&&G($.scopeKey,{sessionId:be.sessionId,provider:be.provider,projectPath:A,createdAt:((Ie=u($.scopeKey))==null?void 0:Ie.createdAt)??be.startedAt,lastUsedAt:Date.now(),sentCount:Math.max(1,((Pe=u($.scopeKey))==null?void 0:Pe.sentCount)??0),sessionPath:be.sessionPath,sessionUrl:be.sessionUrl,invalidated:!1}),t.feedback.toast("success","Genie 已完成执行"),Jt(c.requestId);return}if(c.type==="agent.aborted"&&(w==null?void 0:w.kind)==="agent-run"&&c.requestId){const $=te(c.requestId),be=!!($!=null&&$.interruptRequested),xe=$==null?void 0:$.abortRequestId,et=ot(c.requestId,{status:"error",sessionId:typeof c.sessionId=="string"&&c.sessionId.trim()?c.sessionId:($==null?void 0:$.sessionId)??null,sessionPath:($==null?void 0:$.sessionPath)??null,sessionUrl:($==null?void 0:$.sessionUrl)??null,message:"已中断",recovery:"live",recoveryPending:!1,lastEventAt:Date.now(),errorCode:"GENIE_ABORTED"});vr(et,null),Tr(($==null?void 0:$.scopeKey)??(et==null?void 0:et.scopeKey)??null),xe&&Jt(xe),$t(c.requestId,be?Xe("Genie 任务已中断。",{code:"GENIE_ABORTED",silentToast:!0}):"Genie 任务已中断。");return}if(c.type==="agent.error"&&(w==null?void 0:w.kind)==="agent-run"&&c.requestId){const $=te(c.requestId),be=$n(c),xe=ot(c.requestId,{status:"error",provider:typeof c.provider=="string"&&c.provider.trim()?c.provider:($==null?void 0:$.provider)??ce(),sessionId:typeof c.sessionId=="string"&&c.sessionId.trim()?c.sessionId:($==null?void 0:$.sessionId)??null,sessionPath:($==null?void 0:$.sessionPath)??null,sessionUrl:($==null?void 0:$.sessionUrl)??null,message:Hn(c.error),recovery:"live",recoveryPending:!1,lastEventAt:Date.now(),errorCode:be});vr(xe,be),$t(c.requestId,Hn(c.error));return}if(c.type==="agent.aborted"&&(w==null?void 0:w.kind)==="agent-abort"&&c.requestId){const $=w.linkedRunRequestId,be=$?te($):null;if(Jt(c.requestId),be&&t.feedback.toast("info","已中断 Genie 执行"),$){const xe=ot($,{status:"error",sessionId:typeof c.sessionId=="string"&&c.sessionId.trim()?c.sessionId:(be==null?void 0:be.sessionId)??null,sessionPath:(be==null?void 0:be.sessionPath)??null,sessionUrl:(be==null?void 0:be.sessionUrl)??null,message:"已中断",recovery:"live",recoveryPending:!1,lastEventAt:Date.now(),errorCode:"GENIE_ABORTED"});Tr((be==null?void 0:be.scopeKey)??(xe==null?void 0:xe.scopeKey)??null),$t($,Xe("Genie 任务已中断。",{code:"GENIE_ABORTED",silentToast:!0}))}return}if(c.type==="agent.error"&&(w==null?void 0:w.kind)==="agent-abort"&&c.requestId){const $=w.linkedRunRequestId;$&&Ue($,{abortRequestId:null,interruptRequested:!1}),$t(c.requestId,Hn(c.error));return}if(c.type==="integration.error"){const $=c.payload,be=qa($==null?void 0:$.code,$==null?void 0:$.message);J("Received integration error",{requestId:c.requestId,code:$==null?void 0:$.code,message:be,payload:$}),c.requestId===a&&(a=null,Ht(),re(!1),Qt(String(($==null?void 0:$.code)??"integration_error"))),c.requestId&&$t(c.requestId,be,$==null?void 0:$.code)}}function Zt(){if(!e||!vt()||s)return;let f;try{const c=nr(v,H);f=new WebSocket(c)}catch(c){re(!1),Ir(),J("Failed to create Genie bridge socket",c);return}s=f,f.onopen=()=>{if(s===f){xr(),L=0,i=it("genie_connect");try{Tt({type:"integration.connect",requestId:i,payload:{role:"external-client",channel:F,clientId:Y,capabilities:["presence.query","context.push","prompt.push"]}})}catch(c){J("Failed to send integration.connect",c),f.close()}}},f.onmessage=Ki,f.onerror=()=>{J("Socket error",{integrationChannel:F,targetClientId:E}),Z(!1),re(!1)},f.onclose=()=>{Fi(f)}}async function Ln(){if(!e||!vt())return;const f=it("genie_probe"),c=qt(b,Kn);a=f,Ht();try{Tt({type:"integration.ping",requestId:f,payload:{channel:F,targetClientId:E}})}catch(w){J("Failed to send availability probe",w),a=null,re(!1),Qt("send_failed");return}l=window.setTimeout(()=>{a===f&&(J("Availability probe timed out",{requestId:f,timeoutMs:c,integrationChannel:F,targetClientId:E}),a=null,re(!1),Qt("timeout"))},c)}function Dn(){e=!1,R=null,xr(),Ht(),jt(),a=null,i=null;for(const c of B.values())window.clearTimeout(c);B.clear();for(const{timeoutId:c}of I.values())window.clearTimeout(c);I.clear(),h.clear(),L=0,S=0,Ar("Genie bridge 已停止。"),We(null);const f=s;s=null,f&&(f.onopen=null,f.onmessage=null,f.onerror=null,f.onclose=null,f.close()),Z(!1),re(!1)}function kr(){Z(!1),re(!1),I.clear(),h.clear(),L=0,S=0,jt()}async function Hi(){var w,z;return await((z=(w=t.bridgeOptions).onRequestWake)==null?void 0:z.call(w)),!await ie({autoStartRuntime:!0})||(Dn(),e=!0,kr(),typeof window>"u"||typeof WebSocket>"u")?!1:(Zt(),await $i(zr)?!0:(Dn(),!1))}async function $i(f){if(n&&s&&s.readyState===WebSocket.OPEN)return!0;if(typeof window>"u")return!1;const c=Date.now()+qt(f,zr);return await new Promise(w=>{const z=()=>{if(n&&s&&s.readyState===WebSocket.OPEN){w(!0);return}if(!e||Date.now()>=c){w(!1);return}window.setTimeout(z,120)};z()})}function Ui(){if(e){N&&(s==null?void 0:s.readyState)===WebSocket.OPEN&&Ln();return}if(e=!0,kr(),typeof window>"u"||typeof WebSocket>"u"){J("Bridge start skipped",{hasWindow:typeof window<"u",hasWebSocket:typeof WebSocket<"u"});return}if(vt()){Zt();return}ie({autoStartRuntime:!1}).then(f=>{if(e){if(!f){J("Bridge start skipped",{hasRequiredConfig:vt(),enabled:q,apiBaseUrl:v,integrationChannel:F,targetClientId:E});return}Zt()}})}function Oi(f){const c=t.summaries.resolveCurrentFilePath(),w=t.summaries.resolveTargetPath(),z=(()=>{var he;if(!f)return[];const ne=Xt(_,f);if(ne)return[{tag:((he=ne.sourceElement)==null?void 0:he.tagName.toLowerCase())??"text-selection",selector:t.summaries.formatSelectorPath(ne.locator),label:ne.label}];const Q=Se(f);return[{tag:f.tagName.toLowerCase(),selector:t.summaries.formatSelectorPath(Q),label:t.summaries.formatElementLabelFromLocator(Q)}]})();return{version:"1",systemContext:"",currentFile:{path:c,displayName:Ga(w,c)},selectedElements:z,extensions:{source:"web-editor-v2",pageUrl:typeof window<"u"?window.location.href:"",targetPath:w,webEditorV2:{selectedElementNote:t.changes.getSelectedElementNote(),modifiedElements:t.changes.buildModifiedElementsContext(),markersVisible:t.state.changeMarkersVisible},updatedAt:new Date().toISOString()}}}async function qi(f){if(q)try{f.tagName,Ri();const c=it("genie_context"),w=Oi(f),z=Mn(c,qt(b,Kn),"integration");try{Tt({type:"integration.context.update",requestId:c,payload:{channel:F,targetClientId:E,mode:"append",context:w}})}catch(ne){throw Pn(c),ne}await z,t.feedback.toast("success","已添加到 Genie 对话。")}catch(c){const w=c instanceof Error?c.message:String(c);J("Failed to send selected element context",{message:w,integrationChannel:F,targetClientId:E}),t.feedback.toast("error",`添加到 Genie 对话失败:${w}`)}}async function Nr(f,c){var w,z,ne;if(q)try{const Q=Array.from(new Set(f.filter(Le=>!!(Le!=null&&Le.isConnected))));if(Q.length===0)throw Xe("目标元素已失效,请重新选择后再试。");const he=String(c??""),Ce=Q.map(Le=>Ze(Le));if(Ce.length===0)throw Xe("当前没有可发送到 Genie 的编辑元素。");const Fe=Yt(Q),Ie=V(),Pe=k(),$=g(Pe)?Pe:null,be=String(($==null?void 0:$.provider)??ce()).trim(),xe=($==null?void 0:$.sessionId)??null,et=Date.now();Ce.length,Ce.map(Le=>Le.elementKey),he.length,Nn()||await me(),Pi(),ge(be);const Ct=it("genie_agent_run"),zi=Mn(Ct,Ia,"agent-run","等待 Genie 执行完成超时,请稍后查看 Genie 会话。");for(const Le of Ce){const Bn=qe(Le.elementKey);Kt({scopeKey:Ie,elementKey:Le.elementKey,locator:Le.locator,label:Le.label,requestId:Ct,sessionId:xe,sessionPath:($==null?void 0:$.sessionPath)??null,sessionUrl:($==null?void 0:$.sessionUrl)??null,provider:be,status:"pending",message:"Genie 准备中",startedAt:et,updatedAt:et,dismissed:!1,recovery:"live",recoveryPending:!1,lastEventAt:et,errorCode:null},{clearPreviousRequestId:(Bn==null?void 0:Bn.requestId)??null})}We({requestId:Ct,scopeKey:Ie,provider:be,sessionId:xe,sessionPath:($==null?void 0:$.sessionPath)??null,sessionUrl:($==null?void 0:$.sessionUrl)??null,abortRequestId:null,interruptRequested:!1,elementKey:((w=Ce[0])==null?void 0:w.elementKey)??"",locator:((z=Ce[0])==null?void 0:z.locator)??Se(Q[0]),label:((ne=Ce[0])==null?void 0:ne.label)??""});try{Tt({type:"agent.run",requestId:Ct,payload:{projectPath:A,provider:be,...xe?{sessionId:xe}:{},message:he,...Fe.length>0?{images:Fe}:{},stream:!1}}),$&&G(Ie,{sessionId:$.sessionId,provider:be,projectPath:A,createdAt:$.createdAt,lastUsedAt:et,sentCount:$.sentCount+1,expiresAt:$.expiresAt,sessionPath:$.sessionPath,sessionUrl:$.sessionUrl,invalidated:!1})}catch(Le){throw Pn(Ct),te(Ct),ot(Ct,{status:"error",message:Le instanceof Error?Le.message:String(Le),recovery:"live",recoveryPending:!1,lastEventAt:Date.now()}),Le}await zi}catch(Q){const he=Q instanceof Error?Q.message:String(Q);throw Zr(Q)||J("Failed to send prompt to Genie",{message:he,integrationChannel:F,targetClientId:E}),Zr(Q)||t.feedback.toast("error",`发送到 Genie 失败:${he}`),Q}}async function Gi(f,c){await Nr([f],c)}async function Vi(f){if(!q)return;const c=ve(f);if(!c)throw Xe("当前元素没有可中断的 Genie 执行。");const w=x.get(c.requestId)??null;if(!w)throw Xe("当前没有可中断的 Genie 执行。");if(!w.sessionId)throw Xe("Genie 对话尚未创建,暂时无法中断,请稍后再试。");if(w.abortRequestId)return;Rn();const z=it("genie_agent_abort"),ne=Mn(z,qt(b,Kn),"agent-abort","等待 Genie 中断超时,请稍后查看 Genie 会话。",{linkedRunRequestId:w.requestId});Ue(w.requestId,{abortRequestId:z,interruptRequested:!0});try{Tt({type:"agent.abort",requestId:z,payload:{sessionId:w.sessionId,provider:w.provider??ce()}})}catch(Q){throw Pn(z),Ue(w.requestId,{abortRequestId:null,interruptRequested:!1}),Q}try{await ne}catch(Q){const he=Q instanceof Error?Q.message:String(Q);throw J("Failed to interrupt Genie prompt run",{message:he,integrationChannel:F,targetClientId:E}),t.feedback.toast("error",`中断 Genie 执行失败:${he}`),Q}}return{start:Ui,stop:Dn,requestWake:Hi,isConnected(){return n},isAvailable(){return o},getDebugInfo(){return{apiBaseUrl:v,integrationChannel:F,targetClientId:E,provider:ce()}},getCurrentConversationState:y,hasReusableConversation:D,getElementTaskState:ve,getVisibleTaskStates:Ai,getTaskStateByElementKey:ke,resolveSelectableElement:Ti,isElementInteractionLocked:Ci,dismissElementTaskState:xi,setExternalEditingState:ki,clearExternalEditingState:Ni,canInterruptElementTask(f){const c=ve(f);if(!c)return!1;const w=x.get(c.requestId)??null;return!!(w&&w.sessionId&&!w.abortRequestId)},interruptElementTask:Vi,handleSendSelectionToGenie:qi,handleSendPromptToGenieForElements:Nr,handleSendPromptToGenieForElement:Gi,rehydratePersistedGenieState:Bi}}const za=3e3,Wa=100,Xa=["editor.snapshot","editor.nodes.list","editor.node.screenshot","editor.context-images","editor.editing.set"];class $e extends Error{constructor(e,n){super(n),this.code=e}}function Ye(t){return typeof t=="string"&&t.trim().length>0}function Ya(t="editor_integration"){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?`${t}_${crypto.randomUUID()}`:`${t}_${Date.now()}_${Math.random().toString(36).slice(2,10)}`}function ja(t){if(!t||typeof t!="object")return null;const e=t;return{provider:Ye(e.provider)?e.provider.trim():null,sessionId:Ye(e.sessionId)?e.sessionId.trim():null,requestId:Ye(e.requestId)?e.requestId.trim():null}}function Ja(t){if(t==null)return[];if(!Array.isArray(t))throw new $e("INVALID_PAYLOAD","status must be an array of strings");const e=t.map(r=>String(r??"").trim()).filter(Boolean),n=new Set(["dirty","handled","editing","completed","error","pending-dispatch"]);for(const r of e)if(!n.has(r))throw new $e("INVALID_PAYLOAD",`Unknown status alias: ${r}`);return e}function Qa(t){if(t==null||t==="")return Wa;const e=Number(t);if(!Number.isInteger(e)||e<=0)throw new $e("INVALID_PAYLOAD","limit must be a positive integer");return e}function Za(t){if(t instanceof $e)return t;const e=t instanceof Error?t.message:String(t);return e.startsWith("NOT_FOUND:")?new $e("NOT_FOUND",e.replace(/^NOT_FOUND:\s*/,"")):e.startsWith("NOT_IMPLEMENTED:")?new $e("NOT_IMPLEMENTED",e.replace(/^NOT_IMPLEMENTED:\s*/,"")):new $e("INTERNAL_ERROR",e||"Unknown integration failure")}function ec(t,e){return e==="dirty"?t.changeState==="dirty":e==="handled"?t.changeState==="handled":e==="editing"?t.taskState==="editing":e==="completed"?t.taskState==="completed":e==="error"?t.taskState==="error":t.changeState==="dirty"&&t.taskState==="idle"}function tc(t){const{apiBaseUrl:e,apiKey:n,channel:r,clientId:o,enabled:s}=t.integrationWsOptions;let i=!1,a=null,l=null;function m(){return s&&Ye(e)&&Ye(r)&&Ye(o)}function P(){l!==null&&(window.clearTimeout(l),l=null)}function L(){!i||l!==null||!m()||(l=window.setTimeout(()=>{l=null,H()},za))}function S(F){if(!a||a.readyState!==WebSocket.OPEN)throw new $e("INTERNAL_ERROR","Integration WebSocket is not connected");a.send(JSON.stringify(F))}function R(F,A,X){S({type:"integration.error",requestId:F,payload:{code:A,message:X}})}function I(F,A){const X=Ye(F.channel)?F.channel.trim():"",N=Ye(F.targetClientId)?F.targetClientId.trim():"";if(!X||!N)throw new $e("INVALID_PAYLOAD","payload.channel and payload.targetClientId are required");if(X!==r||N!==o)throw new $e("INVALID_TARGET","Message target does not match this frontend page");if(!A)throw new $e("INVALID_PAYLOAD","requestId is required")}async function h(F){const A=String(F.requestId??"").trim(),X=F.payload??{};I(X,A),S({type:"integration.editor.snapshot.result",requestId:A,payload:t.getEditedSnapshotPayload()})}async function T(F){const A=String(F.requestId??"").trim(),X=F.payload??{};I(X,A);const N=Ja(X.status),b=Ye(X.elementKey)?X.elementKey.trim():null,E=Qa(X.limit),d=t.listEditorNodes().filter(M=>b&&M.elementKey!==b?!1:N.length===0?!0:N.some(j=>ec(M,j)));S({type:"integration.editor.nodes.result",requestId:A,payload:{items:d.slice(0,E),total:d.length,filters:{status:N,elementKey:b,limit:E}}})}async function x(F){const A=String(F.requestId??"").trim(),X=F.payload??{};I(X,A);const N=Ye(X.elementKey)?X.elementKey.trim():"";if(!N)throw new $e("INVALID_PAYLOAD","payload.elementKey is required");S({type:"integration.editor.node.screenshot.result",requestId:A,payload:await t.getNodeScreenshotPayload(N)})}async function B(F){const A=String(F.requestId??"").trim(),X=F.payload??{};I(X,A),S({type:"integration.editor.context-images.result",requestId:A,payload:t.getContextImagesPayload()})}async function K(F){const A=String(F.requestId??"").trim(),X=F.payload??{};I(X,A);const N=Ye(X.elementKey)?X.elementKey.trim():"";if(!N)throw new $e("INVALID_PAYLOAD","payload.elementKey is required");const b=X.state;if(b!=="editing"&&b!=="idle")throw new $e("INVALID_PAYLOAD","payload.state must be editing or idle");S({type:"integration.editor.editing.result",requestId:A,payload:await t.setNodeEditingState(N,b,ja(X.taskRef),A)})}async function _(F){try{if(F.type==="integration.editor.snapshot.get"){await h(F);return}if(F.type==="integration.editor.nodes.list"){await T(F);return}if(F.type==="integration.editor.node.screenshot.get"){await x(F);return}if(F.type==="integration.editor.context-images.get"){await B(F);return}F.type==="integration.editor.editing.set"&&await K(F)}catch(A){const X=String(F.requestId??"").trim();if(!X)return;const N=Za(A);R(X,N.code,N.message)}}function v(F){let A=null;try{A=JSON.parse(F.data)}catch{return}A!=null&&A.type&&A.type!=="integration.connected"&&_(A)}function H(){if(!i||a||!m())return;let F;try{F=new WebSocket(nr(e,n))}catch{L();return}a=F,F.onopen=()=>{try{S({type:"integration.connect",requestId:Ya("integration_connect"),payload:{role:"frontend-page",channel:r.trim(),clientId:o.trim(),pageUrl:t.getPageUrl(),sessionId:t.getSessionId(),capabilities:[...Xa]}})}catch{F.close()}},F.onmessage=v,F.onerror=()=>{},F.onclose=()=>{a===F&&(a=null),L()}}function q(){i=!1,P();const F=a;a=null,F&&(F.onopen=null,F.onmessage=null,F.onerror=null,F.onclose=null,F.close())}function Y(){i||(i=!0,!(typeof window>"u"||typeof WebSocket>"u"||!m())&&H())}return{start:Y,stop:q}}function nc(t){const{state:e,genieBridge:n}=t;function r(){var _;const h=e.selectionAnchor;if(!h)return null;const T=e.selectedElement,x=(_=e.activeTextAnnotation)==null?void 0:_.sourceElement,B=T&&T.isConnected?T:x&&x.isConnected?x:null,K=B instanceof HTMLElement?B.getBoundingClientRect():null;return da(h,{liveRect:K,scrollX:window.scrollX,scrollY:window.scrollY,viewportWidth:window.innerWidth})}function o(){return r()}function s(h){var B,K;h&&n.isElementInteractionLocked(h)&&(h=null);const T=e.hoveredElement;e.hoveredElement=h;const x=T!==null&&h!==null&&T!==h;e.pendingHoverTransition=x,(B=e.positionTracker)==null||B.setHoverElement(h),(K=e.positionTracker)==null||K.forceUpdate()}function i(h,T,x){var K,_,v,H,q,Y,F,A;if(n.isElementInteractionLocked(h))return;t.changes.rememberSelectionAnchor(h,x),e.selectedElement=h,e.hoveredElement=null,(K=e.positionTracker)==null||K.setHoverElement(null),(_=e.positionTracker)==null||_.setSelectionElement(h),(v=e.positionTracker)==null||v.forceUpdate(),(H=e.breadcrumbs)==null||H.setTarget(h),(q=e.propertyPanel)==null||q.setTarget(h),(Y=e.handlesController)==null||Y.setTarget(h),(F=e.parentSelectController)==null||F.setTarget(h),(A=t.onStatusChange)==null||A.call(t);const B=T.alt?" (Alt: drill-up)":"";console.log(`${t.logPrefix} Selected${B}:`,h.tagName,h)}function a(){var h,T,x,B,K,_,v,H,q,Y,F,A,X,N,b,E,O,d;if(!e.selectedElement&&e.activeTextAnnotation){t.changes.clearPendingSelectionAnchor(),e.selectionAnchor=null,e.activeTextAnnotation=null,(h=e.canvasOverlay)==null||h.setTextHighlightRects(null),(T=e.textAnnotationManager)==null||T.clearActiveHighlight(),e.textAnnotationTargetElement&&delete e.textAnnotationTargetElement.dataset.weTextAnnotationId,(x=e.positionTracker)==null||x.setSelectionElement(null),(B=e.positionTracker)==null||B.forceUpdate(),(K=e.breadcrumbs)==null||K.setTarget(null),(_=e.breadcrumbs)==null||_.setAnchorRect(null),(v=e.propertyPanel)==null||v.setTarget(null),(H=e.propertyPanel)==null||H.refresh(),(q=e.handlesController)==null||q.setTarget(null),(Y=e.parentSelectController)==null||Y.setTarget(null),(F=t.onStatusChange)==null||F.call(t),console.log(`${t.logPrefix} Deselected`);return}e.selectedElement=null,t.changes.clearPendingSelectionAnchor(),(A=e.positionTracker)==null||A.setSelectionElement(null),(X=e.positionTracker)==null||X.forceUpdate(),(N=e.breadcrumbs)==null||N.setTarget(null),(b=e.propertyPanel)==null||b.setTarget(null),(E=e.handlesController)==null||E.setTarget(null),(O=e.parentSelectController)==null||O.setTarget(null),(d=t.onStatusChange)==null||d.call(t),console.log(`${t.logPrefix} Deselected`)}function l(h){var A,X,N;const T=o(),x=!!e.activeTextAnnotation;(A=e.breadcrumbs)==null||A.setAnchorRect(x?T:h.selection??T);const B=e.pendingHoverTransition;if(e.pendingHoverTransition=!1,!e.canvasOverlay)return;const K=!!e.selectedElement&&e.hoveredElement===e.selectedElement,_=!e.selectionChromeVisible,v=_||K?null:h.hover,H=_||x?null:h.selection,q=n.isElementInteractionLocked(e.selectedElement),Y=!_&&H&&q?"ai-editing":"default",F=_||e.annotationEntryMode==="bubble-card"||q?null:h.selection;e.canvasOverlay.setHoverRect(v,{animate:B}),e.canvasOverlay.setSelectionEffect(Y),e.canvasOverlay.setSelectionRect(H),e.canvasOverlay.setEditingRects(null),(X=e.handlesController)==null||X.setSelectionRect(F),(N=e.parentSelectController)==null||N.setSelectionRect(H),t.changes.renderChangeMarkers(),e.canvasOverlay.render()}function m(h){var K,_,v,H,q;const{action:T,undoCount:x,redoCount:B}=h;console.log(`${t.logPrefix} Transaction: ${T} (undo: ${x}, redo: ${B})`),t.changes.syncEditMetaWithTransactions(),(K=e.propertyPanel)==null||K.setHistory(x,B),(_=e.breadcrumbs)==null||_.refresh(),(T==="undo"||T==="redo")&&((v=e.propertyPanel)==null||v.refresh()),(H=e.positionTracker)==null||H.forceUpdate(!0),t.persistence.scheduleWrite(),(q=t.onStatusChange)==null||q.call(t)}function P(h="bubble-card"){var T,x;e.annotationEntryMode=h,(x=(T=e.propertyPanel)==null?void 0:T.enterAnnotationInput)==null||x.call(T,h)}function L(h){var B;const T=e.selectedElement;let x=T&&T.isConnected?T:null;return!x&&h&&(x=((B=e.selectionEngine)==null?void 0:B.findBestTarget(h.clientX,h.clientY,Cn))??null),x=n.resolveSelectableElement(x),!x||!x.isConnected?!1:(e.selectedElement!==x&&i(x,Cn,h),P("bubble-card"),!0)}function S(){var B,K,_,v,H,q,Y,F,A,X,N,b,E,O,d,M,j,ee;const h=!!e.selectedElement,T=!!e.activeTextAnnotation;if(!h&&!T&&!e.selectionAnchor)return;const x=()=>{if(typeof t.changes.getMetaForElement!="function"||typeof t.changes.normalizeNote!="function"||typeof t.changes.setNoteForElement!="function")return;const oe=e.textAnnotationTargetElement??null,ie=t.changes.getMetaForElement(oe),me=!!(ie&&(t.changes.normalizeNote(ie.note).trim()||ie.images.length>0||ie.changeKinds.length>0));oe&&!me&&t.changes.setNoteForElement(oe,"")};e.eventController?(e.eventController.setMode("hover"),e.selectedElement?a():(x(),t.changes.clearPendingSelectionAnchor(),e.selectionAnchor=null,e.activeTextAnnotation=null,(B=e.canvasOverlay)==null||B.setTextHighlightRects(null),(K=e.textAnnotationManager)==null||K.clearActiveHighlight(),e.textAnnotationTargetElement&&delete e.textAnnotationTargetElement.dataset.weTextAnnotationId,(_=e.breadcrumbs)==null||_.setTarget(null),(v=e.breadcrumbs)==null||v.setAnchorRect(null),(H=e.propertyPanel)==null||H.setTarget(null),(q=e.propertyPanel)==null||q.refresh(),(Y=e.handlesController)==null||Y.setTarget(null),(F=e.parentSelectController)==null||F.setTarget(null),(A=t.onStatusChange)==null||A.call(t))):e.selectedElement?a():(x(),t.changes.clearPendingSelectionAnchor(),e.selectionAnchor=null,e.activeTextAnnotation=null,(X=e.canvasOverlay)==null||X.setTextHighlightRects(null),(N=e.textAnnotationManager)==null||N.clearActiveHighlight(),e.textAnnotationTargetElement&&delete e.textAnnotationTargetElement.dataset.weTextAnnotationId,(b=e.breadcrumbs)==null||b.setTarget(null),(E=e.breadcrumbs)==null||E.setAnchorRect(null),(O=e.propertyPanel)==null||O.setTarget(null),(d=e.propertyPanel)==null||d.refresh(),(M=e.handlesController)==null||M.setTarget(null),(j=e.parentSelectController)==null||j.setTarget(null),(ee=t.onStatusChange)==null||ee.call(t)),console.log(`${t.logPrefix} Selection cleared`)}async function R(h){var B,K;const T=String(h??"").trim();if(!T)return{success:!1,error:"elementKey is required"};const x=e.transactionManager;if(!x)return{success:!1,error:"Transaction manager not ready"};try{const _=kn(e,x.getUndoStack()),H=tt(_).find(b=>b.elementKey===T);if(!H)return{success:!1,error:"Element not found in current changes"};const q=we(H.locator);if(!q||!q.isConnected)return{success:!1,error:"Failed to locate element for revert"};const Y={};let F=!1;const A=H.netEffect.classChanges;if(A){const b=Array.isArray(A.before)?A.before:[],E=(()=>{try{const M=q.classList;if(M&&typeof M[Symbol.iterator]=="function")return Array.from(M).filter(Boolean)}catch{}return(q.getAttribute("class")??"").split(/\s+/).map(M=>M.trim()).filter(Boolean)})();x.recordClass(q,E,b)&&(Y.class=!0,F=!0)}const X=H.netEffect.textChange;if(X){const b=String(X.before??""),E=q.textContent??"";E!==b&&(q.textContent=b,x.recordText(q,E,b)&&(Y.text=!0,F=!0))}const N=H.netEffect.styleChanges;if(N){const b=N.before??{},E=N.after??{},O=Array.from(new Set([...Object.keys(b),...Object.keys(E)])).map(d=>String(d??"").trim()).filter(Boolean);if(O.length>0){const d=x.beginMultiStyle(q,O);d&&(d.set(b),d.commit({merge:!1})&&(Y.style=!0,F=!0))}}return F?((B=e.propertyPanel)==null||B.refresh(),(K=t.onStatusChange)==null||K.call(t),{success:!0,reverted:Y}):{success:!1,error:"No changes were reverted"}}catch(_){return console.error(`${t.logPrefix} Revert element failed:`,_),{success:!1,error:_ instanceof Error?_.message:String(_)}}}function I(h,T){var O,d,M,j,ee,oe,ie,me,ce,pe,ge,ae,V;const x=h.id,B=(O=h.sourceElement)!=null&&O.isConnected?h.sourceElement:null,K=h.boundingRect,_=Number.isFinite(K.left)&&Number.isFinite(K.top)&&Number.isFinite(K.width)&&Number.isFinite(K.height),v=_?K.left+K.width/2:T.clientX,H=_?K.top+K.height/2:T.clientY,q=B&&"getBoundingClientRect"in B&&typeof B.getBoundingClientRect=="function"?B.getBoundingClientRect():null,Y=q&&Number.isFinite(q.left)&&Number.isFinite(q.width)?v-q.left:void 0,F=q&&Number.isFinite(q.top)&&Number.isFinite(q.height)?H-q.top:void 0,A=B?Se(B):{selectors:[],fingerprint:h.selectedText.slice(0,80),path:[]},X=ai(h.selectedText),N=t.changes.getOrCreateEditMeta(x,A,X),b=ri({clientX:v,clientY:H,scrollX:window.scrollX,scrollY:window.scrollY,viewportWidth:window.innerWidth,isFixed:!1,offsetX:Y,offsetY:F});e.selectedElement=null,e.selectionAnchor=b,e.hoveredElement=null,e.activeTextAnnotation=h,(d=e.positionTracker)==null||d.setSelectionElement(B),N.anchor=b;const E=e.textAnnotationTargetElement;E?(E.dataset.weTextAnnotationId=h.id,E.style.left=`${Math.round(v)}px`,E.style.top=`${Math.round(H)}px`,(M=e.breadcrumbs)==null||M.setTarget(null),(j=e.propertyPanel)==null||j.setTarget(null),(ee=e.breadcrumbs)==null||ee.setTarget(E),(oe=e.propertyPanel)==null||oe.setTarget(E)):((ie=e.breadcrumbs)==null||ie.setTarget(null),(me=e.propertyPanel)==null||me.setTarget(null)),(ce=e.breadcrumbs)==null||ce.setAnchorRect(h.boundingRect),(pe=e.handlesController)==null||pe.setTarget(null),(ge=e.parentSelectController)==null||ge.setTarget(null),P("bubble-card"),(ae=e.propertyPanel)==null||ae.refresh(),(V=t.onStatusChange)==null||V.call(t),console.log(`${t.logPrefix} Text annotation:`,h.selectedText.slice(0,50))}return{handleHover:s,handleSelect:i,handleDeselect:a,handlePositionUpdate:l,handleTransactionChange:m,enterAnnotationInput:P,enterAnnotationFromTrigger:L,enterTextAnnotation:I,clearSelection:S,revertElement:R}}class ze{constructor(){this.disposed=!1,this.disposers=[]}get isDisposed(){return this.disposed}add(e){if(this.disposed){try{e()}catch{}return}this.disposers.push(e)}listen(e,n,r,o){e.addEventListener(n,r,o),this.add(()=>e.removeEventListener(n,r,o))}observeResize(e,n,r){const o=new ResizeObserver(n);return o.observe(e,r),this.add(()=>o.disconnect()),o}observeMutation(e,n,r){const o=new MutationObserver(n);return o.observe(e,r),this.add(()=>o.disconnect()),o}requestAnimationFrame(e){const n=requestAnimationFrame(e);let r=!1;const o=()=>{r||(r=!0,cancelAnimationFrame(n))};return this.add(o),o}dispose(){if(!this.disposed){this.disposed=!0;for(let e=this.disposers.length-1;e>=0;e--)try{this.disposers[e]()}catch{}this.disposers.length=0}}}const rc=`
|
||
:host {
|
||
all: initial;
|
||
|
||
/* Shared overlay tokens */
|
||
--we-surface-bg: #0a0a0a;
|
||
|
||
/* Border colors */
|
||
--we-border-subtle: rgba(255, 255, 255, 0.08);
|
||
|
||
/* Text colors */
|
||
--we-text-primary: rgba(255, 255, 255, 0.94);
|
||
--we-text-secondary: rgba(255, 255, 255, 0.72);
|
||
--we-text-muted: #a1a1aa;
|
||
|
||
/* Shared chrome */
|
||
--we-shadow-panel: 0 20px 54px rgba(0, 0, 0, 0.42), 0 6px 20px rgba(0, 0, 0, 0.28);
|
||
--we-shadow-glow: 0 0 22px rgba(0, 143, 93, 0.18);
|
||
--we-editor-surface-dark: #121212;
|
||
--we-editor-surface-elevated-dark: #161616;
|
||
--we-editor-surface-muted-dark: #18181b;
|
||
--we-editor-surface-interactive-dark: #1d1d1f;
|
||
--we-editor-border-dark: rgba(255, 255, 255, 0.08);
|
||
--we-editor-border-strong-dark: rgba(255, 255, 255, 0.12);
|
||
--we-editor-text-primary-dark: rgba(255, 255, 255, 0.94);
|
||
--we-editor-text-secondary-dark: rgba(255, 255, 255, 0.72);
|
||
--we-editor-text-muted-dark: #a1a1aa;
|
||
--we-brand-primary: #008f5d;
|
||
--we-brand-accent: #00d68f;
|
||
--we-brand-sleeping: #71717a;
|
||
|
||
--we-radius-panel: 16px;
|
||
--we-radius-control: 12px;
|
||
--we-radius-pill: 999px;
|
||
|
||
/* Focus ring */
|
||
--we-focus-ring: rgba(0, 214, 143, 0.24);
|
||
}
|
||
|
||
*,
|
||
*::before,
|
||
*::after {
|
||
box-sizing: border-box;
|
||
}
|
||
|
||
/* Overlay container - for Canvas and visual feedback */
|
||
#${Xo} {
|
||
position: fixed;
|
||
inset: 0;
|
||
pointer-events: none;
|
||
contain: layout style;
|
||
}
|
||
|
||
/* ==========================================================================
|
||
* Resize Handles (Phase 4.9)
|
||
* ========================================================================== */
|
||
|
||
/* Handles layer - covers viewport, pass-through by default */
|
||
.we-handles-layer {
|
||
position: absolute;
|
||
inset: 0;
|
||
pointer-events: none;
|
||
contain: layout style paint;
|
||
}
|
||
|
||
/* Selection frame - positioned by selection rect */
|
||
.we-selection-frame {
|
||
position: absolute;
|
||
top: 0;
|
||
left: 0;
|
||
width: 0;
|
||
height: 0;
|
||
transform: translate3d(0, 0, 0);
|
||
pointer-events: none;
|
||
will-change: transform, width, height;
|
||
}
|
||
|
||
.we-parent-corner {
|
||
position: absolute;
|
||
width: 7px;
|
||
height: 7px;
|
||
margin: 0;
|
||
padding: 0;
|
||
border: 0;
|
||
background: transparent;
|
||
pointer-events: auto;
|
||
display: block;
|
||
cursor: pointer;
|
||
user-select: none;
|
||
touch-action: manipulation;
|
||
z-index: 7;
|
||
}
|
||
|
||
.we-parent-corner[data-hidden="true"] {
|
||
display: none;
|
||
}
|
||
|
||
.we-parent-corner:focus-visible {
|
||
outline: none;
|
||
}
|
||
|
||
.we-parent-corner__chrome {
|
||
width: 100%;
|
||
height: 100%;
|
||
border-radius: 2px;
|
||
display: block;
|
||
opacity: 0.82;
|
||
transition: opacity 140ms ease, box-shadow 140ms ease;
|
||
}
|
||
|
||
/* Individual resize handle */
|
||
.we-resize-handle {
|
||
position: absolute;
|
||
width: 8px;
|
||
height: 8px;
|
||
border-radius: 2px;
|
||
background: #ffffff;
|
||
border: 1px solid ${Me.selectionBorder};
|
||
box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.9), 0 0 0 2px rgba(0, 214, 143, 0.18),
|
||
0 8px 20px rgba(0, 0, 0, 0.18);
|
||
pointer-events: auto;
|
||
touch-action: none;
|
||
user-select: none;
|
||
transition: background-color 0.1s ease, border-color 0.1s ease, transform 0.1s ease,
|
||
box-shadow 0.1s ease;
|
||
}
|
||
|
||
.we-resize-handle:hover {
|
||
background: #ffffff;
|
||
border-color: ${Me.selectionBorder};
|
||
box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.98), 0 0 0 3px rgba(0, 214, 143, 0.22),
|
||
0 10px 24px rgba(0, 0, 0, 0.2);
|
||
transform: translate(-50%, -50%) scale(1.15);
|
||
}
|
||
|
||
.we-resize-handle:active {
|
||
transform: translate(-50%, -50%) scale(1.0);
|
||
}
|
||
|
||
/* Handle positions - all use translate(-50%, -50%) as base */
|
||
.we-resize-handle[data-dir="n"] { left: 50%; top: 0; transform: translate(-50%, -50%); cursor: ns-resize; }
|
||
.we-resize-handle[data-dir="s"] { left: 50%; top: 100%; transform: translate(-50%, -50%); cursor: ns-resize; }
|
||
.we-resize-handle[data-dir="e"] { left: 100%; top: 50%; transform: translate(-50%, -50%); cursor: ew-resize; }
|
||
.we-resize-handle[data-dir="w"] { left: 0; top: 50%; transform: translate(-50%, -50%); cursor: ew-resize; }
|
||
.we-resize-handle[data-dir="nw"] { left: 0; top: 0; transform: translate(-50%, -50%); cursor: nwse-resize; }
|
||
.we-resize-handle[data-dir="ne"] { left: 100%; top: 0; transform: translate(-50%, -50%); cursor: nesw-resize; }
|
||
.we-resize-handle[data-dir="sw"] { left: 0; top: 100%; transform: translate(-50%, -50%); cursor: nesw-resize; }
|
||
.we-resize-handle[data-dir="se"] { left: 100%; top: 100%; transform: translate(-50%, -50%); cursor: nwse-resize; }
|
||
|
||
/* Size HUD - shows W×H while resizing */
|
||
.we-size-hud {
|
||
position: absolute;
|
||
left: 50%;
|
||
top: 0;
|
||
transform: translate(-50%, calc(-100% - 8px));
|
||
padding: 3px 8px;
|
||
font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
|
||
font-size: 11px;
|
||
font-weight: 600;
|
||
line-height: 1.2;
|
||
color: rgba(255, 255, 255, 0.98);
|
||
background: rgba(18, 18, 18, 0.94);
|
||
border: 1px solid rgba(0, 214, 143, 0.2);
|
||
border-radius: 999px;
|
||
pointer-events: none;
|
||
user-select: none;
|
||
white-space: nowrap;
|
||
box-shadow: var(--we-shadow-glow), 0 8px 20px rgba(0, 0, 0, 0.24);
|
||
backdrop-filter: blur(4px);
|
||
-webkit-backdrop-filter: blur(4px);
|
||
}
|
||
|
||
/* ==========================================================================
|
||
* Performance HUD (Phase 5.3)
|
||
* ========================================================================== */
|
||
|
||
.we-perf-hud {
|
||
position: fixed;
|
||
left: 12px;
|
||
bottom: 12px;
|
||
padding: 8px 10px;
|
||
border-radius: 16px;
|
||
background: rgba(18, 18, 18, 0.86);
|
||
border: 1px solid rgba(255, 255, 255, 0.08);
|
||
color: rgba(255, 255, 255, 0.96);
|
||
font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
|
||
font-size: 12px;
|
||
line-height: 1.25;
|
||
pointer-events: none;
|
||
user-select: none;
|
||
white-space: nowrap;
|
||
z-index: 10;
|
||
box-shadow: var(--we-shadow-panel);
|
||
backdrop-filter: blur(6px);
|
||
-webkit-backdrop-filter: blur(6px);
|
||
font-variant-numeric: tabular-nums;
|
||
}
|
||
|
||
.we-perf-hud-line + .we-perf-hud-line {
|
||
margin-top: 4px;
|
||
}
|
||
|
||
/* UI container - for panels and controls */
|
||
/* Position below toolbar: 16px (toolbar top) + 40px (toolbar height) + 8px (gap) = 64px */
|
||
#${Yo} {
|
||
position: fixed;
|
||
inset: 0;
|
||
top: 32px;
|
||
right: 16px;
|
||
pointer-events: none;
|
||
z-index: 10020;
|
||
font-family: "Inter", "SF Pro Display", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
|
||
font-size: 11px;
|
||
line-height: 1.4;
|
||
color: var(--we-text-primary);
|
||
-webkit-font-smoothing: antialiased;
|
||
}
|
||
|
||
/* ==========================================================================
|
||
Breadcrumbs (Phase 2.2) - Anchored to selection element
|
||
========================================================================== */
|
||
.we-breadcrumbs {
|
||
position: fixed;
|
||
/* left/top set dynamically via JS based on selection rect */
|
||
left: 16px;
|
||
top: 72px;
|
||
width: auto;
|
||
max-width: min(600px, calc(100vw - 400px));
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 2px;
|
||
padding: 4px 6px;
|
||
background: var(--we-surface-bg);
|
||
border: 1px solid var(--we-border-subtle);
|
||
border-radius: var(--we-radius-panel);
|
||
box-shadow: var(--we-shadow-panel);
|
||
pointer-events: auto;
|
||
user-select: none;
|
||
overflow-x: auto;
|
||
white-space: nowrap;
|
||
scrollbar-width: none;
|
||
z-index: 5;
|
||
color: var(--we-text-primary);
|
||
}
|
||
|
||
.we-breadcrumbs[data-hidden="true"] {
|
||
display: none;
|
||
}
|
||
|
||
.we-breadcrumbs[data-position="bottom"] {
|
||
top: auto;
|
||
bottom: 72px;
|
||
}
|
||
|
||
.we-breadcrumbs::-webkit-scrollbar {
|
||
display: none;
|
||
}
|
||
|
||
.we-crumb {
|
||
display: inline-flex;
|
||
align-items: center;
|
||
max-width: 220px;
|
||
padding: 4px 8px;
|
||
border-radius: var(--we-radius-control);
|
||
border: none;
|
||
background: transparent;
|
||
color: var(--we-text-secondary);
|
||
font-size: 12px;
|
||
font-weight: 500;
|
||
line-height: 1.2;
|
||
cursor: pointer;
|
||
overflow: hidden;
|
||
text-overflow: ellipsis;
|
||
transition: all 0.15s ease;
|
||
}
|
||
|
||
.we-crumb-send-btn {
|
||
display: inline-flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
width: 24px;
|
||
height: 24px;
|
||
border: none;
|
||
border-radius: var(--we-radius-control);
|
||
background: rgba(0, 143, 93, 0.1);
|
||
color: #008F5D;
|
||
cursor: pointer;
|
||
transition: background 0.15s ease, transform 0.15s ease;
|
||
flex: 0 0 auto;
|
||
}
|
||
|
||
.we-crumb-send-btn svg {
|
||
width: 14px;
|
||
height: 14px;
|
||
display: block;
|
||
}
|
||
|
||
.we-crumb-send-btn:hover {
|
||
background: rgba(0, 143, 93, 0.16);
|
||
transform: translateY(-1px);
|
||
}
|
||
|
||
.we-crumb-send-btn:focus-visible {
|
||
outline: none;
|
||
box-shadow: 0 0 0 2px var(--we-focus-ring);
|
||
}
|
||
|
||
.we-crumb:hover {
|
||
background: rgba(0, 143, 93, 0.08);
|
||
color: var(--we-text-primary);
|
||
}
|
||
|
||
.we-crumb:active {
|
||
background: rgba(0, 143, 93, 0.12);
|
||
}
|
||
|
||
.we-crumb:focus-visible {
|
||
outline: none;
|
||
box-shadow: 0 0 0 2px var(--we-focus-ring);
|
||
}
|
||
|
||
.we-crumb--current {
|
||
background: rgba(0, 143, 93, 0.1);
|
||
color: #008F5D;
|
||
font-weight: 600;
|
||
}
|
||
|
||
.we-crumb-sep {
|
||
display: inline-flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
width: 14px;
|
||
flex: 0 0 auto;
|
||
color: var(--we-text-muted);
|
||
font-size: 12px;
|
||
}
|
||
|
||
.we-crumb-sep--shadow {
|
||
color: var(--we-text-secondary);
|
||
}
|
||
|
||
.we-change-markers {
|
||
position: fixed;
|
||
inset: 0;
|
||
pointer-events: none;
|
||
z-index: 9996;
|
||
}
|
||
|
||
.we-change-marker {
|
||
position: fixed;
|
||
transform: translate(-50%, -50%);
|
||
width: 22px;
|
||
height: 22px;
|
||
border-radius: 999px;
|
||
background: linear-gradient(180deg, #0f172a 0%, #1e293b 100%);
|
||
color: #ffffff;
|
||
display: inline-flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
font-size: 11px;
|
||
font-weight: 700;
|
||
line-height: 1;
|
||
letter-spacing: -0.02em;
|
||
box-shadow:
|
||
0 8px 18px rgba(15, 23, 42, 0.22),
|
||
0 0 0 2px rgba(255, 255, 255, 0.95);
|
||
pointer-events: auto;
|
||
cursor: pointer;
|
||
transition: transform 0.16s ease, box-shadow 0.16s ease, opacity 0.16s ease;
|
||
}
|
||
|
||
.we-change-marker:hover,
|
||
.we-change-marker:focus-visible {
|
||
transform: translate(-50%, -50%) scale(1.06);
|
||
box-shadow:
|
||
0 10px 22px rgba(15, 23, 42, 0.28),
|
||
0 0 0 2px rgba(255, 255, 255, 0.95),
|
||
0 0 0 5px rgba(0, 143, 93, 0.18);
|
||
outline: none;
|
||
}
|
||
|
||
.we-change-marker__tooltip {
|
||
position: absolute;
|
||
left: 50%;
|
||
top: calc(100% + 8px);
|
||
transform: translateX(-50%);
|
||
width: min(280px, calc(100vw - 32px));
|
||
max-width: min(280px, calc(100vw - 32px));
|
||
padding: 8px 10px;
|
||
border-radius: 10px;
|
||
background: rgba(15, 23, 42, 0.96);
|
||
color: rgba(255, 255, 255, 0.92);
|
||
box-shadow: 0 12px 24px rgba(15, 23, 42, 0.22);
|
||
opacity: 0;
|
||
pointer-events: none;
|
||
transition: opacity 0.12s ease, transform 0.12s ease;
|
||
}
|
||
|
||
.we-change-marker:hover .we-change-marker__tooltip,
|
||
.we-change-marker:focus-visible .we-change-marker__tooltip {
|
||
opacity: 1;
|
||
transform: translateX(-50%) translateY(0);
|
||
}
|
||
|
||
.we-change-marker__details {
|
||
display: flex;
|
||
flex-direction: column;
|
||
gap: 4px;
|
||
margin-top: 4px;
|
||
}
|
||
|
||
.we-change-marker__label {
|
||
display: block;
|
||
font-size: 10px;
|
||
font-weight: 500;
|
||
line-height: 1.35;
|
||
color: rgba(255, 255, 255, 0.58);
|
||
}
|
||
|
||
.we-change-marker__note {
|
||
display: block;
|
||
font-size: 12px;
|
||
font-weight: 700;
|
||
line-height: 1.5;
|
||
color: rgba(255, 255, 255, 0.96);
|
||
white-space: pre-wrap;
|
||
word-break: break-word;
|
||
}
|
||
|
||
/* ==========================================================================
|
||
* Global Hidden Rule
|
||
* Ensures [hidden] attribute always hides elements, even when they have
|
||
* explicit display values (flex, inline-flex, etc.)
|
||
* ========================================================================== */
|
||
[hidden] {
|
||
display: none !important;
|
||
}
|
||
`;function lt(t,e,n){t.style.setProperty(e,n,"important")}function oc(t={}){const e=new ze;let n=null;const r=document.getElementById(_r);if(r)try{r.remove()}catch{}const o=document.createElement("div");o.id=_r,o.setAttribute("data-mcp-web-editor","v2"),lt(o,"position","fixed"),lt(o,"inset","0"),lt(o,"z-index",String(us)),lt(o,"pointer-events","none"),lt(o,"background","transparent"),mt()?lt(o,"contain","none"):(lt(o,"contain","layout style paint"),lt(o,"isolation","isolate"));const s=o.attachShadow({mode:"open"}),i=document.createElement("style");i.textContent=rc,s.append(i);const a=document.createElement("div");a.id=Xo;const l=document.createElement("div");l.id=Yo,s.append(a,l),(document.documentElement??document.body).append(o),e.add(()=>o.remove()),n={host:o,shadowRoot:s,overlayRoot:a,uiRoot:l};const P=["pointerdown","pointerup","pointermove","pointerenter","pointerleave","mousedown","mouseup","mousemove","mouseenter","mouseleave","click","dblclick","contextmenu","keydown","keyup","keypress","wheel","touchstart","touchmove","touchend","touchcancel","focus","blur","input","change"],L=I=>{I.stopPropagation()};for(const I of P)e.listen(l,I,L),e.listen(a,I,L);const S=I=>{if(!(I instanceof Node))return!1;if(I===o)return!0;const h=typeof I.getRootNode=="function"?I.getRootNode():null;return h instanceof ShadowRoot&&h.host===o};return{getElements:()=>n,isOverlayElement:S,isEventFromUi:I=>{try{if(typeof I.composedPath=="function")return I.composedPath().some(h=>S(h))}catch{}return S(I.target)},dispose:()=>{n=null,e.dispose()}}}const ic=110,sc=40;function ac(t){return t.status==="completed"?{accent:"#16a34a",border:"rgba(34, 197, 94, 0.78)",glow:"rgba(34, 197, 94, 0.28)",background:"rgba(34, 197, 94, 0.12)",text:"已完成"}:t.status==="error"?{accent:"#ef4444",border:"rgba(239, 68, 68, 0.78)",glow:"rgba(239, 68, 68, 0.24)",background:"rgba(239, 68, 68, 0.12)",text:t.message.trim()==="已中断"?"已中断":"失败"}:{accent:Me.selectionBorder,border:Me.selectionBorder,glow:"rgba(0, 143, 93, 0.22)",background:"rgba(255, 255, 255, 0.22)",text:"修改中"}}function cc(t){const{tasks:e}=t;t.renderTick,t.onDismissTask;const n=e.map(r=>{const o=we(r.locator);if(!o||!o.isConnected||!(o instanceof HTMLElement))return null;const s=o.getBoundingClientRect();if(!Number.isFinite(s.left)||!Number.isFinite(s.top)||!Number.isFinite(s.width)||!Number.isFinite(s.height)||s.width<=0||s.height<=0)return null;const i=ac(r),a=window.getComputedStyle(o),l=a.borderRadius&&a.borderRadius!=="0px"?a.borderRadius:"inherit",m=r.status==="pending"||r.status==="created",P=s.width>ic&&s.height>sc,L=Math.max(48,Math.min(88,Math.round(s.height*.28)));return Re.jsxs("div",{style:{position:"fixed",left:s.left,top:s.top,width:s.width,height:s.height,borderRadius:l,overflow:"hidden",pointerEvents:m?"auto":"none",zIndex:10024},children:[Re.jsx("div",{style:{position:"absolute",inset:0,borderRadius:"inherit",border:m?`2px solid ${Me.selectionBorder}`:`1px solid ${i.border}`,boxShadow:m?"none":`0 0 0 1px ${i.border}, 0 12px 30px ${i.glow}`,background:i.background,backdropFilter:m?"blur(2px)":"blur(1px)"}}),m?Re.jsx("div",{style:{position:"absolute",inset:0,overflow:"hidden",borderRadius:"inherit"},children:Re.jsx("div",{className:"we-runtime-genie-task__scanner",style:{"--we-runtime-genie-task-accent":i.accent,"--we-runtime-genie-task-scan-size":`${L}px`}})}):null,P?Re.jsx("div",{style:{position:"absolute",inset:0,display:"flex",alignItems:"center",justifyContent:"center",color:i.accent,fontSize:14,fontWeight:500,lineHeight:1.2,letterSpacing:"0.02em",whiteSpace:"nowrap",pointerEvents:"none",textShadow:`0 1px 6px ${i.glow}`},children:Re.jsx("span",{children:i.text})}):null]},`${r.elementKey}:${r.requestId}`)}).filter(Boolean);return n.length===0?null:Re.jsx(Re.Fragment,{children:n})}function to(t,e,n){return!n&&t.dirty?{saved:e,draft:t.draft,dirty:t.draft!==e}:{saved:e,draft:e,dirty:!1}}function lc(){const t=de.useRef(null);return de.useEffect(()=>{const e=n=>{!Number.isFinite(n.clientX)||!Number.isFinite(n.clientY)||(t.current={clientX:n.clientX,clientY:n.clientY})};return window.addEventListener("pointermove",e,!0),window.addEventListener("mousemove",e,!0),window.addEventListener("pointerdown",e,!0),window.addEventListener("mousedown",e,!0),()=>{window.removeEventListener("pointermove",e,!0),window.removeEventListener("mousemove",e,!0),window.removeEventListener("pointerdown",e,!0),window.removeEventListener("mousedown",e,!0)}},[]),t}function uc(t){var I;const{propertyPanelOptions:e,setToolMinimized:n}=t,r=de.useRef(!1),o=de.useRef(new Set),s=de.useRef(new Set),i=de.useRef(null),a=de.useRef(!1),l=de.useRef(((I=e==null?void 0:e.getChangeMarkersVisible)==null?void 0:I.call(e))??!0),m=de.useCallback(()=>{var h;(h=e==null?void 0:e.onToggleSelectionMode)==null||h.call(e,!r.current&&!a.current&&o.current.size===0&&s.current.size===0)},[e]),P=de.useCallback(()=>!r.current&&!a.current&&o.current.size===0&&s.current.size===0,[]),L=de.useCallback((h,T)=>{if(i.current!==null&&(window.clearTimeout(i.current),i.current=null),T){o.current.add(h),m();return}if(o.current.delete(h),o.current.size>0){m();return}i.current=window.setTimeout(()=>{i.current=null,m()},80)},[m]),S=de.useCallback((h,T)=>{T?s.current.add(h):s.current.delete(h),m()},[m]),R=de.useCallback(h=>{var T,x,B,K,_,v;r.current!==h&&(r.current=h,h?(s.current.clear(),l.current=((T=e==null?void 0:e.getChangeMarkersVisible)==null?void 0:T.call(e))??!0,(x=e==null?void 0:e.onRequestClose)==null||x.call(e),(B=e==null?void 0:e.onChangeMarkersVisible)==null||B.call(e,!1,{persist:!1}),(K=e==null?void 0:e.onSelectionChromeVisibleChange)==null||K.call(e,!1)):(a.current=!1,(_=e==null?void 0:e.onChangeMarkersVisible)==null||_.call(e,l.current,{persist:!1}),(v=e==null?void 0:e.onSelectionChromeVisibleChange)==null||v.call(e,!0)),m(),n(h),mt()&&Wi())},[e,n,m]);return de.useEffect(()=>()=>{i.current!==null&&window.clearTimeout(i.current)},[]),{toolMinimizedRef:r,selectionHoverOwnersRef:o,selectionInteractionLockOwnersRef:s,selectionRestoreTimerRef:i,selectionNeedsExplicitReactivateRef:a,markerVisibilityBeforeMinimizeRef:l,syncSelectionModeAvailability:m,isSelectionModeActive:P,handlePanelHoverSelectionSuppressedChange:h=>L("panel",h),handlePromptHoverSelectionSuppressedChange:h=>L("prompt",h),handlePanelSelectionInteractionLockChange:h=>S("panel",h),handlePromptSelectionInteractionLockChange:h=>S("prompt",h),handleToolMinimizedChange:R}}function Un(t){return t instanceof HTMLElement?t.closest('input, textarea, select, button, [contenteditable=""], [contenteditable="true"]')instanceof HTMLElement?!0:t.isContentEditable:!1}function no(t){return String(t??"").replace(/\r\n/g,`
|
||
`).trim()}function ro(){if(typeof window>"u"||window.parent===window)return!1;try{return window.parent.location.origin===window.location.origin}catch{return!1}}function On(t){return t?t.tagName==="IFRAME":!1}const _t=3;function dc(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`img_${Date.now().toString(36)}_${Math.random().toString(36).slice(2,8)}`}function fc(t){const e=String(t??"").trim().toLowerCase();if(!e.startsWith("image/"))return"png";const n=e.slice(6).replace(/[^a-z0-9+.-]/g,"");return n?n==="jpeg"?"jpg":n==="svg+xml"?"svg":n:"png"}function hc(t,e,n){const r=String(t??"").trim();return r||`clipboard-image-${n+1}.${fc(e)}`}function mc(t){return new Promise((e,n)=>{const r=new FileReader;r.onerror=()=>n(r.error??new Error("blob-read-failed")),r.onload=()=>e(String(r.result??"")),r.readAsDataURL(t)})}async function hi(t,e=0,n){const r=String(t.type??"").trim()||"image/png";return{id:dc(),name:hc("name"in t&&typeof t.name=="string"?t.name:n,r,e),data:await mc(t),mimeType:r,size:Number(t.size??0),createdAt:Date.now()}}async function mi(t){if(!t)return[];const e=Array.from(t).filter(n=>n.kind==="file"&&String(n.type??"").startsWith("image/")).map(n=>n.getAsFile()).filter(n=>!!n);return Promise.all(e.map((n,r)=>hi(n,r)))}async function gc(t){if(!(t!=null&&t.length))return[];const e=await Promise.all(t.flatMap(n=>n.types.filter(r=>String(r??"").startsWith("image/")).map(async r=>({blob:await n.getType(r),type:r}))));return Promise.all(e.map(({blob:n},r)=>hi(n,r)))}function pc(t,e,n=_t){const r=t.slice(0,n),o=Math.max(0,n-r.length),s=e.slice(0,o);return{images:[...r,...s],acceptedCount:s.length,droppedCount:Math.max(0,e.length-s.length)}}function oo(t,e){return[String(t??"").trim(),String(e.mimeType??"").trim(),String(Number(e.size??0)),String(e.data??"").slice(0,96)].join("::")}const io=450;function yc(t){const{propertyPanelOptions:e,currentTargetRef:n,latestPointerPositionRef:r,isSelectionModeActive:o,selectionNeedsExplicitReactivateRef:s,onApplyImagesToElement:i}=t,a=de.useRef({hotkeyCount:0,pasteEventCount:0,tryApplyCount:0,lastResult:"idle",lastTextPreview:""}),l=de.useRef(new Map);return de.useEffect(()=>(window[Rr]={getState:()=>{var m,P,L,S,R,I,h,T,x,B,K;return{hasSameOriginParentWindow:ro(),isSelectionModeActive:o(),selectionNeedsExplicitReactivate:s.current,currentTargetTag:((m=n.current)==null?void 0:m.tagName)??null,currentTargetText:((S=(L=(P=n.current)==null?void 0:P.textContent)==null?void 0:L.trim())==null?void 0:S.slice(0,60))??null,hoveredElementTag:((I=(R=e==null?void 0:e.getHoveredElement)==null?void 0:R.call(e))==null?void 0:I.tagName)??null,hoveredElementText:((B=(x=(T=(h=e==null?void 0:e.getHoveredElement)==null?void 0:h.call(e))==null?void 0:T.textContent)==null?void 0:x.trim())==null?void 0:B.slice(0,60))??null,latestPointerPosition:r.current,pasteDebug:a.current,frameElementTag:((K=window.frameElement)==null?void 0:K.tagName)??null,frameElementTabIndex:On(window.frameElement)?window.frameElement.getAttribute("tabindex"):null,hasParentBridgeCleanup:On(window.frameElement)&&typeof window.frameElement[Ut]=="function"}}},()=>{delete window[Rr]}),[n,o,r,e,s]),de.useEffect(()=>{if(!(e!=null&&e.onAiNoteChange)||!e.getAiNote||!e.getHoveredElement)return;const{onAiNoteChange:m,getAiNote:P,getHoveredElement:L,onRememberSelectionAnchor:S}=e,R=ro(),I=W=>{const Z=[],re=ue=>{ue&&(Z.includes(ue)||Z.push(ue))};re(W),re(window);let fe=W;for(;;){let ue;try{ue=fe.parent}catch{break}if(!ue||ue===fe)break;try{if(ue.location.origin!==window.location.origin)break}catch{break}re(ue),fe=ue}return Z},h=async W=>{var re;const Z=I(W);for(const fe of Z){const ue=(re=fe.navigator)==null?void 0:re.clipboard;if(ue!=null&&ue.readText)try{const Ee=await ue.readText();if(typeof Ee=="string")return Ee}catch{continue}}throw new Error("clipboard-read-failed")},T=async W=>{var re;const Z=I(W);for(const fe of Z){const ue=(re=fe.navigator)==null?void 0:re.clipboard;if(ue!=null&&ue.read)try{const Ee=await ue.read(),Te=await gc(Ee);if(Te.length>0)return Te}catch{continue}}return[]},x=W=>W?!!(W.closest(`[${En}="true"]`)||W.closest('[data-we-selection-lock-root="true"]')):!1,B=W=>!(!W||!W.isConnected||Un(W)||x(W)),K=()=>{try{const W=document.querySelectorAll(":hover");if(W.length===0)return null;const Z=W.item(W.length-1);return Z&&B(Z)?Z:null}catch{return null}},_=()=>{const W=L();if(B(W))return W;const Z=r.current;if(Z){const ue=document.elementFromPoint(Z.clientX,Z.clientY);if(B(ue))return ue}const re=K();if(re)return re;const fe=document.activeElement;return fe instanceof Element&&B(fe)?fe:null},v=W=>{a.current.tryApplyCount+=1,a.current.lastTextPreview=String(W??"").slice(0,80);const Z=no(W),re=n.current,fe=o(),ue=_();if(re)return a.current.lastResult="blocked:current-target",!1;if(!fe)return a.current.lastResult="blocked:selection-inactive",!1;if(!Z)return a.current.lastResult="blocked:empty-text",!1;if(!(ue!=null&&ue.isConnected))return a.current.lastResult="blocked:no-hovered-element",!1;if(no(P(ue)))return a.current.lastResult="blocked:existing-note",!1;const Te=r.current;return Te?S==null||S(ue,Te):S==null||S(ue),a.current.lastResult="applied",a.current.lastTextPreview=Z.slice(0,80),m(ue,Z),!0},H=W=>{l.current.forEach((Z,re)=>{W-Z>io&&l.current.delete(re)})},q=async W=>{a.current.tryApplyCount+=1;const Z=n.current,re=o(),fe=_();if(Z)return a.current.lastResult="blocked:current-target",!1;if(!re)return a.current.lastResult="blocked:selection-inactive",!1;if(!W.length)return a.current.lastResult="blocked:empty-images",!1;if(!(fe!=null&&fe.isConnected))return a.current.lastResult="blocked:no-hovered-element",!1;if(!i)return a.current.lastResult="blocked:no-image-handler",!1;const ue=Se(fe),Ee=Ne(fe,ue.shadowHostChain),Te=Date.now();H(Te);const De=W.filter(te=>{const le=oo(Ee,te),ye=l.current.get(le);return!(typeof ye=="number"&&Te-ye<=io)});if(!De.length)return a.current.lastResult="blocked:duplicate-image",!1;const We=r.current;We?S==null||S(fe,We):S==null||S(fe);const Ue=await i(fe,De);return Ue.acceptedCount<=0?(a.current.lastResult="blocked:image-limit",!1):(De.slice(0,Ue.acceptedCount).forEach(te=>{l.current.set(oo(Ee,te),Te)}),a.current.lastResult="applied:image",!0)},Y=(W,Z)=>W instanceof Element&&Un(W)?!0:Un(Z.activeElement),F=(W,Z)=>{var fe;if(a.current.pasteEventCount+=1,W.defaultPrevented)return;if(Y(W.target,Z)){a.current.lastResult="blocked:editable-focus";return}const re=((fe=W.clipboardData)==null?void 0:fe.getData("text/plain"))??"";(async()=>{var Ee;const ue=await mi((Ee=W.clipboardData)==null?void 0:Ee.items);ue.length>0&&await q(ue),re.trim()&&v(re)})()},A=async(W,Z,re)=>{if(a.current.hotkeyCount+=1,!((W.metaKey||W.ctrlKey)&&!W.altKey&&(String(W.key).toLowerCase()==="v"||W.code==="KeyV"))){a.current.lastResult="blocked:not-paste-hotkey";return}if(Y(W.target,re)){a.current.lastResult="blocked:editable-focus";return}try{const ue=await T(Z);if(ue.length>0){await q(ue);return}const Ee=await h(Z);if(!v(Ee))return}catch{a.current.lastResult="blocked:clipboard-read-failed"}},X=W=>{A(W,window,document)},N=W=>{F(W,document)};if(document.addEventListener("paste",N,!0),window.addEventListener("keydown",X,!0),!R)return()=>{document.removeEventListener("paste",N,!0),window.removeEventListener("keydown",X,!0)};const b=window.parent,E=b.document,O=window.frameElement,d=On(O)?O:null,M=[];{let W=window;for(;;){let Z;try{Z=W.parent}catch{break}if(!Z||Z===W)break;try{if(Z.location.origin!==window.location.origin)break}catch{break}M.push(Z),W=Z}}if(!d)return()=>{document.removeEventListener("paste",N,!0),window.removeEventListener("keydown",X,!0)};let j=!1,ee=null;const oe=[],ie=d.hasAttribute("tabindex"),me=d.getAttribute("tabindex"),ce=()=>!o()||n.current?!1:E.activeElement!==d,pe=()=>!(j||window.parent!==b||window.frameElement!==d||!d.isConnected||d.contentWindow!==window),ge=()=>{if(!j){for(j=!0,ee==null||ee.disconnect(),ee=null;oe.length>0;){const W=oe.pop();W==null||W()}E.removeEventListener("paste",k,!0),b.removeEventListener("keydown",u,!0),b.removeEventListener("pointermove",U,!0),b.removeEventListener("mousemove",U,!0),b.removeEventListener("focus",g,!0),d.removeEventListener("pointermove",D,!0),d.removeEventListener("mousemove",D,!0),d.removeEventListener("pointerenter",y,!0),d.removeEventListener("mouseenter",y,!0),window.removeEventListener("pointermove",C,!0),window.removeEventListener("focus",G,!0),document.removeEventListener("visibilitychange",se),b.removeEventListener("pagehide",ge),window.removeEventListener("pagehide",ge),window.removeEventListener("beforeunload",ge),document.removeEventListener("paste",N,!0),window.removeEventListener("keydown",X,!0),d[Ut]===ge&&delete d[Ut],ie?me!==null&&d.setAttribute("tabindex",me):d.removeAttribute("tabindex")}},ae=()=>pe()?!0:(ge(),!1),V=()=>{if(ae()&&ce()){try{ie||d.setAttribute("tabindex","-1"),d.focus({preventScroll:!0})}catch{return}try{window.focus()}catch{}}},p=W=>{if(!ae()||!o()||n.current)return;const Z=d.getBoundingClientRect(),re=W.clientX-Z.left,fe=W.clientY-Z.top;if(!Number.isFinite(re)||!Number.isFinite(fe)||re<0||fe<0||re>Z.width||fe>Z.height)return;const ue=window.document.elementFromPoint(re,fe)??window.document.body;if(!ue)return;try{const Te=new PointerEvent("pointermove",{bubbles:!0,cancelable:!0,composed:!0,clientX:re,clientY:fe,pointerId:1,pointerType:"mouse",isPrimary:!0});ue.dispatchEvent(Te),window.document.dispatchEvent(Te),window.dispatchEvent(Te)}catch{}const Ee=new MouseEvent("mousemove",{bubbles:!0,cancelable:!0,composed:!0,clientX:re,clientY:fe,view:window});ue.dispatchEvent(Ee),window.document.dispatchEvent(Ee),window.dispatchEvent(Ee)},u=W=>{ae()&&(V(),A(W,window,document))},k=W=>{ae()&&F(W,E)},y=()=>{V()},D=W=>{p(W),V()},U=W=>{W.target===d&&(p(W),V())},C=()=>{V()},g=()=>{V()},G=()=>{V()},se=()=>{document.visibilityState==="visible"&&V()},J=d[Ut];return typeof J=="function"&&J(),d[Ut]=ge,ee=new MutationObserver(()=>{ae()}),ee.observe(E.documentElement,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["src"]}),V(),E.addEventListener("paste",k,!0),b.addEventListener("keydown",u,!0),M.filter(W=>W!==b).forEach(W=>{const Z=W.document,re=ue=>{ae()&&F(ue,Z)},fe=ue=>{ae()&&(V(),A(ue,window,document))};Z.addEventListener("paste",re,!0),W.addEventListener("keydown",fe,!0),oe.push(()=>{Z.removeEventListener("paste",re,!0),W.removeEventListener("keydown",fe,!0)})}),b.addEventListener("pointermove",U,!0),b.addEventListener("mousemove",U,!0),b.addEventListener("focus",g,!0),d.addEventListener("pointermove",D,!0),d.addEventListener("mousemove",D,!0),d.addEventListener("pointerenter",y,!0),d.addEventListener("mouseenter",y,!0),window.addEventListener("pointermove",C,!0),window.addEventListener("focus",G,!0),document.addEventListener("visibilitychange",se),b.addEventListener("pagehide",ge),window.addEventListener("pagehide",ge),window.addEventListener("beforeunload",ge),ge},[n,o,r,i,e]),a}function so(t){return typeof Element<"u"&&t instanceof Element}function bc(t){const{event:e,selectionInteractionLockOwnersRef:n,selectionHoverOwnersRef:r,selectionNeedsExplicitReactivateRef:o,syncSelectionModeAvailability:s}=t;if(n.current.size===0&&!o.current)return!1;const i=typeof e.composedPath=="function"?e.composedPath():[];return i.some(m=>so(m)&&(m.hasAttribute(En)||m.closest(`[${En}="true"]`)))||i.some(m=>so(m)&&(m.getAttribute("data-we-selection-lock-root")==="true"||m.closest('[data-we-selection-lock-root="true"]')))?!1:(e.preventDefault(),r.current.clear(),n.current.clear(),o.current=!1,s(),!0)}function wc(t){const{selectionInteractionLockOwnersRef:e,selectionHoverOwnersRef:n,selectionNeedsExplicitReactivateRef:r,syncSelectionModeAvailability:o}=t;de.useEffect(()=>{const s=i=>{bc({event:i,selectionInteractionLockOwnersRef:e,selectionHoverOwnersRef:n,selectionNeedsExplicitReactivateRef:r,syncSelectionModeAvailability:o})};return window.addEventListener("pointerdown",s,!0),()=>{window.removeEventListener("pointerdown",s,!0)}},[n,e,r,o])}function Sc(t,e,n){const r=Number.isFinite(t.selectionStart??NaN)?t.selectionStart??e.length:e.length,o=Number.isFinite(t.selectionEnd??NaN)?t.selectionEnd??e.length:e.length;return e.slice(0,r)+n+e.slice(o)}function Ec(t){var We,Ue;const{propertyPanelOptions:e,breadcrumbsOptions:n,propertyPanelRef:r,breadcrumbsRef:o,onThemeModeChange:s}=t,i=((We=e==null?void 0:e.getUiMode)==null?void 0:We.call(e))??(e==null?void 0:e.initialUiMode)??"bubble-card",a=(e==null?void 0:e.interactionProfile)??"design",[l,m]=de.useState(null),[P,L]=de.useState(null),[S,R]=de.useState(i),[I,h]=de.useState(!1),[T,x]=de.useState(()=>{var te;return qr(nn(Lt(((te=e==null?void 0:e.getUiSettings)==null?void 0:te.call(e))??wt),a))}),[B,K]=de.useState(()=>{var te;return nn(Lt(((te=e==null?void 0:e.getUiSettings)==null?void 0:te.call(e))??wt),a).genieAwake?"awake":"sleeping"}),[_,v]=de.useState({savedNote:"",draftNote:"",noteDirty:!1}),[H,q]=de.useState({savedText:"",draftText:"",textDirty:!1}),[Y,F]=de.useState({images:[]}),A=de.useRef(null),X=de.useRef(i),N=de.useRef(_),b=de.useRef(H),E=de.useRef(Y),O=lc(),d=uc({propertyPanelOptions:e,setToolMinimized:h});Xi(),de.useEffect(()=>{N.current=_},[_]),de.useEffect(()=>{b.current=H},[H]),de.useEffect(()=>{E.current=Y},[Y]),de.useEffect(()=>{var le;const te=(le=e==null?void 0:e.getUiMode)==null?void 0:le.call(e);!te||X.current===te||(X.current=te,R(te))}),de.useEffect(()=>{s==null||s(T.darkMode?"dark":"light")},[s,T.darkMode]),de.useEffect(()=>{const te=T.genieAwake?"awake":"sleeping";K(le=>le===te?le:te)},[T.genieAwake]),de.useEffect(()=>{d.toolMinimizedRef.current=I},[d.toolMinimizedRef,I]);const M=de.useMemo(()=>({getCurrentTask:te=>{var le,ye;return((le=e==null?void 0:e.getElementGenieTaskState)==null?void 0:le.call(e,te))??((ye=n==null?void 0:n.getElementGenieTaskState)==null?void 0:ye.call(n,te))??null},getVisibleTasks:()=>{var te,le;return((te=e==null?void 0:e.getVisibleElementGenieTaskStates)==null?void 0:te.call(e))??((le=n==null?void 0:n.getVisibleElementGenieTaskStates)==null?void 0:le.call(n))??[]},dismissTask:te=>{var le,ye;(le=e==null?void 0:e.dismissElementGenieTaskState)==null||le.call(e,te),(ye=n==null?void 0:n.dismissElementGenieTaskState)==null||ye.call(n,te)}}),[n,e]),[j,ee]=de.useState(0);de.useEffect(()=>{let te="";const le=window.setInterval(()=>{const ye=M.getVisibleTasks(),ke=ye.map(ve=>[ve.elementKey,ve.requestId,ve.status,ve.sessionId??"",ve.updatedAt,ve.dismissed?"1":"0"].join(":")).join("|");(ye.length>0||ke!==te)&&ee(ve=>ve+1),te=ke},120);return()=>{window.clearInterval(le)}},[M]);const oe=de.useCallback((te,le)=>{var ke;const ye=((ke=e==null?void 0:e.getAiNote)==null?void 0:ke.call(e,te))??"";v(ve=>{const qe=to({saved:ve.savedNote,draft:ve.draftNote,dirty:ve.noteDirty},ye,le);return{savedNote:qe.saved,draftNote:qe.draft,noteDirty:qe.dirty}})},[e]),ie=de.useCallback((te,le)=>{var ve,qe;const ke=((ve=e==null?void 0:e.canEditText)==null?void 0:ve.call(e,te))??!1?((qe=e==null?void 0:e.getTextValue)==null?void 0:qe.call(e,te))??"":"";q(Et=>{const Ge=to({saved:Et.savedText,draft:Et.draftText,dirty:Et.textDirty},ke,le);return{savedText:Ge.saved,draftText:Ge.draft,textDirty:Ge.dirty}})},[e]),me=de.useCallback(te=>{var le;F({images:(((le=e==null?void 0:e.getAiNoteImages)==null?void 0:le.call(e,te))??[]).slice(0,_t)})},[e]),ce=de.useCallback(async te=>{const le=te??A.current;if(!le||!(e!=null&&e.onAiNoteChange)||!N.current.noteDirty)return!1;const ye=N.current.draftNote;return await e.onAiNoteChange(le,ye),A.current===le&&v({savedNote:ye,draftNote:ye,noteDirty:!1}),!0},[e]),pe=de.useCallback(async te=>{var ke;const le=te??A.current;if(!le||!(e!=null&&e.onTextValueChange)||!(((ke=e==null?void 0:e.canEditText)==null?void 0:ke.call(e,le))??!1)||!b.current.textDirty)return!1;const ye=b.current.draftText;return await e.onTextValueChange(le,ye),A.current===le&&q({savedText:ye,draftText:ye,textDirty:!1}),!0},[e]),ge=de.useCallback(te=>{if(A.current===te)return;const le=A.current;le&&N.current.noteDirty&&ce(le),le&&b.current.textDirty&&pe(le),A.current=te,m(te),(!te||!te.isConnected)&&L(null),d.selectionNeedsExplicitReactivateRef.current=!!(te&&!d.toolMinimizedRef.current),d.syncSelectionModeAvailability(),oe(te,!0),ie(te,!0),me(te)},[ce,pe,d,me,oe,ie]),ae=de.useCallback(te=>{L(te)},[]),V=de.useCallback(te=>{var le,ye;X.current!==te&&(X.current=te,R(te),(le=e==null?void 0:e.onUiModeChange)==null||le.call(e,te),(ye=e==null?void 0:e.onSelectionChromeVisibleChange)==null||ye.call(e,!d.toolMinimizedRef.current))},[e,d.toolMinimizedRef]),p=de.useCallback(()=>{oe(A.current,!1),ie(A.current,!1),me(A.current)},[me,oe,ie]),u=de.useCallback(te=>{var ye;const le=qr(nn(Lt(te),a));x(le),(ye=e==null?void 0:e.onUiSettingsChange)==null||ye.call(e,le)},[a,e]),k=de.useCallback(te=>{K(te),x(le=>{var ve;const ye=te==="awake";if(le.genieAwake===ye)return le;const ke=nn(Lt({...le,genieAwake:ye}),a);return(ve=e==null?void 0:e.onUiSettingsChange)==null||ve.call(e,ke),ke})},[a,e]),y=M.getCurrentTask(l),D=(y==null?void 0:y.status)==="pending"||(y==null?void 0:y.status)==="created",U=!!(e!=null&&e.onAiNoteChange),C=!!(l&&((Ue=e==null?void 0:e.canEditText)!=null&&Ue.call(e,l))&&(e!=null&&e.onTextValueChange)&&!D),g=de.useCallback(te=>{v(le=>({...le,draftNote:te,noteDirty:te!==le.savedNote}))},[]),G=de.useCallback(()=>{v(te=>({...te,draftNote:te.savedNote,noteDirty:!1}))},[]),se=de.useCallback(async()=>{await ce()},[ce]),J=de.useCallback(te=>{q(le=>({...le,draftText:te,textDirty:te!==le.savedText}))},[]),W=de.useCallback(()=>{q(te=>({...te,draftText:te.savedText,textDirty:!1}))},[]),Z=de.useCallback(async()=>{await pe()},[pe]),re=de.useCallback(async te=>{const le=A.current;if(!le||!(e!=null&&e.onAiNoteImagesChange))return;const ye=te.slice(0,_t);await e.onAiNoteImagesChange(le,ye),A.current===le&&F({images:ye.slice()})},[e]),fe=de.useCallback(async te=>{const le=E.current.images.filter(ye=>ye.id!==te);await re(le)},[re]),ue=de.useCallback(async(te,le)=>{var ve;if(!le.length||!(e!=null&&e.onAiNoteImagesChange))return{acceptedCount:0,droppedCount:0};if(e.getGenieBridgeConnected&&!e.getGenieBridgeConnected())return Pr("info","Genie 未启动,暂不支持粘贴标注图片。"),{acceptedCount:0,droppedCount:le.length};const ye=(((ve=e.getAiNoteImages)==null?void 0:ve.call(e,te))??[]).slice(0,_t),ke=pc(ye,le,_t);return await e.onAiNoteImagesChange(te,ke.images),A.current===te&&F({images:ke.images.slice()}),ke.droppedCount>0&&Pr("info",`最多允许 ${_t} 张图片,已忽略多余图片。`),{acceptedCount:ke.acceptedCount,droppedCount:ke.droppedCount}},[e]),Ee=de.useCallback(te=>{var Ge,Nt;const le=A.current;if(!le||!(e!=null&&e.onAiNoteImagesChange))return;const ye=(Ge=te.clipboardData)==null?void 0:Ge.items;if(!(ye!=null&&ye.length)||!Array.from(ye).some(Ze=>Ze.kind==="file"&&String(Ze.type??"").startsWith("image/")))return;const ve=((Nt=te.clipboardData)==null?void 0:Nt.getData("text/plain"))??"",qe=te.target instanceof HTMLTextAreaElement?te.target:null,Et=N.current.draftNote;te.preventDefault(),te.stopPropagation(),(async()=>{const Ze=await mi(ye);if(Ze.length){if(qe&&ve){const Yt=Sc(qe,Et,ve);v(He=>({...He,draftNote:Yt,noteDirty:Yt!==He.savedNote}))}await ue(le,Ze)}})()},[ue,e]),Te=de.useCallback(async()=>{var ye;const te=A.current;!te||!(e!=null&&e.onClearCurrentElementEdits)||!await e.onClearCurrentElementEdits(te)||(oe(te,!0),ie(te,!0),me(te),(ye=e.onDismissSelection)==null||ye.call(e))},[e,me,oe,ie]),De=de.useMemo(()=>{if(e!=null&&e.onSendCurrentElementPromptToGenie)return async te=>{var le;await pe(te),await ce(te),await((le=e.onSendCurrentElementPromptToGenie)==null?void 0:le.call(e,te))}},[ce,pe,e]);return yc({propertyPanelOptions:e,currentTargetRef:A,latestPointerPositionRef:O,isSelectionModeActive:d.isSelectionModeActive,selectionNeedsExplicitReactivateRef:d.selectionNeedsExplicitReactivateRef,onApplyImagesToElement:ue}),wc({selectionInteractionLockOwnersRef:d.selectionInteractionLockOwnersRef,selectionHoverOwnersRef:d.selectionHoverOwnersRef,selectionNeedsExplicitReactivateRef:d.selectionNeedsExplicitReactivateRef,syncSelectionModeAvailability:d.syncSelectionModeAvailability}),Re.jsxs("div",{style:Yi,children:[Re.jsx("style",{children:ji}),Re.jsx(cc,{tasks:M.getVisibleTasks(),onDismissTask:M.dismissTask,renderTick:j}),n?Re.jsx(Ji,{ref:o,options:n,currentTarget:l,anchorRect:P,uiMode:S,interactionProfile:a,designAdjustmentTool:T.designAdjustmentTool,toolMinimized:I,propertyPanelEnabled:!!e,styleDesignEnabled:T.styleDesignEnabled,genieVisualState:B,onSendCurrentElementPromptToGenie:De,getGenieBridgeConnected:e==null?void 0:e.getGenieBridgeConnected,getHasReusableGenieConversation:e==null?void 0:e.getHasReusableGenieConversation,getSendCurrentElementPromptToGenieBlockReason:e==null?void 0:e.getSendCurrentElementPromptToGenieBlockReason,canExportSelectionToDesignTool:e==null?void 0:e.canExportSelectionToDesignTool,onExportSelectionToDesignTool:e==null?void 0:e.onExportSelectionToDesignTool,getExportSelectionToDesignToolBlockReason:e==null?void 0:e.getExportSelectionToDesignToolBlockReason,onHoverSelectionSuppressedChange:d.handlePromptHoverSelectionSuppressedChange,onSelectionInteractionLockChange:d.handlePromptSelectionInteractionLockChange,onUiModeChange:V,onTargetChange:ge,onAnchorRectChange:ae,onPromptCardVisibleChange:e==null?void 0:e.onPromptCardVisibleChange,canEditText:C,images:Y.images,onImagesChange:re,onRemoveImage:fe,onNotePasteCapture:Ee,savedText:H.savedText,draftText:H.draftText,textDirty:H.textDirty,onTextDraftChange:J,onCancelText:W,onConfirmText:Z,canEditNote:U,savedNote:_.savedNote,draftNote:_.draftNote,noteDirty:_.noteDirty,onDraftChange:g,onClearCurrentElementEdits:Te,onCancelNote:G,onConfirmNote:se,onDismissSelection:e==null?void 0:e.onDismissSelection}):null,e?Re.jsx(Qi,{ref:r,options:e,currentTarget:l,uiMode:S,toolMinimized:I,uiSettings:T,interactionProfile:a,genieVisualState:B,onGenieVisualStateChange:k,onUiSettingsChange:u,onHoverSelectionSuppressedChange:d.handlePanelHoverSelectionSuppressedChange,onSelectionInteractionLockChange:d.handlePanelSelectionInteractionLockChange,onUiModeChange:V,onToolMinimizedChange:d.handleToolMinimizedChange,onTargetChange:ge,onRefreshNoteState:p,canEditText:C,images:Y.images,onImagesChange:re,onRemoveImage:fe,onNotePasteCapture:Ee,savedText:H.savedText,draftText:H.draftText,textDirty:H.textDirty,onTextDraftChange:J,onCancelText:W,onConfirmText:Z,canEditNote:U,savedNote:_.savedNote,draftNote:_.draftNote,noteDirty:_.noteDirty,onDraftChange:g,onClearCurrentElementEdits:Te,onCancelNote:G,onConfirmNote:se,onDismissSelection:e==null?void 0:e.onDismissSelection}):null]})}function ao(t){const e=[];return{runOrQueue(n){const r=t();if(r){n(r);return}e.push(n)},flush(){const n=t();if(n)for(;e.length>0;){const r=e.shift();r==null||r(n)}}}}function vc(t){const e={position:t.container.style.position,inset:t.container.style.inset,top:t.container.style.top,right:t.container.style.right,bottom:t.container.style.bottom,left:t.container.style.left,width:t.container.style.width,height:t.container.style.height,pointerEvents:t.container.style.pointerEvents};t.container.style.position="fixed",t.container.style.inset="0",t.container.style.top="0",t.container.style.right="0",t.container.style.bottom="0",t.container.style.left="0",t.container.style.width="auto",t.container.style.height="auto",t.container.style.pointerEvents="none";const n=document.createElement("div");n.style.position="fixed",n.style.pointerEvents="none",n.style.background="transparent",mt()?(n.style.top="0",n.style.left="0",n.style.width="0",n.style.height="0",n.style.overflow="visible"):n.style.inset="0",t.container.append(n);const r=rs(n),o=de.createRef(),s=de.createRef();let i=!1;const a=()=>{i||(i=!0,r.unmount(),n.remove(),t.container.style.position=e.position,t.container.style.inset=e.inset,t.container.style.top=e.top,t.container.style.right=e.right,t.container.style.bottom=e.bottom,t.container.style.left=e.left,t.container.style.width=e.width,t.container.style.height=e.height,t.container.style.pointerEvents=e.pointerEvents)},l=t.propertyPanelOptions?ao(()=>o.current):null,m=t.breadcrumbsOptions?ao(()=>s.current):null;function P(){const L=de.useMemo(()=>os(),[]),S=de.useRef(null),[R,I]=de.useState(()=>{var h,T,x;return(x=(T=(h=t.propertyPanelOptions)==null?void 0:h.getUiSettings)==null?void 0:T.call(h))!=null&&x.darkMode?"dark":"light"});return de.useEffect(()=>{l==null||l.flush(),m==null||m.flush()}),Re.jsx(is,{cache:L,container:t.shadowRoot,children:Re.jsx(ss,{componentSize:"small",getPopupContainer:()=>S.current??t.container,theme:Zi(R),children:Re.jsx(as,{children:Re.jsxs("div",{style:{position:"fixed",inset:0,pointerEvents:"none",...es(R)},children:[Re.jsx(Ec,{propertyPanelOptions:t.propertyPanelOptions,breadcrumbsOptions:t.breadcrumbsOptions,propertyPanelRef:o,breadcrumbsRef:s,onThemeModeChange:I}),Re.jsx("div",{ref:S,[En]:"true"})]})})})})}return r.render(Re.jsx(P,{})),{propertyPanel:l?{setTarget(L){l.runOrQueue(S=>S.setTarget(L))},setTab(L){l.runOrQueue(S=>S.setTab(L))},getTab(){var L;return((L=o.current)==null?void 0:L.getTab())??"design"},refresh(){l.runOrQueue(L=>L.refresh())},setHistory(L,S){l.runOrQueue(R=>R.setHistory(L,S))},getPosition(){var L;return((L=o.current)==null?void 0:L.getPosition())??null},setPosition(L){l.runOrQueue(S=>S.setPosition(L))},enterAnnotationInput(L){l.runOrQueue(S=>{var R;return(R=S.enterAnnotationInput)==null?void 0:R.call(S,L)})},dispose:a}:null,breadcrumbs:m?{setTarget(L){m.runOrQueue(S=>S.setTarget(L))},setAnchorRect(L){m.runOrQueue(S=>S.setAnchorRect(L))},refresh(){m.runOrQueue(L=>L.refresh())},dispose:a}:null,dispose:a}}const co="data-mcp-canvas",lo="overlay",Tc=100,Cc=2600,qn={hover:{strokeColor:Me.hover,fillColor:`${Me.hover}15`,lineWidth:2,dashPattern:[6,4]},selection:{strokeColor:Me.selected,fillColor:"transparent",lineWidth:2,dashPattern:[]},dragGhost:{strokeColor:Me.selectionBorder,fillColor:Me.dragGhost,lineWidth:2,dashPattern:[8,6]}};function uo(t){return Number.isFinite(t)&&t>0}function Pt(t){return t?Number.isFinite(t.left)&&Number.isFinite(t.top)&&uo(t.width)&&uo(t.height):!1}function rn(t){return t?Number.isFinite(t.x1)&&Number.isFinite(t.y1)&&Number.isFinite(t.x2)&&Number.isFinite(t.y2):!1}function on(t,e,n){return Number.isFinite(t)?Math.min(n,Math.max(e,t)):e}function fo(t){return 1-Math.pow(1-t,3)}function sn(t,e,n){return t+(e-t)*n}function ho(t,e,n){return{left:sn(t.left,e.left,n),top:sn(t.top,e.top,n),width:sn(t.width,e.width,n),height:sn(t.height,e.height,n)}}function mo(t,e,n,r,o,s){const i=Math.max(0,Math.min(s,Math.min(r,o)/2));t.moveTo(e+i,n),t.arcTo(e+r,n,e+r,n+o,i),t.arcTo(e+r,n+o,e,n+o,i),t.arcTo(e,n+o,e,n,i),t.arcTo(e,n,e+r,n,i),t.closePath()}function xc(t){const{container:e}=t,n=new ze,r=e.querySelector(`canvas[${co}="${lo}"]`);r&&r.remove();const o=document.createElement("canvas");o.setAttribute(co,lo),o.setAttribute("aria-hidden","true"),Object.assign(o.style,{position:"absolute",inset:"0",width:"100%",height:"100%",pointerEvents:"none",display:"block"}),e.append(o),n.add(()=>o.remove());const s=o.getContext("2d",{alpha:!0,desynchronized:!0});if(!s)throw n.dispose(),new Error(`${Ke} Failed to get canvas 2D context`);const i=s;let a=null,l=null,m=null,P="default",L=null,S=null,R=null,I=null,h=null,T=null,x=1,B=1,K=1,_=!0,v=null;function H(){const y=document.createElement("div");y.setAttribute("data-we-ai-selection-effect","true"),Object.assign(y.style,{position:"absolute",pointerEvents:"none",display:"none",overflow:"hidden",borderRadius:"0",border:`2px solid ${Me.selected}`,boxShadow:"none",backdropFilter:"blur(2px)",WebkitBackdropFilter:"blur(2px)",background:"rgba(255, 255, 255, 0.22)",zIndex:"1"});const D=document.createElement("div");Object.assign(D.style,{position:"absolute",left:"0",top:"0",width:"100%",height:"72px",background:"linear-gradient(to bottom, rgba(0, 143, 93, 0), rgba(0, 143, 93, 0.08) 28%, rgba(0, 143, 93, 0.18) 50%, rgba(0, 143, 93, 0.08) 72%, rgba(0, 143, 93, 0))",display:"flex",alignItems:"center",justifyContent:"center",willChange:"transform"});const U=document.createElement("div");return Object.assign(U.style,{width:"100%",height:"1px",background:"rgba(0, 143, 93, 0.62)",boxShadow:"0 0 12px rgba(0, 143, 93, 0.58)"}),D.append(U),y.append(D),e.append(y),{root:y,sweep:D,animation:null,animationKey:""}}const q=[];n.add(()=>{var y;for(const D of q)(y=D.animation)==null||y.cancel(),D.root.remove()});function Y(y){var D;for(;q.length<y;)q.push(H());for(;q.length>y;){const U=q.pop();if(!U)break;(D=U.animation)==null||D.cancel(),U.root.remove()}}function F(){v!==null&&(cancelAnimationFrame(v),v=null)}n.add(F);function A(){v!==null||n.isDisposed||(v=requestAnimationFrame(()=>{v=null,oe()}))}function X(){const y=Math.max(1,window.devicePixelRatio||1),D=Math.max(1,x),U=Math.max(1,B),C=Math.round(D*y),g=Math.round(U*y);return o.width!==C||o.height!==g||Math.abs(K-y)>.001?(K=y,o.width=C,o.height=g,i.setTransform(K,0,0,K,0,0),i.lineJoin="round",i.lineCap="round",!0):!1}function N(){X(),i.clearRect(0,0,x,B)}function b(y,D){if(!Pt(y))return;const U=Math.round(y.width),C=Math.round(y.height);if(U<=0||C<=0)return;const g=Math.round(y.left)+.5,G=Math.round(y.top)+.5;i.save(),i.lineWidth=D.lineWidth,i.strokeStyle=D.strokeColor,i.fillStyle=D.fillColor,i.setLineDash(D.dashPattern),i.beginPath(),i.rect(g,G,U,C),i.fill(),i.stroke(),i.restore()}function E(){var D;const y=[];if(P==="ai-editing"&&Pt(m)&&y.push(m),L!=null&&L.length)for(const U of L)Pt(U)&&y.push(U);if(Y(y.length),y.length===0){for(const U of q)U.root.style.display="none",(D=U.animation)==null||D.pause();return}y.forEach((U,C)=>{var Z;const g=q[C],G=Math.max(1,Math.round(U.width)),se=Math.max(1,Math.round(U.height)),J=Math.max(48,Math.min(88,Math.round(se*.28)));g.root.style.display="block",g.root.style.left=`${Math.round(U.left)}px`,g.root.style.top=`${Math.round(U.top)}px`,g.root.style.width=`${G}px`,g.root.style.height=`${se}px`,g.sweep.style.height=`${J}px`;const W=`${se}:${J}`;(g.animationKey!==W||!g.animation)&&((Z=g.animation)==null||Z.cancel(),g.animationKey=W,g.animation=g.sweep.animate([{transform:`translateY(-${J}px)`},{transform:`translateY(${se}px)`}],{duration:Cc,iterations:1/0,easing:"linear"})),g.animation.play()})}function O(y){if(!rn(y))return;i.save(),i.lineWidth=fs,i.strokeStyle=Me.insertionLine,i.setLineDash([]),i.lineCap="round";const D=Math.round(y.x1)+.5,U=Math.round(y.y1)+.5,C=Math.round(y.x2)+.5,g=Math.round(y.y2)+.5;i.beginPath(),i.moveTo(D,U),i.lineTo(C,g),i.stroke(),i.restore()}function d(y){if(!(!y||y.length===0)){i.save(),i.lineWidth=ps,i.strokeStyle=Me.guideLine,i.setLineDash([]),i.lineCap="round",i.beginPath();for(const D of y){if(!rn(D))continue;const U=Math.round(D.x1)+.5,C=Math.round(D.y1)+.5,g=Math.round(D.x2)+.5,G=Math.round(D.y2)+.5;i.moveTo(U,C),i.lineTo(g,G)}i.stroke(),i.restore()}}function M(y){if(!y||y.length===0)return;i.save(),i.lineWidth=bs,i.strokeStyle=Me.guideLine,i.setLineDash([]),i.lineCap="round";const D=ws;i.beginPath();for(const U of y){const C=U.line;if(!rn(C))continue;const g=Math.round(C.x1)+.5,G=Math.round(C.y1)+.5,se=Math.round(C.x2)+.5,J=Math.round(C.y2)+.5;i.moveTo(g,G),i.lineTo(se,J),U.axis==="x"?(i.moveTo(g,G-D),i.lineTo(g,G+D),i.moveTo(se,J-D),i.lineTo(se,J+D)):(i.moveTo(g-D,G),i.lineTo(g+D,G),i.moveTo(se-D,J),i.lineTo(se+D,J))}i.stroke(),i.font=Ss,i.textAlign="center",i.textBaseline="middle";for(const U of y){const C=U.line;if(!rn(C))continue;const g=i.measureText(U.text),G=g.width,se=Number.isFinite(g.actualBoundingBoxAscent)?g.actualBoundingBoxAscent:8,J=Number.isFinite(g.actualBoundingBoxDescent)?g.actualBoundingBoxDescent:3,W=se+J,Z=Math.ceil(G+Es*2),re=Math.ceil(W+vs*2),fe=(C.x1+C.x2)/2,ue=(C.y1+C.y2)/2,Ee=Cs;let Te=fe-Z/2,De=ue-re/2;U.axis==="x"?(De=ue-re/2-Ee,De<0&&(De=ue+Ee-re/2)):(Te=fe+Ee-Z/2,Te+Z>x&&(Te=fe-Ee-Z/2));const We=Math.max(2,x-Z-2),Ue=Math.max(2,B-re-2);Te=on(Te,2,We),De=on(De,2,Ue),i.save(),i.fillStyle=Me.distanceLabelBg,i.strokeStyle=Me.distanceLabelBorder,i.lineWidth=1,i.beginPath(),mo(i,Te,De,Z,re,Ts),i.fill(),i.stroke(),i.fillStyle=Me.distanceLabelText,i.fillText(U.text,Te+Z/2,De+re/2),i.restore()}i.restore()}function j(y){if(!(!y||y.length===0)){i.save(),i.fillStyle=`${Me.selected}25`,i.strokeStyle="transparent";for(const D of y){if(!Pt(D))continue;const U=Math.round(D.left),C=Math.round(D.top),g=Math.round(D.width),G=Math.round(D.height);i.beginPath(),mo(i,U,C,g,G,2),i.fill()}i.restore()}}function ee(){n.isDisposed||(_=!0,A())}function oe(){if(n.isDisposed||!_)return;F(),_=!1;const y=performance.now();let D=a;if(l){const U=y-l.startTime,C=on(U/l.durationMs,0,1),g=fo(C);D=ho(l.start,l.end,g),C>=1?l=null:_=!0}N(),j(T),b(D,qn.hover),P!=="ai-editing"&&b(m,qn.selection),b(S,qn.dragGhost),O(R),d(I),M(h),E(),_&&A()}function ie(y,D){if(!((D==null?void 0:D.animate)===!0)){l=null,a=y,ee();return}const C=performance.now();let g=a;if(l){const G=C-l.startTime,se=on(G/l.durationMs,0,1),J=fo(se);g=ho(l.start,l.end,J)}if(!Pt(g)||!Pt(y)){l=null,a=y,ee();return}l={start:{...g},end:{...y},startTime:C,durationMs:Tc},a=y,ee()}function me(y){m=y,E(),ee()}function ce(y){P!==y&&(P=y,E(),ee())}function pe(y){L=y&&y.length>0?y:null,E(),ee()}function ge(y){S=y,ee()}function ae(y){R=y,ee()}function V(y){I=y&&y.length>0?y:null,ee()}function p(y){h=y&&y.length>0?y:null,ee()}function u(y){T=y&&y.length>0?y:null,ee()}function k(){a=null,l=null,m=null,P="default",L=null,T=null,E(),S=null,R=null,I=null,h=null,ee()}try{const y=e.getBoundingClientRect();x=Math.max(1,y.width),B=Math.max(1,y.height)}catch(y){console.warn(`${Ke} Initial size measurement failed:`,y)}return n.observeResize(e,y=>{const D=y[0],U=D==null?void 0:D.contentRect;if(!U)return;const C=Math.max(1,U.width),g=Math.max(1,U.height);Math.abs(C-x)<.5&&Math.abs(g-B)<.5||(x=C,B=g,ee())}),ee(),{canvas:o,markDirty:ee,render:oe,clear:k,setHoverRect:ie,setSelectionRect:me,setSelectionEffect:ce,setEditingRects:pe,setTextHighlightRects:u,setDragGhostRect:ge,setInsertionLine:ae,setGuideLines:V,setDistanceLabels:p,dispose:()=>n.dispose()}}function Be(t){return typeof t=="number"&&Number.isFinite(t)}function mr(t){return t?Be(t.left)&&Be(t.top)&&Be(t.width)&&Be(t.height)&&t.width>.5&&t.height>.5:!1}function Gn(t){try{const e=t.getBoundingClientRect(),n={left:e.left,top:e.top,width:e.width,height:e.height};return mr(n)?n:null}catch{return null}}function je(t){return t.left+t.width}function Je(t){return t.top+t.height}function Dt(t){return t.left+t.width/2}function Bt(t){return t.top+t.height/2}function gi(t,e){switch(e){case"left":return t.left;case"center":return Dt(t);case"right":return je(t)}}function pi(t,e){switch(e){case"top":return t.top;case"middle":return Bt(t);case"bottom":return Je(t)}}function go(){return{x:[],y:[]}}function Ac(t){const e=t.parentElement;if(!e)return go();const n=Gn(t),r=n?Dt(n):0,o=n?Bt(n):0,s=e.children,i=s.length;let a=-1;for(let h=0;h<i;h++)if(s[h]===t){a=h;break}if(a===-1)return go();const l=[];let m=0,P=1,L=1;for(;m<Lr;){const h=a-P,T=a+L,x=h>=0,B=T<i;if(!x&&!B)break;if(x){const K=s[h],_=Gn(K);if(_){const v=Dt(_)-r,H=Bt(_)-o;l.push({rect:_,distanceSquared:v*v+H*H})}m++,P++}if(B&&m<Lr){const K=s[T],_=Gn(K);if(_){const v=Dt(_)-r,H=Bt(_)-o;l.push({rect:_,distanceSquared:v*v+H*H})}m++,L++}}l.sort((h,T)=>h.distanceSquared-T.distanceSquared);const S=l.slice(0,gs),R=[],I=[];for(const{rect:h}of S)R.push({type:"left",value:h.left,source:"sibling",sourceRect:h}),R.push({type:"center",value:Dt(h),source:"sibling",sourceRect:h}),R.push({type:"right",value:je(h),source:"sibling",sourceRect:h}),I.push({type:"top",value:h.top,source:"sibling",sourceRect:h}),I.push({type:"middle",value:Bt(h),source:"sibling",sourceRect:h}),I.push({type:"bottom",value:Je(h),source:"sibling",sourceRect:h});return{x:R,y:I}}function Ic(){const t=Math.max(1,window.innerWidth||1),e=Math.max(1,window.innerHeight||1);return{x:[{type:"left",value:0,source:"viewport"},{type:"center",value:t/2,source:"viewport"},{type:"right",value:t,source:"viewport"}],y:[{type:"top",value:0,source:"viewport"},{type:"middle",value:e/2,source:"viewport"},{type:"bottom",value:e,source:"viewport"}]}}function kc(...t){const e=[],n=[];for(const r of t)e.push(...r.x),n.push(...r.y);return{x:e,y:n}}function or(t,e,n,r,o){const s=t.left,i=je(t);if(e==="left"){if(n==="right"){const a=r-s;return!Be(a)||a<o?null:{left:s,top:t.top,width:a,height:t.height}}if(n==="center"){const a=(r-s)*2;return!Be(a)||a<o?null:{left:s,top:t.top,width:a,height:t.height}}return t}if(e==="right"){if(n==="left"){const a=i-r;return!Be(a)||a<o?null:{left:r,top:t.top,width:a,height:t.height}}if(n==="center"){const a=2*r-i,l=i-a;return!Be(l)||l<o?null:{left:a,top:t.top,width:l,height:t.height}}return t}return t}function ir(t,e,n,r,o){const s=t.top,i=Je(t);if(e==="top"){if(n==="bottom"){const a=r-s;return!Be(a)||a<o?null:{left:t.left,top:s,width:t.width,height:a}}if(n==="middle"){const a=(r-s)*2;return!Be(a)||a<o?null:{left:t.left,top:s,width:t.width,height:a}}return t}if(e==="bottom"){if(n==="top"){const a=i-r;return!Be(a)||a<o?null:{left:t.left,top:r,width:t.width,height:a}}if(n==="middle"){const a=2*r-i,l=i-a;return!Be(l)||l<o?null:{left:t.left,top:a,width:t.width,height:l}}return t}return t}function Nc(t,e,n,r,o,s){let i=null;for(const a of n){if(!r.includes(a.type))continue;const l=gi(t,a.type),m=Math.abs(a.value-l);if(m>o)continue;const P=or(t,e,a.type,a.value,s);if(!P)continue;(!i||m<i.distance||m===i.distance&&a.source==="sibling"&&i.anchor.source!=="sibling")&&(i={distance:m,anchor:a,snappedRect:P})}return i}function Rc(t,e,n,r,o,s){let i=null;for(const a of n){if(!r.includes(a.type))continue;const l=pi(t,a.type),m=Math.abs(a.value-l);if(m>o)continue;const P=ir(t,e,a.type,a.value,s);if(!P)continue;(!i||m<i.distance||m===i.distance&&a.source==="sibling"&&i.anchor.source!=="sibling")&&(i={distance:m,anchor:a,snappedRect:P})}return i}function Pc(t,e,n,r){const o=[],s=Math.max(1,r.width),i=Math.max(1,r.height);if(e){const a=e.value;if(e.source==="viewport"||!e.sourceRect)o.push({x1:a,y1:0,x2:a,y2:i});else{const l=e.sourceRect,m=Math.min(l.top,t.top),P=Math.max(Je(l),Je(t));o.push({x1:a,y1:m,x2:a,y2:P})}}if(n){const a=n.value;if(n.source==="viewport"||!n.sourceRect)o.push({x1:0,y1:a,x2:s,y2:a});else{const l=n.sourceRect,m=Math.min(l.left,t.left),P=Math.max(je(l),je(t));o.push({x1:m,y1:a,x2:P,y2:a})}}return o}function Mc(t){const{rect:e,resize:n,anchors:r,thresholdPx:o,hysteresisPx:s,minSizePx:i,viewport:a}=t;if(!mr(e))return{snappedRect:e,guideLines:[],lockX:null,lockY:null};const l=n.hasWest?"right":n.hasEast?"left":null,m=n.hasNorth?"bottom":n.hasSouth?"top":null,P=l==="left"?["right","center"]:l==="right"?["left","center"]:[],L=m==="top"?["bottom","middle"]:m==="bottom"?["top","middle"]:[];let S={...e},R=t.lockX,I=t.lockY;if(l){if(R)if(!P.includes(R.type))R=null;else{const T=gi(S,R.type),x=Math.abs(R.value-T),B=or(S,l,R.type,R.value,i);(x>o+s||!B)&&(R=null)}if(R){const T=or(S,l,R.type,R.value,i);T&&(S=T)}else{const T=Nc(S,l,r.x,P,o,i);T&&(R={type:T.anchor.type,value:T.anchor.value,source:T.anchor.source,sourceRect:T.anchor.sourceRect??null},S=T.snappedRect)}}else R=null;if(m){if(I)if(!L.includes(I.type))I=null;else{const T=pi(S,I.type),x=Math.abs(I.value-T),B=ir(S,m,I.type,I.value,i);(x>o+s||!B)&&(I=null)}if(I){const T=ir(S,m,I.type,I.value,i);T&&(S=T)}else{const T=Rc(S,m,r.y,L,o,i);T&&(I={type:T.anchor.type,value:T.anchor.value,source:T.anchor.source,sourceRect:T.anchor.sourceRect??null},S=T.snappedRect)}}else I=null;const h=Pc(S,R,I,a);return{snappedRect:S,guideLines:h,lockX:R,lockY:I}}function ut(t,e){return Be(t)&&t>0&&t>=e}function dt(t){const e=Math.round(t);return`${Object.is(e,-0)?0:e}px`}function po(t,e,n){return Be(t)?Math.min(n,Math.max(e,t)):e}function _c(t){const{rect:e,lockX:n,lockY:r,viewport:o,minGapPx:s}=t;if(!mr(e))return[];const i=Be(o.width)?Math.max(1,o.width):1,a=Be(o.height)?Math.max(1,o.height):1,l=Math.max(0,s),m=[];if(n&&n.source==="sibling"&&n.sourceRect){const P=n.sourceRect,L=e.top-Je(P),S=P.top-Je(e);ut(L,l)?m.push({kind:"sibling",axis:"y",value:Math.round(L),text:dt(L),line:{x1:n.value,y1:Je(P),x2:n.value,y2:e.top}}):ut(S,l)&&m.push({kind:"sibling",axis:"y",value:Math.round(S),text:dt(S),line:{x1:n.value,y1:Je(e),x2:n.value,y2:P.top}})}if(r&&r.source==="sibling"&&r.sourceRect){const P=r.sourceRect,L=e.left-je(P),S=P.left-je(e);ut(L,l)?m.push({kind:"sibling",axis:"x",value:Math.round(L),text:dt(L),line:{x1:je(P),y1:r.value,x2:e.left,y2:r.value}}):ut(S,l)&&m.push({kind:"sibling",axis:"x",value:Math.round(S),text:dt(S),line:{x1:je(e),y1:r.value,x2:P.left,y2:r.value}})}if(n&&n.source==="viewport"){const P=po(Bt(e),0,a),L=e.left,S=i-je(e),R=()=>ut(L,l)?(m.push({kind:"viewport",axis:"x",value:Math.round(L),text:dt(L),line:{x1:0,y1:P,x2:e.left,y2:P}}),!0):!1,I=()=>ut(S,l)?(m.push({kind:"viewport",axis:"x",value:Math.round(S),text:dt(S),line:{x1:je(e),y1:P,x2:i,y2:P}}),!0):!1;n.type==="center"?(R(),I()):n.type==="left"?R()||I():I()||R()}if(r&&r.source==="viewport"){const P=po(Dt(e),0,i),L=e.top,S=a-Je(e),R=()=>ut(L,l)?(m.push({kind:"viewport",axis:"y",value:Math.round(L),text:dt(L),line:{x1:P,y1:0,x2:P,y2:e.top}}),!0):!1,I=()=>ut(S,l)?(m.push({kind:"viewport",axis:"y",value:Math.round(S),text:dt(S),line:{x1:P,y1:Je(e),x2:P,y2:a}}),!0):!1;r.type==="middle"?(R(),I()):r.type==="top"?R()||I():I()||R()}return m}const Gt=1,Lc=3,Dc=["nw","n","ne","e","se","s","sw","w"],Bc={n:"ns-resize",s:"ns-resize",e:"ew-resize",w:"ew-resize",ne:"nesw-resize",sw:"nesw-resize",nw:"nwse-resize",se:"nwse-resize"};function an(t){return typeof t=="number"&&Number.isFinite(t)}function cn(t){return t?an(t.left)&&an(t.top)&&an(t.width)&&an(t.height)&&t.width>.5&&t.height>.5:!1}function ln(t,e){return Number.isFinite(t)?t<e?e:t:e}function gt(t){const e=t.trim();if(!e||e==="auto"||e==="none")return null;const n=e.match(/^(-?\d+(?:\.\d+)?)px$/);if(n){const o=Number(n[1]);return Number.isFinite(o)?o:null}const r=Number(e);return Number.isFinite(r)?r:null}function ft(t){if(!Number.isFinite(t))return"0px";const e=Math.round(t*100)/100;return`${Object.is(e,-0)?0:e}px`}function Fc(t){const e=t.trim().toLowerCase();return e==="fixed"?"fixed":e==="absolute"?"absolute":e==="relative"||e==="sticky"?"relative":"static"}function yo(t){return t==="w"||t==="nw"||t==="sw"}function Vn(t){return t==="e"||t==="ne"||t==="se"}function bo(t){return t==="n"||t==="nw"||t==="ne"}function zn(t){return t==="s"||t==="sw"||t==="se"}function Kc(t){try{const e=t.getBoundingClientRect();return!Number.isFinite(e.left)||!Number.isFinite(e.top)||!Number.isFinite(e.width)||!Number.isFinite(e.height)?null:{left:e.left,top:e.top,width:Math.max(0,e.width),height:Math.max(0,e.height)}}catch{return null}}function yi(t){try{return window.getComputedStyle(t)}catch{return null}}function un(t,e,n){const r=gt(t.getPropertyValue(e))??0,o=gt(t.getPropertyValue(n))??0;return r+o}function Hc(t){const n=t.getPropertyValue("box-sizing").trim()==="border-box"?"border-box":"content-box",r=un(t,"padding-left","padding-right"),o=un(t,"padding-top","padding-bottom"),s=un(t,"border-left-width","border-right-width"),i=un(t,"border-top-width","border-bottom-width");return{boxSizing:n,horizontalExtras:r+s,verticalExtras:o+i}}function wo(t,e,n){return n==="border-box"?t:Math.max(0,t-e)}function $c(t){try{const e=t.offsetParent;if(e instanceof HTMLElement){const n=e.getBoundingClientRect(),r=yi(e),o=r?gt(r.getPropertyValue("border-left-width"))??0:0,s=r?gt(r.getPropertyValue("border-top-width"))??0:0;return{originX:n.left+o,originY:n.top+s,scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}}}catch{}return{originX:0,originY:0,scrollLeft:0,scrollTop:0}}function dn(t){t.cancelable&&t.preventDefault(),t.stopPropagation()}function Uc(t){const e=new ze,{container:n,canvasOverlay:r,transactionManager:o,positionTracker:s}=t,i=document.createElement("div");i.className="we-handles-layer",i.setAttribute("aria-hidden","true"),n.append(i),e.add(()=>i.remove());const a=document.createElement("div");a.className="we-selection-frame",a.hidden=!0,i.append(a);const l=document.createElement("div");l.className="we-size-hud",l.hidden=!0,a.append(l);const m=new Map;for(const d of Dc){const M=document.createElement("div");M.className="we-resize-handle",M.dataset.dir=d,M.tabIndex=-1,a.append(M),m.set(d,M)}let P=null,L=null,S=null,R=null;function I(){R!==null&&(cancelAnimationFrame(R),R=null)}e.add(I);function h(d){if(!(!!P&&cn(d))){a.hidden=!0;return}a.hidden=!1,a.style.transform=`translate3d(${d.left}px, ${d.top}px, 0)`,a.style.width=`${d.width}px`,a.style.height=`${d.height}px`}function T(d){if(!d){l.hidden=!0,l.textContent="";return}l.hidden=!1,l.textContent=d}function x(d){document.body.style.cursor=d.prevBodyCursor,document.body.style.userSelect=d.prevBodyUserSelect}function B(d){const M=S;if(M){if(I(),S=null,M.tx)try{M.tx.rollback()}catch(j){console.warn(`${Ke} Resize rollback failed:`,j)}try{x(M)}catch{}try{r.setGuideLines(null),r.setDistanceLabels(null),r.render()}catch{}T(null),h(L);try{s.forceUpdate()}catch{}d&&console.log(`${Ke} Resize cancelled (${d})`)}}function K(){const d=S;if(d){if(I(),S=null,d.tx)try{d.tx.commit({merge:!1})}catch(M){console.warn(`${Ke} Resize commit failed:`,M);try{d.tx.rollback()}catch{}}try{x(d)}catch{}try{r.setGuideLines(null),r.setDistanceLabels(null),r.render()}catch{}T(null);try{s.forceUpdate()}catch{}}}function _(){R!==null||e.isDisposed||(R=requestAnimationFrame(()=>{R=null,v()}))}function v(){const d=S;if(!d)return;if(!d.target.isConnected){B("target_disconnected");return}const M=d.lastClientX-d.startClientX,j=d.lastClientY-d.startClientY;if(!d.hasPassedThreshold){if(Math.hypot(M,j)<Lc)return;d.hasPassedThreshold=!0;const u=o.beginMultiStyle(d.target,Array.from(d.properties));if(!u){B("tx_unavailable");return}d.tx=u;try{const k=Ac(d.target),y=Ic();d.anchors=kc(k,y)}catch{d.anchors=null}}const ee=d.tx;if(!ee){B("tx_missing");return}let oe=d.startRect.width,ie=d.startRect.height;d.affectsWidth&&(Vn(d.dir)&&(oe=ln(d.startRect.width+M,Gt)),yo(d.dir)&&(oe=ln(d.startRect.width-M,Gt))),d.affectsHeight&&(zn(d.dir)&&(ie=ln(d.startRect.height+j,Gt)),bo(d.dir)&&(ie=ln(d.startRect.height-j,Gt)));const me=d.hasWest?d.startRect.width-oe:0,ce=d.hasNorth?d.startRect.height-ie:0,pe={left:d.startRect.left+me,top:d.startRect.top+ce,width:oe,height:ie};let ge=pe;if(d.anchors){const u=Vn(d.dir),k=zn(d.dir),y=Mc({rect:pe,resize:{hasWest:d.hasWest,hasEast:u,hasNorth:d.hasNorth,hasSouth:k},anchors:d.anchors,thresholdPx:hs,hysteresisPx:ms,minSizePx:Gt,lockX:d.lockX,lockY:d.lockY,viewport:{width:window.innerWidth||1,height:window.innerHeight||1}});d.lockX=y.lockX,d.lockY=y.lockY,ge=y.snappedRect;const D=_c({rect:ge,lockX:d.lockX,lockY:d.lockY,minGapPx:ys,viewport:{width:window.innerWidth||1,height:window.innerHeight||1}}),U=y.guideLines.length>0,C=D.length>0;if(U||d.hadGuidesLastFrame||C||d.hadDistanceLabelsLastFrame){try{r.setGuideLines(U?y.guideLines:null),r.setDistanceLabels(C?D:null),r.render()}catch{}d.hadGuidesLastFrame=U,d.hadDistanceLabelsLastFrame=C}oe=ge.width,ie=ge.height}const ae=ge.left-d.startRect.left,V=ge.top-d.startRect.top;h(ge),T(`${Math.round(ge.width)} × ${Math.round(ge.height)}`);const p={};if(d.affectsWidth){const u=wo(oe,d.extras.horizontalExtras,d.extras.boxSizing);p.width=ft(u)}if(d.affectsHeight){const u=wo(ie,d.extras.verticalExtras,d.extras.boxSizing);p.height=ft(u)}d.mode==="absolute"||d.mode==="fixed"?(d.affectsWidth&&(p.left=ft(d.startPosX+ae),p.right=""),d.affectsHeight&&(p.top=ft(d.startPosY+V),p.bottom="")):d.mode==="relative"?(d.affectsWidth&&d.hasWest&&(p.left=ft(d.startPosX+ae)),d.affectsHeight&&d.hasNorth&&(p.top=ft(d.startPosY+V))):(d.affectsWidth&&d.hasWest&&(p["margin-left"]=ft(d.startPosX+ae)),d.affectsHeight&&d.hasNorth&&(p["margin-top"]=ft(d.startPosY+V)));try{ee.set(p)}catch(u){console.warn(`${Ke} Resize preview apply failed:`,u),B("apply_failed")}}function H(d,M,j){if(e.isDisposed||j.button!==0)return;const ee=P;if(!ee||!ee.isConnected)return;S&&B("restart");const oe=yi(ee);if(!oe)return;const ie=oe.getPropertyValue("transform").trim();if(ie&&ie!=="none"){console.warn(`${Ke} Resize handles do not support transformed elements yet`);return}const me=oe.getPropertyValue("position"),ce=Fc(me),pe=yo(d),ge=bo(d),ae=pe||Vn(d),V=ge||zn(d),p=oe.getPropertyValue("margin-left").trim().toLowerCase(),u=oe.getPropertyValue("margin-top").trim().toLowerCase(),k=gt(p)??0,y=gt(u)??0;if(ce==="static"){if(pe&&p==="auto"){console.warn(`${Ke} Resize from west is disabled when margin-left is auto`);return}if(ge&&u==="auto"){console.warn(`${Ke} Resize from north is disabled when margin-top is auto`);return}}const D=cn(L)?L:Kc(ee);if(!D||!cn(D))return;const U=[];ae&&(U.push("width"),ce==="absolute"||ce==="fixed"?U.push("left","right"):ce==="relative"?pe&&U.push("left"):pe&&U.push("margin-left")),V&&(U.push("height"),ce==="absolute"||ce==="fixed"?U.push("top","bottom"):ce==="relative"?ge&&U.push("top"):ge&&U.push("margin-top"));let C=null,g=0,G=0;ce==="absolute"?(C=$c(ee),g=ae?D.left-k-C.originX+C.scrollLeft:0,G=V?D.top-y-C.originY+C.scrollTop:0):ce==="fixed"?(C={originX:0,originY:0,scrollLeft:0,scrollTop:0},g=ae?D.left-k:0,G=V?D.top-y:0):ce==="relative"?(g=ae&&pe?gt(oe.getPropertyValue("left"))??0:0,G=V&&ge?gt(oe.getPropertyValue("top"))??0:0):(g=ae&&pe?k:0,G=V&&ge?y:0);const se=Hc(oe),J=document.body.style.cursor,W=document.body.style.userSelect;S={pointerId:j.pointerId,dir:d,handleEl:M,target:ee,mode:ce,properties:U,tx:null,hasPassedThreshold:!1,affectsWidth:ae,affectsHeight:V,hasWest:pe,hasNorth:ge,anchors:null,lockX:null,lockY:null,hadGuidesLastFrame:!1,hadDistanceLabelsLastFrame:!1,startClientX:j.clientX,startClientY:j.clientY,lastClientX:j.clientX,lastClientY:j.clientY,startRect:D,startPosX:g,startPosY:G,absOrigin:C,extras:se,prevBodyCursor:J,prevBodyUserSelect:W};try{M.setPointerCapture(j.pointerId)}catch{}document.body.style.cursor=Bc[d],document.body.style.userSelect="none",dn(j),h(D),_()}function q(d){const M=S;M&&d.pointerId===M.pointerId&&(dn(d),M.lastClientX=d.clientX,M.lastClientY=d.clientY,_())}function Y(d){const M=S;M&&d.pointerId===M.pointerId&&(dn(d),M.lastClientX=d.clientX,M.lastClientY=d.clientY,K())}function F(d){const M=S;M&&d.pointerId===M.pointerId&&(dn(d),B(d.type))}function A(d){S&&d.key==="Escape"&&(d.preventDefault(),d.stopImmediatePropagation(),d.stopPropagation(),B("escape"))}function X(){S&&B("blur")}function N(){S&&document.visibilityState!=="visible"&&B("visibilitychange")}for(const[d,M]of m)e.listen(M,"pointerdown",j=>H(d,M,j)),e.listen(M,"pointermove",q),e.listen(M,"pointerup",Y),e.listen(M,"pointercancel",F),e.listen(M,"lostpointercapture",F);e.listen(document,"keydown",A,{capture:!0}),e.listen(window,"blur",X),e.listen(document,"visibilitychange",N);function b(d){e.isDisposed||(S&&B("target_change"),d instanceof HTMLElement&&d.isConnected?P=d:P=null,h(L))}function E(d){if(!e.isDisposed){if(L=cn(d)?d:null,!P||!P.isConnected){a.hidden=!0;return}if(S&&!L){B("rect_lost");return}S||h(L)}}function O(){B("dispose"),P=null,L=null,e.dispose()}return h(null),{setTarget:b,setSelectionRect:E,dispose:O}}const So=0,Oc=88,qc=56;function Gc(t,e){return!t||!e?!1:t.width>=Oc&&t.height>=qc}function Vc(t){return{left:t.left+So,top:t.top+So}}function zc(t){const e=new ze;let n=null,r=null,o=null;const s=document.createElement("button");s.type="button",s.className="we-parent-corner",s.dataset.hidden="true",s.setAttribute("aria-label","选择上级"),s.title="选择上级";const i=document.createElement("span");i.className="we-parent-corner__chrome",i.style.background=Me.selectionBorder,s.append(i),t.container.append(s),e.add(()=>s.remove());const a=m=>{m.preventDefault(),m.stopPropagation()};s.addEventListener("pointerdown",a),s.addEventListener("click",m=>{a(m);const P=o;!P||!P.isConnected||t.onSelectParent(P)}),e.add(()=>{s.removeEventListener("pointerdown",a)});function l(){if(o=n&&n.isConnected?t.getParentCandidate(n):null,!Gc(r,!!o)||!r){s.dataset.hidden="true";return}const P=Vc(r);s.style.left=`${P.left}px`,s.style.top=`${P.top}px`,s.dataset.hidden="false"}return{setTarget(m){n=m,l()},setSelectionRect(m){r=m,l()},dispose(){e.dispose()}}}const Wc=8,Xc=6,Yc=60,pt=.5,jc=new Set(["A","BUTTON","INPUT","SELECT","TEXTAREA","LABEL","SUMMARY","DETAILS"]),Jc=new Set(["button","link","checkbox","radio","switch","tab","menuitem","option","combobox","textbox"]),Qc=new Set(["DIV","SPAN","SECTION","ARTICLE","MAIN","HEADER","FOOTER","NAV","ASIDE"]);function rt(t){const e=Number.parseFloat(t);return Number.isFinite(e)?e:0}function Zc(t){const e=t.trim().toLowerCase();if(e==="transparent")return!0;const n=e.match(/^rgba?\((.+)\)$/);if(n){const o=n[1].split(",").map(s=>s.trim());if(o.length>=4){const s=Number.parseFloat(o[3]);return Number.isFinite(s)&&s<=.01}return!1}const r=e.match(/^hsla?\((.+)\)$/);if(r){const o=r[1].split(",").map(s=>s.trim());if(o.length>=4){const s=Number.parseFloat(o[3]);return Number.isFinite(s)&&s<=.01}return!1}return!1}function el(t){var e;for(const n of Array.from(t.childNodes))if(n.nodeType===Node.TEXT_NODE&&((e=n.textContent)!=null&&e.trim()))return!0;return!1}function Vt(t){var e;if(t.parentElement)return t.parentElement;try{const n=(e=t.getRootNode)==null?void 0:e.call(t);if(n instanceof ShadowRoot)return n.host}catch{}return null}function Eo(t,e){if(!Number.isFinite(t)||!Number.isFinite(e))return[];try{if(typeof document.elementsFromPoint=="function")return document.elementsFromPoint(t,e)}catch{}const n=document.elementFromPoint(t,e);return n?[n]:[]}function Wn(){const t=Math.max(1,window.innerWidth||1),e=Math.max(1,window.innerHeight||1);return t*e}function vo(t){try{const e=t.getBoundingClientRect();return!Number.isFinite(e.left)||!Number.isFinite(e.top)||!Number.isFinite(e.width)||!Number.isFinite(e.height)?null:e}catch{return null}}function To(t,e){return t.display==="none"||t.visibility==="hidden"||t.visibility==="collapse"||rt(t.opacity)<=.01||t.contentVisibility==="hidden"||e.width<=pt||e.height<=pt}function Co(t,e){let n=0;const r=[];(!Zc(e.backgroundColor)||e.backgroundImage!=="none")&&(n+=2,r.push("visual:background:+2")),[rt(e.borderTopWidth),rt(e.borderRightWidth),rt(e.borderBottomWidth),rt(e.borderLeftWidth)].some(a=>a>pt)&&(e.borderTopStyle!=="none"||e.borderRightStyle!=="none"||e.borderBottomStyle!=="none"||e.borderLeftStyle!=="none")&&(n+=3,r.push("visual:border:+3")),e.boxShadow&&e.boxShadow!=="none"&&(n+=2,r.push("visual:shadow:+2")),e.outlineStyle!=="none"&&rt(e.outlineWidth)>pt&&(n+=1,r.push("visual:outline:+1"));const i=t.tagName.toUpperCase();return(i==="IMG"||i==="VIDEO"||i==="CANVAS"||i==="SVG")&&(n+=2,r.push("visual:media:+2")),t instanceof SVGElement&&i!=="SVG"&&(n-=1,r.push("visual:svg-sub:-1")),{points:n,reasons:r}}function xo(t,e){var i;let n=0;const r=[],o=t.tagName.toUpperCase();jc.has(o)&&(n+=6,r.push(`type:${o.toLowerCase()}:+6`));const s=((i=t.getAttribute("role"))==null?void 0:i.toLowerCase())??"";return s&&Jc.has(s)&&(n+=4,r.push(`role:${s}:+4`)),t instanceof HTMLAnchorElement&&t.href&&(n+=2,r.push("attr:href:+2")),t instanceof HTMLElement&&(t.isContentEditable&&(n+=5,r.push("attr:contenteditable:+5")),t.tabIndex>=0&&(n+=2,r.push("focusable:+2"))),e.cursor==="pointer"&&(n+=2,r.push("cursor:pointer:+2")),{points:n,reasons:r}}function tl(t,e){let n=0;const r=[],o=t.width*t.height;if(!Number.isFinite(o)||o<=0)return n-=6,r.push("size:invalid:-6"),{points:n,reasons:r};t.width<4||t.height<4?(n-=6,r.push("size:tiny:-6")):o<16*16?(n-=4,r.push("size:small:-4")):o<44*44&&(n-=1,r.push("size:below-tap-target:-1"));const s=e>0?o/e:0;return s>.85?(n-=8,r.push("size:huge:-8")):s>.6&&(n-=4,r.push("size:very-large:-4")),{points:n,reasons:r}}function nl(t){return rt(t.paddingTop)>pt||rt(t.paddingRight)>pt||rt(t.paddingBottom)>pt||rt(t.paddingLeft)>pt}function Ao(t,e,n,r){if(e.display==="contents")return!0;if(r>0)return!1;const o=t.tagName.toUpperCase();return!(!Qc.has(o)||t.children.length!==1||el(t)||n>0||nl(e))}function Io(t,e){return t.hitOrder!==e.hitOrder?t.hitOrder-e.hitOrder:t.depthFromHit-e.depthFromHit}function rl(t){const e=new ze,{isOverlayElement:n}=t;function r(S,R,I){if(!S.isConnected||n(S))return null;const h=S.tagName.toUpperCase();if(h==="HTML"||h==="BODY")return null;const T=vo(S);if(!T)return null;let x=R.get(S);if(x||(x=window.getComputedStyle(S),R.set(S,x)),To(x,T))return null;const B=[];let K=0;const _=xo(S,x);K+=_.points,B.push(..._.reasons);const v=Co(S,x);K+=v.points,B.push(...v.reasons);const H=tl(T,I);K+=H.points,B.push(...H.reasons);const q=Ao(S,x,v.points,_.points);q&&(K-=8,B.push("wrapperOnly:-8")),h==="SPAN"&&_.points===0&&v.points===0&&(K-=2,B.push("inline:span:-2"));const Y=T.width*T.height,F=I>0?Y/I:0;return x.position==="fixed"&&F>.3&&(K-=2,B.push("position:fixed-large:-2")),{element:S,score:K,reasons:B,wrapperOnly:q}}function o(S,R){const I=Eo(S,R);if(I.length===0)return[];const h=new Map;function T(v,H){if(n(v)||h.size>=Yc&&!h.has(v))return;const q=h.get(v);(!q||Io(H,q)<0)&&h.set(v,H)}const x=Math.min(I.length,Wc);for(let v=0;v<x;v++){const H=I[v];T(H,{hitOrder:v,depthFromHit:0});let q=H;for(let Y=1;Y<=Xc&&(q=q?Vt(q):null,!!q);Y++)T(q,{hitOrder:v,depthFromHit:Y})}const B=Wn(),K=new Map,_=[];for(const[v,H]of h){const q=r(v,K,B);q&&_.push({...q,...H})}return _.sort((v,H)=>H.score!==v.score?H.score-v.score:Io(v,H)),_.map(({hitOrder:v,depthFromHit:H,...q})=>q)}function s(S){let R=Vt(S);if(!R)return null;const I=new Map;for(;R;){if(n(R))return null;const h=R.tagName.toUpperCase();if(h==="HTML"||h==="BODY")return null;const T=vo(R);if(!T){R=Vt(R);continue}let x=I.get(R);if(x||(x=window.getComputedStyle(R),I.set(R,x)),To(x,T)){R=Vt(R);continue}const B=xo(R,x),K=Co(R,x);if(!Ao(R,x,K.points,B.points))return R;R=Vt(R)}return null}function i(S,R,I){var x;const T=((x=o(S,R)[0])==null?void 0:x.element)??null;return T?I.alt?s(T)??T:T:null}function a(S){try{const R=typeof S.composedPath=="function"?S.composedPath():null;if(!Array.isArray(R)||R.length===0)return[];const I=[];for(const h of R){if(!(h instanceof Element)||n(h))continue;const T=h.tagName.toUpperCase();T==="HTML"||T==="BODY"||I.push(h)}return I}catch{return[]}}function l(S){const R=S,I=typeof R.clientX=="number"?R.clientX:Number.NaN,h=typeof R.clientY=="number"?R.clientY:Number.NaN;return!Number.isFinite(I)||!Number.isFinite(h)?null:{x:I,y:h}}const m=32;function P(S){const R=Wn(),I=new Map,h=Math.min(S.length,m);for(let T=0;T<h;T++){const x=S[T],B=r(x,I,R);if(B)return B.element}return null}function L(S,R){const I=a(S),h=l(S);if(R.ctrl||R.meta){const v=P(I);return v||(h?i(h.x,h.y,R):null)}const T=I[0]??(h?Eo(h.x,h.y)[0]:null);if(!T)return h?i(h.x,h.y,R):null;const x=Wn(),K=r(T,new Map,x);let _;return K&&!K.wrapperOnly?_=T:_=s(T)??T,R.alt?s(_)??_:_}return{findBestTarget:i,findBestTargetFromEvent:L,getCandidatesAtPoint:o,getParentCandidate:s,dispose:()=>e.dispose()}}const ko=50,sr="axhub-web-editor-text-annotation",No="axhub-web-editor-text-annotation-style";function ol(t){let e=2166136261;for(let n=0;n<t.length;n++)e^=t.charCodeAt(n),e=Math.imul(e,16777619);return(e>>>0).toString(16).padStart(8,"0")}function il(t,e){return`text-ann::${ol(t+"||"+e)}`}function bi(t){const e=[];let n=t instanceof Element?t:t.parentElement;for(;n&&n!==document.body;){if(n instanceof Element){e.unshift(n.tagName.toLowerCase());const r=sl(n);if(r&&r!=="inline"&&r!=="inline-block")break}n=n.parentNode}return e}function sl(t){try{return window.getComputedStyle(t).display}catch{return null}}function al(t){const e=[],n=s=>{let i=s.textContent??"";if(s===t.startContainer&&(i=i.slice(t.startOffset)),s===t.endContainer){const a=s===t.startContainer?t.endOffset-t.startOffset:t.endOffset;i=i.slice(0,a)}i=i.replace(/\s+/g," "),i&&e.push({text:i,tags:bi(s)})};if(t.commonAncestorContainer instanceof Text)return n(t.commonAncestorContainer),e;const r=document.createTreeWalker(t.commonAncestorContainer,NodeFilter.SHOW_TEXT,{acceptNode(s){return t.intersectsNode(s)?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_REJECT}});let o=r.nextNode();for(;o;)n(o),o=r.nextNode();return e}function Ro(t,e){try{const n=t.commonAncestorContainer,r=n instanceof Element?n:n.parentElement;if(!r)return"";const o=r.textContent??"",s=t.toString(),i=o.indexOf(s);if(i<0)return"";if(e==="before"){const a=Math.max(0,i-ko);return o.slice(a,i).replace(/\s+/g," ").trim()}else{const a=i+s.length;return o.slice(a,a+ko).replace(/\s+/g," ").trim()}}catch{return""}}function wi(t){return{left:t.left,top:t.top,width:t.width,height:t.height}}function cl(t){const e=[];for(let n=0;n<t.length;n++){const r=t[n];r.width<=0||r.height<=0||e.push(wi(r))}return e}function ll(t){const e=t.commonAncestorContainer;return e instanceof Element?e:e.parentElement}function ul(){return typeof CSS<"u"&&"highlights"in CSS&&typeof globalThis.Highlight=="function"}function dl(){if(document.getElementById(No))return;const t=document.createElement("style");t.id=No,t.textContent=`
|
||
::highlight(${sr}) {
|
||
background: rgba(0, 143, 93, 0.18);
|
||
color: inherit;
|
||
}
|
||
`,document.head.append(t)}function Po(t){if(!ul())return!1;dl();const e=CSS.highlights;if(e.delete(sr),!t)return!0;const n=globalThis.Highlight;return e.set(sr,new n(t.cloneRange())),!0}function fl(t){const{isOverlayElement:e}=t,n=new Map;function r(){const P=window.getSelection();if(!P||P.isCollapsed||!P.rangeCount)return null;const L=P.getRangeAt(0),S=P.toString().trim();if(!S||e(L.startContainer)||e(L.endContainer))return null;const R=al(L);if(R.length===0)return null;const I=Ro(L,"before"),h=Ro(L,"after"),T=bi(L.commonAncestorContainer),x=wi(L.getBoundingClientRect()),B=cl(L.getClientRects()),K=ll(L),_=il(S,I),v={id:_,selectedText:S,contextBefore:I,contextAfter:h,tagPath:T,segments:R,boundingRect:x,clientRects:B,range:L.cloneRange(),sourceElement:K};return n.set(_,v),v}function o(){return n}function s(P){n.delete(P)}function i(){n.clear(),l()}function a(P){return Po((P==null?void 0:P.range)??null)}function l(){Po(null)}function m(){n.clear(),l()}return{commitSelection:r,getAnnotations:o,removeAnnotation:s,clearAll:i,setActiveHighlight:a,clearActiveHighlight:l,dispose:m}}const st={capture:!0,passive:!1},hl=["pointerup","pointercancel","pointerover","pointerout","pointerenter","pointerleave"],ml=["mouseup","click","dblclick","contextmenu","auxclick","mouseover","mouseout","mouseenter","mouseleave"],gl=["keyup","keypress"],pl=["touchstart","touchmove","touchend","touchcancel"];function yl(t){const{isOverlayElement:e,onHover:n,onSelect:r,onDeselect:o,resolveTargetForHover:s,findTargetForSelect:i,getSelectedElement:a,isElementInteractionLocked:l,onStartDrag:m,onDragMove:P,onDragEnd:L,onDragCancel:S}=t,R=new ze,I=typeof PointerEvent<"u";let h="hover",T=null,x=null,B=null,K=!1,_=!1,v=!1,H=0,q=0,Y=null;function F(g){try{if(typeof g.composedPath=="function")return g.composedPath().some(G=>e(G))}catch{}return e(g.target)}function A(g){h!=="interaction"&&(t.allowNativeTextSelection||(g.cancelable&&g.preventDefault(),g.stopImmediatePropagation(),g.stopPropagation()))}function X(g){return{alt:g.altKey,shift:g.shiftKey,ctrl:g.ctrlKey,meta:g.metaKey}}function N(g){return g instanceof PointerEvent?g.pointerId:0}function b(g){return!(I&&!(g instanceof PointerEvent))}function E(g,G){try{if(typeof g.composedPath=="function")return g.composedPath().some(J=>J===G)}catch{}const se=g.target;return se instanceof Node&&G.contains(se)}function O(){x=null,B=null,K=!1}function d(g){if(h==="dragging"){O();try{S==null||S({reason:g})}catch{}_=!0,ce("selecting")}}function M(g,G,se){if(h==="dragging"&&!(B===null||B!==g)){O();try{L==null||L({pointerId:g,clientX:G,clientY:se})}catch{}_=!0,ce("selecting")}}function j(g,G){if(!Number.isFinite(g)||!Number.isFinite(G))return null;const se=document.elementFromPoint(g,G);if(!se||e(se))return null;const J=s?s(se):se;return!J||e(J)||((l==null?void 0:l(J))??!1)?null:J}function ee(g,G,se,J){if(!Number.isFinite(G)||!Number.isFinite(se))return null;if(i){const W=i(G,se,J,g);return W&&e(W)||W&&((l==null?void 0:l(W))??!1)?null:W}return j(G,se)}function oe(){Y!==null&&(cancelAnimationFrame(Y),Y=null)}R.add(oe);function ie(g=!1){if(Y=null,R.isDisposed||h!=="hover"&&h!=="selecting"||!v)return;const G=j(H,q);!g&&G===T||(T=G,n(G))}function me(g=!1){Y===null&&(R.isDisposed||(Y=requestAnimationFrame(()=>{ie(g)})))}function ce(g){if(R.isDisposed||h===g)return;const G=h;if(h=g,G==="selecting"&&g!=="selecting"&&(x=null),g==="interaction"&&G!=="interaction"&&(oe(),T&&(T=null,n(null))),G==="dragging"&&g!=="dragging"){const se=!_;if(_=!1,O(),se)try{S==null||S({reason:"mode_change"})}catch{}}else _=!1;G==="hover"&&g!=="hover"&&(oe(),T?(T=null,n(null)):T=null),g==="hover"&&G!=="hover"&&(T=null,O(),o(),v&&me(!0))}function pe(g){if(F(g)){h==="hover"&&T!==null&&(T=null,n(null));return}if(A(g),!t.allowNativeTextSelection){if(H=g.clientX,q=g.clientY,v=!0,h==="dragging"&&b(g)){const G=N(g),se=g instanceof PointerEvent;if(K!==se)return;B!==null&&G===B&&(P==null||P({pointerId:G,clientX:g.clientX,clientY:g.clientY}));return}if(ae&&mt()){const G=g.clientX-ae.clientX,se=g.clientY-ae.clientY;Math.hypot(G,se)>=ge&&(ae=null)}if(h==="selecting"&&x&&b(g)){const G=N(g);if(G!==x.pointerId)return;const se=g instanceof PointerEvent;if(x.isPointerEventOrigin!==se)return;const J=g.clientX-x.startClientX,W=g.clientY-x.startClientY,Z=mt()?12:ds;if(Math.hypot(J,W)<Z)return;const re={pointerId:G,draggedElement:x.selectedElement,startClientX:x.startClientX,startClientY:x.startClientY,clientX:g.clientX,clientY:g.clientY,modifiers:x.modifiers},fe=x.isPointerEventOrigin;if(x=null,!((m==null?void 0:m(re))??!1))return;B=G,K=fe,ce("dragging"),P==null||P({pointerId:G,clientX:g.clientX,clientY:g.clientY});return}h!=="hover"&&h!=="selecting"||me()}}const ge=15;let ae=null;function V(g){return mt()&&g instanceof PointerEvent&&g.pointerType==="touch"}function p(g){if(F(g)||(A(g),H=g.clientX,q=g.clientY,v=!0,t.allowNativeTextSelection)||g.button!==0)return;const G=X(g),se=V(g);if(h==="selecting"){if(!b(g))return;const W=(a==null?void 0:a())??null,Z=ee(g,g.clientX,g.clientY,G);if(Z&&Z!==W){if(x=null,se){ae={target:Z,modifiers:G,clientX:g.clientX,clientY:g.clientY};return}ce("hover");return}if(Z&&W&&Z===W&&!m){if(se){ae={target:Z,modifiers:G,clientX:g.clientX,clientY:g.clientY};return}r({element:Z,modifiers:G,clientX:g.clientX,clientY:g.clientY});return}if(m&&W&&W.isConnected&&!((l==null?void 0:l(W))??!1)&&E(g,W)){const re=g instanceof PointerEvent;x={pointerId:N(g),startClientX:g.clientX,startClientY:g.clientY,modifiers:G,selectedElement:W,isPointerEventOrigin:re};return}!se&&!Z&&ce("hover");return}if(h==="dragging"||h!=="hover")return;const J=ee(g,g.clientX,g.clientY,G);if(J){if(se){ae={target:J,modifiers:G,clientX:g.clientX,clientY:g.clientY,nextMode:"selecting"};return}ce("selecting"),r({element:J,modifiers:G,clientX:g.clientX,clientY:g.clientY})}}function u(g){var G;if(!F(g)&&(A(g),g.key==="Escape")){if(h==="dragging"){d("escape");return}if(t.allowNativeTextSelection){(G=window.getSelection())==null||G.removeAllRanges(),o();return}h==="selecting"&&(x=null,ce("hover"))}}function k(g){if(F(g)||(A(g),!b(g)))return;const G=N(g),se=g instanceof PointerEvent;if(ae&&V(g)){const J=ae;ae=null;const W=g.clientX-J.clientX,Z=g.clientY-J.clientY;Math.hypot(W,Z)<ge&&(J.nextMode&&ce(J.nextMode),r({element:J.target,modifiers:J.modifiers,clientX:J.clientX,clientY:J.clientY}));return}h==="selecting"&&x&&x.pointerId===G&&x.isPointerEventOrigin===se&&(x=null),h==="dragging"&&K===se&&M(G,g.clientX,g.clientY)}function y(g){if(F(g))return;A(g);const G=g.pointerId;x&&x.pointerId===G&&x.isPointerEventOrigin&&(x=null),h==="dragging"&&K&&(B===null||B!==G||d("pointercancel"))}function D(g){if(h!=="interaction"&&!F(g)&&!t.allowNativeTextSelection){if(g.type==="pointerup"||g.type==="mouseup"){k(g);return}if(g.type==="pointercancel"){y(g);return}A(g)}}if(I){R.listen(document,"pointermove",pe,st),R.listen(document,"pointerdown",p,st);for(const g of hl)R.listen(document,g,D,st)}R.listen(document,"mousemove",pe,st),R.listen(document,"mousedown",p,st);for(const g of ml)R.listen(document,g,D,st);R.listen(document,"keydown",u,st);for(const g of gl)R.listen(document,g,D,st);if(!mt())for(const g of pl)R.listen(document,g,D,st);function U(){h==="selecting"&&x&&(x=null),h==="dragging"&&d("blur")}function C(){document.visibilityState!=="visible"&&(h==="selecting"&&x&&(x=null),h==="dragging"&&d("visibilitychange"))}return R.listen(window,"blur",U),R.listen(document,"visibilitychange",C),R.add(()=>{if(h==="dragging")try{S==null||S({reason:"dispose"})}catch{}O()}),{getMode:()=>h,setMode:ce,dispose:()=>R.dispose()}}const fn={passive:!0},bl=.5,Mo={childList:!0,subtree:!0};function wl(t){return t?t.parentNode?t.parentNode:t instanceof ShadowRoot?t.host:null:null}function Sl(t){if(!t)return[window,document];const e=new Set;let n=t;for(;n;)(n instanceof Element||n instanceof ShadowRoot||n instanceof Document)&&e.add(n),n=wl(n);return e.add(window),e.add(document),Array.from(e)}function El(t){const{left:e,top:n,width:r,height:o}=t;return!Number.isFinite(e)||!Number.isFinite(n)||!Number.isFinite(r)||!Number.isFinite(o)?null:{left:e,top:n,width:Math.max(0,r),height:Math.max(0,o)}}function hn(t,e){return Math.abs(t-e)<bl}function _o(t,e){return t===e?!0:!t||!e?!1:hn(t.left,e.left)&&hn(t.top,e.top)&&hn(t.width,e.width)&&hn(t.height,e.height)}function vl(t,e){return _o(t.hover,e.hover)&&_o(t.selection,e.selection)}function Tl(t){const{onPositionUpdate:e}=t,n=new ze;let r=null,o=null,s={hover:null,selection:null},i=null;function a(){i!==null&&(cancelAnimationFrame(i),i=null)}n.add(a);function l(){n.isDisposed||i===null&&(i=requestAnimationFrame(()=>{i=null,I()}))}let m=new ze;n.add(()=>m.dispose());function P(){var q;m.dispose(),m=new ze;const K=o;if(!K)return;m.observeResize(K,()=>{n.isDisposed||o===K&&l()});const _=()=>{n.isDisposed||o===K&&l()},v=(q=K.getRootNode)==null?void 0:q.call(K);v instanceof ShadowRoot&&m.observeMutation(v,_,Mo);const H=document.body??document.documentElement;H&&m.observeMutation(H,_,Mo);for(const Y of Sl(K))m.listen(Y,"scroll",_,fn)}function L(K){return K&&K.isConnected?K:null}function S(K){if(!K)return null;try{return El(K.getBoundingClientRect())}catch{return null}}function R(){const K=L(r),_=L(o);if(r&&!K&&(r=null),o&&!_&&(o=null,P()),K&&_&&K===_){const v=S(K);return{hover:v,selection:v}}return{hover:S(K),selection:S(_)}}function I(){if(n.isDisposed)return;const K=R();vl(K,s)||(s=K,e(K))}function h(){!r&&!o&&!s.hover&&!s.selection||l()}n.listen(window,"scroll",h,fn),n.listen(document,"scroll",h,{...fn,capture:!0}),n.listen(window,"resize",h,fn);function T(K){n.isDisposed||r!==K&&(r=K,l())}function x(K){n.isDisposed||o!==K&&(o=K,P(),l())}function B(K){if(!n.isDisposed){if(a(),K){const _=R();s=_,e(_);return}I()}}return{setHoverElement:T,setSelectionElement:x,forceUpdate:B,dispose:()=>n.dispose()}}const Cl=100,xl=800,Al={capture:!0,passive:!1};function yt(t){const e=t.trim();return e?e.startsWith("--")?e:e.includes("-")?e.toLowerCase():e.replace(/[A-Z]/g,n=>`-${n.toLowerCase()}`).toLowerCase():""}function An(t){const n=t.style;return!n||typeof n.getPropertyValue!="function"||typeof n.setProperty!="function"||typeof n.removeProperty!="function"?null:n}function mn(t,e){const n=yt(e);return n?t.getPropertyValue(n).trim():""}function Lo(t,e){if(typeof window>"u"||typeof window.getComputedStyle!="function")return"";const n=yt(e);if(!n)return"";try{return window.getComputedStyle(t).getPropertyValue(n).trim()}catch{return""}}function Wt(t,e,n){const r=yt(e);if(!r)return;const o=n.trim();o?t.setProperty(r,o):t.removeProperty(r)}function Si(t,e){if(!e)return;const n=An(t);if(n)for(const[r,o]of Object.entries(e))Wt(n,r,o)}function Sn(t){const e=[],n=new Set;for(const r of t??[]){const o=String(r??"").trim();o&&(n.has(o)||(n.add(o),e.push(o)))}return e}function Do(t,e){if(t.length!==e.length)return!1;for(let n=0;n<t.length;n++)if(t[n]!==e[n])return!1;return!0}function Il(t){try{const e=t.classList;if(e&&typeof e[Symbol.iterator]=="function")return Array.from(e).filter(Boolean)}catch{}try{return(t.getAttribute("class")??"").split(/\s+/).map(n=>n.trim()).filter(Boolean)}catch{return[]}}function Ei(t,e){const r=Sn(e).join(" ").trim();try{r?t.setAttribute("class",r):t.removeAttribute("class")}catch{}}function kl(t){const e=An(t);if(!e)return;const n={};for(let r=0;r<e.length;r++){const o=e.item(r);if(!o)continue;const s=e.getPropertyValue(o).trim();s&&(n[o]=s)}return Object.keys(n).length>0?n:void 0}function Bo(t){const e=String(t??"").trim();if(!e)return null;try{const n=document.createElement("template");n.innerHTML=e;const r=n.content.firstElementChild;return!r||n.content.childElementCount!==1?null:r}catch{return null}}function Nl(t){try{t.removeAttribute("id");const e=t.querySelectorAll("[id]");for(const n of Array.from(e))n.removeAttribute("id")}catch{}}function Fo(t,e,n){if(!t.isConnected)return!1;let r=null;if(n.anchorLocator){const o=we(n.anchorLocator);o&&o.parentElement===t&&(r=n.anchorPosition==="before"?o:o.nextSibling)}if(!r){const o=Array.from(t.children),s=Math.max(0,Math.min(n.insertIndex,o.length));r=o[s]??null}try{return t.insertBefore(e,r),!0}catch{return!1}}function ar(t,e,n){const r=t.parentElement;if(!r)return null;const o=String(e||"div").toLowerCase(),s=document.createElement(o);n&&Si(s,n);try{return r.insertBefore(s,t),s.appendChild(t),s}catch{return null}}function cr(t){const e=t.parentElement;if(!e||t.childElementCount!==1)return null;const n=t.firstElementChild;if(!n)return null;try{return e.insertBefore(n,t),t.remove(),n}catch{return null}}function Rl(t){const e=t.parentElement;if(!e)return null;const r=Array.from(e.children).indexOf(t);return r<0?null:{parentLocator:Se(e),insertIndex:r+1,anchorLocator:Se(t),anchorPosition:"after"}}let Ko=0;function xt(t){return Ko+=1,`tx_${t.toString(36)}_${Ko.toString(36)}`}function vi(t,e,n,r,o,s,i){const a={locator:e,styles:n};return i&&Object.keys(i).length>0&&(a.computedStyles=i),{id:t,type:"style",targetLocator:e,elementKey:s,before:a,after:{locator:e,styles:r},timestamp:o,merged:!1}}function Ho(t,e,n,r,o,s,i,a){const l=yt(n),m=a&&a.trim()?{[l]:a}:void 0;return vi(t,e,{[l]:r},{[l]:o},s,i,m)}function Pl(t,e,n,r,o,s){return{id:t,type:"text",targetLocator:e,elementKey:s,before:{locator:e,text:n},after:{locator:e,text:r},timestamp:o,merged:!1}}function Ml(t,e,n,r,o,s,i){return{id:t,type:"class",targetLocator:n,elementKey:i,before:{locator:e,classes:r},after:{locator:n,classes:o},timestamp:s,merged:!1}}function _l(t,e,n,r,o,s){return{id:t,type:"move",targetLocator:n,elementKey:s,before:{locator:e},after:{locator:n},moveData:r,timestamp:o,merged:!1}}function gn(t,e,n,r,o,s,i){return{id:t,type:"structure",targetLocator:e,elementKey:i,before:{locator:n},after:{locator:r},structureData:o,timestamp:s,merged:!1}}function At(t){var n;const e=(n=t.tagName)==null?void 0:n.toUpperCase();return e==="HTML"||e==="BODY"||e==="HEAD"}function kt(t){var n;const e=(n=t.tagName)==null?void 0:n.toUpperCase();return e==="HTML"||e==="HEAD"}function lr(t){var n;const e=(n=t.tagName)==null?void 0:n.toUpperCase();return e==="HTML"||e==="BODY"||e==="HEAD"}function Xn(t){const e=t.parentElement;if(!e)return null;const r=Array.from(e.children).indexOf(t);if(r<0)return null;const o=Se(e),s=t.nextElementSibling;if(s)return{parentLocator:o,insertIndex:r,anchorLocator:Se(s),anchorPosition:"before"};const i=t.previousElementSibling;return i?{parentLocator:o,insertIndex:r,anchorLocator:Se(i),anchorPosition:"after"}:{parentLocator:o,insertIndex:r,anchorPosition:"before"}}function Ll(t,e){var i,a;if(!t.isConnected||lr(t))return!1;const n=we(e.parentLocator);if(!n||!n.isConnected)return!1;const r=(i=t.getRootNode)==null?void 0:i.call(t),o=(a=n.getRootNode)==null?void 0:a.call(n);if(r&&o&&r!==o||t===n||t.contains(n))return!1;let s=null;if(e.anchorLocator){const l=we(e.anchorLocator);l&&l!==t&&l.parentElement===n&&(s=e.anchorPosition==="before"?l:l.nextSibling,s===t&&(s=t.nextSibling))}if(!s){const l=Array.from(n.children),m=l.indexOf(t);m!==-1&&l.splice(m,1);const P=Math.max(0,Math.min(e.insertIndex,l.length));s=l[P]??null}try{return n.insertBefore(t,s),!0}catch{return!1}}function ur(t){const e=new Set;if(t.before.styles)for(const n of Object.keys(t.before.styles))e.add(n);if(t.after.styles)for(const n of Object.keys(t.after.styles))e.add(n);return e.size===1?Array.from(e)[0]:null}function Dl(t,e,n){if(t.type!=="style"||e.type!=="style"||Math.abs(e.timestamp-t.timestamp)>n||Oe(t.targetLocator)!==Oe(e.targetLocator))return!1;const r=ur(t),o=ur(e);return!(!r||!o||r!==o)}function Bl(t,e){var o;const n=ur(t);if(!n)return!1;const r=(o=e.after.styles)==null?void 0:o[n];return r===void 0?!1:(t.after.styles||(t.after.styles={}),t.after.styles[n]=r,t.timestamp=e.timestamp,t.merged=!0,!0)}function Fl(t,e){var o,s;const n=t.structureData;if(!n)return!1;const r=e==="redo";switch(n.action){case"wrap":{if(r){const l=we(t.before.locator)??we(t.targetLocator)??we(t.after.locator);if(!l||!l.isConnected||At(l))return!1;const m=l.parentElement;if(!m||!m.isConnected||kt(m))return!1;const P=ar(l,n.wrapperTag??"div",n.wrapperStyles);if(!P||!P.isConnected)return!1;const L=Se(P);return t.after.locator=L,t.targetLocator=L,!0}const i=we(t.after.locator)??we(t.targetLocator);if(!i||!i.isConnected||At(i))return!1;const a=cr(i);return!a||!a.isConnected?!1:(t.before.locator=Se(a),!0)}case"unwrap":{if(r){const m=we(t.before.locator)??((o=we(t.after.locator))==null?void 0:o.parentElement)??((s=we(t.targetLocator))==null?void 0:s.parentElement);if(!m||!m.isConnected||At(m))return!1;const P=cr(m);if(!P||!P.isConnected)return!1;const L=Se(P);return t.after.locator=L,t.targetLocator=L,!0}const i=we(t.after.locator)??we(t.targetLocator);if(!i||!i.isConnected||At(i))return!1;const a=i.parentElement;if(!a||!a.isConnected||kt(a))return!1;const l=ar(i,n.wrapperTag??"div",n.wrapperStyles);return!l||!l.isConnected?!1:(t.before.locator=Se(l),!0)}case"delete":{if(r){const m=we(t.before.locator)??we(t.targetLocator);return!m||!m.isConnected||At(m)?!1:(m.remove(),!0)}if(!n.position||!n.html)return!1;const i=we(n.position.parentLocator);if(!i||!i.isConnected||kt(i))return!1;const a=Bo(n.html);if(!a||!Fo(i,a,n.position))return!1;const l=Se(a);return t.before.locator=l,t.targetLocator=l,!0}case"duplicate":{if(r){if(!n.position||!n.html)return!1;const a=we(n.position.parentLocator);if(!a||!a.isConnected||kt(a))return!1;const l=Bo(n.html);if(!l||!Fo(a,l,n.position))return!1;const m=Se(l);return t.after.locator=m,t.targetLocator=m,!0}const i=we(t.after.locator)??we(t.targetLocator);return!i||!i.isConnected||At(i)?!1:(i.remove(),!0)}default:return!1}}function $o(t,e){if(t.type==="move"){const o=t.moveData;if(!o)return!1;const s=e==="undo"?t.after.locator:t.before.locator,i=e==="undo"?t.before.locator:t.after.locator,a=we(s)??we(i)??we(t.targetLocator);if(!a)return!1;const l=e==="undo"?o.from:o.to;return Ll(a,l)}if(t.type==="class"){const o=e==="undo"?t.after.locator:t.before.locator,s=e==="undo"?t.before.locator:t.after.locator,i=we(o)??we(s)??we(t.targetLocator);if(!i)return!1;const a=e==="undo"?t.before:t.after,l=Array.isArray(a.classes)?a.classes:[];return Ei(i,l),!0}if(t.type==="structure")return Fl(t,e);if(t.type!=="style"&&t.type!=="text")return!0;const n=we(t.targetLocator);if(!n)return!1;const r=e==="undo"?t.before:t.after;return t.type==="style"?(Si(n,r.styles),!0):(t.type==="text"&&(n.textContent=r.text??""),!0)}function Kl(t={}){const e=new ze,n=Math.max(1,t.maxHistory??Cl),r=Math.max(0,t.mergeWindowMs??xl),o=t.now??(()=>Date.now()),s=[],i=[];function a(A,X){var N;(N=t.onChange)==null||N.call(t,{action:A,transaction:X,undoCount:s.length,redoCount:i.length})}function l(){s.length>n&&s.splice(0,s.length-n)}function m(A,X){const N=i.length>0;if(N&&(i.length=0),!N&&X&&s.length>0){const b=s[s.length-1];if(Dl(b,A,r)&&Bl(b,A)){a("merge",b);return}}s.push(A),l(),a("push",A)}function P(A,X,N,b,E){if(e.isDisposed)return null;const O=yt(X);if(!O)return null;const d=N.trim(),M=b.trim();if(d===M)return null;const j=xt(o()),ee=Ho(j,A,O,d,M,o());return m(ee,(E==null?void 0:E.merge)!==!1),ee}function L(A,X,N){if(e.isDisposed)return null;const b=String(X??""),E=String(N??"");if(b===E)return null;const O=Se(A),d=o(),M=xt(d),j=Ne(A,O.shadowHostChain),ee=Pl(M,O,b,E,d,j);return m(ee,!1),ee}function S(A,X,N){if(e.isDisposed||!A.isConnected)return null;const b=Sn(Il(A)),E=Sn(X),O=Sn(N),d=Do(E,b)?E:b;if(Do(d,O))return null;const M=o(),j=xt(M),ee=Se(A),oe=Ne(A,ee.shadowHostChain);Ei(A,O);const ie=Se(A),me=Ml(j,ee,ie,d,O,M,oe);return m(me,!1),me}function R(A,X){if(e.isDisposed||!A.isConnected||At(A))return null;const N=X==null?void 0:X.action,b=o(),E=xt(b);if(N==="wrap"){const O=A.parentElement;if(!O||!O.isConnected||kt(O))return null;const d=Se(A),M=ar(A,X.wrapperTag??"div",X.wrapperStyles);if(!M||!M.isConnected)return null;const j=Se(M),ee=Ne(M,j.shadowHostChain),oe={action:"wrap",wrapperTag:X.wrapperTag??"div",wrapperStyles:X.wrapperStyles},ie=gn(E,j,d,j,oe,b,ee);return m(ie,!1),ie}if(N==="unwrap"){const O=A,d=O.parentElement;if(!d||!d.isConnected||kt(d)||O.childElementCount!==1)return null;const M=Se(O),j=O.tagName.toLowerCase(),ee=kl(O),oe=cr(O);if(!oe||!oe.isConnected)return null;const ie=Se(oe),me=Ne(oe,ie.shadowHostChain),pe=gn(E,ie,M,ie,{action:"unwrap",wrapperTag:j,wrapperStyles:ee},b,me);return m(pe,!1),pe}if(N==="delete"){const O=Xn(A);if(!O)return null;const d=String(A.outerHTML??"").trim();if(!d)return null;const M=Se(A),j=Ne(A,M.shadowHostChain),ee=O.parentLocator;try{A.remove()}catch{return null}const ie=gn(E,M,M,ee,{action:"delete",position:O,html:d},b,j);return m(ie,!1),ie}if(N==="duplicate"){const O=A.parentElement;if(!O||!O.isConnected||kt(O))return null;const d=Rl(A);if(!d)return null;const M=Se(A),j=A.cloneNode(!0);Nl(j);try{O.insertBefore(j,A.nextSibling)}catch{return null}const ee=String(j.outerHTML??"").trim();if(!ee)return null;const oe=Se(j),ie=Ne(j,oe.shadowHostChain),ce=gn(E,oe,M,oe,{action:"duplicate",position:d,html:ee},b,ie);return m(ce,!1),ce}return null}function I(A){if(e.isDisposed||!A.isConnected||lr(A))return null;const X=Xn(A);if(!X)return null;const N=o(),b=xt(N),E=Se(A);let O=!1;function d(j){if(O||e.isDisposed||(O=!0,!j.isConnected)||lr(j))return null;const ee=Xn(j);if(!ee)return null;const oe=Oe(X.parentLocator)===Oe(ee.parentLocator),ie=X.insertIndex===ee.insertIndex,me=X.anchorPosition===ee.anchorPosition,ce=!X.anchorLocator&&!ee.anchorLocator||X.anchorLocator&&ee.anchorLocator&&Oe(X.anchorLocator)===Oe(ee.anchorLocator);if(oe&&ie&&ce&&me)return null;const pe=Se(j),ge=Ne(j,pe.shadowHostChain),V=_l(b,E,pe,{from:X,to:ee},o(),ge);return m(V,!1),V}function M(){O||e.isDisposed||(O=!0)}return{id:b,beforeLocator:E,from:X,commit:d,cancel:M}}function h(A,X){if(e.isDisposed)return null;const N=An(A);if(!N)return null;const b=N,E=yt(X);if(!E)return null;const O=Se(A),d=mn(b,E),M=Lo(A,E),j=xt(o()),ee=Ne(A,O.shadowHostChain);let oe=!1;function ie(pe){oe||e.isDisposed||Wt(b,E,pe)}function me(pe){if(oe||e.isDisposed)return null;oe=!0;const ge=mn(b,E);if(ge===d)return null;const ae=Ho(j,O,E,d,ge,o(),ee,M);return m(ae,(pe==null?void 0:pe.merge)!==!1),ae}function ce(){oe||e.isDisposed||(oe=!0,Wt(b,E,d),a("rollback",null))}return{id:j,property:E,targetLocator:O,set:ie,commit:me,rollback:ce}}function T(A,X){if(e.isDisposed)return null;const N=An(A);if(!N)return null;const b=N,E=Array.from(new Set(X.map(ae=>yt(String(ae))).filter(ae=>!!ae)));if(E.length===0)return null;const O=new Set(E),d=Se(A),M=o(),j=xt(M),ee=Ne(A,d.shadowHostChain),oe={},ie={};for(const ae of E)oe[ae]=mn(b,ae),ie[ae]=Lo(A,ae);let me=!1;function ce(ae){if(!(me||e.isDisposed))for(const[V,p]of Object.entries(ae)){const u=yt(V);!u||!O.has(u)||Wt(b,u,String(p??""))}}function pe(ae){if(me||e.isDisposed)return null;me=!0;const V={},p={},u={};for(const y of E){const D=oe[y]??"",U=mn(b,y);if(U===D)continue;V[y]=D,p[y]=U;const C=ie[y]??"";C.trim()&&(u[y]=C)}if(Object.keys(V).length===0)return null;const k=vi(j,d,V,p,o(),ee,u);return m(k,(ae==null?void 0:ae.merge)===!0),k}function ge(){if(!(me||e.isDisposed)){me=!0;for(const ae of E)Wt(b,ae,oe[ae]??"");a("rollback",null)}}return{id:j,properties:E,targetLocator:d,set:ce,commit:pe,rollback:ge}}function x(A,X,N,b){const E=h(A,X);return E?(E.set(N),E.commit(b)):null}function B(){var N;if(e.isDisposed)return null;const A=s.pop();return A?$o(A,"undo")?(i.push(A),a("undo",A),A):(s.push(A),(N=t.onApplyError)==null||N.call(t,new Error(`Failed to locate element for undo: ${A.id}`)),null):null}function K(){var N;if(e.isDisposed)return null;const A=i.pop();return A?$o(A,"redo")?(s.push(A),l(),a("redo",A),A):(i.push(A),(N=t.onApplyError)==null||N.call(t,new Error(`Failed to locate element for redo: ${A.id}`)),null):null}function _(){return s.length>0}function v(){return i.length>0}function H(){return s.slice()}function q(){return i.slice()}function Y(){s.length=0,i.length=0,a("clear",null)}t.enableKeyBindings&&e.listen(window,"keydown",A=>{var b;if((b=t.isEventFromEditorUi)!=null&&b.call(t,A)||!(A.metaKey||A.ctrlKey)||A.altKey)return;const N=A.key.toLowerCase();N==="z"?(A.shiftKey?K():B(),A.preventDefault(),A.stopPropagation(),A.stopImmediatePropagation()):N==="y"&&(K(),A.preventDefault(),A.stopPropagation(),A.stopImmediatePropagation())},Al);function F(){s.length=0,i.length=0,e.dispose()}return{beginStyle:h,beginMultiStyle:T,beginMove:I,applyStyle:x,recordStyle:P,recordText:L,recordClass:S,applyStructure:R,undo:B,redo:K,canUndo:_,canRedo:v,getUndoStack:H,getRedoStack:q,clear:Y,dispose:F}}function Yn(t){return typeof t=="number"&&Number.isFinite(t)}function Hl(t){return t/(1024*1024)}function Uo(t,e){const n=Hl(t);return Number.isFinite(n)?n.toFixed(e):"N/A"}function $l(){try{const e=performance.memory;if(!e)return null;const n=e.usedJSHeapSize,r=e.jsHeapSizeLimit,o=e.totalJSHeapSize;return!Yn(n)||!Yn(r)||!Yn(o)?null:{usedJSHeapSize:n,totalJSHeapSize:o,jsHeapSizeLimit:r}}catch{return null}}function Ul(t){const e=new ze,n=t.container,r=Math.max(100,Math.floor(t.fpsUiIntervalMs)),o=Math.max(250,Math.floor(t.memorySampleIntervalMs)),s=document.createElement("div");s.className="we-perf-hud",s.hidden=!0,s.setAttribute("aria-hidden","true");const i=document.createElement("div");i.className="we-perf-hud-line",i.textContent="FPS: --";const a=document.createElement("div");a.className="we-perf-hud-line",a.textContent="Heap: --",s.append(i,a),n.append(s),e.add(()=>s.remove());let l=!1,m=null,P=0,L=0,S=0,R=i.textContent??"",I=a.textContent??"";function h(){m!==null&&(cancelAnimationFrame(m),m=null)}e.add(h);function T(Y,F,A){if(A==="fps"){if(F===R)return;R=F}else{if(F===I)return;I=F}Y.textContent=F}function x(){const Y=$l();if(!Y){T(a,"Heap: N/A","heap");return}const F=Uo(Y.usedJSHeapSize,1),A=Uo(Y.jsHeapSizeLimit,0);T(a,`Heap: ${F} / ${A} MB`,"heap")}function B(Y){P=0,L=Y,S=Y-o,T(i,"FPS: --","fps"),x()}function K(){e.isDisposed||l&&m===null&&document.visibilityState==="visible"&&(m=requestAnimationFrame(_))}function _(Y){if(m=null,e.isDisposed||!l||document.visibilityState!=="visible")return;P+=1;const F=Y-L;if(F>=r){const A=F>0?P*1e3/F:0,X=Math.max(0,Math.round(A));T(i,`FPS: ${X}`,"fps"),P=0,L=Y}Y-S>=o&&(S=Y,x()),K()}function v(){if(l){if(document.visibilityState!=="visible"){h();return}B(performance.now()),K()}}e.listen(document,"visibilitychange",v);function H(Y){if(l!==Y){if(l=Y,!l){s.hidden=!0,h();return}s.hidden=!1,document.visibilityState==="visible"&&(B(performance.now()),K())}}function q(){return H(!l),l}return{isEnabled:()=>l,setEnabled:H,toggle:q,dispose:()=>{l=!1,s.hidden=!0,e.dispose()}}}const Ol=50,ql=8;function Gl(t={}){const e=Math.max(1,Math.floor(t.maxDeclarationsPerToken??Ol)),n=Math.max(0,Math.floor(t.maxInlineDepth??ql));function r(S){try{return S.cssRules}catch{return null}}function o(S){var R,I;if(S.disabled)return!1;try{const h=((I=(R=S.media)==null?void 0:R.mediaText)==null?void 0:I.trim())??"";return!h||h.toLowerCase()==="all"?!0:window.matchMedia(h).matches}catch{return!0}}function s(S,R){var T;const I=typeof S.href=="string"?S.href:void 0;if(I){const x=((T=I.split("/").pop())==null?void 0:T.split("?")[0])??I;return{url:I,label:x}}const h=S.ownerNode;return(h==null?void 0:h.nodeType)===Node.ELEMENT_NODE?{label:`<${h.tagName.toLowerCase()} #${R}>`}:{label:`<constructed #${R}>`}}function i(S,R){var I,h;try{const T=((h=(I=S.media)==null?void 0:I.mediaText)==null?void 0:h.trim())??"";return!T||T.toLowerCase()==="all"?!0:window.matchMedia(T).matches}catch(T){return R.push(`Failed to evaluate @media: ${String(T)}`),!1}}function a(S,R){var I;try{const h=((I=S.conditionText)==null?void 0:I.trim())??"";return!h||typeof(CSS==null?void 0:CSS.supports)!="function"?!0:CSS.supports(h)}catch(h){return R.push(`Failed to evaluate @supports: ${String(h)}`),!1}}function l(S){const R=[],I=Number((S==null?void 0:S.length)??0);for(let h=0;h<I;h++){let T="";try{T=String(S.item(h)??"").trim()}catch{continue}if(!T.startsWith("--"))continue;let x="",B=!1;try{x=String(S.getPropertyValue(T)??"").trim(),B=S.getPropertyPriority(T)==="important"}catch{}R.push({name:T,value:x,important:B})}return R}function m(S){const R=S instanceof ShadowRoot?"shadow":"document",I=[],h=new Map;let T=0,x=0,B=0;function K(Y){const F=h.get(Y.name)??[];F.length>=e||(F.push({...Y,order:B++}),h.set(Y.name,F),x++)}function _(Y,F){var A,X,N;for(const b of Array.from(Y)){if(T++,b.type===CSSRule.IMPORT_RULE){const O=b,d=O.styleSheet;if(d&&!F.visited.has(d)){try{const ee=((X=(A=O.media)==null?void 0:A.mediaText)==null?void 0:X.trim())??"";if(ee&&ee.toLowerCase()!=="all"&&!window.matchMedia(ee).matches)continue}catch{}if(!o(d))continue;const M=r(d),j=s(d,F.sheetIndex);if(!M){I.push(`Skipped @import (cross-origin): ${j.url??j.label}`);continue}F.visited.add(d);try{_(M,{...F,source:j})}finally{F.visited.delete(d)}}continue}if(b.type===CSSRule.MEDIA_RULE){i(b,I)&&_(b.cssRules,F);continue}if(b.type===CSSRule.SUPPORTS_RULE){a(b,I)&&_(b.cssRules,F);continue}if(b.type===CSSRule.STYLE_RULE){const O=b,d=String(O.selectorText??"").trim()||void 0,M=l(O.style);for(const j of M)K({name:j.name,value:j.value,important:j.important,origin:"rule",rootType:R,styleSheet:F.source,selectorText:d});continue}const E=b;if((N=E.cssRules)!=null&&N.length)try{_(E.cssRules,F)}catch{}}}const v=S,H=[];try{for(const Y of Array.from(v.styleSheets??[]))Y instanceof CSSStyleSheet&&H.push(Y)}catch{}try{const Y=Array.from(v.adoptedStyleSheets??[]);for(const F of Y)F instanceof CSSStyleSheet&&H.push(F)}catch{}for(let Y=0;Y<H.length;Y++){const F=H[Y];if(!o(F))continue;const A=s(F,Y),X=r(F);if(!X){I.push(`Skipped stylesheet (cross-origin): ${A.url??A.label}`);continue}_(X,{sheetIndex:Y,source:A,visited:new Set([F])})}const q={styleSheets:H.length,rulesScanned:T,tokens:h.size,declarations:x};return{rootType:R,tokens:h,warnings:[...new Set(I)],stats:q}}function P(S){var R;if(S.parentElement)return S.parentElement;try{const I=(R=S.getRootNode)==null?void 0:R.call(S);if(I instanceof ShadowRoot)return I.host}catch{}return null}function L(S,R){const I=Math.max(0,Math.floor((R==null?void 0:R.maxDepth)??n)),h=new Set;let T=S,x=0;for(;T&&x<=I;){x++;try{const B=T.style;if(B){const K=Number(B.length??0);for(let _=0;_<K;_++){const v=String(B.item(_)??"").trim();v.startsWith("--")&&h.add(v)}}}catch{}T=P(T)}return h}return{collectRootIndex:m,collectInlineTokenNames:L}}function Vl(t={}){const e=!!t.enableProbe;function n(l,m){const P=typeof m=="string"?m.trim():"";return P?`var(${l}, ${P})`:`var(${l})`}function r(l){const m=String(l??"").trim();if(!m.toLowerCase().startsWith("var("))return null;let P=0,L=-1;for(let x=0;x<m.length;x++){const B=m[x];if(B==="(")P++;else if(B===")"&&(P--,P===0)){L=x;break}}if(L<0||L!==m.length-1)return null;const S=m.slice(4,L).trim();if(!S)return null;let R=-1;P=0;for(let x=0;x<S.length;x++){const B=S[x];if(B==="(")P++;else if(B===")")P=Math.max(0,P-1);else if(B===","&&P===0){R=x;break}}const I=(R>=0?S.slice(0,R):S).trim(),h=R>=0?S.slice(R+1).trim():"";if(!I.startsWith("--"))return null;const T=I;return h?{name:T,fallback:h}:{name:T}}function o(l){var R;const m=[],P=String(l??""),L=/var\(\s*(--[\w-]+)/g;let S;for(;S=L.exec(P);){const I=(R=S[1])==null?void 0:R.trim();I!=null&&I.startsWith("--")&&m.push(I)}return m}function s(l,m){try{return window.getComputedStyle(l).getPropertyValue(m).trim()}catch{return""}}function i(l,m){const P=s(l,m);return{token:m,computedValue:P,availability:P?"available":"unset"}}function a(l,m,P,L={}){const S=n(m,L.fallback),R=e&&L.preview?"probe":"computed";let I;return R==="computed"&&L.preview&&(I=s(l,m)||void 0),{token:m,cssProperty:P,cssValue:S,resolvedValue:I,method:R}}return{formatCssVar:n,parseCssVar:r,extractCssVarNames:o,readComputedValue:s,resolveToken:i,resolveTokenForProperty:a}}function zl(t={}){const e=new ze,n=t.now??(()=>performance.now()),r=Math.max(0,Math.floor(t.cacheMaxAgeMs??0)),o=t.observeHead!==!1,s=!!t.observeShadowRoots,i=Math.max(0,Math.floor(t.maxInlineDepth??8)),a=t.detector??Gl(t.detectorOptions),l=t.resolver??Vl(t.resolverOptions),m=new WeakMap,P=new WeakSet,L=new Set;function S(b){return b instanceof ShadowRoot?"shadow":"document"}function R(b,E){const O={root:b,rootType:S(b),reason:E,timestamp:n()};for(const d of L)try{d(O)}catch{}}function I(b){var E;try{const O=(E=b.getRootNode)==null?void 0:E.call(b);return O instanceof ShadowRoot?O:b.ownerDocument??document}catch{return b.ownerDocument??document}}function h(b){if(P.has(b))return;if(P.add(b),b instanceof ShadowRoot){if(!s)return;e.observeMutation(b,()=>x(b,"shadow_mutation"),{childList:!0,subtree:!0,characterData:!0,attributes:!0});return}if(!o)return;const E=b.head;E&&e.observeMutation(E,()=>x(b,"head_mutation"),{childList:!0,subtree:!0,characterData:!0,attributes:!0})}function T(b){const E=m.get(b);if(E)if(r>0)if(n()-E.collectedAt>=r)x(b,"ttl");else return E.index;else return E.index;const O=a.collectRootIndex(b);return m.set(b,{index:O,collectedAt:n()}),O}function x(b,E="manual"){m.delete(b),R(b,E)}function B(b,E){const O=[...E].sort((d,M)=>d.order-M.order);return{name:b,kind:"unknown",declarations:O}}function K(b,E={}){h(b);const O=T(b),d=[];for(const[M,j]of O.tokens)d.push(B(M,j));return E.sortByName!==!1&&d.sort((M,j)=>M.name.localeCompare(j.name)),{tokens:d,warnings:O.warnings,stats:O.stats}}function _(b,E={}){const O=I(b);h(O);const d=T(O),M=new Set;for(const ie of d.tokens.keys())M.add(ie);if(E.includeInlineAncestors!==!1){const ie=E.inlineMaxDepth??i,me=a.collectInlineTokenNames(b,{maxDepth:ie});for(const ce of me)M.add(ce)}const ee=[];let oe=null;try{oe=window.getComputedStyle(b)}catch{}if(oe)for(const ie of M){let me="";try{me=oe.getPropertyValue(ie).trim()}catch{}if(!me)continue;const ce=d.tokens.get(ie)??[];ee.push({token:B(ie,ce),computedValue:me})}return E.sortByName!==!1&&ee.sort((ie,me)=>ie.token.name.localeCompare(me.token.name)),{tokens:ee,warnings:d.warnings,stats:d.stats}}function v(b,E){return l.resolveToken(b,E)}function H(b,E,O,d){return l.resolveTokenForProperty(b,E,O,d)}function q(b,E){return l.formatCssVar(b,E)}function Y(b){return l.parseCssVar(b)}function F(b){return l.extractCssVarNames(b)}function A(b,E,O,d,M){const j=q(d,M==null?void 0:M.fallback);return b.applyStyle(E,O,j,{merge:M==null?void 0:M.merge})}function X(b){return L.add(b),()=>L.delete(b)}function N(){L.clear(),e.dispose()}return{getRootTokens:K,getContextTokens:_,resolveToken:v,resolveTokenForProperty:H,formatCssVar:q,parseCssVar:Y,extractCssVarNames:F,invalidateRoot:x,onInvalidation:X,applyTokenToStyle:A,dispose:N}}let Wl=async()=>cs(()=>import("./index.js?v=1775123024591"),__vite__mapDeps([0,1,2,3,4,5,6]));function gr(t){return t instanceof HTMLElement&&t.isConnected}function Xl(t){if(!gr(t))return"当前没有可导出的元素"}function Yl(t){var e,n;for(const r of[t.getAttribute("data-axhub-display-name"),t.getAttribute("aria-label"),t.getAttribute("data-page-id"),t.getAttribute("data-component-id"),t.id,t.getAttribute("data-testid")]){if(typeof r!="string")continue;const o=r.trim();if(o)return o}return((n=(e=t.tagName)==null?void 0:e.toUpperCase)==null?void 0:n.call(e))||"FRAME"}async function jl(t){if(!navigator.clipboard||typeof navigator.clipboard.writeText!="function")throw new Error("当前环境不支持文本复制,请检查浏览器剪贴板权限后重试。");await navigator.clipboard.writeText(JSON.stringify(t))}async function Jl(t,e){if(!gr(e))throw new Error("当前没有可导出的元素。");const n=Yl(e),{htmlToAxure:r,htmlToFigma:o,safeCopyToFigmaWithKiwi:s}=await Wl();if(t==="figma"||t==="pencil"){const a=await o(e,{rootName:n,enableAutoLayout:!0}),l=await s({layers:Array.isArray(a)?a:[]});if(l.skipped)throw l.reason==="clipboard_unavailable"?new Error("当前环境不支持剪贴板写入,请检查浏览器权限后重试。"):new Error(`导出到 ${t} 失败。`);return}const i=await r(e,{rootName:n,preserveHierarchy:!1,preserveSvgIcons:!0});await jl(i)}function Ql(t){const{state:e,options:n,services:r,onStatusChange:o}=t;function s(){const I=Array.from(e.editMetaByKey.values()).filter(x=>x.dirtySince!==null||String(x.note??"").trim()||Array.isArray(x.images)&&x.images.length>0).sort((x,B)=>Number(B.dirtySince??0)-Number(x.dirtySince??0)),h=[],T=new Set;for(const x of I)try{const B=we(x.locator);B!=null&&B.isConnected&&!T.has(B)&&(T.add(B),h.push(B))}catch{}return h}function i(I){var T;const h=s();return h.length>0?h:I!=null&&I.isConnected?[I]:(T=e.selectedElement)!=null&&T.isConnected?[e.selectedElement]:[]}function a(I){var h;return I!=null&&I.isConnected?I:(h=e.selectedElement)!=null&&h.isConnected?e.selectedElement:s()[0]??null}function l(I){console.error(`${Ke} Transaction apply error:`,I)}function m(){var I,h,T,x,B,K,_,v,H,q,Y,F,A,X,N,b,E;(I=r.integrationWs)==null||I.stop(),r.genieBridge.stop(),(h=e.uiResizeCleanup)==null||h.call(e),e.uiResizeCleanup=null,(T=e.propertyPanel)==null||T.dispose(),e.propertyPanel=null,(x=e.tokensService)==null||x.dispose(),e.tokensService=null,(B=e.breadcrumbs)==null||B.dispose(),e.breadcrumbs=null,(K=e.eventController)==null||K.dispose(),e.eventController=null,(_=e.annotationShortcutCleanup)==null||_.call(e),e.annotationShortcutCleanup=null,e.textAnnotationTargetElement&&(e.textAnnotationTargetElement.remove(),e.textAnnotationTargetElement=null),(v=e.dragReorderController)==null||v.dispose(),e.dragReorderController=null,(H=e.handlesController)==null||H.dispose(),e.handlesController=null,(q=e.parentSelectController)==null||q.dispose(),e.parentSelectController=null,(Y=e.transactionManager)==null||Y.dispose(),e.transactionManager=null,(F=e.positionTracker)==null||F.dispose(),e.positionTracker=null,(A=e.selectionEngine)==null||A.dispose(),e.selectionEngine=null,(X=e.perfHotkeyCleanup)==null||X.call(e),e.perfHotkeyCleanup=null,(N=e.perfMonitor)==null||N.dispose(),e.perfMonitor=null,(b=e.canvasOverlay)==null||b.dispose(),e.canvasOverlay=null,(E=e.shadowHost)==null||E.dispose(),e.shadowHost=null,Ea(e)}function P(){const I=T=>{if(T.repeat||!(T.metaKey||T.ctrlKey)||!T.shiftKey||T.altKey||(T.key||"").toLowerCase()!=="p")return;const K=e.perfMonitor;K&&(K.toggle(),T.preventDefault(),T.stopPropagation(),T.stopImmediatePropagation())},h={capture:!0,passive:!1};window.addEventListener("keydown",I,h),e.perfHotkeyCleanup=()=>{window.removeEventListener("keydown",I,h)}}function L(){let I=null,h=null;const T=()=>{e.propertyPanel&&e.propertyPanelPosition&&e.propertyPanel.setPosition(e.propertyPanelPosition)},x=()=>{!e.active||I!==null||(I=window.requestAnimationFrame(()=>{I=null,T()}))},B=()=>{!e.active||h!==null||(h=window.requestAnimationFrame(()=>{h=null,r.changes.renderChangeMarkers()}))},K=typeof(document==null?void 0:document.addEventListener)=="function";window.addEventListener("resize",x,{passive:!0}),window.addEventListener("resize",B,{passive:!0}),window.addEventListener("scroll",B,{passive:!0,capture:!0}),K&&document.addEventListener("scroll",B,{passive:!0,capture:!0}),e.uiResizeCleanup=()=>{window.removeEventListener("resize",x),window.removeEventListener("resize",B),window.removeEventListener("scroll",B,!0),K&&document.removeEventListener("scroll",B,!0),I!==null&&(window.cancelAnimationFrame(I),I=null),h!==null&&(window.cancelAnimationFrame(h),h=null)},T()}function S(){var I;if(e.active){console.log(`${Ke} Already active`);return}try{Sa(e),e.shadowHost=oc({});const h=e.shadowHost.getElements();if(!(h!=null&&h.overlayRoot))throw new Error("Shadow host overlayRoot not available");const T=()=>{e.changeMarkersVisible||(e.changeMarkersVisible=!0,r.persistence.setMarkerVisibility(!0))};e.changeMarkersVisible=r.persistence.readMarkerVisibility(),T(),e.annotationShortcutSettings=r.persistence.readAnnotationShortcutSettings(),e.uiSettings=r.persistence.readUiSettings();const x=document.createElement("div");x.className="we-change-markers",x.hidden=!0,h.uiRoot.append(x),e.markerLayer=x,e.canvasOverlay=xc({container:h.overlayRoot}),e.perfMonitor=Ul({container:h.overlayRoot,fpsUiIntervalMs:500,memorySampleIntervalMs:1e3}),P();const B=n.interactionProfile==="text-annotation";if(B){const K=document.createElement("div");K.setAttribute(ii,"true"),K.setAttribute("aria-hidden","true"),Object.assign(K.style,{position:"fixed",left:"0px",top:"0px",width:"1px",height:"1px",opacity:"0",pointerEvents:"none",userSelect:"none"}),h.overlayRoot.append(K),e.textAnnotationTargetElement=K,e.textAnnotationManager=fl({isOverlayElement:e.shadowHost.isOverlayElement}),e.selectionEngine=null}else e.selectionEngine=rl({isOverlayElement:e.shadowHost.isOverlayElement}),e.textAnnotationManager=null,e.textAnnotationTargetElement=null;if(e.positionTracker=Tl({onPositionUpdate:r.interaction.handlePositionUpdate}),e.annotationShortcutCleanup=null,e.transactionManager=Kl({enableKeyBindings:!0,isEventFromEditorUi:K=>{var _;return!!((_=e.shadowHost)!=null&&_.isEventFromUi(K))},onChange:r.interaction.handleTransactionChange,onApplyError:l}),r.persistence.restoreCachedChanges(),r.genieBridge.rehydratePersistedGenieState(),T(),r.persistence.persistFromTransactions(),e.handlesController=Uc({container:h.overlayRoot,canvasOverlay:e.canvasOverlay,transactionManager:e.transactionManager,positionTracker:e.positionTracker}),e.parentSelectController=zc({container:h.overlayRoot,getParentCandidate:K=>{var _;return((_=e.selectionEngine)==null?void 0:_.getParentCandidate(K))??null},onSelectParent:K=>{const _=K.getBoundingClientRect(),v=Number.isFinite(_.left)?_.left+_.width/2:void 0,H=Number.isFinite(_.top)?_.top+Math.min(18,Math.max(10,_.height/2)):void 0;r.interaction.handleSelect(K,{alt:!1,shift:!1,ctrl:!1,meta:!1},v!==void 0&&H!==void 0?{clientX:v,clientY:H}:void 0)}}),e.eventController=yl({isOverlayElement:e.shadowHost.isOverlayElement,allowNativeTextSelection:B,onHover:B?()=>{}:r.interaction.handleHover,onSelect:B?()=>{}:K=>r.interaction.handleSelect(K.element,K.modifiers,{clientX:K.clientX,clientY:K.clientY}),onDeselect:r.interaction.handleDeselect,resolveTargetForHover:B?void 0:K=>r.genieBridge.resolveSelectableElement(K),findTargetForSelect:B?void 0:(K,_,v,H)=>{var Y;const q=((Y=e.selectionEngine)==null?void 0:Y.findBestTargetFromEvent(H,v))??null;return r.genieBridge.resolveSelectableElement(q)},getSelectedElement:()=>e.selectedElement,isElementInteractionLocked:K=>r.genieBridge.isElementInteractionLocked(K)}),B&&e.textAnnotationManager){const K=e.textAnnotationManager;let _=null;const v=()=>{_!==null&&window.clearTimeout(_),_=window.setTimeout(()=>{var X,N;_=null;const H=K.commitSelection();if(!H)return;e.activeTextAnnotation=H;const q=K.setActiveHighlight(H);(X=e.canvasOverlay)==null||X.setTextHighlightRects(q?null:H.clientRects),(N=e.canvasOverlay)==null||N.render();const Y=H.boundingRect,F=Y.left+Y.width/2,A=Y.top;r.interaction.enterTextAnnotation(H,{clientX:F,clientY:A})},10)};window.addEventListener("pointerup",v,{capture:!0}),window.addEventListener("mouseup",v,{capture:!0}),e.annotationShortcutCleanup=()=>{_!==null&&(window.clearTimeout(_),_=null),window.removeEventListener("pointerup",v,{capture:!0}),window.removeEventListener("mouseup",v,{capture:!0})}}if(n.ui.propertyPanel?e.tokensService=zl():e.tokensService=null,n.ui.propertyPanel||n.ui.breadcrumbs){const K=v=>{if(!v.isConnected)return;const H=v.getBoundingClientRect(),q=Number.isFinite(H.left)?H.left+H.width/2:void 0,Y=Number.isFinite(H.top)?H.top+Math.min(18,Math.max(10,H.height/2)):void 0;r.interaction.handleSelect(v,{alt:!1,shift:!1,ctrl:!1,meta:!1},q!==void 0&&Y!==void 0?{clientX:q,clientY:Y}:void 0)},_=vc({container:h.uiRoot,shadowRoot:h.shadowRoot,breadcrumbsOptions:n.ui.breadcrumbs?{container:h.uiRoot,dock:"top",onSelect:K,getGenieBridgeAvailable:()=>r.genieBridge.isAvailable(),getElementGenieTaskState:v=>r.genieBridge.getElementTaskState(v),getVisibleElementGenieTaskStates:()=>r.genieBridge.getVisibleTaskStates(),dismissElementGenieTaskState:v=>r.genieBridge.dismissElementTaskState(v),onSendToGenie:n.genieBridge.enableContextAppend?v=>{v.isConnected&&r.genieBridge.handleSendSelectionToGenie(v)}:void 0,getElementStyleSummaryLines:v=>{var H;return((H=r.changes.getMetaForElement(v))==null?void 0:H.styleSummaryLines)??[]},onSelectParent:v=>{var q;const H=((q=e.selectionEngine)==null?void 0:q.getParentCandidate(v))??null;H&&K(H)}}:null,propertyPanelOptions:n.ui.propertyPanel?{container:h.uiRoot,transactionManager:e.transactionManager,tokensService:e.tokensService??void 0,initialPosition:e.propertyPanelPosition,initialUiMode:e.annotationEntryMode,onPositionChange:v=>{e.propertyPanelPosition=v},getUiMode:()=>e.annotationEntryMode,onUiModeChange:v=>{var H;e.annotationEntryMode=v,(H=e.positionTracker)==null||H.forceUpdate(!0),r.changes.renderChangeMarkers()},getAnnotationShortcutSettings:()=>e.annotationShortcutSettings,onAnnotationShortcutSettingsChange:v=>{e.annotationShortcutSettings=v,r.persistence.setAnnotationShortcutSettings(v)},getUiSettings:()=>e.uiSettings,interactionProfile:n.interactionProfile,onUiSettingsChange:v=>{e.uiSettings=v,r.persistence.setUiSettings(v)},onAnnotationShortcutDialogOpenChange:v=>{e.annotationShortcutDialogOpen=v},onUndo:()=>{var v;return(v=e.transactionManager)==null?void 0:v.undo()},onRedo:()=>{var v;return(v=e.transactionManager)==null?void 0:v.redo()},onCopyPrompt:r.localActions.handleCopyPrompt,onWakeGenie:async()=>{try{return await r.genieBridge.requestWake()}catch(v){const H=v instanceof Error?v.message:String(v);return H&&r.feedback.toast("warning",H),!1}},onSendPromptToGenie:async v=>{var Y;const H=i(v);if(H.length===0)throw new Error("当前没有可发送到 Genie 的编辑元素。");const q=r.genieBridge.hasReusableConversation()?r.summaries.buildAppendSaveRunPrompt():r.summaries.buildSaveRunPrompt();try{await r.genieBridge.handleSendPromptToGenieForElements(H,q)}finally{(Y=e.positionTracker)==null||Y.forceUpdate(!0)}},onSendCurrentElementPromptToGenie:async v=>{var q;if(!(v!=null&&v.isConnected))throw new Error("当前元素已失效,请重新选择后再试。");const H=r.genieBridge.hasReusableConversation()?r.summaries.buildAppendSaveRunPromptForElement(v):r.summaries.buildSaveRunPromptForElement(v);if(!H)throw new Error("当前元素没有可发送到 Genie 的编辑。");try{await r.genieBridge.handleSendPromptToGenieForElement(v,H)}finally{(q=e.positionTracker)==null||q.forceUpdate(!0)}},onAbortSendPromptToGenie:v=>{const H=a(v);if(!H)throw new Error("当前没有可中断的 Genie 编辑元素。");return r.genieBridge.interruptElementTask(H)},onRequestClose:r.interaction.clearSelection,onClearEdits:r.localActions.handleClearEdits,onClearCurrentElementEdits:async v=>{const H=await r.localActions.handleClearElementEdits(v);return H&&r.genieBridge.dismissElementTaskState(v),H},getCopyPromptBlockReason:r.summaries.getCopyPromptBlockReason,showCopyPromptAction:n.ui.showCopyPromptAction,getGenieBridgeAvailable:()=>r.genieBridge.isAvailable(),getGenieBridgeConnected:()=>r.genieBridge.isConnected(),getCanAbortSendPromptToGenie:v=>r.genieBridge.canInterruptElementTask(a(v)),getHasReusableGenieConversation:()=>r.genieBridge.hasReusableConversation(),getElementGenieTaskState:v=>r.genieBridge.getElementTaskState(v),getVisibleElementGenieTaskStates:()=>r.genieBridge.getVisibleTaskStates(),dismissElementGenieTaskState:v=>r.genieBridge.dismissElementTaskState(v),getSendPromptToGenieBlockReason:v=>i(v).length===0?"当前没有可发送到 Genie 的编辑元素":r.summaries.getSaveRunPromptBlockReason(),getSendCurrentElementPromptToGenieBlockReason:v=>v!=null&&v.isConnected?r.summaries.getSaveRunPromptForElementBlockReason(v):"当前元素已失效,请重新选择后再试。",canExportSelectionToDesignTool:(v,H)=>{const q=a(H);return gr(q)},onExportSelectionToDesignTool:async(v,H)=>{const q=a(H);if(!q)throw new Error("当前没有可导出的元素。");try{await Jl(v,q),r.feedback.toast("success",`已导出到 ${v}`)}catch(Y){const F=Y instanceof Error?Y.message:String(Y);r.feedback.toast("error",F||`导出到 ${v} 失败`)}},getExportSelectionToDesignToolBlockReason:(v,H)=>{const q=a(H);return q?r.genieBridge.isElementInteractionLocked(q)?"当前元素正在由 Genie 更新":Xl(q):"当前没有可导出的元素"},canEditText:v=>r.textSession.isEditable(v),getTextValue:v=>r.textSession.getText(v),onTextValueChange:(v,H)=>{r.textSession.commitText(v,H)},getAiNote:v=>{var H;return((H=r.changes.getMetaForElement(v))==null?void 0:H.note)??""},getAiNoteImages:v=>r.changes.getImagesForElement(v),getHoveredElement:()=>e.hoveredElement,onRememberSelectionAnchor:(v,H)=>{r.changes.rememberSelectionAnchor(v,H)},onAiNoteChange:(v,H)=>{var q;r.changes.setNoteForElement(v,H),(q=e.positionTracker)==null||q.forceUpdate(!0)},onAiNoteImagesChange:(v,H)=>{var q;r.changes.setImagesForElement(v,H),(q=e.positionTracker)==null||q.forceUpdate(!0)},onDismissSelection:r.interaction.clearSelection,getChangeMarkersVisible:()=>e.changeMarkersVisible,onChangeMarkersVisible:r.changes.setChangeMarkersVisible,getModifiedElementCount:()=>Array.from(e.editMetaByKey.values()).filter(v=>v.dirtySince!==null).length,onSelectionChromeVisibleChange:v=>{var H,q,Y,F,A,X;e.selectionChromeVisible=v,v?(X=e.positionTracker)==null||X.forceUpdate(!0):((H=e.canvasOverlay)==null||H.setHoverRect(null),(q=e.canvasOverlay)==null||q.setSelectionEffect("default"),(Y=e.canvasOverlay)==null||Y.setSelectionRect(null),(F=e.canvasOverlay)==null||F.render(),(A=e.handlesController)==null||A.setSelectionRect(null)),o==null||o()},onPromptCardVisibleChange:v=>{var H;e.promptCardVisible!==v&&(e.promptCardVisible=v,r.changes.renderChangeMarkers(),(H=e.positionTracker)==null||H.forceUpdate(!0),o==null||o())},onToggleSelectionMode:v=>{var H,q;if(v){const Y=e.selectedElement,F=!!Y&&Y.isConnected;(H=e.eventController)==null||H.setMode(F?"selecting":"hover")}else(q=e.eventController)==null||q.setMode("interaction")}}:null});e.breadcrumbs=_.breadcrumbs,e.propertyPanel=_.propertyPanel}else e.breadcrumbs=null,e.propertyPanel=null;e.propertyPanel&&(e.propertyPanel.setHistory(e.transactionManager.getUndoStack().length,e.transactionManager.getRedoStack().length),e.propertyPanel.refresh()),r.changes.renderChangeMarkers(),L(),e.active=!0,r.genieBridge.start(),(I=r.integrationWs)==null||I.start(),o==null||o(),console.log(`${Ke} Started`)}catch(h){m(),e.active=!1,o==null||o(),console.error(`${Ke} Failed to start:`,h)}}function R(){if(e.active){e.active=!1;try{r.persistence.flushPendingWrite(),m(),o==null||o(),console.log(`${Ke} Stopped`)}catch(I){console.error(`${Ke} Error during cleanup:`,I),m(),o==null||o()}}}return{start:S,stop:R}}function Zl(t){async function e(){var i,a,l;const o=t.summaries.buildCopyPrompt(),s=(a=(i=t.summaries).getCopyPromptFilteredNotice)==null?void 0:a.call(i);if(!o){t.feedback.toast("info","你好像还没有修改任何内容哦。");return}try{(l=navigator.clipboard)!=null&&l.writeText?await navigator.clipboard.writeText(o):await t.feedback.prompt({title:"请手动复制以下内容",content:s?`浏览器未提供剪贴板权限,请手动复制下面的内容。
|
||
|
||
提示:${s}`:"浏览器未提供剪贴板权限,请手动复制下面的内容。",label:"待复制内容",defaultValue:o,confirmText:"知道了",multiline:!0,readOnly:!0,rows:12,selectOnOpen:!0}),t.feedback.toast("success",s?`已复制到剪贴板。${s}`:"已复制到剪贴板。")}catch{await t.feedback.prompt({title:"请手动复制以下内容",content:s?`自动复制失败,请手动复制下面的内容。
|
||
|
||
提示:${s}`:"自动复制失败,请手动复制下面的内容。",label:"待复制内容",defaultValue:o,confirmText:"知道了",multiline:!0,readOnly:!0,rows:12,selectOnOpen:!0}),t.feedback.toast("error","自动复制失败(已提供手动复制)。")}}async function n(o={}){var i,a;const s=t.state.transactionManager;if(s&&!(!o.skipConfirm&&!await t.feedback.confirm({title:"清空全部编辑",content:"确定要清空所有待修改内容吗?已保存的修改不受影响。",confirmText:"清空",cancelText:"取消",confirmTone:"primary"}))){for(;s.canUndo();)s.undo();s.clear(),t.changes.clearAllEditMeta(),t.persistence.clearStorage(),(i=t.state.propertyPanel)==null||i.refresh(),(a=t.onStatusChange)==null||a.call(t)}}async function r(o){var P,L;if(!o||!o.isConnected)return!1;const s=t.changes.getMetaForElement(o),i=!!t.changes.normalizeNote((s==null?void 0:s.note)??"").trim(),a=!!(s!=null&&s.images.length),l=!!(s!=null&&s.changeKinds.length),m=!!(s&&s.dirtySince!==null&&!l);if(s!=null&&s.changeKinds.some(S=>S==="style"||S==="class"),!i&&!a&&!l&&!m)return t.feedback.toast("info","当前项没有可清空的待修改内容。"),!1;if(l&&s){const S=await t.interaction.revertElement(s.elementKey);if(!S.success)return await t.feedback.alert({title:"清空编辑",content:`清空失败:${S.error??"无法回退该元素修改。"}`,confirmText:"知道了"}),!1}return i&&t.changes.setNoteForElement(o,""),a&&t.changes.setImagesForElement(o,[]),s&&t.changes.markElementEditsHandled(o),(P=t.state.propertyPanel)==null||P.refresh(),t.feedback.toast("success","已清空当前编辑。"),(L=t.onStatusChange)==null||L.call(t),!0}return{handleCopyPrompt:e,handleClearEdits:n,handleClearElementEdits:r}}const Oo=4,eu="web-editor-v2-cache:",tu="web-editor-v2-markers:",nu="web-editor-v2-annotation-shortcuts:",qo="web-editor-v2-ui-settings",ru="web-editor-v2-genie-conversation:",ou="web-editor-v2-genie-tasks:";function iu(t){const{state:e,changes:n}=t,r=t.getResourceContext??(()=>null),o=t.interactionProfile??"design";let s=null,i=!1;function a(V){var p;try{const u=r(),k=(p=u==null?void 0:u.meta)==null?void 0:p[V];return typeof k=="string"?k.trim():""}catch{return""}}function l(V){const u=String(V??"").trim().replace(/\\/g,"/").match(/^src\/(components|prototypes|themes)\/([^/]+)/);return u?`${u[1]}/${u[2]}`:""}function m(){try{const p=r(),u=String((p==null?void 0:p.path)??"").trim()||a("targetPath")||l(a("currentFilePath"));if(u)return u}catch{}if(typeof window>"u")return null;const V=window.location.pathname.match(/\/(components|prototypes)\/([^/]+)/);return V?`${V[1]}/${V[2]}`:null}function P(){const V=a("storageScope")||a("currentFilePath")||a("docPath")||m();return V||(typeof window>"u"?null:String(window.location.pathname??"").trim()||null)}function L(){if(typeof window>"u")return null;const V=P()??"",p=String(V??"").trim();return p?`${eu}${p}`:null}function S(){if(typeof window>"u")return null;const V=L();if(!V)return null;try{const p=window.localStorage.getItem(V);if(!p)return null;const u=JSON.parse(p);return!u||![1,2,3,Oo].includes(Number(u.version??0))||!Array.isArray(u.entries)?null:u}catch{return null}}function R(){if(typeof window>"u")return null;const V=P()??"",p=String(V??"").trim();return p?`${tu}${p}`:null}function I(){var u;if(typeof window>"u")return!0;const V=(u=S())==null?void 0:u.showMarkers;if(typeof V=="boolean")return V;const p=R();if(!p)return!0;try{const k=window.localStorage.getItem(p);if(k==="false")return!1;if(k==="true")return!0}catch{}return!0}function h(){if(typeof window>"u")return null;const V=P()??"",p=String(V??"").trim();return p?`${nu}${p}`:null}function T(V){if(typeof window>"u")return null;try{const p=window.localStorage.getItem(V);return p?JSON.parse(p):null}catch{return null}}function x(V,p){if(!(typeof window>"u"))try{window.localStorage.setItem(V,JSON.stringify(p))}catch{}}function B(V){if(!(typeof window>"u"))try{window.localStorage.removeItem(V)}catch{}}function K(V){return`${ru}${V}`}function _(V){return`${ou}${V}`}function v(V){if(!V||typeof V!="object")return null;const p=V,u=String(p.scopeKey??"").trim(),k=String(p.sessionId??"").trim();if(!u||!k)return null;const y=Number(p.createdAt??0),D=Number(p.lastUsedAt??y),U=Math.max(0,Math.floor(Number(p.sentCount??0))),C=Number(p.expiresAt??y);return{scopeKey:u,sessionId:k,provider:typeof p.provider=="string"&&p.provider.trim()?p.provider.trim():null,projectPath:typeof p.projectPath=="string"&&p.projectPath.trim()?p.projectPath.trim():null,createdAt:Number.isFinite(y)?y:0,lastUsedAt:Number.isFinite(D)?D:Number.isFinite(y)?y:0,sentCount:Number.isFinite(U)?U:0,expiresAt:Number.isFinite(C)?C:0,invalidated:!!p.invalidated,sessionPath:typeof p.sessionPath=="string"&&p.sessionPath.trim()?p.sessionPath.trim():null,sessionUrl:typeof p.sessionUrl=="string"&&p.sessionUrl.trim()?p.sessionUrl.trim():null}}function H(V){if(!V||typeof V!="object")return null;const p=V,u=String(p.scopeKey??"").trim(),k=String(p.requestId??"").trim();if(!u||!k||!p.locator)return null;const y=p.status;if(y!=="pending"&&y!=="created"&&y!=="completed"&&y!=="error")return null;const D=Number(p.startedAt??0),U=Number(p.updatedAt??D),C=Number(p.lastEventAt??U);return{scopeKey:u,elementKey:String(p.elementKey??"").trim()||Oe(p.locator),locator:p.locator,label:String(p.label??"").trim(),requestId:k,sessionId:typeof p.sessionId=="string"&&p.sessionId.trim()?p.sessionId.trim():null,sessionPath:typeof p.sessionPath=="string"&&p.sessionPath.trim()?p.sessionPath.trim():null,sessionUrl:typeof p.sessionUrl=="string"&&p.sessionUrl.trim()?p.sessionUrl.trim():null,provider:typeof p.provider=="string"&&p.provider.trim()?p.provider.trim():null,status:y,message:String(p.message??"").trim(),startedAt:Number.isFinite(D)?D:0,updatedAt:Number.isFinite(U)?U:Number.isFinite(D)?D:0,dismissed:!!p.dismissed,recoveryPending:!!p.recoveryPending,lastEventAt:Number.isFinite(C)?C:Number.isFinite(U)?U:0,errorCode:typeof p.errorCode=="string"&&p.errorCode.trim()?p.errorCode.trim():null}}function q(V){if(typeof window>"u")return;const p=R();if(p)try{window.localStorage.setItem(p,V?"true":"false")}catch{}}function Y(){if(typeof window>"u")return{...zt};const V=h();if(!V)return{...zt};try{const p=window.localStorage.getItem(V);return p?Mr(JSON.parse(p)):{...zt}}catch{return{...zt}}}function F(V){if(typeof window>"u")return;const p=h();if(p)try{window.localStorage.setItem(p,JSON.stringify(Mr(V)))}catch{}}function A(){if(typeof window>"u")return{...wt};try{const V=window.localStorage.getItem(qo);return V?Lt(JSON.parse(V)):{...wt}}catch{return{...wt}}}function X(V){if(!(typeof window>"u"))try{window.localStorage.setItem(qo,JSON.stringify(Lt(V)))}catch{}}function N(V){const p=String(V??"").trim();return p?v(T(K(p))):null}function b(V,p){const u=String(V??"").trim();if(!u)return;const k=v(p);if(!k){B(K(u));return}x(K(u),k)}function E(V){const p=String(V??"").trim();p&&B(K(p))}function O(V){const p=String(V??"").trim();if(!p)return[];const u=T(_(p));return Array.isArray(u)?u.map(k=>H(k)).filter(k=>k?!k.dismissed&&(k.status==="pending"||k.status==="created")&&typeof k.sessionId=="string"&&k.sessionId.trim().length>0&&typeof k.provider=="string"&&k.provider.trim().length>0:!1):[]}function d(V,p){const u=String(V??"").trim();if(!u)return;const k=Array.isArray(p)?p.map(y=>H(y)).filter(y=>y?!y.dismissed&&(y.status==="pending"||y.status==="created")&&typeof y.sessionId=="string"&&y.sessionId.trim().length>0&&typeof y.provider=="string"&&y.provider.trim().length>0:!1):[];if(k.length===0){B(_(u));return}x(_(u),k)}function M(V){const p=String(V??"").trim();p&&d(p,O(p))}function j(V){if(typeof window>"u")return;const p=L();if(p)try{if(!V||V.length===0){window.localStorage.removeItem(p);return}const u={version:Oo,path:P()??window.location.pathname??"",updatedAt:Date.now(),showMarkers:e.changeMarkersVisible,entries:V};window.localStorage.setItem(p,JSON.stringify(u))}catch{}}function ee(){var U;const V=e.transactionManager;if(!V)return Array.from(e.editMetaByKey.values()).filter(C=>C.note||C.anchor).map(C=>({elementKey:C.elementKey,label:C.label,locator:C.locator,note:C.note||void 0,marker:C.anchor?{...C.anchor,dirtySince:C.dirtySince}:null}));const u=kn(e,V.getUndoStack()).slice().map((C,g)=>({tx:C,index:g}));u.sort((C,g)=>{const G=Number(C.tx.timestamp??0),se=Number(g.tx.timestamp??0);return G!==se?G-se:C.index-g.index});const k=new Map;for(const{tx:C}of u){if(C.type!=="style"&&C.type!=="text")continue;const g=C.elementKey?String(C.elementKey):Oe(C.targetLocator),G=k.get(g),se=((U=C.after)==null?void 0:U.locator)??C.targetLocator,J=G??{locator:se,styleBefore:{},styleAfter:{},textBefore:void 0,textAfter:void 0};if(J.locator=se,C.type==="style"){const W=C.before.styles??{},Z=C.after.styles??{},re=new Set([...Object.keys(W),...Object.keys(Z)]);for(const fe of re){const ue=String(fe??"").trim();ue&&(ue in J.styleBefore||(J.styleBefore[ue]=String(W[ue]??"").trim()),J.styleAfter[ue]=String(Z[ue]??"").trim())}}C.type==="text"&&(J.textBefore===void 0&&(J.textBefore=String(C.before.text??"")),J.textAfter=String(C.after.text??"")),G||k.set(g,J)}const y=[],D=new Set;for(const C of k.values()){const g={locator:C.locator};let G;const se=we(C.locator);se?G=Ne(se,C.locator.shadowHostChain):G=Oe(C.locator);const J={},W={},Z=new Set([...Object.keys(C.styleBefore),...Object.keys(C.styleAfter)]);for(const fe of Z){const ue=String(C.styleBefore[fe]??"").trim(),Ee=String(C.styleAfter[fe]??"").trim();ue!==Ee&&(J[fe]=ue,W[fe]=Ee)}(Object.keys(J).length>0||Object.keys(W).length>0)&&(g.styleChanges={before:J,after:W}),C.textBefore!==void 0&&C.textAfter!==void 0&&C.textBefore!==C.textAfter&&(g.textChange={before:C.textBefore,after:C.textAfter});const re=G?e.editMetaByKey.get(G):null;re!=null&&re.elementKey&&(g.elementKey=re.elementKey),re!=null&&re.label&&(g.label=re.label),re!=null&&re.note&&(g.note=re.note),re!=null&&re.anchor&&(g.marker={...re.anchor,dirtySince:re.dirtySince}),!(!g.textChange&&!g.styleChanges&&!g.note)&&(y.push(g),G&&D.add(G))}for(const C of e.editMetaByKey.values())D.has(C.elementKey)||C.note&&y.push({elementKey:C.elementKey,label:C.label,locator:C.locator,note:C.note||void 0,marker:C.anchor?{...C.anchor,dirtySince:C.dirtySince}:null});return y}function oe(){i||j(ee())}function ie(){s!==null&&(window.clearTimeout(s),s=null),oe()}function me(){i||(s!==null&&window.clearTimeout(s),s=window.setTimeout(()=>{s=null,oe()},120))}function ce(V){const p=e.transactionManager;if(p)for(const u of V){const k=String(u.elementKey??"").trim();if(o==="text-annotation"&&!k&&!!u.note&&!!u.marker&&!u.textChange&&!u.styleChanges)continue;const D=we(u.locator);if(!D||!D.isConnected)continue;const U=k||Ne(D,u.locator.shadowHostChain),C=String(u.label??"").trim()||bt(D,u.locator.shadowHostChain),g=n.getOrCreateEditMeta(U,u.locator,C);if(g.locator=u.locator,g.label=C,g.note=n.normalizeNote(u.note??g.note),g.anchor=u.marker?hr(u.marker)??g.anchor:g.anchor,u.marker&&Number.isFinite(Number(u.marker.dirtySince))&&(g.dirtySince=Number(u.marker.dirtySince)),u.styleChanges){const G=u.styleChanges.after??{},se=u.styleChanges.before??{};for(const J of Object.keys(G)){const W=String(G[J]??""),Z=String(se[J]??""),re=D.style;re&&(W.trim()?re.setProperty(J,W.trim()):re.removeProperty(J)),p.recordStyle(u.locator,J,Z,W,{merge:!1})}}if(u.textChange){const G=String(u.textChange.before??""),se=String(u.textChange.after??"");G!==se&&D instanceof HTMLElement&&(D.textContent=se,p.recordText(D,G,se))}}}function pe(){var p;if(typeof window>"u")return;const V=S();if(!(!V||V.entries.length===0)){i=!0;try{typeof V.showMarkers=="boolean"?(e.changeMarkersVisible=V.showMarkers,q(V.showMarkers)):e.changeMarkersVisible=I(),ce(V.entries)}finally{i=!1}(p=e.propertyPanel)==null||p.refresh(),n.syncEditMetaWithTransactions(),oe()}}function ge(V){var k;const p=ee();if(p.length===0){j([]);return}const u=[];for(const y of p){const D={locator:y.locator};y.elementKey&&(D.elementKey=y.elementKey),y.label&&(D.label=y.label),y.note&&(D.note=y.note),y.marker&&(D.marker=y.marker),V==="text"?y.styleChanges&&(D.styleChanges=y.styleChanges):y.textChange&&(D.textChange=y.textChange),!(!D.textChange&&!D.styleChanges)&&u.push(D)}i=!0;try{(k=e.transactionManager)==null||k.clear(),ce(u)}finally{i=!1}j(u)}function ae(){j([])}return{readMarkerVisibility:I,setMarkerVisibility:q,readAnnotationShortcutSettings:Y,setAnnotationShortcutSettings:F,readUiSettings:A,setUiSettings:X,readGenieConversationState:N,writeGenieConversationState:b,clearGenieConversationState:E,readGenieTaskStates:O,writeGenieTaskStates:d,pruneExpiredGenieTaskStates:M,scheduleWrite:me,persistFromTransactions:oe,flushPendingWrite:ie,restoreCachedChanges:pe,clearCachedChanges:ge,clearStorage:ae}}function pn(t){return String(t??"").replace(/\r\n/g,`
|
||
`).trim()}function Ft(t){return String(t??"").replace(/\s+/g," ").trim()}function St(t){return String(t??"").trim()}function jn(t){const e=[],n=new Set;for(const r of t){const o=St(r);!o||n.has(o)||(n.add(o),e.push(o))}return e}function Mt(t,e){var r;const n=(r=t==null?void 0:t.meta)==null?void 0:r[e];return typeof n=="string"?n.trim():""}function su(t){const n=St(t).replace(/\\/g,"/").match(/^src\/(components|prototypes|themes)\/([^/]+)/);return n?`${n[1]}/${n[2]}`:""}function yn(t,e){const n=e(t.parentLocator)||"unknown-parent",r=t.anchorLocator?e(t.anchorLocator):"",o=t.anchorLocator&&r?`, anchor: ${r} (${t.anchorPosition??"after"})`:"";return`${n} @index ${t.insertIndex}${o}`}function dr(t){if(!t)return null;try{return we(t)}catch{return null}}function au(t,e=""){var i,a,l,m;const n=dr(t);if(n)return n.tagName.toLowerCase();const r=(i=St(t.fingerprint).split("|")[0])==null?void 0:i.trim();if(r)return r.toLowerCase();const o=(l=(a=(t.selectors??[]).map(P=>St(P)).find(Boolean))==null?void 0:a.match(/^[a-zA-Z][\w-]*/))==null?void 0:l[0];if(o)return o.toLowerCase();const s=(m=St(e).match(/^[a-zA-Z][\w-]*/))==null?void 0:m[0];return s?s.toLowerCase():""}function cu(t){return t?t instanceof HTMLInputElement||t instanceof HTMLTextAreaElement?Ft(t.value):Ft(t.textContent):""}function Go(t){return St(t)||"(unset)"}function Vo(t){return Ft(t)||"(empty)"}function zo(t){return(t??[]).map(n=>St(n)).filter(Boolean).join(" ")||"(empty)"}function Wo(t){if(!(t!=null&&t.file))return"";const e=[t.file,t.line,t.column].filter(r=>r!=null&&r!=="").join(":"),n=t.componentName?` (${t.componentName})`:"";return`${e}${n}`}function lu(t,e){return{workspacePaths:jn([e??"",...(t==null?void 0:t.workspacePaths)??[]]),relatedFiles:jn((t==null?void 0:t.relatedFiles)??[]),extraContext:jn((t==null?void 0:t.extraContext)??[])}}function Jn(t,e,n){if(n.length!==0){t.push(`- ${e}:`);for(const r of n)t.push(` - ${r}`)}}function uu(t){const{state:e,buildCopyPromptOverride:n}=t,r=lu(t.promptContext,t.projectPath),o=t.getResourceContext??(()=>null);function s(){if(typeof window>"u")return"";try{const p=new URL(window.location.href);p.searchParams.delete("editor");const u=p.searchParams.toString();return p.search=u?`?${u}`:"",p.toString()}catch{return window.location.href.replace(/([?&])editor=webEditorV2(&)?/,(p,u,k)=>u==="?"&&k?"?":"").replace(/\?$/,"")}}function i(){var p;return((p=e.transactionManager)==null?void 0:p.getUndoStack())??[]}function a(){return kn(e,i())}function l(p){if(!p||!p.isConnected)return"";const u=Xt(e,p);if(u)return u.elementKey;const k=Se(p);return Ne(p,k.shadowHostChain)}function m(){const p=S(),u=St(p==null?void 0:p.path)||Mt(p,"targetPath")||su(Mt(p,"currentFilePath"));if(u)return u;if(typeof window>"u")return null;const k=window.location.pathname.match(/\/(components|prototypes)\/([^/]+)/);return k?`${k[1]}/${k[2]}`:null}function P(){const p=S(),u=Mt(p,"currentFilePath")||Mt(p,"docPath");if(u)return u;const k=m();return k?`src/${k}/index.tsx`:""}function L(){const p=S(),u=Mt(p,"prototypeFilePath");if(u)return u;const k=m();return!k||k.startsWith("themes/")?"":`src/${k}/index.tsx`}function S(){try{return o()??null}catch{return null}}function R(p){var k;if(!p)return"";const u=(p.selectors??[]).map(y=>String(y??"").trim()).filter(Boolean);return u.length>0?u.join(" | "):(k=p.path)!=null&&k.length?p.path.join(">"):""}function I(p){const u=dr(p);if(u)return bt(u,p.shadowHostChain);const k=R(p);return k||"element"}function h(p){var D;const u=p.map((U,C)=>({tx:U,index:C}));u.sort((U,C)=>{const g=Number(U.tx.timestamp??0),G=Number(C.tx.timestamp??0);return g!==G?g-G:U.index-C.index});const k=new Map;for(const{tx:U}of u){if(U.type!=="move"||!U.moveData)continue;const C=U.elementKey?String(U.elementKey):Oe(U.targetLocator),g=((D=U.after)==null?void 0:D.locator)??U.targetLocator,G=k.get(C);G?(G.locator=g,G.to=U.moveData.to,G.updatedAt=Number(U.timestamp??0)):k.set(C,{locator:g,from:U.moveData.from,to:U.moveData.to,updatedAt:Number(U.timestamp??0)})}const y=Array.from(k.entries()).map(([U,C])=>({elementKey:U,label:I(C.locator),locator:C.locator,selectorPath:R(C.locator),from:C.from,to:C.to,updatedAt:C.updatedAt}));return y.sort((U,C)=>C.updatedAt-U.updatedAt||U.label.localeCompare(C.label)),y}function T(p){return h(p).map(({elementKey:u,...k})=>k)}function x(){if(!e.transactionManager)return[];const u=tt(a()),k=[],y=new Set;for(const D of u){const U=D.netEffect.textChange;if(!U)continue;const C=Ft(U.before),g=Ft(U.after);if(!C||!g||C===g)continue;const G=`${C}=>${g}`;y.has(G)||(y.add(G),k.push({before:C,after:g}))}return k}function B(){var k,y;const p=tt(a()),u=[];for(const D of p){const U=D.netEffect.styleChanges;if(!U)continue;const C=((y=(k=D.netEffect.locator.selectors)==null?void 0:k.find(G=>String(G??"").trim()))==null?void 0:y.trim())??"";if(!C)continue;const g=Object.entries(U.after??{}).filter(([,G])=>String(G??"").trim()!=="").map(([G,se])=>` ${G}: ${String(se)};`);g.length!==0&&u.push(`${C} {
|
||
${g.join(`
|
||
`)}
|
||
}`)}return u.join(`
|
||
|
||
`)}function K(){return{cssText:B()}}function _(p){return Array.from(e.editMetaByKey.values()).map(u=>({elementKey:String(u.elementKey),label:u.label,locator:u.locator,note:pn(u.note),dirtySince:Number(u.dirtySince??0)})).filter(u=>!!u.note&&!p.has(u.elementKey)).sort((u,k)=>k.dirtySince-u.dirtySince||u.label.localeCompare(k.label))}function v(p){return Array.from(e.editMetaByKey.values()).map(u=>({elementKey:String(u.elementKey),label:u.label,locator:u.locator,note:pn(u.note),imageCount:Array.isArray(u.images)?u.images.length:0,dirtySince:Number(u.dirtySince??0)})).filter(u=>!p.has(u.elementKey)&&(!!u.note||u.imageCount>0)).sort((u,k)=>k.dirtySince-u.dirtySince||u.label.localeCompare(k.label))}function H(p,u={}){const k=dr(p),y=cu(k)||q(u.fallbackText);return{tagName:au(p,u.fallbackLabel??""),currentText:y}}function q(p){return Ft(p)}function Y(p,u){const k=u.includePageUrl?s():"",y=u.includeTargetPath?m()??"":"";p.push("任务上下文:"),k&&p.push(`- 页面地址: ${k}`),y&&p.push(`- 页面路径: ${y}`),u.currentFilePath&&p.push(`- 当前实现文件: ${u.currentFilePath}`),u.prototypeFilePath&&p.push(`- 对应原型文件: ${u.prototypeFilePath}`),Jn(p,"工作区路径",r.workspacePaths),Jn(p,"补充相关文件",r.relatedFiles),Jn(p,"补充上下文",r.extraContext)}function F(p){p.push("全局约束:"),p.push("- 只把“执行修改”字段当作真实改动指令。"),p.push("- “当前元素文本”“元素定位”“可能相关文件”只用于帮助定位,不表示要把代码改成这些内容。"),p.push("- 未在“执行修改”中明确写出的文本内容、标签类型、层级结构和其他样式,不要主动改动。")}function A(p,u){const k=H(u.locator,{fallbackLabel:u.fallbackLabel,fallbackText:u.fallbackText}),y=R(u.locator);p.push(`- 修改项 ${u.index}`),k.tagName&&p.push(` - 当前元素标签: ${k.tagName}`),k.currentText&&p.push(` - 当前元素文本: ${k.currentText}`),y&&p.push(` - 元素定位: ${y}`),u.debugFileHint&&p.push(` - 可能相关文件: ${u.debugFileHint}`);for(const D of u.actions)p.push(` - 执行修改: ${D}`);u.note&&p.push(` - 补充要求: ${u.note}`)}function X(p,u){const{annotation:k}=u;if(p.push(`- 标注项 ${u.index}`),p.push(` - 标注文本: 「${k.selectedText}」`),k.contextBefore&&p.push(` - 文本前文: "...${k.contextBefore}"`),k.contextAfter&&p.push(` - 文本后文: "${k.contextAfter}..."`),k.tagPath.length>0&&p.push(` - 标签路径: ${k.tagPath.join(" > ")}`),k.segments.length>1){p.push(" - 跨标签片段:");for(const y of k.segments)p.push(` - [${y.tags.join(" > ")}]: "${y.text}"`)}u.note&&p.push(` - 补充要求: ${u.note}`)}function N(p){return p.startsWith("text-ann::")}function b(p){var u,k;return((u=e.activeTextAnnotation)==null?void 0:u.id)===p?e.activeTextAnnotation:((k=e.textAnnotationManager)==null?void 0:k.getAnnotations().get(p))??null}function E(p){const u=[],k=p.netEffect.textChange;k&&u.push(`文本内容 "${Vo(k.before)}" -> "${Vo(k.after)}"`);const y=p.netEffect.classChanges;y&&u.push(`class "${zo(y.before)}" -> "${zo(y.after)}"`);const D=p.netEffect.styleChanges;if(D){const U=new Set([...Object.keys(D.before??{}),...Object.keys(D.after??{})]);for(const C of Array.from(U).sort()){const g=String((D.before??{})[C]??"").trim(),G=String((D.after??{})[C]??"").trim();g!==G&&u.push(`样式 ${C}: "${Go(g)}" -> "${Go(G)}"`)}}return u}function O(){var se,J,W;const p=a(),u=tt(p),k=T(p),y=_(new Set(u.map(Z=>String(Z.elementKey))));if(u.length===0&&y.length===0&&k.length===0)return"";const D=P(),U=L(),C=D.toLowerCase().endsWith(".md")||Mt(S(),"docType")!=="",g=[];C?g.push("请根据以下 Markdown 文档预览上的标注,在代码库中完成对应更新。"):g.push("请根据以下所见即所得修改,在代码中实现同样的改动。"),g.push(""),Y(g,{includePageUrl:!0,includeTargetPath:!0,currentFilePath:D,prototypeFilePath:U}),g.push(""),C?(g.push("全局约束:"),g.push("- 当前操作对象是 Markdown 文档预览,不是页面源码 DOM。"),g.push(`- 所有标注都要优先落实到文档文件 ${D||"(unknown)"}。`),U&&g.push(`- 如果标注暴露出文案、结构或交互与原型不一致,也要同步更新 ${U}。`),g.push("- 未明确指出的内容不要擅自改写。"),g.push(""),g.push("标注列表:")):(F(g),g.push(""),g.push("修改列表:"));let G=1;for(const Z of u){const re=pn(((se=e.editMetaByKey.get(Z.elementKey))==null?void 0:se.note)??""),fe=E(Z);fe.length===0&&re&&fe.push("根据补充要求调整当前元素"),A(g,{index:G,locator:Z.netEffect.locator,fallbackLabel:Z.fullLabel||Z.label,fallbackText:((J=Z.netEffect.textChange)==null?void 0:J.after)??((W=Z.netEffect.textChange)==null?void 0:W.before)??"",debugFileHint:Wo(Z.debugSource),actions:fe,note:re}),G+=1}for(const Z of y){const re=N(Z.elementKey)?b(Z.elementKey):null;re?X(g,{index:G,annotation:re,note:Z.note}):A(g,{index:G,locator:Z.locator,fallbackLabel:Z.label,actions:["根据补充要求调整当前元素"],note:Z.note}),G+=1}if(k.length>0){g.push(""),g.push("结构移动列表:");for(const Z of k)A(g,{index:G,locator:Z.locator,fallbackLabel:Z.label,actions:[`结构位置: ${yn(Z.from,R)} -> ${yn(Z.to,R)}`]}),G+=1}return g.push(""),g.push("输出要求:"),C?(g.push("- 优先说明修改了哪些文档文件;若同步了原型,也一并列出。"),g.push("- 给出关键改动摘要,以及仍需人工验证的差异点。")):(g.push("- 给出需要修改的文件列表与具体代码改动。"),g.push("- 如果无法定位文件,请说明缺失了哪些关键信息。")),g.join(`
|
||
`)}function d(){return Array.from(e.editMetaByKey.values()).filter(p=>p.dirtySince!==null).map(p=>({elementKey:p.elementKey,locator:p.locator,label:p.label,note:p.note,imageCount:p.images.length,changeKinds:p.changeKinds.slice()}))}function M(){const p=O();return p?{resource:S(),modifiedElements:d(),textChanges:x(),styleChanges:K(),taskContext:{pageUrl:s(),targetPath:m()??"",currentFilePath:P(),prototypeFilePath:L()},defaultPrompt:p}:null}function j(){const p=O();if(!p)return"";if(n)try{const u=M();if(u)return n(u)}catch(u){console.warn("[GenieEditor] Host buildCopyPrompt failed, falling back to default:",u)}return p}function ee(){const p=a(),u=tt(p),k=new Set(u.map(U=>String(U.elementKey))),y=_(k);return u.some(U=>{const C=e.editMetaByKey.get(U.elementKey);return((C==null?void 0:C.images.length)??0)>0})||y.some(U=>{var C;return(((C=e.editMetaByKey.get(U.elementKey))==null?void 0:C.images.length)??0)>0})?"不支持标注图片,已过滤。":void 0}function oe(p){var G,se;const{summaries:u,annotationOnlyMetas:k,moveSummaries:y}=p,D=p.mode??"initial";if(u.length===0&&k.length===0&&y.length===0)return"";const U=P(),C=[];D==="append"?(C.push("请在同一个已存在的 Genie 会话中继续执行以下代码修改任务。"),C.push("续写要求:"),C.push("- 这是一次追加消息,前文上下文、已完成修改和已有计划都已经存在。"),C.push("- 只基于本次新增的节点信息和补充要求继续执行,不要重复总结整个页面或重复前文计划。"),C.push("- 如果本次要求与前文不一致,以本次消息为准,并直接调整代码。"),C.push("- 优先复用你刚刚已经定位到的文件与实现上下文,直接继续修改。"),C.push("- 不需要重复输出完整修改说明,除非真的被阻塞。"),C.push("- 如需回复,只用 1-2 句话说明这次追加改动涉及的文件和核心变化。")):(C.push("请直接执行以下代码修改任务。"),C.push("执行要求:"),C.push("- 这是直接执行任务,通常不可与用户交互。"),C.push("- 在保证准确的前提下,不需要说明你计划,尽快完成修改。"),C.push("- 完成后回复完成即可,不需要说明修改的内容。"),C.push("- 只有真正阻塞时,才简短说明缺失信息。")),C.push(""),Y(C,{includePageUrl:!0,includeTargetPath:!0,currentFilePath:U,prototypeFilePath:L()}),C.push(""),F(C),C.push(""),C.push("修改列表:");let g=1;for(const J of u){const W=e.editMetaByKey.get(J.elementKey),Z=pn((W==null?void 0:W.note)??""),re=E(J);re.length===0&&Z&&re.push("根据补充要求调整当前元素"),((W==null?void 0:W.images.length)??0)>0&&re.push("请结合附带图片调整当前元素"),A(C,{index:g,locator:J.netEffect.locator,fallbackLabel:J.fullLabel||J.label,fallbackText:((G=J.netEffect.textChange)==null?void 0:G.after)??((se=J.netEffect.textChange)==null?void 0:se.before)??"",debugFileHint:Wo(J.debugSource),actions:re,note:Z}),g+=1}for(const J of k){const W=N(J.elementKey)?b(J.elementKey):null;if(W)X(C,{index:g,annotation:W,note:J.note});else{const Z=J.imageCount>0?["请结合附带图片调整当前元素"]:["根据补充要求调整当前元素"];A(C,{index:g,locator:J.locator,fallbackLabel:J.label,actions:Z,note:J.note})}g+=1}if(y.length>0){C.push(""),C.push("结构移动列表:");for(const J of y)A(C,{index:g,locator:J.locator,fallbackLabel:J.label,actions:[`结构位置: ${yn(J.from,R)} -> ${yn(J.to,R)}`]}),g+=1}return C.join(`
|
||
`)}function ie(){const p=a(),u=tt(p),k=T(p),y=v(new Set(u.map(D=>String(D.elementKey))));return oe({mode:"initial",summaries:u,annotationOnlyMetas:y,moveSummaries:k})}function me(){const p=a(),u=tt(p),k=T(p),y=v(new Set(u.map(D=>String(D.elementKey))));return oe({mode:"append",summaries:u,annotationOnlyMetas:y,moveSummaries:k})}function ce(p){const u=l(p);if(!u)return"";const k=a(),y=tt(k).filter(C=>String(C.elementKey)===u),D=v(new Set(y.map(C=>String(C.elementKey)))).filter(C=>C.elementKey===u),U=h(k).filter(C=>C.elementKey===u).map(({elementKey:C,...g})=>g);return oe({mode:"initial",summaries:y,annotationOnlyMetas:D,moveSummaries:U})}function pe(p){const u=l(p);if(!u)return"";const k=a(),y=tt(k).filter(C=>String(C.elementKey)===u),D=v(new Set(y.map(C=>String(C.elementKey)))).filter(C=>C.elementKey===u),U=h(k).filter(C=>C.elementKey===u).map(({elementKey:C,...g})=>g);return oe({mode:"append",summaries:y,annotationOnlyMetas:D,moveSummaries:U})}function ge(){const p=a();for(const u of p){if(u.type==="structure")return"暂不支持应用结构操作";if(u.type!=="style"&&u.type!=="text"&&u.type!=="class"&&u.type!=="move")return`暂不支持应用 "${u.type}" 事务`}if(!j())return"没有可生成 prompt 的更改"}function ae(){const p=a();for(const u of p){if(u.type==="structure")return"暂不支持执行结构操作";if(u.type!=="style"&&u.type!=="text"&&u.type!=="class"&&u.type!=="move")return`暂不支持执行 "${u.type}" 事务`}if(!ie())return"当前没有可发送到 Genie 的编辑元素"}function V(p){if(!p||!p.isConnected)return"当前元素已失效,请重新选择后再试。";const u=l(p);if(!u)return"当前元素已失效,请重新选择后再试。";for(const k of a())if(String(k.elementKey??Oe(k.targetLocator)).trim()===u){if(k.type==="structure")return"暂不支持执行当前元素的结构操作";if(k.type!=="style"&&k.type!=="text"&&k.type!=="class"&&k.type!=="move")return`暂不支持执行当前元素的 "${k.type}" 事务`}if(!ce(p))return"当前元素没有可发送到 Genie 的编辑"}return{resolveTargetPath:m,resolveCurrentFilePath:P,resolvePrototypeFilePath:L,resolveResourceContext:S,formatSelectorPath:R,formatElementLabelFromLocator:I,collectTextChanges:x,collectStyleCss:B,collectStyleChanges:K,collectMoveSummaries:T,buildSaveRunPrompt:ie,buildAppendSaveRunPrompt:me,buildSaveRunPromptForElement:ce,buildAppendSaveRunPromptForElement:pe,buildCopyPrompt:j,getCopyPromptContext:M,getCopyPromptFilteredNotice:ee,getCopyPromptBlockReason:ge,getSaveRunPromptBlockReason:ae,getSaveRunPromptForElementBlockReason:V}}function bn(t){return String(t??"").replace(/\r\n?/g,`
|
||
`).replace(/\n+/g," ").replace(/\s+/g," ").trim()}function Qn(t){return!(!(t instanceof HTMLElement)||t instanceof HTMLInputElement||t instanceof HTMLTextAreaElement||t.childElementCount>0)}function du(t){const{state:e}=t;function n(r,o){var l,m,P,L;if(!Qn(r)||!r.isConnected)return!1;const s=r.textContent??"",i=bn(s),a=bn(o);return e.selectedElement!==r&&t.ensureSelected(r,Cn),i===a?!1:(r.textContent=a,(l=e.transactionManager)==null||l.recordText(r,s,a),(m=e.positionTracker)==null||m.forceUpdate(!0),e.selectedElement===r&&((P=e.breadcrumbs)==null||P.setTarget(r),(L=e.propertyPanel)==null||L.refresh()),console.log(`${t.logPrefix} Text edit committed`),!0)}return{isEditable:Qn,normalizeText:bn,getText(r){return Qn(r)?bn(r.textContent??""):""},commitText:n}}function pu(t={}){const e=ba(t),n=wa(),r=new Set,o=uu({state:n,promptContext:e.promptContext,projectPath:e.genieBridge.projectPath,getResourceContext:e.host.getResourceContext,buildCopyPromptOverride:e.host.buildCopyPrompt}),s=ts({getUiRoot:()=>{var u,k;return((k=(u=n.shadowHost)==null?void 0:u.getElements())==null?void 0:k.uiRoot)??null}});let i=null,a=null,l=null,m=!1;function P(){const u=n.selectedElement;if(!u||!u.isConnected)return null;const k=Se(u),y=Ne(u,k.shadowHostChain),D=u.id?`${u.tagName.toLowerCase()}#${u.id}`:u.tagName.toLowerCase();return{elementKey:y,locator:k,label:D,fullLabel:bt(u,k.shadowHostChain),tagName:u.tagName.toLowerCase(),updatedAt:Date.now()}}function L(){const u=n.transactionManager;return{undoCount:(u==null?void 0:u.getUndoStack().length)??0,redoCount:(u==null?void 0:u.getRedoStack().length)??0}}function S(){return Array.from(n.editMetaByKey.values()).filter(u=>u.dirtySince!==null).sort((u,k)=>Number(u.dirtySince??0)-Number(k.dirtySince??0)).map(u=>({elementKey:u.elementKey,locator:u.locator,label:u.label,note:u.note,imageCount:u.images.length,changeKinds:u.changeKinds.slice()}))}function R(){return o.collectTextChanges()}function I(){return o.collectStyleChanges()}function h(){var k,y;let u=null;try{u=((y=(k=e.host).getResourceContext)==null?void 0:y.call(k))??null}catch{u=null}return{resource:u,selectedElement:P(),modifiedElements:S(),textChanges:R(),styleChanges:I()}}function T(){var C;const u=P(),k=(l==null?void 0:l.getCurrentConversationState())??null,y=(l==null?void 0:l.getElementTaskState(n.selectedElement))??null,D=(l==null?void 0:l.getVisibleTaskStates())??[],U=((C=l==null?void 0:l.getDebugInfo)==null?void 0:C.call(l))??null;return{available:(l==null?void 0:l.isAvailable())??!1,connected:(l==null?void 0:l.isConnected())??!1,bridgeConfig:U,selectedElementKey:(u==null?void 0:u.elementKey)??null,currentConversation:k?{scopeKey:k.scopeKey,sessionId:k.sessionId,provider:k.provider,invalidated:k.invalidated,sentCount:k.sentCount,expiresAt:k.expiresAt,sessionUrl:k.sessionUrl}:null,hasReusableConversation:(l==null?void 0:l.hasReusableConversation())??!1,currentElementTask:y?{elementKey:y.elementKey,status:y.status,sessionId:y.sessionId,provider:y.provider,message:y.message,updatedAt:y.updatedAt}:null,visibleTasks:D.map(g=>({elementKey:g.elementKey,status:g.status,sessionId:g.sessionId,provider:g.provider,message:g.message,updatedAt:g.updatedAt}))}}function x(){const u=P(),k=R(),y=I(),D=S().length,{undoCount:U,redoCount:C}=L();return{active:n.active,hasSelection:u!==null,selectedElement:u,undoCount:U,redoCount:C,modifiedCount:D,hasTextChanges:k.length>0,hasStyleChanges:!!y.cssText,hasModifiedElements:D>0}}function B(u){return u?{provider:typeof u.provider=="string"&&u.provider.trim()?u.provider.trim():null,sessionId:typeof u.sessionId=="string"&&u.sessionId.trim()?u.sessionId.trim():null,requestId:typeof u.requestId=="string"&&u.requestId.trim()?u.requestId.trim():null}:null}function K(u){return u==="pending"||u==="created"?"editing":u==="completed"?"completed":u==="error"?"error":"idle"}function _(u){var D,U,C,g,G,se;const k=P();if((k==null?void 0:k.elementKey)===u&&((D=n.selectedElement)!=null&&D.isConnected))return n.selectedElement;const y=((U=n.editMetaByKey.get(u))==null?void 0:U.locator)??((g=(C=l==null?void 0:l.getTaskStateByElementKey)==null?void 0:C.call(l,u))==null?void 0:g.locator)??((G=n.externalEditingTaskByElementKey.get(u))==null?void 0:G.locator)??((se=n.genieTaskByElementKey.get(u))==null?void 0:se.locator)??null;if(!y)return null;try{const J=we(y);return J!=null&&J.isConnected?J:null}catch{return null}}function v(){const u=new Set([...n.editMetaByKey.keys(),...n.processedEditTimestampsByKey.keys(),...n.genieTaskByElementKey.keys(),...n.externalEditingTaskByElementKey.keys()]);return Array.from(u).map(y=>{var ue,Ee,Te;const D=n.editMetaByKey.get(y)??null,U=((ue=l==null?void 0:l.getTaskStateByElementKey)==null?void 0:ue.call(l,y))??n.externalEditingTaskByElementKey.get(y)??n.genieTaskByElementKey.get(y)??null,C=n.processedEditTimestampsByKey.get(y),g=Number.isFinite(Number(C))?Number(C):null,G=!!String((D==null?void 0:D.note)??"").trim(),se=!!(D!=null&&D.images.length),J=Number.isFinite(Number(D==null?void 0:D.dirtySince))?Number(D==null?void 0:D.dirtySince):null,W=J!==null&&(g===null||J>g),Z=G||se||W?"dirty":g!==null?"handled":"clean",re=(D==null?void 0:D.label)??(U==null?void 0:U.label)??(((Ee=P())==null?void 0:Ee.elementKey)===y?(Te=P())==null?void 0:Te.fullLabel:null)??y,fe=K(U==null?void 0:U.status);return{elementKey:y,label:re,changeState:Z,taskState:fe,hasNote:G,hasImages:se,changeKinds:(D==null?void 0:D.changeKinds.slice())??[],dirtySince:J,lastHandledAt:g}}).sort((y,D)=>{const U=Math.max(Number(y.dirtySince??0),Number(y.lastHandledAt??0)),C=Math.max(Number(D.dirtySince??0),Number(D.lastHandledAt??0));return U!==C?C-U:y.label.localeCompare(D.label)})}function H(){const u=h(),k={clean:0,dirty:0,handled:0,editing:0,completed:0,error:0},y=v();for(const D of y)k[D.changeState]+=1,(D.taskState==="editing"||D.taskState==="completed"||D.taskState==="error")&&(k[D.taskState]+=1);return{...u,statusSummary:{active:x().active,modifiedCount:y.filter(D=>D.changeState!=="clean").length,nodeStateCounts:k}}}function q(){return{items:Array.from(n.editMetaByKey.values()).flatMap(k=>k.images.map(y=>({id:y.id,name:y.name,data:y.data,mimeType:y.mimeType,createdAt:y.createdAt,source:"prompt-context"}))).sort((k,y)=>k.createdAt-y.createdAt)}}async function Y(u){const k=_(u);if(!k)throw new Error(`NOT_FOUND: Element not found for key: ${u}`);const y=await ns(k,u);return{elementKey:u,image:y,mimeType:"image/png",width:y.width,height:y.height}}async function F(u,k,y){const D=_(u);if(!D)throw new Error(`NOT_FOUND: Element not found for key: ${u}`);if(!(l!=null&&l.setExternalEditingState)||!l.clearExternalEditingState)throw new Error("NOT_IMPLEMENTED: External editing state control is unavailable");k==="editing"?l.setExternalEditingState(D,y):l.clearExternalEditingState(D,y),A();const U=B(y);return{elementKey:u,state:k,applied:!0,...U?{taskRef:U}:{}}}function A(){const u=x();for(const k of r)try{k(u)}catch(y){console.error("[GenieEditor] Status listener failed:",y)}}const X=xa({state:n,scheduleCacheWrite:()=>i==null?void 0:i.scheduleWrite(),persistMarkerVisibility:u=>i==null?void 0:i.setMarkerVisibility(u),onSelectMarkedElement:(u,k)=>{var y;u.isConnected&&((y=n.eventController)==null||y.setMode("selecting"),a==null||a.handleSelect(u,Cn,{clientX:k.clientX,clientY:k.clientY}))},onStatusChange:A}),N=du({state:n,ensureSelected:(u,k)=>{a==null||a.handleSelect(u,k)},logPrefix:"[WebEditorV2]"});i=iu({state:n,changes:X,getResourceContext:e.host.getResourceContext,interactionProfile:e.interactionProfile}),l=Va({state:n,changes:X,feedback:s,persistence:i,summaries:o,bridgeOptions:e.genieBridge,onAvailabilityChange:()=>{var u,k;(u=n.breadcrumbs)==null||u.refresh(),(k=n.propertyPanel)==null||k.refresh()}});const b=tc({integrationWsOptions:e.integrationWs,getPageUrl:()=>typeof window>"u"?e.integrationWs.pageUrl||null:String(e.integrationWs.pageUrl||window.location.href||"").trim()||null,getSessionId:()=>{var k;const u=String(e.integrationWs.sessionId??"").trim();return u||(((k=l==null?void 0:l.getCurrentConversationState())==null?void 0:k.sessionId)??null)},getEditedSnapshotPayload:H,listEditorNodes:v,getContextImagesPayload:q,getNodeScreenshotPayload:Y,setNodeEditingState:async(u,k,y)=>F(u,k,y)});a=nc({state:n,changes:X,persistence:i,textSession:N,genieBridge:l,logPrefix:"[WebEditorV2]",onStatusChange:A});const E=Zl({state:n,feedback:s,changes:X,interaction:a,summaries:o,persistence:i,onStatusChange:A}),d=Ql({state:n,options:e,services:{feedback:s,summaries:o,changes:X,persistence:i,textSession:N,interaction:a,genieBridge:l,integrationWs:b,localActions:E},onStatusChange:A});function M(){m||d.start()}function j(){m||d.stop()}function ee(){return m?!1:(n.active?j():M(),n.active)}function oe(){return{active:n.active,version:ls}}function ie(u){return r.add(u),u(x()),()=>{r.delete(u)}}function me(){m||(a==null||a.clearSelection(),A())}function ce(){m||(i==null||i.clearCachedChanges("text"),A())}function pe(){m||(i==null||i.clearCachedChanges("style"),A())}async function ge(u){if(m)return!1;const k=n.editMetaByKey.get(u);if(!k)return!1;let y=null;try{y=we(k.locator)}catch{y=null}if(!(y!=null&&y.isConnected))return!1;const D=await E.handleClearElementEdits(y);return A(),D}async function ae(){m||(await E.handleClearEdits({skipConfirm:!0}),A())}async function V(u){if(m)return{success:!1,error:"Genie Editor instance has been destroyed."};if(!a)return{success:!1,error:"Genie Editor interaction service is not ready."};const k=await a.revertElement(u);return A(),k}function p(){m||(m=!0,d.stop(),r.clear())}return{start:M,stop:j,destroy:p,toggle:ee,getState:oe,getStatus:x,subscribeStatus:ie,getSelectedElement:P,getModifiedElements:S,getTextChanges:R,getStyleChanges:I,getEditedSnapshot:h,getDebugState:T,getHistoryCounts:L,revertElement:V,clearSelection:me,acknowledgeSavedTextChanges:ce,acknowledgeSavedStyleChanges:pe,clearElementEdits:ge,clearAllEdits:ae}}export{pu as c};
|