import{r as e,j as a}from"./vendor-react-Co0R0q1H.js";import{b as c,c as s}from"./keycap-sfx-CAsrNe23.js";import{Z as n}from"./index-nE6cslhy.js";const d={a:"24,3 76,3 83,7 76,11 24,11 17,7",b:"88,22 93,27 93,71 88,76 83,71 83,27",c:"88,106 93,111 93,155 88,160 83,155 83,111",d:"24,171 76,171 83,175 76,179 24,179 17,175",e:"12,106 17,111 17,155 12,160 7,155 7,111",f:"12,22 17,27 17,71 12,76 7,71 7,27",g:"24,86 76,86 83,91 76,96 24,96 17,91"},t=Object.keys(d),r={0:"abcdef",1:"bc",2:"abdeg",3:"abcdg",4:"bcfg",5:"acdfg",6:"acdefg",7:"abc",8:"abcdefg",9:"abcdfg",A:"abcefg",B:"cdefg",C:"adef",D:"bcdeg",E:"adefg",F:"aefg",G:"acdef",H:"bcefg",I:"ef",J:"bcde",L:"def",M:"abcefg",N:"ceg",O:"abcdef",P:"abefg",Q:"abcfg",R:"eg",S:"acdfg",T:"defg",U:"bcdef",V:"cde",Y:"bcdfg",Z:"abdeg",a:"abcefg",b:"cdefg",c:"deg",d:"bcdeg",e:"adefg",f:"aefg",g:"abcdfg",h:"cefg",i:"c",j:"bcde",l:"def",m:"abcef",n:"ceg",o:"cdeg",p:"abefg",r:"eg",s:"acdfg",t:"defg",u:"cde",v:"cde",y:"bcdfg"," ":"",_:"d","-":"g","=":"dg","°":"abfg",'"':"bf","'":"f","(":"adef",")":"abcd","[":"adef","]":"abcd","!":"bc",".":"d"};function l(e,a){const c=Array.from(e).map(e=>r[e.toUpperCase()]??r[e]??""),s=Math.max(0,(a??0)-e.length);for(let n=0;n<s;n++)c.push("");return c}function i({text:c,color:s="currentColor",size:n=18,minChars:r,noCycle:i=!1,className:o}){const g=Math.round(n*(100/182)),f="light"===document.documentElement.dataset.mode?.08:.16,[b,u]=e.useState(null);e.useEffect(()=>{if(i)return;const e=l(c,r),a=6+2*(e.length-1);let s,n=0,d=!1;const o=()=>{d||(n++,n>=a?u(null):(u(e.map((e,a)=>n>=6+2*a?e:t.filter(()=>Math.random()>.45).join(""))),s=setTimeout(o,56)))};return o(),()=>{d=!0,clearTimeout(s)}},[c,r,i]);const m=l(c,r),p=b??m;return a.jsxs("span",{className:"seven-seg"+(o?` ${o}`:""),children:[p.map((e,c)=>((e,c)=>a.jsx("svg",{viewBox:"0 0 100 182",width:g,height:n,className:"seven-seg__char","aria-hidden":"true",children:t.map(c=>a.jsx("polygon",{points:d[c],fill:s,stroke:s,strokeWidth:4,strokeLinejoin:"round",opacity:e.includes(c)?1:f},c))},c))(e,`${c}-${e}`)),a.jsx("span",{className:"sr-only",children:c})]})}const o={grey:"/assets/keycap.svg",red:"/assets/keycap-red.svg"},g=n[900];function f({icon:n,variant:d="grey",onClick:t,onPress:r,sentDuration:l=2e3,title:i,disabled:f=!1,className:b,iconColor:u=g,iconActiveColor:m="#FFDEB0",indicators:p}){const h=!!r,[y,k]=e.useState("idle"),[j,v]=e.useState(!1),x=e.useRef(),N=h?"held"===y:j,C=h&&("sending"===y||"sent"===y),$=h?"held"===y||"sending"===y:j;e.useEffect(()=>()=>clearTimeout(x.current),[]);const _=e.useCallback(()=>{f||C||(c(),h?k("held"):v(!0))},[f,C,h]),T=e.useCallback(async()=>{if(h){if("held"!==y)return;s(),k("sending");const e=await r();k(e?"sent":"idle"),e&&(x.current=setTimeout(()=>k("idle"),l))}else{if(!j)return;v(!1),s(),null==t||t()}},[h,y,r,l,j,t]),M=e.useCallback(()=>{h?"held"===y&&(s(),k("idle")):(j&&s(),v(!1))},[h,y,j]),E=a.jsx("button",{onMouseDown:_,onMouseUp:T,onMouseLeave:M,onTouchStart:_,onTouchEnd:T,onTouchCancel:M,disabled:f||C,className:`keycap-btn${"red"===d?" keycap-btn--red-cap":""}${$?" keycap-btn--pressed":""}${b&&!p?` ${b}`:""}`,title:i,children:a.jsxs("div",{className:"keycap-wrap",children:[a.jsx("img",{src:o[d],alt:"",className:"keycap-btn__img",draggable:!1}),a.jsx("span",{className:"keycap-icon-overlay",style:{color:N||"sending"===y?m:u},children:n})]})});return(null==p?void 0:p.length)?a.jsxs("div",{className:"keycap-group"+(b?` ${b}`:""),children:[E,a.jsx("div",{className:"indicator-key-pair",children:p.map(e=>{const c=e.trackPress?y:e.active?"active":"idle";return a.jsxs("div",{className:"indicator-key"+("idle"!==c?` indicator-key--${c}`:""),children:[a.jsx("span",{className:"indicator-key__label",children:e.label}),a.jsx("span",{className:"indicator-key__led"})]},e.label)})})]}):E}export{f as K,i as S};
