efficient-shell 12.33.0 → 12.34.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.
Files changed (38) hide show
  1. package/dist/{Browser-TYVPZ2NT.js → Browser-SBOULR4U.js} +15 -15
  2. package/dist/{Files-VUZWJMCE.js → Files-UYO4JLEB.js} +79 -79
  3. package/dist/{Notepad-LXLUGQUN.js → Notepad-C44EOSDD.js} +8 -8
  4. package/dist/{Preview-VRYWLVJY.js → Preview-32K62K27.js} +14 -14
  5. package/dist/ai/index.js +1 -1
  6. package/dist/apps/index.js +1 -1
  7. package/dist/bin/media-host-check.js +1 -1
  8. package/dist/bin/ui-check.js +1 -1
  9. package/dist/charts/PieChart.js +1 -1
  10. package/dist/charts/RadarChart.js +1 -1
  11. package/dist/charts/RadialBarChart.js +1 -1
  12. package/dist/charts/SpecChart.js +1 -1
  13. package/dist/charts/TimeSeriesChart.js +1 -1
  14. package/dist/chunk-56UUJIC4.js +1 -0
  15. package/dist/{chunk-DYOFTZOC.js → chunk-CUJA3HBZ.js} +2 -2
  16. package/dist/{chunk-JTMR3EH3.js → chunk-JZY2RBPX.js} +6 -6
  17. package/dist/{chunk-E6PDAYBR.js → chunk-O5UD3ZWM.js} +4 -4
  18. package/dist/{chunk-XBX3N3VG.js → chunk-OMD5FXGO.js} +2 -2
  19. package/dist/{chunk-DGFFDZCY.js → chunk-OZV5P5A7.js} +5 -5
  20. package/dist/{chunk-XYMEC63O.js → chunk-RUOM4KKK.js} +1 -1
  21. package/dist/{chunk-KZQRUVII.js → chunk-TZBNN6HD.js} +5 -5
  22. package/dist/{chunk-EEFUXXYJ.js → chunk-UF76AFFY.js} +13 -13
  23. package/dist/{chunk-WKWZILZA.js → chunk-VRRPYADW.js} +2 -2
  24. package/dist/{chunk-LPAOHDUE.js → chunk-WAKWESOR.js} +1 -1
  25. package/dist/{chunk-APGIPXR7.js → chunk-YHABPVWU.js} +2 -2
  26. package/dist/data/Gantt.js +1 -1
  27. package/dist/forms/BrandAssetEditor.js +1 -1
  28. package/dist/forms/MediaLibrary.js +1 -1
  29. package/dist/icons/index.js +1 -1
  30. package/dist/index.js +85 -85
  31. package/dist/shell/LanguageSelect.js +1 -1
  32. package/dist/shell/SettingRow.js +1 -1
  33. package/dist/telemetry/index.js +1 -1
  34. package/dist/templates/DashboardTemplate.js +1 -1
  35. package/dist/ui/index.js +1 -1
  36. package/dist/version.js +1 -1
  37. package/package.json +1 -1
  38. package/dist/chunk-LSONG4QV.js +0 -1
