@stagepass/loader 2.5.0 → 2.5.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 +11 -5
- package/dist/loader.js +12 -5
- package/dist/loader.min.js +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -12,16 +12,18 @@ npm install @stagepass/loader@2
|
|
|
12
12
|
|
|
13
13
|
## CDN Usage
|
|
14
14
|
|
|
15
|
-
Prefer
|
|
15
|
+
Prefer an exact pin on the Stagepass CDN in production. Stagepass follows strict semver: no breaking changes within v2; breaking changes only in a new major (v3). Use the full file path (this host has no `/dist/` segment). See [Version pinning](https://github.com/stagepass-one/os/blob/master/docs/loader.md#version-pinning) in the docs.
|
|
16
16
|
|
|
17
17
|
```html
|
|
18
18
|
<script
|
|
19
|
-
src="https://cdn.
|
|
19
|
+
src="https://cdn.stagepass.one/loader@2.5.0/loader.min.js"
|
|
20
20
|
data-stagepass-version="2.5.0"
|
|
21
21
|
></script>
|
|
22
22
|
```
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
Always embed the full file path; the short form `https://cdn.stagepass.one/loader@2.5.0` serves the same loader bytes, but a script tag at that URL resolves session chunks from the CDN root and they 404. Or set `data-stagepass-flag-base`.
|
|
25
|
+
|
|
26
|
+
jsDelivr is the documented alternative: `https://cdn.jsdelivr.net/npm/@stagepass/loader@2/dist/loader.min.js`. That host may cache `@2` for a while; purge with `https://purge.jsdelivr.net/npm/@stagepass/loader@2/dist/loader.min.js`.
|
|
25
27
|
|
|
26
28
|
## Known limits (scoped acceptance)
|
|
27
29
|
|
|
@@ -68,7 +70,7 @@ See [MIGRATION.md](../../MIGRATION.md) for breaking changes from 1.x.
|
|
|
68
70
|
| `data-src` / `data-href` | Production URL for legacy mode (default). Required unless live-src opt-in uses native `src` / `href`. |
|
|
69
71
|
| `data-stagepass-path` | Local path under the linked project root (optional). |
|
|
70
72
|
| `data-stagepass-v` | Per-asset production `?v=<version>` (overrides loader `data-stagepass-version`). |
|
|
71
|
-
| `data-stagepass-nocache` | Requires loader **2.5.0** or later (older loaders ignore the attribute; the asset then loads cached as before). Boolean (present, or `="true"`; `="false"` turns it off). Production only: sets exactly one fresh `?_cb=<timestamp>` on **this asset's** URL on every page view, for every visitor. An existing `_cb` is replaced (never a second one). Combines with `data-stagepass-v` / `data-stagepass-version` as original query (without `_cb`), then `?v=<version>`, then `_cb`. No effect during an active local/dev swap session (local assets already get a per-page-load `_cb` stamp). Not applied to `data-stagepass-live-src="true"` assets, which stay untouched in production by design. |
|
|
73
|
+
| `data-stagepass-nocache` | Available in published loader **2.5.0** (npm `latest`). Requires loader **2.5.0** or later (older loaders ignore the attribute; the asset then loads cached as before). Boolean (present, or `="true"`; `="false"` turns it off). Production only: sets exactly one fresh `?_cb=<timestamp>` on **this asset's** URL on every page view, for every visitor. An existing `_cb` is replaced (never a second one). Combines with `data-stagepass-v` / `data-stagepass-version` as original query (without `_cb`), then `?v=<version>`, then `_cb`. No effect during an active local/dev swap session (local assets already get a per-page-load `_cb` stamp). Not applied to `data-stagepass-live-src="true"` assets, which stay untouched in production by design. |
|
|
72
74
|
| `data-stagepass-cachebust` | Legacy; ignored for production timestamps in v2. |
|
|
73
75
|
| `data-stagepass-processed` | Internal; set after processing. |
|
|
74
76
|
|
|
@@ -84,6 +86,10 @@ After handling, `?stagepass=` is removed with `history.replaceState` (other quer
|
|
|
84
86
|
|
|
85
87
|
Storage key: `localStorage.stagepass_domain` → JSON `{ "domain": "…", "expires": <ms> }`. Legacy plain-string values are cleared.
|
|
86
88
|
|
|
89
|
+
## Privacy / storage
|
|
90
|
+
|
|
91
|
+
The loader sets no cookies. On each load it reads the `localStorage` key `stagepass_domain` and removes that key only when the value is stale or invalid. It writes `stagepass_domain` only when a preview session is started via `?stagepass=` (`off`, `0`, and `false` remove the key). While a session is active, the flag UI may write `stagepass:expand`, `stagepass:prev`, and `stagepass:flash`. Storage capability is probed lazily, only when `sp.can('localStorage')`, `sp.can('sessionStorage')`, or `sp.vars.client.capabilities.localStorage` / `.sessionStorage` is used.
|
|
92
|
+
|
|
87
93
|
## Dev flag
|
|
88
94
|
|
|
89
95
|
Shown only while a session is active (including debug).
|
|
@@ -111,7 +117,7 @@ Opt-in with `data-stagepass-live-src="true"` on the loader tag (loader **2.4.0**
|
|
|
111
117
|
|
|
112
118
|
## Permanent per-asset cache busting
|
|
113
119
|
|
|
114
|
-
`data-stagepass-nocache` requires loader **2.5.0** or later (older loaders ignore the attribute; the asset then loads cached as before). It is for the rare asset that must be fetched fresh on every page view, for every production visitor, not just during a Stagepass session. Typical case: a script that embeds third-party forms via iframes, where a stale cached copy breaks the embed.
|
|
120
|
+
`data-stagepass-nocache` is available in published loader **2.5.0** (npm `latest`). It requires loader **2.5.0** or later (older loaders ignore the attribute; the asset then loads cached as before). It is for the rare asset that must be fetched fresh on every page view, for every production visitor, not just during a Stagepass session. Typical case: a script that embeds third-party forms via iframes, where a stale cached copy breaks the embed.
|
|
115
121
|
|
|
116
122
|
```html
|
|
117
123
|
<script
|
package/dist/loader.js
CHANGED
|
@@ -190,14 +190,16 @@ var Stagepass = (() => {
|
|
|
190
190
|
return { preferred: v || "no-preference", current: v || "unknown" };
|
|
191
191
|
}
|
|
192
192
|
function hasStorage(type) {
|
|
193
|
+
const cache = hasStorage;
|
|
194
|
+
if (type in cache) return cache[type];
|
|
193
195
|
try {
|
|
194
196
|
const storage = window[type];
|
|
195
197
|
const key = "__stagepass_test__";
|
|
196
198
|
storage.setItem(key, "1");
|
|
197
199
|
storage.removeItem(key);
|
|
198
|
-
return true;
|
|
200
|
+
return cache[type] = true;
|
|
199
201
|
} catch (_) {
|
|
200
|
-
return false;
|
|
202
|
+
return cache[type] = false;
|
|
201
203
|
}
|
|
202
204
|
}
|
|
203
205
|
function hasServiceWorker() {
|
|
@@ -230,8 +232,13 @@ var Stagepass = (() => {
|
|
|
230
232
|
},
|
|
231
233
|
capabilities: {
|
|
232
234
|
cookiesEnabled: navigator.cookieEnabled === true,
|
|
233
|
-
|
|
234
|
-
|
|
235
|
+
// First read probes. `can()` hits the same getter, so the result is shared.
|
|
236
|
+
get localStorage() {
|
|
237
|
+
return hasStorage("localStorage");
|
|
238
|
+
},
|
|
239
|
+
get sessionStorage() {
|
|
240
|
+
return hasStorage("sessionStorage");
|
|
241
|
+
}
|
|
235
242
|
}
|
|
236
243
|
};
|
|
237
244
|
}
|
|
@@ -297,7 +304,7 @@ var Stagepass = (() => {
|
|
|
297
304
|
const W = window;
|
|
298
305
|
const d = document;
|
|
299
306
|
const loc = location;
|
|
300
|
-
const PKG_VERSION = true ? "2.5.
|
|
307
|
+
const PKG_VERSION = true ? "2.5.1" : "0.0.0";
|
|
301
308
|
const LOADER_RE = /loader(?:\.min)?\.js/i;
|
|
302
309
|
function flagBase(v, file) {
|
|
303
310
|
if (typeof v !== "string" || !(v = v.trim())) return null;
|
package/dist/loader.min.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var Stagepass=(()=>{function N(t){return typeof t!="string"||!t?!1:t==="debug"||t==="localhost"?!0:t.startsWith("localhost:")?(t=t.slice(10),/^[1-9]\d{0,4}$/.test(t)&&+t<65536):/^[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 se(t){return t?t.replace(/^https?:\/\//i,"").replace(/\/$/,""):null}var
|
|
2
|
-
`);for(let
|
|
1
|
+
var Stagepass=(()=>{function N(t){return typeof t!="string"||!t?!1:t==="debug"||t==="localhost"?!0:t.startsWith("localhost:")?(t=t.slice(10),/^[1-9]\d{0,4}$/.test(t)&&+t<65536):/^[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 se(t){return t?t.replace(/^https?:\/\//i,"").replace(/\/$/,""):null}var $e="stagepass_domain",V=12;function Oe(t,s=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)||!N(o.domain)||o.expires<=s?null:{domain:o.domain,expires:o.expires}}catch{return null}}function Ce(t,s=V,o=Date.now()){let i=Number.isFinite(s)&&s>0?s:V;return{domain:t,expires:o+i*60*60*1e3}}function Ie(t){return JSON.stringify(t)}function Re(t){if(t==null||t==="")return V;let s=Number(t);return!Number.isFinite(s)||s<=0?V:s}function oe(t,s,o){if(!t||typeof t!="string")return t;let i=encodeURIComponent(o),g=t.indexOf("#"),b=g>=0?t.slice(g):"",v=g>=0?t.slice(0,g):t;s==="_cb"&&(v=v.replace(/\?.*/,j=>j.replace(/[&?]_cb(=[^&]*)?(?=&|$)/g,"").replace(/^&/,"?")));let $=v.includes("?")?"&":"?";return`${v}${$}${encodeURIComponent(s)}=${i}${b}`}function q(t,s,o){let i=s.startsWith("/")?s.slice(1):s;return`https://${t}/${i}?_cb=${o}`}async function Ne(){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 o of s)try{let i=await t.query({name:o}),g=i&&i.state;if(g==="granted"||g==="prompt"||g==="denied")return g}catch{}return"unknown"}function ae(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 je(t,s){let o=s.hasAttribute("async"),i=s.hasAttribute("defer");o?t.async=!0:(t.async=!1,i||(t.defer=!0))}var B="data-stagepass-nocache";function Fe(t){return t.hasAttribute(B)?t.getAttribute(B)!=="false":!1}function Te(t){return!t||typeof t!="string"?[]:t.split(",").map(s=>s.trim().toLowerCase()).filter(Boolean)}function Pe(t,s,o=[]){if(s&&s.endsWith(".sp"))return"local";let i=(t||"").toLowerCase();return i.endsWith(".webflow.io")||o.some(g=>g===i)?"staging":"production"}function Me(t){return!t||typeof t!="string"?!1:/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(t)}function De(t,s){try{return typeof t[s]>"u"}catch{return!1}}var rt=[["edge",/Edg\/(\d+)/],["opera",/OPR\/(\d+)/],["firefox",/Firefox\/(\d+)/],["chrome",/Chrome\/(\d+)/],["safari",/Version\/(\d+).+Safari\//]],st=[["android",/Android/i],["ios",/iPhone|iPad|iPod/i],["macos",/Mac OS X|Macintosh/i],["windows",/Windows NT/i],["linux",/Linux/i]];function ot(t){for(let[s,o]of rt){let i=t.match(o);if(i)return{family:s,major:Number(i[1]),userAgent:t}}return{family:"unknown",major:null,userAgent:t}}function at(t){let s=st.find(([,o])=>o.test(t));return{family:s?s[0]:"unknown"}}function it(t){let s="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)&&s&&(o="tablet"),{type:o,touch:s}}function ce(){let t=null;try{let s=o=>matchMedia(`(prefers-color-scheme: ${o})`).matches;t=s("dark")?"dark":s("light")?"light":null}catch{}return{preferred:t||"no-preference",current:t||"unknown"}}function ie(t){let s=ie;if(t in s)return s[t];try{let o=window[t],i="__stagepass_test__";return o.setItem(i,"1"),o.removeItem(i),s[t]=!0}catch{return s[t]=!1}}function ct(){try{return typeof navigator<"u"&&"serviceWorker"in navigator}catch{return!1}}function He(){let t=navigator.userAgent||"",s=null;try{s=Intl.DateTimeFormat().resolvedOptions().timeZone||null}catch{}return{theme:ce(),browser:ot(t),os:at(t),device:it(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,get localStorage(){return ie("localStorage")},get sessionStorage(){return ie("sessionStorage")}}}}function We(t,s){let o=t.capabilities;switch(s){case"localStorage":return o.localStorage===!0;case"sessionStorage":return o.sessionStorage===!0;case"cookies":return o.cookiesEnabled===!0;case"serviceWorker":return ct();default:return!1}}function ze(t){if(!t||typeof t!="string")return null;let s=t.trim().match(/^(\d+)/);if(!s)return null;let o=Number(s[1]);return Number.isFinite(o)?o:null}function Ue(t,s){let o=ze(t),i=new Map;function g(b,v,$,j){if(!b||typeof b!="string")return s("stagepass.use: invalid module name"),!1;let x=ze(v);if(o==null||x==null)return s(`stagepass.use: cannot parse version for module "${b}"`),!1;if(x!==o)return s(`Module "${b}" major ${x} does not match loader major ${o}. Skipping.`),!1;try{return $(j),i.set(b,v),!0}catch(k){return s(`Module "${b}" failed to register:`,k),!1}}return{use:g,registered:i}}(function(){let t=$e,s="stagepass",o=window,i=document,g=location,b="2.5.1",v=/loader(?:\.min)?\.js/i;function $(e,n){if(typeof e!="string"||!(e=e.trim()))return null;try{let r=new URL(e,i.baseURI);return!/^https?:$/.test(r.protocol)||r.username||r.password?null:(r.search=r.hash="",n?new URL("./",r).href:r.href.replace(/\/?$/,"/"))}catch{return null}}function j(){try{if(i.currentScript instanceof HTMLScriptElement)return i.currentScript}catch{}try{let e=i.querySelectorAll('script[src*="loader"]');for(let n=e.length-1;n>=0;n--)if(v.test(e[n].src||""))return e[n]}catch{}return null}let x=j(),k=e=>x?x.getAttribute("data-stagepass-"+e):null,Ve=k("mute-console")==="true",qe=Re(k("session-hours")),Be=k("version"),le=Te(k("staging-hosts")),O=k("alias"),ue=k("live-src")==="true",H=new URLSearchParams(g.search),_=!1,A={n:[0,0],m:[],f:[],swapped:0,v:b,vd:N},F=null,fe=()=>F&&F(),de=()=>new Date().toTimeString().slice(0,8),W=e=>(e||"").split(/[?#]/)[0].split("/").pop()||"",z=(e,n)=>e.length>n?e.slice(0,n)+"\u2026":e,ge=(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 r=Array.isArray(e);if(n>2)return r?"[\u2026]":"{\u2026}";let c=Object.keys(e),a=c.slice(0,20).map(l=>(r?"":l+": ")+ge(e[l],n+1));return c.length>20&&a.push("\u2026"),z(r?"["+a.join(", ")+"]":"{"+a.join(", ")+"}",1e3)}catch{return"[unserializable]"}},G=(e,n=0)=>{let r=(e||"").split(`
|
|
2
|
+
`);for(let c=n;c<r.length;c++){let a=r[c].match(/([a-z][\w+.-]*:\/\/[^\s()]+?):(\d+):(\d+)/i);if(a&&!v.test(W(a[1])))return[a[1],a[2],a[3]]}return null},h=null,Ge=e=>e?h&&!e.indexOf(`https://${h}/`)?"local":"live":"external",C=(e,n,r="",c="",a="",l="",u)=>{A.n[e]++;let f=A.m,m={type:e?"error":"warn",time:de(),src:u||(r?Ge(r):""),file:W(r),url:r.split(/[?#]/)[0],line:c?String(c):"",col:a?String(a):"",text:z(n,500),stack:z(l,2e3),c:1},y=d=>d.type+d.text+d.url+d.line+d.col;for(let d=f.length-1;d>=0;d--)if(y(f[d])===y(m)){m.c=f[d].c+1,f.splice(d,1);break}f.push(m),f.length>50&&f.shift(),fe()},J=(e,n,r,c)=>{let a=r.find(f=>f instanceof Error),l=a&&a.stack||"",u=G(l)||c;C(e,n+r.map(f=>ge(f)).join(" "),u?u[0]:"",u?u[1]:"",u?u[2]:"",l)},T=!1,Je=e=>{T=!0;try{e()}catch{}T=!1};function I(e,...n){if(!_)return;let r=G(new Error().stack||"",3);(e==="warn"||e==="error")&&J(e==="warn"?0:1,"",n,r),Je(()=>{let c=`[\u{1F3AB} ${de()}${r?" | "+W(r[0])+":"+r[1]:""}]`,a=console;e==="error"?a.log(`%c${c}`,"color:red;font-weight:bold",...n):a[e]?a[e](c,...n):a.log(c,e,...n)})}function Ke(...e){let n=e[0]==="warn"||e[0]==="error"?e.shift():"log";I(n,...e)}let P=(...e)=>I("warn",...e),pe=(...e)=>I("error",...e),K=(e,n)=>{let r=_;_=!0,I(e,n),_=r};function Ze(){try{let e=localStorage.getItem(t),n=Oe(e);return!n&&e&&localStorage.removeItem(t),n?n.domain:null}catch{return null}}function Z(){try{localStorage.removeItem(t)}catch{}}let me=!1,S=Ze();if(H.has(s)){let e=H.get(s);if(e==="off"||e==="0"||e==="false")Z(),S=null,K("log","\u{1F50C} Stagepass disconnected.");else if(e){let n=e==="debug"?"debug":se(e);if(n&&N(n)){try{localStorage.setItem(t,Ie(Ce(n,qe)))}catch{}S=n,me=!0,K("log",n==="debug"?"\u{1F50D} Stagepass debug mode enabled.":`\u{1F50C} Stagepass connected to: ${n}`)}else n&&K("warn",`Invalid domain: ${n}. Only .sp domains are allowed.`)}try{H.delete(s);let n=H.toString();history.replaceState({},"",g.pathname+(n?`?${n}`:"")+g.hash)}catch{}}S&&!N(S)&&(Z(),S=null);let M=S==="debug";_=!!S,S&&!me&&!M&&I("log",`\u{1F50C} Stagepass connected to: ${S}`);let he=!!S,w=he&&!M;h=w?se(S):null;let Q=w?Date.now():0,L=g.hostname,Qe=L==="localhost"||L==="127.0.0.1"||L.startsWith("localhost:")||L.startsWith("127.0.0.1:"),be=w||Qe,Se=be?"local":L.endsWith(".webflow.io")||le.includes(L.toLowerCase())?"staging":"production";if(Ve&&Se==="production"&&!_)try{console.log=console.warn=console.error=console.info=console.debug=()=>{}}catch{}let ye={theme:new Set,session:new Set},Y=(e,n)=>ye[e].forEach(r=>{try{r(n)}catch{}}),R=He();try{let e=()=>Y("theme",{...Object.assign(R.theme,ce())});["dark","light"].forEach(n=>{let r=matchMedia(`(prefers-color-scheme: ${n})`);r.addEventListener?r.addEventListener("change",e):r.addListener&&r.addListener(e)})}catch{}o.addEventListener("resize",()=>{let e=R.viewport;e.width=o.innerWidth||0,e.height=o.innerHeight||0,e.dpr=o.devicePixelRatio||1});let p=o.stagepass||{},Ye=Ue(b,P),we=Object.freeze({isLocal:be,env:Se,domain:h||L,timestamp:Q,version:b,client:R});if(p.vars=we,p.log=Ke,p.warn=P,p.error=pe,p.resolveLocalUrl=e=>w&&h&&e?q(h,e,we.timestamp||Date.now()):"",p.env=()=>Pe(L,h,le),p.is=e=>p.env()===e,p.can=e=>We(R,e),p.client=e=>e==null||e===""?R:R[e],p.on=(e,n)=>{let r=ye[e];return!r||e!=="theme"&&e!=="session"?()=>{}:(r.add(n),()=>{r.delete(n)})},p.use=(e,n,r)=>Ye.use(e,n,r,p),o.stagepass=o.sp=p,globalThis.stagepass=globalThis.sp=p,O&&Me(O)&&O!=="sp"&&O!=="stagepass"&&[o,globalThis].forEach(e=>{De(e,O)&&(e[O]=p)}),he)try{let e=Symbol.for("stagepass.flag.v2"),n=k("flag-base")??o.stagepassFlagBase,r=$(n,!1);n!=null&&!r&&P("Ignored flag base (http(s) or relative only): "+z(String(n),99)),r=r||$(x&&x.src||"",!0),r||(r=`https://cdn.jsdelivr.net/npm/@stagepass/loader@${b}/dist/`,M&&P("Loader URL unknown, flag loads from "+r+". Set data-stagepass-flag-base")),Object.assign(A,{debug:M,domain:h,card:r+"flag-card.min.js",end:()=>{Z(),_=!0,I("log","\u{1F50C} Stagepass disconnected."),Y("session",{active:!1,domain:null,swap:!1,debug:!1}),g.reload()}}),Object.defineProperty(p,e,{configurable:!0,value:l=>{delete p[e];try{F=l(A)}catch{}}}),o.addEventListener("error",l=>{let u=l.target,f=u&&u!==o&&(u.src||u.href);typeof f=="string"?ke.has(u)||C(1,"Failed to load "+f.split(/[?#]/)[0],f):/^Script error\.?$/.test(l.message||"")&&!l.filename?C(1,"Error in a cross-origin script (details only in DevTools console)","","","","","external"):C(1,l.message||"Script error",l.filename||"",l.lineno,l.colno,l.error&&l.error.stack||"")},!0),o.addEventListener("unhandledrejection",l=>J(1,"Unhandled rejection: ",[l.reason],null));let c=console;["warn","error"].forEach((l,u)=>{let f=c[l];typeof f=="function"&&(c[l]=function(...m){if(!T){T=!0;try{J(u,"",m,G(new Error().stack||"",2))}catch{}T=!1}return f.apply(this,m)})});let a=i.createElement("script");a.src=r+"flag.min.js",a.async=!0,a.onerror=()=>P("Stagepass flag could not be loaded: "+a.src),(i.head||i.documentElement).appendChild(a)}catch{}Y("session",{active:_,domain:S,swap:w,debug:M});function Xe(e,n,r){if(w&&r&&h)return q(h,r,Q);let c=e.getAttribute("data-stagepass-v")||Be,a=c?oe(n,"v",c):n;return Fe(e)&&(a=oe(a,"_cb",Date.now())),a}function ve(e){try{let n=new URL(e).pathname.split("/");return n[n.length-1]||n[n.length-2]||null}catch{let r=e.match(/\/([^\/\?#]+)(?:\?|#|$)/);return r?r[1]:null}}let ke=new WeakSet,X="";function Ee(e,n,r,c,a,l){let u={live:n,local:r,type:c?"js":"css",st:""};l&&(u.x=!0);let f=W(r);ke.add(e),A.f.push(u),e.addEventListener("load",()=>{u.st="ok",A.swapped++,fe()}),e.addEventListener("error",()=>{let m=(d,re,U)=>{u.st=d,C(re,U,r)},y=o.fetch;if(typeof y!="function")return m("failed",1,`Failed to load ${f}`);y(r,{method:"HEAD",cache:"no-store"}).then(d=>m(d.ok?"failed":String(d.status),1,d.ok?`Failed to load ${f}`:`Local file not found (${d.status}): ${f}`),()=>y(r,{method:"HEAD",mode:"no-cors",cache:"no-store"}).then(()=>{if(!a)return m("failed",1,`Failed to load ${f}`);A.f.splice(A.f.indexOf(u),1),e.replaceWith(a(!1)),C(0,`Local server sends no CORS header for ${f}. Loaded without crossorigin, error details are limited`,r)},()=>m("failed",1,`Local server not reachable: ${f}. Run stagepass doctor`+(ae(X)?". "+ae(X):""))))})}let et=["data-stagepass","data-stagepass-path","data-stagepass-cachebust","data-stagepass-v",B],ee='script[data-stagepass][src]:not([data-src]):not([data-stagepass-processed]),link[rel="stylesheet" i][data-stagepass][href]:not([data-href]):not([data-stagepass-processed])',xe="onbeforescriptexecute"in i;function _e(e){try{let n=e.tagName==="SCRIPT";if(n&&(xe||i.currentScript===e))return;let r=n?"src":"href",c=e.getAttribute(r);if(!c)return;e.setAttribute("data-stagepass-processed","true");let a=e.getAttribute("data-stagepass-path"),l=a||ve(c);if(!l)return;let u=q(h,l,Q);e.removeAttribute("integrity"),e.hasAttribute("crossorigin")||e.setAttribute("crossorigin","anonymous"),e[r]=u,Ee(e,c,u,n,null,!!a)}catch{}}let te=e=>{try{e.matches&&e.matches(ee)&&_e(e),e.querySelectorAll(ee).forEach(_e)}catch{}};function ne(e,n,r){i.querySelectorAll(`${e}:not([data-stagepass-processed])`).forEach(c=>{try{let a=c.getAttribute("data-stagepass-path"),l=!!a,u=c.getAttribute(n);if(!u)return;c.setAttribute("data-stagepass-processed","true"),!a&&w&&h&&(a=ve(u));let f=Xe(c,u,a);if(!f)return;let m=w&&a&&h,y=r==="script",d=U=>{let E=i.createElement(r);U&&(E.crossOrigin="anonymous"),y?E.src=f:(E.rel="stylesheet",E.href=f);for(let D of Array.from(c.attributes))D.name!==n&&!et.includes(D.name)&&D.name!==(y?"src":"href")&&E.setAttribute(D.name,D.value);return m&&E.removeAttribute("integrity"),y&&je(E,c),m&&Ee(E,u,f,y,U?d:null,l),E},re=d(!!m&&!c.hasAttribute("crossorigin"));c.parentNode?(c.parentNode.insertBefore(re,c),c.remove()):pe(`${r} injection failed: No parent node`)}catch{}})}if(w&&ue)try{new MutationObserver(e=>{for(let n of e)for(let r of n.addedNodes)r.nodeType===1&&te(r)}).observe(i.documentElement,{childList:!0,subtree:!0}),xe&&i.addEventListener("beforescriptexecute",e=>{let n=e.target;if(!n||!n.matches||!n.matches(ee))return;let r=n.getAttribute("src");!r||r.indexOf("https://"+h+"/")===0||(e.preventDefault(),n.setAttribute("data-src",r),n.removeAttribute("src"),ne("script[data-stagepass]","data-src","script"))},!0),te(i)}catch{}let tt=()=>{try{ne("script[data-stagepass]","data-src","script"),ne('link[rel="stylesheet"][data-stagepass]',"data-href","link"),w&&ue&&te(i),F&&F()}catch{}},Ae=null,nt=()=>Ae=Ae||(w?Ne().then(e=>{X=e}).catch(()=>{}):Promise.resolve()),Le=()=>{nt().then(tt)};Le(),i.readyState==="loading"&&i.addEventListener("DOMContentLoaded",Le)})();})();
|