@stagepass/loader 1.1.0 → 1.1.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/dist/loader.js CHANGED
@@ -112,6 +112,13 @@ var Stagepass = (() => {
112
112
  timestamp: sessionStartTime,
113
113
  version: "1.1.0"
114
114
  });
115
+ let readyResolve = null;
116
+ let readyReject = null;
117
+ const readyPromise = new Promise((resolve, reject) => {
118
+ readyResolve = resolve;
119
+ readyReject = reject;
120
+ });
121
+ stagepassObj.ready = readyPromise;
115
122
  window.stagepass = stagepassObj;
116
123
  globalThis.stagepass = stagepassObj;
117
124
  function swapEl(sel, pathAttr, srcAttr, type, skipAttrs) {
@@ -157,7 +164,12 @@ var Stagepass = (() => {
157
164
  });
158
165
  }
159
166
  function loadModules() {
160
- if (modulesParam === null) return;
167
+ if (modulesParam === null) {
168
+ if (readyResolve) {
169
+ readyResolve();
170
+ }
171
+ return;
172
+ }
161
173
  const modulesToLoad = modulesParam === "" ? ["all"] : modulesParam.split(",").map((m) => m.trim()).filter(Boolean);
162
174
  if (modulesToLoad.length === 0) return;
163
175
  let baseUrl = window.location.origin;
@@ -171,16 +183,38 @@ var Stagepass = (() => {
171
183
  baseUrl = loaderScript.src.replace(/\/[^\/\?]+(\?.*)?$/, "");
172
184
  }
173
185
  }
174
- modulesToLoad.forEach((moduleName) => {
186
+ let currentIndex = 0;
187
+ function loadNext() {
188
+ if (currentIndex >= modulesToLoad.length) {
189
+ if (env !== "production") {
190
+ splog("\u2705 All modules loaded");
191
+ }
192
+ if (readyResolve) {
193
+ readyResolve();
194
+ }
195
+ return;
196
+ }
197
+ const moduleName = modulesToLoad[currentIndex];
175
198
  const moduleUrl = `${baseUrl}/${moduleName}.min.js`;
176
199
  const script = document.createElement("script");
200
+ script.onload = () => {
201
+ if (env !== "production") {
202
+ splog(`\u{1F4E6} Module loaded: ${moduleName}`);
203
+ }
204
+ currentIndex++;
205
+ loadNext();
206
+ };
207
+ script.onerror = () => {
208
+ if (env !== "production") {
209
+ sperror(`Failed to load module: ${moduleName}`);
210
+ }
211
+ currentIndex++;
212
+ loadNext();
213
+ };
177
214
  script.src = moduleUrl;
178
- script.async = true;
179
215
  document.head.appendChild(script);
180
- if (env !== "production") {
181
- splog(`\u{1F4E6} Loading module: ${moduleName}`);
182
- }
183
- });
216
+ }
217
+ loadNext();
184
218
  }
