@fluritheme/tab-whisper 0.0.0-stage → 1.0.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/CHANGELOG.md +5 -0
- package/LICENSE +21 -0
- package/README.md +100 -2
- package/dist/badge.d.ts +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +266 -0
- package/dist/overlay.d.ts +31 -0
- package/dist/tab-whisper.d.ts +28 -0
- package/dist/tab-whisper.global.js +23 -0
- package/package.json +49 -4
package/CHANGELOG.md
ADDED
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 František Gejdoš (Fluri, https://fluri.xyz)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,101 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Tab Whisper by Fluri
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Your tab calls visitors back when they leave. Tab Whisper.
|
|
4
|
+
|
|
5
|
+
**[Live demo →](https://fluri.xyz/tab-whisper/)** · [All Fluri themes](https://fluri.xyz/themes/) · No-code install for WordPress, Shopify, Wix & more at [fluri.xyz](https://fluri.xyz/tab-whisper/)
|
|
6
|
+
|
|
7
|
+

|
|
8
|
+
|
|
9
|
+
- Zero dependencies, about 7 KB minified
|
|
10
|
+
- Uses the Page Visibility API: nothing runs while your tab is in front
|
|
11
|
+
- The real title is read at the moment the visitor leaves, so it works on single-page apps
|
|
12
|
+
- The emoji icon is drawn on a canvas; your own icons are put back on return
|
|
13
|
+
- `preview()` shows it without leaving the tab, for testing
|
|
14
|
+
- Nothing on the page itself changes
|
|
15
|
+
- Works with plain HTML, React, Vue, Svelte, Astro, Next.js and anything else
|
|
16
|
+
- TypeScript types included
|
|
17
|
+
|
|
18
|
+
## Quick start: one line of HTML
|
|
19
|
+
|
|
20
|
+
Paste this before `</body>`:
|
|
21
|
+
|
|
22
|
+
```html
|
|
23
|
+
<script src="https://cdn.jsdelivr.net/npm/@fluritheme/tab-whisper@1/dist/tab-whisper.global.js" data-auto></script>
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Pass options as JSON:
|
|
27
|
+
|
|
28
|
+
```html
|
|
29
|
+
<script src="https://cdn.jsdelivr.net/npm/@fluritheme/tab-whisper@1/dist/tab-whisper.global.js" data-auto data-options='{"messages":["Come back!","Your cart misses you"]}'></script>
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
The running effect is available as `window.FluriTabWhisper.instance`.
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
## Install with npm
|
|
36
|
+
|
|
37
|
+
```sh
|
|
38
|
+
npm install @fluritheme/tab-whisper
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
```ts
|
|
42
|
+
import { createTabWhisper } from "@fluritheme/tab-whisper";
|
|
43
|
+
|
|
44
|
+
const whisper = createTabWhisper({
|
|
45
|
+
messages: ["Come back!", "Your cart misses you"],
|
|
46
|
+
delay: 2, // seconds away before the first title
|
|
47
|
+
interval: 2.5, // seconds between titles
|
|
48
|
+
icon: "👋", // optional: an emoji as the tab icon while away
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
whisper.preview(6); // see it for 6 seconds without leaving the tab
|
|
52
|
+
|
|
53
|
+
// When leaving the page or unmounting a component:
|
|
54
|
+
whisper.destroy();
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### React
|
|
58
|
+
|
|
59
|
+
```tsx
|
|
60
|
+
import { useEffect } from "react";
|
|
61
|
+
import { createTabWhisper } from "@fluritheme/tab-whisper";
|
|
62
|
+
|
|
63
|
+
export function TabWhisper() {
|
|
64
|
+
useEffect(() => {
|
|
65
|
+
const effect = createTabWhisper();
|
|
66
|
+
return () => effect.destroy();
|
|
67
|
+
}, []);
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## Options
|
|
73
|
+
|
|
74
|
+
| Option | What it does | Default |
|
|
75
|
+
| --- | --- | --- |
|
|
76
|
+
| `messages` | Titles shown while the visitor is away | ["Come back!", "You left something here"] |
|
|
77
|
+
| `delay` | Seconds away before the first title | `2` |
|
|
78
|
+
| `interval` | Seconds between titles | `2.5` |
|
|
79
|
+
| `icon` | An emoji shown as the tab icon while away | — |
|
|
80
|
+
| `welcome` | Title shown for a moment when the visitor returns | — |
|
|
81
|
+
|
|
82
|
+
## Methods
|
|
83
|
+
|
|
84
|
+
- `preview(seconds?)`
|
|
85
|
+
- `update(options)`
|
|
86
|
+
- `getState()`
|
|
87
|
+
- `destroy()`
|
|
88
|
+
|
|
89
|
+
## Great for
|
|
90
|
+
|
|
91
|
+
- Online shops winning back people comparing prices
|
|
92
|
+
- Checkout and booking pages
|
|
93
|
+
- Any site whose visitors open many tabs
|
|
94
|
+
|
|
95
|
+
## No code? Use Fluri
|
|
96
|
+
|
|
97
|
+
Don’t want to touch code? [Fluri](https://fluri.xyz/tab-whisper/) installs Tab Whisper on WordPress, Shopify, Webflow, Wix, Squarespace and Framer with one snippet, with live settings and a dashboard. There are more than a dozen animated themes, from a pet dragon to a koi pond. [See them all →](https://fluri.xyz/themes/)
|
|
98
|
+
|
|
99
|
+
## License
|
|
100
|
+
|
|
101
|
+
MIT © František Gejdoš · [fluri.xyz](https://fluri.xyz)
|
package/dist/badge.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function showFluriBadge(slug: string): void;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export * from "./tab-whisper.js";
|
|
2
|
+
import { createTabWhisper as base } from "./tab-whisper.js";
|
|
3
|
+
/** createTabWhisper from Fluri. Also shows a small "Unlock all themes on fluri.xyz" badge. */
|
|
4
|
+
export declare function createTabWhisper(...args: Parameters<typeof base>): ReturnType<typeof base>;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
/*! @fluritheme/tab-whisper v1.0.0 | MIT | https://fluri.xyz/tab-whisper/ */
|
|
2
|
+
|
|
3
|
+
// packages/tab-whisper/src/overlay.ts
|
|
4
|
+
var clamp = (v, a, b) => Math.max(a, Math.min(b, v));
|
|
5
|
+
|
|
6
|
+
// packages/tab-whisper/src/tab-whisper.ts
|
|
7
|
+
function emojiIcon(emoji) {
|
|
8
|
+
const c = document.createElement("canvas");
|
|
9
|
+
c.width = c.height = 64;
|
|
10
|
+
const x = c.getContext("2d");
|
|
11
|
+
if (!x) return "";
|
|
12
|
+
x.font = '52px "Apple Color Emoji","Segoe UI Emoji","Noto Color Emoji",sans-serif';
|
|
13
|
+
x.textAlign = "center";
|
|
14
|
+
x.textBaseline = "middle";
|
|
15
|
+
x.fillText(emoji, 32, 36);
|
|
16
|
+
return c.toDataURL("image/png");
|
|
17
|
+
}
|
|
18
|
+
function createTabWhisper(options = {}) {
|
|
19
|
+
const o = {
|
|
20
|
+
messages: ["Come back!", "You left something here"],
|
|
21
|
+
delay: 2,
|
|
22
|
+
interval: 2.5,
|
|
23
|
+
icon: "",
|
|
24
|
+
welcome: "",
|
|
25
|
+
titleElement: null,
|
|
26
|
+
...options
|
|
27
|
+
};
|
|
28
|
+
let real = document.title, away = false, shown2 = 0, timer = 0, index = 0, previewing = false;
|
|
29
|
+
let icons = [];
|
|
30
|
+
let made = null;
|
|
31
|
+
function write(title) {
|
|
32
|
+
if (o.titleElement) o.titleElement.textContent = title;
|
|
33
|
+
else document.title = title;
|
|
34
|
+
}
|
|
35
|
+
function swapIcon() {
|
|
36
|
+
if (!o.icon || o.titleElement || made) return;
|
|
37
|
+
const url = emojiIcon(o.icon);
|
|
38
|
+
if (!url) return;
|
|
39
|
+
icons = [...document.querySelectorAll('link[rel~="icon"]')].map(
|
|
40
|
+
(el) => ({ el, href: el.href })
|
|
41
|
+
);
|
|
42
|
+
for (const i of icons) i.el.href = url;
|
|
43
|
+
if (!icons.length) {
|
|
44
|
+
made = document.createElement("link");
|
|
45
|
+
made.rel = "icon";
|
|
46
|
+
made.href = url;
|
|
47
|
+
document.head.append(made);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
function restoreIcon() {
|
|
51
|
+
for (const i of icons) i.el.href = i.href;
|
|
52
|
+
icons = [];
|
|
53
|
+
made?.remove();
|
|
54
|
+
made = null;
|
|
55
|
+
}
|
|
56
|
+
function next() {
|
|
57
|
+
const list = o.messages.filter(Boolean);
|
|
58
|
+
if (!list.length) return;
|
|
59
|
+
write(list[index % list.length]);
|
|
60
|
+
index++;
|
|
61
|
+
shown2++;
|
|
62
|
+
timer = window.setTimeout(next, clamp(o.interval, 0.5, 60) * 1e3);
|
|
63
|
+
}
|
|
64
|
+
function leave() {
|
|
65
|
+
if (away) return;
|
|
66
|
+
away = true;
|
|
67
|
+
if (!o.titleElement) real = document.title;
|
|
68
|
+
index = 0;
|
|
69
|
+
clearTimeout(timer);
|
|
70
|
+
timer = window.setTimeout(() => {
|
|
71
|
+
swapIcon();
|
|
72
|
+
next();
|
|
73
|
+
}, clamp(o.delay, 0, 600) * 1e3);
|
|
74
|
+
}
|
|
75
|
+
function back() {
|
|
76
|
+
if (!away) return;
|
|
77
|
+
away = false;
|
|
78
|
+
clearTimeout(timer);
|
|
79
|
+
restoreIcon();
|
|
80
|
+
if (o.welcome && shown2) {
|
|
81
|
+
write(o.welcome);
|
|
82
|
+
timer = window.setTimeout(() => write(real), 2e3);
|
|
83
|
+
} else write(real);
|
|
84
|
+
}
|
|
85
|
+
const vis = () => {
|
|
86
|
+
if (previewing) return;
|
|
87
|
+
if (document.hidden) leave();
|
|
88
|
+
else back();
|
|
89
|
+
};
|
|
90
|
+
document.addEventListener("visibilitychange", vis);
|
|
91
|
+
if (o.titleElement) real = o.titleElement.textContent || "";
|
|
92
|
+
return {
|
|
93
|
+
/** Shows the messages now, as if the visitor had left, for some seconds. */
|
|
94
|
+
preview(seconds = 6) {
|
|
95
|
+
previewing = true;
|
|
96
|
+
away = false;
|
|
97
|
+
leave();
|
|
98
|
+
clearTimeout(timer);
|
|
99
|
+
swapIcon();
|
|
100
|
+
next();
|
|
101
|
+
window.setTimeout(
|
|
102
|
+
() => {
|
|
103
|
+
previewing = false;
|
|
104
|
+
back();
|
|
105
|
+
},
|
|
106
|
+
clamp(seconds, 1, 120) * 1e3
|
|
107
|
+
);
|
|
108
|
+
},
|
|
109
|
+
update(next2) {
|
|
110
|
+
Object.assign(o, next2);
|
|
111
|
+
if (next2.titleElement) real = next2.titleElement.textContent || "";
|
|
112
|
+
},
|
|
113
|
+
pause() {
|
|
114
|
+
},
|
|
115
|
+
resume() {
|
|
116
|
+
},
|
|
117
|
+
destroy() {
|
|
118
|
+
document.removeEventListener("visibilitychange", vis);
|
|
119
|
+
clearTimeout(timer);
|
|
120
|
+
restoreIcon();
|
|
121
|
+
if (away || previewing) write(real);
|
|
122
|
+
away = false;
|
|
123
|
+
},
|
|
124
|
+
getState() {
|
|
125
|
+
return {
|
|
126
|
+
away,
|
|
127
|
+
title: o.titleElement ? o.titleElement.textContent || "" : document.title,
|
|
128
|
+
shown: shown2
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// packages/tab-whisper/src/badge.ts
|
|
135
|
+
var SITE = "https://fluri.xyz/themes/";
|
|
136
|
+
var shown = false;
|
|
137
|
+
var CSS = `
|
|
138
|
+
:host{all:initial}
|
|
139
|
+
a{position:fixed;z-index:2147483600;display:inline-flex;align-items:center;gap:9px;padding:8px 10px 8px 9px;max-width:calc(100vw - 32px);
|
|
140
|
+
border-radius:999px;background:rgba(22,18,36,.88);-webkit-backdrop-filter:blur(12px) saturate(1.4);backdrop-filter:blur(12px) saturate(1.4);
|
|
141
|
+
border:1px solid rgba(255,255,255,.14);box-shadow:0 10px 30px rgba(10,6,30,.28),0 1px 0 rgba(255,255,255,.08) inset;
|
|
142
|
+
color:#fff;font:600 13px/1.2 ui-sans-serif,system-ui,-apple-system,"Segoe UI",Roboto,sans-serif;letter-spacing:.01em;text-decoration:none;
|
|
143
|
+
opacity:0;transform:translateY(10px) scale(.98);transition:opacity .35s ease,transform .35s cubic-bezier(.2,.8,.2,1),background .2s}
|
|
144
|
+
a.in{opacity:1;transform:none}
|
|
145
|
+
a:hover{background:rgba(32,26,52,.96)}
|
|
146
|
+
a:focus-visible{outline:3px solid #a78bfa;outline-offset:3px}
|
|
147
|
+
.star{flex:none;display:grid;place-items:center;width:22px;height:22px;border-radius:50%;background:conic-gradient(from 210deg,#8b5cf6,#ec4899,#f59e0b,#8b5cf6);box-shadow:0 0 12px rgba(167,139,250,.55)}
|
|
148
|
+
.star svg{width:12px;height:12px;fill:#fff}
|
|
149
|
+
.txt{white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
|
|
150
|
+
.txt b{font-weight:700;background:linear-gradient(90deg,#c4b5fd,#fbcfe8);-webkit-background-clip:text;background-clip:text;color:transparent}
|
|
151
|
+
.arrow{flex:none;transition:transform .2s}
|
|
152
|
+
a:hover .arrow{transform:translateX(2px)}
|
|
153
|
+
button{all:unset;flex:none;display:grid;place-items:center;width:20px;height:20px;margin-left:2px;border-radius:50%;color:rgba(255,255,255,.7);font:600 14px/1 system-ui;cursor:pointer}
|
|
154
|
+
button:hover{background:rgba(255,255,255,.14);color:#fff}
|
|
155
|
+
button:focus-visible{outline:2px solid #a78bfa}
|
|
156
|
+
@media (max-width:480px){a{font-size:12px;padding:7px 8px 7px 7px;gap:7px}.star{width:20px;height:20px}}
|
|
157
|
+
@media (prefers-reduced-motion:reduce){a{transition:opacity .2s}a,a.in{transform:none}}
|
|
158
|
+
`;
|
|
159
|
+
var ORDER = ["bottom-left", "bottom-center", "bottom-right", "top-right"];
|
|
160
|
+
function place(a, c) {
|
|
161
|
+
const s = a.style;
|
|
162
|
+
s.top = s.bottom = s.left = s.right = s.transform = "";
|
|
163
|
+
if (c.startsWith("bottom")) s.bottom = "16px";
|
|
164
|
+
else s.top = "16px";
|
|
165
|
+
if (c.endsWith("left")) s.left = "16px";
|
|
166
|
+
else if (c.endsWith("right")) s.right = "16px";
|
|
167
|
+
else {
|
|
168
|
+
s.left = "50%";
|
|
169
|
+
s.marginLeft = -(a.offsetWidth / 2) + "px";
|
|
170
|
+
}
|
|
171
|
+
if (c !== "bottom-center") s.marginLeft = "";
|
|
172
|
+
}
|
|
173
|
+
function taken(host, r) {
|
|
174
|
+
const pts = [
|
|
175
|
+
[r.left + 4, r.top + 4],
|
|
176
|
+
[r.right - 4, r.top + 4],
|
|
177
|
+
[r.left + 4, r.bottom - 4],
|
|
178
|
+
[r.right - 4, r.bottom - 4],
|
|
179
|
+
[r.left + r.width / 2, r.top + r.height / 2]
|
|
180
|
+
];
|
|
181
|
+
for (const [x, y] of pts) {
|
|
182
|
+
for (const el of document.elementsFromPoint(x, y)) {
|
|
183
|
+
if (el === host || el === document.body || el === document.documentElement) continue;
|
|
184
|
+
for (let e = el; e && e !== document.body; e = e.parentElement) {
|
|
185
|
+
const p = getComputedStyle(e).position;
|
|
186
|
+
if (p === "fixed" || p === "sticky") return true;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
return false;
|
|
191
|
+
}
|
|
192
|
+
function isPreview() {
|
|
193
|
+
try {
|
|
194
|
+
const h = location.hostname;
|
|
195
|
+
if (/(^|\.)fluri\.xyz$/.test(h) || /(^|\.)(codepen\.io|cdpn\.io)$/.test(h)) return true;
|
|
196
|
+
if (navigator.webdriver) return true;
|
|
197
|
+
if (/HeadlessChrome|Playwright|Puppeteer/i.test(navigator.userAgent)) return true;
|
|
198
|
+
} catch {
|
|
199
|
+
}
|
|
200
|
+
return false;
|
|
201
|
+
}
|
|
202
|
+
function showFluriBadge(slug) {
|
|
203
|
+
if (shown || typeof document === "undefined" || typeof window === "undefined") return;
|
|
204
|
+
if (isPreview()) return;
|
|
205
|
+
shown = true;
|
|
206
|
+
const start = () => {
|
|
207
|
+
const host = document.createElement("fluri-badge");
|
|
208
|
+
host.setAttribute("style", "all:initial");
|
|
209
|
+
const root = host.attachShadow({ mode: "open" });
|
|
210
|
+
const style = document.createElement("style");
|
|
211
|
+
style.textContent = CSS;
|
|
212
|
+
const a = document.createElement("a");
|
|
213
|
+
a.href = SITE + "?utm_source=npm&utm_medium=badge&utm_campaign=" + encodeURIComponent(slug);
|
|
214
|
+
a.target = "_blank";
|
|
215
|
+
a.rel = "noopener";
|
|
216
|
+
a.setAttribute("aria-label", "Unlock all themes on fluri.xyz (opens in a new tab)");
|
|
217
|
+
const star = document.createElement("span");
|
|
218
|
+
star.className = "star";
|
|
219
|
+
star.innerHTML = '<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M12 2l2.4 6.6L21 11l-6.6 2.4L12 20l-2.4-6.6L3 11l6.6-2.4z"/></svg>';
|
|
220
|
+
const txt = document.createElement("span");
|
|
221
|
+
txt.className = "txt";
|
|
222
|
+
txt.append("Unlock all themes on ");
|
|
223
|
+
const b = document.createElement("b");
|
|
224
|
+
b.textContent = "fluri.xyz";
|
|
225
|
+
txt.append(b);
|
|
226
|
+
const arrow = document.createElement("span");
|
|
227
|
+
arrow.className = "arrow";
|
|
228
|
+
arrow.setAttribute("aria-hidden", "true");
|
|
229
|
+
arrow.textContent = "\u2192";
|
|
230
|
+
const close = document.createElement("button");
|
|
231
|
+
close.type = "button";
|
|
232
|
+
close.setAttribute("aria-label", "Hide");
|
|
233
|
+
close.textContent = "\xD7";
|
|
234
|
+
close.addEventListener("click", (e) => {
|
|
235
|
+
e.preventDefault();
|
|
236
|
+
e.stopPropagation();
|
|
237
|
+
a.classList.remove("in");
|
|
238
|
+
setTimeout(() => host.remove(), 350);
|
|
239
|
+
});
|
|
240
|
+
a.append(star, txt, arrow, close);
|
|
241
|
+
root.append(style, a);
|
|
242
|
+
document.body.appendChild(host);
|
|
243
|
+
let corner = ORDER[0];
|
|
244
|
+
for (const c of ORDER) {
|
|
245
|
+
place(a, c);
|
|
246
|
+
if (!taken(host, a.getBoundingClientRect())) {
|
|
247
|
+
corner = c;
|
|
248
|
+
break;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
place(a, corner);
|
|
252
|
+
requestAnimationFrame(() => requestAnimationFrame(() => a.classList.add("in")));
|
|
253
|
+
};
|
|
254
|
+
const later = () => setTimeout(start, 1200);
|
|
255
|
+
if (document.readyState === "loading") document.addEventListener("DOMContentLoaded", later, { once: true });
|
|
256
|
+
else later();
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
// packages/tab-whisper/src/index.ts
|
|
260
|
+
function createTabWhisper2(...args) {
|
|
261
|
+
showFluriBadge("tab-whisper");
|
|
262
|
+
return createTabWhisper(...args);
|
|
263
|
+
}
|
|
264
|
+
export {
|
|
265
|
+
createTabWhisper2 as createTabWhisper
|
|
266
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export interface OverlayOptions {
|
|
2
|
+
root?: HTMLElement | undefined;
|
|
3
|
+
zIndex?: number | undefined;
|
|
4
|
+
maxFPS?: number | undefined;
|
|
5
|
+
}
|
|
6
|
+
export interface Overlay {
|
|
7
|
+
canvas: HTMLCanvasElement;
|
|
8
|
+
ctx: CanvasRenderingContext2D;
|
|
9
|
+
/** CSS pixel size of the drawing area. */
|
|
10
|
+
width: number;
|
|
11
|
+
height: number;
|
|
12
|
+
/** Area origin in viewport coordinates (for converting client points). */
|
|
13
|
+
origin(): {
|
|
14
|
+
x: number;
|
|
15
|
+
y: number;
|
|
16
|
+
};
|
|
17
|
+
start(frame: (dt: number, t: number) => void): void;
|
|
18
|
+
pause(): void;
|
|
19
|
+
resume(): void;
|
|
20
|
+
destroy(): void;
|
|
21
|
+
reduced: boolean;
|
|
22
|
+
}
|
|
23
|
+
export declare function createOverlay(o?: OverlayOptions): Overlay;
|
|
24
|
+
export declare function surfacesIn(selector: string, root?: HTMLElement, limit?: number): HTMLElement[];
|
|
25
|
+
export declare const rand: (a: number, b: number) => number;
|
|
26
|
+
export declare const clamp: (v: number, a: number, b: number) => number;
|
|
27
|
+
/**
|
|
28
|
+
* Moves an overlay canvas behind the content of its host (the root, or the
|
|
29
|
+
* body) by giving the host its own stacking context. Returns an undo function.
|
|
30
|
+
*/
|
|
31
|
+
export declare function sendBehind(canvas: HTMLCanvasElement, root?: HTMLElement): () => void;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export interface TabWhisperOptions {
|
|
2
|
+
/** Titles shown while the visitor is away, one after another. */
|
|
3
|
+
messages?: string[];
|
|
4
|
+
/** Seconds away before the first message. Default 2. */
|
|
5
|
+
delay?: number;
|
|
6
|
+
/** Seconds between messages. Default 2.5. */
|
|
7
|
+
interval?: number;
|
|
8
|
+
/** An emoji shown as the tab icon while away. Empty keeps your icon. */
|
|
9
|
+
icon?: string;
|
|
10
|
+
/** Title shown for a moment when the visitor returns. Empty for none. */
|
|
11
|
+
welcome?: string;
|
|
12
|
+
/** Also write the title into this element (for previews). */
|
|
13
|
+
titleElement?: HTMLElement | null;
|
|
14
|
+
}
|
|
15
|
+
export interface TabWhisperState {
|
|
16
|
+
away: boolean;
|
|
17
|
+
title: string;
|
|
18
|
+
shown: number;
|
|
19
|
+
}
|
|
20
|
+
export declare function createTabWhisper(options?: TabWhisperOptions): {
|
|
21
|
+
/** Shows the messages now, as if the visitor had left, for some seconds. */
|
|
22
|
+
preview(seconds?: number): void;
|
|
23
|
+
update(next: Partial<TabWhisperOptions>): void;
|
|
24
|
+
pause(): void;
|
|
25
|
+
resume(): void;
|
|
26
|
+
destroy(): void;
|
|
27
|
+
getState(): TabWhisperState;
|
|
28
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/*! @fluritheme/tab-whisper v1.0.0 | MIT | https://fluri.xyz/tab-whisper/ */
|
|
2
|
+
(()=>{var b=(o,e,t)=>Math.max(e,Math.min(t,o));function S(o){let e=document.createElement("canvas");e.width=e.height=64;let t=e.getContext("2d");return t?(t.font='52px "Apple Color Emoji","Segoe UI Emoji","Noto Color Emoji",sans-serif',t.textAlign="center",t.textBaseline="middle",t.fillText(o,32,36),e.toDataURL("image/png")):""}function E(o={}){let e={messages:["Come back!","You left something here"],delay:2,interval:2.5,icon:"",welcome:"",titleElement:null,...o},t=document.title,r=!1,p=0,a=0,n=0,l=!1,c=[],s=null;function d(i){e.titleElement?e.titleElement.textContent=i:document.title=i}function m(){if(!e.icon||e.titleElement||s)return;let i=S(e.icon);if(i){c=[...document.querySelectorAll('link[rel~="icon"]')].map(h=>({el:h,href:h.href}));for(let h of c)h.el.href=i;c.length||(s=document.createElement("link"),s.rel="icon",s.href=i,document.head.append(s))}}function f(){for(let i of c)i.el.href=i.href;c=[],s==null||s.remove(),s=null}function u(){let i=e.messages.filter(Boolean);i.length&&(d(i[n%i.length]),n++,p++,a=window.setTimeout(u,b(e.interval,.5,60)*1e3))}function y(){r||(r=!0,e.titleElement||(t=document.title),n=0,clearTimeout(a),a=window.setTimeout(()=>{m(),u()},b(e.delay,0,600)*1e3))}function v(){r&&(r=!1,clearTimeout(a),f(),e.welcome&&p?(d(e.welcome),a=window.setTimeout(()=>d(t),2e3)):d(t))}let w=()=>{l||(document.hidden?y():v())};return document.addEventListener("visibilitychange",w),e.titleElement&&(t=e.titleElement.textContent||""),{preview(i=6){l=!0,r=!1,y(),clearTimeout(a),m(),u(),window.setTimeout(()=>{l=!1,v()},b(i,1,120)*1e3)},update(i){Object.assign(e,i),i.titleElement&&(t=i.titleElement.textContent||"")},pause(){},resume(){},destroy(){document.removeEventListener("visibilitychange",w),clearTimeout(a),f(),(r||l)&&d(t),r=!1},getState(){return{away:r,title:e.titleElement?e.titleElement.textContent||"":document.title,shown:p}}}}var W="https://fluri.xyz/themes/",T=!1,H=`
|
|
3
|
+
:host{all:initial}
|
|
4
|
+
a{position:fixed;z-index:2147483600;display:inline-flex;align-items:center;gap:9px;padding:8px 10px 8px 9px;max-width:calc(100vw - 32px);
|
|
5
|
+
border-radius:999px;background:rgba(22,18,36,.88);-webkit-backdrop-filter:blur(12px) saturate(1.4);backdrop-filter:blur(12px) saturate(1.4);
|
|
6
|
+
border:1px solid rgba(255,255,255,.14);box-shadow:0 10px 30px rgba(10,6,30,.28),0 1px 0 rgba(255,255,255,.08) inset;
|
|
7
|
+
color:#fff;font:600 13px/1.2 ui-sans-serif,system-ui,-apple-system,"Segoe UI",Roboto,sans-serif;letter-spacing:.01em;text-decoration:none;
|
|
8
|
+
opacity:0;transform:translateY(10px) scale(.98);transition:opacity .35s ease,transform .35s cubic-bezier(.2,.8,.2,1),background .2s}
|
|
9
|
+
a.in{opacity:1;transform:none}
|
|
10
|
+
a:hover{background:rgba(32,26,52,.96)}
|
|
11
|
+
a:focus-visible{outline:3px solid #a78bfa;outline-offset:3px}
|
|
12
|
+
.star{flex:none;display:grid;place-items:center;width:22px;height:22px;border-radius:50%;background:conic-gradient(from 210deg,#8b5cf6,#ec4899,#f59e0b,#8b5cf6);box-shadow:0 0 12px rgba(167,139,250,.55)}
|
|
13
|
+
.star svg{width:12px;height:12px;fill:#fff}
|
|
14
|
+
.txt{white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
|
|
15
|
+
.txt b{font-weight:700;background:linear-gradient(90deg,#c4b5fd,#fbcfe8);-webkit-background-clip:text;background-clip:text;color:transparent}
|
|
16
|
+
.arrow{flex:none;transition:transform .2s}
|
|
17
|
+
a:hover .arrow{transform:translateX(2px)}
|
|
18
|
+
button{all:unset;flex:none;display:grid;place-items:center;width:20px;height:20px;margin-left:2px;border-radius:50%;color:rgba(255,255,255,.7);font:600 14px/1 system-ui;cursor:pointer}
|
|
19
|
+
button:hover{background:rgba(255,255,255,.14);color:#fff}
|
|
20
|
+
button:focus-visible{outline:2px solid #a78bfa}
|
|
21
|
+
@media (max-width:480px){a{font-size:12px;padding:7px 8px 7px 7px;gap:7px}.star{width:20px;height:20px}}
|
|
22
|
+
@media (prefers-reduced-motion:reduce){a{transition:opacity .2s}a,a.in{transform:none}}
|
|
23
|
+
`,L=["bottom-left","bottom-center","bottom-right","top-right"];function C(o,e){let t=o.style;t.top=t.bottom=t.left=t.right=t.transform="",e.startsWith("bottom")?t.bottom="16px":t.top="16px",e.endsWith("left")?t.left="16px":e.endsWith("right")?t.right="16px":(t.left="50%",t.marginLeft=-(o.offsetWidth/2)+"px"),e!=="bottom-center"&&(t.marginLeft="")}function O(o,e){let t=[[e.left+4,e.top+4],[e.right-4,e.top+4],[e.left+4,e.bottom-4],[e.right-4,e.bottom-4],[e.left+e.width/2,e.top+e.height/2]];for(let[r,p]of t)for(let a of document.elementsFromPoint(r,p))if(!(a===o||a===document.body||a===document.documentElement))for(let n=a;n&&n!==document.body;n=n.parentElement){let l=getComputedStyle(n).position;if(l==="fixed"||l==="sticky")return!0}return!1}function A(){try{let o=location.hostname;if(/(^|\.)fluri\.xyz$/.test(o)||/(^|\.)(codepen\.io|cdpn\.io)$/.test(o)||navigator.webdriver||/HeadlessChrome|Playwright|Puppeteer/i.test(navigator.userAgent))return!0}catch{}return!1}function M(o){if(T||typeof document=="undefined"||typeof window=="undefined"||A())return;T=!0;let e=()=>{let r=document.createElement("fluri-badge");r.setAttribute("style","all:initial");let p=r.attachShadow({mode:"open"}),a=document.createElement("style");a.textContent=H;let n=document.createElement("a");n.href=W+"?utm_source=npm&utm_medium=badge&utm_campaign="+encodeURIComponent(o),n.target="_blank",n.rel="noopener",n.setAttribute("aria-label","Unlock all themes on fluri.xyz (opens in a new tab)");let l=document.createElement("span");l.className="star",l.innerHTML='<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M12 2l2.4 6.6L21 11l-6.6 2.4L12 20l-2.4-6.6L3 11l6.6-2.4z"/></svg>';let c=document.createElement("span");c.className="txt",c.append("Unlock all themes on ");let s=document.createElement("b");s.textContent="fluri.xyz",c.append(s);let d=document.createElement("span");d.className="arrow",d.setAttribute("aria-hidden","true"),d.textContent="\u2192";let m=document.createElement("button");m.type="button",m.setAttribute("aria-label","Hide"),m.textContent="\xD7",m.addEventListener("click",u=>{u.preventDefault(),u.stopPropagation(),n.classList.remove("in"),setTimeout(()=>r.remove(),350)}),n.append(l,c,d,m),p.append(a,n),document.body.appendChild(r);let f=L[0];for(let u of L)if(C(n,u),!O(r,n.getBoundingClientRect())){f=u;break}C(n,f),requestAnimationFrame(()=>requestAnimationFrame(()=>n.classList.add("in")))},t=()=>setTimeout(e,1200);document.readyState==="loading"?document.addEventListener("DOMContentLoaded",t,{once:!0}):t()}function g(...o){return M("tab-whisper"),E(...o)}var k={createTabWhisper:g};window.FluriTabWhisper=k;var x=document.currentScript;if(x&&x.hasAttribute("data-auto")){let o=()=>{let e={};try{e=JSON.parse(x.getAttribute("data-options")||"{}")}catch{}k.instance=g(e)};document.readyState==="loading"?document.addEventListener("DOMContentLoaded",o,{once:!0}):o()}})();
|
package/package.json
CHANGED
|
@@ -1,6 +1,51 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluritheme/tab-whisper",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Tab Whisper: changes the tab title (and optionally the favicon) when a visitor switches to another tab, to call them back: “Come back!”, “Your cart misses you”. Restores everything the moment they return. Zero dependencies.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"author": {
|
|
8
|
+
"name": "František Gejdoš",
|
|
9
|
+
"url": "https://fluri.xyz/founder/",
|
|
10
|
+
"email": "fluritheme@gmail.com"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://fluri.xyz/tab-whisper/",
|
|
13
|
+
"keywords": [
|
|
14
|
+
"tab-title",
|
|
15
|
+
"inactive-tab",
|
|
16
|
+
"page-title",
|
|
17
|
+
"document-title",
|
|
18
|
+
"visibilitychange",
|
|
19
|
+
"favicon",
|
|
20
|
+
"come-back",
|
|
21
|
+
"cart-abandonment",
|
|
22
|
+
"ecommerce",
|
|
23
|
+
"attention",
|
|
24
|
+
"retention",
|
|
25
|
+
"website-effects",
|
|
26
|
+
"fluri"
|
|
27
|
+
],
|
|
28
|
+
"sideEffects": false,
|
|
29
|
+
"files": [
|
|
30
|
+
"dist",
|
|
31
|
+
"README.md",
|
|
32
|
+
"LICENSE",
|
|
33
|
+
"CHANGELOG.md"
|
|
34
|
+
],
|
|
35
|
+
"exports": {
|
|
36
|
+
".": {
|
|
37
|
+
"types": "./dist/index.d.ts",
|
|
38
|
+
"import": "./dist/index.js"
|
|
39
|
+
},
|
|
40
|
+
"./global": "./dist/tab-whisper.global.js",
|
|
41
|
+
"./package.json": "./package.json"
|
|
42
|
+
},
|
|
43
|
+
"main": "./dist/index.js",
|
|
44
|
+
"module": "./dist/index.js",
|
|
45
|
+
"types": "./dist/index.d.ts",
|
|
46
|
+
"unpkg": "./dist/tab-whisper.global.js",
|
|
47
|
+
"jsdelivr": "./dist/tab-whisper.global.js",
|
|
48
|
+
"publishConfig": {
|
|
49
|
+
"access": "public"
|
|
50
|
+
}
|
|
51
|
+
}
|