mohan-bee/mini-mp3-player

Portable, battery-powered MP3 player hardware with USB charging, microSD storage, an MCU, VS10xx audio decoder, headphone output, status controls, and regulated power rails.

Version
1.2.0
License
unset
Stars
0

scripts/install-assembly-viewer.mjs

// A visible mode selector around tscircuit's native CircuitJsonPreview.
import fs from 'node:fs'
fs.copyFileSync('node_modules/@tscircuit/runframe/dist/standalone-preview.min.js','dist/assembly-preview.min.js')
fs.writeFileSync('dist/viewer-frame.html',`<!doctype html><html><head><meta charset="utf-8"><style>html,body,#root{margin:0;height:100%;font:15px system-ui}#error{padding:24px;color:#9d2530}</style></head><body><div id="root">Loading 3D assembly…</div><script type="module">
const view = new URLSearchParams(location.search).get('view') || 'assembled';
try {
 const response=await fetch(view==='exploded'?'./exploded/circuit.json':'./index/circuit.json',{cache:'no-store'});
 if(!response.ok)throw new Error('Circuit could not load ('+response.status+')');
 let circuit=await response.json();
 if(view==='open'||view==='pcb'||view==='fit'){
  const keep=view==='fit'?['MECH_base','MECH_mounting_screws','MECH_power_slider']:['MECH_battery','MECH_jst_harness','MECH_power_slider'];
  const hidden=new Set(circuit.filter(x=>x.type==='source_component'&&x.ftype==='subassembly'&&(view==='pcb'||!keep.includes(x.name))).map(x=>x.source_component_id));
  circuit=circuit.filter(x=>!hidden.has(x.source_component_id));
  if(view==='fit'){
   const base=circuit.find(x=>x.type==='source_component'&&x.name==='MECH_base');
   circuit=circuit.map(x=>x.type==='cad_component'&&x.source_component_id===base?.source_component_id?{...x,show_as_translucent_model:true}:x);
  }
 }
 window.CIRCUIT_JSON=circuit;
 window.CIRCUIT_JSON_PREVIEW_PROPS={defaultActiveTab:view==='schematic'?'schematic':'cad',availableTabs:['cad','pcb','schematic'],showRightHeaderContent:true,showCodeTab:false,showJsonTab:false,showRenderLogTab:false,showImportAndFormatButtons:false,showFileMenu:false,readOnly:true,autoRotate3dViewerDisabled:true};
 await import('./assembly-preview.min.js');
}catch(e){document.getElementById('root').textContent='Unable to load viewer: '+e.message;}
</script></body></html>`)
fs.writeFileSync('dist/index.html',`<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Mini MP3 · 3D assembly</title><style>
*{box-sizing:border-box}body{margin:0;font:14px system-ui;background:#f5f7f9;color:#20334d}header{min-height:96px;padding:14px 22px;display:flex;align-items:center;justify-content:space-between;gap:18px;flex-wrap:wrap;border-bottom:1px solid #d9e0e7;background:#fff}strong{font-size:20px;letter-spacing:.03em}small{display:block;color:#617184;margin-top:4px}nav{display:flex;gap:6px;flex-wrap:wrap}button{font:600 14px system-ui;padding:11px 16px;background:#edf1f5;color:#20334d;border:1px solid transparent;border-radius:8px;cursor:pointer}button[aria-pressed=true]{background:#20334d;color:#fff;border-color:#67cbb0}button:focus-visible{outline:3px solid #67cbb0}#hint{padding:8px 22px;color:#526577;font-size:12px}iframe{display:block;width:100%;height:calc(100dvh - 132px);min-height:430px;border:0;background:white}@media(max-width:650px){header{padding:12px;gap:10px}button{padding:9px 12px}iframe{height:calc(100dvh - 175px)}}</style></head><body>
<header><div><strong>MINI / MP3</strong><small>88 × 68 × 21.5 mm · compact assembly</small></div><nav aria-label="3D assembly view"><button data-view="assembled" aria-pressed="true">Assembled</button><button data-view="open" aria-pressed="false">Open case</button><button data-view="fit" aria-pressed="false">Mounting fit</button><button data-view="exploded" aria-pressed="false">Exploded</button><button data-view="pcb" aria-pressed="false">PCB only</button><button data-view="schematic" aria-pressed="false">Schematic</button></nav></header>
<div id="hint">Drag to rotate · scroll to zoom · enclosure is a prototype pending physical fit checks</div><iframe id="viewer" title="Native tscircuit 3D viewer" src="./viewer-frame.html?view=assembled"></iframe>
<script>const buttons=[...document.querySelectorAll('button[data-view]')];function select(view){if(!buttons.some(b=>b.dataset.view===view))view='assembled';buttons.forEach(b=>b.setAttribute('aria-pressed',String(b.dataset.view===view)));document.getElementById('viewer').src='./viewer-frame.html?view='+view;history.replaceState(null,'','#'+view)}buttons.forEach(b=>b.addEventListener('click',()=>select(b.dataset.view)));select(location.hash.slice(1)||'assembled');</script></body></html>`)
console.log('Installed assembly view controls and the multi-sheet schematic view.')