@plusguard/reels 1.9.2 → 1.10.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 +38 -5
- package/dist/index.js +39 -5
- package/early.js +1 -1
- package/index.ts +40 -4
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -23,9 +23,9 @@ From npm, through jsDelivr — the npm package is the code alone (about
|
|
|
23
23
|
jsDelivr's GitHub route.
|
|
24
24
|
|
|
25
25
|
```html
|
|
26
|
-
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@plusguard/reels@1.
|
|
26
|
+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@plusguard/reels@1.10.1/index.css" />
|
|
27
27
|
<script type="module">
|
|
28
|
-
import { initReels } from "https://cdn.jsdelivr.net/npm/@plusguard/reels@1.
|
|
28
|
+
import { initReels } from "https://cdn.jsdelivr.net/npm/@plusguard/reels@1.10.1/dist/index.js";
|
|
29
29
|
initReels();
|
|
30
30
|
</script>
|
|
31
31
|
```
|
|
@@ -92,6 +92,12 @@ below).
|
|
|
92
92
|
plays; a bar pressed is that clip at once — one bar even for a card of
|
|
93
93
|
one clip. Under the mouse they thicken, to be pressed easily. Out of sight it stops and waits on its poster; a hidden tab
|
|
94
94
|
stops them all.
|
|
95
|
+
- **Only what plays loads.** Write each video `preload="none"` with a
|
|
96
|
+
`poster`: the page fetches the posters, and a video only when its clip
|
|
97
|
+
plays — the playing clip of each card in sight. The other clips, and the
|
|
98
|
+
cards out of sight, cost nothing but their poster until their turn. The
|
|
99
|
+
full view fetches its own clip, and ahead of time only the stills of the
|
|
100
|
+
groups beside it and of the clip after it, so a slide is never blank.
|
|
95
101
|
- **The product is the clip's.** The products under a card are one a clip;
|
|
96
102
|
the playing one's shows (`data-pg-reels-current`).
|
|
97
103
|
- **Sound is one card's.** A sound button pressed gives the sound to its
|
|
@@ -106,6 +112,33 @@ below).
|
|
|
106
112
|
`data-pg-reels-open`: the full view, on that group and clip. First the
|
|
107
113
|
event `pg-reels:open` on the section, with `detail.group` and
|
|
108
114
|
`detail.clip`; `preventDefault()` on it and the site opens its own.
|
|
115
|
+
- **Watched.** A clip that has played **3 seconds** — or half of it, if it
|
|
116
|
+
is shorter than 6 — on a card or in the full view: the event
|
|
117
|
+
`pg-reels:watched` on the section, once a clip a page visit, with
|
|
118
|
+
`detail.group`, `detail.clip`, `detail.id` (the group's
|
|
119
|
+
`data-pg-reels-id`) and `detail.where` (`"card"` or `"full"`). The
|
|
120
|
+
package counts nothing: the site sends it on — to its own server, which
|
|
121
|
+
counts and leaves out the same visitor twice a day — and writes the
|
|
122
|
+
number back in `data-pg-reels-views`.
|
|
123
|
+
|
|
124
|
+
- **Once a page visit.** The same clip is not told twice while the page
|
|
125
|
+
stays open — a card going round, the full view opened again. A visit
|
|
126
|
+
later (the page opened again, or reloaded), it is told again, however
|
|
127
|
+
long since.
|
|
128
|
+
- **The server decides what counts.** Its rule is its own — the same
|
|
129
|
+
visitor and clip once a day, say: watched again the next day, counted
|
|
130
|
+
again; five reloads in a day, counted once. Once an hour, every time,
|
|
131
|
+
or never twice: the site's to choose.
|
|
132
|
+
- **Not the rings.** The seen rings (below) and their
|
|
133
|
+
`--pg-reels-seen-for` are only how the avatars look: a ring bright
|
|
134
|
+
again changes no count, and a count changes no ring.
|
|
135
|
+
|
|
136
|
+
```js
|
|
137
|
+
section.addEventListener("pg-reels:watched", (e) => {
|
|
138
|
+
const { id, clip, where } = e.detail;
|
|
139
|
+
navigator.sendBeacon("/api/reels/watched", JSON.stringify({ id, clip, where }));
|
|
140
|
+
});
|
|
141
|
+
```
|
|
109
142
|
- **Reduced motion:** nothing plays by itself; a bar pressed shows its clip.
|
|
110
143
|
- **Seen.** A group is seen once **every one of its clips** has been shown
|
|
111
144
|
in the full view — one clip watched, and it is not; the rest watched
|
|
@@ -139,7 +172,7 @@ classic script in `<head>` after the stylesheets, marks each group as the
|
|
|
139
172
|
browser reads it, before anything is drawn:
|
|
140
173
|
|
|
141
174
|
```html
|
|
142
|
-
<script src="https://cdn.jsdelivr.net/npm/@plusguard/reels@1.
|
|
175
|
+
<script src="https://cdn.jsdelivr.net/npm/@plusguard/reels@1.10.1/early.js"></script>
|
|
143
176
|
```
|
|
144
177
|
|
|
145
178
|
No dependencies, nothing to call; `initReels()` takes over after. It reads
|
|
@@ -249,7 +282,7 @@ and videos: the box has the shape, what is inside is 100% of it.
|
|
|
249
282
|
| `data-pg-reels-strip` | the row | Scrolls sideways |
|
|
250
283
|
| `data-pg-reels-group` | each group | A card and what is under it |
|
|
251
284
|
| `data-pg-reels-id` | a group | Its name, for what was seen to be remembered in this browser |
|
|
252
|
-
| `data-pg-reels-views` | in the card | A clip's view count, the site's — one a clip, in order, as the products: only the playing clip's shows, and it is copied into the full view, under the close. Only one in the card: the group's, always shown |
|
|
285
|
+
| `data-pg-reels-views` | in the card | A clip's view count, the site's (counted from `pg-reels:watched`) — one a clip, in order, as the products: only the playing clip's shows, and it is copied into the full view, under the close. Only one in the card: the group's, always shown |
|
|
253
286
|
| `data-pg-reels-seen` | a group, the full view's head | Written: `"true"` once seen in the full view, `"false"` before |
|
|
254
287
|
| `data-pg-reels-card` | the card | The shape; its clips fill it |
|
|
255
288
|
| `data-pg-reels-clip` | each clip | A video with its poster, or a picture |
|
|
@@ -313,7 +346,7 @@ So in React they go in the clip, as an element kept hidden:
|
|
|
313
346
|
Give its pictures `loading="lazy"`: hidden, they load when the full view
|
|
314
347
|
shows them. See [`examples/react/Example.tsx`](examples/react/Example.tsx)
|
|
315
348
|
— the section from data (variants and categories too), and
|
|
316
|
-
`pg-reels:open`
|
|
349
|
+
`pg-reels:open` and `pg-reels:watched` sent on to the site's server.
|
|
317
350
|
|
|
318
351
|
### The React example, running
|
|
319
352
|
|
package/dist/index.js
CHANGED
|
@@ -36,7 +36,8 @@
|
|
|
36
36
|
* are one per clip, and only the playing one's shows. So with view
|
|
37
37
|
* counts: one data-pg-reels-views a clip, in order, and only the playing
|
|
38
38
|
* clip's shows — or one for the whole group, always shown. The others wait
|
|
39
|
-
* on their posters. Out of sight, nothing plays
|
|
39
|
+
* on their posters. Out of sight, nothing plays — and with each video
|
|
40
|
+
* written preload="none", nothing loads but its poster until its turn.
|
|
40
41
|
*
|
|
41
42
|
* The strip scrolls sideways — a finger, a wheel, its arrows; it never
|
|
42
43
|
* moves by itself. data-pg-reels-start / -end on the section while it
|
|
@@ -47,6 +48,15 @@
|
|
|
47
48
|
* the event pg-reels:open on the section (detail: group, clip); a site
|
|
48
49
|
* that calls preventDefault() on it opens its own.
|
|
49
50
|
*
|
|
51
|
+
* Watched: a clip that has played 3 seconds — or half of it, if it is
|
|
52
|
+
* shorter than 6 — on a card or in the full view, sends pg-reels:watched
|
|
53
|
+
* on the section (detail: group, clip, id — its group's data-pg-reels-id —
|
|
54
|
+
* and where: "card" or "full"), once a clip a page visit — a visit later
|
|
55
|
+
* (opened again, reloaded) it is told again. The package only says so;
|
|
56
|
+
* counting — what counts, the same visitor once a day, say — and the
|
|
57
|
+
* number shown in data-pg-reels-views, are the site's server's. The seen
|
|
58
|
+
* rings are apart from it: a ring bright again changes no count.
|
|
59
|
+
*
|
|
50
60
|
* The full view — a <dialog>, built here on <body>, its contents copies:
|
|
51
61
|
* the clip playing, the group's data-pg-reels-head, the clip's product.
|
|
52
62
|
* Within a group: the bars on top, a press on the video's right or left,
|
|
@@ -340,6 +350,21 @@ export function forgetReelsSeen() {
|
|
|
340
350
|
watched = new WeakMap();
|
|
341
351
|
paintSeen();
|
|
342
352
|
}
|
|
353
|
+
/* ---------- Watched, said to the site ----------
|
|
354
|
+
A clip that has played long enough: 3 seconds, or half of it if it is
|
|
355
|
+
shorter — once a clip a page visit. The site counts. */
|
|
356
|
+
const WATCHED_MS = 3000;
|
|
357
|
+
const told = new WeakMap();
|
|
358
|
+
function watchedIf(g, clip, playedMs, totalMs, where) {
|
|
359
|
+
if (!(totalMs > 0) || playedMs < Math.min(WATCHED_MS, totalMs / 2))
|
|
360
|
+
return;
|
|
361
|
+
const said = told.get(g.el) ?? new Set();
|
|
362
|
+
if (said.has(clip))
|
|
363
|
+
return;
|
|
364
|
+
said.add(clip);
|
|
365
|
+
told.set(g.el, said);
|
|
366
|
+
g.root.dispatchEvent(new CustomEvent("pg-reels:watched", { bubbles: true, detail: { group: g.el, clip, id: g.el.getAttribute(ID), where } }));
|
|
367
|
+
}
|
|
343
368
|
// The clips of each group shown in the full view so far, this visit.
|
|
344
369
|
let watched = new WeakMap();
|
|
345
370
|
/* ---------- Everything on the page ---------- */
|
|
@@ -452,10 +477,16 @@ export function initReels() {
|
|
|
452
477
|
const clip = g.clips[g.at];
|
|
453
478
|
const v = videoOf(clip);
|
|
454
479
|
let progress;
|
|
455
|
-
if (v)
|
|
480
|
+
if (v) {
|
|
456
481
|
progress = v.duration ? v.currentTime / v.duration : 0;
|
|
457
|
-
|
|
458
|
-
|
|
482
|
+
watchedIf(g, g.at, v.currentTime * 1000, v.duration * 1000, "card");
|
|
483
|
+
}
|
|
484
|
+
else {
|
|
485
|
+
const time = pictureTime(g, clip);
|
|
486
|
+
const played = g.shown + now - g.since;
|
|
487
|
+
progress = played / Math.max(1, time);
|
|
488
|
+
watchedIf(g, g.at, played, time, "card");
|
|
489
|
+
}
|
|
459
490
|
g.bars[g.at]?.style.setProperty(PROGRESS, String(Math.min(1, progress)));
|
|
460
491
|
if (!v && progress >= 1)
|
|
461
492
|
due.push(g);
|
|
@@ -844,7 +875,10 @@ export function initReels() {
|
|
|
844
875
|
const g = current();
|
|
845
876
|
const clip = g.clips[view.ci];
|
|
846
877
|
const v = viewVideo();
|
|
847
|
-
const
|
|
878
|
+
const time = v ? v.duration * 1000 : pictureTime(g, clip);
|
|
879
|
+
const played = v ? v.currentTime * 1000 : view.shown + now - view.since;
|
|
880
|
+
const progress = v ? (v.duration ? v.currentTime / v.duration : 0) : played / Math.max(1, time);
|
|
881
|
+
watchedIf(g, view.ci, played, time, "full");
|
|
848
882
|
viewBars.children[view.ci]?.setAttribute("style", `${PROGRESS}: ${Math.min(1, progress)}`);
|
|
849
883
|
if (!v && progress >= 1) {
|
|
850
884
|
nextClip(true);
|
package/early.js
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* A classic script, in <head>, after the page's stylesheets and before its
|
|
10
10
|
* markup — not deferred, not a module:
|
|
11
11
|
*
|
|
12
|
-
* <script src="https://cdn.jsdelivr.net/npm/@plusguard/reels@1.
|
|
12
|
+
* <script src="https://cdn.jsdelivr.net/npm/@plusguard/reels@1.10.1/early.js"></script>
|
|
13
13
|
*
|
|
14
14
|
* or its text written inline there. No dependencies; nothing to call. It
|
|
15
15
|
* reads --pg-reels-seen and --pg-reels-seen-for from the stylesheets, as
|
package/index.ts
CHANGED
|
@@ -36,7 +36,8 @@
|
|
|
36
36
|
* are one per clip, and only the playing one's shows. So with view
|
|
37
37
|
* counts: one data-pg-reels-views a clip, in order, and only the playing
|
|
38
38
|
* clip's shows — or one for the whole group, always shown. The others wait
|
|
39
|
-
* on their posters. Out of sight, nothing plays
|
|
39
|
+
* on their posters. Out of sight, nothing plays — and with each video
|
|
40
|
+
* written preload="none", nothing loads but its poster until its turn.
|
|
40
41
|
*
|
|
41
42
|
* The strip scrolls sideways — a finger, a wheel, its arrows; it never
|
|
42
43
|
* moves by itself. data-pg-reels-start / -end on the section while it
|
|
@@ -47,6 +48,15 @@
|
|
|
47
48
|
* the event pg-reels:open on the section (detail: group, clip); a site
|
|
48
49
|
* that calls preventDefault() on it opens its own.
|
|
49
50
|
*
|
|
51
|
+
* Watched: a clip that has played 3 seconds — or half of it, if it is
|
|
52
|
+
* shorter than 6 — on a card or in the full view, sends pg-reels:watched
|
|
53
|
+
* on the section (detail: group, clip, id — its group's data-pg-reels-id —
|
|
54
|
+
* and where: "card" or "full"), once a clip a page visit — a visit later
|
|
55
|
+
* (opened again, reloaded) it is told again. The package only says so;
|
|
56
|
+
* counting — what counts, the same visitor once a day, say — and the
|
|
57
|
+
* number shown in data-pg-reels-views, are the site's server's. The seen
|
|
58
|
+
* rings are apart from it: a ring bright again changes no count.
|
|
59
|
+
*
|
|
50
60
|
* The full view — a <dialog>, built here on <body>, its contents copies:
|
|
51
61
|
* the clip playing, the group's data-pg-reels-head, the clip's product.
|
|
52
62
|
* Within a group: the bars on top, a press on the video's right or left,
|
|
@@ -366,6 +376,22 @@ export function forgetReelsSeen(): void {
|
|
|
366
376
|
paintSeen();
|
|
367
377
|
}
|
|
368
378
|
|
|
379
|
+
/* ---------- Watched, said to the site ----------
|
|
380
|
+
A clip that has played long enough: 3 seconds, or half of it if it is
|
|
381
|
+
shorter — once a clip a page visit. The site counts. */
|
|
382
|
+
|
|
383
|
+
const WATCHED_MS = 3000;
|
|
384
|
+
const told = new WeakMap<Element, Set<number>>();
|
|
385
|
+
|
|
386
|
+
function watchedIf(g: Group, clip: number, playedMs: number, totalMs: number, where: "card" | "full"): void {
|
|
387
|
+
if (!(totalMs > 0) || playedMs < Math.min(WATCHED_MS, totalMs / 2)) return;
|
|
388
|
+
const said = told.get(g.el) ?? new Set<number>();
|
|
389
|
+
if (said.has(clip)) return;
|
|
390
|
+
said.add(clip);
|
|
391
|
+
told.set(g.el, said);
|
|
392
|
+
g.root.dispatchEvent(new CustomEvent("pg-reels:watched", { bubbles: true, detail: { group: g.el, clip, id: g.el.getAttribute(ID), where } }));
|
|
393
|
+
}
|
|
394
|
+
|
|
369
395
|
// The clips of each group shown in the full view so far, this visit.
|
|
370
396
|
let watched = new WeakMap<Element, Set<number>>();
|
|
371
397
|
|
|
@@ -480,8 +506,15 @@ export function initReels(): () => void {
|
|
|
480
506
|
const clip = g.clips[g.at];
|
|
481
507
|
const v = videoOf(clip);
|
|
482
508
|
let progress: number;
|
|
483
|
-
if (v)
|
|
484
|
-
|
|
509
|
+
if (v) {
|
|
510
|
+
progress = v.duration ? v.currentTime / v.duration : 0;
|
|
511
|
+
watchedIf(g, g.at, v.currentTime * 1000, v.duration * 1000, "card");
|
|
512
|
+
} else {
|
|
513
|
+
const time = pictureTime(g, clip);
|
|
514
|
+
const played = g.shown + now - g.since;
|
|
515
|
+
progress = played / Math.max(1, time);
|
|
516
|
+
watchedIf(g, g.at, played, time, "card");
|
|
517
|
+
}
|
|
485
518
|
g.bars[g.at]?.style.setProperty(PROGRESS, String(Math.min(1, progress)));
|
|
486
519
|
if (!v && progress >= 1) due.push(g);
|
|
487
520
|
});
|
|
@@ -869,7 +902,10 @@ export function initReels(): () => void {
|
|
|
869
902
|
const g = current();
|
|
870
903
|
const clip = g.clips[view.ci];
|
|
871
904
|
const v = viewVideo();
|
|
872
|
-
const
|
|
905
|
+
const time = v ? v.duration * 1000 : pictureTime(g, clip);
|
|
906
|
+
const played = v ? v.currentTime * 1000 : view.shown + now - view.since;
|
|
907
|
+
const progress = v ? (v.duration ? v.currentTime / v.duration : 0) : played / Math.max(1, time);
|
|
908
|
+
watchedIf(g, view.ci, played, time, "full");
|
|
873
909
|
viewBars.children[view.ci]?.setAttribute("style", `${PROGRESS}: ${Math.min(1, progress)}`);
|
|
874
910
|
if (!v && progress >= 1) {
|
|
875
911
|
nextClip(true);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plusguard/reels",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "Shoppable reels for a store: a strip of video cards — each a group of clips, each clip with its own product — that opens into a full view. Up and down between groups, left and right within one, the product beside the video on a computer and under it on a phone. No dependencies.",
|
|
3
|
+
"version": "1.10.1",
|
|
4
|
+
"description": "Shoppable reels for a store: a strip of video cards — each a group of clips, each clip with its own product — that opens into a full view. Up and down between groups, left and right within one, the product beside the video on a computer and under it on a phone. Only the playing clips load; a clip watched is told to the site (pg-reels:watched), which counts. No dependencies.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
7
7
|
"types": "./dist/index.d.ts",
|