@livx.cc/iab-escape 0.1.0 → 0.2.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 +5 -1
- package/dist/IabEscape.d.ts +24 -1
- package/dist/IabEscape.js +169 -6
- package/dist/iab-escape.min.js +11 -1
- package/dist/loader.d.ts +25 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -24,7 +24,11 @@ Script tag, placed early in the page (no code):
|
|
|
24
24
|
<script src="iab-escape.min.js" data-auto></script>
|
|
25
25
|
```
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
The script tag shows a full-screen loader ("Opening in your browser…"), then an "Open in browser" button (a real link, works if the automatic fire was ignored) and a small "Continue here". Turn it off with `data-ui="false"`; in code it is the `ui: true` option, with text via `labels`. No loader when the app is not matched.
|
|
28
|
+
|
|
29
|
+
Re-entry: if the page comes back after it left (persisted `pageshow`, or hidden then visible), it fires again once per return, at most `maxAutoFires` (default 3) per page lifetime. If the user cancelled the app's dialog (the page never went away), it does not re-fire; the button stays. "Continue here" stops re-fires.
|
|
30
|
+
|
|
31
|
+
Optional attributes: `data-ui`, `data-delay-ms`, `data-mark-param` (empty = off), `data-include-unproven`, `data-url`.
|
|
28
32
|
|
|
29
33
|
npm:
|
|
30
34
|
|
package/dist/IabEscape.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type Env } from './detect';
|
|
2
|
+
import { type Labels } from './loader';
|
|
2
3
|
import { type Rule } from './matrix';
|
|
3
|
-
export type { Env, Rule };
|
|
4
|
+
export type { Env, Labels, Rule };
|
|
4
5
|
export interface AttemptInfo {
|
|
5
6
|
rule: Rule;
|
|
6
7
|
url: string;
|
|
@@ -21,6 +22,11 @@ export declare class IabEscapeOptions {
|
|
|
21
22
|
markParam: string | null;
|
|
22
23
|
onAttempt: ((info: AttemptInfo) => void) | null;
|
|
23
24
|
onResult: ((info: ResultInfo) => void) | null;
|
|
25
|
+
/** Show the full-screen loader (spinner, then an "Open in browser" button) while auto() runs. */
|
|
26
|
+
ui: boolean;
|
|
27
|
+
labels: Partial<Labels>;
|
|
28
|
+
/** Max automatic fires per page lifetime (the first fire + re-entry re-fires). */
|
|
29
|
+
maxAutoFires: number;
|
|
24
30
|
/** Injectable for tests. Default: globalThis.window. */
|
|
25
31
|
window: Window | null;
|
|
26
32
|
}
|
|
@@ -32,6 +38,12 @@ export declare class IabEscape {
|
|
|
32
38
|
static readonly version: string;
|
|
33
39
|
/** ISO build time (injected at build time), or null. */
|
|
34
40
|
static readonly buildTime: string | null;
|
|
41
|
+
private ldr;
|
|
42
|
+
private fires;
|
|
43
|
+
private watching;
|
|
44
|
+
private wentAway;
|
|
45
|
+
private locked;
|
|
46
|
+
private dismissed;
|
|
35
47
|
constructor(options?: Partial<IabEscapeOptions> | undefined);
|
|
36
48
|
private get o();
|
|
37
49
|
private get win();
|
|
@@ -50,6 +62,17 @@ export declare class IabEscape {
|
|
|
50
62
|
* Returns a cancel fn; cancelling before the fire re-arms the guard (StrictMode-safe).
|
|
51
63
|
*/
|
|
52
64
|
auto(): () => void;
|
|
65
|
+
private loader;
|
|
66
|
+
private delay;
|
|
67
|
+
/** One automatic fire: escape(), count it, start watching for re-entry, reveal the button soon after. */
|
|
68
|
+
private fireNow;
|
|
69
|
+
/**
|
|
70
|
+
* Re-entry: the page is shown again after a fire that left (pagehide/hidden seen, or a persisted pageshow,
|
|
71
|
+
* i.e. bfcache / restored webview). Re-fires ONCE per re-entry, up to maxAutoFires per page lifetime.
|
|
72
|
+
* A page that never went away (user pressed Cancel) is not re-fired; the button stays.
|
|
73
|
+
*/
|
|
74
|
+
private watchReentry;
|
|
75
|
+
private reenter;
|
|
53
76
|
/** Plain `<a>` tap path (proven on all three). Leaves the element untouched when there is no rule. */
|
|
54
77
|
bindLink(a: HTMLAnchorElement): boolean;
|
|
55
78
|
private watch;
|
package/dist/IabEscape.js
CHANGED
|
@@ -11,6 +11,84 @@ function detectEnv(ua) {
|
|
|
11
11
|
return { app, os, inApp: app !== null };
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
+
// src/loader.ts
|
|
15
|
+
var DEFAULT_LABELS = { opening: "Opening in your browser…", open: "Open in browser", stay: "Continue here" };
|
|
16
|
+
var CSS = `
|
|
17
|
+
#iab-escape{position:fixed;inset:0;z-index:2147483647;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:18px;
|
|
18
|
+
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));
|
|
19
|
+
background:#fff;color:#111;font:18px/1.35 -apple-system,system-ui,sans-serif;text-align:center}
|
|
20
|
+
#iab-escape .ie-spin{width:36px;height:36px;border:4px solid #8884;border-top-color:#07f;border-radius:50%;animation:ie-r 1s linear infinite}
|
|
21
|
+
#iab-escape a.ie-open{display:block;padding:14px 28px;border-radius:12px;background:#07f;color:#fff;text-decoration:none;font-weight:600}
|
|
22
|
+
#iab-escape a.ie-stay{font-size:14px;color:inherit;opacity:.7}
|
|
23
|
+
#iab-escape [hidden]{display:none}
|
|
24
|
+
@keyframes ie-r{to{transform:rotate(360deg)}}
|
|
25
|
+
@media (prefers-color-scheme:dark){#iab-escape{background:#111;color:#f2f2f2}}
|
|
26
|
+
@media (prefers-reduced-motion:reduce){#iab-escape .ie-spin{animation:none}}`;
|
|
27
|
+
|
|
28
|
+
class Loader {
|
|
29
|
+
doc;
|
|
30
|
+
labels;
|
|
31
|
+
onStay;
|
|
32
|
+
root = null;
|
|
33
|
+
open;
|
|
34
|
+
stay;
|
|
35
|
+
spin;
|
|
36
|
+
constructor(doc, labels, onStay) {
|
|
37
|
+
this.doc = doc;
|
|
38
|
+
this.labels = labels;
|
|
39
|
+
this.onStay = onStay;
|
|
40
|
+
}
|
|
41
|
+
get visible() {
|
|
42
|
+
return this.root !== null;
|
|
43
|
+
}
|
|
44
|
+
show() {
|
|
45
|
+
if (!this.root)
|
|
46
|
+
this.build();
|
|
47
|
+
this.spin.hidden = false;
|
|
48
|
+
this.open.hidden = true;
|
|
49
|
+
this.stay.hidden = true;
|
|
50
|
+
}
|
|
51
|
+
reveal(href) {
|
|
52
|
+
if (!this.root)
|
|
53
|
+
this.build();
|
|
54
|
+
this.open.href = href;
|
|
55
|
+
this.open.hidden = false;
|
|
56
|
+
this.stay.hidden = false;
|
|
57
|
+
}
|
|
58
|
+
hide() {
|
|
59
|
+
this.root?.remove();
|
|
60
|
+
this.root = null;
|
|
61
|
+
}
|
|
62
|
+
el(tag, cls, text) {
|
|
63
|
+
const e = this.doc.createElement(tag);
|
|
64
|
+
e.className = cls;
|
|
65
|
+
if (text)
|
|
66
|
+
e.textContent = text;
|
|
67
|
+
return e;
|
|
68
|
+
}
|
|
69
|
+
build() {
|
|
70
|
+
const root = this.el("div", "");
|
|
71
|
+
root.id = "iab-escape";
|
|
72
|
+
root.setAttribute("role", "status");
|
|
73
|
+
const style = this.doc.createElement("style");
|
|
74
|
+
style.textContent = CSS;
|
|
75
|
+
this.spin = this.el("div", "ie-spin");
|
|
76
|
+
const msg = this.el("div", "ie-msg", this.labels.opening);
|
|
77
|
+
this.open = this.el("a", "ie-open", this.labels.open);
|
|
78
|
+
this.stay = this.el("a", "ie-stay", this.labels.stay);
|
|
79
|
+
this.stay.href = "#";
|
|
80
|
+
this.stay.addEventListener("click", (ev) => {
|
|
81
|
+
ev.preventDefault();
|
|
82
|
+
this.hide();
|
|
83
|
+
this.onStay?.();
|
|
84
|
+
});
|
|
85
|
+
for (const c of [style, this.spin, msg, this.open, this.stay])
|
|
86
|
+
root.appendChild(c);
|
|
87
|
+
(this.doc.body ?? this.doc.documentElement).appendChild(root);
|
|
88
|
+
this.root = root;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
14
92
|
// src/matrix.ts
|
|
15
93
|
var xSafari = (t) => t.protocol === "https:" ? "x-safari-" + t.href : null;
|
|
16
94
|
var extbrowser = (scheme) => (t) => `${scheme}://extbrowser/?url=${encodeURIComponent(t.href)}`;
|
|
@@ -55,6 +133,9 @@ class IabEscapeOptions {
|
|
|
55
133
|
markParam = "iab_escaped";
|
|
56
134
|
onAttempt = null;
|
|
57
135
|
onResult = null;
|
|
136
|
+
ui = false;
|
|
137
|
+
labels = {};
|
|
138
|
+
maxAutoFires = 3;
|
|
58
139
|
window = null;
|
|
59
140
|
}
|
|
60
141
|
function optionsFromDataset(d) {
|
|
@@ -68,16 +149,26 @@ function optionsFromDataset(d) {
|
|
|
68
149
|
o.includeUnproven = true;
|
|
69
150
|
if (d.url)
|
|
70
151
|
o.url = d.url;
|
|
152
|
+
if (d.ui !== undefined)
|
|
153
|
+
o.ui = d.ui !== "false";
|
|
71
154
|
return o;
|
|
72
155
|
}
|
|
73
156
|
var WATCH_MS = 3000;
|
|
157
|
+
var REVEAL_MS = 800;
|
|
158
|
+
var REENTER_LOCK_MS = 1000;
|
|
74
159
|
var FIRED = "__iabEscapeFired";
|
|
75
160
|
var hasParam = (url, key) => new URLSearchParams(url.split("#")[0].split("?")[1] ?? "").has(key);
|
|
76
161
|
|
|
77
162
|
class IabEscape {
|
|
78
163
|
options;
|
|
79
|
-
static version = "0.
|
|
80
|
-
static buildTime = "2026-11-
|
|
164
|
+
static version = "0.2.0";
|
|
165
|
+
static buildTime = "2026-11-16T20:26:43.863Z";
|
|
166
|
+
ldr = null;
|
|
167
|
+
fires = 0;
|
|
168
|
+
watching = false;
|
|
169
|
+
wentAway = false;
|
|
170
|
+
locked = false;
|
|
171
|
+
dismissed = false;
|
|
81
172
|
constructor(options) {
|
|
82
173
|
this.options = options;
|
|
83
174
|
this.options = { ...new IabEscapeOptions, ...options };
|
|
@@ -140,20 +231,22 @@ class IabEscape {
|
|
|
140
231
|
return () => {};
|
|
141
232
|
win[FIRED] = true;
|
|
142
233
|
const { document: doc } = win;
|
|
143
|
-
|
|
234
|
+
this.dismissed = false;
|
|
235
|
+
if (this.o.ui)
|
|
236
|
+
this.loader().show();
|
|
144
237
|
let done = false;
|
|
145
238
|
let id;
|
|
146
239
|
const fire = () => {
|
|
147
240
|
done = true;
|
|
148
|
-
if (!this.
|
|
241
|
+
if (!this.fireNow())
|
|
149
242
|
win[FIRED] = false;
|
|
150
243
|
};
|
|
151
244
|
const start = () => {
|
|
152
245
|
doc.removeEventListener("DOMContentLoaded", start);
|
|
153
|
-
if (delay <= 0)
|
|
246
|
+
if (this.delay(rule) <= 0)
|
|
154
247
|
fire();
|
|
155
248
|
else
|
|
156
|
-
id = win.setTimeout(fire, delay);
|
|
249
|
+
id = win.setTimeout(fire, this.delay(rule));
|
|
157
250
|
};
|
|
158
251
|
if (doc.readyState === "loading")
|
|
159
252
|
doc.addEventListener("DOMContentLoaded", start);
|
|
@@ -166,8 +259,78 @@ class IabEscape {
|
|
|
166
259
|
if (id !== undefined)
|
|
167
260
|
win.clearTimeout(id);
|
|
168
261
|
win[FIRED] = false;
|
|
262
|
+
this.ldr?.hide();
|
|
169
263
|
};
|
|
170
264
|
}
|
|
265
|
+
loader() {
|
|
266
|
+
return this.ldr ??= new Loader(this.win.document, { ...DEFAULT_LABELS, ...this.o.labels }, () => {
|
|
267
|
+
this.dismissed = true;
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
delay(rule) {
|
|
271
|
+
return this.o.delayMs ?? rule.delayMs;
|
|
272
|
+
}
|
|
273
|
+
fireNow() {
|
|
274
|
+
if (!this.escape()) {
|
|
275
|
+
this.ldr?.hide();
|
|
276
|
+
return false;
|
|
277
|
+
}
|
|
278
|
+
this.fires++;
|
|
279
|
+
this.watchReentry();
|
|
280
|
+
if (this.o.ui) {
|
|
281
|
+
const url = this.buildUrl();
|
|
282
|
+
this.win.setTimeout(() => {
|
|
283
|
+
if (url && this.ldr?.visible)
|
|
284
|
+
this.ldr.reveal(url);
|
|
285
|
+
}, REVEAL_MS);
|
|
286
|
+
}
|
|
287
|
+
return true;
|
|
288
|
+
}
|
|
289
|
+
watchReentry() {
|
|
290
|
+
if (this.watching)
|
|
291
|
+
return;
|
|
292
|
+
this.watching = true;
|
|
293
|
+
const { win } = this;
|
|
294
|
+
const doc = win.document;
|
|
295
|
+
win.addEventListener("pagehide", () => {
|
|
296
|
+
this.wentAway = true;
|
|
297
|
+
});
|
|
298
|
+
doc.addEventListener("visibilitychange", () => {
|
|
299
|
+
if (doc.visibilityState === "hidden")
|
|
300
|
+
this.wentAway = true;
|
|
301
|
+
else
|
|
302
|
+
this.reenter();
|
|
303
|
+
});
|
|
304
|
+
win.addEventListener("pageshow", (e) => {
|
|
305
|
+
if (e.persisted) {
|
|
306
|
+
this.wentAway = true;
|
|
307
|
+
this.reenter();
|
|
308
|
+
}
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
reenter() {
|
|
312
|
+
const { win } = this;
|
|
313
|
+
const rule = this.getRule();
|
|
314
|
+
if (!this.wentAway || this.locked || this.dismissed || !rule)
|
|
315
|
+
return;
|
|
316
|
+
this.wentAway = false;
|
|
317
|
+
this.locked = true;
|
|
318
|
+
win.setTimeout(() => {
|
|
319
|
+
this.locked = false;
|
|
320
|
+
}, REENTER_LOCK_MS);
|
|
321
|
+
if (this.fires >= this.o.maxAutoFires) {
|
|
322
|
+
const url = this.buildUrl();
|
|
323
|
+
if (this.o.ui && url)
|
|
324
|
+
this.loader().reveal(url);
|
|
325
|
+
return;
|
|
326
|
+
}
|
|
327
|
+
if (this.o.ui)
|
|
328
|
+
this.loader().show();
|
|
329
|
+
if (this.delay(rule) <= 0)
|
|
330
|
+
this.fireNow();
|
|
331
|
+
else
|
|
332
|
+
win.setTimeout(() => this.fireNow(), this.delay(rule));
|
|
333
|
+
}
|
|
171
334
|
bindLink(a) {
|
|
172
335
|
const url = this.buildUrl();
|
|
173
336
|
if (!url)
|
package/dist/iab-escape.min.js
CHANGED
|
@@ -1 +1,11 @@
|
|
|
1
|
-
(()=>{var{defineProperty:
|
|
1
|
+
(()=>{var{defineProperty:p,getOwnPropertyNames:L,getOwnPropertyDescriptor:A}=Object,T=Object.prototype.hasOwnProperty;function _(e){return this[e]}var I=(e)=>{var t=(c??=new WeakMap).get(e),i;if(t)return t;if(t=p({},"__esModule",{value:!0}),e&&typeof e==="object"||typeof e==="function"){for(var n of L(e))if(!T.call(t,n))p(t,n,{get:_.bind(e,n),enumerable:!(i=A(e,n))||i.enumerable})}return c.set(e,t),t},c;var O=(e)=>e;function R(e,t){this[e]=O.bind(null,t)}var M=(e,t)=>{for(var i in t)p(e,i,{get:t[i],enumerable:!0,configurable:!0,set:R.bind(t,i)})};var U={};M(U,{boot:()=>x});var k=[["threads",/Barcelona/],["instagram",/Instagram/],["messenger",/FBAN\/MessengerForiOS|FB_IAB\/MESSENGER|Orca/],["facebook",/FBAN|FBAV|FB_IAB/]];function h(e){let t=k.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 f={opening:"Opening in your browser…",open:"Open in browser",stay:"Continue here"};class u{doc;labels;onStay;root=null;open;stay;spin;constructor(e,t,i){this.doc=e;this.labels=t;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}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=this.doc.createElement("style");t.textContent=`
|
|
2
|
+
#iab-escape{position:fixed;inset:0;z-index:2147483647;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:18px;
|
|
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
|
+
background:#fff;color:#111;font:18px/1.35 -apple-system,system-ui,sans-serif;text-align:center}
|
|
5
|
+
#iab-escape .ie-spin{width:36px;height:36px;border:4px solid #8884;border-top-color:#07f;border-radius:50%;animation:ie-r 1s linear infinite}
|
|
6
|
+
#iab-escape a.ie-open{display:block;padding:14px 28px;border-radius:12px;background:#07f;color:#fff;text-decoration:none;font-weight:600}
|
|
7
|
+
#iab-escape a.ie-stay{font-size:14px;color:inherit;opacity:.7}
|
|
8
|
+
#iab-escape [hidden]{display:none}
|
|
9
|
+
@keyframes ie-r{to{transform:rotate(360deg)}}
|
|
10
|
+
@media (prefers-color-scheme:dark){#iab-escape{background:#111;color:#f2f2f2}}
|
|
11
|
+
@media (prefers-reduced-motion:reduce){#iab-escape .ie-spin{animation:none}}`,this.spin=this.el("div","ie-spin");let i=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",(n)=>{n.preventDefault(),this.hide(),this.onStay?.()});for(let n of[t,this.spin,i,this.open,this.stay])e.appendChild(n);(this.doc.body??this.doc.documentElement).appendChild(e),this.root=e}}var m=(e)=>e.protocol==="https:"?"x-safari-"+e.href:null,b=(e)=>(t)=>`${e}://extbrowser/?url=${encodeURIComponent(t.href)}`,g=(e)=>`intent://${e.noHash.replace(/^https?:\/\//i,"")}#Intent;scheme=${e.protocol.slice(0,-1)};end`;var v=[{app:"instagram",os:"ios",proven:!0,delayMs:0,build:b("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:g,testedOn:{date:"2026-11-16",os:"Android 16",app:"Facebook 587.0.0.39.55"}},{app:"instagram",os:"android",proven:!1,delayMs:0,build:g,testedOn:null},{app:"threads",os:"ios",proven:!1,delayMs:0,build:b("barcelona"),testedOn:null},{app:"messenger",os:"ios",proven:!1,delayMs:1500,build:m,testedOn:null}];class E{url=null;userAgent=null;delayMs=null;includeUnproven=!1;markParam="iab_escaped";onAttempt=null;onResult=null;ui=!1;labels={};maxAutoFires=3;window=null}function w(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.ui!==void 0)t.ui=e.ui!=="false";return t}var S=3000,P=800,F=1000,l="__iabEscapeFired",y=(e,t)=>new URLSearchParams(e.split("#")[0].split("?")[1]??"").has(t);class d{options;static version="0.2.0";static buildTime="2026-11-16T20:26:43.863Z";ldr=null;fires=0;watching=!1;wentAway=!1;locked=!1;dismissed=!1;constructor(e){this.options=e;this.options={...new E,...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=v.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}target(){let e=this.win.location.href,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("#"),r=s<0?n:n.slice(0,s),a=s<0?"":n.slice(s),o=this.o.markParam;if(o&&!y(r,o))r+=(r.includes("?")?/[?&]$/.test(r)?"":"&":"?")+o+"=1";return{href:r+a,noHash:r,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&&y(e.location.href,t))return()=>{};e[l]=!0;let{document:n}=e;if(this.dismissed=!1,this.o.ui)this.loader().show();let s=!1,r,a=()=>{if(s=!0,!this.fireNow())e[l]=!1},o=()=>{if(n.removeEventListener("DOMContentLoaded",o),this.delay(i)<=0)a();else r=e.setTimeout(a,this.delay(i))};if(n.readyState==="loading")n.addEventListener("DOMContentLoaded",o);else o();return()=>{if(s)return;if(n.removeEventListener("DOMContentLoaded",o),r!==void 0)e.clearTimeout(r);e[l]=!1,this.ldr?.hide()}}loader(){return this.ldr??=new u(this.win.document,{...f,...this.o.labels},()=>{this.dismissed=!0})}delay(e){return this.o.delayMs??e.delayMs}fireNow(){if(!this.escape())return this.ldr?.hide(),!1;if(this.fires++,this.watchReentry(),this.o.ui){let e=this.buildUrl();this.win.setTimeout(()=>{if(e&&this.ldr?.visible)this.ldr.reveal(e)},P)}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},F),this.fires>=this.o.maxAutoFires){let i=this.buildUrl();if(this.o.ui&&i)this.loader().reveal(i);return}if(this.o.ui)this.loader().show();if(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"})},S)}}function x(e,t,i={}){t.IabEscape=d;let n=e?.currentScript;if(n?.hasAttribute("data-auto"))new d({ui:!0,...w(n.dataset),...i}).auto()}if(typeof document<"u")x(document,globalThis);})();
|
package/dist/loader.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export interface Labels {
|
|
2
|
+
opening: string;
|
|
3
|
+
open: string;
|
|
4
|
+
stay: string;
|
|
5
|
+
}
|
|
6
|
+
export declare const DEFAULT_LABELS: Labels;
|
|
7
|
+
/** Full-screen "opening in your browser" overlay. No deps; built with createElement only. */
|
|
8
|
+
export declare class Loader {
|
|
9
|
+
private doc;
|
|
10
|
+
private labels;
|
|
11
|
+
private onStay?;
|
|
12
|
+
private root;
|
|
13
|
+
private open;
|
|
14
|
+
private stay;
|
|
15
|
+
private spin;
|
|
16
|
+
constructor(doc: Document, labels: Labels, onStay?: (() => void) | undefined);
|
|
17
|
+
get visible(): boolean;
|
|
18
|
+
/** Spinner state (also resets a previously revealed button). */
|
|
19
|
+
show(): void;
|
|
20
|
+
/** Reveals the real `<a>` (so a tap works if the automatic fire was ignored) and the "stay" link. */
|
|
21
|
+
reveal(href: string): void;
|
|
22
|
+
hide(): void;
|
|
23
|
+
private el;
|
|
24
|
+
private build;
|
|
25
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@livx.cc/iab-escape",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.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",
|