@dotgui/embed 0.4.0 → 0.4.1
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/README.md +12 -1
- package/dist/gui-embed.esm.js +1 -1
- package/dist/gui-embed.js +2 -2
- package/package.json +4 -3
- package/src/error-message.test.ts +55 -0
- package/src/error-message.ts +63 -0
- package/src/gui-embed.ts +115 -17
package/README.md
CHANGED
|
@@ -44,7 +44,7 @@ to the bundled Inter.
|
|
|
44
44
|
|
|
45
45
|
<!-- widget: fixed canvas, controls, dot grid -->
|
|
46
46
|
<gui-embed src="hero.gui" style="width:360px;height:460px"
|
|
47
|
-
zoom download copy mode-switch grid></gui-embed>
|
|
47
|
+
zoom download copy mode-switch page-switch grid></gui-embed>
|
|
48
48
|
```
|
|
49
49
|
|
|
50
50
|
**Sizing (CSS):**
|
|
@@ -61,6 +61,17 @@ to the bundled Inter.
|
|
|
61
61
|
| `download` | off | download the `.gui` file |
|
|
62
62
|
| `copy` | off | copy the `.guix` markup to the clipboard |
|
|
63
63
|
| `mode-switch` | off | mode dropdown — only when the file declares >1 mode |
|
|
64
|
+
| `page-switch` | off | page dropdown — only when the package holds >1 page |
|
|
65
|
+
|
|
66
|
+
**Pages:** a package may hold several documents and a library (RFC-0042). The first
|
|
67
|
+
page shows by default; `page="settings.guix"` shows another (`el.pages` lists them,
|
|
68
|
+
`el.page` reads or sets the one on show).
|
|
69
|
+
|
|
70
|
+
**Errors:** a document that can't be drawn gets an opaque, scrollable `.gui-embed-error`
|
|
71
|
+
note over the stage. Repeats are dropped, undeclared tokens and text styles are folded
|
|
72
|
+
into one line each, and the list stops at 8 lines. Its styles are inline without
|
|
73
|
+
`!important`, so a host stylesheet can restyle `.gui-embed-error`,
|
|
74
|
+
`.gui-embed-error-title`, `.gui-embed-error-list` and `.gui-embed-error-more`.
|
|
64
75
|
|
|
65
76
|
Default render mode comes from the file (RFC-0037 `<modes>`). Theme the grid with
|
|
66
77
|
`--gui-embed-bg`, `--gui-embed-dot`, `--gui-embed-dot-gap`.
|
package/dist/gui-embed.esm.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"@dotgui/render/canvas";import{pack as S}from"@dotgui/kit/package";var P="gui-embed",U=0.25,V=8;class J extends HTMLElement{_stage;_view;_canvas;_bar;_ro=null;_bytes=null;_markup="";_size=null;_scale=1;_x=0;_y=0;_userZoomed=!1;_settle=null;static get observedAttributes(){return["src"]}connectedCallback(){if(!this._stage)this._build();this._load()}disconnectedCallback(){this._ro?.disconnect(),this._ro=null}attributeChangedCallback(j){if(j==="src"&&this._stage)this._load()}get canvas(){return this._canvas}_build(){let j=getComputedStyle(this);if(j.position==="static")this.style.position="relative";if(j.display==="inline")this.style.display="block";this.style.overflow="hidden";let q=document.createElement("div");q.className="gui-embed-canvas";let z=this.getAttribute("grid")!=="false";q.style.cssText=["position:absolute;inset:0;touch-action:none","background-color:var(--gui-embed-bg, #fafaf8)",z?"background-image:radial-gradient(var(--gui-embed-dot, rgba(0,0,0,.14)) 1px, transparent 1.4px);background-size:var(--gui-embed-dot-gap, 18px) var(--gui-embed-dot-gap, 18px);background-position:center":""].filter(Boolean).join(";"),this.appendChild(q),this._stage=q;let B=document.createElement("div");B.style.cssText="position:absolute;left:0;top:0;width:max-content;transform-origin:0 0",q.appendChild(B),this._view=B;let D=document.createElement("gui-canvas");D.addEventListener("render",(H)=>this._rendered(H.detail)),D.addEventListener("error",(H)=>this._fail(H.detail.message)),B.appendChild(D),this._canvas=D,this._bindZoom(),this._ro=new ResizeObserver(()=>{if(!this._userZoomed)this.fit()}),this._ro.observe(this);let F=document.createElement("div");F.className="gui-embed-controls",F.style.cssText=["position:absolute;top:8px;right:8px;z-index:2","display:flex;gap:4px;padding:4px","border-radius:8px;background:rgba(20,20,20,.55)","backdrop-filter:blur(8px);-webkit-backdrop-filter:blur(8px)","opacity:0;transition:opacity .15s ease"].join(";"),this.appendChild(F),this._bar=F,this.addEventListener("pointerenter",()=>F.style.opacity="1"),this.addEventListener("pointerleave",()=>F.style.opacity="0")}async _load(){this._size=null,this._userZoomed=!1,this._canvas.mode={};try{let j=this.getAttribute("src");if(j){let q=await fetch(j);if(!q.ok)throw Error(`gui-embed: failed to fetch "${j}" (${q.status})`);this._bytes=new Uint8Array(await q.arrayBuffer()),this._markup="",await this._canvas.loadBytes(this._bytes)}else{let q=this.querySelector(':scope > script[type="application/gui"]');if(!q){if(document.readyState==="loading")document.addEventListener("DOMContentLoaded",()=>void this._load(),{once:!0});return}this._bytes=null,this._markup=q.textContent??"",await this._canvas.loadMarkup(this._markup)}this._buildControls()}catch(j){this._fail(String(j?.message??j))}}_fail(j){let q=this.querySelector(":scope > .gui-embed-error");if(!q)q=document.createElement("div"),q.className="gui-embed-error",q.style.cssText="position:absolute;inset:0;display:flex;align-items:center;justify-content:center;font:13px system-ui;color:#c00;padding:12px;text-align:center",this.appendChild(q);q.textContent=j}_rendered(j){this.querySelector(":scope > .gui-embed-error")?.remove();let q=!this._size||this._size.width!==j.width||this._size.height!==j.height;if(this._size={width:j.width,height:j.height},!q)return;if(!this._hasHeight())if(this.style.width)this.style.aspectRatio=`${j.width} / ${j.height}`;else this.style.width=`${j.width}px`,this.style.height=`${j.height}px`;if(!this._userZoomed)this.fit()}_hasHeight(){if(this.style.height||this.style.aspectRatio)return!0;let j=getComputedStyle(this);if(j.aspectRatio&&j.aspectRatio!=="auto")return!0;return this.clientHeight>1}fit(){if(!this._size)return;let{width:j,height:q}=this._size,z=this._stage.getBoundingClientRect();if(z.width<1||z.height<1)return;this._scale=Math.min(z.width/j,z.height/q),this._x=(z.width-j*this._scale)/2,this._y=(z.height-q*this._scale)/2,this._userZoomed=!1,this._apply()}zoomBy(j,q,z){if(!this._size)return;let B=this._stage.getBoundingClientRect(),D=Math.min(B.width/this._size.width,B.height/this._size.height),F=Math.min(Math.max(this._scale*j,D*U),D*V),H=q??B.width/2,L=z??B.height/2;this._x=H-(H-this._x)*F/this._scale,this._y=L-(L-this._y)*F/this._scale,this._scale=F,this._userZoomed=!0,this._apply()}_apply(){if(this._view.style.transform=`translate(${this._x}px, ${this._y}px) scale(${this._scale})`,this._settle)clearTimeout(this._settle);this._settle=setTimeout(()=>{let j=Math.min(Math.max(2,Math.ceil((window.devicePixelRatio||1)*this._scale)),4);if(Number(this._canvas.getAttribute("density"))!==j)this._canvas.setAttribute("density",String(j))},150)}_bindZoom(){let j=this._stage,q=()=>this.getAttribute("zoom")!=="false";j.addEventListener("wheel",(D)=>{if(!q()||!(D.ctrlKey||D.metaKey))return;D.preventDefault();let F=j.getBoundingClientRect();this.zoomBy(Math.exp(-D.deltaY*0.01),D.clientX-F.left,D.clientY-F.top)},{passive:!1});let z=null;j.addEventListener("pointerdown",(D)=>{if(!q()||D.button!==0)return;z={id:D.pointerId,x:D.clientX,y:D.clientY},j.setPointerCapture(D.pointerId)}),j.addEventListener("pointermove",(D)=>{if(!z||z.id!==D.pointerId)return;this._x+=D.clientX-z.x,this._y+=D.clientY-z.y,z.x=D.clientX,z.y=D.clientY,this._userZoomed=!0,this._view.style.transform=`translate(${this._x}px, ${this._y}px) scale(${this._scale})`});let B=()=>z=null;j.addEventListener("pointerup",B),j.addEventListener("pointercancel",B),j.addEventListener("dblclick",()=>q()&&this.fit())}_buildControls(){let j=this._bar;if(j.innerHTML="",this.getAttribute("zoom")!=="false")j.appendChild(this._btn("Fit","Reset zoom",()=>this.fit()));let q=this._canvas.modes,z=Object.keys(q).filter((B)=>q[B].values.length>1);if(this.hasAttribute("mode-switch")&&z.length)for(let B of z)j.appendChild(this._modeSelect(B,q[B]));if(this.hasAttribute("copy"))j.appendChild(this._btn("Copy","Copy .gui markup",async()=>{await navigator.clipboard.writeText(this._canvas.source)}));if(this.hasAttribute("download"))j.appendChild(this._btn("Download","Download .gui file",()=>this._download()));j.style.display=j.children.length?"flex":"none"}_btn(j,q,z){let B=document.createElement("button");return B.type="button",B.textContent=j,B.title=q,B.style.cssText=["all:unset;cursor:pointer;font:600 12px/1 system-ui","color:#fff;padding:6px 9px;border-radius:5px"].join(";"),B.addEventListener("pointerenter",()=>B.style.background="rgba(255,255,255,.18)"),B.addEventListener("pointerleave",()=>B.style.background="transparent"),B.addEventListener("click",z),B}_modeSelect(j,q){let z=document.createElement("select");z.title=`Mode: ${j}`,z.style.cssText=["all:unset;cursor:pointer;font:600 12px/1 system-ui","color:#fff;padding:6px 9px;border-radius:5px"].join(";");let B=this._canvas.mode[j]??q.default;for(let D of q.values){let F=document.createElement("option");if(F.value=D,F.textContent=D,F.style.color="#000",D===B)F.selected=!0;z.appendChild(F)}return z.addEventListener("change",()=>this._canvas.setMode(j,z.value)),z}_download(){let j=this._bytes??S({xml:this._markup,assets:{}}),q=(this.getAttribute("src")?.split("/").pop()||"design.gui").replace(/\.guix$/,".gui"),z=URL.createObjectURL(new Blob([j],{type:"application/octet-stream"})),B=document.createElement("a");B.href=z,B.download=q.endsWith(".gui")?q:q+".gui",B.click(),setTimeout(()=>URL.revokeObjectURL(z),1000)}}function K(){if(typeof customElements<"u"&&!customElements.get(P))customElements.define(P,J)}import{GuiCanvas as _,config as A}from"@dotgui/render/canvas";var Q=!1;function C(){if(Q||typeof window>"u")return;Q=!0,K()}export{C as install,K as defineGuiEmbed,A as config,J as GuiEmbedElement,_ as GuiCanvas};
|
|
1
|
+
import"@dotgui/render/canvas";import{pack as D}from"@dotgui/kit/package";var Y=/uses token '(\$?[^']+)', which is not declared/,C=/uses text style '([^']+)', which is not declared/;function Z(j,q=8){let J=new Set,B=[],F=[],P=[];for(let $ of j.split("; ")){let W=$.trim();if(!W||J.has(W))continue;J.add(W);let z=Y.exec(W);if(z){let I=z[1].startsWith("$")?z[1]:`$${z[1]}`;if(!B.includes(I))B.push(I);continue}let H=C.exec(W);if(H){if(!F.includes(H[1]))F.push(H[1]);continue}P.push(W)}let Q=[];if(B.length)Q.push(U(B.length===1?"Undeclared token":`${B.length} undeclared tokens`,B));if(F.length)Q.push(U(F.length===1?"Undeclared text style":`${F.length} undeclared text styles`,F));Q.push(...P);let V=Math.max(1,q);if(Q.length<=V)return{lines:Q,more:0};return{lines:Q.slice(0,V),more:Q.length-V}}function U(j,q){let J=q.slice(0,12).join(", "),B=q.length-12;return`${j}: ${J}${B>0?`, and ${B} more`:""}`}var R="gui-embed",M=0.25,N=8;class K extends HTMLElement{_stage;_view;_canvas;_bar;_ro=null;_bytes=null;_markup="";_size=null;_scale=1;_x=0;_y=0;_userZoomed=!1;_settle=null;_controlsPage=null;static get observedAttributes(){return["src","page"]}connectedCallback(){if(!this._stage)this._build();this._load()}disconnectedCallback(){this._ro?.disconnect(),this._ro=null}attributeChangedCallback(j){if(!this._stage)return;if(j==="src")this._load();else if(j==="page")this._showPage(this.getAttribute("page"))}get canvas(){return this._canvas}get pages(){return this._canvas?.pages??[]}get page(){return this._canvas?.page??null}set page(j){if(j==null)this.removeAttribute("page");else this.setAttribute("page",j)}_showPage(j){if(!j||j===this._canvas.page)return;if(!this._canvas.pages.some((q)=>q.name===j))return;this._userZoomed=!1,this._canvas.page=j}_build(){let j=getComputedStyle(this);if(j.position==="static")this.style.position="relative";if(j.display==="inline")this.style.display="block";this.style.overflow="hidden";let q=document.createElement("div");q.className="gui-embed-canvas";let J=this.getAttribute("grid")!=="false";q.style.cssText=["position:absolute;inset:0;touch-action:none","background-color:var(--gui-embed-bg, #fafaf8)",J?"background-image:radial-gradient(var(--gui-embed-dot, rgba(0,0,0,.14)) 1px, transparent 1.4px);background-size:var(--gui-embed-dot-gap, 18px) var(--gui-embed-dot-gap, 18px);background-position:center":""].filter(Boolean).join(";"),this.appendChild(q),this._stage=q;let B=document.createElement("div");B.style.cssText="position:absolute;left:0;top:0;width:max-content;transform-origin:0 0",q.appendChild(B),this._view=B;let F=document.createElement("gui-canvas");F.addEventListener("render",(Q)=>this._rendered(Q.detail)),F.addEventListener("error",(Q)=>this._fail(Q.detail.message)),B.appendChild(F),this._canvas=F,this._bindZoom(),this._ro=new ResizeObserver(()=>{if(!this._userZoomed)this.fit()}),this._ro.observe(this);let P=document.createElement("div");P.className="gui-embed-controls",P.style.cssText=["position:absolute;top:8px;right:8px;z-index:2","display:flex;gap:4px;padding:4px","border-radius:8px;background:rgba(20,20,20,.55)","backdrop-filter:blur(8px);-webkit-backdrop-filter:blur(8px)","opacity:0;transition:opacity .15s ease"].join(";"),this.appendChild(P),this._bar=P,this.addEventListener("pointerenter",()=>P.style.opacity="1"),this.addEventListener("pointerleave",()=>P.style.opacity="0")}async _load(){this._size=null,this._userZoomed=!1,this._canvas.mode={};try{let j=this.getAttribute("src");if(j){let q=await fetch(j);if(!q.ok)throw Error(`gui-embed: failed to fetch "${j}" (${q.status})`);this._bytes=new Uint8Array(await q.arrayBuffer()),this._markup="",await this._canvas.loadBytes(this._bytes),this._showPage(this.getAttribute("page"))}else{let q=this.querySelector(':scope > script[type="application/gui"]');if(!q){if(document.readyState==="loading")document.addEventListener("DOMContentLoaded",()=>void this._load(),{once:!0});return}this._bytes=null,this._markup=q.textContent??"",await this._canvas.loadMarkup(this._markup)}this._buildControls()}catch(j){this._fail(String(j?.message??j))}}_fail(j){let q=this.querySelector(":scope > .gui-embed-error");if(!q)q=document.createElement("div"),q.className="gui-embed-error",q.setAttribute("role","alert"),q.style.cssText=["position:absolute;inset:0;z-index:1;overflow:auto;box-sizing:border-box","display:flex;padding:16px","background:var(--gui-embed-bg, #fafaf8)","font:13px/1.45 system-ui,sans-serif;color:#333"].join(";"),this.appendChild(q);let{lines:J,more:B}=Z(j),F=document.createElement("div");F.className="gui-embed-error-body",F.style.cssText="margin:auto;max-width:56ch;text-align:left";let P=document.createElement("div");P.className="gui-embed-error-title",P.style.cssText="font-weight:600;color:#c00;margin-bottom:6px",P.textContent="This design can't be drawn",F.appendChild(P);let Q=document.createElement("ul");Q.className="gui-embed-error-list",Q.style.cssText="margin:0;padding-left:18px;overflow-wrap:anywhere";for(let V of J){let $=document.createElement("li");$.textContent=V,Q.appendChild($)}if(B){let V=document.createElement("li");V.className="gui-embed-error-more",V.style.cssText="list-style:none;margin-left:-18px;color:#777",V.textContent=`and ${B} more`,Q.appendChild(V)}F.appendChild(Q),q.replaceChildren(F)}_rendered(j){if(this.querySelector(":scope > .gui-embed-error")?.remove(),this._canvas.page!==this._controlsPage)this._buildControls();let q=!this._size||this._size.width!==j.width||this._size.height!==j.height;if(this._size={width:j.width,height:j.height},!q)return;if(!this._hasHeight())if(this.style.width)this.style.aspectRatio=`${j.width} / ${j.height}`;else this.style.width=`${j.width}px`,this.style.height=`${j.height}px`;if(!this._userZoomed)this.fit()}_hasHeight(){if(this.style.height||this.style.aspectRatio)return!0;let j=getComputedStyle(this);if(j.aspectRatio&&j.aspectRatio!=="auto")return!0;return this.clientHeight>1}fit(){if(!this._size)return;let{width:j,height:q}=this._size,J=this._stage.getBoundingClientRect();if(J.width<1||J.height<1)return;this._scale=Math.min(J.width/j,J.height/q),this._x=(J.width-j*this._scale)/2,this._y=(J.height-q*this._scale)/2,this._userZoomed=!1,this._apply()}zoomBy(j,q,J){if(!this._size)return;let B=this._stage.getBoundingClientRect(),F=Math.min(B.width/this._size.width,B.height/this._size.height),P=Math.min(Math.max(this._scale*j,F*M),F*N),Q=q??B.width/2,V=J??B.height/2;this._x=Q-(Q-this._x)*P/this._scale,this._y=V-(V-this._y)*P/this._scale,this._scale=P,this._userZoomed=!0,this._apply()}_apply(){if(this._view.style.transform=`translate(${this._x}px, ${this._y}px) scale(${this._scale})`,this._settle)clearTimeout(this._settle);this._settle=setTimeout(()=>{let j=Math.min(Math.max(2,Math.ceil((window.devicePixelRatio||1)*this._scale)),4);if(Number(this._canvas.getAttribute("density"))!==j)this._canvas.setAttribute("density",String(j))},150)}_bindZoom(){let j=this._stage,q=()=>this.getAttribute("zoom")!=="false";j.addEventListener("wheel",(F)=>{if(!q()||!(F.ctrlKey||F.metaKey))return;F.preventDefault();let P=j.getBoundingClientRect();this.zoomBy(Math.exp(-F.deltaY*0.01),F.clientX-P.left,F.clientY-P.top)},{passive:!1});let J=null;j.addEventListener("pointerdown",(F)=>{if(!q()||F.button!==0)return;J={id:F.pointerId,x:F.clientX,y:F.clientY},j.setPointerCapture(F.pointerId)}),j.addEventListener("pointermove",(F)=>{if(!J||J.id!==F.pointerId)return;this._x+=F.clientX-J.x,this._y+=F.clientY-J.y,J.x=F.clientX,J.y=F.clientY,this._userZoomed=!0,this._view.style.transform=`translate(${this._x}px, ${this._y}px) scale(${this._scale})`});let B=()=>J=null;j.addEventListener("pointerup",B),j.addEventListener("pointercancel",B),j.addEventListener("dblclick",()=>q()&&this.fit())}_buildControls(){let j=this._bar;if(j.innerHTML="",this._controlsPage=this._canvas.page,this.getAttribute("zoom")!=="false")j.appendChild(this._btn("Fit","Reset zoom",()=>this.fit()));let q=this._canvas.pages;if(this.hasAttribute("page-switch")&&q.length>1)j.appendChild(this._pageSelect(q));let J=this._canvas.modes,B=Object.keys(J).filter((F)=>J[F].values.length>1);if(this.hasAttribute("mode-switch")&&B.length)for(let F of B)j.appendChild(this._modeSelect(F,J[F]));if(this.hasAttribute("copy"))j.appendChild(this._btn("Copy","Copy .gui markup",async()=>{await navigator.clipboard.writeText(this._canvas.source)}));if(this.hasAttribute("download"))j.appendChild(this._btn("Download","Download .gui file",()=>this._download()));j.style.display=j.children.length?"flex":"none"}_btn(j,q,J){let B=document.createElement("button");return B.type="button",B.textContent=j,B.title=q,B.style.cssText=["all:unset;cursor:pointer;font:600 12px/1 system-ui","color:#fff;padding:6px 9px;border-radius:5px"].join(";"),B.addEventListener("pointerenter",()=>B.style.background="rgba(255,255,255,.18)"),B.addEventListener("pointerleave",()=>B.style.background="transparent"),B.addEventListener("click",J),B}_select(j){let q=document.createElement("select");return q.title=j,q.style.cssText=["all:unset;cursor:pointer;font:600 12px/1 system-ui","color:#fff;padding:6px 9px;border-radius:5px"].join(";"),q}_option(j,q,J){let B=document.createElement("option");if(B.value=j,B.textContent=q,B.style.color="#000",J)B.selected=!0;return B}_pageSelect(j){let q=this._select("Page");q.className="gui-embed-pages";let J=this._canvas.page;for(let B of j){let F=B.library?"Library":B.name.replace(/\.guix$/,"");q.appendChild(this._option(B.name,F,B.name===J))}return q.addEventListener("change",()=>this.setAttribute("page",q.value)),q}_modeSelect(j,q){let J=this._select(`Mode: ${j}`),B=this._canvas.mode[j]??q.default;for(let F of q.values)J.appendChild(this._option(F,F,F===B));return J.addEventListener("change",()=>this._canvas.setMode(j,J.value)),J}_download(){let j=this._bytes??D({xml:this._markup,assets:{}}),q=(this.getAttribute("src")?.split("/").pop()||"design.gui").replace(/\.guix$/,".gui"),J=URL.createObjectURL(new Blob([j],{type:"application/octet-stream"})),B=document.createElement("a");B.href=J,B.download=q.endsWith(".gui")?q:q+".gui",B.click(),setTimeout(()=>URL.revokeObjectURL(J),1000)}}function S(){if(typeof customElements<"u"&&!customElements.get(R))customElements.define(R,K)}import{GuiCanvas as k,config as y}from"@dotgui/render/canvas";var X=!1;function f(){if(X||typeof window>"u")return;X=!0,S()}export{f as install,S as defineGuiEmbed,y as config,K as GuiEmbedElement,k as GuiCanvas};
|
package/dist/gui-embed.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(()=>{var
|
|
1
|
+
(()=>{var eJ=Object.defineProperty;var JQ=(J,Q)=>{for(var $ in Q)eJ(J,$,{get:Q[$],enumerable:!0,configurable:!0,set:(K)=>Q[$]=()=>K})};var RJ={};JQ(RJ,{install:()=>DJ,defineGuiEmbed:()=>WJ,config:()=>t,GuiEmbedElement:()=>HJ,GuiCanvas:()=>$J});var t={workerUrl:null},a=null;function QQ(){if(a)return a;let J=new URL(t.workerUrl??new URL("./render-worker.js",document.baseURI),location.href),Q=J.origin===location.origin?J:URL.createObjectURL(new Blob([`import ${JSON.stringify(J.href)}`],{type:"text/javascript"}));return a=new Worker(Q,{type:"module"}),a.onmessage=({data:{id:$,ok:K,result:q,error:H}})=>{let W=BJ.get($);if(BJ.delete($),K)W.resolve(q);else W.reject(Error(H))},a}var BJ=new Map,$Q=0,KQ=0;function n(J,Q,$=[]){let K=$Q++;return new Promise((q,H)=>{BJ.set(K,{resolve:q,reject:H}),QQ().postMessage({id:K,type:J,...Q},$)})}var FJ=(J)=>J==null?null:new URL(J,location.href).href,qQ=new Set(["tokens","fonts","styles","components","modes"]);function TJ(J,Q){let $=(K,q)=>{Q(K,q),[...K.children].forEach((H,W)=>$(H,`${q}.${W}`))};[...J.documentElement.children].forEach((K,q)=>{if(!qQ.has(K.localName))$(K,String(q))})}var SJ={alert:"alert",banner:"status",breadcrumb:"navigation",button:"button",checkbox:"checkbox",combobox:"combobox","context-menu":"menu",dialog:"dialog",divider:"separator","dropdown-menu":"menu","floating-action-button":"button",hyperlink:"link","loading-indicator":"progressbar","navigation-menu":"navigation",pagination:"navigation","progress-indicator":"progressbar","radio-button":"radio","search-bar":"search",select:"combobox",sidebar:"complementary",slider:"slider",switch:"switch","tab-bar":"tablist",table:"table","text-area":"textbox","text-field":"textbox",toast:"status",toolbar:"toolbar",tooltip:"tooltip","top-navigation-bar":"navigation",tree:"tree"};function HQ(J){let{tag:Q,attributes:$}=J;if(Q==="text"){let H=$.value??J.text??"";if(!H.trim())return null;let W=document.createElement("span");W.textContent=H;let j=Number.parseFloat($.size);if(j>0)W.style.fontSize=`${j}px`;return W}if(Q==="img"){let H=$.alt??$.name;if(!H)return null;let W=document.createElement("div");return W.setAttribute("role","img"),W.setAttribute("aria-label",H),W}let K=$.role;if(!K)return null;let q=document.createElement("div");if(q.setAttribute("role",SJ[K]??"group"),!SJ[K])q.setAttribute("aria-roledescription",K.replace(/-/g," "));if($.name)q.setAttribute("aria-label",$.name);return q}var WQ=`
|
|
2
2
|
:host { display: inline-block; position: relative; line-height: 0; }
|
|
3
3
|
canvas { display: block; max-width: 100%; height: auto; }
|
|
4
4
|
.text { position: absolute; left: 0; top: 0; transform-origin: 0 0; pointer-events: none; overflow: hidden; }
|
|
@@ -7,4 +7,4 @@
|
|
|
7
7
|
.box { position: absolute; pointer-events: none; box-sizing: border-box; }
|
|
8
8
|
.hover { outline: 1px solid #2f7bff; }
|
|
9
9
|
.selected { outline: 2px solid #2f7bff; box-shadow: 0 0 0 1px #fff inset; }
|
|
10
|
-
`,HQ=globalThis.HTMLElement??class{};class $J extends HQ{#W=QQ++;#z=null;#L=!1;#Q=null;#H=null;#V=new Map;#$=null;#D=null;#P=!1;#C=!1;#j=null;#Z={};#R=!1;#q=null;#X=null;#B=null;#M={};#J;#E;#N;#I;constructor(){super();let J=this.attachShadow({mode:"open"});J.innerHTML=`<style>${qQ}</style><canvas aria-hidden="true"></canvas><div class="text"></div><div class="box hover" hidden></div><div class="box selected" hidden></div>`,this.#J=J.querySelector("canvas"),this.#E=J.querySelector(".text"),new ResizeObserver(()=>this.#g()).observe(this.#J),this.#N=J.querySelector(".hover"),this.#I=J.querySelector(".selected"),this.#J.addEventListener("pointermove",(Q)=>{if(!this.selectable)return;let $=this.nodeAt(...this.#_(Q));if($===this.#D)return;this.#D=$,this.#G(this.#N,$!==this.#$?$:null)}),this.#J.addEventListener("pointerleave",()=>{this.#D=null,this.#G(this.#N,null)}),this.#J.addEventListener("click",(Q)=>{if(!this.selectable)return;this.select(this.nodeAt(...this.#_(Q)))})}static get observedAttributes(){return["density"]}attributeChangedCallback(J,Q,$){if(J==="density"&&Q!==$&&this.#Q)this.#F()}get selectable(){return this.hasAttribute("selectable")}async connectedCallback(){this.#y(),await this.#O();let J=this.getAttribute("src"),Q=this.querySelector('script[type="application/gui"]');try{if(J)await this.load(J);else if(Q)await this.#Y(Q.textContent)}catch($){this.#K("error",{message:String($.message??$)})}}#O(){return this.#z??=(()=>{let J=this.#J.transferControlToOffscreen?.();return this.#L=Boolean(J),n("open",{key:this.#W,canvas:J,fontList:this.#U},J?[J]:[])})(),this.#z}get#U(){return FJ(this.getAttribute("font-list"))}async load(J){this.#j=performance.now(),this.#Z={};let Q=async(K,H)=>{let q=performance.now();try{return await H()}finally{this.#Z[K]=(this.#Z[K]??0)+performance.now()-q}};await Q("open",async()=>{await this.#O(),await n("open",{key:this.#W,fontList:this.#U})});let $=await Q("download",async()=>{let K=await fetch(J);if(!K.ok)throw Error(`${J}: ${K.status}`);return K.arrayBuffer()});await this.#A($,Q)}async loadBytes(J){this.#j=performance.now(),this.#Z={},await this.#O(),await n("open",{key:this.#W,fontList:this.#U});let Q=J instanceof ArrayBuffer?J.slice(0):J.buffer.slice(J.byteOffset,J.byteOffset+J.byteLength);await this.#A(Q,($,K)=>K())}async#A(J,Q){let $=new Uint8Array(J,0,Math.min(2,J.byteLength));if(!($[0]===80&&$[1]===75)){this.#q=null,this.#X=null,this.#K("pages",{pages:[],page:null}),await this.#Y(new TextDecoder().decode(J));return}this.#X=null,this.#B=null,this.#q=await Q("unpack",()=>n("loadPackage",{key:this.#W,bytes:J},[J]));let H=this.pages[0];if(!H){this.#K("error",{message:"the package has no page to show"});return}await this.#w(H.name)}async loadMarkup(J){await this.#O(),await n("open",{key:this.#W,fontList:this.#U}),this.#q=null,this.#X=null,this.#B=null,this.#K("pages",{pages:[],page:null}),await this.#Y(J)}get pages(){if(!this.#q)return[];let J=this.#q.documents.map(({name:$})=>({name:$,library:!1})),Q=this.#q.library;if(Q?.hasPage)J.push({name:Q.name,library:!0});return J}get page(){return this.#X}set page(J){this.#w(J)}#T(J){let{documents:Q,library:$}=this.#q??{};return Q?.find((K)=>K.name===J)??($?.name===J?$:null)}get#S(){return Boolean(this.#q?.library&&this.#q.library.name===this.#B)}async#w(J){let Q=this.#T(J);if(!Q)throw Error(`no page ${J}`);let $=this.#T(this.#B);if($&&this.#Q)$.xml=this.source;if(this.#X=J,this.#$=null,this.#K("pages",{pages:this.pages,page:J}),Q.xml==null){this.#K("error",{message:`${J}: ${Q.error??"unreadable"}`});return}await this.#Y(Q.xml)}get source(){return this.#Q?new XMLSerializer().serializeToString(this.#Q):""}set source(J){this.#Y(J)}async#Y(J){this.#j??=performance.now();let Q=performance.now(),$=await n("normalize",{xml:J});this.#Z.normalize=performance.now()-Q;let K=new DOMParser().parseFromString($,"application/xml"),H=K.querySelector("parsererror");if(H||K.documentElement.localName!=="gui"){this.#K("error",{message:H?.textContent??"the root element is not <gui>"});return}if(this.#Q=K,this.#B=this.#X,this.#x(),this.#$&&!this.#V.has(this.#$))this.#$=null;await this.#F()}get modes(){let J={},Q=(K)=>{for(let H of K?.getElementsByTagName("mode")??[]){let q=H.getAttribute("name"),W=(H.getAttribute("values")??"").split(/\s+/).filter(Boolean);if(!q||W.length===0)continue;let j=H.getAttribute("default");J[q]={values:W,default:W.includes(j)?j:W[0]}}},$=this.#q?.library;if($?.xml&&!this.#S)Q(new DOMParser().parseFromString($.xml,"application/xml"));return Q(this.#Q),J}get mode(){return{...this.#M}}set mode(J){if(this.#M={...J},this.#Q)this.#F()}setMode(J,Q){let $={...this.#M};if(Q==null)delete $[J];else $[J]=Q;this.mode=$}get document(){return this.#Q}element(J){return this.#V.get(J)??null}idOf(J){for(let[Q,$]of this.#V)if($===J)return Q;return null}get selected(){return this.#$}select(J){this.#$=J&&this.#V.has(J)?J:null,this.#G(this.#I,this.#$),this.#G(this.#N,null),this.#K("select",{id:this.#$,element:this.element(this.#$)})}nodeAt(J,Q){let $=(K)=>{let{x:H,y:q,width:W,height:j}=K.rect;if(K.attributes.visible==="false")return null;for(let V=K.children.length-1;V>=0;V--){let Z=$(K.children[V]);if(Z)return Z}return J>=H&&Q>=q&&J<H+W&&Q<q+j?K.attributes["data-uid"]??null:null};return this.#H?$(this.#H):null}bounds(J){let Q=($)=>{if($.attributes["data-uid"]===J)return $.rect;for(let K of $.children){let H=Q(K);if(H)return H}return null};return this.#H&&J?Q(this.#H):null}apply(J){this.#j??=performance.now();for(let Q of J){let $=this.element(Q.node);if(!$)throw Error(`no element ${Q.node}`);if(Q.op==="set")if(Q.value==null)$.removeAttribute(Q.attr);else $.setAttribute(Q.attr,Q.value);else if(Q.op==="text")if($.hasAttribute("value")||!$.textContent.trim())$.setAttribute("value",Q.value);else $.textContent=Q.value;else if(Q.op==="remove")$.remove(),this.#x();else throw Error(`unknown op ${Q.op}`)}this.#F()}#x(){this.#V.clear(),TJ(this.#Q,(J,Q)=>this.#V.set(Q,J))}#v(){let J=this.#Q.cloneNode(!0);return TJ(J,(Q,$)=>Q.setAttribute("data-uid",$)),new XMLSerializer().serializeToString(J)}async#F(){if(this.#P){this.#C=!0;return}this.#P=!0;try{do{this.#C=!1;let J=this.density,Q=this.#v(),$=FJ(this.getAttribute("asset-proxy")),K=performance.now(),H=this.#S,q=await n("render",{key:this.#W,xml:Q,library:H,density:J,proxy:$,fontFile:FJ(this.getAttribute("font-file")),modes:this.#M});if(this.#C)continue;if(this.#H=q.layout,!this.#L){this.#J.width=q.width,this.#J.height=q.height;let Z=new ImageData(new Uint8ClampedArray(q.pixels),q.width,q.height);this.#J.getContext("2d").putImageData(Z,0,0)}let{width:W,height:j}=q.layout.rect;this.#J.style.width=`${W}px`,this.#J.style.aspectRatio=`${W} / ${j}`,this.#G(this.#I,this.#$),this.#u(q.layout);let F=this.#j==null?null:performance.now()-this.#j,V={...this.#Z,fonts:q.fontsMs,render:q.engineMs,draw:q.drawMs??0,transport:performance.now()-K-q.fontsMs-q.engineMs-(q.drawMs??0)};if(this.#j=null,this.#Z={},this.#K("render",{ms:q.engineMs+(q.drawMs??0),wallMs:F,timings:V,complete:q.missingImages===0,engineMs:q.engineMs,offscreen:this.#L,density:q.density??J,width:W,height:j,pixels:[q.width,q.height],warnings:q.warnings,repainted:q.repainted??null}),q.missingImages>0)this.#k(Q,H,$)}while(this.#C)}catch(J){this.#K("error",{message:String(J.message??J)})}finally{this.#P=!1}}async#k(J,Q,$){if(this.#R)return;this.#R=!0;try{if(await n("supplyImages",{key:this.#W,xml:J,library:Q,proxy:$})>0)this.#F()}catch(K){this.#K("error",{message:String(K.message??K)})}finally{this.#R=!1}}get density(){let J=Number(this.getAttribute("density"));if(J>0)return Math.min(J,4);return Math.min(Math.max(2,Math.ceil(window.devicePixelRatio||1)),3)}#y(){matchMedia(`(resolution: ${window.devicePixelRatio}dppx)`).addEventListener("change",()=>{if(this.#Q)this.#F();this.#y()},{once:!0})}#_(J){let Q=this.#J.getBoundingClientRect(),$=(this.#H?.rect.width??Q.width)/Q.width;return[(J.clientX-Q.left)*$,(J.clientY-Q.top)*$]}#u(J){let Q=this.#E;Q.replaceChildren();let{width:$,height:K}=J.rect;Object.assign(Q.style,{width:`${$}px`,height:`${K}px`});let H=(q,W,j)=>{if(q.attributes.visible==="false")return;let F=KQ(q);if(F){let{x:V,y:Z,width:X,height:C}=q.rect;Object.assign(F.style,{left:`${V-j.x}px`,top:`${Z-j.y}px`,width:`${X}px`,height:`${C}px`}),W.append(F);for(let M of q.children)H(M,F,q.rect)}else for(let V of q.children)H(V,W,j)};H(J,Q,{x:0,y:0}),this.#g()}#g(){let J=this.#H?.rect.width;if(!J)return;let Q=this.#J.getBoundingClientRect().width;this.#E.style.transform=Q?`scale(${Q/J})`:""}#G(J,Q){let $=this.bounds(Q);if(J.hidden=!$,!$)return;let K=this.#J.getBoundingClientRect().width/this.#H.rect.width||1;Object.assign(J.style,{left:`${$.x*K}px`,top:`${$.y*K}px`,width:`${$.width*K}px`,height:`${$.height*K}px`})}#K(J,Q){this.dispatchEvent(new CustomEvent(J,{detail:Q}))}}if(typeof customElements<"u"&&!customElements.get("gui-canvas"))customElements.define("gui-canvas",$J);var E=Uint8Array,w=Uint16Array,OJ=Int32Array,UJ=new E([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0]),LJ=new E([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,0,0]),wJ=new E([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),kJ=function(J,Q){var $=new w(31);for(var K=0;K<31;++K)$[K]=Q+=1<<J[K-1];var H=new OJ($[30]);for(var K=1;K<30;++K)for(var q=$[K];q<$[K+1];++q)H[q]=q-$[K]<<5|K;return{b:$,r:H}},uJ=kJ(UJ,2),WQ=uJ.b,GJ=uJ.r;WQ[28]=258,GJ[258]=28;var hJ=kJ(LJ,0),kQ=hJ.b,xJ=hJ.r,CJ=new w(32768);for(B=0;B<32768;++B)b=(B&43690)>>1|(B&21845)<<1,b=(b&52428)>>2|(b&13107)<<2,b=(b&61680)>>4|(b&3855)<<4,CJ[B]=((b&65280)>>8|(b&255)<<8)>>1;var b,B,QJ=function(J,Q,$){var K=J.length,H=0,q=new w(Q);for(;H<K;++H)if(J[H])++q[J[H]-1];var W=new w(Q);for(H=1;H<Q;++H)W[H]=W[H-1]+q[H-1]<<1;var j;if($){j=new w(1<<Q);var F=15-Q;for(H=0;H<K;++H)if(J[H]){var V=H<<4|J[H],Z=Q-J[H],X=W[J[H]-1]++<<Z;for(var C=X|(1<<Z)-1;X<=C;++X)j[CJ[X]>>F]=V}}else{j=new w(K);for(H=0;H<K;++H)if(J[H])j[H]=CJ[W[J[H]-1]++]>>15-J[H]}return j},d=new E(288);for(B=0;B<144;++B)d[B]=8;var B;for(B=144;B<256;++B)d[B]=9;var B;for(B=256;B<280;++B)d[B]=7;var B;for(B=280;B<288;++B)d[B]=8;var B,KJ=new E(32);for(B=0;B<32;++B)KJ[B]=5;var B,jQ=QJ(d,9,0);var ZQ=QJ(KJ,5,0);var fJ=function(J){return(J+7)/8|0},bJ=function(J,Q,$){if(Q==null||Q<0)Q=0;if($==null||$>J.length)$=J.length;return new E(J.subarray(Q,$))};var VQ=["unexpected EOF","invalid block type","invalid length/literal","invalid distance","stream finished","no stream handler",,"no callback","invalid UTF-8 data","extra field too long","date not in range 1980-2099","filename too long","stream finishing","invalid zip data"],qJ=function(J,Q,$){var K=Error(Q||VQ[J]);if(K.code=J,Error.captureStackTrace)Error.captureStackTrace(K,qJ);if(!$)throw K;return K};var m=function(J,Q,$){$<<=Q&7;var K=Q/8|0;J[K]|=$,J[K+1]|=$>>8},e=function(J,Q,$){$<<=Q&7;var K=Q/8|0;J[K]|=$,J[K+1]|=$>>8,J[K+2]|=$>>16},YJ=function(J,Q){var $=[];for(var K=0;K<J.length;++K)if(J[K])$.push({s:K,f:J[K]});var H=$.length,q=$.slice();if(!H)return{t:pJ,l:0};if(H==1){var W=new E($[0].s+1);return W[$[0].s]=1,{t:W,l:1}}$.sort(function(z,A){return z.f-A.f}),$.push({s:-1,f:25001});var j=$[0],F=$[1],V=0,Z=1,X=2;$[0]={s:-1,f:j.f+F.f,l:j,r:F};while(Z!=H-1)j=$[$[V].f<$[X].f?V++:X++],F=$[V!=Z&&$[V].f<$[X].f?V++:X++],$[Z++]={s:-1,f:j.f+F.f,l:j,r:F};var C=q[0].s;for(var K=1;K<H;++K)if(q[K].s>C)C=q[K].s;var M=new w(C+1),O=MJ($[Z-1],M,0);if(O>Q){var K=0,N=0,I=O-Q,v=1<<I;q.sort(function(A,U){return M[U.s]-M[A.s]||A.f-U.f});for(;K<H;++K){var x=q[K].s;if(M[x]>Q)N+=v-(1<<O-M[x]),M[x]=Q;else break}N>>=I;while(N>0){var k=q[K].s;if(M[k]<Q)N-=1<<Q-M[k]++-1;else++K}for(;K>=0&&N;--K){var L=q[K].s;if(M[L]==Q)--M[L],++N}O=Q}return{t:new E(M),l:O}},MJ=function(J,Q,$){return J.s==-1?Math.max(MJ(J.l,Q,$+1),MJ(J.r,Q,$+1)):Q[J.s]=$},yJ=function(J){var Q=J.length;while(Q&&!J[--Q]);var $=new w(++Q),K=0,H=J[0],q=1,W=function(F){$[K++]=F};for(var j=1;j<=Q;++j)if(J[j]==H&&j!=Q)++q;else{if(!H&&q>2){for(;q>138;q-=138)W(32754);if(q>2)W(q>10?q-11<<5|28690:q-3<<5|12305),q=0}else if(q>3){W(H),--q;for(;q>6;q-=6)W(8304);if(q>2)W(q-3<<5|8208),q=0}while(q--)W(H);q=1,H=J[j]}return{c:$.subarray(0,K),n:Q}},JJ=function(J,Q){var $=0;for(var K=0;K<Q.length;++K)$+=J[K]*Q[K];return $},mJ=function(J,Q,$){var K=$.length,H=fJ(Q+2);J[H]=K&255,J[H+1]=K>>8,J[H+2]=J[H]^255,J[H+3]=J[H+1]^255;for(var q=0;q<K;++q)J[H+q+4]=$[q];return(H+4+K)*8},_J=function(J,Q,$,K,H,q,W,j,F,V,Z){m(Q,Z++,$),++H[256];var X=YJ(H,15),C=X.t,M=X.l,O=YJ(q,15),N=O.t,I=O.l,v=yJ(C),x=v.c,k=v.n,L=yJ(N),z=L.c,A=L.n,U=new w(19);for(var G=0;G<x.length;++G)++U[x[G]&31];for(var G=0;G<z.length;++G)++U[z[G]&31];var Y=YJ(U,7),T=Y.t,r=Y.l,S=19;for(;S>4&&!T[wJ[S-1]];--S);var o=V+5<<3,y=JJ(H,d)+JJ(q,KJ)+W,_=JJ(H,C)+JJ(q,N)+W+14+3*S+JJ(U,T)+2*U[16]+3*U[17]+7*U[18];if(F>=0&&o<=y&&o<=_)return mJ(Q,Z,J.subarray(F,F+V));var u,D,g,p;if(m(Q,Z,1+(_<y)),Z+=2,_<y){u=QJ(C,M,0),D=C,g=QJ(N,I,0),p=N;var jJ=QJ(T,r,0);m(Q,Z,k-257),m(Q,Z+5,A-1),m(Q,Z+10,S-4),Z+=14;for(var G=0;G<S;++G)m(Q,Z+3*G,T[wJ[G]]);Z+=3*S;var h=[x,z];for(var l=0;l<2;++l){var s=h[l];for(var G=0;G<s.length;++G){var f=s[G]&31;if(m(Q,Z,jJ[f]),Z+=T[f],f>15)m(Q,Z,s[G]>>5&127),Z+=s[G]>>12}}}else u=jQ,D=d,g=ZQ,p=KJ;for(var G=0;G<j;++G){var R=K[G];if(R>255){var f=R>>18&31;if(e(Q,Z,u[f+257]),Z+=D[f+257],f>7)m(Q,Z,R>>23&31),Z+=UJ[f];var i=R&31;if(e(Q,Z,g[i]),Z+=p[i],i>3)e(Q,Z,R>>5&8191),Z+=LJ[i]}else e(Q,Z,u[R]),Z+=D[R]}return e(Q,Z,u[256]),Z+D[256]},XQ=new OJ([65540,131080,131088,131104,262176,1048704,1048832,2114560,2117632]),pJ=new E(0),FQ=function(J,Q,$,K,H,q){var W=q.z||J.length,j=new E(K+W+5*(1+Math.ceil(W/7000))+H),F=j.subarray(K,j.length-H),V=q.l,Z=(q.r||0)&7;if(Q){if(Z)F[0]=q.r>>3;var X=XQ[Q-1],C=X>>13,M=X&8191,O=(1<<$)-1,N=q.p||new w(32768),I=q.h||new w(O+1),v=Math.ceil($/3),x=2*v,k=function(XJ){return(J[XJ]^J[XJ+1]<<v^J[XJ+2]<<x)&O},L=new OJ(25000),z=new w(288),A=new w(32),U=0,G=0,Y=q.i||0,T=0,r=q.w||0,S=0;for(;Y+2<W;++Y){var o=k(Y),y=Y&32767,_=I[o];if(N[y]=_,I[o]=y,r<=Y){var u=W-Y;if((U>7000||T>24576)&&(u>423||!V)){Z=_J(J,F,0,L,z,A,G,T,S,Y-S,Z),T=U=G=0,S=Y;for(var D=0;D<286;++D)z[D]=0;for(var D=0;D<30;++D)A[D]=0}var g=2,p=0,jJ=M,h=y-_&32767;if(u>2&&o==k(Y-h)){var l=Math.min(C,u)-1,s=Math.min(32767,Y),f=Math.min(258,u);while(h<=s&&--jJ&&y!=_){if(J[Y+g]==J[Y+g-h]){var R=0;for(;R<f&&J[Y+R]==J[Y+R-h];++R);if(R>g){if(g=R,p=h,R>l)break;var i=Math.min(h,R-2),EJ=0;for(var D=0;D<i;++D){var ZJ=Y-h+D&32767,lJ=N[ZJ],IJ=ZJ-lJ&32767;if(IJ>EJ)EJ=IJ,_=ZJ}}}y=_,_=N[y],h+=y-_&32767}}if(p){L[T++]=268435456|GJ[g]<<18|xJ[p];var zJ=GJ[g]&31,AJ=xJ[p]&31;G+=UJ[zJ]+LJ[AJ],++z[257+zJ],++A[AJ],r=Y+g,++U}else L[T++]=J[Y],++z[J[Y]]}}for(Y=Math.max(Y,r);Y<W;++Y)L[T++]=J[Y],++z[J[Y]];if(Z=_J(J,F,V,L,z,A,G,T,S,Y-S,Z),!V)q.r=Z&7|F[Z/8|0]<<3,Z-=7,q.h=I,q.p=N,q.i=Y,q.w=r}else{for(var Y=q.w||0;Y<W+V;Y+=65535){var VJ=Y+65535;if(VJ>=W)F[Z/8|0]=V,VJ=W;Z=mJ(F,Z+1,J.subarray(Y,VJ))}q.i=W}return bJ(j,0,K+fJ(Z)+H)},BQ=function(){var J=new Int32Array(256);for(var Q=0;Q<256;++Q){var $=Q,K=9;while(--K)$=($&1&&-306674912)^$>>>1;J[Q]=$}return J}(),YQ=function(){var J=-1;return{p:function(Q){var $=J;for(var K=0;K<Q.length;++K)$=BQ[$&255^Q[K]]^$>>>8;J=$},d:function(){return~J}}};var GQ=function(J,Q,$,K,H){if(!H){if(H={l:1},Q.dictionary){var q=Q.dictionary.subarray(-32768),W=new E(q.length+J.length);W.set(q),W.set(J,q.length),J=W,H.w=q.length}}return FQ(J,Q.level==null?6:Q.level,Q.mem==null?H.l?Math.ceil(Math.max(8,Math.min(13,Math.log(J.length)))*1.5):20:12+Q.mem,$,K,H)},nJ=function(J,Q){var $={};for(var K in J)$[K]=J[K];for(var K in Q)$[K]=Q[K];return $};var P=function(J,Q,$){for(;$;++Q)J[Q]=$,$>>>=8};function CQ(J,Q){return GQ(J,Q||{},0,0)}var cJ=function(J,Q,$,K){for(var H in J){var q=J[H],W=Q+H,j=K;if(Array.isArray(q))j=nJ(K,q[1]),q=q[0];if(ArrayBuffer.isView(q))$[W]=[q,j];else $[W+="/"]=[new E(0),j],cJ(q,W,$,K)}},gJ=typeof TextEncoder<"u"&&new TextEncoder,MQ=typeof TextDecoder<"u"&&new TextDecoder,NQ=0;try{MQ.decode(pJ,{stream:!0}),NQ=1}catch(J){}function c(J,Q){if(Q){var $=new E(J.length);for(var K=0;K<J.length;++K)$[K]=J.charCodeAt(K);return $}if(gJ)return gJ.encode(J);var H=J.length,q=new E(J.length+(J.length>>1)),W=0,j=function(Z){q[W++]=Z};for(var K=0;K<H;++K){if(W+5>q.length){var F=new E(W+8+(H-K<<1));F.set(q),q=F}var V=J.charCodeAt(K);if(V<128||Q)j(V);else if(V<2048)j(192|V>>6),j(128|V&63);else if(V>55295&&V<57344)V=65536+(V&1047552)|J.charCodeAt(++K)&1023,j(240|V>>18),j(128|V>>12&63),j(128|V>>6&63),j(128|V&63);else j(224|V>>12),j(128|V>>6&63),j(128|V&63)}return bJ(q,0,W)}var NJ=function(J){var Q=0;if(J)for(var $ in J){var K=J[$].length;if(K>65535)qJ(9);Q+=K+4}return Q},vJ=function(J,Q,$,K,H,q,W,j){var F=K.length,V=$.extra,Z=j&&j.length,X=NJ(V);if(P(J,Q,W!=null?33639248:67324752),Q+=4,W!=null)J[Q++]=20,J[Q++]=$.os;J[Q]=20,Q+=2,J[Q++]=$.flag<<1|(q<0&&8),J[Q++]=H&&8,J[Q++]=$.compression&255,J[Q++]=$.compression>>8;var C=new Date($.mtime==null?Date.now():$.mtime),M=C.getFullYear()-1980;if(M<0||M>119)qJ(10);if(P(J,Q,M<<25|C.getMonth()+1<<21|C.getDate()<<16|C.getHours()<<11|C.getMinutes()<<5|C.getSeconds()>>1),Q+=4,q!=-1)P(J,Q,$.crc),P(J,Q+4,q<0?-q-2:q),P(J,Q+8,$.size);if(P(J,Q+12,F),P(J,Q+14,X),Q+=16,W!=null)P(J,Q,Z),P(J,Q+6,$.attrs),P(J,Q+10,W),Q+=14;if(J.set(K,Q),Q+=F,X)for(var O in V){var N=V[O],I=N.length;P(J,Q,+O),P(J,Q+2,I),J.set(N,Q+4),Q+=4+I}if(Z)J.set(j,Q),Q+=Z;return Q},OQ=function(J,Q,$,K,H){P(J,Q,101010256),P(J,Q+8,$),P(J,Q+10,$),P(J,Q+12,K),P(J,Q+16,H)};function dJ(J,Q){if(!Q)Q={};var $={},K=[];cJ(J,"",$,Q);var H=0,q=0;for(var W in $){var j=$[W],F=j[0],V=j[1],Z=V.level==0?0:8,X=c(W),C=X.length,M=V.comment,O=M&&c(M),N=O&&O.length,I=NJ(V.extra);if(C>65535)qJ(11);var v=Z?CQ(F,V):F,x=v.length,k=YQ();k.p(F),K.push(nJ(V,{size:F.length,crc:k.d(),c:v,f:X,m:O,u:C!=W.length||O&&M.length!=N,o:H,compression:Z})),H+=30+C+I+x,q+=76+2*(C+I)+(N||0)+x}var L=new E(q+22),z=H,A=q-H;for(var U=0;U<K.length;++U){var X=K[U];vJ(L,X.o,X,X.f,X.u,X.c.length);var G=30+X.f.length+NJ(X.extra);L.set(X.c,X.o+G),vJ(L,H,X,X.f,X.u,X.c.length,X.o,X.m),H+=16+G+(X.m?X.m.length:0)}return OQ(L,H,K.length,A,z),L}var UQ=new Set(["frame","stack","row","col","grid","group"]);var LQ=new Set(["text","img","svg","shape","instance"]),DQ=new Set([...UQ,...LQ]),PQ=new Set(["preview","tokens","styles","fonts","assets","meta","components"]),hQ=new Set([...DQ,...PQ,"gui","color","number","string","text-style","fill-style","effect-style","font","image","appearance","fill","effect","segment","path","component","component-set","variant","props","prop","slot"]);var DJ="library.guix";var zQ="design.guix",AQ="preview.webp",rJ="assets/";function TQ(J){return J.startsWith(rJ)?J:rJ+J}function SQ(J){let Q={};if(J.documents&&J.primary){for(let[K,H]of Object.entries(J.documents))Q[K]=c(H);Q[J.primary]=c(J.xml)}else Q[zQ]=c(J.xml);if(J.library!==void 0)Q[DJ]=c(J.library);for(let[K,H]of Object.entries(J.libraryFiles||{}))Q[K]=c(H);if(J.preview)Q[AQ]=J.preview;for(let[K,H]of Object.entries(J.assets))Q[TQ(K)]=H;let $={};for(let K of Object.keys(Q).sort())$[K.normalize("NFC")]=Q[K];return $}function oJ(J){return dJ(SQ(J))}var sJ="gui-embed",wQ=0.25,xQ=8;class HJ extends HTMLElement{_stage;_view;_canvas;_bar;_ro=null;_bytes=null;_markup="";_size=null;_scale=1;_x=0;_y=0;_userZoomed=!1;_settle=null;static get observedAttributes(){return["src"]}connectedCallback(){if(!this._stage)this._build();this._load()}disconnectedCallback(){this._ro?.disconnect(),this._ro=null}attributeChangedCallback(J){if(J==="src"&&this._stage)this._load()}get canvas(){return this._canvas}_build(){let J=getComputedStyle(this);if(J.position==="static")this.style.position="relative";if(J.display==="inline")this.style.display="block";this.style.overflow="hidden";let Q=document.createElement("div");Q.className="gui-embed-canvas";let $=this.getAttribute("grid")!=="false";Q.style.cssText=["position:absolute;inset:0;touch-action:none","background-color:var(--gui-embed-bg, #fafaf8)",$?"background-image:radial-gradient(var(--gui-embed-dot, rgba(0,0,0,.14)) 1px, transparent 1.4px);background-size:var(--gui-embed-dot-gap, 18px) var(--gui-embed-dot-gap, 18px);background-position:center":""].filter(Boolean).join(";"),this.appendChild(Q),this._stage=Q;let K=document.createElement("div");K.style.cssText="position:absolute;left:0;top:0;width:max-content;transform-origin:0 0",Q.appendChild(K),this._view=K;let H=document.createElement("gui-canvas");H.addEventListener("render",(W)=>this._rendered(W.detail)),H.addEventListener("error",(W)=>this._fail(W.detail.message)),K.appendChild(H),this._canvas=H,this._bindZoom(),this._ro=new ResizeObserver(()=>{if(!this._userZoomed)this.fit()}),this._ro.observe(this);let q=document.createElement("div");q.className="gui-embed-controls",q.style.cssText=["position:absolute;top:8px;right:8px;z-index:2","display:flex;gap:4px;padding:4px","border-radius:8px;background:rgba(20,20,20,.55)","backdrop-filter:blur(8px);-webkit-backdrop-filter:blur(8px)","opacity:0;transition:opacity .15s ease"].join(";"),this.appendChild(q),this._bar=q,this.addEventListener("pointerenter",()=>q.style.opacity="1"),this.addEventListener("pointerleave",()=>q.style.opacity="0")}async _load(){this._size=null,this._userZoomed=!1,this._canvas.mode={};try{let J=this.getAttribute("src");if(J){let Q=await fetch(J);if(!Q.ok)throw Error(`gui-embed: failed to fetch "${J}" (${Q.status})`);this._bytes=new Uint8Array(await Q.arrayBuffer()),this._markup="",await this._canvas.loadBytes(this._bytes)}else{let Q=this.querySelector(':scope > script[type="application/gui"]');if(!Q){if(document.readyState==="loading")document.addEventListener("DOMContentLoaded",()=>void this._load(),{once:!0});return}this._bytes=null,this._markup=Q.textContent??"",await this._canvas.loadMarkup(this._markup)}this._buildControls()}catch(J){this._fail(String(J?.message??J))}}_fail(J){let Q=this.querySelector(":scope > .gui-embed-error");if(!Q)Q=document.createElement("div"),Q.className="gui-embed-error",Q.style.cssText="position:absolute;inset:0;display:flex;align-items:center;justify-content:center;font:13px system-ui;color:#c00;padding:12px;text-align:center",this.appendChild(Q);Q.textContent=J}_rendered(J){this.querySelector(":scope > .gui-embed-error")?.remove();let Q=!this._size||this._size.width!==J.width||this._size.height!==J.height;if(this._size={width:J.width,height:J.height},!Q)return;if(!this._hasHeight())if(this.style.width)this.style.aspectRatio=`${J.width} / ${J.height}`;else this.style.width=`${J.width}px`,this.style.height=`${J.height}px`;if(!this._userZoomed)this.fit()}_hasHeight(){if(this.style.height||this.style.aspectRatio)return!0;let J=getComputedStyle(this);if(J.aspectRatio&&J.aspectRatio!=="auto")return!0;return this.clientHeight>1}fit(){if(!this._size)return;let{width:J,height:Q}=this._size,$=this._stage.getBoundingClientRect();if($.width<1||$.height<1)return;this._scale=Math.min($.width/J,$.height/Q),this._x=($.width-J*this._scale)/2,this._y=($.height-Q*this._scale)/2,this._userZoomed=!1,this._apply()}zoomBy(J,Q,$){if(!this._size)return;let K=this._stage.getBoundingClientRect(),H=Math.min(K.width/this._size.width,K.height/this._size.height),q=Math.min(Math.max(this._scale*J,H*wQ),H*xQ),W=Q??K.width/2,j=$??K.height/2;this._x=W-(W-this._x)*q/this._scale,this._y=j-(j-this._y)*q/this._scale,this._scale=q,this._userZoomed=!0,this._apply()}_apply(){if(this._view.style.transform=`translate(${this._x}px, ${this._y}px) scale(${this._scale})`,this._settle)clearTimeout(this._settle);this._settle=setTimeout(()=>{let J=Math.min(Math.max(2,Math.ceil((window.devicePixelRatio||1)*this._scale)),4);if(Number(this._canvas.getAttribute("density"))!==J)this._canvas.setAttribute("density",String(J))},150)}_bindZoom(){let J=this._stage,Q=()=>this.getAttribute("zoom")!=="false";J.addEventListener("wheel",(H)=>{if(!Q()||!(H.ctrlKey||H.metaKey))return;H.preventDefault();let q=J.getBoundingClientRect();this.zoomBy(Math.exp(-H.deltaY*0.01),H.clientX-q.left,H.clientY-q.top)},{passive:!1});let $=null;J.addEventListener("pointerdown",(H)=>{if(!Q()||H.button!==0)return;$={id:H.pointerId,x:H.clientX,y:H.clientY},J.setPointerCapture(H.pointerId)}),J.addEventListener("pointermove",(H)=>{if(!$||$.id!==H.pointerId)return;this._x+=H.clientX-$.x,this._y+=H.clientY-$.y,$.x=H.clientX,$.y=H.clientY,this._userZoomed=!0,this._view.style.transform=`translate(${this._x}px, ${this._y}px) scale(${this._scale})`});let K=()=>$=null;J.addEventListener("pointerup",K),J.addEventListener("pointercancel",K),J.addEventListener("dblclick",()=>Q()&&this.fit())}_buildControls(){let J=this._bar;if(J.innerHTML="",this.getAttribute("zoom")!=="false")J.appendChild(this._btn("Fit","Reset zoom",()=>this.fit()));let Q=this._canvas.modes,$=Object.keys(Q).filter((K)=>Q[K].values.length>1);if(this.hasAttribute("mode-switch")&&$.length)for(let K of $)J.appendChild(this._modeSelect(K,Q[K]));if(this.hasAttribute("copy"))J.appendChild(this._btn("Copy","Copy .gui markup",async()=>{await navigator.clipboard.writeText(this._canvas.source)}));if(this.hasAttribute("download"))J.appendChild(this._btn("Download","Download .gui file",()=>this._download()));J.style.display=J.children.length?"flex":"none"}_btn(J,Q,$){let K=document.createElement("button");return K.type="button",K.textContent=J,K.title=Q,K.style.cssText=["all:unset;cursor:pointer;font:600 12px/1 system-ui","color:#fff;padding:6px 9px;border-radius:5px"].join(";"),K.addEventListener("pointerenter",()=>K.style.background="rgba(255,255,255,.18)"),K.addEventListener("pointerleave",()=>K.style.background="transparent"),K.addEventListener("click",$),K}_modeSelect(J,Q){let $=document.createElement("select");$.title=`Mode: ${J}`,$.style.cssText=["all:unset;cursor:pointer;font:600 12px/1 system-ui","color:#fff;padding:6px 9px;border-radius:5px"].join(";");let K=this._canvas.mode[J]??Q.default;for(let H of Q.values){let q=document.createElement("option");if(q.value=H,q.textContent=H,q.style.color="#000",H===K)q.selected=!0;$.appendChild(q)}return $.addEventListener("change",()=>this._canvas.setMode(J,$.value)),$}_download(){let J=this._bytes??oJ({xml:this._markup,assets:{}}),Q=(this.getAttribute("src")?.split("/").pop()||"design.gui").replace(/\.guix$/,".gui"),$=URL.createObjectURL(new Blob([J],{type:"application/octet-stream"})),K=document.createElement("a");K.href=$,K.download=Q.endsWith(".gui")?Q:Q+".gui",K.click(),setTimeout(()=>URL.revokeObjectURL($),1000)}}function WJ(){if(typeof customElements<"u"&&!customElements.get(sJ))customElements.define(sJ,HJ)}var iJ=!1;function PJ(){if(iJ||typeof window>"u")return;iJ=!0,WJ()}function yQ(){let J=document.currentScript;if(!J?.src)return null;let Q=new URL(J.src);if(!/\.m?js$/.test(Q.pathname)){let $=Q.pathname.replace(/\/$/,""),K=($.split("/").pop()??"").includes("@");Q.pathname=`${$}${K?"":"@0.4.0"}/dist/gui-embed.js`}return new URL("./render-worker.js",Q).href}t.workerUrl=yQ();PJ();globalThis.GuiEmbed=RJ;})();
|
|
10
|
+
`,jQ=globalThis.HTMLElement??class{};class $J extends jQ{#W=KQ++;#E=null;#L=!1;#Q=null;#H=null;#V=new Map;#$=null;#P=null;#D=!1;#C=!1;#j=null;#Z={};#R=!1;#q=null;#X=null;#B=null;#M={};#J;#I;#O;#z;constructor(){super();let J=this.attachShadow({mode:"open"});J.innerHTML=`<style>${WQ}</style><canvas aria-hidden="true"></canvas><div class="text"></div><div class="box hover" hidden></div><div class="box selected" hidden></div>`,this.#J=J.querySelector("canvas"),this.#I=J.querySelector(".text"),new ResizeObserver(()=>this.#g()).observe(this.#J),this.#O=J.querySelector(".hover"),this.#z=J.querySelector(".selected"),this.#J.addEventListener("pointermove",(Q)=>{if(!this.selectable)return;let $=this.nodeAt(...this.#_(Q));if($===this.#P)return;this.#P=$,this.#Y(this.#O,$!==this.#$?$:null)}),this.#J.addEventListener("pointerleave",()=>{this.#P=null,this.#Y(this.#O,null)}),this.#J.addEventListener("click",(Q)=>{if(!this.selectable)return;this.select(this.nodeAt(...this.#_(Q)))})}static get observedAttributes(){return["density"]}attributeChangedCallback(J,Q,$){if(J==="density"&&Q!==$&&this.#Q)this.#F()}get selectable(){return this.hasAttribute("selectable")}async connectedCallback(){this.#y(),await this.#N();let J=this.getAttribute("src"),Q=this.querySelector('script[type="application/gui"]');try{if(J)await this.load(J);else if(Q)await this.#G(Q.textContent)}catch($){this.#K("error",{message:String($.message??$)})}}#N(){return this.#E??=(()=>{let J=this.#J.transferControlToOffscreen?.();return this.#L=Boolean(J),n("open",{key:this.#W,canvas:J,fontList:this.#U},J?[J]:[])})(),this.#E}get#U(){return FJ(this.getAttribute("font-list"))}async load(J){this.#j=performance.now(),this.#Z={};let Q=async(K,q)=>{let H=performance.now();try{return await q()}finally{this.#Z[K]=(this.#Z[K]??0)+performance.now()-H}};await Q("open",async()=>{await this.#N(),await n("open",{key:this.#W,fontList:this.#U})});let $=await Q("download",async()=>{let K=await fetch(J);if(!K.ok)throw Error(`${J}: ${K.status}`);return K.arrayBuffer()});await this.#A($,Q)}async loadBytes(J){this.#j=performance.now(),this.#Z={},await this.#N(),await n("open",{key:this.#W,fontList:this.#U});let Q=J instanceof ArrayBuffer?J.slice(0):J.buffer.slice(J.byteOffset,J.byteOffset+J.byteLength);await this.#A(Q,($,K)=>K())}async#A(J,Q){let $=new Uint8Array(J,0,Math.min(2,J.byteLength));if(!($[0]===80&&$[1]===75)){this.#q=null,this.#X=null,this.#K("pages",{pages:[],page:null}),await this.#G(new TextDecoder().decode(J));return}this.#X=null,this.#B=null,this.#q=await Q("unpack",()=>n("loadPackage",{key:this.#W,bytes:J},[J]));let q=this.pages[0];if(!q){this.#K("error",{message:"the package has no page to show"});return}await this.#w(q.name)}async loadMarkup(J){await this.#N(),await n("open",{key:this.#W,fontList:this.#U}),this.#q=null,this.#X=null,this.#B=null,this.#K("pages",{pages:[],page:null}),await this.#G(J)}get pages(){if(!this.#q)return[];let J=this.#q.documents.map(({name:$})=>({name:$,library:!1})),Q=this.#q.library;if(Q?.hasPage)J.push({name:Q.name,library:!0});return J}get page(){return this.#X}set page(J){this.#w(J)}#T(J){let{documents:Q,library:$}=this.#q??{};return Q?.find((K)=>K.name===J)??($?.name===J?$:null)}get#S(){return Boolean(this.#q?.library&&this.#q.library.name===this.#B)}async#w(J){let Q=this.#T(J);if(!Q)throw Error(`no page ${J}`);let $=this.#T(this.#B);if($&&this.#Q)$.xml=this.source;if(this.#X=J,this.#$=null,this.#K("pages",{pages:this.pages,page:J}),Q.xml==null){this.#K("error",{message:`${J}: ${Q.error??"unreadable"}`});return}await this.#G(Q.xml)}get source(){return this.#Q?new XMLSerializer().serializeToString(this.#Q):""}set source(J){this.#G(J)}async#G(J){this.#j??=performance.now();let Q=performance.now(),$=await n("normalize",{xml:J});this.#Z.normalize=performance.now()-Q;let K=new DOMParser().parseFromString($,"application/xml"),q=K.querySelector("parsererror");if(q||K.documentElement.localName!=="gui"){this.#K("error",{message:q?.textContent??"the root element is not <gui>"});return}if(this.#Q=K,this.#B=this.#X,this.#x(),this.#$&&!this.#V.has(this.#$))this.#$=null;await this.#F()}get modes(){let J={},Q=(K)=>{for(let q of K?.getElementsByTagName("mode")??[]){let H=q.getAttribute("name"),W=(q.getAttribute("values")??"").split(/\s+/).filter(Boolean);if(!H||W.length===0)continue;let j=q.getAttribute("default");J[H]={values:W,default:W.includes(j)?j:W[0]}}},$=this.#q?.library;if($?.xml&&!this.#S)Q(new DOMParser().parseFromString($.xml,"application/xml"));return Q(this.#Q),J}get mode(){return{...this.#M}}set mode(J){if(this.#M={...J},this.#Q)this.#F()}setMode(J,Q){let $={...this.#M};if(Q==null)delete $[J];else $[J]=Q;this.mode=$}get document(){return this.#Q}element(J){return this.#V.get(J)??null}idOf(J){for(let[Q,$]of this.#V)if($===J)return Q;return null}get selected(){return this.#$}select(J){this.#$=J&&this.#V.has(J)?J:null,this.#Y(this.#z,this.#$),this.#Y(this.#O,null),this.#K("select",{id:this.#$,element:this.element(this.#$)})}nodeAt(J,Q){let $=(K)=>{let{x:q,y:H,width:W,height:j}=K.rect;if(K.attributes.visible==="false")return null;for(let V=K.children.length-1;V>=0;V--){let Z=$(K.children[V]);if(Z)return Z}return J>=q&&Q>=H&&J<q+W&&Q<H+j?K.attributes["data-uid"]??null:null};return this.#H?$(this.#H):null}bounds(J){let Q=($)=>{if($.attributes["data-uid"]===J)return $.rect;for(let K of $.children){let q=Q(K);if(q)return q}return null};return this.#H&&J?Q(this.#H):null}apply(J){this.#j??=performance.now();for(let Q of J){let $=this.element(Q.node);if(!$)throw Error(`no element ${Q.node}`);if(Q.op==="set")if(Q.value==null)$.removeAttribute(Q.attr);else $.setAttribute(Q.attr,Q.value);else if(Q.op==="text")if($.hasAttribute("value")||!$.textContent.trim())$.setAttribute("value",Q.value);else $.textContent=Q.value;else if(Q.op==="remove")$.remove(),this.#x();else throw Error(`unknown op ${Q.op}`)}this.#F()}#x(){this.#V.clear(),TJ(this.#Q,(J,Q)=>this.#V.set(Q,J))}#v(){let J=this.#Q.cloneNode(!0);return TJ(J,(Q,$)=>Q.setAttribute("data-uid",$)),new XMLSerializer().serializeToString(J)}async#F(){if(this.#D){this.#C=!0;return}this.#D=!0;try{do{this.#C=!1;let J=this.density,Q=this.#v(),$=FJ(this.getAttribute("asset-proxy")),K=performance.now(),q=this.#S,H=await n("render",{key:this.#W,xml:Q,library:q,density:J,proxy:$,fontFile:FJ(this.getAttribute("font-file")),modes:this.#M});if(this.#C)continue;if(this.#H=H.layout,!this.#L){this.#J.width=H.width,this.#J.height=H.height;let Z=new ImageData(new Uint8ClampedArray(H.pixels),H.width,H.height);this.#J.getContext("2d").putImageData(Z,0,0)}let{width:W,height:j}=H.layout.rect;this.#J.style.width=`${W}px`,this.#J.style.aspectRatio=`${W} / ${j}`,this.#Y(this.#z,this.#$),this.#u(H.layout);let F=this.#j==null?null:performance.now()-this.#j,V={...this.#Z,fonts:H.fontsMs,render:H.engineMs,draw:H.drawMs??0,transport:performance.now()-K-H.fontsMs-H.engineMs-(H.drawMs??0)};if(this.#j=null,this.#Z={},this.#K("render",{ms:H.engineMs+(H.drawMs??0),wallMs:F,timings:V,complete:H.missingImages===0,engineMs:H.engineMs,offscreen:this.#L,density:H.density??J,width:W,height:j,pixels:[H.width,H.height],warnings:H.warnings,repainted:H.repainted??null}),H.missingImages>0)this.#k(Q,q,$)}while(this.#C)}catch(J){this.#K("error",{message:String(J.message??J)})}finally{this.#D=!1}}async#k(J,Q,$){if(this.#R)return;this.#R=!0;try{if(await n("supplyImages",{key:this.#W,xml:J,library:Q,proxy:$})>0)this.#F()}catch(K){this.#K("error",{message:String(K.message??K)})}finally{this.#R=!1}}get density(){let J=Number(this.getAttribute("density"));if(J>0)return Math.min(J,4);return Math.min(Math.max(2,Math.ceil(window.devicePixelRatio||1)),3)}#y(){matchMedia(`(resolution: ${window.devicePixelRatio}dppx)`).addEventListener("change",()=>{if(this.#Q)this.#F();this.#y()},{once:!0})}#_(J){let Q=this.#J.getBoundingClientRect(),$=(this.#H?.rect.width??Q.width)/Q.width;return[(J.clientX-Q.left)*$,(J.clientY-Q.top)*$]}#u(J){let Q=this.#I;Q.replaceChildren();let{width:$,height:K}=J.rect;Object.assign(Q.style,{width:`${$}px`,height:`${K}px`});let q=(H,W,j)=>{if(H.attributes.visible==="false")return;let F=HQ(H);if(F){let{x:V,y:Z,width:X,height:C}=H.rect;Object.assign(F.style,{left:`${V-j.x}px`,top:`${Z-j.y}px`,width:`${X}px`,height:`${C}px`}),W.append(F);for(let M of H.children)q(M,F,H.rect)}else for(let V of H.children)q(V,W,j)};q(J,Q,{x:0,y:0}),this.#g()}#g(){let J=this.#H?.rect.width;if(!J)return;let Q=this.#J.getBoundingClientRect().width;this.#I.style.transform=Q?`scale(${Q/J})`:""}#Y(J,Q){let $=this.bounds(Q);if(J.hidden=!$,!$)return;let K=this.#J.getBoundingClientRect().width/this.#H.rect.width||1;Object.assign(J.style,{left:`${$.x*K}px`,top:`${$.y*K}px`,width:`${$.width*K}px`,height:`${$.height*K}px`})}#K(J,Q){this.dispatchEvent(new CustomEvent(J,{detail:Q}))}}if(typeof customElements<"u"&&!customElements.get("gui-canvas"))customElements.define("gui-canvas",$J);var I=Uint8Array,w=Uint16Array,NJ=Int32Array,UJ=new I([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0]),LJ=new I([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,0,0]),wJ=new I([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),kJ=function(J,Q){var $=new w(31);for(var K=0;K<31;++K)$[K]=Q+=1<<J[K-1];var q=new NJ($[30]);for(var K=1;K<30;++K)for(var H=$[K];H<$[K+1];++H)q[H]=H-$[K]<<5|K;return{b:$,r:q}},uJ=kJ(UJ,2),ZQ=uJ.b,YJ=uJ.r;ZQ[28]=258,YJ[258]=28;var hJ=kJ(LJ,0),bQ=hJ.b,xJ=hJ.r,CJ=new w(32768);for(B=0;B<32768;++B)b=(B&43690)>>1|(B&21845)<<1,b=(b&52428)>>2|(b&13107)<<2,b=(b&61680)>>4|(b&3855)<<4,CJ[B]=((b&65280)>>8|(b&255)<<8)>>1;var b,B,QJ=function(J,Q,$){var K=J.length,q=0,H=new w(Q);for(;q<K;++q)if(J[q])++H[J[q]-1];var W=new w(Q);for(q=1;q<Q;++q)W[q]=W[q-1]+H[q-1]<<1;var j;if($){j=new w(1<<Q);var F=15-Q;for(q=0;q<K;++q)if(J[q]){var V=q<<4|J[q],Z=Q-J[q],X=W[J[q]-1]++<<Z;for(var C=X|(1<<Z)-1;X<=C;++X)j[CJ[X]>>F]=V}}else{j=new w(K);for(q=0;q<K;++q)if(J[q])j[q]=CJ[W[J[q]-1]++]>>15-J[q]}return j},d=new I(288);for(B=0;B<144;++B)d[B]=8;var B;for(B=144;B<256;++B)d[B]=9;var B;for(B=256;B<280;++B)d[B]=7;var B;for(B=280;B<288;++B)d[B]=8;var B,KJ=new I(32);for(B=0;B<32;++B)KJ[B]=5;var B,VQ=QJ(d,9,0);var XQ=QJ(KJ,5,0);var fJ=function(J){return(J+7)/8|0},bJ=function(J,Q,$){if(Q==null||Q<0)Q=0;if($==null||$>J.length)$=J.length;return new I(J.subarray(Q,$))};var FQ=["unexpected EOF","invalid block type","invalid length/literal","invalid distance","stream finished","no stream handler",,"no callback","invalid UTF-8 data","extra field too long","date not in range 1980-2099","filename too long","stream finishing","invalid zip data"],qJ=function(J,Q,$){var K=Error(Q||FQ[J]);if(K.code=J,Error.captureStackTrace)Error.captureStackTrace(K,qJ);if(!$)throw K;return K};var m=function(J,Q,$){$<<=Q&7;var K=Q/8|0;J[K]|=$,J[K+1]|=$>>8},e=function(J,Q,$){$<<=Q&7;var K=Q/8|0;J[K]|=$,J[K+1]|=$>>8,J[K+2]|=$>>16},GJ=function(J,Q){var $=[];for(var K=0;K<J.length;++K)if(J[K])$.push({s:K,f:J[K]});var q=$.length,H=$.slice();if(!q)return{t:pJ,l:0};if(q==1){var W=new I($[0].s+1);return W[$[0].s]=1,{t:W,l:1}}$.sort(function(E,A){return E.f-A.f}),$.push({s:-1,f:25001});var j=$[0],F=$[1],V=0,Z=1,X=2;$[0]={s:-1,f:j.f+F.f,l:j,r:F};while(Z!=q-1)j=$[$[V].f<$[X].f?V++:X++],F=$[V!=Z&&$[V].f<$[X].f?V++:X++],$[Z++]={s:-1,f:j.f+F.f,l:j,r:F};var C=H[0].s;for(var K=1;K<q;++K)if(H[K].s>C)C=H[K].s;var M=new w(C+1),N=MJ($[Z-1],M,0);if(N>Q){var K=0,O=0,z=N-Q,v=1<<z;H.sort(function(A,U){return M[U.s]-M[A.s]||A.f-U.f});for(;K<q;++K){var x=H[K].s;if(M[x]>Q)O+=v-(1<<N-M[x]),M[x]=Q;else break}O>>=z;while(O>0){var k=H[K].s;if(M[k]<Q)O-=1<<Q-M[k]++-1;else++K}for(;K>=0&&O;--K){var L=H[K].s;if(M[L]==Q)--M[L],++O}N=Q}return{t:new I(M),l:N}},MJ=function(J,Q,$){return J.s==-1?Math.max(MJ(J.l,Q,$+1),MJ(J.r,Q,$+1)):Q[J.s]=$},yJ=function(J){var Q=J.length;while(Q&&!J[--Q]);var $=new w(++Q),K=0,q=J[0],H=1,W=function(F){$[K++]=F};for(var j=1;j<=Q;++j)if(J[j]==q&&j!=Q)++H;else{if(!q&&H>2){for(;H>138;H-=138)W(32754);if(H>2)W(H>10?H-11<<5|28690:H-3<<5|12305),H=0}else if(H>3){W(q),--H;for(;H>6;H-=6)W(8304);if(H>2)W(H-3<<5|8208),H=0}while(H--)W(q);H=1,q=J[j]}return{c:$.subarray(0,K),n:Q}},JJ=function(J,Q){var $=0;for(var K=0;K<Q.length;++K)$+=J[K]*Q[K];return $},mJ=function(J,Q,$){var K=$.length,q=fJ(Q+2);J[q]=K&255,J[q+1]=K>>8,J[q+2]=J[q]^255,J[q+3]=J[q+1]^255;for(var H=0;H<K;++H)J[q+H+4]=$[H];return(q+4+K)*8},_J=function(J,Q,$,K,q,H,W,j,F,V,Z){m(Q,Z++,$),++q[256];var X=GJ(q,15),C=X.t,M=X.l,N=GJ(H,15),O=N.t,z=N.l,v=yJ(C),x=v.c,k=v.n,L=yJ(O),E=L.c,A=L.n,U=new w(19);for(var Y=0;Y<x.length;++Y)++U[x[Y]&31];for(var Y=0;Y<E.length;++Y)++U[E[Y]&31];var G=GJ(U,7),T=G.t,r=G.l,S=19;for(;S>4&&!T[wJ[S-1]];--S);var o=V+5<<3,y=JJ(q,d)+JJ(H,KJ)+W,_=JJ(q,C)+JJ(H,O)+W+14+3*S+JJ(U,T)+2*U[16]+3*U[17]+7*U[18];if(F>=0&&o<=y&&o<=_)return mJ(Q,Z,J.subarray(F,F+V));var u,P,g,p;if(m(Q,Z,1+(_<y)),Z+=2,_<y){u=QJ(C,M,0),P=C,g=QJ(O,z,0),p=O;var jJ=QJ(T,r,0);m(Q,Z,k-257),m(Q,Z+5,A-1),m(Q,Z+10,S-4),Z+=14;for(var Y=0;Y<S;++Y)m(Q,Z+3*Y,T[wJ[Y]]);Z+=3*S;var h=[x,E];for(var l=0;l<2;++l){var s=h[l];for(var Y=0;Y<s.length;++Y){var f=s[Y]&31;if(m(Q,Z,jJ[f]),Z+=T[f],f>15)m(Q,Z,s[Y]>>5&127),Z+=s[Y]>>12}}}else u=VQ,P=d,g=XQ,p=KJ;for(var Y=0;Y<j;++Y){var R=K[Y];if(R>255){var f=R>>18&31;if(e(Q,Z,u[f+257]),Z+=P[f+257],f>7)m(Q,Z,R>>23&31),Z+=UJ[f];var i=R&31;if(e(Q,Z,g[i]),Z+=p[i],i>3)e(Q,Z,R>>5&8191),Z+=LJ[i]}else e(Q,Z,u[R]),Z+=P[R]}return e(Q,Z,u[256]),Z+P[256]},BQ=new NJ([65540,131080,131088,131104,262176,1048704,1048832,2114560,2117632]),pJ=new I(0),GQ=function(J,Q,$,K,q,H){var W=H.z||J.length,j=new I(K+W+5*(1+Math.ceil(W/7000))+q),F=j.subarray(K,j.length-q),V=H.l,Z=(H.r||0)&7;if(Q){if(Z)F[0]=H.r>>3;var X=BQ[Q-1],C=X>>13,M=X&8191,N=(1<<$)-1,O=H.p||new w(32768),z=H.h||new w(N+1),v=Math.ceil($/3),x=2*v,k=function(XJ){return(J[XJ]^J[XJ+1]<<v^J[XJ+2]<<x)&N},L=new NJ(25000),E=new w(288),A=new w(32),U=0,Y=0,G=H.i||0,T=0,r=H.w||0,S=0;for(;G+2<W;++G){var o=k(G),y=G&32767,_=z[o];if(O[y]=_,z[o]=y,r<=G){var u=W-G;if((U>7000||T>24576)&&(u>423||!V)){Z=_J(J,F,0,L,E,A,Y,T,S,G-S,Z),T=U=Y=0,S=G;for(var P=0;P<286;++P)E[P]=0;for(var P=0;P<30;++P)A[P]=0}var g=2,p=0,jJ=M,h=y-_&32767;if(u>2&&o==k(G-h)){var l=Math.min(C,u)-1,s=Math.min(32767,G),f=Math.min(258,u);while(h<=s&&--jJ&&y!=_){if(J[G+g]==J[G+g-h]){var R=0;for(;R<f&&J[G+R]==J[G+R-h];++R);if(R>g){if(g=R,p=h,R>l)break;var i=Math.min(h,R-2),IJ=0;for(var P=0;P<i;++P){var ZJ=G-h+P&32767,tJ=O[ZJ],zJ=ZJ-tJ&32767;if(zJ>IJ)IJ=zJ,_=ZJ}}}y=_,_=O[y],h+=y-_&32767}}if(p){L[T++]=268435456|YJ[g]<<18|xJ[p];var EJ=YJ[g]&31,AJ=xJ[p]&31;Y+=UJ[EJ]+LJ[AJ],++E[257+EJ],++A[AJ],r=G+g,++U}else L[T++]=J[G],++E[J[G]]}}for(G=Math.max(G,r);G<W;++G)L[T++]=J[G],++E[J[G]];if(Z=_J(J,F,V,L,E,A,Y,T,S,G-S,Z),!V)H.r=Z&7|F[Z/8|0]<<3,Z-=7,H.h=z,H.p=O,H.i=G,H.w=r}else{for(var G=H.w||0;G<W+V;G+=65535){var VJ=G+65535;if(VJ>=W)F[Z/8|0]=V,VJ=W;Z=mJ(F,Z+1,J.subarray(G,VJ))}H.i=W}return bJ(j,0,K+fJ(Z)+q)},YQ=function(){var J=new Int32Array(256);for(var Q=0;Q<256;++Q){var $=Q,K=9;while(--K)$=($&1&&-306674912)^$>>>1;J[Q]=$}return J}(),CQ=function(){var J=-1;return{p:function(Q){var $=J;for(var K=0;K<Q.length;++K)$=YQ[$&255^Q[K]]^$>>>8;J=$},d:function(){return~J}}};var MQ=function(J,Q,$,K,q){if(!q){if(q={l:1},Q.dictionary){var H=Q.dictionary.subarray(-32768),W=new I(H.length+J.length);W.set(H),W.set(J,H.length),J=W,q.w=H.length}}return GQ(J,Q.level==null?6:Q.level,Q.mem==null?q.l?Math.ceil(Math.max(8,Math.min(13,Math.log(J.length)))*1.5):20:12+Q.mem,$,K,q)},nJ=function(J,Q){var $={};for(var K in J)$[K]=J[K];for(var K in Q)$[K]=Q[K];return $};var D=function(J,Q,$){for(;$;++Q)J[Q]=$,$>>>=8};function OQ(J,Q){return MQ(J,Q||{},0,0)}var cJ=function(J,Q,$,K){for(var q in J){var H=J[q],W=Q+q,j=K;if(Array.isArray(H))j=nJ(K,H[1]),H=H[0];if(ArrayBuffer.isView(H))$[W]=[H,j];else $[W+="/"]=[new I(0),j],cJ(H,W,$,K)}},gJ=typeof TextEncoder<"u"&&new TextEncoder,NQ=typeof TextDecoder<"u"&&new TextDecoder,UQ=0;try{NQ.decode(pJ,{stream:!0}),UQ=1}catch(J){}function c(J,Q){if(Q){var $=new I(J.length);for(var K=0;K<J.length;++K)$[K]=J.charCodeAt(K);return $}if(gJ)return gJ.encode(J);var q=J.length,H=new I(J.length+(J.length>>1)),W=0,j=function(Z){H[W++]=Z};for(var K=0;K<q;++K){if(W+5>H.length){var F=new I(W+8+(q-K<<1));F.set(H),H=F}var V=J.charCodeAt(K);if(V<128||Q)j(V);else if(V<2048)j(192|V>>6),j(128|V&63);else if(V>55295&&V<57344)V=65536+(V&1047552)|J.charCodeAt(++K)&1023,j(240|V>>18),j(128|V>>12&63),j(128|V>>6&63),j(128|V&63);else j(224|V>>12),j(128|V>>6&63),j(128|V&63)}return bJ(H,0,W)}var OJ=function(J){var Q=0;if(J)for(var $ in J){var K=J[$].length;if(K>65535)qJ(9);Q+=K+4}return Q},vJ=function(J,Q,$,K,q,H,W,j){var F=K.length,V=$.extra,Z=j&&j.length,X=OJ(V);if(D(J,Q,W!=null?33639248:67324752),Q+=4,W!=null)J[Q++]=20,J[Q++]=$.os;J[Q]=20,Q+=2,J[Q++]=$.flag<<1|(H<0&&8),J[Q++]=q&&8,J[Q++]=$.compression&255,J[Q++]=$.compression>>8;var C=new Date($.mtime==null?Date.now():$.mtime),M=C.getFullYear()-1980;if(M<0||M>119)qJ(10);if(D(J,Q,M<<25|C.getMonth()+1<<21|C.getDate()<<16|C.getHours()<<11|C.getMinutes()<<5|C.getSeconds()>>1),Q+=4,H!=-1)D(J,Q,$.crc),D(J,Q+4,H<0?-H-2:H),D(J,Q+8,$.size);if(D(J,Q+12,F),D(J,Q+14,X),Q+=16,W!=null)D(J,Q,Z),D(J,Q+6,$.attrs),D(J,Q+10,W),Q+=14;if(J.set(K,Q),Q+=F,X)for(var N in V){var O=V[N],z=O.length;D(J,Q,+N),D(J,Q+2,z),J.set(O,Q+4),Q+=4+z}if(Z)J.set(j,Q),Q+=Z;return Q},LQ=function(J,Q,$,K,q){D(J,Q,101010256),D(J,Q+8,$),D(J,Q+10,$),D(J,Q+12,K),D(J,Q+16,q)};function dJ(J,Q){if(!Q)Q={};var $={},K=[];cJ(J,"",$,Q);var q=0,H=0;for(var W in $){var j=$[W],F=j[0],V=j[1],Z=V.level==0?0:8,X=c(W),C=X.length,M=V.comment,N=M&&c(M),O=N&&N.length,z=OJ(V.extra);if(C>65535)qJ(11);var v=Z?OQ(F,V):F,x=v.length,k=CQ();k.p(F),K.push(nJ(V,{size:F.length,crc:k.d(),c:v,f:X,m:N,u:C!=W.length||N&&M.length!=O,o:q,compression:Z})),q+=30+C+z+x,H+=76+2*(C+z)+(O||0)+x}var L=new I(H+22),E=q,A=H-q;for(var U=0;U<K.length;++U){var X=K[U];vJ(L,X.o,X,X.f,X.u,X.c.length);var Y=30+X.f.length+OJ(X.extra);L.set(X.c,X.o+Y),vJ(L,q,X,X.f,X.u,X.c.length,X.o,X.m),q+=16+Y+(X.m?X.m.length:0)}return LQ(L,q,K.length,A,E),L}var PQ=new Set(["frame","stack","row","col","grid","group"]);var DQ=new Set(["text","img","svg","shape","instance"]),RQ=new Set([...PQ,...DQ]),IQ=new Set(["preview","tokens","styles","fonts","assets","meta","components"]),pQ=new Set([...RQ,...IQ,"gui","color","number","string","text-style","fill-style","effect-style","font","image","appearance","fill","effect","segment","path","component","component-set","variant","props","prop","slot"]);var PJ="library.guix";var TQ="design.guix",SQ="preview.webp",rJ="assets/";function wQ(J){return J.startsWith(rJ)?J:rJ+J}function xQ(J){let Q={};if(J.documents&&J.primary){for(let[K,q]of Object.entries(J.documents))Q[K]=c(q);Q[J.primary]=c(J.xml)}else Q[TQ]=c(J.xml);if(J.library!==void 0)Q[PJ]=c(J.library);for(let[K,q]of Object.entries(J.libraryFiles||{}))Q[K]=c(q);if(J.preview)Q[SQ]=J.preview;for(let[K,q]of Object.entries(J.assets))Q[wQ(K)]=q;let $={};for(let K of Object.keys(Q).sort())$[K.normalize("NFC")]=Q[K];return $}function oJ(J){return dJ(xQ(J))}var yQ=/uses token '(\$?[^']+)', which is not declared/,_Q=/uses text style '([^']+)', which is not declared/;function iJ(J,Q=8){let $=new Set,K=[],q=[],H=[];for(let F of J.split("; ")){let V=F.trim();if(!V||$.has(V))continue;$.add(V);let Z=yQ.exec(V);if(Z){let C=Z[1].startsWith("$")?Z[1]:`$${Z[1]}`;if(!K.includes(C))K.push(C);continue}let X=_Q.exec(V);if(X){if(!q.includes(X[1]))q.push(X[1]);continue}H.push(V)}let W=[];if(K.length)W.push(sJ(K.length===1?"Undeclared token":`${K.length} undeclared tokens`,K));if(q.length)W.push(sJ(q.length===1?"Undeclared text style":`${q.length} undeclared text styles`,q));W.push(...H);let j=Math.max(1,Q);if(W.length<=j)return{lines:W,more:0};return{lines:W.slice(0,j),more:W.length-j}}function sJ(J,Q){let $=Q.slice(0,12).join(", "),K=Q.length-12;return`${J}: ${$}${K>0?`, and ${K} more`:""}`}var lJ="gui-embed",gQ=0.25,vQ=8;class HJ extends HTMLElement{_stage;_view;_canvas;_bar;_ro=null;_bytes=null;_markup="";_size=null;_scale=1;_x=0;_y=0;_userZoomed=!1;_settle=null;_controlsPage=null;static get observedAttributes(){return["src","page"]}connectedCallback(){if(!this._stage)this._build();this._load()}disconnectedCallback(){this._ro?.disconnect(),this._ro=null}attributeChangedCallback(J){if(!this._stage)return;if(J==="src")this._load();else if(J==="page")this._showPage(this.getAttribute("page"))}get canvas(){return this._canvas}get pages(){return this._canvas?.pages??[]}get page(){return this._canvas?.page??null}set page(J){if(J==null)this.removeAttribute("page");else this.setAttribute("page",J)}_showPage(J){if(!J||J===this._canvas.page)return;if(!this._canvas.pages.some((Q)=>Q.name===J))return;this._userZoomed=!1,this._canvas.page=J}_build(){let J=getComputedStyle(this);if(J.position==="static")this.style.position="relative";if(J.display==="inline")this.style.display="block";this.style.overflow="hidden";let Q=document.createElement("div");Q.className="gui-embed-canvas";let $=this.getAttribute("grid")!=="false";Q.style.cssText=["position:absolute;inset:0;touch-action:none","background-color:var(--gui-embed-bg, #fafaf8)",$?"background-image:radial-gradient(var(--gui-embed-dot, rgba(0,0,0,.14)) 1px, transparent 1.4px);background-size:var(--gui-embed-dot-gap, 18px) var(--gui-embed-dot-gap, 18px);background-position:center":""].filter(Boolean).join(";"),this.appendChild(Q),this._stage=Q;let K=document.createElement("div");K.style.cssText="position:absolute;left:0;top:0;width:max-content;transform-origin:0 0",Q.appendChild(K),this._view=K;let q=document.createElement("gui-canvas");q.addEventListener("render",(W)=>this._rendered(W.detail)),q.addEventListener("error",(W)=>this._fail(W.detail.message)),K.appendChild(q),this._canvas=q,this._bindZoom(),this._ro=new ResizeObserver(()=>{if(!this._userZoomed)this.fit()}),this._ro.observe(this);let H=document.createElement("div");H.className="gui-embed-controls",H.style.cssText=["position:absolute;top:8px;right:8px;z-index:2","display:flex;gap:4px;padding:4px","border-radius:8px;background:rgba(20,20,20,.55)","backdrop-filter:blur(8px);-webkit-backdrop-filter:blur(8px)","opacity:0;transition:opacity .15s ease"].join(";"),this.appendChild(H),this._bar=H,this.addEventListener("pointerenter",()=>H.style.opacity="1"),this.addEventListener("pointerleave",()=>H.style.opacity="0")}async _load(){this._size=null,this._userZoomed=!1,this._canvas.mode={};try{let J=this.getAttribute("src");if(J){let Q=await fetch(J);if(!Q.ok)throw Error(`gui-embed: failed to fetch "${J}" (${Q.status})`);this._bytes=new Uint8Array(await Q.arrayBuffer()),this._markup="",await this._canvas.loadBytes(this._bytes),this._showPage(this.getAttribute("page"))}else{let Q=this.querySelector(':scope > script[type="application/gui"]');if(!Q){if(document.readyState==="loading")document.addEventListener("DOMContentLoaded",()=>void this._load(),{once:!0});return}this._bytes=null,this._markup=Q.textContent??"",await this._canvas.loadMarkup(this._markup)}this._buildControls()}catch(J){this._fail(String(J?.message??J))}}_fail(J){let Q=this.querySelector(":scope > .gui-embed-error");if(!Q)Q=document.createElement("div"),Q.className="gui-embed-error",Q.setAttribute("role","alert"),Q.style.cssText=["position:absolute;inset:0;z-index:1;overflow:auto;box-sizing:border-box","display:flex;padding:16px","background:var(--gui-embed-bg, #fafaf8)","font:13px/1.45 system-ui,sans-serif;color:#333"].join(";"),this.appendChild(Q);let{lines:$,more:K}=iJ(J),q=document.createElement("div");q.className="gui-embed-error-body",q.style.cssText="margin:auto;max-width:56ch;text-align:left";let H=document.createElement("div");H.className="gui-embed-error-title",H.style.cssText="font-weight:600;color:#c00;margin-bottom:6px",H.textContent="This design can't be drawn",q.appendChild(H);let W=document.createElement("ul");W.className="gui-embed-error-list",W.style.cssText="margin:0;padding-left:18px;overflow-wrap:anywhere";for(let j of $){let F=document.createElement("li");F.textContent=j,W.appendChild(F)}if(K){let j=document.createElement("li");j.className="gui-embed-error-more",j.style.cssText="list-style:none;margin-left:-18px;color:#777",j.textContent=`and ${K} more`,W.appendChild(j)}q.appendChild(W),Q.replaceChildren(q)}_rendered(J){if(this.querySelector(":scope > .gui-embed-error")?.remove(),this._canvas.page!==this._controlsPage)this._buildControls();let Q=!this._size||this._size.width!==J.width||this._size.height!==J.height;if(this._size={width:J.width,height:J.height},!Q)return;if(!this._hasHeight())if(this.style.width)this.style.aspectRatio=`${J.width} / ${J.height}`;else this.style.width=`${J.width}px`,this.style.height=`${J.height}px`;if(!this._userZoomed)this.fit()}_hasHeight(){if(this.style.height||this.style.aspectRatio)return!0;let J=getComputedStyle(this);if(J.aspectRatio&&J.aspectRatio!=="auto")return!0;return this.clientHeight>1}fit(){if(!this._size)return;let{width:J,height:Q}=this._size,$=this._stage.getBoundingClientRect();if($.width<1||$.height<1)return;this._scale=Math.min($.width/J,$.height/Q),this._x=($.width-J*this._scale)/2,this._y=($.height-Q*this._scale)/2,this._userZoomed=!1,this._apply()}zoomBy(J,Q,$){if(!this._size)return;let K=this._stage.getBoundingClientRect(),q=Math.min(K.width/this._size.width,K.height/this._size.height),H=Math.min(Math.max(this._scale*J,q*gQ),q*vQ),W=Q??K.width/2,j=$??K.height/2;this._x=W-(W-this._x)*H/this._scale,this._y=j-(j-this._y)*H/this._scale,this._scale=H,this._userZoomed=!0,this._apply()}_apply(){if(this._view.style.transform=`translate(${this._x}px, ${this._y}px) scale(${this._scale})`,this._settle)clearTimeout(this._settle);this._settle=setTimeout(()=>{let J=Math.min(Math.max(2,Math.ceil((window.devicePixelRatio||1)*this._scale)),4);if(Number(this._canvas.getAttribute("density"))!==J)this._canvas.setAttribute("density",String(J))},150)}_bindZoom(){let J=this._stage,Q=()=>this.getAttribute("zoom")!=="false";J.addEventListener("wheel",(q)=>{if(!Q()||!(q.ctrlKey||q.metaKey))return;q.preventDefault();let H=J.getBoundingClientRect();this.zoomBy(Math.exp(-q.deltaY*0.01),q.clientX-H.left,q.clientY-H.top)},{passive:!1});let $=null;J.addEventListener("pointerdown",(q)=>{if(!Q()||q.button!==0)return;$={id:q.pointerId,x:q.clientX,y:q.clientY},J.setPointerCapture(q.pointerId)}),J.addEventListener("pointermove",(q)=>{if(!$||$.id!==q.pointerId)return;this._x+=q.clientX-$.x,this._y+=q.clientY-$.y,$.x=q.clientX,$.y=q.clientY,this._userZoomed=!0,this._view.style.transform=`translate(${this._x}px, ${this._y}px) scale(${this._scale})`});let K=()=>$=null;J.addEventListener("pointerup",K),J.addEventListener("pointercancel",K),J.addEventListener("dblclick",()=>Q()&&this.fit())}_buildControls(){let J=this._bar;if(J.innerHTML="",this._controlsPage=this._canvas.page,this.getAttribute("zoom")!=="false")J.appendChild(this._btn("Fit","Reset zoom",()=>this.fit()));let Q=this._canvas.pages;if(this.hasAttribute("page-switch")&&Q.length>1)J.appendChild(this._pageSelect(Q));let $=this._canvas.modes,K=Object.keys($).filter((q)=>$[q].values.length>1);if(this.hasAttribute("mode-switch")&&K.length)for(let q of K)J.appendChild(this._modeSelect(q,$[q]));if(this.hasAttribute("copy"))J.appendChild(this._btn("Copy","Copy .gui markup",async()=>{await navigator.clipboard.writeText(this._canvas.source)}));if(this.hasAttribute("download"))J.appendChild(this._btn("Download","Download .gui file",()=>this._download()));J.style.display=J.children.length?"flex":"none"}_btn(J,Q,$){let K=document.createElement("button");return K.type="button",K.textContent=J,K.title=Q,K.style.cssText=["all:unset;cursor:pointer;font:600 12px/1 system-ui","color:#fff;padding:6px 9px;border-radius:5px"].join(";"),K.addEventListener("pointerenter",()=>K.style.background="rgba(255,255,255,.18)"),K.addEventListener("pointerleave",()=>K.style.background="transparent"),K.addEventListener("click",$),K}_select(J){let Q=document.createElement("select");return Q.title=J,Q.style.cssText=["all:unset;cursor:pointer;font:600 12px/1 system-ui","color:#fff;padding:6px 9px;border-radius:5px"].join(";"),Q}_option(J,Q,$){let K=document.createElement("option");if(K.value=J,K.textContent=Q,K.style.color="#000",$)K.selected=!0;return K}_pageSelect(J){let Q=this._select("Page");Q.className="gui-embed-pages";let $=this._canvas.page;for(let K of J){let q=K.library?"Library":K.name.replace(/\.guix$/,"");Q.appendChild(this._option(K.name,q,K.name===$))}return Q.addEventListener("change",()=>this.setAttribute("page",Q.value)),Q}_modeSelect(J,Q){let $=this._select(`Mode: ${J}`),K=this._canvas.mode[J]??Q.default;for(let q of Q.values)$.appendChild(this._option(q,q,q===K));return $.addEventListener("change",()=>this._canvas.setMode(J,$.value)),$}_download(){let J=this._bytes??oJ({xml:this._markup,assets:{}}),Q=(this.getAttribute("src")?.split("/").pop()||"design.gui").replace(/\.guix$/,".gui"),$=URL.createObjectURL(new Blob([J],{type:"application/octet-stream"})),K=document.createElement("a");K.href=$,K.download=Q.endsWith(".gui")?Q:Q+".gui",K.click(),setTimeout(()=>URL.revokeObjectURL($),1000)}}function WJ(){if(typeof customElements<"u"&&!customElements.get(lJ))customElements.define(lJ,HJ)}var aJ=!1;function DJ(){if(aJ||typeof window>"u")return;aJ=!0,WJ()}function kQ(){let J=document.currentScript;if(!J?.src)return null;let Q=new URL(J.src);if(!/\.m?js$/.test(Q.pathname)){let $=Q.pathname.replace(/\/$/,""),K=($.split("/").pop()??"").includes("@");Q.pathname=`${$}${K?"":"@0.4.1"}/dist/gui-embed.js`}return new URL("./render-worker.js",Q).href}t.workerUrl=kQ();DJ();globalThis.GuiEmbed=RJ;})();
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dotgui/embed",
|
|
3
|
-
"version": "0.4.
|
|
4
|
-
"description": "Drop-in browser player that renders .gui files anywhere
|
|
3
|
+
"version": "0.4.1",
|
|
4
|
+
"description": "Drop-in browser player that renders .gui files anywhere — one CDN script. Drawn by @dotgui/render, the Rust renderer as WebAssembly.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "./dist/gui-embed.esm.js",
|
|
@@ -24,7 +24,8 @@
|
|
|
24
24
|
"scripts": {
|
|
25
25
|
"build": "bun run build.ts",
|
|
26
26
|
"typecheck": "tsc --noEmit",
|
|
27
|
-
"prepublishOnly": "bun run build.ts"
|
|
27
|
+
"prepublishOnly": "bun run build.ts",
|
|
28
|
+
"test": "bun test"
|
|
28
29
|
},
|
|
29
30
|
"keywords": [
|
|
30
31
|
"dotgui",
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { describe, expect, test } from 'bun:test'
|
|
2
|
+
import { MAX_LINES, MAX_NAMES, summarizeError } from './error-message'
|
|
3
|
+
|
|
4
|
+
const token = (name: string, at = 'frame') => `${at}: uses token '$${name}', which is not declared`
|
|
5
|
+
const style = (name: string, at = 'text') => `${at}: uses text style '${name}', which is not declared`
|
|
6
|
+
|
|
7
|
+
describe('summarizeError', () => {
|
|
8
|
+
test('a single message passes through', () => {
|
|
9
|
+
expect(summarizeError('failed to fetch "a.gui" (404)')).toEqual({ lines: ['failed to fetch "a.gui" (404)'], more: 0 })
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
test('splits on "; " and drops repeats', () => {
|
|
13
|
+
expect(summarizeError('bad width; bad width; bad height').lines).toEqual(['bad width', 'bad height'])
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
test('folds undeclared tokens into one line, each name once', () => {
|
|
17
|
+
const message = [token('primary'), token('primary', 'card'), token('surface'), 'something else'].join('; ')
|
|
18
|
+
expect(summarizeError(message)).toEqual({
|
|
19
|
+
lines: ['2 undeclared tokens: $primary, $surface', 'something else'],
|
|
20
|
+
more: 0,
|
|
21
|
+
})
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
test('folds undeclared text styles separately', () => {
|
|
25
|
+
const message = [style('Body'), token('ink'), style('Heading')].join('; ')
|
|
26
|
+
expect(summarizeError(message).lines).toEqual(['Undeclared token: $ink', '2 undeclared text styles: Body, Heading'])
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
test('caps the names a folded line lists', () => {
|
|
30
|
+
const names = Array.from({ length: MAX_NAMES + 5 }, (_, i) => `t${i}`)
|
|
31
|
+
const [line] = summarizeError(names.map((n) => token(n)).join('; ')).lines
|
|
32
|
+
expect(line.startsWith(`${names.length} undeclared tokens: $t0, $t1`)).toBe(true)
|
|
33
|
+
expect(line.endsWith(', and 5 more')).toBe(true)
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
test('caps the lines shown and counts the rest', () => {
|
|
37
|
+
const message = Array.from({ length: 300 }, (_, i) => `problem ${i}`).join('; ')
|
|
38
|
+
const { lines, more } = summarizeError(message)
|
|
39
|
+
expect(lines).toHaveLength(MAX_LINES)
|
|
40
|
+
expect(more).toBe(300 - MAX_LINES)
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
test('hundreds of undeclared tokens make one line', () => {
|
|
44
|
+
const message = Array.from({ length: 400 }, (_, i) => token(`t${i % 40}`, `node-${i}`)).join('; ')
|
|
45
|
+
const { lines, more } = summarizeError(message)
|
|
46
|
+
expect(lines).toHaveLength(1)
|
|
47
|
+
expect(lines[0].startsWith('40 undeclared tokens:')).toBe(true)
|
|
48
|
+
expect(more).toBe(0)
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
test('uses no em or en dashes', () => {
|
|
52
|
+
const message = [token('a'), style('B'), ...Array.from({ length: 20 }, (_, i) => `x${i}`)].join('; ')
|
|
53
|
+
expect(summarizeError(message).lines.join('\n')).not.toMatch(/[–—]/)
|
|
54
|
+
})
|
|
55
|
+
})
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Turns a renderer error into something a person can read.
|
|
3
|
+
*
|
|
4
|
+
* The renderer joins every problem with "; ", so one document with many
|
|
5
|
+
* undeclared tokens comes back as hundreds of near-identical lines. This
|
|
6
|
+
* splits them, drops repeats, folds every undeclared token and text style into
|
|
7
|
+
* one line that names them, and caps what is left.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/** How many lines the note shows before "and N more". */
|
|
11
|
+
export const MAX_LINES = 8
|
|
12
|
+
/** How many names a folded line lists before "and N more". */
|
|
13
|
+
export const MAX_NAMES = 12
|
|
14
|
+
|
|
15
|
+
const UNDECLARED_TOKEN = /uses token '(\$?[^']+)', which is not declared/
|
|
16
|
+
const UNDECLARED_STYLE = /uses text style '([^']+)', which is not declared/
|
|
17
|
+
|
|
18
|
+
export interface ErrorSummary {
|
|
19
|
+
/** The lines to show, already folded and capped. */
|
|
20
|
+
lines: string[]
|
|
21
|
+
/** How many problems are left out of `lines`. */
|
|
22
|
+
more: number
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function summarizeError(message: string, maxLines = MAX_LINES): ErrorSummary {
|
|
26
|
+
const seen = new Set<string>()
|
|
27
|
+
const tokens: string[] = []
|
|
28
|
+
const styles: string[] = []
|
|
29
|
+
const rest: string[] = []
|
|
30
|
+
|
|
31
|
+
for (const raw of message.split('; ')) {
|
|
32
|
+
const line = raw.trim()
|
|
33
|
+
if (!line || seen.has(line)) continue
|
|
34
|
+
seen.add(line)
|
|
35
|
+
const token = UNDECLARED_TOKEN.exec(line)
|
|
36
|
+
if (token) {
|
|
37
|
+
const name = token[1].startsWith('$') ? token[1] : `$${token[1]}`
|
|
38
|
+
if (!tokens.includes(name)) tokens.push(name)
|
|
39
|
+
continue
|
|
40
|
+
}
|
|
41
|
+
const style = UNDECLARED_STYLE.exec(line)
|
|
42
|
+
if (style) {
|
|
43
|
+
if (!styles.includes(style[1])) styles.push(style[1])
|
|
44
|
+
continue
|
|
45
|
+
}
|
|
46
|
+
rest.push(line)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const lines: string[] = []
|
|
50
|
+
if (tokens.length) lines.push(fold(tokens.length === 1 ? 'Undeclared token' : `${tokens.length} undeclared tokens`, tokens))
|
|
51
|
+
if (styles.length) lines.push(fold(styles.length === 1 ? 'Undeclared text style' : `${styles.length} undeclared text styles`, styles))
|
|
52
|
+
lines.push(...rest)
|
|
53
|
+
|
|
54
|
+
const cap = Math.max(1, maxLines)
|
|
55
|
+
if (lines.length <= cap) return { lines, more: 0 }
|
|
56
|
+
return { lines: lines.slice(0, cap), more: lines.length - cap }
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function fold(label: string, names: string[]): string {
|
|
60
|
+
const shown = names.slice(0, MAX_NAMES).join(', ')
|
|
61
|
+
const extra = names.length - MAX_NAMES
|
|
62
|
+
return `${label}: ${shown}${extra > 0 ? `, and ${extra} more` : ''}`
|
|
63
|
+
}
|
package/src/gui-embed.ts
CHANGED
|
@@ -14,10 +14,15 @@
|
|
|
14
14
|
* WebAssembly, in a worker. This element only places it — center-center,
|
|
15
15
|
* scaled to fit — and adds the player around it. Controls are individual
|
|
16
16
|
* boolean attributes — present = on. `zoom` defaults on (it is a player);
|
|
17
|
-
* `download`, `copy`, `mode-switch` default off.
|
|
17
|
+
* `download`, `copy`, `mode-switch`, `page-switch` default off.
|
|
18
|
+
*
|
|
19
|
+
* A package may hold several documents and a library (RFC-0042). The first
|
|
20
|
+
* page shows by default; `page="name"` picks another, and `page-switch` adds
|
|
21
|
+
* a page dropdown to the controls.
|
|
18
22
|
*/
|
|
19
|
-
import type { GuiCanvas, ModeAxis, RenderDetail } from '@dotgui/render/canvas'
|
|
23
|
+
import type { GuiCanvas, GuiPage, ModeAxis, RenderDetail } from '@dotgui/render/canvas'
|
|
20
24
|
import { pack } from '@dotgui/kit/package'
|
|
25
|
+
import { summarizeError } from './error-message'
|
|
21
26
|
|
|
22
27
|
const TAG = 'gui-embed'
|
|
23
28
|
|
|
@@ -43,9 +48,11 @@ export class GuiEmbedElement extends HTMLElement {
|
|
|
43
48
|
/** True once the user pans/zooms — stops auto-fit from snapping their view back. */
|
|
44
49
|
private _userZoomed = false
|
|
45
50
|
private _settle: ReturnType<typeof setTimeout> | null = null
|
|
51
|
+
/** The page the controls were built for, to rebuild them when another page draws. */
|
|
52
|
+
private _controlsPage: string | null = null
|
|
46
53
|
|
|
47
54
|
static get observedAttributes() {
|
|
48
|
-
return ['src']
|
|
55
|
+
return ['src', 'page']
|
|
49
56
|
}
|
|
50
57
|
|
|
51
58
|
connectedCallback() {
|
|
@@ -59,7 +66,9 @@ export class GuiEmbedElement extends HTMLElement {
|
|
|
59
66
|
}
|
|
60
67
|
|
|
61
68
|
attributeChangedCallback(name: string) {
|
|
62
|
-
if (
|
|
69
|
+
if (!this._stage) return
|
|
70
|
+
if (name === 'src') void this._load()
|
|
71
|
+
else if (name === 'page') this._showPage(this.getAttribute('page'))
|
|
63
72
|
}
|
|
64
73
|
|
|
65
74
|
/** The `<gui-canvas>` drawing the file. */
|
|
@@ -67,6 +76,29 @@ export class GuiEmbedElement extends HTMLElement {
|
|
|
67
76
|
return this._canvas
|
|
68
77
|
}
|
|
69
78
|
|
|
79
|
+
/** The package's pages in order: its documents, then the library's own page. Empty for bare markup. */
|
|
80
|
+
get pages(): GuiPage[] {
|
|
81
|
+
return this._canvas?.pages ?? []
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** The page on show, or null for bare markup. Set it, or the `page` attribute, to show another. */
|
|
85
|
+
get page(): string | null {
|
|
86
|
+
return this._canvas?.page ?? null
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
set page(name: string | null) {
|
|
90
|
+
if (name == null) this.removeAttribute('page')
|
|
91
|
+
else this.setAttribute('page', name)
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** Shows a page by name. An unknown name, or none, leaves the page on show. */
|
|
95
|
+
private _showPage(name: string | null) {
|
|
96
|
+
if (!name || name === this._canvas.page) return
|
|
97
|
+
if (!this._canvas.pages.some((page) => page.name === name)) return
|
|
98
|
+
this._userZoomed = false
|
|
99
|
+
this._canvas.page = name
|
|
100
|
+
}
|
|
101
|
+
|
|
70
102
|
// ── DOM scaffold ──────────────────────────────────────────────────────────
|
|
71
103
|
|
|
72
104
|
private _build() {
|
|
@@ -142,6 +174,7 @@ export class GuiEmbedElement extends HTMLElement {
|
|
|
142
174
|
this._bytes = new Uint8Array(await response.arrayBuffer())
|
|
143
175
|
this._markup = ''
|
|
144
176
|
await this._canvas.loadBytes(this._bytes)
|
|
177
|
+
this._showPage(this.getAttribute('page'))
|
|
145
178
|
} else {
|
|
146
179
|
// Inline content lives in a <script type="application/gui"> child — raw
|
|
147
180
|
// text the HTML parser never mangles (so `<col>`/`<img>` survive).
|
|
@@ -164,21 +197,60 @@ export class GuiEmbedElement extends HTMLElement {
|
|
|
164
197
|
}
|
|
165
198
|
}
|
|
166
199
|
|
|
200
|
+
/**
|
|
201
|
+
* Covers the stage with a readable note. Opaque, so the last good render is
|
|
202
|
+
* not mistaken for this document; scrollable, for long reports. The styles
|
|
203
|
+
* are inline but plain (no `!important`), so a host can restyle
|
|
204
|
+
* `.gui-embed-error` and its parts.
|
|
205
|
+
*/
|
|
167
206
|
private _fail(message: string) {
|
|
168
207
|
let note = this.querySelector(':scope > .gui-embed-error') as HTMLDivElement | null
|
|
169
208
|
if (!note) {
|
|
170
209
|
note = document.createElement('div')
|
|
171
210
|
note.className = 'gui-embed-error'
|
|
172
|
-
note.
|
|
173
|
-
|
|
211
|
+
note.setAttribute('role', 'alert')
|
|
212
|
+
note.style.cssText = [
|
|
213
|
+
'position:absolute;inset:0;z-index:1;overflow:auto;box-sizing:border-box',
|
|
214
|
+
'display:flex;padding:16px',
|
|
215
|
+
'background:var(--gui-embed-bg, #fafaf8)',
|
|
216
|
+
'font:13px/1.45 system-ui,sans-serif;color:#333',
|
|
217
|
+
].join(';')
|
|
174
218
|
this.appendChild(note)
|
|
175
219
|
}
|
|
176
|
-
|
|
220
|
+
const { lines, more } = summarizeError(message)
|
|
221
|
+
const body = document.createElement('div')
|
|
222
|
+
body.className = 'gui-embed-error-body'
|
|
223
|
+
// margin:auto centers a short note and still lets a long one scroll from the top.
|
|
224
|
+
body.style.cssText = 'margin:auto;max-width:56ch;text-align:left'
|
|
225
|
+
const title = document.createElement('div')
|
|
226
|
+
title.className = 'gui-embed-error-title'
|
|
227
|
+
title.style.cssText = 'font-weight:600;color:#c00;margin-bottom:6px'
|
|
228
|
+
title.textContent = "This design can't be drawn"
|
|
229
|
+
body.appendChild(title)
|
|
230
|
+
const list = document.createElement('ul')
|
|
231
|
+
list.className = 'gui-embed-error-list'
|
|
232
|
+
list.style.cssText = 'margin:0;padding-left:18px;overflow-wrap:anywhere'
|
|
233
|
+
for (const line of lines) {
|
|
234
|
+
const item = document.createElement('li')
|
|
235
|
+
item.textContent = line
|
|
236
|
+
list.appendChild(item)
|
|
237
|
+
}
|
|
238
|
+
if (more) {
|
|
239
|
+
const item = document.createElement('li')
|
|
240
|
+
item.className = 'gui-embed-error-more'
|
|
241
|
+
item.style.cssText = 'list-style:none;margin-left:-18px;color:#777'
|
|
242
|
+
item.textContent = `and ${more} more`
|
|
243
|
+
list.appendChild(item)
|
|
244
|
+
}
|
|
245
|
+
body.appendChild(list)
|
|
246
|
+
note.replaceChildren(body)
|
|
177
247
|
}
|
|
178
248
|
|
|
179
249
|
/** A frame arrived: size the host on the first, and keep the view fitted. */
|
|
180
250
|
private _rendered(detail: RenderDetail) {
|
|
181
251
|
this.querySelector(':scope > .gui-embed-error')?.remove()
|
|
252
|
+
// Another page brings its own modes: the controls follow it.
|
|
253
|
+
if (this._canvas.page !== this._controlsPage) this._buildControls()
|
|
182
254
|
const first = !this._size || this._size.width !== detail.width || this._size.height !== detail.height
|
|
183
255
|
this._size = { width: detail.width, height: detail.height }
|
|
184
256
|
if (!first) return
|
|
@@ -283,11 +355,17 @@ export class GuiEmbedElement extends HTMLElement {
|
|
|
283
355
|
private _buildControls() {
|
|
284
356
|
const bar = this._bar
|
|
285
357
|
bar.innerHTML = ''
|
|
358
|
+
this._controlsPage = this._canvas.page
|
|
286
359
|
|
|
287
360
|
if (this.getAttribute('zoom') !== 'false') {
|
|
288
361
|
bar.appendChild(this._btn('Fit', 'Reset zoom', () => this.fit()))
|
|
289
362
|
}
|
|
290
363
|
|
|
364
|
+
const pages = this._canvas.pages
|
|
365
|
+
if (this.hasAttribute('page-switch') && pages.length > 1) {
|
|
366
|
+
bar.appendChild(this._pageSelect(pages))
|
|
367
|
+
}
|
|
368
|
+
|
|
291
369
|
const modes = this._canvas.modes
|
|
292
370
|
const axes = Object.keys(modes).filter((axis) => modes[axis].values.length > 1)
|
|
293
371
|
if (this.hasAttribute('mode-switch') && axes.length) {
|
|
@@ -321,19 +399,39 @@ export class GuiEmbedElement extends HTMLElement {
|
|
|
321
399
|
return b
|
|
322
400
|
}
|
|
323
401
|
|
|
324
|
-
private
|
|
402
|
+
private _select(title: string): HTMLSelectElement {
|
|
325
403
|
const sel = document.createElement('select')
|
|
326
|
-
sel.title =
|
|
404
|
+
sel.title = title
|
|
327
405
|
sel.style.cssText = ['all:unset;cursor:pointer;font:600 12px/1 system-ui', 'color:#fff;padding:6px 9px;border-radius:5px'].join(';')
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
406
|
+
return sel
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
private _option(value: string, label: string, selected: boolean): HTMLOptionElement {
|
|
410
|
+
const opt = document.createElement('option')
|
|
411
|
+
opt.value = value
|
|
412
|
+
opt.textContent = label
|
|
413
|
+
opt.style.color = '#000'
|
|
414
|
+
if (selected) opt.selected = true
|
|
415
|
+
return opt
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
private _pageSelect(pages: GuiPage[]): HTMLSelectElement {
|
|
419
|
+
const sel = this._select('Page')
|
|
420
|
+
sel.className = 'gui-embed-pages'
|
|
421
|
+
const current = this._canvas.page
|
|
422
|
+
for (const page of pages) {
|
|
423
|
+
const label = page.library ? 'Library' : page.name.replace(/\.guix$/, '')
|
|
424
|
+
sel.appendChild(this._option(page.name, label, page.name === current))
|
|
336
425
|
}
|
|
426
|
+
// Through the attribute, so `page` always says what is on show.
|
|
427
|
+
sel.addEventListener('change', () => this.setAttribute('page', sel.value))
|
|
428
|
+
return sel
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
private _modeSelect(axis: string, mode: ModeAxis): HTMLSelectElement {
|
|
432
|
+
const sel = this._select(`Mode: ${axis}`)
|
|
433
|
+
const current = this._canvas.mode[axis] ?? mode.default
|
|
434
|
+
for (const value of mode.values) sel.appendChild(this._option(value, value, value === current))
|
|
337
435
|
// The renderer switches via tokens; the markup is unchanged.
|
|
338
436
|
sel.addEventListener('change', () => this._canvas.setMode(axis, sel.value))
|
|
339
437
|
return sel
|