efficient-shell 4.177.0 → 4.180.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 (66) hide show
  1. package/README.md +384 -7
  2. package/dist/{Browser-MFFTBGEB.js → Browser-RZFOKBSF.js} +14 -14
  3. package/dist/Calculator-R5OEHQ67.js +29 -0
  4. package/dist/ConfirmDialog-CMNQZQA3.js +1 -0
  5. package/dist/{CurrencyConverter-KZPE7ZCC.js → CurrencyConverter-AMXUOQR2.js} +7 -7
  6. package/dist/{Documents-ZD227WZC.js → Documents-VD32HWDQ.js} +7 -7
  7. package/dist/{Files-BLGT4RLF.js → Files-NAY3WK6O.js} +31 -31
  8. package/dist/{Notepad-LUK2IFHD.js → Notepad-AHRPMF57.js} +10 -10
  9. package/dist/PdfViewer-3SC3LE4U.js +1 -0
  10. package/dist/{PomodoroTimer-LHPV6QXG.js → PomodoroTimer-LE6J2KUU.js} +26 -26
  11. package/dist/Preview-OKR5QRQP.js +188 -0
  12. package/dist/{Sidebar-4GIZSTD5.js → Sidebar-BQ4P5LBI.js} +21 -21
  13. package/dist/Spreadsheet-RME4IQ43.js +37 -0
  14. package/dist/{Stock-XSDFN7U2.js → Stock-GWVG2INU.js} +4 -4
  15. package/dist/{Weather-7YDUDMCO.js → Weather-APBCG4TO.js} +14 -14
  16. package/dist/{WorldClock-Q2JHBKLS.js → WorldClock-2LMZYKWR.js} +7 -7
  17. package/dist/apps/index.d.ts +4 -2
  18. package/dist/apps/index.js +1 -1
  19. package/dist/bin/ui-check.js +1 -1
  20. package/dist/{chunk-L3U2R7DH.js → chunk-3DGTIWZP.js} +1 -1
  21. package/dist/{chunk-AZO5NPB4.js → chunk-4VTHXNGZ.js} +625 -625
  22. package/dist/{chunk-KS7OSQ3Y.js → chunk-5ZDM6WIC.js} +11 -11
  23. package/dist/{chunk-E2D54MVV.js → chunk-6CFBF543.js} +2 -2
  24. package/dist/{chunk-LCTSBQBJ.js → chunk-7WZEFHPS.js} +1 -1
  25. package/dist/chunk-BSJIBRWC.js +1 -0
  26. package/dist/chunk-C3QOHMR6.js +1 -0
  27. package/dist/{chunk-YJRC6IKD.js → chunk-CIXQKCFA.js} +4 -4
  28. package/dist/{chunk-Q7UGGJ5X.js → chunk-FORN7LG7.js} +1 -1
  29. package/dist/chunk-J3LIIIHJ.js +1 -0
  30. package/dist/{chunk-7H6Q5TNN.js → chunk-KDRAU4XQ.js} +8 -8
  31. package/dist/{chunk-ZOPYAOUP.js → chunk-KVOFUFPP.js} +1 -1
  32. package/dist/{chunk-KDHXRJIX.js → chunk-LK7V32MR.js} +1 -1
  33. package/dist/{chunk-TZ2BPFCT.js → chunk-N6STBYXR.js} +111 -111
  34. package/dist/{chunk-54OP3M3K.js → chunk-NHIGOEZF.js} +1 -1
  35. package/dist/{chunk-PE6MTNFO.js → chunk-PE4F4MJE.js} +4 -4
  36. package/dist/chunk-R7EBJKN2.js +69 -0
  37. package/dist/chunk-RQOP5JAJ.js +9 -0
  38. package/dist/{chunk-AI6HQ55O.js → chunk-SVO3ES2E.js} +1 -1
  39. package/dist/{chunk-RKR5V4QR.js → chunk-T4CFSGSL.js} +6 -6
  40. package/dist/{chunk-N6BJG6AL.js → chunk-UAIVAA5X.js} +11 -11
  41. package/dist/{chunk-REXHKIIJ.js → chunk-WNEO7TSP.js} +1 -1
  42. package/dist/{chunk-XJYXKO7K.js → chunk-ZAE6ROV7.js} +15 -15
  43. package/dist/file-intake/index.js +1 -1
  44. package/dist/i18n/index.d.ts +3 -2
  45. package/dist/i18n/index.js +1 -1
  46. package/dist/{index-BS_HzJCc.d.ts → index-HAwjA-hn.d.ts} +25 -4
  47. package/dist/index.d.ts +3 -3
  48. package/dist/index.js +656 -656
  49. package/dist/locales/zh-Hans.d.ts +59 -0
  50. package/dist/locales/zh-Hans.js +1 -0
  51. package/dist/map/index.js +3 -3
  52. package/dist/page-tabs/index.js +4 -4
  53. package/dist/pdf/index.js +1 -1
  54. package/dist/{strings-C3kt6WTH.d.ts → strings-ZbotP_I6.d.ts} +368 -0
  55. package/dist/ui/index.d.ts +2 -2
  56. package/dist/ui/index.js +1 -1
  57. package/package.json +6 -1
  58. package/dist/Calculator-AGQQYMMZ.js +0 -29
  59. package/dist/ConfirmDialog-6PVUVYXZ.js +0 -1
  60. package/dist/PdfViewer-RKRGO7Q2.js +0 -1
  61. package/dist/Preview-5CALO6PW.js +0 -187
  62. package/dist/Spreadsheet-F3VBCPHF.js +0 -37
  63. package/dist/chunk-3YTHR7IC.js +0 -1
  64. package/dist/chunk-4PCIZFDR.js +0 -9
  65. package/dist/chunk-MFXG5BWL.js +0 -1
  66. package/dist/chunk-VIIBZ6DE.js +0 -69