@@ -1,8 +1,8 @@
1
- import{getNumberingConfigs as e}from"./chunk-QDIPNQ6M.js";import{SidebarLayout as t}from"./chunk-6D6Q3ZCG.js";import"./chunk-QWK6DRSN.js";import"./chunk-PC3MYH2K.js";import{timeAgo as r}from"./chunk-GEYM4WN3.js";import"./chunk-Y3JW2GW5.js";import"./chunk-36BRD5J3.js";import"./chunk-LF27WIN2.js";import{AboutApp as n}from"./chunk-WKWZILZA.js";import{useWindowManager as o,client_default as i}from"./chunk-FCILLVVT.js";import"./chunk-4LXCCZDM.js";import"./chunk-AW7TOB6N.js";import"./chunk-KNUR2UEG.js";import"./chunk-JDCM2VHG.js";import"./chunk-DASRJ26L.js";import"./chunk-ZDMZM7HD.js";import"./chunk-5A7MWTXX.js";import"./chunk-GHLXZDLU.js";import"./chunk-KV6XCHAG.js";import"./chunk-B447IHIL.js";import"./chunk-EIFNESXS.js";import"./chunk-PR6FNBKR.js";import"./chunk-RIG5FEVS.js";import"./chunk-NDWX5Z4D.js";import"./chunk-VWGWZY7A.js";import"./chunk-7QSDPSXP.js";import"./chunk-ZGIAMYTI.js";import"./chunk-5LHEPE4B.js";import"./chunk-F3ZOO23R.js";import"./chunk-2QY5BJLA.js";import"./chunk-UGTRSRIW.js";import{useShellPrefs as c}from"./chunk-KC3EX26K.js";import"./chunk-LSONG4QV.js";import"./chunk-DWGYC7OD.js";import"./chunk-JMGDGNM7.js";import"./chunk-GOAFMGUI.js";import"./chunk-URHGHXDN.js";import"./chunk-5QFPTDQF.js";import"./chunk-EVYD6UFQ.js";import"./chunk-M5K4AX4E.js";import{Icon as s}from"./chunk-ISVODSRP.js";import"./chunk-J75ZT2JQ.js";import"./chunk-R2VKEMZH.js";import"./chunk-G67CJAQ2.js";import"./chunk-SOZCWT6I.js";import"./chunk-PGN5ME7B.js";import"./chunk-62LW225J.js";import"./chunk-GLUJS42B.js";import"./chunk-D65T4H6J.js";import"./chunk-STKJA4PV.js";import{toast_default as l}from"./chunk-TMSSR5UH.js";import"./chunk-UQYNPYF4.js";import"./chunk-MRJKZWWV.js";import"./chunk-TWVUQUUD.js";import"./chunk-5FYDNH4Y.js";import"./chunk-LNXBTK7Q.js";import"./chunk-DEJIH3ZQ.js";import"./chunk-C3QOHMR6.js";import{useRef as a,useEffect as p,useState as d,useCallback as m}from"react";import{useQuery as u}from"@tanstack/react-query";import{jsxs as h,Fragment as g,jsx as x}from"react/jsx-runtime";var y=[{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 k={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/"}},b=/\[([ xX]?)\]/g;function f(){const{openEntity:f}=o(),{prefs:j,save:N}=c(),{data:v}=u({queryKey:["numbering-configs"],queryFn:()=>e(),retry:!1}),w=a({});p(()=>{if(!v)return;const e={};for(const t of v){const r=k[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})}}w.current=e},[v]);const T=j.notepad_notes||[],[_,D]=d(null),[S,W]=d(""),[C,G]=d(""),[I,M]=d("yellow"),[X,$]=d(!1),[Q,Z]=d(!1),E=a(null),L=a();p(()=>{if(!_&&T.length>0){const e=T[0];D(e.id),W(e.title),G(e.content),M(e.color)}},[T.length]);const R=m(e=>{N({notepad_notes:e})},[N]),U=m(()=>{if(!_||!X)return;const e=T.map(e=>e.id===_?{...e,title:S,content:C,color:I,updated_at:/* @__PURE__ */(new Date).toISOString()}:e);R(e),$(!1)},[_,X,S,C,I,T,R]);p(()=>{if(X)return L.current&&clearTimeout(L.current),L.current=setTimeout(U,800),()=>{L.current&&clearTimeout(L.current)}},[X,U]),p(()=>()=>{X&&U()},[]);const H=e=>{X&&U(),D(e.id),W(e.title),G(e.content),M(e.color),$(!1),Z(!1)},J=e=>{const t=C.slice(0,e),r=C.slice(e).match(/^\[([ xX]?)\]/);if(!r)return;const n="x"===r[1]||"X"===r[1]?"[ ]":"[x]",o=C.slice(e+r[0].length);G(t+n+o),$(!0)},K=async(e,t)=>{const r=w.current[e];if(!r)return;const n=`${e}#${t}`;try{const{data:e}=await i.get(r.endpoint,{params:{search:n,page_size:1}}),t=(e?.results??e??[])[0];t?f(r.entityType,t.id,t,n):l.error(`${n} not found`)}catch{l.error(`Failed to look up ${n}`)}},O="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.)",F=/* @__PURE__ */h(g,{children:[
2
- /* @__PURE__ */x("div",{className:"p-2 border-b border-gray-200",children:/* @__PURE__ */h("button",{onClick:()=>{X&&U();const e={id:`note-${Date.now()}-${Math.random().toString(36).slice(2,6)}`,title:"",content:"",color:"yellow",updated_at:/* @__PURE__ */(new Date).toISOString()},t=[e,...T];R(t),D(e.id),W(""),G(""),M("yellow"),$(!1),Z(!0),setTimeout(()=>E.current?.focus(),50)},className:"w-full flex items-center justify-center gap-2 rounded-lg bg-accent-fill text-on-accent px-3 min-h-8 py-1 text-sm font-medium hover:bg-accent-fill-hover transition-colors",children:[
1
+ import{getNumberingConfigs as e}from"./chunk-QDIPNQ6M.js";import{SidebarLayout as t}from"./chunk-6D6Q3ZCG.js";import"./chunk-QWK6DRSN.js";import"./chunk-PC3MYH2K.js";import{timeAgo as r}from"./chunk-GEYM4WN3.js";import"./chunk-Y3JW2GW5.js";import"./chunk-36BRD5J3.js";import"./chunk-LF27WIN2.js";import{AboutApp as n}from"./chunk-VRRPYADW.js";import{useWindowManager as o,client_default as i}from"./chunk-FCILLVVT.js";import"./chunk-4LXCCZDM.js";import"./chunk-AW7TOB6N.js";import"./chunk-KNUR2UEG.js";import"./chunk-JDCM2VHG.js";import"./chunk-DASRJ26L.js";import"./chunk-ZDMZM7HD.js";import"./chunk-5A7MWTXX.js";import"./chunk-GHLXZDLU.js";import"./chunk-KV6XCHAG.js";import"./chunk-B447IHIL.js";import"./chunk-EIFNESXS.js";import"./chunk-PR6FNBKR.js";import"./chunk-RIG5FEVS.js";import"./chunk-NDWX5Z4D.js";import"./chunk-VWGWZY7A.js";import"./chunk-7QSDPSXP.js";import"./chunk-ZGIAMYTI.js";import"./chunk-5LHEPE4B.js";import"./chunk-F3ZOO23R.js";import"./chunk-2QY5BJLA.js";import"./chunk-UGTRSRIW.js";import{useShellPrefs as c}from"./chunk-KC3EX26K.js";import"./chunk-56UUJIC4.js";import"./chunk-DWGYC7OD.js";import"./chunk-JMGDGNM7.js";import"./chunk-GOAFMGUI.js";import"./chunk-URHGHXDN.js";import"./chunk-5QFPTDQF.js";import"./chunk-EVYD6UFQ.js";import"./chunk-M5K4AX4E.js";import{Icon as s}from"./chunk-ISVODSRP.js";import"./chunk-J75ZT2JQ.js";import"./chunk-R2VKEMZH.js";import"./chunk-G67CJAQ2.js";import"./chunk-SOZCWT6I.js";import"./chunk-PGN5ME7B.js";import"./chunk-62LW225J.js";import"./chunk-GLUJS42B.js";import"./chunk-D65T4H6J.js";import"./chunk-STKJA4PV.js";import{toast_default as l}from"./chunk-TMSSR5UH.js";import"./chunk-UQYNPYF4.js";import"./chunk-MRJKZWWV.js";import"./chunk-TWVUQUUD.js";import"./chunk-5FYDNH4Y.js";import"./chunk-LNXBTK7Q.js";import"./chunk-DEJIH3ZQ.js";import"./chunk-C3QOHMR6.js";import{useRef as a,useEffect as p,useState as d,useCallback as m}from"react";import{useQuery as u}from"@tanstack/react-query";import{jsxs as h,Fragment as g,jsx as x}from"react/jsx-runtime";var y=[{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 k={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/"}},b=/\[([ xX]?)\]/g;function f(){const{openEntity:f}=o(),{prefs:j,save:N}=c(),{data:v}=u({queryKey:["numbering-configs"],queryFn:()=>e(),retry:!1}),w=a({});p(()=>{if(!v)return;const e={};for(const t of v){const r=k[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})}}w.current=e},[v]);const T=j.notepad_notes||[],[_,D]=d(null),[C,S]=d(""),[W,G]=d(""),[I,M]=d("yellow"),[X,$]=d(!1),[R,U]=d(!1),E=a(null),J=a();p(()=>{if(!_&&T.length>0){const e=T[0];D(e.id),S(e.title),G(e.content),M(e.color)}},[T.length]);const Q=m(e=>{N({notepad_notes:e})},[N]),H=m(()=>{if(!_||!X)return;const e=T.map(e=>e.id===_?{...e,title:C,content:W,color:I,updated_at:/* @__PURE__ */(new Date).toISOString()}:e);Q(e),$(!1)},[_,X,C,W,I,T,Q]);p(()=>{if(X)return J.current&&clearTimeout(J.current),J.current=setTimeout(H,800),()=>{J.current&&clearTimeout(J.current)}},[X,H]),p(()=>()=>{X&&H()},[]);const Z=e=>{X&&H(),D(e.id),S(e.title),G(e.content),M(e.color),$(!1),U(!1)},F=e=>{const t=W.slice(0,e),r=W.slice(e).match(/^\[([ xX]?)\]/);if(!r)return;const n="x"===r[1]||"X"===r[1]?"[ ]":"[x]",o=W.slice(e+r[0].length);G(t+n+o),$(!0)},K=async(e,t)=>{const r=w.current[e];if(!r)return;const n=`${e}#${t}`;try{const{data:e}=await i.get(r.endpoint,{params:{search:n,page_size:1}}),t=(e?.results??e??[])[0];t?f(r.entityType,t.id,t,n):l.error(`${n} not found`)}catch{l.error(`Failed to look up ${n}`)}},L="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.)",O=/* @__PURE__ */h(g,{children:[
2
+ /* @__PURE__ */x("div",{className:"p-2 border-b border-gray-200",children:/* @__PURE__ */h("button",{onClick:()=>{X&&H();const e={id:`note-${Date.now()}-${Math.random().toString(36).slice(2,6)}`,title:"",content:"",color:"yellow",updated_at:/* @__PURE__ */(new Date).toISOString()},t=[e,...T];Q(t),D(e.id),S(""),G(""),M("yellow"),$(!1),U(!0),setTimeout(()=>E.current?.focus(),50)},className:"w-full flex items-center justify-center gap-2 rounded-lg bg-accent-fill text-on-accent px-3 min-h-8 py-1 text-sm font-medium hover:bg-accent-fill-hover transition-colors",children:[
3
3
  /* @__PURE__ */x(s,{name:"add",className:"h-4 w-4",strokeWidth:2}),"New Note"]})}),
4
4
  /* @__PURE__ */x("div",{className:"flex-1 overflow-y-auto",children:0===T.length?/* @__PURE__ */x("p",{className:"text-sm text-gray-400 text-center py-8 px-4",children:"No notes yet. Create one to get started."}):T.map(e=>{const t=(n=e.color,y.find(e=>e.key===n)||y[0]);var n;/* @__PURE__ */
5
- return h("button",{onClick:()=>H(e),className:"w-full text-left px-3 py-3 border-b border-line-subtle transition-colors "+(_===e.id?"bg-accent-tint":"hover:bg-row-hover"),children:[
5
+ return h("button",{onClick:()=>Z(e),className:"w-full text-left px-3 py-3 border-b border-line-subtle transition-colors "+(_===e.id?"bg-accent-tint":"hover:bg-row-hover"),children:[
6
6
  /* @__PURE__ */h("div",{className:"flex items-center gap-2",children:[
7
7
  /* @__PURE__ */x("div",{className:`w-3 h-3 rounded-full shrink-0 ${t.dot}`}),
8
8
  /* @__PURE__ */x("span",{className:"text-sm font-medium text-gray-900 truncate flex-1",children:e.title||"Untitled"})]}),
@@ -10,15 +10,15 @@ return h("button",{onClick:()=>H(e),className:"w-full text-left px-3 py-3 border
10
10
  /* @__PURE__ */x("p",{className:"text-2xs text-gray-300 mt-0.5 ml-5",children:r(e.updated_at)})]},e.id)})})]});/* @__PURE__ */
11
11
  return h("div",{className:"h-full",children:[
12
12
  /* @__PURE__ */x(n,{app:"notepad"}),
13
- /* @__PURE__ */x(t,{sidebar:F,storageKey:"notepad.sidebarWidth",defaultWidth:224,minWidth:180,maxWidth:360,children:_?/* @__PURE__ */h("div",{className:"flex-1 flex flex-col min-w-0",children:[
13
+ /* @__PURE__ */x(t,{sidebar:O,storageKey:"notepad.sidebarWidth",defaultWidth:224,minWidth:180,maxWidth:360,children:_?/* @__PURE__ */h("div",{className:"flex-1 flex flex-col min-w-0",children:[
14
14
  /* @__PURE__ */h("div",{className:"flex items-center gap-2 px-4 py-2 border-b border-gray-200",children:[
15
- /* @__PURE__ */x("input",{value:S,onChange:e=>{W(e.target.value),$(!0)},placeholder:"Note title...",className:"flex-1 text-lg font-semibold text-gray-900 outline-none bg-transparent placeholder:text-gray-300"}),
15
+ /* @__PURE__ */x("input",{value:C,onChange:e=>{S(e.target.value),$(!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__ */x("div",{className:"flex gap-1",children:y.map(e=>/* @__PURE__ */x("button",{onClick:()=>{M(e.key),$(!0)},className:`w-5 h-5 rounded-full border-2 transition-all ${e.dot} ${I===e.key?"border-gray-600 scale-110":"border-transparent hover:border-gray-400"}`,title:e.key},e.key))}),
17
- /* @__PURE__ */x("button",{onClick:()=>(e=>{const t=T.filter(t=>t.id!==e);if(R(t),_===e){const e=t[0];e?H(e):(D(null),W(""),G(""))}})(_),title:"Delete note",className:"p-1 rounded text-gray-300 hover:text-red-500 transition-colors",children:/* @__PURE__ */x(s,{name:"trash",className:"h-4 w-4",strokeWidth:1.5})})]}),Q?/* @__PURE__ */x("textarea",{ref:E,value:C,onChange:e=>{G(e.target.value),$(!0)},onBlur:()=>{Z(!1),X&&U()},placeholder:O,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__ */x("div",{onClick:()=>{Z(!0),setTimeout(()=>E.current?.focus(),50)},className:"flex-1 p-4 text-sm text-gray-700 overflow-y-auto leading-relaxed cursor-text",children:C?(e=>{if(!e)return[];const t=e.split("\n");return t.map((e,r)=>{const n=[];let o=0;const i=[],c=/([A-Z]{2,4})#(\d{4,6})/g;let l;for(;null!==(l=c.exec(e));){const e=l[1],t=l[2];if(w.current[e]){const n=l.index,o=l[0];i.push({idx:n,len:o.length,render:()=>/* @__PURE__ */x("button",{onClick:()=>K(e,t),className:"text-blue-600 hover:text-blue-800 hover:underline font-medium cursor-pointer",children:o},`ref-${r}-${n}`)})}}b.lastIndex=0;let a=0;for(let e=0;e<r;e++)a+=t[e].length+1;for(;null!==(l=b.exec(e));){const e="x"===l[1]||"X"===l[1],t=l.index,n=a+t;i.push({idx:t,len:l[0].length,render:()=>/* @__PURE__ */x("button",{onClick:()=>J(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__ */x(s,{name:"check",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__ */x("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__ */x("span",{children:e.slice(o)},`t-${r}-${o}`)),0===n.length&&n.push(/* @__PURE__ */x("span",{children:"​"},`empty-${r}`));const p=/^\[x\]/i.test(e.trimStart());/* @__PURE__ */
18
- return x("div",{className:p?"line-through text-gray-400":"",children:n},r)})})(C):/* @__PURE__ */x("p",{className:"text-gray-300 whitespace-pre-line",children:O})}),
17
+ /* @__PURE__ */x("button",{onClick:()=>(e=>{const t=T.filter(t=>t.id!==e);if(Q(t),_===e){const e=t[0];e?Z(e):(D(null),S(""),G(""))}})(_),title:"Delete note",className:"p-1 rounded text-gray-300 hover:text-red-500 transition-colors",children:/* @__PURE__ */x(s,{name:"trash",className:"h-4 w-4",strokeWidth:1.5})})]}),R?/* @__PURE__ */x("textarea",{ref:E,value:W,onChange:e=>{G(e.target.value),$(!0)},onBlur:()=>{U(!1),X&&H()},placeholder:L,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__ */x("div",{onClick:()=>{U(!0),setTimeout(()=>E.current?.focus(),50)},className:"flex-1 p-4 text-sm text-gray-700 overflow-y-auto leading-relaxed cursor-text",children:W?(e=>{if(!e)return[];const t=e.split("\n");return t.map((e,r)=>{const n=[];let o=0;const i=[],c=/([A-Z]{2,4})#(\d{4,6})/g;let l;for(;null!==(l=c.exec(e));){const e=l[1],t=l[2];if(w.current[e]){const n=l.index,o=l[0];i.push({idx:n,len:o.length,render:()=>/* @__PURE__ */x("button",{onClick:()=>K(e,t),className:"text-blue-600 hover:text-blue-800 hover:underline font-medium cursor-pointer",children:o},`ref-${r}-${n}`)})}}b.lastIndex=0;let a=0;for(let e=0;e<r;e++)a+=t[e].length+1;for(;null!==(l=b.exec(e));){const e="x"===l[1]||"X"===l[1],t=l.index,n=a+t;i.push({idx:t,len:l[0].length,render:()=>/* @__PURE__ */x("button",{onClick:()=>F(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__ */x(s,{name:"check",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__ */x("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__ */x("span",{children:e.slice(o)},`t-${r}-${o}`)),0===n.length&&n.push(/* @__PURE__ */x("span",{children:"​"},`empty-${r}`));const p=/^\[x\]/i.test(e.trimStart());/* @__PURE__ */
18
+ return x("div",{className:p?"line-through text-gray-400":"",children:n},r)})})(W):/* @__PURE__ */x("p",{className:"text-gray-300 whitespace-pre-line",children:L})}),
19
19
  /* @__PURE__ */h("div",{className:"px-4 min-h-8 py-1 border-t border-line-subtle flex items-center gap-4 text-2xs text-ink-faintest",children:[
20
20
  /* @__PURE__ */x("span",{children:"[] checkbox"}),
21
21
  /* @__PURE__ */x("span",{children:"SO#35001 entity link"}),
22
- /* @__PURE__ */x("span",{className:"ml-auto",children:Q?"Editing":"Click to edit"})]})]}):/* @__PURE__ */x("div",{className:"flex-1 flex items-center justify-center",children:/* @__PURE__ */h("div",{className:"text-center text-gray-400",children:[
22
+ /* @__PURE__ */x("span",{className:"ml-auto",children:R?"Editing":"Click to edit"})]})]}):/* @__PURE__ */x("div",{className:"flex-1 flex items-center justify-center",children:/* @__PURE__ */h("div",{className:"text-center text-gray-400",children:[
23
23
  /* @__PURE__ */x(s,{name:"page",className:"h-12 w-12 mx-auto mb-3 text-gray-300",strokeWidth:1}),
24
24
  /* @__PURE__ */x("p",{className:"text-sm",children:"Select a note or create a new one"})]})})})]})}export{f as default};
@@ -1,14 +1,14 @@
1
- import{PdfViewer as e,ToolbarSlotContext as t,PanelActions as n}from"./chunk-44ZHEIJZ.js";import{IconButton_default as r}from"./chunk-SV5RRBVA.js";import{ImageAnnotator_default as s}from"./chunk-EQFWFQOZ.js";import{AboutApp as i}from"./chunk-WKWZILZA.js";import{peekPdfPreviewStage as o,claimPdfPreviewStage as a,PDF_PREVIEW_UPDATE_EVENT as l,previewStepForKey as c}from"./chunk-I4RJAMLJ.js";import{WindowTitle as d}from"./chunk-FCILLVVT.js";import"./chunk-4LXCCZDM.js";import"./chunk-AW7TOB6N.js";import"./chunk-KNUR2UEG.js";import"./chunk-JDCM2VHG.js";import"./chunk-DASRJ26L.js";import"./chunk-ZDMZM7HD.js";import"./chunk-5A7MWTXX.js";import"./chunk-GHLXZDLU.js";import"./chunk-KV6XCHAG.js";import"./chunk-B447IHIL.js";import"./chunk-EIFNESXS.js";import"./chunk-PR6FNBKR.js";import"./chunk-RIG5FEVS.js";import"./chunk-NDWX5Z4D.js";import"./chunk-VWGWZY7A.js";import"./chunk-7QSDPSXP.js";import"./chunk-ZGIAMYTI.js";import"./chunk-5LHEPE4B.js";import{getActiveModalId as u}from"./chunk-F3ZOO23R.js";import"./chunk-2QY5BJLA.js";import"./chunk-UGTRSRIW.js";import"./chunk-KC3EX26K.js";import"./chunk-LSONG4QV.js";import"./chunk-DWGYC7OD.js";import"./chunk-JMGDGNM7.js";import"./chunk-GOAFMGUI.js";import"./chunk-URHGHXDN.js";import"./chunk-5QFPTDQF.js";import"./chunk-EVYD6UFQ.js";import"./chunk-M5K4AX4E.js";import{Icon as p}from"./chunk-ISVODSRP.js";import"./chunk-J75ZT2JQ.js";import{SpinnerRing as m,LoadingSpinner as h}from"./chunk-R2VKEMZH.js";import"./chunk-G67CJAQ2.js";import"./chunk-SOZCWT6I.js";import"./chunk-PGN5ME7B.js";import"./chunk-62LW225J.js";import"./chunk-GLUJS42B.js";import"./chunk-D65T4H6J.js";import"./chunk-STKJA4PV.js";import{toast_default as f}from"./chunk-TMSSR5UH.js";import"./chunk-UQYNPYF4.js";import"./chunk-MRJKZWWV.js";import{registerModalEscapeInterceptor as x}from"./chunk-TWVUQUUD.js";import"./chunk-5FYDNH4Y.js";import"./chunk-LNXBTK7Q.js";import{useShellStrings as y,splitAround as g}from"./chunk-DEJIH3ZQ.js";import"./chunk-C3QOHMR6.js";import{useRef as b,useState as w,useEffect as v}from"react";import{jsxs as k,jsx as N,Fragment as C}from"react/jsx-runtime";var A=!1;function E(e,t){return e?.url&&e.url!==t.url&&e.url.startsWith("blob:")&&URL.revokeObjectURL(e.url),t}function L(){const n=b(void 0);void 0===n.current&&(n.current=o());const[s,m]=w(n.current?.data??null);v(()=>{const e=n.current;null!=e&&(a(e),m(t=>t===e.data?t:E(t,e.data)))},[]),v(()=>{const e=n.current?.token;if(null==e)return;const t=t=>{const n=t.detail;n&&n.token===e&&m(e=>E(e,n.data))};return window.addEventListener(l,t),()=>window.removeEventListener(l,t)},[]);const h=b(void 0);v(()=>{h.current=s?.url},[s?.url]);const x=b(null);v(()=>(null!==x.current&&(clearTimeout(x.current),x.current=null),()=>{const e=h.current;e?.startsWith("blob:")&&(x.current=setTimeout(()=>URL.revokeObjectURL(e),0))}),[]);const A=y().preview,L=s?.filename?(M=s.filename).length>24?`${M.slice(0,23)}…`:M:A.untitled;var M;const j=s?.position&&s.position.count>1?s.position:null,R=j?A.namedPosition(L,A.position(j.index+1,j.count)):L,T=b(null),D=b(null),[F,H]=w(null),[W,O]=w(!1),G=b(0),X=()=>T.current?.click(),B=()=>{G.current=0,O(!1)},U=e=>{const t=e.closest("[data-modal-id]");return!t||u()===t.dataset.modalId};v(()=>{const e=()=>B(),t=()=>B(),n=e=>{"Escape"===e.key&&B()};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 V=b(s);v(()=>{V.current=s},[s]),v(()=>{const e=e=>{const t=D.current;if(!t)return;const n=t.closest("[data-modal-id]"),r=n?u()===n.dataset.modalId:t.contains(document.activeElement),s=c(e,{active:r,data:V.current});s&&(e.preventDefault(),"previous"===s?V.current?.onPrevious?.():V.current?.onNext?.())};return window.addEventListener("keydown",e,!0),()=>window.removeEventListener("keydown",e,!0)},[]);const _=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?f.error(A.dwgUnsupported):f.error(A.unsupportedType(t)));const r=URL.createObjectURL(e);m(t=>(t?.url?.startsWith("blob:")&&t.url!==r&&URL.revokeObjectURL(t.url),{url:r,filename:e.name,kind:n}))},Y=/* @__PURE__ */k("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-44ZHEIJZ.js";import{IconButton_default as r}from"./chunk-SV5RRBVA.js";import{ImageAnnotator_default as s}from"./chunk-EQFWFQOZ.js";import{AboutApp as i}from"./chunk-VRRPYADW.js";import{peekPdfPreviewStage as o,claimPdfPreviewStage as a,PDF_PREVIEW_UPDATE_EVENT as l,previewStepForKey as c}from"./chunk-I4RJAMLJ.js";import{WindowTitle as d}from"./chunk-FCILLVVT.js";import"./chunk-4LXCCZDM.js";import"./chunk-AW7TOB6N.js";import"./chunk-KNUR2UEG.js";import"./chunk-JDCM2VHG.js";import"./chunk-DASRJ26L.js";import"./chunk-ZDMZM7HD.js";import"./chunk-5A7MWTXX.js";import"./chunk-GHLXZDLU.js";import"./chunk-KV6XCHAG.js";import"./chunk-B447IHIL.js";import"./chunk-EIFNESXS.js";import"./chunk-PR6FNBKR.js";import"./chunk-RIG5FEVS.js";import"./chunk-NDWX5Z4D.js";import"./chunk-VWGWZY7A.js";import"./chunk-7QSDPSXP.js";import"./chunk-ZGIAMYTI.js";import"./chunk-5LHEPE4B.js";import{getActiveModalId as u}from"./chunk-F3ZOO23R.js";import"./chunk-2QY5BJLA.js";import"./chunk-UGTRSRIW.js";import"./chunk-KC3EX26K.js";import"./chunk-56UUJIC4.js";import"./chunk-DWGYC7OD.js";import"./chunk-JMGDGNM7.js";import"./chunk-GOAFMGUI.js";import"./chunk-URHGHXDN.js";import"./chunk-5QFPTDQF.js";import"./chunk-EVYD6UFQ.js";import"./chunk-M5K4AX4E.js";import{Icon as p}from"./chunk-ISVODSRP.js";import"./chunk-J75ZT2JQ.js";import{SpinnerRing as m,LoadingSpinner as h}from"./chunk-R2VKEMZH.js";import"./chunk-G67CJAQ2.js";import"./chunk-SOZCWT6I.js";import"./chunk-PGN5ME7B.js";import"./chunk-62LW225J.js";import"./chunk-GLUJS42B.js";import"./chunk-D65T4H6J.js";import"./chunk-STKJA4PV.js";import{toast_default as f}from"./chunk-TMSSR5UH.js";import"./chunk-UQYNPYF4.js";import"./chunk-MRJKZWWV.js";import{registerModalEscapeInterceptor as x}from"./chunk-TWVUQUUD.js";import"./chunk-5FYDNH4Y.js";import"./chunk-LNXBTK7Q.js";import{useShellStrings as y,splitAround as g}from"./chunk-DEJIH3ZQ.js";import"./chunk-C3QOHMR6.js";import{useRef as b,useState as w,useEffect as v}from"react";import{jsxs as k,jsx as N,Fragment as C}from"react/jsx-runtime";var A=!1;function E(e,t){return e?.url&&e.url!==t.url&&e.url.startsWith("blob:")&&URL.revokeObjectURL(e.url),t}function L(){const n=b(void 0);void 0===n.current&&(n.current=o());const[s,m]=w(n.current?.data??null);v(()=>{const e=n.current;null!=e&&(a(e),m(t=>t===e.data?t:E(t,e.data)))},[]),v(()=>{const e=n.current?.token;if(null==e)return;const t=t=>{const n=t.detail;n&&n.token===e&&m(e=>E(e,n.data))};return window.addEventListener(l,t),()=>window.removeEventListener(l,t)},[]);const h=b(void 0);v(()=>{h.current=s?.url},[s?.url]);const x=b(null);v(()=>(null!==x.current&&(clearTimeout(x.current),x.current=null),()=>{const e=h.current;e?.startsWith("blob:")&&(x.current=setTimeout(()=>URL.revokeObjectURL(e),0))}),[]);const A=y().preview,L=s?.filename?(S=s.filename).length>24?`${S.slice(0,23)}…`:S:A.untitled;var S;const j=s?.position&&s.position.count>1?s.position:null,R=j?A.namedPosition(L,A.position(j.index+1,j.count)):L,T=b(null),D=b(null),[F,H]=w(null),[W,O]=w(!1),X=b(0),G=()=>T.current?.click(),B=()=>{X.current=0,O(!1)},U=e=>{const t=e.closest("[data-modal-id]");return!t||u()===t.dataset.modalId};v(()=>{const e=()=>B(),t=()=>B(),n=e=>{"Escape"===e.key&&B()};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 V=b(s);v(()=>{V.current=s},[s]),v(()=>{const e=e=>{const t=D.current;if(!t)return;const n=t.closest("[data-modal-id]"),r=n?u()===n.dataset.modalId:t.contains(document.activeElement),s=c(e,{active:r,data:V.current});s&&(e.preventDefault(),"previous"===s?V.current?.onPrevious?.():V.current?.onNext?.())};return window.addEventListener("keydown",e,!0),()=>window.removeEventListener("keydown",e,!0)},[]);const _=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?f.error(A.dwgUnsupported):f.error(A.unsupportedType(t)));const r=URL.createObjectURL(e);m(t=>(t?.url?.startsWith("blob:")&&t.url!==r&&URL.revokeObjectURL(t.url),{url:r,filename:e.name,kind:n}))},Y=/* @__PURE__ */k("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__ */N("input",{ref:T,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&&_(t),T.current&&(T.current.value="")},className:"hidden"}),
3
- /* @__PURE__ */k("button",{onClick:X,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:[
3
+ /* @__PURE__ */k("button",{onClick:G,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__ */N(p,{name:"folder-open",className:"h-3.5 w-3.5",strokeWidth:1.5}),A.open]}),
5
5
  /* @__PURE__ */N("span",{className:"text-2xs text-ink-faintest ml-1",children:A.formats}),s?.filename&&/* @__PURE__ */k(C,{children:[
6
6
  /* @__PURE__ */N("div",{className:"h-4 w-px bg-gray-300 mx-1"}),
7
7
  /* @__PURE__ */N("span",{className:"text-xs font-medium text-gray-700 truncate max-w-[200px]",title:s.filename,children:s.filename})]}),
8
- /* @__PURE__ */N("div",{ref:H,className:"ml-auto flex items-center gap-1 text-xs"})]});let Z;if(s)Z=s.converting||!s.url?/* @__PURE__ */N(S,{filename:s.filename,message:s.convertingMessage}):"dxf"===s.kind?/* @__PURE__ */N(z,{url:s.url,filename:s.filename,onDownload:s.onDownload,onEmail:s.onEmail},s.url):"3d"===s.kind?/* @__PURE__ */N(I,{url:s.url,filename:s.filename,onDownload:s.onDownload,onEmail:s.onEmail},s.url):"image"===s.kind?/* @__PURE__ */N(P,{url:s.url,filename:s.filename,onDownload:s.onDownload,onEmail:s.onEmail},s.url):/* @__PURE__ */N(e,{url:s.url,filename:s.filename,onDownload:s.onDownload,onEmail:s.onEmail},s.url);else{const[e,t]=g(A.dropHere),[n,r]=g(A.formatDxf),[s,i]=g(A.format3d);Z=/* @__PURE__ */k("div",{className:"flex flex-1 flex-col items-center justify-center text-gray-500 text-sm gap-3 p-8 text-center",children:[
8
+ /* @__PURE__ */N("div",{ref:H,className:"ml-auto flex items-center gap-1 text-xs"})]});let Z;if(s)Z=s.converting||!s.url?/* @__PURE__ */N(M,{filename:s.filename,message:s.convertingMessage}):"dxf"===s.kind?/* @__PURE__ */N(z,{url:s.url,filename:s.filename,onDownload:s.onDownload,onEmail:s.onEmail},s.url):"3d"===s.kind?/* @__PURE__ */N(I,{url:s.url,filename:s.filename,onDownload:s.onDownload,onEmail:s.onEmail},s.url):"image"===s.kind?/* @__PURE__ */N(P,{url:s.url,filename:s.filename,onDownload:s.onDownload,onEmail:s.onEmail},s.url):/* @__PURE__ */N(e,{url:s.url,filename:s.filename,onDownload:s.onDownload,onEmail:s.onEmail},s.url);else{const[e,t]=g(A.dropHere),[n,r]=g(A.formatDxf),[s,i]=g(A.format3d);Z=/* @__PURE__ */k("div",{className:"flex flex-1 flex-col items-center justify-center text-gray-500 text-sm gap-3 p-8 text-center",children:[
9
9
  /* @__PURE__ */N(p,{name:"page",className:"h-12 w-12 text-gray-300",strokeWidth:1.5}),
10
10
  /* @__PURE__ */k("p",{className:"font-medium text-gray-700",children:[e,
11
- /* @__PURE__ */N("button",{onClick:X,className:"text-blue-600 hover:underline",children:A.open}),t]}),
11
+ /* @__PURE__ */N("button",{onClick:G,className:"text-blue-600 hover:underline",children:A.open}),t]}),
12
12
  /* @__PURE__ */k("div",{className:"text-xs text-gray-500 max-w-sm",children:[
13
13
  /* @__PURE__ */N("p",{className:"font-semibold uppercase tracking-wide text-3xs text-ink-faintest mb-1",children:A.supportedFormats}),
14
14
  /* @__PURE__ */k("ul",{className:"space-y-0.5",children:[
@@ -23,22 +23,22 @@ import{PdfViewer as e,ToolbarSlotContext as t,PanelActions as n}from"./chunk-44Z
23
23
  /* @__PURE__ */k("li",{children:[
24
24
  /* @__PURE__ */N("span",{className:"font-mono text-gray-700",children:".jpg .jpeg .png .gif .webp .svg .avif .bmp"})," — ",A.formatImage]})]}),
25
25
  /* @__PURE__ */N("p",{className:"mt-2 text-2xs text-ink-faintest italic",children:A.dwgNote})]})]})}/* @__PURE__ */
26
- return k("div",{className:"relative flex flex-col h-full",ref:D,onDragEnter:e=>{e.dataTransfer?.types?.includes?.("Files")&&U(e.currentTarget)&&(e.preventDefault(),G.current++,W||O(!0))},onDragOver:e=>{e.dataTransfer?.types?.includes?.("Files")&&U(e.currentTarget)&&e.preventDefault()},onDragLeave:()=>{G.current>0&&G.current--,0===G.current&&O(!1)},onDrop:e=>{U(e.currentTarget)?(e=>{e.preventDefault(),B();const t=e.dataTransfer.files?.[0];t&&_(t)})(e):B()},children:[
26
+ return k("div",{className:"relative flex flex-col h-full",ref:D,onDragEnter:e=>{e.dataTransfer?.types?.includes?.("Files")&&U(e.currentTarget)&&(e.preventDefault(),X.current++,W||O(!0))},onDragOver:e=>{e.dataTransfer?.types?.includes?.("Files")&&U(e.currentTarget)&&e.preventDefault()},onDragLeave:()=>{X.current>0&&X.current--,0===X.current&&O(!1)},onDrop:e=>{U(e.currentTarget)?(e=>{e.preventDefault(),B();const t=e.dataTransfer.files?.[0];t&&_(t)})(e):B()},children:[
27
27
  /* @__PURE__ */N(d,{title:A.windowTitle(R)}),
28
28
  /* @__PURE__ */N(i,{app:"preview"}),Y,
29
- /* @__PURE__ */N(t.Provider,{value:F,children:/* @__PURE__ */k("div",{className:"relative flex-1 min-h-0",children:[Z,s?.onPrevious&&/* @__PURE__ */N("div",{className:"absolute inset-y-0 left-3 z-10 flex items-center pointer-events-none",children:/* @__PURE__ */N(r,{variant:"secondary",size:"lg","aria-label":A.previousFile,title:A.previousFile,onClick:s.onPrevious,className:"pointer-events-auto rounded-full! shadow-lg",children:/* @__PURE__ */N(p,{name:"chevron-left",className:"h-5 w-5",strokeWidth:2})})}),s?.onNext&&/* @__PURE__ */N("div",{className:"absolute inset-y-0 right-3 z-10 flex items-center pointer-events-none",children:/* @__PURE__ */N(r,{variant:"secondary",size:"lg","aria-label":A.nextFile,title:A.nextFile,onClick:s.onNext,className:"pointer-events-auto rounded-full! shadow-lg",children:/* @__PURE__ */N(p,{name:"chevron-right",className:"h-5 w-5",strokeWidth:2})})})]})}),W&&/* @__PURE__ */N("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__ */N("div",{className:"px-4 py-2 rounded-md bg-blue-600 text-white text-sm font-medium shadow-lg",children:A.dropToOpen})})]})}function S({filename:e,message:t}){const n=y().preview;/* @__PURE__ */
29
+ /* @__PURE__ */N(t.Provider,{value:F,children:/* @__PURE__ */k("div",{className:"relative flex-1 min-h-0",children:[Z,s?.onPrevious&&/* @__PURE__ */N("div",{className:"absolute inset-y-0 left-3 z-10 flex items-center pointer-events-none",children:/* @__PURE__ */N(r,{variant:"secondary",size:"lg","aria-label":A.previousFile,title:A.previousFile,onClick:s.onPrevious,className:"pointer-events-auto rounded-full! shadow-lg",children:/* @__PURE__ */N(p,{name:"chevron-left",className:"h-5 w-5",strokeWidth:2})})}),s?.onNext&&/* @__PURE__ */N("div",{className:"absolute inset-y-0 right-3 z-10 flex items-center pointer-events-none",children:/* @__PURE__ */N(r,{variant:"secondary",size:"lg","aria-label":A.nextFile,title:A.nextFile,onClick:s.onNext,className:"pointer-events-auto rounded-full! shadow-lg",children:/* @__PURE__ */N(p,{name:"chevron-right",className:"h-5 w-5",strokeWidth:2})})})]})}),W&&/* @__PURE__ */N("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__ */N("div",{className:"px-4 py-2 rounded-md bg-blue-600 text-white text-sm font-medium shadow-lg",children:A.dropToOpen})})]})}function M({filename:e,message:t}){const n=y().preview;/* @__PURE__ */
30
30
  return k("div",{className:"flex flex-col items-center justify-center h-full bg-gray-100 gap-4 px-8",children:[
31
31
  /* @__PURE__ */k("div",{className:"flex flex-col items-center gap-3",children:[
32
32
  /* @__PURE__ */N(m,{className:"h-12 w-12"}),
33
33
  /* @__PURE__ */N("div",{className:"text-base font-semibold tracking-wide text-gray-700 uppercase",children:t||n.converting}),
34
34
  /* @__PURE__ */N("div",{className:"text-xs text-gray-400 truncate max-w-md",children:e})]}),
35
35
  /* @__PURE__ */N("div",{className:"w-72 h-1.5 rounded-full bg-gray-200 overflow-hidden",children:/* @__PURE__ */N("div",{className:"h-full w-1/3 bg-blue-500 rounded-full animate-pulse",style:{animation:"preview-bar 1.4s ease-in-out infinite"}})}),
36
- /* @__PURE__ */N("style",{children:"@keyframes preview-bar { 0% { transform: translateX(-110%); } 100% { transform: translateX(310%); } }"})]})}var M=["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"],j={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 z({url:e,filename:t,onDownload:r,onEmail:s}){const i=b(null),o=b(null),[a,l]=w(!0),[c,d]=w(null),[m,f]=w([]),[A,E]=w(!1),[L,S]=w(!0),z=y(),R=z.drawing,T=z.preview,D=b(R);D.current=R;const[F,I]=w(!1),[P,W]=w("auto"),[O,G]=w(null),[X,B]=w(null),[U,V]=w(null),[_,Y]=w(""),Z=b(P),$=b(U);v(()=>{Z.current=P},[P]),v(()=>{$.current=U},[U]);const K=b(null),J=b(null),Q=b(null),[q,ee]=w(""),[te,ne]=w(null),re=b(""),se=b(null),ie=b(null),oe=b(null);v(()=>{let t=!1,n=null;return l(!0),d(null),f([]),(async()=>{let r;try{r=(await(import("dxf-viewer"))).DxfViewer}catch(e){return void(t||(d(D.current.notInstalled),l(!1)))}if(!t&&i.current)try{if(await new Promise(e=>{const t=()=>{const n=i.current?.getBoundingClientRect();n&&n.width>4&&n.height>4?e():requestAnimationFrame(t)};t()}),t||!i.current)return;const s={autoResize:!0},a=r.DefaultOptions?.clearColor;"function"==typeof a?.clone&&(s.clearColor=a.clone().setHex(16777215)),n=new r(i.current,s),o.current=n;const c="undefined"!=typeof window&&window.__REACT_OS_SHELL_DXF_FONTS__||M;if(await n.Load({url:e,fonts:c,workerFactory:null}),t)return;try{const e=n.GetLayers?.()??[];Array.isArray(e)&&f(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=i.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||(d(e?.message||D.current.renderFailed),l(!1))}})(),()=>{t=!0;try{n?.Destroy?.()}catch{}o.current=null}},[e]),v(()=>{if(!L||a)return;const e=setTimeout(()=>S(!1),5e3);return()=>clearTimeout(e)},[L,a]);const ae=m.map(e=>e.visible?"1":"0").join("");v(()=>{const e=o.current;if(a||c||!e)return;const t=e.GetScene?.(),n=e.GetCamera?.(),r=e.GetCanvas?.();if(!(t&&n&&r&&i.current))return;const s=()=>{const e=oe.current;e&&(e.overlay&&e.overlay.parentElement&&e.overlay.parentElement.removeChild(e.overlay),oe.current=null)};if(!F)return s(),G(null),void B(null);const l=document.createElement("div");l.style.cssText="position:absolute;inset:0;pointer-events:none;z-index:5;",i.current.appendChild(l);const d=document.createElementNS("http://www.w3.org/2000/svg","svg");d.setAttribute("style","position:absolute;inset:0;width:100%;height:100%;pointer-events:none;");const u=document.createElementNS("http://www.w3.org/2000/svg","defs"),p=document.createElementNS("http://www.w3.org/2000/svg","marker");p.setAttribute("id","dxf-measure-arrow"),p.setAttribute("viewBox","0 0 10 10"),p.setAttribute("refX","9"),p.setAttribute("refY","5"),p.setAttribute("markerWidth","6"),p.setAttribute("markerHeight","6"),p.setAttribute("orient","auto-start-reverse");const 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),d.appendChild(u),l.appendChild(d);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",d.appendChild(e),e},f=h(),x=h(),y=document.createElementNS("http://www.w3.org/2000/svg","line");y.setAttribute("stroke","#ff8800"),y.setAttribute("stroke-width","1"),y.setAttribute("opacity","0.85"),y.style.display="none",d.appendChild(y);const g=document.createElementNS("http://www.w3.org/2000/svg","line");g.setAttribute("stroke","#ff8800"),g.setAttribute("stroke-width","1"),g.setAttribute("opacity","0.85"),g.style.display="none",d.appendChild(g);const b=document.createElementNS("http://www.w3.org/2000/svg","line");b.setAttribute("stroke","#ff8800"),b.setAttribute("stroke-width","1.5"),b.setAttribute("stroke-linecap","round"),b.style.display="none",d.appendChild(b);const w=document.createElementNS("http://www.w3.org/2000/svg","line");w.setAttribute("stroke","#ff8800"),w.setAttribute("stroke-width","1.5"),w.setAttribute("stroke-linecap","round"),w.style.display="none",d.appendChild(w);const v=document.createElement("div");v.style.cssText="position:absolute;transform:translate(-50%,-50%);pointer-events:none;display:none;";const k="http://www.w3.org/2000/svg",N=document.createElementNS(k,"svg");N.setAttribute("width","22"),N.setAttribute("height","22"),N.setAttribute("viewBox","0 0 22 22"),N.setAttribute("style","overflow:visible;display:block"),v.appendChild(N);const 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 s=document.createElementNS(k,"line");return s.setAttribute("x1",String(e)),s.setAttribute("y1",String(t)),s.setAttribute("x2",String(n)),s.setAttribute("y2",String(r)),s.setAttribute("stroke","#ff8800"),s.setAttribute("stroke-width","2.2"),s.setAttribute("stroke-linecap","round"),s};e.appendChild(t(4,4,18,18)),e.appendChild(t(18,4,4,18))}),L=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)}),S=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)}),M=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 s=document.createElementNS(k,"line");return s.setAttribute("x1",String(e)),s.setAttribute("y1",String(t)),s.setAttribute("x2",String(n)),s.setAttribute("y2",String(r)),s.setAttribute("stroke","#ff8800"),s.setAttribute("stroke-width","1.6"),s.setAttribute("stroke-linecap","round"),s};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),oe.current={picks:[],rawSecondClick:null,overlay:l,svg:d,line:b,fixedLine:w,fixedLabel:null,refLine:f,refLineV:x,extLineA:y,extLineB:g,markers:[],label:null,snap:v,segs:null,nodes:null};const j=n?.position?.constructor??t?.position?.constructor??null;let z=!1;const R=(e,t)=>{if(!j)return{x:0,y:0};const s=new j(e,t,0).project(n),i=r.clientWidth,o=r.clientHeight;return{x:(s.x+1)/2*i,y:(1-s.y)/2*o}};(()=>{try{const e=oe.current;if(!e)return;const n=[],r=[];let s=!1;const i=e=>{const t=e?.attributes?.instanceTransform0,n=e?.attributes?.instanceTransform1;if(t&&n){const e=[],r=Math.min(t.count,n.count);for(let s=0;s<r;s++)e.push([t.getX(s),t.getY(s),t.getZ(s),n.getX(s),n.getY(s),n.getZ(s)]);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]]},o=e=>{const t=!!e?.isLineSegments;if(!t&&!!!e?.isPoints)return;const o=e.geometry,a=o?.attributes?.position;if(!a)return;const l=i(o);if(t){const e=o.index,t=Math.floor((e?e.count:a.count)/2);for(let r=0;r<t;r++){const t=e?e.getX(2*r):2*r,i=e?e.getX(2*r+1):2*r+1,o=a.getX(t),c=a.getY(t),d=a.getX(i),u=a.getY(i);if(Number.isFinite(o+c+d+u))for(const e of l){if(n.length>=16e5)return void(s=!0);const t=e[0]*o+e[1]*c+e[2],r=e[3]*o+e[4]*c+e[5],i=e[0]*d+e[1]*u+e[2],a=e[3]*d+e[4]*u+e[5];t===i&&r===a||n.push(t,r,i,a)}}}else for(let e=0;e<a.count;e++){const t=a.getX(e),n=a.getY(e);if(Number.isFinite(t+n))for(const e of l)r.push(e[0]*t+e[1]*n+e[2],e[3]*t+e[4]*n+e[5])}};"function"==typeof t.traverseVisible?t.traverseVisible(o):t.traverse(o),e.segs=new Float64Array(n),e.nodes=new Float64Array(r),s&&console.warn("[Preview] DXF snap cache truncated at 400000 segments — snapping may miss some geometry."),z=!0}catch{}})();const T=(e,t,n,r,s,i,o,a)=>{const l=(n-e)*(a-i)-(r-t)*(o-s);if(Math.abs(l)<1e-9)return null;const c=((s-e)*(a-i)-(i-t)*(o-s))/l,d=((s-e)*(r-t)-(i-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}},P=()=>{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},W=(e,t,n)=>{const r=R(t,n);e.style.left=`${r.x}px`,e.style.top=`${r.y}px`},O=()=>{const e=oe.current;if(!e||!e.rawSecondClick||e.picks.length<2)return;const t=e.picks[0],n=e.rawSecondClick,r=$.current,s=Z.current;if(null===r||!Number.isFinite(r)||"horizontal"!==s&&"vertical"!==s)e.picks[1]={x:n.x,y:n.y};else if("horizontal"===s){const s=n.x>=t.x?1:-1;e.picks[1]={x:t.x+s*Math.abs(r),y:n.y}}else{const s=n.y>=t.y?1:-1;e.picks[1]={x:n.x,y:t.y+s*Math.abs(r)}}},X=(e,t)=>{const n=Z.current;return"auto"!==n?n:e&&t?Math.abs(t.x-e.x)>=Math.abs(t.y-e.y)?"horizontal":"vertical":"horizontal"},U=()=>{const e=oe.current;if(!e)return;O();const t=Z.current,n=$.current,s=null!==n&&Number.isFinite(n)&&("horizontal"===t||"vertical"===t);e.markers[0]&&W(e.markers[0],e.picks[0].x,e.picks[0].y),e.markers[1]&&W(e.markers[1],e.picks[1].x,e.picks[1].y);const i=(t,n,s)=>{if(!t)return;if(!s||e.picks.length<1)return void(t.style.display="none");const i=e.picks[0],o=r.clientWidth,a=r.clientHeight,l=4*Math.hypot(o,a),c=R(i.x,i.y),d=R(i.x+n.dx,i.y+n.dy),u=l/(Math.hypot(d.x-c.x,d.y-c.y)||1),p=R(i.x-n.dx*u,i.y-n.dy*u),m=R(i.x+n.dx*u,i.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 o="horizontal"===t,a="vertical"===t;if("auto"===t)if(e.picks.length>=2){const t=X(e.picks[0],e.picks[1]);o="horizontal"===t,a="vertical"===t}else o=!0,a=!0;if(i(e.refLine,{dx:1,dy:0},o),i(e.refLineV,{dx:0,dy:1},a),2===e.picks.length){const t=e.picks[0],i=e.picks[1],o=X(t,i),a=(()=>{const e=oe.current,t=e.picks[0],n=e.picks[1],r=X(t,n),s=Z.current,i=$.current;return null!==i&&Number.isFinite(i)&&"horizontal"===s?{from:{x:n.x,y:t.y},to:{x:n.x,y:n.y}}:null!==i&&Number.isFinite(i)&&"vertical"===s?{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=R(a.from.x,a.from.y),c=R(a.to.x,a.to.y);e.line.setAttribute("x1",String(l.x)),e.line.setAttribute("y1",String(l.y)),e.line.setAttribute("x2",String(c.x)),e.line.setAttribute("y2",String(c.y)),e.line.setAttribute("marker-start","url(#dxf-measure-arrow)"),e.line.setAttribute("marker-end","url(#dxf-measure-arrow)");const d=Math.hypot(c.x-l.x,c.y-l.y);if(e.line.style.display=d>.5?"":"none",s&&e.fixedLine){const s="horizontal"===o?{x:i.x,y:t.y}:{x:t.x,y:i.y},a=R(t.x,t.y),l=R(s.x,s.y);e.fixedLine.setAttribute("x1",String(a.x)),e.fixedLine.setAttribute("y1",String(a.y)),e.fixedLine.setAttribute("x2",String(l.x)),e.fixedLine.setAttribute("y2",String(l.y)),e.fixedLine.setAttribute("marker-start","url(#dxf-measure-arrow)"),e.fixedLine.setAttribute("marker-end","url(#dxf-measure-arrow)"),e.fixedLine.style.display="";const c=V();c.textContent=H(Math.abs(n));const d=(a.x+l.x)/2,u=(a.y+l.y)/2;c.style.left=`${d}px`,c.style.top=`${u}px`;const p=r.clientWidth,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(!s&&"horizontal"===o&&Math.abs(i.y-t.y)>1e-9){const e=R(i.x,t.y),n=R(i.x,i.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(!s&&"vertical"===o&&Math.abs(i.x-t.x)>1e-9){const e=R(t.x,i.y),n=R(i.x,i.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 s=r.clientWidth,i=r.clientHeight;e.label.style.display=t<0||n<0||t>s||n>i?"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")},V=()=>{const e=oe.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:var(--text-2xs);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,Y=0,q=0,ee=!1,te=!1,re=null;const se=e=>{const t=e?.detail;t&&0===t.domEvent?.button&&(_=t.canvasCoord.x,Y=t.canvasCoord.y,q=performance.now(),te=!1,ee=!0)},ie=e=>{const t=r.getBoundingClientRect(),n=e.clientX-t.left,s=e.clientY-t.top;ee&&(n-_)**2+(s-Y)**2>16&&(te=!0);const i=oe.current;var o;if(i&&i.snap)if(ee&&te)i.snap.style.display="none";else if(re=((e,t)=>{const n=oe.current;if(!n||!z||!n.segs)return null;const r=R(0,0),s=R(1,0),i=R(0,1),o=s.x-r.x,a=s.y-r.y,l=i.x-r.x,c=i.y-r.y,d=o*c-l*a;if(!d)return null;const u=((e-r.x)*c-(t-r.y)*l)/d,p=((t-r.y)*o-(e-r.x)*a)/d,m=18/(Math.hypot(o,a)||1),h=18/(Math.hypot(l,c)||1),f=u-m,x=u+m,y=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 S=[],M=n.segs;for(let n=0;n<M.length;n+=4){const s=M[n],i=M[n+1],d=M[n+2],u=M[n+3];if(s<f&&d<f||s>x&&d>x||i<y&&u<y||i>g&&u>g)continue;const p=r.x+o*s+l*i,m=r.y+a*s+c*i,h=r.x+o*d+l*u,E=r.y+a*d+c*u;let L=!1,j=e-p,z=t-m,R=j*j+z*z;R<b&&(L=!0,R<v&&(v=R,w={sx:s,sy:i,type:"endpoint"})),j=e-h,z=t-E,R=j*j+z*z,R<b&&(L=!0,R<v&&(v=R,w={sx:d,sy:u,type:"endpoint"})),j=e-(p+h)/2,z=t-(m+E)/2,R=j*j+z*z,R<b&&(L=!0,R<N&&(N=R,k={sx:(s+d)/2,sy:(i+u)/2,type:"midpoint"}));const T=h-p,D=E-m,F=T*T+D*D;if(F>0){const n=((e-p)*T+(t-m)*D)/F;n>0&&n<1&&(j=e-(p+n*T),z=t-(m+n*D),R=j*j+z*z,R<b&&(L=!0,R<A&&(A=R,C={sx:s+n*(d-s),sy:i+n*(u-i),type:"line"})))}L&&S.push({ax:s,ay:i,bx:d,by:u,apx:p,apy:m,bpx:h,bpy:E})}const j=n.nodes;if(j)for(let n=0;n<j.length;n+=2){const s=j[n],i=j[n+1];if(s<f||s>x||i<y||i>g)continue;const d=e-(r.x+o*s+l*i),u=t-(r.y+a*s+c*i),p=d*d+u*u;p<v&&(v=p,w={sx:s,sy:i,type:"node"})}for(let n=0;n<S.length;n++){const r=S[n];for(let s=n+1;s<S.length;s++){const n=S[s],i=T(r.apx,r.apy,r.bpx,r.bpy,n.apx,n.apy,n.bpx,n.bpy);if(!i)continue;const o=e-i.px,a=t-i.py,l=o*o+a*a;l>=b||l>=L||(L=l,E={sx:r.ax+i.t*(r.bx-r.ax),sy:r.ay+i.t*(r.by-r.ay),type:"intersection"})}}return(E&&w?L<v-1?E:w:E??w)??k??C})(n,s),re){const e=R(re.sx,re.sy);i.snap.style.left=`${e.x}px`,i.snap.style.top=`${e.y}px`,i.snap.style.display="",o=re.type,A.style.display="endpoint"===o?"":"none",E.style.display="intersection"===o?"":"none",L.style.display="line"===o?"":"none",S.style.display="midpoint"===o?"":"none",M.style.display="node"===o?"":"none"}else i.snap.style.display="none"},ae=e=>{if(!ee)return;ee=!1;const t=performance.now()-q;if(te||t>350)return;const n=e?.detail?.position;if(!n)return;const r=re?{x:re.sx,y:re.sy}:{x:n.x,y:n.y};ue(r)},le=()=>{const e=oe.current;if(!e||2!==e.picks.length)return;O();const t=e.picks[0],n=e.picks[1],r=Z.current,s=X(t,n),i=$.current,o=null!==i&&Number.isFinite(i)&&("horizontal"===r||"vertical"===r);let a,c,d="",u=s;const p=Math.abs(n.x-t.x),m=Math.abs(n.y-t.y);if(o&&"horizontal"===r?(a=m,d=" ↕",u="vertical",c=D.current.echoLocked("ΔY",H(m),"ΔX",H(Math.abs(i)))):o&&"vertical"===r?(a=p,d=" ↔",u="horizontal",c=D.current.echoLocked("ΔX",H(p),"ΔY",H(Math.abs(i)))):"horizontal"===s?(a=p,d=" ↔",c=D.current.echoLinear(H(p),"ΔX")):"vertical"===s?(a=m,d=" ↕",c=D.current.echoLinear(H(m),"ΔY")):(a=Math.hypot(n.x-t.x,n.y-t.y),c=D.current.echoDistance(H(a),H(p),H(m))),!Number.isFinite(a))return G(null),B(null),void(e.label&&(e.label.style.opacity="0"));G(a),B(u),ne(c);const h=(()=>{const e=oe.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:var(--text-2xs);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=`${H(a)}${d}`};K.current=()=>{le(),U()};const ce=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"),G(null),B(null)},de=()=>{const e=oe.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"),ce(e)}};J.current=de,Q.current=()=>{const e=oe.current;if(!e||0===e.picks.length)return;e.picks.pop();const t=e.markers.pop();t?.parentElement?.removeChild(t),e.rawSecondClick=null,ce(e),U()};const ue=e=>{const t=oe.current;t&&(2===t.picks.length&&de(),0===t.picks.length?(t.picks.push({x:e.x,y:e.y}),t.markers.push(P())):(t.rawSecondClick={x:e.x,y:e.y},t.picks.push({x:e.x,y:e.y}),t.markers.push(P()),le()),U())},pe=e=>{"Escape"===e.key&&I(!1)};r.style.cursor="crosshair";try{e.Subscribe?.("pointerdown",se)}catch{}try{e.Subscribe?.("pointerup",ae)}catch{}try{e.Subscribe?.("viewChanged",U)}catch{}return r.addEventListener("pointermove",ie),window.addEventListener("keydown",pe),()=>{r.style.cursor="";try{e.Unsubscribe?.("pointerdown",se)}catch{}try{e.Unsubscribe?.("pointerup",ae)}catch{}try{e.Unsubscribe?.("viewChanged",U)}catch{}r.removeEventListener("pointermove",ie),window.removeEventListener("keydown",pe),K.current=null,J.current=null,Q.current=null,s(),G(null),B(null)}},[F,a,c,ae]),v(()=>{K.current?.()},[P,U]);const le=e=>{f(t=>t.map(t=>{if(t.visible===e)return t;try{o.current?.ShowLayer?.(t.name,e)}catch{}return{...t,visible:e}}))},ce=()=>{try{const e=o.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{}};v(()=>{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=ie.current;if(!n)return;const r=n.closest("[data-modal-id]");r&&u()!==r.dataset.modalId||se.current?.focus()};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[]);const de=b(q),ue=b(F);v(()=>{de.current=q},[q]),v(()=>{ue.current=F},[F]),v(()=>x(()=>{const e=ie.current;if(!e)return!1;const t=e.closest("[data-modal-id]");return!(!t||u()!==t.dataset.modalId)&&(de.current?(ee(""),ne(D.current.cancelled),!0):!!ue.current&&(I(!1),ne(D.current.measureOff),!0))}),[]);const pe="px-2 py-1 rounded hover:bg-gray-200 transition-colors text-gray-600 flex items-center gap-1",[me,he]=g(R.typeToMeasure);/* @__PURE__ */
36
+ /* @__PURE__ */N("style",{children:"@keyframes preview-bar { 0% { transform: translateX(-110%); } 100% { transform: translateX(310%); } }"})]})}var S=["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"],j={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 z({url:e,filename:t,onDownload:r,onEmail:s}){const i=b(null),o=b(null),[a,l]=w(!0),[c,d]=w(null),[m,f]=w([]),[A,E]=w(!1),[L,M]=w(!0),z=y(),R=z.drawing,T=z.preview,D=b(R);D.current=R;const[F,I]=w(!1),[P,W]=w("auto"),[O,X]=w(null),[G,B]=w(null),[U,V]=w(null),[_,Y]=w(""),Z=b(P),$=b(U);v(()=>{Z.current=P},[P]),v(()=>{$.current=U},[U]);const J=b(null),K=b(null),Q=b(null),[q,ee]=w(""),[te,ne]=w(null),re=b(""),se=b(null),ie=b(null),oe=b(null);v(()=>{let t=!1,n=null;return l(!0),d(null),f([]),(async()=>{let r;try{r=(await(import("dxf-viewer"))).DxfViewer}catch(e){return void(t||(d(D.current.notInstalled),l(!1)))}if(!t&&i.current)try{if(await new Promise(e=>{const t=()=>{const n=i.current?.getBoundingClientRect();n&&n.width>4&&n.height>4?e():requestAnimationFrame(t)};t()}),t||!i.current)return;const s={autoResize:!0},a=r.DefaultOptions?.clearColor;"function"==typeof a?.clone&&(s.clearColor=a.clone().setHex(16777215)),n=new r(i.current,s),o.current=n;const c="undefined"!=typeof window&&window.__REACT_OS_SHELL_DXF_FONTS__||S;if(await n.Load({url:e,fonts:c,workerFactory:null}),t)return;try{const e=n.GetLayers?.()??[];Array.isArray(e)&&f(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=i.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||(d(e?.message||D.current.renderFailed),l(!1))}})(),()=>{t=!0;try{n?.Destroy?.()}catch{}o.current=null}},[e]),v(()=>{if(!L||a)return;const e=setTimeout(()=>M(!1),5e3);return()=>clearTimeout(e)},[L,a]);const ae=m.map(e=>e.visible?"1":"0").join("");v(()=>{const e=o.current;if(a||c||!e)return;const t=e.GetScene?.(),n=e.GetCamera?.(),r=e.GetCanvas?.();if(!(t&&n&&r&&i.current))return;const s=()=>{const e=oe.current;e&&(e.overlay&&e.overlay.parentElement&&e.overlay.parentElement.removeChild(e.overlay),oe.current=null)};if(!F)return s(),X(null),void B(null);const l=document.createElement("div");l.style.cssText="position:absolute;inset:0;pointer-events:none;z-index:5;",i.current.appendChild(l);const d=document.createElementNS("http://www.w3.org/2000/svg","svg");d.setAttribute("style","position:absolute;inset:0;width:100%;height:100%;pointer-events:none;");const u=document.createElementNS("http://www.w3.org/2000/svg","defs"),p=document.createElementNS("http://www.w3.org/2000/svg","marker");p.setAttribute("id","dxf-measure-arrow"),p.setAttribute("viewBox","0 0 10 10"),p.setAttribute("refX","9"),p.setAttribute("refY","5"),p.setAttribute("markerWidth","6"),p.setAttribute("markerHeight","6"),p.setAttribute("orient","auto-start-reverse");const 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),d.appendChild(u),l.appendChild(d);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",d.appendChild(e),e},f=h(),x=h(),y=document.createElementNS("http://www.w3.org/2000/svg","line");y.setAttribute("stroke","#ff8800"),y.setAttribute("stroke-width","1"),y.setAttribute("opacity","0.85"),y.style.display="none",d.appendChild(y);const g=document.createElementNS("http://www.w3.org/2000/svg","line");g.setAttribute("stroke","#ff8800"),g.setAttribute("stroke-width","1"),g.setAttribute("opacity","0.85"),g.style.display="none",d.appendChild(g);const b=document.createElementNS("http://www.w3.org/2000/svg","line");b.setAttribute("stroke","#ff8800"),b.setAttribute("stroke-width","1.5"),b.setAttribute("stroke-linecap","round"),b.style.display="none",d.appendChild(b);const w=document.createElementNS("http://www.w3.org/2000/svg","line");w.setAttribute("stroke","#ff8800"),w.setAttribute("stroke-width","1.5"),w.setAttribute("stroke-linecap","round"),w.style.display="none",d.appendChild(w);const v=document.createElement("div");v.style.cssText="position:absolute;transform:translate(-50%,-50%);pointer-events:none;display:none;";const k="http://www.w3.org/2000/svg",N=document.createElementNS(k,"svg");N.setAttribute("width","22"),N.setAttribute("height","22"),N.setAttribute("viewBox","0 0 22 22"),N.setAttribute("style","overflow:visible;display:block"),v.appendChild(N);const 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 s=document.createElementNS(k,"line");return s.setAttribute("x1",String(e)),s.setAttribute("y1",String(t)),s.setAttribute("x2",String(n)),s.setAttribute("y2",String(r)),s.setAttribute("stroke","#ff8800"),s.setAttribute("stroke-width","2.2"),s.setAttribute("stroke-linecap","round"),s};e.appendChild(t(4,4,18,18)),e.appendChild(t(18,4,4,18))}),L=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)}),M=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)}),S=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 s=document.createElementNS(k,"line");return s.setAttribute("x1",String(e)),s.setAttribute("y1",String(t)),s.setAttribute("x2",String(n)),s.setAttribute("y2",String(r)),s.setAttribute("stroke","#ff8800"),s.setAttribute("stroke-width","1.6"),s.setAttribute("stroke-linecap","round"),s};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),oe.current={picks:[],rawSecondClick:null,overlay:l,svg:d,line:b,fixedLine:w,fixedLabel:null,refLine:f,refLineV:x,extLineA:y,extLineB:g,markers:[],label:null,snap:v,segs:null,nodes:null};const j=n?.position?.constructor??t?.position?.constructor??null;let z=!1;const R=(e,t)=>{if(!j)return{x:0,y:0};const s=new j(e,t,0).project(n),i=r.clientWidth,o=r.clientHeight;return{x:(s.x+1)/2*i,y:(1-s.y)/2*o}};(()=>{try{const e=oe.current;if(!e)return;const n=[],r=[];let s=!1;const i=e=>{const t=e?.attributes?.instanceTransform0,n=e?.attributes?.instanceTransform1;if(t&&n){const e=[],r=Math.min(t.count,n.count);for(let s=0;s<r;s++)e.push([t.getX(s),t.getY(s),t.getZ(s),n.getX(s),n.getY(s),n.getZ(s)]);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]]},o=e=>{const t=!!e?.isLineSegments;if(!t&&!!!e?.isPoints)return;const o=e.geometry,a=o?.attributes?.position;if(!a)return;const l=i(o);if(t){const e=o.index,t=Math.floor((e?e.count:a.count)/2);for(let r=0;r<t;r++){const t=e?e.getX(2*r):2*r,i=e?e.getX(2*r+1):2*r+1,o=a.getX(t),c=a.getY(t),d=a.getX(i),u=a.getY(i);if(Number.isFinite(o+c+d+u))for(const e of l){if(n.length>=16e5)return void(s=!0);const t=e[0]*o+e[1]*c+e[2],r=e[3]*o+e[4]*c+e[5],i=e[0]*d+e[1]*u+e[2],a=e[3]*d+e[4]*u+e[5];t===i&&r===a||n.push(t,r,i,a)}}}else for(let e=0;e<a.count;e++){const t=a.getX(e),n=a.getY(e);if(Number.isFinite(t+n))for(const e of l)r.push(e[0]*t+e[1]*n+e[2],e[3]*t+e[4]*n+e[5])}};"function"==typeof t.traverseVisible?t.traverseVisible(o):t.traverse(o),e.segs=new Float64Array(n),e.nodes=new Float64Array(r),s&&console.warn("[Preview] DXF snap cache truncated at 400000 segments — snapping may miss some geometry."),z=!0}catch{}})();const T=(e,t,n,r,s,i,o,a)=>{const l=(n-e)*(a-i)-(r-t)*(o-s);if(Math.abs(l)<1e-9)return null;const c=((s-e)*(a-i)-(i-t)*(o-s))/l,d=((s-e)*(r-t)-(i-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}},P=()=>{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},W=(e,t,n)=>{const r=R(t,n);e.style.left=`${r.x}px`,e.style.top=`${r.y}px`},O=()=>{const e=oe.current;if(!e||!e.rawSecondClick||e.picks.length<2)return;const t=e.picks[0],n=e.rawSecondClick,r=$.current,s=Z.current;if(null===r||!Number.isFinite(r)||"horizontal"!==s&&"vertical"!==s)e.picks[1]={x:n.x,y:n.y};else if("horizontal"===s){const s=n.x>=t.x?1:-1;e.picks[1]={x:t.x+s*Math.abs(r),y:n.y}}else{const s=n.y>=t.y?1:-1;e.picks[1]={x:n.x,y:t.y+s*Math.abs(r)}}},G=(e,t)=>{const n=Z.current;return"auto"!==n?n:e&&t?Math.abs(t.x-e.x)>=Math.abs(t.y-e.y)?"horizontal":"vertical":"horizontal"},U=()=>{const e=oe.current;if(!e)return;O();const t=Z.current,n=$.current,s=null!==n&&Number.isFinite(n)&&("horizontal"===t||"vertical"===t);e.markers[0]&&W(e.markers[0],e.picks[0].x,e.picks[0].y),e.markers[1]&&W(e.markers[1],e.picks[1].x,e.picks[1].y);const i=(t,n,s)=>{if(!t)return;if(!s||e.picks.length<1)return void(t.style.display="none");const i=e.picks[0],o=r.clientWidth,a=r.clientHeight,l=4*Math.hypot(o,a),c=R(i.x,i.y),d=R(i.x+n.dx,i.y+n.dy),u=l/(Math.hypot(d.x-c.x,d.y-c.y)||1),p=R(i.x-n.dx*u,i.y-n.dy*u),m=R(i.x+n.dx*u,i.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 o="horizontal"===t,a="vertical"===t;if("auto"===t)if(e.picks.length>=2){const t=G(e.picks[0],e.picks[1]);o="horizontal"===t,a="vertical"===t}else o=!0,a=!0;if(i(e.refLine,{dx:1,dy:0},o),i(e.refLineV,{dx:0,dy:1},a),2===e.picks.length){const t=e.picks[0],i=e.picks[1],o=G(t,i),a=(()=>{const e=oe.current,t=e.picks[0],n=e.picks[1],r=G(t,n),s=Z.current,i=$.current;return null!==i&&Number.isFinite(i)&&"horizontal"===s?{from:{x:n.x,y:t.y},to:{x:n.x,y:n.y}}:null!==i&&Number.isFinite(i)&&"vertical"===s?{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=R(a.from.x,a.from.y),c=R(a.to.x,a.to.y);e.line.setAttribute("x1",String(l.x)),e.line.setAttribute("y1",String(l.y)),e.line.setAttribute("x2",String(c.x)),e.line.setAttribute("y2",String(c.y)),e.line.setAttribute("marker-start","url(#dxf-measure-arrow)"),e.line.setAttribute("marker-end","url(#dxf-measure-arrow)");const d=Math.hypot(c.x-l.x,c.y-l.y);if(e.line.style.display=d>.5?"":"none",s&&e.fixedLine){const s="horizontal"===o?{x:i.x,y:t.y}:{x:t.x,y:i.y},a=R(t.x,t.y),l=R(s.x,s.y);e.fixedLine.setAttribute("x1",String(a.x)),e.fixedLine.setAttribute("y1",String(a.y)),e.fixedLine.setAttribute("x2",String(l.x)),e.fixedLine.setAttribute("y2",String(l.y)),e.fixedLine.setAttribute("marker-start","url(#dxf-measure-arrow)"),e.fixedLine.setAttribute("marker-end","url(#dxf-measure-arrow)"),e.fixedLine.style.display="";const c=V();c.textContent=H(Math.abs(n));const d=(a.x+l.x)/2,u=(a.y+l.y)/2;c.style.left=`${d}px`,c.style.top=`${u}px`;const p=r.clientWidth,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(!s&&"horizontal"===o&&Math.abs(i.y-t.y)>1e-9){const e=R(i.x,t.y),n=R(i.x,i.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(!s&&"vertical"===o&&Math.abs(i.x-t.x)>1e-9){const e=R(t.x,i.y),n=R(i.x,i.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 s=r.clientWidth,i=r.clientHeight;e.label.style.display=t<0||n<0||t>s||n>i?"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")},V=()=>{const e=oe.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:var(--text-2xs);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,Y=0,q=0,ee=!1,te=!1,re=null;const se=e=>{const t=e?.detail;t&&0===t.domEvent?.button&&(_=t.canvasCoord.x,Y=t.canvasCoord.y,q=performance.now(),te=!1,ee=!0)},ie=e=>{const t=r.getBoundingClientRect(),n=e.clientX-t.left,s=e.clientY-t.top;ee&&(n-_)**2+(s-Y)**2>16&&(te=!0);const i=oe.current;var o;if(i&&i.snap)if(ee&&te)i.snap.style.display="none";else if(re=((e,t)=>{const n=oe.current;if(!n||!z||!n.segs)return null;const r=R(0,0),s=R(1,0),i=R(0,1),o=s.x-r.x,a=s.y-r.y,l=i.x-r.x,c=i.y-r.y,d=o*c-l*a;if(!d)return null;const u=((e-r.x)*c-(t-r.y)*l)/d,p=((t-r.y)*o-(e-r.x)*a)/d,m=18/(Math.hypot(o,a)||1),h=18/(Math.hypot(l,c)||1),f=u-m,x=u+m,y=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 s=S[n],i=S[n+1],d=S[n+2],u=S[n+3];if(s<f&&d<f||s>x&&d>x||i<y&&u<y||i>g&&u>g)continue;const p=r.x+o*s+l*i,m=r.y+a*s+c*i,h=r.x+o*d+l*u,E=r.y+a*d+c*u;let L=!1,j=e-p,z=t-m,R=j*j+z*z;R<b&&(L=!0,R<v&&(v=R,w={sx:s,sy:i,type:"endpoint"})),j=e-h,z=t-E,R=j*j+z*z,R<b&&(L=!0,R<v&&(v=R,w={sx:d,sy:u,type:"endpoint"})),j=e-(p+h)/2,z=t-(m+E)/2,R=j*j+z*z,R<b&&(L=!0,R<N&&(N=R,k={sx:(s+d)/2,sy:(i+u)/2,type:"midpoint"}));const T=h-p,D=E-m,F=T*T+D*D;if(F>0){const n=((e-p)*T+(t-m)*D)/F;n>0&&n<1&&(j=e-(p+n*T),z=t-(m+n*D),R=j*j+z*z,R<b&&(L=!0,R<A&&(A=R,C={sx:s+n*(d-s),sy:i+n*(u-i),type:"line"})))}L&&M.push({ax:s,ay:i,bx:d,by:u,apx:p,apy:m,bpx:h,bpy:E})}const j=n.nodes;if(j)for(let n=0;n<j.length;n+=2){const s=j[n],i=j[n+1];if(s<f||s>x||i<y||i>g)continue;const d=e-(r.x+o*s+l*i),u=t-(r.y+a*s+c*i),p=d*d+u*u;p<v&&(v=p,w={sx:s,sy:i,type:"node"})}for(let n=0;n<M.length;n++){const r=M[n];for(let s=n+1;s<M.length;s++){const n=M[s],i=T(r.apx,r.apy,r.bpx,r.bpy,n.apx,n.apy,n.bpx,n.bpy);if(!i)continue;const o=e-i.px,a=t-i.py,l=o*o+a*a;l>=b||l>=L||(L=l,E={sx:r.ax+i.t*(r.bx-r.ax),sy:r.ay+i.t*(r.by-r.ay),type:"intersection"})}}return(E&&w?L<v-1?E:w:E??w)??k??C})(n,s),re){const e=R(re.sx,re.sy);i.snap.style.left=`${e.x}px`,i.snap.style.top=`${e.y}px`,i.snap.style.display="",o=re.type,A.style.display="endpoint"===o?"":"none",E.style.display="intersection"===o?"":"none",L.style.display="line"===o?"":"none",M.style.display="midpoint"===o?"":"none",S.style.display="node"===o?"":"none"}else i.snap.style.display="none"},ae=e=>{if(!ee)return;ee=!1;const t=performance.now()-q;if(te||t>350)return;const n=e?.detail?.position;if(!n)return;const r=re?{x:re.sx,y:re.sy}:{x:n.x,y:n.y};ue(r)},le=()=>{const e=oe.current;if(!e||2!==e.picks.length)return;O();const t=e.picks[0],n=e.picks[1],r=Z.current,s=G(t,n),i=$.current,o=null!==i&&Number.isFinite(i)&&("horizontal"===r||"vertical"===r);let a,c,d="",u=s;const p=Math.abs(n.x-t.x),m=Math.abs(n.y-t.y);if(o&&"horizontal"===r?(a=m,d=" ↕",u="vertical",c=D.current.echoLocked("ΔY",H(m),"ΔX",H(Math.abs(i)))):o&&"vertical"===r?(a=p,d=" ↔",u="horizontal",c=D.current.echoLocked("ΔX",H(p),"ΔY",H(Math.abs(i)))):"horizontal"===s?(a=p,d=" ↔",c=D.current.echoLinear(H(p),"ΔX")):"vertical"===s?(a=m,d=" ↕",c=D.current.echoLinear(H(m),"ΔY")):(a=Math.hypot(n.x-t.x,n.y-t.y),c=D.current.echoDistance(H(a),H(p),H(m))),!Number.isFinite(a))return X(null),B(null),void(e.label&&(e.label.style.opacity="0"));X(a),B(u),ne(c);const h=(()=>{const e=oe.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:var(--text-2xs);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=`${H(a)}${d}`};J.current=()=>{le(),U()};const ce=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"),X(null),B(null)},de=()=>{const e=oe.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"),ce(e)}};K.current=de,Q.current=()=>{const e=oe.current;if(!e||0===e.picks.length)return;e.picks.pop();const t=e.markers.pop();t?.parentElement?.removeChild(t),e.rawSecondClick=null,ce(e),U()};const ue=e=>{const t=oe.current;t&&(2===t.picks.length&&de(),0===t.picks.length?(t.picks.push({x:e.x,y:e.y}),t.markers.push(P())):(t.rawSecondClick={x:e.x,y:e.y},t.picks.push({x:e.x,y:e.y}),t.markers.push(P()),le()),U())},pe=e=>{"Escape"===e.key&&I(!1)};r.style.cursor="crosshair";try{e.Subscribe?.("pointerdown",se)}catch{}try{e.Subscribe?.("pointerup",ae)}catch{}try{e.Subscribe?.("viewChanged",U)}catch{}return r.addEventListener("pointermove",ie),window.addEventListener("keydown",pe),()=>{r.style.cursor="";try{e.Unsubscribe?.("pointerdown",se)}catch{}try{e.Unsubscribe?.("pointerup",ae)}catch{}try{e.Unsubscribe?.("viewChanged",U)}catch{}r.removeEventListener("pointermove",ie),window.removeEventListener("keydown",pe),J.current=null,K.current=null,Q.current=null,s(),X(null),B(null)}},[F,a,c,ae]),v(()=>{J.current?.()},[P,U]);const le=e=>{f(t=>t.map(t=>{if(t.visible===e)return t;try{o.current?.ShowLayer?.(t.name,e)}catch{}return{...t,visible:e}}))},ce=()=>{try{const e=o.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{}};v(()=>{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=ie.current;if(!n)return;const r=n.closest("[data-modal-id]");r&&u()!==r.dataset.modalId||se.current?.focus()};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[]);const de=b(q),ue=b(F);v(()=>{de.current=q},[q]),v(()=>{ue.current=F},[F]),v(()=>x(()=>{const e=ie.current;if(!e)return!1;const t=e.closest("[data-modal-id]");return!(!t||u()!==t.dataset.modalId)&&(de.current?(ee(""),ne(D.current.cancelled),!0):!!ue.current&&(I(!1),ne(D.current.measureOff),!0))}),[]);const pe="px-2 py-1 rounded hover:bg-gray-200 transition-colors text-gray-600 flex items-center gap-1",[me,he]=g(R.typeToMeasure);/* @__PURE__ */
37
37
  return k("div",{ref:ie,className:"flex flex-col h-full",children:[
38
38
  /* @__PURE__ */k(n,{children:[
39
39
  /* @__PURE__ */k("button",{onClick:()=>E(e=>!e),className:pe+(A?" bg-gray-200":""),title:R.layersHint,disabled:0===m.length,children:[
40
40
  /* @__PURE__ */N(p,{name:"layers",className:"h-3.5 w-3.5",strokeWidth:1.5}),R.layers," ",m.length>0&&/* @__PURE__ */k("span",{className:"text-gray-400",children:["(",m.filter(e=>e.visible).length,"/",m.length,")"]})]}),
41
- /* @__PURE__ */N("button",{onClick:()=>S(e=>!e),className:pe,title:T.howToNavigate,children:/* @__PURE__ */N(p,{name:"help",className:"h-3.5 w-3.5",strokeWidth:1.5})}),
41
+ /* @__PURE__ */N("button",{onClick:()=>M(e=>!e),className:pe,title:T.howToNavigate,children:/* @__PURE__ */N(p,{name:"help",className:"h-3.5 w-3.5",strokeWidth:1.5})}),
42
42
  /* @__PURE__ */k("button",{onClick:()=>I(e=>!e),className:pe+(F?" bg-gray-200":""),title:F?T.stopMeasuring:R.measureHint,children:[
43
43
  /* @__PURE__ */k("svg",{className:"h-3.5 w-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:1.5,children:[
44
44
  /* @__PURE__ */N("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"}),
@@ -48,7 +48,7 @@ return k("div",{ref:ie,className:"flex flex-col h-full",children:[
48
48
  /* @__PURE__ */N("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:R.horizontalHint,children:"H"}),
49
49
  /* @__PURE__ */N("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:R.verticalHint,children:"V"}),
50
50
  /* @__PURE__ */N("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:R.pointHint,children:R.point})]}),("horizontal"===P||"vertical"===P)&&/* @__PURE__ */k("div",{className:"flex items-center gap-1",children:[
51
- /* @__PURE__ */N("input",{type:"number",inputMode:"decimal",step:"any",value:_,placeholder:"horizontal"===P?R.fixX:R.fixY,onChange:e=>{const t=e.target.value;if(Y(t),""===t.trim())V(null);else{const e=parseFloat(t);V(Number.isFinite(e)&&0!==e?e:null)}},className:"h-7 w-20 px-2 text-2xs font-mono rounded border border-line bg-surface text-ink focus:outline-none focus:border-orange-400",title:R.fixHint}),null!==U&&/* @__PURE__ */N("button",{onClick:()=>{V(null),Y("")},className:"text-ink-faintest hover:text-gray-600 text-2xs px-1",title:R.clearFixed,children:"×"})]})]}),F&&null!==O&&/* @__PURE__ */k("div",{className:"px-2 py-1 text-2xs font-mono font-semibold text-orange-600 bg-orange-50 border border-orange-200 rounded whitespace-nowrap",title:"horizontal"===X?R.horizontalDistance("auto"===P):"vertical"===X?R.verticalDistance("auto"===P):R.straightDistance,children:[H(O),"horizontal"===X?" ↔":"vertical"===X?" ↕":""]}),
51
+ /* @__PURE__ */N("input",{type:"number",inputMode:"decimal",step:"any",value:_,placeholder:"horizontal"===P?R.fixX:R.fixY,onChange:e=>{const t=e.target.value;if(Y(t),""===t.trim())V(null);else{const e=parseFloat(t);V(Number.isFinite(e)&&0!==e?e:null)}},className:"h-7 w-20 px-2 text-2xs font-mono rounded border border-line bg-surface text-ink focus:outline-none focus:border-orange-400",title:R.fixHint}),null!==U&&/* @__PURE__ */N("button",{onClick:()=>{V(null),Y("")},className:"text-ink-faintest hover:text-gray-600 text-2xs px-1",title:R.clearFixed,children:"×"})]})]}),F&&null!==O&&/* @__PURE__ */k("div",{className:"px-2 py-1 text-2xs font-mono font-semibold text-orange-600 bg-orange-50 border border-orange-200 rounded whitespace-nowrap",title:"horizontal"===G?R.horizontalDistance("auto"===P):"vertical"===G?R.verticalDistance("auto"===P):R.straightDistance,children:[H(O),"horizontal"===G?" ↔":"vertical"===G?" ↕":""]}),
52
52
  /* @__PURE__ */N("button",{onClick:ce,className:pe,title:R.fitHint,children:R.fit}),
53
53
  /* @__PURE__ */k("button",{onClick:r??(()=>{const n=document.createElement("a");n.href=e,n.download=t,n.click()}),className:pe,children:[
54
54
  /* @__PURE__ */N(p,{name:"download",className:"h-3.5 w-3.5",strokeWidth:1.5}),T.download]}),s&&/* @__PURE__ */k("button",{onClick:s,className:pe,children:[
@@ -79,7 +79,7 @@ return k("div",{ref:ie,className:"flex flex-col h-full",children:[
79
79
  /* @__PURE__ */k("div",{className:"shrink-0 border-t border-gray-200 bg-gray-50",children:[te&&/* @__PURE__ */N("div",{className:"px-3 pt-1 text-2xs font-mono text-ink-faint truncate",title:te,children:te}),
80
80
  /* @__PURE__ */k("div",{className:"flex items-center gap-2 px-3 h-7",children:[
81
81
  /* @__PURE__ */N("span",{className:"text-2xs font-mono font-semibold text-ink-faintest select-none",children:">"}),
82
- /* @__PURE__ */N("input",{ref:se,value:q,onChange:e=>ee(e.target.value),onKeyDown:e=>{"Enter"===e.key||" "===e.key?(e.preventDefault(),(e=>{const t=e.trim()||re.current;if(ee(""),!t)return;const n=t.toLowerCase().split(/\s+/)[0],r=()=>{re.current=t},s=(e,t)=>{I(!0),W(e),J.current?.(),ne(t),r()};if(/^-?(\d+\.?\d*|\.\d+)$/.test(n))if(!F||"horizontal"!==P&&"vertical"!==P)ne(R.fixedNeedsAxis);else{const e=parseFloat(n);e?(Y(n),V(e),ne(R.axisLocked("horizontal"===P?"ΔX":"ΔY",H(Math.abs(e))))):(Y(""),V(null),ne(R.fixedCleared))}else switch(n){case"di":case"dist":case"mea":case"measuregeom":s("point",R.echoDist);break;case"dim":case"dli":case"dimlin":case"dimlinear":s("auto",R.echoDimLinear);break;case"h":case"hor":case"horizontal":I(!0),W("horizontal"),ne(R.echoHorizontal),r();break;case"v":case"ver":case"vertical":I(!0),W("vertical"),ne(R.echoVertical),r();break;case"au":case"auto":I(!0),W("auto"),ne(R.echoAuto),r();break;case"measure":I(!F),ne(F?R.measureOff:R.measureOn),r();break;case"u":case"undo":Q.current?.(),ne(R.pickRemoved),r();break;case"z":case"ze":case"zoom":case"fit":case"zoomextents":ce(),ne(R.zoomExtents),r();break;case"la":case"layer":case"layers":E(e=>!e),ne(R.layersToggled),r();break;case"off":case"clear":V(null),Y(""),J.current?.(),ne(R.measurementCleared),r();break;case"?":case"help":ne(R.commandHelp);break;default:{const e=j[n];ne(e?R.readOnly(e):R.unknownCommand(n.toUpperCase()))}}})(q)):"Escape"===e.key&&(q?(e.stopPropagation(),ee(""),ne(R.cancelled)):e.target.blur())},placeholder:R.commandPlaceholder,spellCheck:!1,autoComplete:"off",className:"flex-1 min-w-0 bg-transparent text-2xs font-mono text-ink focus:outline-none placeholder:text-gray-300"})]})]})]})}var R="https://cdn.jsdelivr.net/npm/online-3d-viewer@0.18.0/libs/";function T(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=>T(e,t,n+1))}}function D(e,t){t.add(e.id);for(const n of e.children)D(n,t)}function F(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 H(e){return e>=1e3?`${(e/1e3).toFixed(3)} m`:`${e.toFixed(2)} mm`}function I({url:e,filename:t,onDownload:r,onEmail:s}){const i=b(null),o=b(null),a=b(null),[l,c]=w(!0),[d,u]=w(null),[m,f]=w(!0),x=y(),g=x.model,C=x.preview,E=b(g);E.current=g;const[L,S]=w(null),[M,j]=w({}),[z,I]=w(/* @__PURE__ */new Set),[P,W]=w("#f5f6f8"),[O,G]=w(!0),[X,B]=w("#000000"),[U,V]=w(1),[_,Y]=w(!1),[Z,$]=w(!1),[K,J]=w(!1),[Q,q]=w(!1),[ee,te]=w("x"),[ne,re]=w(!1),[se,ie]=w(.5),[oe,ae]=w(0),[le,ce]=w(!1),[de,ue]=w("point"),[pe,me]=w(null),he=b(null),fe=b(null);v(()=>{let n=!1,r=null,s=null;return c(!0),u(null),S(null),j({}),I(/* @__PURE__ */new Set),(async()=>{let l;try{l=await(import("online-3d-viewer"))}catch{return void(n||(u(E.current.notInstalled),c(!1)))}if(a.current=l,!n&&i.current&&(await new Promise(e=>{const t=()=>{const n=i.current?.getBoundingClientRect();n&&n.width>4&&n.height>4?e():requestAnimationFrame(t)};t()}),!n&&i.current))try{const a="undefined"!=typeof window&&window.__REACT_OS_SHELL_O3DV_LIBS__||R;l.SetExternalLibLocation?.(a),function(){if(A)return;if("undefined"==typeof HTMLCanvasElement)return;A=!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(i.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=T(t,{root:E.current.rootNode,node:E.current.node});S(e);const n={[e.id]:!0};for(const t of e.children)n[t.id]=!0;j(n)}}catch(e){console.warn("[Preview] mesh tree extraction failed",e)}c(!1)}},onModelLoadFailed:()=>{n||(u(E.current.loadFailed),c(!1))}}),o.current=r;const d=new l.InputFile(t,l.FileSource.Url,e);r.LoadModelFromInputFiles([d]),i.current&&"undefined"!=typeof ResizeObserver&&(s=new ResizeObserver(()=>{try{const e=o.current;e?.Resize?e.Resize():e?.viewer?.Resize&&e.viewer.Resize(),e?.viewer?.Render?.()}catch{}}),s.observe(i.current))}catch(e){n||(u(e?.message||E.current.loadFailed),c(!1))}})(),()=>{n=!0;try{s?.disconnect()}catch{}try{r?.Destroy?.()}catch{}o.current=null}},[e,t]),v(()=>{const e=o.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=!z.has(n))};e.viewer.mainModel?.EnumerateMeshesAndLines?.(t),e.viewer.mainModel?.EnumerateEdges?.(t),e.viewer.Render?.()}catch(e){console.warn("[Preview] visibility update failed",e)}},[z,L]),v(()=>{const e=a.current,t=o.current;if(e&&t?.viewer)try{t.viewer.SetEdgeSettings(new e.EdgeSettings(O,F(e,X),U));const n=fe.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,s=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)s(e);else s(t)})}t.viewer.Render?.()}catch{}},[O,X,U]),v(()=>{const e=a.current,t=o.current;if(e&&t?.viewer)try{const n=F(e,P);t.viewer.SetBackgroundColor(new e.RGBAColor(n.r,n.g,n.b,255)),t.viewer.Render?.()}catch{}},[P]),v(()=>{const e=o.current;if(!e?.viewer||l)return;const t=e.viewer.renderer,n=e.viewer.scene;if(!t||!n)return;if(fe.current){const e=fe.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?.()),fe.current=null}if(!Q)return t.localClippingEnabled=!1,void e.viewer.Render?.();const r=e.viewer.GetBoundingBox?.(()=>!0);if(!r)return;const s=[];if(e.viewer.mainModel?.EnumerateMeshes?.(e=>{e.userData?.__sectionHelper||s.push(e)}),!s.length)return t.localClippingEnabled=!1,void e.viewer.Render?.();const i=s[0],a=i.constructor,c=i.material?.constructor,d=i.geometry?.constructor,u=i.geometry?.attributes?.position?.constructor;a&&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 =",s.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}},f=[],x=/* @__PURE__ */new Map,y=e=>{e&&!x.has(e)&&(x.set(e,{clippingPlanes:e.clippingPlanes,clipShadows:e.clipShadows}),e.clippingPlanes=[h],e.clipShadows=!0,e.needsUpdate=!0)};for(const e of s){const t=e.material;if(Array.isArray(t))for(const e of t)y(e);else y(t);const n=Array.isArray(t)?t[0]:t;if(a&&m&&n?.clone){const t=(t,r)=>{const s=n.clone();s.depthWrite=!1,s.depthTest=!1,s.colorWrite=!1,s.stencilWrite=!0,s.stencilFunc=519,s.stencilFail=r,s.stencilZFail=r,s.stencilZPass=r,s.side=t,s.transparent=!1,s.clippingPlanes=[h],s.clipShadows=!0,s.needsUpdate=!0;const i=new a(e.geometry,s);i.matrixAutoUpdate=!1,i.renderOrder=1,i.userData.__sectionHelper=!0,e.add(i),f.push(i)};t(1,7682),t(0,7683)}}e.viewer.mainModel?.EnumerateEdges?.(e=>{const t=e.material;if(Array.isArray(t))for(const e of t)y(e);else y(t)});let g=null;const b=s[0]?.material&&(Array.isArray(s[0].material)?s[0].material[0]:s[0].material);if(m&&a&&d&&u&&b?.clone){const e=r.max.x-r.min.x,t=r.max.y-r.min.y,s=r.max.z-r.min.z,i=2*Math.max(e,t,s,1)/2,o=new d,l=new Float32Array([-i,-i,0,i,-i,0,i,i,0,-i,i,0]),c=new Float32Array([0,0,1,0,0,1,0,0,1,0,0,1]);o.setAttribute("position",new u(l,3)),o.setAttribute("normal",new u(c,3)),o.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 a(o,m),g.renderOrder=2,g.userData.__sectionHelper=!0,n.add(g)}fe.current={plane:h,capMesh:g,helpers:f,materialState:x,bbox:r},console.info("[Preview] section: helpers =",f.length,"cap =",!!g),e.viewer.Render?.()},[Q,l,L]),v(()=>{const e=o.current,t=fe.current;if(e?.viewer&&t&&Q)try{const n=t.bbox,r="x"===ee?0:"y"===ee?1:2,s=[n.min.x,n.min.y,n.min.z][r],i=s+([n.max.x,n.max.y,n.max.z][r]-s)*se,o=oe*Math.PI/180,a=Math.cos(o),l=Math.sin(o),c=ne?-1:1;let d=0,u=0,p=0;"x"===ee?(d=c*a,p=c*l):"y"===ee?(u=c*a,d=c*l):(p=c*a,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"===ee?i:m.x,f="y"===ee?i:m.y,x="z"===ee?i:m.z;if(t.plane.normal.x=d,t.plane.normal.y=u,t.plane.normal.z=p,t.plane.constant=-(d*h+u*f+p*x),t.capMesh){const e=m.x,n=m.y,r=m.z,s=d*e+u*n+p*r+t.plane.constant,i=e-d*s,o=n-u*s,a=r-p*s;t.capMesh.position.set(i,o,a),t.capMesh.lookAt?.(i+d,o+u,a+p)}e.viewer.Render?.()}catch(e){console.warn("[Preview] section update failed",e)}},[Q,ee,ne,se,oe]),v(()=>{const e=o.current;if(!e?.viewer||l||!i.current)return;const t=e.viewer.renderer,n=e.viewer.scene,r=t?.domElement;if(!t||!n||!r)return;let s=null;if(e.viewer.mainModel?.EnumerateMeshes?.(e=>{s||e.userData?.__sectionHelper||e.userData?.__measureHelper||(s=e)}),!s)return;const c=s.position.constructor,d=s.constructor,u=(Array.isArray(s.material)?s.material[0]:s.material)?.constructor,p=s.geometry.constructor,m=s.geometry.attributes?.position?.constructor;if(!(c&&d&&u&&p&&m))return;let h=null,f=null;n.traverse(e=>{if(h&&f)return;if(!e?.isLineSegments)return;h=e.constructor;const t=Array.isArray(e.material)?e.material[0]:e.material;t?.constructor&&(f=t.constructor)});const x=()=>{const t=he.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),he.current=null,e.viewer.Render?.()}};if(!le)return x(),void me(null);he.current={points:[],normals:[],markers:[],line:null,label:null,rafId:null};const y=a.current,g=y?.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,s=n+16+1;r.push(n,s,n+1,s,s+1,n+1)}const s=new p;s.setAttribute("position",new m(new Float32Array(t),3)),s.setIndex(r),s.computeVertexNormals?.();const i=new u;i.color?.setHex?.(16746496),i.depthTest=!1,i.depthWrite=!1,i.transparent=!0,i.opacity=.95;const o=new d(s,i);return o.position.copy(e),o.renderOrder=9999,o.userData.__measureHelper=!0,n.add(o),o},N=()=>{const t=he.current;t&&((()=>{const t=he.current;if(!t||t.points.length<2||!t.label)return;const n=e.viewer.camera;if(!n)return;const s=t.points[0],i=t.points[1],o=new c((s.x+i.x)/2,(s.y+i.y)/2,(s.z+i.z)/2).clone();o.project?.(n);const a=r.getBoundingClientRect(),l=(o.x+1)/2*a.width,d=(1-o.y)/2*a.height;t.label.style.left=`${l}px`,t.label.style.top=`${d}px`;const u=l<0||d<0||l>a.width||d>a.height;t.label.style.opacity=o.z>1||u?"0":"1"})(),t.rafId=requestAnimationFrame(N))};he.current.rafId=requestAnimationFrame(N);let C=0,A=0,E=0,L=!1,S=!1;const M=t=>{if(!e.viewer.camera)return;const s=r.getBoundingClientRect(),o={x:t.clientX-s.left,y:t.clientY-s.top},a=e.viewer.GetMeshIntersectionUnderMouse?.(g,o);if(!a)return;const l=he.current,x=new c(a.point.x,a.point.y,a.point.z),y=(e=>{const t=e?.face?.normal,n=e?.object;if(!t||!n)return null;try{const e=new c(t.x,t.y,t.z);return e.transformDirection?.(n.matrixWorld),{x:e.x,y:e.y,z:e.z}}catch{return{x:t.x,y:t.y,z:t.z}}})(a);if(2===l.points.length){for(const e of l.markers)n.remove(e),e.geometry?.dispose?.(),e.material?.dispose?.();l.line&&(n.remove(l.line),l.line.geometry?.dispose?.(),l.line.material?.dispose?.()),l.label&&(l.label.style.opacity="0"),l.points=[],l.markers=[],l.line=null,l.normals=[],me(null)}if(l.points.push(x),l.normals.push(y),"perp"===de){const e=((e,t)=>{const r=e?.geometry,s=r?.attributes?.position;if(!r||!s||!t?.face?.normal)return null;const i=s.array,o=r.index?r.index.array:null,a=new c(t.point.x,t.point.y,t.point.z);e.worldToLocal?.(a);const l=t.face.normal,h=-(l.x*a.x+l.y*a.y+l.z*a.z);r.computeBoundingBox?.();const f=r.boundingBox,x=f?Math.sqrt((f.max.x-f.min.x)**2+(f.max.y-f.min.y)**2+(f.max.z-f.min.z)**2):100,y=Math.max(.001*x,.005),g=o?o.length/3:s.count/3,b=[],w=new c;for(let t=0;t<g;t++){const n=o?o[3*t]:3*t,r=o?o[3*t+1]:3*t+1,s=o?o[3*t+2]:3*t+2,a=i[3*n],c=i[3*n+1],d=i[3*n+2],u=i[3*r],p=i[3*r+1],m=i[3*r+2],f=i[3*s],x=i[3*s+1],g=i[3*s+2],v=u-a,k=p-c,N=m-d,C=f-a,A=x-c,E=g-d;let L=k*E-N*A,S=N*C-v*E,M=v*A-k*C;const j=Math.sqrt(L*L+S*S+M*M);if(0===j)continue;if(L/=j,S/=j,M/=j,L*l.x+S*l.y+M*l.z<.9995)continue;const z=(a+u+f)/3,R=(c+p+x)/3,T=(d+m+g)/3;if(!(Math.abs(l.x*z+l.y*R+l.z*T+h)>y))for(const[t,n,r]of[[a,c,d],[u,p,m],[f,x,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})(a.object,a);l.markers.push(e??k(x))}else l.markers.push(k(x));if(2===l.points.length){const e=l.points[0];let t,r=l.points[1],s="";if("perp"===de){const n=l.normals[0]??l.normals[1];if(n){const i=Math.sqrt(n.x*n.x+n.y*n.y+n.z*n.z)||1,o=n.x/i,a=n.y/i,d=n.z/i,u=(r.x-e.x)*o+(r.y-e.y)*a+(r.z-e.z)*d,p=new c(e.x+o*u,e.y+a*u,e.z+d*u);l.points[1]=p,r=p,t=Math.abs(u),s=" ⊥"}else{const n=r.x-e.x,s=r.y-e.y,i=r.z-e.z;t=Math.sqrt(n*n+s*s+i*i)}}else{const n=r.x-e.x,s=r.y-e.y,i=r.z-e.z;t=Math.sqrt(n*n+s*s+i*i)}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 s=new(h??d)(r,new(f??u)({color:16746496,depthTest:!1,depthWrite:!1,transparent:!0,opacity:.95}));return s.renderOrder=9998,s.userData.__measureHelper=!0,n.add(s),s})(e,r),me(t);const o=(()=>{const e=he.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",i.current.appendChild(t),e.label=t,t})();o.textContent=`${H(t)}${s}`}e.viewer.Render?.()},j=e=>{0===e.button&&(C=e.clientX,A=e.clientY,E=performance.now(),L=!1,S=!0)},z=e=>{if(!S)return;const t=e.clientX-C,n=e.clientY-A;t*t+n*n>16&&(L=!0)},R=e=>{if(0!==e.button||!S)return;const t=performance.now()-E;S=!1,!L&&t<350&&M(e)},T=e=>{"Escape"===e.key&&ce(!1)};return r.style.cursor="crosshair",r.addEventListener("pointerdown",j),r.addEventListener("pointermove",z),r.addEventListener("pointerup",R),r.addEventListener("pointercancel",R),window.addEventListener("keydown",T),()=>{r.style.cursor="",r.removeEventListener("pointerdown",j),r.removeEventListener("pointermove",z),r.removeEventListener("pointerup",R),r.removeEventListener("pointercancel",R),window.removeEventListener("keydown",T),x(),me(null)}},[le,de,l,L]),v(()=>{if(!m||l)return;const e=setTimeout(()=>f(!1),5e3);return()=>clearTimeout(e)},[m,l]);const xe=e=>{const t=/* @__PURE__ */new Set;D(e,t),I(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})},ye=()=>{try{const e=o.current,t=e?.viewer?.GetBoundingSphere?.(()=>!0);t&&e.viewer.FitSphereToWindow(t,!0),e?.viewer?.Render?.()}catch{}};v(()=>{const e=a.current,t=o.current;if(e&&t?.viewer&&!l)try{t.viewer.SetProjectionMode(K?e.ProjectionMode.Perspective:e.ProjectionMode.Orthographic)}catch{}},[K,l]);const ge=e=>{const t=a.current,n=o.current;if(t&&n?.viewer)try{const r=n.viewer.GetBoundingSphere?.(()=>!0);if(!r)return;const s=r.center,i=3*(r.radius||1),o=s.x??0,a=s.y??0,l=s.z??0;let c,d;switch(e){case"top":c=new t.Coord3D(o,a,l+i),d=new t.Coord3D(0,1,0);break;case"front":c=new t.Coord3D(o,a-i,l),d=new t.Coord3D(0,0,1);break;case"side":c=new t.Coord3D(o+i,a,l),d=new t.Coord3D(0,0,1);break;default:{const e=i/Math.sqrt(3);c=new t.Coord3D(o+e,a-e,l+e),d=new t.Coord3D(0,0,1);break}}const u=new t.Coord3D(o,a,l),p=new t.Camera(c,u,d,45);n.viewer.SetCamera(p),n.viewer.AdjustClippingPlanesToSphere?.(r),n.viewer.Render?.()}catch{}},be=(t.split(".").pop()||"").toUpperCase(),we=(e,t=0)=>{const n=e.children.length>0,r=!1!==M[e.id],s=!z.has(e.id);/* @__PURE__ */
82
+ /* @__PURE__ */N("input",{ref:se,value:q,onChange:e=>ee(e.target.value),onKeyDown:e=>{"Enter"===e.key||" "===e.key?(e.preventDefault(),(e=>{const t=e.trim()||re.current;if(ee(""),!t)return;const n=t.toLowerCase().split(/\s+/)[0],r=()=>{re.current=t},s=(e,t)=>{I(!0),W(e),K.current?.(),ne(t),r()};if(/^-?(\d+\.?\d*|\.\d+)$/.test(n))if(!F||"horizontal"!==P&&"vertical"!==P)ne(R.fixedNeedsAxis);else{const e=parseFloat(n);e?(Y(n),V(e),ne(R.axisLocked("horizontal"===P?"ΔX":"ΔY",H(Math.abs(e))))):(Y(""),V(null),ne(R.fixedCleared))}else switch(n){case"di":case"dist":case"mea":case"measuregeom":s("point",R.echoDist);break;case"dim":case"dli":case"dimlin":case"dimlinear":s("auto",R.echoDimLinear);break;case"h":case"hor":case"horizontal":I(!0),W("horizontal"),ne(R.echoHorizontal),r();break;case"v":case"ver":case"vertical":I(!0),W("vertical"),ne(R.echoVertical),r();break;case"au":case"auto":I(!0),W("auto"),ne(R.echoAuto),r();break;case"measure":I(!F),ne(F?R.measureOff:R.measureOn),r();break;case"u":case"undo":Q.current?.(),ne(R.pickRemoved),r();break;case"z":case"ze":case"zoom":case"fit":case"zoomextents":ce(),ne(R.zoomExtents),r();break;case"la":case"layer":case"layers":E(e=>!e),ne(R.layersToggled),r();break;case"off":case"clear":V(null),Y(""),K.current?.(),ne(R.measurementCleared),r();break;case"?":case"help":ne(R.commandHelp);break;default:{const e=j[n];ne(e?R.readOnly(e):R.unknownCommand(n.toUpperCase()))}}})(q)):"Escape"===e.key&&(q?(e.stopPropagation(),ee(""),ne(R.cancelled)):e.target.blur())},placeholder:R.commandPlaceholder,spellCheck:!1,autoComplete:"off",className:"flex-1 min-w-0 bg-transparent text-2xs font-mono text-ink focus:outline-none placeholder:text-gray-300"})]})]})]})}var R="https://cdn.jsdelivr.net/npm/online-3d-viewer@0.18.0/libs/";function T(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=>T(e,t,n+1))}}function D(e,t){t.add(e.id);for(const n of e.children)D(n,t)}function F(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 H(e){return e>=1e3?`${(e/1e3).toFixed(3)} m`:`${e.toFixed(2)} mm`}function I({url:e,filename:t,onDownload:r,onEmail:s}){const i=b(null),o=b(null),a=b(null),[l,c]=w(!0),[d,u]=w(null),[m,f]=w(!0),x=y(),g=x.model,C=x.preview,E=b(g);E.current=g;const[L,M]=w(null),[S,j]=w({}),[z,I]=w(/* @__PURE__ */new Set),[P,W]=w("#f5f6f8"),[O,X]=w(!0),[G,B]=w("#000000"),[U,V]=w(1),[_,Y]=w(!1),[Z,$]=w(!1),[J,K]=w(!1),[Q,q]=w(!1),[ee,te]=w("x"),[ne,re]=w(!1),[se,ie]=w(.5),[oe,ae]=w(0),[le,ce]=w(!1),[de,ue]=w("point"),[pe,me]=w(null),he=b(null),fe=b(null);v(()=>{let n=!1,r=null,s=null;return c(!0),u(null),M(null),j({}),I(/* @__PURE__ */new Set),(async()=>{let l;try{l=await(import("online-3d-viewer"))}catch{return void(n||(u(E.current.notInstalled),c(!1)))}if(a.current=l,!n&&i.current&&(await new Promise(e=>{const t=()=>{const n=i.current?.getBoundingClientRect();n&&n.width>4&&n.height>4?e():requestAnimationFrame(t)};t()}),!n&&i.current))try{const a="undefined"!=typeof window&&window.__REACT_OS_SHELL_O3DV_LIBS__||R;l.SetExternalLibLocation?.(a),function(){if(A)return;if("undefined"==typeof HTMLCanvasElement)return;A=!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(i.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=T(t,{root:E.current.rootNode,node:E.current.node});M(e);const n={[e.id]:!0};for(const t of e.children)n[t.id]=!0;j(n)}}catch(e){console.warn("[Preview] mesh tree extraction failed",e)}c(!1)}},onModelLoadFailed:()=>{n||(u(E.current.loadFailed),c(!1))}}),o.current=r;const d=new l.InputFile(t,l.FileSource.Url,e);r.LoadModelFromInputFiles([d]),i.current&&"undefined"!=typeof ResizeObserver&&(s=new ResizeObserver(()=>{try{const e=o.current;e?.Resize?e.Resize():e?.viewer?.Resize&&e.viewer.Resize(),e?.viewer?.Render?.()}catch{}}),s.observe(i.current))}catch(e){n||(u(e?.message||E.current.loadFailed),c(!1))}})(),()=>{n=!0;try{s?.disconnect()}catch{}try{r?.Destroy?.()}catch{}o.current=null}},[e,t]),v(()=>{const e=o.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=!z.has(n))};e.viewer.mainModel?.EnumerateMeshesAndLines?.(t),e.viewer.mainModel?.EnumerateEdges?.(t),e.viewer.Render?.()}catch(e){console.warn("[Preview] visibility update failed",e)}},[z,L]),v(()=>{const e=a.current,t=o.current;if(e&&t?.viewer)try{t.viewer.SetEdgeSettings(new e.EdgeSettings(O,F(e,G),U));const n=fe.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,s=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)s(e);else s(t)})}t.viewer.Render?.()}catch{}},[O,G,U]),v(()=>{const e=a.current,t=o.current;if(e&&t?.viewer)try{const n=F(e,P);t.viewer.SetBackgroundColor(new e.RGBAColor(n.r,n.g,n.b,255)),t.viewer.Render?.()}catch{}},[P]),v(()=>{const e=o.current;if(!e?.viewer||l)return;const t=e.viewer.renderer,n=e.viewer.scene;if(!t||!n)return;if(fe.current){const e=fe.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?.()),fe.current=null}if(!Q)return t.localClippingEnabled=!1,void e.viewer.Render?.();const r=e.viewer.GetBoundingBox?.(()=>!0);if(!r)return;const s=[];if(e.viewer.mainModel?.EnumerateMeshes?.(e=>{e.userData?.__sectionHelper||s.push(e)}),!s.length)return t.localClippingEnabled=!1,void e.viewer.Render?.();const i=s[0],a=i.constructor,c=i.material?.constructor,d=i.geometry?.constructor,u=i.geometry?.attributes?.position?.constructor;a&&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 =",s.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}},f=[],x=/* @__PURE__ */new Map,y=e=>{e&&!x.has(e)&&(x.set(e,{clippingPlanes:e.clippingPlanes,clipShadows:e.clipShadows}),e.clippingPlanes=[h],e.clipShadows=!0,e.needsUpdate=!0)};for(const e of s){const t=e.material;if(Array.isArray(t))for(const e of t)y(e);else y(t);const n=Array.isArray(t)?t[0]:t;if(a&&m&&n?.clone){const t=(t,r)=>{const s=n.clone();s.depthWrite=!1,s.depthTest=!1,s.colorWrite=!1,s.stencilWrite=!0,s.stencilFunc=519,s.stencilFail=r,s.stencilZFail=r,s.stencilZPass=r,s.side=t,s.transparent=!1,s.clippingPlanes=[h],s.clipShadows=!0,s.needsUpdate=!0;const i=new a(e.geometry,s);i.matrixAutoUpdate=!1,i.renderOrder=1,i.userData.__sectionHelper=!0,e.add(i),f.push(i)};t(1,7682),t(0,7683)}}e.viewer.mainModel?.EnumerateEdges?.(e=>{const t=e.material;if(Array.isArray(t))for(const e of t)y(e);else y(t)});let g=null;const b=s[0]?.material&&(Array.isArray(s[0].material)?s[0].material[0]:s[0].material);if(m&&a&&d&&u&&b?.clone){const e=r.max.x-r.min.x,t=r.max.y-r.min.y,s=r.max.z-r.min.z,i=2*Math.max(e,t,s,1)/2,o=new d,l=new Float32Array([-i,-i,0,i,-i,0,i,i,0,-i,i,0]),c=new Float32Array([0,0,1,0,0,1,0,0,1,0,0,1]);o.setAttribute("position",new u(l,3)),o.setAttribute("normal",new u(c,3)),o.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 a(o,m),g.renderOrder=2,g.userData.__sectionHelper=!0,n.add(g)}fe.current={plane:h,capMesh:g,helpers:f,materialState:x,bbox:r},console.info("[Preview] section: helpers =",f.length,"cap =",!!g),e.viewer.Render?.()},[Q,l,L]),v(()=>{const e=o.current,t=fe.current;if(e?.viewer&&t&&Q)try{const n=t.bbox,r="x"===ee?0:"y"===ee?1:2,s=[n.min.x,n.min.y,n.min.z][r],i=s+([n.max.x,n.max.y,n.max.z][r]-s)*se,o=oe*Math.PI/180,a=Math.cos(o),l=Math.sin(o),c=ne?-1:1;let d=0,u=0,p=0;"x"===ee?(d=c*a,p=c*l):"y"===ee?(u=c*a,d=c*l):(p=c*a,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"===ee?i:m.x,f="y"===ee?i:m.y,x="z"===ee?i:m.z;if(t.plane.normal.x=d,t.plane.normal.y=u,t.plane.normal.z=p,t.plane.constant=-(d*h+u*f+p*x),t.capMesh){const e=m.x,n=m.y,r=m.z,s=d*e+u*n+p*r+t.plane.constant,i=e-d*s,o=n-u*s,a=r-p*s;t.capMesh.position.set(i,o,a),t.capMesh.lookAt?.(i+d,o+u,a+p)}e.viewer.Render?.()}catch(e){console.warn("[Preview] section update failed",e)}},[Q,ee,ne,se,oe]),v(()=>{const e=o.current;if(!e?.viewer||l||!i.current)return;const t=e.viewer.renderer,n=e.viewer.scene,r=t?.domElement;if(!t||!n||!r)return;let s=null;if(e.viewer.mainModel?.EnumerateMeshes?.(e=>{s||e.userData?.__sectionHelper||e.userData?.__measureHelper||(s=e)}),!s)return;const c=s.position.constructor,d=s.constructor,u=(Array.isArray(s.material)?s.material[0]:s.material)?.constructor,p=s.geometry.constructor,m=s.geometry.attributes?.position?.constructor;if(!(c&&d&&u&&p&&m))return;let h=null,f=null;n.traverse(e=>{if(h&&f)return;if(!e?.isLineSegments)return;h=e.constructor;const t=Array.isArray(e.material)?e.material[0]:e.material;t?.constructor&&(f=t.constructor)});const x=()=>{const t=he.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),he.current=null,e.viewer.Render?.()}};if(!le)return x(),void me(null);he.current={points:[],normals:[],markers:[],line:null,label:null,rafId:null};const y=a.current,g=y?.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,s=n+16+1;r.push(n,s,n+1,s,s+1,n+1)}const s=new p;s.setAttribute("position",new m(new Float32Array(t),3)),s.setIndex(r),s.computeVertexNormals?.();const i=new u;i.color?.setHex?.(16746496),i.depthTest=!1,i.depthWrite=!1,i.transparent=!0,i.opacity=.95;const o=new d(s,i);return o.position.copy(e),o.renderOrder=9999,o.userData.__measureHelper=!0,n.add(o),o},N=()=>{const t=he.current;t&&((()=>{const t=he.current;if(!t||t.points.length<2||!t.label)return;const n=e.viewer.camera;if(!n)return;const s=t.points[0],i=t.points[1],o=new c((s.x+i.x)/2,(s.y+i.y)/2,(s.z+i.z)/2).clone();o.project?.(n);const a=r.getBoundingClientRect(),l=(o.x+1)/2*a.width,d=(1-o.y)/2*a.height;t.label.style.left=`${l}px`,t.label.style.top=`${d}px`;const u=l<0||d<0||l>a.width||d>a.height;t.label.style.opacity=o.z>1||u?"0":"1"})(),t.rafId=requestAnimationFrame(N))};he.current.rafId=requestAnimationFrame(N);let C=0,A=0,E=0,L=!1,M=!1;const S=t=>{if(!e.viewer.camera)return;const s=r.getBoundingClientRect(),o={x:t.clientX-s.left,y:t.clientY-s.top},a=e.viewer.GetMeshIntersectionUnderMouse?.(g,o);if(!a)return;const l=he.current,x=new c(a.point.x,a.point.y,a.point.z),y=(e=>{const t=e?.face?.normal,n=e?.object;if(!t||!n)return null;try{const e=new c(t.x,t.y,t.z);return e.transformDirection?.(n.matrixWorld),{x:e.x,y:e.y,z:e.z}}catch{return{x:t.x,y:t.y,z:t.z}}})(a);if(2===l.points.length){for(const e of l.markers)n.remove(e),e.geometry?.dispose?.(),e.material?.dispose?.();l.line&&(n.remove(l.line),l.line.geometry?.dispose?.(),l.line.material?.dispose?.()),l.label&&(l.label.style.opacity="0"),l.points=[],l.markers=[],l.line=null,l.normals=[],me(null)}if(l.points.push(x),l.normals.push(y),"perp"===de){const e=((e,t)=>{const r=e?.geometry,s=r?.attributes?.position;if(!r||!s||!t?.face?.normal)return null;const i=s.array,o=r.index?r.index.array:null,a=new c(t.point.x,t.point.y,t.point.z);e.worldToLocal?.(a);const l=t.face.normal,h=-(l.x*a.x+l.y*a.y+l.z*a.z);r.computeBoundingBox?.();const f=r.boundingBox,x=f?Math.sqrt((f.max.x-f.min.x)**2+(f.max.y-f.min.y)**2+(f.max.z-f.min.z)**2):100,y=Math.max(.001*x,.005),g=o?o.length/3:s.count/3,b=[],w=new c;for(let t=0;t<g;t++){const n=o?o[3*t]:3*t,r=o?o[3*t+1]:3*t+1,s=o?o[3*t+2]:3*t+2,a=i[3*n],c=i[3*n+1],d=i[3*n+2],u=i[3*r],p=i[3*r+1],m=i[3*r+2],f=i[3*s],x=i[3*s+1],g=i[3*s+2],v=u-a,k=p-c,N=m-d,C=f-a,A=x-c,E=g-d;let L=k*E-N*A,M=N*C-v*E,S=v*A-k*C;const j=Math.sqrt(L*L+M*M+S*S);if(0===j)continue;if(L/=j,M/=j,S/=j,L*l.x+M*l.y+S*l.z<.9995)continue;const z=(a+u+f)/3,R=(c+p+x)/3,T=(d+m+g)/3;if(!(Math.abs(l.x*z+l.y*R+l.z*T+h)>y))for(const[t,n,r]of[[a,c,d],[u,p,m],[f,x,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})(a.object,a);l.markers.push(e??k(x))}else l.markers.push(k(x));if(2===l.points.length){const e=l.points[0];let t,r=l.points[1],s="";if("perp"===de){const n=l.normals[0]??l.normals[1];if(n){const i=Math.sqrt(n.x*n.x+n.y*n.y+n.z*n.z)||1,o=n.x/i,a=n.y/i,d=n.z/i,u=(r.x-e.x)*o+(r.y-e.y)*a+(r.z-e.z)*d,p=new c(e.x+o*u,e.y+a*u,e.z+d*u);l.points[1]=p,r=p,t=Math.abs(u),s=" ⊥"}else{const n=r.x-e.x,s=r.y-e.y,i=r.z-e.z;t=Math.sqrt(n*n+s*s+i*i)}}else{const n=r.x-e.x,s=r.y-e.y,i=r.z-e.z;t=Math.sqrt(n*n+s*s+i*i)}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 s=new(h??d)(r,new(f??u)({color:16746496,depthTest:!1,depthWrite:!1,transparent:!0,opacity:.95}));return s.renderOrder=9998,s.userData.__measureHelper=!0,n.add(s),s})(e,r),me(t);const o=(()=>{const e=he.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",i.current.appendChild(t),e.label=t,t})();o.textContent=`${H(t)}${s}`}e.viewer.Render?.()},j=e=>{0===e.button&&(C=e.clientX,A=e.clientY,E=performance.now(),L=!1,M=!0)},z=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)},T=e=>{"Escape"===e.key&&ce(!1)};return r.style.cursor="crosshair",r.addEventListener("pointerdown",j),r.addEventListener("pointermove",z),r.addEventListener("pointerup",R),r.addEventListener("pointercancel",R),window.addEventListener("keydown",T),()=>{r.style.cursor="",r.removeEventListener("pointerdown",j),r.removeEventListener("pointermove",z),r.removeEventListener("pointerup",R),r.removeEventListener("pointercancel",R),window.removeEventListener("keydown",T),x(),me(null)}},[le,de,l,L]),v(()=>{if(!m||l)return;const e=setTimeout(()=>f(!1),5e3);return()=>clearTimeout(e)},[m,l]);const xe=e=>{const t=/* @__PURE__ */new Set;D(e,t),I(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})},ye=()=>{try{const e=o.current,t=e?.viewer?.GetBoundingSphere?.(()=>!0);t&&e.viewer.FitSphereToWindow(t,!0),e?.viewer?.Render?.()}catch{}};v(()=>{const e=a.current,t=o.current;if(e&&t?.viewer&&!l)try{t.viewer.SetProjectionMode(J?e.ProjectionMode.Perspective:e.ProjectionMode.Orthographic)}catch{}},[J,l]);const ge=e=>{const t=a.current,n=o.current;if(t&&n?.viewer)try{const r=n.viewer.GetBoundingSphere?.(()=>!0);if(!r)return;const s=r.center,i=3*(r.radius||1),o=s.x??0,a=s.y??0,l=s.z??0;let c,d;switch(e){case"top":c=new t.Coord3D(o,a,l+i),d=new t.Coord3D(0,1,0);break;case"front":c=new t.Coord3D(o,a-i,l),d=new t.Coord3D(0,0,1);break;case"side":c=new t.Coord3D(o+i,a,l),d=new t.Coord3D(0,0,1);break;default:{const e=i/Math.sqrt(3);c=new t.Coord3D(o+e,a-e,l+e),d=new t.Coord3D(0,0,1);break}}const u=new t.Coord3D(o,a,l),p=new t.Camera(c,u,d,45);n.viewer.SetCamera(p),n.viewer.AdjustClippingPlanesToSphere?.(r),n.viewer.Render?.()}catch{}},be=(t.split(".").pop()||"").toUpperCase(),we=(e,t=0)=>{const n=e.children.length>0,r=!1!==S[e.id],s=!z.has(e.id);/* @__PURE__ */
83
83
  return k("div",{children:[
84
84
  /* @__PURE__ */k("div",{className:"group flex items-center gap-1 px-2 py-1 hover:bg-gray-100 cursor-default text-xs text-ink",style:{paddingLeft:12*t+6+"px"},children:[n?/* @__PURE__ */N("button",{onClick:()=>{return t=e.id,void j(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__ */N(p,r?{name:"chevron-down",className:"h-3 w-3",strokeWidth:2}:{name:"chevron-right",className:"h-3 w-3",strokeWidth:2})}):/* @__PURE__ */N("span",{className:"h-4 w-4 shrink-0 flex items-center justify-center",children:/* @__PURE__ */N("span",{className:"h-1 w-1 rounded-full bg-gray-400"})}),
85
85
  /* @__PURE__ */N("span",{className:"flex-1 truncate "+(s?"":"opacity-40"),title:e.name,children:e.name}),
@@ -93,7 +93,7 @@ return k("div",{className:"flex flex-col h-full bg-white",children:[
93
93
  /* @__PURE__ */N("button",{onClick:()=>ge("top"),className:ve,title:g.topView,children:/* @__PURE__ */N("span",{className:"text-2xs font-semibold",children:g.top})}),
94
94
  /* @__PURE__ */N("button",{onClick:()=>ge("front"),className:ve,title:g.frontView,children:/* @__PURE__ */N("span",{className:"text-2xs font-semibold",children:g.front})}),
95
95
  /* @__PURE__ */N("button",{onClick:()=>ge("side"),className:ve,title:g.sideView,children:/* @__PURE__ */N("span",{className:"text-2xs font-semibold",children:g.side})}),
96
- /* @__PURE__ */N("button",{onClick:()=>J(e=>!e),className:K?"h-8 shrink-0 flex items-center justify-center px-2 rounded bg-gray-200 text-gray-900":"h-8 shrink-0 flex items-center justify-center px-2 rounded text-gray-600 hover:bg-gray-200 hover:text-gray-900 transition-colors",title:K?g.toOrthographic:g.toPerspective,children:/* @__PURE__ */N("span",{className:"text-2xs font-semibold whitespace-nowrap",children:K?g.perspective:g.orthographic})}),
96
+ /* @__PURE__ */N("button",{onClick:()=>K(e=>!e),className:J?"h-8 shrink-0 flex items-center justify-center px-2 rounded bg-gray-200 text-gray-900":"h-8 shrink-0 flex items-center justify-center px-2 rounded text-gray-600 hover:bg-gray-200 hover:text-gray-900 transition-colors",title:J?g.toOrthographic:g.toPerspective,children:/* @__PURE__ */N("span",{className:"text-2xs font-semibold whitespace-nowrap",children:J?g.perspective:g.orthographic})}),
97
97
  /* @__PURE__ */N("div",{className:Ne}),
98
98
  /* @__PURE__ */N("button",{onClick:()=>{try{const e=o.current,n=e?.viewer?.GetCanvasSize?.()??{width:1280,height:720},r=e?.viewer?.GetImageAsDataUrl?.(n.width,n.height,!1);if(!r)return;const s=document.createElement("a");s.href=r,s.download=`${t.replace(/\.[^.]+$/,"")}-snapshot.png`,s.click()}catch{}},className:ve,title:g.snapshot,children:/* @__PURE__ */N(p,{name:"camera",className:"h-4 w-4",strokeWidth:1.5})}),
99
99
  /* @__PURE__ */N("button",{onClick:()=>f(e=>!e),className:ve,title:C.howToNavigate,children:/* @__PURE__ */N(p,{name:"help",className:"h-4 w-4",strokeWidth:1.5})}),
@@ -127,10 +127,10 @@ return k("div",{className:"flex flex-col h-full bg-white",children:[
127
127
  /* @__PURE__ */N("input",{type:"color",value:P,onChange:e=>W(e.target.value),className:"h-6 w-10 rounded border border-gray-300 bg-white"})]}),
128
128
  /* @__PURE__ */k("label",{className:"flex items-center justify-between gap-2",children:[
129
129
  /* @__PURE__ */N("span",{children:g.showEdges}),
130
- /* @__PURE__ */N("button",{onClick:()=>G(e=>!e),role:"switch","aria-checked":O,className:"relative inline-flex h-5 w-9 shrink-0 items-center rounded-full transition-colors "+(O?"bg-blue-500":"bg-gray-300"),children:/* @__PURE__ */N("span",{className:"inline-block h-4 w-4 rounded-full bg-white shadow-sm transition-transform "+(O?"translate-x-[18px]":"translate-x-0.5")})})]}),
130
+ /* @__PURE__ */N("button",{onClick:()=>X(e=>!e),role:"switch","aria-checked":O,className:"relative inline-flex h-5 w-9 shrink-0 items-center rounded-full transition-colors "+(O?"bg-blue-500":"bg-gray-300"),children:/* @__PURE__ */N("span",{className:"inline-block h-4 w-4 rounded-full bg-white shadow-sm transition-transform "+(O?"translate-x-[18px]":"translate-x-0.5")})})]}),
131
131
  /* @__PURE__ */k("label",{className:"flex items-center justify-between gap-2",children:[
132
132
  /* @__PURE__ */N("span",{className:O?"":"opacity-40",children:g.edgeColor}),
133
- /* @__PURE__ */N("input",{type:"color",value:X,onChange:e=>B(e.target.value),disabled:!O,className:"h-6 w-10 rounded border border-gray-300 bg-white disabled:opacity-40"})]}),
133
+ /* @__PURE__ */N("input",{type:"color",value:G,onChange:e=>B(e.target.value),disabled:!O,className:"h-6 w-10 rounded border border-gray-300 bg-white disabled:opacity-40"})]}),
134
134
  /* @__PURE__ */k("div",{className:O?"":"opacity-40 pointer-events-none",children:[
135
135
  /* @__PURE__ */k("div",{className:"flex items-center justify-between gap-2 mb-1",children:[
136
136
  /* @__PURE__ */N("span",{children:g.edgeThreshold}),
@@ -156,7 +156,7 @@ return k("div",{className:"flex flex-col h-full bg-white",children:[
156
156
  /* @__PURE__ */N("span",{children:g.position}),
157
157
  /* @__PURE__ */k("span",{className:"text-gray-500 tabular-nums",children:[Math.round(100*se),"%"]})]}),
158
158
  /* @__PURE__ */N("input",{type:"range",min:0,max:1,step:.01,value:se,onChange:e=>ie(Number(e.target.value)),className:"w-full accent-blue-500"})]})]})]})]}),
159
- /* @__PURE__ */N("div",{className:"px-3 py-2 border-t border-gray-200",children:/* @__PURE__ */N("button",{onClick:()=>{W("#f5f6f8"),G(!0),B("#000000"),V(1),q(!1),te("x"),re(!1),ie(.5),ae(0)},className:"w-full text-2xs text-ink bg-gray-100 hover:bg-gray-200 rounded py-2 transition-colors",children:g.resetDisplay})})]})]})})]})}function P({url:e,filename:t,onDownload:r,onEmail:i}){const[o,a]=w(1),[l,c]=w(!1),[d,u]=w(!1),m=b(null),h=y().preview,x="px-2 py-1 rounded hover:bg-gray-200 transition-colors text-gray-600 flex items-center gap-1";/* @__PURE__ */
159
+ /* @__PURE__ */N("div",{className:"px-3 py-2 border-t border-gray-200",children:/* @__PURE__ */N("button",{onClick:()=>{W("#f5f6f8"),X(!0),B("#000000"),V(1),q(!1),te("x"),re(!1),ie(.5),ae(0)},className:"w-full text-2xs text-ink bg-gray-100 hover:bg-gray-200 rounded py-2 transition-colors",children:g.resetDisplay})})]})]})})]})}function P({url:e,filename:t,onDownload:r,onEmail:i}){const[o,a]=w(1),[l,c]=w(!1),[d,u]=w(!1),m=b(null),h=y().preview,x="px-2 py-1 rounded hover:bg-gray-200 transition-colors text-gray-600 flex items-center gap-1";/* @__PURE__ */
160
160
  return k("div",{className:"flex flex-col h-full",children:[
161
161
  /* @__PURE__ */k(n,{children:[!d&&/* @__PURE__ */k(C,{children:[
162
162
  /* @__PURE__ */N("button",{onClick:()=>a(e=>Math.max(.1,Math.round(100*(e-.25))/100)),className:x,children:"−"}),
package/dist/ai/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  "use client";
2
- import{StepChainItem as e,StepChain as t}from"../chunk-Z2Z653OO.js";import{Markdown as n}from"../chunk-E44RNULN.js";import{Divider as a}from"../chunk-DFOFEBYX.js";import{Avatar as r}from"../chunk-YAM3L5N4.js";import"../chunk-UJUTS6LJ.js";import"../chunk-Z5TE3MEG.js";import{useContextMenu as s,ContextMenu as o}from"../chunk-QMBMK6PP.js";import{Banner as i}from"../chunk-ID35S5Y6.js";import{AttachmentDropZone as l}from"../chunk-DFOKJAIS.js";import{Input_default as c}from"../chunk-PT4GMPUB.js";import"../chunk-3DSGJIC7.js";import"../chunk-UZFFSZFI.js";import{IconButton_default as d}from"../chunk-SV5RRBVA.js";import"../chunk-AYZY3YNC.js";import{CloseGlyph as p}from"../chunk-CCPUNN4F.js";import"../chunk-ROKUEMAK.js";import{useFileIntake as u,humanSize as m,FileIntakeAlert as h}from"../chunk-ITEOA45V.js";import{parseChartSpec as f}from"../chunk-CR7T435F.js";import{SpecChart as g}from"../chunk-APGIPXR7.js";import{formatBytes as x}from"../chunk-GEYM4WN3.js";import{formatTime as b}from"../chunk-Y3JW2GW5.js";import"../chunk-36BRD5J3.js";import"../chunk-LF27WIN2.js";import"../chunk-EEFUXXYJ.js";import{FlowChart as v}from"../chunk-7NO4IENQ.js";import{parseFlowSpec as y}from"../chunk-FAERBT6Y.js";import"../chunk-FEQQMRHJ.js";import"../chunk-CK2YOGUS.js";import"../chunk-VWYICGVA.js";import"../chunk-VFC6QUEN.js";import"../chunk-PA3OU3Y7.js";import"../chunk-465RRWBY.js";import{ChartSkeleton as w}from"../chunk-NLHGFQ54.js";import"../chunk-CNYAHYE6.js";import"../chunk-DWGYC7OD.js";import"../chunk-JMGDGNM7.js";import"../chunk-GOAFMGUI.js";import"../chunk-URHGHXDN.js";import"../chunk-5QFPTDQF.js";import{Button_default as k}from"../chunk-EVYD6UFQ.js";import"../chunk-M5K4AX4E.js";import{Icon as N}from"../chunk-ISVODSRP.js";import"../chunk-J75ZT2JQ.js";import{SpinnerRing as A}from"../chunk-R2VKEMZH.js";import"../chunk-G67CJAQ2.js";import"../chunk-SOZCWT6I.js";import"../chunk-PGN5ME7B.js";import"../chunk-62LW225J.js";import"../chunk-GLUJS42B.js";import"../chunk-D65T4H6J.js";import"../chunk-UQYNPYF4.js";import"../chunk-MRJKZWWV.js";import"../chunk-D53FU245.js";import"../chunk-2UBR4YUF.js";import"../chunk-MAFUXCPZ.js";import"../chunk-2JWPNR2U.js";import"../chunk-WDQI3FV6.js";import"../chunk-TZFACUMR.js";import"../chunk-TWVUQUUD.js";import"../chunk-5FYDNH4Y.js";import"../chunk-LNXBTK7Q.js";import{useShellStrings as C}from"../chunk-DEJIH3ZQ.js";import"../chunk-C3QOHMR6.js";import{useRef as T,useEffect as j,useState as S,Fragment as $,useId as _,useCallback as O,useMemo as R}from"react";import{isToolUIPart as D,getToolName as I,DefaultChatTransport as F,lastAssistantMessageIsCompleteWithApprovalResponses as M}from"ai";import{jsx as z,jsxs as L,Fragment as P}from"react/jsx-runtime";import{useChat as E}from"@ai-sdk/react";function B(e){if(!D(e))return null;const t=e;return{toolName:I(e),toolCallId:t.toolCallId,state:t.state,input:t.input,output:t.output,errorText:t.errorText,approvalId:t.approval?.id,approved:t.approval?.approved}}function U(e){const t=/* @__PURE__ */new Map;for(const n of e.parts){if("data-tool-summary"!==n.type)continue;const e=n.data;e&&"string"==typeof e.tool_call_id&&Array.isArray(e.rows)&&e.rows.length>0&&t.set(e.tool_call_id,e)}return t}function q(e){const t=/* @__PURE__ */new Map;for(const n of e.parts){if("data-file"!==n.type)continue;const e=n.data;e&&"string"==typeof e.id&&"string"==typeof e.filename&&t.set(e.id,e)}return[...t.values()]}function W(e){return e.parts.map(e=>"text"===e.type?e.text:"").join("")}var Y="efficient-attachment:";function Q(e){return{type:"file",mediaType:e.content_type,filename:e.filename,url:`${Y}${e.id}`,providerMetadata:{efficient:{size:e.size}}}}function H(e){const t=[];for(const n of e.parts){if("file"!==n.type||!n.url.startsWith(Y))continue;const e=n.providerMetadata?.efficient?.size;t.push({id:n.url.slice(21),filename:n.filename??"",content_type:n.mediaType,size:"number"==typeof e?e:0})}return t}var J=/* @__PURE__ */new Set(["data-conversation","data-plan","data-followups","data-choices","data-tool-summary","data-error","data-file","data-approval","data-busy"]);function G(e,t){const n=e[e.length-1];if(!n)throw new Error("assistant chat: no message to send");if("user"===n.role){const e=W(n).trim();if(!e)throw new Error("assistant chat: empty message");const a=H(n).map(e=>e.id),r=n.metadata?.replyTo?.id;return{conversation_id:t,text:e,approvals:[],...a.length>0?{attachments:a}:{},...r?{reply_to:r}:{}}}const a=function(e){const t=[];for(const n of e.parts){if(!D(n))continue;const e=n;if("approval-responded"!==e.state||!e.approval||"boolean"!=typeof e.approval.approved)continue;const a={approval_id:e.approval.id,approved:e.approval.approved};e.approval.reason&&(a.reason=e.approval.reason),t.push(a)}return t}(n);if(0===a.length)throw new Error("assistant chat: no approval decision to send");return{conversation_id:t,text:null,approvals:a}}var V=e=>e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");function Z(e,t,n=""){const a=[t.trim(),n.trim()].filter(Boolean).map(V);return 0!==a.length&&new RegExp(`(^|[^\\p{L}\\p{N}_@])(?:${a.join("|")})(?![\\p{L}\\p{N}_@])`,"iu").test(e)}function K(e,t){const n=("string"==typeof t?[t]:[...t]).map(e=>e.trim()).filter(Boolean).sort((e,t)=>t.length-e.length);if(!n.length||!e)return e?[{text:e,mention:!1}]:[];const a=[];let r=0;const s=new RegExp(`(^|[^\\p{L}\\p{N}_@])(${n.map(V).join("|")})(?![\\p{L}\\p{N}_@])`,"giu");for(const t of e.matchAll(s)){const n=(t.index??0)+t[1].length;n>r&&a.push({text:e.slice(r,n),mention:!1}),a.push({text:t[2],mention:!0}),r=n+t[2].length}return r<e.length&&a.push({text:e.slice(r),mention:!1}),a}function X(e,t){return Z(e,t)?e:`${t.trim()} ${e.trimStart()}`}function ee(e){const t=e.map(e=>e.name).filter(Boolean);return t.length<=1?t[0]??"":`${t.slice(0,-1).join(", ")} and ${t[t.length-1]}`}var te=/* @__PURE__ */new Set(["proposed","approved","running"]);function ne(e){return te.has(e.status)}function ae(e){const t=[];for(const n of e.parts)"data-plan"===n.type&&t.push(n.data);return t}function re(e){const t=/* @__PURE__ */new Map;for(const n of e)for(const e of ae(n))t.delete(e.id),t.set(e.id,e);return t}function se(e){const t=[...re(e).values()],n=t[t.length-1];if(!n)return null;if(ne(n))return n;const a=e[e.length-1];return a&&"assistant"===a.role&&ae(a).some(e=>e.id===n.id)?n:null}function oe(e){const t={};return e.source&&e.source!==e.role&&(t.source=e.source),e.author&&(t.author=e.author),e.asked_by&&(t.askedBy=e.asked_by),e.created_at&&(t.createdAt=e.created_at),e.reply_to&&(t.replyTo=e.reply_to),"assistant"===e.role&&e.run_id&&(t.run_id=e.run_id,t.rating=e.rating??null),Object.keys(t).length>0?{metadata:t}:{}}function ie(e,t){const n=/* @__PURE__ */new Map;for(const a of e.parts){if("data-approval"!==a.type)continue;const e=a.data,r=e?.[t];"string"==typeof e?.approval_id&&"string"==typeof r&&r&&n.set(e.approval_id,r)}return n}function le(e){const t=e.messages.filter(e=>e.text).map(e=>({id:e.id,role:e.role,parts:[...(e.attachments??[]).map(Q),{type:"text",text:e.text},...(e.files??[]).map(e=>({type:"data-file",id:`file-${e.id}`,data:e}))],...oe(e)})),n=(e.plans??[]).filter(ne);return(e.pending_approvals.length>0||n.length>0)&&t.push({id:`pending-approvals-${e.id}`,role:"assistant",parts:[...n.map(e=>({type:"data-plan",id:e.id,data:e})),...e.pending_approvals.map(e=>({type:`tool-${e.tool_name}`,toolCallId:e.tool_call_id??e.approval_id,state:"approval-requested",input:e.input,approval:{id:e.approval_id}})),...e.pending_approvals.filter(e=>e.expires_at||e.notice).map(e=>({type:"data-approval",id:e.approval_id,data:{approval_id:e.approval_id,expires_at:e.expires_at,...e.notice?{notice:e.notice}:{}}}))]}),t}function ce(e,t){const n=e?.message?.trim();if(!n)return t;if(n.startsWith("{")){try{const e=JSON.parse(n);for(const t of["detail","errorText","message","title","error"]){const n=e[t];if("string"==typeof n&&n.trim())return n.trim()}for(const t of Object.values(e)){const e=Array.isArray(t)?t[0]:void 0;if("string"==typeof e&&e.trim()&&e.length<=400)return e.trim()}}catch{return t}return t}return n.startsWith("<")||n.length>400?t:n}var de=/^(load failed|failed to fetch|network ?error( when attempting to fetch resource)?|(the )?network connection was lost|error in input stream|terminated)\.?$/i;function pe(e){return!(!e||"AbortError"===e.name)&&de.test(e.message?.trim()??"")}var ue=/* @__PURE__ */new Set(["budget_reached","not_permitted"]);function me(e,t,n){return pe(e)?{text:n.connectionDropped,retryable:!0}:{text:ce(e,n.genericError),retryable:!(t&&ue.has(t))}}function he(e){const t=e[e.length-1];if(!t)return!1;if("user"===t.role)return""!==W(t).trim();const n=e[e.length-2];return!(!n||"user"!==n.role||!W(n).trim())&&!t.parts.some(e=>void 0!==B(e)?.approvalId)}var fe=["👍","✅","👀"],ge=["👍","👎","❤️","😂","😮","😢","🙏","🎉","✅","❌","👀","🔥","💯","🚀","👏","🙌","😀","😅","🤔","😬","🤝","💪","📦","🚚","📅","⏰","💰","📈","⚠️","❓","➕","👌"];function xe(e,t,n="You"){const a=e.names.map(a=>t&&a===t&&e.mine?n:a),r=e.mine?[n,...a.filter(e=>e!==n)]:a;return r.length<=1?r[0]??"":`${r.slice(0,-1).join(", ")} and ${r[r.length-1]}`}function be({onPick:e,onClose:t,label:n="Add reaction"}){const a=T(null);j(()=>{const e=e=>{a.current&&!a.current.contains(e.target)&&t()};return document.addEventListener("mousedown",e),a.current?.querySelector("button")?.focus(),()=>document.removeEventListener("mousedown",e)},[t]);/* @__PURE__ */
2
+ import{StepChainItem as e,StepChain as t}from"../chunk-Z2Z653OO.js";import{Markdown as n}from"../chunk-E44RNULN.js";import{Divider as a}from"../chunk-DFOFEBYX.js";import{Avatar as r}from"../chunk-YAM3L5N4.js";import"../chunk-UJUTS6LJ.js";import"../chunk-Z5TE3MEG.js";import{useContextMenu as s,ContextMenu as o}from"../chunk-QMBMK6PP.js";import{Banner as i}from"../chunk-ID35S5Y6.js";import{AttachmentDropZone as l}from"../chunk-DFOKJAIS.js";import{Input_default as c}from"../chunk-PT4GMPUB.js";import"../chunk-3DSGJIC7.js";import"../chunk-UZFFSZFI.js";import{IconButton_default as d}from"../chunk-SV5RRBVA.js";import"../chunk-AYZY3YNC.js";import{CloseGlyph as p}from"../chunk-CCPUNN4F.js";import"../chunk-ROKUEMAK.js";import{useFileIntake as u,humanSize as m,FileIntakeAlert as h}from"../chunk-ITEOA45V.js";import{parseChartSpec as f}from"../chunk-CR7T435F.js";import{SpecChart as g}from"../chunk-YHABPVWU.js";import{formatBytes as x}from"../chunk-GEYM4WN3.js";import{formatTime as b}from"../chunk-Y3JW2GW5.js";import"../chunk-36BRD5J3.js";import"../chunk-LF27WIN2.js";import"../chunk-UF76AFFY.js";import"../chunk-PA3OU3Y7.js";import{FlowChart as v}from"../chunk-7NO4IENQ.js";import{parseFlowSpec as y}from"../chunk-FAERBT6Y.js";import"../chunk-465RRWBY.js";import"../chunk-FEQQMRHJ.js";import"../chunk-CK2YOGUS.js";import"../chunk-VWYICGVA.js";import{ChartSkeleton as w}from"../chunk-NLHGFQ54.js";import"../chunk-VFC6QUEN.js";import"../chunk-CNYAHYE6.js";import"../chunk-DWGYC7OD.js";import"../chunk-JMGDGNM7.js";import"../chunk-GOAFMGUI.js";import"../chunk-URHGHXDN.js";import"../chunk-5QFPTDQF.js";import{Button_default as k}from"../chunk-EVYD6UFQ.js";import"../chunk-M5K4AX4E.js";import{Icon as N}from"../chunk-ISVODSRP.js";import"../chunk-J75ZT2JQ.js";import{SpinnerRing as A}from"../chunk-R2VKEMZH.js";import"../chunk-G67CJAQ2.js";import"../chunk-SOZCWT6I.js";import"../chunk-PGN5ME7B.js";import"../chunk-62LW225J.js";import"../chunk-GLUJS42B.js";import"../chunk-D65T4H6J.js";import"../chunk-UQYNPYF4.js";import"../chunk-MRJKZWWV.js";import"../chunk-D53FU245.js";import"../chunk-2UBR4YUF.js";import"../chunk-MAFUXCPZ.js";import"../chunk-2JWPNR2U.js";import"../chunk-WDQI3FV6.js";import"../chunk-TZFACUMR.js";import"../chunk-TWVUQUUD.js";import"../chunk-5FYDNH4Y.js";import"../chunk-LNXBTK7Q.js";import{useShellStrings as C}from"../chunk-DEJIH3ZQ.js";import"../chunk-C3QOHMR6.js";import{useRef as T,useEffect as j,useState as S,Fragment as $,useId as _,useCallback as O,useMemo as R}from"react";import{isToolUIPart as D,getToolName as I,DefaultChatTransport as F,lastAssistantMessageIsCompleteWithApprovalResponses as M}from"ai";import{jsx as z,jsxs as L,Fragment as P}from"react/jsx-runtime";import{useChat as E}from"@ai-sdk/react";function B(e){if(!D(e))return null;const t=e;return{toolName:I(e),toolCallId:t.toolCallId,state:t.state,input:t.input,output:t.output,errorText:t.errorText,approvalId:t.approval?.id,approved:t.approval?.approved}}function U(e){const t=/* @__PURE__ */new Map;for(const n of e.parts){if("data-tool-summary"!==n.type)continue;const e=n.data;e&&"string"==typeof e.tool_call_id&&Array.isArray(e.rows)&&e.rows.length>0&&t.set(e.tool_call_id,e)}return t}function q(e){const t=/* @__PURE__ */new Map;for(const n of e.parts){if("data-file"!==n.type)continue;const e=n.data;e&&"string"==typeof e.id&&"string"==typeof e.filename&&t.set(e.id,e)}return[...t.values()]}function W(e){return e.parts.map(e=>"text"===e.type?e.text:"").join("")}var Y="efficient-attachment:";function Q(e){return{type:"file",mediaType:e.content_type,filename:e.filename,url:`${Y}${e.id}`,providerMetadata:{efficient:{size:e.size}}}}function H(e){const t=[];for(const n of e.parts){if("file"!==n.type||!n.url.startsWith(Y))continue;const e=n.providerMetadata?.efficient?.size;t.push({id:n.url.slice(21),filename:n.filename??"",content_type:n.mediaType,size:"number"==typeof e?e:0})}return t}var J=/* @__PURE__ */new Set(["data-conversation","data-plan","data-followups","data-choices","data-tool-summary","data-error","data-file","data-approval","data-busy"]);function G(e,t){const n=e[e.length-1];if(!n)throw new Error("assistant chat: no message to send");if("user"===n.role){const e=W(n).trim();if(!e)throw new Error("assistant chat: empty message");const a=H(n).map(e=>e.id),r=n.metadata?.replyTo?.id;return{conversation_id:t,text:e,approvals:[],...a.length>0?{attachments:a}:{},...r?{reply_to:r}:{}}}const a=function(e){const t=[];for(const n of e.parts){if(!D(n))continue;const e=n;if("approval-responded"!==e.state||!e.approval||"boolean"!=typeof e.approval.approved)continue;const a={approval_id:e.approval.id,approved:e.approval.approved};e.approval.reason&&(a.reason=e.approval.reason),t.push(a)}return t}(n);if(0===a.length)throw new Error("assistant chat: no approval decision to send");return{conversation_id:t,text:null,approvals:a}}var V=e=>e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");function Z(e,t,n=""){const a=[t.trim(),n.trim()].filter(Boolean).map(V);return 0!==a.length&&new RegExp(`(^|[^\\p{L}\\p{N}_@])(?:${a.join("|")})(?![\\p{L}\\p{N}_@])`,"iu").test(e)}function K(e,t){const n=("string"==typeof t?[t]:[...t]).map(e=>e.trim()).filter(Boolean).sort((e,t)=>t.length-e.length);if(!n.length||!e)return e?[{text:e,mention:!1}]:[];const a=[];let r=0;const s=new RegExp(`(^|[^\\p{L}\\p{N}_@])(${n.map(V).join("|")})(?![\\p{L}\\p{N}_@])`,"giu");for(const t of e.matchAll(s)){const n=(t.index??0)+t[1].length;n>r&&a.push({text:e.slice(r,n),mention:!1}),a.push({text:t[2],mention:!0}),r=n+t[2].length}return r<e.length&&a.push({text:e.slice(r),mention:!1}),a}function X(e,t){return Z(e,t)?e:`${t.trim()} ${e.trimStart()}`}function ee(e){const t=e.map(e=>e.name).filter(Boolean);return t.length<=1?t[0]??"":`${t.slice(0,-1).join(", ")} and ${t[t.length-1]}`}var te=/* @__PURE__ */new Set(["proposed","approved","running"]);function ne(e){return te.has(e.status)}function ae(e){const t=[];for(const n of e.parts)"data-plan"===n.type&&t.push(n.data);return t}function re(e){const t=/* @__PURE__ */new Map;for(const n of e)for(const e of ae(n))t.delete(e.id),t.set(e.id,e);return t}function se(e){const t=[...re(e).values()],n=t[t.length-1];if(!n)return null;if(ne(n))return n;const a=e[e.length-1];return a&&"assistant"===a.role&&ae(a).some(e=>e.id===n.id)?n:null}function oe(e){const t={};return e.source&&e.source!==e.role&&(t.source=e.source),e.author&&(t.author=e.author),e.asked_by&&(t.askedBy=e.asked_by),e.created_at&&(t.createdAt=e.created_at),e.reply_to&&(t.replyTo=e.reply_to),"assistant"===e.role&&e.run_id&&(t.run_id=e.run_id,t.rating=e.rating??null),Object.keys(t).length>0?{metadata:t}:{}}function ie(e,t){const n=/* @__PURE__ */new Map;for(const a of e.parts){if("data-approval"!==a.type)continue;const e=a.data,r=e?.[t];"string"==typeof e?.approval_id&&"string"==typeof r&&r&&n.set(e.approval_id,r)}return n}function le(e){const t=e.messages.filter(e=>e.text).map(e=>({id:e.id,role:e.role,parts:[...(e.attachments??[]).map(Q),{type:"text",text:e.text},...(e.files??[]).map(e=>({type:"data-file",id:`file-${e.id}`,data:e}))],...oe(e)})),n=(e.plans??[]).filter(ne);return(e.pending_approvals.length>0||n.length>0)&&t.push({id:`pending-approvals-${e.id}`,role:"assistant",parts:[...n.map(e=>({type:"data-plan",id:e.id,data:e})),...e.pending_approvals.map(e=>({type:`tool-${e.tool_name}`,toolCallId:e.tool_call_id??e.approval_id,state:"approval-requested",input:e.input,approval:{id:e.approval_id}})),...e.pending_approvals.filter(e=>e.expires_at||e.notice).map(e=>({type:"data-approval",id:e.approval_id,data:{approval_id:e.approval_id,expires_at:e.expires_at,...e.notice?{notice:e.notice}:{}}}))]}),t}function ce(e,t){const n=e?.message?.trim();if(!n)return t;if(n.startsWith("{")){try{const e=JSON.parse(n);for(const t of["detail","errorText","message","title","error"]){const n=e[t];if("string"==typeof n&&n.trim())return n.trim()}for(const t of Object.values(e)){const e=Array.isArray(t)?t[0]:void 0;if("string"==typeof e&&e.trim()&&e.length<=400)return e.trim()}}catch{return t}return t}return n.startsWith("<")||n.length>400?t:n}var de=/^(load failed|failed to fetch|network ?error( when attempting to fetch resource)?|(the )?network connection was lost|error in input stream|terminated)\.?$/i;function pe(e){return!(!e||"AbortError"===e.name)&&de.test(e.message?.trim()??"")}var ue=/* @__PURE__ */new Set(["budget_reached","not_permitted"]);function me(e,t,n){return pe(e)?{text:n.connectionDropped,retryable:!0}:{text:ce(e,n.genericError),retryable:!(t&&ue.has(t))}}function he(e){const t=e[e.length-1];if(!t)return!1;if("user"===t.role)return""!==W(t).trim();const n=e[e.length-2];return!(!n||"user"!==n.role||!W(n).trim())&&!t.parts.some(e=>void 0!==B(e)?.approvalId)}var fe=["👍","✅","👀"],ge=["👍","👎","❤️","😂","😮","😢","🙏","🎉","✅","❌","👀","🔥","💯","🚀","👏","🙌","😀","😅","🤔","😬","🤝","💪","📦","🚚","📅","⏰","💰","📈","⚠️","❓","➕","👌"];function xe(e,t,n="You"){const a=e.names.map(a=>t&&a===t&&e.mine?n:a),r=e.mine?[n,...a.filter(e=>e!==n)]:a;return r.length<=1?r[0]??"":`${r.slice(0,-1).join(", ")} and ${r[r.length-1]}`}function be({onPick:e,onClose:t,label:n="Add reaction"}){const a=T(null);j(()=>{const e=e=>{a.current&&!a.current.contains(e.target)&&t()};return document.addEventListener("mousedown",e),a.current?.querySelector("button")?.focus(),()=>document.removeEventListener("mousedown",e)},[t]);/* @__PURE__ */
3
3
  return z("div",{ref:a,role:"dialog","aria-label":n,className:"absolute z-20 mt-1 grid w-max grid-cols-8 gap-0.5 rounded-md border border-line bg-surface p-1 shadow-lg","data-emoji-picker":"",onKeyDown:e=>{"Escape"===e.key&&(e.stopPropagation(),t())},children:ge.map(n=>/* @__PURE__ */z("button",{type:"button",className:"flex h-7 w-7 items-center justify-center rounded text-base hover:bg-surface-sunken focus-visible:bg-surface-sunken","aria-label":n,onClick:()=>{e(n),t()},children:n},n))})}function ve({onReact:e,label:t="Add reaction"}){const[n,a]=S(!1);/* @__PURE__ */
4
4
  return L("span",{className:"relative flex items-center gap-0.5","data-reaction-bar":"",children:[fe.map(t=>/* @__PURE__ */z("button",{type:"button",className:"flex h-6 w-6 items-center justify-center rounded text-sm hover:bg-surface-sunken","aria-label":`React ${t}`,title:`React ${t}`,onClick:()=>e(t),children:t},t)),
5
5
  /* @__PURE__ */z(d,{size:"sm",variant:"ghost","aria-label":t,title:t,"aria-haspopup":"dialog",onClick:()=>a(e=>!e),children:/* @__PURE__ */z(N,{name:"face-smile",className:"h-3.5 w-3.5"})}),n&&/* @__PURE__ */z("span",{className:"absolute right-0 top-full",children:/* @__PURE__ */z(be,{label:t,onPick:e,onClose:()=>a(!1)})})]})}function ye({reactions:e,onToggle:t,selfName:n,label:a="Add reaction"}){const[r,s]=S(!1);return e.length?/* @__PURE__ */L("div",{className:"relative mt-1 flex flex-wrap items-center gap-1","data-reactions":"",children:[e.map(e=>{const a=xe(e,n),r="inline-flex h-6 items-center gap-1 rounded-full border px-2 text-xs tabular-nums "+(e.mine?"border-accent-border bg-accent-tint text-accent-text":"border-line bg-surface text-ink");/* @__PURE__ */
@@ -1,2 +1,2 @@
1
1
  "use client";
2
- export{FILES_ROUTE,chooseInFiles,openFilesInTrashMode,setFilesDemoTree,withdrawFilesChoice}from"../chunk-4EFIUJ7X.js";export{setBrowserStartUrl}from"../chunk-LWLCNQY7.js";export{BUILTIN_APP_INFO}from"../chunk-WKWZILZA.js";import{setSpreadsheetPreview as e}from"../chunk-WBAWJIVM.js";export{FILES_OFFICE_EXTENSIONS,FilesQuotaError,SPREADSHEET_PREVIEW_UPDATE_EVENT,claimSpreadsheetPreviewStage,createFileServerStore,peekSpreadsheetPreviewStage,setFilesStore,setSpreadsheetPreview}from"../chunk-WBAWJIVM.js";import{setPdfPreview as t}from"../chunk-I4RJAMLJ.js";export{setPdfPreview}from"../chunk-I4RJAMLJ.js";import"../chunk-FCILLVVT.js";import"../chunk-4LXCCZDM.js";import"../chunk-AW7TOB6N.js";import"../chunk-KNUR2UEG.js";import"../chunk-JDCM2VHG.js";import"../chunk-DASRJ26L.js";import"../chunk-ZDMZM7HD.js";import"../chunk-5A7MWTXX.js";import"../chunk-GHLXZDLU.js";import"../chunk-KV6XCHAG.js";import"../chunk-B447IHIL.js";import"../chunk-EIFNESXS.js";import"../chunk-PR6FNBKR.js";import"../chunk-RIG5FEVS.js";import"../chunk-NDWX5Z4D.js";import"../chunk-VWGWZY7A.js";import"../chunk-7QSDPSXP.js";import"../chunk-ZGIAMYTI.js";import"../chunk-5LHEPE4B.js";import"../chunk-F3ZOO23R.js";import"../chunk-2QY5BJLA.js";import"../chunk-UGTRSRIW.js";import"../chunk-KC3EX26K.js";import"../chunk-LSONG4QV.js";import"../chunk-DWGYC7OD.js";import"../chunk-JMGDGNM7.js";import"../chunk-GOAFMGUI.js";import"../chunk-URHGHXDN.js";import"../chunk-5QFPTDQF.js";import"../chunk-EVYD6UFQ.js";import"../chunk-M5K4AX4E.js";import"../chunk-ISVODSRP.js";import"../chunk-J75ZT2JQ.js";import"../chunk-R2VKEMZH.js";import"../chunk-G67CJAQ2.js";import"../chunk-SOZCWT6I.js";import"../chunk-PGN5ME7B.js";import"../chunk-62LW225J.js";import"../chunk-GLUJS42B.js";import"../chunk-D65T4H6J.js";import"../chunk-STKJA4PV.js";import{toast_default as o}from"../chunk-TMSSR5UH.js";import"../chunk-UQYNPYF4.js";import"../chunk-MRJKZWWV.js";import"../chunk-TWVUQUUD.js";import"../chunk-5FYDNH4Y.js";import"../chunk-LNXBTK7Q.js";import{currentShellStrings as n}from"../chunk-DEJIH3ZQ.js";import"../chunk-C3QOHMR6.js";import{lazy as i}from"react";function r(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"]),a=/* @__PURE__ */new Set(["png","jpg","jpeg","gif","webp","bmp","svg","avif"]),m=/* @__PURE__ */new Set(["step","stp","stl","obj","gltf","glb","3mf","iges","igs"]);function l(e){const t=r(e);return"pdf"===t?"pdf":"dxf"===t?"dxf":s.has(t)?"csv":a.has(t)?"image":m.has(t)?"3d":null}function u(e){window.open(e,"_blank","noopener,noreferrer")}async function p(e,t,o){if(t.fetchBlob)return(await t.fetchBlob(o)).text();const n=await fetch(e);if(!n.ok)throw new Error(`fetch failed: ${n.status}`);return n.text()}function h(e,t){return(e instanceof Error?e.message:"")||t}async function k(i,s,a={}){const m=n().attachment,k=i?.url||"",f=i?.filename||m.fallbackName;if(!k&&!a.fetchBlob)return void o.error(m.noLink);const j=l(f)??l(k);if("csv"===j){try{e({csv:await p(k,a,i),filename:f}),s("/spreadsheet")}catch{o.error(m.spreadsheetFailed),k&&u(k)}return}if(c.has(r(f)||r(k)))return o.error(m.workbookUnavailable),void(k&&u(k));if(!j)return k?(o.info(m.noViewer),void u(k)):void o.error(m.noLink);if(!a.fetchBlob)return t({url:k,filename:f,kind:j}),void s("/preview");const d=t({filename:f,kind:j,converting:!0,convertingMessage:a.loadingMessage||m.loading});s("/preview");try{const e=await a.fetchBlob(i);d.update({url:URL.createObjectURL(e),filename:f,kind:j})}catch(e){d.update({filename:f,kind:j,converting:!1,convertingMessage:h(e,m.loadFailed)})}}function f(e,t,o={}){const i=n().attachment,s=[];let a=-1;return e.forEach((e,n)=>{const m=e?.url||"";if(!m&&!o.fetchBlob)return;const u=e?.filename||i.fallbackName;if(c.has(r(u)||r(m)))return;const p=l(u)??l(m);p&&"csv"!==p&&(n===t&&(a=s.length),s.push({att:e,sourceIndex:n,filename:u,url:m,kind:p}))}),{items:s,start:a}}async function j(e,o,i,r={}){const{items:s,start:c}=f(e,o,r);if(c<0||s.length<2){const t=e[o];return void(t&&await k(t,i,r))}const a=n().attachment,m=s.length;let l=null,u=-1;const p=e=>({position:{index:e,count:m},onPrevious:e>0?()=>{d(e-1)}:void 0,onNext:e<m-1?()=>{d(e+1)}:void 0}),j=e=>{l?l.update(e):(l=t(e),i("/preview"))};async function d(e){u=e;const{att:t,filename:o,url:n,kind:i}=s[e];if(r.fetchBlob){j({filename:o,kind:i,converting:!0,convertingMessage:r.loadingMessage||a.loading,...p(e)});try{const n=await r.fetchBlob(t),s=URL.createObjectURL(n);if(u!==e)return void URL.revokeObjectURL(s);j({url:s,filename:o,kind:i,...p(e)})}catch(t){if(u!==e)return;j({filename:o,kind:i,converting:!1,convertingMessage:h(t,a.loadFailed),...p(e)})}}else j({url:n,filename:o,kind:i,...p(e)})}await d(c)}var d=i(()=>import("../Calculator-2N7WJ6NR.js")),w=i(()=>import("../Weather-YQQT5XYX.js")),g=i(()=>import("../CurrencyConverter-LJ73P5P7.js")),v=i(()=>import("../PomodoroTimer-T34U5BLE.js")),S=i(()=>import("../Notepad-LXLUGQUN.js")),L=i(()=>import("../WorldClock-WN2X3YIV.js")),E=i(()=>import("../Stock-BV36WRZA.js")),I=i(()=>import("../Preview-VRYWLVJY.js")),b=i(()=>import("../PdfViewer-OLQBTKOC.js")),P=i(()=>import("../Files-VUZWJMCE.js")),T=i(()=>import("../Browser-TYVPZ2NT.js")),F={"/calculator":{component:d,label:"Calculator",size:"sm",allowPinOnTop:!0,utility:!0,widget:!0,dimensions:[280,420]},"/notepad":{component:S,label:"Notepad",size:"lg",allowPinOnTop:!0,flushBody:!0},"/weather":{component:w,label:"Weather",size:"sm",utility:!0,widget:!0,autoHeight:!0,dimensions:[320,400]},"/currency":{component:g,label:"Currency Converter",size:"sm",utility:!0,widget:!0,autoHeight:!0,dimensions:[320,480]},"/pomodoro":{component:v,label:"Pomodoro Timer",size:"sm",utility:!0,widget:!0,dimensions:[320,600]},"/world-clock":{component:L,label:"World Clock",size:"sm",utility:!0,widget:!0,autoHeight:!0,dimensions:[320,480]},"/stock":{component:E,label:"Stocks",size:"sm",utility:!0,widget:!0,autoHeight:!0,dimensions:[320,360]}},U={"/preview":{component:I,label:"Preview",size:"2xl",appStyle:!0,multiInstance:!0},"/files":{component:P,label:"Files",size:"xl",appStyle:!0}},W={"/browser":{component:T,label:"Browser",size:"2xl",appStyle:!0,multiInstance:!0}},N={...F,...U,...W};export{T as Browser,d as Calculator,g as CurrencyConverter,P as Files,S as Notepad,b as PdfViewer,v as PomodoroTimer,I as Preview,E as Stock,w as Weather,L as WorldClock,l as attachmentKind,N as bundledApps,U as documentApps,k as openAttachment,j as openAttachments,F as utilityApps,f as viewableAttachments,W as webApps};
2
+ export{FILES_ROUTE,chooseInFiles,openFilesInTrashMode,setFilesDemoTree,withdrawFilesChoice}from"../chunk-4EFIUJ7X.js";export{setBrowserStartUrl}from"../chunk-LWLCNQY7.js";export{BUILTIN_APP_INFO}from"../chunk-VRRPYADW.js";import{setSpreadsheetPreview as e}from"../chunk-WBAWJIVM.js";export{FILES_OFFICE_EXTENSIONS,FilesQuotaError,SPREADSHEET_PREVIEW_UPDATE_EVENT,claimSpreadsheetPreviewStage,createFileServerStore,peekSpreadsheetPreviewStage,setFilesStore,setSpreadsheetPreview}from"../chunk-WBAWJIVM.js";import{setPdfPreview as t}from"../chunk-I4RJAMLJ.js";export{setPdfPreview}from"../chunk-I4RJAMLJ.js";import"../chunk-FCILLVVT.js";import"../chunk-4LXCCZDM.js";import"../chunk-AW7TOB6N.js";import"../chunk-KNUR2UEG.js";import"../chunk-JDCM2VHG.js";import"../chunk-DASRJ26L.js";import"../chunk-ZDMZM7HD.js";import"../chunk-5A7MWTXX.js";import"../chunk-GHLXZDLU.js";import"../chunk-KV6XCHAG.js";import"../chunk-B447IHIL.js";import"../chunk-EIFNESXS.js";import"../chunk-PR6FNBKR.js";import"../chunk-RIG5FEVS.js";import"../chunk-NDWX5Z4D.js";import"../chunk-VWGWZY7A.js";import"../chunk-7QSDPSXP.js";import"../chunk-ZGIAMYTI.js";import"../chunk-5LHEPE4B.js";import"../chunk-F3ZOO23R.js";import"../chunk-2QY5BJLA.js";import"../chunk-UGTRSRIW.js";import"../chunk-KC3EX26K.js";import"../chunk-56UUJIC4.js";import"../chunk-DWGYC7OD.js";import"../chunk-JMGDGNM7.js";import"../chunk-GOAFMGUI.js";import"../chunk-URHGHXDN.js";import"../chunk-5QFPTDQF.js";import"../chunk-EVYD6UFQ.js";import"../chunk-M5K4AX4E.js";import"../chunk-ISVODSRP.js";import"../chunk-J75ZT2JQ.js";import"../chunk-R2VKEMZH.js";import"../chunk-G67CJAQ2.js";import"../chunk-SOZCWT6I.js";import"../chunk-PGN5ME7B.js";import"../chunk-62LW225J.js";import"../chunk-GLUJS42B.js";import"../chunk-D65T4H6J.js";import"../chunk-STKJA4PV.js";import{toast_default as o}from"../chunk-TMSSR5UH.js";import"../chunk-UQYNPYF4.js";import"../chunk-MRJKZWWV.js";import"../chunk-TWVUQUUD.js";import"../chunk-5FYDNH4Y.js";import"../chunk-LNXBTK7Q.js";import{currentShellStrings as n}from"../chunk-DEJIH3ZQ.js";import"../chunk-C3QOHMR6.js";import{lazy as i}from"react";function r(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"]),a=/* @__PURE__ */new Set(["png","jpg","jpeg","gif","webp","bmp","svg","avif"]),m=/* @__PURE__ */new Set(["step","stp","stl","obj","gltf","glb","3mf","iges","igs"]);function l(e){const t=r(e);return"pdf"===t?"pdf":"dxf"===t?"dxf":s.has(t)?"csv":a.has(t)?"image":m.has(t)?"3d":null}function u(e){window.open(e,"_blank","noopener,noreferrer")}async function p(e,t,o){if(t.fetchBlob)return(await t.fetchBlob(o)).text();const n=await fetch(e);if(!n.ok)throw new Error(`fetch failed: ${n.status}`);return n.text()}function h(e,t){return(e instanceof Error?e.message:"")||t}async function k(i,s,a={}){const m=n().attachment,k=i?.url||"",f=i?.filename||m.fallbackName;if(!k&&!a.fetchBlob)return void o.error(m.noLink);const j=l(f)??l(k);if("csv"===j){try{e({csv:await p(k,a,i),filename:f}),s("/spreadsheet")}catch{o.error(m.spreadsheetFailed),k&&u(k)}return}if(c.has(r(f)||r(k)))return o.error(m.workbookUnavailable),void(k&&u(k));if(!j)return k?(o.info(m.noViewer),void u(k)):void o.error(m.noLink);if(!a.fetchBlob)return t({url:k,filename:f,kind:j}),void s("/preview");const d=t({filename:f,kind:j,converting:!0,convertingMessage:a.loadingMessage||m.loading});s("/preview");try{const e=await a.fetchBlob(i);d.update({url:URL.createObjectURL(e),filename:f,kind:j})}catch(e){d.update({filename:f,kind:j,converting:!1,convertingMessage:h(e,m.loadFailed)})}}function f(e,t,o={}){const i=n().attachment,s=[];let a=-1;return e.forEach((e,n)=>{const m=e?.url||"";if(!m&&!o.fetchBlob)return;const u=e?.filename||i.fallbackName;if(c.has(r(u)||r(m)))return;const p=l(u)??l(m);p&&"csv"!==p&&(n===t&&(a=s.length),s.push({att:e,sourceIndex:n,filename:u,url:m,kind:p}))}),{items:s,start:a}}async function j(e,o,i,r={}){const{items:s,start:c}=f(e,o,r);if(c<0||s.length<2){const t=e[o];return void(t&&await k(t,i,r))}const a=n().attachment,m=s.length;let l=null,u=-1;const p=e=>({position:{index:e,count:m},onPrevious:e>0?()=>{d(e-1)}:void 0,onNext:e<m-1?()=>{d(e+1)}:void 0}),j=e=>{l?l.update(e):(l=t(e),i("/preview"))};async function d(e){u=e;const{att:t,filename:o,url:n,kind:i}=s[e];if(r.fetchBlob){j({filename:o,kind:i,converting:!0,convertingMessage:r.loadingMessage||a.loading,...p(e)});try{const n=await r.fetchBlob(t),s=URL.createObjectURL(n);if(u!==e)return void URL.revokeObjectURL(s);j({url:s,filename:o,kind:i,...p(e)})}catch(t){if(u!==e)return;j({filename:o,kind:i,converting:!1,convertingMessage:h(t,a.loadFailed),...p(e)})}}else j({url:n,filename:o,kind:i,...p(e)})}await d(c)}var d=i(()=>import("../Calculator-2N7WJ6NR.js")),w=i(()=>import("../Weather-YQQT5XYX.js")),g=i(()=>import("../CurrencyConverter-LJ73P5P7.js")),v=i(()=>import("../PomodoroTimer-T34U5BLE.js")),S=i(()=>import("../Notepad-C44EOSDD.js")),E=i(()=>import("../WorldClock-WN2X3YIV.js")),L=i(()=>import("../Stock-BV36WRZA.js")),I=i(()=>import("../Preview-32K62K27.js")),b=i(()=>import("../PdfViewer-OLQBTKOC.js")),U=i(()=>import("../Files-UYO4JLEB.js")),P=i(()=>import("../Browser-SBOULR4U.js")),R={"/calculator":{component:d,label:"Calculator",size:"sm",allowPinOnTop:!0,utility:!0,widget:!0,dimensions:[280,420]},"/notepad":{component:S,label:"Notepad",size:"lg",allowPinOnTop:!0,flushBody:!0},"/weather":{component:w,label:"Weather",size:"sm",utility:!0,widget:!0,autoHeight:!0,dimensions:[320,400]},"/currency":{component:g,label:"Currency Converter",size:"sm",utility:!0,widget:!0,autoHeight:!0,dimensions:[320,480]},"/pomodoro":{component:v,label:"Pomodoro Timer",size:"sm",utility:!0,widget:!0,dimensions:[320,600]},"/world-clock":{component:E,label:"World Clock",size:"sm",utility:!0,widget:!0,autoHeight:!0,dimensions:[320,480]},"/stock":{component:L,label:"Stocks",size:"sm",utility:!0,widget:!0,autoHeight:!0,dimensions:[320,360]}},F={"/preview":{component:I,label:"Preview",size:"2xl",appStyle:!0,multiInstance:!0},"/files":{component:U,label:"Files",size:"xl",appStyle:!0}},B={"/browser":{component:P,label:"Browser",size:"2xl",appStyle:!0,multiInstance:!0}},T={...R,...F,...B};export{P as Browser,d as Calculator,g as CurrencyConverter,U as Files,S as Notepad,b as PdfViewer,v as PomodoroTimer,I as Preview,L as Stock,w as Weather,E as WorldClock,l as attachmentKind,T as bundledApps,F as documentApps,k as openAttachment,j as openAttachments,R as utilityApps,f as viewableAttachments,B as webApps};