efficient-shell 4.148.0 → 4.150.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import{PdfViewer as e,ToolbarSlotContext as t,PanelActions as n}from"./chunk-CVTOZCM3.js";import{ImageAnnotator_default as r}from"./chunk-L7TEFXIS.js";import{AboutApp as i}from"./chunk-JIUJNTJA.js";import{peekPdfPreviewStage as o,claimPdfPreviewStage as s,PDF_PREVIEW_UPDATE_EVENT as a}from"./chunk-ESL5TDNA.js";import{toast_default as l}from"./chunk-KKOHUQPF.js";import"./chunk-VUXPSUWI.js";import{WindowTitle as c,getActiveModalId as d}from"./chunk-ET5HXDOR.js";import"./chunk-V453E4KU.js";import"./chunk-UB4JIOLD.js";import"./chunk-PH3PRIFP.js";import"./chunk-ZBIWNVJS.js";import{registerModalEscapeInterceptor as u}from"./chunk-QOXIUJTN.js";import"./chunk-57MIENLJ.js";import"./chunk-MAIHBBWT.js";import"./chunk-TR6PLN7W.js";import"./chunk-D65T4H6J.js";import{useRef as p,useState as h,useEffect as m}from"react";import{jsxs as x,jsx as y,Fragment as f}from"react/jsx-runtime";var g=!1;function b(e,t){return e?.url&&e.url!==t.url&&e.url.startsWith("blob:")&&URL.revokeObjectURL(e.url),t}function w(){const n=p(void 0);void 0===n.current&&(n.current=o());const[r,u]=h(n.current?.data??null);m(()=>{const e=n.current;null!=e&&(s(e),u(t=>t===e.data?t:b(t,e.data)))},[]),m(()=>{const e=n.current?.token;if(null==e)return;const t=t=>{const n=t.detail;n&&n.token===e&&u(e=>b(e,n.data))};return window.addEventListener(a,t),()=>window.removeEventListener(a,t)},[]);const g=p(void 0);m(()=>{g.current=r?.url},[r?.url]);const w=p(null);m(()=>(null!==w.current&&(clearTimeout(w.current),w.current=null),()=>{const e=g.current;e?.startsWith("blob:")&&(w.current=setTimeout(()=>URL.revokeObjectURL(e),0))}),[]);const k=r?.filename?(N=r.filename).length>24?`${N.slice(0,23)}…`:N:"Untitled";var N;const L=p(null),A=p(null),[M,E]=h(null),[S,z]=h(!1),R=p(0),T=()=>L.current?.click(),I=()=>{R.current=0,z(!1)},F=e=>{const t=e.closest("[data-modal-id]");return!t||d()===t.dataset.modalId};m(()=>{const e=()=>I(),t=()=>I(),n=e=>{"Escape"===e.key&&I()};return window.addEventListener("dragend",e),window.addEventListener("drop",t),window.addEventListener("keydown",n),()=>{window.removeEventListener("dragend",e),window.removeEventListener("drop",t),window.removeEventListener("keydown",n)}},[]);const B=e=>{const t=(e.name.split(".").pop()||"").toLowerCase(),n="pdf"===t?"pdf":"dxf"===t?"dxf":["jpg","jpeg","png","gif","webp","svg","avif","bmp"].includes(t)?"image":["stp","step","stl","obj","gltf","glb","3mf","iges","igs","ply","fbx"].includes(t)?"3d":void 0;if(!n)return void("dwg"===t?l.error("DWG files need server-side conversion. Convert to PDF or DXF first."):l.error(`Unsupported file type: .${t||"unknown"}`));const r=URL.createObjectURL(e);u(t=>(t?.url?.startsWith("blob:")&&t.url!==r&&URL.revokeObjectURL(t.url),{url:r,filename:e.name,kind:n}))},P=/* @__PURE__ */x("div",{className:"flex items-center gap-2 px-3 py-2 border-b border-gray-200 bg-gray-50 shrink-0",children:[
1
+ import{PdfViewer as e,ToolbarSlotContext as t,PanelActions as n}from"./chunk-CVTOZCM3.js";import{ImageAnnotator_default as r}from"./chunk-L7TEFXIS.js";import{AboutApp as i}from"./chunk-IQVJ3C3D.js";import{peekPdfPreviewStage as o,claimPdfPreviewStage as s,PDF_PREVIEW_UPDATE_EVENT as a}from"./chunk-ESL5TDNA.js";import{toast_default as l}from"./chunk-KKOHUQPF.js";import"./chunk-BJVY3LPW.js";import{WindowTitle as c,getActiveModalId as d}from"./chunk-ET5HXDOR.js";import"./chunk-V453E4KU.js";import"./chunk-UB4JIOLD.js";import"./chunk-PH3PRIFP.js";import"./chunk-ZBIWNVJS.js";import{registerModalEscapeInterceptor as u}from"./chunk-QOXIUJTN.js";import"./chunk-57MIENLJ.js";import"./chunk-MAIHBBWT.js";import"./chunk-TR6PLN7W.js";import"./chunk-D65T4H6J.js";import{useRef as p,useState as h,useEffect as m}from"react";import{jsxs as x,jsx as y,Fragment as f}from"react/jsx-runtime";var g=!1;function b(e,t){return e?.url&&e.url!==t.url&&e.url.startsWith("blob:")&&URL.revokeObjectURL(e.url),t}function w(){const n=p(void 0);void 0===n.current&&(n.current=o());const[r,u]=h(n.current?.data??null);m(()=>{const e=n.current;null!=e&&(s(e),u(t=>t===e.data?t:b(t,e.data)))},[]),m(()=>{const e=n.current?.token;if(null==e)return;const t=t=>{const n=t.detail;n&&n.token===e&&u(e=>b(e,n.data))};return window.addEventListener(a,t),()=>window.removeEventListener(a,t)},[]);const g=p(void 0);m(()=>{g.current=r?.url},[r?.url]);const w=p(null);m(()=>(null!==w.current&&(clearTimeout(w.current),w.current=null),()=>{const e=g.current;e?.startsWith("blob:")&&(w.current=setTimeout(()=>URL.revokeObjectURL(e),0))}),[]);const k=r?.filename?(N=r.filename).length>24?`${N.slice(0,23)}…`:N:"Untitled";var N;const L=p(null),A=p(null),[M,E]=h(null),[S,z]=h(!1),R=p(0),T=()=>L.current?.click(),I=()=>{R.current=0,z(!1)},F=e=>{const t=e.closest("[data-modal-id]");return!t||d()===t.dataset.modalId};m(()=>{const e=()=>I(),t=()=>I(),n=e=>{"Escape"===e.key&&I()};return window.addEventListener("dragend",e),window.addEventListener("drop",t),window.addEventListener("keydown",n),()=>{window.removeEventListener("dragend",e),window.removeEventListener("drop",t),window.removeEventListener("keydown",n)}},[]);const B=e=>{const t=(e.name.split(".").pop()||"").toLowerCase(),n="pdf"===t?"pdf":"dxf"===t?"dxf":["jpg","jpeg","png","gif","webp","svg","avif","bmp"].includes(t)?"image":["stp","step","stl","obj","gltf","glb","3mf","iges","igs","ply","fbx"].includes(t)?"3d":void 0;if(!n)return void("dwg"===t?l.error("DWG files need server-side conversion. Convert to PDF or DXF first."):l.error(`Unsupported file type: .${t||"unknown"}`));const r=URL.createObjectURL(e);u(t=>(t?.url?.startsWith("blob:")&&t.url!==r&&URL.revokeObjectURL(t.url),{url:r,filename:e.name,kind:n}))},P=/* @__PURE__ */x("div",{className:"flex items-center gap-2 px-3 py-2 border-b border-gray-200 bg-gray-50 shrink-0",children:[
2
2
  /* @__PURE__ */y("input",{ref:L,type:"file",accept:".pdf,.dxf,.jpg,.jpeg,.png,.gif,.webp,.svg,.avif,.bmp,.stp,.step,.stl,.obj,.gltf,.glb,.3mf,.iges,.igs,.ply,.fbx",onChange:e=>{const t=e.target.files?.[0];t&&B(t),L.current&&(L.current.value="")},className:"hidden"}),
3
3
  /* @__PURE__ */x("button",{onClick:T,className:"text-xs text-gray-700 hover:text-gray-900 px-2 py-1 rounded hover:bg-gray-200 transition-colors flex items-center gap-1",children:[
4
4
  /* @__PURE__ */y("svg",{className:"h-3.5 w-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:1.5,children:/* @__PURE__ */y("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M3.75 9.776c.112-.017.227-.026.344-.026h15.812c.117 0 .232.009.344.026m-16.5 0a2.25 2.25 0 00-1.883 2.542l.857 6a2.25 2.25 0 002.227 1.932H19.05a2.25 2.25 0 002.227-1.932l.857-6a2.25 2.25 0 00-1.883-2.542m-16.5 0V6A2.25 2.25 0 016 3.75h3.879a1.5 1.5 0 011.06.44l2.122 2.12a1.5 1.5 0 001.06.44H18A2.25 2.25 0 0120.25 9v.776"})}),"Open"]}),
@@ -34,7 +34,7 @@ return x("div",{className:"flex flex-col items-center justify-center h-full bg-g
34
34
  /* @__PURE__ */y("div",{className:"text-base font-semibold tracking-wide text-gray-700 uppercase",children:t||"Converting file"}),
35
35
  /* @__PURE__ */y("div",{className:"text-xs text-gray-400 truncate max-w-md",children:e})]}),
36
36
  /* @__PURE__ */y("div",{className:"w-72 h-1.5 rounded-full bg-gray-200 overflow-hidden",children:/* @__PURE__ */y("div",{className:"h-full w-1/3 bg-blue-500 rounded-full animate-pulse",style:{animation:"preview-bar 1.4s ease-in-out infinite"}})}),
37
- /* @__PURE__ */y("style",{children:"@keyframes preview-bar { 0% { transform: translateX(-110%); } 100% { transform: translateX(310%); } }"})]})}var k=["https://cdn.jsdelivr.net/gh/vagran/dxf-viewer-example-src@master/src/assets/fonts/Roboto-LightItalic.ttf","https://cdn.jsdelivr.net/gh/vagran/dxf-viewer-example-src@master/src/assets/fonts/NotoSansDisplay-SemiCondensedLightItalic.ttf","https://cdn.jsdelivr.net/gh/vagran/dxf-viewer-example-src@master/src/assets/fonts/NanumGothic-Regular.ttf"],N={l:"LINE",line:"LINE",pl:"PLINE",pline:"PLINE",ex:"EXTEND",extend:"EXTEND",tr:"TRIM",trim:"TRIM",e:"ERASE",erase:"ERASE",m:"MOVE",move:"MOVE",co:"COPY",cp:"COPY",copy:"COPY",o:"OFFSET",offset:"OFFSET",f:"FILLET",fillet:"FILLET",cha:"CHAMFER",chamfer:"CHAMFER",x:"EXPLODE",explode:"EXPLODE",mi:"MIRROR",mirror:"MIRROR",ro:"ROTATE",rotate:"ROTATE",sc:"SCALE",scale:"SCALE",s:"STRETCH",stretch:"STRETCH",ar:"ARRAY",array:"ARRAY",rec:"RECTANG",rectang:"RECTANG",rectangle:"RECTANG",c:"CIRCLE",circle:"CIRCLE",a:"ARC",arc:"ARC",el:"ELLIPSE",ellipse:"ELLIPSE",t:"MTEXT",mt:"MTEXT",mtext:"MTEXT",text:"TEXT",b:"BLOCK",block:"BLOCK",i:"INSERT",insert:"INSERT",ha:"HATCH",hatch:"HATCH"},L="Commands: DI distance · DIM/DLI linear dim · H / V force axis · <number> lock Δ · U undo pick · Z fit · LA layers · Esc exit";function C({url:e,filename:t,onDownload:r,onEmail:i}){const o=p(null),s=p(null),[a,l]=h(!0),[c,g]=h(null),[b,w]=h([]),[v,C]=h(!1),[A,M]=h(!0),[E,S]=h(!1),[D,j]=h("auto"),[R,T]=h(null),[I,F]=h(null),[B,P]=h(null),[H,O]=h(""),W=p(D),V=p(B);m(()=>{W.current=D},[D]),m(()=>{V.current=B},[B]);const X=p(null),U=p(null),$=p(null),[_,G]=h(""),[Y,q]=h(null),Z=p(""),K=p(null),J=p(null),Q=p(null);m(()=>{let t=!1,n=null;return l(!0),g(null),w([]),(async()=>{let r;try{r=(await(import("dxf-viewer"))).DxfViewer}catch(e){return void(t||(g("dxf-viewer is not installed in this app."),l(!1)))}if(!t&&o.current)try{if(await new Promise(e=>{const t=()=>{const n=o.current?.getBoundingClientRect();n&&n.width>4&&n.height>4?e():requestAnimationFrame(t)};t()}),t||!o.current)return;const i={autoResize:!0},a=r.DefaultOptions?.clearColor;"function"==typeof a?.clone&&(i.clearColor=a.clone().setHex(16777215)),n=new r(o.current,i),s.current=n;const c="undefined"!=typeof window&&window.__REACT_OS_SHELL_DXF_FONTS__||k;if(await n.Load({url:e,fonts:c,workerFactory:null}),t)return;try{const e=n.GetLayers?.()??[];Array.isArray(e)&&w(e.map(e=>({name:e.name,displayName:e.displayName??e.name,color:"number"==typeof e.color?e.color:void 0,visible:!0})))}catch{}const d=()=>{try{const e=o.current?.getBoundingClientRect();e&&e.width>0&&e.height>0&&n.SetSize?.(Math.round(e.width),Math.round(e.height));const t=n.GetBounds?.(),r=n.GetOrigin?.();t&&r&&n.FitView(t.minX-r.x,t.maxX-r.x,t.minY-r.y,t.maxY-r.y),n.Render?.()}catch(e){console.warn("[Preview] DXF refit failed",e)}};d(),requestAnimationFrame(d),l(!1)}catch(e){t||(g(e?.message||"Failed to render DXF."),l(!1))}})(),()=>{t=!0;try{n?.Destroy?.()}catch{}s.current=null}},[e]),m(()=>{if(!A||a)return;const e=setTimeout(()=>M(!1),5e3);return()=>clearTimeout(e)},[A,a]);const ee=b.map(e=>e.visible?"1":"0").join("");m(()=>{const e=s.current;if(a||c||!e)return;const t=e.GetScene?.(),n=e.GetCamera?.(),r=e.GetCanvas?.();if(!(t&&n&&r&&o.current))return;const i=()=>{const e=Q.current;e&&(e.overlay&&e.overlay.parentElement&&e.overlay.parentElement.removeChild(e.overlay),Q.current=null)};if(!E)return i(),T(null),void F(null);const l=document.createElement("div");l.style.cssText="position:absolute;inset:0;pointer-events:none;z-index:5;",o.current.appendChild(l);const d=document.createElementNS("http://www.w3.org/2000/svg","svg");d.setAttribute("style","position:absolute;inset:0;width:100%;height:100%;pointer-events:none;");const u=document.createElementNS("http://www.w3.org/2000/svg","defs"),p=document.createElementNS("http://www.w3.org/2000/svg","marker");p.setAttribute("id","dxf-measure-arrow"),p.setAttribute("viewBox","0 0 10 10"),p.setAttribute("refX","9"),p.setAttribute("refY","5"),p.setAttribute("markerWidth","6"),p.setAttribute("markerHeight","6"),p.setAttribute("orient","auto-start-reverse");const h=document.createElementNS("http://www.w3.org/2000/svg","path");h.setAttribute("d","M 0 0 L 10 5 L 0 10 z"),h.setAttribute("fill","#ff8800"),p.appendChild(h),u.appendChild(p),d.appendChild(u),l.appendChild(d);const m=()=>{const e=document.createElementNS("http://www.w3.org/2000/svg","line");return e.setAttribute("stroke","#ff8800"),e.setAttribute("stroke-width","1"),e.setAttribute("stroke-dasharray","6,4"),e.setAttribute("opacity","0.55"),e.style.display="none",d.appendChild(e),e},x=m(),y=m(),f=document.createElementNS("http://www.w3.org/2000/svg","line");f.setAttribute("stroke","#ff8800"),f.setAttribute("stroke-width","1"),f.setAttribute("opacity","0.85"),f.style.display="none",d.appendChild(f);const g=document.createElementNS("http://www.w3.org/2000/svg","line");g.setAttribute("stroke","#ff8800"),g.setAttribute("stroke-width","1"),g.setAttribute("opacity","0.85"),g.style.display="none",d.appendChild(g);const b=document.createElementNS("http://www.w3.org/2000/svg","line");b.setAttribute("stroke","#ff8800"),b.setAttribute("stroke-width","1.5"),b.setAttribute("stroke-linecap","round"),b.style.display="none",d.appendChild(b);const w=document.createElementNS("http://www.w3.org/2000/svg","line");w.setAttribute("stroke","#ff8800"),w.setAttribute("stroke-width","1.5"),w.setAttribute("stroke-linecap","round"),w.style.display="none",d.appendChild(w);const v=document.createElement("div");v.style.cssText="position:absolute;transform:translate(-50%,-50%);pointer-events:none;display:none;";const k="http://www.w3.org/2000/svg",N=document.createElementNS(k,"svg");N.setAttribute("width","22"),N.setAttribute("height","22"),N.setAttribute("viewBox","0 0 22 22"),N.setAttribute("style","overflow:visible;display:block"),v.appendChild(N);const L=e=>{const t=document.createElementNS(k,"g");return e(t),t.style.display="none",N.appendChild(t),t},C=L(e=>{const t=document.createElementNS(k,"rect");t.setAttribute("x","4"),t.setAttribute("y","4"),t.setAttribute("width","14"),t.setAttribute("height","14"),t.setAttribute("fill","rgba(255,255,255,0.9)"),t.setAttribute("stroke","#ff8800"),t.setAttribute("stroke-width","1.8"),e.appendChild(t)}),A=L(e=>{const t=(e,t,n,r)=>{const i=document.createElementNS(k,"line");return i.setAttribute("x1",String(e)),i.setAttribute("y1",String(t)),i.setAttribute("x2",String(n)),i.setAttribute("y2",String(r)),i.setAttribute("stroke","#ff8800"),i.setAttribute("stroke-width","2.2"),i.setAttribute("stroke-linecap","round"),i};e.appendChild(t(4,4,18,18)),e.appendChild(t(18,4,4,18))}),M=L(e=>{const t=document.createElementNS(k,"polygon");t.setAttribute("points","4,4 18,4 4,18 18,18"),t.setAttribute("fill","rgba(255,255,255,0.9)"),t.setAttribute("stroke","#ff8800"),t.setAttribute("stroke-width","1.8"),t.setAttribute("stroke-linejoin","round"),e.appendChild(t)}),D=L(e=>{const t=document.createElementNS(k,"polygon");t.setAttribute("points","11,3 19,18 3,18"),t.setAttribute("fill","rgba(255,255,255,0.9)"),t.setAttribute("stroke","#ff8800"),t.setAttribute("stroke-width","1.8"),t.setAttribute("stroke-linejoin","round"),e.appendChild(t)}),j=L(e=>{const t=document.createElementNS(k,"circle");t.setAttribute("cx","11"),t.setAttribute("cy","11"),t.setAttribute("r","7"),t.setAttribute("fill","rgba(255,255,255,0.9)"),t.setAttribute("stroke","#ff8800"),t.setAttribute("stroke-width","1.8"),e.appendChild(t);const n=(e,t,n,r)=>{const i=document.createElementNS(k,"line");return i.setAttribute("x1",String(e)),i.setAttribute("y1",String(t)),i.setAttribute("x2",String(n)),i.setAttribute("y2",String(r)),i.setAttribute("stroke","#ff8800"),i.setAttribute("stroke-width","1.6"),i.setAttribute("stroke-linecap","round"),i};e.appendChild(n(6.5,6.5,15.5,15.5)),e.appendChild(n(15.5,6.5,6.5,15.5))});l.appendChild(v),Q.current={picks:[],rawSecondClick:null,overlay:l,svg:d,line:b,fixedLine:w,fixedLabel:null,refLine:x,refLineV:y,extLineA:f,extLineB:g,markers:[],label:null,snap:v,segs:null,nodes:null};const R=n?.position?.constructor??t?.position?.constructor??null;let I=!1;const B=(e,t)=>{if(!R)return{x:0,y:0};const i=new R(e,t,0).project(n),o=r.clientWidth,s=r.clientHeight;return{x:(i.x+1)/2*o,y:(1-i.y)/2*s}};(()=>{try{const e=Q.current;if(!e)return;const n=[],r=[];let i=!1;const o=e=>{const t=e?.attributes?.instanceTransform0,n=e?.attributes?.instanceTransform1;if(t&&n){const e=[],r=Math.min(t.count,n.count);for(let i=0;i<r;i++)e.push([t.getX(i),t.getY(i),t.getZ(i),n.getX(i),n.getY(i),n.getZ(i)]);return e}const r=e?.attributes?.instanceTransform;if(r){const e=[];for(let t=0;t<r.count;t++)e.push([1,0,r.getX(t),0,1,r.getY(t)]);return e}return[[1,0,0,0,1,0]]},s=e=>{const t=!!e?.isLineSegments;if(!t&&!!!e?.isPoints)return;const s=e.geometry,a=s?.attributes?.position;if(!a)return;const l=o(s);if(t){const e=s.index,t=Math.floor((e?e.count:a.count)/2);for(let r=0;r<t;r++){const t=e?e.getX(2*r):2*r,o=e?e.getX(2*r+1):2*r+1,s=a.getX(t),c=a.getY(t),d=a.getX(o),u=a.getY(o);if(Number.isFinite(s+c+d+u))for(const e of l){if(n.length>=16e5)return void(i=!0);const t=e[0]*s+e[1]*c+e[2],r=e[3]*s+e[4]*c+e[5],o=e[0]*d+e[1]*u+e[2],a=e[3]*d+e[4]*u+e[5];t===o&&r===a||n.push(t,r,o,a)}}}else for(let e=0;e<a.count;e++){const t=a.getX(e),n=a.getY(e);if(Number.isFinite(t+n))for(const e of l)r.push(e[0]*t+e[1]*n+e[2],e[3]*t+e[4]*n+e[5])}};"function"==typeof t.traverseVisible?t.traverseVisible(s):t.traverse(s),e.segs=new Float64Array(n),e.nodes=new Float64Array(r),i&&console.warn("[Preview] DXF snap cache truncated at 400000 segments — snapping may miss some geometry."),I=!0}catch{}})();const P=(e,t,n,r,i,o,s,a)=>{const l=(n-e)*(a-o)-(r-t)*(s-i);if(Math.abs(l)<1e-9)return null;const c=((i-e)*(a-o)-(o-t)*(s-i))/l,d=((i-e)*(r-t)-(o-t)*(n-e))/l,u=1e-4;return c<-u||c>1+u||d<-u||d>1+u?null:{px:e+c*(n-e),py:t+c*(r-t),t:c}},H=()=>{const e=document.createElement("div");return e.style.cssText="position:absolute;width:10px;height:10px;border-radius:50%;background:#ff8800;border:2px solid #fff;box-shadow:0 0 0 1px rgba(0,0,0,0.25);transform:translate(-50%,-50%);pointer-events:none;",l.appendChild(e),e},O=(e,t,n)=>{const r=B(t,n);e.style.left=`${r.x}px`,e.style.top=`${r.y}px`},_=()=>{const e=Q.current;if(!e||!e.rawSecondClick||e.picks.length<2)return;const t=e.picks[0],n=e.rawSecondClick,r=V.current,i=W.current;if(null===r||!Number.isFinite(r)||"horizontal"!==i&&"vertical"!==i)e.picks[1]={x:n.x,y:n.y};else if("horizontal"===i){const i=n.x>=t.x?1:-1;e.picks[1]={x:t.x+i*Math.abs(r),y:n.y}}else{const i=n.y>=t.y?1:-1;e.picks[1]={x:n.x,y:t.y+i*Math.abs(r)}}},G=(e,t)=>{const n=W.current;return"auto"!==n?n:e&&t?Math.abs(t.x-e.x)>=Math.abs(t.y-e.y)?"horizontal":"vertical":"horizontal"},Y=()=>{const e=Q.current;if(!e)return;_();const t=W.current,n=V.current,i=null!==n&&Number.isFinite(n)&&("horizontal"===t||"vertical"===t);e.markers[0]&&O(e.markers[0],e.picks[0].x,e.picks[0].y),e.markers[1]&&O(e.markers[1],e.picks[1].x,e.picks[1].y);const o=(t,n,i)=>{if(!t)return;if(!i||e.picks.length<1)return void(t.style.display="none");const o=e.picks[0],s=r.clientWidth,a=r.clientHeight,l=4*Math.hypot(s,a),c=B(o.x,o.y),d=B(o.x+n.dx,o.y+n.dy),u=l/(Math.hypot(d.x-c.x,d.y-c.y)||1),p=B(o.x-n.dx*u,o.y-n.dy*u),h=B(o.x+n.dx*u,o.y+n.dy*u);t.setAttribute("x1",String(p.x)),t.setAttribute("y1",String(p.y)),t.setAttribute("x2",String(h.x)),t.setAttribute("y2",String(h.y)),t.style.display=""};let s="horizontal"===t,a="vertical"===t;if("auto"===t)if(e.picks.length>=2){const t=G(e.picks[0],e.picks[1]);s="horizontal"===t,a="vertical"===t}else s=!0,a=!0;if(o(e.refLine,{dx:1,dy:0},s),o(e.refLineV,{dx:0,dy:1},a),2===e.picks.length){const t=e.picks[0],o=e.picks[1],s=G(t,o),a=(()=>{const e=Q.current,t=e.picks[0],n=e.picks[1],r=G(t,n),i=W.current,o=V.current;return null!==o&&Number.isFinite(o)&&"horizontal"===i?{from:{x:n.x,y:t.y},to:{x:n.x,y:n.y}}:null!==o&&Number.isFinite(o)&&"vertical"===i?{from:{x:t.x,y:n.y},to:{x:n.x,y:n.y}}:"horizontal"===r?{from:t,to:{x:n.x,y:t.y}}:"vertical"===r?{from:t,to:{x:t.x,y:n.y}}:{from:t,to:n}})(),l=B(a.from.x,a.from.y),c=B(a.to.x,a.to.y);e.line.setAttribute("x1",String(l.x)),e.line.setAttribute("y1",String(l.y)),e.line.setAttribute("x2",String(c.x)),e.line.setAttribute("y2",String(c.y)),e.line.setAttribute("marker-start","url(#dxf-measure-arrow)"),e.line.setAttribute("marker-end","url(#dxf-measure-arrow)");const d=Math.hypot(c.x-l.x,c.y-l.y);if(e.line.style.display=d>.5?"":"none",i&&e.fixedLine){const i="horizontal"===s?{x:o.x,y:t.y}:{x:t.x,y:o.y},a=B(t.x,t.y),l=B(i.x,i.y);e.fixedLine.setAttribute("x1",String(a.x)),e.fixedLine.setAttribute("y1",String(a.y)),e.fixedLine.setAttribute("x2",String(l.x)),e.fixedLine.setAttribute("y2",String(l.y)),e.fixedLine.setAttribute("marker-start","url(#dxf-measure-arrow)"),e.fixedLine.setAttribute("marker-end","url(#dxf-measure-arrow)"),e.fixedLine.style.display="";const c=Z();c.textContent=z(Math.abs(n));const d=(a.x+l.x)/2,u=(a.y+l.y)/2;c.style.left=`${d}px`,c.style.top=`${u}px`;const p=r.clientWidth,h=r.clientHeight;c.style.display=d<0||u<0||d>p||u>h?"none":""}else e.fixedLine&&(e.fixedLine.style.display="none"),e.fixedLabel&&(e.fixedLabel.style.display="none");const u=e.extLineA,p=e.extLineB;if(!i&&"horizontal"===s&&Math.abs(o.y-t.y)>1e-9){const e=B(o.x,t.y),n=B(o.x,o.y);p.setAttribute("x1",String(e.x)),p.setAttribute("y1",String(e.y)),p.setAttribute("x2",String(n.x)),p.setAttribute("y2",String(n.y)),p.style.display="",u.style.display="none"}else if(!i&&"vertical"===s&&Math.abs(o.x-t.x)>1e-9){const e=B(t.x,o.y),n=B(o.x,o.y);p.setAttribute("x1",String(e.x)),p.setAttribute("y1",String(e.y)),p.setAttribute("x2",String(n.x)),p.setAttribute("y2",String(n.y)),p.style.display="",u.style.display="none"}else u.style.display="none",p.style.display="none";if(e.label){const t=(l.x+c.x)/2,n=(l.y+c.y)/2;e.label.style.left=`${t}px`,e.label.style.top=`${n}px`;const i=r.clientWidth,o=r.clientHeight;e.label.style.display=t<0||n<0||t>i||n>o?"none":"",d<=.5&&(e.label.style.display="none")}}else e.line.style.display="none",e.fixedLine&&(e.fixedLine.style.display="none"),e.fixedLabel&&(e.fixedLabel.style.display="none"),e.extLineA&&(e.extLineA.style.display="none"),e.extLineB&&(e.extLineB.style.display="none")},Z=()=>{const e=Q.current;if(e.fixedLabel)return e.fixedLabel;const t=document.createElement("div");return t.style.cssText="position:absolute;left:-9999px;top:-9999px;transform:translate(-50%,-50%);padding:2px 6px;font-size:11px;font-weight:600;font-family:system-ui,-apple-system,sans-serif;background:rgba(255,136,0,0.75);color:#fff;border-radius:4px;white-space:nowrap;box-shadow:0 1px 4px rgba(0,0,0,0.25);pointer-events:none;",l.appendChild(t),e.fixedLabel=t,t};let K=0,J=0,ee=0,te=!1,ne=!1,re=null;const ie=e=>{const t=e?.detail;t&&0===t.domEvent?.button&&(K=t.canvasCoord.x,J=t.canvasCoord.y,ee=performance.now(),ne=!1,te=!0)},oe=e=>{const t=r.getBoundingClientRect(),n=e.clientX-t.left,i=e.clientY-t.top;te&&(n-K)**2+(i-J)**2>16&&(ne=!0);const o=Q.current;var s;if(o&&o.snap)if(te&&ne)o.snap.style.display="none";else if(re=((e,t)=>{const n=Q.current;if(!n||!I||!n.segs)return null;const r=B(0,0),i=B(1,0),o=B(0,1),s=i.x-r.x,a=i.y-r.y,l=o.x-r.x,c=o.y-r.y,d=s*c-l*a;if(!d)return null;const u=((e-r.x)*c-(t-r.y)*l)/d,p=((t-r.y)*s-(e-r.x)*a)/d,h=18/(Math.hypot(s,a)||1),m=18/(Math.hypot(l,c)||1),x=u-h,y=u+h,f=p-m,g=p+m,b=324;let w=null,v=b,k=null,N=b,L=null,C=b,A=null,M=b;const E=[],S=n.segs;for(let n=0;n<S.length;n+=4){const i=S[n],o=S[n+1],d=S[n+2],u=S[n+3];if(i<x&&d<x||i>y&&d>y||o<f&&u<f||o>g&&u>g)continue;const p=r.x+s*i+l*o,h=r.y+a*i+c*o,m=r.x+s*d+l*u,A=r.y+a*d+c*u;let M=!1,z=e-p,D=t-h,j=z*z+D*D;j<b&&(M=!0,j<v&&(v=j,w={sx:i,sy:o,type:"endpoint"})),z=e-m,D=t-A,j=z*z+D*D,j<b&&(M=!0,j<v&&(v=j,w={sx:d,sy:u,type:"endpoint"})),z=e-(p+m)/2,D=t-(h+A)/2,j=z*z+D*D,j<b&&(M=!0,j<N&&(N=j,k={sx:(i+d)/2,sy:(o+u)/2,type:"midpoint"}));const R=m-p,T=A-h,I=R*R+T*T;if(I>0){const n=((e-p)*R+(t-h)*T)/I;n>0&&n<1&&(z=e-(p+n*R),D=t-(h+n*T),j=z*z+D*D,j<b&&(M=!0,j<C&&(C=j,L={sx:i+n*(d-i),sy:o+n*(u-o),type:"line"})))}M&&E.push({ax:i,ay:o,bx:d,by:u,apx:p,apy:h,bpx:m,bpy:A})}const z=n.nodes;if(z)for(let n=0;n<z.length;n+=2){const i=z[n],o=z[n+1];if(i<x||i>y||o<f||o>g)continue;const d=e-(r.x+s*i+l*o),u=t-(r.y+a*i+c*o),p=d*d+u*u;p<v&&(v=p,w={sx:i,sy:o,type:"node"})}for(let n=0;n<E.length;n++){const r=E[n];for(let i=n+1;i<E.length;i++){const n=E[i],o=P(r.apx,r.apy,r.bpx,r.bpy,n.apx,n.apy,n.bpx,n.bpy);if(!o)continue;const s=e-o.px,a=t-o.py,l=s*s+a*a;l>=b||l>=M||(M=l,A={sx:r.ax+o.t*(r.bx-r.ax),sy:r.ay+o.t*(r.by-r.ay),type:"intersection"})}}return(A&&w?M<v-1?A:w:A??w)??k??L})(n,i),re){const e=B(re.sx,re.sy);o.snap.style.left=`${e.x}px`,o.snap.style.top=`${e.y}px`,o.snap.style.display="",s=re.type,C.style.display="endpoint"===s?"":"none",A.style.display="intersection"===s?"":"none",M.style.display="line"===s?"":"none",D.style.display="midpoint"===s?"":"none",j.style.display="node"===s?"":"none"}else o.snap.style.display="none"},se=e=>{if(!te)return;te=!1;const t=performance.now()-ee;if(ne||t>350)return;const n=e?.detail?.position;if(!n)return;const r=re?{x:re.sx,y:re.sy}:{x:n.x,y:n.y};de(r)},ae=()=>{const e=Q.current;if(!e||2!==e.picks.length)return;_();const t=e.picks[0],n=e.picks[1],r=W.current,i=G(t,n),o=V.current,s=null!==o&&Number.isFinite(o)&&("horizontal"===r||"vertical"===r);let a,c,d="",u=i;const p=Math.abs(n.x-t.x),h=Math.abs(n.y-t.y);if(s&&"horizontal"===r?(a=h,d=" ↕",u="vertical",c=`ΔY = ${z(h)} with ΔX locked to ${z(Math.abs(o))}`):s&&"vertical"===r?(a=p,d=" ↔",u="horizontal",c=`ΔX = ${z(p)} with ΔY locked to ${z(Math.abs(o))}`):"horizontal"===i?(a=p,d=" ↔",c=`Linear dimension = ${z(p)} (ΔX)`):"vertical"===i?(a=h,d=" ↕",c=`Linear dimension = ${z(h)} (ΔY)`):(a=Math.hypot(n.x-t.x,n.y-t.y),c=`Distance = ${z(a)} ΔX = ${z(p)} ΔY = ${z(h)}`),!Number.isFinite(a))return T(null),F(null),void(e.label&&(e.label.style.opacity="0"));T(a),F(u),q(c);const m=(()=>{const e=Q.current;if(e.label)return e.label;const t=document.createElement("div");return t.style.cssText="position:absolute;left:-9999px;top:-9999px;transform:translate(-50%,-50%);padding:2px 6px;font-size:11px;font-weight:600;font-family:system-ui,-apple-system,sans-serif;background:rgba(255,136,0,0.95);color:#fff;border-radius:4px;white-space:nowrap;box-shadow:0 1px 4px rgba(0,0,0,0.25);pointer-events:none;",l.appendChild(t),e.label=t,t})();m.style.opacity="1",m.textContent=`${z(a)}${d}`};X.current=()=>{ae(),Y()};const le=e=>{e.line.style.display="none",e.fixedLine&&(e.fixedLine.style.display="none"),e.fixedLabel&&(e.fixedLabel.style.display="none"),e.extLineA&&(e.extLineA.style.display="none"),e.extLineB&&(e.extLineB.style.display="none"),e.label&&(e.label.style.opacity="0"),T(null),F(null)},ce=()=>{const e=Q.current;if(e){for(const t of e.markers)t.parentElement?.removeChild(t);e.markers=[],e.picks=[],e.rawSecondClick=null,e.refLine&&(e.refLine.style.display="none"),e.refLineV&&(e.refLineV.style.display="none"),le(e)}};U.current=ce,$.current=()=>{const e=Q.current;if(!e||0===e.picks.length)return;e.picks.pop();const t=e.markers.pop();t?.parentElement?.removeChild(t),e.rawSecondClick=null,le(e),Y()};const de=e=>{const t=Q.current;t&&(2===t.picks.length&&ce(),0===t.picks.length?(t.picks.push({x:e.x,y:e.y}),t.markers.push(H())):(t.rawSecondClick={x:e.x,y:e.y},t.picks.push({x:e.x,y:e.y}),t.markers.push(H()),ae()),Y())},ue=e=>{"Escape"===e.key&&S(!1)};r.style.cursor="crosshair";try{e.Subscribe?.("pointerdown",ie)}catch{}try{e.Subscribe?.("pointerup",se)}catch{}try{e.Subscribe?.("viewChanged",Y)}catch{}return r.addEventListener("pointermove",oe),window.addEventListener("keydown",ue),()=>{r.style.cursor="";try{e.Unsubscribe?.("pointerdown",ie)}catch{}try{e.Unsubscribe?.("pointerup",se)}catch{}try{e.Unsubscribe?.("viewChanged",Y)}catch{}r.removeEventListener("pointermove",oe),window.removeEventListener("keydown",ue),X.current=null,U.current=null,$.current=null,i(),T(null),F(null)}},[E,a,c,ee]),m(()=>{X.current?.()},[D,B]);const te=e=>{w(t=>t.map(t=>{if(t.visible===e)return t;try{s.current?.ShowLayer?.(t.name,e)}catch{}return{...t,visible:e}}))},ne=()=>{try{const e=s.current,t=e?.GetBounds?.(),n=e?.GetOrigin?.();t&&n?e.FitView(t.minX-n.x,t.maxX-n.x,t.minY-n.y,t.maxY-n.y):e?.FitView?.(),e?.Render?.()}catch{}};m(()=>{const e=e=>{if(e.defaultPrevented||e.metaKey||e.ctrlKey||e.altKey)return;if(1!==e.key.length||" "===e.key)return;const t=e.target;if(t&&("INPUT"===t.tagName||"TEXTAREA"===t.tagName||t.isContentEditable))return;const n=J.current;if(!n)return;const r=n.closest("[data-modal-id]");r&&d()!==r.dataset.modalId||K.current?.focus()};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[]);const re=p(_),ie=p(E);m(()=>{re.current=_},[_]),m(()=>{ie.current=E},[E]),m(()=>u(()=>{const e=J.current;if(!e)return!1;const t=e.closest("[data-modal-id]");return!(!t||d()!==t.dataset.modalId)&&(re.current?(G(""),q("*Cancel*"),!0):!!ie.current&&(S(!1),q("Measure off."),!0))}),[]);const oe="px-2 py-1 rounded hover:bg-gray-200 transition-colors text-gray-600 flex items-center gap-1";/* @__PURE__ */
37
+ /* @__PURE__ */y("style",{children:"@keyframes preview-bar { 0% { transform: translateX(-110%); } 100% { transform: translateX(310%); } }"})]})}var k=["https://cdn.jsdelivr.net/gh/vagran/dxf-viewer-example-src@master/src/assets/fonts/Roboto-LightItalic.ttf","https://cdn.jsdelivr.net/gh/vagran/dxf-viewer-example-src@master/src/assets/fonts/NotoSansDisplay-SemiCondensedLightItalic.ttf","https://cdn.jsdelivr.net/gh/vagran/dxf-viewer-example-src@master/src/assets/fonts/NanumGothic-Regular.ttf"],N={l:"LINE",line:"LINE",pl:"PLINE",pline:"PLINE",ex:"EXTEND",extend:"EXTEND",tr:"TRIM",trim:"TRIM",e:"ERASE",erase:"ERASE",m:"MOVE",move:"MOVE",co:"COPY",cp:"COPY",copy:"COPY",o:"OFFSET",offset:"OFFSET",f:"FILLET",fillet:"FILLET",cha:"CHAMFER",chamfer:"CHAMFER",x:"EXPLODE",explode:"EXPLODE",mi:"MIRROR",mirror:"MIRROR",ro:"ROTATE",rotate:"ROTATE",sc:"SCALE",scale:"SCALE",s:"STRETCH",stretch:"STRETCH",ar:"ARRAY",array:"ARRAY",rec:"RECTANG",rectang:"RECTANG",rectangle:"RECTANG",c:"CIRCLE",circle:"CIRCLE",a:"ARC",arc:"ARC",el:"ELLIPSE",ellipse:"ELLIPSE",t:"MTEXT",mt:"MTEXT",mtext:"MTEXT",text:"TEXT",b:"BLOCK",block:"BLOCK",i:"INSERT",insert:"INSERT",ha:"HATCH",hatch:"HATCH"},L="Commands: DI distance · DIM/DLI linear dim · H / V force axis · <number> lock Δ · U undo pick · Z fit · LA layers · Esc exit";function C({url:e,filename:t,onDownload:r,onEmail:i}){const o=p(null),s=p(null),[a,l]=h(!0),[c,g]=h(null),[b,w]=h([]),[v,C]=h(!1),[A,M]=h(!0),[E,S]=h(!1),[D,j]=h("auto"),[R,T]=h(null),[I,F]=h(null),[B,P]=h(null),[H,O]=h(""),W=p(D),V=p(B);m(()=>{W.current=D},[D]),m(()=>{V.current=B},[B]);const X=p(null),$=p(null),U=p(null),[_,G]=h(""),[Y,q]=h(null),Z=p(""),K=p(null),J=p(null),Q=p(null);m(()=>{let t=!1,n=null;return l(!0),g(null),w([]),(async()=>{let r;try{r=(await(import("dxf-viewer"))).DxfViewer}catch(e){return void(t||(g("dxf-viewer is not installed in this app."),l(!1)))}if(!t&&o.current)try{if(await new Promise(e=>{const t=()=>{const n=o.current?.getBoundingClientRect();n&&n.width>4&&n.height>4?e():requestAnimationFrame(t)};t()}),t||!o.current)return;const i={autoResize:!0},a=r.DefaultOptions?.clearColor;"function"==typeof a?.clone&&(i.clearColor=a.clone().setHex(16777215)),n=new r(o.current,i),s.current=n;const c="undefined"!=typeof window&&window.__REACT_OS_SHELL_DXF_FONTS__||k;if(await n.Load({url:e,fonts:c,workerFactory:null}),t)return;try{const e=n.GetLayers?.()??[];Array.isArray(e)&&w(e.map(e=>({name:e.name,displayName:e.displayName??e.name,color:"number"==typeof e.color?e.color:void 0,visible:!0})))}catch{}const d=()=>{try{const e=o.current?.getBoundingClientRect();e&&e.width>0&&e.height>0&&n.SetSize?.(Math.round(e.width),Math.round(e.height));const t=n.GetBounds?.(),r=n.GetOrigin?.();t&&r&&n.FitView(t.minX-r.x,t.maxX-r.x,t.minY-r.y,t.maxY-r.y),n.Render?.()}catch(e){console.warn("[Preview] DXF refit failed",e)}};d(),requestAnimationFrame(d),l(!1)}catch(e){t||(g(e?.message||"Failed to render DXF."),l(!1))}})(),()=>{t=!0;try{n?.Destroy?.()}catch{}s.current=null}},[e]),m(()=>{if(!A||a)return;const e=setTimeout(()=>M(!1),5e3);return()=>clearTimeout(e)},[A,a]);const ee=b.map(e=>e.visible?"1":"0").join("");m(()=>{const e=s.current;if(a||c||!e)return;const t=e.GetScene?.(),n=e.GetCamera?.(),r=e.GetCanvas?.();if(!(t&&n&&r&&o.current))return;const i=()=>{const e=Q.current;e&&(e.overlay&&e.overlay.parentElement&&e.overlay.parentElement.removeChild(e.overlay),Q.current=null)};if(!E)return i(),T(null),void F(null);const l=document.createElement("div");l.style.cssText="position:absolute;inset:0;pointer-events:none;z-index:5;",o.current.appendChild(l);const d=document.createElementNS("http://www.w3.org/2000/svg","svg");d.setAttribute("style","position:absolute;inset:0;width:100%;height:100%;pointer-events:none;");const u=document.createElementNS("http://www.w3.org/2000/svg","defs"),p=document.createElementNS("http://www.w3.org/2000/svg","marker");p.setAttribute("id","dxf-measure-arrow"),p.setAttribute("viewBox","0 0 10 10"),p.setAttribute("refX","9"),p.setAttribute("refY","5"),p.setAttribute("markerWidth","6"),p.setAttribute("markerHeight","6"),p.setAttribute("orient","auto-start-reverse");const h=document.createElementNS("http://www.w3.org/2000/svg","path");h.setAttribute("d","M 0 0 L 10 5 L 0 10 z"),h.setAttribute("fill","#ff8800"),p.appendChild(h),u.appendChild(p),d.appendChild(u),l.appendChild(d);const m=()=>{const e=document.createElementNS("http://www.w3.org/2000/svg","line");return e.setAttribute("stroke","#ff8800"),e.setAttribute("stroke-width","1"),e.setAttribute("stroke-dasharray","6,4"),e.setAttribute("opacity","0.55"),e.style.display="none",d.appendChild(e),e},x=m(),y=m(),f=document.createElementNS("http://www.w3.org/2000/svg","line");f.setAttribute("stroke","#ff8800"),f.setAttribute("stroke-width","1"),f.setAttribute("opacity","0.85"),f.style.display="none",d.appendChild(f);const g=document.createElementNS("http://www.w3.org/2000/svg","line");g.setAttribute("stroke","#ff8800"),g.setAttribute("stroke-width","1"),g.setAttribute("opacity","0.85"),g.style.display="none",d.appendChild(g);const b=document.createElementNS("http://www.w3.org/2000/svg","line");b.setAttribute("stroke","#ff8800"),b.setAttribute("stroke-width","1.5"),b.setAttribute("stroke-linecap","round"),b.style.display="none",d.appendChild(b);const w=document.createElementNS("http://www.w3.org/2000/svg","line");w.setAttribute("stroke","#ff8800"),w.setAttribute("stroke-width","1.5"),w.setAttribute("stroke-linecap","round"),w.style.display="none",d.appendChild(w);const v=document.createElement("div");v.style.cssText="position:absolute;transform:translate(-50%,-50%);pointer-events:none;display:none;";const k="http://www.w3.org/2000/svg",N=document.createElementNS(k,"svg");N.setAttribute("width","22"),N.setAttribute("height","22"),N.setAttribute("viewBox","0 0 22 22"),N.setAttribute("style","overflow:visible;display:block"),v.appendChild(N);const L=e=>{const t=document.createElementNS(k,"g");return e(t),t.style.display="none",N.appendChild(t),t},C=L(e=>{const t=document.createElementNS(k,"rect");t.setAttribute("x","4"),t.setAttribute("y","4"),t.setAttribute("width","14"),t.setAttribute("height","14"),t.setAttribute("fill","rgba(255,255,255,0.9)"),t.setAttribute("stroke","#ff8800"),t.setAttribute("stroke-width","1.8"),e.appendChild(t)}),A=L(e=>{const t=(e,t,n,r)=>{const i=document.createElementNS(k,"line");return i.setAttribute("x1",String(e)),i.setAttribute("y1",String(t)),i.setAttribute("x2",String(n)),i.setAttribute("y2",String(r)),i.setAttribute("stroke","#ff8800"),i.setAttribute("stroke-width","2.2"),i.setAttribute("stroke-linecap","round"),i};e.appendChild(t(4,4,18,18)),e.appendChild(t(18,4,4,18))}),M=L(e=>{const t=document.createElementNS(k,"polygon");t.setAttribute("points","4,4 18,4 4,18 18,18"),t.setAttribute("fill","rgba(255,255,255,0.9)"),t.setAttribute("stroke","#ff8800"),t.setAttribute("stroke-width","1.8"),t.setAttribute("stroke-linejoin","round"),e.appendChild(t)}),D=L(e=>{const t=document.createElementNS(k,"polygon");t.setAttribute("points","11,3 19,18 3,18"),t.setAttribute("fill","rgba(255,255,255,0.9)"),t.setAttribute("stroke","#ff8800"),t.setAttribute("stroke-width","1.8"),t.setAttribute("stroke-linejoin","round"),e.appendChild(t)}),j=L(e=>{const t=document.createElementNS(k,"circle");t.setAttribute("cx","11"),t.setAttribute("cy","11"),t.setAttribute("r","7"),t.setAttribute("fill","rgba(255,255,255,0.9)"),t.setAttribute("stroke","#ff8800"),t.setAttribute("stroke-width","1.8"),e.appendChild(t);const n=(e,t,n,r)=>{const i=document.createElementNS(k,"line");return i.setAttribute("x1",String(e)),i.setAttribute("y1",String(t)),i.setAttribute("x2",String(n)),i.setAttribute("y2",String(r)),i.setAttribute("stroke","#ff8800"),i.setAttribute("stroke-width","1.6"),i.setAttribute("stroke-linecap","round"),i};e.appendChild(n(6.5,6.5,15.5,15.5)),e.appendChild(n(15.5,6.5,6.5,15.5))});l.appendChild(v),Q.current={picks:[],rawSecondClick:null,overlay:l,svg:d,line:b,fixedLine:w,fixedLabel:null,refLine:x,refLineV:y,extLineA:f,extLineB:g,markers:[],label:null,snap:v,segs:null,nodes:null};const R=n?.position?.constructor??t?.position?.constructor??null;let I=!1;const B=(e,t)=>{if(!R)return{x:0,y:0};const i=new R(e,t,0).project(n),o=r.clientWidth,s=r.clientHeight;return{x:(i.x+1)/2*o,y:(1-i.y)/2*s}};(()=>{try{const e=Q.current;if(!e)return;const n=[],r=[];let i=!1;const o=e=>{const t=e?.attributes?.instanceTransform0,n=e?.attributes?.instanceTransform1;if(t&&n){const e=[],r=Math.min(t.count,n.count);for(let i=0;i<r;i++)e.push([t.getX(i),t.getY(i),t.getZ(i),n.getX(i),n.getY(i),n.getZ(i)]);return e}const r=e?.attributes?.instanceTransform;if(r){const e=[];for(let t=0;t<r.count;t++)e.push([1,0,r.getX(t),0,1,r.getY(t)]);return e}return[[1,0,0,0,1,0]]},s=e=>{const t=!!e?.isLineSegments;if(!t&&!!!e?.isPoints)return;const s=e.geometry,a=s?.attributes?.position;if(!a)return;const l=o(s);if(t){const e=s.index,t=Math.floor((e?e.count:a.count)/2);for(let r=0;r<t;r++){const t=e?e.getX(2*r):2*r,o=e?e.getX(2*r+1):2*r+1,s=a.getX(t),c=a.getY(t),d=a.getX(o),u=a.getY(o);if(Number.isFinite(s+c+d+u))for(const e of l){if(n.length>=16e5)return void(i=!0);const t=e[0]*s+e[1]*c+e[2],r=e[3]*s+e[4]*c+e[5],o=e[0]*d+e[1]*u+e[2],a=e[3]*d+e[4]*u+e[5];t===o&&r===a||n.push(t,r,o,a)}}}else for(let e=0;e<a.count;e++){const t=a.getX(e),n=a.getY(e);if(Number.isFinite(t+n))for(const e of l)r.push(e[0]*t+e[1]*n+e[2],e[3]*t+e[4]*n+e[5])}};"function"==typeof t.traverseVisible?t.traverseVisible(s):t.traverse(s),e.segs=new Float64Array(n),e.nodes=new Float64Array(r),i&&console.warn("[Preview] DXF snap cache truncated at 400000 segments — snapping may miss some geometry."),I=!0}catch{}})();const P=(e,t,n,r,i,o,s,a)=>{const l=(n-e)*(a-o)-(r-t)*(s-i);if(Math.abs(l)<1e-9)return null;const c=((i-e)*(a-o)-(o-t)*(s-i))/l,d=((i-e)*(r-t)-(o-t)*(n-e))/l,u=1e-4;return c<-u||c>1+u||d<-u||d>1+u?null:{px:e+c*(n-e),py:t+c*(r-t),t:c}},H=()=>{const e=document.createElement("div");return e.style.cssText="position:absolute;width:10px;height:10px;border-radius:50%;background:#ff8800;border:2px solid #fff;box-shadow:0 0 0 1px rgba(0,0,0,0.25);transform:translate(-50%,-50%);pointer-events:none;",l.appendChild(e),e},O=(e,t,n)=>{const r=B(t,n);e.style.left=`${r.x}px`,e.style.top=`${r.y}px`},_=()=>{const e=Q.current;if(!e||!e.rawSecondClick||e.picks.length<2)return;const t=e.picks[0],n=e.rawSecondClick,r=V.current,i=W.current;if(null===r||!Number.isFinite(r)||"horizontal"!==i&&"vertical"!==i)e.picks[1]={x:n.x,y:n.y};else if("horizontal"===i){const i=n.x>=t.x?1:-1;e.picks[1]={x:t.x+i*Math.abs(r),y:n.y}}else{const i=n.y>=t.y?1:-1;e.picks[1]={x:n.x,y:t.y+i*Math.abs(r)}}},G=(e,t)=>{const n=W.current;return"auto"!==n?n:e&&t?Math.abs(t.x-e.x)>=Math.abs(t.y-e.y)?"horizontal":"vertical":"horizontal"},Y=()=>{const e=Q.current;if(!e)return;_();const t=W.current,n=V.current,i=null!==n&&Number.isFinite(n)&&("horizontal"===t||"vertical"===t);e.markers[0]&&O(e.markers[0],e.picks[0].x,e.picks[0].y),e.markers[1]&&O(e.markers[1],e.picks[1].x,e.picks[1].y);const o=(t,n,i)=>{if(!t)return;if(!i||e.picks.length<1)return void(t.style.display="none");const o=e.picks[0],s=r.clientWidth,a=r.clientHeight,l=4*Math.hypot(s,a),c=B(o.x,o.y),d=B(o.x+n.dx,o.y+n.dy),u=l/(Math.hypot(d.x-c.x,d.y-c.y)||1),p=B(o.x-n.dx*u,o.y-n.dy*u),h=B(o.x+n.dx*u,o.y+n.dy*u);t.setAttribute("x1",String(p.x)),t.setAttribute("y1",String(p.y)),t.setAttribute("x2",String(h.x)),t.setAttribute("y2",String(h.y)),t.style.display=""};let s="horizontal"===t,a="vertical"===t;if("auto"===t)if(e.picks.length>=2){const t=G(e.picks[0],e.picks[1]);s="horizontal"===t,a="vertical"===t}else s=!0,a=!0;if(o(e.refLine,{dx:1,dy:0},s),o(e.refLineV,{dx:0,dy:1},a),2===e.picks.length){const t=e.picks[0],o=e.picks[1],s=G(t,o),a=(()=>{const e=Q.current,t=e.picks[0],n=e.picks[1],r=G(t,n),i=W.current,o=V.current;return null!==o&&Number.isFinite(o)&&"horizontal"===i?{from:{x:n.x,y:t.y},to:{x:n.x,y:n.y}}:null!==o&&Number.isFinite(o)&&"vertical"===i?{from:{x:t.x,y:n.y},to:{x:n.x,y:n.y}}:"horizontal"===r?{from:t,to:{x:n.x,y:t.y}}:"vertical"===r?{from:t,to:{x:t.x,y:n.y}}:{from:t,to:n}})(),l=B(a.from.x,a.from.y),c=B(a.to.x,a.to.y);e.line.setAttribute("x1",String(l.x)),e.line.setAttribute("y1",String(l.y)),e.line.setAttribute("x2",String(c.x)),e.line.setAttribute("y2",String(c.y)),e.line.setAttribute("marker-start","url(#dxf-measure-arrow)"),e.line.setAttribute("marker-end","url(#dxf-measure-arrow)");const d=Math.hypot(c.x-l.x,c.y-l.y);if(e.line.style.display=d>.5?"":"none",i&&e.fixedLine){const i="horizontal"===s?{x:o.x,y:t.y}:{x:t.x,y:o.y},a=B(t.x,t.y),l=B(i.x,i.y);e.fixedLine.setAttribute("x1",String(a.x)),e.fixedLine.setAttribute("y1",String(a.y)),e.fixedLine.setAttribute("x2",String(l.x)),e.fixedLine.setAttribute("y2",String(l.y)),e.fixedLine.setAttribute("marker-start","url(#dxf-measure-arrow)"),e.fixedLine.setAttribute("marker-end","url(#dxf-measure-arrow)"),e.fixedLine.style.display="";const c=Z();c.textContent=z(Math.abs(n));const d=(a.x+l.x)/2,u=(a.y+l.y)/2;c.style.left=`${d}px`,c.style.top=`${u}px`;const p=r.clientWidth,h=r.clientHeight;c.style.display=d<0||u<0||d>p||u>h?"none":""}else e.fixedLine&&(e.fixedLine.style.display="none"),e.fixedLabel&&(e.fixedLabel.style.display="none");const u=e.extLineA,p=e.extLineB;if(!i&&"horizontal"===s&&Math.abs(o.y-t.y)>1e-9){const e=B(o.x,t.y),n=B(o.x,o.y);p.setAttribute("x1",String(e.x)),p.setAttribute("y1",String(e.y)),p.setAttribute("x2",String(n.x)),p.setAttribute("y2",String(n.y)),p.style.display="",u.style.display="none"}else if(!i&&"vertical"===s&&Math.abs(o.x-t.x)>1e-9){const e=B(t.x,o.y),n=B(o.x,o.y);p.setAttribute("x1",String(e.x)),p.setAttribute("y1",String(e.y)),p.setAttribute("x2",String(n.x)),p.setAttribute("y2",String(n.y)),p.style.display="",u.style.display="none"}else u.style.display="none",p.style.display="none";if(e.label){const t=(l.x+c.x)/2,n=(l.y+c.y)/2;e.label.style.left=`${t}px`,e.label.style.top=`${n}px`;const i=r.clientWidth,o=r.clientHeight;e.label.style.display=t<0||n<0||t>i||n>o?"none":"",d<=.5&&(e.label.style.display="none")}}else e.line.style.display="none",e.fixedLine&&(e.fixedLine.style.display="none"),e.fixedLabel&&(e.fixedLabel.style.display="none"),e.extLineA&&(e.extLineA.style.display="none"),e.extLineB&&(e.extLineB.style.display="none")},Z=()=>{const e=Q.current;if(e.fixedLabel)return e.fixedLabel;const t=document.createElement("div");return t.style.cssText="position:absolute;left:-9999px;top:-9999px;transform:translate(-50%,-50%);padding:2px 6px;font-size:11px;font-weight:600;font-family:system-ui,-apple-system,sans-serif;background:rgba(255,136,0,0.75);color:#fff;border-radius:4px;white-space:nowrap;box-shadow:0 1px 4px rgba(0,0,0,0.25);pointer-events:none;",l.appendChild(t),e.fixedLabel=t,t};let K=0,J=0,ee=0,te=!1,ne=!1,re=null;const ie=e=>{const t=e?.detail;t&&0===t.domEvent?.button&&(K=t.canvasCoord.x,J=t.canvasCoord.y,ee=performance.now(),ne=!1,te=!0)},oe=e=>{const t=r.getBoundingClientRect(),n=e.clientX-t.left,i=e.clientY-t.top;te&&(n-K)**2+(i-J)**2>16&&(ne=!0);const o=Q.current;var s;if(o&&o.snap)if(te&&ne)o.snap.style.display="none";else if(re=((e,t)=>{const n=Q.current;if(!n||!I||!n.segs)return null;const r=B(0,0),i=B(1,0),o=B(0,1),s=i.x-r.x,a=i.y-r.y,l=o.x-r.x,c=o.y-r.y,d=s*c-l*a;if(!d)return null;const u=((e-r.x)*c-(t-r.y)*l)/d,p=((t-r.y)*s-(e-r.x)*a)/d,h=18/(Math.hypot(s,a)||1),m=18/(Math.hypot(l,c)||1),x=u-h,y=u+h,f=p-m,g=p+m,b=324;let w=null,v=b,k=null,N=b,L=null,C=b,A=null,M=b;const E=[],S=n.segs;for(let n=0;n<S.length;n+=4){const i=S[n],o=S[n+1],d=S[n+2],u=S[n+3];if(i<x&&d<x||i>y&&d>y||o<f&&u<f||o>g&&u>g)continue;const p=r.x+s*i+l*o,h=r.y+a*i+c*o,m=r.x+s*d+l*u,A=r.y+a*d+c*u;let M=!1,z=e-p,D=t-h,j=z*z+D*D;j<b&&(M=!0,j<v&&(v=j,w={sx:i,sy:o,type:"endpoint"})),z=e-m,D=t-A,j=z*z+D*D,j<b&&(M=!0,j<v&&(v=j,w={sx:d,sy:u,type:"endpoint"})),z=e-(p+m)/2,D=t-(h+A)/2,j=z*z+D*D,j<b&&(M=!0,j<N&&(N=j,k={sx:(i+d)/2,sy:(o+u)/2,type:"midpoint"}));const R=m-p,T=A-h,I=R*R+T*T;if(I>0){const n=((e-p)*R+(t-h)*T)/I;n>0&&n<1&&(z=e-(p+n*R),D=t-(h+n*T),j=z*z+D*D,j<b&&(M=!0,j<C&&(C=j,L={sx:i+n*(d-i),sy:o+n*(u-o),type:"line"})))}M&&E.push({ax:i,ay:o,bx:d,by:u,apx:p,apy:h,bpx:m,bpy:A})}const z=n.nodes;if(z)for(let n=0;n<z.length;n+=2){const i=z[n],o=z[n+1];if(i<x||i>y||o<f||o>g)continue;const d=e-(r.x+s*i+l*o),u=t-(r.y+a*i+c*o),p=d*d+u*u;p<v&&(v=p,w={sx:i,sy:o,type:"node"})}for(let n=0;n<E.length;n++){const r=E[n];for(let i=n+1;i<E.length;i++){const n=E[i],o=P(r.apx,r.apy,r.bpx,r.bpy,n.apx,n.apy,n.bpx,n.bpy);if(!o)continue;const s=e-o.px,a=t-o.py,l=s*s+a*a;l>=b||l>=M||(M=l,A={sx:r.ax+o.t*(r.bx-r.ax),sy:r.ay+o.t*(r.by-r.ay),type:"intersection"})}}return(A&&w?M<v-1?A:w:A??w)??k??L})(n,i),re){const e=B(re.sx,re.sy);o.snap.style.left=`${e.x}px`,o.snap.style.top=`${e.y}px`,o.snap.style.display="",s=re.type,C.style.display="endpoint"===s?"":"none",A.style.display="intersection"===s?"":"none",M.style.display="line"===s?"":"none",D.style.display="midpoint"===s?"":"none",j.style.display="node"===s?"":"none"}else o.snap.style.display="none"},se=e=>{if(!te)return;te=!1;const t=performance.now()-ee;if(ne||t>350)return;const n=e?.detail?.position;if(!n)return;const r=re?{x:re.sx,y:re.sy}:{x:n.x,y:n.y};de(r)},ae=()=>{const e=Q.current;if(!e||2!==e.picks.length)return;_();const t=e.picks[0],n=e.picks[1],r=W.current,i=G(t,n),o=V.current,s=null!==o&&Number.isFinite(o)&&("horizontal"===r||"vertical"===r);let a,c,d="",u=i;const p=Math.abs(n.x-t.x),h=Math.abs(n.y-t.y);if(s&&"horizontal"===r?(a=h,d=" ↕",u="vertical",c=`ΔY = ${z(h)} with ΔX locked to ${z(Math.abs(o))}`):s&&"vertical"===r?(a=p,d=" ↔",u="horizontal",c=`ΔX = ${z(p)} with ΔY locked to ${z(Math.abs(o))}`):"horizontal"===i?(a=p,d=" ↔",c=`Linear dimension = ${z(p)} (ΔX)`):"vertical"===i?(a=h,d=" ↕",c=`Linear dimension = ${z(h)} (ΔY)`):(a=Math.hypot(n.x-t.x,n.y-t.y),c=`Distance = ${z(a)} ΔX = ${z(p)} ΔY = ${z(h)}`),!Number.isFinite(a))return T(null),F(null),void(e.label&&(e.label.style.opacity="0"));T(a),F(u),q(c);const m=(()=>{const e=Q.current;if(e.label)return e.label;const t=document.createElement("div");return t.style.cssText="position:absolute;left:-9999px;top:-9999px;transform:translate(-50%,-50%);padding:2px 6px;font-size:11px;font-weight:600;font-family:system-ui,-apple-system,sans-serif;background:rgba(255,136,0,0.95);color:#fff;border-radius:4px;white-space:nowrap;box-shadow:0 1px 4px rgba(0,0,0,0.25);pointer-events:none;",l.appendChild(t),e.label=t,t})();m.style.opacity="1",m.textContent=`${z(a)}${d}`};X.current=()=>{ae(),Y()};const le=e=>{e.line.style.display="none",e.fixedLine&&(e.fixedLine.style.display="none"),e.fixedLabel&&(e.fixedLabel.style.display="none"),e.extLineA&&(e.extLineA.style.display="none"),e.extLineB&&(e.extLineB.style.display="none"),e.label&&(e.label.style.opacity="0"),T(null),F(null)},ce=()=>{const e=Q.current;if(e){for(const t of e.markers)t.parentElement?.removeChild(t);e.markers=[],e.picks=[],e.rawSecondClick=null,e.refLine&&(e.refLine.style.display="none"),e.refLineV&&(e.refLineV.style.display="none"),le(e)}};$.current=ce,U.current=()=>{const e=Q.current;if(!e||0===e.picks.length)return;e.picks.pop();const t=e.markers.pop();t?.parentElement?.removeChild(t),e.rawSecondClick=null,le(e),Y()};const de=e=>{const t=Q.current;t&&(2===t.picks.length&&ce(),0===t.picks.length?(t.picks.push({x:e.x,y:e.y}),t.markers.push(H())):(t.rawSecondClick={x:e.x,y:e.y},t.picks.push({x:e.x,y:e.y}),t.markers.push(H()),ae()),Y())},ue=e=>{"Escape"===e.key&&S(!1)};r.style.cursor="crosshair";try{e.Subscribe?.("pointerdown",ie)}catch{}try{e.Subscribe?.("pointerup",se)}catch{}try{e.Subscribe?.("viewChanged",Y)}catch{}return r.addEventListener("pointermove",oe),window.addEventListener("keydown",ue),()=>{r.style.cursor="";try{e.Unsubscribe?.("pointerdown",ie)}catch{}try{e.Unsubscribe?.("pointerup",se)}catch{}try{e.Unsubscribe?.("viewChanged",Y)}catch{}r.removeEventListener("pointermove",oe),window.removeEventListener("keydown",ue),X.current=null,$.current=null,U.current=null,i(),T(null),F(null)}},[E,a,c,ee]),m(()=>{X.current?.()},[D,B]);const te=e=>{w(t=>t.map(t=>{if(t.visible===e)return t;try{s.current?.ShowLayer?.(t.name,e)}catch{}return{...t,visible:e}}))},ne=()=>{try{const e=s.current,t=e?.GetBounds?.(),n=e?.GetOrigin?.();t&&n?e.FitView(t.minX-n.x,t.maxX-n.x,t.minY-n.y,t.maxY-n.y):e?.FitView?.(),e?.Render?.()}catch{}};m(()=>{const e=e=>{if(e.defaultPrevented||e.metaKey||e.ctrlKey||e.altKey)return;if(1!==e.key.length||" "===e.key)return;const t=e.target;if(t&&("INPUT"===t.tagName||"TEXTAREA"===t.tagName||t.isContentEditable))return;const n=J.current;if(!n)return;const r=n.closest("[data-modal-id]");r&&d()!==r.dataset.modalId||K.current?.focus()};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[]);const re=p(_),ie=p(E);m(()=>{re.current=_},[_]),m(()=>{ie.current=E},[E]),m(()=>u(()=>{const e=J.current;if(!e)return!1;const t=e.closest("[data-modal-id]");return!(!t||d()!==t.dataset.modalId)&&(re.current?(G(""),q("*Cancel*"),!0):!!ie.current&&(S(!1),q("Measure off."),!0))}),[]);const oe="px-2 py-1 rounded hover:bg-gray-200 transition-colors text-gray-600 flex items-center gap-1";/* @__PURE__ */
38
38
  return x("div",{ref:J,className:"flex flex-col h-full",children:[
39
39
  /* @__PURE__ */x(n,{children:[
40
40
  /* @__PURE__ */x("button",{onClick:()=>C(e=>!e),className:oe+(v?" bg-gray-200":""),title:"Toggle layer visibility",disabled:0===b.length,children:[
@@ -80,7 +80,7 @@ return x("div",{ref:J,className:"flex flex-col h-full",children:[
80
80
  /* @__PURE__ */x("div",{className:"shrink-0 border-t border-gray-200 bg-gray-50",children:[Y&&/* @__PURE__ */y("div",{className:"px-2.5 pt-1 text-[11px] font-mono text-gray-500 truncate",title:Y,children:Y}),
81
81
  /* @__PURE__ */x("div",{className:"flex items-center gap-1.5 px-2.5 h-7",children:[
82
82
  /* @__PURE__ */y("span",{className:"text-[11px] font-mono font-semibold text-gray-400 select-none",children:">"}),
83
- /* @__PURE__ */y("input",{ref:K,value:_,onChange:e=>G(e.target.value),onKeyDown:e=>{"Enter"===e.key||" "===e.key?(e.preventDefault(),(e=>{const t=e.trim()||Z.current;if(G(""),!t)return;const n=t.toLowerCase().split(/\s+/)[0],r=()=>{Z.current=t},i=(e,t)=>{S(!0),j(e),U.current?.(),q(t),r()};if(/^-?(\d+\.?\d*|\.\d+)$/.test(n))if(!E||"horizontal"!==D&&"vertical"!==D)q("Fixed distances apply in H or V mode — type H or V first.");else{const e=parseFloat(n);e?(O(n),P(e),q(`Δ${"horizontal"===D?"X":"Y"} locked to ${z(Math.abs(e))} — the label shows the perpendicular distance`)):(O(""),P(null),q("Fixed distance cleared."))}else switch(n){case"di":case"dist":case"mea":case"measuregeom":i("point","DIST — click two points; straight-line distance (Esc to exit)");break;case"dim":case"dli":case"dimlin":case"dimlinear":i("auto","DIMLINEAR — click two points; measures ΔX or ΔY, whichever is larger (H / V to force)");break;case"h":case"hor":case"horizontal":S(!0),j("horizontal"),q("Horizontal — ΔX between the two picks"),r();break;case"v":case"ver":case"vertical":S(!0),j("vertical"),q("Vertical — ΔY between the two picks"),r();break;case"au":case"auto":S(!0),j("auto"),q("Auto (DIMLINEAR) — measures along the dominant axis of the two picks"),r();break;case"measure":S(!E),q(E?"Measure off.":"Measure on — click two points."),r();break;case"u":case"undo":$.current?.(),q("Last pick removed."),r();break;case"z":case"ze":case"zoom":case"fit":case"zoomextents":ne(),q("Zoom extents."),r();break;case"la":case"layer":case"layers":C(e=>!e),q("Layer panel toggled."),r();break;case"off":case"clear":P(null),O(""),U.current?.(),q("Measurement cleared."),r();break;case"?":case"help":q(L);break;default:{const e=N[n];q(e?`${e} is a drawing command — Preview is a read-only viewer. Measuring: DI, DIM, H, V (? for help)`:`Unknown command "${n.toUpperCase()}" — try DI, DIM, H, V, Z, LA (? for help)`)}}})(_)):"Escape"===e.key&&(_?(e.stopPropagation(),G(""),q("*Cancel*")):e.target.blur())},placeholder:"Type a command — DI, DIM, H, V, Z, LA (? for help)",spellCheck:!1,autoComplete:"off",className:"flex-1 min-w-0 bg-transparent text-[11px] font-mono text-gray-700 focus:outline-none placeholder:text-gray-300"})]})]})]})}var A="https://cdn.jsdelivr.net/npm/online-3d-viewer@0.18.0/libs/";function M(e,t=0){return{id:e.GetId?.()??0,name:e.GetName?.()||(0===t?"Root":"Node"),isMeshNode:!!e.IsMeshNode?.(),meshIndices:e.GetMeshIndices?.()??[],children:(e.GetChildNodes?.()??[]).map(e=>M(e,t+1))}}function E(e,t){t.add(e.id);for(const n of e.children)E(n,t)}function S(e,t){const n=/^#?([0-9a-f]{6})$/i.exec(t),r=n?parseInt(n[1],16):0;return new e.RGBColor(r>>16&255,r>>8&255,255&r)}function z(e){return e>=1e3?`${(e/1e3).toFixed(3)} m`:`${e.toFixed(2)} mm`}function D({url:e,filename:t,onDownload:r,onEmail:i}){const o=p(null),s=p(null),a=p(null),[l,c]=h(!0),[d,u]=h(null),[f,b]=h(!0),[w,v]=h(null),[k,N]=h({}),[L,C]=h(/* @__PURE__ */new Set),[D,j]=h("#f5f6f8"),[R,T]=h(!0),[I,F]=h("#000000"),[B,P]=h(1),[H,O]=h(!1),[W,V]=h(!1),[X,U]=h(!1),[$,_]=h(!1),[G,Y]=h("x"),[q,Z]=h(!1),[K,J]=h(.5),[Q,ee]=h(0),[te,ne]=h(!1),[re,ie]=h("point"),[oe,se]=h(null),ae=p(null),le=p(null);m(()=>{let n=!1,r=null,i=null;return c(!0),u(null),v(null),N({}),C(/* @__PURE__ */new Set),(async()=>{let l;try{l=await(import("online-3d-viewer"))}catch{return void(n||(u("online-3d-viewer is not installed in this app. Add it to enable 3D file viewing."),c(!1)))}if(a.current=l,!n&&o.current&&(await new Promise(e=>{const t=()=>{const n=o.current?.getBoundingClientRect();n&&n.width>4&&n.height>4?e():requestAnimationFrame(t)};t()}),!n&&o.current))try{const a="undefined"!=typeof window&&window.__REACT_OS_SHELL_O3DV_LIBS__||A;l.SetExternalLibLocation?.(a),function(){if(g)return;if("undefined"==typeof HTMLCanvasElement)return;g=!0;const e=HTMLCanvasElement.prototype.getContext;HTMLCanvasElement.prototype.getContext=function(t,n){return"webgl"!==t&&"webgl2"!==t&&"experimental-webgl"!==t||(n={...n||{},stencil:!0}),e.call(this,t,n)},console.info("[Preview] section: canvas getContext patched (force stencil=true)")}(),r=new l.EmbeddedViewer(o.current,{backgroundColor:new l.RGBAColor(245,246,248,255),defaultColor:new l.RGBColor(180,188,200),edgeSettings:new l.EdgeSettings(!0,new l.RGBColor(0,0,0),1),onModelLoaded:()=>{if(!n){try{const e=r.GetModel?.(),t=e?.GetRootNode?.();if(t){const e=M(t);v(e);const n={[e.id]:!0};for(const t of e.children)n[t.id]=!0;N(n)}}catch(e){console.warn("[Preview] mesh tree extraction failed",e)}c(!1)}},onModelLoadFailed:()=>{n||(u("Failed to load 3D model."),c(!1))}}),s.current=r;const d=new l.InputFile(t,l.FileSource.Url,e);r.LoadModelFromInputFiles([d]),o.current&&"undefined"!=typeof ResizeObserver&&(i=new ResizeObserver(()=>{try{const e=s.current;e?.Resize?e.Resize():e?.viewer?.Resize&&e.viewer.Resize(),e?.viewer?.Render?.()}catch{}}),i.observe(o.current))}catch(e){n||(u(e?.message||"Failed to load 3D model."),c(!1))}})(),()=>{n=!0;try{i?.disconnect()}catch{}try{r?.Destroy?.()}catch{}s.current=null}},[e,t]),m(()=>{const e=s.current;if(e?.viewer)try{const t=e=>{if(e.userData?.__sectionHelper)return;const t=e.userData?.originalMeshInstance??e.userData,n=t?.id?.nodeId??t?.nodeId;"number"==typeof n&&(e.visible=!L.has(n))};e.viewer.mainModel?.EnumerateMeshesAndLines?.(t),e.viewer.mainModel?.EnumerateEdges?.(t),e.viewer.Render?.()}catch(e){console.warn("[Preview] visibility update failed",e)}},[L,w]),m(()=>{const e=a.current,t=s.current;if(e&&t?.viewer)try{t.viewer.SetEdgeSettings(new e.EdgeSettings(R,S(e,I),B));const n=le.current;if(n){const e=[];t.viewer.mainModel?.EnumerateEdges?.(t=>{t.userData?.__sectionHelper&&e.push(t)});for(const t of e)t.parent?.remove(t),t.geometry?.dispose?.(),t.material?.dispose?.();const r=n.plane,i=e=>{e&&!n.materialState.has(e)&&(n.materialState.set(e,{clippingPlanes:e.clippingPlanes,clipShadows:e.clipShadows}),e.clippingPlanes=[r],e.clipShadows=!0,e.needsUpdate=!0)};t.viewer.mainModel?.EnumerateEdges?.(e=>{const t=e.material;if(Array.isArray(t))for(const e of t)i(e);else i(t)})}t.viewer.Render?.()}catch{}},[R,I,B]),m(()=>{const e=a.current,t=s.current;if(e&&t?.viewer)try{const n=S(e,D);t.viewer.SetBackgroundColor(new e.RGBAColor(n.r,n.g,n.b,255)),t.viewer.Render?.()}catch{}},[D]),m(()=>{const e=s.current;if(!e?.viewer||l)return;const t=e.viewer.renderer,n=e.viewer.scene;if(!t||!n)return;if(le.current){const e=le.current;for(const[t,n]of e.materialState.entries())t.clippingPlanes=n.clippingPlanes,t.clipShadows=n.clipShadows,t.needsUpdate=!0;for(const t of e.helpers)t.parent?.remove(t),t.material?.dispose?.();e.capMesh&&(n.remove(e.capMesh),e.capMesh.geometry?.dispose?.(),e.capMesh.material?.dispose?.()),le.current=null}if(!$)return t.localClippingEnabled=!1,void e.viewer.Render?.();const r=e.viewer.GetBoundingBox?.(()=>!0);if(!r)return;const i=[];if(e.viewer.mainModel?.EnumerateMeshes?.(e=>{e.userData?.__sectionHelper||i.push(e)}),!i.length)return t.localClippingEnabled=!1,void e.viewer.Render?.();const o=i[0],a=o.constructor,c=o.material?.constructor,d=o.geometry?.constructor,u=o.geometry?.attributes?.position?.constructor;a&&c&&d&&u||console.warn("[Preview] section: missing THREE constructors, falling back to no cap");const p=7681;let h=!0;try{const e=t.getContext?.(),n=e?.getContextAttributes?.();h=!1!==n?.stencil,t.autoClearStencil=!0,console.info("[Preview] section: stencil buffer =",h,"targets =",i.length)}catch{}t.localClippingEnabled=!0;const m={normal:{x:0,y:0,z:-1},constant:0,clone:function e(){const t={normal:{x:this.normal.x,y:this.normal.y,z:this.normal.z},constant:this.constant};return t.clone=e,t}},x=[],y=/* @__PURE__ */new Map,f=e=>{e&&!y.has(e)&&(y.set(e,{clippingPlanes:e.clippingPlanes,clipShadows:e.clipShadows}),e.clippingPlanes=[m],e.clipShadows=!0,e.needsUpdate=!0)};for(const e of i){const t=e.material;if(Array.isArray(t))for(const e of t)f(e);else f(t);const n=Array.isArray(t)?t[0]:t;if(a&&h&&n?.clone){const t=(t,r)=>{const i=n.clone();i.depthWrite=!1,i.depthTest=!1,i.colorWrite=!1,i.stencilWrite=!0,i.stencilFunc=519,i.stencilFail=r,i.stencilZFail=r,i.stencilZPass=r,i.side=t,i.transparent=!1,i.clippingPlanes=[m],i.clipShadows=!0,i.needsUpdate=!0;const o=new a(e.geometry,i);o.matrixAutoUpdate=!1,o.renderOrder=1,o.userData.__sectionHelper=!0,e.add(o),x.push(o)};t(1,7682),t(0,7683)}}e.viewer.mainModel?.EnumerateEdges?.(e=>{const t=e.material;if(Array.isArray(t))for(const e of t)f(e);else f(t)});let g=null;const b=i[0]?.material&&(Array.isArray(i[0].material)?i[0].material[0]:i[0].material);if(h&&a&&d&&u&&b?.clone){const e=r.max.x-r.min.x,t=r.max.y-r.min.y,i=r.max.z-r.min.z,o=2*Math.max(e,t,i,1)/2,s=new d,l=new Float32Array([-o,-o,0,o,-o,0,o,o,0,-o,o,0]),c=new Float32Array([0,0,1,0,0,1,0,0,1,0,0,1]);s.setAttribute("position",new u(l,3)),s.setAttribute("normal",new u(c,3)),s.setIndex([0,1,2,0,2,3]);const h=b.clone(),m=b.color?.getHex?.()??11844808;h.emissive?.setHex?.(m),"emissiveIntensity"in h&&(h.emissiveIntensity=.25),h.side=2,h.transparent=!1,h.opacity=1,h.stencilWrite=!0,h.stencilRef=0,h.stencilFunc=517,h.stencilFail=p,h.stencilZFail=p,h.stencilZPass=p,h.clippingPlanes=[],h.polygonOffset=!0,h.polygonOffsetFactor=-1,h.polygonOffsetUnits=-1,h.needsUpdate=!0,g=new a(s,h),g.renderOrder=2,g.userData.__sectionHelper=!0,n.add(g)}le.current={plane:m,capMesh:g,helpers:x,materialState:y,bbox:r},console.info("[Preview] section: helpers =",x.length,"cap =",!!g),e.viewer.Render?.()},[$,l,w]),m(()=>{const e=s.current,t=le.current;if(e?.viewer&&t&&$)try{const n=t.bbox,r="x"===G?0:"y"===G?1:2,i=[n.min.x,n.min.y,n.min.z][r],o=i+([n.max.x,n.max.y,n.max.z][r]-i)*K,s=Q*Math.PI/180,a=Math.cos(s),l=Math.sin(s),c=q?-1:1;let d=0,u=0,p=0;"x"===G?(d=c*a,p=c*l):"y"===G?(u=c*a,d=c*l):(p=c*a,u=c*l);const h={x:(n.min.x+n.max.x)/2,y:(n.min.y+n.max.y)/2,z:(n.min.z+n.max.z)/2},m="x"===G?o:h.x,x="y"===G?o:h.y,y="z"===G?o:h.z;if(t.plane.normal.x=d,t.plane.normal.y=u,t.plane.normal.z=p,t.plane.constant=-(d*m+u*x+p*y),t.capMesh){const e=h.x,n=h.y,r=h.z,i=d*e+u*n+p*r+t.plane.constant,o=e-d*i,s=n-u*i,a=r-p*i;t.capMesh.position.set(o,s,a),t.capMesh.lookAt?.(o+d,s+u,a+p)}e.viewer.Render?.()}catch(e){console.warn("[Preview] section update failed",e)}},[$,G,q,K,Q]),m(()=>{const e=s.current;if(!e?.viewer||l||!o.current)return;const t=e.viewer.renderer,n=e.viewer.scene,r=t?.domElement;if(!t||!n||!r)return;let i=null;if(e.viewer.mainModel?.EnumerateMeshes?.(e=>{i||e.userData?.__sectionHelper||e.userData?.__measureHelper||(i=e)}),!i)return;const c=i.position.constructor,d=i.constructor,u=(Array.isArray(i.material)?i.material[0]:i.material)?.constructor,p=i.geometry.constructor,h=i.geometry.attributes?.position?.constructor;if(!(c&&d&&u&&p&&h))return;let m=null,x=null;n.traverse(e=>{if(m&&x)return;if(!e?.isLineSegments)return;m=e.constructor;const t=Array.isArray(e.material)?e.material[0]:e.material;t?.constructor&&(x=t.constructor)});const y=()=>{const t=ae.current;if(t){null!==t.rafId&&cancelAnimationFrame(t.rafId);for(const e of t.markers)n.remove(e),e.geometry?.dispose?.(),e.material?.dispose?.();t.line&&(n.remove(t.line),t.line.geometry?.dispose?.(),t.line.material?.dispose?.()),t.label&&t.label.parentElement&&t.label.parentElement.removeChild(t.label),ae.current=null,e.viewer.Render?.()}};if(!te)return y(),void se(null);ae.current={points:[],normals:[],markers:[],line:null,label:null,rafId:null};const f=a.current,g=f?.IntersectionMode?.MeshOnly??1,b=e.viewer.GetBoundingBox?.(()=>!0),w=b?Math.sqrt((b.max.x-b.min.x)**2+(b.max.y-b.min.y)**2+(b.max.z-b.min.z)**2):100,v=Math.max(.005*w,.2),k=e=>{const t=[],r=[];for(let e=0;e<=12;e++){const n=e/12*Math.PI;for(let e=0;e<=16;e++){const r=e/16*Math.PI*2;t.push(v*Math.sin(n)*Math.cos(r),v*Math.cos(n),v*Math.sin(n)*Math.sin(r))}}for(let e=0;e<12;e++)for(let t=0;t<16;t++){const n=17*e+t,i=n+16+1;r.push(n,i,n+1,i,i+1,n+1)}const i=new p;i.setAttribute("position",new h(new Float32Array(t),3)),i.setIndex(r),i.computeVertexNormals?.();const o=new u;o.color?.setHex?.(16746496),o.depthTest=!1,o.depthWrite=!1,o.transparent=!0,o.opacity=.95;const s=new d(i,o);return s.position.copy(e),s.renderOrder=9999,s.userData.__measureHelper=!0,n.add(s),s},N=()=>{const t=ae.current;t&&((()=>{const t=ae.current;if(!t||t.points.length<2||!t.label)return;const n=e.viewer.camera;if(!n)return;const i=t.points[0],o=t.points[1],s=new c((i.x+o.x)/2,(i.y+o.y)/2,(i.z+o.z)/2).clone();s.project?.(n);const a=r.getBoundingClientRect(),l=(s.x+1)/2*a.width,d=(1-s.y)/2*a.height;t.label.style.left=`${l}px`,t.label.style.top=`${d}px`;const u=l<0||d<0||l>a.width||d>a.height;t.label.style.opacity=s.z>1||u?"0":"1"})(),t.rafId=requestAnimationFrame(N))};ae.current.rafId=requestAnimationFrame(N);let L=0,C=0,A=0,M=!1,E=!1;const S=t=>{if(!e.viewer.camera)return;const i=r.getBoundingClientRect(),s={x:t.clientX-i.left,y:t.clientY-i.top},a=e.viewer.GetMeshIntersectionUnderMouse?.(g,s);if(!a)return;const l=ae.current,y=new c(a.point.x,a.point.y,a.point.z),f=(e=>{const t=e?.face?.normal,n=e?.object;if(!t||!n)return null;try{const e=new c(t.x,t.y,t.z);return e.transformDirection?.(n.matrixWorld),{x:e.x,y:e.y,z:e.z}}catch{return{x:t.x,y:t.y,z:t.z}}})(a);if(2===l.points.length){for(const e of l.markers)n.remove(e),e.geometry?.dispose?.(),e.material?.dispose?.();l.line&&(n.remove(l.line),l.line.geometry?.dispose?.(),l.line.material?.dispose?.()),l.label&&(l.label.style.opacity="0"),l.points=[],l.markers=[],l.line=null,l.normals=[],se(null)}if(l.points.push(y),l.normals.push(f),"perp"===re){const e=((e,t)=>{const r=e?.geometry,i=r?.attributes?.position;if(!r||!i||!t?.face?.normal)return null;const o=i.array,s=r.index?r.index.array:null,a=new c(t.point.x,t.point.y,t.point.z);e.worldToLocal?.(a);const l=t.face.normal,m=-(l.x*a.x+l.y*a.y+l.z*a.z);r.computeBoundingBox?.();const x=r.boundingBox,y=x?Math.sqrt((x.max.x-x.min.x)**2+(x.max.y-x.min.y)**2+(x.max.z-x.min.z)**2):100,f=Math.max(.001*y,.005),g=s?s.length/3:i.count/3,b=[],w=new c;for(let t=0;t<g;t++){const n=s?s[3*t]:3*t,r=s?s[3*t+1]:3*t+1,i=s?s[3*t+2]:3*t+2,a=o[3*n],c=o[3*n+1],d=o[3*n+2],u=o[3*r],p=o[3*r+1],h=o[3*r+2],x=o[3*i],y=o[3*i+1],g=o[3*i+2],v=u-a,k=p-c,N=h-d,L=x-a,C=y-c,A=g-d;let M=k*A-N*C,E=N*L-v*A,S=v*C-k*L;const z=Math.sqrt(M*M+E*E+S*S);if(0===z)continue;if(M/=z,E/=z,S/=z,M*l.x+E*l.y+S*l.z<.9995)continue;const D=(a+u+x)/3,j=(c+p+y)/3,R=(d+h+g)/3;if(!(Math.abs(l.x*D+l.y*j+l.z*R+m)>f))for(const[t,n,r]of[[a,c,d],[u,p,h],[x,y,g]])w.set?.(t,n,r),e.localToWorld?.(w),b.push(w.x,w.y,w.z)}if(0===b.length)return null;const v=new p;v.setAttribute("position",new h(new Float32Array(b),3)),v.computeVertexNormals?.();const k=new u;k.color?.setHex?.(16746496),k.transparent=!0,k.opacity=.45,k.depthWrite=!1,k.polygonOffset=!0,k.polygonOffsetFactor=-2,k.polygonOffsetUnits=-2;const N=new d(v,k);return N.renderOrder=9998,N.userData.__measureHelper=!0,n.add(N),N})(a.object,a);l.markers.push(e??k(y))}else l.markers.push(k(y));if(2===l.points.length){const e=l.points[0];let t,r=l.points[1],i="";if("perp"===re){const n=l.normals[0]??l.normals[1];if(n){const o=Math.sqrt(n.x*n.x+n.y*n.y+n.z*n.z)||1,s=n.x/o,a=n.y/o,d=n.z/o,u=(r.x-e.x)*s+(r.y-e.y)*a+(r.z-e.z)*d,p=new c(e.x+s*u,e.y+a*u,e.z+d*u);l.points[1]=p,r=p,t=Math.abs(u),i=" ⊥"}else{const n=r.x-e.x,i=r.y-e.y,o=r.z-e.z;t=Math.sqrt(n*n+i*i+o*o)}}else{const n=r.x-e.x,i=r.y-e.y,o=r.z-e.z;t=Math.sqrt(n*n+i*i+o*o)}l.line=((e,t)=>{const r=new p;r.setAttribute("position",new h(new Float32Array([e.x,e.y,e.z,t.x,t.y,t.z]),3));const i=new(m??d)(r,new(x??u)({color:16746496,depthTest:!1,depthWrite:!1,transparent:!0,opacity:.95}));return i.renderOrder=9998,i.userData.__measureHelper=!0,n.add(i),i})(e,r),se(t);const s=(()=>{const e=ae.current;if(e.label)return e.label;const t=document.createElement("div");return t.style.position="absolute",t.style.left="-9999px",t.style.top="-9999px",t.style.transform="translate(-50%, -50%)",t.style.padding="2px 6px",t.style.fontSize="11px",t.style.fontWeight="600",t.style.fontFamily="system-ui, -apple-system, sans-serif",t.style.background="rgba(255, 136, 0, 0.95)",t.style.color="#fff",t.style.borderRadius="4px",t.style.pointerEvents="none",t.style.whiteSpace="nowrap",t.style.boxShadow="0 1px 4px rgba(0,0,0,0.25)",t.style.zIndex="5",o.current.appendChild(t),e.label=t,t})();s.textContent=`${z(t)}${i}`}e.viewer.Render?.()},D=e=>{0===e.button&&(L=e.clientX,C=e.clientY,A=performance.now(),M=!1,E=!0)},j=e=>{if(!E)return;const t=e.clientX-L,n=e.clientY-C;t*t+n*n>16&&(M=!0)},R=e=>{if(0!==e.button||!E)return;const t=performance.now()-A;E=!1,!M&&t<350&&S(e)},T=e=>{"Escape"===e.key&&ne(!1)};return r.style.cursor="crosshair",r.addEventListener("pointerdown",D),r.addEventListener("pointermove",j),r.addEventListener("pointerup",R),r.addEventListener("pointercancel",R),window.addEventListener("keydown",T),()=>{r.style.cursor="",r.removeEventListener("pointerdown",D),r.removeEventListener("pointermove",j),r.removeEventListener("pointerup",R),r.removeEventListener("pointercancel",R),window.removeEventListener("keydown",T),y(),se(null)}},[te,re,l,w]),m(()=>{if(!f||l)return;const e=setTimeout(()=>b(!1),5e3);return()=>clearTimeout(e)},[f,l]);const ce=e=>{const t=/* @__PURE__ */new Set;E(e,t),C(e=>{const n=new Set(e),r=[...t].some(e=>!n.has(e));for(const e of t)r?n.add(e):n.delete(e);return n})},de=()=>{try{const e=s.current,t=e?.viewer?.GetBoundingSphere?.(()=>!0);t&&e.viewer.FitSphereToWindow(t,!0),e?.viewer?.Render?.()}catch{}};m(()=>{const e=a.current,t=s.current;if(e&&t?.viewer&&!l)try{t.viewer.SetProjectionMode(X?e.ProjectionMode.Perspective:e.ProjectionMode.Orthographic)}catch{}},[X,l]);const ue=e=>{const t=a.current,n=s.current;if(t&&n?.viewer)try{const r=n.viewer.GetBoundingSphere?.(()=>!0);if(!r)return;const i=r.center,o=3*(r.radius||1),s=i.x??0,a=i.y??0,l=i.z??0;let c,d;switch(e){case"top":c=new t.Coord3D(s,a,l+o),d=new t.Coord3D(0,1,0);break;case"front":c=new t.Coord3D(s,a-o,l),d=new t.Coord3D(0,0,1);break;case"side":c=new t.Coord3D(s+o,a,l),d=new t.Coord3D(0,0,1);break;default:{const e=o/Math.sqrt(3);c=new t.Coord3D(s+e,a-e,l+e),d=new t.Coord3D(0,0,1);break}}const u=new t.Coord3D(s,a,l),p=new t.Camera(c,u,d,45);n.viewer.SetCamera(p),n.viewer.AdjustClippingPlanesToSphere?.(r),n.viewer.Render?.()}catch{}},pe=(t.split(".").pop()||"").toUpperCase(),he=(e,t=0)=>{const n=e.children.length>0,r=!1!==k[e.id],i=!L.has(e.id);/* @__PURE__ */
83
+ /* @__PURE__ */y("input",{ref:K,value:_,onChange:e=>G(e.target.value),onKeyDown:e=>{"Enter"===e.key||" "===e.key?(e.preventDefault(),(e=>{const t=e.trim()||Z.current;if(G(""),!t)return;const n=t.toLowerCase().split(/\s+/)[0],r=()=>{Z.current=t},i=(e,t)=>{S(!0),j(e),$.current?.(),q(t),r()};if(/^-?(\d+\.?\d*|\.\d+)$/.test(n))if(!E||"horizontal"!==D&&"vertical"!==D)q("Fixed distances apply in H or V mode — type H or V first.");else{const e=parseFloat(n);e?(O(n),P(e),q(`Δ${"horizontal"===D?"X":"Y"} locked to ${z(Math.abs(e))} — the label shows the perpendicular distance`)):(O(""),P(null),q("Fixed distance cleared."))}else switch(n){case"di":case"dist":case"mea":case"measuregeom":i("point","DIST — click two points; straight-line distance (Esc to exit)");break;case"dim":case"dli":case"dimlin":case"dimlinear":i("auto","DIMLINEAR — click two points; measures ΔX or ΔY, whichever is larger (H / V to force)");break;case"h":case"hor":case"horizontal":S(!0),j("horizontal"),q("Horizontal — ΔX between the two picks"),r();break;case"v":case"ver":case"vertical":S(!0),j("vertical"),q("Vertical — ΔY between the two picks"),r();break;case"au":case"auto":S(!0),j("auto"),q("Auto (DIMLINEAR) — measures along the dominant axis of the two picks"),r();break;case"measure":S(!E),q(E?"Measure off.":"Measure on — click two points."),r();break;case"u":case"undo":U.current?.(),q("Last pick removed."),r();break;case"z":case"ze":case"zoom":case"fit":case"zoomextents":ne(),q("Zoom extents."),r();break;case"la":case"layer":case"layers":C(e=>!e),q("Layer panel toggled."),r();break;case"off":case"clear":P(null),O(""),$.current?.(),q("Measurement cleared."),r();break;case"?":case"help":q(L);break;default:{const e=N[n];q(e?`${e} is a drawing command — Preview is a read-only viewer. Measuring: DI, DIM, H, V (? for help)`:`Unknown command "${n.toUpperCase()}" — try DI, DIM, H, V, Z, LA (? for help)`)}}})(_)):"Escape"===e.key&&(_?(e.stopPropagation(),G(""),q("*Cancel*")):e.target.blur())},placeholder:"Type a command — DI, DIM, H, V, Z, LA (? for help)",spellCheck:!1,autoComplete:"off",className:"flex-1 min-w-0 bg-transparent text-[11px] font-mono text-gray-700 focus:outline-none placeholder:text-gray-300"})]})]})]})}var A="https://cdn.jsdelivr.net/npm/online-3d-viewer@0.18.0/libs/";function M(e,t=0){return{id:e.GetId?.()??0,name:e.GetName?.()||(0===t?"Root":"Node"),isMeshNode:!!e.IsMeshNode?.(),meshIndices:e.GetMeshIndices?.()??[],children:(e.GetChildNodes?.()??[]).map(e=>M(e,t+1))}}function E(e,t){t.add(e.id);for(const n of e.children)E(n,t)}function S(e,t){const n=/^#?([0-9a-f]{6})$/i.exec(t),r=n?parseInt(n[1],16):0;return new e.RGBColor(r>>16&255,r>>8&255,255&r)}function z(e){return e>=1e3?`${(e/1e3).toFixed(3)} m`:`${e.toFixed(2)} mm`}function D({url:e,filename:t,onDownload:r,onEmail:i}){const o=p(null),s=p(null),a=p(null),[l,c]=h(!0),[d,u]=h(null),[f,b]=h(!0),[w,v]=h(null),[k,N]=h({}),[L,C]=h(/* @__PURE__ */new Set),[D,j]=h("#f5f6f8"),[R,T]=h(!0),[I,F]=h("#000000"),[B,P]=h(1),[H,O]=h(!1),[W,V]=h(!1),[X,$]=h(!1),[U,_]=h(!1),[G,Y]=h("x"),[q,Z]=h(!1),[K,J]=h(.5),[Q,ee]=h(0),[te,ne]=h(!1),[re,ie]=h("point"),[oe,se]=h(null),ae=p(null),le=p(null);m(()=>{let n=!1,r=null,i=null;return c(!0),u(null),v(null),N({}),C(/* @__PURE__ */new Set),(async()=>{let l;try{l=await(import("online-3d-viewer"))}catch{return void(n||(u("online-3d-viewer is not installed in this app. Add it to enable 3D file viewing."),c(!1)))}if(a.current=l,!n&&o.current&&(await new Promise(e=>{const t=()=>{const n=o.current?.getBoundingClientRect();n&&n.width>4&&n.height>4?e():requestAnimationFrame(t)};t()}),!n&&o.current))try{const a="undefined"!=typeof window&&window.__REACT_OS_SHELL_O3DV_LIBS__||A;l.SetExternalLibLocation?.(a),function(){if(g)return;if("undefined"==typeof HTMLCanvasElement)return;g=!0;const e=HTMLCanvasElement.prototype.getContext;HTMLCanvasElement.prototype.getContext=function(t,n){return"webgl"!==t&&"webgl2"!==t&&"experimental-webgl"!==t||(n={...n||{},stencil:!0}),e.call(this,t,n)},console.info("[Preview] section: canvas getContext patched (force stencil=true)")}(),r=new l.EmbeddedViewer(o.current,{backgroundColor:new l.RGBAColor(245,246,248,255),defaultColor:new l.RGBColor(180,188,200),edgeSettings:new l.EdgeSettings(!0,new l.RGBColor(0,0,0),1),onModelLoaded:()=>{if(!n){try{const e=r.GetModel?.(),t=e?.GetRootNode?.();if(t){const e=M(t);v(e);const n={[e.id]:!0};for(const t of e.children)n[t.id]=!0;N(n)}}catch(e){console.warn("[Preview] mesh tree extraction failed",e)}c(!1)}},onModelLoadFailed:()=>{n||(u("Failed to load 3D model."),c(!1))}}),s.current=r;const d=new l.InputFile(t,l.FileSource.Url,e);r.LoadModelFromInputFiles([d]),o.current&&"undefined"!=typeof ResizeObserver&&(i=new ResizeObserver(()=>{try{const e=s.current;e?.Resize?e.Resize():e?.viewer?.Resize&&e.viewer.Resize(),e?.viewer?.Render?.()}catch{}}),i.observe(o.current))}catch(e){n||(u(e?.message||"Failed to load 3D model."),c(!1))}})(),()=>{n=!0;try{i?.disconnect()}catch{}try{r?.Destroy?.()}catch{}s.current=null}},[e,t]),m(()=>{const e=s.current;if(e?.viewer)try{const t=e=>{if(e.userData?.__sectionHelper)return;const t=e.userData?.originalMeshInstance??e.userData,n=t?.id?.nodeId??t?.nodeId;"number"==typeof n&&(e.visible=!L.has(n))};e.viewer.mainModel?.EnumerateMeshesAndLines?.(t),e.viewer.mainModel?.EnumerateEdges?.(t),e.viewer.Render?.()}catch(e){console.warn("[Preview] visibility update failed",e)}},[L,w]),m(()=>{const e=a.current,t=s.current;if(e&&t?.viewer)try{t.viewer.SetEdgeSettings(new e.EdgeSettings(R,S(e,I),B));const n=le.current;if(n){const e=[];t.viewer.mainModel?.EnumerateEdges?.(t=>{t.userData?.__sectionHelper&&e.push(t)});for(const t of e)t.parent?.remove(t),t.geometry?.dispose?.(),t.material?.dispose?.();const r=n.plane,i=e=>{e&&!n.materialState.has(e)&&(n.materialState.set(e,{clippingPlanes:e.clippingPlanes,clipShadows:e.clipShadows}),e.clippingPlanes=[r],e.clipShadows=!0,e.needsUpdate=!0)};t.viewer.mainModel?.EnumerateEdges?.(e=>{const t=e.material;if(Array.isArray(t))for(const e of t)i(e);else i(t)})}t.viewer.Render?.()}catch{}},[R,I,B]),m(()=>{const e=a.current,t=s.current;if(e&&t?.viewer)try{const n=S(e,D);t.viewer.SetBackgroundColor(new e.RGBAColor(n.r,n.g,n.b,255)),t.viewer.Render?.()}catch{}},[D]),m(()=>{const e=s.current;if(!e?.viewer||l)return;const t=e.viewer.renderer,n=e.viewer.scene;if(!t||!n)return;if(le.current){const e=le.current;for(const[t,n]of e.materialState.entries())t.clippingPlanes=n.clippingPlanes,t.clipShadows=n.clipShadows,t.needsUpdate=!0;for(const t of e.helpers)t.parent?.remove(t),t.material?.dispose?.();e.capMesh&&(n.remove(e.capMesh),e.capMesh.geometry?.dispose?.(),e.capMesh.material?.dispose?.()),le.current=null}if(!U)return t.localClippingEnabled=!1,void e.viewer.Render?.();const r=e.viewer.GetBoundingBox?.(()=>!0);if(!r)return;const i=[];if(e.viewer.mainModel?.EnumerateMeshes?.(e=>{e.userData?.__sectionHelper||i.push(e)}),!i.length)return t.localClippingEnabled=!1,void e.viewer.Render?.();const o=i[0],a=o.constructor,c=o.material?.constructor,d=o.geometry?.constructor,u=o.geometry?.attributes?.position?.constructor;a&&c&&d&&u||console.warn("[Preview] section: missing THREE constructors, falling back to no cap");const p=7681;let h=!0;try{const e=t.getContext?.(),n=e?.getContextAttributes?.();h=!1!==n?.stencil,t.autoClearStencil=!0,console.info("[Preview] section: stencil buffer =",h,"targets =",i.length)}catch{}t.localClippingEnabled=!0;const m={normal:{x:0,y:0,z:-1},constant:0,clone:function e(){const t={normal:{x:this.normal.x,y:this.normal.y,z:this.normal.z},constant:this.constant};return t.clone=e,t}},x=[],y=/* @__PURE__ */new Map,f=e=>{e&&!y.has(e)&&(y.set(e,{clippingPlanes:e.clippingPlanes,clipShadows:e.clipShadows}),e.clippingPlanes=[m],e.clipShadows=!0,e.needsUpdate=!0)};for(const e of i){const t=e.material;if(Array.isArray(t))for(const e of t)f(e);else f(t);const n=Array.isArray(t)?t[0]:t;if(a&&h&&n?.clone){const t=(t,r)=>{const i=n.clone();i.depthWrite=!1,i.depthTest=!1,i.colorWrite=!1,i.stencilWrite=!0,i.stencilFunc=519,i.stencilFail=r,i.stencilZFail=r,i.stencilZPass=r,i.side=t,i.transparent=!1,i.clippingPlanes=[m],i.clipShadows=!0,i.needsUpdate=!0;const o=new a(e.geometry,i);o.matrixAutoUpdate=!1,o.renderOrder=1,o.userData.__sectionHelper=!0,e.add(o),x.push(o)};t(1,7682),t(0,7683)}}e.viewer.mainModel?.EnumerateEdges?.(e=>{const t=e.material;if(Array.isArray(t))for(const e of t)f(e);else f(t)});let g=null;const b=i[0]?.material&&(Array.isArray(i[0].material)?i[0].material[0]:i[0].material);if(h&&a&&d&&u&&b?.clone){const e=r.max.x-r.min.x,t=r.max.y-r.min.y,i=r.max.z-r.min.z,o=2*Math.max(e,t,i,1)/2,s=new d,l=new Float32Array([-o,-o,0,o,-o,0,o,o,0,-o,o,0]),c=new Float32Array([0,0,1,0,0,1,0,0,1,0,0,1]);s.setAttribute("position",new u(l,3)),s.setAttribute("normal",new u(c,3)),s.setIndex([0,1,2,0,2,3]);const h=b.clone(),m=b.color?.getHex?.()??11844808;h.emissive?.setHex?.(m),"emissiveIntensity"in h&&(h.emissiveIntensity=.25),h.side=2,h.transparent=!1,h.opacity=1,h.stencilWrite=!0,h.stencilRef=0,h.stencilFunc=517,h.stencilFail=p,h.stencilZFail=p,h.stencilZPass=p,h.clippingPlanes=[],h.polygonOffset=!0,h.polygonOffsetFactor=-1,h.polygonOffsetUnits=-1,h.needsUpdate=!0,g=new a(s,h),g.renderOrder=2,g.userData.__sectionHelper=!0,n.add(g)}le.current={plane:m,capMesh:g,helpers:x,materialState:y,bbox:r},console.info("[Preview] section: helpers =",x.length,"cap =",!!g),e.viewer.Render?.()},[U,l,w]),m(()=>{const e=s.current,t=le.current;if(e?.viewer&&t&&U)try{const n=t.bbox,r="x"===G?0:"y"===G?1:2,i=[n.min.x,n.min.y,n.min.z][r],o=i+([n.max.x,n.max.y,n.max.z][r]-i)*K,s=Q*Math.PI/180,a=Math.cos(s),l=Math.sin(s),c=q?-1:1;let d=0,u=0,p=0;"x"===G?(d=c*a,p=c*l):"y"===G?(u=c*a,d=c*l):(p=c*a,u=c*l);const h={x:(n.min.x+n.max.x)/2,y:(n.min.y+n.max.y)/2,z:(n.min.z+n.max.z)/2},m="x"===G?o:h.x,x="y"===G?o:h.y,y="z"===G?o:h.z;if(t.plane.normal.x=d,t.plane.normal.y=u,t.plane.normal.z=p,t.plane.constant=-(d*m+u*x+p*y),t.capMesh){const e=h.x,n=h.y,r=h.z,i=d*e+u*n+p*r+t.plane.constant,o=e-d*i,s=n-u*i,a=r-p*i;t.capMesh.position.set(o,s,a),t.capMesh.lookAt?.(o+d,s+u,a+p)}e.viewer.Render?.()}catch(e){console.warn("[Preview] section update failed",e)}},[U,G,q,K,Q]),m(()=>{const e=s.current;if(!e?.viewer||l||!o.current)return;const t=e.viewer.renderer,n=e.viewer.scene,r=t?.domElement;if(!t||!n||!r)return;let i=null;if(e.viewer.mainModel?.EnumerateMeshes?.(e=>{i||e.userData?.__sectionHelper||e.userData?.__measureHelper||(i=e)}),!i)return;const c=i.position.constructor,d=i.constructor,u=(Array.isArray(i.material)?i.material[0]:i.material)?.constructor,p=i.geometry.constructor,h=i.geometry.attributes?.position?.constructor;if(!(c&&d&&u&&p&&h))return;let m=null,x=null;n.traverse(e=>{if(m&&x)return;if(!e?.isLineSegments)return;m=e.constructor;const t=Array.isArray(e.material)?e.material[0]:e.material;t?.constructor&&(x=t.constructor)});const y=()=>{const t=ae.current;if(t){null!==t.rafId&&cancelAnimationFrame(t.rafId);for(const e of t.markers)n.remove(e),e.geometry?.dispose?.(),e.material?.dispose?.();t.line&&(n.remove(t.line),t.line.geometry?.dispose?.(),t.line.material?.dispose?.()),t.label&&t.label.parentElement&&t.label.parentElement.removeChild(t.label),ae.current=null,e.viewer.Render?.()}};if(!te)return y(),void se(null);ae.current={points:[],normals:[],markers:[],line:null,label:null,rafId:null};const f=a.current,g=f?.IntersectionMode?.MeshOnly??1,b=e.viewer.GetBoundingBox?.(()=>!0),w=b?Math.sqrt((b.max.x-b.min.x)**2+(b.max.y-b.min.y)**2+(b.max.z-b.min.z)**2):100,v=Math.max(.005*w,.2),k=e=>{const t=[],r=[];for(let e=0;e<=12;e++){const n=e/12*Math.PI;for(let e=0;e<=16;e++){const r=e/16*Math.PI*2;t.push(v*Math.sin(n)*Math.cos(r),v*Math.cos(n),v*Math.sin(n)*Math.sin(r))}}for(let e=0;e<12;e++)for(let t=0;t<16;t++){const n=17*e+t,i=n+16+1;r.push(n,i,n+1,i,i+1,n+1)}const i=new p;i.setAttribute("position",new h(new Float32Array(t),3)),i.setIndex(r),i.computeVertexNormals?.();const o=new u;o.color?.setHex?.(16746496),o.depthTest=!1,o.depthWrite=!1,o.transparent=!0,o.opacity=.95;const s=new d(i,o);return s.position.copy(e),s.renderOrder=9999,s.userData.__measureHelper=!0,n.add(s),s},N=()=>{const t=ae.current;t&&((()=>{const t=ae.current;if(!t||t.points.length<2||!t.label)return;const n=e.viewer.camera;if(!n)return;const i=t.points[0],o=t.points[1],s=new c((i.x+o.x)/2,(i.y+o.y)/2,(i.z+o.z)/2).clone();s.project?.(n);const a=r.getBoundingClientRect(),l=(s.x+1)/2*a.width,d=(1-s.y)/2*a.height;t.label.style.left=`${l}px`,t.label.style.top=`${d}px`;const u=l<0||d<0||l>a.width||d>a.height;t.label.style.opacity=s.z>1||u?"0":"1"})(),t.rafId=requestAnimationFrame(N))};ae.current.rafId=requestAnimationFrame(N);let L=0,C=0,A=0,M=!1,E=!1;const S=t=>{if(!e.viewer.camera)return;const i=r.getBoundingClientRect(),s={x:t.clientX-i.left,y:t.clientY-i.top},a=e.viewer.GetMeshIntersectionUnderMouse?.(g,s);if(!a)return;const l=ae.current,y=new c(a.point.x,a.point.y,a.point.z),f=(e=>{const t=e?.face?.normal,n=e?.object;if(!t||!n)return null;try{const e=new c(t.x,t.y,t.z);return e.transformDirection?.(n.matrixWorld),{x:e.x,y:e.y,z:e.z}}catch{return{x:t.x,y:t.y,z:t.z}}})(a);if(2===l.points.length){for(const e of l.markers)n.remove(e),e.geometry?.dispose?.(),e.material?.dispose?.();l.line&&(n.remove(l.line),l.line.geometry?.dispose?.(),l.line.material?.dispose?.()),l.label&&(l.label.style.opacity="0"),l.points=[],l.markers=[],l.line=null,l.normals=[],se(null)}if(l.points.push(y),l.normals.push(f),"perp"===re){const e=((e,t)=>{const r=e?.geometry,i=r?.attributes?.position;if(!r||!i||!t?.face?.normal)return null;const o=i.array,s=r.index?r.index.array:null,a=new c(t.point.x,t.point.y,t.point.z);e.worldToLocal?.(a);const l=t.face.normal,m=-(l.x*a.x+l.y*a.y+l.z*a.z);r.computeBoundingBox?.();const x=r.boundingBox,y=x?Math.sqrt((x.max.x-x.min.x)**2+(x.max.y-x.min.y)**2+(x.max.z-x.min.z)**2):100,f=Math.max(.001*y,.005),g=s?s.length/3:i.count/3,b=[],w=new c;for(let t=0;t<g;t++){const n=s?s[3*t]:3*t,r=s?s[3*t+1]:3*t+1,i=s?s[3*t+2]:3*t+2,a=o[3*n],c=o[3*n+1],d=o[3*n+2],u=o[3*r],p=o[3*r+1],h=o[3*r+2],x=o[3*i],y=o[3*i+1],g=o[3*i+2],v=u-a,k=p-c,N=h-d,L=x-a,C=y-c,A=g-d;let M=k*A-N*C,E=N*L-v*A,S=v*C-k*L;const z=Math.sqrt(M*M+E*E+S*S);if(0===z)continue;if(M/=z,E/=z,S/=z,M*l.x+E*l.y+S*l.z<.9995)continue;const D=(a+u+x)/3,j=(c+p+y)/3,R=(d+h+g)/3;if(!(Math.abs(l.x*D+l.y*j+l.z*R+m)>f))for(const[t,n,r]of[[a,c,d],[u,p,h],[x,y,g]])w.set?.(t,n,r),e.localToWorld?.(w),b.push(w.x,w.y,w.z)}if(0===b.length)return null;const v=new p;v.setAttribute("position",new h(new Float32Array(b),3)),v.computeVertexNormals?.();const k=new u;k.color?.setHex?.(16746496),k.transparent=!0,k.opacity=.45,k.depthWrite=!1,k.polygonOffset=!0,k.polygonOffsetFactor=-2,k.polygonOffsetUnits=-2;const N=new d(v,k);return N.renderOrder=9998,N.userData.__measureHelper=!0,n.add(N),N})(a.object,a);l.markers.push(e??k(y))}else l.markers.push(k(y));if(2===l.points.length){const e=l.points[0];let t,r=l.points[1],i="";if("perp"===re){const n=l.normals[0]??l.normals[1];if(n){const o=Math.sqrt(n.x*n.x+n.y*n.y+n.z*n.z)||1,s=n.x/o,a=n.y/o,d=n.z/o,u=(r.x-e.x)*s+(r.y-e.y)*a+(r.z-e.z)*d,p=new c(e.x+s*u,e.y+a*u,e.z+d*u);l.points[1]=p,r=p,t=Math.abs(u),i=" ⊥"}else{const n=r.x-e.x,i=r.y-e.y,o=r.z-e.z;t=Math.sqrt(n*n+i*i+o*o)}}else{const n=r.x-e.x,i=r.y-e.y,o=r.z-e.z;t=Math.sqrt(n*n+i*i+o*o)}l.line=((e,t)=>{const r=new p;r.setAttribute("position",new h(new Float32Array([e.x,e.y,e.z,t.x,t.y,t.z]),3));const i=new(m??d)(r,new(x??u)({color:16746496,depthTest:!1,depthWrite:!1,transparent:!0,opacity:.95}));return i.renderOrder=9998,i.userData.__measureHelper=!0,n.add(i),i})(e,r),se(t);const s=(()=>{const e=ae.current;if(e.label)return e.label;const t=document.createElement("div");return t.style.position="absolute",t.style.left="-9999px",t.style.top="-9999px",t.style.transform="translate(-50%, -50%)",t.style.padding="2px 6px",t.style.fontSize="11px",t.style.fontWeight="600",t.style.fontFamily="system-ui, -apple-system, sans-serif",t.style.background="rgba(255, 136, 0, 0.95)",t.style.color="#fff",t.style.borderRadius="4px",t.style.pointerEvents="none",t.style.whiteSpace="nowrap",t.style.boxShadow="0 1px 4px rgba(0,0,0,0.25)",t.style.zIndex="5",o.current.appendChild(t),e.label=t,t})();s.textContent=`${z(t)}${i}`}e.viewer.Render?.()},D=e=>{0===e.button&&(L=e.clientX,C=e.clientY,A=performance.now(),M=!1,E=!0)},j=e=>{if(!E)return;const t=e.clientX-L,n=e.clientY-C;t*t+n*n>16&&(M=!0)},R=e=>{if(0!==e.button||!E)return;const t=performance.now()-A;E=!1,!M&&t<350&&S(e)},T=e=>{"Escape"===e.key&&ne(!1)};return r.style.cursor="crosshair",r.addEventListener("pointerdown",D),r.addEventListener("pointermove",j),r.addEventListener("pointerup",R),r.addEventListener("pointercancel",R),window.addEventListener("keydown",T),()=>{r.style.cursor="",r.removeEventListener("pointerdown",D),r.removeEventListener("pointermove",j),r.removeEventListener("pointerup",R),r.removeEventListener("pointercancel",R),window.removeEventListener("keydown",T),y(),se(null)}},[te,re,l,w]),m(()=>{if(!f||l)return;const e=setTimeout(()=>b(!1),5e3);return()=>clearTimeout(e)},[f,l]);const ce=e=>{const t=/* @__PURE__ */new Set;E(e,t),C(e=>{const n=new Set(e),r=[...t].some(e=>!n.has(e));for(const e of t)r?n.add(e):n.delete(e);return n})},de=()=>{try{const e=s.current,t=e?.viewer?.GetBoundingSphere?.(()=>!0);t&&e.viewer.FitSphereToWindow(t,!0),e?.viewer?.Render?.()}catch{}};m(()=>{const e=a.current,t=s.current;if(e&&t?.viewer&&!l)try{t.viewer.SetProjectionMode(X?e.ProjectionMode.Perspective:e.ProjectionMode.Orthographic)}catch{}},[X,l]);const ue=e=>{const t=a.current,n=s.current;if(t&&n?.viewer)try{const r=n.viewer.GetBoundingSphere?.(()=>!0);if(!r)return;const i=r.center,o=3*(r.radius||1),s=i.x??0,a=i.y??0,l=i.z??0;let c,d;switch(e){case"top":c=new t.Coord3D(s,a,l+o),d=new t.Coord3D(0,1,0);break;case"front":c=new t.Coord3D(s,a-o,l),d=new t.Coord3D(0,0,1);break;case"side":c=new t.Coord3D(s+o,a,l),d=new t.Coord3D(0,0,1);break;default:{const e=o/Math.sqrt(3);c=new t.Coord3D(s+e,a-e,l+e),d=new t.Coord3D(0,0,1);break}}const u=new t.Coord3D(s,a,l),p=new t.Camera(c,u,d,45);n.viewer.SetCamera(p),n.viewer.AdjustClippingPlanesToSphere?.(r),n.viewer.Render?.()}catch{}},pe=(t.split(".").pop()||"").toUpperCase(),he=(e,t=0)=>{const n=e.children.length>0,r=!1!==k[e.id],i=!L.has(e.id);/* @__PURE__ */
84
84
  return x("div",{children:[
85
85
  /* @__PURE__ */x("div",{className:"group flex items-center gap-1 px-1.5 py-1 hover:bg-gray-100 cursor-default text-[12px] text-gray-700",style:{paddingLeft:12*t+6+"px"},children:[n?/* @__PURE__ */y("button",{onClick:()=>{return t=e.id,void N(e=>({...e,[t]:!e[t]}));var t},className:"h-4 w-4 shrink-0 flex items-center justify-center text-gray-500 hover:text-gray-900",title:r?"Collapse":"Expand",children:/* @__PURE__ */y("svg",{className:"h-3 w-3",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:/* @__PURE__ */y("path",{strokeLinecap:"round",strokeLinejoin:"round",d:r?"M19.5 8.25l-7.5 7.5-7.5-7.5":"M8.25 4.5l7.5 7.5-7.5 7.5"})})}):/* @__PURE__ */y("span",{className:"h-4 w-4 shrink-0 flex items-center justify-center",children:/* @__PURE__ */y("span",{className:"h-1 w-1 rounded-full bg-gray-400"})}),
86
86
  /* @__PURE__ */y("span",{className:"flex-1 truncate "+(i?"":"opacity-40"),title:e.name,children:e.name}),
@@ -96,7 +96,7 @@ return x("div",{className:"flex flex-col h-full bg-white",children:[
96
96
  /* @__PURE__ */y("button",{onClick:()=>ue("top"),className:me,title:"Top view",children:/* @__PURE__ */y("span",{className:"text-[10px] font-semibold",children:"TOP"})}),
97
97
  /* @__PURE__ */y("button",{onClick:()=>ue("front"),className:me,title:"Front view",children:/* @__PURE__ */y("span",{className:"text-[10px] font-semibold",children:"FRT"})}),
98
98
  /* @__PURE__ */y("button",{onClick:()=>ue("side"),className:me,title:"Side view",children:/* @__PURE__ */y("span",{className:"text-[10px] font-semibold",children:"SDE"})}),
99
- /* @__PURE__ */y("button",{onClick:()=>U(e=>!e),className:X?"h-8 shrink-0 flex items-center justify-center px-2 rounded bg-gray-200 text-gray-900":"h-8 shrink-0 flex items-center justify-center px-2 rounded text-gray-600 hover:bg-gray-200 hover:text-gray-900 transition-colors",title:X?"Switch to orthographic view":"Switch to perspective view",children:/* @__PURE__ */y("span",{className:"text-[11px] font-semibold whitespace-nowrap",children:X?"Perspective":"Orthographic"})}),
99
+ /* @__PURE__ */y("button",{onClick:()=>$(e=>!e),className:X?"h-8 shrink-0 flex items-center justify-center px-2 rounded bg-gray-200 text-gray-900":"h-8 shrink-0 flex items-center justify-center px-2 rounded text-gray-600 hover:bg-gray-200 hover:text-gray-900 transition-colors",title:X?"Switch to orthographic view":"Switch to perspective view",children:/* @__PURE__ */y("span",{className:"text-[11px] font-semibold whitespace-nowrap",children:X?"Perspective":"Orthographic"})}),
100
100
  /* @__PURE__ */y("div",{className:ye}),
101
101
  /* @__PURE__ */y("button",{onClick:()=>{try{const e=s.current,n=e?.viewer?.GetCanvasSize?.()??{width:1280,height:720},r=e?.viewer?.GetImageAsDataUrl?.(n.width,n.height,!1);if(!r)return;const i=document.createElement("a");i.href=r,i.download=`${t.replace(/\.[^.]+$/,"")}-snapshot.png`,i.click()}catch{}},className:me,title:"Save snapshot as PNG",children:/* @__PURE__ */x("svg",{className:"h-4 w-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:1.5,children:[
102
102
  /* @__PURE__ */y("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6.827 6.175A2.31 2.31 0 015.186 7.23c-.38.054-.757.112-1.134.175C2.999 7.58 2.25 8.507 2.25 9.574V18a2.25 2.25 0 002.25 2.25h15A2.25 2.25 0 0021.75 18V9.574c0-1.067-.75-1.994-1.802-2.169a47.865 47.865 0 00-1.134-.175 2.31 2.31 0 01-1.64-1.055l-.822-1.316a2.192 2.192 0 00-1.736-1.039 48.774 48.774 0 00-5.232 0 2.192 2.192 0 00-1.736 1.039l-.821 1.316z"}),
@@ -149,8 +149,8 @@ return x("div",{className:"flex flex-col h-full bg-white",children:[
149
149
  /* @__PURE__ */x("div",{className:"border-t border-gray-200 -mx-3 px-3 pt-3 mt-1",children:[
150
150
  /* @__PURE__ */x("label",{className:"flex items-center justify-between gap-2",children:[
151
151
  /* @__PURE__ */y("span",{className:"font-medium",children:"Section View"}),
152
- /* @__PURE__ */y("button",{onClick:()=>_(e=>!e),role:"switch","aria-checked":$,className:"relative inline-flex h-5 w-9 shrink-0 items-center rounded-full transition-colors "+($?"bg-blue-500":"bg-gray-300"),children:/* @__PURE__ */y("span",{className:"inline-block h-4 w-4 rounded-full bg-white shadow-sm transition-transform "+($?"translate-x-[18px]":"translate-x-0.5")})})]}),
153
- /* @__PURE__ */x("div",{className:$?"mt-2 space-y-2":"mt-2 space-y-2 opacity-40 pointer-events-none",children:[
152
+ /* @__PURE__ */y("button",{onClick:()=>_(e=>!e),role:"switch","aria-checked":U,className:"relative inline-flex h-5 w-9 shrink-0 items-center rounded-full transition-colors "+(U?"bg-blue-500":"bg-gray-300"),children:/* @__PURE__ */y("span",{className:"inline-block h-4 w-4 rounded-full bg-white shadow-sm transition-transform "+(U?"translate-x-[18px]":"translate-x-0.5")})})]}),
153
+ /* @__PURE__ */x("div",{className:U?"mt-2 space-y-2":"mt-2 space-y-2 opacity-40 pointer-events-none",children:[
154
154
  /* @__PURE__ */x("div",{children:[
155
155
  /* @__PURE__ */x("div",{className:"flex items-center justify-between gap-2 mb-1",children:[
156
156
  /* @__PURE__ */y("span",{children:"Angle"}),
@@ -1,19 +1,19 @@
1
- import{EditableGrid as e}from"./chunk-TFKB2WEB.js";import"./chunk-BR22X7E5.js";import{AboutApp as t}from"./chunk-JIUJNTJA.js";import{peekSpreadsheetPreviewStage as r,claimSpreadsheetPreviewStage as n,SPREADSHEET_PREVIEW_UPDATE_EVENT as o}from"./chunk-VTVSMRFX.js";import"./chunk-VUXPSUWI.js";import{WindowTitle as a}from"./chunk-ET5HXDOR.js";import"./chunk-V453E4KU.js";import"./chunk-UB4JIOLD.js";import"./chunk-PH3PRIFP.js";import"./chunk-ZBIWNVJS.js";import"./chunk-QOXIUJTN.js";import"./chunk-57MIENLJ.js";import"./chunk-MAIHBBWT.js";import"./chunk-TR6PLN7W.js";import"./chunk-D65T4H6J.js";import{useRef as l,useState as s,useEffect as c,useCallback as i}from"react";import{jsxs as u,jsx as d,Fragment as h}from"react/jsx-runtime";var m="ABCDEFGHIJKLMNOPQRSTUVWXYZ",p=10,x=30;function g(e){return e<26?m[e]:m[Math.floor(e/26)-1]+m[e%26]}function y(e){return Array.from({length:e},(e,t)=>({key:`col_${t}`,title:g(t),width:100}))}function b(e,t){return Array.from({length:e},()=>Array(t).fill(""))}function f(e){return{id:crypto.randomUUID(),name:e,columns:y(p),data:b(x,p),cellStyles:{}}}function v(e){return e.split("\n").map(e=>{if(e.includes("\t"))return e.split("\t").map(e=>e.trim());const t=[];let r="",n=!1;for(const o of e)'"'!==o?","!==o||n?r+=o:(t.push(r.trim()),r=""):n=!n;return t.push(r.trim()),t}).filter(e=>e.some(e=>e.trim()))}function w(e,t){const r=v(e);if(0===r.length)return null;const n=Math.max(p,r.reduce((e,t)=>Math.max(e,t.length),0)),o=r.map(e=>{for(;e.length<n;)e.push("");return e});for(;o.length<x;)o.push(Array(n).fill(""));return{id:crypto.randomUUID(),name:t,columns:y(n),data:o,cellStyles:{}}}function k(){const m=l(null),g=l(void 0);void 0===g.current&&(g.current=r());const k=l(g.current?.data??null),N=(()=>{const e=g.current;if(!e)return null;const t=w(e.data.csv,"Sheet 1");if(!t)return null;return{sheet:t,title:e.data.filename.replace(/\.(csv|tsv|txt)$/i,"")}})(),[C,S]=s(N?[N.sheet]:[f("Sheet 1")]),[U,j]=s(0),E=l([]),$=l(C),M=l(!1);c(()=>{M.current?M.current=!1:$.current!==C&&(E.current.push($.current),E.current.length>50&&E.current.shift()),$.current=C},[C]);const A=i(()=>{const e=E.current.pop();e&&(M.current=!0,S(e))},[]);c(()=>{const e=e=>{if(!m.current?.contains(document.activeElement)&&!m.current?.matches(":focus-within"))return;(e.ctrlKey||e.metaKey)&&!e.shiftKey&&("z"===e.key||"Z"===e.key)&&(e.preventDefault(),A())};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[A]);const[I,L]=s(N?.title??"Untitled"),[D,B]=s(()=>g.current?.data.onEmail),R=i(e=>{const t=w(e.csv,"Sheet 1");t&&(S([t]),j(0),L(e.filename.replace(/\.(csv|tsv|txt)$/i,"")),B(()=>e.onEmail))},[]);c(()=>{const e=g.current;null!=e&&(n(e),e.data!==k.current&&R(e.data))},[]),c(()=>{const e=g.current?.token;if(null==e)return;const t=t=>{const r=t.detail;r&&r.token===e&&R(r.data)};return window.addEventListener(o,t),()=>window.removeEventListener(o,t)},[]);const[F,J]=s(!1),[T,K]=s(null),[O,P]=s(""),V=l(null),[X,H]=s("1"),[W,z]=s("10"),Z=C[U]||C[0],_=Z.data,Q=Z.columns,G=Z.cellStyles??{},[Y,q]=s(null),[ee,te]=s(null),re=i(()=>{if(ee){const e=Math.min(ee.anchor.row,ee.end.row),t=Math.max(ee.anchor.row,ee.end.row),r=Math.min(ee.anchor.col,ee.end.col),n=Math.max(ee.anchor.col,ee.end.col),o=[];for(let a=e;a<=t;a++)for(let e=r;e<=n;e++)o.push({row:a,col:e});return o}return Y?[Y]:[]},[ee,Y]),ne=i((e,t)=>{const r=re();0!==r.length&&S(n=>n.map((n,o)=>{if(o!==U)return n;const a={...n.cellStyles??{}},l=`${r[0].row}:${r[0].col}`,s=void 0!==t?t:!(a[l]??{})[e];for(const{row:t,col:n}of r){const r=`${t}:${n}`;a[r]={...a[r]??{},[e]:s}}return{...n,cellStyles:a}}))},[re,U]),oe=ee?{row:ee.anchor.row,col:ee.anchor.col}:Y,ae=oe?G[`${oe.row}:${oe.col}`]??{}:{},le=!!oe,se=i(e=>{S(t=>t.map((t,r)=>r===U?{...t,...e}:t))},[U]),ce=i(e=>{const t=e.reduce((e,t)=>Math.max(e,t.length),0);t!==Q.length?se({data:e,columns:y(t)}):se({data:e})},[se,Q.length]),ie=(e,t)=>{S(r=>r.map((r,n)=>n===e?{...r,name:t}:r)),K(null)},ue=()=>_.filter(e=>e.some(e=>e.trim())).map(e=>e.map(e=>e.includes(",")||e.includes('"')||e.includes("\n")?`"${e.replace(/"/g,'""')}"`:e).join(",")).join("\n"),de=[];_.forEach(e=>e.forEach(e=>{const t=parseFloat(e);!isNaN(t)&&e.trim()&&de.push(t)}));const he=_.reduce((e,t)=>e+t.filter(e=>e.trim()).length,0);/* @__PURE__ */
1
+ import{EditableGrid as e}from"./chunk-TFKB2WEB.js";import"./chunk-BR22X7E5.js";import{AboutApp as t}from"./chunk-IQVJ3C3D.js";import{peekSpreadsheetPreviewStage as r,claimSpreadsheetPreviewStage as n,SPREADSHEET_PREVIEW_UPDATE_EVENT as o}from"./chunk-VTVSMRFX.js";import"./chunk-BJVY3LPW.js";import{WindowTitle as a}from"./chunk-ET5HXDOR.js";import"./chunk-V453E4KU.js";import"./chunk-UB4JIOLD.js";import"./chunk-PH3PRIFP.js";import"./chunk-ZBIWNVJS.js";import"./chunk-QOXIUJTN.js";import"./chunk-57MIENLJ.js";import"./chunk-MAIHBBWT.js";import"./chunk-TR6PLN7W.js";import"./chunk-D65T4H6J.js";import{useRef as l,useState as s,useEffect as c,useCallback as i}from"react";import{jsxs as u,jsx as d,Fragment as h}from"react/jsx-runtime";var m="ABCDEFGHIJKLMNOPQRSTUVWXYZ",p=10,x=30;function g(e){return e<26?m[e]:m[Math.floor(e/26)-1]+m[e%26]}function y(e){return Array.from({length:e},(e,t)=>({key:`col_${t}`,title:g(t),width:100}))}function b(e,t){return Array.from({length:e},()=>Array(t).fill(""))}function f(e){return{id:crypto.randomUUID(),name:e,columns:y(p),data:b(x,p),cellStyles:{}}}function v(e){return e.split("\n").map(e=>{if(e.includes("\t"))return e.split("\t").map(e=>e.trim());const t=[];let r="",n=!1;for(const o of e)'"'!==o?","!==o||n?r+=o:(t.push(r.trim()),r=""):n=!n;return t.push(r.trim()),t}).filter(e=>e.some(e=>e.trim()))}function w(e,t){const r=v(e);if(0===r.length)return null;const n=Math.max(p,r.reduce((e,t)=>Math.max(e,t.length),0)),o=r.map(e=>{for(;e.length<n;)e.push("");return e});for(;o.length<x;)o.push(Array(n).fill(""));return{id:crypto.randomUUID(),name:t,columns:y(n),data:o,cellStyles:{}}}function k(){const m=l(null),g=l(void 0);void 0===g.current&&(g.current=r());const k=l(g.current?.data??null),N=(()=>{const e=g.current;if(!e)return null;const t=w(e.data.csv,"Sheet 1");if(!t)return null;return{sheet:t,title:e.data.filename.replace(/\.(csv|tsv|txt)$/i,"")}})(),[C,S]=s(N?[N.sheet]:[f("Sheet 1")]),[j,E]=s(0),$=l([]),U=l(C),M=l(!1);c(()=>{M.current?M.current=!1:U.current!==C&&($.current.push(U.current),$.current.length>50&&$.current.shift()),U.current=C},[C]);const L=i(()=>{const e=$.current.pop();e&&(M.current=!0,S(e))},[]);c(()=>{const e=e=>{if(!m.current?.contains(document.activeElement)&&!m.current?.matches(":focus-within"))return;(e.ctrlKey||e.metaKey)&&!e.shiftKey&&("z"===e.key||"Z"===e.key)&&(e.preventDefault(),L())};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[L]);const[D,A]=s(N?.title??"Untitled"),[B,I]=s(()=>g.current?.data.onEmail),R=i(e=>{const t=w(e.csv,"Sheet 1");t&&(S([t]),E(0),A(e.filename.replace(/\.(csv|tsv|txt)$/i,"")),I(()=>e.onEmail))},[]);c(()=>{const e=g.current;null!=e&&(n(e),e.data!==k.current&&R(e.data))},[]),c(()=>{const e=g.current?.token;if(null==e)return;const t=t=>{const r=t.detail;r&&r.token===e&&R(r.data)};return window.addEventListener(o,t),()=>window.removeEventListener(o,t)},[]);const[F,J]=s(!1),[K,T]=s(null),[V,O]=s(""),P=l(null),[H,W]=s("1"),[X,z]=s("10"),Q=C[j]||C[0],Z=Q.data,_=Q.columns,Y=Q.cellStyles??{},[G,q]=s(null),[ee,te]=s(null),re=i(()=>{if(ee){const e=Math.min(ee.anchor.row,ee.end.row),t=Math.max(ee.anchor.row,ee.end.row),r=Math.min(ee.anchor.col,ee.end.col),n=Math.max(ee.anchor.col,ee.end.col),o=[];for(let a=e;a<=t;a++)for(let e=r;e<=n;e++)o.push({row:a,col:e});return o}return G?[G]:[]},[ee,G]),ne=i((e,t)=>{const r=re();0!==r.length&&S(n=>n.map((n,o)=>{if(o!==j)return n;const a={...n.cellStyles??{}},l=`${r[0].row}:${r[0].col}`,s=void 0!==t?t:!(a[l]??{})[e];for(const{row:t,col:n}of r){const r=`${t}:${n}`;a[r]={...a[r]??{},[e]:s}}return{...n,cellStyles:a}}))},[re,j]),oe=ee?{row:ee.anchor.row,col:ee.anchor.col}:G,ae=oe?Y[`${oe.row}:${oe.col}`]??{}:{},le=!!oe,se=i(e=>{S(t=>t.map((t,r)=>r===j?{...t,...e}:t))},[j]),ce=i(e=>{const t=e.reduce((e,t)=>Math.max(e,t.length),0);t!==_.length?se({data:e,columns:y(t)}):se({data:e})},[se,_.length]),ie=(e,t)=>{S(r=>r.map((r,n)=>n===e?{...r,name:t}:r)),T(null)},ue=()=>Z.filter(e=>e.some(e=>e.trim())).map(e=>e.map(e=>e.includes(",")||e.includes('"')||e.includes("\n")?`"${e.replace(/"/g,'""')}"`:e).join(",")).join("\n"),de=[];Z.forEach(e=>e.forEach(e=>{const t=parseFloat(e);!isNaN(t)&&e.trim()&&de.push(t)}));const he=Z.reduce((e,t)=>e+t.filter(e=>e.trim()).length,0);/* @__PURE__ */
2
2
  return u("div",{ref:m,className:"flex flex-col h-full",children:[
3
- /* @__PURE__ */d(a,{title:`${me=I||"Untitled",me.length>24?`${me.slice(0,23)}…`:me} - Spreadsheets`}),
3
+ /* @__PURE__ */d(a,{title:`${me=D||"Untitled",me.length>24?`${me.slice(0,23)}…`:me} - Spreadsheets`}),
4
4
  /* @__PURE__ */d(t,{app:"spreadsheet"}),
5
- /* @__PURE__ */u("div",{className:"flex items-center gap-2 px-3 py-2 border-b border-gray-200 bg-gray-50 shrink-0",children:[F?/* @__PURE__ */d("input",{type:"text",value:I,onChange:e=>L(e.target.value),onBlur:()=>J(!1),onKeyDown:e=>{"Enter"===e.key&&J(!1)},autoFocus:!0,className:"text-sm font-medium text-gray-900 border border-gray-300 rounded px-2 py-0.5 w-40 focus:border-blue-500 focus:ring-blue-500"}):/* @__PURE__ */d("button",{onClick:()=>J(!0),className:"text-sm font-medium text-gray-900 hover:text-blue-600 truncate max-w-[200px]",title:"Click to rename",children:I||"Untitled"}),
5
+ /* @__PURE__ */u("div",{className:"flex items-center gap-2 px-3 py-2 border-b border-gray-200 bg-gray-50 shrink-0",children:[F?/* @__PURE__ */d("input",{type:"text",value:D,onChange:e=>A(e.target.value),onBlur:()=>J(!1),onKeyDown:e=>{"Enter"===e.key&&J(!1)},autoFocus:!0,className:"text-sm font-medium text-gray-900 border border-gray-300 rounded px-2 py-0.5 w-40 focus:border-blue-500 focus:ring-blue-500"}):/* @__PURE__ */d("button",{onClick:()=>J(!0),className:"text-sm font-medium text-gray-900 hover:text-blue-600 truncate max-w-[200px]",title:"Click to rename",children:D||"Untitled"}),
6
6
  /* @__PURE__ */d("div",{className:"h-4 w-px bg-gray-300"}),
7
- /* @__PURE__ */d("input",{ref:V,type:"file",accept:".csv,.tsv,.txt,.xlsx,.xls,.ods",onChange:async e=>{const t=e.target.files?.[0];if(!t)return;const r=t.name.replace(/\.(csv|tsv|txt|xlsx|xls|ods)$/i,"");if(/\.(xlsx|xls|ods)$/i.test(t.name)){const e=new Uint8Array(await t.arrayBuffer()),n=await(import("xlsx")),o=n.read(e,{type:"array"}),a=o.SheetNames.map(e=>{const t=n.utils.sheet_to_json(o.Sheets[e],{header:1,defval:""}),r=Math.max(p,t.reduce((e,t)=>Math.max(e,t.length),0)),a=t.map(e=>{const t=e.map(e=>String(e??""));for(;t.length<r;)t.push("");return t});for(;a.length<x;)a.push(Array(r).fill(""));return{id:crypto.randomUUID(),name:e,columns:y(r),data:a}});S(a),j(0),L(r)}else{const e=v(await t.text());if(0===e.length)return;const n=Math.max(p,e.reduce((e,t)=>Math.max(e,t.length),0)),o=e.map(e=>{for(;e.length<n;)e.push("");return e});for(;o.length<x;)o.push(Array(n).fill(""));se({columns:y(n),data:o}),L(r)}V.current&&(V.current.value="")},className:"hidden"}),
8
- /* @__PURE__ */d("button",{onClick:()=>V.current?.click(),className:"text-xs text-gray-600 hover:text-gray-900 px-2 py-1 rounded hover:bg-gray-200 transition-colors",children:"Open"}),
9
- /* @__PURE__ */d("button",{onClick:()=>{const e=new Blob([ue()],{type:"text/csv"}),t=URL.createObjectURL(e),r=document.createElement("a");r.href=t,r.download=`${I||"spreadsheet"}.csv`,r.click(),URL.revokeObjectURL(t)},className:"text-xs text-gray-600 hover:text-gray-900 px-2 py-1 rounded hover:bg-gray-200 transition-colors",children:"Save CSV"}),D&&/* @__PURE__ */d("button",{onClick:()=>D(ue(),`${I||"spreadsheet"}.csv`),className:"text-xs text-gray-600 hover:text-gray-900 px-2 py-1 rounded hover:bg-gray-200 transition-colors",children:"Email"}),
7
+ /* @__PURE__ */d("input",{ref:P,type:"file",accept:".csv,.tsv,.txt,.xlsx,.xls,.ods",onChange:async e=>{const t=e.target.files?.[0];if(!t)return;const r=t.name.replace(/\.(csv|tsv|txt|xlsx|xls|ods)$/i,"");if(/\.(xlsx|xls|ods)$/i.test(t.name)){const e=new Uint8Array(await t.arrayBuffer()),n=await(import("xlsx")),o=n.read(e,{type:"array"}),a=o.SheetNames.map(e=>{const t=n.utils.sheet_to_json(o.Sheets[e],{header:1,defval:""}),r=Math.max(p,t.reduce((e,t)=>Math.max(e,t.length),0)),a=t.map(e=>{const t=e.map(e=>String(e??""));for(;t.length<r;)t.push("");return t});for(;a.length<x;)a.push(Array(r).fill(""));return{id:crypto.randomUUID(),name:e,columns:y(r),data:a}});S(a),E(0),A(r)}else{const e=v(await t.text());if(0===e.length)return;const n=Math.max(p,e.reduce((e,t)=>Math.max(e,t.length),0)),o=e.map(e=>{for(;e.length<n;)e.push("");return e});for(;o.length<x;)o.push(Array(n).fill(""));se({columns:y(n),data:o}),A(r)}P.current&&(P.current.value="")},className:"hidden"}),
8
+ /* @__PURE__ */d("button",{onClick:()=>P.current?.click(),className:"text-xs text-gray-600 hover:text-gray-900 px-2 py-1 rounded hover:bg-gray-200 transition-colors",children:"Open"}),
9
+ /* @__PURE__ */d("button",{onClick:()=>{const e=new Blob([ue()],{type:"text/csv"}),t=URL.createObjectURL(e),r=document.createElement("a");r.href=t,r.download=`${D||"spreadsheet"}.csv`,r.click(),URL.revokeObjectURL(t)},className:"text-xs text-gray-600 hover:text-gray-900 px-2 py-1 rounded hover:bg-gray-200 transition-colors",children:"Save CSV"}),B&&/* @__PURE__ */d("button",{onClick:()=>B(ue(),`${D||"spreadsheet"}.csv`),className:"text-xs text-gray-600 hover:text-gray-900 px-2 py-1 rounded hover:bg-gray-200 transition-colors",children:"Email"}),
10
10
  /* @__PURE__ */d("div",{className:"h-4 w-px bg-gray-300"}),
11
11
  /* @__PURE__ */u("div",{className:"flex items-center gap-1",children:[
12
- /* @__PURE__ */d("input",{type:"number",min:"1",max:"50",value:X,onChange:e=>H(e.target.value),className:"w-10 text-xs text-center border border-gray-300 rounded px-1 py-0.5 focus:border-blue-500 focus:ring-blue-500"}),
13
- /* @__PURE__ */d("button",{onClick:()=>(e=>{const t=Q.length+e;se({columns:y(t),data:_.map(t=>[...t,...Array(e).fill("")])})})(parseInt(X)||1),className:"text-xs text-gray-600 hover:text-gray-900 px-2 py-1 rounded hover:bg-gray-200 transition-colors",children:"+ Col"})]}),
12
+ /* @__PURE__ */d("input",{type:"number",min:"1",max:"50",value:H,onChange:e=>W(e.target.value),className:"w-10 text-xs text-center border border-gray-300 rounded px-1 py-0.5 focus:border-blue-500 focus:ring-blue-500"}),
13
+ /* @__PURE__ */d("button",{onClick:()=>(e=>{const t=_.length+e;se({columns:y(t),data:Z.map(t=>[...t,...Array(e).fill("")])})})(parseInt(H)||1),className:"text-xs text-gray-600 hover:text-gray-900 px-2 py-1 rounded hover:bg-gray-200 transition-colors",children:"+ Col"})]}),
14
14
  /* @__PURE__ */u("div",{className:"flex items-center gap-1",children:[
15
- /* @__PURE__ */d("input",{type:"number",min:"1",max:"500",value:W,onChange:e=>z(e.target.value),className:"w-10 text-xs text-center border border-gray-300 rounded px-1 py-0.5 focus:border-blue-500 focus:ring-blue-500"}),
16
- /* @__PURE__ */d("button",{onClick:()=>{return e=parseInt(W)||10,void se({data:[..._,...Array.from({length:e},()=>Array(Q.length).fill(""))]});var e},className:"text-xs text-gray-600 hover:text-gray-900 px-2 py-1 rounded hover:bg-gray-200 transition-colors",children:"+ Row"})]}),
15
+ /* @__PURE__ */d("input",{type:"number",min:"1",max:"500",value:X,onChange:e=>z(e.target.value),className:"w-10 text-xs text-center border border-gray-300 rounded px-1 py-0.5 focus:border-blue-500 focus:ring-blue-500"}),
16
+ /* @__PURE__ */d("button",{onClick:()=>{return e=parseInt(X)||10,void se({data:[...Z,...Array.from({length:e},()=>Array(_.length).fill(""))]});var e},className:"text-xs text-gray-600 hover:text-gray-900 px-2 py-1 rounded hover:bg-gray-200 transition-colors",children:"+ Row"})]}),
17
17
  /* @__PURE__ */d("div",{className:"h-4 w-px bg-gray-300"}),
18
18
  /* @__PURE__ */d("button",{onClick:()=>{se({columns:y(p),data:b(x,p)})},className:"text-xs text-gray-600 hover:text-gray-900 px-2 py-1 rounded hover:bg-gray-200 transition-colors",children:"Clear"}),
19
19
  /* @__PURE__ */d("div",{className:"h-4 w-px bg-gray-300"}),
@@ -26,12 +26,12 @@ return u("div",{ref:m,className:"flex flex-col h-full",children:[
26
26
  /* @__PURE__ */d("option",{value:"base",children:"S"}),
27
27
  /* @__PURE__ */d("option",{value:"lg",children:"M"}),
28
28
  /* @__PURE__ */d("option",{value:"xl",children:"L"})]})]})]}),
29
- /* @__PURE__ */d("div",{className:"flex-1 min-h-0",children:/* @__PURE__ */d(e,{columns:Q,data:_,onChange:ce,onColumnsChange:e=>se({columns:e}),cellStyles:G,onFocusChange:q,onSelectionChange:te,minRows:x,maxHeight:"100%"})}),
29
+ /* @__PURE__ */d("div",{className:"flex-1 min-h-0",children:/* @__PURE__ */d(e,{columns:_,data:Z,onChange:ce,onColumnsChange:e=>se({columns:e}),cellStyles:Y,onFocusChange:q,onSelectionChange:te,minRows:x,maxHeight:"100%"})}),
30
30
  /* @__PURE__ */u("div",{className:"flex items-center border-t border-gray-200 bg-gray-50 shrink-0",children:[
31
- /* @__PURE__ */u("div",{className:"flex items-center gap-0.5 px-1 py-1 overflow-x-auto flex-1 min-w-0",children:[C.map((e,t)=>/* @__PURE__ */d("button",{onClick:()=>j(t),onDoubleClick:()=>{K(t),P(e.name)},onContextMenu:e=>{e.preventDefault(),C.length>1&&(e=>{C.length<=1||(S(t=>t.filter((t,r)=>r!==e)),U>=e&&U>0&&j(U-1))})(t)},className:"px-3 py-1 text-xs font-medium rounded-b whitespace-nowrap transition-colors "+(t===U?"bg-white text-blue-700 border border-t-0 border-gray-300 -mt-px relative z-10":"text-gray-500 hover:text-gray-700 hover:bg-gray-100"),children:T===t?/* @__PURE__ */d("input",{type:"text",value:O,onChange:e=>P(e.target.value),onBlur:()=>ie(t,O||e.name),onKeyDown:r=>{"Enter"===r.key&&ie(t,O||e.name),"Escape"===r.key&&K(null)},onClick:e=>e.stopPropagation(),autoFocus:!0,className:"w-20 text-xs border border-blue-400 rounded px-1 py-0 focus:ring-0 focus:outline-none"}):e.name},e.id)),
32
- /* @__PURE__ */d("button",{onClick:()=>{const e=`Sheet ${C.length+1}`;S(t=>[...t,f(e)]),j(C.length)},className:"px-2 py-1 text-xs text-gray-400 hover:text-gray-600 hover:bg-gray-100 rounded",title:"Add sheet",children:"+"})]}),
31
+ /* @__PURE__ */u("div",{className:"flex items-center gap-0.5 px-1 py-1 overflow-x-auto flex-1 min-w-0",children:[C.map((e,t)=>/* @__PURE__ */d("button",{onClick:()=>E(t),onDoubleClick:()=>{T(t),O(e.name)},onContextMenu:e=>{e.preventDefault(),C.length>1&&(e=>{C.length<=1||(S(t=>t.filter((t,r)=>r!==e)),j>=e&&j>0&&E(j-1))})(t)},className:"px-3 py-1 text-xs font-medium rounded-b whitespace-nowrap transition-colors "+(t===j?"bg-white text-blue-700 border border-t-0 border-gray-300 -mt-px relative z-10":"text-gray-500 hover:text-gray-700 hover:bg-gray-100"),children:K===t?/* @__PURE__ */d("input",{type:"text",value:V,onChange:e=>O(e.target.value),onBlur:()=>ie(t,V||e.name),onKeyDown:r=>{"Enter"===r.key&&ie(t,V||e.name),"Escape"===r.key&&T(null)},onClick:e=>e.stopPropagation(),autoFocus:!0,className:"w-20 text-xs border border-blue-400 rounded px-1 py-0 focus:ring-0 focus:outline-none"}):e.name},e.id)),
32
+ /* @__PURE__ */d("button",{onClick:()=>{const e=`Sheet ${C.length+1}`;S(t=>[...t,f(e)]),E(C.length)},className:"px-2 py-1 text-xs text-gray-400 hover:text-gray-600 hover:bg-gray-100 rounded",title:"Add sheet",children:"+"})]}),
33
33
  /* @__PURE__ */u("div",{className:"flex items-center gap-4 px-3 py-1 text-xs text-gray-500 shrink-0 border-l border-gray-200",children:[
34
34
  /* @__PURE__ */u("span",{children:[he," cells"]}),de.length>0&&/* @__PURE__ */u(h,{children:[
35
35
  /* @__PURE__ */u("span",{children:["Sum: ",de.reduce((e,t)=>e+t,0).toLocaleString(void 0,{maximumFractionDigits:2})]}),
36
36
  /* @__PURE__ */u("span",{children:["Avg: ",(de.reduce((e,t)=>e+t,0)/de.length).toLocaleString(void 0,{maximumFractionDigits:2})]})]}),
37
- /* @__PURE__ */u("span",{children:[_.length," × ",Q.length]})]})]})]});var me}export{k as default};
37
+ /* @__PURE__ */u("span",{children:[Z.length," × ",_.length]})]})]})]});var me}export{k as default};
@@ -1,2 +1,2 @@
1
1
  "use client";
2
- export{setBrowserStartUrl}from"../chunk-LWLCNQY7.js";export{openFilesInTrashMode,setFilesDemoTree}from"../chunk-FHTLC7HH.js";export{BUILTIN_APP_INFO}from"../chunk-JIUJNTJA.js";import"../chunk-NPJH5MD7.js";import{setPdfPreview as e}from"../chunk-ESL5TDNA.js";export{setPdfPreview}from"../chunk-ESL5TDNA.js";import{toast_default as t}from"../chunk-KKOHUQPF.js";import{setSpreadsheetPreview as o}from"../chunk-VTVSMRFX.js";export{setSpreadsheetPreview}from"../chunk-VTVSMRFX.js";import"../chunk-VUXPSUWI.js";import"../chunk-ET5HXDOR.js";import"../chunk-V453E4KU.js";import"../chunk-UB4JIOLD.js";import"../chunk-PH3PRIFP.js";import"../chunk-ZBIWNVJS.js";import"../chunk-QOXIUJTN.js";import"../chunk-57MIENLJ.js";import"../chunk-MAIHBBWT.js";import"../chunk-TR6PLN7W.js";import"../chunk-D65T4H6J.js";import{lazy as i}from"react";function n(e){const t=/\.([a-z0-9]+)(?:[?#].*)?$/i.exec((e||"").trim());return t?t[1].toLowerCase():""}var r=/* @__PURE__ */new Set(["csv","tsv"]),s=/* @__PURE__ */new Set(["xlsx","xls","xlsm","ods"]),a=/* @__PURE__ */new Set(["png","jpg","jpeg","gif","webp","bmp","svg","avif"]),l=/* @__PURE__ */new Set(["step","stp","stl","obj","gltf","glb","3mf","iges","igs"]);function c(e){const t=n(e);return"pdf"===t?"pdf":"dxf"===t?"dxf":r.has(t)?"csv":a.has(t)?"image":l.has(t)?"3d":null}function p(e){window.open(e,"_blank","noopener,noreferrer")}async function m(e,t,o){if(t.fetchBlob)return(await t.fetchBlob(o)).text();const i=await fetch(e);if(!i.ok)throw new Error(`fetch failed: ${i.status}`);return i.text()}function u(e,t){return(e instanceof Error?e.message:"")||t}async function h(i,r,a={}){const l=i?.url||"",h=i?.filename||"attachment";if(!l&&!a.fetchBlob)return void t.error("This attachment has no download link.");const d=c(h)??c(l);if("csv"===d){try{o({csv:await m(l,a,i),filename:h}),r("/spreadsheet")}catch{t.error("Could not open the spreadsheet — opening the file instead."),l&&p(l)}return}if(s.has(n(h)||n(l)))return t.error("Spreadsheet preview is unavailable for this file type. Opening the file instead."),void(l&&p(l));if(!d)return l?(t.info("Opening this file outside the app — no viewer can show it here."),void p(l)):void t.error("This attachment has no download link.");if(!a.fetchBlob)return e({url:l,filename:h,kind:d}),void r("/preview");const f=e({filename:h,kind:d,converting:!0,convertingMessage:a.loadingMessage||"LOADING FILE"});r("/preview");try{const e=await a.fetchBlob(i);f.update({url:URL.createObjectURL(e),filename:h,kind:d})}catch(e){f.update({filename:h,kind:d,converting:!1,convertingMessage:u(e,"Failed to load this file.")})}}var d=i(()=>import("../Calculator-4CLXMBA4.js")),f=i(()=>import("../Spreadsheet-IWXGGDMT.js")),w=i(()=>import("../Weather-4LJTQLDL.js")),j=i(()=>import("../CurrencyConverter-KWNYRYOZ.js")),k=i(()=>import("../PomodoroTimer-EOQDA5J7.js")),g=i(()=>import("../Notepad-CBP2PUQD.js")),v=i(()=>import("../WorldClock-AHTVTAI7.js")),T=i(()=>import("../Stock-VVM7GK4C.js")),b=i(()=>import("../Preview-PFJ6NPDF.js")),S=i(()=>import("../PdfViewer-ZCT3PYXU.js")),P=i(()=>import("../Documents-ZWKLVUOC.js")),I=i(()=>import("../Files-SLJIS2FX.js")),x=i(()=>import("../Browser-7R3TZSJ6.js")),y={"/calculator":{component:d,label:"Calculator",size:"sm",allowPinOnTop:!0,utility:!0,widget:!0,dimensions:[280,420]},"/spreadsheet":{component:f,label:"Spreadsheets",size:"2xl",appStyle:!0,multiInstance:!0},"/notepad":{component:g,label:"Notepad",size:"lg",allowPinOnTop:!0,flushBody:!0},"/weather":{component:w,label:"Weather",size:"sm",utility:!0,widget:!0,autoHeight:!0,dimensions:[320,400]},"/currency":{component:j,label:"Currency Converter",size:"sm",utility:!0,widget:!0,autoHeight:!0,dimensions:[320,480]},"/pomodoro":{component:k,label:"Pomodoro Timer",size:"sm",utility:!0,widget:!0,dimensions:[320,600]},"/world-clock":{component:v,label:"World Clock",size:"sm",utility:!0,widget:!0,autoHeight:!0,dimensions:[320,480]},"/stock":{component:T,label:"Stocks",size:"sm",utility:!0,widget:!0,autoHeight:!0,dimensions:[320,360]}},L={"/preview":{component:b,label:"Preview",size:"2xl",appStyle:!0,multiInstance:!0},"/documents":{component:P,label:"Documents",size:"xl",appStyle:!0,multiInstance:!0},"/files":{component:I,label:"Files",size:"xl",appStyle:!0}},C={"/browser":{component:x,label:"Browser",size:"2xl",appStyle:!0,multiInstance:!0}},B={...y,...L,...C};export{x as Browser,d as Calculator,j as CurrencyConverter,P as Documents,I as Files,g as Notepad,S as PdfViewer,k as PomodoroTimer,b as Preview,f as Spreadsheet,T as Stock,w as Weather,v as WorldClock,c as attachmentKind,B as bundledApps,L as documentApps,h as openAttachment,y as utilityApps,C as webApps};
2
+ export{setBrowserStartUrl}from"../chunk-LWLCNQY7.js";export{openFilesInTrashMode,setFilesDemoTree}from"../chunk-FHTLC7HH.js";export{BUILTIN_APP_INFO}from"../chunk-IQVJ3C3D.js";import"../chunk-NPJH5MD7.js";import{setPdfPreview as e}from"../chunk-ESL5TDNA.js";export{setPdfPreview}from"../chunk-ESL5TDNA.js";import{toast_default as t}from"../chunk-KKOHUQPF.js";import{setSpreadsheetPreview as o}from"../chunk-VTVSMRFX.js";export{setSpreadsheetPreview}from"../chunk-VTVSMRFX.js";import"../chunk-BJVY3LPW.js";import"../chunk-ET5HXDOR.js";import"../chunk-V453E4KU.js";import"../chunk-UB4JIOLD.js";import"../chunk-PH3PRIFP.js";import"../chunk-ZBIWNVJS.js";import"../chunk-QOXIUJTN.js";import"../chunk-57MIENLJ.js";import"../chunk-MAIHBBWT.js";import"../chunk-TR6PLN7W.js";import"../chunk-D65T4H6J.js";import{lazy as i}from"react";function n(e){const t=/\.([a-z0-9]+)(?:[?#].*)?$/i.exec((e||"").trim());return t?t[1].toLowerCase():""}var r=/* @__PURE__ */new Set(["csv","tsv"]),s=/* @__PURE__ */new Set(["xlsx","xls","xlsm","ods"]),a=/* @__PURE__ */new Set(["png","jpg","jpeg","gif","webp","bmp","svg","avif"]),l=/* @__PURE__ */new Set(["step","stp","stl","obj","gltf","glb","3mf","iges","igs"]);function c(e){const t=n(e);return"pdf"===t?"pdf":"dxf"===t?"dxf":r.has(t)?"csv":a.has(t)?"image":l.has(t)?"3d":null}function p(e){window.open(e,"_blank","noopener,noreferrer")}async function m(e,t,o){if(t.fetchBlob)return(await t.fetchBlob(o)).text();const i=await fetch(e);if(!i.ok)throw new Error(`fetch failed: ${i.status}`);return i.text()}function u(e,t){return(e instanceof Error?e.message:"")||t}async function h(i,r,a={}){const l=i?.url||"",h=i?.filename||"attachment";if(!l&&!a.fetchBlob)return void t.error("This attachment has no download link.");const d=c(h)??c(l);if("csv"===d){try{o({csv:await m(l,a,i),filename:h}),r("/spreadsheet")}catch{t.error("Could not open the spreadsheet — opening the file instead."),l&&p(l)}return}if(s.has(n(h)||n(l)))return t.error("Spreadsheet preview is unavailable for this file type. Opening the file instead."),void(l&&p(l));if(!d)return l?(t.info("Opening this file outside the app — no viewer can show it here."),void p(l)):void t.error("This attachment has no download link.");if(!a.fetchBlob)return e({url:l,filename:h,kind:d}),void r("/preview");const f=e({filename:h,kind:d,converting:!0,convertingMessage:a.loadingMessage||"LOADING FILE"});r("/preview");try{const e=await a.fetchBlob(i);f.update({url:URL.createObjectURL(e),filename:h,kind:d})}catch(e){f.update({filename:h,kind:d,converting:!1,convertingMessage:u(e,"Failed to load this file.")})}}var d=i(()=>import("../Calculator-4CLXMBA4.js")),f=i(()=>import("../Spreadsheet-MXNEADWG.js")),w=i(()=>import("../Weather-4LJTQLDL.js")),j=i(()=>import("../CurrencyConverter-KWNYRYOZ.js")),k=i(()=>import("../PomodoroTimer-EOQDA5J7.js")),g=i(()=>import("../Notepad-CYFDC4FM.js")),v=i(()=>import("../WorldClock-AHTVTAI7.js")),b=i(()=>import("../Stock-VVM7GK4C.js")),T=i(()=>import("../Preview-GZP7YTW3.js")),P=i(()=>import("../PdfViewer-ZCT3PYXU.js")),S=i(()=>import("../Documents-LDCCZRKT.js")),x=i(()=>import("../Files-QUAXBRVO.js")),y=i(()=>import("../Browser-6DPP4K2O.js")),C={"/calculator":{component:d,label:"Calculator",size:"sm",allowPinOnTop:!0,utility:!0,widget:!0,dimensions:[280,420]},"/spreadsheet":{component:f,label:"Spreadsheets",size:"2xl",appStyle:!0,multiInstance:!0},"/notepad":{component:g,label:"Notepad",size:"lg",allowPinOnTop:!0,flushBody:!0},"/weather":{component:w,label:"Weather",size:"sm",utility:!0,widget:!0,autoHeight:!0,dimensions:[320,400]},"/currency":{component:j,label:"Currency Converter",size:"sm",utility:!0,widget:!0,autoHeight:!0,dimensions:[320,480]},"/pomodoro":{component:k,label:"Pomodoro Timer",size:"sm",utility:!0,widget:!0,dimensions:[320,600]},"/world-clock":{component:v,label:"World Clock",size:"sm",utility:!0,widget:!0,autoHeight:!0,dimensions:[320,480]},"/stock":{component:b,label:"Stocks",size:"sm",utility:!0,widget:!0,autoHeight:!0,dimensions:[320,360]}},L={"/preview":{component:T,label:"Preview",size:"2xl",appStyle:!0,multiInstance:!0},"/documents":{component:S,label:"Documents",size:"xl",appStyle:!0,multiInstance:!0},"/files":{component:x,label:"Files",size:"xl",appStyle:!0}},I={"/browser":{component:y,label:"Browser",size:"2xl",appStyle:!0,multiInstance:!0}},B={...C,...L,...I};export{y as Browser,d as Calculator,j as CurrencyConverter,S as Documents,x as Files,g as Notepad,P as PdfViewer,k as PomodoroTimer,T as Preview,f as Spreadsheet,b as Stock,w as Weather,v as WorldClock,c as attachmentKind,B as bundledApps,L as documentApps,h as openAttachment,C as utilityApps,I as webApps};