@tscircuit/runframe 0.0.1 → 0.0.2
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.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{S as at,a as ht,c as w,s as B,t as A,b as it,d as b,f as lt,r as T,e as rt,g as st}from"./index-DDl5GwFA.js";var q=(t,e={})=>{let n=t._internal_store;if(!n){n={counts:{}},t._internal_store=n;for(const s of t){const o=s.type,a=s[`${o}_id`];if(!a)continue;const c=Number.parseInt(a.split("_").pop());Number.isNaN(c)||(n.counts[o]=Math.max(n.counts[o]??0,c))}}return new Proxy({},{get:(s,o)=>o==="toArray"?()=>t:{get:a=>t.find(c=>c.type===o&&c[`${o}_id`]===a),getUsing:a=>{const c=Object.keys(a);if(c.length!==1)throw new Error("getUsing requires exactly one key, e.g. { pcb_component_id }");const i=c[0],r=i.replace("_id",""),l=t.find(g=>g.type===r&&g[i]===a[i]);return l?t.find(g=>g.type===o&&g[`${o}_id`]===l[`${o}_id`]):null},getWhere:a=>{const c=Object.keys(a);return t.find(i=>i.type===o&&c.every(r=>i[r]===a[r]))},list:a=>{const c=a?Object.keys(a):[];return t.filter(i=>i.type===o&&c.every(r=>i[r]===a[r]))},insert:a=>{var r;(r=n.counts)[o]??(r[o]=-1),n.counts[o]++;const c=n.counts[o],i={type:o,[`${o}_id`]:`${o}_${c}`,...a};return e.validateInserts&&(at[o]??ht).parse(i),t.push(i),i},delete:a=>{const c=t.find(i=>i[`${o}_id`]===a);c&&t.splice(t.indexOf(c),1)},update:(a,c)=>{const i=t.find(r=>r.type===o&&r[`${o}_id`]===a);if(i)return Object.assign(i,c),i},select:a=>{if(o==="source_component")return t.find(c=>c.type==="source_component"&&c.name===a.replace(/\./g,""));if(o==="pcb_port"||o==="source_port"||o==="schematic_port"){const[c,i]=a.replace(/\./g,"").split(/[\s\>]+/),r=t.find(g=>g.type==="source_component"&&g.name===c);if(!r)return null;const l=t.find(g=>g.type==="source_port"&&g.source_component_id===r.source_component_id&&(g.name===i||(g.port_hints??[]).includes(i)));if(!l)return null;if(o==="source_port")return l;if(o==="pcb_port")return t.find(g=>g.type==="pcb_port"&&g.source_port_id===l.source_port_id);if(o==="schematic_port")return t.find(g=>g.type==="schematic_port"&&g.source_port_id===l.source_port_id)}}}})};q.unparsed=q;var H=q;function gt(t,e,n,h){if(!h)return[];const{pcb_port_ids:s}=t,o=n.find(g=>g.type==="pcb_port"&&g.pcb_port_id===(s==null?void 0:s[0])),a=n.find(g=>g.type==="pcb_port"&&g.pcb_port_id===(s==null?void 0:s[1]));if(!o||!a)return[];const c=b(e,{x:o.x,y:o.y}),i=b(e,{x:a.x,y:a.y}),r={x:(c.x+i.x)/2,y:(c.y+i.y)/2};return isNaN(c.x)||isNaN(c.y)||isNaN(i.x)||isNaN(i.y)||isNaN(r.x)||isNaN(r.y)?[]:[{name:"line",type:"element",attributes:{x1:c.x.toString(),y1:c.y.toString(),x2:r.x.toString(),y2:r.y.toString(),stroke:"red","stroke-width":"1.5","stroke-dasharray":"2,2"},children:[],value:""},{name:"line",type:"element",attributes:{x1:r.x.toString(),y1:r.y.toString(),x2:i.x.toString(),y2:i.y.toString(),stroke:"red","stroke-width":"1.5","stroke-dasharray":"2,2"},children:[],value:""},{name:"rect",type:"element",attributes:{x:(r.x-5).toString(),y:(r.y-5).toString(),width:"10",height:"10",fill:"red",transform:`rotate(45 ${r.x} ${r.y})`},children:[],value:""},{name:"text",type:"element",attributes:{x:r.x.toString(),y:(r.y-15).toString(),fill:"red","font-family":"sans-serif","font-size":"12","text-anchor":"middle"},children:[{type:"text",value:t.message||"Pcb Trace Error",name:"",attributes:{},children:[]}],value:""}]}function dt(t,e){if(!t.route||!Array.isArray(t.route))return[];const n=t.route[0],h=t.route[t.route.length-1],s=n.x===h.x&&n.y===h.y,o=t.route.slice(0,s?-1:void 0).map((a,c)=>{const[i,r]=b(e,[a.x,a.y]);return c===0?`M ${i} ${r}`:`L ${i} ${r}`}).join(" ")+(s?" Z":"");return[{name:"path",type:"element",attributes:{class:"pcb-fabrication-note-path",stroke:t.color||"rgba(255,255,255,0.5)",fill:"none",d:o,"stroke-width":(t.stroke_width*Math.abs(e.a)).toString(),"data-pcb-component-id":t.pcb_component_id,"data-pcb-fabrication-note-path-id":t.pcb_fabrication_note_path_id},value:"",children:[]}]}function bt(t,e){const{anchor_position:n,anchor_alignment:h,text:s,font_size:o=1,layer:a="top",color:c}=t;if(!n||typeof n.x!="number"||typeof n.y!="number")return console.error("Invalid anchor_position:",n),[];const[i,r]=b(e,[n.x,n.y]),l=o*Math.abs(e.a),g=w(A(i,r),T(Math.PI/180));return[{name:"text",type:"element",attributes:{x:"0",y:"0","font-family":"Arial, sans-serif","font-size":l.toString(),"text-anchor":"middle","dominant-baseline":"central",transform:rt(g),class:"pcb-fabrication-note-text",fill:c||"rgba(255,255,255,0.5)"},children:[{type:"text",value:s,name:"",attributes:{},children:[]}],value:""}]}function mt(t,e){const[n,h]=b(e,[t.x,t.y]);if(t.shape==="pill"){const s=t.outer_width*Math.abs(e.a),o=t.outer_height*Math.abs(e.a),a=t.hole_width*Math.abs(e.a),c=t.hole_height*Math.abs(e.a),i=s/2,r=a/2,l=o-s;return[{name:"g",type:"element",children:[{name:"path",type:"element",attributes:{class:"pcb-hole-outer",d:`M${n-i},${h-l/2} v${l} a${i},${i} 0 0 0 ${s},0 v-${l} a${i},${i} 0 0 0 -${s},0 z`},value:"",children:[]},{name:"path",type:"element",attributes:{class:"pcb-hole-inner",d:`M${n-r},${h-(c-a)/2} v${c-a} a${r},${r} 0 0 0 ${a},0 v-${c-a} a${r},${r} 0 0 0 -${a},0 z`},value:"",children:[]}],value:"",attributes:{}}]}if(t.shape==="circle"){const s=t.outer_diameter*Math.abs(e.a),o=t.outer_diameter*Math.abs(e.a),a=t.hole_diameter*Math.abs(e.a),c=t.hole_diameter*Math.abs(e.a),i=Math.min(s,o)/2,r=Math.min(a,c)/2;return[{name:"g",type:"element",children:[{name:"circle",type:"element",attributes:{class:"pcb-hole-outer",cx:n.toString(),cy:h.toString(),r:i.toString()},value:"",children:[]},{name:"circle",type:"element",attributes:{class:"pcb-hole-inner",cx:n.toString(),cy:h.toString(),r:r.toString()},value:"",children:[]}],value:"",attributes:{}}]}return[]}function ut(t,e){if(!t.route||!Array.isArray(t.route))return[];let n=t.route.map((o,a)=>{const[c,i]=b(e,[o.x,o.y]);return a===0?`M ${c} ${i}`:`L ${c} ${i}`}).join(" ");const h=t.route[0],s=t.route[t.route.length-1];return h&&s&&h.x===s.x&&h.y===s.y&&(n+=" Z"),[{name:"path",type:"element",attributes:{class:`pcb-silkscreen pcb-silkscreen-${t.layer}`,d:n,"stroke-width":(t.stroke_width*Math.abs(e.a)).toString(),"data-pcb-component-id":t.pcb_component_id,"data-pcb-silkscreen-path-id":t.pcb_silkscreen_path_id},value:"",children:[]}]}function ft(t,e){const{anchor_position:n,text:h,font_size:s=1,layer:o="top"}=t;if(!n||typeof n.x!="number"||typeof n.y!="number")return console.error("Invalid anchor_position:",n),[];const[a,c]=b(e,[n.x,n.y]),i=s*Math.abs(e.a),r=w(A(a,c),T(Math.PI/180));return[{name:"text",type:"element",attributes:{x:"0",y:"0","font-family":"Arial, sans-serif","font-size":i.toString(),"text-anchor":"middle","dominant-baseline":"central",transform:rt(r),class:`pcb-silkscreen-text pcb-silkscreen-${o}`,"data-pcb-silkscreen-text-id":t.pcb_component_id},children:[{type:"text",value:h,name:"",attributes:{},children:[]}],value:""}]}function pt(t){const e=[];for(let n=0;n<t.length-1;n++)e.push([t[n],t[n+1]]);return e}var ct={top:"rgb(200, 52, 52)",bottom:"rgb(77, 127, 196)"};function K(t){return ct[t]??"white"}function yt(t,e){if(!t.route||!Array.isArray(t.route)||t.route.length<2)return[];const n=pt(t.route),h=[];for(const[s,o]of n){const a=b(e,[s.x,s.y]),c=b(e,[o.x,o.y]),i="layer"in s?s.layer:"layer"in o?o.layer:null;if(!i)continue;const r=ct[i]??"white",l="width"in s?s.width:"width"in o?o.width:null;h.push({name:"path",type:"element",value:"",children:[],attributes:{class:"pcb-trace",stroke:r,d:`M ${a[0]} ${a[1]} L ${c[0]} ${c[1]}`,"stroke-width":l?(l*Math.abs(e.a)).toString():"0.3","stroke-linecap":"round","stroke-linejoin":"round","shape-rendering":"crispEdges"}})}return h}function xt(t,e){const[n,h]=b(e,[t.x,t.y]);if(t.shape==="rect"||t.shape==="rotated_rect"){const s=t.width*Math.abs(e.a),o=t.height*Math.abs(e.d);return t.shape==="rotated_rect"&&t.ccw_rotation?[{name:"rect",type:"element",attributes:{class:"pcb-pad",fill:K(t.layer),x:(-s/2).toString(),y:(-o/2).toString(),width:s.toString(),height:o.toString(),transform:`translate(${n} ${h}) rotate(${-t.ccw_rotation})`}}]:[{name:"rect",type:"element",attributes:{class:"pcb-pad",fill:K(t.layer),x:(n-s/2).toString(),y:(h-o/2).toString(),width:s.toString(),height:o.toString()}}]}return[]}function _t(t,e){const{width:n,height:h,center:s,outline:o}=t;let a;if(o&&Array.isArray(o)&&o.length>=3)a=o.map((c,i)=>{const[r,l]=b(e,[c.x,c.y]);return i===0?`M ${r} ${l}`:`L ${r} ${l}`}).join(" ");else{const c=n/2,i=h/2,r=b(e,[s.x-c,s.y-i]),l=b(e,[s.x+c,s.y-i]),g=b(e,[s.x+c,s.y+i]),p=b(e,[s.x-c,s.y+i]);a=`M ${r[0]} ${r[1]} L ${l[0]} ${l[1]} L ${g[0]} ${g[1]} L ${p[0]} ${p[1]}`}return a+=" Z",[{name:"path",type:"element",value:"",children:[],attributes:{class:"pcb-board",d:a,stroke:"rgba(255, 255, 255, 0.5)","stroke-width":(.1*Math.abs(e.a)).toString()}}]}function St(t,e){const[n,h]=b(e,[t.x,t.y]),s=t.outer_diameter*Math.abs(e.a),o=t.outer_diameter*Math.abs(e.a),a=t.hole_diameter*Math.abs(e.a),c=t.hole_diameter*Math.abs(e.a),i=Math.min(s,o)/2,r=Math.min(a,c)/2;return{name:"g",type:"element",children:[{name:"circle",type:"element",attributes:{class:"pcb-hole-outer",cx:n.toString(),cy:h.toString(),r:i.toString()}},{name:"circle",type:"element",attributes:{class:"pcb-hole-inner",cx:n.toString(),cy:h.toString(),r:r.toString()}}]}}var C="#FF26E2";function vt(t,e){const[n,h]=b(e,[t.x,t.y]);if(t.hole_shape==="circle"||t.hole_shape==="square"){const s=t.hole_diameter*Math.abs(e.a),o=s/2;return t.hole_shape==="circle"?[{name:"circle",type:"element",attributes:{class:"pcb-hole",cx:n.toString(),cy:h.toString(),r:o.toString(),fill:C},children:[],value:""}]:[{name:"rect",type:"element",attributes:{class:"pcb-hole",x:(n-o).toString(),y:(h-o).toString(),width:s.toString(),height:s.toString(),fill:C},children:[],value:""}]}if(t.hole_shape==="oval"){const s=t.hole_width*Math.abs(e.a),o=t.hole_height*Math.abs(e.a),a=s/2,c=o/2;return[{name:"ellipse",type:"element",attributes:{class:"pcb-hole",cx:n.toString(),cy:h.toString(),rx:a.toString(),ry:c.toString(),fill:C},children:[],value:""}]}return[]}var tt=["pcb_trace_error","pcb_plated_hole","pcb_fabrication_note_text","pcb_fabrication_note_path","pcb_silkscreen_text","pcb_silkscreen_path","pcb_via","pcb_trace","pcb_smtpad","pcb_component","pcb_board"];function wt(t,e){let n=Number.POSITIVE_INFINITY,h=Number.POSITIVE_INFINITY,s=Number.NEGATIVE_INFINITY,o=Number.NEGATIVE_INFINITY;for(const d of t)d.type==="pcb_board"?d.outline&&Array.isArray(d.outline)&&d.outline.length>=3?E(d.outline):"center"in d&&"width"in d&&"height"in d&&O(d.center,d.width,d.height):"x"in d&&"y"in d?O({x:d.x,y:d.y},0,0):"route"in d&&j(d.route);const a=1,c=s-n+2*a,i=o-h+2*a,r=(e==null?void 0:e.width)??800,l=(e==null?void 0:e.height)??600,g=[];for(const d of t)"route"in d&&d.route!==void 0&&g.push(d.route);const p=r/c,x=l/i,_=Math.min(p,x),v=(r-c*_)/2,M=(l-i*_)/2,k=w(A(v-n*_+a*_,l-M+h*_-a*_),B(_,-_)),I=t.sort((d,y)=>(tt.indexOf(y.type)??9999)-(tt.indexOf(d.type)??9999)).flatMap(d=>Mt(d,k,t,e==null?void 0:e.shouldDrawErrors));for(const d of t)if("stroke_width"in d){String(_*d.stroke_width);break}const u={name:"svg",type:"element",attributes:{xmlns:"http://www.w3.org/2000/svg",width:r.toString(),height:l.toString()},value:"",children:[{name:"style",type:"element",children:[{type:"text",value:`
|
|
1
|
+
import{S as at,a as ht,c as w,s as B,t as A,b as it,d as b,f as lt,r as T,e as rt,g as st}from"./index-CHwkIwYw.js";var q=(t,e={})=>{let n=t._internal_store;if(!n){n={counts:{}},t._internal_store=n;for(const s of t){const o=s.type,a=s[`${o}_id`];if(!a)continue;const c=Number.parseInt(a.split("_").pop());Number.isNaN(c)||(n.counts[o]=Math.max(n.counts[o]??0,c))}}return new Proxy({},{get:(s,o)=>o==="toArray"?()=>t:{get:a=>t.find(c=>c.type===o&&c[`${o}_id`]===a),getUsing:a=>{const c=Object.keys(a);if(c.length!==1)throw new Error("getUsing requires exactly one key, e.g. { pcb_component_id }");const i=c[0],r=i.replace("_id",""),l=t.find(g=>g.type===r&&g[i]===a[i]);return l?t.find(g=>g.type===o&&g[`${o}_id`]===l[`${o}_id`]):null},getWhere:a=>{const c=Object.keys(a);return t.find(i=>i.type===o&&c.every(r=>i[r]===a[r]))},list:a=>{const c=a?Object.keys(a):[];return t.filter(i=>i.type===o&&c.every(r=>i[r]===a[r]))},insert:a=>{var r;(r=n.counts)[o]??(r[o]=-1),n.counts[o]++;const c=n.counts[o],i={type:o,[`${o}_id`]:`${o}_${c}`,...a};return e.validateInserts&&(at[o]??ht).parse(i),t.push(i),i},delete:a=>{const c=t.find(i=>i[`${o}_id`]===a);c&&t.splice(t.indexOf(c),1)},update:(a,c)=>{const i=t.find(r=>r.type===o&&r[`${o}_id`]===a);if(i)return Object.assign(i,c),i},select:a=>{if(o==="source_component")return t.find(c=>c.type==="source_component"&&c.name===a.replace(/\./g,""));if(o==="pcb_port"||o==="source_port"||o==="schematic_port"){const[c,i]=a.replace(/\./g,"").split(/[\s\>]+/),r=t.find(g=>g.type==="source_component"&&g.name===c);if(!r)return null;const l=t.find(g=>g.type==="source_port"&&g.source_component_id===r.source_component_id&&(g.name===i||(g.port_hints??[]).includes(i)));if(!l)return null;if(o==="source_port")return l;if(o==="pcb_port")return t.find(g=>g.type==="pcb_port"&&g.source_port_id===l.source_port_id);if(o==="schematic_port")return t.find(g=>g.type==="schematic_port"&&g.source_port_id===l.source_port_id)}}}})};q.unparsed=q;var H=q;function gt(t,e,n,h){if(!h)return[];const{pcb_port_ids:s}=t,o=n.find(g=>g.type==="pcb_port"&&g.pcb_port_id===(s==null?void 0:s[0])),a=n.find(g=>g.type==="pcb_port"&&g.pcb_port_id===(s==null?void 0:s[1]));if(!o||!a)return[];const c=b(e,{x:o.x,y:o.y}),i=b(e,{x:a.x,y:a.y}),r={x:(c.x+i.x)/2,y:(c.y+i.y)/2};return isNaN(c.x)||isNaN(c.y)||isNaN(i.x)||isNaN(i.y)||isNaN(r.x)||isNaN(r.y)?[]:[{name:"line",type:"element",attributes:{x1:c.x.toString(),y1:c.y.toString(),x2:r.x.toString(),y2:r.y.toString(),stroke:"red","stroke-width":"1.5","stroke-dasharray":"2,2"},children:[],value:""},{name:"line",type:"element",attributes:{x1:r.x.toString(),y1:r.y.toString(),x2:i.x.toString(),y2:i.y.toString(),stroke:"red","stroke-width":"1.5","stroke-dasharray":"2,2"},children:[],value:""},{name:"rect",type:"element",attributes:{x:(r.x-5).toString(),y:(r.y-5).toString(),width:"10",height:"10",fill:"red",transform:`rotate(45 ${r.x} ${r.y})`},children:[],value:""},{name:"text",type:"element",attributes:{x:r.x.toString(),y:(r.y-15).toString(),fill:"red","font-family":"sans-serif","font-size":"12","text-anchor":"middle"},children:[{type:"text",value:t.message||"Pcb Trace Error",name:"",attributes:{},children:[]}],value:""}]}function dt(t,e){if(!t.route||!Array.isArray(t.route))return[];const n=t.route[0],h=t.route[t.route.length-1],s=n.x===h.x&&n.y===h.y,o=t.route.slice(0,s?-1:void 0).map((a,c)=>{const[i,r]=b(e,[a.x,a.y]);return c===0?`M ${i} ${r}`:`L ${i} ${r}`}).join(" ")+(s?" Z":"");return[{name:"path",type:"element",attributes:{class:"pcb-fabrication-note-path",stroke:t.color||"rgba(255,255,255,0.5)",fill:"none",d:o,"stroke-width":(t.stroke_width*Math.abs(e.a)).toString(),"data-pcb-component-id":t.pcb_component_id,"data-pcb-fabrication-note-path-id":t.pcb_fabrication_note_path_id},value:"",children:[]}]}function bt(t,e){const{anchor_position:n,anchor_alignment:h,text:s,font_size:o=1,layer:a="top",color:c}=t;if(!n||typeof n.x!="number"||typeof n.y!="number")return console.error("Invalid anchor_position:",n),[];const[i,r]=b(e,[n.x,n.y]),l=o*Math.abs(e.a),g=w(A(i,r),T(Math.PI/180));return[{name:"text",type:"element",attributes:{x:"0",y:"0","font-family":"Arial, sans-serif","font-size":l.toString(),"text-anchor":"middle","dominant-baseline":"central",transform:rt(g),class:"pcb-fabrication-note-text",fill:c||"rgba(255,255,255,0.5)"},children:[{type:"text",value:s,name:"",attributes:{},children:[]}],value:""}]}function mt(t,e){const[n,h]=b(e,[t.x,t.y]);if(t.shape==="pill"){const s=t.outer_width*Math.abs(e.a),o=t.outer_height*Math.abs(e.a),a=t.hole_width*Math.abs(e.a),c=t.hole_height*Math.abs(e.a),i=s/2,r=a/2,l=o-s;return[{name:"g",type:"element",children:[{name:"path",type:"element",attributes:{class:"pcb-hole-outer",d:`M${n-i},${h-l/2} v${l} a${i},${i} 0 0 0 ${s},0 v-${l} a${i},${i} 0 0 0 -${s},0 z`},value:"",children:[]},{name:"path",type:"element",attributes:{class:"pcb-hole-inner",d:`M${n-r},${h-(c-a)/2} v${c-a} a${r},${r} 0 0 0 ${a},0 v-${c-a} a${r},${r} 0 0 0 -${a},0 z`},value:"",children:[]}],value:"",attributes:{}}]}if(t.shape==="circle"){const s=t.outer_diameter*Math.abs(e.a),o=t.outer_diameter*Math.abs(e.a),a=t.hole_diameter*Math.abs(e.a),c=t.hole_diameter*Math.abs(e.a),i=Math.min(s,o)/2,r=Math.min(a,c)/2;return[{name:"g",type:"element",children:[{name:"circle",type:"element",attributes:{class:"pcb-hole-outer",cx:n.toString(),cy:h.toString(),r:i.toString()},value:"",children:[]},{name:"circle",type:"element",attributes:{class:"pcb-hole-inner",cx:n.toString(),cy:h.toString(),r:r.toString()},value:"",children:[]}],value:"",attributes:{}}]}return[]}function ut(t,e){if(!t.route||!Array.isArray(t.route))return[];let n=t.route.map((o,a)=>{const[c,i]=b(e,[o.x,o.y]);return a===0?`M ${c} ${i}`:`L ${c} ${i}`}).join(" ");const h=t.route[0],s=t.route[t.route.length-1];return h&&s&&h.x===s.x&&h.y===s.y&&(n+=" Z"),[{name:"path",type:"element",attributes:{class:`pcb-silkscreen pcb-silkscreen-${t.layer}`,d:n,"stroke-width":(t.stroke_width*Math.abs(e.a)).toString(),"data-pcb-component-id":t.pcb_component_id,"data-pcb-silkscreen-path-id":t.pcb_silkscreen_path_id},value:"",children:[]}]}function ft(t,e){const{anchor_position:n,text:h,font_size:s=1,layer:o="top"}=t;if(!n||typeof n.x!="number"||typeof n.y!="number")return console.error("Invalid anchor_position:",n),[];const[a,c]=b(e,[n.x,n.y]),i=s*Math.abs(e.a),r=w(A(a,c),T(Math.PI/180));return[{name:"text",type:"element",attributes:{x:"0",y:"0","font-family":"Arial, sans-serif","font-size":i.toString(),"text-anchor":"middle","dominant-baseline":"central",transform:rt(r),class:`pcb-silkscreen-text pcb-silkscreen-${o}`,"data-pcb-silkscreen-text-id":t.pcb_component_id},children:[{type:"text",value:h,name:"",attributes:{},children:[]}],value:""}]}function pt(t){const e=[];for(let n=0;n<t.length-1;n++)e.push([t[n],t[n+1]]);return e}var ct={top:"rgb(200, 52, 52)",bottom:"rgb(77, 127, 196)"};function K(t){return ct[t]??"white"}function yt(t,e){if(!t.route||!Array.isArray(t.route)||t.route.length<2)return[];const n=pt(t.route),h=[];for(const[s,o]of n){const a=b(e,[s.x,s.y]),c=b(e,[o.x,o.y]),i="layer"in s?s.layer:"layer"in o?o.layer:null;if(!i)continue;const r=ct[i]??"white",l="width"in s?s.width:"width"in o?o.width:null;h.push({name:"path",type:"element",value:"",children:[],attributes:{class:"pcb-trace",stroke:r,d:`M ${a[0]} ${a[1]} L ${c[0]} ${c[1]}`,"stroke-width":l?(l*Math.abs(e.a)).toString():"0.3","stroke-linecap":"round","stroke-linejoin":"round","shape-rendering":"crispEdges"}})}return h}function xt(t,e){const[n,h]=b(e,[t.x,t.y]);if(t.shape==="rect"||t.shape==="rotated_rect"){const s=t.width*Math.abs(e.a),o=t.height*Math.abs(e.d);return t.shape==="rotated_rect"&&t.ccw_rotation?[{name:"rect",type:"element",attributes:{class:"pcb-pad",fill:K(t.layer),x:(-s/2).toString(),y:(-o/2).toString(),width:s.toString(),height:o.toString(),transform:`translate(${n} ${h}) rotate(${-t.ccw_rotation})`}}]:[{name:"rect",type:"element",attributes:{class:"pcb-pad",fill:K(t.layer),x:(n-s/2).toString(),y:(h-o/2).toString(),width:s.toString(),height:o.toString()}}]}return[]}function _t(t,e){const{width:n,height:h,center:s,outline:o}=t;let a;if(o&&Array.isArray(o)&&o.length>=3)a=o.map((c,i)=>{const[r,l]=b(e,[c.x,c.y]);return i===0?`M ${r} ${l}`:`L ${r} ${l}`}).join(" ");else{const c=n/2,i=h/2,r=b(e,[s.x-c,s.y-i]),l=b(e,[s.x+c,s.y-i]),g=b(e,[s.x+c,s.y+i]),p=b(e,[s.x-c,s.y+i]);a=`M ${r[0]} ${r[1]} L ${l[0]} ${l[1]} L ${g[0]} ${g[1]} L ${p[0]} ${p[1]}`}return a+=" Z",[{name:"path",type:"element",value:"",children:[],attributes:{class:"pcb-board",d:a,stroke:"rgba(255, 255, 255, 0.5)","stroke-width":(.1*Math.abs(e.a)).toString()}}]}function St(t,e){const[n,h]=b(e,[t.x,t.y]),s=t.outer_diameter*Math.abs(e.a),o=t.outer_diameter*Math.abs(e.a),a=t.hole_diameter*Math.abs(e.a),c=t.hole_diameter*Math.abs(e.a),i=Math.min(s,o)/2,r=Math.min(a,c)/2;return{name:"g",type:"element",children:[{name:"circle",type:"element",attributes:{class:"pcb-hole-outer",cx:n.toString(),cy:h.toString(),r:i.toString()}},{name:"circle",type:"element",attributes:{class:"pcb-hole-inner",cx:n.toString(),cy:h.toString(),r:r.toString()}}]}}var C="#FF26E2";function vt(t,e){const[n,h]=b(e,[t.x,t.y]);if(t.hole_shape==="circle"||t.hole_shape==="square"){const s=t.hole_diameter*Math.abs(e.a),o=s/2;return t.hole_shape==="circle"?[{name:"circle",type:"element",attributes:{class:"pcb-hole",cx:n.toString(),cy:h.toString(),r:o.toString(),fill:C},children:[],value:""}]:[{name:"rect",type:"element",attributes:{class:"pcb-hole",x:(n-o).toString(),y:(h-o).toString(),width:s.toString(),height:s.toString(),fill:C},children:[],value:""}]}if(t.hole_shape==="oval"){const s=t.hole_width*Math.abs(e.a),o=t.hole_height*Math.abs(e.a),a=s/2,c=o/2;return[{name:"ellipse",type:"element",attributes:{class:"pcb-hole",cx:n.toString(),cy:h.toString(),rx:a.toString(),ry:c.toString(),fill:C},children:[],value:""}]}return[]}var tt=["pcb_trace_error","pcb_plated_hole","pcb_fabrication_note_text","pcb_fabrication_note_path","pcb_silkscreen_text","pcb_silkscreen_path","pcb_via","pcb_trace","pcb_smtpad","pcb_component","pcb_board"];function wt(t,e){let n=Number.POSITIVE_INFINITY,h=Number.POSITIVE_INFINITY,s=Number.NEGATIVE_INFINITY,o=Number.NEGATIVE_INFINITY;for(const d of t)d.type==="pcb_board"?d.outline&&Array.isArray(d.outline)&&d.outline.length>=3?E(d.outline):"center"in d&&"width"in d&&"height"in d&&O(d.center,d.width,d.height):"x"in d&&"y"in d?O({x:d.x,y:d.y},0,0):"route"in d&&j(d.route);const a=1,c=s-n+2*a,i=o-h+2*a,r=(e==null?void 0:e.width)??800,l=(e==null?void 0:e.height)??600,g=[];for(const d of t)"route"in d&&d.route!==void 0&&g.push(d.route);const p=r/c,x=l/i,_=Math.min(p,x),v=(r-c*_)/2,M=(l-i*_)/2,k=w(A(v-n*_+a*_,l-M+h*_-a*_),B(_,-_)),I=t.sort((d,y)=>(tt.indexOf(y.type)??9999)-(tt.indexOf(d.type)??9999)).flatMap(d=>Mt(d,k,t,e==null?void 0:e.shouldDrawErrors));for(const d of t)if("stroke_width"in d){String(_*d.stroke_width);break}const u={name:"svg",type:"element",attributes:{xmlns:"http://www.w3.org/2000/svg",width:r.toString(),height:l.toString()},value:"",children:[{name:"style",type:"element",children:[{type:"text",value:`
|
|
2
2
|
.boundary { fill: #000; }
|
|
3
3
|
.pcb-board { fill: none; }
|
|
4
4
|
.pcb-trace { fill: none; }
|
package/dist/index.html
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
<meta charset="UTF-8" />
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
6
|
<title>@tscircuit/runframe</title>
|
|
7
|
-
<script type="module" crossorigin src="/assets/index-
|
|
7
|
+
<script type="module" crossorigin src="/assets/index-CHwkIwYw.js"></script>
|
|
8
8
|
</head>
|
|
9
9
|
<body>
|
|
10
10
|
<div id="root"></div>
|