UNPKG

@wayrisignals/kicad-webview

Version:

Interactive KiCad schematic, PCB and 3D viewer for the web, with Gerber, Excellon, linked views and offline HTML exports

3 lines (2 loc) • 21.3 kB
/*! KiCad WebView 1.2.1 | Copyright (c) 2026 wayri | SPDX-License-Identifier: MPL-2.0 | Source: https://github.com/wayri/kicad-webview/tree/v1.2.1 | Keep LICENSE and THIRD-PARTY-NOTICES.md; bundled dependencies retain their licenses. */ import{b as fe}from"./chunk-TZWR7E27.js";var ge=fe((ue,ae)=>{(ee=>{"use strict";let m=l=>l&&typeof l=="object"&&!Array.isArray(l)?l.quoted:l;function ne(l){let c=l.find(s=>Array.isArray(s)&&s[0]==="embedded_files");if(!c)return;let e=new Map,i=0;for(let s of c){if(!Array.isArray(s)||s[0]!=="file")continue;let b=r=>s.find(g=>Array.isArray(g)&&g[0]===r),d=m(b("name")?.[1]);if(m(b("type")?.[1])!=="font"||typeof d!="string"||d.length>255||!/[.](ttf|otf)$/i.test(d))continue;if(e.has(d)){e.set(d,null);continue}let S=b("data");if(!S)continue;let n=0;for(let r=1;r<S.length&&n<=3e6;r++)n+=String(m(S[r])).length;if(n>3e6||i+n>8e6||e.size>=16)continue;let o=S.slice(1).map(m).join("");!o.startsWith("|")||!o.endsWith("|")||(i+=n,e.set(d,{name:d,base64:o.slice(1,-1),checksum:m(b("checksum")?.[1])}))}let t=[...e.values()].filter(Boolean);return t.length?t:void 0}let re="version generator generator_version uuid paper title_block embedded_fonts embedded_files".split(" "),G={kicad_pcb:new Set([...re,..."general layers setup net footprint segment arc via zone gr_line gr_arc gr_rect gr_circle gr_poly gr_text gr_curve gr_text_box gr_bitmap dimension target property group image".split(" ")]),kicad_sch:new Set([...re,..."lib_symbols symbol sheet wire bus bus_entry junction no_connect label global_label hierarchical_label netclass_flag directive_label text text_box table image rule_area polyline rectangle circle arc sheet_instances symbol_instances group".split(" ")])};function P(l){if(l.length>4096)throw Error("expression length limit");let c=[],e=0;for(;e<l.length;){if(/\s/.test(l[e])){e++;continue}let n=/^(?:(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?|[a-zA-Z_][a-zA-Z_0-9]*|[+*/%^(),-])/.exec(l.slice(e));if(!n)throw Error("unsupported expression syntax, unit or function");if(c.push(n[0]),e+=n[0].length,c.length>256)throw Error("expression token limit")}let i=0,t=n=>{if(!Number.isFinite(n))throw Error("non-finite expression result or invalid domain");return n},s=n=>c[i]===n?(i++,!0):!1;function b(n){if(n>32)throw Error("expression nesting limit");if(s("(")){let v=d(0,n+1);if(!s(")"))throw Error("missing closing parenthesis");return v}let o=c[i++];if(o===void 0)throw Error("missing expression operand");if(/^(?:\d|\.)/.test(o))return t(Number(o));if(!/^[a-z]/.test(o)||!s("("))throw Error("unsupported expression syntax, unit or function");let r=[];if(!s(")")){do r.push(d(0,n+1));while(s(","));if(!s(")"))throw Error("missing closing parenthesis")}let g={abs:Math.abs,sqrt:Math.sqrt,floor:Math.floor,ceil:Math.ceil};if(Object.prototype.hasOwnProperty.call(g,o)){if(r.length!==1)throw Error("invalid function argument count");return t(g[o](r[0]))}if(o==="pow"){if(r.length!==2)throw Error("invalid function argument count");return t(Math.pow(r[0],r[1]))}if(["min","max","sum","avg"].includes(o)){if(!r.length)throw Error("invalid function argument count");return t(o==="min"?Math.min(...r):o==="max"?Math.max(...r):r.reduce((v,E)=>v+E,0)/(o==="avg"?r.length:1))}throw Error("unsupported expression function "+o)}function d(n,o){if(o>32)throw Error("expression nesting limit");let r=s("+")?d(3,o+1):s("-")?-d(3,o+1):b(o+1),g={"+":1,"-":1,"*":2,"/":2,"%":2,"^":3};for(;Object.prototype.hasOwnProperty.call(g,c[i])&&g[c[i]]>=n;){let v=c[i++],E=d(g[v]+(v==="^"?0:1),o+1);if((v==="/"||v==="%")&&E===0)throw Error("division or modulo by zero");r=t(v==="+"?r+E:v==="-"?r-E:v==="*"?r*E:v==="/"?r/E:v==="%"?r%E:Math.pow(r,E))}return t(r)}let S=d(0,0);if(i!==c.length)throw Error("unsupported expression syntax, unit or function");return String(Object.is(S,-0)?0:S)}function k(l,c=()=>{}){let e=String(l??""),i=[],t=0;if(!e.includes("@{"))return{value:e,expressions:i};if(e.length>65536){let d="text expression input limit";return c(d+"; preserved literally."),{value:e,expressions:[{raw:e,value:e,status:"unresolved",reason:d}]}}let s=(d,S)=>{let n=1,o=null;for(let r=S+2;r<d.length;r++){let g=d[r];if(o){if(g==="\\"){r++;continue}g===o&&(o=null);continue}if(g==='"'||g==="'"){o=g;continue}if(g==="{")n++;else if(g==="}"&&!--n)return r}return-1};function b(d,S,n){if(S>16)throw Error("nested text expression limit");let o="",r=0,g;for(;(g=d.indexOf("@{",r))>=0;){if(t>=128){let N="text expression count limit";if(!n)throw Error(N);let J=d.slice(g);return i.push({raw:J,value:J,status:"unresolved",reason:N}),c(N+"; remaining text preserved literally."),o+d.slice(r)}o+=d.slice(r,g);let v=s(d,g),E=d.slice(g,v<0?d.length:v+1),M=E,V;try{if(++t>128)throw Error("text expression count limit");if(v<0)throw Error("unclosed text expression");if(E.length>4099)throw Error("expression length limit");M=P(b(E.slice(2,-1),S+1,!1))}catch(N){if(V=N.message,!n)throw N;c("Unsupported or invalid text expression: "+V+"; preserved literally.")}n&&i.push({raw:E,value:M,status:V?"unresolved":"resolved",...V?{reason:V}:{}}),o+=M,r=v<0?d.length:v+1}return o+d.slice(r)}return{value:b(e,0,!0),expressions:i}}function oe(l,c){let e=t=>{if(typeof t!="string"||t.length>4096||/[\x00-\x20\x7f]/.test(t))return null;if(/^#[^#/?\\]{1,64}$/.test(t))return{kind:"sheet",page:t.slice(1),target:t};if(!/^https?:\/\//i.test(t))return null;try{let s=new URL(t);return s.username||s.password||!s.hostname?null:{kind:"web",target:s.href}}catch{return null}};if(c!==void 0&&c!=="")return[e(c)].filter(Boolean);let i=new Map;for(let t of String(l??"").slice(0,65536).matchAll(/https?:\/\/[^\s<>"\u0000-\u001f]+/gi)){let s=e(t[0].replace(/[.,;!]+$/,""));if(s&&i.set(s.target,s),i.size>=32)break}return[...i.values()]}function Z(l,c={},e=()=>{}){let i=f=>{let u=Object.fromEntries((f||[]).filter(y=>Array.isArray(y)&&m(y[0])==="property").map(y=>[String(m(y[1])),String(m(y[2])??"")]));for(let y of["Reference","Value","Footprint","Datasheet","Description"])Object.prototype.hasOwnProperty.call(u,y)&&(u[y.toUpperCase()]=u[y]);return u},t=(c.sheetContexts||[]).map(f=>({...f,fields:Object.assign(Object.create(null),f.fields)})),s=new Set(c.unavailableVariables||[]),b=Object.create(null),d=Object.create(null),S=(l||[]).find(f=>Array.isArray(f)&&m(f[0])==="title_block"),n=(f,u,y)=>{b[f]=u,d[f]=y};for(let f of S||[]){if(!Array.isArray(f))continue;let u=String(m(f[0]));["title","date","rev","company"].includes(u)&&n({title:"TITLE",date:"ISSUE_DATE",rev:"REVISION",company:"COMPANY"}[u],String(m(f[1])??""),"Title block"),u==="comment"&&n("COMMENT"+m(f[1]),String(m(f[2])??""),"Title block")}let o=c.textVariables||c.project?.text_variables||c.projectSettings?.text_variables||{},r=Object.create(null);for(let[f,u]of Object.entries(o))typeof u=="string"&&f.length<=200&&u.length<=65536&&(r[f]=u,Object.prototype.hasOwnProperty.call(b,f)||n(f,u,"Project"));for(let[f,u]of Object.entries(i(l)))n(f,u,"Drawing field");typeof c.path=="string"&&(n("FILENAME",c.path.split("/").pop(),"Drawing context"),n("FILEPATH",c.path,"Drawing context"));for(let[f,u]of[["#",c.sheetNumber],["##",c.sheetCount],["SHEETNAME",c.sheetName],["PROJECTNAME",c.projectName]])u!==void 0&&n(f,String(u),"Sheet context");let g=new Map;for(let f of l||[]){if(!Array.isArray(f)||!["symbol","footprint","module"].includes(m(f[0])))continue;let u=i(f),y=u.Reference;y&&g.set(y,g.has(y)?null:u)}let v=(f,u)=>{if(Object.prototype.hasOwnProperty.call(f||{},u))return u;let y=Object.keys(f||{}).filter(T=>T.toUpperCase()===u.toUpperCase());return y.length===1?y[0]:null},E=new Set;function M(f,u={},y=0,T=!1){let j=String(f??""),A=new Map,a=new Set;if(!j.includes("${")&&!j.includes("@{"))return{raw:j,value:j,fromVariable:!1,variables:[],unresolved:[],status:"literal"};u=Object.assign(Object.create(null),u);for(let I of["Reference","Value","Footprint","Datasheet","Description"])Object.prototype.hasOwnProperty.call(u,I)&&(u[I.toUpperCase()]=u[I]);let p=0,h=(I,Y=[],Q=u,F=0,_=!1)=>I.replace(/\$\{([^{}]{1,200})\}/g,(U,x)=>{let z=x.lastIndexOf(":"),q=z>0?g.get(x.slice(0,z)):null,se=z>0?x.slice(z+1):x,K,D=x,$,L=Q,W=F,X=_;if(!_&&z>0&&g.has(x.slice(0,z)))K=q,D=v(q,se),$="Reference "+x.slice(0,z),L=q||{};else if(!_&&v(Q,x)!==null)K=Q,D=v(Q,x),$=Q===u?"Selected object field":"Referenced object field";else if(!_&&s.has(x))$="Ambiguous sheet instance";else{let te=_?-1:t.findIndex((pe,he)=>he>=F&&Object.prototype.hasOwnProperty.call(pe.fields,x));te>F&&Object.prototype.hasOwnProperty.call(b,x)&&d[x]!=="Project"&&(te=-1),te>=0?(K=t[te].fields,$=t[te].source||"Sheet field",L={},W=te):(K=_?r:b,$=_?"Project":d[x],($==="Project"||$==="Title block")&&(L={},X=!0))}if(!K||!Object.prototype.hasOwnProperty.call(K,D)||typeof K[D]!="string")return a.add(x),A.set(x,{name:x,source:$==="Ambiguous sheet instance"?$:z>0&&g.has(x.slice(0,z))?"Ambiguous or missing reference field":"Unavailable",raw:U}),E.has(x)||(E.add(x),e("Unresolved saved text variable "+U+"; preserved literally.")),U;let ce=$+"\0"+x+"\0"+W;return++p>256||Y.length>=8||Y.includes(ce)?(a.add(x),E.has(x)||(E.add(x),e("Text variable "+U+" is recursive or exceeds the substitution limit; preserved literally.")),U):(A.set(x,{name:x,source:$||"Saved field",raw:K[D]}),h(K[D],Y.concat(ce),L,W,X))}),w=h(j,[],u,y,T);w.length>65536&&(e("Expanded text exceeds the saved-text limit; preserved literally."),w=j,a.add("Expansion limit"));let B=k(w,e);w=B.value;for(let I of B.expressions)I.status==="unresolved"&&a.add(I.raw);return{raw:j,value:w,fromVariable:j.includes("${"),fromExpression:B.expressions.length>0,expressions:B.expressions,variables:[...A.values()],unresolved:[...a],status:a.size?"unresolved":"resolved"}}let V=(f,u={})=>M(f,u).value;function N(f={},{includeShadowed:u=!1}={}){let y=new Set([...Object.keys(b),...t.flatMap(j=>Object.keys(j.fields)),...s,...Object.keys(f)]);for(let j of[...Object.values(b),...t.flatMap(A=>Object.values(A.fields)),...Object.values(f)])if(typeof j=="string")for(let A of j.matchAll(/\$\{([^{}]{1,200})\}/g))y.add(A[1]);let T=[...y].sort().slice(0,512).map(j=>{let A=M("${"+j+"}",f),a=A.variables.find(p=>p.name===j);return{name:j,source:a?.source||"Unavailable",raw:a?.raw??"${"+j+"}",value:A.value,status:A.status,unresolved:A.unresolved}});if(u){let j=(A,a,p,h,w)=>{T.some(B=>B.name===A&&B.source===a)||T.push({name:A,source:a,raw:p,value:h.value,status:h.status,unresolved:h.unresolved,scope:w,shadowed:!0})};for(let[A,a]of Object.entries(r))j(A,"Project",a,M("${"+A+"}",{},0,!0),"project");for(let[A,a]of t.entries())for(let[p,h]of Object.entries(a.fields))j(p,a.source||"Sheet field",h,M("${"+p+"}",{},A),"sheet")}return T.slice(0,1024)}function J(f){let u=Object.create(null),y=Object.create(null);for(let[T,j]of Object.entries(f||{})){let A=M(j,f);u[T]=A.value,(A.fromVariable||A.fromExpression)&&(y[T]=A)}return{values:u,provenance:y}}return{resolve:V,fields:i,inspect:M,list:N,properties:J}}function ie(l,c,{rootFile:e=c,instancePath:i,parse:t}={}){let s=(a,p)=>(a||[]).find(h=>Array.isArray(h)&&m(h[0])===p),b=(a,p)=>m(s(a,p)?.[1]),d=new Map((l||[]).map(a=>[a.path,a])),S=new Map,n=[],o=a=>{if(S.has(a))return S.get(a);let p=d.get(a),h=p?.ast;try{!h&&p&&t&&(h=t(p.content,p))}catch{}return S.set(a,h),h},r=a=>Object.fromEntries((a||[]).filter(p=>Array.isArray(p)&&m(p[0])==="property").map(p=>[String(m(p[1])),String(m(p[2])??"")])),g=(a,p)=>{if(typeof p!="string"||!p||/^(?:[a-z]+:|[\\/])/i.test(p)||p.includes("${"))return null;let h=a.split("/").slice(0,-1);for(let w of p.replace(/\\/g,"/").split("/"))if(w===".."){if(!h.length)return null;h.pop()}else w&&w!=="."&&h.push(w);return h.join("/")},v=0,E=!1;function M(a,p,h,w,B){if(++v>512||B.length>=32||B.includes(a)){E=!0;return}let I=o(a);if(!I)return;let Y=h.every(Boolean)?"/"+h.join("/"):null,Q=w.every(F=>typeof F=="string")?w.length?"/"+w.join("/")+"/":"/":void 0;a===c&&n.push({instancePath:Y,parentPath:B.at(-1)||null,parentInstancePath:h.length>1&&h.every(Boolean)?"/"+h.slice(0,-1).join("/"):null,sheetContexts:p,sheetName:w.length?w.at(-1):"/",sheetPath:Q,...T.has(Y)?{sheetNumber:T.get(Y)}:{}});for(let F of(I||[]).filter(_=>Array.isArray(_)&&m(_[0])==="sheet")){let _=r(F),U=g(a,_.Sheetfile??_["Sheet file"]),x=b(F,"uuid");if(!U||!d.has(U))continue;let z=_.Sheetname??_["Sheet name"],q=h.concat(x),se=w.concat(z),K=q.every(Boolean)?"/"+q.join("/"):null;for(let $ of(F||[]).filter(L=>Array.isArray(L)&&m(L[0])==="instances"))for(let L of $.filter(W=>Array.isArray(W)&&m(W[0])==="project"))for(let W of L.filter(X=>Array.isArray(X)&&m(X[0])==="path"))if(String(m(W[1])).replace(/\/$/,"")===Y){let X=b(W,"page");K&&X!==void 0&&T.set(K,String(X))}let D={..._,SHEETFILE:_.Sheetfile??_["Sheet file"]};z!==void 0&&(D.SHEETNAME=z),se.every($=>typeof $=="string")&&(D.SHEETPATH="/"+se.join("/")+"/"),M(U,[{fields:D,source:D.SHEETPATH?"Sheet "+D.SHEETPATH:"Sheet fields ("+U+")",instancePath:q.every(Boolean)?"/"+q.join("/"):null},...p],q,se,B.concat(a))}}let V=new Map;for(let a of(l||[]).slice(0,512))for(let p of(o(a.path)||[]).filter(h=>Array.isArray(h)&&m(h[0])==="sheet")){let h=r(p),w=g(a.path,h.Sheetfile??h["Sheet file"]);w&&d.has(w)&&(V.has(w)||V.set(w,new Set),V.get(w).add(a.path))}let N=new Set,J=new Set;function f(a){if(J.has(a))return;J.add(a);let p=V.get(a);if(!p?.size)N.add(a);else for(let h of p)f(h)}f(e),N.size===1?e=[...N][0]:N.size!==1&&(E=!0);let u=o(e),y=b(u,"uuid"),T=new Map;for(let a of(u||[]).filter(p=>Array.isArray(p)&&m(p[0])==="sheet_instances"))for(let p of a.filter(h=>Array.isArray(h)&&m(h[0])==="path")){let h=String(m(p[1])).split("/").filter(Boolean);h[0]!==y&&h.unshift(y);let w=b(p,"page");h.every(Boolean)&&w!==void 0&&T.set("/"+h.join("/"),String(w))}M(e,[],[y],[],[]);let j=i?n.filter(a=>a.instancePath?.replace(/\/$/,"")===String(i).replace(/\/$/,"")):n;if(j.length===1&&!E)return{...j[0],contextStatus:"resolved",rootPath:e,instances:n};let A=[...new Set([...n.flatMap(a=>a.sheetContexts.flatMap(p=>Object.keys(p.fields))),"SHEETNAME","SHEETPATH","#"])];return{sheetContexts:[],unavailableVariables:A,contextStatus:j.length>1?"ambiguous":"unavailable",instances:n}}function H(l){let c=String(m(l?.[0])),e=S=>m(l.find(n=>Array.isArray(n)&&m(n[0])===S)?.[1]);if(!Array.isArray(l)||!G[c])throw Error("Unsupported KiCad drawing root.");let i=String(e("generator_version")??""),t=e("version")??null,s=/^(\d+)(?:\.|$)/.exec(i),b=[];s&&Number(s[1])>10&&b.push(`KiCad ${i} is a forward-compatibility preview: only recognized saved constructs are rendered; new version features are not verified.`);let d=[...new Set(l.filter(Array.isArray).map(S=>String(m(S[0]))).filter(S=>!G[c].has(S)))];return d.length&&b.push("Unrecognized saved drawing constructs omitted: "+d.slice(0,40).join(", ")+(d.length>40?" \u2026":"")),{majorVersion:s?Number(s[1]):null,kind:c,generatorVersion:i||null,formatVersion:t,forwardPreview:!!(s&&Number(s[1])>10),unknown:d,warnings:b}}let R=Object.freeze([{id:"drawing",label:"Saved schematic / PCB geometry",since:8,implemented:!0},{id:"review",label:"Selection, properties, comments and comparison",since:8,implemented:!0},{id:"hierarchy",label:"Sheet navigation and cross-sheet highlighting",since:8,implemented:!0},{id:"copper",label:"Saved copper fills and zone outlines",since:8,implemented:!0},{id:"models",label:"Repository-linked 3D models",since:8,implemented:!0},{id:"embeddedAssets",label:"Embedded fonts and 3D assets",since:9,implemented:!0,limitation:"Uses saved TrueType or OpenType faces and supported embedded PCB models. Invalid or oversized assets are skipped."},{id:"componentClasses",label:"Component classes",since:9,implemented:!0,limitation:"Shows saved PCB and schematic classes and rule-area matches supported by drawing geometry. Dynamic PCB conditions and custom DRC expressions require native KiCad."},{id:"netclassRuleAreas",label:"Schematic net-class rule areas",since:9,implemented:!0,limitation:"Shows saved directives, rule areas and sheet-local net assignments. Bus expansion and cross-sheet rule resolution require native KiCad."},{id:"schematicTables",label:"Native schematic tables (horizontal)",since:9,implemented:!0,limitation:"Horizontal tables with saved cell geometry are rendered. Rotated tables are omitted with a drawing diagnostic; table-cell contextual variables are not implemented."}]);function O(l,c){let e=R.find(t=>t.id===c);if(!e)return{available:!1,reason:"This feature is not recognized by the viewer.",upgrade:!1};let i=l?.majorVersion;return Number.isInteger(i)&&i<e.since?{available:!1,upgrade:!0,reason:`${e.label} requires KiCad ${e.since} or later. This drawing identifies itself as KiCad ${l.generatorVersion||i}. Upgrade to the latest stable KiCad and save a separate project copy. `+(e.implemented?"":"This viewer also needs support for this feature; upgrading the project alone will not enable it.")}:e.implemented?{available:!0,upgrade:!1,reason:e.limitation||"Available for recognized saved data; existing geometry and connectivity limits still apply."}:{available:!1,upgrade:!1,reason:`${e.label} is not implemented in this viewer. Upgrading KiCad alone will not enable it.`}}function C(l,c){let e=l.ownerDocument||ee.document,i=e.createElement("button");i.type="button",i.className="compatibility-button",i.title="Saved-file compatibility and feature availability",l.append(i);let t=e.createElement("dialog");t.className="compatibility-dialog",t.setAttribute("aria-label","Saved-file compatibility"),e.body.append(t);let s=(n,o)=>{let r=e.createElement(n);return r.textContent=o,r};function b(n){let o=O(c(),n.id);if(o.available)return!0;if(t.replaceChildren(s("h2",n.label),s("p",o.reason)),o.upgrade){let g=s("a","Get the latest stable KiCad");g.href="https://www.kicad.org/download/",g.target="_blank",g.rel="noopener noreferrer",t.append(g)}let r=s("button","Close");return r.type="button",r.onclick=()=>t.close(),t.append(r),t.open||t.showModal(),!1}function d(){let n=c();t.replaceChildren(s("h2","Saved-file compatibility"),s("p",n?.generatorVersion?`KiCad ${n.generatorVersion} \xB7 saved format ${n.formatVersion??"unknown"}`:"Generator version unknown; no major version inferred from the format date."));for(let r of R){let g=O(n,r.id),v=s("button",`${g.available?"Available":"Blocked"} \xB7 ${r.label}${g.available?"":" \xB7 Why?"}`);v.type="button",v.className="compatibility-feature",v.setAttribute("data-blocked",String(!g.available)),v.title=g.reason,v.onclick=()=>g.available?void 0:b(r),t.append(v)}n?.unknown?.length&&t.append(s("p","Omitted saved constructs: "+n.unknown.join(", ")+". These are renderer limitations; upgrading alone is not a remedy."));let o=s("button","Close");o.type="button",o.onclick=()=>t.close(),t.append(o),t.open||t.showModal()}t.addEventListener("click",n=>{if(n.target===t){let o=t.getBoundingClientRect();(n.clientX<o.left||n.clientX>o.right||n.clientY<o.top||n.clientY>o.bottom)&&t.close()}}),i.onclick=d;let S=()=>{let n=c();i.textContent=n?.majorVersion?`KiCad ${n.majorVersion} \xB7 Features`:"File features",t.open&&t.close()};return S(),{refresh:S,check(n){let o=R.find(r=>r.id===n);return o?b(o):!1},dispose(){t.remove(),i.remove()}}}ee.KiCadFileCompatibility={embeddedFonts:ne,textResolver:Z,textContext:ie,textExpressions:k,textLinks:oe,inspect:H,features:R,capability:O,mountStatus:C},typeof ae=="object"&&ae.exports&&(ae.exports=ee.KiCadFileCompatibility)})(typeof globalThis=="object"?globalThis:ue)});var me=fe((de,le)=>{(ee=>{"use strict";function m(ne,re="",G={}){let{width:P,height:k}=ne||{};if(!Number.isFinite(P)||!Number.isFinite(k)||P<=20||k<=20)return[];let oe=[],Z=ne.titleBlock||{},ie=e=>oe.push({color:"#a0a0a0",width:.1524,frame:!0,path:re,...e}),H=(e,i,t,s,b="title-block")=>ie({type:"line",points:[{x:e,y:i},{x:t,y:s}],kind:b}),R=(e,i,t,s,b)=>ie({type:"polygon",points:[{x:e,y:i},{x:t,y:i},{x:t,y:s},{x:e,y:s}],kind:b}),O=(e,i,t,s=1.5,b={})=>{t==null||t===""||ie({type:"text",x:e,y:i,text:String(t),size:s,fontWidth:s,fontHeight:s,angle:0,align:"left",baseline:"middle",kind:"title-block",...b})};R(0,0,P,k,"page"),R(10,10,P-10,k-10,"page-frame"),R(12,12,P-12,k-12,"page-frame");for(let e=60;e<P-10;e+=50)H(e,10,e,12,"page-zone"),H(e,k-12,e,k-10,"page-zone");for(let e=35,i=1;e<P-10;e+=50,i++)O(e,11,i,1.3,{kind:"page-zone"}),O(e,k-11,i,1.3,{kind:"page-zone"});for(let e=60;e<k-10;e+=50)H(10,e,12,e,"page-zone"),H(P-12,e,P-10,e,"page-zone");for(let e=35,i=0;e<k-10;e+=50,i++)O(11,e,String.fromCharCode(65+i),1.3,{kind:"page-zone",align:"center"}),O(P-11,e,String.fromCharCode(65+i),1.3,{kind:"page-zone",align:"center"});let C=P-10,l=k-10,c=C-110;R(c,l-34,C-2,l-2,"title-block");for(let e of[5.5,8.5,12.5,18.5])H(c,l-e,C-2,l-e);H(C-90,l-8.5,C-90,l-5.5),H(C-26,l-8.5,C-26,l-2),O(C-87,l-6.9,`Date: ${Z.date||""}`),O(C-109,l-4.1,G.kicadVersion?`KiCad E.D.A. ${G.kicadVersion}`:"KiCad E.D.A."),O(C-24,l-6.9,`Rev: ${Z.rev||""}`,1.5,{bold:!0}),O(C-109,l-6.9,`Size: ${ne.format||"User"}`),O(C-24,l-4.1,`Id: ${G.sheetNumber||1}/${G.sheetCount||1}`),O(C-109,l-10.7,`Title: ${Z.title||""}`,2,{bold:!0,italic:!0}),O(C-109,l-14.3,`File: ${String(re).split(/[\\/]/).pop()||""}`),O(C-109,l-17,`Sheet: ${G.sheetName||"/"}`),O(C-109,l-20,Z.company,1.5,{bold:!0});for(let e=0;e<4;e++)O(C-109,l-23-e*3,Z.comments?.[e]);return oe}ee.KiCadWorksheet={build:m},typeof le=="object"&&le.exports&&(le.exports=ee.KiCadWorksheet)})(typeof globalThis=="object"?globalThis:de)});export{ge as a,me as b};