@livx.cc/iab-escape 0.5.0 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -2
- package/dist/IabEscape.d.ts +15 -5
- package/dist/IabEscape.js +89 -17
- package/dist/iab-escape.min.js +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -114,8 +114,10 @@ myUi.onContinue(() => esc.dismiss());
|
|
|
114
114
|
|
|
115
115
|
`fallback` (`data-fallback`), default `'manual'`:
|
|
116
116
|
|
|
117
|
-
- `'
|
|
118
|
-
- `'
|
|
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
|
+
|
|
120
|
+
- `'retry'` (experimental): re-issues the destination navigation every `retryMs` (`data-retry-ms`, default 400) until `pagehide`/`beforeunload` or 15 s. `onContinue(url, reason)` reports every navigation the lib issues (diagnostics).
|
|
119
121
|
|
|
120
122
|
No re-fire happens after either navigates.
|
|
121
123
|
|
package/dist/IabEscape.d.ts
CHANGED
|
@@ -36,11 +36,15 @@ export declare class IabEscapeOptions {
|
|
|
36
36
|
/** Where "Continue here" (and the auto fallback) navigates the webview. Default: `url`; none -> just dismiss. */
|
|
37
37
|
continueUrl: string | null;
|
|
38
38
|
/** 'auto': if the page did not go away after the fire, continue in the webview by itself. Device-unverified. */
|
|
39
|
-
fallback: 'manual' | 'auto' | 'parallel';
|
|
39
|
+
fallback: 'manual' | 'auto' | 'parallel' | 'retry';
|
|
40
40
|
/** 'auto' only: wait this long after the fire before the first check. */
|
|
41
41
|
fallbackMs: number;
|
|
42
42
|
/** 'parallel' only: navigate to the destination this long after the scheme fires, whatever the confirm answer. */
|
|
43
43
|
parallelDelayMs: number;
|
|
44
|
+
/** 'retry' (experimental): re-issue the destination navigation this often, until unload or 15 s. */
|
|
45
|
+
retryMs: number;
|
|
46
|
+
/** Called for every navigation to the destination the lib issues (diagnostics). */
|
|
47
|
+
onContinue: ((url: string, reason: string) => void) | null;
|
|
44
48
|
/** 'auto' only: stop re-checking (every 500 ms while the page is unfocused or hidden) this long after the fire. */
|
|
45
49
|
fallbackMaxMs: number;
|
|
46
50
|
/** Max automatic fires per page lifetime (the first fire + re-entry re-fires). */
|
|
@@ -62,7 +66,8 @@ export declare class IabEscape {
|
|
|
62
66
|
private wentAway;
|
|
63
67
|
private locked;
|
|
64
68
|
private dismissed;
|
|
65
|
-
private
|
|
69
|
+
private continuing;
|
|
70
|
+
private contArmed;
|
|
66
71
|
private base;
|
|
67
72
|
constructor(options?: Partial<IabEscapeOptions> | undefined);
|
|
68
73
|
private get o();
|
|
@@ -90,12 +95,17 @@ export declare class IabEscape {
|
|
|
90
95
|
dismiss(): void;
|
|
91
96
|
/** "Continue here": navigate the current webview to the destination, keeping the loader (no destination: just dismiss). */
|
|
92
97
|
continue(): void;
|
|
98
|
+
/** Navigates the webview. The overlay stays until the page unloads: no bare host page in between. */
|
|
99
|
+
private go;
|
|
93
100
|
private continueTarget;
|
|
94
101
|
/**
|
|
95
|
-
*
|
|
96
|
-
*
|
|
102
|
+
* Continue in the webview after the scheme fired ('parallel': at once / after parallelDelayMs; 'auto': once the
|
|
103
|
+
* page is visible AND focused). A location.href issued while the app's native prompt is open is dropped, so the
|
|
104
|
+
* navigation is re-issued when the user is back on the page (focus, visible, pageshow, pointer/touch; debounced),
|
|
105
|
+
* plus one safety retry at SAFETY_MS ('parallel'). All retries stop on pagehide; none while a beforeunload
|
|
106
|
+
* says a navigation is in flight. 'auto' also polls every AUTO_RECHECK_MS as a backstop.
|
|
97
107
|
*/
|
|
98
|
-
private
|
|
108
|
+
private armContinue;
|
|
99
109
|
private fallback;
|
|
100
110
|
private delay;
|
|
101
111
|
/** One automatic fire: escape(), count it, start watching for re-entry, reveal the button soon after. */
|
package/dist/IabEscape.js
CHANGED
|
@@ -163,6 +163,8 @@ class IabEscapeOptions {
|
|
|
163
163
|
fallback = "manual";
|
|
164
164
|
fallbackMs = 2500;
|
|
165
165
|
parallelDelayMs = 0;
|
|
166
|
+
retryMs = 400;
|
|
167
|
+
onContinue = null;
|
|
166
168
|
fallbackMaxMs = 15000;
|
|
167
169
|
maxAutoFires = 3;
|
|
168
170
|
window = null;
|
|
@@ -180,8 +182,11 @@ function optionsFromDataset(d) {
|
|
|
180
182
|
o.url = d.url;
|
|
181
183
|
if (d.continueUrl)
|
|
182
184
|
o.continueUrl = d.continueUrl;
|
|
183
|
-
if (d.fallback === "auto" || d.fallback === "manual" || d.fallback === "parallel")
|
|
185
|
+
if (d.fallback === "auto" || d.fallback === "manual" || d.fallback === "parallel" || d.fallback === "retry")
|
|
184
186
|
o.fallback = d.fallback;
|
|
187
|
+
const rm = d.retryMs?.trim();
|
|
188
|
+
if (rm && Number.isFinite(Number(rm)) && Number(rm) > 0)
|
|
189
|
+
o.retryMs = Number(rm);
|
|
185
190
|
const pd = d.parallelDelayMs?.trim();
|
|
186
191
|
if (pd && Number.isFinite(Number(pd)) && Number(pd) >= 0)
|
|
187
192
|
o.parallelDelayMs = Number(pd);
|
|
@@ -216,20 +221,24 @@ var WATCH_MS = 3000;
|
|
|
216
221
|
var REVEAL_MS = 800;
|
|
217
222
|
var REENTER_LOCK_MS = 1000;
|
|
218
223
|
var AUTO_RECHECK_MS = 150;
|
|
224
|
+
var DEBOUNCE_MS = 300;
|
|
225
|
+
var SAFETY_MS = 4000;
|
|
226
|
+
var RETRY_MAX_MS = 15000;
|
|
219
227
|
var FIRED = "__iabEscapeFired";
|
|
220
228
|
var hasParam = (url, key) => new URLSearchParams(url.split("#")[0].split("?")[1] ?? "").has(key);
|
|
221
229
|
|
|
222
230
|
class IabEscape {
|
|
223
231
|
options;
|
|
224
|
-
static version = "0.
|
|
225
|
-
static buildTime = "2026-11-
|
|
232
|
+
static version = "0.6.1";
|
|
233
|
+
static buildTime = "2026-11-17T11:22:50.431Z";
|
|
226
234
|
ldr = null;
|
|
227
235
|
fires = 0;
|
|
228
236
|
watching = false;
|
|
229
237
|
wentAway = false;
|
|
230
238
|
locked = false;
|
|
231
239
|
dismissed = false;
|
|
232
|
-
|
|
240
|
+
continuing = false;
|
|
241
|
+
contArmed = false;
|
|
233
242
|
base = "";
|
|
234
243
|
constructor(options) {
|
|
235
244
|
this.options = options;
|
|
@@ -343,10 +352,17 @@ class IabEscape {
|
|
|
343
352
|
const to = this.continueTarget();
|
|
344
353
|
if (!to)
|
|
345
354
|
return this.dismiss();
|
|
346
|
-
this.
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
this.
|
|
355
|
+
this.go(to, "tap");
|
|
356
|
+
}
|
|
357
|
+
go(to, reason) {
|
|
358
|
+
if (!this.continuing) {
|
|
359
|
+
this.continuing = true;
|
|
360
|
+
this.dismissed = true;
|
|
361
|
+
if (this.o.ui)
|
|
362
|
+
this.loader().continuing();
|
|
363
|
+
this.state("continuing");
|
|
364
|
+
}
|
|
365
|
+
this.o.onContinue?.(to, reason);
|
|
350
366
|
this.win.location.href = to;
|
|
351
367
|
}
|
|
352
368
|
continueTarget() {
|
|
@@ -360,16 +376,74 @@ class IabEscape {
|
|
|
360
376
|
return null;
|
|
361
377
|
}
|
|
362
378
|
}
|
|
363
|
-
|
|
379
|
+
armContinue(mode) {
|
|
380
|
+
const to = this.continueTarget();
|
|
381
|
+
if (this.contArmed || !to)
|
|
382
|
+
return;
|
|
383
|
+
this.contArmed = true;
|
|
364
384
|
const { win } = this;
|
|
365
385
|
const doc = win.document;
|
|
366
|
-
const
|
|
386
|
+
const focused = () => doc.visibilityState === "visible" && (doc.hasFocus?.() ?? true);
|
|
387
|
+
let started = false, gone = false, flight = false, quiet = false;
|
|
388
|
+
const stopped = () => gone || flight || this.dismissed && !this.continuing;
|
|
389
|
+
const go = (reason) => {
|
|
390
|
+
started = true;
|
|
391
|
+
this.go(to, reason);
|
|
392
|
+
};
|
|
393
|
+
const retry = (reason) => {
|
|
394
|
+
if (stopped() || quiet || mode === "parallel" && !started)
|
|
395
|
+
return;
|
|
396
|
+
if (mode === "auto" && (this.wentAway || !focused()))
|
|
397
|
+
return;
|
|
398
|
+
quiet = true;
|
|
399
|
+
win.setTimeout(() => {
|
|
400
|
+
quiet = false;
|
|
401
|
+
}, DEBOUNCE_MS);
|
|
402
|
+
go(reason);
|
|
403
|
+
};
|
|
404
|
+
win.addEventListener("pagehide", () => {
|
|
405
|
+
gone = true;
|
|
406
|
+
});
|
|
407
|
+
win.addEventListener("beforeunload", () => {
|
|
408
|
+
flight = true;
|
|
409
|
+
});
|
|
410
|
+
if (mode === "retry") {
|
|
411
|
+
let elapsed = 0;
|
|
412
|
+
const tick = () => {
|
|
413
|
+
if (stopped() || elapsed > RETRY_MAX_MS)
|
|
414
|
+
return;
|
|
415
|
+
go("retry");
|
|
416
|
+
elapsed += this.o.retryMs;
|
|
417
|
+
win.setTimeout(tick, this.o.retryMs);
|
|
418
|
+
};
|
|
419
|
+
tick();
|
|
420
|
+
return;
|
|
421
|
+
}
|
|
422
|
+
win.addEventListener("focus", () => retry("focus"));
|
|
423
|
+
win.addEventListener("pageshow", () => retry("pageshow"));
|
|
424
|
+
doc.addEventListener("visibilitychange", () => {
|
|
425
|
+
if (doc.visibilityState === "visible")
|
|
426
|
+
retry("visible");
|
|
427
|
+
});
|
|
428
|
+
doc.addEventListener("pointerdown", () => retry("pointerdown"), true);
|
|
429
|
+
doc.addEventListener("touchstart", () => retry("touchstart"), true);
|
|
430
|
+
if (mode === "parallel") {
|
|
431
|
+
win.setTimeout(() => {
|
|
432
|
+
if (!stopped())
|
|
433
|
+
go("parallel");
|
|
434
|
+
}, this.o.parallelDelayMs);
|
|
435
|
+
win.setTimeout(() => {
|
|
436
|
+
if (started && !stopped())
|
|
437
|
+
go("safety");
|
|
438
|
+
}, SAFETY_MS);
|
|
439
|
+
return;
|
|
440
|
+
}
|
|
367
441
|
let waited = this.o.fallbackMs;
|
|
368
442
|
const check = () => {
|
|
369
|
-
if (
|
|
443
|
+
if (stopped() || started || this.wentAway)
|
|
370
444
|
return;
|
|
371
|
-
if (
|
|
372
|
-
return
|
|
445
|
+
if (focused())
|
|
446
|
+
return go("poll");
|
|
373
447
|
waited += AUTO_RECHECK_MS;
|
|
374
448
|
if (waited <= this.o.fallbackMaxMs)
|
|
375
449
|
win.setTimeout(check, AUTO_RECHECK_MS);
|
|
@@ -396,10 +470,8 @@ class IabEscape {
|
|
|
396
470
|
if (!this.dismissed)
|
|
397
471
|
this.fallback();
|
|
398
472
|
}, REVEAL_MS);
|
|
399
|
-
if (this.o.fallback === "auto")
|
|
400
|
-
this.
|
|
401
|
-
if (this.o.fallback === "parallel" && this.continueTarget())
|
|
402
|
-
this.win.setTimeout(() => this.continue(), this.o.parallelDelayMs);
|
|
473
|
+
if (this.o.fallback === "auto" || this.o.fallback === "parallel" || this.o.fallback === "retry")
|
|
474
|
+
this.armContinue(this.o.fallback);
|
|
403
475
|
return true;
|
|
404
476
|
}
|
|
405
477
|
watchReentry() {
|
package/dist/iab-escape.min.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(()=>{var{defineProperty:
|
|
1
|
+
(()=>{var{defineProperty:b,getOwnPropertyNames:N,getOwnPropertyDescriptor:U}=Object,F=Object.prototype.hasOwnProperty;function C(e){return this[e]}var P=(e)=>{var t=(E??=new WeakMap).get(e),i;if(t)return t;if(t=b({},"__esModule",{value:!0}),e&&typeof e==="object"||typeof e==="function"){for(var n of N(e))if(!F.call(t,n))b(t,n,{get:C.bind(e,n),enumerable:!(i=U(e,n))||i.enumerable})}return E.set(e,t),t},E;var D=(e)=>e;function B(e,t){this[e]=D.bind(null,t)}var H=(e,t)=>{for(var i in t)b(e,i,{get:t[i],enumerable:!0,configurable:!0,set:B.bind(t,i)})};var q={};H(q,{boot:()=>I});var V=[["threads",/Barcelona/],["instagram",/Instagram/],["messenger",/FBAN\/MessengerForiOS|FB_IAB\/MESSENGER|Orca/],["facebook",/FBAN|FBAV|FB_IAB/]];function w(e){let t=V.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 k={opening:"Opening in your browser…",open:"Open in browser",stay:"Continue here",continuing:"Opening…"},T={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,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(T).filter((s)=>this.theme[s]).map((s)=>`${T[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
|
|
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 x=(e)=>e.protocol==="https:"?"x-safari-"+e.href:null,L=(e)=>(t)=>`${e}://extbrowser/?url=${encodeURIComponent(t.href)}`,M=(e)=>`intent://${e.noHash.replace(/^https?:\/\//i,"")}#Intent;scheme=${e.protocol.slice(0,-1)};end`;var A=[{app:"instagram",os:"ios",proven:!0,delayMs:0,build:L("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:x,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:M,testedOn:{date:"2026-11-16",os:"Android 16",app:"Facebook 587.0.0.39.55"}},{app:"instagram",os:"android",proven:!1,delayMs:0,build:M,testedOn:null},{app:"threads",os:"ios",proven:!1,delayMs:0,build:L("barcelona"),testedOn:null},{app:"messenger",os:"ios",proven:!1,delayMs:1500,build:x,testedOn:null}];class S{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;retryMs=400;onContinue=null;fallbackMaxMs=15000;maxAutoFires=3;window=null}function R(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"||e.fallback==="retry")t.fallback=e.fallback;let n=e.retryMs?.trim();if(n&&Number.isFinite(Number(n))&&Number(n)>0)t.retryMs=Number(n);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 j=3000,W=800,X=1000,O=150,z=300,K=4000,Y=15000,d="__iabEscapeFired",_=(e,t)=>new URLSearchParams(e.split("#")[0].split("?")[1]??"").has(t);class h{options;static version="0.6.1";static buildTime="2026-11-17T11:22:50.431Z";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 S,...e}}get o(){return this.options}get win(){return this.o.window??globalThis.window}detect(){return w(this.o.userAgent??this.win.navigator.userAgent)}getRule(){let{app:e,os:t}=this.detect(),i=A.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),o=s<0?"":n.slice(s),r=this.o.markParam;if(r&&!_(a,r))a+=(a.includes("?")?/[?&]$/.test(a)?"":"&":"?")+r+"=1";return{href:a+o,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[d]||t&&_(e.location.href,t))return()=>{};e[d]=!0;let{document:n}=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[d]=!1},r=()=>{if(n.removeEventListener("DOMContentLoaded",r),this.delay(i)<=0)o();else a=e.setTimeout(o,this.delay(i))};if(n.readyState==="loading")n.addEventListener("DOMContentLoaded",r);else r();return()=>{if(s)return;if(n.removeEventListener("DOMContentLoaded",r),a!==void 0)e.clearTimeout(a);e[d]=!1,this.ldr?.hide()}}loader(){return this.ldr??=new g(this.win.document,{...k,...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{win:i}=this,n=i.document,s=()=>n.visibilityState==="visible"&&(n.hasFocus?.()??!0),a=!1,o=!1,r=!1,f=!1,u=()=>o||r||this.dismissed&&!this.continuing,c=(l)=>{a=!0,this.go(t,l)},p=(l)=>{if(u()||f||e==="parallel"&&!a)return;if(e==="auto"&&(this.wentAway||!s()))return;f=!0,i.setTimeout(()=>{f=!1},z),c(l)};if(i.addEventListener("pagehide",()=>{o=!0}),i.addEventListener("beforeunload",()=>{r=!0}),e==="retry"){let l=0,y=()=>{if(u()||l>Y)return;c("retry"),l+=this.o.retryMs,i.setTimeout(y,this.o.retryMs)};y();return}if(i.addEventListener("focus",()=>p("focus")),i.addEventListener("pageshow",()=>p("pageshow")),n.addEventListener("visibilitychange",()=>{if(n.visibilityState==="visible")p("visible")}),n.addEventListener("pointerdown",()=>p("pointerdown"),!0),n.addEventListener("touchstart",()=>p("touchstart"),!0),e==="parallel"){i.setTimeout(()=>{if(!u())c("parallel")},this.o.parallelDelayMs),i.setTimeout(()=>{if(a&&!u())c("safety")},K);return}let m=this.o.fallbackMs,v=()=>{if(u()||a||this.wentAway)return;if(s())return c("poll");if(m+=O,m<=this.o.fallbackMaxMs)i.setTimeout(v,O)};i.setTimeout(v,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()},W),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",(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},X),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"})},j)}}function I(e,t,i={}){t.IabEscape=h;let n=e?.currentScript;if(n?.hasAttribute("data-auto"))new h({...R(n.dataset),...i}).auto()}if(typeof document<"u")I(document,globalThis);})();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@livx.cc/iab-escape",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.1",
|
|
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",
|