@stagepass/loader 2.5.0 → 2.5.2
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 +28 -13
- package/dist/loader.js +15 -6
- package/dist/loader.min.js +2 -2
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -12,16 +12,24 @@ npm install @stagepass/loader@2
|
|
|
12
12
|
|
|
13
13
|
## CDN Usage
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
Default embed on the Stagepass CDN is the major alias (strict semver: no breaking changes within v2). See [Version pinning](https://github.com/stagepass-one/os/blob/master/docs/loader.md#version-pinning) in the docs.
|
|
16
|
+
|
|
17
|
+
```html
|
|
18
|
+
<script src="https://cdn.stagepass.one/loader@2"></script>
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Loader **2.5.2** and later resolves session chunks (`flag.min.js`, `flag-card.min.js`, `live.min.js`) from that folder URL. The CDN also 302-redirects root `/flag.min.js` (and the other two) to `/loader@2/<file>` as a compatibility shim. Or set `data-stagepass-flag-base`.
|
|
22
|
+
|
|
23
|
+
Exact pin when a specific build must load (optional `data-stagepass-version` for production `?v=` on tagged assets):
|
|
16
24
|
|
|
17
25
|
```html
|
|
18
26
|
<script
|
|
19
|
-
src="https://cdn.
|
|
20
|
-
data-stagepass-version="2.5.
|
|
27
|
+
src="https://cdn.stagepass.one/loader@2.5.1/loader.min.js"
|
|
28
|
+
data-stagepass-version="2.5.1"
|
|
21
29
|
></script>
|
|
22
30
|
```
|
|
23
31
|
|
|
24
|
-
|
|
32
|
+
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
33
|
|
|
26
34
|
## Known limits (scoped acceptance)
|
|
27
35
|
|
|
@@ -29,7 +37,7 @@ Acceptance for `live.min.js` / live reload is **scoped localhost only**. It is n
|
|
|
29
37
|
|
|
30
38
|
A `localhost` / `localhost:<port>` session still reports `sp.env() === 'production'` (unchanged since 2.3.1 / 2.3.3). Only an active `*.sp` swap session is `local`. That is expected behaviour, not a live-reload failure.
|
|
31
39
|
|
|
32
|
-
`live.min.js` ships since loader **2.4.0** (lazy-loaded during an active swap session; not in **2.3.3**). `@2` is a major range alias, not the npm `latest` tag; after a publish the CDN can briefly serve the previous 2.x build. Pin an exact version (e.g. `@2.5.
|
|
40
|
+
`live.min.js` ships since loader **2.4.0** (lazy-loaded during an active swap session; not in **2.3.3**). `@2` is a major range alias, not the npm `latest` tag; after a publish the CDN can briefly serve the previous 2.x build. Pin an exact version (e.g. `@2.5.1`) when a specific build must load.
|
|
33
41
|
|
|
34
42
|
See [MIGRATION.md](../../MIGRATION.md) for breaking changes from 1.x.
|
|
35
43
|
|
|
@@ -68,8 +76,8 @@ See [MIGRATION.md](../../MIGRATION.md) for breaking changes from 1.x.
|
|
|
68
76
|
| `data-src` / `data-href` | Production URL for legacy mode (default). Required unless live-src opt-in uses native `src` / `href`. |
|
|
69
77
|
| `data-stagepass-path` | Local path under the linked project root (optional). |
|
|
70
78
|
| `data-stagepass-v` | Per-asset production `?v=<version>` (overrides loader `data-stagepass-version`). |
|
|
71
|
-
| `data-stagepass-nocache` |
|
|
72
|
-
| `data-stagepass-cachebust` | Legacy;
|
|
79
|
+
| `data-stagepass-nocache` | Available in published loader **2.5.0** and later. 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). Query order with version busting: original query (without `_cb`), then `v` from `data-stagepass-v` / `data-stagepass-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. |
|
|
80
|
+
| `data-stagepass-cachebust` | Legacy; **not** a per-asset opt-in and **does not** timestamp every production view in v2. Use `data-stagepass-nocache` for permanent per-asset busting. |
|
|
73
81
|
| `data-stagepass-processed` | Internal; set after processing. |
|
|
74
82
|
|
|
75
83
|
## URL Modes
|
|
@@ -84,6 +92,10 @@ After handling, `?stagepass=` is removed with `history.replaceState` (other quer
|
|
|
84
92
|
|
|
85
93
|
Storage key: `localStorage.stagepass_domain` → JSON `{ "domain": "…", "expires": <ms> }`. Legacy plain-string values are cleared.
|
|
86
94
|
|
|
95
|
+
## Privacy / storage
|
|
96
|
+
|
|
97
|
+
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. The result of `sp.can('localStorage')` and `sp.can('sessionStorage')` is computed once per page load and cached, including when storage is unavailable. It is not retried until the next page load.
|
|
98
|
+
|
|
87
99
|
## Dev flag
|
|
88
100
|
|
|
89
101
|
Shown only while a session is active (including debug).
|
|
@@ -107,26 +119,29 @@ Shown only while a session is active (including debug).
|
|
|
107
119
|
|
|
108
120
|
## Zero-cost production mode
|
|
109
121
|
|
|
110
|
-
Opt-in with `data-stagepass-live-src="true"` on the loader tag (loader **2.4.0** and later). Put a normal `src` / `href` (optional `integrity` + `crossorigin`) on `data-stagepass` assets instead of `data-src` / `data-href`. Without a session the browser loads those URLs directly; with a session Stagepass rewrites them to the local `.sp` host before classic scripts run (loader must be a sync script in `<head>` before the assets). Legacy `data-src` / `data-href` stays the default and keeps working. See [Zero-cost production mode](https://github.com/
|
|
122
|
+
Opt-in with `data-stagepass-live-src="true"` on the loader tag (loader **2.4.0** and later). Put a normal `src` / `href` (optional `integrity` + `crossorigin`) on `data-stagepass` assets instead of `data-src` / `data-href`. Without a session the browser loads those URLs directly; with a session Stagepass rewrites them to the local `.sp` host before classic scripts run (loader must be a sync script in `<head>` before the assets). Legacy `data-src` / `data-href` stays the default and keeps working. See [Zero-cost production mode](https://github.com/stagepass-one/os/blob/master/docs/loader.md#zero-cost-production-mode) for migration, SRI, and limitations.
|
|
111
123
|
|
|
112
124
|
## Permanent per-asset cache busting
|
|
113
125
|
|
|
114
|
-
`data-stagepass-nocache`
|
|
126
|
+
`data-stagepass-nocache` is available in published loader **2.5.0** and later (older loaders ignore the attribute). 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
127
|
|
|
116
128
|
```html
|
|
117
129
|
<script
|
|
118
130
|
data-stagepass
|
|
119
|
-
data-src="https://cdn.example.com/js/forms-embed.js"
|
|
131
|
+
data-src="https://cdn.example.com/js/forms-embed.js?foo=1#_section"
|
|
132
|
+
data-stagepass-v="2.5.1"
|
|
120
133
|
data-stagepass-nocache
|
|
121
134
|
></script>
|
|
135
|
+
<!-- production URL becomes:
|
|
136
|
+
https://cdn.example.com/js/forms-embed.js?foo=1&v=2.5.1&_cb=<timestamp>#_section -->
|
|
122
137
|
```
|
|
123
138
|
|
|
124
139
|
- Boolean attribute: present (any value, including empty) or `="true"` turns it on; `="false"` turns it off (same as omitting it).
|
|
125
140
|
- Scoped to exactly that asset. All other `data-stagepass` assets keep the existing version-only cache strategy.
|
|
126
|
-
-
|
|
141
|
+
- Query order: keep the original query **without** `_cb`, then append `v` when `data-stagepass-v` / `data-stagepass-version` is set, then exactly one `_cb=<Date.now()>`. An existing `_cb` is replaced (never a second one). Other query keys and the hash stay preserved.
|
|
127
142
|
- Production only. During an active local/dev swap session the asset resolves to the local `.sp` URL as usual (single `?_cb=<timestamp>` per page load, same as every other swapped file). `data-stagepass-nocache` has no extra effect there.
|
|
128
143
|
- Not applied to `data-stagepass-live-src="true"` assets: that mode is intentionally zero-cost (untouched by the loader in production), so pair an asset that needs permanent busting with the default `data-src` / `data-href` mode instead.
|
|
129
|
-
- `data-stagepass-cachebust`
|
|
144
|
+
- `data-stagepass-cachebust` is legacy and unrelated: it does **not** timestamp every production view in v2 and is **not** a per-asset opt-in. Use `data-stagepass-nocache` for that.
|
|
130
145
|
|
|
131
146
|
## Runtime API
|
|
132
147
|
|
|
@@ -174,4 +189,4 @@ With an active session (or debug), the loader warns when two tagged assets resol
|
|
|
174
189
|
|
|
175
190
|
## Repository
|
|
176
191
|
|
|
177
|
-
- Full docs and examples: [stagepass repository](https://github.com/
|
|
192
|
+
- Full docs and examples: [stagepass repository](https://github.com/stagepass-one/os)
|
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.2" : "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;
|
|
@@ -570,7 +577,9 @@ var Stagepass = (() => {
|
|
|
570
577
|
const opt = attr("flag-base") ?? W.stagepassFlagBase;
|
|
571
578
|
let base = flagBase(opt, false);
|
|
572
579
|
if (opt != null && !base) spWarn("Ignored flag base (http(s) or relative only): " + cut(String(opt), 99));
|
|
573
|
-
|
|
580
|
+
const src = loaderScript && loaderScript.src || "";
|
|
581
|
+
const file = fileOf(src);
|
|
582
|
+
base = base || flagBase(src, LOADER_RE.test(file) || /\.js$/i.test(file));
|
|
574
583
|
if (!base) {
|
|
575
584
|
base = `https://cdn.jsdelivr.net/npm/@stagepass/loader@${PKG_VERSION}/dist/`;
|
|
576
585
|
if (debug) spWarn("Loader URL unknown, flag loads from " + base + ". Set data-stagepass-flag-base");
|
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
|
|
2
|
-
`);for(let i=n;i<
|
|
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 re(t){return t?t.replace(/^https?:\/\//i,"").replace(/\/$/,""):null}var $e="stagepass_domain",q=12;function Oe(t,r=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<=r?null:{domain:o.domain,expires:o.expires}}catch{return null}}function Ce(t,r=q,o=Date.now()){let a=Number.isFinite(r)&&r>0?r:q;return{domain:t,expires:o+a*60*60*1e3}}function Ie(t){return JSON.stringify(t)}function Re(t){if(t==null||t==="")return q;let r=Number(t);return!Number.isFinite(r)||r<=0?q:r}function oe(t,r,o){if(!t||typeof t!="string")return t;let a=encodeURIComponent(o),g=t.indexOf("#"),S=g>=0?t.slice(g):"",w=g>=0?t.slice(0,g):t;r==="_cb"&&(w=w.replace(/\?.*/,j=>j.replace(/[&?]_cb(=[^&]*)?(?=&|$)/g,"").replace(/^&/,"?")));let $=w.includes("?")?"&":"?";return`${w}${$}${encodeURIComponent(r)}=${a}${S}`}function B(t,r,o){let a=r.startsWith("/")?r.slice(1):r;return`https://${t}/${a}?_cb=${o}`}async function Ne(){let t=typeof navigator<"u"?navigator.permissions:void 0;if(!t||typeof t.query!="function")return"unknown";let r=["loopback-network","local-network-access"];for(let o of r)try{let a=await t.query({name:o}),g=a&&a.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,r){let o=r.hasAttribute("async"),a=r.hasAttribute("defer");o?t.async=!0:(t.async=!1,a||(t.defer=!0))}var G="data-stagepass-nocache";function Fe(t){return t.hasAttribute(G)?t.getAttribute(G)!=="false":!1}function Te(t){return!t||typeof t!="string"?[]:t.split(",").map(r=>r.trim().toLowerCase()).filter(Boolean)}function Pe(t,r,o=[]){if(r&&r.endsWith(".sp"))return"local";let a=(t||"").toLowerCase();return a.endsWith(".webflow.io")||o.some(g=>g===a)?"staging":"production"}function Me(t){return!t||typeof t!="string"?!1:/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(t)}function De(t,r){try{return typeof t[r]>"u"}catch{return!1}}var st=[["edge",/Edg\/(\d+)/],["opera",/OPR\/(\d+)/],["firefox",/Firefox\/(\d+)/],["chrome",/Chrome\/(\d+)/],["safari",/Version\/(\d+).+Safari\//]],rt=[["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[r,o]of st){let a=t.match(o);if(a)return{family:r,major:Number(a[1]),userAgent:t}}return{family:"unknown",major:null,userAgent:t}}function at(t){let r=rt.find(([,o])=>o.test(t));return{family:r?r[0]:"unknown"}}function it(t){let r="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)&&r&&(o="tablet"),{type:o,touch:r}}function ce(){let t=null;try{let r=o=>matchMedia(`(prefers-color-scheme: ${o})`).matches;t=r("dark")?"dark":r("light")?"light":null}catch{}return{preferred:t||"no-preference",current:t||"unknown"}}function ie(t){let r=ie;if(t in r)return r[t];try{let o=window[t],a="__stagepass_test__";return o.setItem(a,"1"),o.removeItem(a),r[t]=!0}catch{return r[t]=!1}}function ct(){try{return typeof navigator<"u"&&"serviceWorker"in navigator}catch{return!1}}function He(){let t=navigator.userAgent||"",r=null;try{r=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:r},capabilities:{cookiesEnabled:navigator.cookieEnabled===!0,get localStorage(){return ie("localStorage")},get sessionStorage(){return ie("sessionStorage")}}}}function We(t,r){let o=t.capabilities;switch(r){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 r=t.trim().match(/^(\d+)/);if(!r)return null;let o=Number(r[1]);return Number.isFinite(o)?o:null}function Ue(t,r){let o=ze(t),a=new Map;function g(S,w,$,j){if(!S||typeof S!="string")return r("stagepass.use: invalid module name"),!1;let x=ze(w);if(o==null||x==null)return r(`stagepass.use: cannot parse version for module "${S}"`),!1;if(x!==o)return r(`Module "${S}" major ${x} does not match loader major ${o}. Skipping.`),!1;try{return $(j),a.set(S,w),!0}catch(k){return r(`Module "${S}" failed to register:`,k),!1}}return{use:g,registered:a}}(function(){let t=$e,r="stagepass",o=window,a=document,g=location,S="2.5.2",w=/loader(?:\.min)?\.js/i;function $(e,n){if(typeof e!="string"||!(e=e.trim()))return null;try{let s=new URL(e,a.baseURI);return!/^https?:$/.test(s.protocol)||s.username||s.password?null:(s.search=s.hash="",n?new URL("./",s).href:s.href.replace(/\/?$/,"/"))}catch{return null}}function j(){try{if(a.currentScript instanceof HTMLScriptElement)return a.currentScript}catch{}try{let e=a.querySelectorAll('script[src*="loader"]');for(let n=e.length-1;n>=0;n--)if(w.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",W=new URLSearchParams(g.search),_=!1,A={n:[0,0],m:[],f:[],swapped:0,v:S,vd:N},F=null,fe=()=>F&&F(),de=()=>new Date().toTimeString().slice(0,8),T=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 s=Array.isArray(e);if(n>2)return s?"[\u2026]":"{\u2026}";let i=Object.keys(e),c=i.slice(0,20).map(h=>(s?"":h+": ")+ge(e[h],n+1));return i.length>20&&c.push("\u2026"),z(s?"["+c.join(", ")+"]":"{"+c.join(", ")+"}",1e3)}catch{return"[unserializable]"}},J=(e,n=0)=>{let s=(e||"").split(`
|
|
2
|
+
`);for(let i=n;i<s.length;i++){let c=s[i].match(/([a-z][\w+.-]*:\/\/[^\s()]+?):(\d+):(\d+)/i);if(c&&!w.test(T(c[1])))return[c[1],c[2],c[3]]}return null},b=null,Ge=e=>e?b&&!e.indexOf(`https://${b}/`)?"local":"live":"external",C=(e,n,s="",i="",c="",h="",u)=>{A.n[e]++;let l=A.m,d={type:e?"error":"warn",time:de(),src:u||(s?Ge(s):""),file:T(s),url:s.split(/[?#]/)[0],line:i?String(i):"",col:c?String(c):"",text:z(n,500),stack:z(h,2e3),c:1},m=f=>f.type+f.text+f.url+f.line+f.col;for(let f=l.length-1;f>=0;f--)if(m(l[f])===m(d)){d.c=l[f].c+1,l.splice(f,1);break}l.push(d),l.length>50&&l.shift(),fe()},K=(e,n,s,i)=>{let c=s.find(l=>l instanceof Error),h=c&&c.stack||"",u=J(h)||i;C(e,n+s.map(l=>ge(l)).join(" "),u?u[0]:"",u?u[1]:"",u?u[2]:"",h)},P=!1,Je=e=>{P=!0;try{e()}catch{}P=!1};function I(e,...n){if(!_)return;let s=J(new Error().stack||"",3);(e==="warn"||e==="error")&&K(e==="warn"?0:1,"",n,s),Je(()=>{let i=`[\u{1F3AB} ${de()}${s?" | "+T(s[0])+":"+s[1]:""}]`,c=console;e==="error"?c.log(`%c${i}`,"color:red;font-weight:bold",...n):c[e]?c[e](i,...n):c.log(i,e,...n)})}function Ke(...e){let n=e[0]==="warn"||e[0]==="error"?e.shift():"log";I(n,...e)}let M=(...e)=>I("warn",...e),pe=(...e)=>I("error",...e),Z=(e,n)=>{let s=_;_=!0,I(e,n),_=s};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 Q(){try{localStorage.removeItem(t)}catch{}}let me=!1,y=Ze();if(W.has(r)){let e=W.get(r);if(e==="off"||e==="0"||e==="false")Q(),y=null,Z("log","\u{1F50C} Stagepass disconnected.");else if(e){let n=e==="debug"?"debug":re(e);if(n&&N(n)){try{localStorage.setItem(t,Ie(Ce(n,qe)))}catch{}y=n,me=!0,Z("log",n==="debug"?"\u{1F50D} Stagepass debug mode enabled.":`\u{1F50C} Stagepass connected to: ${n}`)}else n&&Z("warn",`Invalid domain: ${n}. Only .sp domains are allowed.`)}try{W.delete(r);let n=W.toString();history.replaceState({},"",g.pathname+(n?`?${n}`:"")+g.hash)}catch{}}y&&!N(y)&&(Q(),y=null);let D=y==="debug";_=!!y,y&&!me&&!D&&I("log",`\u{1F50C} Stagepass connected to: ${y}`);let he=!!y,v=he&&!D;b=v?re(y):null;let Y=v?Date.now():0,L=g.hostname,Qe=L==="localhost"||L==="127.0.0.1"||L.startsWith("localhost:")||L.startsWith("127.0.0.1:"),be=v||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},X=(e,n)=>ye[e].forEach(s=>{try{s(n)}catch{}}),R=He();try{let e=()=>X("theme",{...Object.assign(R.theme,ce())});["dark","light"].forEach(n=>{let s=matchMedia(`(prefers-color-scheme: ${n})`);s.addEventListener?s.addEventListener("change",e):s.addListener&&s.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(S,M),we=Object.freeze({isLocal:be,env:Se,domain:b||L,timestamp:Y,version:S,client:R});if(p.vars=we,p.log=Ke,p.warn=M,p.error=pe,p.resolveLocalUrl=e=>v&&b&&e?B(b,e,we.timestamp||Date.now()):"",p.env=()=>Pe(L,b,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 s=ye[e];return!s||e!=="theme"&&e!=="session"?()=>{}:(s.add(n),()=>{s.delete(n)})},p.use=(e,n,s)=>Ye.use(e,n,s,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,s=$(n,!1);n!=null&&!s&&M("Ignored flag base (http(s) or relative only): "+z(String(n),99));let i=x&&x.src||"",c=T(i);s=s||$(i,w.test(c)||/\.js$/i.test(c)),s||(s=`https://cdn.jsdelivr.net/npm/@stagepass/loader@${S}/dist/`,D&&M("Loader URL unknown, flag loads from "+s+". Set data-stagepass-flag-base")),Object.assign(A,{debug:D,domain:b,card:s+"flag-card.min.js",end:()=>{Q(),_=!0,I("log","\u{1F50C} Stagepass disconnected."),X("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 d=l.target,m=d&&d!==o&&(d.src||d.href);typeof m=="string"?ke.has(d)||C(1,"Failed to load "+m.split(/[?#]/)[0],m):/^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=>K(1,"Unhandled rejection: ",[l.reason],null));let h=console;["warn","error"].forEach((l,d)=>{let m=h[l];typeof m=="function"&&(h[l]=function(...f){if(!P){P=!0;try{K(d,"",f,J(new Error().stack||"",2))}catch{}P=!1}return m.apply(this,f)})});let u=a.createElement("script");u.src=s+"flag.min.js",u.async=!0,u.onerror=()=>M("Stagepass flag could not be loaded: "+u.src),(a.head||a.documentElement).appendChild(u)}catch{}X("session",{active:_,domain:y,swap:v,debug:D});function Xe(e,n,s){if(v&&s&&b)return B(b,s,Y);let i=e.getAttribute("data-stagepass-v")||Be,c=i?oe(n,"v",i):n;return Fe(e)&&(c=oe(c,"_cb",Date.now())),c}function ve(e){try{let n=new URL(e).pathname.split("/");return n[n.length-1]||n[n.length-2]||null}catch{let s=e.match(/\/([^\/\?#]+)(?:\?|#|$)/);return s?s[1]:null}}let ke=new WeakSet,ee="";function Ee(e,n,s,i,c,h){let u={live:n,local:s,type:i?"js":"css",st:""};h&&(u.x=!0);let l=T(s);ke.add(e),A.f.push(u),e.addEventListener("load",()=>{u.st="ok",A.swapped++,fe()}),e.addEventListener("error",()=>{let d=(f,U,V)=>{u.st=f,C(U,V,s)},m=o.fetch;if(typeof m!="function")return d("failed",1,`Failed to load ${l}`);m(s,{method:"HEAD",cache:"no-store"}).then(f=>d(f.ok?"failed":String(f.status),1,f.ok?`Failed to load ${l}`:`Local file not found (${f.status}): ${l}`),()=>m(s,{method:"HEAD",mode:"no-cors",cache:"no-store"}).then(()=>{if(!c)return d("failed",1,`Failed to load ${l}`);A.f.splice(A.f.indexOf(u),1),e.replaceWith(c(!1)),C(0,`Local server sends no CORS header for ${l}. Loaded without crossorigin, error details are limited`,s)},()=>d("failed",1,`Local server not reachable: ${l}. Run stagepass doctor`+(ae(ee)?". "+ae(ee):""))))})}let et=["data-stagepass","data-stagepass-path","data-stagepass-cachebust","data-stagepass-v",G],te='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 a;function _e(e){try{let n=e.tagName==="SCRIPT";if(n&&(xe||a.currentScript===e))return;let s=n?"src":"href",i=e.getAttribute(s);if(!i)return;e.setAttribute("data-stagepass-processed","true");let c=e.getAttribute("data-stagepass-path"),h=c||ve(i);if(!h)return;let u=B(b,h,Y);e.removeAttribute("integrity"),e.hasAttribute("crossorigin")||e.setAttribute("crossorigin","anonymous"),e[s]=u,Ee(e,i,u,n,null,!!c)}catch{}}let ne=e=>{try{e.matches&&e.matches(te)&&_e(e),e.querySelectorAll(te).forEach(_e)}catch{}};function se(e,n,s){a.querySelectorAll(`${e}:not([data-stagepass-processed])`).forEach(i=>{try{let c=i.getAttribute("data-stagepass-path"),h=!!c,u=i.getAttribute(n);if(!u)return;i.setAttribute("data-stagepass-processed","true"),!c&&v&&b&&(c=ve(u));let l=Xe(i,u,c);if(!l)return;let d=v&&c&&b,m=s==="script",f=V=>{let E=a.createElement(s);V&&(E.crossOrigin="anonymous"),m?E.src=l:(E.rel="stylesheet",E.href=l);for(let H of Array.from(i.attributes))H.name!==n&&!et.includes(H.name)&&H.name!==(m?"src":"href")&&E.setAttribute(H.name,H.value);return d&&E.removeAttribute("integrity"),m&&je(E,i),d&&Ee(E,u,l,m,V?f:null,h),E},U=f(!!d&&!i.hasAttribute("crossorigin"));i.parentNode?(i.parentNode.insertBefore(U,i),i.remove()):pe(`${s} injection failed: No parent node`)}catch{}})}if(v&&ue)try{new MutationObserver(e=>{for(let n of e)for(let s of n.addedNodes)s.nodeType===1&&ne(s)}).observe(a.documentElement,{childList:!0,subtree:!0}),xe&&a.addEventListener("beforescriptexecute",e=>{let n=e.target;if(!n||!n.matches||!n.matches(te))return;let s=n.getAttribute("src");!s||s.indexOf("https://"+b+"/")===0||(e.preventDefault(),n.setAttribute("data-src",s),n.removeAttribute("src"),se("script[data-stagepass]","data-src","script"))},!0),ne(a)}catch{}let tt=()=>{try{se("script[data-stagepass]","data-src","script"),se('link[rel="stylesheet"][data-stagepass]',"data-href","link"),v&&ue&&ne(a),F&&F()}catch{}},Ae=null,nt=()=>Ae=Ae||(v?Ne().then(e=>{ee=e}).catch(()=>{}):Promise.resolve()),Le=()=>{nt().then(tt)};Le(),a.readyState==="loading"&&a.addEventListener("DOMContentLoaded",Le)})();})();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stagepass/loader",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.2",
|
|
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",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
],
|
|
28
28
|
"repository": {
|
|
29
29
|
"type": "git",
|
|
30
|
-
"url": "git+https://github.com/
|
|
30
|
+
"url": "git+https://github.com/stagepass-one/os.git",
|
|
31
31
|
"directory": "packages/loader"
|
|
32
32
|
},
|
|
33
33
|
"license": "MIT",
|