efficient-shell 4.181.0 → 5.0.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,8 +1,8 @@
1
- import{getNumberingConfigs as e}from"./chunk-2DX65GOO.js";import{SidebarLayout as t}from"./chunk-PE4F4MJE.js";import{AboutApp as r}from"./chunk-MSIN5HKX.js";import{useWindowManager as n,client_default as o}from"./chunk-SBDIHKLU.js";import"./chunk-DSSLOQDW.js";import"./chunk-GMMTTWHB.js";import"./chunk-OD5KLVU5.js";import{toast_default as i}from"./chunk-3DGTIWZP.js";import{useShellPrefs as a}from"./chunk-PQLVWCUI.js";import"./chunk-5A7MWTXX.js";import"./chunk-OGXU7QFW.js";import"./chunk-ZZKIKW62.js";import"./chunk-ZDF5AR5W.js";import"./chunk-AFYQTVZO.js";import"./chunk-HZZNJHRH.js";import"./chunk-X4FJ54PP.js";import"./chunk-D65T4H6J.js";import{AddFallback as l,BookmarkFallback as s,BookmarkFallbackB as c,TrashFallback as d,PageFallback as p,CheckFallback as m}from"./chunk-XUF7VW4U.js";import"./chunk-J3LIIIHJ.js";import"./chunk-C3QOHMR6.js";import{timeAgo as u}from"./chunk-W32SKK3D.js";import{Icon as h}from"./chunk-YKZHOXI4.js";import{useRef as y,useEffect as g,useState as x,useCallback as b}from"react";import{useQuery as f}from"@tanstack/react-query";import{jsxs as k,Fragment as v,jsx as N}from"react/jsx-runtime";var w=[{key:"yellow",bg:"bg-yellow-100",border:"border-yellow-300",text:"text-yellow-900",dot:"bg-yellow-400"},{key:"blue",bg:"bg-blue-100",border:"border-blue-300",text:"text-blue-900",dot:"bg-blue-400"},{key:"green",bg:"bg-green-100",border:"border-green-300",text:"text-green-900",dot:"bg-green-400"},{key:"pink",bg:"bg-pink-100",border:"border-pink-300",text:"text-pink-900",dot:"bg-pink-400"},{key:"purple",bg:"bg-purple-100",border:"border-purple-300",text:"text-purple-900",dot:"bg-purple-400"},{key:"orange",bg:"bg-orange-100",border:"border-orange-300",text:"text-orange-900",dot:"bg-orange-400"},{key:"white",bg:"bg-white",border:"border-gray-300",text:"text-gray-900",dot:"bg-gray-300"}];var _={sales_order:{entityType:"order",endpoint:"/orders/sales-orders/"},purchase_order:{entityType:"purchase_order",endpoint:"/purchase-orders/"},invoice:{entityType:"invoice",endpoint:"/invoicing/invoices/"},vendor_invoice:{entityType:"vendor_invoice",endpoint:"/invoicing/vendor-invoices/"},shipment:{entityType:"shipment",endpoint:"/shipments/delivery-notes/"},receipt:{entityType:"payment",endpoint:"/invoicing/payments/"},vendor_payment:{entityType:"vendor_payment",endpoint:"/invoicing/vendor-payments/"},vendor_price_sheet:{entityType:"vendor_price_sheet",endpoint:"/pricing/manufacturer-price-sheets/"},client_price_sheet:{entityType:"price_sheet",endpoint:"/pricing/price-sheets/"},qc_report:{entityType:"qc_report",endpoint:"/qc-reports/"},warranty_claim:{entityType:"warranty_claim",endpoint:"/warranty-claims/claims/"},vendor_shipment:{entityType:"vendor_shipment",endpoint:"/shipments/goods-receipts/"}},T=/\[([ xX]?)\]/g;function j(){const{openEntity:j}=n(),{prefs:W,save:$}=a(),{data:C}=f({queryKey:["numbering-configs"],queryFn:()=>e(),retry:!1}),S=y({});g(()=>{if(!C)return;const e={};for(const t of C){const r=_[t.entity_type];if(!r)continue;const n=(t.prefix||"").replace("#","").toUpperCase();if(n&&(e[n]={...r,prefix:t.prefix}),t.alt_prefix){const n=t.alt_prefix.replace("#","").toUpperCase();n&&(e[n]={...r,prefix:t.alt_prefix})}}S.current=e},[C]);const X=W.notepad_notes||[],[I,O]=x(null),[D,H]=x(""),[K,P]=x(""),[U,Z]=x("yellow"),[F,M]=x(!1),[q,J]=x(!1),L=y(null),E=y(),Q=X.find(e=>e.id===I);g(()=>{if(!I&&X.length>0){const e=X[0];O(e.id),H(e.title),P(e.content),Z(e.color)}},[X.length]);const R=b(e=>{$({notepad_notes:e})},[$]),V=b(()=>{if(!I||!F)return;const e=X.map(e=>e.id===I?{...e,title:D,content:K,color:U,updated_at:/* @__PURE__ */(new Date).toISOString()}:e);R(e),M(!1)},[I,F,D,K,U,X,R]);g(()=>{if(F)return E.current&&clearTimeout(E.current),E.current=setTimeout(V,800),()=>{E.current&&clearTimeout(E.current)}},[F,V]),g(()=>()=>{F&&V()},[]);const A=e=>{F&&V(),O(e.id),H(e.title),P(e.content),Z(e.color),M(!1),J(!1)},G=e=>{const t=K.slice(0,e),r=K.slice(e).match(/^\[([ xX]?)\]/);if(!r)return;const n="x"===r[1]||"X"===r[1]?"[ ]":"[x]",o=K.slice(e+r[0].length);P(t+n+o),M(!0)},B=async(e,t)=>{const r=S.current[e];if(!r)return;const n=`${e}#${t}`;try{const{data:e}=await o.get(r.endpoint,{params:{search:n,page_size:1}}),t=(e?.results??e??[])[0];t?j(r.entityType,t.id,t,n):i.error(`${n} not found`)}catch{i.error(`Failed to look up ${n}`)}},z="Start writing...\n\nTips:\n [] Type [] for a checkbox, click to toggle\n SO#35001 Type XX#NNNNN to link entities (SO, PO, CI, VI, PL, etc.)",Y=/* @__PURE__ */k(v,{children:[
2
- /* @__PURE__ */N("div",{className:"p-2 border-b border-gray-200",children:/* @__PURE__ */k("button",{onClick:()=>{F&&V();const e={id:`note-${Date.now()}-${Math.random().toString(36).slice(2,6)}`,title:"",content:"",color:"yellow",sticky:!1,updated_at:/* @__PURE__ */(new Date).toISOString()},t=[e,...X];R(t),O(e.id),H(""),P(""),Z("yellow"),M(!1),J(!0),setTimeout(()=>L.current?.focus(),50)},className:"w-full flex items-center justify-center gap-1.5 rounded-lg bg-blue-600 text-white px-3 py-1.5 text-sm font-medium hover:bg-blue-700 transition-colors",children:[
1
+ import{getNumberingConfigs as e}from"./chunk-2DX65GOO.js";import{SidebarLayout as t}from"./chunk-PE4F4MJE.js";import{AboutApp as r}from"./chunk-TKUNR5KP.js";import{useWindowManager as n,client_default as o}from"./chunk-SBDIHKLU.js";import"./chunk-DSSLOQDW.js";import"./chunk-GMMTTWHB.js";import"./chunk-YKHMAGEM.js";import{toast_default as i}from"./chunk-3DGTIWZP.js";import{useShellPrefs as a}from"./chunk-PQLVWCUI.js";import"./chunk-5A7MWTXX.js";import"./chunk-OGXU7QFW.js";import"./chunk-ZZKIKW62.js";import"./chunk-ZDF5AR5W.js";import"./chunk-AFYQTVZO.js";import"./chunk-HZZNJHRH.js";import"./chunk-X4FJ54PP.js";import"./chunk-D65T4H6J.js";import{AddFallback as l,BookmarkFallback as s,BookmarkFallbackB as c,TrashFallback as d,PageFallback as p,CheckFallback as m}from"./chunk-XUF7VW4U.js";import"./chunk-J3LIIIHJ.js";import"./chunk-C3QOHMR6.js";import{timeAgo as u}from"./chunk-W32SKK3D.js";import{Icon as h}from"./chunk-YKZHOXI4.js";import{useRef as y,useEffect as g,useState as x,useCallback as b}from"react";import{useQuery as f}from"@tanstack/react-query";import{jsxs as k,Fragment as v,jsx as N}from"react/jsx-runtime";var w=[{key:"yellow",bg:"bg-yellow-100",border:"border-yellow-300",text:"text-yellow-900",dot:"bg-yellow-400"},{key:"blue",bg:"bg-blue-100",border:"border-blue-300",text:"text-blue-900",dot:"bg-blue-400"},{key:"green",bg:"bg-green-100",border:"border-green-300",text:"text-green-900",dot:"bg-green-400"},{key:"pink",bg:"bg-pink-100",border:"border-pink-300",text:"text-pink-900",dot:"bg-pink-400"},{key:"purple",bg:"bg-purple-100",border:"border-purple-300",text:"text-purple-900",dot:"bg-purple-400"},{key:"orange",bg:"bg-orange-100",border:"border-orange-300",text:"text-orange-900",dot:"bg-orange-400"},{key:"white",bg:"bg-white",border:"border-gray-300",text:"text-gray-900",dot:"bg-gray-300"}];var _={sales_order:{entityType:"order",endpoint:"/orders/sales-orders/"},purchase_order:{entityType:"purchase_order",endpoint:"/purchase-orders/"},invoice:{entityType:"invoice",endpoint:"/invoicing/invoices/"},vendor_invoice:{entityType:"vendor_invoice",endpoint:"/invoicing/vendor-invoices/"},shipment:{entityType:"shipment",endpoint:"/shipments/delivery-notes/"},receipt:{entityType:"payment",endpoint:"/invoicing/payments/"},vendor_payment:{entityType:"vendor_payment",endpoint:"/invoicing/vendor-payments/"},vendor_price_sheet:{entityType:"vendor_price_sheet",endpoint:"/pricing/manufacturer-price-sheets/"},client_price_sheet:{entityType:"price_sheet",endpoint:"/pricing/price-sheets/"},qc_report:{entityType:"qc_report",endpoint:"/qc-reports/"},warranty_claim:{entityType:"warranty_claim",endpoint:"/warranty-claims/claims/"},vendor_shipment:{entityType:"vendor_shipment",endpoint:"/shipments/goods-receipts/"}},T=/\[([ xX]?)\]/g;function j(){const{openEntity:j}=n(),{prefs:W,save:$}=a(),{data:C}=f({queryKey:["numbering-configs"],queryFn:()=>e(),retry:!1}),S=y({});g(()=>{if(!C)return;const e={};for(const t of C){const r=_[t.entity_type];if(!r)continue;const n=(t.prefix||"").replace("#","").toUpperCase();if(n&&(e[n]={...r,prefix:t.prefix}),t.alt_prefix){const n=t.alt_prefix.replace("#","").toUpperCase();n&&(e[n]={...r,prefix:t.alt_prefix})}}S.current=e},[C]);const X=W.notepad_notes||[],[I,O]=x(null),[D,K]=x(""),[H,P]=x(""),[U,Z]=x("yellow"),[F,M]=x(!1),[q,E]=x(!1),J=y(null),R=y(),A=X.find(e=>e.id===I);g(()=>{if(!I&&X.length>0){const e=X[0];O(e.id),K(e.title),P(e.content),Z(e.color)}},[X.length]);const G=b(e=>{$({notepad_notes:e})},[$]),L=b(()=>{if(!I||!F)return;const e=X.map(e=>e.id===I?{...e,title:D,content:H,color:U,updated_at:/* @__PURE__ */(new Date).toISOString()}:e);G(e),M(!1)},[I,F,D,H,U,X,G]);g(()=>{if(F)return R.current&&clearTimeout(R.current),R.current=setTimeout(L,800),()=>{R.current&&clearTimeout(R.current)}},[F,L]),g(()=>()=>{F&&L()},[]);const Q=e=>{F&&L(),O(e.id),K(e.title),P(e.content),Z(e.color),M(!1),E(!1)},V=e=>{const t=H.slice(0,e),r=H.slice(e).match(/^\[([ xX]?)\]/);if(!r)return;const n="x"===r[1]||"X"===r[1]?"[ ]":"[x]",o=H.slice(e+r[0].length);P(t+n+o),M(!0)},B=async(e,t)=>{const r=S.current[e];if(!r)return;const n=`${e}#${t}`;try{const{data:e}=await o.get(r.endpoint,{params:{search:n,page_size:1}}),t=(e?.results??e??[])[0];t?j(r.entityType,t.id,t,n):i.error(`${n} not found`)}catch{i.error(`Failed to look up ${n}`)}},Y="Start writing...\n\nTips:\n [] Type [] for a checkbox, click to toggle\n SO#35001 Type XX#NNNNN to link entities (SO, PO, CI, VI, PL, etc.)",z=/* @__PURE__ */k(v,{children:[
2
+ /* @__PURE__ */N("div",{className:"p-2 border-b border-gray-200",children:/* @__PURE__ */k("button",{onClick:()=>{F&&L();const e={id:`note-${Date.now()}-${Math.random().toString(36).slice(2,6)}`,title:"",content:"",color:"yellow",sticky:!1,updated_at:/* @__PURE__ */(new Date).toISOString()},t=[e,...X];G(t),O(e.id),K(""),P(""),Z("yellow"),M(!1),E(!0),setTimeout(()=>J.current?.focus(),50)},className:"w-full flex items-center justify-center gap-1.5 rounded-lg bg-blue-600 text-white px-3 py-1.5 text-sm font-medium hover:bg-blue-700 transition-colors",children:[
3
3
  /* @__PURE__ */N(h,{name:"add",fallback:l,className:"h-4 w-4",strokeWidth:2}),"New Note"]})}),
4
4
  /* @__PURE__ */N("div",{className:"flex-1 overflow-y-auto",children:0===X.length?/* @__PURE__ */N("p",{className:"text-sm text-gray-400 text-center py-8 px-4",children:"No notes yet. Create one to get started."}):X.map(e=>{const t=(r=e.color,w.find(e=>e.key===r)||w[0]);var r;/* @__PURE__ */
5
- return k("button",{onClick:()=>A(e),className:"w-full text-left px-3 py-2.5 border-b border-gray-100 transition-colors "+(I===e.id?"bg-blue-50":"hover:bg-gray-50"),children:[
5
+ return k("button",{onClick:()=>Q(e),className:"w-full text-left px-3 py-2.5 border-b border-gray-100 transition-colors "+(I===e.id?"bg-blue-50":"hover:bg-gray-50"),children:[
6
6
  /* @__PURE__ */k("div",{className:"flex items-center gap-2",children:[
7
7
  /* @__PURE__ */N("div",{className:`w-2.5 h-2.5 rounded-full shrink-0 ${t.dot}`}),
8
8
  /* @__PURE__ */N("span",{className:"text-sm font-medium text-gray-900 truncate flex-1",children:e.title||"Untitled"}),e.sticky&&/* @__PURE__ */N(h,{name:"bookmark",fallback:s,className:"h-3 w-3 text-amber-500 shrink-0"})]}),
@@ -10,13 +10,13 @@ return k("button",{onClick:()=>A(e),className:"w-full text-left px-3 py-2.5 bord
10
10
  /* @__PURE__ */N("p",{className:"text-[10px] text-gray-300 mt-0.5 ml-4.5",children:u(e.updated_at)})]},e.id)})})]});/* @__PURE__ */
11
11
  return k("div",{className:"h-full",children:[
12
12
  /* @__PURE__ */N(r,{app:"notepad"}),
13
- /* @__PURE__ */N(t,{sidebar:Y,storageKey:"notepad.sidebarWidth",defaultWidth:224,minWidth:180,maxWidth:360,children:I?/* @__PURE__ */k("div",{className:"flex-1 flex flex-col min-w-0",children:[
13
+ /* @__PURE__ */N(t,{sidebar:z,storageKey:"notepad.sidebarWidth",defaultWidth:224,minWidth:180,maxWidth:360,children:I?/* @__PURE__ */k("div",{className:"flex-1 flex flex-col min-w-0",children:[
14
14
  /* @__PURE__ */k("div",{className:"flex items-center gap-2 px-4 py-2 border-b border-gray-200",children:[
15
- /* @__PURE__ */N("input",{value:D,onChange:e=>{H(e.target.value),M(!0)},placeholder:"Note title...",className:"flex-1 text-lg font-semibold text-gray-900 outline-none bg-transparent placeholder:text-gray-300"}),
15
+ /* @__PURE__ */N("input",{value:D,onChange:e=>{K(e.target.value),M(!0)},placeholder:"Note title...",className:"flex-1 text-lg font-semibold text-gray-900 outline-none bg-transparent placeholder:text-gray-300"}),
16
16
  /* @__PURE__ */N("div",{className:"flex gap-1",children:w.map(e=>/* @__PURE__ */N("button",{onClick:()=>{Z(e.key),M(!0)},className:`w-5 h-5 rounded-full border-2 transition-all ${e.dot} ${U===e.key?"border-gray-600 scale-110":"border-transparent hover:border-gray-400"}`,title:e.key},e.key))}),
17
- /* @__PURE__ */N("button",{onClick:()=>(e=>{const t=X.map(t=>t.id===e?{...t,sticky:!t.sticky}:t);R(t);const r=t.find(t=>t.id===e);i.success(r?.sticky?"Pinned to desktop":"Removed from desktop")})(I),title:Q?.sticky?"Remove from desktop":"Pin to desktop",className:"p-1 rounded transition-colors "+(Q?.sticky?"text-amber-500 hover:text-amber-600":"text-gray-300 hover:text-amber-400"),children:/* @__PURE__ */N(h,{name:"bookmark",fallback:c,className:"h-4 w-4",fill:Q?.sticky?"currentColor":"none",strokeWidth:1.5})}),
18
- /* @__PURE__ */N("button",{onClick:()=>(e=>{const t=X.filter(t=>t.id!==e);if(R(t),I===e){const e=t[0];e?A(e):(O(null),H(""),P(""))}})(I),title:"Delete note",className:"p-1 rounded text-gray-300 hover:text-red-500 transition-colors",children:/* @__PURE__ */N(h,{name:"trash",fallback:d,className:"h-4 w-4",strokeWidth:1.5})})]}),q?/* @__PURE__ */N("textarea",{ref:L,value:K,onChange:e=>{P(e.target.value),M(!0)},onBlur:()=>{J(!1),F&&V()},placeholder:z,className:"flex-1 p-4 text-sm text-gray-700 outline-none resize-none bg-transparent leading-relaxed placeholder:text-gray-300 font-mono"}):/* @__PURE__ */N("div",{onClick:()=>{J(!0),setTimeout(()=>L.current?.focus(),50)},className:"flex-1 p-4 text-sm text-gray-700 overflow-y-auto leading-relaxed cursor-text",children:K?(e=>{if(!e)return[];const t=e.split("\n");return t.map((e,r)=>{const n=[];let o=0;const i=[],a=/([A-Z]{2,4})#(\d{4,6})/g;let l;for(;null!==(l=a.exec(e));){const e=l[1],t=l[2];if(S.current[e]){const n=l.index,o=l[0];i.push({idx:n,len:o.length,render:()=>/* @__PURE__ */N("button",{onClick:()=>B(e,t),className:"text-blue-600 hover:text-blue-800 hover:underline font-medium cursor-pointer",children:o},`ref-${r}-${n}`)})}}T.lastIndex=0;let s=0;for(let e=0;e<r;e++)s+=t[e].length+1;for(;null!==(l=T.exec(e));){const e="x"===l[1]||"X"===l[1],t=l.index,n=s+t;i.push({idx:t,len:l[0].length,render:()=>/* @__PURE__ */N("button",{onClick:()=>G(n),className:`inline-flex items-center justify-center w-4 h-4 rounded border ${e?"bg-blue-500 border-blue-500 text-white":"border-gray-400 bg-white hover:border-blue-400"} cursor-pointer align-text-bottom mr-0.5`,children:e&&/* @__PURE__ */N(h,{name:"check",fallback:m,className:"w-3 h-3",strokeWidth:3})},`cb-${r}-${t}`)})}i.sort((e,t)=>e.idx-t.idx);for(const t of i)t.idx>o&&n.push(/* @__PURE__ */N("span",{children:e.slice(o,t.idx)},`t-${r}-${o}`)),n.push(t.render()),o=t.idx+t.len;o<e.length&&n.push(/* @__PURE__ */N("span",{children:e.slice(o)},`t-${r}-${o}`)),0===n.length&&n.push(/* @__PURE__ */N("span",{children:"​"},`empty-${r}`));const c=/^\[x\]/i.test(e.trimStart());/* @__PURE__ */
19
- return N("div",{className:c?"line-through text-gray-400":"",children:n},r)})})(K):/* @__PURE__ */N("p",{className:"text-gray-300 whitespace-pre-line",children:z})}),
17
+ /* @__PURE__ */N("button",{onClick:()=>(e=>{const t=X.map(t=>t.id===e?{...t,sticky:!t.sticky}:t);G(t);const r=t.find(t=>t.id===e);i.success(r?.sticky?"Pinned to desktop":"Removed from desktop")})(I),title:A?.sticky?"Remove from desktop":"Pin to desktop",className:"p-1 rounded transition-colors "+(A?.sticky?"text-amber-500 hover:text-amber-600":"text-gray-300 hover:text-amber-400"),children:/* @__PURE__ */N(h,{name:"bookmark",fallback:c,className:"h-4 w-4",fill:A?.sticky?"currentColor":"none",strokeWidth:1.5})}),
18
+ /* @__PURE__ */N("button",{onClick:()=>(e=>{const t=X.filter(t=>t.id!==e);if(G(t),I===e){const e=t[0];e?Q(e):(O(null),K(""),P(""))}})(I),title:"Delete note",className:"p-1 rounded text-gray-300 hover:text-red-500 transition-colors",children:/* @__PURE__ */N(h,{name:"trash",fallback:d,className:"h-4 w-4",strokeWidth:1.5})})]}),q?/* @__PURE__ */N("textarea",{ref:J,value:H,onChange:e=>{P(e.target.value),M(!0)},onBlur:()=>{E(!1),F&&L()},placeholder:Y,className:"flex-1 p-4 text-sm text-gray-700 outline-none resize-none bg-transparent leading-relaxed placeholder:text-gray-300 font-mono"}):/* @__PURE__ */N("div",{onClick:()=>{E(!0),setTimeout(()=>J.current?.focus(),50)},className:"flex-1 p-4 text-sm text-gray-700 overflow-y-auto leading-relaxed cursor-text",children:H?(e=>{if(!e)return[];const t=e.split("\n");return t.map((e,r)=>{const n=[];let o=0;const i=[],a=/([A-Z]{2,4})#(\d{4,6})/g;let l;for(;null!==(l=a.exec(e));){const e=l[1],t=l[2];if(S.current[e]){const n=l.index,o=l[0];i.push({idx:n,len:o.length,render:()=>/* @__PURE__ */N("button",{onClick:()=>B(e,t),className:"text-blue-600 hover:text-blue-800 hover:underline font-medium cursor-pointer",children:o},`ref-${r}-${n}`)})}}T.lastIndex=0;let s=0;for(let e=0;e<r;e++)s+=t[e].length+1;for(;null!==(l=T.exec(e));){const e="x"===l[1]||"X"===l[1],t=l.index,n=s+t;i.push({idx:t,len:l[0].length,render:()=>/* @__PURE__ */N("button",{onClick:()=>V(n),className:`inline-flex items-center justify-center w-4 h-4 rounded border ${e?"bg-blue-500 border-blue-500 text-white":"border-gray-400 bg-white hover:border-blue-400"} cursor-pointer align-text-bottom mr-0.5`,children:e&&/* @__PURE__ */N(h,{name:"check",fallback:m,className:"w-3 h-3",strokeWidth:3})},`cb-${r}-${t}`)})}i.sort((e,t)=>e.idx-t.idx);for(const t of i)t.idx>o&&n.push(/* @__PURE__ */N("span",{children:e.slice(o,t.idx)},`t-${r}-${o}`)),n.push(t.render()),o=t.idx+t.len;o<e.length&&n.push(/* @__PURE__ */N("span",{children:e.slice(o)},`t-${r}-${o}`)),0===n.length&&n.push(/* @__PURE__ */N("span",{children:"​"},`empty-${r}`));const c=/^\[x\]/i.test(e.trimStart());/* @__PURE__ */
19
+ return N("div",{className:c?"line-through text-gray-400":"",children:n},r)})})(H):/* @__PURE__ */N("p",{className:"text-gray-300 whitespace-pre-line",children:Y})}),
20
20
  /* @__PURE__ */k("div",{className:"px-4 py-1.5 border-t border-gray-100 flex items-center gap-4 text-[10px] text-gray-400",children:[
21
21
  /* @__PURE__ */N("span",{children:"[] checkbox"}),
22
22
  /* @__PURE__ */N("span",{children:"SO#35001 entity link"}),
@@ -1,8 +1,8 @@
1
- import{PdfViewer as e,ToolbarSlotContext as t,PanelActions as n}from"./chunk-QRV7RNQX.js";import{ImageAnnotator_default as r}from"./chunk-R7EBJKN2.js";import{AboutApp as i}from"./chunk-MSIN5HKX.js";import{peekPdfPreviewStage as s,claimPdfPreviewStage as a,PDF_PREVIEW_UPDATE_EVENT as o}from"./chunk-ESL5TDNA.js";import{WindowTitle as l,getActiveModalId as c}from"./chunk-SBDIHKLU.js";import"./chunk-DSSLOQDW.js";import"./chunk-GMMTTWHB.js";import"./chunk-OD5KLVU5.js";import{toast_default as d}from"./chunk-3DGTIWZP.js";import"./chunk-PQLVWCUI.js";import"./chunk-5A7MWTXX.js";import"./chunk-OGXU7QFW.js";import"./chunk-ZZKIKW62.js";import"./chunk-ZDF5AR5W.js";import"./chunk-AFYQTVZO.js";import"./chunk-HZZNJHRH.js";import{registerModalEscapeInterceptor as u}from"./chunk-X4FJ54PP.js";import"./chunk-D65T4H6J.js";import{FolderOpenFallback as p,PageFallback as m,LayersFallback as h,HelpFallback as y,DownloadFallback as f,EmailFallback as x,ZoomInFallback as g,ExpandFallback as b,CameraFallbackB as w,MenuFallback as v,SettingsFallback as k,EditFallback as N,ChevronLeftFallback as C,DuplicateFallback as A,ChevronDownFallback as E,ChevronRightFallback as L,EyeFallback as M,EyeOffFallback as S}from"./chunk-XUF7VW4U.js";import{useShellStrings as z,splitAround as T}from"./chunk-J3LIIIHJ.js";import"./chunk-C3QOHMR6.js";import{Icon as R}from"./chunk-YKZHOXI4.js";import{useRef as j,useState as D,useEffect as F}from"react";import{jsxs as H,jsx as I,Fragment as O}from"react/jsx-runtime";var P=!1;function W(e,t){return e?.url&&e.url!==t.url&&e.url.startsWith("blob:")&&URL.revokeObjectURL(e.url),t}function X(){const n=j(void 0);void 0===n.current&&(n.current=s());const[r,u]=D(n.current?.data??null);F(()=>{const e=n.current;null!=e&&(a(e),u(t=>t===e.data?t:W(t,e.data)))},[]),F(()=>{const e=n.current?.token;if(null==e)return;const t=t=>{const n=t.detail;n&&n.token===e&&u(e=>W(e,n.data))};return window.addEventListener(o,t),()=>window.removeEventListener(o,t)},[]);const h=j(void 0);F(()=>{h.current=r?.url},[r?.url]);const y=j(null);F(()=>(null!==y.current&&(clearTimeout(y.current),y.current=null),()=>{const e=h.current;e?.startsWith("blob:")&&(y.current=setTimeout(()=>URL.revokeObjectURL(e),0))}),[]);const f=z().preview,x=r?.filename?(g=r.filename).length>24?`${g.slice(0,23)}…`:g:f.untitled;var g;const b=j(null),w=j(null),[v,k]=D(null),[N,C]=D(!1),A=j(0),E=()=>b.current?.click(),L=()=>{A.current=0,C(!1)},M=e=>{const t=e.closest("[data-modal-id]");return!t||c()===t.dataset.modalId};F(()=>{const e=()=>L(),t=()=>L(),n=e=>{"Escape"===e.key&&L()};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 S=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?d.error(f.dwgUnsupported):d.error(f.unsupportedType(t)));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__ */H("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-QRV7RNQX.js";import{ImageAnnotator_default as r}from"./chunk-R7EBJKN2.js";import{AboutApp as i}from"./chunk-TKUNR5KP.js";import{peekPdfPreviewStage as s,claimPdfPreviewStage as a,PDF_PREVIEW_UPDATE_EVENT as o}from"./chunk-ESL5TDNA.js";import{WindowTitle as l,getActiveModalId as c}from"./chunk-SBDIHKLU.js";import"./chunk-DSSLOQDW.js";import"./chunk-GMMTTWHB.js";import"./chunk-YKHMAGEM.js";import{toast_default as d}from"./chunk-3DGTIWZP.js";import"./chunk-PQLVWCUI.js";import"./chunk-5A7MWTXX.js";import"./chunk-OGXU7QFW.js";import"./chunk-ZZKIKW62.js";import"./chunk-ZDF5AR5W.js";import"./chunk-AFYQTVZO.js";import"./chunk-HZZNJHRH.js";import{registerModalEscapeInterceptor as u}from"./chunk-X4FJ54PP.js";import"./chunk-D65T4H6J.js";import{FolderOpenFallback as p,PageFallback as m,LayersFallback as h,HelpFallback as y,DownloadFallback as f,EmailFallback as x,ZoomInFallback as g,ExpandFallback as b,CameraFallbackB as w,MenuFallback as v,SettingsFallback as k,EditFallback as N,ChevronLeftFallback as C,DuplicateFallback as A,ChevronDownFallback as E,ChevronRightFallback as L,EyeFallback as M,EyeOffFallback as S}from"./chunk-XUF7VW4U.js";import{useShellStrings as z,splitAround as T}from"./chunk-J3LIIIHJ.js";import"./chunk-C3QOHMR6.js";import{Icon as R}from"./chunk-YKZHOXI4.js";import{useRef as j,useState as D,useEffect as F}from"react";import{jsxs as H,jsx as I,Fragment as P}from"react/jsx-runtime";var W=!1;function O(e,t){return e?.url&&e.url!==t.url&&e.url.startsWith("blob:")&&URL.revokeObjectURL(e.url),t}function X(){const n=j(void 0);void 0===n.current&&(n.current=s());const[r,u]=D(n.current?.data??null);F(()=>{const e=n.current;null!=e&&(a(e),u(t=>t===e.data?t:O(t,e.data)))},[]),F(()=>{const e=n.current?.token;if(null==e)return;const t=t=>{const n=t.detail;n&&n.token===e&&u(e=>O(e,n.data))};return window.addEventListener(o,t),()=>window.removeEventListener(o,t)},[]);const h=j(void 0);F(()=>{h.current=r?.url},[r?.url]);const y=j(null);F(()=>(null!==y.current&&(clearTimeout(y.current),y.current=null),()=>{const e=h.current;e?.startsWith("blob:")&&(y.current=setTimeout(()=>URL.revokeObjectURL(e),0))}),[]);const f=z().preview,x=r?.filename?(g=r.filename).length>24?`${g.slice(0,23)}…`:g:f.untitled;var g;const b=j(null),w=j(null),[v,k]=D(null),[N,C]=D(!1),A=j(0),E=()=>b.current?.click(),L=()=>{A.current=0,C(!1)},M=e=>{const t=e.closest("[data-modal-id]");return!t||c()===t.dataset.modalId};F(()=>{const e=()=>L(),t=()=>L(),n=e=>{"Escape"===e.key&&L()};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 S=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?d.error(f.dwgUnsupported):d.error(f.unsupportedType(t)));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}))},W=/* @__PURE__ */H("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__ */I("input",{ref:b,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&&S(t),b.current&&(b.current.value="")},className:"hidden"}),
3
3
  /* @__PURE__ */H("button",{onClick:E,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__ */I(R,{name:"folder-open",fallback:p,className:"h-3.5 w-3.5",strokeWidth:1.5}),f.open]}),
5
- /* @__PURE__ */I("span",{className:"text-[10px] text-gray-400 ml-1",children:f.formats}),r?.filename&&/* @__PURE__ */H(O,{children:[
5
+ /* @__PURE__ */I("span",{className:"text-[10px] text-gray-400 ml-1",children:f.formats}),r?.filename&&/* @__PURE__ */H(P,{children:[
6
6
  /* @__PURE__ */I("div",{className:"h-4 w-px bg-gray-300 mx-1"}),
7
7
  /* @__PURE__ */I("span",{className:"text-xs font-medium text-gray-700 truncate max-w-[200px]",title:r.filename,children:r.filename})]}),
8
8
  /* @__PURE__ */I("div",{ref:k,className:"ml-auto flex items-center gap-1 text-xs"})]});let X;if(r)X=r.converting||!r.url?/* @__PURE__ */I(B,{filename:r.filename,message:r.convertingMessage}):"dxf"===r.kind?/* @__PURE__ */I(G,{url:r.url,filename:r.filename,onDownload:r.onDownload,onEmail:r.onEmail},r.url):"3d"===r.kind?/* @__PURE__ */I(q,{url:r.url,filename:r.filename,onDownload:r.onDownload,onEmail:r.onEmail},r.url):"image"===r.kind?/* @__PURE__ */I(Q,{url:r.url,filename:r.filename,onDownload:r.onDownload,onEmail:r.onEmail},r.url):/* @__PURE__ */I(e,{url:r.url,filename:r.filename,onDownload:r.onDownload,onEmail:r.onEmail},r.url);else{const[e,t]=T(f.dropHere),[n,r]=T(f.formatDxf),[i,s]=T(f.format3d);X=/* @__PURE__ */H("div",{className:"flex flex-1 flex-col items-center justify-center text-gray-500 text-sm gap-3 p-8 text-center",children:[
@@ -25,7 +25,7 @@ import{PdfViewer as e,ToolbarSlotContext as t,PanelActions as n}from"./chunk-QRV
25
25
  /* @__PURE__ */I("p",{className:"mt-2 text-[11px] text-gray-400 italic",children:f.dwgNote})]})]})}/* @__PURE__ */
26
26
  return H("div",{className:"relative flex flex-col h-full",ref:w,onDragEnter:e=>{e.dataTransfer?.types?.includes?.("Files")&&M(e.currentTarget)&&(e.preventDefault(),A.current++,N||C(!0))},onDragOver:e=>{e.dataTransfer?.types?.includes?.("Files")&&M(e.currentTarget)&&e.preventDefault()},onDragLeave:()=>{A.current>0&&A.current--,0===A.current&&C(!1)},onDrop:e=>{M(e.currentTarget)?(e=>{e.preventDefault(),L();const t=e.dataTransfer.files?.[0];t&&S(t)})(e):L()},children:[
27
27
  /* @__PURE__ */I(l,{title:f.windowTitle(x)}),
28
- /* @__PURE__ */I(i,{app:"preview"}),P,
28
+ /* @__PURE__ */I(i,{app:"preview"}),W,
29
29
  /* @__PURE__ */I(t.Provider,{value:v,children:/* @__PURE__ */I("div",{className:"flex-1 min-h-0",children:X})}),N&&/* @__PURE__ */I("div",{className:"absolute inset-0 bg-blue-500/15 border-4 border-dashed border-blue-500 pointer-events-none flex items-center justify-center z-20",children:/* @__PURE__ */I("div",{className:"px-4 py-2 rounded-md bg-blue-600 text-white text-sm font-medium shadow-lg",children:f.dropToOpen})})]})}function B({filename:e,message:t}){const n=z().preview;/* @__PURE__ */
30
30
  return H("div",{className:"flex flex-col items-center justify-center h-full bg-gray-100 gap-4 px-8",children:[
31
31
  /* @__PURE__ */H("div",{className:"flex flex-col items-center gap-3",children:[
@@ -35,7 +35,7 @@ return H("div",{className:"flex flex-col items-center justify-center h-full bg-g
35
35
  /* @__PURE__ */I("div",{className:"text-base font-semibold tracking-wide text-gray-700 uppercase",children:t||n.converting}),
36
36
  /* @__PURE__ */I("div",{className:"text-xs text-gray-400 truncate max-w-md",children:e})]}),
37
37
  /* @__PURE__ */I("div",{className:"w-72 h-1.5 rounded-full bg-gray-200 overflow-hidden",children:/* @__PURE__ */I("div",{className:"h-full w-1/3 bg-blue-500 rounded-full animate-pulse",style:{animation:"preview-bar 1.4s ease-in-out infinite"}})}),
38
- /* @__PURE__ */I("style",{children:"@keyframes preview-bar { 0% { transform: translateX(-110%); } 100% { transform: translateX(310%); } }"})]})}var U=["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"],_={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"};function G({url:e,filename:t,onDownload:r,onEmail:i}){const s=j(null),a=j(null),[o,l]=D(!0),[d,p]=D(null),[m,b]=D([]),[w,v]=D(!1),[k,N]=D(!0),C=z(),A=C.drawing,E=C.preview,L=j(A);L.current=A;const[M,S]=D(!1),[P,W]=D("auto"),[X,B]=D(null),[G,V]=D(null),[Y,$]=D(null),[Z,q]=D(""),Q=j(P),J=j(Y);F(()=>{Q.current=P},[P]),F(()=>{J.current=Y},[Y]);const ee=j(null),te=j(null),ne=j(null),[re,ie]=D(""),[se,ae]=D(null),oe=j(""),le=j(null),ce=j(null),de=j(null);F(()=>{let t=!1,n=null;return l(!0),p(null),b([]),(async()=>{let r;try{r=(await(import("dxf-viewer"))).DxfViewer}catch(e){return void(t||(p(L.current.notInstalled),l(!1)))}if(!t&&s.current)try{if(await new Promise(e=>{const t=()=>{const n=s.current?.getBoundingClientRect();n&&n.width>4&&n.height>4?e():requestAnimationFrame(t)};t()}),t||!s.current)return;const i={autoResize:!0},o=r.DefaultOptions?.clearColor;"function"==typeof o?.clone&&(i.clearColor=o.clone().setHex(16777215)),n=new r(s.current,i),a.current=n;const c="undefined"!=typeof window&&window.__REACT_OS_SHELL_DXF_FONTS__||U;if(await n.Load({url:e,fonts:c,workerFactory:null}),t)return;try{const e=n.GetLayers?.()??[];Array.isArray(e)&&b(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=s.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||(p(e?.message||L.current.renderFailed),l(!1))}})(),()=>{t=!0;try{n?.Destroy?.()}catch{}a.current=null}},[e]),F(()=>{if(!k||o)return;const e=setTimeout(()=>N(!1),5e3);return()=>clearTimeout(e)},[k,o]);const ue=m.map(e=>e.visible?"1":"0").join("");F(()=>{const e=a.current;if(o||d||!e)return;const t=e.GetScene?.(),n=e.GetCamera?.(),r=e.GetCanvas?.();if(!(t&&n&&r&&s.current))return;const i=()=>{const e=de.current;e&&(e.overlay&&e.overlay.parentElement&&e.overlay.parentElement.removeChild(e.overlay),de.current=null)};if(!M)return i(),B(null),void V(null);const l=document.createElement("div");l.style.cssText="position:absolute;inset:0;pointer-events:none;z-index:5;",s.current.appendChild(l);const c=document.createElementNS("http://www.w3.org/2000/svg","svg");c.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 m=document.createElementNS("http://www.w3.org/2000/svg","path");m.setAttribute("d","M 0 0 L 10 5 L 0 10 z"),m.setAttribute("fill","#ff8800"),p.appendChild(m),u.appendChild(p),c.appendChild(u),l.appendChild(c);const h=()=>{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",c.appendChild(e),e},y=h(),f=h(),x=document.createElementNS("http://www.w3.org/2000/svg","line");x.setAttribute("stroke","#ff8800"),x.setAttribute("stroke-width","1"),x.setAttribute("opacity","0.85"),x.style.display="none",c.appendChild(x);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",c.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",c.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",c.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 C=e=>{const t=document.createElementNS(k,"g");return e(t),t.style.display="none",N.appendChild(t),t},A=C(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)}),E=C(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))}),z=C(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)}),T=C(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)}),R=C(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),de.current={picks:[],rawSecondClick:null,overlay:l,svg:c,line:b,fixedLine:w,fixedLabel:null,refLine:y,refLineV:f,extLineA:x,extLineB:g,markers:[],label:null,snap:v,segs:null,nodes:null};const j=n?.position?.constructor??t?.position?.constructor??null;let D=!1;const F=(e,t)=>{if(!j)return{x:0,y:0};const i=new j(e,t,0).project(n),s=r.clientWidth,a=r.clientHeight;return{x:(i.x+1)/2*s,y:(1-i.y)/2*a}};(()=>{try{const e=de.current;if(!e)return;const n=[],r=[];let i=!1;const s=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]]},a=e=>{const t=!!e?.isLineSegments;if(!t&&!!!e?.isPoints)return;const a=e.geometry,o=a?.attributes?.position;if(!o)return;const l=s(a);if(t){const e=a.index,t=Math.floor((e?e.count:o.count)/2);for(let r=0;r<t;r++){const t=e?e.getX(2*r):2*r,s=e?e.getX(2*r+1):2*r+1,a=o.getX(t),c=o.getY(t),d=o.getX(s),u=o.getY(s);if(Number.isFinite(a+c+d+u))for(const e of l){if(n.length>=16e5)return void(i=!0);const t=e[0]*a+e[1]*c+e[2],r=e[3]*a+e[4]*c+e[5],s=e[0]*d+e[1]*u+e[2],o=e[3]*d+e[4]*u+e[5];t===s&&r===o||n.push(t,r,s,o)}}}else for(let e=0;e<o.count;e++){const t=o.getX(e),n=o.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(a):t.traverse(a),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."),D=!0}catch{}})();const H=(e,t,n,r,i,s,a,o)=>{const l=(n-e)*(o-s)-(r-t)*(a-i);if(Math.abs(l)<1e-9)return null;const c=((i-e)*(o-s)-(s-t)*(a-i))/l,d=((i-e)*(r-t)-(s-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}},I=()=>{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=F(t,n);e.style.left=`${r.x}px`,e.style.top=`${r.y}px`},P=()=>{const e=de.current;if(!e||!e.rawSecondClick||e.picks.length<2)return;const t=e.picks[0],n=e.rawSecondClick,r=J.current,i=Q.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)}}},W=(e,t)=>{const n=Q.current;return"auto"!==n?n:e&&t?Math.abs(t.x-e.x)>=Math.abs(t.y-e.y)?"horizontal":"vertical":"horizontal"},X=()=>{const e=de.current;if(!e)return;P();const t=Q.current,n=J.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 s=(t,n,i)=>{if(!t)return;if(!i||e.picks.length<1)return void(t.style.display="none");const s=e.picks[0],a=r.clientWidth,o=r.clientHeight,l=4*Math.hypot(a,o),c=F(s.x,s.y),d=F(s.x+n.dx,s.y+n.dy),u=l/(Math.hypot(d.x-c.x,d.y-c.y)||1),p=F(s.x-n.dx*u,s.y-n.dy*u),m=F(s.x+n.dx*u,s.y+n.dy*u);t.setAttribute("x1",String(p.x)),t.setAttribute("y1",String(p.y)),t.setAttribute("x2",String(m.x)),t.setAttribute("y2",String(m.y)),t.style.display=""};let a="horizontal"===t,o="vertical"===t;if("auto"===t)if(e.picks.length>=2){const t=W(e.picks[0],e.picks[1]);a="horizontal"===t,o="vertical"===t}else a=!0,o=!0;if(s(e.refLine,{dx:1,dy:0},a),s(e.refLineV,{dx:0,dy:1},o),2===e.picks.length){const t=e.picks[0],s=e.picks[1],a=W(t,s),o=(()=>{const e=de.current,t=e.picks[0],n=e.picks[1],r=W(t,n),i=Q.current,s=J.current;return null!==s&&Number.isFinite(s)&&"horizontal"===i?{from:{x:n.x,y:t.y},to:{x:n.x,y:n.y}}:null!==s&&Number.isFinite(s)&&"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=F(o.from.x,o.from.y),c=F(o.to.x,o.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"===a?{x:s.x,y:t.y}:{x:t.x,y:s.y},o=F(t.x,t.y),l=F(i.x,i.y);e.fixedLine.setAttribute("x1",String(o.x)),e.fixedLine.setAttribute("y1",String(o.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=U();c.textContent=K(Math.abs(n));const d=(o.x+l.x)/2,u=(o.y+l.y)/2;c.style.left=`${d}px`,c.style.top=`${u}px`;const p=r.clientWidth,m=r.clientHeight;c.style.display=d<0||u<0||d>p||u>m?"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"===a&&Math.abs(s.y-t.y)>1e-9){const e=F(s.x,t.y),n=F(s.x,s.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"===a&&Math.abs(s.x-t.x)>1e-9){const e=F(t.x,s.y),n=F(s.x,s.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,s=r.clientHeight;e.label.style.display=t<0||n<0||t>i||n>s?"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")},U=()=>{const e=de.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 _=0,G=0,Y=0,$=!1,Z=!1,q=null;const re=e=>{const t=e?.detail;t&&0===t.domEvent?.button&&(_=t.canvasCoord.x,G=t.canvasCoord.y,Y=performance.now(),Z=!1,$=!0)},ie=e=>{const t=r.getBoundingClientRect(),n=e.clientX-t.left,i=e.clientY-t.top;$&&(n-_)**2+(i-G)**2>16&&(Z=!0);const s=de.current;var a;if(s&&s.snap)if($&&Z)s.snap.style.display="none";else if(q=((e,t)=>{const n=de.current;if(!n||!D||!n.segs)return null;const r=F(0,0),i=F(1,0),s=F(0,1),a=i.x-r.x,o=i.y-r.y,l=s.x-r.x,c=s.y-r.y,d=a*c-l*o;if(!d)return null;const u=((e-r.x)*c-(t-r.y)*l)/d,p=((t-r.y)*a-(e-r.x)*o)/d,m=18/(Math.hypot(a,o)||1),h=18/(Math.hypot(l,c)||1),y=u-m,f=u+m,x=p-h,g=p+h,b=324;let w=null,v=b,k=null,N=b,C=null,A=b,E=null,L=b;const M=[],S=n.segs;for(let n=0;n<S.length;n+=4){const i=S[n],s=S[n+1],d=S[n+2],u=S[n+3];if(i<y&&d<y||i>f&&d>f||s<x&&u<x||s>g&&u>g)continue;const p=r.x+a*i+l*s,m=r.y+o*i+c*s,h=r.x+a*d+l*u,E=r.y+o*d+c*u;let L=!1,z=e-p,T=t-m,R=z*z+T*T;R<b&&(L=!0,R<v&&(v=R,w={sx:i,sy:s,type:"endpoint"})),z=e-h,T=t-E,R=z*z+T*T,R<b&&(L=!0,R<v&&(v=R,w={sx:d,sy:u,type:"endpoint"})),z=e-(p+h)/2,T=t-(m+E)/2,R=z*z+T*T,R<b&&(L=!0,R<N&&(N=R,k={sx:(i+d)/2,sy:(s+u)/2,type:"midpoint"}));const j=h-p,D=E-m,F=j*j+D*D;if(F>0){const n=((e-p)*j+(t-m)*D)/F;n>0&&n<1&&(z=e-(p+n*j),T=t-(m+n*D),R=z*z+T*T,R<b&&(L=!0,R<A&&(A=R,C={sx:i+n*(d-i),sy:s+n*(u-s),type:"line"})))}L&&M.push({ax:i,ay:s,bx:d,by:u,apx:p,apy:m,bpx:h,bpy:E})}const z=n.nodes;if(z)for(let n=0;n<z.length;n+=2){const i=z[n],s=z[n+1];if(i<y||i>f||s<x||s>g)continue;const d=e-(r.x+a*i+l*s),u=t-(r.y+o*i+c*s),p=d*d+u*u;p<v&&(v=p,w={sx:i,sy:s,type:"node"})}for(let n=0;n<M.length;n++){const r=M[n];for(let i=n+1;i<M.length;i++){const n=M[i],s=H(r.apx,r.apy,r.bpx,r.bpy,n.apx,n.apy,n.bpx,n.bpy);if(!s)continue;const a=e-s.px,o=t-s.py,l=a*a+o*o;l>=b||l>=L||(L=l,E={sx:r.ax+s.t*(r.bx-r.ax),sy:r.ay+s.t*(r.by-r.ay),type:"intersection"})}}return(E&&w?L<v-1?E:w:E??w)??k??C})(n,i),q){const e=F(q.sx,q.sy);s.snap.style.left=`${e.x}px`,s.snap.style.top=`${e.y}px`,s.snap.style.display="",a=q.type,A.style.display="endpoint"===a?"":"none",E.style.display="intersection"===a?"":"none",z.style.display="line"===a?"":"none",T.style.display="midpoint"===a?"":"none",R.style.display="node"===a?"":"none"}else s.snap.style.display="none"},se=e=>{if(!$)return;$=!1;const t=performance.now()-Y;if(Z||t>350)return;const n=e?.detail?.position;if(!n)return;const r=q?{x:q.sx,y:q.sy}:{x:n.x,y:n.y};ue(r)},oe=()=>{const e=de.current;if(!e||2!==e.picks.length)return;P();const t=e.picks[0],n=e.picks[1],r=Q.current,i=W(t,n),s=J.current,a=null!==s&&Number.isFinite(s)&&("horizontal"===r||"vertical"===r);let o,c,d="",u=i;const p=Math.abs(n.x-t.x),m=Math.abs(n.y-t.y);if(a&&"horizontal"===r?(o=m,d=" ↕",u="vertical",c=L.current.echoLocked("ΔY",K(m),"ΔX",K(Math.abs(s)))):a&&"vertical"===r?(o=p,d=" ↔",u="horizontal",c=L.current.echoLocked("ΔX",K(p),"ΔY",K(Math.abs(s)))):"horizontal"===i?(o=p,d=" ↔",c=L.current.echoLinear(K(p),"ΔX")):"vertical"===i?(o=m,d=" ↕",c=L.current.echoLinear(K(m),"ΔY")):(o=Math.hypot(n.x-t.x,n.y-t.y),c=L.current.echoDistance(K(o),K(p),K(m))),!Number.isFinite(o))return B(null),V(null),void(e.label&&(e.label.style.opacity="0"));B(o),V(u),ae(c);const h=(()=>{const e=de.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})();h.style.opacity="1",h.textContent=`${K(o)}${d}`};ee.current=()=>{oe(),X()};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"),B(null),V(null)},ce=()=>{const e=de.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)}};te.current=ce,ne.current=()=>{const e=de.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),X()};const ue=e=>{const t=de.current;t&&(2===t.picks.length&&ce(),0===t.picks.length?(t.picks.push({x:e.x,y:e.y}),t.markers.push(I())):(t.rawSecondClick={x:e.x,y:e.y},t.picks.push({x:e.x,y:e.y}),t.markers.push(I()),oe()),X())},pe=e=>{"Escape"===e.key&&S(!1)};r.style.cursor="crosshair";try{e.Subscribe?.("pointerdown",re)}catch{}try{e.Subscribe?.("pointerup",se)}catch{}try{e.Subscribe?.("viewChanged",X)}catch{}return r.addEventListener("pointermove",ie),window.addEventListener("keydown",pe),()=>{r.style.cursor="";try{e.Unsubscribe?.("pointerdown",re)}catch{}try{e.Unsubscribe?.("pointerup",se)}catch{}try{e.Unsubscribe?.("viewChanged",X)}catch{}r.removeEventListener("pointermove",ie),window.removeEventListener("keydown",pe),ee.current=null,te.current=null,ne.current=null,i(),B(null),V(null)}},[M,o,d,ue]),F(()=>{ee.current?.()},[P,Y]);const pe=e=>{b(t=>t.map(t=>{if(t.visible===e)return t;try{a.current?.ShowLayer?.(t.name,e)}catch{}return{...t,visible:e}}))},me=()=>{try{const e=a.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{}};F(()=>{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=ce.current;if(!n)return;const r=n.closest("[data-modal-id]");r&&c()!==r.dataset.modalId||le.current?.focus()};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[]);const he=j(re),ye=j(M);F(()=>{he.current=re},[re]),F(()=>{ye.current=M},[M]),F(()=>u(()=>{const e=ce.current;if(!e)return!1;const t=e.closest("[data-modal-id]");return!(!t||c()!==t.dataset.modalId)&&(he.current?(ie(""),ae(L.current.cancelled),!0):!!ye.current&&(S(!1),ae(L.current.measureOff),!0))}),[]);const fe="px-2 py-1 rounded hover:bg-gray-200 transition-colors text-gray-600 flex items-center gap-1",[xe,ge]=T(A.typeToMeasure);/* @__PURE__ */
38
+ /* @__PURE__ */I("style",{children:"@keyframes preview-bar { 0% { transform: translateX(-110%); } 100% { transform: translateX(310%); } }"})]})}var U=["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"],_={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"};function G({url:e,filename:t,onDownload:r,onEmail:i}){const s=j(null),a=j(null),[o,l]=D(!0),[d,p]=D(null),[m,b]=D([]),[w,v]=D(!1),[k,N]=D(!0),C=z(),A=C.drawing,E=C.preview,L=j(A);L.current=A;const[M,S]=D(!1),[W,O]=D("auto"),[X,B]=D(null),[G,V]=D(null),[Y,$]=D(null),[Z,q]=D(""),Q=j(W),J=j(Y);F(()=>{Q.current=W},[W]),F(()=>{J.current=Y},[Y]);const ee=j(null),te=j(null),ne=j(null),[re,ie]=D(""),[se,ae]=D(null),oe=j(""),le=j(null),ce=j(null),de=j(null);F(()=>{let t=!1,n=null;return l(!0),p(null),b([]),(async()=>{let r;try{r=(await(import("dxf-viewer"))).DxfViewer}catch(e){return void(t||(p(L.current.notInstalled),l(!1)))}if(!t&&s.current)try{if(await new Promise(e=>{const t=()=>{const n=s.current?.getBoundingClientRect();n&&n.width>4&&n.height>4?e():requestAnimationFrame(t)};t()}),t||!s.current)return;const i={autoResize:!0},o=r.DefaultOptions?.clearColor;"function"==typeof o?.clone&&(i.clearColor=o.clone().setHex(16777215)),n=new r(s.current,i),a.current=n;const c="undefined"!=typeof window&&window.__REACT_OS_SHELL_DXF_FONTS__||U;if(await n.Load({url:e,fonts:c,workerFactory:null}),t)return;try{const e=n.GetLayers?.()??[];Array.isArray(e)&&b(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=s.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||(p(e?.message||L.current.renderFailed),l(!1))}})(),()=>{t=!0;try{n?.Destroy?.()}catch{}a.current=null}},[e]),F(()=>{if(!k||o)return;const e=setTimeout(()=>N(!1),5e3);return()=>clearTimeout(e)},[k,o]);const ue=m.map(e=>e.visible?"1":"0").join("");F(()=>{const e=a.current;if(o||d||!e)return;const t=e.GetScene?.(),n=e.GetCamera?.(),r=e.GetCanvas?.();if(!(t&&n&&r&&s.current))return;const i=()=>{const e=de.current;e&&(e.overlay&&e.overlay.parentElement&&e.overlay.parentElement.removeChild(e.overlay),de.current=null)};if(!M)return i(),B(null),void V(null);const l=document.createElement("div");l.style.cssText="position:absolute;inset:0;pointer-events:none;z-index:5;",s.current.appendChild(l);const c=document.createElementNS("http://www.w3.org/2000/svg","svg");c.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 m=document.createElementNS("http://www.w3.org/2000/svg","path");m.setAttribute("d","M 0 0 L 10 5 L 0 10 z"),m.setAttribute("fill","#ff8800"),p.appendChild(m),u.appendChild(p),c.appendChild(u),l.appendChild(c);const h=()=>{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",c.appendChild(e),e},y=h(),f=h(),x=document.createElementNS("http://www.w3.org/2000/svg","line");x.setAttribute("stroke","#ff8800"),x.setAttribute("stroke-width","1"),x.setAttribute("opacity","0.85"),x.style.display="none",c.appendChild(x);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",c.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",c.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",c.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 C=e=>{const t=document.createElementNS(k,"g");return e(t),t.style.display="none",N.appendChild(t),t},A=C(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)}),E=C(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))}),z=C(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)}),T=C(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)}),R=C(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),de.current={picks:[],rawSecondClick:null,overlay:l,svg:c,line:b,fixedLine:w,fixedLabel:null,refLine:y,refLineV:f,extLineA:x,extLineB:g,markers:[],label:null,snap:v,segs:null,nodes:null};const j=n?.position?.constructor??t?.position?.constructor??null;let D=!1;const F=(e,t)=>{if(!j)return{x:0,y:0};const i=new j(e,t,0).project(n),s=r.clientWidth,a=r.clientHeight;return{x:(i.x+1)/2*s,y:(1-i.y)/2*a}};(()=>{try{const e=de.current;if(!e)return;const n=[],r=[];let i=!1;const s=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]]},a=e=>{const t=!!e?.isLineSegments;if(!t&&!!!e?.isPoints)return;const a=e.geometry,o=a?.attributes?.position;if(!o)return;const l=s(a);if(t){const e=a.index,t=Math.floor((e?e.count:o.count)/2);for(let r=0;r<t;r++){const t=e?e.getX(2*r):2*r,s=e?e.getX(2*r+1):2*r+1,a=o.getX(t),c=o.getY(t),d=o.getX(s),u=o.getY(s);if(Number.isFinite(a+c+d+u))for(const e of l){if(n.length>=16e5)return void(i=!0);const t=e[0]*a+e[1]*c+e[2],r=e[3]*a+e[4]*c+e[5],s=e[0]*d+e[1]*u+e[2],o=e[3]*d+e[4]*u+e[5];t===s&&r===o||n.push(t,r,s,o)}}}else for(let e=0;e<o.count;e++){const t=o.getX(e),n=o.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(a):t.traverse(a),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."),D=!0}catch{}})();const H=(e,t,n,r,i,s,a,o)=>{const l=(n-e)*(o-s)-(r-t)*(a-i);if(Math.abs(l)<1e-9)return null;const c=((i-e)*(o-s)-(s-t)*(a-i))/l,d=((i-e)*(r-t)-(s-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}},I=()=>{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},P=(e,t,n)=>{const r=F(t,n);e.style.left=`${r.x}px`,e.style.top=`${r.y}px`},W=()=>{const e=de.current;if(!e||!e.rawSecondClick||e.picks.length<2)return;const t=e.picks[0],n=e.rawSecondClick,r=J.current,i=Q.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)}}},O=(e,t)=>{const n=Q.current;return"auto"!==n?n:e&&t?Math.abs(t.x-e.x)>=Math.abs(t.y-e.y)?"horizontal":"vertical":"horizontal"},X=()=>{const e=de.current;if(!e)return;W();const t=Q.current,n=J.current,i=null!==n&&Number.isFinite(n)&&("horizontal"===t||"vertical"===t);e.markers[0]&&P(e.markers[0],e.picks[0].x,e.picks[0].y),e.markers[1]&&P(e.markers[1],e.picks[1].x,e.picks[1].y);const s=(t,n,i)=>{if(!t)return;if(!i||e.picks.length<1)return void(t.style.display="none");const s=e.picks[0],a=r.clientWidth,o=r.clientHeight,l=4*Math.hypot(a,o),c=F(s.x,s.y),d=F(s.x+n.dx,s.y+n.dy),u=l/(Math.hypot(d.x-c.x,d.y-c.y)||1),p=F(s.x-n.dx*u,s.y-n.dy*u),m=F(s.x+n.dx*u,s.y+n.dy*u);t.setAttribute("x1",String(p.x)),t.setAttribute("y1",String(p.y)),t.setAttribute("x2",String(m.x)),t.setAttribute("y2",String(m.y)),t.style.display=""};let a="horizontal"===t,o="vertical"===t;if("auto"===t)if(e.picks.length>=2){const t=O(e.picks[0],e.picks[1]);a="horizontal"===t,o="vertical"===t}else a=!0,o=!0;if(s(e.refLine,{dx:1,dy:0},a),s(e.refLineV,{dx:0,dy:1},o),2===e.picks.length){const t=e.picks[0],s=e.picks[1],a=O(t,s),o=(()=>{const e=de.current,t=e.picks[0],n=e.picks[1],r=O(t,n),i=Q.current,s=J.current;return null!==s&&Number.isFinite(s)&&"horizontal"===i?{from:{x:n.x,y:t.y},to:{x:n.x,y:n.y}}:null!==s&&Number.isFinite(s)&&"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=F(o.from.x,o.from.y),c=F(o.to.x,o.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"===a?{x:s.x,y:t.y}:{x:t.x,y:s.y},o=F(t.x,t.y),l=F(i.x,i.y);e.fixedLine.setAttribute("x1",String(o.x)),e.fixedLine.setAttribute("y1",String(o.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=U();c.textContent=K(Math.abs(n));const d=(o.x+l.x)/2,u=(o.y+l.y)/2;c.style.left=`${d}px`,c.style.top=`${u}px`;const p=r.clientWidth,m=r.clientHeight;c.style.display=d<0||u<0||d>p||u>m?"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"===a&&Math.abs(s.y-t.y)>1e-9){const e=F(s.x,t.y),n=F(s.x,s.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"===a&&Math.abs(s.x-t.x)>1e-9){const e=F(t.x,s.y),n=F(s.x,s.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,s=r.clientHeight;e.label.style.display=t<0||n<0||t>i||n>s?"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")},U=()=>{const e=de.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 _=0,G=0,Y=0,$=!1,Z=!1,q=null;const re=e=>{const t=e?.detail;t&&0===t.domEvent?.button&&(_=t.canvasCoord.x,G=t.canvasCoord.y,Y=performance.now(),Z=!1,$=!0)},ie=e=>{const t=r.getBoundingClientRect(),n=e.clientX-t.left,i=e.clientY-t.top;$&&(n-_)**2+(i-G)**2>16&&(Z=!0);const s=de.current;var a;if(s&&s.snap)if($&&Z)s.snap.style.display="none";else if(q=((e,t)=>{const n=de.current;if(!n||!D||!n.segs)return null;const r=F(0,0),i=F(1,0),s=F(0,1),a=i.x-r.x,o=i.y-r.y,l=s.x-r.x,c=s.y-r.y,d=a*c-l*o;if(!d)return null;const u=((e-r.x)*c-(t-r.y)*l)/d,p=((t-r.y)*a-(e-r.x)*o)/d,m=18/(Math.hypot(a,o)||1),h=18/(Math.hypot(l,c)||1),y=u-m,f=u+m,x=p-h,g=p+h,b=324;let w=null,v=b,k=null,N=b,C=null,A=b,E=null,L=b;const M=[],S=n.segs;for(let n=0;n<S.length;n+=4){const i=S[n],s=S[n+1],d=S[n+2],u=S[n+3];if(i<y&&d<y||i>f&&d>f||s<x&&u<x||s>g&&u>g)continue;const p=r.x+a*i+l*s,m=r.y+o*i+c*s,h=r.x+a*d+l*u,E=r.y+o*d+c*u;let L=!1,z=e-p,T=t-m,R=z*z+T*T;R<b&&(L=!0,R<v&&(v=R,w={sx:i,sy:s,type:"endpoint"})),z=e-h,T=t-E,R=z*z+T*T,R<b&&(L=!0,R<v&&(v=R,w={sx:d,sy:u,type:"endpoint"})),z=e-(p+h)/2,T=t-(m+E)/2,R=z*z+T*T,R<b&&(L=!0,R<N&&(N=R,k={sx:(i+d)/2,sy:(s+u)/2,type:"midpoint"}));const j=h-p,D=E-m,F=j*j+D*D;if(F>0){const n=((e-p)*j+(t-m)*D)/F;n>0&&n<1&&(z=e-(p+n*j),T=t-(m+n*D),R=z*z+T*T,R<b&&(L=!0,R<A&&(A=R,C={sx:i+n*(d-i),sy:s+n*(u-s),type:"line"})))}L&&M.push({ax:i,ay:s,bx:d,by:u,apx:p,apy:m,bpx:h,bpy:E})}const z=n.nodes;if(z)for(let n=0;n<z.length;n+=2){const i=z[n],s=z[n+1];if(i<y||i>f||s<x||s>g)continue;const d=e-(r.x+a*i+l*s),u=t-(r.y+o*i+c*s),p=d*d+u*u;p<v&&(v=p,w={sx:i,sy:s,type:"node"})}for(let n=0;n<M.length;n++){const r=M[n];for(let i=n+1;i<M.length;i++){const n=M[i],s=H(r.apx,r.apy,r.bpx,r.bpy,n.apx,n.apy,n.bpx,n.bpy);if(!s)continue;const a=e-s.px,o=t-s.py,l=a*a+o*o;l>=b||l>=L||(L=l,E={sx:r.ax+s.t*(r.bx-r.ax),sy:r.ay+s.t*(r.by-r.ay),type:"intersection"})}}return(E&&w?L<v-1?E:w:E??w)??k??C})(n,i),q){const e=F(q.sx,q.sy);s.snap.style.left=`${e.x}px`,s.snap.style.top=`${e.y}px`,s.snap.style.display="",a=q.type,A.style.display="endpoint"===a?"":"none",E.style.display="intersection"===a?"":"none",z.style.display="line"===a?"":"none",T.style.display="midpoint"===a?"":"none",R.style.display="node"===a?"":"none"}else s.snap.style.display="none"},se=e=>{if(!$)return;$=!1;const t=performance.now()-Y;if(Z||t>350)return;const n=e?.detail?.position;if(!n)return;const r=q?{x:q.sx,y:q.sy}:{x:n.x,y:n.y};ue(r)},oe=()=>{const e=de.current;if(!e||2!==e.picks.length)return;W();const t=e.picks[0],n=e.picks[1],r=Q.current,i=O(t,n),s=J.current,a=null!==s&&Number.isFinite(s)&&("horizontal"===r||"vertical"===r);let o,c,d="",u=i;const p=Math.abs(n.x-t.x),m=Math.abs(n.y-t.y);if(a&&"horizontal"===r?(o=m,d=" ↕",u="vertical",c=L.current.echoLocked("ΔY",K(m),"ΔX",K(Math.abs(s)))):a&&"vertical"===r?(o=p,d=" ↔",u="horizontal",c=L.current.echoLocked("ΔX",K(p),"ΔY",K(Math.abs(s)))):"horizontal"===i?(o=p,d=" ↔",c=L.current.echoLinear(K(p),"ΔX")):"vertical"===i?(o=m,d=" ↕",c=L.current.echoLinear(K(m),"ΔY")):(o=Math.hypot(n.x-t.x,n.y-t.y),c=L.current.echoDistance(K(o),K(p),K(m))),!Number.isFinite(o))return B(null),V(null),void(e.label&&(e.label.style.opacity="0"));B(o),V(u),ae(c);const h=(()=>{const e=de.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})();h.style.opacity="1",h.textContent=`${K(o)}${d}`};ee.current=()=>{oe(),X()};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"),B(null),V(null)},ce=()=>{const e=de.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)}};te.current=ce,ne.current=()=>{const e=de.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),X()};const ue=e=>{const t=de.current;t&&(2===t.picks.length&&ce(),0===t.picks.length?(t.picks.push({x:e.x,y:e.y}),t.markers.push(I())):(t.rawSecondClick={x:e.x,y:e.y},t.picks.push({x:e.x,y:e.y}),t.markers.push(I()),oe()),X())},pe=e=>{"Escape"===e.key&&S(!1)};r.style.cursor="crosshair";try{e.Subscribe?.("pointerdown",re)}catch{}try{e.Subscribe?.("pointerup",se)}catch{}try{e.Subscribe?.("viewChanged",X)}catch{}return r.addEventListener("pointermove",ie),window.addEventListener("keydown",pe),()=>{r.style.cursor="";try{e.Unsubscribe?.("pointerdown",re)}catch{}try{e.Unsubscribe?.("pointerup",se)}catch{}try{e.Unsubscribe?.("viewChanged",X)}catch{}r.removeEventListener("pointermove",ie),window.removeEventListener("keydown",pe),ee.current=null,te.current=null,ne.current=null,i(),B(null),V(null)}},[M,o,d,ue]),F(()=>{ee.current?.()},[W,Y]);const pe=e=>{b(t=>t.map(t=>{if(t.visible===e)return t;try{a.current?.ShowLayer?.(t.name,e)}catch{}return{...t,visible:e}}))},me=()=>{try{const e=a.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{}};F(()=>{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=ce.current;if(!n)return;const r=n.closest("[data-modal-id]");r&&c()!==r.dataset.modalId||le.current?.focus()};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[]);const he=j(re),ye=j(M);F(()=>{he.current=re},[re]),F(()=>{ye.current=M},[M]),F(()=>u(()=>{const e=ce.current;if(!e)return!1;const t=e.closest("[data-modal-id]");return!(!t||c()!==t.dataset.modalId)&&(he.current?(ie(""),ae(L.current.cancelled),!0):!!ye.current&&(S(!1),ae(L.current.measureOff),!0))}),[]);const fe="px-2 py-1 rounded hover:bg-gray-200 transition-colors text-gray-600 flex items-center gap-1",[xe,ge]=T(A.typeToMeasure);/* @__PURE__ */
39
39
  return H("div",{ref:ce,className:"flex flex-col h-full",children:[
40
40
  /* @__PURE__ */H(n,{children:[
41
41
  /* @__PURE__ */H("button",{onClick:()=>v(e=>!e),className:fe+(w?" bg-gray-200":""),title:A.layersHint,disabled:0===m.length,children:[
@@ -44,13 +44,13 @@ return H("div",{ref:ce,className:"flex flex-col h-full",children:[
44
44
  /* @__PURE__ */H("button",{onClick:()=>S(e=>!e),className:fe+(M?" bg-gray-200":""),title:M?E.stopMeasuring:A.measureHint,children:[
45
45
  /* @__PURE__ */H("svg",{className:"h-3.5 w-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:1.5,children:[
46
46
  /* @__PURE__ */I("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M3.75 14.25l6-6 6 6 4.5-4.5M9.75 8.25v3M12.75 11.25v3M15.75 14.25v3"}),
47
- /* @__PURE__ */I("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M2.25 18.75h19.5"})]}),A.measure]}),M&&/* @__PURE__ */H(O,{children:[
47
+ /* @__PURE__ */I("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M2.25 18.75h19.5"})]}),A.measure]}),M&&/* @__PURE__ */H(P,{children:[
48
48
  /* @__PURE__ */H("div",{className:"flex items-stretch h-7 rounded border border-gray-200 overflow-hidden text-[11px] font-semibold",children:[
49
- /* @__PURE__ */I("button",{onClick:()=>W("auto"),className:"px-2 transition-colors "+("auto"===P?"bg-orange-500 text-white":"bg-white text-gray-600 hover:bg-gray-50"),title:A.autoHint,children:A.auto}),
50
- /* @__PURE__ */I("button",{onClick:()=>W("horizontal"),className:"px-2 transition-colors "+("horizontal"===P?"bg-orange-500 text-white":"bg-white text-gray-600 hover:bg-gray-50"),title:A.horizontalHint,children:"H"}),
51
- /* @__PURE__ */I("button",{onClick:()=>W("vertical"),className:"px-2 transition-colors "+("vertical"===P?"bg-orange-500 text-white":"bg-white text-gray-600 hover:bg-gray-50"),title:A.verticalHint,children:"V"}),
52
- /* @__PURE__ */I("button",{onClick:()=>W("point"),className:"px-2 transition-colors "+("point"===P?"bg-orange-500 text-white":"bg-white text-gray-600 hover:bg-gray-50"),title:A.pointHint,children:A.point})]}),("horizontal"===P||"vertical"===P)&&/* @__PURE__ */H("div",{className:"flex items-center gap-1",children:[
53
- /* @__PURE__ */I("input",{type:"number",inputMode:"decimal",step:"any",value:Z,placeholder:"horizontal"===P?A.fixX:A.fixY,onChange:e=>{const t=e.target.value;if(q(t),""===t.trim())$(null);else{const e=parseFloat(t);$(Number.isFinite(e)&&0!==e?e:null)}},className:"h-7 w-20 px-1.5 text-[11px] font-mono rounded border border-gray-200 bg-white text-gray-700 focus:outline-none focus:border-orange-400",title:A.fixHint}),null!==Y&&/* @__PURE__ */I("button",{onClick:()=>{$(null),q("")},className:"text-gray-400 hover:text-gray-600 text-[11px] px-1",title:A.clearFixed,children:"×"})]})]}),M&&null!==X&&/* @__PURE__ */H("div",{className:"px-2 py-1 text-[11px] font-mono font-semibold text-orange-600 bg-orange-50 border border-orange-200 rounded whitespace-nowrap",title:"horizontal"===G?A.horizontalDistance("auto"===P):"vertical"===G?A.verticalDistance("auto"===P):A.straightDistance,children:[K(X),"horizontal"===G?" ↔":"vertical"===G?" ↕":""]}),
49
+ /* @__PURE__ */I("button",{onClick:()=>O("auto"),className:"px-2 transition-colors "+("auto"===W?"bg-orange-500 text-white":"bg-white text-gray-600 hover:bg-gray-50"),title:A.autoHint,children:A.auto}),
50
+ /* @__PURE__ */I("button",{onClick:()=>O("horizontal"),className:"px-2 transition-colors "+("horizontal"===W?"bg-orange-500 text-white":"bg-white text-gray-600 hover:bg-gray-50"),title:A.horizontalHint,children:"H"}),
51
+ /* @__PURE__ */I("button",{onClick:()=>O("vertical"),className:"px-2 transition-colors "+("vertical"===W?"bg-orange-500 text-white":"bg-white text-gray-600 hover:bg-gray-50"),title:A.verticalHint,children:"V"}),
52
+ /* @__PURE__ */I("button",{onClick:()=>O("point"),className:"px-2 transition-colors "+("point"===W?"bg-orange-500 text-white":"bg-white text-gray-600 hover:bg-gray-50"),title:A.pointHint,children:A.point})]}),("horizontal"===W||"vertical"===W)&&/* @__PURE__ */H("div",{className:"flex items-center gap-1",children:[
53
+ /* @__PURE__ */I("input",{type:"number",inputMode:"decimal",step:"any",value:Z,placeholder:"horizontal"===W?A.fixX:A.fixY,onChange:e=>{const t=e.target.value;if(q(t),""===t.trim())$(null);else{const e=parseFloat(t);$(Number.isFinite(e)&&0!==e?e:null)}},className:"h-7 w-20 px-1.5 text-[11px] font-mono rounded border border-gray-200 bg-white text-gray-700 focus:outline-none focus:border-orange-400",title:A.fixHint}),null!==Y&&/* @__PURE__ */I("button",{onClick:()=>{$(null),q("")},className:"text-gray-400 hover:text-gray-600 text-[11px] px-1",title:A.clearFixed,children:"×"})]})]}),M&&null!==X&&/* @__PURE__ */H("div",{className:"px-2 py-1 text-[11px] font-mono font-semibold text-orange-600 bg-orange-50 border border-orange-200 rounded whitespace-nowrap",title:"horizontal"===G?A.horizontalDistance("auto"===W):"vertical"===G?A.verticalDistance("auto"===W):A.straightDistance,children:[K(X),"horizontal"===G?" ↔":"vertical"===G?" ↕":""]}),
54
54
  /* @__PURE__ */I("button",{onClick:me,className:fe,title:A.fitHint,children:A.fit}),
55
55
  /* @__PURE__ */H("button",{onClick:r??(()=>{const n=document.createElement("a");n.href=e,n.download=t,n.click()}),className:fe,children:[
56
56
  /* @__PURE__ */I(R,{name:"download",fallback:f,className:"h-3.5 w-3.5",strokeWidth:1.5}),E.download]}),i&&/* @__PURE__ */H("button",{onClick:i,className:fe,children:[
@@ -81,9 +81,9 @@ return H("div",{ref:ce,className:"flex flex-col h-full",children:[
81
81
  /* @__PURE__ */H("div",{className:"shrink-0 border-t border-gray-200 bg-gray-50",children:[se&&/* @__PURE__ */I("div",{className:"px-2.5 pt-1 text-[11px] font-mono text-gray-500 truncate",title:se,children:se}),
82
82
  /* @__PURE__ */H("div",{className:"flex items-center gap-1.5 px-2.5 h-7",children:[
83
83
  /* @__PURE__ */I("span",{className:"text-[11px] font-mono font-semibold text-gray-400 select-none",children:">"}),
84
- /* @__PURE__ */I("input",{ref:le,value:re,onChange:e=>ie(e.target.value),onKeyDown:e=>{"Enter"===e.key||" "===e.key?(e.preventDefault(),(e=>{const t=e.trim()||oe.current;if(ie(""),!t)return;const n=t.toLowerCase().split(/\s+/)[0],r=()=>{oe.current=t},i=(e,t)=>{S(!0),W(e),te.current?.(),ae(t),r()};if(/^-?(\d+\.?\d*|\.\d+)$/.test(n))if(!M||"horizontal"!==P&&"vertical"!==P)ae(A.fixedNeedsAxis);else{const e=parseFloat(n);e?(q(n),$(e),ae(A.axisLocked("horizontal"===P?"ΔX":"ΔY",K(Math.abs(e))))):(q(""),$(null),ae(A.fixedCleared))}else switch(n){case"di":case"dist":case"mea":case"measuregeom":i("point",A.echoDist);break;case"dim":case"dli":case"dimlin":case"dimlinear":i("auto",A.echoDimLinear);break;case"h":case"hor":case"horizontal":S(!0),W("horizontal"),ae(A.echoHorizontal),r();break;case"v":case"ver":case"vertical":S(!0),W("vertical"),ae(A.echoVertical),r();break;case"au":case"auto":S(!0),W("auto"),ae(A.echoAuto),r();break;case"measure":S(!M),ae(M?A.measureOff:A.measureOn),r();break;case"u":case"undo":ne.current?.(),ae(A.pickRemoved),r();break;case"z":case"ze":case"zoom":case"fit":case"zoomextents":me(),ae(A.zoomExtents),r();break;case"la":case"layer":case"layers":v(e=>!e),ae(A.layersToggled),r();break;case"off":case"clear":$(null),q(""),te.current?.(),ae(A.measurementCleared),r();break;case"?":case"help":ae(A.commandHelp);break;default:{const e=_[n];ae(e?A.readOnly(e):A.unknownCommand(n.toUpperCase()))}}})(re)):"Escape"===e.key&&(re?(e.stopPropagation(),ie(""),ae(A.cancelled)):e.target.blur())},placeholder:A.commandPlaceholder,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 V="https://cdn.jsdelivr.net/npm/online-3d-viewer@0.18.0/libs/";function Y(e,t,n=0){return{id:e.GetId?.()??0,name:e.GetName?.()||(0===n?t.root:t.node),isMeshNode:!!e.IsMeshNode?.(),meshIndices:e.GetMeshIndices?.()??[],children:(e.GetChildNodes?.()??[]).map(e=>Y(e,t,n+1))}}function $(e,t){t.add(e.id);for(const n of e.children)$(n,t)}function Z(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 K(e){return e>=1e3?`${(e/1e3).toFixed(3)} m`:`${e.toFixed(2)} mm`}function q({url:e,filename:t,onDownload:r,onEmail:i}){const s=j(null),a=j(null),o=j(null),[l,c]=D(!0),[d,u]=D(null),[p,m]=D(!0),h=z(),g=h.model,N=h.preview,C=j(g);C.current=g;const[A,T]=D(null),[O,W]=D({}),[X,B]=D(/* @__PURE__ */new Set),[U,_]=D("#f5f6f8"),[G,q]=D(!0),[Q,J]=D("#000000"),[ee,te]=D(1),[ne,re]=D(!1),[ie,se]=D(!1),[ae,oe]=D(!1),[le,ce]=D(!1),[de,ue]=D("x"),[pe,me]=D(!1),[he,ye]=D(.5),[fe,xe]=D(0),[ge,be]=D(!1),[we,ve]=D("point"),[ke,Ne]=D(null),Ce=j(null),Ae=j(null);F(()=>{let n=!1,r=null,i=null;return c(!0),u(null),T(null),W({}),B(/* @__PURE__ */new Set),(async()=>{let l;try{l=await(import("online-3d-viewer"))}catch{return void(n||(u(C.current.notInstalled),c(!1)))}if(o.current=l,!n&&s.current&&(await new Promise(e=>{const t=()=>{const n=s.current?.getBoundingClientRect();n&&n.width>4&&n.height>4?e():requestAnimationFrame(t)};t()}),!n&&s.current))try{const o="undefined"!=typeof window&&window.__REACT_OS_SHELL_O3DV_LIBS__||V;l.SetExternalLibLocation?.(o),function(){if(P)return;if("undefined"==typeof HTMLCanvasElement)return;P=!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(s.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=Y(t,{root:C.current.rootNode,node:C.current.node});T(e);const n={[e.id]:!0};for(const t of e.children)n[t.id]=!0;W(n)}}catch(e){console.warn("[Preview] mesh tree extraction failed",e)}c(!1)}},onModelLoadFailed:()=>{n||(u(C.current.loadFailed),c(!1))}}),a.current=r;const d=new l.InputFile(t,l.FileSource.Url,e);r.LoadModelFromInputFiles([d]),s.current&&"undefined"!=typeof ResizeObserver&&(i=new ResizeObserver(()=>{try{const e=a.current;e?.Resize?e.Resize():e?.viewer?.Resize&&e.viewer.Resize(),e?.viewer?.Render?.()}catch{}}),i.observe(s.current))}catch(e){n||(u(e?.message||C.current.loadFailed),c(!1))}})(),()=>{n=!0;try{i?.disconnect()}catch{}try{r?.Destroy?.()}catch{}a.current=null}},[e,t]),F(()=>{const e=a.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=!X.has(n))};e.viewer.mainModel?.EnumerateMeshesAndLines?.(t),e.viewer.mainModel?.EnumerateEdges?.(t),e.viewer.Render?.()}catch(e){console.warn("[Preview] visibility update failed",e)}},[X,A]),F(()=>{const e=o.current,t=a.current;if(e&&t?.viewer)try{t.viewer.SetEdgeSettings(new e.EdgeSettings(G,Z(e,Q),ee));const n=Ae.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{}},[G,Q,ee]),F(()=>{const e=o.current,t=a.current;if(e&&t?.viewer)try{const n=Z(e,U);t.viewer.SetBackgroundColor(new e.RGBAColor(n.r,n.g,n.b,255)),t.viewer.Render?.()}catch{}},[U]),F(()=>{const e=a.current;if(!e?.viewer||l)return;const t=e.viewer.renderer,n=e.viewer.scene;if(!t||!n)return;if(Ae.current){const e=Ae.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?.()),Ae.current=null}if(!le)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 s=i[0],o=s.constructor,c=s.material?.constructor,d=s.geometry?.constructor,u=s.geometry?.attributes?.position?.constructor;o&&c&&d&&u||console.warn("[Preview] section: missing THREE constructors, falling back to no cap");const p=7681;let m=!0;try{const e=t.getContext?.(),n=e?.getContextAttributes?.();m=!1!==n?.stencil,t.autoClearStencil=!0,console.info("[Preview] section: stencil buffer =",m,"targets =",i.length)}catch{}t.localClippingEnabled=!0;const h={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}},y=[],f=/* @__PURE__ */new Map,x=e=>{e&&!f.has(e)&&(f.set(e,{clippingPlanes:e.clippingPlanes,clipShadows:e.clipShadows}),e.clippingPlanes=[h],e.clipShadows=!0,e.needsUpdate=!0)};for(const e of i){const t=e.material;if(Array.isArray(t))for(const e of t)x(e);else x(t);const n=Array.isArray(t)?t[0]:t;if(o&&m&&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=[h],i.clipShadows=!0,i.needsUpdate=!0;const s=new o(e.geometry,i);s.matrixAutoUpdate=!1,s.renderOrder=1,s.userData.__sectionHelper=!0,e.add(s),y.push(s)};t(1,7682),t(0,7683)}}e.viewer.mainModel?.EnumerateEdges?.(e=>{const t=e.material;if(Array.isArray(t))for(const e of t)x(e);else x(t)});let g=null;const b=i[0]?.material&&(Array.isArray(i[0].material)?i[0].material[0]:i[0].material);if(m&&o&&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,s=2*Math.max(e,t,i,1)/2,a=new d,l=new Float32Array([-s,-s,0,s,-s,0,s,s,0,-s,s,0]),c=new Float32Array([0,0,1,0,0,1,0,0,1,0,0,1]);a.setAttribute("position",new u(l,3)),a.setAttribute("normal",new u(c,3)),a.setIndex([0,1,2,0,2,3]);const m=b.clone(),h=b.color?.getHex?.()??11844808;m.emissive?.setHex?.(h),"emissiveIntensity"in m&&(m.emissiveIntensity=.25),m.side=2,m.transparent=!1,m.opacity=1,m.stencilWrite=!0,m.stencilRef=0,m.stencilFunc=517,m.stencilFail=p,m.stencilZFail=p,m.stencilZPass=p,m.clippingPlanes=[],m.polygonOffset=!0,m.polygonOffsetFactor=-1,m.polygonOffsetUnits=-1,m.needsUpdate=!0,g=new o(a,m),g.renderOrder=2,g.userData.__sectionHelper=!0,n.add(g)}Ae.current={plane:h,capMesh:g,helpers:y,materialState:f,bbox:r},console.info("[Preview] section: helpers =",y.length,"cap =",!!g),e.viewer.Render?.()},[le,l,A]),F(()=>{const e=a.current,t=Ae.current;if(e?.viewer&&t&&le)try{const n=t.bbox,r="x"===de?0:"y"===de?1:2,i=[n.min.x,n.min.y,n.min.z][r],s=i+([n.max.x,n.max.y,n.max.z][r]-i)*he,a=fe*Math.PI/180,o=Math.cos(a),l=Math.sin(a),c=pe?-1:1;let d=0,u=0,p=0;"x"===de?(d=c*o,p=c*l):"y"===de?(u=c*o,d=c*l):(p=c*o,u=c*l);const m={x:(n.min.x+n.max.x)/2,y:(n.min.y+n.max.y)/2,z:(n.min.z+n.max.z)/2},h="x"===de?s:m.x,y="y"===de?s:m.y,f="z"===de?s:m.z;if(t.plane.normal.x=d,t.plane.normal.y=u,t.plane.normal.z=p,t.plane.constant=-(d*h+u*y+p*f),t.capMesh){const e=m.x,n=m.y,r=m.z,i=d*e+u*n+p*r+t.plane.constant,s=e-d*i,a=n-u*i,o=r-p*i;t.capMesh.position.set(s,a,o),t.capMesh.lookAt?.(s+d,a+u,o+p)}e.viewer.Render?.()}catch(e){console.warn("[Preview] section update failed",e)}},[le,de,pe,he,fe]),F(()=>{const e=a.current;if(!e?.viewer||l||!s.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,m=i.geometry.attributes?.position?.constructor;if(!(c&&d&&u&&p&&m))return;let h=null,y=null;n.traverse(e=>{if(h&&y)return;if(!e?.isLineSegments)return;h=e.constructor;const t=Array.isArray(e.material)?e.material[0]:e.material;t?.constructor&&(y=t.constructor)});const f=()=>{const t=Ce.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),Ce.current=null,e.viewer.Render?.()}};if(!ge)return f(),void Ne(null);Ce.current={points:[],normals:[],markers:[],line:null,label:null,rafId:null};const x=o.current,g=x?.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 m(new Float32Array(t),3)),i.setIndex(r),i.computeVertexNormals?.();const s=new u;s.color?.setHex?.(16746496),s.depthTest=!1,s.depthWrite=!1,s.transparent=!0,s.opacity=.95;const a=new d(i,s);return a.position.copy(e),a.renderOrder=9999,a.userData.__measureHelper=!0,n.add(a),a},N=()=>{const t=Ce.current;t&&((()=>{const t=Ce.current;if(!t||t.points.length<2||!t.label)return;const n=e.viewer.camera;if(!n)return;const i=t.points[0],s=t.points[1],a=new c((i.x+s.x)/2,(i.y+s.y)/2,(i.z+s.z)/2).clone();a.project?.(n);const o=r.getBoundingClientRect(),l=(a.x+1)/2*o.width,d=(1-a.y)/2*o.height;t.label.style.left=`${l}px`,t.label.style.top=`${d}px`;const u=l<0||d<0||l>o.width||d>o.height;t.label.style.opacity=a.z>1||u?"0":"1"})(),t.rafId=requestAnimationFrame(N))};Ce.current.rafId=requestAnimationFrame(N);let C=0,A=0,E=0,L=!1,M=!1;const S=t=>{if(!e.viewer.camera)return;const i=r.getBoundingClientRect(),a={x:t.clientX-i.left,y:t.clientY-i.top},o=e.viewer.GetMeshIntersectionUnderMouse?.(g,a);if(!o)return;const l=Ce.current,f=new c(o.point.x,o.point.y,o.point.z),x=(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}}})(o);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=[],Ne(null)}if(l.points.push(f),l.normals.push(x),"perp"===we){const e=((e,t)=>{const r=e?.geometry,i=r?.attributes?.position;if(!r||!i||!t?.face?.normal)return null;const s=i.array,a=r.index?r.index.array:null,o=new c(t.point.x,t.point.y,t.point.z);e.worldToLocal?.(o);const l=t.face.normal,h=-(l.x*o.x+l.y*o.y+l.z*o.z);r.computeBoundingBox?.();const y=r.boundingBox,f=y?Math.sqrt((y.max.x-y.min.x)**2+(y.max.y-y.min.y)**2+(y.max.z-y.min.z)**2):100,x=Math.max(.001*f,.005),g=a?a.length/3:i.count/3,b=[],w=new c;for(let t=0;t<g;t++){const n=a?a[3*t]:3*t,r=a?a[3*t+1]:3*t+1,i=a?a[3*t+2]:3*t+2,o=s[3*n],c=s[3*n+1],d=s[3*n+2],u=s[3*r],p=s[3*r+1],m=s[3*r+2],y=s[3*i],f=s[3*i+1],g=s[3*i+2],v=u-o,k=p-c,N=m-d,C=y-o,A=f-c,E=g-d;let L=k*E-N*A,M=N*C-v*E,S=v*A-k*C;const z=Math.sqrt(L*L+M*M+S*S);if(0===z)continue;if(L/=z,M/=z,S/=z,L*l.x+M*l.y+S*l.z<.9995)continue;const T=(o+u+y)/3,R=(c+p+f)/3,j=(d+m+g)/3;if(!(Math.abs(l.x*T+l.y*R+l.z*j+h)>x))for(const[t,n,r]of[[o,c,d],[u,p,m],[y,f,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 m(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})(o.object,o);l.markers.push(e??k(f))}else l.markers.push(k(f));if(2===l.points.length){const e=l.points[0];let t,r=l.points[1],i="";if("perp"===we){const n=l.normals[0]??l.normals[1];if(n){const s=Math.sqrt(n.x*n.x+n.y*n.y+n.z*n.z)||1,a=n.x/s,o=n.y/s,d=n.z/s,u=(r.x-e.x)*a+(r.y-e.y)*o+(r.z-e.z)*d,p=new c(e.x+a*u,e.y+o*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,s=r.z-e.z;t=Math.sqrt(n*n+i*i+s*s)}}else{const n=r.x-e.x,i=r.y-e.y,s=r.z-e.z;t=Math.sqrt(n*n+i*i+s*s)}l.line=((e,t)=>{const r=new p;r.setAttribute("position",new m(new Float32Array([e.x,e.y,e.z,t.x,t.y,t.z]),3));const i=new(h??d)(r,new(y??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),Ne(t);const a=(()=>{const e=Ce.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",s.current.appendChild(t),e.label=t,t})();a.textContent=`${K(t)}${i}`}e.viewer.Render?.()},z=e=>{0===e.button&&(C=e.clientX,A=e.clientY,E=performance.now(),L=!1,M=!0)},T=e=>{if(!M)return;const t=e.clientX-C,n=e.clientY-A;t*t+n*n>16&&(L=!0)},R=e=>{if(0!==e.button||!M)return;const t=performance.now()-E;M=!1,!L&&t<350&&S(e)},j=e=>{"Escape"===e.key&&be(!1)};return r.style.cursor="crosshair",r.addEventListener("pointerdown",z),r.addEventListener("pointermove",T),r.addEventListener("pointerup",R),r.addEventListener("pointercancel",R),window.addEventListener("keydown",j),()=>{r.style.cursor="",r.removeEventListener("pointerdown",z),r.removeEventListener("pointermove",T),r.removeEventListener("pointerup",R),r.removeEventListener("pointercancel",R),window.removeEventListener("keydown",j),f(),Ne(null)}},[ge,we,l,A]),F(()=>{if(!p||l)return;const e=setTimeout(()=>m(!1),5e3);return()=>clearTimeout(e)},[p,l]);const Ee=e=>{const t=/* @__PURE__ */new Set;$(e,t),B(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})},Le=()=>{try{const e=a.current,t=e?.viewer?.GetBoundingSphere?.(()=>!0);t&&e.viewer.FitSphereToWindow(t,!0),e?.viewer?.Render?.()}catch{}};F(()=>{const e=o.current,t=a.current;if(e&&t?.viewer&&!l)try{t.viewer.SetProjectionMode(ae?e.ProjectionMode.Perspective:e.ProjectionMode.Orthographic)}catch{}},[ae,l]);const Me=e=>{const t=o.current,n=a.current;if(t&&n?.viewer)try{const r=n.viewer.GetBoundingSphere?.(()=>!0);if(!r)return;const i=r.center,s=3*(r.radius||1),a=i.x??0,o=i.y??0,l=i.z??0;let c,d;switch(e){case"top":c=new t.Coord3D(a,o,l+s),d=new t.Coord3D(0,1,0);break;case"front":c=new t.Coord3D(a,o-s,l),d=new t.Coord3D(0,0,1);break;case"side":c=new t.Coord3D(a+s,o,l),d=new t.Coord3D(0,0,1);break;default:{const e=s/Math.sqrt(3);c=new t.Coord3D(a+e,o-e,l+e),d=new t.Coord3D(0,0,1);break}}const u=new t.Coord3D(a,o,l),p=new t.Camera(c,u,d,45);n.viewer.SetCamera(p),n.viewer.AdjustClippingPlanesToSphere?.(r),n.viewer.Render?.()}catch{}},Se=(t.split(".").pop()||"").toUpperCase(),ze=(e,t=0)=>{const n=e.children.length>0,r=!1!==O[e.id],i=!X.has(e.id);/* @__PURE__ */
84
+ /* @__PURE__ */I("input",{ref:le,value:re,onChange:e=>ie(e.target.value),onKeyDown:e=>{"Enter"===e.key||" "===e.key?(e.preventDefault(),(e=>{const t=e.trim()||oe.current;if(ie(""),!t)return;const n=t.toLowerCase().split(/\s+/)[0],r=()=>{oe.current=t},i=(e,t)=>{S(!0),O(e),te.current?.(),ae(t),r()};if(/^-?(\d+\.?\d*|\.\d+)$/.test(n))if(!M||"horizontal"!==W&&"vertical"!==W)ae(A.fixedNeedsAxis);else{const e=parseFloat(n);e?(q(n),$(e),ae(A.axisLocked("horizontal"===W?"ΔX":"ΔY",K(Math.abs(e))))):(q(""),$(null),ae(A.fixedCleared))}else switch(n){case"di":case"dist":case"mea":case"measuregeom":i("point",A.echoDist);break;case"dim":case"dli":case"dimlin":case"dimlinear":i("auto",A.echoDimLinear);break;case"h":case"hor":case"horizontal":S(!0),O("horizontal"),ae(A.echoHorizontal),r();break;case"v":case"ver":case"vertical":S(!0),O("vertical"),ae(A.echoVertical),r();break;case"au":case"auto":S(!0),O("auto"),ae(A.echoAuto),r();break;case"measure":S(!M),ae(M?A.measureOff:A.measureOn),r();break;case"u":case"undo":ne.current?.(),ae(A.pickRemoved),r();break;case"z":case"ze":case"zoom":case"fit":case"zoomextents":me(),ae(A.zoomExtents),r();break;case"la":case"layer":case"layers":v(e=>!e),ae(A.layersToggled),r();break;case"off":case"clear":$(null),q(""),te.current?.(),ae(A.measurementCleared),r();break;case"?":case"help":ae(A.commandHelp);break;default:{const e=_[n];ae(e?A.readOnly(e):A.unknownCommand(n.toUpperCase()))}}})(re)):"Escape"===e.key&&(re?(e.stopPropagation(),ie(""),ae(A.cancelled)):e.target.blur())},placeholder:A.commandPlaceholder,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 V="https://cdn.jsdelivr.net/npm/online-3d-viewer@0.18.0/libs/";function Y(e,t,n=0){return{id:e.GetId?.()??0,name:e.GetName?.()||(0===n?t.root:t.node),isMeshNode:!!e.IsMeshNode?.(),meshIndices:e.GetMeshIndices?.()??[],children:(e.GetChildNodes?.()??[]).map(e=>Y(e,t,n+1))}}function $(e,t){t.add(e.id);for(const n of e.children)$(n,t)}function Z(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 K(e){return e>=1e3?`${(e/1e3).toFixed(3)} m`:`${e.toFixed(2)} mm`}function q({url:e,filename:t,onDownload:r,onEmail:i}){const s=j(null),a=j(null),o=j(null),[l,c]=D(!0),[d,u]=D(null),[p,m]=D(!0),h=z(),g=h.model,N=h.preview,C=j(g);C.current=g;const[A,T]=D(null),[P,O]=D({}),[X,B]=D(/* @__PURE__ */new Set),[U,_]=D("#f5f6f8"),[G,q]=D(!0),[Q,J]=D("#000000"),[ee,te]=D(1),[ne,re]=D(!1),[ie,se]=D(!1),[ae,oe]=D(!1),[le,ce]=D(!1),[de,ue]=D("x"),[pe,me]=D(!1),[he,ye]=D(.5),[fe,xe]=D(0),[ge,be]=D(!1),[we,ve]=D("point"),[ke,Ne]=D(null),Ce=j(null),Ae=j(null);F(()=>{let n=!1,r=null,i=null;return c(!0),u(null),T(null),O({}),B(/* @__PURE__ */new Set),(async()=>{let l;try{l=await(import("online-3d-viewer"))}catch{return void(n||(u(C.current.notInstalled),c(!1)))}if(o.current=l,!n&&s.current&&(await new Promise(e=>{const t=()=>{const n=s.current?.getBoundingClientRect();n&&n.width>4&&n.height>4?e():requestAnimationFrame(t)};t()}),!n&&s.current))try{const o="undefined"!=typeof window&&window.__REACT_OS_SHELL_O3DV_LIBS__||V;l.SetExternalLibLocation?.(o),function(){if(W)return;if("undefined"==typeof HTMLCanvasElement)return;W=!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(s.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=Y(t,{root:C.current.rootNode,node:C.current.node});T(e);const n={[e.id]:!0};for(const t of e.children)n[t.id]=!0;O(n)}}catch(e){console.warn("[Preview] mesh tree extraction failed",e)}c(!1)}},onModelLoadFailed:()=>{n||(u(C.current.loadFailed),c(!1))}}),a.current=r;const d=new l.InputFile(t,l.FileSource.Url,e);r.LoadModelFromInputFiles([d]),s.current&&"undefined"!=typeof ResizeObserver&&(i=new ResizeObserver(()=>{try{const e=a.current;e?.Resize?e.Resize():e?.viewer?.Resize&&e.viewer.Resize(),e?.viewer?.Render?.()}catch{}}),i.observe(s.current))}catch(e){n||(u(e?.message||C.current.loadFailed),c(!1))}})(),()=>{n=!0;try{i?.disconnect()}catch{}try{r?.Destroy?.()}catch{}a.current=null}},[e,t]),F(()=>{const e=a.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=!X.has(n))};e.viewer.mainModel?.EnumerateMeshesAndLines?.(t),e.viewer.mainModel?.EnumerateEdges?.(t),e.viewer.Render?.()}catch(e){console.warn("[Preview] visibility update failed",e)}},[X,A]),F(()=>{const e=o.current,t=a.current;if(e&&t?.viewer)try{t.viewer.SetEdgeSettings(new e.EdgeSettings(G,Z(e,Q),ee));const n=Ae.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{}},[G,Q,ee]),F(()=>{const e=o.current,t=a.current;if(e&&t?.viewer)try{const n=Z(e,U);t.viewer.SetBackgroundColor(new e.RGBAColor(n.r,n.g,n.b,255)),t.viewer.Render?.()}catch{}},[U]),F(()=>{const e=a.current;if(!e?.viewer||l)return;const t=e.viewer.renderer,n=e.viewer.scene;if(!t||!n)return;if(Ae.current){const e=Ae.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?.()),Ae.current=null}if(!le)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 s=i[0],o=s.constructor,c=s.material?.constructor,d=s.geometry?.constructor,u=s.geometry?.attributes?.position?.constructor;o&&c&&d&&u||console.warn("[Preview] section: missing THREE constructors, falling back to no cap");const p=7681;let m=!0;try{const e=t.getContext?.(),n=e?.getContextAttributes?.();m=!1!==n?.stencil,t.autoClearStencil=!0,console.info("[Preview] section: stencil buffer =",m,"targets =",i.length)}catch{}t.localClippingEnabled=!0;const h={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}},y=[],f=/* @__PURE__ */new Map,x=e=>{e&&!f.has(e)&&(f.set(e,{clippingPlanes:e.clippingPlanes,clipShadows:e.clipShadows}),e.clippingPlanes=[h],e.clipShadows=!0,e.needsUpdate=!0)};for(const e of i){const t=e.material;if(Array.isArray(t))for(const e of t)x(e);else x(t);const n=Array.isArray(t)?t[0]:t;if(o&&m&&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=[h],i.clipShadows=!0,i.needsUpdate=!0;const s=new o(e.geometry,i);s.matrixAutoUpdate=!1,s.renderOrder=1,s.userData.__sectionHelper=!0,e.add(s),y.push(s)};t(1,7682),t(0,7683)}}e.viewer.mainModel?.EnumerateEdges?.(e=>{const t=e.material;if(Array.isArray(t))for(const e of t)x(e);else x(t)});let g=null;const b=i[0]?.material&&(Array.isArray(i[0].material)?i[0].material[0]:i[0].material);if(m&&o&&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,s=2*Math.max(e,t,i,1)/2,a=new d,l=new Float32Array([-s,-s,0,s,-s,0,s,s,0,-s,s,0]),c=new Float32Array([0,0,1,0,0,1,0,0,1,0,0,1]);a.setAttribute("position",new u(l,3)),a.setAttribute("normal",new u(c,3)),a.setIndex([0,1,2,0,2,3]);const m=b.clone(),h=b.color?.getHex?.()??11844808;m.emissive?.setHex?.(h),"emissiveIntensity"in m&&(m.emissiveIntensity=.25),m.side=2,m.transparent=!1,m.opacity=1,m.stencilWrite=!0,m.stencilRef=0,m.stencilFunc=517,m.stencilFail=p,m.stencilZFail=p,m.stencilZPass=p,m.clippingPlanes=[],m.polygonOffset=!0,m.polygonOffsetFactor=-1,m.polygonOffsetUnits=-1,m.needsUpdate=!0,g=new o(a,m),g.renderOrder=2,g.userData.__sectionHelper=!0,n.add(g)}Ae.current={plane:h,capMesh:g,helpers:y,materialState:f,bbox:r},console.info("[Preview] section: helpers =",y.length,"cap =",!!g),e.viewer.Render?.()},[le,l,A]),F(()=>{const e=a.current,t=Ae.current;if(e?.viewer&&t&&le)try{const n=t.bbox,r="x"===de?0:"y"===de?1:2,i=[n.min.x,n.min.y,n.min.z][r],s=i+([n.max.x,n.max.y,n.max.z][r]-i)*he,a=fe*Math.PI/180,o=Math.cos(a),l=Math.sin(a),c=pe?-1:1;let d=0,u=0,p=0;"x"===de?(d=c*o,p=c*l):"y"===de?(u=c*o,d=c*l):(p=c*o,u=c*l);const m={x:(n.min.x+n.max.x)/2,y:(n.min.y+n.max.y)/2,z:(n.min.z+n.max.z)/2},h="x"===de?s:m.x,y="y"===de?s:m.y,f="z"===de?s:m.z;if(t.plane.normal.x=d,t.plane.normal.y=u,t.plane.normal.z=p,t.plane.constant=-(d*h+u*y+p*f),t.capMesh){const e=m.x,n=m.y,r=m.z,i=d*e+u*n+p*r+t.plane.constant,s=e-d*i,a=n-u*i,o=r-p*i;t.capMesh.position.set(s,a,o),t.capMesh.lookAt?.(s+d,a+u,o+p)}e.viewer.Render?.()}catch(e){console.warn("[Preview] section update failed",e)}},[le,de,pe,he,fe]),F(()=>{const e=a.current;if(!e?.viewer||l||!s.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,m=i.geometry.attributes?.position?.constructor;if(!(c&&d&&u&&p&&m))return;let h=null,y=null;n.traverse(e=>{if(h&&y)return;if(!e?.isLineSegments)return;h=e.constructor;const t=Array.isArray(e.material)?e.material[0]:e.material;t?.constructor&&(y=t.constructor)});const f=()=>{const t=Ce.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),Ce.current=null,e.viewer.Render?.()}};if(!ge)return f(),void Ne(null);Ce.current={points:[],normals:[],markers:[],line:null,label:null,rafId:null};const x=o.current,g=x?.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 m(new Float32Array(t),3)),i.setIndex(r),i.computeVertexNormals?.();const s=new u;s.color?.setHex?.(16746496),s.depthTest=!1,s.depthWrite=!1,s.transparent=!0,s.opacity=.95;const a=new d(i,s);return a.position.copy(e),a.renderOrder=9999,a.userData.__measureHelper=!0,n.add(a),a},N=()=>{const t=Ce.current;t&&((()=>{const t=Ce.current;if(!t||t.points.length<2||!t.label)return;const n=e.viewer.camera;if(!n)return;const i=t.points[0],s=t.points[1],a=new c((i.x+s.x)/2,(i.y+s.y)/2,(i.z+s.z)/2).clone();a.project?.(n);const o=r.getBoundingClientRect(),l=(a.x+1)/2*o.width,d=(1-a.y)/2*o.height;t.label.style.left=`${l}px`,t.label.style.top=`${d}px`;const u=l<0||d<0||l>o.width||d>o.height;t.label.style.opacity=a.z>1||u?"0":"1"})(),t.rafId=requestAnimationFrame(N))};Ce.current.rafId=requestAnimationFrame(N);let C=0,A=0,E=0,L=!1,M=!1;const S=t=>{if(!e.viewer.camera)return;const i=r.getBoundingClientRect(),a={x:t.clientX-i.left,y:t.clientY-i.top},o=e.viewer.GetMeshIntersectionUnderMouse?.(g,a);if(!o)return;const l=Ce.current,f=new c(o.point.x,o.point.y,o.point.z),x=(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}}})(o);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=[],Ne(null)}if(l.points.push(f),l.normals.push(x),"perp"===we){const e=((e,t)=>{const r=e?.geometry,i=r?.attributes?.position;if(!r||!i||!t?.face?.normal)return null;const s=i.array,a=r.index?r.index.array:null,o=new c(t.point.x,t.point.y,t.point.z);e.worldToLocal?.(o);const l=t.face.normal,h=-(l.x*o.x+l.y*o.y+l.z*o.z);r.computeBoundingBox?.();const y=r.boundingBox,f=y?Math.sqrt((y.max.x-y.min.x)**2+(y.max.y-y.min.y)**2+(y.max.z-y.min.z)**2):100,x=Math.max(.001*f,.005),g=a?a.length/3:i.count/3,b=[],w=new c;for(let t=0;t<g;t++){const n=a?a[3*t]:3*t,r=a?a[3*t+1]:3*t+1,i=a?a[3*t+2]:3*t+2,o=s[3*n],c=s[3*n+1],d=s[3*n+2],u=s[3*r],p=s[3*r+1],m=s[3*r+2],y=s[3*i],f=s[3*i+1],g=s[3*i+2],v=u-o,k=p-c,N=m-d,C=y-o,A=f-c,E=g-d;let L=k*E-N*A,M=N*C-v*E,S=v*A-k*C;const z=Math.sqrt(L*L+M*M+S*S);if(0===z)continue;if(L/=z,M/=z,S/=z,L*l.x+M*l.y+S*l.z<.9995)continue;const T=(o+u+y)/3,R=(c+p+f)/3,j=(d+m+g)/3;if(!(Math.abs(l.x*T+l.y*R+l.z*j+h)>x))for(const[t,n,r]of[[o,c,d],[u,p,m],[y,f,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 m(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})(o.object,o);l.markers.push(e??k(f))}else l.markers.push(k(f));if(2===l.points.length){const e=l.points[0];let t,r=l.points[1],i="";if("perp"===we){const n=l.normals[0]??l.normals[1];if(n){const s=Math.sqrt(n.x*n.x+n.y*n.y+n.z*n.z)||1,a=n.x/s,o=n.y/s,d=n.z/s,u=(r.x-e.x)*a+(r.y-e.y)*o+(r.z-e.z)*d,p=new c(e.x+a*u,e.y+o*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,s=r.z-e.z;t=Math.sqrt(n*n+i*i+s*s)}}else{const n=r.x-e.x,i=r.y-e.y,s=r.z-e.z;t=Math.sqrt(n*n+i*i+s*s)}l.line=((e,t)=>{const r=new p;r.setAttribute("position",new m(new Float32Array([e.x,e.y,e.z,t.x,t.y,t.z]),3));const i=new(h??d)(r,new(y??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),Ne(t);const a=(()=>{const e=Ce.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",s.current.appendChild(t),e.label=t,t})();a.textContent=`${K(t)}${i}`}e.viewer.Render?.()},z=e=>{0===e.button&&(C=e.clientX,A=e.clientY,E=performance.now(),L=!1,M=!0)},T=e=>{if(!M)return;const t=e.clientX-C,n=e.clientY-A;t*t+n*n>16&&(L=!0)},R=e=>{if(0!==e.button||!M)return;const t=performance.now()-E;M=!1,!L&&t<350&&S(e)},j=e=>{"Escape"===e.key&&be(!1)};return r.style.cursor="crosshair",r.addEventListener("pointerdown",z),r.addEventListener("pointermove",T),r.addEventListener("pointerup",R),r.addEventListener("pointercancel",R),window.addEventListener("keydown",j),()=>{r.style.cursor="",r.removeEventListener("pointerdown",z),r.removeEventListener("pointermove",T),r.removeEventListener("pointerup",R),r.removeEventListener("pointercancel",R),window.removeEventListener("keydown",j),f(),Ne(null)}},[ge,we,l,A]),F(()=>{if(!p||l)return;const e=setTimeout(()=>m(!1),5e3);return()=>clearTimeout(e)},[p,l]);const Ee=e=>{const t=/* @__PURE__ */new Set;$(e,t),B(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})},Le=()=>{try{const e=a.current,t=e?.viewer?.GetBoundingSphere?.(()=>!0);t&&e.viewer.FitSphereToWindow(t,!0),e?.viewer?.Render?.()}catch{}};F(()=>{const e=o.current,t=a.current;if(e&&t?.viewer&&!l)try{t.viewer.SetProjectionMode(ae?e.ProjectionMode.Perspective:e.ProjectionMode.Orthographic)}catch{}},[ae,l]);const Me=e=>{const t=o.current,n=a.current;if(t&&n?.viewer)try{const r=n.viewer.GetBoundingSphere?.(()=>!0);if(!r)return;const i=r.center,s=3*(r.radius||1),a=i.x??0,o=i.y??0,l=i.z??0;let c,d;switch(e){case"top":c=new t.Coord3D(a,o,l+s),d=new t.Coord3D(0,1,0);break;case"front":c=new t.Coord3D(a,o-s,l),d=new t.Coord3D(0,0,1);break;case"side":c=new t.Coord3D(a+s,o,l),d=new t.Coord3D(0,0,1);break;default:{const e=s/Math.sqrt(3);c=new t.Coord3D(a+e,o-e,l+e),d=new t.Coord3D(0,0,1);break}}const u=new t.Coord3D(a,o,l),p=new t.Camera(c,u,d,45);n.viewer.SetCamera(p),n.viewer.AdjustClippingPlanesToSphere?.(r),n.viewer.Render?.()}catch{}},Se=(t.split(".").pop()||"").toUpperCase(),ze=(e,t=0)=>{const n=e.children.length>0,r=!1!==P[e.id],i=!X.has(e.id);/* @__PURE__ */
85
85
  return H("div",{children:[
86
- /* @__PURE__ */H("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__ */I("button",{onClick:()=>{return t=e.id,void W(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?g.collapse:g.expand,children:/* @__PURE__ */I(R,r?{name:"chevron-down",fallback:E,className:"h-3 w-3",strokeWidth:2}:{name:"chevron-right",fallback:L,className:"h-3 w-3",strokeWidth:2})}):/* @__PURE__ */I("span",{className:"h-4 w-4 shrink-0 flex items-center justify-center",children:/* @__PURE__ */I("span",{className:"h-1 w-1 rounded-full bg-gray-400"})}),
86
+ /* @__PURE__ */H("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__ */I("button",{onClick:()=>{return t=e.id,void O(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?g.collapse:g.expand,children:/* @__PURE__ */I(R,r?{name:"chevron-down",fallback:E,className:"h-3 w-3",strokeWidth:2}:{name:"chevron-right",fallback:L,className:"h-3 w-3",strokeWidth:2})}):/* @__PURE__ */I("span",{className:"h-4 w-4 shrink-0 flex items-center justify-center",children:/* @__PURE__ */I("span",{className:"h-1 w-1 rounded-full bg-gray-400"})}),
87
87
  /* @__PURE__ */I("span",{className:"flex-1 truncate "+(i?"":"opacity-40"),title:e.name,children:e.name}),
88
88
  /* @__PURE__ */I("button",{onClick:()=>{Le()},className:"h-4 w-4 shrink-0 text-gray-400 hover:text-gray-900 opacity-0 group-hover:opacity-100 transition-opacity",title:g.fitToView,children:/* @__PURE__ */I(R,{name:"expand",fallback:b,className:"h-3.5 w-3.5",strokeWidth:1.5})}),
89
89
  /* @__PURE__ */I("button",{onClick:()=>Ee(e),className:"h-4 w-4 shrink-0 text-gray-500 hover:text-gray-900",title:i?g.hide:g.show,children:/* @__PURE__ */I(R,i?{name:"eye",fallback:M,className:"h-3.5 w-3.5",strokeWidth:1.5}:{name:"eye-off",fallback:S,className:"h-3.5 w-3.5",strokeWidth:1.5})})]}),r&&n&&/* @__PURE__ */I("div",{children:e.children.map(e=>ze(e,t+1))})]},e.id)},Te="h-8 w-8 shrink-0 flex items-center justify-center rounded text-gray-600 hover:bg-gray-200 hover:text-gray-900 transition-colors",Re="h-8 w-8 shrink-0 flex items-center justify-center rounded bg-gray-200 text-gray-900",je="h-5 w-px bg-gray-300 mx-1";/* @__PURE__ */
@@ -163,14 +163,14 @@ return H("div",{className:"flex flex-col h-full bg-white",children:[
163
163
  /* @__PURE__ */I("input",{type:"range",min:0,max:1,step:.01,value:he,onChange:e=>ye(Number(e.target.value)),className:"w-full accent-blue-500"})]})]})]})]}),
164
164
  /* @__PURE__ */I("div",{className:"px-3 py-2 border-t border-gray-200",children:/* @__PURE__ */I("button",{onClick:()=>{_("#f5f6f8"),q(!0),J("#000000"),te(1),ce(!1),ue("x"),me(!1),ye(.5),xe(0)},className:"w-full text-[11px] text-gray-700 bg-gray-100 hover:bg-gray-200 rounded py-1.5 transition-colors",children:g.resetDisplay})})]})]})})]})}function Q({url:e,filename:t,onDownload:i,onEmail:s}){const[a,o]=D(1),[l,c]=D(!1),[u,p]=D(!1),m=j(null),h=z().preview,y="px-2 py-1 rounded hover:bg-gray-200 transition-colors text-gray-600 flex items-center gap-1";/* @__PURE__ */
165
165
  return H("div",{className:"flex flex-col h-full",children:[
166
- /* @__PURE__ */H(n,{children:[!u&&/* @__PURE__ */H(O,{children:[
166
+ /* @__PURE__ */H(n,{children:[!u&&/* @__PURE__ */H(P,{children:[
167
167
  /* @__PURE__ */I("button",{onClick:()=>o(e=>Math.max(.1,Math.round(100*(e-.25))/100)),className:y,children:"−"}),
168
168
  /* @__PURE__ */H("span",{className:"text-gray-500 w-12 text-center tabular-nums",children:[Math.round(100*a),"%"]}),
169
169
  /* @__PURE__ */I("button",{onClick:()=>o(e=>Math.min(8,Math.round(100*(e+.25))/100)),className:y,children:"+"}),
170
170
  /* @__PURE__ */I("button",{onClick:()=>o(1),className:y,children:"1:1"}),
171
171
  /* @__PURE__ */I("div",{className:"h-4 w-px bg-gray-300 mx-1"}),
172
172
  /* @__PURE__ */H("button",{onClick:()=>p(!0),className:y,title:h.annotateHint,children:[
173
- /* @__PURE__ */I(R,{name:"edit",fallback:N,className:"h-3.5 w-3.5",strokeWidth:1.5}),h.annotate]})]}),u&&/* @__PURE__ */H(O,{children:[
173
+ /* @__PURE__ */I(R,{name:"edit",fallback:N,className:"h-3.5 w-3.5",strokeWidth:1.5}),h.annotate]})]}),u&&/* @__PURE__ */H(P,{children:[
174
174
  /* @__PURE__ */H("button",{onClick:()=>p(!1),className:y,title:h.viewHint,children:[
175
175
  /* @__PURE__ */I(R,{name:"chevron-left",fallback:C,className:"h-3.5 w-3.5",strokeWidth:1.5}),h.view]}),
176
176
  /* @__PURE__ */H("button",{onClick:()=>m.current?.copy(),className:y,children:[
@@ -1,19 +1,19 @@
1
- import{EditableGrid as e}from"./chunk-T4CFSGSL.js";import"./chunk-BR22X7E5.js";import{AboutApp as t}from"./chunk-MSIN5HKX.js";import{peekSpreadsheetPreviewStage as r,claimSpreadsheetPreviewStage as n,SPREADSHEET_PREVIEW_UPDATE_EVENT as o}from"./chunk-VTVSMRFX.js";import{WindowTitle as a}from"./chunk-SBDIHKLU.js";import"./chunk-DSSLOQDW.js";import"./chunk-GMMTTWHB.js";import"./chunk-OD5KLVU5.js";import"./chunk-PQLVWCUI.js";import"./chunk-5A7MWTXX.js";import"./chunk-OGXU7QFW.js";import"./chunk-ZZKIKW62.js";import"./chunk-ZDF5AR5W.js";import"./chunk-AFYQTVZO.js";import"./chunk-HZZNJHRH.js";import"./chunk-X4FJ54PP.js";import"./chunk-D65T4H6J.js";import"./chunk-XUF7VW4U.js";import"./chunk-J3LIIIHJ.js";import"./chunk-C3QOHMR6.js";import"./chunk-YKZHOXI4.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 k(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 w(){const m=l(null),g=l(void 0);void 0===g.current&&(g.current=r());const w=l(g.current?.data??null),N=(()=>{const e=g.current;if(!e)return null;const t=k(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,U]=s(0),M=l([]),$=l(C),L=l(!1);c(()=>{L.current?L.current=!1:$.current!==C&&(M.current.push($.current),M.current.length>50&&M.current.shift()),$.current=C},[C]);const D=i(()=>{const e=M.current.pop();e&&(L.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(),D())};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[D]);const[A,E]=s(N?.title??"Untitled"),[I,F]=s(()=>g.current?.data.onEmail),H=i(e=>{const t=k(e.csv,"Sheet 1");t&&(S([t]),U(0),E(e.filename.replace(/\.(csv|tsv|txt)$/i,"")),F(()=>e.onEmail))},[]);c(()=>{const e=g.current;null!=e&&(n(e),e.data!==w.current&&H(e.data))},[]),c(()=>{const e=g.current?.token;if(null==e)return;const t=t=>{const r=t.detail;r&&r.token===e&&H(r.data)};return window.addEventListener(o,t),()=>window.removeEventListener(o,t)},[]);const[K,R]=s(!1),[X,O]=s(null),[B,W]=s(""),Z=l(null),[T,V]=s("1"),[J,Q]=s("10"),P=C[j]||C[0],z=P.data,G=P.columns,Y=P.cellStyles??{},[_,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 _?[_]:[]},[ee,_]),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}:_,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!==G.length?se({data:e,columns:y(t)}):se({data:e})},[se,G.length]),ie=(e,t)=>{S(r=>r.map((r,n)=>n===e?{...r,name:t}:r)),O(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__ */
1
+ import{EditableGrid as e}from"./chunk-T4CFSGSL.js";import"./chunk-BR22X7E5.js";import{AboutApp as t}from"./chunk-TKUNR5KP.js";import{peekSpreadsheetPreviewStage as r,claimSpreadsheetPreviewStage as n,SPREADSHEET_PREVIEW_UPDATE_EVENT as o}from"./chunk-VTVSMRFX.js";import{WindowTitle as a}from"./chunk-SBDIHKLU.js";import"./chunk-DSSLOQDW.js";import"./chunk-GMMTTWHB.js";import"./chunk-YKHMAGEM.js";import"./chunk-PQLVWCUI.js";import"./chunk-5A7MWTXX.js";import"./chunk-OGXU7QFW.js";import"./chunk-ZZKIKW62.js";import"./chunk-ZDF5AR5W.js";import"./chunk-AFYQTVZO.js";import"./chunk-HZZNJHRH.js";import"./chunk-X4FJ54PP.js";import"./chunk-D65T4H6J.js";import"./chunk-XUF7VW4U.js";import"./chunk-J3LIIIHJ.js";import"./chunk-C3QOHMR6.js";import"./chunk-YKZHOXI4.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 k(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 w(){const m=l(null),g=l(void 0);void 0===g.current&&(g.current=r());const w=l(g.current?.data??null),N=(()=>{const e=g.current;if(!e)return null;const t=k(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,M]=s(0),U=l([]),$=l(C),A=l(!1);c(()=>{A.current?A.current=!1:$.current!==C&&(U.current.push($.current),U.current.length>50&&U.current.shift()),$.current=C},[C]);const E=i(()=>{const e=U.current.pop();e&&(A.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(),E())};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[E]);const[L,D]=s(N?.title??"Untitled"),[F,I]=s(()=>g.current?.data.onEmail),K=i(e=>{const t=k(e.csv,"Sheet 1");t&&(S([t]),M(0),D(e.filename.replace(/\.(csv|tsv|txt)$/i,"")),I(()=>e.onEmail))},[]);c(()=>{const e=g.current;null!=e&&(n(e),e.data!==w.current&&K(e.data))},[]),c(()=>{const e=g.current?.token;if(null==e)return;const t=t=>{const r=t.detail;r&&r.token===e&&K(r.data)};return window.addEventListener(o,t),()=>window.removeEventListener(o,t)},[]);const[R,H]=s(!1),[X,B]=s(null),[O,T]=s(""),W=l(null),[Z,V]=s("1"),[J,P]=s("10"),Q=C[j]||C[0],G=Q.data,z=Q.columns,Y=Q.cellStyles??{},[_,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 _?[_]:[]},[ee,_]),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}:_,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!==z.length?se({data:e,columns:y(t)}):se({data:e})},[se,z.length]),ie=(e,t)=>{S(r=>r.map((r,n)=>n===e?{...r,name:t}:r)),B(null)},ue=()=>G.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=[];G.forEach(e=>e.forEach(e=>{const t=parseFloat(e);!isNaN(t)&&e.trim()&&de.push(t)}));const he=G.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=A||"Untitled",me.length>24?`${me.slice(0,23)}…`:me} - Spreadsheets`}),
3
+ /* @__PURE__ */d(a,{title:`${me=L||"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:[K?/* @__PURE__ */d("input",{type:"text",value:A,onChange:e=>E(e.target.value),onBlur:()=>R(!1),onKeyDown:e=>{"Enter"===e.key&&R(!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:()=>R(!0),className:"text-sm font-medium text-gray-900 hover:text-blue-600 truncate max-w-[200px]",title:"Click to rename",children:A||"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:[R?/* @__PURE__ */d("input",{type:"text",value:L,onChange:e=>D(e.target.value),onBlur:()=>H(!1),onKeyDown:e=>{"Enter"===e.key&&H(!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:()=>H(!0),className:"text-sm font-medium text-gray-900 hover:text-blue-600 truncate max-w-[200px]",title:"Click to rename",children:L||"Untitled"}),
6
6
  /* @__PURE__ */d("div",{className:"h-4 w-px bg-gray-300"}),
7
- /* @__PURE__ */d("input",{ref:Z,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),U(0),E(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}),E(r)}Z.current&&(Z.current.value="")},className:"hidden"}),
8
- /* @__PURE__ */d("button",{onClick:()=>Z.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=`${A||"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"}),I&&/* @__PURE__ */d("button",{onClick:()=>I(ue(),`${A||"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:W,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),M(0),D(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}),D(r)}W.current&&(W.current.value="")},className:"hidden"}),
8
+ /* @__PURE__ */d("button",{onClick:()=>W.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=`${L||"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"}),F&&/* @__PURE__ */d("button",{onClick:()=>F(ue(),`${L||"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:T,onChange:e=>V(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=G.length+e;se({columns:y(t),data:z.map(t=>[...t,...Array(e).fill("")])})})(parseInt(T)||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:Z,onChange:e=>V(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=z.length+e;se({columns:y(t),data:G.map(t=>[...t,...Array(e).fill("")])})})(parseInt(Z)||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:J,onChange:e=>Q(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(J)||10,void se({data:[...z,...Array.from({length:e},()=>Array(G.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:J,onChange:e=>P(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(J)||10,void se({data:[...G,...Array.from({length:e},()=>Array(z.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:G,data:z,onChange:ce,onColumnsChange:e=>se({columns:e}),cellStyles:Y,onFocusChange:q,onSelectionChange:te,minRows:x,maxHeight:"100%"})}),
29
+ /* @__PURE__ */d("div",{className:"flex-1 min-h-0",children:/* @__PURE__ */d(e,{columns:z,data:G,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:()=>U(t),onDoubleClick:()=>{O(t),W(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&&U(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:X===t?/* @__PURE__ */d("input",{type:"text",value:B,onChange:e=>W(e.target.value),onBlur:()=>ie(t,B||e.name),onKeyDown:r=>{"Enter"===r.key&&ie(t,B||e.name),"Escape"===r.key&&O(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)]),U(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:()=>M(t),onDoubleClick:()=>{B(t),T(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&&M(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:X===t?/* @__PURE__ */d("input",{type:"text",value:O,onChange:e=>T(e.target.value),onBlur:()=>ie(t,O||e.name),onKeyDown:r=>{"Enter"===r.key&&ie(t,O||e.name),"Escape"===r.key&&B(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)]),M(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:[z.length," × ",G.length]})]})]})]});var me}export{w as default};
37
+ /* @__PURE__ */u("span",{children:[G.length," × ",z.length]})]})]})]});var me}export{w as default};
@@ -1,2 +1,2 @@
1
1
  "use client";
2
- export{openFilesInTrashMode,setFilesDemoTree}from"../chunk-P4SGJTK3.js";export{setBrowserStartUrl}from"../chunk-LWLCNQY7.js";export{BUILTIN_APP_INFO}from"../chunk-MSIN5HKX.js";import"../chunk-LMIQV3NB.js";import{setPdfPreview as e}from"../chunk-ESL5TDNA.js";export{setPdfPreview}from"../chunk-ESL5TDNA.js";import{setSpreadsheetPreview as t}from"../chunk-VTVSMRFX.js";export{setSpreadsheetPreview}from"../chunk-VTVSMRFX.js";import"../chunk-SBDIHKLU.js";import"../chunk-DSSLOQDW.js";import"../chunk-GMMTTWHB.js";import"../chunk-OD5KLVU5.js";import{toast_default as o}from"../chunk-3DGTIWZP.js";import"../chunk-PQLVWCUI.js";import"../chunk-5A7MWTXX.js";import"../chunk-OGXU7QFW.js";import"../chunk-ZZKIKW62.js";import"../chunk-ZDF5AR5W.js";import"../chunk-AFYQTVZO.js";import"../chunk-HZZNJHRH.js";import"../chunk-X4FJ54PP.js";import"../chunk-D65T4H6J.js";import"../chunk-XUF7VW4U.js";import{currentShellStrings as r}from"../chunk-J3LIIIHJ.js";import"../chunk-C3QOHMR6.js";import"../chunk-YKZHOXI4.js";import{lazy as n}from"react";function i(e){const t=/\.([a-z0-9]+)(?:[?#].*)?$/i.exec((e||"").trim());return t?t[1].toLowerCase():""}var s=/* @__PURE__ */new Set(["csv","tsv"]),c=/* @__PURE__ */new Set(["xlsx","xls","xlsm","ods"]),l=/* @__PURE__ */new Set(["png","jpg","jpeg","gif","webp","bmp","svg","avif"]),a=/* @__PURE__ */new Set(["step","stp","stl","obj","gltf","glb","3mf","iges","igs"]);function m(e){const t=i(e);return"pdf"===t?"pdf":"dxf"===t?"dxf":s.has(t)?"csv":l.has(t)?"image":a.has(t)?"3d":null}function p(e){window.open(e,"_blank","noopener,noreferrer")}async function u(e,t,o){if(t.fetchBlob)return(await t.fetchBlob(o)).text();const r=await fetch(e);if(!r.ok)throw new Error(`fetch failed: ${r.status}`);return r.text()}function d(e,t){return(e instanceof Error?e.message:"")||t}async function h(n,s,l={}){const a=r().attachment,h=n?.url||"",f=n?.filename||a.fallbackName;if(!h&&!l.fetchBlob)return void o.error(a.noLink);const j=m(f)??m(h);if("csv"===j){try{t({csv:await u(h,l,n),filename:f}),s("/spreadsheet")}catch{o.error(a.spreadsheetFailed),h&&p(h)}return}if(c.has(i(f)||i(h)))return o.error(a.workbookUnavailable),void(h&&p(h));if(!j)return h?(o.info(a.noViewer),void p(h)):void o.error(a.noLink);if(!l.fetchBlob)return e({url:h,filename:f,kind:j}),void s("/preview");const k=e({filename:f,kind:j,converting:!0,convertingMessage:l.loadingMessage||a.loading});s("/preview");try{const e=await l.fetchBlob(n);k.update({url:URL.createObjectURL(e),filename:f,kind:j})}catch(e){k.update({filename:f,kind:j,converting:!1,convertingMessage:d(e,a.loadFailed)})}}var f=n(()=>import("../Calculator-4K53PFBL.js")),j=n(()=>import("../Spreadsheet-7NUDGOSX.js")),k=n(()=>import("../Weather-S3N5OWYF.js")),w=n(()=>import("../CurrencyConverter-QEG6RFAS.js")),g=n(()=>import("../PomodoroTimer-T6YAQFIE.js")),S=n(()=>import("../Notepad-CNZEWFCR.js")),v=n(()=>import("../WorldClock-ACC3S6OA.js")),b=n(()=>import("../Stock-BZFC2ROU.js")),I=n(()=>import("../Preview-OOVIIQQG.js")),F=n(()=>import("../PdfViewer-UZGDE4HD.js")),x=n(()=>import("../Documents-SFNMDRYU.js")),y=n(()=>import("../Files-OX2UBSQQ.js")),T=n(()=>import("../Browser-QYHW6I6J.js")),P={"/calculator":{component:f,label:"Calculator",size:"sm",allowPinOnTop:!0,utility:!0,widget:!0,dimensions:[280,420]},"/spreadsheet":{component:j,label:"Spreadsheets",size:"2xl",appStyle:!0,multiInstance:!0},"/notepad":{component:S,label:"Notepad",size:"lg",allowPinOnTop:!0,flushBody:!0},"/weather":{component:k,label:"Weather",size:"sm",utility:!0,widget:!0,autoHeight:!0,dimensions:[320,400]},"/currency":{component:w,label:"Currency Converter",size:"sm",utility:!0,widget:!0,autoHeight:!0,dimensions:[320,480]},"/pomodoro":{component:g,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]}},C={"/preview":{component:I,label:"Preview",size:"2xl",appStyle:!0,multiInstance:!0},"/documents":{component:x,label:"Documents",size:"xl",appStyle:!0,multiInstance:!0},"/files":{component:y,label:"Files",size:"xl",appStyle:!0}},L={"/browser":{component:T,label:"Browser",size:"2xl",appStyle:!0,multiInstance:!0}},O={...P,...C,...L};export{T as Browser,f as Calculator,w as CurrencyConverter,x as Documents,y as Files,S as Notepad,F as PdfViewer,g as PomodoroTimer,I as Preview,j as Spreadsheet,b as Stock,k as Weather,v as WorldClock,m as attachmentKind,O as bundledApps,C as documentApps,h as openAttachment,P as utilityApps,L as webApps};
2
+ export{openFilesInTrashMode,setFilesDemoTree}from"../chunk-P4SGJTK3.js";export{setBrowserStartUrl}from"../chunk-LWLCNQY7.js";export{BUILTIN_APP_INFO}from"../chunk-TKUNR5KP.js";import"../chunk-LMIQV3NB.js";import{setPdfPreview as e}from"../chunk-ESL5TDNA.js";export{setPdfPreview}from"../chunk-ESL5TDNA.js";import{setSpreadsheetPreview as t}from"../chunk-VTVSMRFX.js";export{setSpreadsheetPreview}from"../chunk-VTVSMRFX.js";import"../chunk-SBDIHKLU.js";import"../chunk-DSSLOQDW.js";import"../chunk-GMMTTWHB.js";import"../chunk-YKHMAGEM.js";import{toast_default as o}from"../chunk-3DGTIWZP.js";import"../chunk-PQLVWCUI.js";import"../chunk-5A7MWTXX.js";import"../chunk-OGXU7QFW.js";import"../chunk-ZZKIKW62.js";import"../chunk-ZDF5AR5W.js";import"../chunk-AFYQTVZO.js";import"../chunk-HZZNJHRH.js";import"../chunk-X4FJ54PP.js";import"../chunk-D65T4H6J.js";import"../chunk-XUF7VW4U.js";import{currentShellStrings as r}from"../chunk-J3LIIIHJ.js";import"../chunk-C3QOHMR6.js";import"../chunk-YKZHOXI4.js";import{lazy as n}from"react";function i(e){const t=/\.([a-z0-9]+)(?:[?#].*)?$/i.exec((e||"").trim());return t?t[1].toLowerCase():""}var s=/* @__PURE__ */new Set(["csv","tsv"]),c=/* @__PURE__ */new Set(["xlsx","xls","xlsm","ods"]),l=/* @__PURE__ */new Set(["png","jpg","jpeg","gif","webp","bmp","svg","avif"]),a=/* @__PURE__ */new Set(["step","stp","stl","obj","gltf","glb","3mf","iges","igs"]);function m(e){const t=i(e);return"pdf"===t?"pdf":"dxf"===t?"dxf":s.has(t)?"csv":l.has(t)?"image":a.has(t)?"3d":null}function p(e){window.open(e,"_blank","noopener,noreferrer")}async function u(e,t,o){if(t.fetchBlob)return(await t.fetchBlob(o)).text();const r=await fetch(e);if(!r.ok)throw new Error(`fetch failed: ${r.status}`);return r.text()}function d(e,t){return(e instanceof Error?e.message:"")||t}async function h(n,s,l={}){const a=r().attachment,h=n?.url||"",f=n?.filename||a.fallbackName;if(!h&&!l.fetchBlob)return void o.error(a.noLink);const j=m(f)??m(h);if("csv"===j){try{t({csv:await u(h,l,n),filename:f}),s("/spreadsheet")}catch{o.error(a.spreadsheetFailed),h&&p(h)}return}if(c.has(i(f)||i(h)))return o.error(a.workbookUnavailable),void(h&&p(h));if(!j)return h?(o.info(a.noViewer),void p(h)):void o.error(a.noLink);if(!l.fetchBlob)return e({url:h,filename:f,kind:j}),void s("/preview");const k=e({filename:f,kind:j,converting:!0,convertingMessage:l.loadingMessage||a.loading});s("/preview");try{const e=await l.fetchBlob(n);k.update({url:URL.createObjectURL(e),filename:f,kind:j})}catch(e){k.update({filename:f,kind:j,converting:!1,convertingMessage:d(e,a.loadFailed)})}}var f=n(()=>import("../Calculator-4K53PFBL.js")),j=n(()=>import("../Spreadsheet-HKXSYD5B.js")),k=n(()=>import("../Weather-S3N5OWYF.js")),w=n(()=>import("../CurrencyConverter-QEG6RFAS.js")),g=n(()=>import("../PomodoroTimer-T6YAQFIE.js")),S=n(()=>import("../Notepad-KNJRTYXR.js")),v=n(()=>import("../WorldClock-ACC3S6OA.js")),b=n(()=>import("../Stock-BZFC2ROU.js")),F=n(()=>import("../Preview-KEIDYSHF.js")),T=n(()=>import("../PdfViewer-UZGDE4HD.js")),x=n(()=>import("../Documents-6DEUZVVA.js")),y=n(()=>import("../Files-2VSFXA45.js")),I=n(()=>import("../Browser-5F5LWXYQ.js")),P={"/calculator":{component:f,label:"Calculator",size:"sm",allowPinOnTop:!0,utility:!0,widget:!0,dimensions:[280,420]},"/spreadsheet":{component:j,label:"Spreadsheets",size:"2xl",appStyle:!0,multiInstance:!0},"/notepad":{component:S,label:"Notepad",size:"lg",allowPinOnTop:!0,flushBody:!0},"/weather":{component:k,label:"Weather",size:"sm",utility:!0,widget:!0,autoHeight:!0,dimensions:[320,400]},"/currency":{component:w,label:"Currency Converter",size:"sm",utility:!0,widget:!0,autoHeight:!0,dimensions:[320,480]},"/pomodoro":{component:g,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]}},H={"/preview":{component:F,label:"Preview",size:"2xl",appStyle:!0,multiInstance:!0},"/documents":{component:x,label:"Documents",size:"xl",appStyle:!0,multiInstance:!0},"/files":{component:y,label:"Files",size:"xl",appStyle:!0}},L={"/browser":{component:I,label:"Browser",size:"2xl",appStyle:!0,multiInstance:!0}},B={...P,...H,...L};export{I as Browser,f as Calculator,w as CurrencyConverter,x as Documents,y as Files,S as Notepad,T as PdfViewer,g as PomodoroTimer,F as Preview,j as Spreadsheet,b as Stock,k as Weather,v as WorldClock,m as attachmentKind,B as bundledApps,H as documentApps,h as openAttachment,P as utilityApps,L as webApps};