@livx.cc/iab-escape 0.2.0 → 0.3.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 +23 -3
- package/dist/IabEscape.d.ts +15 -3
- package/dist/IabEscape.js +64 -24
- package/dist/iab-escape.min.js +6 -6
- package/dist/loader.d.ts +11 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -24,11 +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
|
+
`auto()` shows, **by default** (script tag and npm API alike), 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"` or `ui: false`. No loader when the app is not matched.
|
|
28
28
|
|
|
29
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
30
|
|
|
31
|
-
Optional attributes: `data-ui`, `data-delay-ms`, `data-mark-param` (empty = off), `data-include-unproven`, `data-url`.
|
|
31
|
+
Optional attributes: `data-ui`, `data-accent`, `data-bg`, `data-fg`, `data-label-opening`, `data-label-open`, `data-label-stay`, `data-delay-ms`, `data-mark-param` (empty = off), `data-include-unproven`, `data-url`.
|
|
32
32
|
|
|
33
33
|
npm:
|
|
34
34
|
|
|
@@ -47,7 +47,27 @@ The script build also exposes the global `IabEscape` class (`IabEscape.version`,
|
|
|
47
47
|
- `detect()` returns `{ app, os, inApp }`; `getRule()` the matrix row (with `testedOn`); `buildUrl()` the scheme URL or null.
|
|
48
48
|
- `escape()` fires now (call inside a tap for buttons). `auto()` returns a cancel function; cancelling before the fire re-arms the once-per-page guard (flag on the window, shared by all instances).
|
|
49
49
|
- `auto()` does nothing when the current page URL already carries the mark param (loop guard); `escape()` still works.
|
|
50
|
-
- Options: `url` (relative resolves against the page), `userAgent`, `delayMs`, `includeUnproven`, `markParam` (default `iab_escaped`, appended raw as `=1` only if absent, query otherwise byte-identical; `null` disables), `onAttempt`, `onResult`, `window`.
|
|
50
|
+
- Options: `url` (relative resolves against the page), `userAgent`, `delayMs`, `includeUnproven`, `markParam` (default `iab_escaped`, appended raw as `=1` only if absent, query otherwise byte-identical; `null` disables), `ui`, `labels`, `theme`, `maxAutoFires`, `onState`, `onAttempt`, `onResult`, `window`. `dismiss()` stops re-fires and removes the loader.
|
|
51
|
+
|
|
52
|
+
## Customize
|
|
53
|
+
|
|
54
|
+
Styling API: `#iab-escape` and the classes `ie-msg`, `ie-spin`, `ie-open`, `ie-stay`. CSS variables (all optional): `--iab-bg`, `--iab-fg`, `--iab-accent`, `--iab-accent-fg`, `--iab-radius`, `--iab-font`.
|
|
55
|
+
|
|
56
|
+
```css
|
|
57
|
+
#iab-escape { --iab-accent: #e33; --iab-radius: 4px; }
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
```ts
|
|
61
|
+
new IabEscape({ theme: { accent: '#e33', bg: '#000' }, labels: { opening: 'One moment…', open: 'Open', stay: 'Stay' } }).auto();
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Own UI: turn the built-in one off and render from `onState` (`phase`: `opening`, `fallback`, `reentry`, `dismissed`; `url` is the scheme URL for the fallback button).
|
|
65
|
+
|
|
66
|
+
```ts
|
|
67
|
+
const esc = new IabEscape({ ui: false, onState: ({ phase, url }) => myUi.render(phase, url) });
|
|
68
|
+
esc.auto();
|
|
69
|
+
myUi.onContinue(() => esc.dismiss());
|
|
70
|
+
```
|
|
51
71
|
|
|
52
72
|
## Limits
|
|
53
73
|
|
package/dist/IabEscape.d.ts
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import { type Env } from './detect';
|
|
2
|
-
import { type Labels } from './loader';
|
|
2
|
+
import { type Labels, type Theme } from './loader';
|
|
3
3
|
import { type Rule } from './matrix';
|
|
4
|
-
export type { Env, Labels, Rule };
|
|
4
|
+
export type { Env, Labels, Rule, Theme };
|
|
5
|
+
export interface State {
|
|
6
|
+
phase: 'opening' | 'fallback' | 'dismissed' | 'reentry';
|
|
7
|
+
url: string | null;
|
|
8
|
+
}
|
|
5
9
|
export interface AttemptInfo {
|
|
6
10
|
rule: Rule;
|
|
7
11
|
url: string;
|
|
@@ -22,9 +26,13 @@ export declare class IabEscapeOptions {
|
|
|
22
26
|
markParam: string | null;
|
|
23
27
|
onAttempt: ((info: AttemptInfo) => void) | null;
|
|
24
28
|
onResult: ((info: ResultInfo) => void) | null;
|
|
25
|
-
/**
|
|
29
|
+
/** Built-in full-screen loader (spinner, then an "Open in browser" button) while auto() runs. false = off. */
|
|
26
30
|
ui: boolean;
|
|
27
31
|
labels: Partial<Labels>;
|
|
32
|
+
/** Sets the `--iab-*` CSS variables inline on the overlay. */
|
|
33
|
+
theme: Theme;
|
|
34
|
+
/** Phase callback for a custom UI (also called when the built-in UI is on). */
|
|
35
|
+
onState: ((state: State) => void) | null;
|
|
28
36
|
/** Max automatic fires per page lifetime (the first fire + re-entry re-fires). */
|
|
29
37
|
maxAutoFires: number;
|
|
30
38
|
/** Injectable for tests. Default: globalThis.window. */
|
|
@@ -63,6 +71,10 @@ export declare class IabEscape {
|
|
|
63
71
|
*/
|
|
64
72
|
auto(): () => void;
|
|
65
73
|
private loader;
|
|
74
|
+
private state;
|
|
75
|
+
/** Stops re-fires and removes the built-in loader. Wire a custom UI's "Continue here" to this. */
|
|
76
|
+
dismiss(): void;
|
|
77
|
+
private fallback;
|
|
66
78
|
private delay;
|
|
67
79
|
/** One automatic fire: escape(), count it, start watching for re-entry, reveal the button soon after. */
|
|
68
80
|
private fireNow;
|
package/dist/IabEscape.js
CHANGED
|
@@ -13,29 +13,39 @@ function detectEnv(ua) {
|
|
|
13
13
|
|
|
14
14
|
// src/loader.ts
|
|
15
15
|
var DEFAULT_LABELS = { opening: "Opening in your browser…", open: "Open in browser", stay: "Continue here" };
|
|
16
|
+
var VARS = {
|
|
17
|
+
bg: "--iab-bg",
|
|
18
|
+
fg: "--iab-fg",
|
|
19
|
+
accent: "--iab-accent",
|
|
20
|
+
accentFg: "--iab-accent-fg",
|
|
21
|
+
radius: "--iab-radius",
|
|
22
|
+
font: "--iab-font"
|
|
23
|
+
};
|
|
16
24
|
var CSS = `
|
|
17
25
|
#iab-escape{position:fixed;inset:0;z-index:2147483647;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:18px;
|
|
18
26
|
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
|
|
20
|
-
#iab-escape .ie-spin{width:36px;height:36px;border:4px solid #8884;border-top-color
|
|
21
|
-
#iab-escape a.ie-open{display:block;padding:14px 28px;border-radius:12px;background
|
|
27
|
+
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}
|
|
28
|
+
#iab-escape .ie-spin{width:36px;height:36px;border:4px solid #8884;border-top-color:var(--iab-accent,#07f);border-radius:50%;animation:ie-r 1s linear infinite}
|
|
29
|
+
#iab-escape a.ie-open{display:block;padding:14px 28px;border-radius:var(--iab-radius,12px);background:var(--iab-accent,#07f);color:var(--iab-accent-fg,#fff);text-decoration:none;font-weight:600}
|
|
22
30
|
#iab-escape a.ie-stay{font-size:14px;color:inherit;opacity:.7}
|
|
23
31
|
#iab-escape [hidden]{display:none}
|
|
24
32
|
@keyframes ie-r{to{transform:rotate(360deg)}}
|
|
25
|
-
@media (prefers-color-scheme:dark){#iab-escape{background
|
|
33
|
+
@media (prefers-color-scheme:dark){#iab-escape{background:var(--iab-bg,#111);color:var(--iab-fg,#f2f2f2)}}
|
|
26
34
|
@media (prefers-reduced-motion:reduce){#iab-escape .ie-spin{animation:none}}`;
|
|
27
35
|
|
|
28
36
|
class Loader {
|
|
29
37
|
doc;
|
|
30
38
|
labels;
|
|
39
|
+
theme;
|
|
31
40
|
onStay;
|
|
32
41
|
root = null;
|
|
33
42
|
open;
|
|
34
43
|
stay;
|
|
35
44
|
spin;
|
|
36
|
-
constructor(doc, labels, onStay) {
|
|
45
|
+
constructor(doc, labels, theme = {}, onStay) {
|
|
37
46
|
this.doc = doc;
|
|
38
47
|
this.labels = labels;
|
|
48
|
+
this.theme = theme;
|
|
39
49
|
this.onStay = onStay;
|
|
40
50
|
}
|
|
41
51
|
get visible() {
|
|
@@ -70,6 +80,9 @@ class Loader {
|
|
|
70
80
|
const root = this.el("div", "");
|
|
71
81
|
root.id = "iab-escape";
|
|
72
82
|
root.setAttribute("role", "status");
|
|
83
|
+
const inline = Object.keys(VARS).filter((k) => this.theme[k]).map((k) => `${VARS[k]}:${this.theme[k]}`).join(";");
|
|
84
|
+
if (inline)
|
|
85
|
+
root.setAttribute("style", inline);
|
|
73
86
|
const style = this.doc.createElement("style");
|
|
74
87
|
style.textContent = CSS;
|
|
75
88
|
this.spin = this.el("div", "ie-spin");
|
|
@@ -133,8 +146,10 @@ class IabEscapeOptions {
|
|
|
133
146
|
markParam = "iab_escaped";
|
|
134
147
|
onAttempt = null;
|
|
135
148
|
onResult = null;
|
|
136
|
-
ui =
|
|
149
|
+
ui = true;
|
|
137
150
|
labels = {};
|
|
151
|
+
theme = {};
|
|
152
|
+
onState = null;
|
|
138
153
|
maxAutoFires = 3;
|
|
139
154
|
window = null;
|
|
140
155
|
}
|
|
@@ -151,6 +166,24 @@ function optionsFromDataset(d) {
|
|
|
151
166
|
o.url = d.url;
|
|
152
167
|
if (d.ui !== undefined)
|
|
153
168
|
o.ui = d.ui !== "false";
|
|
169
|
+
const theme = {};
|
|
170
|
+
if (d.accent)
|
|
171
|
+
theme.accent = d.accent;
|
|
172
|
+
if (d.bg)
|
|
173
|
+
theme.bg = d.bg;
|
|
174
|
+
if (d.fg)
|
|
175
|
+
theme.fg = d.fg;
|
|
176
|
+
if (Object.keys(theme).length)
|
|
177
|
+
o.theme = theme;
|
|
178
|
+
const labels = {};
|
|
179
|
+
if (d.labelOpening)
|
|
180
|
+
labels.opening = d.labelOpening;
|
|
181
|
+
if (d.labelOpen)
|
|
182
|
+
labels.open = d.labelOpen;
|
|
183
|
+
if (d.labelStay)
|
|
184
|
+
labels.stay = d.labelStay;
|
|
185
|
+
if (Object.keys(labels).length)
|
|
186
|
+
o.labels = labels;
|
|
154
187
|
return o;
|
|
155
188
|
}
|
|
156
189
|
var WATCH_MS = 3000;
|
|
@@ -161,8 +194,8 @@ var hasParam = (url, key) => new URLSearchParams(url.split("#")[0].split("?")[1]
|
|
|
161
194
|
|
|
162
195
|
class IabEscape {
|
|
163
196
|
options;
|
|
164
|
-
static version = "0.
|
|
165
|
-
static buildTime = "2026-11-16T20:
|
|
197
|
+
static version = "0.3.0";
|
|
198
|
+
static buildTime = "2026-11-16T20:42:33.752Z";
|
|
166
199
|
ldr = null;
|
|
167
200
|
fires = 0;
|
|
168
201
|
watching = false;
|
|
@@ -234,6 +267,7 @@ class IabEscape {
|
|
|
234
267
|
this.dismissed = false;
|
|
235
268
|
if (this.o.ui)
|
|
236
269
|
this.loader().show();
|
|
270
|
+
this.state("opening");
|
|
237
271
|
let done = false;
|
|
238
272
|
let id;
|
|
239
273
|
const fire = () => {
|
|
@@ -263,9 +297,21 @@ class IabEscape {
|
|
|
263
297
|
};
|
|
264
298
|
}
|
|
265
299
|
loader() {
|
|
266
|
-
return this.ldr ??= new Loader(this.win.document, { ...DEFAULT_LABELS, ...this.o.labels }, () =>
|
|
267
|
-
|
|
268
|
-
|
|
300
|
+
return this.ldr ??= new Loader(this.win.document, { ...DEFAULT_LABELS, ...this.o.labels }, this.o.theme, () => this.dismiss());
|
|
301
|
+
}
|
|
302
|
+
state(phase) {
|
|
303
|
+
this.o.onState?.({ phase, url: this.buildUrl() });
|
|
304
|
+
}
|
|
305
|
+
dismiss() {
|
|
306
|
+
this.dismissed = true;
|
|
307
|
+
this.ldr?.hide();
|
|
308
|
+
this.state("dismissed");
|
|
309
|
+
}
|
|
310
|
+
fallback() {
|
|
311
|
+
const url = this.buildUrl();
|
|
312
|
+
if (url && this.o.ui)
|
|
313
|
+
this.loader().reveal(url);
|
|
314
|
+
this.state("fallback");
|
|
269
315
|
}
|
|
270
316
|
delay(rule) {
|
|
271
317
|
return this.o.delayMs ?? rule.delayMs;
|
|
@@ -277,13 +323,10 @@ class IabEscape {
|
|
|
277
323
|
}
|
|
278
324
|
this.fires++;
|
|
279
325
|
this.watchReentry();
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
this.ldr.reveal(url);
|
|
285
|
-
}, REVEAL_MS);
|
|
286
|
-
}
|
|
326
|
+
this.win.setTimeout(() => {
|
|
327
|
+
if (!this.dismissed)
|
|
328
|
+
this.fallback();
|
|
329
|
+
}, REVEAL_MS);
|
|
287
330
|
return true;
|
|
288
331
|
}
|
|
289
332
|
watchReentry() {
|
|
@@ -318,14 +361,11 @@ class IabEscape {
|
|
|
318
361
|
win.setTimeout(() => {
|
|
319
362
|
this.locked = false;
|
|
320
363
|
}, REENTER_LOCK_MS);
|
|
321
|
-
if (this.fires >= this.o.maxAutoFires)
|
|
322
|
-
|
|
323
|
-
if (this.o.ui && url)
|
|
324
|
-
this.loader().reveal(url);
|
|
325
|
-
return;
|
|
326
|
-
}
|
|
364
|
+
if (this.fires >= this.o.maxAutoFires)
|
|
365
|
+
return this.fallback();
|
|
327
366
|
if (this.o.ui)
|
|
328
367
|
this.loader().show();
|
|
368
|
+
this.state("reentry");
|
|
329
369
|
if (this.delay(rule) <= 0)
|
|
330
370
|
this.fireNow();
|
|
331
371
|
else
|
package/dist/iab-escape.min.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
(()=>{var{defineProperty:
|
|
1
|
+
(()=>{var{defineProperty:d,getOwnPropertyNames:A,getOwnPropertyDescriptor:L}=Object,O=Object.prototype.hasOwnProperty;function k(e){return this[e]}var _=(e)=>{var t=(u??=new WeakMap).get(e),i;if(t)return t;if(t=d({},"__esModule",{value:!0}),e&&typeof e==="object"||typeof e==="function"){for(var n of A(e))if(!O.call(t,n))d(t,n,{get:k.bind(e,n),enumerable:!(i=L(e,n))||i.enumerable})}return u.set(e,t),t},u;var R=(e)=>e;function I(e,t){this[e]=R.bind(null,t)}var S=(e,t)=>{for(var i in t)d(e,i,{get:t[i],enumerable:!0,configurable:!0,set:I.bind(t,i)})};var N={};S(N,{boot:()=>T});var M=[["threads",/Barcelona/],["instagram",/Instagram/],["messenger",/FBAN\/MessengerForiOS|FB_IAB\/MESSENGER|Orca/],["facebook",/FBAN|FBAV|FB_IAB/]];function h(e){let t=M.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"},f={bg:"--iab-bg",fg:"--iab-fg",accent:"--iab-accent",accentFg:"--iab-accent-fg",radius:"--iab-radius",font:"--iab-font"};class c{doc;labels;theme;onStay;root=null;open;stay;spin;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}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=`
|
|
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
|
-
background
|
|
5
|
-
#iab-escape .ie-spin{width:36px;height:36px;border:4px solid #8884;border-top-color
|
|
6
|
-
#iab-escape a.ie-open{display:block;padding:14px 28px;border-radius:12px;background
|
|
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}
|
|
5
|
+
#iab-escape .ie-spin{width:36px;height:36px;border:4px solid #8884;border-top-color:var(--iab-accent,#07f);border-radius:50%;animation:ie-r 1s linear infinite}
|
|
6
|
+
#iab-escape a.ie-open{display:block;padding:14px 28px;border-radius:var(--iab-radius,12px);background:var(--iab-accent,#07f);color:var(--iab-accent-fg,#fff);text-decoration:none;font-weight:600}
|
|
7
7
|
#iab-escape a.ie-stay{font-size:14px;color:inherit;opacity:.7}
|
|
8
8
|
#iab-escape [hidden]{display:none}
|
|
9
9
|
@keyframes ie-r{to{transform:rotate(360deg)}}
|
|
10
|
-
@media (prefers-color-scheme:dark){#iab-escape{background
|
|
11
|
-
@media (prefers-reduced-motion:reduce){#iab-escape .ie-spin{animation:none}}`,this.spin=this.el("div","ie-spin");let
|
|
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.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 w{url=null;userAgent=null;delayMs=null;includeUnproven=!1;markParam="iab_escaped";onAttempt=null;onResult=null;ui=!0;labels={};theme={};onState=null;maxAutoFires=3;window=null}function x(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";let n={};if(e.accent)n.accent=e.accent;if(e.bg)n.bg=e.bg;if(e.fg)n.fg=e.fg;if(Object.keys(n).length)t.theme=n;let s={};if(e.labelOpening)s.opening=e.labelOpening;if(e.labelOpen)s.open=e.labelOpen;if(e.labelStay)s.stay=e.labelStay;if(Object.keys(s).length)t.labels=s;return t}var P=3000,F=800,U=1000,l="__iabEscapeFired",E=(e,t)=>new URLSearchParams(e.split("#")[0].split("?")[1]??"").has(t);class p{options;static version="0.3.0";static buildTime="2026-11-16T20:42:33.752Z";ldr=null;fires=0;watching=!1;wentAway=!1;locked=!1;dismissed=!1;constructor(e){this.options=e;this.options={...new w,...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}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("#"),a=s<0?n:n.slice(0,s),o=s<0?"":n.slice(s),r=this.o.markParam;if(r&&!E(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[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,o=()=>{if(s=!0,!this.fireNow())e[l]=!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[l]=!1,this.ldr?.hide()}}loader(){return this.ldr??=new c(this.win.document,{...b,...this.o.labels},this.o.theme,()=>this.dismiss())}state(e){this.o.onState?.({phase:e,url:this.buildUrl()})}dismiss(){this.dismissed=!0,this.ldr?.hide(),this.state("dismissed")}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;return this.fires++,this.watchReentry(),this.win.setTimeout(()=>{if(!this.dismissed)this.fallback()},F),!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},U),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"})},P)}}function T(e,t,i={}){t.IabEscape=p;let n=e?.currentScript;if(n?.hasAttribute("data-auto"))new p({...x(n.dataset),...i}).auto()}if(typeof document<"u")T(document,globalThis);})();
|
package/dist/loader.d.ts
CHANGED
|
@@ -4,16 +4,26 @@ export interface Labels {
|
|
|
4
4
|
stay: string;
|
|
5
5
|
}
|
|
6
6
|
export declare const DEFAULT_LABELS: Labels;
|
|
7
|
+
/** Styling API: the `#iab-escape` root, the classes below, and these CSS variables (all optional). */
|
|
8
|
+
export interface Theme {
|
|
9
|
+
bg?: string;
|
|
10
|
+
fg?: string;
|
|
11
|
+
accent?: string;
|
|
12
|
+
accentFg?: string;
|
|
13
|
+
radius?: string;
|
|
14
|
+
font?: string;
|
|
15
|
+
}
|
|
7
16
|
/** Full-screen "opening in your browser" overlay. No deps; built with createElement only. */
|
|
8
17
|
export declare class Loader {
|
|
9
18
|
private doc;
|
|
10
19
|
private labels;
|
|
20
|
+
private theme;
|
|
11
21
|
private onStay?;
|
|
12
22
|
private root;
|
|
13
23
|
private open;
|
|
14
24
|
private stay;
|
|
15
25
|
private spin;
|
|
16
|
-
constructor(doc: Document, labels: Labels, onStay?: (() => void) | undefined);
|
|
26
|
+
constructor(doc: Document, labels: Labels, theme?: Theme, onStay?: (() => void) | undefined);
|
|
17
27
|
get visible(): boolean;
|
|
18
28
|
/** Spinner state (also resets a previously revealed button). */
|
|
19
29
|
show(): void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@livx.cc/iab-escape",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.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",
|