@stagepass/loader 1.0.1 → 1.0.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/dist/loader.js CHANGED
@@ -3,9 +3,14 @@ var Stagepass = (() => {
3
3
  (function() {
4
4
  const K = "stagepass_domain";
5
5
  const P = "stagepass";
6
+ function isValidDomain(d) {
7
+ return d === "debug" || d.endsWith(".sp") || d === "localhost" || d.startsWith("localhost:");
8
+ }
6
9
  const p = new URLSearchParams(window.location.search);
7
10
  const svCheck = localStorage.getItem(K);
8
- if (!svCheck && !p.has(P)) {
11
+ const hasValidSession = svCheck && isValidDomain(svCheck);
12
+ const hasParam = p.has(P);
13
+ if (!hasValidSession && !hasParam) {
9
14
  const noop = () => {
10
15
  };
11
16
  console.log = noop;
@@ -49,9 +54,6 @@ var Stagepass = (() => {
49
54
  function clean(d) {
50
55
  return d ? d.replace(/^https?:\/\//, "").replace(/\/$/, "") : null;
51
56
  }
52
- function isValidDomain(d) {
53
- return d === "debug" || d.endsWith(".sp") || d === "localhost" || d.startsWith("localhost:");
54
- }
55
57
  let paramProcessed = false;
56
58
  if (p.has(P)) {
57
59
  const v = p.get(P);
@@ -83,6 +85,7 @@ var Stagepass = (() => {
83
85
  const dev = !!sv;
84
86
  const swap = !!sv && sv !== "debug";
85
87
  const dom = swap ? clean(sv) : null;
88
+ const cacheBust = swap ? Date.now() : 0;
86
89
  function swapEl(sel, pathAttr, srcAttr, type, skipAttrs) {
87
90
  const els = document.querySelectorAll(`${sel}:not([data-stagepass-processed])`);
88
91
  els.forEach((el) => {
@@ -103,7 +106,7 @@ var Stagepass = (() => {
103
106
  let url = "";
104
107
  if (swap && lp && dom) {
105
108
  const cp = lp.startsWith("/") ? lp.substring(1) : lp;
106
- url = `https://${dom}/${cp}`;
109
+ url = `https://${dom}/${cp}?_cb=${cacheBust}`;
107
110
  } else if (ps) {
108
111
  url = ps;
109
112
  }
@@ -1,2 +1,2 @@
1
- var Stagepass=(()=>{(function(){let d="stagepass_domain",h="stagepass",f=new URLSearchParams(window.location.search);if(!localStorage.getItem(d)&&!f.has(h)){let t=()=>{};console.log=t,console.warn=t,console.error=t,console.info=t,console.debug=t}function w(t,...l){var s;let e=localStorage.getItem(d);if(!e||e!=="debug"&&!e)return;let u=new Date().toTimeString().split(" ")[0],m="unknown";try{let a=(s=new Error().stack)==null?void 0:s.split(`
2
- `);if(a){let i=a.find((r,n)=>n>2&&!r.includes("log"));if(i){let r=i.match(/(\/?([^\/\?:]+))(\?[^\s)]*)?:([0-9]+):[0-9]+/);r&&(m=`${r[2]}:${r[4]}`)}}}catch{}let b=`[\u{1F3AB} ${u} \u{1F4CD} ${m}]`;t==="error"?console.log(`%c${b}`,"color: red; font-weight: bold;",...l):console[t]?console[t](b,...l):console.log(b,t,...l)}let g=(...t)=>w("log",...t),A=(...t)=>w("warn",...t),v=(...t)=>w("error",...t);window.splog=g,window.spwarn=A,window.sperror=v;function $(t){return t?t.replace(/^https?:\/\//,"").replace(/\/$/,""):null}function y(t){return t==="debug"||t.endsWith(".sp")||t==="localhost"||t.startsWith("localhost:")}let L=!1;if(f.has(h)){let t=f.get(h);if(t==="off"||t==="0"||t==="false")localStorage.removeItem(d),g("\u{1F50C} Stagepass disconnected.");else if(t){let e=t==="debug"?"debug":$(t);e&&y(e)?(localStorage.setItem(d,e),g(e==="debug"?"\u{1F50D} Stagepass debug mode enabled.":`\u{1F50C} Stagepass connected to: ${e}`),L=!0):e&&!y(e)&&A(`Invalid domain: ${e}. Only .sp domains are allowed.`)}f.delete(h);let l=f.toString();window.history.replaceState({},"",window.location.pathname+(l?`?${l}`:"")+window.location.hash)}let o=localStorage.getItem(d);o&&!y(o)&&(localStorage.removeItem(d),o=null),o&&!L&&o!=="debug"&&g(`\u{1F50C} Stagepass connected to: ${o}`);let x=!!o,S=!!o&&o!=="debug",E=S?$(o):null;function k(t,l,e,u,m){document.querySelectorAll(`${t}:not([data-stagepass-processed])`).forEach(s=>{s.setAttribute("data-stagepass-processed","true");let a=s.getAttribute(l),i=s.getAttribute(e);if(!i)return;if(!a&&i&&S&&E)try{let c=new URL(i).pathname.split("/");a=c[c.length-1]||c[c.length-2]}catch{let c=i.match(/\/([^\/\?#]+)(?:\?|#|$)/);c&&(a=c[1])}let r="";if(S&&a&&E){let n=a.startsWith("/")?a.substring(1):a;r=`https://${E}/${n}`}else i&&(r=i);if(r){let n=document.createElement(u);u==="script"?(n.src=r,Array.from(s.attributes).forEach(c=>{let p=c;m.includes(p.name)||n.setAttribute(p.name,p.value)}),!s.hasAttribute("async")&&!s.hasAttribute("defer")&&n.setAttribute("defer","")):(n.rel="stylesheet",n.href=r,Array.from(s.attributes).forEach(c=>{let p=c;m.includes(p.name)||n.setAttribute(p.name,p.value)})),s.parentNode?(s.parentNode.insertBefore(n,s),s.remove()):v(`${u} injection failed: No parent node`)}})}function C(){k("script[data-stagepass]","data-stagepass-path","data-src","script",["data-src","data-stagepass","data-stagepass-path"]),k('link[rel="stylesheet"][data-stagepass]',"data-stagepass-path","data-href","link",["href","data-href","data-stagepass","data-stagepass-path"])}C(),document.readyState==="loading"&&document.addEventListener("DOMContentLoaded",C);function I(){if(!x)return;let t=document.createElement("div");t.id="stagepass-flag",t.textContent=o==="debug"?"STAGEPASS DEBUG":"STAGEPASS ACTIVE",t.style.cssText='font-size: 12px; line-height: 1; font-weight: bold; color: #fff; background-color: #D92662; padding: 4px 6px; z-index: 9999999999; position: fixed; top: 0; right: 0; cursor: pointer; border-radius: 0 0 0 4px; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; user-select: none;',t.addEventListener("click",()=>{localStorage.removeItem(d),g("\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",I):I()})();})();
1
+ var Stagepass=(()=>{(function(){let d="stagepass_domain",h="stagepass";function b(t){return t==="debug"||t.endsWith(".sp")||t==="localhost"||t.startsWith("localhost:")}let f=new URLSearchParams(window.location.search),A=localStorage.getItem(d),D=A&&b(A),T=f.has(h);if(!D&&!T){let t=()=>{};console.log=t,console.warn=t,console.error=t,console.info=t,console.debug=t}function y(t,...l){var s;let e=localStorage.getItem(d);if(!e||e!=="debug"&&!e)return;let u=new Date().toTimeString().split(" ")[0],m="unknown";try{let a=(s=new Error().stack)==null?void 0:s.split(`
2
+ `);if(a){let i=a.find((r,n)=>n>2&&!r.includes("log"));if(i){let r=i.match(/(\/?([^\/\?:]+))(\?[^\s)]*)?:([0-9]+):[0-9]+/);r&&(m=`${r[2]}:${r[4]}`)}}}catch{}let S=`[\u{1F3AB} ${u} \u{1F4CD} ${m}]`;t==="error"?console.log(`%c${S}`,"color: red; font-weight: bold;",...l):console[t]?console[t](S,...l):console.log(S,t,...l)}let g=(...t)=>y("log",...t),$=(...t)=>y("warn",...t),v=(...t)=>y("error",...t);window.splog=g,window.spwarn=$,window.sperror=v;function L(t){return t?t.replace(/^https?:\/\//,"").replace(/\/$/,""):null}let k=!1;if(f.has(h)){let t=f.get(h);if(t==="off"||t==="0"||t==="false")localStorage.removeItem(d),g("\u{1F50C} Stagepass disconnected.");else if(t){let e=t==="debug"?"debug":L(t);e&&b(e)?(localStorage.setItem(d,e),g(e==="debug"?"\u{1F50D} Stagepass debug mode enabled.":`\u{1F50C} Stagepass connected to: ${e}`),k=!0):e&&!b(e)&&$(`Invalid domain: ${e}. Only .sp domains are allowed.`)}f.delete(h);let l=f.toString();window.history.replaceState({},"",window.location.pathname+(l?`?${l}`:"")+window.location.hash)}let o=localStorage.getItem(d);o&&!b(o)&&(localStorage.removeItem(d),o=null),o&&!k&&o!=="debug"&&g(`\u{1F50C} Stagepass connected to: ${o}`);let M=!!o,w=!!o&&o!=="debug",E=w?L(o):null,P=w?Date.now():0;function C(t,l,e,u,m){document.querySelectorAll(`${t}:not([data-stagepass-processed])`).forEach(s=>{s.setAttribute("data-stagepass-processed","true");let a=s.getAttribute(l),i=s.getAttribute(e);if(!i)return;if(!a&&i&&w&&E)try{let c=new URL(i).pathname.split("/");a=c[c.length-1]||c[c.length-2]}catch{let c=i.match(/\/([^\/\?#]+)(?:\?|#|$)/);c&&(a=c[1])}let r="";if(w&&a&&E){let n=a.startsWith("/")?a.substring(1):a;r=`https://${E}/${n}?_cb=${P}`}else i&&(r=i);if(r){let n=document.createElement(u);u==="script"?(n.src=r,Array.from(s.attributes).forEach(c=>{let p=c;m.includes(p.name)||n.setAttribute(p.name,p.value)}),!s.hasAttribute("async")&&!s.hasAttribute("defer")&&n.setAttribute("defer","")):(n.rel="stylesheet",n.href=r,Array.from(s.attributes).forEach(c=>{let p=c;m.includes(p.name)||n.setAttribute(p.name,p.value)})),s.parentNode?(s.parentNode.insertBefore(n,s),s.remove()):v(`${u} injection failed: No parent node`)}})}function I(){C("script[data-stagepass]","data-stagepass-path","data-src","script",["data-src","data-stagepass","data-stagepass-path"]),C('link[rel="stylesheet"][data-stagepass]',"data-stagepass-path","data-href","link",["href","data-href","data-stagepass","data-stagepass-path"])}I(),document.readyState==="loading"&&document.addEventListener("DOMContentLoaded",I);function x(){if(!M)return;let t=document.createElement("div");t.id="stagepass-flag",t.textContent=o==="debug"?"STAGEPASS DEBUG":"STAGEPASS ACTIVE",t.style.cssText='font-size: 12px; line-height: 1; font-weight: bold; color: #fff; background-color: #D92662; padding: 4px 6px; z-index: 9999999999; position: fixed; top: 0; right: 0; cursor: pointer; border-radius: 0 0 0 4px; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; user-select: none;',t.addEventListener("click",()=>{localStorage.removeItem(d),g("\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",x):x()})();})();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stagepass/loader",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "Universal loader for Stagepass - injects local files into Webflow projects",
5
5
  "main": "dist/loader.min.js",
6
6
  "type": "module",
@@ -9,7 +9,9 @@
9
9
  ],
10
10
  "scripts": {
11
11
  "build": "tsup",
12
- "dev": "tsup --watch"
12
+ "dev": "tsup --watch",
13
+ "test": "vitest run",
14
+ "test:watch": "vitest"
13
15
  },
14
16
  "keywords": [
15
17
  "webflow",
@@ -26,6 +28,9 @@
26
28
  "license": "MIT",
27
29
  "devDependencies": {
28
30
  "tsup": "^8.0.1",
29
- "typescript": "^5.3.3"
31
+ "typescript": "^5.3.3",
32
+ "vitest": "^2.1.0",
33
+ "jsdom": "^24.0.0",
34
+ "@vitest/ui": "^2.1.0"
30
35
  }
31
36
  }