@stagepass/loader 2.3.0-beta.2 → 2.3.0-beta.4

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 CHANGED
@@ -37,7 +37,7 @@ See [MIGRATION.md](../../MIGRATION.md) for breaking changes from 1.x.
37
37
  - Session expiry (default **12 h**): `data-stagepass-session-hours` on the loader tag.
38
38
  - Optional legacy global console mute: `data-stagepass-mute-console="true"` (production, no session only).
39
39
  - Dynamically created scripts use `async=false` unless the original had `async`; `defer` is added when neither async nor defer was set (keeps classic order).
40
- - Chrome Local Network Access: best-effort permission query; flag tooltip, warning counter and console hint when state is `prompt` or `denied`.
40
+ - Chrome Local Network Access: best-effort permission query; when a local file fails at the network level and the state is `prompt` or `denied`, the error in the flag card includes the hint.
41
41
 
42
42
  ## Loader tag attributes
43
43
 
@@ -74,19 +74,23 @@ Storage key: `localStorage.stagepass_domain` → JSON `{ "domain": "…", "expir
74
74
 
75
75
  ## Dev flag
76
76
 
77
- Shown only while a session is active (including debug). Click clears the session and reloads.
77
+ Shown only while a session is active (including debug).
78
78
 
79
- | State | Flag |
79
+ | Stage | Flag |
80
80
  | :--- | :--- |
81
- | Active swap | `LOCAL` |
82
- | Debug | `DEBUG` |
83
- | Warnings / errors | icons with counters (`99+` above 99) |
84
-
85
- - Warnings: `sp.warn`, `sp.log('warn', …)`, loader warnings (for example the LNA hint).
86
- - Errors: `sp.error`, `sp.log('error', …)`, uncaught errors, failed resource loads, unhandled rejections.
87
- - Tooltip: session domain, counts, LNA hint.
88
- - Rendered in an open Shadow DOM (`#stagepass-flag`) with DOM APIs only (no `innerHTML`, no `eval`, constructable stylesheet with a `<style>` fallback). Respects `prefers-reduced-motion`.
89
- - The UI lives in `dist/flag.min.js` (about 1.4 KB gzip) and is fetched only during a session, next to the loader URL (or from jsDelivr at the same version when the loader is served under another file name). Allow that origin in `script-src` if the site uses a strict CSP.
81
+ | Rest | pass-icon pill with a status dot (amber: warnings, red: errors) |
82
+ | Hover / focus (first tap on touch) | expands to the left: `LOCAL` or `DEBUG`, warning and error counters (`99+` above 99) |
83
+ | Click (second tap on touch) | session card |
84
+
85
+ - Card: project, session domain, a collapsed list of swapped files (live → local, `js`/`css`, `ok` / `404` / `failed`; only loaded files count as swapped) and the latest 50 message groups (text only, truncated, repeats as `×N` with the last time). Rows are one-liners; details show source (`local` / `live` / `external`), `file:line:col` and the stack. "Always expanded" is stored per origin. "Copy all" and per-message "Copy" write Markdown (page URL without query, project, loader version, messages; no cookies or storage).
86
+ - Card footer: Reload, "Debug mode" / "Back to local" (reloads with `?stagepass=debug` and back to the previous session, also from a new tab), End session. Without a session to return to the button is disabled and the card explains why.
87
+ - Locally swapped files get `crossorigin="anonymous"` (unless the tag already sets `crossorigin`) for full error details. Without a CORS header from the local server the file loads again without it and a warning says so. Production files and debug sessions are unchanged.
88
+ - Only "End session" clears the session. Esc or a click outside closes the card.
89
+ - Warnings: `sp.warn`, `sp.log('warn', …)`, `console.warn` (only during a session; the original console still runs), loader warnings.
90
+ - Errors: `sp.error`, `sp.log('error', …)`, `console.error`, uncaught errors (with stack), failed resource loads, unhandled rejections (with stack). Local files report "Local file not found (404)" or "Local server not reachable … Run stagepass doctor". Sanitized errors from other origins show as "Error in a cross-origin script (details only in DevTools console)".
91
+ - Accessibility: the pill is a button with `aria-expanded`, the card a `role="dialog"`; focus moves into the card and back to the pill; reduced motion makes all changes instant.
92
+ - Rendered in an open Shadow DOM (`#stagepass-flag`) with DOM APIs only (no `innerHTML`, no `eval`, constructable stylesheet with a `<style>` fallback). No shadows, glow or filters.
93
+ - The UI lives in `dist/flag.min.js` (about 2.7 KB gzip) and `dist/flag-card.min.js` (about 4.8 KB gzip, fetched on first expand). Both are fetched only during a session, next to the loader URL (or from jsDelivr at the same version when the loader is served under another file name). Allow that origin in `script-src` if the site uses a strict CSP.
90
94
 
91
95
  ## Runtime API
92
96
 
