@livx.cc/iab-escape 0.6.4 → 0.7.0

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 CHANGED
@@ -56,7 +56,7 @@ Script-tag attributes map to the JS options.
56
56
  | `userAgent` | | `navigator.userAgent` | Override detection input |
57
57
  | `delayMs` | `data-delay-ms` | per app | Delay before firing |
58
58
  | `includeUnproven` | `data-include-unproven` | `false` | Enable experimental rules |
59
- | `markParam` | `data-mark-param` | `iab_escaped` | Loop-guard query param; `null` / empty disables |
59
+ | `markParam` | `data-mark-param` | `escaped` | Mark + loop-guard param, set to the source app (`escaped=facebook` / `instagram`) so the landing page can filter by it; `null` / empty disables |
60
60
  | `ui` | `data-ui` | `true` | Built-in loader and buttons |
61
61
  | `labels` | `data-label-opening`, `-open`, `-stay` | English | UI text |
62
62
  | `theme` | `data-accent`, `data-bg`, `data-fg` | built-in | Colors |
@@ -101,7 +101,7 @@ myUi.onContinue(() => esc.dismiss());
101
101
 
102
102
  - Each app has its own hand-off: Instagram iOS `instagram://extbrowser/?url=<enc>`, Facebook iOS `x-safari-https://host/path` (fired after a 1.5 s delay), Facebook Android `intent://host/path#Intent;scheme=https;end`.
103
103
  - If the document is still loading, `auto()` waits for `DOMContentLoaded` (never `load`), because navigating mid-parse leaves a half-loaded page on return. If it is already `interactive`/`complete`, the delay counts from the call.
104
- - It adds `iab_escaped=1` to the target as a loop guard; the rest of the query stays byte-identical.
104
+ - It adds `escaped=<app>` (e.g. `escaped=facebook`) to the target: a loop guard and a source mark for analytics; the rest of the query stays byte-identical.
105
105
  - It never uses meta refresh: that loops on Android when the user cancels.
106
106
 
107
107
  ## Tested on
@@ -126,7 +126,7 @@ No re-fire happens after either navigates.
126
126
 
127
127
  - The schemes are undocumented by Meta and an app update can break them: keep a fallback link and monitor.
128
128
  - A late `auto()` call (0.8 s after load) was tested 3/3 on Facebook iOS, Instagram iOS and Facebook Android. Only slow or heavy pages remain untested.
129
- - A bare `?iab_escaped` (no value) counts as "mark present": the URL is left untouched and `auto()` is skipped.
129
+ - A bare `?escaped` (no value) counts as "mark present": the URL is left untouched and `auto()` is skipped.
130
130
  - Paid-ad clicks are untested (organic links only).
131
131
  - A production domain with universal links may open the native app instead of the browser.
132
132
  - Instagram passes no `fbclid` from a DM; Facebook rewrites the `fbclid` at the hand-off.
