abse/smart-ring-flex

A tscircuit package created by abse.

Version
0.0.24
License
unset
Stars
0

src/schematic-layout.tsx

import layout from './schematic-layout.json'
export const schematicRefs=layout.sets
export const schematicFor=(name:string)=>{
 const p=(layout.components as Record<string,{sheet:string;x:number;y:number;section?:string}>)[name]
 return p?{schX:p.x,schY:p.y,schSheetName:p.sheet,schSectionName:p.section}:{}
}
// A4 dimensions are physical mm; schematic coordinates use 9.236 mm/unit.
// Keep symbols, ports, labels, routes and their adjacent notes inside the frame.
export function SchematicSheets({refs}:{refs:string[]}) {
 const active=new Set(refs)
 return <>{layout.sheets.filter(s=>s.refs.some(ref=>active.has(ref))||(s.name==='Charging'&&active.has('R1'))).map((sheet,i)=><schematicsheet key={sheet.name} name={sheet.name} displayName={sheet.title} sheetIndex={i} sheetSize="A4" sheetWidth={297} sheetHeight={210}>
  {Array.from(new Set(sheet.refs.map(ref=>(layout.components as Record<string,{section?:string}>)[ref].section).filter(Boolean))).map(name=><schematicsection key={name} name={name!} displayName={name!.startsWith('RADIO_')?name!.replace('RADIO_',''):''} sectionTitleFontSize={.22}/>)}
  <schematictext text={sheet.title} schX={0} schY={9.8} fontSize={.34}/>
  {[...sheet.refs,...(sheet.name==='Charging'?['R1']:[])].filter(ref=>active.has(ref)).map(ref=>{
   const p=(layout.components as Record<string,{noteX:number;noteY:number;lines:string[]}>)[ref]
   return p.lines.map((line,i)=><schematictext key={`${ref}-purpose-${i}`} text={line} schX={p.noteX} schY={p.noteY-i*.28} fontSize={.20} anchor="left" color="#24384b"/>)
  })}
 </schematicsheet>)}</>
}