@@ -0,0 +1,3 @@
1
+ (()=>{var rt="stagepass:flash",st="stagepass.card.v2";var wt='.cd{--bg:#FFFFFF;--ink:#17171B;--mu:#6D6869;--ln:#9C938E;--sep:#ECE6E2;--hv:#F6F2EF;--cp:#EFE9E4;--live:#C9302A;--err:#C0265A;--wa:#8A5C00;--on:#17171B;--onf:#FFFFFF;position:absolute;right:0;top:44px;width:360px;max-width:calc(100vw - 24px);max-height:calc(100vh - 68px);max-height:calc(100dvh - 68px);display:flex;flex-direction:column;box-sizing:border-box;border:1px solid var(--ln);border-radius:12px;background:var(--bg);color:var(--ink);font:400 13px/1.4 system-ui,-apple-system,"Segoe UI",Roboto,sans-serif;letter-spacing:0;text-align:left;overflow:hidden;opacity:0;transform:translateY(-4px);transform-origin:100% 0;outline:0}.cd.dk{--bg:#18181C;--ink:#F4F2F0;--mu:#A19C9E;--ln:#66666F;--sep:#2C2C32;--hv:#222227;--cp:#2A2A30;--live:#FF6A5E;--err:#FF6B93;--wa:#F2B53A;--on:#F4F2F0;--onf:#17171B}.cd.on{opacity:1;transform:none}.cd[hidden],[hidden]{display:none!important}.hd,.ft{flex:none}.sr{position:absolute;width:1px;height:1px;overflow:hidden;clip-path:inset(50%);white-space:nowrap}.mo{font-family:ui-monospace,"SF Mono",SFMono-Regular,Menlo,Consolas,monospace}.hd{padding:14px 16px 10px;display:grid;gap:4px;border-bottom:1px solid var(--sep)}.r1{display:flex;align-items:center;gap:8px;min-width:0}.r1 strong{font-size:14px;font-weight:600;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;min-width:0}.md{margin-left:auto;flex:none;font:700 11px/1 ui-monospace,"SF Mono",Menlo,Consolas,monospace;letter-spacing:.06em;color:var(--live);border:1px solid currentColor;border-radius:999px;padding:3px 7px}.kp{display:flex;align-items:center;justify-content:center;flex:none;width:20px;height:10px;border-radius:5px;background:#121215}.kp:before{content:"";width:15px;height:5px;border-radius:2.5px;background:linear-gradient(90deg,#FF453A,#FF8A3D)}.dm,.hn{font-size:12px;color:var(--mu);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.hn{white-space:normal}.sc{flex:1 1 auto;min-height:0;overflow:auto;overscroll-behavior:contain}.ds,.it{all:unset;box-sizing:border-box;display:flex;align-items:center;gap:8px;width:100%;min-height:36px;padding:6px 16px;cursor:pointer}.ds{font-size:12px;color:var(--mu)}.ds b{color:var(--ink);font-weight:600}.ds:before,.it:before{content:"";flex:none;width:5px;height:5px;border:solid var(--mu);border-width:0 1.5px 1.5px 0;transform:rotate(-45deg);margin:0 2px 0 -1px}[aria-expanded=true]:before{transform:rotate(45deg)}.ds:hover,.it:hover{background:var(--hv)}ul{list-style:none;margin:0;padding:0}.fl{padding:0 0 6px}.fl li{display:grid;grid-template-columns:30px minmax(0,1fr) auto;column-gap:8px;padding:3px 16px 3px 31px;font-size:12px}.fl .ty,.fl .lv{color:var(--mu)}.fl .lv{grid-column:2/4;font-size:11px}.fl .pa,.fl .lv,.tx,.mt{overflow:hidden;text-overflow:ellipsis;white-space:nowrap;min-width:0}.fl .bad{color:var(--err);font-weight:600}.lh{position:sticky;top:0;z-index:1;display:flex;align-items:center;gap:8px;padding:6px 12px 6px 16px;border-top:1px solid var(--sep);background:var(--bg);font-size:11px;color:var(--mu)}.lh>span:first-child{font-weight:600;letter-spacing:.06em;text-transform:uppercase}.lh .ct{margin-right:auto;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;min-width:0}.sm{all:unset;box-sizing:border-box;flex:none;display:inline-flex;align-items:center;height:24px;padding:0 8px;border:1px solid var(--sep);border-radius:6px;font:500 11px/1 system-ui,-apple-system,"Segoe UI",Roboto,sans-serif;color:var(--ink);cursor:pointer;white-space:nowrap}.sm:hover{background:var(--hv)}.sm[aria-pressed=true]{border-color:var(--ink)}.it svg{flex:none;width:14px;height:14px}.it.e svg{color:var(--err)}.it.w svg{color:var(--wa)}.tx{flex:1}.mt{flex:none;font-size:11px;color:var(--mu)}.mt b{color:var(--ink);font-weight:600;margin-right:6px}.dt{display:grid;gap:6px;padding:0 16px 10px 53px;font-size:12px}.dt .ms{word-break:break-word}.dt .lo{color:var(--mu);font-size:11px;word-break:break-all}.dt pre{margin:0;padding:8px;border-radius:6px;background:var(--hv);font:11px/1.45 ui-monospace,"SF Mono",Menlo,Consolas,monospace;white-space:pre-wrap;word-break:break-all;max-height:180px;overflow:auto;overscroll-behavior:contain}.dt .sm{justify-self:start}.em{margin:0;padding:6px 16px 14px;color:var(--mu);font-size:12px}.ft{display:flex;align-items:center;gap:8px;padding:10px 12px 12px;border-top:1px solid var(--sep)}.bt{all:unset;box-sizing:border-box;display:inline-flex;align-items:center;height:32px;padding:0 12px;border:1px solid var(--ln);border-radius:8px;font:600 13px/1 system-ui,-apple-system,"Segoe UI",Roboto,sans-serif;color:var(--ink);cursor:pointer;white-space:nowrap}.bt:hover{background:var(--hv)}.bt:disabled{opacity:.45;cursor:not-allowed;background:none;border-style:dashed}.end{all:unset;margin-left:auto;padding:8px 4px;font:500 12px/1 system-ui,-apple-system,"Segoe UI",Roboto,sans-serif;color:var(--err);cursor:pointer;white-space:nowrap}.end:hover{text-decoration:underline}.bt:focus-visible,.end:focus-visible,.sm:focus-visible{outline:2px solid var(--ink);outline-offset:2px}.ds:focus-visible,.it:focus-visible{outline:2px solid var(--ink);outline-offset:-2px;border-radius:6px}@media (pointer:coarse){.bt,.ds,.it,.sm{min-height:44px}.end{padding:16px 6px}}@media (max-width:400px){.ft{gap:6px;padding:8px}.bt{padding:0 10px}}@media (prefers-reduced-motion:no-preference){.cd{transition:opacity .1s,transform .1s cubic-bezier(.4,0,1,1)}.cd.on{transition:opacity .16s,transform .16s cubic-bezier(.2,.8,.2,1)}}';function yt(t){let r=t.match(/[\d.]+/g);return!r||r.length>3&&+r[3]<.5?-1:r.slice(0,3).reduce((o,e,n)=>{let l=+e/255;return l=l<=.04045?l/12.92:Math.pow((l+.055)/1.055,2.4),o+l*[.2126,.7152,.0722][n]},0)}function Ft(t){let r=document;try{let o=t.getBoundingClientRect(),e=r.elementsFromPoint(Math.max(8,o.right-170),o.bottom+60);for(let n of e)if(n!=t)for(let l=n;l;l=l.parentElement){let w=yt(getComputedStyle(l).backgroundColor);if(w>=0)return w<.18}}catch{}return dt("(prefers-color-scheme: dark)")}function dt(t){try{return matchMedia(t).matches}catch{return!1}}var R="stagepass:prev",it="stagepass:expand",kt=/^[a-z0-9-]+(\.[a-z0-9-]+)*\.sp$/,H=(t,r)=>{try{if(r===void 0)return localStorage.getItem(t);r===null?localStorage.removeItem(t):localStorage.setItem(t,r)}catch{}return null},at=(t,r)=>t+" "+r+(t==1?"":"s"),P=(t,r)=>{try{let o=new URL(t),e=o.pathname.split("/").filter(Boolean);return r?"/"+e.join("/"):o.host+(e.length>2?"/\u2026/":"/")+e.slice(-2).join("/")}catch{return t}},W=t=>(t.url||t.file)+(t.line?":"+t.line+(t.col?":"+t.col:""):""),Ct=t=>(t.type=="error"?"Error":"Warning")+(t.c>1?" \xD7"+t.c:""),pt=t=>t.st||"loading";function lt(t,r){let o=location,e=["### Stagepass messages","- Page: "+o.origin+o.pathname,"- Project: "+(t.domain?t.domain+" (local files)":"debug session (live files)"),"- Loader: @stagepass/loader "+t.v];return t.f.length&&e.push("- Files: "+t.f.map(n=>P(n.local,!0)+" "+pt(n)).join(", ")),r.forEach((n,l)=>{e.push("","**"+(l+1)+". "+Ct(n)+"** (last "+n.time+")",n.text),(n.src||n.line)&&e.push("Location: "+[n.src,W(n)].filter(Boolean).join(" \xB7 ")),n.stack&&e.push("```",n.stack.replace(/```/g,"` ` `"),"```")}),e.join(`
2
+ `)}function ct(t){let r=document,o=t.s;t.css(t.root,wt);let e=(s,p,c,g)=>{let f=p.appendChild(r.createElement(s));return c&&(f.className=c),g&&(f.textContent=g),f},n=(s,p,c)=>{let g=e("button",s,p,c);return g.type="button",g},l=(s,p)=>{s.textContent!==p&&(s.textContent=p)},w=e("span",t.w,"sr");w.setAttribute("role","status"),w.setAttribute("aria-live","polite");let d=e("div",t.w,"cd");d.hidden=!0,d.tabIndex=-1,d.setAttribute("role","dialog"),d.setAttribute("aria-label","Stagepass session");let j=e("div",d,"hd"),B=e("div",j,"r1");e("span",B,"kp").setAttribute("aria-hidden","true");let U=e("strong",B),ut=e("span",B,"md"),G=e("div",j,"dm mo"),K=e("div",j,"hn"),A=e("div",d,"sc"),h=n(A,"ds"),C=e("ul",A,"fl");C.id="sp-files",h.setAttribute("aria-controls",C.id);let L=e("div",A,"lh");e("span",L,"","Messages");let ft=e("span",L,"ct"),V=n(L,"sm","Always expanded"),_=n(L,"sm","Copy all"),I=e("div",A),O=e("div",d,"ft"),mt=n(O,"bt","Reload"),M=n(O,"bt"),ht=n(O,"end","End session"),y=!1,F=H(it)=="1",z=new Map,q=s=>s.type+s.text+s.url+s.line+s.col,X="",$="",Y,J=(s,p,c)=>{let g=()=>{let u=p.textContent||"";p.textContent=c,w.textContent="Copied to clipboard",setTimeout(()=>p.textContent=u,1600)},f=()=>{let u=e("textarea",t.root);u.value=s,u.select();try{r.execCommand("copy")}catch{}u.remove(),g()};try{navigator.clipboard.writeText(s).then(g,f)}catch{f()}},k=H(R);try{k=k||sessionStorage.getItem(R)}catch{}k&&!kt.test(k)&&(k=null);let x=o.debug?k:"debug",T=()=>{let s=o.domain||location.hostname,p=o.domain?s.replace(/\.sp$/,""):"Debug session";l(U,p),U.title=p,l(ut,o.debug?"DEBUG":"LOCAL"),l(G,s),G.title=s,l(K,o.debug?x?"Live files with console logs. Back to local loads "+x+".":"Live files with console logs. No local session to return to: open the page with ?stagepass=<project>.sp":""),K.hidden=!o.debug,l(M,o.debug?"Back to local":"Debug mode"),M.title=o.debug?x?"Reload with local files from "+x:"No local session to return to":"Reload with live files and console logs",M.disabled=!x;let c=o.f,g=c.filter(i=>i.st&&i.st!="ok").length,f=c.map(i=>i.local+i.st).join()+y;h.hidden=!c.length,f!=$&&($=f,h.textContent="",e("b",h,"",String(o.swapped)),h.appendChild(r.createTextNode(" "+(o.swapped==1?"file":"files")+" swapped locally"+(g?" \xB7 "+g+" failed":""))),h.setAttribute("aria-expanded",String(y)),C.hidden=!y,C.textContent="",y&&c.forEach(i=>{let a=e("li",C);a.title=i.live+`
3
+ \u2192 `+i.local,e("span",a,"ty mo",i.type),e("span",a,"pa mo",P(i.local,!0)),e("span",a,i.st&&i.st!="ok"?"bad":"",pt(i)),e("span",a,"lv mo","live "+P(i.live))}));let[u,N]=o.n,b=o.m,xt=b.reduce((i,a)=>i+a.c,0);l(ft,u+N>xt?u+N+" total, latest "+b.length+" shown":at(N,"error")+" \xB7 "+at(u,"warning")),V.setAttribute("aria-pressed",String(F)),_.hidden=!b.length;let Q=b.map(i=>q(i)+i.c).join("|")+F;if(Q==X)return;X=Q;let bt=t.root.activeElement&&t.root.activeElement.dataset.k;if(I.textContent="",!b.length){e("p",I,"em","No warnings or errors in this session.");return}let vt=e("ul",I);for(let i=b.length-1;i>=0;i--){let a=b[i],S=q(a),D=a.type=="error",Z=e("li",vt),m=n(Z,"it "+(D?"e":"w"));m.dataset.k=S,m.appendChild(t.icon(D?1:0));let tt=e("span",m,"tx");e("span",tt,"sr",D?"Error: ":"Warning: "),tt.appendChild(r.createTextNode(a.text));let et=e("span",m,"mt mo");a.c>1&&e("b",et,"","\xD7"+a.c),et.appendChild(r.createTextNode(a.time));let E=e("div",Z,"dt");if(e("div",E,"ms",a.text),a.src||a.line){let v=e("div",E,"lo mo",[a.src,W(a)].filter(Boolean).join(" \xB7 "));v.title=W(a)}a.stack&&e("pre",E,"",a.stack);let ot=n(E,"sm","Copy");ot.addEventListener("click",()=>J(lt(o,[a]),ot,"Copied"));let nt=v=>{m.setAttribute("aria-expanded",String(v)),E.hidden=!v};nt(z.has(S)?!!z.get(S):F),m.addEventListener("click",()=>{let v=m.getAttribute("aria-expanded")!="true";z.set(S,v),nt(v)}),bt===S&&m.focus({preventScroll:!0})}};return h.addEventListener("click",()=>{y=!y,T()}),V.addEventListener("click",()=>{F=!F,H(it,F?"1":null),z.clear(),T()}),_.addEventListener("click",()=>J(lt(o,o.m.slice().reverse()),_,"Copied")),mt.addEventListener("click",()=>location.reload()),M.addEventListener("click",()=>{if(!x)return;o.domain&&H(R,o.domain);try{o.domain&&sessionStorage.setItem(R,o.domain),sessionStorage.setItem(rt,"1")}catch{}let s=new URL(location.href);s.searchParams.set("stagepass",x),location.href=s.href}),ht.addEventListener("click",()=>o.end()),{render:T,show(){clearTimeout(Y),T(),d.classList.toggle("dk",Ft(t.host)),d.hidden=!1,d.offsetWidth,d.classList.add("on"),d.focus({preventScroll:!0})},hide(){d.classList.remove("on"),Y=setTimeout(()=>d.hidden=!0,dt("(prefers-reduced-motion: reduce)")?0:110)}}}var gt;try{let t=(gt=window.stagepass)==null?void 0:gt[Symbol.for(st)];typeof t=="function"&&t(ct)}catch{}})();
package/dist/flag.min.js CHANGED
@@ -1,2 +1 @@
1
- (()=>{var b=':host{all:initial!important;position:fixed!important;top:12px!important;right:12px!important;z-index:2147483647!important;display:block!important}button{all:unset;box-sizing:border-box;display:flex;align-items:center;gap:6px;height:24px;padding:0 9px 0 8px;border-radius:99px;background:linear-gradient(90deg,#FF453A,#FF8A3D);color:#fff;font:700 11px/1 ui-monospace,SFMono-Regular,Menlo,monospace;letter-spacing:.06em;white-space:nowrap;cursor:pointer;user-select:none;-webkit-user-select:none}button:hover{background:linear-gradient(90deg,#FF5B4F,#FF9A55)}button:focus-visible{outline:2px solid #fff;outline-offset:2px}i{position:relative;width:9px;height:13px;border-radius:2.5px;background:#fff}i:before,i:after{content:"";position:absolute;left:2px;border-radius:1px}i:before{top:2px;width:5px;height:2px;background:#FF453A}i:after{bottom:2px;width:5px;height:3px;background:linear-gradient(#121215 1px,#0000 0 2px,#121215 0);opacity:.45}span{display:flex;align-items:center;gap:3px;height:16px;padding:0 5px 0 4px;border-radius:99px;background:rgba(18,18,21,.3)}span:before{content:"";width:9px;height:8px;background:#fff;clip-path:polygon(50% 0,100% 100%,0 100%)}.e:before{width:8px;clip-path:polygon(30% 0,70% 0,100% 30%,100% 70%,70% 100%,30% 100%,0 70%,0 30%)}[hidden]{display:none}@media (prefers-reduced-motion:no-preference){button{animation:a .45s cubic-bezier(.2,.9,.3,1.2)}i:before{animation:b 1s .15s both}}@keyframes a{from{opacity:0;transform:scale(.8)}}@keyframes b{0%{opacity:0}60%{opacity:1;transform:scale(1.4)}}';function u(a,c,s,y){let o=document,r=o.createElement("div");r.id="stagepass-flag";let p=r.attachShadow({mode:"open"});try{if(!("adoptedStyleSheets"in p))throw 0;let e=new CSSStyleSheet;e.replaceSync(b),p.adoptedStyleSheets=[e]}catch{let t=p.appendChild(o.createElement("style"));t.textContent=b}let i=(e,t)=>t.appendChild(o.createElement(e)),n=i("button",p);n.type="button",i("i",n),i("b",n).textContent=a;let l=[i("span",n),i("span",n)];l[1].className="e";let f=()=>{let e=s.n,t=["Stagepass "+a+(c?" \xB7 "+c:"")];e[0]&&t.push(e[0]+" warning"+(e[0]>1?"s":"")),e[1]&&t.push(e[1]+" error"+(e[1]>1?"s":"")),s.tip&&t.push(s.tip),t.push("Click to disconnect");let h=t.join(`
2
- `);n.title=h,n.setAttribute("aria-label",h),l.forEach((x,d)=>{x.hidden=!e[d],x.textContent=e[d]>99?"99+":String(e[d])})};f(),n.addEventListener("click",y);let g=()=>{r.isConnected||(o.body||o.documentElement).appendChild(r)};return o.readyState==="loading"?o.addEventListener("DOMContentLoaded",g):g(),f}var m;try{let a=(m=window.stagepass)==null?void 0:m[Symbol.for("stagepass.flag")];typeof a=="function"&&a(u)}catch{}})();
1
+ (()=>{var K=":host{all:initial!important;position:fixed!important;top:12px!important;right:12px!important;z-index:2147483647!important;display:block!important}.w{--W:44px;--k:1;--fg:#17171B;--a:#FF453A;--z:#FF8A3D;--ring:#121215;--bd:rgba(18,18,21,.22);position:relative;display:block;font:700 12px/1 ui-monospace,Menlo,Consolas,monospace;letter-spacing:.04em;color:var(--fg)}.b{all:unset;box-sizing:border-box;position:relative;display:block;margin-left:auto;height:44px;width:var(--W);cursor:pointer;-webkit-tap-highlight-color:transparent;touch-action:manipulation}[data-st=rest] .b{width:44px}.bg,.t,.fr{position:absolute;right:0;top:8px;height:28px;box-sizing:border-box}.bg{width:var(--W);transform-origin:100% 50%}.bg i{position:absolute;top:0;height:28px;box-sizing:border-box;border:solid var(--bd);border-width:1px 0}.bg .l{left:0;width:14px;border-left-width:1px;border-radius:14px 0 0 14px;background:var(--a)}.bg .r{right:0;width:14px;border-right-width:1px;border-radius:0 14px 14px 0;background:var(--z)}.m{left:13px;right:13px;background:linear-gradient(90deg,var(--a),var(--z));transform-origin:100% 0}[data-st=rest] .l{transform:translateX(calc(var(--W) - 44px))}[data-st=rest] .m{transform:scaleX(var(--k))}.t{display:flex;align-items:center;gap:10px;padding:0 14px;white-space:nowrap;pointer-events:none}[data-st=rest] .t>b,[data-st=rest] .c{opacity:0}.c{display:flex;gap:10px}.c:empty{display:none}.c span{display:flex;align-items:center;gap:4px}svg{flex:none;fill:none;stroke:currentColor;stroke-width:1.6;stroke-linecap:round;stroke-linejoin:round}.c svg{width:12px;height:12px}.k{width:16px;height:8px;stroke-width:2}.dot{position:absolute;right:-1px;top:3px;width:8px;height:8px;border-radius:50%;border:2px solid var(--ring);background:var(--d);opacity:0}[data-d=e] .dot{--d:#FF2E4D}[data-d=w] .dot{--d:#FFB224}[data-st=rest][data-d] .dot{opacity:1}.fr{right:-4px;top:4px;height:36px;width:calc(var(--W) + 8px);border-radius:18px;border:2px solid #fff;outline:2px solid var(--ring);opacity:0;pointer-events:none}.b:focus-visible .fr{opacity:1}[data-st=rest] .fr{width:52px}.b:active .bg{transform:scale(.96)}@media (prefers-reduced-motion:no-preference){.l,.m{transition:transform .22s cubic-bezier(.2,.8,.2,1)}.t>b,.c{transition:opacity .14s .06s}[data-st=rest] .l,[data-st=rest] .m{transition:transform .16s cubic-bezier(.4,0,.6,1)}[data-st=rest] .t>b,[data-st=rest] .c{transition:opacity .08s}.dot{transition:opacity .12s}[data-st=rest] .dot{transition-delay:.12s}.fr{transition:opacity .12s .12s}.bg{transition:transform .08s}}",m="http://www.w3.org/2000/svg",R=["M6 1.3 11 10.3H1zM6 4.8v2.2m0 1.6v.1","M4 1h4l3 3v4l-3 3H4L1 8V4zM6 3.8v2.6m0 1.6v.1"],O="stagepass.flag.v2",L="stagepass:flash",V="stagepass.card.v2";function T(r,t){try{if(!("adoptedStyleSheets"in r))throw 0;let s=new CSSStyleSheet;s.replaceSync(t),r.adoptedStyleSheets=[...r.adoptedStyleSheets,s]}catch{r.appendChild(document.createElement("style")).textContent=t}}function M(r){let t=document.createElementNS(m,"svg");return t.setAttribute("viewBox","0 0 12 12"),t.setAttribute("aria-hidden","true"),t.appendChild(document.createElementNS(m,"path")).setAttribute("d",R[r]),t}var z=(r,t)=>r+" "+t+(r==1?"":"s"),H=(r,t)=>{try{return r.matches(t)}catch{return!1}};function N(r){let t=document,s=t.createElement("div");s.id="stagepass-flag";let x=s.attachShadow({mode:"open"});T(x,K);let p=(e,d,n)=>{let c=d.appendChild(t.createElement(e));return n&&(c.className=n),c},l=p("div",x,"w");l.setAttribute("data-st","rest");let a=p("button",l,"b");a.type="button",a.setAttribute("aria-haspopup","dialog"),a.setAttribute("aria-expanded","false");let S=p("span",a,"bg");["l","m","r"].forEach(e=>p("i",S,e)),p("span",a,"fr");let u=p("span",a,"t");S.setAttribute("aria-hidden","true"),u.setAttribute("aria-hidden","true");let G=p("b",u),F=p("span",u,"c"),v=u.appendChild(t.createElementNS(m,"svg"));v.setAttribute("class","k"),v.setAttribute("viewBox","0 0 16 8"),v.appendChild(t.createElementNS(m,"path")).setAttribute("d","M4 1h8a3 3 0 0 1 0 6H4a3 3 0 0 1 0-6z"),p("i",a,"dot");let i="rest",g=null,E=!1,y,h=!1,C="rest",w=!1,b=()=>{let[e,d]=r.n,n=r.debug?"DEBUG":"LOCAL";G.textContent=n,F.textContent="",[e,d].forEach((f,D)=>{if(!f)return;let k=p("span",F);k.appendChild(M(D)),k.appendChild(t.createTextNode(f>99?"99+":String(f)))}),d||e?l.setAttribute("data-d",d?"e":"w"):l.removeAttribute("data-d"),a.setAttribute("aria-label","Stagepass "+n+", "+z(e,"warning")+", "+z(d,"error")+". "+(i=="card"?"Hide":"Show")+" session details");let c=u.offsetWidth;c&&(l.style.setProperty("--W",c+"px"),l.style.setProperty("--k",String(18/(c-26)))),g&&g.render()},W=()=>{if(!E){E=!0;try{let e=window.stagepass,d=Symbol.for(V);Object.defineProperty(e,d,{configurable:!0,value:c=>{delete e[d];try{g=c(B),i=="card"&&g.show()}catch{}}});let n=t.createElement("script");n.src=r.card,n.async=!0,(t.head||t.documentElement).appendChild(n)}catch{}}},o=e=>{e!=i&&(clearTimeout(y),i=e,l.setAttribute("data-st",e),a.setAttribute("aria-expanded",String(e=="card")),e!="rest"&&W(),g&&(e=="card"?g.show():g.hide()),b())},B={s:r,root:x,w:l,host:s,go:o,icon:M,css:T};a.addEventListener("pointerdown",e=>{h=e.pointerType=="touch",C=i}),a.addEventListener("pointerenter",e=>{e.pointerType=="mouse"&&i=="rest"&&o("exp")}),l.addEventListener("pointerleave",e=>{e.pointerType=="mouse"&&i=="exp"&&!H(a,":focus-visible")&&o("rest")}),a.addEventListener("focus",()=>{!h&&!w&&i=="rest"&&o("exp")}),a.addEventListener("blur",()=>{i=="exp"&&!H(a,":hover")&&o("rest")}),a.addEventListener("click",()=>{h&&C=="rest"?(o("exp"),y=setTimeout(()=>o("rest"),4e3)):o(i=="card"?"exp":"card"),h=!1}),t.addEventListener("keydown",e=>{e.key!="Escape"||i=="rest"||(i=="card"?(o("exp"),a.focus()):o("rest"))}),t.addEventListener("pointerdown",e=>{if(i=="rest"||e.composedPath().indexOf(s)>=0)return;let d=t.activeElement==s;o("rest"),d&&setTimeout(()=>{let n=t.activeElement;(!n||n==t.body||n==s)&&(w=!0,a.focus({preventScroll:!0}),w=!1)})},!0);let A=()=>{s.isConnected||(t.body||t.documentElement).appendChild(s),b();try{sessionStorage.getItem(L)&&(sessionStorage.removeItem(L),o("exp"),y=setTimeout(()=>o("rest"),3e3))}catch{}};return t.readyState==="loading"?t.addEventListener("DOMContentLoaded",A):A(),b(),b}var _;try{let r=(_=window.stagepass)==null?void 0:_[Symbol.for(O)];typeof r=="function"&&r(N)}catch{}})();
package/dist/loader.js CHANGED
@@ -288,7 +288,7 @@ var Stagepass = (() => {
288
288
  const W = window;
289
289
  const d = document;
290
290
  const loc = location;
291
- const PKG_VERSION = true ? "2.3.0-beta.2" : "0.0.0";
291
+ const PKG_VERSION = true ? "2.3.0-beta.4" : "0.0.0";
292
292
  const LOADER_RE = /loader(?:\.min)?\.js/i;
293
293
  function getLoaderScript() {
294
294
  try {
@@ -312,36 +312,91 @@ var Stagepass = (() => {
312
312
  const stagingHosts = parseStagingHosts(attr("staging-hosts"));
313
313
  const aliasName = attr("alias");
314
314
  const p = new URLSearchParams(loc.search);
315
- function getCallerLocation() {
315
+ let hasActiveSession = false;
316
+ const flagState = { n: [0, 0], m: [], f: [], swapped: 0, v: PKG_VERSION };
317
+ let renderFlag = null;
318
+ const draw = () => renderFlag && renderFlag();
319
+ const time = () => (/* @__PURE__ */ new Date()).toTimeString().slice(0, 8);
320
+ const fileOf = (u) => (u || "").split(/[?#]/)[0].split("/").pop() || "";
321
+ const cut = (t, n) => t.length > n ? t.slice(0, n) + "\u2026" : t;
322
+ const str = (a, depth = 0) => {
316
323
  try {
317
- const stack = (new Error().stack || "").split("\n");
318
- for (let i = 3; i < stack.length; i++) {
319
- const m = stack[i].match(/([^/]+\.(?:js|ts))(?:[?#][^:]*)?:(\d+)/);
320
- if (m && !LOADER_RE.test(m[1])) return ` ${m[1]}:${m[2]}`;
321
- }
324
+ if (typeof a === "string") return depth ? JSON.stringify(a) : a;
325
+ if (a instanceof Error) return a.name + ": " + a.message;
326
+ if (!a || typeof a !== "object") return String(a);
327
+ if (a instanceof Node) return "<" + a.nodeName.toLowerCase() + ">";
328
+ const arr = Array.isArray(a);
329
+ if (depth > 2) return arr ? "[\u2026]" : "{\u2026}";
330
+ const keys = Object.keys(a);
331
+ const out = keys.slice(0, 20).map((k) => (arr ? "" : k + ": ") + str(a[k], depth + 1));
332
+ if (keys.length > 20) out.push("\u2026");
333
+ return cut(arr ? "[" + out.join(", ") + "]" : "{" + out.join(", ") + "}", 1e3);
322
334
  } catch (_) {
335
+ return "[unserializable]";
323
336
  }
324
- return "";
325
- }
326
- let hasActiveSession = false;
327
- const flagState = { n: [0, 0], tip: "" };
328
- let renderFlag = null;
329
- const bump = (i) => {
337
+ };
338
+ const frame = (stack, skip = 0) => {
339
+ const lines = (stack || "").split("\n");
340
+ for (let i = skip; i < lines.length; i++) {
341
+ const m = lines[i].match(/([a-z][\w+.-]*:\/\/[^\s()]+?):(\d+):(\d+)/i);
342
+ if (m && !LOADER_RE.test(fileOf(m[1]))) return [m[1], m[2], m[3]];
343
+ }
344
+ return null;
345
+ };
346
+ let dom = null;
347
+ const srcOf = (u) => !u ? "external" : dom && !u.indexOf(`https://${dom}/`) ? "local" : "live";
348
+ const note = (i, text, url = "", line = "", col = "", stack = "", src) => {
330
349
  flagState.n[i]++;
331
- if (renderFlag) renderFlag();
350
+ const m = flagState.m;
351
+ const x = {
352
+ type: i ? "error" : "warn",
353
+ time: time(),
354
+ src: src || (url ? srcOf(url) : ""),
355
+ file: fileOf(url),
356
+ url: url.split(/[?#]/)[0],
357
+ line: line ? String(line) : "",
358
+ col: col ? String(col) : "",
359
+ text: cut(text, 500),
360
+ stack: cut(stack, 2e3),
361
+ c: 1
362
+ };
363
+ const k = (y) => y.type + y.text + y.url + y.line + y.col;
364
+ for (let j = m.length - 1; j >= 0; j--)
365
+ if (k(m[j]) === k(x)) {
366
+ x.c = m[j].c + 1;
367
+ m.splice(j, 1);
368
+ break;
369
+ }
370
+ m.push(x);
371
+ if (m.length > 50) m.shift();
372
+ draw();
373
+ };
374
+ const noteErr = (i, prefix, args, at) => {
375
+ const er = args.find((a) => a instanceof Error);
376
+ const st = er && er.stack || "";
377
+ const f = frame(st) || at;
378
+ note(i, prefix + args.map((a) => str(a)).join(" "), f ? f[0] : "", f ? f[1] : "", f ? f[2] : "", st);
379
+ };
380
+ let busy = false;
381
+ const print = (fn) => {
382
+ busy = true;
383
+ try {
384
+ fn();
385
+ } catch (_) {
386
+ }
387
+ busy = false;
332
388
  };
333
389
  function log(level, ...args) {
334
390
  if (!hasActiveSession) return;
335
- if (level === "warn" || level === "error") bump(level === "warn" ? 0 : 1);
336
- try {
337
- const where = getCallerLocation();
338
- const pre = `[\u{1F3AB} ${(/* @__PURE__ */ new Date()).toTimeString().split(" ")[0]}${where ? " |" + where : ""}]`;
391
+ const at = frame(new Error().stack || "", 3);
392
+ if (level === "warn" || level === "error") noteErr(level === "warn" ? 0 : 1, "", args, at);
393
+ print(() => {
394
+ const pre = `[\u{1F3AB} ${time()}${at ? " | " + fileOf(at[0]) + ":" + at[1] : ""}]`;
339
395
  const c = console;
340
396
  if (level === "error") c.log(`%c${pre}`, "color:red;font-weight:bold", ...args);
341
397
  else if (c[level]) c[level](pre, ...args);
342
398
  else c.log(pre, level, ...args);
343
- } catch (_) {
344
- }
399
+ });
345
400
  }
346
401
  function spLog(...args) {
347
402
  const level = args[0] === "warn" || args[0] === "error" ? args.shift() : "log";
@@ -412,7 +467,7 @@ var Stagepass = (() => {
412
467
  if (sv && !paramProcessed && !debug) log("log", `\u{1F50C} Stagepass connected to: ${sv}`);
413
468
  const dev = !!sv;
414
469
  const swap = dev && !debug;
415
- const dom = swap ? cleanDomain(sv) : null;
470
+ dom = swap ? cleanDomain(sv) : null;
416
471
  const now = swap ? Date.now() : 0;
417
472
  const hostname = loc.hostname;
418
473
  const isLocalhost = hostname === "localhost" || hostname === "127.0.0.1" || hostname.startsWith("localhost:") || hostname.startsWith("127.0.0.1:");
@@ -489,28 +544,65 @@ var Stagepass = (() => {
489
544
  }
490
545
  if (dev) {
491
546
  try {
492
- const FLAG = /* @__PURE__ */ Symbol.for("stagepass.flag");
547
+ const FLAG = /* @__PURE__ */ Symbol.for("stagepass.flag.v2");
548
+ const src = loaderScript && loaderScript.src || "";
549
+ const base = /\/loader(?:\.min)?\.js$/i.test(src.split(/[?#]/)[0]) ? new URL("./", src).href : `https://cdn.jsdelivr.net/npm/@stagepass/loader@${PKG_VERSION}/dist/`;
550
+ Object.assign(flagState, {
551
+ debug,
552
+ domain: dom,
553
+ card: base + "flag-card.min.js",
554
+ // End session is the only flag action that disconnects
555
+ end: () => {
556
+ clearSession();
557
+ hasActiveSession = true;
558
+ log("log", "\u{1F50C} Stagepass disconnected.");
559
+ emit("session", { active: false, domain: null, swap: false, debug: false });
560
+ loc.reload();
561
+ }
562
+ });
493
563
  Object.defineProperty(stagepassObj, FLAG, {
494
564
  configurable: true,
495
565
  value: (create) => {
496
566
  delete stagepassObj[FLAG];
497
567
  try {
498
- renderFlag = create(debug ? "DEBUG" : "LOCAL", dom, flagState, () => {
499
- clearSession();
500
- hasActiveSession = true;
501
- log("log", "\u{1F50C} Stagepass disconnected.");
502
- emit("session", { active: false, domain: null, swap: false, debug: false });
503
- loc.reload();
504
- });
568
+ renderFlag = create(flagState);
505
569
  } catch (_) {
506
570
  }
507
571
  }
508
572
  });
509
- W.addEventListener("error", () => bump(1), true);
510
- W.addEventListener("unhandledrejection", () => bump(1));
511
- const src = loaderScript && loaderScript.src || "";
573
+ W.addEventListener(
574
+ "error",
575
+ (e) => {
576
+ const t = e.target;
577
+ const u = t && t !== W && (t.src || t.href);
578
+ if (typeof u === "string") {
579
+ if (!mine.has(t)) note(1, "Failed to load " + u.split(/[?#]/)[0], u);
580
+ } else if (/^Script error\.?$/.test(e.message || "") && !e.filename)
581
+ note(1, "Error in a cross-origin script (details only in DevTools console)", "", "", "", "", "external");
582
+ else
583
+ note(1, e.message || "Script error", e.filename || "", e.lineno, e.colno, e.error && e.error.stack || "");
584
+ },
585
+ true
586
+ );
587
+ W.addEventListener("unhandledrejection", (e) => noteErr(1, "Unhandled rejection: ", [e.reason], null));
588
+ const c = console;
589
+ ["warn", "error"].forEach((k, i) => {
590
+ const o = c[k];
591
+ if (typeof o !== "function") return;
592
+ c[k] = function(...args) {
593
+ if (!busy) {
594
+ busy = true;
595
+ try {
596
+ noteErr(i, "", args, frame(new Error().stack || "", 2));
597
+ } catch (_) {
598
+ }
599
+ busy = false;
600
+ }
601
+ return o.apply(this, args);
602
+ };
603
+ });
512
604
  const s = d.createElement("script");
513
- s.src = /\/loader(?:\.min)?\.js$/i.test(src.split(/[?#]/)[0]) ? new URL("flag.min.js", src).href : `https://cdn.jsdelivr.net/npm/@stagepass/loader@${PKG_VERSION}/dist/flag.min.js`;
605
+ s.src = base + "flag.min.js";
514
606
  s.async = true;
515
607
  s.onerror = () => spWarn("Stagepass flag could not be loaded: " + s.src);
516
608
  (d.head || d.documentElement).appendChild(s);
@@ -532,6 +624,39 @@ var Stagepass = (() => {
532
624
  return m ? m[1] : null;
533
625
  }
534
626
  }
627
+ const mine = /* @__PURE__ */ new WeakSet();
628
+ let lnaState = "";
629
+ function track(n, live, local, isScript, retry) {
630
+ const f = { live, local, type: isScript ? "js" : "css", st: "" };
631
+ const name = fileOf(local);
632
+ mine.add(n);
633
+ flagState.f.push(f);
634
+ n.addEventListener("load", () => {
635
+ f.st = "ok";
636
+ flagState.swapped++;
637
+ draw();
638
+ });
639
+ n.addEventListener("error", () => {
640
+ const fail = (st, i, text) => {
641
+ f.st = st;
642
+ note(i, text, local);
643
+ };
644
+ const F = W.fetch;
645
+ if (typeof F !== "function") return fail("failed", 1, `Failed to load ${name}`);
646
+ F(local, { method: "HEAD", cache: "no-store" }).then(
647
+ (r) => fail(r.ok ? "failed" : String(r.status), 1, r.ok ? `Failed to load ${name}` : `Local file not found (${r.status}): ${name}`),
648
+ () => F(local, { method: "HEAD", mode: "no-cors", cache: "no-store" }).then(
649
+ () => {
650
+ if (!retry) return fail("failed", 1, `Failed to load ${name}`);
651
+ flagState.f.splice(flagState.f.indexOf(f), 1);
652
+ n.replaceWith(retry(false));
653
+ note(0, `Local server sends no CORS header for ${name}. Loaded without crossorigin, error details are limited`, local);
654
+ },
655
+ () => fail("failed", 1, `Local server not reachable: ${name}. Run stagepass doctor` + (lnaHintMessage(lnaState) ? ". " + lnaHintMessage(lnaState) : ""))
656
+ )
657
+ );
658
+ });
659
+ }
535
660
  const SKIP = [
536
661
  "data-stagepass",
537
662
  "data-stagepass-path",
@@ -558,19 +683,26 @@ var Stagepass = (() => {
558
683
  }
559
684
  const url = resolveAssetUrl(el, ps, lp);
560
685
  if (!url) return;
561
- const n = d.createElement(type);
686
+ const local = swap && lp && dom;
562
687
  const isScript = type === "script";
563
- if (isScript) n.src = url;
564
- else {
565
- n.rel = "stylesheet";
566
- n.href = url;
567
- }
568
- for (const a of Array.from(el.attributes)) {
569
- if (a.name !== srcAttr && !SKIP.includes(a.name) && (isScript || a.name !== "href")) {
570
- n.setAttribute(a.name, a.value);
688
+ const make = (cors) => {
689
+ const n2 = d.createElement(type);
690
+ if (cors) n2.crossOrigin = "anonymous";
691
+ if (isScript) n2.src = url;
692
+ else {
693
+ n2.rel = "stylesheet";
694
+ n2.href = url;
571
695
  }
572
- }
573
- if (isScript) applyScriptLoadOrder(n, el);
696
+ for (const a of Array.from(el.attributes)) {
697
+ if (a.name !== srcAttr && !SKIP.includes(a.name) && (isScript || a.name !== "href")) {
698
+ n2.setAttribute(a.name, a.value);
699
+ }
700
+ }
701
+ if (isScript) applyScriptLoadOrder(n2, el);
702
+ if (local) track(n2, ps, url, isScript, cors ? make : null);
703
+ return n2;
704
+ };
705
+ const n = make(!!local && !el.hasAttribute("crossorigin"));
574
706
  if (el.parentNode) {
575
707
  el.parentNode.insertBefore(n, el);
576
708
  el.remove();
@@ -586,16 +718,13 @@ var Stagepass = (() => {
586
718
  const seen = /* @__PURE__ */ new Map();
587
719
  swapEl("script[data-stagepass]", "data-src", "script", seen);
588
720
  swapEl('link[rel="stylesheet"][data-stagepass]', "data-href", "link", seen);
721
+ if (renderFlag) renderFlag();
589
722
  } catch (_) {
590
723
  }
591
724
  };
592
725
  let lnaCheck = null;
593
726
  const checkLna = () => lnaCheck = lnaCheck || (swap ? queryLoopbackPermission().then((state) => {
594
- const hint = lnaHintMessage(state);
595
- if (hint) {
596
- flagState.tip = hint;
597
- spWarn(hint);
598
- }
727
+ lnaState = state;
599
728
  }).catch(() => {
600
729
  }) : Promise.resolve());
601
730
  const run = () => {
@@ -1,2 +1,2 @@
1
- var Stagepass=(()=>{function A(t){if(typeof t!="string"||!t)return!1;if(t==="debug"||t==="localhost")return!0;if(t.startsWith("localhost:")){let n=t.slice(10);return/^[0-9]{1,5}$/.test(n)&&Number(n)<=65535}return/^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)*\.sp$/i.test(t)}function z(t){return t?t.replace(/^https?:\/\//i,"").replace(/\/$/,""):null}var ne="stagepass_domain",C=12;function se(t,n=Date.now()){if(!t||!t.startsWith("{"))return null;try{let o=JSON.parse(t);return typeof o.domain!="string"||typeof o.expires!="number"||!Number.isFinite(o.expires)||!A(o.domain)||o.expires<=n?null:{domain:o.domain,expires:o.expires}}catch{return null}}function oe(t,n=C,o=Date.now()){let i=Number.isFinite(n)&&n>0?n:C;return{domain:t,expires:o+i*60*60*1e3}}function re(t){return JSON.stringify(t)}function ie(t){if(t==null||t==="")return C;let n=Number(t);return!Number.isFinite(n)||n<=0?C:n}function ae(t,n,o){if(!t||typeof t!="string")return t;let i=encodeURIComponent(o),a=t.indexOf("#"),u=a>=0?t.slice(a):"",S=a>=0?t.slice(0,a):t,L=S.includes("?")?"&":"?";return`${S}${L}${encodeURIComponent(n)}=${i}${u}`}function U(t,n,o){let i=n.startsWith("/")?n.substring(1):n;return`https://${t}/${i}?_cb=${encodeURIComponent(String(o))}`}async function ce(){let t=typeof navigator<"u"?navigator.permissions:void 0;if(!t||typeof t.query!="function")return"unknown";let n=["loopback-network","local-network-access"];for(let o of n)try{let i=await t.query({name:o}),a=i&&i.state;if(a==="granted"||a==="prompt"||a==="denied")return a}catch{}return"unknown"}function le(t){return t==="prompt"?"Local network access is required. Allow local/loopback network access when Chrome prompts, then reload.":t==="denied"?"Local network access is blocked. Enable loopback/local network access for this site in Chrome settings, then reload.":null}function ue(t,n){let o=n.hasAttribute("async"),i=n.hasAttribute("defer");o?t.async=!0:(t.async=!1,i||(t.defer=!0))}function de(t){return!t||typeof t!="string"?[]:t.split(",").map(n=>n.trim().toLowerCase()).filter(Boolean)}function pe(t,n,o=[]){if(n&&n.endsWith(".sp"))return"local";let i=(t||"").toLowerCase();return i.endsWith(".webflow.io")||o.some(a=>a===i)?"staging":"production"}function ge(t){return!t||typeof t!="string"?!1:/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(t)}function fe(t,n){try{return typeof t[n]>"u"}catch{return!1}}var Oe=[["edge",/Edg\/(\d+)/],["opera",/OPR\/(\d+)/],["firefox",/Firefox\/(\d+)/],["chrome",/Chrome\/(\d+)/],["safari",/Version\/(\d+).+Safari\//]],Me=[["android",/Android/i],["ios",/iPhone|iPad|iPod/i],["macos",/Mac OS X|Macintosh/i],["windows",/Windows NT/i],["linux",/Linux/i]];function Pe(t){for(let[n,o]of Oe){let i=t.match(o);if(i)return{family:n,major:Number(i[1]),userAgent:t}}return{family:"unknown",major:null,userAgent:t}}function je(t){let n=Me.find(([,o])=>o.test(t));return{family:n?n[0]:"unknown"}}function Te(t){let n="ontouchstart"in window||(navigator.maxTouchPoints||0)>0,o="desktop";return/iPad|Tablet/i.test(t)?o="tablet":/Mobi|Android.+Mobile|iPhone/i.test(t)?o="mobile":/Android/i.test(t)&&n&&(o="tablet"),{type:o,touch:n}}function V(){let t=null;try{let n=o=>matchMedia(`(prefers-color-scheme: ${o})`).matches;t=n("dark")?"dark":n("light")?"light":null}catch{}return{preferred:t||"no-preference",current:t||"unknown"}}function me(t){try{let n=window[t],o="__stagepass_test__";return n.setItem(o,"1"),n.removeItem(o),!0}catch{return!1}}function Fe(){try{return typeof navigator<"u"&&"serviceWorker"in navigator}catch{return!1}}function he(){let t=navigator.userAgent||"",n=null;try{n=Intl.DateTimeFormat().resolvedOptions().timeZone||null}catch{}return{theme:V(),browser:Pe(t),os:je(t),device:Te(t),viewport:{width:window.innerWidth||0,height:window.innerHeight||0,dpr:window.devicePixelRatio||1},locale:{language:navigator.language||"unknown",timezone:n},capabilities:{cookiesEnabled:navigator.cookieEnabled===!0,localStorage:me("localStorage"),sessionStorage:me("sessionStorage")}}}function Se(t,n){let o=t.capabilities;switch(n){case"localStorage":return o.localStorage===!0;case"sessionStorage":return o.sessionStorage===!0;case"cookies":return o.cookiesEnabled===!0;case"serviceWorker":return Fe();default:return!1}}function be(t){if(!t||typeof t!="string")return null;let n=t.trim().match(/^(\d+)/);if(!n)return null;let o=Number(n[1]);return Number.isFinite(o)?o:null}function ye(t,n){let o=be(t),i=new Map;function a(u,S,L,v){if(!u||typeof u!="string")return n("stagepass.use: invalid module name"),!1;let g=be(S);if(o==null||g==null)return n(`stagepass.use: cannot parse version for module "${u}"`),!1;if(g!==o)return n(`Module "${u}" major ${g} does not match loader major ${o}. Skipping.`),!1;try{return L(v),i.set(u,S),!0}catch(N){return n(`Module "${u}" failed to register:`,N),!1}}return{use:a,registered:i}}(function(){let t=ne,n="stagepass",o=window,i=document,a=location,u="2.3.0-beta.2",S=/loader(?:\.min)?\.js/i;function L(){try{if(i.currentScript instanceof HTMLScriptElement)return i.currentScript}catch{}try{let e=i.querySelectorAll('script[src*="loader"]');for(let s=e.length-1;s>=0;s--)if(S.test(e[s].src||""))return e[s]}catch{}return null}let v=L(),g=e=>v?v.getAttribute("data-stagepass-"+e):null,N=g("mute-console")==="true",we=ie(g("session-hours")),ve=g("version"),q=de(g("staging-hosts")),k=g("alias"),$=new URLSearchParams(a.search);function ke(){try{let e=(new Error().stack||"").split(`
2
- `);for(let s=3;s<e.length;s++){let r=e[s].match(/([^/]+\.(?:js|ts))(?:[?#][^:]*)?:(\d+)/);if(r&&!S.test(r[1]))return` ${r[1]}:${r[2]}`}}catch{}return""}let f=!1,O={n:[0,0],tip:""},M=null,P=e=>{O.n[e]++,M&&M()};function E(e,...s){if(f){(e==="warn"||e==="error")&&P(e==="warn"?0:1);try{let r=ke(),p=`[\u{1F3AB} ${new Date().toTimeString().split(" ")[0]}${r?" |"+r:""}]`,l=console;e==="error"?l.log(`%c${p}`,"color:red;font-weight:bold",...s):l[e]?l[e](p,...s):l.log(p,e,...s)}catch{}}}function Ee(...e){let s=e[0]==="warn"||e[0]==="error"?e.shift():"log";E(s,...e)}let I=(...e)=>E("warn",...e),G=(...e)=>E("error",...e),j=(e,s)=>{let r=f;f=!0,E(e,s),f=r};function xe(){try{let e=localStorage.getItem(t),s=se(e);return!s&&e&&localStorage.removeItem(t),s?s.domain:null}catch{return null}}function T(){try{localStorage.removeItem(t)}catch{}}let B=!1,d=xe();if($.has(n)){let e=$.get(n);if(e==="off"||e==="0"||e==="false")T(),d=null,j("log","\u{1F50C} Stagepass disconnected.");else if(e){let s=e==="debug"?"debug":z(e);if(s&&A(s)){try{localStorage.setItem(t,re(oe(s,we)))}catch{}d=s,B=!0,j("log",s==="debug"?"\u{1F50D} Stagepass debug mode enabled.":`\u{1F50C} Stagepass connected to: ${s}`)}else s&&j("warn",`Invalid domain: ${s}. Only .sp domains are allowed.`)}try{$.delete(n);let s=$.toString();history.replaceState({},"",a.pathname+(s?`?${s}`:"")+a.hash)}catch{}}d&&!A(d)&&(T(),d=null);let R=d==="debug";f=!!d,d&&!B&&!R&&E("log",`\u{1F50C} Stagepass connected to: ${d}`);let K=!!d,m=K&&!R,b=m?z(d):null,J=m?Date.now():0,y=a.hostname,_e=y==="localhost"||y==="127.0.0.1"||y.startsWith("localhost:")||y.startsWith("127.0.0.1:"),Z=m||_e,Q=Z?"local":y.endsWith(".webflow.io")||q.includes(y.toLowerCase())?"staging":"production";if(N&&Q==="production"&&!f)try{console.log=console.warn=console.error=console.info=console.debug=()=>{}}catch{}let Y={theme:new Set,session:new Set},F=(e,s)=>Y[e].forEach(r=>{try{r(s)}catch{}}),x=he();try{let e=()=>F("theme",{...Object.assign(x.theme,V())});["dark","light"].forEach(s=>{let r=matchMedia(`(prefers-color-scheme: ${s})`);r.addEventListener?r.addEventListener("change",e):r.addListener&&r.addListener(e)})}catch{}o.addEventListener("resize",()=>{let e=x.viewport;e.width=o.innerWidth||0,e.height=o.innerHeight||0,e.dpr=o.devicePixelRatio||1});let c=o.stagepass||{},Le=ye(u,I);if(c.vars=Object.freeze({isLocal:Z,env:Q,domain:b||y,timestamp:J,version:u,client:x}),c.log=Ee,c.warn=I,c.error=G,c.resolveLocalUrl=e=>m&&b&&e?U(b,e,c.vars.timestamp||Date.now()):"",c.env=()=>pe(y,b,q),c.is=e=>c.env()===e,c.can=e=>Se(x,e),c.client=e=>e==null||e===""?x:x[e],c.on=(e,s)=>{let r=Y[e];return!r||e!=="theme"&&e!=="session"?()=>{}:(r.add(s),()=>{r.delete(s)})},c.use=(e,s,r)=>Le.use(e,s,r,c),o.stagepass=o.sp=c,globalThis.stagepass=globalThis.sp=c,k&&ge(k)&&k!=="sp"&&k!=="stagepass"&&[o,globalThis].forEach(e=>{fe(e,k)&&(e[k]=c)}),K)try{let e=Symbol.for("stagepass.flag");Object.defineProperty(c,e,{configurable:!0,value:p=>{delete c[e];try{M=p(R?"DEBUG":"LOCAL",b,O,()=>{T(),f=!0,E("log","\u{1F50C} Stagepass disconnected."),F("session",{active:!1,domain:null,swap:!1,debug:!1}),a.reload()})}catch{}}}),o.addEventListener("error",()=>P(1),!0),o.addEventListener("unhandledrejection",()=>P(1));let s=v&&v.src||"",r=i.createElement("script");r.src=/\/loader(?:\.min)?\.js$/i.test(s.split(/[?#]/)[0])?new URL("flag.min.js",s).href:`https://cdn.jsdelivr.net/npm/@stagepass/loader@${u}/dist/flag.min.js`,r.async=!0,r.onerror=()=>I("Stagepass flag could not be loaded: "+r.src),(i.head||i.documentElement).appendChild(r)}catch{}F("session",{active:f,domain:d,swap:m,debug:R});function Ie(e,s,r){if(m&&r&&b)return U(b,r,J);let p=e.getAttribute("data-stagepass-v")||ve;return p?ae(s,"v",p):s}function Ae(e){try{let s=new URL(e).pathname.split("/");return s[s.length-1]||s[s.length-2]||null}catch{let r=e.match(/\/([^\/\?#]+)(?:\?|#|$)/);return r?r[1]:null}}let $e=["data-stagepass","data-stagepass-path","data-stagepass-cachebust","data-stagepass-v"];function X(e,s,r,p){i.querySelectorAll(`${e}:not([data-stagepass-processed])`).forEach(l=>{try{l.setAttribute("data-stagepass-processed","true");let h=l.getAttribute("data-stagepass-path"),Ne=!!h,D=l.getAttribute(s);if(!D)return;if(!h&&m&&b&&(h=Ae(D)),m&&h&&!Ne&&f){let w=(p.get(h)||0)+1;p.set(h,w),w===2&&I(`Multiple assets resolve to local file "${h}" without data-stagepass-path. Set unique paths to avoid collisions.`)}let W=Ie(l,D,h);if(!W)return;let _=i.createElement(r),H=r==="script";H?_.src=W:(_.rel="stylesheet",_.href=W);for(let w of Array.from(l.attributes))w.name!==s&&!$e.includes(w.name)&&(H||w.name!=="href")&&_.setAttribute(w.name,w.value);H&&ue(_,l),l.parentNode?(l.parentNode.insertBefore(_,l),l.remove()):G(`${r} injection failed: No parent node`)}catch{}})}let Re=()=>{try{let e=new Map;X("script[data-stagepass]","data-src","script",e),X('link[rel="stylesheet"][data-stagepass]',"data-href","link",e)}catch{}},ee=null,Ce=()=>ee=ee||(m?ce().then(e=>{let s=le(e);s&&(O.tip=s,I(s))}).catch(()=>{}):Promise.resolve()),te=()=>{Ce().then(Re)};te(),i.readyState==="loading"&&i.addEventListener("DOMContentLoaded",te)})();})();
1
+ var Stagepass=(()=>{function P(t){if(typeof t!="string"||!t)return!1;if(t==="debug"||t==="localhost")return!0;if(t.startsWith("localhost:")){let s=t.slice(10);return/^[0-9]{1,5}$/.test(s)&&Number(s)<=65535}return/^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)*\.sp$/i.test(t)}function Y(t){return t?t.replace(/^https?:\/\//i,"").replace(/\/$/,""):null}var Se="stagepass_domain",U=12;function ye(t,s=Date.now()){if(!t||!t.startsWith("{"))return null;try{let r=JSON.parse(t);return typeof r.domain!="string"||typeof r.expires!="number"||!Number.isFinite(r.expires)||!P(r.domain)||r.expires<=s?null:{domain:r.domain,expires:r.expires}}catch{return null}}function be(t,s=U,r=Date.now()){let c=Number.isFinite(s)&&s>0?s:U;return{domain:t,expires:r+c*60*60*1e3}}function we(t){return JSON.stringify(t)}function ke(t){if(t==null||t==="")return U;let s=Number(t);return!Number.isFinite(s)||s<=0?U:s}function ve(t,s,r){if(!t||typeof t!="string")return t;let c=encodeURIComponent(r),f=t.indexOf("#"),h=f>=0?t.slice(f):"",E=f>=0?t.slice(0,f):t,N=E.includes("?")?"&":"?";return`${E}${N}${encodeURIComponent(s)}=${c}${h}`}function X(t,s,r){let c=s.startsWith("/")?s.substring(1):s;return`https://${t}/${c}?_cb=${encodeURIComponent(String(r))}`}async function Ee(){let t=typeof navigator<"u"?navigator.permissions:void 0;if(!t||typeof t.query!="function")return"unknown";let s=["loopback-network","local-network-access"];for(let r of s)try{let c=await t.query({name:r}),f=c&&c.state;if(f==="granted"||f==="prompt"||f==="denied")return f}catch{}return"unknown"}function ee(t){return t==="prompt"?"Local network access is required. Allow local/loopback network access when Chrome prompts, then reload.":t==="denied"?"Local network access is blocked. Enable loopback/local network access for this site in Chrome settings, then reload.":null}function xe(t,s){let r=s.hasAttribute("async"),c=s.hasAttribute("defer");r?t.async=!0:(t.async=!1,c||(t.defer=!0))}function _e(t){return!t||typeof t!="string"?[]:t.split(",").map(s=>s.trim().toLowerCase()).filter(Boolean)}function Le(t,s,r=[]){if(s&&s.endsWith(".sp"))return"local";let c=(t||"").toLowerCase();return c.endsWith(".webflow.io")||r.some(f=>f===c)?"staging":"production"}function $e(t){return!t||typeof t!="string"?!1:/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(t)}function Ae(t,s){try{return typeof t[s]>"u"}catch{return!1}}var Ke=[["edge",/Edg\/(\d+)/],["opera",/OPR\/(\d+)/],["firefox",/Firefox\/(\d+)/],["chrome",/Chrome\/(\d+)/],["safari",/Version\/(\d+).+Safari\//]],Ze=[["android",/Android/i],["ios",/iPhone|iPad|iPod/i],["macos",/Mac OS X|Macintosh/i],["windows",/Windows NT/i],["linux",/Linux/i]];function Qe(t){for(let[s,r]of Ke){let c=t.match(r);if(c)return{family:s,major:Number(c[1]),userAgent:t}}return{family:"unknown",major:null,userAgent:t}}function Ye(t){let s=Ze.find(([,r])=>r.test(t));return{family:s?s[0]:"unknown"}}function Xe(t){let s="ontouchstart"in window||(navigator.maxTouchPoints||0)>0,r="desktop";return/iPad|Tablet/i.test(t)?r="tablet":/Mobi|Android.+Mobile|iPhone/i.test(t)?r="mobile":/Android/i.test(t)&&s&&(r="tablet"),{type:r,touch:s}}function te(){let t=null;try{let s=r=>matchMedia(`(prefers-color-scheme: ${r})`).matches;t=s("dark")?"dark":s("light")?"light":null}catch{}return{preferred:t||"no-preference",current:t||"unknown"}}function Ie(t){try{let s=window[t],r="__stagepass_test__";return s.setItem(r,"1"),s.removeItem(r),!0}catch{return!1}}function et(){try{return typeof navigator<"u"&&"serviceWorker"in navigator}catch{return!1}}function Oe(){let t=navigator.userAgent||"",s=null;try{s=Intl.DateTimeFormat().resolvedOptions().timeZone||null}catch{}return{theme:te(),browser:Qe(t),os:Ye(t),device:Xe(t),viewport:{width:window.innerWidth||0,height:window.innerHeight||0,dpr:window.devicePixelRatio||1},locale:{language:navigator.language||"unknown",timezone:s},capabilities:{cookiesEnabled:navigator.cookieEnabled===!0,localStorage:Ie("localStorage"),sessionStorage:Ie("sessionStorage")}}}function Re(t,s){let r=t.capabilities;switch(s){case"localStorage":return r.localStorage===!0;case"sessionStorage":return r.sessionStorage===!0;case"cookies":return r.cookiesEnabled===!0;case"serviceWorker":return et();default:return!1}}function Ne(t){if(!t||typeof t!="string")return null;let s=t.trim().match(/^(\d+)/);if(!s)return null;let r=Number(s[1]);return Number.isFinite(r)?r:null}function Ce(t,s){let r=Ne(t),c=new Map;function f(h,E,N,$){if(!h||typeof h!="string")return s("stagepass.use: invalid module name"),!1;let k=Ne(E);if(r==null||k==null)return s(`stagepass.use: cannot parse version for module "${h}"`),!1;if(k!==r)return s(`Module "${h}" major ${k} does not match loader major ${r}. Skipping.`),!1;try{return N($),c.set(h,E),!0}catch(V){return s(`Module "${h}" failed to register:`,V),!1}}return{use:f,registered:c}}(function(){let t=Se,s="stagepass",r=window,c=document,f=location,h="2.3.0-beta.4",E=/loader(?:\.min)?\.js/i;function N(){try{if(c.currentScript instanceof HTMLScriptElement)return c.currentScript}catch{}try{let e=c.querySelectorAll('script[src*="loader"]');for(let n=e.length-1;n>=0;n--)if(E.test(e[n].src||""))return e[n]}catch{}return null}let $=N(),k=e=>$?$.getAttribute("data-stagepass-"+e):null,V=k("mute-console")==="true",je=ke(k("session-hours")),Fe=k("version"),ne=_e(k("staging-hosts")),A=k("alias"),T=new URLSearchParams(f.search),v=!1,x={n:[0,0],m:[],f:[],swapped:0,v:h},C=null,se=()=>C&&C(),re=()=>new Date().toTimeString().slice(0,8),D=e=>(e||"").split(/[?#]/)[0].split("/").pop()||"",q=(e,n)=>e.length>n?e.slice(0,n)+"\u2026":e,oe=(e,n=0)=>{try{if(typeof e=="string")return n?JSON.stringify(e):e;if(e instanceof Error)return e.name+": "+e.message;if(!e||typeof e!="object")return String(e);if(e instanceof Node)return"<"+e.nodeName.toLowerCase()+">";let o=Array.isArray(e);if(n>2)return o?"[\u2026]":"{\u2026}";let u=Object.keys(e),i=u.slice(0,20).map(a=>(o?"":a+": ")+oe(e[a],n+1));return u.length>20&&i.push("\u2026"),q(o?"["+i.join(", ")+"]":"{"+i.join(", ")+"}",1e3)}catch{return"[unserializable]"}},G=(e,n=0)=>{let o=(e||"").split(`
2
+ `);for(let u=n;u<o.length;u++){let i=o[u].match(/([a-z][\w+.-]*:\/\/[^\s()]+?):(\d+):(\d+)/i);if(i&&!E.test(D(i[1])))return[i[1],i[2],i[3]]}return null},y=null,Me=e=>e?y&&!e.indexOf(`https://${y}/`)?"local":"live":"external",I=(e,n,o="",u="",i="",a="",d)=>{x.n[e]++;let l=x.m,m={type:e?"error":"warn",time:re(),src:d||(o?Me(o):""),file:D(o),url:o.split(/[?#]/)[0],line:u?String(u):"",col:i?String(i):"",text:q(n,500),stack:q(a,2e3),c:1},S=p=>p.type+p.text+p.url+p.line+p.col;for(let p=l.length-1;p>=0;p--)if(S(l[p])===S(m)){m.c=l[p].c+1,l.splice(p,1);break}l.push(m),l.length>50&&l.shift(),se()},B=(e,n,o,u)=>{let i=o.find(l=>l instanceof Error),a=i&&i.stack||"",d=G(a)||u;I(e,n+o.map(l=>oe(l)).join(" "),d?d[0]:"",d?d[1]:"",d?d[2]:"",a)},j=!1,Pe=e=>{j=!0;try{e()}catch{}j=!1};function O(e,...n){if(!v)return;let o=G(new Error().stack||"",3);(e==="warn"||e==="error")&&B(e==="warn"?0:1,"",n,o),Pe(()=>{let u=`[\u{1F3AB} ${re()}${o?" | "+D(o[0])+":"+o[1]:""}]`,i=console;e==="error"?i.log(`%c${u}`,"color:red;font-weight:bold",...n):i[e]?i[e](u,...n):i.log(u,e,...n)})}function Te(...e){let n=e[0]==="warn"||e[0]==="error"?e.shift():"log";O(n,...e)}let W=(...e)=>O("warn",...e),ie=(...e)=>O("error",...e),J=(e,n)=>{let o=v;v=!0,O(e,n),v=o};function De(){try{let e=localStorage.getItem(t),n=ye(e);return!n&&e&&localStorage.removeItem(t),n?n.domain:null}catch{return null}}function K(){try{localStorage.removeItem(t)}catch{}}let ae=!1,b=De();if(T.has(s)){let e=T.get(s);if(e==="off"||e==="0"||e==="false")K(),b=null,J("log","\u{1F50C} Stagepass disconnected.");else if(e){let n=e==="debug"?"debug":Y(e);if(n&&P(n)){try{localStorage.setItem(t,we(be(n,je)))}catch{}b=n,ae=!0,J("log",n==="debug"?"\u{1F50D} Stagepass debug mode enabled.":`\u{1F50C} Stagepass connected to: ${n}`)}else n&&J("warn",`Invalid domain: ${n}. Only .sp domains are allowed.`)}try{T.delete(s);let n=T.toString();history.replaceState({},"",f.pathname+(n?`?${n}`:"")+f.hash)}catch{}}b&&!P(b)&&(K(),b=null);let H=b==="debug";v=!!b,b&&!ae&&!H&&O("log",`\u{1F50C} Stagepass connected to: ${b}`);let ce=!!b,w=ce&&!H;y=w?Y(b):null;let le=w?Date.now():0,_=f.hostname,We=_==="localhost"||_==="127.0.0.1"||_.startsWith("localhost:")||_.startsWith("127.0.0.1:"),ue=w||We,de=ue?"local":_.endsWith(".webflow.io")||ne.includes(_.toLowerCase())?"staging":"production";if(V&&de==="production"&&!v)try{console.log=console.warn=console.error=console.info=console.debug=()=>{}}catch{}let fe={theme:new Set,session:new Set},Z=(e,n)=>fe[e].forEach(o=>{try{o(n)}catch{}}),R=Oe();try{let e=()=>Z("theme",{...Object.assign(R.theme,te())});["dark","light"].forEach(n=>{let o=matchMedia(`(prefers-color-scheme: ${n})`);o.addEventListener?o.addEventListener("change",e):o.addListener&&o.addListener(e)})}catch{}r.addEventListener("resize",()=>{let e=R.viewport;e.width=r.innerWidth||0,e.height=r.innerHeight||0,e.dpr=r.devicePixelRatio||1});let g=r.stagepass||{},He=Ce(h,W);if(g.vars=Object.freeze({isLocal:ue,env:de,domain:y||_,timestamp:le,version:h,client:R}),g.log=Te,g.warn=W,g.error=ie,g.resolveLocalUrl=e=>w&&y&&e?X(y,e,g.vars.timestamp||Date.now()):"",g.env=()=>Le(_,y,ne),g.is=e=>g.env()===e,g.can=e=>Re(R,e),g.client=e=>e==null||e===""?R:R[e],g.on=(e,n)=>{let o=fe[e];return!o||e!=="theme"&&e!=="session"?()=>{}:(o.add(n),()=>{o.delete(n)})},g.use=(e,n,o)=>He.use(e,n,o,g),r.stagepass=r.sp=g,globalThis.stagepass=globalThis.sp=g,A&&$e(A)&&A!=="sp"&&A!=="stagepass"&&[r,globalThis].forEach(e=>{Ae(e,A)&&(e[A]=g)}),ce)try{let e=Symbol.for("stagepass.flag.v2"),n=$&&$.src||"",o=/\/loader(?:\.min)?\.js$/i.test(n.split(/[?#]/)[0])?new URL("./",n).href:`https://cdn.jsdelivr.net/npm/@stagepass/loader@${h}/dist/`;Object.assign(x,{debug:H,domain:y,card:o+"flag-card.min.js",end:()=>{K(),v=!0,O("log","\u{1F50C} Stagepass disconnected."),Z("session",{active:!1,domain:null,swap:!1,debug:!1}),f.reload()}}),Object.defineProperty(g,e,{configurable:!0,value:a=>{delete g[e];try{C=a(x)}catch{}}}),r.addEventListener("error",a=>{let d=a.target,l=d&&d!==r&&(d.src||d.href);typeof l=="string"?ge.has(d)||I(1,"Failed to load "+l.split(/[?#]/)[0],l):/^Script error\.?$/.test(a.message||"")&&!a.filename?I(1,"Error in a cross-origin script (details only in DevTools console)","","","","","external"):I(1,a.message||"Script error",a.filename||"",a.lineno,a.colno,a.error&&a.error.stack||"")},!0),r.addEventListener("unhandledrejection",a=>B(1,"Unhandled rejection: ",[a.reason],null));let u=console;["warn","error"].forEach((a,d)=>{let l=u[a];typeof l=="function"&&(u[a]=function(...m){if(!j){j=!0;try{B(d,"",m,G(new Error().stack||"",2))}catch{}j=!1}return l.apply(this,m)})});let i=c.createElement("script");i.src=o+"flag.min.js",i.async=!0,i.onerror=()=>W("Stagepass flag could not be loaded: "+i.src),(c.head||c.documentElement).appendChild(i)}catch{}Z("session",{active:v,domain:b,swap:w,debug:H});function ze(e,n,o){if(w&&o&&y)return X(y,o,le);let u=e.getAttribute("data-stagepass-v")||Fe;return u?ve(n,"v",u):n}function Ue(e){try{let n=new URL(e).pathname.split("/");return n[n.length-1]||n[n.length-2]||null}catch{let o=e.match(/\/([^\/\?#]+)(?:\?|#|$)/);return o?o[1]:null}}let ge=new WeakSet,Q="";function Ve(e,n,o,u,i){let a={live:n,local:o,type:u?"js":"css",st:""},d=D(o);ge.add(e),x.f.push(a),e.addEventListener("load",()=>{a.st="ok",x.swapped++,se()}),e.addEventListener("error",()=>{let l=(S,p,z)=>{a.st=S,I(p,z,o)},m=r.fetch;if(typeof m!="function")return l("failed",1,`Failed to load ${d}`);m(o,{method:"HEAD",cache:"no-store"}).then(S=>l(S.ok?"failed":String(S.status),1,S.ok?`Failed to load ${d}`:`Local file not found (${S.status}): ${d}`),()=>m(o,{method:"HEAD",mode:"no-cors",cache:"no-store"}).then(()=>{if(!i)return l("failed",1,`Failed to load ${d}`);x.f.splice(x.f.indexOf(a),1),e.replaceWith(i(!1)),I(0,`Local server sends no CORS header for ${d}. Loaded without crossorigin, error details are limited`,o)},()=>l("failed",1,`Local server not reachable: ${d}. Run stagepass doctor`+(ee(Q)?". "+ee(Q):""))))})}let qe=["data-stagepass","data-stagepass-path","data-stagepass-cachebust","data-stagepass-v"];function pe(e,n,o,u){c.querySelectorAll(`${e}:not([data-stagepass-processed])`).forEach(i=>{try{i.setAttribute("data-stagepass-processed","true");let a=i.getAttribute("data-stagepass-path"),d=!!a,l=i.getAttribute(n);if(!l)return;if(!a&&w&&y&&(a=Ue(l)),w&&a&&!d&&v){let F=(u.get(a)||0)+1;u.set(a,F),F===2&&W(`Multiple assets resolve to local file "${a}" without data-stagepass-path. Set unique paths to avoid collisions.`)}let m=ze(i,l,a);if(!m)return;let S=w&&a&&y,p=o==="script",z=F=>{let L=c.createElement(o);F&&(L.crossOrigin="anonymous"),p?L.src=m:(L.rel="stylesheet",L.href=m);for(let M of Array.from(i.attributes))M.name!==n&&!qe.includes(M.name)&&(p||M.name!=="href")&&L.setAttribute(M.name,M.value);return p&&xe(L,i),S&&Ve(L,l,m,p,F?z:null),L},Je=z(!!S&&!i.hasAttribute("crossorigin"));i.parentNode?(i.parentNode.insertBefore(Je,i),i.remove()):ie(`${o} injection failed: No parent node`)}catch{}})}let Ge=()=>{try{let e=new Map;pe("script[data-stagepass]","data-src","script",e),pe('link[rel="stylesheet"][data-stagepass]',"data-href","link",e),C&&C()}catch{}},me=null,Be=()=>me=me||(w?Ee().then(e=>{Q=e}).catch(()=>{}):Promise.resolve()),he=()=>{Be().then(Ge)};he(),c.readyState==="loading"&&c.addEventListener("DOMContentLoaded",he)})();})();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stagepass/loader",
3
- "version": "2.3.0-beta.2",
3
+ "version": "2.3.0-beta.4",
4
4
  "description": "Universal loader for Stagepass - injects local files into Webflow projects",
5
5
  "main": "dist/loader.min.js",
6
6
  "types": "global.d.ts",