@livx.cc/iab-escape 0.5.0 → 0.6.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
@@ -114,8 +114,8 @@ myUi.onContinue(() => esc.dismiss());
114
114
 
115
115
  `fallback` (`data-fallback`), default `'manual'`:
116
116
 
117
- - `'auto'`: continues by itself when the page is still here `fallbackMs` (default 2500) after the fire. A native confirm may leave the page visible with timers running, so it only continues when `document.visibilityState` is `visible` and `document.hasFocus()` is true, re-checking every 150 ms up to `fallbackMaxMs` (15000). Device-unverified.
118
- - `'parallel'`: fires the scheme and navigates to the destination `parallelDelayMs` (`data-parallel-delay-ms`, default 0) later, whatever the confirm answer. Risk: navigating may dismiss the app's confirm dialog before the user answers. Device-unverified.
117
+ - `'parallel'` (**recommended**): fires the scheme and navigates to the destination `parallelDelayMs` (`data-parallel-delay-ms`, default 0) later. A navigation issued while the app's native prompt is open can be dropped (seen on Facebook iOS), so it is re-issued when the user is back on the page: on `focus`, `visibilitychange` to visible, `pageshow`, or any `pointerdown`/`touchstart` (one per ~300 ms burst), plus one safety retry 4 s after the fire. Retries stop on `pagehide` and while a `beforeunload` says a navigation is in flight.
118
+ - `'auto'`: continues once the page is visible AND focused (`document.hasFocus()`), triggered by the same events and by a 150 ms poll starting `fallbackMs` (default 2500) after the fire, up to `fallbackMaxMs` (15000).
119
119
 
120
120
  No re-fire happens after either navigates.
121
121
 
