@nice2dev/ui-forms 1.0.14 → 1.0.16

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.
@@ -0,0 +1,419 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),I=require("./index-DTUvpoAO.cjs"),a=require("react");function Mt(n,t,i){return Math.max(t,Math.min(i,n))}function qt({h:n,s:t,v:i}){n=(n%360+360)%360;const l=i*t,d=l*(1-Math.abs(n/60%2-1)),f=i-l;let _=0,S=0,M=0;return n<60?(_=l,S=d):n<120?(_=d,S=l):n<180?(S=l,M=d):n<240?(S=d,M=l):n<300?(_=d,M=l):(_=l,M=d),{r:Math.round((_+f)*255),g:Math.round((S+f)*255),b:Math.round((M+f)*255)}}function _t({r:n,g:t,b:i}){n/=255,t/=255,i/=255;const l=Math.max(n,t,i),d=Math.min(n,t,i),f=l-d;let _=0;return f!==0&&(l===n?_=(t-i)/f%6:l===t?_=(i-n)/f+2:_=(n-t)/f+4,_=(_*60+360)%360),{h:_,s:l===0?0:f/l,v:l}}function Vt({r:n,g:t,b:i}){n/=255,t/=255,i/=255;const l=Math.max(n,t,i),d=Math.min(n,t,i),f=(l+d)/2;if(l===d)return{h:0,s:0,l:f};const _=l-d,S=f>.5?_/(2-l-d):_/(l+d);let M=0;return l===n?M=((t-i)/_+(t<i?6:0))/6:l===t?M=((i-n)/_+2)/6:M=((n-t)/_+4)/6,{h:M*360,s:S,l:f}}function Je(n){const t=n.replace("#",""),i=t.length===3?t[0]+t[0]+t[1]+t[1]+t[2]+t[2]:t,l=parseInt(i,16);return{r:l>>16&255,g:l>>8&255,b:l&255}}function Bt({r:n,g:t,b:i}){return"#"+[n,t,i].map(l=>l.toString(16).padStart(2,"0")).join("")}function Se(n){return Bt(qt(n))}function Be(n){return _t(Je(n))}function Xt(n,t){const i=[];for(let l=0;l<t;l++){const d=t<=1?.5:l/(t-1),f=Mt(n.s*(.3+d*.7),0,1),_=Mt(n.v*(1.2-d*.7),0,1);i.push(Se({h:n.h,s:f,v:_}))}return i}function kt(n,t){if(n==="custom")return[0];const i=t??30;switch(n){case"monochromatic":return[0];case"complementary":return[0,180];case"split-complementary":return[0,180-i,180+i];case"analogous":return[0,-i,i];case"triadic":return[0,120,240];case"tetradic":return[0,60,180,240];case"square":return[0,90,180,270]}}function Ge(n,t,i){return kt(t,i).map(l=>((n+l)%360+360)%360)}function St({r:n,g:t,b:i}){const[l,d,f]=[n,t,i].map(_=>{const S=_/255;return S<=.03928?S/12.92:Math.pow((S+.055)/1.055,2.4)});return .2126*l+.7152*d+.0722*f}function at(n,t){const i=St(Je(n)),l=St(Je(t)),d=Math.max(i,l),f=Math.min(i,l);return(d+.05)/(f+.05)}function it(n){return n>=7?"AAA":n>=4.5?"AA":n>=3?"AA-lg":"Fail"}const Gt={"lightest-pastel":{sRange:[.1,.25],vRange:[.92,1]},"bright-pastel":{sRange:[.25,.45],vRange:[.9,1]},shiny:{sRange:[.7,.95],vRange:[.9,1]},pastel:{sRange:[.3,.55],vRange:[.75,.92]},full:{sRange:[.75,1],vRange:[.75,1]},dark:{sRange:[.6,.9],vRange:[.3,.55]},deep:{sRange:[.85,1],vRange:[.45,.65]},muted:{sRange:[.15,.35],vRange:[.5,.7]},earth:{sRange:[.3,.6],vRange:[.4,.65]}};function rt(n,t){const i=Gt[t];return n.map(l=>{const d=(i.sRange[0]+i.sRange[1])/2,f=(i.vRange[0]+i.vRange[1])/2;return Se({h:l,s:d,v:f})})}function Tn(){return Math.floor(Math.random()*360)}function Jt(n,t,i){const l=Tn(),d=Ge(l,n,i),f=[];for(let _=0;_<t;_++){const S=d[_%d.length],M=.55+Math.random()*.4,R=.5+Math.random()*.45;f.push(Se({h:S+(Math.random()-.5)*8,s:M,v:R}))}return f}const Rn=({hues:n,baseHue:t,onBaseHueChange:i,mode:l,distance:d,disabled:f})=>{const _=a.useCallback(z=>{if(f)return;const g=z.currentTarget.getBoundingClientRect(),C=z.clientX-g.left-120,W=z.clientY-g.top-120,ne=(Math.atan2(W,C)*180/Math.PI+360)%360;i(Math.round(ne))},[120,120,f,i]),S=[];for(let z=0;z<360;z+=2){const g=(z-1)*Math.PI/180,C=(z+1)*Math.PI/180,W=Se({h:z,s:1,v:1});S.push(e.jsx("path",{d:`M${120+55*Math.cos(g)},${120+55*Math.sin(g)} L${120+110*Math.cos(g)},${120+110*Math.sin(g)} A110,110 0 0,1 ${120+110*Math.cos(C)},${120+110*Math.sin(C)} L${120+55*Math.cos(C)},${120+55*Math.sin(C)} A55,55 0 0,0 ${120+55*Math.cos(g)},${120+55*Math.sin(g)} Z`,fill:W},z))}const M=`wheel-center-${l}`,R=n.map((z,g)=>{const C=z*Math.PI/180;return e.jsx("circle",{cx:120+82.5*Math.cos(C),cy:120+82.5*Math.sin(C),r:g===0?8:6,fill:Se({h:z,s:.85,v:.9}),stroke:g===0?"var(--bg-primary, #fff)":"var(--border-color, #ccc)",strokeWidth:g===0?3:2},g)});let K=null;if(l==="analogous"||l==="split-complementary"){const z=kt(l,d).slice(1).map((g,C)=>{const W=(t+g)*Math.PI/180;return e.jsx("line",{x1:120,y1:120,x2:120+82.5*Math.cos(W),y2:120+82.5*Math.sin(W),stroke:"var(--nice-overlay-light-30, rgba(255, 255, 255, 0.3))",strokeWidth:1,strokeDasharray:"3,3"},`dline-${C}`)});K=e.jsx(e.Fragment,{children:z})}return e.jsxs("svg",{className:"nice-palette__wheel",viewBox:"0 0 240 240",width:240,height:240,onClick:_,style:{cursor:f?"default":"crosshair"},children:[e.jsx("defs",{children:e.jsxs("radialGradient",{id:M,children:[e.jsx("stop",{offset:"0%",stopColor:"var(--nice-bg, #fff)"}),e.jsx("stop",{offset:"100%",stopColor:"transparent"})]})}),S,e.jsx("circle",{cx:120,cy:120,r:53,fill:Se({h:t,s:.6,v:.85})}),e.jsx("circle",{cx:120,cy:120,r:53,fill:`url(#${M})`,opacity:.4}),K,R]})},Dn=({colors:n})=>{if(n.length<2)return null;const t=[];for(let i=0;i<n.length;i++){const l=at(n[i],"var(--bg-primary, #ffffff)"),d=at(n[i],"var(--text-primary, #000000)");t.push({a:n[i],b:"var(--bg-primary, #ffffff)",ratio:l,level:it(l)}),t.push({a:n[i],b:"var(--text-primary, #000000)",ratio:d,level:it(d)});for(let f=i+1;f<n.length;f++){const _=at(n[i],n[f]);t.push({a:n[i],b:n[f],ratio:_,level:it(_)})}}return e.jsxs("div",{className:"nice-palette__contrast",children:[e.jsx("div",{className:"nice-palette__section-title",children:"Contrast Analysis (WCAG 2.1)"}),e.jsx("div",{className:"nice-palette__contrast-grid",children:t.map((i,l)=>e.jsxs("div",{className:"nice-palette__contrast-pair",children:[e.jsxs("div",{className:"nice-palette__contrast-swatches",children:[e.jsx("span",{className:"nice-palette__contrast-dot",style:{background:i.a}}),e.jsx("span",{className:"nice-palette__contrast-vs",children:"vs"}),e.jsx("span",{className:"nice-palette__contrast-dot",style:{background:i.b}})]}),e.jsxs("span",{className:"nice-palette__contrast-ratio",children:[i.ratio.toFixed(1),":1"]}),e.jsx("span",{className:`nice-palette__contrast-level nice-palette__contrast-level--${i.level.toLowerCase().replace("-","")}`,children:i.level})]},l))})]})},Ln=({hex:n})=>{const t=Je(n),i=Vt(t),l=_t(t);return e.jsxs("div",{className:"nice-palette__color-info",children:[e.jsxs("div",{children:[e.jsx("strong",{children:"HEX"})," ",n.toUpperCase()]}),e.jsxs("div",{children:[e.jsx("strong",{children:"RGB"})," ",t.r,", ",t.g,", ",t.b]}),e.jsxs("div",{children:[e.jsx("strong",{children:"HSL"})," ",Math.round(i.h),"°, ",Math.round(i.s*100),"%,"," ",Math.round(i.l*100),"%"]}),e.jsxs("div",{children:[e.jsx("strong",{children:"HSV"})," ",Math.round(l.h),"°, ",Math.round(l.s*100),"%,"," ",Math.round(l.v*100),"%"]})]})},Et={monochromatic:"Monochromatic",complementary:"Complementary","split-complementary":"Split-Complementary",analogous:"Analogous",triadic:"Triadic",tetradic:"Tetradic (Rectangle)",square:"Square",custom:"Custom"},Pn={"lightest-pastel":"Lightest Pastel","bright-pastel":"Bright Pastel",shiny:"Shiny",pastel:"Pastel",full:"Full Colors",dark:"Dark",deep:"Deep Colors",muted:"Muted",earth:"Earth Tones"},An=["monochromatic","complementary","split-complementary","analogous","triadic","tetradic","square","custom"],Zt=a.forwardRef(({id:n,className:t,style:i,accessMode:l,value:d,onChange:f,minColors:_=1,maxColors:S=8,harmonyMode:M,onHarmonyModeChange:R,distance:K,onDistanceChange:z,preset:g,onPresetChange:C,showWheel:W=!0,showContrast:ne=!0,showInfo:Q=!0,showPresets:J=!0,presets:h=[],showVariations:L=!0,showRandom:w=!0,variationCount:E=5,label:X,disabled:b},j)=>{const x=I.ml(l,n),T=x==="hidden";(x==="disabled"||x==="readOnly")&&(b=!0);const A=I.Xs(n),[O,v]=a.useState("analogous"),[c,P]=a.useState(30),[y,k]=a.useState(""),[s,o]=a.useState(0),u=M??O,r=K??c,p=g??y,q=a.useCallback(Z=>{v(Z),R==null||R(Z)},[R]),F=a.useCallback(Z=>{P(Z),z==null||z(Z)},[z]),G=a.useCallback(Z=>{k(Z),Z&&(C==null||C(Z))},[C]),ie=a.useMemo(()=>["var(--color-primary, #3b82f6)","var(--color-error, #ef4444)","var(--color-success, #22c55e)"],[]),N=d&&d.length>0?d:ie,H=N[0],B=a.useMemo(()=>Be(H),[H]),se=a.useMemo(()=>Ge(B.h,u,r),[B.h,u,r]),de=a.useCallback((Z,U,re,fe)=>{const ke=Ge(Z,U,re);let ye;for(fe&&Gt[fe]?ye=rt(ke,fe):ye=ke.map(je=>Se({h:je,s:B.s||.7,v:B.v||.85}));ye.length<_;)ye.push(ye[ye.length-1]||"var(--nice-text-secondary, #888888)");ye.length>S&&(ye=ye.slice(0,S)),f==null||f(ye)},[B.s,B.v,_,S,f]),he=a.useCallback(Z=>{if(!b){if(u==="custom"){const U=Se({h:Z,s:B.s||.7,v:B.v||.85}),re=[...N];re[s]=U,f==null||f(re);return}de(Z,u,r,p)}},[b,u,r,p,de,B.s,B.v,N,s,f]),be=a.useCallback(Z=>{b||(q(Z),Z!=="custom"&&de(B.h,Z,r,p))},[b,B.h,r,p,q,de]),ae=a.useCallback(Z=>{b||(F(Z),de(B.h,u,Z,p))},[b,B.h,u,p,F,de]),oe=a.useCallback(Z=>{if(b)return;G(Z);const U=Ge(B.h,u,r),re=rt(U,Z);f==null||f(re.slice(0,S))},[b,B.h,u,r,S,G,f]),ce=a.useCallback((Z,U)=>{if(b)return;const re=[...N];re[Z]=U,f==null||f(re)},[b,N,f]),me=a.useCallback(()=>{if(b||N.length>=S)return;const Z=Be(N[N.length-1]),U=Se({h:(Z.h+30)%360,s:Z.s,v:Z.v});f==null||f([...N,U])},[b,N,S,f]),le=a.useCallback(Z=>{if(b||N.length<=_)return;const U=N.filter((re,fe)=>fe!==Z);f==null||f(U),s>=U.length&&o(Math.max(0,U.length-1))},[b,N,_,f,s]),$=a.useCallback(()=>{if(b)return;const Z=Math.max(_,Math.min(S,kt(u).length)),U=Jt(u,Z,r);f==null||f(U)},[b,_,S,u,r,f]),D=a.useMemo(()=>{if(!L)return[];const Z=N[s]||N[0];return Xt(Be(Z),E)},[L,N,s,E]),Y=N[s]||N[0],pe=a.useMemo(()=>{const Z=Be(Y);return Se({h:(Z.h+180)%360,s:Z.s,v:Z.v})},[Y]);return T?null:e.jsxs("div",{ref:j,id:A,className:`nice-palette ${b?"nice-palette--disabled":""} ${t||""}`,style:i,children:[X&&e.jsx("div",{className:"nice-palette__label",children:X}),e.jsx("div",{className:"nice-palette__modes",children:An.map(Z=>e.jsx("button",{type:"button",className:`nice-palette__mode-btn ${u===Z?"nice-palette__mode-btn--active":""}`,onClick:()=>be(Z),disabled:b,title:Et[Z],children:Et[Z]},Z))}),e.jsxs("div",{className:"nice-palette__main",children:[W&&e.jsxs("div",{className:"nice-palette__wheel-container",children:[e.jsx(Rn,{hues:se,baseHue:B.h,onBaseHueChange:he,mode:u,distance:r,disabled:b}),(u==="analogous"||u==="split-complementary")&&e.jsxs("div",{className:"nice-palette__distance",children:[e.jsxs("label",{children:["Distance: ",r,"°"]}),e.jsx("input",{type:"range",min:10,max:90,value:r,onChange:Z=>ae(Number(Z.target.value)),disabled:b,className:"nice-palette__distance-slider"})]})]}),e.jsxs("div",{className:"nice-palette__strips",children:[e.jsxs("div",{className:"nice-palette__swatches",children:[N.map((Z,U)=>e.jsxs("div",{className:`nice-palette__swatch-wrapper ${s===U?"nice-palette__swatch-wrapper--selected":""}`,onClick:()=>o(U),children:[e.jsx("div",{className:"nice-palette__swatch",style:{background:Z},children:N.length>_&&e.jsx("button",{type:"button",className:"nice-palette__swatch-remove",onClick:re=>{re.stopPropagation(),le(U)},disabled:b,"aria-label":"Remove color",children:"×"})}),e.jsx("input",{type:"text",className:"nice-palette__hex-input",value:Z.toUpperCase(),maxLength:7,disabled:b,onChange:re=>ce(U,re.target.value)})]},U)),N.length<S&&e.jsx("button",{type:"button",className:"nice-palette__add-btn",onClick:me,disabled:b,title:"Add color",children:"+"})]}),e.jsxs("div",{className:"nice-palette__complementary",children:[e.jsx("span",{className:"nice-palette__section-tag",children:"Complementary"}),e.jsx("div",{className:"nice-palette__swatch nice-palette__swatch--sm",style:{background:pe},title:pe.toUpperCase()}),e.jsx("span",{className:"nice-palette__hex-label",children:pe.toUpperCase()})]}),L&&D.length>0&&e.jsxs("div",{className:"nice-palette__variations",children:[e.jsx("span",{className:"nice-palette__section-tag",children:"Tints & Shades"}),e.jsx("div",{className:"nice-palette__variation-strip",children:D.map((Z,U)=>e.jsx("div",{className:"nice-palette__variation-chip",style:{background:Z},title:Z.toUpperCase(),onClick:()=>{b||ce(s,Z)},role:"button",tabIndex:0},U))})]}),w&&e.jsx("button",{type:"button",className:"nice-btn nice-btn--outline nice-btn--sm nice-palette__random-btn",onClick:$,disabled:b,title:"Random palette","aria-label":"Random palette",children:"🎲 Random Palette"})]})]}),J&&h.length>0&&e.jsxs("div",{className:"nice-palette__presets",children:[e.jsx("div",{className:"nice-palette__section-title",children:"Style Presets"}),e.jsx("div",{className:"nice-palette__preset-grid",children:h.map(Z=>{const U=rt(se,Z);return e.jsxs("button",{type:"button",className:`nice-palette__preset-card ${p===Z?"nice-palette__preset-card--active":""}`,onClick:()=>oe(Z),disabled:b,children:[e.jsx("div",{className:"nice-palette__preset-strip",children:U.map((re,fe)=>e.jsx("span",{className:"nice-palette__preset-dot",style:{background:re}},fe))}),e.jsx("span",{className:"nice-palette__preset-label",children:Pn[Z]})]},Z)})})]}),Q&&e.jsxs("div",{className:"nice-palette__info-panel",children:[e.jsx("div",{className:"nice-palette__section-title",children:"Selected Color Info"}),e.jsx(Ln,{hex:Y})]}),ne&&e.jsxs("details",{className:"nice-palette__contrast-popup",style:{marginTop:8},children:[e.jsx("summary",{style:{cursor:"pointer",padding:"6px 10px",background:"var(--bg-secondary)",color:"var(--text-primary)",border:"1px solid var(--border-color)",borderRadius:4,display:"inline-block",fontSize:12,userSelect:"none"},children:"Contrast Analysis (WCAG 2.1)"}),e.jsx("div",{style:{marginTop:8},children:e.jsx(Dn,{colors:N})})]})]})});Zt.displayName="NiceColorPalette";function bt(){return{type:"linear",angle:90,stops:[{color:"var(--nice-primary, #3b82f6)",position:0},{color:"var(--nice-accent, #8b5cf6)",position:100}]}}function xt(n){const t=n.stops.slice().sort((l,d)=>l.position-d.position).map(l=>`${l.color} ${l.position}%`).join(", "),i=n.repeating?"repeating-":"";switch(n.type){case"linear":return`${i}linear-gradient(${n.angle}deg, ${t})`;case"radial":{const l=n.shape||"ellipse",d=n.size||"farthest-corner",f=n.positionX??50,_=n.positionY??50;return`${i}radial-gradient(${l} ${d} at ${f}% ${_}%, ${t})`}case"conic":{const l=n.angle??0,d=n.positionX??50,f=n.positionY??50;return`${i}conic-gradient(from ${l}deg at ${d}% ${f}%, ${t})`}}}function Qt(n){var l,d,f;const t=n.trim(),i=t.startsWith("repeating-");if(t.includes("linear-gradient")){const _=(l=t.match(/linear-gradient\((.+)\)/))==null?void 0:l[1];if(!_)return null;const S=_.split(",").map(g=>g.trim());let M=90,R=0;const K=S[0].match(/^(\d+)deg$/);K&&(M=parseInt(K[1]),R=1);const z=mt(S.slice(R));return{type:"linear",angle:M,repeating:i,stops:z}}if(t.includes("radial-gradient")){const _=(d=t.match(/radial-gradient\((.+)\)/))==null?void 0:d[1];if(!_)return null;const S=_.split(",").map(R=>R.trim()),M=mt(S.filter(R=>R.includes("#")||R.includes("rgb")));return{type:"radial",angle:0,repeating:i,stops:M.length>=2?M:bt().stops}}if(t.includes("conic-gradient")){const _=(f=t.match(/conic-gradient\((.+)\)/))==null?void 0:f[1];if(!_)return null;const S=_.split(",").map(R=>R.trim()),M=mt(S.filter(R=>R.includes("#")||R.includes("rgb")));return{type:"conic",angle:0,repeating:i,stops:M.length>=2?M:bt().stops}}return null}function mt(n){return n.map((t,i,l)=>{const d=t.match(/^(#[0-9a-fA-F]{3,8}|rgba?\([^)]+\))\s*(\d+%?)?$/);if(d){const f=d[2]?parseFloat(d[2]):i/Math.max(1,l.length-1)*100;return{color:d[1],position:f}}return{color:t,position:i/Math.max(1,l.length-1)*100}})}function In(){return"#"+Math.floor(Math.random()*16777215).toString(16).padStart(6,"0")}function zn(n=2){const t=["linear","radial","conic"],i=t[Math.floor(Math.random()*t.length)],l=[];for(let d=0;d<n;d++)l.push({color:In(),position:Math.round(d/(n-1)*100)});return{type:i,angle:Math.floor(Math.random()*360),stops:l,shape:i==="radial"?Math.random()>.5?"circle":"ellipse":void 0,positionX:i!=="linear"?Math.round(Math.random()*100):void 0,positionY:i!=="linear"?Math.round(Math.random()*100):void 0}}const Yt=[{name:"Sunset",value:{type:"linear",angle:135,stops:[{color:"var(--nice-danger, #ff6b6b)",position:0},{color:"#feca57",position:100}]}},{name:"Ocean",value:{type:"linear",angle:180,stops:[{color:"#667eea",position:0},{color:"#764ba2",position:100}]}},{name:"Forest",value:{type:"linear",angle:120,stops:[{color:"#11998e",position:0},{color:"#38ef7d",position:100}]}},{name:"Fire",value:{type:"linear",angle:90,stops:[{color:"#f12711",position:0},{color:"#f5af19",position:100}]}},{name:"Aurora",value:{type:"linear",angle:135,stops:[{color:"#a18cd1",position:0},{color:"#fbc2eb",position:50},{color:"#a6c1ee",position:100}]}},{name:"Midnight",value:{type:"linear",angle:180,stops:[{color:"#0f0c29",position:0},{color:"#302b63",position:50},{color:"#24243e",position:100}]}},{name:"Candy",value:{type:"linear",angle:45,stops:[{color:"#fc5c7d",position:0},{color:"#6a82fb",position:100}]}},{name:"Radial Glow",value:{type:"radial",angle:0,shape:"circle",stops:[{color:"var(--nice-warning-bg, #ffecd2)",position:0},{color:"#fcb69f",position:100}],positionX:50,positionY:50}},{name:"Rainbow",value:{type:"conic",angle:0,stops:[{color:"var(--nice-danger, #ff0000)",position:0},{color:"#ff8800",position:17},{color:"var(--nice-warning, #ffff00)",position:33},{color:"var(--nice-success, #00ff00)",position:50},{color:"#0088ff",position:67},{color:"#8800ff",position:83},{color:"var(--nice-danger, #ff0000)",position:100}],positionX:50,positionY:50}}],en=a.forwardRef(({id:n,className:t,style:i,accessMode:l,value:d,onChange:f,showCssOutput:_=!0,showPresets:S=!0,showEditor:M=!0,showRandom:R=!0,maxStops:K=10,label:z,disabled:g,width:C},W)=>{const ne=I.ml(l,n),Q=ne==="hidden";(ne==="disabled"||ne==="readOnly")&&(g=!0);const J=I.Xs(n),h=d??bt(),L=a.useMemo(()=>xt(h),[h]),[w,E]=a.useState(0),[X,b]=a.useState(""),j=a.useRef(null),x=a.useCallback(r=>{f==null||f(r)},[f]),T=a.useCallback(r=>{g||x({...h,type:r})},[g,h,x]),A=a.useCallback(r=>{g||x({...h,angle:r})},[g,h,x]),O=a.useCallback(r=>{g||x({...h,repeating:r})},[g,h,x]),v=a.useCallback(r=>{g||x({...h,shape:r})},[g,h,x]),c=a.useCallback((r,p)=>{if(g)return;const q=h.stops.map((F,G)=>G===r?{...F,...p}:F);x({...h,stops:q})},[g,h,x]),P=a.useCallback(()=>{if(g||h.stops.length>=K)return;const r=h.stops.slice().sort((ie,N)=>ie.position-N.position);let p=0,q=r[0];for(let ie=0;ie<r.length-1;ie++){const N=r[ie+1].position-r[ie].position;N>p&&(p=N,q=r[ie])}const F=Math.round(q.position+p/2),G="#"+Math.floor(Math.random()*16777215).toString(16).padStart(6,"0");x({...h,stops:[...h.stops,{color:G,position:F}]})},[g,h,K,x]),y=a.useCallback(r=>{if(g||h.stops.length<=2)return;const p=h.stops.filter((q,F)=>F!==r);x({...h,stops:p}),w>=p.length&&E(p.length-1)},[g,h,w,x]),k=a.useCallback(()=>{if(g)return;const r=2+Math.floor(Math.random()*3);x(zn(r))},[g,x]),s=a.useCallback(()=>{if(g||!X.trim())return;const r=Qt(X);r&&x(r)},[g,X,x]),o=a.useCallback(r=>{if(g||!j.current||h.stops.length>=K)return;const p=j.current.getBoundingClientRect(),q=Math.round((r.clientX-p.left)/p.width*100),F="#"+Math.floor(Math.random()*16777215).toString(16).padStart(6,"0"),G=[...h.stops,{color:F,position:q}];x({...h,stops:G}),E(G.length-1)},[g,h,K,x]),u=a.useMemo(()=>h.stops.slice().sort((r,p)=>r.position-p.position),[h.stops]);return Q?null:e.jsxs("div",{ref:W,id:J,className:`nice-gradient ${g?"nice-gradient--disabled":""} ${t||""}`,style:{width:C!=null?typeof C=="number"?`${C}px`:C:320,boxSizing:"border-box",...i},children:[z&&e.jsx("div",{className:"nice-gradient__label",children:z}),e.jsx("div",{className:"nice-gradient__preview",style:{background:L}}),M&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"nice-gradient__type-row",children:[["linear","radial","conic"].map(r=>e.jsx("button",{type:"button",className:`nice-gradient__type-btn ${h.type===r?"nice-gradient__type-btn--active":""}`,onClick:()=>T(r),disabled:g,children:r.charAt(0).toUpperCase()+r.slice(1)},r)),e.jsxs("label",{className:"nice-gradient__repeat-label",children:[e.jsx("input",{type:"checkbox",checked:h.repeating??!1,onChange:r=>O(r.target.checked),disabled:g}),"Repeating"]})]}),e.jsxs("div",{className:"nice-gradient__controls",children:[h.type==="linear"&&e.jsxs("div",{className:"nice-gradient__control-group",children:[e.jsxs("label",{children:["Angle: ",h.angle,"°"]}),e.jsx("input",{type:"range",min:0,max:360,value:h.angle,onChange:r=>A(Number(r.target.value)),disabled:g,className:"nice-gradient__slider"}),e.jsx("div",{className:"nice-gradient__angle-presets",children:[0,45,90,135,180,225,270,315].map(r=>e.jsx("button",{type:"button",className:`nice-gradient__angle-btn ${h.angle===r?"nice-gradient__angle-btn--active":""}`,onClick:()=>A(r),disabled:g,title:`${r}°`,children:e.jsx("span",{style:{transform:`rotate(${r}deg)`,display:"inline-block"},children:"→"})},r))})]}),h.type==="radial"&&e.jsxs("div",{className:"nice-gradient__control-group",children:[e.jsx("label",{children:"Shape:"}),e.jsx("div",{className:"nice-gradient__shape-btns",children:["circle","ellipse"].map(r=>e.jsx("button",{type:"button",className:`nice-gradient__shape-btn ${(h.shape||"ellipse")===r?"nice-gradient__shape-btn--active":""}`,onClick:()=>v(r),disabled:g,children:r},r))})]}),(h.type==="radial"||h.type==="conic")&&e.jsxs("div",{className:"nice-gradient__control-group",children:[e.jsxs("label",{children:["Center: ",h.positionX??50,"%, ",h.positionY??50,"%"]}),e.jsxs("div",{className:"nice-gradient__center-inputs",children:[e.jsx("input",{type:"range",min:0,max:100,value:h.positionX??50,onChange:r=>x({...h,positionX:Number(r.target.value)}),disabled:g,className:"nice-gradient__slider"}),e.jsx("input",{type:"range",min:0,max:100,value:h.positionY??50,onChange:r=>x({...h,positionY:Number(r.target.value)}),disabled:g,className:"nice-gradient__slider"})]})]}),h.type==="conic"&&e.jsxs("div",{className:"nice-gradient__control-group",children:[e.jsxs("label",{children:["Start angle: ",h.angle,"°"]}),e.jsx("input",{type:"range",min:0,max:360,value:h.angle,onChange:r=>A(Number(r.target.value)),disabled:g,className:"nice-gradient__slider"})]})]}),e.jsxs("div",{className:"nice-gradient__bar-container",children:[e.jsx("div",{ref:j,className:"nice-gradient__bar",style:{background:L},onClick:o,children:h.stops.map((r,p)=>e.jsx("div",{className:`nice-gradient__stop-marker ${w===p?"nice-gradient__stop-marker--active":""}`,style:{left:`${r.position}%`},onClick:q=>{q.stopPropagation(),E(p)},title:`${r.color} @ ${r.position}%`,children:e.jsx("div",{className:"nice-gradient__stop-dot",style:{background:r.color}})},p))}),e.jsx("button",{type:"button",className:"nice-gradient__add-stop",onClick:P,disabled:g||h.stops.length>=K,title:"Add stop",children:"+"})]}),e.jsx("div",{className:"nice-gradient__stop-editor",children:e.jsx("div",{className:"nice-gradient__stop-list",children:u.map((r,p)=>{const q=h.stops.indexOf(r);return e.jsxs("div",{className:`nice-gradient__stop-row ${w===q?"nice-gradient__stop-row--active":""}`,onClick:()=>E(q),children:[e.jsx("input",{type:"color",value:r.color,onChange:F=>c(q,{color:F.target.value}),disabled:g,className:"nice-gradient__stop-color"}),e.jsx("input",{type:"text",value:r.color.toUpperCase(),maxLength:7,onChange:F=>c(q,{color:F.target.value}),disabled:g,className:"nice-gradient__stop-hex"}),e.jsx("input",{type:"number",min:0,max:100,value:r.position,onChange:F=>c(q,{position:Number(F.target.value)}),disabled:g,className:"nice-gradient__stop-pos"}),e.jsx("span",{className:"nice-gradient__stop-pct",children:"%"}),h.stops.length>2&&e.jsx("button",{type:"button",className:"nice-gradient__stop-del",onClick:()=>y(q),disabled:g,"aria-label":"Remove stop",children:"×"})]},q)})})})]}),R&&e.jsx("button",{type:"button",className:"nice-btn nice-btn--outline nice-btn--sm nice-gradient__random-btn",onClick:k,disabled:g,title:"Random gradient","aria-label":"Random gradient",children:"🎲 Random Gradient"}),S&&e.jsxs("div",{className:"nice-gradient__presets",children:[e.jsx("div",{className:"nice-gradient__section-title",children:"Presets"}),e.jsx("div",{className:"nice-gradient__preset-grid",children:Yt.map((r,p)=>e.jsxs("button",{type:"button",className:"nice-gradient__preset-card",onClick:()=>{g||x(r.value)},disabled:g,title:r.name,children:[e.jsx("div",{className:"nice-gradient__preset-preview",style:{background:xt(r.value)}}),e.jsx("span",{className:"nice-gradient__preset-name",children:r.name})]},p))})]}),_&&e.jsxs("div",{className:"nice-gradient__css",children:[e.jsx("div",{className:"nice-gradient__section-title",children:"CSS Output"}),e.jsxs("div",{className:"nice-gradient__css-output",children:[e.jsx("code",{children:`background: ${L};`}),e.jsx("button",{type:"button",className:"nice-gradient__copy-btn",onClick:()=>{var r;return(r=navigator.clipboard)==null?void 0:r.writeText(`background: ${L};`)},title:"Copy CSS",children:"📋"})]}),e.jsxs("div",{className:"nice-gradient__css-import",children:[e.jsx("input",{type:"text",className:"nice-gradient__css-input",placeholder:"Paste CSS gradient to import...",value:X,onChange:r=>b(r.target.value),disabled:g}),e.jsx("button",{type:"button",className:"nice-btn nice-btn--outline nice-btn--sm",onClick:s,disabled:g,children:"Import"})]})]})]})});en.displayName="NiceGradientPicker";const Hn=({options:n,value:t,onChange:i,searchable:l=!0,clearable:d,loading:f,placeholder:_,label:S,error:M,helperText:R,required:K,disabled:z,size:g="md",id:C,className:W,style:ne,data:Q,columns:J,valueField:h="id",displayField:L,dropdownWidth:w,controlWidth:E})=>{var u;const X=I.Xs(C),{t:b}=I.ue(),[j,x]=a.useState(!1),[T,A]=a.useState(""),O=a.useRef(null);I.Js(O,()=>x(!1));const v=!!(Q&&J&&J.length>0),c=L??(J&&((u=J[0])==null?void 0:u.key)),P=a.useMemo(()=>!v||!Q?[]:Q.map(r=>({value:String(r[h]??""),label:c?String(r[c]??""):""})),[v,Q,h,c]),y=v?P:n??[],k=y.find(r=>String(r.value)===t),s=a.useMemo(()=>{if(!v||!Q)return[];if(!T)return Q;const r=T.toLowerCase();return Q.filter(p=>J.some(q=>String(p[q.key]??"").toLowerCase().includes(r)))},[v,Q,J,T]),o=a.useMemo(()=>{if(v||!T)return y;const r=T.toLowerCase();return y.filter(p=>p.label.toLowerCase().includes(r))},[y,T,v]);return e.jsxs("div",{className:`nice-field nice-field--${g} ${M?"nice-field--error":""} ${W||""}`,style:{width:E!=null?typeof E=="number"?`${E}px`:E:"fit-content",...ne},ref:O,children:[S&&e.jsxs("label",{className:"nice-field__label",htmlFor:X,children:[S,K&&e.jsx("span",{className:"nice-field__required",children:"*"})]}),e.jsxs("div",{className:"nice-field__input-wrap",style:{position:"relative"},children:[e.jsxs("button",{type:"button",id:X,className:"nice-select__trigger",onClick:()=>!z&&x(!j),disabled:z,children:[e.jsx("span",{children:(k==null?void 0:k.label)||_||b("controls.select","Select...")}),e.jsx("span",{className:"nice-select__arrow",children:"▾"})]}),d&&t&&!z&&e.jsx("button",{type:"button",className:"nice-field__clear",onClick:()=>i(""),"aria-label":b("controls.clear","Clear"),children:"✕"}),j&&e.jsxs("div",{className:"nice-dropdown nice-lookup__dropdown",style:{position:"absolute",top:"100%",left:0,zIndex:50,marginTop:4,background:"var(--bg-primary)",border:"1px solid var(--border-color)",borderRadius:"var(--nice-radius-md)",boxShadow:"0 4px 16px var(--nice-overlay-15, rgba(0, 0, 0, 0.15))",minWidth:"100%",width:w!=null?typeof w=="number"?`${w}px`:w:v?"max-content":"100%"},children:[l&&e.jsx("div",{className:"nice-dropdown__search",style:{padding:6},children:e.jsx("input",{type:"text",value:T,onChange:r=>A(r.target.value),placeholder:b("controls.search","Search..."),autoFocus:!0,style:{width:"100%",padding:"4px 8px",border:"1px solid var(--border-color)",borderRadius:4,background:"var(--bg-primary)",color:"var(--text-primary)"}})}),v?e.jsxs("table",{className:"nice-lookup__grid",role:"listbox",style:{width:"100%",borderCollapse:"collapse",color:"var(--text-primary)"},children:[e.jsx("thead",{children:e.jsx("tr",{children:J.map(r=>e.jsx("th",{style:{padding:"6px 10px",textAlign:"left",fontSize:12,fontWeight:600,color:"var(--text-secondary)",background:"var(--bg-secondary)",borderBottom:"1px solid var(--border-color)",width:r.width!=null?typeof r.width=="number"?`${r.width}px`:r.width:void 0},children:r.header},r.key))})}),e.jsx("tbody",{children:s.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:J.length,style:{padding:12,textAlign:"center",color:"var(--text-muted)"},children:b("controls.noResults","No results")})}):s.map(r=>{const p=String(r[h]??""),q=p===t;return e.jsx("tr",{role:"option","aria-selected":q,onClick:()=>{i(p),x(!1),A("")},style:{cursor:"pointer",background:q?"var(--hover-bg)":"transparent"},onMouseEnter:F=>{q||(F.currentTarget.style.background="var(--hover-bg)")},onMouseLeave:F=>{q||(F.currentTarget.style.background="transparent")},children:J.map(F=>e.jsx("td",{style:{padding:"6px 10px",fontSize:13,borderBottom:"1px solid var(--border-color)"},children:String(r[F.key]??"")},F.key))},p)})})]}):e.jsx("ul",{className:"nice-dropdown__list",role:"listbox",style:{listStyle:"none",margin:0,padding:4,maxHeight:240,overflowY:"auto"},children:o.length===0?e.jsx("li",{className:"nice-dropdown__empty",style:{padding:8,color:"var(--text-muted)"},children:b("controls.noResults","No results")}):o.map(r=>e.jsx("li",{role:"option",className:`nice-dropdown__option ${String(r.value)===t?"nice-dropdown__option--selected":""}`,onClick:()=>{i(String(r.value)),x(!1),A("")},"aria-selected":String(r.value)===t,children:r.label},String(r.value)))})]})]}),M&&e.jsx("div",{className:"nice-field__error",children:M}),R&&!M&&e.jsx("div",{className:"nice-field__hint",children:R})]})},On=["Su","Mo","Tu","We","Th","Fr","Sa"];function Wn(n,t){return new Date(n,t+1,0).getDate()}function Fn(n,t){return new Date(n,t,1).getDay()}function Tt(n,t,i){return`${n}-${String(t+1).padStart(2,"0")}-${String(i).padStart(2,"0")}`}function Kn(n){const t=new Date(Date.UTC(n.getFullYear(),n.getMonth(),n.getDate()));t.setUTCDate(t.getUTCDate()+4-(t.getUTCDay()||7));const i=new Date(Date.UTC(t.getUTCFullYear(),0,1));return Math.ceil(((t.getTime()-i.getTime())/864e5+1)/7)}const Rt=["January","February","March","April","May","June","July","August","September","October","November","December"],tn=({value:n,onChange:t,min:i,max:l,disabledDates:d=[],firstDayOfWeek:f=1,size:_="md",showWeekNumbers:S,onMonthChange:M,className:R,style:K,accessMode:z,id:g,multiple:C,selectedDates:W=[],onSelectedDatesChange:ne,renderDay:Q,showKeyboardHints:J,persistPreferences:h=!1,fullWidth:L=!1,cookies:w=!1,localStorage:E=!0,sessionStorage:X=!1,storageMode:b,storageKey:j})=>{const x=I.ml(z,g),T=x==="hidden",A=x==="disabled"||x==="readOnly",{t:O}=I.ue(),v=new Date,c=n?new Date(n):v,P=I.da(j??"nice-calendar"),y=a.useMemo(()=>h?P.get("prefs")??{}:{},[h,P]),k=y.firstDayOfWeek??f,[s,o]=a.useState(y.lastViewYear??c.getFullYear()),[u,r]=a.useState(y.lastViewMonth??c.getMonth()),[p,q]=a.useState(y.preferredView??"days"),F=a.useCallback(U=>{if(!h)return;const re=P.get("prefs")??{};P.set("prefs",{...re,...U})},[h,P]),G=a.useCallback(U=>{q(U),F({preferredView:U})},[F]),ie=a.useCallback((U,re)=>{F({lastViewYear:U,lastViewMonth:re})},[F]),N=a.useMemo(()=>[I.Ml.moveUp,I.Ml.moveDown,I.Ml.moveLeft,I.Ml.moveRight,{key:"Enter",description:O("shortcuts.selectDate","Select date")},I.Ml.pageUp,I.Ml.pageDown],[O]),H=a.useMemo(()=>Wn(s,u),[s,u]),B=a.useMemo(()=>(Fn(s,u)-k+7)%7,[s,u,k]),se=a.useMemo(()=>{const U=[...On];for(let re=0;re<k;re++)U.push(U.shift());return U},[k]),de=a.useCallback(U=>i&&U<i||l&&U>l?!0:d.includes(U),[i,l,d]),he=a.useCallback(U=>{if(p==="years"){o(ke=>ke+U*10);return}if(p==="months"){o(ke=>ke+U);return}let re=u+U,fe=s;re<0&&(re=11,fe--),re>11&&(re=0,fe++),r(re),o(fe),ie(fe,re),M==null||M(fe,re)},[u,s,M,p,ie]),be=Tt(v.getFullYear(),v.getMonth(),v.getDate()),ae=a.useCallback(U=>C?W.includes(U):U===n,[C,W,n]),oe=a.useCallback(U=>{if(!A){if(C){const re=W.includes(U)?W.filter(fe=>fe!==U):[...W,U];ne==null||ne(re)}t==null||t(U)}},[C,W,t,ne]),ce=a.useCallback(()=>{p==="days"?G("months"):p==="months"&&G("years")},[p,G]),me=a.useCallback(U=>{r(U),G("days"),ie(s,U),M==null||M(s,U)},[s,M,G,ie]),le=a.useCallback(U=>{o(U),G("months")},[G]),$=p==="years"?`${s-s%10} – ${s-s%10+9}`:p==="months"?`${s}`:`${Rt[u]} ${s}`,D=p==="years"?"decade":p==="months"?"year":"month",Y=[];for(let U=0;U<B;U++)Y.push(null);for(let U=1;U<=H;U++)Y.push(U);for(;Y.length%7!==0;)Y.push(null);const pe=[];for(let U=0;U<Y.length;U+=7)pe.push(Y.slice(U,U+7));const Z=s-s%10;return T?null:e.jsxs("div",{className:`nice-calendar nice-calendar--${_}${L?" nice-calendar--full-width":""} ${R||""}`,style:K,children:[e.jsxs("div",{className:"nice-calendar__header",children:[e.jsx("button",{type:"button",className:"nice-calendar__nav",onClick:()=>he(-1),"aria-label":`Previous ${D}`,children:"‹"}),e.jsx("button",{type:"button",className:"nice-calendar__title",onClick:ce,"aria-label":p==="days"?"Show month picker":p==="months"?"Show year picker":void 0,disabled:p==="years",children:$}),e.jsx("button",{type:"button",className:"nice-calendar__nav",onClick:()=>he(1),"aria-label":`Next ${D}`,children:"›"}),J&&e.jsx(I.Tr,{shortcuts:N,size:"sm"})]}),p==="days"&&e.jsxs("table",{className:"nice-calendar__grid",role:"grid",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[S&&e.jsx("th",{className:"nice-calendar__wk",children:"W"}),se.map(U=>e.jsx("th",{children:U},U))]})}),e.jsx("tbody",{children:pe.map((U,re)=>e.jsxs("tr",{children:[S&&e.jsx("td",{className:"nice-calendar__wk",children:U.find(fe=>fe!=null)?Kn(new Date(s,u,U.find(fe=>fe!=null))):""}),U.map((fe,ke)=>{if(fe==null)return e.jsx("td",{className:"nice-calendar__empty-cell"},ke);const ye=Tt(s,u,fe),je=de(ye),ze=ae(ye);return e.jsx("td",{className:`nice-calendar__day${ze?" nice-calendar__day--selected":""}${ye===be?" nice-calendar__day--today":""}${je?" nice-calendar__day--disabled":""}`,onClick:()=>!je&&oe(ye),role:"gridcell","aria-selected":ze,"aria-disabled":je,children:Q?Q(ye,fe):fe},ke)})]},re))})]}),p==="months"&&e.jsx("div",{className:"nice-calendar__picker-grid",children:Rt.map((U,re)=>e.jsx("button",{type:"button",className:`nice-calendar__picker-cell${re===u&&s===c.getFullYear()?" nice-calendar__picker-cell--selected":""}`,onClick:()=>me(re),children:U.slice(0,3)},re))}),p==="years"&&e.jsx("div",{className:"nice-calendar__picker-grid",children:Array.from({length:12},(U,re)=>Z-1+re).map(U=>e.jsx("button",{type:"button",className:`nice-calendar__picker-cell${U===s?" nice-calendar__picker-cell--selected":""}${U<Z||U>Z+9?" nice-calendar__picker-cell--other":""}`,onClick:()=>le(U),children:U},U))})]})};tn.displayName="NiceCalendar";const Un=({startDate:n,endDate:t,onStartChange:i,onEndChange:l,min:d,max:f,clearable:_,startPlaceholder:S,endPlaceholder:M,startLabel:R,endLabel:K,layout:z="horizontal",separator:g="–",gap:C=12,fullWidth:W=!1,label:ne,error:Q,helperText:J,required:h,disabled:L,size:w="md",id:E,className:X,style:b,accessMode:j,showKeyboardHints:x,labelPlacement:T,errorPlacement:A,labelWidth:O,controlWidth:v,loading:c})=>{const P=I.ml(j,E),y=I.Xs(E),{t:k}=I.ue(),s=P==="disabled"||P==="readOnly"||!!L,o=a.useMemo(()=>[{key:"Tab",description:k("shortcuts.switchField","Switch between start/end")},I.Ml.cancel],[k]);if(P==="hidden")return null;const u=p=>{i(p),p&&t&&p>t&&l(p)},r=z==="horizontal";return e.jsxs("div",{className:`nice-field nice-field--${w} nice-daterange nice-daterange--${z} ${T==="left"?"nice-field--label-left":""} ${Q?"nice-field--error":""} ${c?"nice-field--loading":""} ${X||""}`,style:{...b,...O!=null&&{"--nice-field-label-width":typeof O=="number"?`${O}px`:O},...v!=null&&{"--nice-field-control-width":typeof v=="number"?`${v}px`:v}},"aria-busy":c||void 0,children:[ne&&e.jsxs("label",{className:"nice-field__label",htmlFor:y,children:[ne,h&&e.jsx("span",{className:"nice-field__required",children:"*"}),x&&e.jsx(I.Tr,{shortcuts:o,size:"sm"})]}),e.jsxs("div",{className:"nice-field__control",children:[e.jsxs("div",{className:"nice-daterange__row",style:{display:"flex",flexDirection:r?"row":"column",alignItems:r?"flex-end":"stretch",gap:C,flexWrap:"wrap"},children:[e.jsx("div",{style:{flex:W?"1 1 0":void 0,minWidth:0},children:e.jsx(I.gn,{id:y,label:R,value:n,onChange:u,min:d,max:t||f,placeholder:S||k("controls.startDate","Start date"),disabled:s,size:w,clearable:_,labelPlacement:T,labelWidth:O})}),r&&g!==""&&g!=null&&e.jsx("span",{className:"nice-daterange__separator",style:{paddingBottom:8,color:"var(--text-secondary, #666)"},"aria-hidden":"true",children:g}),e.jsx("div",{style:{flex:W?"1 1 0":void 0,minWidth:0},children:e.jsx(I.gn,{label:K,value:t,onChange:l,min:n||d,max:f,placeholder:M||k("controls.endDate","End date"),disabled:s,size:w,clearable:_,labelPlacement:T,labelWidth:O})})]}),c&&e.jsx("span",{className:"nice-field__spinner",children:e.jsx("span",{className:"nice-spinner nice-spinner--sm"})}),A==="right"&&Q&&e.jsx("div",{className:"nice-field__error",role:"alert",children:Q}),A==="right"&&!Q&&J&&e.jsx("div",{className:"nice-field__helper",children:J})]}),A!=="right"&&Q&&e.jsx("div",{className:"nice-field__error",children:Q}),A!=="right"&&!Q&&J&&e.jsx("div",{className:"nice-field__hint",children:J})]})},qn=({min:n=0,max:t=100,step:i=1,startValue:l,endValue:d,onChange:f,showLabels:_=!0,formatLabel:S,valuePlacement:M="none",label:R,error:K,helperText:z,required:g,disabled:C,readOnly:W,loading:ne,size:Q="md",id:J,className:h,style:L,accessMode:w,showKeyboardHints:E,labelPlacement:X,errorPlacement:b,labelWidth:j,controlWidth:x})=>{const T=I.ml(w,J),A=T==="hidden";(T==="disabled"||T==="readOnly")&&(C=!0);const{t:O}=I.ue(),v=I.Xs(J),c=a.useRef(null),P=a.useMemo(()=>[I.Ml.increment,I.Ml.decrement,I.Ml.first,I.Ml.last,{key:"Tab",description:O("shortcuts.switchThumb","Switch thumb")}],[O]),y=u=>(u-n)/(t-n)*100,k=u=>S?S(u):String(u),s=u=>{const r=Math.round(u/i)*i;return Math.max(n,Math.min(t,r))},o=a.useCallback((u,r)=>{u.preventDefault();const p=c.current;if(!p||C)return;const q=G=>{const ie=p.getBoundingClientRect(),N=Math.max(0,Math.min(1,(G.clientX-ie.left)/ie.width)),H=s(n+N*(t-n));r==="start"?f(Math.min(H,d),d):f(l,Math.max(H,l))},F=()=>{document.removeEventListener("pointermove",q),document.removeEventListener("pointerup",F)};document.addEventListener("pointermove",q),document.addEventListener("pointerup",F)},[n,t,i,l,d,f,C]);return A?null:e.jsxs("div",{className:`nice-field nice-field--${Q} nice-field--rangeslider ${X==="left"?"nice-field--label-left":""} ${b==="right"?"nice-field--error-right":""} ${K?"nice-field--error":""} ${ne?"nice-field--loading":""} ${h||""}`,style:{...L,...j!=null&&{"--nice-field-label-width":typeof j=="number"?`${j}px`:j},...x!=null&&{"--nice-field-control-width":typeof x=="number"?`${x}px`:x}},"aria-busy":ne||void 0,children:[R&&e.jsxs("label",{className:"nice-field__label nice-field__label--with-value",htmlFor:v,children:[e.jsxs("span",{className:"nice-field__label-text",children:[R,g&&e.jsx("span",{className:"nice-field__required",children:"*"}),E&&e.jsx(I.Tr,{shortcuts:P,size:"sm"})]}),M==="right"&&e.jsxs("span",{className:"nice-range-slider__value nice-range-slider__value--inline",children:[k(l)," – ",k(d)]})]}),e.jsxs("div",{className:"nice-field__control",children:[M==="right"&&!R&&e.jsxs("span",{className:"nice-range-slider__value",children:[k(l)," – ",k(d)]}),e.jsxs("div",{className:"nice-range-slider__stack",children:[e.jsxs("div",{className:`nice-range-slider ${_?"nice-range-slider--with-labels":""} ${R?"nice-range-slider--has-field-label":""}`,ref:c,children:[e.jsx("div",{className:"nice-range-slider__track",children:e.jsx("div",{className:"nice-range-slider__fill",style:{left:`${y(l)}%`,width:`${y(d)-y(l)}%`}})}),e.jsx("div",{className:"nice-range-slider__thumb",style:{left:`${y(l)}%`},onPointerDown:u=>W?void 0:o(u,"start"),role:"slider","aria-valuemin":n,"aria-valuemax":d,"aria-valuenow":l,tabIndex:C?-1:0,id:v}),e.jsx("div",{className:"nice-range-slider__thumb",style:{left:`${y(d)}%`},onPointerDown:u=>W?void 0:o(u,"end"),role:"slider","aria-valuemin":l,"aria-valuemax":t,"aria-valuenow":d,tabIndex:C?-1:0})]}),_&&e.jsxs("div",{className:"nice-range-slider__values",children:[e.jsx("span",{className:"nice-range-slider__values-start",style:{left:`${y(l)}%`},children:k(l)}),e.jsx("span",{className:"nice-range-slider__values-end",style:{left:`${y(d)}%`},children:k(d)})]}),M==="bottom"&&e.jsxs("div",{className:"nice-range-slider__value nice-range-slider__value--bottom",children:[k(l)," – ",k(d)]})]}),ne&&e.jsx("span",{className:"nice-field__spinner",children:e.jsx("span",{className:"nice-spinner nice-spinner--sm"})}),b==="right"&&K&&e.jsx("div",{className:"nice-field__error",role:"alert",children:K}),b==="right"&&!K&&z&&e.jsx("div",{className:"nice-field__helper",children:z})]}),b!=="right"&&K&&e.jsx("div",{className:"nice-field__error",role:"alert",children:K}),b!=="right"&&!K&&z&&e.jsx("div",{className:"nice-field__helper",children:z})]})},Vn=({displayValue:n,placeholder:t,clearable:i,children:l,onClear:d,open:f,onOpenChange:_,dropdownWidth:S,label:M,error:R,helperText:K,required:z,disabled:g,size:C="md",id:W,className:ne,style:Q,accessMode:J,showKeyboardHints:h,displayStyle:L})=>{I.Ls("input",L),I.Rs("input",L);const w=I.ml(J,W),E=w==="hidden";(w==="disabled"||w==="readOnly")&&(g=!0);const X=I.Xs(W),{t:b}=I.ue(),[j,x]=a.useState(!1),T=a.useRef(null),A=f??j,O=a.useMemo(()=>[{key:"Enter",description:b("shortcuts.openDropdown","Open dropdown")},I.Ml.cancel],[b]),v=c=>{_?_(c):x(c)};return I.Js(T,()=>v(!1)),E?null:e.jsxs("div",{className:`nice-field nice-field--${C} ${R?"nice-field--error":""} ${ne||""}`,style:Q,ref:T,children:[M&&e.jsxs("label",{className:"nice-field__label",htmlFor:X,children:[M,z&&e.jsx("span",{className:"nice-field__required",children:"*"}),h&&e.jsx(I.Tr,{shortcuts:O,size:"sm"})]}),e.jsxs("div",{className:"nice-field__input-wrap",children:[e.jsxs("button",{type:"button",id:X,className:"nice-select__trigger",onClick:()=>!g&&v(!A),disabled:g,children:[e.jsx("span",{children:n||t||b("controls.select","Select...")}),e.jsx("span",{className:"nice-select__arrow",children:"▾"})]}),i&&n&&!g&&e.jsx("button",{type:"button",className:"nice-field__clear",onClick:()=>d==null?void 0:d(),"aria-label":b("controls.clear","Clear"),children:"✕"})]}),A&&e.jsx("div",{className:"nice-dropdown",style:{width:S},children:l}),R&&e.jsx("div",{className:"nice-field__error",children:R}),K&&!R&&e.jsx("div",{className:"nice-field__hint",children:K})]})};function Dt(n){const t=n.trim().toLowerCase();return t.startsWith("http://")||t.startsWith("https://")||t.startsWith("/")||t.startsWith("./")||t.startsWith("../")?!0:!(t.startsWith("javascript:")||t.startsWith("vbscript:")||t.startsWith("data:text"))}const Bn=["bold","italic","underline","strikethrough","h1","h2","h3","ul","ol","blockquote","hr","link","unlink","image","table","code","alignLeft","alignCenter","alignRight","fontSize","fontColor","undo","redo","clear","findReplace","emoji","source","fullscreen","markdown"],Ne=({d:n,viewBox:t="0 0 24 24"})=>e.jsx("svg",{width:"16",height:"16",viewBox:t,fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:e.jsx("path",{d:n})}),Xn={bold:e.jsx("strong",{style:{fontFamily:"serif"},children:"B"}),italic:e.jsx("em",{style:{fontFamily:"serif"},children:"I"}),underline:e.jsx("span",{style:{textDecoration:"underline"},children:"U"}),strikethrough:e.jsx("span",{style:{textDecoration:"line-through"},children:"S"}),h1:"H1",h2:"H2",h3:"H3",ul:e.jsx(Ne,{d:"M8 6h13M8 12h13M8 18h13M3 6h.01M3 12h.01M3 18h.01"}),ol:e.jsx(Ne,{d:"M10 6h11M10 12h11M10 18h11M4 6h1v4M4 10h2M6 18H4c0-1 2-2 2-3s-1-1.5-2-1"}),link:e.jsx(Ne,{d:"M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"}),unlink:e.jsx(Ne,{d:"M18.84 12.25l1.72-1.71a5 5 0 0 0-7.07-7.07L11 5.78M3 3l18 18M9 15l3-3M14 11l3 3M14 21l-1.72-1.72a5 5 0 0 1-7.07-7.07L7 10.49"}),undo:e.jsx(Ne,{d:"M3 7v6h6M3 13a9 9 0 1 0 3-7.7L3 13"}),redo:e.jsx(Ne,{d:"M21 7v6h-6M21 13a9 9 0 1 1-3-7.7L21 13"}),clear:e.jsx(Ne,{d:"M3 6h18M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"}),table:e.jsx(Ne,{d:"M3 3h18v18H3zM3 9h18M3 15h18M9 3v18M15 3v18"}),image:e.jsx(Ne,{d:"M3 3h18v18H3zM3 16l5-5 4 4 3-3 6 6M9 9a2 2 0 1 1-4 0 2 2 0 0 1 4 0z"}),code:e.jsx(Ne,{d:"M16 18l6-6-6-6M8 6l-6 6 6 6"}),markdown:"MD",blockquote:e.jsx(Ne,{d:"M3 21c3-3 3-9 0-12M21 21c-3-3-3-9 0-12M9 7h6v6H9zM15 7h6v6h-6z"}),hr:e.jsx(Ne,{d:"M5 12h14"}),subscript:"X₂",superscript:"X²",indent:e.jsx(Ne,{d:"M3 8l4 4-4 4M7 6h14M7 12h14M3 18h18"}),outdent:e.jsx(Ne,{d:"M7 8l-4 4 4 4M21 6H3M21 12H7M21 18H3"}),alignLeft:e.jsx(Ne,{d:"M3 6h18M3 12h12M3 18h18"}),alignCenter:e.jsx(Ne,{d:"M3 6h18M6 12h12M3 18h18"}),alignRight:e.jsx(Ne,{d:"M3 6h18M9 12h12M3 18h18"}),alignJustify:e.jsx(Ne,{d:"M3 6h18M3 12h18M3 18h18"}),fullscreen:e.jsx(Ne,{d:"M3 9V3h6M21 9V3h-6M3 15v6h6M21 15v6h-6"}),removeFormat:e.jsx(Ne,{d:"M4 7V4h16v3M5 20h6M13 4 8 20"}),print:e.jsx(Ne,{d:"M6 9V2h12v7M6 18H4a2 2 0 0 1-2-2v-5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2v5a2 2 0 0 1-2 2h-2M6 14h12v8H6z"}),source:e.jsx(Ne,{d:"M16 18l6-6-6-6M8 6l-6 6 6 6"}),emoji:e.jsx(Ne,{d:"M12 22a10 10 0 1 1 0-20 10 10 0 0 1 0 20zM8 14s1.5 2 4 2 4-2 4-2M9 9h.01M15 9h.01"}),findReplace:e.jsx(Ne,{d:"M11 19a8 8 0 1 1 0-16 8 8 0 0 1 0 16zM21 21l-4.35-4.35"}),fontSize:e.jsx(Ne,{d:"M4 7V4h16v3M9 20h6M12 4v16"}),fontColor:e.jsx(Ne,{d:"M4 21h16M5 17l7-12 7 12M8 13h8"})},Gn=[{value:"1",label:"8pt"},{value:"2",label:"10pt"},{value:"3",label:"12pt"},{value:"4",label:"14pt"},{value:"5",label:"18pt"},{value:"6",label:"24pt"},{value:"7",label:"36pt"}],Jn=[{label:"Faces",emojis:["??","??","??","??","??","??","??","??","??","??","??","??"]},{label:"Hands",emojis:["??","??","??","??","??","??","??","??","??","??"]},{label:"Symbols",emojis:["??","?","??","?","?","?","??","??","??","??","??","??"]},{label:"Arrows",emojis:["??","??","??","??","??","??","??","??","??","?"]}];function Zn(n){let t=n;return t=t.replace(/<h1[^>]*>(.*?)<\/h1>/gi,`# $1
2
+ `),t=t.replace(/<h2[^>]*>(.*?)<\/h2>/gi,`## $1
3
+ `),t=t.replace(/<h3[^>]*>(.*?)<\/h3>/gi,`### $1
4
+ `),t=t.replace(/<strong[^>]*>(.*?)<\/strong>/gi,"**$1**"),t=t.replace(/<b[^>]*>(.*?)<\/b>/gi,"**$1**"),t=t.replace(/<em[^>]*>(.*?)<\/em>/gi,"*$1*"),t=t.replace(/<i[^>]*>(.*?)<\/i>/gi,"*$1*"),t=t.replace(/<code[^>]*>(.*?)<\/code>/gi,"`$1`"),t=t.replace(/<pre[^>]*>(.*?)<\/pre>/gis,"```\n$1\n```\n"),t=t.replace(/<br\s*\/?>/gi,`
5
+ `),t=t.replace(/<li[^>]*>(.*?)<\/li>/gi,`- $1
6
+ `),t=t.replace(/<\/?(?:ul|ol|p|div)[^>]*>/gi,`
7
+ `),t=t.replace(/<[^>]+>/g,""),t=t.replace(/\n{3,}/g,`
8
+
9
+ `),t.trim()}function Qn(n){let t=n;return t=t.replace(/^### (.+)$/gm,"<h3>$1</h3>"),t=t.replace(/^## (.+)$/gm,"<h2>$1</h2>"),t=t.replace(/^# (.+)$/gm,"<h1>$1</h1>"),t=t.replace(/\*\*(.+?)\*\*/g,"<strong>$1</strong>"),t=t.replace(/\*(.+?)\*/g,"<em>$1</em>"),t=t.replace(/`([^`]+)`/g,"<code>$1</code>"),t=t.replace(/```\n?([\s\S]*?)\n?```/g,"<pre>$1</pre>"),t=t.replace(/^- (.+)$/gm,"<li>$1</li>"),t=t.replace(/(<li>.*<\/li>)/gs,"<ul>$1</ul>"),t=t.replace(/\n/g,"<br>"),t}const jt=({value:n,onChange:t,placeholder:i,height:l=200,toolbar:d=Bn,readOnly:f,onImageUpload:_,mentionTrigger:S,mentionSuggestions:M,onMentionSearch:R,onFileDrop:K,pasteCleanup:z=!0,maxLength:g=0,showWordCount:C=!1,templates:W,label:ne,error:Q,helperText:J,required:h,disabled:L,size:w="md",id:E,className:X,style:b,accessMode:j})=>{const x=I.ml(j,E),T=x==="hidden";x==="disabled"&&(L=!0),x==="readOnly"&&(f=!0);const A=I.Xs(E),O=a.useRef(null),v=a.useRef(null),c=a.useRef(null),[P,y]=a.useState(!1),[k,s]=a.useState(""),[o,u]=a.useState(!1),[r,p]=a.useState(""),[q,F]=a.useState(!1),[G,ie]=a.useState(""),[N,H]=a.useState(0),[B,se]=a.useState(!1),[de,he]=a.useState("var(--nice-text, #000000)"),[be,ae]=a.useState("var(--nice-warning, #ffff00)"),[oe,ce]=a.useState(0),[me,le]=a.useState(0),[$,D]=a.useState(!1),[Y,pe]=a.useState(""),[Z,U]=a.useState(""),[re,fe]=a.useState(!1),[ke,ye]=a.useState(!1),je=a.useCallback((V,ue)=>{var Ce,ve,$e;if(f||L)return;const ge=O.current;if(ge){if(V==="markdown"){if(!P)s(Zn(n)),y(!0),u(!1);else{const _e=Qn(k);t(_e),y(!1)}return}if(V==="source"){o?(t(r),u(!1)):(p(n),u(!0),y(!1));return}if(V==="fullscreen"){se(_e=>!_e);return}if(V==="emoji"){fe(_e=>!_e);return}if(V==="findReplace"){D(_e=>!_e);return}if(V==="image"){if(_)(Ce=v.current)==null||Ce.click();else{const _e=prompt("Image URL:");_e&&Dt(_e)&&(ge.focus(),document.execCommand("insertImage",!1,_e),t(I.$s(ge.innerHTML)))}return}switch(ge.focus(),V){case"bold":document.execCommand("bold");break;case"italic":document.execCommand("italic");break;case"underline":document.execCommand("underline");break;case"strikethrough":document.execCommand("strikeThrough");break;case"h1":document.execCommand("formatBlock",!1,"h1");break;case"h2":document.execCommand("formatBlock",!1,"h2");break;case"h3":document.execCommand("formatBlock",!1,"h3");break;case"ul":document.execCommand("insertUnorderedList");break;case"ol":document.execCommand("insertOrderedList");break;case"blockquote":document.execCommand("formatBlock",!1,"blockquote");break;case"hr":document.execCommand("insertHorizontalRule");break;case"subscript":document.execCommand("subscript");break;case"superscript":document.execCommand("superscript");break;case"indent":document.execCommand("indent");break;case"outdent":document.execCommand("outdent");break;case"alignLeft":document.execCommand("justifyLeft");break;case"alignCenter":document.execCommand("justifyCenter");break;case"alignRight":document.execCommand("justifyRight");break;case"alignJustify":document.execCommand("justifyFull");break;case"removeFormat":document.execCommand("removeFormat");break;case"print":window.print();return;case"link":{const _e=prompt("URL:");_e&&Dt(_e)&&document.execCommand("createLink",!1,_e);break}case"unlink":document.execCommand("unlink");break;case"undo":document.execCommand("undo");break;case"redo":document.execCommand("redo");break;case"clear":document.execCommand("removeFormat");break;case"fontSize":{ue&&document.execCommand("fontSize",!1,ue);break}case"fontColor":{ue&&document.execCommand("foreColor",!1,ue);break}case"bgColor":{ue&&document.execCommand("hiliteColor",!1,ue);break}case"table":{document.execCommand("insertHTML",!1,'<table class="nice-htmleditor__table"><thead><tr><th>Header 1</th><th>Header 2</th><th>Header 3</th></tr></thead><tbody><tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr><tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr></tbody></table><p>&nbsp;</p>');break}case"code":{const _e=((ve=window.getSelection())==null?void 0:ve.toString())||"";_e.includes(`
10
+ `)||_e.length>60?document.execCommand("insertHTML",!1,`<pre class="nice-htmleditor__code-block">${_e||"// code"}</pre>`):document.execCommand("insertHTML",!1,`<code>${_e||"code"}</code>`);break}}t(I.$s(ge.innerHTML)),ce((($e=ge.textContent)==null?void 0:$e.length)??0)}},[t,f,L,P,k,n,_,o,r]),ze=a.useCallback(async V=>{var ve;const ue=(ve=V.target.files)==null?void 0:ve[0];if(!ue||!_)return;const ge=await _(ue),Ce=O.current;Ce&&ge&&(Ce.focus(),document.execCommand("insertImage",!1,ge),t(Ce.innerHTML)),V.target.value=""},[_,t]),ot=a.useCallback(()=>{var ge;const V=O.current;if(!V)return;const ue=((ge=V.textContent)==null?void 0:ge.length)??0;if(g>0&&ue>g&&(V.textContent=(V.textContent??"").slice(0,g)),ce(ue),le((V.textContent??"").trim().split(/\s+/).filter(Boolean).length),t(V.innerHTML),S){const Ce=window.getSelection();if(Ce&&Ce.rangeCount>0){const ve=Ce.getRangeAt(0),$e=ve.startContainer;if($e.nodeType===Node.TEXT_NODE){const _e=$e.textContent||"",Ae=ve.startOffset,Te=_e.slice(0,Ae),Re=Te.lastIndexOf(S);if(Re>=0&&(Re===0||/\s/.test(Te[Re-1]))){const Le=Te.slice(Re+S.length);if(!/\s/.test(Le)){F(!0),ie(Le),H(0),R==null||R(Le);return}}}}F(!1)}},[t,S,R]),De=(M==null?void 0:M.filter(V=>V.label.toLowerCase().includes(G.toLowerCase())).slice(0,8))??[],Ke=a.useCallback(V=>{var $e;const ue=O.current;if(!ue)return;const ge=window.getSelection();if(!ge||ge.rangeCount===0)return;const Ce=ge.getRangeAt(0),ve=Ce.startContainer;if(ve.nodeType===Node.TEXT_NODE&&S){const _e=ve.textContent||"",Ae=Ce.startOffset,Te=_e.slice(0,Ae).lastIndexOf(S);if(Te>=0){const Re=_e.slice(0,Te),Le=_e.slice(Ae),Ye=`<span class="nice-htmleditor__mention" data-mention="${V.key}" contenteditable="false">${S}${V.label}</span>&nbsp;`;ve.textContent=Re;const Oe=document.createRange();Oe.setStartAfter(ve),Oe.collapse(!0);const et=Oe.createContextualFragment(Ye+Le);($e=ve.parentNode)==null||$e.insertBefore(et,ve.nextSibling),ge.collapseToEnd(),t(ue.innerHTML)}}F(!1)},[S,t]),ct=a.useCallback(V=>{if(q&&De.length>0){V.key==="ArrowDown"?(V.preventDefault(),H(ue=>Math.min(ue+1,De.length-1))):V.key==="ArrowUp"?(V.preventDefault(),H(ue=>Math.max(ue-1,0))):V.key==="Enter"?(V.preventDefault(),Ke(De[N])):V.key==="Escape"&&F(!1);return}(V.ctrlKey||V.metaKey)&&V.key==="b"?(V.preventDefault(),je("bold")):(V.ctrlKey||V.metaKey)&&V.key==="i"?(V.preventDefault(),je("italic")):(V.ctrlKey||V.metaKey)&&V.key==="u"?(V.preventDefault(),je("underline")):(V.ctrlKey||V.metaKey)&&V.key==="f"?(V.preventDefault(),D(ue=>!ue)):(V.ctrlKey||V.metaKey)&&V.key==="z"&&!V.shiftKey?(V.preventDefault(),je("undo")):(V.ctrlKey||V.metaKey)&&(V.key==="y"||V.key==="z"&&V.shiftKey)&&(V.preventDefault(),je("redo"))},[q,De,N,Ke,je]),dt=a.useCallback(V=>{var ve;if(!z)return;V.preventDefault();const ue=V.clipboardData.getData("text/html"),ge=V.clipboardData.getData("text/plain");if(ue){const $e=ue.replace(/<style[\s\S]*?<\/style>/gi,"").replace(/<script[\s\S]*?<\/script>/gi,"").replace(/class="[^"]*"/gi,"").replace(/style="[^"]*"/gi,"").replace(/<o:[^>]*>[\s\S]*?<\/o:[^>]*>/gi,"").replace(/<!--[\s\S]*?-->/g,"").replace(/<\/?(?:xml|meta|link|font|span)[^>]*>/gi,"");document.execCommand("insertHTML",!1,$e)}else ge&&document.execCommand("insertText",!1,ge);const Ce=O.current;Ce&&(t(Ce.innerHTML),ce(((ve=Ce.textContent)==null?void 0:ve.length)??0))},[z,t]),ut=a.useCallback(async V=>{if(!K)return;V.preventDefault();const ue=Array.from(V.dataTransfer.files);if(ue.length===0)return;const ge=await K(ue),Ce=O.current;if(Ce){Ce.focus();for(const ve of ge)if(/\.(png|jpe?g|gif|webp|svg|bmp|ico)$/i.test(ve)||ve.startsWith("data:image/"))document.execCommand("insertImage",!1,ve);else{const $e=`<a href="${ve}">${ve.split("/").pop()??ve}</a>`;document.execCommand("insertHTML",!1,$e)}t(Ce.innerHTML)}},[K,t]),Ze=a.useCallback(V=>{K&&V.preventDefault()},[K]),Qe=a.useCallback(V=>{var $e;const ue=O.current;if(!ue||!Y)return;const ge=ue.textContent??"",Ce=Y.toLowerCase(),ve=ge.toLowerCase();(V===1?ve.indexOf(Ce):ve.lastIndexOf(Ce))!==-1&&(ue.focus(),($e=window.find)==null||$e.call(window,Y))},[Y]),pt=a.useCallback(()=>{const V=O.current;!V||!Y||(V.innerHTML=V.innerHTML.split(Y).join(Z),t(V.innerHTML))},[Y,Z,t]),He=a.useCallback(()=>{if(!Y)return;const V=n.split(Y).join(Z);t(V);const ue=O.current;ue&&(ue.innerHTML=V)},[Y,Z,n,t]),Me=a.useCallback(V=>{const ue=O.current;ue&&(ue.focus(),document.execCommand("insertText",!1,V),t(ue.innerHTML),fe(!1))},[t]),Ee=a.useCallback(V=>{const ue=O.current;ue&&(ue.focus(),document.execCommand("insertHTML",!1,V),t(ue.innerHTML),ye(!1))},[t]),ht=a.useCallback(V=>{const ue=L||f;return V==="fontSize"?e.jsx(I.Pe,{size:"sm",value:"",onChange:ge=>je("fontSize",String(ge)),disabled:ue,placeholder:"Size",options:Gn.map(ge=>({value:ge.value,label:ge.label})),style:{minWidth:70,maxWidth:80}},V):V==="fontColor"?e.jsx(I.on,{value:de,onChange:ge=>{he(ge),je("fontColor",ge)},disabled:ue,size:"sm",label:"",title:"Text color"},V):V==="bgColor"?e.jsx(I.on,{value:be,onChange:ge=>{ae(ge),je("bgColor",ge)},disabled:ue,size:"sm",label:"",title:"Highlight color"},V):e.jsx(I.dn,{size:"sm",variant:V==="markdown"&&P||V==="fullscreen"&&B||V==="source"&&o||V==="findReplace"&&$||V==="emoji"&&re?"primary":"ghost",onClick:()=>je(V),title:V,disabled:ue,children:Xn[V]||V},V)},[L,f,je,P,B,de,be,o,$,re]);return T?null:e.jsxs("div",{className:`nice-field nice-field--${w} ${Q?"nice-field--error":""} ${X||""}`,style:b,children:[ne&&e.jsxs("label",{className:"nice-field__label",htmlFor:A,children:[ne,h&&e.jsx("span",{className:"nice-field__required",children:"*"})]}),e.jsxs("div",{ref:c,className:`nice-htmleditor${B?" nice-htmleditor--fullscreen":""}`,children:[e.jsxs("div",{className:"nice-htmleditor__toolbar",style:{display:"flex",flexWrap:"wrap",gap:2,alignItems:"center"},children:[d.map(ht),W&&W.length>0&&e.jsxs("div",{style:{position:"relative"},children:[e.jsx(I.dn,{size:"sm",variant:ke?"primary":"ghost",onClick:()=>ye(V=>!V),title:"Insert template",children:"??"}),ke&&e.jsx("ul",{style:{position:"absolute",top:"100%",right:0,zIndex:200,background:"var(--bg-primary, #fff)",border:"1px solid var(--border-color, #ddd)",borderRadius:6,boxShadow:"0 4px 16px var(--nice-overlay-12, rgba(0, 0, 0, 0.12))",listStyle:"none",margin:0,padding:4,minWidth:160,maxHeight:200,overflow:"auto"},children:W.map((V,ue)=>e.jsx("li",{style:{padding:"6px 10px",cursor:"pointer",borderRadius:4},onMouseDown:ge=>{ge.preventDefault(),Ee(V.html)},children:V.label},ue))})]})]}),$&&e.jsxs("div",{className:"nice-htmleditor__find-bar",style:{display:"flex",gap:4,alignItems:"center",padding:"4px 8px",background:"var(--bg-secondary, #f8f9fa)",borderBottom:"1px solid var(--border-color, #ddd)",fontSize:"0.875em"},children:[e.jsx("input",{type:"text",placeholder:"Find...",value:Y,onChange:V=>pe(V.target.value),style:{flex:1,maxWidth:180,padding:"2px 6px",border:"1px solid var(--border-color, #ccc)",borderRadius:4,background:"var(--bg-primary, #fff)",color:"var(--text-primary, #1f2937)"}}),e.jsx("input",{type:"text",placeholder:"Replace...",value:Z,onChange:V=>U(V.target.value),style:{flex:1,maxWidth:180,padding:"2px 6px",border:"1px solid var(--border-color, #ccc)",borderRadius:4,background:"var(--bg-primary, #fff)",color:"var(--text-primary, #1f2937)"}}),e.jsx(I.dn,{size:"sm",variant:"ghost",onClick:()=>Qe(1),title:"Find next",children:"?"}),e.jsx(I.dn,{size:"sm",variant:"ghost",onClick:()=>Qe(-1),title:"Find previous",children:"?"}),e.jsx(I.dn,{size:"sm",variant:"ghost",onClick:pt,disabled:L||f,children:"Replace"}),e.jsx(I.dn,{size:"sm",variant:"ghost",onClick:He,disabled:L||f,children:"All"}),e.jsx(I.dn,{size:"sm",variant:"ghost",onClick:()=>D(!1),children:"?"})]}),re&&e.jsx("div",{className:"nice-htmleditor__emoji-picker",style:{padding:8,background:"var(--bg-primary, #fff)",borderBottom:"1px solid var(--border-color, #ddd)",maxHeight:180,overflowY:"auto"},children:Jn.map(V=>e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:"0.7em",fontWeight:600,color:"var(--text-muted, #999)",padding:"4px 0"},children:V.label}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:2},children:V.emojis.map(ue=>e.jsx("span",{style:{cursor:"pointer",fontSize:"1.2em",padding:2,borderRadius:4},onClick:()=>Me(ue),title:ue,children:ue},ue))})]},V.label))}),e.jsx("input",{ref:v,type:"file",accept:"image/*",style:{display:"none"},onChange:ze}),o?e.jsx("textarea",{className:"nice-htmleditor__source",value:r,onChange:V=>p(V.target.value),style:{minHeight:l,width:"100%",fontFamily:"monospace",resize:"vertical",whiteSpace:"pre",fontSize:"0.85em",background:"var(--bg-primary, #fff)",color:"var(--text-primary, #1f2937)",border:"none",padding:12,boxSizing:"border-box",outline:"none"},disabled:L||f}):P?e.jsx("textarea",{className:"nice-htmleditor__markdown",value:k,onChange:V=>s(V.target.value),style:{minHeight:l,width:"100%",fontFamily:"monospace",resize:"vertical",background:"var(--bg-primary, #fff)",color:"var(--text-primary, #1f2937)",border:"none",padding:12,boxSizing:"border-box",outline:"none"},disabled:L||f}):e.jsxs("div",{style:{position:"relative"},children:[e.jsx("div",{ref:O,id:A,className:"nice-htmleditor__content",contentEditable:!L&&!f,dangerouslySetInnerHTML:{__html:n},onInput:ot,onKeyDown:ct,onPaste:dt,onDrop:ut,onDragOver:Ze,style:{minHeight:l},"data-placeholder":i,role:"textbox","aria-multiline":"true",suppressContentEditableWarning:!0}),q&&De.length>0&&e.jsx("ul",{className:"nice-htmleditor__mention-list",children:De.map((V,ue)=>e.jsx("li",{className:`nice-htmleditor__mention-item ${ue===N?"nice-htmleditor__mention-item--active":""}`,onMouseDown:ge=>{ge.preventDefault(),Ke(V)},children:V.label},V.key))})]}),e.jsxs("div",{className:"nice-htmleditor__statusbar",style:{display:"flex",gap:12,padding:"2px 8px",fontSize:"0.75em",color:"var(--text-muted, #666)",borderTop:"1px solid var(--border-color, #eee)"},children:[g>0&&e.jsxs("span",{children:[oe," / ",g]}),C&&e.jsxs("span",{children:[me," words"]}),C&&e.jsxs("span",{children:[oe," chars"]}),o&&e.jsx("span",{style:{fontWeight:600},children:"HTML Source"}),P&&e.jsx("span",{style:{fontWeight:600},children:"Markdown"})]})]}),Q&&e.jsx("div",{className:"nice-field__error",children:Q}),J&&!Q&&e.jsx("div",{className:"nice-field__hint",children:J})]})},Yn=Object.freeze(Object.defineProperty({__proto__:null,NiceHtmlEditor:jt},Symbol.toStringTag,{value:"Module"})),ea=[{code:"en",label:"English"},{code:"es",label:"Spanish"},{code:"fr",label:"French"},{code:"de",label:"German"},{code:"it",label:"Italian"},{code:"pt",label:"Portuguese"},{code:"pl",label:"Polish"},{code:"ru",label:"Russian"},{code:"zh",label:"Chinese"},{code:"ja",label:"Japanese"},{code:"ko",label:"Korean"},{code:"ar",label:"Arabic"}],ta=[{style:"professional",label:"Professional"},{style:"casual",label:"Casual"},{style:"formal",label:"Formal"},{style:"concise",label:"Concise"}];a.forwardRef(function(n,t){var me,le;const{enableAI:i=!0,aiModel:l,enableImprove:d=!0,enableTranslate:f=!0,enableGenerate:_=!0,toolbar:S,languages:M=ea,textStyles:R=ta,onImprove:K,onTranslate:z,onGenerate:g,showAIToolbar:C=!0,value:W,onChange:ne,...Q}=n,J=a.useRef(null),[h,L]=a.useState(!1),[w,E]=a.useState(!1),[X,b]=a.useState(!1),[j,x]=a.useState(""),[T,A]=a.useState(""),[O,v]=a.useState("professional"),[c,P]=a.useState(""),[y,k]=a.useState(((me=M[0])==null?void 0:me.code)||"en"),[s,o]=a.useState(""),[u,r]=a.useState(""),{t:p}=I.ue(),q=I.me(),{improveText:F,translate:G,generateHtml:ie,isLoading:N}=I.Td(),H=i&&q.isConfigured,B=a.useCallback(()=>{const $=window.getSelection();return $&&$.toString().trim()?$.toString():""},[]),se=a.useCallback($=>{const D=window.getSelection();if(D&&D.rangeCount>0){const Y=D.getRangeAt(0);Y.deleteContents();const pe=document.createElement("div");pe.innerHTML=$;const Z=document.createDocumentFragment();for(;pe.firstChild;)Z.appendChild(pe.firstChild);if(Y.insertNode(Z),J.current){const U=J.current.innerHTML;ne(U)}}},[ne]),de=a.useCallback(async($="professional")=>{if(!H||!d)return"";const D=B();if(!D)return"";x(D),v($),L(!0),A("");try{const Y=await F(D,$);return A(Y),K==null||K(D,Y,$),Y}catch{return A(p("htmlEditorAI.improveFailed","Failed to improve text")),""}},[H,d,B,F,K,p]),he=a.useCallback(async $=>{var Y;if(!H||!f)return"";const D=B();if(!D)return"";x(D),k($),E(!0),P("");try{const pe=((Y=M.find(U=>U.code===$))==null?void 0:Y.label)||$,Z=await G(D,pe);return P(Z),z==null||z(D,Z,$),Z}catch{return P(p("htmlEditorAI.translateFailed","Failed to translate text")),""}},[H,f,B,G,M,z,p]),be=a.useCallback(async $=>{if(!H||!_||!$.trim())return"";o($),r("");try{const D=await ie($);return r(D),g==null||g($,D),D}catch{return r(p("htmlEditorAI.generateFailed","Failed to generate HTML")),""}},[H,_,ie,g,p]),ae=a.useCallback(()=>{T&&se(T),L(!1),A("")},[T,se]),oe=a.useCallback(()=>{c&&se(c),E(!1),P("")},[c,se]),ce=a.useCallback(()=>{if(u&&J.current){document.execCommand("insertHTML",!1,u);const $=J.current.innerHTML;ne($)}b(!1),r(""),o("")},[u,ne]);return a.useImperativeHandle(t,()=>({getEditor:()=>J.current,focus:()=>{var $;return($=J.current)==null?void 0:$.focus()},getValue:()=>{var $;return(($=J.current)==null?void 0:$.innerHTML)||""},setValue:$=>{J.current&&(J.current.innerHTML=$,ne($))},getSelection:B,insertHtml:$=>{document.execCommand("insertHTML",!1,$),J.current&&ne(J.current.innerHTML)},improveSelection:de,translateSelection:he,generateHtml:be})),a.useCallback($=>{J.current=$},[]),e.jsxs("div",{className:"nice-html-editor-ai","data-testid":n["data-testid"],children:[C&&H&&e.jsxs("div",{className:"nice-html-editor-ai__toolbar",children:[e.jsxs("div",{className:"nice-html-editor-ai__toolbar-left",children:[e.jsx("span",{className:"nice-html-editor-ai__badge",children:"AI"}),N&&e.jsx("span",{className:"nice-html-editor-ai__loading",children:p("htmlEditorAI.processing","Processing...")})]}),e.jsxs("div",{className:"nice-html-editor-ai__toolbar-right",children:[d&&e.jsxs("div",{className:"nice-html-editor-ai__dropdown",children:[e.jsxs("button",{type:"button",className:"nice-html-editor-ai__btn",onClick:()=>de(),disabled:N,title:p("htmlEditorAI.improveText","Improve selected text"),children:["✨ ",p("htmlEditorAI.improve","Improve")]}),e.jsx("div",{className:"nice-html-editor-ai__dropdown-menu",children:R.map(({style:$,label:D})=>e.jsx("button",{type:"button",className:"nice-html-editor-ai__dropdown-item",onClick:()=>de($),children:D},$))})]}),f&&e.jsxs("div",{className:"nice-html-editor-ai__dropdown",children:[e.jsxs("button",{type:"button",className:"nice-html-editor-ai__btn",disabled:N,title:p("htmlEditorAI.translateText","Translate selected text"),children:["🌐 ",p("htmlEditorAI.translate","Translate")]}),e.jsx("div",{className:"nice-html-editor-ai__dropdown-menu nice-html-editor-ai__dropdown-menu--languages",children:M.map(({code:$,label:D})=>e.jsx("button",{type:"button",className:"nice-html-editor-ai__dropdown-item",onClick:()=>he($),children:D},$))})]}),_&&e.jsxs("button",{type:"button",className:"nice-html-editor-ai__btn",onClick:()=>b(!0),disabled:N,title:p("htmlEditorAI.generateHtml","Generate HTML from description"),children:["⚡ ",p("htmlEditorAI.generate","Generate")]})]})]}),e.jsx("div",{className:"nice-html-editor-ai__editor-wrapper",children:e.jsx(jt,{value:W,onChange:ne,toolbar:S,...Q})}),h&&e.jsxs("div",{className:"nice-html-editor-ai__panel",children:[e.jsxs("div",{className:"nice-html-editor-ai__panel-header",children:[e.jsxs("h4",{children:["✨ ",p("htmlEditorAI.improveText","Improve Text")]}),e.jsx("div",{className:"nice-html-editor-ai__style-selector",children:R.map(({style:$,label:D})=>e.jsx("button",{type:"button",className:`nice-html-editor-ai__style-btn ${O===$?"nice-html-editor-ai__style-btn--active":""}`,onClick:()=>{v($),de($)},children:D},$))}),e.jsx("button",{type:"button",className:"nice-html-editor-ai__close",onClick:()=>L(!1),children:"✕"})]}),e.jsx("div",{className:"nice-html-editor-ai__panel-body",children:N?e.jsx("div",{className:"nice-html-editor-ai__loading-panel",children:p("htmlEditorAI.improving","Improving text...")}):e.jsxs("div",{className:"nice-html-editor-ai__comparison",children:[e.jsxs("div",{className:"nice-html-editor-ai__text-block",children:[e.jsx("h5",{children:p("htmlEditorAI.original","Original")}),e.jsx("div",{className:"nice-html-editor-ai__text-content",children:j})]}),e.jsxs("div",{className:"nice-html-editor-ai__text-block nice-html-editor-ai__text-block--improved",children:[e.jsx("h5",{children:p("htmlEditorAI.improved","Improved")}),e.jsx("div",{className:"nice-html-editor-ai__text-content",children:T})]})]})}),e.jsxs("div",{className:"nice-html-editor-ai__panel-footer",children:[e.jsxs("button",{type:"button",className:"nice-html-editor-ai__apply",onClick:ae,disabled:!T||N,children:["✓ ",p("htmlEditorAI.apply","Apply")]}),e.jsx("button",{type:"button",className:"nice-html-editor-ai__cancel",onClick:()=>{L(!1),A("")},children:p("htmlEditorAI.cancel","Cancel")})]})]}),w&&e.jsxs("div",{className:"nice-html-editor-ai__panel",children:[e.jsxs("div",{className:"nice-html-editor-ai__panel-header",children:[e.jsxs("h4",{children:["🌐 ",p("htmlEditorAI.translateText","Translate Text")]}),e.jsx("div",{className:"nice-html-editor-ai__language-selector",children:e.jsx("select",{value:y,onChange:$=>{k($.target.value),he($.target.value)},className:"nice-html-editor-ai__language-select",children:M.map(({code:$,label:D})=>e.jsx("option",{value:$,children:D},$))})}),e.jsx("button",{type:"button",className:"nice-html-editor-ai__close",onClick:()=>E(!1),children:"✕"})]}),e.jsx("div",{className:"nice-html-editor-ai__panel-body",children:N?e.jsx("div",{className:"nice-html-editor-ai__loading-panel",children:p("htmlEditorAI.translating","Translating...")}):e.jsxs("div",{className:"nice-html-editor-ai__comparison",children:[e.jsxs("div",{className:"nice-html-editor-ai__text-block",children:[e.jsx("h5",{children:p("htmlEditorAI.original","Original")}),e.jsx("div",{className:"nice-html-editor-ai__text-content",children:j})]}),e.jsxs("div",{className:"nice-html-editor-ai__text-block nice-html-editor-ai__text-block--translated",children:[e.jsx("h5",{children:((le=M.find($=>$.code===y))==null?void 0:le.label)||y}),e.jsx("div",{className:"nice-html-editor-ai__text-content",children:c})]})]})}),e.jsxs("div",{className:"nice-html-editor-ai__panel-footer",children:[e.jsxs("button",{type:"button",className:"nice-html-editor-ai__apply",onClick:oe,disabled:!c||N,children:["✓ ",p("htmlEditorAI.apply","Apply")]}),e.jsx("button",{type:"button",className:"nice-html-editor-ai__cancel",onClick:()=>{E(!1),P("")},children:p("htmlEditorAI.cancel","Cancel")})]})]}),X&&e.jsxs("div",{className:"nice-html-editor-ai__panel nice-html-editor-ai__panel--generate",children:[e.jsxs("div",{className:"nice-html-editor-ai__panel-header",children:[e.jsxs("h4",{children:["⚡ ",p("htmlEditorAI.generateHtml","Generate HTML")]}),e.jsx("button",{type:"button",className:"nice-html-editor-ai__close",onClick:()=>{b(!1),r(""),o("")},children:"✕"})]}),e.jsxs("div",{className:"nice-html-editor-ai__panel-body",children:[e.jsxs("div",{className:"nice-html-editor-ai__generate-input",children:[e.jsx("textarea",{placeholder:p("htmlEditorAI.generatePlaceholder",'Describe what you want to create (e.g., "A pricing table with 3 tiers", "A contact form with name, email, and message")'),value:s,onChange:$=>o($.target.value),className:"nice-html-editor-ai__generate-textarea",rows:3}),e.jsx("button",{type:"button",className:"nice-html-editor-ai__generate-btn",onClick:()=>be(s),disabled:N||!s.trim(),children:N?p("htmlEditorAI.generating","Generating..."):p("htmlEditorAI.generate","Generate")})]}),u&&e.jsxs("div",{className:"nice-html-editor-ai__generate-result",children:[e.jsx("h5",{children:p("htmlEditorAI.preview","Preview")}),e.jsx("div",{className:"nice-html-editor-ai__preview",dangerouslySetInnerHTML:{__html:u}}),e.jsx("h5",{children:p("htmlEditorAI.htmlCode","HTML Code")}),e.jsx("pre",{className:"nice-html-editor-ai__code",children:u})]})]}),e.jsxs("div",{className:"nice-html-editor-ai__panel-footer",children:[e.jsxs("button",{type:"button",className:"nice-html-editor-ai__apply",onClick:ce,disabled:!u||N,children:["✓ ",p("htmlEditorAI.insert","Insert")]}),e.jsx("button",{type:"button",className:"nice-html-editor-ai__cancel",onClick:()=>{b(!1),r(""),o("")},children:p("htmlEditorAI.cancel","Cancel")})]})]})]})});const nn=a.forwardRef(({length:n=6,value:t="",onChange:i,masked:l=!1,onComplete:d,label:f,helperText:_,error:S,required:M,disabled:R,readOnly:K,size:z="md",name:g,id:C,className:W,style:ne,autoFocus:Q,labelPlacement:J,errorPlacement:h,labelWidth:L,controlWidth:w,loading:E,cellWidth:X,...b},j)=>{const x=I.Xs(C),T=a.useRef([]),A=t.padEnd(n,"").slice(0,n).split(""),O=a.useCallback(k=>{var o;const s=Math.max(0,Math.min(n-1,k));(o=T.current[s])==null||o.focus()},[n]),v=a.useCallback(k=>{const s=k.join("");i==null||i(s),s.length===n&&s.indexOf("")===-1&&/^\d+$/.test(s)&&(d==null||d(s))},[i,d,n]),c=a.useCallback((k,s)=>{const o=s.target.value.replace(/\D/g,"").slice(-1);if(!o)return;const u=[...A];u[k]=o,v(u),O(k+1)},[A,v,O]),P=a.useCallback((k,s)=>{if(s.key==="Backspace"){s.preventDefault();const o=[...A];A[k]?(o[k]="",v(o)):k>0&&(o[k-1]="",v(o),O(k-1))}else s.key==="ArrowLeft"?(s.preventDefault(),O(k-1)):s.key==="ArrowRight"&&(s.preventDefault(),O(k+1))},[A,v,O]),y=a.useCallback(k=>{k.preventDefault();const s=k.clipboardData.getData("text").replace(/\D/g,"").slice(0,n);if(!s)return;const o=s.padEnd(n,"").slice(0,n).split("");for(let u=s.length;u<n;u++)o[u]=A[u]||"";v(o),O(Math.min(s.length,n-1))},[n,A,v,O]);return e.jsxs("div",{className:`nice-field nice-field--${z} nice-field--otp${J?` nice-field--label-${J}`:""}${h==="right"?" nice-field--error-right":""} ${E?"nice-field--loading":""} ${W||""}`,style:{...ne,...L!=null&&{"--nice-field-label-width":typeof L=="number"?`${L}px`:L},...w!=null&&{"--nice-field-control-width":typeof w=="number"?`${w}px`:w},...X!=null&&{"--nice-otp-cell-width":typeof X=="number"?`${X}px`:X}},"aria-busy":E||void 0,...b,children:[f&&e.jsx("label",{htmlFor:`${x}-0`,className:`nice-field__label ${M?"nice-field__label--required":""}`,children:f}),e.jsxs("div",{className:"nice-field__control",children:[e.jsxs("div",{ref:j,className:`nice-otp nice-otp--${z} ${S?"nice-otp--error":""} ${R?"nice-otp--disabled":""}`,onPaste:y,children:[Array.from({length:n},(k,s)=>e.jsx("input",{ref:o=>{T.current[s]=o},id:s===0?`${x}-0`:void 0,className:"nice-otp__digit",type:l?"password":"text",inputMode:"numeric",maxLength:2,value:A[s]||"",disabled:R,readOnly:K,autoFocus:Q&&s===0,"aria-invalid":!!S,"aria-label":`${s+1}`,onChange:o=>c(s,o),onKeyDown:o=>P(s,o),onFocus:o=>o.target.select()},s)),g&&e.jsx("input",{type:"hidden",name:g,value:t})]}),h==="right"&&S&&e.jsx("div",{id:`${x}-error`,className:"nice-field__error",role:"alert",children:S}),h==="right"&&!S&&_&&e.jsx("div",{id:`${x}-helper`,className:"nice-field__helper",children:_}),E&&e.jsx("span",{className:"nice-field__spinner",children:e.jsx("span",{className:"nice-spinner nice-spinner--sm"})})]}),h!=="right"&&S&&e.jsx("div",{id:`${x}-error`,className:"nice-field__error",role:"alert",children:S}),h!=="right"&&!S&&_&&e.jsx("div",{id:`${x}-helper`,className:"nice-field__helper",children:_})]})});nn.displayName="NiceInputOtp";const na={xxs:36,xs:48,sm:64,md:80,lg:100,xl:128,xxl:160},tt=6,Xe=135,an=405,Ue=an-Xe;function vt(n,t,i,l){const d=(l-90)*(Math.PI/180);return{x:n+i*Math.cos(d),y:t+i*Math.sin(d)}}function Lt(n,t,i,l,d){const f=vt(n,t,i,l),_=vt(n,t,i,d),S=d-l>180?1:0;return`M ${f.x} ${f.y} A ${i} ${i} 0 ${S} 1 ${_.x} ${_.y}`}const rn=a.forwardRef(({value:n=0,onChange:t,min:i=0,max:l=100,step:d=1,showValue:f=!0,valueTemplate:_="{value}",label:S,helperText:M,error:R,required:K,disabled:z,readOnly:g,size:C="md",name:W,id:ne,className:Q,style:J,labelPlacement:h="top",errorPlacement:L,labelWidth:w,controlWidth:E,loading:X,isLabelCentered:b=!0,...j},x)=>{const T=I.Xs(ne),A=a.useRef(!1),O=a.useRef(null),v=typeof C=="number"?C:na[C],c=v/2,P=v/2,y=(v-tt*2)/2,k=l>i?(n-i)/(l-i):0,s=Xe+k*Ue,o=a.useCallback(F=>{let G=F-Xe;G<0&&(G+=360),G>Ue&&(G=G-Ue<360-G?Ue:0);const ie=Math.max(0,Math.min(1,G/Ue)),N=i+ie*(l-i),H=Math.round(N/d)*d;return Math.max(i,Math.min(l,H))},[i,l,d]),u=a.useCallback(F=>{if(z||g)return;const G=O.current;if(!G)return;const ie=G.getBoundingClientRect(),N=F.clientX-ie.left-ie.width/2,H=F.clientY-ie.top-ie.height/2;let B=Math.atan2(N,-H)*(180/Math.PI);B<0&&(B+=360);const se=o(B);t==null||t(se)},[o,z,g,t]);a.useEffect(()=>{const F=ie=>{A.current&&u(ie)},G=()=>{A.current=!1};return window.addEventListener("pointermove",F),window.addEventListener("pointerup",G),()=>{window.removeEventListener("pointermove",F),window.removeEventListener("pointerup",G)}},[u]);const r=a.useCallback(F=>{if(z||g)return;let G=n;F.key==="ArrowUp"||F.key==="ArrowRight"?(F.preventDefault(),G=Math.min(l,n+d)):(F.key==="ArrowDown"||F.key==="ArrowLeft")&&(F.preventDefault(),G=Math.max(i,n-d)),G!==n&&(t==null||t(G))},[n,t,i,l,d,z,g]),p=_.replace("{value}",String(n)),q=vt(c,P,y,s);return e.jsxs("div",{className:`nice-field nice-knob-field nice-knob-field--err-${L||"bottom"} nice-field--${typeof C=="string"?C:"md"} ${X?"nice-field--loading":""} ${Q||""}`,style:{...J,...w!=null&&{"--nice-field-label-width":typeof w=="number"?`${w}px`:w},...E!=null&&{"--nice-field-control-width":typeof E=="number"?`${E}px`:E}},"aria-busy":X||void 0,...j,children:[e.jsxs("div",{className:`nice-knob-field__inner nice-knob-field--${h} ${b?"nice-knob-field--label-centered":""}`,children:[S&&e.jsx("label",{htmlFor:T,className:`nice-field__label ${K?"nice-field__label--required":""}`,children:S}),e.jsx("div",{className:"nice-field__control",children:e.jsxs("div",{ref:F=>{O.current=F,typeof x=="function"?x(F):x&&(x.current=F)},className:`nice-knob nice-knob--${C} ${z?"nice-knob--disabled":""} ${R?"nice-knob--error":""}`,role:"slider",id:T,tabIndex:z?-1:0,"aria-valuenow":n,"aria-valuemin":i,"aria-valuemax":l,"aria-disabled":z,"aria-invalid":!!R,onPointerDown:F=>{z||g||(A.current=!0,u(F))},onKeyDown:r,children:[e.jsxs("svg",{width:v,height:v,viewBox:`0 0 ${v} ${v}`,children:[e.jsx("path",{d:Lt(c,P,y,Xe,an),fill:"none",stroke:"var(--nice-border-color, #d1d5db)",strokeWidth:tt,strokeLinecap:"round"}),k>0&&e.jsx("path",{d:Lt(c,P,y,Xe,s),fill:"none",stroke:"var(--nice-primary, #3b82f6)",strokeWidth:tt,strokeLinecap:"round"}),e.jsx("circle",{cx:q.x,cy:q.y,r:tt,fill:"var(--nice-primary, #3b82f6)"})]}),f&&e.jsx("span",{className:"nice-knob__value",children:p}),W&&e.jsx("input",{type:"hidden",name:W,value:n}),X&&e.jsx("span",{className:"nice-knob__spinner","aria-hidden":"true",children:e.jsx("span",{className:"nice-spinner nice-spinner--sm"})})]})})]}),R&&e.jsx("div",{className:"nice-field__error",role:"alert",children:R}),!R&&M&&e.jsx("div",{className:"nice-field__helper",children:M})]})});rn.displayName="NiceKnob";const ln=a.forwardRef(({value:n="",onChange:t,suggestions:i=[],onSearch:l,trigger:d="@",renderSuggestion:f,placeholder:_,rows:S=3,label:M,helperText:R,error:K,required:z,disabled:g,readOnly:C,size:W="md",name:ne,id:Q,className:J,style:h,...L},w)=>{const E=I.Xs(Q),[X,b]=a.useState(!1),[j,x]=a.useState(""),[T,A]=a.useState(0),[O,v]=a.useState({top:0,left:0}),c=a.useRef(null),P=a.useRef(-1),y=i.map(r=>typeof r=="string"?{key:r,label:r}:r).filter(r=>r.label.toLowerCase().includes(j.toLowerCase())),k=a.useCallback(()=>{b(!1),x(""),A(0),P.current=-1},[]),s=a.useCallback(r=>{const p=c.current;if(!p||P.current<0)return;const q=n.slice(0,P.current),F=n.slice(p.selectionStart),G=`${d}${r.label} `,ie=q+G+F;t==null||t(ie),k(),requestAnimationFrame(()=>{const N=q.length+G.length;p.setSelectionRange(N,N),p.focus()})},[n,t,d,k]),o=a.useCallback(r=>{const p=r.target.value;t==null||t(p);const q=r.target.selectionStart,F=p.slice(0,q),G=F.lastIndexOf(d);if(G>=0){const ie=G>0?F[G-1]:" ",N=F.slice(G+d.length);if(/\s/.test(ie)&&!/\s/.test(N)){P.current=G;const H=N;x(H),b(!0),A(0),l==null||l(H);const B=r.target,se=B.getBoundingClientRect(),de=parseInt(getComputedStyle(B).lineHeight)||20,he=F.split(`
11
+ `);v({top:se.top+he.length*de+4-B.scrollTop,left:se.left+8});return}}k()},[t,d,l,k]),u=a.useCallback(r=>{!X||y.length===0||(r.key==="ArrowDown"?(r.preventDefault(),A(p=>(p+1)%y.length)):r.key==="ArrowUp"?(r.preventDefault(),A(p=>(p-1+y.length)%y.length)):r.key==="Enter"?(r.preventDefault(),y[T]&&s(y[T])):r.key==="Escape"&&k())},[X,y,T,s,k]);return a.useEffect(()=>{if(!X)return;const r=p=>{const q=c.current;q&&!q.contains(p.target)&&k()};return document.addEventListener("mousedown",r),()=>document.removeEventListener("mousedown",r)},[X,k]),e.jsxs("div",{className:`nice-field ${J||""}`,style:h,...L,children:[M&&e.jsx("label",{htmlFor:E,className:`nice-field__label ${z?"nice-field__label--required":""}`,children:M}),e.jsxs("div",{className:`nice-mention nice-mention--${W} ${K?"nice-mention--error":""} ${g?"nice-mention--disabled":""}`,children:[e.jsx("textarea",{ref:r=>{c.current=r,typeof w=="function"?w(r):w&&(w.current=r)},id:E,name:ne,className:"nice-mention__input",value:n,onChange:o,onKeyDown:u,placeholder:_,rows:S,disabled:g,readOnly:C,"aria-invalid":!!K,"aria-describedby":K?`${E}-error`:R?`${E}-helper`:void 0,"aria-autocomplete":"list","aria-expanded":X}),X&&y.length>0&&e.jsx("ul",{className:"nice-mention__suggestions",role:"listbox",style:{position:"fixed",top:O.top,left:O.left},children:y.map((r,p)=>e.jsx("li",{role:"option","aria-selected":p===T,className:`nice-mention__suggestion ${p===T?"nice-mention__suggestion--active":""}`,onMouseDown:q=>{q.preventDefault(),s(r)},onMouseEnter:()=>A(p),children:f?f(r):e.jsxs(e.Fragment,{children:[r.icon&&e.jsx("span",{className:"nice-mention__suggestion-icon",children:r.icon}),e.jsx("span",{children:r.label})]})},r.key))})]}),K&&e.jsx("div",{id:`${E}-error`,className:"nice-field__error",role:"alert",children:K}),!K&&R&&e.jsx("div",{id:`${E}-helper`,className:"nice-field__helper",children:R})]})});ln.displayName="NiceMention";function aa(n){const t=[],i=l=>{for(const d of l)t.push(d),d.children&&i(d.children)};return i(n),t}function sn(n,t){const i=t.toLowerCase();return n.reduce((l,d)=>{const f=d.children?sn(d.children,t):[];return(d.label.toLowerCase().includes(i)||f.length>0)&&l.push({...d,children:f.length>0?f:d.children}),l},[])}const on=({node:n,level:t,selectedKeys:i,expandedKeys:l,onToggleExpand:d,onSelect:f,selectableLeafsOnly:_})=>{const S=n.children&&n.children.length>0,M=l.has(n.key),R=i.has(n.key),K=!S,z=!n.disabled&&(!_||K);return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:`nice-tree-select__node ${R?"nice-tree-select__node--selected":""} ${n.disabled?"nice-tree-select__node--disabled":""}`,style:{paddingLeft:t*16+8},onClick:()=>z&&f(n.key),role:"treeitem","aria-selected":R,"aria-expanded":S?M:void 0,"aria-disabled":n.disabled,children:[S?e.jsx("button",{type:"button",className:"nice-tree-select__toggle",onClick:g=>{g.stopPropagation(),d(n.key)},"aria-label":"Toggle",children:e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"currentColor",style:{transform:M?"rotate(90deg)":"none",transition:"transform 0.15s"},children:e.jsx("path",{d:"M4.5 2l4 4-4 4"})})}):e.jsx("span",{style:{width:12,display:"inline-block"}}),(n.icon==null,null),e.jsx("span",{className:"nice-tree-select__node-label",children:n.label})]}),S&&M&&n.children.map(g=>e.jsx(on,{node:g,level:t+1,selectedKeys:i,expandedKeys:l,onToggleExpand:d,onSelect:f,selectableLeafsOnly:_},g.key))]})},cn=a.forwardRef(({nodes:n,value:t,onChange:i,multiple:l=!1,searchable:d=!1,placeholder:f,selectableLeafsOnly:_=!1,clearable:S=!1,label:M,helperText:R,error:K,required:z,disabled:g,readOnly:C,size:W="md",name:ne,id:Q,className:J,style:h,controlWidth:L,...w},E)=>{const{t:X}=I.ue(),b=I.Xs(Q),[j,x]=a.useState(!1),[T,A]=a.useState(""),[O,v]=a.useState(new Set),c=a.useRef(null);I.Js(c,()=>x(!1));const P=a.useMemo(()=>t==null?new Set:new Set(Array.isArray(t)?t:[t]),[t]),y=a.useMemo(()=>T?sn(n,T):n,[n,T]),k=a.useMemo(()=>{const r=aa(n);return Array.from(P).map(p=>{var q;return(q=r.find(F=>F.key===p))==null?void 0:q.label}).filter(Boolean)},[P,n]),s=a.useCallback(r=>{v(p=>{const q=new Set(p);return q.has(r)?q.delete(r):q.add(r),q})},[]),o=a.useCallback(r=>{if(l){const p=new Set(P);p.has(r)?p.delete(r):p.add(r),i==null||i(Array.from(p))}else i==null||i(r),x(!1)},[l,P,i]),u=a.useCallback(r=>{r.stopPropagation(),i==null||i(l?[]:"")},[i,l]);return e.jsxs("div",{className:`nice-field nice-field--${W} ${J||""}`,style:{width:"fit-content",maxWidth:"100%",...h},...w,children:[M&&e.jsx("label",{htmlFor:b,className:`nice-field__label ${z?"nice-field__label--required":""}`,children:M}),e.jsxs("div",{ref:c,className:"nice-tree-select",style:{position:"relative",width:L!=null?typeof L=="number"?`${L}px`:L:240},children:[e.jsxs("div",{ref:E,id:b,className:`nice-input nice-input--${W} ${K?"nice-input--error":""} ${g?"nice-input--disabled":""} ${C?"nice-input--readonly":""}`,role:"combobox","aria-expanded":j,"aria-haspopup":"tree","aria-invalid":!!K,tabIndex:g?-1:0,onClick:()=>!g&&!C&&x(!j),onKeyDown:r=>{(r.key==="Enter"||r.key===" ")&&(r.preventDefault(),!g&&!C&&x(!j))},children:[e.jsx("span",{className:"nice-tree-select__display",children:k.length>0?k.join(", "):e.jsx("span",{className:"nice-tree-select__placeholder",children:f??X("controls.select","Select...")})}),S&&P.size>0&&e.jsx("button",{type:"button",className:"nice-input__clear",onClick:u,"aria-label":X("controls.clear","Clear"),children:"✕"}),e.jsx("svg",{className:"nice-tree-select__arrow",width:"14",height:"14",viewBox:"0 0 20 20",fill:"currentColor",style:{transform:j?"rotate(180deg)":"none",transition:"transform 0.15s"},children:e.jsx("path",{d:"M5.293 7.293a1 1 0 011.414 0L10 10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z"})})]}),j&&e.jsxs("div",{className:"nice-tree-select__dropdown",role:"tree",children:[d&&e.jsx("div",{className:"nice-tree-select__search",children:e.jsx("input",{className:"nice-input__native",type:"text",placeholder:X("controls.search","Search..."),value:T,onChange:r=>A(r.target.value),autoFocus:!0,onClick:r=>r.stopPropagation()})}),e.jsx("div",{className:"nice-tree-select__list",children:y.length===0?e.jsx("div",{className:"nice-tree-select__empty",children:X("controls.noResults","No results")}):y.map(r=>e.jsx(on,{node:r,level:0,selectedKeys:P,expandedKeys:O,onToggleExpand:s,onSelect:o,selectableLeafsOnly:_},r.key))})]})]}),ne&&e.jsx("input",{type:"hidden",name:ne,value:Array.isArray(t)?t.join(","):t??""}),K&&e.jsx("div",{id:`${b}-error`,className:"nice-field__error",role:"alert",children:K}),!K&&R&&e.jsx("div",{id:`${b}-helper`,className:"nice-field__helper",children:R})]})});cn.displayName="NiceTreeSelect";function Ie(n,t){return String(n[t])}const dn=a.forwardRef(({source:n,target:t,onChange:i,keyField:l="id",labelField:d="label",renderItem:f,filterable:_=!1,searchable:S,groupBy:M,sortable:R=!1,bulkActions:K=!0,maxRight:z,sourceHeader:g,targetHeader:C,disabled:W=!1,size:ne="md",className:Q,style:J,id:h,...L},w)=>{const{t:E}=I.ue(),[X,b]=a.useState(new Set),[j,x]=a.useState(new Set),[T,A]=a.useState(""),[O,v]=a.useState(""),c=a.useCallback((p,q,F)=>{q(G=>{const ie=new Set(G);return ie.has(F)?ie.delete(F):ie.add(F),ie})},[]),P=a.useCallback(()=>{const p=n.filter(ie=>X.has(Ie(ie,l))),q=n.filter(ie=>!X.has(Ie(ie,l))),F=typeof z=="number"?p.slice(0,Math.max(0,z-t.length)):p,G=p.slice(F.length);i([...q,...G],[...t,...F]),b(new Set)},[n,t,X,l,i,z]),y=a.useCallback(()=>{const p=t.filter(F=>j.has(Ie(F,l))),q=t.filter(F=>!j.has(Ie(F,l)));i([...n,...p],q),x(new Set)},[n,t,j,l,i]),k=a.useCallback(()=>{if(typeof z=="number"){const p=Math.max(0,z-t.length),q=n.slice(0,p),F=n.slice(p);i(F,[...t,...q])}else i([],[...t,...n]);b(new Set)},[n,t,i,z]),s=a.useCallback(()=>{i([...n,...t],[]),x(new Set)},[n,t,i]),o=(p,q)=>{if(!q)return p;const F=q.toLowerCase();return p.filter(G=>String(G[d]).toLowerCase().includes(F))},u=K===!1?{moveAll:!1,removeAll:!1}:K===!0||K===void 0?{moveAll:!0,removeAll:!0}:{moveAll:K.moveAll??!0,removeAll:K.removeAll??!0},r=(p,q,F,G,ie,N,H)=>{const B=o(p,G),se=S===!0||_&&S===void 0?"both":S??!1,de=se==="both"||se==="left"&&H==="left"||se==="right"&&H==="right",he=(()=>{if(!M)return[{label:"",items:B}];const oe=new Map;for(const ce of B){const me=String(M(ce));let le=oe.get(me);le||(le=[],oe.set(me,le)),le.push(ce)}return[...oe.entries()].map(([ce,me])=>({label:ce,items:me}))})(),be=(oe,ce)=>{oe.dataTransfer.setData("text/plain",ce),oe.dataTransfer.effectAllowed="move"},ae=(oe,ce)=>{oe.preventDefault();const me=oe.dataTransfer.getData("text/plain");if(!me||me===ce||H!=="right"||!R)return;const le=[...t],$=le.findIndex(pe=>Ie(pe,l)===me),D=le.findIndex(pe=>Ie(pe,l)===ce);if($===-1||D===-1)return;const[Y]=le.splice($,1);le.splice(D,0,Y),i(n,le)};return e.jsxs("div",{className:"nice-picklist__panel",children:[N&&e.jsx("div",{className:"nice-picklist__header",children:N}),de&&e.jsx("div",{className:"nice-picklist__filter",children:e.jsx("input",{className:"nice-input__native",type:"text",placeholder:E("controls.search","Search..."),value:G,onChange:oe=>ie(oe.target.value)})}),e.jsxs("div",{className:"nice-picklist__list",role:"listbox","aria-multiselectable":"true",children:[he.map(oe=>e.jsxs(a.Fragment,{children:[oe.label&&e.jsx("div",{className:"nice-picklist__group-header",role:"presentation",children:oe.label}),oe.items.map(ce=>{const me=Ie(ce,l),le=q.has(me);return e.jsx("div",{className:`nice-picklist__item ${le?"nice-picklist__item--selected":""}`,role:"option","aria-selected":le,draggable:R&&H==="right",onDragStart:R&&H==="right"?$=>be($,me):void 0,onDragOver:R&&H==="right"?$=>$.preventDefault():void 0,onDrop:R&&H==="right"?$=>ae($,me):void 0,onClick:()=>!W&&c(q,F,me),children:f?f(ce,H):String(ce[d])},me)})]},oe.label||"__none__")),B.length===0&&e.jsx("div",{className:"nice-picklist__empty",children:E("controls.noItems","No items")})]})]})};return e.jsxs("div",{ref:w,id:h,className:`nice-picklist nice-picklist--${ne} ${W?"nice-picklist--disabled":""} ${Q||""}`,style:J,...L,children:[r(n,X,b,T,A,g??E("picklist.source","Available"),"left"),e.jsxs("div",{className:"nice-picklist__controls",children:[e.jsx("button",{type:"button",className:"nice-btn nice-btn--outline nice-btn--sm",disabled:W||X.size===0,onClick:P,"aria-label":E("picklist.moveRight","Move right"),children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 20 20",fill:"currentColor",children:e.jsx("path",{d:"M7.293 14.707a1 1 0 010-1.414L10.586 10 7.293 6.707a1 1 0 011.414-1.414l4 4a1 1 0 010 1.414l-4 4a1 1 0 01-1.414 0z"})})}),u.moveAll&&e.jsx("button",{type:"button",className:"nice-btn nice-btn--outline nice-btn--sm",disabled:W||n.length===0,onClick:k,"aria-label":E("picklist.moveAllRight","Move all right"),children:e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 20 20",fill:"currentColor",children:[e.jsx("path",{d:"M4.293 14.707a1 1 0 010-1.414L7.586 10 4.293 6.707a1 1 0 011.414-1.414l4 4a1 1 0 010 1.414l-4 4a1 1 0 01-1.414 0z"}),e.jsx("path",{d:"M10.293 14.707a1 1 0 010-1.414L13.586 10 10.293 6.707a1 1 0 011.414-1.414l4 4a1 1 0 010 1.414l-4 4a1 1 0 01-1.414 0z"})]})}),e.jsx("button",{type:"button",className:"nice-btn nice-btn--outline nice-btn--sm",disabled:W||j.size===0,onClick:y,"aria-label":E("picklist.moveLeft","Move left"),children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 20 20",fill:"currentColor",children:e.jsx("path",{d:"M12.707 5.293a1 1 0 010 1.414L9.414 10l3.293 3.293a1 1 0 01-1.414 1.414l-4-4a1 1 0 010-1.414l4-4a1 1 0 011.414 0z"})})}),u.removeAll&&e.jsx("button",{type:"button",className:"nice-btn nice-btn--outline nice-btn--sm",disabled:W||t.length===0,onClick:s,"aria-label":E("picklist.moveAllLeft","Move all left"),children:e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 20 20",fill:"currentColor",children:[e.jsx("path",{d:"M15.707 5.293a1 1 0 010 1.414L12.414 10l3.293 3.293a1 1 0 01-1.414 1.414l-4-4a1 1 0 010-1.414l4-4a1 1 0 011.414 0z"}),e.jsx("path",{d:"M9.707 5.293a1 1 0 010 1.414L6.414 10l3.293 3.293a1 1 0 01-1.414 1.414l-4-4a1 1 0 010-1.414l4-4a1 1 0 011.414 0z"})]})})]}),r(t,j,x,O,v,C??E("picklist.target","Selected"),"right")]})});dn.displayName="NicePickList";let qe=null,Ve=null;const ia="0.45.0",lt=`https://cdn.jsdelivr.net/npm/monaco-editor@${ia}/min/vs`,Pt=15e3;function At(){var l;const n=window;if((l=n.MonacoEnvironment)!=null&&l.getWorkerUrl)return;const t=`self.MonacoEnvironment={baseUrl:'${lt}/'};importScripts('${lt}/base/worker/workerMain.js');`,i=URL.createObjectURL(new Blob([t],{type:"text/javascript"}));n.MonacoEnvironment={getWorkerUrl:()=>i}}function Fe(n){var i;if(n!=="auto")return n;if(typeof document>"u")return"vs";const t=document.documentElement.dataset.theme;return t==="dark"?"vs-dark":t==="light"?"vs":(i=window.matchMedia)!=null&&i.call(window,"(prefers-color-scheme: dark)").matches?"vs-dark":"vs"}function un(){return Ve?Promise.resolve(Ve):qe||(qe=new Promise((n,t)=>{if(window.monaco){At(),Ve=window.monaco,n(Ve);return}let i=!1;const l=window.setTimeout(()=>{i||(i=!0,qe=null,t(new Error(`Monaco editor failed to load within ${Pt}ms`)))},Pt),d=document.createElement("script");d.src=`${lt}/loader.min.js`,d.async=!0,d.onload=()=>{const f=window.require;f.config({paths:{vs:lt}}),At(),f(["vs/editor/editor.main"],_=>{i||(i=!0,window.clearTimeout(l),Ve=_,n(_))})},d.onerror=()=>{i||(i=!0,window.clearTimeout(l),qe=null,t(new Error("Failed to load Monaco Editor loader script")))},document.head.appendChild(d)}),qe)}const Ct=a.forwardRef(function(n,t){const{value:i,onChange:l,language:d="plaintext",theme:f="auto",options:_={},height:S=400,width:M="100%",markers:R=[],decorations:K=[],completionProvider:z,onMount:g,onCursorPositionChange:C,onSelectionChange:W,onSave:ne,loading:Q,disabled:J=!1,showToolbar:h=!1,showStatusBar:L=!1,editorSize:w="standard",className:E,"data-testid":X,lsp:b}=n,j=a.useRef(null),x=a.useRef(null),T=a.useRef(null),A=a.useRef([]),O=a.useRef(null),[v,c]=a.useState(!0),[P,y]=a.useState(null),[k,s]=a.useState({lineNumber:1,column:1}),[o,u]=a.useState(""),[r,p]=a.useState(_.wordWrap==="on"),q=a.useMemo(()=>({automaticLayout:!0,readOnly:J||_.readOnly,minimap:{enabled:_.minimap??!0},lineNumbers:_.lineNumbers??"on",wordWrap:_.wordWrap??"off",tabSize:_.tabSize??2,insertSpaces:_.insertSpaces??!0,fontSize:_.fontSize??14,fontFamily:_.fontFamily??"'Fira Code', 'Consolas', 'Monaco', monospace",fontLigatures:_.fontLigatures??!0,cursorStyle:_.cursorStyle??"line",cursorBlinking:_.cursorBlinking??"blink",autoClosingBrackets:_.autoClosingBrackets??"languageDefined",autoClosingQuotes:_.autoClosingQuotes??"languageDefined",formatOnPaste:_.formatOnPaste??!1,formatOnType:_.formatOnType??!1,renderWhitespace:_.renderWhitespace??"selection",renderControlCharacters:_.renderControlCharacters??!1,scrollBeyondLastLine:_.scrollBeyondLastLine??!0,smoothScrolling:_.smoothScrolling??!0,folding:_.folding??!0,showFoldingControls:_.showFoldingControls??"mouseover","bracketPairColorization.enabled":_.bracketPairColorization??!0,guides:_.guides??{bracketPairs:!0,indentation:!0,highlightActiveIndentation:!0},stickyScroll:{enabled:_.stickyScroll??!1},quickSuggestions:_.quickSuggestions??!0,suggestOnTriggerCharacters:_.suggestOnTriggerCharacters??!0,acceptSuggestionOnEnter:_.acceptSuggestionOnEnter??"on",inlayHints:{enabled:_.inlayHints?"on":"off"}}),[_,J]);a.useEffect(()=>{if(!j.current)return;let N=!0;return un().then(async H=>{if(!N||!j.current)return;T.current=H;const B=H.editor.create(j.current,{value:i,language:d,theme:Fe(f),...q});if(x.current=B,c(!1),B.onDidChangeModelContent(()=>{const se=B.getValue();l==null||l(se)}),B.onDidChangeCursorPosition(se=>{s({lineNumber:se.position.lineNumber,column:se.position.column}),C==null||C({lineNumber:se.position.lineNumber,column:se.position.column})}),B.onDidChangeCursorSelection(se=>{var be;const de=se.selection,he=((be=B.getModel())==null?void 0:be.getValueInRange(de))??"";u(he),W==null||W({startLineNumber:de.startLineNumber,startColumn:de.startColumn,endLineNumber:de.endLineNumber,endColumn:de.endColumn})}),B.addCommand(H.KeyMod.CtrlCmd|H.KeyCode.KeyS,()=>{ne==null||ne(B.getValue())}),b&&typeof window<"u")try{await st("https://cdn.jsdelivr.net/npm/vscode-ws-jsonrpc@1.0.2/lib/browser/index.min.js"),await st("https://cdn.jsdelivr.net/npm/monaco-languageclient@0.15.0/lib/monaco-languageclient.min.js");const se=window,de=se.ReconnectingWebSocket,{MonacoLanguageClient:he,CloseAction:be,ErrorAction:ae,createConnection:oe}=se.monacoLanguageClient||{};if(he&&oe){const ce=b.url,me=b.language,le=new de(ce),$=new se.VSCodeWebSocketMessageReader(le),D=new se.VSCodeWebSocketMessageWriter(le),Y=oe($,D),pe=new he({name:"LSP Client",clientOptions:{documentSelector:[me],initializationOptions:b.initOptions,errorHandler:{error:()=>ae.Continue,closed:()=>be.Restart}},connectionProvider:{get:()=>Promise.resolve(Y)}});pe.start(),x.current.__lspClient=pe}}catch(se){console.warn("LSP bridge failed to load:",se)}g==null||g(B,H)}).catch(H=>{N&&(y(H.message??"Failed to load editor"),c(!1))}),()=>{var H,B;if(N=!1,(H=x.current)==null||H.dispose(),(B=O.current)==null||B.dispose(),x.current&&x.current.__lspClient)try{x.current.__lspClient.stop()}catch{}}},[b]),a.useEffect(()=>{const N=x.current;if(N&&i!==N.getValue()){const H=N.getPosition();N.setValue(i),H&&N.setPosition(H)}},[i]),a.useEffect(()=>{const N=x.current,H=T.current;if(N&&H){const B=N.getModel();B&&H.editor.setModelLanguage(B,d)}},[d]),a.useEffect(()=>{var de,he;const N=T.current;if(!N||(N.editor.setTheme(Fe(f)),f!=="auto"||typeof document>"u"))return;const H=()=>{var be;(be=T.current)==null||be.editor.setTheme(Fe("auto"))},B=new MutationObserver(H);B.observe(document.documentElement,{attributes:!0,attributeFilter:["data-theme","class"]});const se=(de=window.matchMedia)==null?void 0:de.call(window,"(prefers-color-scheme: dark)");return(he=se==null?void 0:se.addEventListener)==null||he.call(se,"change",H),()=>{var be;B.disconnect(),(be=se==null?void 0:se.removeEventListener)==null||be.call(se,"change",H)}},[f]),a.useEffect(()=>{const N=x.current;N&&N.updateOptions(q)},[q]),a.useEffect(()=>{const N=x.current,H=T.current;if(N&&H){const B=N.getModel();if(B){const se=R.map(de=>({startLineNumber:de.startLineNumber,startColumn:de.startColumn,endLineNumber:de.endLineNumber,endColumn:de.endColumn,message:de.message,severity:de.severity}));H.editor.setModelMarkers(B,"owner",se)}}},[R]),a.useEffect(()=>{const N=x.current;if(N&&K.length>0){const H=K.map(B=>({range:{startLineNumber:B.range.startLineNumber,startColumn:B.range.startColumn,endLineNumber:B.range.endLineNumber,endColumn:B.range.endColumn},options:{className:B.className,glyphMarginClassName:B.glyphMarginClassName,hoverMessage:B.hoverMessage?{value:B.hoverMessage}:void 0,isWholeLine:B.isWholeLine}}));A.current=N.deltaDecorations(A.current,H)}},[K]),a.useEffect(()=>{var B;const N=T.current;if(!N||!z)return;(B=O.current)==null||B.dispose();const H={text:0,method:1,function:2,constructor:3,field:4,variable:5,class:6,interface:7,module:8,property:9,keyword:13,snippet:14,color:15,file:16,reference:17,folder:18};return O.current=N.languages.registerCompletionItemProvider(d,{provideCompletionItems:async(se,de)=>({suggestions:(await z(se,de)).map(he=>({label:he.label,kind:H[he.kind]??0,insertText:he.insertText,insertTextRules:he.insertTextRules==="insertAsSnippet"?4:void 0,documentation:he.documentation,detail:he.detail,range:{startLineNumber:de.lineNumber,startColumn:de.column,endLineNumber:de.lineNumber,endColumn:de.column}}))})}),()=>{var se;(se=O.current)==null||se.dispose()}},[d,z]),a.useImperativeHandle(t,()=>({getEditor:()=>x.current,getMonaco:()=>T.current,focus:()=>{var N;return(N=x.current)==null?void 0:N.focus()},getValue:()=>{var N;return((N=x.current)==null?void 0:N.getValue())??""},setValue:N=>{var H;return(H=x.current)==null?void 0:H.setValue(N)},getSelection:()=>{var B;const N=x.current;if(!N)return"";const H=N.getSelection();return H?((B=N.getModel())==null?void 0:B.getValueInRange(H))??"":""},insertText:N=>{const H=x.current;if(!H)return;const B=H.getSelection();B&&H.executeEdits("",[{range:B,text:N}])},formatDocument:()=>{var N,H;(H=(N=x.current)==null?void 0:N.getAction("editor.action.formatDocument"))==null||H.run()},goToLine:(N,H=1)=>{const B=x.current;B&&(B.setPosition({lineNumber:N,column:H}),B.revealLineInCenter(N),B.focus())},findReplace:()=>{var N,H;(H=(N=x.current)==null?void 0:N.getAction("editor.action.startFindReplaceAction"))==null||H.run()},undo:()=>{var N;(N=x.current)==null||N.trigger("keyboard","undo",null)},redo:()=>{var N;(N=x.current)==null||N.trigger("keyboard","redo",null)},getCursorPosition:()=>{var H;const N=(H=x.current)==null?void 0:H.getPosition();return{lineNumber:(N==null?void 0:N.lineNumber)??1,column:(N==null?void 0:N.column)??1}},setMarkers:N=>{const H=x.current,B=T.current;if(H&&B){const se=H.getModel();if(se){const de=N.map(he=>({startLineNumber:he.startLineNumber,startColumn:he.startColumn,endLineNumber:he.endLineNumber,endColumn:he.endColumn,message:he.message,severity:he.severity}));B.editor.setModelMarkers(se,"owner",de)}}}}),[]);const F=a.useMemo(()=>({format:()=>{var N,H;return(H=(N=x.current)==null?void 0:N.getAction("editor.action.formatDocument"))==null?void 0:H.run()},undo:()=>{var N;return(N=x.current)==null?void 0:N.trigger("keyboard","undo",null)},redo:()=>{var N;return(N=x.current)==null?void 0:N.trigger("keyboard","redo",null)},find:()=>{var N,H;return(H=(N=x.current)==null?void 0:N.getAction("editor.action.startFindReplaceAction"))==null?void 0:H.run()},toggleWordWrap:()=>{var H;const N=!r;p(N),(H=x.current)==null||H.updateOptions({wordWrap:N?"on":"off"})},toggleMinimap:()=>{var H,B,se,de,he,be;const N=(he=(H=x.current)==null?void 0:H.getOption)==null?void 0:he.call(H,(de=(se=(B=T.current)==null?void 0:B.editor)==null?void 0:se.EditorOption)==null?void 0:de.minimap);(be=x.current)==null||be.updateOptions({minimap:{enabled:!(N!=null&&N.enabled)}})},foldAll:()=>{var N,H;return(H=(N=x.current)==null?void 0:N.getAction("editor.foldAll"))==null?void 0:H.run()},unfoldAll:()=>{var N,H;return(H=(N=x.current)==null?void 0:N.getAction("editor.unfoldAll"))==null?void 0:H.run()}}),[r]),G=i.split(`
12
+ `).length,ie=i.length;return e.jsxs("div",{className:`nice-code-editor-wrap nice-editor--${w} ${E??""}`,style:{height:S,width:M,display:"flex",flexDirection:"column",position:"relative"},"data-testid":X,children:[P&&e.jsxs("div",{className:"nice-code-editor__error",style:{position:"absolute",inset:0,zIndex:2,background:"var(--nice-bg-primary, #fff)"},children:[e.jsxs("span",{children:["⚠️ ",P]}),e.jsx("textarea",{value:i,onChange:N=>l==null?void 0:l(N.target.value),readOnly:J||_.readOnly,style:{width:"100%",height:"100%",fontFamily:"monospace"}})]}),v&&!P&&e.jsx("div",{className:"nice-code-editor__loader-overlay",style:{position:"absolute",inset:0,zIndex:2,display:"flex",alignItems:"center",justifyContent:"center",background:"var(--nice-bg-primary, #fff)"},children:Q??e.jsx("div",{className:"nice-code-editor__loader",children:"Loading editor..."})}),h&&e.jsxs("div",{className:"nice-code-editor__toolbar",children:[e.jsx("button",{className:"nice-code-editor__toolbar-btn",onClick:F.undo,title:"Undo (Ctrl+Z)",children:"↶"}),e.jsx("button",{className:"nice-code-editor__toolbar-btn",onClick:F.redo,title:"Redo (Ctrl+Y)",children:"↷"}),e.jsx("span",{className:"nice-code-editor__toolbar-sep"}),e.jsx("button",{className:"nice-code-editor__toolbar-btn",onClick:F.format,title:"Format (Shift+Alt+F)",children:"⎘"}),e.jsx("button",{className:"nice-code-editor__toolbar-btn",onClick:F.find,title:"Find & Replace (Ctrl+H)",children:"🔍"}),e.jsx("span",{className:"nice-code-editor__toolbar-sep"}),e.jsx("button",{className:`nice-code-editor__toolbar-btn${r?" nice-code-editor__toolbar-btn--active":""}`,onClick:F.toggleWordWrap,title:"Toggle Word Wrap",children:"↩"}),e.jsx("button",{className:"nice-code-editor__toolbar-btn",onClick:F.toggleMinimap,title:"Toggle Minimap",children:"▥"}),e.jsx("span",{className:"nice-code-editor__toolbar-sep"}),e.jsx("button",{className:"nice-code-editor__toolbar-btn",onClick:F.foldAll,title:"Fold All",children:"⊟"}),e.jsx("button",{className:"nice-code-editor__toolbar-btn",onClick:F.unfoldAll,title:"Unfold All",children:"⊞"})]}),e.jsx("div",{ref:j,className:"nice-code-editor",style:{flex:1,minHeight:0}}),L&&e.jsxs("div",{className:"nice-code-editor__statusbar",children:[e.jsxs("span",{children:["Ln ",k.lineNumber,", Col ",k.column]}),o.length>0&&e.jsxs("span",{children:["(",o.length," selected)"]}),e.jsx("span",{className:"nice-code-editor__statusbar-spacer"}),e.jsxs("span",{children:[G," lines · ",ie," chars"]}),e.jsx("span",{className:"nice-code-editor__statusbar-lang",children:d}),R.length>0&&e.jsxs("span",{className:"nice-code-editor__statusbar-markers",children:["⚠ ",R.length]})]})]})});function pn(n){const{original:t,modified:i,language:l="plaintext",theme:d="auto",height:f=400,width:_="100%",inline:S=!1,renderSideBySide:M=!0,originalEditable:R=!1,modifiedEditable:K=!1,onOriginalChange:z,onModifiedChange:g,loading:C,className:W,"data-testid":ne}=n,Q=a.useRef(null),J=a.useRef(null),h=a.useRef(null),[L,w]=a.useState(!0),[E,X]=a.useState(null);return a.useEffect(()=>{if(!Q.current)return;let b=!0;return un().then(j=>{if(!b||!Q.current)return;h.current=j;const x=j.editor.createModel(t,l),T=j.editor.createModel(i,l),A=j.editor.createDiffEditor(Q.current,{automaticLayout:!0,theme:Fe(d),renderSideBySide:!S&&M,originalEditable:R,readOnly:!K});A.setModel({original:x,modified:T}),J.current=A,w(!1),R&&x.onDidChangeContent(()=>{z==null||z(x.getValue())}),K&&T.onDidChangeContent(()=>{g==null||g(T.getValue())})}).catch(j=>{b&&(X(j.message??"Failed to load diff editor"),w(!1))}),()=>{var j;b=!1,(j=J.current)==null||j.dispose()}},[]),a.useEffect(()=>{const b=J.current;if(!b)return;const j=b.getModel();j&&(j.original.getValue()!==t&&j.original.setValue(t),j.modified.getValue()!==i&&j.modified.setValue(i))},[t,i]),a.useEffect(()=>{var A,O;const b=h.current;if(!b||(b.editor.setTheme(Fe(d)),d!=="auto"||typeof document>"u"))return;const j=()=>{var v;(v=h.current)==null||v.editor.setTheme(Fe("auto"))},x=new MutationObserver(j);x.observe(document.documentElement,{attributes:!0,attributeFilter:["data-theme","class"]});const T=(A=window.matchMedia)==null?void 0:A.call(window,"(prefers-color-scheme: dark)");return(O=T==null?void 0:T.addEventListener)==null||O.call(T,"change",j),()=>{var v;x.disconnect(),(v=T==null?void 0:T.removeEventListener)==null||v.call(T,"change",j)}},[d,L]),E?e.jsx("div",{className:`nice-code-diff-editor nice-code-diff-editor--error ${W??""}`,style:{height:f,width:_},"data-testid":ne,children:e.jsx("div",{className:"nice-code-editor__error",children:e.jsxs("span",{children:["⚠️ ",E]})})}):e.jsxs("div",{className:`nice-code-diff-editor ${W??""}`,style:{height:f,width:_,position:"relative"},"data-testid":ne,children:[e.jsx("div",{ref:Q,style:{position:"absolute",inset:0}}),L&&e.jsx("div",{style:{position:"absolute",inset:0,display:"flex",alignItems:"center",justifyContent:"center",background:"var(--nice-bg-primary, #fff)",zIndex:2},children:C??e.jsx("div",{className:"nice-code-editor__loader",children:"Loading diff editor..."})})]})}const ra="1.29.0",It=`https://cdn.jsdelivr.net/npm/prismjs@${ra}`;let gt=null;const yt={javascript:"javascript",typescript:"typescript",json:"json",html:"markup",css:"css",scss:"scss",less:"less",markdown:"markdown",xml:"markup",yaml:"yaml",sql:"sql",python:"python",csharp:"csharp",java:"java",cpp:"cpp",c:"c",go:"go",rust:"rust",php:"php",ruby:"ruby",shell:"bash",powershell:"powershell",plaintext:"plain"};function st(n){return new Promise((t,i)=>{if(document.querySelector(`script[data-prism-src="${n}"]`)){t();return}const l=document.createElement("script");l.src=n,l.async=!0,l.dataset.prismSrc=n,l.onload=()=>t(),l.onerror=()=>i(new Error(`Failed to load ${n}`)),document.head.appendChild(l)})}function la(n){if(typeof window>"u")return Promise.resolve(null);const t=window,i=yt[n]??"plain",l=async()=>{var d,f;if(i!=="plain"&&!((f=(d=t.Prism)==null?void 0:d.languages)!=null&&f[i]))try{await st(`${It}/components/prism-${i}.min.js`)}catch{}};return t.Prism?l().then(()=>t.Prism):(gt||(gt=(async()=>(window.Prism={manual:!0},await st(`${It}/prism.min.js`),window.Prism))()),gt.then(async()=>(await l(),window.Prism)))}function ft(n){return n.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function hn(n){const{value:t,onChange:i,language:l="plaintext",height:d=300,width:f="100%",readOnly:_=!1,tabSize:S=2,lineNumbers:M=!0,placeholder:R,theme:K="auto",className:z,"data-testid":g}=n,C=a.useRef(null),W=a.useRef(null),[ne,Q]=a.useState(()=>ft(t)),[J,h]=a.useState("light");a.useEffect(()=>{var A,O;const b=()=>{var c;if(K!=="auto")return K;if(typeof document>"u")return"light";const v=document.documentElement.dataset.theme;return v==="dark"?"dark":v==="light"?"light":(c=window.matchMedia)!=null&&c.call(window,"(prefers-color-scheme: dark)").matches?"dark":"light"};if(h(b()),K!=="auto"||typeof document>"u")return;const j=()=>h(b()),x=new MutationObserver(j);x.observe(document.documentElement,{attributes:!0,attributeFilter:["data-theme","class"]});const T=(A=window.matchMedia)==null?void 0:A.call(window,"(prefers-color-scheme: dark)");return(O=T==null?void 0:T.addEventListener)==null||O.call(T,"change",j),()=>{var v;x.disconnect(),(v=T==null?void 0:T.removeEventListener)==null||v.call(T,"change",j)}},[K]),a.useEffect(()=>{let b=!0;return la(l).then(j=>{var T;if(!b)return;const x=yt[l]??"plain";if((T=j==null?void 0:j.languages)!=null&&T[x])try{const A=j.highlight(t,j.languages[x],x);Q(A);return}catch{}Q(ft(t))}).catch(()=>{b&&Q(ft(t))}),()=>{b=!1}},[t,l]);const L=a.useCallback(()=>{!W.current||!C.current||(W.current.scrollTop=C.current.scrollTop,W.current.scrollLeft=C.current.scrollLeft)},[]),w=a.useCallback(b=>{var j;if(b.key==="Tab"){b.preventDefault();const x=b.currentTarget,T=x.selectionStart,A=x.selectionEnd,O=" ".repeat(S);if(b.shiftKey){const v=t.substring(0,T).lastIndexOf(`
13
+ `)+1;if((((j=t.substring(v,T).match(/^(\s*)/))==null?void 0:j[1])??"").length>=S){const c=t.substring(0,v)+t.substring(v+S);i==null||i(c),setTimeout(()=>{x.selectionStart=x.selectionEnd=T-S},0)}}else{const v=t.substring(0,T)+O+t.substring(A);i==null||i(v),setTimeout(()=>{x.selectionStart=x.selectionEnd=T+S},0)}}},[t,i,S]),E=t.split(`
14
+ `).length,X=yt[l]??"plain";return e.jsxs("div",{className:`nice-simple-code-editor nice-simple-code-editor--${J} ${z??""}`,style:{height:d,width:f},"data-testid":g,"data-language":l,"data-theme":J,children:[M&&e.jsx("div",{className:"nice-simple-code-editor__line-numbers",children:Array.from({length:E},(b,j)=>e.jsx("div",{className:"nice-simple-code-editor__line-number",children:j+1},j))}),e.jsxs("div",{className:"nice-simple-code-editor__editor-area",children:[e.jsx("pre",{ref:W,"aria-hidden":"true",className:`nice-simple-code-editor__highlight language-${X}`,children:e.jsx("code",{className:`language-${X}`,dangerouslySetInnerHTML:{__html:ne+(t.endsWith(`
15
+ `)?`
16
+ `:"")}})}),e.jsx("textarea",{ref:C,className:"nice-simple-code-editor__textarea",value:t,onChange:b=>i==null?void 0:i(b.target.value),onKeyDown:w,onScroll:L,readOnly:_,placeholder:R,spellCheck:!1,autoCapitalize:"off",autoCorrect:"off"})]})]})}const zt="nice-code-editor-styles";if(typeof document<"u"&&!document.getElementById(zt)){const n=document.createElement("style");n.id=zt,n.textContent=`
17
+ .nice-code-editor,
18
+ .nice-code-diff-editor {
19
+ border: 1px solid var(--nice-border, #e0e0e0);
20
+ border-radius: var(--nice-radius-sm, 4px);
21
+ overflow: hidden;
22
+ }
23
+
24
+ .nice-code-editor--loading,
25
+ .nice-code-editor--error,
26
+ .nice-code-diff-editor--loading {
27
+ display: flex;
28
+ align-items: center;
29
+ justify-content: center;
30
+ background: var(--nice-bg-muted, #f5f5f5);
31
+ }
32
+
33
+ .nice-code-editor__loader {
34
+ color: var(--nice-text-secondary, #666);
35
+ font-size: 14px;
36
+ }
37
+
38
+ .nice-code-editor__error {
39
+ display: flex;
40
+ flex-direction: column;
41
+ width: 100%;
42
+ height: 100%;
43
+ padding: var(--nice-space-2, 8px);
44
+ gap: var(--nice-space-2, 8px);
45
+ }
46
+
47
+ .nice-code-editor__error span {
48
+ color: var(--nice-error, #d32f2f);
49
+ }
50
+
51
+ /* Simple code editor */
52
+ .nice-simple-code-editor {
53
+ display: flex;
54
+ border: 1px solid var(--border-color, var(--nice-border, #e0e0e0));
55
+ border-radius: var(--nice-radius-sm, 4px);
56
+ overflow: hidden;
57
+ font-family: 'Fira Code', 'Consolas', 'Monaco', monospace;
58
+ font-size: 14px;
59
+ line-height: 1.5;
60
+ background: var(--bg-primary, var(--nice-bg-surface, #fff));
61
+ color: var(--text-primary, var(--nice-text-primary, #333));
62
+ }
63
+ .nice-simple-code-editor--dark {
64
+ background: var(--nice-bg, #1e1e1e);
65
+ color: var(--nice-text, #d4d4d4);
66
+ }
67
+
68
+ .nice-simple-code-editor__line-numbers {
69
+ padding: var(--nice-space-2, 8px) 0;
70
+ background: var(--bg-secondary, var(--nice-bg-muted, #f5f5f5));
71
+ border-right: 1px solid var(--border-color, var(--nice-border, #e0e0e0));
72
+ user-select: none;
73
+ text-align: right;
74
+ color: var(--text-secondary, var(--nice-text-secondary, #999));
75
+ overflow: hidden;
76
+ }
77
+ .nice-simple-code-editor--dark .nice-simple-code-editor__line-numbers {
78
+ background: var(--nice-bg-secondary, #252526);
79
+ border-right-color: var(--nice-border, #3c3c3c);
80
+ color: var(--nice-text-muted, #858585);
81
+ }
82
+
83
+ .nice-simple-code-editor__line-number {
84
+ padding: 0 var(--nice-space-3, 12px);
85
+ min-width: 40px;
86
+ }
87
+
88
+ .nice-simple-code-editor__editor-area {
89
+ position: relative;
90
+ flex: 1;
91
+ overflow: hidden;
92
+ }
93
+
94
+ .nice-simple-code-editor__highlight,
95
+ .nice-simple-code-editor__textarea {
96
+ position: absolute;
97
+ inset: 0;
98
+ margin: 0;
99
+ padding: var(--nice-space-2, 8px) var(--nice-space-3, 12px);
100
+ border: 0;
101
+ font: inherit;
102
+ line-height: inherit;
103
+ white-space: pre;
104
+ overflow: auto;
105
+ tab-size: 2;
106
+ }
107
+
108
+ .nice-simple-code-editor__highlight {
109
+ pointer-events: none;
110
+ background: transparent;
111
+ color: inherit;
112
+ }
113
+ .nice-simple-code-editor__highlight code {
114
+ font: inherit;
115
+ background: transparent;
116
+ }
117
+
118
+ .nice-simple-code-editor__textarea {
119
+ background: transparent;
120
+ color: transparent;
121
+ caret-color: var(--text-primary, var(--nice-text-primary, #333));
122
+ resize: none;
123
+ outline: none;
124
+ -webkit-text-fill-color: transparent;
125
+ }
126
+ .nice-simple-code-editor--dark .nice-simple-code-editor__textarea {
127
+ caret-color: var(--nice-text, #d4d4d4);
128
+ }
129
+
130
+ .nice-simple-code-editor__textarea::placeholder {
131
+ color: var(--text-secondary, var(--nice-text-secondary, #999));
132
+ -webkit-text-fill-color: var(--text-secondary, var(--nice-text-secondary, #999));
133
+ }
134
+ .nice-simple-code-editor--dark .nice-simple-code-editor__textarea::placeholder {
135
+ color: var(--nice-text-muted, #858585);
136
+ -webkit-text-fill-color: var(--nice-text-muted, #858585);
137
+ }
138
+
139
+ /* Prism token colors — light */
140
+ .nice-simple-code-editor .token.comment,
141
+ .nice-simple-code-editor .token.prolog,
142
+ .nice-simple-code-editor .token.doctype,
143
+ .nice-simple-code-editor .token.cdata { color: #6a737d; font-style: italic; }
144
+ .nice-simple-code-editor .token.punctuation { color: #586069; }
145
+ .nice-simple-code-editor .token.property,
146
+ .nice-simple-code-editor .token.tag,
147
+ .nice-simple-code-editor .token.boolean,
148
+ .nice-simple-code-editor .token.number,
149
+ .nice-simple-code-editor .token.constant,
150
+ .nice-simple-code-editor .token.symbol,
151
+ .nice-simple-code-editor .token.deleted { color: #005cc5; }
152
+ .nice-simple-code-editor .token.selector,
153
+ .nice-simple-code-editor .token.attr-name,
154
+ .nice-simple-code-editor .token.string,
155
+ .nice-simple-code-editor .token.char,
156
+ .nice-simple-code-editor .token.builtin,
157
+ .nice-simple-code-editor .token.inserted { color: #032f62; }
158
+ .nice-simple-code-editor .token.operator,
159
+ .nice-simple-code-editor .token.entity,
160
+ .nice-simple-code-editor .token.url,
161
+ .nice-simple-code-editor .token.variable { color: var(--nice-danger, #d73a49); }
162
+ .nice-simple-code-editor .token.atrule,
163
+ .nice-simple-code-editor .token.attr-value,
164
+ .nice-simple-code-editor .token.keyword { color: var(--nice-danger, #d73a49); font-weight: 600; }
165
+ .nice-simple-code-editor .token.function,
166
+ .nice-simple-code-editor .token.class-name { color: #6f42c1; }
167
+ .nice-simple-code-editor .token.regex,
168
+ .nice-simple-code-editor .token.important { color: #e36209; }
169
+
170
+ /* Prism token colors — dark */
171
+ .nice-simple-code-editor--dark .token.comment,
172
+ .nice-simple-code-editor--dark .token.prolog,
173
+ .nice-simple-code-editor--dark .token.doctype,
174
+ .nice-simple-code-editor--dark .token.cdata { color: var(--nice-success, #6a9955); font-style: italic; }
175
+ .nice-simple-code-editor--dark .token.punctuation { color: var(--nice-text, #d4d4d4); }
176
+ .nice-simple-code-editor--dark .token.property,
177
+ .nice-simple-code-editor--dark .token.tag,
178
+ .nice-simple-code-editor--dark .token.boolean,
179
+ .nice-simple-code-editor--dark .token.number,
180
+ .nice-simple-code-editor--dark .token.constant,
181
+ .nice-simple-code-editor--dark .token.symbol,
182
+ .nice-simple-code-editor--dark .token.deleted { color: var(--nice-success-light, #b5cea8); }
183
+ .nice-simple-code-editor--dark .token.selector,
184
+ .nice-simple-code-editor--dark .token.attr-name,
185
+ .nice-simple-code-editor--dark .token.string,
186
+ .nice-simple-code-editor--dark .token.char,
187
+ .nice-simple-code-editor--dark .token.builtin,
188
+ .nice-simple-code-editor--dark .token.inserted { color: var(--nice-warning, #ce9178); }
189
+ .nice-simple-code-editor--dark .token.operator,
190
+ .nice-simple-code-editor--dark .token.entity,
191
+ .nice-simple-code-editor--dark .token.url,
192
+ .nice-simple-code-editor--dark .token.variable { color: var(--nice-primary, #569cd6); }
193
+ .nice-simple-code-editor--dark .token.atrule,
194
+ .nice-simple-code-editor--dark .token.attr-value,
195
+ .nice-simple-code-editor--dark .token.keyword { color: #c586c0; font-weight: 600; }
196
+ .nice-simple-code-editor--dark .token.function,
197
+ .nice-simple-code-editor--dark .token.class-name { color: #dcdcaa; }
198
+ .nice-simple-code-editor--dark .token.regex,
199
+ .nice-simple-code-editor--dark .token.important { color: #d7ba7d; }
200
+
201
+ /* Toolbar */
202
+ .nice-code-editor-wrap {
203
+ border: 1px solid var(--nice-border, #e0e0e0);
204
+ border-radius: var(--nice-radius-sm, 4px);
205
+ overflow: hidden;
206
+ }
207
+ .nice-code-editor-wrap .nice-code-editor {
208
+ border: none;
209
+ border-radius: 0;
210
+ }
211
+ .nice-code-editor__toolbar {
212
+ display: flex;
213
+ align-items: center;
214
+ gap: var(--nice-space-0-5, 2px);
215
+ padding: var(--nice-space-0-75, 3px) var(--nice-space-1-5, 6px);
216
+ background: var(--nice-bg-muted, #f5f5f5);
217
+ border-bottom: 1px solid var(--nice-border, #e0e0e0);
218
+ }
219
+ .nice-code-editor__toolbar-btn {
220
+ display: inline-flex;
221
+ align-items: center;
222
+ justify-content: center;
223
+ width: 26px;
224
+ height: 26px;
225
+ border: none;
226
+ border-radius: var(--nice-radius-sm, 3px);
227
+ background: transparent;
228
+ color: var(--nice-text-secondary, #666);
229
+ cursor: pointer;
230
+ font-size: 14px;
231
+ transition: background 0.15s, color 0.15s;
232
+ }
233
+ .nice-code-editor__toolbar-btn:hover {
234
+ background: var(--nice-hover, #e0e0e0);
235
+ color: var(--nice-text-primary, #333);
236
+ }
237
+ .nice-code-editor__toolbar-btn--active {
238
+ background: var(--nice-accent, #1976d2);
239
+ color: var(--nice-bg, #FFF);
240
+ }
241
+ .nice-code-editor__toolbar-sep {
242
+ width: 1px;
243
+ height: 18px;
244
+ background: var(--nice-border, #e0e0e0);
245
+ margin: 0 var(--nice-space-1, 4px);
246
+ }
247
+
248
+ /* Status bar */
249
+ .nice-code-editor__statusbar {
250
+ display: flex;
251
+ align-items: center;
252
+ gap: var(--nice-space-3, 12px);
253
+ padding: var(--nice-space-0-5, 2px) var(--nice-space-2-5, 10px);
254
+ background: var(--nice-bg-muted, #f5f5f5);
255
+ border-top: 1px solid var(--nice-border, #e0e0e0);
256
+ font-size: 12px;
257
+ color: var(--nice-text-secondary, #666);
258
+ user-select: none;
259
+ }
260
+ .nice-code-editor__statusbar-spacer { flex: 1; }
261
+ .nice-code-editor__statusbar-lang {
262
+ text-transform: uppercase;
263
+ font-weight: 600;
264
+ font-size: 11px;
265
+ }
266
+ .nice-code-editor__statusbar-markers {
267
+ color: var(--nice-warning, #f39c12);
268
+ font-weight: 600;
269
+ }
270
+ `,document.head.appendChild(n)}const sa=Object.freeze(Object.defineProperty({__proto__:null,NiceCodeDiffEditor:pn,NiceCodeEditor:Ct,NiceSimpleCodeEditor:hn},Symbol.toStringTag,{value:"Module"}));a.forwardRef(function(n,t){const{enableAI:i=!0,aiModel:l,enableInlineCompletion:d=!0,completionDelay:f=500,enableExplain:_=!0,enableRefactor:S=!0,enableGenerate:M=!0,systemPrompt:R,onExplain:K,onRefactor:z,showAIToolbar:g=!0,aiShortcutKey:C="Ctrl",language:W="plaintext",value:ne,onChange:Q,...J}=n,h=a.useRef(null),[L,w]=a.useState(null),[E,X]=a.useState(!1),[b,j]=a.useState(""),[x,T]=a.useState(!1),[A,O]=a.useState(""),[v,c]=a.useState(""),[P,y]=a.useState(""),k=a.useRef(),{t:s}=I.ue(),o=I.me(),{complete:u,explain:r,refactor:p,generateFromComment:q,isLoading:F}=I.Dd({language:W,model:l}),G=i&&o.isConfigured,ie=a.useCallback(async()=>{if(!G||!d||!h.current||!h.current.getEditor())return;const ae=h.current.getCursorPosition(),oe=h.current.getValue().split(`
271
+ `),ce=oe.slice(0,ae.lineNumber-1),me=oe[ae.lineNumber-1]||"",le=[...ce,me.slice(0,ae.column-1)].join(`
272
+ `),$=[me.slice(ae.column-1),...oe.slice(ae.lineNumber)].join(`
273
+ `);try{const D=await u(le,$);D&&w({lineNumber:ae.lineNumber,column:ae.column,text:D})}catch{}},[G,d,u]),N=a.useCallback(async()=>{if(!G||!_||!h.current)return"";const ae=h.current.getSelection();if(!ae)return"";y(ae),X(!0),j("");try{const oe=await r(ae);return j(oe),K==null||K(ae,oe),oe}catch{return j(s("codeEditorAI.explanationFailed","Failed to explain code")),""}},[G,_,r,K,s]),H=a.useCallback(async ae=>{if(!G||!S||!h.current)return"";const oe=h.current.getSelection();if(!oe)return"";try{const ce=await p(oe,ae);return c(ce),z==null||z(oe,ce),ce}catch{return""}},[G,S,p,z]),B=a.useCallback(async()=>{var me;if(!G||!M||!h.current)return;const ae=h.current.getCursorPosition(),oe=h.current.getValue().split(`
274
+ `);let ce="";for(let le=ae.lineNumber-1;le>=0&&le>=ae.lineNumber-3;le--){const $=((me=oe[le])==null?void 0:me.trim())||"";if($.startsWith("//")||$.startsWith("#")||$.startsWith("/*")||$.startsWith("*")){ce=$.replace(/^\/\/\s*|^#\s*|^\/\*\s*|\*\/\s*$|^\*\s*/g,"").trim();break}}if(ce)try{const le=await q(ce);le&&h.current&&h.current.insertText(`
275
+ `+le)}catch{}},[G,M,q]),se=a.useCallback(()=>{!L||!h.current||(h.current.insertText(L.text),w(null))},[L]),de=a.useCallback(()=>{w(null)},[]),he=a.useCallback(ae=>{var oe;(oe=n.onCursorPositionChange)==null||oe.call(n,ae),!(!G||!d)&&(k.current&&clearTimeout(k.current),w(null),k.current=setTimeout(()=>{ie()},f))},[n.onCursorPositionChange,G,d,f,ie]);a.useEffect(()=>{var oe;if(!((oe=h.current)!=null&&oe.getEditor())||!G)return;const ae=ce=>{var me;if(C==="Ctrl"&&ce.ctrlKey||C==="Alt"&&ce.altKey||C==="Meta"&&ce.metaKey){if(ce.key===" "&&d&&(ce.preventDefault(),ie()),ce.key==="e"&&_&&(ce.preventDefault(),N()),ce.key==="r"&&S){ce.preventDefault();const le=(me=h.current)==null?void 0:me.getSelection();le&&(y(le),T(!0))}ce.key==="g"&&M&&(ce.preventDefault(),B())}ce.key==="Tab"&&L&&(ce.preventDefault(),se()),ce.key==="Escape"&&L&&de()};return window.addEventListener("keydown",ae),()=>window.removeEventListener("keydown",ae)},[G,C,d,_,S,M,ie,N,B,L,se,de]),a.useEffect(()=>()=>{k.current&&clearTimeout(k.current)},[]);const be=a.useCallback(()=>{if(!v||!h.current)return;const ae=h.current.getEditor();if(ae!=null&&ae.executeEdits&&(ae!=null&&ae.getSelection)){const oe=ae.getSelection();ae.executeEdits("ai-refactor",[{range:oe,text:v}])}T(!1),c(""),O("")},[v]);return a.useImperativeHandle(t,()=>({...h.current,getEditor:()=>{var ae;return(ae=h.current)==null?void 0:ae.getEditor()},getMonaco:()=>{var ae;return(ae=h.current)==null?void 0:ae.getMonaco()},focus:()=>{var ae;return(ae=h.current)==null?void 0:ae.focus()},getValue:()=>{var ae;return((ae=h.current)==null?void 0:ae.getValue())||""},setValue:ae=>{var oe;return(oe=h.current)==null?void 0:oe.setValue(ae)},getSelection:()=>{var ae;return((ae=h.current)==null?void 0:ae.getSelection())||""},insertText:ae=>{var oe;return(oe=h.current)==null?void 0:oe.insertText(ae)},formatDocument:()=>{var ae;return(ae=h.current)==null?void 0:ae.formatDocument()},goToLine:(ae,oe)=>{var ce;return(ce=h.current)==null?void 0:ce.goToLine(ae,oe)},findReplace:()=>{var ae;return(ae=h.current)==null?void 0:ae.findReplace()},undo:()=>{var ae;return(ae=h.current)==null?void 0:ae.undo()},redo:()=>{var ae;return(ae=h.current)==null?void 0:ae.redo()},getCursorPosition:()=>{var ae;return((ae=h.current)==null?void 0:ae.getCursorPosition())||{lineNumber:1,column:1}},setMarkers:ae=>{var oe;return(oe=h.current)==null?void 0:oe.setMarkers(ae)},triggerCompletion:ie,explainSelection:N,refactorSelection:H,generateFromComment:B,acceptCompletion:se,dismissCompletion:de})),e.jsxs("div",{className:"nice-code-editor-ai","data-testid":n["data-testid"],children:[g&&G&&e.jsxs("div",{className:"nice-code-editor-ai__toolbar",children:[e.jsxs("div",{className:"nice-code-editor-ai__toolbar-left",children:[e.jsx("span",{className:"nice-code-editor-ai__toolbar-badge",children:"AI"}),F&&e.jsx("span",{className:"nice-code-editor-ai__loading",children:s("codeEditorAI.loading","Thinking...")})]}),e.jsxs("div",{className:"nice-code-editor-ai__toolbar-right",children:[d&&e.jsxs("button",{type:"button",className:"nice-code-editor-ai__toolbar-btn",onClick:()=>ie(),disabled:F,title:`${s("codeEditorAI.complete","Complete")} (${C}+Space)`,children:["💡 ",s("codeEditorAI.complete","Complete")]}),_&&e.jsxs("button",{type:"button",className:"nice-code-editor-ai__toolbar-btn",onClick:()=>N(),disabled:F,title:`${s("codeEditorAI.explain","Explain")} (${C}+E)`,children:["📖 ",s("codeEditorAI.explain","Explain")]}),S&&e.jsxs("button",{type:"button",className:"nice-code-editor-ai__toolbar-btn",onClick:()=>{var oe;const ae=(oe=h.current)==null?void 0:oe.getSelection();ae&&(y(ae),T(!0))},disabled:F,title:`${s("codeEditorAI.refactor","Refactor")} (${C}+R)`,children:["🔧 ",s("codeEditorAI.refactor","Refactor")]}),M&&e.jsxs("button",{type:"button",className:"nice-code-editor-ai__toolbar-btn",onClick:()=>B(),disabled:F,title:`${s("codeEditorAI.generate","Generate")} (${C}+G)`,children:["⚡ ",s("codeEditorAI.generate","Generate")]})]})]}),e.jsxs("div",{className:"nice-code-editor-ai__editor-wrapper",children:[e.jsx(Ct,{ref:h,value:ne,onChange:Q,language:W,onCursorPositionChange:he,...J}),L&&e.jsxs("div",{className:"nice-code-editor-ai__ghost-text",style:{top:`calc(${(L.lineNumber-1)*19}px + 4px)`,left:`calc(${(L.column-1)*7.8}px + 60px)`},children:[e.jsx("span",{className:"nice-code-editor-ai__ghost-text-content",children:L.text}),e.jsxs("span",{className:"nice-code-editor-ai__ghost-text-hint",children:["Tab ",s("codeEditorAI.toAccept","to accept")]})]})]}),E&&e.jsxs("div",{className:"nice-code-editor-ai__panel nice-code-editor-ai__panel--explain",children:[e.jsxs("div",{className:"nice-code-editor-ai__panel-header",children:[e.jsxs("h4",{children:["📖 ",s("codeEditorAI.explanation","Explanation")]}),e.jsx("button",{type:"button",className:"nice-code-editor-ai__panel-close",onClick:()=>X(!1),children:"✕"})]}),e.jsx("div",{className:"nice-code-editor-ai__panel-body",children:F?e.jsx("div",{className:"nice-code-editor-ai__panel-loading",children:s("codeEditorAI.analyzing","Analyzing code...")}):e.jsxs("div",{className:"nice-code-editor-ai__explanation",children:[e.jsx("pre",{className:"nice-code-editor-ai__code-preview",children:P}),e.jsx("div",{className:"nice-code-editor-ai__explanation-text",children:b||s("codeEditorAI.noExplanation","Select code and click Explain")})]})})]}),x&&e.jsxs("div",{className:"nice-code-editor-ai__panel nice-code-editor-ai__panel--refactor",children:[e.jsxs("div",{className:"nice-code-editor-ai__panel-header",children:[e.jsxs("h4",{children:["🔧 ",s("codeEditorAI.refactorCode","Refactor Code")]}),e.jsx("button",{type:"button",className:"nice-code-editor-ai__panel-close",onClick:()=>{T(!1),c(""),O("")},children:"✕"})]}),e.jsxs("div",{className:"nice-code-editor-ai__panel-body",children:[e.jsx("pre",{className:"nice-code-editor-ai__code-preview",children:P}),e.jsxs("div",{className:"nice-code-editor-ai__refactor-input",children:[e.jsx("input",{type:"text",placeholder:s("codeEditorAI.refactorInstruction",'Describe how to refactor (e.g., "extract function", "add error handling")'),value:A,onChange:ae=>O(ae.target.value),onKeyDown:ae=>{ae.key==="Enter"&&A&&H(A)}}),e.jsx("button",{type:"button",className:"nice-code-editor-ai__refactor-btn",onClick:()=>H(A),disabled:F||!A,children:F?s("codeEditorAI.refactoring","Refactoring..."):s("codeEditorAI.refactor","Refactor")})]}),v&&e.jsxs("div",{className:"nice-code-editor-ai__refactor-result",children:[e.jsx("h5",{children:s("codeEditorAI.refactoredCode","Refactored Code")}),e.jsx("pre",{className:"nice-code-editor-ai__code-preview nice-code-editor-ai__code-preview--result",children:v}),e.jsxs("div",{className:"nice-code-editor-ai__refactor-actions",children:[e.jsxs("button",{type:"button",className:"nice-code-editor-ai__refactor-apply",onClick:be,children:["✓ ",s("codeEditorAI.apply","Apply")]}),e.jsxs("button",{type:"button",className:"nice-code-editor-ai__refactor-discard",onClick:()=>{c(""),O("")},children:["✕ ",s("codeEditorAI.discard","Discard")]})]})]})]})]})]})});function Ht(n,t){const i=t.getBoundingClientRect();let l,d,f;if("touches"in n){const _=n.touches[0];l=_.clientX-i.left,d=_.clientY-i.top,f=_.force}else"pressure"in n?(l=n.clientX-i.left,d=n.clientY-i.top,f=n.pressure):(l=n.clientX-i.left,d=n.clientY-i.top);return{x:l,y:d,time:Date.now(),pressure:f!==void 0?f:.5}}function Ot(n,t,i,l,d){if(!t)return(i+l)/2;const f=Math.sqrt(Math.pow(n.x-t.x,2)+Math.pow(n.y-t.y,2))/Math.max(1,n.time-t.time),_=Math.min(f/5,1),S=l-_*(l-i),M=n.pressure??.5,R=i+M*(l-i);return S*.7+R*.3}function Wt(n,t,i,l){n.beginPath(),n.moveTo(t.x,t.y),n.lineTo(i.x,i.y),n.lineWidth=l,n.lineCap="round",n.lineJoin="round",n.stroke()}a.forwardRef(function(n,t){const{value:i,onChange:l,width:d="100%",height:f=200,penColor:_="var(--text-primary, #000000)",penWidth:S=2,minWidth:M=.5,maxWidth:R=4,backgroundColor:K="var(--bg-primary, #ffffff)",placeholder:z="Sign here",showClearButton:g=!0,showUndoButton:C=!0,showColorPicker:W=!1,showSizeSlider:ne=!1,velocityFilterWeight:Q=.7,throttle:J=16,disabled:h=!1,readOnly:L=!1,displayMode:w=!1,onBegin:E,onEnd:X,className:b,"data-testid":j}=n,x=L||w,T=w?!1:g,A=w?!1:C,O=w?!1:W,v=w?!1:ne,c=a.useRef(null),[P,y]=a.useState((i==null?void 0:i.strokes)??[]),[k,s]=a.useState([]),[o,u]=a.useState(!1),[r,p]=a.useState(_),[q,F]=a.useState(S),G=a.useRef(null),ie=a.useRef(0),N=P.length===0&&k.length===0;a.useEffect(()=>{const le=c.current;if(!le)return;const $=le.getContext("2d");if(!$)return;const D=le.getBoundingClientRect(),Y=window.devicePixelRatio||1;le.width=D.width*Y,le.height=D.height*Y,$.scale(Y,Y),H()},[d,f]);const H=a.useCallback(()=>{const le=c.current;if(!le)return;const $=le.getContext("2d");if(!$)return;const D=le.getBoundingClientRect();$.fillStyle=K,$.fillRect(0,0,D.width,D.height),P.forEach(Y=>{if($.strokeStyle=Y.color,!(Y.points.length<2))for(let pe=1;pe<Y.points.length;pe++){const Z=Y.points[pe-1],U=Y.points[pe],re=Ot(U,Z,M,R);Wt($,Z,U,re)}})},[P,K,M,R,Q]);a.useEffect(()=>{H()},[H]),a.useEffect(()=>{i!=null&&i.strokes&&y(i.strokes)},[i]),a.useEffect(()=>{const le=c.current;if(le)if(P.length===0)l==null||l(null);else{const $=le.getBoundingClientRect();l==null||l({strokes:P,width:$.width,height:$.height,timestamp:Date.now()})}},[P,l]);const B=a.useCallback(le=>{if(h||x)return;const $=c.current;if(!$)return;$.setPointerCapture(le.pointerId);const D=Ht(le.nativeEvent,$);u(!0),s([D]),G.current=D,ie.current=D.time,E==null||E()},[h,x,E]),se=a.useCallback(le=>{if(!o||h||x)return;const $=c.current;if(!$)return;const D=$.getContext("2d");if(!D)return;const Y=Date.now();if(Y-ie.current<J)return;const pe=Ht(le.nativeEvent,$),Z=G.current;if(Z){D.strokeStyle=r;const U=Ot(pe,Z,M,R);Wt(D,Z,pe,U)}s(U=>[...U,pe]),G.current=pe,ie.current=Y},[o,h,x,r,M,R,Q,J]),de=a.useCallback(le=>{if(!o)return;const $=c.current;if($&&$.releasePointerCapture(le.pointerId),k.length>0){const D={points:k,color:r,width:q};y(Y=>[...Y,D])}u(!1),s([]),G.current=null,X==null||X()},[o,k,r,q,X]),he=a.useCallback(()=>{y([]),s([]),H()},[H]),be=a.useCallback(()=>{y(le=>le.slice(0,-1))},[]),ae=a.useCallback((le="png",$=.92)=>{const D=c.current;if(!D)return"";const Y=le==="jpeg"?"image/jpeg":"image/png";return D.toDataURL(Y,$)},[]),oe=a.useCallback(async(le="png",$=.92)=>{const D=c.current;return D?new Promise(Y=>{const pe=le==="jpeg"?"image/jpeg":"image/png";D.toBlob(Z=>Y(Z),pe,$)}):null},[]),ce=a.useCallback(()=>{const le=c.current;if(!le)return"";const $=le.getBoundingClientRect(),D=P.map(Y=>Y.points.length<2?"":`<path d="${Y.points.reduce((pe,Z,U)=>U===0?`M ${Z.x} ${Z.y}`:`${pe} L ${Z.x} ${Z.y}`,"")}" stroke="${Y.color}" stroke-width="${Y.width}" fill="none" stroke-linecap="round" stroke-linejoin="round"/>`).join(`
276
+ `);return`<svg xmlns="http://www.w3.org/2000/svg" width="${$.width}" height="${$.height}" viewBox="0 0 ${le.width} ${le.height}">
277
+ <rect width="100%" height="100%" fill="${K}"/>
278
+ ${D}
279
+ </svg>`},[P,K]);a.useImperativeHandle(t,()=>({clear:he,undo:be,isEmpty:()=>P.length===0,getData:()=>{const le=c.current;if(!le||P.length===0)return null;const $=le.getBoundingClientRect();return{strokes:P,width:$.width,height:$.height,timestamp:Date.now()}},setData:le=>{y(le.strokes)},toDataURL:ae,toBlob:oe,toSVG:ce,getCanvas:()=>c.current}),[P,he,be,ae,oe,ce]),a.useEffect(()=>{const le=c.current;if(!le)return;const $=D=>{o&&D.preventDefault()};return le.addEventListener("touchmove",$,{passive:!1}),()=>le.removeEventListener("touchmove",$)},[o]);const me=T||A||O||v;return e.jsxs("div",{className:`nice-signature ${h?"nice-signature--disabled":""} ${x?"nice-signature--readonly":""} ${b??""}`,style:{width:d},"data-testid":j,children:[me&&e.jsxs("div",{className:"nice-signature__toolbar",children:[O&&e.jsx("div",{className:"nice-signature__color-picker",children:e.jsx("input",{type:"color",value:r,onChange:le=>p(le.target.value),disabled:h||x,title:"Pen color"})}),v&&e.jsx("div",{className:"nice-signature__size-slider",children:e.jsx("input",{type:"range",min:M,max:R,step:.5,value:q,onChange:le=>F(parseFloat(le.target.value)),disabled:h||x,title:"Pen size"})}),e.jsxs("div",{className:"nice-signature__actions",children:[A&&e.jsx("button",{type:"button",onClick:be,disabled:h||x||P.length===0,className:"nice-signature__btn",title:"Undo",children:"↩️"}),T&&e.jsx("button",{type:"button",onClick:he,disabled:h||x||N,className:"nice-signature__btn",title:"Clear",children:"🗑️"})]})]}),e.jsxs("div",{className:"nice-signature__canvas-wrapper",style:{height:f},children:[e.jsx("canvas",{ref:c,className:"nice-signature__canvas",style:{width:"100%",height:"100%",cursor:h||x?"not-allowed":"crosshair",touchAction:"none"},onPointerDown:B,onPointerMove:se,onPointerUp:de,onPointerLeave:de}),N&&!o&&z&&e.jsx("div",{className:"nice-signature__placeholder",children:z}),e.jsx("div",{className:"nice-signature__line"})]})]})});const Ft="nice-signature-styles";if(typeof document<"u"&&!document.getElementById(Ft)){const n=document.createElement("style");n.id=Ft,n.textContent=`
280
+ .nice-signature {
281
+ display: flex;
282
+ flex-direction: column;
283
+ border: 1px solid var(--nice-border, #e0e0e0);
284
+ border-radius: var(--nice-radius-sm, 4px);
285
+ overflow: hidden;
286
+ background: var(--nice-bg-surface, #fff);
287
+ }
288
+
289
+ .nice-signature--disabled {
290
+ opacity: 0.6;
291
+ }
292
+
293
+ .nice-signature__toolbar {
294
+ display: flex;
295
+ align-items: center;
296
+ gap: var(--nice-space-2, 8px);
297
+ padding: var(--nice-space-2, 8px);
298
+ background: var(--nice-bg-muted, #f5f5f5);
299
+ border-bottom: 1px solid var(--nice-border, #e0e0e0);
300
+ }
301
+
302
+ .nice-signature__color-picker input {
303
+ width: 32px;
304
+ height: 32px;
305
+ padding: var(--nice-space-0-5, 2px);
306
+ border: 1px solid var(--nice-border, #e0e0e0);
307
+ border-radius: var(--nice-radius-sm, 4px);
308
+ cursor: pointer;
309
+ }
310
+
311
+ .nice-signature__size-slider {
312
+ flex: 1;
313
+ max-width: 120px;
314
+ }
315
+
316
+ .nice-signature__size-slider input {
317
+ width: 100%;
318
+ }
319
+
320
+ .nice-signature__actions {
321
+ display: flex;
322
+ gap: var(--nice-space-1, 4px);
323
+ margin-left: auto;
324
+ }
325
+
326
+ .nice-signature__btn {
327
+ padding: var(--nice-space-1-5, 6px) var(--nice-space-2-5, 10px);
328
+ border: 1px solid var(--nice-border, #e0e0e0);
329
+ border-radius: var(--nice-radius-sm, 4px);
330
+ background: var(--nice-bg-surface, #fff);
331
+ cursor: pointer;
332
+ font-size: 14px;
333
+ }
334
+
335
+ .nice-signature__btn:hover:not(:disabled) {
336
+ background: var(--nice-bg-hover, #f0f0f0);
337
+ }
338
+
339
+ .nice-signature__btn:disabled {
340
+ opacity: 0.4;
341
+ cursor: not-allowed;
342
+ }
343
+
344
+ .nice-signature__canvas-wrapper {
345
+ position: relative;
346
+ background: var(--nice-bg, #FFF);
347
+ }
348
+
349
+ .nice-signature__canvas {
350
+ display: block;
351
+ }
352
+
353
+ .nice-signature__placeholder {
354
+ position: absolute;
355
+ top: 50%;
356
+ left: 50%;
357
+ transform: translate(-50%, -50%);
358
+ color: var(--nice-text-secondary, #999);
359
+ font-size: 14px;
360
+ pointer-events: none;
361
+ user-select: none;
362
+ }
363
+
364
+ .nice-signature__line {
365
+ position: absolute;
366
+ bottom: 30px;
367
+ left: 20px;
368
+ right: 20px;
369
+ height: 1px;
370
+ background: var(--nice-border, #ccc);
371
+ pointer-events: none;
372
+ }
373
+
374
+ /* Display component */
375
+ .nice-signature-display {
376
+ border: 1px solid var(--nice-border, #e0e0e0);
377
+ border-radius: var(--nice-radius-sm, 4px);
378
+ overflow: hidden;
379
+ }
380
+
381
+ .nice-signature-display__canvas-wrapper {
382
+ position: relative;
383
+ background: var(--nice-bg, #FFF);
384
+ }
385
+
386
+ .nice-signature-display__canvas {
387
+ display: block;
388
+ }
389
+
390
+ .nice-signature-display__placeholder {
391
+ position: absolute;
392
+ top: 50%;
393
+ left: 50%;
394
+ transform: translate(-50%, -50%);
395
+ color: var(--nice-text-secondary, #999);
396
+ font-size: 14px;
397
+ }
398
+ `,document.head.appendChild(n)}const oa={strokeColor:"#ff3333",fillColor:"transparent",strokeWidth:2,opacity:1,fontSize:16,fontFamily:"sans-serif"};function ca(n,t){switch(t.type){case"SET_TOOL":return{...n,activeTool:t.tool,selectedId:null};case"SET_STYLE":return{...n,style:{...n.style,...t.style}};case"ADD_ANNOTATION":return{...n,annotations:[...n.annotations,t.annotation],past:[...n.past,n.annotations],future:[]};case"UPDATE_ANNOTATION":return{...n,annotations:n.annotations.map(i=>i.id===t.id?{...i,...t.updates}:i),past:[...n.past,n.annotations],future:[]};case"DELETE_ANNOTATION":return{...n,annotations:n.annotations.filter(i=>i.id!==t.id),selectedId:n.selectedId===t.id?null:n.selectedId,past:[...n.past,n.annotations],future:[]};case"SELECT":return{...n,selectedId:t.id};case"SET_ANNOTATIONS":return{...n,annotations:t.annotations,past:[],future:[]};case"SET_ZOOM":return{...n,zoom:t.zoom};case"SET_PAN":return{...n,panX:t.panX,panY:t.panY};case"UNDO":{if(n.past.length===0)return n;const i=n.past[n.past.length-1];return{...n,annotations:i,past:n.past.slice(0,-1),future:[n.annotations,...n.future]}}case"REDO":{if(n.future.length===0)return n;const i=n.future[0];return{...n,annotations:i,past:[...n.past,n.annotations],future:n.future.slice(1)}}case"CLEAR":return{...n,annotations:[],selectedId:null,past:[...n.past,n.annotations],future:[]};default:return n}}let da=0;function ua(){return`ann-${Date.now()}-${da++}`}function pa(n){const{style:t}=n,i=`stroke="${t.strokeColor}" stroke-width="${t.strokeWidth}" fill="${t.fillColor}" opacity="${t.opacity}"`;switch(n.tool){case"rectangle":return`<rect x="${n.x}" y="${n.y}" width="${n.width}" height="${n.height}" ${i} />`;case"ellipse":{const l=n.x+n.width/2,d=n.y+n.height/2;return`<ellipse cx="${l}" cy="${d}" rx="${n.width/2}" ry="${n.height/2}" ${i} />`}case"arrow":{const l=n,d=Math.atan2(l.endY-l.y,l.endX-l.x),f=12,_=l.endX-f*Math.cos(d-Math.PI/6),S=l.endY-f*Math.sin(d-Math.PI/6),M=l.endX-f*Math.cos(d+Math.PI/6),R=l.endY-f*Math.sin(d+Math.PI/6);return`<line x1="${l.x}" y1="${l.y}" x2="${l.endX}" y2="${l.endY}" ${i} />
399
+ <polygon points="${l.endX},${l.endY} ${_},${S} ${M},${R}" fill="${t.strokeColor}" opacity="${t.opacity}" />`}case"line":{const l=n;return`<line x1="${l.x}" y1="${l.y}" x2="${l.endX}" y2="${l.endY}" ${i} />`}case"text":{const l=n;return`<text x="${l.x}" y="${l.y+(l.style.fontSize??16)}" fill="${t.strokeColor}" font-size="${t.fontSize}" font-family="${t.fontFamily}" opacity="${t.opacity}">${ha(l.text)}</text>`}case"freehand":{const l=n;return l.points.length<2?"":`<path d="${l.points.map((d,f)=>`${f===0?"M":"L"}${d.x},${d.y}`).join(" ")}" ${i} fill="none" />`}case"blur":{const l=n,d=`blur-${l.id}`;return`<defs><filter id="${d}"><feGaussianBlur stdDeviation="${l.intensity??5}" /></filter></defs>
400
+ <rect x="${l.x}" y="${l.y}" width="${l.width}" height="${l.height}" fill="transparent" stroke="none" filter="url(#${d})" />`}default:return""}}function ha(n){return n.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&apos;")}const mn=a.forwardRef(({src:n,alt:t="Annotatable image",annotations:i,activeTool:l,defaultStyle:d,onAnnotationsChange:f,className:_,readOnly:S=!1,minZoom:M=.1,maxZoom:R=5},K)=>{const z=a.useRef(null),g=a.useRef(null),C=a.useRef(null),[W,ne]=a.useState(!1),[Q,J]=a.useState({width:0,height:0}),[h,L]=a.useReducer(ca,{annotations:i??[],selectedId:null,activeTool:l??"select",style:{...oa,...d},zoom:1,panX:0,panY:0,past:[],future:[]});a.useEffect(()=>{l&&L({type:"SET_TOOL",tool:l})},[l]),a.useEffect(()=>{f==null||f(h.annotations)},[h.annotations,f]),a.useEffect(()=>{const v=new Image;v.crossOrigin="anonymous",v.onload=()=>{C.current=v,J({width:v.naturalWidth,height:v.naturalHeight}),ne(!0)},v.src=n},[n]);const w=a.useRef({isDrawing:!1,startX:0,startY:0,currentAnnotation:null,freehandPoints:[]}),E=a.useCallback((v,c)=>{const P=z.current;if(!P)return{x:0,y:0};const y=P.getBoundingClientRect();return{x:(v-y.left-h.panX)/h.zoom,y:(c-y.top-h.panY)/h.zoom}},[h.zoom,h.panX,h.panY]),X=a.useCallback(()=>{var k,s;const v=z.current,c=v==null?void 0:v.getContext("2d"),P=C.current;if(!v||!c||!P||!W)return;v.width=((k=g.current)==null?void 0:k.clientWidth)??P.naturalWidth,v.height=((s=g.current)==null?void 0:s.clientHeight)??P.naturalHeight,c.clearRect(0,0,v.width,v.height),c.save(),c.translate(h.panX,h.panY),c.scale(h.zoom,h.zoom),c.drawImage(P,0,0);for(const o of h.annotations){switch(c.save(),c.globalAlpha=o.style.opacity,c.strokeStyle=o.style.strokeColor,c.fillStyle=o.style.fillColor,c.lineWidth=o.style.strokeWidth,o.tool){case"rectangle":c.strokeRect(o.x,o.y,o.width,o.height),o.style.fillColor!=="transparent"&&c.fillRect(o.x,o.y,o.width,o.height);break;case"ellipse":{c.beginPath(),c.ellipse(o.x+o.width/2,o.y+o.height/2,Math.abs(o.width/2),Math.abs(o.height/2),0,0,Math.PI*2),c.stroke(),o.style.fillColor!=="transparent"&&c.fill();break}case"arrow":{const u=o;c.beginPath(),c.moveTo(u.x,u.y),c.lineTo(u.endX,u.endY),c.stroke();const r=Math.atan2(u.endY-u.y,u.endX-u.x),p=12;c.beginPath(),c.moveTo(u.endX,u.endY),c.lineTo(u.endX-p*Math.cos(r-Math.PI/6),u.endY-p*Math.sin(r-Math.PI/6)),c.lineTo(u.endX-p*Math.cos(r+Math.PI/6),u.endY-p*Math.sin(r+Math.PI/6)),c.closePath(),c.fillStyle=o.style.strokeColor,c.fill();break}case"line":{const u=o;c.beginPath(),c.moveTo(u.x,u.y),c.lineTo(u.endX,u.endY),c.stroke();break}case"text":{const u=o;c.font=`${u.style.fontSize??16}px ${u.style.fontFamily??"sans-serif"}`,c.fillStyle=u.style.strokeColor,c.fillText(u.text,u.x,u.y+(u.style.fontSize??16));break}case"freehand":{const u=o;if(u.points.length<2)break;c.beginPath(),c.moveTo(u.points[0].x,u.points[0].y);for(let r=1;r<u.points.length;r++)c.lineTo(u.points[r].x,u.points[r].y);c.stroke();break}case"blur":{const u=o;c.filter=`blur(${u.intensity??5}px)`,c.drawImage(P,u.x,u.y,u.width,u.height,u.x,u.y,u.width,u.height),c.filter="none";break}}o.id===h.selectedId&&(c.strokeStyle="#4488ff",c.lineWidth=1,c.setLineDash([4,4]),c.strokeRect(o.x-2,o.y-2,o.width+4,o.height+4),c.setLineDash([])),c.restore()}const y=w.current;if(y.isDrawing&&y.currentAnnotation){c.save();const o=y.currentAnnotation;if(c.globalAlpha=o.style.opacity,c.strokeStyle=o.style.strokeColor,c.lineWidth=o.style.strokeWidth,c.setLineDash([6,3]),o.tool==="freehand"){const u=o;if(u.points.length>=2){c.beginPath(),c.moveTo(u.points[0].x,u.points[0].y);for(let r=1;r<u.points.length;r++)c.lineTo(u.points[r].x,u.points[r].y);c.stroke()}}else if(o.tool==="rectangle")c.strokeRect(o.x,o.y,o.width,o.height);else if(o.tool==="ellipse")c.beginPath(),c.ellipse(o.x+o.width/2,o.y+o.height/2,Math.abs(o.width/2),Math.abs(o.height/2),0,0,Math.PI*2),c.stroke();else if(o.tool==="arrow"||o.tool==="line"){const u=o;c.beginPath(),c.moveTo(u.x,u.y),c.lineTo(u.endX,u.endY),c.stroke()}c.restore()}c.restore()},[h,W]);a.useEffect(()=>{X()},[X]);const b=a.useCallback(v=>{if(S)return;const c=E(v.clientX,v.clientY),P=h.activeTool;if(P==="select"){const s=[...h.annotations].reverse().find(o=>o.tool==="freehand"?!1:c.x>=o.x&&c.x<=o.x+o.width&&c.y>=o.y&&c.y<=o.y+o.height);L({type:"SELECT",id:(s==null?void 0:s.id)??null});return}const y=w.current;y.isDrawing=!0,y.startX=c.x,y.startY=c.y;const k={id:ua(),style:{...h.style},x:c.x,y:c.y,width:0,height:0};switch(P){case"rectangle":y.currentAnnotation={...k,tool:"rectangle"};break;case"ellipse":y.currentAnnotation={...k,tool:"ellipse"};break;case"arrow":y.currentAnnotation={...k,tool:"arrow",endX:c.x,endY:c.y};break;case"line":y.currentAnnotation={...k,tool:"line",endX:c.x,endY:c.y};break;case"text":y.currentAnnotation={...k,tool:"text",text:"Text",width:100,height:h.style.fontSize??16};break;case"freehand":y.freehandPoints=[c],y.currentAnnotation={...k,tool:"freehand",points:[c]};break;case"blur":y.currentAnnotation={...k,tool:"blur",intensity:5};break}},[S,E,h.activeTool,h.style,h.annotations]),j=a.useCallback(v=>{const c=w.current;if(!c.isDrawing||!c.currentAnnotation)return;const P=E(v.clientX,v.clientY),y=c.currentAnnotation;if(y.tool==="freehand"){c.freehandPoints.push(P),y.points=[...c.freehandPoints];const k=c.freehandPoints.map(o=>o.x),s=c.freehandPoints.map(o=>o.y);y.x=Math.min(...k),y.y=Math.min(...s),y.width=Math.max(...k)-y.x,y.height=Math.max(...s)-y.y}else if(y.tool==="arrow"||y.tool==="line")y.endX=P.x,y.endY=P.y,y.width=Math.abs(P.x-c.startX),y.height=Math.abs(P.y-c.startY);else{const k=Math.min(c.startX,P.x),s=Math.min(c.startY,P.y);y.x=k,y.y=s,y.width=Math.abs(P.x-c.startX),y.height=Math.abs(P.y-c.startY)}X()},[E,X]),x=a.useCallback(()=>{const v=w.current;if(!v.isDrawing||!v.currentAnnotation)return;const c=v.currentAnnotation;(c.tool==="text"||c.tool==="freehand"||Math.abs(c.width)>2||Math.abs(c.height)>2)&&L({type:"ADD_ANNOTATION",annotation:c}),v.isDrawing=!1,v.currentAnnotation=null,v.freehandPoints=[]},[]),T=a.useCallback(v=>{v.preventDefault();const c=v.deltaY>0?.9:1.1,P=Math.max(M,Math.min(R,h.zoom*c));L({type:"SET_ZOOM",zoom:P})},[h.zoom,M,R]);a.useEffect(()=>{if(S)return;const v=c=>{(c.metaKey||c.ctrlKey)&&c.key==="z"&&!c.shiftKey?(c.preventDefault(),L({type:"UNDO"})):(c.metaKey||c.ctrlKey)&&(c.key==="y"||c.key==="z"&&c.shiftKey)?(c.preventDefault(),L({type:"REDO"})):(c.key==="Delete"||c.key==="Backspace")&&h.selectedId&&L({type:"DELETE_ANNOTATION",id:h.selectedId})};return document.addEventListener("keydown",v),()=>document.removeEventListener("keydown",v)},[S,h.selectedId]),a.useImperativeHandle(K,()=>({exportAsDataURL:async(v="png",c=.92)=>{const P=document.createElement("canvas"),y=C.current;if(!y)return"";P.width=y.naturalWidth,P.height=y.naturalHeight;const k=P.getContext("2d");k.drawImage(y,0,0);for(const s of h.annotations){if(k.save(),k.globalAlpha=s.style.opacity,k.strokeStyle=s.style.strokeColor,k.fillStyle=s.style.fillColor,k.lineWidth=s.style.strokeWidth,s.tool==="rectangle")k.strokeRect(s.x,s.y,s.width,s.height);else if(s.tool==="ellipse")k.beginPath(),k.ellipse(s.x+s.width/2,s.y+s.height/2,Math.abs(s.width/2),Math.abs(s.height/2),0,0,Math.PI*2),k.stroke();else if(s.tool==="freehand"){const o=s;if(o.points.length>=2){k.beginPath(),k.moveTo(o.points[0].x,o.points[0].y);for(let u=1;u<o.points.length;u++)k.lineTo(o.points[u].x,o.points[u].y);k.stroke()}}else if(s.tool==="text"){const o=s;k.font=`${o.style.fontSize??16}px ${o.style.fontFamily??"sans-serif"}`,k.fillStyle=o.style.strokeColor,k.fillText(o.text,o.x,o.y+(o.style.fontSize??16))}k.restore()}return P.toDataURL(`image/${v}`,c)},exportAnnotations:()=>[...h.annotations],importAnnotations:v=>{L({type:"SET_ANNOTATIONS",annotations:v})},exportAsSVG:()=>{const{width:v,height:c}=Q,P=h.annotations.map(pa);return`<svg xmlns="http://www.w3.org/2000/svg" width="${v}" height="${c}" viewBox="0 0 ${v} ${c}">
401
+ ${P.join(`
402
+ `)}
403
+ </svg>`},undo:()=>L({type:"UNDO"}),redo:()=>L({type:"REDO"}),setZoom:v=>{L({type:"SET_ZOOM",zoom:Math.max(M,Math.min(R,v))})},fitToScreen:()=>{const v=g.current,c=C.current;if(!v||!c)return;const P=v.clientWidth/c.naturalWidth,y=v.clientHeight/c.naturalHeight,k=Math.min(P,y,1);L({type:"SET_ZOOM",zoom:k}),L({type:"SET_PAN",panX:0,panY:0})},clear:()=>L({type:"CLEAR"})}),[h.annotations,Q,M,R]);const A=a.useCallback(v=>{if(v.touches.length!==1)return;const c=v.touches[0];b({clientX:c.clientX,clientY:c.clientY,preventDefault:()=>{}})},[b]),O=a.useCallback(v=>{if(v.touches.length!==1)return;const c=v.touches[0];j({clientX:c.clientX,clientY:c.clientY})},[j]);return e.jsx("div",{ref:g,className:`nice-image-annotator ${_??""}`,style:{position:"relative",overflow:"hidden",width:"100%",height:"100%"},children:e.jsx("canvas",{ref:z,className:"nice-image-annotator__canvas",style:{cursor:h.activeTool==="select"?"default":"crosshair"},onMouseDown:b,onMouseMove:j,onMouseUp:x,onMouseLeave:x,onWheel:T,onTouchStart:A,onTouchMove:O,onTouchEnd:x,role:"img","aria-label":t})})});mn.displayName="NiceImageAnnotator";function ma(n){let t=n.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;");return t=t.replace(/```(\w*)\n([\s\S]*?)```/g,(i,l,d)=>`<pre><code class="language-${l}">${d.trim()}</code></pre>`),t=t.replace(/^(\|.+\|)\n(\|[-| :]+\|)\n((?:\|.+\|\n?)+)/gm,(i,l,d,f)=>{const _=l.split("|").filter(M=>M.trim()).map(M=>`<th>${M.trim()}</th>`).join(""),S=f.trim().split(`
404
+ `).map(M=>`<tr>${M.split("|").filter(R=>R.trim()).map(R=>`<td>${R.trim()}</td>`).join("")}</tr>`).join("");return`<table><thead><tr>${_}</tr></thead><tbody>${S}</tbody></table>`}),t=t.replace(/^#### (.+)$/gm,"<h4>$1</h4>"),t=t.replace(/^### (.+)$/gm,"<h3>$1</h3>"),t=t.replace(/^## (.+)$/gm,"<h2>$1</h2>"),t=t.replace(/^# (.+)$/gm,"<h1>$1</h1>"),t=t.replace(/^&gt; (.+)$/gm,"<blockquote>$1</blockquote>"),t=t.replace(/^---$/gm,"<hr/>"),t=t.replace(/^- \[x\] (.+)$/gm,'<li class="task done">☑ $1</li>'),t=t.replace(/^- \[ \] (.+)$/gm,'<li class="task">☐ $1</li>'),t=t.replace(/\*\*(.+?)\*\*/g,"<strong>$1</strong>"),t=t.replace(/\*(.+?)\*/g,"<em>$1</em>"),t=t.replace(/~~(.+?)~~/g,"<del>$1</del>"),t=t.replace(/`(.+?)`/g,"<code>$1</code>"),t=t.replace(/!\[([^\]]*)\]\(([^)]+)\)/g,'<img src="$2" alt="$1" style="max-width:100%"/>'),t=t.replace(/\[([^\]]+)\]\(([^)]+)\)/g,'<a href="$2">$1</a>'),t=t.replace(/^\- (.+)$/gm,"<li>$1</li>"),t=t.replace(/^\d+\. (.+)$/gm,"<li>$1</li>"),t=t.replace(/\n/g,"<br/>"),t}const ga=[{key:"bold",label:"B",md:"**",tip:"Bold",shortcut:"Ctrl+B",group:"format"},{key:"italic",label:"I",md:"*",tip:"Italic",shortcut:"Ctrl+I",group:"format"},{key:"strike",label:"S̶",md:"~~",tip:"Strikethrough",group:"format"},{key:"code",label:"< >",md:"`",tip:"Inline code",group:"format"},{key:"h1",label:"H1",md:"# ",tip:"Heading 1",group:"heading"},{key:"h2",label:"H2",md:"## ",tip:"Heading 2",group:"heading"},{key:"h3",label:"H3",md:"### ",tip:"Heading 3",group:"heading"},{key:"ul",label:"•",md:"- ",tip:"Unordered list",group:"list"},{key:"ol",label:"1.",md:"1. ",tip:"Ordered list",group:"list"},{key:"task",label:"☑",md:"- [ ] ",tip:"Task list",group:"list"},{key:"quote",label:"❝",md:"> ",tip:"Blockquote",group:"block"},{key:"hr",label:"—",md:`---
405
+ `,tip:"Horizontal rule",group:"block"},{key:"link",label:"🔗",md:"[](url)",tip:"Link",shortcut:"Ctrl+K",group:"insert"},{key:"image",label:"🖼",md:"![](url)",tip:"Image",group:"insert"},{key:"table",label:"⊞",md:`| H1 | H2 | H3 |
406
+ | --- | --- | --- |
407
+ | c1 | c2 | c3 |
408
+ `,tip:"Table",group:"insert"},{key:"codeblock",label:"```",md:"```\n",tip:"Code block",group:"insert"}],fa=["format","heading","list","block","insert"],gn=a.forwardRef(({value:n="",onChange:t,preview:i="side",placeholder:l,disabled:d,readOnly:f,size:_="md",editorSize:S="standard",toolbar:M=!0,minHeight:R=200,showWordCount:K=!1,showLineNumbers:z=!1,onExportHtml:g,onImageUpload:C,className:W,style:ne,id:Q},J)=>{const h=I.Xs(Q),[L,w]=a.useState("edit"),[E,X]=a.useState(!1),b=a.useRef(null),j=a.useMemo(()=>ma(n),[n]),x=a.useMemo(()=>{const y=n.trim()?n.trim().split(/\s+/).length:0,k=n.length,s=n.split(`
409
+ `).length;return{words:y,chars:k,lines:s}},[n]),T=a.useCallback(y=>{const k=b.current;if(!k)return;const s=k.selectionStart,o=k.selectionEnd,u=n.slice(s,o);let r,p;y==="[](url)"?(r=n.slice(0,s)+`[${u||"text"}](url)`+n.slice(o),p=s+1+(u||"text").length+2):y==="![](url)"?(r=n.slice(0,s)+`![${u||"alt"}](url)`+n.slice(o),p=s+2+(u||"alt").length+2):y.endsWith(`
410
+ `)||y.endsWith(" ")?(r=n.slice(0,s)+y+u+n.slice(o),p=s+y.length+u.length):(r=n.slice(0,s)+y+u+y+n.slice(o),p=s+y.length+u.length+y.length),t==null||t(r),requestAnimationFrame(()=>{k.focus(),k.setSelectionRange(p,p)})},[n,t]),A=a.useCallback(y=>{if((y.ctrlKey||y.metaKey)&&(y.key==="b"?(y.preventDefault(),T("**")):y.key==="i"?(y.preventDefault(),T("*")):y.key==="k"&&(y.preventDefault(),T("[](url)"))),y.key==="Tab"){y.preventDefault();const k=y.currentTarget,s=k.selectionStart,o=k.selectionEnd,u=" ";if(y.shiftKey){const r=n.slice(0,s).lastIndexOf(`
411
+ `)+1;if(n.slice(r,r+u.length)===u){const p=n.slice(0,r)+n.slice(r+u.length);t==null||t(p),requestAnimationFrame(()=>{k.selectionStart=k.selectionEnd=s-u.length})}}else{const r=n.slice(0,s)+u+n.slice(o);t==null||t(r),requestAnimationFrame(()=>{k.selectionStart=k.selectionEnd=s+u.length})}}},[n,t,T]),O=a.useCallback(async y=>{if(!C)return;const k=Array.from(y.dataTransfer.files).filter(s=>s.type.startsWith("image/"));if(k.length!==0){y.preventDefault();for(const s of k){const o=await C(s),u=b.current;if(!u)continue;const r=u.selectionStart,p=`![${s.name}](${o})
412
+ `,q=n.slice(0,r)+p+n.slice(r);t==null||t(q)}}},[n,t,C]),v=i!=="tab"||L==="edit",c=i==="side"||i==="tab"&&L==="preview"||i===!0,P=`nice-md-editor nice-md-editor--${_} nice-editor--${S} nice-md-editor--preview-${i}${E?" nice-md-editor--fullscreen":""} ${W||""}`;return e.jsxs("div",{ref:J,id:h,className:P,style:ne,children:[M&&e.jsxs("div",{className:"nice-md-editor__toolbar",children:[fa.map((y,k)=>e.jsxs(a.Fragment,{children:[k>0&&e.jsx("span",{className:"nice-md-editor__sep"}),ga.filter(s=>s.group===y).map(s=>e.jsx("button",{type:"button",className:"nice-md-editor__btn",title:s.shortcut?`${s.tip} (${s.shortcut})`:s.tip,disabled:d||f,onClick:()=>T(s.md),children:s.label},s.key))]},y)),e.jsx("span",{className:"nice-md-editor__sep"}),e.jsx("button",{type:"button",className:"nice-md-editor__btn",title:"Fullscreen",onClick:()=>X(!E),children:E?"⊙":"⛶"}),g&&e.jsx("button",{type:"button",className:"nice-md-editor__btn",title:"Export HTML",onClick:()=>g(j),children:"↗"}),i==="tab"&&e.jsxs("span",{className:"nice-md-editor__tabs",children:[e.jsx("button",{type:"button",className:`nice-md-editor__tab${L==="edit"?" nice-md-editor__tab--active":""}`,onClick:()=>w("edit"),children:"Edit"}),e.jsx("button",{type:"button",className:`nice-md-editor__tab${L==="preview"?" nice-md-editor__tab--active":""}`,onClick:()=>w("preview"),children:"Preview"})]})]}),e.jsxs("div",{className:"nice-md-editor__body",style:{minHeight:R},children:[v&&e.jsxs("div",{className:"nice-md-editor__editor-wrap",children:[z&&e.jsx("div",{className:"nice-md-editor__line-numbers",children:Array.from({length:x.lines},(y,k)=>e.jsx("div",{className:"nice-md-editor__line-no",children:k+1},k))}),e.jsx("textarea",{ref:b,className:"nice-md-editor__textarea",value:n,onChange:y=>t==null?void 0:t(y.target.value),onKeyDown:A,onDrop:O,placeholder:l,disabled:d,readOnly:f,style:{minHeight:R}})]}),c&&e.jsx("div",{className:"nice-md-editor__preview",dangerouslySetInnerHTML:{__html:I.$s(j)},style:{minHeight:R}})]}),K&&e.jsxs("div",{className:"nice-md-editor__statusbar",children:[e.jsxs("span",{children:[x.words," words"]}),e.jsxs("span",{children:[x.chars," chars"]}),e.jsxs("span",{children:[x.lines," lines"]})]})]})});gn.displayName="NiceMarkdownEditor";const Kt={rotation:0,flipH:!1,flipV:!1,brightness:100,contrast:100,saturate:100,blur:0,crop:null,annotations:[]},ba=["crop","rotate","flip","brightness","contrast","saturate","blur","annotate"],fn=a.forwardRef(({src:n,size:t="md",editorSize:i="standard",tools:l=ba,showToolbar:d=!0,showZoom:f=!0,maxUndo:_=30,onSave:S,onCancel:M,onChange:R,width:K="100%",height:z=500,className:g,style:C,id:W,...ne},Q)=>{const J=I.Xs(W),{t:h}=I.ue(),L=a.useRef(null),w=a.useRef(null),[E,X]=a.useState({...Kt}),[b,j]=a.useState(null),[x,T]=a.useState(!1),[A,O]=a.useState(1),[v,c]=a.useState("rect"),[P,y]=a.useState("var(--nice-danger, #ff0000)"),[k,s]=a.useState({w:0,h:0}),[o,u]=a.useState([]),[r,p]=a.useState([]),[q,F]=a.useState(null),[G,ie]=a.useState(null),[N,H]=a.useState(null),B=a.useCallback($=>{u(D=>[...D.slice(-(_-1)),$]),p([])},[_]),se=a.useCallback($=>{X(D=>{B(D);const Y={...D,...$};return R==null||R(Y),Y})},[R,B]),de=a.useCallback(()=>{if(o.length===0)return;const $=o[o.length-1];u(D=>D.slice(0,-1)),p(D=>[...D,E]),X($),R==null||R($)},[o,E,R]),he=a.useCallback(()=>{if(r.length===0)return;const $=r[r.length-1];p(D=>D.slice(0,-1)),u(D=>[...D,E]),X($),R==null||R($)},[r,E,R]);a.useEffect(()=>{const $=new Image;$.crossOrigin="anonymous",$.onload=()=>{w.current=$,s({w:$.width,h:$.height}),T(!0)},$.src=n},[n]),a.useEffect(()=>{if(!x||!L.current||!w.current)return;const $=L.current,D=$.getContext("2d");if(!D)return;const Y=w.current,pe=E.rotation%180!==0,Z=pe?Y.height:Y.width,U=pe?Y.width:Y.height;$.width=Z,$.height=U,D.clearRect(0,0,Z,U),D.save(),D.filter=`brightness(${E.brightness}%) contrast(${E.contrast}%) saturate(${E.saturate}%) blur(${E.blur}px)`,D.translate(Z/2,U/2),D.rotate(E.rotation*Math.PI/180),D.scale(E.flipH?-1:1,E.flipV?-1:1),D.drawImage(Y,-Y.width/2,-Y.height/2),D.restore(),E.annotations.forEach(re=>{switch(D.save(),D.strokeStyle=re.color??"red",D.fillStyle=re.color??"red",D.lineWidth=re.strokeWidth??2,D.font=`${re.fontSize??16}px sans-serif`,re.type){case"text":D.fillText(re.text??"",re.x,re.y);break;case"rect":D.strokeRect(re.x,re.y,re.width??100,re.height??50);break;case"circle":{const fe=(re.width??50)/2,ke=(re.height??50)/2;D.beginPath(),D.ellipse(re.x+fe,re.y+ke,fe,ke,0,0,Math.PI*2),D.stroke();break}case"line":D.beginPath(),D.moveTo(re.x,re.y),D.lineTo(re.x+(re.width??100),re.y+(re.height??0)),D.stroke();break;case"arrow":{const fe=re.x+(re.width??100),ke=re.y+(re.height??0);D.beginPath(),D.moveTo(re.x,re.y),D.lineTo(fe,ke),D.stroke();const ye=Math.atan2(ke-re.y,fe-re.x),je=10;D.beginPath(),D.moveTo(fe,ke),D.lineTo(fe-je*Math.cos(ye-.4),ke-je*Math.sin(ye-.4)),D.lineTo(fe-je*Math.cos(ye+.4),ke-je*Math.sin(ye+.4)),D.closePath(),D.fill();break}}D.restore()}),G&&(D.save(),D.fillStyle="var(--nice-overlay-50, rgba(0, 0, 0, 0.5))",D.fillRect(0,0,Z,U),D.clearRect(G.x,G.y,G.w,G.h),D.strokeStyle="var(--bg-primary, #fff)",D.lineWidth=2,D.setLineDash([5,5]),D.strokeRect(G.x,G.y,G.w,G.h),D.restore())},[x,E,G]);const be=a.useCallback($=>{if(!L.current)return;const D=L.current.getBoundingClientRect(),Y=L.current.width/D.width,pe=L.current.height/D.height,Z=($.clientX-D.left)*Y,U=($.clientY-D.top)*pe;b==="crop"?F({startX:Z,startY:U}):b==="annotate"&&H({startX:Z,startY:U})},[b]),ae=a.useCallback($=>{if(!L.current)return;const D=L.current.getBoundingClientRect(),Y=L.current.width/D.width,pe=L.current.height/D.height,Z=($.clientX-D.left)*Y,U=($.clientY-D.top)*pe;q&&ie({x:Math.min(q.startX,Z),y:Math.min(q.startY,U),w:Math.abs(Z-q.startX),h:Math.abs(U-q.startY)})},[q]),oe=a.useCallback($=>{if(q&&G&&G.w>5&&G.h>5&&se({crop:{x:G.x,y:G.y,width:G.w,height:G.h}}),F(null),N&&L.current){const D=L.current.getBoundingClientRect(),Y=L.current.width/D.width,pe=L.current.height/D.height,Z=($.clientX-D.left)*Y,U=($.clientY-D.top)*pe,re=Z-N.startX,fe=U-N.startY;if(Math.abs(re)>3||Math.abs(fe)>3||v==="text"){const ke={type:v,x:N.startX,y:N.startY,width:Math.abs(re)||100,height:Math.abs(fe)||50,color:P,strokeWidth:2,text:v==="text"?prompt(h("imageEditor.annotationText","Text:"))??"":void 0};se({annotations:[...E.annotations,ke]})}H(null)}},[q,G,N,v,P,E.annotations,se,h]),ce=a.useCallback(()=>{if(!E.crop||!L.current)return;const $=L.current,D=$.getContext("2d");if(!D)return;const{x:Y,y:pe,width:Z,height:U}=E.crop,re=D.getImageData(Y,pe,Z,U);$.width=Z,$.height=U,D.putImageData(re,0,0),ie(null),j(null)},[E.crop]),me=a.useCallback(()=>{if(!L.current)return;const $=L.current.toDataURL("image/png");S==null||S($,E)},[S,E]),le=a.useCallback(()=>{X({...Kt}),ie(null),j(null)},[]);return a.useMemo(()=>`brightness(${E.brightness}%) contrast(${E.contrast}%) saturate(${E.saturate}%) blur(${E.blur}px)`,[E.brightness,E.contrast,E.saturate,E.blur]),e.jsxs("div",{ref:Q,id:J,className:`nice-image-editor nice-image-editor--${t} nice-editor--${i} ${g??""}`,style:{...C,width:K,height:z},role:"application","aria-label":h("imageEditor.label","Image Editor"),...ne,children:[d&&e.jsxs("div",{className:"nice-image-editor__toolbar",role:"toolbar",children:[e.jsx("button",{type:"button",className:"nice-image-editor__btn",onClick:de,disabled:o.length===0,title:h("imageEditor.undo","Undo"),children:"↶"}),e.jsx("button",{type:"button",className:"nice-image-editor__btn",onClick:he,disabled:r.length===0,title:h("imageEditor.redo","Redo"),children:"↷"}),e.jsx("span",{className:"nice-image-editor__sep"}),l.includes("rotate")&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:"nice-image-editor__btn",onClick:()=>se({rotation:(E.rotation-90+360)%360}),title:h("imageEditor.rotateLeft","Rotate left"),children:"↺"}),e.jsx("button",{type:"button",className:"nice-image-editor__btn",onClick:()=>se({rotation:(E.rotation+90)%360}),title:h("imageEditor.rotateRight","Rotate right"),children:"↻"})]}),l.includes("flip")&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:"nice-image-editor__btn",onClick:()=>se({flipH:!E.flipH}),title:h("imageEditor.flipH","Flip horizontal"),children:"⇔"}),e.jsx("button",{type:"button",className:"nice-image-editor__btn",onClick:()=>se({flipV:!E.flipV}),title:h("imageEditor.flipV","Flip vertical"),children:"⇕"})]}),l.includes("crop")&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:`nice-image-editor__btn ${b==="crop"?"nice-image-editor__btn--active":""}`,onClick:()=>j(b==="crop"?null:"crop"),title:h("imageEditor.crop","Crop"),children:"⊡"}),b==="crop"&&E.crop&&e.jsx("button",{type:"button",className:"nice-image-editor__btn",onClick:ce,title:h("imageEditor.applyCrop","Apply crop"),children:"✓"})]}),l.includes("brightness")&&e.jsxs("label",{className:"nice-image-editor__slider-label",children:[h("imageEditor.brightness","☀"),e.jsx("input",{type:"range",min:0,max:200,value:E.brightness,onChange:$=>se({brightness:Number($.target.value)}),className:"nice-image-editor__slider",title:h("imageEditor.brightness","Brightness")})]}),l.includes("contrast")&&e.jsxs("label",{className:"nice-image-editor__slider-label",children:[h("imageEditor.contrast","◑"),e.jsx("input",{type:"range",min:0,max:200,value:E.contrast,onChange:$=>se({contrast:Number($.target.value)}),className:"nice-image-editor__slider",title:h("imageEditor.contrast","Contrast")})]}),l.includes("saturate")&&e.jsxs("label",{className:"nice-image-editor__slider-label",children:[h("imageEditor.saturate","🎨"),e.jsx("input",{type:"range",min:0,max:200,value:E.saturate,onChange:$=>se({saturate:Number($.target.value)}),className:"nice-image-editor__slider",title:h("imageEditor.saturate","Saturation")})]}),l.includes("blur")&&e.jsxs("label",{className:"nice-image-editor__slider-label",children:[h("imageEditor.blur","⊘"),e.jsx("input",{type:"range",min:0,max:20,step:.5,value:E.blur,onChange:$=>se({blur:Number($.target.value)}),className:"nice-image-editor__slider",title:h("imageEditor.blur","Blur")})]}),l.includes("annotate")&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"nice-image-editor__sep"}),e.jsx("button",{type:"button",className:`nice-image-editor__btn ${b==="annotate"?"nice-image-editor__btn--active":""}`,onClick:()=>j(b==="annotate"?null:"annotate"),title:h("imageEditor.annotate","Annotate"),children:"✎"}),b==="annotate"&&e.jsxs(e.Fragment,{children:[e.jsxs("select",{className:"nice-image-editor__select",value:v,onChange:$=>c($.target.value),children:[e.jsx("option",{value:"rect",children:"□ Rect"}),e.jsx("option",{value:"circle",children:"○ Circle"}),e.jsx("option",{value:"line",children:"╱ Line"}),e.jsx("option",{value:"arrow",children:"→ Arrow"}),e.jsx("option",{value:"text",children:"T Text"})]}),e.jsx("input",{type:"color",value:P,onChange:$=>y($.target.value),className:"nice-image-editor__color",title:h("imageEditor.color","Color")}),E.annotations.length>0&&e.jsx("button",{type:"button",className:"nice-image-editor__btn",onClick:()=>se({annotations:E.annotations.slice(0,-1)}),title:h("imageEditor.removeLastAnnotation","Remove last"),children:"⌫"})]})]}),e.jsx("span",{className:"nice-image-editor__sep"}),e.jsx("button",{type:"button",className:"nice-image-editor__btn",onClick:le,title:h("imageEditor.reset","Reset"),children:"⟲"}),S&&e.jsx("button",{type:"button",className:"nice-image-editor__btn nice-image-editor__btn--save",onClick:me,children:h("imageEditor.save","Save")}),M&&e.jsx("button",{type:"button",className:"nice-image-editor__btn",onClick:M,children:h("imageEditor.cancel","Cancel")})]}),e.jsx("div",{className:"nice-image-editor__canvas-wrap",children:e.jsx("canvas",{ref:L,className:"nice-image-editor__canvas",onMouseDown:be,onMouseMove:ae,onMouseUp:oe,style:{cursor:b==="crop"||b==="annotate"?"crosshair":"default",transform:`scale(${A})`,transformOrigin:"center center"}})}),f&&e.jsxs("div",{className:"nice-image-editor__footer",children:[e.jsx("button",{type:"button",className:"nice-image-editor__btn",onClick:()=>O($=>Math.max(.1,$-.1)),title:"Zoom out",children:"−"}),e.jsxs("span",{style:{fontSize:"0.85em",minWidth:40,textAlign:"center"},children:[Math.round(A*100),"%"]}),e.jsx("button",{type:"button",className:"nice-image-editor__btn",onClick:()=>O($=>Math.min(5,$+.1)),title:"Zoom in",children:"+"}),e.jsx("button",{type:"button",className:"nice-image-editor__btn",onClick:()=>O(1),title:"Reset zoom",children:"1:1"}),e.jsx("span",{style:{flex:1}}),e.jsxs("span",{style:{fontSize:"0.8em",color:"var(--nice-text-secondary, #666)"},children:[k.w,"×",k.h,"px · ",E.rotation,"°"]})]})]})});fn.displayName="NiceImageEditor";const bn=a.forwardRef(({value:n,onChange:t,penColor:i="var(--text-primary, #000)",penWidth:l=2,backgroundColor:d="var(--bg-primary, #fff)",width:f=400,height:_=200,size:S="md",disabled:M=!1,readOnly:R=!1,showClear:K=!0,showUndo:z=!0,label:g,exportFormat:C="image/png",className:W,style:ne,id:Q,...J},h)=>{const L=I.Xs(Q),{t:w}=I.ue(),E=a.useRef(null),[X,b]=a.useState(!1),j=a.useRef([]),x=a.useRef([]),[T,A]=a.useState(!0),O=a.useCallback(()=>{const o=E.current;if(!o)return;const u=o.getContext("2d");if(u){u.fillStyle=d,u.fillRect(0,0,o.width,o.height),u.strokeStyle=i,u.lineWidth=l,u.lineCap="round",u.lineJoin="round";for(const r of j.current)if(!(r.length<2)){u.beginPath(),u.moveTo(r[0].x,r[0].y);for(let p=1;p<r.length;p++)u.lineTo(r[p].x,r[p].y);u.stroke()}}},[d,i,l]);a.useEffect(()=>{if(n&&E.current){const o=new Image;o.onload=()=>{var r;const u=(r=E.current)==null?void 0:r.getContext("2d");!u||!E.current||(u.fillStyle=d,u.fillRect(0,0,E.current.width,E.current.height),u.drawImage(o,0,0),A(!1))},o.src=n}else n||(j.current=[],A(!0),O())},[n,d,O]),a.useEffect(()=>{const o=E.current;o&&(o.width=f,o.height=_,O())},[f,_,O]);const v=a.useCallback(o=>{const u=E.current,r=u.getBoundingClientRect(),p=u.width/r.width,q=u.height/r.height;if("touches"in o){const F=o.touches[0];return{x:(F.clientX-r.left)*p,y:(F.clientY-r.top)*q}}return{x:(o.clientX-r.left)*p,y:(o.clientY-r.top)*q}},[]),c=a.useCallback(o=>{if(M||R)return;o.preventDefault();const u=v(o);x.current=[u],b(!0)},[M,R,v]),P=a.useCallback(o=>{if(!X)return;o.preventDefault();const u=v(o);x.current.push(u);const r=E.current,p=r==null?void 0:r.getContext("2d");if(!p||!r)return;const q=x.current;q.length>=2&&(p.strokeStyle=i,p.lineWidth=l,p.lineCap="round",p.beginPath(),p.moveTo(q[q.length-2].x,q[q.length-2].y),p.lineTo(u.x,u.y),p.stroke())},[X,v,i,l]),y=a.useCallback(()=>{if(X&&(b(!1),x.current.length>0&&(j.current.push([...x.current]),x.current=[],A(!1),E.current))){const o=E.current.toDataURL(C);t==null||t(o)}},[X,C,t]),k=a.useCallback(()=>{j.current=[],x.current=[],A(!0),O(),t==null||t(null)},[O,t]),s=a.useCallback(()=>{if(j.current.length!==0&&(j.current.pop(),A(j.current.length===0),O(),E.current)){const o=j.current.length>0?E.current.toDataURL(C):null;t==null||t(o)}},[O,C,t]);return e.jsxs("div",{ref:h,id:L,className:`nice-signature nice-signature--${S} ${M?"nice-signature--disabled":""} ${R?"nice-signature--readonly":""} ${W??""}`,style:ne,...J,children:[g&&e.jsx("label",{className:"nice-signature__label",children:g}),e.jsx("div",{className:"nice-signature__canvas-wrap",style:{width:f,height:_},children:e.jsx("canvas",{ref:E,className:"nice-signature__canvas",onMouseDown:c,onMouseMove:P,onMouseUp:y,onMouseLeave:y,onTouchStart:c,onTouchMove:P,onTouchEnd:y,style:{touchAction:"none",cursor:M||R?"default":"crosshair"},"aria-label":g??w("signature.label","Signature pad"),role:"img"})}),(K||z)&&!R&&!M&&e.jsxs("div",{className:"nice-signature__actions",children:[z&&e.jsx("button",{type:"button",className:"nice-signature__btn",onClick:s,disabled:T,children:w("signature.undo","Undo")}),K&&e.jsx("button",{type:"button",className:"nice-signature__btn",onClick:k,disabled:T,children:w("signature.clear","Clear")})]})]})});bn.displayName="NiceSignaturePad";let xa=0;function Nt(){return`blk-${++xa}-${Date.now().toString(36)}`}function Ut(n=""){return{id:Nt(),type:"paragraph",content:n}}function va(n,t=""){const i={id:Nt(),type:n,content:t};return n==="heading"&&(i.level=2),n==="list"&&(i.listType="unordered"),n==="callout"&&(i.icon="??"),n==="toggle"&&(i.open=!0),i}const ya=[{type:"paragraph",label:"Text",icon:"�",keywords:"paragraph text"},{type:"heading",label:"Heading",icon:"H",keywords:"heading title"},{type:"list",label:"Bulleted list",icon:"�",keywords:"bullet unordered list"},{type:"list",label:"Numbered list",icon:"1.",keywords:"numbered ordered list"},{type:"list",label:"Checklist",icon:"?",keywords:"check todo list"},{type:"quote",label:"Quote",icon:"?",keywords:"quote blockquote"},{type:"callout",label:"Callout",icon:"??",keywords:"callout info alert"},{type:"toggle",label:"Toggle",icon:"?",keywords:"toggle collapse expand"},{type:"code",label:"Code",icon:"</>",keywords:"code snippet"},{type:"image",label:"Image",icon:"??",keywords:"image photo picture"},{type:"video",label:"Video",icon:"??",keywords:"video embed"},{type:"table",label:"Table",icon:"?",keywords:"table grid"},{type:"divider",label:"Divider",icon:"-",keywords:"divider line separator"},{type:"pageBreak",label:"Page Break",icon:"?",keywords:"page break"}];function _a(n){const t=[n.align?`text-align:${n.align}`:"",n.color?`color:${n.color}`:"",n.bgColor?`background-color:${n.bgColor}`:"",n.indent?`margin-left:${n.indent*24}px`:""].filter(Boolean).join(";"),i=t?` style="${t}"`:"",l=(d,f)=>{let _=f;return n.bold&&(_=`<strong>${_}</strong>`),n.italic&&(_=`<em>${_}</em>`),n.underline&&(_=`<u>${_}</u>`),n.strikethrough&&(_=`<s>${_}</s>`),`<${d}${i}>${_}</${d}>`};switch(n.type){case"heading":return l(`h${n.level??2}`,n.content);case"paragraph":return l("p",n.content||"&nbsp;");case"list":{const d=n.listType==="ordered"?"ol":"ul",f=n.content.split(`
413
+ `).map((_,S)=>{var M;return n.listType==="checklist"?`<li><input type="checkbox" ${((M=n.checked)==null?void 0:M[S])??!1?"checked":""} disabled />${_}</li>`:`<li>${_}</li>`}).join("");return`<${d}${i}>${f}</${d}>`}case"image":return`<figure${i}><img src="${n.src??""}" alt="${n.alt??""}" /></figure>`;case"video":return`<figure${i}><video src="${n.src??""}" controls></video></figure>`;case"divider":return"<hr />";case"pageBreak":return'<div style="page-break-after:always"></div>';case"code":return`<pre><code class="language-${n.language??""}">${n.content}</code></pre>`;case"quote":return l("blockquote",n.content);case"callout":return`<div class="nice-doc-callout"${i}><span>${n.icon??"??"}</span><div>${n.content}</div></div>`;case"toggle":return`<details${i}><summary>${n.content.split(`
414
+ `)[0]}</summary>${n.content.split(`
415
+ `).slice(1).join("<br>")}</details>`;case"table":return`<table${i}>${n.content}</table>`;case"embed":return`<iframe src="${n.src??""}" style="width:100%;border:none;min-height:300px"></iframe>`;default:return l("p",n.content)}}function ka(n){let t=0,i=0;for(const l of n){const d=l.content??"";t+=d.length;const f=d.trim().split(/\s+/).filter(Boolean);i+=f.length}return{words:i,chars:t,readingTime:Math.max(1,Math.ceil(i/200))}}const xn=a.forwardRef(({blocks:n,onChange:t,readOnly:i=!1,showToolbar:l=!0,size:d="md",editorSize:f="standard",placeholder:_,onExport:S,onImageUpload:M,maxUndo:R=50,slashCommands:K=!0,showWordCount:z=!1,showToc:g=!1,showFindReplace:C=!0,className:W,style:ne,id:Q,...J},h)=>{var V,ue,ge,Ce,ve,$e,_e,Ae,Te,Re,Le,Ye,Oe,et,wt,$t;const L=I.Xs(Q),{t:w}=I.ue(),[E,X]=a.useState(()=>n??[Ut()]),b=n??E,[j,x]=a.useState(0),T=a.useRef(new Map),A=a.useRef(null),[O,v]=a.useState(!1),[c,P]=a.useState(""),[y,k]=a.useState(""),[s,o]=a.useState([]),[u,r]=a.useState(0),[p,q]=a.useState(!1),F=a.useRef([]),G=a.useRef([]),ie=a.useCallback(m=>{F.current.push(m.map(ee=>({...ee,checked:ee.checked?[...ee.checked]:void 0}))),F.current.length>R&&F.current.shift(),G.current=[]},[R]),N=a.useCallback(()=>{if(F.current.length===0)return;const m=F.current.pop();G.current.push(b.map(ee=>({...ee}))),n||X(m),t==null||t(m)},[b,n,t]),H=a.useCallback(()=>{if(G.current.length===0)return;const m=G.current.pop();F.current.push(b.map(ee=>({...ee}))),n||X(m),t==null||t(m)},[b,n,t]),[B,se]=a.useState(!1),[de,he]=a.useState(""),[be,ae]=a.useState(0),oe=a.useMemo(()=>{if(!B||!K)return[];const m=de.toLowerCase();return ya.filter(ee=>ee.label.toLowerCase().includes(m)||ee.keywords.includes(m))},[B,de,K]),[ce,me]=a.useState(null),[le,$]=a.useState(null),D=a.useCallback(m=>{ie(b);const ee=m(b);n||X(ee),t==null||t(ee)},[b,n,t,ie]),Y=a.useCallback((m,ee)=>{D(te=>te.map((xe,we)=>we===m?{...xe,...ee}:xe))},[D]),pe=a.useCallback((m,ee)=>{const te=ee??Ut();D(xe=>{const we=[...xe];return we.splice(m+1,0,te),we}),x(m+1)},[D]),Z=a.useCallback(m=>{const ee={...b[m],id:Nt()};pe(m,ee)},[b,pe]),U=a.useCallback(m=>{b.length<=1||(D(ee=>ee.filter((te,xe)=>xe!==m)),x(Math.max(0,m-1)))},[b.length,D]),re=a.useCallback((m,ee)=>{const te=m+ee;te<0||te>=b.length||(D(xe=>{const we=[...xe];return[we[m],we[te]]=[we[te],we[m]],we}),x(te))},[b.length,D]),fe=a.useCallback((m,ee)=>{const te={type:ee};ee==="heading"&&(te.level=2),ee==="list"&&(te.listType="unordered"),ee==="callout"&&(te.icon="??"),ee==="toggle"&&(te.open=!0),Y(m,te)},[Y]),ke=a.useCallback(m=>{var te,xe;const ee=va(m.type);m.type==="list"&&m.label.includes("Numbered")&&(ee.listType="ordered"),m.type==="list"&&m.label.includes("Checklist")&&(ee.listType="checklist",ee.checked=[]),((te=b[j])==null?void 0:te.content)===""||((xe=b[j])==null?void 0:xe.content)==="/"?D(we=>we.map((Pe,We)=>We===j?{...ee,id:Pe.id}:Pe)):pe(j,ee),se(!1),he("")},[b,j,D,pe]),ye=a.useCallback((m,ee)=>{if(i)return;const te=b[ee];if(!(te!=null&&te.locked)){if((m.ctrlKey||m.metaKey)&&m.key==="z"&&!m.shiftKey){m.preventDefault(),N();return}if((m.ctrlKey||m.metaKey)&&(m.key==="y"||m.key==="z"&&m.shiftKey)){m.preventDefault(),H();return}if((m.ctrlKey||m.metaKey)&&m.key==="d"){m.preventDefault(),Z(ee);return}if((m.ctrlKey||m.metaKey)&&m.key==="b"){m.preventDefault(),Y(ee,{bold:!(te!=null&&te.bold)});return}if((m.ctrlKey||m.metaKey)&&m.key==="i"){m.preventDefault(),Y(ee,{italic:!(te!=null&&te.italic)});return}if((m.ctrlKey||m.metaKey)&&m.key==="u"){m.preventDefault(),Y(ee,{underline:!(te!=null&&te.underline)});return}if((m.ctrlKey||m.metaKey)&&m.key==="e"){m.preventDefault(),Y(ee,{strikethrough:!(te!=null&&te.strikethrough)});return}if(m.key==="Tab"&&!m.shiftKey){m.preventDefault(),Y(ee,{indent:Math.min(((te==null?void 0:te.indent)??0)+1,4)});return}if(m.key==="Tab"&&m.shiftKey){m.preventDefault(),Y(ee,{indent:Math.max(((te==null?void 0:te.indent)??0)-1,0)});return}if((m.ctrlKey||m.metaKey)&&m.key==="f"&&C){m.preventDefault(),v(xe=>!xe);return}if(B&&oe.length>0){if(m.key==="ArrowDown"){m.preventDefault(),ae(xe=>Math.min(xe+1,oe.length-1));return}if(m.key==="ArrowUp"){m.preventDefault(),ae(xe=>Math.max(xe-1,0));return}if(m.key==="Enter"){m.preventDefault(),ke(oe[be]);return}if(m.key==="Escape"){se(!1);return}}m.key==="Enter"&&!m.shiftKey?(m.preventDefault(),pe(ee)):m.key==="Backspace"&&b[ee].content===""&&b.length>1?(m.preventDefault(),U(ee)):m.key==="ArrowUp"&&m.altKey?(m.preventDefault(),re(ee,-1)):m.key==="ArrowDown"&&m.altKey&&(m.preventDefault(),re(ee,1))}},[i,b,pe,U,re,N,H,Z,Y,B,oe,be,ke,C]),je=a.useCallback((m,ee)=>{const te=m.target.textContent??"";K&&te.startsWith("/")?(se(!0),he(te.slice(1)),ae(0)):B&&se(!1),ie(b);const xe=b.map((we,Pe)=>Pe===ee?{...we,content:te}:we);n||X(xe),t==null||t(xe)},[b,n,t,ie,K,B]),ze=a.useCallback((m,ee)=>{me(ee),m.dataTransfer.effectAllowed="move"},[]),ot=a.useCallback((m,ee)=>{m.preventDefault(),m.dataTransfer.dropEffect="move",$(ee)},[]),De=a.useCallback((m,ee)=>{if(m.preventDefault(),ce===null||ce===ee){me(null),$(null);return}D(te=>{const xe=[...te],[we]=xe.splice(ce,1);return xe.splice(ee>ce?ee-1:ee,0,we),xe}),x(ee>ce?ee-1:ee),me(null),$(null)},[ce,D]);a.useEffect(()=>{if(!O||!c){o([]);return}const m=c.toLowerCase(),ee=[];b.forEach((te,xe)=>{const we=(te.content??"").toLowerCase();let Pe=0;for(;Pe<we.length;){const We=we.indexOf(m,Pe);if(We===-1)break;ee.push({blockIdx:xe,start:We,end:We+m.length}),Pe=We+1}}),o(ee),r(0)},[c,O,b]);const Ke=a.useCallback(()=>{if(s.length===0)return;const m=(u+1)%s.length;r(m),x(s[m].blockIdx)},[s,u]),ct=a.useCallback(()=>{if(s.length===0)return;const m=(u-1+s.length)%s.length;r(m),x(s[m].blockIdx)},[s,u]),dt=a.useCallback(()=>{if(s.length===0||!c)return;const m=s[u],ee=b[m.blockIdx],te=ee.content.slice(0,m.start),xe=ee.content.slice(m.end);Y(m.blockIdx,{content:te+y+xe})},[s,u,c,y,b,Y]),ut=a.useCallback(()=>{if(!c)return;const m=c;D(ee=>ee.map(te=>({...te,content:te.content.split(m).join(y)})))},[c,y,D]),Ze=a.useMemo(()=>g?b.map((m,ee)=>m.type==="heading"?{idx:ee,level:m.level??2,text:m.content}:null).filter(Boolean):[],[b,g]),Qe=a.useCallback(async m=>{var te;const ee=(te=m.target.files)==null?void 0:te[0];if(ee){if(M){const xe=await M(ee);Y(j,{src:xe})}m.target.value=""}},[M,j,Y]);a.useEffect(()=>{const m=b[j];if(m){const ee=T.current.get(m.id);ee&&ee.focus()}},[j,b]);const pt=a.useCallback(()=>{const m=b.map(_a).join(`
416
+ `);S==null||S(m)},[b,S]),He=a.useMemo(()=>z?ka(b):null,[b,z]),[Me,Ee]=a.useState(null),ht=a.useCallback((m,ee)=>{i||(m.preventDefault(),Ee({x:m.clientX,y:m.clientY,idx:ee}))},[i]);return a.useEffect(()=>{if(!Me)return;const m=()=>Ee(null);return window.addEventListener("click",m),()=>window.removeEventListener("click",m)},[Me]),e.jsxs("div",{ref:h,id:L,className:`nice-doc-editor nice-doc-editor--${d} nice-editor--${f} ${i?"nice-doc-editor--readonly":""} ${W??""}`,style:ne,role:"application","aria-label":w("docEditor.label","Document Editor"),...J,children:[l&&!i&&e.jsxs("div",{className:"nice-doc-editor__toolbar",role:"toolbar",style:{display:"flex",flexWrap:"wrap",gap:4,alignItems:"center",padding:"4px 8px"},children:[e.jsx(I.dn,{size:"sm",variant:"ghost",onClick:N,title:w("docEditor.undo","Undo (Ctrl+Z)"),children:"?"}),e.jsx(I.dn,{size:"sm",variant:"ghost",onClick:H,title:w("docEditor.redo","Redo (Ctrl+Y)"),children:"?"}),e.jsx("span",{className:"nice-doc-editor__sep"}),e.jsx(I.Pe,{size:"sm",value:((V=b[j])==null?void 0:V.type)??"paragraph",onChange:m=>fe(j,m),label:"",options:[{value:"paragraph",label:w("docEditor.paragraph","Paragraph")},{value:"heading",label:w("docEditor.heading","Heading")},{value:"list",label:w("docEditor.list","List")},{value:"code",label:w("docEditor.code","Code")},{value:"quote",label:w("docEditor.quote","Quote")},{value:"callout",label:w("docEditor.callout","Callout")},{value:"toggle",label:w("docEditor.toggle","Toggle")},{value:"divider",label:w("docEditor.divider","Divider")},{value:"image",label:w("docEditor.image","Image")},{value:"video",label:w("docEditor.video","Video")},{value:"pageBreak",label:w("docEditor.pageBreak","Page Break")}],style:{minWidth:100}}),((ue=b[j])==null?void 0:ue.type)==="heading"&&e.jsx(I.Pe,{size:"sm",value:String(((ge=b[j])==null?void 0:ge.level)??2),onChange:m=>Y(j,{level:Number(m)}),label:"",options:[{value:"1",label:"H1"},{value:"2",label:"H2"},{value:"3",label:"H3"},{value:"4",label:"H4"},{value:"5",label:"H5"},{value:"6",label:"H6"}],style:{minWidth:55}}),((Ce=b[j])==null?void 0:Ce.type)==="list"&&e.jsx(I.Pe,{size:"sm",value:((ve=b[j])==null?void 0:ve.listType)??"unordered",onChange:m=>Y(j,{listType:m}),label:"",options:[{value:"unordered",label:"� Bullets"},{value:"ordered",label:"1. Numbers"},{value:"checklist",label:"? Checklist"}],style:{minWidth:90}}),e.jsx("span",{className:"nice-doc-editor__sep"}),e.jsx(I.dn,{size:"sm",variant:($e=b[j])!=null&&$e.bold?"primary":"ghost",onClick:()=>{var m;return Y(j,{bold:!((m=b[j])!=null&&m.bold)})},title:w("docEditor.bold","Bold (Ctrl+B)"),children:e.jsx("strong",{children:"B"})}),e.jsx(I.dn,{size:"sm",variant:(_e=b[j])!=null&&_e.italic?"primary":"ghost",onClick:()=>{var m;return Y(j,{italic:!((m=b[j])!=null&&m.italic)})},title:w("docEditor.italic","Italic (Ctrl+I)"),children:e.jsx("em",{children:"I"})}),e.jsx(I.dn,{size:"sm",variant:(Ae=b[j])!=null&&Ae.underline?"primary":"ghost",onClick:()=>{var m;return Y(j,{underline:!((m=b[j])!=null&&m.underline)})},title:w("docEditor.underline","Underline (Ctrl+U)"),children:e.jsx("u",{children:"U"})}),e.jsx(I.dn,{size:"sm",variant:(Te=b[j])!=null&&Te.strikethrough?"primary":"ghost",onClick:()=>{var m;return Y(j,{strikethrough:!((m=b[j])!=null&&m.strikethrough)})},title:w("docEditor.strikethrough","Strikethrough (Ctrl+E)"),children:e.jsx("s",{children:"S"})}),e.jsx("span",{className:"nice-doc-editor__sep"}),e.jsx(I.dn,{size:"sm",variant:((Re=b[j])==null?void 0:Re.align)==="left"?"primary":"ghost",onClick:()=>Y(j,{align:"left"}),title:w("docEditor.alignLeft","Left"),children:"?"}),e.jsx(I.dn,{size:"sm",variant:((Le=b[j])==null?void 0:Le.align)==="center"?"primary":"ghost",onClick:()=>Y(j,{align:"center"}),title:w("docEditor.alignCenter","Center"),children:"?"}),e.jsx(I.dn,{size:"sm",variant:((Ye=b[j])==null?void 0:Ye.align)==="right"?"primary":"ghost",onClick:()=>Y(j,{align:"right"}),title:w("docEditor.alignRight","Right"),children:"?"}),e.jsx("span",{className:"nice-doc-editor__sep"}),e.jsx(I.dn,{size:"sm",variant:"ghost",onClick:()=>{var m;return Y(j,{indent:Math.min((((m=b[j])==null?void 0:m.indent)??0)+1,4)})},title:w("docEditor.indent","Indent (Tab)"),children:"??"}),e.jsx(I.dn,{size:"sm",variant:"ghost",onClick:()=>{var m;return Y(j,{indent:Math.max((((m=b[j])==null?void 0:m.indent)??0)-1,0)})},title:w("docEditor.outdent","Outdent (Shift+Tab)"),children:"??"}),e.jsx("span",{className:"nice-doc-editor__sep"}),e.jsx(I.on,{size:"sm",label:"",value:((Oe=b[j])==null?void 0:Oe.color)??"var(--text-primary, #000000)",onChange:m=>Y(j,{color:m}),title:"Text color"}),e.jsx(I.on,{size:"sm",label:"",value:((et=b[j])==null?void 0:et.bgColor)??"var(--bg-primary, #ffffff)",onChange:m=>Y(j,{bgColor:m}),title:"Block background"}),e.jsx("span",{className:"nice-doc-editor__sep"}),e.jsx(I.dn,{size:"sm",variant:(wt=b[j])!=null&&wt.locked?"primary":"ghost",onClick:()=>{var m;return Y(j,{locked:!((m=b[j])!=null&&m.locked)})},title:w("docEditor.lock","Lock/Unlock block"),children:"??"}),e.jsx(I.dn,{size:"sm",variant:"ghost",onClick:()=>Z(j),title:w("docEditor.duplicate","Duplicate (Ctrl+D)"),children:"?"}),e.jsx(I.dn,{size:"sm",variant:"ghost",onClick:()=>U(j),title:w("docEditor.delete","Delete block"),children:"??"}),e.jsx(I.dn,{size:"sm",variant:"ghost",onClick:()=>pe(j),title:w("docEditor.addBlock","Add block"),children:"+"}),C&&e.jsx(I.dn,{size:"sm",variant:O?"primary":"ghost",onClick:()=>v(m=>!m),title:w("docEditor.find","Find & Replace (Ctrl+F)"),children:"??"}),e.jsx(I.dn,{size:"sm",variant:"ghost",onClick:()=>q(m=>!m),title:w("docEditor.shortcuts","Keyboard shortcuts"),children:"?"}),S&&e.jsx(I.dn,{size:"sm",variant:"ghost",onClick:pt,children:w("docEditor.export","Export HTML")})]}),e.jsx("input",{ref:A,type:"file",accept:"image/*,video/*",style:{display:"none"},onChange:Qe}),O&&e.jsxs("div",{className:"nice-doc-editor__find-bar",style:{display:"flex",gap:4,alignItems:"center",padding:"4px 8px",background:"var(--nice-doc-find-bg, #f8f9fa)",borderBottom:"1px solid var(--border-color, #ddd)"},children:[e.jsx(I.Qe,{size:"sm",placeholder:w("docEditor.findPlaceholder","Find..."),value:c,onChange:P,style:{flex:1,maxWidth:200}}),e.jsx(I.Qe,{size:"sm",placeholder:w("docEditor.replacePlaceholder","Replace..."),value:y,onChange:k,style:{flex:1,maxWidth:200}}),e.jsx(I.dn,{size:"sm",variant:"ghost",onClick:ct,title:w("docEditor.findPrev","Previous"),children:"?"}),e.jsx(I.dn,{size:"sm",variant:"ghost",onClick:Ke,title:w("docEditor.findNext","Next"),children:"?"}),e.jsx(I.dn,{size:"sm",variant:"ghost",onClick:dt,title:w("docEditor.replaceOne","Replace"),disabled:i,children:w("docEditor.replace","Replace")}),e.jsx(I.dn,{size:"sm",variant:"ghost",onClick:ut,title:w("docEditor.replaceAll","Replace all"),disabled:i,children:w("docEditor.replaceAllBtn","All")}),e.jsx("span",{style:{fontSize:"0.75em",color:"var(--text-muted, #666)"},children:s.length>0?`${u+1}/${s.length}`:"0/0"}),e.jsx(I.dn,{size:"sm",variant:"ghost",onClick:()=>v(!1),children:"?"})]}),p&&e.jsx("div",{className:"nice-doc-editor__shortcuts-overlay",style:{position:"fixed",inset:0,background:"var(--nice-overlay-40, rgba(0, 0, 0, 0.4))",zIndex:9999,display:"flex",alignItems:"center",justifyContent:"center"},onClick:()=>q(!1),children:e.jsxs("div",{style:{background:"var(--bg-primary, #fff)",borderRadius:8,padding:24,maxWidth:420,width:"90%",boxShadow:"0 8px 32px var(--nice-overlay-20, rgba(0, 0, 0, 0.2))"},onClick:m=>m.stopPropagation(),children:[e.jsx("h3",{style:{margin:"0 0 12px"},children:w("docEditor.shortcutsTitle","Keyboard Shortcuts")}),e.jsx("table",{style:{width:"100%",fontSize:"0.875em",borderCollapse:"collapse"},children:e.jsx("tbody",{children:[["Ctrl+B",w("docEditor.bold","Bold")],["Ctrl+I",w("docEditor.italic","Italic")],["Ctrl+U",w("docEditor.underline","Underline")],["Ctrl+E",w("docEditor.strikethrough","Strikethrough")],["Ctrl+D",w("docEditor.duplicate","Duplicate block")],["Ctrl+Z",w("docEditor.undo","Undo")],["Ctrl+Y",w("docEditor.redo","Redo")],["Ctrl+F",w("docEditor.find","Find & Replace")],["Enter",w("docEditor.newBlock","New block")],["Backspace",w("docEditor.deleteEmpty","Delete empty block")],["Alt+?",w("docEditor.moveUp","Move block up")],["Alt+?",w("docEditor.moveDown","Move block down")],["Tab",w("docEditor.indent","Indent")],["Shift+Tab",w("docEditor.outdent","Outdent")],["/",w("docEditor.slashCmd","Slash commands")]].map(([m,ee])=>e.jsxs("tr",{style:{borderBottom:"1px solid var(--border-color, #eee)"},children:[e.jsx("td",{style:{padding:"4px 8px",fontFamily:"monospace",fontWeight:600},children:m}),e.jsx("td",{style:{padding:"4px 8px"},children:ee})]},m))})}),e.jsx("div",{style:{textAlign:"right",marginTop:12},children:e.jsx(I.dn,{size:"sm",variant:"ghost",onClick:()=>q(!1),children:w("docEditor.close","Close")})})]})}),e.jsxs("div",{style:{display:"flex",gap:0},children:[g&&Ze.length>0&&e.jsxs("nav",{className:"nice-doc-editor__toc",style:{width:200,minWidth:160,borderRight:"1px solid var(--border-color, #eee)",padding:"8px 4px",fontSize:"0.8em",overflowY:"auto",maxHeight:500},children:[e.jsx("div",{style:{fontWeight:600,padding:"4px 8px",fontSize:"0.75em",textTransform:"uppercase",color:"var(--text-muted, #999)"},children:w("docEditor.toc","Contents")}),Ze.map(m=>e.jsx("div",{style:{padding:"3px 8px",paddingLeft:8+(m.level-1)*12,cursor:"pointer",borderRadius:4,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",background:m.idx===j?"var(--nice-primary-bg, #e8f0fe)":void 0},onClick:()=>x(m.idx),title:m.text,children:m.text||w("docEditor.untitled","Untitled")},m.idx))]}),e.jsx("div",{className:"nice-doc-editor__body",style:{flex:1},children:b.map((m,ee)=>e.jsxs("div",{className:`nice-doc-editor__block nice-doc-editor__block--${m.type} ${ee===j?"nice-doc-editor__block--focused":""} ${le===ee?"nice-doc-editor__block--drop-target":""} ${m.locked?"nice-doc-editor__block--locked":""}`,onClick:()=>x(ee),onContextMenu:te=>ht(te,ee),draggable:!i&&!m.locked,onDragStart:te=>ze(te,ee),onDragOver:te=>ot(te,ee),onDrop:te=>De(te,ee),onDragEnd:()=>{me(null),$(null)},style:{opacity:ce===ee?.4:1,marginLeft:(m.indent??0)*24},children:[!i&&!m.locked&&e.jsx("div",{className:"nice-doc-editor__block-handle",title:w("docEditor.drag","Drag to reorder"),children:"?"}),m.locked&&e.jsx("span",{className:"nice-doc-editor__lock-icon",style:{position:"absolute",top:2,right:4,fontSize:"0.7em",opacity:.5},children:"??"}),m.type==="divider"?e.jsx("hr",{className:"nice-doc-editor__divider"}):m.type==="pageBreak"?e.jsxs("div",{className:"nice-doc-editor__page-break",style:{borderTop:"2px dashed var(--nice-border, #ccc)",textAlign:"center",padding:4,fontSize:"0.75em",color:"var(--text-muted, #999)"},children:["� ",w("docEditor.pageBreak","Page Break")," �"]}):m.type==="image"||m.type==="video"?e.jsx("div",{className:"nice-doc-editor__media-block",children:m.src?m.type==="image"?e.jsx("img",{src:m.src,alt:m.alt??"",className:"nice-doc-editor__image",style:{maxWidth:"100%"}}):e.jsx("video",{src:m.src,controls:!0,className:"nice-doc-editor__video",style:{maxWidth:"100%"}}):!i&&e.jsxs("div",{style:{display:"flex",gap:4,alignItems:"center"},children:[e.jsx(I.Qe,{size:"sm",placeholder:w("docEditor.mediaUrl",m.type==="image"?"Image URL":"Video URL"),value:m.src??"",onChange:te=>Y(ee,{src:te})}),M&&e.jsx(I.dn,{size:"sm",variant:"ghost",onClick:()=>{var te;x(ee),(te=A.current)==null||te.click()},children:"??"})]})}):m.type==="callout"?e.jsxs("div",{className:"nice-doc-editor__callout",style:{display:"flex",gap:8,padding:"8px 12px",background:m.bgColor??"#f0f7ff",borderRadius:4,color:m.color},children:[e.jsx("span",{style:{fontSize:"1.2em"},children:m.icon??"??"}),e.jsx("div",{ref:te=>{te&&T.current.set(m.id,te)},className:"nice-doc-editor__content",contentEditable:!i&&!m.locked,suppressContentEditableWarning:!0,onInput:te=>je(te,ee),onFocus:()=>x(ee),onKeyDown:te=>ye(te,ee),"data-placeholder":w("docEditor.calloutPlaceholder","Callout text..."),role:"textbox","aria-multiline":"true",style:{flex:1,outline:"none"},children:m.content})]}):m.type==="toggle"?e.jsxs("details",{open:m.open,className:"nice-doc-editor__toggle",onToggle:te=>Y(ee,{open:te.target.open}),children:[e.jsx("summary",{style:{cursor:"pointer",fontWeight:500},children:m.content.split(`
417
+ `)[0]||w("docEditor.toggleTitle","Toggle")}),e.jsx("div",{ref:te=>{te&&T.current.set(m.id,te)},className:"nice-doc-editor__content",contentEditable:!i&&!m.locked,suppressContentEditableWarning:!0,onInput:te=>je(te,ee),onFocus:()=>x(ee),onKeyDown:te=>ye(te,ee),role:"textbox","aria-multiline":"true",style:{padding:"4px 0"},children:m.content.split(`
418
+ `).slice(1).join(`
419
+ `)})]}):m.type==="code"?e.jsxs("div",{className:"nice-doc-editor__code-block",style:{position:"relative"},children:[!i&&e.jsx(I.Qe,{size:"sm",value:m.language??"",onChange:te=>Y(ee,{language:te}),placeholder:"Language",style:{position:"absolute",top:4,right:4,width:80,opacity:.7}}),e.jsx("pre",{ref:te=>{te&&T.current.set(m.id,te)},className:"nice-doc-editor__content",contentEditable:!i&&!m.locked,suppressContentEditableWarning:!0,onInput:te=>je(te,ee),onFocus:()=>x(ee),onKeyDown:te=>ye(te,ee),role:"textbox","aria-multiline":"true",style:{fontFamily:"monospace",background:"var(--bg-elevated, #1e1e1e)",color:"var(--text-secondary, #d4d4d4)",padding:12,borderRadius:4,overflow:"auto"},children:m.content})]}):e.jsxs("div",{style:{position:"relative"},children:[e.jsx("div",{ref:te=>{te&&T.current.set(m.id,te)},className:"nice-doc-editor__content",contentEditable:!i&&!m.locked,suppressContentEditableWarning:!0,style:{textAlign:m.align,fontWeight:m.bold?"bold":void 0,fontStyle:m.italic?"italic":void 0,textDecoration:[m.underline?"underline":"",m.strikethrough?"line-through":""].filter(Boolean).join(" ")||void 0,color:m.color,backgroundColor:m.bgColor},onInput:te=>je(te,ee),onFocus:()=>x(ee),onKeyDown:te=>ye(te,ee),"data-placeholder":!m.content&&_?_:void 0,role:"textbox","aria-multiline":"true",children:m.content}),B&&ee===j&&oe.length>0&&e.jsx("ul",{className:"nice-doc-editor__slash-menu",style:{position:"absolute",left:0,top:"100%",zIndex:100,background:"var(--bg-primary, #fff)",border:"1px solid var(--border-color, #ddd)",borderRadius:6,boxShadow:"0 4px 16px var(--nice-overlay-12, rgba(0, 0, 0, 0.12))",listStyle:"none",margin:0,padding:4,minWidth:180,maxHeight:240,overflow:"auto"},children:oe.map((te,xe)=>e.jsxs("li",{className:xe===be?"nice-doc-editor__slash-item--active":"",style:{padding:"6px 10px",cursor:"pointer",borderRadius:4,display:"flex",gap:8,alignItems:"center",background:xe===be?"var(--nice-primary-bg, #e8f0fe)":void 0},onMouseDown:we=>{we.preventDefault(),ke(te)},onMouseEnter:()=>ae(xe),children:[e.jsx("span",{style:{width:24,textAlign:"center"},children:te.icon}),e.jsx("span",{children:te.label})]},`${te.type}-${te.label}`))})]})]},m.id))})]}),Me&&e.jsxs("div",{className:"nice-doc-editor__ctx-menu",style:{position:"fixed",left:Me.x,top:Me.y,zIndex:1e3,background:"var(--bg-primary, #fff)",border:"1px solid var(--border-color, #ddd)",borderRadius:6,boxShadow:"0 4px 16px var(--nice-overlay-12, rgba(0, 0, 0, 0.12))",padding:4,minWidth:160},children:[e.jsx("div",{style:{padding:"6px 12px",cursor:"pointer"},onClick:()=>{Z(Me.idx),Ee(null)},children:"? Duplicate"}),e.jsx("div",{style:{padding:"6px 12px",cursor:"pointer"},onClick:()=>{pe(Me.idx),Ee(null)},children:"+ Insert below"}),e.jsx("div",{style:{padding:"6px 12px",cursor:"pointer"},onClick:()=>{re(Me.idx,-1),Ee(null)},children:"? Move up"}),e.jsx("div",{style:{padding:"6px 12px",cursor:"pointer"},onClick:()=>{re(Me.idx,1),Ee(null)},children:"? Move down"}),e.jsx("div",{style:{padding:"6px 12px",cursor:"pointer"},onClick:()=>{var m;Y(Me.idx,{locked:!((m=b[Me.idx])!=null&&m.locked)}),Ee(null)},children:($t=b[Me.idx])!=null&&$t.locked?"?? Unlock":"?? Lock"}),e.jsx("hr",{style:{margin:"2px 0",border:"none",borderTop:"1px solid var(--border-color, #eee)"}}),e.jsx("div",{style:{padding:"6px 12px",cursor:"pointer",color:"var(--nice-danger-dark, #d32f2f)"},onClick:()=>{U(Me.idx),Ee(null)},children:"?? Delete"})]}),z&&He&&e.jsxs("div",{className:"nice-doc-editor__footer",style:{padding:"4px 12px",fontSize:"0.75em",color:"var(--text-muted, #666)",borderTop:"1px solid var(--border-color, #eee)",display:"flex",gap:16},children:[e.jsxs("span",{children:[He.words," ",w("docEditor.words","words")]}),e.jsxs("span",{children:[He.chars," ",w("docEditor.chars","characters")]}),e.jsxs("span",{children:[b.length," ",w("docEditor.blocks","blocks")]}),e.jsxs("span",{children:["~",He.readingTime," ",w("docEditor.readingTime","min read")]})]})]})});xn.displayName="NiceDocumentEditor";const ja=["street","streetNumber","apartment","city","postalCode","state","country"],nt={street:"Street",streetNumber:"Number",apartment:"Apt/Suite",city:"City",postalCode:"Postal Code",state:"State/Province",country:"Country"},vn=a.forwardRef(({label:n,helperText:t,error:i,required:l,disabled:d,readOnly:f,size:_="md",name:S,id:M,className:R,style:K,accessMode:z,value:g={},onChange:C,fields:W=ja,placeholders:ne={},countries:Q,layout:J="vertical",countryFirst:h=!1,validatePostalCode:L},w)=>{const E=I.ml(z,M),X=E==="hidden";E==="disabled"&&(d=!0),E==="readOnly"&&(f=!0);const{t:b}=I.ue(),j=I.Xs(M),x=a.useCallback((v,c)=>{C==null||C({...g,[v]:c})},[g,C]),T=a.useMemo(()=>{if(L&&g.postalCode)return L(g.postalCode,g.country)},[L,g.postalCode,g.country]),A=a.useMemo(()=>h&&W.includes("country")?["country",...W.filter(v=>v!=="country")]:W,[W,h]),O=`nice-address nice-address--${J} nice-size-${_}`;return X?null:e.jsxs("div",{ref:w,id:j,className:`${O}${R?` ${R}`:""}${i?" nice-error":""}${d?" nice-disabled":""}`,style:K,role:"group","aria-label":n??b("address","Address"),children:[n&&e.jsxs("label",{className:"nice-address__label",children:[n,l&&e.jsx("span",{className:"nice-required",children:"*"})]}),e.jsx("div",{className:"nice-address__fields",children:A.map(v=>v==="country"&&Q?e.jsxs("div",{className:`nice-address__field nice-address__field--${v}`,children:[e.jsx("label",{className:"nice-address__field-label",children:b(v,nt[v])}),e.jsxs("select",{className:"nice-input nice-select",value:g.country??"",onChange:c=>x("country",c.target.value),disabled:d,"aria-label":b(v,nt[v]),children:[e.jsx("option",{value:"",children:ne.country??b("selectCountry","— Select country —")}),Q.map(c=>e.jsx("option",{value:c.code,children:c.name},c.code))]})]},v):e.jsxs("div",{className:`nice-address__field nice-address__field--${v}`,children:[e.jsx("label",{className:"nice-address__field-label",children:b(v,nt[v])}),e.jsx("input",{className:`nice-input${v==="postalCode"&&T?" nice-input--error":""}`,type:"text",name:S?`${S}.${v}`:v,value:g[v]??"",onChange:c=>x(v,c.target.value),placeholder:ne[v]??"",disabled:d,readOnly:f,"aria-label":b(v,nt[v])}),v==="postalCode"&&T&&e.jsx("span",{className:"nice-error-text",children:T})]},v))}),t&&e.jsx("span",{className:"nice-helper-text",children:t}),i&&typeof i=="string"&&e.jsx("span",{className:"nice-error-text",children:i})]})});vn.displayName="NiceAddressInput";const Ca=[{code:"PLN",symbol:"zł",name:"Polish Zloty"},{code:"EUR",symbol:"€",name:"Euro"},{code:"USD",symbol:"$",name:"US Dollar"},{code:"GBP",symbol:"£",name:"British Pound"},{code:"CZK",symbol:"Kč",name:"Czech Koruna"},{code:"CHF",symbol:"Fr",name:"Swiss Franc"}],yn=a.forwardRef(({label:n,helperText:t,error:i,required:l,disabled:d,readOnly:f,size:_="md",name:S,id:M,className:R,style:K,accessMode:z,value:g,onChange:C,onBlur:W,currency:ne="PLN",onCurrencyChange:Q,currencies:J=Ca,useMinorUnit:h=!1,min:L,max:w,locale:E,placeholder:X,showCurrencySelector:b},j)=>{const x=I.ml(z,M),T=x==="hidden";x==="disabled"&&(d=!0),x==="readOnly"&&(f=!0);const{t:A}=I.ue(),O=I.Xs(M),v=a.useMemo(()=>J.find(o=>o.code===ne)??J[0],[ne,J]),c=(v==null?void 0:v.decimals)??2,P=a.useMemo(()=>g==null?"":(h?g/Math.pow(10,c):g).toFixed(c),[g,h,c]),y=a.useCallback(o=>{const u=o.replace(/[^\d.,\-]/g,"").replace(",",".");if(u===""||u==="-"){C==null||C(null);return}const r=parseFloat(u);if(isNaN(r))return;const p=h?Math.round(r*Math.pow(10,c)):r;L!=null&&p<L||w!=null&&p>w||(C==null||C(p))},[C,h,c,L,w]),k=b??J.length>1,s=a.useMemo(()=>{if(g==null)return"";const o=h?g/Math.pow(10,c):g;try{return new Intl.NumberFormat(E,{style:"currency",currency:(v==null?void 0:v.code)??"USD",minimumFractionDigits:c}).format(o)}catch{return`${o.toFixed(c)} ${v==null?void 0:v.code}`}},[g,h,c,E,v]);return T?null:e.jsxs("div",{ref:j,id:O,className:`nice-currency nice-size-${_}${R?` ${R}`:""}${i?" nice-error":""}${d?" nice-disabled":""}`,style:K,children:[n&&e.jsxs("label",{className:"nice-currency__label",children:[n,l&&e.jsx("span",{className:"nice-required",children:"*"})]}),e.jsxs("div",{className:"nice-currency__row",children:[k&&e.jsx("select",{className:"nice-currency__select nice-select",value:ne,onChange:o=>Q==null?void 0:Q(o.target.value),disabled:d,"aria-label":A("currency","Currency"),children:J.map(o=>e.jsxs("option",{value:o.code,children:[o.symbol," ",o.code]},o.code))}),!k&&e.jsx("span",{className:"nice-currency__symbol",children:v==null?void 0:v.symbol}),e.jsx("input",{className:"nice-input nice-currency__amount",type:"text",inputMode:"decimal",name:S,value:P,onChange:o=>y(o.target.value),onBlur:W,placeholder:X??`0.${"0".repeat(c)}`,disabled:d,readOnly:f,"aria-label":A("amount","Amount")})]}),s&&g!=null&&e.jsx("span",{className:"nice-currency__formatted",children:s}),t&&e.jsx("span",{className:"nice-helper-text",children:t}),i&&typeof i=="string"&&e.jsx("span",{className:"nice-error-text",children:i})]})});yn.displayName="NiceCurrencyInput";let Na=1;function wa(n){return{id:`new-${Na++}`,description:"",quantity:1,unitPrice:0,vatRate:n,discount:0,unit:"szt."}}function _n(n){const t=n.quantity*n.unitPrice*(1-(n.discount??0)/100),i=Math.round(t*100)/100,l=Math.round(i*(n.vatRate??0)/100*100)/100;return{...n,netAmount:i,grossAmount:i+l}}function $a(n){const t=n.map(_n),i=t.reduce((S,M)=>S+(M.netAmount??0),0),l=t.reduce((S,M)=>S+(M.grossAmount??0),0),d=l-i,f=new Map;for(const S of t){const M=S.vatRate??0,R=f.get(M)??{base:0,amount:0};R.base+=S.netAmount??0,R.amount+=(S.grossAmount??0)-(S.netAmount??0),f.set(M,R)}const _=Array.from(f.entries()).map(([S,M])=>({rate:S,base:Math.round(M.base*100)/100,amount:Math.round(M.amount*100)/100}));return{totalNet:Math.round(i*100)/100,totalVat:Math.round(d*100)/100,totalGross:Math.round(l*100)/100,vatBreakdown:_}}const kn=a.forwardRef(({label:n,helperText:t,error:i,required:l,disabled:d,readOnly:f,size:_="md",name:S,id:M,className:R,style:K,accessMode:z,value:g=[],onChange:C,onTotalsChange:W,currencySymbol:ne="zł",defaultVatRate:Q=23,vatRates:J=[0,5,8,23],units:h=["szt.","h","kg","m","usł."],showDiscount:L=!0,showUnit:w=!0,showTotals:E=!0,editable:X=!0,maxLines:b},j)=>{const x=I.ml(z,M),T=x==="hidden";x==="disabled"&&(d=!0),x==="readOnly"&&(f=!0);const{t:A}=I.ue(),O=I.Xs(M),v=a.useMemo(()=>g.map(_n),[g]),c=a.useMemo(()=>$a(g),[g]);a.useEffect(()=>{W==null||W(c)},[c,W]);const P=a.useCallback((o,u,r)=>{const p=[...g];p[o]={...p[o],[u]:r},C==null||C(p)},[g,C]),y=a.useCallback(()=>{b&&g.length>=b||(C==null||C([...g,wa(Q)]))},[g,C,Q,b]),k=a.useCallback(o=>{C==null||C(g.filter((u,r)=>r!==o))},[g,C]),s=o=>`${o.toFixed(2)} ${ne}`;return T?null:e.jsxs("div",{ref:j,id:O,className:`nice-invoice-lines nice-size-${_}${R?` ${R}`:""}${i?" nice-error":""}${d?" nice-disabled":""}`,style:K,children:[n&&e.jsxs("label",{className:"nice-invoice-lines__label",children:[n,l&&e.jsx("span",{className:"nice-required",children:"*"})]}),e.jsxs("table",{className:"nice-invoice-lines__table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{className:"nice-il__th-num",children:"#"}),e.jsx("th",{className:"nice-il__th-desc",children:A("description","Description")}),e.jsx("th",{className:"nice-il__th-qty",children:A("qty","Qty")}),w&&e.jsx("th",{className:"nice-il__th-unit",children:A("unit","Unit")}),e.jsx("th",{className:"nice-il__th-price",children:A("unitPrice","Unit Price")}),L&&e.jsx("th",{className:"nice-il__th-disc",children:A("discount","Disc %")}),e.jsx("th",{className:"nice-il__th-vat",children:A("vat","VAT %")}),e.jsx("th",{className:"nice-il__th-net",children:A("net","Net")}),e.jsx("th",{className:"nice-il__th-gross",children:A("gross","Gross")}),X&&!f&&e.jsx("th",{className:"nice-il__th-actions"})]})}),e.jsx("tbody",{children:v.map((o,u)=>e.jsxs("tr",{children:[e.jsx("td",{className:"nice-il__cell-num",children:u+1}),e.jsx("td",{className:"nice-il__cell-desc",children:e.jsx("input",{className:"nice-input",type:"text",value:o.description,onChange:r=>P(u,"description",r.target.value),disabled:d,readOnly:f,placeholder:A("itemDescription","Item description")})}),e.jsx("td",{className:"nice-il__cell-qty",children:e.jsx("input",{className:"nice-input",type:"number",value:o.quantity,onChange:r=>P(u,"quantity",parseFloat(r.target.value)||0),disabled:d,readOnly:f,min:0,step:"any"})}),w&&e.jsx("td",{className:"nice-il__cell-unit",children:e.jsx("select",{className:"nice-select",value:o.unit??"",onChange:r=>P(u,"unit",r.target.value),disabled:d,children:h.map(r=>e.jsx("option",{value:r,children:r},r))})}),e.jsx("td",{className:"nice-il__cell-price",children:e.jsx("input",{className:"nice-input",type:"number",value:o.unitPrice,onChange:r=>P(u,"unitPrice",parseFloat(r.target.value)||0),disabled:d,readOnly:f,min:0,step:"0.01"})}),L&&e.jsx("td",{className:"nice-il__cell-disc",children:e.jsx("input",{className:"nice-input",type:"number",value:o.discount??0,onChange:r=>P(u,"discount",parseFloat(r.target.value)||0),disabled:d,readOnly:f,min:0,max:100})}),e.jsx("td",{className:"nice-il__cell-vat",children:e.jsx("select",{className:"nice-select",value:o.vatRate??0,onChange:r=>P(u,"vatRate",parseInt(r.target.value,10)),disabled:d,children:J.map(r=>e.jsxs("option",{value:r,children:[r,"%"]},r))})}),e.jsx("td",{className:"nice-il__cell-net",children:s(o.netAmount??0)}),e.jsx("td",{className:"nice-il__cell-gross",children:s(o.grossAmount??0)}),X&&!f&&e.jsx("td",{className:"nice-il__cell-actions",children:e.jsx("button",{type:"button",className:"nice-btn nice-btn--icon nice-btn--sm",onClick:()=>k(u),disabled:d,title:A("remove","Remove"),children:"✕"})})]},o.id))})]}),X&&!f&&e.jsxs("button",{type:"button",className:"nice-btn nice-btn--outlined nice-btn--sm nice-invoice-lines__add",onClick:y,disabled:d||b!=null&&g.length>=b,children:["+ ",A("addLine","Add line")]}),E&&e.jsxs("div",{className:"nice-invoice-lines__totals",children:[e.jsxs("div",{className:"nice-il__total-row",children:[e.jsxs("span",{children:[A("totalNet","Net total"),":"]}),e.jsx("span",{className:"nice-il__total-value",children:s(c.totalNet)})]}),c.vatBreakdown.map(o=>e.jsxs("div",{className:"nice-il__total-row nice-il__total-row--vat",children:[e.jsxs("span",{children:["VAT ",o.rate,"%:"]}),e.jsx("span",{className:"nice-il__total-value",children:s(o.amount)})]},o.rate)),e.jsxs("div",{className:"nice-il__total-row nice-il__total-row--gross",children:[e.jsxs("span",{children:[A("totalGross","Gross total"),":"]}),e.jsx("span",{className:"nice-il__total-value nice-il__total-value--gross",children:s(c.totalGross)})]})]}),t&&e.jsx("span",{className:"nice-helper-text",children:t}),i&&typeof i=="string"&&e.jsx("span",{className:"nice-error-text",children:i})]})});kn.displayName="NiceInvoiceLineEditor";const jn=a.forwardRef(({label:n,helperText:t,error:i,required:l,disabled:d,readOnly:f,size:_="md",name:S,id:M,className:R,style:K,accessMode:z,value:g=[],onChange:C,contacts:W=[],onSearch:ne,searchDelay:Q=300,multiple:J=!1,placeholder:h,onContactClick:L,maxSelections:w},E)=>{const X=I.ml(z,M),b=X==="hidden";X==="disabled"&&(d=!0),X==="readOnly"&&(f=!0);const{t:j}=I.ue(),x=I.Xs(M),[T,A]=a.useState(""),[O,v]=a.useState([]),[c,P]=a.useState(!1),[y,k]=a.useState(!1),s=a.useMemo(()=>{const p=[...W,...O],q=new Map(p.map(F=>[F.id,F]));return g.map(F=>q.get(F)).filter(Boolean)},[g,W,O]),o=a.useCallback(p=>{if(A(p),p.length<1){v([]),P(!1);return}if(ne){k(!0);const G=setTimeout(async()=>{const ie=await ne(p);v(ie),P(!0),k(!1)},Q);return()=>clearTimeout(G)}const q=p.toLowerCase(),F=W.filter(G=>{var ie,N;return G.name.toLowerCase().includes(q)||((ie=G.email)==null?void 0:ie.toLowerCase().includes(q))||((N=G.phone)==null?void 0:N.includes(p))});v(F),P(!0)},[ne,W,Q]),u=a.useCallback(p=>{if(J)if(g.includes(p.id))C==null||C(g.filter(q=>q!==p.id));else{if(w&&g.length>=w)return;C==null||C([...g,p.id])}else C==null||C([p.id]),P(!1),A("")},[g,C,J,w]),r=a.useCallback(p=>{C==null||C(g.filter(q=>q!==p))},[g,C]);return b?null:e.jsxs("div",{ref:E,id:x,className:`nice-contact-picker nice-size-${_}${R?` ${R}`:""}${i?" nice-error":""}${d?" nice-disabled":""}`,style:K,children:[n&&e.jsxs("label",{className:"nice-contact-picker__label",children:[n,l&&e.jsx("span",{className:"nice-required",children:"*"})]}),s.length>0&&e.jsx("div",{className:"nice-contact-picker__chips",children:s.map(p=>e.jsxs("span",{className:"nice-contact-picker__chip",onClick:()=>L==null?void 0:L(p),children:[p.avatarUrl&&e.jsx("img",{src:p.avatarUrl,alt:"",className:"nice-contact-picker__chip-avatar"}),e.jsx("span",{children:p.name}),!f&&e.jsx("button",{type:"button",className:"nice-contact-picker__chip-remove",onClick:q=>{q.stopPropagation(),r(p.id)},disabled:d,children:"×"})]},p.id))}),!f&&e.jsxs("div",{className:"nice-contact-picker__search",children:[e.jsx("input",{className:"nice-input",type:"text",value:T,onChange:p=>o(p.target.value),onFocus:()=>T.length>0&&P(!0),onBlur:()=>setTimeout(()=>P(!1),200),placeholder:h??j("searchContacts","Search contacts…"),disabled:d,"aria-label":j("searchContacts","Search contacts")}),y&&e.jsx("span",{className:"nice-contact-picker__spinner",children:"⏳"})]}),c&&O.length>0&&e.jsx("div",{className:"nice-contact-picker__dropdown",role:"listbox",children:O.map(p=>e.jsxs("div",{className:`nice-contact-picker__option${g.includes(p.id)?" nice-contact-picker__option--selected":""}`,role:"option","aria-selected":g.includes(p.id),onClick:()=>u(p),children:[p.avatarUrl&&e.jsx("img",{src:p.avatarUrl,alt:"",className:"nice-contact-picker__option-avatar"}),e.jsxs("div",{className:"nice-contact-picker__option-info",children:[e.jsx("span",{className:"nice-contact-picker__option-name",children:p.name}),p.subtitle&&e.jsx("span",{className:"nice-contact-picker__option-subtitle",children:p.subtitle}),p.email&&e.jsx("span",{className:"nice-contact-picker__option-email",children:p.email})]}),p.type&&e.jsx("span",{className:"nice-contact-picker__option-type",children:p.type==="person"?"👤":"🏢"})]},p.id))}),t&&e.jsx("span",{className:"nice-helper-text",children:t}),i&&typeof i=="string"&&e.jsx("span",{className:"nice-error-text",children:i})]})});jn.displayName="NiceContactPicker";const Ma=["highlight","underline","strikethrough","freehand","text","rect","arrow"],Sa={highlight:"🖍️",underline:"⎁",strikethrough:"S̶",freehand:"✏️",text:"T",rect:"▭",arrow:"→",stamp:"🔏"},Cn=a.forwardRef(({label:n,helperText:t,error:i,required:l,disabled:d,readOnly:f,size:_="md",id:S,className:M,style:R,accessMode:K,src:z,annotations:g=[],onAnnotationsChange:C,activeTool:W,onToolChange:ne,currentPage:Q=1,onPageChange:J,totalPages:h=1,defaultColor:L="var(--nice-warning, #ffff00)",tools:w=Ma,author:E,zoom:X=1,onZoomChange:b,onAnnotationClick:j,onAnnotationDelete:x},T)=>{const A=I.ml(K,S),O=A==="hidden";A==="disabled"&&(d=!0),A==="readOnly"&&(f=!0);const{t:v}=I.ue(),c=I.Xs(S),P=g.filter(s=>s.page===Q),y=a.useCallback(s=>{ne==null||ne(W===s?null:s)},[W,ne]),k=a.useCallback(s=>{if(f||!W||W==="freehand")return;const o=s.currentTarget.getBoundingClientRect(),u=(s.clientX-o.left)/o.width,r=(s.clientY-o.top)/o.height,p={id:`ann-${Date.now()}-${Math.random().toString(36).slice(2,8)}`,tool:W,page:Q,x:u,y:r,color:L,author:E,createdAt:new Date().toISOString(),text:W==="text"?"":void 0};C==null||C([...g,p])},[f,W,Q,L,E,g,C]);return O?null:e.jsxs("div",{ref:T,id:c,className:`nice-pdf-annotation nice-size-${_}${M?` ${M}`:""}${i?" nice-error":""}${d?" nice-disabled":""}`,style:R,children:[n&&e.jsxs("div",{className:"nice-pdf-annotation__label",children:[n,l&&e.jsx("span",{className:"nice-required",children:"*"})]}),!f&&e.jsxs("div",{className:"nice-pdf-annotation__toolbar",children:[w.map(s=>e.jsx("button",{type:"button",className:`nice-pdf-annotation__tool-btn${W===s?" nice-pdf-annotation__tool-btn--active":""}`,onClick:()=>y(s),disabled:d,title:v(`pdfTool_${s}`,s),children:Sa[s]},s)),e.jsx("span",{className:"nice-pdf-annotation__toolbar-sep"}),e.jsx("button",{type:"button",disabled:d,onClick:()=>b==null?void 0:b(Math.max(.25,X-.25)),title:v("zoomOut","Zoom out"),children:"−"}),e.jsxs("span",{className:"nice-pdf-annotation__zoom",children:[Math.round(X*100),"%"]}),e.jsx("button",{type:"button",disabled:d,onClick:()=>b==null?void 0:b(Math.min(4,X+.25)),title:v("zoomIn","Zoom in"),children:"+"})]}),e.jsxs("div",{className:"nice-pdf-annotation__viewport",style:{transform:`scale(${X})`,transformOrigin:"top left"},children:[e.jsx("iframe",{src:z,className:"nice-pdf-annotation__frame",title:v("pdfViewer","PDF Viewer")}),e.jsx("div",{className:"nice-pdf-annotation__layer",onClick:k,children:P.map(s=>e.jsxs("div",{className:`nice-pdf-annotation__mark nice-pdf-annotation__mark--${s.tool}`,style:{left:`${s.x*100}%`,top:`${s.y*100}%`,backgroundColor:s.color},onClick:o=>{o.stopPropagation(),j==null||j(s)},title:s.text??s.tool,children:[s.text&&e.jsx("span",{children:s.text}),!f&&e.jsx("button",{type:"button",className:"nice-pdf-annotation__mark-delete",onClick:o=>{o.stopPropagation(),x==null||x(s.id)},children:"×"})]},s.id))})]}),e.jsxs("div",{className:"nice-pdf-annotation__pager",children:[e.jsx("button",{type:"button",disabled:d||Q<=1,onClick:()=>J==null?void 0:J(Q-1),children:"◀"}),e.jsx("span",{children:v("pageOf","{page} / {total}").replace("{page}",String(Q)).replace("{total}",String(h))}),e.jsx("button",{type:"button",disabled:d||Q>=h,onClick:()=>J==null?void 0:J(Q+1),children:"▶"})]}),t&&e.jsx("span",{className:"nice-helper-text",children:t}),i&&typeof i=="string"&&e.jsx("span",{className:"nice-error-text",children:i})]})});Cn.displayName="NicePDFAnnotationEditor";const Nn=a.forwardRef(({label:n,helperText:t,error:i,disabled:l,readOnly:d,size:f="md",id:_,className:S,style:M,accessMode:R,pages:K,selectedPageId:z,content:g="",contentFormat:C="html",editing:W=!1,onPageSelect:ne,onContentChange:Q,onSave:J,onCreatePage:h,onDeletePage:L,onEditToggle:w,onVersionHistory:E,sidebarWidth:X=260,sidebarCollapsed:b=!1,onSidebarToggle:j,searchable:x=!0,onSearch:T},A)=>{const O=I.ml(R,_),v=O==="hidden";O==="disabled"&&(l=!0),O==="readOnly"&&(d=!0);const{t:c}=I.ue(),P=I.Xs(_),[y,k]=a.useState(""),[s,o]=a.useState(""),[u,r]=a.useState(!1),p=a.useMemo(()=>{const ie=N=>{for(const H of N){if(H.id===z)return H;if(H.children){const B=ie(H.children);if(B)return B}}};return ie(K)},[K,z]),q=a.useCallback(ie=>{k(ie),T==null||T(ie)},[T]),F=a.useCallback(()=>{s.trim()&&(h==null||h(z??null,s.trim()),o(""),r(!1))},[s,z,h]),G=(ie,N=0)=>e.jsx("ul",{className:"nice-wiki__tree",style:{paddingLeft:N>0?16:0},children:ie.map(H=>{var B;return e.jsxs("li",{className:"nice-wiki__tree-item",children:[e.jsxs("div",{className:`nice-wiki__tree-node${H.id===z?" nice-wiki__tree-node--active":""}${H.isDraft?" nice-wiki__tree-node--draft":""}`,onClick:()=>ne==null?void 0:ne(H),role:"treeitem","aria-selected":H.id===z,children:[e.jsx("span",{className:"nice-wiki__tree-icon",children:(B=H.children)!=null&&B.length?"📁":"📄"}),e.jsx("span",{className:"nice-wiki__tree-title",children:H.title}),H.isDraft&&e.jsx("span",{className:"nice-wiki__tree-draft",children:c("draft","Draft")})]}),H.children&&H.children.length>0&&G(H.children,N+1)]},H.id)})});return v?null:e.jsxs("div",{ref:A,id:P,className:`nice-wiki nice-size-${f}${S?` ${S}`:""}${l?" nice-disabled":""}`,style:M,children:[!b&&e.jsxs("aside",{className:"nice-wiki__sidebar",style:{width:X},children:[e.jsxs("div",{className:"nice-wiki__sidebar-header",children:[e.jsx("span",{className:"nice-wiki__sidebar-title",children:n??c("wiki","Wiki")}),j&&e.jsx("button",{type:"button",className:"nice-wiki__sidebar-toggle",onClick:()=>j(!0),children:"«"})]}),x&&e.jsx("input",{type:"text",className:"nice-input nice-wiki__search",value:y,onChange:ie=>q(ie.target.value),placeholder:c("searchPages","Search pages…"),disabled:l}),e.jsx("div",{className:"nice-wiki__page-tree",role:"tree",children:G(K)}),h&&!d&&e.jsx("div",{className:"nice-wiki__sidebar-footer",children:u?e.jsxs("div",{className:"nice-wiki__create-form",children:[e.jsx("input",{type:"text",className:"nice-input",value:s,onChange:ie=>o(ie.target.value),placeholder:c("pageTitle","Page title"),onKeyDown:ie=>ie.key==="Enter"&&F(),disabled:l}),e.jsx("button",{type:"button",disabled:l||!s.trim(),onClick:F,children:"✓"}),e.jsx("button",{type:"button",onClick:()=>r(!1),children:"✕"})]}):e.jsxs("button",{type:"button",className:"nice-wiki__add-page",onClick:()=>r(!0),disabled:l,children:["+ ",c("newPage","New page")]})})]}),b&&j&&e.jsx("button",{type:"button",className:"nice-wiki__sidebar-expand",onClick:()=>j(!1),children:"»"}),e.jsx("main",{className:"nice-wiki__content",children:p?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"nice-wiki__content-header",children:[e.jsx("h1",{className:"nice-wiki__page-title",children:p.title}),e.jsxs("div",{className:"nice-wiki__content-actions",children:[w&&!d&&e.jsx("button",{type:"button",disabled:l,onClick:()=>w(!W),children:W?c("preview","Preview"):c("edit","Edit")}),E&&e.jsx("button",{type:"button",disabled:l,onClick:()=>E(p.id),children:c("history","History")}),L&&!d&&e.jsx("button",{type:"button",className:"nice-btn--danger",disabled:l,onClick:()=>L(p.id),children:c("delete","Delete")})]})]}),p.updatedAt&&e.jsxs("div",{className:"nice-wiki__page-meta",children:[p.updatedBy&&e.jsxs("span",{children:[c("lastEditedBy","Last edited by")," ",p.updatedBy]}),e.jsx("span",{children:new Date(p.updatedAt).toLocaleDateString()})]}),W?e.jsxs("div",{className:"nice-wiki__editor",children:[e.jsx("textarea",{className:"nice-wiki__editor-textarea",value:g,onChange:ie=>Q==null?void 0:Q(ie.target.value),disabled:l}),J&&e.jsx("button",{type:"button",className:"nice-btn nice-btn--primary",disabled:l,onClick:()=>J(p.id,g),children:c("save","Save")})]}):e.jsx("div",{className:"nice-wiki__viewer",children:C==="html"?e.jsx("div",{className:"nice-wiki__html",dangerouslySetInnerHTML:{__html:I.$s(g)}}):e.jsx("pre",{className:"nice-wiki__markdown",children:g})})]}):e.jsx("div",{className:"nice-wiki__empty",children:e.jsx("p",{children:c("selectPage","Select a page from the sidebar or create a new one.")})})}),t&&e.jsx("span",{className:"nice-helper-text",children:t}),i&&typeof i=="string"&&e.jsx("span",{className:"nice-error-text",children:i})]})});Nn.displayName="NiceWiki";const Ea=[{code:"PL",label:"Polska",prefix:"PL",pattern:/^\d{10}$/,placeholder:"1234567890"},{code:"DE",label:"Deutschland",prefix:"DE",pattern:/^\d{9}$/,placeholder:"123456789"},{code:"GB",label:"United Kingdom",prefix:"GB",pattern:/^\d{9}(\d{3})?$/,placeholder:"123456789"},{code:"FR",label:"France",prefix:"FR",pattern:/^[A-Z0-9]{2}\d{9}$/,placeholder:"XX123456789"},{code:"CZ",label:"Česko",prefix:"CZ",pattern:/^\d{8,10}$/,placeholder:"12345678"},{code:"SK",label:"Slovensko",prefix:"SK",pattern:/^\d{10}$/,placeholder:"1234567890"},{code:"IT",label:"Italia",prefix:"IT",pattern:/^\d{11}$/,placeholder:"12345678901"},{code:"ES",label:"España",prefix:"ES",pattern:/^[A-Z0-9]\d{7}[A-Z0-9]$/,placeholder:"X1234567X"}],wn=a.forwardRef(({label:n,helperText:t,error:i,required:l,disabled:d,readOnly:f,size:_="md",name:S,id:M,className:R,style:K,accessMode:z,value:g="",onChange:C,countryCode:W="PL",onCountryChange:ne,countries:Q=Ea,showCountrySelector:J=!0,autoPrefixVat:h=!0,validationResult:L,onValidateRequest:w,placeholder:E},X)=>{const b=I.ml(z,M),j=b==="hidden";b==="disabled"&&(d=!0),b==="readOnly"&&(f=!0);const{t:x}=I.ue(),T=I.Xs(M),A=a.useMemo(()=>Q.find(y=>y.code===W)??Q[0],[Q,W]),O=a.useCallback(y=>{let k=y.toUpperCase();return A&&k.startsWith(A.prefix)&&(k=k.slice(A.prefix.length)),A?A.pattern.test(k):k.length>0},[A]),v=a.useCallback(y=>{const k=y.target.value.replace(/\s/g,"");C==null||C(k,O(k))},[C,O]),c=h&&g&&A&&!g.toUpperCase().startsWith(A.prefix)?`${A.prefix}${g}`:g,P=O(g);return j?null:e.jsxs("div",{ref:X,id:T,className:`nice-vat-input nice-size-${_}${R?` ${R}`:""}${i||!P&&g.length>0?" nice-error":""}${d?" nice-disabled":""}`,style:K,children:[n&&e.jsxs("label",{className:"nice-vat-input__label",htmlFor:`${T}-input`,children:[n,l&&e.jsx("span",{className:"nice-required",children:"*"})]}),e.jsxs("div",{className:"nice-vat-input__row",children:[J&&e.jsx("select",{className:"nice-vat-input__country",value:W,onChange:y=>ne==null?void 0:ne(y.target.value),disabled:d||f,children:Q.map(y=>e.jsx("option",{value:y.code,children:y.prefix},y.code))}),e.jsx("input",{id:`${T}-input`,className:"nice-input nice-vat-input__field",type:"text",name:S,value:g,onChange:v,readOnly:f,disabled:d,placeholder:E??(A==null?void 0:A.placeholder),required:l,"aria-invalid":!P&&g.length>0}),w&&g.length>0&&e.jsx("button",{type:"button",className:"nice-vat-input__verify",disabled:d||!P,onClick:()=>w(h?c:g,W),title:x("verifyVat","Verify VAT number"),children:"🔍"})]}),L&&e.jsxs("div",{className:`nice-vat-input__result nice-vat-input__result--${L.valid?"valid":"invalid"}`,children:[L.valid?"✅":"❌"," ",L.companyName??L.error??(L.valid?x("vatValid","VAT number valid"):x("vatInvalid","VAT number invalid"))]}),t&&e.jsx("span",{className:"nice-helper-text",children:t}),i&&typeof i=="string"&&e.jsx("span",{className:"nice-error-text",children:i})]})});wn.displayName="NiceVatInput";const Ta=[{id:"pl-23",label:"23%",rate:.23,countryCode:"PL",category:"standard",isDefault:!0},{id:"pl-8",label:"8%",rate:.08,countryCode:"PL",category:"reduced"},{id:"pl-5",label:"5%",rate:.05,countryCode:"PL",category:"reduced"},{id:"pl-0",label:"0%",rate:0,countryCode:"PL",category:"zero"},{id:"pl-zw",label:"zw.",rate:0,countryCode:"PL",category:"exempt"},{id:"pl-np",label:"n.p.",rate:0,countryCode:"PL",category:"exempt"}],$n=a.forwardRef(({label:n,helperText:t,error:i,required:l,disabled:d,readOnly:f,size:_="md",name:S,id:M,className:R,style:K,accessMode:z,value:g,onChange:C,rates:W,countryCode:ne,placeholder:Q,showPercentage:J=!0},h)=>{const L=I.ml(z,M),w=L==="hidden";L==="disabled"&&(d=!0),L==="readOnly"&&(f=!0);const{t:E}=I.ue(),X=I.Xs(M),b=a.useMemo(()=>{const x=W??Ta;return ne?x.filter(T=>!T.countryCode||T.countryCode===ne):x},[W,ne]),j=a.useCallback(x=>{const T=x.target.value,A=b.find(O=>O.id===T);A&&(C==null||C(T,A))},[C,b]);return w?null:e.jsxs("div",{ref:h,id:X,className:`nice-tax-rate nice-size-${_}${R?` ${R}`:""}${i?" nice-error":""}${d?" nice-disabled":""}`,style:K,children:[n&&e.jsxs("label",{className:"nice-tax-rate__label",htmlFor:`${X}-select`,children:[n,l&&e.jsx("span",{className:"nice-required",children:"*"})]}),e.jsxs("select",{id:`${X}-select`,className:"nice-select nice-tax-rate__select",name:S,value:g??"",onChange:j,disabled:d||f,required:l,children:[e.jsx("option",{value:"",disabled:!0,children:Q??E("selectRate","Select rate…")}),b.map(x=>e.jsxs("option",{value:x.id,children:[x.label,J&&x.category!=="exempt"?` (${(x.rate*100).toFixed(0)}%)`:""]},x.id))]}),t&&e.jsx("span",{className:"nice-helper-text",children:t}),i&&typeof i=="string"&&e.jsx("span",{className:"nice-error-text",children:i})]})});$n.displayName="NiceTaxRatePicker";const Ra={asset:"var(--nice-color-info, #5bc0de)",liability:"var(--nice-color-warning, #f0ad4e)",equity:"var(--nice-color-success, #5cb85c)",revenue:"var(--nice-color-primary, #337ab7)",expense:"var(--nice-color-error, #d9534f)"},Mn=a.forwardRef(({label:n,helperText:t,error:i,required:l,disabled:d,readOnly:f,size:_="md",name:S,id:M,className:R,style:K,accessMode:z,value:g,onChange:C,accounts:W,treeView:ne=!1,placeholder:Q,searchable:J=!0,showType:h=!0,onSearch:L},w)=>{const E=I.ml(z,M),X=E==="hidden";E==="disabled"&&(d=!0),E==="readOnly"&&(f=!0);const{t:b}=I.ue(),j=I.Xs(M),[x,T]=a.useState(""),[A,O]=a.useState(!1),v=a.useMemo(()=>{const s=o=>{for(const u of o){if(u.code===g)return u;if(u.children){const r=s(u.children);if(r)return r}}};return s(W)},[W,g]),c=a.useMemo(()=>{const s=[],o=u=>{for(const r of u)s.push(r),r.children&&o(r.children)};return o(W),s},[W]),P=a.useMemo(()=>{if(!x)return c;const s=x.toLowerCase();return c.filter(o=>o.code.toLowerCase().includes(s)||o.name.toLowerCase().includes(s))},[c,x]),y=a.useCallback(s=>{T(s),L==null||L(s),O(!0)},[L]),k=a.useCallback(s=>{C==null||C(s.code,s),O(!1),T("")},[C]);return X?null:e.jsxs("div",{ref:w,id:j,className:`nice-account-picker nice-size-${_}${R?` ${R}`:""}${i?" nice-error":""}${d?" nice-disabled":""}`,style:K,children:[n&&e.jsxs("label",{className:"nice-account-picker__label",htmlFor:`${j}-input`,children:[n,l&&e.jsx("span",{className:"nice-required",children:"*"})]}),e.jsx("div",{className:"nice-account-picker__control",children:J&&!f?e.jsx("input",{id:`${j}-input`,className:"nice-input",type:"text",value:A?x:v?`${v.code} — ${v.name}`:"",onChange:s=>y(s.target.value),onFocus:()=>{T(""),O(!0)},onBlur:()=>setTimeout(()=>O(!1),200),placeholder:Q??b("searchAccount","Search account…"),disabled:d,required:l}):e.jsx("div",{className:"nice-account-picker__display",children:v?`${v.code} — ${v.name}`:Q??b("selectAccount","Select account…")})}),A&&P.length>0&&e.jsx("div",{className:"nice-account-picker__dropdown",role:"listbox",children:P.map(s=>e.jsxs("div",{className:`nice-account-picker__option${s.code===g?" nice-account-picker__option--selected":""}${s.isActive===!1?" nice-account-picker__option--inactive":""}`,role:"option","aria-selected":s.code===g,onClick:()=>k(s),children:[h&&s.type&&e.jsx("span",{className:"nice-account-picker__type",style:{color:Ra[s.type]},title:s.type,children:"●"}),e.jsx("span",{className:"nice-account-picker__code",children:s.code}),e.jsx("span",{className:"nice-account-picker__name",children:s.name})]},s.code))}),t&&e.jsx("span",{className:"nice-helper-text",children:t}),i&&typeof i=="string"&&e.jsx("span",{className:"nice-error-text",children:i})]})});Mn.displayName="NiceAccountPicker";const Sn=a.forwardRef(({label:n,helperText:t,error:i,required:l,disabled:d,readOnly:f,size:_="md",id:S,className:M,style:R,accessMode:K,mode:z="manual",onScan:g,onModeChange:C,beepOnScan:W=!0,beepFrequency:ne=1800,beepDuration:Q=150,placeholder:J,scanHistory:h=[],showHistory:L=!0,maxHistory:w=10,autoFocus:E=!0,onCameraFrame:X},b)=>{const j=I.ml(K,S),x=j==="hidden";j==="disabled"&&(d=!0),j==="readOnly"&&(f=!0);const{t:T}=I.ue(),A=I.Xs(S),[O,v]=a.useState(""),c=a.useRef(null),P=a.useRef(null),y=a.useCallback(()=>{if(W)try{P.current||(P.current=new AudioContext);const o=P.current,u=o.createOscillator(),r=o.createGain();u.connect(r),r.connect(o.destination),u.frequency.value=ne,u.type="square",r.gain.value=.3,u.start(),u.stop(o.currentTime+Q/1e3)}catch{}},[W,ne,Q]),k=a.useCallback(()=>{var o;O.trim()&&(y(),g==null||g({value:O.trim(),format:"manual",scannedAt:new Date}),v(""),(o=c.current)==null||o.focus())},[O,g,y]),s=h.slice(0,w);return x?null:e.jsxs("div",{ref:b,id:A,className:`nice-scanner nice-size-${_}${M?` ${M}`:""}${i?" nice-error":""}${d?" nice-disabled":""}`,style:R,children:[n&&e.jsxs("div",{className:"nice-scanner__label",children:[n,l&&e.jsx("span",{className:"nice-required",children:"*"})]}),e.jsxs("div",{className:"nice-scanner__modes",children:[e.jsxs("button",{type:"button",className:`nice-scanner__mode-btn${z==="camera"?" nice-scanner__mode-btn--active":""}`,onClick:()=>C==null?void 0:C("camera"),disabled:d,children:["📷 ",T("camera","Camera")]}),e.jsxs("button",{type:"button",className:`nice-scanner__mode-btn${z==="manual"?" nice-scanner__mode-btn--active":""}`,onClick:()=>C==null?void 0:C("manual"),disabled:d,children:["⌨️ ",T("manual","Manual")]})]}),z==="camera"&&e.jsx("div",{className:"nice-scanner__camera",children:e.jsx("div",{className:"nice-scanner__viewfinder",children:e.jsxs("div",{className:"nice-scanner__viewfinder-overlay",children:[e.jsx("span",{children:"📷"}),e.jsx("p",{children:T("cameraPlaceholder","Camera preview — connect scanner adapter")})]})})}),z==="manual"&&!f&&e.jsxs("div",{className:"nice-scanner__manual",children:[e.jsx("input",{ref:c,className:"nice-input nice-scanner__input",type:"text",value:O,onChange:o=>v(o.target.value),onKeyDown:o=>o.key==="Enter"&&k(),placeholder:J??T("enterCode","Enter or scan code…"),disabled:d,autoFocus:E}),e.jsx("button",{type:"button",className:"nice-scanner__submit",onClick:k,disabled:d||!O.trim(),children:"✓"})]}),L&&s.length>0&&e.jsxs("div",{className:"nice-scanner__history",children:[e.jsx("div",{className:"nice-scanner__history-label",children:T("recentScans","Recent scans")}),s.map((o,u)=>e.jsxs("div",{className:"nice-scanner__history-item",children:[e.jsx("span",{className:"nice-scanner__history-value",children:o.value}),o.format&&e.jsx("span",{className:"nice-scanner__history-format",children:o.format}),e.jsx("span",{className:"nice-scanner__history-time",children:o.scannedAt.toLocaleTimeString()})]},u))]}),t&&e.jsx("span",{className:"nice-helper-text",children:t}),i&&typeof i=="string"&&e.jsx("span",{className:"nice-error-text",children:i})]})});Sn.displayName="NiceScannerControl";const En=a.forwardRef(({label:n,helperText:t,error:i,required:l,disabled:d,readOnly:f,size:_="md",id:S,className:M,style:R,accessMode:K,value:z="",onChange:g,onComplete:C,length:W=4,masked:ne=!0,showKeypad:Q=!1,autoSubmit:J=!0,shake:h=!1,placeholderChar:L="·"},w)=>{const E=I.ml(K,S),X=E==="hidden";E==="disabled"&&(d=!0),E==="readOnly"&&(f=!0);const{t:b}=I.ue(),j=I.Xs(S),x=a.useRef([]),[T,A]=a.useState(!1);a.useEffect(()=>{if(h){A(!0);const y=setTimeout(()=>A(!1),500);return()=>clearTimeout(y)}},[h]);const O=z.split("").slice(0,W);for(;O.length<W;)O.push("");const v=a.useCallback((y,k)=>{var u;const s=[...O];s[y]=k;const o=s.join("");g==null||g(o),k&&y<W-1&&((u=x.current[y+1])==null||u.focus()),J&&o.length===W&&o.indexOf("")===-1&&(C==null||C(o))},[O,W,g,C,J]),c=a.useCallback((y,k)=>{var s,o,u;y.key==="Backspace"&&!O[k]&&k>0&&((s=x.current[k-1])==null||s.focus(),v(k-1,"")),y.key==="ArrowLeft"&&k>0&&((o=x.current[k-1])==null||o.focus()),y.key==="ArrowRight"&&k<W-1&&((u=x.current[k+1])==null||u.focus())},[O,W,v]),P=a.useCallback(y=>{var k,s,o;if(y==="clear"){g==null||g(""),(k=x.current[0])==null||k.focus();return}if(y==="backspace"){const u=z.slice(0,-1);g==null||g(u);const r=Math.max(0,u.length-1);(s=x.current[r])==null||s.focus();return}if(z.length<W){const u=z+y;g==null||g(u),u.length<W&&((o=x.current[u.length])==null||o.focus()),J&&u.length===W&&(C==null||C(u))}},[z,W,g,C,J]);return X?null:e.jsxs("div",{ref:w,id:j,className:`nice-pin nice-size-${_}${T?" nice-pin--shake":""}${M?` ${M}`:""}${i?" nice-error":""}${d?" nice-disabled":""}`,style:R,children:[n&&e.jsxs("label",{className:"nice-pin__label",children:[n,l&&e.jsx("span",{className:"nice-required",children:"*"})]}),e.jsx("div",{className:"nice-pin__boxes",children:O.map((y,k)=>e.jsx("input",{ref:s=>{x.current[k]=s},className:"nice-pin__box",type:ne?"password":"text",inputMode:"numeric",maxLength:1,value:y,onChange:s=>{const o=s.target.value.replace(/\D/g,"");o.length<=1&&v(k,o)},onKeyDown:s=>c(s,k),disabled:d,readOnly:f,placeholder:L,"aria-label":`${b("digit","Digit")} ${k+1}`},k))}),Q&&!f&&e.jsx("div",{className:"nice-pin__keypad",children:["1","2","3","4","5","6","7","8","9","clear","0","backspace"].map(y=>e.jsx("button",{type:"button",className:`nice-pin__key${y==="clear"||y==="backspace"?" nice-pin__key--action":""}`,onClick:()=>P(y),disabled:d,children:y==="clear"?"C":y==="backspace"?"⌫":y},y))}),t&&e.jsx("span",{className:"nice-helper-text",children:t}),i&&typeof i=="string"&&e.jsx("span",{className:"nice-error-text",children:i})]})});En.displayName="NicePinCodeInput";exports.$=Vt;exports.A=En;exports.B=qn;exports.C=Sn;exports.E=bn;exports.F=$n;exports.G=cn;exports.H=wn;exports.I=Nn;exports.L=Yt;exports.M=pn;exports.O=hn;exports.P=rt;exports.Q=at;exports.R=Qt;exports.S=Ge;exports.T=Xt;exports.U=xt;exports.V=Be;exports.W=Je;exports.X=Se;exports.Y=qt;exports.Z=Jt;exports._=Bt;exports.a=Mn;exports.a0=_t;exports.a1=it;exports.a2=Yn;exports.a3=sa;exports.b=vn;exports.c=tn;exports.d=Ct;exports.f=Zt;exports.g=jn;exports.i=yn;exports.j=Un;exports.k=xn;exports.l=Vn;exports.n=en;exports.o=jt;exports.q=mn;exports.r=fn;exports.s=nn;exports.t=kn;exports.u=rn;exports.v=Hn;exports.w=gn;exports.x=ln;exports.y=Cn;exports.z=dn;