var Ws=Object.defineProperty;var Mn=Object.getOwnPropertyDescriptor;var l=(s,e)=>Ws(s,"name",{value:e,configurable:!0});var P=(s,e,t,r)=>{for(var i=r>1?void 0:r?Mn(e,t):e,n=s.length-1,a;n>=0;n--)(a=s[n])&&(i=(r?a(e,t,i):a(i))||i);return r&&i&&Ws(e,t,i),i};function Re(s){window.setTimeout(()=>{s()},0)}l(Re,"later");var fe=class{static{l(this,"DeferredPromise")}#e;#t;#r;#i;#s;constructor(){this.#e=new Promise((e,t)=>{this.#t=e,this.#r=t})}get rejected(){return this.#i===1}get resolved(){return this.#i===0}get settled(){return!!this.#i}get value(){return this.#s}then(e,t){return this.#e.then(e,t)}resolve(e){this.#i=0,this.#s=e,this.#t(e)}reject(e){this.#i=1,this.#s=e,this.#r(e)}},Ne=class extends fe{static{l(this,"Barrier")}get isOpen(){return this.resolved&&this.value===!0}open(){this.resolve(!0)}};function Zs(s){return s instanceof URL&&(s=s.pathname),s.split("/").slice(0,-1).join("/")}l(Zs,"dirname");function Oe(s){return s instanceof URL&&(s=s.pathname),s.split("/").at(-1)}l(Oe,"basename");function sr(s){return s.split(".").at(-1)??""}l(sr,"extension");function at(s){let e,t;s instanceof File?(e=URL.createObjectURL(s),t=s.name):(e=s.href,t=Oe(e));let r=document.createElement("a");r.href=e,r.download=t,r.target="_blank",console.log(r),r.click(),s instanceof File&&URL.revokeObjectURL(e)}l(at,"initiate_download");var Ue=class{static{l(this,"VirtualFileSystem")}*list_matches(e){for(let t of this.list())t.match(e)&&(yield t)}*list_ext(e){e.startsWith(".")||(e=`.${e}`);for(let t of this.list())t.endsWith(e)&&(yield t)}},lt=class extends Ue{constructor(t,r=null){super();this.urls=new Map;this.resolver=r??this.#e;for(let i of t)this.#t(i)}static{l(this,"FetchFileSystem")}#e(t){return new URL(t,window.location.toString())}#t(t){if(typeof t=="string"){let r=this.urls.get(t);if(r)return r;{let i=this.resolver(t),n=Oe(i);return this.urls.set(n,i),i}}return t}*list(){yield*this.urls.keys()}async has(t){return Promise.resolve(this.urls.has(t))}async get(t){let r=this.#t(t);if(!r)throw new Error(`File ${t} not found!`);let i=new Request(r,{method:"GET"}),n=await fetch(i);if(!n.ok)throw new Error(`Unable to load ${r}: ${n.status} ${n.statusText}`);let a=await n.blob();return new File([a],t)}async download(t){at(await this.get(t))}},D2=class s extends Ue{constructor(t){super();this.items=t}static{l(this,"DragAndDropFileSystem")}static async fromDataTransfer(t){let r=[];for(let i=0;i{i.readEntries(c=>{for(let u of c)u.isFile&&r.push(u);n(!0)},a)})}return new s(r)}*list(){for(let t of this.items)yield t.name}async has(t){for(let r of this.items)if(r.name==t)return!0;return!1}async get(t){let r=null;for(let i of this.items)if(i.name==t){r=i;break}if(r==null)throw new Error(`File ${t} not found!`);return await new Promise((i,n)=>{r.file(i,n)})}async download(t){at(await this.get(t))}},ct=class extends Ue{constructor(t){super();this.files=t}static{l(this,"LocalFileSystem")}*list(){for(let t of this.files)yield t.name}async has(t){return this.files.find(r=>r.name==t)!==void 0}async get(t){let r=this.files.find(i=>i.name==t);if(r)return r;throw new Error(`File ${t} not found`)}async download(t){at(await this.get(t))}},B2=class extends Ue{static{l(this,"MergedFileSystem")}constructor(e){super(),this.fs_list=e.filter(t=>t!==null)}*list(){for(let e of this.fs_list)yield*e.list()}async has(e){for(let t of this.fs_list)if(await t.has(e))return!0;return!1}async get(e){for(let t of this.fs_list)if(await t.has(e))return await t.get(e);throw new Error(`File ${e} not found`)}async download(e){for(let t of this.fs_list)if(await t.has(e))return await t.download(e);throw new Error(`File ${e} not found`)}};var $2=class{static{l(this,"DropTarget")}constructor(e,t){e.addEventListener("dragenter",r=>{r.preventDefault()},!1),e.addEventListener("dragover",r=>{r.dataTransfer&&(r.preventDefault(),r.dataTransfer.dropEffect="move")},!1),e.addEventListener("drop",async r=>{r.stopPropagation(),r.preventDefault();let i=r.dataTransfer;if(!i)return;let n=await D2.fromDataTransfer(i);t(n)},!1)}};var j2=class s{static{l(this,"FilePicker")}static async pick(e){let t=await s.open_picker();t.length>0&&await e(new ct(t))}static open_picker(){return new Promise(e=>{let t=document.createElement("input");t.type="file",t.style.display="none",t.multiple=!0,t.accept=".kicad_pcb,.kicad_pro,.kicad_sch",t.onchange=r=>{let i=r.target.files;i&&i.length>0?e(Array.from(i)):e([])},t.oncancel=()=>{e([])},t.click()})}};var z2=class s extends Event{constructor(t,r){super(s.type,{bubbles:!0,cancelable:!0,composed:!0});this.context_name=t;this._callback=r}static{l(this,"ContextRequestEvent")}static{this.type="context-request"}callback(t){this.stopPropagation(),this._callback(t)}};async function Ss(s,e){return new Promise(t=>{s.dispatchEvent(new z2(e,r=>{t(r)}))})}l(Ss,"requestContext");function Ts(s,e,t){s.addEventListener(z2.type,r=>{let i=r;i.context_name==e&&i.callback(t)})}l(Ts,"provideContext");async function fn(s,e){return(await Ss(s,e))()}l(fn,"requestLazyContext");async function Nn(s,e,t){Ts(s,e,t)}l(Nn,"provideLazyContext");function ys(s){return class extends s{static{l(this,"WithContext")}constructor(...t){super(...t)}async requestContext(t){return await Ss(this,t)}provideContext(t,r){Ts(this,t,r)}async requestLazyContext(t){return await fn(this,t)}provideLazyContext(t,r){Nn(this,t,r)}}}l(ys,"WithContext");function nr(s){return s===null||typeof s!="object"&&typeof s!="function"}l(nr,"is_primitive");function E(s){return typeof s=="string"}l(E,"is_string");function le(s){return typeof s=="number"&&!isNaN(s)}l(le,"is_number");function $t(s){return Array.isArray(s)||typeof s?.[Symbol.iterator]=="function"}l($t,"is_iterable");function or(s){return Array.isArray(s)}l(or,"is_array");function Ls(s){return typeof s=="object"&&s!==null&&!Array.isArray(s)&&!(s instanceof RegExp)&&!(s instanceof Date)}l(Ls,"is_object");var Xs=new Map,ge=class{constructor(e){this.css_string=e}static{l(this,"CSS")}get stylesheet(){let e=Xs.get(this.css_string);return e==null&&(e=new CSSStyleSheet,e.replaceSync(this.css_string),Xs.set(this.css_string,e)),e}};function y(s,...e){let t="";for(let r=0;rt instanceof CSSStyleSheet?t:t.stylesheet))}l(Os,"adopt_styles");function q2(s){return or(s)?s:[s]}l(q2,"as_array");function Us(s){return or(s)?s:$t(s)?Array.from(s):[s]}l(Us,"iterable_as_array");var gn=new Intl.Collator(void 0,{numeric:!0});function ue(s,e){return s.slice().sort((t,r)=>gn.compare(e(t),e(r)))}l(ue,"sorted_by_numeric_strings");var Rt=class{constructor(){this._disposables=new Set;this._is_disposed=!1}static{l(this,"Disposables")}add(e){if(this._is_disposed)throw new Error("Tried to add item to a DisposableStack that's already been disposed");return this._disposables.add(e),e}disposeAndRemove(e){e&&(e.dispose(),this._disposables.delete(e))}get isDisposed(){return this._is_disposed}dispose(){if(this._is_disposed){console.trace("dispose() called on an already disposed resource");return}for(let e of this._disposables.values())e.dispose();this._disposables.clear(),this._is_disposed=!0}};function Vn(s){return typeof HTMLElement=="object"&&s instanceof HTMLElement}l(Vn,"is_HTMLElement");function f(s,...e){let t=document.createElement("template");t.innerHTML=Pn(s,e);let r=t.content;return r=document.importNode(r,!0),Wn(r,e),r.childElementCount==1?r.firstElementChild:r}l(f,"html");var ar=class{constructor(e){this.text=e}static{l(this,"Literal")}},lr=/\$\$:(\d+):\$\$/g;function Pn(s,e){let t=[];for(let i=0;i or ${this.canvas}`}};P([L({type:Boolean})],Le.prototype,"loaded",2),P([L({type:String})],Le.prototype,"theme",2),P([L({type:Boolean})],Le.prototype,"disableinteraction",2);var Ii=class extends Le{static{l(this,"KCBoardViewerElement")}update_theme(){this.viewer.theme=this.themeObject.board}make_viewer(){return new I3(this.canvas,!this.disableinteraction,this.themeObject.board)}};window.customElements.define("kc-board-viewer",Ii);var Jt=class extends g{static{l(this,"KCBoardFootprintsPanelElement")}connectedCallback(){(async()=>(this.viewer=await this.requestLazyContext("viewer"),await this.viewer.loaded,this.sort_footprints(),super.connectedCallback()))()}sort_footprints(){this.sorted_footprints=ue(this.viewer.board.footprints,e=>e.reference||"REF")}initialContentCallback(){this.addEventListener("kc-ui-menu:select",e=>{let t=e.detail;t.name&&this.viewer.select(t.name)}),this.addDisposable(this.viewer.addEventListener(j.type,()=>{this.menu.selected=this.viewer.selected?.context.uuid_text??null})),this.search_input_elm.addEventListener("input",e=>{this.item_filter_elem.filter_text=this.search_input_elm.value??null})}render(){return f` ${this.render_list()} `}render_list(){let e=[],t=[];for(let r of this.sorted_footprints){let i=r.reference||"REF",n=r.value||"VAL",a=`${r.library_link} ${r.descr} ${r.layer} ${i} ${n} ${r.tags}`,c=f` ${i}${n} `;r.layer=="F.Cu"?e.push(c):t.push(c)}return f`Front ${e} Back ${t}`}};P([w("kc-ui-menu",!0)],Jt.prototype,"menu",2),P([w("kc-ui-text-filter-input",!0)],Jt.prototype,"search_input_elm",2),P([w("kc-ui-filtered-list",!0)],Jt.prototype,"item_filter_elem",2);window.customElements.define("kc-board-footprints-panel",Jt);var Ai=class extends g{static{l(this,"KCBoardInfoPanelElement")}connectedCallback(){(async()=>(this.viewer=await this.requestLazyContext("viewer"),await this.viewer.loaded,super.connectedCallback()))()}render(){let e=this.viewer.drawing_sheet,t=this.viewer.board,r=t.edge_cuts_bbox,i=l(c=>f``,"header"),n=l((c,u,h="")=>f` ${u} ${h} `,"entry"),a=Object.entries(t.title_block?.comment||{}).map(([c,u])=>n(`Comment ${c}`,u));return f` ${i("Page properties")} ${n("Size",e.paper?.size)} ${n("Width",e.width,"mm")} ${n("Height",e.height,"mm")} ${i("Board properties")} ${n("KiCAD version",t.version)} ${n("Generator",t.generator)} ${n("Thickness",t.general?.thickness??1.6,"mm")} ${n("Title",t.title_block?.title)} ${n("Date",t.title_block?.date)} ${n("Revision",t.title_block?.rev)} ${n("Company",t.title_block?.company)} ${a} ${n("Dimensions",`${r.w.toFixed(1)} x ${r.h.toFixed(1)} mm`)} ${n("Footprints",t.footprints.length)} ${n("Nets",t.nets.length)} ${n("Track segments",t.segments.length)} ${n("Vias",t.vias.length)} ${n("Zones",t.zones.length)} ${n("Pad to mask clearance",t.setup?.pad_to_mask_clearance??0,"mm")} ${n("Soldermask min width",t.setup?.solder_mask_min_width??0,"mm")} ${n("Pad to paste clearance",t.setup?.pad_to_paste_clearance??0,"mm")} ${n("Pad to paste clearance ratio",t.setup?.pad_to_paste_clearance_ratio??0)} ${n("Grid origin",`${t.setup?.grid_origin?.x??0}, ${t.setup?.grid_origin?.y??0}`)} `}};window.customElements.define("kc-board-info-panel",Ai);var J2=class extends g{static{l(this,"KCBoardLayersPanelElement")}static{this.styles=[...g.styles,y` :host { display: block; height: 100%; overflow-y: auto; overflow-x: hidden; user-select: none; } kc-ui-panel-title button { all: unset; flex-shrink: 0; margin-left: 1em; color: white; border: 0 none; background: transparent; padding: 0 0.25em 0 0.25em; margin-right: -0.25em; display: flex; align-items: center; } `]}get items(){return Array.from(this.panel_body.querySelectorAll("kc-board-layer-control")??[])}connectedCallback(){(async()=>(this.viewer=await this.requestLazyContext("viewer"),await this.viewer.loaded,super.connectedCallback()))()}initialContentCallback(){this.panel_body.addEventListener(k2.select_event,e=>{let t=e.detail;for(let i of this.items)i.layer_highlighted=!1;let r=this.viewer.layers.by_name(t.layer_name);r.highlighted?this.viewer.layers.highlight(null):(this.viewer.layers.highlight(r),r.visible=!0,t.layer_visible=!0,t.layer_highlighted=!0),this.viewer.draw()}),this.panel_body.addEventListener(k2.visibility_event,e=>{let t=e.detail,r=this.viewer.layers.by_name(t.layer_name);r.visible=!r.visible,t.layer_visible=r.visible,this.presets_menu.deselect(),this.viewer.draw()}),this.renderRoot.querySelector("button")?.addEventListener("click",e=>{e.stopPropagation();let t=this.viewer.layers.in_ui_order();if(this.items.some(r=>r.layer_visible))for(let r of t)r.visible=!1;else for(let r of t)r.visible=!0;this.viewer.draw(),this.presets_menu.deselect(),this.update_item_states()}),this.presets_menu.addEventListener("kc-ui-menu:select",e=>{let t=e.detail,r=this.viewer.layers.in_ui_order();switch(t.name){case"all":for(let i of r)i.visible=!0;break;case"front":for(let i of r)i.visible=i.name.startsWith("F.")||i.name=="Edge.Cuts";break;case"back":for(let i of r)i.visible=i.name.startsWith("B.")||i.name=="Edge.Cuts";break;case"copper":for(let i of r)i.visible=i.name.includes(".Cu")||i.name=="Edge.Cuts";break;case"outer-copper":for(let i of r)i.visible=i.name=="F.Cu"||i.name=="B.Cu"||i.name=="Edge.Cuts";break;case"inner-copper":for(let i of r)i.visible=i.name.includes(".Cu")&&!(i.name=="F.Cu"||i.name=="B.Cu")||i.name=="Edge.Cuts";break;case"drawings":for(let i of r)i.visible=!i.name.includes(".Cu")&&!i.name.includes(".Mask")&&!i.name.includes(".Paste")&&!i.name.includes(".Adhes")}this.viewer.draw(),this.update_item_states()})}update_item_states(){for(let e of this.items){let t=this.viewer.layers.by_name(e.layer_name);e.layer_visible=t?.visible??!1,e.layer_highlighted=t?.highlighted??!1}}render(){let e=this.viewer.layers,t=[];for(let r of e.in_ui_order()){let i=r.visible?"":void 0,n=r.color.to_css();t.push(f``)}return f` ${t} Presets All Front Back Copper Outer copper Inner copper Drawings `}};P([w("kc-ui-panel-body",!0)],J2.prototype,"panel_body",2),P([w("#presets",!0)],J2.prototype,"presets_menu",2);var Ce=class Ce extends g{static{l(this,"KCBoardLayerControlElement")}static{this.styles=[...g.styles,y` :host { box-sizing: border-box; padding: 0.1em 0.8em 0.1em 0.4em; color: white; text-align: left; display: flex; flex-direction: row; width: 100%; align-items: center; } button { all: unset; cursor: pointer; flex-shrink: 0; margin-left: 1em; color: white; border: 0 none; background: transparent; padding: 0 0.25em 0 0.25em; margin-right: -0.25em; display: flex; align-items: center; } .color { flex-shrink: 0; display: block; width: 1em; height: 1em; margin-right: 0.5em; } .name { display: block; flex-grow: 1; } .for-hidden { color: #888; } :host { background: var(--list-item-disabled-bg); color: var(--list-item-disabled-fg); } :host(:hover) { background: var(--list-item-hover-bg); color: var(--list-item-hover-fg); } :host(:hover) button { color: var(--list-item-bg); } :host(:hover) button:hover { color: var(--list-item-fg); } :host([layer-visible]) { background: var(--list-item-bg); color: var(--list-item-fg); } :host([layer-highlighted]) { background: var(--list-item-active-bg); color: var(--list-item-active-fg); } :host([layer-highlighted]:hover) button { color: var(--list-item-fg); } :host kc-ui-icon.for-visible, :host([layer-visible]) kc-ui-icon.for-hidden { display: none; } :host kc-ui-icon.for-hidden, :host([layer-visible]) kc-ui-icon.for-visible { display: revert; } `]}static{this.select_event="kicanvas:layer-control:select"}static{this.visibility_event="kicanvas:layer-control:visibility"}initialContentCallback(){super.initialContentCallback(),this.renderRoot.addEventListener("click",e=>{e.stopPropagation();let t=e.target?.closest("button"),r;t?r=Ce.visibility_event:r=Ce.select_event,this.dispatchEvent(new CustomEvent(r,{detail:this,bubbles:!0}))})}render(){return f` ${this.layer_name} `}};P([L({type:String})],Ce.prototype,"layer_name",2),P([L({type:String})],Ce.prototype,"layer_color",2),P([L({type:Boolean})],Ce.prototype,"layer_highlighted",2),P([L({type:Boolean})],Ce.prototype,"layer_visible",2);var k2=Ce;window.customElements.define("kc-board-layer-control",k2);window.customElements.define("kc-board-layers-panel",J2);var I2=class extends g{static{l(this,"KCBoardNetsPanelElement")}connectedCallback(){(async()=>(this.viewer=await this.requestLazyContext("viewer"),await this.viewer.loaded,super.connectedCallback()))()}initialContentCallback(){this.addEventListener("kc-ui-menu:select",e=>{let t=e.detail,r=parseInt(t?.name,10);r&&this.viewer.highlight_net(r)}),this.search_input_elm.addEventListener("input",e=>{this.item_filter_elem.filter_text=this.search_input_elm.value??null})}render(){let e=this.viewer.board,t=[];for(let r of e.nets)t.push(f` ${r.number} ${r.name} `);return f` ${t} `}};P([w("kc-ui-text-filter-input",!0)],I2.prototype,"search_input_elm",2),P([w("kc-ui-filtered-list",!0)],I2.prototype,"item_filter_elem",2);window.customElements.define("kc-board-nets-panel",I2);var Ci=class extends g{static{l(this,"KCBoardObjectsPanelElement")}connectedCallback(){(async()=>(this.viewer=await this.requestLazyContext("viewer"),await this.viewer.loaded,super.connectedCallback(),this.setup_events()))()}setup_events(){pe(this.renderRoot,"kc-ui-range","kc-ui-range:input",e=>{let t=e.target,r=t.valueAsNumber;switch(t.name){case"tracks":this.viewer.track_opacity=r;break;case"vias":this.viewer.via_opacity=r;break;case"pads":this.viewer.pad_opacity=r;break;case"holes":this.viewer.pad_hole_opacity=r;break;case"zones":this.viewer.zone_opacity=r;break;case"grid":this.viewer.grid_opacity=r;break;case"page":this.viewer.page_opacity=r;break}})}render(){return f` `}};window.customElements.define("kc-board-objects-panel",Ci);var Di=class extends g{static{l(this,"KCBoardPropertiesPanelElement")}connectedCallback(){(async()=>(this.viewer=await this.requestLazyContext("viewer"),await this.viewer.loaded,super.connectedCallback(),this.setup_events()))()}setup_events(){this.addDisposable(this.viewer.addEventListener(j.type,e=>{this.selected_item=e.detail.item,this.update()}))}render(){let e=l(n=>f` `,"header"),t=l((n,a,c="")=>f` ${a??""} ${c} `,"entry"),r=l(n=>n?f`check`:f`close`,"checkbox"),i;if(!this.selected_item)i=e("No item selected");else{let n=this.selected_item,a=Object.entries(n.properties).map(([c,u])=>t(c,u.value));i=f` ${e("Basic properties")} ${t("X",n.at.position.x.toFixed(4),"mm")} ${t("Y",n.at.position.y.toFixed(4),"mm")} ${t("Orientation",n.at.rotation,"\xB0")} ${t("Layer",n.layer)} ${e("Footprint properties")} ${t("Reference",n.reference)} ${t("Value",n.value)} ${t("Type",n.attr.through_hole?"through hole":n.attr.smd?"smd":"unspecified")} ${t("Pads",n.pads.length)} ${t("Library link",n.library_link)} ${t("Description",n.descr)} ${t("Keywords",n.tags)} ${a} ${e("Fabrication attributes")} ${t("Not in schematic",r(n.attr.board_only))} ${t("Exclude from position files",r(n.attr.exclude_from_pos_files))} ${t("Exclude from BOM",r(n.attr.exclude_from_bom))} ${e("Overrides")} ${t("Exempt from courtyard requirement",r(n.attr.allow_missing_courtyard))} ${t("Clearance",n.clearance??0,"mm")} ${t("Solderpaste margin",n.solder_paste_margin??0,"mm")} ${t("Solderpaste margin ratio",n.solder_paste_ratio??0)} ${t("Zone connection",n.zone_connect??"inherited")} `}return f` ${i} `}};window.customElements.define("kc-board-properties-panel",Di);var Bi=class extends Te{static{l(this,"KCBoardAppElement")}on_viewer_select(e,t){e&&e==t&&this.change_activity("properties")}can_load(e){return e.document instanceof de}make_viewer_element(){return f``}make_activities(){return[f` `,f` `,f` `,f` `,f` `,f` `]}};window.customElements.define("kc-board-app",Bi);var A3=class extends Ee{constructor(t){super(t);this.#e=[];this.state=new U2}static{l(this,"Canvas2DRenderer")}#e;#t;async setup(){let t=this.canvas.getContext("2d",{alpha:!1,desynchronized:!0});if(t==null)throw new Error("Unable to create Canvas2d context");this.ctx2d=t,this.update_canvas_size()}dispose(){this.ctx2d=void 0;for(let t of this.#e)t.dispose()}update_canvas_size(){let t=window.devicePixelRatio,r=this.canvas.getBoundingClientRect(),i=Math.round(r.width*t),n=Math.round(r.height*t);(this.canvas.width!=i||this.canvas.height!=n)&&(this.canvas.width=i,this.canvas.height=n)}clear_canvas(){this.update_canvas_size(),this.ctx2d.setTransform(),this.ctx2d.scale(window.devicePixelRatio,window.devicePixelRatio),this.ctx2d.fillStyle=this.background_color.to_css(),this.ctx2d.fillRect(0,0,this.canvas.width,this.canvas.height),this.ctx2d.lineCap="round",this.ctx2d.lineJoin="round"}start_layer(t){this.#t=new $i(this,t)}end_layer(){if(!this.#t)throw new Error("No active layer");return this.#e.push(this.#t),this.#t=null,this.#e.at(-1)}arc(t,r,i,n,a,c){super.prep_arc(t,r,i,n,a,c)}circle(t,r,i){let n=super.prep_circle(t,r,i);if(!n.color||n.color.is_transparent_black)return;let a=n.color.to_css(),c=new Path2D;c.arc(n.center.x,n.center.y,n.radius,0,Math.PI*2),this.#t.commands.push(new kt(c,a,null,0))}line(t,r,i){let n=super.prep_line(t,r,i);if(!n.color||n.color.is_transparent_black)return;let a=n.color.to_css(),c=new Path2D,u=!1;for(let h of n.points)u?c.lineTo(h.x,h.y):(c.moveTo(h.x,h.y),u=!0);this.#t.commands.push(new kt(c,null,a,n.width))}polygon(t,r){let i=super.prep_polygon(t,r);if(!i.color||i.color.is_transparent_black)return;let n=i.color.to_css(),a=new Path2D,c=!1;for(let u of i.points)c?a.lineTo(u.x,u.y):(a.moveTo(u.x,u.y),c=!0);a.closePath(),this.#t.commands.push(new kt(a,n,null,0))}get layers(){let t=this.#e;return{*[Symbol.iterator](){for(let r of t)yield r}}}remove_layer(t){let r=this.#e.indexOf(t);r!=-1&&this.#e.splice(r,1)}},kt=class{constructor(e,t,r,i){this.path=e;this.fill=t;this.stroke=r;this.stroke_width=i;this.path_count=1}static{l(this,"DrawCommand")}render(e){e.fillStyle=this.fill??"black",e.strokeStyle=this.stroke??"black",e.lineWidth=this.stroke_width,this.fill&&e.fill(this.path),this.stroke&&e.stroke(this.path)}},$i=class extends Je{constructor(t,r,i=[]){super(t,r);this.renderer=t;this.name=r;this.commands=i}static{l(this,"Canvas2dRenderLayer")}dispose(){this.clear()}clear(){this.commands=[]}push_path(t,r,i,n){let a=this.commands.at(-1);a&&(a.path_count<20,a.fill==r&&a.stroke==i&&a.stroke_width==n)?(a.path.addPath(t),a.path_count++):this.commands.push(new kt(t,r,i,n))}render(t,r,i=1){let n=this.renderer.ctx2d;if(!n)throw new Error("No CanvasRenderingContext2D!");n.save(),n.globalCompositeOperation=this.composite_operation,n.globalAlpha=i;let a=U.from_DOMMatrix(n.getTransform());a.multiply_self(t),n.setTransform(a.to_DOMMatrix());for(let c of this.commands)c.render(n);n.globalCompositeOperation="source-over",n.globalAlpha=1,n.restore()}};var De=(M=>(M.interactive=":Interactive",M.marks=":Marks",M.symbol_field=":Symbol:Field",M.label=":Label",M.junction=":Junction",M.wire=":Wire",M.symbol_foreground=":Symbol:Foreground",M.notes=":Notes",M.bitmap=":Bitmap",M.symbol_pin=":Symbol:Pin",M.symbol_background=":Symbol:Background",M[M.drawing_sheet=":DrawingSheet"]="drawing_sheet",M[M.grid=":Grid"]="grid",M))(De||{}),It=class extends Ht{constructor(t){super();this.theme=t;for(let r of Object.values(De))this.add(new ae(this,r));this.by_name(":Interactive").visible=!1,this.by_name(":Interactive").interactive=!0,this.by_name(De.drawing_sheet).color=this.theme.worksheet??p.white}static{l(this,"LayerSet")}*interactive_layers(){yield this.by_name(":Interactive")}};var C3=class extends Ie{static{l(this,"BaseSchematicPainter")}},H=class extends _e{static{l(this,"SchematicItemPainter")}get theme(){return this.view_painter.theme}get is_dimmed(){return this.view_painter.current_symbol?.dnp??!1}dim_color(e){return e=e.desaturate(),e.mix(this.theme.background,.5)}dim_if_needed(e){return this.is_dimmed?this.dim_color(e):e}determine_stroke(e,t){let r=t.stroke?.width||this.gfx.state.stroke_width;if(r<0)return{width:0,color:null};if((t.stroke?.type??"none")=="none")return{width:0,color:null};let n=e.name==":Symbol:Foreground"?this.theme.component_outline:this.theme.note,a=this.dim_if_needed(t.stroke?.color??n);return{width:r,color:a}}determine_fill(e,t){let r=t.fill?.type??"none";if(r=="none"||r=="background"&&e.name!=":Symbol:Background")return null;let i;switch(r){case"background":i=this.theme.component_body;break;case"outline":i=this.theme.component_outline;break;case"color":i=t.fill.color;break}return this.dim_if_needed(i)}};var A2=class extends H{constructor(){super(...arguments);this.classes=[]}static{l(this,"LabelPainter")}layers_for(t){return[":Label"]}paint(t,r){if(r.effects.hide)return;let i=new Kt(r.shown_text);i.apply_at(r.at),i.apply_effects(r.effects),this.after_apply(r,i),r.at.rotation==0||r.at.rotation==180?i.text_angle.degrees=0:(r.at.rotation==90||r.at.rotation==270)&&(i.text_angle.degrees=90);let n=i.text_pos.add(this.get_schematic_text_offset(r,i));this.gfx.state.push(),this.gfx.state.stroke=this.color,this.gfx.state.fill=this.color,Q.default().draw(this.gfx,i.shown_text,n,i.attributes);let a=this.create_shape(r,i);a&&this.gfx.line(a,i.attributes.stroke_width/1e4),this.gfx.state.pop()}create_shape(t,r){return[]}get color(){return new p(1,0,1,1)}after_apply(t,r){}get_text_offset(t){return Math.round(C.text_offset_ratio*t.text_size.x)}get_box_expansion(t){return Math.round(C.label_size_ratio*t.text_size.y)}get_schematic_text_offset(t,r){let i=Math.round(this.get_text_offset(r)+r.get_effective_text_thickness());return r.text_angle.is_vertical?new d(-i,0):new d(0,-i)}},D3=class extends A2{constructor(){super(...arguments);this.classes=[P2]}static{l(this,"NetLabelPainter")}get color(){return this.theme.label_local}},B3=class extends A2{constructor(){super(...arguments);this.classes=[W2]}static{l(this,"GlobalLabelPainter")}get color(){return this.theme.label_global}get_schematic_text_offset(t,r){let i=t,n=r.text_size.y,a=this.get_box_expansion(r),c=n*.0715;switch(["input","bidirectional","tri_state"].includes(i.shape)&&(a+=n*.75),a=Math.round(a),c=Math.round(c),t.at.rotation){case 0:return new d(a,c);case 90:return new d(c,-a);case 180:return new d(-a,c);case 270:return new d(c,a);default:throw new Error(`Unexpected label rotation ${t.at.rotation}`)}}create_shape(t,r){let i=t,n=r.text_pos,a=W.from_degrees(t.at.rotation+180),c=r.text_size.y,u=this.get_box_expansion(r),h=c/2+u,m=r.get_text_box().w+2*u,_=r.attributes.stroke_width,b=m+_+3,M=h+_+3,N=[new d(0,0),new d(0,-M),new d(-b,-M),new d(-b,0),new d(-b,M),new d(0,M),new d(0,0)],Z=new d;switch(i.shape){case"input":Z.x=-h,N[0].x+=h,N[6].x+=h;break;case"output":N[3].x-=h;break;case"bidirectional":case"tri_state":Z.x=-h,N[0].x+=h,N[6].x+=h,N[3].x-=h;break;default:break}return N=N.map(T=>T.add(Z).rotate(a).add(n).multiply(1/1e4)),N}},$3=class extends A2{constructor(){super(...arguments);this.classes=[je]}static{l(this,"HierarchicalLabelPainter")}get color(){return this.theme.label_hier}after_apply(t,r){r.v_align="center"}get_schematic_text_offset(t,r){let i=Math.round(this.get_text_offset(r)+r.text_width);switch(t.at.rotation){case 0:return new d(i,0);case 90:return new d(0,-i);case 180:return new d(-i,0);case 270:return new d(0,i);default:throw new Error(`Unexpected label rotation ${t.at.rotation}`)}}create_shape(t,r){let i=r.text_pos,n=W.from_degrees(t.at.rotation),a=r.text_width,c;switch(t.shape){case"output":c=[new d(0,a/2),new d(a/2,a/2),new d(a,0),new d(a/2,-a/2),new d(0,-a/2),new d(0,a/2)];break;case"input":c=[new d(a,a/2),new d(a/2,a/2),new d(0,0),new d(a/2,-a/2),new d(a,-a/2),new d(a,a/2)];break;case"bidirectional":case"tri_state":c=[new d(a/2,a/2),new d(a,0),new d(a/2,-a/2),new d(0,0),new d(a/2,a/2)];break;case"passive":default:c=[new d(0,a/2),new d(a,a/2),new d(a,-a/2),new d(0,-a/2),new d(0,a/2)];break}return c=c.map(u=>u.rotate(n).add(i).multiply(1/1e4)),c}};var j3=class s extends H{constructor(){super(...arguments);this.classes=[Z2]}static{l(this,"PinPainter")}layers_for(t){return[":Symbol:Pin",":Symbol:Foreground",":Interactive"]}paint(t,r){if(r.definition.hide)return;let i={pin:r,def:r.definition,position:r.definition.at.position.copy(),orientation:bo(r.definition.at.rotation)},n=this.view_painter.current_symbol_transform,a=this.dim_if_needed(this.theme.pin);s.apply_symbol_transformations(i,n),this.gfx.state.push(),this.gfx.state.matrix=U.identity(),this.gfx.state.stroke=a,(t.name==":Symbol:Pin"||t.name==":Interactive")&&this.draw_pin_shape(this.gfx,i),t.name==":Symbol:Foreground"&&this.draw_name_and_number(this.gfx,i),this.gfx.state.pop()}static apply_symbol_transformations(t,r){for(let n=0;n0?(T=h?void 0:At.place_inside(b,Z,u,r.orientation),v=m?void 0:At.place_above(M,_,N,u,r.orientation)):(T=h?void 0:At.place_above(M,_,Z,u,r.orientation),v=m?void 0:At.place_below(M,_,Z,u,r.orientation)),T&&At.draw(t,a,r.position,T,i.name.effects,t.state.stroke),v&&At.draw(t,c,r.position,v,i.number.effects,t.state.stroke)}};function bo(s){switch(s){case 0:return"right";case 90:return"up";case 180:return"left";case 270:return"down";default:throw new Error(`Unexpected pin angle ${s}`)}}l(bo,"angle_to_orientation");var _n={stem(s,e,t){let r=new d,i=new d;switch(e){case"up":r.set(s.x,s.y-t),i.set(0,1);break;case"down":r.set(s.x,s.y+t),i.set(0,-1);break;case"left":r.set(s.x-t,s.y),i.set(1,0);break;case"right":r.set(s.x+t,s.y),i.set(-1,0);break}return{p0:r,dir:i}},draw(s,e,t,r,i,n){let a=C.pinsymbol_size,c=a*2,u=C.target_pin_radius;if(e=="no_connect"){s.line([i,r]),s.line([r.add(new d(-u,-u)),r.add(new d(u,u))]),s.line([r.add(new d(u,-u)),r.add(new d(-u,u))]);return}let h=l(()=>{n.y?s.line([i.add(new d(a,0)),i.add(new d(0,-n.y*a)),i.add(new d(-a,0))]):s.line([i.add(new d(0,a)),i.add(new d(-n.x*a,0)),i.add(new d(0,-a))])},"clock_notch"),m=l(()=>{n.y?s.line([i.add(new d(0,n.y).multiply(c)),i.add(new d(-1,n.y).multiply(c)),i]):s.line([i.add(new d(n.x,0).multiply(c)),i.add(new d(n.x,-1).multiply(c)),i])},"low_in_tri");switch(t){case"line":s.line([i,r]);return;case"inverted":s.arc(i.add(n.multiply(a)),a),s.line([i.add(n.multiply(c)),r]);return;case"inverted_clock":s.arc(i.add(n.multiply(a)),a),s.line([i.add(n.multiply(c)),r]),h();return;case"clock":s.line([i,r]),h();return;case"clock_low":case"edge_clock_high":s.line([i,r]),h(),m();break;case"input_low":s.line([i,r]),m();break;case"output_low":s.line([i,r]),n.y?s.line([i.sub(new d(c,0)),i.add(new d(0,n.y*c))]):s.line([i.sub(new d(0,c)),i.add(new d(n.x*c,0))]);break;case"non_logic":s.line([i,r]),s.line([i.sub(new d(n.x+n.y,n.y-n.x).multiply(a)),i.add(new d(n.x+n.y,n.y-n.x).multiply(a))]),s.line([i.sub(new d(n.x-n.y,n.y+n.x).multiply(a)),i.add(new d(n.x-n.y,n.y+n.x).multiply(a))]);break}}},At={orient_label(s,e,t,r){switch(e){case"right":break;case"left":s.x*=-1,t=="left"&&(t="right");break;case"up":s=new d(s.y,-s.x);break;case"down":s=new d(s.y,s.x),t=="left"&&(t="right");break}return{offset:s,h_align:t,v_align:r,orientation:e}},place_inside(s,e,t,r){let i=new d(s-e/2+t,0);return this.orient_label(i,r,"left","center")},place_above(s,e,t,r,i){let n=new d(r/2,-(s+e/2+t/2));return this.orient_label(n,i,"center","bottom")},place_below(s,e,t,r,i){let n=new d(r/2,s+e/2+t/2);return this.orient_label(n,i,"center","top")},draw(s,e,t,r,i,n){let a=new D(e);switch(a.apply_effects(i),a.attributes.h_align=r.h_align,a.attributes.v_align=r.v_align,a.attributes.color=n,a.text_pos=t.add(r.offset).multiply(1e4),r.orientation){case"up":case"down":a.text_angle=W.from_degrees(90);break;case"left":case"right":a.text_angle=W.from_degrees(0);break}Q.default().draw(s,a.shown_text,a.text_pos,a.attributes)}};var ji=class extends Je{constructor(){super(...arguments);this.shapes=[]}static{l(this,"NullRenderLayer")}dispose(){this.clear()}clear(){this.shapes=[]}render(t){}},z3=class extends Ee{static{l(this,"NullRenderer")}#e;constructor(){super(null)}set background_color(e){}async setup(){}async dispose(){}update_canvas_size(){}clear_canvas(){}start_layer(e){this.#e=new ji(this,e)}end_layer(){return this.#e}get layers(){return[]}circle(e,t,r){this.#e.shapes.push(super.prep_circle(e,t,r))}arc(e,t,r,i,n,a){this.#e.shapes.push(super.prep_arc(e,t,r,i,n,a))}line(e,t,r){this.#e.shapes.push(super.prep_line(e,t,r))}polygon(e,t){this.#e.shapes.push(super.prep_polygon(e,t))}remove_layer(e){}};var q3=class extends H{constructor(){super(...arguments);this.classes=[yt]}static{l(this,"LibSymbolPainter")}layers_for(t){return[":Symbol:Background",":Symbol:Foreground",":Symbol:Field"]}paint(t,r,i=1){if(![":Symbol:Background",":Symbol:Foreground",":Interactive"].includes(t.name))return;let n=r.units.get(0);n&&this.#e(t,n,i);let a=this.view_painter.current_symbol,c=r.units.get(a?.unit||1);c&&this.#e(t,c,i)}#e(t,r,i=1){for(let n of r)if(!(n.style>0&&i!=n.style))for(let a of n.drawings)this.view_painter.paint_item(t,a)}},er=class extends H{constructor(){super(...arguments);this.classes=[re]}static{l(this,"SchematicSymbolPainter")}layers_for(t){let r=[":Interactive",":Symbol:Foreground",":Symbol:Background",":Symbol:Field",":Symbol:Pin"];return t.dnp&&r.push(":Marks"),r}paint(t,r){if(t.name==":Interactive"&&r.lib_symbol.power)return;let i=Mo(r);this.view_painter.current_symbol=r,this.view_painter.current_symbol_transform=i,this.gfx.state.push(),this.gfx.state.matrix=U.translation(r.at.position.x,r.at.position.y),this.gfx.state.multiply(i.matrix);let n=r.convert??1;if(this.view_painter.paint_item(t,r.lib_symbol,n),this.gfx.state.pop(),[":Symbol:Pin",":Symbol:Foreground",":Interactive"].includes(t.name))for(let a of r.unit_pins)this.view_painter.paint_item(t,a);if(t.name==":Symbol:Field"||t.name==":Interactive")for(let[a,c]of r.properties)this.view_painter.paint_item(t,c);if(r.dnp&&t.name==":Marks"){let a=fo(this.theme,r),c=C.line_width*3,u=this.theme.erc_error;this.gfx.line([a.top_left,a.bottom_right],c,u),this.gfx.line([a.bottom_left,a.top_right],c,u)}this.view_painter.current_symbol=void 0}};function Mo(s){let e=new U([1,0,0,0,-1,0,0,0,1]),t=new U([0,-1,0,-1,0,0,0,0,1]),r=new U([-1,0,0,0,1,0,0,0,1]),i=new U([0,1,0,1,0,0,0,0,1]),n=0,a=e;if(s.at.rotation!=0)if(s.at.rotation==90)n=1,a=t;else if(s.at.rotation==180)n=2,a=r;else if(s.at.rotation==270)n=3,a=i;else throw new Error(`unexpected rotation ${s.at.rotation}`);if(s.mirror=="y"){let c=a.elements[0]*-1,u=a.elements[3]*-1,h=a.elements[1],m=a.elements[4];a.elements[0]=c,a.elements[1]=h,a.elements[3]=u,a.elements[4]=m}else if(s.mirror=="x"){let c=a.elements[0],u=a.elements[3],h=a.elements[1]*-1,m=a.elements[4]*-1;a.elements[0]=c,a.elements[1]=h,a.elements[3]=u,a.elements[4]=m}return{matrix:a,position:s.at.position,rotations:n,mirror_x:s.mirror=="x",mirror_y:s.mirror=="y"}}l(Mo,"get_symbol_transform");function fo(s,e){let t=new z3,r=new It(s),i=new Ct(t,r,s),n=[":Symbol:Foreground",":Symbol:Background",":Symbol:Pin"],a=[];for(let c of n){let u=r.by_name(c);u.items.push(e),i.paint_layer(u),a.push(u.bbox)}return O.combine(a)}l(fo,"get_symbol_body_and_pins_bbox");var zi=class extends H{constructor(){super(...arguments);this.classes=[St]}static{l(this,"RectanglePainter")}layers_for(t){return[":Notes"]}paint(t,r){let i=[r.start,new d(r.end.x,r.start.y),r.end,new d(r.start.x,r.end.y),r.start];this.#t(t,r,i),this.#e(t,r,i)}#e(t,r,i){let{width:n,color:a}=this.determine_stroke(t,r);!n||!a||this.gfx.line(new x(i,r.stroke?.width||this.gfx.state.stroke_width,a))}#t(t,r,i){let n=this.determine_fill(t,r);n&&this.gfx.polygon(new k(i,n))}},qi=class extends H{constructor(){super(...arguments);this.classes=[Zt]}static{l(this,"PolylinePainter")}layers_for(t){return[":Notes"]}paint(t,r){this.#t(t,r),this.#e(t,r)}#e(t,r){let{width:i,color:n}=this.determine_stroke(t,r);!i||!n||this.gfx.line(new x(r.pts,i,n))}#t(t,r){let i=this.determine_fill(t,r);i&&this.gfx.polygon(new k(r.pts,i))}},es=class extends H{constructor(){super(...arguments);this.classes=[_2]}static{l(this,"WirePainter")}layers_for(t){return[":Wire"]}paint(t,r){this.gfx.line(new x(r.pts,this.gfx.state.stroke_width,this.theme.wire))}},ts=class extends H{constructor(){super(...arguments);this.classes=[b2]}static{l(this,"BusPainter")}layers_for(t){return[":Wire"]}paint(t,r){this.gfx.line(new x(r.pts,C.bus_width,this.theme.bus))}},rs=class extends H{constructor(){super(...arguments);this.classes=[M2]}static{l(this,"BusEntryPainter")}layers_for(t){return[":Junction"]}paint(t,r){this.gfx.line(new x([r.at.position,r.at.position.add(r.size)],C.wire_width,this.theme.wire))}},is=class extends H{constructor(){super(...arguments);this.classes=[g2]}static{l(this,"CirclePainter")}layers_for(t){return[":Notes"]}paint(t,r){this.#t(t,r),this.#e(t,r)}#e(t,r){let{width:i,color:n}=this.determine_stroke(t,r);!i||!n||this.gfx.arc(new Ge(r.center,r.radius,new W(0),new W(Math.PI*2),i,n))}#t(t,r){let i=this.determine_fill(t,r);i&&this.gfx.circle(new z(r.center,r.radius,i))}},ss=class extends H{constructor(){super(...arguments);this.classes=[Wt]}static{l(this,"ArcPainter")}layers_for(t){return[":Notes"]}paint(t,r){let i=q.from_three_points(r.start,r.mid,r.end,r.stroke?.width);this.#t(t,r,i),this.#e(t,r,i)}#e(t,r,i){let{width:n,color:a}=this.determine_stroke(t,r);!n||!a||this.gfx.arc(new Ge(i.center,i.radius,i.start_angle,i.end_angle,n,a))}#t(t,r,i){let n=this.determine_fill(t,r);n&&this.gfx.polygon(new k(i.to_polygon(),n))}},ns=class extends H{constructor(){super(...arguments);this.classes=[f2]}static{l(this,"JunctionPainter")}layers_for(t){return[":Junction"]}paint(t,r){let i=this.theme.junction;this.gfx.circle(new z(r.at.position,(r.diameter||1)/2,i))}},os=class extends H{constructor(){super(...arguments);this.classes=[N2]}static{l(this,"NoConnectPainter")}layers_for(t){return[":Junction"]}paint(t,r){let i=this.theme.no_connect,n=C.line_width,a=C.noconnect_size/2;this.gfx.state.push(),this.gfx.state.matrix.translate_self(r.at.position.x,r.at.position.y),this.gfx.line(new x([new d(-a,-a),new d(a,a)],n,i)),this.gfx.line(new x([new d(a,-a),new d(-a,a)],n,i)),this.gfx.state.pop()}},as=class extends H{constructor(){super(...arguments);this.classes=[Tt]}static{l(this,"TextPainter")}layers_for(t){return[":Notes"]}paint(t,r){if(r.effects.hide||!r.text)return;let i=new Kt(r.shown_text);i.apply_at(r.at),i.apply_effects(r.effects);let n=r.effects.font.color;if(n.is_transparent_black){let a=this.theme.note;i.attributes.color=this.dim_if_needed(a)}else i.attributes.color=this.dim_if_needed(n);this.gfx.state.push(),Q.default().draw(this.gfx,i.shown_text,i.text_pos,i.attributes),this.gfx.state.pop()}},ls=class extends H{constructor(){super(...arguments);this.classes=[He]}static{l(this,"PropertyPainter")}layers_for(t){return[":Symbol:Field",":Interactive"]}paint(t,r){if(r.effects.hide||!r.text)return;let i=this.theme.fields;r.parent instanceof ne&&(i=this.theme.sheet_fields);let n=r.effects.font.color;if(n.is_transparent_black){switch(r.name){case"Reference":i=this.theme.reference;break;case"Value":i=this.theme.value;break;case"Sheet name":i=this.theme.sheet_name;break;case"Sheet file":i=this.theme.sheet_filename;break}i=this.dim_if_needed(i)}else i=this.dim_if_needed(n);let a=r.parent,u=this.view_painter.current_symbol_transform?.matrix??U.identity(),h=r.shown_text;r.name=="Reference"&&a.unit&&(h+=a.unit_suffix);let m=new x3(h,{position:a.at.position.multiply(1e4),transform:u,is_symbol:a instanceof re});m.apply_effects(r.effects),m.attributes.angle=W.from_degrees(r.at.rotation);let _=r.at.position.multiply(1e4).sub(m.parent.position);_=u.inverse().transform(_),_=_.add(m.parent.position),m.text_pos=_;let b=m.draw_rotation,M=m.bounding_box,N=M.center;m.attributes.angle=b,m.attributes.h_align="center",m.attributes.v_align="center",m.attributes.stroke_width=m.get_effective_text_thickness(C.line_width*1e4),m.attributes.color=i;let Z=U.scaling(1e-4,1e-4).transform_all([M.top_left,M.top_right,M.bottom_right,M.bottom_left,M.top_left]);t.name==":Interactive"?this.gfx.line(new x(Array.from(Z),.1,p.white)):(this.gfx.state.push(),Q.default().draw(this.gfx,m.shown_text,N,m.attributes),this.gfx.state.pop())}},cs=class extends H{constructor(){super(...arguments);this.classes=[V2]}static{l(this,"LibTextPainter")}layers_for(t){return[":Symbol:Foreground"]}paint(t,r){if(r.effects.hide||!r.text)return;let i=this.view_painter.current_symbol_transform,n=new F3(r.shown_text);n.apply_effects(r.effects),n.apply_at(r.at),n.apply_symbol_transformations(i),n.attributes.color=this.dim_if_needed(this.theme.component_outline);let a=n.world_pos;n.attributes.v_align="center",this.gfx.state.push(),this.gfx.state.matrix=U.identity(),Q.default().draw(this.gfx,n.shown_text,a,n.attributes),this.gfx.state.pop()}paint_debug(t){this.gfx.line(x.from_BBox(t.scale(1/1e4),.127,new p(0,0,1,1))),this.gfx.circle(new z(t.center.multiply(1/1e4),.2,new p(0,1,0,1)))}},Rs=class extends H{constructor(){super(...arguments);this.classes=[ne]}static{l(this,"SchematicSheetPainter")}layers_for(t){return[":Interactive",":Label",":Symbol:Foreground",":Symbol:Background",":Symbol:Field"]}paint(t,r){let i=this.theme.sheet,n=this.theme.sheet_background,a=new O(r.at.position.x,r.at.position.y,r.size.x,r.size.y);if(t.name==":Interactive"&&this.gfx.polygon(k.from_BBox(a.grow(3),n)),t.name==":Symbol:Background"&&this.gfx.polygon(k.from_BBox(a,n)),t.name==":Symbol:Foreground"&&this.gfx.line(x.from_BBox(a,this.gfx.state.stroke_width,i)),t.name==":Symbol:Field")for(let c of r.properties.values())this.view_painter.paint_item(t,c);if(t.name==":Label")for(let c of r.pins){let u=new je;switch(u.at=c.at.copy(),u.effects=c.effects,u.text=c.name,u.shape=c.shape,u.at.rotation){case 0:u.at.rotation=180;break;case 180:u.at.rotation=0;break;case 90:u.at.rotation=270;break;case 270:u.at.rotation=90;break}c.shape=="input"?u.shape="output":c.shape=="output"&&(u.shape="input"),this.view_painter.paint_item(t,u)}}},Ct=class extends C3{static{l(this,"SchematicPainter")}constructor(e,t,r){super(e,t,r),this.painter_list=[new zi(this,e),new qi(this,e),new es(this,e),new ts(this,e),new rs(this,e),new is(this,e),new ss(this,e),new ns(this,e),new os(this,e),new as(this,e),new cs(this,e),new j3(this,e),new q3(this,e),new ls(this,e),new er(this,e),new D3(this,e),new B3(this,e),new $3(this,e),new Rs(this,e)]}};var tr=class extends Gt{static{l(this,"SchematicViewer")}get schematic(){return this.document}create_renderer(e){let t=new A3(e);return t.state.fill=this.theme.note,t.state.stroke=this.theme.note,t.state.stroke_width=.1524,t}async load(e){if(e instanceof me)return await super.load(e);this.document=null;let t=e.document;return t.update_hierarchical_data(e.sheet_path),await super.load(t)}create_painter(){return new Ct(this.renderer,this.layers,this.theme)}create_layer_set(){return new It(this.theme)}select(e){if(E(e)&&(e=this.schematic.find_symbol(e)??this.schematic.find_sheet(e)),e instanceof re||e instanceof ne){let t=this.layers.query_item_bboxes(e);e=t2(t)??null}super.select(e)}};var us=class extends Le{static{l(this,"KCSchematicViewerElement")}update_theme(){this.viewer.theme=this.themeObject.schematic}make_viewer(){return new tr(this.canvas,!this.disableinteraction,this.themeObject.schematic)}};window.customElements.define("kc-schematic-viewer",us);var ps=class extends g{static{l(this,"KCSchematicInfoPanel")}connectedCallback(){(async()=>(this.viewer=await this.requestLazyContext("viewer"),await this.viewer.loaded,super.connectedCallback(),this.addDisposable(this.viewer.addEventListener(ie.type,e=>{this.update()}))))()}render(){let e=this.viewer.drawing_sheet,t=this.viewer.schematic,r=l(a=>f``,"header"),i=l((a,c,u="")=>f` ${c} ${u} `,"entry"),n=Object.entries(t.title_block?.comment||{}).map(([a,c])=>i(`Comment ${a}`,c));return f` ${r("Page properties")} ${i("Size",e.paper?.size)} ${i("Width",e.width,"mm")} ${i("Height",e.height,"mm")} ${r("Schematic properties")} ${i("KiCAD version",t.version)} ${i("Generator",t.generator)} ${i("Title",t.title_block?.title)} ${i("Date",t.title_block?.date)} ${i("Revision",t.title_block?.rev)} ${i("Company",t.title_block?.company)} ${n} ${i("Symbols",t.symbols.size)} ${i("Unique symbols",t.lib_symbols?.symbols.length??0)} ${i("Wires",t.wires.length)} ${i("Buses",t.buses.length)} ${i("Junctions",t.junctions.length)} ${i("Net labels",t.net_labels.length)} ${i("Global labels",t.global_labels.length)} ${i("Hierarchical labels",t.hierarchical_labels.length)} ${i("No connects",t.no_connects.length)} `}};window.customElements.define("kc-schematic-info-panel",ps);var hs=class extends g{static{l(this,"KCSchematicPropertiesPanelElement")}connectedCallback(){(async()=>(this.viewer=await this.requestLazyContext("viewer"),await this.viewer.loaded,super.connectedCallback(),this.setup_events()))()}setup_events(){this.addDisposable(this.viewer.addEventListener(j.type,e=>{this.selected_item=e.detail.item,this.update()})),this.addDisposable(this.viewer.addEventListener(ie.type,e=>{this.selected_item=void 0,this.update()}))}render(){let e=l(a=>f``,"header"),t=l((a,c,u="")=>f` ${c??""} ${u} `,"entry"),r=l(a=>a?f`check`:f`close`,"checkbox"),i,n=this.selected_item;if(!n)i=e("No item selected");else if(n instanceof re){let a=n.lib_symbol,c=Array.from(n.properties.values()).map(h=>t(h.name,h.text)),u=ue(n.unit_pins,h=>h.number).map(h=>t(h.number,h.definition.name.text));i=f` ${e("Basic properties")} ${t("X",n.at.position.x.toFixed(4),"mm")} ${t("Y",n.at.position.y.toFixed(4),"mm")} ${t("Orientation",n.at.rotation,"\xB0")} ${t("Mirror",n.mirror=="x"?"Around X axis":n.mirror=="y"?"Around Y axis":"Not mirrored")} ${e("Instance properties")} ${t("Library link",n.lib_name??n.lib_id)} ${n.unit?t("Unit",String.fromCharCode(65+n.unit-1)):""} ${t("In BOM",r(n.in_bom))} ${t("On board",r(n.in_bom))} ${t("Populate",r(!n.dnp))} ${e("Fields")} ${c} ${e("Symbol properties")} ${t("Name",a.name)} ${t("Description",a.description)} ${t("Keywords",a.keywords)} ${t("Power",r(a.power))} ${t("Units",a.unit_count)} ${t("Units are interchangeable",r(a.units_interchangable))} ${e("Pins")} ${u} `}else if(n instanceof ne){let a=Array.from(n.properties.values()).map(u=>t(u.name,u.text)),c=ue(n.pins,u=>u.name).map(u=>t(u.name,u.shape));i=f` ${e("Basic properties")} ${t("X",n.at.position.x.toFixed(4),"mm")} ${t("Y",n.at.position.y.toFixed(4),"mm")} ${e("Fields")} ${a} ${e("Pins")} ${c} `}return f` ${i} `}};window.customElements.define("kc-schematic-properties-panel",hs);var Dt=class extends g{static{l(this,"KCSchematicSymbolsPanelElement")}connectedCallback(){(async()=>(this.viewer=await this.requestLazyContext("viewer"),await this.viewer.loaded,super.connectedCallback(),this.setup_initial_events()))()}setup_initial_events(){let e=!1;this.addEventListener("kc-ui-menu:select",t=>{if(e)return;let r=t.detail;r.name&&this.viewer.select(r.name)}),this.addDisposable(this.viewer.addEventListener(j.type,()=>{e=!0,this.menu.selected=this.viewer.selected?.context.uuid??null,e=!1})),this.addDisposable(this.viewer.addEventListener(ie.type,()=>{this.update()}))}renderedCallback(){this.search_input_elm.addEventListener("input",e=>{this.item_filter_elem.filter_text=this.search_input_elm.value??null})}render(){let e=this.viewer.schematic,t=[],r=[],i=[],n=ue(Array.from(e.symbols.values()),c=>c.reference);for(let c of n){let u=`${c.reference} ${c.value} ${c.id} ${c.lib_symbol.name}`,h=f` ${c.reference} ${c.value} `;c.lib_symbol.power?r.push(h):t.push(h)}let a=ue(e.sheets,c=>c.sheetname??c.sheetfile??"");for(let c of a){let u=`${c.sheetname} ${c.sheetfile}`;i.push(f` ${c.sheetname} ${c.sheetfile} `)}return f` ${t} ${r.length?f`Power symbols`:null} ${r} ${i.length?f`Sheets`:null} ${i} `}};P([w("kc-ui-menu")],Dt.prototype,"menu",2),P([w("kc-ui-text-filter-input",!0)],Dt.prototype,"search_input_elm",2),P([w("kc-ui-filtered-list",!0)],Dt.prototype,"item_filter_elem",2);window.customElements.define("kc-schematic-symbols-panel",Dt);var ds=class extends Te{static{l(this,"KCSchematicAppElement")}on_viewer_select(e,t){if(!(!e||e!=t)){if(e instanceof ne){this.project.set_active_page(`${e.sheetfile}:${e.path}/${e.uuid}`);return}this.change_activity("properties")}}can_load(e){return e.document instanceof me}make_viewer_element(){return f``}make_activities(){return[f` `,f` `,f` `]}};window.customElements.define("kc-schematic-app",ds);var rr=`:host{font-size:var(--font-size, 16px);--transition-time-very-short: .1s;--transition-time-short: .2s;--transition-time-medium: .5s;--bg: #131218;--fg: #f8f8f0;--tooltip-bg: #8864cb;--tooltip-fg: #f8f8f0;--tooltip-border: 1px solid #131218;--scrollbar-bg: #131218;--scrollbar-fg: #ae81ff66;--scrollbar-active-fg: #ae81ff;--scrollbar-hover-bg: #ae81ffbb;--activity-bar-bg: #282634;--activity-bar-fg: #f8f8f0;--activity-bar-active-bg: #131218;--activity-bar-active-fg: #f8f8f0;--resizer-bg: #ae81ff;--resizer-active-bg: #ae81ffbb;--panel-bg: #131218;--panel-fg: #f8f8f0;--panel-border: 2px solid #282634;--panel-title-bg: #8077a8;--panel-title-fg: #f8f8f0;--panel-title-border: 1px solid #634e89;--panel-title-button-bg: transparent;--panel-title-button-fg: #dcc8ff;--panel-title-button-hover-bg: #ae81ff;--panel-title-button-hover-fg: inherit;--panel-title-button-disabled-bg: inherit;--panel-title-button-disabled-fg: #888;--panel-subtitle-bg: #634e89;--panel-subtitle-fg: var(--panel-fg);--dropdown-bg: #464258;--dropdown-fg: #f8f8f0;--button-bg: #81eeff;--button-fg: #131218;--button-hover-bg: #a3f3ff;--button-hover-fg: #131218;--button-focus-outline: 1px solid #ae81ff;--button-selected-bg: #ae81ff;--button-selected-fg: #131218;--button-disabled-bg: #131218;--button-disabled-fg: #888;--button-success-bg: #64cb96;--button-success-fg: #131218;--button-success-hover-bg: #81ffbe;--button-success-hover-fg: #131218;--button-danger-bg: #cb6488;--button-danger-fg: #131218;--button-danger-hover-bg: #ff81ad;--button-danger-hover-fg: #131218;--button-outline-bg: #282634;--button-outline-fg: #f8f8f0;--button-outline-hover-bg: #282634;--button-outline-hover-fg: #81eeff;--button-outline-disabled-bg: #131218;--button-outline-disabled-fg: #888;--button-toolbar-bg: #282634;--button-toolbar-fg: #f8f8f0;--button-toolbar-hover-bg: #282634;--button-toolbar-hover-fg: #81eeff;--button-toolbar-disabled-bg: #131218;--button-toolbar-disabled-fg: #888;--button-menu-bg: transparent;--button-menu-fg: #f8f8f0;--button-menu-hover-bg: transparent;--button-menu-hover-fg: #81eeff;--button-menu-disabled-bg: transparent;--button-menu-disabled-fg: #888;--input-bg: #131218;--input-fg: #f8f8f0;--input-border: 1px solid #8077a8;--input-accent: #ae81ff;--input-hover-shadow: 1px 1px 10px 5px rgba(0, 0, 0, .2);--input-focus-outline: 1px solid #ae81ff;--input-placeholder: #8077a8;--input-disabled-bg: #131218;--input-disabled-fg: #888;--input-range-bg: #8077a8;--input-range-fg: #f8f8f0;--input-range-hover-bg: #ae81ff;--input-range-disabled-bg: #131218;--input-range-hover-shadow: 1px 1px 10px 5px rgba(0, 0, 0, .2);--input-range-handle-shadow: 1px 1px 5px 5px rgba(180, 180, 180, .2);--list-item-bg: var(--panel-bg);--list-item-fg: var(--panel-fg);--list-item-active-bg: #634e89;--list-item-active-fg: var(--list-item-fg);--list-item-hover-bg: #64cb96;--list-item-hover-fg: var(--list-item-bg);--list-item-disabled-bg: var(--list-item-bg);--list-item-disabled-fg: #888;--grid-outline: #433e56}:host{--gradient-purple-green-light: linear-gradient( 190deg, hsl(261deg 27% 42%) 0%, hsl(243deg 27% 42%) 17%, hsl(224deg 27% 42%) 33%, hsl(205deg 27% 42%) 50%, hsl(187deg 27% 42%) 67%, hsl(168deg 27% 42%) 83%, hsl(149deg 27% 42%) 100% ) 0 0 fixed;--gradient-purple-blue-medium: linear-gradient( 190deg, hsl(261deg 28% 30%) 0%, hsl(248deg 30% 31%) 17%, hsl(235deg 32% 32%) 33%, hsl(222deg 34% 33%) 50%, hsl(209deg 35% 34%) 67%, hsl(197deg 37% 35%) 83%, hsl(183deg 38% 36%) 100% ) 0 0 fixed;--gradient-purple-blue-dark: linear-gradient(10deg, #111928, #1d162a) 0 0 fixed;--gradient-cyan-blue-light: linear-gradient( 190deg, hsl(183deg 63% 33%) 0%, hsl(189deg 69% 30%) 17%, hsl(194deg 74% 27%) 33%, hsl(199deg 79% 24%) 50%, hsl(203deg 85% 21%) 67%, hsl(209deg 89% 18%) 83%, hsl(214deg 95% 15%) 100% ) 0 0 fixed;--gradient-purple-green-highlight: linear-gradient( 190deg, hsl(261deg 27% 53%) 0%, hsl(243deg 27% 52%) 17%, hsl(224deg 27% 52%) 33%, hsl(205deg 27% 51%) 50%, hsl(186deg 27% 51%) 67%, hsl(168deg 27% 50%) 83%, hsl(149deg 27% 50%) 100% ) 0 0 fixed;--gradient-purple-red: linear-gradient(90deg, #8864cb, #cb6488) 0 0 fixed;--gradient-purple-red-highlight: linear-gradient(90deg, #b187ff, #ff80ac) 0 0 fixed;--scrollbar-bg: var(--gradient-purple-blue-dark);--scrollbar-fg: var(--gradient-purple-green-light);--scrollbar-hover-fg: var(--scrollbar-fg);--scrollbar-active-fg: var(--scrollbar-fg);--activity-bar-bg: var(--gradient-purple-green-light);--resizer-bg: var(--gradient-purple-blue-medium);--resizer-active-bg: var(--gradient-purple-green-highlight);--panel-bg: var(--gradient-purple-blue-dark);--panel-title-bg: var(--gradient-purple-green-light);--panel-subtitle-bg: var(--gradient-purple-blue-medium);--button-toolbar-bg: var(--gradient-purple-blue-dark);--button-toolbar-hover-bg: var(--gradient-purple-green-light);--button-toolbar-hover-fg: #f8f8f0;--button-toolbar-disabled-bg: var(--gradient-purple-blue-dark);--button-toolbar-alt-bg: var(--gradient-purple-green-light);--button-toolbar-alt-hover-bg: var(--gradient-purple-green-highlight);--button-toolbar-alt-hover-fg: #f8f8f0;--button-toolbar-alt-disabled-bg: var(--gradient-purple-blue-dark);--dropdown-bg: var(--gradient-purple-green-light);--dropdown-fg: #f8f8f0;--dropdown-hover-bg: var(--gradient-purple-green-highlight);--dropdown-hover-fg: #f8f8f0;--dropdown-active-bg: var(--gradient-purple-blue-dark);--dropdown-active-fg: #f8f8f0;--input-range-bg: var(--gradient-purple-green-light);--list-item-hover-bg: var(--gradient-purple-green-highlight);--list-item-active-bg: var(--gradient-cyan-blue-light);--focus-overlay-bg: var(--gradient-purple-green-light);--focus-overlay-opacity: .5;--focus-overlay-fg: #f8f8f0}::-webkit-scrollbar{position:absolute;width:6px;height:6px;margin-left:-6px;background:var(--scrollbar-bg)}::-webkit-scrollbar-thumb{position:absolute;background:var(--scrollbar-fg)}::-webkit-scrollbar-thumb:hover{background:var(--scrollbar-hover-fg)}::-webkit-scrollbar-thumb:active{background:var(--scrollbar-active-fg)}kc-ui-app{width:100%;height:100%;flex-grow:1;display:flex;flex-direction:row;overflow:hidden}label{display:block;width:100%;margin-top:.75em}input,select,textarea{all:unset;box-sizing:border-box;display:block;width:100%;max-width:100%;margin-top:.5em;font-family:inherit;border-radius:.25em;text-align:center;padding:.25em;background:var(--input-bg);color:var(--input-fg);transition:color var(--transition-time-medium) ease,box-shadow var(--transition-time-medium) ease,outline var(--transition-time-medium) ease,background var(--transition-time-medium) ease,border var(--transition-time-medium) ease}input:hover,select:hover,textarea:hover{z-index:10;box-shadow:var(--input-hover-shadow)}input:focus,select:focus,textarea:focus{z-index:10;box-shadow:none;outline:var(--input-focus-outline)}input:disabled,select:disabled,textarea:disabled{background:var(--input-disabled-bg);color:var(--input-disabled-fg)}input:disabled:hover,select:disabled:hover,textarea:disabled:hover{z-index:10;cursor:unset}input[type=color]::-webkit-color-swatch{border:1px solid transparent;border-radius:.25em}textarea{text-align:left;padding:.5em} `;var bn=`*,*:before,*:after{box-sizing:border-box}:host{box-sizing:border-box;margin:0;display:flex;position:relative;width:100%;height:100%;color:var(--fg)}:host([loaded]) section.overlay,:host([loading]) section.overlay{display:none}:host main{display:contents}section.overlay{position:absolute;top:0;left:0;width:100%;height:100%;z-index:1;display:flex;flex-direction:column;align-items:center;justify-content:center;background:var(--gradient-purple-blue-dark)}section.overlay h1{display:flex;margin:0 auto;align-items:center;justify-content:center;font-size:5em;font-weight:300;text-shadow:0 0 5px var(--gradient-purple-red)}section.overlay h1 img{width:1.5em}section.overlay p{text-align:center;font-size:1.5em;max-width:50%}section.overlay strong{background:var(--gradient-purple-red-highlight);-webkit-background-clip:text;-moz-background-clip:text;background-clip:text;color:transparent}section.overlay a{color:#81eeff}section.overlay a:hover{color:#a3f3ff}section.overlay input{font-size:1.5em;color:var(--fg);background:var(--gradient-purple-red);max-width:50%}section.overlay input::placeholder{color:var(--fg)}section.overlay .link_button{color:#81eeff;background:transparent;font-size:1em;font-weight:400;text-decoration:underline;outline:none;border:none;box-sizing:border-box;transition:color var(--transition-time-medium) ease}section.overlay .link_button:focus{border:var(--button-focus-outline)}section.overlay .link_button:hover{color:var(--fg)}section.overlay p.note{color:var(--input-placeholder);font-size:1em}section.overlay p.github img{width:2em}kc-board-viewer,kc-schematic-viewer{width:100%;height:100%;flex:1}.split-horizontal{display:flex;flex-direction:column;height:100%;max-height:100%;overflow:hidden}.split-vertical{display:flex;flex-direction:row;width:100%;max-width:100%;height:100%;overflow:hidden}kc-board-app,kc-schematic-app{width:100%;height:100%;flex:1} `;jt.sprites_url=Ys;var Be=class extends g{constructor(){super();this.project=new Ot;this.provideContext("project",this.project)}static{l(this,"KiCanvasShellElement")}static{this.styles=[...g.styles,new ge(rr),new ge(bn)]}#e;#t;initialContentCallback(){let r=new URLSearchParams(document.location.search).getAll("github");Re(async()=>{if(this.src){let i=new lt([this.src]);await this.setup_project(i);return}if(r.length){let i=await L2.fromURLs(...r);await this.setup_project(i);return}new $2(this,async i=>{await this.setup_project(i)})}),this.link_input.addEventListener("input",async i=>{let n=this.link_input.value;if(!qe.parse_url(n))return;let a=await L2.fromURLs(n);await this.setup_project(a);let c=new URL(window.location.href);c.searchParams.set("github",n),window.history.pushState(null,"",c)}),this.open_file_button.addEventListener("click",async i=>{j2.pick(async n=>{await this.setup_project(n)})})}async setup_project(t){this.loaded=!1,this.loading=!0;try{await this.project.load(t),this.project.set_active_page(this.project.first_page),this.loaded=!0}catch(r){console.error(r)}finally{this.loading=!1}}render(){return this.#e=f` `,this.#t=f` `,f`

KiCanvas

KiCanvas is an interactive , browser-based viewer for KiCAD schematics and boards. You can learn more from the docs. It's in alpha so please report any bugs!

or drag & drop your KiCAD files, or

KiCanvas is free & open source and supported by community donations with significant support from PartsBox, Blues, Mithro, Jeremy Gordon, & James Neal. KiCanvas runs entirely within your browser, so your files don't ever leave your machine.

${this.#e} ${this.#t}
`}};P([L({type:Boolean})],Be.prototype,"loading",2),P([L({type:Boolean})],Be.prototype,"loaded",2),P([L({type:String})],Be.prototype,"src",2),P([w('input[name="link"]',!0)],Be.prototype,"link_input",2),P([w('button[name="open_local"]',!0)],Be.prototype,"open_file_button",2);window.customElements.define("kc-kicanvas-shell",Be);var C2=new te("kicanvas:embedtag"),Me=class extends g{constructor(){super();this.#e=new Ot;this.custom_resolver=null;this.provideContext("project",this.#e)}static{l(this,"KiCanvasEmbedElement")}static{this.styles=[...g.styles,new ge(rr),y` :host { margin: 0; display: flex; position: relative; width: 100%; max-height: 100%; aspect-ratio: 1.414; background-color: aqua; color: var(--fg); font-family: "Nunito", ui-rounded, "Hiragino Maru Gothic ProN", Quicksand, Comfortaa, Manjari, "Arial Rounded MT Bold", Calibri, source-sans-pro, sans-serif; contain: layout paint; } main { display: contents; } kc-board-app, kc-schematic-app { width: 100%; height: 100%; flex: 1; } `]}#e;#t;#r;initialContentCallback(){this.#i(),Re(()=>{this.#s()})}async#i(){}async#s(){let t=[],r=[];this.src&&t.push(this.src);let i=0;for(let u of this.querySelectorAll("kicanvas-source"))if(u.src)t.push(u.src);else if(u.is_inline_source()){let h=`inline_${i}`;i+=1;let m=u.load_inline_source(h);m&&(C2.info(`Determined inline source ${m.name}, ${m.size} bytes`),r.push(m))}let n=t.length===0?null:new lt(t,this.custom_resolver),a=r.length===0?null:new ct(r);if(n===null&&a===null){C2.warn("No valid sources specified");return}let c=new B2([n,a]);await this.#n(c)}async#n(t){this.loaded=!1,this.loading=!0;try{await this.#e.load(t),this.loaded=!0,await this.update(),this.#e.set_active_page(this.#e.root_schematic_page)}finally{this.loading=!1}}render(){if(!this.loaded)return f``;this.#e.has_schematics&&!this.#t&&(this.#t=f` `),this.#e.has_boards&&!this.#r&&(this.#r=f` `);let t=(this.controls??"none")=="none"||this.controlslist?.includes("nooverlay")?null:f``;return f`
${this.#t} ${this.#r} ${t}
`}};P([L({type:String})],Me.prototype,"src",2),P([L({type:Boolean})],Me.prototype,"loading",2),P([L({type:Boolean})],Me.prototype,"loaded",2),P([L({type:String})],Me.prototype,"controls",2),P([L({type:String})],Me.prototype,"controlslist",2),P([L({type:String})],Me.prototype,"theme",2),P([L({type:String})],Me.prototype,"zoom",2);window.customElements.define("kicanvas-embed",Me);var nt=class nt extends Fe{static{l(this,"KiCanvasSourceElement")}constructor(){super(),this.ariaHidden="true",this.hidden=!0,this.style.display="none"}is_inline_source(){return this.src===null&&this.childNodes.length>0}load_inline_source(e=null){let t="";for(let a of this.childNodes)a.nodeType===Node.TEXT_NODE?t+=a.nodeValue??"":C2.warn(`kicanvas-source children ${a.nodeType} are invaild.`);t=t.trimStart();let r;if(this.name)r=this.name;else{let a=this.type??nt.determine_file_type(t);if(a===void 0){C2.warn(`Unknown file type, content: ${t.slice(0,64)}...`);return}let c=nt.get_file_ext(a);r=(e??"noname")+c}if(t.length===0){C2.warn(`kicanvas-source content ${r} is empty.`);return}let i=new Blob([t],{type:"text/plain"});return new File([i],r)}static determine_file_type(e){if(e.startsWith("(kicad_sch"))return"schematic";if(e.startsWith("(kicad_pcb"))return"board";if(e.startsWith("(kicad_wks"))return"worksheet";if(e.startsWith("{"))return"project"}static get_file_ext(e){switch(e){case"schematic":return".kicad_sch";case"board":return".kicad_pcb";case"worksheet":return".kicad_wks";case"project":return".kicad_prj"}}};P([L({type:String})],nt.prototype,"src",2),P([L({type:String})],nt.prototype,"type",2),P([L({type:String})],nt.prototype,"name",2);var ms=nt;window.customElements.define("kicanvas-source",ms);document.body.appendChild(f``);