@@ -1,69 +0,0 @@
1
- import{toast_default as e}from"./chunk-L3U2R7DH.js";import{forwardRef as t,useRef as r,useState as n,useMemo as o,useEffect as i,useImperativeHandle as a}from"react";import{jsx as l,jsxs as s,Fragment as c}from"react/jsx-runtime";var d=["#ef4444","#f97316","#eab308","#22c55e","#3b82f6","#8b5cf6","#000000","#ffffff"],h=[{id:"system",label:"System",css:"-apple-system, system-ui, sans-serif"},{id:"serif",label:"Serif",css:'Georgia, "Times New Roman", serif'},{id:"mono",label:"Mono",css:'ui-monospace, "SF Mono", Menlo, monospace'},{id:"cursive",label:"Cursive",css:'"Brush Script MT", "Comic Sans MS", cursive'}],u=()=>Math.random().toString(36).slice(2,9),p=t(function({src:t,filename:p,onApply:x,onCancel:m},M){const N=r(null),L=r(null),D=r(null),z=r(null),[P,E]=n("select"),[$,I]=n(d[0]),[W,B]=n(4),[R,S]=n(24),[j,A]=n(h[0].id),[T,U]=n(!0),[F,H]=n(!1),[O,Z]=n(!1),[K,V]=n(null),[X,q]=n(null),[G,Y]=n(6),[_,J]=n(12),[Q,ee]=n([]),[te,re]=n(null),[ne,oe]=n(null),[ie,ae]=n(null),[le,se]=n(1),[ce,de]=n(null),[he,ue]=n(null),[pe,ye]=n(null),xe=r(null),[me,ge]=n(!1),we=o(()=>ie?{w:ie.w*le,h:ie.h*le}:null,[ie,le]),fe=we&&ne?we.w/ne.w:1,be=o(()=>Q.find(e=>e.id===te)??null,[Q,te]);i(()=>{"select"===P&&be&&("color"in be&&I(be.color),"stroke"in be&&B(be.stroke),"rect"===be.type&&J(be.radius),"text"===be.type&&(S(be.size),A(be.font),U(be.bold),H(be.italic),Z(be.underline),V(be.borderColor),q(be.background),Y(be.padding)))},[te]),i(()=>{const r=new Image;r.crossOrigin="anonymous",r.onload=()=>{z.current=r,oe({w:r.naturalWidth,h:r.naturalHeight}),ee([]),re(null)},r.onerror=()=>e.error("Failed to load image"),r.src=t},[t]),i(()=>{if(!ne)return;const e=()=>{const e=N.current;if(!e)return;const t=e.getBoundingClientRect(),r=Math.max(0,t.width-32),n=Math.max(0,t.height-32);if(0===r||0===n)return;const o=ne.w/ne.h;let i=ne.w,a=ne.h;i>r&&(i=r,a=i/o),a>n&&(a=n,i=a*o),ae({w:i,h:a})};e();const t=new ResizeObserver(e);return N.current&&t.observe(N.current),()=>t.disconnect()},[ne]);const ve=o(()=>Q.filter(e=>"mosaic"===e.type),[Q]);i(()=>{const e=z.current,t=L.current;if(!e||!t||!ne)return;t.width=ne.w,t.height=ne.h;const r=t.getContext("2d");r.drawImage(e,0,0);for(const e of ve)C(r,e)},[ne,ve,ie]);const ke=e=>{const t=D.current;if(!t)return{x:0,y:0};const r=t.createSVGPoint();r.x=e.clientX,r.y=e.clientY;const n=t.getScreenCTM();if(!n)return{x:0,y:0};const o=r.matrixTransform(n.inverse());return{x:o.x,y:o.y}},Me=e=>{xe.current=e,ge(!0)};i(()=>{if(!me)return;const e=e=>{const t=xe.current;if(!t)return;const r=ke(e);if("draw"===t.kind)de(f(P,t.start,r,$,W,_));else if("pen"===t.kind){const e=t.points[t.points.length-1];(Math.abs(r.x-e.x)>1||Math.abs(r.y-e.y)>1)&&(t.points.push(r),de({id:"",type:"draw",points:t.points.slice(),color:$,stroke:W}))}else if("crop"===t.kind)ye(k(t.start,r));else if("move"===t.kind){const e=r.x-t.start.x,n=r.y-t.start.y;ee(r=>r.map(r=>r.id===t.id?b(t.original,e,n):r))}else"resize"===t.kind&&ee(e=>e.map(e=>e.id===t.id?function(e,t,r){if("arrow"===e.type)return"start"===t?{...e,x1:r.x,y1:r.y}:"end"===t?{...e,x2:r.x,y2:r.y}:e;if("text"===e.type||"draw"===e.type)return e;const n=e.x,o=e.x+e.w,i=e.y,a=e.y+e.h;let l=n,s=i,c=o,d=a;"nw"===t&&(l=r.x,s=r.y);"ne"===t&&(c=r.x,s=r.y);"se"===t&&(c=r.x,d=r.y);"sw"===t&&(l=r.x,d=r.y);const h=k({x:l,y:s},{x:c,y:d});return{...e,x:h.x,y:h.y,w:h.w,h:h.h}}(t.original,t.corner,r):e))},t=()=>{const e=xe.current;if(xe.current=null,ge(!1),"draw"===e?.kind)de(e=>{if(!e||("arrow"===(t=e).type?Math.abs(t.x2-t.x1)<4&&Math.abs(t.y2-t.y1)<4:"draw"===t.type?t.points.length<2:"w"in t&&"h"in t&&(t.w<4||t.h<4)))return null;var t;const r={...e,id:u()};return ee(e=>[...e,r]),re(r.id),E("select"),null});else if("pen"===e?.kind){if(e.points.length<2)return void de(null);const t={id:u(),type:"draw",points:e.points,color:$,stroke:W};ee(e=>[...e,t]),re(t.id),E("select"),de(null)}};return window.addEventListener("pointermove",e),window.addEventListener("pointerup",t),window.addEventListener("pointercancel",t),()=>{window.removeEventListener("pointermove",e),window.removeEventListener("pointerup",t),window.removeEventListener("pointercancel",t)}},[me,P,$,W,_]);i(()=>{const e=e=>{if(!document.activeElement||!/^(INPUT|TEXTAREA)$/.test(document.activeElement.tagName))return!e.metaKey&&!e.ctrlKey||"z"!==e.key&&"Z"!==e.key||e.shiftKey?void(te&&("Delete"===e.key||"Backspace"===e.key?(e.preventDefault(),ee(e=>e.filter(e=>e.id!==te)),re(null)):"Escape"===e.key&&re(null))):(e.preventDefault(),ee(e=>e.slice(0,-1)),void re(null))};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[te]);const Ce=e=>{const t=!{bold:T,italic:F,underline:O}[e];"bold"===e&&U(t),"italic"===e&&H(t),"underline"===e&&Z(t),te&&ee(r=>r.map(r=>r.id===te&&"text"===r.type?{...r,[e]:t}:r))},Ne=e=>{V(e),te&&ee(t=>t.map(t=>t.id===te&&"text"===t.type?{...t,borderColor:e}:t))},Le=e=>{q(e),te&&ee(t=>t.map(t=>t.id===te&&"text"===t.type?{...t,background:e}:t))},De=e=>{if(!he)return;const t=e??he.value;if(!t.trim())return he.editingId&&ee(e=>e.filter(e=>e.id!==he.editingId)),void ue(null);if(he.editingId)ee(e=>e.map(e=>e.id===he.editingId&&"text"===e.type?{...e,text:t}:e));else{const e={id:u(),type:"text",x:he.x,y:he.y,text:t,color:$,size:R,font:j,bold:T,italic:F,underline:O,borderColor:K,background:X,padding:G};ee(t=>[...t,e]),re(e.id),E("select")}ue(null)},ze=async()=>{const e=L.current,t=D.current;if(!e||!t||!ne)return null;const r=document.createElement("canvas");r.width=ne.w,r.height=ne.h;const n=r.getContext("2d");n.drawImage(e,0,0);const o=t.cloneNode(!0);o.querySelectorAll("[data-chrome]").forEach(e=>e.remove());const i=(new XMLSerializer).serializeToString(o),a=new Blob([i],{type:"image/svg+xml;charset=utf-8"}),l=URL.createObjectURL(a),s=new Image;return await new Promise(e=>{s.onload=()=>e(),s.onerror=()=>e(),s.src=l}),n.drawImage(s,0,0,ne.w,ne.h),URL.revokeObjectURL(l),r};a(M,()=>({save:async()=>{const t=await ze();t&&t.toBlob(t=>{if(!t)return void e.error("Failed to export");const r=URL.createObjectURL(t),n=document.createElement("a");n.href=r;const o=p.replace(/\.[^.]+$/,"");n.download=`${o}-annotated.png`,n.click(),URL.revokeObjectURL(r)},"image/png")},copy:async()=>{if(!("clipboard"in navigator)||"undefined"==typeof ClipboardItem)return void e.error("Clipboard images not supported in this browser");const t=await ze();t&&t.toBlob(async t=>{if(t)try{await navigator.clipboard.write([new ClipboardItem({"image/png":t})]),e.success("Copied to clipboard")}catch{e.error("Copy failed (clipboard permission?)")}else e.error("Failed to copy")},"image/png")}}),[ne,p]);const Pe=o(()=>[{id:"select",label:"Select / Move",icon:/* @__PURE__ */l("svg",{className:"h-4 w-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:1.8,children:/* @__PURE__ */l("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M5 3l7 17 2-7 7-2L5 3z"})})},{id:"draw",label:"Pen / Draw",icon:/* @__PURE__ */l("svg",{className:"h-4 w-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:1.8,children:/* @__PURE__ */l("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M16.862 4.487l1.687-1.688a1.875 1.875 0 112.652 2.652L6.832 19.82a4.5 4.5 0 01-1.897 1.13l-2.685.8.8-2.685a4.5 4.5 0 011.13-1.897L16.863 4.487z"})})},{id:"rect",label:"Rectangle",icon:/* @__PURE__ */l("svg",{className:"h-4 w-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:1.8,children:/* @__PURE__ */l("rect",{x:"4",y:"6",width:"16",height:"12",rx:"3"})})},{id:"circle",label:"Ellipse",icon:/* @__PURE__ */l("svg",{className:"h-4 w-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:1.8,children:/* @__PURE__ */l("ellipse",{cx:"12",cy:"12",rx:"8",ry:"6"})})},{id:"arrow",label:"Arrow",icon:/* @__PURE__ */l("svg",{className:"h-4 w-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:1.8,children:/* @__PURE__ */l("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M5 19L19 5m0 0h-7m7 0v7"})})},{id:"mosaic",label:"Mosaic",icon:/* @__PURE__ */l("svg",{className:"h-4 w-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:1.8,children:/* @__PURE__ */l("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M4 4h6v6H4zM14 4h6v6h-6zM4 14h6v6H4zM14 14h6v6h-6z"})})},{id:"text",label:"Text",icon:/* @__PURE__ */l("svg",{className:"h-4 w-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:1.8,children:/* @__PURE__ */l("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M4 6h16M12 6v14M9 20h6"})})},{id:"crop",label:"Crop",icon:/* @__PURE__ */l("svg",{className:"h-4 w-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:1.8,children:/* @__PURE__ */l("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 2v15a1 1 0 001 1h15M2 6h15a1 1 0 011 1v15"})})}],[]),Ee=e=>"p-1.5 rounded transition-colors "+(e?"bg-blue-500 text-white":"text-gray-700 hover:bg-gray-200"),$e=be?.type??("select"===P?null:P),Ie="rect"===$e||"circle"===$e||"arrow"===$e||"draw"===$e,We="rect"===$e,Be="text"===$e;/* @__PURE__ */
2
- return s("div",{className:"flex flex-col h-full bg-gray-100",children:[
3
- /* @__PURE__ */s("div",{className:"flex items-center gap-1.5 px-3 py-2 border-b border-gray-200 bg-white shrink-0 flex-wrap text-[12px]",children:[Pe.map(e=>/* @__PURE__ */l("button",{onClick:()=>{E(e.id),re(null)},title:e.label,className:Ee(P===e.id),children:e.icon},e.id)),
4
- /* @__PURE__ */l("div",{className:"h-5 w-px bg-gray-300 mx-1"}),
5
- /* @__PURE__ */l("div",{className:"flex items-center gap-1",children:d.map(e=>/* @__PURE__ */l("button",{onClick:()=>(e=>{I(e),te&&ee(t=>t.map(t=>t.id!==te||"mosaic"===t.type?t:{...t,color:e}))})(e),title:e,className:"h-5 w-5 rounded-full border "+($===e?"ring-2 ring-blue-500 ring-offset-1":"border-gray-300"),style:{background:e}},e))}),Ie&&/* @__PURE__ */s(c,{children:[
6
- /* @__PURE__ */l("div",{className:"h-5 w-px bg-gray-300 mx-1"}),
7
- /* @__PURE__ */s("label",{className:"flex items-center gap-1.5 text-gray-600",children:[
8
- /* @__PURE__ */l("span",{children:"Weight"}),
9
- /* @__PURE__ */l("input",{type:"range",min:1,max:20,step:1,value:W,onChange:e=>{return t=Number(e.target.value),B(t),void(te&&ee(e=>e.map(e=>e.id!==te?e:"rect"===e.type||"circle"===e.type||"arrow"===e.type||"draw"===e.type?{...e,stroke:t}:e)));var t},className:"w-16 accent-blue-500"}),
10
- /* @__PURE__ */l("span",{className:"tabular-nums w-5 text-right",children:W})]})]}),We&&/* @__PURE__ */s(c,{children:[
11
- /* @__PURE__ */l("div",{className:"h-5 w-px bg-gray-300 mx-1"}),
12
- /* @__PURE__ */s("label",{className:"flex items-center gap-1.5 text-gray-600",children:[
13
- /* @__PURE__ */l("span",{children:"Radius"}),
14
- /* @__PURE__ */l("input",{type:"range",min:0,max:48,step:1,value:_,onChange:e=>{return t=Number(e.target.value),J(t),void(te&&ee(e=>e.map(e=>e.id===te&&"rect"===e.type?{...e,radius:t}:e)));var t},className:"w-16 accent-blue-500"}),
15
- /* @__PURE__ */l("span",{className:"tabular-nums w-6 text-right",children:_})]})]}),Be&&/* @__PURE__ */s(c,{children:[
16
- /* @__PURE__ */l("div",{className:"h-5 w-px bg-gray-300 mx-1"}),
17
- /* @__PURE__ */l("select",{value:j,onChange:e=>{return t=e.target.value,A(t),void(te&&ee(e=>e.map(e=>e.id===te&&"text"===e.type?{...e,font:t}:e)));var t},className:"text-xs border border-gray-300 rounded px-1 py-0.5 bg-white",children:h.map(e=>/* @__PURE__ */l("option",{value:e.id,children:e.label},e.id))}),
18
- /* @__PURE__ */l("button",{onClick:()=>Ce("bold"),className:Ee(T),title:"Bold",children:/* @__PURE__ */l("span",{className:"font-bold",children:"B"})}),
19
- /* @__PURE__ */l("button",{onClick:()=>Ce("italic"),className:Ee(F),title:"Italic",children:/* @__PURE__ */l("span",{className:"italic",children:"I"})}),
20
- /* @__PURE__ */l("button",{onClick:()=>Ce("underline"),className:Ee(O),title:"Underline",children:/* @__PURE__ */l("span",{className:"underline",children:"U"})}),
21
- /* @__PURE__ */s("label",{className:"flex items-center gap-1.5 text-gray-600",children:[
22
- /* @__PURE__ */l("span",{children:"Size"}),
23
- /* @__PURE__ */l("input",{type:"range",min:10,max:96,step:1,value:R,onChange:e=>{return t=Number(e.target.value),S(t),void(te&&ee(e=>e.map(e=>e.id===te&&"text"===e.type?{...e,size:t}:e)));var t},className:"w-16 accent-blue-500"}),
24
- /* @__PURE__ */l("span",{className:"tabular-nums w-7 text-right",children:R})]}),
25
- /* @__PURE__ */s("label",{className:"flex items-center gap-1 text-gray-600",children:[
26
- /* @__PURE__ */l("span",{children:"Border"}),K?/* @__PURE__ */s(c,{children:[
27
- /* @__PURE__ */l("input",{type:"color",value:K,onChange:e=>Ne(e.target.value),title:"Text-box border color",className:"h-5 w-6 rounded border border-gray-300 bg-white p-0 cursor-pointer"}),
28
- /* @__PURE__ */l("button",{onClick:()=>Ne(null),title:"Remove border",className:"px-0.5 text-gray-400 hover:text-gray-700",children:"✕"})]}):/* @__PURE__ */l("button",{onClick:()=>Ne($),title:"Add a border",className:"px-1.5 py-0.5 rounded border border-gray-300 text-gray-600 hover:bg-gray-100",children:"Add"})]}),
29
- /* @__PURE__ */s("label",{className:"flex items-center gap-1 text-gray-600",children:[
30
- /* @__PURE__ */l("span",{children:"Fill"}),X?/* @__PURE__ */s(c,{children:[
31
- /* @__PURE__ */l("input",{type:"color",value:X,onChange:e=>Le(e.target.value),title:"Text-box background color",className:"h-5 w-6 rounded border border-gray-300 bg-white p-0 cursor-pointer"}),
32
- /* @__PURE__ */l("button",{onClick:()=>Le(null),title:"Remove fill",className:"px-0.5 text-gray-400 hover:text-gray-700",children:"✕"})]}):/* @__PURE__ */l("button",{onClick:()=>Le("#ffffff"),title:"Add a background fill",className:"px-1.5 py-0.5 rounded border border-gray-300 text-gray-600 hover:bg-gray-100",children:"Add"})]}),
33
- /* @__PURE__ */s("label",{className:"flex items-center gap-1.5 text-gray-600",children:[
34
- /* @__PURE__ */l("span",{children:"Pad"}),
35
- /* @__PURE__ */l("input",{type:"range",min:0,max:40,step:1,value:G,onChange:e=>{return t=Number(e.target.value),Y(t),void(te&&ee(e=>e.map(e=>e.id===te&&"text"===e.type?{...e,padding:t}:e)));var t},className:"w-14 accent-blue-500"}),
36
- /* @__PURE__ */l("span",{className:"tabular-nums w-6 text-right",children:G})]})]}),
37
- /* @__PURE__ */l("div",{className:"h-5 w-px bg-gray-300 mx-1"}),
38
- /* @__PURE__ */l("button",{onClick:()=>se(e=>Math.max(.25,Math.round(100*(e-.25))/100)),className:"px-2 py-1 rounded hover:bg-gray-200 text-gray-700",title:"Zoom out",children:"−"}),
39
- /* @__PURE__ */s("span",{className:"text-gray-600 tabular-nums w-10 text-center",children:[Math.round(100*le),"%"]}),
40
- /* @__PURE__ */l("button",{onClick:()=>se(e=>Math.min(4,Math.round(100*(e+.25))/100)),className:"px-2 py-1 rounded hover:bg-gray-200 text-gray-700",title:"Zoom in",children:"+"}),
41
- /* @__PURE__ */l("button",{onClick:()=>se(1),className:"px-2 py-1 rounded hover:bg-gray-200 text-gray-700",title:"Fit to area",children:"Fit"}),
42
- /* @__PURE__ */l("div",{className:"h-5 w-px bg-gray-300 mx-1"}),
43
- /* @__PURE__ */l("button",{onClick:()=>{ee(e=>e.slice(0,-1)),re(null)},disabled:0===Q.length,className:"px-2 py-1 rounded hover:bg-gray-200 disabled:opacity-30 text-gray-700",children:"Undo"}),
44
- /* @__PURE__ */s("div",{className:"ml-auto flex items-center gap-2",children:[pe&&/* @__PURE__ */s(c,{children:[
45
- /* @__PURE__ */l("button",{onClick:()=>{if(!pe||!z.current||!ne)return;const e=pe,t=document.createElement("canvas");t.width=Math.round(e.w),t.height=Math.round(e.h);const r=t.getContext("2d"),n=document.createElement("canvas");n.width=ne.w,n.height=ne.h;const o=n.getContext("2d");o.drawImage(z.current,0,0);for(const e of ve)C(o,e);r.drawImage(n,e.x,e.y,e.w,e.h,0,0,e.w,e.h);const i=new Image;i.onload=()=>{z.current=i,oe({w:i.naturalWidth,h:i.naturalHeight}),ee(t=>t.filter(e=>"mosaic"!==e.type).map(t=>b(t,-e.x,-e.y)).filter(e=>function(e,t,r){const n=v(e);return n.x+n.w>0&&n.y+n.h>0&&n.x<t&&n.y<r}(e,i.naturalWidth,i.naturalHeight))),ye(null)},i.src=t.toDataURL("image/png")},className:"px-2 py-1 rounded bg-blue-500 text-white hover:bg-blue-600",children:"Apply Crop"}),
46
- /* @__PURE__ */l("button",{onClick:()=>ye(null),className:"px-2 py-1 rounded hover:bg-gray-200 text-gray-700",children:"Cancel"})]}),x&&!pe&&/* @__PURE__ */s(c,{children:[m&&/* @__PURE__ */l("button",{onClick:m,className:"px-3 py-1 rounded hover:bg-gray-200 text-gray-700 text-xs font-medium",children:"Cancel"}),
47
- /* @__PURE__ */l("button",{onClick:async()=>{const t=await ze();t?t.toBlob(t=>{t?x(t):e.error("Failed to export")},"image/png"):e.error("Failed to export")},className:"px-3 py-1 rounded bg-blue-500 text-white hover:bg-blue-600 text-xs font-medium",children:"Apply"})]})]})]}),
48
- /* @__PURE__ */l("div",{ref:N,className:"flex-1 overflow-auto bg-gray-200 flex items-center justify-center p-4 relative",children:we&&ne&&/* @__PURE__ */s("div",{className:"relative shadow-lg rounded overflow-hidden bg-white shrink-0",style:{width:we.w,height:we.h},children:[
49
- /* @__PURE__ */l("canvas",{ref:L,style:{position:"absolute",inset:0,width:"100%",height:"100%",display:"block"}}),
50
- /* @__PURE__ */s("svg",{ref:D,viewBox:`0 0 ${ne.w} ${ne.h}`,preserveAspectRatio:"none",style:{position:"absolute",inset:0,width:"100%",height:"100%",touchAction:"none",cursor:"select"===P?"default":"text"===P?"text":"crosshair"},onPointerDown:e=>{if("select"===P)return void re(null);if("text"===P){if(he)return void De();const t=ke(e);return void ue({x:t.x,y:t.y,value:""})}const t=ke(e);if("crop"!==P){if("draw"===P)return Me({kind:"pen",points:[t]}),void de({id:"",type:"draw",points:[t],color:$,stroke:W});de(f(P,t,t,$,W,_)),Me({kind:"draw",start:t})}else Me({kind:"crop",start:t})},children:[Q.map(e=>/* @__PURE__ */l(y,{anno:e,selected:te===e.id,zoom:le,onPointerDown:t=>((e,t)=>{"select"===P&&(e.stopPropagation(),re(t.id),Me({kind:"move",id:t.id,start:ke(e),original:t}))})(t,e),onDoubleClick:()=>{var t;"text"===(t=e).type&&ue({x:t.x,y:t.y,value:t.text,editingId:t.id})},onHandlePointerDown:(t,r)=>((e,t,r)=>{e.stopPropagation(),Me({kind:"resize",id:t.id,corner:r,start:ke(e),original:t})})(t,e,r)},e.id)),ce&&/* @__PURE__ */l(y,{anno:{...ce,id:"__preview"},preview:!0}),pe&&/* @__PURE__ */l(g,{rect:pe,imageSize:ne})]}),he&&/* @__PURE__ */l(w,{pendingText:he,color:$,size:R,font:h.find(e=>e.id===j)?.css??h[0].css,bold:T,italic:F,underline:O,borderColor:K,background:X,padding:G,scale:fe,onChange:e=>ue({...he,value:e}),onCommit:De,onCancel:()=>ue(null)})]})}),
51
- /* @__PURE__ */l("div",{className:"px-3 py-1.5 border-t border-gray-200 bg-white text-[11px] text-gray-500 shrink-0",children:"select"===P?te?"Drag to move. Drag a corner to resize. Delete / Backspace removes. Click outside to deselect.":"Tap a shape to select. Double-click text to edit.":"text"===P?"Click to drop a text label.":"crop"===P?"Drag a rectangle to set the crop region.":"draw"===P?"Drag to draw freehand.":"Drag on the image to draw."})]})});function y({anno:e,selected:t,preview:r,zoom:n=1,onPointerDown:o,onDoubleClick:i,onHandlePointerDown:a}){const d=v(e),u=o?{onPointerDown:o,pointerEvents:"all",style:{cursor:"move"}}:{},p=i?{onDoubleClick:i}:{};let y;if("rect"===e.type)y=/* @__PURE__ */l("rect",{x:e.x,y:e.y,width:e.w,height:e.h,rx:e.radius,ry:e.radius,fill:"none",stroke:e.color,strokeWidth:e.stroke,strokeLinecap:"round",strokeLinejoin:"round",...u});else if("circle"===e.type)y=/* @__PURE__ */l("ellipse",{cx:e.x+e.w/2,cy:e.y+e.h/2,rx:e.w/2,ry:e.h/2,fill:"none",stroke:e.color,strokeWidth:e.stroke,...u});else if("arrow"===e.type)y=/* @__PURE__ */l(m,{anno:e,interactive:u});else if("draw"===e.type)y=/* @__PURE__ */l("path",{d:M(e.points),fill:"none",stroke:e.color,strokeWidth:e.stroke,strokeLinecap:"round",strokeLinejoin:"round",...u});else if("mosaic"===e.type)y=/* @__PURE__ */l("rect",{x:e.x,y:e.y,width:e.w,height:e.h,fill:"rgba(0,0,0,0.001)",stroke:t?"#3b82f6":"none",strokeWidth:t?2:0,strokeDasharray:t?"6,4":void 0,...u});else{const t=h.find(t=>t.id===e.font)?.css??h[0].css,r=e.padding??0,n=!!e.borderColor||!!e.background,o=v(e),i=e.borderColor?Math.max(1,Math.round(e.size/12)):0;y=/* @__PURE__ */s("g",{...u,...p,children:[n&&/* @__PURE__ */l("rect",{x:o.x-r,y:o.y-r,width:Math.max(0,o.w)+2*r,height:Math.max(0,o.h)+2*r,rx:Math.min(8,r),ry:Math.min(8,r),fill:e.background??"none",stroke:e.borderColor??"none",strokeWidth:i}),
52
- /* @__PURE__ */l("text",{x:e.x,y:e.y+e.size,fill:e.color,fontSize:e.size,fontWeight:e.bold?700:400,fontStyle:e.italic?"italic":"normal",textDecoration:e.underline?"underline":void 0,fontFamily:t,style:{userSelect:"none"},children:e.text.split("\n").map((t,r)=>/* @__PURE__ */l("tspan",{x:e.x,dy:0===r?0:1.2*e.size,children:t},r))})]})}/* @__PURE__ */
53
- return s("g",{children:[y,t&&!r&&/* @__PURE__ */s(c,{children:[
54
- /* @__PURE__ */l("rect",{"data-chrome":"selection",x:d.x-4,y:d.y-4,width:d.w+8,height:d.h+8,fill:"none",stroke:"#3b82f6",strokeWidth:2/n,strokeDasharray:`${6/n},${4/n}`,pointerEvents:"none"}),a&&/* @__PURE__ */l(x,{anno:e,zoom:n,onHandlePointerDown:a})]})]})}function x({anno:e,zoom:t,onHandlePointerDown:r}){const n=6/t,o=1.5/t,i=e=>({fill:"#fff",stroke:"#3b82f6",strokeWidth:o,pointerEvents:"all",style:{cursor:e},"data-chrome":"handle"});if("arrow"===e.type)/* @__PURE__ */
55
- return s(c,{children:[
56
- /* @__PURE__ */l("circle",{cx:e.x1,cy:e.y1,r:n,...i("grab"),onPointerDown:e=>r(e,"start")}),
57
- /* @__PURE__ */l("circle",{cx:e.x2,cy:e.y2,r:n,...i("grab"),onPointerDown:e=>r(e,"end")})]});if("text"===e.type||"draw"===e.type)return null;const a=e.x,d=e.y,h=e.w,u=e.h;/* @__PURE__ */
58
- return s(c,{children:[
59
- /* @__PURE__ */l("circle",{cx:a,cy:d,r:n,...i("nwse-resize"),onPointerDown:e=>r(e,"nw")}),
60
- /* @__PURE__ */l("circle",{cx:a+h,cy:d,r:n,...i("nesw-resize"),onPointerDown:e=>r(e,"ne")}),
61
- /* @__PURE__ */l("circle",{cx:a+h,cy:d+u,r:n,...i("nwse-resize"),onPointerDown:e=>r(e,"se")}),
62
- /* @__PURE__ */l("circle",{cx:a,cy:d+u,r:n,...i("nesw-resize"),onPointerDown:e=>r(e,"sw")})]})}function m({anno:e,interactive:t}){const r=Math.max(12,4*e.stroke),n=Math.atan2(e.y2-e.y1,e.x2-e.x1),o=n+Math.PI-Math.PI/7,i=n+Math.PI+Math.PI/7,a=`M${e.x2},${e.y2} L${e.x2+r*Math.cos(o)},${e.y2+r*Math.sin(o)} L${e.x2+r*Math.cos(i)},${e.y2+r*Math.sin(i)} Z`;/* @__PURE__ */
63
- return s("g",{...t,children:[
64
- /* @__PURE__ */l("line",{x1:e.x1,y1:e.y1,x2:e.x2,y2:e.y2,stroke:e.color,strokeWidth:e.stroke,strokeLinecap:"round"}),
65
- /* @__PURE__ */l("path",{d:a,fill:e.color})]})}function g({rect:e,imageSize:t}){/* @__PURE__ */
66
- return s("g",{pointerEvents:"none",children:[
67
- /* @__PURE__ */l("path",{d:`M0,0 H${t.w} V${t.h} H0 Z M${e.x},${e.y} V${e.y+e.h} H${e.x+e.w} V${e.y} Z`,fill:"rgba(0,0,0,0.45)",fillRule:"evenodd"}),
68
- /* @__PURE__ */l("rect",{x:e.x,y:e.y,width:e.w,height:e.h,fill:"none",stroke:"#fff",strokeWidth:2,strokeDasharray:"8,6"})]})}function w({pendingText:e,color:t,size:n,font:o,bold:a,italic:s,underline:c,borderColor:d,background:h,padding:u,scale:p,onChange:y,onCommit:x,onCancel:m}){const g=r(null);i(()=>{const e=requestAnimationFrame(()=>{g.current?.focus(),g.current?.select?.()});return()=>cancelAnimationFrame(e)},[]);const w=()=>x(g.current?.value),f=d?Math.max(1,Math.round(n/12)):0;/* @__PURE__ */
69
- return l("div",{style:{position:"absolute",left:e.x*p+"px",top:e.y*p+"px",transform:"translateY(-2px)",zIndex:5},onPointerDown:e=>e.stopPropagation(),children:/* @__PURE__ */l("textarea",{ref:g,value:e.value,onChange:e=>y(e.target.value),onBlur:w,onKeyDown:e=>{"Escape"===e.key?(e.preventDefault(),m()):"Enter"!==e.key||e.shiftKey||(e.preventDefault(),w())},placeholder:"Type then Enter…",rows:1,className:"outline-none resize-none shadow-md",style:{color:t,fontSize:n*p+"px",fontFamily:o,fontWeight:a?700:400,fontStyle:s?"italic":"normal",textDecoration:c?"underline":void 0,minWidth:80,padding:u*p+"px",borderRadius:Math.min(8,u)*p+"px",border:d?`${f*p}px solid ${d}`:"1px dashed #60a5fa",background:h??"rgba(255,255,255,0.95)"}})})}function f(e,t,r,n,o,i){if("rect"===e){const e=k(t,r);return{id:"",type:"rect",x:e.x,y:e.y,w:e.w,h:e.h,color:n,stroke:o,radius:i}}if("circle"===e){const e=k(t,r);return{id:"",type:"circle",x:e.x,y:e.y,w:e.w,h:e.h,color:n,stroke:o}}if("arrow"===e)return{id:"",type:"arrow",x1:t.x,y1:t.y,x2:r.x,y2:r.y,color:n,stroke:o};if("mosaic"===e){const e=k(t,r);return{id:"",type:"mosaic",x:e.x,y:e.y,w:e.w,h:e.h}}return null}function b(e,t,r){return"arrow"===e.type?{...e,x1:e.x1+t,y1:e.y1+r,x2:e.x2+t,y2:e.y2+r}:"draw"===e.type?{...e,points:e.points.map(e=>({x:e.x+t,y:e.y+r}))}:(e.type,{...e,x:e.x+t,y:e.y+r})}function v(e){if("arrow"===e.type){return{x:Math.min(e.x1,e.x2),y:Math.min(e.y1,e.y2),w:Math.abs(e.x2-e.x1),h:Math.abs(e.y2-e.y1)}}if("draw"===e.type){if(0===e.points.length)return{x:0,y:0,w:0,h:0};let t=e.points[0].x,r=e.points[0].x,n=e.points[0].y,o=e.points[0].y;for(const i of e.points)i.x<t&&(t=i.x),i.x>r&&(r=i.x),i.y<n&&(n=i.y),i.y>o&&(o=i.y);return{x:t,y:n,w:r-t,h:o-n}}if("text"===e.type){const t=e.text.split("\n"),r=t.reduce((e,t)=>Math.max(e,t.length),0);return{x:e.x,y:e.y,w:r*e.size*.55,h:t.length*e.size*1.2}}return{x:e.x,y:e.y,w:e.w,h:e.h}}function k(e,t){return{x:Math.min(e.x,t.x),y:Math.min(e.y,t.y),w:Math.abs(e.x-t.x),h:Math.abs(e.y-t.y)}}function M(e){if(0===e.length)return"";let t=`M ${e[0].x} ${e[0].y}`;for(let r=1;r<e.length;r++)t+=` L ${e[r].x} ${e[r].y}`;return t}function C(e,t){const r=Math.round(Math.max(0,t.x)),n=Math.round(Math.max(0,t.y)),o=Math.round(Math.min(e.canvas.width-r,t.w)),i=Math.round(Math.min(e.canvas.height-n,t.h));if(o<2||i<2)return;const a=e.getImageData(r,n,o,i);for(let e=0;e<i;e+=12)for(let t=0;t<o;t+=12){let r=0,n=0,l=0,s=0,c=0;const d=Math.min(12,o-t),h=Math.min(12,i-e);for(let i=0;i<h;i++)for(let h=0;h<d;h++){const d=4*((e+i)*o+(t+h));r+=a.data[d],n+=a.data[d+1],l+=a.data[d+2],s+=a.data[d+3],c++}r=Math.round(r/c),n=Math.round(n/c),l=Math.round(l/c),s=Math.round(s/c);for(let i=0;i<h;i++)for(let c=0;c<d;c++){const d=4*((e+i)*o+(t+c));a.data[d]=r,a.data[d+1]=n,a.data[d+2]=l,a.data[d+3]=s}}e.putImageData(a,r,n)}export{p as ImageAnnotator_default};