@tscircuit/runframe 0.0.2475 → 0.0.2477
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.
package/dist/standalone.min.js
CHANGED
|
@@ -5685,7 +5685,7 @@ You passed in: '`+this.raw_options[r]+"'");return A},n.prototype._is_valid_selec
|
|
|
5685
5685
|
`);break}}return s}}}),Izo=mc({"node_modules/pretty/index.js"(t,e){var n=uzo(),o=pzo(),i=fHt(),r={unformatted:["code","pre","em","strong","span"],indent_inner_html:!0,indent_char:" ",indent_size:2,sep:`
|
|
5686
5686
|
`};e.exports=function(A,c){var l=i({},r,c);return A=n.html(A,l),l.ocd===!0?(l.newlines&&(l.sep=l.newlines),s(A,l)):A};function s(a,A){return o(a,A).replace(/^\s+/g,"").replace(/\s+$/g,`
|
|
5687
5687
|
`).replace(/(\s*<!--)/g,`
|
|
5688
|
-
$1`).replace(/>(\s*)(?=<!--\s*\/)/g,"> ")}}});function CHt(t,e,n){if(!e||!n)return;let o=t.get(e);o||(o=new Set,t.set(e,o)),o.add(n);let i=t.get(n);i||(i=new Set,t.set(n,i)),i.add(e)}function fzo(t,e){if(!e.subcircuit_id&&!e.source_group_id)return[...t];let n=e;if(e.subcircuit_id){const a=new Set([e.subcircuit_id]),A=new Map,c=new Map;for(const g of t)if(g.type==="source_group"){const u=g.source_group_id,h=g.subcircuit_id;h&&c.set(u,h);const d=g.parent_source_group_id;d&&(A.has(d)||A.set(d,[]),A.get(d).push(u))}let l;for(const[g,u]of c)if(u===e.subcircuit_id){l=g;break}if(l){const g=u=>{const h=A.get(u)||[];for(const d of h){const _=c.get(d);_&&a.add(_),g(d)}};g(l),n={...e,subcircuit_ids:Array.from(a)}}}const o=new Map;for(const a of t){const A=`${a.type}_id`,c=a[A];typeof c=="string"&&o.set(c,a)}const i=new Map;for(const a of t){const A=Object.entries(a);for(const[c,l]of A)if(c!=="parent_source_group_id"){if(c.endsWith("_id")&&typeof l=="string"){const g=o.get(l);CHt(i,a,g)}else if(c.endsWith("_ids")&&Array.isArray(l)){for(const g of l)if(typeof g=="string"){const u=o.get(g);CHt(i,a,u)}}}}const r=[],s=new Set;for(const a of t){let A=!1;(n.subcircuit_id&&"subcircuit_id"in a&&a.subcircuit_id===n.subcircuit_id||n.subcircuit_ids&&"subcircuit_id"in a&&a.subcircuit_id&&n.subcircuit_ids.includes(a.subcircuit_id)||n.source_group_id&&"source_group_id"in a&&a.source_group_id===n.source_group_id||n.source_group_id&&"member_source_group_ids"in a&&Array.isArray(a.member_source_group_ids)&&a.member_source_group_ids.includes(n.source_group_id))&&(A=!0),A&&(r.push(a),s.add(a))}for(;r.length>0;){const a=r.shift(),A=i.get(a);if(A)for(const c of A)s.has(c)||(s.add(c),r.push(c))}return t.filter(a=>s.has(a))}var Aae=(t,e={})=>{const n=t;let o=n._internal_store;if(!o){o={counts:{},editCount:0},n._internal_store=o;for(const r of n){const s=r.type,a=r[`${s}_id`];if(!a)continue;const A=Number.parseInt(a.split("_").pop());Number.isNaN(A)||(o.counts[s]=Math.max(o.counts[s]??0,A))}}const i=new Proxy({},{get:(r,s)=>{if(s==="toArray")return()=>(n.editCount=o.editCount,n);if(s==="editCount")return o.editCount;if(s==="subtree")return A=>Aae(fzo(n,A),e);if(s==="insert")return A=>{const c=A.type;if(!c)throw new Error("insert requires an element with a type");o.counts[c]??=-1,o.counts[c]++;const l=o.counts[c],g={...A,type:c,[`${c}_id`]:`${c}_${l}`};return e.validateInserts&&(S9e[c]??Ose).parse(g),n.push(g),o.editCount++,g};if(s==="insertAll")return A=>A.map(c=>i.insert(c));const a=s;return{get:A=>n.find(c=>c.type===a&&c[`${a}_id`]===A),getUsing:A=>{const c=Object.keys(A);if(c.length!==1)throw new Error("getUsing requires exactly one key, e.g. { pcb_component_id }");const l=c[0],g=l.replace("_id",""),u=n.find(h=>h.type===g&&h[l]===A[l]);return u?n.find(h=>h.type===a&&h[`${a}_id`]===u[`${a}_id`]):null},getWhere:A=>{const c=Object.keys(A);return n.find(l=>l.type===a&&c.every(g=>l[g]===A[g]))},list:A=>{const c=A?Object.keys(A):[];return n.filter(l=>l.type===a&&c.every(g=>l[g]===A[g]))},insert:A=>{o.counts[a]??=-1,o.counts[a]++;const c=o.counts[a],l={type:a,[`${a}_id`]:`${a}_${c}`,...A};return e.validateInserts&&(S9e[a]??Ose).parse(l),n.push(l),o.editCount++,l},delete:A=>{const c=n.find(l=>l[`${a}_id`]===A);c&&(n.splice(n.indexOf(c),1),o.editCount++)},update:(A,c)=>{const l=n.find(g=>g.type===a&&g[`${a}_id`]===A);return l?(Object.assign(l,c),o.editCount++,l):null},select:A=>{if(a==="source_component")return n.find(c=>c.type==="source_component"&&c.name===A.replace(/\./g,""));if(a==="pcb_port"||a==="source_port"||a==="schematic_port"){const[c,l]=A.replace(/\./g,"").split(/[\s\>]+/),g=n.find(h=>h.type==="source_component"&&h.name===c);if(!g)return null;const u=n.find(h=>h.type==="source_port"&&h.source_component_id===g.source_component_id&&(h.name===l||(h.port_hints??[]).includes(l)));if(!u)return null;if(a==="source_port")return u;if(a==="pcb_port")return n.find(h=>h.type==="pcb_port"&&h.source_port_id===u.source_port_id);if(a==="schematic_port")return n.find(h=>h.type==="schematic_port"&&h.source_port_id===u.source_port_id)}}}}});return i};Aae.unparsed=Aae;var q6=Aae;function X9e(t){const e=t.type;return`${e}:${t[`${e}_id`]}`}var yHt=(t,e={})=>{let n=t._internal_store_indexed;if(!n){n={counts:{},editCount:0,indexes:{}};for(const s of t){const a=s.type,A=s[`${a}_id`];if(!A)continue;const c=Number.parseInt(A.split("_").pop()||"");Number.isNaN(c)||(n.counts[a]=Math.max(n.counts[a]??0,c))}const i=e.indexConfig||{},r=n.indexes;if(i.byId&&(r.byId=new Map),i.byType&&(r.byType=new Map),i.byRelation&&(r.byRelation=new Map),i.bySubcircuit&&(r.bySubcircuit=new Map),i.byCustomField&&i.byCustomField.length>0){r.byCustomField=new Map;for(const s of i.byCustomField)r.byCustomField.set(s,new Map)}for(const s of t){if(i.byId){const a=X9e(s);r.byId.set(a,s)}if(i.byType){const a=r.byType.get(s.type)||[];a.push(s),r.byType.set(s.type,a)}if(i.byRelation){const a=Object.entries(s);for(const[A,c]of a)if(A.endsWith("_id")&&A!==`${s.type}_id`&&typeof c=="string"){const l=r.byRelation.get(A)||new Map,g=l.get(c)||[];g.push(s),l.set(c,g),r.byRelation.set(A,l)}}if(i.bySubcircuit&&"subcircuit_id"in s){const a=s.subcircuit_id;if(a&&typeof a=="string"){const A=r.bySubcircuit.get(a)||[];A.push(s),r.bySubcircuit.set(a,A)}}if(i.byCustomField&&r.byCustomField){for(const a of i.byCustomField)if(a in s){const A=s[a];if(A!==void 0&&(typeof A=="string"||typeof A=="number")){const c=String(A),l=r.byCustomField.get(a),g=l.get(c)||[];g.push(s),l.set(c,g)}}}}t._internal_store_indexed=n}return new Proxy({},{get:(i,r)=>{if(r==="toArray")return()=>(t.editCount=n.editCount,t);if(r==="editCount")return n.editCount;const s=r;return{get:a=>{const A=e.indexConfig||{};return A.byId&&n.indexes.byId?n.indexes.byId.get(`${s}:${a}`)||null:A.byType&&n.indexes.byType?(n.indexes.byType.get(s)||[]).find(l=>l[`${s}_id`]===a)||null:t.find(c=>c.type===s&&c[`${s}_id`]===a)||null},getUsing:a=>{const A=e.indexConfig||{},c=Object.keys(a);if(c.length!==1)throw new Error("getUsing requires exactly one key, e.g. { pcb_component_id }");const l=c[0],g=l.replace("_id","");if(A.byRelation&&n.indexes.byRelation){const h=n.indexes.byRelation.get(l);if(h){const _=(h.get(a[l])||[]).find(p=>p.type===g);if(!_)return null;const m=_[`${s}_id`];return A.byId&&n.indexes.byId?n.indexes.byId.get(`${s}:${m}`)||null:A.byType&&n.indexes.byType?(n.indexes.byType.get(s)||[]).find(I=>I[`${s}_id`]===m)||null:t.find(p=>p.type===s&&p[`${s}_id`]===m)||null}}const u=t.find(h=>h.type===g&&h[l]===a[l]);return u&&t.find(h=>h.type===s&&h[`${s}_id`]===u[`${s}_id`])||null},getWhere:a=>{const A=e.indexConfig||{},c=Object.keys(a);if(c.length===1&&A.byCustomField&&n.indexes.byCustomField){const l=c[0],g=n.indexes.byCustomField.get(l);if(g){const u=String(a[l]);return(g.get(u)||[]).find(d=>d.type===s)||null}}if("subcircuit_id"in a&&A.bySubcircuit&&n.indexes.bySubcircuit){const l=a.subcircuit_id;return(n.indexes.bySubcircuit.get(l)||[]).find(u=>u.type===s&&c.every(h=>u[h]===a[h]))||null}return A.byType&&n.indexes.byType?(n.indexes.byType.get(s)||[]).find(g=>c.every(u=>g[u]===a[u]))||null:t.find(l=>l.type===s&&c.every(g=>l[g]===a[g]))||null},list:a=>{const A=e.indexConfig||{},c=a?Object.keys(a):[];if(c.length===0&&A.byType&&n.indexes.byType)return n.indexes.byType.get(s)||[];if(c.length===1&&c[0]==="subcircuit_id"&&A.bySubcircuit&&n.indexes.bySubcircuit){const g=a.subcircuit_id;return(n.indexes.bySubcircuit.get(g)||[]).filter(h=>h.type===s)}let l;return A.byType&&n.indexes.byType?l=n.indexes.byType.get(s)||[]:l=t.filter(g=>g.type===s),c.length>0?l.filter(g=>c.every(u=>g[u]===a[u])):l},insert:a=>{n.counts[s]??=-1,n.counts[s]++;const A=n.counts[s],c={type:s,[`${s}_id`]:`${s}_${A}`,...a};e.validateInserts&&(S9e[s]??Ose).parse(c),t.push(c),n.editCount++;const l=e.indexConfig||{};if(l.byId&&n.indexes.byId){const g=X9e(c);n.indexes.byId.set(g,c)}if(l.byType&&n.indexes.byType){const g=n.indexes.byType.get(s)||[];g.push(c),n.indexes.byType.set(s,g)}if(l.byRelation&&n.indexes.byRelation){const g=Object.entries(c);for(const[u,h]of g)if(u.endsWith("_id")&&u!==`${c.type}_id`&&typeof h=="string"){const d=n.indexes.byRelation.get(u)||new Map,_=d.get(h)||[];_.push(c),d.set(h,_),n.indexes.byRelation.set(u,d)}}if(l.bySubcircuit&&n.indexes.bySubcircuit&&"subcircuit_id"in c){const g=c.subcircuit_id;if(g&&typeof g=="string"){const u=n.indexes.bySubcircuit.get(g)||[];u.push(c),n.indexes.bySubcircuit.set(g,u)}}if(l.byCustomField&&n.indexes.byCustomField){for(const g of l.byCustomField)if(g in c){const u=c[g];if(u!==void 0&&(typeof u=="string"||typeof u=="number")){const h=String(u),d=n.indexes.byCustomField.get(g),_=d.get(h)||[];_.push(c),d.set(h,_)}}}return c},delete:a=>{const A=e.indexConfig||{};let c;if(A.byId&&n.indexes.byId?c=n.indexes.byId.get(`${s}:${a}`):A.byType&&n.indexes.byType?c=(n.indexes.byType.get(s)||[]).find(u=>u[`${s}_id`]===a):c=t.find(g=>g[`${s}_id`]===a),!c)return;const l=t.indexOf(c);if(l>=0&&(t.splice(l,1),n.editCount++),A.byId&&n.indexes.byId){const g=X9e(c);n.indexes.byId.delete(g)}if(A.byType&&n.indexes.byType){const u=(n.indexes.byType.get(s)||[]).filter(h=>h[`${s}_id`]!==a);n.indexes.byType.set(s,u)}if(A.byRelation&&n.indexes.byRelation)for(const[g,u]of n.indexes.byRelation.entries())for(const[h,d]of u.entries()){const _=d.filter(m=>m!==c);_.length===0?u.delete(h):u.set(h,_)}if(A.bySubcircuit&&n.indexes.bySubcircuit&&"subcircuit_id"in c){const g=c.subcircuit_id;if(g){const h=(n.indexes.bySubcircuit.get(g)||[]).filter(d=>d!==c);h.length===0?n.indexes.bySubcircuit.delete(g):n.indexes.bySubcircuit.set(g,h)}}if(A.byCustomField&&n.indexes.byCustomField)for(const g of n.indexes.byCustomField.values())for(const[u,h]of g.entries()){const d=h.filter(_=>_!==c);d.length===0?g.delete(u):g.set(u,d)}},update:(a,A)=>{const c=e.indexConfig||{};let l;if(c.byId&&n.indexes.byId?l=n.indexes.byId.get(`${s}:${a}`):c.byType&&n.indexes.byType?l=(n.indexes.byType.get(s)||[]).find(u=>u[`${s}_id`]===a):l=t.find(g=>g.type===s&&g[`${s}_id`]===a),!l)return null;if(c.byRelation&&n.indexes.byRelation){const g=Object.entries(l);for(const[u,h]of g)if(u.endsWith("_id")&&u!==`${l.type}_id`&&typeof h=="string"&&u in A&&A[u]!==h){const d=n.indexes.byRelation.get(u);if(d){const m=(d.get(h)||[]).filter(p=>p!==l);m.length===0?d.delete(h):d.set(h,m)}}}if(c.bySubcircuit&&n.indexes.bySubcircuit&&"subcircuit_id"in l&&"subcircuit_id"in A){const g=l.subcircuit_id,u=A.subcircuit_id;if(g!==u){const d=(n.indexes.bySubcircuit.get(g)||[]).filter(_=>_!==l);d.length===0?n.indexes.bySubcircuit.delete(g):n.indexes.bySubcircuit.set(g,d)}}if(c.byCustomField&&n.indexes.byCustomField){for(const g of c.byCustomField)if(g in l&&g in A&&l[g]!==A[g]){const u=n.indexes.byCustomField.get(g);if(u){const h=String(l[g]),_=(u.get(h)||[]).filter(m=>m!==l);_.length===0?u.delete(h):u.set(h,_)}}}if(Object.assign(l,A),n.editCount++,c.byRelation&&n.indexes.byRelation){const g=Object.entries(l);for(const[u,h]of g)if(u.endsWith("_id")&&u!==`${l.type}_id`&&typeof h=="string"&&u in A){const d=n.indexes.byRelation.get(u)||new Map,_=d.get(h)||[];_.includes(l)||(_.push(l),d.set(h,_),n.indexes.byRelation.set(u,d))}}if(c.bySubcircuit&&n.indexes.bySubcircuit&&"subcircuit_id"in l&&"subcircuit_id"in A){const g=l.subcircuit_id;if(g&&typeof g=="string"){const u=n.indexes.bySubcircuit.get(g)||[];u.includes(l)||(u.push(l),n.indexes.bySubcircuit.set(g,u))}}if(c.byCustomField&&n.indexes.byCustomField){for(const g of c.byCustomField)if(g in l&&g in A){const u=l[g];if(u!==void 0&&(typeof u=="string"||typeof u=="number")){const h=String(u),d=n.indexes.byCustomField.get(g),_=d.get(h)||[];_.includes(l)||(_.push(l),d.set(h,_))}}}return l},select:a=>{if(s==="source_component")return t.find(A=>A.type==="source_component"&&A.name===a.replace(/\./g,""))||null;if(s==="pcb_port"||s==="source_port"||s==="schematic_port"){const[A,c]=a.replace(/\./g,"").split(/[\s\>]+/),l=t.find(u=>u.type==="source_component"&&u.name===A);if(!l)return null;const g=t.find(u=>u.type==="source_port"&&u.source_component_id===l.source_component_id&&(u.name===c||(u.port_hints??[]).includes(c)));if(!g)return null;if(s==="source_port")return g;if(s==="pcb_port")return t.find(u=>u.type==="pcb_port"&&u.source_port_id===g.source_port_id)||null;if(s==="schematic_port")return t.find(u=>u.type==="schematic_port"&&u.source_port_id===g.source_port_id)||null}return null}}}})};yHt.unparsed=yHt;var Czo=t=>{const e=t.type;return t[`${e}_id`]},EHt=(t,e)=>({minX:Math.min(t.minX,e.minX),minY:Math.min(t.minY,e.minY),maxX:Math.max(t.maxX,e.maxX),maxY:Math.max(t.maxY,e.maxY)}),cae=(t,e,n)=>{const o=n/2;return{minX:t-o,minY:e-o,maxX:t+o,maxY:e+o}},xHt=(t,e,n,o,i)=>{const r=n/2,s=o/2,a=i*Math.PI/180,A=Math.cos(a),c=Math.sin(a),l=[{x:-r,y:-s},{x:r,y:-s},{x:r,y:s},{x:-r,y:s}].map(g=>({x:t+g.x*A-g.y*c,y:e+g.x*c+g.y*A}));return{minX:Math.min(...l.map(g=>g.x)),minY:Math.min(...l.map(g=>g.y)),maxX:Math.max(...l.map(g=>g.x)),maxY:Math.max(...l.map(g=>g.y))}},$9e=t=>{let e=Number.POSITIVE_INFINITY,n=Number.POSITIVE_INFINITY,o=Number.NEGATIVE_INFINITY,i=Number.NEGATIVE_INFINITY;for(const r of t){if(!r.type.startsWith("pcb_"))continue;if(r.type==="pcb_smtpad"&&r.shape==="polygon"&&Array.isArray(r.points)){for(const g of r.points)e=Math.min(e,g.x),n=Math.min(n,g.y),o=Math.max(o,g.x),i=Math.max(i,g.y);continue}if(r.type==="pcb_hole"&&r.hole_shape==="circle"){const g=cae(r.x,r.y,r.hole_diameter);e=Math.min(e,g.minX),n=Math.min(n,g.minY),o=Math.max(o,g.maxX),i=Math.max(i,g.maxY);continue}if(r.type==="pcb_plated_hole"){let g;if("outer_diameter"in r&&typeof r.outer_diameter=="number"?g=cae(r.x,r.y,r.outer_diameter):"hole_diameter"in r&&typeof r.hole_diameter=="number"&&(g=cae(r.x,r.y,r.hole_diameter)),"rect_pad_width"in r&&typeof r.rect_pad_width=="number"&&"rect_pad_height"in r&&typeof r.rect_pad_height=="number"){const u=xHt(r.x,r.y,r.rect_pad_width,r.rect_pad_height,"rect_ccw_rotation"in r?r.rect_ccw_rotation??0:0);g=g?EHt(g,u):u}if("hole_diameter"in r&&typeof r.hole_diameter=="number"){const u=cae(r.x+("hole_offset_x"in r?r.hole_offset_x??0:0),r.y+("hole_offset_y"in r?r.hole_offset_y??0:0),r.hole_diameter);g=g?EHt(g,u):u}if(g){e=Math.min(e,g.minX),n=Math.min(n,g.minY),o=Math.max(o,g.maxX),i=Math.max(i,g.maxY);continue}}let s,a,A,c;"x"in r&&"y"in r&&(s=Number(r.x),a=Number(r.y)),"outer_diameter"in r&&(A=Number(r.outer_diameter),c=Number(r.outer_diameter)),"width"in r&&(A=Number(r.width)),"height"in r&&(c=Number(r.height)),"center"in r&&(s=r.center.x,a=r.center.y);const l=typeof r.rotation=="number"?r.rotation:0;if(s!==void 0&&a!==void 0){if(e=Math.min(e,s),n=Math.min(n,a),o=Math.max(o,s),i=Math.max(i,a),A!==void 0&&c!==void 0)if(l){const g=xHt(s,a,A,c,l);e=Math.min(e,g.minX),n=Math.min(n,g.minY),o=Math.max(o,g.maxX),i=Math.max(i,g.maxY)}else e=Math.min(e,s-A/2),n=Math.min(n,a-c/2),o=Math.max(o,s+A/2),i=Math.max(i,a+c/2);"radius"in r&&(e=Math.min(e,s-r.radius),n=Math.min(n,a-r.radius),o=Math.max(o,s+r.radius),i=Math.max(i,a+r.radius))}else if(r.type==="pcb_trace")for(const g of r.route)e=Math.min(e,g.x),n=Math.min(n,g.y),o=Math.max(o,g.x),i=Math.max(i,g.y);else if(r.type==="pcb_courtyard_outline")for(const g of r.outline)e=Math.min(e,g.x),n=Math.min(n,g.y),o=Math.max(o,g.x),i=Math.max(i,g.y);else if(r.type==="pcb_courtyard_polygon")for(const g of r.points)e=Math.min(e,g.x),n=Math.min(n,g.y),o=Math.max(o,g.x),i=Math.max(i,g.y)}return{minX:e,minY:n,maxX:o,maxY:i}};function yzo(t){let e=0;if(t.length==0)return e;for(var n=0;n<t.length;n++){var o=t.charCodeAt(n);e=(e<<5)-e+o,e=e&e}return Math.abs(e)}var BHt=[["#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"]],Ezo=t=>{let{x:e,y:n,width:o,height:i}={...t,...t.size,...t.center,...t.position};if(t.x1!==void 0&&t.x2!==void 0&&t.y1!==void 0&&t.y2!==void 0&&(e=(t.x1+t.x2)/2,n=(t.y1+t.y2)/2,o=Math.abs(t.x1-t.x2),i=Math.abs(t.y1-t.y2)),t.points&&Array.isArray(t.points)&&t.points.length>0){const a=t.points.map(h=>h.x),A=t.points.map(h=>h.y),c=Math.min(...a),l=Math.max(...a),g=Math.min(...A),u=Math.max(...A);e=(c+l)/2,n=(g+u)/2,o=l-c,i=u-g}const r=t.text||t.name||t.source?.text||t.source?.name||"?",s=t;return e===void 0||n===void 0?null:(o===void 0&&("outer_diameter"in t?(o=t.outer_diameter,i=t.outer_diameter):"rect_pad_width"in t&&"rect_pad_height"in t?(o=t.rect_pad_width,i=t.rect_pad_height,"hole_diameter"in t&&(o=Math.max(o,t.hole_diameter),i=Math.max(i,t.hole_diameter))):"hole_diameter"in t&&(o=t.hole_diameter,i=t.hole_diameter)),(o===void 0||i===void 0)&&(o=.1,i=.1),{x:e,y:n,width:o,height:i,title:r,content:s,bg_color:BHt[yzo(t.type||r)%BHt.length]?.[4]??"#f00"})},xzo=t=>!!t,Bzo=t=>{const e=t.filter(c=>c.type.startsWith("pcb_")||c.type.startsWith("schematic_")).concat(t.filter(c=>c.type==="pcb_trace"||c.type==="schematic_trace").flatMap(c=>c.route)).map(c=>Ezo(c)).filter(xzo);if(e.length===0)return{center:{x:0,y:0},width:0,height:0};let n=e[0].x-e[0].width/2,o=e[0].x+e[0].width/2,i=e[0].y-e[0].height/2,r=e[0].y+e[0].height/2;for(const c of e.slice(1))n=Math.min(n,c.x-c.width/2),o=Math.max(o,c.x+c.width/2),i=Math.min(i,c.y-c.height/2),r=Math.max(r,c.y+c.height/2);const s=o-n,a=r-i;return{center:{x:n+s/2,y:i+a/2},width:s,height:a}},Mp={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_PCB_NOTES:"pcb_viewer_is_showing_pcb_notes",IS_SHOWING_SILKSCREEN:"pcb_viewer_is_showing_silkscreen"},$P=(t,e)=>{if(typeof window>"u")return e;try{const n=localStorage.getItem(t);return n!==null?JSON.parse(n):e}catch{return e}},ZP=(t,e)=>{if(!(typeof window>"u"))try{localStorage.setItem(t,JSON.stringify(e))}catch{}},Qzo=(t,e)=>{if(typeof window>"u")return e;try{const n=localStorage.getItem(t);return n!==null?JSON.parse(n):e}catch{return e}},Szo=(t,e)=>{if(!(typeof window>"u"))try{localStorage.setItem(t,JSON.stringify(e))}catch{}},bzo="named_only",Dzo=(t={},e=!1)=>Ypt(n=>({selected_layer:"top",pcb_viewer_id:`pcb_viewer_${Math.random().toString().slice(2,10)}`,in_edit_mode:!1,in_move_footprint_mode:!1,is_moving_component:!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:$P(Mp.IS_SHOWING_COPPER_POURS,!0),is_showing_courtyards:$P(Mp.IS_SHOWING_COURTYARDS,!0),is_showing_pcb_groups:e?!1:$P(Mp.IS_SHOWING_PCB_GROUPS,!0),is_showing_group_anchor_offsets:$P(Mp.IS_SHOWING_GROUP_ANCHOR_OFFSETS,!1),is_showing_solder_mask:$P(Mp.IS_SHOWING_SOLDER_MASK,!1),is_showing_silkscreen:$P(Mp.IS_SHOWING_SILKSCREEN,!0),is_showing_fabrication_notes:$P(Mp.IS_SHOWING_FABRICATION_NOTES,!1),is_showing_pcb_notes:$P(Mp.IS_SHOWING_PCB_NOTES,!0),pcb_group_view_mode:e?"all":Qzo(Mp.PCB_GROUP_VIEW_MODE,bzo),hovered_error_id:null,focused_error_id:null,...t,selectLayer:o=>n({selected_layer:o}),setEditMode:o=>n({in_edit_mode:o!=="off",in_move_footprint_mode:o==="move_footprint",is_moving_component:!1}),setIsShowingRatsNest:o=>n({is_showing_rats_nest:o}),setIsMovingComponent:o=>n({is_moving_component:o}),setIsMouseOverContainer:o=>n({is_mouse_over_container:o}),setIsShowingMultipleTracesLength:o=>n({is_showing_multiple_traces_length:o}),setIsShowingAutorouting:o=>n({is_showing_autorouting:o}),setIsShowingDrcErrors:o=>n({is_showing_drc_errors:o}),setIsShowingCopperPours:o=>{ZP(Mp.IS_SHOWING_COPPER_POURS,o),n({is_showing_copper_pours:o})},setIsShowingCourtyards:o=>{ZP(Mp.IS_SHOWING_COURTYARDS,o),n({is_showing_courtyards:o})},setIsShowingPcbGroups:o=>{e||(ZP(Mp.IS_SHOWING_PCB_GROUPS,o),n({is_showing_pcb_groups:o}))},setIsShowingGroupAnchorOffsets:o=>{ZP(Mp.IS_SHOWING_GROUP_ANCHOR_OFFSETS,o),n({is_showing_group_anchor_offsets:o})},setIsShowingSolderMask:o=>{ZP(Mp.IS_SHOWING_SOLDER_MASK,o),n({is_showing_solder_mask:o})},setIsShowingSilkscreen:o=>{ZP(Mp.IS_SHOWING_SILKSCREEN,o),n({is_showing_silkscreen:o})},setIsShowingFabricationNotes:o=>{ZP(Mp.IS_SHOWING_FABRICATION_NOTES,o),n({is_showing_fabrication_notes:o})},setIsShowingPcbNotes:o=>{ZP(Mp.IS_SHOWING_PCB_NOTES,o),n({is_showing_pcb_notes:o})},setPcbGroupViewMode:o=>{e||(Szo(Mp.PCB_GROUP_VIEW_MODE,o),n({pcb_group_view_mode:o}))},setHoveredErrorId:o=>n({hovered_error_id:o}),setFocusedErrorId:o=>n({focused_error_id:o})})),yd=t=>{const e=X.useContext(QHt);return eIt(e,t)},QHt=X.createContext(null),vzo=({children:t,initialState:e,disablePcbGroups:n})=>{const o=X.useMemo(()=>Dzo(e,n),[n]);return z.jsx(QHt.Provider,{value:o,children:t})},Pzo=()=>{X.useEffect(()=>{ZUo()},[]);const t=yd(e=>e.pcb_viewer_id);return z.jsx($Uo,{position:"top-center",containerId:t})};function wzo(){var t=X.useRef(!1),e=X.useCallback(function(){return t.current},[]);return X.useEffect(function(){return t.current=!0,function(){t.current=!1}},[]),e}var Mzo=function(t){t===void 0&&(t={});var e=X.useState(t),n=e[0],o=e[1],i=X.useCallback(function(r){o(function(s){return Object.assign({},s,r instanceof Function?r(s):r)})},[]);return[n,i]},Nzo=Mzo,Rzo=function(){},SHt=typeof window<"u",Tzo=V9e(tzo()),kzo=function(){var t=wzo(),e=Nzo({value:void 0,error:void 0,noUserInteraction:!0}),n=e[0],o=e[1],i=X.useCallback(function(r){if(t()){var s,a;try{if(typeof r!="string"&&typeof r!="number"){var A=new Error("Cannot copy typeof "+typeof r+" to clipboard, must be a string");console.error(A),o({value:r,error:A,noUserInteraction:!0});return}else if(r===""){var A=new Error("Cannot copy empty string to clipboard.");console.error(A),o({value:r,error:A,noUserInteraction:!0});return}a=r.toString(),s=(0,Tzo.default)(a),o({value:a,error:void 0,noUserInteraction:s})}catch(c){o({value:a,error:c,noUserInteraction:s})}}},[]);return[n,i]},Fzo=kzo,Lzo=SHt?X.useLayoutEffect:X.useEffect,Hzo=Lzo,bHt={x:0,y:0,width:0,height:0,top:0,left:0,bottom:0,right:0};function Gzo(){var t=X.useState(null),e=t[0],n=t[1],o=X.useState(bHt),i=o[0],r=o[1],s=X.useMemo(function(){return new window.ResizeObserver(function(a){if(a[0]){var A=a[0].contentRect,c=A.x,l=A.y,g=A.width,u=A.height,h=A.top,d=A.left,_=A.bottom,m=A.right;r({x:c,y:l,width:g,height:u,top:h,left:d,bottom:_,right:m})}})},[]);return Hzo(function(){if(e)return s.observe(e),function(){s.disconnect()}},[e]),[n,i]}var GY=SHt&&typeof window.ResizeObserver<"u"?Gzo:function(){return[Rzo,bHt]},DHt=({initialTransform:t,initialTouch1:e,initialTouch2:n,finalTouch1:o,finalTouch2:i})=>{if(!o||!i)return t;const r={x:(e.x+n.x)/2,y:(e.y+n.y)/2},s={x:(o.x+i.x)/2,y:(o.y+i.y)/2},a=Math.hypot(n.x-e.x,n.y-e.y),A=Math.hypot(i.x-o.x,i.y-o.y),c=a===0?1:A/a,l=s.x-r.x,g=s.y-r.y;return Fi(ji(l,g),ji(r.x,r.y),gg(c,c),ji(-r.x,-r.y),t)},Ozo=(t={})=>{const e=X.useRef(null),[n,o]=X.useState(0),i=t.canvasElm??e.current,[r,s]=X.useState(t.initialTransform??Hl()),[a,A]=X.useState(0),[c,l]=X.useReducer(f=>f+1,0),g=X.useCallback(f=>{t.onSetTransform&&t.onSetTransform(f),t.transform||s(f)},[t.onSetTransform,s]),u=X.useCallback(f=>{g(f),l()},[g]),h=t.transform??r,d=X.useCallback(()=>{o(Date.now())},[]),_=X.useRef("none"),m=X.useRef(null),p=X.useRef(null);X.useEffect(()=>{const f=t.canvasElm??e.current;if(f&&!i){A(a+1);return}if(!f){const W=setTimeout(()=>{A(a+1)},100);return()=>clearTimeout(W)}let C=t.transform??r,y={x:0,y:0},E={x:0,y:0},B=!1;const Q=W=>({x:W.pageX-f.getBoundingClientRect().left-window.scrollX,y:W.pageY-f.getBoundingClientRect().top-window.scrollY});function b(W){t.enabled!==!1&&(t.shouldDrag&&!t.shouldDrag(W)||(y=Q(W),!(Date.now()-n<100)&&(B=!0,W.preventDefault())))}function D(W){if(!B||t.enabled===!1||t.shouldDrag&&!t.shouldDrag(W))return;E=Q(W);const j=Fi(ji(E.x-y.x,E.y-y.y),C);g(j),C=j,B=!1}function R(W){if(Q(W),!B||t.enabled===!1||t.shouldDrag&&!t.shouldDrag(W))return;E=Q(W);const j=Fi(ji(E.x-y.x,E.y-y.y),C);g(j)}function M(W){if(t.enabled===!1||t.shouldDrag&&!t.shouldDrag(W))return;const j=Q(W),te=Fi(ji(j.x,j.y),gg(1-W.deltaY/1e3,1-W.deltaY/1e3),ji(-j.x,-j.y),C);g(te),C=te,W.preventDefault()}function L(W){if(!B||t.shouldDrag&&!t.shouldDrag(W))return;if(f){const te=f.getBoundingClientRect();if(W.clientX>=te.left+10&&W.clientX<=te.right-10&&W.clientY>=te.top+10&&W.clientY<=te.bottom-10)return}B=!1,E=Q(W);const j=Fi(ji(E.x-y.x,E.y-y.y),C);g(j),C=j}function G(W){if(W.preventDefault(),t.enabled!==!1){if(W.touches.length===1){_.current="drag";const j=W.touches[0];m.current={initialTransform:C,initialTouch:{x:j.clientX,y:j.clientY}}}else if(W.touches.length===2){_.current="pinch";const j=W.touches[0],te=W.touches[1];p.current={initialTransform:C,initialTouch1:{x:j.clientX,y:j.clientY},initialTouch2:{x:te.clientX,y:te.clientY},finalTouch1:null,finalTouch2:null}}}}function O(W){if(W.preventDefault(),t.enabled!==!1){if(_.current==="drag"&&W.touches.length===1&&m.current){const j=W.touches[0],te={x:j.clientX,y:j.clientY},ie=te.x-m.current.initialTouch.x,$=te.y-m.current.initialTouch.y,Z=Fi(ji(ie,$),m.current.initialTransform);g(Z)}else if(_.current==="pinch"&&W.touches.length===2&&p.current){const j=W.touches[0],te=W.touches[1];p.current.finalTouch1={x:j.clientX,y:j.clientY},p.current.finalTouch2={x:te.clientX,y:te.clientY};const ie=DHt(p.current);g(ie)}}}function U(W){W.preventDefault();const j=W.changedTouches[0];if(_.current==="drag"&&m.current&&j){const te={x:j.clientX,y:j.clientY},ie=te.x-m.current.initialTouch.x,$=te.y-m.current.initialTouch.y,Z=Fi(ji(ie,$),m.current.initialTransform);g(Z),C=Z}else if(_.current==="pinch"&&p.current){const te=DHt(p.current);g(te),C=te}_.current="none",m.current=null,p.current=null}return f.addEventListener("mousedown",b),f.addEventListener("mouseup",D),window.addEventListener("mousemove",R),f.addEventListener("mouseout",L),f.addEventListener("wheel",M),f.addEventListener("touchstart",G,{passive:!1}),f.addEventListener("touchmove",O,{passive:!1}),f.addEventListener("touchend",U,{passive:!1}),f.addEventListener("touchcancel",U,{passive:!1}),()=>{f.removeEventListener("mousedown",b),f.removeEventListener("mouseup",D),window.removeEventListener("mousemove",R),f.removeEventListener("mouseout",L),f.removeEventListener("wheel",M),f.removeEventListener("touchstart",G),f.removeEventListener("touchmove",O),f.removeEventListener("touchend",U),f.removeEventListener("touchcancel",U)}},[i,a,c,n,t.enabled,t.shouldDrag]);const I=X.useCallback(f=>mt(h,f),[h]);return{ref:e,transform:h,applyTransformToPoint:I,setTransform:u,cancelDrag:d}},Kzo=Ozo;function Uzo(t){const e=new Map;let n=0;function o(i){for(const[,s]of e)if(s.has(i))return s;const r=new Set;return e.set(`connectivity_net${n++}`,r),r}for(const i of t){let r=null;for(const s of i){if(!r)r=o(s);else if(!r.has(s)){const a=o(s);if(a!==r){for(const A of a)r.add(A);e.delete(Array.from(e.entries()).find(([,A])=>A===a)[0])}}r.add(s)}}return Object.fromEntries(Array.from(e.entries()).map(([i,r])=>[i,Array.from(r)]))}var Yzo=class{netMap;idToNetMap;constructor(t){this.netMap=t,this.idToNetMap={};for(const[e,n]of Object.entries(t))for(const o of n)this.idToNetMap[o]=e}addConnections(t){for(const e of t){const n=new Set;for(const i of e){const r=this.idToNetMap[i];r&&n.add(r)}let o;if(n.size===0)o=`connectivity_net${Object.keys(this.netMap).length}`,this.netMap[o]=[];else if(n.size===1)o=n.values().next().value??`connectivity_net${Object.keys(this.netMap).length}`;else{o=n.values().next().value??`connectivity_net${Object.keys(this.netMap).length}`;for(const i of n)if(i!==o){this.netMap[o].push(...this.netMap[i]),this.netMap[i]=this.netMap[o];for(const r of this.netMap[o])this.idToNetMap[r]=o}}for(const i of e)this.netMap[o].includes(i)||this.netMap[o].push(i),this.idToNetMap[i]=o}}getIdsConnectedToNet(t){return this.netMap[t]||[]}getNetConnectedToId(t){return this.idToNetMap[t]}areIdsConnected(t,e){if(t===e)return!0;const n=this.getNetConnectedToId(t);if(!n)return!1;const o=this.getNetConnectedToId(e);return o?n===o||o===t||o===t:!1}areAllIdsConnected(t){const e=this.getNetConnectedToId(t[0]);for(const n of t){const o=this.getNetConnectedToId(n);if(o===void 0||o!==e)return!1}return!0}},vHt=t=>{const e=[];for(const o of t)if(o.type==="source_trace")e.push([o.source_trace_id,...o.connected_source_port_ids??[],...o.connected_source_net_ids??[]].filter(Boolean));else if(o.type==="pcb_port"){const{pcb_port_id:i,source_port_id:r}=o;r&&i&&e.push([r,i])}else if(o.type==="pcb_smtpad"){const{pcb_smtpad_id:i,pcb_port_id:r}=o;r&&i&&e.push([i,r])}else if(o.type==="pcb_plated_hole"){const{pcb_plated_hole_id:i,pcb_port_id:r}=o;r&&i&&e.push([i,r])}else if(o.type==="pcb_trace"){const{pcb_trace_id:i,source_trace_id:r}=o,s=Array.isArray(o.route)?o.route.filter(a=>a&&a.route_type==="wire"):[];if(r&&i&&e.push([i,r]),Array.isArray(s)){const a=s.find(c=>c?.start_pcb_port_id)?.start_pcb_port_id,A=s.find(c=>c?.end_pcb_port_id)?.end_pcb_port_id;a&&i&&A&&e.push([a,i,A])}}else if(o.type==="pcb_via"){const{pcb_via_id:i,pcb_trace_id:r}=o;r&&i&&e.push([i,r])}else if(o.type==="source_component"&&o.internally_connected_source_port_ids)for(const i of o.internally_connected_source_port_ids)e.push(i);const n=Uzo(e);return new Yzo(n)};function zzo(t,e){if(t.length<2)throw new Error("Stroke must have at least two points");const n=t.map(g=>Array.isArray(g)?{x:g[0],y:g[1]}:g),o=[],i=[];function r(g,u){const h=u.x-g.x,d=u.y-g.y,_=Math.sqrt(h*h+d*d);return{x:-d/_,y:h/_}}function s(g,u,h,d){const _=d/2,m={x:g.x+u.x*_*h,y:g.y+u.y*_*h};h>0?o.push(m):i.unshift(m)}const a=r(n[0],n[1]),A=n[0].trace_width??e;s(n[0],a,1,A),s(n[0],a,-1,A);for(let g=1;g<n.length-1;g++){const u=n[g-1],h=n[g],d=n[g+1],_=r(u,h),m=r(h,d),p=_.x+m.x,I=_.y+m.y,f=Math.sqrt(p*p+I*I),C=h.trace_width??e;if(f/2>2*(C/2))s(h,_,1,C),s(h,m,1,C),s(h,_,-1,C),s(h,m,-1,C);else{const E=1/f;s(h,{x:p*E,y:I*E},1,C),s(h,{x:p*E,y:I*E},-1,C)}}const c=r(n[n.length-2],n[n.length-1]),l=n[n.length-1].trace_width??e;return s(n[n.length-1],c,1,l),s(n[n.length-1],c,-1,l),[...o,...i]}var Vzo=(t,e)=>{const{x:n,y:o,width:i,height:r,layer:s,rect_border_radius:a}=t,A=t.corner_radius??a??0,c=[{_pcb_drawing_object_id:tQ("rect"),pcb_drawing_type:"rect",x:n,y:o,w:i,h:r,layer:s||"top",_element:t,_parent_pcb_component:e._parent_pcb_component,_parent_source_component:e._parent_source_component,_source_port:e._source_port,roundness:A,...t.shape==="rotated_rect"&&t.ccw_rotation!==void 0?{ccw_rotation:t.ccw_rotation}:{}}];if(t.is_covered_with_solder_mask){const l=s==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",u={...{_pcb_drawing_object_id:tQ("rect"),pcb_drawing_type:"rect",x:n,y:o,w:i,h:r,layer:l,_element:t,_parent_pcb_component:e._parent_pcb_component,_parent_source_component:e._parent_source_component,_source_port:e._source_port,roundness:A,...t.shape==="rotated_rect"&&t.ccw_rotation!==void 0?{ccw_rotation:t.ccw_rotation}:{}},..."solder_mask_color"in t&&t.solder_mask_color?{color:t.solder_mask_color}:{}};c.push(u)}return c},Jzo=(t,e)=>{const{x:n,y:o,radius:i,layer:r}=t,s=[{_pcb_drawing_object_id:tQ("circle"),pcb_drawing_type:"circle",x:n,y:o,r:i,layer:r||"top",_element:t,_parent_pcb_component:e._parent_pcb_component,_parent_source_component:e._parent_source_component,_source_port:e._source_port}];if(t.is_covered_with_solder_mask){const a=r==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",A={_pcb_drawing_object_id:tQ("circle"),pcb_drawing_type:"circle",x:n,y:o,r:i,layer:a,_element:t,_parent_pcb_component:e._parent_pcb_component,_parent_source_component:e._parent_source_component,_source_port:e._source_port,..."solder_mask_color"in t&&t.solder_mask_color?{color:t.solder_mask_color}:{}};s.push(A)}return s},qzo=(t,e)=>{const{layer:n,points:o}=t,i=[{_pcb_drawing_object_id:tQ("polygon"),pcb_drawing_type:"polygon",points:Z9e(o),layer:n||"top",_element:t,_parent_pcb_component:e._parent_pcb_component,_parent_source_component:e._parent_source_component,_source_port:e._source_port}];if(t.is_covered_with_solder_mask){const r=n==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",s={_pcb_drawing_object_id:tQ("polygon"),pcb_drawing_type:"polygon",points:Z9e(o),layer:r,_element:t,_parent_pcb_component:e._parent_pcb_component,_parent_source_component:e._parent_source_component,_source_port:e._source_port,..."solder_mask_color"in t&&t.solder_mask_color?{color:t.solder_mask_color}:{}};i.push(s)}return i},Wzo=(t,e)=>{const{x:n,y:o,width:i,height:r,layer:s}=t,a=[{_pcb_drawing_object_id:tQ("pill"),pcb_drawing_type:"pill",x:n,y:o,w:i,h:r,layer:s||"top",_element:t,_parent_pcb_component:e._parent_pcb_component,_parent_source_component:e._parent_source_component,_source_port:e._source_port}];if(t.is_covered_with_solder_mask){const A=s==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",c={_pcb_drawing_object_id:tQ("pill"),pcb_drawing_type:"pill",x:n,y:o,w:i,h:r,layer:A,_element:t,_parent_pcb_component:e._parent_pcb_component,_parent_source_component:e._parent_source_component,_source_port:e._source_port,..."solder_mask_color"in t&&t.solder_mask_color?{color:t.solder_mask_color}:{}};a.push(c)}return a},jzo=(t,e)=>{const{x:n,y:o,width:i,height:r,layer:s,ccw_rotation:a}=t,A=[{_pcb_drawing_object_id:tQ("pill"),pcb_drawing_type:"pill",x:n,y:o,w:i,h:r,layer:s||"top",_element:t,_parent_pcb_component:e._parent_pcb_component,_parent_source_component:e._parent_source_component,_source_port:e._source_port,ccw_rotation:a}];if(t.is_covered_with_solder_mask){const c=s==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",l={_pcb_drawing_object_id:tQ("pill"),pcb_drawing_type:"pill",x:n,y:o,w:i,h:r,layer:c,_element:t,_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 t&&t.solder_mask_color?{color:t.solder_mask_color}:{}};A.push(l)}return A},s0=0,tQ=t=>`${t}_${s0++}`,Z9e=t=>(t??[]).map(e=>({x:En.parse(e.x),y:En.parse(e.y)})),Xzo=(t,e)=>{const n="pcb_component_id"in t?e.find(s=>s.type==="pcb_component"&&s.pcb_component_id===t.pcb_component_id):void 0,o=n&&"source_component_id"in n?e.find(s=>s.type==="source_component"&&s.source_component_id===n.source_component_id):void 0,i="source_port_id"in t?t.source_port_id:"pcb_port_id"in t?q6(e).pcb_port.get(t.pcb_port_id)?.source_port_id:void 0,r=i?e.find(s=>s.type==="source_port"&&s.source_port_id===i):void 0;switch(t.type){case"pcb_smtpad":{const s={_parent_pcb_component:n,_parent_source_component:o,_source_port:r};return t.shape==="rect"||t.shape==="rotated_rect"?Vzo(t,s):t.shape==="circle"?Jzo(t,s):t.shape==="polygon"?qzo(t,s):t.shape==="pill"?Wzo(t,s):t.shape==="rotated_pill"?jzo(t,s):[]}case"pcb_trace":{const s=[];if(t.route_thickness_mode==="interpolated"){const c=t.route.flatMap(u=>u.route_type==="through_pad"?[{...u.start,trace_width:u.width},{...u.end,trace_width:u.width}]:[{x:u.x,y:u.y,trace_width:u.route_type==="wire"?u.width:.5}]),l=zzo(c,.5),g=t.route[0].layer;return s.push({_pcb_drawing_object_id:`polygon_${s0++}`,_element:t,pcb_drawing_type:"polygon",points:l,layer:g}),t.route.forEach(u=>{u.route_type==="via"&&s.push({_pcb_drawing_object_id:`circle_${s0++}`,_element:t,pcb_drawing_type:"circle",x:u.x,y:u.y,r:u.outer_diameter/2,layer:u.from_layer})}),s}let a=null,A=null;for(const c of t.route)c.route_type==="wire"&&(a!==null&&A!==null&&s.push({_pcb_drawing_object_id:`line_${s0++}`,_element:t,pcb_drawing_type:"line",x1:a,y1:A,x2:c.x,y2:c.y,width:c.width,squareCap:!1,layer:c.layer}),a=c.x,A=c.y);return s}case"pcb_via":{const{x:s,y:a,outer_diameter:A,hole_diameter:c}=t,l=t.from_layer,g=t.to_layer,u=t.layers,h=[];l&&g?h.push(l,g):u&&Array.isArray(u)?h.push(...u):h.push("top","bottom");const d=[];for(const _ of h)d.push({_pcb_drawing_object_id:`circle_${s0++}`,pcb_drawing_type:"circle",x:s,y:a,r:A/2,layer:_,_element:t,_parent_pcb_component:n,_parent_source_component:o});return d.push({_pcb_drawing_object_id:`circle_${s0++}`,pcb_drawing_type:"circle",x:s,y:a,r:c/2,layer:"drill",_element:t}),d}case"pcb_plated_hole":if(t.shape==="circle"){const{x:s,y:a,hole_diameter:A,outer_diameter:c}=t;return[{_pcb_drawing_object_id:`circle_${s0++}`,pcb_drawing_type:"circle",x:s,y:a,r:c/2,layer:"top",_element:t,_parent_pcb_component:n,_parent_source_component:o,_source_port:r},{_pcb_drawing_object_id:`circle_${s0++}`,pcb_drawing_type:"circle",x:s,y:a,r:A/2,layer:"drill",_element:t}]}else if(t.shape==="oval"){const{x:s,y:a,outer_height:A,outer_width:c,hole_height:l,hole_width:g}=t;return[{_pcb_drawing_object_id:`oval_${s0++}`,pcb_drawing_type:"oval",x:s,y:a,rX:c/2,rY:A/2,layer:"top",_element:t,_parent_pcb_component:n,_parent_source_component:o,_source_port:r},{_pcb_drawing_object_id:`oval_${s0++}`,_element:t,pcb_drawing_type:"oval",x:s,y:a,rX:g/2,rY:l/2,layer:"drill"}]}else if(t.shape==="pill"){const{x:s,y:a,outer_height:A,outer_width:c,hole_height:l,hole_width:g}=t;return[{_pcb_drawing_object_id:`pill_${s0++}`,pcb_drawing_type:"pill",x:s,y:a,w:c,h:A,layer:"top",_element:t,_parent_pcb_component:n,_parent_source_component:o,_source_port:r,ccw_rotation:t.ccw_rotation},{_pcb_drawing_object_id:`pill_${s0++}`,_element:t,pcb_drawing_type:"pill",x:s,y:a,w:g,h:l,layer:"drill",ccw_rotation:t.ccw_rotation}]}else if(t.shape==="circular_hole_with_rect_pad"){const{x:s,y:a,hole_diameter:A,rect_pad_width:c,rect_pad_height:l,rect_border_radius:g,hole_offset_x:u,hole_offset_y:h}=t,d=En.parse(u??0),_=En.parse(h??0);return[{_pcb_drawing_object_id:`rect_${s0++}`,pcb_drawing_type:"rect",x:s,y:a,w:c,h:l,layer:"top",_element:t,_parent_pcb_component:n,_parent_source_component:o,_source_port:r,roundness:g},{_pcb_drawing_object_id:`rect_${s0++}`,pcb_drawing_type:"rect",x:s,y:a,w:c,h:l,layer:"bottom",_element:t,_parent_pcb_component:n,_parent_source_component:o,_source_port:r,roundness:g,is_hoverable:!1},{_pcb_drawing_object_id:`circle_${s0++}`,_element:t,pcb_drawing_type:"circle",x:s+d,y:a+_,r:A/2,layer:"drill",is_hoverable:!1}]}else if(t.shape==="pill_hole_with_rect_pad"){const{x:s,y:a,hole_width:A,hole_height:c,rect_pad_width:l,rect_pad_height:g,rect_border_radius:u}=t;return[{_pcb_drawing_object_id:`rect_${s0++}`,pcb_drawing_type:"rect",x:s,y:a,w:l,h:g,layer:"top",_element:t,_parent_pcb_component:n,_parent_source_component:o,_source_port:r,roundness:u},{_pcb_drawing_object_id:`rect_${s0++}`,pcb_drawing_type:"rect",x:s,y:a,w:l,h:g,layer:"bottom",_element:t,_parent_pcb_component:n,_parent_source_component:o,_source_port:r,roundness:u,is_hoverable:!1},{_pcb_drawing_object_id:`pill_${s0++}`,_element:t,pcb_drawing_type:"pill",x:s,y:a,w:A,h:c,layer:"drill",is_hoverable:!1}]}else if(t.shape==="rotated_pill_hole_with_rect_pad"){const{x:s,y:a,hole_width:A,hole_height:c,hole_ccw_rotation:l,rect_pad_width:g,rect_pad_height:u,rect_ccw_rotation:h,rect_border_radius:d}=t;return[{_pcb_drawing_object_id:`rect_${s0++}`,pcb_drawing_type:"rect",x:s,y:a,w:g,h:u,layer:"top",_element:t,_parent_pcb_component:n,_parent_source_component:o,_source_port:r,ccw_rotation:h,roundness:d},{_pcb_drawing_object_id:`rect_${s0++}`,pcb_drawing_type:"rect",x:s,y:a,w:g,h:u,layer:"bottom",_element:t,_parent_pcb_component:n,_parent_source_component:o,_source_port:r,ccw_rotation:h,roundness:d,is_hoverable:!1},{_pcb_drawing_object_id:`pill_${s0++}`,_element:t,pcb_drawing_type:"pill",x:s,y:a,w:A,h:c,layer:"drill",ccw_rotation:l,is_hoverable:!1}]}else if(t.shape==="hole_with_polygon_pad"){const{x:s,y:a,pad_outline:A,hole_shape:c,hole_diameter:l,hole_width:g,hole_height:u,layers:h,hole_offset_x:d,hole_offset_y:_}=t,m=En.parse(d??0),p=En.parse(_??0),I=A,f=[];if(I&&Array.isArray(I)){const E=Z9e(I).map(B=>({x:B.x+s,y:B.y+a}));for(const B of h||["top","bottom"])f.push({_pcb_drawing_object_id:`polygon_${s0++}`,pcb_drawing_type:"polygon",points:E,layer:B,_element:t,_parent_pcb_component:n,_parent_source_component:o,_source_port:r})}const C={x:s+m,y:a+p},y=[];return c==="circle"?y.push({_pcb_drawing_object_id:`circle_${s0++}`,pcb_drawing_type:"circle",x:C.x,y:C.y,r:(l??0)/2,layer:"drill",_element:t,_parent_pcb_component:n,_parent_source_component:o}):c==="oval"?y.push({_pcb_drawing_object_id:`oval_${s0++}`,pcb_drawing_type:"oval",x:C.x,y:C.y,rX:(g??0)/2,rY:(u??0)/2,layer:"drill",_element:t,_parent_pcb_component:n,_parent_source_component:o}):(c==="pill"||c==="rotated_pill")&&y.push({_pcb_drawing_object_id:`pill_${s0++}`,pcb_drawing_type:"pill",x:C.x,y:C.y,w:g??0,h:u??0,layer:"drill",_element:t,_parent_pcb_component:n,_parent_source_component:o,ccw_rotation:t.ccw_rotation}),[...f,...y]}else return[]}return[]};function $zo({primitivesWithoutInteractionMetadata:t,drawingObjectIdsWithMouseOver:e,primitiveIdsInMousedOverNet:n}){const o=[];for(const i of t){const r={...i},s=i._element,a=i._parent_pcb_component;i?.layer==="drill"?(r.is_in_highlighted_net=!1,r.is_mouse_over=!1):e.has(i._pcb_drawing_object_id)?r.is_mouse_over=!0:s&&("pcb_trace_id"in s&&n.includes(s.pcb_trace_id)||"pcb_port_id"in s&&n.includes(s.pcb_port_id)||"pcb_via_id"in s&&n.includes(s.pcb_via_id)||"pcb_component_id"in s&&n.includes(s.pcb_component_id)||a&&"pcb_component_id"in a&&n.includes(a.pcb_component_id))?r.is_in_highlighted_net=!0:(r.is_in_highlighted_net=!1,r.is_mouse_over=!1),o.push(r)}return o}var PHt=t=>{const e=new Map,n=new Map,o=new Map,i=new Map,r=new Map;for(const s of t)s.type==="pcb_trace"&&s.pcb_trace_id?e.set(s.pcb_trace_id,s):s.type==="pcb_port"&&s.pcb_port_id?n.set(s.pcb_port_id,s):s.type==="pcb_via"&&s.pcb_via_id?o.set(s.pcb_via_id,s):s.type==="pcb_component"&&s.pcb_component_id?i.set(s.pcb_component_id,s):s.type==="pcb_board"&&s.pcb_board_id&&r.set(s.pcb_board_id,s);return{tracesById:e,portsById:n,viasById:o,componentsById:i,boardsById:r}},Fx=(t,e)=>e?t?{minX:Math.min(t.minX,e.minX),maxX:Math.max(t.maxX,e.maxX),minY:Math.min(t.minY,e.minY),maxY:Math.max(t.maxY,e.maxY)}:e:t,W6=(t,e=.45)=>({minX:t.x-e,maxX:t.x+e,minY:t.y-e,maxY:t.y+e}),Zzo=t=>{if(t.length===0)return null;let e=null;for(const n of t){const o=Math.max((n.width??.2)/2,.3);e=Fx(e,W6(n,o))}return e},wHt=t=>{if(!t?.center)return null;const e=Math.max(t.width??0,1.2),n=Math.max(t.height??0,1.2);return{minX:t.center.x-e/2,maxX:t.center.x+e/2,minY:t.center.y-n/2,maxY:t.center.y+n/2}},eVo=t=>!t?.center||typeof t.width!="number"||typeof t.height!="number"?null:{minX:t.center.x-t.width/2,maxX:t.center.x+t.width/2,minY:t.center.y-t.height/2,maxY:t.center.y+t.height/2},tVo=(t,e)=>({minX:t.minX-e,maxX:t.maxX+e,minY:t.minY-e,maxY:t.maxY+e}),nVo=(t,e=.35)=>{const n=mp(t);return n?tVo(n,e):null},MHt=({error:t,tracesById:e,portsById:n,viasById:o,componentsById:i})=>{if(t.center)return t.center;if(t.pcb_center)return t.pcb_center;if(t.component_center)return t.component_center;if(t.pcb_via_ids?.length){const r=t.pcb_via_ids.map(s=>o.get(s)).filter(Boolean);if(r.length>0)return{x:r.reduce((s,a)=>s+a.x,0)/r.length,y:r.reduce((s,a)=>s+a.y,0)/r.length}}if(t.pcb_port_ids?.length){const r=t.pcb_port_ids.map(s=>n.get(s)).filter(Boolean);if(r.length>0)return{x:r.reduce((s,a)=>s+a.x,0)/r.length,y:r.reduce((s,a)=>s+a.y,0)/r.length}}if(t.pcb_trace_id){const r=e.get(t.pcb_trace_id);if(r?.route?.length){const s=Math.floor(r.route.length/2);return{x:r.route[s].x,y:r.route[s].y}}}return t.pcb_component_id?i.get(t.pcb_component_id)?.center??null:null},oVo=({error:t,indexes:e})=>MHt({error:t,...e}),iVo=({error:t,boardsById:e})=>{if(!t.component_bounds||!t.pcb_board_id)return null;const n=eVo(e.get(t.pcb_board_id));if(!n)return null;const o=t.component_bounds,i=[];return o.min_x<n.minX&&(i.push({x:n.minX,y:Math.max(o.min_y,n.minY)}),i.push({x:n.minX,y:Math.min(o.max_y,n.maxY)})),o.max_x>n.maxX&&(i.push({x:n.maxX,y:Math.max(o.min_y,n.minY)}),i.push({x:n.maxX,y:Math.min(o.max_y,n.maxY)})),o.min_y<n.minY&&(i.push({x:Math.max(o.min_x,n.minX),y:n.minY}),i.push({x:Math.min(o.max_x,n.maxX),y:n.minY})),o.max_y>n.maxY&&(i.push({x:Math.max(o.min_x,n.minX),y:n.maxY}),i.push({x:Math.min(o.max_x,n.maxX),y:n.maxY})),nVo(i,.3)},NHt=new Set(["source_failed_to_create_component_error"]),rVo=({error:t,indexes:e})=>{if(NHt.has(t.error_type)||NHt.has(t.type))return null;let n=null;const o=MHt({error:t,...e});if(o&&(n=Fx(n,W6(o,.35))),t.error_type==="pcb_component_outside_board_error"?n=Fx(n,iVo({error:t,boardsById:e.boardsById})):t.component_bounds&&!o&&(n=Fx(n,{minX:t.component_bounds.min_x,maxX:t.component_bounds.max_x,minY:t.component_bounds.min_y,maxY:t.component_bounds.max_y})),t.center&&!o&&(n=Fx(n,W6(t.center))),t.pcb_center&&!o&&(n=Fx(n,W6(t.pcb_center))),t.component_center&&!o&&(n=Fx(n,W6(t.component_center))),t.pcb_port_ids&&!o)for(const i of t.pcb_port_ids){const r=e.portsById.get(i);r&&(n=Fx(n,W6({x:r.x,y:r.y},.4)))}if(t.pcb_trace_id&&!o){const i=e.tracesById.get(t.pcb_trace_id);i?.route&&(n=Fx(n,Zzo(i.route)))}if(t.pcb_via_ids)for(const i of t.pcb_via_ids){const r=e.viasById.get(i);r&&(n=Fx(n,W6({x:r.x,y:r.y},Math.max((r.outer_diameter??.5)/2,.28))))}if(t.pcb_component_id&&!o&&(n=Fx(n,wHt(e.componentsById.get(t.pcb_component_id)))),t.pcb_component_ids&&!o)for(const i of t.pcb_component_ids)n=Fx(n,wHt(e.componentsById.get(i)));return n},sVo=({bounds:t,width:e,height:n})=>{const o={x:(t.minX+t.maxX)/2,y:(t.minY+t.maxY)/2},i=Math.max(t.maxX-t.minX,.8)+1.4,r=Math.max(t.maxY-t.minY,.8)+1.4,s=Math.min(e/i,n/r,240)*.92;return Fi(ji(e/2,n/2),gg(s,-s,0,0),ji(-o.x,-o.y))},aVo=t=>{const e=new Set;t.pcb_trace_id&&e.add(t.pcb_trace_id);for(const n of t.pcb_port_ids??[])e.add(n);for(const n of t.pcb_via_ids??[])e.add(n);t.pcb_component_id&&e.add(t.pcb_component_id);for(const n of t.pcb_component_ids??[])e.add(n);return[...e]},Gk=(t,e)=>{const n=["pcb_trace_error_id","pcb_via_clearance_error_id","pcb_component_outside_board_error_id","source_failed_to_create_component_error_id","pcb_error_id"];for(const o of n)if(typeof t?.[o]=="string"&&t[o].length>0)return t[o];for(const[o,i]of Object.entries(t??{}))if(o.endsWith("_error_id")&&typeof i=="string"&&i.length>0)return i;return`error_${e}_${t?.error_type}_${t?.message?.slice(0,20)}`},RHt=(t,e)=>e?t.find((n,o)=>n.type?.includes("error")?Gk(n,o)===e:!1)??null:null,AVo=t=>1-(1-t)**3,cVo=(t,e,n)=>({a:t.a+(e.a-t.a)*n,b:t.b+(e.b-t.b)*n,c:t.c+(e.c-t.c)*n,d:t.d+(e.d-t.d)*n,e:t.e+(e.e-t.e)*n,f:t.f+(e.f-t.f)*n}),THt=t=>{t!==null&&window.cancelAnimationFrame(t)},lVo=({startTransform:t,endTransform:e,durationMs:n,onUpdate:o,setAnimationFrameId:i,onComplete:r})=>{const s=performance.now(),a=c=>{const l=c-s,g=Math.min(1,l/n),u=AVo(g);if(o(cVo(t,e,u)),g<1){i(window.requestAnimationFrame(a));return}i(null),r?.()},A=window.requestAnimationFrame(a);return i(A),A},Fo={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)"}},Fy=(t,e=1)=>{if(Math.abs(t.a)!==Math.abs(t.d))throw new Error("Cannot scale non-uniformly");return e*Math.abs(t.a)},Yg={elementOverlay:40,dimensionOverlay:40,errorOverlay:40,pcbGroupOverlay:35,ratsNestOverlay:30,toolbarOverlay:70,warnings:30,topLayer:30,clickToInteractOverlay:100},lae={red:"red",black:"black",green:"green",board:"rgb(255, 255, 255)",other:"#eee",top:Fo.board.copper.f,inner1:Fo.board.copper.in1,inner2:Fo.board.copper.in2,inner3:Fo.board.copper.in3,inner4:Fo.board.copper.in4,inner5:Fo.board.copper.in5,inner6:Fo.board.copper.in6,inner7:Fo.board.copper.in7,inner8:Fo.board.copper.in8,bottom:Fo.board.copper.b,drill:Fo.board.anchor,keepout:Fo.board.background,tkeepout:Fo.board.b_crtyd,tplace:Fo.board.b_silks,top_courtyard:Fo.board.f_crtyd,bottom_courtyard:Fo.board.b_crtyd,top_silkscreen:Fo.board.f_silks,bottom_silkscreen:Fo.board.b_silks,top_fabrication:Fo.board.f_fab,bottom_fabrication:Fo.board.b_fab,soldermask_top:Fo.board.soldermask.top,soldermask_bottom:Fo.board.soldermask.bottom,soldermask_with_copper_top:Fo.board.soldermaskWithCopper.top,soldermask_with_copper_bottom:Fo.board.soldermaskWithCopper.bottom,bottom_notes:Fo.board.user_2,top_notes:Fo.board.user_2,...Fo.board},gVo=["board","bottom","soldermask_bottom","bottom_silkscreen","top","soldermask_top","bottom_courtyard","bottom_fabrication","top_courtyard","top_fabrication","edge_cuts","top_silkscreen"],uVo=class{canvasLayerMap;ctxLayerMap;aperture;transform;foregroundLayer="top";lastPoint;constructor(t){this.canvasLayerMap=t,this.ctxLayerMap=Object.fromEntries(Object.entries(t).map(([e,n])=>[e,n.getContext("2d")])),this.transform=Hl(),this.transform.d*=-1,this.transform=Fi(this.transform,ji(0,-500)),this.lastPoint={x:0,y:0},this.equip({})}clear(){for(const t of Object.values(this.ctxLayerMap))t.clearRect(0,0,t.canvas.width,t.canvas.height)}equip(t){this.aperture={fontSize:0,shape:"circle",mode:"add",size:0,color:"red",layer:"top",opacity:this.foregroundLayer===t.color?1:.5,...t}}drawMeshPattern(t,e,n,o,i,r=45){const s=this.getLayerCtx(),[a,A]=mt(this.transform,[t,e]),[c,l]=mt(this.transform,[t+n,e+o]),g=Fy(this.transform,i);s.lineWidth=1,s.strokeStyle=this.aperture.color;const u=h=>{const d=Math.sin(h),_=Math.cos(h),m=Math.sqrt((c-a)**2+(l-A)**2);for(let p=-m;p<=m;p+=g)s.beginPath(),s.moveTo(a+p*_-m*d,A+p*d+m*_),s.lineTo(a+p*_+m*d,A+p*d-m*_),s.stroke()};u(r*Math.PI/180),u((r+90)*Math.PI/180)}rect({x:t,y:e,w:n,h:o,mesh_fill:i,is_filled:r=!0,has_stroke:s,is_stroke_dashed:a,stroke_width:A,roundness:c}){const[l,g]=mt(this.transform,[t-n/2,e-o/2]),[u,h]=mt(this.transform,[t+n/2,e+o/2]);this.applyAperture();const d=this.getLayerCtx(),_=c?Fy(this.transform,c):0,m=s===void 0?r===!1:s;if(i)d.save(),d.beginPath(),_>0&&d.roundRect?d.roundRect(l,g,u-l,h-g,_):d.rect(l,g,u-l,h-g),d.clip(),this.drawMeshPattern(t-n/2,e-o/2,n,o,.15),d.restore(),_>0&&d.roundRect?(d.beginPath(),d.roundRect(l,g,u-l,h-g,_),d.stroke()):d.strokeRect(l,g,u-l,h-g);else if(r!==!1&&(_>0&&d.roundRect?(d.beginPath(),d.roundRect(l,g,u-l,h-g,_),d.fill()):d.fillRect(l,g,u-l,h-g)),m){const p=d.lineWidth;if(A!==void 0&&(d.lineWidth=Fy(this.transform,A)),a){let I=[];const f=Math.abs(this.transform.a);if(f>0){const y=.1*f,E=y*1.3;y>.5&&(I=[y,E])}d.setLineDash(I)}_>0&&d.roundRect?(d.beginPath(),d.roundRect(l,g,u-l,h-g,_),d.stroke()):d.strokeRect(l,g,u-l,h-g),a&&d.setLineDash([]),A!==void 0&&(d.lineWidth=p)}}rotatedRect(t,e,n,o,i,r,s){const a=this.getLayerCtx();this.applyAperture();const[A,c]=mt(this.transform,[t-n/2,e-o/2]),[l,g]=mt(this.transform,[t+n/2,e+o/2]),u=r?Fy(this.transform,r):0;a.save();const[h,d]=mt(this.transform,[t,e]);a.translate(h,d);const _=360-i;i&&a.rotate(_*Math.PI/180),a.translate(-h,-d),s?(a.beginPath(),u>0&&a.roundRect?a.roundRect(A,c,l-A,g-c,u):a.rect(A,c,l-A,g-c),a.clip(),this.drawMeshPattern(t-n/2,e-o/2,n,o,.15),u>0&&a.roundRect?(a.beginPath(),a.roundRect(A,c,l-A,g-c,u),a.stroke()):a.strokeRect(A,c,l-A,g-c)):u>0&&a.roundRect?(a.beginPath(),a.roundRect(A,c,l-A,g-c,u),a.fill()):a.fillRect(A,c,l-A,g-c),a.restore()}rotatedPill(t,e,n,o,i){const r=this.getLayerCtx();this.applyAperture(),r.save();const[s,a]=mt(this.transform,[t,e]);r.translate(s,a);const A=360-i;i&&r.rotate(A*Math.PI/180),r.translate(-s,-a),this.pill(t,e,n,o),r.restore()}circle(t,e,n,o,i=!0){const r=Fy(this.transform,n),[s,a]=mt(this.transform,[t,e]);this.applyAperture();const A=this.getLayerCtx();o?(A.save(),A.beginPath(),A.arc(s,a,r,0,2*Math.PI),A.clip(),this.drawMeshPattern(t-n,e-n,n*2,n*2,.15),A.restore(),A.beginPath(),A.arc(s,a,r,0,2*Math.PI),A.stroke()):(A.beginPath(),A.arc(s,a,r,0,2*Math.PI),A.fill())}oval(t,e,n,o){const i=Fy(this.transform,n),r=Fy(this.transform,o),[s,a]=mt(this.transform,[t,e]);this.applyAperture();const A=this.getLayerCtx();A.beginPath(),A.ellipse(s,a,i,r,0,0,2*Math.PI),A.fill(),A.closePath()}pill(t,e,n,o){const[i,r]=mt(this.transform,[t-n/2,e+o/2]),s=Fy(this.transform,n),a=Fy(this.transform,o),A=Math.min(s,a)/2;this.applyAperture();const c=this.getLayerCtx();c.beginPath(),c.arc(i+A,r+A,A,Math.PI,Math.PI*1.5),c.arc(i+s-A,r+A,A,Math.PI*1.5,0),c.arc(i+s-A,r+a-A,A,0,Math.PI*.5),c.arc(i+A,r+a-A,A,Math.PI*.5,Math.PI),c.fill(),c.closePath()}polygon(t){if(t.length<3)return;this.applyAperture();const e=this.getLayerCtx(),n=t.map(i=>mt(this.transform,[i.x,i.y]));e.beginPath(),e.moveTo(n[0][0],n[0][1]);for(let i=1;i<n.length;i++)e.lineTo(n[i][0],n[i][1]);e.closePath(),e.fill("evenodd");const o=Fy(this.transform,this.aperture.size);o>0&&(e.lineWidth=o,e.stroke())}debugText(t,e,n){const[o,i]=mt(this.transform,[e,n]);this.applyAperture();const r=this.getLayerCtx();r.font="10px sans-serif",r.fillText(t,o,i)}getLayerCtx(){const t=this.ctxLayerMap[this.aperture.layer];if(!t)throw new Error(`No context for layer "${this.aperture.layer}"`);return t}orderAndFadeLayers(){const{canvasLayerMap:t,foregroundLayer:e}=this,o=["board",...Object.keys(t).filter(u=>/^inner\d+$/.test(u)).sort((u,h)=>Number(h.slice(5))-Number(u.slice(5))),...gVo.filter(u=>u!=="board")],i=e==="top"?"soldermask_top":e==="bottom"?"soldermask_bottom":void 0,r=e==="top"?"top_silkscreen":e==="bottom"?"bottom_silkscreen":void 0,s=e==="top"?"top_notes":e==="bottom"?"bottom_notes":void 0,a=e==="top"?"top_fabrication":e==="bottom"?"bottom_fabrication":void 0,A=e==="top"?"top_courtyard":e==="bottom"?"bottom_courtyard":void 0,c=new Set([e,"drill","edge_cuts","other","board",...i?[i]:[],...r?[r]:[],...s?[s]:[],...a?[a]:[],...A?[A]:[]]),l=[e,"edge_cuts",...i?[i]:[],...r?[r]:[],...s?[s]:[],...a?[a]:[],...A?[A]:[]],g=[...o.filter(u=>!l.includes(u)),...e==="drill"?[]:[e],...i?[i]:[],"edge_cuts",...r?[r]:[],...s?[s]:[],...a?[a]:[],...A?[A]:[],"drill"];g.forEach((u,h)=>{const d=t[u];d&&(d.style.zIndex=`${Yg.topLayer-(g.length-h)}`,d.style.opacity=c.has(u)?"1":"0.5")})}applyAperture(){const{transform:t,aperture:e}=this;let{size:n,mode:o,color:i,fontSize:r,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=Fy(t,n),a.lineCap="round",o==="add"){a.globalCompositeOperation="source-over";let A=lae[i.toLowerCase()];if(!A)try{A=Kr(i).rgb().toString()}catch{console.warn(`Invalid color format: '${i}'`),A="white"}a.fillStyle=A,a.strokeStyle=A}else a.globalCompositeOperation="destination-out",a.fillStyle="rgba(0,0,0,1)",a.strokeStyle="rgba(0,0,0,1)";a.font=`${Fy(MQ(t),r)}px sans-serif`}moveTo(t,e){this.lastPoint={x:t,y:e}}lineTo(t,e){const[n,o]=mt(this.transform,[t,e]),{size:i,shape:r,mode:s}=this.aperture,a=Fy(this.transform,i),{lastPoint:A}=this,c=mt(this.transform,A);this.applyAperture();const l=this.getLayerCtx();r==="square"&&l.fillRect(c.x-a/2,c.y-a/2,a,a),l.beginPath(),l.moveTo(c.x,c.y),l.lineTo(n,o),l.stroke(),l.closePath(),r==="square"&&l.fillRect(n-a/2,o-a/2,a,a),this.lastPoint={x:t,y:e}}polygonWithArcs(t){const e=this.getLayerCtx(),n=o=>{if(o.vertices.length===0)return;const i=o.vertices[0],r=mt(this.transform,[i.x,i.y]);e.moveTo(r[0],r[1]);for(let s=0;s<o.vertices.length;s++){const a=o.vertices[s],A=o.vertices[(s+1)%o.vertices.length];if(a.bulge&&a.bulge!==0){const c=a.bulge,l=A.x-a.x,g=A.y-a.y,u=Math.sqrt(l*l+g*g);if(u<1e-9){const M=mt(this.transform,[A.x,A.y]);e.lineTo(M[0],M[1]);continue}const h=4*Math.atan(c),d=Math.abs(u/(2*Math.sin(h/2))),_=(a.x+A.x)/2,m=(a.y+A.y)/2,p=l/u,f=-(g/u),C=p,y=Math.sqrt(Math.max(0,d*d-(u/2)**2)),E=_+y*f*Math.sign(c),B=m+y*C*Math.sign(c),Q=Math.atan2(a.y-B,a.x-E);let b=Math.atan2(A.y-B,A.x-E);c>0&&b<Q?b+=2*Math.PI:c<0&&b>Q&&(b-=2*Math.PI);const D=mt(this.transform,[E,B]),R=Fy(this.transform,d);e.arc(D[0],D[1],R,-Q,-b,c>0)}else{const c=mt(this.transform,[A.x,A.y]);e.lineTo(c[0],c[1])}}e.closePath()};if(e.beginPath(),n(t.outer_ring),t.inner_rings)for(const o of t.inner_rings)n(o);e.fill("evenodd")}},dVo=(t=2)=>{const e=Math.max(2,Math.min(10,Math.floor(t)));return["top",...Array.from({length:e-2},(n,o)=>`inner${o+1}`),"bottom"]},e7e=t=>{const e=t.find(n=>n.type==="pcb_board");return dVo(e?.num_layers??2)},hVo=t=>`${t}_copper`,kHt=t=>t.map(e=>e.endsWith("_copper")?e.slice(0,-7):e),_Vo=t=>["board","bottom","soldermask_bottom","bottom_silkscreen","top","soldermask_top","soldermask_with_copper_bottom","soldermask_with_copper_top","top_fabrication","bottom_fabrication",...e7e(t).filter(n=>n.startsWith("inner")),"drill","edge_cuts","bottom_notes","top_notes","top_silkscreen","top_courtyard","bottom_courtyard","other"];function mVo(t){return t.type==="pcb_copper_pour"}function pVo({canvas:t,elements:e,layers:n,realToCanvasMat:o}){const i=e.filter(mVo);if(i.length===0)return;const r=new wc(t);r.realToCanvasMat=o,r.drawElements(i,{layers:n})}var IVo={...t1,courtyard:{top:Fo.board.f_crtyd,bottom:Fo.board.b_crtyd}};function fVo(t){return t.type==="pcb_courtyard_circle"||t.type==="pcb_courtyard_rect"||t.type==="pcb_courtyard_outline"}function FHt({canvas:t,elements:e,layers:n,realToCanvasMat:o}){const i=new wc(t);i.configure({colorOverrides:IVo}),i.realToCanvasMat=o;const r=e.filter(fVo);i.drawElements(r,{layers:n})}var CVo={...t1,silkscreen:{top:Fo.board.f_fab,bottom:Fo.board.b_fab}};function yVo(t){return t.type.includes("pcb_fabrication_note")}function LHt({canvas:t,elements:e,layers:n,realToCanvasMat:o}){const i=new wc(t);i.configure({colorOverrides:CVo}),i.realToCanvasMat=o;const r=e.filter(yVo);i.drawElements(r,{layers:n})}function EVo(t){return t.type==="pcb_hole"}function xVo({canvas:t,elements:e,layers:n,realToCanvasMat:o,drawSoldermask:i}){const r=new wc(t);r.realToCanvasMat=o;const s=e.filter(EVo);r.drawElements(s,{layers:n,drawSoldermask:i})}function BVo(t){return t.type==="pcb_board"}function QVo({canvas:t,elements:e,layers:n,realToCanvasMat:o,drawSoldermask:i}){const r=new wc(t);r.realToCanvasMat=o;const s=e.filter(BVo);for(const a of s)r.drawElements([a],{layers:n,drawSoldermask:!1,drawBoardMaterial:i??!1,minBoardOutlineStrokePx:2})}function SVo(t){return t.type==="pcb_copper_text"}function bVo({canvas:t,elements:e,layers:n,realToCanvasMat:o}){const i=e.filter(SVo);if(i.length===0)return;const r=new wc(t);r.realToCanvasMat=o,r.drawElements(i,{layers:n})}function DVo(t){return t.type==="pcb_cutout"}function vVo({canvas:t,elements:e,layers:n,realToCanvasMat:o}){const i=new wc(t);i.realToCanvasMat=o;const r=e.filter(DVo);i.drawElements(r,{layers:n})}function PVo(t){return t.type==="pcb_keepout"}function wVo({canvas:t,elements:e,layers:n,realToCanvasMat:o}){const i=e.filter(PVo);if(i.length===0)return;const r=new wc(t);r.realToCanvasMat=o,r.drawElements(i,{layers:[]})}function MVo(t){return t.type.startsWith("pcb_note_")}function HHt({canvas:t,elements:e,layers:n,realToCanvasMat:o}){const i=new wc(t);i.realToCanvasMat=o;const r=e.filter(MVo);i.drawElements(r,{layers:n})}function NVo(t){return t.type==="pcb_panel"}function RVo({canvas:t,elements:e,layers:n,realToCanvasMat:o,drawSoldermask:i}){const r=new wc(t);r.realToCanvasMat=o;const s=e.filter(NVo);for(const a of s)r.drawElements([a],{layers:n})}var TVo={...t1,copper:{...t1.copper,top:Kr(Fo.board.pad_front).lighten(.5).toString(),bottom:Kr(Fo.board.pad_back).lighten(.5).toString(),inner1:Kr(Fo.board.copper.in1).lighten(.5).toString(),inner2:Kr(Fo.board.copper.in2).lighten(.5).toString(),inner3:Kr(Fo.board.copper.in3).lighten(.5).toString(),inner4:Kr(Fo.board.copper.in4).lighten(.5).toString(),inner5:Kr(Fo.board.copper.in5).lighten(.5).toString(),inner6:Kr(Fo.board.copper.in6).lighten(.5).toString(),inner7:Kr(Fo.board.copper.in7).lighten(.5).toString(),inner8:Kr(Fo.board.copper.in8).lighten(.5).toString()}};function kVo(t){return t.type==="pcb_smtpad"}function FVo({canvas:t,elements:e,layers:n,realToCanvasMat:o,primitives:i,drawSoldermask:r}){const s=new Set(kHt(n)),a=e.filter(kVo).filter(g=>s.has(g.layer));if(a.length===0)return;const A=new Set;if(i)for(const g of i)(g.is_mouse_over||g.is_in_highlighted_net)&&g._element?.type==="pcb_smtpad"&&A.add(g._element.pcb_smtpad_id);const c=a.filter(g=>A.has(g.pcb_smtpad_id)),l=a.filter(g=>!A.has(g.pcb_smtpad_id));if(l.length>0){const g=new wc(t);g.realToCanvasMat=o,g.drawElements(l,{layers:n,drawSoldermask:r})}if(c.length>0){const g=new wc(t);g.configure({colorOverrides:TVo}),g.realToCanvasMat=o,g.drawElements(c,{layers:n,drawSoldermask:r})}}var LVo={...t1,copper:{...t1.copper,top:Kr(Fo.board.pad_front).lighten(.5).toString(),bottom:Kr(Fo.board.pad_back).lighten(.5).toString(),inner1:Kr(Fo.board.copper.in1).lighten(.5).toString(),inner2:Kr(Fo.board.copper.in2).lighten(.5).toString(),inner3:Kr(Fo.board.copper.in3).lighten(.5).toString(),inner4:Kr(Fo.board.copper.in4).lighten(.5).toString(),inner5:Kr(Fo.board.copper.in5).lighten(.5).toString(),inner6:Kr(Fo.board.copper.in6).lighten(.5).toString(),inner7:Kr(Fo.board.copper.in7).lighten(.5).toString(),inner8:Kr(Fo.board.copper.in8).lighten(.5).toString()}};function HVo(t){return t.type==="pcb_trace"}var GVo=(t,e)=>{const n=t.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 n.filter(i=>i.route_type==="wire").length<2?null:{...t,route:n}},OVo=t=>({...t,route:t.route.map(e=>!("is_inside_copper_pour"in e)||e.is_inside_copper_pour!==!0?e:{...e,is_inside_copper_pour:!1})}),KVo=(t,e)=>e?t:[],UVo=({primitives:t,targetLayers:e,selectedLayer:n})=>{const o=new Set;if(!e.has(n))return o;for(const i of t)(i.is_mouse_over||i.is_in_highlighted_net)&&i._element?.type==="pcb_trace"&&o.add(i._element.pcb_trace_id);return o};function YVo({canvas:t,elements:e,layers:n,selectedLayer:o,realToCanvasMat:i,primitives:r,showCopperPours:s}){const a=new Set(kHt(n)),A=e.filter(HVo).map(h=>GVo(h,a)).filter(h=>h!==null).map(h=>s?h:OVo(h));if(A.length===0)return;const c=UVo({primitives:r??[],targetLayers:a,selectedLayer:o}),l=[],g=[];for(const h of A)c.has(h.pcb_trace_id)?l.push(h):g.push(h);const u=KVo(e,s);if(g.length>0){const h=new wc(t);h.realToCanvasMat=i,h.drawElements(g,{layers:n,clipContextElements:u})}if(l.length>0){const h=new wc(t);h.configure({colorOverrides:LVo}),h.realToCanvasMat=i,h.drawElements(l,{layers:n,clipContextElements:u})}}var zVo={...t1,copper:{...t1.copper,top:Kr(Fo.board.pad_front).lighten(.5).toString(),bottom:Kr(Fo.board.pad_back).lighten(.5).toString(),inner1:Kr(Fo.board.copper.in1).lighten(.5).toString(),inner2:Kr(Fo.board.copper.in2).lighten(.5).toString(),inner3:Kr(Fo.board.copper.in3).lighten(.5).toString(),inner4:Kr(Fo.board.copper.in4).lighten(.5).toString(),inner5:Kr(Fo.board.copper.in5).lighten(.5).toString(),inner6:Kr(Fo.board.copper.in6).lighten(.5).toString(),inner7:Kr(Fo.board.copper.in7).lighten(.5).toString(),inner8:Kr(Fo.board.copper.in8).lighten(.5).toString()}};function VVo(t){return t.type==="pcb_plated_hole"}function JVo({canvas:t,elements:e,layers:n,realToCanvasMat:o,primitives:i,drawSoldermask:r}){const s=e.filter(VVo);if(s.length===0)return;const a=new Set;if(i)for(const l of i)(l.is_mouse_over||l.is_in_highlighted_net)&&l._element?.type==="pcb_plated_hole"&&a.add(l._element.pcb_plated_hole_id);const A=s.filter(l=>a.has(l.pcb_plated_hole_id)),c=s.filter(l=>!a.has(l.pcb_plated_hole_id));if(c.length>0){const l=new wc(t);l.realToCanvasMat=o,l.drawElements(c,{layers:n,drawSoldermask:r})}if(A.length>0){const l=new wc(t);l.configure({colorOverrides:zVo}),l.realToCanvasMat=o,l.drawElements(A,{layers:n,drawSoldermask:r})}}function GHt(t){const{lines:e,anchorPoint:n,ccwRotation:o}=t;if(!o)return e;const i=o*Math.PI/180,r=E_(i),s=Fi(ji(n.x,n.y),r,ji(-n.x,-n.y));return mt(s,n),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 qVo=.6,OHt=.2,KHt=t=>{const e=t.size*.7,n=e*qVo,o=e*OHt,i=e*OHt,r=t.text.split(/\r?\n/),s=t.text.length>0&&e>0,a=s?r.length:0,A=s?r.map(g=>g.length===0?0:g.length*n+(g.length-1)*o):[],c=A.length>0?Math.max(...A):0,l=a>0?a*e+(a-1)*i:0;return{text_lines:r,line_count:a,line_widths:A,target_height:e,target_width_char:n,space_between_chars:o,space_between_lines:i,width:c,height:l}},UHt=t=>{const e=KHt(t);return{width:e.width,height:e.height,lineHeight:e.target_height,lineSpacing:e.space_between_lines,lineCount:e.line_count}},YHt=t=>{const{text_lines:e,line_count:n,line_widths:o,target_height:i,target_width_char:r,space_between_chars:s,space_between_lines:a,width:A}=KHt(t);if(i<=0||n===0)return[];const c=i/12,l=[];for(let g=0;g<n;g++){const u=-g*(i+a),h=o[g],d=(A-h)/2;let _=t.x+d;for(let m=0;m<e[g].length;m++){const p=e[g][m],I=W3[p]??W3[p.toUpperCase()];if(!I){_+=r+s;continue}for(const{x1:f,y1:C,x2:y,y2:E}of I)l.push({_pcb_drawing_object_id:tQ("line"),pcb_drawing_type:"line",x1:_+r*f,y1:t.y+u+i*C,x2:_+r*y,y2:t.y+u+i*E,width:c,layer:t.layer,unit:t.unit,color:t.color});_+=r+s}}return l};function db(t){const n=t.color??lae[t.layer];let o=Kr(n);return t._element?.type==="pcb_copper_pour"&&(o=o.alpha(.7)),t.is_mouse_over||t.is_in_highlighted_net?o.lighten(.5).rgb().toString():o.rgb().toString()}var zHt=(t,e)=>{t.equip({size:e.zoomIndependent?e.width/t.transform.a:e.width,shape:e.squareCap?"square":"circle",color:db(e),layer:e.layer}),t.moveTo(e.x1,e.y1),t.lineTo(e.x2,e.y2)},WVo=(t,e,n)=>{switch(n){case"top_left":return{x:0,y:-e};case"top_center":return{x:-t/2,y:-e};case"top_right":return{x:-t,y:-e};case"center_left":return{x:0,y:-e/2};case"center":return{x:-t/2,y:-e/2};case"center_right":return{x:-t,y:-e/2};case"bottom_left":return{x:0,y:0};case"bottom_center":return{x:-t/2,y:0};case"bottom_right":return{x:-t,y:0};default:return{x:0,y:0}}},VHt=t=>t.layer==="bottom_silkscreen"||t.layer==="bottom"?t.is_mirrored!==!1:t.is_mirrored===!0,jVo=(t,e)=>{t.equip({fontSize:e.size,color:db(e),layer:e.layer});const{width:n,height:o}=UHt(e),i=WVo(n,o,e.align);e.x??=0,e.y??=0;const r={x:e.x,y:e.y};let s=YHt({...e,x:e.x+i.x,y:e.y+i.y});if(VHt(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:r,ccwRotation:e.ccw_rotation};s=GHt(a)}for(const a of s)zHt(t,a)},XVo=(t,e)=>{const{width:n,height:o,lineHeight:i}=UHt(e);e.x??=0,e.y??=0;const r=e.knockout_padding??{left:e.size*.5,right:e.size*.5,top:e.size*.3,bottom:e.size*.3},s=n+r.left+r.right,a=o+r.top+r.bottom,A=n/2,c=i-o/2,l=e.x-A,g=e.y-c,u={x:e.x,y:e.y},h={_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?qHt(t,h):JHt(t,h);let d=YHt({...e,x:l,y:g});if(VHt(e)&&(d=d.map(_=>({..._,x1:2*e.x-_.x1,x2:2*e.x-_.x2}))),e.ccw_rotation){const _={lines:d,anchorPoint:u,ccwRotation:e.ccw_rotation};d=GHt(_)}for(const _ of d)t.equip({size:_.width,shape:"circle",color:"black",layer:e.layer,mode:"subtract"}),t.moveTo(_.x1,_.y1),t.lineTo(_.x2,_.y2);t.equip({mode:"add"})},JHt=(t,e)=>{t.equip({color:db(e),layer:e.layer,size:e.stroke_width}),t.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})},qHt=(t,e)=>{t.equip({color:db(e),layer:e.layer}),t.rotatedRect(e.x,e.y,e.w,e.h,e.ccw_rotation,e.roundness,e.mesh_fill)},$Vo=(t,e)=>{t.equip({color:db(e),layer:e.layer}),t.rotatedPill(e.x,e.y,e.w,e.h,e.ccw_rotation)},ZVo=(t,e)=>{t.equip({color:db(e),layer:e.layer}),t.circle(e.x,e.y,e.r,e.mesh_fill)},eJo=(t,e)=>{t.equip({color:db(e),layer:e.layer}),t.oval(e.x,e.y,e.rX,e.rY)},tJo=(t,e)=>{t.equip({color:db(e),layer:e.layer}),t.pill(e.x,e.y,e.w,e.h)},nJo=(t,e)=>{t.equip({color:db(e),layer:e.layer}),t.polygon(e.points)},oJo=(t,e)=>{t.equip({color:db(e),layer:e.layer}),t.polygonWithArcs(e.brep_shape)},iJo=(t,e)=>{switch(e.pcb_drawing_type){case"line":return zHt(t,e);case"text":return e.is_knockout?XVo(t,e):jVo(t,e);case"rect":return e.ccw_rotation?qHt(t,e):JHt(t,e);case"circle":return ZVo(t,e);case"oval":return eJo(t,e);case"pill":return e.ccw_rotation?$Vo(t,e):tJo(t,e);case"polygon":return nJo(t,e);case"polygon_with_arcs":return oJo(t,e)}},rJo=(t,e)=>{for(const n of e)iJo(t,n)},sJo={...t1,silkscreen:{top:Fo.board.f_silks,bottom:Fo.board.b_silks}};function aJo(t){return t.type.includes("pcb_silkscreen")}function WHt({canvas:t,elements:e,layers:n,realToCanvasMat:o}){const i=new wc(t);i.configure({colorOverrides:sJo}),i.realToCanvasMat=o;const r=e.filter(aJo);i.drawElements(r,{layers:n})}var AJo={...t1,copper:{...t1.copper,top:Kr(Fo.board.pad_front).lighten(.5).toString(),bottom:Kr(Fo.board.pad_back).lighten(.5).toString(),inner1:Kr(Fo.board.copper.in1).lighten(.5).toString(),inner2:Kr(Fo.board.copper.in2).lighten(.5).toString(),inner3:Kr(Fo.board.copper.in3).lighten(.5).toString(),inner4:Kr(Fo.board.copper.in4).lighten(.5).toString(),inner5:Kr(Fo.board.copper.in5).lighten(.5).toString(),inner6:Kr(Fo.board.copper.in6).lighten(.5).toString(),inner7:Kr(Fo.board.copper.in7).lighten(.5).toString(),inner8:Kr(Fo.board.copper.in8).lighten(.5).toString()},soldermask:{...t1.soldermask,top:Kr(Fo.board.soldermask.top).lighten(.35).toString(),bottom:Kr(Fo.board.soldermask.bottom).lighten(.35).toString()}};function jHt({canvas:t,elements:e,layers:n,realToCanvasMat:o,drawSoldermaskTop:i,drawSoldermaskBottom:r,primitives:s}){const a=new wc(t);a.realToCanvasMat=o;const A=e.filter(u=>u.type==="pcb_board");if(A.length<=1)a.drawElements(e,{layers:n,drawSoldermask:!0,drawSoldermaskTop:i,drawSoldermaskBottom:r,drawBoardMaterial:!1});else{const u=e.filter(h=>h.type!=="pcb_board");for(const h of A)a.drawElements([h,...u],{layers:n,drawSoldermask:!0,drawSoldermaskTop:i,drawSoldermaskBottom:r,drawBoardMaterial:!1})}if(!s)return;const c=new Set;for(const u of s){if(!(u.is_mouse_over||u.is_in_highlighted_net))continue;const h=u._element;h?.type==="pcb_smtpad"?c.add(h.pcb_smtpad_id):h?.type==="pcb_plated_hole"?c.add(h.pcb_plated_hole_id):h?.type==="pcb_via"&&c.add(h.pcb_via_id)}if(c.size===0)return;const l=e.filter(u=>u.type==="pcb_smtpad"?c.has(u.pcb_smtpad_id):u.type==="pcb_plated_hole"?c.has(u.pcb_plated_hole_id):u.type==="pcb_via"?c.has(u.pcb_via_id):!1);if(l.length===0)return;const g=new wc(t);g.configure({colorOverrides:AJo}),g.realToCanvasMat=o,g.drawElements(l,{layers:n,drawSoldermask:!0,drawSoldermaskTop:i,drawSoldermaskBottom:r,drawBoardMaterial:!1})}var cJo={...t1,copper:{...t1.copper,top:Kr(Fo.board.pad_front).lighten(.5).toString(),bottom:Kr(Fo.board.pad_back).lighten(.5).toString(),inner1:Kr(Fo.board.copper.in1).lighten(.5).toString(),inner2:Kr(Fo.board.copper.in2).lighten(.5).toString(),inner3:Kr(Fo.board.copper.in3).lighten(.5).toString(),inner4:Kr(Fo.board.copper.in4).lighten(.5).toString(),inner5:Kr(Fo.board.copper.in5).lighten(.5).toString(),inner6:Kr(Fo.board.copper.in6).lighten(.5).toString(),inner7:Kr(Fo.board.copper.in7).lighten(.5).toString(),inner8:Kr(Fo.board.copper.in8).lighten(.5).toString()}};function lJo(t){return t.type==="pcb_via"}function gJo({canvas:t,elements:e,layers:n,realToCanvasMat:o,primitives:i,drawSoldermask:r}){const s=e.filter(lJo).filter(l=>n.some(g=>g.includes("copper")));if(s.length===0)return;const a=new Set;if(i)for(const l of i)(l.is_mouse_over||l.is_in_highlighted_net)&&l._element?.type==="pcb_via"&&a.add(l._element.pcb_via_id);const A=s.filter(l=>a.has(l.pcb_via_id)),c=s.filter(l=>!a.has(l.pcb_via_id));if(c.length>0){const l=new wc(t);l.realToCanvasMat=o,l.drawElements(c,{layers:n,drawSoldermask:r})}if(A.length>0){const l=new wc(t);l.configure({colorOverrides:cJo}),l.realToCanvasMat=o,l.drawElements(A,{layers:n,drawSoldermask:r})}}var uJo=({primitives:t,elements:e,transform:n,grid:o,width:i=500,height:r=500})=>{const s=X.useRef({}),a=yd(d=>d.selected_layer),A=yd(d=>d.is_showing_copper_pours),c=yd(d=>d.is_showing_solder_mask),l=yd(d=>d.is_showing_fabrication_notes),g=yd(d=>d.is_showing_pcb_notes),u=yd(d=>d.is_showing_courtyards),h=yd(d=>d.is_showing_silkscreen);return X.useEffect(()=>{if(!s.current||Object.keys(s.current).length===0)return;const d=Object.fromEntries(Object.entries(s.current).filter(([p,I])=>!!I));if(Object.keys(d).length===0)return;const _=new uVo(d);n&&(_.transform=n),_.clear(),_.foregroundLayer=a;const m=t.filter(p=>c||!p.layer?.includes("soldermask")).filter(p=>h||!p.layer?.includes("silkscreen")).filter(p=>l||!p.layer?.includes("fabrication")).filter(p=>p.layer!=="board").filter(p=>p._element?.type!=="pcb_smtpad").filter(p=>p._element?.type!=="pcb_plated_hole").filter(p=>p._element?.type!=="pcb_via").filter(p=>p._element?.type!=="pcb_trace").filter(p=>p._element?.type!=="pcb_copper_text");if(rJo(_,m),n){const p=s.current.top,I=s.current.bottom,f=e7e(e).map(Q=>({canvas:s.current[Q],layer:Q,copperLayer:hVo(Q)}));for(const{canvas:Q,copperLayer:b}of f)Q&&YVo({canvas:Q,elements:e,layers:[b],selectedLayer:a,realToCanvasMat:n,primitives:t,showCopperPours:A});for(const{canvas:Q,copperLayer:b}of f)Q&&bVo({canvas:Q,elements:e,layers:[b],realToCanvasMat:n});for(const{canvas:Q,copperLayer:b,layer:D}of f)Q&&JVo({canvas:Q,elements:e,layers:[b],realToCanvasMat:n,primitives:t,drawSoldermask:c&&(D==="top"||D==="bottom")});for(const{canvas:Q,copperLayer:b}of f)Q&&pVo({canvas:Q,elements:e,layers:[b],realToCanvasMat:n});for(const{canvas:Q,copperLayer:b}of f)Q&&FVo({canvas:Q,elements:e,layers:[b],realToCanvasMat:n,primitives:t,drawSoldermask:c});for(const{canvas:Q,copperLayer:b,layer:D}of f)Q&&gJo({canvas:Q,elements:e,layers:[b],realToCanvasMat:n,primitives:t,drawSoldermask:c&&(D==="top"||D==="bottom")});if(c){const Q=a==="bottom"?"bottom":"top",b=Q==="top",D=Q==="bottom",R=s.current.soldermask_top;R&&Q==="top"&&jHt({canvas:R,elements:e,layers:["top_soldermask"],realToCanvasMat:n,drawSoldermaskTop:b,drawSoldermaskBottom:D,primitives:t});const M=s.current.soldermask_bottom;M&&Q==="bottom"&&jHt({canvas:M,elements:e,layers:["bottom_soldermask"],realToCanvasMat:n,drawSoldermaskTop:b,drawSoldermaskBottom:D,primitives:t})}const C=s.current.drill;if(C&&xVo({canvas:C,elements:e,layers:["drill"],realToCanvasMat:n}),h){const Q=s.current.top_silkscreen;Q&&WHt({canvas:Q,elements:e,layers:["top_silkscreen"],realToCanvasMat:n});const b=s.current.bottom_silkscreen;b&&WHt({canvas:b,elements:e,layers:["bottom_silkscreen"],realToCanvasMat:n})}if(l){const Q=s.current.top_fabrication;Q&&LHt({canvas:Q,elements:e,layers:["top_fabrication_note"],realToCanvasMat:n});const b=s.current.bottom_fabrication;b&&LHt({canvas:b,elements:e,layers:["bottom_fabrication_note"],realToCanvasMat:n})}if(g){const Q=s.current.bottom_notes;Q&&HHt({canvas:Q,elements:e,layers:["bottom_user_note"],realToCanvasMat:n});const b=s.current.top_notes;b&&HHt({canvas:b,elements:e,layers:["top_user_note"],realToCanvasMat:n})}if(u){const Q=s.current.top_courtyard;Q&&FHt({canvas:Q,elements:e,layers:["top_courtyard"],realToCanvasMat:n});const b=s.current.bottom_courtyard;b&&FHt({canvas:b,elements:e,layers:["bottom_courtyard"],realToCanvasMat:n})}const y=s.current.board;y&&(RVo({canvas:y,elements:e,layers:[],realToCanvasMat:n,drawSoldermask:c}),QVo({canvas:y,elements:e,layers:[],realToCanvasMat:n,drawSoldermask:c}));const E=s.current.edge_cuts;E&&vVo({canvas:E,elements:e,layers:["edge_cuts"],realToCanvasMat:n});const B=[{canvas:p,layer:"top"},{canvas:I,layer:"bottom"}];for(const{canvas:Q,layer:b}of B)Q&&wVo({canvas:Q,elements:e,layers:[b],realToCanvasMat:n})}_.orderAndFadeLayers()},[t,e,n,a,A,c,l,g,u,h]),z.jsxs("div",{style:{backgroundColor:"black",width:i,height:r,position:"relative"},children:[z.jsx(qse.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:r,transform:n,stringifyCoord:(d,_,m)=>`${qse.toMMSI(d,m)}, ${qse.toMMSI(_,m)}`}),_Vo(e).filter(d=>!(!c&&d.includes("soldermask")||!h&&d.includes("silkscreen"))).map(d=>d.replace(/-/g,"")).map((d,_)=>z.jsx("canvas",{className:`pcb-layer-${d}`,ref:m=>{s.current??={},m?s.current[d]=m:delete s.current[d]},style:{position:"absolute",zIndex:_,left:0,top:0,pointerEvents:"none"},width:i,height:r},d))]})},dJo=.6,hJo=1;V9e(nzo(),1),V9e(Izo(),1);var gae=["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 XHt(t,e,n,o={}){const i=o.padding??40,r=o.yFlip??!1;let s;if("center"in t){const l=t.width/2,g=t.height/2;s={minX:t.center.x-l,maxX:t.center.x+l,minY:t.center.y-g,maxY:t.center.y+g}}else s=t;const a=s.maxX-s.minX||1,A=s.maxY-s.minY||1,c=Math.min((e-2*i)/a,(n-2*i)/A);return Fi(ji(e/2,n/2),gg(c,r?-c:c),ji(-(s.minX+a/2),-(s.minY+A/2)))}function _Jo(t){const e=[...t.points||[],...(t.lines||[]).flatMap(n=>n.points),...(t.rects||[]).flatMap(n=>{const o=n.width/2,i=n.height/2;return[{x:n.center.x-o,y:n.center.y-i},{x:n.center.x+o,y:n.center.y-i},{x:n.center.x-o,y:n.center.y+i},{x:n.center.x+o,y:n.center.y+i}]}),...(t.circles||[]).flatMap(n=>[{x:n.center.x-n.radius,y:n.center.y},{x:n.center.x+n.radius,y:n.center.y},{x:n.center.x,y:n.center.y-n.radius},{x:n.center.x,y:n.center.y+n.radius}]),...(t.texts||[]).flatMap(n=>{const o=n.fontSize??12,i=n.text.length*o*dJo,r=o*hJo,s=n.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:-r/2},center:{dx:-i/2,dy:-r/2},center_right:{dx:-i,dy:-r/2},bottom_left:{dx:0,dy:-r},bottom_center:{dx:-i/2,dy:-r},bottom_right:{dx:-i,dy:-r}},{dx:A,dy:c}=a[s],l=n.x+A,g=n.y+c;return[{x:l,y:g},{x:l+i,y:g+r}]})];return e.length===0?{minX:-1,maxX:1,minY:-1,maxY:1}:e.reduce((n,o)=>({minX:Math.min(n.minX,o.x),maxX:Math.max(n.maxX,o.x),minY:Math.min(n.minY,o.y),maxY:Math.max(n.maxY,o.y)}),{minX:1/0,maxX:-1/0,minY:1/0,maxY:-1/0})}function mJo(t,e,n={}){const o=e instanceof HTMLCanvasElement?e.getContext("2d"):e;if(!o)throw new Error("Could not get 2D context from canvas");const i=e instanceof HTMLCanvasElement?e.width:e.canvas.width,r=e instanceof HTMLCanvasElement?e.height:e.canvas.height;let s;if(n.transform)s=n.transform;else if(n.viewbox)s=XHt(n.viewbox,i,r,{padding:n.padding,yFlip:n.yFlip});else{const a=_Jo(t),A=t.coordinateSystem==="cartesian";s=XHt(a,i,r,{padding:n.padding??40,yFlip:A})}o.clearRect(0,0,i,r),o.save(),t.rects&&t.rects.length>0&&t.rects.forEach(a=>{const A=a.width/2,c=a.height/2,l=mt(s,{x:a.center.x-A,y:a.center.y-c}),g=mt(s,{x:a.center.x+A,y:a.center.y+c}),u=Math.abs(g.x-l.x),h=Math.abs(g.y-l.y);o.beginPath(),o.rect(Math.min(l.x,g.x),Math.min(l.y,g.y),u,h),a.fill&&(o.fillStyle=a.fill,o.fill()),a.stroke&&(o.strokeStyle=a.stroke,o.stroke())}),t.circles&&t.circles.length>0&&t.circles.forEach(a=>{const A=mt(s,a.center),c=a.radius*Math.abs(s.a);o.beginPath(),o.arc(A.x,A.y,c,0,2*Math.PI),a.fill&&(o.fillStyle=a.fill,o.fill()),a.stroke&&(o.strokeStyle=a.stroke??"transparent",o.stroke())}),t.lines&&t.lines.length>0&&t.lines.forEach((a,A)=>{if(a.points.length===0)return;o.beginPath();const c=mt(s,a.points[0]);o.moveTo(c.x,c.y);for(let l=1;l<a.points.length;l++){const g=mt(s,a.points[l]);o.lineTo(g.x,g.y)}if(o.strokeStyle=a.strokeColor||gae[A%gae.length],a.strokeWidth?o.lineWidth=a.strokeWidth*s.a:o.lineWidth=2,o.lineCap="round",a.strokeDash)if(typeof a.strokeDash=="string"){let l;if(a.strokeDash.includes(","))l=a.strokeDash.split(",").map(g=>parseFloat(g.trim())).filter(g=>!Number.isNaN(g));else{const g=parseFloat(a.strokeDash.trim());l=Number.isNaN(g)?[]:[g]}o.setLineDash(l)}else o.setLineDash(a.strokeDash.map(l=>l*Math.abs(s.a)));else o.setLineDash([]);o.stroke()}),t.points&&t.points.length>0&&t.points.forEach((a,A)=>{const c=mt(s,a);o.beginPath(),o.arc(c.x,c.y,3,0,2*Math.PI),o.fillStyle=a.color||gae[A%gae.length],o.fill(),a.label&&!n.disableLabels&&(o.fillStyle=a.color||"black",o.font="12px sans-serif",o.fillText(a.label,c.x+5,c.y-5))}),t.texts&&t.texts.length>0&&t.texts.forEach(a=>{const A=mt(s,{x:a.x,y:a.y});o.fillStyle=a.color||"black",o.font=`${(a.fontSize??12)*Math.abs(s.a)}px sans-serif`;const c=a.anchorSide??"center",l={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"},g={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"};o.textAlign=l[c],o.textBaseline=g[c],o.fillText(a.text,A.x,A.y)}),o.restore()}var pJo=({children:t,transform:e,debugGraphics:n})=>{const o=X.useRef(null),[i,{width:r,height:s}]=GY(),a=yd(A=>A.is_showing_autorouting);return X.useEffect(()=>{a&&o.current&&n&&r&&s&&(o.current.width=r,o.current.height=s,mJo(n,o.current,{transform:e,disableLabels:!0}))},[n,e,r,s,a]),a?z.jsxs("div",{ref:i,style:{position:"relative",width:"100%",height:"100%"},children:[t,z.jsx("canvas",{ref:o,style:{position:"absolute",top:0,left:0,opacity:.5,zIndex:100,width:"100%",height:"100%",pointerEvents:"none"}})]}):t},uae=(t,e,n)=>n(t,e),$Ht=(t,e,n,o,i)=>{const r=i*Math.PI/180,s=Math.cos(r),a=Math.sin(r),A=t-n,c=e-o,l=A*s-c*a,g=A*a+c*s;return{x:l+n,y:g+o}},OY=t=>{if(t.length===0)return null;let e=t[0].x,n=t[0].x,o=t[0].y,i=t[0].y;for(const r of t)e=uae(e,r.x,Math.min),n=uae(n,r.x,Math.max),o=uae(o,r.y,Math.min),i=uae(i,r.y,Math.max);return{minX:e,maxX:n,minY:o,maxY:i}},IJo=(t,e)=>({minX:Math.min(t.minX,e.minX),maxX:Math.max(t.maxX,e.maxX),minY:Math.min(t.minY,e.minY),maxY:Math.max(t.maxY,e.maxY)}),fJo=(t,e)=>t?IJo(t,e):e,CJo=t=>{switch(t.pcb_drawing_type){case"line":{const e=(t.width??0)/2,n=[{x:t.x1,y:t.y1},{x:t.x2,y:t.y2}],o=OY(n);return o?{minX:o.minX-e,maxX:o.maxX+e,minY:o.minY-e,maxY:o.maxY+e}:null}case"rect":{const e=t.w/2,n=t.h/2,o=[{x:t.x-e,y:t.y-n},{x:t.x+e,y:t.y-n},{x:t.x+e,y:t.y+n},{x:t.x-e,y:t.y+n}],i=t.ccw_rotation??0,r=i===0?o:o.map(s=>$Ht(s.x,s.y,t.x,t.y,i));return OY(r)}case"circle":return{minX:t.x-t.r,maxX:t.x+t.r,minY:t.y-t.r,maxY:t.y+t.r};case"oval":return{minX:t.x-t.rX,maxX:t.x+t.rX,minY:t.y-t.rY,maxY:t.y+t.rY};case"pill":{const e=t.w/2,n=t.h/2,o=[{x:t.x-e,y:t.y-n},{x:t.x+e,y:t.y-n},{x:t.x+e,y:t.y+n},{x:t.x-e,y:t.y+n}],i=t.ccw_rotation??0,r=i===0?o:o.map(s=>$Ht(s.x,s.y,t.x,t.y,i));return OY(r)}case"polygon":return OY(t.points);case"polygon_with_arcs":{const e=t.brep_shape.outer_ring.vertices.map(n=>({x:n.x,y:n.y}));return OY(e)}case"text":{const e=t.size??0,n=t.text?t.text.length*e*.6:0,o=e;if(n===0&&o===0)return{minX:t.x,maxX:t.x,minY:t.y,maxY:t.y};const i=n/2,r=o/2;return{minX:t.x-i,maxX:t.x+i,minY:t.y-r,maxY:t.y+r}}default:return null}};function yJo(t){const{dimensionStart:e,dimensionEnd:n,screenDimensionStart:o,screenDimensionEnd:i,flipX:r,flipY:s}=t,a=n.x-e.x,A=n.y-e.y,c=Math.sqrt(a*a+A*A),l=i.x-o.x,g=i.y-o.y,u=Math.sqrt(l*l+g*g),h=Math.atan2(g,l)*(180/Math.PI),d=Math.abs(h)%90,m=Math.min(d,90-d)>15,p=(o.x+i.x)/2,I=(o.y+i.y)/2,f=15,C=h+90;let y=Math.cos(C*Math.PI/180)*f,E=Math.sin(C*Math.PI/180)*f;const B=l>0&&g<0,Q=l>0&&g>0,b=l<0&&g>0;r!==s&&!B&&(y=-y,E=-E),B&&(y+=Math.cos(C*Math.PI/180)*-45,E+=Math.sin(C*Math.PI/180)*-45),Q&&(y+=Math.cos(C*Math.PI/180)+-20,E+=Math.sin(C*Math.PI/180)+-10),b&&(y+=Math.cos(C*Math.PI/180)*10,E+=Math.sin(C*Math.PI/180)*10);const D=p+y,R=I+E;return{distance:c,screenDistance:u,x:D,y:R,show:c>.01&&u>30&&m}}function EJo(t){const{dimensionStart:e,dimensionEnd:n,screenDimensionStart:o,screenDimensionEnd:i,flipX:r,flipY:s}=t;return X.useMemo(()=>yJo({dimensionStart:e,dimensionEnd:n,screenDimensionStart:o,screenDimensionEnd:i,flipX:r,flipY:s}),[e,n,o,i,r,s])}var xJo=(t,e,n)=>{const o=n*Math.PI/180,i=Math.cos(o),r=Math.sin(o),s=t.x-e.x,a=t.y-e.y,A=s*i-a*r,c=s*r+a*i;return{x:A+e.x,y:c+e.y}},ZHt=(t,e,n,o)=>{const i={top_left:{x:t.x-e,y:t.y-n},top_center:{x:t.x,y:t.y-n},top_right:{x:t.x+e,y:t.y-n},center_left:{x:t.x-e,y:t.y},center:{x:t.x,y:t.y},center_right:{x:t.x+e,y:t.y},bottom_left:{x:t.x-e,y:t.y+n},bottom_center:{x:t.x,y:t.y+n},bottom_right:{x:t.x+e,y:t.y+n}};return o===0?Object.entries(i).map(([r,s])=>({anchor:r,point:s})):Object.entries(i).map(([r,s])=>({anchor:r,point:xJo(s,t,o)}))},BJo=t=>{switch(t.pcb_drawing_type){case"rect":{const e=t.ccw_rotation??0;return ZHt({x:t.x,y:t.y},t.w/2,t.h/2,e)}case"pill":{const e=t.ccw_rotation??0;return ZHt({x:t.x,y:t.y},t.w/2,t.h/2,e)}case"circle":return[{anchor:"circle_center",point:{x:t.x,y:t.y}},{anchor:"circle_right",point:{x:t.x+t.r,y:t.y}},{anchor:"circle_left",point:{x:t.x-t.r,y:t.y}},{anchor:"circle_top",point:{x:t.x,y:t.y-t.r}},{anchor:"circle_bottom",point:{x:t.x,y:t.y+t.r}}];case"oval":return[{anchor:"oval_center",point:{x:t.x,y:t.y}},{anchor:"oval_right",point:{x:t.x+t.rX,y:t.y}},{anchor:"oval_left",point:{x:t.x-t.rX,y:t.y}},{anchor:"oval_top",point:{x:t.x,y:t.y-t.rY}},{anchor:"oval_bottom",point:{x:t.x,y:t.y+t.rY}}];case"line":{const e={x:(t.x1+t.x2)/2,y:(t.y1+t.y2)/2};return[{anchor:"line_start",point:{x:t.x1,y:t.y1}},{anchor:"line_mid",point:e},{anchor:"line_end",point:{x:t.x2,y:t.y2}}]}case"polygon":return t.points.map((e,n)=>({anchor:`polygon_vertex_${n}`,point:e}));case"polygon_with_arcs":return t.brep_shape.outer_ring.vertices.map((e,n)=>({anchor:`polygon_with_arcs_vertex_${n}`,point:{x:e.x,y:e.y}}));default:return[]}},QJo=16,j6=5,eGt=t=>{if(t.pcb_drawing_type==="text")return!0;const e=t._element;if(!e||typeof e!="object")return!1;const n=typeof e.type=="string"?e.type:void 0;return n?!!(n.startsWith("pcb_silkscreen_")||n.startsWith("pcb_note_")||n==="pcb_text"||n.startsWith("pcb_fabrication_note_")&&n!=="pcb_fabrication_note_rect"):!1},SJo=({children:t,transform:e,focusOnHover:n=!1,primitives:o=[],onBoundsSelected:i,cancelPanDrag:r})=>{e||(e=Hl());const[s,a]=X.useState(!1),[A,c]=X.useState(!1),[l,g]=X.useState(!1),[u,h]=X.useState(!1),[d,_]=X.useState(!1),[m,p]=X.useState(!1),[I,f]=X.useState({start:null,end:null}),C=yd(Me=>Me.is_mouse_over_container),y=X.useCallback(()=>{l&&(g(!1),window.dispatchEvent(new Event("disarm-dimension-tool")))},[l]),E=X.useCallback(()=>{u&&(h(!1),window.dispatchEvent(new Event("disarm-bounds-tool")))},[u]),[B,Q]=X.useState({x:0,y:0}),[b,D]=X.useState({x:0,y:0}),[R,M]=X.useState({x:0,y:0}),[L,G]=X.useState({x:0,y:0}),O=X.useRef({x:0,y:0}),U=X.useRef(null),j=U.current?.getBoundingClientRect(),te=X.useMemo(()=>{const Me=new Map;for(const Ye of o){if(!Ye._element||eGt(Ye)||Ye.pcb_drawing_type==="pill"||Ye.pcb_drawing_type==="rect"&&Ye.ccw_rotation&&Ye.ccw_rotation!==0)continue;const Ie=CJo(Ye);if(!Ie)continue;const We=Me.get(Ye._element);Me.set(Ye._element,fJo(We??void 0,Ie))}return Me},[o]),ie=X.useMemo(()=>{const Me=[];for(const Ye of o){if(!Ye._element||eGt(Ye))continue;const Ie=BJo(Ye);if(Ie.length!==0)for(const We of Ie)Me.push({anchor:We.anchor,point:We.point,element:Ye._element})}return Me},[o]),$=X.useMemo(()=>{const Me=[];te.forEach((Ye,Ie)=>{if(!Ye)return;const We=(Ye.minX+Ye.maxX)/2,Ne=(Ye.minY+Ye.maxY)/2,ke={top_left:{x:Ye.minX,y:Ye.minY},top_center:{x:We,y:Ye.minY},top_right:{x:Ye.maxX,y:Ye.minY},center_left:{x:Ye.minX,y:Ne},center:{x:We,y:Ne},center_right:{x:Ye.maxX,y:Ne},bottom_left:{x:Ye.minX,y:Ye.maxY},bottom_center:{x:We,y:Ye.maxY},bottom_right:{x:Ye.maxX,y:Ye.maxY}};for(const[Ve,Re]of Object.entries(ke))Me.push({anchor:Ve,point:Re,element:Ie})});for(const Ye of ie)Me.push(Ye);return Me.push({anchor:"origin",point:{x:0,y:0},element:null}),Me},[te,ie]),Z=X.useMemo(()=>$.map((Me,Ye)=>({...Me,id:`${Ye}-${Me.anchor}`,screenPoint:mt(e,Me.point)})),[$,e]),se=X.useCallback(Me=>{if(Z.length===0)return{point:Me,id:null};const Ye=mt(e,Me);let Ie=null;for(const We of Z){const Ne=We.screenPoint.x-Ye.x,ke=We.screenPoint.y-Ye.y,Ve=Math.hypot(Ne,ke);Ve>QJo||(!Ie||Ve<Ie.distance)&&(Ie={distance:Ve,id:We.id,point:We.point})}return Ie?{point:Ie.point,id:Ie.id}:{point:Me,id:null}},[Z,e]);X.useEffect(()=>{const Me=We=>{const Ne=We.target;if(Ne.tagName==="INPUT"||Ne.tagName==="TEXTAREA"||Ne.isContentEditable)return;const ke=U.current?.contains(document.activeElement)||document.activeElement===U.current;if(!(!C&&!ke)){if(We.key==="d"){const Ve=se({x:O.current.x,y:O.current.y});Q({x:Ve.point.x,y:Ve.point.y}),D({x:Ve.point.x,y:Ve.point.y}),f({start:Ve.id,end:Ve.id}),s?(a(!1),c(!1),f({start:null,end:null})):(a(!0),c(!0)),y()}We.key==="Escape"&&(a(!1),c(!1),f({start:null,end:null}),_(!1),p(!1),y(),E())}},Ye=()=>{g(!0),h(!1),window.dispatchEvent(new Event("disarm-bounds-tool"))},Ie=()=>{h(!0),g(!1),a(!1),c(!1),window.dispatchEvent(new Event("disarm-dimension-tool"))};return window.addEventListener("keydown",Me),window.addEventListener("arm-dimension-tool",Ye),window.addEventListener("arm-bounds-tool",Ie),()=>{window.removeEventListener("keydown",Me),window.removeEventListener("arm-dimension-tool",Ye),window.removeEventListener("arm-bounds-tool",Ie),y(),E()}},[C,s,y,E,se]);const ae=mt(e,B),ce=mt(e,b),fe=mt(e,R),Ce=mt(e,L),xe={minX:Math.min(R.x,L.x),minY:Math.min(R.y,L.y),maxX:Math.max(R.x,L.x),maxY:Math.max(R.y,L.y)},de={left:Math.min(fe.x,Ce.x),top:Math.min(fe.y,Ce.y),width:Math.abs(fe.x-Ce.x),height:Math.abs(fe.y-Ce.y)},Ee=X.useCallback((Me,Ye)=>{const Ie={minX:Math.min(Me.x,Ye.x),minY:Math.min(Me.y,Ye.y),maxX:Math.max(Me.x,Ye.x),maxY:Math.max(Me.y,Ye.y)};i?.(Ie),window.dispatchEvent(new CustomEvent("pcb-viewer:bounds-selected",{detail:Ie}))},[i]),he={left:Math.min(ae.x,ce.x),right:Math.max(ae.x,ce.x),top:Math.min(ae.y,ce.y),bottom:Math.max(ae.y,ce.y),flipX:ae.x>ce.x,flipY:ae.y>ce.y,width:0,height:0};he.width=he.right-he.left,he.height=he.bottom-he.top;const be=EJo({dimensionStart:B,dimensionEnd:b,screenDimensionStart:ae,screenDimensionEnd:ce,flipX:he.flipX,flipY:he.flipY});return z.jsxs("div",{ref:U,"data-pcb-viewer":!0,tabIndex:0,style:{position:"relative",outline:"none"},onMouseEnter:()=>{n&&U.current&&U.current.focus()},onMouseLeave:()=>{U.current&&U.current.blur()},onClick:()=>{U.current&&U.current.focus()},onMouseMove:Me=>{const Ye=Me.currentTarget.getBoundingClientRect(),Ie=Me.clientX-Ye.left,We=Me.clientY-Ye.top,Ne=mt(MQ(e),{x:Ie,y:We});if(O.current.x=Ne.x,O.current.y=Ne.y,A){const ke=se(Ne);D({x:ke.point.x,y:ke.point.y}),f(Ve=>({...Ve,end:ke.id}))}m&&(r?.(),G({x:Ne.x,y:Ne.y}))},onMouseDown:Me=>{const Ye=Me.currentTarget.getBoundingClientRect(),Ie=Me.clientX-Ye.left,We=Me.clientY-Ye.top,Ne=mt(MQ(e),{x:Ie,y:We});if(u)Me.preventDefault(),Me.stopPropagation(),r?.(),M({x:Ne.x,y:Ne.y}),G({x:Ne.x,y:Ne.y}),_(!0),p(!0),E();else if(l&&!s){const ke=se(Ne);Q({x:ke.point.x,y:ke.point.y}),D({x:ke.point.x,y:ke.point.y}),f({start:ke.id,end:ke.id}),a(!0),c(!0),y()}else A?(c(!1),f(ke=>({...ke,end:null}))):s&&(a(!1),f({start:null,end:null}))},onMouseUp:Me=>{if(!m)return;const Ye=Me.currentTarget.getBoundingClientRect(),Ie=Me.clientX-Ye.left,We=Me.clientY-Ye.top,Ne=mt(MQ(e),{x:Ie,y:We}),ke={x:Ne.x,y:Ne.y};Me.preventDefault(),Me.stopPropagation(),r?.(),G(ke),p(!1),Ee(R,ke)},children:[t,d&&z.jsxs(z.Fragment,{children:[z.jsx("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none",mixBlendMode:"difference",zIndex:Yg.dimensionOverlay},width:j.width,height:j.height,children:z.jsx("rect",{x:de.left,y:de.top,width:de.width,height:de.height,stroke:"red",strokeWidth:1.5,strokeDasharray:"4,3",fill:"rgba(255, 0, 0, 0.12)"})}),z.jsxs("div",{style:{left:0,bottom:s?58:0,position:"absolute",color:"red",fontFamily:"sans-serif",fontSize:12,margin:4,pointerEvents:"none",mixBlendMode:"difference",zIndex:Yg.dimensionOverlay},children:["minX: ",xe.minX.toFixed(2),", minY:"," ",xe.minY.toFixed(2),z.jsx("br",{}),"maxX: ",xe.maxX.toFixed(2),", maxY:"," ",xe.maxY.toFixed(2)]})]}),s&&z.jsxs(z.Fragment,{children:[be.show&&z.jsx("div",{style:{position:"absolute",left:be.x,top:be.y,color:"red",mixBlendMode:"difference",pointerEvents:"none",fontSize:12,fontFamily:"sans-serif",whiteSpace:"nowrap",zIndex:Yg.dimensionOverlay},children:be.distance.toFixed(2)}),z.jsx("div",{style:{position:"absolute",left:he.left,width:he.width,textAlign:"center",top:ae.y+2,color:"red",mixBlendMode:"difference",pointerEvents:"none",marginTop:he.flipY?0:-20,fontSize:12,fontFamily:"sans-serif",zIndex:Yg.dimensionOverlay},children:Math.abs(B.x-b.x).toFixed(2)}),z.jsx("div",{style:{position:"absolute",left:ce.x,height:he.height,display:"flex",flexDirection:"column",justifyContent:"center",top:he.top,color:"red",pointerEvents:"none",mixBlendMode:"difference",fontSize:12,fontFamily:"sans-serif",zIndex:Yg.dimensionOverlay},children:z.jsx("div",{style:{marginLeft:he.flipX?"-100%":4,paddingRight:4},children:Math.abs(B.y-b.y).toFixed(2)})}),z.jsxs("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none",mixBlendMode:"difference",zIndex:Yg.dimensionOverlay},width:j.width,height:j.height,children:[z.jsx("defs",{children:z.jsx("marker",{id:"head",orient:"auto",markerWidth:"3",markerHeight:"4",refX:"2",refY:"2",children:z.jsx("path",{d:"M0,0 V4 L2,2 Z",fill:"red"})})}),z.jsx("line",{x1:ae.x,y1:ae.y,x2:ce.x,y2:ce.y,markerEnd:"url(#head)",strokeWidth:1.5,fill:"none",stroke:"red"}),z.jsx("line",{x1:ae.x,y1:ae.y,x2:ce.x,y2:ae.y,strokeWidth:1.5,fill:"none",strokeDasharray:"2,2",stroke:"red"}),z.jsx("line",{x1:ce.x,y1:ae.y,x2:ce.x,y2:ce.y,strokeWidth:1.5,fill:"none",strokeDasharray:"2,2",stroke:"red"})]}),A&&Z.map(Me=>{const Ye=Me.id===I.start||Me.id===I.end,Ie=j6/2;return z.jsxs("svg",{width:j6,height:j6,style:{position:"absolute",left:Me.screenPoint.x-Ie,top:Me.screenPoint.y-Ie,pointerEvents:"none",zIndex:Yg.dimensionOverlay},children:[z.jsx("line",{x1:0,y1:0,x2:j6,y2:j6,stroke:Ye?"#66ccff":"white",strokeWidth:1}),z.jsx("line",{x1:j6,y1:0,x2:0,y2:j6,stroke:Ye?"#66ccff":"white",strokeWidth:1})]},Me.id)}),z.jsxs("div",{style:{right:0,bottom:0,position:"absolute",color:"red",fontFamily:"sans-serif",fontSize:12,margin:4},children:["(",B.x.toFixed(2),",",B.y.toFixed(2),")",z.jsx("br",{}),"(",b.x.toFixed(2),",",b.y.toFixed(2),")",z.jsx("br",{}),"dist:"," ",Math.sqrt((b.x-B.x)**2+(b.y-B.y)**2).toFixed(2)]})]})]})},bJo=(t,e,n=0)=>{const o=t.width/2,i=t.height/2,r=t.center.x-o-n,s=t.center.x+o+n,a=t.center.y-i-n,A=t.center.y+i+n;return e.x>r&&e.x<s&&e.y>a&&e.y<A},DJo=({children:t,disabled:e,transform:n,soup:o,cancelPanDrag:i,onCreateEditEvent:r,onModifyEditEvent:s})=>{n||(n=Hl());const a=X.useRef(null),[A,c]=X.useState(null),[l,g]=X.useState(null),u=A!==null;yd(m=>m.in_edit_mode);const h=yd(m=>m.in_move_footprint_mode),d=yd(m=>m.setIsMovingComponent),_=e||!h;return z.jsxs("div",{ref:a,style:{position:"relative",overflow:"hidden"},onMouseDown:m=>{if(_)return;const p=m.currentTarget.getBoundingClientRect(),I=m.clientX-p.left,f=m.clientY-p.top;if(Number.isNaN(I)||Number.isNaN(f))return;const C=mt(MQ(n),{x:I,y:f});let y=!1;for(const E of o)if(E.type==="pcb_component"&&bJo(E,C,10/n.a)){i(),c(E.pcb_component_id),y=!0;const B=Math.random().toString();g({dragStart:C,originalCenter:E.center,dragEnd:C,edit_event_id:B}),r({edit_event_id:B,edit_event_type:"edit_pcb_component_location",pcb_edit_event_type:"edit_component_location",pcb_component_id:E.pcb_component_id,original_center:E.center,new_center:E.center,in_progress:!0,created_at:Date.now()}),d(!0);break}if(y||c(null),y)return m.preventDefault(),!1},onMouseMove:m=>{if(!A||!l)return;const p=m.currentTarget.getBoundingClientRect(),I=m.clientX-p.left,f=m.clientY-p.top;if(Number.isNaN(I)||Number.isNaN(f))return;const C=mt(MQ(n),{x:I,y:f});g({...l,dragEnd:C}),s({edit_event_id:l.edit_event_id,new_center:{x:l.originalCenter.x+C.x-l.dragStart.x,y:l.originalCenter.y+C.y-l.dragStart.y}})},onMouseUp:m=>{A&&(c(null),d(!1),l&&(s({edit_event_id:l.edit_event_id,in_progress:!1}),g(null)))},children:[t,!_&&o.filter(m=>m.type==="pcb_component").map(m=>{if(!m?.center)return null;const p=mt(n,m.center);return z.jsx("div",{style:{position:"absolute",pointerEvents:"none",left:p.x,top:p.y,width:m.width*n.a+20,height:m.height*n.a+20,transform:"translate(-50%, -50%)",background:u&&A===m.pcb_component_id?"rgba(255, 0, 0, 0.2)":""}},m.pcb_component_id)})]})},t7e=(t,e)=>{const n=e.current;if(!n)return{transform:"translate(-50%, -100%)",left:t.x,top:t.y};const o=n.getBoundingClientRect(),i=200,r=10,s=60;let a="-50%",A="-100%",c=t.x,l=t.y;return t.x+s+i<o.width-r?(c=t.x+s,a="0%"):t.x-s-i>r?(c=t.x-s,a="-100%"):(c=t.x,a="-50%"),{transform:`translate(${a}, ${A})`,left:c,top:l}},vJo=({center:t})=>z.jsxs("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none",mixBlendMode:"difference",zIndex:Yg.errorOverlay+30},width:"100%",height:"100%",children:[z.jsx("circle",{cx:t.x,cy:t.y,r:11,fill:"none",stroke:"#ff6b6b",strokeWidth:2.5,opacity:.95}),z.jsx("circle",{cx:t.x,cy:t.y,r:4.5,fill:"#ff6b6b",opacity:.95}),z.jsx("line",{x1:t.x-18,y1:t.y,x2:t.x-8,y2:t.y,stroke:"#ff6b6b",strokeWidth:2}),z.jsx("line",{x1:t.x+8,y1:t.y,x2:t.x+18,y2:t.y,stroke:"#ff6b6b",strokeWidth:2}),z.jsx("line",{x1:t.x,y1:t.y-18,x2:t.x,y2:t.y-8,stroke:"#ff6b6b",strokeWidth:2}),z.jsx("line",{x1:t.x,y1:t.y+8,x2:t.x,y2:t.y+18,stroke:"#ff6b6b",strokeWidth:2})]}),tGt=({errorCenter:t,isHighlighted:e=!1})=>z.jsx("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none",mixBlendMode:"difference",zIndex:Yg.errorOverlay},width:"100%",height:"100%",children:z.jsx("rect",{x:t.x-7,y:t.y-7,width:14,height:14,transform:`rotate(45 ${t.x} ${t.y})`,fill:e?"#ff4444":"transparent",stroke:e?"#ff4444":"red",strokeWidth:e?2.5:1.5})}),n7e=iae`
|
|
5688
|
+
$1`).replace(/>(\s*)(?=<!--\s*\/)/g,"> ")}}});function CHt(t,e,n){if(!e||!n)return;let o=t.get(e);o||(o=new Set,t.set(e,o)),o.add(n);let i=t.get(n);i||(i=new Set,t.set(n,i)),i.add(e)}function fzo(t,e){if(!e.subcircuit_id&&!e.source_group_id)return[...t];let n=e;if(e.subcircuit_id){const a=new Set([e.subcircuit_id]),A=new Map,c=new Map;for(const g of t)if(g.type==="source_group"){const u=g.source_group_id,h=g.subcircuit_id;h&&c.set(u,h);const d=g.parent_source_group_id;d&&(A.has(d)||A.set(d,[]),A.get(d).push(u))}let l;for(const[g,u]of c)if(u===e.subcircuit_id){l=g;break}if(l){const g=u=>{const h=A.get(u)||[];for(const d of h){const _=c.get(d);_&&a.add(_),g(d)}};g(l),n={...e,subcircuit_ids:Array.from(a)}}}const o=new Map;for(const a of t){const A=`${a.type}_id`,c=a[A];typeof c=="string"&&o.set(c,a)}const i=new Map;for(const a of t){const A=Object.entries(a);for(const[c,l]of A)if(c!=="parent_source_group_id"){if(c.endsWith("_id")&&typeof l=="string"){const g=o.get(l);CHt(i,a,g)}else if(c.endsWith("_ids")&&Array.isArray(l)){for(const g of l)if(typeof g=="string"){const u=o.get(g);CHt(i,a,u)}}}}const r=[],s=new Set;for(const a of t){let A=!1;(n.subcircuit_id&&"subcircuit_id"in a&&a.subcircuit_id===n.subcircuit_id||n.subcircuit_ids&&"subcircuit_id"in a&&a.subcircuit_id&&n.subcircuit_ids.includes(a.subcircuit_id)||n.source_group_id&&"source_group_id"in a&&a.source_group_id===n.source_group_id||n.source_group_id&&"member_source_group_ids"in a&&Array.isArray(a.member_source_group_ids)&&a.member_source_group_ids.includes(n.source_group_id))&&(A=!0),A&&(r.push(a),s.add(a))}for(;r.length>0;){const a=r.shift(),A=i.get(a);if(A)for(const c of A)s.has(c)||(s.add(c),r.push(c))}return t.filter(a=>s.has(a))}var Aae=(t,e={})=>{const n=t;let o=n._internal_store;if(!o){o={counts:{},editCount:0},n._internal_store=o;for(const r of n){const s=r.type,a=r[`${s}_id`];if(!a)continue;const A=Number.parseInt(a.split("_").pop());Number.isNaN(A)||(o.counts[s]=Math.max(o.counts[s]??0,A))}}const i=new Proxy({},{get:(r,s)=>{if(s==="toArray")return()=>(n.editCount=o.editCount,n);if(s==="editCount")return o.editCount;if(s==="subtree")return A=>Aae(fzo(n,A),e);if(s==="insert")return A=>{const c=A.type;if(!c)throw new Error("insert requires an element with a type");o.counts[c]??=-1,o.counts[c]++;const l=o.counts[c],g={...A,type:c,[`${c}_id`]:`${c}_${l}`};return e.validateInserts&&(S9e[c]??Ose).parse(g),n.push(g),o.editCount++,g};if(s==="insertAll")return A=>A.map(c=>i.insert(c));const a=s;return{get:A=>n.find(c=>c.type===a&&c[`${a}_id`]===A),getUsing:A=>{const c=Object.keys(A);if(c.length!==1)throw new Error("getUsing requires exactly one key, e.g. { pcb_component_id }");const l=c[0],g=l.replace("_id",""),u=n.find(h=>h.type===g&&h[l]===A[l]);return u?n.find(h=>h.type===a&&h[`${a}_id`]===u[`${a}_id`]):null},getWhere:A=>{const c=Object.keys(A);return n.find(l=>l.type===a&&c.every(g=>l[g]===A[g]))},list:A=>{const c=A?Object.keys(A):[];return n.filter(l=>l.type===a&&c.every(g=>l[g]===A[g]))},insert:A=>{o.counts[a]??=-1,o.counts[a]++;const c=o.counts[a],l={type:a,[`${a}_id`]:`${a}_${c}`,...A};return e.validateInserts&&(S9e[a]??Ose).parse(l),n.push(l),o.editCount++,l},delete:A=>{const c=n.find(l=>l[`${a}_id`]===A);c&&(n.splice(n.indexOf(c),1),o.editCount++)},update:(A,c)=>{const l=n.find(g=>g.type===a&&g[`${a}_id`]===A);return l?(Object.assign(l,c),o.editCount++,l):null},select:A=>{if(a==="source_component")return n.find(c=>c.type==="source_component"&&c.name===A.replace(/\./g,""));if(a==="pcb_port"||a==="source_port"||a==="schematic_port"){const[c,l]=A.replace(/\./g,"").split(/[\s\>]+/),g=n.find(h=>h.type==="source_component"&&h.name===c);if(!g)return null;const u=n.find(h=>h.type==="source_port"&&h.source_component_id===g.source_component_id&&(h.name===l||(h.port_hints??[]).includes(l)));if(!u)return null;if(a==="source_port")return u;if(a==="pcb_port")return n.find(h=>h.type==="pcb_port"&&h.source_port_id===u.source_port_id);if(a==="schematic_port")return n.find(h=>h.type==="schematic_port"&&h.source_port_id===u.source_port_id)}}}}});return i};Aae.unparsed=Aae;var q6=Aae;function X9e(t){const e=t.type;return`${e}:${t[`${e}_id`]}`}var yHt=(t,e={})=>{let n=t._internal_store_indexed;if(!n){n={counts:{},editCount:0,indexes:{}};for(const s of t){const a=s.type,A=s[`${a}_id`];if(!A)continue;const c=Number.parseInt(A.split("_").pop()||"");Number.isNaN(c)||(n.counts[a]=Math.max(n.counts[a]??0,c))}const i=e.indexConfig||{},r=n.indexes;if(i.byId&&(r.byId=new Map),i.byType&&(r.byType=new Map),i.byRelation&&(r.byRelation=new Map),i.bySubcircuit&&(r.bySubcircuit=new Map),i.byCustomField&&i.byCustomField.length>0){r.byCustomField=new Map;for(const s of i.byCustomField)r.byCustomField.set(s,new Map)}for(const s of t){if(i.byId){const a=X9e(s);r.byId.set(a,s)}if(i.byType){const a=r.byType.get(s.type)||[];a.push(s),r.byType.set(s.type,a)}if(i.byRelation){const a=Object.entries(s);for(const[A,c]of a)if(A.endsWith("_id")&&A!==`${s.type}_id`&&typeof c=="string"){const l=r.byRelation.get(A)||new Map,g=l.get(c)||[];g.push(s),l.set(c,g),r.byRelation.set(A,l)}}if(i.bySubcircuit&&"subcircuit_id"in s){const a=s.subcircuit_id;if(a&&typeof a=="string"){const A=r.bySubcircuit.get(a)||[];A.push(s),r.bySubcircuit.set(a,A)}}if(i.byCustomField&&r.byCustomField){for(const a of i.byCustomField)if(a in s){const A=s[a];if(A!==void 0&&(typeof A=="string"||typeof A=="number")){const c=String(A),l=r.byCustomField.get(a),g=l.get(c)||[];g.push(s),l.set(c,g)}}}}t._internal_store_indexed=n}return new Proxy({},{get:(i,r)=>{if(r==="toArray")return()=>(t.editCount=n.editCount,t);if(r==="editCount")return n.editCount;const s=r;return{get:a=>{const A=e.indexConfig||{};return A.byId&&n.indexes.byId?n.indexes.byId.get(`${s}:${a}`)||null:A.byType&&n.indexes.byType?(n.indexes.byType.get(s)||[]).find(l=>l[`${s}_id`]===a)||null:t.find(c=>c.type===s&&c[`${s}_id`]===a)||null},getUsing:a=>{const A=e.indexConfig||{},c=Object.keys(a);if(c.length!==1)throw new Error("getUsing requires exactly one key, e.g. { pcb_component_id }");const l=c[0],g=l.replace("_id","");if(A.byRelation&&n.indexes.byRelation){const h=n.indexes.byRelation.get(l);if(h){const _=(h.get(a[l])||[]).find(p=>p.type===g);if(!_)return null;const m=_[`${s}_id`];return A.byId&&n.indexes.byId?n.indexes.byId.get(`${s}:${m}`)||null:A.byType&&n.indexes.byType?(n.indexes.byType.get(s)||[]).find(I=>I[`${s}_id`]===m)||null:t.find(p=>p.type===s&&p[`${s}_id`]===m)||null}}const u=t.find(h=>h.type===g&&h[l]===a[l]);return u&&t.find(h=>h.type===s&&h[`${s}_id`]===u[`${s}_id`])||null},getWhere:a=>{const A=e.indexConfig||{},c=Object.keys(a);if(c.length===1&&A.byCustomField&&n.indexes.byCustomField){const l=c[0],g=n.indexes.byCustomField.get(l);if(g){const u=String(a[l]);return(g.get(u)||[]).find(d=>d.type===s)||null}}if("subcircuit_id"in a&&A.bySubcircuit&&n.indexes.bySubcircuit){const l=a.subcircuit_id;return(n.indexes.bySubcircuit.get(l)||[]).find(u=>u.type===s&&c.every(h=>u[h]===a[h]))||null}return A.byType&&n.indexes.byType?(n.indexes.byType.get(s)||[]).find(g=>c.every(u=>g[u]===a[u]))||null:t.find(l=>l.type===s&&c.every(g=>l[g]===a[g]))||null},list:a=>{const A=e.indexConfig||{},c=a?Object.keys(a):[];if(c.length===0&&A.byType&&n.indexes.byType)return n.indexes.byType.get(s)||[];if(c.length===1&&c[0]==="subcircuit_id"&&A.bySubcircuit&&n.indexes.bySubcircuit){const g=a.subcircuit_id;return(n.indexes.bySubcircuit.get(g)||[]).filter(h=>h.type===s)}let l;return A.byType&&n.indexes.byType?l=n.indexes.byType.get(s)||[]:l=t.filter(g=>g.type===s),c.length>0?l.filter(g=>c.every(u=>g[u]===a[u])):l},insert:a=>{n.counts[s]??=-1,n.counts[s]++;const A=n.counts[s],c={type:s,[`${s}_id`]:`${s}_${A}`,...a};e.validateInserts&&(S9e[s]??Ose).parse(c),t.push(c),n.editCount++;const l=e.indexConfig||{};if(l.byId&&n.indexes.byId){const g=X9e(c);n.indexes.byId.set(g,c)}if(l.byType&&n.indexes.byType){const g=n.indexes.byType.get(s)||[];g.push(c),n.indexes.byType.set(s,g)}if(l.byRelation&&n.indexes.byRelation){const g=Object.entries(c);for(const[u,h]of g)if(u.endsWith("_id")&&u!==`${c.type}_id`&&typeof h=="string"){const d=n.indexes.byRelation.get(u)||new Map,_=d.get(h)||[];_.push(c),d.set(h,_),n.indexes.byRelation.set(u,d)}}if(l.bySubcircuit&&n.indexes.bySubcircuit&&"subcircuit_id"in c){const g=c.subcircuit_id;if(g&&typeof g=="string"){const u=n.indexes.bySubcircuit.get(g)||[];u.push(c),n.indexes.bySubcircuit.set(g,u)}}if(l.byCustomField&&n.indexes.byCustomField){for(const g of l.byCustomField)if(g in c){const u=c[g];if(u!==void 0&&(typeof u=="string"||typeof u=="number")){const h=String(u),d=n.indexes.byCustomField.get(g),_=d.get(h)||[];_.push(c),d.set(h,_)}}}return c},delete:a=>{const A=e.indexConfig||{};let c;if(A.byId&&n.indexes.byId?c=n.indexes.byId.get(`${s}:${a}`):A.byType&&n.indexes.byType?c=(n.indexes.byType.get(s)||[]).find(u=>u[`${s}_id`]===a):c=t.find(g=>g[`${s}_id`]===a),!c)return;const l=t.indexOf(c);if(l>=0&&(t.splice(l,1),n.editCount++),A.byId&&n.indexes.byId){const g=X9e(c);n.indexes.byId.delete(g)}if(A.byType&&n.indexes.byType){const u=(n.indexes.byType.get(s)||[]).filter(h=>h[`${s}_id`]!==a);n.indexes.byType.set(s,u)}if(A.byRelation&&n.indexes.byRelation)for(const[g,u]of n.indexes.byRelation.entries())for(const[h,d]of u.entries()){const _=d.filter(m=>m!==c);_.length===0?u.delete(h):u.set(h,_)}if(A.bySubcircuit&&n.indexes.bySubcircuit&&"subcircuit_id"in c){const g=c.subcircuit_id;if(g){const h=(n.indexes.bySubcircuit.get(g)||[]).filter(d=>d!==c);h.length===0?n.indexes.bySubcircuit.delete(g):n.indexes.bySubcircuit.set(g,h)}}if(A.byCustomField&&n.indexes.byCustomField)for(const g of n.indexes.byCustomField.values())for(const[u,h]of g.entries()){const d=h.filter(_=>_!==c);d.length===0?g.delete(u):g.set(u,d)}},update:(a,A)=>{const c=e.indexConfig||{};let l;if(c.byId&&n.indexes.byId?l=n.indexes.byId.get(`${s}:${a}`):c.byType&&n.indexes.byType?l=(n.indexes.byType.get(s)||[]).find(u=>u[`${s}_id`]===a):l=t.find(g=>g.type===s&&g[`${s}_id`]===a),!l)return null;if(c.byRelation&&n.indexes.byRelation){const g=Object.entries(l);for(const[u,h]of g)if(u.endsWith("_id")&&u!==`${l.type}_id`&&typeof h=="string"&&u in A&&A[u]!==h){const d=n.indexes.byRelation.get(u);if(d){const m=(d.get(h)||[]).filter(p=>p!==l);m.length===0?d.delete(h):d.set(h,m)}}}if(c.bySubcircuit&&n.indexes.bySubcircuit&&"subcircuit_id"in l&&"subcircuit_id"in A){const g=l.subcircuit_id,u=A.subcircuit_id;if(g!==u){const d=(n.indexes.bySubcircuit.get(g)||[]).filter(_=>_!==l);d.length===0?n.indexes.bySubcircuit.delete(g):n.indexes.bySubcircuit.set(g,d)}}if(c.byCustomField&&n.indexes.byCustomField){for(const g of c.byCustomField)if(g in l&&g in A&&l[g]!==A[g]){const u=n.indexes.byCustomField.get(g);if(u){const h=String(l[g]),_=(u.get(h)||[]).filter(m=>m!==l);_.length===0?u.delete(h):u.set(h,_)}}}if(Object.assign(l,A),n.editCount++,c.byRelation&&n.indexes.byRelation){const g=Object.entries(l);for(const[u,h]of g)if(u.endsWith("_id")&&u!==`${l.type}_id`&&typeof h=="string"&&u in A){const d=n.indexes.byRelation.get(u)||new Map,_=d.get(h)||[];_.includes(l)||(_.push(l),d.set(h,_),n.indexes.byRelation.set(u,d))}}if(c.bySubcircuit&&n.indexes.bySubcircuit&&"subcircuit_id"in l&&"subcircuit_id"in A){const g=l.subcircuit_id;if(g&&typeof g=="string"){const u=n.indexes.bySubcircuit.get(g)||[];u.includes(l)||(u.push(l),n.indexes.bySubcircuit.set(g,u))}}if(c.byCustomField&&n.indexes.byCustomField){for(const g of c.byCustomField)if(g in l&&g in A){const u=l[g];if(u!==void 0&&(typeof u=="string"||typeof u=="number")){const h=String(u),d=n.indexes.byCustomField.get(g),_=d.get(h)||[];_.includes(l)||(_.push(l),d.set(h,_))}}}return l},select:a=>{if(s==="source_component")return t.find(A=>A.type==="source_component"&&A.name===a.replace(/\./g,""))||null;if(s==="pcb_port"||s==="source_port"||s==="schematic_port"){const[A,c]=a.replace(/\./g,"").split(/[\s\>]+/),l=t.find(u=>u.type==="source_component"&&u.name===A);if(!l)return null;const g=t.find(u=>u.type==="source_port"&&u.source_component_id===l.source_component_id&&(u.name===c||(u.port_hints??[]).includes(c)));if(!g)return null;if(s==="source_port")return g;if(s==="pcb_port")return t.find(u=>u.type==="pcb_port"&&u.source_port_id===g.source_port_id)||null;if(s==="schematic_port")return t.find(u=>u.type==="schematic_port"&&u.source_port_id===g.source_port_id)||null}return null}}}})};yHt.unparsed=yHt;var Czo=t=>{const e=t.type;return t[`${e}_id`]},EHt=(t,e)=>({minX:Math.min(t.minX,e.minX),minY:Math.min(t.minY,e.minY),maxX:Math.max(t.maxX,e.maxX),maxY:Math.max(t.maxY,e.maxY)}),cae=(t,e,n)=>{const o=n/2;return{minX:t-o,minY:e-o,maxX:t+o,maxY:e+o}},xHt=(t,e,n,o,i)=>{const r=n/2,s=o/2,a=i*Math.PI/180,A=Math.cos(a),c=Math.sin(a),l=[{x:-r,y:-s},{x:r,y:-s},{x:r,y:s},{x:-r,y:s}].map(g=>({x:t+g.x*A-g.y*c,y:e+g.x*c+g.y*A}));return{minX:Math.min(...l.map(g=>g.x)),minY:Math.min(...l.map(g=>g.y)),maxX:Math.max(...l.map(g=>g.x)),maxY:Math.max(...l.map(g=>g.y))}},$9e=t=>{let e=Number.POSITIVE_INFINITY,n=Number.POSITIVE_INFINITY,o=Number.NEGATIVE_INFINITY,i=Number.NEGATIVE_INFINITY;for(const r of t){if(!r.type.startsWith("pcb_"))continue;if(r.type==="pcb_smtpad"&&r.shape==="polygon"&&Array.isArray(r.points)){for(const g of r.points)e=Math.min(e,g.x),n=Math.min(n,g.y),o=Math.max(o,g.x),i=Math.max(i,g.y);continue}if(r.type==="pcb_hole"&&r.hole_shape==="circle"){const g=cae(r.x,r.y,r.hole_diameter);e=Math.min(e,g.minX),n=Math.min(n,g.minY),o=Math.max(o,g.maxX),i=Math.max(i,g.maxY);continue}if(r.type==="pcb_plated_hole"){let g;if("outer_diameter"in r&&typeof r.outer_diameter=="number"?g=cae(r.x,r.y,r.outer_diameter):"hole_diameter"in r&&typeof r.hole_diameter=="number"&&(g=cae(r.x,r.y,r.hole_diameter)),"rect_pad_width"in r&&typeof r.rect_pad_width=="number"&&"rect_pad_height"in r&&typeof r.rect_pad_height=="number"){const u=xHt(r.x,r.y,r.rect_pad_width,r.rect_pad_height,"rect_ccw_rotation"in r?r.rect_ccw_rotation??0:0);g=g?EHt(g,u):u}if("hole_diameter"in r&&typeof r.hole_diameter=="number"){const u=cae(r.x+("hole_offset_x"in r?r.hole_offset_x??0:0),r.y+("hole_offset_y"in r?r.hole_offset_y??0:0),r.hole_diameter);g=g?EHt(g,u):u}if(g){e=Math.min(e,g.minX),n=Math.min(n,g.minY),o=Math.max(o,g.maxX),i=Math.max(i,g.maxY);continue}}let s,a,A,c;"x"in r&&"y"in r&&(s=Number(r.x),a=Number(r.y)),"outer_diameter"in r&&(A=Number(r.outer_diameter),c=Number(r.outer_diameter)),"width"in r&&(A=Number(r.width)),"height"in r&&(c=Number(r.height)),"center"in r&&(s=r.center.x,a=r.center.y);const l=typeof r.rotation=="number"?r.rotation:0;if(s!==void 0&&a!==void 0){if(e=Math.min(e,s),n=Math.min(n,a),o=Math.max(o,s),i=Math.max(i,a),A!==void 0&&c!==void 0)if(l){const g=xHt(s,a,A,c,l);e=Math.min(e,g.minX),n=Math.min(n,g.minY),o=Math.max(o,g.maxX),i=Math.max(i,g.maxY)}else e=Math.min(e,s-A/2),n=Math.min(n,a-c/2),o=Math.max(o,s+A/2),i=Math.max(i,a+c/2);"radius"in r&&(e=Math.min(e,s-r.radius),n=Math.min(n,a-r.radius),o=Math.max(o,s+r.radius),i=Math.max(i,a+r.radius))}else if(r.type==="pcb_trace")for(const g of r.route)e=Math.min(e,g.x),n=Math.min(n,g.y),o=Math.max(o,g.x),i=Math.max(i,g.y);else if(r.type==="pcb_courtyard_outline")for(const g of r.outline)e=Math.min(e,g.x),n=Math.min(n,g.y),o=Math.max(o,g.x),i=Math.max(i,g.y);else if(r.type==="pcb_courtyard_polygon")for(const g of r.points)e=Math.min(e,g.x),n=Math.min(n,g.y),o=Math.max(o,g.x),i=Math.max(i,g.y)}return{minX:e,minY:n,maxX:o,maxY:i}};function yzo(t){let e=0;if(t.length==0)return e;for(var n=0;n<t.length;n++){var o=t.charCodeAt(n);e=(e<<5)-e+o,e=e&e}return Math.abs(e)}var BHt=[["#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"]],Ezo=t=>{let{x:e,y:n,width:o,height:i}={...t,...t.size,...t.center,...t.position};if(t.x1!==void 0&&t.x2!==void 0&&t.y1!==void 0&&t.y2!==void 0&&(e=(t.x1+t.x2)/2,n=(t.y1+t.y2)/2,o=Math.abs(t.x1-t.x2),i=Math.abs(t.y1-t.y2)),t.points&&Array.isArray(t.points)&&t.points.length>0){const a=t.points.map(h=>h.x),A=t.points.map(h=>h.y),c=Math.min(...a),l=Math.max(...a),g=Math.min(...A),u=Math.max(...A);e=(c+l)/2,n=(g+u)/2,o=l-c,i=u-g}const r=t.text||t.name||t.source?.text||t.source?.name||"?",s=t;return e===void 0||n===void 0?null:(o===void 0&&("outer_diameter"in t?(o=t.outer_diameter,i=t.outer_diameter):"rect_pad_width"in t&&"rect_pad_height"in t?(o=t.rect_pad_width,i=t.rect_pad_height,"hole_diameter"in t&&(o=Math.max(o,t.hole_diameter),i=Math.max(i,t.hole_diameter))):"hole_diameter"in t&&(o=t.hole_diameter,i=t.hole_diameter)),(o===void 0||i===void 0)&&(o=.1,i=.1),{x:e,y:n,width:o,height:i,title:r,content:s,bg_color:BHt[yzo(t.type||r)%BHt.length]?.[4]??"#f00"})},xzo=t=>!!t,Bzo=t=>{const e=t.filter(c=>c.type.startsWith("pcb_")||c.type.startsWith("schematic_")).concat(t.filter(c=>c.type==="pcb_trace"||c.type==="schematic_trace").flatMap(c=>c.route)).map(c=>Ezo(c)).filter(xzo);if(e.length===0)return{center:{x:0,y:0},width:0,height:0};let n=e[0].x-e[0].width/2,o=e[0].x+e[0].width/2,i=e[0].y-e[0].height/2,r=e[0].y+e[0].height/2;for(const c of e.slice(1))n=Math.min(n,c.x-c.width/2),o=Math.max(o,c.x+c.width/2),i=Math.min(i,c.y-c.height/2),r=Math.max(r,c.y+c.height/2);const s=o-n,a=r-i;return{center:{x:n+s/2,y:i+a/2},width:s,height:a}},Mp={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_PCB_NOTES:"pcb_viewer_is_showing_pcb_notes",IS_SHOWING_SILKSCREEN:"pcb_viewer_is_showing_silkscreen"},$P=(t,e)=>{if(typeof window>"u")return e;try{const n=localStorage.getItem(t);return n!==null?JSON.parse(n):e}catch{return e}},ZP=(t,e)=>{if(!(typeof window>"u"))try{localStorage.setItem(t,JSON.stringify(e))}catch{}},Qzo=(t,e)=>{if(typeof window>"u")return e;try{const n=localStorage.getItem(t);return n!==null?JSON.parse(n):e}catch{return e}},Szo=(t,e)=>{if(!(typeof window>"u"))try{localStorage.setItem(t,JSON.stringify(e))}catch{}},bzo="named_only",Dzo=(t={},e=!1)=>Ypt(n=>({selected_layer:"top",pcb_viewer_id:`pcb_viewer_${Math.random().toString().slice(2,10)}`,in_edit_mode:!1,in_move_footprint_mode:!1,is_moving_component:!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:$P(Mp.IS_SHOWING_COPPER_POURS,!0),is_showing_courtyards:$P(Mp.IS_SHOWING_COURTYARDS,!0),is_showing_pcb_groups:e?!1:$P(Mp.IS_SHOWING_PCB_GROUPS,!0),is_showing_group_anchor_offsets:$P(Mp.IS_SHOWING_GROUP_ANCHOR_OFFSETS,!1),is_showing_solder_mask:$P(Mp.IS_SHOWING_SOLDER_MASK,!1),is_showing_silkscreen:$P(Mp.IS_SHOWING_SILKSCREEN,!0),is_showing_fabrication_notes:$P(Mp.IS_SHOWING_FABRICATION_NOTES,!1),is_showing_pcb_notes:$P(Mp.IS_SHOWING_PCB_NOTES,!0),pcb_group_view_mode:e?"all":Qzo(Mp.PCB_GROUP_VIEW_MODE,bzo),hovered_error_id:null,focused_error_id:null,...t,selectLayer:o=>n({selected_layer:o}),setEditMode:o=>n({in_edit_mode:o!=="off",in_move_footprint_mode:o==="move_footprint",is_moving_component:!1}),setIsShowingRatsNest:o=>n({is_showing_rats_nest:o}),setIsMovingComponent:o=>n({is_moving_component:o}),setIsMouseOverContainer:o=>n({is_mouse_over_container:o}),setIsShowingMultipleTracesLength:o=>n({is_showing_multiple_traces_length:o}),setIsShowingAutorouting:o=>n({is_showing_autorouting:o}),setIsShowingDrcErrors:o=>n({is_showing_drc_errors:o}),setIsShowingCopperPours:o=>{ZP(Mp.IS_SHOWING_COPPER_POURS,o),n({is_showing_copper_pours:o})},setIsShowingCourtyards:o=>{ZP(Mp.IS_SHOWING_COURTYARDS,o),n({is_showing_courtyards:o})},setIsShowingPcbGroups:o=>{e||(ZP(Mp.IS_SHOWING_PCB_GROUPS,o),n({is_showing_pcb_groups:o}))},setIsShowingGroupAnchorOffsets:o=>{ZP(Mp.IS_SHOWING_GROUP_ANCHOR_OFFSETS,o),n({is_showing_group_anchor_offsets:o})},setIsShowingSolderMask:o=>{ZP(Mp.IS_SHOWING_SOLDER_MASK,o),n({is_showing_solder_mask:o})},setIsShowingSilkscreen:o=>{ZP(Mp.IS_SHOWING_SILKSCREEN,o),n({is_showing_silkscreen:o})},setIsShowingFabricationNotes:o=>{ZP(Mp.IS_SHOWING_FABRICATION_NOTES,o),n({is_showing_fabrication_notes:o})},setIsShowingPcbNotes:o=>{ZP(Mp.IS_SHOWING_PCB_NOTES,o),n({is_showing_pcb_notes:o})},setPcbGroupViewMode:o=>{e||(Szo(Mp.PCB_GROUP_VIEW_MODE,o),n({pcb_group_view_mode:o}))},setHoveredErrorId:o=>n({hovered_error_id:o}),setFocusedErrorId:o=>n({focused_error_id:o})})),yd=t=>{const e=X.useContext(QHt);return eIt(e,t)},QHt=X.createContext(null),vzo=({children:t,initialState:e,disablePcbGroups:n})=>{const o=X.useMemo(()=>Dzo(e,n),[n]);return z.jsx(QHt.Provider,{value:o,children:t})},Pzo=()=>{X.useEffect(()=>{ZUo()},[]);const t=yd(e=>e.pcb_viewer_id);return z.jsx($Uo,{position:"top-center",containerId:t})};function wzo(){var t=X.useRef(!1),e=X.useCallback(function(){return t.current},[]);return X.useEffect(function(){return t.current=!0,function(){t.current=!1}},[]),e}var Mzo=function(t){t===void 0&&(t={});var e=X.useState(t),n=e[0],o=e[1],i=X.useCallback(function(r){o(function(s){return Object.assign({},s,r instanceof Function?r(s):r)})},[]);return[n,i]},Nzo=Mzo,Rzo=function(){},SHt=typeof window<"u",Tzo=V9e(tzo()),kzo=function(){var t=wzo(),e=Nzo({value:void 0,error:void 0,noUserInteraction:!0}),n=e[0],o=e[1],i=X.useCallback(function(r){if(t()){var s,a;try{if(typeof r!="string"&&typeof r!="number"){var A=new Error("Cannot copy typeof "+typeof r+" to clipboard, must be a string");console.error(A),o({value:r,error:A,noUserInteraction:!0});return}else if(r===""){var A=new Error("Cannot copy empty string to clipboard.");console.error(A),o({value:r,error:A,noUserInteraction:!0});return}a=r.toString(),s=(0,Tzo.default)(a),o({value:a,error:void 0,noUserInteraction:s})}catch(c){o({value:a,error:c,noUserInteraction:s})}}},[]);return[n,i]},Fzo=kzo,Lzo=SHt?X.useLayoutEffect:X.useEffect,Hzo=Lzo,bHt={x:0,y:0,width:0,height:0,top:0,left:0,bottom:0,right:0};function Gzo(){var t=X.useState(null),e=t[0],n=t[1],o=X.useState(bHt),i=o[0],r=o[1],s=X.useMemo(function(){return new window.ResizeObserver(function(a){if(a[0]){var A=a[0].contentRect,c=A.x,l=A.y,g=A.width,u=A.height,h=A.top,d=A.left,_=A.bottom,m=A.right;r({x:c,y:l,width:g,height:u,top:h,left:d,bottom:_,right:m})}})},[]);return Hzo(function(){if(e)return s.observe(e),function(){s.disconnect()}},[e]),[n,i]}var GY=SHt&&typeof window.ResizeObserver<"u"?Gzo:function(){return[Rzo,bHt]},DHt=({initialTransform:t,initialTouch1:e,initialTouch2:n,finalTouch1:o,finalTouch2:i})=>{if(!o||!i)return t;const r={x:(e.x+n.x)/2,y:(e.y+n.y)/2},s={x:(o.x+i.x)/2,y:(o.y+i.y)/2},a=Math.hypot(n.x-e.x,n.y-e.y),A=Math.hypot(i.x-o.x,i.y-o.y),c=a===0?1:A/a,l=s.x-r.x,g=s.y-r.y;return Fi(ji(l,g),ji(r.x,r.y),gg(c,c),ji(-r.x,-r.y),t)},Ozo=(t={})=>{const e=X.useRef(null),[n,o]=X.useState(0),i=t.canvasElm??e.current,[r,s]=X.useState(t.initialTransform??Hl()),[a,A]=X.useState(0),[c,l]=X.useReducer(f=>f+1,0),g=X.useCallback(f=>{t.onSetTransform&&t.onSetTransform(f),t.transform||s(f)},[t.onSetTransform,s]),u=X.useCallback(f=>{g(f),l()},[g]),h=t.transform??r,d=X.useCallback(()=>{o(Date.now())},[]),_=X.useRef("none"),m=X.useRef(null),p=X.useRef(null);X.useEffect(()=>{const f=t.canvasElm??e.current;if(f&&!i){A(a+1);return}if(!f){const W=setTimeout(()=>{A(a+1)},100);return()=>clearTimeout(W)}let C=t.transform??r,y={x:0,y:0},E={x:0,y:0},B=!1;const Q=W=>({x:W.pageX-f.getBoundingClientRect().left-window.scrollX,y:W.pageY-f.getBoundingClientRect().top-window.scrollY});function b(W){t.enabled!==!1&&(t.shouldDrag&&!t.shouldDrag(W)||(y=Q(W),!(Date.now()-n<100)&&(B=!0,W.preventDefault())))}function D(W){if(!B||t.enabled===!1||t.shouldDrag&&!t.shouldDrag(W))return;E=Q(W);const j=Fi(ji(E.x-y.x,E.y-y.y),C);g(j),C=j,B=!1}function R(W){if(Q(W),!B||t.enabled===!1||t.shouldDrag&&!t.shouldDrag(W))return;E=Q(W);const j=Fi(ji(E.x-y.x,E.y-y.y),C);g(j)}function M(W){if(t.enabled===!1||t.shouldDrag&&!t.shouldDrag(W))return;const j=Q(W),te=Fi(ji(j.x,j.y),gg(1-W.deltaY/1e3,1-W.deltaY/1e3),ji(-j.x,-j.y),C);g(te),C=te,W.preventDefault()}function L(W){if(!B||t.shouldDrag&&!t.shouldDrag(W))return;if(f){const te=f.getBoundingClientRect();if(W.clientX>=te.left+10&&W.clientX<=te.right-10&&W.clientY>=te.top+10&&W.clientY<=te.bottom-10)return}B=!1,E=Q(W);const j=Fi(ji(E.x-y.x,E.y-y.y),C);g(j),C=j}function G(W){if(W.preventDefault(),t.enabled!==!1){if(W.touches.length===1){_.current="drag";const j=W.touches[0];m.current={initialTransform:C,initialTouch:{x:j.clientX,y:j.clientY}}}else if(W.touches.length===2){_.current="pinch";const j=W.touches[0],te=W.touches[1];p.current={initialTransform:C,initialTouch1:{x:j.clientX,y:j.clientY},initialTouch2:{x:te.clientX,y:te.clientY},finalTouch1:null,finalTouch2:null}}}}function O(W){if(W.preventDefault(),t.enabled!==!1){if(_.current==="drag"&&W.touches.length===1&&m.current){const j=W.touches[0],te={x:j.clientX,y:j.clientY},ie=te.x-m.current.initialTouch.x,$=te.y-m.current.initialTouch.y,Z=Fi(ji(ie,$),m.current.initialTransform);g(Z)}else if(_.current==="pinch"&&W.touches.length===2&&p.current){const j=W.touches[0],te=W.touches[1];p.current.finalTouch1={x:j.clientX,y:j.clientY},p.current.finalTouch2={x:te.clientX,y:te.clientY};const ie=DHt(p.current);g(ie)}}}function U(W){W.preventDefault();const j=W.changedTouches[0];if(_.current==="drag"&&m.current&&j){const te={x:j.clientX,y:j.clientY},ie=te.x-m.current.initialTouch.x,$=te.y-m.current.initialTouch.y,Z=Fi(ji(ie,$),m.current.initialTransform);g(Z),C=Z}else if(_.current==="pinch"&&p.current){const te=DHt(p.current);g(te),C=te}_.current="none",m.current=null,p.current=null}return f.addEventListener("mousedown",b),f.addEventListener("mouseup",D),window.addEventListener("mousemove",R),f.addEventListener("mouseout",L),f.addEventListener("wheel",M),f.addEventListener("touchstart",G,{passive:!1}),f.addEventListener("touchmove",O,{passive:!1}),f.addEventListener("touchend",U,{passive:!1}),f.addEventListener("touchcancel",U,{passive:!1}),()=>{f.removeEventListener("mousedown",b),f.removeEventListener("mouseup",D),window.removeEventListener("mousemove",R),f.removeEventListener("mouseout",L),f.removeEventListener("wheel",M),f.removeEventListener("touchstart",G),f.removeEventListener("touchmove",O),f.removeEventListener("touchend",U),f.removeEventListener("touchcancel",U)}},[i,a,c,n,t.enabled,t.shouldDrag]);const I=X.useCallback(f=>mt(h,f),[h]);return{ref:e,transform:h,applyTransformToPoint:I,setTransform:u,cancelDrag:d}},Kzo=Ozo;function Uzo(t){const e=new Map;let n=0;function o(i){for(const[,s]of e)if(s.has(i))return s;const r=new Set;return e.set(`connectivity_net${n++}`,r),r}for(const i of t){let r=null;for(const s of i){if(!r)r=o(s);else if(!r.has(s)){const a=o(s);if(a!==r){for(const A of a)r.add(A);e.delete(Array.from(e.entries()).find(([,A])=>A===a)[0])}}r.add(s)}}return Object.fromEntries(Array.from(e.entries()).map(([i,r])=>[i,Array.from(r)]))}var Yzo=class{netMap;idToNetMap;constructor(t){this.netMap=t,this.idToNetMap={};for(const[e,n]of Object.entries(t))for(const o of n)this.idToNetMap[o]=e}addConnections(t){for(const e of t){const n=new Set;for(const i of e){const r=this.idToNetMap[i];r&&n.add(r)}let o;if(n.size===0)o=`connectivity_net${Object.keys(this.netMap).length}`,this.netMap[o]=[];else if(n.size===1)o=n.values().next().value??`connectivity_net${Object.keys(this.netMap).length}`;else{o=n.values().next().value??`connectivity_net${Object.keys(this.netMap).length}`;for(const i of n)if(i!==o){this.netMap[o].push(...this.netMap[i]),this.netMap[i]=this.netMap[o];for(const r of this.netMap[o])this.idToNetMap[r]=o}}for(const i of e)this.netMap[o].includes(i)||this.netMap[o].push(i),this.idToNetMap[i]=o}}getIdsConnectedToNet(t){return this.netMap[t]||[]}getNetConnectedToId(t){return this.idToNetMap[t]}areIdsConnected(t,e){if(t===e)return!0;const n=this.getNetConnectedToId(t);if(!n)return!1;const o=this.getNetConnectedToId(e);return o?n===o||o===t||o===t:!1}areAllIdsConnected(t){const e=this.getNetConnectedToId(t[0]);for(const n of t){const o=this.getNetConnectedToId(n);if(o===void 0||o!==e)return!1}return!0}},vHt=t=>{const e=[];for(const o of t)if(o.type==="source_trace")e.push([o.source_trace_id,...o.connected_source_port_ids??[],...o.connected_source_net_ids??[]].filter(Boolean));else if(o.type==="pcb_port"){const{pcb_port_id:i,source_port_id:r}=o;r&&i&&e.push([r,i])}else if(o.type==="pcb_smtpad"){const{pcb_smtpad_id:i,pcb_port_id:r}=o;r&&i&&e.push([i,r])}else if(o.type==="pcb_plated_hole"){const{pcb_plated_hole_id:i,pcb_port_id:r}=o;r&&i&&e.push([i,r])}else if(o.type==="pcb_trace"){const{pcb_trace_id:i,source_trace_id:r}=o,s=Array.isArray(o.route)?o.route.filter(a=>a&&a.route_type==="wire"):[];if(r&&i&&e.push([i,r]),Array.isArray(s)){const a=s.find(c=>c?.start_pcb_port_id)?.start_pcb_port_id,A=s.find(c=>c?.end_pcb_port_id)?.end_pcb_port_id;a&&i&&A&&e.push([a,i,A])}}else if(o.type==="pcb_via"){const{pcb_via_id:i,pcb_trace_id:r}=o;r&&i&&e.push([i,r])}else if(o.type==="source_component"&&o.internally_connected_source_port_ids)for(const i of o.internally_connected_source_port_ids)e.push(i);const n=Uzo(e);return new Yzo(n)};function zzo(t,e){if(t.length<2)throw new Error("Stroke must have at least two points");const n=t.map(g=>Array.isArray(g)?{x:g[0],y:g[1]}:g),o=[],i=[];function r(g,u){const h=u.x-g.x,d=u.y-g.y,_=Math.sqrt(h*h+d*d);return{x:-d/_,y:h/_}}function s(g,u,h,d){const _=d/2,m={x:g.x+u.x*_*h,y:g.y+u.y*_*h};h>0?o.push(m):i.unshift(m)}const a=r(n[0],n[1]),A=n[0].trace_width??e;s(n[0],a,1,A),s(n[0],a,-1,A);for(let g=1;g<n.length-1;g++){const u=n[g-1],h=n[g],d=n[g+1],_=r(u,h),m=r(h,d),p=_.x+m.x,I=_.y+m.y,f=Math.sqrt(p*p+I*I),C=h.trace_width??e;if(f/2>2*(C/2))s(h,_,1,C),s(h,m,1,C),s(h,_,-1,C),s(h,m,-1,C);else{const E=1/f;s(h,{x:p*E,y:I*E},1,C),s(h,{x:p*E,y:I*E},-1,C)}}const c=r(n[n.length-2],n[n.length-1]),l=n[n.length-1].trace_width??e;return s(n[n.length-1],c,1,l),s(n[n.length-1],c,-1,l),[...o,...i]}var Vzo=(t,e)=>{const{x:n,y:o,width:i,height:r,layer:s,rect_border_radius:a}=t,A=t.corner_radius??a??0,c=[{_pcb_drawing_object_id:tQ("rect"),pcb_drawing_type:"rect",x:n,y:o,w:i,h:r,layer:s||"top",_element:t,_parent_pcb_component:e._parent_pcb_component,_parent_source_component:e._parent_source_component,_source_port:e._source_port,roundness:A,...t.shape==="rotated_rect"&&t.ccw_rotation!==void 0?{ccw_rotation:t.ccw_rotation}:{}}];if(t.is_covered_with_solder_mask){const l=s==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",u={...{_pcb_drawing_object_id:tQ("rect"),pcb_drawing_type:"rect",x:n,y:o,w:i,h:r,layer:l,_element:t,_parent_pcb_component:e._parent_pcb_component,_parent_source_component:e._parent_source_component,_source_port:e._source_port,roundness:A,...t.shape==="rotated_rect"&&t.ccw_rotation!==void 0?{ccw_rotation:t.ccw_rotation}:{}},..."solder_mask_color"in t&&t.solder_mask_color?{color:t.solder_mask_color}:{}};c.push(u)}return c},Jzo=(t,e)=>{const{x:n,y:o,radius:i,layer:r}=t,s=[{_pcb_drawing_object_id:tQ("circle"),pcb_drawing_type:"circle",x:n,y:o,r:i,layer:r||"top",_element:t,_parent_pcb_component:e._parent_pcb_component,_parent_source_component:e._parent_source_component,_source_port:e._source_port}];if(t.is_covered_with_solder_mask){const a=r==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",A={_pcb_drawing_object_id:tQ("circle"),pcb_drawing_type:"circle",x:n,y:o,r:i,layer:a,_element:t,_parent_pcb_component:e._parent_pcb_component,_parent_source_component:e._parent_source_component,_source_port:e._source_port,..."solder_mask_color"in t&&t.solder_mask_color?{color:t.solder_mask_color}:{}};s.push(A)}return s},qzo=(t,e)=>{const{layer:n,points:o}=t,i=[{_pcb_drawing_object_id:tQ("polygon"),pcb_drawing_type:"polygon",points:Z9e(o),layer:n||"top",_element:t,_parent_pcb_component:e._parent_pcb_component,_parent_source_component:e._parent_source_component,_source_port:e._source_port}];if(t.is_covered_with_solder_mask){const r=n==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",s={_pcb_drawing_object_id:tQ("polygon"),pcb_drawing_type:"polygon",points:Z9e(o),layer:r,_element:t,_parent_pcb_component:e._parent_pcb_component,_parent_source_component:e._parent_source_component,_source_port:e._source_port,..."solder_mask_color"in t&&t.solder_mask_color?{color:t.solder_mask_color}:{}};i.push(s)}return i},Wzo=(t,e)=>{const{x:n,y:o,width:i,height:r,layer:s}=t,a=[{_pcb_drawing_object_id:tQ("pill"),pcb_drawing_type:"pill",x:n,y:o,w:i,h:r,layer:s||"top",_element:t,_parent_pcb_component:e._parent_pcb_component,_parent_source_component:e._parent_source_component,_source_port:e._source_port}];if(t.is_covered_with_solder_mask){const A=s==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",c={_pcb_drawing_object_id:tQ("pill"),pcb_drawing_type:"pill",x:n,y:o,w:i,h:r,layer:A,_element:t,_parent_pcb_component:e._parent_pcb_component,_parent_source_component:e._parent_source_component,_source_port:e._source_port,..."solder_mask_color"in t&&t.solder_mask_color?{color:t.solder_mask_color}:{}};a.push(c)}return a},jzo=(t,e)=>{const{x:n,y:o,width:i,height:r,layer:s,ccw_rotation:a}=t,A=[{_pcb_drawing_object_id:tQ("pill"),pcb_drawing_type:"pill",x:n,y:o,w:i,h:r,layer:s||"top",_element:t,_parent_pcb_component:e._parent_pcb_component,_parent_source_component:e._parent_source_component,_source_port:e._source_port,ccw_rotation:a}];if(t.is_covered_with_solder_mask){const c=s==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",l={_pcb_drawing_object_id:tQ("pill"),pcb_drawing_type:"pill",x:n,y:o,w:i,h:r,layer:c,_element:t,_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 t&&t.solder_mask_color?{color:t.solder_mask_color}:{}};A.push(l)}return A},s0=0,tQ=t=>`${t}_${s0++}`,Z9e=t=>(t??[]).map(e=>({x:En.parse(e.x),y:En.parse(e.y)})),Xzo=(t,e)=>{const n="pcb_component_id"in t?e.find(s=>s.type==="pcb_component"&&s.pcb_component_id===t.pcb_component_id):void 0,o=n&&"source_component_id"in n?e.find(s=>s.type==="source_component"&&s.source_component_id===n.source_component_id):void 0,i="source_port_id"in t?t.source_port_id:"pcb_port_id"in t?q6(e).pcb_port.get(t.pcb_port_id)?.source_port_id:void 0,r=i?e.find(s=>s.type==="source_port"&&s.source_port_id===i):void 0;switch(t.type){case"pcb_smtpad":{const s={_parent_pcb_component:n,_parent_source_component:o,_source_port:r};return t.shape==="rect"||t.shape==="rotated_rect"?Vzo(t,s):t.shape==="circle"?Jzo(t,s):t.shape==="polygon"?qzo(t,s):t.shape==="pill"?Wzo(t,s):t.shape==="rotated_pill"?jzo(t,s):[]}case"pcb_trace":{const s=[];if(t.route_thickness_mode==="interpolated"){const c=t.route.flatMap(u=>u.route_type==="through_pad"?[{...u.start,trace_width:u.width},{...u.end,trace_width:u.width}]:[{x:u.x,y:u.y,trace_width:u.route_type==="wire"?u.width:.5}]),l=zzo(c,.5),g=t.route[0].layer;return s.push({_pcb_drawing_object_id:`polygon_${s0++}`,_element:t,pcb_drawing_type:"polygon",points:l,layer:g}),t.route.forEach(u=>{u.route_type==="via"&&s.push({_pcb_drawing_object_id:`circle_${s0++}`,_element:t,pcb_drawing_type:"circle",x:u.x,y:u.y,r:u.outer_diameter/2,layer:u.from_layer})}),s}let a=null,A=null;for(const c of t.route)c.route_type==="wire"&&(a!==null&&A!==null&&s.push({_pcb_drawing_object_id:`line_${s0++}`,_element:t,pcb_drawing_type:"line",x1:a,y1:A,x2:c.x,y2:c.y,width:c.width,squareCap:!1,layer:c.layer}),a=c.x,A=c.y);return s}case"pcb_via":{const{x:s,y:a,outer_diameter:A,hole_diameter:c}=t,l=t.from_layer,g=t.to_layer,u=t.layers,h=[];l&&g?h.push(l,g):u&&Array.isArray(u)?h.push(...u):h.push("top","bottom");const d=[];for(const _ of h)d.push({_pcb_drawing_object_id:`circle_${s0++}`,pcb_drawing_type:"circle",x:s,y:a,r:A/2,layer:_,_element:t,_parent_pcb_component:n,_parent_source_component:o});return d.push({_pcb_drawing_object_id:`circle_${s0++}`,pcb_drawing_type:"circle",x:s,y:a,r:c/2,layer:"drill",_element:t}),d}case"pcb_plated_hole":if(t.shape==="circle"){const{x:s,y:a,hole_diameter:A,outer_diameter:c}=t;return[{_pcb_drawing_object_id:`circle_${s0++}`,pcb_drawing_type:"circle",x:s,y:a,r:c/2,layer:"top",_element:t,_parent_pcb_component:n,_parent_source_component:o,_source_port:r},{_pcb_drawing_object_id:`circle_${s0++}`,pcb_drawing_type:"circle",x:s,y:a,r:A/2,layer:"drill",_element:t}]}else if(t.shape==="oval"){const{x:s,y:a,outer_height:A,outer_width:c,hole_height:l,hole_width:g}=t;return[{_pcb_drawing_object_id:`oval_${s0++}`,pcb_drawing_type:"oval",x:s,y:a,rX:c/2,rY:A/2,layer:"top",_element:t,_parent_pcb_component:n,_parent_source_component:o,_source_port:r},{_pcb_drawing_object_id:`oval_${s0++}`,_element:t,pcb_drawing_type:"oval",x:s,y:a,rX:g/2,rY:l/2,layer:"drill"}]}else if(t.shape==="pill"){const{x:s,y:a,outer_height:A,outer_width:c,hole_height:l,hole_width:g}=t;return[{_pcb_drawing_object_id:`pill_${s0++}`,pcb_drawing_type:"pill",x:s,y:a,w:c,h:A,layer:"top",_element:t,_parent_pcb_component:n,_parent_source_component:o,_source_port:r,ccw_rotation:t.ccw_rotation},{_pcb_drawing_object_id:`pill_${s0++}`,_element:t,pcb_drawing_type:"pill",x:s,y:a,w:g,h:l,layer:"drill",ccw_rotation:t.ccw_rotation}]}else if(t.shape==="circular_hole_with_rect_pad"){const{x:s,y:a,hole_diameter:A,rect_pad_width:c,rect_pad_height:l,rect_border_radius:g,hole_offset_x:u,hole_offset_y:h}=t,d=En.parse(u??0),_=En.parse(h??0);return[{_pcb_drawing_object_id:`rect_${s0++}`,pcb_drawing_type:"rect",x:s,y:a,w:c,h:l,layer:"top",_element:t,_parent_pcb_component:n,_parent_source_component:o,_source_port:r,roundness:g},{_pcb_drawing_object_id:`rect_${s0++}`,pcb_drawing_type:"rect",x:s,y:a,w:c,h:l,layer:"bottom",_element:t,_parent_pcb_component:n,_parent_source_component:o,_source_port:r,roundness:g,is_hoverable:!1},{_pcb_drawing_object_id:`circle_${s0++}`,_element:t,pcb_drawing_type:"circle",x:s+d,y:a+_,r:A/2,layer:"drill",is_hoverable:!1}]}else if(t.shape==="pill_hole_with_rect_pad"){const{x:s,y:a,hole_width:A,hole_height:c,rect_pad_width:l,rect_pad_height:g,rect_border_radius:u}=t;return[{_pcb_drawing_object_id:`rect_${s0++}`,pcb_drawing_type:"rect",x:s,y:a,w:l,h:g,layer:"top",_element:t,_parent_pcb_component:n,_parent_source_component:o,_source_port:r,roundness:u},{_pcb_drawing_object_id:`rect_${s0++}`,pcb_drawing_type:"rect",x:s,y:a,w:l,h:g,layer:"bottom",_element:t,_parent_pcb_component:n,_parent_source_component:o,_source_port:r,roundness:u,is_hoverable:!1},{_pcb_drawing_object_id:`pill_${s0++}`,_element:t,pcb_drawing_type:"pill",x:s,y:a,w:A,h:c,layer:"drill",is_hoverable:!1}]}else if(t.shape==="rotated_pill_hole_with_rect_pad"){const{x:s,y:a,hole_width:A,hole_height:c,hole_ccw_rotation:l,rect_pad_width:g,rect_pad_height:u,rect_ccw_rotation:h,rect_border_radius:d}=t;return[{_pcb_drawing_object_id:`rect_${s0++}`,pcb_drawing_type:"rect",x:s,y:a,w:g,h:u,layer:"top",_element:t,_parent_pcb_component:n,_parent_source_component:o,_source_port:r,ccw_rotation:h,roundness:d},{_pcb_drawing_object_id:`rect_${s0++}`,pcb_drawing_type:"rect",x:s,y:a,w:g,h:u,layer:"bottom",_element:t,_parent_pcb_component:n,_parent_source_component:o,_source_port:r,ccw_rotation:h,roundness:d,is_hoverable:!1},{_pcb_drawing_object_id:`pill_${s0++}`,_element:t,pcb_drawing_type:"pill",x:s,y:a,w:A,h:c,layer:"drill",ccw_rotation:l,is_hoverable:!1}]}else if(t.shape==="hole_with_polygon_pad"){const{x:s,y:a,pad_outline:A,hole_shape:c,hole_diameter:l,hole_width:g,hole_height:u,layers:h,hole_offset_x:d,hole_offset_y:_}=t,m=En.parse(d??0),p=En.parse(_??0),I=A,f=[];if(I&&Array.isArray(I)){const E=Z9e(I).map(B=>({x:B.x+s,y:B.y+a}));for(const B of h||["top","bottom"])f.push({_pcb_drawing_object_id:`polygon_${s0++}`,pcb_drawing_type:"polygon",points:E,layer:B,_element:t,_parent_pcb_component:n,_parent_source_component:o,_source_port:r})}const C={x:s+m,y:a+p},y=[];return c==="circle"?y.push({_pcb_drawing_object_id:`circle_${s0++}`,pcb_drawing_type:"circle",x:C.x,y:C.y,r:(l??0)/2,layer:"drill",_element:t,_parent_pcb_component:n,_parent_source_component:o}):c==="oval"?y.push({_pcb_drawing_object_id:`oval_${s0++}`,pcb_drawing_type:"oval",x:C.x,y:C.y,rX:(g??0)/2,rY:(u??0)/2,layer:"drill",_element:t,_parent_pcb_component:n,_parent_source_component:o}):(c==="pill"||c==="rotated_pill")&&y.push({_pcb_drawing_object_id:`pill_${s0++}`,pcb_drawing_type:"pill",x:C.x,y:C.y,w:g??0,h:u??0,layer:"drill",_element:t,_parent_pcb_component:n,_parent_source_component:o,ccw_rotation:t.ccw_rotation}),[...f,...y]}else return[]}return[]};function $zo({primitivesWithoutInteractionMetadata:t,drawingObjectIdsWithMouseOver:e,primitiveIdsInMousedOverNet:n}){const o=[];for(const i of t){const r={...i},s=i._element,a=i._parent_pcb_component;i?.layer==="drill"?(r.is_in_highlighted_net=!1,r.is_mouse_over=!1):e.has(i._pcb_drawing_object_id)?r.is_mouse_over=!0:s&&("pcb_trace_id"in s&&n.includes(s.pcb_trace_id)||"pcb_port_id"in s&&n.includes(s.pcb_port_id)||"pcb_via_id"in s&&n.includes(s.pcb_via_id)||"pcb_component_id"in s&&n.includes(s.pcb_component_id)||a&&"pcb_component_id"in a&&n.includes(a.pcb_component_id))?r.is_in_highlighted_net=!0:(r.is_in_highlighted_net=!1,r.is_mouse_over=!1),o.push(r)}return o}var PHt=t=>{const e=new Map,n=new Map,o=new Map,i=new Map,r=new Map;for(const s of t)s.type==="pcb_trace"&&s.pcb_trace_id?e.set(s.pcb_trace_id,s):s.type==="pcb_port"&&s.pcb_port_id?n.set(s.pcb_port_id,s):s.type==="pcb_via"&&s.pcb_via_id?o.set(s.pcb_via_id,s):s.type==="pcb_component"&&s.pcb_component_id?i.set(s.pcb_component_id,s):s.type==="pcb_board"&&s.pcb_board_id&&r.set(s.pcb_board_id,s);return{tracesById:e,portsById:n,viasById:o,componentsById:i,boardsById:r}},Fx=(t,e)=>e?t?{minX:Math.min(t.minX,e.minX),maxX:Math.max(t.maxX,e.maxX),minY:Math.min(t.minY,e.minY),maxY:Math.max(t.maxY,e.maxY)}:e:t,W6=(t,e=.45)=>({minX:t.x-e,maxX:t.x+e,minY:t.y-e,maxY:t.y+e}),Zzo=t=>{if(t.length===0)return null;let e=null;for(const n of t){const o=Math.max((n.width??.2)/2,.3);e=Fx(e,W6(n,o))}return e},wHt=t=>{if(!t?.center)return null;const e=Math.max(t.width??0,1.2),n=Math.max(t.height??0,1.2);return{minX:t.center.x-e/2,maxX:t.center.x+e/2,minY:t.center.y-n/2,maxY:t.center.y+n/2}},eVo=t=>!t?.center||typeof t.width!="number"||typeof t.height!="number"?null:{minX:t.center.x-t.width/2,maxX:t.center.x+t.width/2,minY:t.center.y-t.height/2,maxY:t.center.y+t.height/2},tVo=(t,e)=>({minX:t.minX-e,maxX:t.maxX+e,minY:t.minY-e,maxY:t.maxY+e}),nVo=(t,e=.35)=>{const n=mp(t);return n?tVo(n,e):null},MHt=({error:t,tracesById:e,portsById:n,viasById:o,componentsById:i})=>{if(t.center)return t.center;if(t.pcb_center)return t.pcb_center;if(t.component_center)return t.component_center;if(t.pcb_via_ids?.length){const r=t.pcb_via_ids.map(s=>o.get(s)).filter(Boolean);if(r.length>0)return{x:r.reduce((s,a)=>s+a.x,0)/r.length,y:r.reduce((s,a)=>s+a.y,0)/r.length}}if(t.pcb_port_ids?.length){const r=t.pcb_port_ids.map(s=>n.get(s)).filter(Boolean);if(r.length>0)return{x:r.reduce((s,a)=>s+a.x,0)/r.length,y:r.reduce((s,a)=>s+a.y,0)/r.length}}if(t.pcb_trace_id){const r=e.get(t.pcb_trace_id);if(r?.route?.length){const s=Math.floor(r.route.length/2);return{x:r.route[s].x,y:r.route[s].y}}}return t.pcb_component_id?i.get(t.pcb_component_id)?.center??null:null},oVo=({error:t,indexes:e})=>MHt({error:t,...e}),iVo=({error:t,boardsById:e})=>{if(!t.component_bounds||!t.pcb_board_id)return null;const n=eVo(e.get(t.pcb_board_id));if(!n)return null;const o=t.component_bounds,i=[];return o.min_x<n.minX&&(i.push({x:n.minX,y:Math.max(o.min_y,n.minY)}),i.push({x:n.minX,y:Math.min(o.max_y,n.maxY)})),o.max_x>n.maxX&&(i.push({x:n.maxX,y:Math.max(o.min_y,n.minY)}),i.push({x:n.maxX,y:Math.min(o.max_y,n.maxY)})),o.min_y<n.minY&&(i.push({x:Math.max(o.min_x,n.minX),y:n.minY}),i.push({x:Math.min(o.max_x,n.maxX),y:n.minY})),o.max_y>n.maxY&&(i.push({x:Math.max(o.min_x,n.minX),y:n.maxY}),i.push({x:Math.min(o.max_x,n.maxX),y:n.maxY})),nVo(i,.3)},NHt=new Set(["source_failed_to_create_component_error"]),rVo=({error:t,indexes:e})=>{if(NHt.has(t.error_type)||NHt.has(t.type))return null;let n=null;const o=MHt({error:t,...e});if(o&&(n=Fx(n,W6(o,.35))),t.error_type==="pcb_component_outside_board_error"?n=Fx(n,iVo({error:t,boardsById:e.boardsById})):t.component_bounds&&!o&&(n=Fx(n,{minX:t.component_bounds.min_x,maxX:t.component_bounds.max_x,minY:t.component_bounds.min_y,maxY:t.component_bounds.max_y})),t.center&&!o&&(n=Fx(n,W6(t.center))),t.pcb_center&&!o&&(n=Fx(n,W6(t.pcb_center))),t.component_center&&!o&&(n=Fx(n,W6(t.component_center))),t.pcb_port_ids&&!o)for(const i of t.pcb_port_ids){const r=e.portsById.get(i);r&&(n=Fx(n,W6({x:r.x,y:r.y},.4)))}if(t.pcb_trace_id&&!o){const i=e.tracesById.get(t.pcb_trace_id);i?.route&&(n=Fx(n,Zzo(i.route)))}if(t.pcb_via_ids)for(const i of t.pcb_via_ids){const r=e.viasById.get(i);r&&(n=Fx(n,W6({x:r.x,y:r.y},Math.max((r.outer_diameter??.5)/2,.28))))}if(t.pcb_component_id&&!o&&(n=Fx(n,wHt(e.componentsById.get(t.pcb_component_id)))),t.pcb_component_ids&&!o)for(const i of t.pcb_component_ids)n=Fx(n,wHt(e.componentsById.get(i)));return n},sVo=({bounds:t,width:e,height:n})=>{const o={x:(t.minX+t.maxX)/2,y:(t.minY+t.maxY)/2},i=Math.max(t.maxX-t.minX,.8)+1.4,r=Math.max(t.maxY-t.minY,.8)+1.4,s=Math.min(e/i,n/r,240)*.92;return Fi(ji(e/2,n/2),gg(s,-s,0,0),ji(-o.x,-o.y))},aVo=t=>{const e=new Set;t.pcb_trace_id&&e.add(t.pcb_trace_id);for(const n of t.pcb_port_ids??[])e.add(n);for(const n of t.pcb_via_ids??[])e.add(n);t.pcb_component_id&&e.add(t.pcb_component_id);for(const n of t.pcb_component_ids??[])e.add(n);return[...e]},Gk=(t,e)=>{const n=["pcb_trace_error_id","pcb_via_clearance_error_id","pcb_component_outside_board_error_id","source_failed_to_create_component_error_id","pcb_error_id"];for(const o of n)if(typeof t?.[o]=="string"&&t[o].length>0)return t[o];for(const[o,i]of Object.entries(t??{}))if(o.endsWith("_error_id")&&typeof i=="string"&&i.length>0)return i;return`error_${e}_${t?.error_type}_${t?.message?.slice(0,20)}`},RHt=(t,e)=>e?t.find((n,o)=>n.type?.includes("error")?Gk(n,o)===e:!1)??null:null,AVo=t=>1-(1-t)**3,cVo=(t,e,n)=>({a:t.a+(e.a-t.a)*n,b:t.b+(e.b-t.b)*n,c:t.c+(e.c-t.c)*n,d:t.d+(e.d-t.d)*n,e:t.e+(e.e-t.e)*n,f:t.f+(e.f-t.f)*n}),THt=t=>{t!==null&&window.cancelAnimationFrame(t)},lVo=({startTransform:t,endTransform:e,durationMs:n,onUpdate:o,setAnimationFrameId:i,onComplete:r})=>{const s=performance.now(),a=c=>{const l=c-s,g=Math.min(1,l/n),u=AVo(g);if(o(cVo(t,e,u)),g<1){i(window.requestAnimationFrame(a));return}i(null),r?.()},A=window.requestAnimationFrame(a);return i(A),A},Fo={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)"}},Fy=(t,e=1)=>{if(Math.abs(t.a)!==Math.abs(t.d))throw new Error("Cannot scale non-uniformly");return e*Math.abs(t.a)},Yg={elementOverlay:40,dimensionOverlay:40,errorOverlay:40,pcbGroupOverlay:35,ratsNestOverlay:30,toolbarOverlay:70,warnings:30,topLayer:30,clickToInteractOverlay:100},lae={red:"red",black:"black",green:"green",board:"rgb(255, 255, 255)",other:"#eee",top:Fo.board.copper.f,inner1:Fo.board.copper.in1,inner2:Fo.board.copper.in2,inner3:Fo.board.copper.in3,inner4:Fo.board.copper.in4,inner5:Fo.board.copper.in5,inner6:Fo.board.copper.in6,inner7:Fo.board.copper.in7,inner8:Fo.board.copper.in8,bottom:Fo.board.copper.b,drill:Fo.board.anchor,keepout:Fo.board.background,tkeepout:Fo.board.b_crtyd,tplace:Fo.board.b_silks,top_courtyard:Fo.board.f_crtyd,bottom_courtyard:Fo.board.b_crtyd,top_silkscreen:Fo.board.f_silks,bottom_silkscreen:Fo.board.b_silks,top_fabrication:Fo.board.f_fab,bottom_fabrication:Fo.board.b_fab,soldermask_top:Fo.board.soldermask.top,soldermask_bottom:Fo.board.soldermask.bottom,soldermask_with_copper_top:Fo.board.soldermaskWithCopper.top,soldermask_with_copper_bottom:Fo.board.soldermaskWithCopper.bottom,bottom_notes:Fo.board.user_2,top_notes:Fo.board.user_2,...Fo.board},gVo=["board","bottom","soldermask_bottom","bottom_silkscreen","top","soldermask_top","bottom_courtyard","bottom_fabrication","top_courtyard","top_fabrication","edge_cuts","top_silkscreen"],uVo=class{canvasLayerMap;ctxLayerMap;aperture;transform;foregroundLayer="top";lastPoint;constructor(t){this.canvasLayerMap=t,this.ctxLayerMap=Object.fromEntries(Object.entries(t).map(([e,n])=>[e,n.getContext("2d")])),this.transform=Hl(),this.transform.d*=-1,this.transform=Fi(this.transform,ji(0,-500)),this.lastPoint={x:0,y:0},this.equip({})}clear(){for(const t of Object.values(this.ctxLayerMap))t.clearRect(0,0,t.canvas.width,t.canvas.height)}equip(t){this.aperture={fontSize:0,shape:"circle",mode:"add",size:0,color:"red",layer:"top",opacity:this.foregroundLayer===t.color?1:.5,...t}}drawMeshPattern(t,e,n,o,i,r=45){const s=this.getLayerCtx(),[a,A]=mt(this.transform,[t,e]),[c,l]=mt(this.transform,[t+n,e+o]),g=Fy(this.transform,i);s.lineWidth=1,s.strokeStyle=this.aperture.color;const u=h=>{const d=Math.sin(h),_=Math.cos(h),m=Math.sqrt((c-a)**2+(l-A)**2);for(let p=-m;p<=m;p+=g)s.beginPath(),s.moveTo(a+p*_-m*d,A+p*d+m*_),s.lineTo(a+p*_+m*d,A+p*d-m*_),s.stroke()};u(r*Math.PI/180),u((r+90)*Math.PI/180)}rect({x:t,y:e,w:n,h:o,mesh_fill:i,is_filled:r=!0,has_stroke:s,is_stroke_dashed:a,stroke_width:A,roundness:c}){const[l,g]=mt(this.transform,[t-n/2,e-o/2]),[u,h]=mt(this.transform,[t+n/2,e+o/2]);this.applyAperture();const d=this.getLayerCtx(),_=c?Fy(this.transform,c):0,m=s===void 0?r===!1:s;if(i)d.save(),d.beginPath(),_>0&&d.roundRect?d.roundRect(l,g,u-l,h-g,_):d.rect(l,g,u-l,h-g),d.clip(),this.drawMeshPattern(t-n/2,e-o/2,n,o,.15),d.restore(),_>0&&d.roundRect?(d.beginPath(),d.roundRect(l,g,u-l,h-g,_),d.stroke()):d.strokeRect(l,g,u-l,h-g);else if(r!==!1&&(_>0&&d.roundRect?(d.beginPath(),d.roundRect(l,g,u-l,h-g,_),d.fill()):d.fillRect(l,g,u-l,h-g)),m){const p=d.lineWidth;if(A!==void 0&&(d.lineWidth=Fy(this.transform,A)),a){let I=[];const f=Math.abs(this.transform.a);if(f>0){const y=.1*f,E=y*1.3;y>.5&&(I=[y,E])}d.setLineDash(I)}_>0&&d.roundRect?(d.beginPath(),d.roundRect(l,g,u-l,h-g,_),d.stroke()):d.strokeRect(l,g,u-l,h-g),a&&d.setLineDash([]),A!==void 0&&(d.lineWidth=p)}}rotatedRect(t,e,n,o,i,r,s){const a=this.getLayerCtx();this.applyAperture();const[A,c]=mt(this.transform,[t-n/2,e-o/2]),[l,g]=mt(this.transform,[t+n/2,e+o/2]),u=r?Fy(this.transform,r):0;a.save();const[h,d]=mt(this.transform,[t,e]);a.translate(h,d);const _=360-i;i&&a.rotate(_*Math.PI/180),a.translate(-h,-d),s?(a.beginPath(),u>0&&a.roundRect?a.roundRect(A,c,l-A,g-c,u):a.rect(A,c,l-A,g-c),a.clip(),this.drawMeshPattern(t-n/2,e-o/2,n,o,.15),u>0&&a.roundRect?(a.beginPath(),a.roundRect(A,c,l-A,g-c,u),a.stroke()):a.strokeRect(A,c,l-A,g-c)):u>0&&a.roundRect?(a.beginPath(),a.roundRect(A,c,l-A,g-c,u),a.fill()):a.fillRect(A,c,l-A,g-c),a.restore()}rotatedPill(t,e,n,o,i){const r=this.getLayerCtx();this.applyAperture(),r.save();const[s,a]=mt(this.transform,[t,e]);r.translate(s,a);const A=360-i;i&&r.rotate(A*Math.PI/180),r.translate(-s,-a),this.pill(t,e,n,o),r.restore()}circle(t,e,n,o,i=!0){const r=Fy(this.transform,n),[s,a]=mt(this.transform,[t,e]);this.applyAperture();const A=this.getLayerCtx();o?(A.save(),A.beginPath(),A.arc(s,a,r,0,2*Math.PI),A.clip(),this.drawMeshPattern(t-n,e-n,n*2,n*2,.15),A.restore(),A.beginPath(),A.arc(s,a,r,0,2*Math.PI),A.stroke()):(A.beginPath(),A.arc(s,a,r,0,2*Math.PI),A.fill())}oval(t,e,n,o){const i=Fy(this.transform,n),r=Fy(this.transform,o),[s,a]=mt(this.transform,[t,e]);this.applyAperture();const A=this.getLayerCtx();A.beginPath(),A.ellipse(s,a,i,r,0,0,2*Math.PI),A.fill(),A.closePath()}pill(t,e,n,o){const[i,r]=mt(this.transform,[t-n/2,e+o/2]),s=Fy(this.transform,n),a=Fy(this.transform,o),A=Math.min(s,a)/2;this.applyAperture();const c=this.getLayerCtx();c.beginPath(),c.arc(i+A,r+A,A,Math.PI,Math.PI*1.5),c.arc(i+s-A,r+A,A,Math.PI*1.5,0),c.arc(i+s-A,r+a-A,A,0,Math.PI*.5),c.arc(i+A,r+a-A,A,Math.PI*.5,Math.PI),c.fill(),c.closePath()}polygon(t){if(t.length<3)return;this.applyAperture();const e=this.getLayerCtx(),n=t.map(i=>mt(this.transform,[i.x,i.y]));e.beginPath(),e.moveTo(n[0][0],n[0][1]);for(let i=1;i<n.length;i++)e.lineTo(n[i][0],n[i][1]);e.closePath(),e.fill("evenodd");const o=Fy(this.transform,this.aperture.size);o>0&&(e.lineWidth=o,e.stroke())}debugText(t,e,n){const[o,i]=mt(this.transform,[e,n]);this.applyAperture();const r=this.getLayerCtx();r.font="10px sans-serif",r.fillText(t,o,i)}getLayerCtx(){const t=this.ctxLayerMap[this.aperture.layer];if(!t)throw new Error(`No context for layer "${this.aperture.layer}"`);return t}orderAndFadeLayers(){const{canvasLayerMap:t,foregroundLayer:e}=this,o=["board",...Object.keys(t).filter(u=>/^inner\d+$/.test(u)).sort((u,h)=>Number(h.slice(5))-Number(u.slice(5))),...gVo.filter(u=>u!=="board")],i=e==="top"?"soldermask_top":e==="bottom"?"soldermask_bottom":void 0,r=e==="top"?"top_silkscreen":e==="bottom"?"bottom_silkscreen":void 0,s=e==="top"?"top_notes":e==="bottom"?"bottom_notes":void 0,a=e==="top"?"top_fabrication":e==="bottom"?"bottom_fabrication":void 0,A=e==="top"?"top_courtyard":e==="bottom"?"bottom_courtyard":void 0,c=new Set([e,"drill","edge_cuts","other","board",...i?[i]:[],...r?[r]:[],...s?[s]:[],...a?[a]:[],...A?[A]:[]]),l=[e,"edge_cuts",...i?[i]:[],...r?[r]:[],...s?[s]:[],...a?[a]:[],...A?[A]:[]],g=[...o.filter(u=>!l.includes(u)),...e==="drill"?[]:[e],...i?[i]:[],"edge_cuts",...r?[r]:[],...s?[s]:[],...a?[a]:[],...A?[A]:[],"drill"];g.forEach((u,h)=>{const d=t[u];d&&(d.style.zIndex=`${Yg.topLayer-(g.length-h)}`,d.style.opacity=c.has(u)?"1":"0.5")})}applyAperture(){const{transform:t,aperture:e}=this;let{size:n,mode:o,color:i,fontSize:r,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=Fy(t,n),a.lineCap="round",o==="add"){a.globalCompositeOperation="source-over";let A=lae[i.toLowerCase()];if(!A)try{A=Kr(i).rgb().toString()}catch{console.warn(`Invalid color format: '${i}'`),A="white"}a.fillStyle=A,a.strokeStyle=A}else a.globalCompositeOperation="destination-out",a.fillStyle="rgba(0,0,0,1)",a.strokeStyle="rgba(0,0,0,1)";a.font=`${Fy(MQ(t),r)}px sans-serif`}moveTo(t,e){this.lastPoint={x:t,y:e}}lineTo(t,e){const[n,o]=mt(this.transform,[t,e]),{size:i,shape:r,mode:s}=this.aperture,a=Fy(this.transform,i),{lastPoint:A}=this,c=mt(this.transform,A);this.applyAperture();const l=this.getLayerCtx();r==="square"&&l.fillRect(c.x-a/2,c.y-a/2,a,a),l.beginPath(),l.moveTo(c.x,c.y),l.lineTo(n,o),l.stroke(),l.closePath(),r==="square"&&l.fillRect(n-a/2,o-a/2,a,a),this.lastPoint={x:t,y:e}}polygonWithArcs(t){const e=this.getLayerCtx(),n=o=>{if(o.vertices.length===0)return;const i=o.vertices[0],r=mt(this.transform,[i.x,i.y]);e.moveTo(r[0],r[1]);for(let s=0;s<o.vertices.length;s++){const a=o.vertices[s],A=o.vertices[(s+1)%o.vertices.length];if(a.bulge&&a.bulge!==0){const c=a.bulge,l=A.x-a.x,g=A.y-a.y,u=Math.sqrt(l*l+g*g);if(u<1e-9){const M=mt(this.transform,[A.x,A.y]);e.lineTo(M[0],M[1]);continue}const h=4*Math.atan(c),d=Math.abs(u/(2*Math.sin(h/2))),_=(a.x+A.x)/2,m=(a.y+A.y)/2,p=l/u,f=-(g/u),C=p,y=Math.sqrt(Math.max(0,d*d-(u/2)**2)),E=_+y*f*Math.sign(c),B=m+y*C*Math.sign(c),Q=Math.atan2(a.y-B,a.x-E);let b=Math.atan2(A.y-B,A.x-E);c>0&&b<Q?b+=2*Math.PI:c<0&&b>Q&&(b-=2*Math.PI);const D=mt(this.transform,[E,B]),R=Fy(this.transform,d);e.arc(D[0],D[1],R,-Q,-b,c>0)}else{const c=mt(this.transform,[A.x,A.y]);e.lineTo(c[0],c[1])}}e.closePath()};if(e.beginPath(),n(t.outer_ring),t.inner_rings)for(const o of t.inner_rings)n(o);e.fill("evenodd")}},dVo=(t=2)=>{const e=Math.max(2,Math.min(10,Math.floor(t)));return["top",...Array.from({length:e-2},(n,o)=>`inner${o+1}`),"bottom"]},e7e=t=>{const e=t.find(n=>n.type==="pcb_board");return dVo(e?.num_layers??2)},hVo=t=>`${t}_copper`,kHt=t=>t.map(e=>e.endsWith("_copper")?e.slice(0,-7):e),_Vo=t=>["board","bottom","soldermask_bottom","bottom_silkscreen","top","soldermask_top","soldermask_with_copper_bottom","soldermask_with_copper_top","top_fabrication","bottom_fabrication",...e7e(t).filter(n=>n.startsWith("inner")),"drill","edge_cuts","bottom_notes","top_notes","top_silkscreen","top_courtyard","bottom_courtyard","other"];function mVo(t){return t.type==="pcb_copper_pour"}function pVo({canvas:t,elements:e,layers:n,realToCanvasMat:o}){const i=e.filter(mVo);if(i.length===0)return;const r=new wc(t);r.realToCanvasMat=o,r.drawElements(i,{layers:n})}var IVo={...t1,courtyard:{top:Fo.board.f_crtyd,bottom:Fo.board.b_crtyd}};function fVo(t){return t.type==="pcb_courtyard_circle"||t.type==="pcb_courtyard_rect"||t.type==="pcb_courtyard_outline"}function FHt({canvas:t,elements:e,layers:n,realToCanvasMat:o}){const i=new wc(t);i.configure({colorOverrides:IVo}),i.realToCanvasMat=o;const r=e.filter(fVo);i.drawElements(r,{layers:n})}var CVo={...t1,silkscreen:{top:Fo.board.f_fab,bottom:Fo.board.b_fab}};function yVo(t){return t.type.includes("pcb_fabrication_note")}function LHt({canvas:t,elements:e,layers:n,realToCanvasMat:o}){const i=new wc(t);i.configure({colorOverrides:CVo}),i.realToCanvasMat=o;const r=e.filter(yVo);i.drawElements(r,{layers:n})}function EVo(t){return t.type==="pcb_hole"}function xVo({canvas:t,elements:e,layers:n,realToCanvasMat:o,drawSoldermask:i}){const r=new wc(t);r.realToCanvasMat=o;const s=e.filter(EVo);r.drawElements(s,{layers:n,drawSoldermask:i})}function BVo(t){return t.type==="pcb_board"}function QVo({canvas:t,elements:e,layers:n,realToCanvasMat:o,drawSoldermask:i}){const r=new wc(t);r.realToCanvasMat=o;const s=e.filter(BVo);for(const a of s)r.drawElements([a],{layers:n,drawSoldermask:!1,drawBoardMaterial:i??!1,minBoardOutlineStrokePx:2})}function SVo(t){return t.type==="pcb_copper_text"}function bVo({canvas:t,elements:e,layers:n,realToCanvasMat:o}){const i=e.filter(SVo);if(i.length===0)return;const r=new wc(t);r.realToCanvasMat=o,r.drawElements(i,{layers:n})}function DVo(t){return t.type==="pcb_cutout"}function vVo({canvas:t,elements:e,layers:n,realToCanvasMat:o}){const i=new wc(t);i.realToCanvasMat=o;const r=e.filter(DVo);i.drawElements(r,{layers:n})}function PVo(t){return t.type==="pcb_keepout"}function wVo({canvas:t,elements:e,layers:n,realToCanvasMat:o}){const i=e.filter(PVo);if(i.length===0)return;const r=new wc(t);r.realToCanvasMat=o,r.drawElements(i,{layers:[]})}function MVo(t){return t.type.startsWith("pcb_note_")}function HHt({canvas:t,elements:e,layers:n,realToCanvasMat:o}){const i=new wc(t);i.realToCanvasMat=o;const r=e.filter(MVo);i.drawElements(r,{layers:n})}function NVo(t){return t.type==="pcb_panel"}function RVo({canvas:t,elements:e,layers:n,realToCanvasMat:o,drawSoldermask:i}){const r=new wc(t);r.realToCanvasMat=o;const s=e.filter(NVo);for(const a of s)r.drawElements([a],{layers:n})}var TVo={...t1,copper:{...t1.copper,top:Kr(Fo.board.pad_front).lighten(.5).toString(),bottom:Kr(Fo.board.pad_back).lighten(.5).toString(),inner1:Kr(Fo.board.copper.in1).lighten(.5).toString(),inner2:Kr(Fo.board.copper.in2).lighten(.5).toString(),inner3:Kr(Fo.board.copper.in3).lighten(.5).toString(),inner4:Kr(Fo.board.copper.in4).lighten(.5).toString(),inner5:Kr(Fo.board.copper.in5).lighten(.5).toString(),inner6:Kr(Fo.board.copper.in6).lighten(.5).toString(),inner7:Kr(Fo.board.copper.in7).lighten(.5).toString(),inner8:Kr(Fo.board.copper.in8).lighten(.5).toString()}};function kVo(t){return t.type==="pcb_smtpad"}function FVo({canvas:t,elements:e,layers:n,realToCanvasMat:o,primitives:i,drawSoldermask:r}){const s=new Set(kHt(n)),a=e.filter(kVo).filter(g=>s.has(g.layer));if(a.length===0)return;const A=new Set;if(i)for(const g of i)(g.is_mouse_over||g.is_in_highlighted_net)&&g._element?.type==="pcb_smtpad"&&A.add(g._element.pcb_smtpad_id);const c=a.filter(g=>A.has(g.pcb_smtpad_id)),l=a.filter(g=>!A.has(g.pcb_smtpad_id));if(l.length>0){const g=new wc(t);g.realToCanvasMat=o,g.drawElements(l,{layers:n,drawSoldermask:r})}if(c.length>0){const g=new wc(t);g.configure({colorOverrides:TVo}),g.realToCanvasMat=o,g.drawElements(c,{layers:n,drawSoldermask:r})}}var LVo={...t1,copper:{...t1.copper,top:Kr(Fo.board.pad_front).lighten(.5).toString(),bottom:Kr(Fo.board.pad_back).lighten(.5).toString(),inner1:Kr(Fo.board.copper.in1).lighten(.5).toString(),inner2:Kr(Fo.board.copper.in2).lighten(.5).toString(),inner3:Kr(Fo.board.copper.in3).lighten(.5).toString(),inner4:Kr(Fo.board.copper.in4).lighten(.5).toString(),inner5:Kr(Fo.board.copper.in5).lighten(.5).toString(),inner6:Kr(Fo.board.copper.in6).lighten(.5).toString(),inner7:Kr(Fo.board.copper.in7).lighten(.5).toString(),inner8:Kr(Fo.board.copper.in8).lighten(.5).toString()}};function HVo(t){return t.type==="pcb_trace"}var GVo=(t,e)=>{const n=t.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 n.filter(i=>i.route_type==="wire").length<2?null:{...t,route:n}},OVo=t=>({...t,route:t.route.map(e=>!("is_inside_copper_pour"in e)||e.is_inside_copper_pour!==!0?e:{...e,is_inside_copper_pour:!1})}),KVo=(t,e)=>e?t:[],UVo=({primitives:t})=>{const e=new Set;for(const n of t)(n.is_mouse_over||n.is_in_highlighted_net)&&n._element?.type==="pcb_trace"&&e.add(n._element.pcb_trace_id);return e};function YVo({canvas:t,elements:e,layers:n,realToCanvasMat:o,primitives:i,showCopperPours:r}){const s=new Set(kHt(n)),a=e.filter(HVo).map(u=>GVo(u,s)).filter(u=>u!==null).map(u=>r?u:OVo(u));if(a.length===0)return;const A=UVo({primitives:i??[]}),c=[],l=[];for(const u of a)A.has(u.pcb_trace_id)?c.push(u):l.push(u);const g=KVo(e,r);if(l.length>0){const u=new wc(t);u.realToCanvasMat=o,u.drawElements(l,{layers:n,clipContextElements:g})}if(c.length>0){const u=new wc(t);u.configure({colorOverrides:LVo}),u.realToCanvasMat=o,u.drawElements(c,{layers:n,clipContextElements:g})}}var zVo={...t1,copper:{...t1.copper,top:Kr(Fo.board.pad_front).lighten(.5).toString(),bottom:Kr(Fo.board.pad_back).lighten(.5).toString(),inner1:Kr(Fo.board.copper.in1).lighten(.5).toString(),inner2:Kr(Fo.board.copper.in2).lighten(.5).toString(),inner3:Kr(Fo.board.copper.in3).lighten(.5).toString(),inner4:Kr(Fo.board.copper.in4).lighten(.5).toString(),inner5:Kr(Fo.board.copper.in5).lighten(.5).toString(),inner6:Kr(Fo.board.copper.in6).lighten(.5).toString(),inner7:Kr(Fo.board.copper.in7).lighten(.5).toString(),inner8:Kr(Fo.board.copper.in8).lighten(.5).toString()}};function VVo(t){return t.type==="pcb_plated_hole"}function JVo({canvas:t,elements:e,layers:n,realToCanvasMat:o,primitives:i,drawSoldermask:r}){const s=e.filter(VVo);if(s.length===0)return;const a=new Set;if(i)for(const l of i)(l.is_mouse_over||l.is_in_highlighted_net)&&l._element?.type==="pcb_plated_hole"&&a.add(l._element.pcb_plated_hole_id);const A=s.filter(l=>a.has(l.pcb_plated_hole_id)),c=s.filter(l=>!a.has(l.pcb_plated_hole_id));if(c.length>0){const l=new wc(t);l.realToCanvasMat=o,l.drawElements(c,{layers:n,drawSoldermask:r})}if(A.length>0){const l=new wc(t);l.configure({colorOverrides:zVo}),l.realToCanvasMat=o,l.drawElements(A,{layers:n,drawSoldermask:r})}}function GHt(t){const{lines:e,anchorPoint:n,ccwRotation:o}=t;if(!o)return e;const i=o*Math.PI/180,r=E_(i),s=Fi(ji(n.x,n.y),r,ji(-n.x,-n.y));return mt(s,n),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 qVo=.6,OHt=.2,KHt=t=>{const e=t.size*.7,n=e*qVo,o=e*OHt,i=e*OHt,r=t.text.split(/\r?\n/),s=t.text.length>0&&e>0,a=s?r.length:0,A=s?r.map(g=>g.length===0?0:g.length*n+(g.length-1)*o):[],c=A.length>0?Math.max(...A):0,l=a>0?a*e+(a-1)*i:0;return{text_lines:r,line_count:a,line_widths:A,target_height:e,target_width_char:n,space_between_chars:o,space_between_lines:i,width:c,height:l}},UHt=t=>{const e=KHt(t);return{width:e.width,height:e.height,lineHeight:e.target_height,lineSpacing:e.space_between_lines,lineCount:e.line_count}},YHt=t=>{const{text_lines:e,line_count:n,line_widths:o,target_height:i,target_width_char:r,space_between_chars:s,space_between_lines:a,width:A}=KHt(t);if(i<=0||n===0)return[];const c=i/12,l=[];for(let g=0;g<n;g++){const u=-g*(i+a),h=o[g],d=(A-h)/2;let _=t.x+d;for(let m=0;m<e[g].length;m++){const p=e[g][m],I=W3[p]??W3[p.toUpperCase()];if(!I){_+=r+s;continue}for(const{x1:f,y1:C,x2:y,y2:E}of I)l.push({_pcb_drawing_object_id:tQ("line"),pcb_drawing_type:"line",x1:_+r*f,y1:t.y+u+i*C,x2:_+r*y,y2:t.y+u+i*E,width:c,layer:t.layer,unit:t.unit,color:t.color});_+=r+s}}return l};function db(t){const n=t.color??lae[t.layer];let o=Kr(n);return t._element?.type==="pcb_copper_pour"&&(o=o.alpha(.7)),t.is_mouse_over||t.is_in_highlighted_net?o.lighten(.5).rgb().toString():o.rgb().toString()}var zHt=(t,e)=>{t.equip({size:e.zoomIndependent?e.width/t.transform.a:e.width,shape:e.squareCap?"square":"circle",color:db(e),layer:e.layer}),t.moveTo(e.x1,e.y1),t.lineTo(e.x2,e.y2)},WVo=(t,e,n)=>{switch(n){case"top_left":return{x:0,y:-e};case"top_center":return{x:-t/2,y:-e};case"top_right":return{x:-t,y:-e};case"center_left":return{x:0,y:-e/2};case"center":return{x:-t/2,y:-e/2};case"center_right":return{x:-t,y:-e/2};case"bottom_left":return{x:0,y:0};case"bottom_center":return{x:-t/2,y:0};case"bottom_right":return{x:-t,y:0};default:return{x:0,y:0}}},VHt=t=>t.layer==="bottom_silkscreen"||t.layer==="bottom"?t.is_mirrored!==!1:t.is_mirrored===!0,jVo=(t,e)=>{t.equip({fontSize:e.size,color:db(e),layer:e.layer});const{width:n,height:o}=UHt(e),i=WVo(n,o,e.align);e.x??=0,e.y??=0;const r={x:e.x,y:e.y};let s=YHt({...e,x:e.x+i.x,y:e.y+i.y});if(VHt(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:r,ccwRotation:e.ccw_rotation};s=GHt(a)}for(const a of s)zHt(t,a)},XVo=(t,e)=>{const{width:n,height:o,lineHeight:i}=UHt(e);e.x??=0,e.y??=0;const r=e.knockout_padding??{left:e.size*.5,right:e.size*.5,top:e.size*.3,bottom:e.size*.3},s=n+r.left+r.right,a=o+r.top+r.bottom,A=n/2,c=i-o/2,l=e.x-A,g=e.y-c,u={x:e.x,y:e.y},h={_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?qHt(t,h):JHt(t,h);let d=YHt({...e,x:l,y:g});if(VHt(e)&&(d=d.map(_=>({..._,x1:2*e.x-_.x1,x2:2*e.x-_.x2}))),e.ccw_rotation){const _={lines:d,anchorPoint:u,ccwRotation:e.ccw_rotation};d=GHt(_)}for(const _ of d)t.equip({size:_.width,shape:"circle",color:"black",layer:e.layer,mode:"subtract"}),t.moveTo(_.x1,_.y1),t.lineTo(_.x2,_.y2);t.equip({mode:"add"})},JHt=(t,e)=>{t.equip({color:db(e),layer:e.layer,size:e.stroke_width}),t.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})},qHt=(t,e)=>{t.equip({color:db(e),layer:e.layer}),t.rotatedRect(e.x,e.y,e.w,e.h,e.ccw_rotation,e.roundness,e.mesh_fill)},$Vo=(t,e)=>{t.equip({color:db(e),layer:e.layer}),t.rotatedPill(e.x,e.y,e.w,e.h,e.ccw_rotation)},ZVo=(t,e)=>{t.equip({color:db(e),layer:e.layer}),t.circle(e.x,e.y,e.r,e.mesh_fill)},eJo=(t,e)=>{t.equip({color:db(e),layer:e.layer}),t.oval(e.x,e.y,e.rX,e.rY)},tJo=(t,e)=>{t.equip({color:db(e),layer:e.layer}),t.pill(e.x,e.y,e.w,e.h)},nJo=(t,e)=>{t.equip({color:db(e),layer:e.layer}),t.polygon(e.points)},oJo=(t,e)=>{t.equip({color:db(e),layer:e.layer}),t.polygonWithArcs(e.brep_shape)},iJo=(t,e)=>{switch(e.pcb_drawing_type){case"line":return zHt(t,e);case"text":return e.is_knockout?XVo(t,e):jVo(t,e);case"rect":return e.ccw_rotation?qHt(t,e):JHt(t,e);case"circle":return ZVo(t,e);case"oval":return eJo(t,e);case"pill":return e.ccw_rotation?$Vo(t,e):tJo(t,e);case"polygon":return nJo(t,e);case"polygon_with_arcs":return oJo(t,e)}},rJo=(t,e)=>{for(const n of e)iJo(t,n)},sJo={...t1,silkscreen:{top:Fo.board.f_silks,bottom:Fo.board.b_silks}};function aJo(t){return t.type.includes("pcb_silkscreen")}function WHt({canvas:t,elements:e,layers:n,realToCanvasMat:o}){const i=new wc(t);i.configure({colorOverrides:sJo}),i.realToCanvasMat=o;const r=e.filter(aJo);i.drawElements(r,{layers:n})}var AJo={...t1,copper:{...t1.copper,top:Kr(Fo.board.pad_front).lighten(.5).toString(),bottom:Kr(Fo.board.pad_back).lighten(.5).toString(),inner1:Kr(Fo.board.copper.in1).lighten(.5).toString(),inner2:Kr(Fo.board.copper.in2).lighten(.5).toString(),inner3:Kr(Fo.board.copper.in3).lighten(.5).toString(),inner4:Kr(Fo.board.copper.in4).lighten(.5).toString(),inner5:Kr(Fo.board.copper.in5).lighten(.5).toString(),inner6:Kr(Fo.board.copper.in6).lighten(.5).toString(),inner7:Kr(Fo.board.copper.in7).lighten(.5).toString(),inner8:Kr(Fo.board.copper.in8).lighten(.5).toString()},soldermask:{...t1.soldermask,top:Kr(Fo.board.soldermask.top).lighten(.35).toString(),bottom:Kr(Fo.board.soldermask.bottom).lighten(.35).toString()}};function jHt({canvas:t,elements:e,layers:n,realToCanvasMat:o,drawSoldermaskTop:i,drawSoldermaskBottom:r,primitives:s}){const a=new wc(t);a.realToCanvasMat=o;const A=e.filter(u=>u.type==="pcb_board");if(A.length<=1)a.drawElements(e,{layers:n,drawSoldermask:!0,drawSoldermaskTop:i,drawSoldermaskBottom:r,drawBoardMaterial:!1});else{const u=e.filter(h=>h.type!=="pcb_board");for(const h of A)a.drawElements([h,...u],{layers:n,drawSoldermask:!0,drawSoldermaskTop:i,drawSoldermaskBottom:r,drawBoardMaterial:!1})}if(!s)return;const c=new Set;for(const u of s){if(!(u.is_mouse_over||u.is_in_highlighted_net))continue;const h=u._element;h?.type==="pcb_smtpad"?c.add(h.pcb_smtpad_id):h?.type==="pcb_plated_hole"?c.add(h.pcb_plated_hole_id):h?.type==="pcb_via"&&c.add(h.pcb_via_id)}if(c.size===0)return;const l=e.filter(u=>u.type==="pcb_smtpad"?c.has(u.pcb_smtpad_id):u.type==="pcb_plated_hole"?c.has(u.pcb_plated_hole_id):u.type==="pcb_via"?c.has(u.pcb_via_id):!1);if(l.length===0)return;const g=new wc(t);g.configure({colorOverrides:AJo}),g.realToCanvasMat=o,g.drawElements(l,{layers:n,drawSoldermask:!0,drawSoldermaskTop:i,drawSoldermaskBottom:r,drawBoardMaterial:!1})}var cJo={...t1,copper:{...t1.copper,top:Kr(Fo.board.pad_front).lighten(.5).toString(),bottom:Kr(Fo.board.pad_back).lighten(.5).toString(),inner1:Kr(Fo.board.copper.in1).lighten(.5).toString(),inner2:Kr(Fo.board.copper.in2).lighten(.5).toString(),inner3:Kr(Fo.board.copper.in3).lighten(.5).toString(),inner4:Kr(Fo.board.copper.in4).lighten(.5).toString(),inner5:Kr(Fo.board.copper.in5).lighten(.5).toString(),inner6:Kr(Fo.board.copper.in6).lighten(.5).toString(),inner7:Kr(Fo.board.copper.in7).lighten(.5).toString(),inner8:Kr(Fo.board.copper.in8).lighten(.5).toString()}};function lJo(t){return t.type==="pcb_via"}function gJo({canvas:t,elements:e,layers:n,realToCanvasMat:o,primitives:i,drawSoldermask:r}){const s=e.filter(lJo).filter(l=>n.some(g=>g.includes("copper")));if(s.length===0)return;const a=new Set;if(i)for(const l of i)(l.is_mouse_over||l.is_in_highlighted_net)&&l._element?.type==="pcb_via"&&a.add(l._element.pcb_via_id);const A=s.filter(l=>a.has(l.pcb_via_id)),c=s.filter(l=>!a.has(l.pcb_via_id));if(c.length>0){const l=new wc(t);l.realToCanvasMat=o,l.drawElements(c,{layers:n,drawSoldermask:r})}if(A.length>0){const l=new wc(t);l.configure({colorOverrides:cJo}),l.realToCanvasMat=o,l.drawElements(A,{layers:n,drawSoldermask:r})}}var uJo=({primitives:t,elements:e,transform:n,grid:o,width:i=500,height:r=500})=>{const s=X.useRef({}),a=yd(d=>d.selected_layer),A=yd(d=>d.is_showing_copper_pours),c=yd(d=>d.is_showing_solder_mask),l=yd(d=>d.is_showing_fabrication_notes),g=yd(d=>d.is_showing_pcb_notes),u=yd(d=>d.is_showing_courtyards),h=yd(d=>d.is_showing_silkscreen);return X.useEffect(()=>{if(!s.current||Object.keys(s.current).length===0)return;const d=Object.fromEntries(Object.entries(s.current).filter(([p,I])=>!!I));if(Object.keys(d).length===0)return;const _=new uVo(d);n&&(_.transform=n),_.clear(),_.foregroundLayer=a;const m=t.filter(p=>c||!p.layer?.includes("soldermask")).filter(p=>h||!p.layer?.includes("silkscreen")).filter(p=>l||!p.layer?.includes("fabrication")).filter(p=>p.layer!=="board").filter(p=>p._element?.type!=="pcb_smtpad").filter(p=>p._element?.type!=="pcb_plated_hole").filter(p=>p._element?.type!=="pcb_via").filter(p=>p._element?.type!=="pcb_trace").filter(p=>p._element?.type!=="pcb_copper_text");if(rJo(_,m),n){const p=s.current.top,I=s.current.bottom,f=e7e(e).map(Q=>({canvas:s.current[Q],layer:Q,copperLayer:hVo(Q)}));for(const{canvas:Q,copperLayer:b}of f)Q&&YVo({canvas:Q,elements:e,layers:[b],realToCanvasMat:n,primitives:t,showCopperPours:A});for(const{canvas:Q,copperLayer:b}of f)Q&&bVo({canvas:Q,elements:e,layers:[b],realToCanvasMat:n});for(const{canvas:Q,copperLayer:b,layer:D}of f)Q&&JVo({canvas:Q,elements:e,layers:[b],realToCanvasMat:n,primitives:t,drawSoldermask:c&&(D==="top"||D==="bottom")});for(const{canvas:Q,copperLayer:b}of f)Q&&pVo({canvas:Q,elements:e,layers:[b],realToCanvasMat:n});for(const{canvas:Q,copperLayer:b}of f)Q&&FVo({canvas:Q,elements:e,layers:[b],realToCanvasMat:n,primitives:t,drawSoldermask:c});for(const{canvas:Q,copperLayer:b,layer:D}of f)Q&&gJo({canvas:Q,elements:e,layers:[b],realToCanvasMat:n,primitives:t,drawSoldermask:c&&(D==="top"||D==="bottom")});if(c){const Q=a==="bottom"?"bottom":"top",b=Q==="top",D=Q==="bottom",R=s.current.soldermask_top;R&&Q==="top"&&jHt({canvas:R,elements:e,layers:["top_soldermask"],realToCanvasMat:n,drawSoldermaskTop:b,drawSoldermaskBottom:D,primitives:t});const M=s.current.soldermask_bottom;M&&Q==="bottom"&&jHt({canvas:M,elements:e,layers:["bottom_soldermask"],realToCanvasMat:n,drawSoldermaskTop:b,drawSoldermaskBottom:D,primitives:t})}const C=s.current.drill;if(C&&xVo({canvas:C,elements:e,layers:["drill"],realToCanvasMat:n}),h){const Q=s.current.top_silkscreen;Q&&WHt({canvas:Q,elements:e,layers:["top_silkscreen"],realToCanvasMat:n});const b=s.current.bottom_silkscreen;b&&WHt({canvas:b,elements:e,layers:["bottom_silkscreen"],realToCanvasMat:n})}if(l){const Q=s.current.top_fabrication;Q&&LHt({canvas:Q,elements:e,layers:["top_fabrication_note"],realToCanvasMat:n});const b=s.current.bottom_fabrication;b&&LHt({canvas:b,elements:e,layers:["bottom_fabrication_note"],realToCanvasMat:n})}if(g){const Q=s.current.bottom_notes;Q&&HHt({canvas:Q,elements:e,layers:["bottom_user_note"],realToCanvasMat:n});const b=s.current.top_notes;b&&HHt({canvas:b,elements:e,layers:["top_user_note"],realToCanvasMat:n})}if(u){const Q=s.current.top_courtyard;Q&&FHt({canvas:Q,elements:e,layers:["top_courtyard"],realToCanvasMat:n});const b=s.current.bottom_courtyard;b&&FHt({canvas:b,elements:e,layers:["bottom_courtyard"],realToCanvasMat:n})}const y=s.current.board;y&&(RVo({canvas:y,elements:e,layers:[],realToCanvasMat:n,drawSoldermask:c}),QVo({canvas:y,elements:e,layers:[],realToCanvasMat:n,drawSoldermask:c}));const E=s.current.edge_cuts;E&&vVo({canvas:E,elements:e,layers:["edge_cuts"],realToCanvasMat:n});const B=[{canvas:p,layer:"top"},{canvas:I,layer:"bottom"}];for(const{canvas:Q,layer:b}of B)Q&&wVo({canvas:Q,elements:e,layers:[b],realToCanvasMat:n})}_.orderAndFadeLayers()},[t,e,n,a,A,c,l,g,u,h]),z.jsxs("div",{style:{backgroundColor:"black",width:i,height:r,position:"relative"},children:[z.jsx(qse.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:r,transform:n,stringifyCoord:(d,_,m)=>`${qse.toMMSI(d,m)}, ${qse.toMMSI(_,m)}`}),_Vo(e).filter(d=>!(!c&&d.includes("soldermask")||!h&&d.includes("silkscreen"))).map(d=>d.replace(/-/g,"")).map((d,_)=>z.jsx("canvas",{className:`pcb-layer-${d}`,ref:m=>{s.current??={},m?s.current[d]=m:delete s.current[d]},style:{position:"absolute",zIndex:_,left:0,top:0,pointerEvents:"none"},width:i,height:r},d))]})},dJo=.6,hJo=1;V9e(nzo(),1),V9e(Izo(),1);var gae=["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 XHt(t,e,n,o={}){const i=o.padding??40,r=o.yFlip??!1;let s;if("center"in t){const l=t.width/2,g=t.height/2;s={minX:t.center.x-l,maxX:t.center.x+l,minY:t.center.y-g,maxY:t.center.y+g}}else s=t;const a=s.maxX-s.minX||1,A=s.maxY-s.minY||1,c=Math.min((e-2*i)/a,(n-2*i)/A);return Fi(ji(e/2,n/2),gg(c,r?-c:c),ji(-(s.minX+a/2),-(s.minY+A/2)))}function _Jo(t){const e=[...t.points||[],...(t.lines||[]).flatMap(n=>n.points),...(t.rects||[]).flatMap(n=>{const o=n.width/2,i=n.height/2;return[{x:n.center.x-o,y:n.center.y-i},{x:n.center.x+o,y:n.center.y-i},{x:n.center.x-o,y:n.center.y+i},{x:n.center.x+o,y:n.center.y+i}]}),...(t.circles||[]).flatMap(n=>[{x:n.center.x-n.radius,y:n.center.y},{x:n.center.x+n.radius,y:n.center.y},{x:n.center.x,y:n.center.y-n.radius},{x:n.center.x,y:n.center.y+n.radius}]),...(t.texts||[]).flatMap(n=>{const o=n.fontSize??12,i=n.text.length*o*dJo,r=o*hJo,s=n.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:-r/2},center:{dx:-i/2,dy:-r/2},center_right:{dx:-i,dy:-r/2},bottom_left:{dx:0,dy:-r},bottom_center:{dx:-i/2,dy:-r},bottom_right:{dx:-i,dy:-r}},{dx:A,dy:c}=a[s],l=n.x+A,g=n.y+c;return[{x:l,y:g},{x:l+i,y:g+r}]})];return e.length===0?{minX:-1,maxX:1,minY:-1,maxY:1}:e.reduce((n,o)=>({minX:Math.min(n.minX,o.x),maxX:Math.max(n.maxX,o.x),minY:Math.min(n.minY,o.y),maxY:Math.max(n.maxY,o.y)}),{minX:1/0,maxX:-1/0,minY:1/0,maxY:-1/0})}function mJo(t,e,n={}){const o=e instanceof HTMLCanvasElement?e.getContext("2d"):e;if(!o)throw new Error("Could not get 2D context from canvas");const i=e instanceof HTMLCanvasElement?e.width:e.canvas.width,r=e instanceof HTMLCanvasElement?e.height:e.canvas.height;let s;if(n.transform)s=n.transform;else if(n.viewbox)s=XHt(n.viewbox,i,r,{padding:n.padding,yFlip:n.yFlip});else{const a=_Jo(t),A=t.coordinateSystem==="cartesian";s=XHt(a,i,r,{padding:n.padding??40,yFlip:A})}o.clearRect(0,0,i,r),o.save(),t.rects&&t.rects.length>0&&t.rects.forEach(a=>{const A=a.width/2,c=a.height/2,l=mt(s,{x:a.center.x-A,y:a.center.y-c}),g=mt(s,{x:a.center.x+A,y:a.center.y+c}),u=Math.abs(g.x-l.x),h=Math.abs(g.y-l.y);o.beginPath(),o.rect(Math.min(l.x,g.x),Math.min(l.y,g.y),u,h),a.fill&&(o.fillStyle=a.fill,o.fill()),a.stroke&&(o.strokeStyle=a.stroke,o.stroke())}),t.circles&&t.circles.length>0&&t.circles.forEach(a=>{const A=mt(s,a.center),c=a.radius*Math.abs(s.a);o.beginPath(),o.arc(A.x,A.y,c,0,2*Math.PI),a.fill&&(o.fillStyle=a.fill,o.fill()),a.stroke&&(o.strokeStyle=a.stroke??"transparent",o.stroke())}),t.lines&&t.lines.length>0&&t.lines.forEach((a,A)=>{if(a.points.length===0)return;o.beginPath();const c=mt(s,a.points[0]);o.moveTo(c.x,c.y);for(let l=1;l<a.points.length;l++){const g=mt(s,a.points[l]);o.lineTo(g.x,g.y)}if(o.strokeStyle=a.strokeColor||gae[A%gae.length],a.strokeWidth?o.lineWidth=a.strokeWidth*s.a:o.lineWidth=2,o.lineCap="round",a.strokeDash)if(typeof a.strokeDash=="string"){let l;if(a.strokeDash.includes(","))l=a.strokeDash.split(",").map(g=>parseFloat(g.trim())).filter(g=>!Number.isNaN(g));else{const g=parseFloat(a.strokeDash.trim());l=Number.isNaN(g)?[]:[g]}o.setLineDash(l)}else o.setLineDash(a.strokeDash.map(l=>l*Math.abs(s.a)));else o.setLineDash([]);o.stroke()}),t.points&&t.points.length>0&&t.points.forEach((a,A)=>{const c=mt(s,a);o.beginPath(),o.arc(c.x,c.y,3,0,2*Math.PI),o.fillStyle=a.color||gae[A%gae.length],o.fill(),a.label&&!n.disableLabels&&(o.fillStyle=a.color||"black",o.font="12px sans-serif",o.fillText(a.label,c.x+5,c.y-5))}),t.texts&&t.texts.length>0&&t.texts.forEach(a=>{const A=mt(s,{x:a.x,y:a.y});o.fillStyle=a.color||"black",o.font=`${(a.fontSize??12)*Math.abs(s.a)}px sans-serif`;const c=a.anchorSide??"center",l={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"},g={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"};o.textAlign=l[c],o.textBaseline=g[c],o.fillText(a.text,A.x,A.y)}),o.restore()}var pJo=({children:t,transform:e,debugGraphics:n})=>{const o=X.useRef(null),[i,{width:r,height:s}]=GY(),a=yd(A=>A.is_showing_autorouting);return X.useEffect(()=>{a&&o.current&&n&&r&&s&&(o.current.width=r,o.current.height=s,mJo(n,o.current,{transform:e,disableLabels:!0}))},[n,e,r,s,a]),a?z.jsxs("div",{ref:i,style:{position:"relative",width:"100%",height:"100%"},children:[t,z.jsx("canvas",{ref:o,style:{position:"absolute",top:0,left:0,opacity:.5,zIndex:100,width:"100%",height:"100%",pointerEvents:"none"}})]}):t},uae=(t,e,n)=>n(t,e),$Ht=(t,e,n,o,i)=>{const r=i*Math.PI/180,s=Math.cos(r),a=Math.sin(r),A=t-n,c=e-o,l=A*s-c*a,g=A*a+c*s;return{x:l+n,y:g+o}},OY=t=>{if(t.length===0)return null;let e=t[0].x,n=t[0].x,o=t[0].y,i=t[0].y;for(const r of t)e=uae(e,r.x,Math.min),n=uae(n,r.x,Math.max),o=uae(o,r.y,Math.min),i=uae(i,r.y,Math.max);return{minX:e,maxX:n,minY:o,maxY:i}},IJo=(t,e)=>({minX:Math.min(t.minX,e.minX),maxX:Math.max(t.maxX,e.maxX),minY:Math.min(t.minY,e.minY),maxY:Math.max(t.maxY,e.maxY)}),fJo=(t,e)=>t?IJo(t,e):e,CJo=t=>{switch(t.pcb_drawing_type){case"line":{const e=(t.width??0)/2,n=[{x:t.x1,y:t.y1},{x:t.x2,y:t.y2}],o=OY(n);return o?{minX:o.minX-e,maxX:o.maxX+e,minY:o.minY-e,maxY:o.maxY+e}:null}case"rect":{const e=t.w/2,n=t.h/2,o=[{x:t.x-e,y:t.y-n},{x:t.x+e,y:t.y-n},{x:t.x+e,y:t.y+n},{x:t.x-e,y:t.y+n}],i=t.ccw_rotation??0,r=i===0?o:o.map(s=>$Ht(s.x,s.y,t.x,t.y,i));return OY(r)}case"circle":return{minX:t.x-t.r,maxX:t.x+t.r,minY:t.y-t.r,maxY:t.y+t.r};case"oval":return{minX:t.x-t.rX,maxX:t.x+t.rX,minY:t.y-t.rY,maxY:t.y+t.rY};case"pill":{const e=t.w/2,n=t.h/2,o=[{x:t.x-e,y:t.y-n},{x:t.x+e,y:t.y-n},{x:t.x+e,y:t.y+n},{x:t.x-e,y:t.y+n}],i=t.ccw_rotation??0,r=i===0?o:o.map(s=>$Ht(s.x,s.y,t.x,t.y,i));return OY(r)}case"polygon":return OY(t.points);case"polygon_with_arcs":{const e=t.brep_shape.outer_ring.vertices.map(n=>({x:n.x,y:n.y}));return OY(e)}case"text":{const e=t.size??0,n=t.text?t.text.length*e*.6:0,o=e;if(n===0&&o===0)return{minX:t.x,maxX:t.x,minY:t.y,maxY:t.y};const i=n/2,r=o/2;return{minX:t.x-i,maxX:t.x+i,minY:t.y-r,maxY:t.y+r}}default:return null}};function yJo(t){const{dimensionStart:e,dimensionEnd:n,screenDimensionStart:o,screenDimensionEnd:i,flipX:r,flipY:s}=t,a=n.x-e.x,A=n.y-e.y,c=Math.sqrt(a*a+A*A),l=i.x-o.x,g=i.y-o.y,u=Math.sqrt(l*l+g*g),h=Math.atan2(g,l)*(180/Math.PI),d=Math.abs(h)%90,m=Math.min(d,90-d)>15,p=(o.x+i.x)/2,I=(o.y+i.y)/2,f=15,C=h+90;let y=Math.cos(C*Math.PI/180)*f,E=Math.sin(C*Math.PI/180)*f;const B=l>0&&g<0,Q=l>0&&g>0,b=l<0&&g>0;r!==s&&!B&&(y=-y,E=-E),B&&(y+=Math.cos(C*Math.PI/180)*-45,E+=Math.sin(C*Math.PI/180)*-45),Q&&(y+=Math.cos(C*Math.PI/180)+-20,E+=Math.sin(C*Math.PI/180)+-10),b&&(y+=Math.cos(C*Math.PI/180)*10,E+=Math.sin(C*Math.PI/180)*10);const D=p+y,R=I+E;return{distance:c,screenDistance:u,x:D,y:R,show:c>.01&&u>30&&m}}function EJo(t){const{dimensionStart:e,dimensionEnd:n,screenDimensionStart:o,screenDimensionEnd:i,flipX:r,flipY:s}=t;return X.useMemo(()=>yJo({dimensionStart:e,dimensionEnd:n,screenDimensionStart:o,screenDimensionEnd:i,flipX:r,flipY:s}),[e,n,o,i,r,s])}var xJo=(t,e,n)=>{const o=n*Math.PI/180,i=Math.cos(o),r=Math.sin(o),s=t.x-e.x,a=t.y-e.y,A=s*i-a*r,c=s*r+a*i;return{x:A+e.x,y:c+e.y}},ZHt=(t,e,n,o)=>{const i={top_left:{x:t.x-e,y:t.y-n},top_center:{x:t.x,y:t.y-n},top_right:{x:t.x+e,y:t.y-n},center_left:{x:t.x-e,y:t.y},center:{x:t.x,y:t.y},center_right:{x:t.x+e,y:t.y},bottom_left:{x:t.x-e,y:t.y+n},bottom_center:{x:t.x,y:t.y+n},bottom_right:{x:t.x+e,y:t.y+n}};return o===0?Object.entries(i).map(([r,s])=>({anchor:r,point:s})):Object.entries(i).map(([r,s])=>({anchor:r,point:xJo(s,t,o)}))},BJo=t=>{switch(t.pcb_drawing_type){case"rect":{const e=t.ccw_rotation??0;return ZHt({x:t.x,y:t.y},t.w/2,t.h/2,e)}case"pill":{const e=t.ccw_rotation??0;return ZHt({x:t.x,y:t.y},t.w/2,t.h/2,e)}case"circle":return[{anchor:"circle_center",point:{x:t.x,y:t.y}},{anchor:"circle_right",point:{x:t.x+t.r,y:t.y}},{anchor:"circle_left",point:{x:t.x-t.r,y:t.y}},{anchor:"circle_top",point:{x:t.x,y:t.y-t.r}},{anchor:"circle_bottom",point:{x:t.x,y:t.y+t.r}}];case"oval":return[{anchor:"oval_center",point:{x:t.x,y:t.y}},{anchor:"oval_right",point:{x:t.x+t.rX,y:t.y}},{anchor:"oval_left",point:{x:t.x-t.rX,y:t.y}},{anchor:"oval_top",point:{x:t.x,y:t.y-t.rY}},{anchor:"oval_bottom",point:{x:t.x,y:t.y+t.rY}}];case"line":{const e={x:(t.x1+t.x2)/2,y:(t.y1+t.y2)/2};return[{anchor:"line_start",point:{x:t.x1,y:t.y1}},{anchor:"line_mid",point:e},{anchor:"line_end",point:{x:t.x2,y:t.y2}}]}case"polygon":return t.points.map((e,n)=>({anchor:`polygon_vertex_${n}`,point:e}));case"polygon_with_arcs":return t.brep_shape.outer_ring.vertices.map((e,n)=>({anchor:`polygon_with_arcs_vertex_${n}`,point:{x:e.x,y:e.y}}));default:return[]}},QJo=16,j6=5,eGt=t=>{if(t.pcb_drawing_type==="text")return!0;const e=t._element;if(!e||typeof e!="object")return!1;const n=typeof e.type=="string"?e.type:void 0;return n?!!(n.startsWith("pcb_silkscreen_")||n.startsWith("pcb_note_")||n==="pcb_text"||n.startsWith("pcb_fabrication_note_")&&n!=="pcb_fabrication_note_rect"):!1},SJo=({children:t,transform:e,focusOnHover:n=!1,primitives:o=[],onBoundsSelected:i,cancelPanDrag:r})=>{e||(e=Hl());const[s,a]=X.useState(!1),[A,c]=X.useState(!1),[l,g]=X.useState(!1),[u,h]=X.useState(!1),[d,_]=X.useState(!1),[m,p]=X.useState(!1),[I,f]=X.useState({start:null,end:null}),C=yd(Me=>Me.is_mouse_over_container),y=X.useCallback(()=>{l&&(g(!1),window.dispatchEvent(new Event("disarm-dimension-tool")))},[l]),E=X.useCallback(()=>{u&&(h(!1),window.dispatchEvent(new Event("disarm-bounds-tool")))},[u]),[B,Q]=X.useState({x:0,y:0}),[b,D]=X.useState({x:0,y:0}),[R,M]=X.useState({x:0,y:0}),[L,G]=X.useState({x:0,y:0}),O=X.useRef({x:0,y:0}),U=X.useRef(null),j=U.current?.getBoundingClientRect(),te=X.useMemo(()=>{const Me=new Map;for(const Ye of o){if(!Ye._element||eGt(Ye)||Ye.pcb_drawing_type==="pill"||Ye.pcb_drawing_type==="rect"&&Ye.ccw_rotation&&Ye.ccw_rotation!==0)continue;const Ie=CJo(Ye);if(!Ie)continue;const We=Me.get(Ye._element);Me.set(Ye._element,fJo(We??void 0,Ie))}return Me},[o]),ie=X.useMemo(()=>{const Me=[];for(const Ye of o){if(!Ye._element||eGt(Ye))continue;const Ie=BJo(Ye);if(Ie.length!==0)for(const We of Ie)Me.push({anchor:We.anchor,point:We.point,element:Ye._element})}return Me},[o]),$=X.useMemo(()=>{const Me=[];te.forEach((Ye,Ie)=>{if(!Ye)return;const We=(Ye.minX+Ye.maxX)/2,Ne=(Ye.minY+Ye.maxY)/2,ke={top_left:{x:Ye.minX,y:Ye.minY},top_center:{x:We,y:Ye.minY},top_right:{x:Ye.maxX,y:Ye.minY},center_left:{x:Ye.minX,y:Ne},center:{x:We,y:Ne},center_right:{x:Ye.maxX,y:Ne},bottom_left:{x:Ye.minX,y:Ye.maxY},bottom_center:{x:We,y:Ye.maxY},bottom_right:{x:Ye.maxX,y:Ye.maxY}};for(const[Ve,Re]of Object.entries(ke))Me.push({anchor:Ve,point:Re,element:Ie})});for(const Ye of ie)Me.push(Ye);return Me.push({anchor:"origin",point:{x:0,y:0},element:null}),Me},[te,ie]),Z=X.useMemo(()=>$.map((Me,Ye)=>({...Me,id:`${Ye}-${Me.anchor}`,screenPoint:mt(e,Me.point)})),[$,e]),se=X.useCallback(Me=>{if(Z.length===0)return{point:Me,id:null};const Ye=mt(e,Me);let Ie=null;for(const We of Z){const Ne=We.screenPoint.x-Ye.x,ke=We.screenPoint.y-Ye.y,Ve=Math.hypot(Ne,ke);Ve>QJo||(!Ie||Ve<Ie.distance)&&(Ie={distance:Ve,id:We.id,point:We.point})}return Ie?{point:Ie.point,id:Ie.id}:{point:Me,id:null}},[Z,e]);X.useEffect(()=>{const Me=We=>{const Ne=We.target;if(Ne.tagName==="INPUT"||Ne.tagName==="TEXTAREA"||Ne.isContentEditable)return;const ke=U.current?.contains(document.activeElement)||document.activeElement===U.current;if(!(!C&&!ke)){if(We.key==="d"){const Ve=se({x:O.current.x,y:O.current.y});Q({x:Ve.point.x,y:Ve.point.y}),D({x:Ve.point.x,y:Ve.point.y}),f({start:Ve.id,end:Ve.id}),s?(a(!1),c(!1),f({start:null,end:null})):(a(!0),c(!0)),y()}We.key==="Escape"&&(a(!1),c(!1),f({start:null,end:null}),_(!1),p(!1),y(),E())}},Ye=()=>{g(!0),h(!1),window.dispatchEvent(new Event("disarm-bounds-tool"))},Ie=()=>{h(!0),g(!1),a(!1),c(!1),window.dispatchEvent(new Event("disarm-dimension-tool"))};return window.addEventListener("keydown",Me),window.addEventListener("arm-dimension-tool",Ye),window.addEventListener("arm-bounds-tool",Ie),()=>{window.removeEventListener("keydown",Me),window.removeEventListener("arm-dimension-tool",Ye),window.removeEventListener("arm-bounds-tool",Ie),y(),E()}},[C,s,y,E,se]);const ae=mt(e,B),ce=mt(e,b),fe=mt(e,R),Ce=mt(e,L),xe={minX:Math.min(R.x,L.x),minY:Math.min(R.y,L.y),maxX:Math.max(R.x,L.x),maxY:Math.max(R.y,L.y)},de={left:Math.min(fe.x,Ce.x),top:Math.min(fe.y,Ce.y),width:Math.abs(fe.x-Ce.x),height:Math.abs(fe.y-Ce.y)},Ee=X.useCallback((Me,Ye)=>{const Ie={minX:Math.min(Me.x,Ye.x),minY:Math.min(Me.y,Ye.y),maxX:Math.max(Me.x,Ye.x),maxY:Math.max(Me.y,Ye.y)};i?.(Ie),window.dispatchEvent(new CustomEvent("pcb-viewer:bounds-selected",{detail:Ie}))},[i]),he={left:Math.min(ae.x,ce.x),right:Math.max(ae.x,ce.x),top:Math.min(ae.y,ce.y),bottom:Math.max(ae.y,ce.y),flipX:ae.x>ce.x,flipY:ae.y>ce.y,width:0,height:0};he.width=he.right-he.left,he.height=he.bottom-he.top;const be=EJo({dimensionStart:B,dimensionEnd:b,screenDimensionStart:ae,screenDimensionEnd:ce,flipX:he.flipX,flipY:he.flipY});return z.jsxs("div",{ref:U,"data-pcb-viewer":!0,tabIndex:0,style:{position:"relative",outline:"none"},onMouseEnter:()=>{n&&U.current&&U.current.focus()},onMouseLeave:()=>{U.current&&U.current.blur()},onClick:()=>{U.current&&U.current.focus()},onMouseMove:Me=>{const Ye=Me.currentTarget.getBoundingClientRect(),Ie=Me.clientX-Ye.left,We=Me.clientY-Ye.top,Ne=mt(MQ(e),{x:Ie,y:We});if(O.current.x=Ne.x,O.current.y=Ne.y,A){const ke=se(Ne);D({x:ke.point.x,y:ke.point.y}),f(Ve=>({...Ve,end:ke.id}))}m&&(r?.(),G({x:Ne.x,y:Ne.y}))},onMouseDown:Me=>{const Ye=Me.currentTarget.getBoundingClientRect(),Ie=Me.clientX-Ye.left,We=Me.clientY-Ye.top,Ne=mt(MQ(e),{x:Ie,y:We});if(u)Me.preventDefault(),Me.stopPropagation(),r?.(),M({x:Ne.x,y:Ne.y}),G({x:Ne.x,y:Ne.y}),_(!0),p(!0),E();else if(l&&!s){const ke=se(Ne);Q({x:ke.point.x,y:ke.point.y}),D({x:ke.point.x,y:ke.point.y}),f({start:ke.id,end:ke.id}),a(!0),c(!0),y()}else A?(c(!1),f(ke=>({...ke,end:null}))):s&&(a(!1),f({start:null,end:null}))},onMouseUp:Me=>{if(!m)return;const Ye=Me.currentTarget.getBoundingClientRect(),Ie=Me.clientX-Ye.left,We=Me.clientY-Ye.top,Ne=mt(MQ(e),{x:Ie,y:We}),ke={x:Ne.x,y:Ne.y};Me.preventDefault(),Me.stopPropagation(),r?.(),G(ke),p(!1),Ee(R,ke)},children:[t,d&&z.jsxs(z.Fragment,{children:[z.jsx("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none",mixBlendMode:"difference",zIndex:Yg.dimensionOverlay},width:j.width,height:j.height,children:z.jsx("rect",{x:de.left,y:de.top,width:de.width,height:de.height,stroke:"red",strokeWidth:1.5,strokeDasharray:"4,3",fill:"rgba(255, 0, 0, 0.12)"})}),z.jsxs("div",{style:{left:0,bottom:s?58:0,position:"absolute",color:"red",fontFamily:"sans-serif",fontSize:12,margin:4,pointerEvents:"none",mixBlendMode:"difference",zIndex:Yg.dimensionOverlay},children:["minX: ",xe.minX.toFixed(2),", minY:"," ",xe.minY.toFixed(2),z.jsx("br",{}),"maxX: ",xe.maxX.toFixed(2),", maxY:"," ",xe.maxY.toFixed(2)]})]}),s&&z.jsxs(z.Fragment,{children:[be.show&&z.jsx("div",{style:{position:"absolute",left:be.x,top:be.y,color:"red",mixBlendMode:"difference",pointerEvents:"none",fontSize:12,fontFamily:"sans-serif",whiteSpace:"nowrap",zIndex:Yg.dimensionOverlay},children:be.distance.toFixed(2)}),z.jsx("div",{style:{position:"absolute",left:he.left,width:he.width,textAlign:"center",top:ae.y+2,color:"red",mixBlendMode:"difference",pointerEvents:"none",marginTop:he.flipY?0:-20,fontSize:12,fontFamily:"sans-serif",zIndex:Yg.dimensionOverlay},children:Math.abs(B.x-b.x).toFixed(2)}),z.jsx("div",{style:{position:"absolute",left:ce.x,height:he.height,display:"flex",flexDirection:"column",justifyContent:"center",top:he.top,color:"red",pointerEvents:"none",mixBlendMode:"difference",fontSize:12,fontFamily:"sans-serif",zIndex:Yg.dimensionOverlay},children:z.jsx("div",{style:{marginLeft:he.flipX?"-100%":4,paddingRight:4},children:Math.abs(B.y-b.y).toFixed(2)})}),z.jsxs("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none",mixBlendMode:"difference",zIndex:Yg.dimensionOverlay},width:j.width,height:j.height,children:[z.jsx("defs",{children:z.jsx("marker",{id:"head",orient:"auto",markerWidth:"3",markerHeight:"4",refX:"2",refY:"2",children:z.jsx("path",{d:"M0,0 V4 L2,2 Z",fill:"red"})})}),z.jsx("line",{x1:ae.x,y1:ae.y,x2:ce.x,y2:ce.y,markerEnd:"url(#head)",strokeWidth:1.5,fill:"none",stroke:"red"}),z.jsx("line",{x1:ae.x,y1:ae.y,x2:ce.x,y2:ae.y,strokeWidth:1.5,fill:"none",strokeDasharray:"2,2",stroke:"red"}),z.jsx("line",{x1:ce.x,y1:ae.y,x2:ce.x,y2:ce.y,strokeWidth:1.5,fill:"none",strokeDasharray:"2,2",stroke:"red"})]}),A&&Z.map(Me=>{const Ye=Me.id===I.start||Me.id===I.end,Ie=j6/2;return z.jsxs("svg",{width:j6,height:j6,style:{position:"absolute",left:Me.screenPoint.x-Ie,top:Me.screenPoint.y-Ie,pointerEvents:"none",zIndex:Yg.dimensionOverlay},children:[z.jsx("line",{x1:0,y1:0,x2:j6,y2:j6,stroke:Ye?"#66ccff":"white",strokeWidth:1}),z.jsx("line",{x1:j6,y1:0,x2:0,y2:j6,stroke:Ye?"#66ccff":"white",strokeWidth:1})]},Me.id)}),z.jsxs("div",{style:{right:0,bottom:0,position:"absolute",color:"red",fontFamily:"sans-serif",fontSize:12,margin:4},children:["(",B.x.toFixed(2),",",B.y.toFixed(2),")",z.jsx("br",{}),"(",b.x.toFixed(2),",",b.y.toFixed(2),")",z.jsx("br",{}),"dist:"," ",Math.sqrt((b.x-B.x)**2+(b.y-B.y)**2).toFixed(2)]})]})]})},bJo=(t,e,n=0)=>{const o=t.width/2,i=t.height/2,r=t.center.x-o-n,s=t.center.x+o+n,a=t.center.y-i-n,A=t.center.y+i+n;return e.x>r&&e.x<s&&e.y>a&&e.y<A},DJo=({children:t,disabled:e,transform:n,soup:o,cancelPanDrag:i,onCreateEditEvent:r,onModifyEditEvent:s})=>{n||(n=Hl());const a=X.useRef(null),[A,c]=X.useState(null),[l,g]=X.useState(null),u=A!==null;yd(m=>m.in_edit_mode);const h=yd(m=>m.in_move_footprint_mode),d=yd(m=>m.setIsMovingComponent),_=e||!h;return z.jsxs("div",{ref:a,style:{position:"relative",overflow:"hidden"},onMouseDown:m=>{if(_)return;const p=m.currentTarget.getBoundingClientRect(),I=m.clientX-p.left,f=m.clientY-p.top;if(Number.isNaN(I)||Number.isNaN(f))return;const C=mt(MQ(n),{x:I,y:f});let y=!1;for(const E of o)if(E.type==="pcb_component"&&bJo(E,C,10/n.a)){i(),c(E.pcb_component_id),y=!0;const B=Math.random().toString();g({dragStart:C,originalCenter:E.center,dragEnd:C,edit_event_id:B}),r({edit_event_id:B,edit_event_type:"edit_pcb_component_location",pcb_edit_event_type:"edit_component_location",pcb_component_id:E.pcb_component_id,original_center:E.center,new_center:E.center,in_progress:!0,created_at:Date.now()}),d(!0);break}if(y||c(null),y)return m.preventDefault(),!1},onMouseMove:m=>{if(!A||!l)return;const p=m.currentTarget.getBoundingClientRect(),I=m.clientX-p.left,f=m.clientY-p.top;if(Number.isNaN(I)||Number.isNaN(f))return;const C=mt(MQ(n),{x:I,y:f});g({...l,dragEnd:C}),s({edit_event_id:l.edit_event_id,new_center:{x:l.originalCenter.x+C.x-l.dragStart.x,y:l.originalCenter.y+C.y-l.dragStart.y}})},onMouseUp:m=>{A&&(c(null),d(!1),l&&(s({edit_event_id:l.edit_event_id,in_progress:!1}),g(null)))},children:[t,!_&&o.filter(m=>m.type==="pcb_component").map(m=>{if(!m?.center)return null;const p=mt(n,m.center);return z.jsx("div",{style:{position:"absolute",pointerEvents:"none",left:p.x,top:p.y,width:m.width*n.a+20,height:m.height*n.a+20,transform:"translate(-50%, -50%)",background:u&&A===m.pcb_component_id?"rgba(255, 0, 0, 0.2)":""}},m.pcb_component_id)})]})},t7e=(t,e)=>{const n=e.current;if(!n)return{transform:"translate(-50%, -100%)",left:t.x,top:t.y};const o=n.getBoundingClientRect(),i=200,r=10,s=60;let a="-50%",A="-100%",c=t.x,l=t.y;return t.x+s+i<o.width-r?(c=t.x+s,a="0%"):t.x-s-i>r?(c=t.x-s,a="-100%"):(c=t.x,a="-50%"),{transform:`translate(${a}, ${A})`,left:c,top:l}},vJo=({center:t})=>z.jsxs("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none",mixBlendMode:"difference",zIndex:Yg.errorOverlay+30},width:"100%",height:"100%",children:[z.jsx("circle",{cx:t.x,cy:t.y,r:11,fill:"none",stroke:"#ff6b6b",strokeWidth:2.5,opacity:.95}),z.jsx("circle",{cx:t.x,cy:t.y,r:4.5,fill:"#ff6b6b",opacity:.95}),z.jsx("line",{x1:t.x-18,y1:t.y,x2:t.x-8,y2:t.y,stroke:"#ff6b6b",strokeWidth:2}),z.jsx("line",{x1:t.x+8,y1:t.y,x2:t.x+18,y2:t.y,stroke:"#ff6b6b",strokeWidth:2}),z.jsx("line",{x1:t.x,y1:t.y-18,x2:t.x,y2:t.y-8,stroke:"#ff6b6b",strokeWidth:2}),z.jsx("line",{x1:t.x,y1:t.y+8,x2:t.x,y2:t.y+18,stroke:"#ff6b6b",strokeWidth:2})]}),tGt=({errorCenter:t,isHighlighted:e=!1})=>z.jsx("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none",mixBlendMode:"difference",zIndex:Yg.errorOverlay},width:"100%",height:"100%",children:z.jsx("rect",{x:t.x-7,y:t.y-7,width:14,height:14,transform:`rotate(45 ${t.x} ${t.y})`,fill:e?"#ff4444":"transparent",stroke:e?"#ff4444":"red",strokeWidth:e?2.5:1.5})}),n7e=iae`
|
|
5689
5689
|
opacity: 0;
|
|
5690
5690
|
pointer-events: none;
|
|
5691
5691
|
background-color: rgba(0, 0, 0, 0.8);
|
|
@@ -5698,7 +5698,7 @@ $1`).replace(/>(\s*)(?=<!--\s*\/)/g,"> ")}}});function CHt(t,e,n){if(!e||!n)retu
|
|
|
5698
5698
|
transition: opacity 0.2s;
|
|
5699
5699
|
margin-bottom: 10px;
|
|
5700
5700
|
color: red;
|
|
5701
|
-
`,PJo=({children:t,transform:e=Hl(),elements:n})=>{const o=X.useRef(null),{isShowingDRCErrors:i,hoveredErrorId:r,focusedErrorId:s}=yd(_=>({isShowingDRCErrors:_.is_showing_drc_errors,hoveredErrorId:_.hovered_error_id,focusedErrorId:_.focused_error_id})),a=s??r;if(!n)return z.jsx("div",{style:{position:"relative"},ref:o,children:t});const A=n.filter(_=>_.type==="pcb_trace_error"&&!_.message?.includes("Multiple components found with name")),c=n.filter(_=>_.type==="pcb_via_clearance_error"),l=n.filter(_=>_.type==="pcb_trace_error"&&_.message?.includes("Multiple components found with name")),g=PHt(n),u=RHt(n,a),h=_=>{const m=oVo({error:_,indexes:g});if(!m||typeof m.x!="number"||typeof m.y!="number")return null;const p=mt(e,m);return Number.isNaN(p.x)||Number.isNaN(p.y)?null:p};let d=null;return u&&(d=h(u)),z.jsxs("div",{style:{position:"relative"},ref:o,children:[t,A.map((_,m)=>{const p=Gk(_,m),I=a===p;if(!I&&!i)return null;const f=h(_);if(!f)return null;const C=t7e(f,o);return z.jsxs(X.Fragment,{children:[z.jsx(tGt,{errorCenter:f,isHighlighted:I}),z.jsx("div",{style:{position:"absolute",left:f.x-15,top:f.y-15,width:30,height:30,zIndex:Yg.errorOverlay+5,cursor:"pointer",borderRadius:"50%"},onMouseEnter:y=>{const E=y.currentTarget.nextElementSibling;if(E){const B=E.querySelector(".error-message");B&&(B.style.opacity="1")}},onMouseLeave:y=>{if(!I){const E=y.currentTarget.nextElementSibling;if(E){const B=E.querySelector(".error-message");B&&(B.style.opacity="0")}}}}),z.jsx("div",{style:{position:"absolute",zIndex:I?200:100,left:C.left,top:C.top,color:I?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:i||I?"flex":"none",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:C.transform},children:z.jsx("div",{className:`error-message ${n7e}`,style:{opacity:I?1:0,border:`1px solid ${I?"#ff4444":"red"}`},children:_.message})})]},p)}),c.map((_,m)=>{const p=Gk(_,m),I=a===p;if(!I&&!i)return null;const f=h(_);if(!f)return null;const C=t7e({x:f.x,y:f.y},o);return z.jsxs(X.Fragment,{children:[z.jsx(tGt,{errorCenter:f,isHighlighted:I}),z.jsx("div",{style:{position:"absolute",left:f.x-15,top:f.y-15,width:30,height:30,zIndex:Yg.errorOverlay+5,cursor:"pointer",borderRadius:"50%"},onMouseEnter:y=>{const E=y.currentTarget.nextElementSibling;if(E){const B=E.querySelector(".error-message");B&&(B.style.opacity="1")}},onMouseLeave:y=>{if(!I){const E=y.currentTarget.nextElementSibling;if(E){const B=E.querySelector(".error-message");B&&(B.style.opacity="0")}}}}),z.jsx("div",{style:{position:"absolute",zIndex:I?Yg.errorOverlay+10:Yg.errorOverlay+1,left:C.left,top:C.top,color:I?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:"flex",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:C.transform},children:z.jsx("div",{className:`error-message ${n7e}`,style:{opacity:I?1:0,border:`1px solid ${I?"#ff4444":"red"}`},children:_.message})})]},p)}),l.map((_,m)=>{const p=_.component_name||_.message?.match(/name "([^"]+)"/)?.[1];if(!p)return null;const I=n?.filter(y=>y.type==="source_component"&&y.name===p||y.type==="pcb_component"&&n?.find(E=>E.type==="source_component"&&E.source_component_id===y.source_component_id&&E.name===p))||[],f=Gk(_,m),C=a===f;return!C&&!i?null:I.map((y,E)=>{let B={x:0,y:0};if(y.type==="pcb_component")B=y.center||{x:0,y:0};else if(y.type==="source_component"){const O=n?.find(U=>U.type==="pcb_component"&&U.source_component_id===y.source_component_id);O&&O.type==="pcb_component"&&(B=O.center||{x:0,y:0})}const Q=mt(e,B);if(Number.isNaN(Q.x)||Number.isNaN(Q.y))return null;const b=Math.abs(e.a),L=Math.max(8,Math.min(30,.5*b)),G=t7e(Q,o);return z.jsxs(X.Fragment,{children:[z.jsx("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none",mixBlendMode:"difference",zIndex:Yg.errorOverlay},width:"100%",height:"100%",children:C?z.jsx("polygon",{points:`${Q.x},${Q.y-L*1.25} ${Q.x+L},${Q.y} ${Q.x},${Q.y+L*1.25} ${Q.x-L},${Q.y}`,fill:"#ff4444"}):z.jsx("circle",{cx:Q.x,cy:Q.y,r:L,fill:"none",stroke:C?"#ff4444":"red",strokeWidth:C?Math.max(2,L*.15):Math.max(1,L*.1),opacity:1})}),z.jsx("div",{style:{position:"absolute",left:Q.x-(L+10),top:Q.y-(L+10),width:(L+10)*2,height:(L+10)*2,zIndex:Yg.errorOverlay+5,cursor:"pointer",borderRadius:"50%"},onMouseEnter:O=>{const U=O.currentTarget.nextElementSibling;if(U){const W=U.querySelector(".error-message");W&&(W.style.opacity="1")}},onMouseLeave:O=>{if(!C){const U=O.currentTarget.nextElementSibling;if(U){const W=U.querySelector(".error-message");W&&(W.style.opacity="0")}}}}),z.jsx("div",{style:{position:"absolute",zIndex:C?Yg.errorOverlay+20:Yg.errorOverlay+10,left:G.left,top:G.top,color:C?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:i||C?"flex":"none",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:G.transform},children:z.jsx("div",{className:`error-message ${n7e}`,style:{opacity:C?1:0,border:`1px solid ${C?"#ff4444":"red"}`},children:_.message})})]},`${f}_${E}`)})}),d&&z.jsx(vJo,{center:d})]})};function wJo(t,e){return t.size!==e.size?!1:Array.from(t).every(n=>e.has(n))}var ew=t=>t?.type==="pcb_component",nGt=t=>t?.type==="pcb_group",MJo=t=>t?.type==="pcb_panel",o7e=t=>t?.type==="pcb_board",yu={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},sE={OFFSET_LINE:"white",COMPONENT_MARKER_FILL:"#66ccff",COMPONENT_MARKER_STROKE:"white",LABEL_TEXT:"white"},i7e=({targets:t,transform:e,containerWidth:n,containerHeight:o})=>{if(t.length===0)return null;const i={color:sE.LABEL_TEXT,mixBlendMode:"difference",pointerEvents:"none",fontSize:yu.LABEL_FONT_SIZE,fontFamily:"monospace",fontWeight:"bold"},r=new Map;return t.forEach(s=>{if(!r.has(s.anchor_id)){const a=mt(e,s.anchor);r.set(s.anchor_id,a)}}),z.jsx("div",{style:{position:"absolute",left:0,top:0,width:n,height:o,overflow:"hidden",pointerEvents:"none",zIndex:Yg.dimensionOverlay},children:z.jsxs("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none"},width:n,height:o,children:[t.map(s=>{const a=s.anchor,A=s.anchor_id,c=s.target,l=r.get(A),g=mt(e,c),u=c.x-a.x,h=c.y-a.y,d=Math.abs(g.x-l.x),_=Math.abs(g.y-l.y),m=g.y<l.y,p=g.x>l.x,I=m?yu.LABEL_OFFSET_ABOVE:yu.LABEL_OFFSET_BELOW,f=p?yu.LABEL_OFFSET_RIGHT:yu.LABEL_OFFSET_LEFT,C=d>yu.MIN_LINE_LENGTH_FOR_LABEL,y=_>yu.MIN_LINE_LENGTH_FOR_LABEL,E=`${s.display_offset_x??u.toFixed(2)}mm`,B=`${s.display_offset_y??h.toFixed(2)}mm`;return z.jsxs("g",{children:[z.jsx("line",{x1:l.x,y1:l.y,x2:g.x,y2:l.y,stroke:sE.OFFSET_LINE,strokeWidth:yu.LINE_STROKE_WIDTH,strokeDasharray:yu.LINE_DASH_PATTERN}),z.jsx("line",{x1:g.x,y1:l.y,x2:g.x,y2:g.y,stroke:sE.OFFSET_LINE,strokeWidth:yu.LINE_STROKE_WIDTH,strokeDasharray:yu.LINE_DASH_PATTERN}),s.type==="component"||s.type==="board"?z.jsx("circle",{cx:g.x,cy:g.y,r:yu.COMPONENT_MARKER_RADIUS,fill:sE.COMPONENT_MARKER_FILL,stroke:sE.COMPONENT_MARKER_STROKE,strokeWidth:1}):z.jsxs(z.Fragment,{children:[z.jsx("line",{x1:g.x-yu.ANCHOR_MARKER_SIZE,y1:g.y,x2:g.x+yu.ANCHOR_MARKER_SIZE,y2:g.y,stroke:sE.OFFSET_LINE,strokeWidth:yu.ANCHOR_MARKER_STROKE_WIDTH}),z.jsx("line",{x1:g.x,y1:g.y-yu.ANCHOR_MARKER_SIZE,x2:g.x,y2:g.y+yu.ANCHOR_MARKER_SIZE,stroke:sE.OFFSET_LINE,strokeWidth:yu.ANCHOR_MARKER_STROKE_WIDTH})]}),C&&z.jsx("foreignObject",{x:Math.min(l.x,g.x),y:l.y+I,width:Math.abs(g.x-l.x),height:20,style:{overflow:"visible"},children:z.jsx("div",{style:{...i,textAlign:"center"},children:E})}),y&&z.jsx("foreignObject",{x:g.x+f,y:Math.min(l.y,g.y),width:yu.Y_LABEL_MIN_WIDTH,height:Math.abs(g.y-l.y),style:{overflow:"visible"},children:z.jsx("div",{style:{...i,display:"flex",alignItems:"center",justifyContent:p?"flex-start":"flex-end",whiteSpace:"nowrap",padding:"0 4px",height:"100%"},children:B})})]},s.id)}),Array.from(r.entries()).map(([s,a])=>z.jsxs("g",{children:[z.jsx("line",{x1:a.x-yu.ANCHOR_MARKER_SIZE,y1:a.y,x2:a.x+yu.ANCHOR_MARKER_SIZE,y2:a.y,stroke:sE.OFFSET_LINE,strokeWidth:yu.ANCHOR_MARKER_STROKE_WIDTH}),z.jsx("line",{x1:a.x,y1:a.y-yu.ANCHOR_MARKER_SIZE,x2:a.x,y2:a.y+yu.ANCHOR_MARKER_SIZE,stroke:sE.OFFSET_LINE,strokeWidth:yu.ANCHOR_MARKER_STROKE_WIDTH})]},`anchor-${s}`))]})})},NJo=({elements:t,highlightedPrimitives:e,transform:n,containerWidth:o,containerHeight:i})=>{const r=t.filter(p=>o7e(p)),s=t.filter(p=>ew(p)),a=t.filter(p=>nGt(p)),A=e.map(p=>ew(p._parent_pcb_component)?p._parent_pcb_component.pcb_component_id:ew(p._element)?p._element.pcb_component_id:null).filter(p=>!!p),c=new Set;if(A.forEach(p=>{const I=s.find(f=>f.pcb_component_id===p);I?.pcb_group_id&&c.add(I.pcb_group_id)}),!yd(p=>p.is_showing_group_anchor_offsets)&&A.length===0)return null;const g=s.map(p=>{const I=p.positioned_relative_to_pcb_board_id;if(!I)return null;const f=r.find(C=>C.pcb_board_id===I);return f?{component:p,board:f,type:"component"}:null}).filter(p=>!!p),u=a.map(p=>{const I=p.positioned_relative_to_pcb_board_id;if(!I||!p.center)return null;const f=r.find(C=>C.pcb_board_id===I);return f?{group:p,board:f,type:"group"}:null}).filter(p=>!!p),h=[...g,...u];if(h.length===0)return null;const d=A.length===0,_=h.filter(p=>p.type==="component"?d||A.includes(p.component.pcb_component_id):d||c.has(p.group.pcb_group_id));if(_.length===0)return null;const m=_.map(p=>p.type==="component"?{id:`${p.board.pcb_board_id}-${p.component.pcb_component_id}-${p.type}`,anchor:p.board.center,anchor_id:p.board.pcb_board_id,target:p.component.center,type:"component",display_offset_x:p.component.display_offset_x,display_offset_y:p.component.display_offset_y}:{id:`${p.board.pcb_board_id}-${p.group.pcb_group_id}-${p.type}`,anchor:p.board.center,anchor_id:p.board.pcb_board_id,target:{x:p.group.anchor_position?.x??p.group.center.x,y:p.group.anchor_position?.y??p.group.center.y},type:"group",display_offset_x:p.group.display_offset_x,display_offset_y:p.group.display_offset_y}).filter(p=>!!p);return z.jsx(i7e,{targets:m,transform:n,containerWidth:o,containerHeight:i})},RJo=({elements:t,highlightedPrimitives:e,transform:n,containerWidth:o,containerHeight:i})=>{const r=t.filter(p=>nGt(p)),s=t.filter(p=>ew(p)),a=e.map(p=>ew(p._parent_pcb_component)?p._parent_pcb_component.pcb_component_id:ew(p._element)?p._element.pcb_component_id:null).filter(p=>!!p),A=(p,I)=>{if(I.has(p))return;I.add(p);const f=r.find(C=>C.pcb_group_id===p);f?.position_mode==="relative_to_group_anchor"&&f.positioned_relative_to_pcb_group_id&&A(f.positioned_relative_to_pcb_group_id,I)},c=new Set;if(a.forEach(p=>{const I=s.find(f=>f.pcb_component_id===p);I&&(I.position_mode==="relative_to_group_anchor"&&I.positioned_relative_to_pcb_group_id&&A(I.positioned_relative_to_pcb_group_id,c),I.pcb_group_id&&A(I.pcb_group_id,c))}),!yd(p=>p.is_showing_group_anchor_offsets)&&a.length===0)return null;const g=s.map(p=>{if(p.position_mode==="relative_to_group_anchor"&&p.positioned_relative_to_pcb_group_id){const I=r.find(f=>f.pcb_group_id===p.positioned_relative_to_pcb_group_id);return I&&I.anchor_position?{component:p,parentGroup:I,type:"component"}:null}if(p.pcb_group_id){const I=r.find(f=>f.pcb_group_id===p.pcb_group_id);return I&&I.anchor_position?{component:p,parentGroup:I,type:"component"}:null}return null}).filter(p=>!!p),u=r.map(p=>{if(p.position_mode==="relative_to_group_anchor"&&p.positioned_relative_to_pcb_group_id){const I=r.find(f=>f.pcb_group_id===p.positioned_relative_to_pcb_group_id);if(I&&I.anchor_position&&p.anchor_position)return{group:p,parentGroup:I,type:"group"}}return null}).filter(p=>!!p),h=[...g,...u];if(h.length===0)return null;const d=a.length===0,_=h.filter(p=>p.type==="component"?d||a.includes(p.component.pcb_component_id):d||c.has(p.group.pcb_group_id)||c.has(p.parentGroup.pcb_group_id));if(_.length===0)return null;const m=_.map(p=>{const I=p.parentGroup.anchor_position;return I?p.type==="component"?p.component.center?{id:`${p.parentGroup.pcb_group_id}-${p.component.pcb_component_id}-${p.type}`,anchor:I,anchor_id:p.parentGroup.pcb_group_id,target:p.component.center,type:"component",display_offset_x:p.component.display_offset_x,display_offset_y:p.component.display_offset_y}:null:p.group.anchor_position?{id:`${p.parentGroup.pcb_group_id}-${p.group.pcb_group_id}-${p.type}`,anchor:I,anchor_id:p.parentGroup.pcb_group_id,target:p.group.anchor_position,type:"group",display_offset_x:p.group.display_offset_x,display_offset_y:p.group.display_offset_y}:null:null}).filter(p=>!!p);return z.jsx(i7e,{targets:m,transform:n,containerWidth:o,containerHeight:i})},TJo=(t,e)=>{const n=t.pcb_component_id,o=e.filter(i=>(i.type==="pcb_smtpad"||i.type==="pcb_plated_hole")&&i.pcb_component_id===n||i.type==="pcb_hole"&&i.pcb_component_id===n);return o.length===0?$9e([t]):$9e(o)},kJo=({elements:t,highlightedPrimitives:e,transform:n,containerWidth:o,containerHeight:i})=>{const r=new Map;for(const a of e)ew(a._parent_pcb_component)&&r.set(a._parent_pcb_component.pcb_component_id,a._parent_pcb_component),ew(a._element)&&r.set(a._element.pcb_component_id,a._element);if(r.size===0)return null;const s=[];for(const a of r.values()){const A=TJo(a,t);if(!A)continue;const c=a.positioned_relative_to_pcb_group_id??a.pcb_group_id,l=c?q6(t).pcb_group.get(c):null;s.push({component:a,bbox:A,group:l})}return s.length===0?null:z.jsx("div",{style:{position:"absolute",left:0,top:0,width:o,height:i,overflow:"hidden",pointerEvents:"none",zIndex:Yg.dimensionOverlay},children:z.jsx("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none"},width:o,height:i,children:s.map(({component:a,bbox:A,group:c})=>{const l=mt(n,{x:A.minX,y:A.maxY}),g=mt(n,{x:A.maxX,y:A.minY}),u={x:Math.min(l.x,g.x),y:Math.min(l.y,g.y),width:Math.abs(g.x-l.x),height:Math.abs(g.y-l.y)},h=a.center??{x:(A.minX+A.maxX)/2,y:(A.minY+A.maxY)/2},d=mt(n,h);return z.jsxs("g",{children:[z.jsx("rect",{x:u.x,y:u.y,width:u.width,height:u.height,fill:"none",stroke:"white",strokeWidth:1.5,strokeDasharray:"4,4"}),z.jsx("line",{x1:d.x-6,y1:d.y,x2:d.x+6,y2:d.y,stroke:sE.COMPONENT_MARKER_STROKE,strokeWidth:1.5}),z.jsx("line",{x1:d.x,y1:d.y-6,x2:d.x,y2:d.y+6,stroke:sE.COMPONENT_MARKER_STROKE,strokeWidth:1.5}),z.jsx("circle",{cx:d.x,cy:d.y,r:yu.COMPONENT_MARKER_RADIUS,fill:sE.COMPONENT_MARKER_FILL,stroke:sE.COMPONENT_MARKER_STROKE,strokeWidth:1})]},a.pcb_component_id)})})})},FJo=({elements:t,highlightedPrimitives:e,transform:n,containerWidth:o,containerHeight:i})=>{const r=t.filter(h=>MJo(h)),s=t.filter(h=>o7e(h)),a=e.map(h=>o7e(h._element)?h._element.pcb_board_id:null).filter(h=>!!h);if(!yd(h=>h.is_showing_group_anchor_offsets)&&a.length===0)return null;const c=s.map(h=>{const d=h.pcb_panel_id,_=h.position_mode;if(!d||_!=="relative_to_panel_anchor")return null;const m=r.find(p=>p.pcb_panel_id===d);return m?{board:h,panel:m,type:"board"}:null}).filter(h=>!!h);if(c.length===0)return null;const l=a.length===0,g=c.filter(h=>l||a.includes(h.board.pcb_board_id));if(g.length===0)return null;const u=g.map(h=>h.board.center?{id:`${h.panel.pcb_panel_id}-${h.board.pcb_board_id}-${h.type}`,anchor:h.panel.center,anchor_id:h.panel.pcb_panel_id,target:h.board.center,type:"board",display_offset_x:h.board.display_offset_x,display_offset_y:h.board.display_offset_y}:null).filter(h=>!!h);return z.jsx(i7e,{targets:u,transform:n,containerWidth:o,containerHeight:i})},dae=t=>t?.trim()||null;function oGt({primitiveElement:t,elements:e}){const n=t.source_trace_id;if(!n)return null;const o=q6(e),i=o.source_trace.get(n),r=dae(i?.name);if(r)return r;const s=o.source_net.get(n),a=dae(s?.name);if(a)return a;for(const A of i?.connected_source_net_ids??[]){const c=dae(o.source_net.get(A)?.name);if(c)return c}return null}function LJo({primitiveElement:t,elements:e}){const n=q6(e).source_trace.get(t?.source_trace_id),o=t.trace_length,i=typeof o=="number",r=n?.max_length,s=i?`${o.toFixed(3)}${typeof r=="number"?` / ${r}`:""} mm`:"",a=oGt({primitiveElement:t,elements:e})??dae(n?.display_name);if(!s&&!a)return null;const A=!!(i&&typeof r=="number"&&o>r);return{text:s,name:a,isOverLength:A}}function HJo(t){const{primitives:e,is_showing_multiple_traces_length:n,elements:o}=t,i=e.filter(A=>A._element.type==="pcb_trace"),r=o.filter(A=>A.type==="source_trace"),s=e.filter(A=>A._element.type!=="pcb_trace"),a=i.filter(A=>r.some(l=>A._element.source_trace_id===l.source_trace_id&&l.max_length!==void 0)||oGt({primitiveElement:A._element,elements:o})!==null);if(!n)return[...s,...a];if(i.length>1){const A=i.reduce((c,l)=>{const g=c._element.trace_length;return l._element.trace_length<g?l:c},i[0]);return[...s,A]}return e}var GJo={position:"absolute",left:0,top:0,pointerEvents:"none",color:"red",fontFamily:"sans-serif",fontSize:12,textShadow:"0 0 2px black"},OJo=t=>{const{_element:e,_parent_pcb_component:n,_parent_source_component:o,_source_port:i}=t;switch(e.type){case"pcb_trace":return e.trace_length?`${e.trace_length.toFixed(3)}`:"";case"pcb_smtpad":case"pcb_plated_hole":{const r=[],s=Array.from(new Set((e.port_hints??[]).concat(i?.port_hints??[]))).filter(A=>!/^[0-9]+$/.test(A)).filter(A=>!A.includes("unnamed_")).sort((A,c)=>c.localeCompare(A)),a=o&&"name"in o&&o.name&&!o.name.includes("unnamed_")?o.name:null;return s.length>0?a?r.push(...s.map(A=>`${a}.${A}`)):r.push(...s):a&&r.push(a),r.join(", ")}default:return""}},KJo={top:"red",bottom:"aqua"},UJo=({primitive:t,mousePos:e,elements:n})=>{const[o,i]=X.useState(!1),r=t._element;X.useEffect(()=>{setTimeout(()=>{i(!0)},100)},[]);const[s,a,A,c]=[t.screen_x,t.screen_y,t.screen_w,t.screen_h],l=t.same_space_index??0,g=26,u=KJo[t?._element?.layer]??"red";let h=0;if(r.type==="pcb_smtpad"&&r?.shape==="rotated_rect"?h=r?.ccw_rotation??0:(r.type==="pcb_smtpad"&&(r?.shape==="pill"||r?.shape==="rotated_pill")&&"ccw_rotation"in t||r.type==="pcb_plated_hole"&&(r?.shape==="pill"||r?.shape==="oval")&&"ccw_rotation"in t)&&(h=r.ccw_rotation??0),r.type==="pcb_trace"){const m=LJo({primitiveElement:r,elements:n});return m?z.jsx("div",{style:{zIndex:Yg.elementOverlay,position:"absolute",left:e.x+12,top:e.y+12,color:u,pointerEvents:"none"},children:z.jsxs("div",{style:{backgroundColor:"#f2efcc",color:m.isOverLength?"red":"black",textShadow:"none",WebkitFontSmoothing:"antialiased",MozOsxFontSmoothing:"grayscale",padding:"4px 6px",borderRadius:"4px",fontSize:"11px",lineHeight:1.2,textAlign:"left",whiteSpace:"nowrap"},children:[m.text&&z.jsx("div",{children:m.text}),m.name&&z.jsx("div",{style:{marginTop:m.text?"2px":0},children:m.name})]})}):null}const d=OJo(t);return d.trim().length===0?null:z.jsx("div",{style:{zIndex:Yg.elementOverlay,position:"absolute",left:s-A/2-8,top:a-c/2-8,width:A+16,height:c+16,color:u,transform:`rotate(${-h}deg)`,transformOrigin:"center center"},children:z.jsx("div",{style:{width:o?`calc(100% + ${g*2*l}px)`:"100%",height:o?`calc(100% + ${g*2*l}px)`:"100%",marginLeft:o?`${-g*l}px`:0,marginTop:o?`${-g*l}px`:0,border:`1px solid ${u}`,opacity:o||l===0?1:0,transition:"width 0.2s, height 0.2s, margin-left 0.2s, margin-top 0.2s, opacity 0.2s"},children:z.jsx("div",{style:{position:"absolute",bottom:c+20+g*l,marginRight:o?`${-g*l}px`:0,marginBottom:o?0:-g*l,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(${h}deg)`,minWidth:"45px",textAlign:"center"},children:d})})})},YJo=({highlightedPrimitives:t,mousePos:e,elements:n})=>{const[o,i]=yd(a=>[a.is_moving_component,a.is_showing_multiple_traces_length]),r=t.some(a=>a._element.type==="pcb_smtpad")&&t.some(a=>a._element.type==="pcb_trace");let s=t;return r&&(s=s.filter(a=>a._element.type==="pcb_smtpad")),s=HJo({primitives:s,is_showing_multiple_traces_length:i,elements:n}),z.jsx("div",{style:GJo,children:!o&&s.map(a=>z.jsx(UJo,{primitive:a,mousePos:e,elements:n},a._pcb_drawing_object_id))})},hae=t=>{if(t.length===0)return null;let e=t[0].x,n=t[0].y,o=t[0].x,i=t[0].y;for(const r of t)r.x<e&&(e=r.x),r.y<n&&(n=r.y),r.x>o&&(o=r.x),r.y>i&&(i=r.y);return{center:{x:(e+o)/2,y:(n+i)/2},width:o-e,height:i-n}},iGt=(t,e)=>{if(e.length<3)return!1;let n=!1;for(let o=0,i=e.length-1;o<e.length;i=o++){const r=e[o].x,s=e[o].y,a=e[i].x,A=e[i].y;s>t.y!=A>t.y&&t.x<(a-r)*(t.y-s)/(A-s||Number.EPSILON)+r&&(n=!n)}return n},zJo=(t,e,n,o)=>{const i=[];for(const r of t){if(!r._element||r._element.type==="pcb_trace"&&r.layer!==o)continue;if("x1"in r&&r._element?.type==="pcb_trace"){const A=gm({x:e.x,y:e.y},{x:r.x1,y:r.y1},{x:r.x2,y:r.y2}),c=r.width||.5,l=Math.max(c*25,2)/n.a;A<l&&i.push(r);continue}if(r.pcb_drawing_type==="polygon"){const A=r.points.map(l=>({x:En.parse(l.x),y:En.parse(l.y)})),c=hae(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;iGt(e,A)&&i.push(r);continue}if(r.pcb_drawing_type==="polygon_with_arcs"){const A=r.brep_shape.outer_ring.vertices.map(l=>({x:En.parse(l.x),y:En.parse(l.y)})),c=hae(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;iGt(e,A)&&i.push(r);continue}if(!("x"in r&&"y"in r))continue;let s=0,a=0;if("w"in r&&"h"in r)s=r.w,a=r.h;else if("r"in r)s=r.r*2,a=r.r*2;else if("rX"in r&&"rY"in r)s=r.rX*2,a=r.rY*2;else continue;Math.abs(r.x-e.x)<s/2&&Math.abs(r.y-e.y)<a/2&&i.push(r)}return i},VJo=({elements:t,children:e,transform:n,primitives:o,selectedLayer:i,onMouseHoverOverPrimitives:r})=>{const[s,a]=X.useState([]),[A,c]=X.useState({x:0,y:0}),[l,{width:g,height:u}]=GY();X.useEffect(()=>{a([]),r([])},[i,r]);const h=X.useMemo(()=>{const _=[];for(const m of s){if(m._element?.type==="pcb_via"||m._element?.type==="pcb_component"||m?.layer==="drill"||m?.is_hoverable===!1)continue;let p=null,I=0,f=0;if(m.pcb_drawing_type==="polygon"){const B=hae(m.points);if(!B)continue;p=B.center,I=B.width,f=B.height}else if(m.pcb_drawing_type==="polygon_with_arcs"){const B=m.brep_shape.outer_ring.vertices.map(b=>({x:b.x,y:b.y})),Q=hae(B);if(!Q)continue;p=Q.center,I=Q.width,f=Q.height}else m.pcb_drawing_type==="line"?(p={x:(m.x1+m.x2)/2,y:(m.y1+m.y2)/2},I=Math.abs(m.x2-m.x1),f=Math.abs(m.y2-m.y1)):"x"in m&&"y"in m&&(p={x:m.x,y:m.y},I="w"in m?m.w:"r"in m?m.r*2:"rX"in m&&"rY"in m?m.rX*2:0,f="h"in m?m.h:"r"in m?m.r*2:"rX"in m&&"rY"in m?m.rY*2:0);if(!p)continue;const C=mt(n,p),y={w:I*n.a,h:f*n.a},E=_.filter(B=>C.x===B.screen_x&&C.y===B.screen_y&&y.w===B.screen_w&&y.h===B.screen_h).length;_.push({...m,x:p.x,y:p.y,w:I,h:f,screen_x:C.x,screen_y:C.y,screen_w:y.w,screen_h:y.h,same_space_index:E})}return _},[s,n]),d=(_,m,p,I)=>{c({x:_,y:m});const f=mt(MQ(p),{x:_,y:m}),C=zJo(I,f,p,i);wJo(new Set(C.map(y=>y._pcb_drawing_object_id)),new Set(s.map(y=>y._pcb_drawing_object_id)))||(a(C),r(C))};return z.jsxs("div",{ref:l,style:{position:"relative",width:"100%",height:"100%"},onMouseMove:_=>{if(n){const m=_.currentTarget.getBoundingClientRect(),p=_.clientX-m.left,I=_.clientY-m.top;d(p,I,n,o)}},onTouchStart:_=>{if(n){const m=_.touches[0],p=_.currentTarget.getBoundingClientRect(),I=m.clientX-p.left,f=m.clientY-p.top;d(I,f,n,o)}},children:[e,z.jsx(YJo,{elements:t,mousePos:A,highlightedPrimitives:h}),n&&z.jsxs(z.Fragment,{children:[z.jsx(NJo,{elements:t,highlightedPrimitives:h,transform:n,containerWidth:g,containerHeight:u}),z.jsx(RJo,{elements:t,highlightedPrimitives:h,transform:n,containerWidth:g,containerHeight:u}),z.jsx(kJo,{elements:t,highlightedPrimitives:h,transform:n,containerWidth:g,containerHeight:u}),z.jsx(FJo,{elements:t,highlightedPrimitives:h,transform:n,containerWidth:g,containerHeight:u})]})]})},rGt=["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)"],JJo=({children:t,transform:e=Hl(),elements:n=[],hoveredComponentIds:o=[]})=>{const[i,{width:r,height:s}]=GY(),a=X.useRef(null),{is_showing_pcb_groups:A,pcb_group_view_mode:c,is_showing_group_anchor_offsets:l}=yd(g=>({is_showing_pcb_groups:g.is_showing_pcb_groups,pcb_group_view_mode:g.pcb_group_view_mode,is_showing_group_anchor_offsets:g.is_showing_group_anchor_offsets}));return X.useEffect(()=>{const g=a.current;if(!g||!r||!s)return;g.width=r,g.height=s;const u=g.getContext("2d");if(!u||(u.clearRect(0,0,r,s),!A))return;const h=n.filter(E=>E.type==="pcb_group"),d=n.filter(E=>E.type==="pcb_component"),_=n.filter(E=>E.type==="source_group"),m=new Map(_.map(E=>[E.source_group_id,E])),p=h.filter(E=>{if(E.name?.toLowerCase().includes("subpanel"))return!1;if(c==="all")return!0;if(!E.source_group_id)return!1;const B=m.get(E.source_group_id);return B?B.was_automatically_named!==!0:!1}),I=new Map;_.forEach(E=>{const B=E;if(B.parent_source_group_id){const Q=I.get(B.parent_source_group_id)||[];Q.push(E.source_group_id),I.set(B.parent_source_group_id,Q)}});const f=E=>{const B=[],Q=I.get(E)||[];for(const b of Q)B.push(b),B.push(...f(b));return B},C=E=>{const B=_.find(Q=>Q.source_group_id===E);return B?.parent_source_group_id?1+C(B.parent_source_group_id):0},y=new Set;if(o.length>0)for(const E of d){if(!o.includes(E.pcb_component_id))continue;const B=E.positioned_relative_to_pcb_group_id??E.pcb_group_id;B&&y.add(B)}p.forEach((E,B)=>{let Q=d.filter(ke=>ke.pcb_group_id===E.pcb_group_id);if(E.source_group_id){const ke=f(E.source_group_id),Ve=h.filter(Re=>Re.source_group_id&&ke.includes(Re.source_group_id));for(const Re of Ve){const Se=d.filter(Oe=>Oe.pcb_group_id===Re.pcb_group_id);Q=[...Q,...Se]}}let b,D,R,M,L=!1;if(E.center&&E.width&&E.height){L=!0;const ke=E.width/2,Ve=E.height/2;b=E.center.x-ke,R=E.center.x+ke,D=E.center.y-Ve,M=E.center.y+Ve}else if(Q.length===0||(b=1/0,D=1/0,R=-1/0,M=-1/0,Q.forEach(ke=>{if(ke.center&&typeof ke.width=="number"&&typeof ke.height=="number"){const Ve=ke.center.x-ke.width/2,Re=ke.center.x+ke.width/2,Se=ke.center.y+ke.height/2,Oe=ke.center.y-ke.height/2;b=Math.min(b,Ve),R=Math.max(R,Re),D=Math.min(D,Oe),M=Math.max(M,Se)}}),b===1/0||R===-1/0))return;const G=E.source_group_id?C(E.source_group_id):0,O=E.source_group_id?f(E.source_group_id).length>0:!1;if(!L){const Re=1+(O?.5:0);b-=Re,R+=Re,D-=Re,M+=Re}const U=mt(e,{x:b,y:M}),W=mt(e,{x:R,y:M}),j=mt(e,{x:b,y:D}),te=mt(e,{x:R,y:D}),ie=rGt[B%rGt.length];u.strokeStyle=ie,u.lineWidth=2;const $=Math.max(4,Math.min(12,8*Math.abs(e.a))),Z=Math.max(2,Math.min(6,4*Math.abs(e.a))),ae=$*(O?1.3:1),ce=Z;u.setLineDash([ae,ce]),u.beginPath(),u.moveTo(U.x,U.y),u.lineTo(W.x,W.y),u.lineTo(te.x,te.y),u.lineTo(j.x,j.y),u.closePath(),u.stroke();const fe=Math.max(8,Math.min(12,10*Math.abs(e.a))),Ce=G==0||G==1?0:G*.11,xe=fe*(1-Ce),de=4,Ee=E.name||`Group ${B+1}`;u.font=`${xe}px sans-serif`,u.setLineDash([]);const be=u.measureText(Ee).width+de*2,Me=xe+de*2,Ye=U.x-5,Ie=U.y-5,We=3;if(u.fillStyle="rgba(0, 0, 0, 0.8)",u.beginPath(),u.roundRect(Ye,Ie-Me,be,Me,We),u.fill(),u.fillStyle=ie,u.textAlign="left",u.textBaseline="middle",u.fillText(Ee,Ye+de,Ie-Me/2),l&&y.has(E.pcb_group_id)&&!!E.anchor_position&&E.anchor_position){const ke=Array.isArray(E.anchor_position)?{x:E.anchor_position[0]??0,y:E.anchor_position[1]??0}:{x:E.anchor_position.x,y:E.anchor_position.y},Ve=mt(e,ke);u.strokeStyle="white",u.lineWidth=1.5,u.setLineDash([]);const Re=Math.max(4,Math.min(8,6*Math.abs(e.a)));u.beginPath(),u.moveTo(Ve.x-Re,Ve.y),u.lineTo(Ve.x+Re,Ve.y),u.stroke(),u.beginPath(),u.moveTo(Ve.x,Ve.y-Re),u.lineTo(Ve.x,Ve.y+Re),u.stroke()}})},[n,e,r,s,A,c,l,o]),z.jsxs("div",{ref:i,style:{position:"relative",width:"100%",height:"100%"},children:[t,z.jsx("canvas",{ref:a,style:{position:"absolute",top:0,left:0,pointerEvents:"none",zIndex:Yg.pcbGroupOverlay,display:A?"block":"none"}})]})},qJo=({transform:t,soup:e,children:n})=>{const o=yd(a=>a.is_showing_rats_nest),{netMap:i,idToNetMap:r}=X.useMemo(()=>vHt(e||[]),[e]),s=X.useMemo(()=>{if(!e||!o)return[];const a=u=>{const h=q6(e)[u.replace(/_\d+$/,"")].get(u);return h&&"x"in h&&"y"in h?{x:h.x,y:h.y}:null},A=(u,h)=>{const d=i[h]||[];let _=null,m=1/0;return d.forEach(p=>{const I=a(p);if(I){const f=Math.sqrt((u.x-I.x)**2+(u.y-I.y)**2);f<m&&f>0&&(m=f,_=I)}}),_},c=q6(e).pcb_port.list(),l=q6(e).source_trace.list(),g=[];return c.forEach((u,h)=>{const d=r[u.pcb_port_id];let _=!1;for(const I of l)I.connected_source_port_ids.includes(u.source_port_id)&&I.connected_source_net_ids.length>0&&(_=!0);if(!d)return;const m={x:u.x,y:u.y},p=A(m,d);p&&g.push({key:`${u.pcb_port_id}-${h}`,startPoint:m,endPoint:p,isInNet:_})}),g},[e,i,r,o]);return!e||!o?n:(t||(t=Hl()),z.jsxs("div",{style:{position:"relative"},children:[n,z.jsx("svg",{style:{position:"absolute",left:0,top:0,width:"100%",height:"100%",pointerEvents:"none",opacity:.5,zIndex:Yg.ratsNestOverlay},children:s.map(({key:a,startPoint:A,endPoint:c,isInNet:l})=>{const g=mt(t,A),u=mt(t,c);return z.jsx("line",{x1:g.x,y1:g.y,x2:u.x,y2:u.y,stroke:"white",strokeWidth:"1",strokeDasharray:l?"6,6":void 0},a)})})]}))},WJo={version:"1.11.387"},hb=(t,e,n)=>{const o=yd(s=>s.is_mouse_over_container),i=X.useRef(o),r=X.useRef(e);X.useEffect(()=>{i.current=o},[o]),X.useEffect(()=>{r.current=e},[e]),X.useEffect(()=>{if(!t)return;const s=a=>{const A=a.target;if(A.tagName==="INPUT"||A.tagName==="TEXTAREA"||A.isContentEditable)return;const c=t.split("+"),l=c.includes("ctrl"),g=c.includes("shift"),u=c.includes("alt"),h=c.includes("meta"),d=c[c.length-1],_=n?.current?n.current.contains(document.activeElement)||document.activeElement===n.current:!1;(i.current||_)&&(!l||a.ctrlKey)&&(!g||a.shiftKey)&&(!u||a.altKey)&&(!h||a.metaKey)&&a.key.toLowerCase()===d.toLowerCase()&&(a.preventDefault(),r.current())};return window.addEventListener("keydown",s),()=>{window.removeEventListener("keydown",s)}},[t])},jJo=()=>{const[t,e]=X.useState(!1);return X.useEffect(()=>{const n=()=>{e(window.innerWidth<=768)};return n(),window.addEventListener("resize",n),()=>window.removeEventListener("resize",n)},[]),t},KY=(t,e={stopPropagation:!0})=>{const n=X.useRef(0),o=X.useCallback(s=>{e.stopPropagation&&s.stopPropagation();const a=Date.now();a-n.current<300||(n.current=a,t?.(s))},[t,e.stopPropagation]),i=X.useCallback(s=>{s.preventDefault(),o(s)},[o]);return{onClick:o,onTouchEnd:i,style:{touchAction:"manipulation"}}},Ok=({children:t,isSmallScreen:e,onClick:n,...o})=>{const{style:i,...r}=KY(n);return z.jsx("div",{...o,...r,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,...o.style},children:t})},XJo=t=>{const e=new Map;return t.forEach((n,o)=>{const i=n.error_type||"unknown_error",r=e.get(i)||[];r.push({error:n,index:o,errorId:Gk(n,o)}),e.set(i,r)}),Array.from(e.entries()).map(([n,o])=>({errorType:n,errors:o}))},$Jo=({onClose:t,setHoveredErrorId:e,setFocusedErrorId:n,highlightDurationMs:o=3e3})=>{const i=X.useRef(null),r=X.useRef(null),s=X.useRef(null),a=X.useCallback(()=>{i.current!==null&&(window.clearTimeout(i.current),i.current=null),r.current!==null&&(window.cancelAnimationFrame(r.current),r.current=null)},[]);X.useEffect(()=>a,[a]);const A=X.useCallback(l=>{a(),s.current=l,e(l),n(null),r.current=window.requestAnimationFrame(()=>{n(l),r.current=null}),t(),i.current=window.setTimeout(()=>{s.current=null,e(null),n(null),i.current=null},o)},[a,o,t,n,e]),c=X.useCallback(l=>s.current===l,[]);return{handleErrorSelect:A,isSelectedError:c}},ZJo=({errorId:t,errorMessage:e,copiedErrorId:n,onCopy:o})=>{const{style:i,...r}=KY(()=>o(e,t));return z.jsx("button",{type:"button","aria-label":n===t?"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},...r,children:n===t?z.jsx("span",{style:{color:"#4caf50",fontSize:12},children:"Copied!"}):z.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"currentColor",children:z.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"})})})},eqo=({elements:t,isOpen:e,isSmallScreen:n,onToggle:o,onClose:i,setHoveredErrorId:r,setFocusedErrorId:s})=>{const[a,A]=X.useState(null),[c,l]=X.useState(new Set),[g,u]=X.useState(new Set),[,h]=Fzo(),{handleErrorSelect:d,isSelectedError:_}=$Jo({onClose:i,setHoveredErrorId:r,setFocusedErrorId:s}),m=X.useMemo(()=>t?.filter(y=>y.type.includes("error"))??[],[t]),p=m.length,I=X.useMemo(()=>XJo(m),[m]),f=X.useCallback(y=>{l(E=>{const B=new Set(E);return B.has(y)?B.delete(y):B.add(y),B})},[]),C=X.useCallback(y=>{u(E=>{const B=new Set(E);return B.has(y)?B.delete(y):B.add(y),B})},[]);return z.jsxs("div",{style:{position:"relative"},children:[z.jsx(Ok,{isSmallScreen:n,style:p>0?{color:"red"}:void 0,onClick:o,children:z.jsxs("div",{children:[p," errors"]})}),e&&p>0&&z.jsx("div",{style:{position:"absolute",top:"100%",left:0,backgroundColor:"#2a2a2a",border:"1px solid #666",borderRadius:4,marginTop:4,zIndex:1e3,minWidth:n?"280px":"400px",maxWidth:n?"90vw":"600px",maxHeight:"400px",overflow:"auto",boxShadow:"0 4px 12px rgba(0, 0, 0, 0.3)"},children:I.map(({errorType:y,errors:E},B)=>{const Q=c.has(y);return z.jsxs("div",{style:{borderBottom:B<I.length-1?"1px solid #444":"none"},children:[z.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:b=>{b.currentTarget.style.backgroundColor="#303030"},onMouseLeave:b=>{b.currentTarget.style.backgroundColor="#232323"},onTouchStart:b=>{b.stopPropagation(),b.currentTarget.style.backgroundColor="#303030"},onTouchEnd:b=>{b.stopPropagation(),b.preventDefault(),b.currentTarget.style.backgroundColor="#232323",f(y)},onClick:b=>{b.stopPropagation(),f(y)},children:[z.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,color:"#ff6b6b"},children:[z.jsx("div",{style:{color:"#888",fontSize:"16px",transform:Q?"rotate(90deg)":"rotate(0deg)",transition:"transform 0.2s ease",flexShrink:0},children:"›"}),z.jsx("div",{style:{fontWeight:"bold",fontSize:n?"12px":"13px"},children:y})]}),z.jsx("div",{style:{fontSize:n?"12px":"13px",color:"#aaa",whiteSpace:"nowrap",marginLeft:12},children:E.length})]}),!Q&&E.map(({error:b,index:D,errorId:R})=>{const M=g.has(R),L=b.message??"No error message";return z.jsxs("div",{style:{borderTop:"1px solid #3a3a3a"},children:[z.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:G=>{G.currentTarget.style.backgroundColor="#333",r(R)},onMouseLeave:G=>{G.currentTarget.style.backgroundColor="#2a2a2a",_(R)||r(null)},onTouchStart:G=>{G.stopPropagation(),G.currentTarget.style.backgroundColor="#333",r(R)},onTouchEnd:G=>{G.stopPropagation(),G.preventDefault(),G.currentTarget.style.backgroundColor="#2a2a2a",d(R)},onClick:G=>{G.stopPropagation(),d(R)},children:[z.jsx("div",{style:{flex:1,fontSize:n?"12px":"13px",color:"#ddd",lineHeight:1.4,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",userSelect:"text"},children:L}),z.jsx("button",{type:"button","aria-label":M?"Collapse error details":"Expand error details",style:{color:"#888",fontSize:"16px",transform:M?"rotate(0deg)":"rotate(90deg)",transition:"transform 0.2s ease",flexShrink:0,background:"none",border:"none",padding:0,cursor:"pointer"},onMouseDown:G=>G.stopPropagation(),onClick:G=>{G.stopPropagation(),C(R)},onTouchEnd:G=>{G.stopPropagation(),G.preventDefault(),C(R)},children:"›"})]}),M&&z.jsxs("div",{"data-error-id":D,style:{display:"block",padding:"12px 16px 12px 24px",backgroundColor:"#1a1a1a",borderTop:"1px solid #444",position:"relative"},children:[z.jsx("div",{style:{fontSize:n?"11px":"12px",color:"#ccc",lineHeight:1.5,wordWrap:"break-word",overflowWrap:"break-word",hyphens:"auto",userSelect:"text",paddingRight:30},onMouseDown:G=>G.stopPropagation(),onClick:G=>G.stopPropagation(),children:L}),z.jsx(ZJo,{errorId:R,errorMessage:L,copiedErrorId:a,onCopy:(G,O)=>{h(G),A(O),setTimeout(()=>A(null),2e3)}})]})]},R)})]},y)})})]})},tqo=({name:t,selected:e,onClick:n})=>{const{style:o,...i}=KY(n);return z.jsxs("div",{className:iae`
|
|
5701
|
+
`,PJo=({children:t,transform:e=Hl(),elements:n})=>{const o=X.useRef(null),{isShowingDRCErrors:i,hoveredErrorId:r,focusedErrorId:s}=yd(_=>({isShowingDRCErrors:_.is_showing_drc_errors,hoveredErrorId:_.hovered_error_id,focusedErrorId:_.focused_error_id})),a=s??r;if(!n)return z.jsx("div",{style:{position:"relative"},ref:o,children:t});const A=n.filter(_=>_.type==="pcb_trace_error"&&!_.message?.includes("Multiple components found with name")),c=n.filter(_=>_.type==="pcb_via_clearance_error"),l=n.filter(_=>_.type==="pcb_trace_error"&&_.message?.includes("Multiple components found with name")),g=PHt(n),u=RHt(n,a),h=_=>{const m=oVo({error:_,indexes:g});if(!m||typeof m.x!="number"||typeof m.y!="number")return null;const p=mt(e,m);return Number.isNaN(p.x)||Number.isNaN(p.y)?null:p};let d=null;return u&&(d=h(u)),z.jsxs("div",{style:{position:"relative"},ref:o,children:[t,A.map((_,m)=>{const p=Gk(_,m),I=a===p;if(!I&&!i)return null;const f=h(_);if(!f)return null;const C=t7e(f,o);return z.jsxs(X.Fragment,{children:[z.jsx(tGt,{errorCenter:f,isHighlighted:I}),z.jsx("div",{style:{position:"absolute",left:f.x-15,top:f.y-15,width:30,height:30,zIndex:Yg.errorOverlay+5,cursor:"pointer",borderRadius:"50%"},onMouseEnter:y=>{const E=y.currentTarget.nextElementSibling;if(E){const B=E.querySelector(".error-message");B&&(B.style.opacity="1")}},onMouseLeave:y=>{if(!I){const E=y.currentTarget.nextElementSibling;if(E){const B=E.querySelector(".error-message");B&&(B.style.opacity="0")}}}}),z.jsx("div",{style:{position:"absolute",zIndex:I?200:100,left:C.left,top:C.top,color:I?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:i||I?"flex":"none",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:C.transform},children:z.jsx("div",{className:`error-message ${n7e}`,style:{opacity:I?1:0,border:`1px solid ${I?"#ff4444":"red"}`},children:_.message})})]},p)}),c.map((_,m)=>{const p=Gk(_,m),I=a===p;if(!I&&!i)return null;const f=h(_);if(!f)return null;const C=t7e({x:f.x,y:f.y},o);return z.jsxs(X.Fragment,{children:[z.jsx(tGt,{errorCenter:f,isHighlighted:I}),z.jsx("div",{style:{position:"absolute",left:f.x-15,top:f.y-15,width:30,height:30,zIndex:Yg.errorOverlay+5,cursor:"pointer",borderRadius:"50%"},onMouseEnter:y=>{const E=y.currentTarget.nextElementSibling;if(E){const B=E.querySelector(".error-message");B&&(B.style.opacity="1")}},onMouseLeave:y=>{if(!I){const E=y.currentTarget.nextElementSibling;if(E){const B=E.querySelector(".error-message");B&&(B.style.opacity="0")}}}}),z.jsx("div",{style:{position:"absolute",zIndex:I?Yg.errorOverlay+10:Yg.errorOverlay+1,left:C.left,top:C.top,color:I?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:"flex",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:C.transform},children:z.jsx("div",{className:`error-message ${n7e}`,style:{opacity:I?1:0,border:`1px solid ${I?"#ff4444":"red"}`},children:_.message})})]},p)}),l.map((_,m)=>{const p=_.component_name||_.message?.match(/name "([^"]+)"/)?.[1];if(!p)return null;const I=n?.filter(y=>y.type==="source_component"&&y.name===p||y.type==="pcb_component"&&n?.find(E=>E.type==="source_component"&&E.source_component_id===y.source_component_id&&E.name===p))||[],f=Gk(_,m),C=a===f;return!C&&!i?null:I.map((y,E)=>{let B={x:0,y:0};if(y.type==="pcb_component")B=y.center||{x:0,y:0};else if(y.type==="source_component"){const O=n?.find(U=>U.type==="pcb_component"&&U.source_component_id===y.source_component_id);O&&O.type==="pcb_component"&&(B=O.center||{x:0,y:0})}const Q=mt(e,B);if(Number.isNaN(Q.x)||Number.isNaN(Q.y))return null;const b=Math.abs(e.a),L=Math.max(8,Math.min(30,.5*b)),G=t7e(Q,o);return z.jsxs(X.Fragment,{children:[z.jsx("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none",mixBlendMode:"difference",zIndex:Yg.errorOverlay},width:"100%",height:"100%",children:C?z.jsx("polygon",{points:`${Q.x},${Q.y-L*1.25} ${Q.x+L},${Q.y} ${Q.x},${Q.y+L*1.25} ${Q.x-L},${Q.y}`,fill:"#ff4444"}):z.jsx("circle",{cx:Q.x,cy:Q.y,r:L,fill:"none",stroke:C?"#ff4444":"red",strokeWidth:C?Math.max(2,L*.15):Math.max(1,L*.1),opacity:1})}),z.jsx("div",{style:{position:"absolute",left:Q.x-(L+10),top:Q.y-(L+10),width:(L+10)*2,height:(L+10)*2,zIndex:Yg.errorOverlay+5,cursor:"pointer",borderRadius:"50%"},onMouseEnter:O=>{const U=O.currentTarget.nextElementSibling;if(U){const W=U.querySelector(".error-message");W&&(W.style.opacity="1")}},onMouseLeave:O=>{if(!C){const U=O.currentTarget.nextElementSibling;if(U){const W=U.querySelector(".error-message");W&&(W.style.opacity="0")}}}}),z.jsx("div",{style:{position:"absolute",zIndex:C?Yg.errorOverlay+20:Yg.errorOverlay+10,left:G.left,top:G.top,color:C?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:i||C?"flex":"none",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:G.transform},children:z.jsx("div",{className:`error-message ${n7e}`,style:{opacity:C?1:0,border:`1px solid ${C?"#ff4444":"red"}`},children:_.message})})]},`${f}_${E}`)})}),d&&z.jsx(vJo,{center:d})]})};function wJo(t,e){return t.size!==e.size?!1:Array.from(t).every(n=>e.has(n))}var ew=t=>t?.type==="pcb_component",nGt=t=>t?.type==="pcb_group",MJo=t=>t?.type==="pcb_panel",o7e=t=>t?.type==="pcb_board",yu={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},sE={OFFSET_LINE:"white",COMPONENT_MARKER_FILL:"#66ccff",COMPONENT_MARKER_STROKE:"white",LABEL_TEXT:"white"},i7e=({targets:t,transform:e,containerWidth:n,containerHeight:o})=>{if(t.length===0)return null;const i={color:sE.LABEL_TEXT,mixBlendMode:"difference",pointerEvents:"none",fontSize:yu.LABEL_FONT_SIZE,fontFamily:"monospace",fontWeight:"bold"},r=new Map;return t.forEach(s=>{if(!r.has(s.anchor_id)){const a=mt(e,s.anchor);r.set(s.anchor_id,a)}}),z.jsx("div",{style:{position:"absolute",left:0,top:0,width:n,height:o,overflow:"hidden",pointerEvents:"none",zIndex:Yg.dimensionOverlay},children:z.jsxs("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none"},width:n,height:o,children:[t.map(s=>{const a=s.anchor,A=s.anchor_id,c=s.target,l=r.get(A),g=mt(e,c),u=c.x-a.x,h=c.y-a.y,d=Math.abs(g.x-l.x),_=Math.abs(g.y-l.y),m=g.y<l.y,p=g.x>l.x,I=m?yu.LABEL_OFFSET_ABOVE:yu.LABEL_OFFSET_BELOW,f=p?yu.LABEL_OFFSET_RIGHT:yu.LABEL_OFFSET_LEFT,C=d>yu.MIN_LINE_LENGTH_FOR_LABEL,y=_>yu.MIN_LINE_LENGTH_FOR_LABEL,E=`${s.display_offset_x??u.toFixed(2)}mm`,B=`${s.display_offset_y??h.toFixed(2)}mm`;return z.jsxs("g",{children:[z.jsx("line",{x1:l.x,y1:l.y,x2:g.x,y2:l.y,stroke:sE.OFFSET_LINE,strokeWidth:yu.LINE_STROKE_WIDTH,strokeDasharray:yu.LINE_DASH_PATTERN}),z.jsx("line",{x1:g.x,y1:l.y,x2:g.x,y2:g.y,stroke:sE.OFFSET_LINE,strokeWidth:yu.LINE_STROKE_WIDTH,strokeDasharray:yu.LINE_DASH_PATTERN}),s.type==="component"||s.type==="board"?z.jsx("circle",{cx:g.x,cy:g.y,r:yu.COMPONENT_MARKER_RADIUS,fill:sE.COMPONENT_MARKER_FILL,stroke:sE.COMPONENT_MARKER_STROKE,strokeWidth:1}):z.jsxs(z.Fragment,{children:[z.jsx("line",{x1:g.x-yu.ANCHOR_MARKER_SIZE,y1:g.y,x2:g.x+yu.ANCHOR_MARKER_SIZE,y2:g.y,stroke:sE.OFFSET_LINE,strokeWidth:yu.ANCHOR_MARKER_STROKE_WIDTH}),z.jsx("line",{x1:g.x,y1:g.y-yu.ANCHOR_MARKER_SIZE,x2:g.x,y2:g.y+yu.ANCHOR_MARKER_SIZE,stroke:sE.OFFSET_LINE,strokeWidth:yu.ANCHOR_MARKER_STROKE_WIDTH})]}),C&&z.jsx("foreignObject",{x:Math.min(l.x,g.x),y:l.y+I,width:Math.abs(g.x-l.x),height:20,style:{overflow:"visible"},children:z.jsx("div",{style:{...i,textAlign:"center"},children:E})}),y&&z.jsx("foreignObject",{x:g.x+f,y:Math.min(l.y,g.y),width:yu.Y_LABEL_MIN_WIDTH,height:Math.abs(g.y-l.y),style:{overflow:"visible"},children:z.jsx("div",{style:{...i,display:"flex",alignItems:"center",justifyContent:p?"flex-start":"flex-end",whiteSpace:"nowrap",padding:"0 4px",height:"100%"},children:B})})]},s.id)}),Array.from(r.entries()).map(([s,a])=>z.jsxs("g",{children:[z.jsx("line",{x1:a.x-yu.ANCHOR_MARKER_SIZE,y1:a.y,x2:a.x+yu.ANCHOR_MARKER_SIZE,y2:a.y,stroke:sE.OFFSET_LINE,strokeWidth:yu.ANCHOR_MARKER_STROKE_WIDTH}),z.jsx("line",{x1:a.x,y1:a.y-yu.ANCHOR_MARKER_SIZE,x2:a.x,y2:a.y+yu.ANCHOR_MARKER_SIZE,stroke:sE.OFFSET_LINE,strokeWidth:yu.ANCHOR_MARKER_STROKE_WIDTH})]},`anchor-${s}`))]})})},NJo=({elements:t,highlightedPrimitives:e,transform:n,containerWidth:o,containerHeight:i})=>{const r=t.filter(p=>o7e(p)),s=t.filter(p=>ew(p)),a=t.filter(p=>nGt(p)),A=e.map(p=>ew(p._parent_pcb_component)?p._parent_pcb_component.pcb_component_id:ew(p._element)?p._element.pcb_component_id:null).filter(p=>!!p),c=new Set;if(A.forEach(p=>{const I=s.find(f=>f.pcb_component_id===p);I?.pcb_group_id&&c.add(I.pcb_group_id)}),!yd(p=>p.is_showing_group_anchor_offsets)&&A.length===0)return null;const g=s.map(p=>{const I=p.positioned_relative_to_pcb_board_id;if(!I)return null;const f=r.find(C=>C.pcb_board_id===I);return f?{component:p,board:f,type:"component"}:null}).filter(p=>!!p),u=a.map(p=>{const I=p.positioned_relative_to_pcb_board_id;if(!I||!p.center)return null;const f=r.find(C=>C.pcb_board_id===I);return f?{group:p,board:f,type:"group"}:null}).filter(p=>!!p),h=[...g,...u];if(h.length===0)return null;const d=A.length===0,_=h.filter(p=>p.type==="component"?d||A.includes(p.component.pcb_component_id):d||c.has(p.group.pcb_group_id));if(_.length===0)return null;const m=_.map(p=>p.type==="component"?{id:`${p.board.pcb_board_id}-${p.component.pcb_component_id}-${p.type}`,anchor:p.board.center,anchor_id:p.board.pcb_board_id,target:p.component.center,type:"component",display_offset_x:p.component.display_offset_x,display_offset_y:p.component.display_offset_y}:{id:`${p.board.pcb_board_id}-${p.group.pcb_group_id}-${p.type}`,anchor:p.board.center,anchor_id:p.board.pcb_board_id,target:{x:p.group.anchor_position?.x??p.group.center.x,y:p.group.anchor_position?.y??p.group.center.y},type:"group",display_offset_x:p.group.display_offset_x,display_offset_y:p.group.display_offset_y}).filter(p=>!!p);return z.jsx(i7e,{targets:m,transform:n,containerWidth:o,containerHeight:i})},RJo=({elements:t,highlightedPrimitives:e,transform:n,containerWidth:o,containerHeight:i})=>{const r=t.filter(p=>nGt(p)),s=t.filter(p=>ew(p)),a=e.map(p=>ew(p._parent_pcb_component)?p._parent_pcb_component.pcb_component_id:ew(p._element)?p._element.pcb_component_id:null).filter(p=>!!p),A=(p,I)=>{if(I.has(p))return;I.add(p);const f=r.find(C=>C.pcb_group_id===p);f?.position_mode==="relative_to_group_anchor"&&f.positioned_relative_to_pcb_group_id&&A(f.positioned_relative_to_pcb_group_id,I)},c=new Set;if(a.forEach(p=>{const I=s.find(f=>f.pcb_component_id===p);I&&(I.position_mode==="relative_to_group_anchor"&&I.positioned_relative_to_pcb_group_id&&A(I.positioned_relative_to_pcb_group_id,c),I.pcb_group_id&&A(I.pcb_group_id,c))}),!yd(p=>p.is_showing_group_anchor_offsets)&&a.length===0)return null;const g=s.map(p=>{if(p.position_mode==="relative_to_group_anchor"&&p.positioned_relative_to_pcb_group_id){const I=r.find(f=>f.pcb_group_id===p.positioned_relative_to_pcb_group_id);return I&&I.anchor_position?{component:p,parentGroup:I,type:"component"}:null}if(p.pcb_group_id){const I=r.find(f=>f.pcb_group_id===p.pcb_group_id);return I&&I.anchor_position?{component:p,parentGroup:I,type:"component"}:null}return null}).filter(p=>!!p),u=r.map(p=>{if(p.position_mode==="relative_to_group_anchor"&&p.positioned_relative_to_pcb_group_id){const I=r.find(f=>f.pcb_group_id===p.positioned_relative_to_pcb_group_id);if(I&&I.anchor_position&&p.anchor_position)return{group:p,parentGroup:I,type:"group"}}return null}).filter(p=>!!p),h=[...g,...u];if(h.length===0)return null;const d=a.length===0,_=h.filter(p=>p.type==="component"?d||a.includes(p.component.pcb_component_id):d||c.has(p.group.pcb_group_id)||c.has(p.parentGroup.pcb_group_id));if(_.length===0)return null;const m=_.map(p=>{const I=p.parentGroup.anchor_position;return I?p.type==="component"?p.component.center?{id:`${p.parentGroup.pcb_group_id}-${p.component.pcb_component_id}-${p.type}`,anchor:I,anchor_id:p.parentGroup.pcb_group_id,target:p.component.center,type:"component",display_offset_x:p.component.display_offset_x,display_offset_y:p.component.display_offset_y}:null:p.group.anchor_position?{id:`${p.parentGroup.pcb_group_id}-${p.group.pcb_group_id}-${p.type}`,anchor:I,anchor_id:p.parentGroup.pcb_group_id,target:p.group.anchor_position,type:"group",display_offset_x:p.group.display_offset_x,display_offset_y:p.group.display_offset_y}:null:null}).filter(p=>!!p);return z.jsx(i7e,{targets:m,transform:n,containerWidth:o,containerHeight:i})},TJo=(t,e)=>{const n=t.pcb_component_id,o=e.filter(i=>(i.type==="pcb_smtpad"||i.type==="pcb_plated_hole")&&i.pcb_component_id===n||i.type==="pcb_hole"&&i.pcb_component_id===n);return o.length===0?$9e([t]):$9e(o)},kJo=({elements:t,highlightedPrimitives:e,transform:n,containerWidth:o,containerHeight:i})=>{const r=new Map;for(const a of e)ew(a._parent_pcb_component)&&r.set(a._parent_pcb_component.pcb_component_id,a._parent_pcb_component),ew(a._element)&&r.set(a._element.pcb_component_id,a._element);if(r.size===0)return null;const s=[];for(const a of r.values()){const A=TJo(a,t);if(!A)continue;const c=a.positioned_relative_to_pcb_group_id??a.pcb_group_id,l=c?q6(t).pcb_group.get(c):null;s.push({component:a,bbox:A,group:l})}return s.length===0?null:z.jsx("div",{style:{position:"absolute",left:0,top:0,width:o,height:i,overflow:"hidden",pointerEvents:"none",zIndex:Yg.dimensionOverlay},children:z.jsx("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none"},width:o,height:i,children:s.map(({component:a,bbox:A,group:c})=>{const l=mt(n,{x:A.minX,y:A.maxY}),g=mt(n,{x:A.maxX,y:A.minY}),u={x:Math.min(l.x,g.x),y:Math.min(l.y,g.y),width:Math.abs(g.x-l.x),height:Math.abs(g.y-l.y)},h=a.center??{x:(A.minX+A.maxX)/2,y:(A.minY+A.maxY)/2},d=mt(n,h);return z.jsxs("g",{children:[z.jsx("rect",{x:u.x,y:u.y,width:u.width,height:u.height,fill:"none",stroke:"white",strokeWidth:1.5,strokeDasharray:"4,4"}),z.jsx("line",{x1:d.x-6,y1:d.y,x2:d.x+6,y2:d.y,stroke:sE.COMPONENT_MARKER_STROKE,strokeWidth:1.5}),z.jsx("line",{x1:d.x,y1:d.y-6,x2:d.x,y2:d.y+6,stroke:sE.COMPONENT_MARKER_STROKE,strokeWidth:1.5}),z.jsx("circle",{cx:d.x,cy:d.y,r:yu.COMPONENT_MARKER_RADIUS,fill:sE.COMPONENT_MARKER_FILL,stroke:sE.COMPONENT_MARKER_STROKE,strokeWidth:1})]},a.pcb_component_id)})})})},FJo=({elements:t,highlightedPrimitives:e,transform:n,containerWidth:o,containerHeight:i})=>{const r=t.filter(h=>MJo(h)),s=t.filter(h=>o7e(h)),a=e.map(h=>o7e(h._element)?h._element.pcb_board_id:null).filter(h=>!!h);if(!yd(h=>h.is_showing_group_anchor_offsets)&&a.length===0)return null;const c=s.map(h=>{const d=h.pcb_panel_id,_=h.position_mode;if(!d||_!=="relative_to_panel_anchor")return null;const m=r.find(p=>p.pcb_panel_id===d);return m?{board:h,panel:m,type:"board"}:null}).filter(h=>!!h);if(c.length===0)return null;const l=a.length===0,g=c.filter(h=>l||a.includes(h.board.pcb_board_id));if(g.length===0)return null;const u=g.map(h=>h.board.center?{id:`${h.panel.pcb_panel_id}-${h.board.pcb_board_id}-${h.type}`,anchor:h.panel.center,anchor_id:h.panel.pcb_panel_id,target:h.board.center,type:"board",display_offset_x:h.board.display_offset_x,display_offset_y:h.board.display_offset_y}:null).filter(h=>!!h);return z.jsx(i7e,{targets:u,transform:n,containerWidth:o,containerHeight:i})},dae=t=>t?.trim()||null;function oGt({primitiveElement:t,elements:e}){const n=t.source_trace_id;if(!n)return null;const o=q6(e),i=o.source_trace.get(n),r=dae(i?.name);if(r)return r;const s=o.source_net.get(n),a=dae(s?.name);if(a)return a;for(const A of i?.connected_source_net_ids??[]){const c=dae(o.source_net.get(A)?.name);if(c)return c}return null}function LJo({primitiveElement:t,elements:e}){const n=q6(e).source_trace.get(t?.source_trace_id),o=t.trace_length,i=typeof o=="number",r=n?.max_length,s=i?`${o.toFixed(3)}${typeof r=="number"?` / ${r}`:""} mm`:"",a=oGt({primitiveElement:t,elements:e})??dae(n?.display_name);if(!s&&!a)return null;const A=!!(i&&typeof r=="number"&&o>r);return{text:s,name:a,isOverLength:A}}function HJo(t){const{primitives:e,is_showing_multiple_traces_length:n,elements:o}=t,i=e.filter(A=>A._element.type==="pcb_trace"),r=o.filter(A=>A.type==="source_trace"),s=e.filter(A=>A._element.type!=="pcb_trace"),a=i.filter(A=>r.some(l=>A._element.source_trace_id===l.source_trace_id&&l.max_length!==void 0)||oGt({primitiveElement:A._element,elements:o})!==null);if(!n)return[...s,...a];if(i.length>1){const A=i.reduce((c,l)=>{const g=c._element.trace_length;return l._element.trace_length<g?l:c},i[0]);return[...s,A]}return e}var GJo={position:"absolute",left:0,top:0,pointerEvents:"none",color:"red",fontFamily:"sans-serif",fontSize:12,textShadow:"0 0 2px black"},OJo=t=>{const{_element:e,_parent_pcb_component:n,_parent_source_component:o,_source_port:i}=t;switch(e.type){case"pcb_trace":return e.trace_length?`${e.trace_length.toFixed(3)}`:"";case"pcb_smtpad":case"pcb_plated_hole":{const r=[],s=Array.from(new Set((e.port_hints??[]).concat(i?.port_hints??[]))).filter(A=>!/^[0-9]+$/.test(A)).filter(A=>!A.includes("unnamed_")).sort((A,c)=>c.localeCompare(A)),a=o&&"name"in o&&o.name&&!o.name.includes("unnamed_")?o.name:null;return s.length>0?a?r.push(...s.map(A=>`${a}.${A}`)):r.push(...s):a&&r.push(a),r.join(", ")}default:return""}},KJo={top:"red",bottom:"aqua"},UJo=({primitive:t,mousePos:e,elements:n})=>{const[o,i]=X.useState(!1),r=t._element;X.useEffect(()=>{setTimeout(()=>{i(!0)},100)},[]);const[s,a,A,c]=[t.screen_x,t.screen_y,t.screen_w,t.screen_h],l=t.same_space_index??0,g=26,u=KJo[t?._element?.layer]??"red";let h=0;if(r.type==="pcb_smtpad"&&r?.shape==="rotated_rect"?h=r?.ccw_rotation??0:(r.type==="pcb_smtpad"&&(r?.shape==="pill"||r?.shape==="rotated_pill")&&"ccw_rotation"in t||r.type==="pcb_plated_hole"&&(r?.shape==="pill"||r?.shape==="oval")&&"ccw_rotation"in t)&&(h=r.ccw_rotation??0),r.type==="pcb_trace"){const m=LJo({primitiveElement:r,elements:n});return m?z.jsx("div",{style:{zIndex:Yg.elementOverlay,position:"absolute",left:e.x+12,top:e.y+12,color:u,pointerEvents:"none"},children:z.jsxs("div",{style:{backgroundColor:"#f2efcc",color:m.isOverLength?"red":"black",textShadow:"none",WebkitFontSmoothing:"antialiased",MozOsxFontSmoothing:"grayscale",padding:"4px 6px",borderRadius:"4px",fontSize:"11px",lineHeight:1.2,textAlign:"left",whiteSpace:"nowrap"},children:[m.text&&z.jsx("div",{children:m.text}),m.name&&z.jsx("div",{style:{marginTop:m.text?"2px":0},children:m.name})]})}):null}const d=OJo(t);return d.trim().length===0?null:z.jsx("div",{style:{zIndex:Yg.elementOverlay,position:"absolute",left:s-A/2-8,top:a-c/2-8,width:A+16,height:c+16,color:u,transform:`rotate(${-h}deg)`,transformOrigin:"center center"},children:z.jsx("div",{style:{width:o?`calc(100% + ${g*2*l}px)`:"100%",height:o?`calc(100% + ${g*2*l}px)`:"100%",marginLeft:o?`${-g*l}px`:0,marginTop:o?`${-g*l}px`:0,border:`1px solid ${u}`,opacity:o||l===0?1:0,transition:"width 0.2s, height 0.2s, margin-left 0.2s, margin-top 0.2s, opacity 0.2s"},children:z.jsx("div",{style:{position:"absolute",bottom:c+20+g*l,marginRight:o?`${-g*l}px`:0,marginBottom:o?0:-g*l,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(${h}deg)`,minWidth:"45px",textAlign:"center"},children:d})})})},YJo=({highlightedPrimitives:t,mousePos:e,elements:n})=>{const[o,i]=yd(a=>[a.is_moving_component,a.is_showing_multiple_traces_length]),r=t.some(a=>a._element.type==="pcb_smtpad")&&t.some(a=>a._element.type==="pcb_trace");let s=t;return r&&(s=s.filter(a=>a._element.type==="pcb_smtpad")),s=HJo({primitives:s,is_showing_multiple_traces_length:i,elements:n}),z.jsx("div",{style:GJo,children:!o&&s.map(a=>z.jsx(UJo,{primitive:a,mousePos:e,elements:n},a._pcb_drawing_object_id))})},hae=t=>{if(t.length===0)return null;let e=t[0].x,n=t[0].y,o=t[0].x,i=t[0].y;for(const r of t)r.x<e&&(e=r.x),r.y<n&&(n=r.y),r.x>o&&(o=r.x),r.y>i&&(i=r.y);return{center:{x:(e+o)/2,y:(n+i)/2},width:o-e,height:i-n}},iGt=(t,e)=>{if(e.length<3)return!1;let n=!1;for(let o=0,i=e.length-1;o<e.length;i=o++){const r=e[o].x,s=e[o].y,a=e[i].x,A=e[i].y;s>t.y!=A>t.y&&t.x<(a-r)*(t.y-s)/(A-s||Number.EPSILON)+r&&(n=!n)}return n},zJo=(t,e,n,o)=>{const i=[];for(const r of t){if(!r._element||r._element.type==="pcb_trace"&&r.layer!==o)continue;if("x1"in r&&r._element?.type==="pcb_trace"){const A=gm({x:e.x,y:e.y},{x:r.x1,y:r.y1},{x:r.x2,y:r.y2}),c=r.width||.5,l=Math.max(c*25,2)/n.a;A<l&&i.push(r);continue}if(r.pcb_drawing_type==="polygon"){const A=r.points.map(l=>({x:En.parse(l.x),y:En.parse(l.y)})),c=hae(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;iGt(e,A)&&i.push(r);continue}if(r.pcb_drawing_type==="polygon_with_arcs"){const A=r.brep_shape.outer_ring.vertices.map(l=>({x:En.parse(l.x),y:En.parse(l.y)})),c=hae(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;iGt(e,A)&&i.push(r);continue}if(!("x"in r&&"y"in r))continue;let s=0,a=0;if("w"in r&&"h"in r)s=r.w,a=r.h;else if("r"in r)s=r.r*2,a=r.r*2;else if("rX"in r&&"rY"in r)s=r.rX*2,a=r.rY*2;else continue;Math.abs(r.x-e.x)<s/2&&Math.abs(r.y-e.y)<a/2&&i.push(r)}return i},VJo=({elements:t,children:e,transform:n,primitives:o,selectedLayer:i,onMouseHoverOverPrimitives:r})=>{const[s,a]=X.useState([]),[A,c]=X.useState({x:0,y:0}),[l,{width:g,height:u}]=GY();X.useEffect(()=>{a([]),r([])},[i,r]);const h=X.useMemo(()=>{const _=[];for(const m of s){if(m._element?.type==="pcb_via"||m._element?.type==="pcb_component"||m?.layer==="drill"||m?.is_hoverable===!1)continue;let p=null,I=0,f=0;if(m.pcb_drawing_type==="polygon"){const B=hae(m.points);if(!B)continue;p=B.center,I=B.width,f=B.height}else if(m.pcb_drawing_type==="polygon_with_arcs"){const B=m.brep_shape.outer_ring.vertices.map(b=>({x:b.x,y:b.y})),Q=hae(B);if(!Q)continue;p=Q.center,I=Q.width,f=Q.height}else m.pcb_drawing_type==="line"?(p={x:(m.x1+m.x2)/2,y:(m.y1+m.y2)/2},I=Math.abs(m.x2-m.x1),f=Math.abs(m.y2-m.y1)):"x"in m&&"y"in m&&(p={x:m.x,y:m.y},I="w"in m?m.w:"r"in m?m.r*2:"rX"in m&&"rY"in m?m.rX*2:0,f="h"in m?m.h:"r"in m?m.r*2:"rX"in m&&"rY"in m?m.rY*2:0);if(!p)continue;const C=mt(n,p),y={w:I*n.a,h:f*n.a},E=_.filter(B=>C.x===B.screen_x&&C.y===B.screen_y&&y.w===B.screen_w&&y.h===B.screen_h).length;_.push({...m,x:p.x,y:p.y,w:I,h:f,screen_x:C.x,screen_y:C.y,screen_w:y.w,screen_h:y.h,same_space_index:E})}return _},[s,n]),d=(_,m,p,I)=>{c({x:_,y:m});const f=mt(MQ(p),{x:_,y:m}),C=zJo(I,f,p,i);wJo(new Set(C.map(y=>y._pcb_drawing_object_id)),new Set(s.map(y=>y._pcb_drawing_object_id)))||(a(C),r(C))};return z.jsxs("div",{ref:l,style:{position:"relative",width:"100%",height:"100%"},onMouseMove:_=>{if(n){const m=_.currentTarget.getBoundingClientRect(),p=_.clientX-m.left,I=_.clientY-m.top;d(p,I,n,o)}},onTouchStart:_=>{if(n){const m=_.touches[0],p=_.currentTarget.getBoundingClientRect(),I=m.clientX-p.left,f=m.clientY-p.top;d(I,f,n,o)}},children:[e,z.jsx(YJo,{elements:t,mousePos:A,highlightedPrimitives:h}),n&&z.jsxs(z.Fragment,{children:[z.jsx(NJo,{elements:t,highlightedPrimitives:h,transform:n,containerWidth:g,containerHeight:u}),z.jsx(RJo,{elements:t,highlightedPrimitives:h,transform:n,containerWidth:g,containerHeight:u}),z.jsx(kJo,{elements:t,highlightedPrimitives:h,transform:n,containerWidth:g,containerHeight:u}),z.jsx(FJo,{elements:t,highlightedPrimitives:h,transform:n,containerWidth:g,containerHeight:u})]})]})},rGt=["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)"],JJo=({children:t,transform:e=Hl(),elements:n=[],hoveredComponentIds:o=[]})=>{const[i,{width:r,height:s}]=GY(),a=X.useRef(null),{is_showing_pcb_groups:A,pcb_group_view_mode:c,is_showing_group_anchor_offsets:l}=yd(g=>({is_showing_pcb_groups:g.is_showing_pcb_groups,pcb_group_view_mode:g.pcb_group_view_mode,is_showing_group_anchor_offsets:g.is_showing_group_anchor_offsets}));return X.useEffect(()=>{const g=a.current;if(!g||!r||!s)return;g.width=r,g.height=s;const u=g.getContext("2d");if(!u||(u.clearRect(0,0,r,s),!A))return;const h=n.filter(E=>E.type==="pcb_group"),d=n.filter(E=>E.type==="pcb_component"),_=n.filter(E=>E.type==="source_group"),m=new Map(_.map(E=>[E.source_group_id,E])),p=h.filter(E=>{if(E.name?.toLowerCase().includes("subpanel"))return!1;if(c==="all")return!0;if(!E.source_group_id)return!1;const B=m.get(E.source_group_id);return B?B.was_automatically_named!==!0:!1}),I=new Map;_.forEach(E=>{const B=E;if(B.parent_source_group_id){const Q=I.get(B.parent_source_group_id)||[];Q.push(E.source_group_id),I.set(B.parent_source_group_id,Q)}});const f=E=>{const B=[],Q=I.get(E)||[];for(const b of Q)B.push(b),B.push(...f(b));return B},C=E=>{const B=_.find(Q=>Q.source_group_id===E);return B?.parent_source_group_id?1+C(B.parent_source_group_id):0},y=new Set;if(o.length>0)for(const E of d){if(!o.includes(E.pcb_component_id))continue;const B=E.positioned_relative_to_pcb_group_id??E.pcb_group_id;B&&y.add(B)}p.forEach((E,B)=>{let Q=d.filter(ke=>ke.pcb_group_id===E.pcb_group_id);if(E.source_group_id){const ke=f(E.source_group_id),Ve=h.filter(Re=>Re.source_group_id&&ke.includes(Re.source_group_id));for(const Re of Ve){const Se=d.filter(Oe=>Oe.pcb_group_id===Re.pcb_group_id);Q=[...Q,...Se]}}let b,D,R,M,L=!1;if(E.center&&E.width&&E.height){L=!0;const ke=E.width/2,Ve=E.height/2;b=E.center.x-ke,R=E.center.x+ke,D=E.center.y-Ve,M=E.center.y+Ve}else if(Q.length===0||(b=1/0,D=1/0,R=-1/0,M=-1/0,Q.forEach(ke=>{if(ke.center&&typeof ke.width=="number"&&typeof ke.height=="number"){const Ve=ke.center.x-ke.width/2,Re=ke.center.x+ke.width/2,Se=ke.center.y+ke.height/2,Oe=ke.center.y-ke.height/2;b=Math.min(b,Ve),R=Math.max(R,Re),D=Math.min(D,Oe),M=Math.max(M,Se)}}),b===1/0||R===-1/0))return;const G=E.source_group_id?C(E.source_group_id):0,O=E.source_group_id?f(E.source_group_id).length>0:!1;if(!L){const Re=1+(O?.5:0);b-=Re,R+=Re,D-=Re,M+=Re}const U=mt(e,{x:b,y:M}),W=mt(e,{x:R,y:M}),j=mt(e,{x:b,y:D}),te=mt(e,{x:R,y:D}),ie=rGt[B%rGt.length];u.strokeStyle=ie,u.lineWidth=2;const $=Math.max(4,Math.min(12,8*Math.abs(e.a))),Z=Math.max(2,Math.min(6,4*Math.abs(e.a))),ae=$*(O?1.3:1),ce=Z;u.setLineDash([ae,ce]),u.beginPath(),u.moveTo(U.x,U.y),u.lineTo(W.x,W.y),u.lineTo(te.x,te.y),u.lineTo(j.x,j.y),u.closePath(),u.stroke();const fe=Math.max(8,Math.min(12,10*Math.abs(e.a))),Ce=G==0||G==1?0:G*.11,xe=fe*(1-Ce),de=4,Ee=E.name||`Group ${B+1}`;u.font=`${xe}px sans-serif`,u.setLineDash([]);const be=u.measureText(Ee).width+de*2,Me=xe+de*2,Ye=U.x-5,Ie=U.y-5,We=3;if(u.fillStyle="rgba(0, 0, 0, 0.8)",u.beginPath(),u.roundRect(Ye,Ie-Me,be,Me,We),u.fill(),u.fillStyle=ie,u.textAlign="left",u.textBaseline="middle",u.fillText(Ee,Ye+de,Ie-Me/2),l&&y.has(E.pcb_group_id)&&!!E.anchor_position&&E.anchor_position){const ke=Array.isArray(E.anchor_position)?{x:E.anchor_position[0]??0,y:E.anchor_position[1]??0}:{x:E.anchor_position.x,y:E.anchor_position.y},Ve=mt(e,ke);u.strokeStyle="white",u.lineWidth=1.5,u.setLineDash([]);const Re=Math.max(4,Math.min(8,6*Math.abs(e.a)));u.beginPath(),u.moveTo(Ve.x-Re,Ve.y),u.lineTo(Ve.x+Re,Ve.y),u.stroke(),u.beginPath(),u.moveTo(Ve.x,Ve.y-Re),u.lineTo(Ve.x,Ve.y+Re),u.stroke()}})},[n,e,r,s,A,c,l,o]),z.jsxs("div",{ref:i,style:{position:"relative",width:"100%",height:"100%"},children:[t,z.jsx("canvas",{ref:a,style:{position:"absolute",top:0,left:0,pointerEvents:"none",zIndex:Yg.pcbGroupOverlay,display:A?"block":"none"}})]})},qJo=({transform:t,soup:e,children:n})=>{const o=yd(a=>a.is_showing_rats_nest),{netMap:i,idToNetMap:r}=X.useMemo(()=>vHt(e||[]),[e]),s=X.useMemo(()=>{if(!e||!o)return[];const a=u=>{const h=q6(e)[u.replace(/_\d+$/,"")].get(u);return h&&"x"in h&&"y"in h?{x:h.x,y:h.y}:null},A=(u,h)=>{const d=i[h]||[];let _=null,m=1/0;return d.forEach(p=>{const I=a(p);if(I){const f=Math.sqrt((u.x-I.x)**2+(u.y-I.y)**2);f<m&&f>0&&(m=f,_=I)}}),_},c=q6(e).pcb_port.list(),l=q6(e).source_trace.list(),g=[];return c.forEach((u,h)=>{const d=r[u.pcb_port_id];let _=!1;for(const I of l)I.connected_source_port_ids.includes(u.source_port_id)&&I.connected_source_net_ids.length>0&&(_=!0);if(!d)return;const m={x:u.x,y:u.y},p=A(m,d);p&&g.push({key:`${u.pcb_port_id}-${h}`,startPoint:m,endPoint:p,isInNet:_})}),g},[e,i,r,o]);return!e||!o?n:(t||(t=Hl()),z.jsxs("div",{style:{position:"relative"},children:[n,z.jsx("svg",{style:{position:"absolute",left:0,top:0,width:"100%",height:"100%",pointerEvents:"none",opacity:.5,zIndex:Yg.ratsNestOverlay},children:s.map(({key:a,startPoint:A,endPoint:c,isInNet:l})=>{const g=mt(t,A),u=mt(t,c);return z.jsx("line",{x1:g.x,y1:g.y,x2:u.x,y2:u.y,stroke:"white",strokeWidth:"1",strokeDasharray:l?"6,6":void 0},a)})})]}))},WJo={version:"1.11.388"},hb=(t,e,n)=>{const o=yd(s=>s.is_mouse_over_container),i=X.useRef(o),r=X.useRef(e);X.useEffect(()=>{i.current=o},[o]),X.useEffect(()=>{r.current=e},[e]),X.useEffect(()=>{if(!t)return;const s=a=>{const A=a.target;if(A.tagName==="INPUT"||A.tagName==="TEXTAREA"||A.isContentEditable)return;const c=t.split("+"),l=c.includes("ctrl"),g=c.includes("shift"),u=c.includes("alt"),h=c.includes("meta"),d=c[c.length-1],_=n?.current?n.current.contains(document.activeElement)||document.activeElement===n.current:!1;(i.current||_)&&(!l||a.ctrlKey)&&(!g||a.shiftKey)&&(!u||a.altKey)&&(!h||a.metaKey)&&a.key.toLowerCase()===d.toLowerCase()&&(a.preventDefault(),r.current())};return window.addEventListener("keydown",s),()=>{window.removeEventListener("keydown",s)}},[t])},jJo=()=>{const[t,e]=X.useState(!1);return X.useEffect(()=>{const n=()=>{e(window.innerWidth<=768)};return n(),window.addEventListener("resize",n),()=>window.removeEventListener("resize",n)},[]),t},KY=(t,e={stopPropagation:!0})=>{const n=X.useRef(0),o=X.useCallback(s=>{e.stopPropagation&&s.stopPropagation();const a=Date.now();a-n.current<300||(n.current=a,t?.(s))},[t,e.stopPropagation]),i=X.useCallback(s=>{s.preventDefault(),o(s)},[o]);return{onClick:o,onTouchEnd:i,style:{touchAction:"manipulation"}}},Ok=({children:t,isSmallScreen:e,onClick:n,...o})=>{const{style:i,...r}=KY(n);return z.jsx("div",{...o,...r,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,...o.style},children:t})},XJo=t=>{const e=new Map;return t.forEach((n,o)=>{const i=n.error_type||"unknown_error",r=e.get(i)||[];r.push({error:n,index:o,errorId:Gk(n,o)}),e.set(i,r)}),Array.from(e.entries()).map(([n,o])=>({errorType:n,errors:o}))},$Jo=({onClose:t,setHoveredErrorId:e,setFocusedErrorId:n,highlightDurationMs:o=3e3})=>{const i=X.useRef(null),r=X.useRef(null),s=X.useRef(null),a=X.useCallback(()=>{i.current!==null&&(window.clearTimeout(i.current),i.current=null),r.current!==null&&(window.cancelAnimationFrame(r.current),r.current=null)},[]);X.useEffect(()=>a,[a]);const A=X.useCallback(l=>{a(),s.current=l,e(l),n(null),r.current=window.requestAnimationFrame(()=>{n(l),r.current=null}),t(),i.current=window.setTimeout(()=>{s.current=null,e(null),n(null),i.current=null},o)},[a,o,t,n,e]),c=X.useCallback(l=>s.current===l,[]);return{handleErrorSelect:A,isSelectedError:c}},ZJo=({errorId:t,errorMessage:e,copiedErrorId:n,onCopy:o})=>{const{style:i,...r}=KY(()=>o(e,t));return z.jsx("button",{type:"button","aria-label":n===t?"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},...r,children:n===t?z.jsx("span",{style:{color:"#4caf50",fontSize:12},children:"Copied!"}):z.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"currentColor",children:z.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"})})})},eqo=({elements:t,isOpen:e,isSmallScreen:n,onToggle:o,onClose:i,setHoveredErrorId:r,setFocusedErrorId:s})=>{const[a,A]=X.useState(null),[c,l]=X.useState(new Set),[g,u]=X.useState(new Set),[,h]=Fzo(),{handleErrorSelect:d,isSelectedError:_}=$Jo({onClose:i,setHoveredErrorId:r,setFocusedErrorId:s}),m=X.useMemo(()=>t?.filter(y=>y.type.includes("error"))??[],[t]),p=m.length,I=X.useMemo(()=>XJo(m),[m]),f=X.useCallback(y=>{l(E=>{const B=new Set(E);return B.has(y)?B.delete(y):B.add(y),B})},[]),C=X.useCallback(y=>{u(E=>{const B=new Set(E);return B.has(y)?B.delete(y):B.add(y),B})},[]);return z.jsxs("div",{style:{position:"relative"},children:[z.jsx(Ok,{isSmallScreen:n,style:p>0?{color:"red"}:void 0,onClick:o,children:z.jsxs("div",{children:[p," errors"]})}),e&&p>0&&z.jsx("div",{style:{position:"absolute",top:"100%",left:0,backgroundColor:"#2a2a2a",border:"1px solid #666",borderRadius:4,marginTop:4,zIndex:1e3,minWidth:n?"280px":"400px",maxWidth:n?"90vw":"600px",maxHeight:"400px",overflow:"auto",boxShadow:"0 4px 12px rgba(0, 0, 0, 0.3)"},children:I.map(({errorType:y,errors:E},B)=>{const Q=c.has(y);return z.jsxs("div",{style:{borderBottom:B<I.length-1?"1px solid #444":"none"},children:[z.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:b=>{b.currentTarget.style.backgroundColor="#303030"},onMouseLeave:b=>{b.currentTarget.style.backgroundColor="#232323"},onTouchStart:b=>{b.stopPropagation(),b.currentTarget.style.backgroundColor="#303030"},onTouchEnd:b=>{b.stopPropagation(),b.preventDefault(),b.currentTarget.style.backgroundColor="#232323",f(y)},onClick:b=>{b.stopPropagation(),f(y)},children:[z.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,color:"#ff6b6b"},children:[z.jsx("div",{style:{color:"#888",fontSize:"16px",transform:Q?"rotate(90deg)":"rotate(0deg)",transition:"transform 0.2s ease",flexShrink:0},children:"›"}),z.jsx("div",{style:{fontWeight:"bold",fontSize:n?"12px":"13px"},children:y})]}),z.jsx("div",{style:{fontSize:n?"12px":"13px",color:"#aaa",whiteSpace:"nowrap",marginLeft:12},children:E.length})]}),!Q&&E.map(({error:b,index:D,errorId:R})=>{const M=g.has(R),L=b.message??"No error message";return z.jsxs("div",{style:{borderTop:"1px solid #3a3a3a"},children:[z.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:G=>{G.currentTarget.style.backgroundColor="#333",r(R)},onMouseLeave:G=>{G.currentTarget.style.backgroundColor="#2a2a2a",_(R)||r(null)},onTouchStart:G=>{G.stopPropagation(),G.currentTarget.style.backgroundColor="#333",r(R)},onTouchEnd:G=>{G.stopPropagation(),G.preventDefault(),G.currentTarget.style.backgroundColor="#2a2a2a",d(R)},onClick:G=>{G.stopPropagation(),d(R)},children:[z.jsx("div",{style:{flex:1,fontSize:n?"12px":"13px",color:"#ddd",lineHeight:1.4,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",userSelect:"text"},children:L}),z.jsx("button",{type:"button","aria-label":M?"Collapse error details":"Expand error details",style:{color:"#888",fontSize:"16px",transform:M?"rotate(0deg)":"rotate(90deg)",transition:"transform 0.2s ease",flexShrink:0,background:"none",border:"none",padding:0,cursor:"pointer"},onMouseDown:G=>G.stopPropagation(),onClick:G=>{G.stopPropagation(),C(R)},onTouchEnd:G=>{G.stopPropagation(),G.preventDefault(),C(R)},children:"›"})]}),M&&z.jsxs("div",{"data-error-id":D,style:{display:"block",padding:"12px 16px 12px 24px",backgroundColor:"#1a1a1a",borderTop:"1px solid #444",position:"relative"},children:[z.jsx("div",{style:{fontSize:n?"11px":"12px",color:"#ccc",lineHeight:1.5,wordWrap:"break-word",overflowWrap:"break-word",hyphens:"auto",userSelect:"text",paddingRight:30},onMouseDown:G=>G.stopPropagation(),onClick:G=>G.stopPropagation(),children:L}),z.jsx(ZJo,{errorId:R,errorMessage:L,copiedErrorId:a,onCopy:(G,O)=>{h(G),A(O),setTimeout(()=>A(null),2e3)}})]})]},R)})]},y)})})]})},tqo=({name:t,selected:e,onClick:n})=>{const{style:o,...i}=KY(n);return z.jsxs("div",{className:iae`
|
|
5702
5702
|
margin-top: 2px;
|
|
5703
5703
|
padding: 4px;
|
|
5704
5704
|
padding-left: 8px;
|
|
@@ -5769,7 +5769,7 @@ test("${c} should solve problem correctly", () => {
|
|
|
5769
5769
|
// Add more specific assertions based on expected output
|
|
5770
5770
|
// expect(solver.netLabelPlacementSolver!.netLabelPlacements).toMatchInlineSnapshot()
|
|
5771
5771
|
})
|
|
5772
|
-
`,g=new Blob([l],{type:"text/plain"}),u=URL.createObjectURL(g),h=document.createElement("a");h.href=u,h.download=`${c}.test.ts`,h.click(),URL.revokeObjectURL(u)}catch(A){alert(`Error generating test.ts for ${t.constructor.name}: ${A instanceof Error?A.message:String(A)}`)}o(!1)};return z.jsxs("div",{className:`relative ${e}`,ref:i,children:[z.jsx("button",{className:"px-2 py-1 rounded text-xs cursor-pointer",onClick:()=>o(!n),title:`Download options for ${t.constructor.name}`,children:t.constructor.name}),n&&z.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:[z.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:r,children:"Download JSON"}),z.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:s,children:"Download page.tsx"}),z.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:a,children:"Download test.ts"})]})]})},lGt=t=>t.activeSubSolver?[t,...lGt(t.activeSubSolver)]:[t],Xqo=({solver:t})=>{const e=lGt(t);return z.jsx("div",{className:"flex gap-1 items-center text-sm pt-1",children:e.map((n,o)=>z.jsxs("div",{className:"flex items-center",children:[o>0&&z.jsx("span",{className:"text-gray-400 mx-1",children:"→"}),z.jsx(jqo,{solver:n})]},n.constructor.name))})},$qo=({solver:t,triggerRender:e,animationSpeed:n=25,onSolverStarted:o,onSolverCompleted:i})=>{const[r,s]=X.useReducer(_=>!_,!1),a=X.useRef(void 0),A=()=>{!t.solved&&!t.failed&&(t.step(),e())},c=()=>{!t.solved&&!t.failed&&(o&&o(t),t.solve(),e(),i&&i(t))},l=()=>{r?(a.current&&(clearInterval(a.current),a.current=void 0),s()):(s(),a.current=setInterval(()=>{if(t.solved||t.failed){a.current&&(clearInterval(a.current),a.current=void 0),s(),e(),i&&t.solved&&i(t);return}t.step(),e()},n))},g=()=>{const _=t;if(_.getCurrentPhase&&!t.solved&&!t.failed){const m=_.getCurrentPhase();for(;_.getCurrentPhase()===m&&!t.solved&&!t.failed;)t.step();e()}},u=()=>{if(t.solved||t.failed||r)return;const _=window.prompt("Step until which iteration?",`${t.iterations}`);if(_===null)return;const m=Number(_);if(!Number.isFinite(m)){window.alert("Please enter a valid number for the iteration");return}for(;t.iterations<m&&!t.solved&&!t.failed;)t.step();e(),t.solved&&i&&i(t)};X.useEffect(()=>()=>{a.current&&clearInterval(a.current)},[]),X.useEffect(()=>{(t.solved||t.failed)&&r&&(a.current&&(clearInterval(a.current),a.current=void 0),s())},[t.solved,t.failed,r]);const h=t.getCurrentPhase!==void 0,d=h?t.getCurrentPhase():null;return z.jsxs("div",{className:"space-y-2 p-2 border-b",children:[z.jsx("div",{className:"flex items-center",children:z.jsx(Xqo,{solver:t})}),z.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[z.jsx("button",{onClick:A,disabled:t.solved||t.failed||r,className:"bg-blue-500 hover:bg-blue-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step"}),z.jsx("button",{onClick:c,disabled:t.solved||t.failed||r,className:"bg-green-500 hover:bg-green-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Solve"}),z.jsx("button",{onClick:l,disabled:t.solved||t.failed,className:`px-3 py-1 rounded text-white text-sm ${r?"bg-red-500 hover:bg-red-600":"bg-yellow-500 hover:bg-yellow-600"} disabled:bg-gray-300`,children:r?"Stop":"Animate"}),z.jsx("button",{onClick:u,disabled:t.solved||t.failed||r,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"}),h&&z.jsx("button",{onClick:g,disabled:t.solved||t.failed||r,className:"bg-purple-500 hover:bg-purple-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Next Stage"}),z.jsxs("div",{className:"text-sm text-gray-600",children:["Iterations: ",t.iterations]}),t.timeToSolve!==void 0&&z.jsxs("div",{className:"text-sm text-gray-600",children:["Time: ",(t.timeToSolve/1e3).toFixed(3),"s"]}),d&&z.jsxs("div",{className:"text-sm text-gray-600",children:["Phase: ",z.jsx("span",{className:"font-medium",children:d})]}),t.solved&&z.jsx("div",{className:"px-2 py-1 bg-green-100 text-green-800 rounded text-sm",children:"Solved"}),t.failed&&z.jsx("div",{className:"px-2 py-1 bg-red-100 text-red-800 rounded text-sm",children:"Failed"})]}),t.error&&z.jsxs("div",{className:"text-red-600 text-sm",children:["Error: ",t.error]})]})},Zqo=(t,e,n)=>{const o=t.currentPipelineStepIndex;return e<o?"Completed":e===o&&t.activeSubSolver?t.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},eWo=(t,e)=>{const o=t.pipelineDef[e].solverName,i=Zqo(t,e),r=t[o],s=t.firstIterationOfPhase?.[o]??null,a=t.iterations;let A=0;if(i==="Completed"){const u=t.pipelineDef[e+1],h=u?t.firstIterationOfPhase?.[u.solverName]:void 0;h!==void 0&&s!==null?A=h-s:s!==null&&(A=a-s)}else i==="In Progress"&&s!==null&&(A=a-s);const c=t.timeSpentOnPhase?.[o]??0;let l=0;i==="Completed"?l=1:i==="In Progress"&&r&&(l=r.progress??0);const g=r?.stats??null;return{index:e,name:o,status:i,firstIteration:s,iterations:A,progress:l,timeSpent:c,stats:g&&Object.keys(g).length>0?g:null,solverInstance:r??null}},tWo=({status:t})=>{const e={"Not Started":"text-blue-600","In Progress":"text-yellow-600",Completed:"text-green-600",Failed:"text-red-600"};return z.jsx("span",{className:`font-medium ${e[t]}`,children:t})},nWo=({progress:t})=>{if(t===0)return null;const e=Math.round(t*100);return z.jsxs("div",{className:"flex items-center gap-2",children:[z.jsx("div",{className:"w-20 h-2 bg-gray-200 rounded overflow-hidden",children:z.jsx("div",{className:"h-full bg-blue-500 transition-all duration-200",style:{width:`${e}%`}})}),z.jsxs("span",{className:"text-xs text-gray-500",children:[e,"%"]})]})},oWo=t=>Object.entries(t).map(([e,n])=>`${e}: ${n}`).join(", "),iWo=({stats:t})=>{if(!t||Object.keys(t).length===0)return z.jsx("span",{children:"-"});const e=Object.entries(t),n=oWo(t);return z.jsxs("details",{className:"cursor-pointer",children:[z.jsx("summary",{className:"whitespace-nowrap overflow-hidden text-ellipsis max-w-[200px]",children:n}),z.jsx("div",{className:"mt-1 text-xs",children:e.map(([o,i])=>z.jsxs("div",{children:[o,": ",String(i)]},o))})]})},s7e=t=>{if(t===null||typeof t!="object")return t;if(Array.isArray(t))return t.map(s7e);const e={};for(const[n,o]of Object.entries(t))n.startsWith("_")||(e[n]=s7e(o));return e},rWo=(t,e)=>{try{if(typeof t.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${e}`);return}const n=s7e(t.getConstructorParams()),o=new Blob([JSON.stringify(n,null,2)],{type:"application/json"}),i=URL.createObjectURL(o),r=document.createElement("a");r.href=i,r.download=`${e}_input.json`,r.click(),URL.revokeObjectURL(i)}catch(n){alert(`Error downloading input for ${e}: ${n instanceof Error?n.message:String(n)}`)}},sWo=({solver:t,onStepUntilPhase:e,onDownloadInput:n})=>{const o=t.pipelineDef.map((a,A)=>eWo(t,A)),i=a=>{e?.(a)},r=a=>{a.solverInstance&&(n?n(a.solverInstance,a.name):rWo(a.solverInstance,a.name))},s=a=>`${(a/1e3).toFixed(2)}s`;return z.jsxs("div",{className:"border-t border-gray-200",children:[z.jsx("div",{className:"px-4 py-2 bg-gray-50 border-b border-gray-200",children:z.jsx("h3",{className:"text-sm font-semibold text-gray-700",children:"Pipeline Steps"})}),z.jsx("div",{className:"overflow-x-auto",children:z.jsxs("table",{className:"w-full text-sm",children:[z.jsx("thead",{children:z.jsxs("tr",{className:"bg-gray-50 border-b border-gray-200",children:[z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Step"}),z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Status"}),z.jsxs("th",{className:"px-4 py-2 text-center font-semibold text-gray-700",children:["i",z.jsx("sub",{children:"0"})]}),z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Iterations"}),z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Progress"}),z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Time"}),z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stats"}),z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Input"})]})}),z.jsx("tbody",{children:o.map(a=>z.jsxs("tr",{className:`border-b border-gray-100 ${a.status==="In Progress"?"bg-yellow-50":""}`,children:[z.jsx("td",{className:"px-4 py-2",children:z.jsxs("div",{className:"flex items-center gap-2",children:[z.jsx("span",{className:"text-gray-400 w-6",children:String(a.index+1).padStart(2,"0")}),z.jsx("button",{onClick:()=>i(a.name),disabled:a.status==="Completed"||t.solved||t.failed,className:"text-blue-500 hover:text-blue-700 disabled:text-gray-300 disabled:cursor-not-allowed",title:`Step until ${a.name} completes`,children:z.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:z.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"})})}),z.jsx("span",{className:"font-medium text-gray-900",children:a.name})]})}),z.jsx("td",{className:"px-4 py-2",children:z.jsx(tWo,{status:a.status})}),z.jsx("td",{className:"px-4 py-2 text-center text-gray-600",children:a.firstIteration!==null?a.firstIteration:""}),z.jsx("td",{className:"px-4 py-2 text-gray-600",children:a.iterations}),z.jsx("td",{className:"px-4 py-2",children:z.jsx(nWo,{progress:a.progress})}),z.jsx("td",{className:"px-4 py-2 text-gray-600",children:s(a.timeSpent)}),z.jsx("td",{className:"px-4 py-2 text-gray-500",children:z.jsx(iWo,{stats:a.stats})}),z.jsx("td",{className:"px-4 py-2",children:a.solverInstance?z.jsxs("button",{onClick:()=>r(a),className:"flex items-center gap-1 text-blue-500 hover:text-blue-700",title:`Download input for ${a.name}`,children:[z.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:z.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"})}),z.jsx("span",{children:"Input"})]}):null})]},a.name))})]})})]})},aWo=class extends Xr.Component{constructor(t){super(t),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(t){console.error("InteractiveGraphics render error:",t)}render(){return this.state.hasError?this.props.fallback:this.props.children}};function AWo({graphics:t}){const e=t.points??[],n=t.lines??[],o=t.rects??[],i=t.circles??[],r=t.texts??[];let s=Number.POSITIVE_INFINITY,a=Number.POSITIVE_INFINITY,A=Number.NEGATIVE_INFINITY,c=Number.NEGATIVE_INFINITY;const l=(m,p)=>{typeof m=="number"&&(m<s&&(s=m),m>A&&(A=m)),typeof p=="number"&&(p<a&&(a=p),p>c&&(c=p))};for(const m of e)l(m.x,m.y);for(const m of n){const p=m.points??[];for(const I of p)l(I.x,I.y)}for(const m of o){const p=m.x??0,I=m.y??0,f=m.width??0,C=m.height??0;l(p,I),l(p+f,I+C)}for(const m of i){const p=m.x??0,I=m.y??0,f=m.radius??1;l(p-f,I-f),l(p+f,I+f)}for(const m of r)l(m.x,m.y);(!isFinite(s)||!isFinite(a)||!isFinite(A)||!isFinite(c))&&(s=-20,a=-20,A=20,c=20);const g=10,u=s-g,h=a-g,d=Math.max(1,A-s+2*g),_=Math.max(1,c-a+2*g);return z.jsxs("svg",{className:"w-full h-[400px] bg-white",viewBox:`${u} ${h} ${d} ${_}`,role:"img","aria-label":"Graphics fallback",children:[o.map((m,p)=>z.jsx("rect",{x:m.x??0,y:m.y??0,width:m.width??0,height:m.height??0,fill:"none",stroke:m.strokeColor??"black",strokeWidth:m.strokeWidth??1},`rect-${p}`)),n.map((m,p)=>z.jsx("polyline",{fill:"none",stroke:m.strokeColor??"black",strokeWidth:m.strokeWidth??1,points:(m.points??[]).map(I=>`${I.x??0},${I.y??0}`).join(" ")},`line-${p}`)),i.map((m,p)=>z.jsx("circle",{cx:m.x??0,cy:m.y??0,r:m.radius??1.5,fill:m.fillColor??"none",stroke:m.strokeColor??"black",strokeWidth:m.strokeWidth??1},`circle-${p}`)),e.map((m,p)=>z.jsx("circle",{cx:m.x??0,cy:m.y??0,r:m.radius??1.5,fill:m.color??"black"},`point-${p}`)),r.map((m,p)=>z.jsx("text",{x:m.x??0,y:m.y??0,fontSize:m.fontSize??10,fill:m.color??"black",children:m.text??""},`text-${p}`))]})}var cWo=({solver:t,animationSpeed:e=25,onSolverStarted:n,onSolverCompleted:o})=>{const[i,r]=X.useReducer(l=>l+1,0),s=X.useMemo(()=>{try{return t.visualize()||{points:[],lines:[],rects:[],circles:[]}}catch(l){return console.error("Visualization error:",l),{points:[],lines:[],rects:[],circles:[]}}},[t,i]),a=X.useMemo(()=>(s.rects?.length||0)===0&&(s.lines?.length||0)===0&&(s.points?.length||0)===0&&(s.circles?.length||0)===0,[s]);X.useEffect(()=>{if(!(typeof document>"u")&&!document.querySelector('script[src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"]')){const l=document.createElement("script");l.src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4",document.head.appendChild(l)}},[]);const A=t.pipelineDef!==void 0,c=l=>{const g=t;if(!t.solved&&!t.failed){for(;!t.solved&&!t.failed&&g.currentPipelineStepIndex<=g.pipelineDef.findIndex(u=>u.solverName===l);)t.step();r()}};return z.jsxs("div",{children:[z.jsx($qo,{solver:t,triggerRender:r,animationSpeed:e,onSolverStarted:n,onSolverCompleted:o}),a?z.jsx("div",{className:"p-4 text-gray-500",children:"No Graphics Yet"}):z.jsx(aWo,{fallback:z.jsx(AWo,{graphics:s}),children:z.jsx(Wqo,{graphics:s})}),A&&z.jsx(sWo,{solver:t,onStepUntilPhase:c})]})};const lWo=()=>{X.useEffect(()=>{const t="tailwind-cdn-script";if(document.getElementById(t)||window.tailwind)return;const e=document.createElement("div");e.className="hidden",document.body.appendChild(e);const n=window.getComputedStyle(e).display==="none";if(document.body.removeChild(e),n)return;const o=document.createElement("script");o.id=t,o.src="https://cdn.tailwindcss.com",document.head.appendChild(o)},[])},gWo=1e3,iQ=(t,e)=>{const{fileName:n,mimeType:o="text/plain"}=e,i=t instanceof Blob?t:new Blob([t],{type:o}),r=URL.createObjectURL(i),s=document.createElement("a");s.href=r,s.download=n,s.target="_blank",s.rel="noopener noreferrer",s.style.display="none",document.body.appendChild(s),s.click(),document.body.removeChild(s),setTimeout(()=>{URL.revokeObjectURL(r)},gWo)},a7e=t=>{let e=t.trim().replace(/[\\/:*?"<>|]/g,"_").replace(/[\x00-\x1f]/g,"").replace(/^\.+/,"").replace(/\.+$/,"").replace(/\s+/g," ").replace(/_+/g,"_");return/^(con|prn|aux|nul|com[0-9]|lpt[0-9])$/i.test(e)&&(e=`_${e}`),e=e.slice(0,200),e||"untitled"},_b="https://github.com/tscircuit/tscircuit-autorouter/issues/new",gGt="https://github.com/tscircuit/copper-pour-solver/issues/new",uGt="https://github.com/tscircuit/calculate-packing/issues/new",uWo="https://github.com/tscircuit/matchpack/issues/new",dGt="https://github.com/tscircuit/schematic-trace-solver/issues/new?template=json-bug-report.yml",dWo={PackSolver2:uGt,LayoutPipelineSolver:uWo,AutoroutingPipelineSolver:_b,AssignableAutoroutingPipeline2:_b,AssignableAutoroutingPipeline3:_b,AutoroutingPipeline1_OriginalUnravel:_b,AutoroutingPipelineSolver3_HgPortPointPathing:_b,AutoroutingPipelineSolver4:_b,AutoroutingPipelineSolver5:_b,AutoroutingPipelineSolver7_MultiGraph:_b,AutoroutingPipelineSolver8:_b,CopperPourPipelineSolver:gGt,SchematicTracePipelineSolver:dGt},hWo=t=>t.toLowerCase().includes("pack")?hNt:t.toLowerCase().includes("rout")?ALo:OFo,hGt=t=>{const e=dWo[t];if(e)return e;const n=t.toLowerCase();return n.includes("autorout")?_b:n.includes("schematic")&&n.includes("trace")?dGt:n.includes("copperpour")?gGt:n.includes("pack")?uGt:null},_Wo=t=>`${a7e(`${t.componentName}-${t.solverName}`)}-solver-input.json`,_Gt=t=>{iQ(JSON.stringify(t.solverParams,null,2),{fileName:_Wo(t),mimeType:"application/json"})},mWo=({solverEvent:t})=>{const e=hGt(t.solverName);return z.jsxs("div",{className:"rf-flex rf-items-center rf-justify-end rf-gap-2 rf-border-b rf-border-gray-200 rf-bg-gray-50 rf-px-4 rf-py-2",children:[z.jsxs(fa,{type:"button",variant:"outline",size:"sm",onClick:()=>_Gt(t),children:[z.jsx(Zre,{className:"rf-w-4 rf-h-4"}),"Download"]}),e?z.jsx(fa,{asChild:!0,variant:"outline",size:"sm",children:z.jsxs("a",{href:e,target:"_blank",rel:"noopener noreferrer",children:[z.jsx($re,{className:"rf-w-4 rf-h-4"}),"Report"]})}):z.jsxs(fa,{type:"button",variant:"outline",size:"sm",disabled:!0,title:"No report link configured for this solver",children:[z.jsx($re,{className:"rf-w-4 rf-h-4"}),"Report"]})]})},pWo=({solverEvent:t})=>{const e=hGt(t.solverName);return e?z.jsx(fa,{asChild:!0,variant:"ghost",size:"icon",className:"rf-h-8 rf-w-8",children:z.jsx("a",{href:e,target:"_blank",rel:"noopener noreferrer",title:"Report solver bug","aria-label":"Report solver bug",children:z.jsx($re,{className:"rf-w-4 rf-h-4"})})}):z.jsx(fa,{type:"button",variant:"ghost",size:"icon",className:"rf-h-8 rf-w-8",disabled:!0,title:"No report link configured for this solver","aria-label":"Report solver bug",children:z.jsx($re,{className:"rf-w-4 rf-h-4"})})},IWo=({solverEvents:t=[]})=>{const[e,n]=X.useState(null);lWo();const o=X.useMemo(()=>{const a=new Map;for(const A of t){const c=`${A.componentName}-${A.solverName}`;a.set(c,A)}return a},[t]),i=X.useMemo(()=>Array.from(o.keys()),[o]),r=e?o.get(e):null,s=X.useMemo(()=>{if(!r)return{instance:null,error:null,classFound:!1};const a=Vye[r.solverName];if(!a)return{instance:null,error:`Solver class "${r.solverName}" not found in SOLVERS registry. Available: ${Object.keys(Vye).join(", ")}`,classFound:!1};try{const A=r.solverParams,c=A?.input!==void 0?A.input:A;return{instance:new a(c),error:null,classFound:!0}}catch(A){const c=A instanceof Error?A.message:String(A);return console.error("Failed to reconstruct solver:",A),{instance:null,error:`Failed to instantiate solver: ${c}`,classFound:!0}}},[r]);return t.length===0?z.jsx("div",{className:"rf-p-4",children:z.jsx("div",{className:"rf-bg-gray-50 rf-rounded-md rf-border rf-border-gray-200",children:z.jsxs("div",{className:"rf-p-4",children:[z.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800 rf-mb-3",children:"No Solvers Detected"}),z.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."})]})})}):z.jsxs("div",{className:"rf-flex rf-h-full rf-overflow-hidden",children:[z.jsxs("div",{className:"rf-w-64 rf-border-r rf-border-gray-200 rf-overflow-y-auto rf-flex-shrink-0",children:[z.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 A=o.get(a),c=e===a;return z.jsx("div",{className:`rf-px-3 rf-py-2 rf-cursor-pointer rf-border-b rf-border-gray-100 ${c?"rf-bg-blue-50 rf-border-l-2 rf-border-l-blue-500":"hover:rf-bg-gray-50"}`,onClick:()=>n(a),children:(()=>{const l=hWo(A.solverName);return z.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[z.jsx(l,{className:"rf-w-4 rf-h-4 rf-text-blue-500 rf-flex-shrink-0"}),z.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[z.jsx("div",{className:"rf-text-sm rf-font-medium rf-text-gray-800 rf-truncate",children:A.componentName}),z.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate",children:A.solverName})]})]})})()},a)})]}),z.jsx("div",{className:"rf-flex-1 rf-overflow-hidden",children:r?s.instance?z.jsxs("div",{className:"rf-flex rf-h-full rf-flex-col rf-overflow-y-auto",children:[z.jsx(mWo,{solverEvent:r}),z.jsx("div",{className:"rf-min-h-0 rf-flex-1",children:z.jsx(Nx,{fallback:z.jsx("div",{className:"rf-p-4",children:z.jsxs("div",{className:"rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200 rf-p-4",children:[z.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-2",children:"Error Loading Solver Debugger"}),z.jsxs("p",{className:"rf-text-sm rf-text-red-600",children:["Failed to render the solver debugger for"," ",r.solverName]})]})}),children:z.jsx(cWo,{solver:s.instance})})})]}):z.jsxs("div",{className:"rf-p-4",children:[z.jsxs("div",{className:"rf-mb-4",children:[z.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800",children:r.solverName}),z.jsxs("p",{className:"rf-text-sm rf-text-gray-500",children:["Component: ",r.componentName]})]}),s.error&&z.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:z.jsx("p",{className:`rf-text-sm ${s.classFound?"rf-text-red-700":"rf-text-yellow-700"}`,children:s.error})}),z.jsxs("div",{className:"rf-border rf-border-gray-200 rf-rounded-md rf-overflow-hidden",children:[z.jsxs("div",{className:"rf-px-3 rf-py-2 rf-bg-gray-50 rf-flex rf-items-center rf-justify-between rf-gap-2",children:[z.jsx("span",{className:"rf-text-sm rf-font-medium rf-text-gray-700",children:"Solver Parameters"}),z.jsxs("div",{className:"rf-flex rf-items-center rf-gap-1",children:[z.jsx(pWo,{solverEvent:r}),z.jsx(fa,{type:"button",variant:"ghost",size:"icon",className:"rf-h-8 rf-w-8","aria-label":"Download solver input JSON",title:"Download solver input JSON",onClick:()=>_Gt(r),children:z.jsx(Zre,{className:"rf-w-4 rf-h-4"})})]})]}),z.jsx("div",{className:"rf-p-3 rf-bg-white rf-border-t rf-border-gray-200",children:z.jsx("pre",{className:"rf-text-xs rf-font-mono rf-text-gray-600 rf-whitespace-pre-wrap rf-overflow-x-auto",children:JSON.stringify(r.solverParams,null,2)})})]})]}):z.jsx("div",{className:"rf-flex rf-items-center rf-justify-center rf-h-full",children:z.jsx("p",{className:"rf-text-sm rf-text-gray-500",children:"Select a solver from the list to view details"})})})]})},mGt=({errorMessage:t,errorStack:e,circuitJsonErrors:n})=>{X.useEffect(()=>{if(t){const o=new Error(t);e&&(o.stack=e);try{DR.captureException(o)}catch{}}},[t,e]),X.useEffect(()=>{if(n&&n.length>0)for(const o of n){const i=new Error(o.message||"Circuit JSON Error");o.stack&&(i.stack=o.stack);try{DR.captureException(i,{error_type:o.type})}catch{}}},[n])},pGt=t=>{X.useEffect(()=>{try{yro(t)}catch{}},[t.source,t.component,t.isWebEmbedded,t.activeTab])},IGt="0.0.2474",fWo={version:IGt},mae=tIt()(nIt(t=>({lastRunEvalVersion:void 0,setLastRunEvalVersion:e=>{t({lastRunEvalVersion:e})}}),{name:"runframe-runner-store"})),CWo=t=>{const[e,n]=X.useState([]),[o,i]=X.useState(null),[r,s]=X.useState(""),[a,A]=iR("eval-version-selection",null),c=mae(h=>h.setLastRunEvalVersion),l=mae(h=>h.lastRunEvalVersion);return X.useEffect(()=>{t&&fetch("https://data.jsdelivr.com/v1/package/npm/@tscircuit/eval").then(h=>h.json()).then(h=>{if(Array.isArray(h?.versions)){let d=[...h.versions];h.tags?.latest&&(i(h.tags.latest),d=d.filter(_=>_!==h.tags.latest)),n(d)}}).catch(()=>{})},[t]),X.useEffect(()=>{t&&(a?(window.TSCIRCUIT_LATEST_EVAL_VERSION=a,c(a)):o&&(window.TSCIRCUIT_LATEST_EVAL_VERSION=o,c(o)))},[t,a,o]),{versions:X.useMemo(()=>e.filter(h=>h.includes(r)).slice(0,50),[e,r]),latestVersion:o,lastRunEvalVersion:l,search:r,setSearch:s,selectVersion:h=>{A(h),s("")}}},yWo=({snippetNames:t,onSelect:e,onCancel:n,isOpen:o})=>{const[i,r]=X.useState(""),[s,a]=X.useState("");if(!o)return null;const A=t.filter(g=>g.toLowerCase().includes(s.toLowerCase())),c=s&&!t.includes(s),l=g=>{g.key==="Enter"&&(A.length===1?r(A[0]):c&&r(s))};return z.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:z.jsxs("div",{className:"rf-bg-white rf-rounded-lg rf-p-6 rf-w-96",children:[z.jsx("h2",{className:"rf-text-lg rf-font-semibold rf-mb-4",children:"Select Snippet"}),z.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:g=>a(g.target.value),onKeyDown:l}),z.jsxs("div",{className:"rf-h-60 rf-overflow-y-auto",children:[A.map(g=>z.jsx("button",{type:"button",className:`w-full text-left px-4 py-2 rounded hover:bg-gray-100 ${i===g?"bg-blue-50":""}`,onClick:()=>r(g),children:g},g)),c&&z.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:()=>r(s),children:['Create new "',s,'"']})]}),z.jsxs("div",{className:"rf-mt-4 rf-flex rf-justify-end rf-gap-2",children:[z.jsx("button",{type:"button",className:"rf-px-4 rf-py-2 rf-text-gray-600 rf-hover:text-gray-800",onClick:n,children:"Cancel"}),z.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}`})]})]})})},EWo=t=>{const e=X.useRef(null),n=ju(o=>o.recentEvents);X.useEffect(()=>{if(n.length===0)return;const o=n[0];o.event_id!==e.current&&(t(o),e.current=o.event_id)},[n,t])};var xWo=Object.defineProperty,aE=(t,e)=>xWo(t,"name",{value:e,configurable:!0}),A7e="Dialog",[fGt,CGt]=Cy(A7e),[BWo,rQ]=fGt(A7e),c7e=aE(t=>{const{__scopeDialog:e,children:n,open:o,defaultOpen:i,onOpenChange:r,modal:s=!0}=t,a=X.useRef(null),A=X.useRef(null),[c,l]=MB({prop:o,defaultProp:i??!1,onChange:r,caller:A7e}),[g,u]=X.useState(0),[h,d]=X.useState(0);return z.jsx(BWo,{scope:e,triggerRef:a,contentRef:A,contentId:P_(),titleId:P_(),descriptionId:P_(),titlePresent:g>0,descriptionPresent:h>0,setTitleCount:u,setDescriptionCount:d,open:c,onOpenChange:l,onOpenToggle:X.useCallback(()=>l(_=>!_),[l]),modal:s,children:n})},"Dialog"),QWo="DialogTrigger",SWo=X.forwardRef(aE(function(e,n){const{__scopeDialog:o,...i}=e,r=rQ(QWo,o),s=Xa(n,r.triggerRef);return z.jsx(Ls.button,{type:"button","aria-haspopup":"dialog","aria-expanded":r.open,"aria-controls":r.open?r.contentId:void 0,"data-state":fae(r.open),...i,ref:s,onClick:yi(e.onClick,r.onOpenToggle)})},"DialogTrigger")),yGt="DialogPortal",[bWo,EGt]=fGt(yGt,{forceMount:void 0}),l7e=aE(t=>{const{__scopeDialog:e,forceMount:n,children:o,container:i}=t,r=rQ(yGt,e);return z.jsx(bWo,{scope:e,forceMount:n,children:X.Children.map(o,s=>z.jsx(O2,{present:n||r.open,children:z.jsx(mse,{asChild:!0,container:i,children:s})}))})},"DialogPortal"),g7e="DialogOverlay",pae=X.forwardRef(aE(function(e,n){const o=EGt(g7e,e.__scopeDialog),{forceMount:i=o.forceMount,...r}=e,s=rQ(g7e,e.__scopeDialog);return s.modal?z.jsx(O2,{present:i||s.open,children:z.jsx(vWo,{...r,ref:n})}):null},"DialogOverlay")),DWo=wB("DialogOverlay.RemoveScroll"),vWo=X.forwardRef(aE(function(e,n){const{__scopeDialog:o,...i}=e,r=rQ(g7e,o),s=INt(),a=Xa(n,s);return z.jsx(EY,{as:DWo,allowPinchZoom:!0,shards:[r.contentRef],children:z.jsx(Ls.div,{"data-state":fae(r.open),...i,ref:a,style:{pointerEvents:"auto",...i.style}})})},"DialogOverlayImpl")),zY="DialogContent",Iae=X.forwardRef(aE(function(e,n){const o=EGt(zY,e.__scopeDialog),{forceMount:i=o.forceMount,...r}=e,s=rQ(zY,e.__scopeDialog);return z.jsx(O2,{present:i||s.open,children:s.modal?z.jsx(PWo,{...r,ref:n}):z.jsx(wWo,{...r,ref:n})})},"DialogContent")),PWo=X.forwardRef(aE(function(e,n){const o=rQ(zY,e.__scopeDialog),i=X.useRef(null),r=Xa(n,o.contentRef,i);return X.useEffect(()=>{const s=i.current;if(s)return fse(s)},[]),z.jsx(xGt,{...e,ref:r,trapFocus:o.open,disableOutsidePointerEvents:o.open,onCloseAutoFocus:yi(e.onCloseAutoFocus,s=>{s.preventDefault(),o.triggerRef.current?.focus()}),onPointerDownOutside:yi(e.onPointerDownOutside,s=>{const a=s.detail.originalEvent,A=a.button===0&&a.ctrlKey===!0;(a.button===2||A)&&s.preventDefault()}),onFocusOutside:yi(e.onFocusOutside,s=>s.preventDefault())})},"DialogContentModal")),wWo=X.forwardRef(aE(function(e,n){const o=rQ(zY,e.__scopeDialog),i=X.useRef(!1),r=X.useRef(!1);return z.jsx(xGt,{...e,ref:n,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:s=>{e.onCloseAutoFocus?.(s),s.defaultPrevented||(i.current||o.triggerRef.current?.focus(),s.preventDefault()),i.current=!1,r.current=!1},onInteractOutside:s=>{e.onInteractOutside?.(s),s.defaultPrevented||(i.current=!0,s.detail.originalEvent.type==="pointerdown"&&(r.current=!0));const a=s.target;o.triggerRef.current?.contains(a)&&s.preventDefault(),s.detail.originalEvent.type==="focusin"&&r.current&&s.preventDefault()}})},"DialogContentNonModal")),xGt=X.forwardRef(aE(function(e,n){const{__scopeDialog:o,trapFocus:i,onOpenAutoFocus:r,onCloseAutoFocus:s,...a}=e,A=rQ(zY,o);return xk(),z.jsx(z.Fragment,{children:z.jsx(tse,{asChild:!0,loop:!0,trapped:i,onMountAutoFocus:r,onUnmountAutoFocus:s,children:z.jsx(IY,{role:"dialog",id:A.contentId,"aria-describedby":A.descriptionPresent?A.descriptionId:void 0,"aria-labelledby":A.titlePresent?A.titleId:void 0,"data-state":fae(A.open),...a,ref:n,deferPointerDownOutside:!0,onDismiss:()=>A.onOpenChange(!1)})})})},"DialogContentImpl")),MWo="DialogTitle",u7e=X.forwardRef(aE(function(e,n){const{__scopeDialog:o,...i}=e,r=rQ(MWo,o),{setTitleCount:s}=r;return jd(()=>(s(a=>a+1),()=>s(a=>a-1)),[s]),z.jsx(Ls.h2,{id:r.titleId,...i,ref:n})},"DialogTitle")),NWo="DialogDescription",d7e=X.forwardRef(aE(function(e,n){const{__scopeDialog:o,...i}=e,r=rQ(NWo,o),{setDescriptionCount:s}=r;return jd(()=>(s(a=>a+1),()=>s(a=>a-1)),[s]),z.jsx(Ls.p,{id:r.descriptionId,...i,ref:n})},"DialogDescription")),RWo="DialogClose",BGt=X.forwardRef(aE(function(e,n){const{__scopeDialog:o,...i}=e,r=rQ(RWo,o);return z.jsx(Ls.button,{type:"button",...i,ref:n,onClick:yi(e.onClick,()=>r.onOpenChange(!1))})},"DialogClose"));function fae(t){return t?"open":"closed"}aE(fae,"getState");var TWo=Object.defineProperty,b5=(t,e)=>TWo(t,"name",{value:e,configurable:!0}),kWo="AlertDialog",[FWo,oai]=Cy(kWo,[CGt]),D5=CGt(),LWo=b5(t=>{const{__scopeAlertDialog:e,...n}=t,o=D5(e);return z.jsx(c7e,{...o,...n,modal:!0})},"AlertDialog");X.forwardRef(b5(function(e,n){const{__scopeAlertDialog:o,...i}=e,r=D5(o);return z.jsx(SWo,{...r,...i,ref:n})},"AlertDialogTrigger"));var HWo=b5(t=>{const{__scopeAlertDialog:e,...n}=t,o=D5(e);return z.jsx(l7e,{...o,...n})},"AlertDialogPortal"),GWo=X.forwardRef(b5(function(e,n){const{__scopeAlertDialog:o,...i}=e,r=D5(o);return z.jsx(pae,{...r,...i,ref:n})},"AlertDialogOverlay")),OWo="AlertDialogContent",[KWo,UWo]=FWo(OWo),YWo=X.forwardRef(b5(function(e,n){const{__scopeAlertDialog:o,children:i,...r}=e,s=D5(o),a=X.useRef(null),A=Xa(n,a),c=X.useRef(null);return z.jsx(KWo,{scope:o,cancelRef:c,children:z.jsx(Iae,{role:"alertdialog",...s,...r,ref:A,onOpenAutoFocus:yi(r.onOpenAutoFocus,l=>{l.preventDefault(),c.current?.focus({preventScroll:!0})}),onPointerDownOutside:l=>l.preventDefault(),onInteractOutside:l=>l.preventDefault(),children:i})})},"AlertDialogContent")),zWo=X.forwardRef(b5(function(e,n){const{__scopeAlertDialog:o,...i}=e,r=D5(o);return z.jsx(u7e,{...r,...i,ref:n})},"AlertDialogTitle")),VWo=X.forwardRef(b5(function(e,n){const{__scopeAlertDialog:o,...i}=e,r=D5(o);return z.jsx(d7e,{...r,...i,ref:n})},"AlertDialogDescription")),JWo=X.forwardRef(b5(function(e,n){const{__scopeAlertDialog:o,...i}=e,r=D5(o);return z.jsx(BGt,{...r,...i,ref:n})},"AlertDialogAction")),qWo="AlertDialogCancel",WWo=X.forwardRef(b5(function(e,n){const{__scopeAlertDialog:o,...i}=e,{cancelRef:r}=UWo(qWo,o),s=D5(o),a=Xa(n,r);return z.jsx(BGt,{...s,...i,ref:a})},"AlertDialogCancel")),jWo=LWo,XWo=HWo,QGt=GWo,SGt=YWo,bGt=JWo,DGt=WWo,vGt=zWo,PGt=VWo;const wGt=jWo,$Wo=XWo,MGt=X.forwardRef(({className:t,...e},n)=>z.jsx(QGt,{className:Ei("rf-fixed rf-inset-0 rf-z-50 rf-bg-black/80 data-[state=open]:rf-animate-in data-[state=closed]:rf-animate-out data-[state=closed]:rf-fade-out-0 data-[state=open]:rf-fade-in-0",t),...e,ref:n}));MGt.displayName=QGt.displayName;const h7e=X.forwardRef(({className:t,...e},n)=>z.jsxs($Wo,{children:[z.jsx(MGt,{}),z.jsx(SGt,{ref:n,className:Ei("rf-fixed rf-left-[50%] rf-top-[50%] rf-z-50 rf-grid rf-w-full rf-max-w-lg rf-translate-x-[-50%] rf-translate-y-[-50%] rf-gap-4 rf-border rf-border-zinc-200 rf-bg-white rf-p-6 rf-shadow-lg rf-duration-200 data-[state=open]:rf-animate-in data-[state=closed]:rf-animate-out data-[state=closed]:rf-fade-out-0 data-[state=open]:rf-fade-in-0 data-[state=closed]:rf-zoom-out-95 data-[state=open]:rf-zoom-in-95 data-[state=closed]:rf-slide-out-to-left-1/2 data-[state=closed]:rf-slide-out-to-top-[48%] data-[state=open]:rf-slide-in-from-left-1/2 data-[state=open]:rf-slide-in-from-top-[48%] sm:rf-rounded-lg dark:rf-border-zinc-800 dark:rf-bg-zinc-950",t),...e})]}));h7e.displayName=SGt.displayName;const _7e=({className:t,...e})=>z.jsx("div",{className:Ei("rf-flex rf-flex-col rf-space-y-2 rf-text-center sm:rf-text-left",t),...e});_7e.displayName="AlertDialogHeader";const m7e=({className:t,...e})=>z.jsx("div",{className:Ei("rf-flex rf-flex-col-reverse sm:rf-flex-row sm:rf-justify-end sm:rf-space-x-2",t),...e});m7e.displayName="AlertDialogFooter";const p7e=X.forwardRef(({className:t,...e},n)=>z.jsx(vGt,{ref:n,className:Ei("rf-text-lg rf-font-semibold",t),...e}));p7e.displayName=vGt.displayName;const I7e=X.forwardRef(({className:t,...e},n)=>z.jsx(PGt,{ref:n,className:Ei("rf-text-sm rf-text-zinc-500 dark:rf-text-zinc-400",t),...e}));I7e.displayName=PGt.displayName;const ZWo=X.forwardRef(({className:t,...e},n)=>z.jsx(bGt,{ref:n,className:Ei(Ck(),t),...e}));ZWo.displayName=bGt.displayName;const f7e=X.forwardRef(({className:t,...e},n)=>z.jsx(DGt,{ref:n,className:Ei(Ck({variant:"outline"}),"rf-mt-2 sm:rf-mt-0",t),...e}));f7e.displayName=DGt.displayName;var ejo=Object.defineProperty,v5=(t,e)=>ejo(t,"name",{value:e,configurable:!0}),C7e="Checkbox",[tjo,iai]=Cy(C7e),[njo,y7e]=tjo(C7e);function NGt(t){const{__scopeCheckbox:e,checked:n,children:o,defaultChecked:i,disabled:r,form:s,name:a,onCheckedChange:A,required:c,value:l="on",internal_do_not_use_render:g}=t,[u,h]=MB({prop:n,defaultProp:i??!1,onChange:A,caller:C7e}),[d,_]=X.useState(null),[m,p]=X.useState(null),I=X.useRef(!1),[f,C]=X.useReducer(B=>B+1,0),y=d?!!s||!!d.closest("form"):!0,E={checked:u,disabled:r,setChecked:h,control:d,setControl:_,name:a,form:s,value:l,hasConsumerStoppedPropagationRef:I,userInteractionCount:f,onUserInteraction:C,required:c,defaultChecked:P5(i)?!1:i,isFormControl:y,bubbleInput:m,setBubbleInput:p};return z.jsx(njo,{scope:e,...E,children:TGt(g)?g(E):o})}v5(NGt,"CheckboxProvider");var ojo="CheckboxTrigger",ijo=X.forwardRef(v5(function({__scopeCheckbox:e,onKeyDown:n,onClick:o,...i},r){const{control:s,value:a,disabled:A,checked:c,required:l,setControl:g,setChecked:u,hasConsumerStoppedPropagationRef:h,onUserInteraction:d,isFormControl:_,bubbleInput:m}=y7e(ojo,e),p=Xa(r,g),I=X.useRef(c);return X.useEffect(()=>{const f=s?.form;if(f){const C=v5(()=>u(I.current),"reset");return f.addEventListener("reset",C),()=>f.removeEventListener("reset",C)}},[s,u]),z.jsx(Ls.button,{type:"button",role:"checkbox","aria-checked":P5(c)?"mixed":c,"aria-required":l,"data-state":E7e(c),"data-disabled":A?"":void 0,disabled:A,value:a,...i,ref:p,onKeyDown:yi(n,f=>{f.key==="Enter"&&f.preventDefault()}),onClick:yi(o,f=>{d(),u(C=>P5(C)?!0:!C),m&&_&&(h.current=f.isPropagationStopped(),h.current||f.stopPropagation())})})},"CheckboxTrigger")),RGt=X.forwardRef(v5(function(e,n){const{__scopeCheckbox:o,name:i,checked:r,defaultChecked:s,required:a,disabled:A,value:c,onCheckedChange:l,form:g,...u}=e;return z.jsx(NGt,{__scopeCheckbox:o,checked:r,defaultChecked:s,disabled:A,required:a,onCheckedChange:l,name:i,form:g,value:c,internal_do_not_use_render:({isFormControl:h})=>z.jsxs(z.Fragment,{children:[z.jsx(ijo,{...u,ref:n,__scopeCheckbox:o}),h&&z.jsx(Ajo,{__scopeCheckbox:o})]})})},"Checkbox")),rjo="CheckboxIndicator",sjo=X.forwardRef(v5(function(e,n){const{__scopeCheckbox:o,forceMount:i,...r}=e,s=y7e(rjo,o);return z.jsx(O2,{present:i||P5(s.checked)||s.checked===!0,children:z.jsx(Ls.span,{"data-state":E7e(s.checked),"data-disabled":s.disabled?"":void 0,...r,ref:n,style:{pointerEvents:"none",...e.style}})})},"CheckboxIndicator")),ajo="CheckboxBubbleInput",Ajo=X.forwardRef(v5(function({__scopeCheckbox:e,onClick:n,...o},i){const{control:r,hasConsumerStoppedPropagationRef:s,userInteractionCount:a,checked:A,defaultChecked:c,required:l,disabled:g,name:u,value:h,form:d,bubbleInput:_,setBubbleInput:m}=y7e(ajo,e),p=Xa(i,m),I=x8e(r),f=X.useRef(!1),C=X.useRef(A),y=X.useRef(a);X.useEffect(()=>{const B=_;if(!B)return;const Q=window.HTMLInputElement.prototype,D=Object.getOwnPropertyDescriptor(Q,"checked").set,R=a!==y.current;y.current=a;const M=C.current!==A;C.current=A;const L=!(R&&s.current);if(M&&D){f.current=!R;const G=new Event("click",{bubbles:L});B.indeterminate=P5(A),D.call(B,P5(A)?!1:A),B.dispatchEvent(G),f.current=!1}},[_,A,s,a]);const E=X.useRef(P5(A)?!1:A);return z.jsx(Ls.input,{type:"checkbox","aria-hidden":!0,defaultChecked:c??E.current,required:l,disabled:g,name:u,value:h,form:d,...o,tabIndex:-1,ref:p,onClick:yi(n,B=>{f.current&&B.stopPropagation()}),style:{...o.style,...I,position:"absolute",pointerEvents:"none",opacity:0,margin:0,transform:"translateX(-100%)"}})},"CheckboxBubbleInput"));function TGt(t){return typeof t=="function"}v5(TGt,"isFunction");function P5(t){return t==="indeterminate"}v5(P5,"isIndeterminate");function E7e(t){return P5(t)?"indeterminate":t?"checked":"unchecked"}v5(E7e,"getState");const VY=X.forwardRef(({className:t,...e},n)=>z.jsx(RGt,{ref:n,className:Ei("rf-peer rf-h-4 rf-w-4 rf-shrink-0 rf-rounded-sm rf-border rf-border-zinc-200 rf-border-zinc-900 rf-shadow focus-visible:rf-outline-none focus-visible:rf-ring-1 focus-visible:rf-ring-zinc-950 disabled:rf-cursor-not-allowed disabled:rf-opacity-50 data-[state=checked]:rf-bg-zinc-900 data-[state=checked]:rf-text-zinc-50 dark:rf-border-zinc-800 dark:rf-border-zinc-50 dark:focus-visible:rf-ring-zinc-300 dark:data-[state=checked]:rf-bg-zinc-50 dark:data-[state=checked]:rf-text-zinc-900",t),...e,children:z.jsx(sjo,{className:Ei("rf-flex rf-items-center rf-justify-center rf-text-current"),children:z.jsx(UP,{className:"rf-h-4 rf-w-4"})})}));VY.displayName=RGt.displayName;const X6=c7e,cjo=l7e,kGt=X.forwardRef(({className:t,...e},n)=>z.jsx(pae,{className:Ei("rf-fixed rf-inset-0 rf-z-50 rf-bg-black/80 data-[state=open]:rf-animate-in data-[state=closed]:rf-animate-out data-[state=closed]:rf-fade-out-0 data-[state=open]:rf-fade-in-0",t),...e,ref:n}));kGt.displayName=pae.displayName;const tw=X.forwardRef(({className:t,children:e,showOverlay:n=!0,...o},i)=>z.jsxs(cjo,{children:[z.jsx(kGt,{className:Ei(n?"":"rf-hidden")}),z.jsx(Iae,{ref:i,className:Ei("rf-fixed rf-left-[50%] rf-top-[50%] rf-z-50 rf-grid rf-w-full rf-max-w-lg rf-translate-x-[-50%] rf-translate-y-[-50%] rf-gap-4 rf-border rf-border-zinc-200 rf-bg-white rf-p-6 rf-shadow-lg rf-duration-200 data-[state=open]:rf-animate-in data-[state=closed]:rf-animate-out data-[state=closed]:rf-fade-out-0 data-[state=open]:rf-fade-in-0 data-[state=closed]:rf-zoom-out-95 data-[state=open]:rf-zoom-in-95 data-[state=closed]:rf-slide-out-to-left-1/2 data-[state=closed]:rf-slide-out-to-top-[48%] data-[state=open]:rf-slide-in-from-left-1/2 data-[state=open]:rf-slide-in-from-top-[48%] sm:rf-rounded-lg dark:rf-border-zinc-800 dark:rf-bg-zinc-950",t),...o,children:e})]}));tw.displayName=Iae.displayName;const nw=({className:t,...e})=>z.jsx("div",{className:Ei("rf-flex rf-flex-col rf-space-y-2 rf-text-center sm:rf-text-left",t),...e});nw.displayName="DialogHeader";const Kk=({className:t,...e})=>z.jsx("div",{className:Ei("rf-flex rf-flex-col-reverse sm:rf-flex-row sm:rf-justify-end sm:rf-space-x-2",t),...e});Kk.displayName="DialogFooter";const ow=X.forwardRef(({className:t,...e},n)=>z.jsx(u7e,{ref:n,className:Ei("rf-text-lg rf-font-semibold",t),...e}));ow.displayName=u7e.displayName;const $6=X.forwardRef(({className:t,...e},n)=>z.jsx(d7e,{ref:n,className:Ei("rf-text-sm rf-text-zinc-500 dark:rf-text-zinc-400",t),...e}));$6.displayName=d7e.displayName;const Cae={"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"}},ljo="https://cdn.jsdelivr.net/npm/easyeda@latest/dist/browser/index.js";let x7e=null;const B7e=async()=>(x7e||(x7e=import(ljo)),x7e),gjo=t=>(e,n)=>{const o=new Headers(n?.headers),i={};return o.forEach((r,s)=>{i[s]=r}),fetch(`${t?.apiBase??Hf}/proxy`,{...n,headers:{...i,"X-Target-Url":e.toString(),"X-Sender-Origin":i.origin??"","X-Sender-Host":i.host??"https://easyeda.com","X-Sender-Referer":i.referer??"","X-Sender-User-Agent":i["user-agent"]??"","X-Sender-Cookie":i.cookie??"",authority:i.authority??"","content-type":i["content-type"]??"",...t?.headers}})},ujo=async(t,e=10)=>{const n=encodeURIComponent(t),o=await fetch(`https://jlcsearch.tscircuit.com/api/search?limit=${e}&q=${n}`);if(!o.ok)throw new Error(`JLCPCB API error: ${o.status}`);return(await o.json()).components??[]},djo=t=>({lcscId:t.lcsc,manufacturer:t.mfr,description:t.description,partNumber:`C${t.lcsc}`,package:t.package,price:t.price,stock:t.stock,isBasic:t.is_basic}),FGt=async(t,e)=>{const{fetchEasyEDAComponent:n}=await B7e();return n(t,{fetch:gjo(e),includeModelMetadata:e?.includeModelMetadata})},hjo=async(t,e)=>{const{convertRawEasyToTsx:n}=await B7e(),o=await FGt(t,e);return n({rawEasy:o})},_jo=async(t,e)=>{const{EasyEdaJsonSchema:n,convertEasyEdaJsonToCircuitJson:o}=await B7e(),i=await FGt(t,{...e,includeModelMetadata:!1}),r=n.parse(i);return o(r,{shouldRecenter:!0,showDesignator:!0,useModelCdn:!1})};function iw(t){return Array.isArray?Array.isArray(t):HGt(t)==="[object Array]"}function mjo(t){if(typeof t=="string")return t;if(typeof t=="bigint")return t.toString();const e=t+"";return e=="0"&&1/t==-1/0?"-0":e}function Q7e(t){return t==null?"":mjo(t)}function Wf(t){return typeof t=="string"}function yae(t){return typeof t=="number"}function pjo(t){return t===!0||t===!1||Ijo(t)&&HGt(t)=="[object Boolean]"}function LGt(t){return typeof t=="object"}function Ijo(t){return LGt(t)&&t!==null}function AE(t){return t!=null}function Eae(t){return!t.trim().length}function HGt(t){return t==null?t===void 0?"[object Undefined]":"[object Null]":Object.prototype.toString.call(t)}const fjo="Incorrect 'index' type",S7e="Invalid doc index: must be a non-negative integer within the bounds of the docs array",Cjo=t=>`Invalid value for key ${t}`,yjo=t=>`Pattern length exceeds max of ${t}.`,Ejo=t=>`Missing ${t} property in key`,xjo=t=>`Property 'weight' in key '${t}' must be a positive integer`,Bjo="Fuse.match does not support useTokenSearch: token search requires corpus-level statistics (df, fieldCount) that a one-off string comparison does not have. Use new Fuse(...).search(...) instead.",GGt=Object.prototype.hasOwnProperty;var Qjo=class{constructor(t){this._keys=[],this._keyMap={};let e=0;t.forEach(n=>{const o=OGt(n);this._keys.push(o),this._keyMap[o.id]=o,e+=o.weight}),this._keys.forEach(n=>{n.weight/=e})}get(t){return this._keyMap[t]}keys(){return this._keys}toJSON(){return JSON.stringify(this._keys)}};function OGt(t){let e=null,n=null,o=null,i=1,r=null;if(Wf(t)||iw(t))o=t,e=KGt(t),n=xae(t);else{if(!GGt.call(t,"name"))throw new Error(Ejo("name"));const s=t.name;if(o=s,GGt.call(t,"weight")&&t.weight!==void 0&&(i=t.weight,i<=0))throw new Error(xjo(xae(s)));e=KGt(s),n=xae(s),r=t.getFn??null}return{path:e,id:n,weight:i,src:o,getFn:r}}function KGt(t){return iw(t)?t:t.split(".")}function xae(t){return iw(t)?t.join("."):t}function Sjo(t,e){const n=[];let o=!1;const i=(r,s,a,A)=>{if(AE(r))if(!s[a])n.push(A!==void 0?{v:r,i:A}:r);else{const c=r[s[a]];if(!AE(c))return;if(a===s.length-1&&(Wf(c)||yae(c)||pjo(c)||typeof c=="bigint"))n.push(A!==void 0?{v:Q7e(c),i:A}:Q7e(c));else if(iw(c)){o=!0;for(let l=0,g=c.length;l<g;l+=1)i(c[l],s,a+1,l)}else s.length&&i(c,s,a+1,A)}};return i(t,Wf(e)?e.split("."):e,0),o?n:n[0]}const Ts=Object.freeze({...{isCaseSensitive:!1,ignoreDiacritics:!1,includeScore:!1,keys:[],shouldSort:!0,sortFn:(t,e)=>t.score===e.score?t.idx<e.idx?-1:1:t.score<e.score?-1:1},...{includeMatches:!1,findAllMatches:!1,minMatchCharLength:1},...{location:0,threshold:.6,distance:100},...{useExtendedSearch:!1,useTokenSearch:!1,tokenize:void 0,tokenMatch:"any",getFn:Sjo,ignoreLocation:!1,ignoreFieldNorm:!1,fieldNormWeight:1}});function bjo(t){return t>=9&&t<=13||t===32||t===160}function Djo(t=1,e=3){const n=new Map,o=Math.pow(10,e);return{get(i){let r=0,s=!1;for(let A=0;A<i.length;A++)bjo(i.charCodeAt(A))?s=!1:s||(r++,s=!0);if(r===0&&(r=1),n.has(r))return n.get(r);const a=Math.round(o/Math.pow(r,.5*t))/o;return n.set(r,a),a},clear(){n.clear()}}}var b7e=class{constructor({getFn:t=Ts.getFn,fieldNormWeight:e=Ts.fieldNormWeight}={}){this.norm=Djo(e,3),this.getFn=t,this.isCreated=!1,this.docs=[],this.keys=[],this._keysMap={},this.setIndexRecords()}setSources(t=[]){this.docs=t}setIndexRecords(t=[]){this.records=t}setKeys(t=[]){this.keys=t,this._keysMap={},t.forEach((e,n)=>{this._keysMap[e.id]=n})}create(){if(this.isCreated||!this.docs.length)return;this.isCreated=!0;const t=this.docs.length;this.records=new Array(t);let e=0;if(Wf(this.docs[0]))for(let n=0;n<t;n++){const o=this._createStringRecord(this.docs[n],n);o&&(this.records[e++]=o)}else for(let n=0;n<t;n++)this.records[e++]=this._createObjectRecord(this.docs[n],n);this.records.length=e,this.norm.clear()}add(t,e){if(!Number.isInteger(e)||e<0)throw new Error(S7e);if(Wf(t)){const o=this._createStringRecord(t,e);return o&&this.records.push(o),o}const n=this._createObjectRecord(t,e);return this.records.push(n),n}removeAt(t){if(!Number.isInteger(t)||t<0)throw new Error(S7e);for(let e=0,n=this.records.length;e<n;e+=1)if(this.records[e].i===t){this.records.splice(e,1);break}for(let e=0,n=this.records.length;e<n;e+=1)this.records[e].i>t&&(this.records[e].i-=1)}removeAll(t){const e=new Set;for(const o of t)Number.isInteger(o)&&o>=0&&e.add(o);if(e.size===0)return;this.records=this.records.filter(o=>!e.has(o.i));const n=Array.from(e).sort((o,i)=>o-i);for(const o of this.records){let i=0,r=n.length;for(;i<r;){const s=i+r>>>1;n[s]<o.i?i=s+1:r=s}o.i-=i}}getValueForItemAtKeyId(t,e){return t[this._keysMap[e]]}size(){return this.records.length}_createStringRecord(t,e){return!AE(t)||Eae(t)?null:{v:t,i:e,n:this.norm.get(t)}}_createObjectRecord(t,e){const n={i:e,$:{}};for(let o=0,i=this.keys.length;o<i;o++){const r=this.keys[o],s=r.getFn?r.getFn(t):this.getFn(t,r.path);if(AE(s)){if(iw(s)){const a=[];for(let A=0,c=s.length;A<c;A+=1){const l=s[A];if(AE(l)){if(Wf(l)){if(!Eae(l)){const g={v:l,i:A,n:this.norm.get(l)};a.push(g)}}else if(AE(l.v)){const g=Wf(l.v)?l.v:Q7e(l.v);if(!Eae(g)){const u={v:g,i:l.i,n:this.norm.get(g)};a.push(u)}}}}n.$[o]=a}else if(Wf(s)&&!Eae(s)){const a={v:s,n:this.norm.get(s)};n.$[o]=a}}}return n}toJSON(){return{keys:this.keys.map(({getFn:t,...e})=>e),records:this.records}}};function UGt(t,e,{getFn:n=Ts.getFn,fieldNormWeight:o=Ts.fieldNormWeight}={}){const i=new b7e({getFn:n,fieldNormWeight:o});return i.setKeys(t.map(OGt)),i.setSources(e),i.create(),i}function vjo(t,{getFn:e=Ts.getFn,fieldNormWeight:n=Ts.fieldNormWeight}={}){const{keys:o,records:i}=t,r=new b7e({getFn:e,fieldNormWeight:n});return r.setKeys(o),r.setIndexRecords(i),r}function Pjo(t=[],e=Ts.minMatchCharLength){const n=[];let o=-1,i=-1,r=0;for(let s=t.length;r<s;r+=1){const a=t[r];a&&o===-1?o=r:!a&&o!==-1&&(i=r-1,i-o+1>=e&&n.push([o,i]),o=-1)}return t[r-1]&&r-o>=e&&n.push([o,r-1]),n}function wjo(t,e,n,{location:o=Ts.location,distance:i=Ts.distance,threshold:r=Ts.threshold,findAllMatches:s=Ts.findAllMatches,minMatchCharLength:a=Ts.minMatchCharLength,includeMatches:A=Ts.includeMatches,ignoreLocation:c=Ts.ignoreLocation}={}){if(e.length>32)throw new Error(yjo(32));const l=e.length,g=t.length,u=Math.max(0,Math.min(o,g));let h=r,d=u;const _=(b,D)=>{const R=b/l;if(c)return R;const M=Math.abs(u-D);return i?R+M/i:M?1:R},m=a>1||A,p=m?Array(g):[];let I;for(;(I=t.indexOf(e,d))>-1;){const b=_(0,I);if(h=Math.min(b,h),d=I+l,m){let D=0;for(;D<l;)p[I+D]=1,D+=1}}d=-1;let f=[],C=1,y=0,E=l+g;const B=1<<l-1;for(let b=0;b<l;b+=1){let D=0,R=E;for(;D<R;)_(b,u+R)<=h?D=R:E=R,R=Math.floor((E-D)/2+D);E=R;let M=Math.max(1,u-R+1);const L=s?g:Math.min(u+R,g)+l,G=Array(L+2);G[L+1]=(1<<b)-1;for(let O=L;O>=M;O-=1){const U=O-1,W=n[t[U]];if(G[O]=(G[O+1]<<1|1)&W,b&&(G[O]|=(f[O+1]|f[O])<<1|1|f[O+1]),G[O]&B&&(C=_(b,U),C<=h)){if(h=C,d=U,y=b,d<=u)break;M=Math.max(1,2*u-d)}}if(_(b+1,u)>h)break;f=G}if(m&&d>=0){const b=Math.min(g-1,d+l-1+y);for(let D=d;D<=b;D+=1)n[t[D]]&&(p[D]=1)}const Q={isMatch:d>=0,score:Math.max(.001,C)};if(m){const b=Pjo(p,a);b.length?A&&(Q.indices=b):Q.isMatch=!1}return Q}function Mjo(t){const e={};for(let n=0,o=t.length;n<o;n+=1){const i=t.charAt(n);e[i]=(e[i]||0)|1<<o-n-1}return e}function D7e(t){if(t.length<=1)return t;t.sort((n,o)=>n[0]-o[0]||n[1]-o[1]);const e=[t[0]];for(let n=1,o=t.length;n<o;n+=1){const i=e[e.length-1],r=t[n];r[0]<=i[1]+1?i[1]=Math.max(i[1],r[1]):e.push(r)}return e}const YGt={ł:"l",Ł:"L",đ:"d",Đ:"D",ø:"o",Ø:"O",ħ:"h",Ħ:"H",ŧ:"t",Ŧ:"T",ı:"i",ß:"ss"},Njo=new RegExp("["+Object.keys(YGt).join("")+"]","g"),JY=typeof String.prototype.normalize=="function"?t=>t.normalize("NFD").replace(/[\u0300-\u036F\u0483-\u0489\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u0610-\u061A\u064B-\u065F\u0670\u06D6-\u06DC\u06DF-\u06E4\u06E7\u06E8\u06EA-\u06ED\u0711\u0730-\u074A\u07A6-\u07B0\u07EB-\u07F3\u07FD\u0816-\u0819\u081B-\u0823\u0825-\u0827\u0829-\u082D\u0859-\u085B\u08D3-\u08E1\u08E3-\u0903\u093A-\u093C\u093E-\u094F\u0951-\u0957\u0962\u0963\u0981-\u0983\u09BC\u09BE-\u09C4\u09C7\u09C8\u09CB-\u09CD\u09D7\u09E2\u09E3\u09FE\u0A01-\u0A03\u0A3C\u0A3E-\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A70\u0A71\u0A75\u0A81-\u0A83\u0ABC\u0ABE-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD\u0AE2\u0AE3\u0AFA-\u0AFF\u0B01-\u0B03\u0B3C\u0B3E-\u0B44\u0B47\u0B48\u0B4B-\u0B4D\u0B56\u0B57\u0B62\u0B63\u0B82\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD7\u0C00-\u0C04\u0C3E-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C62\u0C63\u0C81-\u0C83\u0CBC\u0CBE-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5\u0CD6\u0CE2\u0CE3\u0D00-\u0D03\u0D3B\u0D3C\u0D3E-\u0D44\u0D46-\u0D48\u0D4A-\u0D4D\u0D57\u0D62\u0D63\u0D82\u0D83\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DF2\u0DF3\u0E31\u0E34-\u0E3A\u0E47-\u0E4E\u0EB1\u0EB4-\u0EB9\u0EBB\u0EBC\u0EC8-\u0ECD\u0F18\u0F19\u0F35\u0F37\u0F39\u0F3E\u0F3F\u0F71-\u0F84\u0F86\u0F87\u0F8D-\u0F97\u0F99-\u0FBC\u0FC6\u102B-\u103E\u1056-\u1059\u105E-\u1060\u1062-\u1064\u1067-\u106D\u1071-\u1074\u1082-\u108D\u108F\u109A-\u109D\u135D-\u135F\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17B4-\u17D3\u17DD\u180B-\u180D\u1885\u1886\u18A9\u1920-\u192B\u1930-\u193B\u1A17-\u1A1B\u1A55-\u1A5E\u1A60-\u1A7C\u1A7F\u1AB0-\u1ABE\u1B00-\u1B04\u1B34-\u1B44\u1B6B-\u1B73\u1B80-\u1B82\u1BA1-\u1BAD\u1BE6-\u1BF3\u1C24-\u1C37\u1CD0-\u1CD2\u1CD4-\u1CE8\u1CED\u1CF2-\u1CF4\u1CF7-\u1CF9\u1DC0-\u1DF9\u1DFB-\u1DFF\u20D0-\u20F0\u2CEF-\u2CF1\u2D7F\u2DE0-\u2DFF\u302A-\u302F\u3099\u309A\uA66F-\uA672\uA674-\uA67D\uA69E\uA69F\uA6F0\uA6F1\uA802\uA806\uA80B\uA823-\uA827\uA880\uA881\uA8B4-\uA8C5\uA8E0-\uA8F1\uA8FF\uA926-\uA92D\uA947-\uA953\uA980-\uA983\uA9B3-\uA9C0\uA9E5\uAA29-\uAA36\uAA43\uAA4C\uAA4D\uAA7B-\uAA7D\uAAB0\uAAB2-\uAAB4\uAAB7\uAAB8\uAABE\uAABF\uAAC1\uAAEB-\uAAEF\uAAF5\uAAF6\uABE3-\uABEA\uABEC\uABED\uFB1E\uFE00-\uFE0F\uFE20-\uFE2F]/g,"").replace(Njo,e=>YGt[e]):t=>t;var v7e=class{constructor(t,{location:e=Ts.location,threshold:n=Ts.threshold,distance:o=Ts.distance,includeMatches:i=Ts.includeMatches,findAllMatches:r=Ts.findAllMatches,minMatchCharLength:s=Ts.minMatchCharLength,isCaseSensitive:a=Ts.isCaseSensitive,ignoreDiacritics:A=Ts.ignoreDiacritics,ignoreLocation:c=Ts.ignoreLocation}={}){if(this.options={location:e,threshold:n,distance:o,includeMatches:i,findAllMatches:r,minMatchCharLength:s,isCaseSensitive:a,ignoreDiacritics:A,ignoreLocation:c},t=a?t:t.toLowerCase(),t=A?JY(t):t,this.pattern=t,this.chunks=[],!this.pattern.length)return;const l=(u,h)=>{this.chunks.push({pattern:u,alphabet:Mjo(u),startIndex:h})},g=this.pattern.length;if(g>32){let u=0;const h=g%32,d=g-h;for(;u<d;)l(this.pattern.substr(u,32),u),u+=32;if(h){const _=g-32;l(this.pattern.substr(_),_)}}else l(this.pattern,0)}searchIn(t){const{isCaseSensitive:e,ignoreDiacritics:n,includeMatches:o}=this.options;if(t=e?t:t.toLowerCase(),t=n?JY(t):t,this.pattern===t){if(t.length<this.options.minMatchCharLength)return{isMatch:!1,score:1};const d={isMatch:!0,score:0};return o&&(d.indices=[[0,t.length-1]]),d}const{location:i,distance:r,threshold:s,findAllMatches:a,minMatchCharLength:A,ignoreLocation:c}=this.options,l=[];let g=0,u=!1;this.chunks.forEach(({pattern:d,alphabet:_,startIndex:m})=>{const{isMatch:p,score:I,indices:f}=wjo(t,d,_,{location:i+m,distance:r,threshold:s,findAllMatches:a,minMatchCharLength:A,includeMatches:o,ignoreLocation:c});p&&(u=!0),g+=I,p&&f&&l.push(...f)});const h={isMatch:u,score:u?g/this.chunks.length:1};return u&&o&&(h.indices=D7e(l)),h}};const Rjo=new Set(["fuzzy","include"]);function Tjo(t){return t.startsWith("inverse")}const P7e=[{type:"exact",multiRegex:/^="(.*)"$/,singleRegex:/^=(.*)$/,create:t=>({type:"exact",search(e){const n=e===t;return{isMatch:n,score:n?0:1,indices:[0,t.length-1]}}})},{type:"include",multiRegex:/^'"(.*)"$/,singleRegex:/^'(.*)$/,create:t=>({type:"include",search(e){let n=0,o;const i=[],r=t.length;for(;(o=e.indexOf(t,n))>-1;)n=o+r,i.push([o,n-1]);const s=!!i.length;return{isMatch:s,score:s?0:1,indices:i}}})},{type:"prefix-exact",multiRegex:/^\^"(.*)"$/,singleRegex:/^\^(.*)$/,create:t=>({type:"prefix-exact",search(e){const n=e.startsWith(t);return{isMatch:n,score:n?0:1,indices:[0,t.length-1]}}})},{type:"inverse-prefix-exact",multiRegex:/^!\^"(.*)"$/,singleRegex:/^!\^(.*)$/,create:t=>({type:"inverse-prefix-exact",search(e){const n=!e.startsWith(t);return{isMatch:n,score:n?0:1,indices:[0,e.length-1]}}})},{type:"inverse-suffix-exact",multiRegex:/^!"(.*)"\$$/,singleRegex:/^!(.*)\$$/,create:t=>({type:"inverse-suffix-exact",search(e){const n=!e.endsWith(t);return{isMatch:n,score:n?0:1,indices:[0,e.length-1]}}})},{type:"suffix-exact",multiRegex:/^"(.*)"\$$/,singleRegex:/^(.*)\$$/,create:t=>({type:"suffix-exact",search(e){const n=e.endsWith(t);return{isMatch:n,score:n?0:1,indices:[e.length-t.length,e.length-1]}}})},{type:"inverse-exact",multiRegex:/^!"(.*)"$/,singleRegex:/^!(.*)$/,create:t=>({type:"inverse-exact",search(e){const n=e.indexOf(t)===-1;return{isMatch:n,score:n?0:1,indices:[0,e.length-1]}}})},{type:"fuzzy",multiRegex:/^"(.*)"$/,singleRegex:/^(.*)$/,create:(t,e={})=>{const n=new v7e(t,{location:e.location??Ts.location,threshold:e.threshold??Ts.threshold,distance:e.distance??Ts.distance,includeMatches:e.includeMatches??Ts.includeMatches,findAllMatches:e.findAllMatches??Ts.findAllMatches,minMatchCharLength:e.minMatchCharLength??Ts.minMatchCharLength,isCaseSensitive:e.isCaseSensitive??Ts.isCaseSensitive,ignoreDiacritics:e.ignoreDiacritics??Ts.ignoreDiacritics,ignoreLocation:e.ignoreLocation??Ts.ignoreLocation});return{type:"fuzzy",search(o){return n.searchIn(o)}}}}],zGt=P7e.length,kjo="\0",Fjo="|";function Ljo(t){const e=[],n=t.length;let o=0;for(;o<n;){for(;o<n&&t[o]===" ";)o++;if(o>=n)break;let i=o;for(;i<n&&t[i]!==" "&&t[i]!=='"';)i++;if(i<n&&t[i]==='"'){for(i++;i<n;){if(t[i]==='"'){const r=i+1;if(r>=n||t[r]===" "){i++;break}if(t[r]==="$"&&(r+1>=n||t[r+1]===" ")){i+=2;break}}i++}e.push(t.substring(o,i)),o=i}else{for(;i<n&&t[i]!==" ";)i++;e.push(t.substring(o,i)),o=i}}return e}function VGt(t,e){const n=t.match(e);return n?n[1]:null}function Hjo(t,e={}){return t.replace(/\\\|/g,kjo).split(Fjo).map(n=>{const o=Ljo(n.replace(/\u0000/g,"|").trim()).filter(r=>r&&!!r.trim()),i=[];for(let r=0,s=o.length;r<s;r+=1){const a=o[r];let A=!1,c=-1;for(;!A&&++c<zGt;){const l=P7e[c],g=VGt(a,l.multiRegex);g&&(i.push(l.create(g,e)),A=!0)}if(!A)for(c=-1;++c<zGt;){const l=P7e[c],g=VGt(a,l.singleRegex);if(g){i.push(l.create(g,e));break}}}return i})}var Gjo=class{constructor(t,{isCaseSensitive:e=Ts.isCaseSensitive,ignoreDiacritics:n=Ts.ignoreDiacritics,includeMatches:o=Ts.includeMatches,minMatchCharLength:i=Ts.minMatchCharLength,ignoreLocation:r=Ts.ignoreLocation,findAllMatches:s=Ts.findAllMatches,location:a=Ts.location,threshold:A=Ts.threshold,distance:c=Ts.distance}={}){this.query=null,this.options={isCaseSensitive:e,ignoreDiacritics:n,includeMatches:o,minMatchCharLength:i,findAllMatches:s,ignoreLocation:r,location:a,threshold:A,distance:c},t=e?t:t.toLowerCase(),t=n?JY(t):t,this.pattern=t,this.query=Hjo(this.pattern,this.options)}static condition(t,e){return e.useExtendedSearch}searchIn(t){const e=this.query;if(!e)return{isMatch:!1,score:1};const{includeMatches:n,isCaseSensitive:o,ignoreDiacritics:i}=this.options;t=o?t:t.toLowerCase(),t=i?JY(t):t;let r=0;const s=[];let a=0,A=!1;for(let c=0,l=e.length;c<l;c+=1){const g=e[c];s.length=0,r=0,A=!1;for(let u=0,h=g.length;u<h;u+=1){const d=g[u],{isMatch:_,indices:m,score:p}=d.search(t);if(_)r+=1,a+=p,Tjo(d.type)&&(A=!0),n&&(Rjo.has(d.type)?s.push(...m):s.push(m));else{a=0,r=0,s.length=0,A=!1;break}}if(r){const u={isMatch:!0,score:a/r};return A&&(u.hasInverse=!0),n&&(u.indices=D7e(s)),u}}return{isMatch:!1,score:1}}};const w7e=[];function M7e(...t){w7e.push(...t)}function Bae(t,e){for(let n=0,o=w7e.length;n<o;n+=1){const i=w7e[n];if(i.condition(t,e))return new i(t,e)}return new v7e(t,e)}const Qae={AND:"$and",OR:"$or"},N7e={PATH:"$path",PATTERN:"$val"},R7e=t=>!!(t[Qae.AND]||t[Qae.OR]),Ojo=t=>!!t[N7e.PATH],Kjo=t=>!iw(t)&&LGt(t)&&!R7e(t),JGt=t=>({[Qae.AND]:Object.keys(t).map(e=>({[e]:t[e]}))});function qGt(t,e,{auto:n=!0}={}){const o=i=>{if(Wf(i)){const A={keyId:null,pattern:i};return n&&(A.searcher=Bae(i,e)),A}const r=Object.keys(i),s=Ojo(i);if(!s&&r.length>1&&!R7e(i))return o(JGt(i));if(Kjo(i)){const A=s?i[N7e.PATH]:r[0],c=s?i[N7e.PATTERN]:i[A];if(!Wf(c))throw new Error(Cjo(A));const l={keyId:xae(A),pattern:c};return n&&(l.searcher=Bae(c,e)),l}const a={children:[],operator:r[0]};return r.forEach(A=>{const c=i[A];iw(c)&&c.forEach(l=>{a.children.push(o(l))})}),a};return R7e(t)||(t=JGt(t)),o(t)}function T7e(t,{ignoreFieldNorm:e=Ts.ignoreFieldNorm}){let n=1;return t.forEach(({key:o,norm:i,score:r})=>{const s=o?o.weight:null;n*=Math.pow(r===0&&s?Number.EPSILON:r,(s||1)*(e?1:i))}),n}function Ujo(t,{ignoreFieldNorm:e=Ts.ignoreFieldNorm}){t.forEach(n=>{n.score=T7e(n.matches,{ignoreFieldNorm:e})})}var Yjo=class{constructor(t,e){this.limit=t,this.heap=[],this.comparator=e}get size(){return this.heap.length}insert(t){this.size<this.limit?(this.heap.push(t),this._bubbleUp(this.size-1)):this.comparator(t,this.heap[0])<0&&(this.heap[0]=t,this._sinkDown(0))}extractSorted(){return this.heap.sort(this.comparator)}_bubbleUp(t){const e=this.heap;for(;t>0;){const n=t-1>>1;if(this.comparator(e[t],e[n])<=0)break;const o=e[t];e[t]=e[n],e[n]=o,t=n}}_sinkDown(t){const e=this.heap,n=e.length;let o=t;do{t=o;const i=2*t+1,r=2*t+2;if(i<n&&this.comparator(e[i],e[o])>0&&(o=i),r<n&&this.comparator(e[r],e[o])>0&&(o=r),o!==t){const s=e[t];e[t]=e[o],e[o]=s}}while(o!==t)}};function zjo(t){const e=[];return t.matches.forEach(n=>{if(!AE(n.indices)||!n.indices.length)return;const o={indices:n.indices,value:n.value};n.key&&(o.key=n.key.id),n.idx>-1&&(o.refIndex=n.idx),e.push(o)}),e}function Vjo(t,e,{includeMatches:n=Ts.includeMatches,includeScore:o=Ts.includeScore}={}){return t.map(i=>{const{idx:r}=i,s={item:e[r],refIndex:r};return n&&(s.matches=zjo(i)),o&&(s.score=i.score),s})}const Jjo=/[\p{L}\p{M}\p{N}_]+/gu,WGt=new WeakSet;function qjo(t){WGt.has(t)||(WGt.add(t),console.warn(`[Fuse] tokenize regex ${t} lacks the global flag; only the first match per text will be returned. Add the 'g' flag.`))}function Wjo(t){if(typeof t=="function"){let e=!1;return n=>{const o=t(n);if(!e&&(e=!0,!Array.isArray(o)||o.some(i=>typeof i!="string")))throw new Error(`[Fuse] tokenize function must return string[]; received ${Array.isArray(o)?"array containing non-strings":typeof o}.`);return o}}return t instanceof RegExp?(t.global||qjo(t),e=>e.match(t)||[]):e=>e.match(Jjo)||[]}function k7e({isCaseSensitive:t=!1,ignoreDiacritics:e=!1,tokenize:n}={}){const o=Wjo(n);return{tokenize(i){return t||(i=i.toLowerCase()),e&&(i=JY(i)),o(i)}}}var jjo=class{static condition(t,e){return e.useTokenSearch}constructor(t,e){this.options=e,this.analyzer=k7e({isCaseSensitive:e.isCaseSensitive,ignoreDiacritics:e.ignoreDiacritics,tokenize:e.tokenize});const n=this.analyzer.tokenize(t),{df:o,fieldCount:i}=e._invertedIndex;this.termSearchers=[],this.idfWeights=[];for(const r of n){this.termSearchers.push(new v7e(r,{location:e.location,threshold:e.threshold,distance:e.distance,includeMatches:e.includeMatches,findAllMatches:e.findAllMatches,minMatchCharLength:e.minMatchCharLength,isCaseSensitive:e.isCaseSensitive,ignoreDiacritics:e.ignoreDiacritics,ignoreLocation:!0}));const s=o.get(r)||0,a=Math.log(1+(i-s+.5)/(s+.5));this.idfWeights.push(a)}this.combineAll=e.tokenMatch==="all",this.numTerms=this.termSearchers.length,this.useMask=this.numTerms<=31}searchIn(t){if(!this.termSearchers.length)return{isMatch:!1,score:1};const e=[];let n=0,o=0,i=0,r=0;const s=this.combineAll&&!this.useMask?new Set:null;for(let c=0;c<this.termSearchers.length;c++){const l=this.termSearchers[c].searchIn(t),g=this.idfWeights[c];o+=g,l.isMatch&&(i++,n+=g*(1-l.score),l.indices&&e.push(...l.indices),this.combineAll&&(this.useMask?r|=1<<c:s.add(c)))}if(i===0)return{isMatch:!1,score:1};const a=o>0?1-n/o:0,A={isMatch:!0,score:Math.max(.001,a)};return this.options.includeMatches&&e.length&&(A.indices=D7e(e)),this.combineAll&&(this.useMask?A.matchedMask=r:A.matchedTerms=s,A.termCount=this.numTerms),A}};function F7e(t,e,n,o){const i=o.tokenize(e);if(!i.length)return;t.fieldCount++,t.docFieldCount.set(n,(t.docFieldCount.get(n)||0)+1);const r=new Set(i);let s=t.docTermFieldHits.get(n);s||(s=new Map,t.docTermFieldHits.set(n,s));for(const a of r)s.set(a,(s.get(a)||0)+1),t.df.set(a,(t.df.get(a)||0)+1)}function jGt(t,e,n,o){const{i,v:r,$:s}=e;if(r!==void 0){F7e(t,r,i,o);return}if(s)for(let a=0;a<n;a++){const A=s[a];if(A)if(Array.isArray(A))for(const c of A)F7e(t,c.v,i,o);else F7e(t,A.v,i,o)}}function Xjo(t,e,n){const o={fieldCount:0,df:new Map,docFieldCount:new Map,docTermFieldHits:new Map};for(const i of t)jGt(o,i,e,n);return o}function $jo(t,e,n,o){jGt(t,e,n,o)}function Zjo(t,e){const n=t.docFieldCount.get(e);if(n===void 0)return;t.fieldCount-=n,t.docFieldCount.delete(e);const o=t.docTermFieldHits.get(e);if(o){for(const[i,r]of o){const s=(t.df.get(i)||0)-r;s<=0?t.df.delete(i):t.df.set(i,s)}t.docTermFieldHits.delete(e)}}function XGt(t,e){if(e.length===0)return;const n=Array.from(new Set(e)).sort((a,A)=>a-A);for(const a of n)Zjo(t,a);const o=a=>{let A=0,c=n.length;for(;A<c;){const l=A+c>>>1;n[l]<a?A=l+1:c=l}return a-A},i=n[0],r=new Map;for(const[a,A]of t.docFieldCount)r.set(a>i?o(a):a,A);t.docFieldCount=r;const s=new Map;for(const[a,A]of t.docTermFieldHits)s.set(a>i?o(a):a,A);t.docTermFieldHits=s}var rw=class{constructor(t,e,n){this.options={...Ts,...e},this.options.useExtendedSearch,this.options.useTokenSearch,this._keyStore=new Qjo(this.options.keys),this._docs=t,this._myIndex=null,this._invertedIndex=null,this.setCollection(t,n),this._lastQuery=null,this._lastSearcher=null}_getSearcher(t){if(this._lastQuery===t)return this._lastSearcher;const e=Bae(t,this._invertedIndex?{...this.options,_invertedIndex:this._invertedIndex}:this.options);return this._lastQuery=t,this._lastSearcher=e,e}setCollection(t,e){if(this._docs=t,e&&!(e instanceof b7e))throw new Error(fjo);if(this._myIndex=e||UGt(this.options.keys,this._docs,{getFn:this.options.getFn,fieldNormWeight:this.options.fieldNormWeight}),this.options.useTokenSearch){const n=k7e({isCaseSensitive:this.options.isCaseSensitive,ignoreDiacritics:this.options.ignoreDiacritics,tokenize:this.options.tokenize});this._invertedIndex=Xjo(this._myIndex.records,this._myIndex.keys.length,n)}this._invalidateSearcherCache()}add(t){if(!AE(t))return;this._docs.push(t);const e=this._myIndex.add(t,this._docs.length-1);if(this._invertedIndex&&e){const n=k7e({isCaseSensitive:this.options.isCaseSensitive,ignoreDiacritics:this.options.ignoreDiacritics,tokenize:this.options.tokenize});$jo(this._invertedIndex,e,this._myIndex.keys.length,n)}this._invalidateSearcherCache()}remove(t=()=>!1){const e=[],n=[];for(let o=0,i=this._docs.length;o<i;o+=1)t(this._docs[o],o)&&(e.push(this._docs[o]),n.push(o));if(n.length){this._invertedIndex&&XGt(this._invertedIndex,n);const o=new Set(n);this._docs=this._docs.filter((i,r)=>!o.has(r)),this._myIndex.removeAll(n),this._invalidateSearcherCache()}return e}removeAt(t){if(!Number.isInteger(t)||t<0||t>=this._docs.length)throw new Error(S7e);this._invertedIndex&&XGt(this._invertedIndex,[t]);const e=this._docs.splice(t,1)[0];return this._myIndex.removeAt(t),this._invalidateSearcherCache(),e}_invalidateSearcherCache(){this._lastQuery=null,this._lastSearcher=null}getIndex(){return this._myIndex}_normalizedKeys(){return this._myIndex.keys.map(t=>this._keyStore.get(t.id)||t)}search(t,e){const{limit:n=-1}=e||{},{includeMatches:o,includeScore:i,shouldSort:r,sortFn:s,ignoreFieldNorm:a}=this.options;if(Wf(t)&&!t.trim()){let u=this._docs.map((h,d)=>({item:h,refIndex:d}));return yae(n)&&n>-1&&(u=u.slice(0,n)),u}const A=r&&yae(n)&&n>0&&Wf(t),c=s,l=(u,h)=>c(u,h)||u.idx-h.idx;let g;if(A){const u=new Yjo(n,l);Wf(this._docs[0])?this._searchStringList(t,{heap:u,ignoreFieldNorm:a}):this._searchObjectList(t,{heap:u,ignoreFieldNorm:a}),g=u.extractSorted()}else g=Wf(t)?Wf(this._docs[0])?this._searchStringList(t):this._searchObjectList(t):this._searchLogical(t),Ujo(g,{ignoreFieldNorm:a}),r&&g.sort(Wf(t)?l:c),yae(n)&&n>-1&&(g=g.slice(0,n));return Vjo(g,this._docs,{includeMatches:o,includeScore:i})}_searchStringList(t,{heap:e,ignoreFieldNorm:n}={}){const o=this._getSearcher(t),i=this.options.useTokenSearch&&this.options.tokenMatch==="all",{records:r}=this._myIndex,s=e?null:[];return r.forEach(({v:a,i:A,n:c})=>{if(!AE(a))return;const l=o.searchIn(a);if(l.isMatch){const g={score:l.score,value:a,norm:c,indices:l.indices};i&&(g.matchedMask=l.matchedMask,g.matchedTerms=l.matchedTerms,g.termCount=l.termCount);const u=[g];if(!i||this._coversAllTokens(u)){const h={item:a,idx:A,matches:u};e?(h.score=T7e(h.matches,{ignoreFieldNorm:n}),e.insert(h)):s.push(h)}}}),s}_searchLogical(t){const e=qGt(t,this.options),n=this._normalizedKeys(),o=(a,A,c)=>{if(!("children"in a)){const{keyId:h,searcher:d}=a;let _;return h===null?(_=[],n.forEach((m,p)=>{_.push(...this._findMatches({key:m,value:A[p],searcher:d}))})):_=this._findMatches({key:this._keyStore.get(h),value:this._myIndex.getValueForItemAtKeyId(A,h),searcher:d}),_&&_.length?[{idx:c,item:A,matches:_}]:[]}const{children:l,operator:g}=a,u=[];for(let h=0,d=l.length;h<d;h+=1){const _=l[h],m=o(_,A,c);if(m.length)u.push(...m);else if(g===Qae.AND)return[]}return u},i=this._myIndex.records,r=new Map,s=[];return i.forEach(({$:a,i:A})=>{if(AE(a)){const c=o(e,a,A);c.length&&(r.has(A)||(r.set(A,{idx:A,item:a,matches:[]}),s.push(r.get(A))),c.forEach(({matches:l})=>{r.get(A).matches.push(...l)}))}}),s}_searchObjectList(t,{heap:e,ignoreFieldNorm:n}={}){const o=this._getSearcher(t),i=this.options.useTokenSearch&&this.options.tokenMatch==="all",{records:r}=this._myIndex,s=this._normalizedKeys(),a=e?null:[];return r.forEach(({$:A,i:c})=>{if(!AE(A))return;const l=[];let g=!1,u=!1;if(s.forEach((h,d)=>{const _=this._findMatches({key:h,value:A[d],searcher:o});_.length?(l.push(..._),_[0].hasInverse&&(u=!0)):g=!0}),!(u&&g)&&l.length&&(!i||this._coversAllTokens(l))){const h={idx:c,item:A,matches:l};e?(h.score=T7e(h.matches,{ignoreFieldNorm:n}),e.insert(h)):a.push(h)}}),a}_findMatches({key:t,value:e,searcher:n}){if(!AE(e))return[];const o=[];if(iw(e))e.forEach(({v:i,i:r,n:s})=>{if(!AE(i))return;const a=n.searchIn(i);if(a.isMatch){const A={score:a.score,key:t,value:i,idx:r,norm:s,indices:a.indices,hasInverse:a.hasInverse};a.termCount!==void 0&&(A.matchedMask=a.matchedMask,A.matchedTerms=a.matchedTerms,A.termCount=a.termCount),o.push(A)}});else{const{v:i,n:r}=e,s=n.searchIn(i);if(s.isMatch){const a={score:s.score,key:t,value:i,norm:r,indices:s.indices,hasInverse:s.hasInverse};s.termCount!==void 0&&(a.matchedMask=s.matchedMask,a.matchedTerms=s.matchedTerms,a.termCount=s.termCount),o.push(a)}}return o}_coversAllTokens(t){const e=t.length?t[0].termCount:void 0;if(e===void 0)return!0;if(e<=31){let o=0;for(let i=0;i<t.length;i++)o|=t[i].matchedMask||0;return o===2**e-1}const n=new Set;for(let o=0;o<t.length;o++){const i=t[o].matchedTerms;if(i)for(const r of i)n.add(r)}return n.size===e}};rw.version="7.5.0",rw.createIndex=UGt,rw.parseIndex=vjo,rw.config=Ts,rw.match=function(t,e,n){if(n&&n.useTokenSearch)throw new Error(Bjo);return Bae(t,{...Ts,...n}).searchIn(e)},rw.parseQuery=qGt,M7e(Gjo),M7e(jjo),rw.use=function(...t){t.forEach(e=>M7e(e))};var eXo=rw;const tXo="https://kicad-mod-cache.tscircuit.com";let L7e=null,qY=null,H7e=null;const nXo=async()=>L7e||qY||(qY=fetch("https://kicad-mod-cache.tscircuit.com/kicad_files.json").then(t=>t.json()).then(t=>(L7e=t,qY=null,t)),qY),oXo=async(t,e=20)=>{const n=await nXo();return H7e||(H7e=new eXo(n)),H7e.search(t).slice(0,e).map(o=>o.item)},iXo=t=>{const e=t.replace(".pretty/","/").replace(".kicad_mod",""),n=`kicad:${e}`;return{path:t,qualifiedName:n,description:e}},rXo=t=>t.replace(/^\/+/,"").split("/").map(e=>encodeURIComponent(e)).join("/"),sXo=async t=>{const e=await fetch(`${tXo}/${rXo(t)}`);if(!e.ok)throw new Error(`KiCad footprint fetch failed: ${e.status}`);const n=await e.text(),{KicadFootprintToCircuitJsonConverter:o}=await oE("kicad-to-circuit-json"),i=new o;return i.addFile(t.split("/").pop()??"selected-footprint.kicad_mod",n),i.runUntilFinished(),i.getOutput()},$Gt=t=>t?.source==="jlcpcb"||t?.source==="kicad",aXo=async(t,e)=>{if(t.source==="jlcpcb")return _jo(t.component.partNumber,e?.jlcpcb);if(t.source==="kicad")return sXo(t.footprint.path);throw new Error("Footprint preview is not available for this source")},AXo=({query:t,placeholder:e,isSearching:n,onQueryChange:o,onSubmit:i})=>{const r=X.useCallback(s=>{s.key==="Enter"&&(s.preventDefault(),i())},[i]);return z.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2 rf-mt-4",children:[z.jsxs("div",{className:"rf-relative rf-flex-grow",children:[z.jsx(t8e,{className:"rf-absolute rf-left-2 rf-top-2.5 rf-h-4 rf-w-4 rf-text-muted-foreground"}),z.jsx(z8e,{placeholder:e,className:"rf-pl-8",spellCheck:!1,autoComplete:"off",value:t,onChange:s=>o(s.target.value),onKeyDown:r})]}),z.jsx(fa,{onClick:i,disabled:n||t.trim().length<1,className:"sm:rf-px-4 rf-px-3",children:n?z.jsx(Rx,{className:"rf-h-4 rf-w-4 rf-animate-spin"}):z.jsxs(z.Fragment,{children:[z.jsx(t8e,{className:"rf-h-4 rf-w-4 sm:rf-hidden"}),z.jsx("span",{className:"rf-hidden sm:rf-inline",children:"Search"})]})})]})},cXo=new Intl.NumberFormat("en-US",{style:"currency",currency:"USD"}),lXo=t=>cXo.format(t),ZGt=t=>{switch(t.source){case"tscircuit.com":{const e=t.package;return`tscircuit-${e.package_id??`${e.org_owner_tscircuit_handle??"unknown"}-${e.unscoped_name??e.name??"package"}`}`}case"jlcpcb":return`jlc-${t.component.lcscId}`;case"kicad":return`kicad-${t.footprint.path}`;default:return"unknown"}},gXo=t=>{switch(t.source){case"tscircuit.com":return t.package.unscoped_name;case"jlcpcb":return t.component.isDirectLookup?t.component.partNumber:t.component.manufacturer;case"kicad":return t.footprint.qualifiedName}},uXo=t=>{switch(t.source){case"tscircuit.com":return t.package.description||(t.package.org_owner_tscircuit_handle?`Component by ${t.package.org_owner_tscircuit_handle}`:void 0);case"jlcpcb":return t.component.description;case"kicad":return t.footprint.description}},dXo=t=>{switch(t.source){case"tscircuit.com":return t.package.name;case"jlcpcb":return t.component.isDirectLookup?void 0:t.component.partNumber;case"kicad":return}},hXo=({results:t,selected:e,onSelect:n,onShowDetails:o})=>{const i=e?ZGt(e):null;return z.jsx("div",{className:"rf-divide-y rf-w-full rf-overflow-hidden",children:t.map(r=>{const s=ZGt(r),a=i===s,A=gXo(r),c=uXo(r),l=dXo(r),g=r.source==="jlcpcb"?r.component.stock:null,u=r.source==="jlcpcb"?r.component.price:null,h=r.source==="jlcpcb"?r.component.isBasic:null,d=r.source==="jlcpcb"?r.component.isDirectLookup:!1;return z.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:()=>n(r),children:[z.jsxs("div",{className:"rf-min-w-0 rf-overflow-hidden rf-w-full",children:[z.jsxs("div",{className:"rf-flex rf-items-start rf-gap-2 rf-min-w-0",children:[z.jsxs("div",{className:"rf-font-medium rf-text-sm rf-truncate rf-flex-1 rf-min-w-0 rf-flex rf-items-center rf-gap-1.5",children:[A,r.source==="jlcpcb"&&h!=null&&z.jsx("span",{className:`rf-text-xs rf-px-1.5 rf-py-0.5 rf-rounded rf-font-medium rf-flex-shrink-0 ${h?"rf-bg-green-100 rf-text-green-700":"rf-bg-orange-100 rf-text-orange-700"}`,children:h?"Basic":"Extended"}),d&&z.jsx("span",{className:"rf-text-xs rf-px-1.5 rf-py-0.5 rf-rounded rf-font-medium rf-flex-shrink-0 rf-bg-blue-100 rf-text-blue-700",children:"Direct lookup"}),r.source==="tscircuit.com"&&r.package.is_private&&z.jsx(oLo,{className:"rf-ml-1 rf-h-3 rf-w-3 rf-text-zinc-400 rf-flex-shrink-0"})]}),r.source==="jlcpcb"&&g!=null?z.jsxs("div",{className:"rf-text-xs rf-text-zinc-500 rf-font-medium rf-whitespace-nowrap rf-flex-shrink-0 sm:rf-hidden",children:[g.toLocaleString()," in stock"]}):null]}),z.jsxs("div",{className:"rf-text-xs rf-text-zinc-500 rf-truncate rf-w-full",children:[l?z.jsx("span",{className:"rf-mr-2",children:l}):null,c]})]}),z.jsxs("div",{children:[r.source==="tscircuit.com"&&o?z.jsx("div",{className:"rf-flex-shrink-0 rf-w-full sm:rf-w-auto",children:z.jsx(fa,{variant:"outline",size:"sm",className:"rf-text-xs rf-w-full sm:rf-w-auto",onClick:_=>{_.stopPropagation(),o(r)},children:"See Details"})}):r.source==="jlcpcb"&&g!=null?z.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:[g.toLocaleString()," in stock"]}):null,u!=null&&z.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:lXo(u)})]})]},s)})})},_Xo=({circuitJson:t,error:e,isLoading:n,height:o})=>z.jsx("section",{className:"rf-flex rf-min-w-0 rf-items-center rf-justify-center",style:{height:o},children:n?z.jsxs("div",{className:"rf-flex rf-w-full rf-items-center rf-justify-center rf-gap-2 rf-bg-zinc-950 rf-text-sm rf-text-zinc-300",style:{height:o},children:[z.jsx(Rx,{className:"rf-h-4 rf-w-4 rf-animate-spin"}),"Loading preview..."]}):e?z.jsx("div",{className:"rf-flex rf-w-full rf-items-center rf-justify-center rf-bg-zinc-950 rf-p-4",style:{height:o},children:z.jsxs("div",{className:"rf-flex rf-max-w-[320px] rf-items-start rf-gap-2 rf-text-sm rf-text-zinc-300",children:[z.jsx(uNt,{className:"rf-mt-0.5 rf-h-4 rf-w-4 rf-flex-shrink-0"}),z.jsx("span",{children:e})]})}):t?z.jsx("div",{className:"rf-w-full rf-min-w-0 rf-overflow-hidden",children:z.jsx(aGt,{circuitJson:t,height:o,allowEditing:!1,clickToInteractEnabled:!1,focusOnHover:!1,disablePcbGroups:!0})}):z.jsx("div",{className:"rf-flex rf-w-full rf-items-center rf-justify-center rf-bg-zinc-950 rf-text-sm rf-text-zinc-300",style:{height:o},children:"No preview"})}),eOt={importComponentDialog:101,importComponentDetailsDialog:102},mXo=({packageResult:t,isOpen:e,onOpenChange:n,isLoading:o,details:i,previewTab:r,onPreviewTabChange:s,isSubmitting:a,onImport:A})=>{const c=t?.package??null,l=c?.latest_pcb_preview_image_url,g=c?.latest_sch_preview_image_url,u=c?.latest_cad_preview_image_url,h=c?.unscoped_name?.split("/").pop()??c?.unscoped_name,d=c?.org_owner_tscircuit_handle??void 0,_=d?`https://tscircuit.com/${d}`:void 0,m=d&&h?`https://tscircuit.com/${d}/${h}`:void 0;return z.jsx(X6,{open:e,onOpenChange:n,children:z.jsxs(tw,{showOverlay:!1,style:{width:"calc(100vw - 2rem)",zIndex:eOt.importComponentDetailsDialog},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:[z.jsx(nw,{className:"rf-pb-4 rf-border-b",children:z.jsx("div",{className:"rf-flex rf-items-start rf-justify-between rf-gap-4",children:z.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[z.jsx(ow,{className:"rf-text-xl rf-font-semibold rf-truncate",children:h}),z.jsx($6,{children:c?.description})]})})}),z.jsxs("div",{className:"rf-flex-1 rf-overflow-y-auto rf-py-4 rf-space-y-6",children:[d?z.jsxs("div",{children:[z.jsx("span",{className:"rf-text-xs rf-font-medium rf-text-gray-500 rf-uppercase rf-tracking-wide",children:"Created by"}),z.jsx("div",{className:"rf-mt-1 rf-text-sm rf-font-medium",children:_?z.jsx("a",{href:_,target:"_blank",rel:"noopener noreferrer",className:"rf-text-black hover:rf-underline",children:d}):d})]}):null,(u||l||g)&&z.jsx(z.Fragment,{children:z.jsxs("div",{children:[z.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-mb-4",children:"Preview"}),z.jsxs(Nxe,{value:r,onValueChange:p=>s(p),children:[z.jsxs(Tne,{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:[l&&z.jsx(HS,{value:"pcb",children:"PCB"}),g&&z.jsx(HS,{value:"schematic",children:"Schematic"}),u&&z.jsx(HS,{value:"3d",children:"3D"})]}),z.jsxs("div",{className:"rf-mt-4",children:[z.jsx(Kf,{value:"pcb",className:"rf-border rf-rounded-lg rf-overflow-hidden rf-bg-gray-50",children:l?z.jsx("img",{src:l,alt:`${h??"package"} PCB preview`,className:"rf-w-full rf-h-full rf-object-contain rf-bg-white rf-p-4"}):null}),z.jsx(Kf,{value:"schematic",className:"rf-border rf-rounded-lg rf-overflow-hidden rf-bg-gray-50",children:g?z.jsx("img",{src:g,alt:`${h??"package"} schematic preview`,className:"rf-w-full rf-h-full rf-object-contain rf-bg-white rf-p-4"}):null}),z.jsx(Kf,{value:"3d",className:"rf-border rf-rounded-lg rf-overflow-hidden rf-bg-gray-50",children:u?z.jsx("img",{src:u,alt:`${h??"package"} 3D preview`,className:"rf-w-full rf-h-full rf-object-contain rf-bg-white rf-p-4"}):null})]})]})]})}),i?.ai_description?z.jsxs("section",{children:[z.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-mb-3",children:"AI Description"}),z.jsx("div",{className:"rf-bg-gray-50 rf-border rf-border-gray-200 rf-rounded-lg rf-p-4",children:z.jsx("p",{className:"rf-text-sm rf-text-gray-700 rf-leading-relaxed",children:i.ai_description})})]}):null,i?.ai_usage_instructions?z.jsxs("section",{children:[z.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-mb-3",children:"Usage Instructions"}),z.jsx("div",{className:"rf-bg-gray-50 rf-border rf-border-gray-200 rf-rounded-lg rf-p-4",children:z.jsx("p",{className:"rf-text-sm rf-text-gray-700 rf-leading-relaxed rf-whitespace-pre-wrap",children:i.ai_usage_instructions})})]}):null,o?z.jsxs("div",{className:"rf-flex rf-justify-center rf-items-center rf-gap-2 rf-text-gray-500",children:[z.jsx(Rx,{className:"rf-h-4 rf-w-4 rf-animate-spin"}),z.jsx("span",{className:"rf-text-sm",children:"Loading package details..."})]}):null]}),z.jsxs(Kk,{className:"rf-pt-4 rf-border-t rf-flex rf-flex-col sm:rf-flex-row rf-justify-between rf-gap-2",children:[z.jsx("div",{className:"rf-flex-1",children:m?z.jsxs(fa,{variant:"outline",size:"sm",className:"rf-gap-2 rf-w-full sm:rf-w-auto",onClick:()=>window.open(m,"_blank"),children:[z.jsx(jFo,{className:"rf-h-4 rf-w-4"}),"View on tscircuit.com"]}):null}),z.jsxs("div",{className:"rf-flex rf-flex-col sm:rf-flex-row rf-gap-2",children:[z.jsx(fa,{variant:"outline",onClick:()=>n(!1),className:"rf-order-2 sm:rf-order-1",children:"Close"}),z.jsx(fa,{onClick:A,disabled:a,className:"rf-bg-blue-600 hover:rf-bg-blue-700",children:a?z.jsx(Rx,{className:"rf-h-4 rf-w-4 rf-animate-spin"}):"Import Component"})]})]})]})})},pXo=()=>{const[t,e]=X.useState(null),[n,o]=X.useState(!1),i=X.useCallback(async(s,a)=>{o(!0);try{const A=await fetch(`https://api.tscircuit.com/packages/get?name=${encodeURIComponent(`${s}/${a}`)}`);if(!A.ok)throw new Error(`Failed to load package details: ${A.status}`);const c=await A.json();e(c.package??null)}catch(A){console.error("Failed to fetch package details",A),e(null)}finally{o(!1)}},[]),r=X.useCallback(()=>{e(null),o(!1)},[]);return{details:t,isLoading:n,fetchDetails:i,reset:r}},IXo=(t,e)=>{const[n,o]=X.useState({circuitJson:null,error:null,isLoading:!1});return X.useEffect(()=>{if(!t||!$Gt(t)){o({circuitJson:null,error:null,isLoading:!1});return}let i=!1;return o({circuitJson:null,error:null,isLoading:!0}),aXo(t,e).then(r=>{i||o({circuitJson:r,error:null,isLoading:!1})}).catch(r=>{i||o({circuitJson:null,error:r instanceof Error?r.message:"Failed to load footprint preview",isLoading:!1})}),()=>{i=!0}},[t,e]),n},fXo=async(t,e)=>{const n={"Content-Type":"application/json"};e&&(n.Authorization=`Bearer ${e}`);const o=await fetch("https://registry-api.tscircuit.com/packages/search",{method:"POST",headers:n,body:JSON.stringify({query:t})});if(!o.ok)throw new Error(`tscircuit registry error: ${o.status}`);return(await o.json()).packages??[]},CXo=({sessionToken:t})=>{const[e,n]=X.useState([]),[o,i]=X.useState(!1),[r,s]=X.useState(null),[a,A]=X.useState(!1),c=X.useCallback(async g=>{const u=g.trim();if(!u)return[];i(!0),s(null);try{const d=(await fXo(u,t)).map(_=>({source:"tscircuit.com",package:_}));return n(d),d}catch(h){return console.error("Error searching tscircuit packages",h),n([]),s(h instanceof Error?h.message:"Failed to search tscircuit packages"),[]}finally{i(!1),A(!0)}},[t]),l=X.useCallback(()=>{n([]),i(!1),s(null),A(!1)},[]);return{results:e,isSearching:o,error:r,hasSearched:a,search:c,reset:l}},yXo=t=>{const e=/^C(\d+)$/i.exec(t.trim());if(!e)return null;const n=Number(e[1]);if(!Number.isSafeInteger(n))return null;const o=`C${e[1]}`;return{source:"jlcpcb",component:{lcscId:n,manufacturer:o,partNumber:o,description:"Import directly from EasyEDA; stock and availability are unknown",package:"",isDirectLookup:!0}}},tOt=(t,e)=>{const n=yXo(t);return n?e.some(i=>i.component.partNumber.toUpperCase()===n.component.partNumber)?e:[n,...e]:e},EXo=t=>{const e=t.trim();return/^C\d+/i.test(e)?e.replace(/^C/i,""):e},xXo=()=>{const[t,e]=X.useState([]),[n,o]=X.useState(!1),[i,r]=X.useState(null),[s,a]=X.useState(!1),A=X.useCallback(async l=>{const g=EXo(l);if(!g)return[];o(!0),r(null);try{const u=await ujo(g,10),h=tOt(l,u.map(d=>({source:"jlcpcb",component:djo(d)})));return e(h),h}catch(u){console.error("Error searching JLCPCB components",u);const h=tOt(l,[]);return e(h),r(h.length>0?null:u instanceof Error?u.message:"Failed to search JLCPCB components"),h}finally{o(!1),a(!0)}},[]),c=X.useCallback(()=>{e([]),o(!1),r(null),a(!1)},[]);return{results:t,isSearching:n,error:i,hasSearched:s,search:A,reset:c}},BXo=()=>{const[t,e]=X.useState([]),[n,o]=X.useState(!1),[i,r]=X.useState(null),[s,a]=X.useState(!1),A=X.useCallback(async l=>{const g=l.trim();if(!g)return[];o(!0),r(null);try{const h=(await oXo(g,20)).map(d=>({source:"kicad",footprint:iXo(d)}));return e(h),h}catch(u){return console.error("Error searching KiCad footprints",u),e([]),r(u instanceof Error?u.message:"Failed to search KiCad footprints"),[]}finally{o(!1),a(!0)}},[]),c=X.useCallback(()=>{e([]),o(!1),r(null),a(!1)},[]);return{results:t,isSearching:n,error:i,hasSearched:s,search:A,reset:c}},QXo=({onTscircuitPackageSelected:t,onJlcpcbComponentTsxLoaded:e,onKicadStringSelected:n})=>{const o=[];return t&&o.push("tscircuit.com"),e&&o.push("jlcpcb"),n&&o.push("kicad"),o},SXo=({isOpen:t,onClose:e,jlcpcbProxyRequestHeaders:n,onKicadStringSelected:o,onTscircuitPackageSelected:i,onJlcpcbComponentTsxLoaded:r,jlcpcbProxyApiBase:s,tscircuitSessionToken:a})=>{UY();const A=X.useMemo(()=>QXo({onKicadStringSelected:o,onTscircuitPackageSelected:i,onJlcpcbComponentTsxLoaded:r}),[o,i,r]),c=A.length>0,l=A.length===1,[g,u]=X.useState(A[0]??"tscircuit.com"),[h,d]=X.useState(""),[_,m]=X.useState(null),{results:p,isSearching:I,error:f,hasSearched:C,search:y,reset:E}=CXo({sessionToken:a}),{results:B,isSearching:Q,error:b,hasSearched:D,search:R,reset:M}=xXo(),{results:L,isSearching:G,error:O,hasSearched:U,search:W,reset:j}=BXo(),{details:te,isLoading:ie,fetchDetails:$,reset:Z}=pXo(),[se,ae]=X.useState(null),[ce,fe]=X.useState(!1),[Ce,xe]=X.useState("pcb"),[de,Ee]=X.useState(null),[he,be]=X.useState(!1),Me=X.useMemo(()=>({jlcpcb:{headers:n,apiBase:s}}),[s,n]),{circuitJson:Ye,error:Ie,isLoading:We}=IXo(_,Me),Ne=$Gt(_);X.useEffect(()=>{Ee(null)},[_]);const ke=X.useCallback(()=>{E(),M(),j(),m(null)},[M,j,E]);X.useEffect(()=>{t||(ke(),d(""),fe(!1),ae(null),Ee(null))},[t,ke]),X.useEffect(()=>{d(""),m(null),g==="tscircuit.com"?E():g==="jlcpcb"?M():g==="kicad"&&j()},[g,M,j,E]);const Ve=gt=>{m(gt),ae(gt),xe("pcb"),fe(!0),Z();const nt=gt.package.org_owner_tscircuit_handle,xt=gt.package.unscoped_name;if(nt&&xt){const _t=xt.split("/").pop()??xt;$(nt,_t)}},Re=async()=>{h.trim()&&(m(null),g==="tscircuit.com"?await y(h):g==="jlcpcb"?await R(h):g==="kicad"&&await W(h))},Se=async gt=>{try{if(Ee(null),be(!0),gt.source==="kicad"){if(!o)throw new Error("KiCad handler not provided");await o({result:gt,footprint:gt.footprint.qualifiedName})}else if(gt.source==="jlcpcb"){if(!r)throw new Error("JLCPCB handler not provided");const nt=await hjo(gt.component.partNumber,{headers:n,apiBase:s});await r({result:gt,tsx:nt})}else if(gt.source==="tscircuit.com"){if(!i)throw new Error("tscircuit package handler not provided");const nt=gt.package.org_owner_tscircuit_handle,xt=gt.package.unscoped_name;if(!nt||!xt)throw new Error("Missing package metadata");const _t=xt.split("/").pop()??xt,vt=`@tsci/${nt}.${_t}`;await i({result:gt,fullPackageName:vt})}return!0}catch(nt){return console.error("Failed to import component",nt),Ee(nt instanceof Error?nt.message:"Failed to import component"),!1}finally{be(!1)}};let Oe=[],Pe=!1,qe=null,$e=!1;g==="tscircuit.com"?(Oe=p,Pe=I,qe=f,$e=C):g==="jlcpcb"?(Oe=B,Pe=Q,qe=b,$e=D):g==="kicad"&&(Oe=L,Pe=G,qe=O,$e=U);const at=async()=>{if(!_)return;await Se(_)&&(e(),ke(),d(""))},ct=gt=>{gt||e()},dt=gt=>{fe(gt),gt||ae(null)};return z.jsxs(X6,{open:t,onOpenChange:ct,children:[z.jsxs(tw,{style:{width:"calc(100vw - 2rem)",maxWidth:Ne?"min(1120px, calc(100vw - 2rem))":"min(672px, calc(100vw - 2rem))",zIndex:eOt.importComponentDialog},className:"rf-rounded-sm rf-max-h-[90vh] rf-overflow-y-auto rf-overflow-x-hidden rf-flex rf-flex-col",children:[z.jsxs(nw,{children:[z.jsxs(ow,{className:"rf-text-lg sm:rf-text-xl",children:["Import ",l?Cae[g].label:""," ","Component"]}),z.jsx($6,{className:"rf-text-sm",children:c?"Search for components from available sources.":"Import options are disabled because no handlers were provided."})]}),c?z.jsxs(Nxe,{value:g,onValueChange:gt=>u(gt),className:"rf-min-w-0 rf-w-full",children:[!l&&z.jsx(Tne,{className:"rf-flex rf-w-full rf-gap-2",children:A.map(gt=>z.jsx(HS,{value:gt,className:"rf-flex-1 rf-text-xs sm:rf-text-sm",children:Cae[gt].label},gt))}),z.jsxs("div",{className:"rf-min-w-0",style:Ne?{display:"grid",gridTemplateColumns:"minmax(0, 1fr) minmax(360px, 0.95fr)",gap:"1.5rem",alignItems:"start"}:void 0,children:[z.jsxs("div",{className:"rf-min-w-0",children:[z.jsx(AXo,{query:h,placeholder:Cae[g].placeholder,isSearching:Pe,onQueryChange:d,onSubmit:Re}),z.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:Pe?z.jsxs("div",{className:"rf-p-8 rf-text-center rf-text-zinc-500",children:[z.jsx(Rx,{className:"rf-h-8 rf-w-8 rf-animate-spin rf-mx-auto rf-mb-2"}),z.jsx("p",{children:"Searching..."})]}):Oe.length>0?z.jsx(hXo,{results:Oe,selected:_,onSelect:m,onShowDetails:g==="tscircuit.com"?Ve:void 0}):z.jsx("div",{className:"rf-p-8 rf-text-center rf-text-zinc-500",children:qe?`Error: ${qe}`:$e?Cae[g].emptyMessage:"Enter a search term to find components"})})]}),Ne?z.jsx("div",{className:"rf-mt-4",children:z.jsx(_Xo,{circuitJson:Ye,error:Ie,isLoading:We,height:325})}):null]})]}):null,de?z.jsx("div",{className:"rf-text-sm rf-text-red-600 rf-mt-2",children:de}):null,z.jsxs(Kk,{className:"rf-flex rf-flex-col sm:rf-flex-row rf-gap-2",children:[z.jsx(fa,{variant:"outline",onClick:e,className:"rf-order-2 sm:rf-order-1",children:"Cancel"}),z.jsx(fa,{onClick:at,disabled:!_||he,className:"rf-order-1 sm:rf-order-2",children:he?z.jsx(Rx,{className:"rf-h-4 rf-w-4 rf-animate-spin"}):"Import"})]})]}),z.jsx(mXo,{packageResult:se,isOpen:ce,onOpenChange:dt,isLoading:ie,details:te,previewTab:Ce,onPreviewTabChange:gt=>xe(gt),isSubmitting:he,onImport:()=>{se&&Se(se).then(gt=>{gt&&(fe(!1),e(),ke(),d(""))})}})]})},bXo=t=>{const e=t.match(/export const (\w+) =/);if(!e)throw new Error("Could not determine component name from TSX contents");return e[1]},nOt=t=>{const e=ju(s=>s.pushEvent),n=ju(s=>s.upsertFile),o=async({result:s,fullPackageName:a})=>{const c=s.package.unscoped_name??s.package.name;await Rs.promise(e({event_type:"INSTALL_PACKAGE",full_package_name:a}),{loading:`Requesting install for "${c}"`,success:`Install requested for "${c}"`,error:l=>`Failed to request install: ${l instanceof Error?l.message:String(l)}`})},i=async({footprint:s})=>{await Rs.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)}`})},r=async({result:s,tsx:a})=>{const c=`imports/${bXo(a)}.tsx`;await Rs.promise(n(c,a),{loading:`Importing ${s.component.partNumber}`,success:`Imported to "${c}"`,error:l=>`Failed to import component: ${l instanceof Error?l.message:String(l)}`})};return z.jsx(SXo,{...t,onTscircuitPackageSelected:o,onKicadStringSelected:i,onJlcpcbComponentTsxLoaded:r})};nOt.displayName="ImportComponentDialogForCli";var G7e={exports:{}},oOt;function DXo(){return oOt||(oOt=1,(function(t,e){var n={env:{},version:""};(function(o){t.exports=o()})(function(){return(function o(i,r,s){function a(l,g){if(!r[l]){if(!i[l]){var u=typeof bD=="function"&&bD;if(!g&&u)return u(l,!0);if(A)return A(l,!0);var h=new Error("Cannot find module '"+l+"'");throw h.code="MODULE_NOT_FOUND",h}var d=r[l]={exports:{}};i[l][0].call(d.exports,function(_){var m=i[l][1][_];return a(m||_)},d,d.exports,o,i,r,s)}return r[l].exports}for(var A=typeof bD=="function"&&bD,c=0;c<s.length;c++)a(s[c]);return a})({1:[function(o,i,r){var s=o("./utils"),a=o("./support"),A="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";r.encode=function(c){for(var l,g,u,h,d,_,m,p=[],I=0,f=c.length,C=f,y=s.getTypeOf(c)!=="string";I<c.length;)C=f-I,u=y?(l=c[I++],g=I<f?c[I++]:0,I<f?c[I++]:0):(l=c.charCodeAt(I++),g=I<f?c.charCodeAt(I++):0,I<f?c.charCodeAt(I++):0),h=l>>2,d=(3&l)<<4|g>>4,_=1<C?(15&g)<<2|u>>6:64,m=2<C?63&u:64,p.push(A.charAt(h)+A.charAt(d)+A.charAt(_)+A.charAt(m));return p.join("")},r.decode=function(c){var l,g,u,h,d,_,m=0,p=0,I="data:";if(c.substr(0,I.length)===I)throw new Error("Invalid base64 input, it looks like a data url.");var f,C=3*(c=c.replace(/[^A-Za-z0-9+/=]/g,"")).length/4;if(c.charAt(c.length-1)===A.charAt(64)&&C--,c.charAt(c.length-2)===A.charAt(64)&&C--,C%1!=0)throw new Error("Invalid base64 input, bad content length.");for(f=a.uint8array?new Uint8Array(0|C):new Array(0|C);m<c.length;)l=A.indexOf(c.charAt(m++))<<2|(h=A.indexOf(c.charAt(m++)))>>4,g=(15&h)<<4|(d=A.indexOf(c.charAt(m++)))>>2,u=(3&d)<<6|(_=A.indexOf(c.charAt(m++))),f[p++]=l,d!==64&&(f[p++]=g),_!==64&&(f[p++]=u);return f}},{"./support":30,"./utils":32}],2:[function(o,i,r){var s=o("./external"),a=o("./stream/DataWorker"),A=o("./stream/Crc32Probe"),c=o("./stream/DataLengthProbe");function l(g,u,h,d,_){this.compressedSize=g,this.uncompressedSize=u,this.crc32=h,this.compression=d,this.compressedContent=_}l.prototype={getContentWorker:function(){var g=new a(s.Promise.resolve(this.compressedContent)).pipe(this.compression.uncompressWorker()).pipe(new c("data_length")),u=this;return g.on("end",function(){if(this.streamInfo.data_length!==u.uncompressedSize)throw new Error("Bug : uncompressed data size mismatch")}),g},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)}},l.createWorkerFrom=function(g,u,h){return g.pipe(new A).pipe(new c("uncompressedSize")).pipe(u.compressWorker(h)).pipe(new c("compressedSize")).withStreamInfo("compression",u)},i.exports=l},{"./external":6,"./stream/Crc32Probe":25,"./stream/DataLengthProbe":26,"./stream/DataWorker":27}],3:[function(o,i,r){var s=o("./stream/GenericWorker");r.STORE={magic:"\0\0",compressWorker:function(){return new s("STORE compression")},uncompressWorker:function(){return new s("STORE decompression")}},r.DEFLATE=o("./flate")},{"./flate":7,"./stream/GenericWorker":28}],4:[function(o,i,r){var s=o("./utils"),a=(function(){for(var A,c=[],l=0;l<256;l++){A=l;for(var g=0;g<8;g++)A=1&A?3988292384^A>>>1:A>>>1;c[l]=A}return c})();i.exports=function(A,c){return A!==void 0&&A.length?s.getTypeOf(A)!=="string"?(function(l,g,u,h){var d=a,_=h+u;l^=-1;for(var m=h;m<_;m++)l=l>>>8^d[255&(l^g[m])];return-1^l})(0|c,A,A.length,0):(function(l,g,u,h){var d=a,_=h+u;l^=-1;for(var m=h;m<_;m++)l=l>>>8^d[255&(l^g.charCodeAt(m))];return-1^l})(0|c,A,A.length,0):0}},{"./utils":32}],5:[function(o,i,r){r.base64=!1,r.binary=!1,r.dir=!1,r.createFolders=!0,r.date=null,r.compression=null,r.compressionOptions=null,r.comment=null,r.unixPermissions=null,r.dosPermissions=null},{}],6:[function(o,i,r){var s=null;s=typeof Promise<"u"?Promise:o("lie"),i.exports={Promise:s}},{lie:37}],7:[function(o,i,r){var s=typeof Uint8Array<"u"&&typeof Uint16Array<"u"&&typeof Uint32Array<"u",a=o("pako"),A=o("./utils"),c=o("./stream/GenericWorker"),l=s?"uint8array":"array";function g(u,h){c.call(this,"FlateWorker/"+u),this._pako=null,this._pakoAction=u,this._pakoOptions=h,this.meta={}}r.magic="\b\0",A.inherits(g,c),g.prototype.processChunk=function(u){this.meta=u.meta,this._pako===null&&this._createPako(),this._pako.push(A.transformTo(l,u.data),!1)},g.prototype.flush=function(){c.prototype.flush.call(this),this._pako===null&&this._createPako(),this._pako.push([],!0)},g.prototype.cleanUp=function(){c.prototype.cleanUp.call(this),this._pako=null},g.prototype._createPako=function(){this._pako=new a[this._pakoAction]({raw:!0,level:this._pakoOptions.level||-1});var u=this;this._pako.onData=function(h){u.push({data:h,meta:u.meta})}},r.compressWorker=function(u){return new g("Deflate",u)},r.uncompressWorker=function(){return new g("Inflate",{})}},{"./stream/GenericWorker":28,"./utils":32,pako:38}],8:[function(o,i,r){function s(d,_){var m,p="";for(m=0;m<_;m++)p+=String.fromCharCode(255&d),d>>>=8;return p}function a(d,_,m,p,I,f){var C,y,E=d.file,B=d.compression,Q=f!==l.utf8encode,b=A.transformTo("string",f(E.name)),D=A.transformTo("string",l.utf8encode(E.name)),R=E.comment,M=A.transformTo("string",f(R)),L=A.transformTo("string",l.utf8encode(R)),G=D.length!==E.name.length,O=L.length!==R.length,U="",W="",j="",te=E.dir,ie=E.date,$={crc32:0,compressedSize:0,uncompressedSize:0};_&&!m||($.crc32=d.crc32,$.compressedSize=d.compressedSize,$.uncompressedSize=d.uncompressedSize);var Z=0;_&&(Z|=8),Q||!G&&!O||(Z|=2048);var se=0,ae=0;te&&(se|=16),I==="UNIX"?(ae=798,se|=(function(fe,Ce){var xe=fe;return fe||(xe=Ce?16893:33204),(65535&xe)<<16})(E.unixPermissions,te)):(ae=20,se|=(function(fe){return 63&(fe||0)})(E.dosPermissions)),C=ie.getUTCHours(),C<<=6,C|=ie.getUTCMinutes(),C<<=5,C|=ie.getUTCSeconds()/2,y=ie.getUTCFullYear()-1980,y<<=4,y|=ie.getUTCMonth()+1,y<<=5,y|=ie.getUTCDate(),G&&(W=s(1,1)+s(g(b),4)+D,U+="up"+s(W.length,2)+W),O&&(j=s(1,1)+s(g(M),4)+L,U+="uc"+s(j.length,2)+j);var ce="";return ce+=`
|
|
5772
|
+
`,g=new Blob([l],{type:"text/plain"}),u=URL.createObjectURL(g),h=document.createElement("a");h.href=u,h.download=`${c}.test.ts`,h.click(),URL.revokeObjectURL(u)}catch(A){alert(`Error generating test.ts for ${t.constructor.name}: ${A instanceof Error?A.message:String(A)}`)}o(!1)};return z.jsxs("div",{className:`relative ${e}`,ref:i,children:[z.jsx("button",{className:"px-2 py-1 rounded text-xs cursor-pointer",onClick:()=>o(!n),title:`Download options for ${t.constructor.name}`,children:t.constructor.name}),n&&z.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:[z.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:r,children:"Download JSON"}),z.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:s,children:"Download page.tsx"}),z.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:a,children:"Download test.ts"})]})]})},lGt=t=>t.activeSubSolver?[t,...lGt(t.activeSubSolver)]:[t],Xqo=({solver:t})=>{const e=lGt(t);return z.jsx("div",{className:"flex gap-1 items-center text-sm pt-1",children:e.map((n,o)=>z.jsxs("div",{className:"flex items-center",children:[o>0&&z.jsx("span",{className:"text-gray-400 mx-1",children:"→"}),z.jsx(jqo,{solver:n})]},n.constructor.name))})},$qo=({solver:t,triggerRender:e,animationSpeed:n=25,onSolverStarted:o,onSolverCompleted:i})=>{const[r,s]=X.useReducer(_=>!_,!1),a=X.useRef(void 0),A=()=>{!t.solved&&!t.failed&&(t.step(),e())},c=()=>{!t.solved&&!t.failed&&(o&&o(t),t.solve(),e(),i&&i(t))},l=()=>{r?(a.current&&(clearInterval(a.current),a.current=void 0),s()):(s(),a.current=setInterval(()=>{if(t.solved||t.failed){a.current&&(clearInterval(a.current),a.current=void 0),s(),e(),i&&t.solved&&i(t);return}t.step(),e()},n))},g=()=>{const _=t;if(_.getCurrentPhase&&!t.solved&&!t.failed){const m=_.getCurrentPhase();for(;_.getCurrentPhase()===m&&!t.solved&&!t.failed;)t.step();e()}},u=()=>{if(t.solved||t.failed||r)return;const _=window.prompt("Step until which iteration?",`${t.iterations}`);if(_===null)return;const m=Number(_);if(!Number.isFinite(m)){window.alert("Please enter a valid number for the iteration");return}for(;t.iterations<m&&!t.solved&&!t.failed;)t.step();e(),t.solved&&i&&i(t)};X.useEffect(()=>()=>{a.current&&clearInterval(a.current)},[]),X.useEffect(()=>{(t.solved||t.failed)&&r&&(a.current&&(clearInterval(a.current),a.current=void 0),s())},[t.solved,t.failed,r]);const h=t.getCurrentPhase!==void 0,d=h?t.getCurrentPhase():null;return z.jsxs("div",{className:"space-y-2 p-2 border-b",children:[z.jsx("div",{className:"flex items-center",children:z.jsx(Xqo,{solver:t})}),z.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[z.jsx("button",{onClick:A,disabled:t.solved||t.failed||r,className:"bg-blue-500 hover:bg-blue-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step"}),z.jsx("button",{onClick:c,disabled:t.solved||t.failed||r,className:"bg-green-500 hover:bg-green-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Solve"}),z.jsx("button",{onClick:l,disabled:t.solved||t.failed,className:`px-3 py-1 rounded text-white text-sm ${r?"bg-red-500 hover:bg-red-600":"bg-yellow-500 hover:bg-yellow-600"} disabled:bg-gray-300`,children:r?"Stop":"Animate"}),z.jsx("button",{onClick:u,disabled:t.solved||t.failed||r,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"}),h&&z.jsx("button",{onClick:g,disabled:t.solved||t.failed||r,className:"bg-purple-500 hover:bg-purple-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Next Stage"}),z.jsxs("div",{className:"text-sm text-gray-600",children:["Iterations: ",t.iterations]}),t.timeToSolve!==void 0&&z.jsxs("div",{className:"text-sm text-gray-600",children:["Time: ",(t.timeToSolve/1e3).toFixed(3),"s"]}),d&&z.jsxs("div",{className:"text-sm text-gray-600",children:["Phase: ",z.jsx("span",{className:"font-medium",children:d})]}),t.solved&&z.jsx("div",{className:"px-2 py-1 bg-green-100 text-green-800 rounded text-sm",children:"Solved"}),t.failed&&z.jsx("div",{className:"px-2 py-1 bg-red-100 text-red-800 rounded text-sm",children:"Failed"})]}),t.error&&z.jsxs("div",{className:"text-red-600 text-sm",children:["Error: ",t.error]})]})},Zqo=(t,e,n)=>{const o=t.currentPipelineStepIndex;return e<o?"Completed":e===o&&t.activeSubSolver?t.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},eWo=(t,e)=>{const o=t.pipelineDef[e].solverName,i=Zqo(t,e),r=t[o],s=t.firstIterationOfPhase?.[o]??null,a=t.iterations;let A=0;if(i==="Completed"){const u=t.pipelineDef[e+1],h=u?t.firstIterationOfPhase?.[u.solverName]:void 0;h!==void 0&&s!==null?A=h-s:s!==null&&(A=a-s)}else i==="In Progress"&&s!==null&&(A=a-s);const c=t.timeSpentOnPhase?.[o]??0;let l=0;i==="Completed"?l=1:i==="In Progress"&&r&&(l=r.progress??0);const g=r?.stats??null;return{index:e,name:o,status:i,firstIteration:s,iterations:A,progress:l,timeSpent:c,stats:g&&Object.keys(g).length>0?g:null,solverInstance:r??null}},tWo=({status:t})=>{const e={"Not Started":"text-blue-600","In Progress":"text-yellow-600",Completed:"text-green-600",Failed:"text-red-600"};return z.jsx("span",{className:`font-medium ${e[t]}`,children:t})},nWo=({progress:t})=>{if(t===0)return null;const e=Math.round(t*100);return z.jsxs("div",{className:"flex items-center gap-2",children:[z.jsx("div",{className:"w-20 h-2 bg-gray-200 rounded overflow-hidden",children:z.jsx("div",{className:"h-full bg-blue-500 transition-all duration-200",style:{width:`${e}%`}})}),z.jsxs("span",{className:"text-xs text-gray-500",children:[e,"%"]})]})},oWo=t=>Object.entries(t).map(([e,n])=>`${e}: ${n}`).join(", "),iWo=({stats:t})=>{if(!t||Object.keys(t).length===0)return z.jsx("span",{children:"-"});const e=Object.entries(t),n=oWo(t);return z.jsxs("details",{className:"cursor-pointer",children:[z.jsx("summary",{className:"whitespace-nowrap overflow-hidden text-ellipsis max-w-[200px]",children:n}),z.jsx("div",{className:"mt-1 text-xs",children:e.map(([o,i])=>z.jsxs("div",{children:[o,": ",String(i)]},o))})]})},s7e=t=>{if(t===null||typeof t!="object")return t;if(Array.isArray(t))return t.map(s7e);const e={};for(const[n,o]of Object.entries(t))n.startsWith("_")||(e[n]=s7e(o));return e},rWo=(t,e)=>{try{if(typeof t.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${e}`);return}const n=s7e(t.getConstructorParams()),o=new Blob([JSON.stringify(n,null,2)],{type:"application/json"}),i=URL.createObjectURL(o),r=document.createElement("a");r.href=i,r.download=`${e}_input.json`,r.click(),URL.revokeObjectURL(i)}catch(n){alert(`Error downloading input for ${e}: ${n instanceof Error?n.message:String(n)}`)}},sWo=({solver:t,onStepUntilPhase:e,onDownloadInput:n})=>{const o=t.pipelineDef.map((a,A)=>eWo(t,A)),i=a=>{e?.(a)},r=a=>{a.solverInstance&&(n?n(a.solverInstance,a.name):rWo(a.solverInstance,a.name))},s=a=>`${(a/1e3).toFixed(2)}s`;return z.jsxs("div",{className:"border-t border-gray-200",children:[z.jsx("div",{className:"px-4 py-2 bg-gray-50 border-b border-gray-200",children:z.jsx("h3",{className:"text-sm font-semibold text-gray-700",children:"Pipeline Steps"})}),z.jsx("div",{className:"overflow-x-auto",children:z.jsxs("table",{className:"w-full text-sm",children:[z.jsx("thead",{children:z.jsxs("tr",{className:"bg-gray-50 border-b border-gray-200",children:[z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Step"}),z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Status"}),z.jsxs("th",{className:"px-4 py-2 text-center font-semibold text-gray-700",children:["i",z.jsx("sub",{children:"0"})]}),z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Iterations"}),z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Progress"}),z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Time"}),z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stats"}),z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Input"})]})}),z.jsx("tbody",{children:o.map(a=>z.jsxs("tr",{className:`border-b border-gray-100 ${a.status==="In Progress"?"bg-yellow-50":""}`,children:[z.jsx("td",{className:"px-4 py-2",children:z.jsxs("div",{className:"flex items-center gap-2",children:[z.jsx("span",{className:"text-gray-400 w-6",children:String(a.index+1).padStart(2,"0")}),z.jsx("button",{onClick:()=>i(a.name),disabled:a.status==="Completed"||t.solved||t.failed,className:"text-blue-500 hover:text-blue-700 disabled:text-gray-300 disabled:cursor-not-allowed",title:`Step until ${a.name} completes`,children:z.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:z.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"})})}),z.jsx("span",{className:"font-medium text-gray-900",children:a.name})]})}),z.jsx("td",{className:"px-4 py-2",children:z.jsx(tWo,{status:a.status})}),z.jsx("td",{className:"px-4 py-2 text-center text-gray-600",children:a.firstIteration!==null?a.firstIteration:""}),z.jsx("td",{className:"px-4 py-2 text-gray-600",children:a.iterations}),z.jsx("td",{className:"px-4 py-2",children:z.jsx(nWo,{progress:a.progress})}),z.jsx("td",{className:"px-4 py-2 text-gray-600",children:s(a.timeSpent)}),z.jsx("td",{className:"px-4 py-2 text-gray-500",children:z.jsx(iWo,{stats:a.stats})}),z.jsx("td",{className:"px-4 py-2",children:a.solverInstance?z.jsxs("button",{onClick:()=>r(a),className:"flex items-center gap-1 text-blue-500 hover:text-blue-700",title:`Download input for ${a.name}`,children:[z.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:z.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"})}),z.jsx("span",{children:"Input"})]}):null})]},a.name))})]})})]})},aWo=class extends Xr.Component{constructor(t){super(t),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(t){console.error("InteractiveGraphics render error:",t)}render(){return this.state.hasError?this.props.fallback:this.props.children}};function AWo({graphics:t}){const e=t.points??[],n=t.lines??[],o=t.rects??[],i=t.circles??[],r=t.texts??[];let s=Number.POSITIVE_INFINITY,a=Number.POSITIVE_INFINITY,A=Number.NEGATIVE_INFINITY,c=Number.NEGATIVE_INFINITY;const l=(m,p)=>{typeof m=="number"&&(m<s&&(s=m),m>A&&(A=m)),typeof p=="number"&&(p<a&&(a=p),p>c&&(c=p))};for(const m of e)l(m.x,m.y);for(const m of n){const p=m.points??[];for(const I of p)l(I.x,I.y)}for(const m of o){const p=m.x??0,I=m.y??0,f=m.width??0,C=m.height??0;l(p,I),l(p+f,I+C)}for(const m of i){const p=m.x??0,I=m.y??0,f=m.radius??1;l(p-f,I-f),l(p+f,I+f)}for(const m of r)l(m.x,m.y);(!isFinite(s)||!isFinite(a)||!isFinite(A)||!isFinite(c))&&(s=-20,a=-20,A=20,c=20);const g=10,u=s-g,h=a-g,d=Math.max(1,A-s+2*g),_=Math.max(1,c-a+2*g);return z.jsxs("svg",{className:"w-full h-[400px] bg-white",viewBox:`${u} ${h} ${d} ${_}`,role:"img","aria-label":"Graphics fallback",children:[o.map((m,p)=>z.jsx("rect",{x:m.x??0,y:m.y??0,width:m.width??0,height:m.height??0,fill:"none",stroke:m.strokeColor??"black",strokeWidth:m.strokeWidth??1},`rect-${p}`)),n.map((m,p)=>z.jsx("polyline",{fill:"none",stroke:m.strokeColor??"black",strokeWidth:m.strokeWidth??1,points:(m.points??[]).map(I=>`${I.x??0},${I.y??0}`).join(" ")},`line-${p}`)),i.map((m,p)=>z.jsx("circle",{cx:m.x??0,cy:m.y??0,r:m.radius??1.5,fill:m.fillColor??"none",stroke:m.strokeColor??"black",strokeWidth:m.strokeWidth??1},`circle-${p}`)),e.map((m,p)=>z.jsx("circle",{cx:m.x??0,cy:m.y??0,r:m.radius??1.5,fill:m.color??"black"},`point-${p}`)),r.map((m,p)=>z.jsx("text",{x:m.x??0,y:m.y??0,fontSize:m.fontSize??10,fill:m.color??"black",children:m.text??""},`text-${p}`))]})}var cWo=({solver:t,animationSpeed:e=25,onSolverStarted:n,onSolverCompleted:o})=>{const[i,r]=X.useReducer(l=>l+1,0),s=X.useMemo(()=>{try{return t.visualize()||{points:[],lines:[],rects:[],circles:[]}}catch(l){return console.error("Visualization error:",l),{points:[],lines:[],rects:[],circles:[]}}},[t,i]),a=X.useMemo(()=>(s.rects?.length||0)===0&&(s.lines?.length||0)===0&&(s.points?.length||0)===0&&(s.circles?.length||0)===0,[s]);X.useEffect(()=>{if(!(typeof document>"u")&&!document.querySelector('script[src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"]')){const l=document.createElement("script");l.src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4",document.head.appendChild(l)}},[]);const A=t.pipelineDef!==void 0,c=l=>{const g=t;if(!t.solved&&!t.failed){for(;!t.solved&&!t.failed&&g.currentPipelineStepIndex<=g.pipelineDef.findIndex(u=>u.solverName===l);)t.step();r()}};return z.jsxs("div",{children:[z.jsx($qo,{solver:t,triggerRender:r,animationSpeed:e,onSolverStarted:n,onSolverCompleted:o}),a?z.jsx("div",{className:"p-4 text-gray-500",children:"No Graphics Yet"}):z.jsx(aWo,{fallback:z.jsx(AWo,{graphics:s}),children:z.jsx(Wqo,{graphics:s})}),A&&z.jsx(sWo,{solver:t,onStepUntilPhase:c})]})};const lWo=()=>{X.useEffect(()=>{const t="tailwind-cdn-script";if(document.getElementById(t)||window.tailwind)return;const e=document.createElement("div");e.className="hidden",document.body.appendChild(e);const n=window.getComputedStyle(e).display==="none";if(document.body.removeChild(e),n)return;const o=document.createElement("script");o.id=t,o.src="https://cdn.tailwindcss.com",document.head.appendChild(o)},[])},gWo=1e3,iQ=(t,e)=>{const{fileName:n,mimeType:o="text/plain"}=e,i=t instanceof Blob?t:new Blob([t],{type:o}),r=URL.createObjectURL(i),s=document.createElement("a");s.href=r,s.download=n,s.target="_blank",s.rel="noopener noreferrer",s.style.display="none",document.body.appendChild(s),s.click(),document.body.removeChild(s),setTimeout(()=>{URL.revokeObjectURL(r)},gWo)},a7e=t=>{let e=t.trim().replace(/[\\/:*?"<>|]/g,"_").replace(/[\x00-\x1f]/g,"").replace(/^\.+/,"").replace(/\.+$/,"").replace(/\s+/g," ").replace(/_+/g,"_");return/^(con|prn|aux|nul|com[0-9]|lpt[0-9])$/i.test(e)&&(e=`_${e}`),e=e.slice(0,200),e||"untitled"},_b="https://github.com/tscircuit/tscircuit-autorouter/issues/new",gGt="https://github.com/tscircuit/copper-pour-solver/issues/new",uGt="https://github.com/tscircuit/calculate-packing/issues/new",uWo="https://github.com/tscircuit/matchpack/issues/new",dGt="https://github.com/tscircuit/schematic-trace-solver/issues/new?template=json-bug-report.yml",dWo={PackSolver2:uGt,LayoutPipelineSolver:uWo,AutoroutingPipelineSolver:_b,AssignableAutoroutingPipeline2:_b,AssignableAutoroutingPipeline3:_b,AutoroutingPipeline1_OriginalUnravel:_b,AutoroutingPipelineSolver3_HgPortPointPathing:_b,AutoroutingPipelineSolver4:_b,AutoroutingPipelineSolver5:_b,AutoroutingPipelineSolver7_MultiGraph:_b,AutoroutingPipelineSolver8:_b,CopperPourPipelineSolver:gGt,SchematicTracePipelineSolver:dGt},hWo=t=>t.toLowerCase().includes("pack")?hNt:t.toLowerCase().includes("rout")?ALo:OFo,hGt=t=>{const e=dWo[t];if(e)return e;const n=t.toLowerCase();return n.includes("autorout")?_b:n.includes("schematic")&&n.includes("trace")?dGt:n.includes("copperpour")?gGt:n.includes("pack")?uGt:null},_Wo=t=>`${a7e(`${t.componentName}-${t.solverName}`)}-solver-input.json`,_Gt=t=>{iQ(JSON.stringify(t.solverParams,null,2),{fileName:_Wo(t),mimeType:"application/json"})},mWo=({solverEvent:t})=>{const e=hGt(t.solverName);return z.jsxs("div",{className:"rf-flex rf-items-center rf-justify-end rf-gap-2 rf-border-b rf-border-gray-200 rf-bg-gray-50 rf-px-4 rf-py-2",children:[z.jsxs(fa,{type:"button",variant:"outline",size:"sm",onClick:()=>_Gt(t),children:[z.jsx(Zre,{className:"rf-w-4 rf-h-4"}),"Download"]}),e?z.jsx(fa,{asChild:!0,variant:"outline",size:"sm",children:z.jsxs("a",{href:e,target:"_blank",rel:"noopener noreferrer",children:[z.jsx($re,{className:"rf-w-4 rf-h-4"}),"Report"]})}):z.jsxs(fa,{type:"button",variant:"outline",size:"sm",disabled:!0,title:"No report link configured for this solver",children:[z.jsx($re,{className:"rf-w-4 rf-h-4"}),"Report"]})]})},pWo=({solverEvent:t})=>{const e=hGt(t.solverName);return e?z.jsx(fa,{asChild:!0,variant:"ghost",size:"icon",className:"rf-h-8 rf-w-8",children:z.jsx("a",{href:e,target:"_blank",rel:"noopener noreferrer",title:"Report solver bug","aria-label":"Report solver bug",children:z.jsx($re,{className:"rf-w-4 rf-h-4"})})}):z.jsx(fa,{type:"button",variant:"ghost",size:"icon",className:"rf-h-8 rf-w-8",disabled:!0,title:"No report link configured for this solver","aria-label":"Report solver bug",children:z.jsx($re,{className:"rf-w-4 rf-h-4"})})},IWo=({solverEvents:t=[]})=>{const[e,n]=X.useState(null);lWo();const o=X.useMemo(()=>{const a=new Map;for(const A of t){const c=`${A.componentName}-${A.solverName}`;a.set(c,A)}return a},[t]),i=X.useMemo(()=>Array.from(o.keys()),[o]),r=e?o.get(e):null,s=X.useMemo(()=>{if(!r)return{instance:null,error:null,classFound:!1};const a=Vye[r.solverName];if(!a)return{instance:null,error:`Solver class "${r.solverName}" not found in SOLVERS registry. Available: ${Object.keys(Vye).join(", ")}`,classFound:!1};try{const A=r.solverParams,c=A?.input!==void 0?A.input:A;return{instance:new a(c),error:null,classFound:!0}}catch(A){const c=A instanceof Error?A.message:String(A);return console.error("Failed to reconstruct solver:",A),{instance:null,error:`Failed to instantiate solver: ${c}`,classFound:!0}}},[r]);return t.length===0?z.jsx("div",{className:"rf-p-4",children:z.jsx("div",{className:"rf-bg-gray-50 rf-rounded-md rf-border rf-border-gray-200",children:z.jsxs("div",{className:"rf-p-4",children:[z.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800 rf-mb-3",children:"No Solvers Detected"}),z.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."})]})})}):z.jsxs("div",{className:"rf-flex rf-h-full rf-overflow-hidden",children:[z.jsxs("div",{className:"rf-w-64 rf-border-r rf-border-gray-200 rf-overflow-y-auto rf-flex-shrink-0",children:[z.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 A=o.get(a),c=e===a;return z.jsx("div",{className:`rf-px-3 rf-py-2 rf-cursor-pointer rf-border-b rf-border-gray-100 ${c?"rf-bg-blue-50 rf-border-l-2 rf-border-l-blue-500":"hover:rf-bg-gray-50"}`,onClick:()=>n(a),children:(()=>{const l=hWo(A.solverName);return z.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[z.jsx(l,{className:"rf-w-4 rf-h-4 rf-text-blue-500 rf-flex-shrink-0"}),z.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[z.jsx("div",{className:"rf-text-sm rf-font-medium rf-text-gray-800 rf-truncate",children:A.componentName}),z.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate",children:A.solverName})]})]})})()},a)})]}),z.jsx("div",{className:"rf-flex-1 rf-overflow-hidden",children:r?s.instance?z.jsxs("div",{className:"rf-flex rf-h-full rf-flex-col rf-overflow-y-auto",children:[z.jsx(mWo,{solverEvent:r}),z.jsx("div",{className:"rf-min-h-0 rf-flex-1",children:z.jsx(Nx,{fallback:z.jsx("div",{className:"rf-p-4",children:z.jsxs("div",{className:"rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200 rf-p-4",children:[z.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-2",children:"Error Loading Solver Debugger"}),z.jsxs("p",{className:"rf-text-sm rf-text-red-600",children:["Failed to render the solver debugger for"," ",r.solverName]})]})}),children:z.jsx(cWo,{solver:s.instance})})})]}):z.jsxs("div",{className:"rf-p-4",children:[z.jsxs("div",{className:"rf-mb-4",children:[z.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800",children:r.solverName}),z.jsxs("p",{className:"rf-text-sm rf-text-gray-500",children:["Component: ",r.componentName]})]}),s.error&&z.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:z.jsx("p",{className:`rf-text-sm ${s.classFound?"rf-text-red-700":"rf-text-yellow-700"}`,children:s.error})}),z.jsxs("div",{className:"rf-border rf-border-gray-200 rf-rounded-md rf-overflow-hidden",children:[z.jsxs("div",{className:"rf-px-3 rf-py-2 rf-bg-gray-50 rf-flex rf-items-center rf-justify-between rf-gap-2",children:[z.jsx("span",{className:"rf-text-sm rf-font-medium rf-text-gray-700",children:"Solver Parameters"}),z.jsxs("div",{className:"rf-flex rf-items-center rf-gap-1",children:[z.jsx(pWo,{solverEvent:r}),z.jsx(fa,{type:"button",variant:"ghost",size:"icon",className:"rf-h-8 rf-w-8","aria-label":"Download solver input JSON",title:"Download solver input JSON",onClick:()=>_Gt(r),children:z.jsx(Zre,{className:"rf-w-4 rf-h-4"})})]})]}),z.jsx("div",{className:"rf-p-3 rf-bg-white rf-border-t rf-border-gray-200",children:z.jsx("pre",{className:"rf-text-xs rf-font-mono rf-text-gray-600 rf-whitespace-pre-wrap rf-overflow-x-auto",children:JSON.stringify(r.solverParams,null,2)})})]})]}):z.jsx("div",{className:"rf-flex rf-items-center rf-justify-center rf-h-full",children:z.jsx("p",{className:"rf-text-sm rf-text-gray-500",children:"Select a solver from the list to view details"})})})]})},mGt=({errorMessage:t,errorStack:e,circuitJsonErrors:n})=>{X.useEffect(()=>{if(t){const o=new Error(t);e&&(o.stack=e);try{DR.captureException(o)}catch{}}},[t,e]),X.useEffect(()=>{if(n&&n.length>0)for(const o of n){const i=new Error(o.message||"Circuit JSON Error");o.stack&&(i.stack=o.stack);try{DR.captureException(i,{error_type:o.type})}catch{}}},[n])},pGt=t=>{X.useEffect(()=>{try{yro(t)}catch{}},[t.source,t.component,t.isWebEmbedded,t.activeTab])},IGt="0.0.2476",fWo={version:IGt},mae=tIt()(nIt(t=>({lastRunEvalVersion:void 0,setLastRunEvalVersion:e=>{t({lastRunEvalVersion:e})}}),{name:"runframe-runner-store"})),CWo=t=>{const[e,n]=X.useState([]),[o,i]=X.useState(null),[r,s]=X.useState(""),[a,A]=iR("eval-version-selection",null),c=mae(h=>h.setLastRunEvalVersion),l=mae(h=>h.lastRunEvalVersion);return X.useEffect(()=>{t&&fetch("https://data.jsdelivr.com/v1/package/npm/@tscircuit/eval").then(h=>h.json()).then(h=>{if(Array.isArray(h?.versions)){let d=[...h.versions];h.tags?.latest&&(i(h.tags.latest),d=d.filter(_=>_!==h.tags.latest)),n(d)}}).catch(()=>{})},[t]),X.useEffect(()=>{t&&(a?(window.TSCIRCUIT_LATEST_EVAL_VERSION=a,c(a)):o&&(window.TSCIRCUIT_LATEST_EVAL_VERSION=o,c(o)))},[t,a,o]),{versions:X.useMemo(()=>e.filter(h=>h.includes(r)).slice(0,50),[e,r]),latestVersion:o,lastRunEvalVersion:l,search:r,setSearch:s,selectVersion:h=>{A(h),s("")}}},yWo=({snippetNames:t,onSelect:e,onCancel:n,isOpen:o})=>{const[i,r]=X.useState(""),[s,a]=X.useState("");if(!o)return null;const A=t.filter(g=>g.toLowerCase().includes(s.toLowerCase())),c=s&&!t.includes(s),l=g=>{g.key==="Enter"&&(A.length===1?r(A[0]):c&&r(s))};return z.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:z.jsxs("div",{className:"rf-bg-white rf-rounded-lg rf-p-6 rf-w-96",children:[z.jsx("h2",{className:"rf-text-lg rf-font-semibold rf-mb-4",children:"Select Snippet"}),z.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:g=>a(g.target.value),onKeyDown:l}),z.jsxs("div",{className:"rf-h-60 rf-overflow-y-auto",children:[A.map(g=>z.jsx("button",{type:"button",className:`w-full text-left px-4 py-2 rounded hover:bg-gray-100 ${i===g?"bg-blue-50":""}`,onClick:()=>r(g),children:g},g)),c&&z.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:()=>r(s),children:['Create new "',s,'"']})]}),z.jsxs("div",{className:"rf-mt-4 rf-flex rf-justify-end rf-gap-2",children:[z.jsx("button",{type:"button",className:"rf-px-4 rf-py-2 rf-text-gray-600 rf-hover:text-gray-800",onClick:n,children:"Cancel"}),z.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}`})]})]})})},EWo=t=>{const e=X.useRef(null),n=ju(o=>o.recentEvents);X.useEffect(()=>{if(n.length===0)return;const o=n[0];o.event_id!==e.current&&(t(o),e.current=o.event_id)},[n,t])};var xWo=Object.defineProperty,aE=(t,e)=>xWo(t,"name",{value:e,configurable:!0}),A7e="Dialog",[fGt,CGt]=Cy(A7e),[BWo,rQ]=fGt(A7e),c7e=aE(t=>{const{__scopeDialog:e,children:n,open:o,defaultOpen:i,onOpenChange:r,modal:s=!0}=t,a=X.useRef(null),A=X.useRef(null),[c,l]=MB({prop:o,defaultProp:i??!1,onChange:r,caller:A7e}),[g,u]=X.useState(0),[h,d]=X.useState(0);return z.jsx(BWo,{scope:e,triggerRef:a,contentRef:A,contentId:P_(),titleId:P_(),descriptionId:P_(),titlePresent:g>0,descriptionPresent:h>0,setTitleCount:u,setDescriptionCount:d,open:c,onOpenChange:l,onOpenToggle:X.useCallback(()=>l(_=>!_),[l]),modal:s,children:n})},"Dialog"),QWo="DialogTrigger",SWo=X.forwardRef(aE(function(e,n){const{__scopeDialog:o,...i}=e,r=rQ(QWo,o),s=Xa(n,r.triggerRef);return z.jsx(Ls.button,{type:"button","aria-haspopup":"dialog","aria-expanded":r.open,"aria-controls":r.open?r.contentId:void 0,"data-state":fae(r.open),...i,ref:s,onClick:yi(e.onClick,r.onOpenToggle)})},"DialogTrigger")),yGt="DialogPortal",[bWo,EGt]=fGt(yGt,{forceMount:void 0}),l7e=aE(t=>{const{__scopeDialog:e,forceMount:n,children:o,container:i}=t,r=rQ(yGt,e);return z.jsx(bWo,{scope:e,forceMount:n,children:X.Children.map(o,s=>z.jsx(O2,{present:n||r.open,children:z.jsx(mse,{asChild:!0,container:i,children:s})}))})},"DialogPortal"),g7e="DialogOverlay",pae=X.forwardRef(aE(function(e,n){const o=EGt(g7e,e.__scopeDialog),{forceMount:i=o.forceMount,...r}=e,s=rQ(g7e,e.__scopeDialog);return s.modal?z.jsx(O2,{present:i||s.open,children:z.jsx(vWo,{...r,ref:n})}):null},"DialogOverlay")),DWo=wB("DialogOverlay.RemoveScroll"),vWo=X.forwardRef(aE(function(e,n){const{__scopeDialog:o,...i}=e,r=rQ(g7e,o),s=INt(),a=Xa(n,s);return z.jsx(EY,{as:DWo,allowPinchZoom:!0,shards:[r.contentRef],children:z.jsx(Ls.div,{"data-state":fae(r.open),...i,ref:a,style:{pointerEvents:"auto",...i.style}})})},"DialogOverlayImpl")),zY="DialogContent",Iae=X.forwardRef(aE(function(e,n){const o=EGt(zY,e.__scopeDialog),{forceMount:i=o.forceMount,...r}=e,s=rQ(zY,e.__scopeDialog);return z.jsx(O2,{present:i||s.open,children:s.modal?z.jsx(PWo,{...r,ref:n}):z.jsx(wWo,{...r,ref:n})})},"DialogContent")),PWo=X.forwardRef(aE(function(e,n){const o=rQ(zY,e.__scopeDialog),i=X.useRef(null),r=Xa(n,o.contentRef,i);return X.useEffect(()=>{const s=i.current;if(s)return fse(s)},[]),z.jsx(xGt,{...e,ref:r,trapFocus:o.open,disableOutsidePointerEvents:o.open,onCloseAutoFocus:yi(e.onCloseAutoFocus,s=>{s.preventDefault(),o.triggerRef.current?.focus()}),onPointerDownOutside:yi(e.onPointerDownOutside,s=>{const a=s.detail.originalEvent,A=a.button===0&&a.ctrlKey===!0;(a.button===2||A)&&s.preventDefault()}),onFocusOutside:yi(e.onFocusOutside,s=>s.preventDefault())})},"DialogContentModal")),wWo=X.forwardRef(aE(function(e,n){const o=rQ(zY,e.__scopeDialog),i=X.useRef(!1),r=X.useRef(!1);return z.jsx(xGt,{...e,ref:n,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:s=>{e.onCloseAutoFocus?.(s),s.defaultPrevented||(i.current||o.triggerRef.current?.focus(),s.preventDefault()),i.current=!1,r.current=!1},onInteractOutside:s=>{e.onInteractOutside?.(s),s.defaultPrevented||(i.current=!0,s.detail.originalEvent.type==="pointerdown"&&(r.current=!0));const a=s.target;o.triggerRef.current?.contains(a)&&s.preventDefault(),s.detail.originalEvent.type==="focusin"&&r.current&&s.preventDefault()}})},"DialogContentNonModal")),xGt=X.forwardRef(aE(function(e,n){const{__scopeDialog:o,trapFocus:i,onOpenAutoFocus:r,onCloseAutoFocus:s,...a}=e,A=rQ(zY,o);return xk(),z.jsx(z.Fragment,{children:z.jsx(tse,{asChild:!0,loop:!0,trapped:i,onMountAutoFocus:r,onUnmountAutoFocus:s,children:z.jsx(IY,{role:"dialog",id:A.contentId,"aria-describedby":A.descriptionPresent?A.descriptionId:void 0,"aria-labelledby":A.titlePresent?A.titleId:void 0,"data-state":fae(A.open),...a,ref:n,deferPointerDownOutside:!0,onDismiss:()=>A.onOpenChange(!1)})})})},"DialogContentImpl")),MWo="DialogTitle",u7e=X.forwardRef(aE(function(e,n){const{__scopeDialog:o,...i}=e,r=rQ(MWo,o),{setTitleCount:s}=r;return jd(()=>(s(a=>a+1),()=>s(a=>a-1)),[s]),z.jsx(Ls.h2,{id:r.titleId,...i,ref:n})},"DialogTitle")),NWo="DialogDescription",d7e=X.forwardRef(aE(function(e,n){const{__scopeDialog:o,...i}=e,r=rQ(NWo,o),{setDescriptionCount:s}=r;return jd(()=>(s(a=>a+1),()=>s(a=>a-1)),[s]),z.jsx(Ls.p,{id:r.descriptionId,...i,ref:n})},"DialogDescription")),RWo="DialogClose",BGt=X.forwardRef(aE(function(e,n){const{__scopeDialog:o,...i}=e,r=rQ(RWo,o);return z.jsx(Ls.button,{type:"button",...i,ref:n,onClick:yi(e.onClick,()=>r.onOpenChange(!1))})},"DialogClose"));function fae(t){return t?"open":"closed"}aE(fae,"getState");var TWo=Object.defineProperty,b5=(t,e)=>TWo(t,"name",{value:e,configurable:!0}),kWo="AlertDialog",[FWo,oai]=Cy(kWo,[CGt]),D5=CGt(),LWo=b5(t=>{const{__scopeAlertDialog:e,...n}=t,o=D5(e);return z.jsx(c7e,{...o,...n,modal:!0})},"AlertDialog");X.forwardRef(b5(function(e,n){const{__scopeAlertDialog:o,...i}=e,r=D5(o);return z.jsx(SWo,{...r,...i,ref:n})},"AlertDialogTrigger"));var HWo=b5(t=>{const{__scopeAlertDialog:e,...n}=t,o=D5(e);return z.jsx(l7e,{...o,...n})},"AlertDialogPortal"),GWo=X.forwardRef(b5(function(e,n){const{__scopeAlertDialog:o,...i}=e,r=D5(o);return z.jsx(pae,{...r,...i,ref:n})},"AlertDialogOverlay")),OWo="AlertDialogContent",[KWo,UWo]=FWo(OWo),YWo=X.forwardRef(b5(function(e,n){const{__scopeAlertDialog:o,children:i,...r}=e,s=D5(o),a=X.useRef(null),A=Xa(n,a),c=X.useRef(null);return z.jsx(KWo,{scope:o,cancelRef:c,children:z.jsx(Iae,{role:"alertdialog",...s,...r,ref:A,onOpenAutoFocus:yi(r.onOpenAutoFocus,l=>{l.preventDefault(),c.current?.focus({preventScroll:!0})}),onPointerDownOutside:l=>l.preventDefault(),onInteractOutside:l=>l.preventDefault(),children:i})})},"AlertDialogContent")),zWo=X.forwardRef(b5(function(e,n){const{__scopeAlertDialog:o,...i}=e,r=D5(o);return z.jsx(u7e,{...r,...i,ref:n})},"AlertDialogTitle")),VWo=X.forwardRef(b5(function(e,n){const{__scopeAlertDialog:o,...i}=e,r=D5(o);return z.jsx(d7e,{...r,...i,ref:n})},"AlertDialogDescription")),JWo=X.forwardRef(b5(function(e,n){const{__scopeAlertDialog:o,...i}=e,r=D5(o);return z.jsx(BGt,{...r,...i,ref:n})},"AlertDialogAction")),qWo="AlertDialogCancel",WWo=X.forwardRef(b5(function(e,n){const{__scopeAlertDialog:o,...i}=e,{cancelRef:r}=UWo(qWo,o),s=D5(o),a=Xa(n,r);return z.jsx(BGt,{...s,...i,ref:a})},"AlertDialogCancel")),jWo=LWo,XWo=HWo,QGt=GWo,SGt=YWo,bGt=JWo,DGt=WWo,vGt=zWo,PGt=VWo;const wGt=jWo,$Wo=XWo,MGt=X.forwardRef(({className:t,...e},n)=>z.jsx(QGt,{className:Ei("rf-fixed rf-inset-0 rf-z-50 rf-bg-black/80 data-[state=open]:rf-animate-in data-[state=closed]:rf-animate-out data-[state=closed]:rf-fade-out-0 data-[state=open]:rf-fade-in-0",t),...e,ref:n}));MGt.displayName=QGt.displayName;const h7e=X.forwardRef(({className:t,...e},n)=>z.jsxs($Wo,{children:[z.jsx(MGt,{}),z.jsx(SGt,{ref:n,className:Ei("rf-fixed rf-left-[50%] rf-top-[50%] rf-z-50 rf-grid rf-w-full rf-max-w-lg rf-translate-x-[-50%] rf-translate-y-[-50%] rf-gap-4 rf-border rf-border-zinc-200 rf-bg-white rf-p-6 rf-shadow-lg rf-duration-200 data-[state=open]:rf-animate-in data-[state=closed]:rf-animate-out data-[state=closed]:rf-fade-out-0 data-[state=open]:rf-fade-in-0 data-[state=closed]:rf-zoom-out-95 data-[state=open]:rf-zoom-in-95 data-[state=closed]:rf-slide-out-to-left-1/2 data-[state=closed]:rf-slide-out-to-top-[48%] data-[state=open]:rf-slide-in-from-left-1/2 data-[state=open]:rf-slide-in-from-top-[48%] sm:rf-rounded-lg dark:rf-border-zinc-800 dark:rf-bg-zinc-950",t),...e})]}));h7e.displayName=SGt.displayName;const _7e=({className:t,...e})=>z.jsx("div",{className:Ei("rf-flex rf-flex-col rf-space-y-2 rf-text-center sm:rf-text-left",t),...e});_7e.displayName="AlertDialogHeader";const m7e=({className:t,...e})=>z.jsx("div",{className:Ei("rf-flex rf-flex-col-reverse sm:rf-flex-row sm:rf-justify-end sm:rf-space-x-2",t),...e});m7e.displayName="AlertDialogFooter";const p7e=X.forwardRef(({className:t,...e},n)=>z.jsx(vGt,{ref:n,className:Ei("rf-text-lg rf-font-semibold",t),...e}));p7e.displayName=vGt.displayName;const I7e=X.forwardRef(({className:t,...e},n)=>z.jsx(PGt,{ref:n,className:Ei("rf-text-sm rf-text-zinc-500 dark:rf-text-zinc-400",t),...e}));I7e.displayName=PGt.displayName;const ZWo=X.forwardRef(({className:t,...e},n)=>z.jsx(bGt,{ref:n,className:Ei(Ck(),t),...e}));ZWo.displayName=bGt.displayName;const f7e=X.forwardRef(({className:t,...e},n)=>z.jsx(DGt,{ref:n,className:Ei(Ck({variant:"outline"}),"rf-mt-2 sm:rf-mt-0",t),...e}));f7e.displayName=DGt.displayName;var ejo=Object.defineProperty,v5=(t,e)=>ejo(t,"name",{value:e,configurable:!0}),C7e="Checkbox",[tjo,iai]=Cy(C7e),[njo,y7e]=tjo(C7e);function NGt(t){const{__scopeCheckbox:e,checked:n,children:o,defaultChecked:i,disabled:r,form:s,name:a,onCheckedChange:A,required:c,value:l="on",internal_do_not_use_render:g}=t,[u,h]=MB({prop:n,defaultProp:i??!1,onChange:A,caller:C7e}),[d,_]=X.useState(null),[m,p]=X.useState(null),I=X.useRef(!1),[f,C]=X.useReducer(B=>B+1,0),y=d?!!s||!!d.closest("form"):!0,E={checked:u,disabled:r,setChecked:h,control:d,setControl:_,name:a,form:s,value:l,hasConsumerStoppedPropagationRef:I,userInteractionCount:f,onUserInteraction:C,required:c,defaultChecked:P5(i)?!1:i,isFormControl:y,bubbleInput:m,setBubbleInput:p};return z.jsx(njo,{scope:e,...E,children:TGt(g)?g(E):o})}v5(NGt,"CheckboxProvider");var ojo="CheckboxTrigger",ijo=X.forwardRef(v5(function({__scopeCheckbox:e,onKeyDown:n,onClick:o,...i},r){const{control:s,value:a,disabled:A,checked:c,required:l,setControl:g,setChecked:u,hasConsumerStoppedPropagationRef:h,onUserInteraction:d,isFormControl:_,bubbleInput:m}=y7e(ojo,e),p=Xa(r,g),I=X.useRef(c);return X.useEffect(()=>{const f=s?.form;if(f){const C=v5(()=>u(I.current),"reset");return f.addEventListener("reset",C),()=>f.removeEventListener("reset",C)}},[s,u]),z.jsx(Ls.button,{type:"button",role:"checkbox","aria-checked":P5(c)?"mixed":c,"aria-required":l,"data-state":E7e(c),"data-disabled":A?"":void 0,disabled:A,value:a,...i,ref:p,onKeyDown:yi(n,f=>{f.key==="Enter"&&f.preventDefault()}),onClick:yi(o,f=>{d(),u(C=>P5(C)?!0:!C),m&&_&&(h.current=f.isPropagationStopped(),h.current||f.stopPropagation())})})},"CheckboxTrigger")),RGt=X.forwardRef(v5(function(e,n){const{__scopeCheckbox:o,name:i,checked:r,defaultChecked:s,required:a,disabled:A,value:c,onCheckedChange:l,form:g,...u}=e;return z.jsx(NGt,{__scopeCheckbox:o,checked:r,defaultChecked:s,disabled:A,required:a,onCheckedChange:l,name:i,form:g,value:c,internal_do_not_use_render:({isFormControl:h})=>z.jsxs(z.Fragment,{children:[z.jsx(ijo,{...u,ref:n,__scopeCheckbox:o}),h&&z.jsx(Ajo,{__scopeCheckbox:o})]})})},"Checkbox")),rjo="CheckboxIndicator",sjo=X.forwardRef(v5(function(e,n){const{__scopeCheckbox:o,forceMount:i,...r}=e,s=y7e(rjo,o);return z.jsx(O2,{present:i||P5(s.checked)||s.checked===!0,children:z.jsx(Ls.span,{"data-state":E7e(s.checked),"data-disabled":s.disabled?"":void 0,...r,ref:n,style:{pointerEvents:"none",...e.style}})})},"CheckboxIndicator")),ajo="CheckboxBubbleInput",Ajo=X.forwardRef(v5(function({__scopeCheckbox:e,onClick:n,...o},i){const{control:r,hasConsumerStoppedPropagationRef:s,userInteractionCount:a,checked:A,defaultChecked:c,required:l,disabled:g,name:u,value:h,form:d,bubbleInput:_,setBubbleInput:m}=y7e(ajo,e),p=Xa(i,m),I=x8e(r),f=X.useRef(!1),C=X.useRef(A),y=X.useRef(a);X.useEffect(()=>{const B=_;if(!B)return;const Q=window.HTMLInputElement.prototype,D=Object.getOwnPropertyDescriptor(Q,"checked").set,R=a!==y.current;y.current=a;const M=C.current!==A;C.current=A;const L=!(R&&s.current);if(M&&D){f.current=!R;const G=new Event("click",{bubbles:L});B.indeterminate=P5(A),D.call(B,P5(A)?!1:A),B.dispatchEvent(G),f.current=!1}},[_,A,s,a]);const E=X.useRef(P5(A)?!1:A);return z.jsx(Ls.input,{type:"checkbox","aria-hidden":!0,defaultChecked:c??E.current,required:l,disabled:g,name:u,value:h,form:d,...o,tabIndex:-1,ref:p,onClick:yi(n,B=>{f.current&&B.stopPropagation()}),style:{...o.style,...I,position:"absolute",pointerEvents:"none",opacity:0,margin:0,transform:"translateX(-100%)"}})},"CheckboxBubbleInput"));function TGt(t){return typeof t=="function"}v5(TGt,"isFunction");function P5(t){return t==="indeterminate"}v5(P5,"isIndeterminate");function E7e(t){return P5(t)?"indeterminate":t?"checked":"unchecked"}v5(E7e,"getState");const VY=X.forwardRef(({className:t,...e},n)=>z.jsx(RGt,{ref:n,className:Ei("rf-peer rf-h-4 rf-w-4 rf-shrink-0 rf-rounded-sm rf-border rf-border-zinc-200 rf-border-zinc-900 rf-shadow focus-visible:rf-outline-none focus-visible:rf-ring-1 focus-visible:rf-ring-zinc-950 disabled:rf-cursor-not-allowed disabled:rf-opacity-50 data-[state=checked]:rf-bg-zinc-900 data-[state=checked]:rf-text-zinc-50 dark:rf-border-zinc-800 dark:rf-border-zinc-50 dark:focus-visible:rf-ring-zinc-300 dark:data-[state=checked]:rf-bg-zinc-50 dark:data-[state=checked]:rf-text-zinc-900",t),...e,children:z.jsx(sjo,{className:Ei("rf-flex rf-items-center rf-justify-center rf-text-current"),children:z.jsx(UP,{className:"rf-h-4 rf-w-4"})})}));VY.displayName=RGt.displayName;const X6=c7e,cjo=l7e,kGt=X.forwardRef(({className:t,...e},n)=>z.jsx(pae,{className:Ei("rf-fixed rf-inset-0 rf-z-50 rf-bg-black/80 data-[state=open]:rf-animate-in data-[state=closed]:rf-animate-out data-[state=closed]:rf-fade-out-0 data-[state=open]:rf-fade-in-0",t),...e,ref:n}));kGt.displayName=pae.displayName;const tw=X.forwardRef(({className:t,children:e,showOverlay:n=!0,...o},i)=>z.jsxs(cjo,{children:[z.jsx(kGt,{className:Ei(n?"":"rf-hidden")}),z.jsx(Iae,{ref:i,className:Ei("rf-fixed rf-left-[50%] rf-top-[50%] rf-z-50 rf-grid rf-w-full rf-max-w-lg rf-translate-x-[-50%] rf-translate-y-[-50%] rf-gap-4 rf-border rf-border-zinc-200 rf-bg-white rf-p-6 rf-shadow-lg rf-duration-200 data-[state=open]:rf-animate-in data-[state=closed]:rf-animate-out data-[state=closed]:rf-fade-out-0 data-[state=open]:rf-fade-in-0 data-[state=closed]:rf-zoom-out-95 data-[state=open]:rf-zoom-in-95 data-[state=closed]:rf-slide-out-to-left-1/2 data-[state=closed]:rf-slide-out-to-top-[48%] data-[state=open]:rf-slide-in-from-left-1/2 data-[state=open]:rf-slide-in-from-top-[48%] sm:rf-rounded-lg dark:rf-border-zinc-800 dark:rf-bg-zinc-950",t),...o,children:e})]}));tw.displayName=Iae.displayName;const nw=({className:t,...e})=>z.jsx("div",{className:Ei("rf-flex rf-flex-col rf-space-y-2 rf-text-center sm:rf-text-left",t),...e});nw.displayName="DialogHeader";const Kk=({className:t,...e})=>z.jsx("div",{className:Ei("rf-flex rf-flex-col-reverse sm:rf-flex-row sm:rf-justify-end sm:rf-space-x-2",t),...e});Kk.displayName="DialogFooter";const ow=X.forwardRef(({className:t,...e},n)=>z.jsx(u7e,{ref:n,className:Ei("rf-text-lg rf-font-semibold",t),...e}));ow.displayName=u7e.displayName;const $6=X.forwardRef(({className:t,...e},n)=>z.jsx(d7e,{ref:n,className:Ei("rf-text-sm rf-text-zinc-500 dark:rf-text-zinc-400",t),...e}));$6.displayName=d7e.displayName;const Cae={"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"}},ljo="https://cdn.jsdelivr.net/npm/easyeda@latest/dist/browser/index.js";let x7e=null;const B7e=async()=>(x7e||(x7e=import(ljo)),x7e),gjo=t=>(e,n)=>{const o=new Headers(n?.headers),i={};return o.forEach((r,s)=>{i[s]=r}),fetch(`${t?.apiBase??Hf}/proxy`,{...n,headers:{...i,"X-Target-Url":e.toString(),"X-Sender-Origin":i.origin??"","X-Sender-Host":i.host??"https://easyeda.com","X-Sender-Referer":i.referer??"","X-Sender-User-Agent":i["user-agent"]??"","X-Sender-Cookie":i.cookie??"",authority:i.authority??"","content-type":i["content-type"]??"",...t?.headers}})},ujo=async(t,e=10)=>{const n=encodeURIComponent(t),o=await fetch(`https://jlcsearch.tscircuit.com/api/search?limit=${e}&q=${n}`);if(!o.ok)throw new Error(`JLCPCB API error: ${o.status}`);return(await o.json()).components??[]},djo=t=>({lcscId:t.lcsc,manufacturer:t.mfr,description:t.description,partNumber:`C${t.lcsc}`,package:t.package,price:t.price,stock:t.stock,isBasic:t.is_basic}),FGt=async(t,e)=>{const{fetchEasyEDAComponent:n}=await B7e();return n(t,{fetch:gjo(e),includeModelMetadata:e?.includeModelMetadata})},hjo=async(t,e)=>{const{convertRawEasyToTsx:n}=await B7e(),o=await FGt(t,e);return n({rawEasy:o})},_jo=async(t,e)=>{const{EasyEdaJsonSchema:n,convertEasyEdaJsonToCircuitJson:o}=await B7e(),i=await FGt(t,{...e,includeModelMetadata:!1}),r=n.parse(i);return o(r,{shouldRecenter:!0,showDesignator:!0,useModelCdn:!1})};function iw(t){return Array.isArray?Array.isArray(t):HGt(t)==="[object Array]"}function mjo(t){if(typeof t=="string")return t;if(typeof t=="bigint")return t.toString();const e=t+"";return e=="0"&&1/t==-1/0?"-0":e}function Q7e(t){return t==null?"":mjo(t)}function Wf(t){return typeof t=="string"}function yae(t){return typeof t=="number"}function pjo(t){return t===!0||t===!1||Ijo(t)&&HGt(t)=="[object Boolean]"}function LGt(t){return typeof t=="object"}function Ijo(t){return LGt(t)&&t!==null}function AE(t){return t!=null}function Eae(t){return!t.trim().length}function HGt(t){return t==null?t===void 0?"[object Undefined]":"[object Null]":Object.prototype.toString.call(t)}const fjo="Incorrect 'index' type",S7e="Invalid doc index: must be a non-negative integer within the bounds of the docs array",Cjo=t=>`Invalid value for key ${t}`,yjo=t=>`Pattern length exceeds max of ${t}.`,Ejo=t=>`Missing ${t} property in key`,xjo=t=>`Property 'weight' in key '${t}' must be a positive integer`,Bjo="Fuse.match does not support useTokenSearch: token search requires corpus-level statistics (df, fieldCount) that a one-off string comparison does not have. Use new Fuse(...).search(...) instead.",GGt=Object.prototype.hasOwnProperty;var Qjo=class{constructor(t){this._keys=[],this._keyMap={};let e=0;t.forEach(n=>{const o=OGt(n);this._keys.push(o),this._keyMap[o.id]=o,e+=o.weight}),this._keys.forEach(n=>{n.weight/=e})}get(t){return this._keyMap[t]}keys(){return this._keys}toJSON(){return JSON.stringify(this._keys)}};function OGt(t){let e=null,n=null,o=null,i=1,r=null;if(Wf(t)||iw(t))o=t,e=KGt(t),n=xae(t);else{if(!GGt.call(t,"name"))throw new Error(Ejo("name"));const s=t.name;if(o=s,GGt.call(t,"weight")&&t.weight!==void 0&&(i=t.weight,i<=0))throw new Error(xjo(xae(s)));e=KGt(s),n=xae(s),r=t.getFn??null}return{path:e,id:n,weight:i,src:o,getFn:r}}function KGt(t){return iw(t)?t:t.split(".")}function xae(t){return iw(t)?t.join("."):t}function Sjo(t,e){const n=[];let o=!1;const i=(r,s,a,A)=>{if(AE(r))if(!s[a])n.push(A!==void 0?{v:r,i:A}:r);else{const c=r[s[a]];if(!AE(c))return;if(a===s.length-1&&(Wf(c)||yae(c)||pjo(c)||typeof c=="bigint"))n.push(A!==void 0?{v:Q7e(c),i:A}:Q7e(c));else if(iw(c)){o=!0;for(let l=0,g=c.length;l<g;l+=1)i(c[l],s,a+1,l)}else s.length&&i(c,s,a+1,A)}};return i(t,Wf(e)?e.split("."):e,0),o?n:n[0]}const Ts=Object.freeze({...{isCaseSensitive:!1,ignoreDiacritics:!1,includeScore:!1,keys:[],shouldSort:!0,sortFn:(t,e)=>t.score===e.score?t.idx<e.idx?-1:1:t.score<e.score?-1:1},...{includeMatches:!1,findAllMatches:!1,minMatchCharLength:1},...{location:0,threshold:.6,distance:100},...{useExtendedSearch:!1,useTokenSearch:!1,tokenize:void 0,tokenMatch:"any",getFn:Sjo,ignoreLocation:!1,ignoreFieldNorm:!1,fieldNormWeight:1}});function bjo(t){return t>=9&&t<=13||t===32||t===160}function Djo(t=1,e=3){const n=new Map,o=Math.pow(10,e);return{get(i){let r=0,s=!1;for(let A=0;A<i.length;A++)bjo(i.charCodeAt(A))?s=!1:s||(r++,s=!0);if(r===0&&(r=1),n.has(r))return n.get(r);const a=Math.round(o/Math.pow(r,.5*t))/o;return n.set(r,a),a},clear(){n.clear()}}}var b7e=class{constructor({getFn:t=Ts.getFn,fieldNormWeight:e=Ts.fieldNormWeight}={}){this.norm=Djo(e,3),this.getFn=t,this.isCreated=!1,this.docs=[],this.keys=[],this._keysMap={},this.setIndexRecords()}setSources(t=[]){this.docs=t}setIndexRecords(t=[]){this.records=t}setKeys(t=[]){this.keys=t,this._keysMap={},t.forEach((e,n)=>{this._keysMap[e.id]=n})}create(){if(this.isCreated||!this.docs.length)return;this.isCreated=!0;const t=this.docs.length;this.records=new Array(t);let e=0;if(Wf(this.docs[0]))for(let n=0;n<t;n++){const o=this._createStringRecord(this.docs[n],n);o&&(this.records[e++]=o)}else for(let n=0;n<t;n++)this.records[e++]=this._createObjectRecord(this.docs[n],n);this.records.length=e,this.norm.clear()}add(t,e){if(!Number.isInteger(e)||e<0)throw new Error(S7e);if(Wf(t)){const o=this._createStringRecord(t,e);return o&&this.records.push(o),o}const n=this._createObjectRecord(t,e);return this.records.push(n),n}removeAt(t){if(!Number.isInteger(t)||t<0)throw new Error(S7e);for(let e=0,n=this.records.length;e<n;e+=1)if(this.records[e].i===t){this.records.splice(e,1);break}for(let e=0,n=this.records.length;e<n;e+=1)this.records[e].i>t&&(this.records[e].i-=1)}removeAll(t){const e=new Set;for(const o of t)Number.isInteger(o)&&o>=0&&e.add(o);if(e.size===0)return;this.records=this.records.filter(o=>!e.has(o.i));const n=Array.from(e).sort((o,i)=>o-i);for(const o of this.records){let i=0,r=n.length;for(;i<r;){const s=i+r>>>1;n[s]<o.i?i=s+1:r=s}o.i-=i}}getValueForItemAtKeyId(t,e){return t[this._keysMap[e]]}size(){return this.records.length}_createStringRecord(t,e){return!AE(t)||Eae(t)?null:{v:t,i:e,n:this.norm.get(t)}}_createObjectRecord(t,e){const n={i:e,$:{}};for(let o=0,i=this.keys.length;o<i;o++){const r=this.keys[o],s=r.getFn?r.getFn(t):this.getFn(t,r.path);if(AE(s)){if(iw(s)){const a=[];for(let A=0,c=s.length;A<c;A+=1){const l=s[A];if(AE(l)){if(Wf(l)){if(!Eae(l)){const g={v:l,i:A,n:this.norm.get(l)};a.push(g)}}else if(AE(l.v)){const g=Wf(l.v)?l.v:Q7e(l.v);if(!Eae(g)){const u={v:g,i:l.i,n:this.norm.get(g)};a.push(u)}}}}n.$[o]=a}else if(Wf(s)&&!Eae(s)){const a={v:s,n:this.norm.get(s)};n.$[o]=a}}}return n}toJSON(){return{keys:this.keys.map(({getFn:t,...e})=>e),records:this.records}}};function UGt(t,e,{getFn:n=Ts.getFn,fieldNormWeight:o=Ts.fieldNormWeight}={}){const i=new b7e({getFn:n,fieldNormWeight:o});return i.setKeys(t.map(OGt)),i.setSources(e),i.create(),i}function vjo(t,{getFn:e=Ts.getFn,fieldNormWeight:n=Ts.fieldNormWeight}={}){const{keys:o,records:i}=t,r=new b7e({getFn:e,fieldNormWeight:n});return r.setKeys(o),r.setIndexRecords(i),r}function Pjo(t=[],e=Ts.minMatchCharLength){const n=[];let o=-1,i=-1,r=0;for(let s=t.length;r<s;r+=1){const a=t[r];a&&o===-1?o=r:!a&&o!==-1&&(i=r-1,i-o+1>=e&&n.push([o,i]),o=-1)}return t[r-1]&&r-o>=e&&n.push([o,r-1]),n}function wjo(t,e,n,{location:o=Ts.location,distance:i=Ts.distance,threshold:r=Ts.threshold,findAllMatches:s=Ts.findAllMatches,minMatchCharLength:a=Ts.minMatchCharLength,includeMatches:A=Ts.includeMatches,ignoreLocation:c=Ts.ignoreLocation}={}){if(e.length>32)throw new Error(yjo(32));const l=e.length,g=t.length,u=Math.max(0,Math.min(o,g));let h=r,d=u;const _=(b,D)=>{const R=b/l;if(c)return R;const M=Math.abs(u-D);return i?R+M/i:M?1:R},m=a>1||A,p=m?Array(g):[];let I;for(;(I=t.indexOf(e,d))>-1;){const b=_(0,I);if(h=Math.min(b,h),d=I+l,m){let D=0;for(;D<l;)p[I+D]=1,D+=1}}d=-1;let f=[],C=1,y=0,E=l+g;const B=1<<l-1;for(let b=0;b<l;b+=1){let D=0,R=E;for(;D<R;)_(b,u+R)<=h?D=R:E=R,R=Math.floor((E-D)/2+D);E=R;let M=Math.max(1,u-R+1);const L=s?g:Math.min(u+R,g)+l,G=Array(L+2);G[L+1]=(1<<b)-1;for(let O=L;O>=M;O-=1){const U=O-1,W=n[t[U]];if(G[O]=(G[O+1]<<1|1)&W,b&&(G[O]|=(f[O+1]|f[O])<<1|1|f[O+1]),G[O]&B&&(C=_(b,U),C<=h)){if(h=C,d=U,y=b,d<=u)break;M=Math.max(1,2*u-d)}}if(_(b+1,u)>h)break;f=G}if(m&&d>=0){const b=Math.min(g-1,d+l-1+y);for(let D=d;D<=b;D+=1)n[t[D]]&&(p[D]=1)}const Q={isMatch:d>=0,score:Math.max(.001,C)};if(m){const b=Pjo(p,a);b.length?A&&(Q.indices=b):Q.isMatch=!1}return Q}function Mjo(t){const e={};for(let n=0,o=t.length;n<o;n+=1){const i=t.charAt(n);e[i]=(e[i]||0)|1<<o-n-1}return e}function D7e(t){if(t.length<=1)return t;t.sort((n,o)=>n[0]-o[0]||n[1]-o[1]);const e=[t[0]];for(let n=1,o=t.length;n<o;n+=1){const i=e[e.length-1],r=t[n];r[0]<=i[1]+1?i[1]=Math.max(i[1],r[1]):e.push(r)}return e}const YGt={ł:"l",Ł:"L",đ:"d",Đ:"D",ø:"o",Ø:"O",ħ:"h",Ħ:"H",ŧ:"t",Ŧ:"T",ı:"i",ß:"ss"},Njo=new RegExp("["+Object.keys(YGt).join("")+"]","g"),JY=typeof String.prototype.normalize=="function"?t=>t.normalize("NFD").replace(/[\u0300-\u036F\u0483-\u0489\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u0610-\u061A\u064B-\u065F\u0670\u06D6-\u06DC\u06DF-\u06E4\u06E7\u06E8\u06EA-\u06ED\u0711\u0730-\u074A\u07A6-\u07B0\u07EB-\u07F3\u07FD\u0816-\u0819\u081B-\u0823\u0825-\u0827\u0829-\u082D\u0859-\u085B\u08D3-\u08E1\u08E3-\u0903\u093A-\u093C\u093E-\u094F\u0951-\u0957\u0962\u0963\u0981-\u0983\u09BC\u09BE-\u09C4\u09C7\u09C8\u09CB-\u09CD\u09D7\u09E2\u09E3\u09FE\u0A01-\u0A03\u0A3C\u0A3E-\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A70\u0A71\u0A75\u0A81-\u0A83\u0ABC\u0ABE-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD\u0AE2\u0AE3\u0AFA-\u0AFF\u0B01-\u0B03\u0B3C\u0B3E-\u0B44\u0B47\u0B48\u0B4B-\u0B4D\u0B56\u0B57\u0B62\u0B63\u0B82\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD7\u0C00-\u0C04\u0C3E-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C62\u0C63\u0C81-\u0C83\u0CBC\u0CBE-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5\u0CD6\u0CE2\u0CE3\u0D00-\u0D03\u0D3B\u0D3C\u0D3E-\u0D44\u0D46-\u0D48\u0D4A-\u0D4D\u0D57\u0D62\u0D63\u0D82\u0D83\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DF2\u0DF3\u0E31\u0E34-\u0E3A\u0E47-\u0E4E\u0EB1\u0EB4-\u0EB9\u0EBB\u0EBC\u0EC8-\u0ECD\u0F18\u0F19\u0F35\u0F37\u0F39\u0F3E\u0F3F\u0F71-\u0F84\u0F86\u0F87\u0F8D-\u0F97\u0F99-\u0FBC\u0FC6\u102B-\u103E\u1056-\u1059\u105E-\u1060\u1062-\u1064\u1067-\u106D\u1071-\u1074\u1082-\u108D\u108F\u109A-\u109D\u135D-\u135F\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17B4-\u17D3\u17DD\u180B-\u180D\u1885\u1886\u18A9\u1920-\u192B\u1930-\u193B\u1A17-\u1A1B\u1A55-\u1A5E\u1A60-\u1A7C\u1A7F\u1AB0-\u1ABE\u1B00-\u1B04\u1B34-\u1B44\u1B6B-\u1B73\u1B80-\u1B82\u1BA1-\u1BAD\u1BE6-\u1BF3\u1C24-\u1C37\u1CD0-\u1CD2\u1CD4-\u1CE8\u1CED\u1CF2-\u1CF4\u1CF7-\u1CF9\u1DC0-\u1DF9\u1DFB-\u1DFF\u20D0-\u20F0\u2CEF-\u2CF1\u2D7F\u2DE0-\u2DFF\u302A-\u302F\u3099\u309A\uA66F-\uA672\uA674-\uA67D\uA69E\uA69F\uA6F0\uA6F1\uA802\uA806\uA80B\uA823-\uA827\uA880\uA881\uA8B4-\uA8C5\uA8E0-\uA8F1\uA8FF\uA926-\uA92D\uA947-\uA953\uA980-\uA983\uA9B3-\uA9C0\uA9E5\uAA29-\uAA36\uAA43\uAA4C\uAA4D\uAA7B-\uAA7D\uAAB0\uAAB2-\uAAB4\uAAB7\uAAB8\uAABE\uAABF\uAAC1\uAAEB-\uAAEF\uAAF5\uAAF6\uABE3-\uABEA\uABEC\uABED\uFB1E\uFE00-\uFE0F\uFE20-\uFE2F]/g,"").replace(Njo,e=>YGt[e]):t=>t;var v7e=class{constructor(t,{location:e=Ts.location,threshold:n=Ts.threshold,distance:o=Ts.distance,includeMatches:i=Ts.includeMatches,findAllMatches:r=Ts.findAllMatches,minMatchCharLength:s=Ts.minMatchCharLength,isCaseSensitive:a=Ts.isCaseSensitive,ignoreDiacritics:A=Ts.ignoreDiacritics,ignoreLocation:c=Ts.ignoreLocation}={}){if(this.options={location:e,threshold:n,distance:o,includeMatches:i,findAllMatches:r,minMatchCharLength:s,isCaseSensitive:a,ignoreDiacritics:A,ignoreLocation:c},t=a?t:t.toLowerCase(),t=A?JY(t):t,this.pattern=t,this.chunks=[],!this.pattern.length)return;const l=(u,h)=>{this.chunks.push({pattern:u,alphabet:Mjo(u),startIndex:h})},g=this.pattern.length;if(g>32){let u=0;const h=g%32,d=g-h;for(;u<d;)l(this.pattern.substr(u,32),u),u+=32;if(h){const _=g-32;l(this.pattern.substr(_),_)}}else l(this.pattern,0)}searchIn(t){const{isCaseSensitive:e,ignoreDiacritics:n,includeMatches:o}=this.options;if(t=e?t:t.toLowerCase(),t=n?JY(t):t,this.pattern===t){if(t.length<this.options.minMatchCharLength)return{isMatch:!1,score:1};const d={isMatch:!0,score:0};return o&&(d.indices=[[0,t.length-1]]),d}const{location:i,distance:r,threshold:s,findAllMatches:a,minMatchCharLength:A,ignoreLocation:c}=this.options,l=[];let g=0,u=!1;this.chunks.forEach(({pattern:d,alphabet:_,startIndex:m})=>{const{isMatch:p,score:I,indices:f}=wjo(t,d,_,{location:i+m,distance:r,threshold:s,findAllMatches:a,minMatchCharLength:A,includeMatches:o,ignoreLocation:c});p&&(u=!0),g+=I,p&&f&&l.push(...f)});const h={isMatch:u,score:u?g/this.chunks.length:1};return u&&o&&(h.indices=D7e(l)),h}};const Rjo=new Set(["fuzzy","include"]);function Tjo(t){return t.startsWith("inverse")}const P7e=[{type:"exact",multiRegex:/^="(.*)"$/,singleRegex:/^=(.*)$/,create:t=>({type:"exact",search(e){const n=e===t;return{isMatch:n,score:n?0:1,indices:[0,t.length-1]}}})},{type:"include",multiRegex:/^'"(.*)"$/,singleRegex:/^'(.*)$/,create:t=>({type:"include",search(e){let n=0,o;const i=[],r=t.length;for(;(o=e.indexOf(t,n))>-1;)n=o+r,i.push([o,n-1]);const s=!!i.length;return{isMatch:s,score:s?0:1,indices:i}}})},{type:"prefix-exact",multiRegex:/^\^"(.*)"$/,singleRegex:/^\^(.*)$/,create:t=>({type:"prefix-exact",search(e){const n=e.startsWith(t);return{isMatch:n,score:n?0:1,indices:[0,t.length-1]}}})},{type:"inverse-prefix-exact",multiRegex:/^!\^"(.*)"$/,singleRegex:/^!\^(.*)$/,create:t=>({type:"inverse-prefix-exact",search(e){const n=!e.startsWith(t);return{isMatch:n,score:n?0:1,indices:[0,e.length-1]}}})},{type:"inverse-suffix-exact",multiRegex:/^!"(.*)"\$$/,singleRegex:/^!(.*)\$$/,create:t=>({type:"inverse-suffix-exact",search(e){const n=!e.endsWith(t);return{isMatch:n,score:n?0:1,indices:[0,e.length-1]}}})},{type:"suffix-exact",multiRegex:/^"(.*)"\$$/,singleRegex:/^(.*)\$$/,create:t=>({type:"suffix-exact",search(e){const n=e.endsWith(t);return{isMatch:n,score:n?0:1,indices:[e.length-t.length,e.length-1]}}})},{type:"inverse-exact",multiRegex:/^!"(.*)"$/,singleRegex:/^!(.*)$/,create:t=>({type:"inverse-exact",search(e){const n=e.indexOf(t)===-1;return{isMatch:n,score:n?0:1,indices:[0,e.length-1]}}})},{type:"fuzzy",multiRegex:/^"(.*)"$/,singleRegex:/^(.*)$/,create:(t,e={})=>{const n=new v7e(t,{location:e.location??Ts.location,threshold:e.threshold??Ts.threshold,distance:e.distance??Ts.distance,includeMatches:e.includeMatches??Ts.includeMatches,findAllMatches:e.findAllMatches??Ts.findAllMatches,minMatchCharLength:e.minMatchCharLength??Ts.minMatchCharLength,isCaseSensitive:e.isCaseSensitive??Ts.isCaseSensitive,ignoreDiacritics:e.ignoreDiacritics??Ts.ignoreDiacritics,ignoreLocation:e.ignoreLocation??Ts.ignoreLocation});return{type:"fuzzy",search(o){return n.searchIn(o)}}}}],zGt=P7e.length,kjo="\0",Fjo="|";function Ljo(t){const e=[],n=t.length;let o=0;for(;o<n;){for(;o<n&&t[o]===" ";)o++;if(o>=n)break;let i=o;for(;i<n&&t[i]!==" "&&t[i]!=='"';)i++;if(i<n&&t[i]==='"'){for(i++;i<n;){if(t[i]==='"'){const r=i+1;if(r>=n||t[r]===" "){i++;break}if(t[r]==="$"&&(r+1>=n||t[r+1]===" ")){i+=2;break}}i++}e.push(t.substring(o,i)),o=i}else{for(;i<n&&t[i]!==" ";)i++;e.push(t.substring(o,i)),o=i}}return e}function VGt(t,e){const n=t.match(e);return n?n[1]:null}function Hjo(t,e={}){return t.replace(/\\\|/g,kjo).split(Fjo).map(n=>{const o=Ljo(n.replace(/\u0000/g,"|").trim()).filter(r=>r&&!!r.trim()),i=[];for(let r=0,s=o.length;r<s;r+=1){const a=o[r];let A=!1,c=-1;for(;!A&&++c<zGt;){const l=P7e[c],g=VGt(a,l.multiRegex);g&&(i.push(l.create(g,e)),A=!0)}if(!A)for(c=-1;++c<zGt;){const l=P7e[c],g=VGt(a,l.singleRegex);if(g){i.push(l.create(g,e));break}}}return i})}var Gjo=class{constructor(t,{isCaseSensitive:e=Ts.isCaseSensitive,ignoreDiacritics:n=Ts.ignoreDiacritics,includeMatches:o=Ts.includeMatches,minMatchCharLength:i=Ts.minMatchCharLength,ignoreLocation:r=Ts.ignoreLocation,findAllMatches:s=Ts.findAllMatches,location:a=Ts.location,threshold:A=Ts.threshold,distance:c=Ts.distance}={}){this.query=null,this.options={isCaseSensitive:e,ignoreDiacritics:n,includeMatches:o,minMatchCharLength:i,findAllMatches:s,ignoreLocation:r,location:a,threshold:A,distance:c},t=e?t:t.toLowerCase(),t=n?JY(t):t,this.pattern=t,this.query=Hjo(this.pattern,this.options)}static condition(t,e){return e.useExtendedSearch}searchIn(t){const e=this.query;if(!e)return{isMatch:!1,score:1};const{includeMatches:n,isCaseSensitive:o,ignoreDiacritics:i}=this.options;t=o?t:t.toLowerCase(),t=i?JY(t):t;let r=0;const s=[];let a=0,A=!1;for(let c=0,l=e.length;c<l;c+=1){const g=e[c];s.length=0,r=0,A=!1;for(let u=0,h=g.length;u<h;u+=1){const d=g[u],{isMatch:_,indices:m,score:p}=d.search(t);if(_)r+=1,a+=p,Tjo(d.type)&&(A=!0),n&&(Rjo.has(d.type)?s.push(...m):s.push(m));else{a=0,r=0,s.length=0,A=!1;break}}if(r){const u={isMatch:!0,score:a/r};return A&&(u.hasInverse=!0),n&&(u.indices=D7e(s)),u}}return{isMatch:!1,score:1}}};const w7e=[];function M7e(...t){w7e.push(...t)}function Bae(t,e){for(let n=0,o=w7e.length;n<o;n+=1){const i=w7e[n];if(i.condition(t,e))return new i(t,e)}return new v7e(t,e)}const Qae={AND:"$and",OR:"$or"},N7e={PATH:"$path",PATTERN:"$val"},R7e=t=>!!(t[Qae.AND]||t[Qae.OR]),Ojo=t=>!!t[N7e.PATH],Kjo=t=>!iw(t)&&LGt(t)&&!R7e(t),JGt=t=>({[Qae.AND]:Object.keys(t).map(e=>({[e]:t[e]}))});function qGt(t,e,{auto:n=!0}={}){const o=i=>{if(Wf(i)){const A={keyId:null,pattern:i};return n&&(A.searcher=Bae(i,e)),A}const r=Object.keys(i),s=Ojo(i);if(!s&&r.length>1&&!R7e(i))return o(JGt(i));if(Kjo(i)){const A=s?i[N7e.PATH]:r[0],c=s?i[N7e.PATTERN]:i[A];if(!Wf(c))throw new Error(Cjo(A));const l={keyId:xae(A),pattern:c};return n&&(l.searcher=Bae(c,e)),l}const a={children:[],operator:r[0]};return r.forEach(A=>{const c=i[A];iw(c)&&c.forEach(l=>{a.children.push(o(l))})}),a};return R7e(t)||(t=JGt(t)),o(t)}function T7e(t,{ignoreFieldNorm:e=Ts.ignoreFieldNorm}){let n=1;return t.forEach(({key:o,norm:i,score:r})=>{const s=o?o.weight:null;n*=Math.pow(r===0&&s?Number.EPSILON:r,(s||1)*(e?1:i))}),n}function Ujo(t,{ignoreFieldNorm:e=Ts.ignoreFieldNorm}){t.forEach(n=>{n.score=T7e(n.matches,{ignoreFieldNorm:e})})}var Yjo=class{constructor(t,e){this.limit=t,this.heap=[],this.comparator=e}get size(){return this.heap.length}insert(t){this.size<this.limit?(this.heap.push(t),this._bubbleUp(this.size-1)):this.comparator(t,this.heap[0])<0&&(this.heap[0]=t,this._sinkDown(0))}extractSorted(){return this.heap.sort(this.comparator)}_bubbleUp(t){const e=this.heap;for(;t>0;){const n=t-1>>1;if(this.comparator(e[t],e[n])<=0)break;const o=e[t];e[t]=e[n],e[n]=o,t=n}}_sinkDown(t){const e=this.heap,n=e.length;let o=t;do{t=o;const i=2*t+1,r=2*t+2;if(i<n&&this.comparator(e[i],e[o])>0&&(o=i),r<n&&this.comparator(e[r],e[o])>0&&(o=r),o!==t){const s=e[t];e[t]=e[o],e[o]=s}}while(o!==t)}};function zjo(t){const e=[];return t.matches.forEach(n=>{if(!AE(n.indices)||!n.indices.length)return;const o={indices:n.indices,value:n.value};n.key&&(o.key=n.key.id),n.idx>-1&&(o.refIndex=n.idx),e.push(o)}),e}function Vjo(t,e,{includeMatches:n=Ts.includeMatches,includeScore:o=Ts.includeScore}={}){return t.map(i=>{const{idx:r}=i,s={item:e[r],refIndex:r};return n&&(s.matches=zjo(i)),o&&(s.score=i.score),s})}const Jjo=/[\p{L}\p{M}\p{N}_]+/gu,WGt=new WeakSet;function qjo(t){WGt.has(t)||(WGt.add(t),console.warn(`[Fuse] tokenize regex ${t} lacks the global flag; only the first match per text will be returned. Add the 'g' flag.`))}function Wjo(t){if(typeof t=="function"){let e=!1;return n=>{const o=t(n);if(!e&&(e=!0,!Array.isArray(o)||o.some(i=>typeof i!="string")))throw new Error(`[Fuse] tokenize function must return string[]; received ${Array.isArray(o)?"array containing non-strings":typeof o}.`);return o}}return t instanceof RegExp?(t.global||qjo(t),e=>e.match(t)||[]):e=>e.match(Jjo)||[]}function k7e({isCaseSensitive:t=!1,ignoreDiacritics:e=!1,tokenize:n}={}){const o=Wjo(n);return{tokenize(i){return t||(i=i.toLowerCase()),e&&(i=JY(i)),o(i)}}}var jjo=class{static condition(t,e){return e.useTokenSearch}constructor(t,e){this.options=e,this.analyzer=k7e({isCaseSensitive:e.isCaseSensitive,ignoreDiacritics:e.ignoreDiacritics,tokenize:e.tokenize});const n=this.analyzer.tokenize(t),{df:o,fieldCount:i}=e._invertedIndex;this.termSearchers=[],this.idfWeights=[];for(const r of n){this.termSearchers.push(new v7e(r,{location:e.location,threshold:e.threshold,distance:e.distance,includeMatches:e.includeMatches,findAllMatches:e.findAllMatches,minMatchCharLength:e.minMatchCharLength,isCaseSensitive:e.isCaseSensitive,ignoreDiacritics:e.ignoreDiacritics,ignoreLocation:!0}));const s=o.get(r)||0,a=Math.log(1+(i-s+.5)/(s+.5));this.idfWeights.push(a)}this.combineAll=e.tokenMatch==="all",this.numTerms=this.termSearchers.length,this.useMask=this.numTerms<=31}searchIn(t){if(!this.termSearchers.length)return{isMatch:!1,score:1};const e=[];let n=0,o=0,i=0,r=0;const s=this.combineAll&&!this.useMask?new Set:null;for(let c=0;c<this.termSearchers.length;c++){const l=this.termSearchers[c].searchIn(t),g=this.idfWeights[c];o+=g,l.isMatch&&(i++,n+=g*(1-l.score),l.indices&&e.push(...l.indices),this.combineAll&&(this.useMask?r|=1<<c:s.add(c)))}if(i===0)return{isMatch:!1,score:1};const a=o>0?1-n/o:0,A={isMatch:!0,score:Math.max(.001,a)};return this.options.includeMatches&&e.length&&(A.indices=D7e(e)),this.combineAll&&(this.useMask?A.matchedMask=r:A.matchedTerms=s,A.termCount=this.numTerms),A}};function F7e(t,e,n,o){const i=o.tokenize(e);if(!i.length)return;t.fieldCount++,t.docFieldCount.set(n,(t.docFieldCount.get(n)||0)+1);const r=new Set(i);let s=t.docTermFieldHits.get(n);s||(s=new Map,t.docTermFieldHits.set(n,s));for(const a of r)s.set(a,(s.get(a)||0)+1),t.df.set(a,(t.df.get(a)||0)+1)}function jGt(t,e,n,o){const{i,v:r,$:s}=e;if(r!==void 0){F7e(t,r,i,o);return}if(s)for(let a=0;a<n;a++){const A=s[a];if(A)if(Array.isArray(A))for(const c of A)F7e(t,c.v,i,o);else F7e(t,A.v,i,o)}}function Xjo(t,e,n){const o={fieldCount:0,df:new Map,docFieldCount:new Map,docTermFieldHits:new Map};for(const i of t)jGt(o,i,e,n);return o}function $jo(t,e,n,o){jGt(t,e,n,o)}function Zjo(t,e){const n=t.docFieldCount.get(e);if(n===void 0)return;t.fieldCount-=n,t.docFieldCount.delete(e);const o=t.docTermFieldHits.get(e);if(o){for(const[i,r]of o){const s=(t.df.get(i)||0)-r;s<=0?t.df.delete(i):t.df.set(i,s)}t.docTermFieldHits.delete(e)}}function XGt(t,e){if(e.length===0)return;const n=Array.from(new Set(e)).sort((a,A)=>a-A);for(const a of n)Zjo(t,a);const o=a=>{let A=0,c=n.length;for(;A<c;){const l=A+c>>>1;n[l]<a?A=l+1:c=l}return a-A},i=n[0],r=new Map;for(const[a,A]of t.docFieldCount)r.set(a>i?o(a):a,A);t.docFieldCount=r;const s=new Map;for(const[a,A]of t.docTermFieldHits)s.set(a>i?o(a):a,A);t.docTermFieldHits=s}var rw=class{constructor(t,e,n){this.options={...Ts,...e},this.options.useExtendedSearch,this.options.useTokenSearch,this._keyStore=new Qjo(this.options.keys),this._docs=t,this._myIndex=null,this._invertedIndex=null,this.setCollection(t,n),this._lastQuery=null,this._lastSearcher=null}_getSearcher(t){if(this._lastQuery===t)return this._lastSearcher;const e=Bae(t,this._invertedIndex?{...this.options,_invertedIndex:this._invertedIndex}:this.options);return this._lastQuery=t,this._lastSearcher=e,e}setCollection(t,e){if(this._docs=t,e&&!(e instanceof b7e))throw new Error(fjo);if(this._myIndex=e||UGt(this.options.keys,this._docs,{getFn:this.options.getFn,fieldNormWeight:this.options.fieldNormWeight}),this.options.useTokenSearch){const n=k7e({isCaseSensitive:this.options.isCaseSensitive,ignoreDiacritics:this.options.ignoreDiacritics,tokenize:this.options.tokenize});this._invertedIndex=Xjo(this._myIndex.records,this._myIndex.keys.length,n)}this._invalidateSearcherCache()}add(t){if(!AE(t))return;this._docs.push(t);const e=this._myIndex.add(t,this._docs.length-1);if(this._invertedIndex&&e){const n=k7e({isCaseSensitive:this.options.isCaseSensitive,ignoreDiacritics:this.options.ignoreDiacritics,tokenize:this.options.tokenize});$jo(this._invertedIndex,e,this._myIndex.keys.length,n)}this._invalidateSearcherCache()}remove(t=()=>!1){const e=[],n=[];for(let o=0,i=this._docs.length;o<i;o+=1)t(this._docs[o],o)&&(e.push(this._docs[o]),n.push(o));if(n.length){this._invertedIndex&&XGt(this._invertedIndex,n);const o=new Set(n);this._docs=this._docs.filter((i,r)=>!o.has(r)),this._myIndex.removeAll(n),this._invalidateSearcherCache()}return e}removeAt(t){if(!Number.isInteger(t)||t<0||t>=this._docs.length)throw new Error(S7e);this._invertedIndex&&XGt(this._invertedIndex,[t]);const e=this._docs.splice(t,1)[0];return this._myIndex.removeAt(t),this._invalidateSearcherCache(),e}_invalidateSearcherCache(){this._lastQuery=null,this._lastSearcher=null}getIndex(){return this._myIndex}_normalizedKeys(){return this._myIndex.keys.map(t=>this._keyStore.get(t.id)||t)}search(t,e){const{limit:n=-1}=e||{},{includeMatches:o,includeScore:i,shouldSort:r,sortFn:s,ignoreFieldNorm:a}=this.options;if(Wf(t)&&!t.trim()){let u=this._docs.map((h,d)=>({item:h,refIndex:d}));return yae(n)&&n>-1&&(u=u.slice(0,n)),u}const A=r&&yae(n)&&n>0&&Wf(t),c=s,l=(u,h)=>c(u,h)||u.idx-h.idx;let g;if(A){const u=new Yjo(n,l);Wf(this._docs[0])?this._searchStringList(t,{heap:u,ignoreFieldNorm:a}):this._searchObjectList(t,{heap:u,ignoreFieldNorm:a}),g=u.extractSorted()}else g=Wf(t)?Wf(this._docs[0])?this._searchStringList(t):this._searchObjectList(t):this._searchLogical(t),Ujo(g,{ignoreFieldNorm:a}),r&&g.sort(Wf(t)?l:c),yae(n)&&n>-1&&(g=g.slice(0,n));return Vjo(g,this._docs,{includeMatches:o,includeScore:i})}_searchStringList(t,{heap:e,ignoreFieldNorm:n}={}){const o=this._getSearcher(t),i=this.options.useTokenSearch&&this.options.tokenMatch==="all",{records:r}=this._myIndex,s=e?null:[];return r.forEach(({v:a,i:A,n:c})=>{if(!AE(a))return;const l=o.searchIn(a);if(l.isMatch){const g={score:l.score,value:a,norm:c,indices:l.indices};i&&(g.matchedMask=l.matchedMask,g.matchedTerms=l.matchedTerms,g.termCount=l.termCount);const u=[g];if(!i||this._coversAllTokens(u)){const h={item:a,idx:A,matches:u};e?(h.score=T7e(h.matches,{ignoreFieldNorm:n}),e.insert(h)):s.push(h)}}}),s}_searchLogical(t){const e=qGt(t,this.options),n=this._normalizedKeys(),o=(a,A,c)=>{if(!("children"in a)){const{keyId:h,searcher:d}=a;let _;return h===null?(_=[],n.forEach((m,p)=>{_.push(...this._findMatches({key:m,value:A[p],searcher:d}))})):_=this._findMatches({key:this._keyStore.get(h),value:this._myIndex.getValueForItemAtKeyId(A,h),searcher:d}),_&&_.length?[{idx:c,item:A,matches:_}]:[]}const{children:l,operator:g}=a,u=[];for(let h=0,d=l.length;h<d;h+=1){const _=l[h],m=o(_,A,c);if(m.length)u.push(...m);else if(g===Qae.AND)return[]}return u},i=this._myIndex.records,r=new Map,s=[];return i.forEach(({$:a,i:A})=>{if(AE(a)){const c=o(e,a,A);c.length&&(r.has(A)||(r.set(A,{idx:A,item:a,matches:[]}),s.push(r.get(A))),c.forEach(({matches:l})=>{r.get(A).matches.push(...l)}))}}),s}_searchObjectList(t,{heap:e,ignoreFieldNorm:n}={}){const o=this._getSearcher(t),i=this.options.useTokenSearch&&this.options.tokenMatch==="all",{records:r}=this._myIndex,s=this._normalizedKeys(),a=e?null:[];return r.forEach(({$:A,i:c})=>{if(!AE(A))return;const l=[];let g=!1,u=!1;if(s.forEach((h,d)=>{const _=this._findMatches({key:h,value:A[d],searcher:o});_.length?(l.push(..._),_[0].hasInverse&&(u=!0)):g=!0}),!(u&&g)&&l.length&&(!i||this._coversAllTokens(l))){const h={idx:c,item:A,matches:l};e?(h.score=T7e(h.matches,{ignoreFieldNorm:n}),e.insert(h)):a.push(h)}}),a}_findMatches({key:t,value:e,searcher:n}){if(!AE(e))return[];const o=[];if(iw(e))e.forEach(({v:i,i:r,n:s})=>{if(!AE(i))return;const a=n.searchIn(i);if(a.isMatch){const A={score:a.score,key:t,value:i,idx:r,norm:s,indices:a.indices,hasInverse:a.hasInverse};a.termCount!==void 0&&(A.matchedMask=a.matchedMask,A.matchedTerms=a.matchedTerms,A.termCount=a.termCount),o.push(A)}});else{const{v:i,n:r}=e,s=n.searchIn(i);if(s.isMatch){const a={score:s.score,key:t,value:i,norm:r,indices:s.indices,hasInverse:s.hasInverse};s.termCount!==void 0&&(a.matchedMask=s.matchedMask,a.matchedTerms=s.matchedTerms,a.termCount=s.termCount),o.push(a)}}return o}_coversAllTokens(t){const e=t.length?t[0].termCount:void 0;if(e===void 0)return!0;if(e<=31){let o=0;for(let i=0;i<t.length;i++)o|=t[i].matchedMask||0;return o===2**e-1}const n=new Set;for(let o=0;o<t.length;o++){const i=t[o].matchedTerms;if(i)for(const r of i)n.add(r)}return n.size===e}};rw.version="7.5.0",rw.createIndex=UGt,rw.parseIndex=vjo,rw.config=Ts,rw.match=function(t,e,n){if(n&&n.useTokenSearch)throw new Error(Bjo);return Bae(t,{...Ts,...n}).searchIn(e)},rw.parseQuery=qGt,M7e(Gjo),M7e(jjo),rw.use=function(...t){t.forEach(e=>M7e(e))};var eXo=rw;const tXo="https://kicad-mod-cache.tscircuit.com";let L7e=null,qY=null,H7e=null;const nXo=async()=>L7e||qY||(qY=fetch("https://kicad-mod-cache.tscircuit.com/kicad_files.json").then(t=>t.json()).then(t=>(L7e=t,qY=null,t)),qY),oXo=async(t,e=20)=>{const n=await nXo();return H7e||(H7e=new eXo(n)),H7e.search(t).slice(0,e).map(o=>o.item)},iXo=t=>{const e=t.replace(".pretty/","/").replace(".kicad_mod",""),n=`kicad:${e}`;return{path:t,qualifiedName:n,description:e}},rXo=t=>t.replace(/^\/+/,"").split("/").map(e=>encodeURIComponent(e)).join("/"),sXo=async t=>{const e=await fetch(`${tXo}/${rXo(t)}`);if(!e.ok)throw new Error(`KiCad footprint fetch failed: ${e.status}`);const n=await e.text(),{KicadFootprintToCircuitJsonConverter:o}=await oE("kicad-to-circuit-json"),i=new o;return i.addFile(t.split("/").pop()??"selected-footprint.kicad_mod",n),i.runUntilFinished(),i.getOutput()},$Gt=t=>t?.source==="jlcpcb"||t?.source==="kicad",aXo=async(t,e)=>{if(t.source==="jlcpcb")return _jo(t.component.partNumber,e?.jlcpcb);if(t.source==="kicad")return sXo(t.footprint.path);throw new Error("Footprint preview is not available for this source")},AXo=({query:t,placeholder:e,isSearching:n,onQueryChange:o,onSubmit:i})=>{const r=X.useCallback(s=>{s.key==="Enter"&&(s.preventDefault(),i())},[i]);return z.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2 rf-mt-4",children:[z.jsxs("div",{className:"rf-relative rf-flex-grow",children:[z.jsx(t8e,{className:"rf-absolute rf-left-2 rf-top-2.5 rf-h-4 rf-w-4 rf-text-muted-foreground"}),z.jsx(z8e,{placeholder:e,className:"rf-pl-8",spellCheck:!1,autoComplete:"off",value:t,onChange:s=>o(s.target.value),onKeyDown:r})]}),z.jsx(fa,{onClick:i,disabled:n||t.trim().length<1,className:"sm:rf-px-4 rf-px-3",children:n?z.jsx(Rx,{className:"rf-h-4 rf-w-4 rf-animate-spin"}):z.jsxs(z.Fragment,{children:[z.jsx(t8e,{className:"rf-h-4 rf-w-4 sm:rf-hidden"}),z.jsx("span",{className:"rf-hidden sm:rf-inline",children:"Search"})]})})]})},cXo=new Intl.NumberFormat("en-US",{style:"currency",currency:"USD"}),lXo=t=>cXo.format(t),ZGt=t=>{switch(t.source){case"tscircuit.com":{const e=t.package;return`tscircuit-${e.package_id??`${e.org_owner_tscircuit_handle??"unknown"}-${e.unscoped_name??e.name??"package"}`}`}case"jlcpcb":return`jlc-${t.component.lcscId}`;case"kicad":return`kicad-${t.footprint.path}`;default:return"unknown"}},gXo=t=>{switch(t.source){case"tscircuit.com":return t.package.unscoped_name;case"jlcpcb":return t.component.isDirectLookup?t.component.partNumber:t.component.manufacturer;case"kicad":return t.footprint.qualifiedName}},uXo=t=>{switch(t.source){case"tscircuit.com":return t.package.description||(t.package.org_owner_tscircuit_handle?`Component by ${t.package.org_owner_tscircuit_handle}`:void 0);case"jlcpcb":return t.component.description;case"kicad":return t.footprint.description}},dXo=t=>{switch(t.source){case"tscircuit.com":return t.package.name;case"jlcpcb":return t.component.isDirectLookup?void 0:t.component.partNumber;case"kicad":return}},hXo=({results:t,selected:e,onSelect:n,onShowDetails:o})=>{const i=e?ZGt(e):null;return z.jsx("div",{className:"rf-divide-y rf-w-full rf-overflow-hidden",children:t.map(r=>{const s=ZGt(r),a=i===s,A=gXo(r),c=uXo(r),l=dXo(r),g=r.source==="jlcpcb"?r.component.stock:null,u=r.source==="jlcpcb"?r.component.price:null,h=r.source==="jlcpcb"?r.component.isBasic:null,d=r.source==="jlcpcb"?r.component.isDirectLookup:!1;return z.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:()=>n(r),children:[z.jsxs("div",{className:"rf-min-w-0 rf-overflow-hidden rf-w-full",children:[z.jsxs("div",{className:"rf-flex rf-items-start rf-gap-2 rf-min-w-0",children:[z.jsxs("div",{className:"rf-font-medium rf-text-sm rf-truncate rf-flex-1 rf-min-w-0 rf-flex rf-items-center rf-gap-1.5",children:[A,r.source==="jlcpcb"&&h!=null&&z.jsx("span",{className:`rf-text-xs rf-px-1.5 rf-py-0.5 rf-rounded rf-font-medium rf-flex-shrink-0 ${h?"rf-bg-green-100 rf-text-green-700":"rf-bg-orange-100 rf-text-orange-700"}`,children:h?"Basic":"Extended"}),d&&z.jsx("span",{className:"rf-text-xs rf-px-1.5 rf-py-0.5 rf-rounded rf-font-medium rf-flex-shrink-0 rf-bg-blue-100 rf-text-blue-700",children:"Direct lookup"}),r.source==="tscircuit.com"&&r.package.is_private&&z.jsx(oLo,{className:"rf-ml-1 rf-h-3 rf-w-3 rf-text-zinc-400 rf-flex-shrink-0"})]}),r.source==="jlcpcb"&&g!=null?z.jsxs("div",{className:"rf-text-xs rf-text-zinc-500 rf-font-medium rf-whitespace-nowrap rf-flex-shrink-0 sm:rf-hidden",children:[g.toLocaleString()," in stock"]}):null]}),z.jsxs("div",{className:"rf-text-xs rf-text-zinc-500 rf-truncate rf-w-full",children:[l?z.jsx("span",{className:"rf-mr-2",children:l}):null,c]})]}),z.jsxs("div",{children:[r.source==="tscircuit.com"&&o?z.jsx("div",{className:"rf-flex-shrink-0 rf-w-full sm:rf-w-auto",children:z.jsx(fa,{variant:"outline",size:"sm",className:"rf-text-xs rf-w-full sm:rf-w-auto",onClick:_=>{_.stopPropagation(),o(r)},children:"See Details"})}):r.source==="jlcpcb"&&g!=null?z.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:[g.toLocaleString()," in stock"]}):null,u!=null&&z.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:lXo(u)})]})]},s)})})},_Xo=({circuitJson:t,error:e,isLoading:n,height:o})=>z.jsx("section",{className:"rf-flex rf-min-w-0 rf-items-center rf-justify-center",style:{height:o},children:n?z.jsxs("div",{className:"rf-flex rf-w-full rf-items-center rf-justify-center rf-gap-2 rf-bg-zinc-950 rf-text-sm rf-text-zinc-300",style:{height:o},children:[z.jsx(Rx,{className:"rf-h-4 rf-w-4 rf-animate-spin"}),"Loading preview..."]}):e?z.jsx("div",{className:"rf-flex rf-w-full rf-items-center rf-justify-center rf-bg-zinc-950 rf-p-4",style:{height:o},children:z.jsxs("div",{className:"rf-flex rf-max-w-[320px] rf-items-start rf-gap-2 rf-text-sm rf-text-zinc-300",children:[z.jsx(uNt,{className:"rf-mt-0.5 rf-h-4 rf-w-4 rf-flex-shrink-0"}),z.jsx("span",{children:e})]})}):t?z.jsx("div",{className:"rf-w-full rf-min-w-0 rf-overflow-hidden",children:z.jsx(aGt,{circuitJson:t,height:o,allowEditing:!1,clickToInteractEnabled:!1,focusOnHover:!1,disablePcbGroups:!0})}):z.jsx("div",{className:"rf-flex rf-w-full rf-items-center rf-justify-center rf-bg-zinc-950 rf-text-sm rf-text-zinc-300",style:{height:o},children:"No preview"})}),eOt={importComponentDialog:101,importComponentDetailsDialog:102},mXo=({packageResult:t,isOpen:e,onOpenChange:n,isLoading:o,details:i,previewTab:r,onPreviewTabChange:s,isSubmitting:a,onImport:A})=>{const c=t?.package??null,l=c?.latest_pcb_preview_image_url,g=c?.latest_sch_preview_image_url,u=c?.latest_cad_preview_image_url,h=c?.unscoped_name?.split("/").pop()??c?.unscoped_name,d=c?.org_owner_tscircuit_handle??void 0,_=d?`https://tscircuit.com/${d}`:void 0,m=d&&h?`https://tscircuit.com/${d}/${h}`:void 0;return z.jsx(X6,{open:e,onOpenChange:n,children:z.jsxs(tw,{showOverlay:!1,style:{width:"calc(100vw - 2rem)",zIndex:eOt.importComponentDetailsDialog},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:[z.jsx(nw,{className:"rf-pb-4 rf-border-b",children:z.jsx("div",{className:"rf-flex rf-items-start rf-justify-between rf-gap-4",children:z.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[z.jsx(ow,{className:"rf-text-xl rf-font-semibold rf-truncate",children:h}),z.jsx($6,{children:c?.description})]})})}),z.jsxs("div",{className:"rf-flex-1 rf-overflow-y-auto rf-py-4 rf-space-y-6",children:[d?z.jsxs("div",{children:[z.jsx("span",{className:"rf-text-xs rf-font-medium rf-text-gray-500 rf-uppercase rf-tracking-wide",children:"Created by"}),z.jsx("div",{className:"rf-mt-1 rf-text-sm rf-font-medium",children:_?z.jsx("a",{href:_,target:"_blank",rel:"noopener noreferrer",className:"rf-text-black hover:rf-underline",children:d}):d})]}):null,(u||l||g)&&z.jsx(z.Fragment,{children:z.jsxs("div",{children:[z.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-mb-4",children:"Preview"}),z.jsxs(Nxe,{value:r,onValueChange:p=>s(p),children:[z.jsxs(Tne,{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:[l&&z.jsx(HS,{value:"pcb",children:"PCB"}),g&&z.jsx(HS,{value:"schematic",children:"Schematic"}),u&&z.jsx(HS,{value:"3d",children:"3D"})]}),z.jsxs("div",{className:"rf-mt-4",children:[z.jsx(Kf,{value:"pcb",className:"rf-border rf-rounded-lg rf-overflow-hidden rf-bg-gray-50",children:l?z.jsx("img",{src:l,alt:`${h??"package"} PCB preview`,className:"rf-w-full rf-h-full rf-object-contain rf-bg-white rf-p-4"}):null}),z.jsx(Kf,{value:"schematic",className:"rf-border rf-rounded-lg rf-overflow-hidden rf-bg-gray-50",children:g?z.jsx("img",{src:g,alt:`${h??"package"} schematic preview`,className:"rf-w-full rf-h-full rf-object-contain rf-bg-white rf-p-4"}):null}),z.jsx(Kf,{value:"3d",className:"rf-border rf-rounded-lg rf-overflow-hidden rf-bg-gray-50",children:u?z.jsx("img",{src:u,alt:`${h??"package"} 3D preview`,className:"rf-w-full rf-h-full rf-object-contain rf-bg-white rf-p-4"}):null})]})]})]})}),i?.ai_description?z.jsxs("section",{children:[z.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-mb-3",children:"AI Description"}),z.jsx("div",{className:"rf-bg-gray-50 rf-border rf-border-gray-200 rf-rounded-lg rf-p-4",children:z.jsx("p",{className:"rf-text-sm rf-text-gray-700 rf-leading-relaxed",children:i.ai_description})})]}):null,i?.ai_usage_instructions?z.jsxs("section",{children:[z.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-mb-3",children:"Usage Instructions"}),z.jsx("div",{className:"rf-bg-gray-50 rf-border rf-border-gray-200 rf-rounded-lg rf-p-4",children:z.jsx("p",{className:"rf-text-sm rf-text-gray-700 rf-leading-relaxed rf-whitespace-pre-wrap",children:i.ai_usage_instructions})})]}):null,o?z.jsxs("div",{className:"rf-flex rf-justify-center rf-items-center rf-gap-2 rf-text-gray-500",children:[z.jsx(Rx,{className:"rf-h-4 rf-w-4 rf-animate-spin"}),z.jsx("span",{className:"rf-text-sm",children:"Loading package details..."})]}):null]}),z.jsxs(Kk,{className:"rf-pt-4 rf-border-t rf-flex rf-flex-col sm:rf-flex-row rf-justify-between rf-gap-2",children:[z.jsx("div",{className:"rf-flex-1",children:m?z.jsxs(fa,{variant:"outline",size:"sm",className:"rf-gap-2 rf-w-full sm:rf-w-auto",onClick:()=>window.open(m,"_blank"),children:[z.jsx(jFo,{className:"rf-h-4 rf-w-4"}),"View on tscircuit.com"]}):null}),z.jsxs("div",{className:"rf-flex rf-flex-col sm:rf-flex-row rf-gap-2",children:[z.jsx(fa,{variant:"outline",onClick:()=>n(!1),className:"rf-order-2 sm:rf-order-1",children:"Close"}),z.jsx(fa,{onClick:A,disabled:a,className:"rf-bg-blue-600 hover:rf-bg-blue-700",children:a?z.jsx(Rx,{className:"rf-h-4 rf-w-4 rf-animate-spin"}):"Import Component"})]})]})]})})},pXo=()=>{const[t,e]=X.useState(null),[n,o]=X.useState(!1),i=X.useCallback(async(s,a)=>{o(!0);try{const A=await fetch(`https://api.tscircuit.com/packages/get?name=${encodeURIComponent(`${s}/${a}`)}`);if(!A.ok)throw new Error(`Failed to load package details: ${A.status}`);const c=await A.json();e(c.package??null)}catch(A){console.error("Failed to fetch package details",A),e(null)}finally{o(!1)}},[]),r=X.useCallback(()=>{e(null),o(!1)},[]);return{details:t,isLoading:n,fetchDetails:i,reset:r}},IXo=(t,e)=>{const[n,o]=X.useState({circuitJson:null,error:null,isLoading:!1});return X.useEffect(()=>{if(!t||!$Gt(t)){o({circuitJson:null,error:null,isLoading:!1});return}let i=!1;return o({circuitJson:null,error:null,isLoading:!0}),aXo(t,e).then(r=>{i||o({circuitJson:r,error:null,isLoading:!1})}).catch(r=>{i||o({circuitJson:null,error:r instanceof Error?r.message:"Failed to load footprint preview",isLoading:!1})}),()=>{i=!0}},[t,e]),n},fXo=async(t,e)=>{const n={"Content-Type":"application/json"};e&&(n.Authorization=`Bearer ${e}`);const o=await fetch("https://registry-api.tscircuit.com/packages/search",{method:"POST",headers:n,body:JSON.stringify({query:t})});if(!o.ok)throw new Error(`tscircuit registry error: ${o.status}`);return(await o.json()).packages??[]},CXo=({sessionToken:t})=>{const[e,n]=X.useState([]),[o,i]=X.useState(!1),[r,s]=X.useState(null),[a,A]=X.useState(!1),c=X.useCallback(async g=>{const u=g.trim();if(!u)return[];i(!0),s(null);try{const d=(await fXo(u,t)).map(_=>({source:"tscircuit.com",package:_}));return n(d),d}catch(h){return console.error("Error searching tscircuit packages",h),n([]),s(h instanceof Error?h.message:"Failed to search tscircuit packages"),[]}finally{i(!1),A(!0)}},[t]),l=X.useCallback(()=>{n([]),i(!1),s(null),A(!1)},[]);return{results:e,isSearching:o,error:r,hasSearched:a,search:c,reset:l}},yXo=t=>{const e=/^C(\d+)$/i.exec(t.trim());if(!e)return null;const n=Number(e[1]);if(!Number.isSafeInteger(n))return null;const o=`C${e[1]}`;return{source:"jlcpcb",component:{lcscId:n,manufacturer:o,partNumber:o,description:"Import directly from EasyEDA; stock and availability are unknown",package:"",isDirectLookup:!0}}},tOt=(t,e)=>{const n=yXo(t);return n?e.some(i=>i.component.partNumber.toUpperCase()===n.component.partNumber)?e:[n,...e]:e},EXo=t=>{const e=t.trim();return/^C\d+/i.test(e)?e.replace(/^C/i,""):e},xXo=()=>{const[t,e]=X.useState([]),[n,o]=X.useState(!1),[i,r]=X.useState(null),[s,a]=X.useState(!1),A=X.useCallback(async l=>{const g=EXo(l);if(!g)return[];o(!0),r(null);try{const u=await ujo(g,10),h=tOt(l,u.map(d=>({source:"jlcpcb",component:djo(d)})));return e(h),h}catch(u){console.error("Error searching JLCPCB components",u);const h=tOt(l,[]);return e(h),r(h.length>0?null:u instanceof Error?u.message:"Failed to search JLCPCB components"),h}finally{o(!1),a(!0)}},[]),c=X.useCallback(()=>{e([]),o(!1),r(null),a(!1)},[]);return{results:t,isSearching:n,error:i,hasSearched:s,search:A,reset:c}},BXo=()=>{const[t,e]=X.useState([]),[n,o]=X.useState(!1),[i,r]=X.useState(null),[s,a]=X.useState(!1),A=X.useCallback(async l=>{const g=l.trim();if(!g)return[];o(!0),r(null);try{const h=(await oXo(g,20)).map(d=>({source:"kicad",footprint:iXo(d)}));return e(h),h}catch(u){return console.error("Error searching KiCad footprints",u),e([]),r(u instanceof Error?u.message:"Failed to search KiCad footprints"),[]}finally{o(!1),a(!0)}},[]),c=X.useCallback(()=>{e([]),o(!1),r(null),a(!1)},[]);return{results:t,isSearching:n,error:i,hasSearched:s,search:A,reset:c}},QXo=({onTscircuitPackageSelected:t,onJlcpcbComponentTsxLoaded:e,onKicadStringSelected:n})=>{const o=[];return t&&o.push("tscircuit.com"),e&&o.push("jlcpcb"),n&&o.push("kicad"),o},SXo=({isOpen:t,onClose:e,jlcpcbProxyRequestHeaders:n,onKicadStringSelected:o,onTscircuitPackageSelected:i,onJlcpcbComponentTsxLoaded:r,jlcpcbProxyApiBase:s,tscircuitSessionToken:a})=>{UY();const A=X.useMemo(()=>QXo({onKicadStringSelected:o,onTscircuitPackageSelected:i,onJlcpcbComponentTsxLoaded:r}),[o,i,r]),c=A.length>0,l=A.length===1,[g,u]=X.useState(A[0]??"tscircuit.com"),[h,d]=X.useState(""),[_,m]=X.useState(null),{results:p,isSearching:I,error:f,hasSearched:C,search:y,reset:E}=CXo({sessionToken:a}),{results:B,isSearching:Q,error:b,hasSearched:D,search:R,reset:M}=xXo(),{results:L,isSearching:G,error:O,hasSearched:U,search:W,reset:j}=BXo(),{details:te,isLoading:ie,fetchDetails:$,reset:Z}=pXo(),[se,ae]=X.useState(null),[ce,fe]=X.useState(!1),[Ce,xe]=X.useState("pcb"),[de,Ee]=X.useState(null),[he,be]=X.useState(!1),Me=X.useMemo(()=>({jlcpcb:{headers:n,apiBase:s}}),[s,n]),{circuitJson:Ye,error:Ie,isLoading:We}=IXo(_,Me),Ne=$Gt(_);X.useEffect(()=>{Ee(null)},[_]);const ke=X.useCallback(()=>{E(),M(),j(),m(null)},[M,j,E]);X.useEffect(()=>{t||(ke(),d(""),fe(!1),ae(null),Ee(null))},[t,ke]),X.useEffect(()=>{d(""),m(null),g==="tscircuit.com"?E():g==="jlcpcb"?M():g==="kicad"&&j()},[g,M,j,E]);const Ve=gt=>{m(gt),ae(gt),xe("pcb"),fe(!0),Z();const nt=gt.package.org_owner_tscircuit_handle,xt=gt.package.unscoped_name;if(nt&&xt){const _t=xt.split("/").pop()??xt;$(nt,_t)}},Re=async()=>{h.trim()&&(m(null),g==="tscircuit.com"?await y(h):g==="jlcpcb"?await R(h):g==="kicad"&&await W(h))},Se=async gt=>{try{if(Ee(null),be(!0),gt.source==="kicad"){if(!o)throw new Error("KiCad handler not provided");await o({result:gt,footprint:gt.footprint.qualifiedName})}else if(gt.source==="jlcpcb"){if(!r)throw new Error("JLCPCB handler not provided");const nt=await hjo(gt.component.partNumber,{headers:n,apiBase:s});await r({result:gt,tsx:nt})}else if(gt.source==="tscircuit.com"){if(!i)throw new Error("tscircuit package handler not provided");const nt=gt.package.org_owner_tscircuit_handle,xt=gt.package.unscoped_name;if(!nt||!xt)throw new Error("Missing package metadata");const _t=xt.split("/").pop()??xt,vt=`@tsci/${nt}.${_t}`;await i({result:gt,fullPackageName:vt})}return!0}catch(nt){return console.error("Failed to import component",nt),Ee(nt instanceof Error?nt.message:"Failed to import component"),!1}finally{be(!1)}};let Oe=[],Pe=!1,qe=null,$e=!1;g==="tscircuit.com"?(Oe=p,Pe=I,qe=f,$e=C):g==="jlcpcb"?(Oe=B,Pe=Q,qe=b,$e=D):g==="kicad"&&(Oe=L,Pe=G,qe=O,$e=U);const at=async()=>{if(!_)return;await Se(_)&&(e(),ke(),d(""))},ct=gt=>{gt||e()},dt=gt=>{fe(gt),gt||ae(null)};return z.jsxs(X6,{open:t,onOpenChange:ct,children:[z.jsxs(tw,{style:{width:"calc(100vw - 2rem)",maxWidth:Ne?"min(1120px, calc(100vw - 2rem))":"min(672px, calc(100vw - 2rem))",zIndex:eOt.importComponentDialog},className:"rf-rounded-sm rf-max-h-[90vh] rf-overflow-y-auto rf-overflow-x-hidden rf-flex rf-flex-col",children:[z.jsxs(nw,{children:[z.jsxs(ow,{className:"rf-text-lg sm:rf-text-xl",children:["Import ",l?Cae[g].label:""," ","Component"]}),z.jsx($6,{className:"rf-text-sm",children:c?"Search for components from available sources.":"Import options are disabled because no handlers were provided."})]}),c?z.jsxs(Nxe,{value:g,onValueChange:gt=>u(gt),className:"rf-min-w-0 rf-w-full",children:[!l&&z.jsx(Tne,{className:"rf-flex rf-w-full rf-gap-2",children:A.map(gt=>z.jsx(HS,{value:gt,className:"rf-flex-1 rf-text-xs sm:rf-text-sm",children:Cae[gt].label},gt))}),z.jsxs("div",{className:"rf-min-w-0",style:Ne?{display:"grid",gridTemplateColumns:"minmax(0, 1fr) minmax(360px, 0.95fr)",gap:"1.5rem",alignItems:"start"}:void 0,children:[z.jsxs("div",{className:"rf-min-w-0",children:[z.jsx(AXo,{query:h,placeholder:Cae[g].placeholder,isSearching:Pe,onQueryChange:d,onSubmit:Re}),z.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:Pe?z.jsxs("div",{className:"rf-p-8 rf-text-center rf-text-zinc-500",children:[z.jsx(Rx,{className:"rf-h-8 rf-w-8 rf-animate-spin rf-mx-auto rf-mb-2"}),z.jsx("p",{children:"Searching..."})]}):Oe.length>0?z.jsx(hXo,{results:Oe,selected:_,onSelect:m,onShowDetails:g==="tscircuit.com"?Ve:void 0}):z.jsx("div",{className:"rf-p-8 rf-text-center rf-text-zinc-500",children:qe?`Error: ${qe}`:$e?Cae[g].emptyMessage:"Enter a search term to find components"})})]}),Ne?z.jsx("div",{className:"rf-mt-4",children:z.jsx(_Xo,{circuitJson:Ye,error:Ie,isLoading:We,height:325})}):null]})]}):null,de?z.jsx("div",{className:"rf-text-sm rf-text-red-600 rf-mt-2",children:de}):null,z.jsxs(Kk,{className:"rf-flex rf-flex-col sm:rf-flex-row rf-gap-2",children:[z.jsx(fa,{variant:"outline",onClick:e,className:"rf-order-2 sm:rf-order-1",children:"Cancel"}),z.jsx(fa,{onClick:at,disabled:!_||he,className:"rf-order-1 sm:rf-order-2",children:he?z.jsx(Rx,{className:"rf-h-4 rf-w-4 rf-animate-spin"}):"Import"})]})]}),z.jsx(mXo,{packageResult:se,isOpen:ce,onOpenChange:dt,isLoading:ie,details:te,previewTab:Ce,onPreviewTabChange:gt=>xe(gt),isSubmitting:he,onImport:()=>{se&&Se(se).then(gt=>{gt&&(fe(!1),e(),ke(),d(""))})}})]})},bXo=t=>{const e=t.match(/export const (\w+) =/);if(!e)throw new Error("Could not determine component name from TSX contents");return e[1]},nOt=t=>{const e=ju(s=>s.pushEvent),n=ju(s=>s.upsertFile),o=async({result:s,fullPackageName:a})=>{const c=s.package.unscoped_name??s.package.name;await Rs.promise(e({event_type:"INSTALL_PACKAGE",full_package_name:a}),{loading:`Requesting install for "${c}"`,success:`Install requested for "${c}"`,error:l=>`Failed to request install: ${l instanceof Error?l.message:String(l)}`})},i=async({footprint:s})=>{await Rs.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)}`})},r=async({result:s,tsx:a})=>{const c=`imports/${bXo(a)}.tsx`;await Rs.promise(n(c,a),{loading:`Importing ${s.component.partNumber}`,success:`Imported to "${c}"`,error:l=>`Failed to import component: ${l instanceof Error?l.message:String(l)}`})};return z.jsx(SXo,{...t,onTscircuitPackageSelected:o,onKicadStringSelected:i,onJlcpcbComponentTsxLoaded:r})};nOt.displayName="ImportComponentDialogForCli";var G7e={exports:{}},oOt;function DXo(){return oOt||(oOt=1,(function(t,e){var n={env:{},version:""};(function(o){t.exports=o()})(function(){return(function o(i,r,s){function a(l,g){if(!r[l]){if(!i[l]){var u=typeof bD=="function"&&bD;if(!g&&u)return u(l,!0);if(A)return A(l,!0);var h=new Error("Cannot find module '"+l+"'");throw h.code="MODULE_NOT_FOUND",h}var d=r[l]={exports:{}};i[l][0].call(d.exports,function(_){var m=i[l][1][_];return a(m||_)},d,d.exports,o,i,r,s)}return r[l].exports}for(var A=typeof bD=="function"&&bD,c=0;c<s.length;c++)a(s[c]);return a})({1:[function(o,i,r){var s=o("./utils"),a=o("./support"),A="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";r.encode=function(c){for(var l,g,u,h,d,_,m,p=[],I=0,f=c.length,C=f,y=s.getTypeOf(c)!=="string";I<c.length;)C=f-I,u=y?(l=c[I++],g=I<f?c[I++]:0,I<f?c[I++]:0):(l=c.charCodeAt(I++),g=I<f?c.charCodeAt(I++):0,I<f?c.charCodeAt(I++):0),h=l>>2,d=(3&l)<<4|g>>4,_=1<C?(15&g)<<2|u>>6:64,m=2<C?63&u:64,p.push(A.charAt(h)+A.charAt(d)+A.charAt(_)+A.charAt(m));return p.join("")},r.decode=function(c){var l,g,u,h,d,_,m=0,p=0,I="data:";if(c.substr(0,I.length)===I)throw new Error("Invalid base64 input, it looks like a data url.");var f,C=3*(c=c.replace(/[^A-Za-z0-9+/=]/g,"")).length/4;if(c.charAt(c.length-1)===A.charAt(64)&&C--,c.charAt(c.length-2)===A.charAt(64)&&C--,C%1!=0)throw new Error("Invalid base64 input, bad content length.");for(f=a.uint8array?new Uint8Array(0|C):new Array(0|C);m<c.length;)l=A.indexOf(c.charAt(m++))<<2|(h=A.indexOf(c.charAt(m++)))>>4,g=(15&h)<<4|(d=A.indexOf(c.charAt(m++)))>>2,u=(3&d)<<6|(_=A.indexOf(c.charAt(m++))),f[p++]=l,d!==64&&(f[p++]=g),_!==64&&(f[p++]=u);return f}},{"./support":30,"./utils":32}],2:[function(o,i,r){var s=o("./external"),a=o("./stream/DataWorker"),A=o("./stream/Crc32Probe"),c=o("./stream/DataLengthProbe");function l(g,u,h,d,_){this.compressedSize=g,this.uncompressedSize=u,this.crc32=h,this.compression=d,this.compressedContent=_}l.prototype={getContentWorker:function(){var g=new a(s.Promise.resolve(this.compressedContent)).pipe(this.compression.uncompressWorker()).pipe(new c("data_length")),u=this;return g.on("end",function(){if(this.streamInfo.data_length!==u.uncompressedSize)throw new Error("Bug : uncompressed data size mismatch")}),g},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)}},l.createWorkerFrom=function(g,u,h){return g.pipe(new A).pipe(new c("uncompressedSize")).pipe(u.compressWorker(h)).pipe(new c("compressedSize")).withStreamInfo("compression",u)},i.exports=l},{"./external":6,"./stream/Crc32Probe":25,"./stream/DataLengthProbe":26,"./stream/DataWorker":27}],3:[function(o,i,r){var s=o("./stream/GenericWorker");r.STORE={magic:"\0\0",compressWorker:function(){return new s("STORE compression")},uncompressWorker:function(){return new s("STORE decompression")}},r.DEFLATE=o("./flate")},{"./flate":7,"./stream/GenericWorker":28}],4:[function(o,i,r){var s=o("./utils"),a=(function(){for(var A,c=[],l=0;l<256;l++){A=l;for(var g=0;g<8;g++)A=1&A?3988292384^A>>>1:A>>>1;c[l]=A}return c})();i.exports=function(A,c){return A!==void 0&&A.length?s.getTypeOf(A)!=="string"?(function(l,g,u,h){var d=a,_=h+u;l^=-1;for(var m=h;m<_;m++)l=l>>>8^d[255&(l^g[m])];return-1^l})(0|c,A,A.length,0):(function(l,g,u,h){var d=a,_=h+u;l^=-1;for(var m=h;m<_;m++)l=l>>>8^d[255&(l^g.charCodeAt(m))];return-1^l})(0|c,A,A.length,0):0}},{"./utils":32}],5:[function(o,i,r){r.base64=!1,r.binary=!1,r.dir=!1,r.createFolders=!0,r.date=null,r.compression=null,r.compressionOptions=null,r.comment=null,r.unixPermissions=null,r.dosPermissions=null},{}],6:[function(o,i,r){var s=null;s=typeof Promise<"u"?Promise:o("lie"),i.exports={Promise:s}},{lie:37}],7:[function(o,i,r){var s=typeof Uint8Array<"u"&&typeof Uint16Array<"u"&&typeof Uint32Array<"u",a=o("pako"),A=o("./utils"),c=o("./stream/GenericWorker"),l=s?"uint8array":"array";function g(u,h){c.call(this,"FlateWorker/"+u),this._pako=null,this._pakoAction=u,this._pakoOptions=h,this.meta={}}r.magic="\b\0",A.inherits(g,c),g.prototype.processChunk=function(u){this.meta=u.meta,this._pako===null&&this._createPako(),this._pako.push(A.transformTo(l,u.data),!1)},g.prototype.flush=function(){c.prototype.flush.call(this),this._pako===null&&this._createPako(),this._pako.push([],!0)},g.prototype.cleanUp=function(){c.prototype.cleanUp.call(this),this._pako=null},g.prototype._createPako=function(){this._pako=new a[this._pakoAction]({raw:!0,level:this._pakoOptions.level||-1});var u=this;this._pako.onData=function(h){u.push({data:h,meta:u.meta})}},r.compressWorker=function(u){return new g("Deflate",u)},r.uncompressWorker=function(){return new g("Inflate",{})}},{"./stream/GenericWorker":28,"./utils":32,pako:38}],8:[function(o,i,r){function s(d,_){var m,p="";for(m=0;m<_;m++)p+=String.fromCharCode(255&d),d>>>=8;return p}function a(d,_,m,p,I,f){var C,y,E=d.file,B=d.compression,Q=f!==l.utf8encode,b=A.transformTo("string",f(E.name)),D=A.transformTo("string",l.utf8encode(E.name)),R=E.comment,M=A.transformTo("string",f(R)),L=A.transformTo("string",l.utf8encode(R)),G=D.length!==E.name.length,O=L.length!==R.length,U="",W="",j="",te=E.dir,ie=E.date,$={crc32:0,compressedSize:0,uncompressedSize:0};_&&!m||($.crc32=d.crc32,$.compressedSize=d.compressedSize,$.uncompressedSize=d.uncompressedSize);var Z=0;_&&(Z|=8),Q||!G&&!O||(Z|=2048);var se=0,ae=0;te&&(se|=16),I==="UNIX"?(ae=798,se|=(function(fe,Ce){var xe=fe;return fe||(xe=Ce?16893:33204),(65535&xe)<<16})(E.unixPermissions,te)):(ae=20,se|=(function(fe){return 63&(fe||0)})(E.dosPermissions)),C=ie.getUTCHours(),C<<=6,C|=ie.getUTCMinutes(),C<<=5,C|=ie.getUTCSeconds()/2,y=ie.getUTCFullYear()-1980,y<<=4,y|=ie.getUTCMonth()+1,y<<=5,y|=ie.getUTCDate(),G&&(W=s(1,1)+s(g(b),4)+D,U+="up"+s(W.length,2)+W),O&&(j=s(1,1)+s(g(M),4)+L,U+="uc"+s(j.length,2)+j);var ce="";return ce+=`
|
|
5773
5773
|
\0`,ce+=s(Z,2),ce+=B.magic,ce+=s(C,2),ce+=s(y,2),ce+=s($.crc32,4),ce+=s($.compressedSize,4),ce+=s($.uncompressedSize,4),ce+=s(b.length,2),ce+=s(U.length,2),{fileRecord:u.LOCAL_FILE_HEADER+ce+b+U,dirRecord:u.CENTRAL_FILE_HEADER+s(ae,2)+ce+s(M.length,2)+"\0\0\0\0"+s(se,4)+s(p,4)+b+U+M}}var A=o("../utils"),c=o("../stream/GenericWorker"),l=o("../utf8"),g=o("../crc32"),u=o("../signature");function h(d,_,m,p){c.call(this,"ZipFileWorker"),this.bytesWritten=0,this.zipComment=_,this.zipPlatform=m,this.encodeFileName=p,this.streamFiles=d,this.accumulate=!1,this.contentBuffer=[],this.dirRecords=[],this.currentSourceOffset=0,this.entriesCount=0,this.currentFile=null,this._sources=[]}A.inherits(h,c),h.prototype.push=function(d){var _=d.meta.percent||0,m=this.entriesCount,p=this._sources.length;this.accumulate?this.contentBuffer.push(d):(this.bytesWritten+=d.data.length,c.prototype.push.call(this,{data:d.data,meta:{currentFile:this.currentFile,percent:m?(_+100*(m-p-1))/m:100}}))},h.prototype.openedSource=function(d){this.currentSourceOffset=this.bytesWritten,this.currentFile=d.file.name;var _=this.streamFiles&&!d.file.dir;if(_){var m=a(d,_,!1,this.currentSourceOffset,this.zipPlatform,this.encodeFileName);this.push({data:m.fileRecord,meta:{percent:0}})}else this.accumulate=!0},h.prototype.closedSource=function(d){this.accumulate=!1;var _=this.streamFiles&&!d.file.dir,m=a(d,_,!0,this.currentSourceOffset,this.zipPlatform,this.encodeFileName);if(this.dirRecords.push(m.dirRecord),_)this.push({data:(function(p){return u.DATA_DESCRIPTOR+s(p.crc32,4)+s(p.compressedSize,4)+s(p.uncompressedSize,4)})(d),meta:{percent:100}});else for(this.push({data:m.fileRecord,meta:{percent:0}});this.contentBuffer.length;)this.push(this.contentBuffer.shift());this.currentFile=null},h.prototype.flush=function(){for(var d=this.bytesWritten,_=0;_<this.dirRecords.length;_++)this.push({data:this.dirRecords[_],meta:{percent:100}});var m=this.bytesWritten-d,p=(function(I,f,C,y,E){var B=A.transformTo("string",E(y));return u.CENTRAL_DIRECTORY_END+"\0\0\0\0"+s(I,2)+s(I,2)+s(f,4)+s(C,4)+s(B.length,2)+B})(this.dirRecords.length,m,d,this.zipComment,this.encodeFileName);this.push({data:p,meta:{percent:100}})},h.prototype.prepareNextSource=function(){this.previous=this._sources.shift(),this.openedSource(this.previous.streamInfo),this.isPaused?this.previous.pause():this.previous.resume()},h.prototype.registerPrevious=function(d){this._sources.push(d);var _=this;return d.on("data",function(m){_.processChunk(m)}),d.on("end",function(){_.closedSource(_.previous.streamInfo),_._sources.length?_.prepareNextSource():_.end()}),d.on("error",function(m){_.error(m)}),this},h.prototype.resume=function(){return!!c.prototype.resume.call(this)&&(!this.previous&&this._sources.length?(this.prepareNextSource(),!0):this.previous||this._sources.length||this.generatedError?void 0:(this.end(),!0))},h.prototype.error=function(d){var _=this._sources;if(!c.prototype.error.call(this,d))return!1;for(var m=0;m<_.length;m++)try{_[m].error(d)}catch{}return!0},h.prototype.lock=function(){c.prototype.lock.call(this);for(var d=this._sources,_=0;_<d.length;_++)d[_].lock()},i.exports=h},{"../crc32":4,"../signature":23,"../stream/GenericWorker":28,"../utf8":31,"../utils":32}],9:[function(o,i,r){var s=o("../compressions"),a=o("./ZipFileWorker");r.generateWorker=function(A,c,l){var g=new a(c.streamFiles,l,c.platform,c.encodeFileName),u=0;try{A.forEach(function(h,d){u++;var _=(function(f,C){var y=f||C,E=s[y];if(!E)throw new Error(y+" is not a valid compression method !");return E})(d.options.compression,c.compression),m=d.options.compressionOptions||c.compressionOptions||{},p=d.dir,I=d.date;d._compressWorker(_,m).withStreamInfo("file",{name:h,dir:p,date:I,comment:d.comment||"",unixPermissions:d.unixPermissions,dosPermissions:d.dosPermissions}).pipe(g)}),g.entriesCount=u}catch(h){g.error(h)}return g}},{"../compressions":3,"./ZipFileWorker":8}],10:[function(o,i,r){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 A in this)typeof this[A]!="function"&&(a[A]=this[A]);return a}}(s.prototype=o("./object")).loadAsync=o("./load"),s.support=o("./support"),s.defaults=o("./defaults"),s.version="3.10.1",s.loadAsync=function(a,A){return new s().loadAsync(a,A)},s.external=o("./external"),i.exports=s},{"./defaults":5,"./external":6,"./load":11,"./object":15,"./support":30}],11:[function(o,i,r){var s=o("./utils"),a=o("./external"),A=o("./utf8"),c=o("./zipEntries"),l=o("./stream/Crc32Probe"),g=o("./nodejsUtils");function u(h){return new a.Promise(function(d,_){var m=h.decompressed.getContentWorker().pipe(new l);m.on("error",function(p){_(p)}).on("end",function(){m.streamInfo.crc32!==h.decompressed.crc32?_(new Error("Corrupted zip : CRC32 mismatch")):d()}).resume()})}i.exports=function(h,d){var _=this;return d=s.extend(d||{},{base64:!1,checkCRC32:!1,optimizedBinaryString:!1,createFolders:!1,decodeFileName:A.utf8decode}),g.isNode&&g.isStream(h)?a.Promise.reject(new Error("JSZip can't accept a stream when loading a zip file.")):s.prepareContent("the loaded zip file",h,!0,d.optimizedBinaryString,d.base64).then(function(m){var p=new c(d);return p.load(m),p}).then(function(m){var p=[a.Promise.resolve(m)],I=m.files;if(d.checkCRC32)for(var f=0;f<I.length;f++)p.push(u(I[f]));return a.Promise.all(p)}).then(function(m){for(var p=m.shift(),I=p.files,f=0;f<I.length;f++){var C=I[f],y=C.fileNameStr,E=s.resolve(C.fileNameStr);_.file(E,C.decompressed,{binary:!0,optimizedBinaryString:!0,date:C.date,dir:C.dir,comment:C.fileCommentStr.length?C.fileCommentStr:null,unixPermissions:C.unixPermissions,dosPermissions:C.dosPermissions,createFolders:d.createFolders}),C.dir||(_.file(E).unsafeOriginalName=y)}return p.zipComment.length&&(_.comment=p.zipComment),_})}},{"./external":6,"./nodejsUtils":14,"./stream/Crc32Probe":25,"./utf8":31,"./utils":32,"./zipEntries":33}],12:[function(o,i,r){var s=o("../utils"),a=o("../stream/GenericWorker");function A(c,l){a.call(this,"Nodejs stream input adapter for "+c),this._upstreamEnded=!1,this._bindStream(l)}s.inherits(A,a),A.prototype._bindStream=function(c){var l=this;(this._stream=c).pause(),c.on("data",function(g){l.push({data:g,meta:{percent:0}})}).on("error",function(g){l.isPaused?this.generatedError=g:l.error(g)}).on("end",function(){l.isPaused?l._upstreamEnded=!0:l.end()})},A.prototype.pause=function(){return!!a.prototype.pause.call(this)&&(this._stream.pause(),!0)},A.prototype.resume=function(){return!!a.prototype.resume.call(this)&&(this._upstreamEnded?this.end():this._stream.resume(),!0)},i.exports=A},{"../stream/GenericWorker":28,"../utils":32}],13:[function(o,i,r){var s=o("readable-stream").Readable;function a(A,c,l){s.call(this,c),this._helper=A;var g=this;A.on("data",function(u,h){g.push(u)||g._helper.pause(),l&&l(h)}).on("error",function(u){g.emit("error",u)}).on("end",function(){g.push(null)})}o("../utils").inherits(a,s),a.prototype._read=function(){this._helper.resume()},i.exports=a},{"../utils":32,"readable-stream":16}],14:[function(o,i,r){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(o,i,r){function s(E,B,Q){var b,D=A.getTypeOf(B),R=A.extend(Q||{},g);R.date=R.date||new Date,R.compression!==null&&(R.compression=R.compression.toUpperCase()),typeof R.unixPermissions=="string"&&(R.unixPermissions=parseInt(R.unixPermissions,8)),R.unixPermissions&&16384&R.unixPermissions&&(R.dir=!0),R.dosPermissions&&16&R.dosPermissions&&(R.dir=!0),R.dir&&(E=I(E)),R.createFolders&&(b=p(E))&&f.call(this,b,!0);var M=D==="string"&&R.binary===!1&&R.base64===!1;Q&&Q.binary!==void 0||(R.binary=!M),(B instanceof u&&B.uncompressedSize===0||R.dir||!B||B.length===0)&&(R.base64=!1,R.binary=!0,B="",R.compression="STORE",D="string");var L=null;L=B instanceof u||B instanceof c?B:_.isNode&&_.isStream(B)?new m(E,B):A.prepareContent(E,B,R.binary,R.optimizedBinaryString,R.base64);var G=new h(E,L,R);this.files[E]=G}var a=o("./utf8"),A=o("./utils"),c=o("./stream/GenericWorker"),l=o("./stream/StreamHelper"),g=o("./defaults"),u=o("./compressedObject"),h=o("./zipObject"),d=o("./generate"),_=o("./nodejsUtils"),m=o("./nodejs/NodejsStreamInputAdapter"),p=function(E){E.slice(-1)==="/"&&(E=E.substring(0,E.length-1));var B=E.lastIndexOf("/");return 0<B?E.substring(0,B):""},I=function(E){return E.slice(-1)!=="/"&&(E+="/"),E},f=function(E,B){return B=B!==void 0?B:g.createFolders,E=I(E),this.files[E]||s.call(this,E,null,{dir:!0,createFolders:B}),this.files[E]};function C(E){return Object.prototype.toString.call(E)==="[object RegExp]"}var y={load:function(){throw new Error("This method has been removed in JSZip 3.0, please check the upgrade guide.")},forEach:function(E){var B,Q,b;for(B in this.files)b=this.files[B],(Q=B.slice(this.root.length,B.length))&&B.slice(0,this.root.length)===this.root&&E(Q,b)},filter:function(E){var B=[];return this.forEach(function(Q,b){E(Q,b)&&B.push(b)}),B},file:function(E,B,Q){if(arguments.length!==1)return E=this.root+E,s.call(this,E,B,Q),this;if(C(E)){var b=E;return this.filter(function(R,M){return!M.dir&&b.test(R)})}var D=this.files[this.root+E];return D&&!D.dir?D:null},folder:function(E){if(!E)return this;if(C(E))return this.filter(function(D,R){return R.dir&&E.test(D)});var B=this.root+E,Q=f.call(this,B),b=this.clone();return b.root=Q.name,b},remove:function(E){E=this.root+E;var B=this.files[E];if(B||(E.slice(-1)!=="/"&&(E+="/"),B=this.files[E]),B&&!B.dir)delete this.files[E];else for(var Q=this.filter(function(D,R){return R.name.slice(0,E.length)===E}),b=0;b<Q.length;b++)delete this.files[Q[b].name];return this},generate:function(){throw new Error("This method has been removed in JSZip 3.0, please check the upgrade guide.")},generateInternalStream:function(E){var B,Q={};try{if((Q=A.extend(E||{},{streamFiles:!1,compression:"STORE",compressionOptions:null,type:"",platform:"DOS",comment:null,mimeType:"application/zip",encodeFileName:a.utf8encode})).type=Q.type.toLowerCase(),Q.compression=Q.compression.toUpperCase(),Q.type==="binarystring"&&(Q.type="string"),!Q.type)throw new Error("No output type specified.");A.checkSupport(Q.type),Q.platform!=="darwin"&&Q.platform!=="freebsd"&&Q.platform!=="linux"&&Q.platform!=="sunos"||(Q.platform="UNIX"),Q.platform==="win32"&&(Q.platform="DOS");var b=Q.comment||this.comment||"";B=d.generateWorker(this,Q,b)}catch(D){(B=new c("error")).error(D)}return new l(B,Q.type||"string",Q.mimeType)},generateAsync:function(E,B){return this.generateInternalStream(E).accumulate(B)},generateNodeStream:function(E,B){return(E=E||{}).type||(E.type="nodebuffer"),this.generateInternalStream(E).toNodejsStream(B)}};i.exports=y},{"./compressedObject":2,"./defaults":5,"./generate":9,"./nodejs/NodejsStreamInputAdapter":12,"./nodejsUtils":14,"./stream/GenericWorker":28,"./stream/StreamHelper":29,"./utf8":31,"./utils":32,"./zipObject":35}],16:[function(o,i,r){i.exports=o("stream")},{stream:void 0}],17:[function(o,i,r){var s=o("./DataReader");function a(A){s.call(this,A);for(var c=0;c<this.data.length;c++)A[c]=255&A[c]}o("../utils").inherits(a,s),a.prototype.byteAt=function(A){return this.data[this.zero+A]},a.prototype.lastIndexOfSignature=function(A){for(var c=A.charCodeAt(0),l=A.charCodeAt(1),g=A.charCodeAt(2),u=A.charCodeAt(3),h=this.length-4;0<=h;--h)if(this.data[h]===c&&this.data[h+1]===l&&this.data[h+2]===g&&this.data[h+3]===u)return h-this.zero;return-1},a.prototype.readAndCheckSignature=function(A){var c=A.charCodeAt(0),l=A.charCodeAt(1),g=A.charCodeAt(2),u=A.charCodeAt(3),h=this.readData(4);return c===h[0]&&l===h[1]&&g===h[2]&&u===h[3]},a.prototype.readData=function(A){if(this.checkOffset(A),A===0)return[];var c=this.data.slice(this.zero+this.index,this.zero+this.index+A);return this.index+=A,c},i.exports=a},{"../utils":32,"./DataReader":18}],18:[function(o,i,r){var s=o("../utils");function a(A){this.data=A,this.length=A.length,this.index=0,this.zero=0}a.prototype={checkOffset:function(A){this.checkIndex(this.index+A)},checkIndex:function(A){if(this.length<this.zero+A||A<0)throw new Error("End of data reached (data length = "+this.length+", asked index = "+A+"). Corrupted zip ?")},setIndex:function(A){this.checkIndex(A),this.index=A},skip:function(A){this.setIndex(this.index+A)},byteAt:function(){},readInt:function(A){var c,l=0;for(this.checkOffset(A),c=this.index+A-1;c>=this.index;c--)l=(l<<8)+this.byteAt(c);return this.index+=A,l},readString:function(A){return s.transformTo("string",this.readData(A))},readData:function(){},lastIndexOfSignature:function(){},readAndCheckSignature:function(){},readDate:function(){var A=this.readInt(4);return new Date(Date.UTC(1980+(A>>25&127),(A>>21&15)-1,A>>16&31,A>>11&31,A>>5&63,(31&A)<<1))}},i.exports=a},{"../utils":32}],19:[function(o,i,r){var s=o("./Uint8ArrayReader");function a(A){s.call(this,A)}o("../utils").inherits(a,s),a.prototype.readData=function(A){this.checkOffset(A);var c=this.data.slice(this.zero+this.index,this.zero+this.index+A);return this.index+=A,c},i.exports=a},{"../utils":32,"./Uint8ArrayReader":21}],20:[function(o,i,r){var s=o("./DataReader");function a(A){s.call(this,A)}o("../utils").inherits(a,s),a.prototype.byteAt=function(A){return this.data.charCodeAt(this.zero+A)},a.prototype.lastIndexOfSignature=function(A){return this.data.lastIndexOf(A)-this.zero},a.prototype.readAndCheckSignature=function(A){return A===this.readData(4)},a.prototype.readData=function(A){this.checkOffset(A);var c=this.data.slice(this.zero+this.index,this.zero+this.index+A);return this.index+=A,c},i.exports=a},{"../utils":32,"./DataReader":18}],21:[function(o,i,r){var s=o("./ArrayReader");function a(A){s.call(this,A)}o("../utils").inherits(a,s),a.prototype.readData=function(A){if(this.checkOffset(A),A===0)return new Uint8Array(0);var c=this.data.subarray(this.zero+this.index,this.zero+this.index+A);return this.index+=A,c},i.exports=a},{"../utils":32,"./ArrayReader":17}],22:[function(o,i,r){var s=o("../utils"),a=o("../support"),A=o("./ArrayReader"),c=o("./StringReader"),l=o("./NodeBufferReader"),g=o("./Uint8ArrayReader");i.exports=function(u){var h=s.getTypeOf(u);return s.checkSupport(h),h!=="string"||a.uint8array?h==="nodebuffer"?new l(u):a.uint8array?new g(s.transformTo("uint8array",u)):new A(s.transformTo("array",u)):new c(u)}},{"../support":30,"../utils":32,"./ArrayReader":17,"./NodeBufferReader":19,"./StringReader":20,"./Uint8ArrayReader":21}],23:[function(o,i,r){r.LOCAL_FILE_HEADER="PK",r.CENTRAL_FILE_HEADER="PK",r.CENTRAL_DIRECTORY_END="PK",r.ZIP64_CENTRAL_DIRECTORY_LOCATOR="PK\x07",r.ZIP64_CENTRAL_DIRECTORY_END="PK",r.DATA_DESCRIPTOR="PK\x07\b"},{}],24:[function(o,i,r){var s=o("./GenericWorker"),a=o("../utils");function A(c){s.call(this,"ConvertWorker to "+c),this.destType=c}a.inherits(A,s),A.prototype.processChunk=function(c){this.push({data:a.transformTo(this.destType,c.data),meta:c.meta})},i.exports=A},{"../utils":32,"./GenericWorker":28}],25:[function(o,i,r){var s=o("./GenericWorker"),a=o("../crc32");function A(){s.call(this,"Crc32Probe"),this.withStreamInfo("crc32",0)}o("../utils").inherits(A,s),A.prototype.processChunk=function(c){this.streamInfo.crc32=a(c.data,this.streamInfo.crc32||0),this.push(c)},i.exports=A},{"../crc32":4,"../utils":32,"./GenericWorker":28}],26:[function(o,i,r){var s=o("../utils"),a=o("./GenericWorker");function A(c){a.call(this,"DataLengthProbe for "+c),this.propName=c,this.withStreamInfo(c,0)}s.inherits(A,a),A.prototype.processChunk=function(c){if(c){var l=this.streamInfo[this.propName]||0;this.streamInfo[this.propName]=l+c.data.length}a.prototype.processChunk.call(this,c)},i.exports=A},{"../utils":32,"./GenericWorker":28}],27:[function(o,i,r){var s=o("../utils"),a=o("./GenericWorker");function A(c){a.call(this,"DataWorker");var l=this;this.dataIsReady=!1,this.index=0,this.max=0,this.data=null,this.type="",this._tickScheduled=!1,c.then(function(g){l.dataIsReady=!0,l.data=g,l.max=g&&g.length||0,l.type=s.getTypeOf(g),l.isPaused||l._tickAndRepeat()},function(g){l.error(g)})}s.inherits(A,a),A.prototype.cleanUp=function(){a.prototype.cleanUp.call(this),this.data=null},A.prototype.resume=function(){return!!a.prototype.resume.call(this)&&(!this._tickScheduled&&this.dataIsReady&&(this._tickScheduled=!0,s.delay(this._tickAndRepeat,[],this)),!0)},A.prototype._tickAndRepeat=function(){this._tickScheduled=!1,this.isPaused||this.isFinished||(this._tick(),this.isFinished||(s.delay(this._tickAndRepeat,[],this),this._tickScheduled=!0))},A.prototype._tick=function(){if(this.isPaused||this.isFinished)return!1;var c=null,l=Math.min(this.max,this.index+16384);if(this.index>=this.max)return this.end();switch(this.type){case"string":c=this.data.substring(this.index,l);break;case"uint8array":c=this.data.subarray(this.index,l);break;case"array":case"nodebuffer":c=this.data.slice(this.index,l)}return this.index=l,this.push({data:c,meta:{percent:this.max?this.index/this.max*100:0}})},i.exports=A},{"../utils":32,"./GenericWorker":28}],28:[function(o,i,r){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,A){return this._listeners[a].push(A),this},cleanUp:function(){this.streamInfo=this.generatedError=this.extraStreamInfo=null,this._listeners=[]},emit:function(a,A){if(this._listeners[a])for(var c=0;c<this._listeners[a].length;c++)this._listeners[a][c].call(this,A)},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 A=this;return a.on("data",function(c){A.processChunk(c)}),a.on("end",function(){A.end()}),a.on("error",function(c){A.error(c)}),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,A){return this.extraStreamInfo[a]=A,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(o,i,r){var s=o("../utils"),a=o("./ConvertWorker"),A=o("./GenericWorker"),c=o("../base64"),l=o("../support"),g=o("../external"),u=null;if(l.nodestream)try{u=o("../nodejs/NodejsStreamOutputAdapter")}catch{}function h(_,m){return new g.Promise(function(p,I){var f=[],C=_._internalType,y=_._outputType,E=_._mimeType;_.on("data",function(B,Q){f.push(B),m&&m(Q)}).on("error",function(B){f=[],I(B)}).on("end",function(){try{var B=(function(Q,b,D){switch(Q){case"blob":return s.newBlob(s.transformTo("arraybuffer",b),D);case"base64":return c.encode(b);default:return s.transformTo(Q,b)}})(y,(function(Q,b){var D,R=0,M=null,L=0;for(D=0;D<b.length;D++)L+=b[D].length;switch(Q){case"string":return b.join("");case"array":return Array.prototype.concat.apply([],b);case"uint8array":for(M=new Uint8Array(L),D=0;D<b.length;D++)M.set(b[D],R),R+=b[D].length;return M;case"nodebuffer":return Buffer.concat(b);default:throw new Error("concat : unsupported type '"+Q+"'")}})(C,f),E);p(B)}catch(Q){I(Q)}f=[]}).resume()})}function d(_,m,p){var I=m;switch(m){case"blob":case"arraybuffer":I="uint8array";break;case"base64":I="string"}try{this._internalType=I,this._outputType=m,this._mimeType=p,s.checkSupport(I),this._worker=_.pipe(new a(I)),_.lock()}catch(f){this._worker=new A("error"),this._worker.error(f)}}d.prototype={accumulate:function(_){return h(this,_)},on:function(_,m){var p=this;return _==="data"?this._worker.on(_,function(I){m.call(p,I.data,I.meta)}):this._worker.on(_,function(){s.delay(m,arguments,p)}),this},resume:function(){return s.delay(this._worker.resume,[],this._worker),this},pause:function(){return this._worker.pause(),this},toNodejsStream:function(_){if(s.checkSupport("nodestream"),this._outputType!=="nodebuffer")throw new Error(this._outputType+" is not supported by this method");return new u(this,{objectMode:this._outputType!=="nodebuffer"},_)}},i.exports=d},{"../base64":1,"../external":6,"../nodejs/NodejsStreamOutputAdapter":13,"../support":30,"../utils":32,"./ConvertWorker":24,"./GenericWorker":28}],30:[function(o,i,r){if(r.base64=!0,r.array=!0,r.string=!0,r.arraybuffer=typeof ArrayBuffer<"u"&&typeof Uint8Array<"u",r.nodebuffer=typeof Buffer<"u",r.uint8array=typeof Uint8Array<"u",typeof ArrayBuffer>"u")r.blob=!1;else{var s=new ArrayBuffer(0);try{r.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),r.blob=a.getBlob("application/zip").size===0}catch{r.blob=!1}}}try{r.nodestream=!!o("readable-stream").Readable}catch{r.nodestream=!1}},{"readable-stream":16}],31:[function(o,i,r){for(var s=o("./utils"),a=o("./support"),A=o("./nodejsUtils"),c=o("./stream/GenericWorker"),l=new Array(256),g=0;g<256;g++)l[g]=252<=g?6:248<=g?5:240<=g?4:224<=g?3:192<=g?2:1;l[254]=l[254]=1;function u(){c.call(this,"utf-8 decode"),this.leftOver=null}function h(){c.call(this,"utf-8 encode")}r.utf8encode=function(d){return a.nodebuffer?A.newBufferFrom(d,"utf-8"):(function(_){var m,p,I,f,C,y=_.length,E=0;for(f=0;f<y;f++)(64512&(p=_.charCodeAt(f)))==55296&&f+1<y&&(64512&(I=_.charCodeAt(f+1)))==56320&&(p=65536+(p-55296<<10)+(I-56320),f++),E+=p<128?1:p<2048?2:p<65536?3:4;for(m=a.uint8array?new Uint8Array(E):new Array(E),f=C=0;C<E;f++)(64512&(p=_.charCodeAt(f)))==55296&&f+1<y&&(64512&(I=_.charCodeAt(f+1)))==56320&&(p=65536+(p-55296<<10)+(I-56320),f++),p<128?m[C++]=p:(p<2048?m[C++]=192|p>>>6:(p<65536?m[C++]=224|p>>>12:(m[C++]=240|p>>>18,m[C++]=128|p>>>12&63),m[C++]=128|p>>>6&63),m[C++]=128|63&p);return m})(d)},r.utf8decode=function(d){return a.nodebuffer?s.transformTo("nodebuffer",d).toString("utf-8"):(function(_){var m,p,I,f,C=_.length,y=new Array(2*C);for(m=p=0;m<C;)if((I=_[m++])<128)y[p++]=I;else if(4<(f=l[I]))y[p++]=65533,m+=f-1;else{for(I&=f===2?31:f===3?15:7;1<f&&m<C;)I=I<<6|63&_[m++],f--;1<f?y[p++]=65533:I<65536?y[p++]=I:(I-=65536,y[p++]=55296|I>>10&1023,y[p++]=56320|1023&I)}return y.length!==p&&(y.subarray?y=y.subarray(0,p):y.length=p),s.applyFromCharCode(y)})(d=s.transformTo(a.uint8array?"uint8array":"array",d))},s.inherits(u,c),u.prototype.processChunk=function(d){var _=s.transformTo(a.uint8array?"uint8array":"array",d.data);if(this.leftOver&&this.leftOver.length){if(a.uint8array){var m=_;(_=new Uint8Array(m.length+this.leftOver.length)).set(this.leftOver,0),_.set(m,this.leftOver.length)}else _=this.leftOver.concat(_);this.leftOver=null}var p=(function(f,C){var y;for((C=C||f.length)>f.length&&(C=f.length),y=C-1;0<=y&&(192&f[y])==128;)y--;return y<0||y===0?C:y+l[f[y]]>C?y:C})(_),I=_;p!==_.length&&(a.uint8array?(I=_.subarray(0,p),this.leftOver=_.subarray(p,_.length)):(I=_.slice(0,p),this.leftOver=_.slice(p,_.length))),this.push({data:r.utf8decode(I),meta:d.meta})},u.prototype.flush=function(){this.leftOver&&this.leftOver.length&&(this.push({data:r.utf8decode(this.leftOver),meta:{}}),this.leftOver=null)},r.Utf8DecodeWorker=u,s.inherits(h,c),h.prototype.processChunk=function(d){this.push({data:r.utf8encode(d.data),meta:d.meta})},r.Utf8EncodeWorker=h},{"./nodejsUtils":14,"./stream/GenericWorker":28,"./support":30,"./utils":32}],32:[function(o,i,r){var s=o("./support"),a=o("./base64"),A=o("./nodejsUtils"),c=o("./external");function l(m){return m}function g(m,p){for(var I=0;I<m.length;++I)p[I]=255&m.charCodeAt(I);return p}o("setimmediate"),r.newBlob=function(m,p){r.checkSupport("blob");try{return new Blob([m],{type:p})}catch{try{var I=new(self.BlobBuilder||self.WebKitBlobBuilder||self.MozBlobBuilder||self.MSBlobBuilder);return I.append(m),I.getBlob(p)}catch{throw new Error("Bug : can't construct the Blob.")}}};var u={stringifyByChunk:function(m,p,I){var f=[],C=0,y=m.length;if(y<=I)return String.fromCharCode.apply(null,m);for(;C<y;)p==="array"||p==="nodebuffer"?f.push(String.fromCharCode.apply(null,m.slice(C,Math.min(C+I,y)))):f.push(String.fromCharCode.apply(null,m.subarray(C,Math.min(C+I,y)))),C+=I;return f.join("")},stringifyByChar:function(m){for(var p="",I=0;I<m.length;I++)p+=String.fromCharCode(m[I]);return p},applyCanBeUsed:{uint8array:(function(){try{return s.uint8array&&String.fromCharCode.apply(null,new Uint8Array(1)).length===1}catch{return!1}})(),nodebuffer:(function(){try{return s.nodebuffer&&String.fromCharCode.apply(null,A.allocBuffer(1)).length===1}catch{return!1}})()}};function h(m){var p=65536,I=r.getTypeOf(m),f=!0;if(I==="uint8array"?f=u.applyCanBeUsed.uint8array:I==="nodebuffer"&&(f=u.applyCanBeUsed.nodebuffer),f)for(;1<p;)try{return u.stringifyByChunk(m,I,p)}catch{p=Math.floor(p/2)}return u.stringifyByChar(m)}function d(m,p){for(var I=0;I<m.length;I++)p[I]=m[I];return p}r.applyFromCharCode=h;var _={};_.string={string:l,array:function(m){return g(m,new Array(m.length))},arraybuffer:function(m){return _.string.uint8array(m).buffer},uint8array:function(m){return g(m,new Uint8Array(m.length))},nodebuffer:function(m){return g(m,A.allocBuffer(m.length))}},_.array={string:h,array:l,arraybuffer:function(m){return new Uint8Array(m).buffer},uint8array:function(m){return new Uint8Array(m)},nodebuffer:function(m){return A.newBufferFrom(m)}},_.arraybuffer={string:function(m){return h(new Uint8Array(m))},array:function(m){return d(new Uint8Array(m),new Array(m.byteLength))},arraybuffer:l,uint8array:function(m){return new Uint8Array(m)},nodebuffer:function(m){return A.newBufferFrom(new Uint8Array(m))}},_.uint8array={string:h,array:function(m){return d(m,new Array(m.length))},arraybuffer:function(m){return m.buffer},uint8array:l,nodebuffer:function(m){return A.newBufferFrom(m)}},_.nodebuffer={string:h,array:function(m){return d(m,new Array(m.length))},arraybuffer:function(m){return _.nodebuffer.uint8array(m).buffer},uint8array:function(m){return d(m,new Uint8Array(m.length))},nodebuffer:l},r.transformTo=function(m,p){if(p=p||"",!m)return p;r.checkSupport(m);var I=r.getTypeOf(p);return _[I][m](p)},r.resolve=function(m){for(var p=m.split("/"),I=[],f=0;f<p.length;f++){var C=p[f];C==="."||C===""&&f!==0&&f!==p.length-1||(C===".."?I.pop():I.push(C))}return I.join("/")},r.getTypeOf=function(m){return typeof m=="string"?"string":Object.prototype.toString.call(m)==="[object Array]"?"array":s.nodebuffer&&A.isBuffer(m)?"nodebuffer":s.uint8array&&m instanceof Uint8Array?"uint8array":s.arraybuffer&&m instanceof ArrayBuffer?"arraybuffer":void 0},r.checkSupport=function(m){if(!s[m.toLowerCase()])throw new Error(m+" is not supported by this platform")},r.MAX_VALUE_16BITS=65535,r.MAX_VALUE_32BITS=-1,r.pretty=function(m){var p,I,f="";for(I=0;I<(m||"").length;I++)f+="\\x"+((p=m.charCodeAt(I))<16?"0":"")+p.toString(16).toUpperCase();return f},r.delay=function(m,p,I){setImmediate(function(){m.apply(I||null,p||[])})},r.inherits=function(m,p){function I(){}I.prototype=p.prototype,m.prototype=new I},r.extend=function(){var m,p,I={};for(m=0;m<arguments.length;m++)for(p in arguments[m])Object.prototype.hasOwnProperty.call(arguments[m],p)&&I[p]===void 0&&(I[p]=arguments[m][p]);return I},r.prepareContent=function(m,p,I,f,C){return c.Promise.resolve(p).then(function(y){return s.blob&&(y instanceof Blob||["[object File]","[object Blob]"].indexOf(Object.prototype.toString.call(y))!==-1)&&typeof FileReader<"u"?new c.Promise(function(E,B){var Q=new FileReader;Q.onload=function(b){E(b.target.result)},Q.onerror=function(b){B(b.target.error)},Q.readAsArrayBuffer(y)}):y}).then(function(y){var E=r.getTypeOf(y);return E?(E==="arraybuffer"?y=r.transformTo("uint8array",y):E==="string"&&(C?y=a.decode(y):I&&f!==!0&&(y=(function(B){return g(B,s.uint8array?new Uint8Array(B.length):new Array(B.length))})(y))),y):c.Promise.reject(new Error("Can't read the data of '"+m+"'. Is it in a supported JavaScript type (String, Blob, ArrayBuffer, etc) ?"))})}},{"./base64":1,"./external":6,"./nodejsUtils":14,"./support":30,setimmediate:54}],33:[function(o,i,r){var s=o("./reader/readerFor"),a=o("./utils"),A=o("./signature"),c=o("./zipEntry"),l=o("./support");function g(u){this.files=[],this.loadOptions=u}g.prototype={checkSignature:function(u){if(!this.reader.readAndCheckSignature(u)){this.reader.index-=4;var h=this.reader.readString(4);throw new Error("Corrupted zip or bug: unexpected signature ("+a.pretty(h)+", expected "+a.pretty(u)+")")}},isSignature:function(u,h){var d=this.reader.index;this.reader.setIndex(u);var _=this.reader.readString(4)===h;return this.reader.setIndex(d),_},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 u=this.reader.readData(this.zipCommentLength),h=l.uint8array?"uint8array":"array",d=a.transformTo(h,u);this.zipComment=this.loadOptions.decodeFileName(d)},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 u,h,d,_=this.zip64EndOfCentralSize-44;0<_;)u=this.reader.readInt(2),h=this.reader.readInt(4),d=this.reader.readData(h),this.zip64ExtensibleData[u]={id:u,length:h,value:d}},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 u,h;for(u=0;u<this.files.length;u++)h=this.files[u],this.reader.setIndex(h.localHeaderOffset),this.checkSignature(A.LOCAL_FILE_HEADER),h.readLocalPart(this.reader),h.handleUTF8(),h.processAttributes()},readCentralDir:function(){var u;for(this.reader.setIndex(this.centralDirOffset);this.reader.readAndCheckSignature(A.CENTRAL_FILE_HEADER);)(u=new c({zip64:this.zip64},this.loadOptions)).readCentralPart(this.reader),this.files.push(u);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 u=this.reader.lastIndexOfSignature(A.CENTRAL_DIRECTORY_END);if(u<0)throw this.isSignature(0,A.LOCAL_FILE_HEADER)?new Error("Corrupted zip: can't find end of central directory"):new Error("Can't find end of central directory : is this a zip file ? If it is, see https://stuk.github.io/jszip/documentation/howto/read_zip.html");this.reader.setIndex(u);var h=u;if(this.checkSignature(A.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,(u=this.reader.lastIndexOfSignature(A.ZIP64_CENTRAL_DIRECTORY_LOCATOR))<0)throw new Error("Corrupted zip: can't find the ZIP64 end of central directory locator");if(this.reader.setIndex(u),this.checkSignature(A.ZIP64_CENTRAL_DIRECTORY_LOCATOR),this.readBlockZip64EndOfCentralLocator(),!this.isSignature(this.relativeOffsetEndOfZip64CentralDir,A.ZIP64_CENTRAL_DIRECTORY_END)&&(this.relativeOffsetEndOfZip64CentralDir=this.reader.lastIndexOfSignature(A.ZIP64_CENTRAL_DIRECTORY_END),this.relativeOffsetEndOfZip64CentralDir<0))throw new Error("Corrupted zip: can't find the ZIP64 end of central directory");this.reader.setIndex(this.relativeOffsetEndOfZip64CentralDir),this.checkSignature(A.ZIP64_CENTRAL_DIRECTORY_END),this.readBlockZip64EndOfCentral()}var d=this.centralDirOffset+this.centralDirSize;this.zip64&&(d+=20,d+=12+this.zip64EndOfCentralSize);var _=h-d;if(0<_)this.isSignature(h,A.CENTRAL_FILE_HEADER)||(this.reader.zero=_);else if(_<0)throw new Error("Corrupted zip: missing "+Math.abs(_)+" bytes.")},prepareReader:function(u){this.reader=s(u)},load:function(u){this.prepareReader(u),this.readEndOfCentral(),this.readCentralDir(),this.readLocalFiles()}},i.exports=g},{"./reader/readerFor":22,"./signature":23,"./support":30,"./utils":32,"./zipEntry":34}],34:[function(o,i,r){var s=o("./reader/readerFor"),a=o("./utils"),A=o("./compressedObject"),c=o("./crc32"),l=o("./utf8"),g=o("./compressions"),u=o("./support");function h(d,_){this.options=d,this.loadOptions=_}h.prototype={isEncrypted:function(){return(1&this.bitFlag)==1},useUTF8:function(){return(2048&this.bitFlag)==2048},readLocalPart:function(d){var _,m;if(d.skip(22),this.fileNameLength=d.readInt(2),m=d.readInt(2),this.fileName=d.readData(this.fileNameLength),d.skip(m),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((_=(function(p){for(var I in g)if(Object.prototype.hasOwnProperty.call(g,I)&&g[I].magic===p)return g[I];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 A(this.compressedSize,this.uncompressedSize,this.crc32,_,d.readData(this.compressedSize))},readCentralPart:function(d){this.versionMadeBy=d.readInt(2),d.skip(2),this.bitFlag=d.readInt(2),this.compressionMethod=d.readString(2),this.date=d.readDate(),this.crc32=d.readInt(4),this.compressedSize=d.readInt(4),this.uncompressedSize=d.readInt(4);var _=d.readInt(2);if(this.extraFieldsLength=d.readInt(2),this.fileCommentLength=d.readInt(2),this.diskNumberStart=d.readInt(2),this.internalFileAttributes=d.readInt(2),this.externalFileAttributes=d.readInt(4),this.localHeaderOffset=d.readInt(4),this.isEncrypted())throw new Error("Encrypted zip are not supported");d.skip(_),this.readExtraFields(d),this.parseZIP64ExtraField(d),this.fileComment=d.readData(this.fileCommentLength)},processAttributes:function(){this.unixPermissions=null,this.dosPermissions=null;var d=this.versionMadeBy>>8;this.dir=!!(16&this.externalFileAttributes),d==0&&(this.dosPermissions=63&this.externalFileAttributes),d==3&&(this.unixPermissions=this.externalFileAttributes>>16&65535),this.dir||this.fileNameStr.slice(-1)!=="/"||(this.dir=!0)},parseZIP64ExtraField:function(){if(this.extraFields[1]){var d=s(this.extraFields[1].value);this.uncompressedSize===a.MAX_VALUE_32BITS&&(this.uncompressedSize=d.readInt(8)),this.compressedSize===a.MAX_VALUE_32BITS&&(this.compressedSize=d.readInt(8)),this.localHeaderOffset===a.MAX_VALUE_32BITS&&(this.localHeaderOffset=d.readInt(8)),this.diskNumberStart===a.MAX_VALUE_32BITS&&(this.diskNumberStart=d.readInt(4))}},readExtraFields:function(d){var _,m,p,I=d.index+this.extraFieldsLength;for(this.extraFields||(this.extraFields={});d.index+4<I;)_=d.readInt(2),m=d.readInt(2),p=d.readData(m),this.extraFields[_]={id:_,length:m,value:p};d.setIndex(I)},handleUTF8:function(){var d=u.uint8array?"uint8array":"array";if(this.useUTF8())this.fileNameStr=l.utf8decode(this.fileName),this.fileCommentStr=l.utf8decode(this.fileComment);else{var _=this.findExtraFieldUnicodePath();if(_!==null)this.fileNameStr=_;else{var m=a.transformTo(d,this.fileName);this.fileNameStr=this.loadOptions.decodeFileName(m)}var p=this.findExtraFieldUnicodeComment();if(p!==null)this.fileCommentStr=p;else{var I=a.transformTo(d,this.fileComment);this.fileCommentStr=this.loadOptions.decodeFileName(I)}}},findExtraFieldUnicodePath:function(){var d=this.extraFields[28789];if(d){var _=s(d.value);return _.readInt(1)!==1||c(this.fileName)!==_.readInt(4)?null:l.utf8decode(_.readData(d.length-5))}return null},findExtraFieldUnicodeComment:function(){var d=this.extraFields[25461];if(d){var _=s(d.value);return _.readInt(1)!==1||c(this.fileComment)!==_.readInt(4)?null:l.utf8decode(_.readData(d.length-5))}return null}},i.exports=h},{"./compressedObject":2,"./compressions":3,"./crc32":4,"./reader/readerFor":22,"./support":30,"./utf8":31,"./utils":32}],35:[function(o,i,r){function s(_,m,p){this.name=_,this.dir=p.dir,this.date=p.date,this.comment=p.comment,this.unixPermissions=p.unixPermissions,this.dosPermissions=p.dosPermissions,this._data=m,this._dataBinary=p.binary,this.options={compression:p.compression,compressionOptions:p.compressionOptions}}var a=o("./stream/StreamHelper"),A=o("./stream/DataWorker"),c=o("./utf8"),l=o("./compressedObject"),g=o("./stream/GenericWorker");s.prototype={internalStream:function(_){var m=null,p="string";try{if(!_)throw new Error("No output type specified.");var I=(p=_.toLowerCase())==="string"||p==="text";p!=="binarystring"&&p!=="text"||(p="string"),m=this._decompressWorker();var f=!this._dataBinary;f&&!I&&(m=m.pipe(new c.Utf8EncodeWorker)),!f&&I&&(m=m.pipe(new c.Utf8DecodeWorker))}catch(C){(m=new g("error")).error(C)}return new a(m,p,"")},async:function(_,m){return this.internalStream(_).accumulate(m)},nodeStream:function(_,m){return this.internalStream(_||"nodebuffer").toNodejsStream(m)},_compressWorker:function(_,m){if(this._data instanceof l&&this._data.compression.magic===_.magic)return this._data.getCompressedWorker();var p=this._decompressWorker();return this._dataBinary||(p=p.pipe(new c.Utf8EncodeWorker)),l.createWorkerFrom(p,_,m)},_decompressWorker:function(){return this._data instanceof l?this._data.getContentWorker():this._data instanceof g?this._data:new A(this._data)}};for(var u=["asText","asBinary","asNodeBuffer","asUint8Array","asArrayBuffer"],h=function(){throw new Error("This method has been removed in JSZip 3.0, please check the upgrade guide.")},d=0;d<u.length;d++)s.prototype[u[d]]=h;i.exports=s},{"./compressedObject":2,"./stream/DataWorker":27,"./stream/GenericWorker":28,"./stream/StreamHelper":29,"./utf8":31}],36:[function(o,i,r){(function(s){var a,A,c=s.MutationObserver||s.WebKitMutationObserver;if(c){var l=0,g=new c(_),u=s.document.createTextNode("");g.observe(u,{characterData:!0}),a=function(){u.data=l=++l%2}}else if(s.setImmediate||s.MessageChannel===void 0)a="document"in s&&"onreadystatechange"in s.document.createElement("script")?function(){var m=s.document.createElement("script");m.onreadystatechange=function(){_(),m.onreadystatechange=null,m.parentNode.removeChild(m),m=null},s.document.documentElement.appendChild(m)}:function(){setTimeout(_,0)};else{var h=new s.MessageChannel;h.port1.onmessage=_,a=function(){h.port2.postMessage(0)}}var d=[];function _(){var m,p;A=!0;for(var I=d.length;I;){for(p=d,d=[],m=-1;++m<I;)p[m]();I=d.length}A=!1}i.exports=function(m){d.push(m)!==1||A||a()}}).call(this,typeof PC<"u"?PC:typeof self<"u"?self:typeof window<"u"?window:{})},{}],37:[function(o,i,r){var s=o("immediate");function a(){}var A={},c=["REJECTED"],l=["FULFILLED"],g=["PENDING"];function u(I){if(typeof I!="function")throw new TypeError("resolver must be a function");this.state=g,this.queue=[],this.outcome=void 0,I!==a&&m(this,I)}function h(I,f,C){this.promise=I,typeof f=="function"&&(this.onFulfilled=f,this.callFulfilled=this.otherCallFulfilled),typeof C=="function"&&(this.onRejected=C,this.callRejected=this.otherCallRejected)}function d(I,f,C){s(function(){var y;try{y=f(C)}catch(E){return A.reject(I,E)}y===I?A.reject(I,new TypeError("Cannot resolve promise with itself")):A.resolve(I,y)})}function _(I){var f=I&&I.then;if(I&&(typeof I=="object"||typeof I=="function")&&typeof f=="function")return function(){f.apply(I,arguments)}}function m(I,f){var C=!1;function y(Q){C||(C=!0,A.reject(I,Q))}function E(Q){C||(C=!0,A.resolve(I,Q))}var B=p(function(){f(E,y)});B.status==="error"&&y(B.value)}function p(I,f){var C={};try{C.value=I(f),C.status="success"}catch(y){C.status="error",C.value=y}return C}(i.exports=u).prototype.finally=function(I){if(typeof I!="function")return this;var f=this.constructor;return this.then(function(C){return f.resolve(I()).then(function(){return C})},function(C){return f.resolve(I()).then(function(){throw C})})},u.prototype.catch=function(I){return this.then(null,I)},u.prototype.then=function(I,f){if(typeof I!="function"&&this.state===l||typeof f!="function"&&this.state===c)return this;var C=new this.constructor(a);return this.state!==g?d(C,this.state===l?I:f,this.outcome):this.queue.push(new h(C,I,f)),C},h.prototype.callFulfilled=function(I){A.resolve(this.promise,I)},h.prototype.otherCallFulfilled=function(I){d(this.promise,this.onFulfilled,I)},h.prototype.callRejected=function(I){A.reject(this.promise,I)},h.prototype.otherCallRejected=function(I){d(this.promise,this.onRejected,I)},A.resolve=function(I,f){var C=p(_,f);if(C.status==="error")return A.reject(I,C.value);var y=C.value;if(y)m(I,y);else{I.state=l,I.outcome=f;for(var E=-1,B=I.queue.length;++E<B;)I.queue[E].callFulfilled(f)}return I},A.reject=function(I,f){I.state=c,I.outcome=f;for(var C=-1,y=I.queue.length;++C<y;)I.queue[C].callRejected(f);return I},u.resolve=function(I){return I instanceof this?I:A.resolve(new this(a),I)},u.reject=function(I){var f=new this(a);return A.reject(f,I)},u.all=function(I){var f=this;if(Object.prototype.toString.call(I)!=="[object Array]")return this.reject(new TypeError("must be an array"));var C=I.length,y=!1;if(!C)return this.resolve([]);for(var E=new Array(C),B=0,Q=-1,b=new this(a);++Q<C;)D(I[Q],Q);return b;function D(R,M){f.resolve(R).then(function(L){E[M]=L,++B!==C||y||(y=!0,A.resolve(b,E))},function(L){y||(y=!0,A.reject(b,L))})}},u.race=function(I){var f=this;if(Object.prototype.toString.call(I)!=="[object Array]")return this.reject(new TypeError("must be an array"));var C=I.length,y=!1;if(!C)return this.resolve([]);for(var E=-1,B=new this(a);++E<C;)Q=I[E],f.resolve(Q).then(function(b){y||(y=!0,A.resolve(B,b))},function(b){y||(y=!0,A.reject(B,b))});var Q;return B}},{immediate:36}],38:[function(o,i,r){var s={};(0,o("./lib/utils/common").assign)(s,o("./lib/deflate"),o("./lib/inflate"),o("./lib/zlib/constants")),i.exports=s},{"./lib/deflate":39,"./lib/inflate":40,"./lib/utils/common":41,"./lib/zlib/constants":44}],39:[function(o,i,r){var s=o("./zlib/deflate"),a=o("./utils/common"),A=o("./utils/strings"),c=o("./zlib/messages"),l=o("./zlib/zstream"),g=Object.prototype.toString,u=0,h=-1,d=0,_=8;function m(I){if(!(this instanceof m))return new m(I);this.options=a.assign({level:h,method:_,chunkSize:16384,windowBits:15,memLevel:8,strategy:d,to:""},I||{});var f=this.options;f.raw&&0<f.windowBits?f.windowBits=-f.windowBits:f.gzip&&0<f.windowBits&&f.windowBits<16&&(f.windowBits+=16),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new l,this.strm.avail_out=0;var C=s.deflateInit2(this.strm,f.level,f.method,f.windowBits,f.memLevel,f.strategy);if(C!==u)throw new Error(c[C]);if(f.header&&s.deflateSetHeader(this.strm,f.header),f.dictionary){var y;if(y=typeof f.dictionary=="string"?A.string2buf(f.dictionary):g.call(f.dictionary)==="[object ArrayBuffer]"?new Uint8Array(f.dictionary):f.dictionary,(C=s.deflateSetDictionary(this.strm,y))!==u)throw new Error(c[C]);this._dict_set=!0}}function p(I,f){var C=new m(f);if(C.push(I,!0),C.err)throw C.msg||c[C.err];return C.result}m.prototype.push=function(I,f){var C,y,E=this.strm,B=this.options.chunkSize;if(this.ended)return!1;y=f===~~f?f:f===!0?4:0,typeof I=="string"?E.input=A.string2buf(I):g.call(I)==="[object ArrayBuffer]"?E.input=new Uint8Array(I):E.input=I,E.next_in=0,E.avail_in=E.input.length;do{if(E.avail_out===0&&(E.output=new a.Buf8(B),E.next_out=0,E.avail_out=B),(C=s.deflate(E,y))!==1&&C!==u)return this.onEnd(C),!(this.ended=!0);E.avail_out!==0&&(E.avail_in!==0||y!==4&&y!==2)||(this.options.to==="string"?this.onData(A.buf2binstring(a.shrinkBuf(E.output,E.next_out))):this.onData(a.shrinkBuf(E.output,E.next_out)))}while((0<E.avail_in||E.avail_out===0)&&C!==1);return y===4?(C=s.deflateEnd(this.strm),this.onEnd(C),this.ended=!0,C===u):y!==2||(this.onEnd(u),!(E.avail_out=0))},m.prototype.onData=function(I){this.chunks.push(I)},m.prototype.onEnd=function(I){I===u&&(this.options.to==="string"?this.result=this.chunks.join(""):this.result=a.flattenChunks(this.chunks)),this.chunks=[],this.err=I,this.msg=this.strm.msg},r.Deflate=m,r.deflate=p,r.deflateRaw=function(I,f){return(f=f||{}).raw=!0,p(I,f)},r.gzip=function(I,f){return(f=f||{}).gzip=!0,p(I,f)}},{"./utils/common":41,"./utils/strings":42,"./zlib/deflate":46,"./zlib/messages":51,"./zlib/zstream":53}],40:[function(o,i,r){var s=o("./zlib/inflate"),a=o("./utils/common"),A=o("./utils/strings"),c=o("./zlib/constants"),l=o("./zlib/messages"),g=o("./zlib/zstream"),u=o("./zlib/gzheader"),h=Object.prototype.toString;function d(m){if(!(this instanceof d))return new d(m);this.options=a.assign({chunkSize:16384,windowBits:0,to:""},m||{});var p=this.options;p.raw&&0<=p.windowBits&&p.windowBits<16&&(p.windowBits=-p.windowBits,p.windowBits===0&&(p.windowBits=-15)),!(0<=p.windowBits&&p.windowBits<16)||m&&m.windowBits||(p.windowBits+=32),15<p.windowBits&&p.windowBits<48&&(15&p.windowBits)==0&&(p.windowBits|=15),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new g,this.strm.avail_out=0;var I=s.inflateInit2(this.strm,p.windowBits);if(I!==c.Z_OK)throw new Error(l[I]);this.header=new u,s.inflateGetHeader(this.strm,this.header)}function _(m,p){var I=new d(p);if(I.push(m,!0),I.err)throw I.msg||l[I.err];return I.result}d.prototype.push=function(m,p){var I,f,C,y,E,B,Q=this.strm,b=this.options.chunkSize,D=this.options.dictionary,R=!1;if(this.ended)return!1;f=p===~~p?p:p===!0?c.Z_FINISH:c.Z_NO_FLUSH,typeof m=="string"?Q.input=A.binstring2buf(m):h.call(m)==="[object ArrayBuffer]"?Q.input=new Uint8Array(m):Q.input=m,Q.next_in=0,Q.avail_in=Q.input.length;do{if(Q.avail_out===0&&(Q.output=new a.Buf8(b),Q.next_out=0,Q.avail_out=b),(I=s.inflate(Q,c.Z_NO_FLUSH))===c.Z_NEED_DICT&&D&&(B=typeof D=="string"?A.string2buf(D):h.call(D)==="[object ArrayBuffer]"?new Uint8Array(D):D,I=s.inflateSetDictionary(this.strm,B)),I===c.Z_BUF_ERROR&&R===!0&&(I=c.Z_OK,R=!1),I!==c.Z_STREAM_END&&I!==c.Z_OK)return this.onEnd(I),!(this.ended=!0);Q.next_out&&(Q.avail_out!==0&&I!==c.Z_STREAM_END&&(Q.avail_in!==0||f!==c.Z_FINISH&&f!==c.Z_SYNC_FLUSH)||(this.options.to==="string"?(C=A.utf8border(Q.output,Q.next_out),y=Q.next_out-C,E=A.buf2string(Q.output,C),Q.next_out=y,Q.avail_out=b-y,y&&a.arraySet(Q.output,Q.output,C,y,0),this.onData(E)):this.onData(a.shrinkBuf(Q.output,Q.next_out)))),Q.avail_in===0&&Q.avail_out===0&&(R=!0)}while((0<Q.avail_in||Q.avail_out===0)&&I!==c.Z_STREAM_END);return I===c.Z_STREAM_END&&(f=c.Z_FINISH),f===c.Z_FINISH?(I=s.inflateEnd(this.strm),this.onEnd(I),this.ended=!0,I===c.Z_OK):f!==c.Z_SYNC_FLUSH||(this.onEnd(c.Z_OK),!(Q.avail_out=0))},d.prototype.onData=function(m){this.chunks.push(m)},d.prototype.onEnd=function(m){m===c.Z_OK&&(this.options.to==="string"?this.result=this.chunks.join(""):this.result=a.flattenChunks(this.chunks)),this.chunks=[],this.err=m,this.msg=this.strm.msg},r.Inflate=d,r.inflate=_,r.inflateRaw=function(m,p){return(p=p||{}).raw=!0,_(m,p)},r.ungzip=_},{"./utils/common":41,"./utils/strings":42,"./zlib/constants":44,"./zlib/gzheader":47,"./zlib/inflate":49,"./zlib/messages":51,"./zlib/zstream":53}],41:[function(o,i,r){var s=typeof Uint8Array<"u"&&typeof Uint16Array<"u"&&typeof Int32Array<"u";r.assign=function(c){for(var l=Array.prototype.slice.call(arguments,1);l.length;){var g=l.shift();if(g){if(typeof g!="object")throw new TypeError(g+"must be non-object");for(var u in g)g.hasOwnProperty(u)&&(c[u]=g[u])}}return c},r.shrinkBuf=function(c,l){return c.length===l?c:c.subarray?c.subarray(0,l):(c.length=l,c)};var a={arraySet:function(c,l,g,u,h){if(l.subarray&&c.subarray)c.set(l.subarray(g,g+u),h);else for(var d=0;d<u;d++)c[h+d]=l[g+d]},flattenChunks:function(c){var l,g,u,h,d,_;for(l=u=0,g=c.length;l<g;l++)u+=c[l].length;for(_=new Uint8Array(u),l=h=0,g=c.length;l<g;l++)d=c[l],_.set(d,h),h+=d.length;return _}},A={arraySet:function(c,l,g,u,h){for(var d=0;d<u;d++)c[h+d]=l[g+d]},flattenChunks:function(c){return[].concat.apply([],c)}};r.setTyped=function(c){c?(r.Buf8=Uint8Array,r.Buf16=Uint16Array,r.Buf32=Int32Array,r.assign(r,a)):(r.Buf8=Array,r.Buf16=Array,r.Buf32=Array,r.assign(r,A))},r.setTyped(s)},{}],42:[function(o,i,r){var s=o("./common"),a=!0,A=!0;try{String.fromCharCode.apply(null,[0])}catch{a=!1}try{String.fromCharCode.apply(null,new Uint8Array(1))}catch{A=!1}for(var c=new s.Buf8(256),l=0;l<256;l++)c[l]=252<=l?6:248<=l?5:240<=l?4:224<=l?3:192<=l?2:1;function g(u,h){if(h<65537&&(u.subarray&&A||!u.subarray&&a))return String.fromCharCode.apply(null,s.shrinkBuf(u,h));for(var d="",_=0;_<h;_++)d+=String.fromCharCode(u[_]);return d}c[254]=c[254]=1,r.string2buf=function(u){var h,d,_,m,p,I=u.length,f=0;for(m=0;m<I;m++)(64512&(d=u.charCodeAt(m)))==55296&&m+1<I&&(64512&(_=u.charCodeAt(m+1)))==56320&&(d=65536+(d-55296<<10)+(_-56320),m++),f+=d<128?1:d<2048?2:d<65536?3:4;for(h=new s.Buf8(f),m=p=0;p<f;m++)(64512&(d=u.charCodeAt(m)))==55296&&m+1<I&&(64512&(_=u.charCodeAt(m+1)))==56320&&(d=65536+(d-55296<<10)+(_-56320),m++),d<128?h[p++]=d:(d<2048?h[p++]=192|d>>>6:(d<65536?h[p++]=224|d>>>12:(h[p++]=240|d>>>18,h[p++]=128|d>>>12&63),h[p++]=128|d>>>6&63),h[p++]=128|63&d);return h},r.buf2binstring=function(u){return g(u,u.length)},r.binstring2buf=function(u){for(var h=new s.Buf8(u.length),d=0,_=h.length;d<_;d++)h[d]=u.charCodeAt(d);return h},r.buf2string=function(u,h){var d,_,m,p,I=h||u.length,f=new Array(2*I);for(d=_=0;d<I;)if((m=u[d++])<128)f[_++]=m;else if(4<(p=c[m]))f[_++]=65533,d+=p-1;else{for(m&=p===2?31:p===3?15:7;1<p&&d<I;)m=m<<6|63&u[d++],p--;1<p?f[_++]=65533:m<65536?f[_++]=m:(m-=65536,f[_++]=55296|m>>10&1023,f[_++]=56320|1023&m)}return g(f,_)},r.utf8border=function(u,h){var d;for((h=h||u.length)>u.length&&(h=u.length),d=h-1;0<=d&&(192&u[d])==128;)d--;return d<0||d===0?h:d+c[u[d]]>h?d:h}},{"./common":41}],43:[function(o,i,r){i.exports=function(s,a,A,c){for(var l=65535&s|0,g=s>>>16&65535|0,u=0;A!==0;){for(A-=u=2e3<A?2e3:A;g=g+(l=l+a[c++]|0)|0,--u;);l%=65521,g%=65521}return l|g<<16|0}},{}],44:[function(o,i,r){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(o,i,r){var s=(function(){for(var a,A=[],c=0;c<256;c++){a=c;for(var l=0;l<8;l++)a=1&a?3988292384^a>>>1:a>>>1;A[c]=a}return A})();i.exports=function(a,A,c,l){var g=s,u=l+c;a^=-1;for(var h=l;h<u;h++)a=a>>>8^g[255&(a^A[h])];return-1^a}},{}],46:[function(o,i,r){var s,a=o("../utils/common"),A=o("./trees"),c=o("./adler32"),l=o("./crc32"),g=o("./messages"),u=0,h=4,d=0,_=-2,m=-1,p=4,I=2,f=8,C=9,y=286,E=30,B=19,Q=2*y+1,b=15,D=3,R=258,M=R+D+1,L=42,G=113,O=1,U=2,W=3,j=4;function te(Ie,We){return Ie.msg=g[We],We}function ie(Ie){return(Ie<<1)-(4<Ie?9:0)}function $(Ie){for(var We=Ie.length;0<=--We;)Ie[We]=0}function Z(Ie){var We=Ie.state,Ne=We.pending;Ne>Ie.avail_out&&(Ne=Ie.avail_out),Ne!==0&&(a.arraySet(Ie.output,We.pending_buf,We.pending_out,Ne,Ie.next_out),Ie.next_out+=Ne,We.pending_out+=Ne,Ie.total_out+=Ne,Ie.avail_out-=Ne,We.pending-=Ne,We.pending===0&&(We.pending_out=0))}function se(Ie,We){A._tr_flush_block(Ie,0<=Ie.block_start?Ie.block_start:-1,Ie.strstart-Ie.block_start,We),Ie.block_start=Ie.strstart,Z(Ie.strm)}function ae(Ie,We){Ie.pending_buf[Ie.pending++]=We}function ce(Ie,We){Ie.pending_buf[Ie.pending++]=We>>>8&255,Ie.pending_buf[Ie.pending++]=255&We}function fe(Ie,We){var Ne,ke,Ve=Ie.max_chain_length,Re=Ie.strstart,Se=Ie.prev_length,Oe=Ie.nice_match,Pe=Ie.strstart>Ie.w_size-M?Ie.strstart-(Ie.w_size-M):0,qe=Ie.window,$e=Ie.w_mask,at=Ie.prev,ct=Ie.strstart+R,dt=qe[Re+Se-1],gt=qe[Re+Se];Ie.prev_length>=Ie.good_match&&(Ve>>=2),Oe>Ie.lookahead&&(Oe=Ie.lookahead);do if(qe[(Ne=We)+Se]===gt&&qe[Ne+Se-1]===dt&&qe[Ne]===qe[Re]&&qe[++Ne]===qe[Re+1]){Re+=2,Ne++;do;while(qe[++Re]===qe[++Ne]&&qe[++Re]===qe[++Ne]&&qe[++Re]===qe[++Ne]&&qe[++Re]===qe[++Ne]&&qe[++Re]===qe[++Ne]&&qe[++Re]===qe[++Ne]&&qe[++Re]===qe[++Ne]&&qe[++Re]===qe[++Ne]&&Re<ct);if(ke=R-(ct-Re),Re=ct-R,Se<ke){if(Ie.match_start=We,Oe<=(Se=ke))break;dt=qe[Re+Se-1],gt=qe[Re+Se]}}while((We=at[We&$e])>Pe&&--Ve!=0);return Se<=Ie.lookahead?Se:Ie.lookahead}function Ce(Ie){var We,Ne,ke,Ve,Re,Se,Oe,Pe,qe,$e,at=Ie.w_size;do{if(Ve=Ie.window_size-Ie.lookahead-Ie.strstart,Ie.strstart>=at+(at-M)){for(a.arraySet(Ie.window,Ie.window,at,at,0),Ie.match_start-=at,Ie.strstart-=at,Ie.block_start-=at,We=Ne=Ie.hash_size;ke=Ie.head[--We],Ie.head[We]=at<=ke?ke-at:0,--Ne;);for(We=Ne=at;ke=Ie.prev[--We],Ie.prev[We]=at<=ke?ke-at:0,--Ne;);Ve+=at}if(Ie.strm.avail_in===0)break;if(Se=Ie.strm,Oe=Ie.window,Pe=Ie.strstart+Ie.lookahead,qe=Ve,$e=void 0,$e=Se.avail_in,qe<$e&&($e=qe),Ne=$e===0?0:(Se.avail_in-=$e,a.arraySet(Oe,Se.input,Se.next_in,$e,Pe),Se.state.wrap===1?Se.adler=c(Se.adler,Oe,$e,Pe):Se.state.wrap===2&&(Se.adler=l(Se.adler,Oe,$e,Pe)),Se.next_in+=$e,Se.total_in+=$e,$e),Ie.lookahead+=Ne,Ie.lookahead+Ie.insert>=D)for(Re=Ie.strstart-Ie.insert,Ie.ins_h=Ie.window[Re],Ie.ins_h=(Ie.ins_h<<Ie.hash_shift^Ie.window[Re+1])&Ie.hash_mask;Ie.insert&&(Ie.ins_h=(Ie.ins_h<<Ie.hash_shift^Ie.window[Re+D-1])&Ie.hash_mask,Ie.prev[Re&Ie.w_mask]=Ie.head[Ie.ins_h],Ie.head[Ie.ins_h]=Re,Re++,Ie.insert--,!(Ie.lookahead+Ie.insert<D)););}while(Ie.lookahead<M&&Ie.strm.avail_in!==0)}function xe(Ie,We){for(var Ne,ke;;){if(Ie.lookahead<M){if(Ce(Ie),Ie.lookahead<M&&We===u)return O;if(Ie.lookahead===0)break}if(Ne=0,Ie.lookahead>=D&&(Ie.ins_h=(Ie.ins_h<<Ie.hash_shift^Ie.window[Ie.strstart+D-1])&Ie.hash_mask,Ne=Ie.prev[Ie.strstart&Ie.w_mask]=Ie.head[Ie.ins_h],Ie.head[Ie.ins_h]=Ie.strstart),Ne!==0&&Ie.strstart-Ne<=Ie.w_size-M&&(Ie.match_length=fe(Ie,Ne)),Ie.match_length>=D)if(ke=A._tr_tally(Ie,Ie.strstart-Ie.match_start,Ie.match_length-D),Ie.lookahead-=Ie.match_length,Ie.match_length<=Ie.max_lazy_match&&Ie.lookahead>=D){for(Ie.match_length--;Ie.strstart++,Ie.ins_h=(Ie.ins_h<<Ie.hash_shift^Ie.window[Ie.strstart+D-1])&Ie.hash_mask,Ne=Ie.prev[Ie.strstart&Ie.w_mask]=Ie.head[Ie.ins_h],Ie.head[Ie.ins_h]=Ie.strstart,--Ie.match_length!=0;);Ie.strstart++}else Ie.strstart+=Ie.match_length,Ie.match_length=0,Ie.ins_h=Ie.window[Ie.strstart],Ie.ins_h=(Ie.ins_h<<Ie.hash_shift^Ie.window[Ie.strstart+1])&Ie.hash_mask;else ke=A._tr_tally(Ie,0,Ie.window[Ie.strstart]),Ie.lookahead--,Ie.strstart++;if(ke&&(se(Ie,!1),Ie.strm.avail_out===0))return O}return Ie.insert=Ie.strstart<D-1?Ie.strstart:D-1,We===h?(se(Ie,!0),Ie.strm.avail_out===0?W:j):Ie.last_lit&&(se(Ie,!1),Ie.strm.avail_out===0)?O:U}function de(Ie,We){for(var Ne,ke,Ve;;){if(Ie.lookahead<M){if(Ce(Ie),Ie.lookahead<M&&We===u)return O;if(Ie.lookahead===0)break}if(Ne=0,Ie.lookahead>=D&&(Ie.ins_h=(Ie.ins_h<<Ie.hash_shift^Ie.window[Ie.strstart+D-1])&Ie.hash_mask,Ne=Ie.prev[Ie.strstart&Ie.w_mask]=Ie.head[Ie.ins_h],Ie.head[Ie.ins_h]=Ie.strstart),Ie.prev_length=Ie.match_length,Ie.prev_match=Ie.match_start,Ie.match_length=D-1,Ne!==0&&Ie.prev_length<Ie.max_lazy_match&&Ie.strstart-Ne<=Ie.w_size-M&&(Ie.match_length=fe(Ie,Ne),Ie.match_length<=5&&(Ie.strategy===1||Ie.match_length===D&&4096<Ie.strstart-Ie.match_start)&&(Ie.match_length=D-1)),Ie.prev_length>=D&&Ie.match_length<=Ie.prev_length){for(Ve=Ie.strstart+Ie.lookahead-D,ke=A._tr_tally(Ie,Ie.strstart-1-Ie.prev_match,Ie.prev_length-D),Ie.lookahead-=Ie.prev_length-1,Ie.prev_length-=2;++Ie.strstart<=Ve&&(Ie.ins_h=(Ie.ins_h<<Ie.hash_shift^Ie.window[Ie.strstart+D-1])&Ie.hash_mask,Ne=Ie.prev[Ie.strstart&Ie.w_mask]=Ie.head[Ie.ins_h],Ie.head[Ie.ins_h]=Ie.strstart),--Ie.prev_length!=0;);if(Ie.match_available=0,Ie.match_length=D-1,Ie.strstart++,ke&&(se(Ie,!1),Ie.strm.avail_out===0))return O}else if(Ie.match_available){if((ke=A._tr_tally(Ie,0,Ie.window[Ie.strstart-1]))&&se(Ie,!1),Ie.strstart++,Ie.lookahead--,Ie.strm.avail_out===0)return O}else Ie.match_available=1,Ie.strstart++,Ie.lookahead--}return Ie.match_available&&(ke=A._tr_tally(Ie,0,Ie.window[Ie.strstart-1]),Ie.match_available=0),Ie.insert=Ie.strstart<D-1?Ie.strstart:D-1,We===h?(se(Ie,!0),Ie.strm.avail_out===0?W:j):Ie.last_lit&&(se(Ie,!1),Ie.strm.avail_out===0)?O:U}function Ee(Ie,We,Ne,ke,Ve){this.good_length=Ie,this.max_lazy=We,this.nice_length=Ne,this.max_chain=ke,this.func=Ve}function he(){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=f,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*Q),this.dyn_dtree=new a.Buf16(2*(2*E+1)),this.bl_tree=new a.Buf16(2*(2*B+1)),$(this.dyn_ltree),$(this.dyn_dtree),$(this.bl_tree),this.l_desc=null,this.d_desc=null,this.bl_desc=null,this.bl_count=new a.Buf16(b+1),this.heap=new a.Buf16(2*y+1),$(this.heap),this.heap_len=0,this.heap_max=0,this.depth=new a.Buf16(2*y+1),$(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 be(Ie){var We;return Ie&&Ie.state?(Ie.total_in=Ie.total_out=0,Ie.data_type=I,(We=Ie.state).pending=0,We.pending_out=0,We.wrap<0&&(We.wrap=-We.wrap),We.status=We.wrap?L:G,Ie.adler=We.wrap===2?0:1,We.last_flush=u,A._tr_init(We),d):te(Ie,_)}function Me(Ie){var We=be(Ie);return We===d&&(function(Ne){Ne.window_size=2*Ne.w_size,$(Ne.head),Ne.max_lazy_match=s[Ne.level].max_lazy,Ne.good_match=s[Ne.level].good_length,Ne.nice_match=s[Ne.level].nice_length,Ne.max_chain_length=s[Ne.level].max_chain,Ne.strstart=0,Ne.block_start=0,Ne.lookahead=0,Ne.insert=0,Ne.match_length=Ne.prev_length=D-1,Ne.match_available=0,Ne.ins_h=0})(Ie.state),We}function Ye(Ie,We,Ne,ke,Ve,Re){if(!Ie)return _;var Se=1;if(We===m&&(We=6),ke<0?(Se=0,ke=-ke):15<ke&&(Se=2,ke-=16),Ve<1||C<Ve||Ne!==f||ke<8||15<ke||We<0||9<We||Re<0||p<Re)return te(Ie,_);ke===8&&(ke=9);var Oe=new he;return(Ie.state=Oe).strm=Ie,Oe.wrap=Se,Oe.gzhead=null,Oe.w_bits=ke,Oe.w_size=1<<Oe.w_bits,Oe.w_mask=Oe.w_size-1,Oe.hash_bits=Ve+7,Oe.hash_size=1<<Oe.hash_bits,Oe.hash_mask=Oe.hash_size-1,Oe.hash_shift=~~((Oe.hash_bits+D-1)/D),Oe.window=new a.Buf8(2*Oe.w_size),Oe.head=new a.Buf16(Oe.hash_size),Oe.prev=new a.Buf16(Oe.w_size),Oe.lit_bufsize=1<<Ve+6,Oe.pending_buf_size=4*Oe.lit_bufsize,Oe.pending_buf=new a.Buf8(Oe.pending_buf_size),Oe.d_buf=1*Oe.lit_bufsize,Oe.l_buf=3*Oe.lit_bufsize,Oe.level=We,Oe.strategy=Re,Oe.method=Ne,Me(Ie)}s=[new Ee(0,0,0,0,function(Ie,We){var Ne=65535;for(Ne>Ie.pending_buf_size-5&&(Ne=Ie.pending_buf_size-5);;){if(Ie.lookahead<=1){if(Ce(Ie),Ie.lookahead===0&&We===u)return O;if(Ie.lookahead===0)break}Ie.strstart+=Ie.lookahead,Ie.lookahead=0;var ke=Ie.block_start+Ne;if((Ie.strstart===0||Ie.strstart>=ke)&&(Ie.lookahead=Ie.strstart-ke,Ie.strstart=ke,se(Ie,!1),Ie.strm.avail_out===0)||Ie.strstart-Ie.block_start>=Ie.w_size-M&&(se(Ie,!1),Ie.strm.avail_out===0))return O}return Ie.insert=0,We===h?(se(Ie,!0),Ie.strm.avail_out===0?W:j):(Ie.strstart>Ie.block_start&&(se(Ie,!1),Ie.strm.avail_out),O)}),new Ee(4,4,8,4,xe),new Ee(4,5,16,8,xe),new Ee(4,6,32,32,xe),new Ee(4,4,16,16,de),new Ee(8,16,32,32,de),new Ee(8,16,128,128,de),new Ee(8,32,128,256,de),new Ee(32,128,258,1024,de),new Ee(32,258,258,4096,de)],r.deflateInit=function(Ie,We){return Ye(Ie,We,f,15,8,0)},r.deflateInit2=Ye,r.deflateReset=Me,r.deflateResetKeep=be,r.deflateSetHeader=function(Ie,We){return Ie&&Ie.state?Ie.state.wrap!==2?_:(Ie.state.gzhead=We,d):_},r.deflate=function(Ie,We){var Ne,ke,Ve,Re;if(!Ie||!Ie.state||5<We||We<0)return Ie?te(Ie,_):_;if(ke=Ie.state,!Ie.output||!Ie.input&&Ie.avail_in!==0||ke.status===666&&We!==h)return te(Ie,Ie.avail_out===0?-5:_);if(ke.strm=Ie,Ne=ke.last_flush,ke.last_flush=We,ke.status===L)if(ke.wrap===2)Ie.adler=0,ae(ke,31),ae(ke,139),ae(ke,8),ke.gzhead?(ae(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)),ae(ke,255&ke.gzhead.time),ae(ke,ke.gzhead.time>>8&255),ae(ke,ke.gzhead.time>>16&255),ae(ke,ke.gzhead.time>>24&255),ae(ke,ke.level===9?2:2<=ke.strategy||ke.level<2?4:0),ae(ke,255&ke.gzhead.os),ke.gzhead.extra&&ke.gzhead.extra.length&&(ae(ke,255&ke.gzhead.extra.length),ae(ke,ke.gzhead.extra.length>>8&255)),ke.gzhead.hcrc&&(Ie.adler=l(Ie.adler,ke.pending_buf,ke.pending,0)),ke.gzindex=0,ke.status=69):(ae(ke,0),ae(ke,0),ae(ke,0),ae(ke,0),ae(ke,0),ae(ke,ke.level===9?2:2<=ke.strategy||ke.level<2?4:0),ae(ke,3),ke.status=G);else{var Se=f+(ke.w_bits-8<<4)<<8;Se|=(2<=ke.strategy||ke.level<2?0:ke.level<6?1:ke.level===6?2:3)<<6,ke.strstart!==0&&(Se|=32),Se+=31-Se%31,ke.status=G,ce(ke,Se),ke.strstart!==0&&(ce(ke,Ie.adler>>>16),ce(ke,65535&Ie.adler)),Ie.adler=1}if(ke.status===69)if(ke.gzhead.extra){for(Ve=ke.pending;ke.gzindex<(65535&ke.gzhead.extra.length)&&(ke.pending!==ke.pending_buf_size||(ke.gzhead.hcrc&&ke.pending>Ve&&(Ie.adler=l(Ie.adler,ke.pending_buf,ke.pending-Ve,Ve)),Z(Ie),Ve=ke.pending,ke.pending!==ke.pending_buf_size));)ae(ke,255&ke.gzhead.extra[ke.gzindex]),ke.gzindex++;ke.gzhead.hcrc&&ke.pending>Ve&&(Ie.adler=l(Ie.adler,ke.pending_buf,ke.pending-Ve,Ve)),ke.gzindex===ke.gzhead.extra.length&&(ke.gzindex=0,ke.status=73)}else ke.status=73;if(ke.status===73)if(ke.gzhead.name){Ve=ke.pending;do{if(ke.pending===ke.pending_buf_size&&(ke.gzhead.hcrc&&ke.pending>Ve&&(Ie.adler=l(Ie.adler,ke.pending_buf,ke.pending-Ve,Ve)),Z(Ie),Ve=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,ae(ke,Re)}while(Re!==0);ke.gzhead.hcrc&&ke.pending>Ve&&(Ie.adler=l(Ie.adler,ke.pending_buf,ke.pending-Ve,Ve)),Re===0&&(ke.gzindex=0,ke.status=91)}else ke.status=91;if(ke.status===91)if(ke.gzhead.comment){Ve=ke.pending;do{if(ke.pending===ke.pending_buf_size&&(ke.gzhead.hcrc&&ke.pending>Ve&&(Ie.adler=l(Ie.adler,ke.pending_buf,ke.pending-Ve,Ve)),Z(Ie),Ve=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,ae(ke,Re)}while(Re!==0);ke.gzhead.hcrc&&ke.pending>Ve&&(Ie.adler=l(Ie.adler,ke.pending_buf,ke.pending-Ve,Ve)),Re===0&&(ke.status=103)}else ke.status=103;if(ke.status===103&&(ke.gzhead.hcrc?(ke.pending+2>ke.pending_buf_size&&Z(Ie),ke.pending+2<=ke.pending_buf_size&&(ae(ke,255&Ie.adler),ae(ke,Ie.adler>>8&255),Ie.adler=0,ke.status=G)):ke.status=G),ke.pending!==0){if(Z(Ie),Ie.avail_out===0)return ke.last_flush=-1,d}else if(Ie.avail_in===0&&ie(We)<=ie(Ne)&&We!==h)return te(Ie,-5);if(ke.status===666&&Ie.avail_in!==0)return te(Ie,-5);if(Ie.avail_in!==0||ke.lookahead!==0||We!==u&&ke.status!==666){var Oe=ke.strategy===2?(function(Pe,qe){for(var $e;;){if(Pe.lookahead===0&&(Ce(Pe),Pe.lookahead===0)){if(qe===u)return O;break}if(Pe.match_length=0,$e=A._tr_tally(Pe,0,Pe.window[Pe.strstart]),Pe.lookahead--,Pe.strstart++,$e&&(se(Pe,!1),Pe.strm.avail_out===0))return O}return Pe.insert=0,qe===h?(se(Pe,!0),Pe.strm.avail_out===0?W:j):Pe.last_lit&&(se(Pe,!1),Pe.strm.avail_out===0)?O:U})(ke,We):ke.strategy===3?(function(Pe,qe){for(var $e,at,ct,dt,gt=Pe.window;;){if(Pe.lookahead<=R){if(Ce(Pe),Pe.lookahead<=R&&qe===u)return O;if(Pe.lookahead===0)break}if(Pe.match_length=0,Pe.lookahead>=D&&0<Pe.strstart&&(at=gt[ct=Pe.strstart-1])===gt[++ct]&&at===gt[++ct]&&at===gt[++ct]){dt=Pe.strstart+R;do;while(at===gt[++ct]&&at===gt[++ct]&&at===gt[++ct]&&at===gt[++ct]&&at===gt[++ct]&&at===gt[++ct]&&at===gt[++ct]&&at===gt[++ct]&&ct<dt);Pe.match_length=R-(dt-ct),Pe.match_length>Pe.lookahead&&(Pe.match_length=Pe.lookahead)}if(Pe.match_length>=D?($e=A._tr_tally(Pe,1,Pe.match_length-D),Pe.lookahead-=Pe.match_length,Pe.strstart+=Pe.match_length,Pe.match_length=0):($e=A._tr_tally(Pe,0,Pe.window[Pe.strstart]),Pe.lookahead--,Pe.strstart++),$e&&(se(Pe,!1),Pe.strm.avail_out===0))return O}return Pe.insert=0,qe===h?(se(Pe,!0),Pe.strm.avail_out===0?W:j):Pe.last_lit&&(se(Pe,!1),Pe.strm.avail_out===0)?O:U})(ke,We):s[ke.level].func(ke,We);if(Oe!==W&&Oe!==j||(ke.status=666),Oe===O||Oe===W)return Ie.avail_out===0&&(ke.last_flush=-1),d;if(Oe===U&&(We===1?A._tr_align(ke):We!==5&&(A._tr_stored_block(ke,0,0,!1),We===3&&($(ke.head),ke.lookahead===0&&(ke.strstart=0,ke.block_start=0,ke.insert=0))),Z(Ie),Ie.avail_out===0))return ke.last_flush=-1,d}return We!==h?d:ke.wrap<=0?1:(ke.wrap===2?(ae(ke,255&Ie.adler),ae(ke,Ie.adler>>8&255),ae(ke,Ie.adler>>16&255),ae(ke,Ie.adler>>24&255),ae(ke,255&Ie.total_in),ae(ke,Ie.total_in>>8&255),ae(ke,Ie.total_in>>16&255),ae(ke,Ie.total_in>>24&255)):(ce(ke,Ie.adler>>>16),ce(ke,65535&Ie.adler)),Z(Ie),0<ke.wrap&&(ke.wrap=-ke.wrap),ke.pending!==0?d:1)},r.deflateEnd=function(Ie){var We;return Ie&&Ie.state?(We=Ie.state.status)!==L&&We!==69&&We!==73&&We!==91&&We!==103&&We!==G&&We!==666?te(Ie,_):(Ie.state=null,We===G?te(Ie,-3):d):_},r.deflateSetDictionary=function(Ie,We){var Ne,ke,Ve,Re,Se,Oe,Pe,qe,$e=We.length;if(!Ie||!Ie.state||(Re=(Ne=Ie.state).wrap)===2||Re===1&&Ne.status!==L||Ne.lookahead)return _;for(Re===1&&(Ie.adler=c(Ie.adler,We,$e,0)),Ne.wrap=0,$e>=Ne.w_size&&(Re===0&&($(Ne.head),Ne.strstart=0,Ne.block_start=0,Ne.insert=0),qe=new a.Buf8(Ne.w_size),a.arraySet(qe,We,$e-Ne.w_size,Ne.w_size,0),We=qe,$e=Ne.w_size),Se=Ie.avail_in,Oe=Ie.next_in,Pe=Ie.input,Ie.avail_in=$e,Ie.next_in=0,Ie.input=We,Ce(Ne);Ne.lookahead>=D;){for(ke=Ne.strstart,Ve=Ne.lookahead-(D-1);Ne.ins_h=(Ne.ins_h<<Ne.hash_shift^Ne.window[ke+D-1])&Ne.hash_mask,Ne.prev[ke&Ne.w_mask]=Ne.head[Ne.ins_h],Ne.head[Ne.ins_h]=ke,ke++,--Ve;);Ne.strstart=ke,Ne.lookahead=D-1,Ce(Ne)}return Ne.strstart+=Ne.lookahead,Ne.block_start=Ne.strstart,Ne.insert=Ne.lookahead,Ne.lookahead=0,Ne.match_length=Ne.prev_length=D-1,Ne.match_available=0,Ie.next_in=Oe,Ie.input=Pe,Ie.avail_in=Se,Ne.wrap=Re,d},r.deflateInfo="pako deflate (from Nodeca project)"},{"../utils/common":41,"./adler32":43,"./crc32":45,"./messages":51,"./trees":52}],47:[function(o,i,r){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(o,i,r){i.exports=function(s,a){var A,c,l,g,u,h,d,_,m,p,I,f,C,y,E,B,Q,b,D,R,M,L,G,O,U;A=s.state,c=s.next_in,O=s.input,l=c+(s.avail_in-5),g=s.next_out,U=s.output,u=g-(a-s.avail_out),h=g+(s.avail_out-257),d=A.dmax,_=A.wsize,m=A.whave,p=A.wnext,I=A.window,f=A.hold,C=A.bits,y=A.lencode,E=A.distcode,B=(1<<A.lenbits)-1,Q=(1<<A.distbits)-1;e:do{C<15&&(f+=O[c++]<<C,C+=8,f+=O[c++]<<C,C+=8),b=y[f&B];t:for(;;){if(f>>>=D=b>>>24,C-=D,(D=b>>>16&255)===0)U[g++]=65535&b;else{if(!(16&D)){if((64&D)==0){b=y[(65535&b)+(f&(1<<D)-1)];continue t}if(32&D){A.mode=12;break e}s.msg="invalid literal/length code",A.mode=30;break e}R=65535&b,(D&=15)&&(C<D&&(f+=O[c++]<<C,C+=8),R+=f&(1<<D)-1,f>>>=D,C-=D),C<15&&(f+=O[c++]<<C,C+=8,f+=O[c++]<<C,C+=8),b=E[f&Q];n:for(;;){if(f>>>=D=b>>>24,C-=D,!(16&(D=b>>>16&255))){if((64&D)==0){b=E[(65535&b)+(f&(1<<D)-1)];continue n}s.msg="invalid distance code",A.mode=30;break e}if(M=65535&b,C<(D&=15)&&(f+=O[c++]<<C,(C+=8)<D&&(f+=O[c++]<<C,C+=8)),d<(M+=f&(1<<D)-1)){s.msg="invalid distance too far back",A.mode=30;break e}if(f>>>=D,C-=D,(D=g-u)<M){if(m<(D=M-D)&&A.sane){s.msg="invalid distance too far back",A.mode=30;break e}if(G=I,(L=0)===p){if(L+=_-D,D<R){for(R-=D;U[g++]=I[L++],--D;);L=g-M,G=U}}else if(p<D){if(L+=_+p-D,(D-=p)<R){for(R-=D;U[g++]=I[L++],--D;);if(L=0,p<R){for(R-=D=p;U[g++]=I[L++],--D;);L=g-M,G=U}}}else if(L+=p-D,D<R){for(R-=D;U[g++]=I[L++],--D;);L=g-M,G=U}for(;2<R;)U[g++]=G[L++],U[g++]=G[L++],U[g++]=G[L++],R-=3;R&&(U[g++]=G[L++],1<R&&(U[g++]=G[L++]))}else{for(L=g-M;U[g++]=U[L++],U[g++]=U[L++],U[g++]=U[L++],2<(R-=3););R&&(U[g++]=U[L++],1<R&&(U[g++]=U[L++]))}break}}break}}while(c<l&&g<h);c-=R=C>>3,f&=(1<<(C-=R<<3))-1,s.next_in=c,s.next_out=g,s.avail_in=c<l?l-c+5:5-(c-l),s.avail_out=g<h?h-g+257:257-(g-h),A.hold=f,A.bits=C}},{}],49:[function(o,i,r){var s=o("../utils/common"),a=o("./adler32"),A=o("./crc32"),c=o("./inffast"),l=o("./inftrees"),g=1,u=2,h=0,d=-2,_=1,m=852,p=592;function I(L){return(L>>>24&255)+(L>>>8&65280)+((65280&L)<<8)+((255&L)<<24)}function f(){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 C(L){var G;return L&&L.state?(G=L.state,L.total_in=L.total_out=G.total=0,L.msg="",G.wrap&&(L.adler=1&G.wrap),G.mode=_,G.last=0,G.havedict=0,G.dmax=32768,G.head=null,G.hold=0,G.bits=0,G.lencode=G.lendyn=new s.Buf32(m),G.distcode=G.distdyn=new s.Buf32(p),G.sane=1,G.back=-1,h):d}function y(L){var G;return L&&L.state?((G=L.state).wsize=0,G.whave=0,G.wnext=0,C(L)):d}function E(L,G){var O,U;return L&&L.state?(U=L.state,G<0?(O=0,G=-G):(O=1+(G>>4),G<48&&(G&=15)),G&&(G<8||15<G)?d:(U.window!==null&&U.wbits!==G&&(U.window=null),U.wrap=O,U.wbits=G,y(L))):d}function B(L,G){var O,U;return L?(U=new f,(L.state=U).window=null,(O=E(L,G))!==h&&(L.state=null),O):d}var Q,b,D=!0;function R(L){if(D){var G;for(Q=new s.Buf32(512),b=new s.Buf32(32),G=0;G<144;)L.lens[G++]=8;for(;G<256;)L.lens[G++]=9;for(;G<280;)L.lens[G++]=7;for(;G<288;)L.lens[G++]=8;for(l(g,L.lens,0,288,Q,0,L.work,{bits:9}),G=0;G<32;)L.lens[G++]=5;l(u,L.lens,0,32,b,0,L.work,{bits:5}),D=!1}L.lencode=Q,L.lenbits=9,L.distcode=b,L.distbits=5}function M(L,G,O,U){var W,j=L.state;return j.window===null&&(j.wsize=1<<j.wbits,j.wnext=0,j.whave=0,j.window=new s.Buf8(j.wsize)),U>=j.wsize?(s.arraySet(j.window,G,O-j.wsize,j.wsize,0),j.wnext=0,j.whave=j.wsize):(U<(W=j.wsize-j.wnext)&&(W=U),s.arraySet(j.window,G,O-U,W,j.wnext),(U-=W)?(s.arraySet(j.window,G,O-U,U,0),j.wnext=U,j.whave=j.wsize):(j.wnext+=W,j.wnext===j.wsize&&(j.wnext=0),j.whave<j.wsize&&(j.whave+=W))),0}r.inflateReset=y,r.inflateReset2=E,r.inflateResetKeep=C,r.inflateInit=function(L){return B(L,15)},r.inflateInit2=B,r.inflate=function(L,G){var O,U,W,j,te,ie,$,Z,se,ae,ce,fe,Ce,xe,de,Ee,he,be,Me,Ye,Ie,We,Ne,ke,Ve=0,Re=new s.Buf8(4),Se=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15];if(!L||!L.state||!L.output||!L.input&&L.avail_in!==0)return d;(O=L.state).mode===12&&(O.mode=13),te=L.next_out,W=L.output,$=L.avail_out,j=L.next_in,U=L.input,ie=L.avail_in,Z=O.hold,se=O.bits,ae=ie,ce=$,We=h;e:for(;;)switch(O.mode){case _:if(O.wrap===0){O.mode=13;break}for(;se<16;){if(ie===0)break e;ie--,Z+=U[j++]<<se,se+=8}if(2&O.wrap&&Z===35615){Re[O.check=0]=255&Z,Re[1]=Z>>>8&255,O.check=A(O.check,Re,2,0),se=Z=0,O.mode=2;break}if(O.flags=0,O.head&&(O.head.done=!1),!(1&O.wrap)||(((255&Z)<<8)+(Z>>8))%31){L.msg="incorrect header check",O.mode=30;break}if((15&Z)!=8){L.msg="unknown compression method",O.mode=30;break}if(se-=4,Ie=8+(15&(Z>>>=4)),O.wbits===0)O.wbits=Ie;else if(Ie>O.wbits){L.msg="invalid window size",O.mode=30;break}O.dmax=1<<Ie,L.adler=O.check=1,O.mode=512&Z?10:12,se=Z=0;break;case 2:for(;se<16;){if(ie===0)break e;ie--,Z+=U[j++]<<se,se+=8}if(O.flags=Z,(255&O.flags)!=8){L.msg="unknown compression method",O.mode=30;break}if(57344&O.flags){L.msg="unknown header flags set",O.mode=30;break}O.head&&(O.head.text=Z>>8&1),512&O.flags&&(Re[0]=255&Z,Re[1]=Z>>>8&255,O.check=A(O.check,Re,2,0)),se=Z=0,O.mode=3;case 3:for(;se<32;){if(ie===0)break e;ie--,Z+=U[j++]<<se,se+=8}O.head&&(O.head.time=Z),512&O.flags&&(Re[0]=255&Z,Re[1]=Z>>>8&255,Re[2]=Z>>>16&255,Re[3]=Z>>>24&255,O.check=A(O.check,Re,4,0)),se=Z=0,O.mode=4;case 4:for(;se<16;){if(ie===0)break e;ie--,Z+=U[j++]<<se,se+=8}O.head&&(O.head.xflags=255&Z,O.head.os=Z>>8),512&O.flags&&(Re[0]=255&Z,Re[1]=Z>>>8&255,O.check=A(O.check,Re,2,0)),se=Z=0,O.mode=5;case 5:if(1024&O.flags){for(;se<16;){if(ie===0)break e;ie--,Z+=U[j++]<<se,se+=8}O.length=Z,O.head&&(O.head.extra_len=Z),512&O.flags&&(Re[0]=255&Z,Re[1]=Z>>>8&255,O.check=A(O.check,Re,2,0)),se=Z=0}else O.head&&(O.head.extra=null);O.mode=6;case 6:if(1024&O.flags&&(ie<(fe=O.length)&&(fe=ie),fe&&(O.head&&(Ie=O.head.extra_len-O.length,O.head.extra||(O.head.extra=new Array(O.head.extra_len)),s.arraySet(O.head.extra,U,j,fe,Ie)),512&O.flags&&(O.check=A(O.check,U,fe,j)),ie-=fe,j+=fe,O.length-=fe),O.length))break e;O.length=0,O.mode=7;case 7:if(2048&O.flags){if(ie===0)break e;for(fe=0;Ie=U[j+fe++],O.head&&Ie&&O.length<65536&&(O.head.name+=String.fromCharCode(Ie)),Ie&&fe<ie;);if(512&O.flags&&(O.check=A(O.check,U,fe,j)),ie-=fe,j+=fe,Ie)break e}else O.head&&(O.head.name=null);O.length=0,O.mode=8;case 8:if(4096&O.flags){if(ie===0)break e;for(fe=0;Ie=U[j+fe++],O.head&&Ie&&O.length<65536&&(O.head.comment+=String.fromCharCode(Ie)),Ie&&fe<ie;);if(512&O.flags&&(O.check=A(O.check,U,fe,j)),ie-=fe,j+=fe,Ie)break e}else O.head&&(O.head.comment=null);O.mode=9;case 9:if(512&O.flags){for(;se<16;){if(ie===0)break e;ie--,Z+=U[j++]<<se,se+=8}if(Z!==(65535&O.check)){L.msg="header crc mismatch",O.mode=30;break}se=Z=0}O.head&&(O.head.hcrc=O.flags>>9&1,O.head.done=!0),L.adler=O.check=0,O.mode=12;break;case 10:for(;se<32;){if(ie===0)break e;ie--,Z+=U[j++]<<se,se+=8}L.adler=O.check=I(Z),se=Z=0,O.mode=11;case 11:if(O.havedict===0)return L.next_out=te,L.avail_out=$,L.next_in=j,L.avail_in=ie,O.hold=Z,O.bits=se,2;L.adler=O.check=1,O.mode=12;case 12:if(G===5||G===6)break e;case 13:if(O.last){Z>>>=7&se,se-=7&se,O.mode=27;break}for(;se<3;){if(ie===0)break e;ie--,Z+=U[j++]<<se,se+=8}switch(O.last=1&Z,se-=1,3&(Z>>>=1)){case 0:O.mode=14;break;case 1:if(R(O),O.mode=20,G!==6)break;Z>>>=2,se-=2;break e;case 2:O.mode=17;break;case 3:L.msg="invalid block type",O.mode=30}Z>>>=2,se-=2;break;case 14:for(Z>>>=7&se,se-=7&se;se<32;){if(ie===0)break e;ie--,Z+=U[j++]<<se,se+=8}if((65535&Z)!=(Z>>>16^65535)){L.msg="invalid stored block lengths",O.mode=30;break}if(O.length=65535&Z,se=Z=0,O.mode=15,G===6)break e;case 15:O.mode=16;case 16:if(fe=O.length){if(ie<fe&&(fe=ie),$<fe&&(fe=$),fe===0)break e;s.arraySet(W,U,j,fe,te),ie-=fe,j+=fe,$-=fe,te+=fe,O.length-=fe;break}O.mode=12;break;case 17:for(;se<14;){if(ie===0)break e;ie--,Z+=U[j++]<<se,se+=8}if(O.nlen=257+(31&Z),Z>>>=5,se-=5,O.ndist=1+(31&Z),Z>>>=5,se-=5,O.ncode=4+(15&Z),Z>>>=4,se-=4,286<O.nlen||30<O.ndist){L.msg="too many length or distance symbols",O.mode=30;break}O.have=0,O.mode=18;case 18:for(;O.have<O.ncode;){for(;se<3;){if(ie===0)break e;ie--,Z+=U[j++]<<se,se+=8}O.lens[Se[O.have++]]=7&Z,Z>>>=3,se-=3}for(;O.have<19;)O.lens[Se[O.have++]]=0;if(O.lencode=O.lendyn,O.lenbits=7,Ne={bits:O.lenbits},We=l(0,O.lens,0,19,O.lencode,0,O.work,Ne),O.lenbits=Ne.bits,We){L.msg="invalid code lengths set",O.mode=30;break}O.have=0,O.mode=19;case 19:for(;O.have<O.nlen+O.ndist;){for(;Ee=(Ve=O.lencode[Z&(1<<O.lenbits)-1])>>>16&255,he=65535&Ve,!((de=Ve>>>24)<=se);){if(ie===0)break e;ie--,Z+=U[j++]<<se,se+=8}if(he<16)Z>>>=de,se-=de,O.lens[O.have++]=he;else{if(he===16){for(ke=de+2;se<ke;){if(ie===0)break e;ie--,Z+=U[j++]<<se,se+=8}if(Z>>>=de,se-=de,O.have===0){L.msg="invalid bit length repeat",O.mode=30;break}Ie=O.lens[O.have-1],fe=3+(3&Z),Z>>>=2,se-=2}else if(he===17){for(ke=de+3;se<ke;){if(ie===0)break e;ie--,Z+=U[j++]<<se,se+=8}se-=de,Ie=0,fe=3+(7&(Z>>>=de)),Z>>>=3,se-=3}else{for(ke=de+7;se<ke;){if(ie===0)break e;ie--,Z+=U[j++]<<se,se+=8}se-=de,Ie=0,fe=11+(127&(Z>>>=de)),Z>>>=7,se-=7}if(O.have+fe>O.nlen+O.ndist){L.msg="invalid bit length repeat",O.mode=30;break}for(;fe--;)O.lens[O.have++]=Ie}}if(O.mode===30)break;if(O.lens[256]===0){L.msg="invalid code -- missing end-of-block",O.mode=30;break}if(O.lenbits=9,Ne={bits:O.lenbits},We=l(g,O.lens,0,O.nlen,O.lencode,0,O.work,Ne),O.lenbits=Ne.bits,We){L.msg="invalid literal/lengths set",O.mode=30;break}if(O.distbits=6,O.distcode=O.distdyn,Ne={bits:O.distbits},We=l(u,O.lens,O.nlen,O.ndist,O.distcode,0,O.work,Ne),O.distbits=Ne.bits,We){L.msg="invalid distances set",O.mode=30;break}if(O.mode=20,G===6)break e;case 20:O.mode=21;case 21:if(6<=ie&&258<=$){L.next_out=te,L.avail_out=$,L.next_in=j,L.avail_in=ie,O.hold=Z,O.bits=se,c(L,ce),te=L.next_out,W=L.output,$=L.avail_out,j=L.next_in,U=L.input,ie=L.avail_in,Z=O.hold,se=O.bits,O.mode===12&&(O.back=-1);break}for(O.back=0;Ee=(Ve=O.lencode[Z&(1<<O.lenbits)-1])>>>16&255,he=65535&Ve,!((de=Ve>>>24)<=se);){if(ie===0)break e;ie--,Z+=U[j++]<<se,se+=8}if(Ee&&(240&Ee)==0){for(be=de,Me=Ee,Ye=he;Ee=(Ve=O.lencode[Ye+((Z&(1<<be+Me)-1)>>be)])>>>16&255,he=65535&Ve,!(be+(de=Ve>>>24)<=se);){if(ie===0)break e;ie--,Z+=U[j++]<<se,se+=8}Z>>>=be,se-=be,O.back+=be}if(Z>>>=de,se-=de,O.back+=de,O.length=he,Ee===0){O.mode=26;break}if(32&Ee){O.back=-1,O.mode=12;break}if(64&Ee){L.msg="invalid literal/length code",O.mode=30;break}O.extra=15&Ee,O.mode=22;case 22:if(O.extra){for(ke=O.extra;se<ke;){if(ie===0)break e;ie--,Z+=U[j++]<<se,se+=8}O.length+=Z&(1<<O.extra)-1,Z>>>=O.extra,se-=O.extra,O.back+=O.extra}O.was=O.length,O.mode=23;case 23:for(;Ee=(Ve=O.distcode[Z&(1<<O.distbits)-1])>>>16&255,he=65535&Ve,!((de=Ve>>>24)<=se);){if(ie===0)break e;ie--,Z+=U[j++]<<se,se+=8}if((240&Ee)==0){for(be=de,Me=Ee,Ye=he;Ee=(Ve=O.distcode[Ye+((Z&(1<<be+Me)-1)>>be)])>>>16&255,he=65535&Ve,!(be+(de=Ve>>>24)<=se);){if(ie===0)break e;ie--,Z+=U[j++]<<se,se+=8}Z>>>=be,se-=be,O.back+=be}if(Z>>>=de,se-=de,O.back+=de,64&Ee){L.msg="invalid distance code",O.mode=30;break}O.offset=he,O.extra=15&Ee,O.mode=24;case 24:if(O.extra){for(ke=O.extra;se<ke;){if(ie===0)break e;ie--,Z+=U[j++]<<se,se+=8}O.offset+=Z&(1<<O.extra)-1,Z>>>=O.extra,se-=O.extra,O.back+=O.extra}if(O.offset>O.dmax){L.msg="invalid distance too far back",O.mode=30;break}O.mode=25;case 25:if($===0)break e;if(fe=ce-$,O.offset>fe){if((fe=O.offset-fe)>O.whave&&O.sane){L.msg="invalid distance too far back",O.mode=30;break}Ce=fe>O.wnext?(fe-=O.wnext,O.wsize-fe):O.wnext-fe,fe>O.length&&(fe=O.length),xe=O.window}else xe=W,Ce=te-O.offset,fe=O.length;for($<fe&&(fe=$),$-=fe,O.length-=fe;W[te++]=xe[Ce++],--fe;);O.length===0&&(O.mode=21);break;case 26:if($===0)break e;W[te++]=O.length,$--,O.mode=21;break;case 27:if(O.wrap){for(;se<32;){if(ie===0)break e;ie--,Z|=U[j++]<<se,se+=8}if(ce-=$,L.total_out+=ce,O.total+=ce,ce&&(L.adler=O.check=O.flags?A(O.check,W,ce,te-ce):a(O.check,W,ce,te-ce)),ce=$,(O.flags?Z:I(Z))!==O.check){L.msg="incorrect data check",O.mode=30;break}se=Z=0}O.mode=28;case 28:if(O.wrap&&O.flags){for(;se<32;){if(ie===0)break e;ie--,Z+=U[j++]<<se,se+=8}if(Z!==(4294967295&O.total)){L.msg="incorrect length check",O.mode=30;break}se=Z=0}O.mode=29;case 29:We=1;break e;case 30:We=-3;break e;case 31:return-4;default:return d}return L.next_out=te,L.avail_out=$,L.next_in=j,L.avail_in=ie,O.hold=Z,O.bits=se,(O.wsize||ce!==L.avail_out&&O.mode<30&&(O.mode<27||G!==4))&&M(L,L.output,L.next_out,ce-L.avail_out)?(O.mode=31,-4):(ae-=L.avail_in,ce-=L.avail_out,L.total_in+=ae,L.total_out+=ce,O.total+=ce,O.wrap&&ce&&(L.adler=O.check=O.flags?A(O.check,W,ce,L.next_out-ce):a(O.check,W,ce,L.next_out-ce)),L.data_type=O.bits+(O.last?64:0)+(O.mode===12?128:0)+(O.mode===20||O.mode===15?256:0),(ae==0&&ce===0||G===4)&&We===h&&(We=-5),We)},r.inflateEnd=function(L){if(!L||!L.state)return d;var G=L.state;return G.window&&(G.window=null),L.state=null,h},r.inflateGetHeader=function(L,G){var O;return L&&L.state?(2&(O=L.state).wrap)==0?d:((O.head=G).done=!1,h):d},r.inflateSetDictionary=function(L,G){var O,U=G.length;return L&&L.state?(O=L.state).wrap!==0&&O.mode!==11?d:O.mode===11&&a(1,G,U,0)!==O.check?-3:M(L,G,U,U)?(O.mode=31,-4):(O.havedict=1,h):d},r.inflateInfo="pako inflate (from Nodeca project)"},{"../utils/common":41,"./adler32":43,"./crc32":45,"./inffast":48,"./inftrees":50}],50:[function(o,i,r){var s=o("../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],A=[16,16,16,16,16,16,16,16,17,17,17,17,18,18,18,18,19,19,19,19,20,20,20,20,21,21,21,21,16,72,78],c=[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],l=[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(g,u,h,d,_,m,p,I){var f,C,y,E,B,Q,b,D,R,M=I.bits,L=0,G=0,O=0,U=0,W=0,j=0,te=0,ie=0,$=0,Z=0,se=null,ae=0,ce=new s.Buf16(16),fe=new s.Buf16(16),Ce=null,xe=0;for(L=0;L<=15;L++)ce[L]=0;for(G=0;G<d;G++)ce[u[h+G]]++;for(W=M,U=15;1<=U&&ce[U]===0;U--);if(U<W&&(W=U),U===0)return _[m++]=20971520,_[m++]=20971520,I.bits=1,0;for(O=1;O<U&&ce[O]===0;O++);for(W<O&&(W=O),L=ie=1;L<=15;L++)if(ie<<=1,(ie-=ce[L])<0)return-1;if(0<ie&&(g===0||U!==1))return-1;for(fe[1]=0,L=1;L<15;L++)fe[L+1]=fe[L]+ce[L];for(G=0;G<d;G++)u[h+G]!==0&&(p[fe[u[h+G]]++]=G);if(Q=g===0?(se=Ce=p,19):g===1?(se=a,ae-=257,Ce=A,xe-=257,256):(se=c,Ce=l,-1),L=O,B=m,te=G=Z=0,y=-1,E=($=1<<(j=W))-1,g===1&&852<$||g===2&&592<$)return 1;for(;;){for(b=L-te,R=p[G]<Q?(D=0,p[G]):p[G]>Q?(D=Ce[xe+p[G]],se[ae+p[G]]):(D=96,0),f=1<<L-te,O=C=1<<j;_[B+(Z>>te)+(C-=f)]=b<<24|D<<16|R|0,C!==0;);for(f=1<<L-1;Z&f;)f>>=1;if(f!==0?(Z&=f-1,Z+=f):Z=0,G++,--ce[L]==0){if(L===U)break;L=u[h+p[G]]}if(W<L&&(Z&E)!==y){for(te===0&&(te=W),B+=O,ie=1<<(j=L-te);j+te<U&&!((ie-=ce[j+te])<=0);)j++,ie<<=1;if($+=1<<j,g===1&&852<$||g===2&&592<$)return 1;_[y=Z&E]=W<<24|j<<16|B-m|0}}return Z!==0&&(_[B+Z]=L-te<<24|64<<16|0),I.bits=W,0}},{"../utils/common":41}],51:[function(o,i,r){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(o,i,r){var s=o("../utils/common"),a=0,A=1;function c(Ve){for(var Re=Ve.length;0<=--Re;)Ve[Re]=0}var l=0,g=29,u=256,h=u+1+g,d=30,_=19,m=2*h+1,p=15,I=16,f=7,C=256,y=16,E=17,B=18,Q=[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],b=[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],D=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7],R=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],M=new Array(2*(h+2));c(M);var L=new Array(2*d);c(L);var G=new Array(512);c(G);var O=new Array(256);c(O);var U=new Array(g);c(U);var W,j,te,ie=new Array(d);function $(Ve,Re,Se,Oe,Pe){this.static_tree=Ve,this.extra_bits=Re,this.extra_base=Se,this.elems=Oe,this.max_length=Pe,this.has_stree=Ve&&Ve.length}function Z(Ve,Re){this.dyn_tree=Ve,this.max_code=0,this.stat_desc=Re}function se(Ve){return Ve<256?G[Ve]:G[256+(Ve>>>7)]}function ae(Ve,Re){Ve.pending_buf[Ve.pending++]=255&Re,Ve.pending_buf[Ve.pending++]=Re>>>8&255}function ce(Ve,Re,Se){Ve.bi_valid>I-Se?(Ve.bi_buf|=Re<<Ve.bi_valid&65535,ae(Ve,Ve.bi_buf),Ve.bi_buf=Re>>I-Ve.bi_valid,Ve.bi_valid+=Se-I):(Ve.bi_buf|=Re<<Ve.bi_valid&65535,Ve.bi_valid+=Se)}function fe(Ve,Re,Se){ce(Ve,Se[2*Re],Se[2*Re+1])}function Ce(Ve,Re){for(var Se=0;Se|=1&Ve,Ve>>>=1,Se<<=1,0<--Re;);return Se>>>1}function xe(Ve,Re,Se){var Oe,Pe,qe=new Array(p+1),$e=0;for(Oe=1;Oe<=p;Oe++)qe[Oe]=$e=$e+Se[Oe-1]<<1;for(Pe=0;Pe<=Re;Pe++){var at=Ve[2*Pe+1];at!==0&&(Ve[2*Pe]=Ce(qe[at]++,at))}}function de(Ve){var Re;for(Re=0;Re<h;Re++)Ve.dyn_ltree[2*Re]=0;for(Re=0;Re<d;Re++)Ve.dyn_dtree[2*Re]=0;for(Re=0;Re<_;Re++)Ve.bl_tree[2*Re]=0;Ve.dyn_ltree[2*C]=1,Ve.opt_len=Ve.static_len=0,Ve.last_lit=Ve.matches=0}function Ee(Ve){8<Ve.bi_valid?ae(Ve,Ve.bi_buf):0<Ve.bi_valid&&(Ve.pending_buf[Ve.pending++]=Ve.bi_buf),Ve.bi_buf=0,Ve.bi_valid=0}function he(Ve,Re,Se,Oe){var Pe=2*Re,qe=2*Se;return Ve[Pe]<Ve[qe]||Ve[Pe]===Ve[qe]&&Oe[Re]<=Oe[Se]}function be(Ve,Re,Se){for(var Oe=Ve.heap[Se],Pe=Se<<1;Pe<=Ve.heap_len&&(Pe<Ve.heap_len&&he(Re,Ve.heap[Pe+1],Ve.heap[Pe],Ve.depth)&&Pe++,!he(Re,Oe,Ve.heap[Pe],Ve.depth));)Ve.heap[Se]=Ve.heap[Pe],Se=Pe,Pe<<=1;Ve.heap[Se]=Oe}function Me(Ve,Re,Se){var Oe,Pe,qe,$e,at=0;if(Ve.last_lit!==0)for(;Oe=Ve.pending_buf[Ve.d_buf+2*at]<<8|Ve.pending_buf[Ve.d_buf+2*at+1],Pe=Ve.pending_buf[Ve.l_buf+at],at++,Oe===0?fe(Ve,Pe,Re):(fe(Ve,(qe=O[Pe])+u+1,Re),($e=Q[qe])!==0&&ce(Ve,Pe-=U[qe],$e),fe(Ve,qe=se(--Oe),Se),($e=b[qe])!==0&&ce(Ve,Oe-=ie[qe],$e)),at<Ve.last_lit;);fe(Ve,C,Re)}function Ye(Ve,Re){var Se,Oe,Pe,qe=Re.dyn_tree,$e=Re.stat_desc.static_tree,at=Re.stat_desc.has_stree,ct=Re.stat_desc.elems,dt=-1;for(Ve.heap_len=0,Ve.heap_max=m,Se=0;Se<ct;Se++)qe[2*Se]!==0?(Ve.heap[++Ve.heap_len]=dt=Se,Ve.depth[Se]=0):qe[2*Se+1]=0;for(;Ve.heap_len<2;)qe[2*(Pe=Ve.heap[++Ve.heap_len]=dt<2?++dt:0)]=1,Ve.depth[Pe]=0,Ve.opt_len--,at&&(Ve.static_len-=$e[2*Pe+1]);for(Re.max_code=dt,Se=Ve.heap_len>>1;1<=Se;Se--)be(Ve,qe,Se);for(Pe=ct;Se=Ve.heap[1],Ve.heap[1]=Ve.heap[Ve.heap_len--],be(Ve,qe,1),Oe=Ve.heap[1],Ve.heap[--Ve.heap_max]=Se,Ve.heap[--Ve.heap_max]=Oe,qe[2*Pe]=qe[2*Se]+qe[2*Oe],Ve.depth[Pe]=(Ve.depth[Se]>=Ve.depth[Oe]?Ve.depth[Se]:Ve.depth[Oe])+1,qe[2*Se+1]=qe[2*Oe+1]=Pe,Ve.heap[1]=Pe++,be(Ve,qe,1),2<=Ve.heap_len;);Ve.heap[--Ve.heap_max]=Ve.heap[1],(function(gt,nt){var xt,_t,vt,Ft,en,tn,Ut=nt.dyn_tree,ye=nt.max_code,st=nt.stat_desc.static_tree,lt=nt.stat_desc.has_stree,ht=nt.stat_desc.extra_bits,Tt=nt.stat_desc.extra_base,Ht=nt.stat_desc.max_length,gn=0;for(Ft=0;Ft<=p;Ft++)gt.bl_count[Ft]=0;for(Ut[2*gt.heap[gt.heap_max]+1]=0,xt=gt.heap_max+1;xt<m;xt++)Ht<(Ft=Ut[2*Ut[2*(_t=gt.heap[xt])+1]+1]+1)&&(Ft=Ht,gn++),Ut[2*_t+1]=Ft,ye<_t||(gt.bl_count[Ft]++,en=0,Tt<=_t&&(en=ht[_t-Tt]),tn=Ut[2*_t],gt.opt_len+=tn*(Ft+en),lt&&(gt.static_len+=tn*(st[2*_t+1]+en)));if(gn!==0){do{for(Ft=Ht-1;gt.bl_count[Ft]===0;)Ft--;gt.bl_count[Ft]--,gt.bl_count[Ft+1]+=2,gt.bl_count[Ht]--,gn-=2}while(0<gn);for(Ft=Ht;Ft!==0;Ft--)for(_t=gt.bl_count[Ft];_t!==0;)ye<(vt=gt.heap[--xt])||(Ut[2*vt+1]!==Ft&&(gt.opt_len+=(Ft-Ut[2*vt+1])*Ut[2*vt],Ut[2*vt+1]=Ft),_t--)}})(Ve,Re),xe(qe,dt,Ve.bl_count)}function Ie(Ve,Re,Se){var Oe,Pe,qe=-1,$e=Re[1],at=0,ct=7,dt=4;for($e===0&&(ct=138,dt=3),Re[2*(Se+1)+1]=65535,Oe=0;Oe<=Se;Oe++)Pe=$e,$e=Re[2*(Oe+1)+1],++at<ct&&Pe===$e||(at<dt?Ve.bl_tree[2*Pe]+=at:Pe!==0?(Pe!==qe&&Ve.bl_tree[2*Pe]++,Ve.bl_tree[2*y]++):at<=10?Ve.bl_tree[2*E]++:Ve.bl_tree[2*B]++,qe=Pe,dt=(at=0)===$e?(ct=138,3):Pe===$e?(ct=6,3):(ct=7,4))}function We(Ve,Re,Se){var Oe,Pe,qe=-1,$e=Re[1],at=0,ct=7,dt=4;for($e===0&&(ct=138,dt=3),Oe=0;Oe<=Se;Oe++)if(Pe=$e,$e=Re[2*(Oe+1)+1],!(++at<ct&&Pe===$e)){if(at<dt)for(;fe(Ve,Pe,Ve.bl_tree),--at!=0;);else Pe!==0?(Pe!==qe&&(fe(Ve,Pe,Ve.bl_tree),at--),fe(Ve,y,Ve.bl_tree),ce(Ve,at-3,2)):at<=10?(fe(Ve,E,Ve.bl_tree),ce(Ve,at-3,3)):(fe(Ve,B,Ve.bl_tree),ce(Ve,at-11,7));qe=Pe,dt=(at=0)===$e?(ct=138,3):Pe===$e?(ct=6,3):(ct=7,4)}}c(ie);var Ne=!1;function ke(Ve,Re,Se,Oe){ce(Ve,(l<<1)+(Oe?1:0),3),(function(Pe,qe,$e,at){Ee(Pe),ae(Pe,$e),ae(Pe,~$e),s.arraySet(Pe.pending_buf,Pe.window,qe,$e,Pe.pending),Pe.pending+=$e})(Ve,Re,Se)}r._tr_init=function(Ve){Ne||((function(){var Re,Se,Oe,Pe,qe,$e=new Array(p+1);for(Pe=Oe=0;Pe<g-1;Pe++)for(U[Pe]=Oe,Re=0;Re<1<<Q[Pe];Re++)O[Oe++]=Pe;for(O[Oe-1]=Pe,Pe=qe=0;Pe<16;Pe++)for(ie[Pe]=qe,Re=0;Re<1<<b[Pe];Re++)G[qe++]=Pe;for(qe>>=7;Pe<d;Pe++)for(ie[Pe]=qe<<7,Re=0;Re<1<<b[Pe]-7;Re++)G[256+qe++]=Pe;for(Se=0;Se<=p;Se++)$e[Se]=0;for(Re=0;Re<=143;)M[2*Re+1]=8,Re++,$e[8]++;for(;Re<=255;)M[2*Re+1]=9,Re++,$e[9]++;for(;Re<=279;)M[2*Re+1]=7,Re++,$e[7]++;for(;Re<=287;)M[2*Re+1]=8,Re++,$e[8]++;for(xe(M,h+1,$e),Re=0;Re<d;Re++)L[2*Re+1]=5,L[2*Re]=Ce(Re,5);W=new $(M,Q,u+1,h,p),j=new $(L,b,0,d,p),te=new $(new Array(0),D,0,_,f)})(),Ne=!0),Ve.l_desc=new Z(Ve.dyn_ltree,W),Ve.d_desc=new Z(Ve.dyn_dtree,j),Ve.bl_desc=new Z(Ve.bl_tree,te),Ve.bi_buf=0,Ve.bi_valid=0,de(Ve)},r._tr_stored_block=ke,r._tr_flush_block=function(Ve,Re,Se,Oe){var Pe,qe,$e=0;0<Ve.level?(Ve.strm.data_type===2&&(Ve.strm.data_type=(function(at){var ct,dt=4093624447;for(ct=0;ct<=31;ct++,dt>>>=1)if(1&dt&&at.dyn_ltree[2*ct]!==0)return a;if(at.dyn_ltree[18]!==0||at.dyn_ltree[20]!==0||at.dyn_ltree[26]!==0)return A;for(ct=32;ct<u;ct++)if(at.dyn_ltree[2*ct]!==0)return A;return a})(Ve)),Ye(Ve,Ve.l_desc),Ye(Ve,Ve.d_desc),$e=(function(at){var ct;for(Ie(at,at.dyn_ltree,at.l_desc.max_code),Ie(at,at.dyn_dtree,at.d_desc.max_code),Ye(at,at.bl_desc),ct=_-1;3<=ct&&at.bl_tree[2*R[ct]+1]===0;ct--);return at.opt_len+=3*(ct+1)+5+5+4,ct})(Ve),Pe=Ve.opt_len+3+7>>>3,(qe=Ve.static_len+3+7>>>3)<=Pe&&(Pe=qe)):Pe=qe=Se+5,Se+4<=Pe&&Re!==-1?ke(Ve,Re,Se,Oe):Ve.strategy===4||qe===Pe?(ce(Ve,2+(Oe?1:0),3),Me(Ve,M,L)):(ce(Ve,4+(Oe?1:0),3),(function(at,ct,dt,gt){var nt;for(ce(at,ct-257,5),ce(at,dt-1,5),ce(at,gt-4,4),nt=0;nt<gt;nt++)ce(at,at.bl_tree[2*R[nt]+1],3);We(at,at.dyn_ltree,ct-1),We(at,at.dyn_dtree,dt-1)})(Ve,Ve.l_desc.max_code+1,Ve.d_desc.max_code+1,$e+1),Me(Ve,Ve.dyn_ltree,Ve.dyn_dtree)),de(Ve),Oe&&Ee(Ve)},r._tr_tally=function(Ve,Re,Se){return Ve.pending_buf[Ve.d_buf+2*Ve.last_lit]=Re>>>8&255,Ve.pending_buf[Ve.d_buf+2*Ve.last_lit+1]=255&Re,Ve.pending_buf[Ve.l_buf+Ve.last_lit]=255&Se,Ve.last_lit++,Re===0?Ve.dyn_ltree[2*Se]++:(Ve.matches++,Re--,Ve.dyn_ltree[2*(O[Se]+u+1)]++,Ve.dyn_dtree[2*se(Re)]++),Ve.last_lit===Ve.lit_bufsize-1},r._tr_align=function(Ve){ce(Ve,2,3),fe(Ve,C,M),(function(Re){Re.bi_valid===16?(ae(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)})(Ve)}},{"../utils/common":41}],53:[function(o,i,r){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(o,i,r){(function(s){(function(a,A){if(!a.setImmediate){var c,l,g,u,h=1,d={},_=!1,m=a.document,p=Object.getPrototypeOf&&Object.getPrototypeOf(a);p=p&&p.setTimeout?p:a,c={}.toString.call(a.process)==="[object process]"?function(y){n.nextTick(function(){f(y)})}:(function(){if(a.postMessage&&!a.importScripts){var y=!0,E=a.onmessage;return a.onmessage=function(){y=!1},a.postMessage("","*"),a.onmessage=E,y}})()?(u="setImmediate$"+Math.random()+"$",a.addEventListener?a.addEventListener("message",C,!1):a.attachEvent("onmessage",C),function(y){a.postMessage(u+y,"*")}):a.MessageChannel?((g=new MessageChannel).port1.onmessage=function(y){f(y.data)},function(y){g.port2.postMessage(y)}):m&&"onreadystatechange"in m.createElement("script")?(l=m.documentElement,function(y){var E=m.createElement("script");E.onreadystatechange=function(){f(y),E.onreadystatechange=null,l.removeChild(E),E=null},l.appendChild(E)}):function(y){setTimeout(f,0,y)},p.setImmediate=function(y){typeof y!="function"&&(y=new Function(""+y));for(var E=new Array(arguments.length-1),B=0;B<E.length;B++)E[B]=arguments[B+1];var Q={callback:y,args:E};return d[h]=Q,c(h),h++},p.clearImmediate=I}function I(y){delete d[y]}function f(y){if(_)setTimeout(f,0,y);else{var E=d[y];if(E){_=!0;try{(function(B){var Q=B.callback,b=B.args;switch(b.length){case 0:Q();break;case 1:Q(b[0]);break;case 2:Q(b[0],b[1]);break;case 3:Q(b[0],b[1],b[2]);break;default:Q.apply(A,b)}})(E)}finally{I(y),_=!1}}}}function C(y){y.source===a&&typeof y.data=="string"&&y.data.indexOf(u)===0&&f(+y.data.slice(u.length))}})(typeof self>"u"?s===void 0?this:s:self)}).call(this,typeof PC<"u"?PC:typeof self<"u"?self:typeof window<"u"?window:{})},{}]},{},[10])(10)})})(G7e)),G7e.exports}var vXo=DXo();const O7e=ty(vXo),PXo=async({circuitJson:t,projectName:e})=>{await Rs.promise((async()=>{const n=new O7e,[{stringifyGerberCommandLayers:o,convertSoupToGerberCommands:i,convertSoupToExcellonDrillCommands:r,stringifyExcellonDrill:s},{convertCircuitJsonToBomRows:a,convertBomRowsToCsv:A},{convertCircuitJsonToPickAndPlaceCsv:c}]=await Promise.all([oE("circuit-json-to-gerber"),oE("circuit-json-to-bom-csv"),oE("circuit-json-to-pnp-csv")]),l=t.filter(f=>!("error_type"in f)&&!("warning_type"in f)),g=i(l,{flip_y_axis:!1}),u=o(g);for(const[f,C]of Object.entries(u))n.file(`gerber/${f}.gbr`,C);const h=r({circuitJson:l,is_plated:!0,flip_y_axis:!1}),d=s(h);n.file("gerber/drill.drl",d);const _=await a({circuitJson:t}),m=await A(_);n.file("bom.csv",m);const p=await c(t,{supplier:"jlcpcb"});n.file("pick_and_place.csv",p);const I=await n.generateAsync({type:"blob"});iQ(I,{fileName:`${e}_fabrication_files.zip`})})(),{loading:"Generating fabrication files...",success:"Fabrication ZIP ready",error:n=>`Failed to generate fabrication files: ${n instanceof Error?n.message:String(n)}`})},wXo=async t=>{const{createFdmComponentBox:e,renderFdmComponentBoxPng:n}=await oE("circuit-json-to-fdm-component-box"),[o,i]=await Promise.all([e(t),n(t,{},{width:960,height:640})]);return{...o,previewPng:i}},MXo=async t=>{const{createFdmComponentBox:e}=await oE("circuit-json-to-fdm-component-box");return e(t)},iOt=({generatedBox:t,projectName:e})=>{const n=Uint8Array.from(t.threeMf);iQ(new Blob([n.buffer],{type:"model/3mf"}),{fileName:`${a7e(e)}-component-box.3mf`})},NXo=async({circuitJson:t,projectName:e})=>{await Rs.promise((async()=>{const n=await MXo(t);iOt({generatedBox:n,projectName:e})})(),{loading:"Generating component box...",success:"Component box 3MF ready",error:n=>`Failed to generate component box: ${n instanceof Error?n.message:String(n)}`})},RXo=async({circuitJson:t,projectName:e})=>{let n;try{const{convertCircuitJsonToGltf:o}=await oE("circuit-json-to-gltf");console.log("convertCircuitJsonToGltf",o);const i=await o(t,{format:"glb",boardTextureResolution:1024});if(!i||!(i instanceof ArrayBuffer))throw new Error("Invalid GLB data returned from converter");n=new Blob([i],{type:"model/gltf-binary"})}catch(o){console.error("GLB Export Error:",o);return}iQ(n,{fileName:`${e}.glb`})},TXo=async({circuitJson:t,libraryName:e})=>{const{CircuitJsonToKicadLibraryConverter:n}=await oE("circuit-json-to-kicad"),o=new n(t,{libraryName:e,footprintLibraryName:e});o.runUntilFinished();const i=o.getOutput(),r=new O7e;r.file(`${e}.kicad_sym`,i.kicadSymString);for(const s of i.footprints){const a=r.folder(`${e}.pretty`);a&&a.file(`${s.footprintName}.kicad_mod`,`${s.kicadModString}
|
|
5774
5774
|
`)}if(i.model3dSourcePaths.length>0){const s=r.folder(`${e}.3dshapes`);if(s)for(const a of i.model3dSourcePaths)try{const A=a.split("/").pop()||a,c=await fetch(a);if(c.ok){const l=await c.arrayBuffer();s.file(A,l)}}catch{}}return r.file("fp-lib-table",i.fpLibTableString),r.file("sym-lib-table",i.symLibTableString),r},kXo=async({circuitJson:t,projectName:e})=>{await Rs.promise((async()=>{const o=await(await TXo({circuitJson:t,libraryName:e})).generateAsync({type:"blob"});iQ(o,{fileName:`${e}_kicad_library.zip`})})(),{loading:"Generating KiCad library...",success:"KiCad library ZIP ready",error:n=>`Failed to generate KiCad library: ${n instanceof Error?n.message:String(n)}`})},FXo=async({circuitJson:t,projectName:e})=>{const{CircuitJsonToKicadPcbConverter:n,CircuitJsonToKicadSchConverter:o,CircuitJsonToKicadProConverter:i,resolveAndLoadKicad3dModelFiles:r}=await oE("circuit-json-to-kicad"),s=new o(t);s.runUntilFinished();const a=s.getOutputString(),A=new n(t,{includeBuiltin3dModels:!0,projectName:e});A.runUntilFinished();const c=A.getOutputString(),l=new i(t,{projectName:e,schematicFilename:`${e}.kicad_sch`,pcbFilename:`${e}.kicad_pcb`});l.runUntilFinished();const g=l.getOutputString(),u=new O7e;return u.file(`${e}.kicad_sch`,a),u.file(`${e}.kicad_pcb`,c),u.file(`${e}.kicad_pro`,g),await r({projectName:e,model3dSourcePaths:A.getModel3dSourcePaths(),fetch,onModelFile:({outputPath:h,content:d})=>{u.file(h,d)},onError:({sourcePath:h})=>{console.warn(`Failed to load 3D model from ${h}`)}}),u},LXo=async({circuitJson:t,projectName:e})=>{await Rs.promise((async()=>{const o=await(await FXo({circuitJson:t,projectName:e})).generateAsync({type:"blob"});iQ(o,{fileName:`${e}_kicad_project.zip`})})(),{loading:"Generating KiCad project...",success:"KiCad project ZIP ready",error:n=>`Failed to generate KiCad project: ${n instanceof Error?n.message:String(n)}`})},rOt=async({circuitJson:t,projectName:e,options:n={}})=>{try{const{convertCircuitJsonToLbrn:o}=await oE("circuit-json-to-lbrn"),r=(await o(t,{includeSilkscreen:n.includeSilkscreen??!1,includeOxidationCleaningLayer:n.includeOxidationCleaningLayer??!0})).toXml(),s=new Blob([r],{type:"application/lbrn"});iQ(s,{fileName:`${e}.lbrn2`})}catch(o){const i=o instanceof Error?o.message:"Unknown error";Rs.error(`Failed to export to LBRN format: ${i}`)}},HXo=async({circuitJson:t,projectName:e})=>{const{convertCircuitJsonToPinoutSvg:n}=await oE("circuit-to-svg"),o=n(t);iQ(o,{fileName:`${e}-pinout.svg`,mimeType:"image/svg+xml"})},GXo=async({circuitJson:t,projectName:e})=>{const{circuitJsonToStep:n}=await oE("circuit-json-to-step"),o=t.find(c=>c.type==="pcb_board"),i=o&&"width"in o?o.width:void 0,r=o&&"height"in o?o.height:void 0,s=o&&"thickness"in o?o.thickness:void 0;if(i===void 0||r===void 0||s===void 0){Rs.error("Board dimensions not found. Please add a pcb_board with width, height, and thickness to your circuit.");return}let a;try{a=await n(t,{boardWidth:i,boardHeight:r,boardThickness:s,productName:e,includeComponents:!0,includeExternalMeshes:!0})}catch(c){const l=c instanceof Error?c.message:"Unknown error";Rs.error(`Failed to convert circuit to STEP format: ${l}`);return}const A=new Blob([a],{type:"application/step"});try{iQ(A,{fileName:`${e}.step`})}catch(c){const l=c instanceof Error?c.message:"Unknown error";Rs.error(`Failed to download STEP file: ${l}`)}},OXo=[{extension:"json",name:"Circuit JSON"},{extension:"json",name:"Simple Route JSON"},{extension:"zip",name:"Fabrication Files"},{extension:"zip",name:"KiCad Project"},{extension:"zip",name:"KiCad Library"},{extension:"glb",name:"GLB (Binary GLTF)"},{extension:"svg",name:"Pinout SVG"},{extension:"step",name:"STEP"},{extension:"lbrn2",name:"LightBurn"}],KXo=async({exportName:t,circuitJson:e,simpleRouteJson:n,projectName:o})=>{const i=a7e(o);if(t==="Fabrication Files"){await PXo({circuitJson:e,projectName:i});return}if(t==="KiCad Project"){await LXo({circuitJson:e,projectName:i});return}if(t==="KiCad Library"){await kXo({circuitJson:e,projectName:i});return}if(t==="Circuit JSON"){iQ(JSON.stringify(e,null,2),{fileName:`${i}.circuit.json`,mimeType:"application/json"});return}if(t==="Simple Route JSON"){if(!n)throw new Error("No Simple Route JSON available to export");iQ(JSON.stringify(n,null,2),{fileName:`${i}.simple-route.json`,mimeType:"application/json"});return}if(t==="GLB (Binary GLTF)"){await RXo({circuitJson:e,projectName:i});return}if(t==="Pinout SVG"){HXo({circuitJson:e,projectName:i});return}if(t==="STEP"){await GXo({circuitJson:e,projectName:i});return}if(t==="Component Box (3MF)"){await NXo({circuitJson:e,projectName:i});return}if(t==="LightBurn"){await rOt({circuitJson:e,projectName:i});return}throw new Error(`Unsupported export type: "${t}"`)},UXo=({packageName:t,onSelectReview:e})=>{const n=ju(g=>g.fsMap),o=ju(g=>g.circuitJson),[i,r]=X.useState([]),[s,a]=X.useState(!1),[A,c]=X.useState(!1);X.useEffect(()=>{!t||!Rne()||(a(!0),BK.get("ai_reviews/list",{searchParams:{package_name:t}}).json().then(g=>r(g.ai_reviews)).catch(g=>{console.error("Failed to load AI reviews",g),Rs.error("Failed to load AI reviews")}).finally(()=>a(!1)))},[t]);const l=async()=>{if(!o){Rs.error("Need Circuit JSON to Request AI Review");return}if(!Rne()){Rs.error("Missing registry token");return}c(!0);try{const{ai_review:g}=await BK.post("ai_reviews/create",{json:{package_name:t??"unknown",fs_map:Object.fromEntries(n),circuit_json:o}}).json();r(u=>[g,...u]),e(g),Rs.success("AI review requested")}catch(g){console.error("Failed to create AI review",g),Rs.error("Failed to request AI review")}finally{c(!1)}};return z.jsxs(z.Fragment,{children:[z.jsxs(nw,{children:[z.jsx(ow,{children:"AI Review"}),z.jsx($6,{children:"Select an AI review or request a new one."})]}),z.jsx("div",{className:"rf-flex rf-gap-4 rf-mt-4",children:z.jsx("div",{className:"rf-w-48 rf-h-64 rf-overflow-y-auto rf-border rf-rounded rf-p-2 rf-flex-shrink-0",children:s?z.jsx("div",{className:"rf-text-sm",children:"Loading..."}):i.length>0?i.map(g=>z.jsx("div",{className:"rf-text-sm rf-p-2 rf-cursor-pointer rf-rounded hover:rf-bg-zinc-100",onClick:()=>e(g),children:new Date(g.created_at||"").toLocaleString()},g.ai_review_id)):z.jsx("div",{className:"rf-text-sm rf-text-muted-foreground",children:"No AI reviews found."})})}),z.jsx(Kk,{className:"rf-mt-4",children:z.jsx(fa,{onClick:l,disabled:A,children:A?"Requesting...":"Review my Board"})})]})};function K7e(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}var Z6=K7e();function sOt(t){Z6=t}var WY={exec:()=>null};function El(t,e=""){let n=typeof t=="string"?t:t.source;const o={replace:(i,r)=>{let s=typeof r=="string"?r:r.source;return s=s.replace(a1.caret,"$1"),n=n.replace(i,s),o},getRegex:()=>new RegExp(n,e)};return o}var a1={codeRemoveIndent:/^(?: {1,4}| {0,3}\t)/gm,outputLinkReplace:/\\([\[\]])/g,indentCodeCompensation:/^(\s+)(?:```)/,beginningSpace:/^\s+/,endingHash:/#$/,startingSpaceChar:/^ /,endingSpaceChar:/ $/,nonSpaceChar:/[^ ]/,newLineCharGlobal:/\n/g,tabCharGlobal:/\t/g,multipleSpaceGlobal:/\s+/g,blankLine:/^[ \t]*$/,doubleBlankLine:/\n[ \t]*\n[ \t]*$/,blockquoteStart:/^ {0,3}>/,blockquoteSetextReplace:/\n {0,3}((?:=+|-+) *)(?=\n|$)/g,blockquoteSetextReplace2:/^ {0,3}>[ \t]?/gm,listReplaceTabs:/^\t+/,listReplaceNesting:/^ {1,4}(?=( {4})*[^ ])/g,listIsTask:/^\[[ xX]\] /,listReplaceTask:/^\[[ xX]\] +/,anyLine:/\n.*\n/,hrefBrackets:/^<(.*)>$/,tableDelimiter:/[:|]/,tableAlignChars:/^\||\| *$/g,tableRowBlankLine:/\n[ \t]*$/,tableAlignRight:/^ *-+: *$/,tableAlignCenter:/^ *:-+: *$/,tableAlignLeft:/^ *:-+ *$/,startATag:/^<a /i,endATag:/^<\/a>/i,startPreScriptTag:/^<(pre|code|kbd|script)(\s|>)/i,endPreScriptTag:/^<\/(pre|code|kbd|script)(\s|>)/i,startAngleBracket:/^</,endAngleBracket:/>$/,pedanticHrefTitle:/^([^'"]*[^\s])\s+(['"])(.*)\2/,unicodeAlphaNumeric:/[\p{L}\p{N}]/u,escapeTest:/[&<>"']/,escapeReplace:/[&<>"']/g,escapeTestNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,escapeReplaceNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/g,unescapeTest:/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig,caret:/(^|[^\[])\^/g,percentDecode:/%25/g,findPipe:/\|/g,splitPipe:/ \|/,slashPipe:/\\\|/g,carriageReturn:/\r\n|\r/g,spaceLine:/^ +$/gm,notSpaceStart:/^\S*/,endingNewline:/\n$/,listItemRegex:t=>new RegExp(`^( {0,3}${t})((?:[ ][^\\n]*)?(?:\\n|$))`),nextBulletRegex:t=>new RegExp(`^ {0,${Math.min(3,t-1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`),hrRegex:t=>new RegExp(`^ {0,${Math.min(3,t-1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`),fencesBeginRegex:t=>new RegExp(`^ {0,${Math.min(3,t-1)}}(?:\`\`\`|~~~)`),headingBeginRegex:t=>new RegExp(`^ {0,${Math.min(3,t-1)}}#`),htmlBeginRegex:t=>new RegExp(`^ {0,${Math.min(3,t-1)}}<(?:[a-z].*>|!--)`,"i")},YXo=/^(?:[ \t]*(?:\n|$))+/,zXo=/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,VXo=/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,jY=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,JXo=/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,U7e=/(?:[*+-]|\d{1,9}[.)])/,aOt=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,AOt=El(aOt).replace(/bull/g,U7e).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/\|table/g,"").getRegex(),qXo=El(aOt).replace(/bull/g,U7e).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/table/g,/ {0,3}\|?(?:[:\- ]*\|)+[\:\- ]*\n/).getRegex(),Y7e=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,WXo=/^[^\n]+/,z7e=/(?!\s*\])(?:\\.|[^\[\]\\])+/,jXo=El(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label",z7e).replace("title",/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),XXo=El(/^( {0,3}bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g,U7e).getRegex(),Sae="address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|search|section|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul",V7e=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,$Xo=El("^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>\\n*|$)|<![A-Z][\\s\\S]*?(?:>\\n*|$)|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>\\n*|$)|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|</(?!script|pre|style|textarea)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$))","i").replace("comment",V7e).replace("tag",Sae).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),cOt=El(Y7e).replace("hr",jY).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("|table","").replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",Sae).getRegex(),ZXo=El(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph",cOt).getRegex(),J7e={blockquote:ZXo,code:zXo,def:jXo,fences:VXo,heading:JXo,hr:jY,html:$Xo,lheading:AOt,list:XXo,newline:YXo,paragraph:cOt,table:WY,text:WXo},lOt=El("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr",jY).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("blockquote"," {0,3}>").replace("code","(?: {4}| {0,3} )[^\\n]").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",Sae).getRegex(),e$o={...J7e,lheading:qXo,table:lOt,paragraph:El(Y7e).replace("hr",jY).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("table",lOt).replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",Sae).getRegex()},t$o={...J7e,html:El(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment",V7e).replace(/tag/g,"(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:|[^\\w\\s@]*@)\\b").getRegex(),def:/^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,heading:/^(#{1,6})(.*)(?:\n+|$)/,fences:WY,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:El(Y7e).replace("hr",jY).replace("heading",` *#{1,6} *[^
|
|
5775
5775
|
]`).replace("lheading",AOt).replace("|table","").replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").replace("|tag","").getRegex()},n$o=/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,o$o=/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,gOt=/^( {2,}|\\)\n(?!\s*$)/,i$o=/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,bae=/[\p{P}\p{S}]/u,q7e=/[\s\p{P}\p{S}]/u,uOt=/[^\s\p{P}\p{S}]/u,r$o=El(/^((?![*_])punctSpace)/,"u").replace(/punctSpace/g,q7e).getRegex(),dOt=/(?!~)[\p{P}\p{S}]/u,s$o=/(?!~)[\s\p{P}\p{S}]/u,a$o=/(?:[^\s\p{P}\p{S}]|~)/u,A$o=/\[[^[\]]*?\]\((?:\\.|[^\\\(\)]|\((?:\\.|[^\\\(\)])*\))*\)|`[^`]*?`|<[^<>]*?>/g,hOt=/^(?:\*+(?:((?!\*)punct)|[^\s*]))|^_+(?:((?!_)punct)|([^\s_]))/,c$o=El(hOt,"u").replace(/punct/g,bae).getRegex(),l$o=El(hOt,"u").replace(/punct/g,dOt).getRegex(),_Ot="^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)",g$o=El(_Ot,"gu").replace(/notPunctSpace/g,uOt).replace(/punctSpace/g,q7e).replace(/punct/g,bae).getRegex(),u$o=El(_Ot,"gu").replace(/notPunctSpace/g,a$o).replace(/punctSpace/g,s$o).replace(/punct/g,dOt).getRegex(),d$o=El("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)","gu").replace(/notPunctSpace/g,uOt).replace(/punctSpace/g,q7e).replace(/punct/g,bae).getRegex(),h$o=El(/\\(punct)/,"gu").replace(/punct/g,bae).getRegex(),_$o=El(/^<(scheme:[^\s\x00-\x1f<>]*|email)>/).replace("scheme",/[a-zA-Z][a-zA-Z0-9+.-]{1,31}/).replace("email",/[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+(@)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(?![-_])/).getRegex(),m$o=El(V7e).replace("(?:-->|$)","-->").getRegex(),p$o=El("^comment|^</[a-zA-Z][\\w:-]*\\s*>|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>|^<\\?[\\s\\S]*?\\?>|^<![a-zA-Z]+\\s[\\s\\S]*?>|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>").replace("comment",m$o).replace("attribute",/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),Dae=/(?:\[(?:\\.|[^\[\]\\])*\]|\\.|`[^`]*`|[^\[\]\\`])*?/,I$o=El(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]*(?:\n[ \t]*)?)(title))?\s*\)/).replace("label",Dae).replace("href",/<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]*/).replace("title",/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),mOt=El(/^!?\[(label)\]\[(ref)\]/).replace("label",Dae).replace("ref",z7e).getRegex(),pOt=El(/^!?\[(ref)\](?:\[\])?/).replace("ref",z7e).getRegex(),f$o=El("reflink|nolink(?!\\()","g").replace("reflink",mOt).replace("nolink",pOt).getRegex(),W7e={_backpedal:WY,anyPunctuation:h$o,autolink:_$o,blockSkip:A$o,br:gOt,code:o$o,del:WY,emStrongLDelim:c$o,emStrongRDelimAst:g$o,emStrongRDelimUnd:d$o,escape:n$o,link:I$o,nolink:pOt,punctuation:r$o,reflink:mOt,reflinkSearch:f$o,tag:p$o,text:i$o,url:WY},C$o={...W7e,link:El(/^!?\[(label)\]\((.*?)\)/).replace("label",Dae).getRegex(),reflink:El(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",Dae).getRegex()},j7e={...W7e,emStrongRDelimAst:u$o,emStrongLDelim:l$o,url:El(/^((?:ftp|https?):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/,"i").replace("email",/[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/).getRegex(),_backpedal:/(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/,del:/^(~~?)(?=[^\s~])((?:\\.|[^\\])*?(?:\\.|[^\s~\\]))\1(?=[^~]|$)/,text:/^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|https?:\/\/|ftp:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/},y$o={...j7e,br:El(gOt).replace("{2,}","*").getRegex(),text:El(j7e.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()},vae={normal:J7e,gfm:e$o,pedantic:t$o},XY={normal:W7e,gfm:j7e,breaks:y$o,pedantic:C$o},E$o={"&":"&","<":"<",">":">",'"':""","'":"'"},IOt=t=>E$o[t];function mb(t,e){if(e){if(a1.escapeTest.test(t))return t.replace(a1.escapeReplace,IOt)}else if(a1.escapeTestNoEncode.test(t))return t.replace(a1.escapeReplaceNoEncode,IOt);return t}function fOt(t){try{t=encodeURI(t).replace(a1.percentDecode,"%")}catch{return null}return t}function COt(t,e){const n=t.replace(a1.findPipe,(r,s,a)=>{let A=!1,c=s;for(;--c>=0&&a[c]==="\\";)A=!A;return A?"|":" |"}),o=n.split(a1.splitPipe);let i=0;if(o[0].trim()||o.shift(),o.length>0&&!o.at(-1)?.trim()&&o.pop(),e)if(o.length>e)o.splice(e);else for(;o.length<e;)o.push("");for(;i<o.length;i++)o[i]=o[i].trim().replace(a1.slashPipe,"|");return o}function $Y(t,e,n){const o=t.length;if(o===0)return"";let i=0;for(;i<o&&t.charAt(o-i-1)===e;)i++;return t.slice(0,o-i)}function x$o(t,e){if(t.indexOf(e[1])===-1)return-1;let n=0;for(let o=0;o<t.length;o++)if(t[o]==="\\")o++;else if(t[o]===e[0])n++;else if(t[o]===e[1]&&(n--,n<0))return o;return n>0?-2:-1}function yOt(t,e,n,o,i){const r=e.href,s=e.title||null,a=t[1].replace(i.other.outputLinkReplace,"$1");o.state.inLink=!0;const A={type:t[0].charAt(0)==="!"?"image":"link",raw:n,href:r,title:s,text:a,tokens:o.inlineTokens(a)};return o.state.inLink=!1,A}function B$o(t,e,n){const o=t.match(n.other.indentCodeCompensation);if(o===null)return e;const i=o[1];return e.split(`
|