@@ -62,7 +62,8 @@ export declare class IabEscape {
62
62
  private wentAway;
63
63
  private locked;
64
64
  private dismissed;
65
- private fallbackSeq;
65
+ private continuing;
66
+ private contArmed;
66
67
  private base;
67
68
  constructor(options?: Partial<IabEscapeOptions> | undefined);
68
69
  private get o();
@@ -90,12 +91,17 @@ export declare class IabEscape {
90
91
  dismiss(): void;
91
92
  /** "Continue here": navigate the current webview to the destination, keeping the loader (no destination: just dismiss). */
92
93
  continue(): void;
94
+ /** Navigates the webview. The overlay stays until the page unloads: no bare host page in between. */
95
+ private go;
93
96
  private continueTarget;
94
97
  /**
95
- * 'auto' fallback: if the page is still here after the fire, continue in the webview. A native confirm may leave
96
- * the page 'visible' with timers running, so only continue when it is visible AND focused; else re-check.
98
+ * Continue in the webview after the scheme fired ('parallel': at once / after parallelDelayMs; 'auto': once the
99
+ * page is visible AND focused). A location.href issued while the app's native prompt is open is dropped, so the
100
+ * navigation is re-issued when the user is back on the page (focus, visible, pageshow, pointer/touch; debounced),
101
+ * plus one safety retry at SAFETY_MS ('parallel'). All retries stop on pagehide; none while a beforeunload
102
+ * says a navigation is in flight. 'auto' also polls every AUTO_RECHECK_MS as a backstop.
97
103
  */
98
- private armAutoFallback;
104
+ private armContinue;
99
105
  private fallback;
100
106
  private delay;
101
107
  /** One automatic fire: escape(), count it, start watching for re-entry, reveal the button soon after. */
package/dist/IabEscape.js CHANGED
@@ -216,20 +216,23 @@ var WATCH_MS = 3000;
216
216
  var REVEAL_MS = 800;
217
217
  var REENTER_LOCK_MS = 1000;
218
218
  var AUTO_RECHECK_MS = 150;
219
+ var DEBOUNCE_MS = 300;
220
+ var SAFETY_MS = 4000;
219
221
  var FIRED = "__iabEscapeFired";
220
222
  var hasParam = (url, key) => new URLSearchParams(url.split("#")[0].split("?")[1] ?? "").has(key);
221
223
 
222
224
  class IabEscape {
223
225
  options;
224
- static version = "0.5.0";
225
- static buildTime = "2026-11-17T10:56:42.504Z";
226
+ static version = "0.6.0";
227
+ static buildTime = "2026-11-17T11:15:12.535Z";
226
228
  ldr = null;
227
229
  fires = 0;
228
230
  watching = false;
229
231
  wentAway = false;
230
232
  locked = false;
231
233
  dismissed = false;
232
- fallbackSeq = 0;
234
+ continuing = false;
235
+ contArmed = false;
233
236
  base = "";
234
237
  constructor(options) {
235
238
  this.options = options;
@@ -343,10 +346,16 @@ class IabEscape {
343
346
  const to = this.continueTarget();
344
347
  if (!to)
345
348
  return this.dismiss();
346
- this.dismissed = true;
347
- if (this.o.ui)
348
- this.loader().continuing();
349
- this.state("continuing");
349
+ this.go(to);
350
+ }
351
+ go(to) {
352
+ if (!this.continuing) {
353
+ this.continuing = true;
354
+ this.dismissed = true;
355
+ if (this.o.ui)
356
+ this.loader().continuing();
357
+ this.state("continuing");
358
+ }
350
359
  this.win.location.href = to;
351
360
  }
352
361
  continueTarget() {
@@ -360,16 +369,62 @@ class IabEscape {
360
369
  return null;
361
370
  }
362
371
  }
363
- armAutoFallback() {
372
+ armContinue(mode) {
373
+ const to = this.continueTarget();
374
+ if (this.contArmed || !to)
375
+ return;
376
+ this.contArmed = true;
364
377
  const { win } = this;
365
378
  const doc = win.document;
366
- const seq = ++this.fallbackSeq;
379
+ const focused = () => doc.visibilityState === "visible" && (doc.hasFocus?.() ?? true);
380
+ let started = false, gone = false, flight = false, quiet = false;
381
+ const stopped = () => gone || flight || this.dismissed && !this.continuing;
382
+ const go = () => {
383
+ started = true;
384
+ this.go(to);
385
+ };
386
+ const retry = () => {
387
+ if (stopped() || quiet || mode === "parallel" && !started)
388
+ return;
389
+ if (mode === "auto" && (this.wentAway || !focused()))
390
+ return;
391
+ quiet = true;
392
+ win.setTimeout(() => {
393
+ quiet = false;
394
+ }, DEBOUNCE_MS);
395
+ go();
396
+ };
397
+ win.addEventListener("focus", retry);
398
+ win.addEventListener("pageshow", retry);
399
+ doc.addEventListener("visibilitychange", () => {
400
+ if (doc.visibilityState === "visible")
401
+ retry();
402
+ });
403
+ doc.addEventListener("pointerdown", retry, true);
404
+ doc.addEventListener("touchstart", retry, true);
405
+ win.addEventListener("pagehide", () => {
406
+ gone = true;
407
+ });
408
+ win.addEventListener("beforeunload", () => {
409
+ flight = true;
410
+ });
411
+ if (mode === "parallel") {
412
+ win.setTimeout(() => {
413
+ if (!stopped())
414
+ go();
415
+ }, this.o.parallelDelayMs);
416
+ win.setTimeout(() => {
417
+ if (started && !stopped())
418
+ go();
419
+ }, SAFETY_MS);
420
+ return;
421
+ }
367
422
  let waited = this.o.fallbackMs;
368
423
  const check = () => {
369
- if (seq !== this.fallbackSeq || this.dismissed || this.wentAway)
424
+ if (stopped() || started || this.wentAway)
370
425
  return;
371
- if (doc.visibilityState === "visible" && (doc.hasFocus?.() ?? true))
372
- return this.continue();
426
+ if (focused())
427
+ return go();
373
428
  waited += AUTO_RECHECK_MS;
374
429
  if (waited <= this.o.fallbackMaxMs)
375
430
  win.setTimeout(check, AUTO_RECHECK_MS);
@@ -396,10 +451,8 @@ class IabEscape {
396
451
  if (!this.dismissed)
397
452
  this.fallback();
398
453
  }, REVEAL_MS);
399
- if (this.o.fallback === "auto")
400
- this.armAutoFallback();
401
- if (this.o.fallback === "parallel" && this.continueTarget())
402
- this.win.setTimeout(() => this.continue(), this.o.parallelDelayMs);
454
+ if (this.o.fallback === "auto" || this.o.fallback === "parallel")
455
+ this.armContinue(this.o.fallback);
403
456
  return true;
404
457
  }
405
458
  watchReentry() {
@@ -1,4 +1,4 @@
1
- (()=>{var{defineProperty:u,getOwnPropertyNames:A,getOwnPropertyDescriptor:L}=Object,M=Object.prototype.hasOwnProperty;function O(e){return this[e]}var S=(e)=>{var t=(d??=new WeakMap).get(e),i;if(t)return t;if(t=u({},"__esModule",{value:!0}),e&&typeof e==="object"||typeof e==="function"){for(var n of A(e))if(!M.call(t,n))u(t,n,{get:O.bind(e,n),enumerable:!(i=L(e,n))||i.enumerable})}return d.set(e,t),t},d;var _=(e)=>e;function R(e,t){this[e]=_.bind(null,t)}var I=(e,t)=>{for(var i in t)u(e,i,{get:t[i],enumerable:!0,configurable:!0,set:R.bind(t,i)})};var D={};I(D,{boot:()=>x});var U=[["threads",/Barcelona/],["instagram",/Instagram/],["messenger",/FBAN\/MessengerForiOS|FB_IAB\/MESSENGER|Orca/],["facebook",/FBAN|FBAV|FB_IAB/]];function h(e){let t=U.find(([,n])=>n.test(e))?.[0]??null,i=/iPhone|iPad|iPod/.test(e)?"ios":/Android/.test(e)?"android":null;return{app:t,os:i,inApp:t!==null}}var b={opening:"Opening in your browser…",open:"Open in browser",stay:"Continue here",continuing:"Opening…"},f={bg:"--iab-bg",fg:"--iab-fg",accent:"--iab-accent",accentFg:"--iab-accent-fg",radius:"--iab-radius",font:"--iab-font"};class p{doc;labels;theme;onStay;root=null;open;stay;spin;msg;constructor(e,t,i={},n){this.doc=e;this.labels=t;this.theme=i;this.onStay=n}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,i){let n=this.doc.createElement(e);if(n.className=t,i)n.textContent=i;return n}build(){let e=this.el("div","");e.id="iab-escape",e.setAttribute("role","status");let t=Object.keys(f).filter((s)=>this.theme[s]).map((s)=>`${f[s]}:${this.theme[s]}`).join(";");if(t)e.setAttribute("style",t);let i=this.doc.createElement("style");i.textContent=`
1
+ (()=>{var{defineProperty:f,getOwnPropertyNames:R,getOwnPropertyDescriptor:I}=Object,U=Object.prototype.hasOwnProperty;function N(e){return this[e]}var F=(e)=>{var t=(v??=new WeakMap).get(e),i;if(t)return t;if(t=f({},"__esModule",{value:!0}),e&&typeof e==="object"||typeof e==="function"){for(var n of R(e))if(!U.call(t,n))f(t,n,{get:N.bind(e,n),enumerable:!(i=I(e,n))||i.enumerable})}return v.set(e,t),t},v;var C=(e)=>e;function P(e,t){this[e]=C.bind(null,t)}var D=(e,t)=>{for(var i in t)f(e,i,{get:t[i],enumerable:!0,configurable:!0,set:P.bind(t,i)})};var K={};D(K,{boot:()=>S});var B=[["threads",/Barcelona/],["instagram",/Instagram/],["messenger",/FBAN\/MessengerForiOS|FB_IAB\/MESSENGER|Orca/],["facebook",/FBAN|FBAV|FB_IAB/]];function y(e){let t=B.find(([,n])=>n.test(e))?.[0]??null,i=/iPhone|iPad|iPod/.test(e)?"ios":/Android/.test(e)?"android":null;return{app:t,os:i,inApp:t!==null}}var w={opening:"Opening in your browser…",open:"Open in browser",stay:"Continue here",continuing:"Opening…"},E={bg:"--iab-bg",fg:"--iab-fg",accent:"--iab-accent",accentFg:"--iab-accent-fg",radius:"--iab-radius",font:"--iab-font"};class b{doc;labels;theme;onStay;root=null;open;stay;spin;msg;constructor(e,t,i={},n){this.doc=e;this.labels=t;this.theme=i;this.onStay=n}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,i){let n=this.doc.createElement(e);if(n.className=t,i)n.textContent=i;return n}build(){let e=this.el("div","");e.id="iab-escape",e.setAttribute("role","status");let t=Object.keys(E).filter((s)=>this.theme[s]).map((s)=>`${E[s]}:${this.theme[s]}`).join(";");if(t)e.setAttribute("style",t);let i=this.doc.createElement("style");i.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 n=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[i,this.spin,n,this.open,this.stay])e.appendChild(s);(this.doc.body??this.doc.documentElement).appendChild(e),this.root=e}}var m=(e)=>e.protocol==="https:"?"x-safari-"+e.href:null,g=(e)=>(t)=>`${e}://extbrowser/?url=${encodeURIComponent(t.href)}`,v=(e)=>`intent://${e.noHash.replace(/^https?:\/\//i,"")}#Intent;scheme=${e.protocol.slice(0,-1)};end`;var y=[{app:"instagram",os:"ios",proven:!0,delayMs:0,build:g("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:m,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:v,testedOn:{date:"2026-11-16",os:"Android 16",app:"Facebook 587.0.0.39.55"}},{app:"instagram",os:"android",proven:!1,delayMs:0,build:v,testedOn:null},{app:"threads",os:"ios",proven:!1,delayMs:0,build:g("barcelona"),testedOn:null},{app:"messenger",os:"ios",proven:!1,delayMs:1500,build:m,testedOn:null}];class k{url=null;userAgent=null;delayMs=null;includeUnproven=!1;markParam="iab_escaped";onAttempt=null;onResult=null;ui=!0;labels={};theme={};onState=null;continueUrl=null;fallback="manual";fallbackMs=2500;parallelDelayMs=0;fallbackMaxMs=15000;maxAutoFires=3;window=null}function T(e){let t={},i=e.delayMs?.trim();if(i&&Number.isFinite(Number(i))&&Number(i)>=0)t.delayMs=Number(i);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")t.fallback=e.fallback;let n=e.parallelDelayMs?.trim();if(n&&Number.isFinite(Number(n))&&Number(n)>=0)t.parallelDelayMs=Number(n);let s=e.fallbackMs?.trim();if(s&&Number.isFinite(Number(s))&&Number(s)>=0)t.fallbackMs=Number(s);if(e.ui!==void 0)t.ui=e.ui!=="false";let a={};if(e.accent)a.accent=e.accent;if(e.bg)a.bg=e.bg;if(e.fg)a.fg=e.fg;if(Object.keys(a).length)t.theme=a;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 F=3000,N=800,P=1000,w=150,l="__iabEscapeFired",E=(e,t)=>new URLSearchParams(e.split("#")[0].split("?")[1]??"").has(t);class c{options;static version="0.5.0";static buildTime="2026-11-17T10:56:42.504Z";ldr=null;fires=0;watching=!1;wentAway=!1;locked=!1;dismissed=!1;fallbackSeq=0;base="";constructor(e){this.options=e;this.options={...new k,...e}}get o(){return this.options}get win(){return this.o.window??globalThis.window}detect(){return h(this.o.userAgent??this.win.navigator.userAgent)}getRule(){let{app:e,os:t}=this.detect(),i=y.find((n)=>n.app===e&&n.os===t);return i&&(i.proven||this.o.includeUnproven)?i: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,i;try{i=new URL(t,e)}catch{return null}if(!/^https?:$/.test(i.protocol))return null;let n=/^https?:\/\//i.test(t)?t:i.href,s=n.indexOf("#"),a=s<0?n:n.slice(0,s),r=s<0?"":n.slice(s),o=this.o.markParam;if(o&&!E(a,o))a+=(a.includes("?")?/[?&]$/.test(a)?"":"&":"?")+o+"=1";return{href:a+r,noHash:a,protocol:i.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,i=this.getRule();if(!i||e[l]||t&&E(e.location.href,t))return()=>{};e[l]=!0;let{document:n}=e;if(this.dismissed=!1,this.o.ui)this.loader().show();this.state("opening");let s=!1,a,r=()=>{if(s=!0,!this.fireNow())e[l]=!1},o=()=>{if(n.removeEventListener("DOMContentLoaded",o),this.delay(i)<=0)r();else a=e.setTimeout(r,this.delay(i))};if(n.readyState==="loading")n.addEventListener("DOMContentLoaded",o);else o();return()=>{if(s)return;if(n.removeEventListener("DOMContentLoaded",o),a!==void 0)e.clearTimeout(a);e[l]=!1,this.ldr?.hide()}}loader(){return this.ldr??=new p(this.win.document,{...b,...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();if(this.dismissed=!0,this.o.ui)this.loader().continuing();this.state("continuing"),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}}armAutoFallback(){let{win:e}=this,t=e.document,i=++this.fallbackSeq,n=this.o.fallbackMs,s=()=>{if(i!==this.fallbackSeq||this.dismissed||this.wentAway)return;if(t.visibilityState==="visible"&&(t.hasFocus?.()??!0))return this.continue();if(n+=w,n<=this.o.fallbackMaxMs)e.setTimeout(s,w)};e.setTimeout(s,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()},N),this.o.fallback==="auto")this.armAutoFallback();if(this.o.fallback==="parallel"&&this.continueTarget())this.win.setTimeout(()=>this.continue(),this.o.parallelDelayMs);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",(i)=>{if(i.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},P),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,i=!1,n=()=>{i=!0},s=()=>{if(t.document.visibilityState==="hidden")n()};t.addEventListener("pagehide",n),t.document.addEventListener("visibilitychange",s),t.setTimeout(()=>{t.removeEventListener("pagehide",n),t.document.removeEventListener("visibilitychange",s),this.o.onResult?.({...e,outcome:i?"left":"stayed-or-unknown"})},F)}}function x(e,t,i={}){t.IabEscape=c;let n=e?.currentScript;if(n?.hasAttribute("data-auto"))new c({...T(n.dataset),...i}).auto()}if(typeof document<"u")x(document,globalThis);})();
11
+ @media (prefers-reduced-motion:reduce){#iab-escape .ie-spin{animation:none}}`,this.spin=this.el("div","ie-spin");let n=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[i,this.spin,n,this.open,this.stay])e.appendChild(s);(this.doc.body??this.doc.documentElement).appendChild(e),this.root=e}}var T=(e)=>e.protocol==="https:"?"x-safari-"+e.href:null,x=(e)=>(t)=>`${e}://extbrowser/?url=${encodeURIComponent(t.href)}`,k=(e)=>`intent://${e.noHash.replace(/^https?:\/\//i,"")}#Intent;scheme=${e.protocol.slice(0,-1)};end`;var L=[{app:"instagram",os:"ios",proven:!0,delayMs:0,build:x("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:T,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:k,testedOn:{date:"2026-11-16",os:"Android 16",app:"Facebook 587.0.0.39.55"}},{app:"instagram",os:"android",proven:!1,delayMs:0,build:k,testedOn:null},{app:"threads",os:"ios",proven:!1,delayMs:0,build:x("barcelona"),testedOn:null},{app:"messenger",os:"ios",proven:!1,delayMs:1500,build:T,testedOn:null}];class O{url=null;userAgent=null;delayMs=null;includeUnproven=!1;markParam="iab_escaped";onAttempt=null;onResult=null;ui=!0;labels={};theme={};onState=null;continueUrl=null;fallback="manual";fallbackMs=2500;parallelDelayMs=0;fallbackMaxMs=15000;maxAutoFires=3;window=null}function _(e){let t={},i=e.delayMs?.trim();if(i&&Number.isFinite(Number(i))&&Number(i)>=0)t.delayMs=Number(i);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")t.fallback=e.fallback;let n=e.parallelDelayMs?.trim();if(n&&Number.isFinite(Number(n))&&Number(n)>=0)t.parallelDelayMs=Number(n);let s=e.fallbackMs?.trim();if(s&&Number.isFinite(Number(s))&&Number(s)>=0)t.fallbackMs=Number(s);if(e.ui!==void 0)t.ui=e.ui!=="false";let a={};if(e.accent)a.accent=e.accent;if(e.bg)a.bg=e.bg;if(e.fg)a.fg=e.fg;if(Object.keys(a).length)t.theme=a;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 H=3000,V=800,j=1000,A=150,W=300,z=4000,p="__iabEscapeFired",M=(e,t)=>new URLSearchParams(e.split("#")[0].split("?")[1]??"").has(t);class d{options;static version="0.6.0";static buildTime="2026-11-17T11:15:12.535Z";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 O,...e}}get o(){return this.options}get win(){return this.o.window??globalThis.window}detect(){return y(this.o.userAgent??this.win.navigator.userAgent)}getRule(){let{app:e,os:t}=this.detect(),i=L.find((n)=>n.app===e&&n.os===t);return i&&(i.proven||this.o.includeUnproven)?i: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,i;try{i=new URL(t,e)}catch{return null}if(!/^https?:$/.test(i.protocol))return null;let n=/^https?:\/\//i.test(t)?t:i.href,s=n.indexOf("#"),a=s<0?n:n.slice(0,s),r=s<0?"":n.slice(s),o=this.o.markParam;if(o&&!M(a,o))a+=(a.includes("?")?/[?&]$/.test(a)?"":"&":"?")+o+"=1";return{href:a+r,noHash:a,protocol:i.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,i=this.getRule();if(!i||e[p]||t&&M(e.location.href,t))return()=>{};e[p]=!0;let{document:n}=e;if(this.dismissed=!1,this.o.ui)this.loader().show();this.state("opening");let s=!1,a,r=()=>{if(s=!0,!this.fireNow())e[p]=!1},o=()=>{if(n.removeEventListener("DOMContentLoaded",o),this.delay(i)<=0)r();else a=e.setTimeout(r,this.delay(i))};if(n.readyState==="loading")n.addEventListener("DOMContentLoaded",o);else o();return()=>{if(s)return;if(n.removeEventListener("DOMContentLoaded",o),a!==void 0)e.clearTimeout(a);e[p]=!1,this.ldr?.hide()}}loader(){return this.ldr??=new b(this.win.document,{...w,...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)}go(e){if(!this.continuing){if(this.continuing=!0,this.dismissed=!0,this.o.ui)this.loader().continuing();this.state("continuing")}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{win:i}=this,n=i.document,s=()=>n.visibilityState==="visible"&&(n.hasFocus?.()??!0),a=!1,r=!1,o=!1,h=!1,u=()=>r||o||this.dismissed&&!this.continuing,c=()=>{a=!0,this.go(t)},l=()=>{if(u()||h||e==="parallel"&&!a)return;if(e==="auto"&&(this.wentAway||!s()))return;h=!0,i.setTimeout(()=>{h=!1},W),c()};if(i.addEventListener("focus",l),i.addEventListener("pageshow",l),n.addEventListener("visibilitychange",()=>{if(n.visibilityState==="visible")l()}),n.addEventListener("pointerdown",l,!0),n.addEventListener("touchstart",l,!0),i.addEventListener("pagehide",()=>{r=!0}),i.addEventListener("beforeunload",()=>{o=!0}),e==="parallel"){i.setTimeout(()=>{if(!u())c()},this.o.parallelDelayMs),i.setTimeout(()=>{if(a&&!u())c()},z);return}let g=this.o.fallbackMs,m=()=>{if(u()||a||this.wentAway)return;if(s())return c();if(g+=A,g<=this.o.fallbackMaxMs)i.setTimeout(m,A)};i.setTimeout(m,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()},V),this.o.fallback==="auto"||this.o.fallback==="parallel")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",(i)=>{if(i.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},j),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,i=!1,n=()=>{i=!0},s=()=>{if(t.document.visibilityState==="hidden")n()};t.addEventListener("pagehide",n),t.document.addEventListener("visibilitychange",s),t.setTimeout(()=>{t.removeEventListener("pagehide",n),t.document.removeEventListener("visibilitychange",s),this.o.onResult?.({...e,outcome:i?"left":"stayed-or-unknown"})},H)}}function S(e,t,i={}){t.IabEscape=d;let n=e?.currentScript;if(n?.hasAttribute("data-auto"))new d({..._(n.dataset),...i}).auto()}if(typeof document<"u")S(document,globalThis);})();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@livx.cc/iab-escape",
3
- "version": "0.5.0",
3
+ "version": "0.6.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",