@@ -24,7 +24,7 @@ export declare class IabEscapeOptions {
24
24
  /** Override the rule's continueDelayMs (min wait before retry/parallel continues). null = use the rule. */
25
25
  continueDelayMs: number | null;
26
26
  includeUnproven: boolean;
27
- /** Query param appended as `=1` to the target so the landing page can tell. null disables. */
27
+ /** Query param appended to the target as `=<app>` (facebook | instagram) so the landing page can tell and filter by source. null disables. */
28
28
  markParam: string | null;
29
29
  onAttempt: ((info: AttemptInfo) => void) | null;
30
30
  onResult: ((info: ResultInfo) => void) | null;
package/dist/IabEscape.js CHANGED
@@ -154,7 +154,7 @@ class IabEscapeOptions {
154
154
  delayMs = null;
155
155
  continueDelayMs = null;
156
156
  includeUnproven = false;
157
- markParam = "iab_escaped";
157
+ markParam = "escaped";
158
158
  onAttempt = null;
159
159
  onResult = null;
160
160
  ui = true;
@@ -232,8 +232,8 @@ var hasParam = (url, key) => new URLSearchParams(url.split("#")[0].split("?")[1]
232
232
 
233
233
  class IabEscape {
234
234
  options;
235
- static version = "0.6.4";
236
- static buildTime = "2026-11-18T12:15:17.565Z";
235
+ static version = "0.7.0";
236
+ static buildTime = "2026-11-18T21:25:06.505Z";
237
237
  ldr = null;
238
238
  fires = 0;
239
239
  watching = false;
@@ -286,7 +286,7 @@ class IabEscape {
286
286
  const hash = h < 0 ? "" : raw.slice(h);
287
287
  const key = this.o.markParam;
288
288
  if (key && !hasParam(noHash, key)) {
289
- noHash += (noHash.includes("?") ? /[?&]$/.test(noHash) ? "" : "&" : "?") + key + "=1";
289
+ noHash += (noHash.includes("?") ? /[?&]$/.test(noHash) ? "" : "&" : "?") + key + "=" + encodeURIComponent(this.getRule()?.app ?? "1");
290
290
  }
291
291
  return { href: noHash + hash, noHash, protocol: resolved.protocol };
292
292
  }
@@ -1,4 +1,4 @@
1
- (()=>{var{defineProperty:b,getOwnPropertyNames:D,getOwnPropertyDescriptor:F}=Object,C=Object.prototype.hasOwnProperty;function P(e){return this[e]}var B=(e)=>{var t=(M??=new WeakMap).get(e),n;if(t)return t;if(t=b({},"__esModule",{value:!0}),e&&typeof e==="object"||typeof e==="function"){for(var i of D(e))if(!C.call(t,i))b(t,i,{get:P.bind(e,i),enumerable:!(n=F(e,i))||n.enumerable})}return M.set(e,t),t},M;var H=(e)=>e;function V(e,t){this[e]=H.bind(null,t)}var j=(e,t)=>{for(var n in t)b(e,n,{get:t[n],enumerable:!0,configurable:!0,set:V.bind(t,n)})};var Q={};j(Q,{boot:()=>U});var W=[["threads",/Barcelona/],["instagram",/Instagram/],["messenger",/FBAN\/MessengerForiOS|FB_IAB\/MESSENGER|Orca/],["facebook",/FBAN|FBAV|FB_IAB/]];function T(e){let t=W.find(([,i])=>i.test(e))?.[0]??null,n=/iPhone|iPad|iPod/.test(e)?"ios":/Android/.test(e)?"android":null;return{app:t,os:n,inApp:t!==null}}var x={opening:"Opening in your browser…",open:"Open in browser",stay:"Continue here",continuing:"Opening…"},k={bg:"--iab-bg",fg:"--iab-fg",accent:"--iab-accent",accentFg:"--iab-accent-fg",radius:"--iab-radius",font:"--iab-font"};class g{doc;labels;theme;onStay;root=null;open;stay;spin;msg;constructor(e,t,n={},i){this.doc=e;this.labels=t;this.theme=n;this.onStay=i}get visible(){return this.root!==null}show(){if(!this.root)this.build();this.spin.hidden=!1,this.open.hidden=!0,this.stay.hidden=!0}reveal(e){if(!this.root)this.build();this.open.href=e,this.open.hidden=!1,this.stay.hidden=!1}continuing(){if(!this.root)this.build();this.spin.hidden=!1,this.open.hidden=!0,this.stay.hidden=!0,this.msg.textContent=this.labels.continuing}hide(){this.root?.remove(),this.root=null}el(e,t,n){let i=this.doc.createElement(e);if(i.className=t,n)i.textContent=n;return i}build(){let e=this.el("div","");e.id="iab-escape",e.setAttribute("role","status");let t=Object.keys(k).filter((s)=>this.theme[s]).map((s)=>`${k[s]}:${this.theme[s]}`).join(";");if(t)e.setAttribute("style",t);let n=this.doc.createElement("style");n.textContent=`
1
+ (()=>{var{defineProperty:b,getOwnPropertyNames:D,getOwnPropertyDescriptor:C}=Object,F=Object.prototype.hasOwnProperty;function P(e){return this[e]}var B=(e)=>{var t=(M??=new WeakMap).get(e),n;if(t)return t;if(t=b({},"__esModule",{value:!0}),e&&typeof e==="object"||typeof e==="function"){for(var i of D(e))if(!F.call(t,i))b(t,i,{get:P.bind(e,i),enumerable:!(n=C(e,i))||n.enumerable})}return M.set(e,t),t},M;var H=(e)=>e;function V(e,t){this[e]=H.bind(null,t)}var j=(e,t)=>{for(var n in t)b(e,n,{get:t[n],enumerable:!0,configurable:!0,set:V.bind(t,n)})};var Q={};j(Q,{boot:()=>N});var W=[["threads",/Barcelona/],["instagram",/Instagram/],["messenger",/FBAN\/MessengerForiOS|FB_IAB\/MESSENGER|Orca/],["facebook",/FBAN|FBAV|FB_IAB/]];function T(e){let t=W.find(([,i])=>i.test(e))?.[0]??null,n=/iPhone|iPad|iPod/.test(e)?"ios":/Android/.test(e)?"android":null;return{app:t,os:n,inApp:t!==null}}var x={opening:"Opening in your browser…",open:"Open in browser",stay:"Continue here",continuing:"Opening…"},k={bg:"--iab-bg",fg:"--iab-fg",accent:"--iab-accent",accentFg:"--iab-accent-fg",radius:"--iab-radius",font:"--iab-font"};class g{doc;labels;theme;onStay;root=null;open;stay;spin;msg;constructor(e,t,n={},i){this.doc=e;this.labels=t;this.theme=n;this.onStay=i}get visible(){return this.root!==null}show(){if(!this.root)this.build();this.spin.hidden=!1,this.open.hidden=!0,this.stay.hidden=!0}reveal(e){if(!this.root)this.build();this.open.href=e,this.open.hidden=!1,this.stay.hidden=!1}continuing(){if(!this.root)this.build();this.spin.hidden=!1,this.open.hidden=!0,this.stay.hidden=!0,this.msg.textContent=this.labels.continuing}hide(){this.root?.remove(),this.root=null}el(e,t,n){let i=this.doc.createElement(e);if(i.className=t,n)i.textContent=n;return i}build(){let e=this.el("div","");e.id="iab-escape",e.setAttribute("role","status");let t=Object.keys(k).filter((s)=>this.theme[s]).map((s)=>`${k[s]}:${this.theme[s]}`).join(";");if(t)e.setAttribute("style",t);let n=this.doc.createElement("style");n.textContent=`
2
2
  #iab-escape{position:fixed;inset:0;z-index:2147483647;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:18px;
3
3
  padding:max(24px,env(safe-area-inset-top)) max(24px,env(safe-area-inset-right)) max(24px,env(safe-area-inset-bottom)) max(24px,env(safe-area-inset-left));
4
4
  background:var(--iab-bg,#fff);color:var(--iab-fg,#111);font:var(--iab-font,18px/1.35 -apple-system,system-ui,sans-serif);text-align:center}
@@ -8,4 +8,4 @@ background:var(--iab-bg,#fff);color:var(--iab-fg,#111);font:var(--iab-font,18px/
8
8
  #iab-escape [hidden]{display:none}
9
9
  @keyframes ie-r{to{transform:rotate(360deg)}}
10
10
  @media (prefers-color-scheme:dark){#iab-escape{background:var(--iab-bg,#111);color:var(--iab-fg,#f2f2f2)}}
11
- @media (prefers-reduced-motion:reduce){#iab-escape .ie-spin{animation:none}}`,this.spin=this.el("div","ie-spin");let i=this.msg=this.el("div","ie-msg",this.labels.opening);this.open=this.el("a","ie-open",this.labels.open),this.stay=this.el("a","ie-stay",this.labels.stay),this.stay.href="#",this.stay.addEventListener("click",(s)=>{s.preventDefault(),this.hide(),this.onStay?.()});for(let s of[n,this.spin,i,this.open,this.stay])e.appendChild(s);(this.doc.body??this.doc.documentElement).appendChild(e),this.root=e}}var L=(e)=>e.protocol==="https:"?"x-safari-"+e.href:null,A=(e)=>(t)=>`${e}://extbrowser/?url=${encodeURIComponent(t.href)}`,_=(e)=>`intent://${e.noHash.replace(/^https?:\/\//i,"")}#Intent;scheme=${e.protocol.slice(0,-1)};end`;var O=[{app:"instagram",os:"ios",proven:!0,delayMs:0,continueDelayMs:2000,build:A("instagram"),testedOn:{date:"2026-11-16",os:"iOS 26.7.3",app:"Instagram 455.0.0.35.67"}},{app:"facebook",os:"ios",proven:!0,delayMs:1500,build:L,testedOn:{date:"2026-11-16",os:"iOS 26.7.3",app:"Facebook 587.0.0.31.71"}},{app:"facebook",os:"android",proven:!0,delayMs:0,build:_,testedOn:{date:"2026-11-16",os:"Android 16",app:"Facebook 587.0.0.39.55"}},{app:"instagram",os:"android",proven:!1,delayMs:0,build:_,testedOn:null},{app:"threads",os:"ios",proven:!1,delayMs:0,build:A("barcelona"),testedOn:null},{app:"messenger",os:"ios",proven:!1,delayMs:1500,build:L,testedOn:null}];class I{url=null;userAgent=null;delayMs=null;continueDelayMs=null;includeUnproven=!1;markParam="iab_escaped";onAttempt=null;onResult=null;ui=!0;labels={};theme={};onState=null;continueUrl=null;fallback="manual";fallbackMs=2500;parallelDelayMs=0;retryMs=300;onContinue=null;fallbackMaxMs=15000;maxAutoFires=3;window=null}function N(e){let t={},n=e.delayMs?.trim();if(n&&Number.isFinite(Number(n))&&Number(n)>=0)t.delayMs=Number(n);if(e.markParam!==void 0)t.markParam=e.markParam===""?null:e.markParam;if(e.includeUnproven!==void 0)t.includeUnproven=!0;if(e.url)t.url=e.url;if(e.continueUrl)t.continueUrl=e.continueUrl;if(e.fallback==="auto"||e.fallback==="manual"||e.fallback==="parallel"||e.fallback==="retry")t.fallback=e.fallback;let i=e.retryMs?.trim();if(i&&Number.isFinite(Number(i))&&Number(i)>0)t.retryMs=Number(i);let s=e.parallelDelayMs?.trim();if(s&&Number.isFinite(Number(s))&&Number(s)>=0)t.parallelDelayMs=Number(s);let a=e.fallbackMs?.trim();if(a&&Number.isFinite(Number(a))&&Number(a)>=0)t.fallbackMs=Number(a);if(e.ui!==void 0)t.ui=e.ui!=="false";let o={};if(e.accent)o.accent=e.accent;if(e.bg)o.bg=e.bg;if(e.fg)o.fg=e.fg;if(Object.keys(o).length)t.theme=o;let r={};if(e.labelOpening)r.opening=e.labelOpening;if(e.labelOpen)r.open=e.labelOpen;if(e.labelStay)r.stay=e.labelStay;if(e.labelContinuing)r.continuing=e.labelContinuing;if(Object.keys(r).length)t.labels=r;return t}var X=3000,Y=800,z=1000,R=150,K=300,q=15000,G=1000,J=600000,c="__iabEscapeFired",S=(e,t)=>new URLSearchParams(e.split("#")[0].split("?")[1]??"").has(t);class p{options;static version="0.6.4";static buildTime="2026-11-18T12:15:17.565Z";ldr=null;fires=0;watching=!1;wentAway=!1;locked=!1;dismissed=!1;continuing=!1;contArmed=!1;base="";constructor(e){this.options=e;this.options={...new I,...e}}get o(){return this.options}get win(){return this.o.window??globalThis.window}detect(){return T(this.o.userAgent??this.win.navigator.userAgent)}getRule(){let{app:e,os:t}=this.detect(),n=O.find((i)=>i.app===e&&i.os===t);return n&&(n.proven||this.o.includeUnproven)?n:null}buildUrl(){let e=this.getRule(),t=e&&this.target();return e&&t?e.build(t):null}pageUrl(){return this.base||=this.win.location.href}target(){let e=this.pageUrl(),t=this.o.url??e,n;try{n=new URL(t,e)}catch{return null}if(!/^https?:$/.test(n.protocol))return null;let i=/^https?:\/\//i.test(t)?t:n.href,s=i.indexOf("#"),a=s<0?i:i.slice(0,s),o=s<0?"":i.slice(s),r=this.o.markParam;if(r&&!S(a,r))a+=(a.includes("?")?/[?&]$/.test(a)?"":"&":"?")+r+"=1";return{href:a+o,noHash:a,protocol:n.protocol}}escape(){let e=this.getRule(),t=this.buildUrl();if(!e||!t)return!1;return this.o.onAttempt?.({rule:e,url:t}),this.win.location.href=t,this.watch({rule:e,url:t}),!0}auto(){let{win:e}=this,t=this.o.markParam,n=this.getRule();if(!n||e[c]||t&&S(e.location.href,t))return()=>{};e[c]=!0;let{document:i}=e;if(this.dismissed=!1,this.o.ui)this.loader().show();this.state("opening");let s=!1,a,o=()=>{if(s=!0,!this.fireNow())e[c]=!1},r=()=>{if(i.removeEventListener("DOMContentLoaded",r),this.delay(n)<=0)o();else a=e.setTimeout(o,this.delay(n))};if(i.readyState==="loading")i.addEventListener("DOMContentLoaded",r);else r();return()=>{if(s)return;if(i.removeEventListener("DOMContentLoaded",r),a!==void 0)e.clearTimeout(a);e[c]=!1,this.ldr?.hide()}}loader(){return this.ldr??=new g(this.win.document,{...x,...this.o.labels},this.o.theme,()=>this.continue())}state(e){this.o.onState?.({phase:e,url:this.buildUrl()})}dismiss(){this.dismissed=!0,this.ldr?.hide(),this.state("dismissed")}continue(){let e=this.continueTarget();if(!e)return this.dismiss();this.go(e,"tap")}go(e,t){if(!this.continuing){if(this.continuing=!0,this.dismissed=!0,this.o.ui)this.loader().continuing();this.state("continuing")}this.o.onContinue?.(e,t),this.win.location.href=e}continueTarget(){let e=this.o.continueUrl??this.o.url;if(!e)return null;try{let t=new URL(e,this.pageUrl());return/^https?:$/.test(t.protocol)?/^https?:\/\//i.test(e)?e:t.href:null}catch{return null}}armContinue(e){let t=this.continueTarget();if(this.contArmed||!t)return;this.contArmed=!0;let n=Math.max(e==="parallel"?this.o.parallelDelayMs:this.o.retryMs,this.o.continueDelayMs??this.getRule()?.continueDelayMs??0),{win:i}=this,s=i.document,a=()=>s.visibilityState==="visible"&&(s.hasFocus?.()??!0),o=!1,r=!1,m=!1,d=!1,h=()=>r||m||this.dismissed&&!this.continuing,f=(l)=>{o=!0,this.go(t,l)},u=(l)=>{if(h()||d||this.wentAway||!a())return;d=!0,i.setTimeout(()=>{d=!1},K),f(l)};if(i.addEventListener("pagehide",()=>{r=!0}),i.addEventListener("beforeunload",()=>{m=!0}),e!=="auto"){let l=n,E=()=>{if(h()||l>J)return;f(e);let w=l<q?this.o.retryMs:G;l+=w,i.setTimeout(E,w)};i.setTimeout(E,n);return}i.addEventListener("focus",()=>u("focus")),i.addEventListener("pageshow",()=>u("pageshow")),s.addEventListener("visibilitychange",()=>{if(s.visibilityState==="visible")u("visible")}),s.addEventListener("pointerdown",()=>u("pointerdown"),!0),s.addEventListener("touchstart",()=>u("touchstart"),!0);let v=this.o.fallbackMs,y=()=>{if(h()||o||this.wentAway)return;if(a())return f("poll");if(v+=R,v<=this.o.fallbackMaxMs)i.setTimeout(y,R)};i.setTimeout(y,this.o.fallbackMs)}fallback(){let e=this.buildUrl();if(e&&this.o.ui)this.loader().reveal(e);this.state("fallback")}delay(e){return this.o.delayMs??e.delayMs}fireNow(){if(!this.escape())return this.ldr?.hide(),!1;if(this.fires++,this.watchReentry(),this.win.setTimeout(()=>{if(!this.dismissed)this.fallback()},Y),this.o.fallback==="auto"||this.o.fallback==="parallel"||this.o.fallback==="retry")this.armContinue(this.o.fallback);return!0}watchReentry(){if(this.watching)return;this.watching=!0;let{win:e}=this,t=e.document;e.addEventListener("pagehide",()=>{this.wentAway=!0}),t.addEventListener("visibilitychange",()=>{if(t.visibilityState==="hidden")this.wentAway=!0;else this.reenter()}),e.addEventListener("pageshow",(n)=>{if(n.persisted)this.wentAway=!0,this.reenter()})}reenter(){let{win:e}=this,t=this.getRule();if(!this.wentAway||this.locked||this.dismissed||!t)return;if(this.wentAway=!1,this.locked=!0,e.setTimeout(()=>{this.locked=!1},z),this.fires>=this.o.maxAutoFires)return this.fallback();if(this.o.ui)this.loader().show();if(this.state("reentry"),this.delay(t)<=0)this.fireNow();else e.setTimeout(()=>this.fireNow(),this.delay(t))}bindLink(e){let t=this.buildUrl();if(!t)return!1;return e.href=t,!0}watch(e){let{win:t}=this,n=!1,i=()=>{n=!0},s=()=>{if(t.document.visibilityState==="hidden")i()};t.addEventListener("pagehide",i),t.document.addEventListener("visibilitychange",s),t.setTimeout(()=>{t.removeEventListener("pagehide",i),t.document.removeEventListener("visibilitychange",s),this.o.onResult?.({...e,outcome:n?"left":"stayed-or-unknown"})},X)}}function U(e,t,n={}){t.IabEscape=p;let i=e?.currentScript;if(i?.hasAttribute("data-auto"))new p({...N(i.dataset),...n}).auto()}if(typeof document<"u")U(document,globalThis);})();
11
+ @media (prefers-reduced-motion:reduce){#iab-escape .ie-spin{animation:none}}`,this.spin=this.el("div","ie-spin");let i=this.msg=this.el("div","ie-msg",this.labels.opening);this.open=this.el("a","ie-open",this.labels.open),this.stay=this.el("a","ie-stay",this.labels.stay),this.stay.href="#",this.stay.addEventListener("click",(s)=>{s.preventDefault(),this.hide(),this.onStay?.()});for(let s of[n,this.spin,i,this.open,this.stay])e.appendChild(s);(this.doc.body??this.doc.documentElement).appendChild(e),this.root=e}}var L=(e)=>e.protocol==="https:"?"x-safari-"+e.href:null,A=(e)=>(t)=>`${e}://extbrowser/?url=${encodeURIComponent(t.href)}`,R=(e)=>`intent://${e.noHash.replace(/^https?:\/\//i,"")}#Intent;scheme=${e.protocol.slice(0,-1)};end`;var O=[{app:"instagram",os:"ios",proven:!0,delayMs:0,continueDelayMs:2000,build:A("instagram"),testedOn:{date:"2026-11-16",os:"iOS 26.7.3",app:"Instagram 455.0.0.35.67"}},{app:"facebook",os:"ios",proven:!0,delayMs:1500,build:L,testedOn:{date:"2026-11-16",os:"iOS 26.7.3",app:"Facebook 587.0.0.31.71"}},{app:"facebook",os:"android",proven:!0,delayMs:0,build:R,testedOn:{date:"2026-11-16",os:"Android 16",app:"Facebook 587.0.0.39.55"}},{app:"instagram",os:"android",proven:!1,delayMs:0,build:R,testedOn:null},{app:"threads",os:"ios",proven:!1,delayMs:0,build:A("barcelona"),testedOn:null},{app:"messenger",os:"ios",proven:!1,delayMs:1500,build:L,testedOn:null}];class I{url=null;userAgent=null;delayMs=null;continueDelayMs=null;includeUnproven=!1;markParam="escaped";onAttempt=null;onResult=null;ui=!0;labels={};theme={};onState=null;continueUrl=null;fallback="manual";fallbackMs=2500;parallelDelayMs=0;retryMs=300;onContinue=null;fallbackMaxMs=15000;maxAutoFires=3;window=null}function U(e){let t={},n=e.delayMs?.trim();if(n&&Number.isFinite(Number(n))&&Number(n)>=0)t.delayMs=Number(n);if(e.markParam!==void 0)t.markParam=e.markParam===""?null:e.markParam;if(e.includeUnproven!==void 0)t.includeUnproven=!0;if(e.url)t.url=e.url;if(e.continueUrl)t.continueUrl=e.continueUrl;if(e.fallback==="auto"||e.fallback==="manual"||e.fallback==="parallel"||e.fallback==="retry")t.fallback=e.fallback;let i=e.retryMs?.trim();if(i&&Number.isFinite(Number(i))&&Number(i)>0)t.retryMs=Number(i);let s=e.parallelDelayMs?.trim();if(s&&Number.isFinite(Number(s))&&Number(s)>=0)t.parallelDelayMs=Number(s);let a=e.fallbackMs?.trim();if(a&&Number.isFinite(Number(a))&&Number(a)>=0)t.fallbackMs=Number(a);if(e.ui!==void 0)t.ui=e.ui!=="false";let o={};if(e.accent)o.accent=e.accent;if(e.bg)o.bg=e.bg;if(e.fg)o.fg=e.fg;if(Object.keys(o).length)t.theme=o;let r={};if(e.labelOpening)r.opening=e.labelOpening;if(e.labelOpen)r.open=e.labelOpen;if(e.labelStay)r.stay=e.labelStay;if(e.labelContinuing)r.continuing=e.labelContinuing;if(Object.keys(r).length)t.labels=r;return t}var X=3000,Y=800,z=1000,_=150,K=300,q=15000,G=1000,J=600000,c="__iabEscapeFired",S=(e,t)=>new URLSearchParams(e.split("#")[0].split("?")[1]??"").has(t);class p{options;static version="0.7.0";static buildTime="2026-11-18T21:25:06.505Z";ldr=null;fires=0;watching=!1;wentAway=!1;locked=!1;dismissed=!1;continuing=!1;contArmed=!1;base="";constructor(e){this.options=e;this.options={...new I,...e}}get o(){return this.options}get win(){return this.o.window??globalThis.window}detect(){return T(this.o.userAgent??this.win.navigator.userAgent)}getRule(){let{app:e,os:t}=this.detect(),n=O.find((i)=>i.app===e&&i.os===t);return n&&(n.proven||this.o.includeUnproven)?n:null}buildUrl(){let e=this.getRule(),t=e&&this.target();return e&&t?e.build(t):null}pageUrl(){return this.base||=this.win.location.href}target(){let e=this.pageUrl(),t=this.o.url??e,n;try{n=new URL(t,e)}catch{return null}if(!/^https?:$/.test(n.protocol))return null;let i=/^https?:\/\//i.test(t)?t:n.href,s=i.indexOf("#"),a=s<0?i:i.slice(0,s),o=s<0?"":i.slice(s),r=this.o.markParam;if(r&&!S(a,r))a+=(a.includes("?")?/[?&]$/.test(a)?"":"&":"?")+r+"="+encodeURIComponent(this.getRule()?.app??"1");return{href:a+o,noHash:a,protocol:n.protocol}}escape(){let e=this.getRule(),t=this.buildUrl();if(!e||!t)return!1;return this.o.onAttempt?.({rule:e,url:t}),this.win.location.href=t,this.watch({rule:e,url:t}),!0}auto(){let{win:e}=this,t=this.o.markParam,n=this.getRule();if(!n||e[c]||t&&S(e.location.href,t))return()=>{};e[c]=!0;let{document:i}=e;if(this.dismissed=!1,this.o.ui)this.loader().show();this.state("opening");let s=!1,a,o=()=>{if(s=!0,!this.fireNow())e[c]=!1},r=()=>{if(i.removeEventListener("DOMContentLoaded",r),this.delay(n)<=0)o();else a=e.setTimeout(o,this.delay(n))};if(i.readyState==="loading")i.addEventListener("DOMContentLoaded",r);else r();return()=>{if(s)return;if(i.removeEventListener("DOMContentLoaded",r),a!==void 0)e.clearTimeout(a);e[c]=!1,this.ldr?.hide()}}loader(){return this.ldr??=new g(this.win.document,{...x,...this.o.labels},this.o.theme,()=>this.continue())}state(e){this.o.onState?.({phase:e,url:this.buildUrl()})}dismiss(){this.dismissed=!0,this.ldr?.hide(),this.state("dismissed")}continue(){let e=this.continueTarget();if(!e)return this.dismiss();this.go(e,"tap")}go(e,t){if(!this.continuing){if(this.continuing=!0,this.dismissed=!0,this.o.ui)this.loader().continuing();this.state("continuing")}this.o.onContinue?.(e,t),this.win.location.href=e}continueTarget(){let e=this.o.continueUrl??this.o.url;if(!e)return null;try{let t=new URL(e,this.pageUrl());return/^https?:$/.test(t.protocol)?/^https?:\/\//i.test(e)?e:t.href:null}catch{return null}}armContinue(e){let t=this.continueTarget();if(this.contArmed||!t)return;this.contArmed=!0;let n=Math.max(e==="parallel"?this.o.parallelDelayMs:this.o.retryMs,this.o.continueDelayMs??this.getRule()?.continueDelayMs??0),{win:i}=this,s=i.document,a=()=>s.visibilityState==="visible"&&(s.hasFocus?.()??!0),o=!1,r=!1,m=!1,d=!1,h=()=>r||m||this.dismissed&&!this.continuing,f=(l)=>{o=!0,this.go(t,l)},u=(l)=>{if(h()||d||this.wentAway||!a())return;d=!0,i.setTimeout(()=>{d=!1},K),f(l)};if(i.addEventListener("pagehide",()=>{r=!0}),i.addEventListener("beforeunload",()=>{m=!0}),e!=="auto"){let l=n,E=()=>{if(h()||l>J)return;f(e);let w=l<q?this.o.retryMs:G;l+=w,i.setTimeout(E,w)};i.setTimeout(E,n);return}i.addEventListener("focus",()=>u("focus")),i.addEventListener("pageshow",()=>u("pageshow")),s.addEventListener("visibilitychange",()=>{if(s.visibilityState==="visible")u("visible")}),s.addEventListener("pointerdown",()=>u("pointerdown"),!0),s.addEventListener("touchstart",()=>u("touchstart"),!0);let v=this.o.fallbackMs,y=()=>{if(h()||o||this.wentAway)return;if(a())return f("poll");if(v+=_,v<=this.o.fallbackMaxMs)i.setTimeout(y,_)};i.setTimeout(y,this.o.fallbackMs)}fallback(){let e=this.buildUrl();if(e&&this.o.ui)this.loader().reveal(e);this.state("fallback")}delay(e){return this.o.delayMs??e.delayMs}fireNow(){if(!this.escape())return this.ldr?.hide(),!1;if(this.fires++,this.watchReentry(),this.win.setTimeout(()=>{if(!this.dismissed)this.fallback()},Y),this.o.fallback==="auto"||this.o.fallback==="parallel"||this.o.fallback==="retry")this.armContinue(this.o.fallback);return!0}watchReentry(){if(this.watching)return;this.watching=!0;let{win:e}=this,t=e.document;e.addEventListener("pagehide",()=>{this.wentAway=!0}),t.addEventListener("visibilitychange",()=>{if(t.visibilityState==="hidden")this.wentAway=!0;else this.reenter()}),e.addEventListener("pageshow",(n)=>{if(n.persisted)this.wentAway=!0,this.reenter()})}reenter(){let{win:e}=this,t=this.getRule();if(!this.wentAway||this.locked||this.dismissed||!t)return;if(this.wentAway=!1,this.locked=!0,e.setTimeout(()=>{this.locked=!1},z),this.fires>=this.o.maxAutoFires)return this.fallback();if(this.o.ui)this.loader().show();if(this.state("reentry"),this.delay(t)<=0)this.fireNow();else e.setTimeout(()=>this.fireNow(),this.delay(t))}bindLink(e){let t=this.buildUrl();if(!t)return!1;return e.href=t,!0}watch(e){let{win:t}=this,n=!1,i=()=>{n=!0},s=()=>{if(t.document.visibilityState==="hidden")i()};t.addEventListener("pagehide",i),t.document.addEventListener("visibilitychange",s),t.setTimeout(()=>{t.removeEventListener("pagehide",i),t.document.removeEventListener("visibilitychange",s),this.o.onResult?.({...e,outcome:n?"left":"stayed-or-unknown"})},X)}}function N(e,t,n={}){t.IabEscape=p;let i=e?.currentScript;if(i?.hasAttribute("data-auto"))new p({...U(i.dataset),...n}).auto()}if(typeof document<"u")N(document,globalThis);})();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@livx.cc/iab-escape",
3
- "version": "0.6.4",
3
+ "version": "0.7.0",
4
4
  "type": "module",
5
5
  "description": "Move users from the Facebook / Instagram in-app browser to the device default browser, using only trigger methods proven on real devices.",
6
6
  "license": "MIT",