1import{K as e,Y as t,o as n,t as r}from"./jsx-runtime-vrPXwdFF.js";import{M as i}from"./useValueAsRef-DjOXBW7J.js";import{a,n as o,o as s,r as c,t as l}from"./jsonld-jP1ryWsw.js";import{a as u,b as d,d as f,n as p,r as m}from"./hooks-RrVsvdAa.js";import{n as h}from"./number-C5_5n4Oi.js";import{n as g,t as _}from"./trash-2-YF4DRHPK.js";var v=t(e(),1);function y(e){return e.length===0?1:e.reduce((e,[t,n])=>n===0?0:t/n*e,1)}function b(e){return e===0?0:1/e}var x=r(),S=`/ratio`,C=`FRC & FTC Gear Ratio Calculator | ReCalc`,w=`Ratio Calculator`,T=`Calculate gear, belt, and chain drive ratios for FRC and FTC robot mechanisms. Chain multi-stage reduction calculations.`;function E(){return[...a({path:S,title:C,description:T}),{"script:ld+json":o(c({url:s(S),name:w,description:T,breadcrumbLabel:w}),l({url:s(S),name:w,description:T}))}]}var D=0,O=()=>`pair-${D++}`,k={ratioPairs:f.withDefault([[18,72],[24,48]])};function A({children:e}){return(0,x.jsx)(`p`,{className:`text-xs font-semibold tracking-widest text-muted-foreground uppercase`,children:e})}var j=n(function(){let e=p(k),[t,n]=(0,v.useState)(()=>e.ratioPairs.map(e=>({id:O(),pair:e}))),r=(0,v.useMemo)(()=>t.map(e=>e.pair),[t]),a=(0,v.useMemo)(()=>y(r),[r]),o=(0,v.useMemo)(()=>b(a),[a]),s=(0,v.useCallback)((e,t,r)=>{n(n=>n.map(n=>n.id===e?{...n,pair:[t,r]}:n))},[]),c=(0,v.useCallback)(()=>{n(e=>[...e,{id:O(),pair:[1,1]}])},[]),l=(0,v.useCallback)(e=>{n(t=>t.length>1?t.filter(t=>t.id!==e):t)},[]),f=m(k,{ratioPairs:r}),h=a<1,_=h?`${o.toFixed(3)}:1`:`1:${a.toFixed(3)}`,S=h?`1:${a.toFixed(3)}`:`${o.toFixed(3)}:1`,C=r.map(e=>`${e[0]}:${e[1]}`).join(` Ã `),w=h?`${o.toFixed(2)}:1`:`1:${a.toFixed(2)}`;return(0,x.jsxs)(`div`,{children:[(0,x.jsx)(u,{title:`Ratio Calculator`,getSerializedState:()=>f}),(0,x.jsxs)(`div`,{className:`flex flex-col gap-4 px-1 *:flex-1 md:flex-row md:gap-x-4`,children:[(0,x.jsxs)(`div`,{className:`rounded-xl border bg-muted/20 p-4 shadow-sm`,children:[(0,x.jsx)(`div`,{className:`mb-3`,children:(0,x.jsx)(A,{children:`Stages`})}),(0,x.jsxs)(`div`,{className:`mb-1 grid grid-cols-[auto_1fr_1fr_5rem_2.25rem] items-center gap-2 px-1`,children:[(0,x.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Stage`}),(0,x.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Driving`}),(0,x.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Driven`}),(0,x.jsx)(`span`,{className:`text-right text-xs text-muted-foreground`,children:`Ratio`}),(0,x.jsx)(`div`,{})]}),(0,x.jsx)(`div`,{className:`flex flex-col divide-y`,children:t.map((e,n)=>(0,x.jsx)(M,{id:e.id,index:n,driving:e.pair[0],driven:e.pair[1],onUpdate:s,onRemove:l,canRemove:t.length>1,drivingTestId:`driving${n}`,drivenTestId:`driven${n}`,removeTestId:`removeStage${n}`},e.id))}),(0,x.jsx)(`div`,{className:`mt-3 border-t pt-3`,children:(0,x.jsxs)(i,{variant:`ghost`,size:`sm`,onClick:c,"data-testid":`addStage`,className:`gap-1.5`,children:[(0,x.jsx)(g,{className:`h-3.5 w-3.5`}),`Add Stage`]})})]}),(0,x.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,x.jsxs)(`div`,{className:`rounded-xl border bg-card p-5 shadow-sm`,children:[(0,x.jsx)(`div`,{className:`mb-3`,children:(0,x.jsx)(A,{children:`Result`})}),(0,x.jsxs)(`div`,{className:`flex items-start justify-between gap-4`,children:[(0,x.jsxs)(`div`,{children:[(0,x.jsx)(`div`,{className:`font-mono text-4xl font-bold tabular-nums`,"data-testid":`netRatio`,children:_}),(0,x.jsx)(`div`,{className:`mt-1 font-mono text-sm text-muted-foreground tabular-nums`,children:S})]}),(0,x.jsx)(`span`,{className:`rounded-full bg-primary/10 px-2.5 py-1 text-xs font-semibold text-primary`,children:h?`Reduction`:`Step-Up`})]}),(0,x.jsx)(`div`,{className:`mt-4 border-t pt-3`,children:(0,x.jsxs)(`p`,{className:`font-mono text-xs text-muted-foreground tabular-nums`,children:[C,` = `,_]})})]}),(0,x.jsxs)(`div`,{className:`rounded-xl border bg-muted/20 p-4 shadow-sm`,children:[(0,x.jsxs)(`div`,{className:`mb-3 flex items-center justify-between gap-4`,children:[(0,x.jsx)(A,{children:`Motor Speeds`}),(0,x.jsxs)(`span`,{className:`font-mono text-xs text-muted-foreground tabular-nums`,children:[`at `,w]})]}),(0,x.jsx)(`div`,{className:`grid grid-cols-2 gap-x-6 gap-y-1.5 text-xs`,children:d.toSorted((e,t)=>e.name.localeCompare(t.name)).map(e=>(0,x.jsxs)(`div`,{className:`flex justify-between gap-2`,children:[(0,x.jsx)(`span`,{className:`truncate text-muted-foreground`,children:e.name}),(0,x.jsxs)(`span`,{className:`font-mono tabular-nums`,children:[Math.round(e.freeSpeed.mul(a).to(`rpm`).scalar),` `,`rpm`]})]},e.name))})]})]})]})]})});function M({id:e,index:t,driving:n,driven:r,onUpdate:a,onRemove:o,canRemove:s,drivingTestId:c,drivenTestId:l,removeTestId:u}){let d=t=>a(e,typeof t==`function`?t(n):t,r),f=t=>a(e,n,typeof t==`function`?t(r):t),p=n>0?r/n:0,m=p>0?1/p:0,g=p===0?`â`:p<1?`${m.toFixed(2)}:1`:`1:${p.toFixed(2)}`;return(0,x.jsxs)(`div`,{className:`grid grid-cols-[auto_1fr_1fr_5rem_2.25rem] items-center gap-2 py-2`,children:[(0,x.jsx)(`span`,{className:`text-sm text-muted-foreground`,children:t+1}),(0,x.jsx)(`div`,{children:(0,x.jsx)(h,{stateHook:[n,d],label:``,testId:c})}),(0,x.jsx)(`div`,{children:(0,x.jsx)(h,{stateHook:[r,f],label:``,testId:l})}),(0,x.jsx)(`span`,{className:`text-right font-mono text-xs text-muted-foreground tabular-nums`,children:g}),(0,x.jsx)(i,{variant:`ghost`,size:`icon`,onClick:()=>o(e),disabled:!s,className:`h-9 w-9`,"data-testid":u,children:(0,x.jsx)(_,{className:`h-4 w-4`})})]})}export{j as default,E as meta};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.