import{aN as J,bp as K,bo as Q,aG as b,bk as X,aK as u,ad as Y,c8 as c,aD as f,bL as s,aE as V,aF as p,r as Z,bS as T,Q as ee,bC as l,ay as A,bs as i,aJ as m,bD as ae,a$ as te,bc as ne,ak as oe}from"./index-D5GfLbIx.js";/* empty css             *//* empty css                  *//* empty css               */const se={key:0,class:"workspace-3d-toolbar"},le={class:"hint"},re=["src"],ce={key:1,class:"workspace-3d-mask"},ie=1800,de=4,ue=18e3,fe=J({__name:"Workspace3D",props:{host:{default:void 0},scope:{default:"Platform"},token:{default:""},readOnly:{type:Boolean,default:!1},embedUi:{type:Boolean,default:!1},canvasOnly:{type:Boolean,default:!1},hideToolbar:{type:Boolean,default:!1}},emits:["pick","select","ready"],setup(o,{expose:F,emit:M}){const n=o,h=M,_=l(),D=l(),y=l(!1),v=l("正在连接 webVRender ..."),w=l(null),g=l([]),r=l(""),d=A(()=>n.host??"localhost:8223"??"localhost:8223"),R=A(()=>{const a=new URLSearchParams;return a.set("scope",n.scope??"Platform"),n.token&&a.set("token",n.token),a.set("ro",n.readOnly?"1":"0"),n.canvasOnly?a.set("ui","canvas-only"):n.embedUi&&a.set("ui","embed"),`http://${d.value}/?${a.toString()}`});let k=null,E=0;function z(){return`http://${d.value}`}function L(a){return new Promise(e=>setTimeout(e,a))}function P(){return n.canvasOnly||n.embedUi}function N(){return n.canvasOnly?"/declareCanvasOnly":n.embedUi?"/declareEmbedUi":null}async function O(a){try{return(await fetch(`${z()}${a}`,{method:"GET",cache:"no-store",credentials:"omit",signal:AbortSignal.timeout(ie)})).ok}catch{return!1}}async function G(){const a=N();if(a){for(let e=0;e<de;e++){if(await O(a))return;await L(80*(e+1))}console.warn(`[Workspace3D] ${a} 未成功，将依赖 SimpleLite 默认 canvas-only 模式`)}}async function H(a=1e4){const e=Date.now()+a;let t=60;for(;Date.now()<e;){if(await O("/vrenderReady"))return!0;await L(t),t=Math.min(t+40,280)}return!1}function S(){k!=null&&(clearTimeout(k),k=null)}function I(a){S(),k=setTimeout(()=>{a!==E||y.value||(v.value=`连接超时 (http://${d.value})，请确认 SimpleLite 已启动`)},ue)}function B(a){const e=R.value;if(!a)return e;const t=e.includes("?")?"&":"?";return`${e}${t}_=${Date.now()}`}async function C(a=!1){const e=++E;if(y.value=!1,v.value=`正在连接 webVRender (http://${d.value}) ...`,I(e),P())G(),r.value=B(a||!!r.value);else{if(v.value="正在等待 SimpleLite webVRender 就绪 ...",await H(),e!==E)return;r.value=B(a||!!r.value)}}function j(){y.value=!0,S(),h("ready")}function W(a){if(!_.value||a.source!==_.value.contentWindow)return;const e=a.data;if(!(!e||typeof e!="object")){if(e.type==="workspace.pick"&&e.payload&&typeof e.payload.x=="number")w.value=e.payload,h("pick",e.payload);else if(e.type==="workspace.select"&&Array.isArray(e.payload))g.value=e.payload,h("select",e.payload);else if(e.type==="workspace.shortcut"&&e.payload&&typeof e.payload=="object"){const t=e.payload.action;(t==="undo"||t==="redo"||t==="delete")&&window.dispatchEvent(new CustomEvent("workspace-shortcut",{detail:{action:t}}))}}}function $(){C(!0)}function x(){const a=D.value;a&&(document.fullscreenElement?document.exitFullscreen():a.requestFullscreen())}return K(()=>{window.addEventListener("message",W),C(!1)}),Q(()=>{window.removeEventListener("message",W),S()}),F({reload:$,enterFullscreen:x}),(a,e)=>{const t=Y,U=Z,q=ee;return i(),b("div",{class:X(["workspace-3d-wrap",{"workspace-3d--canvas-only":o.canvasOnly||o.hideToolbar}])},[o.canvasOnly||o.hideToolbar?p("",!0):(i(),b("div",se,[u(t,{type:o.readOnly?"info":"success",effect:"dark",size:"small"},{default:c(()=>[m(s(o.readOnly?"只读":"可交互"),1)]),_:1},8,["type"]),f("span",le,"webVRender · http://"+s(d.value)+" · scope="+s(o.scope),1),e[2]||(e[2]=f("div",{class:"spacer"},null,-1)),w.value?(i(),V(t,{key:0,type:"warning",size:"small"},{default:c(()=>[m(" Pick ("+s(w.value.x.toFixed(0))+", "+s(w.value.y.toFixed(0))+") ",1)]),_:1})):p("",!0),g.value.length?(i(),V(t,{key:1,type:"primary",size:"small"},{default:c(()=>[m(" Selected: "+s(g.value.length),1)]),_:1})):p("",!0),u(U,{size:"small",icon:T(ae),onClick:$},{default:c(()=>[...e[0]||(e[0]=[m("重载",-1)])]),_:1},8,["icon"]),u(U,{size:"small",icon:T(te),onClick:x},{default:c(()=>[...e[1]||(e[1]=[m("全屏",-1)])]),_:1},8,["icon"])])),f("div",{ref_key:"frameWrap",ref:D,class:"workspace-3d-frame"},[r.value?(i(),b("iframe",{key:0,ref_key:"frame",ref:_,src:r.value,class:"workspace-3d-iframe",allow:"fullscreen",onLoad:j},null,40,re)):p("",!0),y.value?p("",!0):(i(),b("div",ce,[u(q,{class:"is-loading",size:"32"},{default:c(()=>[u(T(ne))]),_:1}),f("span",null,s(v.value),1),e[3]||(e[3]=f("span",{class:"muted"},"如长时间未加载，请确认 SimpleLite 已以 Web-Enabled 模式启动且 8223 端口可达。",-1))]))],512)],2)}}}),we=oe(fe,[["__scopeId","data-v-17efa15d"]]);export{we as W};
