@tscircuit/runframe 0.0.1803 → 0.0.1805

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.
@@ -5419,7 +5419,7 @@ You passed in: '`+this.raw_options[o]+"'");return c},t.prototype._is_valid_selec
5419
5419
  `);break}}return s}}}),hYn=Ya({"node_modules/pretty/index.js"(n,e){var t=sYn(),r=dYn(),i=Wdt(),o={unformatted:["code","pre","em","strong","span"],indent_inner_html:!0,indent_char:" ",indent_size:2,sep:`
5420
5420
  `};e.exports=function(c,l){var u=i({},o,l);return c=t.html(c,u),u.ocd===!0?(u.newlines&&(u.sep=u.newlines),s(c,u)):c};function s(a,c){return r(a,c).replace(/^\s+/g,"").replace(/\s+$/g,`
5421
5421
  `).replace(/(\s*<!--)/g,`
5422
- $1`).replace(/>(\s*)(?=<!--\s*\/)/g,"> ")}}});function Zdt(n,e,t){if(!e||!t)return;let r=n.get(e);r||(r=new Set,n.set(e,r)),r.add(t);let i=n.get(t);i||(i=new Set,n.set(t,i)),i.add(e)}function pYn(n,e){if(!e.subcircuit_id&&!e.source_group_id)return[...n];let t=e;if(e.subcircuit_id){const a=new Set([e.subcircuit_id]),c=new Map,l=new Map;for(const d of n)if(d.type==="source_group"){const h=d.source_group_id,f=d.subcircuit_id;f&&l.set(h,f);const p=d.parent_source_group_id;p&&(c.has(p)||c.set(p,[]),c.get(p).push(h))}let u;for(const[d,h]of l)if(h===e.subcircuit_id){u=d;break}if(u){const d=h=>{const f=c.get(h)||[];for(const p of f){const m=l.get(p);m&&a.add(m),d(p)}};d(u),t={...e,subcircuit_ids:Array.from(a)}}}const r=new Map;for(const a of n){const c=`${a.type}_id`,l=a[c];typeof l=="string"&&r.set(l,a)}const i=new Map;for(const a of n){const c=Object.entries(a);for(const[l,u]of c)if(l!=="parent_source_group_id"){if(l.endsWith("_id")&&typeof u=="string"){const d=r.get(u);Zdt(i,a,d)}else if(l.endsWith("_ids")&&Array.isArray(u)){for(const d of u)if(typeof d=="string"){const h=r.get(d);Zdt(i,a,h)}}}}const o=[],s=new Set;for(const a of n){let c=!1;(t.subcircuit_id&&"subcircuit_id"in a&&a.subcircuit_id===t.subcircuit_id||t.subcircuit_ids&&"subcircuit_id"in a&&a.subcircuit_id&&t.subcircuit_ids.includes(a.subcircuit_id)||t.source_group_id&&"source_group_id"in a&&a.source_group_id===t.source_group_id||t.source_group_id&&"member_source_group_ids"in a&&Array.isArray(a.member_source_group_ids)&&a.member_source_group_ids.includes(t.source_group_id))&&(c=!0),c&&(o.push(a),s.add(a))}for(;o.length>0;){const a=o.shift(),c=i.get(a);if(c)for(const l of c)s.has(l)||(s.add(l),o.push(l))}return n.filter(a=>s.has(a))}var WG=(n,e={})=>{const t=n;let r=t._internal_store;if(!r){r={counts:{},editCount:0},t._internal_store=r;for(const o of t){const s=o.type,a=o[`${s}_id`];if(!a)continue;const c=Number.parseInt(a.split("_").pop());Number.isNaN(c)||(r.counts[s]=Math.max(r.counts[s]??0,c))}}const i=new Proxy({},{get:(o,s)=>{if(s==="toArray")return()=>(t.editCount=r.editCount,t);if(s==="editCount")return r.editCount;if(s==="subtree")return c=>WG(pYn(t,c),e);if(s==="insert")return c=>{const l=c.type;if(!l)throw new Error("insert requires an element with a type");r.counts[l]??=-1,r.counts[l]++;const u=r.counts[l],d={...c,type:l,[`${l}_id`]:`${l}_${u}`};return e.validateInserts&&(dxe[l]??SG).parse(d),t.push(d),r.editCount++,d};if(s==="insertAll")return c=>c.map(l=>i.insert(l));const a=s;return{get:c=>t.find(l=>l.type===a&&l[`${a}_id`]===c),getUsing:c=>{const l=Object.keys(c);if(l.length!==1)throw new Error("getUsing requires exactly one key, e.g. { pcb_component_id }");const u=l[0],d=u.replace("_id",""),h=t.find(f=>f.type===d&&f[u]===c[u]);return h?t.find(f=>f.type===a&&f[`${a}_id`]===h[`${a}_id`]):null},getWhere:c=>{const l=Object.keys(c);return t.find(u=>u.type===a&&l.every(d=>u[d]===c[d]))},list:c=>{const l=c?Object.keys(c):[];return t.filter(u=>u.type===a&&l.every(d=>u[d]===c[d]))},insert:c=>{r.counts[a]??=-1,r.counts[a]++;const l=r.counts[a],u={type:a,[`${a}_id`]:`${a}_${l}`,...c};return e.validateInserts&&(dxe[a]??SG).parse(u),t.push(u),r.editCount++,u},delete:c=>{const l=t.find(u=>u[`${a}_id`]===c);l&&(t.splice(t.indexOf(l),1),r.editCount++)},update:(c,l)=>{const u=t.find(d=>d.type===a&&d[`${a}_id`]===c);return u?(Object.assign(u,l),r.editCount++,u):null},select:c=>{if(a==="source_component")return t.find(l=>l.type==="source_component"&&l.name===c.replace(/\./g,""));if(a==="pcb_port"||a==="source_port"||a==="schematic_port"){const[l,u]=c.replace(/\./g,"").split(/[\s\>]+/),d=t.find(f=>f.type==="source_component"&&f.name===l);if(!d)return null;const h=t.find(f=>f.type==="source_port"&&f.source_component_id===d.source_component_id&&(f.name===u||(f.port_hints??[]).includes(u)));if(!h)return null;if(a==="source_port")return h;if(a==="pcb_port")return t.find(f=>f.type==="pcb_port"&&f.source_port_id===h.source_port_id);if(a==="schematic_port")return t.find(f=>f.type==="schematic_port"&&f.source_port_id===h.source_port_id)}}}}});return i};WG.unparsed=WG;var W9=WG;function Hxe(n){const e=n.type;return`${e}:${n[`${e}_id`]}`}var Kdt=(n,e={})=>{let t=n._internal_store_indexed;if(!t){t={counts:{},editCount:0,indexes:{}};for(const s of n){const a=s.type,c=s[`${a}_id`];if(!c)continue;const l=Number.parseInt(c.split("_").pop()||"");Number.isNaN(l)||(t.counts[a]=Math.max(t.counts[a]??0,l))}const i=e.indexConfig||{},o=t.indexes;if(i.byId&&(o.byId=new Map),i.byType&&(o.byType=new Map),i.byRelation&&(o.byRelation=new Map),i.bySubcircuit&&(o.bySubcircuit=new Map),i.byCustomField&&i.byCustomField.length>0){o.byCustomField=new Map;for(const s of i.byCustomField)o.byCustomField.set(s,new Map)}for(const s of n){if(i.byId){const a=Hxe(s);o.byId.set(a,s)}if(i.byType){const a=o.byType.get(s.type)||[];a.push(s),o.byType.set(s.type,a)}if(i.byRelation){const a=Object.entries(s);for(const[c,l]of a)if(c.endsWith("_id")&&c!==`${s.type}_id`&&typeof l=="string"){const u=o.byRelation.get(c)||new Map,d=u.get(l)||[];d.push(s),u.set(l,d),o.byRelation.set(c,u)}}if(i.bySubcircuit&&"subcircuit_id"in s){const a=s.subcircuit_id;if(a&&typeof a=="string"){const c=o.bySubcircuit.get(a)||[];c.push(s),o.bySubcircuit.set(a,c)}}if(i.byCustomField&&o.byCustomField){for(const a of i.byCustomField)if(a in s){const c=s[a];if(c!==void 0&&(typeof c=="string"||typeof c=="number")){const l=String(c),u=o.byCustomField.get(a),d=u.get(l)||[];d.push(s),u.set(l,d)}}}}n._internal_store_indexed=t}return new Proxy({},{get:(i,o)=>{if(o==="toArray")return()=>(n.editCount=t.editCount,n);if(o==="editCount")return t.editCount;const s=o;return{get:a=>{const c=e.indexConfig||{};return c.byId&&t.indexes.byId?t.indexes.byId.get(`${s}:${a}`)||null:c.byType&&t.indexes.byType?(t.indexes.byType.get(s)||[]).find(u=>u[`${s}_id`]===a)||null:n.find(l=>l.type===s&&l[`${s}_id`]===a)||null},getUsing:a=>{const c=e.indexConfig||{},l=Object.keys(a);if(l.length!==1)throw new Error("getUsing requires exactly one key, e.g. { pcb_component_id }");const u=l[0],d=u.replace("_id","");if(c.byRelation&&t.indexes.byRelation){const f=t.indexes.byRelation.get(u);if(f){const m=(f.get(a[u])||[]).find(y=>y.type===d);if(!m)return null;const g=m[`${s}_id`];return c.byId&&t.indexes.byId?t.indexes.byId.get(`${s}:${g}`)||null:c.byType&&t.indexes.byType?(t.indexes.byType.get(s)||[]).find(_=>_[`${s}_id`]===g)||null:n.find(y=>y.type===s&&y[`${s}_id`]===g)||null}}const h=n.find(f=>f.type===d&&f[u]===a[u]);return h&&n.find(f=>f.type===s&&f[`${s}_id`]===h[`${s}_id`])||null},getWhere:a=>{const c=e.indexConfig||{},l=Object.keys(a);if(l.length===1&&c.byCustomField&&t.indexes.byCustomField){const u=l[0],d=t.indexes.byCustomField.get(u);if(d){const h=String(a[u]);return(d.get(h)||[]).find(p=>p.type===s)||null}}if("subcircuit_id"in a&&c.bySubcircuit&&t.indexes.bySubcircuit){const u=a.subcircuit_id;return(t.indexes.bySubcircuit.get(u)||[]).find(h=>h.type===s&&l.every(f=>h[f]===a[f]))||null}return c.byType&&t.indexes.byType?(t.indexes.byType.get(s)||[]).find(d=>l.every(h=>d[h]===a[h]))||null:n.find(u=>u.type===s&&l.every(d=>u[d]===a[d]))||null},list:a=>{const c=e.indexConfig||{},l=a?Object.keys(a):[];if(l.length===0&&c.byType&&t.indexes.byType)return t.indexes.byType.get(s)||[];if(l.length===1&&l[0]==="subcircuit_id"&&c.bySubcircuit&&t.indexes.bySubcircuit){const d=a.subcircuit_id;return(t.indexes.bySubcircuit.get(d)||[]).filter(f=>f.type===s)}let u;return c.byType&&t.indexes.byType?u=t.indexes.byType.get(s)||[]:u=n.filter(d=>d.type===s),l.length>0?u.filter(d=>l.every(h=>d[h]===a[h])):u},insert:a=>{t.counts[s]??=-1,t.counts[s]++;const c=t.counts[s],l={type:s,[`${s}_id`]:`${s}_${c}`,...a};e.validateInserts&&(dxe[s]??SG).parse(l),n.push(l),t.editCount++;const u=e.indexConfig||{};if(u.byId&&t.indexes.byId){const d=Hxe(l);t.indexes.byId.set(d,l)}if(u.byType&&t.indexes.byType){const d=t.indexes.byType.get(s)||[];d.push(l),t.indexes.byType.set(s,d)}if(u.byRelation&&t.indexes.byRelation){const d=Object.entries(l);for(const[h,f]of d)if(h.endsWith("_id")&&h!==`${l.type}_id`&&typeof f=="string"){const p=t.indexes.byRelation.get(h)||new Map,m=p.get(f)||[];m.push(l),p.set(f,m),t.indexes.byRelation.set(h,p)}}if(u.bySubcircuit&&t.indexes.bySubcircuit&&"subcircuit_id"in l){const d=l.subcircuit_id;if(d&&typeof d=="string"){const h=t.indexes.bySubcircuit.get(d)||[];h.push(l),t.indexes.bySubcircuit.set(d,h)}}if(u.byCustomField&&t.indexes.byCustomField){for(const d of u.byCustomField)if(d in l){const h=l[d];if(h!==void 0&&(typeof h=="string"||typeof h=="number")){const f=String(h),p=t.indexes.byCustomField.get(d),m=p.get(f)||[];m.push(l),p.set(f,m)}}}return l},delete:a=>{const c=e.indexConfig||{};let l;if(c.byId&&t.indexes.byId?l=t.indexes.byId.get(`${s}:${a}`):c.byType&&t.indexes.byType?l=(t.indexes.byType.get(s)||[]).find(h=>h[`${s}_id`]===a):l=n.find(d=>d[`${s}_id`]===a),!l)return;const u=n.indexOf(l);if(u>=0&&(n.splice(u,1),t.editCount++),c.byId&&t.indexes.byId){const d=Hxe(l);t.indexes.byId.delete(d)}if(c.byType&&t.indexes.byType){const h=(t.indexes.byType.get(s)||[]).filter(f=>f[`${s}_id`]!==a);t.indexes.byType.set(s,h)}if(c.byRelation&&t.indexes.byRelation)for(const[d,h]of t.indexes.byRelation.entries())for(const[f,p]of h.entries()){const m=p.filter(g=>g!==l);m.length===0?h.delete(f):h.set(f,m)}if(c.bySubcircuit&&t.indexes.bySubcircuit&&"subcircuit_id"in l){const d=l.subcircuit_id;if(d){const f=(t.indexes.bySubcircuit.get(d)||[]).filter(p=>p!==l);f.length===0?t.indexes.bySubcircuit.delete(d):t.indexes.bySubcircuit.set(d,f)}}if(c.byCustomField&&t.indexes.byCustomField)for(const d of t.indexes.byCustomField.values())for(const[h,f]of d.entries()){const p=f.filter(m=>m!==l);p.length===0?d.delete(h):d.set(h,p)}},update:(a,c)=>{const l=e.indexConfig||{};let u;if(l.byId&&t.indexes.byId?u=t.indexes.byId.get(`${s}:${a}`):l.byType&&t.indexes.byType?u=(t.indexes.byType.get(s)||[]).find(h=>h[`${s}_id`]===a):u=n.find(d=>d.type===s&&d[`${s}_id`]===a),!u)return null;if(l.byRelation&&t.indexes.byRelation){const d=Object.entries(u);for(const[h,f]of d)if(h.endsWith("_id")&&h!==`${u.type}_id`&&typeof f=="string"&&h in c&&c[h]!==f){const p=t.indexes.byRelation.get(h);if(p){const g=(p.get(f)||[]).filter(y=>y!==u);g.length===0?p.delete(f):p.set(f,g)}}}if(l.bySubcircuit&&t.indexes.bySubcircuit&&"subcircuit_id"in u&&"subcircuit_id"in c){const d=u.subcircuit_id,h=c.subcircuit_id;if(d!==h){const p=(t.indexes.bySubcircuit.get(d)||[]).filter(m=>m!==u);p.length===0?t.indexes.bySubcircuit.delete(d):t.indexes.bySubcircuit.set(d,p)}}if(l.byCustomField&&t.indexes.byCustomField){for(const d of l.byCustomField)if(d in u&&d in c&&u[d]!==c[d]){const h=t.indexes.byCustomField.get(d);if(h){const f=String(u[d]),m=(h.get(f)||[]).filter(g=>g!==u);m.length===0?h.delete(f):h.set(f,m)}}}if(Object.assign(u,c),t.editCount++,l.byRelation&&t.indexes.byRelation){const d=Object.entries(u);for(const[h,f]of d)if(h.endsWith("_id")&&h!==`${u.type}_id`&&typeof f=="string"&&h in c){const p=t.indexes.byRelation.get(h)||new Map,m=p.get(f)||[];m.includes(u)||(m.push(u),p.set(f,m),t.indexes.byRelation.set(h,p))}}if(l.bySubcircuit&&t.indexes.bySubcircuit&&"subcircuit_id"in u&&"subcircuit_id"in c){const d=u.subcircuit_id;if(d&&typeof d=="string"){const h=t.indexes.bySubcircuit.get(d)||[];h.includes(u)||(h.push(u),t.indexes.bySubcircuit.set(d,h))}}if(l.byCustomField&&t.indexes.byCustomField){for(const d of l.byCustomField)if(d in u&&d in c){const h=u[d];if(h!==void 0&&(typeof h=="string"||typeof h=="number")){const f=String(h),p=t.indexes.byCustomField.get(d),m=p.get(f)||[];m.includes(u)||(m.push(u),p.set(f,m))}}}return u},select:a=>{if(s==="source_component")return n.find(c=>c.type==="source_component"&&c.name===a.replace(/\./g,""))||null;if(s==="pcb_port"||s==="source_port"||s==="schematic_port"){const[c,l]=a.replace(/\./g,"").split(/[\s\>]+/),u=n.find(h=>h.type==="source_component"&&h.name===c);if(!u)return null;const d=n.find(h=>h.type==="source_port"&&h.source_component_id===u.source_component_id&&(h.name===l||(h.port_hints??[]).includes(l)));if(!d)return null;if(s==="source_port")return d;if(s==="pcb_port")return n.find(h=>h.type==="pcb_port"&&h.source_port_id===d.source_port_id)||null;if(s==="schematic_port")return n.find(h=>h.type==="schematic_port"&&h.source_port_id===d.source_port_id)||null}return null}}}})};Kdt.unparsed=Kdt;var fYn=n=>{const e=n.type;return n[`${e}_id`]},Qdt=(n,e)=>({minX:Math.min(n.minX,e.minX),minY:Math.min(n.minY,e.minY),maxX:Math.max(n.maxX,e.maxX),maxY:Math.max(n.maxY,e.maxY)}),ZG=(n,e,t)=>{const r=t/2;return{minX:n-r,minY:e-r,maxX:n+r,maxY:e+r}},mYn=(n,e,t,r,i)=>{const o=t/2,s=r/2,a=i*Math.PI/180,c=Math.cos(a),l=Math.sin(a),u=[{x:-o,y:-s},{x:o,y:-s},{x:o,y:s},{x:-o,y:s}].map(d=>({x:n+d.x*c-d.y*l,y:e+d.x*l+d.y*c}));return{minX:Math.min(...u.map(d=>d.x)),minY:Math.min(...u.map(d=>d.y)),maxX:Math.max(...u.map(d=>d.x)),maxY:Math.max(...u.map(d=>d.y))}},Yxe=n=>{let e=Number.POSITIVE_INFINITY,t=Number.POSITIVE_INFINITY,r=Number.NEGATIVE_INFINITY,i=Number.NEGATIVE_INFINITY;for(const o of n){if(!o.type.startsWith("pcb_"))continue;if(o.type==="pcb_smtpad"&&o.shape==="polygon"&&Array.isArray(o.points)){for(const u of o.points)e=Math.min(e,u.x),t=Math.min(t,u.y),r=Math.max(r,u.x),i=Math.max(i,u.y);continue}if(o.type==="pcb_hole"&&o.hole_shape==="circle"){const u=ZG(o.x,o.y,o.hole_diameter);e=Math.min(e,u.minX),t=Math.min(t,u.minY),r=Math.max(r,u.maxX),i=Math.max(i,u.maxY);continue}if(o.type==="pcb_plated_hole"){let u;if("outer_diameter"in o&&typeof o.outer_diameter=="number"?u=ZG(o.x,o.y,o.outer_diameter):"hole_diameter"in o&&typeof o.hole_diameter=="number"&&(u=ZG(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 d=mYn(o.x,o.y,o.rect_pad_width,o.rect_pad_height,"rect_ccw_rotation"in o?o.rect_ccw_rotation??0:0);u=u?Qdt(u,d):d}if("hole_diameter"in o&&typeof o.hole_diameter=="number"){const d=ZG(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);u=u?Qdt(u,d):d}if(u){e=Math.min(e,u.minX),t=Math.min(t,u.minY),r=Math.max(r,u.maxX),i=Math.max(i,u.maxY);continue}}let s,a,c,l;if("x"in o&&"y"in o&&(s=Number(o.x),a=Number(o.y)),"outer_diameter"in o&&(c=Number(o.outer_diameter),l=Number(o.outer_diameter)),"width"in o&&(c=Number(o.width)),"height"in o&&(l=Number(o.height)),"center"in o&&(s=o.center.x,a=o.center.y),s!==void 0&&a!==void 0)e=Math.min(e,s),t=Math.min(t,a),r=Math.max(r,s),i=Math.max(i,a),c!==void 0&&l!==void 0&&(e=Math.min(e,s-c/2),t=Math.min(t,a-l/2),r=Math.max(r,s+c/2),i=Math.max(i,a+l/2)),"radius"in o&&(e=Math.min(e,s-o.radius),t=Math.min(t,a-o.radius),r=Math.max(r,s+o.radius),i=Math.max(i,a+o.radius));else if(o.type==="pcb_trace")for(const u of o.route)e=Math.min(e,u.x),t=Math.min(t,u.y),r=Math.max(r,u.x),i=Math.max(i,u.y);else if(o.type==="pcb_courtyard_outline")for(const u of o.outline)e=Math.min(e,u.x),t=Math.min(t,u.y),r=Math.max(r,u.x),i=Math.max(i,u.y);else if(o.type==="pcb_courtyard_polygon")for(const u of o.points)e=Math.min(e,u.x),t=Math.min(t,u.y),r=Math.max(r,u.x),i=Math.max(i,u.y)}return{minX:e,minY:t,maxX:r,maxY:i}};function yYn(n){let e=0;if(n.length==0)return e;for(var t=0;t<n.length;t++){var r=n.charCodeAt(t);e=(e<<5)-e+r,e=e&e}return Math.abs(e)}var Jdt=[["#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"]],gYn=n=>{let{x:e,y:t,width:r,height:i}={...n,...n.size,...n.center,...n.position};if(n.x1!==void 0&&n.x2!==void 0&&n.y1!==void 0&&n.y2!==void 0&&(e=(n.x1+n.x2)/2,t=(n.y1+n.y2)/2,r=Math.abs(n.x1-n.x2),i=Math.abs(n.y1-n.y2)),n.points&&Array.isArray(n.points)&&n.points.length>0){const a=n.points.map(f=>f.x),c=n.points.map(f=>f.y),l=Math.min(...a),u=Math.max(...a),d=Math.min(...c),h=Math.max(...c);e=(l+u)/2,t=(d+h)/2,r=u-l,i=h-d}const o=n.text||n.name||n.source?.text||n.source?.name||"?",s=n;return e===void 0||t===void 0?null:(r===void 0&&"outer_diameter"in n&&(r=n.outer_diameter,i=n.outer_diameter),(r===void 0||i===void 0)&&(r=.1,i=.1),{x:e,y:t,width:r,height:i,title:o,content:s,bg_color:Jdt[yYn(n.type||o)%Jdt.length]?.[4]??"#f00"})},_Yn=n=>!!n,xYn=n=>{const e=n.filter(l=>l.type.startsWith("pcb_")||l.type.startsWith("schematic_")).concat(n.filter(l=>l.type==="pcb_trace"||l.type==="schematic_trace").flatMap(l=>l.route)).map(l=>gYn(l)).filter(_Yn);if(e.length===0)return{center:{x:0,y:0},width:0,height:0};let t=e[0].x-e[0].width/2,r=e[0].x+e[0].width/2,i=e[0].y-e[0].height/2,o=e[0].y+e[0].height/2;for(const l of e.slice(1))t=Math.min(t,l.x-l.width/2),r=Math.max(r,l.x+l.width/2),i=Math.min(i,l.y-l.height/2),o=Math.max(o,l.y+l.height/2);const s=r-t,a=o-i;return{center:{x:t+s/2,y:i+a/2},width:s,height:a}},fy={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"},BS=(n,e)=>{if(typeof window>"u")return e;try{const t=localStorage.getItem(n);return t!==null?JSON.parse(t):e}catch{return e}},jS=(n,e)=>{if(!(typeof window>"u"))try{localStorage.setItem(n,JSON.stringify(e))}catch{}},bYn=(n,e)=>{if(typeof window>"u")return e;try{const t=localStorage.getItem(n);return t!==null?JSON.parse(t):e}catch{return e}},vYn=(n,e)=>{if(!(typeof window>"u"))try{localStorage.setItem(n,JSON.stringify(e))}catch{}},wYn="named_only",SYn=(n={},e=!1)=>BOe(t=>({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:BS(fy.IS_SHOWING_COPPER_POURS,!0),is_showing_courtyards:BS(fy.IS_SHOWING_COURTYARDS,!0),is_showing_pcb_groups:e?!1:BS(fy.IS_SHOWING_PCB_GROUPS,!0),is_showing_group_anchor_offsets:BS(fy.IS_SHOWING_GROUP_ANCHOR_OFFSETS,!1),is_showing_solder_mask:BS(fy.IS_SHOWING_SOLDER_MASK,!1),is_showing_silkscreen:BS(fy.IS_SHOWING_SILKSCREEN,!0),is_showing_fabrication_notes:BS(fy.IS_SHOWING_FABRICATION_NOTES,!1),pcb_group_view_mode:e?"all":bYn(fy.PCB_GROUP_VIEW_MODE,wYn),hovered_error_id:null,...n,selectLayer:r=>t({selected_layer:r}),setEditMode:r=>t({in_edit_mode:r!=="off",in_move_footprint_mode:r==="move_footprint",in_draw_trace_mode:r==="draw_trace",is_moving_component:!1,is_drawing_trace:!1}),setIsShowingRatsNest:r=>t({is_showing_rats_nest:r}),setIsMovingComponent:r=>t({is_moving_component:r}),setIsDrawingTrace:r=>t({is_drawing_trace:r}),setIsMouseOverContainer:r=>t({is_mouse_over_container:r}),setIsShowingMultipleTracesLength:r=>t({is_showing_multiple_traces_length:r}),setIsShowingAutorouting:r=>t({is_showing_autorouting:r}),setIsShowingDrcErrors:r=>t({is_showing_drc_errors:r}),setIsShowingCopperPours:r=>{jS(fy.IS_SHOWING_COPPER_POURS,r),t({is_showing_copper_pours:r})},setIsShowingCourtyards:r=>{jS(fy.IS_SHOWING_COURTYARDS,r),t({is_showing_courtyards:r})},setIsShowingPcbGroups:r=>{e||(jS(fy.IS_SHOWING_PCB_GROUPS,r),t({is_showing_pcb_groups:r}))},setIsShowingGroupAnchorOffsets:r=>{jS(fy.IS_SHOWING_GROUP_ANCHOR_OFFSETS,r),t({is_showing_group_anchor_offsets:r})},setIsShowingSolderMask:r=>{jS(fy.IS_SHOWING_SOLDER_MASK,r),t({is_showing_solder_mask:r})},setIsShowingSilkscreen:r=>{jS(fy.IS_SHOWING_SILKSCREEN,r),t({is_showing_silkscreen:r})},setIsShowingFabricationNotes:r=>{jS(fy.IS_SHOWING_FABRICATION_NOTES,r),t({is_showing_fabrication_notes:r})},setPcbGroupViewMode:r=>{e||(vYn(fy.PCB_GROUP_VIEW_MODE,r),t({pcb_group_view_mode:r}))},setHoveredErrorId:r=>t({hovered_error_id:r})})),Pd=n=>{const e=q.useContext(e0t);return ZOe(e,n)},e0t=q.createContext(null),MYn=({children:n,initialState:e,disablePcbGroups:t})=>{const r=q.useMemo(()=>SYn(e,t),[t]);return V.jsx(e0t.Provider,{value:r,children:n})},EYn=()=>{const n=Pd(t=>t.pcb_viewer_id),e=(t,r)=>Al(t,{containerId:n,...r});return e.error=(t,r)=>Al.error(t,{containerId:n,...r}),e.promise=Al.promise,e},TYn=()=>{q.useEffect(()=>{mjn()},[]);const n=Pd(e=>e.pcb_viewer_id);return V.jsx(fjn,{position:"top-center",containerId:n})};function CYn(){var n=q.useRef(!1),e=q.useCallback(function(){return n.current},[]);return q.useEffect(function(){return n.current=!0,function(){n.current=!1}},[]),e}var PYn=function(n){n===void 0&&(n={});var e=q.useState(n),t=e[0],r=e[1],i=q.useCallback(function(o){r(function(s){return Object.assign({},s,o instanceof Function?o(s):o)})},[]);return[t,i]},AYn=PYn,RYn=function(){},t0t=typeof window<"u",NYn=$xe(WHn()),IYn=function(){var n=CYn(),e=AYn({value:void 0,error:void 0,noUserInteraction:!0}),t=e[0],r=e[1],i=q.useCallback(function(o){if(n()){var s,a;try{if(typeof o!="string"&&typeof o!="number"){var c=new Error("Cannot copy typeof "+typeof o+" to clipboard, must be a string");console.error(c),r({value:o,error:c,noUserInteraction:!0});return}else if(o===""){var c=new Error("Cannot copy empty string to clipboard.");console.error(c),r({value:o,error:c,noUserInteraction:!0});return}a=o.toString(),s=(0,NYn.default)(a),r({value:a,error:void 0,noUserInteraction:s})}catch(l){r({value:a,error:l,noUserInteraction:s})}}},[]);return[t,i]},kYn=IYn,OYn=t0t?q.useLayoutEffect:q.useEffect,LYn=OYn,n0t={x:0,y:0,width:0,height:0,top:0,left:0,bottom:0,right:0};function DYn(){var n=q.useState(null),e=n[0],t=n[1],r=q.useState(n0t),i=r[0],o=r[1],s=q.useMemo(function(){return new window.ResizeObserver(function(a){if(a[0]){var c=a[0].contentRect,l=c.x,u=c.y,d=c.width,h=c.height,f=c.top,p=c.left,m=c.bottom,g=c.right;o({x:l,y:u,width:d,height:h,top:f,left:p,bottom:m,right:g})}})},[]);return LYn(function(){if(e)return s.observe(e),function(){s.disconnect()}},[e]),[t,i]}var BO=t0t&&typeof window.ResizeObserver<"u"?DYn:function(){return[RYn,n0t]},r0t=({initialTransform:n,initialTouch1:e,initialTouch2:t,finalTouch1:r,finalTouch2:i})=>{if(!r||!i)return n;const o={x:(e.x+t.x)/2,y:(e.y+t.y)/2},s={x:(r.x+i.x)/2,y:(r.y+i.y)/2},a=Math.hypot(t.x-e.x,t.y-e.y),c=Math.hypot(i.x-r.x,i.y-r.y),l=a===0?1:c/a,u=s.x-o.x,d=s.y-o.y;return hi(xi(u,d),xi(o.x,o.y),Gu(l,l),xi(-o.x,-o.y),n)},zYn=(n={})=>{const e=q.useRef(null),[t,r]=q.useState(0),i=n.canvasElm??e.current,[o,s]=q.useState(n.initialTransform??Jc()),[a,c]=q.useState(0),[l,u]=q.useReducer(x=>x+1,0),d=q.useCallback(x=>{n.onSetTransform&&n.onSetTransform(x),n.transform||s(x)},[n.onSetTransform,s]),h=q.useCallback(x=>{d(x),u()},[d]),f=n.transform??o,p=q.useCallback(()=>{r(Date.now())},[]),m=q.useRef("none"),g=q.useRef(null),y=q.useRef(null);q.useEffect(()=>{const x=n.canvasElm??e.current;if(x&&!i){c(a+1);return}if(!x){const W=setTimeout(()=>{c(a+1)},100);return()=>clearTimeout(W)}let b=n.transform??o,w={x:0,y:0},S={x:0,y:0},E=!1;const C=W=>({x:W.pageX-x.getBoundingClientRect().left-window.scrollX,y:W.pageY-x.getBoundingClientRect().top-window.scrollY});function A(W){n.enabled!==!1&&(n.shouldDrag&&!n.shouldDrag(W)||(w=C(W),!(Date.now()-t<100)&&(E=!0,W.preventDefault())))}function R(W){if(!E||n.enabled===!1||n.shouldDrag&&!n.shouldDrag(W))return;S=C(W);const Q=hi(xi(S.x-w.x,S.y-w.y),b);d(Q),b=Q,E=!1}function L(W){if(C(W),!E||n.enabled===!1||n.shouldDrag&&!n.shouldDrag(W))return;S=C(W);const Q=hi(xi(S.x-w.x,S.y-w.y),b);d(Q)}function O(W){if(n.enabled===!1||n.shouldDrag&&!n.shouldDrag(W))return;const Q=C(W),ne=hi(xi(Q.x,Q.y),Gu(1-W.deltaY/1e3,1-W.deltaY/1e3),xi(-Q.x,-Q.y),b);d(ne),b=ne,W.preventDefault()}function F(W){if(!E||n.shouldDrag&&!n.shouldDrag(W))return;if(x){const ne=x.getBoundingClientRect();if(W.clientX>=ne.left+10&&W.clientX<=ne.right-10&&W.clientY>=ne.top+10&&W.clientY<=ne.bottom-10)return}E=!1,S=C(W);const Q=hi(xi(S.x-w.x,S.y-w.y),b);d(Q),b=Q}function B(W){if(W.preventDefault(),n.enabled!==!1){if(W.touches.length===1){m.current="drag";const Q=W.touches[0];g.current={initialTransform:b,initialTouch:{x:Q.clientX,y:Q.clientY}}}else if(W.touches.length===2){m.current="pinch";const Q=W.touches[0],ne=W.touches[1];y.current={initialTransform:b,initialTouch1:{x:Q.clientX,y:Q.clientY},initialTouch2:{x:ne.clientX,y:ne.clientY},finalTouch1:null,finalTouch2:null}}}}function j(W){if(W.preventDefault(),n.enabled!==!1){if(m.current==="drag"&&W.touches.length===1&&g.current){const Q=W.touches[0],ne={x:Q.clientX,y:Q.clientY},ue=ne.x-g.current.initialTouch.x,te=ne.y-g.current.initialTouch.y,re=hi(xi(ue,te),g.current.initialTransform);d(re)}else if(m.current==="pinch"&&W.touches.length===2&&y.current){const Q=W.touches[0],ne=W.touches[1];y.current.finalTouch1={x:Q.clientX,y:Q.clientY},y.current.finalTouch2={x:ne.clientX,y:ne.clientY};const ue=r0t(y.current);d(ue)}}}function G(W){W.preventDefault();const Q=W.changedTouches[0];if(m.current==="drag"&&g.current&&Q){const ne={x:Q.clientX,y:Q.clientY},ue=ne.x-g.current.initialTouch.x,te=ne.y-g.current.initialTouch.y,re=hi(xi(ue,te),g.current.initialTransform);d(re),b=re}else if(m.current==="pinch"&&y.current){const ne=r0t(y.current);d(ne),b=ne}m.current="none",g.current=null,y.current=null}return x.addEventListener("mousedown",A),x.addEventListener("mouseup",R),window.addEventListener("mousemove",L),x.addEventListener("mouseout",F),x.addEventListener("wheel",O),x.addEventListener("touchstart",B,{passive:!1}),x.addEventListener("touchmove",j,{passive:!1}),x.addEventListener("touchend",G,{passive:!1}),x.addEventListener("touchcancel",G,{passive:!1}),()=>{x.removeEventListener("mousedown",A),x.removeEventListener("mouseup",R),window.removeEventListener("mousemove",L),x.removeEventListener("mouseout",F),x.removeEventListener("wheel",O),x.removeEventListener("touchstart",B),x.removeEventListener("touchmove",j),x.removeEventListener("touchend",G),x.removeEventListener("touchcancel",G)}},[i,a,l,t,n.enabled,n.shouldDrag]);const _=q.useCallback(x=>mt(f,x),[f]);return{ref:e,transform:f,applyTransformToPoint:_,setTransform:h,cancelDrag:p}},$Yn=zYn;function FYn(n){const e=new Map;let t=0;function r(i){for(const[,s]of e)if(s.has(i))return s;const o=new Set;return e.set(`connectivity_net${t++}`,o),o}for(const i of n){let o=null;for(const s of i){if(!o)o=r(s);else if(!o.has(s)){const a=r(s);if(a!==o){for(const c of a)o.add(c);e.delete(Array.from(e.entries()).find(([,c])=>c===a)[0])}}o.add(s)}}return Object.fromEntries(Array.from(e.entries()).map(([i,o])=>[i,Array.from(o)]))}var BYn=class{netMap;idToNetMap;constructor(n){this.netMap=n,this.idToNetMap={};for(const[e,t]of Object.entries(n))for(const r of t)this.idToNetMap[r]=e}addConnections(n){for(const e of n){const t=new Set;for(const i of e){const o=this.idToNetMap[i];o&&t.add(o)}let r;if(t.size===0)r=`connectivity_net${Object.keys(this.netMap).length}`,this.netMap[r]=[];else if(t.size===1)r=t.values().next().value??`connectivity_net${Object.keys(this.netMap).length}`;else{r=t.values().next().value??`connectivity_net${Object.keys(this.netMap).length}`;for(const i of t)if(i!==r){this.netMap[r].push(...this.netMap[i]),this.netMap[i]=this.netMap[r];for(const o of this.netMap[r])this.idToNetMap[o]=r}}for(const i of e)this.netMap[r].includes(i)||this.netMap[r].push(i),this.idToNetMap[i]=r}}getIdsConnectedToNet(n){return this.netMap[n]||[]}getNetConnectedToId(n){return this.idToNetMap[n]}areIdsConnected(n,e){if(n===e)return!0;const t=this.getNetConnectedToId(n);if(!t)return!1;const r=this.getNetConnectedToId(e);return r?t===r||r===n||r===n:!1}areAllIdsConnected(n){const e=this.getNetConnectedToId(n[0]);for(const t of n){const r=this.getNetConnectedToId(t);if(r===void 0||r!==e)return!1}return!0}},i0t=n=>{const e=[];for(const r of n)if(r.type==="source_trace")e.push([r.source_trace_id,...r.connected_source_port_ids??[],...r.connected_source_net_ids??[]].filter(Boolean));else if(r.type==="pcb_port"){const{pcb_port_id:i,source_port_id:o}=r;o&&i&&e.push([o,i])}else if(r.type==="pcb_smtpad"){const{pcb_smtpad_id:i,pcb_port_id:o}=r;o&&i&&e.push([i,o])}else if(r.type==="pcb_plated_hole"){const{pcb_plated_hole_id:i,pcb_port_id:o}=r;o&&i&&e.push([i,o])}else if(r.type==="pcb_trace"){const{pcb_trace_id:i,source_trace_id:o}=r,s=Array.isArray(r.route)?r.route.filter(a=>a&&a.route_type==="wire"):[];if(o&&i&&e.push([i,o]),Array.isArray(s)){const a=s.find(l=>l?.start_pcb_port_id)?.start_pcb_port_id,c=s.find(l=>l?.end_pcb_port_id)?.end_pcb_port_id;a&&i&&c&&e.push([a,i,c])}}else if(r.type==="pcb_via"){const{pcb_via_id:i,pcb_trace_id:o}=r;o&&i&&e.push([i,o])}else if(r.type==="source_component"&&r.internally_connected_source_port_ids)for(const i of r.internally_connected_source_port_ids)e.push(i);const t=FYn(e);return new BYn(t)};function jYn({primitivesWithoutInteractionMetadata:n,drawingObjectIdsWithMouseOver:e,primitiveIdsInMousedOverNet:t}){const r=[];for(const i of n){const o={...i};i?.layer==="drill"?(o.is_in_highlighted_net=!1,o.is_mouse_over=!1):e.has(i._pcb_drawing_object_id)?o.is_mouse_over=!0:i._element&&("pcb_trace_id"in i._element&&t.includes(i._element.pcb_trace_id)||"pcb_port_id"in i._element&&t.includes(i._element.pcb_port_id))?o.is_in_highlighted_net=!0:(o.is_in_highlighted_net=!1,o.is_mouse_over=!1),r.push(o)}return r}function UYn(n,e){if(n.length<2)throw new Error("Stroke must have at least two points");const t=n.map(d=>Array.isArray(d)?{x:d[0],y:d[1]}:d),r=[],i=[];function o(d,h){const f=h.x-d.x,p=h.y-d.y,m=Math.sqrt(f*f+p*p);return{x:-p/m,y:f/m}}function s(d,h,f,p){const m=p/2,g={x:d.x+h.x*m*f,y:d.y+h.y*m*f};f>0?r.push(g):i.unshift(g)}const a=o(t[0],t[1]),c=t[0].trace_width??e;s(t[0],a,1,c),s(t[0],a,-1,c);for(let d=1;d<t.length-1;d++){const h=t[d-1],f=t[d],p=t[d+1],m=o(h,f),g=o(f,p),y=m.x+g.x,_=m.y+g.y,x=Math.sqrt(y*y+_*_),b=f.trace_width??e;if(x/2>2*(b/2))s(f,m,1,b),s(f,g,1,b),s(f,m,-1,b),s(f,g,-1,b);else{const S=1/x;s(f,{x:y*S,y:_*S},1,b),s(f,{x:y*S,y:_*S},-1,b)}}const l=o(t[t.length-2],t[t.length-1]),u=t[t.length-1].trace_width??e;return s(t[t.length-1],l,1,u),s(t[t.length-1],l,-1,u),[...r,...i]}var HYn=(n,e)=>{const{x:t,y:r,width:i,height:o,layer:s,rect_border_radius:a}=n,c=n.corner_radius??a??0,l=[{_pcb_drawing_object_id:A4("rect"),pcb_drawing_type:"rect",x:t,y:r,w:i,h:o,layer:s||"top",_element:n,_parent_pcb_component:e._parent_pcb_component,_parent_source_component:e._parent_source_component,_source_port:e._source_port,roundness:c,...n.shape==="rotated_rect"&&n.ccw_rotation!==void 0?{ccw_rotation:n.ccw_rotation}:{}}];if(n.is_covered_with_solder_mask){const u=s==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",h={...{_pcb_drawing_object_id:A4("rect"),pcb_drawing_type:"rect",x:t,y:r,w:i,h:o,layer:u,_element:n,_parent_pcb_component:e._parent_pcb_component,_parent_source_component:e._parent_source_component,_source_port:e._source_port,roundness:c,...n.shape==="rotated_rect"&&n.ccw_rotation!==void 0?{ccw_rotation:n.ccw_rotation}:{}},..."solder_mask_color"in n&&n.solder_mask_color?{color:n.solder_mask_color}:{}};l.push(h)}return l},YYn=(n,e)=>{const{x:t,y:r,radius:i,layer:o}=n,s=[{_pcb_drawing_object_id:A4("circle"),pcb_drawing_type:"circle",x:t,y:r,r:i,layer:o||"top",_element:n,_parent_pcb_component:e._parent_pcb_component,_parent_source_component:e._parent_source_component,_source_port:e._source_port}];if(n.is_covered_with_solder_mask){const a=o==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",c={_pcb_drawing_object_id:A4("circle"),pcb_drawing_type:"circle",x:t,y:r,r:i,layer:a,_element:n,_parent_pcb_component:e._parent_pcb_component,_parent_source_component:e._parent_source_component,_source_port:e._source_port,..."solder_mask_color"in n&&n.solder_mask_color?{color:n.solder_mask_color}:{}};s.push(c)}return s},XYn=(n,e)=>{const{layer:t,points:r}=n,i=[{_pcb_drawing_object_id:A4("polygon"),pcb_drawing_type:"polygon",points:Xxe(r),layer:t||"top",_element:n,_parent_pcb_component:e._parent_pcb_component,_parent_source_component:e._parent_source_component,_source_port:e._source_port}];if(n.is_covered_with_solder_mask){const o=t==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",s={_pcb_drawing_object_id:A4("polygon"),pcb_drawing_type:"polygon",points:Xxe(r),layer:o,_element:n,_parent_pcb_component:e._parent_pcb_component,_parent_source_component:e._parent_source_component,_source_port:e._source_port,..."solder_mask_color"in n&&n.solder_mask_color?{color:n.solder_mask_color}:{}};i.push(s)}return i},VYn=(n,e)=>{const{x:t,y:r,width:i,height:o,layer:s}=n,a=[{_pcb_drawing_object_id:A4("pill"),pcb_drawing_type:"pill",x:t,y:r,w:i,h:o,layer:s||"top",_element:n,_parent_pcb_component:e._parent_pcb_component,_parent_source_component:e._parent_source_component,_source_port:e._source_port}];if(n.is_covered_with_solder_mask){const c=s==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",l={_pcb_drawing_object_id:A4("pill"),pcb_drawing_type:"pill",x:t,y:r,w:i,h:o,layer:c,_element:n,_parent_pcb_component:e._parent_pcb_component,_parent_source_component:e._parent_source_component,_source_port:e._source_port,..."solder_mask_color"in n&&n.solder_mask_color?{color:n.solder_mask_color}:{}};a.push(l)}return a},GYn=(n,e)=>{const{x:t,y:r,width:i,height:o,layer:s,ccw_rotation:a}=n,c=[{_pcb_drawing_object_id:A4("pill"),pcb_drawing_type:"pill",x:t,y:r,w:i,h:o,layer:s||"top",_element:n,_parent_pcb_component:e._parent_pcb_component,_parent_source_component:e._parent_source_component,_source_port:e._source_port,ccw_rotation:a}];if(n.is_covered_with_solder_mask){const l=s==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",u={_pcb_drawing_object_id:A4("pill"),pcb_drawing_type:"pill",x:t,y:r,w:i,h:o,layer:l,_element:n,_parent_pcb_component:e._parent_pcb_component,_parent_source_component:e._parent_source_component,_source_port:e._source_port,ccw_rotation:a,..."solder_mask_color"in n&&n.solder_mask_color?{color:n.solder_mask_color}:{}};c.push(u)}return c},cd=0,A4=n=>`${n}_${cd++}`,Xxe=n=>(n??[]).map(e=>({x:gn.parse(e.x),y:gn.parse(e.y)})),qYn=(n,e)=>{const t="pcb_component_id"in n?e.find(s=>s.type==="pcb_component"&&s.pcb_component_id===n.pcb_component_id):void 0,r=t&&"source_component_id"in t?e.find(s=>s.type==="source_component"&&s.source_component_id===t.source_component_id):void 0,i="source_port_id"in n?n.source_port_id:"pcb_port_id"in n?W9(e).pcb_port.get(n.pcb_port_id)?.source_port_id:void 0,o=i?e.find(s=>s.type==="source_port"&&s.source_port_id===i):void 0;switch(n.type){case"pcb_smtpad":{const s={_parent_pcb_component:t,_parent_source_component:r,_source_port:o};return n.shape==="rect"||n.shape==="rotated_rect"?HYn(n,s):n.shape==="circle"?YYn(n,s):n.shape==="polygon"?XYn(n,s):n.shape==="pill"?VYn(n,s):n.shape==="rotated_pill"?GYn(n,s):[]}case"pcb_trace":{const s=[];if(n.route_thickness_mode==="interpolated"){const l=n.route.map(h=>({x:h.x,y:h.y,trace_width:h.route_type==="wire"?h.width:.5})),u=UYn(l,.5),d=n.route[0].layer;return s.push({_pcb_drawing_object_id:`polygon_${cd++}`,_element:n,pcb_drawing_type:"polygon",points:u,layer:d}),n.route.forEach(h=>{h.route_type==="via"&&s.push({_pcb_drawing_object_id:`circle_${cd++}`,_element:n,pcb_drawing_type:"circle",x:h.x,y:h.y,r:h.outer_diameter/2,layer:h.from_layer})}),s}let a=null,c=null;for(const l of n.route)l.route_type==="wire"&&(a!==null&&c!==null&&s.push({_pcb_drawing_object_id:`line_${cd++}`,_element:n,pcb_drawing_type:"line",x1:a,y1:c,x2:l.x,y2:l.y,width:l.width,squareCap:!1,layer:l.layer}),a=l.x,c=l.y);return s}case"pcb_via":{const{x:s,y:a,outer_diameter:c,hole_diameter:l}=n,u=n.from_layer,d=n.to_layer,h=n.layers,f=[];u&&d?f.push(u,d):h&&Array.isArray(h)?f.push(...h):f.push("top","bottom");const p=[];for(const m of f)p.push({_pcb_drawing_object_id:`circle_${cd++}`,pcb_drawing_type:"circle",x:s,y:a,r:c/2,layer:m,_element:n,_parent_pcb_component:t,_parent_source_component:r});return p.push({_pcb_drawing_object_id:`circle_${cd++}`,pcb_drawing_type:"circle",x:s,y:a,r:l/2,layer:"drill",_element:n}),p}case"pcb_plated_hole":if(n.shape==="circle"){const{x:s,y:a,hole_diameter:c,outer_diameter:l}=n;return[{_pcb_drawing_object_id:`circle_${cd++}`,pcb_drawing_type:"circle",x:s,y:a,r:l/2,layer:"top",_element:n,_parent_pcb_component:t,_parent_source_component:r,_source_port:o},{_pcb_drawing_object_id:`circle_${cd++}`,pcb_drawing_type:"circle",x:s,y:a,r:c/2,layer:"drill",_element:n}]}else if(n.shape==="oval"){const{x:s,y:a,outer_height:c,outer_width:l,hole_height:u,hole_width:d}=n;return[{_pcb_drawing_object_id:`oval_${cd++}`,pcb_drawing_type:"oval",x:s,y:a,rX:l/2,rY:c/2,layer:"top",_element:n,_parent_pcb_component:t,_parent_source_component:r,_source_port:o},{_pcb_drawing_object_id:`oval_${cd++}`,_element:n,pcb_drawing_type:"oval",x:s,y:a,rX:d/2,rY:u/2,layer:"drill"}]}else if(n.shape==="pill"){const{x:s,y:a,outer_height:c,outer_width:l,hole_height:u,hole_width:d}=n;return[{_pcb_drawing_object_id:`pill_${cd++}`,pcb_drawing_type:"pill",x:s,y:a,w:l,h:c,layer:"top",_element:n,_parent_pcb_component:t,_parent_source_component:r,_source_port:o,ccw_rotation:n.ccw_rotation},{_pcb_drawing_object_id:`pill_${cd++}`,_element:n,pcb_drawing_type:"pill",x:s,y:a,w:d,h:u,layer:"drill",ccw_rotation:n.ccw_rotation}]}else if(n.shape==="circular_hole_with_rect_pad"){const{x:s,y:a,hole_diameter:c,rect_pad_width:l,rect_pad_height:u,rect_border_radius:d,hole_offset_x:h,hole_offset_y:f}=n,p=gn.parse(h??0),m=gn.parse(f??0);return[{_pcb_drawing_object_id:`rect_${cd++}`,pcb_drawing_type:"rect",x:s,y:a,w:l,h:u,layer:"top",_element:n,_parent_pcb_component:t,_parent_source_component:r,_source_port:o,roundness:d},{_pcb_drawing_object_id:`rect_${cd++}`,pcb_drawing_type:"rect",x:s,y:a,w:l,h:u,layer:"bottom",_element:n,_parent_pcb_component:t,_parent_source_component:r,_source_port:o,roundness:d,is_hoverable:!1},{_pcb_drawing_object_id:`circle_${cd++}`,_element:n,pcb_drawing_type:"circle",x:s+p,y:a+m,r:c/2,layer:"drill",is_hoverable:!1}]}else if(n.shape==="pill_hole_with_rect_pad"){const{x:s,y:a,hole_width:c,hole_height:l,rect_pad_width:u,rect_pad_height:d,rect_border_radius:h}=n;return[{_pcb_drawing_object_id:`rect_${cd++}`,pcb_drawing_type:"rect",x:s,y:a,w:u,h:d,layer:"top",_element:n,_parent_pcb_component:t,_parent_source_component:r,_source_port:o,roundness:h},{_pcb_drawing_object_id:`rect_${cd++}`,pcb_drawing_type:"rect",x:s,y:a,w:u,h:d,layer:"bottom",_element:n,_parent_pcb_component:t,_parent_source_component:r,_source_port:o,roundness:h,is_hoverable:!1},{_pcb_drawing_object_id:`pill_${cd++}`,_element:n,pcb_drawing_type:"pill",x:s,y:a,w:c,h:l,layer:"drill",is_hoverable:!1}]}else if(n.shape==="rotated_pill_hole_with_rect_pad"){const{x:s,y:a,hole_width:c,hole_height:l,hole_ccw_rotation:u,rect_pad_width:d,rect_pad_height:h,rect_ccw_rotation:f,rect_border_radius:p}=n;return[{_pcb_drawing_object_id:`rect_${cd++}`,pcb_drawing_type:"rect",x:s,y:a,w:d,h,layer:"top",_element:n,_parent_pcb_component:t,_parent_source_component:r,_source_port:o,ccw_rotation:f,roundness:p},{_pcb_drawing_object_id:`rect_${cd++}`,pcb_drawing_type:"rect",x:s,y:a,w:d,h,layer:"bottom",_element:n,_parent_pcb_component:t,_parent_source_component:r,_source_port:o,ccw_rotation:f,roundness:p,is_hoverable:!1},{_pcb_drawing_object_id:`pill_${cd++}`,_element:n,pcb_drawing_type:"pill",x:s,y:a,w:c,h:l,layer:"drill",ccw_rotation:u,is_hoverable:!1}]}else if(n.shape==="hole_with_polygon_pad"){const{x:s,y:a,pad_outline:c,hole_shape:l,hole_diameter:u,hole_width:d,hole_height:h,layers:f,hole_offset_x:p,hole_offset_y:m}=n,g=gn.parse(p??0),y=gn.parse(m??0),_=c,x=[];if(_&&Array.isArray(_)){const S=Xxe(_).map(E=>({x:E.x+s,y:E.y+a}));for(const E of f||["top","bottom"])x.push({_pcb_drawing_object_id:`polygon_${cd++}`,pcb_drawing_type:"polygon",points:S,layer:E,_element:n,_parent_pcb_component:t,_parent_source_component:r,_source_port:o})}const b={x:s+g,y:a+y},w=[];return l==="circle"?w.push({_pcb_drawing_object_id:`circle_${cd++}`,pcb_drawing_type:"circle",x:b.x,y:b.y,r:(u??0)/2,layer:"drill",_element:n,_parent_pcb_component:t,_parent_source_component:r}):l==="oval"?w.push({_pcb_drawing_object_id:`oval_${cd++}`,pcb_drawing_type:"oval",x:b.x,y:b.y,rX:(d??0)/2,rY:(h??0)/2,layer:"drill",_element:n,_parent_pcb_component:t,_parent_source_component:r}):(l==="pill"||l==="rotated_pill")&&w.push({_pcb_drawing_object_id:`pill_${cd++}`,pcb_drawing_type:"pill",x:b.x,y:b.y,w:d??0,h:h??0,layer:"drill",_element:n,_parent_pcb_component:t,_parent_source_component:r,ccw_rotation:n.ccw_rotation}),[...x,...w]}else return[]}return[]},fi={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)"}},z_=(n,e=1)=>{if(Math.abs(n.a)!==Math.abs(n.d))throw new Error("Cannot scale non-uniformly");return e*Math.abs(n.a)},Kl={elementOverlay:40,dimensionOverlay:40,editTraceHintOverlay:40,errorOverlay:40,pcbGroupOverlay:35,ratsNestOverlay:30,toolbarOverlay:70,warnings:30,topLayer:20,clickToInteractOverlay:100},KG={red:"red",black:"black",green:"green",board:"rgb(255, 255, 255)",other:"#eee",top:fi.board.copper.f,inner1:fi.board.copper.in1,inner2:fi.board.copper.in2,inner3:fi.board.copper.in3,inner4:fi.board.copper.in4,inner5:fi.board.copper.in5,inner6:fi.board.copper.in6,inner7:fi.board.copper.in7,inner8:fi.board.copper.in8,bottom:fi.board.copper.b,drill:fi.board.anchor,keepout:fi.board.background,tkeepout:fi.board.b_crtyd,tplace:fi.board.b_silks,top_courtyard:fi.board.f_crtyd,bottom_courtyard:fi.board.b_crtyd,top_silkscreen:fi.board.f_silks,bottom_silkscreen:fi.board.b_silks,top_fabrication:fi.board.f_fab,bottom_fabrication:fi.board.b_fab,soldermask_top:fi.board.soldermask.top,soldermask_bottom:fi.board.soldermask.bottom,soldermask_with_copper_top:fi.board.soldermaskWithCopper.top,soldermask_with_copper_bottom:fi.board.soldermaskWithCopper.bottom,bottom_notes:fi.board.user_2,top_notes:fi.board.user_2,...fi.board},WYn=["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"],ZYn=class{canvasLayerMap;ctxLayerMap;aperture;transform;foregroundLayer="top";lastPoint;constructor(n){this.canvasLayerMap=n,this.ctxLayerMap=Object.fromEntries(Object.entries(n).map(([e,t])=>[e,t.getContext("2d")])),this.transform=Jc(),this.transform.d*=-1,this.transform=hi(this.transform,xi(0,-500)),this.lastPoint={x:0,y:0},this.equip({})}clear(){for(const n of Object.values(this.ctxLayerMap))n.clearRect(0,0,n.canvas.width,n.canvas.height)}equip(n){this.aperture={fontSize:0,shape:"circle",mode:"add",size:0,color:"red",layer:"top",opacity:this.foregroundLayer===n.color?1:.5,...n}}drawMeshPattern(n,e,t,r,i,o=45){const s=this.getLayerCtx(),[a,c]=mt(this.transform,[n,e]),[l,u]=mt(this.transform,[n+t,e+r]),d=z_(this.transform,i);s.lineWidth=1,s.strokeStyle=this.aperture.color;const h=f=>{const p=Math.sin(f),m=Math.cos(f),g=Math.sqrt((l-a)**2+(u-c)**2);for(let y=-g;y<=g;y+=d)s.beginPath(),s.moveTo(a+y*m-g*p,c+y*p+g*m),s.lineTo(a+y*m+g*p,c+y*p-g*m),s.stroke()};h(o*Math.PI/180),h((o+90)*Math.PI/180)}rect({x:n,y:e,w:t,h:r,mesh_fill:i,is_filled:o=!0,has_stroke:s,is_stroke_dashed:a,stroke_width:c,roundness:l}){const[u,d]=mt(this.transform,[n-t/2,e-r/2]),[h,f]=mt(this.transform,[n+t/2,e+r/2]);this.applyAperture();const p=this.getLayerCtx(),m=l?z_(this.transform,l):0,g=s===void 0?o===!1:s;if(i)p.save(),p.beginPath(),m>0&&p.roundRect?p.roundRect(u,d,h-u,f-d,m):p.rect(u,d,h-u,f-d),p.clip(),this.drawMeshPattern(n-t/2,e-r/2,t,r,.15),p.restore(),m>0&&p.roundRect?(p.beginPath(),p.roundRect(u,d,h-u,f-d,m),p.stroke()):p.strokeRect(u,d,h-u,f-d);else if(o!==!1&&(m>0&&p.roundRect?(p.beginPath(),p.roundRect(u,d,h-u,f-d,m),p.fill()):p.fillRect(u,d,h-u,f-d)),g){const y=p.lineWidth;if(c!==void 0&&(p.lineWidth=z_(this.transform,c)),a){let _=[];const x=Math.abs(this.transform.a);if(x>0){const w=.1*x,S=w*1.3;w>.5&&(_=[w,S])}p.setLineDash(_)}m>0&&p.roundRect?(p.beginPath(),p.roundRect(u,d,h-u,f-d,m),p.stroke()):p.strokeRect(u,d,h-u,f-d),a&&p.setLineDash([]),c!==void 0&&(p.lineWidth=y)}}rotatedRect(n,e,t,r,i,o,s){const a=this.getLayerCtx();this.applyAperture();const[c,l]=mt(this.transform,[n-t/2,e-r/2]),[u,d]=mt(this.transform,[n+t/2,e+r/2]),h=o?z_(this.transform,o):0;a.save();const[f,p]=mt(this.transform,[n,e]);a.translate(f,p);const m=360-i;i&&a.rotate(m*Math.PI/180),a.translate(-f,-p),s?(a.beginPath(),h>0&&a.roundRect?a.roundRect(c,l,u-c,d-l,h):a.rect(c,l,u-c,d-l),a.clip(),this.drawMeshPattern(n-t/2,e-r/2,t,r,.15),h>0&&a.roundRect?(a.beginPath(),a.roundRect(c,l,u-c,d-l,h),a.stroke()):a.strokeRect(c,l,u-c,d-l)):h>0&&a.roundRect?(a.beginPath(),a.roundRect(c,l,u-c,d-l,h),a.fill()):a.fillRect(c,l,u-c,d-l),a.restore()}rotatedPill(n,e,t,r,i){const o=this.getLayerCtx();this.applyAperture(),o.save();const[s,a]=mt(this.transform,[n,e]);o.translate(s,a);const c=360-i;i&&o.rotate(c*Math.PI/180),o.translate(-s,-a),this.pill(n,e,t,r),o.restore()}circle(n,e,t,r,i=!0){const o=z_(this.transform,t),[s,a]=mt(this.transform,[n,e]);this.applyAperture();const c=this.getLayerCtx();r?(c.save(),c.beginPath(),c.arc(s,a,o,0,2*Math.PI),c.clip(),this.drawMeshPattern(n-t,e-t,t*2,t*2,.15),c.restore(),c.beginPath(),c.arc(s,a,o,0,2*Math.PI),c.stroke()):(c.beginPath(),c.arc(s,a,o,0,2*Math.PI),c.fill())}oval(n,e,t,r){const i=z_(this.transform,t),o=z_(this.transform,r),[s,a]=mt(this.transform,[n,e]);this.applyAperture();const c=this.getLayerCtx();c.beginPath(),c.ellipse(s,a,i,o,0,0,2*Math.PI),c.fill(),c.closePath()}pill(n,e,t,r){const[i,o]=mt(this.transform,[n-t/2,e+r/2]),s=z_(this.transform,t),a=z_(this.transform,r),c=Math.min(s,a)/2;this.applyAperture();const l=this.getLayerCtx();l.beginPath(),l.arc(i+c,o+c,c,Math.PI,Math.PI*1.5),l.arc(i+s-c,o+c,c,Math.PI*1.5,0),l.arc(i+s-c,o+a-c,c,0,Math.PI*.5),l.arc(i+c,o+a-c,c,Math.PI*.5,Math.PI),l.fill(),l.closePath()}polygon(n){if(n.length<3)return;this.applyAperture();const e=this.getLayerCtx(),t=n.map(i=>mt(this.transform,[i.x,i.y]));e.beginPath(),e.moveTo(t[0][0],t[0][1]);for(let i=1;i<t.length;i++)e.lineTo(t[i][0],t[i][1]);e.closePath(),e.fill("evenodd");const r=z_(this.transform,this.aperture.size);r>0&&(e.lineWidth=r,e.stroke())}debugText(n,e,t){const[r,i]=mt(this.transform,[e,t]);this.applyAperture();const o=this.getLayerCtx();o.font="10px sans-serif",o.fillText(n,r,i)}getLayerCtx(){const n=this.ctxLayerMap[this.aperture.layer];if(!n)throw new Error(`No context for layer "${this.aperture.layer}"`);return n}orderAndFadeLayers(){const{canvasLayerMap:n,foregroundLayer:e}=this,t=e==="top"?"soldermask_top":e==="bottom"?"soldermask_bottom":void 0,r=e==="top"?"top_silkscreen":e==="bottom"?"bottom_silkscreen":void 0,i=e==="top"?"top_notes":e==="bottom"?"bottom_notes":void 0,o=e==="top"?"top_fabrication":e==="bottom"?"bottom_fabrication":void 0,s=e==="top"?"top_courtyard":e==="bottom"?"bottom_courtyard":void 0,a=new Set([e,"drill","edge_cuts","other","board",...t?[t]:[],...r?[r]:[],...i?[i]:[],...o?[o]:[],...s?[s]:[]]),c=[e,"edge_cuts",...t?[t]:[],...r?[r]:[],...i?[i]:[],...o?[o]:[],...s?[s]:[]],l=e==="drill"?[]:["drill"],u=e==="drill"?["drill"]:[],d=[...WYn.filter(h=>!c.includes(h)),...l,e,...t?[t]:[],...u,"edge_cuts",...r?[r]:[],...i?[i]:[],...o?[o]:[],...s?[s]:[]];d.forEach((h,f)=>{const p=n[h];p&&(p.style.zIndex=`${Kl.topLayer-(d.length-f)}`,p.style.opacity=a.has(h)?"1":"0.5")})}applyAperture(){const{transform:n,aperture:e}=this;let{size:t,mode:r,color:i,fontSize:o,layer:s}=e;s in this.ctxLayerMap||(this.aperture.layer="other");const a=this.getLayerCtx();if(!a)throw new Error(`No context for layer "${this.foregroundLayer}"`);if(i||(i="undefined"),a.lineWidth=z_(n,t),a.lineCap="round",r==="add"){a.globalCompositeOperation="source-over";let c=KG[i.toLowerCase()];if(!c)try{c=pc(i).rgb().toString()}catch{console.warn(`Invalid color format: '${i}'`),c="white"}a.fillStyle=c,a.strokeStyle=c}else a.globalCompositeOperation="destination-out",a.fillStyle="rgba(0,0,0,1)",a.strokeStyle="rgba(0,0,0,1)";a.font=`${z_(Y2(n),o)}px sans-serif`}moveTo(n,e){this.lastPoint={x:n,y:e}}lineTo(n,e){const[t,r]=mt(this.transform,[n,e]),{size:i,shape:o,mode:s}=this.aperture,a=z_(this.transform,i),{lastPoint:c}=this,l=mt(this.transform,c);this.applyAperture();const u=this.getLayerCtx();o==="square"&&u.fillRect(l.x-a/2,l.y-a/2,a,a),u.beginPath(),u.moveTo(l.x,l.y),u.lineTo(t,r),u.stroke(),u.closePath(),o==="square"&&u.fillRect(t-a/2,r-a/2,a,a),this.lastPoint={x:n,y:e}}polygonWithArcs(n){const e=this.getLayerCtx(),t=r=>{if(r.vertices.length===0)return;const i=r.vertices[0],o=mt(this.transform,[i.x,i.y]);e.moveTo(o[0],o[1]);for(let s=0;s<r.vertices.length;s++){const a=r.vertices[s],c=r.vertices[(s+1)%r.vertices.length];if(a.bulge&&a.bulge!==0){const l=a.bulge,u=c.x-a.x,d=c.y-a.y,h=Math.sqrt(u*u+d*d);if(h<1e-9){const O=mt(this.transform,[c.x,c.y]);e.lineTo(O[0],O[1]);continue}const f=4*Math.atan(l),p=Math.abs(h/(2*Math.sin(f/2))),m=(a.x+c.x)/2,g=(a.y+c.y)/2,y=u/h,x=-(d/h),b=y,w=Math.sqrt(Math.max(0,p*p-(h/2)**2)),S=m+w*x*Math.sign(l),E=g+w*b*Math.sign(l),C=Math.atan2(a.y-E,a.x-S);let A=Math.atan2(c.y-E,c.x-S);l>0&&A<C?A+=2*Math.PI:l<0&&A>C&&(A-=2*Math.PI);const R=mt(this.transform,[S,E]),L=z_(this.transform,p);e.arc(R[0],R[1],L,-C,-A,l>0)}else{const l=mt(this.transform,[c.x,c.y]);e.lineTo(l[0],l[1])}}e.closePath()};if(e.beginPath(),t(n.outer_ring),n.inner_rings)for(const r of n.inner_rings)t(r);e.fill("evenodd")}};function KYn(n){return n.type==="pcb_copper_pour"}function QG({canvas:n,elements:e,layers:t,realToCanvasMat:r}){const i=e.filter(KYn);if(i.length===0)return;const o=new Ch(n);o.realToCanvasMat=r,o.drawElements(i,{layers:t})}var QYn={...dg,silkscreen:{top:fi.board.f_fab,bottom:fi.board.b_fab}};function JYn(n){return n.type.includes("pcb_fabrication_note")}function o0t({canvas:n,elements:e,layers:t,realToCanvasMat:r}){const i=new Ch(n);i.configure({colorOverrides:QYn}),i.realToCanvasMat=r;const o=e.filter(JYn);i.drawElements(o,{layers:t})}function eXn(n){return n.type==="pcb_hole"}function tXn({canvas:n,elements:e,layers:t,realToCanvasMat:r,drawSoldermask:i}){const o=new Ch(n);o.realToCanvasMat=r;const s=e.filter(eXn);o.drawElements(s,{layers:t,drawSoldermask:i})}function nXn(n){return n.type==="pcb_board"}function rXn({canvas:n,elements:e,layers:t,realToCanvasMat:r,drawSoldermask:i}){const o=new Ch(n);o.realToCanvasMat=r;const s=e.filter(nXn);for(const a of s)o.drawElements([a],{layers:t,drawSoldermask:!1,drawBoardMaterial:i??!1,minBoardOutlineStrokePx:2})}function iXn(n){return n.type==="pcb_copper_text"}function oXn({canvas:n,elements:e,layers:t,realToCanvasMat:r}){const i=e.filter(iXn);if(i.length===0)return;const o=new Ch(n);o.realToCanvasMat=r,o.drawElements(i,{layers:t})}function sXn(n){return n.type==="pcb_cutout"}function aXn({canvas:n,elements:e,layers:t,realToCanvasMat:r}){const i=new Ch(n);i.realToCanvasMat=r;const o=e.filter(sXn);i.drawElements(o,{layers:t})}function cXn(n){return n.type==="pcb_keepout"}function lXn({canvas:n,elements:e,layers:t,realToCanvasMat:r}){const i=e.filter(cXn);if(i.length===0)return;const o=new Ch(n);o.realToCanvasMat=r,o.drawElements(i,{layers:[]})}function uXn(n){return n.type.startsWith("pcb_note_")}function s0t({canvas:n,elements:e,layers:t,realToCanvasMat:r}){const i=new Ch(n);i.realToCanvasMat=r;const o=e.filter(uXn);i.drawElements(o,{layers:t})}function dXn(n){return n.type==="pcb_panel"}function hXn({canvas:n,elements:e,layers:t,realToCanvasMat:r,drawSoldermask:i}){const o=new Ch(n);o.realToCanvasMat=r;const s=e.filter(dXn);for(const a of s)o.drawElements([a],{layers:t})}var pXn={...dg,copper:{...dg.copper,top:pc(fi.board.pad_front).lighten(.5).toString(),bottom:pc(fi.board.pad_back).lighten(.5).toString(),inner1:pc(fi.board.copper.in1).lighten(.5).toString(),inner2:pc(fi.board.copper.in2).lighten(.5).toString(),inner3:pc(fi.board.copper.in3).lighten(.5).toString(),inner4:pc(fi.board.copper.in4).lighten(.5).toString(),inner5:pc(fi.board.copper.in5).lighten(.5).toString(),inner6:pc(fi.board.copper.in6).lighten(.5).toString()}};function fXn(n){return n.type==="pcb_smtpad"}function mXn({canvas:n,elements:e,layers:t,realToCanvasMat:r,primitives:i,drawSoldermask:o}){const s=e.filter(fXn).filter(u=>{const d=u.layer;return t.some(h=>h==="top_copper"&&d==="top"||h==="bottom_copper"&&d==="bottom"||h==="inner1_copper"&&d==="inner1"||h==="inner2_copper"&&d==="inner2"||h==="inner3_copper"&&d==="inner3"||h==="inner4_copper"&&d==="inner4"||h==="inner5_copper"&&d==="inner5"||h==="inner6_copper"&&d==="inner6")});if(s.length===0)return;const a=new Set;if(i)for(const u of i)(u.is_mouse_over||u.is_in_highlighted_net)&&u._element?.type==="pcb_smtpad"&&a.add(u._element.pcb_smtpad_id);const c=s.filter(u=>a.has(u.pcb_smtpad_id)),l=s.filter(u=>!a.has(u.pcb_smtpad_id));if(l.length>0){const u=new Ch(n);u.realToCanvasMat=r,u.drawElements(l,{layers:t,drawSoldermask:o})}if(c.length>0){const u=new Ch(n);u.configure({colorOverrides:pXn}),u.realToCanvasMat=r,u.drawElements(c,{layers:t,drawSoldermask:o})}}var yXn={...dg,copper:{...dg.copper,top:pc(fi.board.pad_front).lighten(.5).toString(),bottom:pc(fi.board.pad_back).lighten(.5).toString(),inner1:pc(fi.board.copper.in1).lighten(.5).toString(),inner2:pc(fi.board.copper.in2).lighten(.5).toString(),inner3:pc(fi.board.copper.in3).lighten(.5).toString(),inner4:pc(fi.board.copper.in4).lighten(.5).toString(),inner5:pc(fi.board.copper.in5).lighten(.5).toString(),inner6:pc(fi.board.copper.in6).lighten(.5).toString()}};function gXn(n){return n.type==="pcb_trace"}var _Xn=n=>n.map(e=>e.endsWith("_copper")?e.replace("_copper",""):e),xXn=(n,e)=>{const t=n.route.filter(i=>i.route_type==="wire"&&"layer"in i&&e.has(i.layer)?!0:i.route_type==="via"?e.has(i.from_layer)||e.has(i.to_layer):!1);return t.filter(i=>i.route_type==="wire").length<2?null:{...n,route:t}};function bXn({canvas:n,elements:e,layers:t,realToCanvasMat:r,primitives:i}){const o=new Set(_Xn(t)),s=e.filter(gXn).map(u=>xXn(u,o)).filter(u=>u!==null);if(s.length===0)return;const a=new Set;if(i)for(const u of i)(u.is_mouse_over||u.is_in_highlighted_net)&&u._element?.type==="pcb_trace"&&a.add(u._element.pcb_trace_id);const c=[],l=[];for(const u of s)a.has(u.pcb_trace_id)?c.push(u):l.push(u);if(l.length>0){const u=new Ch(n);u.realToCanvasMat=r,u.drawElements(l,{layers:t})}if(c.length>0){const u=new Ch(n);u.configure({colorOverrides:yXn}),u.realToCanvasMat=r,u.drawElements(c,{layers:t})}}var vXn={...dg,copper:{...dg.copper,top:pc(fi.board.pad_front).lighten(.5).toString(),bottom:pc(fi.board.pad_back).lighten(.5).toString()}};function wXn(n){return n.type==="pcb_plated_hole"}function a0t({canvas:n,elements:e,layers:t,realToCanvasMat:r,primitives:i,drawSoldermask:o}){const s=e.filter(wXn);if(s.length===0)return;const a=new Set;if(i)for(const u of i)(u.is_mouse_over||u.is_in_highlighted_net)&&u._element?.type==="pcb_plated_hole"&&a.add(u._element.pcb_plated_hole_id);const c=s.filter(u=>a.has(u.pcb_plated_hole_id)),l=s.filter(u=>!a.has(u.pcb_plated_hole_id));if(l.length>0){const u=new Ch(n);u.realToCanvasMat=r,u.drawElements(l,{layers:t,drawSoldermask:o})}if(c.length>0){const u=new Ch(n);u.configure({colorOverrides:vXn}),u.realToCanvasMat=r,u.drawElements(c,{layers:t,drawSoldermask:o})}}function c0t(n){const{lines:e,anchorPoint:t,ccwRotation:r}=n;if(!r)return e;const i=r*Math.PI/180,o=Gf(i),s=hi(xi(t.x,t.y),o,xi(-t.x,-t.y));return mt(s,t),e.map(a=>({...a,x1:mt(s,{x:a.x1,y:a.y1}).x,y1:mt(s,{x:a.x1,y:a.y1}).y,x2:mt(s,{x:a.x2,y:a.y2}).x,y2:mt(s,{x:a.x2,y:a.y2}).y}))}var SXn=.6,l0t=.2,u0t=n=>{const e=n.size*.7,t=e*SXn,r=e*l0t,i=e*l0t,o=n.text.split(/\r?\n/),s=n.text.length>0&&e>0,a=s?o.length:0,c=s?o.map(d=>d.length===0?0:d.length*t+(d.length-1)*r):[],l=c.length>0?Math.max(...c):0,u=a>0?a*e+(a-1)*i:0;return{text_lines:o,line_count:a,line_widths:c,target_height:e,target_width_char:t,space_between_chars:r,space_between_lines:i,width:l,height:u}},d0t=n=>{const e=u0t(n);return{width:e.width,height:e.height,lineHeight:e.target_height,lineSpacing:e.space_between_lines,lineCount:e.line_count}},h0t=n=>{const{text_lines:e,line_count:t,line_widths:r,target_height:i,target_width_char:o,space_between_chars:s,space_between_lines:a,width:c}=u0t(n);if(i<=0||t===0)return[];const l=i/12,u=[];for(let d=0;d<t;d++){const h=-d*(i+a),f=r[d],p=(c-f)/2;let m=n.x+p;for(let g=0;g<e[d].length;g++){const y=e[d][g],_=nS[y]??nS[y.toUpperCase()];if(!_){m+=o+s;continue}for(const{x1:x,y1:b,x2:w,y2:S}of _)u.push({_pcb_drawing_object_id:A4("line"),pcb_drawing_type:"line",x1:m+o*x,y1:n.y+h+i*b,x2:m+o*w,y2:n.y+h+i*S,width:l,layer:n.layer,unit:n.unit,color:n.color});m+=o+s}}return u};function dv(n){const t=n.color??KG[n.layer];let r=pc(t);return n._element?.type==="pcb_copper_pour"&&(r=r.alpha(.7)),n.is_mouse_over||n.is_in_highlighted_net?r.lighten(.5).rgb().toString():r.rgb().toString()}var p0t=(n,e)=>{n.equip({size:e.zoomIndependent?e.width/n.transform.a:e.width,shape:e.squareCap?"square":"circle",color:dv(e),layer:e.layer}),n.moveTo(e.x1,e.y1),n.lineTo(e.x2,e.y2)},MXn=(n,e,t)=>{switch(t){case"top_left":return{x:0,y:-e};case"top_center":return{x:-n/2,y:-e};case"top_right":return{x:-n,y:-e};case"center_left":return{x:0,y:-e/2};case"center":return{x:-n/2,y:-e/2};case"center_right":return{x:-n,y:-e/2};case"bottom_left":return{x:0,y:0};case"bottom_center":return{x:-n/2,y:0};case"bottom_right":return{x:-n,y:0};default:return{x:0,y:0}}},f0t=n=>n.layer==="bottom_silkscreen"||n.layer==="bottom"?n.is_mirrored!==!1:n.is_mirrored===!0,EXn=(n,e)=>{n.equip({fontSize:e.size,color:dv(e),layer:e.layer});const{width:t,height:r}=d0t(e),i=MXn(t,r,e.align);e.x??=0,e.y??=0;const o={x:e.x,y:e.y};let s=h0t({...e,x:e.x+i.x,y:e.y+i.y});if(f0t(e)&&(s=s.map(a=>({...a,x1:2*e.x-a.x1,x2:2*e.x-a.x2}))),e.ccw_rotation){const a={lines:s,anchorPoint:o,ccwRotation:e.ccw_rotation};s=c0t(a)}for(const a of s)p0t(n,a)},TXn=(n,e)=>{const{width:t,height:r,lineHeight:i}=d0t(e);e.x??=0,e.y??=0;const o=e.knockout_padding??{left:e.size*.5,right:e.size*.5,top:e.size*.3,bottom:e.size*.3},s=t+o.left+o.right,a=r+o.top+o.bottom,c=t/2,l=i-r/2,u=e.x-c,d=e.y-l,h={x:e.x,y:e.y},f={_pcb_drawing_object_id:`knockout_rect_${e._pcb_drawing_object_id}`,x:e.x,y:e.y,w:s,h:a,layer:e.layer,ccw_rotation:e.ccw_rotation};e.ccw_rotation?y0t(n,f):m0t(n,f);let p=h0t({...e,x:u,y:d});if(f0t(e)&&(p=p.map(m=>({...m,x1:2*e.x-m.x1,x2:2*e.x-m.x2}))),e.ccw_rotation){const m={lines:p,anchorPoint:h,ccwRotation:e.ccw_rotation};p=c0t(m)}for(const m of p)n.equip({size:m.width,shape:"circle",color:"black",layer:e.layer,mode:"subtract"}),n.moveTo(m.x1,m.y1),n.lineTo(m.x2,m.y2);n.equip({mode:"add"})},m0t=(n,e)=>{n.equip({color:dv(e),layer:e.layer,size:e.stroke_width}),n.rect({x:e.x,y:e.y,w:e.w,h:e.h,mesh_fill:e.mesh_fill,is_filled:e.is_filled,has_stroke:e.has_stroke,is_stroke_dashed:e.is_stroke_dashed,stroke_width:e.stroke_width,roundness:e.roundness})},y0t=(n,e)=>{n.equip({color:dv(e),layer:e.layer}),n.rotatedRect(e.x,e.y,e.w,e.h,e.ccw_rotation,e.roundness,e.mesh_fill)},CXn=(n,e)=>{n.equip({color:dv(e),layer:e.layer}),n.rotatedPill(e.x,e.y,e.w,e.h,e.ccw_rotation)},PXn=(n,e)=>{n.equip({color:dv(e),layer:e.layer}),n.circle(e.x,e.y,e.r,e.mesh_fill)},AXn=(n,e)=>{n.equip({color:dv(e),layer:e.layer}),n.oval(e.x,e.y,e.rX,e.rY)},RXn=(n,e)=>{n.equip({color:dv(e),layer:e.layer}),n.pill(e.x,e.y,e.w,e.h)},NXn=(n,e)=>{n.equip({color:dv(e),layer:e.layer}),n.polygon(e.points)},IXn=(n,e)=>{n.equip({color:dv(e),layer:e.layer}),n.polygonWithArcs(e.brep_shape)},kXn=(n,e)=>{switch(e.pcb_drawing_type){case"line":return p0t(n,e);case"text":return e.is_knockout?TXn(n,e):EXn(n,e);case"rect":return e.ccw_rotation?y0t(n,e):m0t(n,e);case"circle":return PXn(n,e);case"oval":return AXn(n,e);case"pill":return e.ccw_rotation?CXn(n,e):RXn(n,e);case"polygon":return NXn(n,e);case"polygon_with_arcs":return IXn(n,e)}},OXn=(n,e)=>{for(const t of e)kXn(n,t)},LXn={...dg,copper:{...dg.copper,top:pc(fi.board.pad_front).lighten(.5).toString(),bottom:pc(fi.board.pad_back).lighten(.5).toString(),inner1:pc(fi.board.copper.in1).lighten(.5).toString(),inner2:pc(fi.board.copper.in2).lighten(.5).toString(),inner3:pc(fi.board.copper.in3).lighten(.5).toString(),inner4:pc(fi.board.copper.in4).lighten(.5).toString(),inner5:pc(fi.board.copper.in5).lighten(.5).toString(),inner6:pc(fi.board.copper.in6).lighten(.5).toString()},soldermask:{...dg.soldermask,top:pc(fi.board.soldermask.top).lighten(.35).toString(),bottom:pc(fi.board.soldermask.bottom).lighten(.35).toString()}};function g0t({canvas:n,elements:e,layers:t,realToCanvasMat:r,drawSoldermaskTop:i,drawSoldermaskBottom:o,primitives:s}){const a=new Ch(n);a.realToCanvasMat=r;const c=e.filter(h=>h.type==="pcb_board");if(c.length<=1)a.drawElements(e,{layers:t,drawSoldermask:!0,drawSoldermaskTop:i,drawSoldermaskBottom:o,drawBoardMaterial:!1});else{const h=e.filter(f=>f.type!=="pcb_board");for(const f of c)a.drawElements([f,...h],{layers:t,drawSoldermask:!0,drawSoldermaskTop:i,drawSoldermaskBottom:o,drawBoardMaterial:!1})}if(!s)return;const l=new Set;for(const h of s){if(!(h.is_mouse_over||h.is_in_highlighted_net))continue;const f=h._element;f?.type==="pcb_smtpad"?l.add(f.pcb_smtpad_id):f?.type==="pcb_plated_hole"?l.add(f.pcb_plated_hole_id):f?.type==="pcb_via"&&l.add(f.pcb_via_id)}if(l.size===0)return;const u=e.filter(h=>h.type==="pcb_smtpad"?l.has(h.pcb_smtpad_id):h.type==="pcb_plated_hole"?l.has(h.pcb_plated_hole_id):h.type==="pcb_via"?l.has(h.pcb_via_id):!1);if(u.length===0)return;const d=new Ch(n);d.configure({colorOverrides:LXn}),d.realToCanvasMat=r,d.drawElements(u,{layers:t,drawSoldermask:!0,drawSoldermaskTop:i,drawSoldermaskBottom:o,drawBoardMaterial:!1})}var DXn={...dg,silkscreen:{top:fi.board.f_silks,bottom:fi.board.b_silks}};function zXn(n){return n.type.includes("pcb_silkscreen")}function _0t({canvas:n,elements:e,layers:t,realToCanvasMat:r}){const i=new Ch(n);i.configure({colorOverrides:DXn}),i.realToCanvasMat=r;const o=e.filter(zXn);i.drawElements(o,{layers:t})}var $Xn={...dg,copper:{...dg.copper,top:pc(fi.board.pad_front).lighten(.5).toString(),bottom:pc(fi.board.pad_back).lighten(.5).toString()}};function FXn(n){return n.type==="pcb_via"}function x0t({canvas:n,elements:e,layers:t,realToCanvasMat:r,primitives:i,drawSoldermask:o}){const s=e.filter(FXn).filter(u=>t.some(d=>d.includes("copper")));if(s.length===0)return;const a=new Set;if(i)for(const u of i)(u.is_mouse_over||u.is_in_highlighted_net)&&u._element?.type==="pcb_via"&&a.add(u._element.pcb_via_id);const c=s.filter(u=>a.has(u.pcb_via_id)),l=s.filter(u=>!a.has(u.pcb_via_id));if(l.length>0){const u=new Ch(n);u.realToCanvasMat=r,u.drawElements(l,{layers:t,drawSoldermask:o})}if(c.length>0){const u=new Ch(n);u.configure({colorOverrides:$Xn}),u.realToCanvasMat=r,u.drawElements(c,{layers:t,drawSoldermask:o})}}var BXn={...dg,courtyard:{top:fi.board.f_crtyd,bottom:fi.board.b_crtyd}};function jXn(n){return n.type==="pcb_courtyard_circle"||n.type==="pcb_courtyard_rect"||n.type==="pcb_courtyard_outline"}function b0t({canvas:n,elements:e,layers:t,realToCanvasMat:r}){const i=new Ch(n);i.configure({colorOverrides:BXn}),i.realToCanvasMat=r;const o=e.filter(jXn);i.drawElements(o,{layers:t})}var UXn=["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"],HXn=({primitives:n,elements:e,transform:t,grid:r,width:i=500,height:o=500})=>{const s=q.useRef({}),a=Pd(h=>h.selected_layer),c=Pd(h=>h.is_showing_solder_mask),l=Pd(h=>h.is_showing_fabrication_notes),u=Pd(h=>h.is_showing_courtyards),d=Pd(h=>h.is_showing_silkscreen);return q.useEffect(()=>{if(!s.current||Object.keys(s.current).length===0)return;const h=Object.fromEntries(Object.entries(s.current).filter(([m,g])=>!!g));if(Object.keys(h).length===0)return;const f=new ZYn(h);t&&(f.transform=t),f.clear(),f.foregroundLayer=a;const p=n.filter(m=>c||!m.layer?.includes("soldermask")).filter(m=>d||!m.layer?.includes("silkscreen")).filter(m=>l||!m.layer?.includes("fabrication")).filter(m=>m.layer!=="board").filter(m=>m._element?.type!=="pcb_smtpad").filter(m=>m._element?.type!=="pcb_plated_hole").filter(m=>m._element?.type!=="pcb_via").filter(m=>m._element?.type!=="pcb_trace").filter(m=>m._element?.type!=="pcb_copper_text");if(OXn(f,p),t){const m=s.current.top,g=s.current.bottom,y=s.current.inner1,_=s.current.inner2,x=s.current.inner3,b=s.current.inner4,w=s.current.inner5,S=s.current.inner6,E=[{canvas:m,copperLayer:"top_copper"},{canvas:g,copperLayer:"bottom_copper"},{canvas:y,copperLayer:"inner1_copper"},{canvas:_,copperLayer:"inner2_copper"},{canvas:x,copperLayer:"inner3_copper"},{canvas:b,copperLayer:"inner4_copper"},{canvas:w,copperLayer:"inner5_copper"},{canvas:S,copperLayer:"inner6_copper"}];for(const{canvas:B,copperLayer:j}of E)B&&bXn({canvas:B,elements:e,layers:[j],realToCanvasMat:t,primitives:n});for(const{canvas:B,copperLayer:j}of E)B&&oXn({canvas:B,elements:e,layers:[j],realToCanvasMat:t});m&&a0t({canvas:m,elements:e,layers:["top_copper"],realToCanvasMat:t,primitives:n,drawSoldermask:c}),g&&a0t({canvas:g,elements:e,layers:["bottom_copper"],realToCanvasMat:t,primitives:n,drawSoldermask:c}),m&&QG({canvas:m,elements:e,layers:["top_copper"],realToCanvasMat:t}),g&&QG({canvas:g,elements:e,layers:["bottom_copper"],realToCanvasMat:t});for(const{canvas:B,copperLayer:j}of E)B&&mXn({canvas:B,elements:e,layers:[j],realToCanvasMat:t,primitives:n,drawSoldermask:c});if(m&&x0t({canvas:m,elements:e,layers:["top_copper"],realToCanvasMat:t,primitives:n,drawSoldermask:c}),g&&x0t({canvas:g,elements:e,layers:["bottom_copper"],realToCanvasMat:t,primitives:n,drawSoldermask:c}),c){const B=a==="bottom"?"bottom":"top",j=B==="top",G=B==="bottom",W=s.current.soldermask_top;W&&B==="top"&&g0t({canvas:W,elements:e,layers:["top_soldermask"],realToCanvasMat:t,drawSoldermaskTop:j,drawSoldermaskBottom:G,primitives:n});const Q=s.current.soldermask_bottom;Q&&B==="bottom"&&g0t({canvas:Q,elements:e,layers:["bottom_soldermask"],realToCanvasMat:t,drawSoldermaskTop:j,drawSoldermaskBottom:G,primitives:n})}m&&QG({canvas:m,elements:e,layers:["top_copper"],realToCanvasMat:t}),g&&QG({canvas:g,elements:e,layers:["bottom_copper"],realToCanvasMat:t});const C=s.current.drill;if(C&&tXn({canvas:C,elements:e,layers:["drill"],realToCanvasMat:t}),d){const B=s.current.top_silkscreen;B&&_0t({canvas:B,elements:e,layers:["top_silkscreen"],realToCanvasMat:t});const j=s.current.bottom_silkscreen;j&&_0t({canvas:j,elements:e,layers:["bottom_silkscreen"],realToCanvasMat:t})}if(l){const B=s.current.top_fabrication;B&&o0t({canvas:B,elements:e,layers:["top_fabrication_note"],realToCanvasMat:t});const j=s.current.bottom_fabrication;j&&o0t({canvas:j,elements:e,layers:["bottom_fabrication_note"],realToCanvasMat:t})}const A=s.current.bottom_notes;A&&s0t({canvas:A,elements:e,layers:["bottom_user_note"],realToCanvasMat:t});const R=s.current.top_notes;if(R&&s0t({canvas:R,elements:e,layers:["top_user_note"],realToCanvasMat:t}),u){const B=s.current.top_courtyard;B&&b0t({canvas:B,elements:e,layers:["top_courtyard"],realToCanvasMat:t});const j=s.current.bottom_courtyard;j&&b0t({canvas:j,elements:e,layers:["bottom_courtyard"],realToCanvasMat:t})}const L=s.current.board;L&&(hXn({canvas:L,elements:e,layers:[],realToCanvasMat:t,drawSoldermask:c}),rXn({canvas:L,elements:e,layers:[],realToCanvasMat:t,drawSoldermask:c}));const O=s.current.edge_cuts;O&&aXn({canvas:O,elements:e,layers:["edge_cuts"],realToCanvasMat:t});const F=[{canvas:m,layer:"top"},{canvas:g,layer:"bottom"}];for(const{canvas:B,layer:j}of F)B&&lXn({canvas:B,elements:e,layers:[j],realToCanvasMat:t})}f.orderAndFadeLayers()},[n,e,t,a,c,l,u,d]),V.jsxs("div",{style:{backgroundColor:"black",width:i,height:o,position:"relative"},children:[V.jsx(DG.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:i,height:o,transform:t,stringifyCoord:(h,f,p)=>`${DG.toMMSI(h,p)}, ${DG.toMMSI(f,p)}`}),UXn.filter(h=>!(!c&&h.includes("soldermask")||!d&&h.includes("silkscreen"))).map(h=>h.replace(/-/g,"")).map((h,f)=>V.jsx("canvas",{className:`pcb-layer-${h}`,ref:p=>{s.current??={},p?s.current[h]=p:delete s.current[h]},style:{position:"absolute",zIndex:f,left:0,top:0,pointerEvents:"none"},width:i,height:o},h))]})},YXn=.6,XXn=1;$xe(ZHn(),1),$xe(hYn(),1);var JG=["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 v0t(n,e,t,r={}){const i=r.padding??40,o=r.yFlip??!1;let s;if("center"in n){const u=n.width/2,d=n.height/2;s={minX:n.center.x-u,maxX:n.center.x+u,minY:n.center.y-d,maxY:n.center.y+d}}else s=n;const a=s.maxX-s.minX||1,c=s.maxY-s.minY||1,l=Math.min((e-2*i)/a,(t-2*i)/c);return hi(xi(e/2,t/2),Gu(l,o?-l:l),xi(-(s.minX+a/2),-(s.minY+c/2)))}function VXn(n){const e=[...n.points||[],...(n.lines||[]).flatMap(t=>t.points),...(n.rects||[]).flatMap(t=>{const r=t.width/2,i=t.height/2;return[{x:t.center.x-r,y:t.center.y-i},{x:t.center.x+r,y:t.center.y-i},{x:t.center.x-r,y:t.center.y+i},{x:t.center.x+r,y:t.center.y+i}]}),...(n.circles||[]).flatMap(t=>[{x:t.center.x-t.radius,y:t.center.y},{x:t.center.x+t.radius,y:t.center.y},{x:t.center.x,y:t.center.y-t.radius},{x:t.center.x,y:t.center.y+t.radius}]),...(n.texts||[]).flatMap(t=>{const r=t.fontSize??12,i=t.text.length*r*YXn,o=r*XXn,s=t.anchorSide??"center",a={top_left:{dx:0,dy:0},top_center:{dx:-i/2,dy:0},top_right:{dx:-i,dy:0},center_left:{dx:0,dy:-o/2},center:{dx:-i/2,dy:-o/2},center_right:{dx:-i,dy:-o/2},bottom_left:{dx:0,dy:-o},bottom_center:{dx:-i/2,dy:-o},bottom_right:{dx:-i,dy:-o}},{dx:c,dy:l}=a[s],u=t.x+c,d=t.y+l;return[{x:u,y:d},{x:u+i,y:d+o}]})];return e.length===0?{minX:-1,maxX:1,minY:-1,maxY:1}:e.reduce((t,r)=>({minX:Math.min(t.minX,r.x),maxX:Math.max(t.maxX,r.x),minY:Math.min(t.minY,r.y),maxY:Math.max(t.maxY,r.y)}),{minX:1/0,maxX:-1/0,minY:1/0,maxY:-1/0})}function GXn(n,e,t={}){const r=e instanceof HTMLCanvasElement?e.getContext("2d"):e;if(!r)throw new Error("Could not get 2D context from canvas");const i=e instanceof HTMLCanvasElement?e.width:e.canvas.width,o=e instanceof HTMLCanvasElement?e.height:e.canvas.height;let s;if(t.transform)s=t.transform;else if(t.viewbox)s=v0t(t.viewbox,i,o,{padding:t.padding,yFlip:t.yFlip});else{const a=VXn(n),c=n.coordinateSystem==="cartesian";s=v0t(a,i,o,{padding:t.padding??40,yFlip:c})}r.clearRect(0,0,i,o),r.save(),n.rects&&n.rects.length>0&&n.rects.forEach(a=>{const c=a.width/2,l=a.height/2,u=mt(s,{x:a.center.x-c,y:a.center.y-l}),d=mt(s,{x:a.center.x+c,y:a.center.y+l}),h=Math.abs(d.x-u.x),f=Math.abs(d.y-u.y);r.beginPath(),r.rect(Math.min(u.x,d.x),Math.min(u.y,d.y),h,f),a.fill&&(r.fillStyle=a.fill,r.fill()),a.stroke&&(r.strokeStyle=a.stroke,r.stroke())}),n.circles&&n.circles.length>0&&n.circles.forEach(a=>{const c=mt(s,a.center),l=a.radius*Math.abs(s.a);r.beginPath(),r.arc(c.x,c.y,l,0,2*Math.PI),a.fill&&(r.fillStyle=a.fill,r.fill()),a.stroke&&(r.strokeStyle=a.stroke??"transparent",r.stroke())}),n.lines&&n.lines.length>0&&n.lines.forEach((a,c)=>{if(a.points.length===0)return;r.beginPath();const l=mt(s,a.points[0]);r.moveTo(l.x,l.y);for(let u=1;u<a.points.length;u++){const d=mt(s,a.points[u]);r.lineTo(d.x,d.y)}if(r.strokeStyle=a.strokeColor||JG[c%JG.length],a.strokeWidth?r.lineWidth=a.strokeWidth*s.a:r.lineWidth=2,r.lineCap="round",a.strokeDash)if(typeof a.strokeDash=="string"){let u;if(a.strokeDash.includes(","))u=a.strokeDash.split(",").map(d=>parseFloat(d.trim())).filter(d=>!Number.isNaN(d));else{const d=parseFloat(a.strokeDash.trim());u=Number.isNaN(d)?[]:[d]}r.setLineDash(u)}else r.setLineDash(a.strokeDash.map(u=>u*Math.abs(s.a)));else r.setLineDash([]);r.stroke()}),n.points&&n.points.length>0&&n.points.forEach((a,c)=>{const l=mt(s,a);r.beginPath(),r.arc(l.x,l.y,3,0,2*Math.PI),r.fillStyle=a.color||JG[c%JG.length],r.fill(),a.label&&!t.disableLabels&&(r.fillStyle=a.color||"black",r.font="12px sans-serif",r.fillText(a.label,l.x+5,l.y-5))}),n.texts&&n.texts.length>0&&n.texts.forEach(a=>{const c=mt(s,{x:a.x,y:a.y});r.fillStyle=a.color||"black",r.font=`${(a.fontSize??12)*Math.abs(s.a)}px sans-serif`;const l=a.anchorSide??"center",u={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"},d={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"};r.textAlign=u[l],r.textBaseline=d[l],r.fillText(a.text,c.x,c.y)}),r.restore()}var qXn=({children:n,transform:e,debugGraphics:t})=>{const r=q.useRef(null),[i,{width:o,height:s}]=BO(),a=Pd(c=>c.is_showing_autorouting);return q.useEffect(()=>{a&&r.current&&t&&o&&s&&(r.current.width=o,r.current.height=s,GXn(t,r.current,{transform:e,disableLabels:!0}))},[t,e,o,s,a]),a?V.jsxs("div",{ref:i,style:{position:"relative",width:"100%",height:"100%"},children:[n,V.jsx("canvas",{ref:r,style:{position:"absolute",top:0,left:0,opacity:.5,zIndex:100,width:"100%",height:"100%",pointerEvents:"none"}})]}):n},WXn=({children:n,transform:e=Jc(),elements:t=[]})=>{const[r,{width:i,height:o}]=BO(),s=q.useRef(null);return q.useEffect(()=>{const a=s.current;if(!a||!i||!o)return;a.width=i,a.height=o;const c=a.getContext("2d");if(!c)return;c.clearRect(0,0,i,o);const l=t.filter(d=>d.type==="pcb_component"),u=t.filter(d=>d.type==="pcb_manual_edit_conflict_warning");c.strokeStyle=fi.board.drc_warning,c.lineWidth=2,u.forEach(d=>{const h=l.find(G=>G.pcb_component_id===d.pcb_component_id);if(!h)return;const{width:f,height:p,center:m}=h,g=mt(e,m),y=f*Math.abs(e.a),_=p*Math.abs(e.d),x=.1*Math.abs(e.a),b=y+x*2,w=_+x*2,S=g.x-b/2,E=g.y-w/2;c.beginPath(),c.rect(S,E,b,w),c.stroke();const C="Manual Edit Conflict",A=4,R=Math.max(8,Math.min(12,10*Math.abs(e.a)));c.font=`${R}px sans-serif`;const O=c.measureText(C).width+A*2,F=R+A*2,B=S+(b-O)/2,j=E+w+5;c.fillStyle="rgba(0, 0, 0, 0.7)",c.beginPath(),c.roundRect(B,j,O,F,3),c.fill(),c.fillStyle=fi.board.drc_warning,c.textAlign="center",c.textBaseline="middle",c.fillText(C,B+O/2,j+F/2)})},[t,e,i,o]),V.jsxs("div",{ref:r,style:{position:"relative",width:"100%",height:"100%"},children:[n,V.jsx("canvas",{ref:s,style:{position:"absolute",top:0,left:0,pointerEvents:"none",zIndex:Kl.warnings}})]})},eq=(n,e,t)=>t(n,e),w0t=(n,e,t,r,i)=>{const o=i*Math.PI/180,s=Math.cos(o),a=Math.sin(o),c=n-t,l=e-r,u=c*s-l*a,d=c*a+l*s;return{x:u+t,y:d+r}},jO=n=>{if(n.length===0)return null;let e=n[0].x,t=n[0].x,r=n[0].y,i=n[0].y;for(const o of n)e=eq(e,o.x,Math.min),t=eq(t,o.x,Math.max),r=eq(r,o.y,Math.min),i=eq(i,o.y,Math.max);return{minX:e,maxX:t,minY:r,maxY:i}},ZXn=(n,e)=>({minX:Math.min(n.minX,e.minX),maxX:Math.max(n.maxX,e.maxX),minY:Math.min(n.minY,e.minY),maxY:Math.max(n.maxY,e.maxY)}),KXn=(n,e)=>n?ZXn(n,e):e,QXn=n=>{switch(n.pcb_drawing_type){case"line":{const e=(n.width??0)/2,t=[{x:n.x1,y:n.y1},{x:n.x2,y:n.y2}],r=jO(t);return r?{minX:r.minX-e,maxX:r.maxX+e,minY:r.minY-e,maxY:r.maxY+e}:null}case"rect":{const e=n.w/2,t=n.h/2,r=[{x:n.x-e,y:n.y-t},{x:n.x+e,y:n.y-t},{x:n.x+e,y:n.y+t},{x:n.x-e,y:n.y+t}],i=n.ccw_rotation??0,o=i===0?r:r.map(s=>w0t(s.x,s.y,n.x,n.y,i));return jO(o)}case"circle":return{minX:n.x-n.r,maxX:n.x+n.r,minY:n.y-n.r,maxY:n.y+n.r};case"oval":return{minX:n.x-n.rX,maxX:n.x+n.rX,minY:n.y-n.rY,maxY:n.y+n.rY};case"pill":{const e=n.w/2,t=n.h/2,r=[{x:n.x-e,y:n.y-t},{x:n.x+e,y:n.y-t},{x:n.x+e,y:n.y+t},{x:n.x-e,y:n.y+t}],i=n.ccw_rotation??0,o=i===0?r:r.map(s=>w0t(s.x,s.y,n.x,n.y,i));return jO(o)}case"polygon":return jO(n.points);case"polygon_with_arcs":{const e=n.brep_shape.outer_ring.vertices.map(t=>({x:t.x,y:t.y}));return jO(e)}case"text":{const e=n.size??0,t=n.text?n.text.length*e*.6:0,r=e;if(t===0&&r===0)return{minX:n.x,maxX:n.x,minY:n.y,maxY:n.y};const i=t/2,o=r/2;return{minX:n.x-i,maxX:n.x+i,minY:n.y-o,maxY:n.y+o}}default:return null}};function JXn(n){const{dimensionStart:e,dimensionEnd:t,screenDimensionStart:r,screenDimensionEnd:i,flipX:o,flipY:s}=n,a=t.x-e.x,c=t.y-e.y,l=Math.sqrt(a*a+c*c),u=i.x-r.x,d=i.y-r.y,h=Math.sqrt(u*u+d*d),f=Math.atan2(d,u)*(180/Math.PI),p=Math.abs(f)%90,g=Math.min(p,90-p)>15,y=(r.x+i.x)/2,_=(r.y+i.y)/2,x=15,b=f+90;let w=Math.cos(b*Math.PI/180)*x,S=Math.sin(b*Math.PI/180)*x;const E=u>0&&d<0,C=u>0&&d>0,A=u<0&&d>0;o!==s&&!E&&(w=-w,S=-S),E&&(w+=Math.cos(b*Math.PI/180)*-45,S+=Math.sin(b*Math.PI/180)*-45),C&&(w+=Math.cos(b*Math.PI/180)+-20,S+=Math.sin(b*Math.PI/180)+-10),A&&(w+=Math.cos(b*Math.PI/180)*10,S+=Math.sin(b*Math.PI/180)*10);const R=y+w,L=_+S;return{distance:l,screenDistance:h,x:R,y:L,show:l>.01&&h>30&&g}}function eVn(n){const{dimensionStart:e,dimensionEnd:t,screenDimensionStart:r,screenDimensionEnd:i,flipX:o,flipY:s}=n;return q.useMemo(()=>JXn({dimensionStart:e,dimensionEnd:t,screenDimensionStart:r,screenDimensionEnd:i,flipX:o,flipY:s}),[e,t,r,i,o,s])}var tVn=(n,e,t)=>{const r=t*Math.PI/180,i=Math.cos(r),o=Math.sin(r),s=n.x-e.x,a=n.y-e.y,c=s*i-a*o,l=s*o+a*i;return{x:c+e.x,y:l+e.y}},S0t=(n,e,t,r)=>{const i={top_left:{x:n.x-e,y:n.y-t},top_center:{x:n.x,y:n.y-t},top_right:{x:n.x+e,y:n.y-t},center_left:{x:n.x-e,y:n.y},center:{x:n.x,y:n.y},center_right:{x:n.x+e,y:n.y},bottom_left:{x:n.x-e,y:n.y+t},bottom_center:{x:n.x,y:n.y+t},bottom_right:{x:n.x+e,y:n.y+t}};return r===0?Object.entries(i).map(([o,s])=>({anchor:o,point:s})):Object.entries(i).map(([o,s])=>({anchor:o,point:tVn(s,n,r)}))},nVn=n=>{switch(n.pcb_drawing_type){case"rect":{const e=n.ccw_rotation??0;return S0t({x:n.x,y:n.y},n.w/2,n.h/2,e)}case"pill":{const e=n.ccw_rotation??0;return S0t({x:n.x,y:n.y},n.w/2,n.h/2,e)}case"circle":return[{anchor:"circle_center",point:{x:n.x,y:n.y}},{anchor:"circle_right",point:{x:n.x+n.r,y:n.y}},{anchor:"circle_left",point:{x:n.x-n.r,y:n.y}},{anchor:"circle_top",point:{x:n.x,y:n.y-n.r}},{anchor:"circle_bottom",point:{x:n.x,y:n.y+n.r}}];case"oval":return[{anchor:"oval_center",point:{x:n.x,y:n.y}},{anchor:"oval_right",point:{x:n.x+n.rX,y:n.y}},{anchor:"oval_left",point:{x:n.x-n.rX,y:n.y}},{anchor:"oval_top",point:{x:n.x,y:n.y-n.rY}},{anchor:"oval_bottom",point:{x:n.x,y:n.y+n.rY}}];case"line":{const e={x:(n.x1+n.x2)/2,y:(n.y1+n.y2)/2};return[{anchor:"line_start",point:{x:n.x1,y:n.y1}},{anchor:"line_mid",point:e},{anchor:"line_end",point:{x:n.x2,y:n.y2}}]}case"polygon":return n.points.map((e,t)=>({anchor:`polygon_vertex_${t}`,point:e}));case"polygon_with_arcs":return n.brep_shape.outer_ring.vertices.map((e,t)=>({anchor:`polygon_with_arcs_vertex_${t}`,point:{x:e.x,y:e.y}}));default:return[]}},rVn=16,US=5,M0t=n=>{if(n.pcb_drawing_type==="text")return!0;const e=n._element;if(!e||typeof e!="object")return!1;const t=typeof e.type=="string"?e.type:void 0;return t?!!(t.startsWith("pcb_silkscreen_")||t.startsWith("pcb_note_")||t==="pcb_text"||t.startsWith("pcb_fabrication_note_")&&t!=="pcb_fabrication_note_rect"):!1},iVn=({children:n,transform:e,focusOnHover:t=!1,primitives:r=[]})=>{e||(e=Jc());const[i,o]=q.useState(!1),[s,a]=q.useState(!1),[c,l]=q.useState(!1),[u,d]=q.useState({start:null,end:null}),h=Pd(j=>j.is_mouse_over_container),f=q.useCallback(()=>{c&&(l(!1),window.dispatchEvent(new Event("disarm-dimension-tool")))},[c]),[p,m]=q.useState({x:0,y:0}),[g,y]=q.useState({x:0,y:0}),_=q.useRef({x:0,y:0}),x=q.useRef(null),w=x.current?.getBoundingClientRect(),S=q.useMemo(()=>{const j=new Map;for(const G of r){if(!G._element||M0t(G)||G.pcb_drawing_type==="pill"||G.pcb_drawing_type==="rect"&&G.ccw_rotation&&G.ccw_rotation!==0)continue;const W=QXn(G);if(!W)continue;const Q=j.get(G._element);j.set(G._element,KXn(Q??void 0,W))}return j},[r]),E=q.useMemo(()=>{const j=[];for(const G of r){if(!G._element||M0t(G))continue;const W=nVn(G);if(W.length!==0)for(const Q of W)j.push({anchor:Q.anchor,point:Q.point,element:G._element})}return j},[r]),C=q.useMemo(()=>{const j=[];S.forEach((G,W)=>{if(!G)return;const Q=(G.minX+G.maxX)/2,ne=(G.minY+G.maxY)/2,ue={top_left:{x:G.minX,y:G.minY},top_center:{x:Q,y:G.minY},top_right:{x:G.maxX,y:G.minY},center_left:{x:G.minX,y:ne},center:{x:Q,y:ne},center_right:{x:G.maxX,y:ne},bottom_left:{x:G.minX,y:G.maxY},bottom_center:{x:Q,y:G.maxY},bottom_right:{x:G.maxX,y:G.maxY}};for(const[te,re]of Object.entries(ue))j.push({anchor:te,point:re,element:W})});for(const G of E)j.push(G);return j.push({anchor:"origin",point:{x:0,y:0},element:null}),j},[S,E]),A=q.useMemo(()=>C.map((j,G)=>({...j,id:`${G}-${j.anchor}`,screenPoint:mt(e,j.point)})),[C,e]),R=q.useCallback(j=>{if(A.length===0)return{point:j,id:null};const G=mt(e,j);let W=null;for(const Q of A){const ne=Q.screenPoint.x-G.x,ue=Q.screenPoint.y-G.y,te=Math.hypot(ne,ue);te>rVn||(!W||te<W.distance)&&(W={distance:te,id:Q.id,point:Q.point})}return W?{point:W.point,id:W.id}:{point:j,id:null}},[A,e]);q.useEffect(()=>{const j=W=>{const Q=W.target;if(Q.tagName==="INPUT"||Q.tagName==="TEXTAREA"||Q.isContentEditable)return;const ne=x.current?.contains(document.activeElement)||document.activeElement===x.current;if(!(!h&&!ne)){if(W.key==="d"){const ue=R({x:_.current.x,y:_.current.y});m({x:ue.point.x,y:ue.point.y}),y({x:ue.point.x,y:ue.point.y}),d({start:ue.id,end:ue.id}),i?(o(!1),a(!1),d({start:null,end:null})):(o(!0),a(!0)),f()}W.key==="Escape"&&(o(!1),a(!1),d({start:null,end:null}),f())}},G=()=>{l(!0)};return window.addEventListener("keydown",j),window.addEventListener("arm-dimension-tool",G),()=>{window.removeEventListener("keydown",j),window.removeEventListener("arm-dimension-tool",G),f()}},[h,i,f,R]);const L=mt(e,p),O=mt(e,g),F={left:Math.min(L.x,O.x),right:Math.max(L.x,O.x),top:Math.min(L.y,O.y),bottom:Math.max(L.y,O.y),flipX:L.x>O.x,flipY:L.y>O.y,width:0,height:0};F.width=F.right-F.left,F.height=F.bottom-F.top;const B=eVn({dimensionStart:p,dimensionEnd:g,screenDimensionStart:L,screenDimensionEnd:O,flipX:F.flipX,flipY:F.flipY});return V.jsxs("div",{ref:x,"data-pcb-viewer":!0,tabIndex:0,style:{position:"relative",outline:"none"},onMouseEnter:()=>{t&&x.current&&x.current.focus()},onMouseLeave:()=>{x.current&&x.current.blur()},onClick:()=>{x.current&&x.current.focus()},onMouseMove:j=>{const G=j.currentTarget.getBoundingClientRect(),W=j.clientX-G.left,Q=j.clientY-G.top,ne=mt(Y2(e),{x:W,y:Q});if(_.current.x=ne.x,_.current.y=ne.y,s){const ue=R(ne);y({x:ue.point.x,y:ue.point.y}),d(te=>({...te,end:ue.id}))}},onMouseDown:j=>{const G=j.currentTarget.getBoundingClientRect(),W=j.clientX-G.left,Q=j.clientY-G.top,ne=mt(Y2(e),{x:W,y:Q});if(c&&!i){const ue=R(ne);m({x:ue.point.x,y:ue.point.y}),y({x:ue.point.x,y:ue.point.y}),d({start:ue.id,end:ue.id}),o(!0),a(!0),f()}else s?(a(!1),d(ue=>({...ue,end:null}))):i&&(o(!1),d({start:null,end:null}))},children:[n,i&&V.jsxs(V.Fragment,{children:[B.show&&V.jsx("div",{style:{position:"absolute",left:B.x,top:B.y,color:"red",mixBlendMode:"difference",pointerEvents:"none",fontSize:12,fontFamily:"sans-serif",whiteSpace:"nowrap",zIndex:Kl.dimensionOverlay},children:B.distance.toFixed(2)}),V.jsx("div",{style:{position:"absolute",left:F.left,width:F.width,textAlign:"center",top:L.y+2,color:"red",mixBlendMode:"difference",pointerEvents:"none",marginTop:F.flipY?0:-20,fontSize:12,fontFamily:"sans-serif",zIndex:Kl.dimensionOverlay},children:Math.abs(p.x-g.x).toFixed(2)}),V.jsx("div",{style:{position:"absolute",left:O.x,height:F.height,display:"flex",flexDirection:"column",justifyContent:"center",top:F.top,color:"red",pointerEvents:"none",mixBlendMode:"difference",fontSize:12,fontFamily:"sans-serif",zIndex:Kl.dimensionOverlay},children:V.jsx("div",{style:{marginLeft:F.flipX?"-100%":4,paddingRight:4},children:Math.abs(p.y-g.y).toFixed(2)})}),V.jsxs("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none",mixBlendMode:"difference",zIndex:Kl.dimensionOverlay},width:w.width,height:w.height,children:[V.jsx("defs",{children:V.jsx("marker",{id:"head",orient:"auto",markerWidth:"3",markerHeight:"4",refX:"2",refY:"2",children:V.jsx("path",{d:"M0,0 V4 L2,2 Z",fill:"red"})})}),V.jsx("line",{x1:L.x,y1:L.y,x2:O.x,y2:O.y,markerEnd:"url(#head)",strokeWidth:1.5,fill:"none",stroke:"red"}),V.jsx("line",{x1:L.x,y1:L.y,x2:O.x,y2:L.y,strokeWidth:1.5,fill:"none",strokeDasharray:"2,2",stroke:"red"}),V.jsx("line",{x1:O.x,y1:L.y,x2:O.x,y2:O.y,strokeWidth:1.5,fill:"none",strokeDasharray:"2,2",stroke:"red"})]}),s&&A.map(j=>{const G=j.id===u.start||j.id===u.end,W=US/2;return V.jsxs("svg",{width:US,height:US,style:{position:"absolute",left:j.screenPoint.x-W,top:j.screenPoint.y-W,pointerEvents:"none",zIndex:Kl.dimensionOverlay},children:[V.jsx("line",{x1:0,y1:0,x2:US,y2:US,stroke:G?"#66ccff":"white",strokeWidth:1}),V.jsx("line",{x1:US,y1:0,x2:0,y2:US,stroke:G?"#66ccff":"white",strokeWidth:1})]},j.id)}),V.jsxs("div",{style:{right:0,bottom:0,position:"absolute",color:"red",fontFamily:"sans-serif",fontSize:12,margin:4},children:["(",p.x.toFixed(2),",",p.y.toFixed(2),")",V.jsx("br",{}),"(",g.x.toFixed(2),",",g.y.toFixed(2),")",V.jsx("br",{}),"dist:"," ",Math.sqrt((g.x-p.x)**2+(g.y-p.y)**2).toFixed(2)]})]})]})},oVn=(n,e,t=0)=>{const r=n.width/2,i=n.height/2,o=n.center.x-r-t,s=n.center.x+r+t,a=n.center.y-i-t,c=n.center.y+i+t;return e.x>o&&e.x<s&&e.y>a&&e.y<c},sVn=({children:n,disabled:e,transform:t,soup:r,cancelPanDrag:i,onCreateEditEvent:o,onModifyEditEvent:s})=>{t||(t=Jc());const a=q.useRef(null),[c,l]=q.useState(null),[u,d]=q.useState(null),h=c!==null;Pd(g=>g.in_edit_mode);const f=Pd(g=>g.in_move_footprint_mode),p=Pd(g=>g.setIsMovingComponent),m=e||!f;return V.jsxs("div",{ref:a,style:{position:"relative",overflow:"hidden"},onMouseDown:g=>{if(m)return;const y=g.currentTarget.getBoundingClientRect(),_=g.clientX-y.left,x=g.clientY-y.top;if(Number.isNaN(_)||Number.isNaN(x))return;const b=mt(Y2(t),{x:_,y:x});let w=!1;for(const S of r)if(S.type==="pcb_component"&&oVn(S,b,10/t.a)){i(),l(S.pcb_component_id),w=!0;const E=Math.random().toString();d({dragStart:b,originalCenter:S.center,dragEnd:b,edit_event_id:E}),o({edit_event_id:E,edit_event_type:"edit_pcb_component_location",pcb_edit_event_type:"edit_component_location",pcb_component_id:S.pcb_component_id,original_center:S.center,new_center:S.center,in_progress:!0,created_at:Date.now()}),p(!0);break}if(w||l(null),w)return g.preventDefault(),!1},onMouseMove:g=>{if(!c||!u)return;const y=g.currentTarget.getBoundingClientRect(),_=g.clientX-y.left,x=g.clientY-y.top;if(Number.isNaN(_)||Number.isNaN(x))return;const b=mt(Y2(t),{x:_,y:x});d({...u,dragEnd:b}),s({edit_event_id:u.edit_event_id,new_center:{x:u.originalCenter.x+b.x-u.dragStart.x,y:u.originalCenter.y+b.y-u.dragStart.y}})},onMouseUp:g=>{c&&(l(null),p(!1),u&&(s({edit_event_id:u.edit_event_id,in_progress:!1}),d(null)))},children:[n,!m&&r.filter(g=>g.type==="pcb_component").map(g=>{if(!g?.center)return null;const y=mt(t,g.center);return V.jsx("div",{style:{position:"absolute",pointerEvents:"none",left:y.x,top:y.y,width:g.width*t.a+20,height:g.height*t.a+20,transform:"translate(-50%, -50%)",background:h&&c===g.pcb_component_id?"rgba(255, 0, 0, 0.2)":""}},g.pcb_component_id)})]})},aVn=({hotkeys:n})=>(q.useEffect(()=>{const e=t=>{n.forEach(r=>{t.key===r.key&&r.onUse()})};return window.addEventListener("keydown",e),()=>{window.removeEventListener("keydown",e)}},[n]),V.jsx("div",{className:$P`
5422
+ $1`).replace(/>(\s*)(?=<!--\s*\/)/g,"> ")}}});function Zdt(n,e,t){if(!e||!t)return;let r=n.get(e);r||(r=new Set,n.set(e,r)),r.add(t);let i=n.get(t);i||(i=new Set,n.set(t,i)),i.add(e)}function pYn(n,e){if(!e.subcircuit_id&&!e.source_group_id)return[...n];let t=e;if(e.subcircuit_id){const a=new Set([e.subcircuit_id]),c=new Map,l=new Map;for(const d of n)if(d.type==="source_group"){const h=d.source_group_id,f=d.subcircuit_id;f&&l.set(h,f);const p=d.parent_source_group_id;p&&(c.has(p)||c.set(p,[]),c.get(p).push(h))}let u;for(const[d,h]of l)if(h===e.subcircuit_id){u=d;break}if(u){const d=h=>{const f=c.get(h)||[];for(const p of f){const m=l.get(p);m&&a.add(m),d(p)}};d(u),t={...e,subcircuit_ids:Array.from(a)}}}const r=new Map;for(const a of n){const c=`${a.type}_id`,l=a[c];typeof l=="string"&&r.set(l,a)}const i=new Map;for(const a of n){const c=Object.entries(a);for(const[l,u]of c)if(l!=="parent_source_group_id"){if(l.endsWith("_id")&&typeof u=="string"){const d=r.get(u);Zdt(i,a,d)}else if(l.endsWith("_ids")&&Array.isArray(u)){for(const d of u)if(typeof d=="string"){const h=r.get(d);Zdt(i,a,h)}}}}const o=[],s=new Set;for(const a of n){let c=!1;(t.subcircuit_id&&"subcircuit_id"in a&&a.subcircuit_id===t.subcircuit_id||t.subcircuit_ids&&"subcircuit_id"in a&&a.subcircuit_id&&t.subcircuit_ids.includes(a.subcircuit_id)||t.source_group_id&&"source_group_id"in a&&a.source_group_id===t.source_group_id||t.source_group_id&&"member_source_group_ids"in a&&Array.isArray(a.member_source_group_ids)&&a.member_source_group_ids.includes(t.source_group_id))&&(c=!0),c&&(o.push(a),s.add(a))}for(;o.length>0;){const a=o.shift(),c=i.get(a);if(c)for(const l of c)s.has(l)||(s.add(l),o.push(l))}return n.filter(a=>s.has(a))}var WG=(n,e={})=>{const t=n;let r=t._internal_store;if(!r){r={counts:{},editCount:0},t._internal_store=r;for(const o of t){const s=o.type,a=o[`${s}_id`];if(!a)continue;const c=Number.parseInt(a.split("_").pop());Number.isNaN(c)||(r.counts[s]=Math.max(r.counts[s]??0,c))}}const i=new Proxy({},{get:(o,s)=>{if(s==="toArray")return()=>(t.editCount=r.editCount,t);if(s==="editCount")return r.editCount;if(s==="subtree")return c=>WG(pYn(t,c),e);if(s==="insert")return c=>{const l=c.type;if(!l)throw new Error("insert requires an element with a type");r.counts[l]??=-1,r.counts[l]++;const u=r.counts[l],d={...c,type:l,[`${l}_id`]:`${l}_${u}`};return e.validateInserts&&(dxe[l]??SG).parse(d),t.push(d),r.editCount++,d};if(s==="insertAll")return c=>c.map(l=>i.insert(l));const a=s;return{get:c=>t.find(l=>l.type===a&&l[`${a}_id`]===c),getUsing:c=>{const l=Object.keys(c);if(l.length!==1)throw new Error("getUsing requires exactly one key, e.g. { pcb_component_id }");const u=l[0],d=u.replace("_id",""),h=t.find(f=>f.type===d&&f[u]===c[u]);return h?t.find(f=>f.type===a&&f[`${a}_id`]===h[`${a}_id`]):null},getWhere:c=>{const l=Object.keys(c);return t.find(u=>u.type===a&&l.every(d=>u[d]===c[d]))},list:c=>{const l=c?Object.keys(c):[];return t.filter(u=>u.type===a&&l.every(d=>u[d]===c[d]))},insert:c=>{r.counts[a]??=-1,r.counts[a]++;const l=r.counts[a],u={type:a,[`${a}_id`]:`${a}_${l}`,...c};return e.validateInserts&&(dxe[a]??SG).parse(u),t.push(u),r.editCount++,u},delete:c=>{const l=t.find(u=>u[`${a}_id`]===c);l&&(t.splice(t.indexOf(l),1),r.editCount++)},update:(c,l)=>{const u=t.find(d=>d.type===a&&d[`${a}_id`]===c);return u?(Object.assign(u,l),r.editCount++,u):null},select:c=>{if(a==="source_component")return t.find(l=>l.type==="source_component"&&l.name===c.replace(/\./g,""));if(a==="pcb_port"||a==="source_port"||a==="schematic_port"){const[l,u]=c.replace(/\./g,"").split(/[\s\>]+/),d=t.find(f=>f.type==="source_component"&&f.name===l);if(!d)return null;const h=t.find(f=>f.type==="source_port"&&f.source_component_id===d.source_component_id&&(f.name===u||(f.port_hints??[]).includes(u)));if(!h)return null;if(a==="source_port")return h;if(a==="pcb_port")return t.find(f=>f.type==="pcb_port"&&f.source_port_id===h.source_port_id);if(a==="schematic_port")return t.find(f=>f.type==="schematic_port"&&f.source_port_id===h.source_port_id)}}}}});return i};WG.unparsed=WG;var W9=WG;function Hxe(n){const e=n.type;return`${e}:${n[`${e}_id`]}`}var Kdt=(n,e={})=>{let t=n._internal_store_indexed;if(!t){t={counts:{},editCount:0,indexes:{}};for(const s of n){const a=s.type,c=s[`${a}_id`];if(!c)continue;const l=Number.parseInt(c.split("_").pop()||"");Number.isNaN(l)||(t.counts[a]=Math.max(t.counts[a]??0,l))}const i=e.indexConfig||{},o=t.indexes;if(i.byId&&(o.byId=new Map),i.byType&&(o.byType=new Map),i.byRelation&&(o.byRelation=new Map),i.bySubcircuit&&(o.bySubcircuit=new Map),i.byCustomField&&i.byCustomField.length>0){o.byCustomField=new Map;for(const s of i.byCustomField)o.byCustomField.set(s,new Map)}for(const s of n){if(i.byId){const a=Hxe(s);o.byId.set(a,s)}if(i.byType){const a=o.byType.get(s.type)||[];a.push(s),o.byType.set(s.type,a)}if(i.byRelation){const a=Object.entries(s);for(const[c,l]of a)if(c.endsWith("_id")&&c!==`${s.type}_id`&&typeof l=="string"){const u=o.byRelation.get(c)||new Map,d=u.get(l)||[];d.push(s),u.set(l,d),o.byRelation.set(c,u)}}if(i.bySubcircuit&&"subcircuit_id"in s){const a=s.subcircuit_id;if(a&&typeof a=="string"){const c=o.bySubcircuit.get(a)||[];c.push(s),o.bySubcircuit.set(a,c)}}if(i.byCustomField&&o.byCustomField){for(const a of i.byCustomField)if(a in s){const c=s[a];if(c!==void 0&&(typeof c=="string"||typeof c=="number")){const l=String(c),u=o.byCustomField.get(a),d=u.get(l)||[];d.push(s),u.set(l,d)}}}}n._internal_store_indexed=t}return new Proxy({},{get:(i,o)=>{if(o==="toArray")return()=>(n.editCount=t.editCount,n);if(o==="editCount")return t.editCount;const s=o;return{get:a=>{const c=e.indexConfig||{};return c.byId&&t.indexes.byId?t.indexes.byId.get(`${s}:${a}`)||null:c.byType&&t.indexes.byType?(t.indexes.byType.get(s)||[]).find(u=>u[`${s}_id`]===a)||null:n.find(l=>l.type===s&&l[`${s}_id`]===a)||null},getUsing:a=>{const c=e.indexConfig||{},l=Object.keys(a);if(l.length!==1)throw new Error("getUsing requires exactly one key, e.g. { pcb_component_id }");const u=l[0],d=u.replace("_id","");if(c.byRelation&&t.indexes.byRelation){const f=t.indexes.byRelation.get(u);if(f){const m=(f.get(a[u])||[]).find(y=>y.type===d);if(!m)return null;const g=m[`${s}_id`];return c.byId&&t.indexes.byId?t.indexes.byId.get(`${s}:${g}`)||null:c.byType&&t.indexes.byType?(t.indexes.byType.get(s)||[]).find(_=>_[`${s}_id`]===g)||null:n.find(y=>y.type===s&&y[`${s}_id`]===g)||null}}const h=n.find(f=>f.type===d&&f[u]===a[u]);return h&&n.find(f=>f.type===s&&f[`${s}_id`]===h[`${s}_id`])||null},getWhere:a=>{const c=e.indexConfig||{},l=Object.keys(a);if(l.length===1&&c.byCustomField&&t.indexes.byCustomField){const u=l[0],d=t.indexes.byCustomField.get(u);if(d){const h=String(a[u]);return(d.get(h)||[]).find(p=>p.type===s)||null}}if("subcircuit_id"in a&&c.bySubcircuit&&t.indexes.bySubcircuit){const u=a.subcircuit_id;return(t.indexes.bySubcircuit.get(u)||[]).find(h=>h.type===s&&l.every(f=>h[f]===a[f]))||null}return c.byType&&t.indexes.byType?(t.indexes.byType.get(s)||[]).find(d=>l.every(h=>d[h]===a[h]))||null:n.find(u=>u.type===s&&l.every(d=>u[d]===a[d]))||null},list:a=>{const c=e.indexConfig||{},l=a?Object.keys(a):[];if(l.length===0&&c.byType&&t.indexes.byType)return t.indexes.byType.get(s)||[];if(l.length===1&&l[0]==="subcircuit_id"&&c.bySubcircuit&&t.indexes.bySubcircuit){const d=a.subcircuit_id;return(t.indexes.bySubcircuit.get(d)||[]).filter(f=>f.type===s)}let u;return c.byType&&t.indexes.byType?u=t.indexes.byType.get(s)||[]:u=n.filter(d=>d.type===s),l.length>0?u.filter(d=>l.every(h=>d[h]===a[h])):u},insert:a=>{t.counts[s]??=-1,t.counts[s]++;const c=t.counts[s],l={type:s,[`${s}_id`]:`${s}_${c}`,...a};e.validateInserts&&(dxe[s]??SG).parse(l),n.push(l),t.editCount++;const u=e.indexConfig||{};if(u.byId&&t.indexes.byId){const d=Hxe(l);t.indexes.byId.set(d,l)}if(u.byType&&t.indexes.byType){const d=t.indexes.byType.get(s)||[];d.push(l),t.indexes.byType.set(s,d)}if(u.byRelation&&t.indexes.byRelation){const d=Object.entries(l);for(const[h,f]of d)if(h.endsWith("_id")&&h!==`${l.type}_id`&&typeof f=="string"){const p=t.indexes.byRelation.get(h)||new Map,m=p.get(f)||[];m.push(l),p.set(f,m),t.indexes.byRelation.set(h,p)}}if(u.bySubcircuit&&t.indexes.bySubcircuit&&"subcircuit_id"in l){const d=l.subcircuit_id;if(d&&typeof d=="string"){const h=t.indexes.bySubcircuit.get(d)||[];h.push(l),t.indexes.bySubcircuit.set(d,h)}}if(u.byCustomField&&t.indexes.byCustomField){for(const d of u.byCustomField)if(d in l){const h=l[d];if(h!==void 0&&(typeof h=="string"||typeof h=="number")){const f=String(h),p=t.indexes.byCustomField.get(d),m=p.get(f)||[];m.push(l),p.set(f,m)}}}return l},delete:a=>{const c=e.indexConfig||{};let l;if(c.byId&&t.indexes.byId?l=t.indexes.byId.get(`${s}:${a}`):c.byType&&t.indexes.byType?l=(t.indexes.byType.get(s)||[]).find(h=>h[`${s}_id`]===a):l=n.find(d=>d[`${s}_id`]===a),!l)return;const u=n.indexOf(l);if(u>=0&&(n.splice(u,1),t.editCount++),c.byId&&t.indexes.byId){const d=Hxe(l);t.indexes.byId.delete(d)}if(c.byType&&t.indexes.byType){const h=(t.indexes.byType.get(s)||[]).filter(f=>f[`${s}_id`]!==a);t.indexes.byType.set(s,h)}if(c.byRelation&&t.indexes.byRelation)for(const[d,h]of t.indexes.byRelation.entries())for(const[f,p]of h.entries()){const m=p.filter(g=>g!==l);m.length===0?h.delete(f):h.set(f,m)}if(c.bySubcircuit&&t.indexes.bySubcircuit&&"subcircuit_id"in l){const d=l.subcircuit_id;if(d){const f=(t.indexes.bySubcircuit.get(d)||[]).filter(p=>p!==l);f.length===0?t.indexes.bySubcircuit.delete(d):t.indexes.bySubcircuit.set(d,f)}}if(c.byCustomField&&t.indexes.byCustomField)for(const d of t.indexes.byCustomField.values())for(const[h,f]of d.entries()){const p=f.filter(m=>m!==l);p.length===0?d.delete(h):d.set(h,p)}},update:(a,c)=>{const l=e.indexConfig||{};let u;if(l.byId&&t.indexes.byId?u=t.indexes.byId.get(`${s}:${a}`):l.byType&&t.indexes.byType?u=(t.indexes.byType.get(s)||[]).find(h=>h[`${s}_id`]===a):u=n.find(d=>d.type===s&&d[`${s}_id`]===a),!u)return null;if(l.byRelation&&t.indexes.byRelation){const d=Object.entries(u);for(const[h,f]of d)if(h.endsWith("_id")&&h!==`${u.type}_id`&&typeof f=="string"&&h in c&&c[h]!==f){const p=t.indexes.byRelation.get(h);if(p){const g=(p.get(f)||[]).filter(y=>y!==u);g.length===0?p.delete(f):p.set(f,g)}}}if(l.bySubcircuit&&t.indexes.bySubcircuit&&"subcircuit_id"in u&&"subcircuit_id"in c){const d=u.subcircuit_id,h=c.subcircuit_id;if(d!==h){const p=(t.indexes.bySubcircuit.get(d)||[]).filter(m=>m!==u);p.length===0?t.indexes.bySubcircuit.delete(d):t.indexes.bySubcircuit.set(d,p)}}if(l.byCustomField&&t.indexes.byCustomField){for(const d of l.byCustomField)if(d in u&&d in c&&u[d]!==c[d]){const h=t.indexes.byCustomField.get(d);if(h){const f=String(u[d]),m=(h.get(f)||[]).filter(g=>g!==u);m.length===0?h.delete(f):h.set(f,m)}}}if(Object.assign(u,c),t.editCount++,l.byRelation&&t.indexes.byRelation){const d=Object.entries(u);for(const[h,f]of d)if(h.endsWith("_id")&&h!==`${u.type}_id`&&typeof f=="string"&&h in c){const p=t.indexes.byRelation.get(h)||new Map,m=p.get(f)||[];m.includes(u)||(m.push(u),p.set(f,m),t.indexes.byRelation.set(h,p))}}if(l.bySubcircuit&&t.indexes.bySubcircuit&&"subcircuit_id"in u&&"subcircuit_id"in c){const d=u.subcircuit_id;if(d&&typeof d=="string"){const h=t.indexes.bySubcircuit.get(d)||[];h.includes(u)||(h.push(u),t.indexes.bySubcircuit.set(d,h))}}if(l.byCustomField&&t.indexes.byCustomField){for(const d of l.byCustomField)if(d in u&&d in c){const h=u[d];if(h!==void 0&&(typeof h=="string"||typeof h=="number")){const f=String(h),p=t.indexes.byCustomField.get(d),m=p.get(f)||[];m.includes(u)||(m.push(u),p.set(f,m))}}}return u},select:a=>{if(s==="source_component")return n.find(c=>c.type==="source_component"&&c.name===a.replace(/\./g,""))||null;if(s==="pcb_port"||s==="source_port"||s==="schematic_port"){const[c,l]=a.replace(/\./g,"").split(/[\s\>]+/),u=n.find(h=>h.type==="source_component"&&h.name===c);if(!u)return null;const d=n.find(h=>h.type==="source_port"&&h.source_component_id===u.source_component_id&&(h.name===l||(h.port_hints??[]).includes(l)));if(!d)return null;if(s==="source_port")return d;if(s==="pcb_port")return n.find(h=>h.type==="pcb_port"&&h.source_port_id===d.source_port_id)||null;if(s==="schematic_port")return n.find(h=>h.type==="schematic_port"&&h.source_port_id===d.source_port_id)||null}return null}}}})};Kdt.unparsed=Kdt;var fYn=n=>{const e=n.type;return n[`${e}_id`]},Qdt=(n,e)=>({minX:Math.min(n.minX,e.minX),minY:Math.min(n.minY,e.minY),maxX:Math.max(n.maxX,e.maxX),maxY:Math.max(n.maxY,e.maxY)}),ZG=(n,e,t)=>{const r=t/2;return{minX:n-r,minY:e-r,maxX:n+r,maxY:e+r}},mYn=(n,e,t,r,i)=>{const o=t/2,s=r/2,a=i*Math.PI/180,c=Math.cos(a),l=Math.sin(a),u=[{x:-o,y:-s},{x:o,y:-s},{x:o,y:s},{x:-o,y:s}].map(d=>({x:n+d.x*c-d.y*l,y:e+d.x*l+d.y*c}));return{minX:Math.min(...u.map(d=>d.x)),minY:Math.min(...u.map(d=>d.y)),maxX:Math.max(...u.map(d=>d.x)),maxY:Math.max(...u.map(d=>d.y))}},Yxe=n=>{let e=Number.POSITIVE_INFINITY,t=Number.POSITIVE_INFINITY,r=Number.NEGATIVE_INFINITY,i=Number.NEGATIVE_INFINITY;for(const o of n){if(!o.type.startsWith("pcb_"))continue;if(o.type==="pcb_smtpad"&&o.shape==="polygon"&&Array.isArray(o.points)){for(const u of o.points)e=Math.min(e,u.x),t=Math.min(t,u.y),r=Math.max(r,u.x),i=Math.max(i,u.y);continue}if(o.type==="pcb_hole"&&o.hole_shape==="circle"){const u=ZG(o.x,o.y,o.hole_diameter);e=Math.min(e,u.minX),t=Math.min(t,u.minY),r=Math.max(r,u.maxX),i=Math.max(i,u.maxY);continue}if(o.type==="pcb_plated_hole"){let u;if("outer_diameter"in o&&typeof o.outer_diameter=="number"?u=ZG(o.x,o.y,o.outer_diameter):"hole_diameter"in o&&typeof o.hole_diameter=="number"&&(u=ZG(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 d=mYn(o.x,o.y,o.rect_pad_width,o.rect_pad_height,"rect_ccw_rotation"in o?o.rect_ccw_rotation??0:0);u=u?Qdt(u,d):d}if("hole_diameter"in o&&typeof o.hole_diameter=="number"){const d=ZG(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);u=u?Qdt(u,d):d}if(u){e=Math.min(e,u.minX),t=Math.min(t,u.minY),r=Math.max(r,u.maxX),i=Math.max(i,u.maxY);continue}}let s,a,c,l;if("x"in o&&"y"in o&&(s=Number(o.x),a=Number(o.y)),"outer_diameter"in o&&(c=Number(o.outer_diameter),l=Number(o.outer_diameter)),"width"in o&&(c=Number(o.width)),"height"in o&&(l=Number(o.height)),"center"in o&&(s=o.center.x,a=o.center.y),s!==void 0&&a!==void 0)e=Math.min(e,s),t=Math.min(t,a),r=Math.max(r,s),i=Math.max(i,a),c!==void 0&&l!==void 0&&(e=Math.min(e,s-c/2),t=Math.min(t,a-l/2),r=Math.max(r,s+c/2),i=Math.max(i,a+l/2)),"radius"in o&&(e=Math.min(e,s-o.radius),t=Math.min(t,a-o.radius),r=Math.max(r,s+o.radius),i=Math.max(i,a+o.radius));else if(o.type==="pcb_trace")for(const u of o.route)e=Math.min(e,u.x),t=Math.min(t,u.y),r=Math.max(r,u.x),i=Math.max(i,u.y);else if(o.type==="pcb_courtyard_outline")for(const u of o.outline)e=Math.min(e,u.x),t=Math.min(t,u.y),r=Math.max(r,u.x),i=Math.max(i,u.y);else if(o.type==="pcb_courtyard_polygon")for(const u of o.points)e=Math.min(e,u.x),t=Math.min(t,u.y),r=Math.max(r,u.x),i=Math.max(i,u.y)}return{minX:e,minY:t,maxX:r,maxY:i}};function yYn(n){let e=0;if(n.length==0)return e;for(var t=0;t<n.length;t++){var r=n.charCodeAt(t);e=(e<<5)-e+r,e=e&e}return Math.abs(e)}var Jdt=[["#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"]],gYn=n=>{let{x:e,y:t,width:r,height:i}={...n,...n.size,...n.center,...n.position};if(n.x1!==void 0&&n.x2!==void 0&&n.y1!==void 0&&n.y2!==void 0&&(e=(n.x1+n.x2)/2,t=(n.y1+n.y2)/2,r=Math.abs(n.x1-n.x2),i=Math.abs(n.y1-n.y2)),n.points&&Array.isArray(n.points)&&n.points.length>0){const a=n.points.map(f=>f.x),c=n.points.map(f=>f.y),l=Math.min(...a),u=Math.max(...a),d=Math.min(...c),h=Math.max(...c);e=(l+u)/2,t=(d+h)/2,r=u-l,i=h-d}const o=n.text||n.name||n.source?.text||n.source?.name||"?",s=n;return e===void 0||t===void 0?null:(r===void 0&&"outer_diameter"in n&&(r=n.outer_diameter,i=n.outer_diameter),(r===void 0||i===void 0)&&(r=.1,i=.1),{x:e,y:t,width:r,height:i,title:o,content:s,bg_color:Jdt[yYn(n.type||o)%Jdt.length]?.[4]??"#f00"})},_Yn=n=>!!n,xYn=n=>{const e=n.filter(l=>l.type.startsWith("pcb_")||l.type.startsWith("schematic_")).concat(n.filter(l=>l.type==="pcb_trace"||l.type==="schematic_trace").flatMap(l=>l.route)).map(l=>gYn(l)).filter(_Yn);if(e.length===0)return{center:{x:0,y:0},width:0,height:0};let t=e[0].x-e[0].width/2,r=e[0].x+e[0].width/2,i=e[0].y-e[0].height/2,o=e[0].y+e[0].height/2;for(const l of e.slice(1))t=Math.min(t,l.x-l.width/2),r=Math.max(r,l.x+l.width/2),i=Math.min(i,l.y-l.height/2),o=Math.max(o,l.y+l.height/2);const s=r-t,a=o-i;return{center:{x:t+s/2,y:i+a/2},width:s,height:a}},fy={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"},BS=(n,e)=>{if(typeof window>"u")return e;try{const t=localStorage.getItem(n);return t!==null?JSON.parse(t):e}catch{return e}},jS=(n,e)=>{if(!(typeof window>"u"))try{localStorage.setItem(n,JSON.stringify(e))}catch{}},bYn=(n,e)=>{if(typeof window>"u")return e;try{const t=localStorage.getItem(n);return t!==null?JSON.parse(t):e}catch{return e}},vYn=(n,e)=>{if(!(typeof window>"u"))try{localStorage.setItem(n,JSON.stringify(e))}catch{}},wYn="named_only",SYn=(n={},e=!1)=>BOe(t=>({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:BS(fy.IS_SHOWING_COPPER_POURS,!0),is_showing_courtyards:BS(fy.IS_SHOWING_COURTYARDS,!0),is_showing_pcb_groups:e?!1:BS(fy.IS_SHOWING_PCB_GROUPS,!0),is_showing_group_anchor_offsets:BS(fy.IS_SHOWING_GROUP_ANCHOR_OFFSETS,!1),is_showing_solder_mask:BS(fy.IS_SHOWING_SOLDER_MASK,!1),is_showing_silkscreen:BS(fy.IS_SHOWING_SILKSCREEN,!0),is_showing_fabrication_notes:BS(fy.IS_SHOWING_FABRICATION_NOTES,!1),pcb_group_view_mode:e?"all":bYn(fy.PCB_GROUP_VIEW_MODE,wYn),hovered_error_id:null,...n,selectLayer:r=>t({selected_layer:r}),setEditMode:r=>t({in_edit_mode:r!=="off",in_move_footprint_mode:r==="move_footprint",in_draw_trace_mode:r==="draw_trace",is_moving_component:!1,is_drawing_trace:!1}),setIsShowingRatsNest:r=>t({is_showing_rats_nest:r}),setIsMovingComponent:r=>t({is_moving_component:r}),setIsDrawingTrace:r=>t({is_drawing_trace:r}),setIsMouseOverContainer:r=>t({is_mouse_over_container:r}),setIsShowingMultipleTracesLength:r=>t({is_showing_multiple_traces_length:r}),setIsShowingAutorouting:r=>t({is_showing_autorouting:r}),setIsShowingDrcErrors:r=>t({is_showing_drc_errors:r}),setIsShowingCopperPours:r=>{jS(fy.IS_SHOWING_COPPER_POURS,r),t({is_showing_copper_pours:r})},setIsShowingCourtyards:r=>{jS(fy.IS_SHOWING_COURTYARDS,r),t({is_showing_courtyards:r})},setIsShowingPcbGroups:r=>{e||(jS(fy.IS_SHOWING_PCB_GROUPS,r),t({is_showing_pcb_groups:r}))},setIsShowingGroupAnchorOffsets:r=>{jS(fy.IS_SHOWING_GROUP_ANCHOR_OFFSETS,r),t({is_showing_group_anchor_offsets:r})},setIsShowingSolderMask:r=>{jS(fy.IS_SHOWING_SOLDER_MASK,r),t({is_showing_solder_mask:r})},setIsShowingSilkscreen:r=>{jS(fy.IS_SHOWING_SILKSCREEN,r),t({is_showing_silkscreen:r})},setIsShowingFabricationNotes:r=>{jS(fy.IS_SHOWING_FABRICATION_NOTES,r),t({is_showing_fabrication_notes:r})},setPcbGroupViewMode:r=>{e||(vYn(fy.PCB_GROUP_VIEW_MODE,r),t({pcb_group_view_mode:r}))},setHoveredErrorId:r=>t({hovered_error_id:r})})),Pd=n=>{const e=q.useContext(e0t);return ZOe(e,n)},e0t=q.createContext(null),MYn=({children:n,initialState:e,disablePcbGroups:t})=>{const r=q.useMemo(()=>SYn(e,t),[t]);return V.jsx(e0t.Provider,{value:r,children:n})},EYn=()=>{const n=Pd(t=>t.pcb_viewer_id),e=(t,r)=>Al(t,{containerId:n,...r});return e.error=(t,r)=>Al.error(t,{containerId:n,...r}),e.promise=Al.promise,e},TYn=()=>{q.useEffect(()=>{mjn()},[]);const n=Pd(e=>e.pcb_viewer_id);return V.jsx(fjn,{position:"top-center",containerId:n})};function CYn(){var n=q.useRef(!1),e=q.useCallback(function(){return n.current},[]);return q.useEffect(function(){return n.current=!0,function(){n.current=!1}},[]),e}var PYn=function(n){n===void 0&&(n={});var e=q.useState(n),t=e[0],r=e[1],i=q.useCallback(function(o){r(function(s){return Object.assign({},s,o instanceof Function?o(s):o)})},[]);return[t,i]},AYn=PYn,RYn=function(){},t0t=typeof window<"u",NYn=$xe(WHn()),IYn=function(){var n=CYn(),e=AYn({value:void 0,error:void 0,noUserInteraction:!0}),t=e[0],r=e[1],i=q.useCallback(function(o){if(n()){var s,a;try{if(typeof o!="string"&&typeof o!="number"){var c=new Error("Cannot copy typeof "+typeof o+" to clipboard, must be a string");console.error(c),r({value:o,error:c,noUserInteraction:!0});return}else if(o===""){var c=new Error("Cannot copy empty string to clipboard.");console.error(c),r({value:o,error:c,noUserInteraction:!0});return}a=o.toString(),s=(0,NYn.default)(a),r({value:a,error:void 0,noUserInteraction:s})}catch(l){r({value:a,error:l,noUserInteraction:s})}}},[]);return[t,i]},kYn=IYn,OYn=t0t?q.useLayoutEffect:q.useEffect,LYn=OYn,n0t={x:0,y:0,width:0,height:0,top:0,left:0,bottom:0,right:0};function DYn(){var n=q.useState(null),e=n[0],t=n[1],r=q.useState(n0t),i=r[0],o=r[1],s=q.useMemo(function(){return new window.ResizeObserver(function(a){if(a[0]){var c=a[0].contentRect,l=c.x,u=c.y,d=c.width,h=c.height,f=c.top,p=c.left,m=c.bottom,g=c.right;o({x:l,y:u,width:d,height:h,top:f,left:p,bottom:m,right:g})}})},[]);return LYn(function(){if(e)return s.observe(e),function(){s.disconnect()}},[e]),[t,i]}var BO=t0t&&typeof window.ResizeObserver<"u"?DYn:function(){return[RYn,n0t]},r0t=({initialTransform:n,initialTouch1:e,initialTouch2:t,finalTouch1:r,finalTouch2:i})=>{if(!r||!i)return n;const o={x:(e.x+t.x)/2,y:(e.y+t.y)/2},s={x:(r.x+i.x)/2,y:(r.y+i.y)/2},a=Math.hypot(t.x-e.x,t.y-e.y),c=Math.hypot(i.x-r.x,i.y-r.y),l=a===0?1:c/a,u=s.x-o.x,d=s.y-o.y;return hi(xi(u,d),xi(o.x,o.y),Gu(l,l),xi(-o.x,-o.y),n)},zYn=(n={})=>{const e=q.useRef(null),[t,r]=q.useState(0),i=n.canvasElm??e.current,[o,s]=q.useState(n.initialTransform??Jc()),[a,c]=q.useState(0),[l,u]=q.useReducer(x=>x+1,0),d=q.useCallback(x=>{n.onSetTransform&&n.onSetTransform(x),n.transform||s(x)},[n.onSetTransform,s]),h=q.useCallback(x=>{d(x),u()},[d]),f=n.transform??o,p=q.useCallback(()=>{r(Date.now())},[]),m=q.useRef("none"),g=q.useRef(null),y=q.useRef(null);q.useEffect(()=>{const x=n.canvasElm??e.current;if(x&&!i){c(a+1);return}if(!x){const W=setTimeout(()=>{c(a+1)},100);return()=>clearTimeout(W)}let b=n.transform??o,w={x:0,y:0},S={x:0,y:0},E=!1;const C=W=>({x:W.pageX-x.getBoundingClientRect().left-window.scrollX,y:W.pageY-x.getBoundingClientRect().top-window.scrollY});function A(W){n.enabled!==!1&&(n.shouldDrag&&!n.shouldDrag(W)||(w=C(W),!(Date.now()-t<100)&&(E=!0,W.preventDefault())))}function R(W){if(!E||n.enabled===!1||n.shouldDrag&&!n.shouldDrag(W))return;S=C(W);const Q=hi(xi(S.x-w.x,S.y-w.y),b);d(Q),b=Q,E=!1}function L(W){if(C(W),!E||n.enabled===!1||n.shouldDrag&&!n.shouldDrag(W))return;S=C(W);const Q=hi(xi(S.x-w.x,S.y-w.y),b);d(Q)}function O(W){if(n.enabled===!1||n.shouldDrag&&!n.shouldDrag(W))return;const Q=C(W),ne=hi(xi(Q.x,Q.y),Gu(1-W.deltaY/1e3,1-W.deltaY/1e3),xi(-Q.x,-Q.y),b);d(ne),b=ne,W.preventDefault()}function F(W){if(!E||n.shouldDrag&&!n.shouldDrag(W))return;if(x){const ne=x.getBoundingClientRect();if(W.clientX>=ne.left+10&&W.clientX<=ne.right-10&&W.clientY>=ne.top+10&&W.clientY<=ne.bottom-10)return}E=!1,S=C(W);const Q=hi(xi(S.x-w.x,S.y-w.y),b);d(Q),b=Q}function B(W){if(W.preventDefault(),n.enabled!==!1){if(W.touches.length===1){m.current="drag";const Q=W.touches[0];g.current={initialTransform:b,initialTouch:{x:Q.clientX,y:Q.clientY}}}else if(W.touches.length===2){m.current="pinch";const Q=W.touches[0],ne=W.touches[1];y.current={initialTransform:b,initialTouch1:{x:Q.clientX,y:Q.clientY},initialTouch2:{x:ne.clientX,y:ne.clientY},finalTouch1:null,finalTouch2:null}}}}function j(W){if(W.preventDefault(),n.enabled!==!1){if(m.current==="drag"&&W.touches.length===1&&g.current){const Q=W.touches[0],ne={x:Q.clientX,y:Q.clientY},ue=ne.x-g.current.initialTouch.x,te=ne.y-g.current.initialTouch.y,re=hi(xi(ue,te),g.current.initialTransform);d(re)}else if(m.current==="pinch"&&W.touches.length===2&&y.current){const Q=W.touches[0],ne=W.touches[1];y.current.finalTouch1={x:Q.clientX,y:Q.clientY},y.current.finalTouch2={x:ne.clientX,y:ne.clientY};const ue=r0t(y.current);d(ue)}}}function G(W){W.preventDefault();const Q=W.changedTouches[0];if(m.current==="drag"&&g.current&&Q){const ne={x:Q.clientX,y:Q.clientY},ue=ne.x-g.current.initialTouch.x,te=ne.y-g.current.initialTouch.y,re=hi(xi(ue,te),g.current.initialTransform);d(re),b=re}else if(m.current==="pinch"&&y.current){const ne=r0t(y.current);d(ne),b=ne}m.current="none",g.current=null,y.current=null}return x.addEventListener("mousedown",A),x.addEventListener("mouseup",R),window.addEventListener("mousemove",L),x.addEventListener("mouseout",F),x.addEventListener("wheel",O),x.addEventListener("touchstart",B,{passive:!1}),x.addEventListener("touchmove",j,{passive:!1}),x.addEventListener("touchend",G,{passive:!1}),x.addEventListener("touchcancel",G,{passive:!1}),()=>{x.removeEventListener("mousedown",A),x.removeEventListener("mouseup",R),window.removeEventListener("mousemove",L),x.removeEventListener("mouseout",F),x.removeEventListener("wheel",O),x.removeEventListener("touchstart",B),x.removeEventListener("touchmove",j),x.removeEventListener("touchend",G),x.removeEventListener("touchcancel",G)}},[i,a,l,t,n.enabled,n.shouldDrag]);const _=q.useCallback(x=>mt(f,x),[f]);return{ref:e,transform:f,applyTransformToPoint:_,setTransform:h,cancelDrag:p}},$Yn=zYn;function FYn(n){const e=new Map;let t=0;function r(i){for(const[,s]of e)if(s.has(i))return s;const o=new Set;return e.set(`connectivity_net${t++}`,o),o}for(const i of n){let o=null;for(const s of i){if(!o)o=r(s);else if(!o.has(s)){const a=r(s);if(a!==o){for(const c of a)o.add(c);e.delete(Array.from(e.entries()).find(([,c])=>c===a)[0])}}o.add(s)}}return Object.fromEntries(Array.from(e.entries()).map(([i,o])=>[i,Array.from(o)]))}var BYn=class{netMap;idToNetMap;constructor(n){this.netMap=n,this.idToNetMap={};for(const[e,t]of Object.entries(n))for(const r of t)this.idToNetMap[r]=e}addConnections(n){for(const e of n){const t=new Set;for(const i of e){const o=this.idToNetMap[i];o&&t.add(o)}let r;if(t.size===0)r=`connectivity_net${Object.keys(this.netMap).length}`,this.netMap[r]=[];else if(t.size===1)r=t.values().next().value??`connectivity_net${Object.keys(this.netMap).length}`;else{r=t.values().next().value??`connectivity_net${Object.keys(this.netMap).length}`;for(const i of t)if(i!==r){this.netMap[r].push(...this.netMap[i]),this.netMap[i]=this.netMap[r];for(const o of this.netMap[r])this.idToNetMap[o]=r}}for(const i of e)this.netMap[r].includes(i)||this.netMap[r].push(i),this.idToNetMap[i]=r}}getIdsConnectedToNet(n){return this.netMap[n]||[]}getNetConnectedToId(n){return this.idToNetMap[n]}areIdsConnected(n,e){if(n===e)return!0;const t=this.getNetConnectedToId(n);if(!t)return!1;const r=this.getNetConnectedToId(e);return r?t===r||r===n||r===n:!1}areAllIdsConnected(n){const e=this.getNetConnectedToId(n[0]);for(const t of n){const r=this.getNetConnectedToId(t);if(r===void 0||r!==e)return!1}return!0}},i0t=n=>{const e=[];for(const r of n)if(r.type==="source_trace")e.push([r.source_trace_id,...r.connected_source_port_ids??[],...r.connected_source_net_ids??[]].filter(Boolean));else if(r.type==="pcb_port"){const{pcb_port_id:i,source_port_id:o}=r;o&&i&&e.push([o,i])}else if(r.type==="pcb_smtpad"){const{pcb_smtpad_id:i,pcb_port_id:o}=r;o&&i&&e.push([i,o])}else if(r.type==="pcb_plated_hole"){const{pcb_plated_hole_id:i,pcb_port_id:o}=r;o&&i&&e.push([i,o])}else if(r.type==="pcb_trace"){const{pcb_trace_id:i,source_trace_id:o}=r,s=Array.isArray(r.route)?r.route.filter(a=>a&&a.route_type==="wire"):[];if(o&&i&&e.push([i,o]),Array.isArray(s)){const a=s.find(l=>l?.start_pcb_port_id)?.start_pcb_port_id,c=s.find(l=>l?.end_pcb_port_id)?.end_pcb_port_id;a&&i&&c&&e.push([a,i,c])}}else if(r.type==="pcb_via"){const{pcb_via_id:i,pcb_trace_id:o}=r;o&&i&&e.push([i,o])}else if(r.type==="source_component"&&r.internally_connected_source_port_ids)for(const i of r.internally_connected_source_port_ids)e.push(i);const t=FYn(e);return new BYn(t)};function jYn({primitivesWithoutInteractionMetadata:n,drawingObjectIdsWithMouseOver:e,primitiveIdsInMousedOverNet:t}){const r=[];for(const i of n){const o={...i};i?.layer==="drill"?(o.is_in_highlighted_net=!1,o.is_mouse_over=!1):e.has(i._pcb_drawing_object_id)?o.is_mouse_over=!0:i._element&&("pcb_trace_id"in i._element&&t.includes(i._element.pcb_trace_id)||"pcb_port_id"in i._element&&t.includes(i._element.pcb_port_id))?o.is_in_highlighted_net=!0:(o.is_in_highlighted_net=!1,o.is_mouse_over=!1),r.push(o)}return r}function UYn(n,e){if(n.length<2)throw new Error("Stroke must have at least two points");const t=n.map(d=>Array.isArray(d)?{x:d[0],y:d[1]}:d),r=[],i=[];function o(d,h){const f=h.x-d.x,p=h.y-d.y,m=Math.sqrt(f*f+p*p);return{x:-p/m,y:f/m}}function s(d,h,f,p){const m=p/2,g={x:d.x+h.x*m*f,y:d.y+h.y*m*f};f>0?r.push(g):i.unshift(g)}const a=o(t[0],t[1]),c=t[0].trace_width??e;s(t[0],a,1,c),s(t[0],a,-1,c);for(let d=1;d<t.length-1;d++){const h=t[d-1],f=t[d],p=t[d+1],m=o(h,f),g=o(f,p),y=m.x+g.x,_=m.y+g.y,x=Math.sqrt(y*y+_*_),b=f.trace_width??e;if(x/2>2*(b/2))s(f,m,1,b),s(f,g,1,b),s(f,m,-1,b),s(f,g,-1,b);else{const S=1/x;s(f,{x:y*S,y:_*S},1,b),s(f,{x:y*S,y:_*S},-1,b)}}const l=o(t[t.length-2],t[t.length-1]),u=t[t.length-1].trace_width??e;return s(t[t.length-1],l,1,u),s(t[t.length-1],l,-1,u),[...r,...i]}var HYn=(n,e)=>{const{x:t,y:r,width:i,height:o,layer:s,rect_border_radius:a}=n,c=n.corner_radius??a??0,l=[{_pcb_drawing_object_id:A4("rect"),pcb_drawing_type:"rect",x:t,y:r,w:i,h:o,layer:s||"top",_element:n,_parent_pcb_component:e._parent_pcb_component,_parent_source_component:e._parent_source_component,_source_port:e._source_port,roundness:c,...n.shape==="rotated_rect"&&n.ccw_rotation!==void 0?{ccw_rotation:n.ccw_rotation}:{}}];if(n.is_covered_with_solder_mask){const u=s==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",h={...{_pcb_drawing_object_id:A4("rect"),pcb_drawing_type:"rect",x:t,y:r,w:i,h:o,layer:u,_element:n,_parent_pcb_component:e._parent_pcb_component,_parent_source_component:e._parent_source_component,_source_port:e._source_port,roundness:c,...n.shape==="rotated_rect"&&n.ccw_rotation!==void 0?{ccw_rotation:n.ccw_rotation}:{}},..."solder_mask_color"in n&&n.solder_mask_color?{color:n.solder_mask_color}:{}};l.push(h)}return l},YYn=(n,e)=>{const{x:t,y:r,radius:i,layer:o}=n,s=[{_pcb_drawing_object_id:A4("circle"),pcb_drawing_type:"circle",x:t,y:r,r:i,layer:o||"top",_element:n,_parent_pcb_component:e._parent_pcb_component,_parent_source_component:e._parent_source_component,_source_port:e._source_port}];if(n.is_covered_with_solder_mask){const a=o==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",c={_pcb_drawing_object_id:A4("circle"),pcb_drawing_type:"circle",x:t,y:r,r:i,layer:a,_element:n,_parent_pcb_component:e._parent_pcb_component,_parent_source_component:e._parent_source_component,_source_port:e._source_port,..."solder_mask_color"in n&&n.solder_mask_color?{color:n.solder_mask_color}:{}};s.push(c)}return s},XYn=(n,e)=>{const{layer:t,points:r}=n,i=[{_pcb_drawing_object_id:A4("polygon"),pcb_drawing_type:"polygon",points:Xxe(r),layer:t||"top",_element:n,_parent_pcb_component:e._parent_pcb_component,_parent_source_component:e._parent_source_component,_source_port:e._source_port}];if(n.is_covered_with_solder_mask){const o=t==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",s={_pcb_drawing_object_id:A4("polygon"),pcb_drawing_type:"polygon",points:Xxe(r),layer:o,_element:n,_parent_pcb_component:e._parent_pcb_component,_parent_source_component:e._parent_source_component,_source_port:e._source_port,..."solder_mask_color"in n&&n.solder_mask_color?{color:n.solder_mask_color}:{}};i.push(s)}return i},VYn=(n,e)=>{const{x:t,y:r,width:i,height:o,layer:s}=n,a=[{_pcb_drawing_object_id:A4("pill"),pcb_drawing_type:"pill",x:t,y:r,w:i,h:o,layer:s||"top",_element:n,_parent_pcb_component:e._parent_pcb_component,_parent_source_component:e._parent_source_component,_source_port:e._source_port}];if(n.is_covered_with_solder_mask){const c=s==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",l={_pcb_drawing_object_id:A4("pill"),pcb_drawing_type:"pill",x:t,y:r,w:i,h:o,layer:c,_element:n,_parent_pcb_component:e._parent_pcb_component,_parent_source_component:e._parent_source_component,_source_port:e._source_port,..."solder_mask_color"in n&&n.solder_mask_color?{color:n.solder_mask_color}:{}};a.push(l)}return a},GYn=(n,e)=>{const{x:t,y:r,width:i,height:o,layer:s,ccw_rotation:a}=n,c=[{_pcb_drawing_object_id:A4("pill"),pcb_drawing_type:"pill",x:t,y:r,w:i,h:o,layer:s||"top",_element:n,_parent_pcb_component:e._parent_pcb_component,_parent_source_component:e._parent_source_component,_source_port:e._source_port,ccw_rotation:a}];if(n.is_covered_with_solder_mask){const l=s==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",u={_pcb_drawing_object_id:A4("pill"),pcb_drawing_type:"pill",x:t,y:r,w:i,h:o,layer:l,_element:n,_parent_pcb_component:e._parent_pcb_component,_parent_source_component:e._parent_source_component,_source_port:e._source_port,ccw_rotation:a,..."solder_mask_color"in n&&n.solder_mask_color?{color:n.solder_mask_color}:{}};c.push(u)}return c},cd=0,A4=n=>`${n}_${cd++}`,Xxe=n=>(n??[]).map(e=>({x:gn.parse(e.x),y:gn.parse(e.y)})),qYn=(n,e)=>{const t="pcb_component_id"in n?e.find(s=>s.type==="pcb_component"&&s.pcb_component_id===n.pcb_component_id):void 0,r=t&&"source_component_id"in t?e.find(s=>s.type==="source_component"&&s.source_component_id===t.source_component_id):void 0,i="source_port_id"in n?n.source_port_id:"pcb_port_id"in n?W9(e).pcb_port.get(n.pcb_port_id)?.source_port_id:void 0,o=i?e.find(s=>s.type==="source_port"&&s.source_port_id===i):void 0;switch(n.type){case"pcb_smtpad":{const s={_parent_pcb_component:t,_parent_source_component:r,_source_port:o};return n.shape==="rect"||n.shape==="rotated_rect"?HYn(n,s):n.shape==="circle"?YYn(n,s):n.shape==="polygon"?XYn(n,s):n.shape==="pill"?VYn(n,s):n.shape==="rotated_pill"?GYn(n,s):[]}case"pcb_trace":{const s=[];if(n.route_thickness_mode==="interpolated"){const l=n.route.map(h=>({x:h.x,y:h.y,trace_width:h.route_type==="wire"?h.width:.5})),u=UYn(l,.5),d=n.route[0].layer;return s.push({_pcb_drawing_object_id:`polygon_${cd++}`,_element:n,pcb_drawing_type:"polygon",points:u,layer:d}),n.route.forEach(h=>{h.route_type==="via"&&s.push({_pcb_drawing_object_id:`circle_${cd++}`,_element:n,pcb_drawing_type:"circle",x:h.x,y:h.y,r:h.outer_diameter/2,layer:h.from_layer})}),s}let a=null,c=null;for(const l of n.route)l.route_type==="wire"&&(a!==null&&c!==null&&s.push({_pcb_drawing_object_id:`line_${cd++}`,_element:n,pcb_drawing_type:"line",x1:a,y1:c,x2:l.x,y2:l.y,width:l.width,squareCap:!1,layer:l.layer}),a=l.x,c=l.y);return s}case"pcb_via":{const{x:s,y:a,outer_diameter:c,hole_diameter:l}=n,u=n.from_layer,d=n.to_layer,h=n.layers,f=[];u&&d?f.push(u,d):h&&Array.isArray(h)?f.push(...h):f.push("top","bottom");const p=[];for(const m of f)p.push({_pcb_drawing_object_id:`circle_${cd++}`,pcb_drawing_type:"circle",x:s,y:a,r:c/2,layer:m,_element:n,_parent_pcb_component:t,_parent_source_component:r});return p.push({_pcb_drawing_object_id:`circle_${cd++}`,pcb_drawing_type:"circle",x:s,y:a,r:l/2,layer:"drill",_element:n}),p}case"pcb_plated_hole":if(n.shape==="circle"){const{x:s,y:a,hole_diameter:c,outer_diameter:l}=n;return[{_pcb_drawing_object_id:`circle_${cd++}`,pcb_drawing_type:"circle",x:s,y:a,r:l/2,layer:"top",_element:n,_parent_pcb_component:t,_parent_source_component:r,_source_port:o},{_pcb_drawing_object_id:`circle_${cd++}`,pcb_drawing_type:"circle",x:s,y:a,r:c/2,layer:"drill",_element:n}]}else if(n.shape==="oval"){const{x:s,y:a,outer_height:c,outer_width:l,hole_height:u,hole_width:d}=n;return[{_pcb_drawing_object_id:`oval_${cd++}`,pcb_drawing_type:"oval",x:s,y:a,rX:l/2,rY:c/2,layer:"top",_element:n,_parent_pcb_component:t,_parent_source_component:r,_source_port:o},{_pcb_drawing_object_id:`oval_${cd++}`,_element:n,pcb_drawing_type:"oval",x:s,y:a,rX:d/2,rY:u/2,layer:"drill"}]}else if(n.shape==="pill"){const{x:s,y:a,outer_height:c,outer_width:l,hole_height:u,hole_width:d}=n;return[{_pcb_drawing_object_id:`pill_${cd++}`,pcb_drawing_type:"pill",x:s,y:a,w:l,h:c,layer:"top",_element:n,_parent_pcb_component:t,_parent_source_component:r,_source_port:o,ccw_rotation:n.ccw_rotation},{_pcb_drawing_object_id:`pill_${cd++}`,_element:n,pcb_drawing_type:"pill",x:s,y:a,w:d,h:u,layer:"drill",ccw_rotation:n.ccw_rotation}]}else if(n.shape==="circular_hole_with_rect_pad"){const{x:s,y:a,hole_diameter:c,rect_pad_width:l,rect_pad_height:u,rect_border_radius:d,hole_offset_x:h,hole_offset_y:f}=n,p=gn.parse(h??0),m=gn.parse(f??0);return[{_pcb_drawing_object_id:`rect_${cd++}`,pcb_drawing_type:"rect",x:s,y:a,w:l,h:u,layer:"top",_element:n,_parent_pcb_component:t,_parent_source_component:r,_source_port:o,roundness:d},{_pcb_drawing_object_id:`rect_${cd++}`,pcb_drawing_type:"rect",x:s,y:a,w:l,h:u,layer:"bottom",_element:n,_parent_pcb_component:t,_parent_source_component:r,_source_port:o,roundness:d,is_hoverable:!1},{_pcb_drawing_object_id:`circle_${cd++}`,_element:n,pcb_drawing_type:"circle",x:s+p,y:a+m,r:c/2,layer:"drill",is_hoverable:!1}]}else if(n.shape==="pill_hole_with_rect_pad"){const{x:s,y:a,hole_width:c,hole_height:l,rect_pad_width:u,rect_pad_height:d,rect_border_radius:h}=n;return[{_pcb_drawing_object_id:`rect_${cd++}`,pcb_drawing_type:"rect",x:s,y:a,w:u,h:d,layer:"top",_element:n,_parent_pcb_component:t,_parent_source_component:r,_source_port:o,roundness:h},{_pcb_drawing_object_id:`rect_${cd++}`,pcb_drawing_type:"rect",x:s,y:a,w:u,h:d,layer:"bottom",_element:n,_parent_pcb_component:t,_parent_source_component:r,_source_port:o,roundness:h,is_hoverable:!1},{_pcb_drawing_object_id:`pill_${cd++}`,_element:n,pcb_drawing_type:"pill",x:s,y:a,w:c,h:l,layer:"drill",is_hoverable:!1}]}else if(n.shape==="rotated_pill_hole_with_rect_pad"){const{x:s,y:a,hole_width:c,hole_height:l,hole_ccw_rotation:u,rect_pad_width:d,rect_pad_height:h,rect_ccw_rotation:f,rect_border_radius:p}=n;return[{_pcb_drawing_object_id:`rect_${cd++}`,pcb_drawing_type:"rect",x:s,y:a,w:d,h,layer:"top",_element:n,_parent_pcb_component:t,_parent_source_component:r,_source_port:o,ccw_rotation:f,roundness:p},{_pcb_drawing_object_id:`rect_${cd++}`,pcb_drawing_type:"rect",x:s,y:a,w:d,h,layer:"bottom",_element:n,_parent_pcb_component:t,_parent_source_component:r,_source_port:o,ccw_rotation:f,roundness:p,is_hoverable:!1},{_pcb_drawing_object_id:`pill_${cd++}`,_element:n,pcb_drawing_type:"pill",x:s,y:a,w:c,h:l,layer:"drill",ccw_rotation:u,is_hoverable:!1}]}else if(n.shape==="hole_with_polygon_pad"){const{x:s,y:a,pad_outline:c,hole_shape:l,hole_diameter:u,hole_width:d,hole_height:h,layers:f,hole_offset_x:p,hole_offset_y:m}=n,g=gn.parse(p??0),y=gn.parse(m??0),_=c,x=[];if(_&&Array.isArray(_)){const S=Xxe(_).map(E=>({x:E.x+s,y:E.y+a}));for(const E of f||["top","bottom"])x.push({_pcb_drawing_object_id:`polygon_${cd++}`,pcb_drawing_type:"polygon",points:S,layer:E,_element:n,_parent_pcb_component:t,_parent_source_component:r,_source_port:o})}const b={x:s+g,y:a+y},w=[];return l==="circle"?w.push({_pcb_drawing_object_id:`circle_${cd++}`,pcb_drawing_type:"circle",x:b.x,y:b.y,r:(u??0)/2,layer:"drill",_element:n,_parent_pcb_component:t,_parent_source_component:r}):l==="oval"?w.push({_pcb_drawing_object_id:`oval_${cd++}`,pcb_drawing_type:"oval",x:b.x,y:b.y,rX:(d??0)/2,rY:(h??0)/2,layer:"drill",_element:n,_parent_pcb_component:t,_parent_source_component:r}):(l==="pill"||l==="rotated_pill")&&w.push({_pcb_drawing_object_id:`pill_${cd++}`,pcb_drawing_type:"pill",x:b.x,y:b.y,w:d??0,h:h??0,layer:"drill",_element:n,_parent_pcb_component:t,_parent_source_component:r,ccw_rotation:n.ccw_rotation}),[...x,...w]}else return[]}return[]},fi={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)"}},z_=(n,e=1)=>{if(Math.abs(n.a)!==Math.abs(n.d))throw new Error("Cannot scale non-uniformly");return e*Math.abs(n.a)},Kl={elementOverlay:40,dimensionOverlay:40,editTraceHintOverlay:40,errorOverlay:40,pcbGroupOverlay:35,ratsNestOverlay:30,toolbarOverlay:70,warnings:30,topLayer:20,clickToInteractOverlay:100},KG={red:"red",black:"black",green:"green",board:"rgb(255, 255, 255)",other:"#eee",top:fi.board.copper.f,inner1:fi.board.copper.in1,inner2:fi.board.copper.in2,inner3:fi.board.copper.in3,inner4:fi.board.copper.in4,inner5:fi.board.copper.in5,inner6:fi.board.copper.in6,inner7:fi.board.copper.in7,inner8:fi.board.copper.in8,bottom:fi.board.copper.b,drill:fi.board.anchor,keepout:fi.board.background,tkeepout:fi.board.b_crtyd,tplace:fi.board.b_silks,top_courtyard:fi.board.f_crtyd,bottom_courtyard:fi.board.b_crtyd,top_silkscreen:fi.board.f_silks,bottom_silkscreen:fi.board.b_silks,top_fabrication:fi.board.f_fab,bottom_fabrication:fi.board.b_fab,soldermask_top:fi.board.soldermask.top,soldermask_bottom:fi.board.soldermask.bottom,soldermask_with_copper_top:fi.board.soldermaskWithCopper.top,soldermask_with_copper_bottom:fi.board.soldermaskWithCopper.bottom,bottom_notes:fi.board.user_2,top_notes:fi.board.user_2,...fi.board},WYn=["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"],ZYn=class{canvasLayerMap;ctxLayerMap;aperture;transform;foregroundLayer="top";lastPoint;constructor(n){this.canvasLayerMap=n,this.ctxLayerMap=Object.fromEntries(Object.entries(n).map(([e,t])=>[e,t.getContext("2d")])),this.transform=Jc(),this.transform.d*=-1,this.transform=hi(this.transform,xi(0,-500)),this.lastPoint={x:0,y:0},this.equip({})}clear(){for(const n of Object.values(this.ctxLayerMap))n.clearRect(0,0,n.canvas.width,n.canvas.height)}equip(n){this.aperture={fontSize:0,shape:"circle",mode:"add",size:0,color:"red",layer:"top",opacity:this.foregroundLayer===n.color?1:.5,...n}}drawMeshPattern(n,e,t,r,i,o=45){const s=this.getLayerCtx(),[a,c]=mt(this.transform,[n,e]),[l,u]=mt(this.transform,[n+t,e+r]),d=z_(this.transform,i);s.lineWidth=1,s.strokeStyle=this.aperture.color;const h=f=>{const p=Math.sin(f),m=Math.cos(f),g=Math.sqrt((l-a)**2+(u-c)**2);for(let y=-g;y<=g;y+=d)s.beginPath(),s.moveTo(a+y*m-g*p,c+y*p+g*m),s.lineTo(a+y*m+g*p,c+y*p-g*m),s.stroke()};h(o*Math.PI/180),h((o+90)*Math.PI/180)}rect({x:n,y:e,w:t,h:r,mesh_fill:i,is_filled:o=!0,has_stroke:s,is_stroke_dashed:a,stroke_width:c,roundness:l}){const[u,d]=mt(this.transform,[n-t/2,e-r/2]),[h,f]=mt(this.transform,[n+t/2,e+r/2]);this.applyAperture();const p=this.getLayerCtx(),m=l?z_(this.transform,l):0,g=s===void 0?o===!1:s;if(i)p.save(),p.beginPath(),m>0&&p.roundRect?p.roundRect(u,d,h-u,f-d,m):p.rect(u,d,h-u,f-d),p.clip(),this.drawMeshPattern(n-t/2,e-r/2,t,r,.15),p.restore(),m>0&&p.roundRect?(p.beginPath(),p.roundRect(u,d,h-u,f-d,m),p.stroke()):p.strokeRect(u,d,h-u,f-d);else if(o!==!1&&(m>0&&p.roundRect?(p.beginPath(),p.roundRect(u,d,h-u,f-d,m),p.fill()):p.fillRect(u,d,h-u,f-d)),g){const y=p.lineWidth;if(c!==void 0&&(p.lineWidth=z_(this.transform,c)),a){let _=[];const x=Math.abs(this.transform.a);if(x>0){const w=.1*x,S=w*1.3;w>.5&&(_=[w,S])}p.setLineDash(_)}m>0&&p.roundRect?(p.beginPath(),p.roundRect(u,d,h-u,f-d,m),p.stroke()):p.strokeRect(u,d,h-u,f-d),a&&p.setLineDash([]),c!==void 0&&(p.lineWidth=y)}}rotatedRect(n,e,t,r,i,o,s){const a=this.getLayerCtx();this.applyAperture();const[c,l]=mt(this.transform,[n-t/2,e-r/2]),[u,d]=mt(this.transform,[n+t/2,e+r/2]),h=o?z_(this.transform,o):0;a.save();const[f,p]=mt(this.transform,[n,e]);a.translate(f,p);const m=360-i;i&&a.rotate(m*Math.PI/180),a.translate(-f,-p),s?(a.beginPath(),h>0&&a.roundRect?a.roundRect(c,l,u-c,d-l,h):a.rect(c,l,u-c,d-l),a.clip(),this.drawMeshPattern(n-t/2,e-r/2,t,r,.15),h>0&&a.roundRect?(a.beginPath(),a.roundRect(c,l,u-c,d-l,h),a.stroke()):a.strokeRect(c,l,u-c,d-l)):h>0&&a.roundRect?(a.beginPath(),a.roundRect(c,l,u-c,d-l,h),a.fill()):a.fillRect(c,l,u-c,d-l),a.restore()}rotatedPill(n,e,t,r,i){const o=this.getLayerCtx();this.applyAperture(),o.save();const[s,a]=mt(this.transform,[n,e]);o.translate(s,a);const c=360-i;i&&o.rotate(c*Math.PI/180),o.translate(-s,-a),this.pill(n,e,t,r),o.restore()}circle(n,e,t,r,i=!0){const o=z_(this.transform,t),[s,a]=mt(this.transform,[n,e]);this.applyAperture();const c=this.getLayerCtx();r?(c.save(),c.beginPath(),c.arc(s,a,o,0,2*Math.PI),c.clip(),this.drawMeshPattern(n-t,e-t,t*2,t*2,.15),c.restore(),c.beginPath(),c.arc(s,a,o,0,2*Math.PI),c.stroke()):(c.beginPath(),c.arc(s,a,o,0,2*Math.PI),c.fill())}oval(n,e,t,r){const i=z_(this.transform,t),o=z_(this.transform,r),[s,a]=mt(this.transform,[n,e]);this.applyAperture();const c=this.getLayerCtx();c.beginPath(),c.ellipse(s,a,i,o,0,0,2*Math.PI),c.fill(),c.closePath()}pill(n,e,t,r){const[i,o]=mt(this.transform,[n-t/2,e+r/2]),s=z_(this.transform,t),a=z_(this.transform,r),c=Math.min(s,a)/2;this.applyAperture();const l=this.getLayerCtx();l.beginPath(),l.arc(i+c,o+c,c,Math.PI,Math.PI*1.5),l.arc(i+s-c,o+c,c,Math.PI*1.5,0),l.arc(i+s-c,o+a-c,c,0,Math.PI*.5),l.arc(i+c,o+a-c,c,Math.PI*.5,Math.PI),l.fill(),l.closePath()}polygon(n){if(n.length<3)return;this.applyAperture();const e=this.getLayerCtx(),t=n.map(i=>mt(this.transform,[i.x,i.y]));e.beginPath(),e.moveTo(t[0][0],t[0][1]);for(let i=1;i<t.length;i++)e.lineTo(t[i][0],t[i][1]);e.closePath(),e.fill("evenodd");const r=z_(this.transform,this.aperture.size);r>0&&(e.lineWidth=r,e.stroke())}debugText(n,e,t){const[r,i]=mt(this.transform,[e,t]);this.applyAperture();const o=this.getLayerCtx();o.font="10px sans-serif",o.fillText(n,r,i)}getLayerCtx(){const n=this.ctxLayerMap[this.aperture.layer];if(!n)throw new Error(`No context for layer "${this.aperture.layer}"`);return n}orderAndFadeLayers(){const{canvasLayerMap:n,foregroundLayer:e}=this,t=e==="top"?"soldermask_top":e==="bottom"?"soldermask_bottom":void 0,r=e==="top"?"top_silkscreen":e==="bottom"?"bottom_silkscreen":void 0,i=e==="top"?"top_notes":e==="bottom"?"bottom_notes":void 0,o=e==="top"?"top_fabrication":e==="bottom"?"bottom_fabrication":void 0,s=e==="top"?"top_courtyard":e==="bottom"?"bottom_courtyard":void 0,a=new Set([e,"drill","edge_cuts","other","board",...t?[t]:[],...r?[r]:[],...i?[i]:[],...o?[o]:[],...s?[s]:[]]),c=[e,"edge_cuts",...t?[t]:[],...r?[r]:[],...i?[i]:[],...o?[o]:[],...s?[s]:[]],l=[...WYn.filter(u=>!c.includes(u)),...e==="drill"?[]:[e],...t?[t]:[],"edge_cuts",...r?[r]:[],...i?[i]:[],...o?[o]:[],...s?[s]:[],"drill"];l.forEach((u,d)=>{const h=n[u];h&&(h.style.zIndex=`${Kl.topLayer-(l.length-d)}`,h.style.opacity=a.has(u)?"1":"0.5")})}applyAperture(){const{transform:n,aperture:e}=this;let{size:t,mode:r,color:i,fontSize:o,layer:s}=e;s in this.ctxLayerMap||(this.aperture.layer="other");const a=this.getLayerCtx();if(!a)throw new Error(`No context for layer "${this.foregroundLayer}"`);if(i||(i="undefined"),a.lineWidth=z_(n,t),a.lineCap="round",r==="add"){a.globalCompositeOperation="source-over";let c=KG[i.toLowerCase()];if(!c)try{c=pc(i).rgb().toString()}catch{console.warn(`Invalid color format: '${i}'`),c="white"}a.fillStyle=c,a.strokeStyle=c}else a.globalCompositeOperation="destination-out",a.fillStyle="rgba(0,0,0,1)",a.strokeStyle="rgba(0,0,0,1)";a.font=`${z_(Y2(n),o)}px sans-serif`}moveTo(n,e){this.lastPoint={x:n,y:e}}lineTo(n,e){const[t,r]=mt(this.transform,[n,e]),{size:i,shape:o,mode:s}=this.aperture,a=z_(this.transform,i),{lastPoint:c}=this,l=mt(this.transform,c);this.applyAperture();const u=this.getLayerCtx();o==="square"&&u.fillRect(l.x-a/2,l.y-a/2,a,a),u.beginPath(),u.moveTo(l.x,l.y),u.lineTo(t,r),u.stroke(),u.closePath(),o==="square"&&u.fillRect(t-a/2,r-a/2,a,a),this.lastPoint={x:n,y:e}}polygonWithArcs(n){const e=this.getLayerCtx(),t=r=>{if(r.vertices.length===0)return;const i=r.vertices[0],o=mt(this.transform,[i.x,i.y]);e.moveTo(o[0],o[1]);for(let s=0;s<r.vertices.length;s++){const a=r.vertices[s],c=r.vertices[(s+1)%r.vertices.length];if(a.bulge&&a.bulge!==0){const l=a.bulge,u=c.x-a.x,d=c.y-a.y,h=Math.sqrt(u*u+d*d);if(h<1e-9){const O=mt(this.transform,[c.x,c.y]);e.lineTo(O[0],O[1]);continue}const f=4*Math.atan(l),p=Math.abs(h/(2*Math.sin(f/2))),m=(a.x+c.x)/2,g=(a.y+c.y)/2,y=u/h,x=-(d/h),b=y,w=Math.sqrt(Math.max(0,p*p-(h/2)**2)),S=m+w*x*Math.sign(l),E=g+w*b*Math.sign(l),C=Math.atan2(a.y-E,a.x-S);let A=Math.atan2(c.y-E,c.x-S);l>0&&A<C?A+=2*Math.PI:l<0&&A>C&&(A-=2*Math.PI);const R=mt(this.transform,[S,E]),L=z_(this.transform,p);e.arc(R[0],R[1],L,-C,-A,l>0)}else{const l=mt(this.transform,[c.x,c.y]);e.lineTo(l[0],l[1])}}e.closePath()};if(e.beginPath(),t(n.outer_ring),n.inner_rings)for(const r of n.inner_rings)t(r);e.fill("evenodd")}};function KYn(n){return n.type==="pcb_copper_pour"}function QG({canvas:n,elements:e,layers:t,realToCanvasMat:r}){const i=e.filter(KYn);if(i.length===0)return;const o=new Ch(n);o.realToCanvasMat=r,o.drawElements(i,{layers:t})}var QYn={...dg,silkscreen:{top:fi.board.f_fab,bottom:fi.board.b_fab}};function JYn(n){return n.type.includes("pcb_fabrication_note")}function o0t({canvas:n,elements:e,layers:t,realToCanvasMat:r}){const i=new Ch(n);i.configure({colorOverrides:QYn}),i.realToCanvasMat=r;const o=e.filter(JYn);i.drawElements(o,{layers:t})}function eXn(n){return n.type==="pcb_hole"}function tXn({canvas:n,elements:e,layers:t,realToCanvasMat:r,drawSoldermask:i}){const o=new Ch(n);o.realToCanvasMat=r;const s=e.filter(eXn);o.drawElements(s,{layers:t,drawSoldermask:i})}function nXn(n){return n.type==="pcb_board"}function rXn({canvas:n,elements:e,layers:t,realToCanvasMat:r,drawSoldermask:i}){const o=new Ch(n);o.realToCanvasMat=r;const s=e.filter(nXn);for(const a of s)o.drawElements([a],{layers:t,drawSoldermask:!1,drawBoardMaterial:i??!1,minBoardOutlineStrokePx:2})}function iXn(n){return n.type==="pcb_copper_text"}function oXn({canvas:n,elements:e,layers:t,realToCanvasMat:r}){const i=e.filter(iXn);if(i.length===0)return;const o=new Ch(n);o.realToCanvasMat=r,o.drawElements(i,{layers:t})}function sXn(n){return n.type==="pcb_cutout"}function aXn({canvas:n,elements:e,layers:t,realToCanvasMat:r}){const i=new Ch(n);i.realToCanvasMat=r;const o=e.filter(sXn);i.drawElements(o,{layers:t})}function cXn(n){return n.type==="pcb_keepout"}function lXn({canvas:n,elements:e,layers:t,realToCanvasMat:r}){const i=e.filter(cXn);if(i.length===0)return;const o=new Ch(n);o.realToCanvasMat=r,o.drawElements(i,{layers:[]})}function uXn(n){return n.type.startsWith("pcb_note_")}function s0t({canvas:n,elements:e,layers:t,realToCanvasMat:r}){const i=new Ch(n);i.realToCanvasMat=r;const o=e.filter(uXn);i.drawElements(o,{layers:t})}function dXn(n){return n.type==="pcb_panel"}function hXn({canvas:n,elements:e,layers:t,realToCanvasMat:r,drawSoldermask:i}){const o=new Ch(n);o.realToCanvasMat=r;const s=e.filter(dXn);for(const a of s)o.drawElements([a],{layers:t})}var pXn={...dg,copper:{...dg.copper,top:pc(fi.board.pad_front).lighten(.5).toString(),bottom:pc(fi.board.pad_back).lighten(.5).toString(),inner1:pc(fi.board.copper.in1).lighten(.5).toString(),inner2:pc(fi.board.copper.in2).lighten(.5).toString(),inner3:pc(fi.board.copper.in3).lighten(.5).toString(),inner4:pc(fi.board.copper.in4).lighten(.5).toString(),inner5:pc(fi.board.copper.in5).lighten(.5).toString(),inner6:pc(fi.board.copper.in6).lighten(.5).toString()}};function fXn(n){return n.type==="pcb_smtpad"}function mXn({canvas:n,elements:e,layers:t,realToCanvasMat:r,primitives:i,drawSoldermask:o}){const s=e.filter(fXn).filter(u=>{const d=u.layer;return t.some(h=>h==="top_copper"&&d==="top"||h==="bottom_copper"&&d==="bottom"||h==="inner1_copper"&&d==="inner1"||h==="inner2_copper"&&d==="inner2"||h==="inner3_copper"&&d==="inner3"||h==="inner4_copper"&&d==="inner4"||h==="inner5_copper"&&d==="inner5"||h==="inner6_copper"&&d==="inner6")});if(s.length===0)return;const a=new Set;if(i)for(const u of i)(u.is_mouse_over||u.is_in_highlighted_net)&&u._element?.type==="pcb_smtpad"&&a.add(u._element.pcb_smtpad_id);const c=s.filter(u=>a.has(u.pcb_smtpad_id)),l=s.filter(u=>!a.has(u.pcb_smtpad_id));if(l.length>0){const u=new Ch(n);u.realToCanvasMat=r,u.drawElements(l,{layers:t,drawSoldermask:o})}if(c.length>0){const u=new Ch(n);u.configure({colorOverrides:pXn}),u.realToCanvasMat=r,u.drawElements(c,{layers:t,drawSoldermask:o})}}var yXn={...dg,copper:{...dg.copper,top:pc(fi.board.pad_front).lighten(.5).toString(),bottom:pc(fi.board.pad_back).lighten(.5).toString(),inner1:pc(fi.board.copper.in1).lighten(.5).toString(),inner2:pc(fi.board.copper.in2).lighten(.5).toString(),inner3:pc(fi.board.copper.in3).lighten(.5).toString(),inner4:pc(fi.board.copper.in4).lighten(.5).toString(),inner5:pc(fi.board.copper.in5).lighten(.5).toString(),inner6:pc(fi.board.copper.in6).lighten(.5).toString()}};function gXn(n){return n.type==="pcb_trace"}var _Xn=n=>n.map(e=>e.endsWith("_copper")?e.replace("_copper",""):e),xXn=(n,e)=>{const t=n.route.filter(i=>i.route_type==="wire"&&"layer"in i&&e.has(i.layer)?!0:i.route_type==="via"?e.has(i.from_layer)||e.has(i.to_layer):!1);return t.filter(i=>i.route_type==="wire").length<2?null:{...n,route:t}};function bXn({canvas:n,elements:e,layers:t,realToCanvasMat:r,primitives:i}){const o=new Set(_Xn(t)),s=e.filter(gXn).map(u=>xXn(u,o)).filter(u=>u!==null);if(s.length===0)return;const a=new Set;if(i)for(const u of i)(u.is_mouse_over||u.is_in_highlighted_net)&&u._element?.type==="pcb_trace"&&a.add(u._element.pcb_trace_id);const c=[],l=[];for(const u of s)a.has(u.pcb_trace_id)?c.push(u):l.push(u);if(l.length>0){const u=new Ch(n);u.realToCanvasMat=r,u.drawElements(l,{layers:t})}if(c.length>0){const u=new Ch(n);u.configure({colorOverrides:yXn}),u.realToCanvasMat=r,u.drawElements(c,{layers:t})}}var vXn={...dg,copper:{...dg.copper,top:pc(fi.board.pad_front).lighten(.5).toString(),bottom:pc(fi.board.pad_back).lighten(.5).toString()}};function wXn(n){return n.type==="pcb_plated_hole"}function a0t({canvas:n,elements:e,layers:t,realToCanvasMat:r,primitives:i,drawSoldermask:o}){const s=e.filter(wXn);if(s.length===0)return;const a=new Set;if(i)for(const u of i)(u.is_mouse_over||u.is_in_highlighted_net)&&u._element?.type==="pcb_plated_hole"&&a.add(u._element.pcb_plated_hole_id);const c=s.filter(u=>a.has(u.pcb_plated_hole_id)),l=s.filter(u=>!a.has(u.pcb_plated_hole_id));if(l.length>0){const u=new Ch(n);u.realToCanvasMat=r,u.drawElements(l,{layers:t,drawSoldermask:o})}if(c.length>0){const u=new Ch(n);u.configure({colorOverrides:vXn}),u.realToCanvasMat=r,u.drawElements(c,{layers:t,drawSoldermask:o})}}function c0t(n){const{lines:e,anchorPoint:t,ccwRotation:r}=n;if(!r)return e;const i=r*Math.PI/180,o=Gf(i),s=hi(xi(t.x,t.y),o,xi(-t.x,-t.y));return mt(s,t),e.map(a=>({...a,x1:mt(s,{x:a.x1,y:a.y1}).x,y1:mt(s,{x:a.x1,y:a.y1}).y,x2:mt(s,{x:a.x2,y:a.y2}).x,y2:mt(s,{x:a.x2,y:a.y2}).y}))}var SXn=.6,l0t=.2,u0t=n=>{const e=n.size*.7,t=e*SXn,r=e*l0t,i=e*l0t,o=n.text.split(/\r?\n/),s=n.text.length>0&&e>0,a=s?o.length:0,c=s?o.map(d=>d.length===0?0:d.length*t+(d.length-1)*r):[],l=c.length>0?Math.max(...c):0,u=a>0?a*e+(a-1)*i:0;return{text_lines:o,line_count:a,line_widths:c,target_height:e,target_width_char:t,space_between_chars:r,space_between_lines:i,width:l,height:u}},d0t=n=>{const e=u0t(n);return{width:e.width,height:e.height,lineHeight:e.target_height,lineSpacing:e.space_between_lines,lineCount:e.line_count}},h0t=n=>{const{text_lines:e,line_count:t,line_widths:r,target_height:i,target_width_char:o,space_between_chars:s,space_between_lines:a,width:c}=u0t(n);if(i<=0||t===0)return[];const l=i/12,u=[];for(let d=0;d<t;d++){const h=-d*(i+a),f=r[d],p=(c-f)/2;let m=n.x+p;for(let g=0;g<e[d].length;g++){const y=e[d][g],_=nS[y]??nS[y.toUpperCase()];if(!_){m+=o+s;continue}for(const{x1:x,y1:b,x2:w,y2:S}of _)u.push({_pcb_drawing_object_id:A4("line"),pcb_drawing_type:"line",x1:m+o*x,y1:n.y+h+i*b,x2:m+o*w,y2:n.y+h+i*S,width:l,layer:n.layer,unit:n.unit,color:n.color});m+=o+s}}return u};function dv(n){const t=n.color??KG[n.layer];let r=pc(t);return n._element?.type==="pcb_copper_pour"&&(r=r.alpha(.7)),n.is_mouse_over||n.is_in_highlighted_net?r.lighten(.5).rgb().toString():r.rgb().toString()}var p0t=(n,e)=>{n.equip({size:e.zoomIndependent?e.width/n.transform.a:e.width,shape:e.squareCap?"square":"circle",color:dv(e),layer:e.layer}),n.moveTo(e.x1,e.y1),n.lineTo(e.x2,e.y2)},MXn=(n,e,t)=>{switch(t){case"top_left":return{x:0,y:-e};case"top_center":return{x:-n/2,y:-e};case"top_right":return{x:-n,y:-e};case"center_left":return{x:0,y:-e/2};case"center":return{x:-n/2,y:-e/2};case"center_right":return{x:-n,y:-e/2};case"bottom_left":return{x:0,y:0};case"bottom_center":return{x:-n/2,y:0};case"bottom_right":return{x:-n,y:0};default:return{x:0,y:0}}},f0t=n=>n.layer==="bottom_silkscreen"||n.layer==="bottom"?n.is_mirrored!==!1:n.is_mirrored===!0,EXn=(n,e)=>{n.equip({fontSize:e.size,color:dv(e),layer:e.layer});const{width:t,height:r}=d0t(e),i=MXn(t,r,e.align);e.x??=0,e.y??=0;const o={x:e.x,y:e.y};let s=h0t({...e,x:e.x+i.x,y:e.y+i.y});if(f0t(e)&&(s=s.map(a=>({...a,x1:2*e.x-a.x1,x2:2*e.x-a.x2}))),e.ccw_rotation){const a={lines:s,anchorPoint:o,ccwRotation:e.ccw_rotation};s=c0t(a)}for(const a of s)p0t(n,a)},TXn=(n,e)=>{const{width:t,height:r,lineHeight:i}=d0t(e);e.x??=0,e.y??=0;const o=e.knockout_padding??{left:e.size*.5,right:e.size*.5,top:e.size*.3,bottom:e.size*.3},s=t+o.left+o.right,a=r+o.top+o.bottom,c=t/2,l=i-r/2,u=e.x-c,d=e.y-l,h={x:e.x,y:e.y},f={_pcb_drawing_object_id:`knockout_rect_${e._pcb_drawing_object_id}`,x:e.x,y:e.y,w:s,h:a,layer:e.layer,ccw_rotation:e.ccw_rotation};e.ccw_rotation?y0t(n,f):m0t(n,f);let p=h0t({...e,x:u,y:d});if(f0t(e)&&(p=p.map(m=>({...m,x1:2*e.x-m.x1,x2:2*e.x-m.x2}))),e.ccw_rotation){const m={lines:p,anchorPoint:h,ccwRotation:e.ccw_rotation};p=c0t(m)}for(const m of p)n.equip({size:m.width,shape:"circle",color:"black",layer:e.layer,mode:"subtract"}),n.moveTo(m.x1,m.y1),n.lineTo(m.x2,m.y2);n.equip({mode:"add"})},m0t=(n,e)=>{n.equip({color:dv(e),layer:e.layer,size:e.stroke_width}),n.rect({x:e.x,y:e.y,w:e.w,h:e.h,mesh_fill:e.mesh_fill,is_filled:e.is_filled,has_stroke:e.has_stroke,is_stroke_dashed:e.is_stroke_dashed,stroke_width:e.stroke_width,roundness:e.roundness})},y0t=(n,e)=>{n.equip({color:dv(e),layer:e.layer}),n.rotatedRect(e.x,e.y,e.w,e.h,e.ccw_rotation,e.roundness,e.mesh_fill)},CXn=(n,e)=>{n.equip({color:dv(e),layer:e.layer}),n.rotatedPill(e.x,e.y,e.w,e.h,e.ccw_rotation)},PXn=(n,e)=>{n.equip({color:dv(e),layer:e.layer}),n.circle(e.x,e.y,e.r,e.mesh_fill)},AXn=(n,e)=>{n.equip({color:dv(e),layer:e.layer}),n.oval(e.x,e.y,e.rX,e.rY)},RXn=(n,e)=>{n.equip({color:dv(e),layer:e.layer}),n.pill(e.x,e.y,e.w,e.h)},NXn=(n,e)=>{n.equip({color:dv(e),layer:e.layer}),n.polygon(e.points)},IXn=(n,e)=>{n.equip({color:dv(e),layer:e.layer}),n.polygonWithArcs(e.brep_shape)},kXn=(n,e)=>{switch(e.pcb_drawing_type){case"line":return p0t(n,e);case"text":return e.is_knockout?TXn(n,e):EXn(n,e);case"rect":return e.ccw_rotation?y0t(n,e):m0t(n,e);case"circle":return PXn(n,e);case"oval":return AXn(n,e);case"pill":return e.ccw_rotation?CXn(n,e):RXn(n,e);case"polygon":return NXn(n,e);case"polygon_with_arcs":return IXn(n,e)}},OXn=(n,e)=>{for(const t of e)kXn(n,t)},LXn={...dg,copper:{...dg.copper,top:pc(fi.board.pad_front).lighten(.5).toString(),bottom:pc(fi.board.pad_back).lighten(.5).toString(),inner1:pc(fi.board.copper.in1).lighten(.5).toString(),inner2:pc(fi.board.copper.in2).lighten(.5).toString(),inner3:pc(fi.board.copper.in3).lighten(.5).toString(),inner4:pc(fi.board.copper.in4).lighten(.5).toString(),inner5:pc(fi.board.copper.in5).lighten(.5).toString(),inner6:pc(fi.board.copper.in6).lighten(.5).toString()},soldermask:{...dg.soldermask,top:pc(fi.board.soldermask.top).lighten(.35).toString(),bottom:pc(fi.board.soldermask.bottom).lighten(.35).toString()}};function g0t({canvas:n,elements:e,layers:t,realToCanvasMat:r,drawSoldermaskTop:i,drawSoldermaskBottom:o,primitives:s}){const a=new Ch(n);a.realToCanvasMat=r;const c=e.filter(h=>h.type==="pcb_board");if(c.length<=1)a.drawElements(e,{layers:t,drawSoldermask:!0,drawSoldermaskTop:i,drawSoldermaskBottom:o,drawBoardMaterial:!1});else{const h=e.filter(f=>f.type!=="pcb_board");for(const f of c)a.drawElements([f,...h],{layers:t,drawSoldermask:!0,drawSoldermaskTop:i,drawSoldermaskBottom:o,drawBoardMaterial:!1})}if(!s)return;const l=new Set;for(const h of s){if(!(h.is_mouse_over||h.is_in_highlighted_net))continue;const f=h._element;f?.type==="pcb_smtpad"?l.add(f.pcb_smtpad_id):f?.type==="pcb_plated_hole"?l.add(f.pcb_plated_hole_id):f?.type==="pcb_via"&&l.add(f.pcb_via_id)}if(l.size===0)return;const u=e.filter(h=>h.type==="pcb_smtpad"?l.has(h.pcb_smtpad_id):h.type==="pcb_plated_hole"?l.has(h.pcb_plated_hole_id):h.type==="pcb_via"?l.has(h.pcb_via_id):!1);if(u.length===0)return;const d=new Ch(n);d.configure({colorOverrides:LXn}),d.realToCanvasMat=r,d.drawElements(u,{layers:t,drawSoldermask:!0,drawSoldermaskTop:i,drawSoldermaskBottom:o,drawBoardMaterial:!1})}var DXn={...dg,silkscreen:{top:fi.board.f_silks,bottom:fi.board.b_silks}};function zXn(n){return n.type.includes("pcb_silkscreen")}function _0t({canvas:n,elements:e,layers:t,realToCanvasMat:r}){const i=new Ch(n);i.configure({colorOverrides:DXn}),i.realToCanvasMat=r;const o=e.filter(zXn);i.drawElements(o,{layers:t})}var $Xn={...dg,copper:{...dg.copper,top:pc(fi.board.pad_front).lighten(.5).toString(),bottom:pc(fi.board.pad_back).lighten(.5).toString()}};function FXn(n){return n.type==="pcb_via"}function x0t({canvas:n,elements:e,layers:t,realToCanvasMat:r,primitives:i,drawSoldermask:o}){const s=e.filter(FXn).filter(u=>t.some(d=>d.includes("copper")));if(s.length===0)return;const a=new Set;if(i)for(const u of i)(u.is_mouse_over||u.is_in_highlighted_net)&&u._element?.type==="pcb_via"&&a.add(u._element.pcb_via_id);const c=s.filter(u=>a.has(u.pcb_via_id)),l=s.filter(u=>!a.has(u.pcb_via_id));if(l.length>0){const u=new Ch(n);u.realToCanvasMat=r,u.drawElements(l,{layers:t,drawSoldermask:o})}if(c.length>0){const u=new Ch(n);u.configure({colorOverrides:$Xn}),u.realToCanvasMat=r,u.drawElements(c,{layers:t,drawSoldermask:o})}}var BXn={...dg,courtyard:{top:fi.board.f_crtyd,bottom:fi.board.b_crtyd}};function jXn(n){return n.type==="pcb_courtyard_circle"||n.type==="pcb_courtyard_rect"||n.type==="pcb_courtyard_outline"}function b0t({canvas:n,elements:e,layers:t,realToCanvasMat:r}){const i=new Ch(n);i.configure({colorOverrides:BXn}),i.realToCanvasMat=r;const o=e.filter(jXn);i.drawElements(o,{layers:t})}var UXn=["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"],HXn=({primitives:n,elements:e,transform:t,grid:r,width:i=500,height:o=500})=>{const s=q.useRef({}),a=Pd(h=>h.selected_layer),c=Pd(h=>h.is_showing_solder_mask),l=Pd(h=>h.is_showing_fabrication_notes),u=Pd(h=>h.is_showing_courtyards),d=Pd(h=>h.is_showing_silkscreen);return q.useEffect(()=>{if(!s.current||Object.keys(s.current).length===0)return;const h=Object.fromEntries(Object.entries(s.current).filter(([m,g])=>!!g));if(Object.keys(h).length===0)return;const f=new ZYn(h);t&&(f.transform=t),f.clear(),f.foregroundLayer=a;const p=n.filter(m=>c||!m.layer?.includes("soldermask")).filter(m=>d||!m.layer?.includes("silkscreen")).filter(m=>l||!m.layer?.includes("fabrication")).filter(m=>m.layer!=="board").filter(m=>m._element?.type!=="pcb_smtpad").filter(m=>m._element?.type!=="pcb_plated_hole").filter(m=>m._element?.type!=="pcb_via").filter(m=>m._element?.type!=="pcb_trace").filter(m=>m._element?.type!=="pcb_copper_text");if(OXn(f,p),t){const m=s.current.top,g=s.current.bottom,y=s.current.inner1,_=s.current.inner2,x=s.current.inner3,b=s.current.inner4,w=s.current.inner5,S=s.current.inner6,E=[{canvas:m,copperLayer:"top_copper"},{canvas:g,copperLayer:"bottom_copper"},{canvas:y,copperLayer:"inner1_copper"},{canvas:_,copperLayer:"inner2_copper"},{canvas:x,copperLayer:"inner3_copper"},{canvas:b,copperLayer:"inner4_copper"},{canvas:w,copperLayer:"inner5_copper"},{canvas:S,copperLayer:"inner6_copper"}];for(const{canvas:B,copperLayer:j}of E)B&&bXn({canvas:B,elements:e,layers:[j],realToCanvasMat:t,primitives:n});for(const{canvas:B,copperLayer:j}of E)B&&oXn({canvas:B,elements:e,layers:[j],realToCanvasMat:t});m&&a0t({canvas:m,elements:e,layers:["top_copper"],realToCanvasMat:t,primitives:n,drawSoldermask:c}),g&&a0t({canvas:g,elements:e,layers:["bottom_copper"],realToCanvasMat:t,primitives:n,drawSoldermask:c}),m&&QG({canvas:m,elements:e,layers:["top_copper"],realToCanvasMat:t}),g&&QG({canvas:g,elements:e,layers:["bottom_copper"],realToCanvasMat:t});for(const{canvas:B,copperLayer:j}of E)B&&mXn({canvas:B,elements:e,layers:[j],realToCanvasMat:t,primitives:n,drawSoldermask:c});if(m&&x0t({canvas:m,elements:e,layers:["top_copper"],realToCanvasMat:t,primitives:n,drawSoldermask:c}),g&&x0t({canvas:g,elements:e,layers:["bottom_copper"],realToCanvasMat:t,primitives:n,drawSoldermask:c}),c){const B=a==="bottom"?"bottom":"top",j=B==="top",G=B==="bottom",W=s.current.soldermask_top;W&&B==="top"&&g0t({canvas:W,elements:e,layers:["top_soldermask"],realToCanvasMat:t,drawSoldermaskTop:j,drawSoldermaskBottom:G,primitives:n});const Q=s.current.soldermask_bottom;Q&&B==="bottom"&&g0t({canvas:Q,elements:e,layers:["bottom_soldermask"],realToCanvasMat:t,drawSoldermaskTop:j,drawSoldermaskBottom:G,primitives:n})}m&&QG({canvas:m,elements:e,layers:["top_copper"],realToCanvasMat:t}),g&&QG({canvas:g,elements:e,layers:["bottom_copper"],realToCanvasMat:t});const C=s.current.drill;if(C&&tXn({canvas:C,elements:e,layers:["drill"],realToCanvasMat:t}),d){const B=s.current.top_silkscreen;B&&_0t({canvas:B,elements:e,layers:["top_silkscreen"],realToCanvasMat:t});const j=s.current.bottom_silkscreen;j&&_0t({canvas:j,elements:e,layers:["bottom_silkscreen"],realToCanvasMat:t})}if(l){const B=s.current.top_fabrication;B&&o0t({canvas:B,elements:e,layers:["top_fabrication_note"],realToCanvasMat:t});const j=s.current.bottom_fabrication;j&&o0t({canvas:j,elements:e,layers:["bottom_fabrication_note"],realToCanvasMat:t})}const A=s.current.bottom_notes;A&&s0t({canvas:A,elements:e,layers:["bottom_user_note"],realToCanvasMat:t});const R=s.current.top_notes;if(R&&s0t({canvas:R,elements:e,layers:["top_user_note"],realToCanvasMat:t}),u){const B=s.current.top_courtyard;B&&b0t({canvas:B,elements:e,layers:["top_courtyard"],realToCanvasMat:t});const j=s.current.bottom_courtyard;j&&b0t({canvas:j,elements:e,layers:["bottom_courtyard"],realToCanvasMat:t})}const L=s.current.board;L&&(hXn({canvas:L,elements:e,layers:[],realToCanvasMat:t,drawSoldermask:c}),rXn({canvas:L,elements:e,layers:[],realToCanvasMat:t,drawSoldermask:c}));const O=s.current.edge_cuts;O&&aXn({canvas:O,elements:e,layers:["edge_cuts"],realToCanvasMat:t});const F=[{canvas:m,layer:"top"},{canvas:g,layer:"bottom"}];for(const{canvas:B,layer:j}of F)B&&lXn({canvas:B,elements:e,layers:[j],realToCanvasMat:t})}f.orderAndFadeLayers()},[n,e,t,a,c,l,u,d]),V.jsxs("div",{style:{backgroundColor:"black",width:i,height:o,position:"relative"},children:[V.jsx(DG.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:i,height:o,transform:t,stringifyCoord:(h,f,p)=>`${DG.toMMSI(h,p)}, ${DG.toMMSI(f,p)}`}),UXn.filter(h=>!(!c&&h.includes("soldermask")||!d&&h.includes("silkscreen"))).map(h=>h.replace(/-/g,"")).map((h,f)=>V.jsx("canvas",{className:`pcb-layer-${h}`,ref:p=>{s.current??={},p?s.current[h]=p:delete s.current[h]},style:{position:"absolute",zIndex:f,left:0,top:0,pointerEvents:"none"},width:i,height:o},h))]})},YXn=.6,XXn=1;$xe(ZHn(),1),$xe(hYn(),1);var JG=["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 v0t(n,e,t,r={}){const i=r.padding??40,o=r.yFlip??!1;let s;if("center"in n){const u=n.width/2,d=n.height/2;s={minX:n.center.x-u,maxX:n.center.x+u,minY:n.center.y-d,maxY:n.center.y+d}}else s=n;const a=s.maxX-s.minX||1,c=s.maxY-s.minY||1,l=Math.min((e-2*i)/a,(t-2*i)/c);return hi(xi(e/2,t/2),Gu(l,o?-l:l),xi(-(s.minX+a/2),-(s.minY+c/2)))}function VXn(n){const e=[...n.points||[],...(n.lines||[]).flatMap(t=>t.points),...(n.rects||[]).flatMap(t=>{const r=t.width/2,i=t.height/2;return[{x:t.center.x-r,y:t.center.y-i},{x:t.center.x+r,y:t.center.y-i},{x:t.center.x-r,y:t.center.y+i},{x:t.center.x+r,y:t.center.y+i}]}),...(n.circles||[]).flatMap(t=>[{x:t.center.x-t.radius,y:t.center.y},{x:t.center.x+t.radius,y:t.center.y},{x:t.center.x,y:t.center.y-t.radius},{x:t.center.x,y:t.center.y+t.radius}]),...(n.texts||[]).flatMap(t=>{const r=t.fontSize??12,i=t.text.length*r*YXn,o=r*XXn,s=t.anchorSide??"center",a={top_left:{dx:0,dy:0},top_center:{dx:-i/2,dy:0},top_right:{dx:-i,dy:0},center_left:{dx:0,dy:-o/2},center:{dx:-i/2,dy:-o/2},center_right:{dx:-i,dy:-o/2},bottom_left:{dx:0,dy:-o},bottom_center:{dx:-i/2,dy:-o},bottom_right:{dx:-i,dy:-o}},{dx:c,dy:l}=a[s],u=t.x+c,d=t.y+l;return[{x:u,y:d},{x:u+i,y:d+o}]})];return e.length===0?{minX:-1,maxX:1,minY:-1,maxY:1}:e.reduce((t,r)=>({minX:Math.min(t.minX,r.x),maxX:Math.max(t.maxX,r.x),minY:Math.min(t.minY,r.y),maxY:Math.max(t.maxY,r.y)}),{minX:1/0,maxX:-1/0,minY:1/0,maxY:-1/0})}function GXn(n,e,t={}){const r=e instanceof HTMLCanvasElement?e.getContext("2d"):e;if(!r)throw new Error("Could not get 2D context from canvas");const i=e instanceof HTMLCanvasElement?e.width:e.canvas.width,o=e instanceof HTMLCanvasElement?e.height:e.canvas.height;let s;if(t.transform)s=t.transform;else if(t.viewbox)s=v0t(t.viewbox,i,o,{padding:t.padding,yFlip:t.yFlip});else{const a=VXn(n),c=n.coordinateSystem==="cartesian";s=v0t(a,i,o,{padding:t.padding??40,yFlip:c})}r.clearRect(0,0,i,o),r.save(),n.rects&&n.rects.length>0&&n.rects.forEach(a=>{const c=a.width/2,l=a.height/2,u=mt(s,{x:a.center.x-c,y:a.center.y-l}),d=mt(s,{x:a.center.x+c,y:a.center.y+l}),h=Math.abs(d.x-u.x),f=Math.abs(d.y-u.y);r.beginPath(),r.rect(Math.min(u.x,d.x),Math.min(u.y,d.y),h,f),a.fill&&(r.fillStyle=a.fill,r.fill()),a.stroke&&(r.strokeStyle=a.stroke,r.stroke())}),n.circles&&n.circles.length>0&&n.circles.forEach(a=>{const c=mt(s,a.center),l=a.radius*Math.abs(s.a);r.beginPath(),r.arc(c.x,c.y,l,0,2*Math.PI),a.fill&&(r.fillStyle=a.fill,r.fill()),a.stroke&&(r.strokeStyle=a.stroke??"transparent",r.stroke())}),n.lines&&n.lines.length>0&&n.lines.forEach((a,c)=>{if(a.points.length===0)return;r.beginPath();const l=mt(s,a.points[0]);r.moveTo(l.x,l.y);for(let u=1;u<a.points.length;u++){const d=mt(s,a.points[u]);r.lineTo(d.x,d.y)}if(r.strokeStyle=a.strokeColor||JG[c%JG.length],a.strokeWidth?r.lineWidth=a.strokeWidth*s.a:r.lineWidth=2,r.lineCap="round",a.strokeDash)if(typeof a.strokeDash=="string"){let u;if(a.strokeDash.includes(","))u=a.strokeDash.split(",").map(d=>parseFloat(d.trim())).filter(d=>!Number.isNaN(d));else{const d=parseFloat(a.strokeDash.trim());u=Number.isNaN(d)?[]:[d]}r.setLineDash(u)}else r.setLineDash(a.strokeDash.map(u=>u*Math.abs(s.a)));else r.setLineDash([]);r.stroke()}),n.points&&n.points.length>0&&n.points.forEach((a,c)=>{const l=mt(s,a);r.beginPath(),r.arc(l.x,l.y,3,0,2*Math.PI),r.fillStyle=a.color||JG[c%JG.length],r.fill(),a.label&&!t.disableLabels&&(r.fillStyle=a.color||"black",r.font="12px sans-serif",r.fillText(a.label,l.x+5,l.y-5))}),n.texts&&n.texts.length>0&&n.texts.forEach(a=>{const c=mt(s,{x:a.x,y:a.y});r.fillStyle=a.color||"black",r.font=`${(a.fontSize??12)*Math.abs(s.a)}px sans-serif`;const l=a.anchorSide??"center",u={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"},d={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"};r.textAlign=u[l],r.textBaseline=d[l],r.fillText(a.text,c.x,c.y)}),r.restore()}var qXn=({children:n,transform:e,debugGraphics:t})=>{const r=q.useRef(null),[i,{width:o,height:s}]=BO(),a=Pd(c=>c.is_showing_autorouting);return q.useEffect(()=>{a&&r.current&&t&&o&&s&&(r.current.width=o,r.current.height=s,GXn(t,r.current,{transform:e,disableLabels:!0}))},[t,e,o,s,a]),a?V.jsxs("div",{ref:i,style:{position:"relative",width:"100%",height:"100%"},children:[n,V.jsx("canvas",{ref:r,style:{position:"absolute",top:0,left:0,opacity:.5,zIndex:100,width:"100%",height:"100%",pointerEvents:"none"}})]}):n},WXn=({children:n,transform:e=Jc(),elements:t=[]})=>{const[r,{width:i,height:o}]=BO(),s=q.useRef(null);return q.useEffect(()=>{const a=s.current;if(!a||!i||!o)return;a.width=i,a.height=o;const c=a.getContext("2d");if(!c)return;c.clearRect(0,0,i,o);const l=t.filter(d=>d.type==="pcb_component"),u=t.filter(d=>d.type==="pcb_manual_edit_conflict_warning");c.strokeStyle=fi.board.drc_warning,c.lineWidth=2,u.forEach(d=>{const h=l.find(G=>G.pcb_component_id===d.pcb_component_id);if(!h)return;const{width:f,height:p,center:m}=h,g=mt(e,m),y=f*Math.abs(e.a),_=p*Math.abs(e.d),x=.1*Math.abs(e.a),b=y+x*2,w=_+x*2,S=g.x-b/2,E=g.y-w/2;c.beginPath(),c.rect(S,E,b,w),c.stroke();const C="Manual Edit Conflict",A=4,R=Math.max(8,Math.min(12,10*Math.abs(e.a)));c.font=`${R}px sans-serif`;const O=c.measureText(C).width+A*2,F=R+A*2,B=S+(b-O)/2,j=E+w+5;c.fillStyle="rgba(0, 0, 0, 0.7)",c.beginPath(),c.roundRect(B,j,O,F,3),c.fill(),c.fillStyle=fi.board.drc_warning,c.textAlign="center",c.textBaseline="middle",c.fillText(C,B+O/2,j+F/2)})},[t,e,i,o]),V.jsxs("div",{ref:r,style:{position:"relative",width:"100%",height:"100%"},children:[n,V.jsx("canvas",{ref:s,style:{position:"absolute",top:0,left:0,pointerEvents:"none",zIndex:Kl.warnings}})]})},eq=(n,e,t)=>t(n,e),w0t=(n,e,t,r,i)=>{const o=i*Math.PI/180,s=Math.cos(o),a=Math.sin(o),c=n-t,l=e-r,u=c*s-l*a,d=c*a+l*s;return{x:u+t,y:d+r}},jO=n=>{if(n.length===0)return null;let e=n[0].x,t=n[0].x,r=n[0].y,i=n[0].y;for(const o of n)e=eq(e,o.x,Math.min),t=eq(t,o.x,Math.max),r=eq(r,o.y,Math.min),i=eq(i,o.y,Math.max);return{minX:e,maxX:t,minY:r,maxY:i}},ZXn=(n,e)=>({minX:Math.min(n.minX,e.minX),maxX:Math.max(n.maxX,e.maxX),minY:Math.min(n.minY,e.minY),maxY:Math.max(n.maxY,e.maxY)}),KXn=(n,e)=>n?ZXn(n,e):e,QXn=n=>{switch(n.pcb_drawing_type){case"line":{const e=(n.width??0)/2,t=[{x:n.x1,y:n.y1},{x:n.x2,y:n.y2}],r=jO(t);return r?{minX:r.minX-e,maxX:r.maxX+e,minY:r.minY-e,maxY:r.maxY+e}:null}case"rect":{const e=n.w/2,t=n.h/2,r=[{x:n.x-e,y:n.y-t},{x:n.x+e,y:n.y-t},{x:n.x+e,y:n.y+t},{x:n.x-e,y:n.y+t}],i=n.ccw_rotation??0,o=i===0?r:r.map(s=>w0t(s.x,s.y,n.x,n.y,i));return jO(o)}case"circle":return{minX:n.x-n.r,maxX:n.x+n.r,minY:n.y-n.r,maxY:n.y+n.r};case"oval":return{minX:n.x-n.rX,maxX:n.x+n.rX,minY:n.y-n.rY,maxY:n.y+n.rY};case"pill":{const e=n.w/2,t=n.h/2,r=[{x:n.x-e,y:n.y-t},{x:n.x+e,y:n.y-t},{x:n.x+e,y:n.y+t},{x:n.x-e,y:n.y+t}],i=n.ccw_rotation??0,o=i===0?r:r.map(s=>w0t(s.x,s.y,n.x,n.y,i));return jO(o)}case"polygon":return jO(n.points);case"polygon_with_arcs":{const e=n.brep_shape.outer_ring.vertices.map(t=>({x:t.x,y:t.y}));return jO(e)}case"text":{const e=n.size??0,t=n.text?n.text.length*e*.6:0,r=e;if(t===0&&r===0)return{minX:n.x,maxX:n.x,minY:n.y,maxY:n.y};const i=t/2,o=r/2;return{minX:n.x-i,maxX:n.x+i,minY:n.y-o,maxY:n.y+o}}default:return null}};function JXn(n){const{dimensionStart:e,dimensionEnd:t,screenDimensionStart:r,screenDimensionEnd:i,flipX:o,flipY:s}=n,a=t.x-e.x,c=t.y-e.y,l=Math.sqrt(a*a+c*c),u=i.x-r.x,d=i.y-r.y,h=Math.sqrt(u*u+d*d),f=Math.atan2(d,u)*(180/Math.PI),p=Math.abs(f)%90,g=Math.min(p,90-p)>15,y=(r.x+i.x)/2,_=(r.y+i.y)/2,x=15,b=f+90;let w=Math.cos(b*Math.PI/180)*x,S=Math.sin(b*Math.PI/180)*x;const E=u>0&&d<0,C=u>0&&d>0,A=u<0&&d>0;o!==s&&!E&&(w=-w,S=-S),E&&(w+=Math.cos(b*Math.PI/180)*-45,S+=Math.sin(b*Math.PI/180)*-45),C&&(w+=Math.cos(b*Math.PI/180)+-20,S+=Math.sin(b*Math.PI/180)+-10),A&&(w+=Math.cos(b*Math.PI/180)*10,S+=Math.sin(b*Math.PI/180)*10);const R=y+w,L=_+S;return{distance:l,screenDistance:h,x:R,y:L,show:l>.01&&h>30&&g}}function eVn(n){const{dimensionStart:e,dimensionEnd:t,screenDimensionStart:r,screenDimensionEnd:i,flipX:o,flipY:s}=n;return q.useMemo(()=>JXn({dimensionStart:e,dimensionEnd:t,screenDimensionStart:r,screenDimensionEnd:i,flipX:o,flipY:s}),[e,t,r,i,o,s])}var tVn=(n,e,t)=>{const r=t*Math.PI/180,i=Math.cos(r),o=Math.sin(r),s=n.x-e.x,a=n.y-e.y,c=s*i-a*o,l=s*o+a*i;return{x:c+e.x,y:l+e.y}},S0t=(n,e,t,r)=>{const i={top_left:{x:n.x-e,y:n.y-t},top_center:{x:n.x,y:n.y-t},top_right:{x:n.x+e,y:n.y-t},center_left:{x:n.x-e,y:n.y},center:{x:n.x,y:n.y},center_right:{x:n.x+e,y:n.y},bottom_left:{x:n.x-e,y:n.y+t},bottom_center:{x:n.x,y:n.y+t},bottom_right:{x:n.x+e,y:n.y+t}};return r===0?Object.entries(i).map(([o,s])=>({anchor:o,point:s})):Object.entries(i).map(([o,s])=>({anchor:o,point:tVn(s,n,r)}))},nVn=n=>{switch(n.pcb_drawing_type){case"rect":{const e=n.ccw_rotation??0;return S0t({x:n.x,y:n.y},n.w/2,n.h/2,e)}case"pill":{const e=n.ccw_rotation??0;return S0t({x:n.x,y:n.y},n.w/2,n.h/2,e)}case"circle":return[{anchor:"circle_center",point:{x:n.x,y:n.y}},{anchor:"circle_right",point:{x:n.x+n.r,y:n.y}},{anchor:"circle_left",point:{x:n.x-n.r,y:n.y}},{anchor:"circle_top",point:{x:n.x,y:n.y-n.r}},{anchor:"circle_bottom",point:{x:n.x,y:n.y+n.r}}];case"oval":return[{anchor:"oval_center",point:{x:n.x,y:n.y}},{anchor:"oval_right",point:{x:n.x+n.rX,y:n.y}},{anchor:"oval_left",point:{x:n.x-n.rX,y:n.y}},{anchor:"oval_top",point:{x:n.x,y:n.y-n.rY}},{anchor:"oval_bottom",point:{x:n.x,y:n.y+n.rY}}];case"line":{const e={x:(n.x1+n.x2)/2,y:(n.y1+n.y2)/2};return[{anchor:"line_start",point:{x:n.x1,y:n.y1}},{anchor:"line_mid",point:e},{anchor:"line_end",point:{x:n.x2,y:n.y2}}]}case"polygon":return n.points.map((e,t)=>({anchor:`polygon_vertex_${t}`,point:e}));case"polygon_with_arcs":return n.brep_shape.outer_ring.vertices.map((e,t)=>({anchor:`polygon_with_arcs_vertex_${t}`,point:{x:e.x,y:e.y}}));default:return[]}},rVn=16,US=5,M0t=n=>{if(n.pcb_drawing_type==="text")return!0;const e=n._element;if(!e||typeof e!="object")return!1;const t=typeof e.type=="string"?e.type:void 0;return t?!!(t.startsWith("pcb_silkscreen_")||t.startsWith("pcb_note_")||t==="pcb_text"||t.startsWith("pcb_fabrication_note_")&&t!=="pcb_fabrication_note_rect"):!1},iVn=({children:n,transform:e,focusOnHover:t=!1,primitives:r=[]})=>{e||(e=Jc());const[i,o]=q.useState(!1),[s,a]=q.useState(!1),[c,l]=q.useState(!1),[u,d]=q.useState({start:null,end:null}),h=Pd(j=>j.is_mouse_over_container),f=q.useCallback(()=>{c&&(l(!1),window.dispatchEvent(new Event("disarm-dimension-tool")))},[c]),[p,m]=q.useState({x:0,y:0}),[g,y]=q.useState({x:0,y:0}),_=q.useRef({x:0,y:0}),x=q.useRef(null),w=x.current?.getBoundingClientRect(),S=q.useMemo(()=>{const j=new Map;for(const G of r){if(!G._element||M0t(G)||G.pcb_drawing_type==="pill"||G.pcb_drawing_type==="rect"&&G.ccw_rotation&&G.ccw_rotation!==0)continue;const W=QXn(G);if(!W)continue;const Q=j.get(G._element);j.set(G._element,KXn(Q??void 0,W))}return j},[r]),E=q.useMemo(()=>{const j=[];for(const G of r){if(!G._element||M0t(G))continue;const W=nVn(G);if(W.length!==0)for(const Q of W)j.push({anchor:Q.anchor,point:Q.point,element:G._element})}return j},[r]),C=q.useMemo(()=>{const j=[];S.forEach((G,W)=>{if(!G)return;const Q=(G.minX+G.maxX)/2,ne=(G.minY+G.maxY)/2,ue={top_left:{x:G.minX,y:G.minY},top_center:{x:Q,y:G.minY},top_right:{x:G.maxX,y:G.minY},center_left:{x:G.minX,y:ne},center:{x:Q,y:ne},center_right:{x:G.maxX,y:ne},bottom_left:{x:G.minX,y:G.maxY},bottom_center:{x:Q,y:G.maxY},bottom_right:{x:G.maxX,y:G.maxY}};for(const[te,re]of Object.entries(ue))j.push({anchor:te,point:re,element:W})});for(const G of E)j.push(G);return j.push({anchor:"origin",point:{x:0,y:0},element:null}),j},[S,E]),A=q.useMemo(()=>C.map((j,G)=>({...j,id:`${G}-${j.anchor}`,screenPoint:mt(e,j.point)})),[C,e]),R=q.useCallback(j=>{if(A.length===0)return{point:j,id:null};const G=mt(e,j);let W=null;for(const Q of A){const ne=Q.screenPoint.x-G.x,ue=Q.screenPoint.y-G.y,te=Math.hypot(ne,ue);te>rVn||(!W||te<W.distance)&&(W={distance:te,id:Q.id,point:Q.point})}return W?{point:W.point,id:W.id}:{point:j,id:null}},[A,e]);q.useEffect(()=>{const j=W=>{const Q=W.target;if(Q.tagName==="INPUT"||Q.tagName==="TEXTAREA"||Q.isContentEditable)return;const ne=x.current?.contains(document.activeElement)||document.activeElement===x.current;if(!(!h&&!ne)){if(W.key==="d"){const ue=R({x:_.current.x,y:_.current.y});m({x:ue.point.x,y:ue.point.y}),y({x:ue.point.x,y:ue.point.y}),d({start:ue.id,end:ue.id}),i?(o(!1),a(!1),d({start:null,end:null})):(o(!0),a(!0)),f()}W.key==="Escape"&&(o(!1),a(!1),d({start:null,end:null}),f())}},G=()=>{l(!0)};return window.addEventListener("keydown",j),window.addEventListener("arm-dimension-tool",G),()=>{window.removeEventListener("keydown",j),window.removeEventListener("arm-dimension-tool",G),f()}},[h,i,f,R]);const L=mt(e,p),O=mt(e,g),F={left:Math.min(L.x,O.x),right:Math.max(L.x,O.x),top:Math.min(L.y,O.y),bottom:Math.max(L.y,O.y),flipX:L.x>O.x,flipY:L.y>O.y,width:0,height:0};F.width=F.right-F.left,F.height=F.bottom-F.top;const B=eVn({dimensionStart:p,dimensionEnd:g,screenDimensionStart:L,screenDimensionEnd:O,flipX:F.flipX,flipY:F.flipY});return V.jsxs("div",{ref:x,"data-pcb-viewer":!0,tabIndex:0,style:{position:"relative",outline:"none"},onMouseEnter:()=>{t&&x.current&&x.current.focus()},onMouseLeave:()=>{x.current&&x.current.blur()},onClick:()=>{x.current&&x.current.focus()},onMouseMove:j=>{const G=j.currentTarget.getBoundingClientRect(),W=j.clientX-G.left,Q=j.clientY-G.top,ne=mt(Y2(e),{x:W,y:Q});if(_.current.x=ne.x,_.current.y=ne.y,s){const ue=R(ne);y({x:ue.point.x,y:ue.point.y}),d(te=>({...te,end:ue.id}))}},onMouseDown:j=>{const G=j.currentTarget.getBoundingClientRect(),W=j.clientX-G.left,Q=j.clientY-G.top,ne=mt(Y2(e),{x:W,y:Q});if(c&&!i){const ue=R(ne);m({x:ue.point.x,y:ue.point.y}),y({x:ue.point.x,y:ue.point.y}),d({start:ue.id,end:ue.id}),o(!0),a(!0),f()}else s?(a(!1),d(ue=>({...ue,end:null}))):i&&(o(!1),d({start:null,end:null}))},children:[n,i&&V.jsxs(V.Fragment,{children:[B.show&&V.jsx("div",{style:{position:"absolute",left:B.x,top:B.y,color:"red",mixBlendMode:"difference",pointerEvents:"none",fontSize:12,fontFamily:"sans-serif",whiteSpace:"nowrap",zIndex:Kl.dimensionOverlay},children:B.distance.toFixed(2)}),V.jsx("div",{style:{position:"absolute",left:F.left,width:F.width,textAlign:"center",top:L.y+2,color:"red",mixBlendMode:"difference",pointerEvents:"none",marginTop:F.flipY?0:-20,fontSize:12,fontFamily:"sans-serif",zIndex:Kl.dimensionOverlay},children:Math.abs(p.x-g.x).toFixed(2)}),V.jsx("div",{style:{position:"absolute",left:O.x,height:F.height,display:"flex",flexDirection:"column",justifyContent:"center",top:F.top,color:"red",pointerEvents:"none",mixBlendMode:"difference",fontSize:12,fontFamily:"sans-serif",zIndex:Kl.dimensionOverlay},children:V.jsx("div",{style:{marginLeft:F.flipX?"-100%":4,paddingRight:4},children:Math.abs(p.y-g.y).toFixed(2)})}),V.jsxs("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none",mixBlendMode:"difference",zIndex:Kl.dimensionOverlay},width:w.width,height:w.height,children:[V.jsx("defs",{children:V.jsx("marker",{id:"head",orient:"auto",markerWidth:"3",markerHeight:"4",refX:"2",refY:"2",children:V.jsx("path",{d:"M0,0 V4 L2,2 Z",fill:"red"})})}),V.jsx("line",{x1:L.x,y1:L.y,x2:O.x,y2:O.y,markerEnd:"url(#head)",strokeWidth:1.5,fill:"none",stroke:"red"}),V.jsx("line",{x1:L.x,y1:L.y,x2:O.x,y2:L.y,strokeWidth:1.5,fill:"none",strokeDasharray:"2,2",stroke:"red"}),V.jsx("line",{x1:O.x,y1:L.y,x2:O.x,y2:O.y,strokeWidth:1.5,fill:"none",strokeDasharray:"2,2",stroke:"red"})]}),s&&A.map(j=>{const G=j.id===u.start||j.id===u.end,W=US/2;return V.jsxs("svg",{width:US,height:US,style:{position:"absolute",left:j.screenPoint.x-W,top:j.screenPoint.y-W,pointerEvents:"none",zIndex:Kl.dimensionOverlay},children:[V.jsx("line",{x1:0,y1:0,x2:US,y2:US,stroke:G?"#66ccff":"white",strokeWidth:1}),V.jsx("line",{x1:US,y1:0,x2:0,y2:US,stroke:G?"#66ccff":"white",strokeWidth:1})]},j.id)}),V.jsxs("div",{style:{right:0,bottom:0,position:"absolute",color:"red",fontFamily:"sans-serif",fontSize:12,margin:4},children:["(",p.x.toFixed(2),",",p.y.toFixed(2),")",V.jsx("br",{}),"(",g.x.toFixed(2),",",g.y.toFixed(2),")",V.jsx("br",{}),"dist:"," ",Math.sqrt((g.x-p.x)**2+(g.y-p.y)**2).toFixed(2)]})]})]})},oVn=(n,e,t=0)=>{const r=n.width/2,i=n.height/2,o=n.center.x-r-t,s=n.center.x+r+t,a=n.center.y-i-t,c=n.center.y+i+t;return e.x>o&&e.x<s&&e.y>a&&e.y<c},sVn=({children:n,disabled:e,transform:t,soup:r,cancelPanDrag:i,onCreateEditEvent:o,onModifyEditEvent:s})=>{t||(t=Jc());const a=q.useRef(null),[c,l]=q.useState(null),[u,d]=q.useState(null),h=c!==null;Pd(g=>g.in_edit_mode);const f=Pd(g=>g.in_move_footprint_mode),p=Pd(g=>g.setIsMovingComponent),m=e||!f;return V.jsxs("div",{ref:a,style:{position:"relative",overflow:"hidden"},onMouseDown:g=>{if(m)return;const y=g.currentTarget.getBoundingClientRect(),_=g.clientX-y.left,x=g.clientY-y.top;if(Number.isNaN(_)||Number.isNaN(x))return;const b=mt(Y2(t),{x:_,y:x});let w=!1;for(const S of r)if(S.type==="pcb_component"&&oVn(S,b,10/t.a)){i(),l(S.pcb_component_id),w=!0;const E=Math.random().toString();d({dragStart:b,originalCenter:S.center,dragEnd:b,edit_event_id:E}),o({edit_event_id:E,edit_event_type:"edit_pcb_component_location",pcb_edit_event_type:"edit_component_location",pcb_component_id:S.pcb_component_id,original_center:S.center,new_center:S.center,in_progress:!0,created_at:Date.now()}),p(!0);break}if(w||l(null),w)return g.preventDefault(),!1},onMouseMove:g=>{if(!c||!u)return;const y=g.currentTarget.getBoundingClientRect(),_=g.clientX-y.left,x=g.clientY-y.top;if(Number.isNaN(_)||Number.isNaN(x))return;const b=mt(Y2(t),{x:_,y:x});d({...u,dragEnd:b}),s({edit_event_id:u.edit_event_id,new_center:{x:u.originalCenter.x+b.x-u.dragStart.x,y:u.originalCenter.y+b.y-u.dragStart.y}})},onMouseUp:g=>{c&&(l(null),p(!1),u&&(s({edit_event_id:u.edit_event_id,in_progress:!1}),d(null)))},children:[n,!m&&r.filter(g=>g.type==="pcb_component").map(g=>{if(!g?.center)return null;const y=mt(t,g.center);return V.jsx("div",{style:{position:"absolute",pointerEvents:"none",left:y.x,top:y.y,width:g.width*t.a+20,height:g.height*t.a+20,transform:"translate(-50%, -50%)",background:h&&c===g.pcb_component_id?"rgba(255, 0, 0, 0.2)":""}},g.pcb_component_id)})]})},aVn=({hotkeys:n})=>(q.useEffect(()=>{const e=t=>{n.forEach(r=>{t.key===r.key&&r.onUse()})};return window.addEventListener("keydown",e),()=>{window.removeEventListener("keydown",e)}},[n]),V.jsx("div",{className:$P`
5423
5423
  display: flex;
5424
5424
  flex-direction: column;
5425
5425
  font-family: sans-serif;
@@ -5458,7 +5458,7 @@ $1`).replace(/>(\s*)(?=<!--\s*\/)/g,"> ")}}});function Zdt(n,e,t){if(!e||!t)retu
5458
5458
  transition: opacity 0.2s;
5459
5459
  margin-bottom: 10px;
5460
5460
  color: red;
5461
- `,pVn=({children:n,transform:e=Jc(),elements:t})=>{const r=q.useRef(null),{isShowingDRCErrors:i,hoveredErrorId:o}=Pd(l=>({isShowingDRCErrors:l.is_showing_drc_errors,hoveredErrorId:l.hovered_error_id}));if(!t)return V.jsx("div",{style:{position:"relative"},ref:r,children:n});const s=t.filter(l=>l.type==="pcb_trace_error"),a=t.filter(l=>l.type==="pcb_trace_error"&&l.message?.includes("Multiple components found with name")),c=new Map;return t.forEach(l=>{l.type==="pcb_port"&&c.set(l.pcb_port_id,l)}),V.jsxs("div",{style:{position:"relative"},ref:r,children:[n,s.map((l,u)=>{const{pcb_port_ids:d,pcb_trace_id:h}=l,f=d?.[0]?c.get(d[0]):void 0,p=d?.[1]?c.get(d[1]):void 0,m=t?W9(t).pcb_trace.get(h):void 0,g=l.pcb_trace_error_id||`error_${u}_${l.error_type}_${l.message?.slice(0,20)}`,y=o===g;if(f&&p){const _=mt(e,{x:f.x,y:f.y}),x=mt(e,{x:p.x,y:p.y});if(!i)return null;const b=!(isNaN(_.x)||isNaN(_.y)||isNaN(x.x)||isNaN(x.y)),w={x:(_.x+x.x)/2,y:(_.y+x.y)/2};if(isNaN(w.x)||isNaN(w.y))return null;const S=Vxe(w,r);return V.jsxs(q.Fragment,{children:[V.jsx(dVn,{screenPort1:_,screenPort2:x,errorCenter:w,canLineBeDrawn:b,isHighlighted:y}),V.jsx("div",{style:{position:"absolute",left:w.x-15,top:w.y-15,width:30,height:30,zIndex:Kl.errorOverlay+5,cursor:"pointer",borderRadius:"50%"},onMouseEnter:E=>{const C=E.currentTarget.nextElementSibling;if(C){const A=C.querySelector(".error-message");A&&(A.style.opacity="1")}},onMouseLeave:E=>{if(!y){const C=E.currentTarget.nextElementSibling;if(C){const A=C.querySelector(".error-message");A&&(A.style.opacity="0")}}}}),V.jsx("div",{style:{position:"absolute",zIndex:y?200:100,left:S.left,top:S.top,color:y?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:i||y?"flex":"none",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:S.transform},children:V.jsx("div",{className:`error-message ${Gxe}`,style:{opacity:y?1:0,border:`1px solid ${y?"#ff4444":"red"}`},children:l.message})})]},g)}if(m?.route&&(i||y)){const _=m.route.map(S=>mt(e,{x:S.x,y:S.y}));if(_.some(S=>isNaN(S.x)||isNaN(S.y)))return null;const x=Math.floor(_.length/2),b=_[x],w=Vxe(b,r);return V.jsxs(q.Fragment,{children:[V.jsx(hVn,{points:_,errorCenter:b,isHighlighted:y}),V.jsx("div",{style:{position:"absolute",left:b.x-15,top:b.y-15,width:30,height:30,zIndex:Kl.errorOverlay+5,cursor:"pointer",borderRadius:"50%"},onMouseEnter:S=>{const E=S.currentTarget.nextElementSibling;if(E){const C=E.querySelector(".error-message");C&&(C.style.opacity="1")}},onMouseLeave:S=>{if(!y){const E=S.currentTarget.nextElementSibling;if(E){const C=E.querySelector(".error-message");C&&(C.style.opacity="0")}}}}),V.jsx("div",{style:{position:"absolute",zIndex:y?Kl.errorOverlay+10:Kl.errorOverlay+1,left:w.left,top:w.top,color:y?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:"flex",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:w.transform},children:V.jsx("div",{className:`error-message ${Gxe}`,style:{opacity:y?1:0,border:`1px solid ${y?"#ff4444":"red"}`},children:l.message})})]},g)}return null}),a.map((l,u)=>{const d=l.component_name||l.message?.match(/name "([^"]+)"/)?.[1];if(!d)return null;const h=t?.filter(m=>m.type==="source_component"&&m.name===d||m.type==="pcb_component"&&t?.find(g=>g.type==="source_component"&&g.source_component_id===m.source_component_id&&g.name===d))||[],f=l.pcb_trace_error_id||`error_${u}_${l.error_type}_${l.message?.slice(0,20)}`,p=o===f;return!p&&!i?null:h.map((m,g)=>{let y={x:0,y:0};if(m.type==="pcb_component")y=m.center||{x:0,y:0};else if(m.type==="source_component"){const A=t?.find(R=>R.type==="pcb_component"&&R.source_component_id===m.source_component_id);A&&A.type==="pcb_component"&&(y=A.center||{x:0,y:0})}const _=mt(e,y);if(isNaN(_.x)||isNaN(_.y))return null;const x=Math.abs(e.a),E=Math.max(8,Math.min(30,.5*x)),C=Vxe(_,r);return V.jsxs(q.Fragment,{children:[V.jsx("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none",mixBlendMode:"difference",zIndex:Kl.errorOverlay},width:"100%",height:"100%",children:p?V.jsx("polygon",{points:`${_.x},${_.y-E*1.25} ${_.x+E},${_.y} ${_.x},${_.y+E*1.25} ${_.x-E},${_.y}`,fill:"#ff4444"}):V.jsx("circle",{cx:_.x,cy:_.y,r:E,fill:"none",stroke:p?"#ff4444":"red",strokeWidth:p?Math.max(2,E*.15):Math.max(1,E*.1),opacity:1})}),V.jsx("div",{style:{position:"absolute",left:_.x-(E+10),top:_.y-(E+10),width:(E+10)*2,height:(E+10)*2,zIndex:Kl.errorOverlay+5,cursor:"pointer",borderRadius:"50%"},onMouseEnter:A=>{const R=A.currentTarget.nextElementSibling;if(R){const L=R.querySelector(".error-message");L&&(L.style.opacity="1")}},onMouseLeave:A=>{if(!p){const R=A.currentTarget.nextElementSibling;if(R){const L=R.querySelector(".error-message");L&&(L.style.opacity="0")}}}}),V.jsx("div",{style:{position:"absolute",zIndex:p?Kl.errorOverlay+20:Kl.errorOverlay+10,left:C.left,top:C.top,color:p?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:i||p?"flex":"none",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:C.transform},children:V.jsx("div",{className:`error-message ${Gxe}`,style:{opacity:p?1:0,border:`1px solid ${p?"#ff4444":"red"}`},children:l.message})})]},`${f}_${g}`)})})]})};function fVn(n,e){return n.size!==e.size?!1:Array.from(n).every(t=>e.has(t))}function mVn({primitiveElement:n,elements:e}){let t=n.trace_length?`${n.trace_length.toFixed(3)}`:"";const r=W9(e).source_trace.get(n?.source_trace_id);if(r?.display_name&&(r?.max_length?t+=` / ${r.max_length}mm `:t+=" mm ",t+=`(${r.display_name})`),!t)return null;const i=n.trace_length&&r?.max_length&&n.trace_length>r.max_length;return{text:t,isOverLength:i}}function yVn(n){const{primitives:e,is_showing_multiple_traces_length:t,elements:r}=n,i=e.filter(c=>c._element.type==="pcb_trace"),o=r.filter(c=>c.type==="source_trace"),s=e.filter(c=>c._element.type!=="pcb_trace"),a=i.filter(c=>o.some(l=>c._element.type==="pcb_trace"&&c._element.source_trace_id===l.source_trace_id&&l.max_length!==void 0));if(!t)return[...s,...a];if(i.length>1){const c=i.reduce((l,u)=>{const d=l._element.trace_length;return u._element.trace_length<d?u:l},i[0]);return[...s,c]}return e}var gVn={position:"absolute",left:0,top:0,pointerEvents:"none",color:"red",fontFamily:"sans-serif",fontSize:12,textShadow:"0 0 2px black"},_Vn=n=>{const{_element:e,_parent_pcb_component:t,_parent_source_component:r,_source_port:i}=n;switch(e.type){case"pcb_trace":return e.trace_length?`${e.trace_length.toFixed(3)}`:"";case"pcb_smtpad":case"pcb_plated_hole":{const o=[],s=Array.from(new Set((e.port_hints??[]).concat(i?.port_hints??[]))).filter(c=>!/^[0-9]+$/.test(c)).filter(c=>!c.includes("unnamed_")).sort((c,l)=>l.localeCompare(c)),a=r&&"name"in r&&r.name&&!r.name.includes("unnamed_")?r.name:null;return s.length>0?a?o.push(...s.map(c=>`${a}.${c}`)):o.push(...s):a&&o.push(a),o.join(", ")}default:return""}},xVn={top:"red",bottom:"aqua"},bVn=({primitive:n,mousePos:e,elements:t})=>{const[r,i]=q.useState(!1),o=n._element;q.useEffect(()=>{setTimeout(()=>{i(!0)},100)},[]);const[s,a,c,l]=[n.screen_x,n.screen_y,n.screen_w,n.screen_h],u=n.same_space_index??0,d=26,h=xVn[n?._element?.layer]??"red";let f=0;if(o.type==="pcb_smtpad"&&o?.shape==="rotated_rect"?f=o?.ccw_rotation??0:(o.type==="pcb_smtpad"&&(o?.shape==="pill"||o?.shape==="rotated_pill")&&"ccw_rotation"in n||o.type==="pcb_plated_hole"&&(o?.shape==="pill"||o?.shape==="oval")&&"ccw_rotation"in n)&&(f=o.ccw_rotation??0),o.type==="pcb_trace"){const g=mVn({primitiveElement:o,elements:t});if(!g)return null;const y=e.y-35;return V.jsx("div",{style:{zIndex:Kl.elementOverlay,position:"absolute",left:e.x,top:y,color:h,pointerEvents:"none",transform:"translateX(-50%)"},children:V.jsx("div",{style:{backgroundColor:"#f2efcc",color:g.isOverLength?"red":"black",textShadow:"none",WebkitFontSmoothing:"antialiased",MozOsxFontSmoothing:"grayscale",padding:"6px 6px",borderRadius:"6px",fontSize:"14px",minWidth:"45px",textAlign:"center",whiteSpace:"nowrap"},children:g.text})})}const p=_Vn(n);return p.trim().length===0?null:V.jsx("div",{style:{zIndex:Kl.elementOverlay,position:"absolute",left:s-c/2-8,top:a-l/2-8,width:c+16,height:l+16,color:h,transform:`rotate(${-f}deg)`,transformOrigin:"center center"},children:V.jsx("div",{style:{width:r?`calc(100% + ${d*2*u}px)`:"100%",height:r?`calc(100% + ${d*2*u}px)`:"100%",marginLeft:r?`${-d*u}px`:0,marginTop:r?`${-d*u}px`:0,border:`1px solid ${h}`,opacity:r||u===0?1:0,transition:"width 0.2s, height 0.2s, margin-left 0.2s, margin-top 0.2s, opacity 0.2s"},children:V.jsx("div",{style:{position:"absolute",bottom:l+20+d*u,marginRight:r?`${-d*u}px`:0,marginBottom:r?0:-d*u,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(${f}deg)`,minWidth:"45px",textAlign:"center"},children:p})})})},vVn=({highlightedPrimitives:n,mousePos:e,elements:t})=>{const[r,i]=Pd(a=>[a.is_moving_component,a.is_showing_multiple_traces_length]),o=n.some(a=>a._element.type==="pcb_smtpad")&&n.some(a=>a._element.type==="pcb_trace");let s=n;return o&&(s=s.filter(a=>a._element.type==="pcb_smtpad")),s=yVn({primitives:s,is_showing_multiple_traces_length:i,elements:t}),V.jsx("div",{style:gVn,children:!r&&s.map((a,c)=>V.jsx(bVn,{primitive:a,mousePos:e,elements:t},c))})},N8=n=>n?.type==="pcb_component",E0t=n=>n?.type==="pcb_group",wVn=n=>n?.type==="pcb_panel",qxe=n=>n?.type==="pcb_board",Pu={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},Qx={OFFSET_LINE:"white",COMPONENT_MARKER_FILL:"#66ccff",COMPONENT_MARKER_STROKE:"white",LABEL_TEXT:"white"},Wxe=({targets:n,transform:e,containerWidth:t,containerHeight:r})=>{if(n.length===0)return null;const i={color:Qx.LABEL_TEXT,mixBlendMode:"difference",pointerEvents:"none",fontSize:Pu.LABEL_FONT_SIZE,fontFamily:"monospace",fontWeight:"bold"},o=new Map;return n.forEach(s=>{if(!o.has(s.anchor_id)){const a=mt(e,s.anchor);o.set(s.anchor_id,a)}}),V.jsx("div",{style:{position:"absolute",left:0,top:0,width:t,height:r,overflow:"hidden",pointerEvents:"none",zIndex:Kl.dimensionOverlay},children:V.jsxs("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none"},width:t,height:r,children:[n.map(s=>{const a=s.anchor,c=s.anchor_id,l=s.target,u=o.get(c),d=mt(e,l),h=l.x-a.x,f=l.y-a.y,p=Math.abs(d.x-u.x),m=Math.abs(d.y-u.y),g=d.y<u.y,y=d.x>u.x,_=g?Pu.LABEL_OFFSET_ABOVE:Pu.LABEL_OFFSET_BELOW,x=y?Pu.LABEL_OFFSET_RIGHT:Pu.LABEL_OFFSET_LEFT,b=p>Pu.MIN_LINE_LENGTH_FOR_LABEL,w=m>Pu.MIN_LINE_LENGTH_FOR_LABEL,S=`${s.display_offset_x??h.toFixed(2)}mm`,E=`${s.display_offset_y??f.toFixed(2)}mm`;return V.jsxs("g",{children:[V.jsx("line",{x1:u.x,y1:u.y,x2:d.x,y2:u.y,stroke:Qx.OFFSET_LINE,strokeWidth:Pu.LINE_STROKE_WIDTH,strokeDasharray:Pu.LINE_DASH_PATTERN}),V.jsx("line",{x1:d.x,y1:u.y,x2:d.x,y2:d.y,stroke:Qx.OFFSET_LINE,strokeWidth:Pu.LINE_STROKE_WIDTH,strokeDasharray:Pu.LINE_DASH_PATTERN}),s.type==="component"||s.type==="board"?V.jsx("circle",{cx:d.x,cy:d.y,r:Pu.COMPONENT_MARKER_RADIUS,fill:Qx.COMPONENT_MARKER_FILL,stroke:Qx.COMPONENT_MARKER_STROKE,strokeWidth:1}):V.jsxs(V.Fragment,{children:[V.jsx("line",{x1:d.x-Pu.ANCHOR_MARKER_SIZE,y1:d.y,x2:d.x+Pu.ANCHOR_MARKER_SIZE,y2:d.y,stroke:Qx.OFFSET_LINE,strokeWidth:Pu.ANCHOR_MARKER_STROKE_WIDTH}),V.jsx("line",{x1:d.x,y1:d.y-Pu.ANCHOR_MARKER_SIZE,x2:d.x,y2:d.y+Pu.ANCHOR_MARKER_SIZE,stroke:Qx.OFFSET_LINE,strokeWidth:Pu.ANCHOR_MARKER_STROKE_WIDTH})]}),b&&V.jsx("foreignObject",{x:Math.min(u.x,d.x),y:u.y+_,width:Math.abs(d.x-u.x),height:20,style:{overflow:"visible"},children:V.jsx("div",{style:{...i,textAlign:"center"},children:S})}),w&&V.jsx("foreignObject",{x:d.x+x,y:Math.min(u.y,d.y),width:Pu.Y_LABEL_MIN_WIDTH,height:Math.abs(d.y-u.y),style:{overflow:"visible"},children:V.jsx("div",{style:{...i,display:"flex",alignItems:"center",justifyContent:y?"flex-start":"flex-end",whiteSpace:"nowrap",padding:"0 4px",height:"100%"},children:E})})]},s.id)}),Array.from(o.entries()).map(([s,a])=>V.jsxs("g",{children:[V.jsx("line",{x1:a.x-Pu.ANCHOR_MARKER_SIZE,y1:a.y,x2:a.x+Pu.ANCHOR_MARKER_SIZE,y2:a.y,stroke:Qx.OFFSET_LINE,strokeWidth:Pu.ANCHOR_MARKER_STROKE_WIDTH}),V.jsx("line",{x1:a.x,y1:a.y-Pu.ANCHOR_MARKER_SIZE,x2:a.x,y2:a.y+Pu.ANCHOR_MARKER_SIZE,stroke:Qx.OFFSET_LINE,strokeWidth:Pu.ANCHOR_MARKER_STROKE_WIDTH})]},`anchor-${s}`))]})})},SVn=({elements:n,highlightedPrimitives:e,transform:t,containerWidth:r,containerHeight:i})=>{const o=n.filter(y=>qxe(y)),s=n.filter(y=>N8(y)),a=n.filter(y=>E0t(y)),c=e.map(y=>N8(y._parent_pcb_component)?y._parent_pcb_component.pcb_component_id:N8(y._element)?y._element.pcb_component_id:null).filter(y=>!!y),l=new Set;if(c.forEach(y=>{const _=s.find(x=>x.pcb_component_id===y);_?.pcb_group_id&&l.add(_.pcb_group_id)}),!Pd(y=>y.is_showing_group_anchor_offsets)&&c.length===0)return null;const d=s.map(y=>{const _=y.positioned_relative_to_pcb_board_id;if(!_)return null;const x=o.find(b=>b.pcb_board_id===_);return x?{component:y,board:x,type:"component"}:null}).filter(y=>!!y),h=a.map(y=>{const _=y.positioned_relative_to_pcb_board_id;if(!_||!y.center)return null;const x=o.find(b=>b.pcb_board_id===_);return x?{group:y,board:x,type:"group"}:null}).filter(y=>!!y),f=[...d,...h];if(f.length===0)return null;const p=c.length===0,m=f.filter(y=>y.type==="component"?p||c.includes(y.component.pcb_component_id):p||l.has(y.group.pcb_group_id));if(m.length===0)return null;const g=m.map(y=>y.type==="component"?{id:`${y.board.pcb_board_id}-${y.component.pcb_component_id}-${y.type}`,anchor:y.board.center,anchor_id:y.board.pcb_board_id,target:y.component.center,type:"component",display_offset_x:y.component.display_offset_x,display_offset_y:y.component.display_offset_y}:{id:`${y.board.pcb_board_id}-${y.group.pcb_group_id}-${y.type}`,anchor:y.board.center,anchor_id:y.board.pcb_board_id,target:{x:y.group.anchor_position?.x??y.group.center.x,y:y.group.anchor_position?.y??y.group.center.y},type:"group",display_offset_x:y.group.display_offset_x,display_offset_y:y.group.display_offset_y}).filter(y=>!!y);return V.jsx(Wxe,{targets:g,transform:t,containerWidth:r,containerHeight:i})},MVn=({elements:n,highlightedPrimitives:e,transform:t,containerWidth:r,containerHeight:i})=>{const o=n.filter(y=>E0t(y)),s=n.filter(y=>N8(y)),a=e.map(y=>N8(y._parent_pcb_component)?y._parent_pcb_component.pcb_component_id:N8(y._element)?y._element.pcb_component_id:null).filter(y=>!!y),c=(y,_)=>{if(_.has(y))return;_.add(y);const x=o.find(b=>b.pcb_group_id===y);x?.position_mode==="relative_to_group_anchor"&&x.positioned_relative_to_pcb_group_id&&c(x.positioned_relative_to_pcb_group_id,_)},l=new Set;if(a.forEach(y=>{const _=s.find(x=>x.pcb_component_id===y);_&&(_.position_mode==="relative_to_group_anchor"&&_.positioned_relative_to_pcb_group_id&&c(_.positioned_relative_to_pcb_group_id,l),_.pcb_group_id&&c(_.pcb_group_id,l))}),!Pd(y=>y.is_showing_group_anchor_offsets)&&a.length===0)return null;const d=s.map(y=>{if(y.position_mode==="relative_to_group_anchor"&&y.positioned_relative_to_pcb_group_id){const _=o.find(x=>x.pcb_group_id===y.positioned_relative_to_pcb_group_id);return _&&_.anchor_position?{component:y,parentGroup:_,type:"component"}:null}if(y.pcb_group_id){const _=o.find(x=>x.pcb_group_id===y.pcb_group_id);return _&&_.anchor_position?{component:y,parentGroup:_,type:"component"}:null}return null}).filter(y=>!!y),h=o.map(y=>{if(y.position_mode==="relative_to_group_anchor"&&y.positioned_relative_to_pcb_group_id){const _=o.find(x=>x.pcb_group_id===y.positioned_relative_to_pcb_group_id);if(_&&_.anchor_position&&y.anchor_position)return{group:y,parentGroup:_,type:"group"}}return null}).filter(y=>!!y),f=[...d,...h];if(f.length===0)return null;const p=a.length===0,m=f.filter(y=>y.type==="component"?p||a.includes(y.component.pcb_component_id):p||l.has(y.group.pcb_group_id)||l.has(y.parentGroup.pcb_group_id));if(m.length===0)return null;const g=m.map(y=>{const _=y.parentGroup.anchor_position;return _?y.type==="component"?y.component.center?{id:`${y.parentGroup.pcb_group_id}-${y.component.pcb_component_id}-${y.type}`,anchor:_,anchor_id:y.parentGroup.pcb_group_id,target:y.component.center,type:"component",display_offset_x:y.component.display_offset_x,display_offset_y:y.component.display_offset_y}:null:y.group.anchor_position?{id:`${y.parentGroup.pcb_group_id}-${y.group.pcb_group_id}-${y.type}`,anchor:_,anchor_id:y.parentGroup.pcb_group_id,target:y.group.anchor_position,type:"group",display_offset_x:y.group.display_offset_x,display_offset_y:y.group.display_offset_y}:null:null}).filter(y=>!!y);return V.jsx(Wxe,{targets:g,transform:t,containerWidth:r,containerHeight:i})},EVn=(n,e)=>{const t=n.pcb_component_id,r=e.filter(i=>(i.type==="pcb_smtpad"||i.type==="pcb_plated_hole")&&i.pcb_component_id===t||i.type==="pcb_hole"&&i.pcb_component_id===t);return r.length===0?Yxe([n]):Yxe(r)},TVn=({elements:n,highlightedPrimitives:e,transform:t,containerWidth:r,containerHeight:i})=>{const o=new Map;for(const a of e)N8(a._parent_pcb_component)&&o.set(a._parent_pcb_component.pcb_component_id,a._parent_pcb_component),N8(a._element)&&o.set(a._element.pcb_component_id,a._element);if(o.size===0)return null;const s=[];for(const a of o.values()){const c=EVn(a,n);if(!c)continue;const l=a.positioned_relative_to_pcb_group_id??a.pcb_group_id,u=l?W9(n).pcb_group.get(l):null;s.push({component:a,bbox:c,group:u})}return s.length===0?null:V.jsx("div",{style:{position:"absolute",left:0,top:0,width:r,height:i,overflow:"hidden",pointerEvents:"none",zIndex:Kl.dimensionOverlay},children:V.jsx("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none"},width:r,height:i,children:s.map(({component:a,bbox:c,group:l})=>{const u=mt(t,{x:c.minX,y:c.maxY}),d=mt(t,{x:c.maxX,y:c.minY}),h={x:Math.min(u.x,d.x),y:Math.min(u.y,d.y),width:Math.abs(d.x-u.x),height:Math.abs(d.y-u.y)},f=a.center??{x:(c.minX+c.maxX)/2,y:(c.minY+c.maxY)/2},p=mt(t,f);return V.jsxs("g",{children:[V.jsx("rect",{x:h.x,y:h.y,width:h.width,height:h.height,fill:"none",stroke:"white",strokeWidth:1.5,strokeDasharray:"4,4"}),V.jsx("line",{x1:p.x-6,y1:p.y,x2:p.x+6,y2:p.y,stroke:Qx.COMPONENT_MARKER_STROKE,strokeWidth:1.5}),V.jsx("line",{x1:p.x,y1:p.y-6,x2:p.x,y2:p.y+6,stroke:Qx.COMPONENT_MARKER_STROKE,strokeWidth:1.5}),V.jsx("circle",{cx:p.x,cy:p.y,r:Pu.COMPONENT_MARKER_RADIUS,fill:Qx.COMPONENT_MARKER_FILL,stroke:Qx.COMPONENT_MARKER_STROKE,strokeWidth:1})]},a.pcb_component_id)})})})},CVn=({elements:n,highlightedPrimitives:e,transform:t,containerWidth:r,containerHeight:i})=>{const o=n.filter(f=>wVn(f)),s=n.filter(f=>qxe(f)),a=e.map(f=>qxe(f._element)?f._element.pcb_board_id:null).filter(f=>!!f);if(!Pd(f=>f.is_showing_group_anchor_offsets)&&a.length===0)return null;const l=s.map(f=>{const p=f.pcb_panel_id,m=f.position_mode;if(!p||m!=="relative_to_panel_anchor")return null;const g=o.find(y=>y.pcb_panel_id===p);return g?{board:f,panel:g,type:"board"}:null}).filter(f=>!!f);if(l.length===0)return null;const u=a.length===0,d=l.filter(f=>u||a.includes(f.board.pcb_board_id));if(d.length===0)return null;const h=d.map(f=>f.board.center?{id:`${f.panel.pcb_panel_id}-${f.board.pcb_board_id}-${f.type}`,anchor:f.panel.center,anchor_id:f.panel.pcb_panel_id,target:f.board.center,type:"board",display_offset_x:f.board.display_offset_x,display_offset_y:f.board.display_offset_y}:null).filter(f=>!!f);return V.jsx(Wxe,{targets:h,transform:t,containerWidth:r,containerHeight:i})},tq=n=>{if(n.length===0)return null;let e=n[0].x,t=n[0].y,r=n[0].x,i=n[0].y;for(const o of n)o.x<e&&(e=o.x),o.y<t&&(t=o.y),o.x>r&&(r=o.x),o.y>i&&(i=o.y);return{center:{x:(e+r)/2,y:(t+i)/2},width:r-e,height:i-t}},T0t=(n,e)=>{if(e.length<3)return!1;let t=!1;for(let r=0,i=e.length-1;r<e.length;i=r++){const o=e[r].x,s=e[r].y,a=e[i].x,c=e[i].y;s>n.y!=c>n.y&&n.x<(a-o)*(n.y-s)/(c-s||Number.EPSILON)+o&&(t=!t)}return t},PVn=(n,e,t)=>{const r=[];for(const i of n){if(!i._element)continue;if("x1"in i&&i._element?.type==="pcb_trace"){const a=Hm({x:e.x,y:e.y},{x:i.x1,y:i.y1},{x:i.x2,y:i.y2}),c=i.width||.5,l=Math.max(c*25,2)/t.a;a<l&&r.push(i);continue}if(i.pcb_drawing_type==="polygon"){const a=i.points.map(l=>({x:gn.parse(l.x),y:gn.parse(l.y)})),c=tq(a);if(!c||e.x<c.center.x-c.width/2||e.x>c.center.x+c.width/2||e.y<c.center.y-c.height/2||e.y>c.center.y+c.height/2)continue;T0t(e,a)&&r.push(i);continue}if(i.pcb_drawing_type==="polygon_with_arcs"){const a=i.brep_shape.outer_ring.vertices.map(l=>({x:gn.parse(l.x),y:gn.parse(l.y)})),c=tq(a);if(!c||e.x<c.center.x-c.width/2||e.x>c.center.x+c.width/2||e.y<c.center.y-c.height/2||e.y>c.center.y+c.height/2)continue;T0t(e,a)&&r.push(i);continue}if(!("x"in i&&"y"in i))continue;let o=0,s=0;if("w"in i&&"h"in i)o=i.w,s=i.h;else if("r"in i)o=i.r*2,s=i.r*2;else if("rX"in i&&"rY"in i)o=i.rX*2,s=i.rY*2;else continue;Math.abs(i.x-e.x)<o/2&&Math.abs(i.y-e.y)<s/2&&r.push(i)}return r},AVn=({elements:n,children:e,transform:t,primitives:r,onMouseHoverOverPrimitives:i})=>{const[o,s]=q.useState([]),[a,c]=q.useState({x:0,y:0}),[l,{width:u,height:d}]=BO(),h=q.useMemo(()=>{const p=[];for(const m of o){if(m._element?.type==="pcb_via"||m._element?.type==="pcb_component"||m?.layer==="drill"||m?.is_hoverable===!1)continue;let g=null,y=0,_=0;if(m.pcb_drawing_type==="polygon"){const S=tq(m.points);if(!S)continue;g=S.center,y=S.width,_=S.height}else if(m.pcb_drawing_type==="polygon_with_arcs"){const S=m.brep_shape.outer_ring.vertices.map(C=>({x:C.x,y:C.y})),E=tq(S);if(!E)continue;g=E.center,y=E.width,_=E.height}else"x"in m&&"y"in m&&(g={x:m.x,y:m.y},y="w"in m?m.w:"r"in m?m.r*2:"rX"in m&&"rY"in m?m.rX*2:0,_="h"in m?m.h:"r"in m?m.r*2:"rX"in m&&"rY"in m?m.rY*2:0);if(!g)continue;const x=mt(t,g),b={w:y*t.a,h:_*t.a},w=p.filter(S=>x.x===S.screen_x&&x.y===S.screen_y&&b.w===S.screen_w&&b.h===S.screen_h).length;p.push({...m,x:g.x,y:g.y,w:y,h:_,screen_x:x.x,screen_y:x.y,screen_w:b.w,screen_h:b.h,same_space_index:w})}return p},[o,t]),f=(p,m,g,y)=>{c({x:p,y:m});const _=mt(Y2(g),{x:p,y:m}),x=PVn(y,_,g);fVn(new Set(x.map(b=>b._pcb_drawing_object_id)),new Set(o.map(b=>b._pcb_drawing_object_id)))||(s(x),i(x))};return V.jsxs("div",{ref:l,style:{position:"relative",width:"100%",height:"100%"},onMouseMove:p=>{if(t){const m=p.currentTarget.getBoundingClientRect(),g=p.clientX-m.left,y=p.clientY-m.top;f(g,y,t,r)}},onTouchStart:p=>{if(t){const m=p.touches[0],g=p.currentTarget.getBoundingClientRect(),y=m.clientX-g.left,_=m.clientY-g.top;f(y,_,t,r)}},children:[e,V.jsx(vVn,{elements:n,mousePos:a,highlightedPrimitives:h}),t&&V.jsxs(V.Fragment,{children:[V.jsx(SVn,{elements:n,highlightedPrimitives:h,transform:t,containerWidth:u,containerHeight:d}),V.jsx(MVn,{elements:n,highlightedPrimitives:h,transform:t,containerWidth:u,containerHeight:d}),V.jsx(TVn,{elements:n,highlightedPrimitives:h,transform:t,containerWidth:u,containerHeight:d}),V.jsx(CVn,{elements:n,highlightedPrimitives:h,transform:t,containerWidth:u,containerHeight:d})]})]})},C0t=["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)"],RVn=({children:n,transform:e=Jc(),elements:t=[],hoveredComponentIds:r=[]})=>{const[i,{width:o,height:s}]=BO(),a=q.useRef(null),{is_showing_pcb_groups:c,pcb_group_view_mode:l,is_showing_group_anchor_offsets:u}=Pd(d=>({is_showing_pcb_groups:d.is_showing_pcb_groups,pcb_group_view_mode:d.pcb_group_view_mode,is_showing_group_anchor_offsets:d.is_showing_group_anchor_offsets}));return q.useEffect(()=>{const d=a.current;if(!d||!o||!s)return;d.width=o,d.height=s;const h=d.getContext("2d");if(!h||(h.clearRect(0,0,o,s),!c))return;const f=t.filter(S=>S.type==="pcb_group"),p=t.filter(S=>S.type==="pcb_component"),m=t.filter(S=>S.type==="source_group"),g=new Map(m.map(S=>[S.source_group_id,S])),y=f.filter(S=>{if(S.name?.toLowerCase().includes("subpanel"))return!1;if(l==="all")return!0;if(!S.source_group_id)return!1;const E=g.get(S.source_group_id);return E?E.was_automatically_named!==!0:!1}),_=new Map;m.forEach(S=>{const E=S;if(E.parent_source_group_id){const C=_.get(E.parent_source_group_id)||[];C.push(S.source_group_id),_.set(E.parent_source_group_id,C)}});const x=S=>{const E=[],C=_.get(S)||[];for(const A of C)E.push(A),E.push(...x(A));return E},b=S=>{const E=m.find(C=>C.source_group_id===S);return E?.parent_source_group_id?1+b(E.parent_source_group_id):0},w=new Set;if(r.length>0)for(const S of p){if(!r.includes(S.pcb_component_id))continue;const E=S.positioned_relative_to_pcb_group_id??S.pcb_group_id;E&&w.add(E)}y.forEach((S,E)=>{let C=p.filter(ke=>ke.pcb_group_id===S.pcb_group_id);if(S.source_group_id){const ke=x(S.source_group_id),je=f.filter(Re=>Re.source_group_id&&ke.includes(Re.source_group_id));for(const Re of je){const be=p.filter(Ce=>Ce.pcb_group_id===Re.pcb_group_id);C=[...C,...be]}}let A,R,L,O,F=!1;if(S.center&&S.width&&S.height){F=!0;const ke=S.width/2,je=S.height/2;A=S.center.x-ke,L=S.center.x+ke,R=S.center.y-je,O=S.center.y+je}else if(C.length===0||(A=1/0,R=1/0,L=-1/0,O=-1/0,C.forEach(ke=>{if(ke.center&&typeof ke.width=="number"&&typeof ke.height=="number"){const je=ke.center.x-ke.width/2,Re=ke.center.x+ke.width/2,be=ke.center.y+ke.height/2,Ce=ke.center.y-ke.height/2;A=Math.min(A,je),L=Math.max(L,Re),R=Math.min(R,Ce),O=Math.max(O,be)}}),A===1/0||L===-1/0))return;const B=S.source_group_id?b(S.source_group_id):0,j=S.source_group_id?x(S.source_group_id).length>0:!1;if(!F){const Re=1+(j?.5:0);A-=Re,L+=Re,R-=Re,O+=Re}const G=mt(e,{x:A,y:O}),W=mt(e,{x:L,y:O}),Q=mt(e,{x:A,y:R}),ne=mt(e,{x:L,y:R}),ue=C0t[E%C0t.length];h.strokeStyle=ue,h.lineWidth=2;const te=Math.max(4,Math.min(12,8*Math.abs(e.a))),re=Math.max(2,Math.min(6,4*Math.abs(e.a))),ce=te*(j?1.3:1),fe=re;h.setLineDash([ce,fe]),h.beginPath(),h.moveTo(G.x,G.y),h.lineTo(W.x,W.y),h.lineTo(ne.x,ne.y),h.lineTo(Q.x,Q.y),h.closePath(),h.stroke();const Me=Math.max(8,Math.min(12,10*Math.abs(e.a))),Pe=B==0||B==1?0:B*.11,Ne=Me*(1-Pe),me=4,Se=S.name||`Group ${E+1}`;h.font=`${Ne}px sans-serif`,h.setLineDash([]);const He=h.measureText(Se).width+me*2,Ye=Ne+me*2,We=G.x-5,ge=G.y-5,Ze=3;if(h.fillStyle="rgba(0, 0, 0, 0.8)",h.beginPath(),h.roundRect(We,ge-Ye,He,Ye,Ze),h.fill(),h.fillStyle=ue,h.textAlign="left",h.textBaseline="middle",h.fillText(Se,We+me,ge-Ye/2),u&&w.has(S.pcb_group_id)&&!!S.anchor_position&&S.anchor_position){const ke=Array.isArray(S.anchor_position)?{x:S.anchor_position[0]??0,y:S.anchor_position[1]??0}:{x:S.anchor_position.x,y:S.anchor_position.y},je=mt(e,ke);h.strokeStyle="white",h.lineWidth=1.5,h.setLineDash([]);const Re=Math.max(4,Math.min(8,6*Math.abs(e.a)));h.beginPath(),h.moveTo(je.x-Re,je.y),h.lineTo(je.x+Re,je.y),h.stroke(),h.beginPath(),h.moveTo(je.x,je.y-Re),h.lineTo(je.x,je.y+Re),h.stroke()}})},[t,e,o,s,c,l,u,r]),V.jsxs("div",{ref:i,style:{position:"relative",width:"100%",height:"100%"},children:[n,V.jsx("canvas",{ref:a,style:{position:"absolute",top:0,left:0,pointerEvents:"none",zIndex:Kl.pcbGroupOverlay,display:c?"block":"none"}})]})},NVn=({transform:n,soup:e,children:t})=>{const r=Pd(a=>a.is_showing_rats_nest),{netMap:i,idToNetMap:o}=q.useMemo(()=>i0t(e||[]),[e]),s=q.useMemo(()=>{if(!e||!r)return[];const a=h=>{const f=W9(e)[h.replace(/_\d+$/,"")].get(h);return f&&"x"in f&&"y"in f?{x:f.x,y:f.y}:null},c=(h,f)=>{const p=i[f]||[];let m=null,g=1/0;return p.forEach(y=>{const _=a(y);if(_){const x=Math.sqrt((h.x-_.x)**2+(h.y-_.y)**2);x<g&&x>0&&(g=x,m=_)}}),m},l=W9(e).pcb_port.list(),u=W9(e).source_trace.list(),d=[];return l.forEach((h,f)=>{const p=o[h.pcb_port_id];let m=!1;for(const _ of u)_.connected_source_port_ids.includes(h.source_port_id)&&_.connected_source_net_ids.length>0&&(m=!0);if(!p)return;const g={x:h.x,y:h.y},y=c(g,p);y&&d.push({key:`${h.pcb_port_id}-${f}`,startPoint:g,endPoint:y,isInNet:m})}),d},[e,i,o,r]);return!e||!r?t:(n||(n=Jc()),V.jsxs("div",{style:{position:"relative"},children:[t,V.jsx("svg",{style:{position:"absolute",left:0,top:0,width:"100%",height:"100%",pointerEvents:"none",opacity:.5,zIndex:Kl.ratsNestOverlay},children:s.map(({key:a,startPoint:c,endPoint:l,isInNet:u})=>{const d=mt(n,c),h=mt(n,l);return V.jsx("line",{x1:d.x,y1:d.y,x2:h.x,y2:h.y,stroke:"white",strokeWidth:"1",strokeDasharray:u?"6,6":void 0},a)})})]}))},IVn={version:"1.11.361"},I8=(n,e,t)=>{const r=Pd(s=>s.is_mouse_over_container),i=q.useRef(r),o=q.useRef(e);q.useEffect(()=>{i.current=r},[r]),q.useEffect(()=>{o.current=e},[e]),q.useEffect(()=>{if(!n)return;const s=a=>{const c=a.target;if(c.tagName==="INPUT"||c.tagName==="TEXTAREA"||c.isContentEditable)return;const l=n.split("+"),u=l.includes("ctrl"),d=l.includes("shift"),h=l.includes("alt"),f=l.includes("meta"),p=l[l.length-1],m=t?.current?t.current.contains(document.activeElement)||document.activeElement===t.current:!1;(i.current||m)&&(!u||a.ctrlKey)&&(!d||a.shiftKey)&&(!h||a.altKey)&&(!f||a.metaKey)&&a.key.toLowerCase()===p.toLowerCase()&&(a.preventDefault(),o.current())};return window.addEventListener("keydown",s),()=>{window.removeEventListener("keydown",s)}},[n])},kVn=()=>{const[n,e]=q.useState(!1);return q.useEffect(()=>{const t=()=>{e(window.innerWidth<=768)};return t(),window.addEventListener("resize",t),()=>window.removeEventListener("resize",t)},[]),n},UO=(n,e={stopPropagation:!0})=>{const t=q.useRef(0),r=q.useCallback(s=>{e.stopPropagation&&s.stopPropagation();const a=Date.now();a-t.current<300||(t.current=a,n?.(s))},[n,e.stopPropagation]),i=q.useCallback(s=>{s.preventDefault(),r(s)},[r]);return{onClick:r,onTouchEnd:i,style:{touchAction:"manipulation"}}},HS=({children:n,isSmallScreen:e,onClick:t,...r})=>{const{style:i,...o}=UO(t);return V.jsx("div",{...r,...o,style:{backgroundColor:"#1F1F1F",border:"1px solid #666",margin:0,padding:4,paddingLeft:e?8:6,paddingRight:e?8:6,borderRadius:2,color:"#eee",cursor:"pointer",fontSize:12,height:"fit-content",userSelect:"none",whiteSpace:"nowrap",...i,...r.style},children:n})},OVn=({errorId:n,errorMessage:e,copiedErrorId:t,onCopy:r})=>{const{style:i,...o}=UO(()=>r(e,n));return V.jsx("button",{type:"button","aria-label":t===n?"Error message copied":"Copy error message",style:{position:"absolute",top:12,right:16,cursor:"pointer",color:"#888",fontSize:16,background:"none",border:"none",padding:0,display:"flex",alignItems:"center",...i},...o,children:t===n?V.jsx("span",{style:{color:"#4caf50",fontSize:12},children:"Copied!"}):V.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"currentColor",children:V.jsx("path",{d:"M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 16H8V7h11v14z"})})})},LVn=({elements:n,isOpen:e,isSmallScreen:t,onToggle:r,setHoveredErrorId:i})=>{const[o,s]=q.useState(null),[a,c]=q.useState(new Set),[l,u]=q.useState(new Set),[,d]=kYn(),h=q.useMemo(()=>n?.filter(_=>_.type.includes("error"))??[],[n]),f=h.length,p=q.useCallback((_,x)=>_.pcb_trace_error_id||`error_${x}_${_.error_type}_${_.message?.slice(0,20)}`,[]),m=q.useMemo(()=>{const _=new Map;return h.forEach((x,b)=>{const w=x.error_type||"unknown_error",S=_.get(w)||[];S.push({error:x,index:b,errorId:p(x,b)}),_.set(w,S)}),Array.from(_.entries()).map(([x,b])=>({errorType:x,errors:b}))},[h,p]),g=q.useCallback(_=>{c(x=>{const b=new Set(x);return b.has(_)?b.delete(_):b.add(_),b})},[]),y=q.useCallback(_=>{u(x=>{const b=new Set(x);return b.has(_)?b.delete(_):b.add(_),b})},[]);return V.jsxs("div",{style:{position:"relative"},children:[V.jsx(HS,{isSmallScreen:t,style:f>0?{color:"red"}:void 0,onClick:r,children:V.jsxs("div",{children:[f," errors"]})}),e&&f>0&&V.jsx("div",{style:{position:"absolute",top:"100%",left:0,backgroundColor:"#2a2a2a",border:"1px solid #666",borderRadius:4,marginTop:4,zIndex:1e3,minWidth:t?"280px":"400px",maxWidth:t?"90vw":"600px",maxHeight:"400px",overflow:"auto",boxShadow:"0 4px 12px rgba(0, 0, 0, 0.3)"},children:m.map(({errorType:_,errors:x},b)=>{const w=a.has(_);return V.jsxs("div",{style:{borderBottom:b<m.length-1?"1px solid #444":"none"},children:[V.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"12px 16px",cursor:"pointer",backgroundColor:"#232323",transition:"background-color 0.2s ease",touchAction:"manipulation",position:"sticky",top:0,zIndex:1},onMouseEnter:S=>{S.currentTarget.style.backgroundColor="#303030"},onMouseLeave:S=>{S.currentTarget.style.backgroundColor="#232323"},onTouchStart:S=>{S.stopPropagation(),S.currentTarget.style.backgroundColor="#303030"},onTouchEnd:S=>{S.stopPropagation(),S.preventDefault(),S.currentTarget.style.backgroundColor="#232323",g(_)},onClick:S=>{S.stopPropagation(),g(_)},children:[V.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,color:"#ff6b6b"},children:[V.jsx("div",{style:{color:"#888",fontSize:"16px",transform:w?"rotate(90deg)":"rotate(0deg)",transition:"transform 0.2s ease",flexShrink:0},children:"›"}),V.jsx("div",{style:{fontWeight:"bold",fontSize:t?"12px":"13px"},children:_})]}),V.jsx("div",{style:{fontSize:t?"12px":"13px",color:"#aaa",whiteSpace:"nowrap",marginLeft:12},children:x.length})]}),!w&&x.map(({error:S,index:E,errorId:C})=>{const A=l.has(C),R=S.message??"No error message";return V.jsxs("div",{style:{borderTop:"1px solid #3a3a3a"},children:[V.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12,padding:"12px 16px 12px 24px",cursor:"pointer",backgroundColor:"#2a2a2a",transition:"background-color 0.2s ease",touchAction:"manipulation"},onMouseEnter:L=>{L.currentTarget.style.backgroundColor="#333",i(C)},onMouseLeave:L=>{L.currentTarget.style.backgroundColor="#2a2a2a",i(null)},onTouchStart:L=>{L.stopPropagation(),L.currentTarget.style.backgroundColor="#333",i(C)},onTouchEnd:L=>{L.stopPropagation(),L.preventDefault(),L.currentTarget.style.backgroundColor="#2a2a2a",i(null),y(C)},onClick:L=>{L.stopPropagation(),y(C)},children:[V.jsx("div",{style:{flex:1,fontSize:t?"12px":"13px",color:"#ddd",lineHeight:1.4,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",userSelect:"text"},onMouseDown:L=>L.stopPropagation(),onClick:L=>L.stopPropagation(),children:R}),V.jsx("div",{style:{color:"#888",fontSize:"16px",transform:A?"rotate(0deg)":"rotate(90deg)",transition:"transform 0.2s ease",flexShrink:0},children:"›"})]}),A&&V.jsxs("div",{"data-error-id":E,style:{display:"block",padding:"12px 16px 12px 24px",backgroundColor:"#1a1a1a",borderTop:"1px solid #444",position:"relative"},children:[V.jsx("div",{style:{fontSize:t?"11px":"12px",color:"#ccc",lineHeight:1.5,wordWrap:"break-word",overflowWrap:"break-word",hyphens:"auto",userSelect:"text",paddingRight:30},onMouseDown:L=>L.stopPropagation(),onClick:L=>L.stopPropagation(),children:R}),V.jsx(OVn,{errorId:C,errorMessage:R,copiedErrorId:o,onCopy:(L,O)=>{d(L),s(O),setTimeout(()=>s(null),2e3)}})]})]},C)})]},_)})})]})},DVn=({name:n,selected:e,onClick:t})=>{const{style:r,...i}=UO(t);return V.jsxs("div",{className:$P`
5461
+ `,pVn=({children:n,transform:e=Jc(),elements:t})=>{const r=q.useRef(null),{isShowingDRCErrors:i,hoveredErrorId:o}=Pd(l=>({isShowingDRCErrors:l.is_showing_drc_errors,hoveredErrorId:l.hovered_error_id}));if(!t)return V.jsx("div",{style:{position:"relative"},ref:r,children:n});const s=t.filter(l=>l.type==="pcb_trace_error"),a=t.filter(l=>l.type==="pcb_trace_error"&&l.message?.includes("Multiple components found with name")),c=new Map;return t.forEach(l=>{l.type==="pcb_port"&&c.set(l.pcb_port_id,l)}),V.jsxs("div",{style:{position:"relative"},ref:r,children:[n,s.map((l,u)=>{const{pcb_port_ids:d,pcb_trace_id:h}=l,f=d?.[0]?c.get(d[0]):void 0,p=d?.[1]?c.get(d[1]):void 0,m=t?W9(t).pcb_trace.get(h):void 0,g=l.pcb_trace_error_id||`error_${u}_${l.error_type}_${l.message?.slice(0,20)}`,y=o===g;if(f&&p){const _=mt(e,{x:f.x,y:f.y}),x=mt(e,{x:p.x,y:p.y});if(!i)return null;const b=!(isNaN(_.x)||isNaN(_.y)||isNaN(x.x)||isNaN(x.y)),w={x:(_.x+x.x)/2,y:(_.y+x.y)/2};if(isNaN(w.x)||isNaN(w.y))return null;const S=Vxe(w,r);return V.jsxs(q.Fragment,{children:[V.jsx(dVn,{screenPort1:_,screenPort2:x,errorCenter:w,canLineBeDrawn:b,isHighlighted:y}),V.jsx("div",{style:{position:"absolute",left:w.x-15,top:w.y-15,width:30,height:30,zIndex:Kl.errorOverlay+5,cursor:"pointer",borderRadius:"50%"},onMouseEnter:E=>{const C=E.currentTarget.nextElementSibling;if(C){const A=C.querySelector(".error-message");A&&(A.style.opacity="1")}},onMouseLeave:E=>{if(!y){const C=E.currentTarget.nextElementSibling;if(C){const A=C.querySelector(".error-message");A&&(A.style.opacity="0")}}}}),V.jsx("div",{style:{position:"absolute",zIndex:y?200:100,left:S.left,top:S.top,color:y?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:i||y?"flex":"none",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:S.transform},children:V.jsx("div",{className:`error-message ${Gxe}`,style:{opacity:y?1:0,border:`1px solid ${y?"#ff4444":"red"}`},children:l.message})})]},g)}if(m?.route&&(i||y)){const _=m.route.map(S=>mt(e,{x:S.x,y:S.y}));if(_.some(S=>isNaN(S.x)||isNaN(S.y)))return null;const x=Math.floor(_.length/2),b=_[x],w=Vxe(b,r);return V.jsxs(q.Fragment,{children:[V.jsx(hVn,{points:_,errorCenter:b,isHighlighted:y}),V.jsx("div",{style:{position:"absolute",left:b.x-15,top:b.y-15,width:30,height:30,zIndex:Kl.errorOverlay+5,cursor:"pointer",borderRadius:"50%"},onMouseEnter:S=>{const E=S.currentTarget.nextElementSibling;if(E){const C=E.querySelector(".error-message");C&&(C.style.opacity="1")}},onMouseLeave:S=>{if(!y){const E=S.currentTarget.nextElementSibling;if(E){const C=E.querySelector(".error-message");C&&(C.style.opacity="0")}}}}),V.jsx("div",{style:{position:"absolute",zIndex:y?Kl.errorOverlay+10:Kl.errorOverlay+1,left:w.left,top:w.top,color:y?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:"flex",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:w.transform},children:V.jsx("div",{className:`error-message ${Gxe}`,style:{opacity:y?1:0,border:`1px solid ${y?"#ff4444":"red"}`},children:l.message})})]},g)}return null}),a.map((l,u)=>{const d=l.component_name||l.message?.match(/name "([^"]+)"/)?.[1];if(!d)return null;const h=t?.filter(m=>m.type==="source_component"&&m.name===d||m.type==="pcb_component"&&t?.find(g=>g.type==="source_component"&&g.source_component_id===m.source_component_id&&g.name===d))||[],f=l.pcb_trace_error_id||`error_${u}_${l.error_type}_${l.message?.slice(0,20)}`,p=o===f;return!p&&!i?null:h.map((m,g)=>{let y={x:0,y:0};if(m.type==="pcb_component")y=m.center||{x:0,y:0};else if(m.type==="source_component"){const A=t?.find(R=>R.type==="pcb_component"&&R.source_component_id===m.source_component_id);A&&A.type==="pcb_component"&&(y=A.center||{x:0,y:0})}const _=mt(e,y);if(isNaN(_.x)||isNaN(_.y))return null;const x=Math.abs(e.a),E=Math.max(8,Math.min(30,.5*x)),C=Vxe(_,r);return V.jsxs(q.Fragment,{children:[V.jsx("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none",mixBlendMode:"difference",zIndex:Kl.errorOverlay},width:"100%",height:"100%",children:p?V.jsx("polygon",{points:`${_.x},${_.y-E*1.25} ${_.x+E},${_.y} ${_.x},${_.y+E*1.25} ${_.x-E},${_.y}`,fill:"#ff4444"}):V.jsx("circle",{cx:_.x,cy:_.y,r:E,fill:"none",stroke:p?"#ff4444":"red",strokeWidth:p?Math.max(2,E*.15):Math.max(1,E*.1),opacity:1})}),V.jsx("div",{style:{position:"absolute",left:_.x-(E+10),top:_.y-(E+10),width:(E+10)*2,height:(E+10)*2,zIndex:Kl.errorOverlay+5,cursor:"pointer",borderRadius:"50%"},onMouseEnter:A=>{const R=A.currentTarget.nextElementSibling;if(R){const L=R.querySelector(".error-message");L&&(L.style.opacity="1")}},onMouseLeave:A=>{if(!p){const R=A.currentTarget.nextElementSibling;if(R){const L=R.querySelector(".error-message");L&&(L.style.opacity="0")}}}}),V.jsx("div",{style:{position:"absolute",zIndex:p?Kl.errorOverlay+20:Kl.errorOverlay+10,left:C.left,top:C.top,color:p?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:i||p?"flex":"none",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:C.transform},children:V.jsx("div",{className:`error-message ${Gxe}`,style:{opacity:p?1:0,border:`1px solid ${p?"#ff4444":"red"}`},children:l.message})})]},`${f}_${g}`)})})]})};function fVn(n,e){return n.size!==e.size?!1:Array.from(n).every(t=>e.has(t))}function mVn({primitiveElement:n,elements:e}){let t=n.trace_length?`${n.trace_length.toFixed(3)}`:"";const r=W9(e).source_trace.get(n?.source_trace_id);if(r?.display_name&&(r?.max_length?t+=` / ${r.max_length}mm `:t+=" mm ",t+=`(${r.display_name})`),!t)return null;const i=n.trace_length&&r?.max_length&&n.trace_length>r.max_length;return{text:t,isOverLength:i}}function yVn(n){const{primitives:e,is_showing_multiple_traces_length:t,elements:r}=n,i=e.filter(c=>c._element.type==="pcb_trace"),o=r.filter(c=>c.type==="source_trace"),s=e.filter(c=>c._element.type!=="pcb_trace"),a=i.filter(c=>o.some(l=>c._element.type==="pcb_trace"&&c._element.source_trace_id===l.source_trace_id&&l.max_length!==void 0));if(!t)return[...s,...a];if(i.length>1){const c=i.reduce((l,u)=>{const d=l._element.trace_length;return u._element.trace_length<d?u:l},i[0]);return[...s,c]}return e}var gVn={position:"absolute",left:0,top:0,pointerEvents:"none",color:"red",fontFamily:"sans-serif",fontSize:12,textShadow:"0 0 2px black"},_Vn=n=>{const{_element:e,_parent_pcb_component:t,_parent_source_component:r,_source_port:i}=n;switch(e.type){case"pcb_trace":return e.trace_length?`${e.trace_length.toFixed(3)}`:"";case"pcb_smtpad":case"pcb_plated_hole":{const o=[],s=Array.from(new Set((e.port_hints??[]).concat(i?.port_hints??[]))).filter(c=>!/^[0-9]+$/.test(c)).filter(c=>!c.includes("unnamed_")).sort((c,l)=>l.localeCompare(c)),a=r&&"name"in r&&r.name&&!r.name.includes("unnamed_")?r.name:null;return s.length>0?a?o.push(...s.map(c=>`${a}.${c}`)):o.push(...s):a&&o.push(a),o.join(", ")}default:return""}},xVn={top:"red",bottom:"aqua"},bVn=({primitive:n,mousePos:e,elements:t})=>{const[r,i]=q.useState(!1),o=n._element;q.useEffect(()=>{setTimeout(()=>{i(!0)},100)},[]);const[s,a,c,l]=[n.screen_x,n.screen_y,n.screen_w,n.screen_h],u=n.same_space_index??0,d=26,h=xVn[n?._element?.layer]??"red";let f=0;if(o.type==="pcb_smtpad"&&o?.shape==="rotated_rect"?f=o?.ccw_rotation??0:(o.type==="pcb_smtpad"&&(o?.shape==="pill"||o?.shape==="rotated_pill")&&"ccw_rotation"in n||o.type==="pcb_plated_hole"&&(o?.shape==="pill"||o?.shape==="oval")&&"ccw_rotation"in n)&&(f=o.ccw_rotation??0),o.type==="pcb_trace"){const g=mVn({primitiveElement:o,elements:t});if(!g)return null;const y=e.y-35;return V.jsx("div",{style:{zIndex:Kl.elementOverlay,position:"absolute",left:e.x,top:y,color:h,pointerEvents:"none",transform:"translateX(-50%)"},children:V.jsx("div",{style:{backgroundColor:"#f2efcc",color:g.isOverLength?"red":"black",textShadow:"none",WebkitFontSmoothing:"antialiased",MozOsxFontSmoothing:"grayscale",padding:"6px 6px",borderRadius:"6px",fontSize:"14px",minWidth:"45px",textAlign:"center",whiteSpace:"nowrap"},children:g.text})})}const p=_Vn(n);return p.trim().length===0?null:V.jsx("div",{style:{zIndex:Kl.elementOverlay,position:"absolute",left:s-c/2-8,top:a-l/2-8,width:c+16,height:l+16,color:h,transform:`rotate(${-f}deg)`,transformOrigin:"center center"},children:V.jsx("div",{style:{width:r?`calc(100% + ${d*2*u}px)`:"100%",height:r?`calc(100% + ${d*2*u}px)`:"100%",marginLeft:r?`${-d*u}px`:0,marginTop:r?`${-d*u}px`:0,border:`1px solid ${h}`,opacity:r||u===0?1:0,transition:"width 0.2s, height 0.2s, margin-left 0.2s, margin-top 0.2s, opacity 0.2s"},children:V.jsx("div",{style:{position:"absolute",bottom:l+20+d*u,marginRight:r?`${-d*u}px`:0,marginBottom:r?0:-d*u,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(${f}deg)`,minWidth:"45px",textAlign:"center"},children:p})})})},vVn=({highlightedPrimitives:n,mousePos:e,elements:t})=>{const[r,i]=Pd(a=>[a.is_moving_component,a.is_showing_multiple_traces_length]),o=n.some(a=>a._element.type==="pcb_smtpad")&&n.some(a=>a._element.type==="pcb_trace");let s=n;return o&&(s=s.filter(a=>a._element.type==="pcb_smtpad")),s=yVn({primitives:s,is_showing_multiple_traces_length:i,elements:t}),V.jsx("div",{style:gVn,children:!r&&s.map((a,c)=>V.jsx(bVn,{primitive:a,mousePos:e,elements:t},c))})},N8=n=>n?.type==="pcb_component",E0t=n=>n?.type==="pcb_group",wVn=n=>n?.type==="pcb_panel",qxe=n=>n?.type==="pcb_board",Pu={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},Qx={OFFSET_LINE:"white",COMPONENT_MARKER_FILL:"#66ccff",COMPONENT_MARKER_STROKE:"white",LABEL_TEXT:"white"},Wxe=({targets:n,transform:e,containerWidth:t,containerHeight:r})=>{if(n.length===0)return null;const i={color:Qx.LABEL_TEXT,mixBlendMode:"difference",pointerEvents:"none",fontSize:Pu.LABEL_FONT_SIZE,fontFamily:"monospace",fontWeight:"bold"},o=new Map;return n.forEach(s=>{if(!o.has(s.anchor_id)){const a=mt(e,s.anchor);o.set(s.anchor_id,a)}}),V.jsx("div",{style:{position:"absolute",left:0,top:0,width:t,height:r,overflow:"hidden",pointerEvents:"none",zIndex:Kl.dimensionOverlay},children:V.jsxs("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none"},width:t,height:r,children:[n.map(s=>{const a=s.anchor,c=s.anchor_id,l=s.target,u=o.get(c),d=mt(e,l),h=l.x-a.x,f=l.y-a.y,p=Math.abs(d.x-u.x),m=Math.abs(d.y-u.y),g=d.y<u.y,y=d.x>u.x,_=g?Pu.LABEL_OFFSET_ABOVE:Pu.LABEL_OFFSET_BELOW,x=y?Pu.LABEL_OFFSET_RIGHT:Pu.LABEL_OFFSET_LEFT,b=p>Pu.MIN_LINE_LENGTH_FOR_LABEL,w=m>Pu.MIN_LINE_LENGTH_FOR_LABEL,S=`${s.display_offset_x??h.toFixed(2)}mm`,E=`${s.display_offset_y??f.toFixed(2)}mm`;return V.jsxs("g",{children:[V.jsx("line",{x1:u.x,y1:u.y,x2:d.x,y2:u.y,stroke:Qx.OFFSET_LINE,strokeWidth:Pu.LINE_STROKE_WIDTH,strokeDasharray:Pu.LINE_DASH_PATTERN}),V.jsx("line",{x1:d.x,y1:u.y,x2:d.x,y2:d.y,stroke:Qx.OFFSET_LINE,strokeWidth:Pu.LINE_STROKE_WIDTH,strokeDasharray:Pu.LINE_DASH_PATTERN}),s.type==="component"||s.type==="board"?V.jsx("circle",{cx:d.x,cy:d.y,r:Pu.COMPONENT_MARKER_RADIUS,fill:Qx.COMPONENT_MARKER_FILL,stroke:Qx.COMPONENT_MARKER_STROKE,strokeWidth:1}):V.jsxs(V.Fragment,{children:[V.jsx("line",{x1:d.x-Pu.ANCHOR_MARKER_SIZE,y1:d.y,x2:d.x+Pu.ANCHOR_MARKER_SIZE,y2:d.y,stroke:Qx.OFFSET_LINE,strokeWidth:Pu.ANCHOR_MARKER_STROKE_WIDTH}),V.jsx("line",{x1:d.x,y1:d.y-Pu.ANCHOR_MARKER_SIZE,x2:d.x,y2:d.y+Pu.ANCHOR_MARKER_SIZE,stroke:Qx.OFFSET_LINE,strokeWidth:Pu.ANCHOR_MARKER_STROKE_WIDTH})]}),b&&V.jsx("foreignObject",{x:Math.min(u.x,d.x),y:u.y+_,width:Math.abs(d.x-u.x),height:20,style:{overflow:"visible"},children:V.jsx("div",{style:{...i,textAlign:"center"},children:S})}),w&&V.jsx("foreignObject",{x:d.x+x,y:Math.min(u.y,d.y),width:Pu.Y_LABEL_MIN_WIDTH,height:Math.abs(d.y-u.y),style:{overflow:"visible"},children:V.jsx("div",{style:{...i,display:"flex",alignItems:"center",justifyContent:y?"flex-start":"flex-end",whiteSpace:"nowrap",padding:"0 4px",height:"100%"},children:E})})]},s.id)}),Array.from(o.entries()).map(([s,a])=>V.jsxs("g",{children:[V.jsx("line",{x1:a.x-Pu.ANCHOR_MARKER_SIZE,y1:a.y,x2:a.x+Pu.ANCHOR_MARKER_SIZE,y2:a.y,stroke:Qx.OFFSET_LINE,strokeWidth:Pu.ANCHOR_MARKER_STROKE_WIDTH}),V.jsx("line",{x1:a.x,y1:a.y-Pu.ANCHOR_MARKER_SIZE,x2:a.x,y2:a.y+Pu.ANCHOR_MARKER_SIZE,stroke:Qx.OFFSET_LINE,strokeWidth:Pu.ANCHOR_MARKER_STROKE_WIDTH})]},`anchor-${s}`))]})})},SVn=({elements:n,highlightedPrimitives:e,transform:t,containerWidth:r,containerHeight:i})=>{const o=n.filter(y=>qxe(y)),s=n.filter(y=>N8(y)),a=n.filter(y=>E0t(y)),c=e.map(y=>N8(y._parent_pcb_component)?y._parent_pcb_component.pcb_component_id:N8(y._element)?y._element.pcb_component_id:null).filter(y=>!!y),l=new Set;if(c.forEach(y=>{const _=s.find(x=>x.pcb_component_id===y);_?.pcb_group_id&&l.add(_.pcb_group_id)}),!Pd(y=>y.is_showing_group_anchor_offsets)&&c.length===0)return null;const d=s.map(y=>{const _=y.positioned_relative_to_pcb_board_id;if(!_)return null;const x=o.find(b=>b.pcb_board_id===_);return x?{component:y,board:x,type:"component"}:null}).filter(y=>!!y),h=a.map(y=>{const _=y.positioned_relative_to_pcb_board_id;if(!_||!y.center)return null;const x=o.find(b=>b.pcb_board_id===_);return x?{group:y,board:x,type:"group"}:null}).filter(y=>!!y),f=[...d,...h];if(f.length===0)return null;const p=c.length===0,m=f.filter(y=>y.type==="component"?p||c.includes(y.component.pcb_component_id):p||l.has(y.group.pcb_group_id));if(m.length===0)return null;const g=m.map(y=>y.type==="component"?{id:`${y.board.pcb_board_id}-${y.component.pcb_component_id}-${y.type}`,anchor:y.board.center,anchor_id:y.board.pcb_board_id,target:y.component.center,type:"component",display_offset_x:y.component.display_offset_x,display_offset_y:y.component.display_offset_y}:{id:`${y.board.pcb_board_id}-${y.group.pcb_group_id}-${y.type}`,anchor:y.board.center,anchor_id:y.board.pcb_board_id,target:{x:y.group.anchor_position?.x??y.group.center.x,y:y.group.anchor_position?.y??y.group.center.y},type:"group",display_offset_x:y.group.display_offset_x,display_offset_y:y.group.display_offset_y}).filter(y=>!!y);return V.jsx(Wxe,{targets:g,transform:t,containerWidth:r,containerHeight:i})},MVn=({elements:n,highlightedPrimitives:e,transform:t,containerWidth:r,containerHeight:i})=>{const o=n.filter(y=>E0t(y)),s=n.filter(y=>N8(y)),a=e.map(y=>N8(y._parent_pcb_component)?y._parent_pcb_component.pcb_component_id:N8(y._element)?y._element.pcb_component_id:null).filter(y=>!!y),c=(y,_)=>{if(_.has(y))return;_.add(y);const x=o.find(b=>b.pcb_group_id===y);x?.position_mode==="relative_to_group_anchor"&&x.positioned_relative_to_pcb_group_id&&c(x.positioned_relative_to_pcb_group_id,_)},l=new Set;if(a.forEach(y=>{const _=s.find(x=>x.pcb_component_id===y);_&&(_.position_mode==="relative_to_group_anchor"&&_.positioned_relative_to_pcb_group_id&&c(_.positioned_relative_to_pcb_group_id,l),_.pcb_group_id&&c(_.pcb_group_id,l))}),!Pd(y=>y.is_showing_group_anchor_offsets)&&a.length===0)return null;const d=s.map(y=>{if(y.position_mode==="relative_to_group_anchor"&&y.positioned_relative_to_pcb_group_id){const _=o.find(x=>x.pcb_group_id===y.positioned_relative_to_pcb_group_id);return _&&_.anchor_position?{component:y,parentGroup:_,type:"component"}:null}if(y.pcb_group_id){const _=o.find(x=>x.pcb_group_id===y.pcb_group_id);return _&&_.anchor_position?{component:y,parentGroup:_,type:"component"}:null}return null}).filter(y=>!!y),h=o.map(y=>{if(y.position_mode==="relative_to_group_anchor"&&y.positioned_relative_to_pcb_group_id){const _=o.find(x=>x.pcb_group_id===y.positioned_relative_to_pcb_group_id);if(_&&_.anchor_position&&y.anchor_position)return{group:y,parentGroup:_,type:"group"}}return null}).filter(y=>!!y),f=[...d,...h];if(f.length===0)return null;const p=a.length===0,m=f.filter(y=>y.type==="component"?p||a.includes(y.component.pcb_component_id):p||l.has(y.group.pcb_group_id)||l.has(y.parentGroup.pcb_group_id));if(m.length===0)return null;const g=m.map(y=>{const _=y.parentGroup.anchor_position;return _?y.type==="component"?y.component.center?{id:`${y.parentGroup.pcb_group_id}-${y.component.pcb_component_id}-${y.type}`,anchor:_,anchor_id:y.parentGroup.pcb_group_id,target:y.component.center,type:"component",display_offset_x:y.component.display_offset_x,display_offset_y:y.component.display_offset_y}:null:y.group.anchor_position?{id:`${y.parentGroup.pcb_group_id}-${y.group.pcb_group_id}-${y.type}`,anchor:_,anchor_id:y.parentGroup.pcb_group_id,target:y.group.anchor_position,type:"group",display_offset_x:y.group.display_offset_x,display_offset_y:y.group.display_offset_y}:null:null}).filter(y=>!!y);return V.jsx(Wxe,{targets:g,transform:t,containerWidth:r,containerHeight:i})},EVn=(n,e)=>{const t=n.pcb_component_id,r=e.filter(i=>(i.type==="pcb_smtpad"||i.type==="pcb_plated_hole")&&i.pcb_component_id===t||i.type==="pcb_hole"&&i.pcb_component_id===t);return r.length===0?Yxe([n]):Yxe(r)},TVn=({elements:n,highlightedPrimitives:e,transform:t,containerWidth:r,containerHeight:i})=>{const o=new Map;for(const a of e)N8(a._parent_pcb_component)&&o.set(a._parent_pcb_component.pcb_component_id,a._parent_pcb_component),N8(a._element)&&o.set(a._element.pcb_component_id,a._element);if(o.size===0)return null;const s=[];for(const a of o.values()){const c=EVn(a,n);if(!c)continue;const l=a.positioned_relative_to_pcb_group_id??a.pcb_group_id,u=l?W9(n).pcb_group.get(l):null;s.push({component:a,bbox:c,group:u})}return s.length===0?null:V.jsx("div",{style:{position:"absolute",left:0,top:0,width:r,height:i,overflow:"hidden",pointerEvents:"none",zIndex:Kl.dimensionOverlay},children:V.jsx("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none"},width:r,height:i,children:s.map(({component:a,bbox:c,group:l})=>{const u=mt(t,{x:c.minX,y:c.maxY}),d=mt(t,{x:c.maxX,y:c.minY}),h={x:Math.min(u.x,d.x),y:Math.min(u.y,d.y),width:Math.abs(d.x-u.x),height:Math.abs(d.y-u.y)},f=a.center??{x:(c.minX+c.maxX)/2,y:(c.minY+c.maxY)/2},p=mt(t,f);return V.jsxs("g",{children:[V.jsx("rect",{x:h.x,y:h.y,width:h.width,height:h.height,fill:"none",stroke:"white",strokeWidth:1.5,strokeDasharray:"4,4"}),V.jsx("line",{x1:p.x-6,y1:p.y,x2:p.x+6,y2:p.y,stroke:Qx.COMPONENT_MARKER_STROKE,strokeWidth:1.5}),V.jsx("line",{x1:p.x,y1:p.y-6,x2:p.x,y2:p.y+6,stroke:Qx.COMPONENT_MARKER_STROKE,strokeWidth:1.5}),V.jsx("circle",{cx:p.x,cy:p.y,r:Pu.COMPONENT_MARKER_RADIUS,fill:Qx.COMPONENT_MARKER_FILL,stroke:Qx.COMPONENT_MARKER_STROKE,strokeWidth:1})]},a.pcb_component_id)})})})},CVn=({elements:n,highlightedPrimitives:e,transform:t,containerWidth:r,containerHeight:i})=>{const o=n.filter(f=>wVn(f)),s=n.filter(f=>qxe(f)),a=e.map(f=>qxe(f._element)?f._element.pcb_board_id:null).filter(f=>!!f);if(!Pd(f=>f.is_showing_group_anchor_offsets)&&a.length===0)return null;const l=s.map(f=>{const p=f.pcb_panel_id,m=f.position_mode;if(!p||m!=="relative_to_panel_anchor")return null;const g=o.find(y=>y.pcb_panel_id===p);return g?{board:f,panel:g,type:"board"}:null}).filter(f=>!!f);if(l.length===0)return null;const u=a.length===0,d=l.filter(f=>u||a.includes(f.board.pcb_board_id));if(d.length===0)return null;const h=d.map(f=>f.board.center?{id:`${f.panel.pcb_panel_id}-${f.board.pcb_board_id}-${f.type}`,anchor:f.panel.center,anchor_id:f.panel.pcb_panel_id,target:f.board.center,type:"board",display_offset_x:f.board.display_offset_x,display_offset_y:f.board.display_offset_y}:null).filter(f=>!!f);return V.jsx(Wxe,{targets:h,transform:t,containerWidth:r,containerHeight:i})},tq=n=>{if(n.length===0)return null;let e=n[0].x,t=n[0].y,r=n[0].x,i=n[0].y;for(const o of n)o.x<e&&(e=o.x),o.y<t&&(t=o.y),o.x>r&&(r=o.x),o.y>i&&(i=o.y);return{center:{x:(e+r)/2,y:(t+i)/2},width:r-e,height:i-t}},T0t=(n,e)=>{if(e.length<3)return!1;let t=!1;for(let r=0,i=e.length-1;r<e.length;i=r++){const o=e[r].x,s=e[r].y,a=e[i].x,c=e[i].y;s>n.y!=c>n.y&&n.x<(a-o)*(n.y-s)/(c-s||Number.EPSILON)+o&&(t=!t)}return t},PVn=(n,e,t)=>{const r=[];for(const i of n){if(!i._element)continue;if("x1"in i&&i._element?.type==="pcb_trace"){const a=Hm({x:e.x,y:e.y},{x:i.x1,y:i.y1},{x:i.x2,y:i.y2}),c=i.width||.5,l=Math.max(c*25,2)/t.a;a<l&&r.push(i);continue}if(i.pcb_drawing_type==="polygon"){const a=i.points.map(l=>({x:gn.parse(l.x),y:gn.parse(l.y)})),c=tq(a);if(!c||e.x<c.center.x-c.width/2||e.x>c.center.x+c.width/2||e.y<c.center.y-c.height/2||e.y>c.center.y+c.height/2)continue;T0t(e,a)&&r.push(i);continue}if(i.pcb_drawing_type==="polygon_with_arcs"){const a=i.brep_shape.outer_ring.vertices.map(l=>({x:gn.parse(l.x),y:gn.parse(l.y)})),c=tq(a);if(!c||e.x<c.center.x-c.width/2||e.x>c.center.x+c.width/2||e.y<c.center.y-c.height/2||e.y>c.center.y+c.height/2)continue;T0t(e,a)&&r.push(i);continue}if(!("x"in i&&"y"in i))continue;let o=0,s=0;if("w"in i&&"h"in i)o=i.w,s=i.h;else if("r"in i)o=i.r*2,s=i.r*2;else if("rX"in i&&"rY"in i)o=i.rX*2,s=i.rY*2;else continue;Math.abs(i.x-e.x)<o/2&&Math.abs(i.y-e.y)<s/2&&r.push(i)}return r},AVn=({elements:n,children:e,transform:t,primitives:r,onMouseHoverOverPrimitives:i})=>{const[o,s]=q.useState([]),[a,c]=q.useState({x:0,y:0}),[l,{width:u,height:d}]=BO(),h=q.useMemo(()=>{const p=[];for(const m of o){if(m._element?.type==="pcb_via"||m._element?.type==="pcb_component"||m?.layer==="drill"||m?.is_hoverable===!1)continue;let g=null,y=0,_=0;if(m.pcb_drawing_type==="polygon"){const S=tq(m.points);if(!S)continue;g=S.center,y=S.width,_=S.height}else if(m.pcb_drawing_type==="polygon_with_arcs"){const S=m.brep_shape.outer_ring.vertices.map(C=>({x:C.x,y:C.y})),E=tq(S);if(!E)continue;g=E.center,y=E.width,_=E.height}else"x"in m&&"y"in m&&(g={x:m.x,y:m.y},y="w"in m?m.w:"r"in m?m.r*2:"rX"in m&&"rY"in m?m.rX*2:0,_="h"in m?m.h:"r"in m?m.r*2:"rX"in m&&"rY"in m?m.rY*2:0);if(!g)continue;const x=mt(t,g),b={w:y*t.a,h:_*t.a},w=p.filter(S=>x.x===S.screen_x&&x.y===S.screen_y&&b.w===S.screen_w&&b.h===S.screen_h).length;p.push({...m,x:g.x,y:g.y,w:y,h:_,screen_x:x.x,screen_y:x.y,screen_w:b.w,screen_h:b.h,same_space_index:w})}return p},[o,t]),f=(p,m,g,y)=>{c({x:p,y:m});const _=mt(Y2(g),{x:p,y:m}),x=PVn(y,_,g);fVn(new Set(x.map(b=>b._pcb_drawing_object_id)),new Set(o.map(b=>b._pcb_drawing_object_id)))||(s(x),i(x))};return V.jsxs("div",{ref:l,style:{position:"relative",width:"100%",height:"100%"},onMouseMove:p=>{if(t){const m=p.currentTarget.getBoundingClientRect(),g=p.clientX-m.left,y=p.clientY-m.top;f(g,y,t,r)}},onTouchStart:p=>{if(t){const m=p.touches[0],g=p.currentTarget.getBoundingClientRect(),y=m.clientX-g.left,_=m.clientY-g.top;f(y,_,t,r)}},children:[e,V.jsx(vVn,{elements:n,mousePos:a,highlightedPrimitives:h}),t&&V.jsxs(V.Fragment,{children:[V.jsx(SVn,{elements:n,highlightedPrimitives:h,transform:t,containerWidth:u,containerHeight:d}),V.jsx(MVn,{elements:n,highlightedPrimitives:h,transform:t,containerWidth:u,containerHeight:d}),V.jsx(TVn,{elements:n,highlightedPrimitives:h,transform:t,containerWidth:u,containerHeight:d}),V.jsx(CVn,{elements:n,highlightedPrimitives:h,transform:t,containerWidth:u,containerHeight:d})]})]})},C0t=["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)"],RVn=({children:n,transform:e=Jc(),elements:t=[],hoveredComponentIds:r=[]})=>{const[i,{width:o,height:s}]=BO(),a=q.useRef(null),{is_showing_pcb_groups:c,pcb_group_view_mode:l,is_showing_group_anchor_offsets:u}=Pd(d=>({is_showing_pcb_groups:d.is_showing_pcb_groups,pcb_group_view_mode:d.pcb_group_view_mode,is_showing_group_anchor_offsets:d.is_showing_group_anchor_offsets}));return q.useEffect(()=>{const d=a.current;if(!d||!o||!s)return;d.width=o,d.height=s;const h=d.getContext("2d");if(!h||(h.clearRect(0,0,o,s),!c))return;const f=t.filter(S=>S.type==="pcb_group"),p=t.filter(S=>S.type==="pcb_component"),m=t.filter(S=>S.type==="source_group"),g=new Map(m.map(S=>[S.source_group_id,S])),y=f.filter(S=>{if(S.name?.toLowerCase().includes("subpanel"))return!1;if(l==="all")return!0;if(!S.source_group_id)return!1;const E=g.get(S.source_group_id);return E?E.was_automatically_named!==!0:!1}),_=new Map;m.forEach(S=>{const E=S;if(E.parent_source_group_id){const C=_.get(E.parent_source_group_id)||[];C.push(S.source_group_id),_.set(E.parent_source_group_id,C)}});const x=S=>{const E=[],C=_.get(S)||[];for(const A of C)E.push(A),E.push(...x(A));return E},b=S=>{const E=m.find(C=>C.source_group_id===S);return E?.parent_source_group_id?1+b(E.parent_source_group_id):0},w=new Set;if(r.length>0)for(const S of p){if(!r.includes(S.pcb_component_id))continue;const E=S.positioned_relative_to_pcb_group_id??S.pcb_group_id;E&&w.add(E)}y.forEach((S,E)=>{let C=p.filter(ke=>ke.pcb_group_id===S.pcb_group_id);if(S.source_group_id){const ke=x(S.source_group_id),je=f.filter(Re=>Re.source_group_id&&ke.includes(Re.source_group_id));for(const Re of je){const be=p.filter(Ce=>Ce.pcb_group_id===Re.pcb_group_id);C=[...C,...be]}}let A,R,L,O,F=!1;if(S.center&&S.width&&S.height){F=!0;const ke=S.width/2,je=S.height/2;A=S.center.x-ke,L=S.center.x+ke,R=S.center.y-je,O=S.center.y+je}else if(C.length===0||(A=1/0,R=1/0,L=-1/0,O=-1/0,C.forEach(ke=>{if(ke.center&&typeof ke.width=="number"&&typeof ke.height=="number"){const je=ke.center.x-ke.width/2,Re=ke.center.x+ke.width/2,be=ke.center.y+ke.height/2,Ce=ke.center.y-ke.height/2;A=Math.min(A,je),L=Math.max(L,Re),R=Math.min(R,Ce),O=Math.max(O,be)}}),A===1/0||L===-1/0))return;const B=S.source_group_id?b(S.source_group_id):0,j=S.source_group_id?x(S.source_group_id).length>0:!1;if(!F){const Re=1+(j?.5:0);A-=Re,L+=Re,R-=Re,O+=Re}const G=mt(e,{x:A,y:O}),W=mt(e,{x:L,y:O}),Q=mt(e,{x:A,y:R}),ne=mt(e,{x:L,y:R}),ue=C0t[E%C0t.length];h.strokeStyle=ue,h.lineWidth=2;const te=Math.max(4,Math.min(12,8*Math.abs(e.a))),re=Math.max(2,Math.min(6,4*Math.abs(e.a))),ce=te*(j?1.3:1),fe=re;h.setLineDash([ce,fe]),h.beginPath(),h.moveTo(G.x,G.y),h.lineTo(W.x,W.y),h.lineTo(ne.x,ne.y),h.lineTo(Q.x,Q.y),h.closePath(),h.stroke();const Me=Math.max(8,Math.min(12,10*Math.abs(e.a))),Pe=B==0||B==1?0:B*.11,Ne=Me*(1-Pe),me=4,Se=S.name||`Group ${E+1}`;h.font=`${Ne}px sans-serif`,h.setLineDash([]);const He=h.measureText(Se).width+me*2,Ye=Ne+me*2,We=G.x-5,ge=G.y-5,Ze=3;if(h.fillStyle="rgba(0, 0, 0, 0.8)",h.beginPath(),h.roundRect(We,ge-Ye,He,Ye,Ze),h.fill(),h.fillStyle=ue,h.textAlign="left",h.textBaseline="middle",h.fillText(Se,We+me,ge-Ye/2),u&&w.has(S.pcb_group_id)&&!!S.anchor_position&&S.anchor_position){const ke=Array.isArray(S.anchor_position)?{x:S.anchor_position[0]??0,y:S.anchor_position[1]??0}:{x:S.anchor_position.x,y:S.anchor_position.y},je=mt(e,ke);h.strokeStyle="white",h.lineWidth=1.5,h.setLineDash([]);const Re=Math.max(4,Math.min(8,6*Math.abs(e.a)));h.beginPath(),h.moveTo(je.x-Re,je.y),h.lineTo(je.x+Re,je.y),h.stroke(),h.beginPath(),h.moveTo(je.x,je.y-Re),h.lineTo(je.x,je.y+Re),h.stroke()}})},[t,e,o,s,c,l,u,r]),V.jsxs("div",{ref:i,style:{position:"relative",width:"100%",height:"100%"},children:[n,V.jsx("canvas",{ref:a,style:{position:"absolute",top:0,left:0,pointerEvents:"none",zIndex:Kl.pcbGroupOverlay,display:c?"block":"none"}})]})},NVn=({transform:n,soup:e,children:t})=>{const r=Pd(a=>a.is_showing_rats_nest),{netMap:i,idToNetMap:o}=q.useMemo(()=>i0t(e||[]),[e]),s=q.useMemo(()=>{if(!e||!r)return[];const a=h=>{const f=W9(e)[h.replace(/_\d+$/,"")].get(h);return f&&"x"in f&&"y"in f?{x:f.x,y:f.y}:null},c=(h,f)=>{const p=i[f]||[];let m=null,g=1/0;return p.forEach(y=>{const _=a(y);if(_){const x=Math.sqrt((h.x-_.x)**2+(h.y-_.y)**2);x<g&&x>0&&(g=x,m=_)}}),m},l=W9(e).pcb_port.list(),u=W9(e).source_trace.list(),d=[];return l.forEach((h,f)=>{const p=o[h.pcb_port_id];let m=!1;for(const _ of u)_.connected_source_port_ids.includes(h.source_port_id)&&_.connected_source_net_ids.length>0&&(m=!0);if(!p)return;const g={x:h.x,y:h.y},y=c(g,p);y&&d.push({key:`${h.pcb_port_id}-${f}`,startPoint:g,endPoint:y,isInNet:m})}),d},[e,i,o,r]);return!e||!r?t:(n||(n=Jc()),V.jsxs("div",{style:{position:"relative"},children:[t,V.jsx("svg",{style:{position:"absolute",left:0,top:0,width:"100%",height:"100%",pointerEvents:"none",opacity:.5,zIndex:Kl.ratsNestOverlay},children:s.map(({key:a,startPoint:c,endPoint:l,isInNet:u})=>{const d=mt(n,c),h=mt(n,l);return V.jsx("line",{x1:d.x,y1:d.y,x2:h.x,y2:h.y,stroke:"white",strokeWidth:"1",strokeDasharray:u?"6,6":void 0},a)})})]}))},IVn={version:"1.11.362"},I8=(n,e,t)=>{const r=Pd(s=>s.is_mouse_over_container),i=q.useRef(r),o=q.useRef(e);q.useEffect(()=>{i.current=r},[r]),q.useEffect(()=>{o.current=e},[e]),q.useEffect(()=>{if(!n)return;const s=a=>{const c=a.target;if(c.tagName==="INPUT"||c.tagName==="TEXTAREA"||c.isContentEditable)return;const l=n.split("+"),u=l.includes("ctrl"),d=l.includes("shift"),h=l.includes("alt"),f=l.includes("meta"),p=l[l.length-1],m=t?.current?t.current.contains(document.activeElement)||document.activeElement===t.current:!1;(i.current||m)&&(!u||a.ctrlKey)&&(!d||a.shiftKey)&&(!h||a.altKey)&&(!f||a.metaKey)&&a.key.toLowerCase()===p.toLowerCase()&&(a.preventDefault(),o.current())};return window.addEventListener("keydown",s),()=>{window.removeEventListener("keydown",s)}},[n])},kVn=()=>{const[n,e]=q.useState(!1);return q.useEffect(()=>{const t=()=>{e(window.innerWidth<=768)};return t(),window.addEventListener("resize",t),()=>window.removeEventListener("resize",t)},[]),n},UO=(n,e={stopPropagation:!0})=>{const t=q.useRef(0),r=q.useCallback(s=>{e.stopPropagation&&s.stopPropagation();const a=Date.now();a-t.current<300||(t.current=a,n?.(s))},[n,e.stopPropagation]),i=q.useCallback(s=>{s.preventDefault(),r(s)},[r]);return{onClick:r,onTouchEnd:i,style:{touchAction:"manipulation"}}},HS=({children:n,isSmallScreen:e,onClick:t,...r})=>{const{style:i,...o}=UO(t);return V.jsx("div",{...r,...o,style:{backgroundColor:"#1F1F1F",border:"1px solid #666",margin:0,padding:4,paddingLeft:e?8:6,paddingRight:e?8:6,borderRadius:2,color:"#eee",cursor:"pointer",fontSize:12,height:"fit-content",userSelect:"none",whiteSpace:"nowrap",...i,...r.style},children:n})},OVn=({errorId:n,errorMessage:e,copiedErrorId:t,onCopy:r})=>{const{style:i,...o}=UO(()=>r(e,n));return V.jsx("button",{type:"button","aria-label":t===n?"Error message copied":"Copy error message",style:{position:"absolute",top:12,right:16,cursor:"pointer",color:"#888",fontSize:16,background:"none",border:"none",padding:0,display:"flex",alignItems:"center",...i},...o,children:t===n?V.jsx("span",{style:{color:"#4caf50",fontSize:12},children:"Copied!"}):V.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"currentColor",children:V.jsx("path",{d:"M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 16H8V7h11v14z"})})})},LVn=({elements:n,isOpen:e,isSmallScreen:t,onToggle:r,setHoveredErrorId:i})=>{const[o,s]=q.useState(null),[a,c]=q.useState(new Set),[l,u]=q.useState(new Set),[,d]=kYn(),h=q.useMemo(()=>n?.filter(_=>_.type.includes("error"))??[],[n]),f=h.length,p=q.useCallback((_,x)=>_.pcb_trace_error_id||`error_${x}_${_.error_type}_${_.message?.slice(0,20)}`,[]),m=q.useMemo(()=>{const _=new Map;return h.forEach((x,b)=>{const w=x.error_type||"unknown_error",S=_.get(w)||[];S.push({error:x,index:b,errorId:p(x,b)}),_.set(w,S)}),Array.from(_.entries()).map(([x,b])=>({errorType:x,errors:b}))},[h,p]),g=q.useCallback(_=>{c(x=>{const b=new Set(x);return b.has(_)?b.delete(_):b.add(_),b})},[]),y=q.useCallback(_=>{u(x=>{const b=new Set(x);return b.has(_)?b.delete(_):b.add(_),b})},[]);return V.jsxs("div",{style:{position:"relative"},children:[V.jsx(HS,{isSmallScreen:t,style:f>0?{color:"red"}:void 0,onClick:r,children:V.jsxs("div",{children:[f," errors"]})}),e&&f>0&&V.jsx("div",{style:{position:"absolute",top:"100%",left:0,backgroundColor:"#2a2a2a",border:"1px solid #666",borderRadius:4,marginTop:4,zIndex:1e3,minWidth:t?"280px":"400px",maxWidth:t?"90vw":"600px",maxHeight:"400px",overflow:"auto",boxShadow:"0 4px 12px rgba(0, 0, 0, 0.3)"},children:m.map(({errorType:_,errors:x},b)=>{const w=a.has(_);return V.jsxs("div",{style:{borderBottom:b<m.length-1?"1px solid #444":"none"},children:[V.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"12px 16px",cursor:"pointer",backgroundColor:"#232323",transition:"background-color 0.2s ease",touchAction:"manipulation",position:"sticky",top:0,zIndex:1},onMouseEnter:S=>{S.currentTarget.style.backgroundColor="#303030"},onMouseLeave:S=>{S.currentTarget.style.backgroundColor="#232323"},onTouchStart:S=>{S.stopPropagation(),S.currentTarget.style.backgroundColor="#303030"},onTouchEnd:S=>{S.stopPropagation(),S.preventDefault(),S.currentTarget.style.backgroundColor="#232323",g(_)},onClick:S=>{S.stopPropagation(),g(_)},children:[V.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,color:"#ff6b6b"},children:[V.jsx("div",{style:{color:"#888",fontSize:"16px",transform:w?"rotate(90deg)":"rotate(0deg)",transition:"transform 0.2s ease",flexShrink:0},children:"›"}),V.jsx("div",{style:{fontWeight:"bold",fontSize:t?"12px":"13px"},children:_})]}),V.jsx("div",{style:{fontSize:t?"12px":"13px",color:"#aaa",whiteSpace:"nowrap",marginLeft:12},children:x.length})]}),!w&&x.map(({error:S,index:E,errorId:C})=>{const A=l.has(C),R=S.message??"No error message";return V.jsxs("div",{style:{borderTop:"1px solid #3a3a3a"},children:[V.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12,padding:"12px 16px 12px 24px",cursor:"pointer",backgroundColor:"#2a2a2a",transition:"background-color 0.2s ease",touchAction:"manipulation"},onMouseEnter:L=>{L.currentTarget.style.backgroundColor="#333",i(C)},onMouseLeave:L=>{L.currentTarget.style.backgroundColor="#2a2a2a",i(null)},onTouchStart:L=>{L.stopPropagation(),L.currentTarget.style.backgroundColor="#333",i(C)},onTouchEnd:L=>{L.stopPropagation(),L.preventDefault(),L.currentTarget.style.backgroundColor="#2a2a2a",i(null),y(C)},onClick:L=>{L.stopPropagation(),y(C)},children:[V.jsx("div",{style:{flex:1,fontSize:t?"12px":"13px",color:"#ddd",lineHeight:1.4,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",userSelect:"text"},onMouseDown:L=>L.stopPropagation(),onClick:L=>L.stopPropagation(),children:R}),V.jsx("div",{style:{color:"#888",fontSize:"16px",transform:A?"rotate(0deg)":"rotate(90deg)",transition:"transform 0.2s ease",flexShrink:0},children:"›"})]}),A&&V.jsxs("div",{"data-error-id":E,style:{display:"block",padding:"12px 16px 12px 24px",backgroundColor:"#1a1a1a",borderTop:"1px solid #444",position:"relative"},children:[V.jsx("div",{style:{fontSize:t?"11px":"12px",color:"#ccc",lineHeight:1.5,wordWrap:"break-word",overflowWrap:"break-word",hyphens:"auto",userSelect:"text",paddingRight:30},onMouseDown:L=>L.stopPropagation(),onClick:L=>L.stopPropagation(),children:R}),V.jsx(OVn,{errorId:C,errorMessage:R,copiedErrorId:o,onCopy:(L,O)=>{d(L),s(O),setTimeout(()=>s(null),2e3)}})]})]},C)})]},_)})})]})},DVn=({name:n,selected:e,onClick:t})=>{const{style:r,...i}=UO(t);return V.jsxs("div",{className:$P`
5462
5462
  margin-top: 2px;
5463
5463
  padding: 4px;
5464
5464
  padding-left: 8px;
@@ -5675,7 +5675,7 @@ test("${l} should solve problem correctly", () => {
5675
5675
  // Add more specific assertions based on expected output
5676
5676
  // expect(solver.netLabelPlacementSolver!.netLabelPlacements).toMatchInlineSnapshot()
5677
5677
  })
5678
- `,d=new Blob([u],{type:"text/plain"}),h=URL.createObjectURL(d),f=document.createElement("a");f.href=h,f.download=`${l}.test.ts`,f.click(),URL.revokeObjectURL(h)}catch(c){alert(`Error generating test.ts for ${n.constructor.name}: ${c instanceof Error?c.message:String(c)}`)}r(!1)};return V.jsxs("div",{className:`relative ${e}`,ref:i,children:[V.jsx("button",{className:"px-2 py-1 rounded text-xs cursor-pointer",onClick:()=>r(!t),title:`Download options for ${n.constructor.name}`,children:n.constructor.name}),t&&V.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:[V.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:o,children:"Download JSON"}),V.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:s,children:"Download page.tsx"}),V.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:a,children:"Download test.ts"})]})]})},z0t=n=>n.activeSubSolver?[n,...z0t(n.activeSubSolver)]:[n],mqn=({solver:n})=>{const e=z0t(n);return V.jsx("div",{className:"flex gap-1 items-center text-sm pt-1",children:e.map((t,r)=>V.jsxs("div",{className:"flex items-center",children:[r>0&&V.jsx("span",{className:"text-gray-400 mx-1",children:"→"}),V.jsx(fqn,{solver:t})]},t.constructor.name))})},yqn=({solver:n,triggerRender:e,animationSpeed:t=25,onSolverStarted:r,onSolverCompleted:i})=>{const[o,s]=q.useReducer(m=>!m,!1),a=q.useRef(void 0),c=()=>{!n.solved&&!n.failed&&(n.step(),e())},l=()=>{!n.solved&&!n.failed&&(r&&r(n),n.solve(),e(),i&&i(n))},u=()=>{o?(a.current&&(clearInterval(a.current),a.current=void 0),s()):(s(),a.current=setInterval(()=>{if(n.solved||n.failed){a.current&&(clearInterval(a.current),a.current=void 0),s(),e(),i&&n.solved&&i(n);return}n.step(),e()},t))},d=()=>{const m=n;if(m.getCurrentPhase&&!n.solved&&!n.failed){const g=m.getCurrentPhase();for(;m.getCurrentPhase()===g&&!n.solved&&!n.failed;)n.step();e()}},h=()=>{if(n.solved||n.failed||o)return;const m=window.prompt("Step until which iteration?",`${n.iterations}`);if(m===null)return;const g=Number(m);if(!Number.isFinite(g)){window.alert("Please enter a valid number for the iteration");return}for(;n.iterations<g&&!n.solved&&!n.failed;)n.step();e(),n.solved&&i&&i(n)};q.useEffect(()=>()=>{a.current&&clearInterval(a.current)},[]),q.useEffect(()=>{(n.solved||n.failed)&&o&&(a.current&&(clearInterval(a.current),a.current=void 0),s())},[n.solved,n.failed,o]);const f=n.getCurrentPhase!==void 0,p=f?n.getCurrentPhase():null;return V.jsxs("div",{className:"space-y-2 p-2 border-b",children:[V.jsx("div",{className:"flex items-center",children:V.jsx(mqn,{solver:n})}),V.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[V.jsx("button",{onClick:c,disabled:n.solved||n.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"}),V.jsx("button",{onClick:l,disabled:n.solved||n.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"}),V.jsx("button",{onClick:u,disabled:n.solved||n.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"}),V.jsx("button",{onClick:h,disabled:n.solved||n.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"}),f&&V.jsx("button",{onClick:d,disabled:n.solved||n.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"}),V.jsxs("div",{className:"text-sm text-gray-600",children:["Iterations: ",n.iterations]}),n.timeToSolve!==void 0&&V.jsxs("div",{className:"text-sm text-gray-600",children:["Time: ",(n.timeToSolve/1e3).toFixed(3),"s"]}),p&&V.jsxs("div",{className:"text-sm text-gray-600",children:["Phase: ",V.jsx("span",{className:"font-medium",children:p})]}),n.solved&&V.jsx("div",{className:"px-2 py-1 bg-green-100 text-green-800 rounded text-sm",children:"Solved"}),n.failed&&V.jsx("div",{className:"px-2 py-1 bg-red-100 text-red-800 rounded text-sm",children:"Failed"})]}),n.error&&V.jsxs("div",{className:"text-red-600 text-sm",children:["Error: ",n.error]})]})},gqn=(n,e,t)=>{const r=n.currentPipelineStepIndex;return e<r?"Completed":e===r&&n.activeSubSolver?n.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},_qn=(n,e)=>{const r=n.pipelineDef[e].solverName,i=gqn(n,e),o=n[r],s=n.firstIterationOfPhase?.[r]??null,a=n.iterations;let c=0;if(i==="Completed"){const h=n.pipelineDef[e+1],f=h?n.firstIterationOfPhase?.[h.solverName]:void 0;f!==void 0&&s!==null?c=f-s:s!==null&&(c=a-s)}else i==="In Progress"&&s!==null&&(c=a-s);const l=n.timeSpentOnPhase?.[r]??0;let u=0;i==="Completed"?u=1:i==="In Progress"&&o&&(u=o.progress??0);const d=o?.stats??null;return{index:e,name:r,status:i,firstIteration:s,iterations:c,progress:u,timeSpent:l,stats:d&&Object.keys(d).length>0?d:null,solverInstance:o??null}},xqn=({status:n})=>{const e={"Not Started":"text-blue-600","In Progress":"text-yellow-600",Completed:"text-green-600",Failed:"text-red-600"};return V.jsx("span",{className:`font-medium ${e[n]}`,children:n})},bqn=({progress:n})=>{if(n===0)return null;const e=Math.round(n*100);return V.jsxs("div",{className:"flex items-center gap-2",children:[V.jsx("div",{className:"w-20 h-2 bg-gray-200 rounded overflow-hidden",children:V.jsx("div",{className:"h-full bg-blue-500 transition-all duration-200",style:{width:`${e}%`}})}),V.jsxs("span",{className:"text-xs text-gray-500",children:[e,"%"]})]})},vqn=n=>Object.entries(n).map(([e,t])=>`${e}: ${t}`).join(", "),wqn=({stats:n})=>{if(!n||Object.keys(n).length===0)return V.jsx("span",{children:"-"});const e=Object.entries(n),t=vqn(n);return V.jsxs("details",{className:"cursor-pointer",children:[V.jsx("summary",{className:"whitespace-nowrap overflow-hidden text-ellipsis max-w-[200px]",children:t}),V.jsx("div",{className:"mt-1 text-xs",children:e.map(([r,i])=>V.jsxs("div",{children:[r,": ",String(i)]},r))})]})},r2e=n=>{if(n===null||typeof n!="object")return n;if(Array.isArray(n))return n.map(r2e);const e={};for(const[t,r]of Object.entries(n))t.startsWith("_")||(e[t]=r2e(r));return e},Sqn=(n,e)=>{try{if(typeof n.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${e}`);return}const t=r2e(n.getConstructorParams()),r=new Blob([JSON.stringify(t,null,2)],{type:"application/json"}),i=URL.createObjectURL(r),o=document.createElement("a");o.href=i,o.download=`${e}_input.json`,o.click(),URL.revokeObjectURL(i)}catch(t){alert(`Error downloading input for ${e}: ${t instanceof Error?t.message:String(t)}`)}},Mqn=({solver:n,onStepUntilPhase:e,onDownloadInput:t})=>{const r=n.pipelineDef.map((a,c)=>_qn(n,c)),i=a=>{e?.(a)},o=a=>{a.solverInstance&&(t?t(a.solverInstance,a.name):Sqn(a.solverInstance,a.name))},s=a=>`${(a/1e3).toFixed(2)}s`;return V.jsxs("div",{className:"border-t border-gray-200",children:[V.jsx("div",{className:"px-4 py-2 bg-gray-50 border-b border-gray-200",children:V.jsx("h3",{className:"text-sm font-semibold text-gray-700",children:"Pipeline Steps"})}),V.jsx("div",{className:"overflow-x-auto",children:V.jsxs("table",{className:"w-full text-sm",children:[V.jsx("thead",{children:V.jsxs("tr",{className:"bg-gray-50 border-b border-gray-200",children:[V.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Step"}),V.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Status"}),V.jsxs("th",{className:"px-4 py-2 text-center font-semibold text-gray-700",children:["i",V.jsx("sub",{children:"0"})]}),V.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Iterations"}),V.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Progress"}),V.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Time"}),V.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stats"}),V.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Input"})]})}),V.jsx("tbody",{children:r.map(a=>V.jsxs("tr",{className:`border-b border-gray-100 ${a.status==="In Progress"?"bg-yellow-50":""}`,children:[V.jsx("td",{className:"px-4 py-2",children:V.jsxs("div",{className:"flex items-center gap-2",children:[V.jsx("span",{className:"text-gray-400 w-6",children:String(a.index+1).padStart(2,"0")}),V.jsx("button",{onClick:()=>i(a.name),disabled:a.status==="Completed"||n.solved||n.failed,className:"text-blue-500 hover:text-blue-700 disabled:text-gray-300 disabled:cursor-not-allowed",title:`Step until ${a.name} completes`,children:V.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:V.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"})})}),V.jsx("span",{className:"font-medium text-gray-900",children:a.name})]})}),V.jsx("td",{className:"px-4 py-2",children:V.jsx(xqn,{status:a.status})}),V.jsx("td",{className:"px-4 py-2 text-center text-gray-600",children:a.firstIteration!==null?a.firstIteration:""}),V.jsx("td",{className:"px-4 py-2 text-gray-600",children:a.iterations}),V.jsx("td",{className:"px-4 py-2",children:V.jsx(bqn,{progress:a.progress})}),V.jsx("td",{className:"px-4 py-2 text-gray-600",children:s(a.timeSpent)}),V.jsx("td",{className:"px-4 py-2 text-gray-500",children:V.jsx(wqn,{stats:a.stats})}),V.jsx("td",{className:"px-4 py-2",children:a.solverInstance?V.jsxs("button",{onClick:()=>o(a),className:"flex items-center gap-1 text-blue-500 hover:text-blue-700",title:`Download input for ${a.name}`,children:[V.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:V.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"})}),V.jsx("span",{children:"Input"})]}):null})]},a.name))})]})})]})},Eqn=class extends si.Component{constructor(n){super(n),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(n){console.error("InteractiveGraphics render error:",n)}render(){return this.state.hasError?this.props.fallback:this.props.children}};function Tqn({graphics:n}){const e=n.points??[],t=n.lines??[],r=n.rects??[],i=n.circles??[],o=n.texts??[];let s=Number.POSITIVE_INFINITY,a=Number.POSITIVE_INFINITY,c=Number.NEGATIVE_INFINITY,l=Number.NEGATIVE_INFINITY;const u=(g,y)=>{typeof g=="number"&&(g<s&&(s=g),g>c&&(c=g)),typeof y=="number"&&(y<a&&(a=y),y>l&&(l=y))};for(const g of e)u(g.x,g.y);for(const g of t){const y=g.points??[];for(const _ of y)u(_.x,_.y)}for(const g of r){const y=g.x??0,_=g.y??0,x=g.width??0,b=g.height??0;u(y,_),u(y+x,_+b)}for(const g of i){const y=g.x??0,_=g.y??0,x=g.radius??1;u(y-x,_-x),u(y+x,_+x)}for(const g of o)u(g.x,g.y);(!isFinite(s)||!isFinite(a)||!isFinite(c)||!isFinite(l))&&(s=-20,a=-20,c=20,l=20);const d=10,h=s-d,f=a-d,p=Math.max(1,c-s+2*d),m=Math.max(1,l-a+2*d);return V.jsxs("svg",{className:"w-full h-[400px] bg-white",viewBox:`${h} ${f} ${p} ${m}`,role:"img","aria-label":"Graphics fallback",children:[r.map((g,y)=>V.jsx("rect",{x:g.x??0,y:g.y??0,width:g.width??0,height:g.height??0,fill:"none",stroke:g.strokeColor??"black",strokeWidth:g.strokeWidth??1},`rect-${y}`)),t.map((g,y)=>V.jsx("polyline",{fill:"none",stroke:g.strokeColor??"black",strokeWidth:g.strokeWidth??1,points:(g.points??[]).map(_=>`${_.x??0},${_.y??0}`).join(" ")},`line-${y}`)),i.map((g,y)=>V.jsx("circle",{cx:g.x??0,cy:g.y??0,r:g.radius??1.5,fill:g.fillColor??"none",stroke:g.strokeColor??"black",strokeWidth:g.strokeWidth??1},`circle-${y}`)),e.map((g,y)=>V.jsx("circle",{cx:g.x??0,cy:g.y??0,r:g.radius??1.5,fill:g.color??"black"},`point-${y}`)),o.map((g,y)=>V.jsx("text",{x:g.x??0,y:g.y??0,fontSize:g.fontSize??10,fill:g.color??"black",children:g.text??""},`text-${y}`))]})}var Cqn=({solver:n,animationSpeed:e=25,onSolverStarted:t,onSolverCompleted:r})=>{const[i,o]=q.useReducer(u=>u+1,0),s=q.useMemo(()=>{try{return n.visualize()||{points:[],lines:[],rects:[],circles:[]}}catch(u){return console.error("Visualization error:",u),{points:[],lines:[],rects:[],circles:[]}}},[n,i]),a=q.useMemo(()=>(s.rects?.length||0)===0&&(s.lines?.length||0)===0&&(s.points?.length||0)===0&&(s.circles?.length||0)===0,[s]);q.useEffect(()=>{if(!(typeof document>"u")&&!document.querySelector('script[src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"]')){const u=document.createElement("script");u.src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4",document.head.appendChild(u)}},[]);const c=n.pipelineDef!==void 0,l=u=>{const d=n;if(!n.solved&&!n.failed){for(;!n.solved&&!n.failed&&d.currentPipelineStepIndex<=d.pipelineDef.findIndex(h=>h.solverName===u);)n.step();o()}};return V.jsxs("div",{children:[V.jsx(yqn,{solver:n,triggerRender:o,animationSpeed:e,onSolverStarted:t,onSolverCompleted:r}),a?V.jsx("div",{className:"p-4 text-gray-500",children:"No Graphics Yet"}):V.jsx(Eqn,{fallback:V.jsx(Tqn,{graphics:s}),children:V.jsx(pqn,{graphics:s})}),c&&V.jsx(Mqn,{solver:n,onStepUntilPhase:l})]})};const Pqn=()=>{q.useEffect(()=>{const n="tailwind-cdn-script";if(document.getElementById(n)||window.tailwind)return;const e=document.createElement("div");e.className="hidden",document.body.appendChild(e);const t=window.getComputedStyle(e).display==="none";if(document.body.removeChild(e),t)return;const r=document.createElement("script");r.id=n,r.src="https://cdn.tailwindcss.com",document.head.appendChild(r)},[])},Aqn=n=>n.toLowerCase().includes("pack")?iPn:n.toLowerCase().includes("rout")?lPn:HCn,Rqn=({solverEvents:n=[]})=>{const[e,t]=q.useState(null);Pqn();const r=q.useMemo(()=>{const a=new Map;for(const c of n){const l=`${c.componentName}-${c.solverName}`;a.set(l,c)}return a},[n]),i=q.useMemo(()=>Array.from(r.keys()),[r]),o=e?r.get(e):null,s=q.useMemo(()=>{if(!o)return{instance:null,error:null,classFound:!1};const a=moe[o.solverName];if(!a)return{instance:null,error:`Solver class "${o.solverName}" not found in SOLVERS registry. Available: ${Object.keys(moe).join(", ")}`,classFound:!1};try{const c=o.solverParams,l=c?.input!==void 0?c.input:c;return{instance:new a(l),error:null,classFound:!0}}catch(c){const l=c instanceof Error?c.message:String(c);return console.error("Failed to reconstruct solver:",c),{instance:null,error:`Failed to instantiate solver: ${l}`,classFound:!0}}},[o]);return n.length===0?V.jsx("div",{className:"rf-p-4",children:V.jsx("div",{className:"rf-bg-gray-50 rf-rounded-md rf-border rf-border-gray-200",children:V.jsxs("div",{className:"rf-p-4",children:[V.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800 rf-mb-3",children:"No Solvers Detected"}),V.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."})]})})}):V.jsxs("div",{className:"rf-flex rf-h-full rf-overflow-hidden",children:[V.jsxs("div",{className:"rf-w-64 rf-border-r rf-border-gray-200 rf-overflow-y-auto rf-flex-shrink-0",children:[V.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:[i.length," ",i.length===1?"Solver":"Solvers"]}),i.map(a=>{const c=r.get(a),l=e===a;return V.jsx("div",{className:`rf-px-3 rf-py-2 rf-cursor-pointer rf-border-b rf-border-gray-100 ${l?"rf-bg-blue-50 rf-border-l-2 rf-border-l-blue-500":"hover:rf-bg-gray-50"}`,onClick:()=>t(a),children:(()=>{const u=Aqn(c.solverName);return V.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[V.jsx(u,{className:"rf-w-4 rf-h-4 rf-text-blue-500 rf-flex-shrink-0"}),V.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[V.jsx("div",{className:"rf-text-sm rf-font-medium rf-text-gray-800 rf-truncate",children:c.componentName}),V.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate",children:c.solverName})]})]})})()},a)})]}),V.jsx("div",{className:"rf-flex-1 rf-overflow-hidden",children:o?s.instance?V.jsx(m5,{fallback:V.jsx("div",{className:"rf-p-4",children:V.jsxs("div",{className:"rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200 rf-p-4",children:[V.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-2",children:"Error Loading Solver Debugger"}),V.jsxs("p",{className:"rf-text-sm rf-text-red-600",children:["Failed to render the solver debugger for"," ",o.solverName]})]})}),children:V.jsx(Cqn,{solver:s.instance})}):V.jsxs("div",{className:"rf-p-4",children:[V.jsxs("div",{className:"rf-mb-4",children:[V.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800",children:o.solverName}),V.jsxs("p",{className:"rf-text-sm rf-text-gray-500",children:["Component: ",o.componentName]})]}),s.error&&V.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:V.jsx("p",{className:`rf-text-sm ${s.classFound?"rf-text-red-700":"rf-text-yellow-700"}`,children:s.error})}),V.jsxs("div",{className:"rf-border rf-border-gray-200 rf-rounded-md rf-overflow-hidden",children:[V.jsx("div",{className:"rf-px-3 rf-py-2 rf-bg-gray-50",children:V.jsx("span",{className:"rf-text-sm rf-font-medium rf-text-gray-700",children:"Solver Parameters"})}),V.jsx("div",{className:"rf-p-3 rf-bg-white rf-border-t rf-border-gray-200",children:V.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)})})]})]}):V.jsx("div",{className:"rf-flex rf-items-center rf-justify-center rf-h-full",children:V.jsx("p",{className:"rf-text-sm rf-text-gray-500",children:"Select a solver from the list to view details"})})})]})},$0t=({errorMessage:n,errorStack:e,circuitJsonErrors:t})=>{q.useEffect(()=>{if(n){const r=new Error(n);e&&(r.stack=e);try{fH.captureException(r)}catch{}}},[n,e]),q.useEffect(()=>{if(t&&t.length>0)for(const r of t){const i=new Error(r.message||"Circuit JSON Error");r.stack&&(i.stack=r.stack);try{fH.captureException(i,{error_type:r.type})}catch{}}},[t])},F0t="0.0.1802",Nqn={version:F0t},sq=KOe()(QOe(n=>({lastRunEvalVersion:void 0,setLastRunEvalVersion:e=>{n({lastRunEvalVersion:e})}}),{name:"runframe-runner-store"})),Iqn=n=>{const[e,t]=q.useState([]),[r,i]=q.useState(null),[o,s]=q.useState(""),[a,c]=vT("eval-version-selection",null),l=sq(f=>f.setLastRunEvalVersion),u=sq(f=>f.lastRunEvalVersion);return q.useEffect(()=>{n&&fetch("https://data.jsdelivr.com/v1/package/npm/@tscircuit/eval").then(f=>f.json()).then(f=>{if(Array.isArray(f?.versions)){let p=[...f.versions];f.tags?.latest&&(i(f.tags.latest),p=p.filter(m=>m!==f.tags.latest)),t(p)}}).catch(()=>{})},[n]),q.useEffect(()=>{n&&(a?(window.TSCIRCUIT_LATEST_EVAL_VERSION=a,l(a)):r&&(window.TSCIRCUIT_LATEST_EVAL_VERSION=r,l(r)))},[n,a,r]),{versions:q.useMemo(()=>e.filter(f=>f.includes(o)).slice(0,50),[e,o]),latestVersion:r,lastRunEvalVersion:u,search:o,setSearch:s,selectVersion:f=>{c(f),s("")}}},kqn=({snippetNames:n,onSelect:e,onCancel:t,isOpen:r})=>{const[i,o]=q.useState(""),[s,a]=q.useState("");if(!r)return null;const c=n.filter(d=>d.toLowerCase().includes(s.toLowerCase())),l=s&&!n.includes(s),u=d=>{d.key==="Enter"&&(c.length===1?o(c[0]):l&&o(s))};return V.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:V.jsxs("div",{className:"rf-bg-white rf-rounded-lg rf-p-6 rf-w-96",children:[V.jsx("h2",{className:"rf-text-lg rf-font-semibold rf-mb-4",children:"Select Snippet"}),V.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:d=>a(d.target.value),onKeyDown:u}),V.jsxs("div",{className:"rf-h-60 rf-overflow-y-auto",children:[c.map(d=>V.jsx("button",{type:"button",className:`w-full text-left px-4 py-2 rounded hover:bg-gray-100 ${i===d?"bg-blue-50":""}`,onClick:()=>o(d),children:d},d)),l&&V.jsxs("button",{type:"button",className:`w-full text-left px-4 py-2 rounded hover:bg-gray-100 text-blue-500 ${i===s?"bg-blue-50":""}`,onClick:()=>o(s),children:['Create new "',s,'"']})]}),V.jsxs("div",{className:"rf-mt-4 rf-flex rf-justify-end rf-gap-2",children:[V.jsx("button",{type:"button",className:"rf-px-4 rf-py-2 rf-text-gray-600 rf-hover:text-gray-800",onClick:t,children:"Cancel"}),V.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:()=>i&&e(i),disabled:!i,children:i===s?`Create "${i}"`:`Save to ${i}`})]})]})})},Oqn=n=>{const e=q.useRef(null),t=Ju(r=>r.recentEvents);q.useEffect(()=>{if(t.length===0)return;const r=t[0];r.event_id!==e.current&&(n(r),e.current=r.event_id)},[t,n])};function Lqn(n){const e=Dqn(n),t=q.forwardRef((r,i)=>{const{children:o,...s}=r,a=q.Children.toArray(o),c=a.find($qn);if(c){const l=c.props.children,u=a.map(d=>d===c?q.Children.count(l)>1?q.Children.only(null):q.isValidElement(l)?l.props.children:null:d);return V.jsx(e,{...s,ref:i,children:q.isValidElement(l)?q.cloneElement(l,void 0,u):null})}return V.jsx(e,{...s,ref:i,children:o})});return t.displayName=`${n}.Slot`,t}function Dqn(n){const e=q.forwardRef((t,r)=>{const{children:i,...o}=t;if(q.isValidElement(i)){const s=Bqn(i),a=Fqn(o,i.props);return i.type!==q.Fragment&&(a.ref=r?E_(r,s):s),q.cloneElement(i,a)}return q.Children.count(i)>1?q.Children.only(null):null});return e.displayName=`${n}.SlotClone`,e}var zqn=Symbol("radix.slottable");function $qn(n){return q.isValidElement(n)&&typeof n.type=="function"&&"__radixId"in n.type&&n.type.__radixId===zqn}function Fqn(n,e){const t={...e};for(const r in e){const i=n[r],o=e[r];/^on[A-Z]/.test(r)?i&&o?t[r]=(...a)=>{const c=o(...a);return i(...a),c}:i&&(t[r]=i):r==="style"?t[r]={...i,...o}:r==="className"&&(t[r]=[i,o].filter(Boolean).join(" "))}return{...n,...t}}function Bqn(n){let e=Object.getOwnPropertyDescriptor(n.props,"ref")?.get,t=e&&"isReactWarning"in e&&e.isReactWarning;return t?n.ref:(e=Object.getOwnPropertyDescriptor(n,"ref")?.get,t=e&&"isReactWarning"in e&&e.isReactWarning,t?n.props.ref:n.props.ref||n.ref)}var aq="Dialog",[B0t,j0t]=r4(aq),[jqn,R4]=B0t(aq),U0t=n=>{const{__scopeDialog:e,children:t,open:r,defaultOpen:i,onOpenChange:o,modal:s=!0}=n,a=q.useRef(null),c=q.useRef(null),[l,u]=M3({prop:r,defaultProp:i??!1,onChange:o,caller:aq});return V.jsx(jqn,{scope:e,triggerRef:a,contentRef:c,contentId:Wm(),titleId:Wm(),descriptionId:Wm(),open:l,onOpenChange:u,onOpenToggle:q.useCallback(()=>u(d=>!d),[u]),modal:s,children:t})};U0t.displayName=aq;var H0t="DialogTrigger",Y0t=q.forwardRef((n,e)=>{const{__scopeDialog:t,...r}=n,i=R4(H0t,t),o=ed(e,i.triggerRef);return V.jsx(Mc.button,{type:"button","aria-haspopup":"dialog","aria-expanded":i.open,"aria-controls":i.contentId,"data-state":s2e(i.open),...r,ref:o,onClick:Bi(n.onClick,i.onOpenToggle)})});Y0t.displayName=H0t;var i2e="DialogPortal",[Uqn,X0t]=B0t(i2e,{forceMount:void 0}),V0t=n=>{const{__scopeDialog:e,forceMount:t,children:r,container:i}=n,o=R4(i2e,e);return V.jsx(Uqn,{scope:e,forceMount:t,children:q.Children.map(r,s=>V.jsx(Nx,{present:t||o.open,children:V.jsx(wV,{asChild:!0,container:i,children:s})}))})};V0t.displayName=i2e;var cq="DialogOverlay",G0t=q.forwardRef((n,e)=>{const t=X0t(cq,n.__scopeDialog),{forceMount:r=t.forceMount,...i}=n,o=R4(cq,n.__scopeDialog);return o.modal?V.jsx(Nx,{present:r||o.open,children:V.jsx(Yqn,{...i,ref:e})}):null});G0t.displayName=cq;var Hqn=Lqn("DialogOverlay.RemoveScroll"),Yqn=q.forwardRef((n,e)=>{const{__scopeDialog:t,...r}=n,i=R4(cq,t);return V.jsx(RV,{as:Hqn,allowPinchZoom:!0,shards:[i.contentRef],children:V.jsx(Mc.div,{"data-state":s2e(i.open),...r,ref:e,style:{pointerEvents:"auto",...r.style}})})}),VS="DialogContent",q0t=q.forwardRef((n,e)=>{const t=X0t(VS,n.__scopeDialog),{forceMount:r=t.forceMount,...i}=n,o=R4(VS,n.__scopeDialog);return V.jsx(Nx,{present:r||o.open,children:o.modal?V.jsx(Xqn,{...i,ref:e}):V.jsx(Vqn,{...i,ref:e})})});q0t.displayName=VS;var Xqn=q.forwardRef((n,e)=>{const t=R4(VS,n.__scopeDialog),r=q.useRef(null),i=ed(e,t.contentRef,r);return q.useEffect(()=>{const o=r.current;if(o)return wge(o)},[]),V.jsx(W0t,{...n,ref:i,trapFocus:t.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:Bi(n.onCloseAutoFocus,o=>{o.preventDefault(),t.triggerRef.current?.focus()}),onPointerDownOutside:Bi(n.onPointerDownOutside,o=>{const s=o.detail.originalEvent,a=s.button===0&&s.ctrlKey===!0;(s.button===2||a)&&o.preventDefault()}),onFocusOutside:Bi(n.onFocusOutside,o=>o.preventDefault())})}),Vqn=q.forwardRef((n,e)=>{const t=R4(VS,n.__scopeDialog),r=q.useRef(!1),i=q.useRef(!1);return V.jsx(W0t,{...n,ref:e,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:o=>{n.onCloseAutoFocus?.(o),o.defaultPrevented||(r.current||t.triggerRef.current?.focus(),o.preventDefault()),r.current=!1,i.current=!1},onInteractOutside:o=>{n.onInteractOutside?.(o),o.defaultPrevented||(r.current=!0,o.detail.originalEvent.type==="pointerdown"&&(i.current=!0));const s=o.target;t.triggerRef.current?.contains(s)&&o.preventDefault(),o.detail.originalEvent.type==="focusin"&&i.current&&o.preventDefault()}})}),W0t=q.forwardRef((n,e)=>{const{__scopeDialog:t,trapFocus:r,onOpenAutoFocus:i,onCloseAutoFocus:o,...s}=n,a=R4(VS,t),c=q.useRef(null),l=ed(e,c);return rge(),V.jsxs(V.Fragment,{children:[V.jsx(lV,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:i,onUnmountAutoFocus:o,children:V.jsx($k,{role:"dialog",id:a.contentId,"aria-describedby":a.descriptionId,"aria-labelledby":a.titleId,"data-state":s2e(a.open),...s,ref:l,onDismiss:()=>a.onOpenChange(!1)})}),V.jsxs(V.Fragment,{children:[V.jsx(qqn,{titleId:a.titleId}),V.jsx(Zqn,{contentRef:c,descriptionId:a.descriptionId})]})]})}),o2e="DialogTitle",Z0t=q.forwardRef((n,e)=>{const{__scopeDialog:t,...r}=n,i=R4(o2e,t);return V.jsx(Mc.h2,{id:i.titleId,...r,ref:e})});Z0t.displayName=o2e;var K0t="DialogDescription",Q0t=q.forwardRef((n,e)=>{const{__scopeDialog:t,...r}=n,i=R4(K0t,t);return V.jsx(Mc.p,{id:i.descriptionId,...r,ref:e})});Q0t.displayName=K0t;var J0t="DialogClose",eht=q.forwardRef((n,e)=>{const{__scopeDialog:t,...r}=n,i=R4(J0t,t);return V.jsx(Mc.button,{type:"button",...r,ref:e,onClick:Bi(n.onClick,()=>i.onOpenChange(!1))})});eht.displayName=J0t;function s2e(n){return n?"open":"closed"}var tht="DialogTitleWarning",[Gqn,nht]=cQt(tht,{contentName:VS,titleName:o2e,docsSlug:"dialog"}),qqn=({titleId:n})=>{const e=nht(tht),t=`\`${e.contentName}\` requires a \`${e.titleName}\` for the component to be accessible for screen reader users.
5678
+ `,d=new Blob([u],{type:"text/plain"}),h=URL.createObjectURL(d),f=document.createElement("a");f.href=h,f.download=`${l}.test.ts`,f.click(),URL.revokeObjectURL(h)}catch(c){alert(`Error generating test.ts for ${n.constructor.name}: ${c instanceof Error?c.message:String(c)}`)}r(!1)};return V.jsxs("div",{className:`relative ${e}`,ref:i,children:[V.jsx("button",{className:"px-2 py-1 rounded text-xs cursor-pointer",onClick:()=>r(!t),title:`Download options for ${n.constructor.name}`,children:n.constructor.name}),t&&V.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:[V.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:o,children:"Download JSON"}),V.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:s,children:"Download page.tsx"}),V.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:a,children:"Download test.ts"})]})]})},z0t=n=>n.activeSubSolver?[n,...z0t(n.activeSubSolver)]:[n],mqn=({solver:n})=>{const e=z0t(n);return V.jsx("div",{className:"flex gap-1 items-center text-sm pt-1",children:e.map((t,r)=>V.jsxs("div",{className:"flex items-center",children:[r>0&&V.jsx("span",{className:"text-gray-400 mx-1",children:"→"}),V.jsx(fqn,{solver:t})]},t.constructor.name))})},yqn=({solver:n,triggerRender:e,animationSpeed:t=25,onSolverStarted:r,onSolverCompleted:i})=>{const[o,s]=q.useReducer(m=>!m,!1),a=q.useRef(void 0),c=()=>{!n.solved&&!n.failed&&(n.step(),e())},l=()=>{!n.solved&&!n.failed&&(r&&r(n),n.solve(),e(),i&&i(n))},u=()=>{o?(a.current&&(clearInterval(a.current),a.current=void 0),s()):(s(),a.current=setInterval(()=>{if(n.solved||n.failed){a.current&&(clearInterval(a.current),a.current=void 0),s(),e(),i&&n.solved&&i(n);return}n.step(),e()},t))},d=()=>{const m=n;if(m.getCurrentPhase&&!n.solved&&!n.failed){const g=m.getCurrentPhase();for(;m.getCurrentPhase()===g&&!n.solved&&!n.failed;)n.step();e()}},h=()=>{if(n.solved||n.failed||o)return;const m=window.prompt("Step until which iteration?",`${n.iterations}`);if(m===null)return;const g=Number(m);if(!Number.isFinite(g)){window.alert("Please enter a valid number for the iteration");return}for(;n.iterations<g&&!n.solved&&!n.failed;)n.step();e(),n.solved&&i&&i(n)};q.useEffect(()=>()=>{a.current&&clearInterval(a.current)},[]),q.useEffect(()=>{(n.solved||n.failed)&&o&&(a.current&&(clearInterval(a.current),a.current=void 0),s())},[n.solved,n.failed,o]);const f=n.getCurrentPhase!==void 0,p=f?n.getCurrentPhase():null;return V.jsxs("div",{className:"space-y-2 p-2 border-b",children:[V.jsx("div",{className:"flex items-center",children:V.jsx(mqn,{solver:n})}),V.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[V.jsx("button",{onClick:c,disabled:n.solved||n.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"}),V.jsx("button",{onClick:l,disabled:n.solved||n.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"}),V.jsx("button",{onClick:u,disabled:n.solved||n.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"}),V.jsx("button",{onClick:h,disabled:n.solved||n.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"}),f&&V.jsx("button",{onClick:d,disabled:n.solved||n.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"}),V.jsxs("div",{className:"text-sm text-gray-600",children:["Iterations: ",n.iterations]}),n.timeToSolve!==void 0&&V.jsxs("div",{className:"text-sm text-gray-600",children:["Time: ",(n.timeToSolve/1e3).toFixed(3),"s"]}),p&&V.jsxs("div",{className:"text-sm text-gray-600",children:["Phase: ",V.jsx("span",{className:"font-medium",children:p})]}),n.solved&&V.jsx("div",{className:"px-2 py-1 bg-green-100 text-green-800 rounded text-sm",children:"Solved"}),n.failed&&V.jsx("div",{className:"px-2 py-1 bg-red-100 text-red-800 rounded text-sm",children:"Failed"})]}),n.error&&V.jsxs("div",{className:"text-red-600 text-sm",children:["Error: ",n.error]})]})},gqn=(n,e,t)=>{const r=n.currentPipelineStepIndex;return e<r?"Completed":e===r&&n.activeSubSolver?n.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},_qn=(n,e)=>{const r=n.pipelineDef[e].solverName,i=gqn(n,e),o=n[r],s=n.firstIterationOfPhase?.[r]??null,a=n.iterations;let c=0;if(i==="Completed"){const h=n.pipelineDef[e+1],f=h?n.firstIterationOfPhase?.[h.solverName]:void 0;f!==void 0&&s!==null?c=f-s:s!==null&&(c=a-s)}else i==="In Progress"&&s!==null&&(c=a-s);const l=n.timeSpentOnPhase?.[r]??0;let u=0;i==="Completed"?u=1:i==="In Progress"&&o&&(u=o.progress??0);const d=o?.stats??null;return{index:e,name:r,status:i,firstIteration:s,iterations:c,progress:u,timeSpent:l,stats:d&&Object.keys(d).length>0?d:null,solverInstance:o??null}},xqn=({status:n})=>{const e={"Not Started":"text-blue-600","In Progress":"text-yellow-600",Completed:"text-green-600",Failed:"text-red-600"};return V.jsx("span",{className:`font-medium ${e[n]}`,children:n})},bqn=({progress:n})=>{if(n===0)return null;const e=Math.round(n*100);return V.jsxs("div",{className:"flex items-center gap-2",children:[V.jsx("div",{className:"w-20 h-2 bg-gray-200 rounded overflow-hidden",children:V.jsx("div",{className:"h-full bg-blue-500 transition-all duration-200",style:{width:`${e}%`}})}),V.jsxs("span",{className:"text-xs text-gray-500",children:[e,"%"]})]})},vqn=n=>Object.entries(n).map(([e,t])=>`${e}: ${t}`).join(", "),wqn=({stats:n})=>{if(!n||Object.keys(n).length===0)return V.jsx("span",{children:"-"});const e=Object.entries(n),t=vqn(n);return V.jsxs("details",{className:"cursor-pointer",children:[V.jsx("summary",{className:"whitespace-nowrap overflow-hidden text-ellipsis max-w-[200px]",children:t}),V.jsx("div",{className:"mt-1 text-xs",children:e.map(([r,i])=>V.jsxs("div",{children:[r,": ",String(i)]},r))})]})},r2e=n=>{if(n===null||typeof n!="object")return n;if(Array.isArray(n))return n.map(r2e);const e={};for(const[t,r]of Object.entries(n))t.startsWith("_")||(e[t]=r2e(r));return e},Sqn=(n,e)=>{try{if(typeof n.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${e}`);return}const t=r2e(n.getConstructorParams()),r=new Blob([JSON.stringify(t,null,2)],{type:"application/json"}),i=URL.createObjectURL(r),o=document.createElement("a");o.href=i,o.download=`${e}_input.json`,o.click(),URL.revokeObjectURL(i)}catch(t){alert(`Error downloading input for ${e}: ${t instanceof Error?t.message:String(t)}`)}},Mqn=({solver:n,onStepUntilPhase:e,onDownloadInput:t})=>{const r=n.pipelineDef.map((a,c)=>_qn(n,c)),i=a=>{e?.(a)},o=a=>{a.solverInstance&&(t?t(a.solverInstance,a.name):Sqn(a.solverInstance,a.name))},s=a=>`${(a/1e3).toFixed(2)}s`;return V.jsxs("div",{className:"border-t border-gray-200",children:[V.jsx("div",{className:"px-4 py-2 bg-gray-50 border-b border-gray-200",children:V.jsx("h3",{className:"text-sm font-semibold text-gray-700",children:"Pipeline Steps"})}),V.jsx("div",{className:"overflow-x-auto",children:V.jsxs("table",{className:"w-full text-sm",children:[V.jsx("thead",{children:V.jsxs("tr",{className:"bg-gray-50 border-b border-gray-200",children:[V.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Step"}),V.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Status"}),V.jsxs("th",{className:"px-4 py-2 text-center font-semibold text-gray-700",children:["i",V.jsx("sub",{children:"0"})]}),V.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Iterations"}),V.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Progress"}),V.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Time"}),V.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stats"}),V.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Input"})]})}),V.jsx("tbody",{children:r.map(a=>V.jsxs("tr",{className:`border-b border-gray-100 ${a.status==="In Progress"?"bg-yellow-50":""}`,children:[V.jsx("td",{className:"px-4 py-2",children:V.jsxs("div",{className:"flex items-center gap-2",children:[V.jsx("span",{className:"text-gray-400 w-6",children:String(a.index+1).padStart(2,"0")}),V.jsx("button",{onClick:()=>i(a.name),disabled:a.status==="Completed"||n.solved||n.failed,className:"text-blue-500 hover:text-blue-700 disabled:text-gray-300 disabled:cursor-not-allowed",title:`Step until ${a.name} completes`,children:V.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:V.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"})})}),V.jsx("span",{className:"font-medium text-gray-900",children:a.name})]})}),V.jsx("td",{className:"px-4 py-2",children:V.jsx(xqn,{status:a.status})}),V.jsx("td",{className:"px-4 py-2 text-center text-gray-600",children:a.firstIteration!==null?a.firstIteration:""}),V.jsx("td",{className:"px-4 py-2 text-gray-600",children:a.iterations}),V.jsx("td",{className:"px-4 py-2",children:V.jsx(bqn,{progress:a.progress})}),V.jsx("td",{className:"px-4 py-2 text-gray-600",children:s(a.timeSpent)}),V.jsx("td",{className:"px-4 py-2 text-gray-500",children:V.jsx(wqn,{stats:a.stats})}),V.jsx("td",{className:"px-4 py-2",children:a.solverInstance?V.jsxs("button",{onClick:()=>o(a),className:"flex items-center gap-1 text-blue-500 hover:text-blue-700",title:`Download input for ${a.name}`,children:[V.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:V.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"})}),V.jsx("span",{children:"Input"})]}):null})]},a.name))})]})})]})},Eqn=class extends si.Component{constructor(n){super(n),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(n){console.error("InteractiveGraphics render error:",n)}render(){return this.state.hasError?this.props.fallback:this.props.children}};function Tqn({graphics:n}){const e=n.points??[],t=n.lines??[],r=n.rects??[],i=n.circles??[],o=n.texts??[];let s=Number.POSITIVE_INFINITY,a=Number.POSITIVE_INFINITY,c=Number.NEGATIVE_INFINITY,l=Number.NEGATIVE_INFINITY;const u=(g,y)=>{typeof g=="number"&&(g<s&&(s=g),g>c&&(c=g)),typeof y=="number"&&(y<a&&(a=y),y>l&&(l=y))};for(const g of e)u(g.x,g.y);for(const g of t){const y=g.points??[];for(const _ of y)u(_.x,_.y)}for(const g of r){const y=g.x??0,_=g.y??0,x=g.width??0,b=g.height??0;u(y,_),u(y+x,_+b)}for(const g of i){const y=g.x??0,_=g.y??0,x=g.radius??1;u(y-x,_-x),u(y+x,_+x)}for(const g of o)u(g.x,g.y);(!isFinite(s)||!isFinite(a)||!isFinite(c)||!isFinite(l))&&(s=-20,a=-20,c=20,l=20);const d=10,h=s-d,f=a-d,p=Math.max(1,c-s+2*d),m=Math.max(1,l-a+2*d);return V.jsxs("svg",{className:"w-full h-[400px] bg-white",viewBox:`${h} ${f} ${p} ${m}`,role:"img","aria-label":"Graphics fallback",children:[r.map((g,y)=>V.jsx("rect",{x:g.x??0,y:g.y??0,width:g.width??0,height:g.height??0,fill:"none",stroke:g.strokeColor??"black",strokeWidth:g.strokeWidth??1},`rect-${y}`)),t.map((g,y)=>V.jsx("polyline",{fill:"none",stroke:g.strokeColor??"black",strokeWidth:g.strokeWidth??1,points:(g.points??[]).map(_=>`${_.x??0},${_.y??0}`).join(" ")},`line-${y}`)),i.map((g,y)=>V.jsx("circle",{cx:g.x??0,cy:g.y??0,r:g.radius??1.5,fill:g.fillColor??"none",stroke:g.strokeColor??"black",strokeWidth:g.strokeWidth??1},`circle-${y}`)),e.map((g,y)=>V.jsx("circle",{cx:g.x??0,cy:g.y??0,r:g.radius??1.5,fill:g.color??"black"},`point-${y}`)),o.map((g,y)=>V.jsx("text",{x:g.x??0,y:g.y??0,fontSize:g.fontSize??10,fill:g.color??"black",children:g.text??""},`text-${y}`))]})}var Cqn=({solver:n,animationSpeed:e=25,onSolverStarted:t,onSolverCompleted:r})=>{const[i,o]=q.useReducer(u=>u+1,0),s=q.useMemo(()=>{try{return n.visualize()||{points:[],lines:[],rects:[],circles:[]}}catch(u){return console.error("Visualization error:",u),{points:[],lines:[],rects:[],circles:[]}}},[n,i]),a=q.useMemo(()=>(s.rects?.length||0)===0&&(s.lines?.length||0)===0&&(s.points?.length||0)===0&&(s.circles?.length||0)===0,[s]);q.useEffect(()=>{if(!(typeof document>"u")&&!document.querySelector('script[src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"]')){const u=document.createElement("script");u.src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4",document.head.appendChild(u)}},[]);const c=n.pipelineDef!==void 0,l=u=>{const d=n;if(!n.solved&&!n.failed){for(;!n.solved&&!n.failed&&d.currentPipelineStepIndex<=d.pipelineDef.findIndex(h=>h.solverName===u);)n.step();o()}};return V.jsxs("div",{children:[V.jsx(yqn,{solver:n,triggerRender:o,animationSpeed:e,onSolverStarted:t,onSolverCompleted:r}),a?V.jsx("div",{className:"p-4 text-gray-500",children:"No Graphics Yet"}):V.jsx(Eqn,{fallback:V.jsx(Tqn,{graphics:s}),children:V.jsx(pqn,{graphics:s})}),c&&V.jsx(Mqn,{solver:n,onStepUntilPhase:l})]})};const Pqn=()=>{q.useEffect(()=>{const n="tailwind-cdn-script";if(document.getElementById(n)||window.tailwind)return;const e=document.createElement("div");e.className="hidden",document.body.appendChild(e);const t=window.getComputedStyle(e).display==="none";if(document.body.removeChild(e),t)return;const r=document.createElement("script");r.id=n,r.src="https://cdn.tailwindcss.com",document.head.appendChild(r)},[])},Aqn=n=>n.toLowerCase().includes("pack")?iPn:n.toLowerCase().includes("rout")?lPn:HCn,Rqn=({solverEvents:n=[]})=>{const[e,t]=q.useState(null);Pqn();const r=q.useMemo(()=>{const a=new Map;for(const c of n){const l=`${c.componentName}-${c.solverName}`;a.set(l,c)}return a},[n]),i=q.useMemo(()=>Array.from(r.keys()),[r]),o=e?r.get(e):null,s=q.useMemo(()=>{if(!o)return{instance:null,error:null,classFound:!1};const a=moe[o.solverName];if(!a)return{instance:null,error:`Solver class "${o.solverName}" not found in SOLVERS registry. Available: ${Object.keys(moe).join(", ")}`,classFound:!1};try{const c=o.solverParams,l=c?.input!==void 0?c.input:c;return{instance:new a(l),error:null,classFound:!0}}catch(c){const l=c instanceof Error?c.message:String(c);return console.error("Failed to reconstruct solver:",c),{instance:null,error:`Failed to instantiate solver: ${l}`,classFound:!0}}},[o]);return n.length===0?V.jsx("div",{className:"rf-p-4",children:V.jsx("div",{className:"rf-bg-gray-50 rf-rounded-md rf-border rf-border-gray-200",children:V.jsxs("div",{className:"rf-p-4",children:[V.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800 rf-mb-3",children:"No Solvers Detected"}),V.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."})]})})}):V.jsxs("div",{className:"rf-flex rf-h-full rf-overflow-hidden",children:[V.jsxs("div",{className:"rf-w-64 rf-border-r rf-border-gray-200 rf-overflow-y-auto rf-flex-shrink-0",children:[V.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:[i.length," ",i.length===1?"Solver":"Solvers"]}),i.map(a=>{const c=r.get(a),l=e===a;return V.jsx("div",{className:`rf-px-3 rf-py-2 rf-cursor-pointer rf-border-b rf-border-gray-100 ${l?"rf-bg-blue-50 rf-border-l-2 rf-border-l-blue-500":"hover:rf-bg-gray-50"}`,onClick:()=>t(a),children:(()=>{const u=Aqn(c.solverName);return V.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[V.jsx(u,{className:"rf-w-4 rf-h-4 rf-text-blue-500 rf-flex-shrink-0"}),V.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[V.jsx("div",{className:"rf-text-sm rf-font-medium rf-text-gray-800 rf-truncate",children:c.componentName}),V.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate",children:c.solverName})]})]})})()},a)})]}),V.jsx("div",{className:"rf-flex-1 rf-overflow-hidden",children:o?s.instance?V.jsx(m5,{fallback:V.jsx("div",{className:"rf-p-4",children:V.jsxs("div",{className:"rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200 rf-p-4",children:[V.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-2",children:"Error Loading Solver Debugger"}),V.jsxs("p",{className:"rf-text-sm rf-text-red-600",children:["Failed to render the solver debugger for"," ",o.solverName]})]})}),children:V.jsx(Cqn,{solver:s.instance})}):V.jsxs("div",{className:"rf-p-4",children:[V.jsxs("div",{className:"rf-mb-4",children:[V.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800",children:o.solverName}),V.jsxs("p",{className:"rf-text-sm rf-text-gray-500",children:["Component: ",o.componentName]})]}),s.error&&V.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:V.jsx("p",{className:`rf-text-sm ${s.classFound?"rf-text-red-700":"rf-text-yellow-700"}`,children:s.error})}),V.jsxs("div",{className:"rf-border rf-border-gray-200 rf-rounded-md rf-overflow-hidden",children:[V.jsx("div",{className:"rf-px-3 rf-py-2 rf-bg-gray-50",children:V.jsx("span",{className:"rf-text-sm rf-font-medium rf-text-gray-700",children:"Solver Parameters"})}),V.jsx("div",{className:"rf-p-3 rf-bg-white rf-border-t rf-border-gray-200",children:V.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)})})]})]}):V.jsx("div",{className:"rf-flex rf-items-center rf-justify-center rf-h-full",children:V.jsx("p",{className:"rf-text-sm rf-text-gray-500",children:"Select a solver from the list to view details"})})})]})},$0t=({errorMessage:n,errorStack:e,circuitJsonErrors:t})=>{q.useEffect(()=>{if(n){const r=new Error(n);e&&(r.stack=e);try{fH.captureException(r)}catch{}}},[n,e]),q.useEffect(()=>{if(t&&t.length>0)for(const r of t){const i=new Error(r.message||"Circuit JSON Error");r.stack&&(i.stack=r.stack);try{fH.captureException(i,{error_type:r.type})}catch{}}},[t])},F0t="0.0.1804",Nqn={version:F0t},sq=KOe()(QOe(n=>({lastRunEvalVersion:void 0,setLastRunEvalVersion:e=>{n({lastRunEvalVersion:e})}}),{name:"runframe-runner-store"})),Iqn=n=>{const[e,t]=q.useState([]),[r,i]=q.useState(null),[o,s]=q.useState(""),[a,c]=vT("eval-version-selection",null),l=sq(f=>f.setLastRunEvalVersion),u=sq(f=>f.lastRunEvalVersion);return q.useEffect(()=>{n&&fetch("https://data.jsdelivr.com/v1/package/npm/@tscircuit/eval").then(f=>f.json()).then(f=>{if(Array.isArray(f?.versions)){let p=[...f.versions];f.tags?.latest&&(i(f.tags.latest),p=p.filter(m=>m!==f.tags.latest)),t(p)}}).catch(()=>{})},[n]),q.useEffect(()=>{n&&(a?(window.TSCIRCUIT_LATEST_EVAL_VERSION=a,l(a)):r&&(window.TSCIRCUIT_LATEST_EVAL_VERSION=r,l(r)))},[n,a,r]),{versions:q.useMemo(()=>e.filter(f=>f.includes(o)).slice(0,50),[e,o]),latestVersion:r,lastRunEvalVersion:u,search:o,setSearch:s,selectVersion:f=>{c(f),s("")}}},kqn=({snippetNames:n,onSelect:e,onCancel:t,isOpen:r})=>{const[i,o]=q.useState(""),[s,a]=q.useState("");if(!r)return null;const c=n.filter(d=>d.toLowerCase().includes(s.toLowerCase())),l=s&&!n.includes(s),u=d=>{d.key==="Enter"&&(c.length===1?o(c[0]):l&&o(s))};return V.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:V.jsxs("div",{className:"rf-bg-white rf-rounded-lg rf-p-6 rf-w-96",children:[V.jsx("h2",{className:"rf-text-lg rf-font-semibold rf-mb-4",children:"Select Snippet"}),V.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:d=>a(d.target.value),onKeyDown:u}),V.jsxs("div",{className:"rf-h-60 rf-overflow-y-auto",children:[c.map(d=>V.jsx("button",{type:"button",className:`w-full text-left px-4 py-2 rounded hover:bg-gray-100 ${i===d?"bg-blue-50":""}`,onClick:()=>o(d),children:d},d)),l&&V.jsxs("button",{type:"button",className:`w-full text-left px-4 py-2 rounded hover:bg-gray-100 text-blue-500 ${i===s?"bg-blue-50":""}`,onClick:()=>o(s),children:['Create new "',s,'"']})]}),V.jsxs("div",{className:"rf-mt-4 rf-flex rf-justify-end rf-gap-2",children:[V.jsx("button",{type:"button",className:"rf-px-4 rf-py-2 rf-text-gray-600 rf-hover:text-gray-800",onClick:t,children:"Cancel"}),V.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:()=>i&&e(i),disabled:!i,children:i===s?`Create "${i}"`:`Save to ${i}`})]})]})})},Oqn=n=>{const e=q.useRef(null),t=Ju(r=>r.recentEvents);q.useEffect(()=>{if(t.length===0)return;const r=t[0];r.event_id!==e.current&&(n(r),e.current=r.event_id)},[t,n])};function Lqn(n){const e=Dqn(n),t=q.forwardRef((r,i)=>{const{children:o,...s}=r,a=q.Children.toArray(o),c=a.find($qn);if(c){const l=c.props.children,u=a.map(d=>d===c?q.Children.count(l)>1?q.Children.only(null):q.isValidElement(l)?l.props.children:null:d);return V.jsx(e,{...s,ref:i,children:q.isValidElement(l)?q.cloneElement(l,void 0,u):null})}return V.jsx(e,{...s,ref:i,children:o})});return t.displayName=`${n}.Slot`,t}function Dqn(n){const e=q.forwardRef((t,r)=>{const{children:i,...o}=t;if(q.isValidElement(i)){const s=Bqn(i),a=Fqn(o,i.props);return i.type!==q.Fragment&&(a.ref=r?E_(r,s):s),q.cloneElement(i,a)}return q.Children.count(i)>1?q.Children.only(null):null});return e.displayName=`${n}.SlotClone`,e}var zqn=Symbol("radix.slottable");function $qn(n){return q.isValidElement(n)&&typeof n.type=="function"&&"__radixId"in n.type&&n.type.__radixId===zqn}function Fqn(n,e){const t={...e};for(const r in e){const i=n[r],o=e[r];/^on[A-Z]/.test(r)?i&&o?t[r]=(...a)=>{const c=o(...a);return i(...a),c}:i&&(t[r]=i):r==="style"?t[r]={...i,...o}:r==="className"&&(t[r]=[i,o].filter(Boolean).join(" "))}return{...n,...t}}function Bqn(n){let e=Object.getOwnPropertyDescriptor(n.props,"ref")?.get,t=e&&"isReactWarning"in e&&e.isReactWarning;return t?n.ref:(e=Object.getOwnPropertyDescriptor(n,"ref")?.get,t=e&&"isReactWarning"in e&&e.isReactWarning,t?n.props.ref:n.props.ref||n.ref)}var aq="Dialog",[B0t,j0t]=r4(aq),[jqn,R4]=B0t(aq),U0t=n=>{const{__scopeDialog:e,children:t,open:r,defaultOpen:i,onOpenChange:o,modal:s=!0}=n,a=q.useRef(null),c=q.useRef(null),[l,u]=M3({prop:r,defaultProp:i??!1,onChange:o,caller:aq});return V.jsx(jqn,{scope:e,triggerRef:a,contentRef:c,contentId:Wm(),titleId:Wm(),descriptionId:Wm(),open:l,onOpenChange:u,onOpenToggle:q.useCallback(()=>u(d=>!d),[u]),modal:s,children:t})};U0t.displayName=aq;var H0t="DialogTrigger",Y0t=q.forwardRef((n,e)=>{const{__scopeDialog:t,...r}=n,i=R4(H0t,t),o=ed(e,i.triggerRef);return V.jsx(Mc.button,{type:"button","aria-haspopup":"dialog","aria-expanded":i.open,"aria-controls":i.contentId,"data-state":s2e(i.open),...r,ref:o,onClick:Bi(n.onClick,i.onOpenToggle)})});Y0t.displayName=H0t;var i2e="DialogPortal",[Uqn,X0t]=B0t(i2e,{forceMount:void 0}),V0t=n=>{const{__scopeDialog:e,forceMount:t,children:r,container:i}=n,o=R4(i2e,e);return V.jsx(Uqn,{scope:e,forceMount:t,children:q.Children.map(r,s=>V.jsx(Nx,{present:t||o.open,children:V.jsx(wV,{asChild:!0,container:i,children:s})}))})};V0t.displayName=i2e;var cq="DialogOverlay",G0t=q.forwardRef((n,e)=>{const t=X0t(cq,n.__scopeDialog),{forceMount:r=t.forceMount,...i}=n,o=R4(cq,n.__scopeDialog);return o.modal?V.jsx(Nx,{present:r||o.open,children:V.jsx(Yqn,{...i,ref:e})}):null});G0t.displayName=cq;var Hqn=Lqn("DialogOverlay.RemoveScroll"),Yqn=q.forwardRef((n,e)=>{const{__scopeDialog:t,...r}=n,i=R4(cq,t);return V.jsx(RV,{as:Hqn,allowPinchZoom:!0,shards:[i.contentRef],children:V.jsx(Mc.div,{"data-state":s2e(i.open),...r,ref:e,style:{pointerEvents:"auto",...r.style}})})}),VS="DialogContent",q0t=q.forwardRef((n,e)=>{const t=X0t(VS,n.__scopeDialog),{forceMount:r=t.forceMount,...i}=n,o=R4(VS,n.__scopeDialog);return V.jsx(Nx,{present:r||o.open,children:o.modal?V.jsx(Xqn,{...i,ref:e}):V.jsx(Vqn,{...i,ref:e})})});q0t.displayName=VS;var Xqn=q.forwardRef((n,e)=>{const t=R4(VS,n.__scopeDialog),r=q.useRef(null),i=ed(e,t.contentRef,r);return q.useEffect(()=>{const o=r.current;if(o)return wge(o)},[]),V.jsx(W0t,{...n,ref:i,trapFocus:t.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:Bi(n.onCloseAutoFocus,o=>{o.preventDefault(),t.triggerRef.current?.focus()}),onPointerDownOutside:Bi(n.onPointerDownOutside,o=>{const s=o.detail.originalEvent,a=s.button===0&&s.ctrlKey===!0;(s.button===2||a)&&o.preventDefault()}),onFocusOutside:Bi(n.onFocusOutside,o=>o.preventDefault())})}),Vqn=q.forwardRef((n,e)=>{const t=R4(VS,n.__scopeDialog),r=q.useRef(!1),i=q.useRef(!1);return V.jsx(W0t,{...n,ref:e,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:o=>{n.onCloseAutoFocus?.(o),o.defaultPrevented||(r.current||t.triggerRef.current?.focus(),o.preventDefault()),r.current=!1,i.current=!1},onInteractOutside:o=>{n.onInteractOutside?.(o),o.defaultPrevented||(r.current=!0,o.detail.originalEvent.type==="pointerdown"&&(i.current=!0));const s=o.target;t.triggerRef.current?.contains(s)&&o.preventDefault(),o.detail.originalEvent.type==="focusin"&&i.current&&o.preventDefault()}})}),W0t=q.forwardRef((n,e)=>{const{__scopeDialog:t,trapFocus:r,onOpenAutoFocus:i,onCloseAutoFocus:o,...s}=n,a=R4(VS,t),c=q.useRef(null),l=ed(e,c);return rge(),V.jsxs(V.Fragment,{children:[V.jsx(lV,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:i,onUnmountAutoFocus:o,children:V.jsx($k,{role:"dialog",id:a.contentId,"aria-describedby":a.descriptionId,"aria-labelledby":a.titleId,"data-state":s2e(a.open),...s,ref:l,onDismiss:()=>a.onOpenChange(!1)})}),V.jsxs(V.Fragment,{children:[V.jsx(qqn,{titleId:a.titleId}),V.jsx(Zqn,{contentRef:c,descriptionId:a.descriptionId})]})]})}),o2e="DialogTitle",Z0t=q.forwardRef((n,e)=>{const{__scopeDialog:t,...r}=n,i=R4(o2e,t);return V.jsx(Mc.h2,{id:i.titleId,...r,ref:e})});Z0t.displayName=o2e;var K0t="DialogDescription",Q0t=q.forwardRef((n,e)=>{const{__scopeDialog:t,...r}=n,i=R4(K0t,t);return V.jsx(Mc.p,{id:i.descriptionId,...r,ref:e})});Q0t.displayName=K0t;var J0t="DialogClose",eht=q.forwardRef((n,e)=>{const{__scopeDialog:t,...r}=n,i=R4(J0t,t);return V.jsx(Mc.button,{type:"button",...r,ref:e,onClick:Bi(n.onClick,()=>i.onOpenChange(!1))})});eht.displayName=J0t;function s2e(n){return n?"open":"closed"}var tht="DialogTitleWarning",[Gqn,nht]=cQt(tht,{contentName:VS,titleName:o2e,docsSlug:"dialog"}),qqn=({titleId:n})=>{const e=nht(tht),t=`\`${e.contentName}\` requires a \`${e.titleName}\` for the component to be accessible for screen reader users.
5679
5679
 
5680
5680
  If you want to hide the \`${e.titleName}\`, you can wrap it with our VisuallyHidden component.
5681
5681
 
@@ -5685,7 +5685,7 @@ You can add a description to the \`${BP}\` by passing a \`${dht}\` component as
5685
5685
 
5686
5686
  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 \`${BP}\`. 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.
5687
5687
 
5688
- For more information, see https://radix-ui.com/primitives/docs/components/alert-dialog`;return q.useEffect(()=>{document.getElementById(n.current?.getAttribute("aria-describedby"))||console.warn(e)},[e,n]),null},uWn=oht,dWn=sht,yht=aht,ght=cht,_ht=pht,xht=mht,bht=uht,vht=hht;const wht=uWn,hWn=dWn,Sht=q.forwardRef(({className:n,...e},t)=>V.jsx(yht,{className:ai("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",n),...e,ref:t}));Sht.displayName=yht.displayName;const d2e=q.forwardRef(({className:n,...e},t)=>V.jsxs(hWn,{children:[V.jsx(Sht,{}),V.jsx(ght,{ref:t,className:ai("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",n),...e})]}));d2e.displayName=ght.displayName;const h2e=({className:n,...e})=>V.jsx("div",{className:ai("rf-flex rf-flex-col rf-space-y-2 rf-text-center sm:rf-text-left",n),...e});h2e.displayName="AlertDialogHeader";const p2e=({className:n,...e})=>V.jsx("div",{className:ai("rf-flex rf-flex-col-reverse sm:rf-flex-row sm:rf-justify-end sm:rf-space-x-2",n),...e});p2e.displayName="AlertDialogFooter";const f2e=q.forwardRef(({className:n,...e},t)=>V.jsx(bht,{ref:t,className:ai("rf-text-lg rf-font-semibold",n),...e}));f2e.displayName=bht.displayName;const m2e=q.forwardRef(({className:n,...e},t)=>V.jsx(vht,{ref:t,className:ai("rf-text-sm rf-text-zinc-500 dark:rf-text-zinc-400",n),...e}));m2e.displayName=vht.displayName;const pWn=q.forwardRef(({className:n,...e},t)=>V.jsx(_ht,{ref:t,className:ai(sP(),n),...e}));pWn.displayName=_ht.displayName;const y2e=q.forwardRef(({className:n,...e},t)=>V.jsx(xht,{ref:t,className:ai(sP({variant:"outline"}),"rf-mt-2 sm:rf-mt-0",n),...e}));y2e.displayName=xht.displayName;function fWn(n){const e=q.useRef({value:n,previous:n});return q.useMemo(()=>(e.current.value!==n&&(e.current.previous=e.current.value,e.current.value=n),e.current.previous),[n])}var dq="Checkbox",[mWn]=r4(dq),[yWn,g2e]=mWn(dq);function gWn(n){const{__scopeCheckbox:e,checked:t,children:r,defaultChecked:i,disabled:o,form:s,name:a,onCheckedChange:c,required:l,value:u="on",internal_do_not_use_render:d}=n,[h,f]=M3({prop:t,defaultProp:i??!1,onChange:c,caller:dq}),[p,m]=q.useState(null),[g,y]=q.useState(null),_=q.useRef(!1),x=p?!!s||!!p.closest("form"):!0,b={checked:h,disabled:o,setChecked:f,control:p,setControl:m,name:a,form:s,value:u,hasConsumerStoppedPropagationRef:_,required:l,defaultChecked:L8(i)?!1:i,isFormControl:x,bubbleInput:g,setBubbleInput:y};return V.jsx(yWn,{scope:e,...b,children:_Wn(d)?d(b):r})}var Mht="CheckboxTrigger",Eht=q.forwardRef(({__scopeCheckbox:n,onKeyDown:e,onClick:t,...r},i)=>{const{control:o,value:s,disabled:a,checked:c,required:l,setControl:u,setChecked:d,hasConsumerStoppedPropagationRef:h,isFormControl:f,bubbleInput:p}=g2e(Mht,n),m=ed(i,u),g=q.useRef(c);return q.useEffect(()=>{const y=o?.form;if(y){const _=()=>d(g.current);return y.addEventListener("reset",_),()=>y.removeEventListener("reset",_)}},[o,d]),V.jsx(Mc.button,{type:"button",role:"checkbox","aria-checked":L8(c)?"mixed":c,"aria-required":l,"data-state":Rht(c),"data-disabled":a?"":void 0,disabled:a,value:s,...r,ref:m,onKeyDown:Bi(e,y=>{y.key==="Enter"&&y.preventDefault()}),onClick:Bi(t,y=>{d(_=>L8(_)?!0:!_),p&&f&&(h.current=y.isPropagationStopped(),h.current||y.stopPropagation())})})});Eht.displayName=Mht;var _2e=q.forwardRef((n,e)=>{const{__scopeCheckbox:t,name:r,checked:i,defaultChecked:o,required:s,disabled:a,value:c,onCheckedChange:l,form:u,...d}=n;return V.jsx(gWn,{__scopeCheckbox:t,checked:i,defaultChecked:o,disabled:a,required:s,onCheckedChange:l,name:r,form:u,value:c,internal_do_not_use_render:({isFormControl:h})=>V.jsxs(V.Fragment,{children:[V.jsx(Eht,{...d,ref:e,__scopeCheckbox:t}),h&&V.jsx(Aht,{__scopeCheckbox:t})]})})});_2e.displayName=dq;var Tht="CheckboxIndicator",Cht=q.forwardRef((n,e)=>{const{__scopeCheckbox:t,forceMount:r,...i}=n,o=g2e(Tht,t);return V.jsx(Nx,{present:r||L8(o.checked)||o.checked===!0,children:V.jsx(Mc.span,{"data-state":Rht(o.checked),"data-disabled":o.disabled?"":void 0,...i,ref:e,style:{pointerEvents:"none",...n.style}})})});Cht.displayName=Tht;var Pht="CheckboxBubbleInput",Aht=q.forwardRef(({__scopeCheckbox:n,...e},t)=>{const{control:r,hasConsumerStoppedPropagationRef:i,checked:o,defaultChecked:s,required:a,disabled:c,name:l,value:u,form:d,bubbleInput:h,setBubbleInput:f}=g2e(Pht,n),p=ed(t,f),m=fWn(o),g=nrt(r);q.useEffect(()=>{const _=h;if(!_)return;const x=window.HTMLInputElement.prototype,w=Object.getOwnPropertyDescriptor(x,"checked").set,S=!i.current;if(m!==o&&w){const E=new Event("click",{bubbles:S});_.indeterminate=L8(o),w.call(_,L8(o)?!1:o),_.dispatchEvent(E)}},[h,m,o,i]);const y=q.useRef(L8(o)?!1:o);return V.jsx(Mc.input,{type:"checkbox","aria-hidden":!0,defaultChecked:s??y.current,required:a,disabled:c,name:l,value:u,form:d,...e,tabIndex:-1,ref:p,style:{...e.style,...g,position:"absolute",pointerEvents:"none",opacity:0,margin:0,transform:"translateX(-100%)"}})});Aht.displayName=Pht;function _Wn(n){return typeof n=="function"}function L8(n){return n==="indeterminate"}function Rht(n){return L8(n)?"indeterminate":n?"checked":"unchecked"}const GO=q.forwardRef(({className:n,...e},t)=>V.jsx(_2e,{ref:t,className:ai("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",n),...e,children:V.jsx(Cht,{className:ai("rf-flex rf-items-center rf-justify-center rf-text-current"),children:V.jsx(bS,{className:"rf-h-4 rf-w-4"})})}));GO.displayName=_2e.displayName;const jP=a2e,xWn=c2e,Nht=q.forwardRef(({className:n,...e},t)=>V.jsx(lq,{className:ai("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",n),...e,ref:t}));Nht.displayName=lq.displayName;const GS=q.forwardRef(({className:n,children:e,showOverlay:t=!0,...r},i)=>V.jsxs(xWn,{children:[V.jsx(Nht,{className:ai(t?"":"rf-hidden")}),V.jsx(uq,{ref:i,className:ai("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",n),...r,children:e})]}));GS.displayName=uq.displayName;const qS=({className:n,...e})=>V.jsx("div",{className:ai("rf-flex rf-flex-col rf-space-y-2 rf-text-center sm:rf-text-left",n),...e});qS.displayName="DialogHeader";const qO=({className:n,...e})=>V.jsx("div",{className:ai("rf-flex rf-flex-col-reverse sm:rf-flex-row sm:rf-justify-end sm:rf-space-x-2",n),...e});qO.displayName="DialogFooter";const WS=q.forwardRef(({className:n,...e},t)=>V.jsx(l2e,{ref:t,className:ai("rf-text-lg rf-font-semibold",n),...e}));WS.displayName=l2e.displayName;const UP=q.forwardRef(({className:n,...e},t)=>V.jsx(u2e,{ref:t,className:ai("rf-text-sm rf-text-zinc-500 dark:rf-text-zinc-400",n),...e}));UP.displayName=u2e.displayName;const hq={"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"}},bWn="https://cdn.jsdelivr.net/npm/easyeda@latest/dist/browser/index.js";let x2e=null;const vWn=async()=>(x2e||(x2e=import(bWn)),x2e),wWn=async(n,e=10)=>{const t=encodeURIComponent(n),r=await fetch(`https://jlcsearch.tscircuit.com/api/search?limit=${e}&q=${t}`);if(!r.ok)throw new Error(`JLCPCB API error: ${r.status}`);return(await r.json()).components??[]},SWn=n=>({lcscId:n.lcsc,manufacturer:n.mfr,description:n.description,partNumber:`C${n.lcsc}`,package:n.package,price:n.price,stock:n.stock,isBasic:n.is_basic}),MWn=async(n,e)=>{const{fetchEasyEDAComponent:t,convertRawEasyToTsx:r}=await vWn(),i=await t(n,{fetch:(o,s)=>fetch(`${e?.apiBase??M_}/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"]??"",...e?.headers}})});return r({rawEasy:i})},EWn=({query:n,placeholder:e,isSearching:t,onQueryChange:r,onSubmit:i})=>{const o=q.useCallback(s=>{s.key==="Enter"&&(s.preventDefault(),i())},[i]);return V.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2 rf-mt-4",children:[V.jsxs("div",{className:"rf-relative rf-flex-grow",children:[V.jsx(ege,{className:"rf-absolute rf-left-2 rf-top-2.5 rf-h-4 rf-w-4 rf-text-muted-foreground"}),V.jsx(O_e,{placeholder:e,className:"rf-pl-8",spellCheck:!1,autoComplete:"off",value:n,onChange:s=>r(s.target.value),onKeyDown:o})]}),V.jsx(hc,{onClick:i,disabled:t||n.trim().length<1,className:"sm:rf-px-4 rf-px-3",children:t?V.jsx(D9,{className:"rf-h-4 rf-w-4 rf-animate-spin"}):V.jsxs(V.Fragment,{children:[V.jsx(ege,{className:"rf-h-4 rf-w-4 sm:rf-hidden"}),V.jsx("span",{className:"rf-hidden sm:rf-inline",children:"Search"})]})})]})},TWn=new Intl.NumberFormat("en-US",{style:"currency",currency:"USD"}),CWn=n=>TWn.format(n),Iht=n=>{switch(n.source){case"tscircuit.com":{const e=n.package;return`tscircuit-${e.package_id??`${e.org_owner_tscircuit_handle??"unknown"}-${e.unscoped_name??e.name??"package"}`}`}case"jlcpcb":return`jlc-${n.component.lcscId}`;case"kicad":return`kicad-${n.footprint.path}`;default:return"unknown"}},PWn=n=>{switch(n.source){case"tscircuit.com":return n.package.unscoped_name;case"jlcpcb":return n.component.manufacturer;case"kicad":return n.footprint.qualifiedName}},AWn=n=>{switch(n.source){case"tscircuit.com":return n.package.description||(n.package.org_owner_tscircuit_handle?`Component by ${n.package.org_owner_tscircuit_handle}`:void 0);case"jlcpcb":return n.component.description;case"kicad":return n.footprint.description}},RWn=n=>{switch(n.source){case"tscircuit.com":return n.package.name;case"jlcpcb":return n.component.partNumber;case"kicad":return}},NWn=({results:n,selected:e,onSelect:t,onShowDetails:r})=>{const i=e?Iht(e):null;return V.jsx("div",{className:"rf-divide-y rf-w-full rf-overflow-hidden",children:n.map(o=>{const s=Iht(o),a=i===s,c=PWn(o),l=AWn(o),u=RWn(o),d=o.source==="jlcpcb"?o.component.stock:null,h=o.source==="jlcpcb"?o.component.price:null,f=o.source==="jlcpcb"?o.component.isBasic:null;return V.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 ${a?"rf-bg-zinc-100":""}`,onClick:()=>t(o),children:[V.jsxs("div",{className:"rf-min-w-0 rf-overflow-hidden rf-w-full",children:[V.jsxs("div",{className:"rf-flex rf-items-start rf-gap-2 rf-min-w-0",children:[V.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:[c,o.source==="jlcpcb"&&f!=null&&V.jsx("span",{className:`rf-text-xs rf-px-1.5 rf-py-0.5 rf-rounded rf-font-medium rf-flex-shrink-0 ${f?"rf-bg-green-100 rf-text-green-700":"rf-bg-orange-100 rf-text-orange-700"}`,children:f?"Basic":"Extended"}),o.source==="tscircuit.com"&&o.package.is_private&&V.jsx(sPn,{className:"rf-ml-1 rf-h-3 rf-w-3 rf-text-zinc-400 rf-flex-shrink-0"})]}),o.source==="jlcpcb"&&d!=null?V.jsxs("div",{className:"rf-text-xs rf-text-zinc-500 rf-font-medium rf-whitespace-nowrap rf-flex-shrink-0 sm:rf-hidden",children:[d.toLocaleString()," in stock"]}):null]}),V.jsxs("div",{className:"rf-text-xs rf-text-zinc-500 rf-truncate rf-w-full",children:[u?V.jsx("span",{className:"rf-mr-2",children:u}):null,l]})]}),V.jsxs("div",{children:[o.source==="tscircuit.com"&&r?V.jsx("div",{className:"rf-flex-shrink-0 rf-w-full sm:rf-w-auto",children:V.jsx(hc,{variant:"outline",size:"sm",className:"rf-text-xs rf-w-full sm:rf-w-auto",onClick:p=>{p.stopPropagation(),r(o)},children:"See Details"})}):o.source==="jlcpcb"&&d!=null?V.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:[d.toLocaleString()," in stock"]}):null,h!=null&&V.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:CWn(h)})]})]},s)})})},IWn=({packageResult:n,isOpen:e,onOpenChange:t,isLoading:r,details:i,previewTab:o,onPreviewTabChange:s,isSubmitting:a,onImport:c})=>{const l=n?.package??null,u=l?.latest_pcb_preview_image_url,d=l?.latest_sch_preview_image_url,h=l?.latest_cad_preview_image_url,f=l?.unscoped_name?.split("/").pop()??l?.unscoped_name,p=l?.org_owner_tscircuit_handle??void 0,m=p?`https://tscircuit.com/${p}`:void 0,g=p&&f?`https://tscircuit.com/${p}/${f}`:void 0;return V.jsx(jP,{open:e,onOpenChange:t,children:V.jsxs(GS,{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:[V.jsx(qS,{className:"rf-pb-4 rf-border-b",children:V.jsx("div",{className:"rf-flex rf-items-start rf-justify-between rf-gap-4",children:V.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[V.jsx(WS,{className:"rf-text-xl rf-font-semibold rf-truncate",children:f}),V.jsx(UP,{children:l?.description})]})})}),V.jsxs("div",{className:"rf-flex-1 rf-overflow-y-auto rf-py-4 rf-space-y-6",children:[p?V.jsxs("div",{children:[V.jsx("span",{className:"rf-text-xs rf-font-medium rf-text-gray-500 rf-uppercase rf-tracking-wide",children:"Created by"}),V.jsx("div",{className:"rf-mt-1 rf-text-sm rf-font-medium",children:m?V.jsx("a",{href:m,target:"_blank",rel:"noopener noreferrer",className:"rf-text-black hover:rf-underline",children:p}):p})]}):null,(h||u||d)&&V.jsx(V.Fragment,{children:V.jsxs("div",{children:[V.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-mb-4",children:"Preview"}),V.jsxs(Gse,{value:o,onValueChange:y=>s(y),children:[V.jsxs(yH,{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:[u&&V.jsx(Rb,{value:"pcb",children:"PCB"}),d&&V.jsx(Rb,{value:"schematic",children:"Schematic"}),h&&V.jsx(Rb,{value:"3d",children:"3D"})]}),V.jsxs("div",{className:"rf-mt-4",children:[V.jsx(ry,{value:"pcb",className:"rf-border rf-rounded-lg rf-overflow-hidden rf-bg-gray-50",children:u?V.jsx("img",{src:u,alt:`${f??"package"} PCB preview`,className:"rf-w-full rf-h-full rf-object-contain rf-bg-white rf-p-4"}):null}),V.jsx(ry,{value:"schematic",className:"rf-border rf-rounded-lg rf-overflow-hidden rf-bg-gray-50",children:d?V.jsx("img",{src:d,alt:`${f??"package"} schematic preview`,className:"rf-w-full rf-h-full rf-object-contain rf-bg-white rf-p-4"}):null}),V.jsx(ry,{value:"3d",className:"rf-border rf-rounded-lg rf-overflow-hidden rf-bg-gray-50",children:h?V.jsx("img",{src:h,alt:`${f??"package"} 3D preview`,className:"rf-w-full rf-h-full rf-object-contain rf-bg-white rf-p-4"}):null})]})]})]})}),i?.ai_description?V.jsxs("section",{children:[V.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-mb-3",children:"AI Description"}),V.jsx("div",{className:"rf-bg-gray-50 rf-border rf-border-gray-200 rf-rounded-lg rf-p-4",children:V.jsx("p",{className:"rf-text-sm rf-text-gray-700 rf-leading-relaxed",children:i.ai_description})})]}):null,i?.ai_usage_instructions?V.jsxs("section",{children:[V.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-mb-3",children:"Usage Instructions"}),V.jsx("div",{className:"rf-bg-gray-50 rf-border rf-border-gray-200 rf-rounded-lg rf-p-4",children:V.jsx("p",{className:"rf-text-sm rf-text-gray-700 rf-leading-relaxed rf-whitespace-pre-wrap",children:i.ai_usage_instructions})})]}):null,r?V.jsxs("div",{className:"rf-flex rf-justify-center rf-items-center rf-gap-2 rf-text-gray-500",children:[V.jsx(D9,{className:"rf-h-4 rf-w-4 rf-animate-spin"}),V.jsx("span",{className:"rf-text-sm",children:"Loading package details..."})]}):null]}),V.jsxs(qO,{className:"rf-pt-4 rf-border-t rf-flex rf-flex-col sm:rf-flex-row rf-justify-between rf-gap-2",children:[V.jsx("div",{className:"rf-flex-1",children:g?V.jsxs(hc,{variant:"outline",size:"sm",className:"rf-gap-2 rf-w-full sm:rf-w-auto",onClick:()=>window.open(g,"_blank"),children:[V.jsx(JCn,{className:"rf-h-4 rf-w-4"}),"View on tscircuit.com"]}):null}),V.jsxs("div",{className:"rf-flex rf-flex-col sm:rf-flex-row rf-gap-2",children:[V.jsx(hc,{variant:"outline",onClick:()=>t(!1),className:"rf-order-2 sm:rf-order-1",children:"Close"}),V.jsx(hc,{onClick:c,disabled:a,className:"rf-bg-blue-600 hover:rf-bg-blue-700",children:a?V.jsx(D9,{className:"rf-h-4 rf-w-4 rf-animate-spin"}):"Import Component"})]})]})]})})},kWn=()=>{const[n,e]=q.useState(null),[t,r]=q.useState(!1),i=q.useCallback(async(s,a)=>{r(!0);try{const c=await fetch(`https://api.tscircuit.com/packages/get?name=${encodeURIComponent(`${s}/${a}`)}`);if(!c.ok)throw new Error(`Failed to load package details: ${c.status}`);const l=await c.json();e(l.package??null)}catch(c){console.error("Failed to fetch package details",c),e(null)}finally{r(!1)}},[]),o=q.useCallback(()=>{e(null),r(!1)},[]);return{details:n,isLoading:t,fetchDetails:i,reset:o}},OWn=async(n,e)=>{const t={"Content-Type":"application/json"};e&&(t.Authorization=`Bearer ${e}`);const r=await fetch("https://registry-api.tscircuit.com/packages/search",{method:"POST",headers:t,body:JSON.stringify({query:n})});if(!r.ok)throw new Error(`tscircuit registry error: ${r.status}`);return(await r.json()).packages??[]},LWn=({sessionToken:n})=>{const[e,t]=q.useState([]),[r,i]=q.useState(!1),[o,s]=q.useState(null),[a,c]=q.useState(!1),l=q.useCallback(async d=>{const h=d.trim();if(!h)return[];i(!0),s(null);try{const p=(await OWn(h,n)).map(m=>({source:"tscircuit.com",package:m}));return t(p),p}catch(f){return console.error("Error searching tscircuit packages",f),t([]),s(f instanceof Error?f.message:"Failed to search tscircuit packages"),[]}finally{i(!1),c(!0)}},[n]),u=q.useCallback(()=>{t([]),i(!1),s(null),c(!1)},[]);return{results:e,isSearching:r,error:o,hasSearched:a,search:l,reset:u}},DWn=n=>{const e=n.trim();return/^C\d+/i.test(e)?e.replace(/^C/i,""):e},zWn=()=>{const[n,e]=q.useState([]),[t,r]=q.useState(!1),[i,o]=q.useState(null),[s,a]=q.useState(!1),c=q.useCallback(async u=>{const d=DWn(u);if(!d)return[];r(!0),o(null);try{const f=(await wWn(d,10)).map(p=>({source:"jlcpcb",component:SWn(p)}));return e(f),f}catch(h){return console.error("Error searching JLCPCB components",h),e([]),o(h instanceof Error?h.message:"Failed to search JLCPCB components"),[]}finally{r(!1),a(!0)}},[]),l=q.useCallback(()=>{e([]),r(!1),o(null),a(!1)},[]);return{results:n,isSearching:t,error:i,hasSearched:s,search:c,reset:l}};function K9(n){return Array.isArray?Array.isArray(n):Lht(n)==="[object Array]"}function $Wn(n){if(typeof n=="string")return n;let e=n+"";return e=="0"&&1/n==-1/0?"-0":e}function FWn(n){return n==null?"":$Wn(n)}function mv(n){return typeof n=="string"}function kht(n){return typeof n=="number"}function BWn(n){return n===!0||n===!1||jWn(n)&&Lht(n)=="[object Boolean]"}function Oht(n){return typeof n=="object"}function jWn(n){return Oht(n)&&n!==null}function e2(n){return n!=null}function b2e(n){return!n.trim().length}function Lht(n){return n==null?n===void 0?"[object Undefined]":"[object Null]":Object.prototype.toString.call(n)}const UWn="Incorrect 'index' type",HWn=n=>`Invalid value for key ${n}`,YWn=n=>`Pattern length exceeds max of ${n}.`,XWn=n=>`Missing ${n} property in key`,VWn=n=>`Property 'weight' in key '${n}' must be a positive integer`,Dht=Object.prototype.hasOwnProperty;class GWn{constructor(e){this._keys=[],this._keyMap={};let t=0;e.forEach(r=>{let i=zht(r);this._keys.push(i),this._keyMap[i.id]=i,t+=i.weight}),this._keys.forEach(r=>{r.weight/=t})}get(e){return this._keyMap[e]}keys(){return this._keys}toJSON(){return JSON.stringify(this._keys)}}function zht(n){let e=null,t=null,r=null,i=1,o=null;if(mv(n)||K9(n))r=n,e=$ht(n),t=v2e(n);else{if(!Dht.call(n,"name"))throw new Error(XWn("name"));const s=n.name;if(r=s,Dht.call(n,"weight")&&(i=n.weight,i<=0))throw new Error(VWn(s));e=$ht(s),t=v2e(s),o=n.getFn}return{path:e,id:t,weight:i,src:r,getFn:o}}function $ht(n){return K9(n)?n:n.split(".")}function v2e(n){return K9(n)?n.join("."):n}function qWn(n,e){let t=[],r=!1;const i=(o,s,a)=>{if(e2(o))if(!s[a])t.push(o);else{let c=s[a];const l=o[c];if(!e2(l))return;if(a===s.length-1&&(mv(l)||kht(l)||BWn(l)))t.push(FWn(l));else if(K9(l)){r=!0;for(let u=0,d=l.length;u<d;u+=1)i(l[u],s,a+1)}else s.length&&i(l,s,a+1)}};return i(n,mv(e)?e.split("."):e,0),r?t:t[0]}var Do={...{isCaseSensitive:!1,ignoreDiacritics:!1,includeScore:!1,keys:[],shouldSort:!0,sortFn:(n,e)=>n.score===e.score?n.idx<e.idx?-1:1:n.score<e.score?-1:1},...{includeMatches:!1,findAllMatches:!1,minMatchCharLength:1},...{location:0,threshold:.6,distance:100},...{useExtendedSearch:!1,getFn:qWn,ignoreLocation:!1,ignoreFieldNorm:!1,fieldNormWeight:1}};const WWn=/[^ ]+/g;function ZWn(n=1,e=3){const t=new Map,r=Math.pow(10,e);return{get(i){const o=i.match(WWn).length;if(t.has(o))return t.get(o);const s=1/Math.pow(o,.5*n),a=parseFloat(Math.round(s*r)/r);return t.set(o,a),a},clear(){t.clear()}}}class w2e{constructor({getFn:e=Do.getFn,fieldNormWeight:t=Do.fieldNormWeight}={}){this.norm=ZWn(t,3),this.getFn=e,this.isCreated=!1,this.setIndexRecords()}setSources(e=[]){this.docs=e}setIndexRecords(e=[]){this.records=e}setKeys(e=[]){this.keys=e,this._keysMap={},e.forEach((t,r)=>{this._keysMap[t.id]=r})}create(){this.isCreated||!this.docs.length||(this.isCreated=!0,mv(this.docs[0])?this.docs.forEach((e,t)=>{this._addString(e,t)}):this.docs.forEach((e,t)=>{this._addObject(e,t)}),this.norm.clear())}add(e){const t=this.size();mv(e)?this._addString(e,t):this._addObject(e,t)}removeAt(e){this.records.splice(e,1);for(let t=e,r=this.size();t<r;t+=1)this.records[t].i-=1}getValueForItemAtKeyId(e,t){return e[this._keysMap[t]]}size(){return this.records.length}_addString(e,t){if(!e2(e)||b2e(e))return;let r={v:e,i:t,n:this.norm.get(e)};this.records.push(r)}_addObject(e,t){let r={i:t,$:{}};this.keys.forEach((i,o)=>{let s=i.getFn?i.getFn(e):this.getFn(e,i.path);if(e2(s)){if(K9(s)){let a=[];const c=[{nestedArrIndex:-1,value:s}];for(;c.length;){const{nestedArrIndex:l,value:u}=c.pop();if(e2(u))if(mv(u)&&!b2e(u)){let d={v:u,i:l,n:this.norm.get(u)};a.push(d)}else K9(u)&&u.forEach((d,h)=>{c.push({nestedArrIndex:h,value:d})})}r.$[o]=a}else if(mv(s)&&!b2e(s)){let a={v:s,n:this.norm.get(s)};r.$[o]=a}}}),this.records.push(r)}toJSON(){return{keys:this.keys,records:this.records}}}function Fht(n,e,{getFn:t=Do.getFn,fieldNormWeight:r=Do.fieldNormWeight}={}){const i=new w2e({getFn:t,fieldNormWeight:r});return i.setKeys(n.map(zht)),i.setSources(e),i.create(),i}function KWn(n,{getFn:e=Do.getFn,fieldNormWeight:t=Do.fieldNormWeight}={}){const{keys:r,records:i}=n,o=new w2e({getFn:e,fieldNormWeight:t});return o.setKeys(r),o.setIndexRecords(i),o}function pq(n,{errors:e=0,currentLocation:t=0,expectedLocation:r=0,distance:i=Do.distance,ignoreLocation:o=Do.ignoreLocation}={}){const s=e/n.length;if(o)return s;const a=Math.abs(r-t);return i?s+a/i:a?1:s}function QWn(n=[],e=Do.minMatchCharLength){let t=[],r=-1,i=-1,o=0;for(let s=n.length;o<s;o+=1){let a=n[o];a&&r===-1?r=o:!a&&r!==-1&&(i=o-1,i-r+1>=e&&t.push([r,i]),r=-1)}return n[o-1]&&o-r>=e&&t.push([r,o-1]),t}const ZS=32;function JWn(n,e,t,{location:r=Do.location,distance:i=Do.distance,threshold:o=Do.threshold,findAllMatches:s=Do.findAllMatches,minMatchCharLength:a=Do.minMatchCharLength,includeMatches:c=Do.includeMatches,ignoreLocation:l=Do.ignoreLocation}={}){if(e.length>ZS)throw new Error(YWn(ZS));const u=e.length,d=n.length,h=Math.max(0,Math.min(r,d));let f=o,p=h;const m=a>1||c,g=m?Array(d):[];let y;for(;(y=n.indexOf(e,p))>-1;){let E=pq(e,{currentLocation:y,expectedLocation:h,distance:i,ignoreLocation:l});if(f=Math.min(E,f),p=y+u,m){let C=0;for(;C<u;)g[y+C]=1,C+=1}}p=-1;let _=[],x=1,b=u+d;const w=1<<u-1;for(let E=0;E<u;E+=1){let C=0,A=b;for(;C<A;)pq(e,{errors:E,currentLocation:h+A,expectedLocation:h,distance:i,ignoreLocation:l})<=f?C=A:b=A,A=Math.floor((b-C)/2+C);b=A;let R=Math.max(1,h-A+1),L=s?d:Math.min(h+A,d)+u,O=Array(L+2);O[L+1]=(1<<E)-1;for(let B=L;B>=R;B-=1){let j=B-1,G=t[n.charAt(j)];if(m&&(g[j]=+!!G),O[B]=(O[B+1]<<1|1)&G,E&&(O[B]|=(_[B+1]|_[B])<<1|1|_[B+1]),O[B]&w&&(x=pq(e,{errors:E,currentLocation:j,expectedLocation:h,distance:i,ignoreLocation:l}),x<=f)){if(f=x,p=j,p<=h)break;R=Math.max(1,2*h-p)}}if(pq(e,{errors:E+1,currentLocation:h,expectedLocation:h,distance:i,ignoreLocation:l})>f)break;_=O}const S={isMatch:p>=0,score:Math.max(.001,x)};if(m){const E=QWn(g,a);E.length?c&&(S.indices=E):S.isMatch=!1}return S}function eZn(n){let e={};for(let t=0,r=n.length;t<r;t+=1){const i=n.charAt(t);e[i]=(e[i]||0)|1<<r-t-1}return e}const fq=String.prototype.normalize?(n=>n.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,"")):(n=>n);class Bht{constructor(e,{location:t=Do.location,threshold:r=Do.threshold,distance:i=Do.distance,includeMatches:o=Do.includeMatches,findAllMatches:s=Do.findAllMatches,minMatchCharLength:a=Do.minMatchCharLength,isCaseSensitive:c=Do.isCaseSensitive,ignoreDiacritics:l=Do.ignoreDiacritics,ignoreLocation:u=Do.ignoreLocation}={}){if(this.options={location:t,threshold:r,distance:i,includeMatches:o,findAllMatches:s,minMatchCharLength:a,isCaseSensitive:c,ignoreDiacritics:l,ignoreLocation:u},e=c?e:e.toLowerCase(),e=l?fq(e):e,this.pattern=e,this.chunks=[],!this.pattern.length)return;const d=(f,p)=>{this.chunks.push({pattern:f,alphabet:eZn(f),startIndex:p})},h=this.pattern.length;if(h>ZS){let f=0;const p=h%ZS,m=h-p;for(;f<m;)d(this.pattern.substr(f,ZS),f),f+=ZS;if(p){const g=h-ZS;d(this.pattern.substr(g),g)}}else d(this.pattern,0)}searchIn(e){const{isCaseSensitive:t,ignoreDiacritics:r,includeMatches:i}=this.options;if(e=t?e:e.toLowerCase(),e=r?fq(e):e,this.pattern===e){let m={isMatch:!0,score:0};return i&&(m.indices=[[0,e.length-1]]),m}const{location:o,distance:s,threshold:a,findAllMatches:c,minMatchCharLength:l,ignoreLocation:u}=this.options;let d=[],h=0,f=!1;this.chunks.forEach(({pattern:m,alphabet:g,startIndex:y})=>{const{isMatch:_,score:x,indices:b}=JWn(e,m,g,{location:o+y,distance:s,threshold:a,findAllMatches:c,minMatchCharLength:l,includeMatches:i,ignoreLocation:u});_&&(f=!0),h+=x,_&&b&&(d=[...d,...b])});let p={isMatch:f,score:f?h/this.chunks.length:1};return f&&i&&(p.indices=d),p}}class D8{constructor(e){this.pattern=e}static isMultiMatch(e){return jht(e,this.multiRegex)}static isSingleMatch(e){return jht(e,this.singleRegex)}search(){}}function jht(n,e){const t=n.match(e);return t?t[1]:null}class tZn extends D8{constructor(e){super(e)}static get type(){return"exact"}static get multiRegex(){return/^="(.*)"$/}static get singleRegex(){return/^=(.*)$/}search(e){const t=e===this.pattern;return{isMatch:t,score:t?0:1,indices:[0,this.pattern.length-1]}}}class nZn extends D8{constructor(e){super(e)}static get type(){return"inverse-exact"}static get multiRegex(){return/^!"(.*)"$/}static get singleRegex(){return/^!(.*)$/}search(e){const r=e.indexOf(this.pattern)===-1;return{isMatch:r,score:r?0:1,indices:[0,e.length-1]}}}class rZn extends D8{constructor(e){super(e)}static get type(){return"prefix-exact"}static get multiRegex(){return/^\^"(.*)"$/}static get singleRegex(){return/^\^(.*)$/}search(e){const t=e.startsWith(this.pattern);return{isMatch:t,score:t?0:1,indices:[0,this.pattern.length-1]}}}class iZn extends D8{constructor(e){super(e)}static get type(){return"inverse-prefix-exact"}static get multiRegex(){return/^!\^"(.*)"$/}static get singleRegex(){return/^!\^(.*)$/}search(e){const t=!e.startsWith(this.pattern);return{isMatch:t,score:t?0:1,indices:[0,e.length-1]}}}class oZn extends D8{constructor(e){super(e)}static get type(){return"suffix-exact"}static get multiRegex(){return/^"(.*)"\$$/}static get singleRegex(){return/^(.*)\$$/}search(e){const t=e.endsWith(this.pattern);return{isMatch:t,score:t?0:1,indices:[e.length-this.pattern.length,e.length-1]}}}class sZn extends D8{constructor(e){super(e)}static get type(){return"inverse-suffix-exact"}static get multiRegex(){return/^!"(.*)"\$$/}static get singleRegex(){return/^!(.*)\$$/}search(e){const t=!e.endsWith(this.pattern);return{isMatch:t,score:t?0:1,indices:[0,e.length-1]}}}class Uht extends D8{constructor(e,{location:t=Do.location,threshold:r=Do.threshold,distance:i=Do.distance,includeMatches:o=Do.includeMatches,findAllMatches:s=Do.findAllMatches,minMatchCharLength:a=Do.minMatchCharLength,isCaseSensitive:c=Do.isCaseSensitive,ignoreDiacritics:l=Do.ignoreDiacritics,ignoreLocation:u=Do.ignoreLocation}={}){super(e),this._bitapSearch=new Bht(e,{location:t,threshold:r,distance:i,includeMatches:o,findAllMatches:s,minMatchCharLength:a,isCaseSensitive:c,ignoreDiacritics:l,ignoreLocation:u})}static get type(){return"fuzzy"}static get multiRegex(){return/^"(.*)"$/}static get singleRegex(){return/^(.*)$/}search(e){return this._bitapSearch.searchIn(e)}}class Hht extends D8{constructor(e){super(e)}static get type(){return"include"}static get multiRegex(){return/^'"(.*)"$/}static get singleRegex(){return/^'(.*)$/}search(e){let t=0,r;const i=[],o=this.pattern.length;for(;(r=e.indexOf(this.pattern,t))>-1;)t=r+o,i.push([r,t-1]);const s=!!i.length;return{isMatch:s,score:s?0:1,indices:i}}}const S2e=[tZn,Hht,rZn,iZn,sZn,oZn,nZn,Uht],Yht=S2e.length,aZn=/ +(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/,cZn="|";function lZn(n,e={}){return n.split(cZn).map(t=>{let r=t.trim().split(aZn).filter(o=>o&&!!o.trim()),i=[];for(let o=0,s=r.length;o<s;o+=1){const a=r[o];let c=!1,l=-1;for(;!c&&++l<Yht;){const u=S2e[l];let d=u.isMultiMatch(a);d&&(i.push(new u(d,e)),c=!0)}if(!c)for(l=-1;++l<Yht;){const u=S2e[l];let d=u.isSingleMatch(a);if(d){i.push(new u(d,e));break}}}return i})}const uZn=new Set([Uht.type,Hht.type]);class dZn{constructor(e,{isCaseSensitive:t=Do.isCaseSensitive,ignoreDiacritics:r=Do.ignoreDiacritics,includeMatches:i=Do.includeMatches,minMatchCharLength:o=Do.minMatchCharLength,ignoreLocation:s=Do.ignoreLocation,findAllMatches:a=Do.findAllMatches,location:c=Do.location,threshold:l=Do.threshold,distance:u=Do.distance}={}){this.query=null,this.options={isCaseSensitive:t,ignoreDiacritics:r,includeMatches:i,minMatchCharLength:o,findAllMatches:a,ignoreLocation:s,location:c,threshold:l,distance:u},e=t?e:e.toLowerCase(),e=r?fq(e):e,this.pattern=e,this.query=lZn(this.pattern,this.options)}static condition(e,t){return t.useExtendedSearch}searchIn(e){const t=this.query;if(!t)return{isMatch:!1,score:1};const{includeMatches:r,isCaseSensitive:i,ignoreDiacritics:o}=this.options;e=i?e:e.toLowerCase(),e=o?fq(e):e;let s=0,a=[],c=0;for(let l=0,u=t.length;l<u;l+=1){const d=t[l];a.length=0,s=0;for(let h=0,f=d.length;h<f;h+=1){const p=d[h],{isMatch:m,indices:g,score:y}=p.search(e);if(m){if(s+=1,c+=y,r){const _=p.constructor.type;uZn.has(_)?a=[...a,...g]:a.push(g)}}else{c=0,s=0,a.length=0;break}}if(s){let h={isMatch:!0,score:c/s};return r&&(h.indices=a),h}}return{isMatch:!1,score:1}}}const M2e=[];function hZn(...n){M2e.push(...n)}function E2e(n,e){for(let t=0,r=M2e.length;t<r;t+=1){let i=M2e[t];if(i.condition(n,e))return new i(n,e)}return new Bht(n,e)}const mq={AND:"$and",OR:"$or"},T2e={PATH:"$path",PATTERN:"$val"},C2e=n=>!!(n[mq.AND]||n[mq.OR]),pZn=n=>!!n[T2e.PATH],fZn=n=>!K9(n)&&Oht(n)&&!C2e(n),Xht=n=>({[mq.AND]:Object.keys(n).map(e=>({[e]:n[e]}))});function Vht(n,e,{auto:t=!0}={}){const r=i=>{let o=Object.keys(i);const s=pZn(i);if(!s&&o.length>1&&!C2e(i))return r(Xht(i));if(fZn(i)){const c=s?i[T2e.PATH]:o[0],l=s?i[T2e.PATTERN]:i[c];if(!mv(l))throw new Error(HWn(c));const u={keyId:v2e(c),pattern:l};return t&&(u.searcher=E2e(l,e)),u}let a={children:[],operator:o[0]};return o.forEach(c=>{const l=i[c];K9(l)&&l.forEach(u=>{a.children.push(r(u))})}),a};return C2e(n)||(n=Xht(n)),r(n)}function mZn(n,{ignoreFieldNorm:e=Do.ignoreFieldNorm}){n.forEach(t=>{let r=1;t.matches.forEach(({key:i,norm:o,score:s})=>{const a=i?i.weight:null;r*=Math.pow(s===0&&a?Number.EPSILON:s,(a||1)*(e?1:o))}),t.score=r})}function yZn(n,e){const t=n.matches;e.matches=[],e2(t)&&t.forEach(r=>{if(!e2(r.indices)||!r.indices.length)return;const{indices:i,value:o}=r;let s={indices:i,value:o};r.key&&(s.key=r.key.src),r.idx>-1&&(s.refIndex=r.idx),e.matches.push(s)})}function gZn(n,e){e.score=n.score}function _Zn(n,e,{includeMatches:t=Do.includeMatches,includeScore:r=Do.includeScore}={}){const i=[];return t&&i.push(yZn),r&&i.push(gZn),n.map(o=>{const{idx:s}=o,a={item:e[s],refIndex:s};return i.length&&i.forEach(c=>{c(o,a)}),a})}class HP{constructor(e,t={},r){this.options={...Do,...t},this.options.useExtendedSearch,this._keyStore=new GWn(this.options.keys),this.setCollection(e,r)}setCollection(e,t){if(this._docs=e,t&&!(t instanceof w2e))throw new Error(UWn);this._myIndex=t||Fht(this.options.keys,this._docs,{getFn:this.options.getFn,fieldNormWeight:this.options.fieldNormWeight})}add(e){e2(e)&&(this._docs.push(e),this._myIndex.add(e))}remove(e=()=>!1){const t=[];for(let r=0,i=this._docs.length;r<i;r+=1){const o=this._docs[r];e(o,r)&&(this.removeAt(r),r-=1,i-=1,t.push(o))}return t}removeAt(e){this._docs.splice(e,1),this._myIndex.removeAt(e)}getIndex(){return this._myIndex}search(e,{limit:t=-1}={}){const{includeMatches:r,includeScore:i,shouldSort:o,sortFn:s,ignoreFieldNorm:a}=this.options;let c=mv(e)?mv(this._docs[0])?this._searchStringList(e):this._searchObjectList(e):this._searchLogical(e);return mZn(c,{ignoreFieldNorm:a}),o&&c.sort(s),kht(t)&&t>-1&&(c=c.slice(0,t)),_Zn(c,this._docs,{includeMatches:r,includeScore:i})}_searchStringList(e){const t=E2e(e,this.options),{records:r}=this._myIndex,i=[];return r.forEach(({v:o,i:s,n:a})=>{if(!e2(o))return;const{isMatch:c,score:l,indices:u}=t.searchIn(o);c&&i.push({item:o,idx:s,matches:[{score:l,value:o,norm:a,indices:u}]})}),i}_searchLogical(e){const t=Vht(e,this.options),r=(a,c,l)=>{if(!a.children){const{keyId:d,searcher:h}=a,f=this._findMatches({key:this._keyStore.get(d),value:this._myIndex.getValueForItemAtKeyId(c,d),searcher:h});return f&&f.length?[{idx:l,item:c,matches:f}]:[]}const u=[];for(let d=0,h=a.children.length;d<h;d+=1){const f=a.children[d],p=r(f,c,l);if(p.length)u.push(...p);else if(a.operator===mq.AND)return[]}return u},i=this._myIndex.records,o={},s=[];return i.forEach(({$:a,i:c})=>{if(e2(a)){let l=r(t,a,c);l.length&&(o[c]||(o[c]={idx:c,item:a,matches:[]},s.push(o[c])),l.forEach(({matches:u})=>{o[c].matches.push(...u)}))}}),s}_searchObjectList(e){const t=E2e(e,this.options),{keys:r,records:i}=this._myIndex,o=[];return i.forEach(({$:s,i:a})=>{if(!e2(s))return;let c=[];r.forEach((l,u)=>{c.push(...this._findMatches({key:l,value:s[u],searcher:t}))}),c.length&&o.push({idx:a,item:s,matches:c})}),o}_findMatches({key:e,value:t,searcher:r}){if(!e2(t))return[];let i=[];if(K9(t))t.forEach(({v:o,i:s,n:a})=>{if(!e2(o))return;const{isMatch:c,score:l,indices:u}=r.searchIn(o);c&&i.push({score:l,key:e,value:o,idx:s,norm:a,indices:u})});else{const{v:o,n:s}=t,{isMatch:a,score:c,indices:l}=r.searchIn(o);a&&i.push({score:c,key:e,value:o,norm:s,indices:l})}return i}}HP.version="7.1.0",HP.createIndex=Fht,HP.parseIndex=KWn,HP.config=Do,HP.parseQuery=Vht,hZn(dZn);let P2e=null,WO=null,A2e=null;const xZn=async()=>P2e||WO||(WO=fetch("https://kicad-mod-cache.tscircuit.com/kicad_files.json").then(n=>n.json()).then(n=>(P2e=n,WO=null,n)),WO),bZn=async(n,e=20)=>{const t=await xZn();return A2e||(A2e=new HP(t)),A2e.search(n).slice(0,e).map(r=>r.item)},vZn=n=>{const e=n.replace(".pretty/",":").replace(".kicad_mod",""),t=`kicad:${e}`;return{path:n,qualifiedName:t,description:e}},wZn=()=>{const[n,e]=q.useState([]),[t,r]=q.useState(!1),[i,o]=q.useState(null),[s,a]=q.useState(!1),c=q.useCallback(async u=>{const d=u.trim();if(!d)return[];r(!0),o(null);try{const f=(await bZn(d,20)).map(p=>({source:"kicad",footprint:vZn(p)}));return e(f),f}catch(h){return console.error("Error searching KiCad footprints",h),e([]),o(h instanceof Error?h.message:"Failed to search KiCad footprints"),[]}finally{r(!1),a(!0)}},[]),l=q.useCallback(()=>{e([]),r(!1),o(null),a(!1)},[]);return{results:n,isSearching:t,error:i,hasSearched:s,search:c,reset:l}},SZn={dialog:101},MZn=({onTscircuitPackageSelected:n,onJlcpcbComponentTsxLoaded:e,onKicadStringSelected:t})=>{const r=[];return n&&r.push("tscircuit.com"),e&&r.push("jlcpcb"),t&&r.push("kicad"),r},EZn=({isOpen:n,onClose:e,jlcpcbProxyRequestHeaders:t,onKicadStringSelected:r,onTscircuitPackageSelected:i,onJlcpcbComponentTsxLoaded:o,jlcpcbProxyApiBase:s,tscircuitSessionToken:a})=>{rq();const c=q.useMemo(()=>MZn({onKicadStringSelected:r,onTscircuitPackageSelected:i,onJlcpcbComponentTsxLoaded:o}),[r,i,o]),l=c.length>0,u=c.length===1,[d,h]=q.useState(c[0]??"tscircuit.com"),[f,p]=q.useState(""),[m,g]=q.useState(null),{results:y,isSearching:_,error:x,hasSearched:b,search:w,reset:S}=LWn({sessionToken:a}),{results:E,isSearching:C,error:A,hasSearched:R,search:L,reset:O}=zWn(),{results:F,isSearching:B,error:j,hasSearched:G,search:W,reset:Q}=wZn(),{details:ne,isLoading:ue,fetchDetails:te,reset:re}=kWn(),[se,ce]=q.useState(null),[fe,Me]=q.useState(!1),[Pe,Ne]=q.useState("pcb"),[me,Se]=q.useState(null),[ye,He]=q.useState(!1);q.useEffect(()=>{Se(null)},[m]);const Ye=q.useCallback(()=>{S(),O(),Q(),g(null)},[O,Q,S]);q.useEffect(()=>{n||(Ye(),p(""),Me(!1),ce(null),Se(null))},[n,Ye]),q.useEffect(()=>{p(""),g(null),d==="tscircuit.com"?S():d==="jlcpcb"?O():d==="kicad"&&Q()},[d,O,Q,S]);const We=Be=>{g(Be),ce(Be),Ne("pcb"),Me(!0),re();const Xe=Be.package.org_owner_tscircuit_handle,et=Be.package.unscoped_name;if(Xe&&et){const rt=et.split("/").pop()??et;te(Xe,rt)}},ge=async()=>{f.trim()&&(g(null),d==="tscircuit.com"?await w(f):d==="jlcpcb"?await L(f):d==="kicad"&&await W(f))},Ze=async Be=>{try{if(Se(null),He(!0),Be.source==="kicad"){if(!r)throw new Error("KiCad handler not provided");await r({result:Be,footprint:Be.footprint.qualifiedName})}else if(Be.source==="jlcpcb"){if(!o)throw new Error("JLCPCB handler not provided");const Xe=await MWn(Be.component.partNumber,{headers:t,apiBase:s});await o({result:Be,tsx:Xe})}else if(Be.source==="tscircuit.com"){if(!i)throw new Error("tscircuit package handler not provided");const Xe=Be.package.org_owner_tscircuit_handle,et=Be.package.unscoped_name;if(!Xe||!et)throw new Error("Missing package metadata");const rt=et.split("/").pop()??et,at=`@tsci/${Xe}.${rt}`;await i({result:Be,fullPackageName:at})}return!0}catch(Xe){return console.error("Failed to import component",Xe),Se(Xe instanceof Error?Xe.message:"Failed to import component"),!1}finally{He(!1)}};let $e=[],ke=!1,je=null,Re=!1;d==="tscircuit.com"?($e=y,ke=_,je=x,Re=b):d==="jlcpcb"?($e=E,ke=C,je=A,Re=R):d==="kicad"&&($e=F,ke=B,je=j,Re=G);const be=async()=>{if(!m)return;await Ze(m)&&(e(),Ye(),p(""))},Ce=Be=>{Be||e()},Te=Be=>{Me(Be),Be||ce(null)};return V.jsxs(jP,{open:n,onOpenChange:Ce,children:[V.jsxs(GS,{style:{width:"calc(100vw - 2rem)",zIndex:SZn.dialog},className:"rf-rounded-sm rf-max-h-[90vh] rf-overflow-y-auto rf-overflow-x-hidden rf-flex rf-flex-col",children:[V.jsxs(qS,{children:[V.jsxs(WS,{className:"rf-text-lg sm:rf-text-xl",children:["Import ",u?hq[d].label:""," ","Component"]}),V.jsx(UP,{className:"rf-text-sm",children:l?"Search for components from available sources.":"Import options are disabled because no handlers were provided."})]}),l?V.jsxs(Gse,{value:d,onValueChange:Be=>h(Be),className:"rf-min-w-0 rf-w-full",children:[!u&&V.jsx(yH,{className:"rf-flex rf-w-full rf-gap-2",children:c.map(Be=>V.jsx(Rb,{value:Be,className:"rf-flex-1 rf-text-xs sm:rf-text-sm",children:hq[Be].label},Be))}),V.jsx(EWn,{query:f,placeholder:hq[d].placeholder,isSearching:ke,onQueryChange:p,onSubmit:ge}),V.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:ke?V.jsxs("div",{className:"rf-p-8 rf-text-center rf-text-zinc-500",children:[V.jsx(D9,{className:"rf-h-8 rf-w-8 rf-animate-spin rf-mx-auto rf-mb-2"}),V.jsx("p",{children:"Searching..."})]}):$e.length>0?V.jsx(NWn,{results:$e,selected:m,onSelect:g,onShowDetails:d==="tscircuit.com"?We:void 0}):V.jsx("div",{className:"rf-p-8 rf-text-center rf-text-zinc-500",children:je?`Error: ${je}`:Re?hq[d].emptyMessage:"Enter a search term to find components"})})]}):null,me?V.jsx("div",{className:"rf-text-sm rf-text-red-600 rf-mt-2",children:me}):null,V.jsxs(qO,{className:"rf-flex rf-flex-col sm:rf-flex-row rf-gap-2",children:[V.jsx(hc,{variant:"outline",onClick:e,className:"rf-order-2 sm:rf-order-1",children:"Cancel"}),V.jsx(hc,{onClick:be,disabled:!m||ye,className:"rf-order-1 sm:rf-order-2",children:ye?V.jsx(D9,{className:"rf-h-4 rf-w-4 rf-animate-spin"}):"Import"})]})]}),V.jsx(IWn,{packageResult:se,isOpen:fe,onOpenChange:Te,isLoading:ue,details:ne,previewTab:Pe,onPreviewTabChange:Be=>Ne(Be),isSubmitting:ye,onImport:()=>{se&&Ze(se).then(Be=>{Be&&(Me(!1),e(),Ye(),p(""))})}})]})},TZn=n=>{const e=n.match(/export const (\w+) =/);if(!e)throw new Error("Could not determine component name from TSX contents");return e[1]},Ght=n=>{const e=Ju(s=>s.pushEvent),t=Ju(s=>s.upsertFile),r=async({result:s,fullPackageName:a})=>{const l=s.package.unscoped_name??s.package.name;await ds.promise(e({event_type:"INSTALL_PACKAGE",full_package_name:a}),{loading:`Requesting install for "${l}"`,success:`Install requested for "${l}"`,error:u=>`Failed to request install: ${u instanceof Error?u.message:String(u)}`})},i=async({footprint:s})=>{await ds.promise(navigator.clipboard.writeText(s),{loading:`Copying "${s}"`,success:`Copied "${s}" to clipboard`,error:a=>`Failed to copy footprint: ${a instanceof Error?a.message:String(a)}`})},o=async({result:s,tsx:a})=>{const l=`imports/${TZn(a)}.tsx`;await ds.promise(t(l,a),{loading:`Importing ${s.component.partNumber}`,success:`Imported to "${l}"`,error:u=>`Failed to import component: ${u instanceof Error?u.message:String(u)}`})};return V.jsx(EZn,{...n,onTscircuitPackageSelected:r,onKicadStringSelected:i,onJlcpcbComponentTsxLoaded:o})};Ght.displayName="ImportComponentDialogForCli";var R2e={exports:{}},qht;function CZn(){return qht||(qht=1,(function(n,e){var t={env:{},version:""};(function(r){n.exports=r()})(function(){return(function r(i,o,s){function a(u,d){if(!o[u]){if(!i[u]){var h=typeof B6=="function"&&B6;if(!d&&h)return h(u,!0);if(c)return c(u,!0);var f=new Error("Cannot find module '"+u+"'");throw f.code="MODULE_NOT_FOUND",f}var p=o[u]={exports:{}};i[u][0].call(p.exports,function(m){var g=i[u][1][m];return a(g||m)},p,p.exports,r,i,o,s)}return o[u].exports}for(var c=typeof B6=="function"&&B6,l=0;l<s.length;l++)a(s[l]);return a})({1:[function(r,i,o){var s=r("./utils"),a=r("./support"),c="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";o.encode=function(l){for(var u,d,h,f,p,m,g,y=[],_=0,x=l.length,b=x,w=s.getTypeOf(l)!=="string";_<l.length;)b=x-_,h=w?(u=l[_++],d=_<x?l[_++]:0,_<x?l[_++]:0):(u=l.charCodeAt(_++),d=_<x?l.charCodeAt(_++):0,_<x?l.charCodeAt(_++):0),f=u>>2,p=(3&u)<<4|d>>4,m=1<b?(15&d)<<2|h>>6:64,g=2<b?63&h:64,y.push(c.charAt(f)+c.charAt(p)+c.charAt(m)+c.charAt(g));return y.join("")},o.decode=function(l){var u,d,h,f,p,m,g=0,y=0,_="data:";if(l.substr(0,_.length)===_)throw new Error("Invalid base64 input, it looks like a data url.");var x,b=3*(l=l.replace(/[^A-Za-z0-9+/=]/g,"")).length/4;if(l.charAt(l.length-1)===c.charAt(64)&&b--,l.charAt(l.length-2)===c.charAt(64)&&b--,b%1!=0)throw new Error("Invalid base64 input, bad content length.");for(x=a.uint8array?new Uint8Array(0|b):new Array(0|b);g<l.length;)u=c.indexOf(l.charAt(g++))<<2|(f=c.indexOf(l.charAt(g++)))>>4,d=(15&f)<<4|(p=c.indexOf(l.charAt(g++)))>>2,h=(3&p)<<6|(m=c.indexOf(l.charAt(g++))),x[y++]=u,p!==64&&(x[y++]=d),m!==64&&(x[y++]=h);return x}},{"./support":30,"./utils":32}],2:[function(r,i,o){var s=r("./external"),a=r("./stream/DataWorker"),c=r("./stream/Crc32Probe"),l=r("./stream/DataLengthProbe");function u(d,h,f,p,m){this.compressedSize=d,this.uncompressedSize=h,this.crc32=f,this.compression=p,this.compressedContent=m}u.prototype={getContentWorker:function(){var d=new a(s.Promise.resolve(this.compressedContent)).pipe(this.compression.uncompressWorker()).pipe(new l("data_length")),h=this;return d.on("end",function(){if(this.streamInfo.data_length!==h.uncompressedSize)throw new Error("Bug : uncompressed data size mismatch")}),d},getCompressedWorker:function(){return new a(s.Promise.resolve(this.compressedContent)).withStreamInfo("compressedSize",this.compressedSize).withStreamInfo("uncompressedSize",this.uncompressedSize).withStreamInfo("crc32",this.crc32).withStreamInfo("compression",this.compression)}},u.createWorkerFrom=function(d,h,f){return d.pipe(new c).pipe(new l("uncompressedSize")).pipe(h.compressWorker(f)).pipe(new l("compressedSize")).withStreamInfo("compression",h)},i.exports=u},{"./external":6,"./stream/Crc32Probe":25,"./stream/DataLengthProbe":26,"./stream/DataWorker":27}],3:[function(r,i,o){var s=r("./stream/GenericWorker");o.STORE={magic:"\0\0",compressWorker:function(){return new s("STORE compression")},uncompressWorker:function(){return new s("STORE decompression")}},o.DEFLATE=r("./flate")},{"./flate":7,"./stream/GenericWorker":28}],4:[function(r,i,o){var s=r("./utils"),a=(function(){for(var c,l=[],u=0;u<256;u++){c=u;for(var d=0;d<8;d++)c=1&c?3988292384^c>>>1:c>>>1;l[u]=c}return l})();i.exports=function(c,l){return c!==void 0&&c.length?s.getTypeOf(c)!=="string"?(function(u,d,h,f){var p=a,m=f+h;u^=-1;for(var g=f;g<m;g++)u=u>>>8^p[255&(u^d[g])];return-1^u})(0|l,c,c.length,0):(function(u,d,h,f){var p=a,m=f+h;u^=-1;for(var g=f;g<m;g++)u=u>>>8^p[255&(u^d.charCodeAt(g))];return-1^u})(0|l,c,c.length,0):0}},{"./utils":32}],5:[function(r,i,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(r,i,o){var s=null;s=typeof Promise<"u"?Promise:r("lie"),i.exports={Promise:s}},{lie:37}],7:[function(r,i,o){var s=typeof Uint8Array<"u"&&typeof Uint16Array<"u"&&typeof Uint32Array<"u",a=r("pako"),c=r("./utils"),l=r("./stream/GenericWorker"),u=s?"uint8array":"array";function d(h,f){l.call(this,"FlateWorker/"+h),this._pako=null,this._pakoAction=h,this._pakoOptions=f,this.meta={}}o.magic="\b\0",c.inherits(d,l),d.prototype.processChunk=function(h){this.meta=h.meta,this._pako===null&&this._createPako(),this._pako.push(c.transformTo(u,h.data),!1)},d.prototype.flush=function(){l.prototype.flush.call(this),this._pako===null&&this._createPako(),this._pako.push([],!0)},d.prototype.cleanUp=function(){l.prototype.cleanUp.call(this),this._pako=null},d.prototype._createPako=function(){this._pako=new a[this._pakoAction]({raw:!0,level:this._pakoOptions.level||-1});var h=this;this._pako.onData=function(f){h.push({data:f,meta:h.meta})}},o.compressWorker=function(h){return new d("Deflate",h)},o.uncompressWorker=function(){return new d("Inflate",{})}},{"./stream/GenericWorker":28,"./utils":32,pako:38}],8:[function(r,i,o){function s(p,m){var g,y="";for(g=0;g<m;g++)y+=String.fromCharCode(255&p),p>>>=8;return y}function a(p,m,g,y,_,x){var b,w,S=p.file,E=p.compression,C=x!==u.utf8encode,A=c.transformTo("string",x(S.name)),R=c.transformTo("string",u.utf8encode(S.name)),L=S.comment,O=c.transformTo("string",x(L)),F=c.transformTo("string",u.utf8encode(L)),B=R.length!==S.name.length,j=F.length!==L.length,G="",W="",Q="",ne=S.dir,ue=S.date,te={crc32:0,compressedSize:0,uncompressedSize:0};m&&!g||(te.crc32=p.crc32,te.compressedSize=p.compressedSize,te.uncompressedSize=p.uncompressedSize);var re=0;m&&(re|=8),C||!B&&!j||(re|=2048);var se=0,ce=0;ne&&(se|=16),_==="UNIX"?(ce=798,se|=(function(Me,Pe){var Ne=Me;return Me||(Ne=Pe?16893:33204),(65535&Ne)<<16})(S.unixPermissions,ne)):(ce=20,se|=(function(Me){return 63&(Me||0)})(S.dosPermissions)),b=ue.getUTCHours(),b<<=6,b|=ue.getUTCMinutes(),b<<=5,b|=ue.getUTCSeconds()/2,w=ue.getUTCFullYear()-1980,w<<=4,w|=ue.getUTCMonth()+1,w<<=5,w|=ue.getUTCDate(),B&&(W=s(1,1)+s(d(A),4)+R,G+="up"+s(W.length,2)+W),j&&(Q=s(1,1)+s(d(O),4)+F,G+="uc"+s(Q.length,2)+Q);var fe="";return fe+=`
5688
+ For more information, see https://radix-ui.com/primitives/docs/components/alert-dialog`;return q.useEffect(()=>{document.getElementById(n.current?.getAttribute("aria-describedby"))||console.warn(e)},[e,n]),null},uWn=oht,dWn=sht,yht=aht,ght=cht,_ht=pht,xht=mht,bht=uht,vht=hht;const wht=uWn,hWn=dWn,Sht=q.forwardRef(({className:n,...e},t)=>V.jsx(yht,{className:ai("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",n),...e,ref:t}));Sht.displayName=yht.displayName;const d2e=q.forwardRef(({className:n,...e},t)=>V.jsxs(hWn,{children:[V.jsx(Sht,{}),V.jsx(ght,{ref:t,className:ai("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",n),...e})]}));d2e.displayName=ght.displayName;const h2e=({className:n,...e})=>V.jsx("div",{className:ai("rf-flex rf-flex-col rf-space-y-2 rf-text-center sm:rf-text-left",n),...e});h2e.displayName="AlertDialogHeader";const p2e=({className:n,...e})=>V.jsx("div",{className:ai("rf-flex rf-flex-col-reverse sm:rf-flex-row sm:rf-justify-end sm:rf-space-x-2",n),...e});p2e.displayName="AlertDialogFooter";const f2e=q.forwardRef(({className:n,...e},t)=>V.jsx(bht,{ref:t,className:ai("rf-text-lg rf-font-semibold",n),...e}));f2e.displayName=bht.displayName;const m2e=q.forwardRef(({className:n,...e},t)=>V.jsx(vht,{ref:t,className:ai("rf-text-sm rf-text-zinc-500 dark:rf-text-zinc-400",n),...e}));m2e.displayName=vht.displayName;const pWn=q.forwardRef(({className:n,...e},t)=>V.jsx(_ht,{ref:t,className:ai(sP(),n),...e}));pWn.displayName=_ht.displayName;const y2e=q.forwardRef(({className:n,...e},t)=>V.jsx(xht,{ref:t,className:ai(sP({variant:"outline"}),"rf-mt-2 sm:rf-mt-0",n),...e}));y2e.displayName=xht.displayName;function fWn(n){const e=q.useRef({value:n,previous:n});return q.useMemo(()=>(e.current.value!==n&&(e.current.previous=e.current.value,e.current.value=n),e.current.previous),[n])}var dq="Checkbox",[mWn]=r4(dq),[yWn,g2e]=mWn(dq);function gWn(n){const{__scopeCheckbox:e,checked:t,children:r,defaultChecked:i,disabled:o,form:s,name:a,onCheckedChange:c,required:l,value:u="on",internal_do_not_use_render:d}=n,[h,f]=M3({prop:t,defaultProp:i??!1,onChange:c,caller:dq}),[p,m]=q.useState(null),[g,y]=q.useState(null),_=q.useRef(!1),x=p?!!s||!!p.closest("form"):!0,b={checked:h,disabled:o,setChecked:f,control:p,setControl:m,name:a,form:s,value:u,hasConsumerStoppedPropagationRef:_,required:l,defaultChecked:L8(i)?!1:i,isFormControl:x,bubbleInput:g,setBubbleInput:y};return V.jsx(yWn,{scope:e,...b,children:_Wn(d)?d(b):r})}var Mht="CheckboxTrigger",Eht=q.forwardRef(({__scopeCheckbox:n,onKeyDown:e,onClick:t,...r},i)=>{const{control:o,value:s,disabled:a,checked:c,required:l,setControl:u,setChecked:d,hasConsumerStoppedPropagationRef:h,isFormControl:f,bubbleInput:p}=g2e(Mht,n),m=ed(i,u),g=q.useRef(c);return q.useEffect(()=>{const y=o?.form;if(y){const _=()=>d(g.current);return y.addEventListener("reset",_),()=>y.removeEventListener("reset",_)}},[o,d]),V.jsx(Mc.button,{type:"button",role:"checkbox","aria-checked":L8(c)?"mixed":c,"aria-required":l,"data-state":Rht(c),"data-disabled":a?"":void 0,disabled:a,value:s,...r,ref:m,onKeyDown:Bi(e,y=>{y.key==="Enter"&&y.preventDefault()}),onClick:Bi(t,y=>{d(_=>L8(_)?!0:!_),p&&f&&(h.current=y.isPropagationStopped(),h.current||y.stopPropagation())})})});Eht.displayName=Mht;var _2e=q.forwardRef((n,e)=>{const{__scopeCheckbox:t,name:r,checked:i,defaultChecked:o,required:s,disabled:a,value:c,onCheckedChange:l,form:u,...d}=n;return V.jsx(gWn,{__scopeCheckbox:t,checked:i,defaultChecked:o,disabled:a,required:s,onCheckedChange:l,name:r,form:u,value:c,internal_do_not_use_render:({isFormControl:h})=>V.jsxs(V.Fragment,{children:[V.jsx(Eht,{...d,ref:e,__scopeCheckbox:t}),h&&V.jsx(Aht,{__scopeCheckbox:t})]})})});_2e.displayName=dq;var Tht="CheckboxIndicator",Cht=q.forwardRef((n,e)=>{const{__scopeCheckbox:t,forceMount:r,...i}=n,o=g2e(Tht,t);return V.jsx(Nx,{present:r||L8(o.checked)||o.checked===!0,children:V.jsx(Mc.span,{"data-state":Rht(o.checked),"data-disabled":o.disabled?"":void 0,...i,ref:e,style:{pointerEvents:"none",...n.style}})})});Cht.displayName=Tht;var Pht="CheckboxBubbleInput",Aht=q.forwardRef(({__scopeCheckbox:n,...e},t)=>{const{control:r,hasConsumerStoppedPropagationRef:i,checked:o,defaultChecked:s,required:a,disabled:c,name:l,value:u,form:d,bubbleInput:h,setBubbleInput:f}=g2e(Pht,n),p=ed(t,f),m=fWn(o),g=nrt(r);q.useEffect(()=>{const _=h;if(!_)return;const x=window.HTMLInputElement.prototype,w=Object.getOwnPropertyDescriptor(x,"checked").set,S=!i.current;if(m!==o&&w){const E=new Event("click",{bubbles:S});_.indeterminate=L8(o),w.call(_,L8(o)?!1:o),_.dispatchEvent(E)}},[h,m,o,i]);const y=q.useRef(L8(o)?!1:o);return V.jsx(Mc.input,{type:"checkbox","aria-hidden":!0,defaultChecked:s??y.current,required:a,disabled:c,name:l,value:u,form:d,...e,tabIndex:-1,ref:p,style:{...e.style,...g,position:"absolute",pointerEvents:"none",opacity:0,margin:0,transform:"translateX(-100%)"}})});Aht.displayName=Pht;function _Wn(n){return typeof n=="function"}function L8(n){return n==="indeterminate"}function Rht(n){return L8(n)?"indeterminate":n?"checked":"unchecked"}const GO=q.forwardRef(({className:n,...e},t)=>V.jsx(_2e,{ref:t,className:ai("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",n),...e,children:V.jsx(Cht,{className:ai("rf-flex rf-items-center rf-justify-center rf-text-current"),children:V.jsx(bS,{className:"rf-h-4 rf-w-4"})})}));GO.displayName=_2e.displayName;const jP=a2e,xWn=c2e,Nht=q.forwardRef(({className:n,...e},t)=>V.jsx(lq,{className:ai("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",n),...e,ref:t}));Nht.displayName=lq.displayName;const GS=q.forwardRef(({className:n,children:e,showOverlay:t=!0,...r},i)=>V.jsxs(xWn,{children:[V.jsx(Nht,{className:ai(t?"":"rf-hidden")}),V.jsx(uq,{ref:i,className:ai("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",n),...r,children:e})]}));GS.displayName=uq.displayName;const qS=({className:n,...e})=>V.jsx("div",{className:ai("rf-flex rf-flex-col rf-space-y-2 rf-text-center sm:rf-text-left",n),...e});qS.displayName="DialogHeader";const qO=({className:n,...e})=>V.jsx("div",{className:ai("rf-flex rf-flex-col-reverse sm:rf-flex-row sm:rf-justify-end sm:rf-space-x-2",n),...e});qO.displayName="DialogFooter";const WS=q.forwardRef(({className:n,...e},t)=>V.jsx(l2e,{ref:t,className:ai("rf-text-lg rf-font-semibold",n),...e}));WS.displayName=l2e.displayName;const UP=q.forwardRef(({className:n,...e},t)=>V.jsx(u2e,{ref:t,className:ai("rf-text-sm rf-text-zinc-500 dark:rf-text-zinc-400",n),...e}));UP.displayName=u2e.displayName;const hq={"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"}},bWn="https://cdn.jsdelivr.net/npm/easyeda@latest/dist/browser/index.js";let x2e=null;const vWn=async()=>(x2e||(x2e=import(bWn)),x2e),wWn=async(n,e=10)=>{const t=encodeURIComponent(n),r=await fetch(`https://jlcsearch.tscircuit.com/api/search?limit=${e}&q=${t}`);if(!r.ok)throw new Error(`JLCPCB API error: ${r.status}`);return(await r.json()).components??[]},SWn=n=>({lcscId:n.lcsc,manufacturer:n.mfr,description:n.description,partNumber:`C${n.lcsc}`,package:n.package,price:n.price,stock:n.stock,isBasic:n.is_basic}),MWn=async(n,e)=>{const{fetchEasyEDAComponent:t,convertRawEasyToTsx:r}=await vWn(),i=await t(n,{fetch:(o,s)=>fetch(`${e?.apiBase??M_}/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"]??"",...e?.headers}})});return r({rawEasy:i})},EWn=({query:n,placeholder:e,isSearching:t,onQueryChange:r,onSubmit:i})=>{const o=q.useCallback(s=>{s.key==="Enter"&&(s.preventDefault(),i())},[i]);return V.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2 rf-mt-4",children:[V.jsxs("div",{className:"rf-relative rf-flex-grow",children:[V.jsx(ege,{className:"rf-absolute rf-left-2 rf-top-2.5 rf-h-4 rf-w-4 rf-text-muted-foreground"}),V.jsx(O_e,{placeholder:e,className:"rf-pl-8",spellCheck:!1,autoComplete:"off",value:n,onChange:s=>r(s.target.value),onKeyDown:o})]}),V.jsx(hc,{onClick:i,disabled:t||n.trim().length<1,className:"sm:rf-px-4 rf-px-3",children:t?V.jsx(D9,{className:"rf-h-4 rf-w-4 rf-animate-spin"}):V.jsxs(V.Fragment,{children:[V.jsx(ege,{className:"rf-h-4 rf-w-4 sm:rf-hidden"}),V.jsx("span",{className:"rf-hidden sm:rf-inline",children:"Search"})]})})]})},TWn=new Intl.NumberFormat("en-US",{style:"currency",currency:"USD"}),CWn=n=>TWn.format(n),Iht=n=>{switch(n.source){case"tscircuit.com":{const e=n.package;return`tscircuit-${e.package_id??`${e.org_owner_tscircuit_handle??"unknown"}-${e.unscoped_name??e.name??"package"}`}`}case"jlcpcb":return`jlc-${n.component.lcscId}`;case"kicad":return`kicad-${n.footprint.path}`;default:return"unknown"}},PWn=n=>{switch(n.source){case"tscircuit.com":return n.package.unscoped_name;case"jlcpcb":return n.component.manufacturer;case"kicad":return n.footprint.qualifiedName}},AWn=n=>{switch(n.source){case"tscircuit.com":return n.package.description||(n.package.org_owner_tscircuit_handle?`Component by ${n.package.org_owner_tscircuit_handle}`:void 0);case"jlcpcb":return n.component.description;case"kicad":return n.footprint.description}},RWn=n=>{switch(n.source){case"tscircuit.com":return n.package.name;case"jlcpcb":return n.component.partNumber;case"kicad":return}},NWn=({results:n,selected:e,onSelect:t,onShowDetails:r})=>{const i=e?Iht(e):null;return V.jsx("div",{className:"rf-divide-y rf-w-full rf-overflow-hidden",children:n.map(o=>{const s=Iht(o),a=i===s,c=PWn(o),l=AWn(o),u=RWn(o),d=o.source==="jlcpcb"?o.component.stock:null,h=o.source==="jlcpcb"?o.component.price:null,f=o.source==="jlcpcb"?o.component.isBasic:null;return V.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 ${a?"rf-bg-zinc-100":""}`,onClick:()=>t(o),children:[V.jsxs("div",{className:"rf-min-w-0 rf-overflow-hidden rf-w-full",children:[V.jsxs("div",{className:"rf-flex rf-items-start rf-gap-2 rf-min-w-0",children:[V.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:[c,o.source==="jlcpcb"&&f!=null&&V.jsx("span",{className:`rf-text-xs rf-px-1.5 rf-py-0.5 rf-rounded rf-font-medium rf-flex-shrink-0 ${f?"rf-bg-green-100 rf-text-green-700":"rf-bg-orange-100 rf-text-orange-700"}`,children:f?"Basic":"Extended"}),o.source==="tscircuit.com"&&o.package.is_private&&V.jsx(sPn,{className:"rf-ml-1 rf-h-3 rf-w-3 rf-text-zinc-400 rf-flex-shrink-0"})]}),o.source==="jlcpcb"&&d!=null?V.jsxs("div",{className:"rf-text-xs rf-text-zinc-500 rf-font-medium rf-whitespace-nowrap rf-flex-shrink-0 sm:rf-hidden",children:[d.toLocaleString()," in stock"]}):null]}),V.jsxs("div",{className:"rf-text-xs rf-text-zinc-500 rf-truncate rf-w-full",children:[u?V.jsx("span",{className:"rf-mr-2",children:u}):null,l]})]}),V.jsxs("div",{children:[o.source==="tscircuit.com"&&r?V.jsx("div",{className:"rf-flex-shrink-0 rf-w-full sm:rf-w-auto",children:V.jsx(hc,{variant:"outline",size:"sm",className:"rf-text-xs rf-w-full sm:rf-w-auto",onClick:p=>{p.stopPropagation(),r(o)},children:"See Details"})}):o.source==="jlcpcb"&&d!=null?V.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:[d.toLocaleString()," in stock"]}):null,h!=null&&V.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:CWn(h)})]})]},s)})})},IWn=({packageResult:n,isOpen:e,onOpenChange:t,isLoading:r,details:i,previewTab:o,onPreviewTabChange:s,isSubmitting:a,onImport:c})=>{const l=n?.package??null,u=l?.latest_pcb_preview_image_url,d=l?.latest_sch_preview_image_url,h=l?.latest_cad_preview_image_url,f=l?.unscoped_name?.split("/").pop()??l?.unscoped_name,p=l?.org_owner_tscircuit_handle??void 0,m=p?`https://tscircuit.com/${p}`:void 0,g=p&&f?`https://tscircuit.com/${p}/${f}`:void 0;return V.jsx(jP,{open:e,onOpenChange:t,children:V.jsxs(GS,{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:[V.jsx(qS,{className:"rf-pb-4 rf-border-b",children:V.jsx("div",{className:"rf-flex rf-items-start rf-justify-between rf-gap-4",children:V.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[V.jsx(WS,{className:"rf-text-xl rf-font-semibold rf-truncate",children:f}),V.jsx(UP,{children:l?.description})]})})}),V.jsxs("div",{className:"rf-flex-1 rf-overflow-y-auto rf-py-4 rf-space-y-6",children:[p?V.jsxs("div",{children:[V.jsx("span",{className:"rf-text-xs rf-font-medium rf-text-gray-500 rf-uppercase rf-tracking-wide",children:"Created by"}),V.jsx("div",{className:"rf-mt-1 rf-text-sm rf-font-medium",children:m?V.jsx("a",{href:m,target:"_blank",rel:"noopener noreferrer",className:"rf-text-black hover:rf-underline",children:p}):p})]}):null,(h||u||d)&&V.jsx(V.Fragment,{children:V.jsxs("div",{children:[V.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-mb-4",children:"Preview"}),V.jsxs(Gse,{value:o,onValueChange:y=>s(y),children:[V.jsxs(yH,{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:[u&&V.jsx(Rb,{value:"pcb",children:"PCB"}),d&&V.jsx(Rb,{value:"schematic",children:"Schematic"}),h&&V.jsx(Rb,{value:"3d",children:"3D"})]}),V.jsxs("div",{className:"rf-mt-4",children:[V.jsx(ry,{value:"pcb",className:"rf-border rf-rounded-lg rf-overflow-hidden rf-bg-gray-50",children:u?V.jsx("img",{src:u,alt:`${f??"package"} PCB preview`,className:"rf-w-full rf-h-full rf-object-contain rf-bg-white rf-p-4"}):null}),V.jsx(ry,{value:"schematic",className:"rf-border rf-rounded-lg rf-overflow-hidden rf-bg-gray-50",children:d?V.jsx("img",{src:d,alt:`${f??"package"} schematic preview`,className:"rf-w-full rf-h-full rf-object-contain rf-bg-white rf-p-4"}):null}),V.jsx(ry,{value:"3d",className:"rf-border rf-rounded-lg rf-overflow-hidden rf-bg-gray-50",children:h?V.jsx("img",{src:h,alt:`${f??"package"} 3D preview`,className:"rf-w-full rf-h-full rf-object-contain rf-bg-white rf-p-4"}):null})]})]})]})}),i?.ai_description?V.jsxs("section",{children:[V.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-mb-3",children:"AI Description"}),V.jsx("div",{className:"rf-bg-gray-50 rf-border rf-border-gray-200 rf-rounded-lg rf-p-4",children:V.jsx("p",{className:"rf-text-sm rf-text-gray-700 rf-leading-relaxed",children:i.ai_description})})]}):null,i?.ai_usage_instructions?V.jsxs("section",{children:[V.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-mb-3",children:"Usage Instructions"}),V.jsx("div",{className:"rf-bg-gray-50 rf-border rf-border-gray-200 rf-rounded-lg rf-p-4",children:V.jsx("p",{className:"rf-text-sm rf-text-gray-700 rf-leading-relaxed rf-whitespace-pre-wrap",children:i.ai_usage_instructions})})]}):null,r?V.jsxs("div",{className:"rf-flex rf-justify-center rf-items-center rf-gap-2 rf-text-gray-500",children:[V.jsx(D9,{className:"rf-h-4 rf-w-4 rf-animate-spin"}),V.jsx("span",{className:"rf-text-sm",children:"Loading package details..."})]}):null]}),V.jsxs(qO,{className:"rf-pt-4 rf-border-t rf-flex rf-flex-col sm:rf-flex-row rf-justify-between rf-gap-2",children:[V.jsx("div",{className:"rf-flex-1",children:g?V.jsxs(hc,{variant:"outline",size:"sm",className:"rf-gap-2 rf-w-full sm:rf-w-auto",onClick:()=>window.open(g,"_blank"),children:[V.jsx(JCn,{className:"rf-h-4 rf-w-4"}),"View on tscircuit.com"]}):null}),V.jsxs("div",{className:"rf-flex rf-flex-col sm:rf-flex-row rf-gap-2",children:[V.jsx(hc,{variant:"outline",onClick:()=>t(!1),className:"rf-order-2 sm:rf-order-1",children:"Close"}),V.jsx(hc,{onClick:c,disabled:a,className:"rf-bg-blue-600 hover:rf-bg-blue-700",children:a?V.jsx(D9,{className:"rf-h-4 rf-w-4 rf-animate-spin"}):"Import Component"})]})]})]})})},kWn=()=>{const[n,e]=q.useState(null),[t,r]=q.useState(!1),i=q.useCallback(async(s,a)=>{r(!0);try{const c=await fetch(`https://api.tscircuit.com/packages/get?name=${encodeURIComponent(`${s}/${a}`)}`);if(!c.ok)throw new Error(`Failed to load package details: ${c.status}`);const l=await c.json();e(l.package??null)}catch(c){console.error("Failed to fetch package details",c),e(null)}finally{r(!1)}},[]),o=q.useCallback(()=>{e(null),r(!1)},[]);return{details:n,isLoading:t,fetchDetails:i,reset:o}},OWn=async(n,e)=>{const t={"Content-Type":"application/json"};e&&(t.Authorization=`Bearer ${e}`);const r=await fetch("https://registry-api.tscircuit.com/packages/search",{method:"POST",headers:t,body:JSON.stringify({query:n})});if(!r.ok)throw new Error(`tscircuit registry error: ${r.status}`);return(await r.json()).packages??[]},LWn=({sessionToken:n})=>{const[e,t]=q.useState([]),[r,i]=q.useState(!1),[o,s]=q.useState(null),[a,c]=q.useState(!1),l=q.useCallback(async d=>{const h=d.trim();if(!h)return[];i(!0),s(null);try{const p=(await OWn(h,n)).map(m=>({source:"tscircuit.com",package:m}));return t(p),p}catch(f){return console.error("Error searching tscircuit packages",f),t([]),s(f instanceof Error?f.message:"Failed to search tscircuit packages"),[]}finally{i(!1),c(!0)}},[n]),u=q.useCallback(()=>{t([]),i(!1),s(null),c(!1)},[]);return{results:e,isSearching:r,error:o,hasSearched:a,search:l,reset:u}},DWn=n=>{const e=n.trim();return/^C\d+/i.test(e)?e.replace(/^C/i,""):e},zWn=()=>{const[n,e]=q.useState([]),[t,r]=q.useState(!1),[i,o]=q.useState(null),[s,a]=q.useState(!1),c=q.useCallback(async u=>{const d=DWn(u);if(!d)return[];r(!0),o(null);try{const f=(await wWn(d,10)).map(p=>({source:"jlcpcb",component:SWn(p)}));return e(f),f}catch(h){return console.error("Error searching JLCPCB components",h),e([]),o(h instanceof Error?h.message:"Failed to search JLCPCB components"),[]}finally{r(!1),a(!0)}},[]),l=q.useCallback(()=>{e([]),r(!1),o(null),a(!1)},[]);return{results:n,isSearching:t,error:i,hasSearched:s,search:c,reset:l}};function K9(n){return Array.isArray?Array.isArray(n):Lht(n)==="[object Array]"}function $Wn(n){if(typeof n=="string")return n;let e=n+"";return e=="0"&&1/n==-1/0?"-0":e}function FWn(n){return n==null?"":$Wn(n)}function mv(n){return typeof n=="string"}function kht(n){return typeof n=="number"}function BWn(n){return n===!0||n===!1||jWn(n)&&Lht(n)=="[object Boolean]"}function Oht(n){return typeof n=="object"}function jWn(n){return Oht(n)&&n!==null}function e2(n){return n!=null}function b2e(n){return!n.trim().length}function Lht(n){return n==null?n===void 0?"[object Undefined]":"[object Null]":Object.prototype.toString.call(n)}const UWn="Incorrect 'index' type",HWn=n=>`Invalid value for key ${n}`,YWn=n=>`Pattern length exceeds max of ${n}.`,XWn=n=>`Missing ${n} property in key`,VWn=n=>`Property 'weight' in key '${n}' must be a positive integer`,Dht=Object.prototype.hasOwnProperty;class GWn{constructor(e){this._keys=[],this._keyMap={};let t=0;e.forEach(r=>{let i=zht(r);this._keys.push(i),this._keyMap[i.id]=i,t+=i.weight}),this._keys.forEach(r=>{r.weight/=t})}get(e){return this._keyMap[e]}keys(){return this._keys}toJSON(){return JSON.stringify(this._keys)}}function zht(n){let e=null,t=null,r=null,i=1,o=null;if(mv(n)||K9(n))r=n,e=$ht(n),t=v2e(n);else{if(!Dht.call(n,"name"))throw new Error(XWn("name"));const s=n.name;if(r=s,Dht.call(n,"weight")&&(i=n.weight,i<=0))throw new Error(VWn(s));e=$ht(s),t=v2e(s),o=n.getFn}return{path:e,id:t,weight:i,src:r,getFn:o}}function $ht(n){return K9(n)?n:n.split(".")}function v2e(n){return K9(n)?n.join("."):n}function qWn(n,e){let t=[],r=!1;const i=(o,s,a)=>{if(e2(o))if(!s[a])t.push(o);else{let c=s[a];const l=o[c];if(!e2(l))return;if(a===s.length-1&&(mv(l)||kht(l)||BWn(l)))t.push(FWn(l));else if(K9(l)){r=!0;for(let u=0,d=l.length;u<d;u+=1)i(l[u],s,a+1)}else s.length&&i(l,s,a+1)}};return i(n,mv(e)?e.split("."):e,0),r?t:t[0]}var Do={...{isCaseSensitive:!1,ignoreDiacritics:!1,includeScore:!1,keys:[],shouldSort:!0,sortFn:(n,e)=>n.score===e.score?n.idx<e.idx?-1:1:n.score<e.score?-1:1},...{includeMatches:!1,findAllMatches:!1,minMatchCharLength:1},...{location:0,threshold:.6,distance:100},...{useExtendedSearch:!1,getFn:qWn,ignoreLocation:!1,ignoreFieldNorm:!1,fieldNormWeight:1}};const WWn=/[^ ]+/g;function ZWn(n=1,e=3){const t=new Map,r=Math.pow(10,e);return{get(i){const o=i.match(WWn).length;if(t.has(o))return t.get(o);const s=1/Math.pow(o,.5*n),a=parseFloat(Math.round(s*r)/r);return t.set(o,a),a},clear(){t.clear()}}}class w2e{constructor({getFn:e=Do.getFn,fieldNormWeight:t=Do.fieldNormWeight}={}){this.norm=ZWn(t,3),this.getFn=e,this.isCreated=!1,this.setIndexRecords()}setSources(e=[]){this.docs=e}setIndexRecords(e=[]){this.records=e}setKeys(e=[]){this.keys=e,this._keysMap={},e.forEach((t,r)=>{this._keysMap[t.id]=r})}create(){this.isCreated||!this.docs.length||(this.isCreated=!0,mv(this.docs[0])?this.docs.forEach((e,t)=>{this._addString(e,t)}):this.docs.forEach((e,t)=>{this._addObject(e,t)}),this.norm.clear())}add(e){const t=this.size();mv(e)?this._addString(e,t):this._addObject(e,t)}removeAt(e){this.records.splice(e,1);for(let t=e,r=this.size();t<r;t+=1)this.records[t].i-=1}getValueForItemAtKeyId(e,t){return e[this._keysMap[t]]}size(){return this.records.length}_addString(e,t){if(!e2(e)||b2e(e))return;let r={v:e,i:t,n:this.norm.get(e)};this.records.push(r)}_addObject(e,t){let r={i:t,$:{}};this.keys.forEach((i,o)=>{let s=i.getFn?i.getFn(e):this.getFn(e,i.path);if(e2(s)){if(K9(s)){let a=[];const c=[{nestedArrIndex:-1,value:s}];for(;c.length;){const{nestedArrIndex:l,value:u}=c.pop();if(e2(u))if(mv(u)&&!b2e(u)){let d={v:u,i:l,n:this.norm.get(u)};a.push(d)}else K9(u)&&u.forEach((d,h)=>{c.push({nestedArrIndex:h,value:d})})}r.$[o]=a}else if(mv(s)&&!b2e(s)){let a={v:s,n:this.norm.get(s)};r.$[o]=a}}}),this.records.push(r)}toJSON(){return{keys:this.keys,records:this.records}}}function Fht(n,e,{getFn:t=Do.getFn,fieldNormWeight:r=Do.fieldNormWeight}={}){const i=new w2e({getFn:t,fieldNormWeight:r});return i.setKeys(n.map(zht)),i.setSources(e),i.create(),i}function KWn(n,{getFn:e=Do.getFn,fieldNormWeight:t=Do.fieldNormWeight}={}){const{keys:r,records:i}=n,o=new w2e({getFn:e,fieldNormWeight:t});return o.setKeys(r),o.setIndexRecords(i),o}function pq(n,{errors:e=0,currentLocation:t=0,expectedLocation:r=0,distance:i=Do.distance,ignoreLocation:o=Do.ignoreLocation}={}){const s=e/n.length;if(o)return s;const a=Math.abs(r-t);return i?s+a/i:a?1:s}function QWn(n=[],e=Do.minMatchCharLength){let t=[],r=-1,i=-1,o=0;for(let s=n.length;o<s;o+=1){let a=n[o];a&&r===-1?r=o:!a&&r!==-1&&(i=o-1,i-r+1>=e&&t.push([r,i]),r=-1)}return n[o-1]&&o-r>=e&&t.push([r,o-1]),t}const ZS=32;function JWn(n,e,t,{location:r=Do.location,distance:i=Do.distance,threshold:o=Do.threshold,findAllMatches:s=Do.findAllMatches,minMatchCharLength:a=Do.minMatchCharLength,includeMatches:c=Do.includeMatches,ignoreLocation:l=Do.ignoreLocation}={}){if(e.length>ZS)throw new Error(YWn(ZS));const u=e.length,d=n.length,h=Math.max(0,Math.min(r,d));let f=o,p=h;const m=a>1||c,g=m?Array(d):[];let y;for(;(y=n.indexOf(e,p))>-1;){let E=pq(e,{currentLocation:y,expectedLocation:h,distance:i,ignoreLocation:l});if(f=Math.min(E,f),p=y+u,m){let C=0;for(;C<u;)g[y+C]=1,C+=1}}p=-1;let _=[],x=1,b=u+d;const w=1<<u-1;for(let E=0;E<u;E+=1){let C=0,A=b;for(;C<A;)pq(e,{errors:E,currentLocation:h+A,expectedLocation:h,distance:i,ignoreLocation:l})<=f?C=A:b=A,A=Math.floor((b-C)/2+C);b=A;let R=Math.max(1,h-A+1),L=s?d:Math.min(h+A,d)+u,O=Array(L+2);O[L+1]=(1<<E)-1;for(let B=L;B>=R;B-=1){let j=B-1,G=t[n.charAt(j)];if(m&&(g[j]=+!!G),O[B]=(O[B+1]<<1|1)&G,E&&(O[B]|=(_[B+1]|_[B])<<1|1|_[B+1]),O[B]&w&&(x=pq(e,{errors:E,currentLocation:j,expectedLocation:h,distance:i,ignoreLocation:l}),x<=f)){if(f=x,p=j,p<=h)break;R=Math.max(1,2*h-p)}}if(pq(e,{errors:E+1,currentLocation:h,expectedLocation:h,distance:i,ignoreLocation:l})>f)break;_=O}const S={isMatch:p>=0,score:Math.max(.001,x)};if(m){const E=QWn(g,a);E.length?c&&(S.indices=E):S.isMatch=!1}return S}function eZn(n){let e={};for(let t=0,r=n.length;t<r;t+=1){const i=n.charAt(t);e[i]=(e[i]||0)|1<<r-t-1}return e}const fq=String.prototype.normalize?(n=>n.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,"")):(n=>n);class Bht{constructor(e,{location:t=Do.location,threshold:r=Do.threshold,distance:i=Do.distance,includeMatches:o=Do.includeMatches,findAllMatches:s=Do.findAllMatches,minMatchCharLength:a=Do.minMatchCharLength,isCaseSensitive:c=Do.isCaseSensitive,ignoreDiacritics:l=Do.ignoreDiacritics,ignoreLocation:u=Do.ignoreLocation}={}){if(this.options={location:t,threshold:r,distance:i,includeMatches:o,findAllMatches:s,minMatchCharLength:a,isCaseSensitive:c,ignoreDiacritics:l,ignoreLocation:u},e=c?e:e.toLowerCase(),e=l?fq(e):e,this.pattern=e,this.chunks=[],!this.pattern.length)return;const d=(f,p)=>{this.chunks.push({pattern:f,alphabet:eZn(f),startIndex:p})},h=this.pattern.length;if(h>ZS){let f=0;const p=h%ZS,m=h-p;for(;f<m;)d(this.pattern.substr(f,ZS),f),f+=ZS;if(p){const g=h-ZS;d(this.pattern.substr(g),g)}}else d(this.pattern,0)}searchIn(e){const{isCaseSensitive:t,ignoreDiacritics:r,includeMatches:i}=this.options;if(e=t?e:e.toLowerCase(),e=r?fq(e):e,this.pattern===e){let m={isMatch:!0,score:0};return i&&(m.indices=[[0,e.length-1]]),m}const{location:o,distance:s,threshold:a,findAllMatches:c,minMatchCharLength:l,ignoreLocation:u}=this.options;let d=[],h=0,f=!1;this.chunks.forEach(({pattern:m,alphabet:g,startIndex:y})=>{const{isMatch:_,score:x,indices:b}=JWn(e,m,g,{location:o+y,distance:s,threshold:a,findAllMatches:c,minMatchCharLength:l,includeMatches:i,ignoreLocation:u});_&&(f=!0),h+=x,_&&b&&(d=[...d,...b])});let p={isMatch:f,score:f?h/this.chunks.length:1};return f&&i&&(p.indices=d),p}}class D8{constructor(e){this.pattern=e}static isMultiMatch(e){return jht(e,this.multiRegex)}static isSingleMatch(e){return jht(e,this.singleRegex)}search(){}}function jht(n,e){const t=n.match(e);return t?t[1]:null}class tZn extends D8{constructor(e){super(e)}static get type(){return"exact"}static get multiRegex(){return/^="(.*)"$/}static get singleRegex(){return/^=(.*)$/}search(e){const t=e===this.pattern;return{isMatch:t,score:t?0:1,indices:[0,this.pattern.length-1]}}}class nZn extends D8{constructor(e){super(e)}static get type(){return"inverse-exact"}static get multiRegex(){return/^!"(.*)"$/}static get singleRegex(){return/^!(.*)$/}search(e){const r=e.indexOf(this.pattern)===-1;return{isMatch:r,score:r?0:1,indices:[0,e.length-1]}}}class rZn extends D8{constructor(e){super(e)}static get type(){return"prefix-exact"}static get multiRegex(){return/^\^"(.*)"$/}static get singleRegex(){return/^\^(.*)$/}search(e){const t=e.startsWith(this.pattern);return{isMatch:t,score:t?0:1,indices:[0,this.pattern.length-1]}}}class iZn extends D8{constructor(e){super(e)}static get type(){return"inverse-prefix-exact"}static get multiRegex(){return/^!\^"(.*)"$/}static get singleRegex(){return/^!\^(.*)$/}search(e){const t=!e.startsWith(this.pattern);return{isMatch:t,score:t?0:1,indices:[0,e.length-1]}}}class oZn extends D8{constructor(e){super(e)}static get type(){return"suffix-exact"}static get multiRegex(){return/^"(.*)"\$$/}static get singleRegex(){return/^(.*)\$$/}search(e){const t=e.endsWith(this.pattern);return{isMatch:t,score:t?0:1,indices:[e.length-this.pattern.length,e.length-1]}}}class sZn extends D8{constructor(e){super(e)}static get type(){return"inverse-suffix-exact"}static get multiRegex(){return/^!"(.*)"\$$/}static get singleRegex(){return/^!(.*)\$$/}search(e){const t=!e.endsWith(this.pattern);return{isMatch:t,score:t?0:1,indices:[0,e.length-1]}}}class Uht extends D8{constructor(e,{location:t=Do.location,threshold:r=Do.threshold,distance:i=Do.distance,includeMatches:o=Do.includeMatches,findAllMatches:s=Do.findAllMatches,minMatchCharLength:a=Do.minMatchCharLength,isCaseSensitive:c=Do.isCaseSensitive,ignoreDiacritics:l=Do.ignoreDiacritics,ignoreLocation:u=Do.ignoreLocation}={}){super(e),this._bitapSearch=new Bht(e,{location:t,threshold:r,distance:i,includeMatches:o,findAllMatches:s,minMatchCharLength:a,isCaseSensitive:c,ignoreDiacritics:l,ignoreLocation:u})}static get type(){return"fuzzy"}static get multiRegex(){return/^"(.*)"$/}static get singleRegex(){return/^(.*)$/}search(e){return this._bitapSearch.searchIn(e)}}class Hht extends D8{constructor(e){super(e)}static get type(){return"include"}static get multiRegex(){return/^'"(.*)"$/}static get singleRegex(){return/^'(.*)$/}search(e){let t=0,r;const i=[],o=this.pattern.length;for(;(r=e.indexOf(this.pattern,t))>-1;)t=r+o,i.push([r,t-1]);const s=!!i.length;return{isMatch:s,score:s?0:1,indices:i}}}const S2e=[tZn,Hht,rZn,iZn,sZn,oZn,nZn,Uht],Yht=S2e.length,aZn=/ +(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/,cZn="|";function lZn(n,e={}){return n.split(cZn).map(t=>{let r=t.trim().split(aZn).filter(o=>o&&!!o.trim()),i=[];for(let o=0,s=r.length;o<s;o+=1){const a=r[o];let c=!1,l=-1;for(;!c&&++l<Yht;){const u=S2e[l];let d=u.isMultiMatch(a);d&&(i.push(new u(d,e)),c=!0)}if(!c)for(l=-1;++l<Yht;){const u=S2e[l];let d=u.isSingleMatch(a);if(d){i.push(new u(d,e));break}}}return i})}const uZn=new Set([Uht.type,Hht.type]);class dZn{constructor(e,{isCaseSensitive:t=Do.isCaseSensitive,ignoreDiacritics:r=Do.ignoreDiacritics,includeMatches:i=Do.includeMatches,minMatchCharLength:o=Do.minMatchCharLength,ignoreLocation:s=Do.ignoreLocation,findAllMatches:a=Do.findAllMatches,location:c=Do.location,threshold:l=Do.threshold,distance:u=Do.distance}={}){this.query=null,this.options={isCaseSensitive:t,ignoreDiacritics:r,includeMatches:i,minMatchCharLength:o,findAllMatches:a,ignoreLocation:s,location:c,threshold:l,distance:u},e=t?e:e.toLowerCase(),e=r?fq(e):e,this.pattern=e,this.query=lZn(this.pattern,this.options)}static condition(e,t){return t.useExtendedSearch}searchIn(e){const t=this.query;if(!t)return{isMatch:!1,score:1};const{includeMatches:r,isCaseSensitive:i,ignoreDiacritics:o}=this.options;e=i?e:e.toLowerCase(),e=o?fq(e):e;let s=0,a=[],c=0;for(let l=0,u=t.length;l<u;l+=1){const d=t[l];a.length=0,s=0;for(let h=0,f=d.length;h<f;h+=1){const p=d[h],{isMatch:m,indices:g,score:y}=p.search(e);if(m){if(s+=1,c+=y,r){const _=p.constructor.type;uZn.has(_)?a=[...a,...g]:a.push(g)}}else{c=0,s=0,a.length=0;break}}if(s){let h={isMatch:!0,score:c/s};return r&&(h.indices=a),h}}return{isMatch:!1,score:1}}}const M2e=[];function hZn(...n){M2e.push(...n)}function E2e(n,e){for(let t=0,r=M2e.length;t<r;t+=1){let i=M2e[t];if(i.condition(n,e))return new i(n,e)}return new Bht(n,e)}const mq={AND:"$and",OR:"$or"},T2e={PATH:"$path",PATTERN:"$val"},C2e=n=>!!(n[mq.AND]||n[mq.OR]),pZn=n=>!!n[T2e.PATH],fZn=n=>!K9(n)&&Oht(n)&&!C2e(n),Xht=n=>({[mq.AND]:Object.keys(n).map(e=>({[e]:n[e]}))});function Vht(n,e,{auto:t=!0}={}){const r=i=>{let o=Object.keys(i);const s=pZn(i);if(!s&&o.length>1&&!C2e(i))return r(Xht(i));if(fZn(i)){const c=s?i[T2e.PATH]:o[0],l=s?i[T2e.PATTERN]:i[c];if(!mv(l))throw new Error(HWn(c));const u={keyId:v2e(c),pattern:l};return t&&(u.searcher=E2e(l,e)),u}let a={children:[],operator:o[0]};return o.forEach(c=>{const l=i[c];K9(l)&&l.forEach(u=>{a.children.push(r(u))})}),a};return C2e(n)||(n=Xht(n)),r(n)}function mZn(n,{ignoreFieldNorm:e=Do.ignoreFieldNorm}){n.forEach(t=>{let r=1;t.matches.forEach(({key:i,norm:o,score:s})=>{const a=i?i.weight:null;r*=Math.pow(s===0&&a?Number.EPSILON:s,(a||1)*(e?1:o))}),t.score=r})}function yZn(n,e){const t=n.matches;e.matches=[],e2(t)&&t.forEach(r=>{if(!e2(r.indices)||!r.indices.length)return;const{indices:i,value:o}=r;let s={indices:i,value:o};r.key&&(s.key=r.key.src),r.idx>-1&&(s.refIndex=r.idx),e.matches.push(s)})}function gZn(n,e){e.score=n.score}function _Zn(n,e,{includeMatches:t=Do.includeMatches,includeScore:r=Do.includeScore}={}){const i=[];return t&&i.push(yZn),r&&i.push(gZn),n.map(o=>{const{idx:s}=o,a={item:e[s],refIndex:s};return i.length&&i.forEach(c=>{c(o,a)}),a})}class HP{constructor(e,t={},r){this.options={...Do,...t},this.options.useExtendedSearch,this._keyStore=new GWn(this.options.keys),this.setCollection(e,r)}setCollection(e,t){if(this._docs=e,t&&!(t instanceof w2e))throw new Error(UWn);this._myIndex=t||Fht(this.options.keys,this._docs,{getFn:this.options.getFn,fieldNormWeight:this.options.fieldNormWeight})}add(e){e2(e)&&(this._docs.push(e),this._myIndex.add(e))}remove(e=()=>!1){const t=[];for(let r=0,i=this._docs.length;r<i;r+=1){const o=this._docs[r];e(o,r)&&(this.removeAt(r),r-=1,i-=1,t.push(o))}return t}removeAt(e){this._docs.splice(e,1),this._myIndex.removeAt(e)}getIndex(){return this._myIndex}search(e,{limit:t=-1}={}){const{includeMatches:r,includeScore:i,shouldSort:o,sortFn:s,ignoreFieldNorm:a}=this.options;let c=mv(e)?mv(this._docs[0])?this._searchStringList(e):this._searchObjectList(e):this._searchLogical(e);return mZn(c,{ignoreFieldNorm:a}),o&&c.sort(s),kht(t)&&t>-1&&(c=c.slice(0,t)),_Zn(c,this._docs,{includeMatches:r,includeScore:i})}_searchStringList(e){const t=E2e(e,this.options),{records:r}=this._myIndex,i=[];return r.forEach(({v:o,i:s,n:a})=>{if(!e2(o))return;const{isMatch:c,score:l,indices:u}=t.searchIn(o);c&&i.push({item:o,idx:s,matches:[{score:l,value:o,norm:a,indices:u}]})}),i}_searchLogical(e){const t=Vht(e,this.options),r=(a,c,l)=>{if(!a.children){const{keyId:d,searcher:h}=a,f=this._findMatches({key:this._keyStore.get(d),value:this._myIndex.getValueForItemAtKeyId(c,d),searcher:h});return f&&f.length?[{idx:l,item:c,matches:f}]:[]}const u=[];for(let d=0,h=a.children.length;d<h;d+=1){const f=a.children[d],p=r(f,c,l);if(p.length)u.push(...p);else if(a.operator===mq.AND)return[]}return u},i=this._myIndex.records,o={},s=[];return i.forEach(({$:a,i:c})=>{if(e2(a)){let l=r(t,a,c);l.length&&(o[c]||(o[c]={idx:c,item:a,matches:[]},s.push(o[c])),l.forEach(({matches:u})=>{o[c].matches.push(...u)}))}}),s}_searchObjectList(e){const t=E2e(e,this.options),{keys:r,records:i}=this._myIndex,o=[];return i.forEach(({$:s,i:a})=>{if(!e2(s))return;let c=[];r.forEach((l,u)=>{c.push(...this._findMatches({key:l,value:s[u],searcher:t}))}),c.length&&o.push({idx:a,item:s,matches:c})}),o}_findMatches({key:e,value:t,searcher:r}){if(!e2(t))return[];let i=[];if(K9(t))t.forEach(({v:o,i:s,n:a})=>{if(!e2(o))return;const{isMatch:c,score:l,indices:u}=r.searchIn(o);c&&i.push({score:l,key:e,value:o,idx:s,norm:a,indices:u})});else{const{v:o,n:s}=t,{isMatch:a,score:c,indices:l}=r.searchIn(o);a&&i.push({score:c,key:e,value:o,norm:s,indices:l})}return i}}HP.version="7.1.0",HP.createIndex=Fht,HP.parseIndex=KWn,HP.config=Do,HP.parseQuery=Vht,hZn(dZn);let P2e=null,WO=null,A2e=null;const xZn=async()=>P2e||WO||(WO=fetch("https://kicad-mod-cache.tscircuit.com/kicad_files.json").then(n=>n.json()).then(n=>(P2e=n,WO=null,n)),WO),bZn=async(n,e=20)=>{const t=await xZn();return A2e||(A2e=new HP(t)),A2e.search(n).slice(0,e).map(r=>r.item)},vZn=n=>{const e=n.replace(".pretty/","/").replace(".kicad_mod",""),t=`kicad:${e}`;return{path:n,qualifiedName:t,description:e}},wZn=()=>{const[n,e]=q.useState([]),[t,r]=q.useState(!1),[i,o]=q.useState(null),[s,a]=q.useState(!1),c=q.useCallback(async u=>{const d=u.trim();if(!d)return[];r(!0),o(null);try{const f=(await bZn(d,20)).map(p=>({source:"kicad",footprint:vZn(p)}));return e(f),f}catch(h){return console.error("Error searching KiCad footprints",h),e([]),o(h instanceof Error?h.message:"Failed to search KiCad footprints"),[]}finally{r(!1),a(!0)}},[]),l=q.useCallback(()=>{e([]),r(!1),o(null),a(!1)},[]);return{results:n,isSearching:t,error:i,hasSearched:s,search:c,reset:l}},SZn={dialog:101},MZn=({onTscircuitPackageSelected:n,onJlcpcbComponentTsxLoaded:e,onKicadStringSelected:t})=>{const r=[];return n&&r.push("tscircuit.com"),e&&r.push("jlcpcb"),t&&r.push("kicad"),r},EZn=({isOpen:n,onClose:e,jlcpcbProxyRequestHeaders:t,onKicadStringSelected:r,onTscircuitPackageSelected:i,onJlcpcbComponentTsxLoaded:o,jlcpcbProxyApiBase:s,tscircuitSessionToken:a})=>{rq();const c=q.useMemo(()=>MZn({onKicadStringSelected:r,onTscircuitPackageSelected:i,onJlcpcbComponentTsxLoaded:o}),[r,i,o]),l=c.length>0,u=c.length===1,[d,h]=q.useState(c[0]??"tscircuit.com"),[f,p]=q.useState(""),[m,g]=q.useState(null),{results:y,isSearching:_,error:x,hasSearched:b,search:w,reset:S}=LWn({sessionToken:a}),{results:E,isSearching:C,error:A,hasSearched:R,search:L,reset:O}=zWn(),{results:F,isSearching:B,error:j,hasSearched:G,search:W,reset:Q}=wZn(),{details:ne,isLoading:ue,fetchDetails:te,reset:re}=kWn(),[se,ce]=q.useState(null),[fe,Me]=q.useState(!1),[Pe,Ne]=q.useState("pcb"),[me,Se]=q.useState(null),[ye,He]=q.useState(!1);q.useEffect(()=>{Se(null)},[m]);const Ye=q.useCallback(()=>{S(),O(),Q(),g(null)},[O,Q,S]);q.useEffect(()=>{n||(Ye(),p(""),Me(!1),ce(null),Se(null))},[n,Ye]),q.useEffect(()=>{p(""),g(null),d==="tscircuit.com"?S():d==="jlcpcb"?O():d==="kicad"&&Q()},[d,O,Q,S]);const We=Be=>{g(Be),ce(Be),Ne("pcb"),Me(!0),re();const Xe=Be.package.org_owner_tscircuit_handle,et=Be.package.unscoped_name;if(Xe&&et){const rt=et.split("/").pop()??et;te(Xe,rt)}},ge=async()=>{f.trim()&&(g(null),d==="tscircuit.com"?await w(f):d==="jlcpcb"?await L(f):d==="kicad"&&await W(f))},Ze=async Be=>{try{if(Se(null),He(!0),Be.source==="kicad"){if(!r)throw new Error("KiCad handler not provided");await r({result:Be,footprint:Be.footprint.qualifiedName})}else if(Be.source==="jlcpcb"){if(!o)throw new Error("JLCPCB handler not provided");const Xe=await MWn(Be.component.partNumber,{headers:t,apiBase:s});await o({result:Be,tsx:Xe})}else if(Be.source==="tscircuit.com"){if(!i)throw new Error("tscircuit package handler not provided");const Xe=Be.package.org_owner_tscircuit_handle,et=Be.package.unscoped_name;if(!Xe||!et)throw new Error("Missing package metadata");const rt=et.split("/").pop()??et,at=`@tsci/${Xe}.${rt}`;await i({result:Be,fullPackageName:at})}return!0}catch(Xe){return console.error("Failed to import component",Xe),Se(Xe instanceof Error?Xe.message:"Failed to import component"),!1}finally{He(!1)}};let $e=[],ke=!1,je=null,Re=!1;d==="tscircuit.com"?($e=y,ke=_,je=x,Re=b):d==="jlcpcb"?($e=E,ke=C,je=A,Re=R):d==="kicad"&&($e=F,ke=B,je=j,Re=G);const be=async()=>{if(!m)return;await Ze(m)&&(e(),Ye(),p(""))},Ce=Be=>{Be||e()},Te=Be=>{Me(Be),Be||ce(null)};return V.jsxs(jP,{open:n,onOpenChange:Ce,children:[V.jsxs(GS,{style:{width:"calc(100vw - 2rem)",zIndex:SZn.dialog},className:"rf-rounded-sm rf-max-h-[90vh] rf-overflow-y-auto rf-overflow-x-hidden rf-flex rf-flex-col",children:[V.jsxs(qS,{children:[V.jsxs(WS,{className:"rf-text-lg sm:rf-text-xl",children:["Import ",u?hq[d].label:""," ","Component"]}),V.jsx(UP,{className:"rf-text-sm",children:l?"Search for components from available sources.":"Import options are disabled because no handlers were provided."})]}),l?V.jsxs(Gse,{value:d,onValueChange:Be=>h(Be),className:"rf-min-w-0 rf-w-full",children:[!u&&V.jsx(yH,{className:"rf-flex rf-w-full rf-gap-2",children:c.map(Be=>V.jsx(Rb,{value:Be,className:"rf-flex-1 rf-text-xs sm:rf-text-sm",children:hq[Be].label},Be))}),V.jsx(EWn,{query:f,placeholder:hq[d].placeholder,isSearching:ke,onQueryChange:p,onSubmit:ge}),V.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:ke?V.jsxs("div",{className:"rf-p-8 rf-text-center rf-text-zinc-500",children:[V.jsx(D9,{className:"rf-h-8 rf-w-8 rf-animate-spin rf-mx-auto rf-mb-2"}),V.jsx("p",{children:"Searching..."})]}):$e.length>0?V.jsx(NWn,{results:$e,selected:m,onSelect:g,onShowDetails:d==="tscircuit.com"?We:void 0}):V.jsx("div",{className:"rf-p-8 rf-text-center rf-text-zinc-500",children:je?`Error: ${je}`:Re?hq[d].emptyMessage:"Enter a search term to find components"})})]}):null,me?V.jsx("div",{className:"rf-text-sm rf-text-red-600 rf-mt-2",children:me}):null,V.jsxs(qO,{className:"rf-flex rf-flex-col sm:rf-flex-row rf-gap-2",children:[V.jsx(hc,{variant:"outline",onClick:e,className:"rf-order-2 sm:rf-order-1",children:"Cancel"}),V.jsx(hc,{onClick:be,disabled:!m||ye,className:"rf-order-1 sm:rf-order-2",children:ye?V.jsx(D9,{className:"rf-h-4 rf-w-4 rf-animate-spin"}):"Import"})]})]}),V.jsx(IWn,{packageResult:se,isOpen:fe,onOpenChange:Te,isLoading:ue,details:ne,previewTab:Pe,onPreviewTabChange:Be=>Ne(Be),isSubmitting:ye,onImport:()=>{se&&Ze(se).then(Be=>{Be&&(Me(!1),e(),Ye(),p(""))})}})]})},TZn=n=>{const e=n.match(/export const (\w+) =/);if(!e)throw new Error("Could not determine component name from TSX contents");return e[1]},Ght=n=>{const e=Ju(s=>s.pushEvent),t=Ju(s=>s.upsertFile),r=async({result:s,fullPackageName:a})=>{const l=s.package.unscoped_name??s.package.name;await ds.promise(e({event_type:"INSTALL_PACKAGE",full_package_name:a}),{loading:`Requesting install for "${l}"`,success:`Install requested for "${l}"`,error:u=>`Failed to request install: ${u instanceof Error?u.message:String(u)}`})},i=async({footprint:s})=>{await ds.promise(navigator.clipboard.writeText(s),{loading:`Copying "${s}"`,success:`Copied "${s}" to clipboard`,error:a=>`Failed to copy footprint: ${a instanceof Error?a.message:String(a)}`})},o=async({result:s,tsx:a})=>{const l=`imports/${TZn(a)}.tsx`;await ds.promise(t(l,a),{loading:`Importing ${s.component.partNumber}`,success:`Imported to "${l}"`,error:u=>`Failed to import component: ${u instanceof Error?u.message:String(u)}`})};return V.jsx(EZn,{...n,onTscircuitPackageSelected:r,onKicadStringSelected:i,onJlcpcbComponentTsxLoaded:o})};Ght.displayName="ImportComponentDialogForCli";var R2e={exports:{}},qht;function CZn(){return qht||(qht=1,(function(n,e){var t={env:{},version:""};(function(r){n.exports=r()})(function(){return(function r(i,o,s){function a(u,d){if(!o[u]){if(!i[u]){var h=typeof B6=="function"&&B6;if(!d&&h)return h(u,!0);if(c)return c(u,!0);var f=new Error("Cannot find module '"+u+"'");throw f.code="MODULE_NOT_FOUND",f}var p=o[u]={exports:{}};i[u][0].call(p.exports,function(m){var g=i[u][1][m];return a(g||m)},p,p.exports,r,i,o,s)}return o[u].exports}for(var c=typeof B6=="function"&&B6,l=0;l<s.length;l++)a(s[l]);return a})({1:[function(r,i,o){var s=r("./utils"),a=r("./support"),c="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";o.encode=function(l){for(var u,d,h,f,p,m,g,y=[],_=0,x=l.length,b=x,w=s.getTypeOf(l)!=="string";_<l.length;)b=x-_,h=w?(u=l[_++],d=_<x?l[_++]:0,_<x?l[_++]:0):(u=l.charCodeAt(_++),d=_<x?l.charCodeAt(_++):0,_<x?l.charCodeAt(_++):0),f=u>>2,p=(3&u)<<4|d>>4,m=1<b?(15&d)<<2|h>>6:64,g=2<b?63&h:64,y.push(c.charAt(f)+c.charAt(p)+c.charAt(m)+c.charAt(g));return y.join("")},o.decode=function(l){var u,d,h,f,p,m,g=0,y=0,_="data:";if(l.substr(0,_.length)===_)throw new Error("Invalid base64 input, it looks like a data url.");var x,b=3*(l=l.replace(/[^A-Za-z0-9+/=]/g,"")).length/4;if(l.charAt(l.length-1)===c.charAt(64)&&b--,l.charAt(l.length-2)===c.charAt(64)&&b--,b%1!=0)throw new Error("Invalid base64 input, bad content length.");for(x=a.uint8array?new Uint8Array(0|b):new Array(0|b);g<l.length;)u=c.indexOf(l.charAt(g++))<<2|(f=c.indexOf(l.charAt(g++)))>>4,d=(15&f)<<4|(p=c.indexOf(l.charAt(g++)))>>2,h=(3&p)<<6|(m=c.indexOf(l.charAt(g++))),x[y++]=u,p!==64&&(x[y++]=d),m!==64&&(x[y++]=h);return x}},{"./support":30,"./utils":32}],2:[function(r,i,o){var s=r("./external"),a=r("./stream/DataWorker"),c=r("./stream/Crc32Probe"),l=r("./stream/DataLengthProbe");function u(d,h,f,p,m){this.compressedSize=d,this.uncompressedSize=h,this.crc32=f,this.compression=p,this.compressedContent=m}u.prototype={getContentWorker:function(){var d=new a(s.Promise.resolve(this.compressedContent)).pipe(this.compression.uncompressWorker()).pipe(new l("data_length")),h=this;return d.on("end",function(){if(this.streamInfo.data_length!==h.uncompressedSize)throw new Error("Bug : uncompressed data size mismatch")}),d},getCompressedWorker:function(){return new a(s.Promise.resolve(this.compressedContent)).withStreamInfo("compressedSize",this.compressedSize).withStreamInfo("uncompressedSize",this.uncompressedSize).withStreamInfo("crc32",this.crc32).withStreamInfo("compression",this.compression)}},u.createWorkerFrom=function(d,h,f){return d.pipe(new c).pipe(new l("uncompressedSize")).pipe(h.compressWorker(f)).pipe(new l("compressedSize")).withStreamInfo("compression",h)},i.exports=u},{"./external":6,"./stream/Crc32Probe":25,"./stream/DataLengthProbe":26,"./stream/DataWorker":27}],3:[function(r,i,o){var s=r("./stream/GenericWorker");o.STORE={magic:"\0\0",compressWorker:function(){return new s("STORE compression")},uncompressWorker:function(){return new s("STORE decompression")}},o.DEFLATE=r("./flate")},{"./flate":7,"./stream/GenericWorker":28}],4:[function(r,i,o){var s=r("./utils"),a=(function(){for(var c,l=[],u=0;u<256;u++){c=u;for(var d=0;d<8;d++)c=1&c?3988292384^c>>>1:c>>>1;l[u]=c}return l})();i.exports=function(c,l){return c!==void 0&&c.length?s.getTypeOf(c)!=="string"?(function(u,d,h,f){var p=a,m=f+h;u^=-1;for(var g=f;g<m;g++)u=u>>>8^p[255&(u^d[g])];return-1^u})(0|l,c,c.length,0):(function(u,d,h,f){var p=a,m=f+h;u^=-1;for(var g=f;g<m;g++)u=u>>>8^p[255&(u^d.charCodeAt(g))];return-1^u})(0|l,c,c.length,0):0}},{"./utils":32}],5:[function(r,i,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(r,i,o){var s=null;s=typeof Promise<"u"?Promise:r("lie"),i.exports={Promise:s}},{lie:37}],7:[function(r,i,o){var s=typeof Uint8Array<"u"&&typeof Uint16Array<"u"&&typeof Uint32Array<"u",a=r("pako"),c=r("./utils"),l=r("./stream/GenericWorker"),u=s?"uint8array":"array";function d(h,f){l.call(this,"FlateWorker/"+h),this._pako=null,this._pakoAction=h,this._pakoOptions=f,this.meta={}}o.magic="\b\0",c.inherits(d,l),d.prototype.processChunk=function(h){this.meta=h.meta,this._pako===null&&this._createPako(),this._pako.push(c.transformTo(u,h.data),!1)},d.prototype.flush=function(){l.prototype.flush.call(this),this._pako===null&&this._createPako(),this._pako.push([],!0)},d.prototype.cleanUp=function(){l.prototype.cleanUp.call(this),this._pako=null},d.prototype._createPako=function(){this._pako=new a[this._pakoAction]({raw:!0,level:this._pakoOptions.level||-1});var h=this;this._pako.onData=function(f){h.push({data:f,meta:h.meta})}},o.compressWorker=function(h){return new d("Deflate",h)},o.uncompressWorker=function(){return new d("Inflate",{})}},{"./stream/GenericWorker":28,"./utils":32,pako:38}],8:[function(r,i,o){function s(p,m){var g,y="";for(g=0;g<m;g++)y+=String.fromCharCode(255&p),p>>>=8;return y}function a(p,m,g,y,_,x){var b,w,S=p.file,E=p.compression,C=x!==u.utf8encode,A=c.transformTo("string",x(S.name)),R=c.transformTo("string",u.utf8encode(S.name)),L=S.comment,O=c.transformTo("string",x(L)),F=c.transformTo("string",u.utf8encode(L)),B=R.length!==S.name.length,j=F.length!==L.length,G="",W="",Q="",ne=S.dir,ue=S.date,te={crc32:0,compressedSize:0,uncompressedSize:0};m&&!g||(te.crc32=p.crc32,te.compressedSize=p.compressedSize,te.uncompressedSize=p.uncompressedSize);var re=0;m&&(re|=8),C||!B&&!j||(re|=2048);var se=0,ce=0;ne&&(se|=16),_==="UNIX"?(ce=798,se|=(function(Me,Pe){var Ne=Me;return Me||(Ne=Pe?16893:33204),(65535&Ne)<<16})(S.unixPermissions,ne)):(ce=20,se|=(function(Me){return 63&(Me||0)})(S.dosPermissions)),b=ue.getUTCHours(),b<<=6,b|=ue.getUTCMinutes(),b<<=5,b|=ue.getUTCSeconds()/2,w=ue.getUTCFullYear()-1980,w<<=4,w|=ue.getUTCMonth()+1,w<<=5,w|=ue.getUTCDate(),B&&(W=s(1,1)+s(d(A),4)+R,G+="up"+s(W.length,2)+W),j&&(Q=s(1,1)+s(d(O),4)+F,G+="uc"+s(Q.length,2)+Q);var fe="";return fe+=`
5689
5689
  \0`,fe+=s(re,2),fe+=E.magic,fe+=s(b,2),fe+=s(w,2),fe+=s(te.crc32,4),fe+=s(te.compressedSize,4),fe+=s(te.uncompressedSize,4),fe+=s(A.length,2),fe+=s(G.length,2),{fileRecord:h.LOCAL_FILE_HEADER+fe+A+G,dirRecord:h.CENTRAL_FILE_HEADER+s(ce,2)+fe+s(O.length,2)+"\0\0\0\0"+s(se,4)+s(y,4)+A+G+O}}var c=r("../utils"),l=r("../stream/GenericWorker"),u=r("../utf8"),d=r("../crc32"),h=r("../signature");function f(p,m,g,y){l.call(this,"ZipFileWorker"),this.bytesWritten=0,this.zipComment=m,this.zipPlatform=g,this.encodeFileName=y,this.streamFiles=p,this.accumulate=!1,this.contentBuffer=[],this.dirRecords=[],this.currentSourceOffset=0,this.entriesCount=0,this.currentFile=null,this._sources=[]}c.inherits(f,l),f.prototype.push=function(p){var m=p.meta.percent||0,g=this.entriesCount,y=this._sources.length;this.accumulate?this.contentBuffer.push(p):(this.bytesWritten+=p.data.length,l.prototype.push.call(this,{data:p.data,meta:{currentFile:this.currentFile,percent:g?(m+100*(g-y-1))/g:100}}))},f.prototype.openedSource=function(p){this.currentSourceOffset=this.bytesWritten,this.currentFile=p.file.name;var m=this.streamFiles&&!p.file.dir;if(m){var g=a(p,m,!1,this.currentSourceOffset,this.zipPlatform,this.encodeFileName);this.push({data:g.fileRecord,meta:{percent:0}})}else this.accumulate=!0},f.prototype.closedSource=function(p){this.accumulate=!1;var m=this.streamFiles&&!p.file.dir,g=a(p,m,!0,this.currentSourceOffset,this.zipPlatform,this.encodeFileName);if(this.dirRecords.push(g.dirRecord),m)this.push({data:(function(y){return h.DATA_DESCRIPTOR+s(y.crc32,4)+s(y.compressedSize,4)+s(y.uncompressedSize,4)})(p),meta:{percent:100}});else for(this.push({data:g.fileRecord,meta:{percent:0}});this.contentBuffer.length;)this.push(this.contentBuffer.shift());this.currentFile=null},f.prototype.flush=function(){for(var p=this.bytesWritten,m=0;m<this.dirRecords.length;m++)this.push({data:this.dirRecords[m],meta:{percent:100}});var g=this.bytesWritten-p,y=(function(_,x,b,w,S){var E=c.transformTo("string",S(w));return h.CENTRAL_DIRECTORY_END+"\0\0\0\0"+s(_,2)+s(_,2)+s(x,4)+s(b,4)+s(E.length,2)+E})(this.dirRecords.length,g,p,this.zipComment,this.encodeFileName);this.push({data:y,meta:{percent:100}})},f.prototype.prepareNextSource=function(){this.previous=this._sources.shift(),this.openedSource(this.previous.streamInfo),this.isPaused?this.previous.pause():this.previous.resume()},f.prototype.registerPrevious=function(p){this._sources.push(p);var m=this;return p.on("data",function(g){m.processChunk(g)}),p.on("end",function(){m.closedSource(m.previous.streamInfo),m._sources.length?m.prepareNextSource():m.end()}),p.on("error",function(g){m.error(g)}),this},f.prototype.resume=function(){return!!l.prototype.resume.call(this)&&(!this.previous&&this._sources.length?(this.prepareNextSource(),!0):this.previous||this._sources.length||this.generatedError?void 0:(this.end(),!0))},f.prototype.error=function(p){var m=this._sources;if(!l.prototype.error.call(this,p))return!1;for(var g=0;g<m.length;g++)try{m[g].error(p)}catch{}return!0},f.prototype.lock=function(){l.prototype.lock.call(this);for(var p=this._sources,m=0;m<p.length;m++)p[m].lock()},i.exports=f},{"../crc32":4,"../signature":23,"../stream/GenericWorker":28,"../utf8":31,"../utils":32}],9:[function(r,i,o){var s=r("../compressions"),a=r("./ZipFileWorker");o.generateWorker=function(c,l,u){var d=new a(l.streamFiles,u,l.platform,l.encodeFileName),h=0;try{c.forEach(function(f,p){h++;var m=(function(x,b){var w=x||b,S=s[w];if(!S)throw new Error(w+" is not a valid compression method !");return S})(p.options.compression,l.compression),g=p.options.compressionOptions||l.compressionOptions||{},y=p.dir,_=p.date;p._compressWorker(m,g).withStreamInfo("file",{name:f,dir:y,date:_,comment:p.comment||"",unixPermissions:p.unixPermissions,dosPermissions:p.dosPermissions}).pipe(d)}),d.entriesCount=h}catch(f){d.error(f)}return d}},{"../compressions":3,"./ZipFileWorker":8}],10:[function(r,i,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 a=new s;for(var c in this)typeof this[c]!="function"&&(a[c]=this[c]);return a}}(s.prototype=r("./object")).loadAsync=r("./load"),s.support=r("./support"),s.defaults=r("./defaults"),s.version="3.10.1",s.loadAsync=function(a,c){return new s().loadAsync(a,c)},s.external=r("./external"),i.exports=s},{"./defaults":5,"./external":6,"./load":11,"./object":15,"./support":30}],11:[function(r,i,o){var s=r("./utils"),a=r("./external"),c=r("./utf8"),l=r("./zipEntries"),u=r("./stream/Crc32Probe"),d=r("./nodejsUtils");function h(f){return new a.Promise(function(p,m){var g=f.decompressed.getContentWorker().pipe(new u);g.on("error",function(y){m(y)}).on("end",function(){g.streamInfo.crc32!==f.decompressed.crc32?m(new Error("Corrupted zip : CRC32 mismatch")):p()}).resume()})}i.exports=function(f,p){var m=this;return p=s.extend(p||{},{base64:!1,checkCRC32:!1,optimizedBinaryString:!1,createFolders:!1,decodeFileName:c.utf8decode}),d.isNode&&d.isStream(f)?a.Promise.reject(new Error("JSZip can't accept a stream when loading a zip file.")):s.prepareContent("the loaded zip file",f,!0,p.optimizedBinaryString,p.base64).then(function(g){var y=new l(p);return y.load(g),y}).then(function(g){var y=[a.Promise.resolve(g)],_=g.files;if(p.checkCRC32)for(var x=0;x<_.length;x++)y.push(h(_[x]));return a.Promise.all(y)}).then(function(g){for(var y=g.shift(),_=y.files,x=0;x<_.length;x++){var b=_[x],w=b.fileNameStr,S=s.resolve(b.fileNameStr);m.file(S,b.decompressed,{binary:!0,optimizedBinaryString:!0,date:b.date,dir:b.dir,comment:b.fileCommentStr.length?b.fileCommentStr:null,unixPermissions:b.unixPermissions,dosPermissions:b.dosPermissions,createFolders:p.createFolders}),b.dir||(m.file(S).unsafeOriginalName=w)}return y.zipComment.length&&(m.comment=y.zipComment),m})}},{"./external":6,"./nodejsUtils":14,"./stream/Crc32Probe":25,"./utf8":31,"./utils":32,"./zipEntries":33}],12:[function(r,i,o){var s=r("../utils"),a=r("../stream/GenericWorker");function c(l,u){a.call(this,"Nodejs stream input adapter for "+l),this._upstreamEnded=!1,this._bindStream(u)}s.inherits(c,a),c.prototype._bindStream=function(l){var u=this;(this._stream=l).pause(),l.on("data",function(d){u.push({data:d,meta:{percent:0}})}).on("error",function(d){u.isPaused?this.generatedError=d:u.error(d)}).on("end",function(){u.isPaused?u._upstreamEnded=!0:u.end()})},c.prototype.pause=function(){return!!a.prototype.pause.call(this)&&(this._stream.pause(),!0)},c.prototype.resume=function(){return!!a.prototype.resume.call(this)&&(this._upstreamEnded?this.end():this._stream.resume(),!0)},i.exports=c},{"../stream/GenericWorker":28,"../utils":32}],13:[function(r,i,o){var s=r("readable-stream").Readable;function a(c,l,u){s.call(this,l),this._helper=c;var d=this;c.on("data",function(h,f){d.push(h)||d._helper.pause(),u&&u(f)}).on("error",function(h){d.emit("error",h)}).on("end",function(){d.push(null)})}r("../utils").inherits(a,s),a.prototype._read=function(){this._helper.resume()},i.exports=a},{"../utils":32,"readable-stream":16}],14:[function(r,i,o){i.exports={isNode:typeof Buffer<"u",newBufferFrom:function(s,a){if(Buffer.from&&Buffer.from!==Uint8Array.from)return Buffer.from(s,a);if(typeof s=="number")throw new Error('The "data" argument must not be a number');return new Buffer(s,a)},allocBuffer:function(s){if(Buffer.alloc)return Buffer.alloc(s);var a=new Buffer(s);return a.fill(0),a},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(r,i,o){function s(S,E,C){var A,R=c.getTypeOf(E),L=c.extend(C||{},d);L.date=L.date||new Date,L.compression!==null&&(L.compression=L.compression.toUpperCase()),typeof L.unixPermissions=="string"&&(L.unixPermissions=parseInt(L.unixPermissions,8)),L.unixPermissions&&16384&L.unixPermissions&&(L.dir=!0),L.dosPermissions&&16&L.dosPermissions&&(L.dir=!0),L.dir&&(S=_(S)),L.createFolders&&(A=y(S))&&x.call(this,A,!0);var O=R==="string"&&L.binary===!1&&L.base64===!1;C&&C.binary!==void 0||(L.binary=!O),(E instanceof h&&E.uncompressedSize===0||L.dir||!E||E.length===0)&&(L.base64=!1,L.binary=!0,E="",L.compression="STORE",R="string");var F=null;F=E instanceof h||E instanceof l?E:m.isNode&&m.isStream(E)?new g(S,E):c.prepareContent(S,E,L.binary,L.optimizedBinaryString,L.base64);var B=new f(S,F,L);this.files[S]=B}var a=r("./utf8"),c=r("./utils"),l=r("./stream/GenericWorker"),u=r("./stream/StreamHelper"),d=r("./defaults"),h=r("./compressedObject"),f=r("./zipObject"),p=r("./generate"),m=r("./nodejsUtils"),g=r("./nodejs/NodejsStreamInputAdapter"),y=function(S){S.slice(-1)==="/"&&(S=S.substring(0,S.length-1));var E=S.lastIndexOf("/");return 0<E?S.substring(0,E):""},_=function(S){return S.slice(-1)!=="/"&&(S+="/"),S},x=function(S,E){return E=E!==void 0?E:d.createFolders,S=_(S),this.files[S]||s.call(this,S,null,{dir:!0,createFolders:E}),this.files[S]};function b(S){return Object.prototype.toString.call(S)==="[object RegExp]"}var w={load:function(){throw new Error("This method has been removed in JSZip 3.0, please check the upgrade guide.")},forEach:function(S){var E,C,A;for(E in this.files)A=this.files[E],(C=E.slice(this.root.length,E.length))&&E.slice(0,this.root.length)===this.root&&S(C,A)},filter:function(S){var E=[];return this.forEach(function(C,A){S(C,A)&&E.push(A)}),E},file:function(S,E,C){if(arguments.length!==1)return S=this.root+S,s.call(this,S,E,C),this;if(b(S)){var A=S;return this.filter(function(L,O){return!O.dir&&A.test(L)})}var R=this.files[this.root+S];return R&&!R.dir?R:null},folder:function(S){if(!S)return this;if(b(S))return this.filter(function(R,L){return L.dir&&S.test(R)});var E=this.root+S,C=x.call(this,E),A=this.clone();return A.root=C.name,A},remove:function(S){S=this.root+S;var E=this.files[S];if(E||(S.slice(-1)!=="/"&&(S+="/"),E=this.files[S]),E&&!E.dir)delete this.files[S];else for(var C=this.filter(function(R,L){return L.name.slice(0,S.length)===S}),A=0;A<C.length;A++)delete this.files[C[A].name];return this},generate:function(){throw new Error("This method has been removed in JSZip 3.0, please check the upgrade guide.")},generateInternalStream:function(S){var E,C={};try{if((C=c.extend(S||{},{streamFiles:!1,compression:"STORE",compressionOptions:null,type:"",platform:"DOS",comment:null,mimeType:"application/zip",encodeFileName:a.utf8encode})).type=C.type.toLowerCase(),C.compression=C.compression.toUpperCase(),C.type==="binarystring"&&(C.type="string"),!C.type)throw new Error("No output type specified.");c.checkSupport(C.type),C.platform!=="darwin"&&C.platform!=="freebsd"&&C.platform!=="linux"&&C.platform!=="sunos"||(C.platform="UNIX"),C.platform==="win32"&&(C.platform="DOS");var A=C.comment||this.comment||"";E=p.generateWorker(this,C,A)}catch(R){(E=new l("error")).error(R)}return new u(E,C.type||"string",C.mimeType)},generateAsync:function(S,E){return this.generateInternalStream(S).accumulate(E)},generateNodeStream:function(S,E){return(S=S||{}).type||(S.type="nodebuffer"),this.generateInternalStream(S).toNodejsStream(E)}};i.exports=w},{"./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(r,i,o){i.exports=r("stream")},{stream:void 0}],17:[function(r,i,o){var s=r("./DataReader");function a(c){s.call(this,c);for(var l=0;l<this.data.length;l++)c[l]=255&c[l]}r("../utils").inherits(a,s),a.prototype.byteAt=function(c){return this.data[this.zero+c]},a.prototype.lastIndexOfSignature=function(c){for(var l=c.charCodeAt(0),u=c.charCodeAt(1),d=c.charCodeAt(2),h=c.charCodeAt(3),f=this.length-4;0<=f;--f)if(this.data[f]===l&&this.data[f+1]===u&&this.data[f+2]===d&&this.data[f+3]===h)return f-this.zero;return-1},a.prototype.readAndCheckSignature=function(c){var l=c.charCodeAt(0),u=c.charCodeAt(1),d=c.charCodeAt(2),h=c.charCodeAt(3),f=this.readData(4);return l===f[0]&&u===f[1]&&d===f[2]&&h===f[3]},a.prototype.readData=function(c){if(this.checkOffset(c),c===0)return[];var l=this.data.slice(this.zero+this.index,this.zero+this.index+c);return this.index+=c,l},i.exports=a},{"../utils":32,"./DataReader":18}],18:[function(r,i,o){var s=r("../utils");function a(c){this.data=c,this.length=c.length,this.index=0,this.zero=0}a.prototype={checkOffset:function(c){this.checkIndex(this.index+c)},checkIndex:function(c){if(this.length<this.zero+c||c<0)throw new Error("End of data reached (data length = "+this.length+", asked index = "+c+"). Corrupted zip ?")},setIndex:function(c){this.checkIndex(c),this.index=c},skip:function(c){this.setIndex(this.index+c)},byteAt:function(){},readInt:function(c){var l,u=0;for(this.checkOffset(c),l=this.index+c-1;l>=this.index;l--)u=(u<<8)+this.byteAt(l);return this.index+=c,u},readString:function(c){return s.transformTo("string",this.readData(c))},readData:function(){},lastIndexOfSignature:function(){},readAndCheckSignature:function(){},readDate:function(){var c=this.readInt(4);return new Date(Date.UTC(1980+(c>>25&127),(c>>21&15)-1,c>>16&31,c>>11&31,c>>5&63,(31&c)<<1))}},i.exports=a},{"../utils":32}],19:[function(r,i,o){var s=r("./Uint8ArrayReader");function a(c){s.call(this,c)}r("../utils").inherits(a,s),a.prototype.readData=function(c){this.checkOffset(c);var l=this.data.slice(this.zero+this.index,this.zero+this.index+c);return this.index+=c,l},i.exports=a},{"../utils":32,"./Uint8ArrayReader":21}],20:[function(r,i,o){var s=r("./DataReader");function a(c){s.call(this,c)}r("../utils").inherits(a,s),a.prototype.byteAt=function(c){return this.data.charCodeAt(this.zero+c)},a.prototype.lastIndexOfSignature=function(c){return this.data.lastIndexOf(c)-this.zero},a.prototype.readAndCheckSignature=function(c){return c===this.readData(4)},a.prototype.readData=function(c){this.checkOffset(c);var l=this.data.slice(this.zero+this.index,this.zero+this.index+c);return this.index+=c,l},i.exports=a},{"../utils":32,"./DataReader":18}],21:[function(r,i,o){var s=r("./ArrayReader");function a(c){s.call(this,c)}r("../utils").inherits(a,s),a.prototype.readData=function(c){if(this.checkOffset(c),c===0)return new Uint8Array(0);var l=this.data.subarray(this.zero+this.index,this.zero+this.index+c);return this.index+=c,l},i.exports=a},{"../utils":32,"./ArrayReader":17}],22:[function(r,i,o){var s=r("../utils"),a=r("../support"),c=r("./ArrayReader"),l=r("./StringReader"),u=r("./NodeBufferReader"),d=r("./Uint8ArrayReader");i.exports=function(h){var f=s.getTypeOf(h);return s.checkSupport(f),f!=="string"||a.uint8array?f==="nodebuffer"?new u(h):a.uint8array?new d(s.transformTo("uint8array",h)):new c(s.transformTo("array",h)):new l(h)}},{"../support":30,"../utils":32,"./ArrayReader":17,"./NodeBufferReader":19,"./StringReader":20,"./Uint8ArrayReader":21}],23:[function(r,i,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(r,i,o){var s=r("./GenericWorker"),a=r("../utils");function c(l){s.call(this,"ConvertWorker to "+l),this.destType=l}a.inherits(c,s),c.prototype.processChunk=function(l){this.push({data:a.transformTo(this.destType,l.data),meta:l.meta})},i.exports=c},{"../utils":32,"./GenericWorker":28}],25:[function(r,i,o){var s=r("./GenericWorker"),a=r("../crc32");function c(){s.call(this,"Crc32Probe"),this.withStreamInfo("crc32",0)}r("../utils").inherits(c,s),c.prototype.processChunk=function(l){this.streamInfo.crc32=a(l.data,this.streamInfo.crc32||0),this.push(l)},i.exports=c},{"../crc32":4,"../utils":32,"./GenericWorker":28}],26:[function(r,i,o){var s=r("../utils"),a=r("./GenericWorker");function c(l){a.call(this,"DataLengthProbe for "+l),this.propName=l,this.withStreamInfo(l,0)}s.inherits(c,a),c.prototype.processChunk=function(l){if(l){var u=this.streamInfo[this.propName]||0;this.streamInfo[this.propName]=u+l.data.length}a.prototype.processChunk.call(this,l)},i.exports=c},{"../utils":32,"./GenericWorker":28}],27:[function(r,i,o){var s=r("../utils"),a=r("./GenericWorker");function c(l){a.call(this,"DataWorker");var u=this;this.dataIsReady=!1,this.index=0,this.max=0,this.data=null,this.type="",this._tickScheduled=!1,l.then(function(d){u.dataIsReady=!0,u.data=d,u.max=d&&d.length||0,u.type=s.getTypeOf(d),u.isPaused||u._tickAndRepeat()},function(d){u.error(d)})}s.inherits(c,a),c.prototype.cleanUp=function(){a.prototype.cleanUp.call(this),this.data=null},c.prototype.resume=function(){return!!a.prototype.resume.call(this)&&(!this._tickScheduled&&this.dataIsReady&&(this._tickScheduled=!0,s.delay(this._tickAndRepeat,[],this)),!0)},c.prototype._tickAndRepeat=function(){this._tickScheduled=!1,this.isPaused||this.isFinished||(this._tick(),this.isFinished||(s.delay(this._tickAndRepeat,[],this),this._tickScheduled=!0))},c.prototype._tick=function(){if(this.isPaused||this.isFinished)return!1;var l=null,u=Math.min(this.max,this.index+16384);if(this.index>=this.max)return this.end();switch(this.type){case"string":l=this.data.substring(this.index,u);break;case"uint8array":l=this.data.subarray(this.index,u);break;case"array":case"nodebuffer":l=this.data.slice(this.index,u)}return this.index=u,this.push({data:l,meta:{percent:this.max?this.index/this.max*100:0}})},i.exports=c},{"../utils":32,"./GenericWorker":28}],28:[function(r,i,o){function s(a){this.name=a||"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(a){this.emit("data",a)},end:function(){if(this.isFinished)return!1;this.flush();try{this.emit("end"),this.cleanUp(),this.isFinished=!0}catch(a){this.emit("error",a)}return!0},error:function(a){return!this.isFinished&&(this.isPaused?this.generatedError=a:(this.isFinished=!0,this.emit("error",a),this.previous&&this.previous.error(a),this.cleanUp()),!0)},on:function(a,c){return this._listeners[a].push(c),this},cleanUp:function(){this.streamInfo=this.generatedError=this.extraStreamInfo=null,this._listeners=[]},emit:function(a,c){if(this._listeners[a])for(var l=0;l<this._listeners[a].length;l++)this._listeners[a][l].call(this,c)},pipe:function(a){return a.registerPrevious(this)},registerPrevious:function(a){if(this.isLocked)throw new Error("The stream '"+this+"' has already been used.");this.streamInfo=a.streamInfo,this.mergeStreamInfo(),this.previous=a;var c=this;return a.on("data",function(l){c.processChunk(l)}),a.on("end",function(){c.end()}),a.on("error",function(l){c.error(l)}),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 a=this.isPaused=!1;return this.generatedError&&(this.error(this.generatedError),a=!0),this.previous&&this.previous.resume(),!a},flush:function(){},processChunk:function(a){this.push(a)},withStreamInfo:function(a,c){return this.extraStreamInfo[a]=c,this.mergeStreamInfo(),this},mergeStreamInfo:function(){for(var a in this.extraStreamInfo)Object.prototype.hasOwnProperty.call(this.extraStreamInfo,a)&&(this.streamInfo[a]=this.extraStreamInfo[a])},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 a="Worker "+this.name;return this.previous?this.previous+" -> "+a:a}},i.exports=s},{}],29:[function(r,i,o){var s=r("../utils"),a=r("./ConvertWorker"),c=r("./GenericWorker"),l=r("../base64"),u=r("../support"),d=r("../external"),h=null;if(u.nodestream)try{h=r("../nodejs/NodejsStreamOutputAdapter")}catch{}function f(m,g){return new d.Promise(function(y,_){var x=[],b=m._internalType,w=m._outputType,S=m._mimeType;m.on("data",function(E,C){x.push(E),g&&g(C)}).on("error",function(E){x=[],_(E)}).on("end",function(){try{var E=(function(C,A,R){switch(C){case"blob":return s.newBlob(s.transformTo("arraybuffer",A),R);case"base64":return l.encode(A);default:return s.transformTo(C,A)}})(w,(function(C,A){var R,L=0,O=null,F=0;for(R=0;R<A.length;R++)F+=A[R].length;switch(C){case"string":return A.join("");case"array":return Array.prototype.concat.apply([],A);case"uint8array":for(O=new Uint8Array(F),R=0;R<A.length;R++)O.set(A[R],L),L+=A[R].length;return O;case"nodebuffer":return Buffer.concat(A);default:throw new Error("concat : unsupported type '"+C+"'")}})(b,x),S);y(E)}catch(C){_(C)}x=[]}).resume()})}function p(m,g,y){var _=g;switch(g){case"blob":case"arraybuffer":_="uint8array";break;case"base64":_="string"}try{this._internalType=_,this._outputType=g,this._mimeType=y,s.checkSupport(_),this._worker=m.pipe(new a(_)),m.lock()}catch(x){this._worker=new c("error"),this._worker.error(x)}}p.prototype={accumulate:function(m){return f(this,m)},on:function(m,g){var y=this;return m==="data"?this._worker.on(m,function(_){g.call(y,_.data,_.meta)}):this._worker.on(m,function(){s.delay(g,arguments,y)}),this},resume:function(){return s.delay(this._worker.resume,[],this._worker),this},pause:function(){return this._worker.pause(),this},toNodejsStream:function(m){if(s.checkSupport("nodestream"),this._outputType!=="nodebuffer")throw new Error(this._outputType+" is not supported by this method");return new h(this,{objectMode:this._outputType!=="nodebuffer"},m)}},i.exports=p},{"../base64":1,"../external":6,"../nodejs/NodejsStreamOutputAdapter":13,"../support":30,"../utils":32,"./ConvertWorker":24,"./GenericWorker":28}],30:[function(r,i,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 a=new(self.BlobBuilder||self.WebKitBlobBuilder||self.MozBlobBuilder||self.MSBlobBuilder);a.append(s),o.blob=a.getBlob("application/zip").size===0}catch{o.blob=!1}}}try{o.nodestream=!!r("readable-stream").Readable}catch{o.nodestream=!1}},{"readable-stream":16}],31:[function(r,i,o){for(var s=r("./utils"),a=r("./support"),c=r("./nodejsUtils"),l=r("./stream/GenericWorker"),u=new Array(256),d=0;d<256;d++)u[d]=252<=d?6:248<=d?5:240<=d?4:224<=d?3:192<=d?2:1;u[254]=u[254]=1;function h(){l.call(this,"utf-8 decode"),this.leftOver=null}function f(){l.call(this,"utf-8 encode")}o.utf8encode=function(p){return a.nodebuffer?c.newBufferFrom(p,"utf-8"):(function(m){var g,y,_,x,b,w=m.length,S=0;for(x=0;x<w;x++)(64512&(y=m.charCodeAt(x)))==55296&&x+1<w&&(64512&(_=m.charCodeAt(x+1)))==56320&&(y=65536+(y-55296<<10)+(_-56320),x++),S+=y<128?1:y<2048?2:y<65536?3:4;for(g=a.uint8array?new Uint8Array(S):new Array(S),x=b=0;b<S;x++)(64512&(y=m.charCodeAt(x)))==55296&&x+1<w&&(64512&(_=m.charCodeAt(x+1)))==56320&&(y=65536+(y-55296<<10)+(_-56320),x++),y<128?g[b++]=y:(y<2048?g[b++]=192|y>>>6:(y<65536?g[b++]=224|y>>>12:(g[b++]=240|y>>>18,g[b++]=128|y>>>12&63),g[b++]=128|y>>>6&63),g[b++]=128|63&y);return g})(p)},o.utf8decode=function(p){return a.nodebuffer?s.transformTo("nodebuffer",p).toString("utf-8"):(function(m){var g,y,_,x,b=m.length,w=new Array(2*b);for(g=y=0;g<b;)if((_=m[g++])<128)w[y++]=_;else if(4<(x=u[_]))w[y++]=65533,g+=x-1;else{for(_&=x===2?31:x===3?15:7;1<x&&g<b;)_=_<<6|63&m[g++],x--;1<x?w[y++]=65533:_<65536?w[y++]=_:(_-=65536,w[y++]=55296|_>>10&1023,w[y++]=56320|1023&_)}return w.length!==y&&(w.subarray?w=w.subarray(0,y):w.length=y),s.applyFromCharCode(w)})(p=s.transformTo(a.uint8array?"uint8array":"array",p))},s.inherits(h,l),h.prototype.processChunk=function(p){var m=s.transformTo(a.uint8array?"uint8array":"array",p.data);if(this.leftOver&&this.leftOver.length){if(a.uint8array){var g=m;(m=new Uint8Array(g.length+this.leftOver.length)).set(this.leftOver,0),m.set(g,this.leftOver.length)}else m=this.leftOver.concat(m);this.leftOver=null}var y=(function(x,b){var w;for((b=b||x.length)>x.length&&(b=x.length),w=b-1;0<=w&&(192&x[w])==128;)w--;return w<0||w===0?b:w+u[x[w]]>b?w:b})(m),_=m;y!==m.length&&(a.uint8array?(_=m.subarray(0,y),this.leftOver=m.subarray(y,m.length)):(_=m.slice(0,y),this.leftOver=m.slice(y,m.length))),this.push({data:o.utf8decode(_),meta:p.meta})},h.prototype.flush=function(){this.leftOver&&this.leftOver.length&&(this.push({data:o.utf8decode(this.leftOver),meta:{}}),this.leftOver=null)},o.Utf8DecodeWorker=h,s.inherits(f,l),f.prototype.processChunk=function(p){this.push({data:o.utf8encode(p.data),meta:p.meta})},o.Utf8EncodeWorker=f},{"./nodejsUtils":14,"./stream/GenericWorker":28,"./support":30,"./utils":32}],32:[function(r,i,o){var s=r("./support"),a=r("./base64"),c=r("./nodejsUtils"),l=r("./external");function u(g){return g}function d(g,y){for(var _=0;_<g.length;++_)y[_]=255&g.charCodeAt(_);return y}r("setimmediate"),o.newBlob=function(g,y){o.checkSupport("blob");try{return new Blob([g],{type:y})}catch{try{var _=new(self.BlobBuilder||self.WebKitBlobBuilder||self.MozBlobBuilder||self.MSBlobBuilder);return _.append(g),_.getBlob(y)}catch{throw new Error("Bug : can't construct the Blob.")}}};var h={stringifyByChunk:function(g,y,_){var x=[],b=0,w=g.length;if(w<=_)return String.fromCharCode.apply(null,g);for(;b<w;)y==="array"||y==="nodebuffer"?x.push(String.fromCharCode.apply(null,g.slice(b,Math.min(b+_,w)))):x.push(String.fromCharCode.apply(null,g.subarray(b,Math.min(b+_,w)))),b+=_;return x.join("")},stringifyByChar:function(g){for(var y="",_=0;_<g.length;_++)y+=String.fromCharCode(g[_]);return y},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,c.allocBuffer(1)).length===1}catch{return!1}})()}};function f(g){var y=65536,_=o.getTypeOf(g),x=!0;if(_==="uint8array"?x=h.applyCanBeUsed.uint8array:_==="nodebuffer"&&(x=h.applyCanBeUsed.nodebuffer),x)for(;1<y;)try{return h.stringifyByChunk(g,_,y)}catch{y=Math.floor(y/2)}return h.stringifyByChar(g)}function p(g,y){for(var _=0;_<g.length;_++)y[_]=g[_];return y}o.applyFromCharCode=f;var m={};m.string={string:u,array:function(g){return d(g,new Array(g.length))},arraybuffer:function(g){return m.string.uint8array(g).buffer},uint8array:function(g){return d(g,new Uint8Array(g.length))},nodebuffer:function(g){return d(g,c.allocBuffer(g.length))}},m.array={string:f,array:u,arraybuffer:function(g){return new Uint8Array(g).buffer},uint8array:function(g){return new Uint8Array(g)},nodebuffer:function(g){return c.newBufferFrom(g)}},m.arraybuffer={string:function(g){return f(new Uint8Array(g))},array:function(g){return p(new Uint8Array(g),new Array(g.byteLength))},arraybuffer:u,uint8array:function(g){return new Uint8Array(g)},nodebuffer:function(g){return c.newBufferFrom(new Uint8Array(g))}},m.uint8array={string:f,array:function(g){return p(g,new Array(g.length))},arraybuffer:function(g){return g.buffer},uint8array:u,nodebuffer:function(g){return c.newBufferFrom(g)}},m.nodebuffer={string:f,array:function(g){return p(g,new Array(g.length))},arraybuffer:function(g){return m.nodebuffer.uint8array(g).buffer},uint8array:function(g){return p(g,new Uint8Array(g.length))},nodebuffer:u},o.transformTo=function(g,y){if(y=y||"",!g)return y;o.checkSupport(g);var _=o.getTypeOf(y);return m[_][g](y)},o.resolve=function(g){for(var y=g.split("/"),_=[],x=0;x<y.length;x++){var b=y[x];b==="."||b===""&&x!==0&&x!==y.length-1||(b===".."?_.pop():_.push(b))}return _.join("/")},o.getTypeOf=function(g){return typeof g=="string"?"string":Object.prototype.toString.call(g)==="[object Array]"?"array":s.nodebuffer&&c.isBuffer(g)?"nodebuffer":s.uint8array&&g instanceof Uint8Array?"uint8array":s.arraybuffer&&g instanceof ArrayBuffer?"arraybuffer":void 0},o.checkSupport=function(g){if(!s[g.toLowerCase()])throw new Error(g+" is not supported by this platform")},o.MAX_VALUE_16BITS=65535,o.MAX_VALUE_32BITS=-1,o.pretty=function(g){var y,_,x="";for(_=0;_<(g||"").length;_++)x+="\\x"+((y=g.charCodeAt(_))<16?"0":"")+y.toString(16).toUpperCase();return x},o.delay=function(g,y,_){setImmediate(function(){g.apply(_||null,y||[])})},o.inherits=function(g,y){function _(){}_.prototype=y.prototype,g.prototype=new _},o.extend=function(){var g,y,_={};for(g=0;g<arguments.length;g++)for(y in arguments[g])Object.prototype.hasOwnProperty.call(arguments[g],y)&&_[y]===void 0&&(_[y]=arguments[g][y]);return _},o.prepareContent=function(g,y,_,x,b){return l.Promise.resolve(y).then(function(w){return s.blob&&(w instanceof Blob||["[object File]","[object Blob]"].indexOf(Object.prototype.toString.call(w))!==-1)&&typeof FileReader<"u"?new l.Promise(function(S,E){var C=new FileReader;C.onload=function(A){S(A.target.result)},C.onerror=function(A){E(A.target.error)},C.readAsArrayBuffer(w)}):w}).then(function(w){var S=o.getTypeOf(w);return S?(S==="arraybuffer"?w=o.transformTo("uint8array",w):S==="string"&&(b?w=a.decode(w):_&&x!==!0&&(w=(function(E){return d(E,s.uint8array?new Uint8Array(E.length):new Array(E.length))})(w))),w):l.Promise.reject(new Error("Can't read the data of '"+g+"'. Is it in a supported JavaScript type (String, Blob, ArrayBuffer, etc) ?"))})}},{"./base64":1,"./external":6,"./nodejsUtils":14,"./support":30,setimmediate:54}],33:[function(r,i,o){var s=r("./reader/readerFor"),a=r("./utils"),c=r("./signature"),l=r("./zipEntry"),u=r("./support");function d(h){this.files=[],this.loadOptions=h}d.prototype={checkSignature:function(h){if(!this.reader.readAndCheckSignature(h)){this.reader.index-=4;var f=this.reader.readString(4);throw new Error("Corrupted zip or bug: unexpected signature ("+a.pretty(f)+", expected "+a.pretty(h)+")")}},isSignature:function(h,f){var p=this.reader.index;this.reader.setIndex(h);var m=this.reader.readString(4)===f;return this.reader.setIndex(p),m},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 h=this.reader.readData(this.zipCommentLength),f=u.uint8array?"uint8array":"array",p=a.transformTo(f,h);this.zipComment=this.loadOptions.decodeFileName(p)},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 h,f,p,m=this.zip64EndOfCentralSize-44;0<m;)h=this.reader.readInt(2),f=this.reader.readInt(4),p=this.reader.readData(f),this.zip64ExtensibleData[h]={id:h,length:f,value:p}},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 h,f;for(h=0;h<this.files.length;h++)f=this.files[h],this.reader.setIndex(f.localHeaderOffset),this.checkSignature(c.LOCAL_FILE_HEADER),f.readLocalPart(this.reader),f.handleUTF8(),f.processAttributes()},readCentralDir:function(){var h;for(this.reader.setIndex(this.centralDirOffset);this.reader.readAndCheckSignature(c.CENTRAL_FILE_HEADER);)(h=new l({zip64:this.zip64},this.loadOptions)).readCentralPart(this.reader),this.files.push(h);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 h=this.reader.lastIndexOfSignature(c.CENTRAL_DIRECTORY_END);if(h<0)throw this.isSignature(0,c.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(h);var f=h;if(this.checkSignature(c.CENTRAL_DIRECTORY_END),this.readBlockEndOfCentral(),this.diskNumber===a.MAX_VALUE_16BITS||this.diskWithCentralDirStart===a.MAX_VALUE_16BITS||this.centralDirRecordsOnThisDisk===a.MAX_VALUE_16BITS||this.centralDirRecords===a.MAX_VALUE_16BITS||this.centralDirSize===a.MAX_VALUE_32BITS||this.centralDirOffset===a.MAX_VALUE_32BITS){if(this.zip64=!0,(h=this.reader.lastIndexOfSignature(c.ZIP64_CENTRAL_DIRECTORY_LOCATOR))<0)throw new Error("Corrupted zip: can't find the ZIP64 end of central directory locator");if(this.reader.setIndex(h),this.checkSignature(c.ZIP64_CENTRAL_DIRECTORY_LOCATOR),this.readBlockZip64EndOfCentralLocator(),!this.isSignature(this.relativeOffsetEndOfZip64CentralDir,c.ZIP64_CENTRAL_DIRECTORY_END)&&(this.relativeOffsetEndOfZip64CentralDir=this.reader.lastIndexOfSignature(c.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(c.ZIP64_CENTRAL_DIRECTORY_END),this.readBlockZip64EndOfCentral()}var p=this.centralDirOffset+this.centralDirSize;this.zip64&&(p+=20,p+=12+this.zip64EndOfCentralSize);var m=f-p;if(0<m)this.isSignature(f,c.CENTRAL_FILE_HEADER)||(this.reader.zero=m);else if(m<0)throw new Error("Corrupted zip: missing "+Math.abs(m)+" bytes.")},prepareReader:function(h){this.reader=s(h)},load:function(h){this.prepareReader(h),this.readEndOfCentral(),this.readCentralDir(),this.readLocalFiles()}},i.exports=d},{"./reader/readerFor":22,"./signature":23,"./support":30,"./utils":32,"./zipEntry":34}],34:[function(r,i,o){var s=r("./reader/readerFor"),a=r("./utils"),c=r("./compressedObject"),l=r("./crc32"),u=r("./utf8"),d=r("./compressions"),h=r("./support");function f(p,m){this.options=p,this.loadOptions=m}f.prototype={isEncrypted:function(){return(1&this.bitFlag)==1},useUTF8:function(){return(2048&this.bitFlag)==2048},readLocalPart:function(p){var m,g;if(p.skip(22),this.fileNameLength=p.readInt(2),g=p.readInt(2),this.fileName=p.readData(this.fileNameLength),p.skip(g),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((m=(function(y){for(var _ in d)if(Object.prototype.hasOwnProperty.call(d,_)&&d[_].magic===y)return d[_];return null})(this.compressionMethod))===null)throw new Error("Corrupted zip : compression "+a.pretty(this.compressionMethod)+" unknown (inner file : "+a.transformTo("string",this.fileName)+")");this.decompressed=new c(this.compressedSize,this.uncompressedSize,this.crc32,m,p.readData(this.compressedSize))},readCentralPart:function(p){this.versionMadeBy=p.readInt(2),p.skip(2),this.bitFlag=p.readInt(2),this.compressionMethod=p.readString(2),this.date=p.readDate(),this.crc32=p.readInt(4),this.compressedSize=p.readInt(4),this.uncompressedSize=p.readInt(4);var m=p.readInt(2);if(this.extraFieldsLength=p.readInt(2),this.fileCommentLength=p.readInt(2),this.diskNumberStart=p.readInt(2),this.internalFileAttributes=p.readInt(2),this.externalFileAttributes=p.readInt(4),this.localHeaderOffset=p.readInt(4),this.isEncrypted())throw new Error("Encrypted zip are not supported");p.skip(m),this.readExtraFields(p),this.parseZIP64ExtraField(p),this.fileComment=p.readData(this.fileCommentLength)},processAttributes:function(){this.unixPermissions=null,this.dosPermissions=null;var p=this.versionMadeBy>>8;this.dir=!!(16&this.externalFileAttributes),p==0&&(this.dosPermissions=63&this.externalFileAttributes),p==3&&(this.unixPermissions=this.externalFileAttributes>>16&65535),this.dir||this.fileNameStr.slice(-1)!=="/"||(this.dir=!0)},parseZIP64ExtraField:function(){if(this.extraFields[1]){var p=s(this.extraFields[1].value);this.uncompressedSize===a.MAX_VALUE_32BITS&&(this.uncompressedSize=p.readInt(8)),this.compressedSize===a.MAX_VALUE_32BITS&&(this.compressedSize=p.readInt(8)),this.localHeaderOffset===a.MAX_VALUE_32BITS&&(this.localHeaderOffset=p.readInt(8)),this.diskNumberStart===a.MAX_VALUE_32BITS&&(this.diskNumberStart=p.readInt(4))}},readExtraFields:function(p){var m,g,y,_=p.index+this.extraFieldsLength;for(this.extraFields||(this.extraFields={});p.index+4<_;)m=p.readInt(2),g=p.readInt(2),y=p.readData(g),this.extraFields[m]={id:m,length:g,value:y};p.setIndex(_)},handleUTF8:function(){var p=h.uint8array?"uint8array":"array";if(this.useUTF8())this.fileNameStr=u.utf8decode(this.fileName),this.fileCommentStr=u.utf8decode(this.fileComment);else{var m=this.findExtraFieldUnicodePath();if(m!==null)this.fileNameStr=m;else{var g=a.transformTo(p,this.fileName);this.fileNameStr=this.loadOptions.decodeFileName(g)}var y=this.findExtraFieldUnicodeComment();if(y!==null)this.fileCommentStr=y;else{var _=a.transformTo(p,this.fileComment);this.fileCommentStr=this.loadOptions.decodeFileName(_)}}},findExtraFieldUnicodePath:function(){var p=this.extraFields[28789];if(p){var m=s(p.value);return m.readInt(1)!==1||l(this.fileName)!==m.readInt(4)?null:u.utf8decode(m.readData(p.length-5))}return null},findExtraFieldUnicodeComment:function(){var p=this.extraFields[25461];if(p){var m=s(p.value);return m.readInt(1)!==1||l(this.fileComment)!==m.readInt(4)?null:u.utf8decode(m.readData(p.length-5))}return null}},i.exports=f},{"./compressedObject":2,"./compressions":3,"./crc32":4,"./reader/readerFor":22,"./support":30,"./utf8":31,"./utils":32}],35:[function(r,i,o){function s(m,g,y){this.name=m,this.dir=y.dir,this.date=y.date,this.comment=y.comment,this.unixPermissions=y.unixPermissions,this.dosPermissions=y.dosPermissions,this._data=g,this._dataBinary=y.binary,this.options={compression:y.compression,compressionOptions:y.compressionOptions}}var a=r("./stream/StreamHelper"),c=r("./stream/DataWorker"),l=r("./utf8"),u=r("./compressedObject"),d=r("./stream/GenericWorker");s.prototype={internalStream:function(m){var g=null,y="string";try{if(!m)throw new Error("No output type specified.");var _=(y=m.toLowerCase())==="string"||y==="text";y!=="binarystring"&&y!=="text"||(y="string"),g=this._decompressWorker();var x=!this._dataBinary;x&&!_&&(g=g.pipe(new l.Utf8EncodeWorker)),!x&&_&&(g=g.pipe(new l.Utf8DecodeWorker))}catch(b){(g=new d("error")).error(b)}return new a(g,y,"")},async:function(m,g){return this.internalStream(m).accumulate(g)},nodeStream:function(m,g){return this.internalStream(m||"nodebuffer").toNodejsStream(g)},_compressWorker:function(m,g){if(this._data instanceof u&&this._data.compression.magic===m.magic)return this._data.getCompressedWorker();var y=this._decompressWorker();return this._dataBinary||(y=y.pipe(new l.Utf8EncodeWorker)),u.createWorkerFrom(y,m,g)},_decompressWorker:function(){return this._data instanceof u?this._data.getContentWorker():this._data instanceof d?this._data:new c(this._data)}};for(var h=["asText","asBinary","asNodeBuffer","asUint8Array","asArrayBuffer"],f=function(){throw new Error("This method has been removed in JSZip 3.0, please check the upgrade guide.")},p=0;p<h.length;p++)s.prototype[h[p]]=f;i.exports=s},{"./compressedObject":2,"./stream/DataWorker":27,"./stream/GenericWorker":28,"./stream/StreamHelper":29,"./utf8":31}],36:[function(r,i,o){(function(s){var a,c,l=s.MutationObserver||s.WebKitMutationObserver;if(l){var u=0,d=new l(m),h=s.document.createTextNode("");d.observe(h,{characterData:!0}),a=function(){h.data=u=++u%2}}else if(s.setImmediate||s.MessageChannel===void 0)a="document"in s&&"onreadystatechange"in s.document.createElement("script")?function(){var g=s.document.createElement("script");g.onreadystatechange=function(){m(),g.onreadystatechange=null,g.parentNode.removeChild(g),g=null},s.document.documentElement.appendChild(g)}:function(){setTimeout(m,0)};else{var f=new s.MessageChannel;f.port1.onmessage=m,a=function(){f.port2.postMessage(0)}}var p=[];function m(){var g,y;c=!0;for(var _=p.length;_;){for(y=p,p=[],g=-1;++g<_;)y[g]();_=p.length}c=!1}i.exports=function(g){p.push(g)!==1||c||a()}}).call(this,typeof nD<"u"?nD:typeof self<"u"?self:typeof window<"u"?window:{})},{}],37:[function(r,i,o){var s=r("immediate");function a(){}var c={},l=["REJECTED"],u=["FULFILLED"],d=["PENDING"];function h(_){if(typeof _!="function")throw new TypeError("resolver must be a function");this.state=d,this.queue=[],this.outcome=void 0,_!==a&&g(this,_)}function f(_,x,b){this.promise=_,typeof x=="function"&&(this.onFulfilled=x,this.callFulfilled=this.otherCallFulfilled),typeof b=="function"&&(this.onRejected=b,this.callRejected=this.otherCallRejected)}function p(_,x,b){s(function(){var w;try{w=x(b)}catch(S){return c.reject(_,S)}w===_?c.reject(_,new TypeError("Cannot resolve promise with itself")):c.resolve(_,w)})}function m(_){var x=_&&_.then;if(_&&(typeof _=="object"||typeof _=="function")&&typeof x=="function")return function(){x.apply(_,arguments)}}function g(_,x){var b=!1;function w(C){b||(b=!0,c.reject(_,C))}function S(C){b||(b=!0,c.resolve(_,C))}var E=y(function(){x(S,w)});E.status==="error"&&w(E.value)}function y(_,x){var b={};try{b.value=_(x),b.status="success"}catch(w){b.status="error",b.value=w}return b}(i.exports=h).prototype.finally=function(_){if(typeof _!="function")return this;var x=this.constructor;return this.then(function(b){return x.resolve(_()).then(function(){return b})},function(b){return x.resolve(_()).then(function(){throw b})})},h.prototype.catch=function(_){return this.then(null,_)},h.prototype.then=function(_,x){if(typeof _!="function"&&this.state===u||typeof x!="function"&&this.state===l)return this;var b=new this.constructor(a);return this.state!==d?p(b,this.state===u?_:x,this.outcome):this.queue.push(new f(b,_,x)),b},f.prototype.callFulfilled=function(_){c.resolve(this.promise,_)},f.prototype.otherCallFulfilled=function(_){p(this.promise,this.onFulfilled,_)},f.prototype.callRejected=function(_){c.reject(this.promise,_)},f.prototype.otherCallRejected=function(_){p(this.promise,this.onRejected,_)},c.resolve=function(_,x){var b=y(m,x);if(b.status==="error")return c.reject(_,b.value);var w=b.value;if(w)g(_,w);else{_.state=u,_.outcome=x;for(var S=-1,E=_.queue.length;++S<E;)_.queue[S].callFulfilled(x)}return _},c.reject=function(_,x){_.state=l,_.outcome=x;for(var b=-1,w=_.queue.length;++b<w;)_.queue[b].callRejected(x);return _},h.resolve=function(_){return _ instanceof this?_:c.resolve(new this(a),_)},h.reject=function(_){var x=new this(a);return c.reject(x,_)},h.all=function(_){var x=this;if(Object.prototype.toString.call(_)!=="[object Array]")return this.reject(new TypeError("must be an array"));var b=_.length,w=!1;if(!b)return this.resolve([]);for(var S=new Array(b),E=0,C=-1,A=new this(a);++C<b;)R(_[C],C);return A;function R(L,O){x.resolve(L).then(function(F){S[O]=F,++E!==b||w||(w=!0,c.resolve(A,S))},function(F){w||(w=!0,c.reject(A,F))})}},h.race=function(_){var x=this;if(Object.prototype.toString.call(_)!=="[object Array]")return this.reject(new TypeError("must be an array"));var b=_.length,w=!1;if(!b)return this.resolve([]);for(var S=-1,E=new this(a);++S<b;)C=_[S],x.resolve(C).then(function(A){w||(w=!0,c.resolve(E,A))},function(A){w||(w=!0,c.reject(E,A))});var C;return E}},{immediate:36}],38:[function(r,i,o){var s={};(0,r("./lib/utils/common").assign)(s,r("./lib/deflate"),r("./lib/inflate"),r("./lib/zlib/constants")),i.exports=s},{"./lib/deflate":39,"./lib/inflate":40,"./lib/utils/common":41,"./lib/zlib/constants":44}],39:[function(r,i,o){var s=r("./zlib/deflate"),a=r("./utils/common"),c=r("./utils/strings"),l=r("./zlib/messages"),u=r("./zlib/zstream"),d=Object.prototype.toString,h=0,f=-1,p=0,m=8;function g(_){if(!(this instanceof g))return new g(_);this.options=a.assign({level:f,method:m,chunkSize:16384,windowBits:15,memLevel:8,strategy:p,to:""},_||{});var x=this.options;x.raw&&0<x.windowBits?x.windowBits=-x.windowBits:x.gzip&&0<x.windowBits&&x.windowBits<16&&(x.windowBits+=16),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new u,this.strm.avail_out=0;var b=s.deflateInit2(this.strm,x.level,x.method,x.windowBits,x.memLevel,x.strategy);if(b!==h)throw new Error(l[b]);if(x.header&&s.deflateSetHeader(this.strm,x.header),x.dictionary){var w;if(w=typeof x.dictionary=="string"?c.string2buf(x.dictionary):d.call(x.dictionary)==="[object ArrayBuffer]"?new Uint8Array(x.dictionary):x.dictionary,(b=s.deflateSetDictionary(this.strm,w))!==h)throw new Error(l[b]);this._dict_set=!0}}function y(_,x){var b=new g(x);if(b.push(_,!0),b.err)throw b.msg||l[b.err];return b.result}g.prototype.push=function(_,x){var b,w,S=this.strm,E=this.options.chunkSize;if(this.ended)return!1;w=x===~~x?x:x===!0?4:0,typeof _=="string"?S.input=c.string2buf(_):d.call(_)==="[object ArrayBuffer]"?S.input=new Uint8Array(_):S.input=_,S.next_in=0,S.avail_in=S.input.length;do{if(S.avail_out===0&&(S.output=new a.Buf8(E),S.next_out=0,S.avail_out=E),(b=s.deflate(S,w))!==1&&b!==h)return this.onEnd(b),!(this.ended=!0);S.avail_out!==0&&(S.avail_in!==0||w!==4&&w!==2)||(this.options.to==="string"?this.onData(c.buf2binstring(a.shrinkBuf(S.output,S.next_out))):this.onData(a.shrinkBuf(S.output,S.next_out)))}while((0<S.avail_in||S.avail_out===0)&&b!==1);return w===4?(b=s.deflateEnd(this.strm),this.onEnd(b),this.ended=!0,b===h):w!==2||(this.onEnd(h),!(S.avail_out=0))},g.prototype.onData=function(_){this.chunks.push(_)},g.prototype.onEnd=function(_){_===h&&(this.options.to==="string"?this.result=this.chunks.join(""):this.result=a.flattenChunks(this.chunks)),this.chunks=[],this.err=_,this.msg=this.strm.msg},o.Deflate=g,o.deflate=y,o.deflateRaw=function(_,x){return(x=x||{}).raw=!0,y(_,x)},o.gzip=function(_,x){return(x=x||{}).gzip=!0,y(_,x)}},{"./utils/common":41,"./utils/strings":42,"./zlib/deflate":46,"./zlib/messages":51,"./zlib/zstream":53}],40:[function(r,i,o){var s=r("./zlib/inflate"),a=r("./utils/common"),c=r("./utils/strings"),l=r("./zlib/constants"),u=r("./zlib/messages"),d=r("./zlib/zstream"),h=r("./zlib/gzheader"),f=Object.prototype.toString;function p(g){if(!(this instanceof p))return new p(g);this.options=a.assign({chunkSize:16384,windowBits:0,to:""},g||{});var y=this.options;y.raw&&0<=y.windowBits&&y.windowBits<16&&(y.windowBits=-y.windowBits,y.windowBits===0&&(y.windowBits=-15)),!(0<=y.windowBits&&y.windowBits<16)||g&&g.windowBits||(y.windowBits+=32),15<y.windowBits&&y.windowBits<48&&(15&y.windowBits)==0&&(y.windowBits|=15),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new d,this.strm.avail_out=0;var _=s.inflateInit2(this.strm,y.windowBits);if(_!==l.Z_OK)throw new Error(u[_]);this.header=new h,s.inflateGetHeader(this.strm,this.header)}function m(g,y){var _=new p(y);if(_.push(g,!0),_.err)throw _.msg||u[_.err];return _.result}p.prototype.push=function(g,y){var _,x,b,w,S,E,C=this.strm,A=this.options.chunkSize,R=this.options.dictionary,L=!1;if(this.ended)return!1;x=y===~~y?y:y===!0?l.Z_FINISH:l.Z_NO_FLUSH,typeof g=="string"?C.input=c.binstring2buf(g):f.call(g)==="[object ArrayBuffer]"?C.input=new Uint8Array(g):C.input=g,C.next_in=0,C.avail_in=C.input.length;do{if(C.avail_out===0&&(C.output=new a.Buf8(A),C.next_out=0,C.avail_out=A),(_=s.inflate(C,l.Z_NO_FLUSH))===l.Z_NEED_DICT&&R&&(E=typeof R=="string"?c.string2buf(R):f.call(R)==="[object ArrayBuffer]"?new Uint8Array(R):R,_=s.inflateSetDictionary(this.strm,E)),_===l.Z_BUF_ERROR&&L===!0&&(_=l.Z_OK,L=!1),_!==l.Z_STREAM_END&&_!==l.Z_OK)return this.onEnd(_),!(this.ended=!0);C.next_out&&(C.avail_out!==0&&_!==l.Z_STREAM_END&&(C.avail_in!==0||x!==l.Z_FINISH&&x!==l.Z_SYNC_FLUSH)||(this.options.to==="string"?(b=c.utf8border(C.output,C.next_out),w=C.next_out-b,S=c.buf2string(C.output,b),C.next_out=w,C.avail_out=A-w,w&&a.arraySet(C.output,C.output,b,w,0),this.onData(S)):this.onData(a.shrinkBuf(C.output,C.next_out)))),C.avail_in===0&&C.avail_out===0&&(L=!0)}while((0<C.avail_in||C.avail_out===0)&&_!==l.Z_STREAM_END);return _===l.Z_STREAM_END&&(x=l.Z_FINISH),x===l.Z_FINISH?(_=s.inflateEnd(this.strm),this.onEnd(_),this.ended=!0,_===l.Z_OK):x!==l.Z_SYNC_FLUSH||(this.onEnd(l.Z_OK),!(C.avail_out=0))},p.prototype.onData=function(g){this.chunks.push(g)},p.prototype.onEnd=function(g){g===l.Z_OK&&(this.options.to==="string"?this.result=this.chunks.join(""):this.result=a.flattenChunks(this.chunks)),this.chunks=[],this.err=g,this.msg=this.strm.msg},o.Inflate=p,o.inflate=m,o.inflateRaw=function(g,y){return(y=y||{}).raw=!0,m(g,y)},o.ungzip=m},{"./utils/common":41,"./utils/strings":42,"./zlib/constants":44,"./zlib/gzheader":47,"./zlib/inflate":49,"./zlib/messages":51,"./zlib/zstream":53}],41:[function(r,i,o){var s=typeof Uint8Array<"u"&&typeof Uint16Array<"u"&&typeof Int32Array<"u";o.assign=function(l){for(var u=Array.prototype.slice.call(arguments,1);u.length;){var d=u.shift();if(d){if(typeof d!="object")throw new TypeError(d+"must be non-object");for(var h in d)d.hasOwnProperty(h)&&(l[h]=d[h])}}return l},o.shrinkBuf=function(l,u){return l.length===u?l:l.subarray?l.subarray(0,u):(l.length=u,l)};var a={arraySet:function(l,u,d,h,f){if(u.subarray&&l.subarray)l.set(u.subarray(d,d+h),f);else for(var p=0;p<h;p++)l[f+p]=u[d+p]},flattenChunks:function(l){var u,d,h,f,p,m;for(u=h=0,d=l.length;u<d;u++)h+=l[u].length;for(m=new Uint8Array(h),u=f=0,d=l.length;u<d;u++)p=l[u],m.set(p,f),f+=p.length;return m}},c={arraySet:function(l,u,d,h,f){for(var p=0;p<h;p++)l[f+p]=u[d+p]},flattenChunks:function(l){return[].concat.apply([],l)}};o.setTyped=function(l){l?(o.Buf8=Uint8Array,o.Buf16=Uint16Array,o.Buf32=Int32Array,o.assign(o,a)):(o.Buf8=Array,o.Buf16=Array,o.Buf32=Array,o.assign(o,c))},o.setTyped(s)},{}],42:[function(r,i,o){var s=r("./common"),a=!0,c=!0;try{String.fromCharCode.apply(null,[0])}catch{a=!1}try{String.fromCharCode.apply(null,new Uint8Array(1))}catch{c=!1}for(var l=new s.Buf8(256),u=0;u<256;u++)l[u]=252<=u?6:248<=u?5:240<=u?4:224<=u?3:192<=u?2:1;function d(h,f){if(f<65537&&(h.subarray&&c||!h.subarray&&a))return String.fromCharCode.apply(null,s.shrinkBuf(h,f));for(var p="",m=0;m<f;m++)p+=String.fromCharCode(h[m]);return p}l[254]=l[254]=1,o.string2buf=function(h){var f,p,m,g,y,_=h.length,x=0;for(g=0;g<_;g++)(64512&(p=h.charCodeAt(g)))==55296&&g+1<_&&(64512&(m=h.charCodeAt(g+1)))==56320&&(p=65536+(p-55296<<10)+(m-56320),g++),x+=p<128?1:p<2048?2:p<65536?3:4;for(f=new s.Buf8(x),g=y=0;y<x;g++)(64512&(p=h.charCodeAt(g)))==55296&&g+1<_&&(64512&(m=h.charCodeAt(g+1)))==56320&&(p=65536+(p-55296<<10)+(m-56320),g++),p<128?f[y++]=p:(p<2048?f[y++]=192|p>>>6:(p<65536?f[y++]=224|p>>>12:(f[y++]=240|p>>>18,f[y++]=128|p>>>12&63),f[y++]=128|p>>>6&63),f[y++]=128|63&p);return f},o.buf2binstring=function(h){return d(h,h.length)},o.binstring2buf=function(h){for(var f=new s.Buf8(h.length),p=0,m=f.length;p<m;p++)f[p]=h.charCodeAt(p);return f},o.buf2string=function(h,f){var p,m,g,y,_=f||h.length,x=new Array(2*_);for(p=m=0;p<_;)if((g=h[p++])<128)x[m++]=g;else if(4<(y=l[g]))x[m++]=65533,p+=y-1;else{for(g&=y===2?31:y===3?15:7;1<y&&p<_;)g=g<<6|63&h[p++],y--;1<y?x[m++]=65533:g<65536?x[m++]=g:(g-=65536,x[m++]=55296|g>>10&1023,x[m++]=56320|1023&g)}return d(x,m)},o.utf8border=function(h,f){var p;for((f=f||h.length)>h.length&&(f=h.length),p=f-1;0<=p&&(192&h[p])==128;)p--;return p<0||p===0?f:p+l[h[p]]>f?p:f}},{"./common":41}],43:[function(r,i,o){i.exports=function(s,a,c,l){for(var u=65535&s|0,d=s>>>16&65535|0,h=0;c!==0;){for(c-=h=2e3<c?2e3:c;d=d+(u=u+a[l++]|0)|0,--h;);u%=65521,d%=65521}return u|d<<16|0}},{}],44:[function(r,i,o){i.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(r,i,o){var s=(function(){for(var a,c=[],l=0;l<256;l++){a=l;for(var u=0;u<8;u++)a=1&a?3988292384^a>>>1:a>>>1;c[l]=a}return c})();i.exports=function(a,c,l,u){var d=s,h=u+l;a^=-1;for(var f=u;f<h;f++)a=a>>>8^d[255&(a^c[f])];return-1^a}},{}],46:[function(r,i,o){var s,a=r("../utils/common"),c=r("./trees"),l=r("./adler32"),u=r("./crc32"),d=r("./messages"),h=0,f=4,p=0,m=-2,g=-1,y=4,_=2,x=8,b=9,w=286,S=30,E=19,C=2*w+1,A=15,R=3,L=258,O=L+R+1,F=42,B=113,j=1,G=2,W=3,Q=4;function ne(ge,Ze){return ge.msg=d[Ze],Ze}function ue(ge){return(ge<<1)-(4<ge?9:0)}function te(ge){for(var Ze=ge.length;0<=--Ze;)ge[Ze]=0}function re(ge){var Ze=ge.state,$e=Ze.pending;$e>ge.avail_out&&($e=ge.avail_out),$e!==0&&(a.arraySet(ge.output,Ze.pending_buf,Ze.pending_out,$e,ge.next_out),ge.next_out+=$e,Ze.pending_out+=$e,ge.total_out+=$e,ge.avail_out-=$e,Ze.pending-=$e,Ze.pending===0&&(Ze.pending_out=0))}function se(ge,Ze){c._tr_flush_block(ge,0<=ge.block_start?ge.block_start:-1,ge.strstart-ge.block_start,Ze),ge.block_start=ge.strstart,re(ge.strm)}function ce(ge,Ze){ge.pending_buf[ge.pending++]=Ze}function fe(ge,Ze){ge.pending_buf[ge.pending++]=Ze>>>8&255,ge.pending_buf[ge.pending++]=255&Ze}function Me(ge,Ze){var $e,ke,je=ge.max_chain_length,Re=ge.strstart,be=ge.prev_length,Ce=ge.nice_match,Te=ge.strstart>ge.w_size-O?ge.strstart-(ge.w_size-O):0,Be=ge.window,Xe=ge.w_mask,et=ge.prev,rt=ge.strstart+L,at=Be[Re+be-1],lt=Be[Re+be];ge.prev_length>=ge.good_match&&(je>>=2),Ce>ge.lookahead&&(Ce=ge.lookahead);do if(Be[($e=Ze)+be]===lt&&Be[$e+be-1]===at&&Be[$e]===Be[Re]&&Be[++$e]===Be[Re+1]){Re+=2,$e++;do;while(Be[++Re]===Be[++$e]&&Be[++Re]===Be[++$e]&&Be[++Re]===Be[++$e]&&Be[++Re]===Be[++$e]&&Be[++Re]===Be[++$e]&&Be[++Re]===Be[++$e]&&Be[++Re]===Be[++$e]&&Be[++Re]===Be[++$e]&&Re<rt);if(ke=L-(rt-Re),Re=rt-L,be<ke){if(ge.match_start=Ze,Ce<=(be=ke))break;at=Be[Re+be-1],lt=Be[Re+be]}}while((Ze=et[Ze&Xe])>Te&&--je!=0);return be<=ge.lookahead?be:ge.lookahead}function Pe(ge){var Ze,$e,ke,je,Re,be,Ce,Te,Be,Xe,et=ge.w_size;do{if(je=ge.window_size-ge.lookahead-ge.strstart,ge.strstart>=et+(et-O)){for(a.arraySet(ge.window,ge.window,et,et,0),ge.match_start-=et,ge.strstart-=et,ge.block_start-=et,Ze=$e=ge.hash_size;ke=ge.head[--Ze],ge.head[Ze]=et<=ke?ke-et:0,--$e;);for(Ze=$e=et;ke=ge.prev[--Ze],ge.prev[Ze]=et<=ke?ke-et:0,--$e;);je+=et}if(ge.strm.avail_in===0)break;if(be=ge.strm,Ce=ge.window,Te=ge.strstart+ge.lookahead,Be=je,Xe=void 0,Xe=be.avail_in,Be<Xe&&(Xe=Be),$e=Xe===0?0:(be.avail_in-=Xe,a.arraySet(Ce,be.input,be.next_in,Xe,Te),be.state.wrap===1?be.adler=l(be.adler,Ce,Xe,Te):be.state.wrap===2&&(be.adler=u(be.adler,Ce,Xe,Te)),be.next_in+=Xe,be.total_in+=Xe,Xe),ge.lookahead+=$e,ge.lookahead+ge.insert>=R)for(Re=ge.strstart-ge.insert,ge.ins_h=ge.window[Re],ge.ins_h=(ge.ins_h<<ge.hash_shift^ge.window[Re+1])&ge.hash_mask;ge.insert&&(ge.ins_h=(ge.ins_h<<ge.hash_shift^ge.window[Re+R-1])&ge.hash_mask,ge.prev[Re&ge.w_mask]=ge.head[ge.ins_h],ge.head[ge.ins_h]=Re,Re++,ge.insert--,!(ge.lookahead+ge.insert<R)););}while(ge.lookahead<O&&ge.strm.avail_in!==0)}function Ne(ge,Ze){for(var $e,ke;;){if(ge.lookahead<O){if(Pe(ge),ge.lookahead<O&&Ze===h)return j;if(ge.lookahead===0)break}if($e=0,ge.lookahead>=R&&(ge.ins_h=(ge.ins_h<<ge.hash_shift^ge.window[ge.strstart+R-1])&ge.hash_mask,$e=ge.prev[ge.strstart&ge.w_mask]=ge.head[ge.ins_h],ge.head[ge.ins_h]=ge.strstart),$e!==0&&ge.strstart-$e<=ge.w_size-O&&(ge.match_length=Me(ge,$e)),ge.match_length>=R)if(ke=c._tr_tally(ge,ge.strstart-ge.match_start,ge.match_length-R),ge.lookahead-=ge.match_length,ge.match_length<=ge.max_lazy_match&&ge.lookahead>=R){for(ge.match_length--;ge.strstart++,ge.ins_h=(ge.ins_h<<ge.hash_shift^ge.window[ge.strstart+R-1])&ge.hash_mask,$e=ge.prev[ge.strstart&ge.w_mask]=ge.head[ge.ins_h],ge.head[ge.ins_h]=ge.strstart,--ge.match_length!=0;);ge.strstart++}else ge.strstart+=ge.match_length,ge.match_length=0,ge.ins_h=ge.window[ge.strstart],ge.ins_h=(ge.ins_h<<ge.hash_shift^ge.window[ge.strstart+1])&ge.hash_mask;else ke=c._tr_tally(ge,0,ge.window[ge.strstart]),ge.lookahead--,ge.strstart++;if(ke&&(se(ge,!1),ge.strm.avail_out===0))return j}return ge.insert=ge.strstart<R-1?ge.strstart:R-1,Ze===f?(se(ge,!0),ge.strm.avail_out===0?W:Q):ge.last_lit&&(se(ge,!1),ge.strm.avail_out===0)?j:G}function me(ge,Ze){for(var $e,ke,je;;){if(ge.lookahead<O){if(Pe(ge),ge.lookahead<O&&Ze===h)return j;if(ge.lookahead===0)break}if($e=0,ge.lookahead>=R&&(ge.ins_h=(ge.ins_h<<ge.hash_shift^ge.window[ge.strstart+R-1])&ge.hash_mask,$e=ge.prev[ge.strstart&ge.w_mask]=ge.head[ge.ins_h],ge.head[ge.ins_h]=ge.strstart),ge.prev_length=ge.match_length,ge.prev_match=ge.match_start,ge.match_length=R-1,$e!==0&&ge.prev_length<ge.max_lazy_match&&ge.strstart-$e<=ge.w_size-O&&(ge.match_length=Me(ge,$e),ge.match_length<=5&&(ge.strategy===1||ge.match_length===R&&4096<ge.strstart-ge.match_start)&&(ge.match_length=R-1)),ge.prev_length>=R&&ge.match_length<=ge.prev_length){for(je=ge.strstart+ge.lookahead-R,ke=c._tr_tally(ge,ge.strstart-1-ge.prev_match,ge.prev_length-R),ge.lookahead-=ge.prev_length-1,ge.prev_length-=2;++ge.strstart<=je&&(ge.ins_h=(ge.ins_h<<ge.hash_shift^ge.window[ge.strstart+R-1])&ge.hash_mask,$e=ge.prev[ge.strstart&ge.w_mask]=ge.head[ge.ins_h],ge.head[ge.ins_h]=ge.strstart),--ge.prev_length!=0;);if(ge.match_available=0,ge.match_length=R-1,ge.strstart++,ke&&(se(ge,!1),ge.strm.avail_out===0))return j}else if(ge.match_available){if((ke=c._tr_tally(ge,0,ge.window[ge.strstart-1]))&&se(ge,!1),ge.strstart++,ge.lookahead--,ge.strm.avail_out===0)return j}else ge.match_available=1,ge.strstart++,ge.lookahead--}return ge.match_available&&(ke=c._tr_tally(ge,0,ge.window[ge.strstart-1]),ge.match_available=0),ge.insert=ge.strstart<R-1?ge.strstart:R-1,Ze===f?(se(ge,!0),ge.strm.avail_out===0?W:Q):ge.last_lit&&(se(ge,!1),ge.strm.avail_out===0)?j:G}function Se(ge,Ze,$e,ke,je){this.good_length=ge,this.max_lazy=Ze,this.nice_length=$e,this.max_chain=ke,this.func=je}function ye(){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=x,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 a.Buf16(2*C),this.dyn_dtree=new a.Buf16(2*(2*S+1)),this.bl_tree=new a.Buf16(2*(2*E+1)),te(this.dyn_ltree),te(this.dyn_dtree),te(this.bl_tree),this.l_desc=null,this.d_desc=null,this.bl_desc=null,this.bl_count=new a.Buf16(A+1),this.heap=new a.Buf16(2*w+1),te(this.heap),this.heap_len=0,this.heap_max=0,this.depth=new a.Buf16(2*w+1),te(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 He(ge){var Ze;return ge&&ge.state?(ge.total_in=ge.total_out=0,ge.data_type=_,(Ze=ge.state).pending=0,Ze.pending_out=0,Ze.wrap<0&&(Ze.wrap=-Ze.wrap),Ze.status=Ze.wrap?F:B,ge.adler=Ze.wrap===2?0:1,Ze.last_flush=h,c._tr_init(Ze),p):ne(ge,m)}function Ye(ge){var Ze=He(ge);return Ze===p&&(function($e){$e.window_size=2*$e.w_size,te($e.head),$e.max_lazy_match=s[$e.level].max_lazy,$e.good_match=s[$e.level].good_length,$e.nice_match=s[$e.level].nice_length,$e.max_chain_length=s[$e.level].max_chain,$e.strstart=0,$e.block_start=0,$e.lookahead=0,$e.insert=0,$e.match_length=$e.prev_length=R-1,$e.match_available=0,$e.ins_h=0})(ge.state),Ze}function We(ge,Ze,$e,ke,je,Re){if(!ge)return m;var be=1;if(Ze===g&&(Ze=6),ke<0?(be=0,ke=-ke):15<ke&&(be=2,ke-=16),je<1||b<je||$e!==x||ke<8||15<ke||Ze<0||9<Ze||Re<0||y<Re)return ne(ge,m);ke===8&&(ke=9);var Ce=new ye;return(ge.state=Ce).strm=ge,Ce.wrap=be,Ce.gzhead=null,Ce.w_bits=ke,Ce.w_size=1<<Ce.w_bits,Ce.w_mask=Ce.w_size-1,Ce.hash_bits=je+7,Ce.hash_size=1<<Ce.hash_bits,Ce.hash_mask=Ce.hash_size-1,Ce.hash_shift=~~((Ce.hash_bits+R-1)/R),Ce.window=new a.Buf8(2*Ce.w_size),Ce.head=new a.Buf16(Ce.hash_size),Ce.prev=new a.Buf16(Ce.w_size),Ce.lit_bufsize=1<<je+6,Ce.pending_buf_size=4*Ce.lit_bufsize,Ce.pending_buf=new a.Buf8(Ce.pending_buf_size),Ce.d_buf=1*Ce.lit_bufsize,Ce.l_buf=3*Ce.lit_bufsize,Ce.level=Ze,Ce.strategy=Re,Ce.method=$e,Ye(ge)}s=[new Se(0,0,0,0,function(ge,Ze){var $e=65535;for($e>ge.pending_buf_size-5&&($e=ge.pending_buf_size-5);;){if(ge.lookahead<=1){if(Pe(ge),ge.lookahead===0&&Ze===h)return j;if(ge.lookahead===0)break}ge.strstart+=ge.lookahead,ge.lookahead=0;var ke=ge.block_start+$e;if((ge.strstart===0||ge.strstart>=ke)&&(ge.lookahead=ge.strstart-ke,ge.strstart=ke,se(ge,!1),ge.strm.avail_out===0)||ge.strstart-ge.block_start>=ge.w_size-O&&(se(ge,!1),ge.strm.avail_out===0))return j}return ge.insert=0,Ze===f?(se(ge,!0),ge.strm.avail_out===0?W:Q):(ge.strstart>ge.block_start&&(se(ge,!1),ge.strm.avail_out),j)}),new Se(4,4,8,4,Ne),new Se(4,5,16,8,Ne),new Se(4,6,32,32,Ne),new Se(4,4,16,16,me),new Se(8,16,32,32,me),new Se(8,16,128,128,me),new Se(8,32,128,256,me),new Se(32,128,258,1024,me),new Se(32,258,258,4096,me)],o.deflateInit=function(ge,Ze){return We(ge,Ze,x,15,8,0)},o.deflateInit2=We,o.deflateReset=Ye,o.deflateResetKeep=He,o.deflateSetHeader=function(ge,Ze){return ge&&ge.state?ge.state.wrap!==2?m:(ge.state.gzhead=Ze,p):m},o.deflate=function(ge,Ze){var $e,ke,je,Re;if(!ge||!ge.state||5<Ze||Ze<0)return ge?ne(ge,m):m;if(ke=ge.state,!ge.output||!ge.input&&ge.avail_in!==0||ke.status===666&&Ze!==f)return ne(ge,ge.avail_out===0?-5:m);if(ke.strm=ge,$e=ke.last_flush,ke.last_flush=Ze,ke.status===F)if(ke.wrap===2)ge.adler=0,ce(ke,31),ce(ke,139),ce(ke,8),ke.gzhead?(ce(ke,(ke.gzhead.text?1:0)+(ke.gzhead.hcrc?2:0)+(ke.gzhead.extra?4:0)+(ke.gzhead.name?8:0)+(ke.gzhead.comment?16:0)),ce(ke,255&ke.gzhead.time),ce(ke,ke.gzhead.time>>8&255),ce(ke,ke.gzhead.time>>16&255),ce(ke,ke.gzhead.time>>24&255),ce(ke,ke.level===9?2:2<=ke.strategy||ke.level<2?4:0),ce(ke,255&ke.gzhead.os),ke.gzhead.extra&&ke.gzhead.extra.length&&(ce(ke,255&ke.gzhead.extra.length),ce(ke,ke.gzhead.extra.length>>8&255)),ke.gzhead.hcrc&&(ge.adler=u(ge.adler,ke.pending_buf,ke.pending,0)),ke.gzindex=0,ke.status=69):(ce(ke,0),ce(ke,0),ce(ke,0),ce(ke,0),ce(ke,0),ce(ke,ke.level===9?2:2<=ke.strategy||ke.level<2?4:0),ce(ke,3),ke.status=B);else{var be=x+(ke.w_bits-8<<4)<<8;be|=(2<=ke.strategy||ke.level<2?0:ke.level<6?1:ke.level===6?2:3)<<6,ke.strstart!==0&&(be|=32),be+=31-be%31,ke.status=B,fe(ke,be),ke.strstart!==0&&(fe(ke,ge.adler>>>16),fe(ke,65535&ge.adler)),ge.adler=1}if(ke.status===69)if(ke.gzhead.extra){for(je=ke.pending;ke.gzindex<(65535&ke.gzhead.extra.length)&&(ke.pending!==ke.pending_buf_size||(ke.gzhead.hcrc&&ke.pending>je&&(ge.adler=u(ge.adler,ke.pending_buf,ke.pending-je,je)),re(ge),je=ke.pending,ke.pending!==ke.pending_buf_size));)ce(ke,255&ke.gzhead.extra[ke.gzindex]),ke.gzindex++;ke.gzhead.hcrc&&ke.pending>je&&(ge.adler=u(ge.adler,ke.pending_buf,ke.pending-je,je)),ke.gzindex===ke.gzhead.extra.length&&(ke.gzindex=0,ke.status=73)}else ke.status=73;if(ke.status===73)if(ke.gzhead.name){je=ke.pending;do{if(ke.pending===ke.pending_buf_size&&(ke.gzhead.hcrc&&ke.pending>je&&(ge.adler=u(ge.adler,ke.pending_buf,ke.pending-je,je)),re(ge),je=ke.pending,ke.pending===ke.pending_buf_size)){Re=1;break}Re=ke.gzindex<ke.gzhead.name.length?255&ke.gzhead.name.charCodeAt(ke.gzindex++):0,ce(ke,Re)}while(Re!==0);ke.gzhead.hcrc&&ke.pending>je&&(ge.adler=u(ge.adler,ke.pending_buf,ke.pending-je,je)),Re===0&&(ke.gzindex=0,ke.status=91)}else ke.status=91;if(ke.status===91)if(ke.gzhead.comment){je=ke.pending;do{if(ke.pending===ke.pending_buf_size&&(ke.gzhead.hcrc&&ke.pending>je&&(ge.adler=u(ge.adler,ke.pending_buf,ke.pending-je,je)),re(ge),je=ke.pending,ke.pending===ke.pending_buf_size)){Re=1;break}Re=ke.gzindex<ke.gzhead.comment.length?255&ke.gzhead.comment.charCodeAt(ke.gzindex++):0,ce(ke,Re)}while(Re!==0);ke.gzhead.hcrc&&ke.pending>je&&(ge.adler=u(ge.adler,ke.pending_buf,ke.pending-je,je)),Re===0&&(ke.status=103)}else ke.status=103;if(ke.status===103&&(ke.gzhead.hcrc?(ke.pending+2>ke.pending_buf_size&&re(ge),ke.pending+2<=ke.pending_buf_size&&(ce(ke,255&ge.adler),ce(ke,ge.adler>>8&255),ge.adler=0,ke.status=B)):ke.status=B),ke.pending!==0){if(re(ge),ge.avail_out===0)return ke.last_flush=-1,p}else if(ge.avail_in===0&&ue(Ze)<=ue($e)&&Ze!==f)return ne(ge,-5);if(ke.status===666&&ge.avail_in!==0)return ne(ge,-5);if(ge.avail_in!==0||ke.lookahead!==0||Ze!==h&&ke.status!==666){var Ce=ke.strategy===2?(function(Te,Be){for(var Xe;;){if(Te.lookahead===0&&(Pe(Te),Te.lookahead===0)){if(Be===h)return j;break}if(Te.match_length=0,Xe=c._tr_tally(Te,0,Te.window[Te.strstart]),Te.lookahead--,Te.strstart++,Xe&&(se(Te,!1),Te.strm.avail_out===0))return j}return Te.insert=0,Be===f?(se(Te,!0),Te.strm.avail_out===0?W:Q):Te.last_lit&&(se(Te,!1),Te.strm.avail_out===0)?j:G})(ke,Ze):ke.strategy===3?(function(Te,Be){for(var Xe,et,rt,at,lt=Te.window;;){if(Te.lookahead<=L){if(Pe(Te),Te.lookahead<=L&&Be===h)return j;if(Te.lookahead===0)break}if(Te.match_length=0,Te.lookahead>=R&&0<Te.strstart&&(et=lt[rt=Te.strstart-1])===lt[++rt]&&et===lt[++rt]&&et===lt[++rt]){at=Te.strstart+L;do;while(et===lt[++rt]&&et===lt[++rt]&&et===lt[++rt]&&et===lt[++rt]&&et===lt[++rt]&&et===lt[++rt]&&et===lt[++rt]&&et===lt[++rt]&&rt<at);Te.match_length=L-(at-rt),Te.match_length>Te.lookahead&&(Te.match_length=Te.lookahead)}if(Te.match_length>=R?(Xe=c._tr_tally(Te,1,Te.match_length-R),Te.lookahead-=Te.match_length,Te.strstart+=Te.match_length,Te.match_length=0):(Xe=c._tr_tally(Te,0,Te.window[Te.strstart]),Te.lookahead--,Te.strstart++),Xe&&(se(Te,!1),Te.strm.avail_out===0))return j}return Te.insert=0,Be===f?(se(Te,!0),Te.strm.avail_out===0?W:Q):Te.last_lit&&(se(Te,!1),Te.strm.avail_out===0)?j:G})(ke,Ze):s[ke.level].func(ke,Ze);if(Ce!==W&&Ce!==Q||(ke.status=666),Ce===j||Ce===W)return ge.avail_out===0&&(ke.last_flush=-1),p;if(Ce===G&&(Ze===1?c._tr_align(ke):Ze!==5&&(c._tr_stored_block(ke,0,0,!1),Ze===3&&(te(ke.head),ke.lookahead===0&&(ke.strstart=0,ke.block_start=0,ke.insert=0))),re(ge),ge.avail_out===0))return ke.last_flush=-1,p}return Ze!==f?p:ke.wrap<=0?1:(ke.wrap===2?(ce(ke,255&ge.adler),ce(ke,ge.adler>>8&255),ce(ke,ge.adler>>16&255),ce(ke,ge.adler>>24&255),ce(ke,255&ge.total_in),ce(ke,ge.total_in>>8&255),ce(ke,ge.total_in>>16&255),ce(ke,ge.total_in>>24&255)):(fe(ke,ge.adler>>>16),fe(ke,65535&ge.adler)),re(ge),0<ke.wrap&&(ke.wrap=-ke.wrap),ke.pending!==0?p:1)},o.deflateEnd=function(ge){var Ze;return ge&&ge.state?(Ze=ge.state.status)!==F&&Ze!==69&&Ze!==73&&Ze!==91&&Ze!==103&&Ze!==B&&Ze!==666?ne(ge,m):(ge.state=null,Ze===B?ne(ge,-3):p):m},o.deflateSetDictionary=function(ge,Ze){var $e,ke,je,Re,be,Ce,Te,Be,Xe=Ze.length;if(!ge||!ge.state||(Re=($e=ge.state).wrap)===2||Re===1&&$e.status!==F||$e.lookahead)return m;for(Re===1&&(ge.adler=l(ge.adler,Ze,Xe,0)),$e.wrap=0,Xe>=$e.w_size&&(Re===0&&(te($e.head),$e.strstart=0,$e.block_start=0,$e.insert=0),Be=new a.Buf8($e.w_size),a.arraySet(Be,Ze,Xe-$e.w_size,$e.w_size,0),Ze=Be,Xe=$e.w_size),be=ge.avail_in,Ce=ge.next_in,Te=ge.input,ge.avail_in=Xe,ge.next_in=0,ge.input=Ze,Pe($e);$e.lookahead>=R;){for(ke=$e.strstart,je=$e.lookahead-(R-1);$e.ins_h=($e.ins_h<<$e.hash_shift^$e.window[ke+R-1])&$e.hash_mask,$e.prev[ke&$e.w_mask]=$e.head[$e.ins_h],$e.head[$e.ins_h]=ke,ke++,--je;);$e.strstart=ke,$e.lookahead=R-1,Pe($e)}return $e.strstart+=$e.lookahead,$e.block_start=$e.strstart,$e.insert=$e.lookahead,$e.lookahead=0,$e.match_length=$e.prev_length=R-1,$e.match_available=0,ge.next_in=Ce,ge.input=Te,ge.avail_in=be,$e.wrap=Re,p},o.deflateInfo="pako deflate (from Nodeca project)"},{"../utils/common":41,"./adler32":43,"./crc32":45,"./messages":51,"./trees":52}],47:[function(r,i,o){i.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(r,i,o){i.exports=function(s,a){var c,l,u,d,h,f,p,m,g,y,_,x,b,w,S,E,C,A,R,L,O,F,B,j,G;c=s.state,l=s.next_in,j=s.input,u=l+(s.avail_in-5),d=s.next_out,G=s.output,h=d-(a-s.avail_out),f=d+(s.avail_out-257),p=c.dmax,m=c.wsize,g=c.whave,y=c.wnext,_=c.window,x=c.hold,b=c.bits,w=c.lencode,S=c.distcode,E=(1<<c.lenbits)-1,C=(1<<c.distbits)-1;e:do{b<15&&(x+=j[l++]<<b,b+=8,x+=j[l++]<<b,b+=8),A=w[x&E];t:for(;;){if(x>>>=R=A>>>24,b-=R,(R=A>>>16&255)===0)G[d++]=65535&A;else{if(!(16&R)){if((64&R)==0){A=w[(65535&A)+(x&(1<<R)-1)];continue t}if(32&R){c.mode=12;break e}s.msg="invalid literal/length code",c.mode=30;break e}L=65535&A,(R&=15)&&(b<R&&(x+=j[l++]<<b,b+=8),L+=x&(1<<R)-1,x>>>=R,b-=R),b<15&&(x+=j[l++]<<b,b+=8,x+=j[l++]<<b,b+=8),A=S[x&C];n:for(;;){if(x>>>=R=A>>>24,b-=R,!(16&(R=A>>>16&255))){if((64&R)==0){A=S[(65535&A)+(x&(1<<R)-1)];continue n}s.msg="invalid distance code",c.mode=30;break e}if(O=65535&A,b<(R&=15)&&(x+=j[l++]<<b,(b+=8)<R&&(x+=j[l++]<<b,b+=8)),p<(O+=x&(1<<R)-1)){s.msg="invalid distance too far back",c.mode=30;break e}if(x>>>=R,b-=R,(R=d-h)<O){if(g<(R=O-R)&&c.sane){s.msg="invalid distance too far back",c.mode=30;break e}if(B=_,(F=0)===y){if(F+=m-R,R<L){for(L-=R;G[d++]=_[F++],--R;);F=d-O,B=G}}else if(y<R){if(F+=m+y-R,(R-=y)<L){for(L-=R;G[d++]=_[F++],--R;);if(F=0,y<L){for(L-=R=y;G[d++]=_[F++],--R;);F=d-O,B=G}}}else if(F+=y-R,R<L){for(L-=R;G[d++]=_[F++],--R;);F=d-O,B=G}for(;2<L;)G[d++]=B[F++],G[d++]=B[F++],G[d++]=B[F++],L-=3;L&&(G[d++]=B[F++],1<L&&(G[d++]=B[F++]))}else{for(F=d-O;G[d++]=G[F++],G[d++]=G[F++],G[d++]=G[F++],2<(L-=3););L&&(G[d++]=G[F++],1<L&&(G[d++]=G[F++]))}break}}break}}while(l<u&&d<f);l-=L=b>>3,x&=(1<<(b-=L<<3))-1,s.next_in=l,s.next_out=d,s.avail_in=l<u?u-l+5:5-(l-u),s.avail_out=d<f?f-d+257:257-(d-f),c.hold=x,c.bits=b}},{}],49:[function(r,i,o){var s=r("../utils/common"),a=r("./adler32"),c=r("./crc32"),l=r("./inffast"),u=r("./inftrees"),d=1,h=2,f=0,p=-2,m=1,g=852,y=592;function _(F){return(F>>>24&255)+(F>>>8&65280)+((65280&F)<<8)+((255&F)<<24)}function x(){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 b(F){var B;return F&&F.state?(B=F.state,F.total_in=F.total_out=B.total=0,F.msg="",B.wrap&&(F.adler=1&B.wrap),B.mode=m,B.last=0,B.havedict=0,B.dmax=32768,B.head=null,B.hold=0,B.bits=0,B.lencode=B.lendyn=new s.Buf32(g),B.distcode=B.distdyn=new s.Buf32(y),B.sane=1,B.back=-1,f):p}function w(F){var B;return F&&F.state?((B=F.state).wsize=0,B.whave=0,B.wnext=0,b(F)):p}function S(F,B){var j,G;return F&&F.state?(G=F.state,B<0?(j=0,B=-B):(j=1+(B>>4),B<48&&(B&=15)),B&&(B<8||15<B)?p:(G.window!==null&&G.wbits!==B&&(G.window=null),G.wrap=j,G.wbits=B,w(F))):p}function E(F,B){var j,G;return F?(G=new x,(F.state=G).window=null,(j=S(F,B))!==f&&(F.state=null),j):p}var C,A,R=!0;function L(F){if(R){var B;for(C=new s.Buf32(512),A=new s.Buf32(32),B=0;B<144;)F.lens[B++]=8;for(;B<256;)F.lens[B++]=9;for(;B<280;)F.lens[B++]=7;for(;B<288;)F.lens[B++]=8;for(u(d,F.lens,0,288,C,0,F.work,{bits:9}),B=0;B<32;)F.lens[B++]=5;u(h,F.lens,0,32,A,0,F.work,{bits:5}),R=!1}F.lencode=C,F.lenbits=9,F.distcode=A,F.distbits=5}function O(F,B,j,G){var W,Q=F.state;return Q.window===null&&(Q.wsize=1<<Q.wbits,Q.wnext=0,Q.whave=0,Q.window=new s.Buf8(Q.wsize)),G>=Q.wsize?(s.arraySet(Q.window,B,j-Q.wsize,Q.wsize,0),Q.wnext=0,Q.whave=Q.wsize):(G<(W=Q.wsize-Q.wnext)&&(W=G),s.arraySet(Q.window,B,j-G,W,Q.wnext),(G-=W)?(s.arraySet(Q.window,B,j-G,G,0),Q.wnext=G,Q.whave=Q.wsize):(Q.wnext+=W,Q.wnext===Q.wsize&&(Q.wnext=0),Q.whave<Q.wsize&&(Q.whave+=W))),0}o.inflateReset=w,o.inflateReset2=S,o.inflateResetKeep=b,o.inflateInit=function(F){return E(F,15)},o.inflateInit2=E,o.inflate=function(F,B){var j,G,W,Q,ne,ue,te,re,se,ce,fe,Me,Pe,Ne,me,Se,ye,He,Ye,We,ge,Ze,$e,ke,je=0,Re=new s.Buf8(4),be=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15];if(!F||!F.state||!F.output||!F.input&&F.avail_in!==0)return p;(j=F.state).mode===12&&(j.mode=13),ne=F.next_out,W=F.output,te=F.avail_out,Q=F.next_in,G=F.input,ue=F.avail_in,re=j.hold,se=j.bits,ce=ue,fe=te,Ze=f;e:for(;;)switch(j.mode){case m:if(j.wrap===0){j.mode=13;break}for(;se<16;){if(ue===0)break e;ue--,re+=G[Q++]<<se,se+=8}if(2&j.wrap&&re===35615){Re[j.check=0]=255&re,Re[1]=re>>>8&255,j.check=c(j.check,Re,2,0),se=re=0,j.mode=2;break}if(j.flags=0,j.head&&(j.head.done=!1),!(1&j.wrap)||(((255&re)<<8)+(re>>8))%31){F.msg="incorrect header check",j.mode=30;break}if((15&re)!=8){F.msg="unknown compression method",j.mode=30;break}if(se-=4,ge=8+(15&(re>>>=4)),j.wbits===0)j.wbits=ge;else if(ge>j.wbits){F.msg="invalid window size",j.mode=30;break}j.dmax=1<<ge,F.adler=j.check=1,j.mode=512&re?10:12,se=re=0;break;case 2:for(;se<16;){if(ue===0)break e;ue--,re+=G[Q++]<<se,se+=8}if(j.flags=re,(255&j.flags)!=8){F.msg="unknown compression method",j.mode=30;break}if(57344&j.flags){F.msg="unknown header flags set",j.mode=30;break}j.head&&(j.head.text=re>>8&1),512&j.flags&&(Re[0]=255&re,Re[1]=re>>>8&255,j.check=c(j.check,Re,2,0)),se=re=0,j.mode=3;case 3:for(;se<32;){if(ue===0)break e;ue--,re+=G[Q++]<<se,se+=8}j.head&&(j.head.time=re),512&j.flags&&(Re[0]=255&re,Re[1]=re>>>8&255,Re[2]=re>>>16&255,Re[3]=re>>>24&255,j.check=c(j.check,Re,4,0)),se=re=0,j.mode=4;case 4:for(;se<16;){if(ue===0)break e;ue--,re+=G[Q++]<<se,se+=8}j.head&&(j.head.xflags=255&re,j.head.os=re>>8),512&j.flags&&(Re[0]=255&re,Re[1]=re>>>8&255,j.check=c(j.check,Re,2,0)),se=re=0,j.mode=5;case 5:if(1024&j.flags){for(;se<16;){if(ue===0)break e;ue--,re+=G[Q++]<<se,se+=8}j.length=re,j.head&&(j.head.extra_len=re),512&j.flags&&(Re[0]=255&re,Re[1]=re>>>8&255,j.check=c(j.check,Re,2,0)),se=re=0}else j.head&&(j.head.extra=null);j.mode=6;case 6:if(1024&j.flags&&(ue<(Me=j.length)&&(Me=ue),Me&&(j.head&&(ge=j.head.extra_len-j.length,j.head.extra||(j.head.extra=new Array(j.head.extra_len)),s.arraySet(j.head.extra,G,Q,Me,ge)),512&j.flags&&(j.check=c(j.check,G,Me,Q)),ue-=Me,Q+=Me,j.length-=Me),j.length))break e;j.length=0,j.mode=7;case 7:if(2048&j.flags){if(ue===0)break e;for(Me=0;ge=G[Q+Me++],j.head&&ge&&j.length<65536&&(j.head.name+=String.fromCharCode(ge)),ge&&Me<ue;);if(512&j.flags&&(j.check=c(j.check,G,Me,Q)),ue-=Me,Q+=Me,ge)break e}else j.head&&(j.head.name=null);j.length=0,j.mode=8;case 8:if(4096&j.flags){if(ue===0)break e;for(Me=0;ge=G[Q+Me++],j.head&&ge&&j.length<65536&&(j.head.comment+=String.fromCharCode(ge)),ge&&Me<ue;);if(512&j.flags&&(j.check=c(j.check,G,Me,Q)),ue-=Me,Q+=Me,ge)break e}else j.head&&(j.head.comment=null);j.mode=9;case 9:if(512&j.flags){for(;se<16;){if(ue===0)break e;ue--,re+=G[Q++]<<se,se+=8}if(re!==(65535&j.check)){F.msg="header crc mismatch",j.mode=30;break}se=re=0}j.head&&(j.head.hcrc=j.flags>>9&1,j.head.done=!0),F.adler=j.check=0,j.mode=12;break;case 10:for(;se<32;){if(ue===0)break e;ue--,re+=G[Q++]<<se,se+=8}F.adler=j.check=_(re),se=re=0,j.mode=11;case 11:if(j.havedict===0)return F.next_out=ne,F.avail_out=te,F.next_in=Q,F.avail_in=ue,j.hold=re,j.bits=se,2;F.adler=j.check=1,j.mode=12;case 12:if(B===5||B===6)break e;case 13:if(j.last){re>>>=7&se,se-=7&se,j.mode=27;break}for(;se<3;){if(ue===0)break e;ue--,re+=G[Q++]<<se,se+=8}switch(j.last=1&re,se-=1,3&(re>>>=1)){case 0:j.mode=14;break;case 1:if(L(j),j.mode=20,B!==6)break;re>>>=2,se-=2;break e;case 2:j.mode=17;break;case 3:F.msg="invalid block type",j.mode=30}re>>>=2,se-=2;break;case 14:for(re>>>=7&se,se-=7&se;se<32;){if(ue===0)break e;ue--,re+=G[Q++]<<se,se+=8}if((65535&re)!=(re>>>16^65535)){F.msg="invalid stored block lengths",j.mode=30;break}if(j.length=65535&re,se=re=0,j.mode=15,B===6)break e;case 15:j.mode=16;case 16:if(Me=j.length){if(ue<Me&&(Me=ue),te<Me&&(Me=te),Me===0)break e;s.arraySet(W,G,Q,Me,ne),ue-=Me,Q+=Me,te-=Me,ne+=Me,j.length-=Me;break}j.mode=12;break;case 17:for(;se<14;){if(ue===0)break e;ue--,re+=G[Q++]<<se,se+=8}if(j.nlen=257+(31&re),re>>>=5,se-=5,j.ndist=1+(31&re),re>>>=5,se-=5,j.ncode=4+(15&re),re>>>=4,se-=4,286<j.nlen||30<j.ndist){F.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(;se<3;){if(ue===0)break e;ue--,re+=G[Q++]<<se,se+=8}j.lens[be[j.have++]]=7&re,re>>>=3,se-=3}for(;j.have<19;)j.lens[be[j.have++]]=0;if(j.lencode=j.lendyn,j.lenbits=7,$e={bits:j.lenbits},Ze=u(0,j.lens,0,19,j.lencode,0,j.work,$e),j.lenbits=$e.bits,Ze){F.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(;Se=(je=j.lencode[re&(1<<j.lenbits)-1])>>>16&255,ye=65535&je,!((me=je>>>24)<=se);){if(ue===0)break e;ue--,re+=G[Q++]<<se,se+=8}if(ye<16)re>>>=me,se-=me,j.lens[j.have++]=ye;else{if(ye===16){for(ke=me+2;se<ke;){if(ue===0)break e;ue--,re+=G[Q++]<<se,se+=8}if(re>>>=me,se-=me,j.have===0){F.msg="invalid bit length repeat",j.mode=30;break}ge=j.lens[j.have-1],Me=3+(3&re),re>>>=2,se-=2}else if(ye===17){for(ke=me+3;se<ke;){if(ue===0)break e;ue--,re+=G[Q++]<<se,se+=8}se-=me,ge=0,Me=3+(7&(re>>>=me)),re>>>=3,se-=3}else{for(ke=me+7;se<ke;){if(ue===0)break e;ue--,re+=G[Q++]<<se,se+=8}se-=me,ge=0,Me=11+(127&(re>>>=me)),re>>>=7,se-=7}if(j.have+Me>j.nlen+j.ndist){F.msg="invalid bit length repeat",j.mode=30;break}for(;Me--;)j.lens[j.have++]=ge}}if(j.mode===30)break;if(j.lens[256]===0){F.msg="invalid code -- missing end-of-block",j.mode=30;break}if(j.lenbits=9,$e={bits:j.lenbits},Ze=u(d,j.lens,0,j.nlen,j.lencode,0,j.work,$e),j.lenbits=$e.bits,Ze){F.msg="invalid literal/lengths set",j.mode=30;break}if(j.distbits=6,j.distcode=j.distdyn,$e={bits:j.distbits},Ze=u(h,j.lens,j.nlen,j.ndist,j.distcode,0,j.work,$e),j.distbits=$e.bits,Ze){F.msg="invalid distances set",j.mode=30;break}if(j.mode=20,B===6)break e;case 20:j.mode=21;case 21:if(6<=ue&&258<=te){F.next_out=ne,F.avail_out=te,F.next_in=Q,F.avail_in=ue,j.hold=re,j.bits=se,l(F,fe),ne=F.next_out,W=F.output,te=F.avail_out,Q=F.next_in,G=F.input,ue=F.avail_in,re=j.hold,se=j.bits,j.mode===12&&(j.back=-1);break}for(j.back=0;Se=(je=j.lencode[re&(1<<j.lenbits)-1])>>>16&255,ye=65535&je,!((me=je>>>24)<=se);){if(ue===0)break e;ue--,re+=G[Q++]<<se,se+=8}if(Se&&(240&Se)==0){for(He=me,Ye=Se,We=ye;Se=(je=j.lencode[We+((re&(1<<He+Ye)-1)>>He)])>>>16&255,ye=65535&je,!(He+(me=je>>>24)<=se);){if(ue===0)break e;ue--,re+=G[Q++]<<se,se+=8}re>>>=He,se-=He,j.back+=He}if(re>>>=me,se-=me,j.back+=me,j.length=ye,Se===0){j.mode=26;break}if(32&Se){j.back=-1,j.mode=12;break}if(64&Se){F.msg="invalid literal/length code",j.mode=30;break}j.extra=15&Se,j.mode=22;case 22:if(j.extra){for(ke=j.extra;se<ke;){if(ue===0)break e;ue--,re+=G[Q++]<<se,se+=8}j.length+=re&(1<<j.extra)-1,re>>>=j.extra,se-=j.extra,j.back+=j.extra}j.was=j.length,j.mode=23;case 23:for(;Se=(je=j.distcode[re&(1<<j.distbits)-1])>>>16&255,ye=65535&je,!((me=je>>>24)<=se);){if(ue===0)break e;ue--,re+=G[Q++]<<se,se+=8}if((240&Se)==0){for(He=me,Ye=Se,We=ye;Se=(je=j.distcode[We+((re&(1<<He+Ye)-1)>>He)])>>>16&255,ye=65535&je,!(He+(me=je>>>24)<=se);){if(ue===0)break e;ue--,re+=G[Q++]<<se,se+=8}re>>>=He,se-=He,j.back+=He}if(re>>>=me,se-=me,j.back+=me,64&Se){F.msg="invalid distance code",j.mode=30;break}j.offset=ye,j.extra=15&Se,j.mode=24;case 24:if(j.extra){for(ke=j.extra;se<ke;){if(ue===0)break e;ue--,re+=G[Q++]<<se,se+=8}j.offset+=re&(1<<j.extra)-1,re>>>=j.extra,se-=j.extra,j.back+=j.extra}if(j.offset>j.dmax){F.msg="invalid distance too far back",j.mode=30;break}j.mode=25;case 25:if(te===0)break e;if(Me=fe-te,j.offset>Me){if((Me=j.offset-Me)>j.whave&&j.sane){F.msg="invalid distance too far back",j.mode=30;break}Pe=Me>j.wnext?(Me-=j.wnext,j.wsize-Me):j.wnext-Me,Me>j.length&&(Me=j.length),Ne=j.window}else Ne=W,Pe=ne-j.offset,Me=j.length;for(te<Me&&(Me=te),te-=Me,j.length-=Me;W[ne++]=Ne[Pe++],--Me;);j.length===0&&(j.mode=21);break;case 26:if(te===0)break e;W[ne++]=j.length,te--,j.mode=21;break;case 27:if(j.wrap){for(;se<32;){if(ue===0)break e;ue--,re|=G[Q++]<<se,se+=8}if(fe-=te,F.total_out+=fe,j.total+=fe,fe&&(F.adler=j.check=j.flags?c(j.check,W,fe,ne-fe):a(j.check,W,fe,ne-fe)),fe=te,(j.flags?re:_(re))!==j.check){F.msg="incorrect data check",j.mode=30;break}se=re=0}j.mode=28;case 28:if(j.wrap&&j.flags){for(;se<32;){if(ue===0)break e;ue--,re+=G[Q++]<<se,se+=8}if(re!==(4294967295&j.total)){F.msg="incorrect length check",j.mode=30;break}se=re=0}j.mode=29;case 29:Ze=1;break e;case 30:Ze=-3;break e;case 31:return-4;default:return p}return F.next_out=ne,F.avail_out=te,F.next_in=Q,F.avail_in=ue,j.hold=re,j.bits=se,(j.wsize||fe!==F.avail_out&&j.mode<30&&(j.mode<27||B!==4))&&O(F,F.output,F.next_out,fe-F.avail_out)?(j.mode=31,-4):(ce-=F.avail_in,fe-=F.avail_out,F.total_in+=ce,F.total_out+=fe,j.total+=fe,j.wrap&&fe&&(F.adler=j.check=j.flags?c(j.check,W,fe,F.next_out-fe):a(j.check,W,fe,F.next_out-fe)),F.data_type=j.bits+(j.last?64:0)+(j.mode===12?128:0)+(j.mode===20||j.mode===15?256:0),(ce==0&&fe===0||B===4)&&Ze===f&&(Ze=-5),Ze)},o.inflateEnd=function(F){if(!F||!F.state)return p;var B=F.state;return B.window&&(B.window=null),F.state=null,f},o.inflateGetHeader=function(F,B){var j;return F&&F.state?(2&(j=F.state).wrap)==0?p:((j.head=B).done=!1,f):p},o.inflateSetDictionary=function(F,B){var j,G=B.length;return F&&F.state?(j=F.state).wrap!==0&&j.mode!==11?p:j.mode===11&&a(1,B,G,0)!==j.check?-3:O(F,B,G,G)?(j.mode=31,-4):(j.havedict=1,f):p},o.inflateInfo="pako inflate (from Nodeca project)"},{"../utils/common":41,"./adler32":43,"./crc32":45,"./inffast":48,"./inftrees":50}],50:[function(r,i,o){var s=r("../utils/common"),a=[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],c=[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],l=[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],u=[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];i.exports=function(d,h,f,p,m,g,y,_){var x,b,w,S,E,C,A,R,L,O=_.bits,F=0,B=0,j=0,G=0,W=0,Q=0,ne=0,ue=0,te=0,re=0,se=null,ce=0,fe=new s.Buf16(16),Me=new s.Buf16(16),Pe=null,Ne=0;for(F=0;F<=15;F++)fe[F]=0;for(B=0;B<p;B++)fe[h[f+B]]++;for(W=O,G=15;1<=G&&fe[G]===0;G--);if(G<W&&(W=G),G===0)return m[g++]=20971520,m[g++]=20971520,_.bits=1,0;for(j=1;j<G&&fe[j]===0;j++);for(W<j&&(W=j),F=ue=1;F<=15;F++)if(ue<<=1,(ue-=fe[F])<0)return-1;if(0<ue&&(d===0||G!==1))return-1;for(Me[1]=0,F=1;F<15;F++)Me[F+1]=Me[F]+fe[F];for(B=0;B<p;B++)h[f+B]!==0&&(y[Me[h[f+B]]++]=B);if(C=d===0?(se=Pe=y,19):d===1?(se=a,ce-=257,Pe=c,Ne-=257,256):(se=l,Pe=u,-1),F=j,E=g,ne=B=re=0,w=-1,S=(te=1<<(Q=W))-1,d===1&&852<te||d===2&&592<te)return 1;for(;;){for(A=F-ne,L=y[B]<C?(R=0,y[B]):y[B]>C?(R=Pe[Ne+y[B]],se[ce+y[B]]):(R=96,0),x=1<<F-ne,j=b=1<<Q;m[E+(re>>ne)+(b-=x)]=A<<24|R<<16|L|0,b!==0;);for(x=1<<F-1;re&x;)x>>=1;if(x!==0?(re&=x-1,re+=x):re=0,B++,--fe[F]==0){if(F===G)break;F=h[f+y[B]]}if(W<F&&(re&S)!==w){for(ne===0&&(ne=W),E+=j,ue=1<<(Q=F-ne);Q+ne<G&&!((ue-=fe[Q+ne])<=0);)Q++,ue<<=1;if(te+=1<<Q,d===1&&852<te||d===2&&592<te)return 1;m[w=re&S]=W<<24|Q<<16|E-g|0}}return re!==0&&(m[E+re]=F-ne<<24|64<<16|0),_.bits=W,0}},{"../utils/common":41}],51:[function(r,i,o){i.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(r,i,o){var s=r("../utils/common"),a=0,c=1;function l(je){for(var Re=je.length;0<=--Re;)je[Re]=0}var u=0,d=29,h=256,f=h+1+d,p=30,m=19,g=2*f+1,y=15,_=16,x=7,b=256,w=16,S=17,E=18,C=[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],A=[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],R=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7],L=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],O=new Array(2*(f+2));l(O);var F=new Array(2*p);l(F);var B=new Array(512);l(B);var j=new Array(256);l(j);var G=new Array(d);l(G);var W,Q,ne,ue=new Array(p);function te(je,Re,be,Ce,Te){this.static_tree=je,this.extra_bits=Re,this.extra_base=be,this.elems=Ce,this.max_length=Te,this.has_stree=je&&je.length}function re(je,Re){this.dyn_tree=je,this.max_code=0,this.stat_desc=Re}function se(je){return je<256?B[je]:B[256+(je>>>7)]}function ce(je,Re){je.pending_buf[je.pending++]=255&Re,je.pending_buf[je.pending++]=Re>>>8&255}function fe(je,Re,be){je.bi_valid>_-be?(je.bi_buf|=Re<<je.bi_valid&65535,ce(je,je.bi_buf),je.bi_buf=Re>>_-je.bi_valid,je.bi_valid+=be-_):(je.bi_buf|=Re<<je.bi_valid&65535,je.bi_valid+=be)}function Me(je,Re,be){fe(je,be[2*Re],be[2*Re+1])}function Pe(je,Re){for(var be=0;be|=1&je,je>>>=1,be<<=1,0<--Re;);return be>>>1}function Ne(je,Re,be){var Ce,Te,Be=new Array(y+1),Xe=0;for(Ce=1;Ce<=y;Ce++)Be[Ce]=Xe=Xe+be[Ce-1]<<1;for(Te=0;Te<=Re;Te++){var et=je[2*Te+1];et!==0&&(je[2*Te]=Pe(Be[et]++,et))}}function me(je){var Re;for(Re=0;Re<f;Re++)je.dyn_ltree[2*Re]=0;for(Re=0;Re<p;Re++)je.dyn_dtree[2*Re]=0;for(Re=0;Re<m;Re++)je.bl_tree[2*Re]=0;je.dyn_ltree[2*b]=1,je.opt_len=je.static_len=0,je.last_lit=je.matches=0}function Se(je){8<je.bi_valid?ce(je,je.bi_buf):0<je.bi_valid&&(je.pending_buf[je.pending++]=je.bi_buf),je.bi_buf=0,je.bi_valid=0}function ye(je,Re,be,Ce){var Te=2*Re,Be=2*be;return je[Te]<je[Be]||je[Te]===je[Be]&&Ce[Re]<=Ce[be]}function He(je,Re,be){for(var Ce=je.heap[be],Te=be<<1;Te<=je.heap_len&&(Te<je.heap_len&&ye(Re,je.heap[Te+1],je.heap[Te],je.depth)&&Te++,!ye(Re,Ce,je.heap[Te],je.depth));)je.heap[be]=je.heap[Te],be=Te,Te<<=1;je.heap[be]=Ce}function Ye(je,Re,be){var Ce,Te,Be,Xe,et=0;if(je.last_lit!==0)for(;Ce=je.pending_buf[je.d_buf+2*et]<<8|je.pending_buf[je.d_buf+2*et+1],Te=je.pending_buf[je.l_buf+et],et++,Ce===0?Me(je,Te,Re):(Me(je,(Be=j[Te])+h+1,Re),(Xe=C[Be])!==0&&fe(je,Te-=G[Be],Xe),Me(je,Be=se(--Ce),be),(Xe=A[Be])!==0&&fe(je,Ce-=ue[Be],Xe)),et<je.last_lit;);Me(je,b,Re)}function We(je,Re){var be,Ce,Te,Be=Re.dyn_tree,Xe=Re.stat_desc.static_tree,et=Re.stat_desc.has_stree,rt=Re.stat_desc.elems,at=-1;for(je.heap_len=0,je.heap_max=g,be=0;be<rt;be++)Be[2*be]!==0?(je.heap[++je.heap_len]=at=be,je.depth[be]=0):Be[2*be+1]=0;for(;je.heap_len<2;)Be[2*(Te=je.heap[++je.heap_len]=at<2?++at:0)]=1,je.depth[Te]=0,je.opt_len--,et&&(je.static_len-=Xe[2*Te+1]);for(Re.max_code=at,be=je.heap_len>>1;1<=be;be--)He(je,Be,be);for(Te=rt;be=je.heap[1],je.heap[1]=je.heap[je.heap_len--],He(je,Be,1),Ce=je.heap[1],je.heap[--je.heap_max]=be,je.heap[--je.heap_max]=Ce,Be[2*Te]=Be[2*be]+Be[2*Ce],je.depth[Te]=(je.depth[be]>=je.depth[Ce]?je.depth[be]:je.depth[Ce])+1,Be[2*be+1]=Be[2*Ce+1]=Te,je.heap[1]=Te++,He(je,Be,1),2<=je.heap_len;);je.heap[--je.heap_max]=je.heap[1],(function(lt,gt){var Mt,Dt,Ut,zt,At,Ht,Mn=gt.dyn_tree,_e=gt.max_code,tt=gt.stat_desc.static_tree,ct=gt.stat_desc.has_stree,_t=gt.stat_desc.extra_bits,It=gt.stat_desc.extra_base,Ft=gt.stat_desc.max_length,nn=0;for(zt=0;zt<=y;zt++)lt.bl_count[zt]=0;for(Mn[2*lt.heap[lt.heap_max]+1]=0,Mt=lt.heap_max+1;Mt<g;Mt++)Ft<(zt=Mn[2*Mn[2*(Dt=lt.heap[Mt])+1]+1]+1)&&(zt=Ft,nn++),Mn[2*Dt+1]=zt,_e<Dt||(lt.bl_count[zt]++,At=0,It<=Dt&&(At=_t[Dt-It]),Ht=Mn[2*Dt],lt.opt_len+=Ht*(zt+At),ct&&(lt.static_len+=Ht*(tt[2*Dt+1]+At)));if(nn!==0){do{for(zt=Ft-1;lt.bl_count[zt]===0;)zt--;lt.bl_count[zt]--,lt.bl_count[zt+1]+=2,lt.bl_count[Ft]--,nn-=2}while(0<nn);for(zt=Ft;zt!==0;zt--)for(Dt=lt.bl_count[zt];Dt!==0;)_e<(Ut=lt.heap[--Mt])||(Mn[2*Ut+1]!==zt&&(lt.opt_len+=(zt-Mn[2*Ut+1])*Mn[2*Ut],Mn[2*Ut+1]=zt),Dt--)}})(je,Re),Ne(Be,at,je.bl_count)}function ge(je,Re,be){var Ce,Te,Be=-1,Xe=Re[1],et=0,rt=7,at=4;for(Xe===0&&(rt=138,at=3),Re[2*(be+1)+1]=65535,Ce=0;Ce<=be;Ce++)Te=Xe,Xe=Re[2*(Ce+1)+1],++et<rt&&Te===Xe||(et<at?je.bl_tree[2*Te]+=et:Te!==0?(Te!==Be&&je.bl_tree[2*Te]++,je.bl_tree[2*w]++):et<=10?je.bl_tree[2*S]++:je.bl_tree[2*E]++,Be=Te,at=(et=0)===Xe?(rt=138,3):Te===Xe?(rt=6,3):(rt=7,4))}function Ze(je,Re,be){var Ce,Te,Be=-1,Xe=Re[1],et=0,rt=7,at=4;for(Xe===0&&(rt=138,at=3),Ce=0;Ce<=be;Ce++)if(Te=Xe,Xe=Re[2*(Ce+1)+1],!(++et<rt&&Te===Xe)){if(et<at)for(;Me(je,Te,je.bl_tree),--et!=0;);else Te!==0?(Te!==Be&&(Me(je,Te,je.bl_tree),et--),Me(je,w,je.bl_tree),fe(je,et-3,2)):et<=10?(Me(je,S,je.bl_tree),fe(je,et-3,3)):(Me(je,E,je.bl_tree),fe(je,et-11,7));Be=Te,at=(et=0)===Xe?(rt=138,3):Te===Xe?(rt=6,3):(rt=7,4)}}l(ue);var $e=!1;function ke(je,Re,be,Ce){fe(je,(u<<1)+(Ce?1:0),3),(function(Te,Be,Xe,et){Se(Te),ce(Te,Xe),ce(Te,~Xe),s.arraySet(Te.pending_buf,Te.window,Be,Xe,Te.pending),Te.pending+=Xe})(je,Re,be)}o._tr_init=function(je){$e||((function(){var Re,be,Ce,Te,Be,Xe=new Array(y+1);for(Te=Ce=0;Te<d-1;Te++)for(G[Te]=Ce,Re=0;Re<1<<C[Te];Re++)j[Ce++]=Te;for(j[Ce-1]=Te,Te=Be=0;Te<16;Te++)for(ue[Te]=Be,Re=0;Re<1<<A[Te];Re++)B[Be++]=Te;for(Be>>=7;Te<p;Te++)for(ue[Te]=Be<<7,Re=0;Re<1<<A[Te]-7;Re++)B[256+Be++]=Te;for(be=0;be<=y;be++)Xe[be]=0;for(Re=0;Re<=143;)O[2*Re+1]=8,Re++,Xe[8]++;for(;Re<=255;)O[2*Re+1]=9,Re++,Xe[9]++;for(;Re<=279;)O[2*Re+1]=7,Re++,Xe[7]++;for(;Re<=287;)O[2*Re+1]=8,Re++,Xe[8]++;for(Ne(O,f+1,Xe),Re=0;Re<p;Re++)F[2*Re+1]=5,F[2*Re]=Pe(Re,5);W=new te(O,C,h+1,f,y),Q=new te(F,A,0,p,y),ne=new te(new Array(0),R,0,m,x)})(),$e=!0),je.l_desc=new re(je.dyn_ltree,W),je.d_desc=new re(je.dyn_dtree,Q),je.bl_desc=new re(je.bl_tree,ne),je.bi_buf=0,je.bi_valid=0,me(je)},o._tr_stored_block=ke,o._tr_flush_block=function(je,Re,be,Ce){var Te,Be,Xe=0;0<je.level?(je.strm.data_type===2&&(je.strm.data_type=(function(et){var rt,at=4093624447;for(rt=0;rt<=31;rt++,at>>>=1)if(1&at&&et.dyn_ltree[2*rt]!==0)return a;if(et.dyn_ltree[18]!==0||et.dyn_ltree[20]!==0||et.dyn_ltree[26]!==0)return c;for(rt=32;rt<h;rt++)if(et.dyn_ltree[2*rt]!==0)return c;return a})(je)),We(je,je.l_desc),We(je,je.d_desc),Xe=(function(et){var rt;for(ge(et,et.dyn_ltree,et.l_desc.max_code),ge(et,et.dyn_dtree,et.d_desc.max_code),We(et,et.bl_desc),rt=m-1;3<=rt&&et.bl_tree[2*L[rt]+1]===0;rt--);return et.opt_len+=3*(rt+1)+5+5+4,rt})(je),Te=je.opt_len+3+7>>>3,(Be=je.static_len+3+7>>>3)<=Te&&(Te=Be)):Te=Be=be+5,be+4<=Te&&Re!==-1?ke(je,Re,be,Ce):je.strategy===4||Be===Te?(fe(je,2+(Ce?1:0),3),Ye(je,O,F)):(fe(je,4+(Ce?1:0),3),(function(et,rt,at,lt){var gt;for(fe(et,rt-257,5),fe(et,at-1,5),fe(et,lt-4,4),gt=0;gt<lt;gt++)fe(et,et.bl_tree[2*L[gt]+1],3);Ze(et,et.dyn_ltree,rt-1),Ze(et,et.dyn_dtree,at-1)})(je,je.l_desc.max_code+1,je.d_desc.max_code+1,Xe+1),Ye(je,je.dyn_ltree,je.dyn_dtree)),me(je),Ce&&Se(je)},o._tr_tally=function(je,Re,be){return je.pending_buf[je.d_buf+2*je.last_lit]=Re>>>8&255,je.pending_buf[je.d_buf+2*je.last_lit+1]=255&Re,je.pending_buf[je.l_buf+je.last_lit]=255&be,je.last_lit++,Re===0?je.dyn_ltree[2*be]++:(je.matches++,Re--,je.dyn_ltree[2*(j[be]+h+1)]++,je.dyn_dtree[2*se(Re)]++),je.last_lit===je.lit_bufsize-1},o._tr_align=function(je){fe(je,2,3),Me(je,b,O),(function(Re){Re.bi_valid===16?(ce(Re,Re.bi_buf),Re.bi_buf=0,Re.bi_valid=0):8<=Re.bi_valid&&(Re.pending_buf[Re.pending++]=255&Re.bi_buf,Re.bi_buf>>=8,Re.bi_valid-=8)})(je)}},{"../utils/common":41}],53:[function(r,i,o){i.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(r,i,o){(function(s){(function(a,c){if(!a.setImmediate){var l,u,d,h,f=1,p={},m=!1,g=a.document,y=Object.getPrototypeOf&&Object.getPrototypeOf(a);y=y&&y.setTimeout?y:a,l={}.toString.call(a.process)==="[object process]"?function(w){t.nextTick(function(){x(w)})}:(function(){if(a.postMessage&&!a.importScripts){var w=!0,S=a.onmessage;return a.onmessage=function(){w=!1},a.postMessage("","*"),a.onmessage=S,w}})()?(h="setImmediate$"+Math.random()+"$",a.addEventListener?a.addEventListener("message",b,!1):a.attachEvent("onmessage",b),function(w){a.postMessage(h+w,"*")}):a.MessageChannel?((d=new MessageChannel).port1.onmessage=function(w){x(w.data)},function(w){d.port2.postMessage(w)}):g&&"onreadystatechange"in g.createElement("script")?(u=g.documentElement,function(w){var S=g.createElement("script");S.onreadystatechange=function(){x(w),S.onreadystatechange=null,u.removeChild(S),S=null},u.appendChild(S)}):function(w){setTimeout(x,0,w)},y.setImmediate=function(w){typeof w!="function"&&(w=new Function(""+w));for(var S=new Array(arguments.length-1),E=0;E<S.length;E++)S[E]=arguments[E+1];var C={callback:w,args:S};return p[f]=C,l(f),f++},y.clearImmediate=_}function _(w){delete p[w]}function x(w){if(m)setTimeout(x,0,w);else{var S=p[w];if(S){m=!0;try{(function(E){var C=E.callback,A=E.args;switch(A.length){case 0:C();break;case 1:C(A[0]);break;case 2:C(A[0],A[1]);break;case 3:C(A[0],A[1],A[2]);break;default:C.apply(c,A)}})(S)}finally{_(w),m=!1}}}}function b(w){w.source===a&&typeof w.data=="string"&&w.data.indexOf(h)===0&&x(+w.data.slice(h.length))}})(typeof self>"u"?s===void 0?this:s:self)}).call(this,typeof nD<"u"?nD:typeof self<"u"?self:typeof window<"u"?window:{})},{}]},{},[10])(10)})})(R2e)),R2e.exports}var PZn=CZn();const N2e=F2(PZn);var AZn=["circuit-json-to-bom-csv","circuit-json-to-bpc","circuit-json-to-connectivity-map","circuit-json-to-gerber","circuit-json-to-gltf","circuit-json-to-kicad","circuit-json-to-lbrn","circuit-json-to-pnp-csv","circuit-json-to-readable-netlist","circuit-json-to-simple-3d","circuit-json-to-spice","circuit-json-to-step","circuit-json-to-tscircuit","circuit-to-canvas","circuit-to-svg"],RZn=new Set(AZn),NZn=n=>{const e=n.indexOf("@");return e===-1?n:n.slice(0,e)},IZn=n=>{const e=NZn(n);if(!RZn.has(e))throw new Error(`Unsupported module: ${n}`);return`https://esm.run/${n}`};async function kZn(n){return import(IZn(n))}var KS=kZn,ZO={},I2e={},Wht;function OZn(){return Wht||(Wht=1,(function(n){Object.defineProperty(n,"__esModule",{value:!0});var e=(function(){function o(s,a){var c=[],l=!0,u=!1,d=void 0;try{for(var h=s[Symbol.iterator](),f;!(l=(f=h.next()).done)&&(c.push(f.value),!(a&&c.length===a));l=!0);}catch(p){u=!0,d=p}finally{try{!l&&h.return&&h.return()}finally{if(u)throw d}}return c}return function(s,a){if(Array.isArray(s))return s;if(Symbol.iterator in Object(s))return o(s,a);throw new TypeError("Invalid attempt to destructure non-iterable instance")}})();n.default=r,n.parseUnitObj=i;var t=/-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/;function r(o){var s=parseFloat(o),a=o.match(t)||[],c=a.length>0?o.substr(a[0].length).trim():"";return[s,c]}function i(o){var s=r(o),a=e(s,2),c=a[0],l=a[1];return{val:c,unit:l}}})(I2e)),I2e}var Zht;function LZn(){if(Zht)return ZO;Zht=1,Object.defineProperty(ZO,"__esModule",{value:!0});var n=(function(){function c(l,u){var d=[],h=!0,f=!1,p=void 0;try{for(var m=l[Symbol.iterator](),g;!(h=(g=m.next()).done)&&(d.push(g.value),!(u&&d.length===u));h=!0);}catch(y){f=!0,p=y}finally{try{!h&&m.return&&m.return()}finally{if(f)throw p}}return d}return function(l,u){if(Array.isArray(l))return l;if(Symbol.iterator in Object(l))return c(l,u);throw new TypeError("Invalid attempt to destructure non-iterable instance")}})();ZO.formatSI=o,ZO.unformatSI=a;function e(c){return c&&c.__esModule?c:{default:c}}var t=OZn(),r=e(t),i={24:"Y",21:"Z",18:"E",15:"P",12:"T",9:"G",6:"M",3:"k",0:"","-3":"m","-6":"µ","-9":"n","-12":"p","-15":"f","-18":"a","-21":"z","-24":"y"};function o(c){if(c===0)return"0";for(var l=Math.abs(c),u=0;l>=1e3&&u<24;)l/=1e3,u+=3;for(;l<1&&u>-24;)l*=1e3,u-=3;var d=c<0?"-":"";return l>1e3?d+l.toFixed(0)+i[u]:d+parseFloat(l.toPrecision(3))+i[u]}var s={Y:1e24,Z:1e21,E:1e18,P:1e15,T:1e12,G:1e9,M:1e6,k:1e3,"":1,m:.001,µ:1e-6,u:1e-6,n:1e-9,p:1e-12,f:1e-15,a:1e-18,z:1e-21,y:1e-24};function a(c){if(c==null||c==="")return NaN;var l=(0,r.default)(c),u=n(l,2),d=u[0],h=u[1],f=s[h];return d*f}return ZO}var DZn=LZn(),yq={exports:{}};var zZn=yq.exports,Kht;function $Zn(){return Kht||(Kht=1,(function(n,e){((t,r)=>{n.exports=r()})(zZn,function t(){var r=typeof self<"u"?self:typeof window<"u"?window:r!==void 0?r:{},i,o=!r.document&&!!r.postMessage,s=r.IS_PAPA_WORKER||!1,a={},c=0,l={};function u(C){this._handle=null,this._finished=!1,this._completed=!1,this._halted=!1,this._input=null,this._baseIndex=0,this._partialLine="",this._rowCount=0,this._start=0,this._nextChunk=null,this.isFirstChunk=!0,this._completeResults={data:[],errors:[],meta:{}},(function(A){var R=w(A);R.chunkSize=parseInt(R.chunkSize),A.step||A.chunk||(R.chunkSize=null),this._handle=new m(R),(this._handle.streamer=this)._config=R}).call(this,C),this.parseChunk=function(A,R){var L=parseInt(this._config.skipFirstNLines)||0;if(this.isFirstChunk&&0<L){let F=this._config.newline;F||(O=this._config.quoteChar||'"',F=this._handle.guessLineEndings(A,O)),A=[...A.split(F).slice(L)].join(F)}this.isFirstChunk&&E(this._config.beforeFirstChunk)&&(O=this._config.beforeFirstChunk(A))!==void 0&&(A=O),this.isFirstChunk=!1,this._halted=!1;var L=this._partialLine+A,O=(this._partialLine="",this._handle.parse(L,this._baseIndex,!this._finished));if(!this._handle.paused()&&!this._handle.aborted()){if(A=O.meta.cursor,L=(this._finished||(this._partialLine=L.substring(A-this._baseIndex),this._baseIndex=A),O&&O.data&&(this._rowCount+=O.data.length),this._finished||this._config.preview&&this._rowCount>=this._config.preview),s)r.postMessage({results:O,workerId:l.WORKER_ID,finished:L});else if(E(this._config.chunk)&&!R){if(this._config.chunk(O,this._handle),this._handle.paused()||this._handle.aborted())return void(this._halted=!0);this._completeResults=O=void 0}return this._config.step||this._config.chunk||(this._completeResults.data=this._completeResults.data.concat(O.data),this._completeResults.errors=this._completeResults.errors.concat(O.errors),this._completeResults.meta=O.meta),this._completed||!L||!E(this._config.complete)||O&&O.meta.aborted||(this._config.complete(this._completeResults,this._input),this._completed=!0),L||O&&O.meta.paused||this._nextChunk(),O}this._halted=!0},this._sendError=function(A){E(this._config.error)?this._config.error(A):s&&this._config.error&&r.postMessage({workerId:l.WORKER_ID,error:A,finished:!1})}}function d(C){var A;(C=C||{}).chunkSize||(C.chunkSize=l.RemoteChunkSize),u.call(this,C),this._nextChunk=o?function(){this._readChunk(),this._chunkLoaded()}:function(){this._readChunk()},this.stream=function(R){this._input=R,this._nextChunk()},this._readChunk=function(){if(this._finished)this._chunkLoaded();else{if(A=new XMLHttpRequest,this._config.withCredentials&&(A.withCredentials=this._config.withCredentials),o||(A.onload=S(this._chunkLoaded,this),A.onerror=S(this._chunkError,this)),A.open(this._config.downloadRequestBody?"POST":"GET",this._input,!o),this._config.downloadRequestHeaders){var R,L=this._config.downloadRequestHeaders;for(R in L)A.setRequestHeader(R,L[R])}var O;this._config.chunkSize&&(O=this._start+this._config.chunkSize-1,A.setRequestHeader("Range","bytes="+this._start+"-"+O));try{A.send(this._config.downloadRequestBody)}catch(F){this._chunkError(F.message)}o&&A.status===0&&this._chunkError()}},this._chunkLoaded=function(){A.readyState===4&&(A.status<200||400<=A.status?this._chunkError():(this._start+=this._config.chunkSize||A.responseText.length,this._finished=!this._config.chunkSize||this._start>=(R=>(R=R.getResponseHeader("Content-Range"))!==null?parseInt(R.substring(R.lastIndexOf("/")+1)):-1)(A),this.parseChunk(A.responseText)))},this._chunkError=function(R){R=A.statusText||R,this._sendError(new Error(R))}}function h(C){(C=C||{}).chunkSize||(C.chunkSize=l.LocalChunkSize),u.call(this,C);var A,R,L=typeof FileReader<"u";this.stream=function(O){this._input=O,R=O.slice||O.webkitSlice||O.mozSlice,L?((A=new FileReader).onload=S(this._chunkLoaded,this),A.onerror=S(this._chunkError,this)):A=new FileReaderSync,this._nextChunk()},this._nextChunk=function(){this._finished||this._config.preview&&!(this._rowCount<this._config.preview)||this._readChunk()},this._readChunk=function(){var O=this._input,F=(this._config.chunkSize&&(F=Math.min(this._start+this._config.chunkSize,this._input.size),O=R.call(O,this._start,F)),A.readAsText(O,this._config.encoding));L||this._chunkLoaded({target:{result:F}})},this._chunkLoaded=function(O){this._start+=this._config.chunkSize,this._finished=!this._config.chunkSize||this._start>=this._input.size,this.parseChunk(O.target.result)},this._chunkError=function(){this._sendError(A.error)}}function f(C){var A;u.call(this,C=C||{}),this.stream=function(R){return A=R,this._nextChunk()},this._nextChunk=function(){var R,L;if(!this._finished)return R=this._config.chunkSize,A=R?(L=A.substring(0,R),A.substring(R)):(L=A,""),this._finished=!A,this.parseChunk(L)}}function p(C){u.call(this,C=C||{});var A=[],R=!0,L=!1;this.pause=function(){u.prototype.pause.apply(this,arguments),this._input.pause()},this.resume=function(){u.prototype.resume.apply(this,arguments),this._input.resume()},this.stream=function(O){this._input=O,this._input.on("data",this._streamData),this._input.on("end",this._streamEnd),this._input.on("error",this._streamError)},this._checkIsFinished=function(){L&&A.length===1&&(this._finished=!0)},this._nextChunk=function(){this._checkIsFinished(),A.length?this.parseChunk(A.shift()):R=!0},this._streamData=S(function(O){try{A.push(typeof O=="string"?O:O.toString(this._config.encoding)),R&&(R=!1,this._checkIsFinished(),this.parseChunk(A.shift()))}catch(F){this._streamError(F)}},this),this._streamError=S(function(O){this._streamCleanUp(),this._sendError(O)},this),this._streamEnd=S(function(){this._streamCleanUp(),L=!0,this._streamData("")},this),this._streamCleanUp=S(function(){this._input.removeListener("data",this._streamData),this._input.removeListener("end",this._streamEnd),this._input.removeListener("error",this._streamError)},this)}function m(C){var A,R,L,O,F=Math.pow(2,53),B=-F,j=/^\s*-?(\d+\.?|\.\d+|\d+\.\d+)([eE][-+]?\d+)?\s*$/,G=/^((\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d+([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z)))$/,W=this,Q=0,ne=0,ue=!1,te=!1,re=[],se={data:[],errors:[],meta:{}};function ce(Ne){return C.skipEmptyLines==="greedy"?Ne.join("").trim()==="":Ne.length===1&&Ne[0].length===0}function fe(){if(se&&L&&(Pe("Delimiter","UndetectableDelimiter","Unable to auto-detect delimiting character; defaulted to '"+l.DefaultDelimiter+"'"),L=!1),C.skipEmptyLines&&(se.data=se.data.filter(function(ye){return!ce(ye)})),Me()){let ye=function(He,Ye){E(C.transformHeader)&&(He=C.transformHeader(He,Ye)),re.push(He)};if(se)if(Array.isArray(se.data[0])){for(var Ne=0;Me()&&Ne<se.data.length;Ne++)se.data[Ne].forEach(ye);se.data.splice(0,1)}else se.data.forEach(ye)}function me(ye,He){for(var Ye=C.header?{}:[],We=0;We<ye.length;We++){var ge=We,Ze=ye[We],Ze=(($e,ke)=>(je=>(C.dynamicTypingFunction&&C.dynamicTyping[je]===void 0&&(C.dynamicTyping[je]=C.dynamicTypingFunction(je)),(C.dynamicTyping[je]||C.dynamicTyping)===!0))($e)?ke==="true"||ke==="TRUE"||ke!=="false"&&ke!=="FALSE"&&((je=>{if(j.test(je)&&(je=parseFloat(je),B<je&&je<F))return 1})(ke)?parseFloat(ke):G.test(ke)?new Date(ke):ke===""?null:ke):ke)(ge=C.header?We>=re.length?"__parsed_extra":re[We]:ge,Ze=C.transform?C.transform(Ze,ge):Ze);ge==="__parsed_extra"?(Ye[ge]=Ye[ge]||[],Ye[ge].push(Ze)):Ye[ge]=Ze}return C.header&&(We>re.length?Pe("FieldMismatch","TooManyFields","Too many fields: expected "+re.length+" fields but parsed "+We,ne+He):We<re.length&&Pe("FieldMismatch","TooFewFields","Too few fields: expected "+re.length+" fields but parsed "+We,ne+He)),Ye}var Se;se&&(C.header||C.dynamicTyping||C.transform)&&(Se=1,!se.data.length||Array.isArray(se.data[0])?(se.data=se.data.map(me),Se=se.data.length):se.data=me(se.data,0),C.header&&se.meta&&(se.meta.fields=re),ne+=Se)}function Me(){return C.header&&re.length===0}function Pe(Ne,me,Se,ye){Ne={type:Ne,code:me,message:Se},ye!==void 0&&(Ne.row=ye),se.errors.push(Ne)}E(C.step)&&(O=C.step,C.step=function(Ne){se=Ne,Me()?fe():(fe(),se.data.length!==0&&(Q+=Ne.data.length,C.preview&&Q>C.preview?R.abort():(se.data=se.data[0],O(se,W))))}),this.parse=function(Ne,me,Se){var ye=C.quoteChar||'"',ye=(C.newline||(C.newline=this.guessLineEndings(Ne,ye)),L=!1,C.delimiter?E(C.delimiter)&&(C.delimiter=C.delimiter(Ne),se.meta.delimiter=C.delimiter):((ye=((He,Ye,We,ge,Ze)=>{var $e,ke,je,Re;Ze=Ze||[","," ","|",";",l.RECORD_SEP,l.UNIT_SEP];for(var be=0;be<Ze.length;be++){for(var Ce,Te=Ze[be],Be=0,Xe=0,et=0,rt=(je=void 0,new y({comments:ge,delimiter:Te,newline:Ye,preview:10}).parse(He)),at=0;at<rt.data.length;at++)We&&ce(rt.data[at])?et++:(Ce=rt.data[at].length,Xe+=Ce,je===void 0?je=Ce:0<Ce&&(Be+=Math.abs(Ce-je),je=Ce));0<rt.data.length&&(Xe/=rt.data.length-et),(ke===void 0||Be<=ke)&&(Re===void 0||Re<Xe)&&1.99<Xe&&(ke=Be,$e=Te,Re=Xe)}return{successful:!!(C.delimiter=$e),bestDelimiter:$e}})(Ne,C.newline,C.skipEmptyLines,C.comments,C.delimitersToGuess)).successful?C.delimiter=ye.bestDelimiter:(L=!0,C.delimiter=l.DefaultDelimiter),se.meta.delimiter=C.delimiter),w(C));return C.preview&&C.header&&ye.preview++,A=Ne,R=new y(ye),se=R.parse(A,me,Se),fe(),ue?{meta:{paused:!0}}:se||{meta:{paused:!1}}},this.paused=function(){return ue},this.pause=function(){ue=!0,R.abort(),A=E(C.chunk)?"":A.substring(R.getCharIndex())},this.resume=function(){W.streamer._halted?(ue=!1,W.streamer.parseChunk(A,!0)):setTimeout(W.resume,3)},this.aborted=function(){return te},this.abort=function(){te=!0,R.abort(),se.meta.aborted=!0,E(C.complete)&&C.complete(se),A=""},this.guessLineEndings=function(He,ye){He=He.substring(0,1048576);var ye=new RegExp(g(ye)+"([^]*?)"+g(ye),"gm"),Se=(He=He.replace(ye,"")).split("\r"),ye=He.split(`
5690
5690
  `),He=1<ye.length&&ye[0].length<Se[0].length;if(Se.length===1||He)return`
5691
5691
  `;for(var Ye=0,We=0;We<Se.length;We++)Se[We][0]===`