185
219
  const process = () => {
186
220
  swapEl("script[data-stagepass]", "data-stagepass-path", "data-src", "script", ["data-src", "data-stagepass", "data-stagepass-path"]);
@@ -1,2 +1,2 @@
1
- var Stagepass=(()=>{(function(){let g="stagepass_domain",y="stagepass",$=t=>t==="debug"||t.endsWith(".sp")||t==="localhost"||t.startsWith("localhost:"),w=new URLSearchParams(window.location.search),d=document.querySelector('script[src*="loader"]'),b=null,v=null;if(d&&d.src)try{let t=new URL(d.src);b=t.searchParams.get("modules"),v=t.searchParams.get("silent")}catch{let s=d.src.match(/[?&]modules(=([^&]*))?/);s&&(b=s[2]!==void 0?s[2]:""),d.src.match(/[?&]silent/)&&(v="")}function A(t,...s){var l;if(!localStorage.getItem(g))return;let c=new Date().toTimeString().split(" ")[0],i="";try{let p=(l=new Error().stack)==null?void 0:l.split(`
2
- `);if(p){let h=p.find((r,u)=>u>2&&!r.includes("log"));if(h){let r=h.match(/:([0-9]+):/);r&&(i=`:${r[1]}`)}}}catch{}let o=`[\u{1F3AB} ${c}${i?" \u{1F4CD}"+i:""}]`;t==="error"?console.log(`%c${o}`,"color: red; font-weight: bold;",...s):console[t]?console[t](o,...s):console.log(o,t,...s)}let f=(...t)=>A("log",...t),T=(...t)=>A("warn",...t),P=(...t)=>A("error",...t);window.splog=f,window.spwarn=T,window.sperror=P;let k=t=>t?t.replace(/^https?:\/\//,"").replace(/\/$/,""):null,C=!1,n=localStorage.getItem(g);if(w.has(y)){let t=w.get(y);if(t==="off"||t==="0"||t==="false")localStorage.removeItem(g),n=null,f("\u{1F50C} Stagepass disconnected.");else if(t){let e=t==="debug"?"debug":k(t);e&&$(e)?(localStorage.setItem(g,e),n=e,f(e==="debug"?"\u{1F50D} Stagepass debug mode enabled.":`\u{1F50C} Stagepass connected to: ${e}`),C=!0):e&&T(`Invalid domain: ${e}. Only .sp domains are allowed.`)}w.delete(y);let s=w.toString();window.history.replaceState({},"",window.location.pathname+(s?`?${s}`:"")+window.location.hash)}n&&!$(n)&&(localStorage.removeItem(g),n=null),n&&!C&&n!=="debug"&&f(`\u{1F50C} Stagepass connected to: ${n}`);let j=!!n,S=!!n&&n!=="debug",E=S?k(n):null,U=S?Date.now():0,W=U,B=U,m=window.location.hostname,R=m==="localhost"||m==="127.0.0.1"||m.startsWith("localhost:")||m.startsWith("127.0.0.1:"),I=S||R,L=I?"local":m.endsWith(".webflow.io")?"staging":"production";!(n&&$(n))&&!w.has(y)&&(L==="production"||L==="staging"&&v!==null)&&(console.log=console.warn=console.error=console.info=console.debug=()=>{});let M=window.stagepass||{};M.vars=Object.freeze({isLocal:I,env:L,domain:E||m,timestamp:B,version:"1.1.0"}),window.stagepass=M,globalThis.stagepass=M;function x(t,s,e,c,i){document.querySelectorAll(`${t}:not([data-stagepass-processed])`).forEach(o=>{o.setAttribute("data-stagepass-processed","true");let l=o.getAttribute(s),p=o.getAttribute(e);if(!p)return;if(!l&&p&&S&&E)try{let a=new URL(p).pathname.split("/");l=a[a.length-1]||a[a.length-2]}catch{let a=p.match(/\/([^\/\?#]+)(?:\?|#|$)/);a&&(l=a[1])}let h=S&&l&&E?`https://${E}/${l.startsWith("/")?l.substring(1):l}?_cb=${W}`:p;if(!h)return;let r=document.createElement(c);c==="script"?(r.src=h,Array.from(o.attributes).forEach(u=>{let a=u;i.includes(a.name)||r.setAttribute(a.name,a.value)}),!o.hasAttribute("async")&&!o.hasAttribute("defer")&&r.setAttribute("defer","")):(r.rel="stylesheet",r.href=h,Array.from(o.attributes).forEach(u=>{let a=u;i.includes(a.name)||r.setAttribute(a.name,a.value)})),o.parentNode?(o.parentNode.insertBefore(r,o),o.remove()):P(`${c} injection failed: No parent node`)})}function H(){if(b===null)return;let t=b===""?["all"]:b.split(",").map(e=>e.trim()).filter(Boolean);if(t.length===0)return;let s=window.location.origin;if(d&&d.src)try{let e=new URL(d.src),c=e.pathname.split("/");c.pop(),s=`${e.origin}${c.join("/")}`}catch{s=d.src.replace(/\/[^\/\?]+(\?.*)?$/,"")}t.forEach(e=>{let c=`${s}/${e}.min.js`,i=document.createElement("script");i.src=c,i.async=!0,document.head.appendChild(i),L!=="production"&&f(`\u{1F4E6} Loading module: ${e}`)})}let D=()=>{x("script[data-stagepass]","data-stagepass-path","data-src","script",["data-src","data-stagepass","data-stagepass-path"]),x('link[rel="stylesheet"][data-stagepass]',"data-stagepass-path","data-href","link",["href","data-href","data-stagepass","data-stagepass-path"])};H(),D(),document.readyState==="loading"&&document.addEventListener("DOMContentLoaded",D);function O(){if(!j)return;let t=document.createElement("div");t.id="stagepass-flag",t.textContent=n==="debug"?"STAGEPASS DEBUG":"STAGEPASS ACTIVE",t.style.cssText='font:12px/1 -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,sans-serif;font-weight:bold;color:#fff;background:#D92662;padding:4px 6px;z-index:9999999999;position:fixed;top:0;right:0;cursor:pointer;border-radius:0 0 0 4px;user-select:none;',t.addEventListener("click",()=>{localStorage.removeItem(g),f("\u{1F50C} Stagepass disconnected."),window.location.reload()}),document.body?document.body.appendChild(t):document.addEventListener("DOMContentLoaded",()=>{document.body&&document.body.appendChild(t)})}document.readyState==="loading"?document.addEventListener("DOMContentLoaded",O):O()})();})();
1
+ var Stagepass=(()=>{(function(){let m="stagepass_domain",v="stagepass",A=t=>t==="debug"||t.endsWith(".sp")||t==="localhost"||t.startsWith("localhost:"),b=new URLSearchParams(window.location.search),l=document.querySelector('script[src*="loader"]'),y=null,M=null;if(l&&l.src)try{let t=new URL(l.src);y=t.searchParams.get("modules"),M=t.searchParams.get("silent")}catch{let s=l.src.match(/[?&]modules(=([^&]*))?/);s&&(y=s[2]!==void 0?s[2]:""),l.src.match(/[?&]silent/)&&(M="")}function P(t,...s){var r;if(!localStorage.getItem(m))return;let d=new Date().toTimeString().split(" ")[0],n="";try{let u=(r=new Error().stack)==null?void 0:r.split(`
2
+ `);if(u){let w=u.find((i,g)=>g>2&&!i.includes("log"));if(w){let i=w.match(/:([0-9]+):/);i&&(n=`:${i[1]}`)}}}catch{}let e=`[\u{1F3AB} ${d}${n?" \u{1F4CD}"+n:""}]`;t==="error"?console.log(`%c${e}`,"color: red; font-weight: bold;",...s):console[t]?console[t](e,...s):console.log(e,t,...s)}let p=(...t)=>P("log",...t),k=(...t)=>P("warn",...t),T=(...t)=>P("error",...t);window.splog=p,window.spwarn=k,window.sperror=T;let x=t=>t?t.replace(/^https?:\/\//,"").replace(/\/$/,""):null,C=!1,a=localStorage.getItem(m);if(b.has(v)){let t=b.get(v);if(t==="off"||t==="0"||t==="false")localStorage.removeItem(m),a=null,p("\u{1F50C} Stagepass disconnected.");else if(t){let o=t==="debug"?"debug":x(t);o&&A(o)?(localStorage.setItem(m,o),a=o,p(o==="debug"?"\u{1F50D} Stagepass debug mode enabled.":`\u{1F50C} Stagepass connected to: ${o}`),C=!0):o&&k(`Invalid domain: ${o}. Only .sp domains are allowed.`)}b.delete(v);let s=b.toString();window.history.replaceState({},"",window.location.pathname+(s?`?${s}`:"")+window.location.hash)}a&&!A(a)&&(localStorage.removeItem(m),a=null),a&&!C&&a!=="debug"&&p(`\u{1F50C} Stagepass connected to: ${a}`);let R=!!a,S=!!a&&a!=="debug",E=S?x(a):null,I=S?Date.now():0,W=I,B=I,f=window.location.hostname,N=f==="localhost"||f==="127.0.0.1"||f.startsWith("localhost:")||f.startsWith("127.0.0.1:"),U=S||N,h=U?"local":f.endsWith(".webflow.io")?"staging":"production";!(a&&A(a))&&!b.has(v)&&(h==="production"||h==="staging"&&M!==null)&&(console.log=console.warn=console.error=console.info=console.debug=()=>{});let L=window.stagepass||{};L.vars=Object.freeze({isLocal:U,env:h,domain:E||f,timestamp:B,version:"1.1.0"});let $=null,H=null,V=new Promise((t,s)=>{$=t,H=s});L.ready=V,window.stagepass=L,globalThis.stagepass=L;function j(t,s,o,d,n){document.querySelectorAll(`${t}:not([data-stagepass-processed])`).forEach(e=>{e.setAttribute("data-stagepass-processed","true");let r=e.getAttribute(s),u=e.getAttribute(o);if(!u)return;if(!r&&u&&S&&E)try{let c=new URL(u).pathname.split("/");r=c[c.length-1]||c[c.length-2]}catch{let c=u.match(/\/([^\/\?#]+)(?:\?|#|$)/);c&&(r=c[1])}let w=S&&r&&E?`https://${E}/${r.startsWith("/")?r.substring(1):r}?_cb=${W}`:u;if(!w)return;let i=document.createElement(d);d==="script"?(i.src=w,Array.from(e.attributes).forEach(g=>{let c=g;n.includes(c.name)||i.setAttribute(c.name,c.value)}),!e.hasAttribute("async")&&!e.hasAttribute("defer")&&i.setAttribute("defer","")):(i.rel="stylesheet",i.href=w,Array.from(e.attributes).forEach(g=>{let c=g;n.includes(c.name)||i.setAttribute(c.name,c.value)})),e.parentNode?(e.parentNode.insertBefore(i,e),e.remove()):T(`${d} injection failed: No parent node`)})}function F(){if(y===null){$&&$();return}let t=y===""?["all"]:y.split(",").map(n=>n.trim()).filter(Boolean);if(t.length===0)return;let s=window.location.origin;if(l&&l.src)try{let n=new URL(l.src),e=n.pathname.split("/");e.pop(),s=`${n.origin}${e.join("/")}`}catch{s=l.src.replace(/\/[^\/\?]+(\?.*)?$/,"")}let o=0;function d(){if(o>=t.length){h!=="production"&&p("\u2705 All modules loaded"),$&&$();return}let n=t[o],e=`${s}/${n}.min.js`,r=document.createElement("script");r.onload=()=>{h!=="production"&&p(`\u{1F4E6} Module loaded: ${n}`),o++,d()},r.onerror=()=>{h!=="production"&&T(`Failed to load module: ${n}`),o++,d()},r.src=e,document.head.appendChild(r)}d()}let D=()=>{j("script[data-stagepass]","data-stagepass-path","data-src","script",["data-src","data-stagepass","data-stagepass-path"]),j('link[rel="stylesheet"][data-stagepass]',"data-stagepass-path","data-href","link",["href","data-href","data-stagepass","data-stagepass-path"])};F(),D(),document.readyState==="loading"&&document.addEventListener("DOMContentLoaded",D);function O(){if(!R)return;let t=document.createElement("div");t.id="stagepass-flag",t.textContent=a==="debug"?"STAGEPASS DEBUG":"STAGEPASS ACTIVE",t.style.cssText='font:12px/1 -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,sans-serif;font-weight:bold;color:#fff;background:#D92662;padding:4px 6px;z-index:9999999999;position:fixed;top:0;right:0;cursor:pointer;border-radius:0 0 0 4px;user-select:none;',t.addEventListener("click",()=>{localStorage.removeItem(m),p("\u{1F50C} Stagepass disconnected."),window.location.reload()}),document.body?document.body.appendChild(t):document.addEventListener("DOMContentLoaded",()=>{document.body&&document.body.appendChild(t)})}document.readyState==="loading"?document.addEventListener("DOMContentLoaded",O):O()})();})();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stagepass/loader",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "description": "Universal loader for Stagepass - injects local files into Webflow projects",
5
5
  "main": "dist/loader.min.js",
6
6
  "type": "module",