@stagepass/modules 2.2.0 → 2.2.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 +1 -1
- package/dist/all.min.js +2 -2
- package/dist/inject.min.js +1 -1
- package/global.d.ts +3 -3
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -75,7 +75,7 @@ await sp.inject({
|
|
|
75
75
|
| :--- | :--- |
|
|
76
76
|
| `src` | Required production URL. |
|
|
77
77
|
| `type` | `'script'` \| `'style'` (default: `.css` → style, else script). |
|
|
78
|
-
| `stagepass` | When not `false` and `sp.vars.isLocal`,
|
|
78
|
+
| `stagepass` | When not `false` and `sp.vars.isLocal`, use `sp.resolveLocalUrl` only if it returns a non-empty URL; otherwise keep the production `src` (plus optional `version` / `?v=`). |
|
|
79
79
|
| `localPath` / `path` | Local path under the linked root (default: filename from `src`). |
|
|
80
80
|
| `id` | Element id; skips inject if already present. |
|
|
81
81
|
| `async` | If `true`, set `script.async = true`; otherwise `async = false` and keep order. |
|
package/dist/all.min.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var StagepassModules=(()=>{(function(){function b(){let e=window.stagepass||globalThis.stagepass||window.sp||globalThis.sp;return e||null}function x(){try{console.warn("[Stagepass] Core loader should be loaded before the inject module.")}catch{}}function S(){let e=b();if(!e||!e.vars)throw new Error("Stagepass core loader must be loaded before modules");return e.vars}let j=new Set(["src","href","rel","integrity","crossorigin","nonce"]);function E(e){try{let n=S();(n.env==="local"||n.env==="staging")&&console.log(`[Stagepass] ${e}`)}catch{}}function A(e){try{let n=b();if(n&&typeof n.warn=="function"){n.warn(e);return}}catch{}try{console.warn(`[Stagepass] ${e}`)}catch{}}function L(e){if(!e||typeof e!="string")return"file";try{let s=new URL(e).pathname||"";if(!s||s.length===0){let p=e.match(/\/([^\/\?#]+)(?:\?|#|$)/);return p?p[1]:"file"}let a=s.split("/");return a[a.length-1]||a[a.length-2]||"file"}catch{try{let s=e.match(/\/([^\/\?#]+)(?:\?|#|$)/);return s?s[1]:"file"}catch{return"file"}}}function I(e,n){if(n)return n;if(!e||typeof e!="string")return"script";try{if(e.split(".").pop()?.toLowerCase()==="css")return"style"}catch{}return"script"}function T(e,n,s){let a=encodeURIComponent(s),p=e.indexOf("#"),t=p>=0?e.slice(p):"",o=p>=0?e.slice(0,p):e,r=o.includes("?")?"&":"?";return`${o}${r}${encodeURIComponent(n)}=${a}${t}`}function f(e,n){if(!n||n.length===0)return!0;try{let s=new URL(e,window.location.href).hostname.toLowerCase();return n.map(p=>String(p).toLowerCase()).includes(s)}catch{return!1}}function m(e){let n=S(),{src:s,stagepass:a,localPath:p,path:t,version:o}=e;if(!s||typeof s!="string")throw new Error("Invalid src: must be a non-empty string");if(a!==!1&&n.isLocal){let r=p||t||L(s);if(!r||typeof r!="string")return s;let i=r.startsWith("/")?r.substring(1):r,c=b();if(c&&typeof c.resolveLocalUrl=="function"){let y=c.resolveLocalUrl(i);if(y)return y}return`https://${n.domain}/${i}?_cb=${n.timestamp}`}return o?T(s,"v",o):s}function w(e,n){let{id:s,type:a}=e,p=I(e.src,a);if(s&&document.getElementById(s))return E(`Skipping injection: Element with id "${s}" already exists`),!0;if(p==="script"){let t=document.getElementsByTagName("script");for(let o=0;o<t.length;o++)if(t[o].getAttribute("src")===n)return E(`Skipping injection: Resource "${n}" already loaded`),!0}else{let t=document.getElementsByTagName("link");for(let o=0;o<t.length;o++)if(t[o].getAttribute("href")===n)return E(`Skipping injection: Resource "${n}" already loaded`),!0}return!1}function O(e="body-end"){if(typeof e=="string")switch(e){case"head":return document.head;case"body-start":return document.body?.firstChild||document.body;case"body-end":return document.body;default:return document.body}let{target:n,action:s}=e,a=document.querySelector(n);return a?s==="before"?a:a.nextSibling||a.parentNode:(E(`Warning: Target selector "${n}" not found, falling back to body-end`),document.body)}function k(e,n){n.integrity&&e.setAttribute("integrity",n.integrity),n.crossorigin&&e.setAttribute("crossorigin",n.crossorigin),n.nonce&&e.setAttribute("nonce",n.nonce)}function $(e){return new Promise((n,s)=>{if(!e.src){let i=S(),c=new Error('InjectOptions must have a "src" property');i.env!=="production"&&console.error("[Stagepass]",c),s(c);return}if(!f(e.src,e.allowedHosts)){A(`inject: host not allowed for "${e.src}". Check allowedHosts.`),n();return}let a=S(),p=I(e.src,e.type),t=m(e);if(w(e,t)){n();return}let o=p==="script"?document.createElement("script"):document.createElement("link");if(p==="script"){let i=o;e.async?i.async=!0:(i.async=!1,e.defer!==!1&&(i.defer=!0)),e.id&&(i.id=e.id),e.attributes&&Object.entries(e.attributes).forEach(([c,y])=>{j.has(String(c).toLowerCase())||i.setAttribute(c,y)}),i.src=t,k(i,e),i.onload=()=>{E(`Injected: ${t}`),n()},i.onerror=()=>{let c=new Error(`Failed to load script: ${t}`);a.env!=="production"&&console.error("[Stagepass]",c),s(c)}}else{let i=o;e.id&&(i.id=e.id),e.attributes&&Object.entries(e.attributes).forEach(([y,h])=>{j.has(String(y).toLowerCase())||i.setAttribute(y,h)}),i.rel="stylesheet",i.href=t,k(i,e);let c=setInterval(()=>{(i.sheet||i.styleSheet)&&(clearInterval(c),E(`Injected: ${t}`),n())},10);setTimeout(()=>{if(clearInterval(c),!(i.sheet||i.styleSheet)){let h=new Error(`Failed to load stylesheet: ${t}`);a.env!=="production"&&console.error("[Stagepass]",h),s(h)}},5e3)}let r=O(e.position);if(!r){s(new Error("Could not find insertion point"));return}if(r===document.head||r===document.body)r.appendChild(o);else{let i=r.parentNode;i&&(typeof e.position=="object"&&e.position.action==="before"?i.insertBefore(o,r):i.insertBefore(o,r.nextSibling))}})}async function u(e){let n=[];if(!Array.isArray(e)&&typeof e=="object"&&("scripts"in e||"styles"in e)){let s=e;s.scripts&&n.push(...s.scripts.filter(a=>a&&typeof a=="object"&&"src"in a&&typeof a.src=="string"&&a.src.trim().length>0).map(a=>({...a,type:"script"}))),s.styles&&n.push(...s.styles.filter(a=>a&&typeof a=="object"&&"src"in a&&typeof a.src=="string"&&a.src.trim().length>0).map(a=>({...a,type:"style"})))}else Array.isArray(e)?n=e.filter(s=>s&&typeof s=="object"&&"src"in s&&typeof s.src=="string"&&s.src.trim().length>0):e&&typeof e=="object"&&"src"in e&&typeof e.src=="string"&&e.src.trim().length>0&&(n=[e]);for(let s of n)try{await $(s)}catch(a){try{S().env!=="production"&&console.error("[Stagepass] Injection error:",a)}catch{}}}function d(e){e.inject=u}let l=b()||{};l.vars||x(),l.vars&&typeof l.use=="function"?l.use("inject","2.0.0",d):d(l),window.stagepass=l,globalThis.stagepass=l,window.sp=l,globalThis.sp=l})();(function(){function b(){let f=window.stagepass||globalThis.stagepass||window.sp||globalThis.sp;return f||null}function x(){try{console.warn("[Stagepass] Core loader should be loaded before the cookies module.")}catch{}}function S(f,m){if(!(m==null||m==="")&&/[;\r\n]/.test(m))throw new Error(`Invalid cookie ${f}`)}function j(){return window.location.protocol==="https:"}function E(f){try{return decodeURIComponent(f)}catch{return f}}function A(f,m){let O=m.decode!==!1?E(f):f;if(!m.json)return O;try{return JSON.parse(O)}catch{return O}}function L(f){let m=new Map,w=[],O=()=>!0;function k(t,o,r={}){if(!t||typeof t!="string"||t.includes(";")||/[\r\n]/.test(t))throw new Error("Invalid cookie name");let i=r.encode!==!1,c=r.sameSite||"Lax";S("sameSite",c);let y=r.secure!==void 0?r.secure:j(),h=r.path||"/";S("path",h),S("domain",r.domain);let v=r.json?JSON.stringify(o):String(o);i||(S("value",v),S("name",t));let _=i?encodeURIComponent(t):t;v=i?encodeURIComponent(v):v;let C=[`${_}=${v}`];if(typeof r.maxAge=="number"&&C.push(`Max-Age=${Math.floor(r.maxAge)}`),typeof r.days=="number"){let M=new Date(Date.now()+r.days*24*60*60*1e3);C.push(`Expires=${M.toUTCString()}`)}h&&C.push(`Path=${h}`),r.domain&&C.push(`Domain=${r.domain}`),C.push(`SameSite=${c}`);let R=y;c==="None"&&!R&&(R=!0,typeof f.warn=="function"&&f.warn("SameSite=None requires Secure=true. Enforcing Secure for cookie write.")),R&&C.push("Secure"),document.cookie=C.join("; ")}function $(t,o,r={}){let i=r.category,c={name:t,value:o,options:{...r},category:i};if(i&&!O(i)){let h=w.findIndex(v=>v.name===t);h>=0&&w.splice(h,1),w.push(c),m.set(t,c);return}k(t,o,r),m.set(t,c);let y=w.findIndex(h=>h.name===t);y>=0&&w.splice(y,1)}function u(t,o={}){if(!t||typeof t!="string")return null;let r=o.decode===!1?t:E(t),i=document.cookie?document.cookie.split("; "):[];for(let c of i){let y=c.indexOf("=");if(y<0)continue;let h=c.substring(0,y),v=c.substring(y+1),_=E(h);if(h===r||_===r)return A(v,o)}return null}function d(t){return u(t)!==null}function l(t={}){let o=document.cookie?document.cookie.split("; "):[],r={};for(let i of o){let c=i.indexOf("=");if(c<0)continue;let y=i.substring(0,c),h=i.substring(c+1),v=t.decode===!1?y:E(y);r[v]=A(h,t)}return r}function g(t,o={}){k(t,"",{days:-1,maxAge:0,path:o.path||"/",domain:o.domain,secure:o.secure,sameSite:o.sameSite}),m.delete(t);let r=w.findIndex(i=>i.name===t);r>=0&&w.splice(r,1)}function e(t={}){let o=t.category,r=[];m.forEach((i,c)=>{(!o||i.category===o)&&r.push(c)});for(let i of r){let c=m.get(i);g(i,{path:c?.options.path,domain:c?.options.domain,secure:c?.options.secure,sameSite:c?.options.sameSite})}}function n(){let t={};return m.forEach((o,r)=>{t[r]=o.value}),t}function s(t){let o=t==null?"":String(t),r=[];return m.forEach((i,c)=>{c.startsWith(o)&&r.push(c)}),r}let a={bake:$,eat:u,throw:g,has:d,list:l,throwAll:e,jar:n,crumbs:s},p={allows(t){try{return O(t)===!0}catch{return!1}},set(t){typeof t=="function"&&(O=t)},update(){let t=w.splice(0,w.length);for(let o of t)!o.category||O(o.category)?$(o.name,o.value,o.options):w.push(o)}};f.cookies=a,f.cookie=a,f.consent=p}let I=b()||{};I.vars||x(),I.vars&&typeof I.use=="function"?I.use("cookies","2.0.0",L):L(I),window.stagepass=I,globalThis.stagepass=I,window.sp=I,globalThis.sp=I})();(function(){let b="stagepass-maintenance-overlay",x="stagepass-maintenance-badge",S="stagepass-maintenance-style",j="We will be back soon",E="This site is temporarily unavailable while we perform maintenance.";function A(){let u=window.stagepass||globalThis.stagepass||window.sp||globalThis.sp;if(!u||!u.vars){try{console.warn("[Stagepass] Core loader must be loaded before the maintenance module. Skipping registration.")}catch{}return null}return u}function L(){try{if(document.currentScript instanceof HTMLScriptElement)return document.currentScript}catch{}try{let u=document.querySelectorAll('script[src*="maintenance"]');for(let l=u.length-1;l>=0;l--){let g=u[l];if(/maintenance(?:\.min)?\.js/i.test(g.src||""))return g}let d=document.querySelectorAll('script[src*="all"]');for(let l=d.length-1;l>=0;l--){let g=d[l];if(/all(?:\.min)?\.js/i.test(g.src||"")&&g.hasAttribute("data-stagepass-maintenance"))return g}}catch{}return null}function I(u){try{if(typeof u.is=="function"&&u.is("local"))return!0}catch{}try{let d=localStorage.getItem("stagepass_domain");if(!d)return!1;if(d.startsWith("{")){let l=JSON.parse(d),g=l&&l.domain;if(g==="debug"||typeof g=="string"&&g.endsWith(".sp")||g==="localhost"||typeof g=="string"&&g.startsWith("localhost:"))return!0}}catch{}return!1}function T(){if(document.getElementById(S))return;let u=document.createElement("style");u.id=S,u.textContent=`
|
|
1
|
+
"use strict";var StagepassModules=(()=>{(function(){function b(){let e=window.stagepass||globalThis.stagepass||window.sp||globalThis.sp;return e||null}function x(){try{console.warn("[Stagepass] Core loader should be loaded before the inject module.")}catch{}}function S(){let e=b();if(!e||!e.vars)throw new Error("Stagepass core loader must be loaded before modules");return e.vars}let j=new Set(["src","href","rel","integrity","crossorigin","nonce"]);function E(e){try{let n=S();(n.env==="local"||n.env==="staging")&&console.log(`[Stagepass] ${e}`)}catch{}}function A(e){try{let n=b();if(n&&typeof n.warn=="function"){n.warn(e);return}}catch{}try{console.warn(`[Stagepass] ${e}`)}catch{}}function L(e){if(!e||typeof e!="string")return"file";try{let r=new URL(e).pathname||"";if(!r||r.length===0){let p=e.match(/\/([^\/\?#]+)(?:\?|#|$)/);return p?p[1]:"file"}let a=r.split("/");return a[a.length-1]||a[a.length-2]||"file"}catch{try{let r=e.match(/\/([^\/\?#]+)(?:\?|#|$)/);return r?r[1]:"file"}catch{return"file"}}}function I(e,n){if(n)return n;if(!e||typeof e!="string")return"script";try{if(e.split(".").pop()?.toLowerCase()==="css")return"style"}catch{}return"script"}function T(e,n,r){let a=encodeURIComponent(r),p=e.indexOf("#"),t=p>=0?e.slice(p):"",s=p>=0?e.slice(0,p):e,o=s.includes("?")?"&":"?";return`${s}${o}${encodeURIComponent(n)}=${a}${t}`}function f(e,n){if(!n||n.length===0)return!0;try{let r=new URL(e,window.location.href).hostname.toLowerCase();return n.map(p=>String(p).toLowerCase()).includes(r)}catch{return!1}}function m(e){let n=S(),{src:r,stagepass:a,localPath:p,path:t,version:s}=e;if(!r||typeof r!="string")throw new Error("Invalid src: must be a non-empty string");if(a!==!1&&n.isLocal){let o=p||t||L(r);if(!o||typeof o!="string")return r;let i=o.startsWith("/")?o.substring(1):o,c=b();if(c&&typeof c.resolveLocalUrl=="function"){let y=c.resolveLocalUrl(i);if(y)return y}}return s?T(r,"v",s):r}function w(e,n){let{id:r,type:a}=e,p=I(e.src,a);if(r&&document.getElementById(r))return E(`Skipping injection: Element with id "${r}" already exists`),!0;if(p==="script"){let t=document.getElementsByTagName("script");for(let s=0;s<t.length;s++)if(t[s].getAttribute("src")===n)return E(`Skipping injection: Resource "${n}" already loaded`),!0}else{let t=document.getElementsByTagName("link");for(let s=0;s<t.length;s++)if(t[s].getAttribute("href")===n)return E(`Skipping injection: Resource "${n}" already loaded`),!0}return!1}function O(e="body-end"){if(typeof e=="string")return e==="head"?document.head:document.body;let{target:n,action:r}=e,a=document.querySelector(n);return a?r==="before"?a:a.nextSibling||a.parentNode:(E(`Warning: Target selector "${n}" not found, falling back to body-end`),document.body)}function k(e,n){n.integrity&&e.setAttribute("integrity",n.integrity),n.crossorigin&&e.setAttribute("crossorigin",n.crossorigin),n.nonce&&e.setAttribute("nonce",n.nonce)}function $(e){return new Promise((n,r)=>{if(!e.src){let i=S(),c=new Error('InjectOptions must have a "src" property');i.env!=="production"&&console.error("[Stagepass]",c),r(c);return}if(!f(e.src,e.allowedHosts)){A(`inject: host not allowed for "${e.src}". Check allowedHosts.`),n();return}let a=S(),p=I(e.src,e.type),t=m(e);if(w(e,t)){n();return}let s=p==="script"?document.createElement("script"):document.createElement("link");if(p==="script"){let i=s;e.async?i.async=!0:(i.async=!1,e.defer!==!1&&(i.defer=!0)),e.id&&(i.id=e.id),e.attributes&&Object.entries(e.attributes).forEach(([c,y])=>{j.has(String(c).toLowerCase())||i.setAttribute(c,y)}),i.src=t,k(i,e),i.onload=()=>{E(`Injected: ${t}`),n()},i.onerror=()=>{let c=new Error(`Failed to load script: ${t}`);a.env!=="production"&&console.error("[Stagepass]",c),r(c)}}else{let i=s;e.id&&(i.id=e.id),e.attributes&&Object.entries(e.attributes).forEach(([y,h])=>{j.has(String(y).toLowerCase())||i.setAttribute(y,h)}),i.rel="stylesheet",i.href=t,k(i,e);let c=setInterval(()=>{(i.sheet||i.styleSheet)&&(clearInterval(c),E(`Injected: ${t}`),n())},10);setTimeout(()=>{if(clearInterval(c),!(i.sheet||i.styleSheet)){let h=new Error(`Failed to load stylesheet: ${t}`);a.env!=="production"&&console.error("[Stagepass]",h),r(h)}},5e3)}let o=O(e.position);if(!o){r(new Error("Could not find insertion point"));return}if(o===document.head||o===document.body)e.position==="body-start"?o.prepend(s):o.appendChild(s);else{let i=o.parentNode;i&&(typeof e.position=="object"&&e.position.action==="before"?i.insertBefore(s,o):i.insertBefore(s,o.nextSibling))}})}async function u(e){let n=[];if(!Array.isArray(e)&&typeof e=="object"&&("scripts"in e||"styles"in e)){let r=e;r.scripts&&n.push(...r.scripts.filter(a=>a&&typeof a=="object"&&"src"in a&&typeof a.src=="string"&&a.src.trim().length>0).map(a=>({...a,type:"script"}))),r.styles&&n.push(...r.styles.filter(a=>a&&typeof a=="object"&&"src"in a&&typeof a.src=="string"&&a.src.trim().length>0).map(a=>({...a,type:"style"})))}else Array.isArray(e)?n=e.filter(r=>r&&typeof r=="object"&&"src"in r&&typeof r.src=="string"&&r.src.trim().length>0):e&&typeof e=="object"&&"src"in e&&typeof e.src=="string"&&e.src.trim().length>0&&(n=[e]);for(let r of n)try{await $(r)}catch(a){try{S().env!=="production"&&console.error("[Stagepass] Injection error:",a)}catch{}}}function d(e){e.inject=u}let l=b()||{};l.vars||x(),l.vars&&typeof l.use=="function"?l.use("inject","2.0.0",d):d(l),window.stagepass=l,globalThis.stagepass=l,window.sp=l,globalThis.sp=l})();(function(){function b(){let f=window.stagepass||globalThis.stagepass||window.sp||globalThis.sp;return f||null}function x(){try{console.warn("[Stagepass] Core loader should be loaded before the cookies module.")}catch{}}function S(f,m){if(!(m==null||m==="")&&/[;\r\n]/.test(m))throw new Error(`Invalid cookie ${f}`)}function j(){return window.location.protocol==="https:"}function E(f){try{return decodeURIComponent(f)}catch{return f}}function A(f,m){let O=m.decode!==!1?E(f):f;if(!m.json)return O;try{return JSON.parse(O)}catch{return O}}function L(f){let m=new Map,w=[],O=()=>!0;function k(t,s,o={}){if(!t||typeof t!="string"||t.includes(";")||/[\r\n]/.test(t))throw new Error("Invalid cookie name");let i=o.encode!==!1,c=o.sameSite||"Lax";S("sameSite",c);let y=o.secure!==void 0?o.secure:j(),h=o.path||"/";S("path",h),S("domain",o.domain);let v=o.json?JSON.stringify(s):String(s);i||(S("value",v),S("name",t));let R=i?encodeURIComponent(t):t;v=i?encodeURIComponent(v):v;let C=[`${R}=${v}`];if(typeof o.maxAge=="number"&&C.push(`Max-Age=${Math.floor(o.maxAge)}`),typeof o.days=="number"){let M=new Date(Date.now()+o.days*24*60*60*1e3);C.push(`Expires=${M.toUTCString()}`)}h&&C.push(`Path=${h}`),o.domain&&C.push(`Domain=${o.domain}`),C.push(`SameSite=${c}`);let _=y;c==="None"&&!_&&(_=!0,typeof f.warn=="function"&&f.warn("SameSite=None requires Secure=true. Enforcing Secure for cookie write.")),_&&C.push("Secure"),document.cookie=C.join("; ")}function $(t,s,o={}){let i=o.category,c={name:t,value:s,options:{...o},category:i};if(i&&!O(i)){let h=w.findIndex(v=>v.name===t);h>=0&&w.splice(h,1),w.push(c),m.set(t,c);return}k(t,s,o),m.set(t,c);let y=w.findIndex(h=>h.name===t);y>=0&&w.splice(y,1)}function u(t,s={}){if(!t||typeof t!="string")return null;let o=s.decode===!1?t:E(t),i=document.cookie?document.cookie.split("; "):[];for(let c of i){let y=c.indexOf("=");if(y<0)continue;let h=c.substring(0,y),v=c.substring(y+1),R=E(h);if(h===o||R===o)return A(v,s)}return null}function d(t){return u(t)!==null}function l(t={}){let s=document.cookie?document.cookie.split("; "):[],o={};for(let i of s){let c=i.indexOf("=");if(c<0)continue;let y=i.substring(0,c),h=i.substring(c+1),v=t.decode===!1?y:E(y);o[v]=A(h,t)}return o}function g(t,s={}){k(t,"",{days:-1,maxAge:0,path:s.path||"/",domain:s.domain,secure:s.secure,sameSite:s.sameSite}),m.delete(t);let o=w.findIndex(i=>i.name===t);o>=0&&w.splice(o,1)}function e(t={}){let s=t.category,o=[];m.forEach((i,c)=>{(!s||i.category===s)&&o.push(c)});for(let i of o){let c=m.get(i);g(i,{path:c?.options.path,domain:c?.options.domain,secure:c?.options.secure,sameSite:c?.options.sameSite})}}function n(){let t={};return m.forEach((s,o)=>{t[o]=s.value}),t}function r(t){let s=t==null?"":String(t),o=[];return m.forEach((i,c)=>{c.startsWith(s)&&o.push(c)}),o}let a={bake:$,eat:u,throw:g,has:d,list:l,throwAll:e,jar:n,crumbs:r},p={allows(t){try{return O(t)===!0}catch{return!1}},set(t){typeof t=="function"&&(O=t)},update(){let t=w.splice(0,w.length);for(let s of t)!s.category||O(s.category)?$(s.name,s.value,s.options):w.push(s)}};f.cookies=a,f.cookie=a,f.consent=p}let I=b()||{};I.vars||x(),I.vars&&typeof I.use=="function"?I.use("cookies","2.0.0",L):L(I),window.stagepass=I,globalThis.stagepass=I,window.sp=I,globalThis.sp=I})();(function(){let b="stagepass-maintenance-overlay",x="stagepass-maintenance-badge",S="stagepass-maintenance-style",j="We will be back soon",E="This site is temporarily unavailable while we perform maintenance.";function A(){let u=window.stagepass||globalThis.stagepass||window.sp||globalThis.sp;if(!u||!u.vars){try{console.warn("[Stagepass] Core loader must be loaded before the maintenance module. Skipping registration.")}catch{}return null}return u}function L(){try{if(document.currentScript instanceof HTMLScriptElement)return document.currentScript}catch{}try{let u=document.querySelectorAll('script[src*="maintenance"]');for(let l=u.length-1;l>=0;l--){let g=u[l];if(/maintenance(?:\.min)?\.js/i.test(g.src||""))return g}let d=document.querySelectorAll('script[src*="all"]');for(let l=d.length-1;l>=0;l--){let g=d[l];if(/all(?:\.min)?\.js/i.test(g.src||"")&&g.hasAttribute("data-stagepass-maintenance"))return g}}catch{}return null}function I(u){try{if(typeof u.is=="function"&&u.is("local"))return!0}catch{}try{let d=localStorage.getItem("stagepass_domain");if(!d)return!1;if(d.startsWith("{")){let l=JSON.parse(d),g=l&&l.domain;if(g==="debug"||typeof g=="string"&&g.endsWith(".sp")||g==="localhost"||typeof g=="string"&&g.startsWith("localhost:"))return!0}}catch{}return!1}function T(){if(document.getElementById(S))return;let u=document.createElement("style");u.id=S,u.textContent=`
|
|
2
2
|
#${b}{position:fixed;inset:0;z-index:2147483646;display:flex;align-items:center;justify-content:center;padding:24px;box-sizing:border-box;font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Helvetica,Arial,sans-serif;background:#f4f4f5;color:#18181b}
|
|
3
3
|
#${b} .sp-m-card{max-width:32rem;width:100%;text-align:center}
|
|
4
4
|
#${b} .sp-m-title{margin:0 0 12px;font-size:1.75rem;line-height:1.2;font-weight:700}
|
|
@@ -7,4 +7,4 @@
|
|
|
7
7
|
@media (prefers-color-scheme:dark){
|
|
8
8
|
#${b}{background:#09090b;color:#fafafa}
|
|
9
9
|
#${x}{background:#d97706;color:#111}
|
|
10
|
-
}`,(document.head||document.documentElement).appendChild(u)}function f(u){let d=document.getElementById(u);d&&d.remove()}function m(u,d){T(),f(b),f(x);let l=document.createElement("div");l.id=b,l.setAttribute("role","alertdialog"),l.setAttribute("aria-modal","true"),l.setAttribute("aria-labelledby","stagepass-maintenance-title"),l.setAttribute("aria-describedby","stagepass-maintenance-desc"),l.tabIndex=-1;let g=document.createElement("div");g.className="sp-m-card";let e=document.createElement("h1");e.id="stagepass-maintenance-title",e.className="sp-m-title",e.textContent=u;let n=document.createElement("p");n.id="stagepass-maintenance-desc",n.className="sp-m-text",n.textContent=d,g.appendChild(e),g.appendChild(n),l.appendChild(g);let
|
|
10
|
+
}`,(document.head||document.documentElement).appendChild(u)}function f(u){let d=document.getElementById(u);d&&d.remove()}function m(u,d){T(),f(b),f(x);let l=document.createElement("div");l.id=b,l.setAttribute("role","alertdialog"),l.setAttribute("aria-modal","true"),l.setAttribute("aria-labelledby","stagepass-maintenance-title"),l.setAttribute("aria-describedby","stagepass-maintenance-desc"),l.tabIndex=-1;let g=document.createElement("div");g.className="sp-m-card";let e=document.createElement("h1");e.id="stagepass-maintenance-title",e.className="sp-m-title",e.textContent=u;let n=document.createElement("p");n.id="stagepass-maintenance-desc",n.className="sp-m-text",n.textContent=d,g.appendChild(e),g.appendChild(n),l.appendChild(g);let r=()=>{(document.body||document.documentElement).appendChild(l);try{l.focus()}catch{}};document.body?r():document.addEventListener("DOMContentLoaded",r,{once:!0})}function w(u){T(),f(b),f(x);let d=document.createElement("div");d.id=x,d.setAttribute("role","status"),d.textContent=`Maintenance mode on (visitors see: ${u})`;let l=()=>{(document.body||document.documentElement).appendChild(d)};document.body?l():document.addEventListener("DOMContentLoaded",l,{once:!0})}function O(u){let d=!1,l=j,g=E;function e(t){t?.title&&(l=String(t.title)),t?.text&&(g=String(t.text)),d=!0,I(u)?w(l):m(l,g)}function n(){d=!1,f(b),f(x)}function r(){return d}u.maintenance={enable:e,disable:n,isActive:r};let a=L();if(a?.getAttribute("data-stagepass-maintenance")==="true"){let t=a?.getAttribute("data-stagepass-maintenance-title")||j,s=a?.getAttribute("data-stagepass-maintenance-text")||E;e({title:t,text:s})}}let k=A();if(!k)return;typeof k.use=="function"?k.use("maintenance","2.0.0",O):O(k),globalThis.stagepass=k,window.sp=k,globalThis.sp=k})();})();
|
package/dist/inject.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var StagepassInject=(()=>{(function(){function y(){let t=window.stagepass||globalThis.stagepass||window.sp||globalThis.sp;return t||null}function w(){try{console.warn("[Stagepass] Core loader should be loaded before the inject module.")}catch{}}function g(){let t=y();if(!t||!t.vars)throw new Error("Stagepass core loader must be loaded before modules");return t.vars}let h=new Set(["src","href","rel","integrity","crossorigin","nonce"]);function d(t){try{let e=g();(e.env==="local"||e.env==="staging")&&console.log(`[Stagepass] ${t}`)}catch{}}function I(t){try{let e=y();if(e&&typeof e.warn=="function"){e.warn(t);return}}catch{}try{console.warn(`[Stagepass] ${t}`)}catch{}}function O(t){if(!t||typeof t!="string")return"file";try{let n=new URL(t).pathname||"";if(!n||n.length===0){let c=t.match(/\/([^\/\?#]+)(?:\?|#|$)/);return c?c[1]:"file"}let r=n.split("/");return r[r.length-1]||r[r.length-2]||"file"}catch{try{let n=t.match(/\/([^\/\?#]+)(?:\?|#|$)/);return n?n[1]:"file"}catch{return"file"}}}function b(t,e){if(e)return e;if(!t||typeof t!="string")return"script";try{if(t.split(".").pop()?.toLowerCase()==="css")return"style"}catch{}return"script"}function S(t,e,n){let r=encodeURIComponent(n),c=t.indexOf("#"),o=c>=0?t.slice(c):"",i=c>=0?t.slice(0,c):t,a=i.includes("?")?"&":"?";return`${i}${a}${encodeURIComponent(e)}=${r}${o}`}function E(t,e){if(!e||e.length===0)return!0;try{let n=new URL(t,window.location.href).hostname.toLowerCase();return e.map(c=>String(c).toLowerCase()).includes(n)}catch{return!1}}function v(t){let e=g(),{src:n,stagepass:r,localPath:c,path:o,version:i}=t;if(!n||typeof n!="string")throw new Error("Invalid src: must be a non-empty string");if(r!==!1&&e.isLocal){let a=c||o||O(n);if(!a||typeof a!="string")return n;let s=a.startsWith("/")?a.substring(1):a,l=y();if(l&&typeof l.resolveLocalUrl=="function"){let u=l.resolveLocalUrl(s);if(u)return u}
|
|
1
|
+
"use strict";var StagepassInject=(()=>{(function(){function y(){let t=window.stagepass||globalThis.stagepass||window.sp||globalThis.sp;return t||null}function w(){try{console.warn("[Stagepass] Core loader should be loaded before the inject module.")}catch{}}function g(){let t=y();if(!t||!t.vars)throw new Error("Stagepass core loader must be loaded before modules");return t.vars}let h=new Set(["src","href","rel","integrity","crossorigin","nonce"]);function d(t){try{let e=g();(e.env==="local"||e.env==="staging")&&console.log(`[Stagepass] ${t}`)}catch{}}function I(t){try{let e=y();if(e&&typeof e.warn=="function"){e.warn(t);return}}catch{}try{console.warn(`[Stagepass] ${t}`)}catch{}}function O(t){if(!t||typeof t!="string")return"file";try{let n=new URL(t).pathname||"";if(!n||n.length===0){let c=t.match(/\/([^\/\?#]+)(?:\?|#|$)/);return c?c[1]:"file"}let r=n.split("/");return r[r.length-1]||r[r.length-2]||"file"}catch{try{let n=t.match(/\/([^\/\?#]+)(?:\?|#|$)/);return n?n[1]:"file"}catch{return"file"}}}function b(t,e){if(e)return e;if(!t||typeof t!="string")return"script";try{if(t.split(".").pop()?.toLowerCase()==="css")return"style"}catch{}return"script"}function S(t,e,n){let r=encodeURIComponent(n),c=t.indexOf("#"),o=c>=0?t.slice(c):"",i=c>=0?t.slice(0,c):t,a=i.includes("?")?"&":"?";return`${i}${a}${encodeURIComponent(e)}=${r}${o}`}function E(t,e){if(!e||e.length===0)return!0;try{let n=new URL(t,window.location.href).hostname.toLowerCase();return e.map(c=>String(c).toLowerCase()).includes(n)}catch{return!1}}function v(t){let e=g(),{src:n,stagepass:r,localPath:c,path:o,version:i}=t;if(!n||typeof n!="string")throw new Error("Invalid src: must be a non-empty string");if(r!==!1&&e.isLocal){let a=c||o||O(n);if(!a||typeof a!="string")return n;let s=a.startsWith("/")?a.substring(1):a,l=y();if(l&&typeof l.resolveLocalUrl=="function"){let u=l.resolveLocalUrl(s);if(u)return u}}return i?S(n,"v",i):n}function L(t,e){let{id:n,type:r}=t,c=b(t.src,r);if(n&&document.getElementById(n))return d(`Skipping injection: Element with id "${n}" already exists`),!0;if(c==="script"){let o=document.getElementsByTagName("script");for(let i=0;i<o.length;i++)if(o[i].getAttribute("src")===e)return d(`Skipping injection: Resource "${e}" already loaded`),!0}else{let o=document.getElementsByTagName("link");for(let i=0;i<o.length;i++)if(o[i].getAttribute("href")===e)return d(`Skipping injection: Resource "${e}" already loaded`),!0}return!1}function $(t="body-end"){if(typeof t=="string")return t==="head"?document.head:document.body;let{target:e,action:n}=t,r=document.querySelector(e);return r?n==="before"?r:r.nextSibling||r.parentNode:(d(`Warning: Target selector "${e}" not found, falling back to body-end`),document.body)}function m(t,e){e.integrity&&t.setAttribute("integrity",e.integrity),e.crossorigin&&t.setAttribute("crossorigin",e.crossorigin),e.nonce&&t.setAttribute("nonce",e.nonce)}function T(t){return new Promise((e,n)=>{if(!t.src){let s=g(),l=new Error('InjectOptions must have a "src" property');s.env!=="production"&&console.error("[Stagepass]",l),n(l);return}if(!E(t.src,t.allowedHosts)){I(`inject: host not allowed for "${t.src}". Check allowedHosts.`),e();return}let r=g(),c=b(t.src,t.type),o=v(t);if(L(t,o)){e();return}let i=c==="script"?document.createElement("script"):document.createElement("link");if(c==="script"){let s=i;t.async?s.async=!0:(s.async=!1,t.defer!==!1&&(s.defer=!0)),t.id&&(s.id=t.id),t.attributes&&Object.entries(t.attributes).forEach(([l,u])=>{h.has(String(l).toLowerCase())||s.setAttribute(l,u)}),s.src=o,m(s,t),s.onload=()=>{d(`Injected: ${o}`),e()},s.onerror=()=>{let l=new Error(`Failed to load script: ${o}`);r.env!=="production"&&console.error("[Stagepass]",l),n(l)}}else{let s=i;t.id&&(s.id=t.id),t.attributes&&Object.entries(t.attributes).forEach(([u,p])=>{h.has(String(u).toLowerCase())||s.setAttribute(u,p)}),s.rel="stylesheet",s.href=o,m(s,t);let l=setInterval(()=>{(s.sheet||s.styleSheet)&&(clearInterval(l),d(`Injected: ${o}`),e())},10);setTimeout(()=>{if(clearInterval(l),!(s.sheet||s.styleSheet)){let p=new Error(`Failed to load stylesheet: ${o}`);r.env!=="production"&&console.error("[Stagepass]",p),n(p)}},5e3)}let a=$(t.position);if(!a){n(new Error("Could not find insertion point"));return}if(a===document.head||a===document.body)t.position==="body-start"?a.prepend(i):a.appendChild(i);else{let s=a.parentNode;s&&(typeof t.position=="object"&&t.position.action==="before"?s.insertBefore(i,a):s.insertBefore(i,a.nextSibling))}})}async function A(t){let e=[];if(!Array.isArray(t)&&typeof t=="object"&&("scripts"in t||"styles"in t)){let n=t;n.scripts&&e.push(...n.scripts.filter(r=>r&&typeof r=="object"&&"src"in r&&typeof r.src=="string"&&r.src.trim().length>0).map(r=>({...r,type:"script"}))),n.styles&&e.push(...n.styles.filter(r=>r&&typeof r=="object"&&"src"in r&&typeof r.src=="string"&&r.src.trim().length>0).map(r=>({...r,type:"style"})))}else Array.isArray(t)?e=t.filter(n=>n&&typeof n=="object"&&"src"in n&&typeof n.src=="string"&&n.src.trim().length>0):t&&typeof t=="object"&&"src"in t&&typeof t.src=="string"&&t.src.trim().length>0&&(e=[t]);for(let n of e)try{await T(n)}catch(r){try{g().env!=="production"&&console.error("[Stagepass] Injection error:",r)}catch{}}}function j(t){t.inject=A}let f=y()||{};f.vars||w(),f.vars&&typeof f.use=="function"?f.use("inject","2.0.0",j):j(f),window.stagepass=f,globalThis.stagepass=f,window.sp=f,globalThis.sp=f})();})();
|
package/global.d.ts
CHANGED
|
@@ -7,6 +7,6 @@
|
|
|
7
7
|
* instead: `@stagepass/modules/inject`, `@stagepass/modules/cookies`,
|
|
8
8
|
* `@stagepass/modules/maintenance`.
|
|
9
9
|
*/
|
|
10
|
-
export * from './inject';
|
|
11
|
-
export * from './cookies';
|
|
12
|
-
export * from './maintenance';
|
|
10
|
+
export * from './inject.js';
|
|
11
|
+
export * from './cookies.js';
|
|
12
|
+
export * from './maintenance.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stagepass/modules",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.2",
|
|
4
4
|
"description": "Modular feature extensions for Stagepass",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/all.min.js",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"dev": "tsup --watch",
|
|
20
20
|
"test": "vitest run && npm run typecheck",
|
|
21
21
|
"test:watch": "vitest",
|
|
22
|
-
"typecheck": "tsc --noEmit -p fixtures/tsconfig.json && tsc --noEmit -p fixtures/tsconfig.cookies.json && tsc --noEmit -p fixtures/tsconfig.none.json"
|
|
22
|
+
"typecheck": "tsc --noEmit -p fixtures/tsconfig.json && tsc --noEmit -p fixtures/tsconfig.cookies.json && tsc --noEmit -p fixtures/tsconfig.none.json && tsc --noEmit -p fixtures/tsconfig.nodenext.json && tsc --noEmit -p fixtures/nodenext-cjs/tsconfig.json"
|
|
23
23
|
},
|
|
24
24
|
"keywords": [
|
|
25
25
|
"stagepass",
|