@tscircuit/runframe 0.0.1751 → 0.0.1753

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.
@@ -5433,7 +5433,7 @@ You passed in: '`+this.raw_options[o]+"'");return a},e.prototype._is_valid_selec
5433
5433
  `);break}}return s}}}),SAi=ha({"node_modules/pretty/index.js"(t,A){var e=pAi(),i=DAi(),n=Rhe(),o={unformatted:["code","pre","em","strong","span"],indent_inner_html:!0,indent_char:" ",indent_size:2,sep:`
5434
5434
  `};A.exports=function(a,g){var c=n({},o,g);return a=e.html(a,c),c.ocd===!0?(c.newlines&&(c.sep=c.newlines),s(a,c)):a};function s(r,a){return i(r,a).replace(/^\s+/g,"").replace(/\s+$/g,`
5435
5435
  `).replace(/(\s*<!--)/g,`
5436
- $1`).replace(/>(\s*)(?=<!--\s*\/)/g,"> ")}}});function Nhe(t,A,e){if(!A||!e)return;let i=t.get(A);i||(i=new Set,t.set(A,i)),i.add(e);let n=t.get(e);n||(n=new Set,t.set(e,n)),n.add(A)}function bAi(t,A){if(!A.subcircuit_id&&!A.source_group_id)return[...t];let e=A;if(A.subcircuit_id){const r=new Set([A.subcircuit_id]),a=new Map,g=new Map;for(const I of t)if(I.type==="source_group"){const l=I.source_group_id,B=I.subcircuit_id;B&&g.set(l,B);const C=I.parent_source_group_id;C&&(a.has(C)||a.set(C,[]),a.get(C).push(l))}let c;for(const[I,l]of g)if(l===A.subcircuit_id){c=I;break}if(c){const I=l=>{const B=a.get(l)||[];for(const C of B){const Q=g.get(C);Q&&r.add(Q),I(C)}};I(c),e={...A,subcircuit_ids:Array.from(r)}}}const i=new Map;for(const r of t){const a=`${r.type}_id`,g=r[a];typeof g=="string"&&i.set(g,r)}const n=new Map;for(const r of t){const a=Object.entries(r);for(const[g,c]of a)if(g!=="parent_source_group_id"){if(g.endsWith("_id")&&typeof c=="string"){const I=i.get(c);Nhe(n,r,I)}else if(g.endsWith("_ids")&&Array.isArray(c)){for(const I of c)if(typeof I=="string"){const l=i.get(I);Nhe(n,r,l)}}}}const o=[],s=new Set;for(const r of t){let a=!1;(e.subcircuit_id&&"subcircuit_id"in r&&r.subcircuit_id===e.subcircuit_id||e.subcircuit_ids&&"subcircuit_id"in r&&r.subcircuit_id&&e.subcircuit_ids.includes(r.subcircuit_id)||e.source_group_id&&"source_group_id"in r&&r.source_group_id===e.source_group_id||e.source_group_id&&"member_source_group_ids"in r&&Array.isArray(r.member_source_group_ids)&&r.member_source_group_ids.includes(e.source_group_id))&&(a=!0),a&&(o.push(r),s.add(r))}for(;o.length>0;){const r=o.shift(),a=n.get(r);if(a)for(const g of a)s.has(g)||(s.add(g),o.push(g))}return t.filter(r=>s.has(r))}var _z=(t,A={})=>{const e=t;let i=e._internal_store;if(!i){i={counts:{},editCount:0},e._internal_store=i;for(const o of e){const s=o.type,r=o[`${s}_id`];if(!r)continue;const a=Number.parseInt(r.split("_").pop());Number.isNaN(a)||(i.counts[s]=Math.max(i.counts[s]??0,a))}}const n=new Proxy({},{get:(o,s)=>{if(s==="toArray")return()=>(e.editCount=i.editCount,e);if(s==="editCount")return i.editCount;if(s==="subtree")return a=>_z(bAi(e,a),A);if(s==="insert")return a=>{const g=a.type;if(!g)throw new Error("insert requires an element with a type");i.counts[g]??=-1,i.counts[g]++;const c=i.counts[g],I={...a,type:g,[`${g}_id`]:`${g}_${c}`};return A.validateInserts&&(JyA[g]??tz).parse(I),e.push(I),i.editCount++,I};if(s==="insertAll")return a=>a.map(g=>n.insert(g));const r=s;return{get:a=>e.find(g=>g.type===r&&g[`${r}_id`]===a),getUsing:a=>{const g=Object.keys(a);if(g.length!==1)throw new Error("getUsing requires exactly one key, e.g. { pcb_component_id }");const c=g[0],I=c.replace("_id",""),l=e.find(B=>B.type===I&&B[c]===a[c]);return l?e.find(B=>B.type===r&&B[`${r}_id`]===l[`${r}_id`]):null},getWhere:a=>{const g=Object.keys(a);return e.find(c=>c.type===r&&g.every(I=>c[I]===a[I]))},list:a=>{const g=a?Object.keys(a):[];return e.filter(c=>c.type===r&&g.every(I=>c[I]===a[I]))},insert:a=>{i.counts[r]??=-1,i.counts[r]++;const g=i.counts[r],c={type:r,[`${r}_id`]:`${r}_${g}`,...a};return A.validateInserts&&(JyA[r]??tz).parse(c),e.push(c),i.editCount++,c},delete:a=>{const g=e.find(c=>c[`${r}_id`]===a);g&&(e.splice(e.indexOf(g),1),i.editCount++)},update:(a,g)=>{const c=e.find(I=>I.type===r&&I[`${r}_id`]===a);return c?(Object.assign(c,g),i.editCount++,c):null},select:a=>{if(r==="source_component")return e.find(g=>g.type==="source_component"&&g.name===a.replace(/\./g,""));if(r==="pcb_port"||r==="source_port"||r==="schematic_port"){const[g,c]=a.replace(/\./g,"").split(/[\s\>]+/),I=e.find(B=>B.type==="source_component"&&B.name===g);if(!I)return null;const l=e.find(B=>B.type==="source_port"&&B.source_component_id===I.source_component_id&&(B.name===c||(B.port_hints??[]).includes(c)));if(!l)return null;if(r==="source_port")return l;if(r==="pcb_port")return e.find(B=>B.type==="pcb_port"&&B.source_port_id===l.source_port_id);if(r==="schematic_port")return e.find(B=>B.type==="schematic_port"&&B.source_port_id===l.source_port_id)}}}}});return n};_z.unparsed=_z;var rx=_z;function dmA(t){const A=t.type;return`${A}:${t[`${A}_id`]}`}var Ghe=(t,A={})=>{let e=t._internal_store_indexed;if(!e){e={counts:{},editCount:0,indexes:{}};for(const s of t){const r=s.type,a=s[`${r}_id`];if(!a)continue;const g=Number.parseInt(a.split("_").pop()||"");Number.isNaN(g)||(e.counts[r]=Math.max(e.counts[r]??0,g))}const n=A.indexConfig||{},o=e.indexes;if(n.byId&&(o.byId=new Map),n.byType&&(o.byType=new Map),n.byRelation&&(o.byRelation=new Map),n.bySubcircuit&&(o.bySubcircuit=new Map),n.byCustomField&&n.byCustomField.length>0){o.byCustomField=new Map;for(const s of n.byCustomField)o.byCustomField.set(s,new Map)}for(const s of t){if(n.byId){const r=dmA(s);o.byId.set(r,s)}if(n.byType){const r=o.byType.get(s.type)||[];r.push(s),o.byType.set(s.type,r)}if(n.byRelation){const r=Object.entries(s);for(const[a,g]of r)if(a.endsWith("_id")&&a!==`${s.type}_id`&&typeof g=="string"){const c=o.byRelation.get(a)||new Map,I=c.get(g)||[];I.push(s),c.set(g,I),o.byRelation.set(a,c)}}if(n.bySubcircuit&&"subcircuit_id"in s){const r=s.subcircuit_id;if(r&&typeof r=="string"){const a=o.bySubcircuit.get(r)||[];a.push(s),o.bySubcircuit.set(r,a)}}if(n.byCustomField&&o.byCustomField){for(const r of n.byCustomField)if(r in s){const a=s[r];if(a!==void 0&&(typeof a=="string"||typeof a=="number")){const g=String(a),c=o.byCustomField.get(r),I=c.get(g)||[];I.push(s),c.set(g,I)}}}}t._internal_store_indexed=e}return new Proxy({},{get:(n,o)=>{if(o==="toArray")return()=>(t.editCount=e.editCount,t);if(o==="editCount")return e.editCount;const s=o;return{get:r=>{const a=A.indexConfig||{};return a.byId&&e.indexes.byId?e.indexes.byId.get(`${s}:${r}`)||null:a.byType&&e.indexes.byType?(e.indexes.byType.get(s)||[]).find(c=>c[`${s}_id`]===r)||null:t.find(g=>g.type===s&&g[`${s}_id`]===r)||null},getUsing:r=>{const a=A.indexConfig||{},g=Object.keys(r);if(g.length!==1)throw new Error("getUsing requires exactly one key, e.g. { pcb_component_id }");const c=g[0],I=c.replace("_id","");if(a.byRelation&&e.indexes.byRelation){const B=e.indexes.byRelation.get(c);if(B){const Q=(B.get(r[c])||[]).find(E=>E.type===I);if(!Q)return null;const h=Q[`${s}_id`];return a.byId&&e.indexes.byId?e.indexes.byId.get(`${s}:${h}`)||null:a.byType&&e.indexes.byType?(e.indexes.byType.get(s)||[]).find(u=>u[`${s}_id`]===h)||null:t.find(E=>E.type===s&&E[`${s}_id`]===h)||null}}const l=t.find(B=>B.type===I&&B[c]===r[c]);return l&&t.find(B=>B.type===s&&B[`${s}_id`]===l[`${s}_id`])||null},getWhere:r=>{const a=A.indexConfig||{},g=Object.keys(r);if(g.length===1&&a.byCustomField&&e.indexes.byCustomField){const c=g[0],I=e.indexes.byCustomField.get(c);if(I){const l=String(r[c]);return(I.get(l)||[]).find(C=>C.type===s)||null}}if("subcircuit_id"in r&&a.bySubcircuit&&e.indexes.bySubcircuit){const c=r.subcircuit_id;return(e.indexes.bySubcircuit.get(c)||[]).find(l=>l.type===s&&g.every(B=>l[B]===r[B]))||null}return a.byType&&e.indexes.byType?(e.indexes.byType.get(s)||[]).find(I=>g.every(l=>I[l]===r[l]))||null:t.find(c=>c.type===s&&g.every(I=>c[I]===r[I]))||null},list:r=>{const a=A.indexConfig||{},g=r?Object.keys(r):[];if(g.length===0&&a.byType&&e.indexes.byType)return e.indexes.byType.get(s)||[];if(g.length===1&&g[0]==="subcircuit_id"&&a.bySubcircuit&&e.indexes.bySubcircuit){const I=r.subcircuit_id;return(e.indexes.bySubcircuit.get(I)||[]).filter(B=>B.type===s)}let c;return a.byType&&e.indexes.byType?c=e.indexes.byType.get(s)||[]:c=t.filter(I=>I.type===s),g.length>0?c.filter(I=>g.every(l=>I[l]===r[l])):c},insert:r=>{e.counts[s]??=-1,e.counts[s]++;const a=e.counts[s],g={type:s,[`${s}_id`]:`${s}_${a}`,...r};A.validateInserts&&(JyA[s]??tz).parse(g),t.push(g),e.editCount++;const c=A.indexConfig||{};if(c.byId&&e.indexes.byId){const I=dmA(g);e.indexes.byId.set(I,g)}if(c.byType&&e.indexes.byType){const I=e.indexes.byType.get(s)||[];I.push(g),e.indexes.byType.set(s,I)}if(c.byRelation&&e.indexes.byRelation){const I=Object.entries(g);for(const[l,B]of I)if(l.endsWith("_id")&&l!==`${g.type}_id`&&typeof B=="string"){const C=e.indexes.byRelation.get(l)||new Map,Q=C.get(B)||[];Q.push(g),C.set(B,Q),e.indexes.byRelation.set(l,C)}}if(c.bySubcircuit&&e.indexes.bySubcircuit&&"subcircuit_id"in g){const I=g.subcircuit_id;if(I&&typeof I=="string"){const l=e.indexes.bySubcircuit.get(I)||[];l.push(g),e.indexes.bySubcircuit.set(I,l)}}if(c.byCustomField&&e.indexes.byCustomField){for(const I of c.byCustomField)if(I in g){const l=g[I];if(l!==void 0&&(typeof l=="string"||typeof l=="number")){const B=String(l),C=e.indexes.byCustomField.get(I),Q=C.get(B)||[];Q.push(g),C.set(B,Q)}}}return g},delete:r=>{const a=A.indexConfig||{};let g;if(a.byId&&e.indexes.byId?g=e.indexes.byId.get(`${s}:${r}`):a.byType&&e.indexes.byType?g=(e.indexes.byType.get(s)||[]).find(l=>l[`${s}_id`]===r):g=t.find(I=>I[`${s}_id`]===r),!g)return;const c=t.indexOf(g);if(c>=0&&(t.splice(c,1),e.editCount++),a.byId&&e.indexes.byId){const I=dmA(g);e.indexes.byId.delete(I)}if(a.byType&&e.indexes.byType){const l=(e.indexes.byType.get(s)||[]).filter(B=>B[`${s}_id`]!==r);e.indexes.byType.set(s,l)}if(a.byRelation&&e.indexes.byRelation)for(const[I,l]of e.indexes.byRelation.entries())for(const[B,C]of l.entries()){const Q=C.filter(h=>h!==g);Q.length===0?l.delete(B):l.set(B,Q)}if(a.bySubcircuit&&e.indexes.bySubcircuit&&"subcircuit_id"in g){const I=g.subcircuit_id;if(I){const B=(e.indexes.bySubcircuit.get(I)||[]).filter(C=>C!==g);B.length===0?e.indexes.bySubcircuit.delete(I):e.indexes.bySubcircuit.set(I,B)}}if(a.byCustomField&&e.indexes.byCustomField)for(const I of e.indexes.byCustomField.values())for(const[l,B]of I.entries()){const C=B.filter(Q=>Q!==g);C.length===0?I.delete(l):I.set(l,C)}},update:(r,a)=>{const g=A.indexConfig||{};let c;if(g.byId&&e.indexes.byId?c=e.indexes.byId.get(`${s}:${r}`):g.byType&&e.indexes.byType?c=(e.indexes.byType.get(s)||[]).find(l=>l[`${s}_id`]===r):c=t.find(I=>I.type===s&&I[`${s}_id`]===r),!c)return null;if(g.byRelation&&e.indexes.byRelation){const I=Object.entries(c);for(const[l,B]of I)if(l.endsWith("_id")&&l!==`${c.type}_id`&&typeof B=="string"&&l in a&&a[l]!==B){const C=e.indexes.byRelation.get(l);if(C){const h=(C.get(B)||[]).filter(E=>E!==c);h.length===0?C.delete(B):C.set(B,h)}}}if(g.bySubcircuit&&e.indexes.bySubcircuit&&"subcircuit_id"in c&&"subcircuit_id"in a){const I=c.subcircuit_id,l=a.subcircuit_id;if(I!==l){const C=(e.indexes.bySubcircuit.get(I)||[]).filter(Q=>Q!==c);C.length===0?e.indexes.bySubcircuit.delete(I):e.indexes.bySubcircuit.set(I,C)}}if(g.byCustomField&&e.indexes.byCustomField){for(const I of g.byCustomField)if(I in c&&I in a&&c[I]!==a[I]){const l=e.indexes.byCustomField.get(I);if(l){const B=String(c[I]),Q=(l.get(B)||[]).filter(h=>h!==c);Q.length===0?l.delete(B):l.set(B,Q)}}}if(Object.assign(c,a),e.editCount++,g.byRelation&&e.indexes.byRelation){const I=Object.entries(c);for(const[l,B]of I)if(l.endsWith("_id")&&l!==`${c.type}_id`&&typeof B=="string"&&l in a){const C=e.indexes.byRelation.get(l)||new Map,Q=C.get(B)||[];Q.includes(c)||(Q.push(c),C.set(B,Q),e.indexes.byRelation.set(l,C))}}if(g.bySubcircuit&&e.indexes.bySubcircuit&&"subcircuit_id"in c&&"subcircuit_id"in a){const I=c.subcircuit_id;if(I&&typeof I=="string"){const l=e.indexes.bySubcircuit.get(I)||[];l.includes(c)||(l.push(c),e.indexes.bySubcircuit.set(I,l))}}if(g.byCustomField&&e.indexes.byCustomField){for(const I of g.byCustomField)if(I in c&&I in a){const l=c[I];if(l!==void 0&&(typeof l=="string"||typeof l=="number")){const B=String(l),C=e.indexes.byCustomField.get(I),Q=C.get(B)||[];Q.includes(c)||(Q.push(c),C.set(B,Q))}}}return c},select:r=>{if(s==="source_component")return t.find(a=>a.type==="source_component"&&a.name===r.replace(/\./g,""))||null;if(s==="pcb_port"||s==="source_port"||s==="schematic_port"){const[a,g]=r.replace(/\./g,"").split(/[\s\>]+/),c=t.find(l=>l.type==="source_component"&&l.name===a);if(!c)return null;const I=t.find(l=>l.type==="source_port"&&l.source_component_id===c.source_component_id&&(l.name===g||(l.port_hints??[]).includes(g)));if(!I)return null;if(s==="source_port")return I;if(s==="pcb_port")return t.find(l=>l.type==="pcb_port"&&l.source_port_id===I.source_port_id)||null;if(s==="schematic_port")return t.find(l=>l.type==="schematic_port"&&l.source_port_id===I.source_port_id)||null}return null}}}})};Ghe.unparsed=Ghe;var xAi=t=>{const A=t.type;return t[`${A}_id`]},Lhe=(t,A)=>({minX:Math.min(t.minX,A.minX),minY:Math.min(t.minY,A.minY),maxX:Math.max(t.maxX,A.maxX),maxY:Math.max(t.maxY,A.maxY)}),kz=(t,A,e)=>{const i=e/2;return{minX:t-i,minY:A-i,maxX:t+i,maxY:A+i}},_Ai=(t,A,e,i,n)=>{const o=e/2,s=i/2,r=n*Math.PI/180,a=Math.cos(r),g=Math.sin(r),c=[{x:-o,y:-s},{x:o,y:-s},{x:o,y:s},{x:-o,y:s}].map(I=>({x:t+I.x*a-I.y*g,y:A+I.x*g+I.y*a}));return{minX:Math.min(...c.map(I=>I.x)),minY:Math.min(...c.map(I=>I.y)),maxX:Math.max(...c.map(I=>I.x)),maxY:Math.max(...c.map(I=>I.y))}},pmA=t=>{let A=Number.POSITIVE_INFINITY,e=Number.POSITIVE_INFINITY,i=Number.NEGATIVE_INFINITY,n=Number.NEGATIVE_INFINITY;for(const o of t){if(!o.type.startsWith("pcb_"))continue;if(o.type==="pcb_smtpad"&&o.shape==="polygon"&&Array.isArray(o.points)){for(const c of o.points)A=Math.min(A,c.x),e=Math.min(e,c.y),i=Math.max(i,c.x),n=Math.max(n,c.y);continue}if(o.type==="pcb_hole"&&o.hole_shape==="circle"){const c=kz(o.x,o.y,o.hole_diameter);A=Math.min(A,c.minX),e=Math.min(e,c.minY),i=Math.max(i,c.maxX),n=Math.max(n,c.maxY);continue}if(o.type==="pcb_plated_hole"){let c;if("outer_diameter"in o&&typeof o.outer_diameter=="number"?c=kz(o.x,o.y,o.outer_diameter):"hole_diameter"in o&&typeof o.hole_diameter=="number"&&(c=kz(o.x,o.y,o.hole_diameter)),"rect_pad_width"in o&&typeof o.rect_pad_width=="number"&&"rect_pad_height"in o&&typeof o.rect_pad_height=="number"){const I=_Ai(o.x,o.y,o.rect_pad_width,o.rect_pad_height,"rect_ccw_rotation"in o?o.rect_ccw_rotation??0:0);c=c?Lhe(c,I):I}if("hole_diameter"in o&&typeof o.hole_diameter=="number"){const I=kz(o.x+("hole_offset_x"in o?o.hole_offset_x??0:0),o.y+("hole_offset_y"in o?o.hole_offset_y??0:0),o.hole_diameter);c=c?Lhe(c,I):I}if(c){A=Math.min(A,c.minX),e=Math.min(e,c.minY),i=Math.max(i,c.maxX),n=Math.max(n,c.maxY);continue}}let s,r,a,g;if("x"in o&&"y"in o&&(s=Number(o.x),r=Number(o.y)),"outer_diameter"in o&&(a=Number(o.outer_diameter),g=Number(o.outer_diameter)),"width"in o&&(a=Number(o.width)),"height"in o&&(g=Number(o.height)),"center"in o&&(s=o.center.x,r=o.center.y),s!==void 0&&r!==void 0)A=Math.min(A,s),e=Math.min(e,r),i=Math.max(i,s),n=Math.max(n,r),a!==void 0&&g!==void 0&&(A=Math.min(A,s-a/2),e=Math.min(e,r-g/2),i=Math.max(i,s+a/2),n=Math.max(n,r+g/2)),"radius"in o&&(A=Math.min(A,s-o.radius),e=Math.min(e,r-o.radius),i=Math.max(i,s+o.radius),n=Math.max(n,r+o.radius));else if(o.type==="pcb_trace")for(const c of o.route)A=Math.min(A,c.x),e=Math.min(e,c.y),i=Math.max(i,c.x),n=Math.max(n,c.y);else if(o.type==="pcb_courtyard_outline")for(const c of o.outline)A=Math.min(A,c.x),e=Math.min(e,c.y),i=Math.max(i,c.x),n=Math.max(n,c.y);else if(o.type==="pcb_courtyard_polygon")for(const c of o.points)A=Math.min(A,c.x),e=Math.min(e,c.y),i=Math.max(i,c.x),n=Math.max(n,c.y)}return{minX:A,minY:e,maxX:i,maxY:n}};function kAi(t){let A=0;if(t.length==0)return A;for(var e=0;e<t.length;e++){var i=t.charCodeAt(e);A=(A<<5)-A+i,A=A&A}return Math.abs(A)}var Uhe=[["#69d2e7","#a7dbd8","#e0e4cc","#f38630","#fa6900"],["#fe4365","#fc9d9a","#f9cdad","#c8c8a9","#83af9b"],["#ecd078","#d95b43","#c02942","#542437","#53777a"],["#556270","#4ecdc4","#c7f464","#ff6b6b","#c44d58"],["#774f38","#e08e79","#f1d4af","#ece5ce","#c5e0dc"],["#e8ddcb","#cdb380","#036564","#033649","#031634"],["#490a3d","#bd1550","#e97f02","#f8ca00","#8a9b0f"],["#594f4f","#547980","#45ada8","#9de0ad","#e5fcc2"],["#00a0b0","#6a4a3c","#cc333f","#eb6841","#edc951"],["#e94e77","#d68189","#c6a49a","#c6e5d9","#f4ead5"],["#3fb8af","#7fc7af","#dad8a7","#ff9e9d","#ff3d7f"],["#d9ceb2","#948c75","#d5ded9","#7a6a53","#99b2b7"],["#ffffff","#cbe86b","#f2e9e1","#1c140d","#cbe86b"],["#efffcd","#dce9be","#555152","#2e2633","#99173c"],["#343838","#005f6b","#008c9e","#00b4cc","#00dffc"],["#413e4a","#73626e","#b38184","#f0b49e","#f7e4be"],["#ff4e50","#fc913a","#f9d423","#ede574","#e1f5c4"],["#99b898","#fecea8","#ff847c","#e84a5f","#2a363b"],["#655643","#80bca3","#f6f7bd","#e6ac27","#bf4d28"],["#00a8c6","#40c0cb","#f9f2e7","#aee239","#8fbe00"],["#351330","#424254","#64908a","#e8caa4","#cc2a41"],["#554236","#f77825","#d3ce3d","#f1efa5","#60b99a"],["#5d4157","#838689","#a8caba","#cad7b2","#ebe3aa"],["#8c2318","#5e8c6a","#88a65e","#bfb35a","#f2c45a"],["#fad089","#ff9c5b","#f5634a","#ed303c","#3b8183"],["#ff4242","#f4fad2","#d4ee5e","#e1edb9","#f0f2eb"],["#f8b195","#f67280","#c06c84","#6c5b7b","#355c7d"],["#d1e751","#ffffff","#000000","#4dbce9","#26ade4"],["#1b676b","#519548","#88c425","#bef202","#eafde6"],["#5e412f","#fcebb6","#78c0a8","#f07818","#f0a830"],["#bcbdac","#cfbe27","#f27435","#f02475","#3b2d38"],["#452632","#91204d","#e4844a","#e8bf56","#e2f7ce"],["#eee6ab","#c5bc8e","#696758","#45484b","#36393b"],["#f0d8a8","#3d1c00","#86b8b1","#f2d694","#fa2a00"],["#2a044a","#0b2e59","#0d6759","#7ab317","#a0c55f"],["#f04155","#ff823a","#f2f26f","#fff7bd","#95cfb7"],["#b9d7d9","#668284","#2a2829","#493736","#7b3b3b"],["#bbbb88","#ccc68d","#eedd99","#eec290","#eeaa88"],["#b3cc57","#ecf081","#ffbe40","#ef746f","#ab3e5b"],["#a3a948","#edb92e","#f85931","#ce1836","#009989"],["#300030","#480048","#601848","#c04848","#f07241"],["#67917a","#170409","#b8af03","#ccbf82","#e33258"],["#aab3ab","#c4cbb7","#ebefc9","#eee0b7","#e8caaf"],["#e8d5b7","#0e2430","#fc3a51","#f5b349","#e8d5b9"],["#ab526b","#bca297","#c5ceae","#f0e2a4","#f4ebc3"],["#607848","#789048","#c0d860","#f0f0d8","#604848"],["#b6d8c0","#c8d9bf","#dadabd","#ecdbbc","#fedcba"],["#a8e6ce","#dcedc2","#ffd3b5","#ffaaa6","#ff8c94"],["#3e4147","#fffedf","#dfba69","#5a2e2e","#2a2c31"],["#fc354c","#29221f","#13747d","#0abfbc","#fcf7c5"],["#cc0c39","#e6781e","#c8cf02","#f8fcc1","#1693a7"],["#1c2130","#028f76","#b3e099","#ffeaad","#d14334"],["#a7c5bd","#e5ddcb","#eb7b59","#cf4647","#524656"],["#dad6ca","#1bb0ce","#4f8699","#6a5e72","#563444"],["#5c323e","#a82743","#e15e32","#c0d23e","#e5f04c"],["#edebe6","#d6e1c7","#94c7b6","#403b33","#d3643b"],["#fdf1cc","#c6d6b8","#987f69","#e3ad40","#fcd036"],["#230f2b","#f21d41","#ebebbc","#bce3c5","#82b3ae"],["#b9d3b0","#81bda4","#b28774","#f88f79","#f6aa93"],["#3a111c","#574951","#83988e","#bcdea5","#e6f9bc"],["#5e3929","#cd8c52","#b7d1a3","#dee8be","#fcf7d3"],["#1c0113","#6b0103","#a30006","#c21a01","#f03c02"],["#000000","#9f111b","#b11623","#292c37","#cccccc"],["#382f32","#ffeaf2","#fcd9e5","#fbc5d8","#f1396d"],["#e3dfba","#c8d6bf","#93ccc6","#6cbdb5","#1a1f1e"],["#f6f6f6","#e8e8e8","#333333","#990100","#b90504"],["#1b325f","#9cc4e4","#e9f2f9","#3a89c9","#f26c4f"],["#a1dbb2","#fee5ad","#faca66","#f7a541","#f45d4c"],["#c1b398","#605951","#fbeec2","#61a6ab","#accec0"],["#5e9fa3","#dcd1b4","#fab87f","#f87e7b","#b05574"],["#951f2b","#f5f4d7","#e0dfb1","#a5a36c","#535233"],["#8dccad","#988864","#fea6a2","#f9d6ac","#ffe9af"],["#2d2d29","#215a6d","#3ca2a2","#92c7a3","#dfece6"],["#413d3d","#040004","#c8ff00","#fa023c","#4b000f"],["#eff3cd","#b2d5ba","#61ada0","#248f8d","#605063"],["#ffefd3","#fffee4","#d0ecea","#9fd6d2","#8b7a5e"],["#cfffdd","#b4dec1","#5c5863","#a85163","#ff1f4c"],["#9dc9ac","#fffec7","#f56218","#ff9d2e","#919167"],["#4e395d","#827085","#8ebe94","#ccfc8e","#dc5b3e"],["#a8a7a7","#cc527a","#e8175d","#474747","#363636"],["#f8edd1","#d88a8a","#474843","#9d9d93","#c5cfc6"],["#046d8b","#309292","#2fb8ac","#93a42a","#ecbe13"],["#f38a8a","#55443d","#a0cab5","#cde9ca","#f1edd0"],["#a70267","#f10c49","#fb6b41","#f6d86b","#339194"],["#ff003c","#ff8a00","#fabe28","#88c100","#00c176"],["#ffedbf","#f7803c","#f54828","#2e0d23","#f8e4c1"],["#4e4d4a","#353432","#94ba65","#2790b0","#2b4e72"],["#0ca5b0","#4e3f30","#fefeeb","#f8f4e4","#a5b3aa"],["#4d3b3b","#de6262","#ffb88c","#ffd0b3","#f5e0d3"],["#fffbb7","#a6f6af","#66b6ab","#5b7c8d","#4f2958"],["#edf6ee","#d1c089","#b3204d","#412e28","#151101"],["#9d7e79","#ccac95","#9a947c","#748b83","#5b756c"],["#fcfef5","#e9ffe1","#cdcfb7","#d6e6c3","#fafbe3"],["#9cddc8","#bfd8ad","#ddd9ab","#f7af63","#633d2e"],["#30261c","#403831","#36544f","#1f5f61","#0b8185"],["#aaff00","#ffaa00","#ff00aa","#aa00ff","#00aaff"],["#d1313d","#e5625c","#f9bf76","#8eb2c5","#615375"],["#ffe181","#eee9e5","#fad3b2","#ffba7f","#ff9c97"],["#73c8a9","#dee1b6","#e1b866","#bd5532","#373b44"],["#805841","#dcf7f3","#fffcdd","#ffd8d8","#f5a2a2"]],vAi=t=>{let{x:A,y:e,width:i,height:n}={...t,...t.size,...t.center,...t.position};if(t.x1!==void 0&&t.x2!==void 0&&t.y1!==void 0&&t.y2!==void 0&&(A=(t.x1+t.x2)/2,e=(t.y1+t.y2)/2,i=Math.abs(t.x1-t.x2),n=Math.abs(t.y1-t.y2)),t.points&&Array.isArray(t.points)&&t.points.length>0){const r=t.points.map(B=>B.x),a=t.points.map(B=>B.y),g=Math.min(...r),c=Math.max(...r),I=Math.min(...a),l=Math.max(...a);A=(g+c)/2,e=(I+l)/2,i=c-g,n=l-I}const o=t.text||t.name||t.source?.text||t.source?.name||"?",s=t;return A===void 0||e===void 0?null:(i===void 0&&"outer_diameter"in t&&(i=t.outer_diameter,n=t.outer_diameter),(i===void 0||n===void 0)&&(i=.1,n=.1),{x:A,y:e,width:i,height:n,title:o,content:s,bg_color:Uhe[kAi(t.type||o)%Uhe.length]?.[4]??"#f00"})},FAi=t=>!!t,MAi=t=>{const A=t.filter(g=>g.type.startsWith("pcb_")||g.type.startsWith("schematic_")).concat(t.filter(g=>g.type==="pcb_trace"||g.type==="schematic_trace").flatMap(g=>g.route)).map(g=>vAi(g)).filter(FAi);if(A.length===0)return{center:{x:0,y:0},width:0,height:0};let e=A[0].x-A[0].width/2,i=A[0].x+A[0].width/2,n=A[0].y-A[0].height/2,o=A[0].y+A[0].height/2;for(const g of A.slice(1))e=Math.min(e,g.x-g.width/2),i=Math.max(i,g.x+g.width/2),n=Math.min(n,g.y-g.height/2),o=Math.max(o,g.y+g.height/2);const s=i-e,r=o-n;return{center:{x:e+s/2,y:n+r/2},width:s,height:r}},Cd={IS_SHOWING_PCB_GROUPS:"pcb_viewer_is_showing_pcb_groups",PCB_GROUP_VIEW_MODE:"pcb_viewer_group_view_mode",IS_SHOWING_COPPER_POURS:"pcb_viewer_is_showing_copper_pours",IS_SHOWING_COURTYARDS:"pcb_viewer_is_showing_courtyards",IS_SHOWING_GROUP_ANCHOR_OFFSETS:"pcb_viewer_is_showing_group_anchor_offsets",IS_SHOWING_SOLDER_MASK:"pcb_viewer_is_showing_solder_mask",IS_SHOWING_FABRICATION_NOTES:"pcb_viewer_is_showing_fabrication_notes",IS_SHOWING_SILKSCREEN:"pcb_viewer_is_showing_silkscreen"},GM=(t,A)=>{if(typeof window>"u")return A;try{const e=localStorage.getItem(t);return e!==null?JSON.parse(e):A}catch{return A}},LM=(t,A)=>{if(!(typeof window>"u"))try{localStorage.setItem(t,JSON.stringify(A))}catch{}},RAi=(t,A)=>{if(typeof window>"u")return A;try{const e=localStorage.getItem(t);return e!==null?JSON.parse(e):A}catch{return A}},NAi=(t,A)=>{if(!(typeof window>"u"))try{localStorage.setItem(t,JSON.stringify(A))}catch{}},GAi="named_only",LAi=(t={},A=!1)=>y4A(e=>({selected_layer:"top",pcb_viewer_id:`pcb_viewer_${Math.random().toString().slice(2,10)}`,in_edit_mode:!1,in_move_footprint_mode:!1,in_draw_trace_mode:!1,is_moving_component:!1,is_drawing_trace:!1,is_mouse_over_container:!1,is_showing_multiple_traces_length:!1,is_showing_rats_nest:!1,is_showing_autorouting:!0,is_showing_drc_errors:!0,is_showing_copper_pours:GM(Cd.IS_SHOWING_COPPER_POURS,!0),is_showing_courtyards:GM(Cd.IS_SHOWING_COURTYARDS,!0),is_showing_pcb_groups:A?!1:GM(Cd.IS_SHOWING_PCB_GROUPS,!0),is_showing_group_anchor_offsets:GM(Cd.IS_SHOWING_GROUP_ANCHOR_OFFSETS,!1),is_showing_solder_mask:GM(Cd.IS_SHOWING_SOLDER_MASK,!1),is_showing_silkscreen:GM(Cd.IS_SHOWING_SILKSCREEN,!0),is_showing_fabrication_notes:GM(Cd.IS_SHOWING_FABRICATION_NOTES,!1),pcb_group_view_mode:A?"all":RAi(Cd.PCB_GROUP_VIEW_MODE,GAi),hovered_error_id:null,...t,selectLayer:i=>e({selected_layer:i}),setEditMode:i=>e({in_edit_mode:i!=="off",in_move_footprint_mode:i==="move_footprint",in_draw_trace_mode:i==="draw_trace",is_moving_component:!1,is_drawing_trace:!1}),setIsShowingRatsNest:i=>e({is_showing_rats_nest:i}),setIsMovingComponent:i=>e({is_moving_component:i}),setIsDrawingTrace:i=>e({is_drawing_trace:i}),setIsMouseOverContainer:i=>e({is_mouse_over_container:i}),setIsShowingMultipleTracesLength:i=>e({is_showing_multiple_traces_length:i}),setIsShowingAutorouting:i=>e({is_showing_autorouting:i}),setIsShowingDrcErrors:i=>e({is_showing_drc_errors:i}),setIsShowingCopperPours:i=>{LM(Cd.IS_SHOWING_COPPER_POURS,i),e({is_showing_copper_pours:i})},setIsShowingCourtyards:i=>{LM(Cd.IS_SHOWING_COURTYARDS,i),e({is_showing_courtyards:i})},setIsShowingPcbGroups:i=>{A||(LM(Cd.IS_SHOWING_PCB_GROUPS,i),e({is_showing_pcb_groups:i}))},setIsShowingGroupAnchorOffsets:i=>{LM(Cd.IS_SHOWING_GROUP_ANCHOR_OFFSETS,i),e({is_showing_group_anchor_offsets:i})},setIsShowingSolderMask:i=>{LM(Cd.IS_SHOWING_SOLDER_MASK,i),e({is_showing_solder_mask:i})},setIsShowingSilkscreen:i=>{LM(Cd.IS_SHOWING_SILKSCREEN,i),e({is_showing_silkscreen:i})},setIsShowingFabricationNotes:i=>{LM(Cd.IS_SHOWING_FABRICATION_NOTES,i),e({is_showing_fabrication_notes:i})},setPcbGroupViewMode:i=>{A||(NAi(Cd.PCB_GROUP_VIEW_MODE,i),e({pcb_group_view_mode:i}))},setHoveredErrorId:i=>e({hovered_error_id:i})})),gl=t=>{const A=V.useContext(Hhe);return F4A(A,t)},Hhe=V.createContext(null),UAi=({children:t,initialState:A,disablePcbGroups:e})=>{const i=V.useMemo(()=>LAi(A,e),[e]);return W.jsx(Hhe.Provider,{value:i,children:t})},HAi=()=>{const t=gl(e=>e.pcb_viewer_id),A=(e,i)=>sc(e,{containerId:t,...i});return A.error=(e,i)=>sc.error(e,{containerId:t,...i}),A.promise=sc.promise,A},YAi=()=>{V.useEffect(()=>{M6t()},[]);const t=gl(A=>A.pcb_viewer_id);return W.jsx(F6t,{position:"top-center",containerId:t})};function JAi(){var t=V.useRef(!1),A=V.useCallback(function(){return t.current},[]);return V.useEffect(function(){return t.current=!0,function(){t.current=!1}},[]),A}var TAi=function(t){t===void 0&&(t={});var A=V.useState(t),e=A[0],i=A[1],n=V.useCallback(function(o){i(function(s){return Object.assign({},s,o instanceof Function?o(s):o)})},[]);return[e,n]},PAi=TAi,KAi=function(){},Yhe=typeof window<"u",qAi=CmA(gAi()),OAi=function(){var t=JAi(),A=PAi({value:void 0,error:void 0,noUserInteraction:!0}),e=A[0],i=A[1],n=V.useCallback(function(o){if(t()){var s,r;try{if(typeof o!="string"&&typeof o!="number"){var a=new Error("Cannot copy typeof "+typeof o+" to clipboard, must be a string");console.error(a),i({value:o,error:a,noUserInteraction:!0});return}else if(o===""){var a=new Error("Cannot copy empty string to clipboard.");console.error(a),i({value:o,error:a,noUserInteraction:!0});return}r=o.toString(),s=(0,qAi.default)(r),i({value:r,error:void 0,noUserInteraction:s})}catch(g){i({value:r,error:g,noUserInteraction:s})}}},[]);return[e,n]},WAi=OAi,ZAi=Yhe?V.useLayoutEffect:V.useEffect,VAi=ZAi,Jhe={x:0,y:0,width:0,height:0,top:0,left:0,bottom:0,right:0};function jAi(){var t=V.useState(null),A=t[0],e=t[1],i=V.useState(Jhe),n=i[0],o=i[1],s=V.useMemo(function(){return new window.ResizeObserver(function(r){if(r[0]){var a=r[0].contentRect,g=a.x,c=a.y,I=a.width,l=a.height,B=a.top,C=a.left,Q=a.bottom,h=a.right;o({x:g,y:c,width:I,height:l,top:B,left:C,bottom:Q,right:h})}})},[]);return VAi(function(){if(A)return s.observe(A),function(){s.disconnect()}},[A]),[e,n]}var qT=Yhe&&typeof window.ResizeObserver<"u"?jAi:function(){return[KAi,Jhe]},The=({initialTransform:t,initialTouch1:A,initialTouch2:e,finalTouch1:i,finalTouch2:n})=>{if(!i||!n)return t;const o={x:(A.x+e.x)/2,y:(A.y+e.y)/2},s={x:(i.x+n.x)/2,y:(i.y+n.y)/2},r=Math.hypot(e.x-A.x,e.y-A.y),a=Math.hypot(n.x-i.x,n.y-i.y),g=r===0?1:a/r,c=s.x-o.x,I=s.y-o.y;return An(on(c,I),on(o.x,o.y),$a(g,g),on(-o.x,-o.y),t)},zAi=(t={})=>{const A=V.useRef(null),[e,i]=V.useState(0),n=t.canvasElm??A.current,[o,s]=V.useState(t.initialTransform??xa()),[r,a]=V.useState(0),[g,c]=V.useReducer(d=>d+1,0),I=V.useCallback(d=>{t.onSetTransform&&t.onSetTransform(d),t.transform||s(d)},[t.onSetTransform,s]),l=V.useCallback(d=>{I(d),c()},[I]),B=t.transform??o,C=V.useCallback(()=>{i(Date.now())},[]),Q=V.useRef("none"),h=V.useRef(null),E=V.useRef(null);V.useEffect(()=>{const d=t.canvasElm??A.current;if(d&&!n){a(r+1);return}if(!d){const Z=setTimeout(()=>{a(r+1)},100);return()=>clearTimeout(Z)}let f=t.transform??o,y={x:0,y:0},w={x:0,y:0},D=!1;const S=Z=>({x:Z.pageX-d.getBoundingClientRect().left-window.scrollX,y:Z.pageY-d.getBoundingClientRect().top-window.scrollY});function _(Z){t.enabled!==!1&&(t.shouldDrag&&!t.shouldDrag(Z)||(y=S(Z),!(Date.now()-e<100)&&(D=!0,Z.preventDefault())))}function b(Z){if(!D||t.enabled===!1||t.shouldDrag&&!t.shouldDrag(Z))return;w=S(Z);const X=An(on(w.x-y.x,w.y-y.y),f);I(X),f=X,D=!1}function N(Z){if(S(Z),!D||t.enabled===!1||t.shouldDrag&&!t.shouldDrag(Z))return;w=S(Z);const X=An(on(w.x-y.x,w.y-y.y),f);I(X)}function F(Z){if(t.enabled===!1||t.shouldDrag&&!t.shouldDrag(Z))return;const X=S(Z),eA=An(on(X.x,X.y),$a(1-Z.deltaY/1e3,1-Z.deltaY/1e3),on(-X.x,-X.y),f);I(eA),f=eA,Z.preventDefault()}function L(Z){if(!D||t.shouldDrag&&!t.shouldDrag(Z))return;if(d){const eA=d.getBoundingClientRect();if(Z.clientX>=eA.left+10&&Z.clientX<=eA.right-10&&Z.clientY>=eA.top+10&&Z.clientY<=eA.bottom-10)return}D=!1,w=S(Z);const X=An(on(w.x-y.x,w.y-y.y),f);I(X),f=X}function Y(Z){if(Z.preventDefault(),t.enabled!==!1){if(Z.touches.length===1){Q.current="drag";const X=Z.touches[0];h.current={initialTransform:f,initialTouch:{x:X.clientX,y:X.clientY}}}else if(Z.touches.length===2){Q.current="pinch";const X=Z.touches[0],eA=Z.touches[1];E.current={initialTransform:f,initialTouch1:{x:X.clientX,y:X.clientY},initialTouch2:{x:eA.clientX,y:eA.clientY},finalTouch1:null,finalTouch2:null}}}}function J(Z){if(Z.preventDefault(),t.enabled!==!1){if(Q.current==="drag"&&Z.touches.length===1&&h.current){const X=Z.touches[0],eA={x:X.clientX,y:X.clientY},gA=eA.x-h.current.initialTouch.x,tA=eA.y-h.current.initialTouch.y,iA=An(on(gA,tA),h.current.initialTransform);I(iA)}else if(Q.current==="pinch"&&Z.touches.length===2&&E.current){const X=Z.touches[0],eA=Z.touches[1];E.current.finalTouch1={x:X.clientX,y:X.clientY},E.current.finalTouch2={x:eA.clientX,y:eA.clientY};const gA=The(E.current);I(gA)}}}function O(Z){Z.preventDefault();const X=Z.changedTouches[0];if(Q.current==="drag"&&h.current&&X){const eA={x:X.clientX,y:X.clientY},gA=eA.x-h.current.initialTouch.x,tA=eA.y-h.current.initialTouch.y,iA=An(on(gA,tA),h.current.initialTransform);I(iA),f=iA}else if(Q.current==="pinch"&&E.current){const eA=The(E.current);I(eA),f=eA}Q.current="none",h.current=null,E.current=null}return d.addEventListener("mousedown",_),d.addEventListener("mouseup",b),window.addEventListener("mousemove",N),d.addEventListener("mouseout",L),d.addEventListener("wheel",F),d.addEventListener("touchstart",Y,{passive:!1}),d.addEventListener("touchmove",J,{passive:!1}),d.addEventListener("touchend",O,{passive:!1}),d.addEventListener("touchcancel",O,{passive:!1}),()=>{d.removeEventListener("mousedown",_),d.removeEventListener("mouseup",b),window.removeEventListener("mousemove",N),d.removeEventListener("mouseout",L),d.removeEventListener("wheel",F),d.removeEventListener("touchstart",Y),d.removeEventListener("touchmove",J),d.removeEventListener("touchend",O),d.removeEventListener("touchcancel",O)}},[n,r,g,e,t.enabled,t.shouldDrag]);const u=V.useCallback(d=>Ce(B,d),[B]);return{ref:A,transform:B,applyTransformToPoint:u,setTransform:l,cancelDrag:C}},XAi=zAi;function $Ai(t){const A=new Map;let e=0;function i(n){for(const[,s]of A)if(s.has(n))return s;const o=new Set;return A.set(`connectivity_net${e++}`,o),o}for(const n of t){let o=null;for(const s of n){if(!o)o=i(s);else if(!o.has(s)){const r=i(s);if(r!==o){for(const a of r)o.add(a);A.delete(Array.from(A.entries()).find(([,a])=>a===r)[0])}}o.add(s)}}return Object.fromEntries(Array.from(A.entries()).map(([n,o])=>[n,Array.from(o)]))}var Aei=class{netMap;idToNetMap;constructor(t){this.netMap=t,this.idToNetMap={};for(const[A,e]of Object.entries(t))for(const i of e)this.idToNetMap[i]=A}addConnections(t){for(const A of t){const e=new Set;for(const n of A){const o=this.idToNetMap[n];o&&e.add(o)}let i;if(e.size===0)i=`connectivity_net${Object.keys(this.netMap).length}`,this.netMap[i]=[];else if(e.size===1)i=e.values().next().value??`connectivity_net${Object.keys(this.netMap).length}`;else{i=e.values().next().value??`connectivity_net${Object.keys(this.netMap).length}`;for(const n of e)if(n!==i){this.netMap[i].push(...this.netMap[n]),this.netMap[n]=this.netMap[i];for(const o of this.netMap[i])this.idToNetMap[o]=i}}for(const n of A)this.netMap[i].includes(n)||this.netMap[i].push(n),this.idToNetMap[n]=i}}getIdsConnectedToNet(t){return this.netMap[t]||[]}getNetConnectedToId(t){return this.idToNetMap[t]}areIdsConnected(t,A){if(t===A)return!0;const e=this.getNetConnectedToId(t);if(!e)return!1;const i=this.getNetConnectedToId(A);return i?e===i||i===t||i===t:!1}areAllIdsConnected(t){const A=this.getNetConnectedToId(t[0]);for(const e of t){const i=this.getNetConnectedToId(e);if(i===void 0||i!==A)return!1}return!0}},Phe=t=>{const A=[];for(const i of t)if(i.type==="source_trace")A.push([i.source_trace_id,...i.connected_source_port_ids??[],...i.connected_source_net_ids??[]].filter(Boolean));else if(i.type==="pcb_port"){const{pcb_port_id:n,source_port_id:o}=i;o&&n&&A.push([o,n])}else if(i.type==="pcb_smtpad"){const{pcb_smtpad_id:n,pcb_port_id:o}=i;o&&n&&A.push([n,o])}else if(i.type==="pcb_plated_hole"){const{pcb_plated_hole_id:n,pcb_port_id:o}=i;o&&n&&A.push([n,o])}else if(i.type==="pcb_trace"){const{pcb_trace_id:n,source_trace_id:o}=i,s=Array.isArray(i.route)?i.route.filter(r=>r&&r.route_type==="wire"):[];if(o&&n&&A.push([n,o]),Array.isArray(s)){const r=s.find(g=>g?.start_pcb_port_id)?.start_pcb_port_id,a=s.find(g=>g?.end_pcb_port_id)?.end_pcb_port_id;r&&n&&a&&A.push([r,n,a])}}else if(i.type==="pcb_via"){const{pcb_via_id:n,pcb_trace_id:o}=i;o&&n&&A.push([n,o])}else if(i.type==="source_component"&&i.internally_connected_source_port_ids)for(const n of i.internally_connected_source_port_ids)A.push(n);const e=$Ai(A);return new Aei(e)};function eei({primitivesWithoutInteractionMetadata:t,drawingObjectIdsWithMouseOver:A,primitiveIdsInMousedOverNet:e}){const i=[];for(const n of t){const o={...n};n?.layer==="drill"?(o.is_in_highlighted_net=!1,o.is_mouse_over=!1):A.has(n._pcb_drawing_object_id)?o.is_mouse_over=!0:n._element&&("pcb_trace_id"in n._element&&e.includes(n._element.pcb_trace_id)||"pcb_port_id"in n._element&&e.includes(n._element.pcb_port_id))?o.is_in_highlighted_net=!0:(o.is_in_highlighted_net=!1,o.is_mouse_over=!1),i.push(o)}return i}function tei(t,A){if(t.length<2)throw new Error("Stroke must have at least two points");const e=t.map(I=>Array.isArray(I)?{x:I[0],y:I[1]}:I),i=[],n=[];function o(I,l){const B=l.x-I.x,C=l.y-I.y,Q=Math.sqrt(B*B+C*C);return{x:-C/Q,y:B/Q}}function s(I,l,B,C){const Q=C/2,h={x:I.x+l.x*Q*B,y:I.y+l.y*Q*B};B>0?i.push(h):n.unshift(h)}const r=o(e[0],e[1]),a=e[0].trace_width??A;s(e[0],r,1,a),s(e[0],r,-1,a);for(let I=1;I<e.length-1;I++){const l=e[I-1],B=e[I],C=e[I+1],Q=o(l,B),h=o(B,C),E=Q.x+h.x,u=Q.y+h.y,d=Math.sqrt(E*E+u*u),f=B.trace_width??A;if(d/2>2*(f/2))s(B,Q,1,f),s(B,h,1,f),s(B,Q,-1,f),s(B,h,-1,f);else{const w=1/d;s(B,{x:E*w,y:u*w},1,f),s(B,{x:E*w,y:u*w},-1,f)}}const g=o(e[e.length-2],e[e.length-1]),c=e[e.length-1].trace_width??A;return s(e[e.length-1],g,1,c),s(e[e.length-1],g,-1,c),[...i,...n]}var iei=(t,A)=>{const{x:e,y:i,width:n,height:o,layer:s,rect_border_radius:r}=t,a=t.corner_radius??r??0,g=[{_pcb_drawing_object_id:Nm("rect"),pcb_drawing_type:"rect",x:e,y:i,w:n,h:o,layer:s||"top",_element:t,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port,roundness:a,...t.shape==="rotated_rect"&&t.ccw_rotation!==void 0?{ccw_rotation:t.ccw_rotation}:{}}];if(t.is_covered_with_solder_mask){const c=s==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",l={...{_pcb_drawing_object_id:Nm("rect"),pcb_drawing_type:"rect",x:e,y:i,w:n,h:o,layer:c,_element:t,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port,roundness:a,...t.shape==="rotated_rect"&&t.ccw_rotation!==void 0?{ccw_rotation:t.ccw_rotation}:{}},..."solder_mask_color"in t&&t.solder_mask_color?{color:t.solder_mask_color}:{}};g.push(l)}return g},nei=(t,A)=>{const{x:e,y:i,radius:n,layer:o}=t,s=[{_pcb_drawing_object_id:Nm("circle"),pcb_drawing_type:"circle",x:e,y:i,r:n,layer:o||"top",_element:t,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port}];if(t.is_covered_with_solder_mask){const r=o==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",a={_pcb_drawing_object_id:Nm("circle"),pcb_drawing_type:"circle",x:e,y:i,r:n,layer:r,_element:t,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port,..."solder_mask_color"in t&&t.solder_mask_color?{color:t.solder_mask_color}:{}};s.push(a)}return s},oei=(t,A)=>{const{layer:e,points:i}=t,n=[{_pcb_drawing_object_id:Nm("polygon"),pcb_drawing_type:"polygon",points:fmA(i),layer:e||"top",_element:t,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port}];if(t.is_covered_with_solder_mask){const o=e==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",s={_pcb_drawing_object_id:Nm("polygon"),pcb_drawing_type:"polygon",points:fmA(i),layer:o,_element:t,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port,..."solder_mask_color"in t&&t.solder_mask_color?{color:t.solder_mask_color}:{}};n.push(s)}return n},sei=(t,A)=>{const{x:e,y:i,width:n,height:o,layer:s}=t,r=[{_pcb_drawing_object_id:Nm("pill"),pcb_drawing_type:"pill",x:e,y:i,w:n,h:o,layer:s||"top",_element:t,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port}];if(t.is_covered_with_solder_mask){const a=s==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",g={_pcb_drawing_object_id:Nm("pill"),pcb_drawing_type:"pill",x:e,y:i,w:n,h:o,layer:a,_element:t,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port,..."solder_mask_color"in t&&t.solder_mask_color?{color:t.solder_mask_color}:{}};r.push(g)}return r},rei=(t,A)=>{const{x:e,y:i,width:n,height:o,layer:s,ccw_rotation:r}=t,a=[{_pcb_drawing_object_id:Nm("pill"),pcb_drawing_type:"pill",x:e,y:i,w:n,h:o,layer:s||"top",_element:t,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port,ccw_rotation:r}];if(t.is_covered_with_solder_mask){const g=s==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",c={_pcb_drawing_object_id:Nm("pill"),pcb_drawing_type:"pill",x:e,y:i,w:n,h:o,layer:g,_element:t,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port,ccw_rotation:r,..."solder_mask_color"in t&&t.solder_mask_color?{color:t.solder_mask_color}:{}};a.push(c)}return a},aei=(t,A)=>{const{_parent_pcb_component:e,_parent_source_component:i}=A,n=t,o=typeof n.font_size=="string"?Et.parse(n.font_size):n.font_size??.2;let s;return n.knockout_padding&&(s={left:typeof n.knockout_padding.left=="string"?Et.parse(n.knockout_padding.left):n.knockout_padding.left,top:typeof n.knockout_padding.top=="string"?Et.parse(n.knockout_padding.top):n.knockout_padding.top,bottom:typeof n.knockout_padding.bottom=="string"?Et.parse(n.knockout_padding.bottom):n.knockout_padding.bottom,right:typeof n.knockout_padding.right=="string"?Et.parse(n.knockout_padding.right):n.knockout_padding.right}),[{_pcb_drawing_object_id:Nm("text"),pcb_drawing_type:"text",x:n.anchor_position.x,y:n.anchor_position.y,layer:n.layer,align:n.anchor_alignment??"center",text:n.text,size:o,ccw_rotation:n.ccw_rotation,is_mirrored:n.is_mirrored,is_knockout:n.is_knockout,knockout_padding:s,_element:t,_parent_pcb_component:e,_parent_source_component:i}]},TI=0,Nm=t=>`${t}_${TI++}`,fmA=t=>(t??[]).map(A=>({x:Et.parse(A.x),y:Et.parse(A.y)})),gei=(t,A)=>{const e="pcb_component_id"in t?A.find(s=>s.type==="pcb_component"&&s.pcb_component_id===t.pcb_component_id):void 0,i=e&&"source_component_id"in e?A.find(s=>s.type==="source_component"&&s.source_component_id===e.source_component_id):void 0,n="source_port_id"in t?t.source_port_id:"pcb_port_id"in t?rx(A).pcb_port.get(t.pcb_port_id)?.source_port_id:void 0,o=n?A.find(s=>s.type==="source_port"&&s.source_port_id===n):void 0;switch(t.type){case"pcb_smtpad":{const s={_parent_pcb_component:e,_parent_source_component:i,_source_port:o};return t.shape==="rect"||t.shape==="rotated_rect"?iei(t,s):t.shape==="circle"?nei(t,s):t.shape==="polygon"?oei(t,s):t.shape==="pill"?sei(t,s):t.shape==="rotated_pill"?rei(t,s):[]}case"pcb_trace":{const s=[];if(t.route_thickness_mode==="interpolated"){const g=t.route.map(l=>({x:l.x,y:l.y,trace_width:l.route_type==="wire"?l.width:.5})),c=tei(g,.5),I=t.route[0].layer;return s.push({_pcb_drawing_object_id:`polygon_${TI++}`,_element:t,pcb_drawing_type:"polygon",points:c,layer:I}),t.route.forEach(l=>{l.route_type==="via"&&s.push({_pcb_drawing_object_id:`circle_${TI++}`,_element:t,pcb_drawing_type:"circle",x:l.x,y:l.y,r:l.outer_diameter/2,layer:l.from_layer})}),s}let r=null,a=null;for(const g of t.route)g.route_type==="wire"&&(r!==null&&a!==null&&s.push({_pcb_drawing_object_id:`line_${TI++}`,_element:t,pcb_drawing_type:"line",x1:r,y1:a,x2:g.x,y2:g.y,width:g.width,squareCap:!1,layer:g.layer}),r=g.x,a=g.y);return s}case"pcb_via":{const{x:s,y:r,outer_diameter:a,hole_diameter:g}=t,c=t.from_layer,I=t.to_layer,l=t.layers,B=[];c&&I?B.push(c,I):l&&Array.isArray(l)?B.push(...l):B.push("top","bottom");const C=[];for(const Q of B)C.push({_pcb_drawing_object_id:`circle_${TI++}`,pcb_drawing_type:"circle",x:s,y:r,r:a/2,layer:Q,_element:t,_parent_pcb_component:e,_parent_source_component:i});return C.push({_pcb_drawing_object_id:`circle_${TI++}`,pcb_drawing_type:"circle",x:s,y:r,r:g/2,layer:"drill",_element:t}),C}case"pcb_plated_hole":if(t.shape==="circle"){const{x:s,y:r,hole_diameter:a,outer_diameter:g}=t;return[{_pcb_drawing_object_id:`circle_${TI++}`,pcb_drawing_type:"circle",x:s,y:r,r:g/2,layer:"top",_element:t,_parent_pcb_component:e,_parent_source_component:i,_source_port:o},{_pcb_drawing_object_id:`circle_${TI++}`,pcb_drawing_type:"circle",x:s,y:r,r:a/2,layer:"drill",_element:t}]}else if(t.shape==="oval"){const{x:s,y:r,outer_height:a,outer_width:g,hole_height:c,hole_width:I}=t;return[{_pcb_drawing_object_id:`oval_${TI++}`,pcb_drawing_type:"oval",x:s,y:r,rX:g/2,rY:a/2,layer:"top",_element:t,_parent_pcb_component:e,_parent_source_component:i,_source_port:o},{_pcb_drawing_object_id:`oval_${TI++}`,_element:t,pcb_drawing_type:"oval",x:s,y:r,rX:I/2,rY:c/2,layer:"drill"}]}else if(t.shape==="pill"){const{x:s,y:r,outer_height:a,outer_width:g,hole_height:c,hole_width:I}=t;return[{_pcb_drawing_object_id:`pill_${TI++}`,pcb_drawing_type:"pill",x:s,y:r,w:g,h:a,layer:"top",_element:t,_parent_pcb_component:e,_parent_source_component:i,_source_port:o,ccw_rotation:t.ccw_rotation},{_pcb_drawing_object_id:`pill_${TI++}`,_element:t,pcb_drawing_type:"pill",x:s,y:r,w:I,h:c,layer:"drill",ccw_rotation:t.ccw_rotation}]}else if(t.shape==="circular_hole_with_rect_pad"){const{x:s,y:r,hole_diameter:a,rect_pad_width:g,rect_pad_height:c,rect_border_radius:I,hole_offset_x:l,hole_offset_y:B}=t,C=Et.parse(l??0),Q=Et.parse(B??0);return[{_pcb_drawing_object_id:`rect_${TI++}`,pcb_drawing_type:"rect",x:s,y:r,w:g,h:c,layer:"top",_element:t,_parent_pcb_component:e,_parent_source_component:i,_source_port:o,roundness:I},{_pcb_drawing_object_id:`rect_${TI++}`,pcb_drawing_type:"rect",x:s,y:r,w:g,h:c,layer:"bottom",_element:t,_parent_pcb_component:e,_parent_source_component:i,_source_port:o,roundness:I},{_pcb_drawing_object_id:`circle_${TI++}`,_element:t,pcb_drawing_type:"circle",x:s+C,y:r+Q,r:a/2,layer:"drill"}]}else if(t.shape==="pill_hole_with_rect_pad"){const{x:s,y:r,hole_width:a,hole_height:g,rect_pad_width:c,rect_pad_height:I,rect_border_radius:l}=t;return[{_pcb_drawing_object_id:`rect_${TI++}`,pcb_drawing_type:"rect",x:s,y:r,w:c,h:I,layer:"top",_element:t,_parent_pcb_component:e,_parent_source_component:i,_source_port:o,roundness:l},{_pcb_drawing_object_id:`rect_${TI++}`,pcb_drawing_type:"rect",x:s,y:r,w:c,h:I,layer:"bottom",_element:t,_parent_pcb_component:e,_parent_source_component:i,_source_port:o,roundness:l},{_pcb_drawing_object_id:`pill_${TI++}`,_element:t,pcb_drawing_type:"pill",x:s,y:r,w:a,h:g,layer:"drill"}]}else if(t.shape==="rotated_pill_hole_with_rect_pad"){const{x:s,y:r,hole_width:a,hole_height:g,hole_ccw_rotation:c,rect_pad_width:I,rect_pad_height:l,rect_ccw_rotation:B,rect_border_radius:C}=t;return[{_pcb_drawing_object_id:`rect_${TI++}`,pcb_drawing_type:"rect",x:s,y:r,w:I,h:l,layer:"top",_element:t,_parent_pcb_component:e,_parent_source_component:i,_source_port:o,ccw_rotation:B,roundness:C},{_pcb_drawing_object_id:`rect_${TI++}`,pcb_drawing_type:"rect",x:s,y:r,w:I,h:l,layer:"bottom",_element:t,_parent_pcb_component:e,_parent_source_component:i,_source_port:o,ccw_rotation:B,roundness:C},{_pcb_drawing_object_id:`pill_${TI++}`,_element:t,pcb_drawing_type:"pill",x:s,y:r,w:a,h:g,layer:"drill",ccw_rotation:c}]}else if(t.shape==="hole_with_polygon_pad"){const{x:s,y:r,pad_outline:a,hole_shape:g,hole_diameter:c,hole_width:I,hole_height:l,layers:B,hole_offset_x:C,hole_offset_y:Q}=t,h=Et.parse(C??0),E=Et.parse(Q??0),u=a,d=[];if(u&&Array.isArray(u)){const w=fmA(u).map(D=>({x:D.x+s,y:D.y+r}));for(const D of B||["top","bottom"])d.push({_pcb_drawing_object_id:`polygon_${TI++}`,pcb_drawing_type:"polygon",points:w,layer:D,_element:t,_parent_pcb_component:e,_parent_source_component:i,_source_port:o})}const f={x:s+h,y:r+E},y=[];return g==="circle"?y.push({_pcb_drawing_object_id:`circle_${TI++}`,pcb_drawing_type:"circle",x:f.x,y:f.y,r:(c??0)/2,layer:"drill",_element:t,_parent_pcb_component:e,_parent_source_component:i}):g==="oval"?y.push({_pcb_drawing_object_id:`oval_${TI++}`,pcb_drawing_type:"oval",x:f.x,y:f.y,rX:(I??0)/2,rY:(l??0)/2,layer:"drill",_element:t,_parent_pcb_component:e,_parent_source_component:i}):(g==="pill"||g==="rotated_pill")&&y.push({_pcb_drawing_object_id:`pill_${TI++}`,pcb_drawing_type:"pill",x:f.x,y:f.y,w:I??0,h:l??0,layer:"drill",_element:t,_parent_pcb_component:e,_parent_source_component:i,ccw_rotation:t.ccw_rotation}),[...d,...y]}else return[];case"pcb_copper_text":return aei(t,{_parent_pcb_component:e,_parent_source_component:i})}return[]},yn={board:{anchor:"rgb(255, 38, 226)",aux_items:"rgb(255, 255, 255)",b_adhes:"rgb(0, 0, 132)",b_crtyd:"rgb(38, 233, 255)",b_fab:"rgb(88, 93, 132)",b_mask:"rgba(2, 255, 238, 0.400)",b_paste:"rgb(0, 194, 194)",b_silks:"rgb(242, 237, 161)",background:"rgb(0, 16, 35)",cmts_user:"rgb(89, 148, 220)",copper:{b:"rgb(77, 127, 196)",f:"rgb(200, 52, 52)",in1:"rgb(127, 200, 127)",in10:"rgb(237, 124, 51)",in11:"rgb(91, 195, 235)",in12:"rgb(247, 111, 142)",in13:"rgb(167, 165, 198)",in14:"rgb(40, 204, 217)",in15:"rgb(232, 178, 167)",in16:"rgb(242, 237, 161)",in17:"rgb(237, 124, 51)",in18:"rgb(91, 195, 235)",in19:"rgb(247, 111, 142)",in2:"rgb(206, 125, 44)",in20:"rgb(167, 165, 198)",in21:"rgb(40, 204, 217)",in22:"rgb(232, 178, 167)",in23:"rgb(242, 237, 161)",in24:"rgb(237, 124, 51)",in25:"rgb(91, 195, 235)",in26:"rgb(247, 111, 142)",in27:"rgb(167, 165, 198)",in28:"rgb(40, 204, 217)",in29:"rgb(232, 178, 167)",in3:"rgb(79, 203, 203)",in30:"rgb(242, 237, 161)",in4:"rgb(219, 98, 139)",in5:"rgb(167, 165, 198)",in6:"rgb(40, 204, 217)",in7:"rgb(232, 178, 167)",in8:"rgb(242, 237, 161)",in9:"rgb(141, 203, 129)"},cursor:"rgb(255, 255, 255)",drc:"rgb(194, 194, 194)",drc_error:"rgba(215, 91, 107, 0.800)",drc_exclusion:"rgb(255, 255, 255)",drc_warning:"rgba(255, 208, 66, 0.902)",dwgs_user:"rgb(194, 194, 194)",eco1_user:"rgb(180, 219, 210)",eco2_user:"rgb(216, 200, 82)",edge_cuts:"rgb(208, 210, 205)",f_adhes:"rgb(132, 0, 132)",f_crtyd:"rgb(255, 0, 245)",f_fab:"rgb(175, 175, 175)",f_mask:"rgba(216, 100, 255, 0.400)",f_paste:"rgba(180, 160, 154, 0.902)",f_silks:"rgb(242, 237, 161)",footprint_text_back:"rgb(0, 0, 132)",footprint_text_front:"rgb(194, 194, 194)",footprint_text_invisible:"rgb(132, 132, 132)",grid:"rgb(132, 132, 132)",grid_axes:"rgb(194, 194, 194)",margin:"rgb(255, 38, 226)",microvia:"rgb(0, 132, 132)",no_connect:"rgb(0, 0, 132)",pad_back:"rgb(77, 127, 196)",pad_front:"rgb(200, 52, 52)",pad_plated_hole:"rgb(194, 194, 0)",pad_through_hole:"rgb(227, 183, 46)",plated_hole:"rgb(26, 196, 210)",ratsnest:"rgba(245, 255, 213, 0.702)",select_overlay:"rgb(4, 255, 67)",soldermaskWithCopper:{top:"rgb(18, 82, 50)",bottom:"rgb(77, 127, 196)"},soldermask:{top:"rgb(12, 55, 33)",bottom:"rgb(12, 55, 33)"},through_via:"rgb(236, 236, 236)",user_1:"rgb(194, 194, 194)",user_2:"rgb(89, 148, 220)",user_3:"rgb(180, 219, 210)",user_4:"rgb(216, 200, 82)",user_5:"rgb(194, 194, 194)",user_6:"rgb(89, 148, 220)",user_7:"rgb(180, 219, 210)",user_8:"rgb(216, 200, 82)",user_9:"rgb(232, 178, 167)",via_blind_buried:"rgb(187, 151, 38)",via_hole:"rgb(227, 183, 46)",via_micro:"rgb(0, 132, 132)",via_through:"rgb(236, 236, 236)",worksheet:"rgb(200, 114, 171)"}},Pf=(t,A=1)=>{if(Math.abs(t.a)!==Math.abs(t.d))throw new Error("Cannot scale non-uniformly");return A*Math.abs(t.a)},kc={elementOverlay:40,dimensionOverlay:40,editTraceHintOverlay:40,errorOverlay:40,pcbGroupOverlay:35,ratsNestOverlay:30,toolbarOverlay:70,warnings:30,topLayer:20,clickToInteractOverlay:100},vz={red:"red",black:"black",green:"green",board:"rgb(255, 255, 255)",other:"#eee",top:yn.board.copper.f,inner1:yn.board.copper.in1,inner2:yn.board.copper.in2,inner3:yn.board.copper.in3,inner4:yn.board.copper.in4,inner5:yn.board.copper.in5,inner6:yn.board.copper.in6,inner7:yn.board.copper.in7,inner8:yn.board.copper.in8,bottom:yn.board.copper.b,drill:yn.board.anchor,keepout:yn.board.background,tkeepout:yn.board.b_crtyd,tplace:yn.board.b_silks,top_courtyard:yn.board.f_crtyd,bottom_courtyard:yn.board.b_crtyd,top_silkscreen:yn.board.f_silks,bottom_silkscreen:yn.board.b_silks,top_fabrication:yn.board.f_fab,bottom_fabrication:yn.board.b_fab,soldermask_top:yn.board.soldermask.top,soldermask_bottom:yn.board.soldermask.bottom,soldermask_with_copper_top:yn.board.soldermaskWithCopper.top,soldermask_with_copper_bottom:yn.board.soldermaskWithCopper.bottom,bottom_notes:yn.board.user_2,top_notes:yn.board.user_2,...yn.board},cei=["board","inner6","inner5","inner4","inner3","inner2","inner1","bottom","soldermask_bottom","bottom_silkscreen","top","soldermask_top","bottom_courtyard","bottom_fabrication","top_courtyard","top_fabrication","edge_cuts","top_silkscreen"],Iei=class{canvasLayerMap;ctxLayerMap;aperture;transform;foregroundLayer="top";lastPoint;constructor(t){this.canvasLayerMap=t,this.ctxLayerMap=Object.fromEntries(Object.entries(t).map(([A,e])=>[A,e.getContext("2d")])),this.transform=xa(),this.transform.d*=-1,this.transform=An(this.transform,on(0,-500)),this.lastPoint={x:0,y:0},this.equip({})}clear(){for(const t of Object.values(this.ctxLayerMap))t.clearRect(0,0,t.canvas.width,t.canvas.height)}equip(t){this.aperture={fontSize:0,shape:"circle",mode:"add",size:0,color:"red",layer:"top",opacity:this.foregroundLayer===t.color?1:.5,...t}}drawMeshPattern(t,A,e,i,n,o=45){const s=this.getLayerCtx(),[r,a]=Ce(this.transform,[t,A]),[g,c]=Ce(this.transform,[t+e,A+i]),I=Pf(this.transform,n);s.lineWidth=1,s.strokeStyle=this.aperture.color;const l=B=>{const C=Math.sin(B),Q=Math.cos(B),h=Math.sqrt((g-r)**2+(c-a)**2);for(let E=-h;E<=h;E+=I)s.beginPath(),s.moveTo(r+E*Q-h*C,a+E*C+h*Q),s.lineTo(r+E*Q+h*C,a+E*C-h*Q),s.stroke()};l(o*Math.PI/180),l((o+90)*Math.PI/180)}rect({x:t,y:A,w:e,h:i,mesh_fill:n,is_filled:o=!0,has_stroke:s,is_stroke_dashed:r,stroke_width:a,roundness:g}){const[c,I]=Ce(this.transform,[t-e/2,A-i/2]),[l,B]=Ce(this.transform,[t+e/2,A+i/2]);this.applyAperture();const C=this.getLayerCtx(),Q=g?Pf(this.transform,g):0,h=s===void 0?o===!1:s;if(n)C.save(),C.beginPath(),Q>0&&C.roundRect?C.roundRect(c,I,l-c,B-I,Q):C.rect(c,I,l-c,B-I),C.clip(),this.drawMeshPattern(t-e/2,A-i/2,e,i,.15),C.restore(),Q>0&&C.roundRect?(C.beginPath(),C.roundRect(c,I,l-c,B-I,Q),C.stroke()):C.strokeRect(c,I,l-c,B-I);else if(o!==!1&&(Q>0&&C.roundRect?(C.beginPath(),C.roundRect(c,I,l-c,B-I,Q),C.fill()):C.fillRect(c,I,l-c,B-I)),h){const E=C.lineWidth;if(a!==void 0&&(C.lineWidth=Pf(this.transform,a)),r){let u=[];const d=Math.abs(this.transform.a);if(d>0){const y=.1*d,w=y*1.3;y>.5&&(u=[y,w])}C.setLineDash(u)}Q>0&&C.roundRect?(C.beginPath(),C.roundRect(c,I,l-c,B-I,Q),C.stroke()):C.strokeRect(c,I,l-c,B-I),r&&C.setLineDash([]),a!==void 0&&(C.lineWidth=E)}}rotatedRect(t,A,e,i,n,o,s){const r=this.getLayerCtx();this.applyAperture();const[a,g]=Ce(this.transform,[t-e/2,A-i/2]),[c,I]=Ce(this.transform,[t+e/2,A+i/2]),l=o?Pf(this.transform,o):0;r.save();const[B,C]=Ce(this.transform,[t,A]);r.translate(B,C);const Q=360-n;n&&r.rotate(Q*Math.PI/180),r.translate(-B,-C),s?(r.beginPath(),l>0&&r.roundRect?r.roundRect(a,g,c-a,I-g,l):r.rect(a,g,c-a,I-g),r.clip(),this.drawMeshPattern(t-e/2,A-i/2,e,i,.15),l>0&&r.roundRect?(r.beginPath(),r.roundRect(a,g,c-a,I-g,l),r.stroke()):r.strokeRect(a,g,c-a,I-g)):l>0&&r.roundRect?(r.beginPath(),r.roundRect(a,g,c-a,I-g,l),r.fill()):r.fillRect(a,g,c-a,I-g),r.restore()}rotatedPill(t,A,e,i,n){const o=this.getLayerCtx();this.applyAperture(),o.save();const[s,r]=Ce(this.transform,[t,A]);o.translate(s,r);const a=360-n;n&&o.rotate(a*Math.PI/180),o.translate(-s,-r),this.pill(t,A,e,i),o.restore()}circle(t,A,e,i,n=!0){const o=Pf(this.transform,e),[s,r]=Ce(this.transform,[t,A]);this.applyAperture();const a=this.getLayerCtx();i?(a.save(),a.beginPath(),a.arc(s,r,o,0,2*Math.PI),a.clip(),this.drawMeshPattern(t-e,A-e,e*2,e*2,.15),a.restore(),a.beginPath(),a.arc(s,r,o,0,2*Math.PI),a.stroke()):(a.beginPath(),a.arc(s,r,o,0,2*Math.PI),a.fill())}oval(t,A,e,i){const n=Pf(this.transform,e),o=Pf(this.transform,i),[s,r]=Ce(this.transform,[t,A]);this.applyAperture();const a=this.getLayerCtx();a.beginPath(),a.ellipse(s,r,n,o,0,0,2*Math.PI),a.fill(),a.closePath()}pill(t,A,e,i){const[n,o]=Ce(this.transform,[t-e/2,A+i/2]),s=Pf(this.transform,e),r=Pf(this.transform,i),a=Math.min(s,r)/2;this.applyAperture();const g=this.getLayerCtx();g.beginPath(),g.arc(n+a,o+a,a,Math.PI,Math.PI*1.5),g.arc(n+s-a,o+a,a,Math.PI*1.5,0),g.arc(n+s-a,o+r-a,a,0,Math.PI*.5),g.arc(n+a,o+r-a,a,Math.PI*.5,Math.PI),g.fill(),g.closePath()}polygon(t){if(t.length<3)return;this.applyAperture();const A=this.getLayerCtx(),e=t.map(n=>Ce(this.transform,[n.x,n.y]));A.beginPath(),A.moveTo(e[0][0],e[0][1]);for(let n=1;n<e.length;n++)A.lineTo(e[n][0],e[n][1]);A.closePath(),A.fill("evenodd");const i=Pf(this.transform,this.aperture.size);i>0&&(A.lineWidth=i,A.stroke())}debugText(t,A,e){const[i,n]=Ce(this.transform,[A,e]);this.applyAperture();const o=this.getLayerCtx();o.font="10px sans-serif",o.fillText(t,i,n)}getLayerCtx(){const t=this.ctxLayerMap[this.aperture.layer];if(!t)throw new Error(`No context for layer "${this.aperture.layer}"`);return t}orderAndFadeLayers(){const{canvasLayerMap:t,foregroundLayer:A}=this,e=A==="top"?"soldermask_top":A==="bottom"?"soldermask_bottom":void 0,i=A==="top"?"top_silkscreen":A==="bottom"?"bottom_silkscreen":void 0,n=A==="top"?"top_notes":A==="bottom"?"bottom_notes":void 0,o=A==="top"?"top_fabrication":A==="bottom"?"bottom_fabrication":void 0,s=A==="top"?"top_courtyard":A==="bottom"?"bottom_courtyard":void 0,r=new Set([A,"drill","edge_cuts","other","board",...e?[e]:[],...i?[i]:[],...n?[n]:[],...o?[o]:[],...s?[s]:[]]),a=[A,"edge_cuts",...e?[e]:[],...i?[i]:[],...n?[n]:[],...o?[o]:[],...s?[s]:[]],g=A==="drill"?[]:["drill"],c=A==="drill"?["drill"]:[],I=[...cei.filter(l=>!a.includes(l)),...g,A,...e?[e]:[],...c,"edge_cuts",...i?[i]:[],...n?[n]:[],...o?[o]:[],...s?[s]:[]];I.forEach((l,B)=>{const C=t[l];C&&(C.style.zIndex=`${kc.topLayer-(I.length-B)}`,C.style.opacity=r.has(l)?"1":"0.5")})}applyAperture(){const{transform:t,aperture:A}=this;let{size:e,mode:i,color:n,fontSize:o,layer:s}=A;s in this.ctxLayerMap||(this.aperture.layer="other");const r=this.getLayerCtx();if(!r)throw new Error(`No context for layer "${this.foregroundLayer}"`);if(n||(n="undefined"),r.lineWidth=Pf(t,e),r.lineCap="round",i==="add"){r.globalCompositeOperation="source-over";let a=vz[n.toLowerCase()];if(!a)try{a=Ta(n).rgb().toString()}catch{console.warn(`Invalid color format: '${n}'`),a="white"}r.fillStyle=a,r.strokeStyle=a}else r.globalCompositeOperation="destination-out",r.fillStyle="rgba(0,0,0,1)",r.strokeStyle="rgba(0,0,0,1)";r.font=`${Pf(tm(t),o)}px sans-serif`}moveTo(t,A){this.lastPoint={x:t,y:A}}lineTo(t,A){const[e,i]=Ce(this.transform,[t,A]),{size:n,shape:o,mode:s}=this.aperture,r=Pf(this.transform,n),{lastPoint:a}=this,g=Ce(this.transform,a);this.applyAperture();const c=this.getLayerCtx();o==="square"&&c.fillRect(g.x-r/2,g.y-r/2,r,r),c.beginPath(),c.moveTo(g.x,g.y),c.lineTo(e,i),c.stroke(),c.closePath(),o==="square"&&c.fillRect(e-r/2,i-r/2,r,r),this.lastPoint={x:t,y:A}}polygonWithArcs(t){const A=this.getLayerCtx(),e=i=>{if(i.vertices.length===0)return;const n=i.vertices[0],o=Ce(this.transform,[n.x,n.y]);A.moveTo(o[0],o[1]);for(let s=0;s<i.vertices.length;s++){const r=i.vertices[s],a=i.vertices[(s+1)%i.vertices.length];if(r.bulge&&r.bulge!==0){const g=r.bulge,c=a.x-r.x,I=a.y-r.y,l=Math.sqrt(c*c+I*I);if(l<1e-9){const F=Ce(this.transform,[a.x,a.y]);A.lineTo(F[0],F[1]);continue}const B=4*Math.atan(g),C=Math.abs(l/(2*Math.sin(B/2))),Q=(r.x+a.x)/2,h=(r.y+a.y)/2,E=c/l,d=-(I/l),f=E,y=Math.sqrt(Math.max(0,C*C-(l/2)**2)),w=Q+y*d*Math.sign(g),D=h+y*f*Math.sign(g),S=Math.atan2(r.y-D,r.x-w);let _=Math.atan2(a.y-D,a.x-w);g>0&&_<S?_+=2*Math.PI:g<0&&_>S&&(_-=2*Math.PI);const b=Ce(this.transform,[w,D]),N=Pf(this.transform,C);A.arc(b[0],b[1],N,-S,-_,g>0)}else{const g=Ce(this.transform,[a.x,a.y]);A.lineTo(g[0],g[1])}}A.closePath()};if(A.beginPath(),e(t.outer_ring),t.inner_rings)for(const i of t.inner_rings)e(i);A.fill("evenodd")}};function lei(t){return t.type==="pcb_copper_pour"}function Fz({canvas:t,elements:A,layers:e,realToCanvasMat:i}){const n=A.filter(lei);if(n.length===0)return;const o=new iQ(t);o.realToCanvasMat=i,o.drawElements(n,{layers:e})}var Bei={...gp,silkscreen:{top:yn.board.f_fab,bottom:yn.board.b_fab}};function Cei(t){return t.type.includes("pcb_fabrication_note")}function Khe({canvas:t,elements:A,layers:e,realToCanvasMat:i}){const n=new iQ(t);n.configure({colorOverrides:Bei}),n.realToCanvasMat=i;const o=A.filter(Cei);n.drawElements(o,{layers:e})}function Qei(t){return t.type==="pcb_hole"}function hei({canvas:t,elements:A,layers:e,realToCanvasMat:i,drawSoldermask:n}){const o=new iQ(t);o.realToCanvasMat=i;const s=A.filter(Qei);o.drawElements(s,{layers:e,drawSoldermask:n})}function Eei(t){return t.type==="pcb_board"}function uei({canvas:t,elements:A,layers:e,realToCanvasMat:i,drawSoldermask:n}){const o=new iQ(t);o.realToCanvasMat=i;const s=A.filter(Eei);for(const r of s)o.drawElements([r],{layers:e,drawSoldermask:!1,drawBoardMaterial:n??!1,minBoardOutlineStrokePx:2})}function dei(t){return t.type==="pcb_cutout"}function pei({canvas:t,elements:A,layers:e,realToCanvasMat:i}){const n=new iQ(t);n.realToCanvasMat=i;const o=A.filter(dei);n.drawElements(o,{layers:e})}function fei(t){return t.type==="pcb_keepout"}function yei({canvas:t,elements:A,layers:e,realToCanvasMat:i}){const n=A.filter(fei);if(n.length===0)return;const o=new iQ(t);o.realToCanvasMat=i,o.drawElements(n,{layers:[]})}function mei(t){return t.type.startsWith("pcb_note_")}function qhe({canvas:t,elements:A,layers:e,realToCanvasMat:i}){const n=new iQ(t);n.realToCanvasMat=i;const o=A.filter(mei);n.drawElements(o,{layers:e})}function wei(t){return t.type==="pcb_panel"}function Dei({canvas:t,elements:A,layers:e,realToCanvasMat:i,drawSoldermask:n}){const o=new iQ(t);o.realToCanvasMat=i;const s=A.filter(wei);for(const r of s)o.drawElements([r],{layers:e})}var Sei={...gp,copper:{...gp.copper,top:Ta(yn.board.pad_front).lighten(.5).toString(),bottom:Ta(yn.board.pad_back).lighten(.5).toString(),inner1:Ta(yn.board.copper.in1).lighten(.5).toString(),inner2:Ta(yn.board.copper.in2).lighten(.5).toString(),inner3:Ta(yn.board.copper.in3).lighten(.5).toString(),inner4:Ta(yn.board.copper.in4).lighten(.5).toString(),inner5:Ta(yn.board.copper.in5).lighten(.5).toString(),inner6:Ta(yn.board.copper.in6).lighten(.5).toString()}};function bei(t){return t.type==="pcb_smtpad"}function xei({canvas:t,elements:A,layers:e,realToCanvasMat:i,primitives:n,drawSoldermask:o}){const s=A.filter(bei).filter(c=>{const I=c.layer;return e.some(l=>l==="top_copper"&&I==="top"||l==="bottom_copper"&&I==="bottom"||l==="inner1_copper"&&I==="inner1"||l==="inner2_copper"&&I==="inner2"||l==="inner3_copper"&&I==="inner3"||l==="inner4_copper"&&I==="inner4"||l==="inner5_copper"&&I==="inner5"||l==="inner6_copper"&&I==="inner6")});if(s.length===0)return;const r=new Set;if(n)for(const c of n)(c.is_mouse_over||c.is_in_highlighted_net)&&c._element?.type==="pcb_smtpad"&&r.add(c._element.pcb_smtpad_id);const a=s.filter(c=>r.has(c.pcb_smtpad_id)),g=s.filter(c=>!r.has(c.pcb_smtpad_id));if(g.length>0){const c=new iQ(t);c.realToCanvasMat=i,c.drawElements(g,{layers:e,drawSoldermask:o})}if(a.length>0){const c=new iQ(t);c.configure({colorOverrides:Sei}),c.realToCanvasMat=i,c.drawElements(a,{layers:e,drawSoldermask:o})}}var _ei={...gp,copper:{...gp.copper,top:Ta(yn.board.pad_front).lighten(.5).toString(),bottom:Ta(yn.board.pad_back).lighten(.5).toString(),inner1:Ta(yn.board.copper.in1).lighten(.5).toString(),inner2:Ta(yn.board.copper.in2).lighten(.5).toString(),inner3:Ta(yn.board.copper.in3).lighten(.5).toString(),inner4:Ta(yn.board.copper.in4).lighten(.5).toString(),inner5:Ta(yn.board.copper.in5).lighten(.5).toString(),inner6:Ta(yn.board.copper.in6).lighten(.5).toString()}};function kei(t){return t.type==="pcb_trace"}var vei=t=>t.map(A=>A.endsWith("_copper")?A.replace("_copper",""):A),Fei=(t,A)=>{const e=t.route.filter(i=>i.route_type==="wire"&&"layer"in i&&A.has(i.layer));return e.length===0?null:{...t,route:e}};function Mei({canvas:t,elements:A,layers:e,realToCanvasMat:i,primitives:n}){const o=new Set(vei(e)),s=A.filter(kei).map(c=>Fei(c,o)).filter(c=>c!==null);if(s.length===0)return;const r=new Set;if(n)for(const c of n)(c.is_mouse_over||c.is_in_highlighted_net)&&c._element?.type==="pcb_trace"&&r.add(c._element.pcb_trace_id);const a=[],g=[];for(const c of s)r.has(c.pcb_trace_id)?a.push(c):g.push(c);if(g.length>0){const c=new iQ(t);c.realToCanvasMat=i,c.drawElements(g,{layers:e})}if(a.length>0){const c=new iQ(t);c.configure({colorOverrides:_ei}),c.realToCanvasMat=i,c.drawElements(a,{layers:e})}}var Rei={...gp,copper:{...gp.copper,top:Ta(yn.board.pad_front).lighten(.5).toString(),bottom:Ta(yn.board.pad_back).lighten(.5).toString()}};function Nei(t){return t.type==="pcb_plated_hole"}function Ohe({canvas:t,elements:A,layers:e,realToCanvasMat:i,primitives:n,drawSoldermask:o}){const s=A.filter(Nei);if(s.length===0)return;const r=new Set;if(n)for(const c of n)(c.is_mouse_over||c.is_in_highlighted_net)&&c._element?.type==="pcb_plated_hole"&&r.add(c._element.pcb_plated_hole_id);const a=s.filter(c=>r.has(c.pcb_plated_hole_id)),g=s.filter(c=>!r.has(c.pcb_plated_hole_id));if(g.length>0){const c=new iQ(t);c.realToCanvasMat=i,c.drawElements(g,{layers:e,drawSoldermask:o})}if(a.length>0){const c=new iQ(t);c.configure({colorOverrides:Rei}),c.realToCanvasMat=i,c.drawElements(a,{layers:e,drawSoldermask:o})}}function Whe(t){const{lines:A,anchorPoint:e,ccwRotation:i}=t;if(!i)return A;const n=i*Math.PI/180,o=Tl(n),s=An(on(e.x,e.y),o,on(-e.x,-e.y));return Ce(s,e),A.map(r=>({...r,x1:Ce(s,{x:r.x1,y:r.y1}).x,y1:Ce(s,{x:r.x1,y:r.y1}).y,x2:Ce(s,{x:r.x2,y:r.y2}).x,y2:Ce(s,{x:r.x2,y:r.y2}).y}))}var Gei=.6,Zhe=.2,Vhe=t=>{const A=t.size*.7,e=A*Gei,i=A*Zhe,n=A*Zhe,o=t.text.split(/\r?\n/),s=t.text.length>0&&A>0,r=s?o.length:0,a=s?o.map(I=>I.length===0?0:I.length*e+(I.length-1)*i):[],g=a.length>0?Math.max(...a):0,c=r>0?r*A+(r-1)*n:0;return{text_lines:o,line_count:r,line_widths:a,target_height:A,target_width_char:e,space_between_chars:i,space_between_lines:n,width:g,height:c}},jhe=t=>{const A=Vhe(t);return{width:A.width,height:A.height,lineHeight:A.target_height,lineSpacing:A.space_between_lines,lineCount:A.line_count}},zhe=t=>{const{text_lines:A,line_count:e,line_widths:i,target_height:n,target_width_char:o,space_between_chars:s,space_between_lines:r,width:a}=Vhe(t);if(n<=0||e===0)return[];const g=n/12,c=[];for(let I=0;I<e;I++){const l=-I*(n+r),B=i[I],C=(a-B)/2;let Q=t.x+C;for(let h=0;h<A[I].length;h++){const E=A[I][h],u=XF[E]??XF[E.toUpperCase()];if(!u){Q+=o+s;continue}for(const{x1:d,y1:f,x2:y,y2:w}of u)c.push({_pcb_drawing_object_id:Nm("line"),pcb_drawing_type:"line",x1:Q+o*d,y1:t.y+l+n*f,x2:Q+o*y,y2:t.y+l+n*w,width:g,layer:t.layer,unit:t.unit,color:t.color});Q+=o+s}}return c};function yS(t){const e=t.color??vz[t.layer];let i=Ta(e);return t._element?.type==="pcb_copper_pour"&&(i=i.alpha(.7)),t.is_mouse_over||t.is_in_highlighted_net?i.lighten(.5).rgb().toString():i.rgb().toString()}var Xhe=(t,A)=>{t.equip({size:A.zoomIndependent?A.width/t.transform.a:A.width,shape:A.squareCap?"square":"circle",color:yS(A),layer:A.layer}),t.moveTo(A.x1,A.y1),t.lineTo(A.x2,A.y2)},Lei=(t,A,e)=>{switch(e){case"top_left":return{x:0,y:-A};case"top_center":return{x:-t/2,y:-A};case"top_right":return{x:-t,y:-A};case"center_left":return{x:0,y:-A/2};case"center":return{x:-t/2,y:-A/2};case"center_right":return{x:-t,y:-A/2};case"bottom_left":return{x:0,y:0};case"bottom_center":return{x:-t/2,y:0};case"bottom_right":return{x:-t,y:0};default:return{x:0,y:0}}},$he=t=>t.layer==="bottom_silkscreen"||t.layer==="bottom"?t.is_mirrored!==!1:t.is_mirrored===!0,Uei=(t,A)=>{t.equip({fontSize:A.size,color:yS(A),layer:A.layer});const{width:e,height:i}=jhe(A),n=Lei(e,i,A.align);A.x??=0,A.y??=0;const o={x:A.x,y:A.y};let s=zhe({...A,x:A.x+n.x,y:A.y+n.y});if($he(A)&&(s=s.map(r=>({...r,x1:2*A.x-r.x1,x2:2*A.x-r.x2}))),A.ccw_rotation){const r={lines:s,anchorPoint:o,ccwRotation:A.ccw_rotation};s=Whe(r)}for(const r of s)Xhe(t,r)},Hei=(t,A)=>{const{width:e,height:i,lineHeight:n}=jhe(A);A.x??=0,A.y??=0;const o=A.knockout_padding??{left:A.size*.5,right:A.size*.5,top:A.size*.3,bottom:A.size*.3},s=e+o.left+o.right,r=i+o.top+o.bottom,a=e/2,g=n-i/2,c=A.x-a,I=A.y-g,l={x:A.x,y:A.y},B={_pcb_drawing_object_id:`knockout_rect_${A._pcb_drawing_object_id}`,x:A.x,y:A.y,w:s,h:r,layer:A.layer,ccw_rotation:A.ccw_rotation};A.ccw_rotation?eEe(t,B):AEe(t,B);let C=zhe({...A,x:c,y:I});if($he(A)&&(C=C.map(Q=>({...Q,x1:2*A.x-Q.x1,x2:2*A.x-Q.x2}))),A.ccw_rotation){const Q={lines:C,anchorPoint:l,ccwRotation:A.ccw_rotation};C=Whe(Q)}for(const Q of C)t.equip({size:Q.width,shape:"circle",color:"black",layer:A.layer,mode:"subtract"}),t.moveTo(Q.x1,Q.y1),t.lineTo(Q.x2,Q.y2);t.equip({mode:"add"})},AEe=(t,A)=>{t.equip({color:yS(A),layer:A.layer,size:A.stroke_width}),t.rect({x:A.x,y:A.y,w:A.w,h:A.h,mesh_fill:A.mesh_fill,is_filled:A.is_filled,has_stroke:A.has_stroke,is_stroke_dashed:A.is_stroke_dashed,stroke_width:A.stroke_width,roundness:A.roundness})},eEe=(t,A)=>{t.equip({color:yS(A),layer:A.layer}),t.rotatedRect(A.x,A.y,A.w,A.h,A.ccw_rotation,A.roundness,A.mesh_fill)},Yei=(t,A)=>{t.equip({color:yS(A),layer:A.layer}),t.rotatedPill(A.x,A.y,A.w,A.h,A.ccw_rotation)},Jei=(t,A)=>{t.equip({color:yS(A),layer:A.layer}),t.circle(A.x,A.y,A.r,A.mesh_fill)},Tei=(t,A)=>{t.equip({color:yS(A),layer:A.layer}),t.oval(A.x,A.y,A.rX,A.rY)},Pei=(t,A)=>{t.equip({color:yS(A),layer:A.layer}),t.pill(A.x,A.y,A.w,A.h)},Kei=(t,A)=>{t.equip({color:yS(A),layer:A.layer}),t.polygon(A.points)},qei=(t,A)=>{t.equip({color:yS(A),layer:A.layer}),t.polygonWithArcs(A.brep_shape)},Oei=(t,A)=>{switch(A.pcb_drawing_type){case"line":return Xhe(t,A);case"text":return A.is_knockout?Hei(t,A):Uei(t,A);case"rect":return A.ccw_rotation?eEe(t,A):AEe(t,A);case"circle":return Jei(t,A);case"oval":return Tei(t,A);case"pill":return A.ccw_rotation?Yei(t,A):Pei(t,A);case"polygon":return Kei(t,A);case"polygon_with_arcs":return qei(t,A)}},Wei=(t,A)=>{for(const e of A)Oei(t,e)},Zei={...gp,copper:{...gp.copper,top:Ta(yn.board.pad_front).lighten(.5).toString(),bottom:Ta(yn.board.pad_back).lighten(.5).toString(),inner1:Ta(yn.board.copper.in1).lighten(.5).toString(),inner2:Ta(yn.board.copper.in2).lighten(.5).toString(),inner3:Ta(yn.board.copper.in3).lighten(.5).toString(),inner4:Ta(yn.board.copper.in4).lighten(.5).toString(),inner5:Ta(yn.board.copper.in5).lighten(.5).toString(),inner6:Ta(yn.board.copper.in6).lighten(.5).toString()},soldermask:{...gp.soldermask,top:Ta(yn.board.soldermask.top).lighten(.35).toString(),bottom:Ta(yn.board.soldermask.bottom).lighten(.35).toString()}};function tEe({canvas:t,elements:A,layers:e,realToCanvasMat:i,drawSoldermaskTop:n,drawSoldermaskBottom:o,primitives:s}){const r=new iQ(t);r.realToCanvasMat=i;const a=A.filter(l=>l.type==="pcb_board");if(a.length<=1)r.drawElements(A,{layers:e,drawSoldermask:!0,drawSoldermaskTop:n,drawSoldermaskBottom:o,drawBoardMaterial:!1});else{const l=A.filter(B=>B.type!=="pcb_board");for(const B of a)r.drawElements([B,...l],{layers:e,drawSoldermask:!0,drawSoldermaskTop:n,drawSoldermaskBottom:o,drawBoardMaterial:!1})}if(!s)return;const g=new Set;for(const l of s){if(!(l.is_mouse_over||l.is_in_highlighted_net))continue;const B=l._element;B?.type==="pcb_smtpad"?g.add(B.pcb_smtpad_id):B?.type==="pcb_plated_hole"?g.add(B.pcb_plated_hole_id):B?.type==="pcb_via"&&g.add(B.pcb_via_id)}if(g.size===0)return;const c=A.filter(l=>l.type==="pcb_smtpad"?g.has(l.pcb_smtpad_id):l.type==="pcb_plated_hole"?g.has(l.pcb_plated_hole_id):l.type==="pcb_via"?g.has(l.pcb_via_id):!1);if(c.length===0)return;const I=new iQ(t);I.configure({colorOverrides:Zei}),I.realToCanvasMat=i,I.drawElements(c,{layers:e,drawSoldermask:!0,drawSoldermaskTop:n,drawSoldermaskBottom:o,drawBoardMaterial:!1})}var Vei={...gp,silkscreen:{top:yn.board.f_silks,bottom:yn.board.b_silks}};function jei(t){return t.type.includes("pcb_silkscreen")}function iEe({canvas:t,elements:A,layers:e,realToCanvasMat:i}){const n=new iQ(t);n.configure({colorOverrides:Vei}),n.realToCanvasMat=i;const o=A.filter(jei);n.drawElements(o,{layers:e})}var zei={...gp,copper:{...gp.copper,top:Ta(yn.board.pad_front).lighten(.5).toString(),bottom:Ta(yn.board.pad_back).lighten(.5).toString()}};function Xei(t){return t.type==="pcb_via"}function nEe({canvas:t,elements:A,layers:e,realToCanvasMat:i,primitives:n,drawSoldermask:o}){const s=A.filter(Xei).filter(c=>e.some(I=>I.includes("copper")));if(s.length===0)return;const r=new Set;if(n)for(const c of n)(c.is_mouse_over||c.is_in_highlighted_net)&&c._element?.type==="pcb_via"&&r.add(c._element.pcb_via_id);const a=s.filter(c=>r.has(c.pcb_via_id)),g=s.filter(c=>!r.has(c.pcb_via_id));if(g.length>0){const c=new iQ(t);c.realToCanvasMat=i,c.drawElements(g,{layers:e,drawSoldermask:o})}if(a.length>0){const c=new iQ(t);c.configure({colorOverrides:zei}),c.realToCanvasMat=i,c.drawElements(a,{layers:e,drawSoldermask:o})}}var $ei={...gp,courtyard:{top:yn.board.f_crtyd,bottom:yn.board.b_crtyd}};function Ati(t){return t.type==="pcb_courtyard_circle"||t.type==="pcb_courtyard_rect"||t.type==="pcb_courtyard_outline"}function oEe({canvas:t,elements:A,layers:e,realToCanvasMat:i}){const n=new iQ(t);n.configure({colorOverrides:$ei}),n.realToCanvasMat=i;const o=A.filter(Ati);n.drawElements(o,{layers:e})}var eti=["board","bottom","soldermask_bottom","bottom_silkscreen","top","soldermask_top","soldermask_with_copper_bottom","soldermask_with_copper_top","top_fabrication","bottom_fabrication","inner1","inner2","inner3","inner4","inner5","inner6","drill","edge_cuts","bottom_notes","top_notes","top_silkscreen","top_courtyard","bottom_courtyard","other"],tti=({primitives:t,elements:A,transform:e,grid:i,width:n=500,height:o=500})=>{const s=V.useRef({}),r=gl(l=>l.selected_layer),a=gl(l=>l.is_showing_solder_mask),g=gl(l=>l.is_showing_fabrication_notes),c=gl(l=>l.is_showing_courtyards),I=gl(l=>l.is_showing_silkscreen);return V.useEffect(()=>{if(!s.current||Object.keys(s.current).length===0)return;const l=Object.fromEntries(Object.entries(s.current).filter(([Q,h])=>!!h));if(Object.keys(l).length===0)return;const B=new Iei(l);e&&(B.transform=e),B.clear(),B.foregroundLayer=r;const C=t.filter(Q=>a||!Q.layer?.includes("soldermask")).filter(Q=>I||!Q.layer?.includes("silkscreen")).filter(Q=>g||!Q.layer?.includes("fabrication")).filter(Q=>Q.layer!=="board").filter(Q=>Q._element?.type!=="pcb_smtpad").filter(Q=>Q._element?.type!=="pcb_plated_hole").filter(Q=>Q._element?.type!=="pcb_via").filter(Q=>Q._element?.type!=="pcb_trace");if(Wei(B,C),e){const Q=s.current.top,h=s.current.bottom,E=s.current.inner1,u=s.current.inner2,d=s.current.inner3,f=s.current.inner4,y=s.current.inner5,w=s.current.inner6,D=[{canvas:Q,copperLayer:"top_copper"},{canvas:h,copperLayer:"bottom_copper"},{canvas:E,copperLayer:"inner1_copper"},{canvas:u,copperLayer:"inner2_copper"},{canvas:d,copperLayer:"inner3_copper"},{canvas:f,copperLayer:"inner4_copper"},{canvas:y,copperLayer:"inner5_copper"},{canvas:w,copperLayer:"inner6_copper"}];for(const{canvas:Y,copperLayer:J}of D)Y&&Mei({canvas:Y,elements:A,layers:[J],realToCanvasMat:e,primitives:t});Q&&Ohe({canvas:Q,elements:A,layers:["top_copper"],realToCanvasMat:e,primitives:t,drawSoldermask:a}),h&&Ohe({canvas:h,elements:A,layers:["bottom_copper"],realToCanvasMat:e,primitives:t,drawSoldermask:a}),Q&&Fz({canvas:Q,elements:A,layers:["top_copper"],realToCanvasMat:e}),h&&Fz({canvas:h,elements:A,layers:["bottom_copper"],realToCanvasMat:e});for(const{canvas:Y,copperLayer:J}of D)Y&&xei({canvas:Y,elements:A,layers:[J],realToCanvasMat:e,primitives:t,drawSoldermask:a});if(Q&&nEe({canvas:Q,elements:A,layers:["top_copper"],realToCanvasMat:e,primitives:t,drawSoldermask:a}),h&&nEe({canvas:h,elements:A,layers:["bottom_copper"],realToCanvasMat:e,primitives:t,drawSoldermask:a}),a){const Y=r==="bottom"?"bottom":"top",J=Y==="top",O=Y==="bottom",Z=s.current.soldermask_top;Z&&Y==="top"&&tEe({canvas:Z,elements:A,layers:["top_soldermask"],realToCanvasMat:e,drawSoldermaskTop:J,drawSoldermaskBottom:O,primitives:t});const X=s.current.soldermask_bottom;X&&Y==="bottom"&&tEe({canvas:X,elements:A,layers:["bottom_soldermask"],realToCanvasMat:e,drawSoldermaskTop:J,drawSoldermaskBottom:O,primitives:t})}Q&&Fz({canvas:Q,elements:A,layers:["top_copper"],realToCanvasMat:e}),h&&Fz({canvas:h,elements:A,layers:["bottom_copper"],realToCanvasMat:e});const S=s.current.drill;if(S&&hei({canvas:S,elements:A,layers:["drill"],realToCanvasMat:e}),I){const Y=s.current.top_silkscreen;Y&&iEe({canvas:Y,elements:A,layers:["top_silkscreen"],realToCanvasMat:e});const J=s.current.bottom_silkscreen;J&&iEe({canvas:J,elements:A,layers:["bottom_silkscreen"],realToCanvasMat:e})}if(g){const Y=s.current.top_fabrication;Y&&Khe({canvas:Y,elements:A,layers:["top_fabrication_note"],realToCanvasMat:e});const J=s.current.bottom_fabrication;J&&Khe({canvas:J,elements:A,layers:["bottom_fabrication_note"],realToCanvasMat:e})}const _=s.current.bottom_notes;_&&qhe({canvas:_,elements:A,layers:["bottom_user_note"],realToCanvasMat:e});const b=s.current.top_notes;if(b&&qhe({canvas:b,elements:A,layers:["top_user_note"],realToCanvasMat:e}),c){const Y=s.current.top_courtyard;Y&&oEe({canvas:Y,elements:A,layers:["top_courtyard"],realToCanvasMat:e});const J=s.current.bottom_courtyard;J&&oEe({canvas:J,elements:A,layers:["bottom_courtyard"],realToCanvasMat:e})}const N=s.current.board;N&&(Dei({canvas:N,elements:A,layers:[],realToCanvasMat:e,drawSoldermask:a}),uei({canvas:N,elements:A,layers:[],realToCanvasMat:e,drawSoldermask:a}));const F=s.current.edge_cuts;F&&pei({canvas:F,elements:A,layers:["edge_cuts"],realToCanvasMat:e});const L=[{canvas:Q,layer:"top"},{canvas:h,layer:"bottom"}];for(const{canvas:Y,layer:J}of L)Y&&yei({canvas:Y,elements:A,layers:[J],realToCanvasMat:e})}B.orderAndFadeLayers()},[t,A,e,r,a,g,c,I]),W.jsxs("div",{style:{backgroundColor:"black",width:n,height:o,position:"relative"},children:[W.jsx(hz.SuperGrid,{textColor:"rgba(0,255,0,0.8)",majorColor:"rgba(0,255,0,0.4)",minorColor:"rgba(0,255,0,0.2)",screenSpaceCellSize:200,width:n,height:o,transform:e,stringifyCoord:(l,B,C)=>`${hz.toMMSI(l,C)}, ${hz.toMMSI(B,C)}`}),eti.filter(l=>!(!a&&l.includes("soldermask")||!I&&l.includes("silkscreen"))).map(l=>l.replace(/-/g,"")).map((l,B)=>W.jsx("canvas",{className:`pcb-layer-${l}`,ref:C=>{s.current??={},C?s.current[l]=C:delete s.current[l]},style:{position:"absolute",zIndex:B,left:0,top:0,pointerEvents:"none"},width:n,height:o},l))]})},iti=.6,nti=1;CmA(cAi(),1),CmA(SAi(),1);var Mz=["rgba(239, 68, 68, 0.8)","rgba(249, 115, 22, 0.8)","rgba(245, 158, 11, 0.8)","rgba(234, 179, 8, 0.8)","rgba(132, 204, 22, 0.8)","rgba(34, 197, 94, 0.8)","rgba(16, 185, 129, 0.8)","rgba(20, 184, 166, 0.8)","rgba(6, 182, 212, 0.8)","rgba(14, 165, 233, 0.8)","rgba(59, 130, 246, 0.8)","rgba(99, 102, 241, 0.8)","rgba(139, 92, 246, 0.8)","rgba(168, 85, 247, 0.8)","rgba(217, 70, 239, 0.8)","rgba(236, 72, 153, 0.8)","rgba(249, 168, 212, 0.8)","rgba(161, 161, 170, 0.8)"];function sEe(t,A,e,i={}){const n=i.padding??40,o=i.yFlip??!1;let s;if("center"in t){const c=t.width/2,I=t.height/2;s={minX:t.center.x-c,maxX:t.center.x+c,minY:t.center.y-I,maxY:t.center.y+I}}else s=t;const r=s.maxX-s.minX||1,a=s.maxY-s.minY||1,g=Math.min((A-2*n)/r,(e-2*n)/a);return An(on(A/2,e/2),$a(g,o?-g:g),on(-(s.minX+r/2),-(s.minY+a/2)))}function oti(t){const A=[...t.points||[],...(t.lines||[]).flatMap(e=>e.points),...(t.rects||[]).flatMap(e=>{const i=e.width/2,n=e.height/2;return[{x:e.center.x-i,y:e.center.y-n},{x:e.center.x+i,y:e.center.y-n},{x:e.center.x-i,y:e.center.y+n},{x:e.center.x+i,y:e.center.y+n}]}),...(t.circles||[]).flatMap(e=>[{x:e.center.x-e.radius,y:e.center.y},{x:e.center.x+e.radius,y:e.center.y},{x:e.center.x,y:e.center.y-e.radius},{x:e.center.x,y:e.center.y+e.radius}]),...(t.texts||[]).flatMap(e=>{const i=e.fontSize??12,n=e.text.length*i*iti,o=i*nti,s=e.anchorSide??"center",r={top_left:{dx:0,dy:0},top_center:{dx:-n/2,dy:0},top_right:{dx:-n,dy:0},center_left:{dx:0,dy:-o/2},center:{dx:-n/2,dy:-o/2},center_right:{dx:-n,dy:-o/2},bottom_left:{dx:0,dy:-o},bottom_center:{dx:-n/2,dy:-o},bottom_right:{dx:-n,dy:-o}},{dx:a,dy:g}=r[s],c=e.x+a,I=e.y+g;return[{x:c,y:I},{x:c+n,y:I+o}]})];return A.length===0?{minX:-1,maxX:1,minY:-1,maxY:1}:A.reduce((e,i)=>({minX:Math.min(e.minX,i.x),maxX:Math.max(e.maxX,i.x),minY:Math.min(e.minY,i.y),maxY:Math.max(e.maxY,i.y)}),{minX:1/0,maxX:-1/0,minY:1/0,maxY:-1/0})}function sti(t,A,e={}){const i=A instanceof HTMLCanvasElement?A.getContext("2d"):A;if(!i)throw new Error("Could not get 2D context from canvas");const n=A instanceof HTMLCanvasElement?A.width:A.canvas.width,o=A instanceof HTMLCanvasElement?A.height:A.canvas.height;let s;if(e.transform)s=e.transform;else if(e.viewbox)s=sEe(e.viewbox,n,o,{padding:e.padding,yFlip:e.yFlip});else{const r=oti(t),a=t.coordinateSystem==="cartesian";s=sEe(r,n,o,{padding:e.padding??40,yFlip:a})}i.clearRect(0,0,n,o),i.save(),t.rects&&t.rects.length>0&&t.rects.forEach(r=>{const a=r.width/2,g=r.height/2,c=Ce(s,{x:r.center.x-a,y:r.center.y-g}),I=Ce(s,{x:r.center.x+a,y:r.center.y+g}),l=Math.abs(I.x-c.x),B=Math.abs(I.y-c.y);i.beginPath(),i.rect(Math.min(c.x,I.x),Math.min(c.y,I.y),l,B),r.fill&&(i.fillStyle=r.fill,i.fill()),r.stroke&&(i.strokeStyle=r.stroke,i.stroke())}),t.circles&&t.circles.length>0&&t.circles.forEach(r=>{const a=Ce(s,r.center),g=r.radius*Math.abs(s.a);i.beginPath(),i.arc(a.x,a.y,g,0,2*Math.PI),r.fill&&(i.fillStyle=r.fill,i.fill()),r.stroke&&(i.strokeStyle=r.stroke??"transparent",i.stroke())}),t.lines&&t.lines.length>0&&t.lines.forEach((r,a)=>{if(r.points.length===0)return;i.beginPath();const g=Ce(s,r.points[0]);i.moveTo(g.x,g.y);for(let c=1;c<r.points.length;c++){const I=Ce(s,r.points[c]);i.lineTo(I.x,I.y)}if(i.strokeStyle=r.strokeColor||Mz[a%Mz.length],r.strokeWidth?i.lineWidth=r.strokeWidth*s.a:i.lineWidth=2,i.lineCap="round",r.strokeDash)if(typeof r.strokeDash=="string"){let c;if(r.strokeDash.includes(","))c=r.strokeDash.split(",").map(I=>parseFloat(I.trim())).filter(I=>!Number.isNaN(I));else{const I=parseFloat(r.strokeDash.trim());c=Number.isNaN(I)?[]:[I]}i.setLineDash(c)}else i.setLineDash(r.strokeDash.map(c=>c*Math.abs(s.a)));else i.setLineDash([]);i.stroke()}),t.points&&t.points.length>0&&t.points.forEach((r,a)=>{const g=Ce(s,r);i.beginPath(),i.arc(g.x,g.y,3,0,2*Math.PI),i.fillStyle=r.color||Mz[a%Mz.length],i.fill(),r.label&&!e.disableLabels&&(i.fillStyle=r.color||"black",i.font="12px sans-serif",i.fillText(r.label,g.x+5,g.y-5))}),t.texts&&t.texts.length>0&&t.texts.forEach(r=>{const a=Ce(s,{x:r.x,y:r.y});i.fillStyle=r.color||"black",i.font=`${(r.fontSize??12)*Math.abs(s.a)}px sans-serif`;const g=r.anchorSide??"center",c={top_left:"left",center_left:"left",bottom_left:"left",top_center:"center",center:"center",bottom_center:"center",top_right:"right",center_right:"right",bottom_right:"right"},I={top_left:"top",top_center:"top",top_right:"top",center_left:"middle",center:"middle",center_right:"middle",bottom_left:"bottom",bottom_center:"bottom",bottom_right:"bottom"};i.textAlign=c[g],i.textBaseline=I[g],i.fillText(r.text,a.x,a.y)}),i.restore()}var rti=({children:t,transform:A,debugGraphics:e})=>{const i=V.useRef(null),[n,{width:o,height:s}]=qT(),r=gl(a=>a.is_showing_autorouting);return V.useEffect(()=>{r&&i.current&&e&&o&&s&&(i.current.width=o,i.current.height=s,sti(e,i.current,{transform:A,disableLabels:!0}))},[e,A,o,s,r]),r?W.jsxs("div",{ref:n,style:{position:"relative",width:"100%",height:"100%"},children:[t,W.jsx("canvas",{ref:i,style:{position:"absolute",top:0,left:0,opacity:.5,zIndex:100,width:"100%",height:"100%",pointerEvents:"none"}})]}):t},ati=({children:t,transform:A=xa(),elements:e=[]})=>{const[i,{width:n,height:o}]=qT(),s=V.useRef(null);return V.useEffect(()=>{const r=s.current;if(!r||!n||!o)return;r.width=n,r.height=o;const a=r.getContext("2d");if(!a)return;a.clearRect(0,0,n,o);const g=e.filter(I=>I.type==="pcb_component"),c=e.filter(I=>I.type==="pcb_manual_edit_conflict_warning");a.strokeStyle=yn.board.drc_warning,a.lineWidth=2,c.forEach(I=>{const l=g.find(O=>O.pcb_component_id===I.pcb_component_id);if(!l)return;const{width:B,height:C,center:Q}=l,h=Ce(A,Q),E=B*Math.abs(A.a),u=C*Math.abs(A.d),d=.1*Math.abs(A.a),f=E+d*2,y=u+d*2,w=h.x-f/2,D=h.y-y/2;a.beginPath(),a.rect(w,D,f,y),a.stroke();const S="Manual Edit Conflict",_=4,b=Math.max(8,Math.min(12,10*Math.abs(A.a)));a.font=`${b}px sans-serif`;const F=a.measureText(S).width+_*2,L=b+_*2,Y=w+(f-F)/2,J=D+y+5;a.fillStyle="rgba(0, 0, 0, 0.7)",a.beginPath(),a.roundRect(Y,J,F,L,3),a.fill(),a.fillStyle=yn.board.drc_warning,a.textAlign="center",a.textBaseline="middle",a.fillText(S,Y+F/2,J+L/2)})},[e,A,n,o]),W.jsxs("div",{ref:i,style:{position:"relative",width:"100%",height:"100%"},children:[t,W.jsx("canvas",{ref:s,style:{position:"absolute",top:0,left:0,pointerEvents:"none",zIndex:kc.warnings}})]})},Rz=(t,A,e)=>e(t,A),rEe=(t,A,e,i,n)=>{const o=n*Math.PI/180,s=Math.cos(o),r=Math.sin(o),a=t-e,g=A-i,c=a*s-g*r,I=a*r+g*s;return{x:c+e,y:I+i}},OT=t=>{if(t.length===0)return null;let A=t[0].x,e=t[0].x,i=t[0].y,n=t[0].y;for(const o of t)A=Rz(A,o.x,Math.min),e=Rz(e,o.x,Math.max),i=Rz(i,o.y,Math.min),n=Rz(n,o.y,Math.max);return{minX:A,maxX:e,minY:i,maxY:n}},gti=(t,A)=>({minX:Math.min(t.minX,A.minX),maxX:Math.max(t.maxX,A.maxX),minY:Math.min(t.minY,A.minY),maxY:Math.max(t.maxY,A.maxY)}),cti=(t,A)=>t?gti(t,A):A,Iti=t=>{switch(t.pcb_drawing_type){case"line":{const A=(t.width??0)/2,e=[{x:t.x1,y:t.y1},{x:t.x2,y:t.y2}],i=OT(e);return i?{minX:i.minX-A,maxX:i.maxX+A,minY:i.minY-A,maxY:i.maxY+A}:null}case"rect":{const A=t.w/2,e=t.h/2,i=[{x:t.x-A,y:t.y-e},{x:t.x+A,y:t.y-e},{x:t.x+A,y:t.y+e},{x:t.x-A,y:t.y+e}],n=t.ccw_rotation??0,o=n===0?i:i.map(s=>rEe(s.x,s.y,t.x,t.y,n));return OT(o)}case"circle":return{minX:t.x-t.r,maxX:t.x+t.r,minY:t.y-t.r,maxY:t.y+t.r};case"oval":return{minX:t.x-t.rX,maxX:t.x+t.rX,minY:t.y-t.rY,maxY:t.y+t.rY};case"pill":{const A=t.w/2,e=t.h/2,i=[{x:t.x-A,y:t.y-e},{x:t.x+A,y:t.y-e},{x:t.x+A,y:t.y+e},{x:t.x-A,y:t.y+e}],n=t.ccw_rotation??0,o=n===0?i:i.map(s=>rEe(s.x,s.y,t.x,t.y,n));return OT(o)}case"polygon":return OT(t.points);case"polygon_with_arcs":{const A=t.brep_shape.outer_ring.vertices.map(e=>({x:e.x,y:e.y}));return OT(A)}case"text":{const A=t.size??0,e=t.text?t.text.length*A*.6:0,i=A;if(e===0&&i===0)return{minX:t.x,maxX:t.x,minY:t.y,maxY:t.y};const n=e/2,o=i/2;return{minX:t.x-n,maxX:t.x+n,minY:t.y-o,maxY:t.y+o}}default:return null}};function lti(t){const{dimensionStart:A,dimensionEnd:e,screenDimensionStart:i,screenDimensionEnd:n,flipX:o,flipY:s}=t,r=e.x-A.x,a=e.y-A.y,g=Math.sqrt(r*r+a*a),c=n.x-i.x,I=n.y-i.y,l=Math.sqrt(c*c+I*I),B=Math.atan2(I,c)*(180/Math.PI),C=Math.abs(B)%90,h=Math.min(C,90-C)>15,E=(i.x+n.x)/2,u=(i.y+n.y)/2,d=15,f=B+90;let y=Math.cos(f*Math.PI/180)*d,w=Math.sin(f*Math.PI/180)*d;const D=c>0&&I<0,S=c>0&&I>0,_=c<0&&I>0;o!==s&&!D&&(y=-y,w=-w),D&&(y+=Math.cos(f*Math.PI/180)*-45,w+=Math.sin(f*Math.PI/180)*-45),S&&(y+=Math.cos(f*Math.PI/180)+-20,w+=Math.sin(f*Math.PI/180)+-10),_&&(y+=Math.cos(f*Math.PI/180)*10,w+=Math.sin(f*Math.PI/180)*10);const b=E+y,N=u+w;return{distance:g,screenDistance:l,x:b,y:N,show:g>.01&&l>30&&h}}function Bti(t){const{dimensionStart:A,dimensionEnd:e,screenDimensionStart:i,screenDimensionEnd:n,flipX:o,flipY:s}=t;return V.useMemo(()=>lti({dimensionStart:A,dimensionEnd:e,screenDimensionStart:i,screenDimensionEnd:n,flipX:o,flipY:s}),[A,e,i,n,o,s])}var Cti=(t,A,e)=>{const i=e*Math.PI/180,n=Math.cos(i),o=Math.sin(i),s=t.x-A.x,r=t.y-A.y,a=s*n-r*o,g=s*o+r*n;return{x:a+A.x,y:g+A.y}},aEe=(t,A,e,i)=>{const n={top_left:{x:t.x-A,y:t.y-e},top_center:{x:t.x,y:t.y-e},top_right:{x:t.x+A,y:t.y-e},center_left:{x:t.x-A,y:t.y},center:{x:t.x,y:t.y},center_right:{x:t.x+A,y:t.y},bottom_left:{x:t.x-A,y:t.y+e},bottom_center:{x:t.x,y:t.y+e},bottom_right:{x:t.x+A,y:t.y+e}};return i===0?Object.entries(n).map(([o,s])=>({anchor:o,point:s})):Object.entries(n).map(([o,s])=>({anchor:o,point:Cti(s,t,i)}))},Qti=t=>{switch(t.pcb_drawing_type){case"rect":{const A=t.ccw_rotation??0;return aEe({x:t.x,y:t.y},t.w/2,t.h/2,A)}case"pill":{const A=t.ccw_rotation??0;return aEe({x:t.x,y:t.y},t.w/2,t.h/2,A)}case"circle":return[{anchor:"circle_center",point:{x:t.x,y:t.y}},{anchor:"circle_right",point:{x:t.x+t.r,y:t.y}},{anchor:"circle_left",point:{x:t.x-t.r,y:t.y}},{anchor:"circle_top",point:{x:t.x,y:t.y-t.r}},{anchor:"circle_bottom",point:{x:t.x,y:t.y+t.r}}];case"oval":return[{anchor:"oval_center",point:{x:t.x,y:t.y}},{anchor:"oval_right",point:{x:t.x+t.rX,y:t.y}},{anchor:"oval_left",point:{x:t.x-t.rX,y:t.y}},{anchor:"oval_top",point:{x:t.x,y:t.y-t.rY}},{anchor:"oval_bottom",point:{x:t.x,y:t.y+t.rY}}];case"line":{const A={x:(t.x1+t.x2)/2,y:(t.y1+t.y2)/2};return[{anchor:"line_start",point:{x:t.x1,y:t.y1}},{anchor:"line_mid",point:A},{anchor:"line_end",point:{x:t.x2,y:t.y2}}]}case"polygon":return t.points.map((A,e)=>({anchor:`polygon_vertex_${e}`,point:A}));case"polygon_with_arcs":return t.brep_shape.outer_ring.vertices.map((A,e)=>({anchor:`polygon_with_arcs_vertex_${e}`,point:{x:A.x,y:A.y}}));default:return[]}},hti=16,UM=5,gEe=t=>{if(t.pcb_drawing_type==="text")return!0;const A=t._element;if(!A||typeof A!="object")return!1;const e=typeof A.type=="string"?A.type:void 0;return e?!!(e.startsWith("pcb_silkscreen_")||e.startsWith("pcb_note_")||e==="pcb_text"||e.startsWith("pcb_fabrication_note_")&&e!=="pcb_fabrication_note_rect"):!1},Eti=({children:t,transform:A,focusOnHover:e=!1,primitives:i=[]})=>{A||(A=xa());const[n,o]=V.useState(!1),[s,r]=V.useState(!1),[a,g]=V.useState(!1),[c,I]=V.useState({start:null,end:null}),l=gl(J=>J.is_mouse_over_container),B=V.useCallback(()=>{a&&(g(!1),window.dispatchEvent(new Event("disarm-dimension-tool")))},[a]),[C,Q]=V.useState({x:0,y:0}),[h,E]=V.useState({x:0,y:0}),u=V.useRef({x:0,y:0}),d=V.useRef(null),y=d.current?.getBoundingClientRect(),w=V.useMemo(()=>{const J=new Map;for(const O of i){if(!O._element||gEe(O)||O.pcb_drawing_type==="pill"||O.pcb_drawing_type==="rect"&&O.ccw_rotation&&O.ccw_rotation!==0)continue;const Z=Iti(O);if(!Z)continue;const X=J.get(O._element);J.set(O._element,cti(X??void 0,Z))}return J},[i]),D=V.useMemo(()=>{const J=[];for(const O of i){if(!O._element||gEe(O))continue;const Z=Qti(O);if(Z.length!==0)for(const X of Z)J.push({anchor:X.anchor,point:X.point,element:O._element})}return J},[i]),S=V.useMemo(()=>{const J=[];w.forEach((O,Z)=>{if(!O)return;const X=(O.minX+O.maxX)/2,eA=(O.minY+O.maxY)/2,gA={top_left:{x:O.minX,y:O.minY},top_center:{x:X,y:O.minY},top_right:{x:O.maxX,y:O.minY},center_left:{x:O.minX,y:eA},center:{x:X,y:eA},center_right:{x:O.maxX,y:eA},bottom_left:{x:O.minX,y:O.maxY},bottom_center:{x:X,y:O.maxY},bottom_right:{x:O.maxX,y:O.maxY}};for(const[tA,iA]of Object.entries(gA))J.push({anchor:tA,point:iA,element:Z})});for(const O of D)J.push(O);return J.push({anchor:"origin",point:{x:0,y:0},element:null}),J},[w,D]),_=V.useMemo(()=>S.map((J,O)=>({...J,id:`${O}-${J.anchor}`,screenPoint:Ce(A,J.point)})),[S,A]),b=V.useCallback(J=>{if(_.length===0)return{point:J,id:null};const O=Ce(A,J);let Z=null;for(const X of _){const eA=X.screenPoint.x-O.x,gA=X.screenPoint.y-O.y,tA=Math.hypot(eA,gA);tA>hti||(!Z||tA<Z.distance)&&(Z={distance:tA,id:X.id,point:X.point})}return Z?{point:Z.point,id:Z.id}:{point:J,id:null}},[_,A]);V.useEffect(()=>{const J=Z=>{const X=Z.target;if(X.tagName==="INPUT"||X.tagName==="TEXTAREA"||X.isContentEditable)return;const eA=d.current?.contains(document.activeElement)||document.activeElement===d.current;if(!(!l&&!eA)){if(Z.key==="d"){const gA=b({x:u.current.x,y:u.current.y});Q({x:gA.point.x,y:gA.point.y}),E({x:gA.point.x,y:gA.point.y}),I({start:gA.id,end:gA.id}),n?(o(!1),r(!1),I({start:null,end:null})):(o(!0),r(!0)),B()}Z.key==="Escape"&&(o(!1),r(!1),I({start:null,end:null}),B())}},O=()=>{g(!0)};return window.addEventListener("keydown",J),window.addEventListener("arm-dimension-tool",O),()=>{window.removeEventListener("keydown",J),window.removeEventListener("arm-dimension-tool",O),B()}},[l,n,B,b]);const N=Ce(A,C),F=Ce(A,h),L={left:Math.min(N.x,F.x),right:Math.max(N.x,F.x),top:Math.min(N.y,F.y),bottom:Math.max(N.y,F.y),flipX:N.x>F.x,flipY:N.y>F.y,width:0,height:0};L.width=L.right-L.left,L.height=L.bottom-L.top;const Y=Bti({dimensionStart:C,dimensionEnd:h,screenDimensionStart:N,screenDimensionEnd:F,flipX:L.flipX,flipY:L.flipY});return W.jsxs("div",{ref:d,"data-pcb-viewer":!0,tabIndex:0,style:{position:"relative",outline:"none"},onMouseEnter:()=>{e&&d.current&&d.current.focus()},onMouseLeave:()=>{d.current&&d.current.blur()},onClick:()=>{d.current&&d.current.focus()},onMouseMove:J=>{const O=J.currentTarget.getBoundingClientRect(),Z=J.clientX-O.left,X=J.clientY-O.top,eA=Ce(tm(A),{x:Z,y:X});if(u.current.x=eA.x,u.current.y=eA.y,s){const gA=b(eA);E({x:gA.point.x,y:gA.point.y}),I(tA=>({...tA,end:gA.id}))}},onMouseDown:J=>{const O=J.currentTarget.getBoundingClientRect(),Z=J.clientX-O.left,X=J.clientY-O.top,eA=Ce(tm(A),{x:Z,y:X});if(a&&!n){const gA=b(eA);Q({x:gA.point.x,y:gA.point.y}),E({x:gA.point.x,y:gA.point.y}),I({start:gA.id,end:gA.id}),o(!0),r(!0),B()}else s?(r(!1),I(gA=>({...gA,end:null}))):n&&(o(!1),I({start:null,end:null}))},children:[t,n&&W.jsxs(W.Fragment,{children:[Y.show&&W.jsx("div",{style:{position:"absolute",left:Y.x,top:Y.y,color:"red",mixBlendMode:"difference",pointerEvents:"none",fontSize:12,fontFamily:"sans-serif",whiteSpace:"nowrap",zIndex:kc.dimensionOverlay},children:Y.distance.toFixed(2)}),W.jsx("div",{style:{position:"absolute",left:L.left,width:L.width,textAlign:"center",top:N.y+2,color:"red",mixBlendMode:"difference",pointerEvents:"none",marginTop:L.flipY?0:-20,fontSize:12,fontFamily:"sans-serif",zIndex:kc.dimensionOverlay},children:Math.abs(C.x-h.x).toFixed(2)}),W.jsx("div",{style:{position:"absolute",left:F.x,height:L.height,display:"flex",flexDirection:"column",justifyContent:"center",top:L.top,color:"red",pointerEvents:"none",mixBlendMode:"difference",fontSize:12,fontFamily:"sans-serif",zIndex:kc.dimensionOverlay},children:W.jsx("div",{style:{marginLeft:L.flipX?"-100%":4,paddingRight:4},children:Math.abs(C.y-h.y).toFixed(2)})}),W.jsxs("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none",mixBlendMode:"difference",zIndex:kc.dimensionOverlay},width:y.width,height:y.height,children:[W.jsx("defs",{children:W.jsx("marker",{id:"head",orient:"auto",markerWidth:"3",markerHeight:"4",refX:"2",refY:"2",children:W.jsx("path",{d:"M0,0 V4 L2,2 Z",fill:"red"})})}),W.jsx("line",{x1:N.x,y1:N.y,x2:F.x,y2:F.y,markerEnd:"url(#head)",strokeWidth:1.5,fill:"none",stroke:"red"}),W.jsx("line",{x1:N.x,y1:N.y,x2:F.x,y2:N.y,strokeWidth:1.5,fill:"none",strokeDasharray:"2,2",stroke:"red"}),W.jsx("line",{x1:F.x,y1:N.y,x2:F.x,y2:F.y,strokeWidth:1.5,fill:"none",strokeDasharray:"2,2",stroke:"red"})]}),s&&_.map(J=>{const O=J.id===c.start||J.id===c.end,Z=UM/2;return W.jsxs("svg",{width:UM,height:UM,style:{position:"absolute",left:J.screenPoint.x-Z,top:J.screenPoint.y-Z,pointerEvents:"none",zIndex:kc.dimensionOverlay},children:[W.jsx("line",{x1:0,y1:0,x2:UM,y2:UM,stroke:O?"#66ccff":"white",strokeWidth:1}),W.jsx("line",{x1:UM,y1:0,x2:0,y2:UM,stroke:O?"#66ccff":"white",strokeWidth:1})]},J.id)}),W.jsxs("div",{style:{right:0,bottom:0,position:"absolute",color:"red",fontFamily:"sans-serif",fontSize:12,margin:4},children:["(",C.x.toFixed(2),",",C.y.toFixed(2),")",W.jsx("br",{}),"(",h.x.toFixed(2),",",h.y.toFixed(2),")",W.jsx("br",{}),"dist:"," ",Math.sqrt((h.x-C.x)**2+(h.y-C.y)**2).toFixed(2)]})]})]})},uti=(t,A,e=0)=>{const i=t.width/2,n=t.height/2,o=t.center.x-i-e,s=t.center.x+i+e,r=t.center.y-n-e,a=t.center.y+n+e;return A.x>o&&A.x<s&&A.y>r&&A.y<a},dti=({children:t,disabled:A,transform:e,soup:i,cancelPanDrag:n,onCreateEditEvent:o,onModifyEditEvent:s})=>{e||(e=xa());const r=V.useRef(null),[a,g]=V.useState(null),[c,I]=V.useState(null),l=a!==null;gl(h=>h.in_edit_mode);const B=gl(h=>h.in_move_footprint_mode),C=gl(h=>h.setIsMovingComponent),Q=A||!B;return W.jsxs("div",{ref:r,style:{position:"relative",overflow:"hidden"},onMouseDown:h=>{if(Q)return;const E=h.currentTarget.getBoundingClientRect(),u=h.clientX-E.left,d=h.clientY-E.top;if(Number.isNaN(u)||Number.isNaN(d))return;const f=Ce(tm(e),{x:u,y:d});let y=!1;for(const w of i)if(w.type==="pcb_component"&&uti(w,f,10/e.a)){n(),g(w.pcb_component_id),y=!0;const D=Math.random().toString();I({dragStart:f,originalCenter:w.center,dragEnd:f,edit_event_id:D}),o({edit_event_id:D,edit_event_type:"edit_pcb_component_location",pcb_edit_event_type:"edit_component_location",pcb_component_id:w.pcb_component_id,original_center:w.center,new_center:w.center,in_progress:!0,created_at:Date.now()}),C(!0);break}if(y||g(null),y)return h.preventDefault(),!1},onMouseMove:h=>{if(!a||!c)return;const E=h.currentTarget.getBoundingClientRect(),u=h.clientX-E.left,d=h.clientY-E.top;if(Number.isNaN(u)||Number.isNaN(d))return;const f=Ce(tm(e),{x:u,y:d});I({...c,dragEnd:f}),s({edit_event_id:c.edit_event_id,new_center:{x:c.originalCenter.x+f.x-c.dragStart.x,y:c.originalCenter.y+f.y-c.dragStart.y}})},onMouseUp:h=>{a&&(g(null),C(!1),c&&(s({edit_event_id:c.edit_event_id,in_progress:!1}),I(null)))},children:[t,!Q&&i.filter(h=>h.type==="pcb_component").map(h=>{if(!h?.center)return null;const E=Ce(e,h.center);return W.jsx("div",{style:{position:"absolute",pointerEvents:"none",left:E.x,top:E.y,width:h.width*e.a+20,height:h.height*e.a+20,transform:"translate(-50%, -50%)",background:l&&a===h.pcb_component_id?"rgba(255, 0, 0, 0.2)":""}},h.pcb_component_id)})]})},pti=({hotkeys:t})=>(V.useEffect(()=>{const A=e=>{t.forEach(i=>{e.key===i.key&&i.onUse()})};return window.addEventListener("keydown",A),()=>{window.removeEventListener("keydown",A)}},[t]),W.jsx("div",{className:D2`
5436
+ $1`).replace(/>(\s*)(?=<!--\s*\/)/g,"> ")}}});function Nhe(t,A,e){if(!A||!e)return;let i=t.get(A);i||(i=new Set,t.set(A,i)),i.add(e);let n=t.get(e);n||(n=new Set,t.set(e,n)),n.add(A)}function bAi(t,A){if(!A.subcircuit_id&&!A.source_group_id)return[...t];let e=A;if(A.subcircuit_id){const r=new Set([A.subcircuit_id]),a=new Map,g=new Map;for(const I of t)if(I.type==="source_group"){const l=I.source_group_id,B=I.subcircuit_id;B&&g.set(l,B);const C=I.parent_source_group_id;C&&(a.has(C)||a.set(C,[]),a.get(C).push(l))}let c;for(const[I,l]of g)if(l===A.subcircuit_id){c=I;break}if(c){const I=l=>{const B=a.get(l)||[];for(const C of B){const Q=g.get(C);Q&&r.add(Q),I(C)}};I(c),e={...A,subcircuit_ids:Array.from(r)}}}const i=new Map;for(const r of t){const a=`${r.type}_id`,g=r[a];typeof g=="string"&&i.set(g,r)}const n=new Map;for(const r of t){const a=Object.entries(r);for(const[g,c]of a)if(g!=="parent_source_group_id"){if(g.endsWith("_id")&&typeof c=="string"){const I=i.get(c);Nhe(n,r,I)}else if(g.endsWith("_ids")&&Array.isArray(c)){for(const I of c)if(typeof I=="string"){const l=i.get(I);Nhe(n,r,l)}}}}const o=[],s=new Set;for(const r of t){let a=!1;(e.subcircuit_id&&"subcircuit_id"in r&&r.subcircuit_id===e.subcircuit_id||e.subcircuit_ids&&"subcircuit_id"in r&&r.subcircuit_id&&e.subcircuit_ids.includes(r.subcircuit_id)||e.source_group_id&&"source_group_id"in r&&r.source_group_id===e.source_group_id||e.source_group_id&&"member_source_group_ids"in r&&Array.isArray(r.member_source_group_ids)&&r.member_source_group_ids.includes(e.source_group_id))&&(a=!0),a&&(o.push(r),s.add(r))}for(;o.length>0;){const r=o.shift(),a=n.get(r);if(a)for(const g of a)s.has(g)||(s.add(g),o.push(g))}return t.filter(r=>s.has(r))}var _z=(t,A={})=>{const e=t;let i=e._internal_store;if(!i){i={counts:{},editCount:0},e._internal_store=i;for(const o of e){const s=o.type,r=o[`${s}_id`];if(!r)continue;const a=Number.parseInt(r.split("_").pop());Number.isNaN(a)||(i.counts[s]=Math.max(i.counts[s]??0,a))}}const n=new Proxy({},{get:(o,s)=>{if(s==="toArray")return()=>(e.editCount=i.editCount,e);if(s==="editCount")return i.editCount;if(s==="subtree")return a=>_z(bAi(e,a),A);if(s==="insert")return a=>{const g=a.type;if(!g)throw new Error("insert requires an element with a type");i.counts[g]??=-1,i.counts[g]++;const c=i.counts[g],I={...a,type:g,[`${g}_id`]:`${g}_${c}`};return A.validateInserts&&(JyA[g]??tz).parse(I),e.push(I),i.editCount++,I};if(s==="insertAll")return a=>a.map(g=>n.insert(g));const r=s;return{get:a=>e.find(g=>g.type===r&&g[`${r}_id`]===a),getUsing:a=>{const g=Object.keys(a);if(g.length!==1)throw new Error("getUsing requires exactly one key, e.g. { pcb_component_id }");const c=g[0],I=c.replace("_id",""),l=e.find(B=>B.type===I&&B[c]===a[c]);return l?e.find(B=>B.type===r&&B[`${r}_id`]===l[`${r}_id`]):null},getWhere:a=>{const g=Object.keys(a);return e.find(c=>c.type===r&&g.every(I=>c[I]===a[I]))},list:a=>{const g=a?Object.keys(a):[];return e.filter(c=>c.type===r&&g.every(I=>c[I]===a[I]))},insert:a=>{i.counts[r]??=-1,i.counts[r]++;const g=i.counts[r],c={type:r,[`${r}_id`]:`${r}_${g}`,...a};return A.validateInserts&&(JyA[r]??tz).parse(c),e.push(c),i.editCount++,c},delete:a=>{const g=e.find(c=>c[`${r}_id`]===a);g&&(e.splice(e.indexOf(g),1),i.editCount++)},update:(a,g)=>{const c=e.find(I=>I.type===r&&I[`${r}_id`]===a);return c?(Object.assign(c,g),i.editCount++,c):null},select:a=>{if(r==="source_component")return e.find(g=>g.type==="source_component"&&g.name===a.replace(/\./g,""));if(r==="pcb_port"||r==="source_port"||r==="schematic_port"){const[g,c]=a.replace(/\./g,"").split(/[\s\>]+/),I=e.find(B=>B.type==="source_component"&&B.name===g);if(!I)return null;const l=e.find(B=>B.type==="source_port"&&B.source_component_id===I.source_component_id&&(B.name===c||(B.port_hints??[]).includes(c)));if(!l)return null;if(r==="source_port")return l;if(r==="pcb_port")return e.find(B=>B.type==="pcb_port"&&B.source_port_id===l.source_port_id);if(r==="schematic_port")return e.find(B=>B.type==="schematic_port"&&B.source_port_id===l.source_port_id)}}}}});return n};_z.unparsed=_z;var rx=_z;function dmA(t){const A=t.type;return`${A}:${t[`${A}_id`]}`}var Ghe=(t,A={})=>{let e=t._internal_store_indexed;if(!e){e={counts:{},editCount:0,indexes:{}};for(const s of t){const r=s.type,a=s[`${r}_id`];if(!a)continue;const g=Number.parseInt(a.split("_").pop()||"");Number.isNaN(g)||(e.counts[r]=Math.max(e.counts[r]??0,g))}const n=A.indexConfig||{},o=e.indexes;if(n.byId&&(o.byId=new Map),n.byType&&(o.byType=new Map),n.byRelation&&(o.byRelation=new Map),n.bySubcircuit&&(o.bySubcircuit=new Map),n.byCustomField&&n.byCustomField.length>0){o.byCustomField=new Map;for(const s of n.byCustomField)o.byCustomField.set(s,new Map)}for(const s of t){if(n.byId){const r=dmA(s);o.byId.set(r,s)}if(n.byType){const r=o.byType.get(s.type)||[];r.push(s),o.byType.set(s.type,r)}if(n.byRelation){const r=Object.entries(s);for(const[a,g]of r)if(a.endsWith("_id")&&a!==`${s.type}_id`&&typeof g=="string"){const c=o.byRelation.get(a)||new Map,I=c.get(g)||[];I.push(s),c.set(g,I),o.byRelation.set(a,c)}}if(n.bySubcircuit&&"subcircuit_id"in s){const r=s.subcircuit_id;if(r&&typeof r=="string"){const a=o.bySubcircuit.get(r)||[];a.push(s),o.bySubcircuit.set(r,a)}}if(n.byCustomField&&o.byCustomField){for(const r of n.byCustomField)if(r in s){const a=s[r];if(a!==void 0&&(typeof a=="string"||typeof a=="number")){const g=String(a),c=o.byCustomField.get(r),I=c.get(g)||[];I.push(s),c.set(g,I)}}}}t._internal_store_indexed=e}return new Proxy({},{get:(n,o)=>{if(o==="toArray")return()=>(t.editCount=e.editCount,t);if(o==="editCount")return e.editCount;const s=o;return{get:r=>{const a=A.indexConfig||{};return a.byId&&e.indexes.byId?e.indexes.byId.get(`${s}:${r}`)||null:a.byType&&e.indexes.byType?(e.indexes.byType.get(s)||[]).find(c=>c[`${s}_id`]===r)||null:t.find(g=>g.type===s&&g[`${s}_id`]===r)||null},getUsing:r=>{const a=A.indexConfig||{},g=Object.keys(r);if(g.length!==1)throw new Error("getUsing requires exactly one key, e.g. { pcb_component_id }");const c=g[0],I=c.replace("_id","");if(a.byRelation&&e.indexes.byRelation){const B=e.indexes.byRelation.get(c);if(B){const Q=(B.get(r[c])||[]).find(E=>E.type===I);if(!Q)return null;const h=Q[`${s}_id`];return a.byId&&e.indexes.byId?e.indexes.byId.get(`${s}:${h}`)||null:a.byType&&e.indexes.byType?(e.indexes.byType.get(s)||[]).find(u=>u[`${s}_id`]===h)||null:t.find(E=>E.type===s&&E[`${s}_id`]===h)||null}}const l=t.find(B=>B.type===I&&B[c]===r[c]);return l&&t.find(B=>B.type===s&&B[`${s}_id`]===l[`${s}_id`])||null},getWhere:r=>{const a=A.indexConfig||{},g=Object.keys(r);if(g.length===1&&a.byCustomField&&e.indexes.byCustomField){const c=g[0],I=e.indexes.byCustomField.get(c);if(I){const l=String(r[c]);return(I.get(l)||[]).find(C=>C.type===s)||null}}if("subcircuit_id"in r&&a.bySubcircuit&&e.indexes.bySubcircuit){const c=r.subcircuit_id;return(e.indexes.bySubcircuit.get(c)||[]).find(l=>l.type===s&&g.every(B=>l[B]===r[B]))||null}return a.byType&&e.indexes.byType?(e.indexes.byType.get(s)||[]).find(I=>g.every(l=>I[l]===r[l]))||null:t.find(c=>c.type===s&&g.every(I=>c[I]===r[I]))||null},list:r=>{const a=A.indexConfig||{},g=r?Object.keys(r):[];if(g.length===0&&a.byType&&e.indexes.byType)return e.indexes.byType.get(s)||[];if(g.length===1&&g[0]==="subcircuit_id"&&a.bySubcircuit&&e.indexes.bySubcircuit){const I=r.subcircuit_id;return(e.indexes.bySubcircuit.get(I)||[]).filter(B=>B.type===s)}let c;return a.byType&&e.indexes.byType?c=e.indexes.byType.get(s)||[]:c=t.filter(I=>I.type===s),g.length>0?c.filter(I=>g.every(l=>I[l]===r[l])):c},insert:r=>{e.counts[s]??=-1,e.counts[s]++;const a=e.counts[s],g={type:s,[`${s}_id`]:`${s}_${a}`,...r};A.validateInserts&&(JyA[s]??tz).parse(g),t.push(g),e.editCount++;const c=A.indexConfig||{};if(c.byId&&e.indexes.byId){const I=dmA(g);e.indexes.byId.set(I,g)}if(c.byType&&e.indexes.byType){const I=e.indexes.byType.get(s)||[];I.push(g),e.indexes.byType.set(s,I)}if(c.byRelation&&e.indexes.byRelation){const I=Object.entries(g);for(const[l,B]of I)if(l.endsWith("_id")&&l!==`${g.type}_id`&&typeof B=="string"){const C=e.indexes.byRelation.get(l)||new Map,Q=C.get(B)||[];Q.push(g),C.set(B,Q),e.indexes.byRelation.set(l,C)}}if(c.bySubcircuit&&e.indexes.bySubcircuit&&"subcircuit_id"in g){const I=g.subcircuit_id;if(I&&typeof I=="string"){const l=e.indexes.bySubcircuit.get(I)||[];l.push(g),e.indexes.bySubcircuit.set(I,l)}}if(c.byCustomField&&e.indexes.byCustomField){for(const I of c.byCustomField)if(I in g){const l=g[I];if(l!==void 0&&(typeof l=="string"||typeof l=="number")){const B=String(l),C=e.indexes.byCustomField.get(I),Q=C.get(B)||[];Q.push(g),C.set(B,Q)}}}return g},delete:r=>{const a=A.indexConfig||{};let g;if(a.byId&&e.indexes.byId?g=e.indexes.byId.get(`${s}:${r}`):a.byType&&e.indexes.byType?g=(e.indexes.byType.get(s)||[]).find(l=>l[`${s}_id`]===r):g=t.find(I=>I[`${s}_id`]===r),!g)return;const c=t.indexOf(g);if(c>=0&&(t.splice(c,1),e.editCount++),a.byId&&e.indexes.byId){const I=dmA(g);e.indexes.byId.delete(I)}if(a.byType&&e.indexes.byType){const l=(e.indexes.byType.get(s)||[]).filter(B=>B[`${s}_id`]!==r);e.indexes.byType.set(s,l)}if(a.byRelation&&e.indexes.byRelation)for(const[I,l]of e.indexes.byRelation.entries())for(const[B,C]of l.entries()){const Q=C.filter(h=>h!==g);Q.length===0?l.delete(B):l.set(B,Q)}if(a.bySubcircuit&&e.indexes.bySubcircuit&&"subcircuit_id"in g){const I=g.subcircuit_id;if(I){const B=(e.indexes.bySubcircuit.get(I)||[]).filter(C=>C!==g);B.length===0?e.indexes.bySubcircuit.delete(I):e.indexes.bySubcircuit.set(I,B)}}if(a.byCustomField&&e.indexes.byCustomField)for(const I of e.indexes.byCustomField.values())for(const[l,B]of I.entries()){const C=B.filter(Q=>Q!==g);C.length===0?I.delete(l):I.set(l,C)}},update:(r,a)=>{const g=A.indexConfig||{};let c;if(g.byId&&e.indexes.byId?c=e.indexes.byId.get(`${s}:${r}`):g.byType&&e.indexes.byType?c=(e.indexes.byType.get(s)||[]).find(l=>l[`${s}_id`]===r):c=t.find(I=>I.type===s&&I[`${s}_id`]===r),!c)return null;if(g.byRelation&&e.indexes.byRelation){const I=Object.entries(c);for(const[l,B]of I)if(l.endsWith("_id")&&l!==`${c.type}_id`&&typeof B=="string"&&l in a&&a[l]!==B){const C=e.indexes.byRelation.get(l);if(C){const h=(C.get(B)||[]).filter(E=>E!==c);h.length===0?C.delete(B):C.set(B,h)}}}if(g.bySubcircuit&&e.indexes.bySubcircuit&&"subcircuit_id"in c&&"subcircuit_id"in a){const I=c.subcircuit_id,l=a.subcircuit_id;if(I!==l){const C=(e.indexes.bySubcircuit.get(I)||[]).filter(Q=>Q!==c);C.length===0?e.indexes.bySubcircuit.delete(I):e.indexes.bySubcircuit.set(I,C)}}if(g.byCustomField&&e.indexes.byCustomField){for(const I of g.byCustomField)if(I in c&&I in a&&c[I]!==a[I]){const l=e.indexes.byCustomField.get(I);if(l){const B=String(c[I]),Q=(l.get(B)||[]).filter(h=>h!==c);Q.length===0?l.delete(B):l.set(B,Q)}}}if(Object.assign(c,a),e.editCount++,g.byRelation&&e.indexes.byRelation){const I=Object.entries(c);for(const[l,B]of I)if(l.endsWith("_id")&&l!==`${c.type}_id`&&typeof B=="string"&&l in a){const C=e.indexes.byRelation.get(l)||new Map,Q=C.get(B)||[];Q.includes(c)||(Q.push(c),C.set(B,Q),e.indexes.byRelation.set(l,C))}}if(g.bySubcircuit&&e.indexes.bySubcircuit&&"subcircuit_id"in c&&"subcircuit_id"in a){const I=c.subcircuit_id;if(I&&typeof I=="string"){const l=e.indexes.bySubcircuit.get(I)||[];l.includes(c)||(l.push(c),e.indexes.bySubcircuit.set(I,l))}}if(g.byCustomField&&e.indexes.byCustomField){for(const I of g.byCustomField)if(I in c&&I in a){const l=c[I];if(l!==void 0&&(typeof l=="string"||typeof l=="number")){const B=String(l),C=e.indexes.byCustomField.get(I),Q=C.get(B)||[];Q.includes(c)||(Q.push(c),C.set(B,Q))}}}return c},select:r=>{if(s==="source_component")return t.find(a=>a.type==="source_component"&&a.name===r.replace(/\./g,""))||null;if(s==="pcb_port"||s==="source_port"||s==="schematic_port"){const[a,g]=r.replace(/\./g,"").split(/[\s\>]+/),c=t.find(l=>l.type==="source_component"&&l.name===a);if(!c)return null;const I=t.find(l=>l.type==="source_port"&&l.source_component_id===c.source_component_id&&(l.name===g||(l.port_hints??[]).includes(g)));if(!I)return null;if(s==="source_port")return I;if(s==="pcb_port")return t.find(l=>l.type==="pcb_port"&&l.source_port_id===I.source_port_id)||null;if(s==="schematic_port")return t.find(l=>l.type==="schematic_port"&&l.source_port_id===I.source_port_id)||null}return null}}}})};Ghe.unparsed=Ghe;var xAi=t=>{const A=t.type;return t[`${A}_id`]},Lhe=(t,A)=>({minX:Math.min(t.minX,A.minX),minY:Math.min(t.minY,A.minY),maxX:Math.max(t.maxX,A.maxX),maxY:Math.max(t.maxY,A.maxY)}),kz=(t,A,e)=>{const i=e/2;return{minX:t-i,minY:A-i,maxX:t+i,maxY:A+i}},_Ai=(t,A,e,i,n)=>{const o=e/2,s=i/2,r=n*Math.PI/180,a=Math.cos(r),g=Math.sin(r),c=[{x:-o,y:-s},{x:o,y:-s},{x:o,y:s},{x:-o,y:s}].map(I=>({x:t+I.x*a-I.y*g,y:A+I.x*g+I.y*a}));return{minX:Math.min(...c.map(I=>I.x)),minY:Math.min(...c.map(I=>I.y)),maxX:Math.max(...c.map(I=>I.x)),maxY:Math.max(...c.map(I=>I.y))}},pmA=t=>{let A=Number.POSITIVE_INFINITY,e=Number.POSITIVE_INFINITY,i=Number.NEGATIVE_INFINITY,n=Number.NEGATIVE_INFINITY;for(const o of t){if(!o.type.startsWith("pcb_"))continue;if(o.type==="pcb_smtpad"&&o.shape==="polygon"&&Array.isArray(o.points)){for(const c of o.points)A=Math.min(A,c.x),e=Math.min(e,c.y),i=Math.max(i,c.x),n=Math.max(n,c.y);continue}if(o.type==="pcb_hole"&&o.hole_shape==="circle"){const c=kz(o.x,o.y,o.hole_diameter);A=Math.min(A,c.minX),e=Math.min(e,c.minY),i=Math.max(i,c.maxX),n=Math.max(n,c.maxY);continue}if(o.type==="pcb_plated_hole"){let c;if("outer_diameter"in o&&typeof o.outer_diameter=="number"?c=kz(o.x,o.y,o.outer_diameter):"hole_diameter"in o&&typeof o.hole_diameter=="number"&&(c=kz(o.x,o.y,o.hole_diameter)),"rect_pad_width"in o&&typeof o.rect_pad_width=="number"&&"rect_pad_height"in o&&typeof o.rect_pad_height=="number"){const I=_Ai(o.x,o.y,o.rect_pad_width,o.rect_pad_height,"rect_ccw_rotation"in o?o.rect_ccw_rotation??0:0);c=c?Lhe(c,I):I}if("hole_diameter"in o&&typeof o.hole_diameter=="number"){const I=kz(o.x+("hole_offset_x"in o?o.hole_offset_x??0:0),o.y+("hole_offset_y"in o?o.hole_offset_y??0:0),o.hole_diameter);c=c?Lhe(c,I):I}if(c){A=Math.min(A,c.minX),e=Math.min(e,c.minY),i=Math.max(i,c.maxX),n=Math.max(n,c.maxY);continue}}let s,r,a,g;if("x"in o&&"y"in o&&(s=Number(o.x),r=Number(o.y)),"outer_diameter"in o&&(a=Number(o.outer_diameter),g=Number(o.outer_diameter)),"width"in o&&(a=Number(o.width)),"height"in o&&(g=Number(o.height)),"center"in o&&(s=o.center.x,r=o.center.y),s!==void 0&&r!==void 0)A=Math.min(A,s),e=Math.min(e,r),i=Math.max(i,s),n=Math.max(n,r),a!==void 0&&g!==void 0&&(A=Math.min(A,s-a/2),e=Math.min(e,r-g/2),i=Math.max(i,s+a/2),n=Math.max(n,r+g/2)),"radius"in o&&(A=Math.min(A,s-o.radius),e=Math.min(e,r-o.radius),i=Math.max(i,s+o.radius),n=Math.max(n,r+o.radius));else if(o.type==="pcb_trace")for(const c of o.route)A=Math.min(A,c.x),e=Math.min(e,c.y),i=Math.max(i,c.x),n=Math.max(n,c.y);else if(o.type==="pcb_courtyard_outline")for(const c of o.outline)A=Math.min(A,c.x),e=Math.min(e,c.y),i=Math.max(i,c.x),n=Math.max(n,c.y);else if(o.type==="pcb_courtyard_polygon")for(const c of o.points)A=Math.min(A,c.x),e=Math.min(e,c.y),i=Math.max(i,c.x),n=Math.max(n,c.y)}return{minX:A,minY:e,maxX:i,maxY:n}};function kAi(t){let A=0;if(t.length==0)return A;for(var e=0;e<t.length;e++){var i=t.charCodeAt(e);A=(A<<5)-A+i,A=A&A}return Math.abs(A)}var Uhe=[["#69d2e7","#a7dbd8","#e0e4cc","#f38630","#fa6900"],["#fe4365","#fc9d9a","#f9cdad","#c8c8a9","#83af9b"],["#ecd078","#d95b43","#c02942","#542437","#53777a"],["#556270","#4ecdc4","#c7f464","#ff6b6b","#c44d58"],["#774f38","#e08e79","#f1d4af","#ece5ce","#c5e0dc"],["#e8ddcb","#cdb380","#036564","#033649","#031634"],["#490a3d","#bd1550","#e97f02","#f8ca00","#8a9b0f"],["#594f4f","#547980","#45ada8","#9de0ad","#e5fcc2"],["#00a0b0","#6a4a3c","#cc333f","#eb6841","#edc951"],["#e94e77","#d68189","#c6a49a","#c6e5d9","#f4ead5"],["#3fb8af","#7fc7af","#dad8a7","#ff9e9d","#ff3d7f"],["#d9ceb2","#948c75","#d5ded9","#7a6a53","#99b2b7"],["#ffffff","#cbe86b","#f2e9e1","#1c140d","#cbe86b"],["#efffcd","#dce9be","#555152","#2e2633","#99173c"],["#343838","#005f6b","#008c9e","#00b4cc","#00dffc"],["#413e4a","#73626e","#b38184","#f0b49e","#f7e4be"],["#ff4e50","#fc913a","#f9d423","#ede574","#e1f5c4"],["#99b898","#fecea8","#ff847c","#e84a5f","#2a363b"],["#655643","#80bca3","#f6f7bd","#e6ac27","#bf4d28"],["#00a8c6","#40c0cb","#f9f2e7","#aee239","#8fbe00"],["#351330","#424254","#64908a","#e8caa4","#cc2a41"],["#554236","#f77825","#d3ce3d","#f1efa5","#60b99a"],["#5d4157","#838689","#a8caba","#cad7b2","#ebe3aa"],["#8c2318","#5e8c6a","#88a65e","#bfb35a","#f2c45a"],["#fad089","#ff9c5b","#f5634a","#ed303c","#3b8183"],["#ff4242","#f4fad2","#d4ee5e","#e1edb9","#f0f2eb"],["#f8b195","#f67280","#c06c84","#6c5b7b","#355c7d"],["#d1e751","#ffffff","#000000","#4dbce9","#26ade4"],["#1b676b","#519548","#88c425","#bef202","#eafde6"],["#5e412f","#fcebb6","#78c0a8","#f07818","#f0a830"],["#bcbdac","#cfbe27","#f27435","#f02475","#3b2d38"],["#452632","#91204d","#e4844a","#e8bf56","#e2f7ce"],["#eee6ab","#c5bc8e","#696758","#45484b","#36393b"],["#f0d8a8","#3d1c00","#86b8b1","#f2d694","#fa2a00"],["#2a044a","#0b2e59","#0d6759","#7ab317","#a0c55f"],["#f04155","#ff823a","#f2f26f","#fff7bd","#95cfb7"],["#b9d7d9","#668284","#2a2829","#493736","#7b3b3b"],["#bbbb88","#ccc68d","#eedd99","#eec290","#eeaa88"],["#b3cc57","#ecf081","#ffbe40","#ef746f","#ab3e5b"],["#a3a948","#edb92e","#f85931","#ce1836","#009989"],["#300030","#480048","#601848","#c04848","#f07241"],["#67917a","#170409","#b8af03","#ccbf82","#e33258"],["#aab3ab","#c4cbb7","#ebefc9","#eee0b7","#e8caaf"],["#e8d5b7","#0e2430","#fc3a51","#f5b349","#e8d5b9"],["#ab526b","#bca297","#c5ceae","#f0e2a4","#f4ebc3"],["#607848","#789048","#c0d860","#f0f0d8","#604848"],["#b6d8c0","#c8d9bf","#dadabd","#ecdbbc","#fedcba"],["#a8e6ce","#dcedc2","#ffd3b5","#ffaaa6","#ff8c94"],["#3e4147","#fffedf","#dfba69","#5a2e2e","#2a2c31"],["#fc354c","#29221f","#13747d","#0abfbc","#fcf7c5"],["#cc0c39","#e6781e","#c8cf02","#f8fcc1","#1693a7"],["#1c2130","#028f76","#b3e099","#ffeaad","#d14334"],["#a7c5bd","#e5ddcb","#eb7b59","#cf4647","#524656"],["#dad6ca","#1bb0ce","#4f8699","#6a5e72","#563444"],["#5c323e","#a82743","#e15e32","#c0d23e","#e5f04c"],["#edebe6","#d6e1c7","#94c7b6","#403b33","#d3643b"],["#fdf1cc","#c6d6b8","#987f69","#e3ad40","#fcd036"],["#230f2b","#f21d41","#ebebbc","#bce3c5","#82b3ae"],["#b9d3b0","#81bda4","#b28774","#f88f79","#f6aa93"],["#3a111c","#574951","#83988e","#bcdea5","#e6f9bc"],["#5e3929","#cd8c52","#b7d1a3","#dee8be","#fcf7d3"],["#1c0113","#6b0103","#a30006","#c21a01","#f03c02"],["#000000","#9f111b","#b11623","#292c37","#cccccc"],["#382f32","#ffeaf2","#fcd9e5","#fbc5d8","#f1396d"],["#e3dfba","#c8d6bf","#93ccc6","#6cbdb5","#1a1f1e"],["#f6f6f6","#e8e8e8","#333333","#990100","#b90504"],["#1b325f","#9cc4e4","#e9f2f9","#3a89c9","#f26c4f"],["#a1dbb2","#fee5ad","#faca66","#f7a541","#f45d4c"],["#c1b398","#605951","#fbeec2","#61a6ab","#accec0"],["#5e9fa3","#dcd1b4","#fab87f","#f87e7b","#b05574"],["#951f2b","#f5f4d7","#e0dfb1","#a5a36c","#535233"],["#8dccad","#988864","#fea6a2","#f9d6ac","#ffe9af"],["#2d2d29","#215a6d","#3ca2a2","#92c7a3","#dfece6"],["#413d3d","#040004","#c8ff00","#fa023c","#4b000f"],["#eff3cd","#b2d5ba","#61ada0","#248f8d","#605063"],["#ffefd3","#fffee4","#d0ecea","#9fd6d2","#8b7a5e"],["#cfffdd","#b4dec1","#5c5863","#a85163","#ff1f4c"],["#9dc9ac","#fffec7","#f56218","#ff9d2e","#919167"],["#4e395d","#827085","#8ebe94","#ccfc8e","#dc5b3e"],["#a8a7a7","#cc527a","#e8175d","#474747","#363636"],["#f8edd1","#d88a8a","#474843","#9d9d93","#c5cfc6"],["#046d8b","#309292","#2fb8ac","#93a42a","#ecbe13"],["#f38a8a","#55443d","#a0cab5","#cde9ca","#f1edd0"],["#a70267","#f10c49","#fb6b41","#f6d86b","#339194"],["#ff003c","#ff8a00","#fabe28","#88c100","#00c176"],["#ffedbf","#f7803c","#f54828","#2e0d23","#f8e4c1"],["#4e4d4a","#353432","#94ba65","#2790b0","#2b4e72"],["#0ca5b0","#4e3f30","#fefeeb","#f8f4e4","#a5b3aa"],["#4d3b3b","#de6262","#ffb88c","#ffd0b3","#f5e0d3"],["#fffbb7","#a6f6af","#66b6ab","#5b7c8d","#4f2958"],["#edf6ee","#d1c089","#b3204d","#412e28","#151101"],["#9d7e79","#ccac95","#9a947c","#748b83","#5b756c"],["#fcfef5","#e9ffe1","#cdcfb7","#d6e6c3","#fafbe3"],["#9cddc8","#bfd8ad","#ddd9ab","#f7af63","#633d2e"],["#30261c","#403831","#36544f","#1f5f61","#0b8185"],["#aaff00","#ffaa00","#ff00aa","#aa00ff","#00aaff"],["#d1313d","#e5625c","#f9bf76","#8eb2c5","#615375"],["#ffe181","#eee9e5","#fad3b2","#ffba7f","#ff9c97"],["#73c8a9","#dee1b6","#e1b866","#bd5532","#373b44"],["#805841","#dcf7f3","#fffcdd","#ffd8d8","#f5a2a2"]],vAi=t=>{let{x:A,y:e,width:i,height:n}={...t,...t.size,...t.center,...t.position};if(t.x1!==void 0&&t.x2!==void 0&&t.y1!==void 0&&t.y2!==void 0&&(A=(t.x1+t.x2)/2,e=(t.y1+t.y2)/2,i=Math.abs(t.x1-t.x2),n=Math.abs(t.y1-t.y2)),t.points&&Array.isArray(t.points)&&t.points.length>0){const r=t.points.map(B=>B.x),a=t.points.map(B=>B.y),g=Math.min(...r),c=Math.max(...r),I=Math.min(...a),l=Math.max(...a);A=(g+c)/2,e=(I+l)/2,i=c-g,n=l-I}const o=t.text||t.name||t.source?.text||t.source?.name||"?",s=t;return A===void 0||e===void 0?null:(i===void 0&&"outer_diameter"in t&&(i=t.outer_diameter,n=t.outer_diameter),(i===void 0||n===void 0)&&(i=.1,n=.1),{x:A,y:e,width:i,height:n,title:o,content:s,bg_color:Uhe[kAi(t.type||o)%Uhe.length]?.[4]??"#f00"})},FAi=t=>!!t,MAi=t=>{const A=t.filter(g=>g.type.startsWith("pcb_")||g.type.startsWith("schematic_")).concat(t.filter(g=>g.type==="pcb_trace"||g.type==="schematic_trace").flatMap(g=>g.route)).map(g=>vAi(g)).filter(FAi);if(A.length===0)return{center:{x:0,y:0},width:0,height:0};let e=A[0].x-A[0].width/2,i=A[0].x+A[0].width/2,n=A[0].y-A[0].height/2,o=A[0].y+A[0].height/2;for(const g of A.slice(1))e=Math.min(e,g.x-g.width/2),i=Math.max(i,g.x+g.width/2),n=Math.min(n,g.y-g.height/2),o=Math.max(o,g.y+g.height/2);const s=i-e,r=o-n;return{center:{x:e+s/2,y:n+r/2},width:s,height:r}},Cd={IS_SHOWING_PCB_GROUPS:"pcb_viewer_is_showing_pcb_groups",PCB_GROUP_VIEW_MODE:"pcb_viewer_group_view_mode",IS_SHOWING_COPPER_POURS:"pcb_viewer_is_showing_copper_pours",IS_SHOWING_COURTYARDS:"pcb_viewer_is_showing_courtyards",IS_SHOWING_GROUP_ANCHOR_OFFSETS:"pcb_viewer_is_showing_group_anchor_offsets",IS_SHOWING_SOLDER_MASK:"pcb_viewer_is_showing_solder_mask",IS_SHOWING_FABRICATION_NOTES:"pcb_viewer_is_showing_fabrication_notes",IS_SHOWING_SILKSCREEN:"pcb_viewer_is_showing_silkscreen"},GM=(t,A)=>{if(typeof window>"u")return A;try{const e=localStorage.getItem(t);return e!==null?JSON.parse(e):A}catch{return A}},LM=(t,A)=>{if(!(typeof window>"u"))try{localStorage.setItem(t,JSON.stringify(A))}catch{}},RAi=(t,A)=>{if(typeof window>"u")return A;try{const e=localStorage.getItem(t);return e!==null?JSON.parse(e):A}catch{return A}},NAi=(t,A)=>{if(!(typeof window>"u"))try{localStorage.setItem(t,JSON.stringify(A))}catch{}},GAi="named_only",LAi=(t={},A=!1)=>y4A(e=>({selected_layer:"top",pcb_viewer_id:`pcb_viewer_${Math.random().toString().slice(2,10)}`,in_edit_mode:!1,in_move_footprint_mode:!1,in_draw_trace_mode:!1,is_moving_component:!1,is_drawing_trace:!1,is_mouse_over_container:!1,is_showing_multiple_traces_length:!1,is_showing_rats_nest:!1,is_showing_autorouting:!0,is_showing_drc_errors:!0,is_showing_copper_pours:GM(Cd.IS_SHOWING_COPPER_POURS,!0),is_showing_courtyards:GM(Cd.IS_SHOWING_COURTYARDS,!0),is_showing_pcb_groups:A?!1:GM(Cd.IS_SHOWING_PCB_GROUPS,!0),is_showing_group_anchor_offsets:GM(Cd.IS_SHOWING_GROUP_ANCHOR_OFFSETS,!1),is_showing_solder_mask:GM(Cd.IS_SHOWING_SOLDER_MASK,!1),is_showing_silkscreen:GM(Cd.IS_SHOWING_SILKSCREEN,!0),is_showing_fabrication_notes:GM(Cd.IS_SHOWING_FABRICATION_NOTES,!1),pcb_group_view_mode:A?"all":RAi(Cd.PCB_GROUP_VIEW_MODE,GAi),hovered_error_id:null,...t,selectLayer:i=>e({selected_layer:i}),setEditMode:i=>e({in_edit_mode:i!=="off",in_move_footprint_mode:i==="move_footprint",in_draw_trace_mode:i==="draw_trace",is_moving_component:!1,is_drawing_trace:!1}),setIsShowingRatsNest:i=>e({is_showing_rats_nest:i}),setIsMovingComponent:i=>e({is_moving_component:i}),setIsDrawingTrace:i=>e({is_drawing_trace:i}),setIsMouseOverContainer:i=>e({is_mouse_over_container:i}),setIsShowingMultipleTracesLength:i=>e({is_showing_multiple_traces_length:i}),setIsShowingAutorouting:i=>e({is_showing_autorouting:i}),setIsShowingDrcErrors:i=>e({is_showing_drc_errors:i}),setIsShowingCopperPours:i=>{LM(Cd.IS_SHOWING_COPPER_POURS,i),e({is_showing_copper_pours:i})},setIsShowingCourtyards:i=>{LM(Cd.IS_SHOWING_COURTYARDS,i),e({is_showing_courtyards:i})},setIsShowingPcbGroups:i=>{A||(LM(Cd.IS_SHOWING_PCB_GROUPS,i),e({is_showing_pcb_groups:i}))},setIsShowingGroupAnchorOffsets:i=>{LM(Cd.IS_SHOWING_GROUP_ANCHOR_OFFSETS,i),e({is_showing_group_anchor_offsets:i})},setIsShowingSolderMask:i=>{LM(Cd.IS_SHOWING_SOLDER_MASK,i),e({is_showing_solder_mask:i})},setIsShowingSilkscreen:i=>{LM(Cd.IS_SHOWING_SILKSCREEN,i),e({is_showing_silkscreen:i})},setIsShowingFabricationNotes:i=>{LM(Cd.IS_SHOWING_FABRICATION_NOTES,i),e({is_showing_fabrication_notes:i})},setPcbGroupViewMode:i=>{A||(NAi(Cd.PCB_GROUP_VIEW_MODE,i),e({pcb_group_view_mode:i}))},setHoveredErrorId:i=>e({hovered_error_id:i})})),gl=t=>{const A=V.useContext(Hhe);return F4A(A,t)},Hhe=V.createContext(null),UAi=({children:t,initialState:A,disablePcbGroups:e})=>{const i=V.useMemo(()=>LAi(A,e),[e]);return W.jsx(Hhe.Provider,{value:i,children:t})},HAi=()=>{const t=gl(e=>e.pcb_viewer_id),A=(e,i)=>sc(e,{containerId:t,...i});return A.error=(e,i)=>sc.error(e,{containerId:t,...i}),A.promise=sc.promise,A},YAi=()=>{V.useEffect(()=>{M6t()},[]);const t=gl(A=>A.pcb_viewer_id);return W.jsx(F6t,{position:"top-center",containerId:t})};function JAi(){var t=V.useRef(!1),A=V.useCallback(function(){return t.current},[]);return V.useEffect(function(){return t.current=!0,function(){t.current=!1}},[]),A}var TAi=function(t){t===void 0&&(t={});var A=V.useState(t),e=A[0],i=A[1],n=V.useCallback(function(o){i(function(s){return Object.assign({},s,o instanceof Function?o(s):o)})},[]);return[e,n]},PAi=TAi,KAi=function(){},Yhe=typeof window<"u",qAi=CmA(gAi()),OAi=function(){var t=JAi(),A=PAi({value:void 0,error:void 0,noUserInteraction:!0}),e=A[0],i=A[1],n=V.useCallback(function(o){if(t()){var s,r;try{if(typeof o!="string"&&typeof o!="number"){var a=new Error("Cannot copy typeof "+typeof o+" to clipboard, must be a string");console.error(a),i({value:o,error:a,noUserInteraction:!0});return}else if(o===""){var a=new Error("Cannot copy empty string to clipboard.");console.error(a),i({value:o,error:a,noUserInteraction:!0});return}r=o.toString(),s=(0,qAi.default)(r),i({value:r,error:void 0,noUserInteraction:s})}catch(g){i({value:r,error:g,noUserInteraction:s})}}},[]);return[e,n]},WAi=OAi,ZAi=Yhe?V.useLayoutEffect:V.useEffect,VAi=ZAi,Jhe={x:0,y:0,width:0,height:0,top:0,left:0,bottom:0,right:0};function jAi(){var t=V.useState(null),A=t[0],e=t[1],i=V.useState(Jhe),n=i[0],o=i[1],s=V.useMemo(function(){return new window.ResizeObserver(function(r){if(r[0]){var a=r[0].contentRect,g=a.x,c=a.y,I=a.width,l=a.height,B=a.top,C=a.left,Q=a.bottom,h=a.right;o({x:g,y:c,width:I,height:l,top:B,left:C,bottom:Q,right:h})}})},[]);return VAi(function(){if(A)return s.observe(A),function(){s.disconnect()}},[A]),[e,n]}var qT=Yhe&&typeof window.ResizeObserver<"u"?jAi:function(){return[KAi,Jhe]},The=({initialTransform:t,initialTouch1:A,initialTouch2:e,finalTouch1:i,finalTouch2:n})=>{if(!i||!n)return t;const o={x:(A.x+e.x)/2,y:(A.y+e.y)/2},s={x:(i.x+n.x)/2,y:(i.y+n.y)/2},r=Math.hypot(e.x-A.x,e.y-A.y),a=Math.hypot(n.x-i.x,n.y-i.y),g=r===0?1:a/r,c=s.x-o.x,I=s.y-o.y;return An(on(c,I),on(o.x,o.y),$a(g,g),on(-o.x,-o.y),t)},zAi=(t={})=>{const A=V.useRef(null),[e,i]=V.useState(0),n=t.canvasElm??A.current,[o,s]=V.useState(t.initialTransform??xa()),[r,a]=V.useState(0),[g,c]=V.useReducer(d=>d+1,0),I=V.useCallback(d=>{t.onSetTransform&&t.onSetTransform(d),t.transform||s(d)},[t.onSetTransform,s]),l=V.useCallback(d=>{I(d),c()},[I]),B=t.transform??o,C=V.useCallback(()=>{i(Date.now())},[]),Q=V.useRef("none"),h=V.useRef(null),E=V.useRef(null);V.useEffect(()=>{const d=t.canvasElm??A.current;if(d&&!n){a(r+1);return}if(!d){const Z=setTimeout(()=>{a(r+1)},100);return()=>clearTimeout(Z)}let f=t.transform??o,y={x:0,y:0},w={x:0,y:0},D=!1;const S=Z=>({x:Z.pageX-d.getBoundingClientRect().left-window.scrollX,y:Z.pageY-d.getBoundingClientRect().top-window.scrollY});function _(Z){t.enabled!==!1&&(t.shouldDrag&&!t.shouldDrag(Z)||(y=S(Z),!(Date.now()-e<100)&&(D=!0,Z.preventDefault())))}function b(Z){if(!D||t.enabled===!1||t.shouldDrag&&!t.shouldDrag(Z))return;w=S(Z);const X=An(on(w.x-y.x,w.y-y.y),f);I(X),f=X,D=!1}function N(Z){if(S(Z),!D||t.enabled===!1||t.shouldDrag&&!t.shouldDrag(Z))return;w=S(Z);const X=An(on(w.x-y.x,w.y-y.y),f);I(X)}function F(Z){if(t.enabled===!1||t.shouldDrag&&!t.shouldDrag(Z))return;const X=S(Z),eA=An(on(X.x,X.y),$a(1-Z.deltaY/1e3,1-Z.deltaY/1e3),on(-X.x,-X.y),f);I(eA),f=eA,Z.preventDefault()}function L(Z){if(!D||t.shouldDrag&&!t.shouldDrag(Z))return;if(d){const eA=d.getBoundingClientRect();if(Z.clientX>=eA.left+10&&Z.clientX<=eA.right-10&&Z.clientY>=eA.top+10&&Z.clientY<=eA.bottom-10)return}D=!1,w=S(Z);const X=An(on(w.x-y.x,w.y-y.y),f);I(X),f=X}function Y(Z){if(Z.preventDefault(),t.enabled!==!1){if(Z.touches.length===1){Q.current="drag";const X=Z.touches[0];h.current={initialTransform:f,initialTouch:{x:X.clientX,y:X.clientY}}}else if(Z.touches.length===2){Q.current="pinch";const X=Z.touches[0],eA=Z.touches[1];E.current={initialTransform:f,initialTouch1:{x:X.clientX,y:X.clientY},initialTouch2:{x:eA.clientX,y:eA.clientY},finalTouch1:null,finalTouch2:null}}}}function J(Z){if(Z.preventDefault(),t.enabled!==!1){if(Q.current==="drag"&&Z.touches.length===1&&h.current){const X=Z.touches[0],eA={x:X.clientX,y:X.clientY},gA=eA.x-h.current.initialTouch.x,tA=eA.y-h.current.initialTouch.y,iA=An(on(gA,tA),h.current.initialTransform);I(iA)}else if(Q.current==="pinch"&&Z.touches.length===2&&E.current){const X=Z.touches[0],eA=Z.touches[1];E.current.finalTouch1={x:X.clientX,y:X.clientY},E.current.finalTouch2={x:eA.clientX,y:eA.clientY};const gA=The(E.current);I(gA)}}}function O(Z){Z.preventDefault();const X=Z.changedTouches[0];if(Q.current==="drag"&&h.current&&X){const eA={x:X.clientX,y:X.clientY},gA=eA.x-h.current.initialTouch.x,tA=eA.y-h.current.initialTouch.y,iA=An(on(gA,tA),h.current.initialTransform);I(iA),f=iA}else if(Q.current==="pinch"&&E.current){const eA=The(E.current);I(eA),f=eA}Q.current="none",h.current=null,E.current=null}return d.addEventListener("mousedown",_),d.addEventListener("mouseup",b),window.addEventListener("mousemove",N),d.addEventListener("mouseout",L),d.addEventListener("wheel",F),d.addEventListener("touchstart",Y,{passive:!1}),d.addEventListener("touchmove",J,{passive:!1}),d.addEventListener("touchend",O,{passive:!1}),d.addEventListener("touchcancel",O,{passive:!1}),()=>{d.removeEventListener("mousedown",_),d.removeEventListener("mouseup",b),window.removeEventListener("mousemove",N),d.removeEventListener("mouseout",L),d.removeEventListener("wheel",F),d.removeEventListener("touchstart",Y),d.removeEventListener("touchmove",J),d.removeEventListener("touchend",O),d.removeEventListener("touchcancel",O)}},[n,r,g,e,t.enabled,t.shouldDrag]);const u=V.useCallback(d=>Ce(B,d),[B]);return{ref:A,transform:B,applyTransformToPoint:u,setTransform:l,cancelDrag:C}},XAi=zAi;function $Ai(t){const A=new Map;let e=0;function i(n){for(const[,s]of A)if(s.has(n))return s;const o=new Set;return A.set(`connectivity_net${e++}`,o),o}for(const n of t){let o=null;for(const s of n){if(!o)o=i(s);else if(!o.has(s)){const r=i(s);if(r!==o){for(const a of r)o.add(a);A.delete(Array.from(A.entries()).find(([,a])=>a===r)[0])}}o.add(s)}}return Object.fromEntries(Array.from(A.entries()).map(([n,o])=>[n,Array.from(o)]))}var Aei=class{netMap;idToNetMap;constructor(t){this.netMap=t,this.idToNetMap={};for(const[A,e]of Object.entries(t))for(const i of e)this.idToNetMap[i]=A}addConnections(t){for(const A of t){const e=new Set;for(const n of A){const o=this.idToNetMap[n];o&&e.add(o)}let i;if(e.size===0)i=`connectivity_net${Object.keys(this.netMap).length}`,this.netMap[i]=[];else if(e.size===1)i=e.values().next().value??`connectivity_net${Object.keys(this.netMap).length}`;else{i=e.values().next().value??`connectivity_net${Object.keys(this.netMap).length}`;for(const n of e)if(n!==i){this.netMap[i].push(...this.netMap[n]),this.netMap[n]=this.netMap[i];for(const o of this.netMap[i])this.idToNetMap[o]=i}}for(const n of A)this.netMap[i].includes(n)||this.netMap[i].push(n),this.idToNetMap[n]=i}}getIdsConnectedToNet(t){return this.netMap[t]||[]}getNetConnectedToId(t){return this.idToNetMap[t]}areIdsConnected(t,A){if(t===A)return!0;const e=this.getNetConnectedToId(t);if(!e)return!1;const i=this.getNetConnectedToId(A);return i?e===i||i===t||i===t:!1}areAllIdsConnected(t){const A=this.getNetConnectedToId(t[0]);for(const e of t){const i=this.getNetConnectedToId(e);if(i===void 0||i!==A)return!1}return!0}},Phe=t=>{const A=[];for(const i of t)if(i.type==="source_trace")A.push([i.source_trace_id,...i.connected_source_port_ids??[],...i.connected_source_net_ids??[]].filter(Boolean));else if(i.type==="pcb_port"){const{pcb_port_id:n,source_port_id:o}=i;o&&n&&A.push([o,n])}else if(i.type==="pcb_smtpad"){const{pcb_smtpad_id:n,pcb_port_id:o}=i;o&&n&&A.push([n,o])}else if(i.type==="pcb_plated_hole"){const{pcb_plated_hole_id:n,pcb_port_id:o}=i;o&&n&&A.push([n,o])}else if(i.type==="pcb_trace"){const{pcb_trace_id:n,source_trace_id:o}=i,s=Array.isArray(i.route)?i.route.filter(r=>r&&r.route_type==="wire"):[];if(o&&n&&A.push([n,o]),Array.isArray(s)){const r=s.find(g=>g?.start_pcb_port_id)?.start_pcb_port_id,a=s.find(g=>g?.end_pcb_port_id)?.end_pcb_port_id;r&&n&&a&&A.push([r,n,a])}}else if(i.type==="pcb_via"){const{pcb_via_id:n,pcb_trace_id:o}=i;o&&n&&A.push([n,o])}else if(i.type==="source_component"&&i.internally_connected_source_port_ids)for(const n of i.internally_connected_source_port_ids)A.push(n);const e=$Ai(A);return new Aei(e)};function eei({primitivesWithoutInteractionMetadata:t,drawingObjectIdsWithMouseOver:A,primitiveIdsInMousedOverNet:e}){const i=[];for(const n of t){const o={...n};n?.layer==="drill"?(o.is_in_highlighted_net=!1,o.is_mouse_over=!1):A.has(n._pcb_drawing_object_id)?o.is_mouse_over=!0:n._element&&("pcb_trace_id"in n._element&&e.includes(n._element.pcb_trace_id)||"pcb_port_id"in n._element&&e.includes(n._element.pcb_port_id))?o.is_in_highlighted_net=!0:(o.is_in_highlighted_net=!1,o.is_mouse_over=!1),i.push(o)}return i}function tei(t,A){if(t.length<2)throw new Error("Stroke must have at least two points");const e=t.map(I=>Array.isArray(I)?{x:I[0],y:I[1]}:I),i=[],n=[];function o(I,l){const B=l.x-I.x,C=l.y-I.y,Q=Math.sqrt(B*B+C*C);return{x:-C/Q,y:B/Q}}function s(I,l,B,C){const Q=C/2,h={x:I.x+l.x*Q*B,y:I.y+l.y*Q*B};B>0?i.push(h):n.unshift(h)}const r=o(e[0],e[1]),a=e[0].trace_width??A;s(e[0],r,1,a),s(e[0],r,-1,a);for(let I=1;I<e.length-1;I++){const l=e[I-1],B=e[I],C=e[I+1],Q=o(l,B),h=o(B,C),E=Q.x+h.x,u=Q.y+h.y,d=Math.sqrt(E*E+u*u),f=B.trace_width??A;if(d/2>2*(f/2))s(B,Q,1,f),s(B,h,1,f),s(B,Q,-1,f),s(B,h,-1,f);else{const w=1/d;s(B,{x:E*w,y:u*w},1,f),s(B,{x:E*w,y:u*w},-1,f)}}const g=o(e[e.length-2],e[e.length-1]),c=e[e.length-1].trace_width??A;return s(e[e.length-1],g,1,c),s(e[e.length-1],g,-1,c),[...i,...n]}var iei=(t,A)=>{const{x:e,y:i,width:n,height:o,layer:s,rect_border_radius:r}=t,a=t.corner_radius??r??0,g=[{_pcb_drawing_object_id:Nm("rect"),pcb_drawing_type:"rect",x:e,y:i,w:n,h:o,layer:s||"top",_element:t,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port,roundness:a,...t.shape==="rotated_rect"&&t.ccw_rotation!==void 0?{ccw_rotation:t.ccw_rotation}:{}}];if(t.is_covered_with_solder_mask){const c=s==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",l={...{_pcb_drawing_object_id:Nm("rect"),pcb_drawing_type:"rect",x:e,y:i,w:n,h:o,layer:c,_element:t,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port,roundness:a,...t.shape==="rotated_rect"&&t.ccw_rotation!==void 0?{ccw_rotation:t.ccw_rotation}:{}},..."solder_mask_color"in t&&t.solder_mask_color?{color:t.solder_mask_color}:{}};g.push(l)}return g},nei=(t,A)=>{const{x:e,y:i,radius:n,layer:o}=t,s=[{_pcb_drawing_object_id:Nm("circle"),pcb_drawing_type:"circle",x:e,y:i,r:n,layer:o||"top",_element:t,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port}];if(t.is_covered_with_solder_mask){const r=o==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",a={_pcb_drawing_object_id:Nm("circle"),pcb_drawing_type:"circle",x:e,y:i,r:n,layer:r,_element:t,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port,..."solder_mask_color"in t&&t.solder_mask_color?{color:t.solder_mask_color}:{}};s.push(a)}return s},oei=(t,A)=>{const{layer:e,points:i}=t,n=[{_pcb_drawing_object_id:Nm("polygon"),pcb_drawing_type:"polygon",points:fmA(i),layer:e||"top",_element:t,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port}];if(t.is_covered_with_solder_mask){const o=e==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",s={_pcb_drawing_object_id:Nm("polygon"),pcb_drawing_type:"polygon",points:fmA(i),layer:o,_element:t,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port,..."solder_mask_color"in t&&t.solder_mask_color?{color:t.solder_mask_color}:{}};n.push(s)}return n},sei=(t,A)=>{const{x:e,y:i,width:n,height:o,layer:s}=t,r=[{_pcb_drawing_object_id:Nm("pill"),pcb_drawing_type:"pill",x:e,y:i,w:n,h:o,layer:s||"top",_element:t,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port}];if(t.is_covered_with_solder_mask){const a=s==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",g={_pcb_drawing_object_id:Nm("pill"),pcb_drawing_type:"pill",x:e,y:i,w:n,h:o,layer:a,_element:t,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port,..."solder_mask_color"in t&&t.solder_mask_color?{color:t.solder_mask_color}:{}};r.push(g)}return r},rei=(t,A)=>{const{x:e,y:i,width:n,height:o,layer:s,ccw_rotation:r}=t,a=[{_pcb_drawing_object_id:Nm("pill"),pcb_drawing_type:"pill",x:e,y:i,w:n,h:o,layer:s||"top",_element:t,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port,ccw_rotation:r}];if(t.is_covered_with_solder_mask){const g=s==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",c={_pcb_drawing_object_id:Nm("pill"),pcb_drawing_type:"pill",x:e,y:i,w:n,h:o,layer:g,_element:t,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port,ccw_rotation:r,..."solder_mask_color"in t&&t.solder_mask_color?{color:t.solder_mask_color}:{}};a.push(c)}return a},aei=(t,A)=>{const{_parent_pcb_component:e,_parent_source_component:i}=A,n=t,o=typeof n.font_size=="string"?Et.parse(n.font_size):n.font_size??.2;let s;return n.knockout_padding&&(s={left:typeof n.knockout_padding.left=="string"?Et.parse(n.knockout_padding.left):n.knockout_padding.left,top:typeof n.knockout_padding.top=="string"?Et.parse(n.knockout_padding.top):n.knockout_padding.top,bottom:typeof n.knockout_padding.bottom=="string"?Et.parse(n.knockout_padding.bottom):n.knockout_padding.bottom,right:typeof n.knockout_padding.right=="string"?Et.parse(n.knockout_padding.right):n.knockout_padding.right}),[{_pcb_drawing_object_id:Nm("text"),pcb_drawing_type:"text",x:n.anchor_position.x,y:n.anchor_position.y,layer:n.layer,align:n.anchor_alignment??"center",text:n.text,size:o,ccw_rotation:n.ccw_rotation,is_mirrored:n.is_mirrored,is_knockout:n.is_knockout,knockout_padding:s,_element:t,_parent_pcb_component:e,_parent_source_component:i}]},TI=0,Nm=t=>`${t}_${TI++}`,fmA=t=>(t??[]).map(A=>({x:Et.parse(A.x),y:Et.parse(A.y)})),gei=(t,A)=>{const e="pcb_component_id"in t?A.find(s=>s.type==="pcb_component"&&s.pcb_component_id===t.pcb_component_id):void 0,i=e&&"source_component_id"in e?A.find(s=>s.type==="source_component"&&s.source_component_id===e.source_component_id):void 0,n="source_port_id"in t?t.source_port_id:"pcb_port_id"in t?rx(A).pcb_port.get(t.pcb_port_id)?.source_port_id:void 0,o=n?A.find(s=>s.type==="source_port"&&s.source_port_id===n):void 0;switch(t.type){case"pcb_smtpad":{const s={_parent_pcb_component:e,_parent_source_component:i,_source_port:o};return t.shape==="rect"||t.shape==="rotated_rect"?iei(t,s):t.shape==="circle"?nei(t,s):t.shape==="polygon"?oei(t,s):t.shape==="pill"?sei(t,s):t.shape==="rotated_pill"?rei(t,s):[]}case"pcb_trace":{const s=[];if(t.route_thickness_mode==="interpolated"){const g=t.route.map(l=>({x:l.x,y:l.y,trace_width:l.route_type==="wire"?l.width:.5})),c=tei(g,.5),I=t.route[0].layer;return s.push({_pcb_drawing_object_id:`polygon_${TI++}`,_element:t,pcb_drawing_type:"polygon",points:c,layer:I}),t.route.forEach(l=>{l.route_type==="via"&&s.push({_pcb_drawing_object_id:`circle_${TI++}`,_element:t,pcb_drawing_type:"circle",x:l.x,y:l.y,r:l.outer_diameter/2,layer:l.from_layer})}),s}let r=null,a=null;for(const g of t.route)g.route_type==="wire"&&(r!==null&&a!==null&&s.push({_pcb_drawing_object_id:`line_${TI++}`,_element:t,pcb_drawing_type:"line",x1:r,y1:a,x2:g.x,y2:g.y,width:g.width,squareCap:!1,layer:g.layer}),r=g.x,a=g.y);return s}case"pcb_via":{const{x:s,y:r,outer_diameter:a,hole_diameter:g}=t,c=t.from_layer,I=t.to_layer,l=t.layers,B=[];c&&I?B.push(c,I):l&&Array.isArray(l)?B.push(...l):B.push("top","bottom");const C=[];for(const Q of B)C.push({_pcb_drawing_object_id:`circle_${TI++}`,pcb_drawing_type:"circle",x:s,y:r,r:a/2,layer:Q,_element:t,_parent_pcb_component:e,_parent_source_component:i});return C.push({_pcb_drawing_object_id:`circle_${TI++}`,pcb_drawing_type:"circle",x:s,y:r,r:g/2,layer:"drill",_element:t}),C}case"pcb_plated_hole":if(t.shape==="circle"){const{x:s,y:r,hole_diameter:a,outer_diameter:g}=t;return[{_pcb_drawing_object_id:`circle_${TI++}`,pcb_drawing_type:"circle",x:s,y:r,r:g/2,layer:"top",_element:t,_parent_pcb_component:e,_parent_source_component:i,_source_port:o},{_pcb_drawing_object_id:`circle_${TI++}`,pcb_drawing_type:"circle",x:s,y:r,r:a/2,layer:"drill",_element:t}]}else if(t.shape==="oval"){const{x:s,y:r,outer_height:a,outer_width:g,hole_height:c,hole_width:I}=t;return[{_pcb_drawing_object_id:`oval_${TI++}`,pcb_drawing_type:"oval",x:s,y:r,rX:g/2,rY:a/2,layer:"top",_element:t,_parent_pcb_component:e,_parent_source_component:i,_source_port:o},{_pcb_drawing_object_id:`oval_${TI++}`,_element:t,pcb_drawing_type:"oval",x:s,y:r,rX:I/2,rY:c/2,layer:"drill"}]}else if(t.shape==="pill"){const{x:s,y:r,outer_height:a,outer_width:g,hole_height:c,hole_width:I}=t;return[{_pcb_drawing_object_id:`pill_${TI++}`,pcb_drawing_type:"pill",x:s,y:r,w:g,h:a,layer:"top",_element:t,_parent_pcb_component:e,_parent_source_component:i,_source_port:o,ccw_rotation:t.ccw_rotation},{_pcb_drawing_object_id:`pill_${TI++}`,_element:t,pcb_drawing_type:"pill",x:s,y:r,w:I,h:c,layer:"drill",ccw_rotation:t.ccw_rotation}]}else if(t.shape==="circular_hole_with_rect_pad"){const{x:s,y:r,hole_diameter:a,rect_pad_width:g,rect_pad_height:c,rect_border_radius:I,hole_offset_x:l,hole_offset_y:B}=t,C=Et.parse(l??0),Q=Et.parse(B??0);return[{_pcb_drawing_object_id:`rect_${TI++}`,pcb_drawing_type:"rect",x:s,y:r,w:g,h:c,layer:"top",_element:t,_parent_pcb_component:e,_parent_source_component:i,_source_port:o,roundness:I},{_pcb_drawing_object_id:`rect_${TI++}`,pcb_drawing_type:"rect",x:s,y:r,w:g,h:c,layer:"bottom",_element:t,_parent_pcb_component:e,_parent_source_component:i,_source_port:o,roundness:I,is_hoverable:!1},{_pcb_drawing_object_id:`circle_${TI++}`,_element:t,pcb_drawing_type:"circle",x:s+C,y:r+Q,r:a/2,layer:"drill",is_hoverable:!1}]}else if(t.shape==="pill_hole_with_rect_pad"){const{x:s,y:r,hole_width:a,hole_height:g,rect_pad_width:c,rect_pad_height:I,rect_border_radius:l}=t;return[{_pcb_drawing_object_id:`rect_${TI++}`,pcb_drawing_type:"rect",x:s,y:r,w:c,h:I,layer:"top",_element:t,_parent_pcb_component:e,_parent_source_component:i,_source_port:o,roundness:l},{_pcb_drawing_object_id:`rect_${TI++}`,pcb_drawing_type:"rect",x:s,y:r,w:c,h:I,layer:"bottom",_element:t,_parent_pcb_component:e,_parent_source_component:i,_source_port:o,roundness:l,is_hoverable:!1},{_pcb_drawing_object_id:`pill_${TI++}`,_element:t,pcb_drawing_type:"pill",x:s,y:r,w:a,h:g,layer:"drill",is_hoverable:!1}]}else if(t.shape==="rotated_pill_hole_with_rect_pad"){const{x:s,y:r,hole_width:a,hole_height:g,hole_ccw_rotation:c,rect_pad_width:I,rect_pad_height:l,rect_ccw_rotation:B,rect_border_radius:C}=t;return[{_pcb_drawing_object_id:`rect_${TI++}`,pcb_drawing_type:"rect",x:s,y:r,w:I,h:l,layer:"top",_element:t,_parent_pcb_component:e,_parent_source_component:i,_source_port:o,ccw_rotation:B,roundness:C},{_pcb_drawing_object_id:`rect_${TI++}`,pcb_drawing_type:"rect",x:s,y:r,w:I,h:l,layer:"bottom",_element:t,_parent_pcb_component:e,_parent_source_component:i,_source_port:o,ccw_rotation:B,roundness:C,is_hoverable:!1},{_pcb_drawing_object_id:`pill_${TI++}`,_element:t,pcb_drawing_type:"pill",x:s,y:r,w:a,h:g,layer:"drill",ccw_rotation:c,is_hoverable:!1}]}else if(t.shape==="hole_with_polygon_pad"){const{x:s,y:r,pad_outline:a,hole_shape:g,hole_diameter:c,hole_width:I,hole_height:l,layers:B,hole_offset_x:C,hole_offset_y:Q}=t,h=Et.parse(C??0),E=Et.parse(Q??0),u=a,d=[];if(u&&Array.isArray(u)){const w=fmA(u).map(D=>({x:D.x+s,y:D.y+r}));for(const D of B||["top","bottom"])d.push({_pcb_drawing_object_id:`polygon_${TI++}`,pcb_drawing_type:"polygon",points:w,layer:D,_element:t,_parent_pcb_component:e,_parent_source_component:i,_source_port:o})}const f={x:s+h,y:r+E},y=[];return g==="circle"?y.push({_pcb_drawing_object_id:`circle_${TI++}`,pcb_drawing_type:"circle",x:f.x,y:f.y,r:(c??0)/2,layer:"drill",_element:t,_parent_pcb_component:e,_parent_source_component:i}):g==="oval"?y.push({_pcb_drawing_object_id:`oval_${TI++}`,pcb_drawing_type:"oval",x:f.x,y:f.y,rX:(I??0)/2,rY:(l??0)/2,layer:"drill",_element:t,_parent_pcb_component:e,_parent_source_component:i}):(g==="pill"||g==="rotated_pill")&&y.push({_pcb_drawing_object_id:`pill_${TI++}`,pcb_drawing_type:"pill",x:f.x,y:f.y,w:I??0,h:l??0,layer:"drill",_element:t,_parent_pcb_component:e,_parent_source_component:i,ccw_rotation:t.ccw_rotation}),[...d,...y]}else return[];case"pcb_copper_text":return aei(t,{_parent_pcb_component:e,_parent_source_component:i})}return[]},yn={board:{anchor:"rgb(255, 38, 226)",aux_items:"rgb(255, 255, 255)",b_adhes:"rgb(0, 0, 132)",b_crtyd:"rgb(38, 233, 255)",b_fab:"rgb(88, 93, 132)",b_mask:"rgba(2, 255, 238, 0.400)",b_paste:"rgb(0, 194, 194)",b_silks:"rgb(242, 237, 161)",background:"rgb(0, 16, 35)",cmts_user:"rgb(89, 148, 220)",copper:{b:"rgb(77, 127, 196)",f:"rgb(200, 52, 52)",in1:"rgb(127, 200, 127)",in10:"rgb(237, 124, 51)",in11:"rgb(91, 195, 235)",in12:"rgb(247, 111, 142)",in13:"rgb(167, 165, 198)",in14:"rgb(40, 204, 217)",in15:"rgb(232, 178, 167)",in16:"rgb(242, 237, 161)",in17:"rgb(237, 124, 51)",in18:"rgb(91, 195, 235)",in19:"rgb(247, 111, 142)",in2:"rgb(206, 125, 44)",in20:"rgb(167, 165, 198)",in21:"rgb(40, 204, 217)",in22:"rgb(232, 178, 167)",in23:"rgb(242, 237, 161)",in24:"rgb(237, 124, 51)",in25:"rgb(91, 195, 235)",in26:"rgb(247, 111, 142)",in27:"rgb(167, 165, 198)",in28:"rgb(40, 204, 217)",in29:"rgb(232, 178, 167)",in3:"rgb(79, 203, 203)",in30:"rgb(242, 237, 161)",in4:"rgb(219, 98, 139)",in5:"rgb(167, 165, 198)",in6:"rgb(40, 204, 217)",in7:"rgb(232, 178, 167)",in8:"rgb(242, 237, 161)",in9:"rgb(141, 203, 129)"},cursor:"rgb(255, 255, 255)",drc:"rgb(194, 194, 194)",drc_error:"rgba(215, 91, 107, 0.800)",drc_exclusion:"rgb(255, 255, 255)",drc_warning:"rgba(255, 208, 66, 0.902)",dwgs_user:"rgb(194, 194, 194)",eco1_user:"rgb(180, 219, 210)",eco2_user:"rgb(216, 200, 82)",edge_cuts:"rgb(208, 210, 205)",f_adhes:"rgb(132, 0, 132)",f_crtyd:"rgb(255, 0, 245)",f_fab:"rgb(175, 175, 175)",f_mask:"rgba(216, 100, 255, 0.400)",f_paste:"rgba(180, 160, 154, 0.902)",f_silks:"rgb(242, 237, 161)",footprint_text_back:"rgb(0, 0, 132)",footprint_text_front:"rgb(194, 194, 194)",footprint_text_invisible:"rgb(132, 132, 132)",grid:"rgb(132, 132, 132)",grid_axes:"rgb(194, 194, 194)",margin:"rgb(255, 38, 226)",microvia:"rgb(0, 132, 132)",no_connect:"rgb(0, 0, 132)",pad_back:"rgb(77, 127, 196)",pad_front:"rgb(200, 52, 52)",pad_plated_hole:"rgb(194, 194, 0)",pad_through_hole:"rgb(227, 183, 46)",plated_hole:"rgb(26, 196, 210)",ratsnest:"rgba(245, 255, 213, 0.702)",select_overlay:"rgb(4, 255, 67)",soldermaskWithCopper:{top:"rgb(18, 82, 50)",bottom:"rgb(77, 127, 196)"},soldermask:{top:"rgb(12, 55, 33)",bottom:"rgb(12, 55, 33)"},through_via:"rgb(236, 236, 236)",user_1:"rgb(194, 194, 194)",user_2:"rgb(89, 148, 220)",user_3:"rgb(180, 219, 210)",user_4:"rgb(216, 200, 82)",user_5:"rgb(194, 194, 194)",user_6:"rgb(89, 148, 220)",user_7:"rgb(180, 219, 210)",user_8:"rgb(216, 200, 82)",user_9:"rgb(232, 178, 167)",via_blind_buried:"rgb(187, 151, 38)",via_hole:"rgb(227, 183, 46)",via_micro:"rgb(0, 132, 132)",via_through:"rgb(236, 236, 236)",worksheet:"rgb(200, 114, 171)"}},Pf=(t,A=1)=>{if(Math.abs(t.a)!==Math.abs(t.d))throw new Error("Cannot scale non-uniformly");return A*Math.abs(t.a)},kc={elementOverlay:40,dimensionOverlay:40,editTraceHintOverlay:40,errorOverlay:40,pcbGroupOverlay:35,ratsNestOverlay:30,toolbarOverlay:70,warnings:30,topLayer:20,clickToInteractOverlay:100},vz={red:"red",black:"black",green:"green",board:"rgb(255, 255, 255)",other:"#eee",top:yn.board.copper.f,inner1:yn.board.copper.in1,inner2:yn.board.copper.in2,inner3:yn.board.copper.in3,inner4:yn.board.copper.in4,inner5:yn.board.copper.in5,inner6:yn.board.copper.in6,inner7:yn.board.copper.in7,inner8:yn.board.copper.in8,bottom:yn.board.copper.b,drill:yn.board.anchor,keepout:yn.board.background,tkeepout:yn.board.b_crtyd,tplace:yn.board.b_silks,top_courtyard:yn.board.f_crtyd,bottom_courtyard:yn.board.b_crtyd,top_silkscreen:yn.board.f_silks,bottom_silkscreen:yn.board.b_silks,top_fabrication:yn.board.f_fab,bottom_fabrication:yn.board.b_fab,soldermask_top:yn.board.soldermask.top,soldermask_bottom:yn.board.soldermask.bottom,soldermask_with_copper_top:yn.board.soldermaskWithCopper.top,soldermask_with_copper_bottom:yn.board.soldermaskWithCopper.bottom,bottom_notes:yn.board.user_2,top_notes:yn.board.user_2,...yn.board},cei=["board","inner6","inner5","inner4","inner3","inner2","inner1","bottom","soldermask_bottom","bottom_silkscreen","top","soldermask_top","bottom_courtyard","bottom_fabrication","top_courtyard","top_fabrication","edge_cuts","top_silkscreen"],Iei=class{canvasLayerMap;ctxLayerMap;aperture;transform;foregroundLayer="top";lastPoint;constructor(t){this.canvasLayerMap=t,this.ctxLayerMap=Object.fromEntries(Object.entries(t).map(([A,e])=>[A,e.getContext("2d")])),this.transform=xa(),this.transform.d*=-1,this.transform=An(this.transform,on(0,-500)),this.lastPoint={x:0,y:0},this.equip({})}clear(){for(const t of Object.values(this.ctxLayerMap))t.clearRect(0,0,t.canvas.width,t.canvas.height)}equip(t){this.aperture={fontSize:0,shape:"circle",mode:"add",size:0,color:"red",layer:"top",opacity:this.foregroundLayer===t.color?1:.5,...t}}drawMeshPattern(t,A,e,i,n,o=45){const s=this.getLayerCtx(),[r,a]=Ce(this.transform,[t,A]),[g,c]=Ce(this.transform,[t+e,A+i]),I=Pf(this.transform,n);s.lineWidth=1,s.strokeStyle=this.aperture.color;const l=B=>{const C=Math.sin(B),Q=Math.cos(B),h=Math.sqrt((g-r)**2+(c-a)**2);for(let E=-h;E<=h;E+=I)s.beginPath(),s.moveTo(r+E*Q-h*C,a+E*C+h*Q),s.lineTo(r+E*Q+h*C,a+E*C-h*Q),s.stroke()};l(o*Math.PI/180),l((o+90)*Math.PI/180)}rect({x:t,y:A,w:e,h:i,mesh_fill:n,is_filled:o=!0,has_stroke:s,is_stroke_dashed:r,stroke_width:a,roundness:g}){const[c,I]=Ce(this.transform,[t-e/2,A-i/2]),[l,B]=Ce(this.transform,[t+e/2,A+i/2]);this.applyAperture();const C=this.getLayerCtx(),Q=g?Pf(this.transform,g):0,h=s===void 0?o===!1:s;if(n)C.save(),C.beginPath(),Q>0&&C.roundRect?C.roundRect(c,I,l-c,B-I,Q):C.rect(c,I,l-c,B-I),C.clip(),this.drawMeshPattern(t-e/2,A-i/2,e,i,.15),C.restore(),Q>0&&C.roundRect?(C.beginPath(),C.roundRect(c,I,l-c,B-I,Q),C.stroke()):C.strokeRect(c,I,l-c,B-I);else if(o!==!1&&(Q>0&&C.roundRect?(C.beginPath(),C.roundRect(c,I,l-c,B-I,Q),C.fill()):C.fillRect(c,I,l-c,B-I)),h){const E=C.lineWidth;if(a!==void 0&&(C.lineWidth=Pf(this.transform,a)),r){let u=[];const d=Math.abs(this.transform.a);if(d>0){const y=.1*d,w=y*1.3;y>.5&&(u=[y,w])}C.setLineDash(u)}Q>0&&C.roundRect?(C.beginPath(),C.roundRect(c,I,l-c,B-I,Q),C.stroke()):C.strokeRect(c,I,l-c,B-I),r&&C.setLineDash([]),a!==void 0&&(C.lineWidth=E)}}rotatedRect(t,A,e,i,n,o,s){const r=this.getLayerCtx();this.applyAperture();const[a,g]=Ce(this.transform,[t-e/2,A-i/2]),[c,I]=Ce(this.transform,[t+e/2,A+i/2]),l=o?Pf(this.transform,o):0;r.save();const[B,C]=Ce(this.transform,[t,A]);r.translate(B,C);const Q=360-n;n&&r.rotate(Q*Math.PI/180),r.translate(-B,-C),s?(r.beginPath(),l>0&&r.roundRect?r.roundRect(a,g,c-a,I-g,l):r.rect(a,g,c-a,I-g),r.clip(),this.drawMeshPattern(t-e/2,A-i/2,e,i,.15),l>0&&r.roundRect?(r.beginPath(),r.roundRect(a,g,c-a,I-g,l),r.stroke()):r.strokeRect(a,g,c-a,I-g)):l>0&&r.roundRect?(r.beginPath(),r.roundRect(a,g,c-a,I-g,l),r.fill()):r.fillRect(a,g,c-a,I-g),r.restore()}rotatedPill(t,A,e,i,n){const o=this.getLayerCtx();this.applyAperture(),o.save();const[s,r]=Ce(this.transform,[t,A]);o.translate(s,r);const a=360-n;n&&o.rotate(a*Math.PI/180),o.translate(-s,-r),this.pill(t,A,e,i),o.restore()}circle(t,A,e,i,n=!0){const o=Pf(this.transform,e),[s,r]=Ce(this.transform,[t,A]);this.applyAperture();const a=this.getLayerCtx();i?(a.save(),a.beginPath(),a.arc(s,r,o,0,2*Math.PI),a.clip(),this.drawMeshPattern(t-e,A-e,e*2,e*2,.15),a.restore(),a.beginPath(),a.arc(s,r,o,0,2*Math.PI),a.stroke()):(a.beginPath(),a.arc(s,r,o,0,2*Math.PI),a.fill())}oval(t,A,e,i){const n=Pf(this.transform,e),o=Pf(this.transform,i),[s,r]=Ce(this.transform,[t,A]);this.applyAperture();const a=this.getLayerCtx();a.beginPath(),a.ellipse(s,r,n,o,0,0,2*Math.PI),a.fill(),a.closePath()}pill(t,A,e,i){const[n,o]=Ce(this.transform,[t-e/2,A+i/2]),s=Pf(this.transform,e),r=Pf(this.transform,i),a=Math.min(s,r)/2;this.applyAperture();const g=this.getLayerCtx();g.beginPath(),g.arc(n+a,o+a,a,Math.PI,Math.PI*1.5),g.arc(n+s-a,o+a,a,Math.PI*1.5,0),g.arc(n+s-a,o+r-a,a,0,Math.PI*.5),g.arc(n+a,o+r-a,a,Math.PI*.5,Math.PI),g.fill(),g.closePath()}polygon(t){if(t.length<3)return;this.applyAperture();const A=this.getLayerCtx(),e=t.map(n=>Ce(this.transform,[n.x,n.y]));A.beginPath(),A.moveTo(e[0][0],e[0][1]);for(let n=1;n<e.length;n++)A.lineTo(e[n][0],e[n][1]);A.closePath(),A.fill("evenodd");const i=Pf(this.transform,this.aperture.size);i>0&&(A.lineWidth=i,A.stroke())}debugText(t,A,e){const[i,n]=Ce(this.transform,[A,e]);this.applyAperture();const o=this.getLayerCtx();o.font="10px sans-serif",o.fillText(t,i,n)}getLayerCtx(){const t=this.ctxLayerMap[this.aperture.layer];if(!t)throw new Error(`No context for layer "${this.aperture.layer}"`);return t}orderAndFadeLayers(){const{canvasLayerMap:t,foregroundLayer:A}=this,e=A==="top"?"soldermask_top":A==="bottom"?"soldermask_bottom":void 0,i=A==="top"?"top_silkscreen":A==="bottom"?"bottom_silkscreen":void 0,n=A==="top"?"top_notes":A==="bottom"?"bottom_notes":void 0,o=A==="top"?"top_fabrication":A==="bottom"?"bottom_fabrication":void 0,s=A==="top"?"top_courtyard":A==="bottom"?"bottom_courtyard":void 0,r=new Set([A,"drill","edge_cuts","other","board",...e?[e]:[],...i?[i]:[],...n?[n]:[],...o?[o]:[],...s?[s]:[]]),a=[A,"edge_cuts",...e?[e]:[],...i?[i]:[],...n?[n]:[],...o?[o]:[],...s?[s]:[]],g=A==="drill"?[]:["drill"],c=A==="drill"?["drill"]:[],I=[...cei.filter(l=>!a.includes(l)),...g,A,...e?[e]:[],...c,"edge_cuts",...i?[i]:[],...n?[n]:[],...o?[o]:[],...s?[s]:[]];I.forEach((l,B)=>{const C=t[l];C&&(C.style.zIndex=`${kc.topLayer-(I.length-B)}`,C.style.opacity=r.has(l)?"1":"0.5")})}applyAperture(){const{transform:t,aperture:A}=this;let{size:e,mode:i,color:n,fontSize:o,layer:s}=A;s in this.ctxLayerMap||(this.aperture.layer="other");const r=this.getLayerCtx();if(!r)throw new Error(`No context for layer "${this.foregroundLayer}"`);if(n||(n="undefined"),r.lineWidth=Pf(t,e),r.lineCap="round",i==="add"){r.globalCompositeOperation="source-over";let a=vz[n.toLowerCase()];if(!a)try{a=Ta(n).rgb().toString()}catch{console.warn(`Invalid color format: '${n}'`),a="white"}r.fillStyle=a,r.strokeStyle=a}else r.globalCompositeOperation="destination-out",r.fillStyle="rgba(0,0,0,1)",r.strokeStyle="rgba(0,0,0,1)";r.font=`${Pf(tm(t),o)}px sans-serif`}moveTo(t,A){this.lastPoint={x:t,y:A}}lineTo(t,A){const[e,i]=Ce(this.transform,[t,A]),{size:n,shape:o,mode:s}=this.aperture,r=Pf(this.transform,n),{lastPoint:a}=this,g=Ce(this.transform,a);this.applyAperture();const c=this.getLayerCtx();o==="square"&&c.fillRect(g.x-r/2,g.y-r/2,r,r),c.beginPath(),c.moveTo(g.x,g.y),c.lineTo(e,i),c.stroke(),c.closePath(),o==="square"&&c.fillRect(e-r/2,i-r/2,r,r),this.lastPoint={x:t,y:A}}polygonWithArcs(t){const A=this.getLayerCtx(),e=i=>{if(i.vertices.length===0)return;const n=i.vertices[0],o=Ce(this.transform,[n.x,n.y]);A.moveTo(o[0],o[1]);for(let s=0;s<i.vertices.length;s++){const r=i.vertices[s],a=i.vertices[(s+1)%i.vertices.length];if(r.bulge&&r.bulge!==0){const g=r.bulge,c=a.x-r.x,I=a.y-r.y,l=Math.sqrt(c*c+I*I);if(l<1e-9){const F=Ce(this.transform,[a.x,a.y]);A.lineTo(F[0],F[1]);continue}const B=4*Math.atan(g),C=Math.abs(l/(2*Math.sin(B/2))),Q=(r.x+a.x)/2,h=(r.y+a.y)/2,E=c/l,d=-(I/l),f=E,y=Math.sqrt(Math.max(0,C*C-(l/2)**2)),w=Q+y*d*Math.sign(g),D=h+y*f*Math.sign(g),S=Math.atan2(r.y-D,r.x-w);let _=Math.atan2(a.y-D,a.x-w);g>0&&_<S?_+=2*Math.PI:g<0&&_>S&&(_-=2*Math.PI);const b=Ce(this.transform,[w,D]),N=Pf(this.transform,C);A.arc(b[0],b[1],N,-S,-_,g>0)}else{const g=Ce(this.transform,[a.x,a.y]);A.lineTo(g[0],g[1])}}A.closePath()};if(A.beginPath(),e(t.outer_ring),t.inner_rings)for(const i of t.inner_rings)e(i);A.fill("evenodd")}};function lei(t){return t.type==="pcb_copper_pour"}function Fz({canvas:t,elements:A,layers:e,realToCanvasMat:i}){const n=A.filter(lei);if(n.length===0)return;const o=new iQ(t);o.realToCanvasMat=i,o.drawElements(n,{layers:e})}var Bei={...gp,silkscreen:{top:yn.board.f_fab,bottom:yn.board.b_fab}};function Cei(t){return t.type.includes("pcb_fabrication_note")}function Khe({canvas:t,elements:A,layers:e,realToCanvasMat:i}){const n=new iQ(t);n.configure({colorOverrides:Bei}),n.realToCanvasMat=i;const o=A.filter(Cei);n.drawElements(o,{layers:e})}function Qei(t){return t.type==="pcb_hole"}function hei({canvas:t,elements:A,layers:e,realToCanvasMat:i,drawSoldermask:n}){const o=new iQ(t);o.realToCanvasMat=i;const s=A.filter(Qei);o.drawElements(s,{layers:e,drawSoldermask:n})}function Eei(t){return t.type==="pcb_board"}function uei({canvas:t,elements:A,layers:e,realToCanvasMat:i,drawSoldermask:n}){const o=new iQ(t);o.realToCanvasMat=i;const s=A.filter(Eei);for(const r of s)o.drawElements([r],{layers:e,drawSoldermask:!1,drawBoardMaterial:n??!1,minBoardOutlineStrokePx:2})}function dei(t){return t.type==="pcb_cutout"}function pei({canvas:t,elements:A,layers:e,realToCanvasMat:i}){const n=new iQ(t);n.realToCanvasMat=i;const o=A.filter(dei);n.drawElements(o,{layers:e})}function fei(t){return t.type==="pcb_keepout"}function yei({canvas:t,elements:A,layers:e,realToCanvasMat:i}){const n=A.filter(fei);if(n.length===0)return;const o=new iQ(t);o.realToCanvasMat=i,o.drawElements(n,{layers:[]})}function mei(t){return t.type.startsWith("pcb_note_")}function qhe({canvas:t,elements:A,layers:e,realToCanvasMat:i}){const n=new iQ(t);n.realToCanvasMat=i;const o=A.filter(mei);n.drawElements(o,{layers:e})}function wei(t){return t.type==="pcb_panel"}function Dei({canvas:t,elements:A,layers:e,realToCanvasMat:i,drawSoldermask:n}){const o=new iQ(t);o.realToCanvasMat=i;const s=A.filter(wei);for(const r of s)o.drawElements([r],{layers:e})}var Sei={...gp,copper:{...gp.copper,top:Ta(yn.board.pad_front).lighten(.5).toString(),bottom:Ta(yn.board.pad_back).lighten(.5).toString(),inner1:Ta(yn.board.copper.in1).lighten(.5).toString(),inner2:Ta(yn.board.copper.in2).lighten(.5).toString(),inner3:Ta(yn.board.copper.in3).lighten(.5).toString(),inner4:Ta(yn.board.copper.in4).lighten(.5).toString(),inner5:Ta(yn.board.copper.in5).lighten(.5).toString(),inner6:Ta(yn.board.copper.in6).lighten(.5).toString()}};function bei(t){return t.type==="pcb_smtpad"}function xei({canvas:t,elements:A,layers:e,realToCanvasMat:i,primitives:n,drawSoldermask:o}){const s=A.filter(bei).filter(c=>{const I=c.layer;return e.some(l=>l==="top_copper"&&I==="top"||l==="bottom_copper"&&I==="bottom"||l==="inner1_copper"&&I==="inner1"||l==="inner2_copper"&&I==="inner2"||l==="inner3_copper"&&I==="inner3"||l==="inner4_copper"&&I==="inner4"||l==="inner5_copper"&&I==="inner5"||l==="inner6_copper"&&I==="inner6")});if(s.length===0)return;const r=new Set;if(n)for(const c of n)(c.is_mouse_over||c.is_in_highlighted_net)&&c._element?.type==="pcb_smtpad"&&r.add(c._element.pcb_smtpad_id);const a=s.filter(c=>r.has(c.pcb_smtpad_id)),g=s.filter(c=>!r.has(c.pcb_smtpad_id));if(g.length>0){const c=new iQ(t);c.realToCanvasMat=i,c.drawElements(g,{layers:e,drawSoldermask:o})}if(a.length>0){const c=new iQ(t);c.configure({colorOverrides:Sei}),c.realToCanvasMat=i,c.drawElements(a,{layers:e,drawSoldermask:o})}}var _ei={...gp,copper:{...gp.copper,top:Ta(yn.board.pad_front).lighten(.5).toString(),bottom:Ta(yn.board.pad_back).lighten(.5).toString(),inner1:Ta(yn.board.copper.in1).lighten(.5).toString(),inner2:Ta(yn.board.copper.in2).lighten(.5).toString(),inner3:Ta(yn.board.copper.in3).lighten(.5).toString(),inner4:Ta(yn.board.copper.in4).lighten(.5).toString(),inner5:Ta(yn.board.copper.in5).lighten(.5).toString(),inner6:Ta(yn.board.copper.in6).lighten(.5).toString()}};function kei(t){return t.type==="pcb_trace"}var vei=t=>t.map(A=>A.endsWith("_copper")?A.replace("_copper",""):A),Fei=(t,A)=>{const e=t.route.filter(i=>i.route_type==="wire"&&"layer"in i&&A.has(i.layer));return e.length===0?null:{...t,route:e}};function Mei({canvas:t,elements:A,layers:e,realToCanvasMat:i,primitives:n}){const o=new Set(vei(e)),s=A.filter(kei).map(c=>Fei(c,o)).filter(c=>c!==null);if(s.length===0)return;const r=new Set;if(n)for(const c of n)(c.is_mouse_over||c.is_in_highlighted_net)&&c._element?.type==="pcb_trace"&&r.add(c._element.pcb_trace_id);const a=[],g=[];for(const c of s)r.has(c.pcb_trace_id)?a.push(c):g.push(c);if(g.length>0){const c=new iQ(t);c.realToCanvasMat=i,c.drawElements(g,{layers:e})}if(a.length>0){const c=new iQ(t);c.configure({colorOverrides:_ei}),c.realToCanvasMat=i,c.drawElements(a,{layers:e})}}var Rei={...gp,copper:{...gp.copper,top:Ta(yn.board.pad_front).lighten(.5).toString(),bottom:Ta(yn.board.pad_back).lighten(.5).toString()}};function Nei(t){return t.type==="pcb_plated_hole"}function Ohe({canvas:t,elements:A,layers:e,realToCanvasMat:i,primitives:n,drawSoldermask:o}){const s=A.filter(Nei);if(s.length===0)return;const r=new Set;if(n)for(const c of n)(c.is_mouse_over||c.is_in_highlighted_net)&&c._element?.type==="pcb_plated_hole"&&r.add(c._element.pcb_plated_hole_id);const a=s.filter(c=>r.has(c.pcb_plated_hole_id)),g=s.filter(c=>!r.has(c.pcb_plated_hole_id));if(g.length>0){const c=new iQ(t);c.realToCanvasMat=i,c.drawElements(g,{layers:e,drawSoldermask:o})}if(a.length>0){const c=new iQ(t);c.configure({colorOverrides:Rei}),c.realToCanvasMat=i,c.drawElements(a,{layers:e,drawSoldermask:o})}}function Whe(t){const{lines:A,anchorPoint:e,ccwRotation:i}=t;if(!i)return A;const n=i*Math.PI/180,o=Tl(n),s=An(on(e.x,e.y),o,on(-e.x,-e.y));return Ce(s,e),A.map(r=>({...r,x1:Ce(s,{x:r.x1,y:r.y1}).x,y1:Ce(s,{x:r.x1,y:r.y1}).y,x2:Ce(s,{x:r.x2,y:r.y2}).x,y2:Ce(s,{x:r.x2,y:r.y2}).y}))}var Gei=.6,Zhe=.2,Vhe=t=>{const A=t.size*.7,e=A*Gei,i=A*Zhe,n=A*Zhe,o=t.text.split(/\r?\n/),s=t.text.length>0&&A>0,r=s?o.length:0,a=s?o.map(I=>I.length===0?0:I.length*e+(I.length-1)*i):[],g=a.length>0?Math.max(...a):0,c=r>0?r*A+(r-1)*n:0;return{text_lines:o,line_count:r,line_widths:a,target_height:A,target_width_char:e,space_between_chars:i,space_between_lines:n,width:g,height:c}},jhe=t=>{const A=Vhe(t);return{width:A.width,height:A.height,lineHeight:A.target_height,lineSpacing:A.space_between_lines,lineCount:A.line_count}},zhe=t=>{const{text_lines:A,line_count:e,line_widths:i,target_height:n,target_width_char:o,space_between_chars:s,space_between_lines:r,width:a}=Vhe(t);if(n<=0||e===0)return[];const g=n/12,c=[];for(let I=0;I<e;I++){const l=-I*(n+r),B=i[I],C=(a-B)/2;let Q=t.x+C;for(let h=0;h<A[I].length;h++){const E=A[I][h],u=XF[E]??XF[E.toUpperCase()];if(!u){Q+=o+s;continue}for(const{x1:d,y1:f,x2:y,y2:w}of u)c.push({_pcb_drawing_object_id:Nm("line"),pcb_drawing_type:"line",x1:Q+o*d,y1:t.y+l+n*f,x2:Q+o*y,y2:t.y+l+n*w,width:g,layer:t.layer,unit:t.unit,color:t.color});Q+=o+s}}return c};function yS(t){const e=t.color??vz[t.layer];let i=Ta(e);return t._element?.type==="pcb_copper_pour"&&(i=i.alpha(.7)),t.is_mouse_over||t.is_in_highlighted_net?i.lighten(.5).rgb().toString():i.rgb().toString()}var Xhe=(t,A)=>{t.equip({size:A.zoomIndependent?A.width/t.transform.a:A.width,shape:A.squareCap?"square":"circle",color:yS(A),layer:A.layer}),t.moveTo(A.x1,A.y1),t.lineTo(A.x2,A.y2)},Lei=(t,A,e)=>{switch(e){case"top_left":return{x:0,y:-A};case"top_center":return{x:-t/2,y:-A};case"top_right":return{x:-t,y:-A};case"center_left":return{x:0,y:-A/2};case"center":return{x:-t/2,y:-A/2};case"center_right":return{x:-t,y:-A/2};case"bottom_left":return{x:0,y:0};case"bottom_center":return{x:-t/2,y:0};case"bottom_right":return{x:-t,y:0};default:return{x:0,y:0}}},$he=t=>t.layer==="bottom_silkscreen"||t.layer==="bottom"?t.is_mirrored!==!1:t.is_mirrored===!0,Uei=(t,A)=>{t.equip({fontSize:A.size,color:yS(A),layer:A.layer});const{width:e,height:i}=jhe(A),n=Lei(e,i,A.align);A.x??=0,A.y??=0;const o={x:A.x,y:A.y};let s=zhe({...A,x:A.x+n.x,y:A.y+n.y});if($he(A)&&(s=s.map(r=>({...r,x1:2*A.x-r.x1,x2:2*A.x-r.x2}))),A.ccw_rotation){const r={lines:s,anchorPoint:o,ccwRotation:A.ccw_rotation};s=Whe(r)}for(const r of s)Xhe(t,r)},Hei=(t,A)=>{const{width:e,height:i,lineHeight:n}=jhe(A);A.x??=0,A.y??=0;const o=A.knockout_padding??{left:A.size*.5,right:A.size*.5,top:A.size*.3,bottom:A.size*.3},s=e+o.left+o.right,r=i+o.top+o.bottom,a=e/2,g=n-i/2,c=A.x-a,I=A.y-g,l={x:A.x,y:A.y},B={_pcb_drawing_object_id:`knockout_rect_${A._pcb_drawing_object_id}`,x:A.x,y:A.y,w:s,h:r,layer:A.layer,ccw_rotation:A.ccw_rotation};A.ccw_rotation?eEe(t,B):AEe(t,B);let C=zhe({...A,x:c,y:I});if($he(A)&&(C=C.map(Q=>({...Q,x1:2*A.x-Q.x1,x2:2*A.x-Q.x2}))),A.ccw_rotation){const Q={lines:C,anchorPoint:l,ccwRotation:A.ccw_rotation};C=Whe(Q)}for(const Q of C)t.equip({size:Q.width,shape:"circle",color:"black",layer:A.layer,mode:"subtract"}),t.moveTo(Q.x1,Q.y1),t.lineTo(Q.x2,Q.y2);t.equip({mode:"add"})},AEe=(t,A)=>{t.equip({color:yS(A),layer:A.layer,size:A.stroke_width}),t.rect({x:A.x,y:A.y,w:A.w,h:A.h,mesh_fill:A.mesh_fill,is_filled:A.is_filled,has_stroke:A.has_stroke,is_stroke_dashed:A.is_stroke_dashed,stroke_width:A.stroke_width,roundness:A.roundness})},eEe=(t,A)=>{t.equip({color:yS(A),layer:A.layer}),t.rotatedRect(A.x,A.y,A.w,A.h,A.ccw_rotation,A.roundness,A.mesh_fill)},Yei=(t,A)=>{t.equip({color:yS(A),layer:A.layer}),t.rotatedPill(A.x,A.y,A.w,A.h,A.ccw_rotation)},Jei=(t,A)=>{t.equip({color:yS(A),layer:A.layer}),t.circle(A.x,A.y,A.r,A.mesh_fill)},Tei=(t,A)=>{t.equip({color:yS(A),layer:A.layer}),t.oval(A.x,A.y,A.rX,A.rY)},Pei=(t,A)=>{t.equip({color:yS(A),layer:A.layer}),t.pill(A.x,A.y,A.w,A.h)},Kei=(t,A)=>{t.equip({color:yS(A),layer:A.layer}),t.polygon(A.points)},qei=(t,A)=>{t.equip({color:yS(A),layer:A.layer}),t.polygonWithArcs(A.brep_shape)},Oei=(t,A)=>{switch(A.pcb_drawing_type){case"line":return Xhe(t,A);case"text":return A.is_knockout?Hei(t,A):Uei(t,A);case"rect":return A.ccw_rotation?eEe(t,A):AEe(t,A);case"circle":return Jei(t,A);case"oval":return Tei(t,A);case"pill":return A.ccw_rotation?Yei(t,A):Pei(t,A);case"polygon":return Kei(t,A);case"polygon_with_arcs":return qei(t,A)}},Wei=(t,A)=>{for(const e of A)Oei(t,e)},Zei={...gp,copper:{...gp.copper,top:Ta(yn.board.pad_front).lighten(.5).toString(),bottom:Ta(yn.board.pad_back).lighten(.5).toString(),inner1:Ta(yn.board.copper.in1).lighten(.5).toString(),inner2:Ta(yn.board.copper.in2).lighten(.5).toString(),inner3:Ta(yn.board.copper.in3).lighten(.5).toString(),inner4:Ta(yn.board.copper.in4).lighten(.5).toString(),inner5:Ta(yn.board.copper.in5).lighten(.5).toString(),inner6:Ta(yn.board.copper.in6).lighten(.5).toString()},soldermask:{...gp.soldermask,top:Ta(yn.board.soldermask.top).lighten(.35).toString(),bottom:Ta(yn.board.soldermask.bottom).lighten(.35).toString()}};function tEe({canvas:t,elements:A,layers:e,realToCanvasMat:i,drawSoldermaskTop:n,drawSoldermaskBottom:o,primitives:s}){const r=new iQ(t);r.realToCanvasMat=i;const a=A.filter(l=>l.type==="pcb_board");if(a.length<=1)r.drawElements(A,{layers:e,drawSoldermask:!0,drawSoldermaskTop:n,drawSoldermaskBottom:o,drawBoardMaterial:!1});else{const l=A.filter(B=>B.type!=="pcb_board");for(const B of a)r.drawElements([B,...l],{layers:e,drawSoldermask:!0,drawSoldermaskTop:n,drawSoldermaskBottom:o,drawBoardMaterial:!1})}if(!s)return;const g=new Set;for(const l of s){if(!(l.is_mouse_over||l.is_in_highlighted_net))continue;const B=l._element;B?.type==="pcb_smtpad"?g.add(B.pcb_smtpad_id):B?.type==="pcb_plated_hole"?g.add(B.pcb_plated_hole_id):B?.type==="pcb_via"&&g.add(B.pcb_via_id)}if(g.size===0)return;const c=A.filter(l=>l.type==="pcb_smtpad"?g.has(l.pcb_smtpad_id):l.type==="pcb_plated_hole"?g.has(l.pcb_plated_hole_id):l.type==="pcb_via"?g.has(l.pcb_via_id):!1);if(c.length===0)return;const I=new iQ(t);I.configure({colorOverrides:Zei}),I.realToCanvasMat=i,I.drawElements(c,{layers:e,drawSoldermask:!0,drawSoldermaskTop:n,drawSoldermaskBottom:o,drawBoardMaterial:!1})}var Vei={...gp,silkscreen:{top:yn.board.f_silks,bottom:yn.board.b_silks}};function jei(t){return t.type.includes("pcb_silkscreen")}function iEe({canvas:t,elements:A,layers:e,realToCanvasMat:i}){const n=new iQ(t);n.configure({colorOverrides:Vei}),n.realToCanvasMat=i;const o=A.filter(jei);n.drawElements(o,{layers:e})}var zei={...gp,copper:{...gp.copper,top:Ta(yn.board.pad_front).lighten(.5).toString(),bottom:Ta(yn.board.pad_back).lighten(.5).toString()}};function Xei(t){return t.type==="pcb_via"}function nEe({canvas:t,elements:A,layers:e,realToCanvasMat:i,primitives:n,drawSoldermask:o}){const s=A.filter(Xei).filter(c=>e.some(I=>I.includes("copper")));if(s.length===0)return;const r=new Set;if(n)for(const c of n)(c.is_mouse_over||c.is_in_highlighted_net)&&c._element?.type==="pcb_via"&&r.add(c._element.pcb_via_id);const a=s.filter(c=>r.has(c.pcb_via_id)),g=s.filter(c=>!r.has(c.pcb_via_id));if(g.length>0){const c=new iQ(t);c.realToCanvasMat=i,c.drawElements(g,{layers:e,drawSoldermask:o})}if(a.length>0){const c=new iQ(t);c.configure({colorOverrides:zei}),c.realToCanvasMat=i,c.drawElements(a,{layers:e,drawSoldermask:o})}}var $ei={...gp,courtyard:{top:yn.board.f_crtyd,bottom:yn.board.b_crtyd}};function Ati(t){return t.type==="pcb_courtyard_circle"||t.type==="pcb_courtyard_rect"||t.type==="pcb_courtyard_outline"}function oEe({canvas:t,elements:A,layers:e,realToCanvasMat:i}){const n=new iQ(t);n.configure({colorOverrides:$ei}),n.realToCanvasMat=i;const o=A.filter(Ati);n.drawElements(o,{layers:e})}var eti=["board","bottom","soldermask_bottom","bottom_silkscreen","top","soldermask_top","soldermask_with_copper_bottom","soldermask_with_copper_top","top_fabrication","bottom_fabrication","inner1","inner2","inner3","inner4","inner5","inner6","drill","edge_cuts","bottom_notes","top_notes","top_silkscreen","top_courtyard","bottom_courtyard","other"],tti=({primitives:t,elements:A,transform:e,grid:i,width:n=500,height:o=500})=>{const s=V.useRef({}),r=gl(l=>l.selected_layer),a=gl(l=>l.is_showing_solder_mask),g=gl(l=>l.is_showing_fabrication_notes),c=gl(l=>l.is_showing_courtyards),I=gl(l=>l.is_showing_silkscreen);return V.useEffect(()=>{if(!s.current||Object.keys(s.current).length===0)return;const l=Object.fromEntries(Object.entries(s.current).filter(([Q,h])=>!!h));if(Object.keys(l).length===0)return;const B=new Iei(l);e&&(B.transform=e),B.clear(),B.foregroundLayer=r;const C=t.filter(Q=>a||!Q.layer?.includes("soldermask")).filter(Q=>I||!Q.layer?.includes("silkscreen")).filter(Q=>g||!Q.layer?.includes("fabrication")).filter(Q=>Q.layer!=="board").filter(Q=>Q._element?.type!=="pcb_smtpad").filter(Q=>Q._element?.type!=="pcb_plated_hole").filter(Q=>Q._element?.type!=="pcb_via").filter(Q=>Q._element?.type!=="pcb_trace");if(Wei(B,C),e){const Q=s.current.top,h=s.current.bottom,E=s.current.inner1,u=s.current.inner2,d=s.current.inner3,f=s.current.inner4,y=s.current.inner5,w=s.current.inner6,D=[{canvas:Q,copperLayer:"top_copper"},{canvas:h,copperLayer:"bottom_copper"},{canvas:E,copperLayer:"inner1_copper"},{canvas:u,copperLayer:"inner2_copper"},{canvas:d,copperLayer:"inner3_copper"},{canvas:f,copperLayer:"inner4_copper"},{canvas:y,copperLayer:"inner5_copper"},{canvas:w,copperLayer:"inner6_copper"}];for(const{canvas:Y,copperLayer:J}of D)Y&&Mei({canvas:Y,elements:A,layers:[J],realToCanvasMat:e,primitives:t});Q&&Ohe({canvas:Q,elements:A,layers:["top_copper"],realToCanvasMat:e,primitives:t,drawSoldermask:a}),h&&Ohe({canvas:h,elements:A,layers:["bottom_copper"],realToCanvasMat:e,primitives:t,drawSoldermask:a}),Q&&Fz({canvas:Q,elements:A,layers:["top_copper"],realToCanvasMat:e}),h&&Fz({canvas:h,elements:A,layers:["bottom_copper"],realToCanvasMat:e});for(const{canvas:Y,copperLayer:J}of D)Y&&xei({canvas:Y,elements:A,layers:[J],realToCanvasMat:e,primitives:t,drawSoldermask:a});if(Q&&nEe({canvas:Q,elements:A,layers:["top_copper"],realToCanvasMat:e,primitives:t,drawSoldermask:a}),h&&nEe({canvas:h,elements:A,layers:["bottom_copper"],realToCanvasMat:e,primitives:t,drawSoldermask:a}),a){const Y=r==="bottom"?"bottom":"top",J=Y==="top",O=Y==="bottom",Z=s.current.soldermask_top;Z&&Y==="top"&&tEe({canvas:Z,elements:A,layers:["top_soldermask"],realToCanvasMat:e,drawSoldermaskTop:J,drawSoldermaskBottom:O,primitives:t});const X=s.current.soldermask_bottom;X&&Y==="bottom"&&tEe({canvas:X,elements:A,layers:["bottom_soldermask"],realToCanvasMat:e,drawSoldermaskTop:J,drawSoldermaskBottom:O,primitives:t})}Q&&Fz({canvas:Q,elements:A,layers:["top_copper"],realToCanvasMat:e}),h&&Fz({canvas:h,elements:A,layers:["bottom_copper"],realToCanvasMat:e});const S=s.current.drill;if(S&&hei({canvas:S,elements:A,layers:["drill"],realToCanvasMat:e}),I){const Y=s.current.top_silkscreen;Y&&iEe({canvas:Y,elements:A,layers:["top_silkscreen"],realToCanvasMat:e});const J=s.current.bottom_silkscreen;J&&iEe({canvas:J,elements:A,layers:["bottom_silkscreen"],realToCanvasMat:e})}if(g){const Y=s.current.top_fabrication;Y&&Khe({canvas:Y,elements:A,layers:["top_fabrication_note"],realToCanvasMat:e});const J=s.current.bottom_fabrication;J&&Khe({canvas:J,elements:A,layers:["bottom_fabrication_note"],realToCanvasMat:e})}const _=s.current.bottom_notes;_&&qhe({canvas:_,elements:A,layers:["bottom_user_note"],realToCanvasMat:e});const b=s.current.top_notes;if(b&&qhe({canvas:b,elements:A,layers:["top_user_note"],realToCanvasMat:e}),c){const Y=s.current.top_courtyard;Y&&oEe({canvas:Y,elements:A,layers:["top_courtyard"],realToCanvasMat:e});const J=s.current.bottom_courtyard;J&&oEe({canvas:J,elements:A,layers:["bottom_courtyard"],realToCanvasMat:e})}const N=s.current.board;N&&(Dei({canvas:N,elements:A,layers:[],realToCanvasMat:e,drawSoldermask:a}),uei({canvas:N,elements:A,layers:[],realToCanvasMat:e,drawSoldermask:a}));const F=s.current.edge_cuts;F&&pei({canvas:F,elements:A,layers:["edge_cuts"],realToCanvasMat:e});const L=[{canvas:Q,layer:"top"},{canvas:h,layer:"bottom"}];for(const{canvas:Y,layer:J}of L)Y&&yei({canvas:Y,elements:A,layers:[J],realToCanvasMat:e})}B.orderAndFadeLayers()},[t,A,e,r,a,g,c,I]),W.jsxs("div",{style:{backgroundColor:"black",width:n,height:o,position:"relative"},children:[W.jsx(hz.SuperGrid,{textColor:"rgba(0,255,0,0.8)",majorColor:"rgba(0,255,0,0.4)",minorColor:"rgba(0,255,0,0.2)",screenSpaceCellSize:200,width:n,height:o,transform:e,stringifyCoord:(l,B,C)=>`${hz.toMMSI(l,C)}, ${hz.toMMSI(B,C)}`}),eti.filter(l=>!(!a&&l.includes("soldermask")||!I&&l.includes("silkscreen"))).map(l=>l.replace(/-/g,"")).map((l,B)=>W.jsx("canvas",{className:`pcb-layer-${l}`,ref:C=>{s.current??={},C?s.current[l]=C:delete s.current[l]},style:{position:"absolute",zIndex:B,left:0,top:0,pointerEvents:"none"},width:n,height:o},l))]})},iti=.6,nti=1;CmA(cAi(),1),CmA(SAi(),1);var Mz=["rgba(239, 68, 68, 0.8)","rgba(249, 115, 22, 0.8)","rgba(245, 158, 11, 0.8)","rgba(234, 179, 8, 0.8)","rgba(132, 204, 22, 0.8)","rgba(34, 197, 94, 0.8)","rgba(16, 185, 129, 0.8)","rgba(20, 184, 166, 0.8)","rgba(6, 182, 212, 0.8)","rgba(14, 165, 233, 0.8)","rgba(59, 130, 246, 0.8)","rgba(99, 102, 241, 0.8)","rgba(139, 92, 246, 0.8)","rgba(168, 85, 247, 0.8)","rgba(217, 70, 239, 0.8)","rgba(236, 72, 153, 0.8)","rgba(249, 168, 212, 0.8)","rgba(161, 161, 170, 0.8)"];function sEe(t,A,e,i={}){const n=i.padding??40,o=i.yFlip??!1;let s;if("center"in t){const c=t.width/2,I=t.height/2;s={minX:t.center.x-c,maxX:t.center.x+c,minY:t.center.y-I,maxY:t.center.y+I}}else s=t;const r=s.maxX-s.minX||1,a=s.maxY-s.minY||1,g=Math.min((A-2*n)/r,(e-2*n)/a);return An(on(A/2,e/2),$a(g,o?-g:g),on(-(s.minX+r/2),-(s.minY+a/2)))}function oti(t){const A=[...t.points||[],...(t.lines||[]).flatMap(e=>e.points),...(t.rects||[]).flatMap(e=>{const i=e.width/2,n=e.height/2;return[{x:e.center.x-i,y:e.center.y-n},{x:e.center.x+i,y:e.center.y-n},{x:e.center.x-i,y:e.center.y+n},{x:e.center.x+i,y:e.center.y+n}]}),...(t.circles||[]).flatMap(e=>[{x:e.center.x-e.radius,y:e.center.y},{x:e.center.x+e.radius,y:e.center.y},{x:e.center.x,y:e.center.y-e.radius},{x:e.center.x,y:e.center.y+e.radius}]),...(t.texts||[]).flatMap(e=>{const i=e.fontSize??12,n=e.text.length*i*iti,o=i*nti,s=e.anchorSide??"center",r={top_left:{dx:0,dy:0},top_center:{dx:-n/2,dy:0},top_right:{dx:-n,dy:0},center_left:{dx:0,dy:-o/2},center:{dx:-n/2,dy:-o/2},center_right:{dx:-n,dy:-o/2},bottom_left:{dx:0,dy:-o},bottom_center:{dx:-n/2,dy:-o},bottom_right:{dx:-n,dy:-o}},{dx:a,dy:g}=r[s],c=e.x+a,I=e.y+g;return[{x:c,y:I},{x:c+n,y:I+o}]})];return A.length===0?{minX:-1,maxX:1,minY:-1,maxY:1}:A.reduce((e,i)=>({minX:Math.min(e.minX,i.x),maxX:Math.max(e.maxX,i.x),minY:Math.min(e.minY,i.y),maxY:Math.max(e.maxY,i.y)}),{minX:1/0,maxX:-1/0,minY:1/0,maxY:-1/0})}function sti(t,A,e={}){const i=A instanceof HTMLCanvasElement?A.getContext("2d"):A;if(!i)throw new Error("Could not get 2D context from canvas");const n=A instanceof HTMLCanvasElement?A.width:A.canvas.width,o=A instanceof HTMLCanvasElement?A.height:A.canvas.height;let s;if(e.transform)s=e.transform;else if(e.viewbox)s=sEe(e.viewbox,n,o,{padding:e.padding,yFlip:e.yFlip});else{const r=oti(t),a=t.coordinateSystem==="cartesian";s=sEe(r,n,o,{padding:e.padding??40,yFlip:a})}i.clearRect(0,0,n,o),i.save(),t.rects&&t.rects.length>0&&t.rects.forEach(r=>{const a=r.width/2,g=r.height/2,c=Ce(s,{x:r.center.x-a,y:r.center.y-g}),I=Ce(s,{x:r.center.x+a,y:r.center.y+g}),l=Math.abs(I.x-c.x),B=Math.abs(I.y-c.y);i.beginPath(),i.rect(Math.min(c.x,I.x),Math.min(c.y,I.y),l,B),r.fill&&(i.fillStyle=r.fill,i.fill()),r.stroke&&(i.strokeStyle=r.stroke,i.stroke())}),t.circles&&t.circles.length>0&&t.circles.forEach(r=>{const a=Ce(s,r.center),g=r.radius*Math.abs(s.a);i.beginPath(),i.arc(a.x,a.y,g,0,2*Math.PI),r.fill&&(i.fillStyle=r.fill,i.fill()),r.stroke&&(i.strokeStyle=r.stroke??"transparent",i.stroke())}),t.lines&&t.lines.length>0&&t.lines.forEach((r,a)=>{if(r.points.length===0)return;i.beginPath();const g=Ce(s,r.points[0]);i.moveTo(g.x,g.y);for(let c=1;c<r.points.length;c++){const I=Ce(s,r.points[c]);i.lineTo(I.x,I.y)}if(i.strokeStyle=r.strokeColor||Mz[a%Mz.length],r.strokeWidth?i.lineWidth=r.strokeWidth*s.a:i.lineWidth=2,i.lineCap="round",r.strokeDash)if(typeof r.strokeDash=="string"){let c;if(r.strokeDash.includes(","))c=r.strokeDash.split(",").map(I=>parseFloat(I.trim())).filter(I=>!Number.isNaN(I));else{const I=parseFloat(r.strokeDash.trim());c=Number.isNaN(I)?[]:[I]}i.setLineDash(c)}else i.setLineDash(r.strokeDash.map(c=>c*Math.abs(s.a)));else i.setLineDash([]);i.stroke()}),t.points&&t.points.length>0&&t.points.forEach((r,a)=>{const g=Ce(s,r);i.beginPath(),i.arc(g.x,g.y,3,0,2*Math.PI),i.fillStyle=r.color||Mz[a%Mz.length],i.fill(),r.label&&!e.disableLabels&&(i.fillStyle=r.color||"black",i.font="12px sans-serif",i.fillText(r.label,g.x+5,g.y-5))}),t.texts&&t.texts.length>0&&t.texts.forEach(r=>{const a=Ce(s,{x:r.x,y:r.y});i.fillStyle=r.color||"black",i.font=`${(r.fontSize??12)*Math.abs(s.a)}px sans-serif`;const g=r.anchorSide??"center",c={top_left:"left",center_left:"left",bottom_left:"left",top_center:"center",center:"center",bottom_center:"center",top_right:"right",center_right:"right",bottom_right:"right"},I={top_left:"top",top_center:"top",top_right:"top",center_left:"middle",center:"middle",center_right:"middle",bottom_left:"bottom",bottom_center:"bottom",bottom_right:"bottom"};i.textAlign=c[g],i.textBaseline=I[g],i.fillText(r.text,a.x,a.y)}),i.restore()}var rti=({children:t,transform:A,debugGraphics:e})=>{const i=V.useRef(null),[n,{width:o,height:s}]=qT(),r=gl(a=>a.is_showing_autorouting);return V.useEffect(()=>{r&&i.current&&e&&o&&s&&(i.current.width=o,i.current.height=s,sti(e,i.current,{transform:A,disableLabels:!0}))},[e,A,o,s,r]),r?W.jsxs("div",{ref:n,style:{position:"relative",width:"100%",height:"100%"},children:[t,W.jsx("canvas",{ref:i,style:{position:"absolute",top:0,left:0,opacity:.5,zIndex:100,width:"100%",height:"100%",pointerEvents:"none"}})]}):t},ati=({children:t,transform:A=xa(),elements:e=[]})=>{const[i,{width:n,height:o}]=qT(),s=V.useRef(null);return V.useEffect(()=>{const r=s.current;if(!r||!n||!o)return;r.width=n,r.height=o;const a=r.getContext("2d");if(!a)return;a.clearRect(0,0,n,o);const g=e.filter(I=>I.type==="pcb_component"),c=e.filter(I=>I.type==="pcb_manual_edit_conflict_warning");a.strokeStyle=yn.board.drc_warning,a.lineWidth=2,c.forEach(I=>{const l=g.find(O=>O.pcb_component_id===I.pcb_component_id);if(!l)return;const{width:B,height:C,center:Q}=l,h=Ce(A,Q),E=B*Math.abs(A.a),u=C*Math.abs(A.d),d=.1*Math.abs(A.a),f=E+d*2,y=u+d*2,w=h.x-f/2,D=h.y-y/2;a.beginPath(),a.rect(w,D,f,y),a.stroke();const S="Manual Edit Conflict",_=4,b=Math.max(8,Math.min(12,10*Math.abs(A.a)));a.font=`${b}px sans-serif`;const F=a.measureText(S).width+_*2,L=b+_*2,Y=w+(f-F)/2,J=D+y+5;a.fillStyle="rgba(0, 0, 0, 0.7)",a.beginPath(),a.roundRect(Y,J,F,L,3),a.fill(),a.fillStyle=yn.board.drc_warning,a.textAlign="center",a.textBaseline="middle",a.fillText(S,Y+F/2,J+L/2)})},[e,A,n,o]),W.jsxs("div",{ref:i,style:{position:"relative",width:"100%",height:"100%"},children:[t,W.jsx("canvas",{ref:s,style:{position:"absolute",top:0,left:0,pointerEvents:"none",zIndex:kc.warnings}})]})},Rz=(t,A,e)=>e(t,A),rEe=(t,A,e,i,n)=>{const o=n*Math.PI/180,s=Math.cos(o),r=Math.sin(o),a=t-e,g=A-i,c=a*s-g*r,I=a*r+g*s;return{x:c+e,y:I+i}},OT=t=>{if(t.length===0)return null;let A=t[0].x,e=t[0].x,i=t[0].y,n=t[0].y;for(const o of t)A=Rz(A,o.x,Math.min),e=Rz(e,o.x,Math.max),i=Rz(i,o.y,Math.min),n=Rz(n,o.y,Math.max);return{minX:A,maxX:e,minY:i,maxY:n}},gti=(t,A)=>({minX:Math.min(t.minX,A.minX),maxX:Math.max(t.maxX,A.maxX),minY:Math.min(t.minY,A.minY),maxY:Math.max(t.maxY,A.maxY)}),cti=(t,A)=>t?gti(t,A):A,Iti=t=>{switch(t.pcb_drawing_type){case"line":{const A=(t.width??0)/2,e=[{x:t.x1,y:t.y1},{x:t.x2,y:t.y2}],i=OT(e);return i?{minX:i.minX-A,maxX:i.maxX+A,minY:i.minY-A,maxY:i.maxY+A}:null}case"rect":{const A=t.w/2,e=t.h/2,i=[{x:t.x-A,y:t.y-e},{x:t.x+A,y:t.y-e},{x:t.x+A,y:t.y+e},{x:t.x-A,y:t.y+e}],n=t.ccw_rotation??0,o=n===0?i:i.map(s=>rEe(s.x,s.y,t.x,t.y,n));return OT(o)}case"circle":return{minX:t.x-t.r,maxX:t.x+t.r,minY:t.y-t.r,maxY:t.y+t.r};case"oval":return{minX:t.x-t.rX,maxX:t.x+t.rX,minY:t.y-t.rY,maxY:t.y+t.rY};case"pill":{const A=t.w/2,e=t.h/2,i=[{x:t.x-A,y:t.y-e},{x:t.x+A,y:t.y-e},{x:t.x+A,y:t.y+e},{x:t.x-A,y:t.y+e}],n=t.ccw_rotation??0,o=n===0?i:i.map(s=>rEe(s.x,s.y,t.x,t.y,n));return OT(o)}case"polygon":return OT(t.points);case"polygon_with_arcs":{const A=t.brep_shape.outer_ring.vertices.map(e=>({x:e.x,y:e.y}));return OT(A)}case"text":{const A=t.size??0,e=t.text?t.text.length*A*.6:0,i=A;if(e===0&&i===0)return{minX:t.x,maxX:t.x,minY:t.y,maxY:t.y};const n=e/2,o=i/2;return{minX:t.x-n,maxX:t.x+n,minY:t.y-o,maxY:t.y+o}}default:return null}};function lti(t){const{dimensionStart:A,dimensionEnd:e,screenDimensionStart:i,screenDimensionEnd:n,flipX:o,flipY:s}=t,r=e.x-A.x,a=e.y-A.y,g=Math.sqrt(r*r+a*a),c=n.x-i.x,I=n.y-i.y,l=Math.sqrt(c*c+I*I),B=Math.atan2(I,c)*(180/Math.PI),C=Math.abs(B)%90,h=Math.min(C,90-C)>15,E=(i.x+n.x)/2,u=(i.y+n.y)/2,d=15,f=B+90;let y=Math.cos(f*Math.PI/180)*d,w=Math.sin(f*Math.PI/180)*d;const D=c>0&&I<0,S=c>0&&I>0,_=c<0&&I>0;o!==s&&!D&&(y=-y,w=-w),D&&(y+=Math.cos(f*Math.PI/180)*-45,w+=Math.sin(f*Math.PI/180)*-45),S&&(y+=Math.cos(f*Math.PI/180)+-20,w+=Math.sin(f*Math.PI/180)+-10),_&&(y+=Math.cos(f*Math.PI/180)*10,w+=Math.sin(f*Math.PI/180)*10);const b=E+y,N=u+w;return{distance:g,screenDistance:l,x:b,y:N,show:g>.01&&l>30&&h}}function Bti(t){const{dimensionStart:A,dimensionEnd:e,screenDimensionStart:i,screenDimensionEnd:n,flipX:o,flipY:s}=t;return V.useMemo(()=>lti({dimensionStart:A,dimensionEnd:e,screenDimensionStart:i,screenDimensionEnd:n,flipX:o,flipY:s}),[A,e,i,n,o,s])}var Cti=(t,A,e)=>{const i=e*Math.PI/180,n=Math.cos(i),o=Math.sin(i),s=t.x-A.x,r=t.y-A.y,a=s*n-r*o,g=s*o+r*n;return{x:a+A.x,y:g+A.y}},aEe=(t,A,e,i)=>{const n={top_left:{x:t.x-A,y:t.y-e},top_center:{x:t.x,y:t.y-e},top_right:{x:t.x+A,y:t.y-e},center_left:{x:t.x-A,y:t.y},center:{x:t.x,y:t.y},center_right:{x:t.x+A,y:t.y},bottom_left:{x:t.x-A,y:t.y+e},bottom_center:{x:t.x,y:t.y+e},bottom_right:{x:t.x+A,y:t.y+e}};return i===0?Object.entries(n).map(([o,s])=>({anchor:o,point:s})):Object.entries(n).map(([o,s])=>({anchor:o,point:Cti(s,t,i)}))},Qti=t=>{switch(t.pcb_drawing_type){case"rect":{const A=t.ccw_rotation??0;return aEe({x:t.x,y:t.y},t.w/2,t.h/2,A)}case"pill":{const A=t.ccw_rotation??0;return aEe({x:t.x,y:t.y},t.w/2,t.h/2,A)}case"circle":return[{anchor:"circle_center",point:{x:t.x,y:t.y}},{anchor:"circle_right",point:{x:t.x+t.r,y:t.y}},{anchor:"circle_left",point:{x:t.x-t.r,y:t.y}},{anchor:"circle_top",point:{x:t.x,y:t.y-t.r}},{anchor:"circle_bottom",point:{x:t.x,y:t.y+t.r}}];case"oval":return[{anchor:"oval_center",point:{x:t.x,y:t.y}},{anchor:"oval_right",point:{x:t.x+t.rX,y:t.y}},{anchor:"oval_left",point:{x:t.x-t.rX,y:t.y}},{anchor:"oval_top",point:{x:t.x,y:t.y-t.rY}},{anchor:"oval_bottom",point:{x:t.x,y:t.y+t.rY}}];case"line":{const A={x:(t.x1+t.x2)/2,y:(t.y1+t.y2)/2};return[{anchor:"line_start",point:{x:t.x1,y:t.y1}},{anchor:"line_mid",point:A},{anchor:"line_end",point:{x:t.x2,y:t.y2}}]}case"polygon":return t.points.map((A,e)=>({anchor:`polygon_vertex_${e}`,point:A}));case"polygon_with_arcs":return t.brep_shape.outer_ring.vertices.map((A,e)=>({anchor:`polygon_with_arcs_vertex_${e}`,point:{x:A.x,y:A.y}}));default:return[]}},hti=16,UM=5,gEe=t=>{if(t.pcb_drawing_type==="text")return!0;const A=t._element;if(!A||typeof A!="object")return!1;const e=typeof A.type=="string"?A.type:void 0;return e?!!(e.startsWith("pcb_silkscreen_")||e.startsWith("pcb_note_")||e==="pcb_text"||e.startsWith("pcb_fabrication_note_")&&e!=="pcb_fabrication_note_rect"):!1},Eti=({children:t,transform:A,focusOnHover:e=!1,primitives:i=[]})=>{A||(A=xa());const[n,o]=V.useState(!1),[s,r]=V.useState(!1),[a,g]=V.useState(!1),[c,I]=V.useState({start:null,end:null}),l=gl(J=>J.is_mouse_over_container),B=V.useCallback(()=>{a&&(g(!1),window.dispatchEvent(new Event("disarm-dimension-tool")))},[a]),[C,Q]=V.useState({x:0,y:0}),[h,E]=V.useState({x:0,y:0}),u=V.useRef({x:0,y:0}),d=V.useRef(null),y=d.current?.getBoundingClientRect(),w=V.useMemo(()=>{const J=new Map;for(const O of i){if(!O._element||gEe(O)||O.pcb_drawing_type==="pill"||O.pcb_drawing_type==="rect"&&O.ccw_rotation&&O.ccw_rotation!==0)continue;const Z=Iti(O);if(!Z)continue;const X=J.get(O._element);J.set(O._element,cti(X??void 0,Z))}return J},[i]),D=V.useMemo(()=>{const J=[];for(const O of i){if(!O._element||gEe(O))continue;const Z=Qti(O);if(Z.length!==0)for(const X of Z)J.push({anchor:X.anchor,point:X.point,element:O._element})}return J},[i]),S=V.useMemo(()=>{const J=[];w.forEach((O,Z)=>{if(!O)return;const X=(O.minX+O.maxX)/2,eA=(O.minY+O.maxY)/2,gA={top_left:{x:O.minX,y:O.minY},top_center:{x:X,y:O.minY},top_right:{x:O.maxX,y:O.minY},center_left:{x:O.minX,y:eA},center:{x:X,y:eA},center_right:{x:O.maxX,y:eA},bottom_left:{x:O.minX,y:O.maxY},bottom_center:{x:X,y:O.maxY},bottom_right:{x:O.maxX,y:O.maxY}};for(const[tA,iA]of Object.entries(gA))J.push({anchor:tA,point:iA,element:Z})});for(const O of D)J.push(O);return J.push({anchor:"origin",point:{x:0,y:0},element:null}),J},[w,D]),_=V.useMemo(()=>S.map((J,O)=>({...J,id:`${O}-${J.anchor}`,screenPoint:Ce(A,J.point)})),[S,A]),b=V.useCallback(J=>{if(_.length===0)return{point:J,id:null};const O=Ce(A,J);let Z=null;for(const X of _){const eA=X.screenPoint.x-O.x,gA=X.screenPoint.y-O.y,tA=Math.hypot(eA,gA);tA>hti||(!Z||tA<Z.distance)&&(Z={distance:tA,id:X.id,point:X.point})}return Z?{point:Z.point,id:Z.id}:{point:J,id:null}},[_,A]);V.useEffect(()=>{const J=Z=>{const X=Z.target;if(X.tagName==="INPUT"||X.tagName==="TEXTAREA"||X.isContentEditable)return;const eA=d.current?.contains(document.activeElement)||document.activeElement===d.current;if(!(!l&&!eA)){if(Z.key==="d"){const gA=b({x:u.current.x,y:u.current.y});Q({x:gA.point.x,y:gA.point.y}),E({x:gA.point.x,y:gA.point.y}),I({start:gA.id,end:gA.id}),n?(o(!1),r(!1),I({start:null,end:null})):(o(!0),r(!0)),B()}Z.key==="Escape"&&(o(!1),r(!1),I({start:null,end:null}),B())}},O=()=>{g(!0)};return window.addEventListener("keydown",J),window.addEventListener("arm-dimension-tool",O),()=>{window.removeEventListener("keydown",J),window.removeEventListener("arm-dimension-tool",O),B()}},[l,n,B,b]);const N=Ce(A,C),F=Ce(A,h),L={left:Math.min(N.x,F.x),right:Math.max(N.x,F.x),top:Math.min(N.y,F.y),bottom:Math.max(N.y,F.y),flipX:N.x>F.x,flipY:N.y>F.y,width:0,height:0};L.width=L.right-L.left,L.height=L.bottom-L.top;const Y=Bti({dimensionStart:C,dimensionEnd:h,screenDimensionStart:N,screenDimensionEnd:F,flipX:L.flipX,flipY:L.flipY});return W.jsxs("div",{ref:d,"data-pcb-viewer":!0,tabIndex:0,style:{position:"relative",outline:"none"},onMouseEnter:()=>{e&&d.current&&d.current.focus()},onMouseLeave:()=>{d.current&&d.current.blur()},onClick:()=>{d.current&&d.current.focus()},onMouseMove:J=>{const O=J.currentTarget.getBoundingClientRect(),Z=J.clientX-O.left,X=J.clientY-O.top,eA=Ce(tm(A),{x:Z,y:X});if(u.current.x=eA.x,u.current.y=eA.y,s){const gA=b(eA);E({x:gA.point.x,y:gA.point.y}),I(tA=>({...tA,end:gA.id}))}},onMouseDown:J=>{const O=J.currentTarget.getBoundingClientRect(),Z=J.clientX-O.left,X=J.clientY-O.top,eA=Ce(tm(A),{x:Z,y:X});if(a&&!n){const gA=b(eA);Q({x:gA.point.x,y:gA.point.y}),E({x:gA.point.x,y:gA.point.y}),I({start:gA.id,end:gA.id}),o(!0),r(!0),B()}else s?(r(!1),I(gA=>({...gA,end:null}))):n&&(o(!1),I({start:null,end:null}))},children:[t,n&&W.jsxs(W.Fragment,{children:[Y.show&&W.jsx("div",{style:{position:"absolute",left:Y.x,top:Y.y,color:"red",mixBlendMode:"difference",pointerEvents:"none",fontSize:12,fontFamily:"sans-serif",whiteSpace:"nowrap",zIndex:kc.dimensionOverlay},children:Y.distance.toFixed(2)}),W.jsx("div",{style:{position:"absolute",left:L.left,width:L.width,textAlign:"center",top:N.y+2,color:"red",mixBlendMode:"difference",pointerEvents:"none",marginTop:L.flipY?0:-20,fontSize:12,fontFamily:"sans-serif",zIndex:kc.dimensionOverlay},children:Math.abs(C.x-h.x).toFixed(2)}),W.jsx("div",{style:{position:"absolute",left:F.x,height:L.height,display:"flex",flexDirection:"column",justifyContent:"center",top:L.top,color:"red",pointerEvents:"none",mixBlendMode:"difference",fontSize:12,fontFamily:"sans-serif",zIndex:kc.dimensionOverlay},children:W.jsx("div",{style:{marginLeft:L.flipX?"-100%":4,paddingRight:4},children:Math.abs(C.y-h.y).toFixed(2)})}),W.jsxs("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none",mixBlendMode:"difference",zIndex:kc.dimensionOverlay},width:y.width,height:y.height,children:[W.jsx("defs",{children:W.jsx("marker",{id:"head",orient:"auto",markerWidth:"3",markerHeight:"4",refX:"2",refY:"2",children:W.jsx("path",{d:"M0,0 V4 L2,2 Z",fill:"red"})})}),W.jsx("line",{x1:N.x,y1:N.y,x2:F.x,y2:F.y,markerEnd:"url(#head)",strokeWidth:1.5,fill:"none",stroke:"red"}),W.jsx("line",{x1:N.x,y1:N.y,x2:F.x,y2:N.y,strokeWidth:1.5,fill:"none",strokeDasharray:"2,2",stroke:"red"}),W.jsx("line",{x1:F.x,y1:N.y,x2:F.x,y2:F.y,strokeWidth:1.5,fill:"none",strokeDasharray:"2,2",stroke:"red"})]}),s&&_.map(J=>{const O=J.id===c.start||J.id===c.end,Z=UM/2;return W.jsxs("svg",{width:UM,height:UM,style:{position:"absolute",left:J.screenPoint.x-Z,top:J.screenPoint.y-Z,pointerEvents:"none",zIndex:kc.dimensionOverlay},children:[W.jsx("line",{x1:0,y1:0,x2:UM,y2:UM,stroke:O?"#66ccff":"white",strokeWidth:1}),W.jsx("line",{x1:UM,y1:0,x2:0,y2:UM,stroke:O?"#66ccff":"white",strokeWidth:1})]},J.id)}),W.jsxs("div",{style:{right:0,bottom:0,position:"absolute",color:"red",fontFamily:"sans-serif",fontSize:12,margin:4},children:["(",C.x.toFixed(2),",",C.y.toFixed(2),")",W.jsx("br",{}),"(",h.x.toFixed(2),",",h.y.toFixed(2),")",W.jsx("br",{}),"dist:"," ",Math.sqrt((h.x-C.x)**2+(h.y-C.y)**2).toFixed(2)]})]})]})},uti=(t,A,e=0)=>{const i=t.width/2,n=t.height/2,o=t.center.x-i-e,s=t.center.x+i+e,r=t.center.y-n-e,a=t.center.y+n+e;return A.x>o&&A.x<s&&A.y>r&&A.y<a},dti=({children:t,disabled:A,transform:e,soup:i,cancelPanDrag:n,onCreateEditEvent:o,onModifyEditEvent:s})=>{e||(e=xa());const r=V.useRef(null),[a,g]=V.useState(null),[c,I]=V.useState(null),l=a!==null;gl(h=>h.in_edit_mode);const B=gl(h=>h.in_move_footprint_mode),C=gl(h=>h.setIsMovingComponent),Q=A||!B;return W.jsxs("div",{ref:r,style:{position:"relative",overflow:"hidden"},onMouseDown:h=>{if(Q)return;const E=h.currentTarget.getBoundingClientRect(),u=h.clientX-E.left,d=h.clientY-E.top;if(Number.isNaN(u)||Number.isNaN(d))return;const f=Ce(tm(e),{x:u,y:d});let y=!1;for(const w of i)if(w.type==="pcb_component"&&uti(w,f,10/e.a)){n(),g(w.pcb_component_id),y=!0;const D=Math.random().toString();I({dragStart:f,originalCenter:w.center,dragEnd:f,edit_event_id:D}),o({edit_event_id:D,edit_event_type:"edit_pcb_component_location",pcb_edit_event_type:"edit_component_location",pcb_component_id:w.pcb_component_id,original_center:w.center,new_center:w.center,in_progress:!0,created_at:Date.now()}),C(!0);break}if(y||g(null),y)return h.preventDefault(),!1},onMouseMove:h=>{if(!a||!c)return;const E=h.currentTarget.getBoundingClientRect(),u=h.clientX-E.left,d=h.clientY-E.top;if(Number.isNaN(u)||Number.isNaN(d))return;const f=Ce(tm(e),{x:u,y:d});I({...c,dragEnd:f}),s({edit_event_id:c.edit_event_id,new_center:{x:c.originalCenter.x+f.x-c.dragStart.x,y:c.originalCenter.y+f.y-c.dragStart.y}})},onMouseUp:h=>{a&&(g(null),C(!1),c&&(s({edit_event_id:c.edit_event_id,in_progress:!1}),I(null)))},children:[t,!Q&&i.filter(h=>h.type==="pcb_component").map(h=>{if(!h?.center)return null;const E=Ce(e,h.center);return W.jsx("div",{style:{position:"absolute",pointerEvents:"none",left:E.x,top:E.y,width:h.width*e.a+20,height:h.height*e.a+20,transform:"translate(-50%, -50%)",background:l&&a===h.pcb_component_id?"rgba(255, 0, 0, 0.2)":""}},h.pcb_component_id)})]})},pti=({hotkeys:t})=>(V.useEffect(()=>{const A=e=>{t.forEach(i=>{e.key===i.key&&i.onUse()})};return window.addEventListener("keydown",A),()=>{window.removeEventListener("keydown",A)}},[t]),W.jsx("div",{className:D2`
5437
5437
  display: flex;
5438
5438
  flex-direction: column;
5439
5439
  font-family: sans-serif;
@@ -5472,7 +5472,7 @@ $1`).replace(/>(\s*)(?=<!--\s*\/)/g,"> ")}}});function Nhe(t,A,e){if(!A||!e)retu
5472
5472
  transition: opacity 0.2s;
5473
5473
  margin-bottom: 10px;
5474
5474
  color: red;
5475
- `,Sti=({children:t,transform:A=xa(),elements:e})=>{const i=V.useRef(null),{isShowingDRCErrors:n,hoveredErrorId:o}=gl(g=>({isShowingDRCErrors:g.is_showing_drc_errors,hoveredErrorId:g.hovered_error_id}));if(!e)return W.jsx("div",{style:{position:"relative"},ref:i,children:t});const s=e.filter(g=>g.type==="pcb_trace_error"),r=e.filter(g=>g.type==="pcb_trace_error"&&g.message?.includes("Multiple components found with name")),a=new Map;return e.forEach(g=>{g.type==="pcb_port"&&a.set(g.pcb_port_id,g)}),W.jsxs("div",{style:{position:"relative"},ref:i,children:[t,s.map((g,c)=>{const{pcb_port_ids:I,pcb_trace_id:l}=g,B=I?.[0]?a.get(I[0]):void 0,C=I?.[1]?a.get(I[1]):void 0,Q=e?rx(e).pcb_trace.get(l):void 0,h=g.pcb_trace_error_id||`error_${c}_${g.error_type}_${g.message?.slice(0,20)}`,E=o===h;if(B&&C){const u=Ce(A,{x:B.x,y:B.y}),d=Ce(A,{x:C.x,y:C.y});if(!n)return null;const f=!(isNaN(u.x)||isNaN(u.y)||isNaN(d.x)||isNaN(d.y)),y={x:(u.x+d.x)/2,y:(u.y+d.y)/2};if(isNaN(y.x)||isNaN(y.y))return null;const w=ymA(y,i);return W.jsxs(V.Fragment,{children:[W.jsx(wti,{screenPort1:u,screenPort2:d,errorCenter:y,canLineBeDrawn:f,isHighlighted:E}),W.jsx("div",{style:{position:"absolute",left:y.x-15,top:y.y-15,width:30,height:30,zIndex:kc.errorOverlay+5,cursor:"pointer",borderRadius:"50%"},onMouseEnter:D=>{const S=D.currentTarget.nextElementSibling;if(S){const _=S.querySelector(".error-message");_&&(_.style.opacity="1")}},onMouseLeave:D=>{if(!E){const S=D.currentTarget.nextElementSibling;if(S){const _=S.querySelector(".error-message");_&&(_.style.opacity="0")}}}}),W.jsx("div",{style:{position:"absolute",zIndex:E?200:100,left:w.left,top:w.top,color:E?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:n||E?"flex":"none",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:w.transform},children:W.jsx("div",{className:`error-message ${mmA}`,style:{opacity:E?1:0,border:`1px solid ${E?"#ff4444":"red"}`},children:g.message})})]},h)}if(Q?.route&&(n||E)){const u=Q.route.map(w=>Ce(A,{x:w.x,y:w.y}));if(u.some(w=>isNaN(w.x)||isNaN(w.y)))return null;const d=Math.floor(u.length/2),f=u[d],y=ymA(f,i);return W.jsxs(V.Fragment,{children:[W.jsx(Dti,{points:u,errorCenter:f,isHighlighted:E}),W.jsx("div",{style:{position:"absolute",left:f.x-15,top:f.y-15,width:30,height:30,zIndex:kc.errorOverlay+5,cursor:"pointer",borderRadius:"50%"},onMouseEnter:w=>{const D=w.currentTarget.nextElementSibling;if(D){const S=D.querySelector(".error-message");S&&(S.style.opacity="1")}},onMouseLeave:w=>{if(!E){const D=w.currentTarget.nextElementSibling;if(D){const S=D.querySelector(".error-message");S&&(S.style.opacity="0")}}}}),W.jsx("div",{style:{position:"absolute",zIndex:E?kc.errorOverlay+10:kc.errorOverlay+1,left:y.left,top:y.top,color:E?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:"flex",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:y.transform},children:W.jsx("div",{className:`error-message ${mmA}`,style:{opacity:E?1:0,border:`1px solid ${E?"#ff4444":"red"}`},children:g.message})})]},h)}return null}),r.map((g,c)=>{const I=g.component_name||g.message?.match(/name "([^"]+)"/)?.[1];if(!I)return null;const l=e?.filter(Q=>Q.type==="source_component"&&Q.name===I||Q.type==="pcb_component"&&e?.find(h=>h.type==="source_component"&&h.source_component_id===Q.source_component_id&&h.name===I))||[],B=g.pcb_trace_error_id||`error_${c}_${g.error_type}_${g.message?.slice(0,20)}`,C=o===B;return!C&&!n?null:l.map((Q,h)=>{let E={x:0,y:0};if(Q.type==="pcb_component")E=Q.center||{x:0,y:0};else if(Q.type==="source_component"){const _=e?.find(b=>b.type==="pcb_component"&&b.source_component_id===Q.source_component_id);_&&_.type==="pcb_component"&&(E=_.center||{x:0,y:0})}const u=Ce(A,E);if(isNaN(u.x)||isNaN(u.y))return null;const d=Math.abs(A.a),D=Math.max(8,Math.min(30,.5*d)),S=ymA(u,i);return W.jsxs(V.Fragment,{children:[W.jsx("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none",mixBlendMode:"difference",zIndex:kc.errorOverlay},width:"100%",height:"100%",children:C?W.jsx("polygon",{points:`${u.x},${u.y-D*1.25} ${u.x+D},${u.y} ${u.x},${u.y+D*1.25} ${u.x-D},${u.y}`,fill:"#ff4444"}):W.jsx("circle",{cx:u.x,cy:u.y,r:D,fill:"none",stroke:C?"#ff4444":"red",strokeWidth:C?Math.max(2,D*.15):Math.max(1,D*.1),opacity:1})}),W.jsx("div",{style:{position:"absolute",left:u.x-(D+10),top:u.y-(D+10),width:(D+10)*2,height:(D+10)*2,zIndex:kc.errorOverlay+5,cursor:"pointer",borderRadius:"50%"},onMouseEnter:_=>{const b=_.currentTarget.nextElementSibling;if(b){const N=b.querySelector(".error-message");N&&(N.style.opacity="1")}},onMouseLeave:_=>{if(!C){const b=_.currentTarget.nextElementSibling;if(b){const N=b.querySelector(".error-message");N&&(N.style.opacity="0")}}}}),W.jsx("div",{style:{position:"absolute",zIndex:C?kc.errorOverlay+20:kc.errorOverlay+10,left:S.left,top:S.top,color:C?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:n||C?"flex":"none",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:S.transform},children:W.jsx("div",{className:`error-message ${mmA}`,style:{opacity:C?1:0,border:`1px solid ${C?"#ff4444":"red"}`},children:g.message})})]},`${B}_${h}`)})})]})};function bti(t,A){return t.size!==A.size?!1:Array.from(t).every(e=>A.has(e))}function xti({primitiveElement:t,elements:A}){let e=t.trace_length?`${t.trace_length.toFixed(3)}`:"";const i=rx(A).source_trace.get(t?.source_trace_id);if(i?.display_name&&(i?.max_length?e+=` / ${i.max_length}mm `:e+=" mm ",e+=`(${i.display_name})`),!e)return null;const n=t.trace_length&&i?.max_length&&t.trace_length>i.max_length;return{text:e,isOverLength:n}}function _ti(t){const{primitives:A,is_showing_multiple_traces_length:e,elements:i}=t,n=A.filter(a=>a._element.type==="pcb_trace"),o=i.filter(a=>a.type==="source_trace"),s=A.filter(a=>a._element.type!=="pcb_trace"),r=n.filter(a=>o.some(g=>a._element.type==="pcb_trace"&&a._element.source_trace_id===g.source_trace_id&&g.max_length!==void 0));if(!e)return[...s,...r];if(n.length>1){const a=n.reduce((g,c)=>{const I=g._element.trace_length;return c._element.trace_length<I?c:g},n[0]);return[...s,a]}return A}var kti={position:"absolute",left:0,top:0,pointerEvents:"none",color:"red",fontFamily:"sans-serif",fontSize:12,textShadow:"0 0 2px black"},vti=t=>{const{_element:A,_parent_pcb_component:e,_parent_source_component:i,_source_port:n}=t;switch(A.type){case"pcb_trace":return A.trace_length?`${A.trace_length.toFixed(3)}`:"";case"pcb_smtpad":case"pcb_plated_hole":{const o=[],s=Array.from(new Set((A.port_hints??[]).concat(n?.port_hints??[]))).filter(a=>!/^[0-9]+$/.test(a)).filter(a=>!a.includes("unnamed_")).sort((a,g)=>g.localeCompare(a)),r=i&&"name"in i&&i.name&&!i.name.includes("unnamed_")?i.name:null;return s.length>0?r?o.push(...s.map(a=>`${r}.${a}`)):o.push(...s):r&&o.push(r),o.join(", ")}default:return""}},Fti={top:"red",bottom:"aqua"},Mti=({primitive:t,mousePos:A,elements:e})=>{const[i,n]=V.useState(!1),o=t._element;V.useEffect(()=>{setTimeout(()=>{n(!0)},100)},[]);const[s,r,a,g]=[t.screen_x,t.screen_y,t.screen_w,t.screen_h],c=t.same_space_index??0,I=26,l=Fti[t?._element?.layer]??"red";let B=0;if(o.type==="pcb_smtpad"&&o?.shape==="rotated_rect"?B=o?.ccw_rotation??0:(o.type==="pcb_smtpad"&&(o?.shape==="pill"||o?.shape==="rotated_pill")&&"ccw_rotation"in t||o.type==="pcb_plated_hole"&&(o?.shape==="pill"||o?.shape==="oval")&&"ccw_rotation"in t)&&(B=o.ccw_rotation??0),o.type==="pcb_trace"){const h=xti({primitiveElement:o,elements:e});if(!h)return null;const E=A.y-35;return W.jsx("div",{style:{zIndex:kc.elementOverlay,position:"absolute",left:A.x,top:E,color:l,pointerEvents:"none",transform:"translateX(-50%)"},children:W.jsx("div",{style:{backgroundColor:"#f2efcc",color:h.isOverLength?"red":"black",textShadow:"none",WebkitFontSmoothing:"antialiased",MozOsxFontSmoothing:"grayscale",padding:"6px 6px",borderRadius:"6px",fontSize:"14px",minWidth:"45px",textAlign:"center",whiteSpace:"nowrap"},children:h.text})})}const C=vti(t);return C.trim().length===0?null:W.jsx("div",{style:{zIndex:kc.elementOverlay,position:"absolute",left:s-a/2-8,top:r-g/2-8,width:a+16,height:g+16,color:l,transform:`rotate(${-B}deg)`,transformOrigin:"center center"},children:W.jsx("div",{style:{width:i?`calc(100% + ${I*2*c}px)`:"100%",height:i?`calc(100% + ${I*2*c}px)`:"100%",marginLeft:i?`${-I*c}px`:0,marginTop:i?`${-I*c}px`:0,border:`1px solid ${l}`,opacity:i||c===0?1:0,transition:"width 0.2s, height 0.2s, margin-left 0.2s, margin-top 0.2s, opacity 0.2s"},children:W.jsx("div",{style:{position:"absolute",bottom:g+20+I*c,marginRight:i?`${-I*c}px`:0,marginBottom:i?0:-I*c,transition:"margin-right 0.2s, margin-bottom 0.2s",backgroundColor:"#f2efcc",color:"black",textShadow:"none",WebkitFontSmoothing:"antialiased",MozOsxFontSmoothing:"grayscale",padding:"6px 6px",borderRadius:"6px",fontSize:"14px",transform:`rotate(${B}deg)`,minWidth:"45px",textAlign:"center"},children:C})})})},Rti=({highlightedPrimitives:t,mousePos:A,elements:e})=>{const[i,n]=gl(r=>[r.is_moving_component,r.is_showing_multiple_traces_length]),o=t.some(r=>r._element.type==="pcb_smtpad")&&t.some(r=>r._element.type==="pcb_trace");let s=t;return o&&(s=s.filter(r=>r._element.type==="pcb_smtpad")),s=_ti({primitives:s,is_showing_multiple_traces_length:n,elements:e}),W.jsx("div",{style:kti,children:!i&&s.map((r,a)=>W.jsx(Mti,{primitive:r,mousePos:A,elements:e},a))})},Tk=t=>t?.type==="pcb_component",cEe=t=>t?.type==="pcb_group",Nti=t=>t?.type==="pcb_panel",wmA=t=>t?.type==="pcb_board",aI={MIN_LINE_LENGTH_FOR_LABEL:40,LABEL_OFFSET_ABOVE:2,LABEL_OFFSET_BELOW:-18,LABEL_OFFSET_RIGHT:8,LABEL_OFFSET_LEFT:-120,Y_LABEL_MIN_WIDTH:110,LINE_STROKE_WIDTH:1.5,LINE_DASH_PATTERN:"4,4",COMPONENT_MARKER_RADIUS:3,LABEL_FONT_SIZE:11,ANCHOR_MARKER_SIZE:6,ANCHOR_MARKER_STROKE_WIDTH:1.5},ly={OFFSET_LINE:"white",COMPONENT_MARKER_FILL:"#66ccff",COMPONENT_MARKER_STROKE:"white",LABEL_TEXT:"white"},DmA=({targets:t,transform:A,containerWidth:e,containerHeight:i})=>{if(t.length===0)return null;const n={color:ly.LABEL_TEXT,mixBlendMode:"difference",pointerEvents:"none",fontSize:aI.LABEL_FONT_SIZE,fontFamily:"monospace",fontWeight:"bold"},o=new Map;return t.forEach(s=>{if(!o.has(s.anchor_id)){const r=Ce(A,s.anchor);o.set(s.anchor_id,r)}}),W.jsx("div",{style:{position:"absolute",left:0,top:0,width:e,height:i,overflow:"hidden",pointerEvents:"none",zIndex:kc.dimensionOverlay},children:W.jsxs("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none"},width:e,height:i,children:[t.map(s=>{const r=s.anchor,a=s.anchor_id,g=s.target,c=o.get(a),I=Ce(A,g),l=g.x-r.x,B=g.y-r.y,C=Math.abs(I.x-c.x),Q=Math.abs(I.y-c.y),h=I.y<c.y,E=I.x>c.x,u=h?aI.LABEL_OFFSET_ABOVE:aI.LABEL_OFFSET_BELOW,d=E?aI.LABEL_OFFSET_RIGHT:aI.LABEL_OFFSET_LEFT,f=C>aI.MIN_LINE_LENGTH_FOR_LABEL,y=Q>aI.MIN_LINE_LENGTH_FOR_LABEL,w=`${s.display_offset_x??l.toFixed(2)}mm`,D=`${s.display_offset_y??B.toFixed(2)}mm`;return W.jsxs("g",{children:[W.jsx("line",{x1:c.x,y1:c.y,x2:I.x,y2:c.y,stroke:ly.OFFSET_LINE,strokeWidth:aI.LINE_STROKE_WIDTH,strokeDasharray:aI.LINE_DASH_PATTERN}),W.jsx("line",{x1:I.x,y1:c.y,x2:I.x,y2:I.y,stroke:ly.OFFSET_LINE,strokeWidth:aI.LINE_STROKE_WIDTH,strokeDasharray:aI.LINE_DASH_PATTERN}),s.type==="component"||s.type==="board"?W.jsx("circle",{cx:I.x,cy:I.y,r:aI.COMPONENT_MARKER_RADIUS,fill:ly.COMPONENT_MARKER_FILL,stroke:ly.COMPONENT_MARKER_STROKE,strokeWidth:1}):W.jsxs(W.Fragment,{children:[W.jsx("line",{x1:I.x-aI.ANCHOR_MARKER_SIZE,y1:I.y,x2:I.x+aI.ANCHOR_MARKER_SIZE,y2:I.y,stroke:ly.OFFSET_LINE,strokeWidth:aI.ANCHOR_MARKER_STROKE_WIDTH}),W.jsx("line",{x1:I.x,y1:I.y-aI.ANCHOR_MARKER_SIZE,x2:I.x,y2:I.y+aI.ANCHOR_MARKER_SIZE,stroke:ly.OFFSET_LINE,strokeWidth:aI.ANCHOR_MARKER_STROKE_WIDTH})]}),f&&W.jsx("foreignObject",{x:Math.min(c.x,I.x),y:c.y+u,width:Math.abs(I.x-c.x),height:20,style:{overflow:"visible"},children:W.jsx("div",{style:{...n,textAlign:"center"},children:w})}),y&&W.jsx("foreignObject",{x:I.x+d,y:Math.min(c.y,I.y),width:aI.Y_LABEL_MIN_WIDTH,height:Math.abs(I.y-c.y),style:{overflow:"visible"},children:W.jsx("div",{style:{...n,display:"flex",alignItems:"center",justifyContent:E?"flex-start":"flex-end",whiteSpace:"nowrap",padding:"0 4px",height:"100%"},children:D})})]},s.id)}),Array.from(o.entries()).map(([s,r])=>W.jsxs("g",{children:[W.jsx("line",{x1:r.x-aI.ANCHOR_MARKER_SIZE,y1:r.y,x2:r.x+aI.ANCHOR_MARKER_SIZE,y2:r.y,stroke:ly.OFFSET_LINE,strokeWidth:aI.ANCHOR_MARKER_STROKE_WIDTH}),W.jsx("line",{x1:r.x,y1:r.y-aI.ANCHOR_MARKER_SIZE,x2:r.x,y2:r.y+aI.ANCHOR_MARKER_SIZE,stroke:ly.OFFSET_LINE,strokeWidth:aI.ANCHOR_MARKER_STROKE_WIDTH})]},`anchor-${s}`))]})})},Gti=({elements:t,highlightedPrimitives:A,transform:e,containerWidth:i,containerHeight:n})=>{const o=t.filter(E=>wmA(E)),s=t.filter(E=>Tk(E)),r=t.filter(E=>cEe(E)),a=A.map(E=>Tk(E._parent_pcb_component)?E._parent_pcb_component.pcb_component_id:Tk(E._element)?E._element.pcb_component_id:null).filter(E=>!!E),g=new Set;if(a.forEach(E=>{const u=s.find(d=>d.pcb_component_id===E);u?.pcb_group_id&&g.add(u.pcb_group_id)}),!gl(E=>E.is_showing_group_anchor_offsets)&&a.length===0)return null;const I=s.map(E=>{const u=E.positioned_relative_to_pcb_board_id;if(!u)return null;const d=o.find(f=>f.pcb_board_id===u);return d?{component:E,board:d,type:"component"}:null}).filter(E=>!!E),l=r.map(E=>{const u=E.positioned_relative_to_pcb_board_id;if(!u||!E.center)return null;const d=o.find(f=>f.pcb_board_id===u);return d?{group:E,board:d,type:"group"}:null}).filter(E=>!!E),B=[...I,...l];if(B.length===0)return null;const C=a.length===0,Q=B.filter(E=>E.type==="component"?C||a.includes(E.component.pcb_component_id):C||g.has(E.group.pcb_group_id));if(Q.length===0)return null;const h=Q.map(E=>E.type==="component"?{id:`${E.board.pcb_board_id}-${E.component.pcb_component_id}-${E.type}`,anchor:E.board.center,anchor_id:E.board.pcb_board_id,target:E.component.center,type:"component",display_offset_x:E.component.display_offset_x,display_offset_y:E.component.display_offset_y}:{id:`${E.board.pcb_board_id}-${E.group.pcb_group_id}-${E.type}`,anchor:E.board.center,anchor_id:E.board.pcb_board_id,target:{x:E.group.anchor_position?.x??E.group.center.x,y:E.group.anchor_position?.y??E.group.center.y},type:"group",display_offset_x:E.group.display_offset_x,display_offset_y:E.group.display_offset_y}).filter(E=>!!E);return W.jsx(DmA,{targets:h,transform:e,containerWidth:i,containerHeight:n})},Lti=({elements:t,highlightedPrimitives:A,transform:e,containerWidth:i,containerHeight:n})=>{const o=t.filter(E=>cEe(E)),s=t.filter(E=>Tk(E)),r=A.map(E=>Tk(E._parent_pcb_component)?E._parent_pcb_component.pcb_component_id:Tk(E._element)?E._element.pcb_component_id:null).filter(E=>!!E),a=(E,u)=>{if(u.has(E))return;u.add(E);const d=o.find(f=>f.pcb_group_id===E);d?.position_mode==="relative_to_group_anchor"&&d.positioned_relative_to_pcb_group_id&&a(d.positioned_relative_to_pcb_group_id,u)},g=new Set;if(r.forEach(E=>{const u=s.find(d=>d.pcb_component_id===E);u&&(u.position_mode==="relative_to_group_anchor"&&u.positioned_relative_to_pcb_group_id&&a(u.positioned_relative_to_pcb_group_id,g),u.pcb_group_id&&a(u.pcb_group_id,g))}),!gl(E=>E.is_showing_group_anchor_offsets)&&r.length===0)return null;const I=s.map(E=>{if(E.position_mode==="relative_to_group_anchor"&&E.positioned_relative_to_pcb_group_id){const u=o.find(d=>d.pcb_group_id===E.positioned_relative_to_pcb_group_id);return u&&u.anchor_position?{component:E,parentGroup:u,type:"component"}:null}if(E.pcb_group_id){const u=o.find(d=>d.pcb_group_id===E.pcb_group_id);return u&&u.anchor_position?{component:E,parentGroup:u,type:"component"}:null}return null}).filter(E=>!!E),l=o.map(E=>{if(E.position_mode==="relative_to_group_anchor"&&E.positioned_relative_to_pcb_group_id){const u=o.find(d=>d.pcb_group_id===E.positioned_relative_to_pcb_group_id);if(u&&u.anchor_position&&E.anchor_position)return{group:E,parentGroup:u,type:"group"}}return null}).filter(E=>!!E),B=[...I,...l];if(B.length===0)return null;const C=r.length===0,Q=B.filter(E=>E.type==="component"?C||r.includes(E.component.pcb_component_id):C||g.has(E.group.pcb_group_id)||g.has(E.parentGroup.pcb_group_id));if(Q.length===0)return null;const h=Q.map(E=>{const u=E.parentGroup.anchor_position;return u?E.type==="component"?E.component.center?{id:`${E.parentGroup.pcb_group_id}-${E.component.pcb_component_id}-${E.type}`,anchor:u,anchor_id:E.parentGroup.pcb_group_id,target:E.component.center,type:"component",display_offset_x:E.component.display_offset_x,display_offset_y:E.component.display_offset_y}:null:E.group.anchor_position?{id:`${E.parentGroup.pcb_group_id}-${E.group.pcb_group_id}-${E.type}`,anchor:u,anchor_id:E.parentGroup.pcb_group_id,target:E.group.anchor_position,type:"group",display_offset_x:E.group.display_offset_x,display_offset_y:E.group.display_offset_y}:null:null}).filter(E=>!!E);return W.jsx(DmA,{targets:h,transform:e,containerWidth:i,containerHeight:n})},Uti=(t,A)=>{const e=t.pcb_component_id,i=A.filter(n=>(n.type==="pcb_smtpad"||n.type==="pcb_plated_hole")&&n.pcb_component_id===e||n.type==="pcb_hole"&&n.pcb_component_id===e);return i.length===0?pmA([t]):pmA(i)},Hti=({elements:t,highlightedPrimitives:A,transform:e,containerWidth:i,containerHeight:n})=>{const o=new Map;for(const r of A)Tk(r._parent_pcb_component)&&o.set(r._parent_pcb_component.pcb_component_id,r._parent_pcb_component),Tk(r._element)&&o.set(r._element.pcb_component_id,r._element);if(o.size===0)return null;const s=[];for(const r of o.values()){const a=Uti(r,t);if(!a)continue;const g=r.positioned_relative_to_pcb_group_id??r.pcb_group_id,c=g?rx(t).pcb_group.get(g):null;s.push({component:r,bbox:a,group:c})}return s.length===0?null:W.jsx("div",{style:{position:"absolute",left:0,top:0,width:i,height:n,overflow:"hidden",pointerEvents:"none",zIndex:kc.dimensionOverlay},children:W.jsx("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none"},width:i,height:n,children:s.map(({component:r,bbox:a,group:g})=>{const c=Ce(e,{x:a.minX,y:a.maxY}),I=Ce(e,{x:a.maxX,y:a.minY}),l={x:Math.min(c.x,I.x),y:Math.min(c.y,I.y),width:Math.abs(I.x-c.x),height:Math.abs(I.y-c.y)},B=r.center??{x:(a.minX+a.maxX)/2,y:(a.minY+a.maxY)/2},C=Ce(e,B);return W.jsxs("g",{children:[W.jsx("rect",{x:l.x,y:l.y,width:l.width,height:l.height,fill:"none",stroke:"white",strokeWidth:1.5,strokeDasharray:"4,4"}),W.jsx("line",{x1:C.x-6,y1:C.y,x2:C.x+6,y2:C.y,stroke:ly.COMPONENT_MARKER_STROKE,strokeWidth:1.5}),W.jsx("line",{x1:C.x,y1:C.y-6,x2:C.x,y2:C.y+6,stroke:ly.COMPONENT_MARKER_STROKE,strokeWidth:1.5}),W.jsx("circle",{cx:C.x,cy:C.y,r:aI.COMPONENT_MARKER_RADIUS,fill:ly.COMPONENT_MARKER_FILL,stroke:ly.COMPONENT_MARKER_STROKE,strokeWidth:1})]},r.pcb_component_id)})})})},Yti=({elements:t,highlightedPrimitives:A,transform:e,containerWidth:i,containerHeight:n})=>{const o=t.filter(B=>Nti(B)),s=t.filter(B=>wmA(B)),r=A.map(B=>wmA(B._element)?B._element.pcb_board_id:null).filter(B=>!!B);if(!gl(B=>B.is_showing_group_anchor_offsets)&&r.length===0)return null;const g=s.map(B=>{const C=B.pcb_panel_id,Q=B.position_mode;if(!C||Q!=="relative_to_panel_anchor")return null;const h=o.find(E=>E.pcb_panel_id===C);return h?{board:B,panel:h,type:"board"}:null}).filter(B=>!!B);if(g.length===0)return null;const c=r.length===0,I=g.filter(B=>c||r.includes(B.board.pcb_board_id));if(I.length===0)return null;const l=I.map(B=>B.board.center?{id:`${B.panel.pcb_panel_id}-${B.board.pcb_board_id}-${B.type}`,anchor:B.panel.center,anchor_id:B.panel.pcb_panel_id,target:B.board.center,type:"board",display_offset_x:B.board.display_offset_x,display_offset_y:B.board.display_offset_y}:null).filter(B=>!!B);return W.jsx(DmA,{targets:l,transform:e,containerWidth:i,containerHeight:n})},Nz=t=>{if(t.length===0)return null;let A=t[0].x,e=t[0].y,i=t[0].x,n=t[0].y;for(const o of t)o.x<A&&(A=o.x),o.y<e&&(e=o.y),o.x>i&&(i=o.x),o.y>n&&(n=o.y);return{center:{x:(A+i)/2,y:(e+n)/2},width:i-A,height:n-e}},IEe=(t,A)=>{if(A.length<3)return!1;let e=!1;for(let i=0,n=A.length-1;i<A.length;n=i++){const o=A[i].x,s=A[i].y,r=A[n].x,a=A[n].y;s>t.y!=a>t.y&&t.x<(r-o)*(t.y-s)/(a-s||Number.EPSILON)+o&&(e=!e)}return e},Jti=(t,A,e)=>{const i=[];for(const n of t){if(!n._element)continue;if("x1"in n&&n._element?.type==="pcb_trace"){const r=HE({x:A.x,y:A.y},{x:n.x1,y:n.y1},{x:n.x2,y:n.y2}),a=n.width||.5,g=Math.max(a*25,2)/e.a;r<g&&i.push(n);continue}if(n.pcb_drawing_type==="polygon"){const r=n.points.map(g=>({x:Et.parse(g.x),y:Et.parse(g.y)})),a=Nz(r);if(!a||A.x<a.center.x-a.width/2||A.x>a.center.x+a.width/2||A.y<a.center.y-a.height/2||A.y>a.center.y+a.height/2)continue;IEe(A,r)&&i.push(n);continue}if(n.pcb_drawing_type==="polygon_with_arcs"){const r=n.brep_shape.outer_ring.vertices.map(g=>({x:Et.parse(g.x),y:Et.parse(g.y)})),a=Nz(r);if(!a||A.x<a.center.x-a.width/2||A.x>a.center.x+a.width/2||A.y<a.center.y-a.height/2||A.y>a.center.y+a.height/2)continue;IEe(A,r)&&i.push(n);continue}if(!("x"in n&&"y"in n))continue;let o=0,s=0;if("w"in n&&"h"in n)o=n.w,s=n.h;else if("r"in n)o=n.r*2,s=n.r*2;else if("rX"in n&&"rY"in n)o=n.rX*2,s=n.rY*2;else continue;Math.abs(n.x-A.x)<o/2&&Math.abs(n.y-A.y)<s/2&&i.push(n)}return i},Tti=({elements:t,children:A,transform:e,primitives:i,onMouseHoverOverPrimitives:n})=>{const[o,s]=V.useState([]),[r,a]=V.useState({x:0,y:0}),[g,{width:c,height:I}]=qT(),l=V.useMemo(()=>{const C=[];for(const Q of o){if(Q._element?.type==="pcb_via"||Q._element?.type==="pcb_component"||Q?.layer==="drill")continue;let h=null,E=0,u=0;if(Q.pcb_drawing_type==="polygon"){const w=Nz(Q.points);if(!w)continue;h=w.center,E=w.width,u=w.height}else if(Q.pcb_drawing_type==="polygon_with_arcs"){const w=Q.brep_shape.outer_ring.vertices.map(S=>({x:S.x,y:S.y})),D=Nz(w);if(!D)continue;h=D.center,E=D.width,u=D.height}else"x"in Q&&"y"in Q&&(h={x:Q.x,y:Q.y},E="w"in Q?Q.w:"r"in Q?Q.r*2:"rX"in Q&&"rY"in Q?Q.rX*2:0,u="h"in Q?Q.h:"r"in Q?Q.r*2:"rX"in Q&&"rY"in Q?Q.rY*2:0);if(!h)continue;const d=Ce(e,h),f={w:E*e.a,h:u*e.a},y=C.filter(w=>d.x===w.screen_x&&d.y===w.screen_y&&f.w===w.screen_w&&f.h===w.screen_h).length;C.push({...Q,x:h.x,y:h.y,w:E,h:u,screen_x:d.x,screen_y:d.y,screen_w:f.w,screen_h:f.h,same_space_index:y})}return C},[o,e]),B=(C,Q,h,E)=>{a({x:C,y:Q});const u=Ce(tm(h),{x:C,y:Q}),d=Jti(E,u,h);bti(new Set(d.map(f=>f._pcb_drawing_object_id)),new Set(o.map(f=>f._pcb_drawing_object_id)))||(s(d),n(d))};return W.jsxs("div",{ref:g,style:{position:"relative",width:"100%",height:"100%"},onMouseMove:C=>{if(e){const Q=C.currentTarget.getBoundingClientRect(),h=C.clientX-Q.left,E=C.clientY-Q.top;B(h,E,e,i)}},onTouchStart:C=>{if(e){const Q=C.touches[0],h=C.currentTarget.getBoundingClientRect(),E=Q.clientX-h.left,u=Q.clientY-h.top;B(E,u,e,i)}},children:[A,W.jsx(Rti,{elements:t,mousePos:r,highlightedPrimitives:l}),e&&W.jsxs(W.Fragment,{children:[W.jsx(Gti,{elements:t,highlightedPrimitives:l,transform:e,containerWidth:c,containerHeight:I}),W.jsx(Lti,{elements:t,highlightedPrimitives:l,transform:e,containerWidth:c,containerHeight:I}),W.jsx(Hti,{elements:t,highlightedPrimitives:l,transform:e,containerWidth:c,containerHeight:I}),W.jsx(Yti,{elements:t,highlightedPrimitives:l,transform:e,containerWidth:c,containerHeight:I})]})]})},lEe=["rgb(255, 100, 100)","rgb(100, 255, 100)","rgb(100, 100, 255)","rgb(255, 255, 100)","rgb(255, 100, 255)","rgb(100, 255, 255)","rgb(255, 150, 100)","rgb(150, 100, 255)","rgb(100, 255, 150)","rgb(255, 100, 150)"],Pti=({children:t,transform:A=xa(),elements:e=[],hoveredComponentIds:i=[]})=>{const[n,{width:o,height:s}]=qT(),r=V.useRef(null),{is_showing_pcb_groups:a,pcb_group_view_mode:g,is_showing_group_anchor_offsets:c}=gl(I=>({is_showing_pcb_groups:I.is_showing_pcb_groups,pcb_group_view_mode:I.pcb_group_view_mode,is_showing_group_anchor_offsets:I.is_showing_group_anchor_offsets}));return V.useEffect(()=>{const I=r.current;if(!I||!o||!s)return;I.width=o,I.height=s;const l=I.getContext("2d");if(!l||(l.clearRect(0,0,o,s),!a))return;const B=e.filter(w=>w.type==="pcb_group"),C=e.filter(w=>w.type==="pcb_component"),Q=e.filter(w=>w.type==="source_group"),h=new Map(Q.map(w=>[w.source_group_id,w])),E=B.filter(w=>{if(w.name?.toLowerCase().includes("subpanel"))return!1;if(g==="all")return!0;if(!w.source_group_id)return!1;const D=h.get(w.source_group_id);return D?D.was_automatically_named!==!0:!1}),u=new Map;Q.forEach(w=>{const D=w;if(D.parent_source_group_id){const S=u.get(D.parent_source_group_id)||[];S.push(w.source_group_id),u.set(D.parent_source_group_id,S)}});const d=w=>{const D=[],S=u.get(w)||[];for(const _ of S)D.push(_),D.push(...d(_));return D},f=w=>{const D=Q.find(S=>S.source_group_id===w);return D?.parent_source_group_id?1+f(D.parent_source_group_id):0},y=new Set;if(i.length>0)for(const w of C){if(!i.includes(w.pcb_component_id))continue;const D=w.positioned_relative_to_pcb_group_id??w.pcb_group_id;D&&y.add(D)}E.forEach((w,D)=>{let S=C.filter(JA=>JA.pcb_group_id===w.pcb_group_id);if(w.source_group_id){const JA=d(w.source_group_id),WA=B.filter(vA=>vA.source_group_id&&JA.includes(vA.source_group_id));for(const vA of WA){const wA=C.filter(RA=>RA.pcb_group_id===vA.pcb_group_id);S=[...S,...wA]}}let _,b,N,F,L=!1;if(w.center&&w.width&&w.height){L=!0;const JA=w.width/2,WA=w.height/2;_=w.center.x-JA,N=w.center.x+JA,b=w.center.y-WA,F=w.center.y+WA}else if(S.length===0||(_=1/0,b=1/0,N=-1/0,F=-1/0,S.forEach(JA=>{if(JA.center&&typeof JA.width=="number"&&typeof JA.height=="number"){const WA=JA.center.x-JA.width/2,vA=JA.center.x+JA.width/2,wA=JA.center.y+JA.height/2,RA=JA.center.y-JA.height/2;_=Math.min(_,WA),N=Math.max(N,vA),b=Math.min(b,RA),F=Math.max(F,wA)}}),_===1/0||N===-1/0))return;const Y=w.source_group_id?f(w.source_group_id):0,J=w.source_group_id?d(w.source_group_id).length>0:!1;if(!L){const vA=1+(J?.5:0);_-=vA,N+=vA,b-=vA,F+=vA}const O=Ce(A,{x:_,y:F}),Z=Ce(A,{x:N,y:F}),X=Ce(A,{x:_,y:b}),eA=Ce(A,{x:N,y:b}),gA=lEe[D%lEe.length];l.strokeStyle=gA,l.lineWidth=2;const tA=Math.max(4,Math.min(12,8*Math.abs(A.a))),iA=Math.max(2,Math.min(6,4*Math.abs(A.a))),aA=tA*(J?1.3:1),EA=iA;l.setLineDash([aA,EA]),l.beginPath(),l.moveTo(O.x,O.y),l.lineTo(Z.x,Z.y),l.lineTo(eA.x,eA.y),l.lineTo(X.x,X.y),l.closePath(),l.stroke();const bA=Math.max(8,Math.min(12,10*Math.abs(A.a))),_A=Y==0||Y==1?0:Y*.11,LA=bA*(1-_A),QA=4,kA=w.name||`Group ${D+1}`;l.font=`${LA}px sans-serif`,l.setLineDash([]);const qA=l.measureText(kA).width+QA*2,VA=LA+QA*2,ce=O.x-5,fA=O.y-5,ge=3;if(l.fillStyle="rgba(0, 0, 0, 0.8)",l.beginPath(),l.roundRect(ce,fA-VA,qA,VA,ge),l.fill(),l.fillStyle=gA,l.textAlign="left",l.textBaseline="middle",l.fillText(kA,ce+QA,fA-VA/2),c&&y.has(w.pcb_group_id)&&!!w.anchor_position&&w.anchor_position){const JA=Array.isArray(w.anchor_position)?{x:w.anchor_position[0]??0,y:w.anchor_position[1]??0}:{x:w.anchor_position.x,y:w.anchor_position.y},WA=Ce(A,JA);l.strokeStyle="white",l.lineWidth=1.5,l.setLineDash([]);const vA=Math.max(4,Math.min(8,6*Math.abs(A.a)));l.beginPath(),l.moveTo(WA.x-vA,WA.y),l.lineTo(WA.x+vA,WA.y),l.stroke(),l.beginPath(),l.moveTo(WA.x,WA.y-vA),l.lineTo(WA.x,WA.y+vA),l.stroke()}})},[e,A,o,s,a,g,c,i]),W.jsxs("div",{ref:n,style:{position:"relative",width:"100%",height:"100%"},children:[t,W.jsx("canvas",{ref:r,style:{position:"absolute",top:0,left:0,pointerEvents:"none",zIndex:kc.pcbGroupOverlay,display:a?"block":"none"}})]})},Kti=({transform:t,soup:A,children:e})=>{const i=gl(r=>r.is_showing_rats_nest),{netMap:n,idToNetMap:o}=V.useMemo(()=>Phe(A||[]),[A]),s=V.useMemo(()=>{if(!A||!i)return[];const r=l=>{const B=rx(A)[l.replace(/_\d+$/,"")].get(l);return B&&"x"in B&&"y"in B?{x:B.x,y:B.y}:null},a=(l,B)=>{const C=n[B]||[];let Q=null,h=1/0;return C.forEach(E=>{const u=r(E);if(u){const d=Math.sqrt((l.x-u.x)**2+(l.y-u.y)**2);d<h&&d>0&&(h=d,Q=u)}}),Q},g=rx(A).pcb_port.list(),c=rx(A).source_trace.list(),I=[];return g.forEach((l,B)=>{const C=o[l.pcb_port_id];let Q=!1;for(const u of c)u.connected_source_port_ids.includes(l.source_port_id)&&u.connected_source_net_ids.length>0&&(Q=!0);if(!C)return;const h={x:l.x,y:l.y},E=a(h,C);E&&I.push({key:`${l.pcb_port_id}-${B}`,startPoint:h,endPoint:E,isInNet:Q})}),I},[A,n,o,i]);return!A||!i?e:(t||(t=xa()),W.jsxs("div",{style:{position:"relative"},children:[e,W.jsx("svg",{style:{position:"absolute",left:0,top:0,width:"100%",height:"100%",pointerEvents:"none",opacity:.5,zIndex:kc.ratsNestOverlay},children:s.map(({key:r,startPoint:a,endPoint:g,isInNet:c})=>{const I=Ce(t,a),l=Ce(t,g);return W.jsx("line",{x1:I.x,y1:I.y,x2:l.x,y2:l.y,stroke:"white",strokeWidth:"1",strokeDasharray:c?"6,6":void 0},r)})})]}))},qti={version:"1.11.354"},Pk=(t,A,e)=>{const i=gl(s=>s.is_mouse_over_container),n=V.useRef(i),o=V.useRef(A);V.useEffect(()=>{n.current=i},[i]),V.useEffect(()=>{o.current=A},[A]),V.useEffect(()=>{if(!t)return;const s=r=>{const a=r.target;if(a.tagName==="INPUT"||a.tagName==="TEXTAREA"||a.isContentEditable)return;const g=t.split("+"),c=g.includes("ctrl"),I=g.includes("shift"),l=g.includes("alt"),B=g.includes("meta"),C=g[g.length-1],Q=e?.current?e.current.contains(document.activeElement)||document.activeElement===e.current:!1;(n.current||Q)&&(!c||r.ctrlKey)&&(!I||r.shiftKey)&&(!l||r.altKey)&&(!B||r.metaKey)&&r.key.toLowerCase()===C.toLowerCase()&&(r.preventDefault(),o.current())};return window.addEventListener("keydown",s),()=>{window.removeEventListener("keydown",s)}},[t])},Oti=()=>{const[t,A]=V.useState(!1);return V.useEffect(()=>{const e=()=>{A(window.innerWidth<=768)};return e(),window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)},[]),t},WT=(t,A={stopPropagation:!0})=>{const e=V.useRef(0),i=V.useCallback(s=>{A.stopPropagation&&s.stopPropagation();const r=Date.now();r-e.current<300||(e.current=r,t?.(s))},[t,A.stopPropagation]),n=V.useCallback(s=>{s.preventDefault(),i(s)},[i]);return{onClick:i,onTouchEnd:n,style:{touchAction:"manipulation"}}},Wti=({name:t,selected:A,onClick:e})=>{const{style:i,...n}=WT(e);return W.jsxs("div",{className:D2`
5475
+ `,Sti=({children:t,transform:A=xa(),elements:e})=>{const i=V.useRef(null),{isShowingDRCErrors:n,hoveredErrorId:o}=gl(g=>({isShowingDRCErrors:g.is_showing_drc_errors,hoveredErrorId:g.hovered_error_id}));if(!e)return W.jsx("div",{style:{position:"relative"},ref:i,children:t});const s=e.filter(g=>g.type==="pcb_trace_error"),r=e.filter(g=>g.type==="pcb_trace_error"&&g.message?.includes("Multiple components found with name")),a=new Map;return e.forEach(g=>{g.type==="pcb_port"&&a.set(g.pcb_port_id,g)}),W.jsxs("div",{style:{position:"relative"},ref:i,children:[t,s.map((g,c)=>{const{pcb_port_ids:I,pcb_trace_id:l}=g,B=I?.[0]?a.get(I[0]):void 0,C=I?.[1]?a.get(I[1]):void 0,Q=e?rx(e).pcb_trace.get(l):void 0,h=g.pcb_trace_error_id||`error_${c}_${g.error_type}_${g.message?.slice(0,20)}`,E=o===h;if(B&&C){const u=Ce(A,{x:B.x,y:B.y}),d=Ce(A,{x:C.x,y:C.y});if(!n)return null;const f=!(isNaN(u.x)||isNaN(u.y)||isNaN(d.x)||isNaN(d.y)),y={x:(u.x+d.x)/2,y:(u.y+d.y)/2};if(isNaN(y.x)||isNaN(y.y))return null;const w=ymA(y,i);return W.jsxs(V.Fragment,{children:[W.jsx(wti,{screenPort1:u,screenPort2:d,errorCenter:y,canLineBeDrawn:f,isHighlighted:E}),W.jsx("div",{style:{position:"absolute",left:y.x-15,top:y.y-15,width:30,height:30,zIndex:kc.errorOverlay+5,cursor:"pointer",borderRadius:"50%"},onMouseEnter:D=>{const S=D.currentTarget.nextElementSibling;if(S){const _=S.querySelector(".error-message");_&&(_.style.opacity="1")}},onMouseLeave:D=>{if(!E){const S=D.currentTarget.nextElementSibling;if(S){const _=S.querySelector(".error-message");_&&(_.style.opacity="0")}}}}),W.jsx("div",{style:{position:"absolute",zIndex:E?200:100,left:w.left,top:w.top,color:E?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:n||E?"flex":"none",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:w.transform},children:W.jsx("div",{className:`error-message ${mmA}`,style:{opacity:E?1:0,border:`1px solid ${E?"#ff4444":"red"}`},children:g.message})})]},h)}if(Q?.route&&(n||E)){const u=Q.route.map(w=>Ce(A,{x:w.x,y:w.y}));if(u.some(w=>isNaN(w.x)||isNaN(w.y)))return null;const d=Math.floor(u.length/2),f=u[d],y=ymA(f,i);return W.jsxs(V.Fragment,{children:[W.jsx(Dti,{points:u,errorCenter:f,isHighlighted:E}),W.jsx("div",{style:{position:"absolute",left:f.x-15,top:f.y-15,width:30,height:30,zIndex:kc.errorOverlay+5,cursor:"pointer",borderRadius:"50%"},onMouseEnter:w=>{const D=w.currentTarget.nextElementSibling;if(D){const S=D.querySelector(".error-message");S&&(S.style.opacity="1")}},onMouseLeave:w=>{if(!E){const D=w.currentTarget.nextElementSibling;if(D){const S=D.querySelector(".error-message");S&&(S.style.opacity="0")}}}}),W.jsx("div",{style:{position:"absolute",zIndex:E?kc.errorOverlay+10:kc.errorOverlay+1,left:y.left,top:y.top,color:E?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:"flex",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:y.transform},children:W.jsx("div",{className:`error-message ${mmA}`,style:{opacity:E?1:0,border:`1px solid ${E?"#ff4444":"red"}`},children:g.message})})]},h)}return null}),r.map((g,c)=>{const I=g.component_name||g.message?.match(/name "([^"]+)"/)?.[1];if(!I)return null;const l=e?.filter(Q=>Q.type==="source_component"&&Q.name===I||Q.type==="pcb_component"&&e?.find(h=>h.type==="source_component"&&h.source_component_id===Q.source_component_id&&h.name===I))||[],B=g.pcb_trace_error_id||`error_${c}_${g.error_type}_${g.message?.slice(0,20)}`,C=o===B;return!C&&!n?null:l.map((Q,h)=>{let E={x:0,y:0};if(Q.type==="pcb_component")E=Q.center||{x:0,y:0};else if(Q.type==="source_component"){const _=e?.find(b=>b.type==="pcb_component"&&b.source_component_id===Q.source_component_id);_&&_.type==="pcb_component"&&(E=_.center||{x:0,y:0})}const u=Ce(A,E);if(isNaN(u.x)||isNaN(u.y))return null;const d=Math.abs(A.a),D=Math.max(8,Math.min(30,.5*d)),S=ymA(u,i);return W.jsxs(V.Fragment,{children:[W.jsx("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none",mixBlendMode:"difference",zIndex:kc.errorOverlay},width:"100%",height:"100%",children:C?W.jsx("polygon",{points:`${u.x},${u.y-D*1.25} ${u.x+D},${u.y} ${u.x},${u.y+D*1.25} ${u.x-D},${u.y}`,fill:"#ff4444"}):W.jsx("circle",{cx:u.x,cy:u.y,r:D,fill:"none",stroke:C?"#ff4444":"red",strokeWidth:C?Math.max(2,D*.15):Math.max(1,D*.1),opacity:1})}),W.jsx("div",{style:{position:"absolute",left:u.x-(D+10),top:u.y-(D+10),width:(D+10)*2,height:(D+10)*2,zIndex:kc.errorOverlay+5,cursor:"pointer",borderRadius:"50%"},onMouseEnter:_=>{const b=_.currentTarget.nextElementSibling;if(b){const N=b.querySelector(".error-message");N&&(N.style.opacity="1")}},onMouseLeave:_=>{if(!C){const b=_.currentTarget.nextElementSibling;if(b){const N=b.querySelector(".error-message");N&&(N.style.opacity="0")}}}}),W.jsx("div",{style:{position:"absolute",zIndex:C?kc.errorOverlay+20:kc.errorOverlay+10,left:S.left,top:S.top,color:C?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:n||C?"flex":"none",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:S.transform},children:W.jsx("div",{className:`error-message ${mmA}`,style:{opacity:C?1:0,border:`1px solid ${C?"#ff4444":"red"}`},children:g.message})})]},`${B}_${h}`)})})]})};function bti(t,A){return t.size!==A.size?!1:Array.from(t).every(e=>A.has(e))}function xti({primitiveElement:t,elements:A}){let e=t.trace_length?`${t.trace_length.toFixed(3)}`:"";const i=rx(A).source_trace.get(t?.source_trace_id);if(i?.display_name&&(i?.max_length?e+=` / ${i.max_length}mm `:e+=" mm ",e+=`(${i.display_name})`),!e)return null;const n=t.trace_length&&i?.max_length&&t.trace_length>i.max_length;return{text:e,isOverLength:n}}function _ti(t){const{primitives:A,is_showing_multiple_traces_length:e,elements:i}=t,n=A.filter(a=>a._element.type==="pcb_trace"),o=i.filter(a=>a.type==="source_trace"),s=A.filter(a=>a._element.type!=="pcb_trace"),r=n.filter(a=>o.some(g=>a._element.type==="pcb_trace"&&a._element.source_trace_id===g.source_trace_id&&g.max_length!==void 0));if(!e)return[...s,...r];if(n.length>1){const a=n.reduce((g,c)=>{const I=g._element.trace_length;return c._element.trace_length<I?c:g},n[0]);return[...s,a]}return A}var kti={position:"absolute",left:0,top:0,pointerEvents:"none",color:"red",fontFamily:"sans-serif",fontSize:12,textShadow:"0 0 2px black"},vti=t=>{const{_element:A,_parent_pcb_component:e,_parent_source_component:i,_source_port:n}=t;switch(A.type){case"pcb_trace":return A.trace_length?`${A.trace_length.toFixed(3)}`:"";case"pcb_smtpad":case"pcb_plated_hole":{const o=[],s=Array.from(new Set((A.port_hints??[]).concat(n?.port_hints??[]))).filter(a=>!/^[0-9]+$/.test(a)).filter(a=>!a.includes("unnamed_")).sort((a,g)=>g.localeCompare(a)),r=i&&"name"in i&&i.name&&!i.name.includes("unnamed_")?i.name:null;return s.length>0?r?o.push(...s.map(a=>`${r}.${a}`)):o.push(...s):r&&o.push(r),o.join(", ")}default:return""}},Fti={top:"red",bottom:"aqua"},Mti=({primitive:t,mousePos:A,elements:e})=>{const[i,n]=V.useState(!1),o=t._element;V.useEffect(()=>{setTimeout(()=>{n(!0)},100)},[]);const[s,r,a,g]=[t.screen_x,t.screen_y,t.screen_w,t.screen_h],c=t.same_space_index??0,I=26,l=Fti[t?._element?.layer]??"red";let B=0;if(o.type==="pcb_smtpad"&&o?.shape==="rotated_rect"?B=o?.ccw_rotation??0:(o.type==="pcb_smtpad"&&(o?.shape==="pill"||o?.shape==="rotated_pill")&&"ccw_rotation"in t||o.type==="pcb_plated_hole"&&(o?.shape==="pill"||o?.shape==="oval")&&"ccw_rotation"in t)&&(B=o.ccw_rotation??0),o.type==="pcb_trace"){const h=xti({primitiveElement:o,elements:e});if(!h)return null;const E=A.y-35;return W.jsx("div",{style:{zIndex:kc.elementOverlay,position:"absolute",left:A.x,top:E,color:l,pointerEvents:"none",transform:"translateX(-50%)"},children:W.jsx("div",{style:{backgroundColor:"#f2efcc",color:h.isOverLength?"red":"black",textShadow:"none",WebkitFontSmoothing:"antialiased",MozOsxFontSmoothing:"grayscale",padding:"6px 6px",borderRadius:"6px",fontSize:"14px",minWidth:"45px",textAlign:"center",whiteSpace:"nowrap"},children:h.text})})}const C=vti(t);return C.trim().length===0?null:W.jsx("div",{style:{zIndex:kc.elementOverlay,position:"absolute",left:s-a/2-8,top:r-g/2-8,width:a+16,height:g+16,color:l,transform:`rotate(${-B}deg)`,transformOrigin:"center center"},children:W.jsx("div",{style:{width:i?`calc(100% + ${I*2*c}px)`:"100%",height:i?`calc(100% + ${I*2*c}px)`:"100%",marginLeft:i?`${-I*c}px`:0,marginTop:i?`${-I*c}px`:0,border:`1px solid ${l}`,opacity:i||c===0?1:0,transition:"width 0.2s, height 0.2s, margin-left 0.2s, margin-top 0.2s, opacity 0.2s"},children:W.jsx("div",{style:{position:"absolute",bottom:g+20+I*c,marginRight:i?`${-I*c}px`:0,marginBottom:i?0:-I*c,transition:"margin-right 0.2s, margin-bottom 0.2s",backgroundColor:"#f2efcc",color:"black",textShadow:"none",WebkitFontSmoothing:"antialiased",MozOsxFontSmoothing:"grayscale",padding:"6px 6px",borderRadius:"6px",fontSize:"14px",transform:`rotate(${B}deg)`,minWidth:"45px",textAlign:"center"},children:C})})})},Rti=({highlightedPrimitives:t,mousePos:A,elements:e})=>{const[i,n]=gl(r=>[r.is_moving_component,r.is_showing_multiple_traces_length]),o=t.some(r=>r._element.type==="pcb_smtpad")&&t.some(r=>r._element.type==="pcb_trace");let s=t;return o&&(s=s.filter(r=>r._element.type==="pcb_smtpad")),s=_ti({primitives:s,is_showing_multiple_traces_length:n,elements:e}),W.jsx("div",{style:kti,children:!i&&s.map((r,a)=>W.jsx(Mti,{primitive:r,mousePos:A,elements:e},a))})},Tk=t=>t?.type==="pcb_component",cEe=t=>t?.type==="pcb_group",Nti=t=>t?.type==="pcb_panel",wmA=t=>t?.type==="pcb_board",aI={MIN_LINE_LENGTH_FOR_LABEL:40,LABEL_OFFSET_ABOVE:2,LABEL_OFFSET_BELOW:-18,LABEL_OFFSET_RIGHT:8,LABEL_OFFSET_LEFT:-120,Y_LABEL_MIN_WIDTH:110,LINE_STROKE_WIDTH:1.5,LINE_DASH_PATTERN:"4,4",COMPONENT_MARKER_RADIUS:3,LABEL_FONT_SIZE:11,ANCHOR_MARKER_SIZE:6,ANCHOR_MARKER_STROKE_WIDTH:1.5},ly={OFFSET_LINE:"white",COMPONENT_MARKER_FILL:"#66ccff",COMPONENT_MARKER_STROKE:"white",LABEL_TEXT:"white"},DmA=({targets:t,transform:A,containerWidth:e,containerHeight:i})=>{if(t.length===0)return null;const n={color:ly.LABEL_TEXT,mixBlendMode:"difference",pointerEvents:"none",fontSize:aI.LABEL_FONT_SIZE,fontFamily:"monospace",fontWeight:"bold"},o=new Map;return t.forEach(s=>{if(!o.has(s.anchor_id)){const r=Ce(A,s.anchor);o.set(s.anchor_id,r)}}),W.jsx("div",{style:{position:"absolute",left:0,top:0,width:e,height:i,overflow:"hidden",pointerEvents:"none",zIndex:kc.dimensionOverlay},children:W.jsxs("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none"},width:e,height:i,children:[t.map(s=>{const r=s.anchor,a=s.anchor_id,g=s.target,c=o.get(a),I=Ce(A,g),l=g.x-r.x,B=g.y-r.y,C=Math.abs(I.x-c.x),Q=Math.abs(I.y-c.y),h=I.y<c.y,E=I.x>c.x,u=h?aI.LABEL_OFFSET_ABOVE:aI.LABEL_OFFSET_BELOW,d=E?aI.LABEL_OFFSET_RIGHT:aI.LABEL_OFFSET_LEFT,f=C>aI.MIN_LINE_LENGTH_FOR_LABEL,y=Q>aI.MIN_LINE_LENGTH_FOR_LABEL,w=`${s.display_offset_x??l.toFixed(2)}mm`,D=`${s.display_offset_y??B.toFixed(2)}mm`;return W.jsxs("g",{children:[W.jsx("line",{x1:c.x,y1:c.y,x2:I.x,y2:c.y,stroke:ly.OFFSET_LINE,strokeWidth:aI.LINE_STROKE_WIDTH,strokeDasharray:aI.LINE_DASH_PATTERN}),W.jsx("line",{x1:I.x,y1:c.y,x2:I.x,y2:I.y,stroke:ly.OFFSET_LINE,strokeWidth:aI.LINE_STROKE_WIDTH,strokeDasharray:aI.LINE_DASH_PATTERN}),s.type==="component"||s.type==="board"?W.jsx("circle",{cx:I.x,cy:I.y,r:aI.COMPONENT_MARKER_RADIUS,fill:ly.COMPONENT_MARKER_FILL,stroke:ly.COMPONENT_MARKER_STROKE,strokeWidth:1}):W.jsxs(W.Fragment,{children:[W.jsx("line",{x1:I.x-aI.ANCHOR_MARKER_SIZE,y1:I.y,x2:I.x+aI.ANCHOR_MARKER_SIZE,y2:I.y,stroke:ly.OFFSET_LINE,strokeWidth:aI.ANCHOR_MARKER_STROKE_WIDTH}),W.jsx("line",{x1:I.x,y1:I.y-aI.ANCHOR_MARKER_SIZE,x2:I.x,y2:I.y+aI.ANCHOR_MARKER_SIZE,stroke:ly.OFFSET_LINE,strokeWidth:aI.ANCHOR_MARKER_STROKE_WIDTH})]}),f&&W.jsx("foreignObject",{x:Math.min(c.x,I.x),y:c.y+u,width:Math.abs(I.x-c.x),height:20,style:{overflow:"visible"},children:W.jsx("div",{style:{...n,textAlign:"center"},children:w})}),y&&W.jsx("foreignObject",{x:I.x+d,y:Math.min(c.y,I.y),width:aI.Y_LABEL_MIN_WIDTH,height:Math.abs(I.y-c.y),style:{overflow:"visible"},children:W.jsx("div",{style:{...n,display:"flex",alignItems:"center",justifyContent:E?"flex-start":"flex-end",whiteSpace:"nowrap",padding:"0 4px",height:"100%"},children:D})})]},s.id)}),Array.from(o.entries()).map(([s,r])=>W.jsxs("g",{children:[W.jsx("line",{x1:r.x-aI.ANCHOR_MARKER_SIZE,y1:r.y,x2:r.x+aI.ANCHOR_MARKER_SIZE,y2:r.y,stroke:ly.OFFSET_LINE,strokeWidth:aI.ANCHOR_MARKER_STROKE_WIDTH}),W.jsx("line",{x1:r.x,y1:r.y-aI.ANCHOR_MARKER_SIZE,x2:r.x,y2:r.y+aI.ANCHOR_MARKER_SIZE,stroke:ly.OFFSET_LINE,strokeWidth:aI.ANCHOR_MARKER_STROKE_WIDTH})]},`anchor-${s}`))]})})},Gti=({elements:t,highlightedPrimitives:A,transform:e,containerWidth:i,containerHeight:n})=>{const o=t.filter(E=>wmA(E)),s=t.filter(E=>Tk(E)),r=t.filter(E=>cEe(E)),a=A.map(E=>Tk(E._parent_pcb_component)?E._parent_pcb_component.pcb_component_id:Tk(E._element)?E._element.pcb_component_id:null).filter(E=>!!E),g=new Set;if(a.forEach(E=>{const u=s.find(d=>d.pcb_component_id===E);u?.pcb_group_id&&g.add(u.pcb_group_id)}),!gl(E=>E.is_showing_group_anchor_offsets)&&a.length===0)return null;const I=s.map(E=>{const u=E.positioned_relative_to_pcb_board_id;if(!u)return null;const d=o.find(f=>f.pcb_board_id===u);return d?{component:E,board:d,type:"component"}:null}).filter(E=>!!E),l=r.map(E=>{const u=E.positioned_relative_to_pcb_board_id;if(!u||!E.center)return null;const d=o.find(f=>f.pcb_board_id===u);return d?{group:E,board:d,type:"group"}:null}).filter(E=>!!E),B=[...I,...l];if(B.length===0)return null;const C=a.length===0,Q=B.filter(E=>E.type==="component"?C||a.includes(E.component.pcb_component_id):C||g.has(E.group.pcb_group_id));if(Q.length===0)return null;const h=Q.map(E=>E.type==="component"?{id:`${E.board.pcb_board_id}-${E.component.pcb_component_id}-${E.type}`,anchor:E.board.center,anchor_id:E.board.pcb_board_id,target:E.component.center,type:"component",display_offset_x:E.component.display_offset_x,display_offset_y:E.component.display_offset_y}:{id:`${E.board.pcb_board_id}-${E.group.pcb_group_id}-${E.type}`,anchor:E.board.center,anchor_id:E.board.pcb_board_id,target:{x:E.group.anchor_position?.x??E.group.center.x,y:E.group.anchor_position?.y??E.group.center.y},type:"group",display_offset_x:E.group.display_offset_x,display_offset_y:E.group.display_offset_y}).filter(E=>!!E);return W.jsx(DmA,{targets:h,transform:e,containerWidth:i,containerHeight:n})},Lti=({elements:t,highlightedPrimitives:A,transform:e,containerWidth:i,containerHeight:n})=>{const o=t.filter(E=>cEe(E)),s=t.filter(E=>Tk(E)),r=A.map(E=>Tk(E._parent_pcb_component)?E._parent_pcb_component.pcb_component_id:Tk(E._element)?E._element.pcb_component_id:null).filter(E=>!!E),a=(E,u)=>{if(u.has(E))return;u.add(E);const d=o.find(f=>f.pcb_group_id===E);d?.position_mode==="relative_to_group_anchor"&&d.positioned_relative_to_pcb_group_id&&a(d.positioned_relative_to_pcb_group_id,u)},g=new Set;if(r.forEach(E=>{const u=s.find(d=>d.pcb_component_id===E);u&&(u.position_mode==="relative_to_group_anchor"&&u.positioned_relative_to_pcb_group_id&&a(u.positioned_relative_to_pcb_group_id,g),u.pcb_group_id&&a(u.pcb_group_id,g))}),!gl(E=>E.is_showing_group_anchor_offsets)&&r.length===0)return null;const I=s.map(E=>{if(E.position_mode==="relative_to_group_anchor"&&E.positioned_relative_to_pcb_group_id){const u=o.find(d=>d.pcb_group_id===E.positioned_relative_to_pcb_group_id);return u&&u.anchor_position?{component:E,parentGroup:u,type:"component"}:null}if(E.pcb_group_id){const u=o.find(d=>d.pcb_group_id===E.pcb_group_id);return u&&u.anchor_position?{component:E,parentGroup:u,type:"component"}:null}return null}).filter(E=>!!E),l=o.map(E=>{if(E.position_mode==="relative_to_group_anchor"&&E.positioned_relative_to_pcb_group_id){const u=o.find(d=>d.pcb_group_id===E.positioned_relative_to_pcb_group_id);if(u&&u.anchor_position&&E.anchor_position)return{group:E,parentGroup:u,type:"group"}}return null}).filter(E=>!!E),B=[...I,...l];if(B.length===0)return null;const C=r.length===0,Q=B.filter(E=>E.type==="component"?C||r.includes(E.component.pcb_component_id):C||g.has(E.group.pcb_group_id)||g.has(E.parentGroup.pcb_group_id));if(Q.length===0)return null;const h=Q.map(E=>{const u=E.parentGroup.anchor_position;return u?E.type==="component"?E.component.center?{id:`${E.parentGroup.pcb_group_id}-${E.component.pcb_component_id}-${E.type}`,anchor:u,anchor_id:E.parentGroup.pcb_group_id,target:E.component.center,type:"component",display_offset_x:E.component.display_offset_x,display_offset_y:E.component.display_offset_y}:null:E.group.anchor_position?{id:`${E.parentGroup.pcb_group_id}-${E.group.pcb_group_id}-${E.type}`,anchor:u,anchor_id:E.parentGroup.pcb_group_id,target:E.group.anchor_position,type:"group",display_offset_x:E.group.display_offset_x,display_offset_y:E.group.display_offset_y}:null:null}).filter(E=>!!E);return W.jsx(DmA,{targets:h,transform:e,containerWidth:i,containerHeight:n})},Uti=(t,A)=>{const e=t.pcb_component_id,i=A.filter(n=>(n.type==="pcb_smtpad"||n.type==="pcb_plated_hole")&&n.pcb_component_id===e||n.type==="pcb_hole"&&n.pcb_component_id===e);return i.length===0?pmA([t]):pmA(i)},Hti=({elements:t,highlightedPrimitives:A,transform:e,containerWidth:i,containerHeight:n})=>{const o=new Map;for(const r of A)Tk(r._parent_pcb_component)&&o.set(r._parent_pcb_component.pcb_component_id,r._parent_pcb_component),Tk(r._element)&&o.set(r._element.pcb_component_id,r._element);if(o.size===0)return null;const s=[];for(const r of o.values()){const a=Uti(r,t);if(!a)continue;const g=r.positioned_relative_to_pcb_group_id??r.pcb_group_id,c=g?rx(t).pcb_group.get(g):null;s.push({component:r,bbox:a,group:c})}return s.length===0?null:W.jsx("div",{style:{position:"absolute",left:0,top:0,width:i,height:n,overflow:"hidden",pointerEvents:"none",zIndex:kc.dimensionOverlay},children:W.jsx("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none"},width:i,height:n,children:s.map(({component:r,bbox:a,group:g})=>{const c=Ce(e,{x:a.minX,y:a.maxY}),I=Ce(e,{x:a.maxX,y:a.minY}),l={x:Math.min(c.x,I.x),y:Math.min(c.y,I.y),width:Math.abs(I.x-c.x),height:Math.abs(I.y-c.y)},B=r.center??{x:(a.minX+a.maxX)/2,y:(a.minY+a.maxY)/2},C=Ce(e,B);return W.jsxs("g",{children:[W.jsx("rect",{x:l.x,y:l.y,width:l.width,height:l.height,fill:"none",stroke:"white",strokeWidth:1.5,strokeDasharray:"4,4"}),W.jsx("line",{x1:C.x-6,y1:C.y,x2:C.x+6,y2:C.y,stroke:ly.COMPONENT_MARKER_STROKE,strokeWidth:1.5}),W.jsx("line",{x1:C.x,y1:C.y-6,x2:C.x,y2:C.y+6,stroke:ly.COMPONENT_MARKER_STROKE,strokeWidth:1.5}),W.jsx("circle",{cx:C.x,cy:C.y,r:aI.COMPONENT_MARKER_RADIUS,fill:ly.COMPONENT_MARKER_FILL,stroke:ly.COMPONENT_MARKER_STROKE,strokeWidth:1})]},r.pcb_component_id)})})})},Yti=({elements:t,highlightedPrimitives:A,transform:e,containerWidth:i,containerHeight:n})=>{const o=t.filter(B=>Nti(B)),s=t.filter(B=>wmA(B)),r=A.map(B=>wmA(B._element)?B._element.pcb_board_id:null).filter(B=>!!B);if(!gl(B=>B.is_showing_group_anchor_offsets)&&r.length===0)return null;const g=s.map(B=>{const C=B.pcb_panel_id,Q=B.position_mode;if(!C||Q!=="relative_to_panel_anchor")return null;const h=o.find(E=>E.pcb_panel_id===C);return h?{board:B,panel:h,type:"board"}:null}).filter(B=>!!B);if(g.length===0)return null;const c=r.length===0,I=g.filter(B=>c||r.includes(B.board.pcb_board_id));if(I.length===0)return null;const l=I.map(B=>B.board.center?{id:`${B.panel.pcb_panel_id}-${B.board.pcb_board_id}-${B.type}`,anchor:B.panel.center,anchor_id:B.panel.pcb_panel_id,target:B.board.center,type:"board",display_offset_x:B.board.display_offset_x,display_offset_y:B.board.display_offset_y}:null).filter(B=>!!B);return W.jsx(DmA,{targets:l,transform:e,containerWidth:i,containerHeight:n})},Nz=t=>{if(t.length===0)return null;let A=t[0].x,e=t[0].y,i=t[0].x,n=t[0].y;for(const o of t)o.x<A&&(A=o.x),o.y<e&&(e=o.y),o.x>i&&(i=o.x),o.y>n&&(n=o.y);return{center:{x:(A+i)/2,y:(e+n)/2},width:i-A,height:n-e}},IEe=(t,A)=>{if(A.length<3)return!1;let e=!1;for(let i=0,n=A.length-1;i<A.length;n=i++){const o=A[i].x,s=A[i].y,r=A[n].x,a=A[n].y;s>t.y!=a>t.y&&t.x<(r-o)*(t.y-s)/(a-s||Number.EPSILON)+o&&(e=!e)}return e},Jti=(t,A,e)=>{const i=[];for(const n of t){if(!n._element)continue;if("x1"in n&&n._element?.type==="pcb_trace"){const r=HE({x:A.x,y:A.y},{x:n.x1,y:n.y1},{x:n.x2,y:n.y2}),a=n.width||.5,g=Math.max(a*25,2)/e.a;r<g&&i.push(n);continue}if(n.pcb_drawing_type==="polygon"){const r=n.points.map(g=>({x:Et.parse(g.x),y:Et.parse(g.y)})),a=Nz(r);if(!a||A.x<a.center.x-a.width/2||A.x>a.center.x+a.width/2||A.y<a.center.y-a.height/2||A.y>a.center.y+a.height/2)continue;IEe(A,r)&&i.push(n);continue}if(n.pcb_drawing_type==="polygon_with_arcs"){const r=n.brep_shape.outer_ring.vertices.map(g=>({x:Et.parse(g.x),y:Et.parse(g.y)})),a=Nz(r);if(!a||A.x<a.center.x-a.width/2||A.x>a.center.x+a.width/2||A.y<a.center.y-a.height/2||A.y>a.center.y+a.height/2)continue;IEe(A,r)&&i.push(n);continue}if(!("x"in n&&"y"in n))continue;let o=0,s=0;if("w"in n&&"h"in n)o=n.w,s=n.h;else if("r"in n)o=n.r*2,s=n.r*2;else if("rX"in n&&"rY"in n)o=n.rX*2,s=n.rY*2;else continue;Math.abs(n.x-A.x)<o/2&&Math.abs(n.y-A.y)<s/2&&i.push(n)}return i},Tti=({elements:t,children:A,transform:e,primitives:i,onMouseHoverOverPrimitives:n})=>{const[o,s]=V.useState([]),[r,a]=V.useState({x:0,y:0}),[g,{width:c,height:I}]=qT(),l=V.useMemo(()=>{const C=[];for(const Q of o){if(Q._element?.type==="pcb_via"||Q._element?.type==="pcb_component"||Q?.layer==="drill"||Q?.is_hoverable===!1)continue;let h=null,E=0,u=0;if(Q.pcb_drawing_type==="polygon"){const w=Nz(Q.points);if(!w)continue;h=w.center,E=w.width,u=w.height}else if(Q.pcb_drawing_type==="polygon_with_arcs"){const w=Q.brep_shape.outer_ring.vertices.map(S=>({x:S.x,y:S.y})),D=Nz(w);if(!D)continue;h=D.center,E=D.width,u=D.height}else"x"in Q&&"y"in Q&&(h={x:Q.x,y:Q.y},E="w"in Q?Q.w:"r"in Q?Q.r*2:"rX"in Q&&"rY"in Q?Q.rX*2:0,u="h"in Q?Q.h:"r"in Q?Q.r*2:"rX"in Q&&"rY"in Q?Q.rY*2:0);if(!h)continue;const d=Ce(e,h),f={w:E*e.a,h:u*e.a},y=C.filter(w=>d.x===w.screen_x&&d.y===w.screen_y&&f.w===w.screen_w&&f.h===w.screen_h).length;C.push({...Q,x:h.x,y:h.y,w:E,h:u,screen_x:d.x,screen_y:d.y,screen_w:f.w,screen_h:f.h,same_space_index:y})}return C},[o,e]),B=(C,Q,h,E)=>{a({x:C,y:Q});const u=Ce(tm(h),{x:C,y:Q}),d=Jti(E,u,h);bti(new Set(d.map(f=>f._pcb_drawing_object_id)),new Set(o.map(f=>f._pcb_drawing_object_id)))||(s(d),n(d))};return W.jsxs("div",{ref:g,style:{position:"relative",width:"100%",height:"100%"},onMouseMove:C=>{if(e){const Q=C.currentTarget.getBoundingClientRect(),h=C.clientX-Q.left,E=C.clientY-Q.top;B(h,E,e,i)}},onTouchStart:C=>{if(e){const Q=C.touches[0],h=C.currentTarget.getBoundingClientRect(),E=Q.clientX-h.left,u=Q.clientY-h.top;B(E,u,e,i)}},children:[A,W.jsx(Rti,{elements:t,mousePos:r,highlightedPrimitives:l}),e&&W.jsxs(W.Fragment,{children:[W.jsx(Gti,{elements:t,highlightedPrimitives:l,transform:e,containerWidth:c,containerHeight:I}),W.jsx(Lti,{elements:t,highlightedPrimitives:l,transform:e,containerWidth:c,containerHeight:I}),W.jsx(Hti,{elements:t,highlightedPrimitives:l,transform:e,containerWidth:c,containerHeight:I}),W.jsx(Yti,{elements:t,highlightedPrimitives:l,transform:e,containerWidth:c,containerHeight:I})]})]})},lEe=["rgb(255, 100, 100)","rgb(100, 255, 100)","rgb(100, 100, 255)","rgb(255, 255, 100)","rgb(255, 100, 255)","rgb(100, 255, 255)","rgb(255, 150, 100)","rgb(150, 100, 255)","rgb(100, 255, 150)","rgb(255, 100, 150)"],Pti=({children:t,transform:A=xa(),elements:e=[],hoveredComponentIds:i=[]})=>{const[n,{width:o,height:s}]=qT(),r=V.useRef(null),{is_showing_pcb_groups:a,pcb_group_view_mode:g,is_showing_group_anchor_offsets:c}=gl(I=>({is_showing_pcb_groups:I.is_showing_pcb_groups,pcb_group_view_mode:I.pcb_group_view_mode,is_showing_group_anchor_offsets:I.is_showing_group_anchor_offsets}));return V.useEffect(()=>{const I=r.current;if(!I||!o||!s)return;I.width=o,I.height=s;const l=I.getContext("2d");if(!l||(l.clearRect(0,0,o,s),!a))return;const B=e.filter(w=>w.type==="pcb_group"),C=e.filter(w=>w.type==="pcb_component"),Q=e.filter(w=>w.type==="source_group"),h=new Map(Q.map(w=>[w.source_group_id,w])),E=B.filter(w=>{if(w.name?.toLowerCase().includes("subpanel"))return!1;if(g==="all")return!0;if(!w.source_group_id)return!1;const D=h.get(w.source_group_id);return D?D.was_automatically_named!==!0:!1}),u=new Map;Q.forEach(w=>{const D=w;if(D.parent_source_group_id){const S=u.get(D.parent_source_group_id)||[];S.push(w.source_group_id),u.set(D.parent_source_group_id,S)}});const d=w=>{const D=[],S=u.get(w)||[];for(const _ of S)D.push(_),D.push(...d(_));return D},f=w=>{const D=Q.find(S=>S.source_group_id===w);return D?.parent_source_group_id?1+f(D.parent_source_group_id):0},y=new Set;if(i.length>0)for(const w of C){if(!i.includes(w.pcb_component_id))continue;const D=w.positioned_relative_to_pcb_group_id??w.pcb_group_id;D&&y.add(D)}E.forEach((w,D)=>{let S=C.filter(JA=>JA.pcb_group_id===w.pcb_group_id);if(w.source_group_id){const JA=d(w.source_group_id),WA=B.filter(vA=>vA.source_group_id&&JA.includes(vA.source_group_id));for(const vA of WA){const wA=C.filter(RA=>RA.pcb_group_id===vA.pcb_group_id);S=[...S,...wA]}}let _,b,N,F,L=!1;if(w.center&&w.width&&w.height){L=!0;const JA=w.width/2,WA=w.height/2;_=w.center.x-JA,N=w.center.x+JA,b=w.center.y-WA,F=w.center.y+WA}else if(S.length===0||(_=1/0,b=1/0,N=-1/0,F=-1/0,S.forEach(JA=>{if(JA.center&&typeof JA.width=="number"&&typeof JA.height=="number"){const WA=JA.center.x-JA.width/2,vA=JA.center.x+JA.width/2,wA=JA.center.y+JA.height/2,RA=JA.center.y-JA.height/2;_=Math.min(_,WA),N=Math.max(N,vA),b=Math.min(b,RA),F=Math.max(F,wA)}}),_===1/0||N===-1/0))return;const Y=w.source_group_id?f(w.source_group_id):0,J=w.source_group_id?d(w.source_group_id).length>0:!1;if(!L){const vA=1+(J?.5:0);_-=vA,N+=vA,b-=vA,F+=vA}const O=Ce(A,{x:_,y:F}),Z=Ce(A,{x:N,y:F}),X=Ce(A,{x:_,y:b}),eA=Ce(A,{x:N,y:b}),gA=lEe[D%lEe.length];l.strokeStyle=gA,l.lineWidth=2;const tA=Math.max(4,Math.min(12,8*Math.abs(A.a))),iA=Math.max(2,Math.min(6,4*Math.abs(A.a))),aA=tA*(J?1.3:1),EA=iA;l.setLineDash([aA,EA]),l.beginPath(),l.moveTo(O.x,O.y),l.lineTo(Z.x,Z.y),l.lineTo(eA.x,eA.y),l.lineTo(X.x,X.y),l.closePath(),l.stroke();const bA=Math.max(8,Math.min(12,10*Math.abs(A.a))),_A=Y==0||Y==1?0:Y*.11,LA=bA*(1-_A),QA=4,kA=w.name||`Group ${D+1}`;l.font=`${LA}px sans-serif`,l.setLineDash([]);const qA=l.measureText(kA).width+QA*2,VA=LA+QA*2,ce=O.x-5,fA=O.y-5,ge=3;if(l.fillStyle="rgba(0, 0, 0, 0.8)",l.beginPath(),l.roundRect(ce,fA-VA,qA,VA,ge),l.fill(),l.fillStyle=gA,l.textAlign="left",l.textBaseline="middle",l.fillText(kA,ce+QA,fA-VA/2),c&&y.has(w.pcb_group_id)&&!!w.anchor_position&&w.anchor_position){const JA=Array.isArray(w.anchor_position)?{x:w.anchor_position[0]??0,y:w.anchor_position[1]??0}:{x:w.anchor_position.x,y:w.anchor_position.y},WA=Ce(A,JA);l.strokeStyle="white",l.lineWidth=1.5,l.setLineDash([]);const vA=Math.max(4,Math.min(8,6*Math.abs(A.a)));l.beginPath(),l.moveTo(WA.x-vA,WA.y),l.lineTo(WA.x+vA,WA.y),l.stroke(),l.beginPath(),l.moveTo(WA.x,WA.y-vA),l.lineTo(WA.x,WA.y+vA),l.stroke()}})},[e,A,o,s,a,g,c,i]),W.jsxs("div",{ref:n,style:{position:"relative",width:"100%",height:"100%"},children:[t,W.jsx("canvas",{ref:r,style:{position:"absolute",top:0,left:0,pointerEvents:"none",zIndex:kc.pcbGroupOverlay,display:a?"block":"none"}})]})},Kti=({transform:t,soup:A,children:e})=>{const i=gl(r=>r.is_showing_rats_nest),{netMap:n,idToNetMap:o}=V.useMemo(()=>Phe(A||[]),[A]),s=V.useMemo(()=>{if(!A||!i)return[];const r=l=>{const B=rx(A)[l.replace(/_\d+$/,"")].get(l);return B&&"x"in B&&"y"in B?{x:B.x,y:B.y}:null},a=(l,B)=>{const C=n[B]||[];let Q=null,h=1/0;return C.forEach(E=>{const u=r(E);if(u){const d=Math.sqrt((l.x-u.x)**2+(l.y-u.y)**2);d<h&&d>0&&(h=d,Q=u)}}),Q},g=rx(A).pcb_port.list(),c=rx(A).source_trace.list(),I=[];return g.forEach((l,B)=>{const C=o[l.pcb_port_id];let Q=!1;for(const u of c)u.connected_source_port_ids.includes(l.source_port_id)&&u.connected_source_net_ids.length>0&&(Q=!0);if(!C)return;const h={x:l.x,y:l.y},E=a(h,C);E&&I.push({key:`${l.pcb_port_id}-${B}`,startPoint:h,endPoint:E,isInNet:Q})}),I},[A,n,o,i]);return!A||!i?e:(t||(t=xa()),W.jsxs("div",{style:{position:"relative"},children:[e,W.jsx("svg",{style:{position:"absolute",left:0,top:0,width:"100%",height:"100%",pointerEvents:"none",opacity:.5,zIndex:kc.ratsNestOverlay},children:s.map(({key:r,startPoint:a,endPoint:g,isInNet:c})=>{const I=Ce(t,a),l=Ce(t,g);return W.jsx("line",{x1:I.x,y1:I.y,x2:l.x,y2:l.y,stroke:"white",strokeWidth:"1",strokeDasharray:c?"6,6":void 0},r)})})]}))},qti={version:"1.11.355"},Pk=(t,A,e)=>{const i=gl(s=>s.is_mouse_over_container),n=V.useRef(i),o=V.useRef(A);V.useEffect(()=>{n.current=i},[i]),V.useEffect(()=>{o.current=A},[A]),V.useEffect(()=>{if(!t)return;const s=r=>{const a=r.target;if(a.tagName==="INPUT"||a.tagName==="TEXTAREA"||a.isContentEditable)return;const g=t.split("+"),c=g.includes("ctrl"),I=g.includes("shift"),l=g.includes("alt"),B=g.includes("meta"),C=g[g.length-1],Q=e?.current?e.current.contains(document.activeElement)||document.activeElement===e.current:!1;(n.current||Q)&&(!c||r.ctrlKey)&&(!I||r.shiftKey)&&(!l||r.altKey)&&(!B||r.metaKey)&&r.key.toLowerCase()===C.toLowerCase()&&(r.preventDefault(),o.current())};return window.addEventListener("keydown",s),()=>{window.removeEventListener("keydown",s)}},[t])},Oti=()=>{const[t,A]=V.useState(!1);return V.useEffect(()=>{const e=()=>{A(window.innerWidth<=768)};return e(),window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)},[]),t},WT=(t,A={stopPropagation:!0})=>{const e=V.useRef(0),i=V.useCallback(s=>{A.stopPropagation&&s.stopPropagation();const r=Date.now();r-e.current<300||(e.current=r,t?.(s))},[t,A.stopPropagation]),n=V.useCallback(s=>{s.preventDefault(),i(s)},[i]);return{onClick:i,onTouchEnd:n,style:{touchAction:"manipulation"}}},Wti=({name:t,selected:A,onClick:e})=>{const{style:i,...n}=WT(e);return W.jsxs("div",{className:D2`
5476
5476
  margin-top: 2px;
5477
5477
  padding: 4px;
5478
5478
  padding-left: 8px;
@@ -5689,7 +5689,7 @@ test("${g} should solve problem correctly", () => {
5689
5689
  // Add more specific assertions based on expected output
5690
5690
  // expect(solver.netLabelPlacementSolver!.netLabelPlacements).toMatchInlineSnapshot()
5691
5691
  })
5692
- `,I=new Blob([c],{type:"text/plain"}),l=URL.createObjectURL(I),B=document.createElement("a");B.href=l,B.download=`${g}.test.ts`,B.click(),URL.revokeObjectURL(l)}catch(a){alert(`Error generating test.ts for ${t.constructor.name}: ${a instanceof Error?a.message:String(a)}`)}i(!1)};return W.jsxs("div",{className:`relative ${A}`,ref:n,children:[W.jsx("button",{className:"px-2 py-1 rounded text-xs cursor-pointer",onClick:()=>i(!e),title:`Download options for ${t.constructor.name}`,children:t.constructor.name}),e&&W.jsxs("div",{className:"absolute top-full left-0 mt-1 bg-white border border-gray-300 rounded shadow-lg z-10 min-w-[150px]",children:[W.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:o,children:"Download JSON"}),W.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:s,children:"Download page.tsx"}),W.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:r,children:"Download test.ts"})]})]})},fEe=t=>t.activeSubSolver?[t,...fEe(t.activeSubSolver)]:[t],pni=({solver:t})=>{const A=fEe(t);return W.jsx("div",{className:"flex gap-1 items-center text-sm pt-1",children:A.map((e,i)=>W.jsxs("div",{className:"flex items-center",children:[i>0&&W.jsx("span",{className:"text-gray-400 mx-1",children:"→"}),W.jsx(dni,{solver:e})]},e.constructor.name))})},fni=({solver:t,triggerRender:A,animationSpeed:e=25,onSolverStarted:i,onSolverCompleted:n})=>{const[o,s]=V.useReducer(Q=>!Q,!1),r=V.useRef(void 0),a=()=>{!t.solved&&!t.failed&&(t.step(),A())},g=()=>{!t.solved&&!t.failed&&(i&&i(t),t.solve(),A(),n&&n(t))},c=()=>{o?(r.current&&(clearInterval(r.current),r.current=void 0),s()):(s(),r.current=setInterval(()=>{if(t.solved||t.failed){r.current&&(clearInterval(r.current),r.current=void 0),s(),A(),n&&t.solved&&n(t);return}t.step(),A()},e))},I=()=>{const Q=t;if(Q.getCurrentPhase&&!t.solved&&!t.failed){const h=Q.getCurrentPhase();for(;Q.getCurrentPhase()===h&&!t.solved&&!t.failed;)t.step();A()}},l=()=>{if(t.solved||t.failed||o)return;const Q=window.prompt("Step until which iteration?",`${t.iterations}`);if(Q===null)return;const h=Number(Q);if(!Number.isFinite(h)){window.alert("Please enter a valid number for the iteration");return}for(;t.iterations<h&&!t.solved&&!t.failed;)t.step();A(),t.solved&&n&&n(t)};V.useEffect(()=>()=>{r.current&&clearInterval(r.current)},[]),V.useEffect(()=>{(t.solved||t.failed)&&o&&(r.current&&(clearInterval(r.current),r.current=void 0),s())},[t.solved,t.failed,o]);const B=t.getCurrentPhase!==void 0,C=B?t.getCurrentPhase():null;return W.jsxs("div",{className:"space-y-2 p-2 border-b",children:[W.jsx("div",{className:"flex items-center",children:W.jsx(pni,{solver:t})}),W.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[W.jsx("button",{onClick:a,disabled:t.solved||t.failed||o,className:"bg-blue-500 hover:bg-blue-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step"}),W.jsx("button",{onClick:g,disabled:t.solved||t.failed||o,className:"bg-green-500 hover:bg-green-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Solve"}),W.jsx("button",{onClick:c,disabled:t.solved||t.failed,className:`px-3 py-1 rounded text-white text-sm ${o?"bg-red-500 hover:bg-red-600":"bg-yellow-500 hover:bg-yellow-600"} disabled:bg-gray-300`,children:o?"Stop":"Animate"}),W.jsx("button",{onClick:l,disabled:t.solved||t.failed||o,className:"bg-orange-500 hover:bg-orange-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step Until Iteration"}),B&&W.jsx("button",{onClick:I,disabled:t.solved||t.failed||o,className:"bg-purple-500 hover:bg-purple-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Next Stage"}),W.jsxs("div",{className:"text-sm text-gray-600",children:["Iterations: ",t.iterations]}),t.timeToSolve!==void 0&&W.jsxs("div",{className:"text-sm text-gray-600",children:["Time: ",(t.timeToSolve/1e3).toFixed(3),"s"]}),C&&W.jsxs("div",{className:"text-sm text-gray-600",children:["Phase: ",W.jsx("span",{className:"font-medium",children:C})]}),t.solved&&W.jsx("div",{className:"px-2 py-1 bg-green-100 text-green-800 rounded text-sm",children:"Solved"}),t.failed&&W.jsx("div",{className:"px-2 py-1 bg-red-100 text-red-800 rounded text-sm",children:"Failed"})]}),t.error&&W.jsxs("div",{className:"text-red-600 text-sm",children:["Error: ",t.error]})]})},yni=(t,A,e)=>{const i=t.currentPipelineStepIndex;return A<i?"Completed":A===i&&t.activeSubSolver?t.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},mni=(t,A)=>{const i=t.pipelineDef[A].solverName,n=yni(t,A),o=t[i],s=t.firstIterationOfPhase?.[i]??null,r=t.iterations;let a=0;if(n==="Completed"){const l=t.pipelineDef[A+1],B=l?t.firstIterationOfPhase?.[l.solverName]:void 0;B!==void 0&&s!==null?a=B-s:s!==null&&(a=r-s)}else n==="In Progress"&&s!==null&&(a=r-s);const g=t.timeSpentOnPhase?.[i]??0;let c=0;n==="Completed"?c=1:n==="In Progress"&&o&&(c=o.progress??0);const I=o?.stats??null;return{index:A,name:i,status:n,firstIteration:s,iterations:a,progress:c,timeSpent:g,stats:I&&Object.keys(I).length>0?I:null,solverInstance:o??null}},wni=({status:t})=>{const A={"Not Started":"text-blue-600","In Progress":"text-yellow-600",Completed:"text-green-600",Failed:"text-red-600"};return W.jsx("span",{className:`font-medium ${A[t]}`,children:t})},Dni=({progress:t})=>{if(t===0)return null;const A=Math.round(t*100);return W.jsxs("div",{className:"flex items-center gap-2",children:[W.jsx("div",{className:"w-20 h-2 bg-gray-200 rounded overflow-hidden",children:W.jsx("div",{className:"h-full bg-blue-500 transition-all duration-200",style:{width:`${A}%`}})}),W.jsxs("span",{className:"text-xs text-gray-500",children:[A,"%"]})]})},Sni=t=>Object.entries(t).map(([A,e])=>`${A}: ${e}`).join(", "),bni=({stats:t})=>{if(!t||Object.keys(t).length===0)return W.jsx("span",{children:"-"});const A=Object.entries(t),e=Sni(t);return W.jsxs("details",{className:"cursor-pointer",children:[W.jsx("summary",{className:"whitespace-nowrap overflow-hidden text-ellipsis max-w-[200px]",children:e}),W.jsx("div",{className:"mt-1 text-xs",children:A.map(([i,n])=>W.jsxs("div",{children:[i,": ",String(n)]},i))})]})},MmA=t=>{if(t===null||typeof t!="object")return t;if(Array.isArray(t))return t.map(MmA);const A={};for(const[e,i]of Object.entries(t))e.startsWith("_")||(A[e]=MmA(i));return A},xni=(t,A)=>{try{if(typeof t.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${A}`);return}const e=MmA(t.getConstructorParams()),i=new Blob([JSON.stringify(e,null,2)],{type:"application/json"}),n=URL.createObjectURL(i),o=document.createElement("a");o.href=n,o.download=`${A}_input.json`,o.click(),URL.revokeObjectURL(n)}catch(e){alert(`Error downloading input for ${A}: ${e instanceof Error?e.message:String(e)}`)}},_ni=({solver:t,onStepUntilPhase:A,onDownloadInput:e})=>{const i=t.pipelineDef.map((r,a)=>mni(t,a)),n=r=>{A?.(r)},o=r=>{r.solverInstance&&(e?e(r.solverInstance,r.name):xni(r.solverInstance,r.name))},s=r=>`${(r/1e3).toFixed(2)}s`;return W.jsxs("div",{className:"border-t border-gray-200",children:[W.jsx("div",{className:"px-4 py-2 bg-gray-50 border-b border-gray-200",children:W.jsx("h3",{className:"text-sm font-semibold text-gray-700",children:"Pipeline Steps"})}),W.jsx("div",{className:"overflow-x-auto",children:W.jsxs("table",{className:"w-full text-sm",children:[W.jsx("thead",{children:W.jsxs("tr",{className:"bg-gray-50 border-b border-gray-200",children:[W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Step"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Status"}),W.jsxs("th",{className:"px-4 py-2 text-center font-semibold text-gray-700",children:["i",W.jsx("sub",{children:"0"})]}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Iterations"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Progress"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Time"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stats"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Input"})]})}),W.jsx("tbody",{children:i.map(r=>W.jsxs("tr",{className:`border-b border-gray-100 ${r.status==="In Progress"?"bg-yellow-50":""}`,children:[W.jsx("td",{className:"px-4 py-2",children:W.jsxs("div",{className:"flex items-center gap-2",children:[W.jsx("span",{className:"text-gray-400 w-6",children:String(r.index+1).padStart(2,"0")}),W.jsx("button",{onClick:()=>n(r.name),disabled:r.status==="Completed"||t.solved||t.failed,className:"text-blue-500 hover:text-blue-700 disabled:text-gray-300 disabled:cursor-not-allowed",title:`Step until ${r.name} completes`,children:W.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:W.jsx("path",{fillRule:"evenodd",d:"M4.5 5.653c0-1.426 1.529-2.33 2.779-1.643l11.54 6.348c1.295.712 1.295 2.573 0 3.285L7.28 19.991c-1.25.687-2.779-.217-2.779-1.643V5.653z",clipRule:"evenodd"})})}),W.jsx("span",{className:"font-medium text-gray-900",children:r.name})]})}),W.jsx("td",{className:"px-4 py-2",children:W.jsx(wni,{status:r.status})}),W.jsx("td",{className:"px-4 py-2 text-center text-gray-600",children:r.firstIteration!==null?r.firstIteration:""}),W.jsx("td",{className:"px-4 py-2 text-gray-600",children:r.iterations}),W.jsx("td",{className:"px-4 py-2",children:W.jsx(Dni,{progress:r.progress})}),W.jsx("td",{className:"px-4 py-2 text-gray-600",children:s(r.timeSpent)}),W.jsx("td",{className:"px-4 py-2 text-gray-500",children:W.jsx(bni,{stats:r.stats})}),W.jsx("td",{className:"px-4 py-2",children:r.solverInstance?W.jsxs("button",{onClick:()=>o(r),className:"flex items-center gap-1 text-blue-500 hover:text-blue-700",title:`Download input for ${r.name}`,children:[W.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:W.jsx("path",{fillRule:"evenodd",d:"M12 2.25a.75.75 0 01.75.75v11.69l3.22-3.22a.75.75 0 111.06 1.06l-4.5 4.5a.75.75 0 01-1.06 0l-4.5-4.5a.75.75 0 111.06-1.06l3.22 3.22V3a.75.75 0 01.75-.75zm-9 13.5a.75.75 0 01.75.75v2.25a1.5 1.5 0 001.5 1.5h13.5a1.5 1.5 0 001.5-1.5V16.5a.75.75 0 011.5 0v2.25a3 3 0 01-3 3H5.25a3 3 0 01-3-3V16.5a.75.75 0 01.75-.75z",clipRule:"evenodd"})}),W.jsx("span",{children:"Input"})]}):null})]},r.name))})]})})]})},kni=class extends Qn.Component{constructor(t){super(t),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(t){console.error("InteractiveGraphics render error:",t)}render(){return this.state.hasError?this.props.fallback:this.props.children}};function vni({graphics:t}){const A=t.points??[],e=t.lines??[],i=t.rects??[],n=t.circles??[],o=t.texts??[];let s=Number.POSITIVE_INFINITY,r=Number.POSITIVE_INFINITY,a=Number.NEGATIVE_INFINITY,g=Number.NEGATIVE_INFINITY;const c=(h,E)=>{typeof h=="number"&&(h<s&&(s=h),h>a&&(a=h)),typeof E=="number"&&(E<r&&(r=E),E>g&&(g=E))};for(const h of A)c(h.x,h.y);for(const h of e){const E=h.points??[];for(const u of E)c(u.x,u.y)}for(const h of i){const E=h.x??0,u=h.y??0,d=h.width??0,f=h.height??0;c(E,u),c(E+d,u+f)}for(const h of n){const E=h.x??0,u=h.y??0,d=h.radius??1;c(E-d,u-d),c(E+d,u+d)}for(const h of o)c(h.x,h.y);(!isFinite(s)||!isFinite(r)||!isFinite(a)||!isFinite(g))&&(s=-20,r=-20,a=20,g=20);const I=10,l=s-I,B=r-I,C=Math.max(1,a-s+2*I),Q=Math.max(1,g-r+2*I);return W.jsxs("svg",{className:"w-full h-[400px] bg-white",viewBox:`${l} ${B} ${C} ${Q}`,role:"img","aria-label":"Graphics fallback",children:[i.map((h,E)=>W.jsx("rect",{x:h.x??0,y:h.y??0,width:h.width??0,height:h.height??0,fill:"none",stroke:h.strokeColor??"black",strokeWidth:h.strokeWidth??1},`rect-${E}`)),e.map((h,E)=>W.jsx("polyline",{fill:"none",stroke:h.strokeColor??"black",strokeWidth:h.strokeWidth??1,points:(h.points??[]).map(u=>`${u.x??0},${u.y??0}`).join(" ")},`line-${E}`)),n.map((h,E)=>W.jsx("circle",{cx:h.x??0,cy:h.y??0,r:h.radius??1.5,fill:h.fillColor??"none",stroke:h.strokeColor??"black",strokeWidth:h.strokeWidth??1},`circle-${E}`)),A.map((h,E)=>W.jsx("circle",{cx:h.x??0,cy:h.y??0,r:h.radius??1.5,fill:h.color??"black"},`point-${E}`)),o.map((h,E)=>W.jsx("text",{x:h.x??0,y:h.y??0,fontSize:h.fontSize??10,fill:h.color??"black",children:h.text??""},`text-${E}`))]})}var Fni=({solver:t,animationSpeed:A=25,onSolverStarted:e,onSolverCompleted:i})=>{const[n,o]=V.useReducer(c=>c+1,0),s=V.useMemo(()=>{try{return t.visualize()||{points:[],lines:[],rects:[],circles:[]}}catch(c){return console.error("Visualization error:",c),{points:[],lines:[],rects:[],circles:[]}}},[t,n]),r=V.useMemo(()=>(s.rects?.length||0)===0&&(s.lines?.length||0)===0&&(s.points?.length||0)===0&&(s.circles?.length||0)===0,[s]);V.useEffect(()=>{if(!(typeof document>"u")&&!document.querySelector('script[src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"]')){const c=document.createElement("script");c.src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4",document.head.appendChild(c)}},[]);const a=t.pipelineDef!==void 0,g=c=>{const I=t;if(!t.solved&&!t.failed){for(;!t.solved&&!t.failed&&I.currentPipelineStepIndex<=I.pipelineDef.findIndex(l=>l.solverName===c);)t.step();o()}};return W.jsxs("div",{children:[W.jsx(fni,{solver:t,triggerRender:o,animationSpeed:A,onSolverStarted:e,onSolverCompleted:i}),r?W.jsx("div",{className:"p-4 text-gray-500",children:"No Graphics Yet"}):W.jsx(kni,{fallback:W.jsx(vni,{graphics:s}),children:W.jsx(uni,{graphics:s})}),a&&W.jsx(_ni,{solver:t,onStepUntilPhase:g})]})};const Mni=()=>{V.useEffect(()=>{const t="tailwind-cdn-script";if(document.getElementById(t)||window.tailwind)return;const A=document.createElement("div");A.className="hidden",document.body.appendChild(A);const e=window.getComputedStyle(A).display==="none";if(document.body.removeChild(A),e)return;const i=document.createElement("script");i.id=t,i.src="https://cdn.tailwindcss.com",document.head.appendChild(i)},[])},Rni=t=>t.toLowerCase().includes("pack")?yqt:t.toLowerCase().includes("rout")?bqt:rqt,Nni=({solverEvents:t=[]})=>{const[A,e]=V.useState(null);Mni();const i=V.useMemo(()=>{const r=new Map;for(const a of t){const g=`${a.componentName}-${a.solverName}`;r.set(g,a)}return r},[t]),n=V.useMemo(()=>Array.from(i.keys()),[i]),o=A?i.get(A):null,s=V.useMemo(()=>{if(!o)return{instance:null,error:null,classFound:!1};const r=WrA[o.solverName];if(!r)return{instance:null,error:`Solver class "${o.solverName}" not found in SOLVERS registry. Available: ${Object.keys(WrA).join(", ")}`,classFound:!1};try{const a=o.solverParams,g=a?.input!==void 0?a.input:a;return{instance:new r(g),error:null,classFound:!0}}catch(a){const g=a instanceof Error?a.message:String(a);return console.error("Failed to reconstruct solver:",a),{instance:null,error:`Failed to instantiate solver: ${g}`,classFound:!0}}},[o]);return t.length===0?W.jsx("div",{className:"rf-p-4",children:W.jsx("div",{className:"rf-bg-gray-50 rf-rounded-md rf-border rf-border-gray-200",children:W.jsxs("div",{className:"rf-p-4",children:[W.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800 rf-mb-3",children:"No Solvers Detected"}),W.jsx("p",{className:"rf-text-sm rf-text-gray-600",children:"Solvers will appear here when the circuit runs. Solvers are used for tasks like component packing and autorouting."})]})})}):W.jsxs("div",{className:"rf-flex rf-h-full rf-overflow-hidden",children:[W.jsxs("div",{className:"rf-w-64 rf-border-r rf-border-gray-200 rf-overflow-y-auto rf-flex-shrink-0",children:[W.jsxs("div",{className:"rf-text-xs rf-font-semibold rf-text-gray-500 rf-px-3 rf-py-2 rf-bg-gray-50 rf-border-b rf-border-gray-200",children:[n.length," ",n.length===1?"Solver":"Solvers"]}),n.map(r=>{const a=i.get(r),g=A===r;return W.jsx("div",{className:`rf-px-3 rf-py-2 rf-cursor-pointer rf-border-b rf-border-gray-100 ${g?"rf-bg-blue-50 rf-border-l-2 rf-border-l-blue-500":"hover:rf-bg-gray-50"}`,onClick:()=>e(r),children:(()=>{const c=Rni(a.solverName);return W.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[W.jsx(c,{className:"rf-w-4 rf-h-4 rf-text-blue-500 rf-flex-shrink-0"}),W.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[W.jsx("div",{className:"rf-text-sm rf-font-medium rf-text-gray-800 rf-truncate",children:a.componentName}),W.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate",children:a.solverName})]})]})})()},r)})]}),W.jsx("div",{className:"rf-flex-1 rf-overflow-hidden",children:o?s.instance?W.jsx(Dm,{fallback:W.jsx("div",{className:"rf-p-4",children:W.jsxs("div",{className:"rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200 rf-p-4",children:[W.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-2",children:"Error Loading Solver Debugger"}),W.jsxs("p",{className:"rf-text-sm rf-text-red-600",children:["Failed to render the solver debugger for"," ",o.solverName]})]})}),children:W.jsx(Fni,{solver:s.instance})}):W.jsxs("div",{className:"rf-p-4",children:[W.jsxs("div",{className:"rf-mb-4",children:[W.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800",children:o.solverName}),W.jsxs("p",{className:"rf-text-sm rf-text-gray-500",children:["Component: ",o.componentName]})]}),s.error&&W.jsx("div",{className:`rf-rounded-md rf-border rf-p-4 rf-mb-4 ${s.classFound?"rf-bg-red-50 rf-border-red-200":"rf-bg-yellow-50 rf-border-yellow-200"}`,children:W.jsx("p",{className:`rf-text-sm ${s.classFound?"rf-text-red-700":"rf-text-yellow-700"}`,children:s.error})}),W.jsxs("div",{className:"rf-border rf-border-gray-200 rf-rounded-md rf-overflow-hidden",children:[W.jsx("div",{className:"rf-px-3 rf-py-2 rf-bg-gray-50",children:W.jsx("span",{className:"rf-text-sm rf-font-medium rf-text-gray-700",children:"Solver Parameters"})}),W.jsx("div",{className:"rf-p-3 rf-bg-white rf-border-t rf-border-gray-200",children:W.jsx("pre",{className:"rf-text-xs rf-font-mono rf-text-gray-600 rf-whitespace-pre-wrap rf-overflow-x-auto",children:JSON.stringify(o.solverParams,null,2)})})]})]}):W.jsx("div",{className:"rf-flex rf-items-center rf-justify-center rf-h-full",children:W.jsx("p",{className:"rf-text-sm rf-text-gray-500",children:"Select a solver from the list to view details"})})})]})},yEe=({errorMessage:t,errorStack:A,circuitJsonErrors:e})=>{V.useEffect(()=>{if(t){const i=new Error(t);A&&(i.stack=A);try{qW.captureException(i)}catch{}}},[t,A]),V.useEffect(()=>{if(e&&e.length>0)for(const i of e){const n=new Error(i.message||"Circuit JSON Error");i.stack&&(n.stack=i.stack);try{qW.captureException(n,{error_type:i.type})}catch{}}},[e])},mEe="0.0.1750",Gni={version:mEe},Jz=M4A()(R4A(t=>({lastRunEvalVersion:void 0,setLastRunEvalVersion:A=>{t({lastRunEvalVersion:A})}}),{name:"runframe-runner-store"})),Lni=t=>{const[A,e]=V.useState([]),[i,n]=V.useState(null),[o,s]=V.useState(""),[r,a]=cG("eval-version-selection",null),g=Jz(B=>B.setLastRunEvalVersion),c=Jz(B=>B.lastRunEvalVersion);return V.useEffect(()=>{t&&fetch("https://data.jsdelivr.com/v1/package/npm/@tscircuit/eval").then(B=>B.json()).then(B=>{if(Array.isArray(B?.versions)){let C=[...B.versions];B.tags?.latest&&(n(B.tags.latest),C=C.filter(Q=>Q!==B.tags.latest)),e(C)}}).catch(()=>{})},[t]),V.useEffect(()=>{t&&(r?(window.TSCIRCUIT_LATEST_EVAL_VERSION=r,g(r)):i&&(window.TSCIRCUIT_LATEST_EVAL_VERSION=i,g(i)))},[t,r,i]),{versions:V.useMemo(()=>A.filter(B=>B.includes(o)).slice(0,50),[A,o]),latestVersion:i,lastRunEvalVersion:c,search:o,setSearch:s,selectVersion:B=>{a(B),s("")}}},Uni=({snippetNames:t,onSelect:A,onCancel:e,isOpen:i})=>{const[n,o]=V.useState(""),[s,r]=V.useState("");if(!i)return null;const a=t.filter(I=>I.toLowerCase().includes(s.toLowerCase())),g=s&&!t.includes(s),c=I=>{I.key==="Enter"&&(a.length===1?o(a[0]):g&&o(s))};return W.jsx("div",{className:"rf-fixed rf-inset-0 rf-bg-black rf-bg-opacity-50 rf-flex rf-items-center rf-justify-center rf-z-[100]",children:W.jsxs("div",{className:"rf-bg-white rf-rounded-lg rf-p-6 rf-w-96",children:[W.jsx("h2",{className:"rf-text-lg rf-font-semibold rf-mb-4",children:"Select Snippet"}),W.jsx("input",{type:"text",className:"rf-w-full rf-px-4 rf-py-2 rf-border rf-rounded rf-mb-4",placeholder:"Search snippets or new snippet name...",value:s,onChange:I=>r(I.target.value),onKeyDown:c}),W.jsxs("div",{className:"rf-h-60 rf-overflow-y-auto",children:[a.map(I=>W.jsx("button",{type:"button",className:`w-full text-left px-4 py-2 rounded hover:bg-gray-100 ${n===I?"bg-blue-50":""}`,onClick:()=>o(I),children:I},I)),g&&W.jsxs("button",{type:"button",className:`w-full text-left px-4 py-2 rounded hover:bg-gray-100 text-blue-500 ${n===s?"bg-blue-50":""}`,onClick:()=>o(s),children:['Create new "',s,'"']})]}),W.jsxs("div",{className:"rf-mt-4 rf-flex rf-justify-end rf-gap-2",children:[W.jsx("button",{type:"button",className:"rf-px-4 rf-py-2 rf-text-gray-600 rf-hover:text-gray-800",onClick:e,children:"Cancel"}),W.jsx("button",{type:"button",className:"rf-px-4 rf-py-2 rf-bg-blue-500 rf-text-white rf-rounded rf-hover:bg-blue-600 rf-disabled:opacity-50",onClick:()=>n&&A(n),disabled:!n,children:n===s?`Create "${n}"`:`Save to ${n}`})]})]})})},Hni=t=>{const A=V.useRef(null),e=MI(i=>i.recentEvents);V.useEffect(()=>{if(e.length===0)return;const i=e[0];i.event_id!==A.current&&(t(i),A.current=i.event_id)},[e,t])};function Yni(t){const A=Jni(t),e=V.forwardRef((i,n)=>{const{children:o,...s}=i,r=V.Children.toArray(o),a=r.find(Pni);if(a){const g=a.props.children,c=r.map(I=>I===a?V.Children.count(g)>1?V.Children.only(null):V.isValidElement(g)?g.props.children:null:I);return W.jsx(A,{...s,ref:n,children:V.isValidElement(g)?V.cloneElement(g,void 0,c):null})}return W.jsx(A,{...s,ref:n,children:o})});return e.displayName=`${t}.Slot`,e}function Jni(t){const A=V.forwardRef((e,i)=>{const{children:n,...o}=e;if(V.isValidElement(n)){const s=qni(n),r=Kni(o,n.props);return n.type!==V.Fragment&&(r.ref=i?_f(i,s):s),V.cloneElement(n,r)}return V.Children.count(n)>1?V.Children.only(null):null});return A.displayName=`${t}.SlotClone`,A}var Tni=Symbol("radix.slottable");function Pni(t){return V.isValidElement(t)&&typeof t.type=="function"&&"__radixId"in t.type&&t.type.__radixId===Tni}function Kni(t,A){const e={...A};for(const i in A){const n=t[i],o=A[i];/^on[A-Z]/.test(i)?n&&o?e[i]=(...r)=>{const a=o(...r);return n(...r),a}:n&&(e[i]=n):i==="style"?e[i]={...n,...o}:i==="className"&&(e[i]=[n,o].filter(Boolean).join(" "))}return{...t,...e}}function qni(t){let A=Object.getOwnPropertyDescriptor(t.props,"ref")?.get,e=A&&"isReactWarning"in A&&A.isReactWarning;return e?t.ref:(A=Object.getOwnPropertyDescriptor(t,"ref")?.get,e=A&&"isReactWarning"in A&&A.isReactWarning,e?t.props.ref:t.props.ref||t.ref)}var Tz="Dialog",[wEe,DEe]=dw(Tz),[Oni,Ow]=wEe(Tz),SEe=t=>{const{__scopeDialog:A,children:e,open:i,defaultOpen:n,onOpenChange:o,modal:s=!0}=t,r=V.useRef(null),a=V.useRef(null),[g,c]=G_({prop:i,defaultProp:n??!1,onChange:o,caller:Tz});return W.jsx(Oni,{scope:A,triggerRef:r,contentRef:a,contentId:qE(),titleId:qE(),descriptionId:qE(),open:g,onOpenChange:c,onOpenToggle:V.useCallback(()=>c(I=>!I),[c]),modal:s,children:e})};SEe.displayName=Tz;var bEe="DialogTrigger",xEe=V.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,n=Ow(bEe,e),o=RI(A,n.triggerRef);return W.jsx(Ag.button,{type:"button","aria-haspopup":"dialog","aria-expanded":n.open,"aria-controls":n.contentId,"data-state":GmA(n.open),...i,ref:o,onClick:Vn(t.onClick,n.onOpenToggle)})});xEe.displayName=bEe;var RmA="DialogPortal",[Wni,_Ee]=wEe(RmA,{forceMount:void 0}),kEe=t=>{const{__scopeDialog:A,forceMount:e,children:i,container:n}=t,o=Ow(RmA,A);return W.jsx(Wni,{scope:A,forceMount:e,children:V.Children.map(i,s=>W.jsx(q0,{present:e||o.open,children:W.jsx($9,{asChild:!0,container:n,children:s})}))})};kEe.displayName=RmA;var Pz="DialogOverlay",vEe=V.forwardRef((t,A)=>{const e=_Ee(Pz,t.__scopeDialog),{forceMount:i=e.forceMount,...n}=t,o=Ow(Pz,t.__scopeDialog);return o.modal?W.jsx(q0,{present:i||o.open,children:W.jsx(Vni,{...n,ref:A})}):null});vEe.displayName=Pz;var Zni=Yni("DialogOverlay.RemoveScroll"),Vni=V.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,n=Ow(Pz,e);return W.jsx(rj,{as:Zni,allowPinchZoom:!0,shards:[n.contentRef],children:W.jsx(Ag.div,{"data-state":GmA(n.open),...i,ref:A,style:{pointerEvents:"auto",...i.style}})})}),PM="DialogContent",FEe=V.forwardRef((t,A)=>{const e=_Ee(PM,t.__scopeDialog),{forceMount:i=e.forceMount,...n}=t,o=Ow(PM,t.__scopeDialog);return W.jsx(q0,{present:i||o.open,children:o.modal?W.jsx(jni,{...n,ref:A}):W.jsx(zni,{...n,ref:A})})});FEe.displayName=PM;var jni=V.forwardRef((t,A)=>{const e=Ow(PM,t.__scopeDialog),i=V.useRef(null),n=RI(A,e.contentRef,i);return V.useEffect(()=>{const o=i.current;if(o)return jfA(o)},[]),W.jsx(MEe,{...t,ref:n,trapFocus:e.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:Vn(t.onCloseAutoFocus,o=>{o.preventDefault(),e.triggerRef.current?.focus()}),onPointerDownOutside:Vn(t.onPointerDownOutside,o=>{const s=o.detail.originalEvent,r=s.button===0&&s.ctrlKey===!0;(s.button===2||r)&&o.preventDefault()}),onFocusOutside:Vn(t.onFocusOutside,o=>o.preventDefault())})}),zni=V.forwardRef((t,A)=>{const e=Ow(PM,t.__scopeDialog),i=V.useRef(!1),n=V.useRef(!1);return W.jsx(MEe,{...t,ref:A,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:o=>{t.onCloseAutoFocus?.(o),o.defaultPrevented||(i.current||e.triggerRef.current?.focus(),o.preventDefault()),i.current=!1,n.current=!1},onInteractOutside:o=>{t.onInteractOutside?.(o),o.defaultPrevented||(i.current=!0,o.detail.originalEvent.type==="pointerdown"&&(n.current=!0));const s=o.target;e.triggerRef.current?.contains(s)&&o.preventDefault(),o.detail.originalEvent.type==="focusin"&&n.current&&o.preventDefault()}})}),MEe=V.forwardRef((t,A)=>{const{__scopeDialog:e,trapFocus:i,onOpenAutoFocus:n,onCloseAutoFocus:o,...s}=t,r=Ow(PM,e),a=V.useRef(null),g=RI(A,a);return vfA(),W.jsxs(W.Fragment,{children:[W.jsx(Y9,{asChild:!0,loop:!0,trapped:i,onMountAutoFocus:n,onUnmountAutoFocus:o,children:W.jsx(qJ,{role:"dialog",id:r.contentId,"aria-describedby":r.descriptionId,"aria-labelledby":r.titleId,"data-state":GmA(r.open),...s,ref:g,onDismiss:()=>r.onOpenChange(!1)})}),W.jsxs(W.Fragment,{children:[W.jsx($ni,{titleId:r.titleId}),W.jsx(eoi,{contentRef:a,descriptionId:r.descriptionId})]})]})}),NmA="DialogTitle",REe=V.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,n=Ow(NmA,e);return W.jsx(Ag.h2,{id:n.titleId,...i,ref:A})});REe.displayName=NmA;var NEe="DialogDescription",GEe=V.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,n=Ow(NEe,e);return W.jsx(Ag.p,{id:n.descriptionId,...i,ref:A})});GEe.displayName=NEe;var LEe="DialogClose",UEe=V.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,n=Ow(LEe,e);return W.jsx(Ag.button,{type:"button",...i,ref:A,onClick:Vn(t.onClick,()=>n.onOpenChange(!1))})});UEe.displayName=LEe;function GmA(t){return t?"open":"closed"}var HEe="DialogTitleWarning",[Xni,YEe]=Kat(HEe,{contentName:PM,titleName:NmA,docsSlug:"dialog"}),$ni=({titleId:t})=>{const A=YEe(HEe),e=`\`${A.contentName}\` requires a \`${A.titleName}\` for the component to be accessible for screen reader users.
5692
+ `,I=new Blob([c],{type:"text/plain"}),l=URL.createObjectURL(I),B=document.createElement("a");B.href=l,B.download=`${g}.test.ts`,B.click(),URL.revokeObjectURL(l)}catch(a){alert(`Error generating test.ts for ${t.constructor.name}: ${a instanceof Error?a.message:String(a)}`)}i(!1)};return W.jsxs("div",{className:`relative ${A}`,ref:n,children:[W.jsx("button",{className:"px-2 py-1 rounded text-xs cursor-pointer",onClick:()=>i(!e),title:`Download options for ${t.constructor.name}`,children:t.constructor.name}),e&&W.jsxs("div",{className:"absolute top-full left-0 mt-1 bg-white border border-gray-300 rounded shadow-lg z-10 min-w-[150px]",children:[W.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:o,children:"Download JSON"}),W.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:s,children:"Download page.tsx"}),W.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:r,children:"Download test.ts"})]})]})},fEe=t=>t.activeSubSolver?[t,...fEe(t.activeSubSolver)]:[t],pni=({solver:t})=>{const A=fEe(t);return W.jsx("div",{className:"flex gap-1 items-center text-sm pt-1",children:A.map((e,i)=>W.jsxs("div",{className:"flex items-center",children:[i>0&&W.jsx("span",{className:"text-gray-400 mx-1",children:"→"}),W.jsx(dni,{solver:e})]},e.constructor.name))})},fni=({solver:t,triggerRender:A,animationSpeed:e=25,onSolverStarted:i,onSolverCompleted:n})=>{const[o,s]=V.useReducer(Q=>!Q,!1),r=V.useRef(void 0),a=()=>{!t.solved&&!t.failed&&(t.step(),A())},g=()=>{!t.solved&&!t.failed&&(i&&i(t),t.solve(),A(),n&&n(t))},c=()=>{o?(r.current&&(clearInterval(r.current),r.current=void 0),s()):(s(),r.current=setInterval(()=>{if(t.solved||t.failed){r.current&&(clearInterval(r.current),r.current=void 0),s(),A(),n&&t.solved&&n(t);return}t.step(),A()},e))},I=()=>{const Q=t;if(Q.getCurrentPhase&&!t.solved&&!t.failed){const h=Q.getCurrentPhase();for(;Q.getCurrentPhase()===h&&!t.solved&&!t.failed;)t.step();A()}},l=()=>{if(t.solved||t.failed||o)return;const Q=window.prompt("Step until which iteration?",`${t.iterations}`);if(Q===null)return;const h=Number(Q);if(!Number.isFinite(h)){window.alert("Please enter a valid number for the iteration");return}for(;t.iterations<h&&!t.solved&&!t.failed;)t.step();A(),t.solved&&n&&n(t)};V.useEffect(()=>()=>{r.current&&clearInterval(r.current)},[]),V.useEffect(()=>{(t.solved||t.failed)&&o&&(r.current&&(clearInterval(r.current),r.current=void 0),s())},[t.solved,t.failed,o]);const B=t.getCurrentPhase!==void 0,C=B?t.getCurrentPhase():null;return W.jsxs("div",{className:"space-y-2 p-2 border-b",children:[W.jsx("div",{className:"flex items-center",children:W.jsx(pni,{solver:t})}),W.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[W.jsx("button",{onClick:a,disabled:t.solved||t.failed||o,className:"bg-blue-500 hover:bg-blue-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step"}),W.jsx("button",{onClick:g,disabled:t.solved||t.failed||o,className:"bg-green-500 hover:bg-green-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Solve"}),W.jsx("button",{onClick:c,disabled:t.solved||t.failed,className:`px-3 py-1 rounded text-white text-sm ${o?"bg-red-500 hover:bg-red-600":"bg-yellow-500 hover:bg-yellow-600"} disabled:bg-gray-300`,children:o?"Stop":"Animate"}),W.jsx("button",{onClick:l,disabled:t.solved||t.failed||o,className:"bg-orange-500 hover:bg-orange-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step Until Iteration"}),B&&W.jsx("button",{onClick:I,disabled:t.solved||t.failed||o,className:"bg-purple-500 hover:bg-purple-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Next Stage"}),W.jsxs("div",{className:"text-sm text-gray-600",children:["Iterations: ",t.iterations]}),t.timeToSolve!==void 0&&W.jsxs("div",{className:"text-sm text-gray-600",children:["Time: ",(t.timeToSolve/1e3).toFixed(3),"s"]}),C&&W.jsxs("div",{className:"text-sm text-gray-600",children:["Phase: ",W.jsx("span",{className:"font-medium",children:C})]}),t.solved&&W.jsx("div",{className:"px-2 py-1 bg-green-100 text-green-800 rounded text-sm",children:"Solved"}),t.failed&&W.jsx("div",{className:"px-2 py-1 bg-red-100 text-red-800 rounded text-sm",children:"Failed"})]}),t.error&&W.jsxs("div",{className:"text-red-600 text-sm",children:["Error: ",t.error]})]})},yni=(t,A,e)=>{const i=t.currentPipelineStepIndex;return A<i?"Completed":A===i&&t.activeSubSolver?t.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},mni=(t,A)=>{const i=t.pipelineDef[A].solverName,n=yni(t,A),o=t[i],s=t.firstIterationOfPhase?.[i]??null,r=t.iterations;let a=0;if(n==="Completed"){const l=t.pipelineDef[A+1],B=l?t.firstIterationOfPhase?.[l.solverName]:void 0;B!==void 0&&s!==null?a=B-s:s!==null&&(a=r-s)}else n==="In Progress"&&s!==null&&(a=r-s);const g=t.timeSpentOnPhase?.[i]??0;let c=0;n==="Completed"?c=1:n==="In Progress"&&o&&(c=o.progress??0);const I=o?.stats??null;return{index:A,name:i,status:n,firstIteration:s,iterations:a,progress:c,timeSpent:g,stats:I&&Object.keys(I).length>0?I:null,solverInstance:o??null}},wni=({status:t})=>{const A={"Not Started":"text-blue-600","In Progress":"text-yellow-600",Completed:"text-green-600",Failed:"text-red-600"};return W.jsx("span",{className:`font-medium ${A[t]}`,children:t})},Dni=({progress:t})=>{if(t===0)return null;const A=Math.round(t*100);return W.jsxs("div",{className:"flex items-center gap-2",children:[W.jsx("div",{className:"w-20 h-2 bg-gray-200 rounded overflow-hidden",children:W.jsx("div",{className:"h-full bg-blue-500 transition-all duration-200",style:{width:`${A}%`}})}),W.jsxs("span",{className:"text-xs text-gray-500",children:[A,"%"]})]})},Sni=t=>Object.entries(t).map(([A,e])=>`${A}: ${e}`).join(", "),bni=({stats:t})=>{if(!t||Object.keys(t).length===0)return W.jsx("span",{children:"-"});const A=Object.entries(t),e=Sni(t);return W.jsxs("details",{className:"cursor-pointer",children:[W.jsx("summary",{className:"whitespace-nowrap overflow-hidden text-ellipsis max-w-[200px]",children:e}),W.jsx("div",{className:"mt-1 text-xs",children:A.map(([i,n])=>W.jsxs("div",{children:[i,": ",String(n)]},i))})]})},MmA=t=>{if(t===null||typeof t!="object")return t;if(Array.isArray(t))return t.map(MmA);const A={};for(const[e,i]of Object.entries(t))e.startsWith("_")||(A[e]=MmA(i));return A},xni=(t,A)=>{try{if(typeof t.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${A}`);return}const e=MmA(t.getConstructorParams()),i=new Blob([JSON.stringify(e,null,2)],{type:"application/json"}),n=URL.createObjectURL(i),o=document.createElement("a");o.href=n,o.download=`${A}_input.json`,o.click(),URL.revokeObjectURL(n)}catch(e){alert(`Error downloading input for ${A}: ${e instanceof Error?e.message:String(e)}`)}},_ni=({solver:t,onStepUntilPhase:A,onDownloadInput:e})=>{const i=t.pipelineDef.map((r,a)=>mni(t,a)),n=r=>{A?.(r)},o=r=>{r.solverInstance&&(e?e(r.solverInstance,r.name):xni(r.solverInstance,r.name))},s=r=>`${(r/1e3).toFixed(2)}s`;return W.jsxs("div",{className:"border-t border-gray-200",children:[W.jsx("div",{className:"px-4 py-2 bg-gray-50 border-b border-gray-200",children:W.jsx("h3",{className:"text-sm font-semibold text-gray-700",children:"Pipeline Steps"})}),W.jsx("div",{className:"overflow-x-auto",children:W.jsxs("table",{className:"w-full text-sm",children:[W.jsx("thead",{children:W.jsxs("tr",{className:"bg-gray-50 border-b border-gray-200",children:[W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Step"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Status"}),W.jsxs("th",{className:"px-4 py-2 text-center font-semibold text-gray-700",children:["i",W.jsx("sub",{children:"0"})]}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Iterations"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Progress"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Time"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stats"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Input"})]})}),W.jsx("tbody",{children:i.map(r=>W.jsxs("tr",{className:`border-b border-gray-100 ${r.status==="In Progress"?"bg-yellow-50":""}`,children:[W.jsx("td",{className:"px-4 py-2",children:W.jsxs("div",{className:"flex items-center gap-2",children:[W.jsx("span",{className:"text-gray-400 w-6",children:String(r.index+1).padStart(2,"0")}),W.jsx("button",{onClick:()=>n(r.name),disabled:r.status==="Completed"||t.solved||t.failed,className:"text-blue-500 hover:text-blue-700 disabled:text-gray-300 disabled:cursor-not-allowed",title:`Step until ${r.name} completes`,children:W.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:W.jsx("path",{fillRule:"evenodd",d:"M4.5 5.653c0-1.426 1.529-2.33 2.779-1.643l11.54 6.348c1.295.712 1.295 2.573 0 3.285L7.28 19.991c-1.25.687-2.779-.217-2.779-1.643V5.653z",clipRule:"evenodd"})})}),W.jsx("span",{className:"font-medium text-gray-900",children:r.name})]})}),W.jsx("td",{className:"px-4 py-2",children:W.jsx(wni,{status:r.status})}),W.jsx("td",{className:"px-4 py-2 text-center text-gray-600",children:r.firstIteration!==null?r.firstIteration:""}),W.jsx("td",{className:"px-4 py-2 text-gray-600",children:r.iterations}),W.jsx("td",{className:"px-4 py-2",children:W.jsx(Dni,{progress:r.progress})}),W.jsx("td",{className:"px-4 py-2 text-gray-600",children:s(r.timeSpent)}),W.jsx("td",{className:"px-4 py-2 text-gray-500",children:W.jsx(bni,{stats:r.stats})}),W.jsx("td",{className:"px-4 py-2",children:r.solverInstance?W.jsxs("button",{onClick:()=>o(r),className:"flex items-center gap-1 text-blue-500 hover:text-blue-700",title:`Download input for ${r.name}`,children:[W.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:W.jsx("path",{fillRule:"evenodd",d:"M12 2.25a.75.75 0 01.75.75v11.69l3.22-3.22a.75.75 0 111.06 1.06l-4.5 4.5a.75.75 0 01-1.06 0l-4.5-4.5a.75.75 0 111.06-1.06l3.22 3.22V3a.75.75 0 01.75-.75zm-9 13.5a.75.75 0 01.75.75v2.25a1.5 1.5 0 001.5 1.5h13.5a1.5 1.5 0 001.5-1.5V16.5a.75.75 0 011.5 0v2.25a3 3 0 01-3 3H5.25a3 3 0 01-3-3V16.5a.75.75 0 01.75-.75z",clipRule:"evenodd"})}),W.jsx("span",{children:"Input"})]}):null})]},r.name))})]})})]})},kni=class extends Qn.Component{constructor(t){super(t),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(t){console.error("InteractiveGraphics render error:",t)}render(){return this.state.hasError?this.props.fallback:this.props.children}};function vni({graphics:t}){const A=t.points??[],e=t.lines??[],i=t.rects??[],n=t.circles??[],o=t.texts??[];let s=Number.POSITIVE_INFINITY,r=Number.POSITIVE_INFINITY,a=Number.NEGATIVE_INFINITY,g=Number.NEGATIVE_INFINITY;const c=(h,E)=>{typeof h=="number"&&(h<s&&(s=h),h>a&&(a=h)),typeof E=="number"&&(E<r&&(r=E),E>g&&(g=E))};for(const h of A)c(h.x,h.y);for(const h of e){const E=h.points??[];for(const u of E)c(u.x,u.y)}for(const h of i){const E=h.x??0,u=h.y??0,d=h.width??0,f=h.height??0;c(E,u),c(E+d,u+f)}for(const h of n){const E=h.x??0,u=h.y??0,d=h.radius??1;c(E-d,u-d),c(E+d,u+d)}for(const h of o)c(h.x,h.y);(!isFinite(s)||!isFinite(r)||!isFinite(a)||!isFinite(g))&&(s=-20,r=-20,a=20,g=20);const I=10,l=s-I,B=r-I,C=Math.max(1,a-s+2*I),Q=Math.max(1,g-r+2*I);return W.jsxs("svg",{className:"w-full h-[400px] bg-white",viewBox:`${l} ${B} ${C} ${Q}`,role:"img","aria-label":"Graphics fallback",children:[i.map((h,E)=>W.jsx("rect",{x:h.x??0,y:h.y??0,width:h.width??0,height:h.height??0,fill:"none",stroke:h.strokeColor??"black",strokeWidth:h.strokeWidth??1},`rect-${E}`)),e.map((h,E)=>W.jsx("polyline",{fill:"none",stroke:h.strokeColor??"black",strokeWidth:h.strokeWidth??1,points:(h.points??[]).map(u=>`${u.x??0},${u.y??0}`).join(" ")},`line-${E}`)),n.map((h,E)=>W.jsx("circle",{cx:h.x??0,cy:h.y??0,r:h.radius??1.5,fill:h.fillColor??"none",stroke:h.strokeColor??"black",strokeWidth:h.strokeWidth??1},`circle-${E}`)),A.map((h,E)=>W.jsx("circle",{cx:h.x??0,cy:h.y??0,r:h.radius??1.5,fill:h.color??"black"},`point-${E}`)),o.map((h,E)=>W.jsx("text",{x:h.x??0,y:h.y??0,fontSize:h.fontSize??10,fill:h.color??"black",children:h.text??""},`text-${E}`))]})}var Fni=({solver:t,animationSpeed:A=25,onSolverStarted:e,onSolverCompleted:i})=>{const[n,o]=V.useReducer(c=>c+1,0),s=V.useMemo(()=>{try{return t.visualize()||{points:[],lines:[],rects:[],circles:[]}}catch(c){return console.error("Visualization error:",c),{points:[],lines:[],rects:[],circles:[]}}},[t,n]),r=V.useMemo(()=>(s.rects?.length||0)===0&&(s.lines?.length||0)===0&&(s.points?.length||0)===0&&(s.circles?.length||0)===0,[s]);V.useEffect(()=>{if(!(typeof document>"u")&&!document.querySelector('script[src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"]')){const c=document.createElement("script");c.src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4",document.head.appendChild(c)}},[]);const a=t.pipelineDef!==void 0,g=c=>{const I=t;if(!t.solved&&!t.failed){for(;!t.solved&&!t.failed&&I.currentPipelineStepIndex<=I.pipelineDef.findIndex(l=>l.solverName===c);)t.step();o()}};return W.jsxs("div",{children:[W.jsx(fni,{solver:t,triggerRender:o,animationSpeed:A,onSolverStarted:e,onSolverCompleted:i}),r?W.jsx("div",{className:"p-4 text-gray-500",children:"No Graphics Yet"}):W.jsx(kni,{fallback:W.jsx(vni,{graphics:s}),children:W.jsx(uni,{graphics:s})}),a&&W.jsx(_ni,{solver:t,onStepUntilPhase:g})]})};const Mni=()=>{V.useEffect(()=>{const t="tailwind-cdn-script";if(document.getElementById(t)||window.tailwind)return;const A=document.createElement("div");A.className="hidden",document.body.appendChild(A);const e=window.getComputedStyle(A).display==="none";if(document.body.removeChild(A),e)return;const i=document.createElement("script");i.id=t,i.src="https://cdn.tailwindcss.com",document.head.appendChild(i)},[])},Rni=t=>t.toLowerCase().includes("pack")?yqt:t.toLowerCase().includes("rout")?bqt:rqt,Nni=({solverEvents:t=[]})=>{const[A,e]=V.useState(null);Mni();const i=V.useMemo(()=>{const r=new Map;for(const a of t){const g=`${a.componentName}-${a.solverName}`;r.set(g,a)}return r},[t]),n=V.useMemo(()=>Array.from(i.keys()),[i]),o=A?i.get(A):null,s=V.useMemo(()=>{if(!o)return{instance:null,error:null,classFound:!1};const r=WrA[o.solverName];if(!r)return{instance:null,error:`Solver class "${o.solverName}" not found in SOLVERS registry. Available: ${Object.keys(WrA).join(", ")}`,classFound:!1};try{const a=o.solverParams,g=a?.input!==void 0?a.input:a;return{instance:new r(g),error:null,classFound:!0}}catch(a){const g=a instanceof Error?a.message:String(a);return console.error("Failed to reconstruct solver:",a),{instance:null,error:`Failed to instantiate solver: ${g}`,classFound:!0}}},[o]);return t.length===0?W.jsx("div",{className:"rf-p-4",children:W.jsx("div",{className:"rf-bg-gray-50 rf-rounded-md rf-border rf-border-gray-200",children:W.jsxs("div",{className:"rf-p-4",children:[W.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800 rf-mb-3",children:"No Solvers Detected"}),W.jsx("p",{className:"rf-text-sm rf-text-gray-600",children:"Solvers will appear here when the circuit runs. Solvers are used for tasks like component packing and autorouting."})]})})}):W.jsxs("div",{className:"rf-flex rf-h-full rf-overflow-hidden",children:[W.jsxs("div",{className:"rf-w-64 rf-border-r rf-border-gray-200 rf-overflow-y-auto rf-flex-shrink-0",children:[W.jsxs("div",{className:"rf-text-xs rf-font-semibold rf-text-gray-500 rf-px-3 rf-py-2 rf-bg-gray-50 rf-border-b rf-border-gray-200",children:[n.length," ",n.length===1?"Solver":"Solvers"]}),n.map(r=>{const a=i.get(r),g=A===r;return W.jsx("div",{className:`rf-px-3 rf-py-2 rf-cursor-pointer rf-border-b rf-border-gray-100 ${g?"rf-bg-blue-50 rf-border-l-2 rf-border-l-blue-500":"hover:rf-bg-gray-50"}`,onClick:()=>e(r),children:(()=>{const c=Rni(a.solverName);return W.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[W.jsx(c,{className:"rf-w-4 rf-h-4 rf-text-blue-500 rf-flex-shrink-0"}),W.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[W.jsx("div",{className:"rf-text-sm rf-font-medium rf-text-gray-800 rf-truncate",children:a.componentName}),W.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate",children:a.solverName})]})]})})()},r)})]}),W.jsx("div",{className:"rf-flex-1 rf-overflow-hidden",children:o?s.instance?W.jsx(Dm,{fallback:W.jsx("div",{className:"rf-p-4",children:W.jsxs("div",{className:"rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200 rf-p-4",children:[W.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-2",children:"Error Loading Solver Debugger"}),W.jsxs("p",{className:"rf-text-sm rf-text-red-600",children:["Failed to render the solver debugger for"," ",o.solverName]})]})}),children:W.jsx(Fni,{solver:s.instance})}):W.jsxs("div",{className:"rf-p-4",children:[W.jsxs("div",{className:"rf-mb-4",children:[W.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800",children:o.solverName}),W.jsxs("p",{className:"rf-text-sm rf-text-gray-500",children:["Component: ",o.componentName]})]}),s.error&&W.jsx("div",{className:`rf-rounded-md rf-border rf-p-4 rf-mb-4 ${s.classFound?"rf-bg-red-50 rf-border-red-200":"rf-bg-yellow-50 rf-border-yellow-200"}`,children:W.jsx("p",{className:`rf-text-sm ${s.classFound?"rf-text-red-700":"rf-text-yellow-700"}`,children:s.error})}),W.jsxs("div",{className:"rf-border rf-border-gray-200 rf-rounded-md rf-overflow-hidden",children:[W.jsx("div",{className:"rf-px-3 rf-py-2 rf-bg-gray-50",children:W.jsx("span",{className:"rf-text-sm rf-font-medium rf-text-gray-700",children:"Solver Parameters"})}),W.jsx("div",{className:"rf-p-3 rf-bg-white rf-border-t rf-border-gray-200",children:W.jsx("pre",{className:"rf-text-xs rf-font-mono rf-text-gray-600 rf-whitespace-pre-wrap rf-overflow-x-auto",children:JSON.stringify(o.solverParams,null,2)})})]})]}):W.jsx("div",{className:"rf-flex rf-items-center rf-justify-center rf-h-full",children:W.jsx("p",{className:"rf-text-sm rf-text-gray-500",children:"Select a solver from the list to view details"})})})]})},yEe=({errorMessage:t,errorStack:A,circuitJsonErrors:e})=>{V.useEffect(()=>{if(t){const i=new Error(t);A&&(i.stack=A);try{qW.captureException(i)}catch{}}},[t,A]),V.useEffect(()=>{if(e&&e.length>0)for(const i of e){const n=new Error(i.message||"Circuit JSON Error");i.stack&&(n.stack=i.stack);try{qW.captureException(n,{error_type:i.type})}catch{}}},[e])},mEe="0.0.1752",Gni={version:mEe},Jz=M4A()(R4A(t=>({lastRunEvalVersion:void 0,setLastRunEvalVersion:A=>{t({lastRunEvalVersion:A})}}),{name:"runframe-runner-store"})),Lni=t=>{const[A,e]=V.useState([]),[i,n]=V.useState(null),[o,s]=V.useState(""),[r,a]=cG("eval-version-selection",null),g=Jz(B=>B.setLastRunEvalVersion),c=Jz(B=>B.lastRunEvalVersion);return V.useEffect(()=>{t&&fetch("https://data.jsdelivr.com/v1/package/npm/@tscircuit/eval").then(B=>B.json()).then(B=>{if(Array.isArray(B?.versions)){let C=[...B.versions];B.tags?.latest&&(n(B.tags.latest),C=C.filter(Q=>Q!==B.tags.latest)),e(C)}}).catch(()=>{})},[t]),V.useEffect(()=>{t&&(r?(window.TSCIRCUIT_LATEST_EVAL_VERSION=r,g(r)):i&&(window.TSCIRCUIT_LATEST_EVAL_VERSION=i,g(i)))},[t,r,i]),{versions:V.useMemo(()=>A.filter(B=>B.includes(o)).slice(0,50),[A,o]),latestVersion:i,lastRunEvalVersion:c,search:o,setSearch:s,selectVersion:B=>{a(B),s("")}}},Uni=({snippetNames:t,onSelect:A,onCancel:e,isOpen:i})=>{const[n,o]=V.useState(""),[s,r]=V.useState("");if(!i)return null;const a=t.filter(I=>I.toLowerCase().includes(s.toLowerCase())),g=s&&!t.includes(s),c=I=>{I.key==="Enter"&&(a.length===1?o(a[0]):g&&o(s))};return W.jsx("div",{className:"rf-fixed rf-inset-0 rf-bg-black rf-bg-opacity-50 rf-flex rf-items-center rf-justify-center rf-z-[100]",children:W.jsxs("div",{className:"rf-bg-white rf-rounded-lg rf-p-6 rf-w-96",children:[W.jsx("h2",{className:"rf-text-lg rf-font-semibold rf-mb-4",children:"Select Snippet"}),W.jsx("input",{type:"text",className:"rf-w-full rf-px-4 rf-py-2 rf-border rf-rounded rf-mb-4",placeholder:"Search snippets or new snippet name...",value:s,onChange:I=>r(I.target.value),onKeyDown:c}),W.jsxs("div",{className:"rf-h-60 rf-overflow-y-auto",children:[a.map(I=>W.jsx("button",{type:"button",className:`w-full text-left px-4 py-2 rounded hover:bg-gray-100 ${n===I?"bg-blue-50":""}`,onClick:()=>o(I),children:I},I)),g&&W.jsxs("button",{type:"button",className:`w-full text-left px-4 py-2 rounded hover:bg-gray-100 text-blue-500 ${n===s?"bg-blue-50":""}`,onClick:()=>o(s),children:['Create new "',s,'"']})]}),W.jsxs("div",{className:"rf-mt-4 rf-flex rf-justify-end rf-gap-2",children:[W.jsx("button",{type:"button",className:"rf-px-4 rf-py-2 rf-text-gray-600 rf-hover:text-gray-800",onClick:e,children:"Cancel"}),W.jsx("button",{type:"button",className:"rf-px-4 rf-py-2 rf-bg-blue-500 rf-text-white rf-rounded rf-hover:bg-blue-600 rf-disabled:opacity-50",onClick:()=>n&&A(n),disabled:!n,children:n===s?`Create "${n}"`:`Save to ${n}`})]})]})})},Hni=t=>{const A=V.useRef(null),e=MI(i=>i.recentEvents);V.useEffect(()=>{if(e.length===0)return;const i=e[0];i.event_id!==A.current&&(t(i),A.current=i.event_id)},[e,t])};function Yni(t){const A=Jni(t),e=V.forwardRef((i,n)=>{const{children:o,...s}=i,r=V.Children.toArray(o),a=r.find(Pni);if(a){const g=a.props.children,c=r.map(I=>I===a?V.Children.count(g)>1?V.Children.only(null):V.isValidElement(g)?g.props.children:null:I);return W.jsx(A,{...s,ref:n,children:V.isValidElement(g)?V.cloneElement(g,void 0,c):null})}return W.jsx(A,{...s,ref:n,children:o})});return e.displayName=`${t}.Slot`,e}function Jni(t){const A=V.forwardRef((e,i)=>{const{children:n,...o}=e;if(V.isValidElement(n)){const s=qni(n),r=Kni(o,n.props);return n.type!==V.Fragment&&(r.ref=i?_f(i,s):s),V.cloneElement(n,r)}return V.Children.count(n)>1?V.Children.only(null):null});return A.displayName=`${t}.SlotClone`,A}var Tni=Symbol("radix.slottable");function Pni(t){return V.isValidElement(t)&&typeof t.type=="function"&&"__radixId"in t.type&&t.type.__radixId===Tni}function Kni(t,A){const e={...A};for(const i in A){const n=t[i],o=A[i];/^on[A-Z]/.test(i)?n&&o?e[i]=(...r)=>{const a=o(...r);return n(...r),a}:n&&(e[i]=n):i==="style"?e[i]={...n,...o}:i==="className"&&(e[i]=[n,o].filter(Boolean).join(" "))}return{...t,...e}}function qni(t){let A=Object.getOwnPropertyDescriptor(t.props,"ref")?.get,e=A&&"isReactWarning"in A&&A.isReactWarning;return e?t.ref:(A=Object.getOwnPropertyDescriptor(t,"ref")?.get,e=A&&"isReactWarning"in A&&A.isReactWarning,e?t.props.ref:t.props.ref||t.ref)}var Tz="Dialog",[wEe,DEe]=dw(Tz),[Oni,Ow]=wEe(Tz),SEe=t=>{const{__scopeDialog:A,children:e,open:i,defaultOpen:n,onOpenChange:o,modal:s=!0}=t,r=V.useRef(null),a=V.useRef(null),[g,c]=G_({prop:i,defaultProp:n??!1,onChange:o,caller:Tz});return W.jsx(Oni,{scope:A,triggerRef:r,contentRef:a,contentId:qE(),titleId:qE(),descriptionId:qE(),open:g,onOpenChange:c,onOpenToggle:V.useCallback(()=>c(I=>!I),[c]),modal:s,children:e})};SEe.displayName=Tz;var bEe="DialogTrigger",xEe=V.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,n=Ow(bEe,e),o=RI(A,n.triggerRef);return W.jsx(Ag.button,{type:"button","aria-haspopup":"dialog","aria-expanded":n.open,"aria-controls":n.contentId,"data-state":GmA(n.open),...i,ref:o,onClick:Vn(t.onClick,n.onOpenToggle)})});xEe.displayName=bEe;var RmA="DialogPortal",[Wni,_Ee]=wEe(RmA,{forceMount:void 0}),kEe=t=>{const{__scopeDialog:A,forceMount:e,children:i,container:n}=t,o=Ow(RmA,A);return W.jsx(Wni,{scope:A,forceMount:e,children:V.Children.map(i,s=>W.jsx(q0,{present:e||o.open,children:W.jsx($9,{asChild:!0,container:n,children:s})}))})};kEe.displayName=RmA;var Pz="DialogOverlay",vEe=V.forwardRef((t,A)=>{const e=_Ee(Pz,t.__scopeDialog),{forceMount:i=e.forceMount,...n}=t,o=Ow(Pz,t.__scopeDialog);return o.modal?W.jsx(q0,{present:i||o.open,children:W.jsx(Vni,{...n,ref:A})}):null});vEe.displayName=Pz;var Zni=Yni("DialogOverlay.RemoveScroll"),Vni=V.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,n=Ow(Pz,e);return W.jsx(rj,{as:Zni,allowPinchZoom:!0,shards:[n.contentRef],children:W.jsx(Ag.div,{"data-state":GmA(n.open),...i,ref:A,style:{pointerEvents:"auto",...i.style}})})}),PM="DialogContent",FEe=V.forwardRef((t,A)=>{const e=_Ee(PM,t.__scopeDialog),{forceMount:i=e.forceMount,...n}=t,o=Ow(PM,t.__scopeDialog);return W.jsx(q0,{present:i||o.open,children:o.modal?W.jsx(jni,{...n,ref:A}):W.jsx(zni,{...n,ref:A})})});FEe.displayName=PM;var jni=V.forwardRef((t,A)=>{const e=Ow(PM,t.__scopeDialog),i=V.useRef(null),n=RI(A,e.contentRef,i);return V.useEffect(()=>{const o=i.current;if(o)return jfA(o)},[]),W.jsx(MEe,{...t,ref:n,trapFocus:e.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:Vn(t.onCloseAutoFocus,o=>{o.preventDefault(),e.triggerRef.current?.focus()}),onPointerDownOutside:Vn(t.onPointerDownOutside,o=>{const s=o.detail.originalEvent,r=s.button===0&&s.ctrlKey===!0;(s.button===2||r)&&o.preventDefault()}),onFocusOutside:Vn(t.onFocusOutside,o=>o.preventDefault())})}),zni=V.forwardRef((t,A)=>{const e=Ow(PM,t.__scopeDialog),i=V.useRef(!1),n=V.useRef(!1);return W.jsx(MEe,{...t,ref:A,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:o=>{t.onCloseAutoFocus?.(o),o.defaultPrevented||(i.current||e.triggerRef.current?.focus(),o.preventDefault()),i.current=!1,n.current=!1},onInteractOutside:o=>{t.onInteractOutside?.(o),o.defaultPrevented||(i.current=!0,o.detail.originalEvent.type==="pointerdown"&&(n.current=!0));const s=o.target;e.triggerRef.current?.contains(s)&&o.preventDefault(),o.detail.originalEvent.type==="focusin"&&n.current&&o.preventDefault()}})}),MEe=V.forwardRef((t,A)=>{const{__scopeDialog:e,trapFocus:i,onOpenAutoFocus:n,onCloseAutoFocus:o,...s}=t,r=Ow(PM,e),a=V.useRef(null),g=RI(A,a);return vfA(),W.jsxs(W.Fragment,{children:[W.jsx(Y9,{asChild:!0,loop:!0,trapped:i,onMountAutoFocus:n,onUnmountAutoFocus:o,children:W.jsx(qJ,{role:"dialog",id:r.contentId,"aria-describedby":r.descriptionId,"aria-labelledby":r.titleId,"data-state":GmA(r.open),...s,ref:g,onDismiss:()=>r.onOpenChange(!1)})}),W.jsxs(W.Fragment,{children:[W.jsx($ni,{titleId:r.titleId}),W.jsx(eoi,{contentRef:a,descriptionId:r.descriptionId})]})]})}),NmA="DialogTitle",REe=V.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,n=Ow(NmA,e);return W.jsx(Ag.h2,{id:n.titleId,...i,ref:A})});REe.displayName=NmA;var NEe="DialogDescription",GEe=V.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,n=Ow(NEe,e);return W.jsx(Ag.p,{id:n.descriptionId,...i,ref:A})});GEe.displayName=NEe;var LEe="DialogClose",UEe=V.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,n=Ow(LEe,e);return W.jsx(Ag.button,{type:"button",...i,ref:A,onClick:Vn(t.onClick,()=>n.onOpenChange(!1))})});UEe.displayName=LEe;function GmA(t){return t?"open":"closed"}var HEe="DialogTitleWarning",[Xni,YEe]=Kat(HEe,{contentName:PM,titleName:NmA,docsSlug:"dialog"}),$ni=({titleId:t})=>{const A=YEe(HEe),e=`\`${A.contentName}\` requires a \`${A.titleName}\` for the component to be accessible for screen reader users.
5693
5693
 
5694
5694
  If you want to hide the \`${A.titleName}\`, you can wrap it with our VisuallyHidden component.
5695
5695
 
@@ -5699,7 +5699,7 @@ You can add a description to the \`${b2}\` by passing a \`${VEe}\` component as
5699
5699
 
5700
5700
  Alternatively, you can use your own component as a description by assigning it an \`id\` and passing the same value to the \`aria-describedby\` prop in \`${b2}\`. If the description is confusing or duplicative for sighted users, you can use the \`@radix-ui/react-visually-hidden\` primitive as a wrapper around your description component.
5701
5701
 
5702
- For more information, see https://radix-ui.com/primitives/docs/components/alert-dialog`;return V.useEffect(()=>{document.getElementById(t.current?.getAttribute("aria-describedby"))||console.warn(A)},[A,t]),null},Qoi=PEe,hoi=KEe,Aue=qEe,eue=OEe,tue=zEe,iue=$Ee,nue=ZEe,oue=jEe;const sue=Qoi,Eoi=hoi,rue=V.forwardRef(({className:t,...A},e)=>W.jsx(Aue,{className:hn("rf-fixed rf-inset-0 rf-z-50 rf-bg-black/80 data-[state=open]:rf-animate-in data-[state=closed]:rf-animate-out data-[state=closed]:rf-fade-out-0 data-[state=open]:rf-fade-in-0",t),...A,ref:e}));rue.displayName=Aue.displayName;const JmA=V.forwardRef(({className:t,...A},e)=>W.jsxs(Eoi,{children:[W.jsx(rue,{}),W.jsx(eue,{ref:e,className:hn("rf-fixed rf-left-[50%] rf-top-[50%] rf-z-50 rf-grid rf-w-full rf-max-w-lg rf-translate-x-[-50%] rf-translate-y-[-50%] rf-gap-4 rf-border rf-border-zinc-200 rf-bg-white rf-p-6 rf-shadow-lg rf-duration-200 data-[state=open]:rf-animate-in data-[state=closed]:rf-animate-out data-[state=closed]:rf-fade-out-0 data-[state=open]:rf-fade-in-0 data-[state=closed]:rf-zoom-out-95 data-[state=open]:rf-zoom-in-95 data-[state=closed]:rf-slide-out-to-left-1/2 data-[state=closed]:rf-slide-out-to-top-[48%] data-[state=open]:rf-slide-in-from-left-1/2 data-[state=open]:rf-slide-in-from-top-[48%] sm:rf-rounded-lg dark:rf-border-zinc-800 dark:rf-bg-zinc-950",t),...A})]}));JmA.displayName=eue.displayName;const TmA=({className:t,...A})=>W.jsx("div",{className:hn("rf-flex rf-flex-col rf-space-y-2 rf-text-center sm:rf-text-left",t),...A});TmA.displayName="AlertDialogHeader";const PmA=({className:t,...A})=>W.jsx("div",{className:hn("rf-flex rf-flex-col-reverse sm:rf-flex-row sm:rf-justify-end sm:rf-space-x-2",t),...A});PmA.displayName="AlertDialogFooter";const KmA=V.forwardRef(({className:t,...A},e)=>W.jsx(nue,{ref:e,className:hn("rf-text-lg rf-font-semibold",t),...A}));KmA.displayName=nue.displayName;const qmA=V.forwardRef(({className:t,...A},e)=>W.jsx(oue,{ref:e,className:hn("rf-text-sm rf-text-zinc-500 dark:rf-text-zinc-400",t),...A}));qmA.displayName=oue.displayName;const uoi=V.forwardRef(({className:t,...A},e)=>W.jsx(tue,{ref:e,className:hn(V1(),t),...A}));uoi.displayName=tue.displayName;const OmA=V.forwardRef(({className:t,...A},e)=>W.jsx(iue,{ref:e,className:hn(V1({variant:"outline"}),"rf-mt-2 sm:rf-mt-0",t),...A}));OmA.displayName=iue.displayName;function doi(t){const A=V.useRef({value:t,previous:t});return V.useMemo(()=>(A.current.value!==t&&(A.current.previous=A.current.value,A.current.value=t),A.current.previous),[t])}var Oz="Checkbox",[poi]=dw(Oz),[foi,WmA]=poi(Oz);function yoi(t){const{__scopeCheckbox:A,checked:e,children:i,defaultChecked:n,disabled:o,form:s,name:r,onCheckedChange:a,required:g,value:c="on",internal_do_not_use_render:I}=t,[l,B]=G_({prop:e,defaultProp:n??!1,onChange:a,caller:Oz}),[C,Q]=V.useState(null),[h,E]=V.useState(null),u=V.useRef(!1),d=C?!!s||!!C.closest("form"):!0,f={checked:l,disabled:o,setChecked:B,control:C,setControl:Q,name:r,form:s,value:c,hasConsumerStoppedPropagationRef:u,required:g,defaultChecked:Ok(n)?!1:n,isFormControl:d,bubbleInput:h,setBubbleInput:E};return W.jsx(foi,{scope:A,...f,children:moi(I)?I(f):i})}var aue="CheckboxTrigger",gue=V.forwardRef(({__scopeCheckbox:t,onKeyDown:A,onClick:e,...i},n)=>{const{control:o,value:s,disabled:r,checked:a,required:g,setControl:c,setChecked:I,hasConsumerStoppedPropagationRef:l,isFormControl:B,bubbleInput:C}=WmA(aue,t),Q=RI(n,c),h=V.useRef(a);return V.useEffect(()=>{const E=o?.form;if(E){const u=()=>I(h.current);return E.addEventListener("reset",u),()=>E.removeEventListener("reset",u)}},[o,I]),W.jsx(Ag.button,{type:"button",role:"checkbox","aria-checked":Ok(a)?"mixed":a,"aria-required":g,"data-state":Cue(a),"data-disabled":r?"":void 0,disabled:r,value:s,...i,ref:Q,onKeyDown:Vn(A,E=>{E.key==="Enter"&&E.preventDefault()}),onClick:Vn(e,E=>{I(u=>Ok(u)?!0:!u),C&&B&&(l.current=E.isPropagationStopped(),l.current||E.stopPropagation())})})});gue.displayName=aue;var ZmA=V.forwardRef((t,A)=>{const{__scopeCheckbox:e,name:i,checked:n,defaultChecked:o,required:s,disabled:r,value:a,onCheckedChange:g,form:c,...I}=t;return W.jsx(yoi,{__scopeCheckbox:e,checked:n,defaultChecked:o,disabled:r,required:s,onCheckedChange:g,name:i,form:c,value:a,internal_do_not_use_render:({isFormControl:l})=>W.jsxs(W.Fragment,{children:[W.jsx(gue,{...I,ref:A,__scopeCheckbox:e}),l&&W.jsx(Bue,{__scopeCheckbox:e})]})})});ZmA.displayName=Oz;var cue="CheckboxIndicator",Iue=V.forwardRef((t,A)=>{const{__scopeCheckbox:e,forceMount:i,...n}=t,o=WmA(cue,e);return W.jsx(q0,{present:i||Ok(o.checked)||o.checked===!0,children:W.jsx(Ag.span,{"data-state":Cue(o.checked),"data-disabled":o.disabled?"":void 0,...n,ref:A,style:{pointerEvents:"none",...t.style}})})});Iue.displayName=cue;var lue="CheckboxBubbleInput",Bue=V.forwardRef(({__scopeCheckbox:t,...A},e)=>{const{control:i,hasConsumerStoppedPropagationRef:n,checked:o,defaultChecked:s,required:r,disabled:a,name:g,value:c,form:I,bubbleInput:l,setBubbleInput:B}=WmA(lue,t),C=RI(e,B),Q=doi(o),h=Hre(i);V.useEffect(()=>{const u=l;if(!u)return;const d=window.HTMLInputElement.prototype,y=Object.getOwnPropertyDescriptor(d,"checked").set,w=!n.current;if(Q!==o&&y){const D=new Event("click",{bubbles:w});u.indeterminate=Ok(o),y.call(u,Ok(o)?!1:o),u.dispatchEvent(D)}},[l,Q,o,n]);const E=V.useRef(Ok(o)?!1:o);return W.jsx(Ag.input,{type:"checkbox","aria-hidden":!0,defaultChecked:s??E.current,required:r,disabled:a,name:g,value:c,form:I,...A,tabIndex:-1,ref:C,style:{...A.style,...h,position:"absolute",pointerEvents:"none",opacity:0,margin:0,transform:"translateX(-100%)"}})});Bue.displayName=lue;function moi(t){return typeof t=="function"}function Ok(t){return t==="indeterminate"}function Cue(t){return Ok(t)?"indeterminate":t?"checked":"unchecked"}const zT=V.forwardRef(({className:t,...A},e)=>W.jsx(ZmA,{ref:e,className:hn("rf-peer rf-h-4 rf-w-4 rf-shrink-0 rf-rounded-sm rf-border rf-border-zinc-200 rf-border-zinc-900 rf-shadow focus-visible:rf-outline-none focus-visible:rf-ring-1 focus-visible:rf-ring-zinc-950 disabled:rf-cursor-not-allowed disabled:rf-opacity-50 data-[state=checked]:rf-bg-zinc-900 data-[state=checked]:rf-text-zinc-50 dark:rf-border-zinc-800 dark:rf-border-zinc-50 dark:focus-visible:rf-ring-zinc-300 dark:data-[state=checked]:rf-bg-zinc-50 dark:data-[state=checked]:rf-text-zinc-900",t),...A,children:W.jsx(Iue,{className:hn("rf-flex rf-items-center rf-justify-center rf-text-current"),children:W.jsx(hM,{className:"rf-h-4 rf-w-4"})})}));zT.displayName=ZmA.displayName;const x2=LmA,woi=UmA,Que=V.forwardRef(({className:t,...A},e)=>W.jsx(Kz,{className:hn("rf-fixed rf-inset-0 rf-z-50 rf-bg-black/80 data-[state=open]:rf-animate-in data-[state=closed]:rf-animate-out data-[state=closed]:rf-fade-out-0 data-[state=open]:rf-fade-in-0",t),...A,ref:e}));Que.displayName=Kz.displayName;const KM=V.forwardRef(({className:t,children:A,showOverlay:e=!0,...i},n)=>W.jsxs(woi,{children:[W.jsx(Que,{className:hn(e?"":"rf-hidden")}),W.jsx(qz,{ref:n,className:hn("rf-fixed rf-left-[50%] rf-top-[50%] rf-z-50 rf-grid rf-w-full rf-max-w-lg rf-translate-x-[-50%] rf-translate-y-[-50%] rf-gap-4 rf-border rf-border-zinc-200 rf-bg-white rf-p-6 rf-shadow-lg rf-duration-200 data-[state=open]:rf-animate-in data-[state=closed]:rf-animate-out data-[state=closed]:rf-fade-out-0 data-[state=open]:rf-fade-in-0 data-[state=closed]:rf-zoom-out-95 data-[state=open]:rf-zoom-in-95 data-[state=closed]:rf-slide-out-to-left-1/2 data-[state=closed]:rf-slide-out-to-top-[48%] data-[state=open]:rf-slide-in-from-left-1/2 data-[state=open]:rf-slide-in-from-top-[48%] sm:rf-rounded-lg dark:rf-border-zinc-800 dark:rf-bg-zinc-950",t),...i,children:A})]}));KM.displayName=qz.displayName;const qM=({className:t,...A})=>W.jsx("div",{className:hn("rf-flex rf-flex-col rf-space-y-2 rf-text-center sm:rf-text-left",t),...A});qM.displayName="DialogHeader";const XT=({className:t,...A})=>W.jsx("div",{className:hn("rf-flex rf-flex-col-reverse sm:rf-flex-row sm:rf-justify-end sm:rf-space-x-2",t),...A});XT.displayName="DialogFooter";const OM=V.forwardRef(({className:t,...A},e)=>W.jsx(HmA,{ref:e,className:hn("rf-text-lg rf-font-semibold",t),...A}));OM.displayName=HmA.displayName;const _2=V.forwardRef(({className:t,...A},e)=>W.jsx(YmA,{ref:e,className:hn("rf-text-sm rf-text-zinc-500 dark:rf-text-zinc-400",t),...A}));_2.displayName=YmA.displayName;const Wz={"tscircuit.com":{label:"tscircuit.com",placeholder:"Search tscircuit packages...",emptyMessage:"No packages found"},jlcpcb:{label:"JLCPCB Parts",placeholder:"Search JLCPCB parts (e.g. C14663)...",emptyMessage:"No parts found"},kicad:{label:"KiCad Footprints",placeholder:"Search KiCad footprints...",emptyMessage:"No footprints found"}},Doi="https://cdn.jsdelivr.net/npm/easyeda@latest/dist/browser/index.js";let VmA=null;const Soi=async()=>(VmA||(VmA=import(Doi)),VmA),boi=async(t,A=10)=>{const e=encodeURIComponent(t),i=await fetch(`https://jlcsearch.tscircuit.com/api/search?limit=${A}&q=${e}`);if(!i.ok)throw new Error(`JLCPCB API error: ${i.status}`);return(await i.json()).components??[]},xoi=t=>({lcscId:t.lcsc,manufacturer:t.mfr,description:t.description,partNumber:`C${t.lcsc}`,package:t.package,price:t.price,stock:t.stock,isBasic:t.is_basic}),_oi=async(t,A)=>{const{fetchEasyEDAComponent:e,convertRawEasyToTsx:i}=await Soi(),n=await e(t,{fetch:(o,s)=>fetch(`${A?.apiBase??xf}/proxy`,{...s,headers:{...s?.headers,"X-Target-Url":o.toString(),"X-Sender-Origin":s?.headers?.origin??"","X-Sender-Host":s?.headers?.host??"https://easyeda.com","X-Sender-Referer":s?.headers?.referer??"","X-Sender-User-Agent":s?.headers?.userAgent??"","X-Sender-Cookie":s?.headers?.cookie??"",authority:s?.headers?.authority??"","content-type":s?.headers?.["content-type"]??"",...A?.headers}})});return i(n)},koi=({query:t,placeholder:A,isSearching:e,onQueryChange:i,onSubmit:n})=>{const o=V.useCallback(s=>{s.key==="Enter"&&(s.preventDefault(),n())},[n]);return W.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2 rf-mt-4",children:[W.jsxs("div",{className:"rf-relative rf-flex-grow",children:[W.jsx(xfA,{className:"rf-absolute rf-left-2 rf-top-2.5 rf-h-4 rf-w-4 rf-text-muted-foreground"}),W.jsx(cyA,{placeholder:A,className:"rf-pl-8",spellCheck:!1,autoComplete:"off",value:t,onChange:s=>i(s.target.value),onKeyDown:o})]}),W.jsx(Ja,{onClick:n,disabled:e||t.trim().length<1,className:"sm:rf-px-4 rf-px-3",children:e?W.jsx(Zb,{className:"rf-h-4 rf-w-4 rf-animate-spin"}):W.jsxs(W.Fragment,{children:[W.jsx(xfA,{className:"rf-h-4 rf-w-4 sm:rf-hidden"}),W.jsx("span",{className:"rf-hidden sm:rf-inline",children:"Search"})]})})]})},voi=new Intl.NumberFormat("en-US",{style:"currency",currency:"USD"}),Foi=t=>voi.format(t),hue=t=>{switch(t.source){case"tscircuit.com":{const A=t.package;return`tscircuit-${A.package_id??`${A.org_owner_tscircuit_handle??"unknown"}-${A.unscoped_name??A.name??"package"}`}`}case"jlcpcb":return`jlc-${t.component.lcscId}`;case"kicad":return`kicad-${t.footprint.path}`;default:return"unknown"}},Moi=t=>{switch(t.source){case"tscircuit.com":return t.package.unscoped_name;case"jlcpcb":return t.component.manufacturer;case"kicad":return t.footprint.qualifiedName}},Roi=t=>{switch(t.source){case"tscircuit.com":return t.package.description||(t.package.org_owner_tscircuit_handle?`Component by ${t.package.org_owner_tscircuit_handle}`:void 0);case"jlcpcb":return t.component.description;case"kicad":return t.footprint.description}},Noi=t=>{switch(t.source){case"tscircuit.com":return t.package.name;case"jlcpcb":return t.component.partNumber;case"kicad":return}},Goi=({results:t,selected:A,onSelect:e,onShowDetails:i})=>{const n=A?hue(A):null;return W.jsx("div",{className:"rf-divide-y rf-w-full rf-overflow-hidden",children:t.map(o=>{const s=hue(o),r=n===s,a=Moi(o),g=Roi(o),c=Noi(o),I=o.source==="jlcpcb"?o.component.stock:null,l=o.source==="jlcpcb"?o.component.price:null,B=o.source==="jlcpcb"?o.component.isBasic:null;return W.jsxs("div",{className:`rf-p-3 rf-flex rf-flex-col sm:rf-grid sm:rf-grid-cols-[minmax(0,1fr)_auto] rf-items-start sm:rf-items-center rf-cursor-pointer hover:rf-bg-zinc-100 rf-gap-2 rf-overflow-hidden ${r?"rf-bg-zinc-100":""}`,onClick:()=>e(o),children:[W.jsxs("div",{className:"rf-min-w-0 rf-overflow-hidden rf-w-full",children:[W.jsxs("div",{className:"rf-flex rf-items-start rf-gap-2 rf-min-w-0",children:[W.jsxs("div",{className:"rf-font-medium rf-text-sm rf-truncate rf-flex-1 rf-min-w-0 rf-flex rf-items-center rf-gap-1.5",children:[a,o.source==="jlcpcb"&&B!=null&&W.jsx("span",{className:`rf-text-xs rf-px-1.5 rf-py-0.5 rf-rounded rf-font-medium rf-flex-shrink-0 ${B?"rf-bg-green-100 rf-text-green-700":"rf-bg-orange-100 rf-text-orange-700"}`,children:B?"Basic":"Extended"}),o.source==="tscircuit.com"&&o.package.is_private&&W.jsx(wqt,{className:"rf-ml-1 rf-h-3 rf-w-3 rf-text-zinc-400 rf-flex-shrink-0"})]}),o.source==="jlcpcb"&&I!=null?W.jsxs("div",{className:"rf-text-xs rf-text-zinc-500 rf-font-medium rf-whitespace-nowrap rf-flex-shrink-0 sm:rf-hidden",children:[I.toLocaleString()," in stock"]}):null]}),W.jsxs("div",{className:"rf-text-xs rf-text-zinc-500 rf-truncate rf-w-full",children:[c?W.jsx("span",{className:"rf-mr-2",children:c}):null,g]})]}),W.jsxs("div",{children:[o.source==="tscircuit.com"&&i?W.jsx("div",{className:"rf-flex-shrink-0 rf-w-full sm:rf-w-auto",children:W.jsx(Ja,{variant:"outline",size:"sm",className:"rf-text-xs rf-w-full sm:rf-w-auto",onClick:C=>{C.stopPropagation(),i(o)},children:"See Details"})}):o.source==="jlcpcb"&&I!=null?W.jsxs("div",{className:"rf-hidden sm:rf-block rf-text-xs rf-text-zinc-500 rf-font-medium rf-whitespace-nowrap rf-flex-shrink-0",children:[I.toLocaleString()," in stock"]}):null,l!=null&&W.jsx("div",{className:"rf-hidden sm:rf-block rf-text-xs rf-text-zinc-500 rf-font-medium rf-whitespace-nowrap rf-flex-shrink-0 rf-text-right",children:Foi(l)})]})]},s)})})},Loi=({packageResult:t,isOpen:A,onOpenChange:e,isLoading:i,details:n,previewTab:o,onPreviewTabChange:s,isSubmitting:r,onImport:a})=>{const g=t?.package??null,c=g?.latest_pcb_preview_image_url,I=g?.latest_sch_preview_image_url,l=g?.latest_cad_preview_image_url,B=g?.unscoped_name?.split("/").pop()??g?.unscoped_name,C=g?.org_owner_tscircuit_handle??void 0,Q=C?`https://tscircuit.com/${C}`:void 0,h=C&&B?`https://tscircuit.com/${C}/${B}`:void 0;return W.jsx(x2,{open:A,onOpenChange:e,children:W.jsxs(KM,{showOverlay:!1,style:{width:"calc(100vw - 2rem)"},className:"rf-max-w-5xl no-scrollbar !rf-overflow-y-auto rf-max-h-[90vh] rf-overflow-hidden rf-flex rf-flex-col rf-rounded-sm",children:[W.jsx(qM,{className:"rf-pb-4 rf-border-b",children:W.jsx("div",{className:"rf-flex rf-items-start rf-justify-between rf-gap-4",children:W.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[W.jsx(OM,{className:"rf-text-xl rf-font-semibold rf-truncate",children:B}),W.jsx(_2,{children:g?.description})]})})}),W.jsxs("div",{className:"rf-flex-1 rf-overflow-y-auto rf-py-4 rf-space-y-6",children:[C?W.jsxs("div",{children:[W.jsx("span",{className:"rf-text-xs rf-font-medium rf-text-gray-500 rf-uppercase rf-tracking-wide",children:"Created by"}),W.jsx("div",{className:"rf-mt-1 rf-text-sm rf-font-medium",children:Q?W.jsx("a",{href:Q,target:"_blank",rel:"noopener noreferrer",className:"rf-text-black hover:rf-underline",children:C}):C})]}):null,(l||c||I)&&W.jsx(W.Fragment,{children:W.jsxs("div",{children:[W.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-mb-4",children:"Preview"}),W.jsxs(DgA,{value:o,onValueChange:E=>s(E),children:[W.jsxs(WW,{className:"rf-inline-flex rf-h-9 rf-items-center rf-justify-center rf-rounded-lg rf-bg-zinc-100 rf-p-1 rf-text-zinc-500 dark:rf-bg-zinc-800 dark:rf-text-zinc-400",children:[c&&W.jsx(JD,{value:"pcb",children:"PCB"}),I&&W.jsx(JD,{value:"schematic",children:"Schematic"}),l&&W.jsx(JD,{value:"3d",children:"3D"})]}),W.jsxs("div",{className:"rf-mt-4",children:[W.jsx(td,{value:"pcb",className:"rf-border rf-rounded-lg rf-overflow-hidden rf-bg-gray-50",children:c?W.jsx("img",{src:c,alt:`${B??"package"} PCB preview`,className:"rf-w-full rf-h-full rf-object-contain rf-bg-white rf-p-4"}):null}),W.jsx(td,{value:"schematic",className:"rf-border rf-rounded-lg rf-overflow-hidden rf-bg-gray-50",children:I?W.jsx("img",{src:I,alt:`${B??"package"} schematic preview`,className:"rf-w-full rf-h-full rf-object-contain rf-bg-white rf-p-4"}):null}),W.jsx(td,{value:"3d",className:"rf-border rf-rounded-lg rf-overflow-hidden rf-bg-gray-50",children:l?W.jsx("img",{src:l,alt:`${B??"package"} 3D preview`,className:"rf-w-full rf-h-full rf-object-contain rf-bg-white rf-p-4"}):null})]})]})]})}),n?.ai_description?W.jsxs("section",{children:[W.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-mb-3",children:"AI Description"}),W.jsx("div",{className:"rf-bg-gray-50 rf-border rf-border-gray-200 rf-rounded-lg rf-p-4",children:W.jsx("p",{className:"rf-text-sm rf-text-gray-700 rf-leading-relaxed",children:n.ai_description})})]}):null,n?.ai_usage_instructions?W.jsxs("section",{children:[W.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-mb-3",children:"Usage Instructions"}),W.jsx("div",{className:"rf-bg-gray-50 rf-border rf-border-gray-200 rf-rounded-lg rf-p-4",children:W.jsx("p",{className:"rf-text-sm rf-text-gray-700 rf-leading-relaxed rf-whitespace-pre-wrap",children:n.ai_usage_instructions})})]}):null,i?W.jsxs("div",{className:"rf-flex rf-justify-center rf-items-center rf-gap-2 rf-text-gray-500",children:[W.jsx(Zb,{className:"rf-h-4 rf-w-4 rf-animate-spin"}),W.jsx("span",{className:"rf-text-sm",children:"Loading package details..."})]}):null]}),W.jsxs(XT,{className:"rf-pt-4 rf-border-t rf-flex rf-flex-col sm:rf-flex-row rf-justify-between rf-gap-2",children:[W.jsx("div",{className:"rf-flex-1",children:h?W.jsxs(Ja,{variant:"outline",size:"sm",className:"rf-gap-2 rf-w-full sm:rf-w-auto",onClick:()=>window.open(h,"_blank"),children:[W.jsx(Eqt,{className:"rf-h-4 rf-w-4"}),"View on tscircuit.com"]}):null}),W.jsxs("div",{className:"rf-flex rf-flex-col sm:rf-flex-row rf-gap-2",children:[W.jsx(Ja,{variant:"outline",onClick:()=>e(!1),className:"rf-order-2 sm:rf-order-1",children:"Close"}),W.jsx(Ja,{onClick:a,disabled:r,className:"rf-bg-blue-600 hover:rf-bg-blue-700",children:r?W.jsx(Zb,{className:"rf-h-4 rf-w-4 rf-animate-spin"}):"Import Component"})]})]})]})})},Uoi=()=>{const[t,A]=V.useState(null),[e,i]=V.useState(!1),n=V.useCallback(async(s,r)=>{i(!0);try{const a=await fetch(`https://api.tscircuit.com/packages/get?name=${encodeURIComponent(`${s}/${r}`)}`);if(!a.ok)throw new Error(`Failed to load package details: ${a.status}`);const g=await a.json();A(g.package??null)}catch(a){console.error("Failed to fetch package details",a),A(null)}finally{i(!1)}},[]),o=V.useCallback(()=>{A(null),i(!1)},[]);return{details:t,isLoading:e,fetchDetails:n,reset:o}},Hoi=async(t,A)=>{const e={"Content-Type":"application/json"};A&&(e.Authorization=`Bearer ${A}`);const i=await fetch("https://registry-api.tscircuit.com/packages/search",{method:"POST",headers:e,body:JSON.stringify({query:t})});if(!i.ok)throw new Error(`tscircuit registry error: ${i.status}`);return(await i.json()).packages??[]},Yoi=({sessionToken:t})=>{const[A,e]=V.useState([]),[i,n]=V.useState(!1),[o,s]=V.useState(null),[r,a]=V.useState(!1),g=V.useCallback(async I=>{const l=I.trim();if(!l)return[];n(!0),s(null);try{const C=(await Hoi(l,t)).map(Q=>({source:"tscircuit.com",package:Q}));return e(C),C}catch(B){return console.error("Error searching tscircuit packages",B),e([]),s(B instanceof Error?B.message:"Failed to search tscircuit packages"),[]}finally{n(!1),a(!0)}},[t]),c=V.useCallback(()=>{e([]),n(!1),s(null),a(!1)},[]);return{results:A,isSearching:i,error:o,hasSearched:r,search:g,reset:c}},Joi=t=>{const A=t.trim();return/^C\d+/i.test(A)?A.replace(/^C/i,""):A},Toi=()=>{const[t,A]=V.useState([]),[e,i]=V.useState(!1),[n,o]=V.useState(null),[s,r]=V.useState(!1),a=V.useCallback(async c=>{const I=Joi(c);if(!I)return[];i(!0),o(null);try{const B=(await boi(I,10)).map(C=>({source:"jlcpcb",component:xoi(C)}));return A(B),B}catch(l){return console.error("Error searching JLCPCB components",l),A([]),o(l instanceof Error?l.message:"Failed to search JLCPCB components"),[]}finally{i(!1),r(!0)}},[]),g=V.useCallback(()=>{A([]),i(!1),o(null),r(!1)},[]);return{results:t,isSearching:e,error:n,hasSearched:s,search:a,reset:g}};function gx(t){return Array.isArray?Array.isArray(t):due(t)==="[object Array]"}function Poi(t){if(typeof t=="string")return t;let A=t+"";return A=="0"&&1/t==-1/0?"-0":A}function Koi(t){return t==null?"":Poi(t)}function DS(t){return typeof t=="string"}function Eue(t){return typeof t=="number"}function qoi(t){return t===!0||t===!1||Ooi(t)&&due(t)=="[object Boolean]"}function uue(t){return typeof t=="object"}function Ooi(t){return uue(t)&&t!==null}function Cy(t){return t!=null}function jmA(t){return!t.trim().length}function due(t){return t==null?t===void 0?"[object Undefined]":"[object Null]":Object.prototype.toString.call(t)}const Woi="Incorrect 'index' type",Zoi=t=>`Invalid value for key ${t}`,Voi=t=>`Pattern length exceeds max of ${t}.`,joi=t=>`Missing ${t} property in key`,zoi=t=>`Property 'weight' in key '${t}' must be a positive integer`,pue=Object.prototype.hasOwnProperty;class Xoi{constructor(A){this._keys=[],this._keyMap={};let e=0;A.forEach(i=>{let n=fue(i);this._keys.push(n),this._keyMap[n.id]=n,e+=n.weight}),this._keys.forEach(i=>{i.weight/=e})}get(A){return this._keyMap[A]}keys(){return this._keys}toJSON(){return JSON.stringify(this._keys)}}function fue(t){let A=null,e=null,i=null,n=1,o=null;if(DS(t)||gx(t))i=t,A=yue(t),e=zmA(t);else{if(!pue.call(t,"name"))throw new Error(joi("name"));const s=t.name;if(i=s,pue.call(t,"weight")&&(n=t.weight,n<=0))throw new Error(zoi(s));A=yue(s),e=zmA(s),o=t.getFn}return{path:A,id:e,weight:n,src:i,getFn:o}}function yue(t){return gx(t)?t:t.split(".")}function zmA(t){return gx(t)?t.join("."):t}function $oi(t,A){let e=[],i=!1;const n=(o,s,r)=>{if(Cy(o))if(!s[r])e.push(o);else{let a=s[r];const g=o[a];if(!Cy(g))return;if(r===s.length-1&&(DS(g)||Eue(g)||qoi(g)))e.push(Koi(g));else if(gx(g)){i=!0;for(let c=0,I=g.length;c<I;c+=1)n(g[c],s,r+1)}else s.length&&n(g,s,r+1)}};return n(t,DS(A)?A.split("."):A,0),i?e:e[0]}var Zo={...{isCaseSensitive:!1,ignoreDiacritics:!1,includeScore:!1,keys:[],shouldSort:!0,sortFn:(t,A)=>t.score===A.score?t.idx<A.idx?-1:1:t.score<A.score?-1:1},...{includeMatches:!1,findAllMatches:!1,minMatchCharLength:1},...{location:0,threshold:.6,distance:100},...{useExtendedSearch:!1,getFn:$oi,ignoreLocation:!1,ignoreFieldNorm:!1,fieldNormWeight:1}};const Asi=/[^ ]+/g;function esi(t=1,A=3){const e=new Map,i=Math.pow(10,A);return{get(n){const o=n.match(Asi).length;if(e.has(o))return e.get(o);const s=1/Math.pow(o,.5*t),r=parseFloat(Math.round(s*i)/i);return e.set(o,r),r},clear(){e.clear()}}}class XmA{constructor({getFn:A=Zo.getFn,fieldNormWeight:e=Zo.fieldNormWeight}={}){this.norm=esi(e,3),this.getFn=A,this.isCreated=!1,this.setIndexRecords()}setSources(A=[]){this.docs=A}setIndexRecords(A=[]){this.records=A}setKeys(A=[]){this.keys=A,this._keysMap={},A.forEach((e,i)=>{this._keysMap[e.id]=i})}create(){this.isCreated||!this.docs.length||(this.isCreated=!0,DS(this.docs[0])?this.docs.forEach((A,e)=>{this._addString(A,e)}):this.docs.forEach((A,e)=>{this._addObject(A,e)}),this.norm.clear())}add(A){const e=this.size();DS(A)?this._addString(A,e):this._addObject(A,e)}removeAt(A){this.records.splice(A,1);for(let e=A,i=this.size();e<i;e+=1)this.records[e].i-=1}getValueForItemAtKeyId(A,e){return A[this._keysMap[e]]}size(){return this.records.length}_addString(A,e){if(!Cy(A)||jmA(A))return;let i={v:A,i:e,n:this.norm.get(A)};this.records.push(i)}_addObject(A,e){let i={i:e,$:{}};this.keys.forEach((n,o)=>{let s=n.getFn?n.getFn(A):this.getFn(A,n.path);if(Cy(s)){if(gx(s)){let r=[];const a=[{nestedArrIndex:-1,value:s}];for(;a.length;){const{nestedArrIndex:g,value:c}=a.pop();if(Cy(c))if(DS(c)&&!jmA(c)){let I={v:c,i:g,n:this.norm.get(c)};r.push(I)}else gx(c)&&c.forEach((I,l)=>{a.push({nestedArrIndex:l,value:I})})}i.$[o]=r}else if(DS(s)&&!jmA(s)){let r={v:s,n:this.norm.get(s)};i.$[o]=r}}}),this.records.push(i)}toJSON(){return{keys:this.keys,records:this.records}}}function mue(t,A,{getFn:e=Zo.getFn,fieldNormWeight:i=Zo.fieldNormWeight}={}){const n=new XmA({getFn:e,fieldNormWeight:i});return n.setKeys(t.map(fue)),n.setSources(A),n.create(),n}function tsi(t,{getFn:A=Zo.getFn,fieldNormWeight:e=Zo.fieldNormWeight}={}){const{keys:i,records:n}=t,o=new XmA({getFn:A,fieldNormWeight:e});return o.setKeys(i),o.setIndexRecords(n),o}function Zz(t,{errors:A=0,currentLocation:e=0,expectedLocation:i=0,distance:n=Zo.distance,ignoreLocation:o=Zo.ignoreLocation}={}){const s=A/t.length;if(o)return s;const r=Math.abs(i-e);return n?s+r/n:r?1:s}function isi(t=[],A=Zo.minMatchCharLength){let e=[],i=-1,n=-1,o=0;for(let s=t.length;o<s;o+=1){let r=t[o];r&&i===-1?i=o:!r&&i!==-1&&(n=o-1,n-i+1>=A&&e.push([i,n]),i=-1)}return t[o-1]&&o-i>=A&&e.push([i,o-1]),e}const WM=32;function nsi(t,A,e,{location:i=Zo.location,distance:n=Zo.distance,threshold:o=Zo.threshold,findAllMatches:s=Zo.findAllMatches,minMatchCharLength:r=Zo.minMatchCharLength,includeMatches:a=Zo.includeMatches,ignoreLocation:g=Zo.ignoreLocation}={}){if(A.length>WM)throw new Error(Voi(WM));const c=A.length,I=t.length,l=Math.max(0,Math.min(i,I));let B=o,C=l;const Q=r>1||a,h=Q?Array(I):[];let E;for(;(E=t.indexOf(A,C))>-1;){let D=Zz(A,{currentLocation:E,expectedLocation:l,distance:n,ignoreLocation:g});if(B=Math.min(D,B),C=E+c,Q){let S=0;for(;S<c;)h[E+S]=1,S+=1}}C=-1;let u=[],d=1,f=c+I;const y=1<<c-1;for(let D=0;D<c;D+=1){let S=0,_=f;for(;S<_;)Zz(A,{errors:D,currentLocation:l+_,expectedLocation:l,distance:n,ignoreLocation:g})<=B?S=_:f=_,_=Math.floor((f-S)/2+S);f=_;let b=Math.max(1,l-_+1),N=s?I:Math.min(l+_,I)+c,F=Array(N+2);F[N+1]=(1<<D)-1;for(let Y=N;Y>=b;Y-=1){let J=Y-1,O=e[t.charAt(J)];if(Q&&(h[J]=+!!O),F[Y]=(F[Y+1]<<1|1)&O,D&&(F[Y]|=(u[Y+1]|u[Y])<<1|1|u[Y+1]),F[Y]&y&&(d=Zz(A,{errors:D,currentLocation:J,expectedLocation:l,distance:n,ignoreLocation:g}),d<=B)){if(B=d,C=J,C<=l)break;b=Math.max(1,2*l-C)}}if(Zz(A,{errors:D+1,currentLocation:l,expectedLocation:l,distance:n,ignoreLocation:g})>B)break;u=F}const w={isMatch:C>=0,score:Math.max(.001,d)};if(Q){const D=isi(h,r);D.length?a&&(w.indices=D):w.isMatch=!1}return w}function osi(t){let A={};for(let e=0,i=t.length;e<i;e+=1){const n=t.charAt(e);A[n]=(A[n]||0)|1<<i-e-1}return A}const Vz=String.prototype.normalize?(t=>t.normalize("NFD").replace(/[\u0300-\u036F\u0483-\u0489\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u0610-\u061A\u064B-\u065F\u0670\u06D6-\u06DC\u06DF-\u06E4\u06E7\u06E8\u06EA-\u06ED\u0711\u0730-\u074A\u07A6-\u07B0\u07EB-\u07F3\u07FD\u0816-\u0819\u081B-\u0823\u0825-\u0827\u0829-\u082D\u0859-\u085B\u08D3-\u08E1\u08E3-\u0903\u093A-\u093C\u093E-\u094F\u0951-\u0957\u0962\u0963\u0981-\u0983\u09BC\u09BE-\u09C4\u09C7\u09C8\u09CB-\u09CD\u09D7\u09E2\u09E3\u09FE\u0A01-\u0A03\u0A3C\u0A3E-\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A70\u0A71\u0A75\u0A81-\u0A83\u0ABC\u0ABE-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD\u0AE2\u0AE3\u0AFA-\u0AFF\u0B01-\u0B03\u0B3C\u0B3E-\u0B44\u0B47\u0B48\u0B4B-\u0B4D\u0B56\u0B57\u0B62\u0B63\u0B82\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD7\u0C00-\u0C04\u0C3E-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C62\u0C63\u0C81-\u0C83\u0CBC\u0CBE-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5\u0CD6\u0CE2\u0CE3\u0D00-\u0D03\u0D3B\u0D3C\u0D3E-\u0D44\u0D46-\u0D48\u0D4A-\u0D4D\u0D57\u0D62\u0D63\u0D82\u0D83\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DF2\u0DF3\u0E31\u0E34-\u0E3A\u0E47-\u0E4E\u0EB1\u0EB4-\u0EB9\u0EBB\u0EBC\u0EC8-\u0ECD\u0F18\u0F19\u0F35\u0F37\u0F39\u0F3E\u0F3F\u0F71-\u0F84\u0F86\u0F87\u0F8D-\u0F97\u0F99-\u0FBC\u0FC6\u102B-\u103E\u1056-\u1059\u105E-\u1060\u1062-\u1064\u1067-\u106D\u1071-\u1074\u1082-\u108D\u108F\u109A-\u109D\u135D-\u135F\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17B4-\u17D3\u17DD\u180B-\u180D\u1885\u1886\u18A9\u1920-\u192B\u1930-\u193B\u1A17-\u1A1B\u1A55-\u1A5E\u1A60-\u1A7C\u1A7F\u1AB0-\u1ABE\u1B00-\u1B04\u1B34-\u1B44\u1B6B-\u1B73\u1B80-\u1B82\u1BA1-\u1BAD\u1BE6-\u1BF3\u1C24-\u1C37\u1CD0-\u1CD2\u1CD4-\u1CE8\u1CED\u1CF2-\u1CF4\u1CF7-\u1CF9\u1DC0-\u1DF9\u1DFB-\u1DFF\u20D0-\u20F0\u2CEF-\u2CF1\u2D7F\u2DE0-\u2DFF\u302A-\u302F\u3099\u309A\uA66F-\uA672\uA674-\uA67D\uA69E\uA69F\uA6F0\uA6F1\uA802\uA806\uA80B\uA823-\uA827\uA880\uA881\uA8B4-\uA8C5\uA8E0-\uA8F1\uA8FF\uA926-\uA92D\uA947-\uA953\uA980-\uA983\uA9B3-\uA9C0\uA9E5\uAA29-\uAA36\uAA43\uAA4C\uAA4D\uAA7B-\uAA7D\uAAB0\uAAB2-\uAAB4\uAAB7\uAAB8\uAABE\uAABF\uAAC1\uAAEB-\uAAEF\uAAF5\uAAF6\uABE3-\uABEA\uABEC\uABED\uFB1E\uFE00-\uFE0F\uFE20-\uFE2F]/g,"")):(t=>t);class wue{constructor(A,{location:e=Zo.location,threshold:i=Zo.threshold,distance:n=Zo.distance,includeMatches:o=Zo.includeMatches,findAllMatches:s=Zo.findAllMatches,minMatchCharLength:r=Zo.minMatchCharLength,isCaseSensitive:a=Zo.isCaseSensitive,ignoreDiacritics:g=Zo.ignoreDiacritics,ignoreLocation:c=Zo.ignoreLocation}={}){if(this.options={location:e,threshold:i,distance:n,includeMatches:o,findAllMatches:s,minMatchCharLength:r,isCaseSensitive:a,ignoreDiacritics:g,ignoreLocation:c},A=a?A:A.toLowerCase(),A=g?Vz(A):A,this.pattern=A,this.chunks=[],!this.pattern.length)return;const I=(B,C)=>{this.chunks.push({pattern:B,alphabet:osi(B),startIndex:C})},l=this.pattern.length;if(l>WM){let B=0;const C=l%WM,Q=l-C;for(;B<Q;)I(this.pattern.substr(B,WM),B),B+=WM;if(C){const h=l-WM;I(this.pattern.substr(h),h)}}else I(this.pattern,0)}searchIn(A){const{isCaseSensitive:e,ignoreDiacritics:i,includeMatches:n}=this.options;if(A=e?A:A.toLowerCase(),A=i?Vz(A):A,this.pattern===A){let Q={isMatch:!0,score:0};return n&&(Q.indices=[[0,A.length-1]]),Q}const{location:o,distance:s,threshold:r,findAllMatches:a,minMatchCharLength:g,ignoreLocation:c}=this.options;let I=[],l=0,B=!1;this.chunks.forEach(({pattern:Q,alphabet:h,startIndex:E})=>{const{isMatch:u,score:d,indices:f}=nsi(A,Q,h,{location:o+E,distance:s,threshold:r,findAllMatches:a,minMatchCharLength:g,includeMatches:n,ignoreLocation:c});u&&(B=!0),l+=d,u&&f&&(I=[...I,...f])});let C={isMatch:B,score:B?l/this.chunks.length:1};return B&&n&&(C.indices=I),C}}class Wk{constructor(A){this.pattern=A}static isMultiMatch(A){return Due(A,this.multiRegex)}static isSingleMatch(A){return Due(A,this.singleRegex)}search(){}}function Due(t,A){const e=t.match(A);return e?e[1]:null}class ssi extends Wk{constructor(A){super(A)}static get type(){return"exact"}static get multiRegex(){return/^="(.*)"$/}static get singleRegex(){return/^=(.*)$/}search(A){const e=A===this.pattern;return{isMatch:e,score:e?0:1,indices:[0,this.pattern.length-1]}}}class rsi extends Wk{constructor(A){super(A)}static get type(){return"inverse-exact"}static get multiRegex(){return/^!"(.*)"$/}static get singleRegex(){return/^!(.*)$/}search(A){const i=A.indexOf(this.pattern)===-1;return{isMatch:i,score:i?0:1,indices:[0,A.length-1]}}}class asi extends Wk{constructor(A){super(A)}static get type(){return"prefix-exact"}static get multiRegex(){return/^\^"(.*)"$/}static get singleRegex(){return/^\^(.*)$/}search(A){const e=A.startsWith(this.pattern);return{isMatch:e,score:e?0:1,indices:[0,this.pattern.length-1]}}}class gsi extends Wk{constructor(A){super(A)}static get type(){return"inverse-prefix-exact"}static get multiRegex(){return/^!\^"(.*)"$/}static get singleRegex(){return/^!\^(.*)$/}search(A){const e=!A.startsWith(this.pattern);return{isMatch:e,score:e?0:1,indices:[0,A.length-1]}}}class csi extends Wk{constructor(A){super(A)}static get type(){return"suffix-exact"}static get multiRegex(){return/^"(.*)"\$$/}static get singleRegex(){return/^(.*)\$$/}search(A){const e=A.endsWith(this.pattern);return{isMatch:e,score:e?0:1,indices:[A.length-this.pattern.length,A.length-1]}}}class Isi extends Wk{constructor(A){super(A)}static get type(){return"inverse-suffix-exact"}static get multiRegex(){return/^!"(.*)"\$$/}static get singleRegex(){return/^!(.*)\$$/}search(A){const e=!A.endsWith(this.pattern);return{isMatch:e,score:e?0:1,indices:[0,A.length-1]}}}class Sue extends Wk{constructor(A,{location:e=Zo.location,threshold:i=Zo.threshold,distance:n=Zo.distance,includeMatches:o=Zo.includeMatches,findAllMatches:s=Zo.findAllMatches,minMatchCharLength:r=Zo.minMatchCharLength,isCaseSensitive:a=Zo.isCaseSensitive,ignoreDiacritics:g=Zo.ignoreDiacritics,ignoreLocation:c=Zo.ignoreLocation}={}){super(A),this._bitapSearch=new wue(A,{location:e,threshold:i,distance:n,includeMatches:o,findAllMatches:s,minMatchCharLength:r,isCaseSensitive:a,ignoreDiacritics:g,ignoreLocation:c})}static get type(){return"fuzzy"}static get multiRegex(){return/^"(.*)"$/}static get singleRegex(){return/^(.*)$/}search(A){return this._bitapSearch.searchIn(A)}}class bue extends Wk{constructor(A){super(A)}static get type(){return"include"}static get multiRegex(){return/^'"(.*)"$/}static get singleRegex(){return/^'(.*)$/}search(A){let e=0,i;const n=[],o=this.pattern.length;for(;(i=A.indexOf(this.pattern,e))>-1;)e=i+o,n.push([i,e-1]);const s=!!n.length;return{isMatch:s,score:s?0:1,indices:n}}}const $mA=[ssi,bue,asi,gsi,Isi,csi,rsi,Sue],xue=$mA.length,lsi=/ +(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/,Bsi="|";function Csi(t,A={}){return t.split(Bsi).map(e=>{let i=e.trim().split(lsi).filter(o=>o&&!!o.trim()),n=[];for(let o=0,s=i.length;o<s;o+=1){const r=i[o];let a=!1,g=-1;for(;!a&&++g<xue;){const c=$mA[g];let I=c.isMultiMatch(r);I&&(n.push(new c(I,A)),a=!0)}if(!a)for(g=-1;++g<xue;){const c=$mA[g];let I=c.isSingleMatch(r);if(I){n.push(new c(I,A));break}}}return n})}const Qsi=new Set([Sue.type,bue.type]);class hsi{constructor(A,{isCaseSensitive:e=Zo.isCaseSensitive,ignoreDiacritics:i=Zo.ignoreDiacritics,includeMatches:n=Zo.includeMatches,minMatchCharLength:o=Zo.minMatchCharLength,ignoreLocation:s=Zo.ignoreLocation,findAllMatches:r=Zo.findAllMatches,location:a=Zo.location,threshold:g=Zo.threshold,distance:c=Zo.distance}={}){this.query=null,this.options={isCaseSensitive:e,ignoreDiacritics:i,includeMatches:n,minMatchCharLength:o,findAllMatches:r,ignoreLocation:s,location:a,threshold:g,distance:c},A=e?A:A.toLowerCase(),A=i?Vz(A):A,this.pattern=A,this.query=Csi(this.pattern,this.options)}static condition(A,e){return e.useExtendedSearch}searchIn(A){const e=this.query;if(!e)return{isMatch:!1,score:1};const{includeMatches:i,isCaseSensitive:n,ignoreDiacritics:o}=this.options;A=n?A:A.toLowerCase(),A=o?Vz(A):A;let s=0,r=[],a=0;for(let g=0,c=e.length;g<c;g+=1){const I=e[g];r.length=0,s=0;for(let l=0,B=I.length;l<B;l+=1){const C=I[l],{isMatch:Q,indices:h,score:E}=C.search(A);if(Q){if(s+=1,a+=E,i){const u=C.constructor.type;Qsi.has(u)?r=[...r,...h]:r.push(h)}}else{a=0,s=0,r.length=0;break}}if(s){let l={isMatch:!0,score:a/s};return i&&(l.indices=r),l}}return{isMatch:!1,score:1}}}const AwA=[];function Esi(...t){AwA.push(...t)}function ewA(t,A){for(let e=0,i=AwA.length;e<i;e+=1){let n=AwA[e];if(n.condition(t,A))return new n(t,A)}return new wue(t,A)}const jz={AND:"$and",OR:"$or"},twA={PATH:"$path",PATTERN:"$val"},iwA=t=>!!(t[jz.AND]||t[jz.OR]),usi=t=>!!t[twA.PATH],dsi=t=>!gx(t)&&uue(t)&&!iwA(t),_ue=t=>({[jz.AND]:Object.keys(t).map(A=>({[A]:t[A]}))});function kue(t,A,{auto:e=!0}={}){const i=n=>{let o=Object.keys(n);const s=usi(n);if(!s&&o.length>1&&!iwA(n))return i(_ue(n));if(dsi(n)){const a=s?n[twA.PATH]:o[0],g=s?n[twA.PATTERN]:n[a];if(!DS(g))throw new Error(Zoi(a));const c={keyId:zmA(a),pattern:g};return e&&(c.searcher=ewA(g,A)),c}let r={children:[],operator:o[0]};return o.forEach(a=>{const g=n[a];gx(g)&&g.forEach(c=>{r.children.push(i(c))})}),r};return iwA(t)||(t=_ue(t)),i(t)}function psi(t,{ignoreFieldNorm:A=Zo.ignoreFieldNorm}){t.forEach(e=>{let i=1;e.matches.forEach(({key:n,norm:o,score:s})=>{const r=n?n.weight:null;i*=Math.pow(s===0&&r?Number.EPSILON:s,(r||1)*(A?1:o))}),e.score=i})}function fsi(t,A){const e=t.matches;A.matches=[],Cy(e)&&e.forEach(i=>{if(!Cy(i.indices)||!i.indices.length)return;const{indices:n,value:o}=i;let s={indices:n,value:o};i.key&&(s.key=i.key.src),i.idx>-1&&(s.refIndex=i.idx),A.matches.push(s)})}function ysi(t,A){A.score=t.score}function msi(t,A,{includeMatches:e=Zo.includeMatches,includeScore:i=Zo.includeScore}={}){const n=[];return e&&n.push(fsi),i&&n.push(ysi),t.map(o=>{const{idx:s}=o,r={item:A[s],refIndex:s};return n.length&&n.forEach(a=>{a(o,r)}),r})}class k2{constructor(A,e={},i){this.options={...Zo,...e},this.options.useExtendedSearch,this._keyStore=new Xoi(this.options.keys),this.setCollection(A,i)}setCollection(A,e){if(this._docs=A,e&&!(e instanceof XmA))throw new Error(Woi);this._myIndex=e||mue(this.options.keys,this._docs,{getFn:this.options.getFn,fieldNormWeight:this.options.fieldNormWeight})}add(A){Cy(A)&&(this._docs.push(A),this._myIndex.add(A))}remove(A=()=>!1){const e=[];for(let i=0,n=this._docs.length;i<n;i+=1){const o=this._docs[i];A(o,i)&&(this.removeAt(i),i-=1,n-=1,e.push(o))}return e}removeAt(A){this._docs.splice(A,1),this._myIndex.removeAt(A)}getIndex(){return this._myIndex}search(A,{limit:e=-1}={}){const{includeMatches:i,includeScore:n,shouldSort:o,sortFn:s,ignoreFieldNorm:r}=this.options;let a=DS(A)?DS(this._docs[0])?this._searchStringList(A):this._searchObjectList(A):this._searchLogical(A);return psi(a,{ignoreFieldNorm:r}),o&&a.sort(s),Eue(e)&&e>-1&&(a=a.slice(0,e)),msi(a,this._docs,{includeMatches:i,includeScore:n})}_searchStringList(A){const e=ewA(A,this.options),{records:i}=this._myIndex,n=[];return i.forEach(({v:o,i:s,n:r})=>{if(!Cy(o))return;const{isMatch:a,score:g,indices:c}=e.searchIn(o);a&&n.push({item:o,idx:s,matches:[{score:g,value:o,norm:r,indices:c}]})}),n}_searchLogical(A){const e=kue(A,this.options),i=(r,a,g)=>{if(!r.children){const{keyId:I,searcher:l}=r,B=this._findMatches({key:this._keyStore.get(I),value:this._myIndex.getValueForItemAtKeyId(a,I),searcher:l});return B&&B.length?[{idx:g,item:a,matches:B}]:[]}const c=[];for(let I=0,l=r.children.length;I<l;I+=1){const B=r.children[I],C=i(B,a,g);if(C.length)c.push(...C);else if(r.operator===jz.AND)return[]}return c},n=this._myIndex.records,o={},s=[];return n.forEach(({$:r,i:a})=>{if(Cy(r)){let g=i(e,r,a);g.length&&(o[a]||(o[a]={idx:a,item:r,matches:[]},s.push(o[a])),g.forEach(({matches:c})=>{o[a].matches.push(...c)}))}}),s}_searchObjectList(A){const e=ewA(A,this.options),{keys:i,records:n}=this._myIndex,o=[];return n.forEach(({$:s,i:r})=>{if(!Cy(s))return;let a=[];i.forEach((g,c)=>{a.push(...this._findMatches({key:g,value:s[c],searcher:e}))}),a.length&&o.push({idx:r,item:s,matches:a})}),o}_findMatches({key:A,value:e,searcher:i}){if(!Cy(e))return[];let n=[];if(gx(e))e.forEach(({v:o,i:s,n:r})=>{if(!Cy(o))return;const{isMatch:a,score:g,indices:c}=i.searchIn(o);a&&n.push({score:g,key:A,value:o,idx:s,norm:r,indices:c})});else{const{v:o,n:s}=e,{isMatch:r,score:a,indices:g}=i.searchIn(o);r&&n.push({score:a,key:A,value:o,norm:s,indices:g})}return n}}k2.version="7.1.0",k2.createIndex=mue,k2.parseIndex=tsi,k2.config=Zo,k2.parseQuery=kue,Esi(hsi);let nwA=null,$T=null,owA=null;const wsi=async()=>nwA||$T||($T=fetch("https://kicad-mod-cache.tscircuit.com/kicad_files.json").then(t=>t.json()).then(t=>(nwA=t,$T=null,t)),$T),Dsi=async(t,A=20)=>{const e=await wsi();return owA||(owA=new k2(e)),owA.search(t).slice(0,A).map(i=>i.item)},Ssi=t=>{const A=t.replace(".pretty/",":").replace(".kicad_mod",""),e=`kicad:${A}`;return{path:t,qualifiedName:e,description:A}},bsi=()=>{const[t,A]=V.useState([]),[e,i]=V.useState(!1),[n,o]=V.useState(null),[s,r]=V.useState(!1),a=V.useCallback(async c=>{const I=c.trim();if(!I)return[];i(!0),o(null);try{const B=(await Dsi(I,20)).map(C=>({source:"kicad",footprint:Ssi(C)}));return A(B),B}catch(l){return console.error("Error searching KiCad footprints",l),A([]),o(l instanceof Error?l.message:"Failed to search KiCad footprints"),[]}finally{i(!1),r(!0)}},[]),g=V.useCallback(()=>{A([]),i(!1),o(null),r(!1)},[]);return{results:t,isSearching:e,error:n,hasSearched:s,search:a,reset:g}},xsi={dialog:101},_si=({onTscircuitPackageSelected:t,onJlcpcbComponentTsxLoaded:A,onKicadStringSelected:e})=>{const i=[];return t&&i.push("tscircuit.com"),A&&i.push("jlcpcb"),e&&i.push("kicad"),i},ksi=({isOpen:t,onClose:A,jlcpcbProxyRequestHeaders:e,onKicadStringSelected:i,onTscircuitPackageSelected:n,onJlcpcbComponentTsxLoaded:o,jlcpcbProxyApiBase:s,tscircuitSessionToken:r})=>{Lz();const a=V.useMemo(()=>_si({onKicadStringSelected:i,onTscircuitPackageSelected:n,onJlcpcbComponentTsxLoaded:o}),[i,n,o]),g=a.length>0,c=a.length===1,[I,l]=V.useState(a[0]??"tscircuit.com"),[B,C]=V.useState(""),[Q,h]=V.useState(null),{results:E,isSearching:u,error:d,hasSearched:f,search:y,reset:w}=Yoi({sessionToken:r}),{results:D,isSearching:S,error:_,hasSearched:b,search:N,reset:F}=Toi(),{results:L,isSearching:Y,error:J,hasSearched:O,search:Z,reset:X}=bsi(),{details:eA,isLoading:gA,fetchDetails:tA,reset:iA}=Uoi(),[sA,aA]=V.useState(null),[EA,bA]=V.useState(!1),[_A,LA]=V.useState("pcb"),[QA,kA]=V.useState(null),[dA,qA]=V.useState(!1);V.useEffect(()=>{kA(null)},[Q]);const VA=V.useCallback(()=>{w(),F(),X(),h(null)},[F,X,w]);V.useEffect(()=>{t||(VA(),C(""),bA(!1),aA(null),kA(null))},[t,VA]),V.useEffect(()=>{C(""),h(null),I==="tscircuit.com"?w():I==="jlcpcb"?F():I==="kicad"&&X()},[I,F,X,w]);const ce=KA=>{h(KA),aA(KA),LA("pcb"),bA(!0),iA();const ZA=KA.package.org_owner_tscircuit_handle,ne=KA.package.unscoped_name;if(ZA&&ne){const SA=ne.split("/").pop()??ne;tA(ZA,SA)}},fA=async()=>{B.trim()&&(h(null),I==="tscircuit.com"?await y(B):I==="jlcpcb"?await N(B):I==="kicad"&&await Z(B))},ge=async KA=>{try{if(kA(null),qA(!0),KA.source==="kicad"){if(!i)throw new Error("KiCad handler not provided");await i({result:KA,footprint:KA.footprint.qualifiedName})}else if(KA.source==="jlcpcb"){if(!o)throw new Error("JLCPCB handler not provided");const ZA=await _oi(KA.component.partNumber,{headers:e,apiBase:s});await o({result:KA,tsx:ZA})}else if(KA.source==="tscircuit.com"){if(!n)throw new Error("tscircuit package handler not provided");const ZA=KA.package.org_owner_tscircuit_handle,ne=KA.package.unscoped_name;if(!ZA||!ne)throw new Error("Missing package metadata");const SA=ne.split("/").pop()??ne,CA=`@tsci/${ZA}.${SA}`;await n({result:KA,fullPackageName:CA})}return!0}catch(ZA){return console.error("Failed to import component",ZA),kA(ZA instanceof Error?ZA.message:"Failed to import component"),!1}finally{qA(!1)}};let jA=[],JA=!1,WA=null,vA=!1;I==="tscircuit.com"?(jA=E,JA=u,WA=d,vA=f):I==="jlcpcb"?(jA=D,JA=S,WA=_,vA=b):I==="kicad"&&(jA=L,JA=Y,WA=J,vA=O);const wA=async()=>{if(!Q)return;await ge(Q)&&(A(),VA(),C(""))},RA=KA=>{KA||A()},MA=KA=>{bA(KA),KA||aA(null)};return W.jsxs(x2,{open:t,onOpenChange:RA,children:[W.jsxs(KM,{style:{width:"calc(100vw - 2rem)",zIndex:xsi.dialog},className:"rf-rounded-sm rf-max-h-[90vh] rf-overflow-y-auto rf-overflow-x-hidden rf-flex rf-flex-col",children:[W.jsxs(qM,{children:[W.jsxs(OM,{className:"rf-text-lg sm:rf-text-xl",children:["Import ",c?Wz[I].label:""," ","Component"]}),W.jsx(_2,{className:"rf-text-sm",children:g?"Search for components from available sources.":"Import options are disabled because no handlers were provided."})]}),g?W.jsxs(DgA,{value:I,onValueChange:KA=>l(KA),className:"rf-min-w-0 rf-w-full",children:[!c&&W.jsx(WW,{className:"rf-flex rf-w-full rf-gap-2",children:a.map(KA=>W.jsx(JD,{value:KA,className:"rf-flex-1 rf-text-xs sm:rf-text-sm",children:Wz[KA].label},KA))}),W.jsx(koi,{query:B,placeholder:Wz[I].placeholder,isSearching:JA,onQueryChange:C,onSubmit:fA}),W.jsx("div",{className:"no-scrollbar rf-mt-4 rf-flex-1 rf-min-h-[200px] !rf-max-h-[40vh] !rf-overflow-y-auto rf-overflow-x-hidden rf-border rf-rounded-md rf-min-w-0",children:JA?W.jsxs("div",{className:"rf-p-8 rf-text-center rf-text-zinc-500",children:[W.jsx(Zb,{className:"rf-h-8 rf-w-8 rf-animate-spin rf-mx-auto rf-mb-2"}),W.jsx("p",{children:"Searching..."})]}):jA.length>0?W.jsx(Goi,{results:jA,selected:Q,onSelect:h,onShowDetails:I==="tscircuit.com"?ce:void 0}):W.jsx("div",{className:"rf-p-8 rf-text-center rf-text-zinc-500",children:WA?`Error: ${WA}`:vA?Wz[I].emptyMessage:"Enter a search term to find components"})})]}):null,QA?W.jsx("div",{className:"rf-text-sm rf-text-red-600 rf-mt-2",children:QA}):null,W.jsxs(XT,{className:"rf-flex rf-flex-col sm:rf-flex-row rf-gap-2",children:[W.jsx(Ja,{variant:"outline",onClick:A,className:"rf-order-2 sm:rf-order-1",children:"Cancel"}),W.jsx(Ja,{onClick:wA,disabled:!Q||dA,className:"rf-order-1 sm:rf-order-2",children:dA?W.jsx(Zb,{className:"rf-h-4 rf-w-4 rf-animate-spin"}):"Import"})]})]}),W.jsx(Loi,{packageResult:sA,isOpen:EA,onOpenChange:MA,isLoading:gA,details:eA,previewTab:_A,onPreviewTabChange:KA=>LA(KA),isSubmitting:dA,onImport:()=>{sA&&ge(sA).then(KA=>{KA&&(bA(!1),A(),VA(),C(""))})}})]})},vsi=t=>{const A=t.match(/export const (\w+) =/);if(!A)throw new Error("Could not determine component name from TSX contents");return A[1]},vue=t=>{const A=MI(s=>s.pushEvent),e=MI(s=>s.upsertFile),i=async({result:s,fullPackageName:r})=>{const g=s.package.unscoped_name??s.package.name;await _s.promise(A({event_type:"INSTALL_PACKAGE",full_package_name:r}),{loading:`Requesting install for "${g}"`,success:`Install requested for "${g}"`,error:c=>`Failed to request install: ${c instanceof Error?c.message:String(c)}`})},n=async({footprint:s})=>{await _s.promise(navigator.clipboard.writeText(s),{loading:`Copying "${s}"`,success:`Copied "${s}" to clipboard`,error:r=>`Failed to copy footprint: ${r instanceof Error?r.message:String(r)}`})},o=async({result:s,tsx:r})=>{const g=`imports/${vsi(r)}.tsx`;await _s.promise(e(g,r),{loading:`Importing ${s.component.partNumber}`,success:`Imported to "${g}"`,error:c=>`Failed to import component: ${c instanceof Error?c.message:String(c)}`})};return W.jsx(ksi,{...t,onTscircuitPackageSelected:i,onKicadStringSelected:n,onJlcpcbComponentTsxLoaded:o})};vue.displayName="ImportComponentDialogForCli";var swA={exports:{}},Fue;function Fsi(){return Fue||(Fue=1,(function(t,A){var e={env:{},version:""};(function(i){t.exports=i()})(function(){return(function i(n,o,s){function r(c,I){if(!o[c]){if(!n[c]){var l=typeof o_=="function"&&o_;if(!I&&l)return l(c,!0);if(a)return a(c,!0);var B=new Error("Cannot find module '"+c+"'");throw B.code="MODULE_NOT_FOUND",B}var C=o[c]={exports:{}};n[c][0].call(C.exports,function(Q){var h=n[c][1][Q];return r(h||Q)},C,C.exports,i,n,o,s)}return o[c].exports}for(var a=typeof o_=="function"&&o_,g=0;g<s.length;g++)r(s[g]);return r})({1:[function(i,n,o){var s=i("./utils"),r=i("./support"),a="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";o.encode=function(g){for(var c,I,l,B,C,Q,h,E=[],u=0,d=g.length,f=d,y=s.getTypeOf(g)!=="string";u<g.length;)f=d-u,l=y?(c=g[u++],I=u<d?g[u++]:0,u<d?g[u++]:0):(c=g.charCodeAt(u++),I=u<d?g.charCodeAt(u++):0,u<d?g.charCodeAt(u++):0),B=c>>2,C=(3&c)<<4|I>>4,Q=1<f?(15&I)<<2|l>>6:64,h=2<f?63&l:64,E.push(a.charAt(B)+a.charAt(C)+a.charAt(Q)+a.charAt(h));return E.join("")},o.decode=function(g){var c,I,l,B,C,Q,h=0,E=0,u="data:";if(g.substr(0,u.length)===u)throw new Error("Invalid base64 input, it looks like a data url.");var d,f=3*(g=g.replace(/[^A-Za-z0-9+/=]/g,"")).length/4;if(g.charAt(g.length-1)===a.charAt(64)&&f--,g.charAt(g.length-2)===a.charAt(64)&&f--,f%1!=0)throw new Error("Invalid base64 input, bad content length.");for(d=r.uint8array?new Uint8Array(0|f):new Array(0|f);h<g.length;)c=a.indexOf(g.charAt(h++))<<2|(B=a.indexOf(g.charAt(h++)))>>4,I=(15&B)<<4|(C=a.indexOf(g.charAt(h++)))>>2,l=(3&C)<<6|(Q=a.indexOf(g.charAt(h++))),d[E++]=c,C!==64&&(d[E++]=I),Q!==64&&(d[E++]=l);return d}},{"./support":30,"./utils":32}],2:[function(i,n,o){var s=i("./external"),r=i("./stream/DataWorker"),a=i("./stream/Crc32Probe"),g=i("./stream/DataLengthProbe");function c(I,l,B,C,Q){this.compressedSize=I,this.uncompressedSize=l,this.crc32=B,this.compression=C,this.compressedContent=Q}c.prototype={getContentWorker:function(){var I=new r(s.Promise.resolve(this.compressedContent)).pipe(this.compression.uncompressWorker()).pipe(new g("data_length")),l=this;return I.on("end",function(){if(this.streamInfo.data_length!==l.uncompressedSize)throw new Error("Bug : uncompressed data size mismatch")}),I},getCompressedWorker:function(){return new r(s.Promise.resolve(this.compressedContent)).withStreamInfo("compressedSize",this.compressedSize).withStreamInfo("uncompressedSize",this.uncompressedSize).withStreamInfo("crc32",this.crc32).withStreamInfo("compression",this.compression)}},c.createWorkerFrom=function(I,l,B){return I.pipe(new a).pipe(new g("uncompressedSize")).pipe(l.compressWorker(B)).pipe(new g("compressedSize")).withStreamInfo("compression",l)},n.exports=c},{"./external":6,"./stream/Crc32Probe":25,"./stream/DataLengthProbe":26,"./stream/DataWorker":27}],3:[function(i,n,o){var s=i("./stream/GenericWorker");o.STORE={magic:"\0\0",compressWorker:function(){return new s("STORE compression")},uncompressWorker:function(){return new s("STORE decompression")}},o.DEFLATE=i("./flate")},{"./flate":7,"./stream/GenericWorker":28}],4:[function(i,n,o){var s=i("./utils"),r=(function(){for(var a,g=[],c=0;c<256;c++){a=c;for(var I=0;I<8;I++)a=1&a?3988292384^a>>>1:a>>>1;g[c]=a}return g})();n.exports=function(a,g){return a!==void 0&&a.length?s.getTypeOf(a)!=="string"?(function(c,I,l,B){var C=r,Q=B+l;c^=-1;for(var h=B;h<Q;h++)c=c>>>8^C[255&(c^I[h])];return-1^c})(0|g,a,a.length,0):(function(c,I,l,B){var C=r,Q=B+l;c^=-1;for(var h=B;h<Q;h++)c=c>>>8^C[255&(c^I.charCodeAt(h))];return-1^c})(0|g,a,a.length,0):0}},{"./utils":32}],5:[function(i,n,o){o.base64=!1,o.binary=!1,o.dir=!1,o.createFolders=!0,o.date=null,o.compression=null,o.compressionOptions=null,o.comment=null,o.unixPermissions=null,o.dosPermissions=null},{}],6:[function(i,n,o){var s=null;s=typeof Promise<"u"?Promise:i("lie"),n.exports={Promise:s}},{lie:37}],7:[function(i,n,o){var s=typeof Uint8Array<"u"&&typeof Uint16Array<"u"&&typeof Uint32Array<"u",r=i("pako"),a=i("./utils"),g=i("./stream/GenericWorker"),c=s?"uint8array":"array";function I(l,B){g.call(this,"FlateWorker/"+l),this._pako=null,this._pakoAction=l,this._pakoOptions=B,this.meta={}}o.magic="\b\0",a.inherits(I,g),I.prototype.processChunk=function(l){this.meta=l.meta,this._pako===null&&this._createPako(),this._pako.push(a.transformTo(c,l.data),!1)},I.prototype.flush=function(){g.prototype.flush.call(this),this._pako===null&&this._createPako(),this._pako.push([],!0)},I.prototype.cleanUp=function(){g.prototype.cleanUp.call(this),this._pako=null},I.prototype._createPako=function(){this._pako=new r[this._pakoAction]({raw:!0,level:this._pakoOptions.level||-1});var l=this;this._pako.onData=function(B){l.push({data:B,meta:l.meta})}},o.compressWorker=function(l){return new I("Deflate",l)},o.uncompressWorker=function(){return new I("Inflate",{})}},{"./stream/GenericWorker":28,"./utils":32,pako:38}],8:[function(i,n,o){function s(C,Q){var h,E="";for(h=0;h<Q;h++)E+=String.fromCharCode(255&C),C>>>=8;return E}function r(C,Q,h,E,u,d){var f,y,w=C.file,D=C.compression,S=d!==c.utf8encode,_=a.transformTo("string",d(w.name)),b=a.transformTo("string",c.utf8encode(w.name)),N=w.comment,F=a.transformTo("string",d(N)),L=a.transformTo("string",c.utf8encode(N)),Y=b.length!==w.name.length,J=L.length!==N.length,O="",Z="",X="",eA=w.dir,gA=w.date,tA={crc32:0,compressedSize:0,uncompressedSize:0};Q&&!h||(tA.crc32=C.crc32,tA.compressedSize=C.compressedSize,tA.uncompressedSize=C.uncompressedSize);var iA=0;Q&&(iA|=8),S||!Y&&!J||(iA|=2048);var sA=0,aA=0;eA&&(sA|=16),u==="UNIX"?(aA=798,sA|=(function(bA,_A){var LA=bA;return bA||(LA=_A?16893:33204),(65535&LA)<<16})(w.unixPermissions,eA)):(aA=20,sA|=(function(bA){return 63&(bA||0)})(w.dosPermissions)),f=gA.getUTCHours(),f<<=6,f|=gA.getUTCMinutes(),f<<=5,f|=gA.getUTCSeconds()/2,y=gA.getUTCFullYear()-1980,y<<=4,y|=gA.getUTCMonth()+1,y<<=5,y|=gA.getUTCDate(),Y&&(Z=s(1,1)+s(I(_),4)+b,O+="up"+s(Z.length,2)+Z),J&&(X=s(1,1)+s(I(F),4)+L,O+="uc"+s(X.length,2)+X);var EA="";return EA+=`
5702
+ For more information, see https://radix-ui.com/primitives/docs/components/alert-dialog`;return V.useEffect(()=>{document.getElementById(t.current?.getAttribute("aria-describedby"))||console.warn(A)},[A,t]),null},Qoi=PEe,hoi=KEe,Aue=qEe,eue=OEe,tue=zEe,iue=$Ee,nue=ZEe,oue=jEe;const sue=Qoi,Eoi=hoi,rue=V.forwardRef(({className:t,...A},e)=>W.jsx(Aue,{className:hn("rf-fixed rf-inset-0 rf-z-50 rf-bg-black/80 data-[state=open]:rf-animate-in data-[state=closed]:rf-animate-out data-[state=closed]:rf-fade-out-0 data-[state=open]:rf-fade-in-0",t),...A,ref:e}));rue.displayName=Aue.displayName;const JmA=V.forwardRef(({className:t,...A},e)=>W.jsxs(Eoi,{children:[W.jsx(rue,{}),W.jsx(eue,{ref:e,className:hn("rf-fixed rf-left-[50%] rf-top-[50%] rf-z-50 rf-grid rf-w-full rf-max-w-lg rf-translate-x-[-50%] rf-translate-y-[-50%] rf-gap-4 rf-border rf-border-zinc-200 rf-bg-white rf-p-6 rf-shadow-lg rf-duration-200 data-[state=open]:rf-animate-in data-[state=closed]:rf-animate-out data-[state=closed]:rf-fade-out-0 data-[state=open]:rf-fade-in-0 data-[state=closed]:rf-zoom-out-95 data-[state=open]:rf-zoom-in-95 data-[state=closed]:rf-slide-out-to-left-1/2 data-[state=closed]:rf-slide-out-to-top-[48%] data-[state=open]:rf-slide-in-from-left-1/2 data-[state=open]:rf-slide-in-from-top-[48%] sm:rf-rounded-lg dark:rf-border-zinc-800 dark:rf-bg-zinc-950",t),...A})]}));JmA.displayName=eue.displayName;const TmA=({className:t,...A})=>W.jsx("div",{className:hn("rf-flex rf-flex-col rf-space-y-2 rf-text-center sm:rf-text-left",t),...A});TmA.displayName="AlertDialogHeader";const PmA=({className:t,...A})=>W.jsx("div",{className:hn("rf-flex rf-flex-col-reverse sm:rf-flex-row sm:rf-justify-end sm:rf-space-x-2",t),...A});PmA.displayName="AlertDialogFooter";const KmA=V.forwardRef(({className:t,...A},e)=>W.jsx(nue,{ref:e,className:hn("rf-text-lg rf-font-semibold",t),...A}));KmA.displayName=nue.displayName;const qmA=V.forwardRef(({className:t,...A},e)=>W.jsx(oue,{ref:e,className:hn("rf-text-sm rf-text-zinc-500 dark:rf-text-zinc-400",t),...A}));qmA.displayName=oue.displayName;const uoi=V.forwardRef(({className:t,...A},e)=>W.jsx(tue,{ref:e,className:hn(V1(),t),...A}));uoi.displayName=tue.displayName;const OmA=V.forwardRef(({className:t,...A},e)=>W.jsx(iue,{ref:e,className:hn(V1({variant:"outline"}),"rf-mt-2 sm:rf-mt-0",t),...A}));OmA.displayName=iue.displayName;function doi(t){const A=V.useRef({value:t,previous:t});return V.useMemo(()=>(A.current.value!==t&&(A.current.previous=A.current.value,A.current.value=t),A.current.previous),[t])}var Oz="Checkbox",[poi]=dw(Oz),[foi,WmA]=poi(Oz);function yoi(t){const{__scopeCheckbox:A,checked:e,children:i,defaultChecked:n,disabled:o,form:s,name:r,onCheckedChange:a,required:g,value:c="on",internal_do_not_use_render:I}=t,[l,B]=G_({prop:e,defaultProp:n??!1,onChange:a,caller:Oz}),[C,Q]=V.useState(null),[h,E]=V.useState(null),u=V.useRef(!1),d=C?!!s||!!C.closest("form"):!0,f={checked:l,disabled:o,setChecked:B,control:C,setControl:Q,name:r,form:s,value:c,hasConsumerStoppedPropagationRef:u,required:g,defaultChecked:Ok(n)?!1:n,isFormControl:d,bubbleInput:h,setBubbleInput:E};return W.jsx(foi,{scope:A,...f,children:moi(I)?I(f):i})}var aue="CheckboxTrigger",gue=V.forwardRef(({__scopeCheckbox:t,onKeyDown:A,onClick:e,...i},n)=>{const{control:o,value:s,disabled:r,checked:a,required:g,setControl:c,setChecked:I,hasConsumerStoppedPropagationRef:l,isFormControl:B,bubbleInput:C}=WmA(aue,t),Q=RI(n,c),h=V.useRef(a);return V.useEffect(()=>{const E=o?.form;if(E){const u=()=>I(h.current);return E.addEventListener("reset",u),()=>E.removeEventListener("reset",u)}},[o,I]),W.jsx(Ag.button,{type:"button",role:"checkbox","aria-checked":Ok(a)?"mixed":a,"aria-required":g,"data-state":Cue(a),"data-disabled":r?"":void 0,disabled:r,value:s,...i,ref:Q,onKeyDown:Vn(A,E=>{E.key==="Enter"&&E.preventDefault()}),onClick:Vn(e,E=>{I(u=>Ok(u)?!0:!u),C&&B&&(l.current=E.isPropagationStopped(),l.current||E.stopPropagation())})})});gue.displayName=aue;var ZmA=V.forwardRef((t,A)=>{const{__scopeCheckbox:e,name:i,checked:n,defaultChecked:o,required:s,disabled:r,value:a,onCheckedChange:g,form:c,...I}=t;return W.jsx(yoi,{__scopeCheckbox:e,checked:n,defaultChecked:o,disabled:r,required:s,onCheckedChange:g,name:i,form:c,value:a,internal_do_not_use_render:({isFormControl:l})=>W.jsxs(W.Fragment,{children:[W.jsx(gue,{...I,ref:A,__scopeCheckbox:e}),l&&W.jsx(Bue,{__scopeCheckbox:e})]})})});ZmA.displayName=Oz;var cue="CheckboxIndicator",Iue=V.forwardRef((t,A)=>{const{__scopeCheckbox:e,forceMount:i,...n}=t,o=WmA(cue,e);return W.jsx(q0,{present:i||Ok(o.checked)||o.checked===!0,children:W.jsx(Ag.span,{"data-state":Cue(o.checked),"data-disabled":o.disabled?"":void 0,...n,ref:A,style:{pointerEvents:"none",...t.style}})})});Iue.displayName=cue;var lue="CheckboxBubbleInput",Bue=V.forwardRef(({__scopeCheckbox:t,...A},e)=>{const{control:i,hasConsumerStoppedPropagationRef:n,checked:o,defaultChecked:s,required:r,disabled:a,name:g,value:c,form:I,bubbleInput:l,setBubbleInput:B}=WmA(lue,t),C=RI(e,B),Q=doi(o),h=Hre(i);V.useEffect(()=>{const u=l;if(!u)return;const d=window.HTMLInputElement.prototype,y=Object.getOwnPropertyDescriptor(d,"checked").set,w=!n.current;if(Q!==o&&y){const D=new Event("click",{bubbles:w});u.indeterminate=Ok(o),y.call(u,Ok(o)?!1:o),u.dispatchEvent(D)}},[l,Q,o,n]);const E=V.useRef(Ok(o)?!1:o);return W.jsx(Ag.input,{type:"checkbox","aria-hidden":!0,defaultChecked:s??E.current,required:r,disabled:a,name:g,value:c,form:I,...A,tabIndex:-1,ref:C,style:{...A.style,...h,position:"absolute",pointerEvents:"none",opacity:0,margin:0,transform:"translateX(-100%)"}})});Bue.displayName=lue;function moi(t){return typeof t=="function"}function Ok(t){return t==="indeterminate"}function Cue(t){return Ok(t)?"indeterminate":t?"checked":"unchecked"}const zT=V.forwardRef(({className:t,...A},e)=>W.jsx(ZmA,{ref:e,className:hn("rf-peer rf-h-4 rf-w-4 rf-shrink-0 rf-rounded-sm rf-border rf-border-zinc-200 rf-border-zinc-900 rf-shadow focus-visible:rf-outline-none focus-visible:rf-ring-1 focus-visible:rf-ring-zinc-950 disabled:rf-cursor-not-allowed disabled:rf-opacity-50 data-[state=checked]:rf-bg-zinc-900 data-[state=checked]:rf-text-zinc-50 dark:rf-border-zinc-800 dark:rf-border-zinc-50 dark:focus-visible:rf-ring-zinc-300 dark:data-[state=checked]:rf-bg-zinc-50 dark:data-[state=checked]:rf-text-zinc-900",t),...A,children:W.jsx(Iue,{className:hn("rf-flex rf-items-center rf-justify-center rf-text-current"),children:W.jsx(hM,{className:"rf-h-4 rf-w-4"})})}));zT.displayName=ZmA.displayName;const x2=LmA,woi=UmA,Que=V.forwardRef(({className:t,...A},e)=>W.jsx(Kz,{className:hn("rf-fixed rf-inset-0 rf-z-50 rf-bg-black/80 data-[state=open]:rf-animate-in data-[state=closed]:rf-animate-out data-[state=closed]:rf-fade-out-0 data-[state=open]:rf-fade-in-0",t),...A,ref:e}));Que.displayName=Kz.displayName;const KM=V.forwardRef(({className:t,children:A,showOverlay:e=!0,...i},n)=>W.jsxs(woi,{children:[W.jsx(Que,{className:hn(e?"":"rf-hidden")}),W.jsx(qz,{ref:n,className:hn("rf-fixed rf-left-[50%] rf-top-[50%] rf-z-50 rf-grid rf-w-full rf-max-w-lg rf-translate-x-[-50%] rf-translate-y-[-50%] rf-gap-4 rf-border rf-border-zinc-200 rf-bg-white rf-p-6 rf-shadow-lg rf-duration-200 data-[state=open]:rf-animate-in data-[state=closed]:rf-animate-out data-[state=closed]:rf-fade-out-0 data-[state=open]:rf-fade-in-0 data-[state=closed]:rf-zoom-out-95 data-[state=open]:rf-zoom-in-95 data-[state=closed]:rf-slide-out-to-left-1/2 data-[state=closed]:rf-slide-out-to-top-[48%] data-[state=open]:rf-slide-in-from-left-1/2 data-[state=open]:rf-slide-in-from-top-[48%] sm:rf-rounded-lg dark:rf-border-zinc-800 dark:rf-bg-zinc-950",t),...i,children:A})]}));KM.displayName=qz.displayName;const qM=({className:t,...A})=>W.jsx("div",{className:hn("rf-flex rf-flex-col rf-space-y-2 rf-text-center sm:rf-text-left",t),...A});qM.displayName="DialogHeader";const XT=({className:t,...A})=>W.jsx("div",{className:hn("rf-flex rf-flex-col-reverse sm:rf-flex-row sm:rf-justify-end sm:rf-space-x-2",t),...A});XT.displayName="DialogFooter";const OM=V.forwardRef(({className:t,...A},e)=>W.jsx(HmA,{ref:e,className:hn("rf-text-lg rf-font-semibold",t),...A}));OM.displayName=HmA.displayName;const _2=V.forwardRef(({className:t,...A},e)=>W.jsx(YmA,{ref:e,className:hn("rf-text-sm rf-text-zinc-500 dark:rf-text-zinc-400",t),...A}));_2.displayName=YmA.displayName;const Wz={"tscircuit.com":{label:"tscircuit.com",placeholder:"Search tscircuit packages...",emptyMessage:"No packages found"},jlcpcb:{label:"JLCPCB Parts",placeholder:"Search JLCPCB parts (e.g. C14663)...",emptyMessage:"No parts found"},kicad:{label:"KiCad Footprints",placeholder:"Search KiCad footprints...",emptyMessage:"No footprints found"}},Doi="https://cdn.jsdelivr.net/npm/easyeda@latest/dist/browser/index.js";let VmA=null;const Soi=async()=>(VmA||(VmA=import(Doi)),VmA),boi=async(t,A=10)=>{const e=encodeURIComponent(t),i=await fetch(`https://jlcsearch.tscircuit.com/api/search?limit=${A}&q=${e}`);if(!i.ok)throw new Error(`JLCPCB API error: ${i.status}`);return(await i.json()).components??[]},xoi=t=>({lcscId:t.lcsc,manufacturer:t.mfr,description:t.description,partNumber:`C${t.lcsc}`,package:t.package,price:t.price,stock:t.stock,isBasic:t.is_basic}),_oi=async(t,A)=>{const{fetchEasyEDAComponent:e,convertRawEasyToTsx:i}=await Soi(),n=await e(t,{fetch:(o,s)=>fetch(`${A?.apiBase??xf}/proxy`,{...s,headers:{...s?.headers,"X-Target-Url":o.toString(),"X-Sender-Origin":s?.headers?.origin??"","X-Sender-Host":s?.headers?.host??"https://easyeda.com","X-Sender-Referer":s?.headers?.referer??"","X-Sender-User-Agent":s?.headers?.userAgent??"","X-Sender-Cookie":s?.headers?.cookie??"",authority:s?.headers?.authority??"","content-type":s?.headers?.["content-type"]??"",...A?.headers}})});return i({rawEasy:n})},koi=({query:t,placeholder:A,isSearching:e,onQueryChange:i,onSubmit:n})=>{const o=V.useCallback(s=>{s.key==="Enter"&&(s.preventDefault(),n())},[n]);return W.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2 rf-mt-4",children:[W.jsxs("div",{className:"rf-relative rf-flex-grow",children:[W.jsx(xfA,{className:"rf-absolute rf-left-2 rf-top-2.5 rf-h-4 rf-w-4 rf-text-muted-foreground"}),W.jsx(cyA,{placeholder:A,className:"rf-pl-8",spellCheck:!1,autoComplete:"off",value:t,onChange:s=>i(s.target.value),onKeyDown:o})]}),W.jsx(Ja,{onClick:n,disabled:e||t.trim().length<1,className:"sm:rf-px-4 rf-px-3",children:e?W.jsx(Zb,{className:"rf-h-4 rf-w-4 rf-animate-spin"}):W.jsxs(W.Fragment,{children:[W.jsx(xfA,{className:"rf-h-4 rf-w-4 sm:rf-hidden"}),W.jsx("span",{className:"rf-hidden sm:rf-inline",children:"Search"})]})})]})},voi=new Intl.NumberFormat("en-US",{style:"currency",currency:"USD"}),Foi=t=>voi.format(t),hue=t=>{switch(t.source){case"tscircuit.com":{const A=t.package;return`tscircuit-${A.package_id??`${A.org_owner_tscircuit_handle??"unknown"}-${A.unscoped_name??A.name??"package"}`}`}case"jlcpcb":return`jlc-${t.component.lcscId}`;case"kicad":return`kicad-${t.footprint.path}`;default:return"unknown"}},Moi=t=>{switch(t.source){case"tscircuit.com":return t.package.unscoped_name;case"jlcpcb":return t.component.manufacturer;case"kicad":return t.footprint.qualifiedName}},Roi=t=>{switch(t.source){case"tscircuit.com":return t.package.description||(t.package.org_owner_tscircuit_handle?`Component by ${t.package.org_owner_tscircuit_handle}`:void 0);case"jlcpcb":return t.component.description;case"kicad":return t.footprint.description}},Noi=t=>{switch(t.source){case"tscircuit.com":return t.package.name;case"jlcpcb":return t.component.partNumber;case"kicad":return}},Goi=({results:t,selected:A,onSelect:e,onShowDetails:i})=>{const n=A?hue(A):null;return W.jsx("div",{className:"rf-divide-y rf-w-full rf-overflow-hidden",children:t.map(o=>{const s=hue(o),r=n===s,a=Moi(o),g=Roi(o),c=Noi(o),I=o.source==="jlcpcb"?o.component.stock:null,l=o.source==="jlcpcb"?o.component.price:null,B=o.source==="jlcpcb"?o.component.isBasic:null;return W.jsxs("div",{className:`rf-p-3 rf-flex rf-flex-col sm:rf-grid sm:rf-grid-cols-[minmax(0,1fr)_auto] rf-items-start sm:rf-items-center rf-cursor-pointer hover:rf-bg-zinc-100 rf-gap-2 rf-overflow-hidden ${r?"rf-bg-zinc-100":""}`,onClick:()=>e(o),children:[W.jsxs("div",{className:"rf-min-w-0 rf-overflow-hidden rf-w-full",children:[W.jsxs("div",{className:"rf-flex rf-items-start rf-gap-2 rf-min-w-0",children:[W.jsxs("div",{className:"rf-font-medium rf-text-sm rf-truncate rf-flex-1 rf-min-w-0 rf-flex rf-items-center rf-gap-1.5",children:[a,o.source==="jlcpcb"&&B!=null&&W.jsx("span",{className:`rf-text-xs rf-px-1.5 rf-py-0.5 rf-rounded rf-font-medium rf-flex-shrink-0 ${B?"rf-bg-green-100 rf-text-green-700":"rf-bg-orange-100 rf-text-orange-700"}`,children:B?"Basic":"Extended"}),o.source==="tscircuit.com"&&o.package.is_private&&W.jsx(wqt,{className:"rf-ml-1 rf-h-3 rf-w-3 rf-text-zinc-400 rf-flex-shrink-0"})]}),o.source==="jlcpcb"&&I!=null?W.jsxs("div",{className:"rf-text-xs rf-text-zinc-500 rf-font-medium rf-whitespace-nowrap rf-flex-shrink-0 sm:rf-hidden",children:[I.toLocaleString()," in stock"]}):null]}),W.jsxs("div",{className:"rf-text-xs rf-text-zinc-500 rf-truncate rf-w-full",children:[c?W.jsx("span",{className:"rf-mr-2",children:c}):null,g]})]}),W.jsxs("div",{children:[o.source==="tscircuit.com"&&i?W.jsx("div",{className:"rf-flex-shrink-0 rf-w-full sm:rf-w-auto",children:W.jsx(Ja,{variant:"outline",size:"sm",className:"rf-text-xs rf-w-full sm:rf-w-auto",onClick:C=>{C.stopPropagation(),i(o)},children:"See Details"})}):o.source==="jlcpcb"&&I!=null?W.jsxs("div",{className:"rf-hidden sm:rf-block rf-text-xs rf-text-zinc-500 rf-font-medium rf-whitespace-nowrap rf-flex-shrink-0",children:[I.toLocaleString()," in stock"]}):null,l!=null&&W.jsx("div",{className:"rf-hidden sm:rf-block rf-text-xs rf-text-zinc-500 rf-font-medium rf-whitespace-nowrap rf-flex-shrink-0 rf-text-right",children:Foi(l)})]})]},s)})})},Loi=({packageResult:t,isOpen:A,onOpenChange:e,isLoading:i,details:n,previewTab:o,onPreviewTabChange:s,isSubmitting:r,onImport:a})=>{const g=t?.package??null,c=g?.latest_pcb_preview_image_url,I=g?.latest_sch_preview_image_url,l=g?.latest_cad_preview_image_url,B=g?.unscoped_name?.split("/").pop()??g?.unscoped_name,C=g?.org_owner_tscircuit_handle??void 0,Q=C?`https://tscircuit.com/${C}`:void 0,h=C&&B?`https://tscircuit.com/${C}/${B}`:void 0;return W.jsx(x2,{open:A,onOpenChange:e,children:W.jsxs(KM,{showOverlay:!1,style:{width:"calc(100vw - 2rem)"},className:"rf-max-w-5xl no-scrollbar !rf-overflow-y-auto rf-max-h-[90vh] rf-overflow-hidden rf-flex rf-flex-col rf-rounded-sm",children:[W.jsx(qM,{className:"rf-pb-4 rf-border-b",children:W.jsx("div",{className:"rf-flex rf-items-start rf-justify-between rf-gap-4",children:W.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[W.jsx(OM,{className:"rf-text-xl rf-font-semibold rf-truncate",children:B}),W.jsx(_2,{children:g?.description})]})})}),W.jsxs("div",{className:"rf-flex-1 rf-overflow-y-auto rf-py-4 rf-space-y-6",children:[C?W.jsxs("div",{children:[W.jsx("span",{className:"rf-text-xs rf-font-medium rf-text-gray-500 rf-uppercase rf-tracking-wide",children:"Created by"}),W.jsx("div",{className:"rf-mt-1 rf-text-sm rf-font-medium",children:Q?W.jsx("a",{href:Q,target:"_blank",rel:"noopener noreferrer",className:"rf-text-black hover:rf-underline",children:C}):C})]}):null,(l||c||I)&&W.jsx(W.Fragment,{children:W.jsxs("div",{children:[W.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-mb-4",children:"Preview"}),W.jsxs(DgA,{value:o,onValueChange:E=>s(E),children:[W.jsxs(WW,{className:"rf-inline-flex rf-h-9 rf-items-center rf-justify-center rf-rounded-lg rf-bg-zinc-100 rf-p-1 rf-text-zinc-500 dark:rf-bg-zinc-800 dark:rf-text-zinc-400",children:[c&&W.jsx(JD,{value:"pcb",children:"PCB"}),I&&W.jsx(JD,{value:"schematic",children:"Schematic"}),l&&W.jsx(JD,{value:"3d",children:"3D"})]}),W.jsxs("div",{className:"rf-mt-4",children:[W.jsx(td,{value:"pcb",className:"rf-border rf-rounded-lg rf-overflow-hidden rf-bg-gray-50",children:c?W.jsx("img",{src:c,alt:`${B??"package"} PCB preview`,className:"rf-w-full rf-h-full rf-object-contain rf-bg-white rf-p-4"}):null}),W.jsx(td,{value:"schematic",className:"rf-border rf-rounded-lg rf-overflow-hidden rf-bg-gray-50",children:I?W.jsx("img",{src:I,alt:`${B??"package"} schematic preview`,className:"rf-w-full rf-h-full rf-object-contain rf-bg-white rf-p-4"}):null}),W.jsx(td,{value:"3d",className:"rf-border rf-rounded-lg rf-overflow-hidden rf-bg-gray-50",children:l?W.jsx("img",{src:l,alt:`${B??"package"} 3D preview`,className:"rf-w-full rf-h-full rf-object-contain rf-bg-white rf-p-4"}):null})]})]})]})}),n?.ai_description?W.jsxs("section",{children:[W.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-mb-3",children:"AI Description"}),W.jsx("div",{className:"rf-bg-gray-50 rf-border rf-border-gray-200 rf-rounded-lg rf-p-4",children:W.jsx("p",{className:"rf-text-sm rf-text-gray-700 rf-leading-relaxed",children:n.ai_description})})]}):null,n?.ai_usage_instructions?W.jsxs("section",{children:[W.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-mb-3",children:"Usage Instructions"}),W.jsx("div",{className:"rf-bg-gray-50 rf-border rf-border-gray-200 rf-rounded-lg rf-p-4",children:W.jsx("p",{className:"rf-text-sm rf-text-gray-700 rf-leading-relaxed rf-whitespace-pre-wrap",children:n.ai_usage_instructions})})]}):null,i?W.jsxs("div",{className:"rf-flex rf-justify-center rf-items-center rf-gap-2 rf-text-gray-500",children:[W.jsx(Zb,{className:"rf-h-4 rf-w-4 rf-animate-spin"}),W.jsx("span",{className:"rf-text-sm",children:"Loading package details..."})]}):null]}),W.jsxs(XT,{className:"rf-pt-4 rf-border-t rf-flex rf-flex-col sm:rf-flex-row rf-justify-between rf-gap-2",children:[W.jsx("div",{className:"rf-flex-1",children:h?W.jsxs(Ja,{variant:"outline",size:"sm",className:"rf-gap-2 rf-w-full sm:rf-w-auto",onClick:()=>window.open(h,"_blank"),children:[W.jsx(Eqt,{className:"rf-h-4 rf-w-4"}),"View on tscircuit.com"]}):null}),W.jsxs("div",{className:"rf-flex rf-flex-col sm:rf-flex-row rf-gap-2",children:[W.jsx(Ja,{variant:"outline",onClick:()=>e(!1),className:"rf-order-2 sm:rf-order-1",children:"Close"}),W.jsx(Ja,{onClick:a,disabled:r,className:"rf-bg-blue-600 hover:rf-bg-blue-700",children:r?W.jsx(Zb,{className:"rf-h-4 rf-w-4 rf-animate-spin"}):"Import Component"})]})]})]})})},Uoi=()=>{const[t,A]=V.useState(null),[e,i]=V.useState(!1),n=V.useCallback(async(s,r)=>{i(!0);try{const a=await fetch(`https://api.tscircuit.com/packages/get?name=${encodeURIComponent(`${s}/${r}`)}`);if(!a.ok)throw new Error(`Failed to load package details: ${a.status}`);const g=await a.json();A(g.package??null)}catch(a){console.error("Failed to fetch package details",a),A(null)}finally{i(!1)}},[]),o=V.useCallback(()=>{A(null),i(!1)},[]);return{details:t,isLoading:e,fetchDetails:n,reset:o}},Hoi=async(t,A)=>{const e={"Content-Type":"application/json"};A&&(e.Authorization=`Bearer ${A}`);const i=await fetch("https://registry-api.tscircuit.com/packages/search",{method:"POST",headers:e,body:JSON.stringify({query:t})});if(!i.ok)throw new Error(`tscircuit registry error: ${i.status}`);return(await i.json()).packages??[]},Yoi=({sessionToken:t})=>{const[A,e]=V.useState([]),[i,n]=V.useState(!1),[o,s]=V.useState(null),[r,a]=V.useState(!1),g=V.useCallback(async I=>{const l=I.trim();if(!l)return[];n(!0),s(null);try{const C=(await Hoi(l,t)).map(Q=>({source:"tscircuit.com",package:Q}));return e(C),C}catch(B){return console.error("Error searching tscircuit packages",B),e([]),s(B instanceof Error?B.message:"Failed to search tscircuit packages"),[]}finally{n(!1),a(!0)}},[t]),c=V.useCallback(()=>{e([]),n(!1),s(null),a(!1)},[]);return{results:A,isSearching:i,error:o,hasSearched:r,search:g,reset:c}},Joi=t=>{const A=t.trim();return/^C\d+/i.test(A)?A.replace(/^C/i,""):A},Toi=()=>{const[t,A]=V.useState([]),[e,i]=V.useState(!1),[n,o]=V.useState(null),[s,r]=V.useState(!1),a=V.useCallback(async c=>{const I=Joi(c);if(!I)return[];i(!0),o(null);try{const B=(await boi(I,10)).map(C=>({source:"jlcpcb",component:xoi(C)}));return A(B),B}catch(l){return console.error("Error searching JLCPCB components",l),A([]),o(l instanceof Error?l.message:"Failed to search JLCPCB components"),[]}finally{i(!1),r(!0)}},[]),g=V.useCallback(()=>{A([]),i(!1),o(null),r(!1)},[]);return{results:t,isSearching:e,error:n,hasSearched:s,search:a,reset:g}};function gx(t){return Array.isArray?Array.isArray(t):due(t)==="[object Array]"}function Poi(t){if(typeof t=="string")return t;let A=t+"";return A=="0"&&1/t==-1/0?"-0":A}function Koi(t){return t==null?"":Poi(t)}function DS(t){return typeof t=="string"}function Eue(t){return typeof t=="number"}function qoi(t){return t===!0||t===!1||Ooi(t)&&due(t)=="[object Boolean]"}function uue(t){return typeof t=="object"}function Ooi(t){return uue(t)&&t!==null}function Cy(t){return t!=null}function jmA(t){return!t.trim().length}function due(t){return t==null?t===void 0?"[object Undefined]":"[object Null]":Object.prototype.toString.call(t)}const Woi="Incorrect 'index' type",Zoi=t=>`Invalid value for key ${t}`,Voi=t=>`Pattern length exceeds max of ${t}.`,joi=t=>`Missing ${t} property in key`,zoi=t=>`Property 'weight' in key '${t}' must be a positive integer`,pue=Object.prototype.hasOwnProperty;class Xoi{constructor(A){this._keys=[],this._keyMap={};let e=0;A.forEach(i=>{let n=fue(i);this._keys.push(n),this._keyMap[n.id]=n,e+=n.weight}),this._keys.forEach(i=>{i.weight/=e})}get(A){return this._keyMap[A]}keys(){return this._keys}toJSON(){return JSON.stringify(this._keys)}}function fue(t){let A=null,e=null,i=null,n=1,o=null;if(DS(t)||gx(t))i=t,A=yue(t),e=zmA(t);else{if(!pue.call(t,"name"))throw new Error(joi("name"));const s=t.name;if(i=s,pue.call(t,"weight")&&(n=t.weight,n<=0))throw new Error(zoi(s));A=yue(s),e=zmA(s),o=t.getFn}return{path:A,id:e,weight:n,src:i,getFn:o}}function yue(t){return gx(t)?t:t.split(".")}function zmA(t){return gx(t)?t.join("."):t}function $oi(t,A){let e=[],i=!1;const n=(o,s,r)=>{if(Cy(o))if(!s[r])e.push(o);else{let a=s[r];const g=o[a];if(!Cy(g))return;if(r===s.length-1&&(DS(g)||Eue(g)||qoi(g)))e.push(Koi(g));else if(gx(g)){i=!0;for(let c=0,I=g.length;c<I;c+=1)n(g[c],s,r+1)}else s.length&&n(g,s,r+1)}};return n(t,DS(A)?A.split("."):A,0),i?e:e[0]}var Zo={...{isCaseSensitive:!1,ignoreDiacritics:!1,includeScore:!1,keys:[],shouldSort:!0,sortFn:(t,A)=>t.score===A.score?t.idx<A.idx?-1:1:t.score<A.score?-1:1},...{includeMatches:!1,findAllMatches:!1,minMatchCharLength:1},...{location:0,threshold:.6,distance:100},...{useExtendedSearch:!1,getFn:$oi,ignoreLocation:!1,ignoreFieldNorm:!1,fieldNormWeight:1}};const Asi=/[^ ]+/g;function esi(t=1,A=3){const e=new Map,i=Math.pow(10,A);return{get(n){const o=n.match(Asi).length;if(e.has(o))return e.get(o);const s=1/Math.pow(o,.5*t),r=parseFloat(Math.round(s*i)/i);return e.set(o,r),r},clear(){e.clear()}}}class XmA{constructor({getFn:A=Zo.getFn,fieldNormWeight:e=Zo.fieldNormWeight}={}){this.norm=esi(e,3),this.getFn=A,this.isCreated=!1,this.setIndexRecords()}setSources(A=[]){this.docs=A}setIndexRecords(A=[]){this.records=A}setKeys(A=[]){this.keys=A,this._keysMap={},A.forEach((e,i)=>{this._keysMap[e.id]=i})}create(){this.isCreated||!this.docs.length||(this.isCreated=!0,DS(this.docs[0])?this.docs.forEach((A,e)=>{this._addString(A,e)}):this.docs.forEach((A,e)=>{this._addObject(A,e)}),this.norm.clear())}add(A){const e=this.size();DS(A)?this._addString(A,e):this._addObject(A,e)}removeAt(A){this.records.splice(A,1);for(let e=A,i=this.size();e<i;e+=1)this.records[e].i-=1}getValueForItemAtKeyId(A,e){return A[this._keysMap[e]]}size(){return this.records.length}_addString(A,e){if(!Cy(A)||jmA(A))return;let i={v:A,i:e,n:this.norm.get(A)};this.records.push(i)}_addObject(A,e){let i={i:e,$:{}};this.keys.forEach((n,o)=>{let s=n.getFn?n.getFn(A):this.getFn(A,n.path);if(Cy(s)){if(gx(s)){let r=[];const a=[{nestedArrIndex:-1,value:s}];for(;a.length;){const{nestedArrIndex:g,value:c}=a.pop();if(Cy(c))if(DS(c)&&!jmA(c)){let I={v:c,i:g,n:this.norm.get(c)};r.push(I)}else gx(c)&&c.forEach((I,l)=>{a.push({nestedArrIndex:l,value:I})})}i.$[o]=r}else if(DS(s)&&!jmA(s)){let r={v:s,n:this.norm.get(s)};i.$[o]=r}}}),this.records.push(i)}toJSON(){return{keys:this.keys,records:this.records}}}function mue(t,A,{getFn:e=Zo.getFn,fieldNormWeight:i=Zo.fieldNormWeight}={}){const n=new XmA({getFn:e,fieldNormWeight:i});return n.setKeys(t.map(fue)),n.setSources(A),n.create(),n}function tsi(t,{getFn:A=Zo.getFn,fieldNormWeight:e=Zo.fieldNormWeight}={}){const{keys:i,records:n}=t,o=new XmA({getFn:A,fieldNormWeight:e});return o.setKeys(i),o.setIndexRecords(n),o}function Zz(t,{errors:A=0,currentLocation:e=0,expectedLocation:i=0,distance:n=Zo.distance,ignoreLocation:o=Zo.ignoreLocation}={}){const s=A/t.length;if(o)return s;const r=Math.abs(i-e);return n?s+r/n:r?1:s}function isi(t=[],A=Zo.minMatchCharLength){let e=[],i=-1,n=-1,o=0;for(let s=t.length;o<s;o+=1){let r=t[o];r&&i===-1?i=o:!r&&i!==-1&&(n=o-1,n-i+1>=A&&e.push([i,n]),i=-1)}return t[o-1]&&o-i>=A&&e.push([i,o-1]),e}const WM=32;function nsi(t,A,e,{location:i=Zo.location,distance:n=Zo.distance,threshold:o=Zo.threshold,findAllMatches:s=Zo.findAllMatches,minMatchCharLength:r=Zo.minMatchCharLength,includeMatches:a=Zo.includeMatches,ignoreLocation:g=Zo.ignoreLocation}={}){if(A.length>WM)throw new Error(Voi(WM));const c=A.length,I=t.length,l=Math.max(0,Math.min(i,I));let B=o,C=l;const Q=r>1||a,h=Q?Array(I):[];let E;for(;(E=t.indexOf(A,C))>-1;){let D=Zz(A,{currentLocation:E,expectedLocation:l,distance:n,ignoreLocation:g});if(B=Math.min(D,B),C=E+c,Q){let S=0;for(;S<c;)h[E+S]=1,S+=1}}C=-1;let u=[],d=1,f=c+I;const y=1<<c-1;for(let D=0;D<c;D+=1){let S=0,_=f;for(;S<_;)Zz(A,{errors:D,currentLocation:l+_,expectedLocation:l,distance:n,ignoreLocation:g})<=B?S=_:f=_,_=Math.floor((f-S)/2+S);f=_;let b=Math.max(1,l-_+1),N=s?I:Math.min(l+_,I)+c,F=Array(N+2);F[N+1]=(1<<D)-1;for(let Y=N;Y>=b;Y-=1){let J=Y-1,O=e[t.charAt(J)];if(Q&&(h[J]=+!!O),F[Y]=(F[Y+1]<<1|1)&O,D&&(F[Y]|=(u[Y+1]|u[Y])<<1|1|u[Y+1]),F[Y]&y&&(d=Zz(A,{errors:D,currentLocation:J,expectedLocation:l,distance:n,ignoreLocation:g}),d<=B)){if(B=d,C=J,C<=l)break;b=Math.max(1,2*l-C)}}if(Zz(A,{errors:D+1,currentLocation:l,expectedLocation:l,distance:n,ignoreLocation:g})>B)break;u=F}const w={isMatch:C>=0,score:Math.max(.001,d)};if(Q){const D=isi(h,r);D.length?a&&(w.indices=D):w.isMatch=!1}return w}function osi(t){let A={};for(let e=0,i=t.length;e<i;e+=1){const n=t.charAt(e);A[n]=(A[n]||0)|1<<i-e-1}return A}const Vz=String.prototype.normalize?(t=>t.normalize("NFD").replace(/[\u0300-\u036F\u0483-\u0489\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u0610-\u061A\u064B-\u065F\u0670\u06D6-\u06DC\u06DF-\u06E4\u06E7\u06E8\u06EA-\u06ED\u0711\u0730-\u074A\u07A6-\u07B0\u07EB-\u07F3\u07FD\u0816-\u0819\u081B-\u0823\u0825-\u0827\u0829-\u082D\u0859-\u085B\u08D3-\u08E1\u08E3-\u0903\u093A-\u093C\u093E-\u094F\u0951-\u0957\u0962\u0963\u0981-\u0983\u09BC\u09BE-\u09C4\u09C7\u09C8\u09CB-\u09CD\u09D7\u09E2\u09E3\u09FE\u0A01-\u0A03\u0A3C\u0A3E-\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A70\u0A71\u0A75\u0A81-\u0A83\u0ABC\u0ABE-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD\u0AE2\u0AE3\u0AFA-\u0AFF\u0B01-\u0B03\u0B3C\u0B3E-\u0B44\u0B47\u0B48\u0B4B-\u0B4D\u0B56\u0B57\u0B62\u0B63\u0B82\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD7\u0C00-\u0C04\u0C3E-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C62\u0C63\u0C81-\u0C83\u0CBC\u0CBE-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5\u0CD6\u0CE2\u0CE3\u0D00-\u0D03\u0D3B\u0D3C\u0D3E-\u0D44\u0D46-\u0D48\u0D4A-\u0D4D\u0D57\u0D62\u0D63\u0D82\u0D83\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DF2\u0DF3\u0E31\u0E34-\u0E3A\u0E47-\u0E4E\u0EB1\u0EB4-\u0EB9\u0EBB\u0EBC\u0EC8-\u0ECD\u0F18\u0F19\u0F35\u0F37\u0F39\u0F3E\u0F3F\u0F71-\u0F84\u0F86\u0F87\u0F8D-\u0F97\u0F99-\u0FBC\u0FC6\u102B-\u103E\u1056-\u1059\u105E-\u1060\u1062-\u1064\u1067-\u106D\u1071-\u1074\u1082-\u108D\u108F\u109A-\u109D\u135D-\u135F\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17B4-\u17D3\u17DD\u180B-\u180D\u1885\u1886\u18A9\u1920-\u192B\u1930-\u193B\u1A17-\u1A1B\u1A55-\u1A5E\u1A60-\u1A7C\u1A7F\u1AB0-\u1ABE\u1B00-\u1B04\u1B34-\u1B44\u1B6B-\u1B73\u1B80-\u1B82\u1BA1-\u1BAD\u1BE6-\u1BF3\u1C24-\u1C37\u1CD0-\u1CD2\u1CD4-\u1CE8\u1CED\u1CF2-\u1CF4\u1CF7-\u1CF9\u1DC0-\u1DF9\u1DFB-\u1DFF\u20D0-\u20F0\u2CEF-\u2CF1\u2D7F\u2DE0-\u2DFF\u302A-\u302F\u3099\u309A\uA66F-\uA672\uA674-\uA67D\uA69E\uA69F\uA6F0\uA6F1\uA802\uA806\uA80B\uA823-\uA827\uA880\uA881\uA8B4-\uA8C5\uA8E0-\uA8F1\uA8FF\uA926-\uA92D\uA947-\uA953\uA980-\uA983\uA9B3-\uA9C0\uA9E5\uAA29-\uAA36\uAA43\uAA4C\uAA4D\uAA7B-\uAA7D\uAAB0\uAAB2-\uAAB4\uAAB7\uAAB8\uAABE\uAABF\uAAC1\uAAEB-\uAAEF\uAAF5\uAAF6\uABE3-\uABEA\uABEC\uABED\uFB1E\uFE00-\uFE0F\uFE20-\uFE2F]/g,"")):(t=>t);class wue{constructor(A,{location:e=Zo.location,threshold:i=Zo.threshold,distance:n=Zo.distance,includeMatches:o=Zo.includeMatches,findAllMatches:s=Zo.findAllMatches,minMatchCharLength:r=Zo.minMatchCharLength,isCaseSensitive:a=Zo.isCaseSensitive,ignoreDiacritics:g=Zo.ignoreDiacritics,ignoreLocation:c=Zo.ignoreLocation}={}){if(this.options={location:e,threshold:i,distance:n,includeMatches:o,findAllMatches:s,minMatchCharLength:r,isCaseSensitive:a,ignoreDiacritics:g,ignoreLocation:c},A=a?A:A.toLowerCase(),A=g?Vz(A):A,this.pattern=A,this.chunks=[],!this.pattern.length)return;const I=(B,C)=>{this.chunks.push({pattern:B,alphabet:osi(B),startIndex:C})},l=this.pattern.length;if(l>WM){let B=0;const C=l%WM,Q=l-C;for(;B<Q;)I(this.pattern.substr(B,WM),B),B+=WM;if(C){const h=l-WM;I(this.pattern.substr(h),h)}}else I(this.pattern,0)}searchIn(A){const{isCaseSensitive:e,ignoreDiacritics:i,includeMatches:n}=this.options;if(A=e?A:A.toLowerCase(),A=i?Vz(A):A,this.pattern===A){let Q={isMatch:!0,score:0};return n&&(Q.indices=[[0,A.length-1]]),Q}const{location:o,distance:s,threshold:r,findAllMatches:a,minMatchCharLength:g,ignoreLocation:c}=this.options;let I=[],l=0,B=!1;this.chunks.forEach(({pattern:Q,alphabet:h,startIndex:E})=>{const{isMatch:u,score:d,indices:f}=nsi(A,Q,h,{location:o+E,distance:s,threshold:r,findAllMatches:a,minMatchCharLength:g,includeMatches:n,ignoreLocation:c});u&&(B=!0),l+=d,u&&f&&(I=[...I,...f])});let C={isMatch:B,score:B?l/this.chunks.length:1};return B&&n&&(C.indices=I),C}}class Wk{constructor(A){this.pattern=A}static isMultiMatch(A){return Due(A,this.multiRegex)}static isSingleMatch(A){return Due(A,this.singleRegex)}search(){}}function Due(t,A){const e=t.match(A);return e?e[1]:null}class ssi extends Wk{constructor(A){super(A)}static get type(){return"exact"}static get multiRegex(){return/^="(.*)"$/}static get singleRegex(){return/^=(.*)$/}search(A){const e=A===this.pattern;return{isMatch:e,score:e?0:1,indices:[0,this.pattern.length-1]}}}class rsi extends Wk{constructor(A){super(A)}static get type(){return"inverse-exact"}static get multiRegex(){return/^!"(.*)"$/}static get singleRegex(){return/^!(.*)$/}search(A){const i=A.indexOf(this.pattern)===-1;return{isMatch:i,score:i?0:1,indices:[0,A.length-1]}}}class asi extends Wk{constructor(A){super(A)}static get type(){return"prefix-exact"}static get multiRegex(){return/^\^"(.*)"$/}static get singleRegex(){return/^\^(.*)$/}search(A){const e=A.startsWith(this.pattern);return{isMatch:e,score:e?0:1,indices:[0,this.pattern.length-1]}}}class gsi extends Wk{constructor(A){super(A)}static get type(){return"inverse-prefix-exact"}static get multiRegex(){return/^!\^"(.*)"$/}static get singleRegex(){return/^!\^(.*)$/}search(A){const e=!A.startsWith(this.pattern);return{isMatch:e,score:e?0:1,indices:[0,A.length-1]}}}class csi extends Wk{constructor(A){super(A)}static get type(){return"suffix-exact"}static get multiRegex(){return/^"(.*)"\$$/}static get singleRegex(){return/^(.*)\$$/}search(A){const e=A.endsWith(this.pattern);return{isMatch:e,score:e?0:1,indices:[A.length-this.pattern.length,A.length-1]}}}class Isi extends Wk{constructor(A){super(A)}static get type(){return"inverse-suffix-exact"}static get multiRegex(){return/^!"(.*)"\$$/}static get singleRegex(){return/^!(.*)\$$/}search(A){const e=!A.endsWith(this.pattern);return{isMatch:e,score:e?0:1,indices:[0,A.length-1]}}}class Sue extends Wk{constructor(A,{location:e=Zo.location,threshold:i=Zo.threshold,distance:n=Zo.distance,includeMatches:o=Zo.includeMatches,findAllMatches:s=Zo.findAllMatches,minMatchCharLength:r=Zo.minMatchCharLength,isCaseSensitive:a=Zo.isCaseSensitive,ignoreDiacritics:g=Zo.ignoreDiacritics,ignoreLocation:c=Zo.ignoreLocation}={}){super(A),this._bitapSearch=new wue(A,{location:e,threshold:i,distance:n,includeMatches:o,findAllMatches:s,minMatchCharLength:r,isCaseSensitive:a,ignoreDiacritics:g,ignoreLocation:c})}static get type(){return"fuzzy"}static get multiRegex(){return/^"(.*)"$/}static get singleRegex(){return/^(.*)$/}search(A){return this._bitapSearch.searchIn(A)}}class bue extends Wk{constructor(A){super(A)}static get type(){return"include"}static get multiRegex(){return/^'"(.*)"$/}static get singleRegex(){return/^'(.*)$/}search(A){let e=0,i;const n=[],o=this.pattern.length;for(;(i=A.indexOf(this.pattern,e))>-1;)e=i+o,n.push([i,e-1]);const s=!!n.length;return{isMatch:s,score:s?0:1,indices:n}}}const $mA=[ssi,bue,asi,gsi,Isi,csi,rsi,Sue],xue=$mA.length,lsi=/ +(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/,Bsi="|";function Csi(t,A={}){return t.split(Bsi).map(e=>{let i=e.trim().split(lsi).filter(o=>o&&!!o.trim()),n=[];for(let o=0,s=i.length;o<s;o+=1){const r=i[o];let a=!1,g=-1;for(;!a&&++g<xue;){const c=$mA[g];let I=c.isMultiMatch(r);I&&(n.push(new c(I,A)),a=!0)}if(!a)for(g=-1;++g<xue;){const c=$mA[g];let I=c.isSingleMatch(r);if(I){n.push(new c(I,A));break}}}return n})}const Qsi=new Set([Sue.type,bue.type]);class hsi{constructor(A,{isCaseSensitive:e=Zo.isCaseSensitive,ignoreDiacritics:i=Zo.ignoreDiacritics,includeMatches:n=Zo.includeMatches,minMatchCharLength:o=Zo.minMatchCharLength,ignoreLocation:s=Zo.ignoreLocation,findAllMatches:r=Zo.findAllMatches,location:a=Zo.location,threshold:g=Zo.threshold,distance:c=Zo.distance}={}){this.query=null,this.options={isCaseSensitive:e,ignoreDiacritics:i,includeMatches:n,minMatchCharLength:o,findAllMatches:r,ignoreLocation:s,location:a,threshold:g,distance:c},A=e?A:A.toLowerCase(),A=i?Vz(A):A,this.pattern=A,this.query=Csi(this.pattern,this.options)}static condition(A,e){return e.useExtendedSearch}searchIn(A){const e=this.query;if(!e)return{isMatch:!1,score:1};const{includeMatches:i,isCaseSensitive:n,ignoreDiacritics:o}=this.options;A=n?A:A.toLowerCase(),A=o?Vz(A):A;let s=0,r=[],a=0;for(let g=0,c=e.length;g<c;g+=1){const I=e[g];r.length=0,s=0;for(let l=0,B=I.length;l<B;l+=1){const C=I[l],{isMatch:Q,indices:h,score:E}=C.search(A);if(Q){if(s+=1,a+=E,i){const u=C.constructor.type;Qsi.has(u)?r=[...r,...h]:r.push(h)}}else{a=0,s=0,r.length=0;break}}if(s){let l={isMatch:!0,score:a/s};return i&&(l.indices=r),l}}return{isMatch:!1,score:1}}}const AwA=[];function Esi(...t){AwA.push(...t)}function ewA(t,A){for(let e=0,i=AwA.length;e<i;e+=1){let n=AwA[e];if(n.condition(t,A))return new n(t,A)}return new wue(t,A)}const jz={AND:"$and",OR:"$or"},twA={PATH:"$path",PATTERN:"$val"},iwA=t=>!!(t[jz.AND]||t[jz.OR]),usi=t=>!!t[twA.PATH],dsi=t=>!gx(t)&&uue(t)&&!iwA(t),_ue=t=>({[jz.AND]:Object.keys(t).map(A=>({[A]:t[A]}))});function kue(t,A,{auto:e=!0}={}){const i=n=>{let o=Object.keys(n);const s=usi(n);if(!s&&o.length>1&&!iwA(n))return i(_ue(n));if(dsi(n)){const a=s?n[twA.PATH]:o[0],g=s?n[twA.PATTERN]:n[a];if(!DS(g))throw new Error(Zoi(a));const c={keyId:zmA(a),pattern:g};return e&&(c.searcher=ewA(g,A)),c}let r={children:[],operator:o[0]};return o.forEach(a=>{const g=n[a];gx(g)&&g.forEach(c=>{r.children.push(i(c))})}),r};return iwA(t)||(t=_ue(t)),i(t)}function psi(t,{ignoreFieldNorm:A=Zo.ignoreFieldNorm}){t.forEach(e=>{let i=1;e.matches.forEach(({key:n,norm:o,score:s})=>{const r=n?n.weight:null;i*=Math.pow(s===0&&r?Number.EPSILON:s,(r||1)*(A?1:o))}),e.score=i})}function fsi(t,A){const e=t.matches;A.matches=[],Cy(e)&&e.forEach(i=>{if(!Cy(i.indices)||!i.indices.length)return;const{indices:n,value:o}=i;let s={indices:n,value:o};i.key&&(s.key=i.key.src),i.idx>-1&&(s.refIndex=i.idx),A.matches.push(s)})}function ysi(t,A){A.score=t.score}function msi(t,A,{includeMatches:e=Zo.includeMatches,includeScore:i=Zo.includeScore}={}){const n=[];return e&&n.push(fsi),i&&n.push(ysi),t.map(o=>{const{idx:s}=o,r={item:A[s],refIndex:s};return n.length&&n.forEach(a=>{a(o,r)}),r})}class k2{constructor(A,e={},i){this.options={...Zo,...e},this.options.useExtendedSearch,this._keyStore=new Xoi(this.options.keys),this.setCollection(A,i)}setCollection(A,e){if(this._docs=A,e&&!(e instanceof XmA))throw new Error(Woi);this._myIndex=e||mue(this.options.keys,this._docs,{getFn:this.options.getFn,fieldNormWeight:this.options.fieldNormWeight})}add(A){Cy(A)&&(this._docs.push(A),this._myIndex.add(A))}remove(A=()=>!1){const e=[];for(let i=0,n=this._docs.length;i<n;i+=1){const o=this._docs[i];A(o,i)&&(this.removeAt(i),i-=1,n-=1,e.push(o))}return e}removeAt(A){this._docs.splice(A,1),this._myIndex.removeAt(A)}getIndex(){return this._myIndex}search(A,{limit:e=-1}={}){const{includeMatches:i,includeScore:n,shouldSort:o,sortFn:s,ignoreFieldNorm:r}=this.options;let a=DS(A)?DS(this._docs[0])?this._searchStringList(A):this._searchObjectList(A):this._searchLogical(A);return psi(a,{ignoreFieldNorm:r}),o&&a.sort(s),Eue(e)&&e>-1&&(a=a.slice(0,e)),msi(a,this._docs,{includeMatches:i,includeScore:n})}_searchStringList(A){const e=ewA(A,this.options),{records:i}=this._myIndex,n=[];return i.forEach(({v:o,i:s,n:r})=>{if(!Cy(o))return;const{isMatch:a,score:g,indices:c}=e.searchIn(o);a&&n.push({item:o,idx:s,matches:[{score:g,value:o,norm:r,indices:c}]})}),n}_searchLogical(A){const e=kue(A,this.options),i=(r,a,g)=>{if(!r.children){const{keyId:I,searcher:l}=r,B=this._findMatches({key:this._keyStore.get(I),value:this._myIndex.getValueForItemAtKeyId(a,I),searcher:l});return B&&B.length?[{idx:g,item:a,matches:B}]:[]}const c=[];for(let I=0,l=r.children.length;I<l;I+=1){const B=r.children[I],C=i(B,a,g);if(C.length)c.push(...C);else if(r.operator===jz.AND)return[]}return c},n=this._myIndex.records,o={},s=[];return n.forEach(({$:r,i:a})=>{if(Cy(r)){let g=i(e,r,a);g.length&&(o[a]||(o[a]={idx:a,item:r,matches:[]},s.push(o[a])),g.forEach(({matches:c})=>{o[a].matches.push(...c)}))}}),s}_searchObjectList(A){const e=ewA(A,this.options),{keys:i,records:n}=this._myIndex,o=[];return n.forEach(({$:s,i:r})=>{if(!Cy(s))return;let a=[];i.forEach((g,c)=>{a.push(...this._findMatches({key:g,value:s[c],searcher:e}))}),a.length&&o.push({idx:r,item:s,matches:a})}),o}_findMatches({key:A,value:e,searcher:i}){if(!Cy(e))return[];let n=[];if(gx(e))e.forEach(({v:o,i:s,n:r})=>{if(!Cy(o))return;const{isMatch:a,score:g,indices:c}=i.searchIn(o);a&&n.push({score:g,key:A,value:o,idx:s,norm:r,indices:c})});else{const{v:o,n:s}=e,{isMatch:r,score:a,indices:g}=i.searchIn(o);r&&n.push({score:a,key:A,value:o,norm:s,indices:g})}return n}}k2.version="7.1.0",k2.createIndex=mue,k2.parseIndex=tsi,k2.config=Zo,k2.parseQuery=kue,Esi(hsi);let nwA=null,$T=null,owA=null;const wsi=async()=>nwA||$T||($T=fetch("https://kicad-mod-cache.tscircuit.com/kicad_files.json").then(t=>t.json()).then(t=>(nwA=t,$T=null,t)),$T),Dsi=async(t,A=20)=>{const e=await wsi();return owA||(owA=new k2(e)),owA.search(t).slice(0,A).map(i=>i.item)},Ssi=t=>{const A=t.replace(".pretty/",":").replace(".kicad_mod",""),e=`kicad:${A}`;return{path:t,qualifiedName:e,description:A}},bsi=()=>{const[t,A]=V.useState([]),[e,i]=V.useState(!1),[n,o]=V.useState(null),[s,r]=V.useState(!1),a=V.useCallback(async c=>{const I=c.trim();if(!I)return[];i(!0),o(null);try{const B=(await Dsi(I,20)).map(C=>({source:"kicad",footprint:Ssi(C)}));return A(B),B}catch(l){return console.error("Error searching KiCad footprints",l),A([]),o(l instanceof Error?l.message:"Failed to search KiCad footprints"),[]}finally{i(!1),r(!0)}},[]),g=V.useCallback(()=>{A([]),i(!1),o(null),r(!1)},[]);return{results:t,isSearching:e,error:n,hasSearched:s,search:a,reset:g}},xsi={dialog:101},_si=({onTscircuitPackageSelected:t,onJlcpcbComponentTsxLoaded:A,onKicadStringSelected:e})=>{const i=[];return t&&i.push("tscircuit.com"),A&&i.push("jlcpcb"),e&&i.push("kicad"),i},ksi=({isOpen:t,onClose:A,jlcpcbProxyRequestHeaders:e,onKicadStringSelected:i,onTscircuitPackageSelected:n,onJlcpcbComponentTsxLoaded:o,jlcpcbProxyApiBase:s,tscircuitSessionToken:r})=>{Lz();const a=V.useMemo(()=>_si({onKicadStringSelected:i,onTscircuitPackageSelected:n,onJlcpcbComponentTsxLoaded:o}),[i,n,o]),g=a.length>0,c=a.length===1,[I,l]=V.useState(a[0]??"tscircuit.com"),[B,C]=V.useState(""),[Q,h]=V.useState(null),{results:E,isSearching:u,error:d,hasSearched:f,search:y,reset:w}=Yoi({sessionToken:r}),{results:D,isSearching:S,error:_,hasSearched:b,search:N,reset:F}=Toi(),{results:L,isSearching:Y,error:J,hasSearched:O,search:Z,reset:X}=bsi(),{details:eA,isLoading:gA,fetchDetails:tA,reset:iA}=Uoi(),[sA,aA]=V.useState(null),[EA,bA]=V.useState(!1),[_A,LA]=V.useState("pcb"),[QA,kA]=V.useState(null),[dA,qA]=V.useState(!1);V.useEffect(()=>{kA(null)},[Q]);const VA=V.useCallback(()=>{w(),F(),X(),h(null)},[F,X,w]);V.useEffect(()=>{t||(VA(),C(""),bA(!1),aA(null),kA(null))},[t,VA]),V.useEffect(()=>{C(""),h(null),I==="tscircuit.com"?w():I==="jlcpcb"?F():I==="kicad"&&X()},[I,F,X,w]);const ce=KA=>{h(KA),aA(KA),LA("pcb"),bA(!0),iA();const ZA=KA.package.org_owner_tscircuit_handle,ne=KA.package.unscoped_name;if(ZA&&ne){const SA=ne.split("/").pop()??ne;tA(ZA,SA)}},fA=async()=>{B.trim()&&(h(null),I==="tscircuit.com"?await y(B):I==="jlcpcb"?await N(B):I==="kicad"&&await Z(B))},ge=async KA=>{try{if(kA(null),qA(!0),KA.source==="kicad"){if(!i)throw new Error("KiCad handler not provided");await i({result:KA,footprint:KA.footprint.qualifiedName})}else if(KA.source==="jlcpcb"){if(!o)throw new Error("JLCPCB handler not provided");const ZA=await _oi(KA.component.partNumber,{headers:e,apiBase:s});await o({result:KA,tsx:ZA})}else if(KA.source==="tscircuit.com"){if(!n)throw new Error("tscircuit package handler not provided");const ZA=KA.package.org_owner_tscircuit_handle,ne=KA.package.unscoped_name;if(!ZA||!ne)throw new Error("Missing package metadata");const SA=ne.split("/").pop()??ne,CA=`@tsci/${ZA}.${SA}`;await n({result:KA,fullPackageName:CA})}return!0}catch(ZA){return console.error("Failed to import component",ZA),kA(ZA instanceof Error?ZA.message:"Failed to import component"),!1}finally{qA(!1)}};let jA=[],JA=!1,WA=null,vA=!1;I==="tscircuit.com"?(jA=E,JA=u,WA=d,vA=f):I==="jlcpcb"?(jA=D,JA=S,WA=_,vA=b):I==="kicad"&&(jA=L,JA=Y,WA=J,vA=O);const wA=async()=>{if(!Q)return;await ge(Q)&&(A(),VA(),C(""))},RA=KA=>{KA||A()},MA=KA=>{bA(KA),KA||aA(null)};return W.jsxs(x2,{open:t,onOpenChange:RA,children:[W.jsxs(KM,{style:{width:"calc(100vw - 2rem)",zIndex:xsi.dialog},className:"rf-rounded-sm rf-max-h-[90vh] rf-overflow-y-auto rf-overflow-x-hidden rf-flex rf-flex-col",children:[W.jsxs(qM,{children:[W.jsxs(OM,{className:"rf-text-lg sm:rf-text-xl",children:["Import ",c?Wz[I].label:""," ","Component"]}),W.jsx(_2,{className:"rf-text-sm",children:g?"Search for components from available sources.":"Import options are disabled because no handlers were provided."})]}),g?W.jsxs(DgA,{value:I,onValueChange:KA=>l(KA),className:"rf-min-w-0 rf-w-full",children:[!c&&W.jsx(WW,{className:"rf-flex rf-w-full rf-gap-2",children:a.map(KA=>W.jsx(JD,{value:KA,className:"rf-flex-1 rf-text-xs sm:rf-text-sm",children:Wz[KA].label},KA))}),W.jsx(koi,{query:B,placeholder:Wz[I].placeholder,isSearching:JA,onQueryChange:C,onSubmit:fA}),W.jsx("div",{className:"no-scrollbar rf-mt-4 rf-flex-1 rf-min-h-[200px] !rf-max-h-[40vh] !rf-overflow-y-auto rf-overflow-x-hidden rf-border rf-rounded-md rf-min-w-0",children:JA?W.jsxs("div",{className:"rf-p-8 rf-text-center rf-text-zinc-500",children:[W.jsx(Zb,{className:"rf-h-8 rf-w-8 rf-animate-spin rf-mx-auto rf-mb-2"}),W.jsx("p",{children:"Searching..."})]}):jA.length>0?W.jsx(Goi,{results:jA,selected:Q,onSelect:h,onShowDetails:I==="tscircuit.com"?ce:void 0}):W.jsx("div",{className:"rf-p-8 rf-text-center rf-text-zinc-500",children:WA?`Error: ${WA}`:vA?Wz[I].emptyMessage:"Enter a search term to find components"})})]}):null,QA?W.jsx("div",{className:"rf-text-sm rf-text-red-600 rf-mt-2",children:QA}):null,W.jsxs(XT,{className:"rf-flex rf-flex-col sm:rf-flex-row rf-gap-2",children:[W.jsx(Ja,{variant:"outline",onClick:A,className:"rf-order-2 sm:rf-order-1",children:"Cancel"}),W.jsx(Ja,{onClick:wA,disabled:!Q||dA,className:"rf-order-1 sm:rf-order-2",children:dA?W.jsx(Zb,{className:"rf-h-4 rf-w-4 rf-animate-spin"}):"Import"})]})]}),W.jsx(Loi,{packageResult:sA,isOpen:EA,onOpenChange:MA,isLoading:gA,details:eA,previewTab:_A,onPreviewTabChange:KA=>LA(KA),isSubmitting:dA,onImport:()=>{sA&&ge(sA).then(KA=>{KA&&(bA(!1),A(),VA(),C(""))})}})]})},vsi=t=>{const A=t.match(/export const (\w+) =/);if(!A)throw new Error("Could not determine component name from TSX contents");return A[1]},vue=t=>{const A=MI(s=>s.pushEvent),e=MI(s=>s.upsertFile),i=async({result:s,fullPackageName:r})=>{const g=s.package.unscoped_name??s.package.name;await _s.promise(A({event_type:"INSTALL_PACKAGE",full_package_name:r}),{loading:`Requesting install for "${g}"`,success:`Install requested for "${g}"`,error:c=>`Failed to request install: ${c instanceof Error?c.message:String(c)}`})},n=async({footprint:s})=>{await _s.promise(navigator.clipboard.writeText(s),{loading:`Copying "${s}"`,success:`Copied "${s}" to clipboard`,error:r=>`Failed to copy footprint: ${r instanceof Error?r.message:String(r)}`})},o=async({result:s,tsx:r})=>{const g=`imports/${vsi(r)}.tsx`;await _s.promise(e(g,r),{loading:`Importing ${s.component.partNumber}`,success:`Imported to "${g}"`,error:c=>`Failed to import component: ${c instanceof Error?c.message:String(c)}`})};return W.jsx(ksi,{...t,onTscircuitPackageSelected:i,onKicadStringSelected:n,onJlcpcbComponentTsxLoaded:o})};vue.displayName="ImportComponentDialogForCli";var swA={exports:{}},Fue;function Fsi(){return Fue||(Fue=1,(function(t,A){var e={env:{},version:""};(function(i){t.exports=i()})(function(){return(function i(n,o,s){function r(c,I){if(!o[c]){if(!n[c]){var l=typeof o_=="function"&&o_;if(!I&&l)return l(c,!0);if(a)return a(c,!0);var B=new Error("Cannot find module '"+c+"'");throw B.code="MODULE_NOT_FOUND",B}var C=o[c]={exports:{}};n[c][0].call(C.exports,function(Q){var h=n[c][1][Q];return r(h||Q)},C,C.exports,i,n,o,s)}return o[c].exports}for(var a=typeof o_=="function"&&o_,g=0;g<s.length;g++)r(s[g]);return r})({1:[function(i,n,o){var s=i("./utils"),r=i("./support"),a="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";o.encode=function(g){for(var c,I,l,B,C,Q,h,E=[],u=0,d=g.length,f=d,y=s.getTypeOf(g)!=="string";u<g.length;)f=d-u,l=y?(c=g[u++],I=u<d?g[u++]:0,u<d?g[u++]:0):(c=g.charCodeAt(u++),I=u<d?g.charCodeAt(u++):0,u<d?g.charCodeAt(u++):0),B=c>>2,C=(3&c)<<4|I>>4,Q=1<f?(15&I)<<2|l>>6:64,h=2<f?63&l:64,E.push(a.charAt(B)+a.charAt(C)+a.charAt(Q)+a.charAt(h));return E.join("")},o.decode=function(g){var c,I,l,B,C,Q,h=0,E=0,u="data:";if(g.substr(0,u.length)===u)throw new Error("Invalid base64 input, it looks like a data url.");var d,f=3*(g=g.replace(/[^A-Za-z0-9+/=]/g,"")).length/4;if(g.charAt(g.length-1)===a.charAt(64)&&f--,g.charAt(g.length-2)===a.charAt(64)&&f--,f%1!=0)throw new Error("Invalid base64 input, bad content length.");for(d=r.uint8array?new Uint8Array(0|f):new Array(0|f);h<g.length;)c=a.indexOf(g.charAt(h++))<<2|(B=a.indexOf(g.charAt(h++)))>>4,I=(15&B)<<4|(C=a.indexOf(g.charAt(h++)))>>2,l=(3&C)<<6|(Q=a.indexOf(g.charAt(h++))),d[E++]=c,C!==64&&(d[E++]=I),Q!==64&&(d[E++]=l);return d}},{"./support":30,"./utils":32}],2:[function(i,n,o){var s=i("./external"),r=i("./stream/DataWorker"),a=i("./stream/Crc32Probe"),g=i("./stream/DataLengthProbe");function c(I,l,B,C,Q){this.compressedSize=I,this.uncompressedSize=l,this.crc32=B,this.compression=C,this.compressedContent=Q}c.prototype={getContentWorker:function(){var I=new r(s.Promise.resolve(this.compressedContent)).pipe(this.compression.uncompressWorker()).pipe(new g("data_length")),l=this;return I.on("end",function(){if(this.streamInfo.data_length!==l.uncompressedSize)throw new Error("Bug : uncompressed data size mismatch")}),I},getCompressedWorker:function(){return new r(s.Promise.resolve(this.compressedContent)).withStreamInfo("compressedSize",this.compressedSize).withStreamInfo("uncompressedSize",this.uncompressedSize).withStreamInfo("crc32",this.crc32).withStreamInfo("compression",this.compression)}},c.createWorkerFrom=function(I,l,B){return I.pipe(new a).pipe(new g("uncompressedSize")).pipe(l.compressWorker(B)).pipe(new g("compressedSize")).withStreamInfo("compression",l)},n.exports=c},{"./external":6,"./stream/Crc32Probe":25,"./stream/DataLengthProbe":26,"./stream/DataWorker":27}],3:[function(i,n,o){var s=i("./stream/GenericWorker");o.STORE={magic:"\0\0",compressWorker:function(){return new s("STORE compression")},uncompressWorker:function(){return new s("STORE decompression")}},o.DEFLATE=i("./flate")},{"./flate":7,"./stream/GenericWorker":28}],4:[function(i,n,o){var s=i("./utils"),r=(function(){for(var a,g=[],c=0;c<256;c++){a=c;for(var I=0;I<8;I++)a=1&a?3988292384^a>>>1:a>>>1;g[c]=a}return g})();n.exports=function(a,g){return a!==void 0&&a.length?s.getTypeOf(a)!=="string"?(function(c,I,l,B){var C=r,Q=B+l;c^=-1;for(var h=B;h<Q;h++)c=c>>>8^C[255&(c^I[h])];return-1^c})(0|g,a,a.length,0):(function(c,I,l,B){var C=r,Q=B+l;c^=-1;for(var h=B;h<Q;h++)c=c>>>8^C[255&(c^I.charCodeAt(h))];return-1^c})(0|g,a,a.length,0):0}},{"./utils":32}],5:[function(i,n,o){o.base64=!1,o.binary=!1,o.dir=!1,o.createFolders=!0,o.date=null,o.compression=null,o.compressionOptions=null,o.comment=null,o.unixPermissions=null,o.dosPermissions=null},{}],6:[function(i,n,o){var s=null;s=typeof Promise<"u"?Promise:i("lie"),n.exports={Promise:s}},{lie:37}],7:[function(i,n,o){var s=typeof Uint8Array<"u"&&typeof Uint16Array<"u"&&typeof Uint32Array<"u",r=i("pako"),a=i("./utils"),g=i("./stream/GenericWorker"),c=s?"uint8array":"array";function I(l,B){g.call(this,"FlateWorker/"+l),this._pako=null,this._pakoAction=l,this._pakoOptions=B,this.meta={}}o.magic="\b\0",a.inherits(I,g),I.prototype.processChunk=function(l){this.meta=l.meta,this._pako===null&&this._createPako(),this._pako.push(a.transformTo(c,l.data),!1)},I.prototype.flush=function(){g.prototype.flush.call(this),this._pako===null&&this._createPako(),this._pako.push([],!0)},I.prototype.cleanUp=function(){g.prototype.cleanUp.call(this),this._pako=null},I.prototype._createPako=function(){this._pako=new r[this._pakoAction]({raw:!0,level:this._pakoOptions.level||-1});var l=this;this._pako.onData=function(B){l.push({data:B,meta:l.meta})}},o.compressWorker=function(l){return new I("Deflate",l)},o.uncompressWorker=function(){return new I("Inflate",{})}},{"./stream/GenericWorker":28,"./utils":32,pako:38}],8:[function(i,n,o){function s(C,Q){var h,E="";for(h=0;h<Q;h++)E+=String.fromCharCode(255&C),C>>>=8;return E}function r(C,Q,h,E,u,d){var f,y,w=C.file,D=C.compression,S=d!==c.utf8encode,_=a.transformTo("string",d(w.name)),b=a.transformTo("string",c.utf8encode(w.name)),N=w.comment,F=a.transformTo("string",d(N)),L=a.transformTo("string",c.utf8encode(N)),Y=b.length!==w.name.length,J=L.length!==N.length,O="",Z="",X="",eA=w.dir,gA=w.date,tA={crc32:0,compressedSize:0,uncompressedSize:0};Q&&!h||(tA.crc32=C.crc32,tA.compressedSize=C.compressedSize,tA.uncompressedSize=C.uncompressedSize);var iA=0;Q&&(iA|=8),S||!Y&&!J||(iA|=2048);var sA=0,aA=0;eA&&(sA|=16),u==="UNIX"?(aA=798,sA|=(function(bA,_A){var LA=bA;return bA||(LA=_A?16893:33204),(65535&LA)<<16})(w.unixPermissions,eA)):(aA=20,sA|=(function(bA){return 63&(bA||0)})(w.dosPermissions)),f=gA.getUTCHours(),f<<=6,f|=gA.getUTCMinutes(),f<<=5,f|=gA.getUTCSeconds()/2,y=gA.getUTCFullYear()-1980,y<<=4,y|=gA.getUTCMonth()+1,y<<=5,y|=gA.getUTCDate(),Y&&(Z=s(1,1)+s(I(_),4)+b,O+="up"+s(Z.length,2)+Z),J&&(X=s(1,1)+s(I(F),4)+L,O+="uc"+s(X.length,2)+X);var EA="";return EA+=`
5703
5703
  \0`,EA+=s(iA,2),EA+=D.magic,EA+=s(f,2),EA+=s(y,2),EA+=s(tA.crc32,4),EA+=s(tA.compressedSize,4),EA+=s(tA.uncompressedSize,4),EA+=s(_.length,2),EA+=s(O.length,2),{fileRecord:l.LOCAL_FILE_HEADER+EA+_+O,dirRecord:l.CENTRAL_FILE_HEADER+s(aA,2)+EA+s(F.length,2)+"\0\0\0\0"+s(sA,4)+s(E,4)+_+O+F}}var a=i("../utils"),g=i("../stream/GenericWorker"),c=i("../utf8"),I=i("../crc32"),l=i("../signature");function B(C,Q,h,E){g.call(this,"ZipFileWorker"),this.bytesWritten=0,this.zipComment=Q,this.zipPlatform=h,this.encodeFileName=E,this.streamFiles=C,this.accumulate=!1,this.contentBuffer=[],this.dirRecords=[],this.currentSourceOffset=0,this.entriesCount=0,this.currentFile=null,this._sources=[]}a.inherits(B,g),B.prototype.push=function(C){var Q=C.meta.percent||0,h=this.entriesCount,E=this._sources.length;this.accumulate?this.contentBuffer.push(C):(this.bytesWritten+=C.data.length,g.prototype.push.call(this,{data:C.data,meta:{currentFile:this.currentFile,percent:h?(Q+100*(h-E-1))/h:100}}))},B.prototype.openedSource=function(C){this.currentSourceOffset=this.bytesWritten,this.currentFile=C.file.name;var Q=this.streamFiles&&!C.file.dir;if(Q){var h=r(C,Q,!1,this.currentSourceOffset,this.zipPlatform,this.encodeFileName);this.push({data:h.fileRecord,meta:{percent:0}})}else this.accumulate=!0},B.prototype.closedSource=function(C){this.accumulate=!1;var Q=this.streamFiles&&!C.file.dir,h=r(C,Q,!0,this.currentSourceOffset,this.zipPlatform,this.encodeFileName);if(this.dirRecords.push(h.dirRecord),Q)this.push({data:(function(E){return l.DATA_DESCRIPTOR+s(E.crc32,4)+s(E.compressedSize,4)+s(E.uncompressedSize,4)})(C),meta:{percent:100}});else for(this.push({data:h.fileRecord,meta:{percent:0}});this.contentBuffer.length;)this.push(this.contentBuffer.shift());this.currentFile=null},B.prototype.flush=function(){for(var C=this.bytesWritten,Q=0;Q<this.dirRecords.length;Q++)this.push({data:this.dirRecords[Q],meta:{percent:100}});var h=this.bytesWritten-C,E=(function(u,d,f,y,w){var D=a.transformTo("string",w(y));return l.CENTRAL_DIRECTORY_END+"\0\0\0\0"+s(u,2)+s(u,2)+s(d,4)+s(f,4)+s(D.length,2)+D})(this.dirRecords.length,h,C,this.zipComment,this.encodeFileName);this.push({data:E,meta:{percent:100}})},B.prototype.prepareNextSource=function(){this.previous=this._sources.shift(),this.openedSource(this.previous.streamInfo),this.isPaused?this.previous.pause():this.previous.resume()},B.prototype.registerPrevious=function(C){this._sources.push(C);var Q=this;return C.on("data",function(h){Q.processChunk(h)}),C.on("end",function(){Q.closedSource(Q.previous.streamInfo),Q._sources.length?Q.prepareNextSource():Q.end()}),C.on("error",function(h){Q.error(h)}),this},B.prototype.resume=function(){return!!g.prototype.resume.call(this)&&(!this.previous&&this._sources.length?(this.prepareNextSource(),!0):this.previous||this._sources.length||this.generatedError?void 0:(this.end(),!0))},B.prototype.error=function(C){var Q=this._sources;if(!g.prototype.error.call(this,C))return!1;for(var h=0;h<Q.length;h++)try{Q[h].error(C)}catch{}return!0},B.prototype.lock=function(){g.prototype.lock.call(this);for(var C=this._sources,Q=0;Q<C.length;Q++)C[Q].lock()},n.exports=B},{"../crc32":4,"../signature":23,"../stream/GenericWorker":28,"../utf8":31,"../utils":32}],9:[function(i,n,o){var s=i("../compressions"),r=i("./ZipFileWorker");o.generateWorker=function(a,g,c){var I=new r(g.streamFiles,c,g.platform,g.encodeFileName),l=0;try{a.forEach(function(B,C){l++;var Q=(function(d,f){var y=d||f,w=s[y];if(!w)throw new Error(y+" is not a valid compression method !");return w})(C.options.compression,g.compression),h=C.options.compressionOptions||g.compressionOptions||{},E=C.dir,u=C.date;C._compressWorker(Q,h).withStreamInfo("file",{name:B,dir:E,date:u,comment:C.comment||"",unixPermissions:C.unixPermissions,dosPermissions:C.dosPermissions}).pipe(I)}),I.entriesCount=l}catch(B){I.error(B)}return I}},{"../compressions":3,"./ZipFileWorker":8}],10:[function(i,n,o){function s(){if(!(this instanceof s))return new s;if(arguments.length)throw new Error("The constructor with parameters has been removed in JSZip 3.0, please check the upgrade guide.");this.files=Object.create(null),this.comment=null,this.root="",this.clone=function(){var r=new s;for(var a in this)typeof this[a]!="function"&&(r[a]=this[a]);return r}}(s.prototype=i("./object")).loadAsync=i("./load"),s.support=i("./support"),s.defaults=i("./defaults"),s.version="3.10.1",s.loadAsync=function(r,a){return new s().loadAsync(r,a)},s.external=i("./external"),n.exports=s},{"./defaults":5,"./external":6,"./load":11,"./object":15,"./support":30}],11:[function(i,n,o){var s=i("./utils"),r=i("./external"),a=i("./utf8"),g=i("./zipEntries"),c=i("./stream/Crc32Probe"),I=i("./nodejsUtils");function l(B){return new r.Promise(function(C,Q){var h=B.decompressed.getContentWorker().pipe(new c);h.on("error",function(E){Q(E)}).on("end",function(){h.streamInfo.crc32!==B.decompressed.crc32?Q(new Error("Corrupted zip : CRC32 mismatch")):C()}).resume()})}n.exports=function(B,C){var Q=this;return C=s.extend(C||{},{base64:!1,checkCRC32:!1,optimizedBinaryString:!1,createFolders:!1,decodeFileName:a.utf8decode}),I.isNode&&I.isStream(B)?r.Promise.reject(new Error("JSZip can't accept a stream when loading a zip file.")):s.prepareContent("the loaded zip file",B,!0,C.optimizedBinaryString,C.base64).then(function(h){var E=new g(C);return E.load(h),E}).then(function(h){var E=[r.Promise.resolve(h)],u=h.files;if(C.checkCRC32)for(var d=0;d<u.length;d++)E.push(l(u[d]));return r.Promise.all(E)}).then(function(h){for(var E=h.shift(),u=E.files,d=0;d<u.length;d++){var f=u[d],y=f.fileNameStr,w=s.resolve(f.fileNameStr);Q.file(w,f.decompressed,{binary:!0,optimizedBinaryString:!0,date:f.date,dir:f.dir,comment:f.fileCommentStr.length?f.fileCommentStr:null,unixPermissions:f.unixPermissions,dosPermissions:f.dosPermissions,createFolders:C.createFolders}),f.dir||(Q.file(w).unsafeOriginalName=y)}return E.zipComment.length&&(Q.comment=E.zipComment),Q})}},{"./external":6,"./nodejsUtils":14,"./stream/Crc32Probe":25,"./utf8":31,"./utils":32,"./zipEntries":33}],12:[function(i,n,o){var s=i("../utils"),r=i("../stream/GenericWorker");function a(g,c){r.call(this,"Nodejs stream input adapter for "+g),this._upstreamEnded=!1,this._bindStream(c)}s.inherits(a,r),a.prototype._bindStream=function(g){var c=this;(this._stream=g).pause(),g.on("data",function(I){c.push({data:I,meta:{percent:0}})}).on("error",function(I){c.isPaused?this.generatedError=I:c.error(I)}).on("end",function(){c.isPaused?c._upstreamEnded=!0:c.end()})},a.prototype.pause=function(){return!!r.prototype.pause.call(this)&&(this._stream.pause(),!0)},a.prototype.resume=function(){return!!r.prototype.resume.call(this)&&(this._upstreamEnded?this.end():this._stream.resume(),!0)},n.exports=a},{"../stream/GenericWorker":28,"../utils":32}],13:[function(i,n,o){var s=i("readable-stream").Readable;function r(a,g,c){s.call(this,g),this._helper=a;var I=this;a.on("data",function(l,B){I.push(l)||I._helper.pause(),c&&c(B)}).on("error",function(l){I.emit("error",l)}).on("end",function(){I.push(null)})}i("../utils").inherits(r,s),r.prototype._read=function(){this._helper.resume()},n.exports=r},{"../utils":32,"readable-stream":16}],14:[function(i,n,o){n.exports={isNode:typeof Buffer<"u",newBufferFrom:function(s,r){if(Buffer.from&&Buffer.from!==Uint8Array.from)return Buffer.from(s,r);if(typeof s=="number")throw new Error('The "data" argument must not be a number');return new Buffer(s,r)},allocBuffer:function(s){if(Buffer.alloc)return Buffer.alloc(s);var r=new Buffer(s);return r.fill(0),r},isBuffer:function(s){return Buffer.isBuffer(s)},isStream:function(s){return s&&typeof s.on=="function"&&typeof s.pause=="function"&&typeof s.resume=="function"}}},{}],15:[function(i,n,o){function s(w,D,S){var _,b=a.getTypeOf(D),N=a.extend(S||{},I);N.date=N.date||new Date,N.compression!==null&&(N.compression=N.compression.toUpperCase()),typeof N.unixPermissions=="string"&&(N.unixPermissions=parseInt(N.unixPermissions,8)),N.unixPermissions&&16384&N.unixPermissions&&(N.dir=!0),N.dosPermissions&&16&N.dosPermissions&&(N.dir=!0),N.dir&&(w=u(w)),N.createFolders&&(_=E(w))&&d.call(this,_,!0);var F=b==="string"&&N.binary===!1&&N.base64===!1;S&&S.binary!==void 0||(N.binary=!F),(D instanceof l&&D.uncompressedSize===0||N.dir||!D||D.length===0)&&(N.base64=!1,N.binary=!0,D="",N.compression="STORE",b="string");var L=null;L=D instanceof l||D instanceof g?D:Q.isNode&&Q.isStream(D)?new h(w,D):a.prepareContent(w,D,N.binary,N.optimizedBinaryString,N.base64);var Y=new B(w,L,N);this.files[w]=Y}var r=i("./utf8"),a=i("./utils"),g=i("./stream/GenericWorker"),c=i("./stream/StreamHelper"),I=i("./defaults"),l=i("./compressedObject"),B=i("./zipObject"),C=i("./generate"),Q=i("./nodejsUtils"),h=i("./nodejs/NodejsStreamInputAdapter"),E=function(w){w.slice(-1)==="/"&&(w=w.substring(0,w.length-1));var D=w.lastIndexOf("/");return 0<D?w.substring(0,D):""},u=function(w){return w.slice(-1)!=="/"&&(w+="/"),w},d=function(w,D){return D=D!==void 0?D:I.createFolders,w=u(w),this.files[w]||s.call(this,w,null,{dir:!0,createFolders:D}),this.files[w]};function f(w){return Object.prototype.toString.call(w)==="[object RegExp]"}var y={load:function(){throw new Error("This method has been removed in JSZip 3.0, please check the upgrade guide.")},forEach:function(w){var D,S,_;for(D in this.files)_=this.files[D],(S=D.slice(this.root.length,D.length))&&D.slice(0,this.root.length)===this.root&&w(S,_)},filter:function(w){var D=[];return this.forEach(function(S,_){w(S,_)&&D.push(_)}),D},file:function(w,D,S){if(arguments.length!==1)return w=this.root+w,s.call(this,w,D,S),this;if(f(w)){var _=w;return this.filter(function(N,F){return!F.dir&&_.test(N)})}var b=this.files[this.root+w];return b&&!b.dir?b:null},folder:function(w){if(!w)return this;if(f(w))return this.filter(function(b,N){return N.dir&&w.test(b)});var D=this.root+w,S=d.call(this,D),_=this.clone();return _.root=S.name,_},remove:function(w){w=this.root+w;var D=this.files[w];if(D||(w.slice(-1)!=="/"&&(w+="/"),D=this.files[w]),D&&!D.dir)delete this.files[w];else for(var S=this.filter(function(b,N){return N.name.slice(0,w.length)===w}),_=0;_<S.length;_++)delete this.files[S[_].name];return this},generate:function(){throw new Error("This method has been removed in JSZip 3.0, please check the upgrade guide.")},generateInternalStream:function(w){var D,S={};try{if((S=a.extend(w||{},{streamFiles:!1,compression:"STORE",compressionOptions:null,type:"",platform:"DOS",comment:null,mimeType:"application/zip",encodeFileName:r.utf8encode})).type=S.type.toLowerCase(),S.compression=S.compression.toUpperCase(),S.type==="binarystring"&&(S.type="string"),!S.type)throw new Error("No output type specified.");a.checkSupport(S.type),S.platform!=="darwin"&&S.platform!=="freebsd"&&S.platform!=="linux"&&S.platform!=="sunos"||(S.platform="UNIX"),S.platform==="win32"&&(S.platform="DOS");var _=S.comment||this.comment||"";D=C.generateWorker(this,S,_)}catch(b){(D=new g("error")).error(b)}return new c(D,S.type||"string",S.mimeType)},generateAsync:function(w,D){return this.generateInternalStream(w).accumulate(D)},generateNodeStream:function(w,D){return(w=w||{}).type||(w.type="nodebuffer"),this.generateInternalStream(w).toNodejsStream(D)}};n.exports=y},{"./compressedObject":2,"./defaults":5,"./generate":9,"./nodejs/NodejsStreamInputAdapter":12,"./nodejsUtils":14,"./stream/GenericWorker":28,"./stream/StreamHelper":29,"./utf8":31,"./utils":32,"./zipObject":35}],16:[function(i,n,o){n.exports=i("stream")},{stream:void 0}],17:[function(i,n,o){var s=i("./DataReader");function r(a){s.call(this,a);for(var g=0;g<this.data.length;g++)a[g]=255&a[g]}i("../utils").inherits(r,s),r.prototype.byteAt=function(a){return this.data[this.zero+a]},r.prototype.lastIndexOfSignature=function(a){for(var g=a.charCodeAt(0),c=a.charCodeAt(1),I=a.charCodeAt(2),l=a.charCodeAt(3),B=this.length-4;0<=B;--B)if(this.data[B]===g&&this.data[B+1]===c&&this.data[B+2]===I&&this.data[B+3]===l)return B-this.zero;return-1},r.prototype.readAndCheckSignature=function(a){var g=a.charCodeAt(0),c=a.charCodeAt(1),I=a.charCodeAt(2),l=a.charCodeAt(3),B=this.readData(4);return g===B[0]&&c===B[1]&&I===B[2]&&l===B[3]},r.prototype.readData=function(a){if(this.checkOffset(a),a===0)return[];var g=this.data.slice(this.zero+this.index,this.zero+this.index+a);return this.index+=a,g},n.exports=r},{"../utils":32,"./DataReader":18}],18:[function(i,n,o){var s=i("../utils");function r(a){this.data=a,this.length=a.length,this.index=0,this.zero=0}r.prototype={checkOffset:function(a){this.checkIndex(this.index+a)},checkIndex:function(a){if(this.length<this.zero+a||a<0)throw new Error("End of data reached (data length = "+this.length+", asked index = "+a+"). Corrupted zip ?")},setIndex:function(a){this.checkIndex(a),this.index=a},skip:function(a){this.setIndex(this.index+a)},byteAt:function(){},readInt:function(a){var g,c=0;for(this.checkOffset(a),g=this.index+a-1;g>=this.index;g--)c=(c<<8)+this.byteAt(g);return this.index+=a,c},readString:function(a){return s.transformTo("string",this.readData(a))},readData:function(){},lastIndexOfSignature:function(){},readAndCheckSignature:function(){},readDate:function(){var a=this.readInt(4);return new Date(Date.UTC(1980+(a>>25&127),(a>>21&15)-1,a>>16&31,a>>11&31,a>>5&63,(31&a)<<1))}},n.exports=r},{"../utils":32}],19:[function(i,n,o){var s=i("./Uint8ArrayReader");function r(a){s.call(this,a)}i("../utils").inherits(r,s),r.prototype.readData=function(a){this.checkOffset(a);var g=this.data.slice(this.zero+this.index,this.zero+this.index+a);return this.index+=a,g},n.exports=r},{"../utils":32,"./Uint8ArrayReader":21}],20:[function(i,n,o){var s=i("./DataReader");function r(a){s.call(this,a)}i("../utils").inherits(r,s),r.prototype.byteAt=function(a){return this.data.charCodeAt(this.zero+a)},r.prototype.lastIndexOfSignature=function(a){return this.data.lastIndexOf(a)-this.zero},r.prototype.readAndCheckSignature=function(a){return a===this.readData(4)},r.prototype.readData=function(a){this.checkOffset(a);var g=this.data.slice(this.zero+this.index,this.zero+this.index+a);return this.index+=a,g},n.exports=r},{"../utils":32,"./DataReader":18}],21:[function(i,n,o){var s=i("./ArrayReader");function r(a){s.call(this,a)}i("../utils").inherits(r,s),r.prototype.readData=function(a){if(this.checkOffset(a),a===0)return new Uint8Array(0);var g=this.data.subarray(this.zero+this.index,this.zero+this.index+a);return this.index+=a,g},n.exports=r},{"../utils":32,"./ArrayReader":17}],22:[function(i,n,o){var s=i("../utils"),r=i("../support"),a=i("./ArrayReader"),g=i("./StringReader"),c=i("./NodeBufferReader"),I=i("./Uint8ArrayReader");n.exports=function(l){var B=s.getTypeOf(l);return s.checkSupport(B),B!=="string"||r.uint8array?B==="nodebuffer"?new c(l):r.uint8array?new I(s.transformTo("uint8array",l)):new a(s.transformTo("array",l)):new g(l)}},{"../support":30,"../utils":32,"./ArrayReader":17,"./NodeBufferReader":19,"./StringReader":20,"./Uint8ArrayReader":21}],23:[function(i,n,o){o.LOCAL_FILE_HEADER="PK",o.CENTRAL_FILE_HEADER="PK",o.CENTRAL_DIRECTORY_END="PK",o.ZIP64_CENTRAL_DIRECTORY_LOCATOR="PK\x07",o.ZIP64_CENTRAL_DIRECTORY_END="PK",o.DATA_DESCRIPTOR="PK\x07\b"},{}],24:[function(i,n,o){var s=i("./GenericWorker"),r=i("../utils");function a(g){s.call(this,"ConvertWorker to "+g),this.destType=g}r.inherits(a,s),a.prototype.processChunk=function(g){this.push({data:r.transformTo(this.destType,g.data),meta:g.meta})},n.exports=a},{"../utils":32,"./GenericWorker":28}],25:[function(i,n,o){var s=i("./GenericWorker"),r=i("../crc32");function a(){s.call(this,"Crc32Probe"),this.withStreamInfo("crc32",0)}i("../utils").inherits(a,s),a.prototype.processChunk=function(g){this.streamInfo.crc32=r(g.data,this.streamInfo.crc32||0),this.push(g)},n.exports=a},{"../crc32":4,"../utils":32,"./GenericWorker":28}],26:[function(i,n,o){var s=i("../utils"),r=i("./GenericWorker");function a(g){r.call(this,"DataLengthProbe for "+g),this.propName=g,this.withStreamInfo(g,0)}s.inherits(a,r),a.prototype.processChunk=function(g){if(g){var c=this.streamInfo[this.propName]||0;this.streamInfo[this.propName]=c+g.data.length}r.prototype.processChunk.call(this,g)},n.exports=a},{"../utils":32,"./GenericWorker":28}],27:[function(i,n,o){var s=i("../utils"),r=i("./GenericWorker");function a(g){r.call(this,"DataWorker");var c=this;this.dataIsReady=!1,this.index=0,this.max=0,this.data=null,this.type="",this._tickScheduled=!1,g.then(function(I){c.dataIsReady=!0,c.data=I,c.max=I&&I.length||0,c.type=s.getTypeOf(I),c.isPaused||c._tickAndRepeat()},function(I){c.error(I)})}s.inherits(a,r),a.prototype.cleanUp=function(){r.prototype.cleanUp.call(this),this.data=null},a.prototype.resume=function(){return!!r.prototype.resume.call(this)&&(!this._tickScheduled&&this.dataIsReady&&(this._tickScheduled=!0,s.delay(this._tickAndRepeat,[],this)),!0)},a.prototype._tickAndRepeat=function(){this._tickScheduled=!1,this.isPaused||this.isFinished||(this._tick(),this.isFinished||(s.delay(this._tickAndRepeat,[],this),this._tickScheduled=!0))},a.prototype._tick=function(){if(this.isPaused||this.isFinished)return!1;var g=null,c=Math.min(this.max,this.index+16384);if(this.index>=this.max)return this.end();switch(this.type){case"string":g=this.data.substring(this.index,c);break;case"uint8array":g=this.data.subarray(this.index,c);break;case"array":case"nodebuffer":g=this.data.slice(this.index,c)}return this.index=c,this.push({data:g,meta:{percent:this.max?this.index/this.max*100:0}})},n.exports=a},{"../utils":32,"./GenericWorker":28}],28:[function(i,n,o){function s(r){this.name=r||"default",this.streamInfo={},this.generatedError=null,this.extraStreamInfo={},this.isPaused=!0,this.isFinished=!1,this.isLocked=!1,this._listeners={data:[],end:[],error:[]},this.previous=null}s.prototype={push:function(r){this.emit("data",r)},end:function(){if(this.isFinished)return!1;this.flush();try{this.emit("end"),this.cleanUp(),this.isFinished=!0}catch(r){this.emit("error",r)}return!0},error:function(r){return!this.isFinished&&(this.isPaused?this.generatedError=r:(this.isFinished=!0,this.emit("error",r),this.previous&&this.previous.error(r),this.cleanUp()),!0)},on:function(r,a){return this._listeners[r].push(a),this},cleanUp:function(){this.streamInfo=this.generatedError=this.extraStreamInfo=null,this._listeners=[]},emit:function(r,a){if(this._listeners[r])for(var g=0;g<this._listeners[r].length;g++)this._listeners[r][g].call(this,a)},pipe:function(r){return r.registerPrevious(this)},registerPrevious:function(r){if(this.isLocked)throw new Error("The stream '"+this+"' has already been used.");this.streamInfo=r.streamInfo,this.mergeStreamInfo(),this.previous=r;var a=this;return r.on("data",function(g){a.processChunk(g)}),r.on("end",function(){a.end()}),r.on("error",function(g){a.error(g)}),this},pause:function(){return!this.isPaused&&!this.isFinished&&(this.isPaused=!0,this.previous&&this.previous.pause(),!0)},resume:function(){if(!this.isPaused||this.isFinished)return!1;var r=this.isPaused=!1;return this.generatedError&&(this.error(this.generatedError),r=!0),this.previous&&this.previous.resume(),!r},flush:function(){},processChunk:function(r){this.push(r)},withStreamInfo:function(r,a){return this.extraStreamInfo[r]=a,this.mergeStreamInfo(),this},mergeStreamInfo:function(){for(var r in this.extraStreamInfo)Object.prototype.hasOwnProperty.call(this.extraStreamInfo,r)&&(this.streamInfo[r]=this.extraStreamInfo[r])},lock:function(){if(this.isLocked)throw new Error("The stream '"+this+"' has already been used.");this.isLocked=!0,this.previous&&this.previous.lock()},toString:function(){var r="Worker "+this.name;return this.previous?this.previous+" -> "+r:r}},n.exports=s},{}],29:[function(i,n,o){var s=i("../utils"),r=i("./ConvertWorker"),a=i("./GenericWorker"),g=i("../base64"),c=i("../support"),I=i("../external"),l=null;if(c.nodestream)try{l=i("../nodejs/NodejsStreamOutputAdapter")}catch{}function B(Q,h){return new I.Promise(function(E,u){var d=[],f=Q._internalType,y=Q._outputType,w=Q._mimeType;Q.on("data",function(D,S){d.push(D),h&&h(S)}).on("error",function(D){d=[],u(D)}).on("end",function(){try{var D=(function(S,_,b){switch(S){case"blob":return s.newBlob(s.transformTo("arraybuffer",_),b);case"base64":return g.encode(_);default:return s.transformTo(S,_)}})(y,(function(S,_){var b,N=0,F=null,L=0;for(b=0;b<_.length;b++)L+=_[b].length;switch(S){case"string":return _.join("");case"array":return Array.prototype.concat.apply([],_);case"uint8array":for(F=new Uint8Array(L),b=0;b<_.length;b++)F.set(_[b],N),N+=_[b].length;return F;case"nodebuffer":return Buffer.concat(_);default:throw new Error("concat : unsupported type '"+S+"'")}})(f,d),w);E(D)}catch(S){u(S)}d=[]}).resume()})}function C(Q,h,E){var u=h;switch(h){case"blob":case"arraybuffer":u="uint8array";break;case"base64":u="string"}try{this._internalType=u,this._outputType=h,this._mimeType=E,s.checkSupport(u),this._worker=Q.pipe(new r(u)),Q.lock()}catch(d){this._worker=new a("error"),this._worker.error(d)}}C.prototype={accumulate:function(Q){return B(this,Q)},on:function(Q,h){var E=this;return Q==="data"?this._worker.on(Q,function(u){h.call(E,u.data,u.meta)}):this._worker.on(Q,function(){s.delay(h,arguments,E)}),this},resume:function(){return s.delay(this._worker.resume,[],this._worker),this},pause:function(){return this._worker.pause(),this},toNodejsStream:function(Q){if(s.checkSupport("nodestream"),this._outputType!=="nodebuffer")throw new Error(this._outputType+" is not supported by this method");return new l(this,{objectMode:this._outputType!=="nodebuffer"},Q)}},n.exports=C},{"../base64":1,"../external":6,"../nodejs/NodejsStreamOutputAdapter":13,"../support":30,"../utils":32,"./ConvertWorker":24,"./GenericWorker":28}],30:[function(i,n,o){if(o.base64=!0,o.array=!0,o.string=!0,o.arraybuffer=typeof ArrayBuffer<"u"&&typeof Uint8Array<"u",o.nodebuffer=typeof Buffer<"u",o.uint8array=typeof Uint8Array<"u",typeof ArrayBuffer>"u")o.blob=!1;else{var s=new ArrayBuffer(0);try{o.blob=new Blob([s],{type:"application/zip"}).size===0}catch{try{var r=new(self.BlobBuilder||self.WebKitBlobBuilder||self.MozBlobBuilder||self.MSBlobBuilder);r.append(s),o.blob=r.getBlob("application/zip").size===0}catch{o.blob=!1}}}try{o.nodestream=!!i("readable-stream").Readable}catch{o.nodestream=!1}},{"readable-stream":16}],31:[function(i,n,o){for(var s=i("./utils"),r=i("./support"),a=i("./nodejsUtils"),g=i("./stream/GenericWorker"),c=new Array(256),I=0;I<256;I++)c[I]=252<=I?6:248<=I?5:240<=I?4:224<=I?3:192<=I?2:1;c[254]=c[254]=1;function l(){g.call(this,"utf-8 decode"),this.leftOver=null}function B(){g.call(this,"utf-8 encode")}o.utf8encode=function(C){return r.nodebuffer?a.newBufferFrom(C,"utf-8"):(function(Q){var h,E,u,d,f,y=Q.length,w=0;for(d=0;d<y;d++)(64512&(E=Q.charCodeAt(d)))==55296&&d+1<y&&(64512&(u=Q.charCodeAt(d+1)))==56320&&(E=65536+(E-55296<<10)+(u-56320),d++),w+=E<128?1:E<2048?2:E<65536?3:4;for(h=r.uint8array?new Uint8Array(w):new Array(w),d=f=0;f<w;d++)(64512&(E=Q.charCodeAt(d)))==55296&&d+1<y&&(64512&(u=Q.charCodeAt(d+1)))==56320&&(E=65536+(E-55296<<10)+(u-56320),d++),E<128?h[f++]=E:(E<2048?h[f++]=192|E>>>6:(E<65536?h[f++]=224|E>>>12:(h[f++]=240|E>>>18,h[f++]=128|E>>>12&63),h[f++]=128|E>>>6&63),h[f++]=128|63&E);return h})(C)},o.utf8decode=function(C){return r.nodebuffer?s.transformTo("nodebuffer",C).toString("utf-8"):(function(Q){var h,E,u,d,f=Q.length,y=new Array(2*f);for(h=E=0;h<f;)if((u=Q[h++])<128)y[E++]=u;else if(4<(d=c[u]))y[E++]=65533,h+=d-1;else{for(u&=d===2?31:d===3?15:7;1<d&&h<f;)u=u<<6|63&Q[h++],d--;1<d?y[E++]=65533:u<65536?y[E++]=u:(u-=65536,y[E++]=55296|u>>10&1023,y[E++]=56320|1023&u)}return y.length!==E&&(y.subarray?y=y.subarray(0,E):y.length=E),s.applyFromCharCode(y)})(C=s.transformTo(r.uint8array?"uint8array":"array",C))},s.inherits(l,g),l.prototype.processChunk=function(C){var Q=s.transformTo(r.uint8array?"uint8array":"array",C.data);if(this.leftOver&&this.leftOver.length){if(r.uint8array){var h=Q;(Q=new Uint8Array(h.length+this.leftOver.length)).set(this.leftOver,0),Q.set(h,this.leftOver.length)}else Q=this.leftOver.concat(Q);this.leftOver=null}var E=(function(d,f){var y;for((f=f||d.length)>d.length&&(f=d.length),y=f-1;0<=y&&(192&d[y])==128;)y--;return y<0||y===0?f:y+c[d[y]]>f?y:f})(Q),u=Q;E!==Q.length&&(r.uint8array?(u=Q.subarray(0,E),this.leftOver=Q.subarray(E,Q.length)):(u=Q.slice(0,E),this.leftOver=Q.slice(E,Q.length))),this.push({data:o.utf8decode(u),meta:C.meta})},l.prototype.flush=function(){this.leftOver&&this.leftOver.length&&(this.push({data:o.utf8decode(this.leftOver),meta:{}}),this.leftOver=null)},o.Utf8DecodeWorker=l,s.inherits(B,g),B.prototype.processChunk=function(C){this.push({data:o.utf8encode(C.data),meta:C.meta})},o.Utf8EncodeWorker=B},{"./nodejsUtils":14,"./stream/GenericWorker":28,"./support":30,"./utils":32}],32:[function(i,n,o){var s=i("./support"),r=i("./base64"),a=i("./nodejsUtils"),g=i("./external");function c(h){return h}function I(h,E){for(var u=0;u<h.length;++u)E[u]=255&h.charCodeAt(u);return E}i("setimmediate"),o.newBlob=function(h,E){o.checkSupport("blob");try{return new Blob([h],{type:E})}catch{try{var u=new(self.BlobBuilder||self.WebKitBlobBuilder||self.MozBlobBuilder||self.MSBlobBuilder);return u.append(h),u.getBlob(E)}catch{throw new Error("Bug : can't construct the Blob.")}}};var l={stringifyByChunk:function(h,E,u){var d=[],f=0,y=h.length;if(y<=u)return String.fromCharCode.apply(null,h);for(;f<y;)E==="array"||E==="nodebuffer"?d.push(String.fromCharCode.apply(null,h.slice(f,Math.min(f+u,y)))):d.push(String.fromCharCode.apply(null,h.subarray(f,Math.min(f+u,y)))),f+=u;return d.join("")},stringifyByChar:function(h){for(var E="",u=0;u<h.length;u++)E+=String.fromCharCode(h[u]);return E},applyCanBeUsed:{uint8array:(function(){try{return s.uint8array&&String.fromCharCode.apply(null,new Uint8Array(1)).length===1}catch{return!1}})(),nodebuffer:(function(){try{return s.nodebuffer&&String.fromCharCode.apply(null,a.allocBuffer(1)).length===1}catch{return!1}})()}};function B(h){var E=65536,u=o.getTypeOf(h),d=!0;if(u==="uint8array"?d=l.applyCanBeUsed.uint8array:u==="nodebuffer"&&(d=l.applyCanBeUsed.nodebuffer),d)for(;1<E;)try{return l.stringifyByChunk(h,u,E)}catch{E=Math.floor(E/2)}return l.stringifyByChar(h)}function C(h,E){for(var u=0;u<h.length;u++)E[u]=h[u];return E}o.applyFromCharCode=B;var Q={};Q.string={string:c,array:function(h){return I(h,new Array(h.length))},arraybuffer:function(h){return Q.string.uint8array(h).buffer},uint8array:function(h){return I(h,new Uint8Array(h.length))},nodebuffer:function(h){return I(h,a.allocBuffer(h.length))}},Q.array={string:B,array:c,arraybuffer:function(h){return new Uint8Array(h).buffer},uint8array:function(h){return new Uint8Array(h)},nodebuffer:function(h){return a.newBufferFrom(h)}},Q.arraybuffer={string:function(h){return B(new Uint8Array(h))},array:function(h){return C(new Uint8Array(h),new Array(h.byteLength))},arraybuffer:c,uint8array:function(h){return new Uint8Array(h)},nodebuffer:function(h){return a.newBufferFrom(new Uint8Array(h))}},Q.uint8array={string:B,array:function(h){return C(h,new Array(h.length))},arraybuffer:function(h){return h.buffer},uint8array:c,nodebuffer:function(h){return a.newBufferFrom(h)}},Q.nodebuffer={string:B,array:function(h){return C(h,new Array(h.length))},arraybuffer:function(h){return Q.nodebuffer.uint8array(h).buffer},uint8array:function(h){return C(h,new Uint8Array(h.length))},nodebuffer:c},o.transformTo=function(h,E){if(E=E||"",!h)return E;o.checkSupport(h);var u=o.getTypeOf(E);return Q[u][h](E)},o.resolve=function(h){for(var E=h.split("/"),u=[],d=0;d<E.length;d++){var f=E[d];f==="."||f===""&&d!==0&&d!==E.length-1||(f===".."?u.pop():u.push(f))}return u.join("/")},o.getTypeOf=function(h){return typeof h=="string"?"string":Object.prototype.toString.call(h)==="[object Array]"?"array":s.nodebuffer&&a.isBuffer(h)?"nodebuffer":s.uint8array&&h instanceof Uint8Array?"uint8array":s.arraybuffer&&h instanceof ArrayBuffer?"arraybuffer":void 0},o.checkSupport=function(h){if(!s[h.toLowerCase()])throw new Error(h+" is not supported by this platform")},o.MAX_VALUE_16BITS=65535,o.MAX_VALUE_32BITS=-1,o.pretty=function(h){var E,u,d="";for(u=0;u<(h||"").length;u++)d+="\\x"+((E=h.charCodeAt(u))<16?"0":"")+E.toString(16).toUpperCase();return d},o.delay=function(h,E,u){setImmediate(function(){h.apply(u||null,E||[])})},o.inherits=function(h,E){function u(){}u.prototype=E.prototype,h.prototype=new u},o.extend=function(){var h,E,u={};for(h=0;h<arguments.length;h++)for(E in arguments[h])Object.prototype.hasOwnProperty.call(arguments[h],E)&&u[E]===void 0&&(u[E]=arguments[h][E]);return u},o.prepareContent=function(h,E,u,d,f){return g.Promise.resolve(E).then(function(y){return s.blob&&(y instanceof Blob||["[object File]","[object Blob]"].indexOf(Object.prototype.toString.call(y))!==-1)&&typeof FileReader<"u"?new g.Promise(function(w,D){var S=new FileReader;S.onload=function(_){w(_.target.result)},S.onerror=function(_){D(_.target.error)},S.readAsArrayBuffer(y)}):y}).then(function(y){var w=o.getTypeOf(y);return w?(w==="arraybuffer"?y=o.transformTo("uint8array",y):w==="string"&&(f?y=r.decode(y):u&&d!==!0&&(y=(function(D){return I(D,s.uint8array?new Uint8Array(D.length):new Array(D.length))})(y))),y):g.Promise.reject(new Error("Can't read the data of '"+h+"'. Is it in a supported JavaScript type (String, Blob, ArrayBuffer, etc) ?"))})}},{"./base64":1,"./external":6,"./nodejsUtils":14,"./support":30,setimmediate:54}],33:[function(i,n,o){var s=i("./reader/readerFor"),r=i("./utils"),a=i("./signature"),g=i("./zipEntry"),c=i("./support");function I(l){this.files=[],this.loadOptions=l}I.prototype={checkSignature:function(l){if(!this.reader.readAndCheckSignature(l)){this.reader.index-=4;var B=this.reader.readString(4);throw new Error("Corrupted zip or bug: unexpected signature ("+r.pretty(B)+", expected "+r.pretty(l)+")")}},isSignature:function(l,B){var C=this.reader.index;this.reader.setIndex(l);var Q=this.reader.readString(4)===B;return this.reader.setIndex(C),Q},readBlockEndOfCentral:function(){this.diskNumber=this.reader.readInt(2),this.diskWithCentralDirStart=this.reader.readInt(2),this.centralDirRecordsOnThisDisk=this.reader.readInt(2),this.centralDirRecords=this.reader.readInt(2),this.centralDirSize=this.reader.readInt(4),this.centralDirOffset=this.reader.readInt(4),this.zipCommentLength=this.reader.readInt(2);var l=this.reader.readData(this.zipCommentLength),B=c.uint8array?"uint8array":"array",C=r.transformTo(B,l);this.zipComment=this.loadOptions.decodeFileName(C)},readBlockZip64EndOfCentral:function(){this.zip64EndOfCentralSize=this.reader.readInt(8),this.reader.skip(4),this.diskNumber=this.reader.readInt(4),this.diskWithCentralDirStart=this.reader.readInt(4),this.centralDirRecordsOnThisDisk=this.reader.readInt(8),this.centralDirRecords=this.reader.readInt(8),this.centralDirSize=this.reader.readInt(8),this.centralDirOffset=this.reader.readInt(8),this.zip64ExtensibleData={};for(var l,B,C,Q=this.zip64EndOfCentralSize-44;0<Q;)l=this.reader.readInt(2),B=this.reader.readInt(4),C=this.reader.readData(B),this.zip64ExtensibleData[l]={id:l,length:B,value:C}},readBlockZip64EndOfCentralLocator:function(){if(this.diskWithZip64CentralDirStart=this.reader.readInt(4),this.relativeOffsetEndOfZip64CentralDir=this.reader.readInt(8),this.disksCount=this.reader.readInt(4),1<this.disksCount)throw new Error("Multi-volumes zip are not supported")},readLocalFiles:function(){var l,B;for(l=0;l<this.files.length;l++)B=this.files[l],this.reader.setIndex(B.localHeaderOffset),this.checkSignature(a.LOCAL_FILE_HEADER),B.readLocalPart(this.reader),B.handleUTF8(),B.processAttributes()},readCentralDir:function(){var l;for(this.reader.setIndex(this.centralDirOffset);this.reader.readAndCheckSignature(a.CENTRAL_FILE_HEADER);)(l=new g({zip64:this.zip64},this.loadOptions)).readCentralPart(this.reader),this.files.push(l);if(this.centralDirRecords!==this.files.length&&this.centralDirRecords!==0&&this.files.length===0)throw new Error("Corrupted zip or bug: expected "+this.centralDirRecords+" records in central dir, got "+this.files.length)},readEndOfCentral:function(){var l=this.reader.lastIndexOfSignature(a.CENTRAL_DIRECTORY_END);if(l<0)throw this.isSignature(0,a.LOCAL_FILE_HEADER)?new Error("Corrupted zip: can't find end of central directory"):new Error("Can't find end of central directory : is this a zip file ? If it is, see https://stuk.github.io/jszip/documentation/howto/read_zip.html");this.reader.setIndex(l);var B=l;if(this.checkSignature(a.CENTRAL_DIRECTORY_END),this.readBlockEndOfCentral(),this.diskNumber===r.MAX_VALUE_16BITS||this.diskWithCentralDirStart===r.MAX_VALUE_16BITS||this.centralDirRecordsOnThisDisk===r.MAX_VALUE_16BITS||this.centralDirRecords===r.MAX_VALUE_16BITS||this.centralDirSize===r.MAX_VALUE_32BITS||this.centralDirOffset===r.MAX_VALUE_32BITS){if(this.zip64=!0,(l=this.reader.lastIndexOfSignature(a.ZIP64_CENTRAL_DIRECTORY_LOCATOR))<0)throw new Error("Corrupted zip: can't find the ZIP64 end of central directory locator");if(this.reader.setIndex(l),this.checkSignature(a.ZIP64_CENTRAL_DIRECTORY_LOCATOR),this.readBlockZip64EndOfCentralLocator(),!this.isSignature(this.relativeOffsetEndOfZip64CentralDir,a.ZIP64_CENTRAL_DIRECTORY_END)&&(this.relativeOffsetEndOfZip64CentralDir=this.reader.lastIndexOfSignature(a.ZIP64_CENTRAL_DIRECTORY_END),this.relativeOffsetEndOfZip64CentralDir<0))throw new Error("Corrupted zip: can't find the ZIP64 end of central directory");this.reader.setIndex(this.relativeOffsetEndOfZip64CentralDir),this.checkSignature(a.ZIP64_CENTRAL_DIRECTORY_END),this.readBlockZip64EndOfCentral()}var C=this.centralDirOffset+this.centralDirSize;this.zip64&&(C+=20,C+=12+this.zip64EndOfCentralSize);var Q=B-C;if(0<Q)this.isSignature(B,a.CENTRAL_FILE_HEADER)||(this.reader.zero=Q);else if(Q<0)throw new Error("Corrupted zip: missing "+Math.abs(Q)+" bytes.")},prepareReader:function(l){this.reader=s(l)},load:function(l){this.prepareReader(l),this.readEndOfCentral(),this.readCentralDir(),this.readLocalFiles()}},n.exports=I},{"./reader/readerFor":22,"./signature":23,"./support":30,"./utils":32,"./zipEntry":34}],34:[function(i,n,o){var s=i("./reader/readerFor"),r=i("./utils"),a=i("./compressedObject"),g=i("./crc32"),c=i("./utf8"),I=i("./compressions"),l=i("./support");function B(C,Q){this.options=C,this.loadOptions=Q}B.prototype={isEncrypted:function(){return(1&this.bitFlag)==1},useUTF8:function(){return(2048&this.bitFlag)==2048},readLocalPart:function(C){var Q,h;if(C.skip(22),this.fileNameLength=C.readInt(2),h=C.readInt(2),this.fileName=C.readData(this.fileNameLength),C.skip(h),this.compressedSize===-1||this.uncompressedSize===-1)throw new Error("Bug or corrupted zip : didn't get enough information from the central directory (compressedSize === -1 || uncompressedSize === -1)");if((Q=(function(E){for(var u in I)if(Object.prototype.hasOwnProperty.call(I,u)&&I[u].magic===E)return I[u];return null})(this.compressionMethod))===null)throw new Error("Corrupted zip : compression "+r.pretty(this.compressionMethod)+" unknown (inner file : "+r.transformTo("string",this.fileName)+")");this.decompressed=new a(this.compressedSize,this.uncompressedSize,this.crc32,Q,C.readData(this.compressedSize))},readCentralPart:function(C){this.versionMadeBy=C.readInt(2),C.skip(2),this.bitFlag=C.readInt(2),this.compressionMethod=C.readString(2),this.date=C.readDate(),this.crc32=C.readInt(4),this.compressedSize=C.readInt(4),this.uncompressedSize=C.readInt(4);var Q=C.readInt(2);if(this.extraFieldsLength=C.readInt(2),this.fileCommentLength=C.readInt(2),this.diskNumberStart=C.readInt(2),this.internalFileAttributes=C.readInt(2),this.externalFileAttributes=C.readInt(4),this.localHeaderOffset=C.readInt(4),this.isEncrypted())throw new Error("Encrypted zip are not supported");C.skip(Q),this.readExtraFields(C),this.parseZIP64ExtraField(C),this.fileComment=C.readData(this.fileCommentLength)},processAttributes:function(){this.unixPermissions=null,this.dosPermissions=null;var C=this.versionMadeBy>>8;this.dir=!!(16&this.externalFileAttributes),C==0&&(this.dosPermissions=63&this.externalFileAttributes),C==3&&(this.unixPermissions=this.externalFileAttributes>>16&65535),this.dir||this.fileNameStr.slice(-1)!=="/"||(this.dir=!0)},parseZIP64ExtraField:function(){if(this.extraFields[1]){var C=s(this.extraFields[1].value);this.uncompressedSize===r.MAX_VALUE_32BITS&&(this.uncompressedSize=C.readInt(8)),this.compressedSize===r.MAX_VALUE_32BITS&&(this.compressedSize=C.readInt(8)),this.localHeaderOffset===r.MAX_VALUE_32BITS&&(this.localHeaderOffset=C.readInt(8)),this.diskNumberStart===r.MAX_VALUE_32BITS&&(this.diskNumberStart=C.readInt(4))}},readExtraFields:function(C){var Q,h,E,u=C.index+this.extraFieldsLength;for(this.extraFields||(this.extraFields={});C.index+4<u;)Q=C.readInt(2),h=C.readInt(2),E=C.readData(h),this.extraFields[Q]={id:Q,length:h,value:E};C.setIndex(u)},handleUTF8:function(){var C=l.uint8array?"uint8array":"array";if(this.useUTF8())this.fileNameStr=c.utf8decode(this.fileName),this.fileCommentStr=c.utf8decode(this.fileComment);else{var Q=this.findExtraFieldUnicodePath();if(Q!==null)this.fileNameStr=Q;else{var h=r.transformTo(C,this.fileName);this.fileNameStr=this.loadOptions.decodeFileName(h)}var E=this.findExtraFieldUnicodeComment();if(E!==null)this.fileCommentStr=E;else{var u=r.transformTo(C,this.fileComment);this.fileCommentStr=this.loadOptions.decodeFileName(u)}}},findExtraFieldUnicodePath:function(){var C=this.extraFields[28789];if(C){var Q=s(C.value);return Q.readInt(1)!==1||g(this.fileName)!==Q.readInt(4)?null:c.utf8decode(Q.readData(C.length-5))}return null},findExtraFieldUnicodeComment:function(){var C=this.extraFields[25461];if(C){var Q=s(C.value);return Q.readInt(1)!==1||g(this.fileComment)!==Q.readInt(4)?null:c.utf8decode(Q.readData(C.length-5))}return null}},n.exports=B},{"./compressedObject":2,"./compressions":3,"./crc32":4,"./reader/readerFor":22,"./support":30,"./utf8":31,"./utils":32}],35:[function(i,n,o){function s(Q,h,E){this.name=Q,this.dir=E.dir,this.date=E.date,this.comment=E.comment,this.unixPermissions=E.unixPermissions,this.dosPermissions=E.dosPermissions,this._data=h,this._dataBinary=E.binary,this.options={compression:E.compression,compressionOptions:E.compressionOptions}}var r=i("./stream/StreamHelper"),a=i("./stream/DataWorker"),g=i("./utf8"),c=i("./compressedObject"),I=i("./stream/GenericWorker");s.prototype={internalStream:function(Q){var h=null,E="string";try{if(!Q)throw new Error("No output type specified.");var u=(E=Q.toLowerCase())==="string"||E==="text";E!=="binarystring"&&E!=="text"||(E="string"),h=this._decompressWorker();var d=!this._dataBinary;d&&!u&&(h=h.pipe(new g.Utf8EncodeWorker)),!d&&u&&(h=h.pipe(new g.Utf8DecodeWorker))}catch(f){(h=new I("error")).error(f)}return new r(h,E,"")},async:function(Q,h){return this.internalStream(Q).accumulate(h)},nodeStream:function(Q,h){return this.internalStream(Q||"nodebuffer").toNodejsStream(h)},_compressWorker:function(Q,h){if(this._data instanceof c&&this._data.compression.magic===Q.magic)return this._data.getCompressedWorker();var E=this._decompressWorker();return this._dataBinary||(E=E.pipe(new g.Utf8EncodeWorker)),c.createWorkerFrom(E,Q,h)},_decompressWorker:function(){return this._data instanceof c?this._data.getContentWorker():this._data instanceof I?this._data:new a(this._data)}};for(var l=["asText","asBinary","asNodeBuffer","asUint8Array","asArrayBuffer"],B=function(){throw new Error("This method has been removed in JSZip 3.0, please check the upgrade guide.")},C=0;C<l.length;C++)s.prototype[l[C]]=B;n.exports=s},{"./compressedObject":2,"./stream/DataWorker":27,"./stream/GenericWorker":28,"./stream/StreamHelper":29,"./utf8":31}],36:[function(i,n,o){(function(s){var r,a,g=s.MutationObserver||s.WebKitMutationObserver;if(g){var c=0,I=new g(Q),l=s.document.createTextNode("");I.observe(l,{characterData:!0}),r=function(){l.data=c=++c%2}}else if(s.setImmediate||s.MessageChannel===void 0)r="document"in s&&"onreadystatechange"in s.document.createElement("script")?function(){var h=s.document.createElement("script");h.onreadystatechange=function(){Q(),h.onreadystatechange=null,h.parentNode.removeChild(h),h=null},s.document.documentElement.appendChild(h)}:function(){setTimeout(Q,0)};else{var B=new s.MessageChannel;B.port1.onmessage=Q,r=function(){B.port2.postMessage(0)}}var C=[];function Q(){var h,E;a=!0;for(var u=C.length;u;){for(E=C,C=[],h=-1;++h<u;)E[h]();u=C.length}a=!1}n.exports=function(h){C.push(h)!==1||a||r()}}).call(this,typeof cq<"u"?cq:typeof self<"u"?self:typeof window<"u"?window:{})},{}],37:[function(i,n,o){var s=i("immediate");function r(){}var a={},g=["REJECTED"],c=["FULFILLED"],I=["PENDING"];function l(u){if(typeof u!="function")throw new TypeError("resolver must be a function");this.state=I,this.queue=[],this.outcome=void 0,u!==r&&h(this,u)}function B(u,d,f){this.promise=u,typeof d=="function"&&(this.onFulfilled=d,this.callFulfilled=this.otherCallFulfilled),typeof f=="function"&&(this.onRejected=f,this.callRejected=this.otherCallRejected)}function C(u,d,f){s(function(){var y;try{y=d(f)}catch(w){return a.reject(u,w)}y===u?a.reject(u,new TypeError("Cannot resolve promise with itself")):a.resolve(u,y)})}function Q(u){var d=u&&u.then;if(u&&(typeof u=="object"||typeof u=="function")&&typeof d=="function")return function(){d.apply(u,arguments)}}function h(u,d){var f=!1;function y(S){f||(f=!0,a.reject(u,S))}function w(S){f||(f=!0,a.resolve(u,S))}var D=E(function(){d(w,y)});D.status==="error"&&y(D.value)}function E(u,d){var f={};try{f.value=u(d),f.status="success"}catch(y){f.status="error",f.value=y}return f}(n.exports=l).prototype.finally=function(u){if(typeof u!="function")return this;var d=this.constructor;return this.then(function(f){return d.resolve(u()).then(function(){return f})},function(f){return d.resolve(u()).then(function(){throw f})})},l.prototype.catch=function(u){return this.then(null,u)},l.prototype.then=function(u,d){if(typeof u!="function"&&this.state===c||typeof d!="function"&&this.state===g)return this;var f=new this.constructor(r);return this.state!==I?C(f,this.state===c?u:d,this.outcome):this.queue.push(new B(f,u,d)),f},B.prototype.callFulfilled=function(u){a.resolve(this.promise,u)},B.prototype.otherCallFulfilled=function(u){C(this.promise,this.onFulfilled,u)},B.prototype.callRejected=function(u){a.reject(this.promise,u)},B.prototype.otherCallRejected=function(u){C(this.promise,this.onRejected,u)},a.resolve=function(u,d){var f=E(Q,d);if(f.status==="error")return a.reject(u,f.value);var y=f.value;if(y)h(u,y);else{u.state=c,u.outcome=d;for(var w=-1,D=u.queue.length;++w<D;)u.queue[w].callFulfilled(d)}return u},a.reject=function(u,d){u.state=g,u.outcome=d;for(var f=-1,y=u.queue.length;++f<y;)u.queue[f].callRejected(d);return u},l.resolve=function(u){return u instanceof this?u:a.resolve(new this(r),u)},l.reject=function(u){var d=new this(r);return a.reject(d,u)},l.all=function(u){var d=this;if(Object.prototype.toString.call(u)!=="[object Array]")return this.reject(new TypeError("must be an array"));var f=u.length,y=!1;if(!f)return this.resolve([]);for(var w=new Array(f),D=0,S=-1,_=new this(r);++S<f;)b(u[S],S);return _;function b(N,F){d.resolve(N).then(function(L){w[F]=L,++D!==f||y||(y=!0,a.resolve(_,w))},function(L){y||(y=!0,a.reject(_,L))})}},l.race=function(u){var d=this;if(Object.prototype.toString.call(u)!=="[object Array]")return this.reject(new TypeError("must be an array"));var f=u.length,y=!1;if(!f)return this.resolve([]);for(var w=-1,D=new this(r);++w<f;)S=u[w],d.resolve(S).then(function(_){y||(y=!0,a.resolve(D,_))},function(_){y||(y=!0,a.reject(D,_))});var S;return D}},{immediate:36}],38:[function(i,n,o){var s={};(0,i("./lib/utils/common").assign)(s,i("./lib/deflate"),i("./lib/inflate"),i("./lib/zlib/constants")),n.exports=s},{"./lib/deflate":39,"./lib/inflate":40,"./lib/utils/common":41,"./lib/zlib/constants":44}],39:[function(i,n,o){var s=i("./zlib/deflate"),r=i("./utils/common"),a=i("./utils/strings"),g=i("./zlib/messages"),c=i("./zlib/zstream"),I=Object.prototype.toString,l=0,B=-1,C=0,Q=8;function h(u){if(!(this instanceof h))return new h(u);this.options=r.assign({level:B,method:Q,chunkSize:16384,windowBits:15,memLevel:8,strategy:C,to:""},u||{});var d=this.options;d.raw&&0<d.windowBits?d.windowBits=-d.windowBits:d.gzip&&0<d.windowBits&&d.windowBits<16&&(d.windowBits+=16),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new c,this.strm.avail_out=0;var f=s.deflateInit2(this.strm,d.level,d.method,d.windowBits,d.memLevel,d.strategy);if(f!==l)throw new Error(g[f]);if(d.header&&s.deflateSetHeader(this.strm,d.header),d.dictionary){var y;if(y=typeof d.dictionary=="string"?a.string2buf(d.dictionary):I.call(d.dictionary)==="[object ArrayBuffer]"?new Uint8Array(d.dictionary):d.dictionary,(f=s.deflateSetDictionary(this.strm,y))!==l)throw new Error(g[f]);this._dict_set=!0}}function E(u,d){var f=new h(d);if(f.push(u,!0),f.err)throw f.msg||g[f.err];return f.result}h.prototype.push=function(u,d){var f,y,w=this.strm,D=this.options.chunkSize;if(this.ended)return!1;y=d===~~d?d:d===!0?4:0,typeof u=="string"?w.input=a.string2buf(u):I.call(u)==="[object ArrayBuffer]"?w.input=new Uint8Array(u):w.input=u,w.next_in=0,w.avail_in=w.input.length;do{if(w.avail_out===0&&(w.output=new r.Buf8(D),w.next_out=0,w.avail_out=D),(f=s.deflate(w,y))!==1&&f!==l)return this.onEnd(f),!(this.ended=!0);w.avail_out!==0&&(w.avail_in!==0||y!==4&&y!==2)||(this.options.to==="string"?this.onData(a.buf2binstring(r.shrinkBuf(w.output,w.next_out))):this.onData(r.shrinkBuf(w.output,w.next_out)))}while((0<w.avail_in||w.avail_out===0)&&f!==1);return y===4?(f=s.deflateEnd(this.strm),this.onEnd(f),this.ended=!0,f===l):y!==2||(this.onEnd(l),!(w.avail_out=0))},h.prototype.onData=function(u){this.chunks.push(u)},h.prototype.onEnd=function(u){u===l&&(this.options.to==="string"?this.result=this.chunks.join(""):this.result=r.flattenChunks(this.chunks)),this.chunks=[],this.err=u,this.msg=this.strm.msg},o.Deflate=h,o.deflate=E,o.deflateRaw=function(u,d){return(d=d||{}).raw=!0,E(u,d)},o.gzip=function(u,d){return(d=d||{}).gzip=!0,E(u,d)}},{"./utils/common":41,"./utils/strings":42,"./zlib/deflate":46,"./zlib/messages":51,"./zlib/zstream":53}],40:[function(i,n,o){var s=i("./zlib/inflate"),r=i("./utils/common"),a=i("./utils/strings"),g=i("./zlib/constants"),c=i("./zlib/messages"),I=i("./zlib/zstream"),l=i("./zlib/gzheader"),B=Object.prototype.toString;function C(h){if(!(this instanceof C))return new C(h);this.options=r.assign({chunkSize:16384,windowBits:0,to:""},h||{});var E=this.options;E.raw&&0<=E.windowBits&&E.windowBits<16&&(E.windowBits=-E.windowBits,E.windowBits===0&&(E.windowBits=-15)),!(0<=E.windowBits&&E.windowBits<16)||h&&h.windowBits||(E.windowBits+=32),15<E.windowBits&&E.windowBits<48&&(15&E.windowBits)==0&&(E.windowBits|=15),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new I,this.strm.avail_out=0;var u=s.inflateInit2(this.strm,E.windowBits);if(u!==g.Z_OK)throw new Error(c[u]);this.header=new l,s.inflateGetHeader(this.strm,this.header)}function Q(h,E){var u=new C(E);if(u.push(h,!0),u.err)throw u.msg||c[u.err];return u.result}C.prototype.push=function(h,E){var u,d,f,y,w,D,S=this.strm,_=this.options.chunkSize,b=this.options.dictionary,N=!1;if(this.ended)return!1;d=E===~~E?E:E===!0?g.Z_FINISH:g.Z_NO_FLUSH,typeof h=="string"?S.input=a.binstring2buf(h):B.call(h)==="[object ArrayBuffer]"?S.input=new Uint8Array(h):S.input=h,S.next_in=0,S.avail_in=S.input.length;do{if(S.avail_out===0&&(S.output=new r.Buf8(_),S.next_out=0,S.avail_out=_),(u=s.inflate(S,g.Z_NO_FLUSH))===g.Z_NEED_DICT&&b&&(D=typeof b=="string"?a.string2buf(b):B.call(b)==="[object ArrayBuffer]"?new Uint8Array(b):b,u=s.inflateSetDictionary(this.strm,D)),u===g.Z_BUF_ERROR&&N===!0&&(u=g.Z_OK,N=!1),u!==g.Z_STREAM_END&&u!==g.Z_OK)return this.onEnd(u),!(this.ended=!0);S.next_out&&(S.avail_out!==0&&u!==g.Z_STREAM_END&&(S.avail_in!==0||d!==g.Z_FINISH&&d!==g.Z_SYNC_FLUSH)||(this.options.to==="string"?(f=a.utf8border(S.output,S.next_out),y=S.next_out-f,w=a.buf2string(S.output,f),S.next_out=y,S.avail_out=_-y,y&&r.arraySet(S.output,S.output,f,y,0),this.onData(w)):this.onData(r.shrinkBuf(S.output,S.next_out)))),S.avail_in===0&&S.avail_out===0&&(N=!0)}while((0<S.avail_in||S.avail_out===0)&&u!==g.Z_STREAM_END);return u===g.Z_STREAM_END&&(d=g.Z_FINISH),d===g.Z_FINISH?(u=s.inflateEnd(this.strm),this.onEnd(u),this.ended=!0,u===g.Z_OK):d!==g.Z_SYNC_FLUSH||(this.onEnd(g.Z_OK),!(S.avail_out=0))},C.prototype.onData=function(h){this.chunks.push(h)},C.prototype.onEnd=function(h){h===g.Z_OK&&(this.options.to==="string"?this.result=this.chunks.join(""):this.result=r.flattenChunks(this.chunks)),this.chunks=[],this.err=h,this.msg=this.strm.msg},o.Inflate=C,o.inflate=Q,o.inflateRaw=function(h,E){return(E=E||{}).raw=!0,Q(h,E)},o.ungzip=Q},{"./utils/common":41,"./utils/strings":42,"./zlib/constants":44,"./zlib/gzheader":47,"./zlib/inflate":49,"./zlib/messages":51,"./zlib/zstream":53}],41:[function(i,n,o){var s=typeof Uint8Array<"u"&&typeof Uint16Array<"u"&&typeof Int32Array<"u";o.assign=function(g){for(var c=Array.prototype.slice.call(arguments,1);c.length;){var I=c.shift();if(I){if(typeof I!="object")throw new TypeError(I+"must be non-object");for(var l in I)I.hasOwnProperty(l)&&(g[l]=I[l])}}return g},o.shrinkBuf=function(g,c){return g.length===c?g:g.subarray?g.subarray(0,c):(g.length=c,g)};var r={arraySet:function(g,c,I,l,B){if(c.subarray&&g.subarray)g.set(c.subarray(I,I+l),B);else for(var C=0;C<l;C++)g[B+C]=c[I+C]},flattenChunks:function(g){var c,I,l,B,C,Q;for(c=l=0,I=g.length;c<I;c++)l+=g[c].length;for(Q=new Uint8Array(l),c=B=0,I=g.length;c<I;c++)C=g[c],Q.set(C,B),B+=C.length;return Q}},a={arraySet:function(g,c,I,l,B){for(var C=0;C<l;C++)g[B+C]=c[I+C]},flattenChunks:function(g){return[].concat.apply([],g)}};o.setTyped=function(g){g?(o.Buf8=Uint8Array,o.Buf16=Uint16Array,o.Buf32=Int32Array,o.assign(o,r)):(o.Buf8=Array,o.Buf16=Array,o.Buf32=Array,o.assign(o,a))},o.setTyped(s)},{}],42:[function(i,n,o){var s=i("./common"),r=!0,a=!0;try{String.fromCharCode.apply(null,[0])}catch{r=!1}try{String.fromCharCode.apply(null,new Uint8Array(1))}catch{a=!1}for(var g=new s.Buf8(256),c=0;c<256;c++)g[c]=252<=c?6:248<=c?5:240<=c?4:224<=c?3:192<=c?2:1;function I(l,B){if(B<65537&&(l.subarray&&a||!l.subarray&&r))return String.fromCharCode.apply(null,s.shrinkBuf(l,B));for(var C="",Q=0;Q<B;Q++)C+=String.fromCharCode(l[Q]);return C}g[254]=g[254]=1,o.string2buf=function(l){var B,C,Q,h,E,u=l.length,d=0;for(h=0;h<u;h++)(64512&(C=l.charCodeAt(h)))==55296&&h+1<u&&(64512&(Q=l.charCodeAt(h+1)))==56320&&(C=65536+(C-55296<<10)+(Q-56320),h++),d+=C<128?1:C<2048?2:C<65536?3:4;for(B=new s.Buf8(d),h=E=0;E<d;h++)(64512&(C=l.charCodeAt(h)))==55296&&h+1<u&&(64512&(Q=l.charCodeAt(h+1)))==56320&&(C=65536+(C-55296<<10)+(Q-56320),h++),C<128?B[E++]=C:(C<2048?B[E++]=192|C>>>6:(C<65536?B[E++]=224|C>>>12:(B[E++]=240|C>>>18,B[E++]=128|C>>>12&63),B[E++]=128|C>>>6&63),B[E++]=128|63&C);return B},o.buf2binstring=function(l){return I(l,l.length)},o.binstring2buf=function(l){for(var B=new s.Buf8(l.length),C=0,Q=B.length;C<Q;C++)B[C]=l.charCodeAt(C);return B},o.buf2string=function(l,B){var C,Q,h,E,u=B||l.length,d=new Array(2*u);for(C=Q=0;C<u;)if((h=l[C++])<128)d[Q++]=h;else if(4<(E=g[h]))d[Q++]=65533,C+=E-1;else{for(h&=E===2?31:E===3?15:7;1<E&&C<u;)h=h<<6|63&l[C++],E--;1<E?d[Q++]=65533:h<65536?d[Q++]=h:(h-=65536,d[Q++]=55296|h>>10&1023,d[Q++]=56320|1023&h)}return I(d,Q)},o.utf8border=function(l,B){var C;for((B=B||l.length)>l.length&&(B=l.length),C=B-1;0<=C&&(192&l[C])==128;)C--;return C<0||C===0?B:C+g[l[C]]>B?C:B}},{"./common":41}],43:[function(i,n,o){n.exports=function(s,r,a,g){for(var c=65535&s|0,I=s>>>16&65535|0,l=0;a!==0;){for(a-=l=2e3<a?2e3:a;I=I+(c=c+r[g++]|0)|0,--l;);c%=65521,I%=65521}return c|I<<16|0}},{}],44:[function(i,n,o){n.exports={Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_TREES:6,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_BUF_ERROR:-5,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,Z_BINARY:0,Z_TEXT:1,Z_UNKNOWN:2,Z_DEFLATED:8}},{}],45:[function(i,n,o){var s=(function(){for(var r,a=[],g=0;g<256;g++){r=g;for(var c=0;c<8;c++)r=1&r?3988292384^r>>>1:r>>>1;a[g]=r}return a})();n.exports=function(r,a,g,c){var I=s,l=c+g;r^=-1;for(var B=c;B<l;B++)r=r>>>8^I[255&(r^a[B])];return-1^r}},{}],46:[function(i,n,o){var s,r=i("../utils/common"),a=i("./trees"),g=i("./adler32"),c=i("./crc32"),I=i("./messages"),l=0,B=4,C=0,Q=-2,h=-1,E=4,u=2,d=8,f=9,y=286,w=30,D=19,S=2*y+1,_=15,b=3,N=258,F=N+b+1,L=42,Y=113,J=1,O=2,Z=3,X=4;function eA(fA,ge){return fA.msg=I[ge],ge}function gA(fA){return(fA<<1)-(4<fA?9:0)}function tA(fA){for(var ge=fA.length;0<=--ge;)fA[ge]=0}function iA(fA){var ge=fA.state,jA=ge.pending;jA>fA.avail_out&&(jA=fA.avail_out),jA!==0&&(r.arraySet(fA.output,ge.pending_buf,ge.pending_out,jA,fA.next_out),fA.next_out+=jA,ge.pending_out+=jA,fA.total_out+=jA,fA.avail_out-=jA,ge.pending-=jA,ge.pending===0&&(ge.pending_out=0))}function sA(fA,ge){a._tr_flush_block(fA,0<=fA.block_start?fA.block_start:-1,fA.strstart-fA.block_start,ge),fA.block_start=fA.strstart,iA(fA.strm)}function aA(fA,ge){fA.pending_buf[fA.pending++]=ge}function EA(fA,ge){fA.pending_buf[fA.pending++]=ge>>>8&255,fA.pending_buf[fA.pending++]=255&ge}function bA(fA,ge){var jA,JA,WA=fA.max_chain_length,vA=fA.strstart,wA=fA.prev_length,RA=fA.nice_match,MA=fA.strstart>fA.w_size-F?fA.strstart-(fA.w_size-F):0,KA=fA.window,ZA=fA.w_mask,ne=fA.prev,SA=fA.strstart+N,CA=KA[vA+wA-1],uA=KA[vA+wA];fA.prev_length>=fA.good_match&&(WA>>=2),RA>fA.lookahead&&(RA=fA.lookahead);do if(KA[(jA=ge)+wA]===uA&&KA[jA+wA-1]===CA&&KA[jA]===KA[vA]&&KA[++jA]===KA[vA+1]){vA+=2,jA++;do;while(KA[++vA]===KA[++jA]&&KA[++vA]===KA[++jA]&&KA[++vA]===KA[++jA]&&KA[++vA]===KA[++jA]&&KA[++vA]===KA[++jA]&&KA[++vA]===KA[++jA]&&KA[++vA]===KA[++jA]&&KA[++vA]===KA[++jA]&&vA<SA);if(JA=N-(SA-vA),vA=SA-N,wA<JA){if(fA.match_start=ge,RA<=(wA=JA))break;CA=KA[vA+wA-1],uA=KA[vA+wA]}}while((ge=ne[ge&ZA])>MA&&--WA!=0);return wA<=fA.lookahead?wA:fA.lookahead}function _A(fA){var ge,jA,JA,WA,vA,wA,RA,MA,KA,ZA,ne=fA.w_size;do{if(WA=fA.window_size-fA.lookahead-fA.strstart,fA.strstart>=ne+(ne-F)){for(r.arraySet(fA.window,fA.window,ne,ne,0),fA.match_start-=ne,fA.strstart-=ne,fA.block_start-=ne,ge=jA=fA.hash_size;JA=fA.head[--ge],fA.head[ge]=ne<=JA?JA-ne:0,--jA;);for(ge=jA=ne;JA=fA.prev[--ge],fA.prev[ge]=ne<=JA?JA-ne:0,--jA;);WA+=ne}if(fA.strm.avail_in===0)break;if(wA=fA.strm,RA=fA.window,MA=fA.strstart+fA.lookahead,KA=WA,ZA=void 0,ZA=wA.avail_in,KA<ZA&&(ZA=KA),jA=ZA===0?0:(wA.avail_in-=ZA,r.arraySet(RA,wA.input,wA.next_in,ZA,MA),wA.state.wrap===1?wA.adler=g(wA.adler,RA,ZA,MA):wA.state.wrap===2&&(wA.adler=c(wA.adler,RA,ZA,MA)),wA.next_in+=ZA,wA.total_in+=ZA,ZA),fA.lookahead+=jA,fA.lookahead+fA.insert>=b)for(vA=fA.strstart-fA.insert,fA.ins_h=fA.window[vA],fA.ins_h=(fA.ins_h<<fA.hash_shift^fA.window[vA+1])&fA.hash_mask;fA.insert&&(fA.ins_h=(fA.ins_h<<fA.hash_shift^fA.window[vA+b-1])&fA.hash_mask,fA.prev[vA&fA.w_mask]=fA.head[fA.ins_h],fA.head[fA.ins_h]=vA,vA++,fA.insert--,!(fA.lookahead+fA.insert<b)););}while(fA.lookahead<F&&fA.strm.avail_in!==0)}function LA(fA,ge){for(var jA,JA;;){if(fA.lookahead<F){if(_A(fA),fA.lookahead<F&&ge===l)return J;if(fA.lookahead===0)break}if(jA=0,fA.lookahead>=b&&(fA.ins_h=(fA.ins_h<<fA.hash_shift^fA.window[fA.strstart+b-1])&fA.hash_mask,jA=fA.prev[fA.strstart&fA.w_mask]=fA.head[fA.ins_h],fA.head[fA.ins_h]=fA.strstart),jA!==0&&fA.strstart-jA<=fA.w_size-F&&(fA.match_length=bA(fA,jA)),fA.match_length>=b)if(JA=a._tr_tally(fA,fA.strstart-fA.match_start,fA.match_length-b),fA.lookahead-=fA.match_length,fA.match_length<=fA.max_lazy_match&&fA.lookahead>=b){for(fA.match_length--;fA.strstart++,fA.ins_h=(fA.ins_h<<fA.hash_shift^fA.window[fA.strstart+b-1])&fA.hash_mask,jA=fA.prev[fA.strstart&fA.w_mask]=fA.head[fA.ins_h],fA.head[fA.ins_h]=fA.strstart,--fA.match_length!=0;);fA.strstart++}else fA.strstart+=fA.match_length,fA.match_length=0,fA.ins_h=fA.window[fA.strstart],fA.ins_h=(fA.ins_h<<fA.hash_shift^fA.window[fA.strstart+1])&fA.hash_mask;else JA=a._tr_tally(fA,0,fA.window[fA.strstart]),fA.lookahead--,fA.strstart++;if(JA&&(sA(fA,!1),fA.strm.avail_out===0))return J}return fA.insert=fA.strstart<b-1?fA.strstart:b-1,ge===B?(sA(fA,!0),fA.strm.avail_out===0?Z:X):fA.last_lit&&(sA(fA,!1),fA.strm.avail_out===0)?J:O}function QA(fA,ge){for(var jA,JA,WA;;){if(fA.lookahead<F){if(_A(fA),fA.lookahead<F&&ge===l)return J;if(fA.lookahead===0)break}if(jA=0,fA.lookahead>=b&&(fA.ins_h=(fA.ins_h<<fA.hash_shift^fA.window[fA.strstart+b-1])&fA.hash_mask,jA=fA.prev[fA.strstart&fA.w_mask]=fA.head[fA.ins_h],fA.head[fA.ins_h]=fA.strstart),fA.prev_length=fA.match_length,fA.prev_match=fA.match_start,fA.match_length=b-1,jA!==0&&fA.prev_length<fA.max_lazy_match&&fA.strstart-jA<=fA.w_size-F&&(fA.match_length=bA(fA,jA),fA.match_length<=5&&(fA.strategy===1||fA.match_length===b&&4096<fA.strstart-fA.match_start)&&(fA.match_length=b-1)),fA.prev_length>=b&&fA.match_length<=fA.prev_length){for(WA=fA.strstart+fA.lookahead-b,JA=a._tr_tally(fA,fA.strstart-1-fA.prev_match,fA.prev_length-b),fA.lookahead-=fA.prev_length-1,fA.prev_length-=2;++fA.strstart<=WA&&(fA.ins_h=(fA.ins_h<<fA.hash_shift^fA.window[fA.strstart+b-1])&fA.hash_mask,jA=fA.prev[fA.strstart&fA.w_mask]=fA.head[fA.ins_h],fA.head[fA.ins_h]=fA.strstart),--fA.prev_length!=0;);if(fA.match_available=0,fA.match_length=b-1,fA.strstart++,JA&&(sA(fA,!1),fA.strm.avail_out===0))return J}else if(fA.match_available){if((JA=a._tr_tally(fA,0,fA.window[fA.strstart-1]))&&sA(fA,!1),fA.strstart++,fA.lookahead--,fA.strm.avail_out===0)return J}else fA.match_available=1,fA.strstart++,fA.lookahead--}return fA.match_available&&(JA=a._tr_tally(fA,0,fA.window[fA.strstart-1]),fA.match_available=0),fA.insert=fA.strstart<b-1?fA.strstart:b-1,ge===B?(sA(fA,!0),fA.strm.avail_out===0?Z:X):fA.last_lit&&(sA(fA,!1),fA.strm.avail_out===0)?J:O}function kA(fA,ge,jA,JA,WA){this.good_length=fA,this.max_lazy=ge,this.nice_length=jA,this.max_chain=JA,this.func=WA}function dA(){this.strm=null,this.status=0,this.pending_buf=null,this.pending_buf_size=0,this.pending_out=0,this.pending=0,this.wrap=0,this.gzhead=null,this.gzindex=0,this.method=d,this.last_flush=-1,this.w_size=0,this.w_bits=0,this.w_mask=0,this.window=null,this.window_size=0,this.prev=null,this.head=null,this.ins_h=0,this.hash_size=0,this.hash_bits=0,this.hash_mask=0,this.hash_shift=0,this.block_start=0,this.match_length=0,this.prev_match=0,this.match_available=0,this.strstart=0,this.match_start=0,this.lookahead=0,this.prev_length=0,this.max_chain_length=0,this.max_lazy_match=0,this.level=0,this.strategy=0,this.good_match=0,this.nice_match=0,this.dyn_ltree=new r.Buf16(2*S),this.dyn_dtree=new r.Buf16(2*(2*w+1)),this.bl_tree=new r.Buf16(2*(2*D+1)),tA(this.dyn_ltree),tA(this.dyn_dtree),tA(this.bl_tree),this.l_desc=null,this.d_desc=null,this.bl_desc=null,this.bl_count=new r.Buf16(_+1),this.heap=new r.Buf16(2*y+1),tA(this.heap),this.heap_len=0,this.heap_max=0,this.depth=new r.Buf16(2*y+1),tA(this.depth),this.l_buf=0,this.lit_bufsize=0,this.last_lit=0,this.d_buf=0,this.opt_len=0,this.static_len=0,this.matches=0,this.insert=0,this.bi_buf=0,this.bi_valid=0}function qA(fA){var ge;return fA&&fA.state?(fA.total_in=fA.total_out=0,fA.data_type=u,(ge=fA.state).pending=0,ge.pending_out=0,ge.wrap<0&&(ge.wrap=-ge.wrap),ge.status=ge.wrap?L:Y,fA.adler=ge.wrap===2?0:1,ge.last_flush=l,a._tr_init(ge),C):eA(fA,Q)}function VA(fA){var ge=qA(fA);return ge===C&&(function(jA){jA.window_size=2*jA.w_size,tA(jA.head),jA.max_lazy_match=s[jA.level].max_lazy,jA.good_match=s[jA.level].good_length,jA.nice_match=s[jA.level].nice_length,jA.max_chain_length=s[jA.level].max_chain,jA.strstart=0,jA.block_start=0,jA.lookahead=0,jA.insert=0,jA.match_length=jA.prev_length=b-1,jA.match_available=0,jA.ins_h=0})(fA.state),ge}function ce(fA,ge,jA,JA,WA,vA){if(!fA)return Q;var wA=1;if(ge===h&&(ge=6),JA<0?(wA=0,JA=-JA):15<JA&&(wA=2,JA-=16),WA<1||f<WA||jA!==d||JA<8||15<JA||ge<0||9<ge||vA<0||E<vA)return eA(fA,Q);JA===8&&(JA=9);var RA=new dA;return(fA.state=RA).strm=fA,RA.wrap=wA,RA.gzhead=null,RA.w_bits=JA,RA.w_size=1<<RA.w_bits,RA.w_mask=RA.w_size-1,RA.hash_bits=WA+7,RA.hash_size=1<<RA.hash_bits,RA.hash_mask=RA.hash_size-1,RA.hash_shift=~~((RA.hash_bits+b-1)/b),RA.window=new r.Buf8(2*RA.w_size),RA.head=new r.Buf16(RA.hash_size),RA.prev=new r.Buf16(RA.w_size),RA.lit_bufsize=1<<WA+6,RA.pending_buf_size=4*RA.lit_bufsize,RA.pending_buf=new r.Buf8(RA.pending_buf_size),RA.d_buf=1*RA.lit_bufsize,RA.l_buf=3*RA.lit_bufsize,RA.level=ge,RA.strategy=vA,RA.method=jA,VA(fA)}s=[new kA(0,0,0,0,function(fA,ge){var jA=65535;for(jA>fA.pending_buf_size-5&&(jA=fA.pending_buf_size-5);;){if(fA.lookahead<=1){if(_A(fA),fA.lookahead===0&&ge===l)return J;if(fA.lookahead===0)break}fA.strstart+=fA.lookahead,fA.lookahead=0;var JA=fA.block_start+jA;if((fA.strstart===0||fA.strstart>=JA)&&(fA.lookahead=fA.strstart-JA,fA.strstart=JA,sA(fA,!1),fA.strm.avail_out===0)||fA.strstart-fA.block_start>=fA.w_size-F&&(sA(fA,!1),fA.strm.avail_out===0))return J}return fA.insert=0,ge===B?(sA(fA,!0),fA.strm.avail_out===0?Z:X):(fA.strstart>fA.block_start&&(sA(fA,!1),fA.strm.avail_out),J)}),new kA(4,4,8,4,LA),new kA(4,5,16,8,LA),new kA(4,6,32,32,LA),new kA(4,4,16,16,QA),new kA(8,16,32,32,QA),new kA(8,16,128,128,QA),new kA(8,32,128,256,QA),new kA(32,128,258,1024,QA),new kA(32,258,258,4096,QA)],o.deflateInit=function(fA,ge){return ce(fA,ge,d,15,8,0)},o.deflateInit2=ce,o.deflateReset=VA,o.deflateResetKeep=qA,o.deflateSetHeader=function(fA,ge){return fA&&fA.state?fA.state.wrap!==2?Q:(fA.state.gzhead=ge,C):Q},o.deflate=function(fA,ge){var jA,JA,WA,vA;if(!fA||!fA.state||5<ge||ge<0)return fA?eA(fA,Q):Q;if(JA=fA.state,!fA.output||!fA.input&&fA.avail_in!==0||JA.status===666&&ge!==B)return eA(fA,fA.avail_out===0?-5:Q);if(JA.strm=fA,jA=JA.last_flush,JA.last_flush=ge,JA.status===L)if(JA.wrap===2)fA.adler=0,aA(JA,31),aA(JA,139),aA(JA,8),JA.gzhead?(aA(JA,(JA.gzhead.text?1:0)+(JA.gzhead.hcrc?2:0)+(JA.gzhead.extra?4:0)+(JA.gzhead.name?8:0)+(JA.gzhead.comment?16:0)),aA(JA,255&JA.gzhead.time),aA(JA,JA.gzhead.time>>8&255),aA(JA,JA.gzhead.time>>16&255),aA(JA,JA.gzhead.time>>24&255),aA(JA,JA.level===9?2:2<=JA.strategy||JA.level<2?4:0),aA(JA,255&JA.gzhead.os),JA.gzhead.extra&&JA.gzhead.extra.length&&(aA(JA,255&JA.gzhead.extra.length),aA(JA,JA.gzhead.extra.length>>8&255)),JA.gzhead.hcrc&&(fA.adler=c(fA.adler,JA.pending_buf,JA.pending,0)),JA.gzindex=0,JA.status=69):(aA(JA,0),aA(JA,0),aA(JA,0),aA(JA,0),aA(JA,0),aA(JA,JA.level===9?2:2<=JA.strategy||JA.level<2?4:0),aA(JA,3),JA.status=Y);else{var wA=d+(JA.w_bits-8<<4)<<8;wA|=(2<=JA.strategy||JA.level<2?0:JA.level<6?1:JA.level===6?2:3)<<6,JA.strstart!==0&&(wA|=32),wA+=31-wA%31,JA.status=Y,EA(JA,wA),JA.strstart!==0&&(EA(JA,fA.adler>>>16),EA(JA,65535&fA.adler)),fA.adler=1}if(JA.status===69)if(JA.gzhead.extra){for(WA=JA.pending;JA.gzindex<(65535&JA.gzhead.extra.length)&&(JA.pending!==JA.pending_buf_size||(JA.gzhead.hcrc&&JA.pending>WA&&(fA.adler=c(fA.adler,JA.pending_buf,JA.pending-WA,WA)),iA(fA),WA=JA.pending,JA.pending!==JA.pending_buf_size));)aA(JA,255&JA.gzhead.extra[JA.gzindex]),JA.gzindex++;JA.gzhead.hcrc&&JA.pending>WA&&(fA.adler=c(fA.adler,JA.pending_buf,JA.pending-WA,WA)),JA.gzindex===JA.gzhead.extra.length&&(JA.gzindex=0,JA.status=73)}else JA.status=73;if(JA.status===73)if(JA.gzhead.name){WA=JA.pending;do{if(JA.pending===JA.pending_buf_size&&(JA.gzhead.hcrc&&JA.pending>WA&&(fA.adler=c(fA.adler,JA.pending_buf,JA.pending-WA,WA)),iA(fA),WA=JA.pending,JA.pending===JA.pending_buf_size)){vA=1;break}vA=JA.gzindex<JA.gzhead.name.length?255&JA.gzhead.name.charCodeAt(JA.gzindex++):0,aA(JA,vA)}while(vA!==0);JA.gzhead.hcrc&&JA.pending>WA&&(fA.adler=c(fA.adler,JA.pending_buf,JA.pending-WA,WA)),vA===0&&(JA.gzindex=0,JA.status=91)}else JA.status=91;if(JA.status===91)if(JA.gzhead.comment){WA=JA.pending;do{if(JA.pending===JA.pending_buf_size&&(JA.gzhead.hcrc&&JA.pending>WA&&(fA.adler=c(fA.adler,JA.pending_buf,JA.pending-WA,WA)),iA(fA),WA=JA.pending,JA.pending===JA.pending_buf_size)){vA=1;break}vA=JA.gzindex<JA.gzhead.comment.length?255&JA.gzhead.comment.charCodeAt(JA.gzindex++):0,aA(JA,vA)}while(vA!==0);JA.gzhead.hcrc&&JA.pending>WA&&(fA.adler=c(fA.adler,JA.pending_buf,JA.pending-WA,WA)),vA===0&&(JA.status=103)}else JA.status=103;if(JA.status===103&&(JA.gzhead.hcrc?(JA.pending+2>JA.pending_buf_size&&iA(fA),JA.pending+2<=JA.pending_buf_size&&(aA(JA,255&fA.adler),aA(JA,fA.adler>>8&255),fA.adler=0,JA.status=Y)):JA.status=Y),JA.pending!==0){if(iA(fA),fA.avail_out===0)return JA.last_flush=-1,C}else if(fA.avail_in===0&&gA(ge)<=gA(jA)&&ge!==B)return eA(fA,-5);if(JA.status===666&&fA.avail_in!==0)return eA(fA,-5);if(fA.avail_in!==0||JA.lookahead!==0||ge!==l&&JA.status!==666){var RA=JA.strategy===2?(function(MA,KA){for(var ZA;;){if(MA.lookahead===0&&(_A(MA),MA.lookahead===0)){if(KA===l)return J;break}if(MA.match_length=0,ZA=a._tr_tally(MA,0,MA.window[MA.strstart]),MA.lookahead--,MA.strstart++,ZA&&(sA(MA,!1),MA.strm.avail_out===0))return J}return MA.insert=0,KA===B?(sA(MA,!0),MA.strm.avail_out===0?Z:X):MA.last_lit&&(sA(MA,!1),MA.strm.avail_out===0)?J:O})(JA,ge):JA.strategy===3?(function(MA,KA){for(var ZA,ne,SA,CA,uA=MA.window;;){if(MA.lookahead<=N){if(_A(MA),MA.lookahead<=N&&KA===l)return J;if(MA.lookahead===0)break}if(MA.match_length=0,MA.lookahead>=b&&0<MA.strstart&&(ne=uA[SA=MA.strstart-1])===uA[++SA]&&ne===uA[++SA]&&ne===uA[++SA]){CA=MA.strstart+N;do;while(ne===uA[++SA]&&ne===uA[++SA]&&ne===uA[++SA]&&ne===uA[++SA]&&ne===uA[++SA]&&ne===uA[++SA]&&ne===uA[++SA]&&ne===uA[++SA]&&SA<CA);MA.match_length=N-(CA-SA),MA.match_length>MA.lookahead&&(MA.match_length=MA.lookahead)}if(MA.match_length>=b?(ZA=a._tr_tally(MA,1,MA.match_length-b),MA.lookahead-=MA.match_length,MA.strstart+=MA.match_length,MA.match_length=0):(ZA=a._tr_tally(MA,0,MA.window[MA.strstart]),MA.lookahead--,MA.strstart++),ZA&&(sA(MA,!1),MA.strm.avail_out===0))return J}return MA.insert=0,KA===B?(sA(MA,!0),MA.strm.avail_out===0?Z:X):MA.last_lit&&(sA(MA,!1),MA.strm.avail_out===0)?J:O})(JA,ge):s[JA.level].func(JA,ge);if(RA!==Z&&RA!==X||(JA.status=666),RA===J||RA===Z)return fA.avail_out===0&&(JA.last_flush=-1),C;if(RA===O&&(ge===1?a._tr_align(JA):ge!==5&&(a._tr_stored_block(JA,0,0,!1),ge===3&&(tA(JA.head),JA.lookahead===0&&(JA.strstart=0,JA.block_start=0,JA.insert=0))),iA(fA),fA.avail_out===0))return JA.last_flush=-1,C}return ge!==B?C:JA.wrap<=0?1:(JA.wrap===2?(aA(JA,255&fA.adler),aA(JA,fA.adler>>8&255),aA(JA,fA.adler>>16&255),aA(JA,fA.adler>>24&255),aA(JA,255&fA.total_in),aA(JA,fA.total_in>>8&255),aA(JA,fA.total_in>>16&255),aA(JA,fA.total_in>>24&255)):(EA(JA,fA.adler>>>16),EA(JA,65535&fA.adler)),iA(fA),0<JA.wrap&&(JA.wrap=-JA.wrap),JA.pending!==0?C:1)},o.deflateEnd=function(fA){var ge;return fA&&fA.state?(ge=fA.state.status)!==L&&ge!==69&&ge!==73&&ge!==91&&ge!==103&&ge!==Y&&ge!==666?eA(fA,Q):(fA.state=null,ge===Y?eA(fA,-3):C):Q},o.deflateSetDictionary=function(fA,ge){var jA,JA,WA,vA,wA,RA,MA,KA,ZA=ge.length;if(!fA||!fA.state||(vA=(jA=fA.state).wrap)===2||vA===1&&jA.status!==L||jA.lookahead)return Q;for(vA===1&&(fA.adler=g(fA.adler,ge,ZA,0)),jA.wrap=0,ZA>=jA.w_size&&(vA===0&&(tA(jA.head),jA.strstart=0,jA.block_start=0,jA.insert=0),KA=new r.Buf8(jA.w_size),r.arraySet(KA,ge,ZA-jA.w_size,jA.w_size,0),ge=KA,ZA=jA.w_size),wA=fA.avail_in,RA=fA.next_in,MA=fA.input,fA.avail_in=ZA,fA.next_in=0,fA.input=ge,_A(jA);jA.lookahead>=b;){for(JA=jA.strstart,WA=jA.lookahead-(b-1);jA.ins_h=(jA.ins_h<<jA.hash_shift^jA.window[JA+b-1])&jA.hash_mask,jA.prev[JA&jA.w_mask]=jA.head[jA.ins_h],jA.head[jA.ins_h]=JA,JA++,--WA;);jA.strstart=JA,jA.lookahead=b-1,_A(jA)}return jA.strstart+=jA.lookahead,jA.block_start=jA.strstart,jA.insert=jA.lookahead,jA.lookahead=0,jA.match_length=jA.prev_length=b-1,jA.match_available=0,fA.next_in=RA,fA.input=MA,fA.avail_in=wA,jA.wrap=vA,C},o.deflateInfo="pako deflate (from Nodeca project)"},{"../utils/common":41,"./adler32":43,"./crc32":45,"./messages":51,"./trees":52}],47:[function(i,n,o){n.exports=function(){this.text=0,this.time=0,this.xflags=0,this.os=0,this.extra=null,this.extra_len=0,this.name="",this.comment="",this.hcrc=0,this.done=!1}},{}],48:[function(i,n,o){n.exports=function(s,r){var a,g,c,I,l,B,C,Q,h,E,u,d,f,y,w,D,S,_,b,N,F,L,Y,J,O;a=s.state,g=s.next_in,J=s.input,c=g+(s.avail_in-5),I=s.next_out,O=s.output,l=I-(r-s.avail_out),B=I+(s.avail_out-257),C=a.dmax,Q=a.wsize,h=a.whave,E=a.wnext,u=a.window,d=a.hold,f=a.bits,y=a.lencode,w=a.distcode,D=(1<<a.lenbits)-1,S=(1<<a.distbits)-1;A:do{f<15&&(d+=J[g++]<<f,f+=8,d+=J[g++]<<f,f+=8),_=y[d&D];e:for(;;){if(d>>>=b=_>>>24,f-=b,(b=_>>>16&255)===0)O[I++]=65535&_;else{if(!(16&b)){if((64&b)==0){_=y[(65535&_)+(d&(1<<b)-1)];continue e}if(32&b){a.mode=12;break A}s.msg="invalid literal/length code",a.mode=30;break A}N=65535&_,(b&=15)&&(f<b&&(d+=J[g++]<<f,f+=8),N+=d&(1<<b)-1,d>>>=b,f-=b),f<15&&(d+=J[g++]<<f,f+=8,d+=J[g++]<<f,f+=8),_=w[d&S];t:for(;;){if(d>>>=b=_>>>24,f-=b,!(16&(b=_>>>16&255))){if((64&b)==0){_=w[(65535&_)+(d&(1<<b)-1)];continue t}s.msg="invalid distance code",a.mode=30;break A}if(F=65535&_,f<(b&=15)&&(d+=J[g++]<<f,(f+=8)<b&&(d+=J[g++]<<f,f+=8)),C<(F+=d&(1<<b)-1)){s.msg="invalid distance too far back",a.mode=30;break A}if(d>>>=b,f-=b,(b=I-l)<F){if(h<(b=F-b)&&a.sane){s.msg="invalid distance too far back",a.mode=30;break A}if(Y=u,(L=0)===E){if(L+=Q-b,b<N){for(N-=b;O[I++]=u[L++],--b;);L=I-F,Y=O}}else if(E<b){if(L+=Q+E-b,(b-=E)<N){for(N-=b;O[I++]=u[L++],--b;);if(L=0,E<N){for(N-=b=E;O[I++]=u[L++],--b;);L=I-F,Y=O}}}else if(L+=E-b,b<N){for(N-=b;O[I++]=u[L++],--b;);L=I-F,Y=O}for(;2<N;)O[I++]=Y[L++],O[I++]=Y[L++],O[I++]=Y[L++],N-=3;N&&(O[I++]=Y[L++],1<N&&(O[I++]=Y[L++]))}else{for(L=I-F;O[I++]=O[L++],O[I++]=O[L++],O[I++]=O[L++],2<(N-=3););N&&(O[I++]=O[L++],1<N&&(O[I++]=O[L++]))}break}}break}}while(g<c&&I<B);g-=N=f>>3,d&=(1<<(f-=N<<3))-1,s.next_in=g,s.next_out=I,s.avail_in=g<c?c-g+5:5-(g-c),s.avail_out=I<B?B-I+257:257-(I-B),a.hold=d,a.bits=f}},{}],49:[function(i,n,o){var s=i("../utils/common"),r=i("./adler32"),a=i("./crc32"),g=i("./inffast"),c=i("./inftrees"),I=1,l=2,B=0,C=-2,Q=1,h=852,E=592;function u(L){return(L>>>24&255)+(L>>>8&65280)+((65280&L)<<8)+((255&L)<<24)}function d(){this.mode=0,this.last=!1,this.wrap=0,this.havedict=!1,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=null,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=null,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=null,this.distcode=null,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=null,this.lens=new s.Buf16(320),this.work=new s.Buf16(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0}function f(L){var Y;return L&&L.state?(Y=L.state,L.total_in=L.total_out=Y.total=0,L.msg="",Y.wrap&&(L.adler=1&Y.wrap),Y.mode=Q,Y.last=0,Y.havedict=0,Y.dmax=32768,Y.head=null,Y.hold=0,Y.bits=0,Y.lencode=Y.lendyn=new s.Buf32(h),Y.distcode=Y.distdyn=new s.Buf32(E),Y.sane=1,Y.back=-1,B):C}function y(L){var Y;return L&&L.state?((Y=L.state).wsize=0,Y.whave=0,Y.wnext=0,f(L)):C}function w(L,Y){var J,O;return L&&L.state?(O=L.state,Y<0?(J=0,Y=-Y):(J=1+(Y>>4),Y<48&&(Y&=15)),Y&&(Y<8||15<Y)?C:(O.window!==null&&O.wbits!==Y&&(O.window=null),O.wrap=J,O.wbits=Y,y(L))):C}function D(L,Y){var J,O;return L?(O=new d,(L.state=O).window=null,(J=w(L,Y))!==B&&(L.state=null),J):C}var S,_,b=!0;function N(L){if(b){var Y;for(S=new s.Buf32(512),_=new s.Buf32(32),Y=0;Y<144;)L.lens[Y++]=8;for(;Y<256;)L.lens[Y++]=9;for(;Y<280;)L.lens[Y++]=7;for(;Y<288;)L.lens[Y++]=8;for(c(I,L.lens,0,288,S,0,L.work,{bits:9}),Y=0;Y<32;)L.lens[Y++]=5;c(l,L.lens,0,32,_,0,L.work,{bits:5}),b=!1}L.lencode=S,L.lenbits=9,L.distcode=_,L.distbits=5}function F(L,Y,J,O){var Z,X=L.state;return X.window===null&&(X.wsize=1<<X.wbits,X.wnext=0,X.whave=0,X.window=new s.Buf8(X.wsize)),O>=X.wsize?(s.arraySet(X.window,Y,J-X.wsize,X.wsize,0),X.wnext=0,X.whave=X.wsize):(O<(Z=X.wsize-X.wnext)&&(Z=O),s.arraySet(X.window,Y,J-O,Z,X.wnext),(O-=Z)?(s.arraySet(X.window,Y,J-O,O,0),X.wnext=O,X.whave=X.wsize):(X.wnext+=Z,X.wnext===X.wsize&&(X.wnext=0),X.whave<X.wsize&&(X.whave+=Z))),0}o.inflateReset=y,o.inflateReset2=w,o.inflateResetKeep=f,o.inflateInit=function(L){return D(L,15)},o.inflateInit2=D,o.inflate=function(L,Y){var J,O,Z,X,eA,gA,tA,iA,sA,aA,EA,bA,_A,LA,QA,kA,dA,qA,VA,ce,fA,ge,jA,JA,WA=0,vA=new s.Buf8(4),wA=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15];if(!L||!L.state||!L.output||!L.input&&L.avail_in!==0)return C;(J=L.state).mode===12&&(J.mode=13),eA=L.next_out,Z=L.output,tA=L.avail_out,X=L.next_in,O=L.input,gA=L.avail_in,iA=J.hold,sA=J.bits,aA=gA,EA=tA,ge=B;A:for(;;)switch(J.mode){case Q:if(J.wrap===0){J.mode=13;break}for(;sA<16;){if(gA===0)break A;gA--,iA+=O[X++]<<sA,sA+=8}if(2&J.wrap&&iA===35615){vA[J.check=0]=255&iA,vA[1]=iA>>>8&255,J.check=a(J.check,vA,2,0),sA=iA=0,J.mode=2;break}if(J.flags=0,J.head&&(J.head.done=!1),!(1&J.wrap)||(((255&iA)<<8)+(iA>>8))%31){L.msg="incorrect header check",J.mode=30;break}if((15&iA)!=8){L.msg="unknown compression method",J.mode=30;break}if(sA-=4,fA=8+(15&(iA>>>=4)),J.wbits===0)J.wbits=fA;else if(fA>J.wbits){L.msg="invalid window size",J.mode=30;break}J.dmax=1<<fA,L.adler=J.check=1,J.mode=512&iA?10:12,sA=iA=0;break;case 2:for(;sA<16;){if(gA===0)break A;gA--,iA+=O[X++]<<sA,sA+=8}if(J.flags=iA,(255&J.flags)!=8){L.msg="unknown compression method",J.mode=30;break}if(57344&J.flags){L.msg="unknown header flags set",J.mode=30;break}J.head&&(J.head.text=iA>>8&1),512&J.flags&&(vA[0]=255&iA,vA[1]=iA>>>8&255,J.check=a(J.check,vA,2,0)),sA=iA=0,J.mode=3;case 3:for(;sA<32;){if(gA===0)break A;gA--,iA+=O[X++]<<sA,sA+=8}J.head&&(J.head.time=iA),512&J.flags&&(vA[0]=255&iA,vA[1]=iA>>>8&255,vA[2]=iA>>>16&255,vA[3]=iA>>>24&255,J.check=a(J.check,vA,4,0)),sA=iA=0,J.mode=4;case 4:for(;sA<16;){if(gA===0)break A;gA--,iA+=O[X++]<<sA,sA+=8}J.head&&(J.head.xflags=255&iA,J.head.os=iA>>8),512&J.flags&&(vA[0]=255&iA,vA[1]=iA>>>8&255,J.check=a(J.check,vA,2,0)),sA=iA=0,J.mode=5;case 5:if(1024&J.flags){for(;sA<16;){if(gA===0)break A;gA--,iA+=O[X++]<<sA,sA+=8}J.length=iA,J.head&&(J.head.extra_len=iA),512&J.flags&&(vA[0]=255&iA,vA[1]=iA>>>8&255,J.check=a(J.check,vA,2,0)),sA=iA=0}else J.head&&(J.head.extra=null);J.mode=6;case 6:if(1024&J.flags&&(gA<(bA=J.length)&&(bA=gA),bA&&(J.head&&(fA=J.head.extra_len-J.length,J.head.extra||(J.head.extra=new Array(J.head.extra_len)),s.arraySet(J.head.extra,O,X,bA,fA)),512&J.flags&&(J.check=a(J.check,O,bA,X)),gA-=bA,X+=bA,J.length-=bA),J.length))break A;J.length=0,J.mode=7;case 7:if(2048&J.flags){if(gA===0)break A;for(bA=0;fA=O[X+bA++],J.head&&fA&&J.length<65536&&(J.head.name+=String.fromCharCode(fA)),fA&&bA<gA;);if(512&J.flags&&(J.check=a(J.check,O,bA,X)),gA-=bA,X+=bA,fA)break A}else J.head&&(J.head.name=null);J.length=0,J.mode=8;case 8:if(4096&J.flags){if(gA===0)break A;for(bA=0;fA=O[X+bA++],J.head&&fA&&J.length<65536&&(J.head.comment+=String.fromCharCode(fA)),fA&&bA<gA;);if(512&J.flags&&(J.check=a(J.check,O,bA,X)),gA-=bA,X+=bA,fA)break A}else J.head&&(J.head.comment=null);J.mode=9;case 9:if(512&J.flags){for(;sA<16;){if(gA===0)break A;gA--,iA+=O[X++]<<sA,sA+=8}if(iA!==(65535&J.check)){L.msg="header crc mismatch",J.mode=30;break}sA=iA=0}J.head&&(J.head.hcrc=J.flags>>9&1,J.head.done=!0),L.adler=J.check=0,J.mode=12;break;case 10:for(;sA<32;){if(gA===0)break A;gA--,iA+=O[X++]<<sA,sA+=8}L.adler=J.check=u(iA),sA=iA=0,J.mode=11;case 11:if(J.havedict===0)return L.next_out=eA,L.avail_out=tA,L.next_in=X,L.avail_in=gA,J.hold=iA,J.bits=sA,2;L.adler=J.check=1,J.mode=12;case 12:if(Y===5||Y===6)break A;case 13:if(J.last){iA>>>=7&sA,sA-=7&sA,J.mode=27;break}for(;sA<3;){if(gA===0)break A;gA--,iA+=O[X++]<<sA,sA+=8}switch(J.last=1&iA,sA-=1,3&(iA>>>=1)){case 0:J.mode=14;break;case 1:if(N(J),J.mode=20,Y!==6)break;iA>>>=2,sA-=2;break A;case 2:J.mode=17;break;case 3:L.msg="invalid block type",J.mode=30}iA>>>=2,sA-=2;break;case 14:for(iA>>>=7&sA,sA-=7&sA;sA<32;){if(gA===0)break A;gA--,iA+=O[X++]<<sA,sA+=8}if((65535&iA)!=(iA>>>16^65535)){L.msg="invalid stored block lengths",J.mode=30;break}if(J.length=65535&iA,sA=iA=0,J.mode=15,Y===6)break A;case 15:J.mode=16;case 16:if(bA=J.length){if(gA<bA&&(bA=gA),tA<bA&&(bA=tA),bA===0)break A;s.arraySet(Z,O,X,bA,eA),gA-=bA,X+=bA,tA-=bA,eA+=bA,J.length-=bA;break}J.mode=12;break;case 17:for(;sA<14;){if(gA===0)break A;gA--,iA+=O[X++]<<sA,sA+=8}if(J.nlen=257+(31&iA),iA>>>=5,sA-=5,J.ndist=1+(31&iA),iA>>>=5,sA-=5,J.ncode=4+(15&iA),iA>>>=4,sA-=4,286<J.nlen||30<J.ndist){L.msg="too many length or distance symbols",J.mode=30;break}J.have=0,J.mode=18;case 18:for(;J.have<J.ncode;){for(;sA<3;){if(gA===0)break A;gA--,iA+=O[X++]<<sA,sA+=8}J.lens[wA[J.have++]]=7&iA,iA>>>=3,sA-=3}for(;J.have<19;)J.lens[wA[J.have++]]=0;if(J.lencode=J.lendyn,J.lenbits=7,jA={bits:J.lenbits},ge=c(0,J.lens,0,19,J.lencode,0,J.work,jA),J.lenbits=jA.bits,ge){L.msg="invalid code lengths set",J.mode=30;break}J.have=0,J.mode=19;case 19:for(;J.have<J.nlen+J.ndist;){for(;kA=(WA=J.lencode[iA&(1<<J.lenbits)-1])>>>16&255,dA=65535&WA,!((QA=WA>>>24)<=sA);){if(gA===0)break A;gA--,iA+=O[X++]<<sA,sA+=8}if(dA<16)iA>>>=QA,sA-=QA,J.lens[J.have++]=dA;else{if(dA===16){for(JA=QA+2;sA<JA;){if(gA===0)break A;gA--,iA+=O[X++]<<sA,sA+=8}if(iA>>>=QA,sA-=QA,J.have===0){L.msg="invalid bit length repeat",J.mode=30;break}fA=J.lens[J.have-1],bA=3+(3&iA),iA>>>=2,sA-=2}else if(dA===17){for(JA=QA+3;sA<JA;){if(gA===0)break A;gA--,iA+=O[X++]<<sA,sA+=8}sA-=QA,fA=0,bA=3+(7&(iA>>>=QA)),iA>>>=3,sA-=3}else{for(JA=QA+7;sA<JA;){if(gA===0)break A;gA--,iA+=O[X++]<<sA,sA+=8}sA-=QA,fA=0,bA=11+(127&(iA>>>=QA)),iA>>>=7,sA-=7}if(J.have+bA>J.nlen+J.ndist){L.msg="invalid bit length repeat",J.mode=30;break}for(;bA--;)J.lens[J.have++]=fA}}if(J.mode===30)break;if(J.lens[256]===0){L.msg="invalid code -- missing end-of-block",J.mode=30;break}if(J.lenbits=9,jA={bits:J.lenbits},ge=c(I,J.lens,0,J.nlen,J.lencode,0,J.work,jA),J.lenbits=jA.bits,ge){L.msg="invalid literal/lengths set",J.mode=30;break}if(J.distbits=6,J.distcode=J.distdyn,jA={bits:J.distbits},ge=c(l,J.lens,J.nlen,J.ndist,J.distcode,0,J.work,jA),J.distbits=jA.bits,ge){L.msg="invalid distances set",J.mode=30;break}if(J.mode=20,Y===6)break A;case 20:J.mode=21;case 21:if(6<=gA&&258<=tA){L.next_out=eA,L.avail_out=tA,L.next_in=X,L.avail_in=gA,J.hold=iA,J.bits=sA,g(L,EA),eA=L.next_out,Z=L.output,tA=L.avail_out,X=L.next_in,O=L.input,gA=L.avail_in,iA=J.hold,sA=J.bits,J.mode===12&&(J.back=-1);break}for(J.back=0;kA=(WA=J.lencode[iA&(1<<J.lenbits)-1])>>>16&255,dA=65535&WA,!((QA=WA>>>24)<=sA);){if(gA===0)break A;gA--,iA+=O[X++]<<sA,sA+=8}if(kA&&(240&kA)==0){for(qA=QA,VA=kA,ce=dA;kA=(WA=J.lencode[ce+((iA&(1<<qA+VA)-1)>>qA)])>>>16&255,dA=65535&WA,!(qA+(QA=WA>>>24)<=sA);){if(gA===0)break A;gA--,iA+=O[X++]<<sA,sA+=8}iA>>>=qA,sA-=qA,J.back+=qA}if(iA>>>=QA,sA-=QA,J.back+=QA,J.length=dA,kA===0){J.mode=26;break}if(32&kA){J.back=-1,J.mode=12;break}if(64&kA){L.msg="invalid literal/length code",J.mode=30;break}J.extra=15&kA,J.mode=22;case 22:if(J.extra){for(JA=J.extra;sA<JA;){if(gA===0)break A;gA--,iA+=O[X++]<<sA,sA+=8}J.length+=iA&(1<<J.extra)-1,iA>>>=J.extra,sA-=J.extra,J.back+=J.extra}J.was=J.length,J.mode=23;case 23:for(;kA=(WA=J.distcode[iA&(1<<J.distbits)-1])>>>16&255,dA=65535&WA,!((QA=WA>>>24)<=sA);){if(gA===0)break A;gA--,iA+=O[X++]<<sA,sA+=8}if((240&kA)==0){for(qA=QA,VA=kA,ce=dA;kA=(WA=J.distcode[ce+((iA&(1<<qA+VA)-1)>>qA)])>>>16&255,dA=65535&WA,!(qA+(QA=WA>>>24)<=sA);){if(gA===0)break A;gA--,iA+=O[X++]<<sA,sA+=8}iA>>>=qA,sA-=qA,J.back+=qA}if(iA>>>=QA,sA-=QA,J.back+=QA,64&kA){L.msg="invalid distance code",J.mode=30;break}J.offset=dA,J.extra=15&kA,J.mode=24;case 24:if(J.extra){for(JA=J.extra;sA<JA;){if(gA===0)break A;gA--,iA+=O[X++]<<sA,sA+=8}J.offset+=iA&(1<<J.extra)-1,iA>>>=J.extra,sA-=J.extra,J.back+=J.extra}if(J.offset>J.dmax){L.msg="invalid distance too far back",J.mode=30;break}J.mode=25;case 25:if(tA===0)break A;if(bA=EA-tA,J.offset>bA){if((bA=J.offset-bA)>J.whave&&J.sane){L.msg="invalid distance too far back",J.mode=30;break}_A=bA>J.wnext?(bA-=J.wnext,J.wsize-bA):J.wnext-bA,bA>J.length&&(bA=J.length),LA=J.window}else LA=Z,_A=eA-J.offset,bA=J.length;for(tA<bA&&(bA=tA),tA-=bA,J.length-=bA;Z[eA++]=LA[_A++],--bA;);J.length===0&&(J.mode=21);break;case 26:if(tA===0)break A;Z[eA++]=J.length,tA--,J.mode=21;break;case 27:if(J.wrap){for(;sA<32;){if(gA===0)break A;gA--,iA|=O[X++]<<sA,sA+=8}if(EA-=tA,L.total_out+=EA,J.total+=EA,EA&&(L.adler=J.check=J.flags?a(J.check,Z,EA,eA-EA):r(J.check,Z,EA,eA-EA)),EA=tA,(J.flags?iA:u(iA))!==J.check){L.msg="incorrect data check",J.mode=30;break}sA=iA=0}J.mode=28;case 28:if(J.wrap&&J.flags){for(;sA<32;){if(gA===0)break A;gA--,iA+=O[X++]<<sA,sA+=8}if(iA!==(4294967295&J.total)){L.msg="incorrect length check",J.mode=30;break}sA=iA=0}J.mode=29;case 29:ge=1;break A;case 30:ge=-3;break A;case 31:return-4;default:return C}return L.next_out=eA,L.avail_out=tA,L.next_in=X,L.avail_in=gA,J.hold=iA,J.bits=sA,(J.wsize||EA!==L.avail_out&&J.mode<30&&(J.mode<27||Y!==4))&&F(L,L.output,L.next_out,EA-L.avail_out)?(J.mode=31,-4):(aA-=L.avail_in,EA-=L.avail_out,L.total_in+=aA,L.total_out+=EA,J.total+=EA,J.wrap&&EA&&(L.adler=J.check=J.flags?a(J.check,Z,EA,L.next_out-EA):r(J.check,Z,EA,L.next_out-EA)),L.data_type=J.bits+(J.last?64:0)+(J.mode===12?128:0)+(J.mode===20||J.mode===15?256:0),(aA==0&&EA===0||Y===4)&&ge===B&&(ge=-5),ge)},o.inflateEnd=function(L){if(!L||!L.state)return C;var Y=L.state;return Y.window&&(Y.window=null),L.state=null,B},o.inflateGetHeader=function(L,Y){var J;return L&&L.state?(2&(J=L.state).wrap)==0?C:((J.head=Y).done=!1,B):C},o.inflateSetDictionary=function(L,Y){var J,O=Y.length;return L&&L.state?(J=L.state).wrap!==0&&J.mode!==11?C:J.mode===11&&r(1,Y,O,0)!==J.check?-3:F(L,Y,O,O)?(J.mode=31,-4):(J.havedict=1,B):C},o.inflateInfo="pako inflate (from Nodeca project)"},{"../utils/common":41,"./adler32":43,"./crc32":45,"./inffast":48,"./inftrees":50}],50:[function(i,n,o){var s=i("../utils/common"),r=[3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258,0,0],a=[16,16,16,16,16,16,16,16,17,17,17,17,18,18,18,18,19,19,19,19,20,20,20,20,21,21,21,21,16,72,78],g=[1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577,0,0],c=[16,16,16,16,17,17,18,18,19,19,20,20,21,21,22,22,23,23,24,24,25,25,26,26,27,27,28,28,29,29,64,64];n.exports=function(I,l,B,C,Q,h,E,u){var d,f,y,w,D,S,_,b,N,F=u.bits,L=0,Y=0,J=0,O=0,Z=0,X=0,eA=0,gA=0,tA=0,iA=0,sA=null,aA=0,EA=new s.Buf16(16),bA=new s.Buf16(16),_A=null,LA=0;for(L=0;L<=15;L++)EA[L]=0;for(Y=0;Y<C;Y++)EA[l[B+Y]]++;for(Z=F,O=15;1<=O&&EA[O]===0;O--);if(O<Z&&(Z=O),O===0)return Q[h++]=20971520,Q[h++]=20971520,u.bits=1,0;for(J=1;J<O&&EA[J]===0;J++);for(Z<J&&(Z=J),L=gA=1;L<=15;L++)if(gA<<=1,(gA-=EA[L])<0)return-1;if(0<gA&&(I===0||O!==1))return-1;for(bA[1]=0,L=1;L<15;L++)bA[L+1]=bA[L]+EA[L];for(Y=0;Y<C;Y++)l[B+Y]!==0&&(E[bA[l[B+Y]]++]=Y);if(S=I===0?(sA=_A=E,19):I===1?(sA=r,aA-=257,_A=a,LA-=257,256):(sA=g,_A=c,-1),L=J,D=h,eA=Y=iA=0,y=-1,w=(tA=1<<(X=Z))-1,I===1&&852<tA||I===2&&592<tA)return 1;for(;;){for(_=L-eA,N=E[Y]<S?(b=0,E[Y]):E[Y]>S?(b=_A[LA+E[Y]],sA[aA+E[Y]]):(b=96,0),d=1<<L-eA,J=f=1<<X;Q[D+(iA>>eA)+(f-=d)]=_<<24|b<<16|N|0,f!==0;);for(d=1<<L-1;iA&d;)d>>=1;if(d!==0?(iA&=d-1,iA+=d):iA=0,Y++,--EA[L]==0){if(L===O)break;L=l[B+E[Y]]}if(Z<L&&(iA&w)!==y){for(eA===0&&(eA=Z),D+=J,gA=1<<(X=L-eA);X+eA<O&&!((gA-=EA[X+eA])<=0);)X++,gA<<=1;if(tA+=1<<X,I===1&&852<tA||I===2&&592<tA)return 1;Q[y=iA&w]=Z<<24|X<<16|D-h|0}}return iA!==0&&(Q[D+iA]=L-eA<<24|64<<16|0),u.bits=Z,0}},{"../utils/common":41}],51:[function(i,n,o){n.exports={2:"need dictionary",1:"stream end",0:"","-1":"file error","-2":"stream error","-3":"data error","-4":"insufficient memory","-5":"buffer error","-6":"incompatible version"}},{}],52:[function(i,n,o){var s=i("../utils/common"),r=0,a=1;function g(WA){for(var vA=WA.length;0<=--vA;)WA[vA]=0}var c=0,I=29,l=256,B=l+1+I,C=30,Q=19,h=2*B+1,E=15,u=16,d=7,f=256,y=16,w=17,D=18,S=[0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0],_=[0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13],b=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7],N=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],F=new Array(2*(B+2));g(F);var L=new Array(2*C);g(L);var Y=new Array(512);g(Y);var J=new Array(256);g(J);var O=new Array(I);g(O);var Z,X,eA,gA=new Array(C);function tA(WA,vA,wA,RA,MA){this.static_tree=WA,this.extra_bits=vA,this.extra_base=wA,this.elems=RA,this.max_length=MA,this.has_stree=WA&&WA.length}function iA(WA,vA){this.dyn_tree=WA,this.max_code=0,this.stat_desc=vA}function sA(WA){return WA<256?Y[WA]:Y[256+(WA>>>7)]}function aA(WA,vA){WA.pending_buf[WA.pending++]=255&vA,WA.pending_buf[WA.pending++]=vA>>>8&255}function EA(WA,vA,wA){WA.bi_valid>u-wA?(WA.bi_buf|=vA<<WA.bi_valid&65535,aA(WA,WA.bi_buf),WA.bi_buf=vA>>u-WA.bi_valid,WA.bi_valid+=wA-u):(WA.bi_buf|=vA<<WA.bi_valid&65535,WA.bi_valid+=wA)}function bA(WA,vA,wA){EA(WA,wA[2*vA],wA[2*vA+1])}function _A(WA,vA){for(var wA=0;wA|=1&WA,WA>>>=1,wA<<=1,0<--vA;);return wA>>>1}function LA(WA,vA,wA){var RA,MA,KA=new Array(E+1),ZA=0;for(RA=1;RA<=E;RA++)KA[RA]=ZA=ZA+wA[RA-1]<<1;for(MA=0;MA<=vA;MA++){var ne=WA[2*MA+1];ne!==0&&(WA[2*MA]=_A(KA[ne]++,ne))}}function QA(WA){var vA;for(vA=0;vA<B;vA++)WA.dyn_ltree[2*vA]=0;for(vA=0;vA<C;vA++)WA.dyn_dtree[2*vA]=0;for(vA=0;vA<Q;vA++)WA.bl_tree[2*vA]=0;WA.dyn_ltree[2*f]=1,WA.opt_len=WA.static_len=0,WA.last_lit=WA.matches=0}function kA(WA){8<WA.bi_valid?aA(WA,WA.bi_buf):0<WA.bi_valid&&(WA.pending_buf[WA.pending++]=WA.bi_buf),WA.bi_buf=0,WA.bi_valid=0}function dA(WA,vA,wA,RA){var MA=2*vA,KA=2*wA;return WA[MA]<WA[KA]||WA[MA]===WA[KA]&&RA[vA]<=RA[wA]}function qA(WA,vA,wA){for(var RA=WA.heap[wA],MA=wA<<1;MA<=WA.heap_len&&(MA<WA.heap_len&&dA(vA,WA.heap[MA+1],WA.heap[MA],WA.depth)&&MA++,!dA(vA,RA,WA.heap[MA],WA.depth));)WA.heap[wA]=WA.heap[MA],wA=MA,MA<<=1;WA.heap[wA]=RA}function VA(WA,vA,wA){var RA,MA,KA,ZA,ne=0;if(WA.last_lit!==0)for(;RA=WA.pending_buf[WA.d_buf+2*ne]<<8|WA.pending_buf[WA.d_buf+2*ne+1],MA=WA.pending_buf[WA.l_buf+ne],ne++,RA===0?bA(WA,MA,vA):(bA(WA,(KA=J[MA])+l+1,vA),(ZA=S[KA])!==0&&EA(WA,MA-=O[KA],ZA),bA(WA,KA=sA(--RA),wA),(ZA=_[KA])!==0&&EA(WA,RA-=gA[KA],ZA)),ne<WA.last_lit;);bA(WA,f,vA)}function ce(WA,vA){var wA,RA,MA,KA=vA.dyn_tree,ZA=vA.stat_desc.static_tree,ne=vA.stat_desc.has_stree,SA=vA.stat_desc.elems,CA=-1;for(WA.heap_len=0,WA.heap_max=h,wA=0;wA<SA;wA++)KA[2*wA]!==0?(WA.heap[++WA.heap_len]=CA=wA,WA.depth[wA]=0):KA[2*wA+1]=0;for(;WA.heap_len<2;)KA[2*(MA=WA.heap[++WA.heap_len]=CA<2?++CA:0)]=1,WA.depth[MA]=0,WA.opt_len--,ne&&(WA.static_len-=ZA[2*MA+1]);for(vA.max_code=CA,wA=WA.heap_len>>1;1<=wA;wA--)qA(WA,KA,wA);for(MA=SA;wA=WA.heap[1],WA.heap[1]=WA.heap[WA.heap_len--],qA(WA,KA,1),RA=WA.heap[1],WA.heap[--WA.heap_max]=wA,WA.heap[--WA.heap_max]=RA,KA[2*MA]=KA[2*wA]+KA[2*RA],WA.depth[MA]=(WA.depth[wA]>=WA.depth[RA]?WA.depth[wA]:WA.depth[RA])+1,KA[2*wA+1]=KA[2*RA+1]=MA,WA.heap[1]=MA++,qA(WA,KA,1),2<=WA.heap_len;);WA.heap[--WA.heap_max]=WA.heap[1],(function(uA,TA){var re,Qe,me,_e,ke,Pe,lt=TA.dyn_tree,hA=TA.max_code,oe=TA.stat_desc.static_tree,Be=TA.stat_desc.has_stree,ye=TA.stat_desc.extra_bits,Le=TA.stat_desc.extra_base,Te=TA.stat_desc.max_length,nt=0;for(_e=0;_e<=E;_e++)uA.bl_count[_e]=0;for(lt[2*uA.heap[uA.heap_max]+1]=0,re=uA.heap_max+1;re<h;re++)Te<(_e=lt[2*lt[2*(Qe=uA.heap[re])+1]+1]+1)&&(_e=Te,nt++),lt[2*Qe+1]=_e,hA<Qe||(uA.bl_count[_e]++,ke=0,Le<=Qe&&(ke=ye[Qe-Le]),Pe=lt[2*Qe],uA.opt_len+=Pe*(_e+ke),Be&&(uA.static_len+=Pe*(oe[2*Qe+1]+ke)));if(nt!==0){do{for(_e=Te-1;uA.bl_count[_e]===0;)_e--;uA.bl_count[_e]--,uA.bl_count[_e+1]+=2,uA.bl_count[Te]--,nt-=2}while(0<nt);for(_e=Te;_e!==0;_e--)for(Qe=uA.bl_count[_e];Qe!==0;)hA<(me=uA.heap[--re])||(lt[2*me+1]!==_e&&(uA.opt_len+=(_e-lt[2*me+1])*lt[2*me],lt[2*me+1]=_e),Qe--)}})(WA,vA),LA(KA,CA,WA.bl_count)}function fA(WA,vA,wA){var RA,MA,KA=-1,ZA=vA[1],ne=0,SA=7,CA=4;for(ZA===0&&(SA=138,CA=3),vA[2*(wA+1)+1]=65535,RA=0;RA<=wA;RA++)MA=ZA,ZA=vA[2*(RA+1)+1],++ne<SA&&MA===ZA||(ne<CA?WA.bl_tree[2*MA]+=ne:MA!==0?(MA!==KA&&WA.bl_tree[2*MA]++,WA.bl_tree[2*y]++):ne<=10?WA.bl_tree[2*w]++:WA.bl_tree[2*D]++,KA=MA,CA=(ne=0)===ZA?(SA=138,3):MA===ZA?(SA=6,3):(SA=7,4))}function ge(WA,vA,wA){var RA,MA,KA=-1,ZA=vA[1],ne=0,SA=7,CA=4;for(ZA===0&&(SA=138,CA=3),RA=0;RA<=wA;RA++)if(MA=ZA,ZA=vA[2*(RA+1)+1],!(++ne<SA&&MA===ZA)){if(ne<CA)for(;bA(WA,MA,WA.bl_tree),--ne!=0;);else MA!==0?(MA!==KA&&(bA(WA,MA,WA.bl_tree),ne--),bA(WA,y,WA.bl_tree),EA(WA,ne-3,2)):ne<=10?(bA(WA,w,WA.bl_tree),EA(WA,ne-3,3)):(bA(WA,D,WA.bl_tree),EA(WA,ne-11,7));KA=MA,CA=(ne=0)===ZA?(SA=138,3):MA===ZA?(SA=6,3):(SA=7,4)}}g(gA);var jA=!1;function JA(WA,vA,wA,RA){EA(WA,(c<<1)+(RA?1:0),3),(function(MA,KA,ZA,ne){kA(MA),aA(MA,ZA),aA(MA,~ZA),s.arraySet(MA.pending_buf,MA.window,KA,ZA,MA.pending),MA.pending+=ZA})(WA,vA,wA)}o._tr_init=function(WA){jA||((function(){var vA,wA,RA,MA,KA,ZA=new Array(E+1);for(MA=RA=0;MA<I-1;MA++)for(O[MA]=RA,vA=0;vA<1<<S[MA];vA++)J[RA++]=MA;for(J[RA-1]=MA,MA=KA=0;MA<16;MA++)for(gA[MA]=KA,vA=0;vA<1<<_[MA];vA++)Y[KA++]=MA;for(KA>>=7;MA<C;MA++)for(gA[MA]=KA<<7,vA=0;vA<1<<_[MA]-7;vA++)Y[256+KA++]=MA;for(wA=0;wA<=E;wA++)ZA[wA]=0;for(vA=0;vA<=143;)F[2*vA+1]=8,vA++,ZA[8]++;for(;vA<=255;)F[2*vA+1]=9,vA++,ZA[9]++;for(;vA<=279;)F[2*vA+1]=7,vA++,ZA[7]++;for(;vA<=287;)F[2*vA+1]=8,vA++,ZA[8]++;for(LA(F,B+1,ZA),vA=0;vA<C;vA++)L[2*vA+1]=5,L[2*vA]=_A(vA,5);Z=new tA(F,S,l+1,B,E),X=new tA(L,_,0,C,E),eA=new tA(new Array(0),b,0,Q,d)})(),jA=!0),WA.l_desc=new iA(WA.dyn_ltree,Z),WA.d_desc=new iA(WA.dyn_dtree,X),WA.bl_desc=new iA(WA.bl_tree,eA),WA.bi_buf=0,WA.bi_valid=0,QA(WA)},o._tr_stored_block=JA,o._tr_flush_block=function(WA,vA,wA,RA){var MA,KA,ZA=0;0<WA.level?(WA.strm.data_type===2&&(WA.strm.data_type=(function(ne){var SA,CA=4093624447;for(SA=0;SA<=31;SA++,CA>>>=1)if(1&CA&&ne.dyn_ltree[2*SA]!==0)return r;if(ne.dyn_ltree[18]!==0||ne.dyn_ltree[20]!==0||ne.dyn_ltree[26]!==0)return a;for(SA=32;SA<l;SA++)if(ne.dyn_ltree[2*SA]!==0)return a;return r})(WA)),ce(WA,WA.l_desc),ce(WA,WA.d_desc),ZA=(function(ne){var SA;for(fA(ne,ne.dyn_ltree,ne.l_desc.max_code),fA(ne,ne.dyn_dtree,ne.d_desc.max_code),ce(ne,ne.bl_desc),SA=Q-1;3<=SA&&ne.bl_tree[2*N[SA]+1]===0;SA--);return ne.opt_len+=3*(SA+1)+5+5+4,SA})(WA),MA=WA.opt_len+3+7>>>3,(KA=WA.static_len+3+7>>>3)<=MA&&(MA=KA)):MA=KA=wA+5,wA+4<=MA&&vA!==-1?JA(WA,vA,wA,RA):WA.strategy===4||KA===MA?(EA(WA,2+(RA?1:0),3),VA(WA,F,L)):(EA(WA,4+(RA?1:0),3),(function(ne,SA,CA,uA){var TA;for(EA(ne,SA-257,5),EA(ne,CA-1,5),EA(ne,uA-4,4),TA=0;TA<uA;TA++)EA(ne,ne.bl_tree[2*N[TA]+1],3);ge(ne,ne.dyn_ltree,SA-1),ge(ne,ne.dyn_dtree,CA-1)})(WA,WA.l_desc.max_code+1,WA.d_desc.max_code+1,ZA+1),VA(WA,WA.dyn_ltree,WA.dyn_dtree)),QA(WA),RA&&kA(WA)},o._tr_tally=function(WA,vA,wA){return WA.pending_buf[WA.d_buf+2*WA.last_lit]=vA>>>8&255,WA.pending_buf[WA.d_buf+2*WA.last_lit+1]=255&vA,WA.pending_buf[WA.l_buf+WA.last_lit]=255&wA,WA.last_lit++,vA===0?WA.dyn_ltree[2*wA]++:(WA.matches++,vA--,WA.dyn_ltree[2*(J[wA]+l+1)]++,WA.dyn_dtree[2*sA(vA)]++),WA.last_lit===WA.lit_bufsize-1},o._tr_align=function(WA){EA(WA,2,3),bA(WA,f,F),(function(vA){vA.bi_valid===16?(aA(vA,vA.bi_buf),vA.bi_buf=0,vA.bi_valid=0):8<=vA.bi_valid&&(vA.pending_buf[vA.pending++]=255&vA.bi_buf,vA.bi_buf>>=8,vA.bi_valid-=8)})(WA)}},{"../utils/common":41}],53:[function(i,n,o){n.exports=function(){this.input=null,this.next_in=0,this.avail_in=0,this.total_in=0,this.output=null,this.next_out=0,this.avail_out=0,this.total_out=0,this.msg="",this.state=null,this.data_type=2,this.adler=0}},{}],54:[function(i,n,o){(function(s){(function(r,a){if(!r.setImmediate){var g,c,I,l,B=1,C={},Q=!1,h=r.document,E=Object.getPrototypeOf&&Object.getPrototypeOf(r);E=E&&E.setTimeout?E:r,g={}.toString.call(r.process)==="[object process]"?function(y){e.nextTick(function(){d(y)})}:(function(){if(r.postMessage&&!r.importScripts){var y=!0,w=r.onmessage;return r.onmessage=function(){y=!1},r.postMessage("","*"),r.onmessage=w,y}})()?(l="setImmediate$"+Math.random()+"$",r.addEventListener?r.addEventListener("message",f,!1):r.attachEvent("onmessage",f),function(y){r.postMessage(l+y,"*")}):r.MessageChannel?((I=new MessageChannel).port1.onmessage=function(y){d(y.data)},function(y){I.port2.postMessage(y)}):h&&"onreadystatechange"in h.createElement("script")?(c=h.documentElement,function(y){var w=h.createElement("script");w.onreadystatechange=function(){d(y),w.onreadystatechange=null,c.removeChild(w),w=null},c.appendChild(w)}):function(y){setTimeout(d,0,y)},E.setImmediate=function(y){typeof y!="function"&&(y=new Function(""+y));for(var w=new Array(arguments.length-1),D=0;D<w.length;D++)w[D]=arguments[D+1];var S={callback:y,args:w};return C[B]=S,g(B),B++},E.clearImmediate=u}function u(y){delete C[y]}function d(y){if(Q)setTimeout(d,0,y);else{var w=C[y];if(w){Q=!0;try{(function(D){var S=D.callback,_=D.args;switch(_.length){case 0:S();break;case 1:S(_[0]);break;case 2:S(_[0],_[1]);break;case 3:S(_[0],_[1],_[2]);break;default:S.apply(a,_)}})(w)}finally{u(y),Q=!1}}}}function f(y){y.source===r&&typeof y.data=="string"&&y.data.indexOf(l)===0&&d(+y.data.slice(l.length))}})(typeof self>"u"?s===void 0?this:s:self)}).call(this,typeof cq<"u"?cq:typeof self<"u"?self:typeof window<"u"?window:{})},{}]},{},[10])(10)})})(swA)),swA.exports}var Msi=Fsi();const rwA=N0(Msi);var awA,Mue;function Rsi(){return Mue||(Mue=1,awA=function(t,A){A||(A={}),typeof A=="function"&&(A={cmp:A});var e=typeof A.cycles=="boolean"?A.cycles:!1,i=A.cmp&&(function(o){return function(s){return function(r,a){var g={key:r,value:s[r]},c={key:a,value:s[a]};return o(g,c)}}})(A.cmp),n=[];return(function o(s){if(s&&s.toJSON&&typeof s.toJSON=="function"&&(s=s.toJSON()),s!==void 0){if(typeof s=="number")return isFinite(s)?""+s:"null";if(typeof s!="object")return JSON.stringify(s);var r,a;if(Array.isArray(s)){for(a="[",r=0;r<s.length;r++)r&&(a+=","),a+=o(s[r])||"null";return a+"]"}if(s===null)return"null";if(n.indexOf(s)!==-1){if(e)return JSON.stringify("__cycle__");throw new TypeError("Converting circular structure to JSON")}var g=n.push(s)-1,c=Object.keys(s).sort(i&&i(s));for(a="",r=0;r<c.length;r++){var I=c[r],l=o(s[I]);l&&(a&&(a+=","),a+=JSON.stringify(I)+":"+l)}return n.splice(g,1),"{"+a+"}"}})(t)}),awA}var Nsi=Rsi();const Gsi=N0(Nsi);var Rue={0:"M0.4544564813877358 0L0.2723441540828736 0.03592830447352719L0.1086847233315459 0.14528754990019965L0.020630545837255005 0.3040632652221331L0 0.5395277421960205L0.049259221760993496 0.7369487828466779L0.18080513776237842 0.9005494166306564L0.37036887043974215 0.9872116270037247L0.5864663759301132 1L0.8148695622827444 0.9332890276148733L0.9326583645506394 0.8113052246023419L1 0.4031281830668562L0.833288960385582 0.09886798567812842L0.6801767918233781 0.02483708485091681L0.4544564813877358 0",1:"M 0.198 0.272 L 0.537 0 L 0.54 1",2:"M0.069593147751606 0.19461498231706575L0.1039380353319058 0.1224291500164194L0.20543361884368308 0.05510832064153169L0.3717712794432549 0.009452970962689482L0.4785344452623127 0L0.663238590738758 0.008714098643339864L0.8017933618843684 0.04769189395915288L0.8775637379550322 0.10746757678258442L0.9047778372591005 0.17693069668193287L0.9029710920770878 0.2231347105796246L0.8704496788008566 0.30047744598157516L0.7292906538577354 0.4508486051631194L0.3737955032119913 0.7369006417749693L0 1L1 1",3:"M0.03917438899874637 0.19855364635107545L0.15510940508963084 0.06745632622133718L0.37598645522339846 0L0.8486391893813088 0.0652271323161611L0.9782182415054349 0.21747394183735683L0.9213133780517754 0.3547560290117714L0.6504271515903481 0.4543436297681271L0.22975249764129613 0.48476611625264143L0.7659038682744629 0.5411919558122493L0.9258712987734741 0.6203185665660985L1 0.7458360609169667L0.8938813281118737 0.9059190913045964L0.6166890258875837 1L0.261528440153542 0.9874861530507921L0 0.8837289530851273",4:"M0.7328897338403042 0L0 0.6684672518568535L1 0.6684672518568535M0.7243346007604563 0.4530722484807562L0.7243346007604563 1",5:"M 0 0 L 0 0.4973 L 0.4262 0.4319 L 0.7305 0.4565 L 0.8516 0.5009 L 0.9357 0.5639 L 1 0.7356 L 0.9696 0.8248 L 0.8898 0.895 L 0.733 0.9602 L 0.5518 0.9945 L 0.3814 1 L 0.2379 0.9821 L 0.1219 0.947 L 0 0.8748 M 0 0 L 1 0",6:"M0.6964601700926856 0L0.3639239026215478 0.0743562375769351L0.1415931962925719 0.21735490179786915L0.009977939399608712 0.46336322325406004L0.00029622007592593224 0.7083131475173043L0.09408885043224748 0.8746809149767036L0.3379247445101846 0.9876686500961888L0.7109203869569624 1L0.9260852957913362 0.9103558029693921L1 0.7716571969091733L0.9824294723385016 0.6390635485705886L0.7446504992867332 0.4733643097729175L0.31028858071607296 0.47578021640899115L0.1208702146816024 0.5481452483973847L0 0.6616669755788906",7:"M0 0L1 0L0.9246479649697582 0.030539772727272752L0.8850302419354837 0.05075757575757579L0.7922946068548385 0.11079545454545457L0.7419268208165322 0.15213068181818185L0.6907258064516127 0.20202020202020204L0.6400666267641127 0.26122159090909086L0.5913243447580644 0.33049242424242414L0.5458740234374998 0.4105902777777778L0.5050907258064514 0.5022727272727272L0.4703495148689514 0.6062973484848484L0.43257456133442534 0.787133049242424L0.41612903225806447 1",8:"M0.5143001078924863 0L0.16007477667923162 0.10731570786949331L0.14924628550868277 0.3146018498698755L0.2939585848842112 0.41617921794558677L0.8648302624811545 0.5385163833653317L1 0.7775820770511038L0.8180842915260376 0.9505845566922285L0.41968938540525413 1L0.08062381919779889 0.882831681184498L0 0.6936376947135333L0.17150171673893433 0.5188652309607817L0.6529263782780712 0.4242818653203618L0.8650205888491803 0.29644027376796367L0.8702067371119496 0.09910067291661573L0.5143001078924863 0",9:"M1 0.25379591792994305L0.9514789771111742 0.11679361536614272L0.8702482473521467 0.05711741614054847L0.7327445265851579 0.015213872471965633L0.525248180711544 0L0.3292056884418538 0.012928195113745608L0.15997632037247655 0.058762870026191856L0.05266940041228321 0.12882439350476L0 0.2562067822770946L0.11316462894512366 0.4121335905917837L0.2403060136479954 0.4603365890068938L0.4097241967586011 0.4745978388276783L0.8642414300184816 0.420815170259988L0.9732054796346318 0.34537434075898393L1 0.25379591792994305M0.9647426784191072 0.35488595400360495L0.4756895081034974 1",A:"M0 1L0.4808333333333333 0L1 1M0.24250000000000002 0.6099439775910365L0.7341666666666666 0.6099439775910365",B:"M0 1L0 0.0117369978777208L0.30665717153513444 0L0.5874522807082946 0.03451403469442413L0.7766202217193218 0.15033936404895643L0.7471969743588041 0.31967962568332936L0.5246013359741988 0.4102978954282461L0.04378745314885416 0.44918617613783574L0.5112949594180156 0.469692928091109L0.8540266515643348 0.5552749498651879L1 0.6868463175009967L0.9880091196159324 0.8570018204672155L0.922301719975498 0.9321708046604659L0.7584266951758925 0.9932594737131338L0 1",C:"M1 0.23038928858890784L0.9328355511865092 0.12426412616785204L0.8096380839483327 0.04912601676267708L0.5763225801788256 0L0.4039037709527492 0.015028068281399815L0.2519579390951737 0.06533979308999706L0.10359458463139784 0.18146243506591617L0 0.4862728453971315L0.08129580872733055 0.792689266886982L0.20257034847159672 0.9160822255736587L0.3286572892798542 0.9738230826074175L0.5742878414421707 1L0.7883510303801312 0.9665431511195721L0.946851033994232 0.8689071500976585L1 0.7311049027121912",D:"M0 1L0.015604366822624637 0.020770988281483303L0.22564758265176144 0L0.3865476147957666 0.0024153386496795644L0.6479126635475078 0.051745644338731314L0.841191887805517 0.15827717679529366L0.9517008345536152 0.30172260586872185L0.9957536578687336 0.4504541551987709L1 0.5624359222498485L0.9798483279164735 0.6584121775234548L0.9386273319285215 0.7395945263504481L0.806292129480815 0.8624239259880274L0.6296239151398265 0.9406169638094516L0.3397492767598845 0.9954164354263132L0 1",E:"M0 0L0 1M0 0L1 0M0 0.5L0.7 0.5M0 1L1 1",F:"M0 0L0 1M0.011363636363636364 0.006802721088435374L1 0.006802721088435374M0.011363636363636364 0.4965986394557823L0.8409090909090909 0.4965986394557823",G:"M0.902666857540557 0.03860785012651126L0.6504261864675637 0L0.3838947267237336 0.015442305268228053L0.21293332876776194 0.07706794377239819L0.07799659974941617 0.1994951236187481L0 0.46380381528937314L0.04159964421546915 0.7502491408002389L0.13176692977834842 0.8535497868383203L0.2709176262273927 0.936767572377719L0.4386472596876406 0.9891638569283179L0.6145513562841309 1L0.7782254421419019 0.9585373611026471L0.9092650433859927 0.8540372997461425L1 0.5556012645283437L0.5583959277303046 0.55491741080559",H:"M0 0L0 1M0 0.4788732394366197L0.989010989010989 0.4788732394366197M1 0L1 1",I:"M0.5 0L0.5 1",J:"M0.9976457238788704 0L1 0.7396412315872798L0.9773931362096968 0.8322033314977973L0.9345115952458736 0.882296255506608L0.8743862896259549 0.9221331222466961L0.8024024079884948 0.9526431718061675L0.6443996712151668 0.9893997797356828L0.5035848940343224 1L0.3127211130319937 0.9877004749449337L0.17201910858386513 0.9539509911894274L0.10357419806379677 0.9212555066079295L0.053656568662899015 0.8816079295154184L0.020759483663648916 0.8360407488986785L0.003376206348523566 0.7855864537444934L0 0.7312775330396476",K:"M0 0L0 1M0.8787878787878788 0.06666666666666667L0 0.6148148148148148M0.3333333333333333 0.45925925925925926L1 0.9777777777777777",L:"M0 0L0 1L1 1",M:"M0 1L0 0L0.5 0.6512L1 0L1 1",N:"M0 1L0 0L1 1L0.9803729146221786 0",O:"M0.4718499217948183 1L0.2896765846490613 0.9606979309189402L0.12315162147934663 0.8411184486080473L0 0.4352399966492615L0.11730398524516283 0.13145645436014852L0.2612197451988078 0.04493357858878059L0.5104071592772554 0L0.7450113425917159 0.05393013710105273L0.882367950645524 0.15242300282020502L1 0.5224527406249126L0.9414597290654386 0.7560662329321755L0.8371289514446183 0.8910800547287298L0.6518259868433511 0.9830452628933628L0.4718499217948183 1",P:"M0 1L0 0.018871774228013626L0.29609603495819875 0L0.5609840637427541 0.011794858892508529L0.7332142696692472 0.04353904702296349L0.8102258645858864 0.0691965055027166L0.9330504315465442 0.14445061754775845L0.9876391714147118 0.22527816445836535L1 0.3434414070631638L0.9510549958116356 0.41772808046663146L0.8746646891596713 0.45879131862541683L0.7528523813396283 0.49171525113425024L0.5766919939969619 0.5153253033973054L0.33725744877712827 0.5284469008187558L0.025622667325582785 0.529905468802775",Q:"M0.4618887943546369 0.9755918167206952L0.28356128136544534 0.9372490397450218L0.12055179272160406 0.8205882753548176L0 0.4246165790405623L0.1148276047430244 0.12824784112887844L0.25570518844754375 0.043836831567190586L0.49963205786237674 0L0.7292835601228574 0.0526138004304122L0.8637404608452104 0.14870263423138746L0.9788892040030622 0.5097006183769648L0.9215847647858059 0.7376120297474734L0.8194564929275405 0.869330409436378L0.6380654214095985 0.9590509139448092L0.4618887943546369 0.9755918167206952M0.5824181120212351 0.6861805006946525L1 1",R:"M0 0.9928375167236815L0 0.02590227442068435L0.3611517274211098 0L0.6146286724700761 0.008660554424468435L0.7675462459194776 0.035269459580494614L0.831839975516866 0.056961676692569484L0.8847592491838954 0.08519560521497332L0.9238557535364527 0.120683646438422L0.9583303225312839 0.21691797435320384L0.955092470586235 0.3022616904894429L0.9198097669001631 0.3640573439322699L0.8564862239866702 0.40639258627024005L0.7691258543593579 0.43335506909190874L0.601775027203482 0.4539166070813109L0.023939064200217658 0.46997623755243123M0.5038084874863982 0.5108023922274467L1 1",S:"M0.8886929689221953 0.15146982162688968L0.7276173683050475 0.013780286031594946L0.34582323121005076 0L0.1318235250900008 0.09920162734298861L0.0444543935052531 0.2811287071349243L0.08064065829108809 0.3709571405906485L0.21603115127470426 0.4485505768228281L0.7525409135992945 0.5111160926769565L0.9330263665417677 0.5850732219351329L1 0.7129938124702524L0.9117772389978691 0.9130572743138187L0.6423187128058188 1L0.29586019579751677 0.9935291584506244L0.10638454191462794 0.9229845198431584L0 0.7570771288048773",T:"M0 0L1 0M0.5148514851485149 0L0.5148514851485149 1",U:"M0 0L0.0023103778751369115 0.5467447428390111L0.01823032542100219 0.6954785891481812L0.05895528135268338 0.8056480226151669L0.13703402031421133 0.8894445726483398L0.23918400876232196 0.9448524533417946L0.3917887458926616 0.9848674531975652L0.584341627875137 1L0.7194816196604602 0.9848501456716763L0.8303268115073934 0.9449411544119768L0.8966613970084885 0.898186315516197L0.9251437568455642 0.867453197565408L0.9687114937020809 0.7890904895145239L0.9890470974808324 0.6852857184065537L1 0.0014769088758762145",V:"M0 0L0.5348837209302325 1L1 0",W:"M0 0L0.23300090661831369 0.9873417721518988L0.49954669084315495 0.30081906180193585L0.7851314596554849 1L1 0.0215934475055845",X:"M0 0L0.9893617021276596 1M1 0L0.010638297872340425 1",Y:"M0 0L0.4860515021459227 0.44712562100780695M1 0.0014194464158977947L0.48927038626609437 0.44996451383960256L0.5075107296137339 1",Z:"M0 0L1 0L0 1L1 1",".":"M 0.49 1 L 0.41 1","*":"M 0.5 0.25 L 0.8 0.25 M 0.5 0.25 L 0.5927 0.4402 M 0.5 0.25 L 0.2573 0.3676 M 0.5 0.25 L 0.2573 0.1324 M 0.5 0.25 L 0.599 0.055","(":"M0.75 0L0.25 0.5L0.25 0.5L0.75 1",")":"M0.25 0L0.75 0.5L0.75 0.5L0.25 1","-":"M0 0.5L1 0.5","+":"M 0 0.5 L 1 0.5 M 0.5 0.125 L 0.5 0.875","=":"M0 0.25L1 0.25M0 0.75L1 0.75",_:"M0 1 L1 1","[":"M0.75 0L0.25 0L0.25 1L0.75 1","]":"M0.25 0L0.75 0L0.75 1L0.25 1","<":"M0.75 0L0.25 0.5L0.25 0.5L0.75 1",">":"M0.25 0L0.75 0.5L0.75 0.5L0.25 1","'":"M 0.5 0 L 0.5 0.5",'"':"M 0.25 0 L 0.25 0.5 M 0.75 0 L 0.75 0.5"},gwA={};for(const t in Rue){gwA[t]=[];const A=Rue[t].split("M").slice(1).map(e=>e.split("L").map(i=>i.trim().split(" ").map(parseFloat)));for(const e of A)for(let i=0;i<e.length-1;i++)gwA[t].push({x1:e[i][0],y1:1-e[i][1],x2:e[i+1][0],y2:1-e[i+1][1]})}function ZM(t,A){return Array.isArray(A)?[t.a*A[0]+t.c*A[1]+t.e,t.b*A[0]+t.d*A[1]+t.f]:{x:t.a*A.x+t.c*A.y+t.e,y:t.b*A.x+t.d*A.y+t.f}}function Nue(){return{a:1,c:0,e:0,b:0,d:1,f:0}}function v2(t,A=0){return{a:1,c:0,e:t,b:0,d:1,f:A}}function Gue(...t){t=Array.isArray(t[0])?t[0]:t;const A=(e,i)=>({a:e.a*i.a+e.c*i.b,c:e.a*i.c+e.c*i.d,e:e.a*i.e+e.c*i.f+e.e,b:e.b*i.a+e.d*i.b,d:e.b*i.c+e.d*i.d,f:e.b*i.e+e.d*i.f+e.f});switch(t.length){case 0:throw new Error("no matrices provided");case 1:return t[0];case 2:return A(t[0],t[1]);default:{const[e,i,...n]=t,o=A(e,i);return Gue(o,...n)}}}function cwA(...t){return Gue(...t)}const{cos:Lsi,sin:Usi}=Math;function IwA(t,A,e){const i=Lsi(t),n=Usi(t);return{a:i,c:-n,e:0,b:n,d:i,f:0}}var oQ=({command_code:t,schema:A,stringify:e})=>({command_code:t,schema:A,stringify:e}),Hsi=oQ({command_code:"FMAT",schema:te({command_code:xA("FMAT").default("FMAT"),format:OA()}),stringify:t=>`FMAT,${t.format}`}),Ysi=oQ({command_code:"G00",schema:te({command_code:xA("G00").default("G00")}),stringify:()=>"G00"}),Jsi=oQ({command_code:"G01",schema:te({command_code:xA("G01").default("G01")}),stringify:()=>"G01"}),Tsi=oQ({command_code:"G05",schema:te({command_code:xA("G05").default("G05")}),stringify:()=>"G05"}),Psi=oQ({command_code:"G85",schema:te({command_code:xA("G85").default("G85"),x:OA(),y:OA(),width:OA()}),stringify:({x:t,y:A})=>`G85X${t.toFixed(3)}Y${A.toFixed(3)}`}),Ksi=oQ({command_code:"G90",schema:te({command_code:xA("G90").default("G90")}),stringify:()=>"G90"}),qsi=oQ({command_code:"M15",schema:te({command_code:xA("M15").default("M15")}),stringify:()=>"M15"}),Osi=oQ({command_code:"M16",schema:te({command_code:xA("M16").default("M16")}),stringify:()=>"M16"}),Wsi=oQ({command_code:"M30",schema:te({command_code:xA("M30").default("M30")}),stringify:()=>"M30"}),Zsi=oQ({command_code:"M48",schema:te({command_code:xA("M48").default("M48")}),stringify:()=>"M48"}),Vsi=oQ({command_code:"M95",schema:te({command_code:xA("M95").default("M95")}),stringify:()=>"M95"}),Lue=oQ({command_code:"define_tool",schema:te({command_code:xA("define_tool").default("define_tool"),tool_number:OA(),diameter:OA()}),stringify:t=>`T${t.tool_number}C${t.diameter.toFixed(6)}`}),jsi=oQ({command_code:"drill_at",schema:te({command_code:xA("drill_at").default("drill_at"),x:OA(),y:OA()}),stringify:t=>`X${t.x.toFixed(4)}Y${t.y.toFixed(4)}`}),zsi=oQ({command_code:"header_attribute",schema:te({command_code:xA("header_attribute").default("header_attribute"),attribute_name:U(),attribute_value:U()}),stringify({attribute_name:t,attribute_value:A}){return`; #@! ${t},${A}`}}),Xsi=oQ({command_code:"header_comment",schema:te({command_code:xA("header_comment").default("header_comment"),text:U()}),stringify({text:t}){return`; ${t}`}}),$si=oQ({command_code:"rewind",schema:te({command_code:xA("rewind").default("rewind")}),stringify:()=>"%"}),Ari=oQ({command_code:"unit_format",schema:te({command_code:xA("unit_format").default("unit_format"),unit:Rt([xA("INCH"),xA("METRIC")]),lz:Rt([xA("LZ"),xA("TZ")]).nullable().default(null)}),stringify(t){return`${t.unit}${t.lz?`,${t.lz}`:""}`}}),eri=oQ({command_code:"use_tool",schema:te({command_code:xA("use_tool").default("use_tool"),tool_number:OA()}),stringify:t=>`T${t.tool_number}`}),tri=oQ({command_code:"aper_function_header",schema:te({command_code:xA("aper_function_header").default("aper_function_header"),is_plated:PA()}),stringify({is_plated:t}){return t?"; #@! TA.AperFunction,Plated,PTH,ComponentDrill":"; #@! TA.AperFunction,NonPlated,NPTH,ComponentDrill"}}),iri=oQ({command_code:"percent_sign",schema:te({command_code:xA("percent_sign").default("percent_sign")}),stringify:()=>"%"}),Uue={G00:Ysi,G01:Jsi,G85:Psi,M48:Zsi,M95:Vsi,FMAT:Hsi,unit_format:Ari,aper_function_header:tri,percent_sign:iri,T:Lue,define_tool:Lue,use_tool:eri,G90:Ksi,G05:Tsi,M15:qsi,M16:Osi,M30:Wsi,drill_at:jsi,header_comment:Xsi,header_attribute:zsi,rewind:$si},nri=t=>t.map(A=>Uue[A.command_code].stringify(A)).join(`
5704
5704
  `),ori=class{commands;constructor(){this.commands=[]}add(t,A){return this.commands.push({command_code:Uue[t].command_code,...A}),this}build(){return this.commands}},sri=()=>new ori,rri=({circuitJson:t,is_plated:A,flip_y_axis:e=!1})=>{const i=sri();i.add("M48",{});const n=new Date().toISOString();i.add("header_comment",{text:`DRILL file {tscircuit} date ${n}`}).add("header_comment",{text:"FORMAT={-:-/ absolute / metric / decimal}"}).add("header_attribute",{attribute_name:"TF.CreationDate",attribute_value:n}).add("header_attribute",{attribute_name:"TF.GenerationSoftware",attribute_value:"tscircuit"}).add("header_attribute",{attribute_name:"TF.FileFunction",attribute_value:"Plated,1,2,PTH"}).add("FMAT",{format:2}).add("unit_format",{unit:"METRIC",lz:null});let o=10;const s={};for(const r of t){if(r.type!=="pcb_plated_hole"&&r.type!=="pcb_hole"&&r.type!=="pcb_via")continue;const a="hole_diameter"in r&&typeof r.hole_diameter=="number"?r.hole_diameter:"hole_width"in r&&typeof r.hole_width=="number"&&"hole_height"in r&&typeof r.hole_height=="number"?Math.min(r.hole_width,r.hole_height):void 0;a&&(s[a]||(i.add("aper_function_header",{is_plated:A}),i.add("define_tool",{tool_number:o,diameter:a}),s[a]=o,o++))}i.add("percent_sign",{}),i.add("G90",{}),i.add("G05",{});for(let r=10;r<o;r++){i.add("use_tool",{tool_number:r});for(const a of t)if(a.type==="pcb_plated_hole"||a.type==="pcb_hole"||a.type==="pcb_via"){const g="hole_diameter"in a&&typeof a.hole_diameter=="number"?a.hole_diameter:"hole_width"in a&&typeof a.hole_width=="number"&&"hole_height"in a&&typeof a.hole_height=="number"?Math.min(a.hole_width,a.hole_height):void 0;if(!g||s[g]!==r)continue;const c="x"in a&&typeof a.x=="number"?a.x:0,I="y"in a&&typeof a.y=="number"?a.y:0,l="hole_offset_x"in a&&typeof a.hole_offset_x=="number"?a.hole_offset_x:0,B="hole_offset_y"in a&&typeof a.hole_offset_y=="number"?a.hole_offset_y:0,C=c+l,Q=I+B,h=e?-1:1;if("hole_width"in a&&typeof a.hole_width=="number"&&"hole_height"in a&&typeof a.hole_height=="number"){const E=a.hole_width,u=a.hole_height,d=Math.max(E,u),f=Math.min(E,u);if(Math.abs(d-f)<=1e-6){i.add("drill_at",{x:C,y:Q*h});continue}const w=("hole_ccw_rotation"in a&&typeof a.hole_ccw_rotation=="number"?a.hole_ccw_rotation:"ccw_rotation"in a&&typeof a.ccw_rotation=="number"?a.ccw_rotation:0)*Math.PI/180,D=Math.cos(w),S=Math.sin(w),_=E>=u,b=(d-f)/2,N=_?{x:-b,y:0}:{x:0,y:-b},F=_?{x:b,y:0}:{x:0,y:b},L=({x:gA,y:tA})=>({x:gA*D-tA*S,y:gA*S+tA*D}),Y=L(N),J=L(F),O=C+Y.x,Z=(Q+Y.y)*h,X=C+J.x,eA=(Q+J.y)*h;i.add("drill_at",{x:O,y:Z}).add("G85",{x:X,y:eA,width:f});continue}i.add("drill_at",{x:C,y:Q*h})}}return i.add("M30",{}),i.build()},cl=({command_code:t,schema:A,stringify:e})=>({command_code:t,schema:A,stringify:e}),ari=cl({command_code:"TA",schema:te({command_code:xA("TA").default("TA"),attribute_name:U(),attribute_value:U()}).describe("Add attribute on aperture: Add an aperture attribute to the dictionary or modify it."),stringify:({attribute_name:t,attribute_value:A})=>`%TA${t},${A}*%`}),gri=cl({command_code:"TF",schema:te({command_code:xA("TF").default("TF"),attribute_name:U(),attribute_value:U()}).describe("Add attribute on file: Set a file attribute."),stringify:({attribute_name:t,attribute_value:A})=>`%TF.${t},${A}*%`}),cri=cl({command_code:"TO",schema:te({command_code:xA("TO").default("TO"),attribute_name:U(),attribute_value:U()}).describe("Add attribute on object: Add an object attribute to the dictionary or modify it."),stringify:({attribute_name:t,attribute_value:A})=>`%TO${t},${A}*%`}),Iri=cl({command_code:"AB",schema:te({command_code:xA("AB").default("AB"),block:U()}).describe("Aperture block: Opens a block aperture statement and assigns its aperture number or closes a block aperture statement"),stringify(){return""}}),lri=cl({command_code:"G04",schema:te({command_code:xA("G04").default("G04"),comment:U()}).describe("Comment: A human readable comment, does not affect the image. 4.1"),stringify:t=>`G04 ${t.comment}*`}),Bri=cl({command_code:"G75",schema:te({command_code:xA("G75").default("G75")}).describe("Create arc: A G75 must be called before creating the first arc."),stringify(){return"G75*"}}),Cri=cl({command_code:"AD",schema:te({command_code:xA("AD").default("AD"),aperture_code:U()}).describe("Aperture define: Defines a template-based aperture, assigns a D code to it. 4.3"),stringify(){return""}}),Qri=cl({command_code:"AM",schema:te({command_code:xA("AM").default("AM"),macro_name:U(),template_code:U()}).describe("Aperture macro: Defines a macro aperture template. 4.5"),stringify({macro_name:t,template_code:A}){return`%AM${t}*
5705
5705
  ${A}%`}}),hri=cl({command_code:"TD",schema:te({command_code:xA("TD").default("TD"),attribute:U().optional()}).describe("Delete attribute: Attribute delete Delete one or all attributes in the dictionary."),stringify({attribute:t}){return t?`%TD${t}*%`:"%TD*%"}}),Eri=cl({command_code:"M02",schema:te({command_code:xA("M02").default("M02")}).describe("End of file: 4.13"),stringify(){return"M02*"}}),uri=cl({command_code:"G37",schema:te({command_code:xA("G37").default("G37")}).describe("End region statement: Ends the region statement"),stringify(){return"G37*"}}),F2=t=>{const A=t*1e6;let e=A.toFixed(0);for(;e.length<9;)A<0?e=`-0${e.slice(1)}`:e=`0${e}`;return e},dri=cl({command_code:"D03",schema:te({command_code:xA("D03").default("D03"),x:OA(),y:OA()}).describe("Flash operation: Creates a flash object with the current aperture. The current point is moved to the flash point."),stringify({x:t,y:A}){const[e,i]=[t,A].map(n=>F2(n));return`X${e}Y${i}D03*`}});te({command_code:xA("LM"),mirroring:U()}).describe("Load mirroring: Loads the mirror object transformation parameter."),te({command_code:xA("LP"),polarity:U()}).describe("Load polarity: Loads the polarity object transformation parameter.");var pri=cl({command_code:"LR",schema:te({command_code:xA("LR").default("LR"),rotation_degrees:OA()}).describe("Load rotation: Loads the rotation object transformation parameter."),stringify:({rotation_degrees:t})=>`%LR${t}*%`});te({command_code:xA("LS"),scaling:U()}).describe("Load scaling: Loads the scale object transformation parameter.");var fri=cl({command_code:"D02",schema:te({command_code:xA("D02").default("D02"),x:OA(),y:OA()}).describe("Move operation: D02 moves the current point to the coordinate in the command. It does not create an object."),stringify({x:t,y:A}){const[e,i]=[t,A].map(n=>F2(n));return`X${e}Y${i}D02*`}}),yri=cl({command_code:"D01",schema:te({command_code:xA("D01").default("D01"),x:OA(),y:OA(),i:OA().optional(),j:OA().optional()}).describe("Plot operation: Outside a region statement D01 creates a draw or arc object with the current aperture. Inside it adds a draw/arc segment to the contour under construction. The current point is moved to draw/arc end point after the creation of the draw/arc."),stringify({x:t,y:A,i:e,j:i}){const n=F2(t),o=F2(A);let s=`X${n}Y${o}`;if(e!==void 0&&i!==void 0){const r=F2(e),a=F2(i);s+=`I${r}J${a}`}return`${s}D01*`}});te({command_code:xA("FS"),format:U()}).describe("Sets the coordinate format, e.g. the number of decimals."),te({command_code:xA("Dnn"),d_code:U()}).describe("(nn≥10) Sets the current aperture to D code nn. 4.6");var mri=cl({command_code:"G02",schema:te({command_code:xA("G02").default("G02")}).describe("Set movement mode to clockwise circular: Sets linear/circular mode to clockwise circular."),stringify(){return"G02*"}}),wri=cl({command_code:"G03",schema:te({command_code:xA("G03").default("G03")}).describe("Set movement mode to counterclockwise circular: Sets linear/circular mode to counterclockwise circular."),stringify(){return"G03*"}}),Dri=cl({command_code:"G01",schema:te({command_code:xA("G01").default("G01")}).describe("Set movement mode to linear: Sets linear/circular mode to linear."),stringify(){return"G01*"}}),Sri=cl({command_code:"MO",schema:te({command_code:xA("MO").default("MO"),unit:Xe(["MM","in"])}).describe("Mode: Sets the unit to mm or inch. 4.2.1"),stringify({unit:t}){return`%MO${t}*%`}}),bri=cl({command_code:"G36",schema:te({command_code:xA("G36").default("G36")}).describe("Start region statement: Starts a region statement which creates a region by defining its contours."),stringify(){return"G36*"}});te({command_code:xA("SR"),statement:U()}).describe("Step and repeat: Open or closes a step and repeat statement.");var xri=cl({command_code:"FS",schema:te({command_code:xA("FS").default("FS"),zero_omission_mode:Rt([xA("L").describe("leading zeros omitted"),xA("T")]).nullable().default(null),coordinate_notation:Rt([xA("A").describe("absolute notation"),xA("I").describe("incremental notation")]).default("A"),x_integer_digits:OA().int().default(4),x_decimal_digits:OA().int().default(6),y_integer_digits:OA().int().default(4),y_decimal_digits:OA().int().default(6)}),stringify:()=>"%FSLAX46Y46*%"}),_ri=cl({command_code:"LP",schema:te({command_code:xA("LP").default("LP"),polarity:Xe(["D","C"])}).describe("Layer Polarity: Sets the layer polarity to dark or clear. 4.2.1"),stringify({polarity:t}){return`%LP${t}*%`}}),kri=te({standard_template_code:xA("C").describe("circle"),diameter:OA(),hole_diameter:OA().optional()}),vri=te({standard_template_code:xA("R").describe("rectangle"),x_size:OA(),y_size:OA(),hole_diameter:OA().optional()}),Fri=te({standard_template_code:xA("O").describe("obround"),x_size:OA(),y_size:OA(),hole_diameter:OA().optional()}),Mri=te({standard_template_code:xA("P").describe("polygon"),outer_diameter:OA(),number_of_vertices:OA().int(),rotation:OA().optional(),hole_diameter:OA().optional()}),Rri=Ef("standard_template_code",[kri,vri,Fri,Mri]),Nri=te({macro_name:xA("HORZPILL"),x_size:OA(),y_size:OA(),circle_diameter:OA(),circle_center_offset:OA()}),Gri=te({macro_name:xA("VERTPILL"),x_size:OA(),y_size:OA(),circle_diameter:OA(),circle_center_offset:OA()}),Lri=te({macro_name:xA("ROUNDRECT"),corner_radius:OA(),corner_1_x:OA(),corner_1_y:OA(),corner_2_x:OA(),corner_2_y:OA(),corner_3_x:OA(),corner_3_y:OA(),corner_4_x:OA(),corner_4_y:OA()}),Uri=Ef("macro_name",[Nri,Gri,Lri]),Hri=Rt([Rri,Uri]),Yri=cl({command_code:"ADD",schema:Hri.and(te({command_code:xA("ADD").default("ADD"),aperture_number:OA().int()})),stringify(t){if("macro_name"in t){const{aperture_number:A,macro_name:e}=t;let i=`%ADD${A}${e},`;if(e==="HORZPILL"||e==="VERTPILL")i+=`${t.x_size.toFixed(6)}X${t.y_size.toFixed(6)}X${t.circle_diameter.toFixed(6)}X${t.circle_center_offset.toFixed(6)}`;else if(e==="ROUNDRECT")throw new Error("ROUNDRECT macro not implemented yet");return i+="*%",i}if("standard_template_code"in t){const{aperture_number:A,standard_template_code:e}=t;let i=`%ADD${A}${e},`;return e==="C"?i+=`${t.diameter.toFixed(6)}`:e==="R"||e==="O"?i+=`${t.x_size.toFixed(6)}X${t.y_size.toFixed(6)}`:e==="P"&&(i+=`${t.outer_diameter}X${t.number_of_vertices}X${t.rotation?`X${t.rotation}`:""}`),t.hole_diameter&&(i+=`X${t.hole_diameter.toFixed(6)}`),i+="*%",i}throw new Error(`Invalid aperture template config: ${JSON.stringify(t)}`)}}),Jri=cl({command_code:"D",schema:te({command_code:xA("D").default("D"),aperture_number:OA().int()}),stringify({aperture_number:t}){return`D${t}*`}}),Hue={add_attribute_on_aperture:ari,add_attribute_on_file:gri,add_attribute_on_object:cri,aperture_block:Iri,comment:lri,create_arc:Bri,define_aperture:Cri,define_macro_aperture_template:Qri,delete_attribute:hri,end_of_file:Eri,move_operation:fri,flash_operation:dri,end_region_statement:uri,format_specification:xri,load_rotation:pri,plot_operation:yri,define_aperture_template:Yri,set_movement_mode_to_clockwise_circular:mri,set_movement_mode_to_counterclockwise_circular:wri,set_movement_mode_to_linear:Dri,select_aperture:Jri,set_unit:Sri,set_layer_polarity:_ri,start_region_statement:bri},sg=()=>new Tri,Tri=class{commands;constructor(){this.commands=[]}$if(t,A){return t?A(this):this}add(t,A){return this.commands.push({command_code:Hue[t].command_code,...A}),this}build(){return this.commands}},Pri=t=>{const A=Object.values(Hue).find(e=>e.command_code===t.command_code);if(!A)throw new Error(`Command for command_code:"${t.command_code}" not found`);if(!A.stringify)throw new Error(`Command for command_code:"${t.command_code}" does not have a stringify method`);return A.stringify(t)},Kri=t=>{const A={};for(const e of Object.keys(t))A[e]=t[e].map(i=>Pri(i)).join(`