@plusguard/reels 1.7.0 → 1.9.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 +47 -24
- package/dist/index.js +48 -13
- package/index.css +76 -40
- package/index.ts +50 -13
- package/package.json +1 -1
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.9.0/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.9.0/dist/index.js";
|
|
29
29
|
initReels();
|
|
30
30
|
</script>
|
|
31
31
|
```
|
|
@@ -90,15 +90,15 @@ below).
|
|
|
90
90
|
`data-pg-reels-duration="4s"` on the clip, or `--pg-reels-duration` on
|
|
91
91
|
the group or above (5s by default). The bars under the card fill as each
|
|
92
92
|
plays; a bar pressed is that clip at once — one bar even for a card of
|
|
93
|
-
one clip. Out of sight it stops and waits on its poster; a hidden tab
|
|
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
95
|
- **The product is the clip's.** The products under a card are one a clip;
|
|
96
96
|
the playing one's shows (`data-pg-reels-current`).
|
|
97
97
|
- **Sound is one card's.** A sound button pressed gives the sound to its
|
|
98
98
|
card — every other card is muted; pressed again, off. The card going out
|
|
99
99
|
of sight takes the sound with it. The full view takes
|
|
100
|
-
it over while open
|
|
101
|
-
|
|
100
|
+
it over while open — from the card it opened on, if that one had it —
|
|
101
|
+
and keeps it: closed, every card is muted again.
|
|
102
102
|
- **The strip scrolls sideways** — a finger, a wheel, its arrows, one card
|
|
103
103
|
a press. It never moves by itself. `data-pg-reels-start` / `-end` on the
|
|
104
104
|
section while it stands at either end, for the arrows.
|
|
@@ -158,16 +158,18 @@ in it, copies of the site's markup: the clip, the group's
|
|
|
158
158
|
links; the rest of the clip passes presses to the taps under it.
|
|
159
159
|
- **Held down** — a finger, the mouse — it stands still, the controls
|
|
160
160
|
out of the way; let go and it goes on. Its play / pause button, Space.
|
|
161
|
-
- **Its corner:** the sound
|
|
162
|
-
the
|
|
163
|
-
element, copied, so it looks as in the card. The
|
|
164
|
-
(from its own counting); the package shows it.
|
|
165
|
-
|
|
161
|
+
- **Its corner:** the sound, play / pause and close at the video's top
|
|
162
|
+
right, the playing clip's view count under them — the card's
|
|
163
|
+
`data-pg-reels-views` element, copied, so it looks as in the card. The
|
|
164
|
+
number is the site's (from its own counting); the package shows it. On
|
|
165
|
+
a computer a second close, a plain ✕, at the window's top right, and
|
|
166
|
+
the ↑ ↓ at the window's left, their names on their right under the
|
|
167
|
+
mouse.
|
|
166
168
|
- **The product:** on a computer, a panel beside the video, touching it
|
|
167
|
-
as a post opened on Instagram (no corners where they meet,
|
|
168
|
-
outside),
|
|
169
|
+
as a post opened on Instagram (no corners where they meet, rounded ones
|
|
170
|
+
outside), as tall as the video, about a third of the
|
|
169
171
|
window wide: a head — the template's `data-pg-reels-title`, moved there
|
|
170
|
-
(the example puts the
|
|
172
|
+
(the example puts the product's name there) — a line under it; at the
|
|
171
173
|
bottom a foot — the template's `data-pg-reels-foot`, the link to the
|
|
172
174
|
product, always in sight; and between them the rest of the template,
|
|
173
175
|
scrolling.
|
|
@@ -231,7 +233,7 @@ and videos: the box has the shape, what is inside is 100% of it.
|
|
|
231
233
|
| `data-pg-reels-strip` | the row | Scrolls sideways |
|
|
232
234
|
| `data-pg-reels-group` | each group | A card and what is under it |
|
|
233
235
|
| `data-pg-reels-id` | a group | Its name, for what was seen to be remembered in this browser |
|
|
234
|
-
| `data-pg-reels-views` | in the card |
|
|
236
|
+
| `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 |
|
|
235
237
|
| `data-pg-reels-seen` | a group, the full view's head | Written: `"true"` once seen in the full view, `"false"` before |
|
|
236
238
|
| `data-pg-reels-card` | the card | The shape; its clips fill it |
|
|
237
239
|
| `data-pg-reels-clip` | each clip | A video with its poster, or a picture |
|
|
@@ -293,20 +295,41 @@ So in React they go in the clip, as an element kept hidden:
|
|
|
293
295
|
|
|
294
296
|
Give its pictures `loading="lazy"`: hidden, they load when the full view
|
|
295
297
|
shows them. See [`examples/react/Example.tsx`](examples/react/Example.tsx)
|
|
296
|
-
— the section from data
|
|
298
|
+
— the section from data (variants and categories too), and
|
|
299
|
+
`pg-reels:open` counted.
|
|
300
|
+
|
|
301
|
+
### The React example, running
|
|
302
|
+
|
|
303
|
+
[`examples/react`](examples/react) is a small Vite app: the static
|
|
304
|
+
example's six groups ([`data.ts`](examples/react/data.ts)) rendered with
|
|
305
|
+
`Example.tsx`, the static example's look
|
|
306
|
+
([`examples/static/example.css`](examples/static/example.css)) and its
|
|
307
|
+
media. It imports the package from its source (`../../index.ts`), so an
|
|
308
|
+
edit to the package shows at once — no build, no release.
|
|
309
|
+
|
|
310
|
+
```sh
|
|
311
|
+
cd examples/react
|
|
312
|
+
npm install
|
|
313
|
+
npm run dev # http://localhost:5110
|
|
314
|
+
```
|
|
297
315
|
|
|
298
316
|
## Example
|
|
299
317
|
|
|
300
318
|
[`examples/static/index.html`](examples/static/index.html) — six groups of
|
|
301
|
-
three to five clips, videos (`?duration=2s` sets a picture's time;
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
319
|
+
three to five clips, videos (`?duration=2s` sets a picture's time; the
|
|
320
|
+
switches at the top for the rings — pale once seen or always bright, and
|
|
321
|
+
bright again after a minute, an hour, a day or never: `?seen=off`,
|
|
322
|
+
`?seen-for=1h`), each clip with a product and its
|
|
323
|
+
details: its name heading the panel, a big picture at 16:9, small ones
|
|
324
|
+
— nine for the first product, a row that scrolls — the price, variants
|
|
325
|
+
as pills where there are some, a line about it, the post's text with its
|
|
326
|
+
#tags — links to them where the post is: Instagram, TikTok or YouTube —
|
|
327
|
+
a link. Every link out of the site (the profiles, the tags) is
|
|
328
|
+
`rel="nofollow noopener"`. Under the card the product
|
|
329
|
+
shows "In the video" over its name, the name in two lines' room (longer
|
|
330
|
+
ends in "…"), so every row is as tall — no price: it is one press away,
|
|
331
|
+
in the full view; over each clip's caption its category, a link to it
|
|
332
|
+
in a new tab — a dark pill, on the card and in the full view. The first group is
|
|
310
333
|
three clips from a food shop, the second five from a scarf shop, the
|
|
311
334
|
third four from a pasta and mantı maker, the fourth four from a
|
|
312
335
|
jeweller, the fifth four from a nut and sweet shop — a coffee with four
|
package/dist/index.js
CHANGED
|
@@ -33,8 +33,10 @@
|
|
|
33
33
|
* data-pg-reels-duration;
|
|
34
34
|
* the bars under it fill as each plays. A bar pressed is that clip at
|
|
35
35
|
* once. The clip playing shows its product: the products under the card
|
|
36
|
-
* are one per clip, and only the playing one's shows.
|
|
37
|
-
*
|
|
36
|
+
* are one per clip, and only the playing one's shows. So with view
|
|
37
|
+
* counts: one data-pg-reels-views a clip, in order, and only the playing
|
|
38
|
+
* clip's shows — or one for the whole group, always shown. The others wait
|
|
39
|
+
* on their posters. Out of sight, nothing plays.
|
|
38
40
|
*
|
|
39
41
|
* The strip scrolls sideways — a finger, a wheel, its arrows; it never
|
|
40
42
|
* moves by itself. data-pg-reels-start / -end on the section while it
|
|
@@ -54,9 +56,10 @@
|
|
|
54
56
|
* goes on or back — its ↑ and ↓ buttons, a wheel, ↑ and ↓; after a
|
|
55
57
|
* group's last clip, the next group. The product changes once it has
|
|
56
58
|
* landed. Held
|
|
57
|
-
* down — a finger, the mouse — it stands still; its sound
|
|
58
|
-
*
|
|
59
|
-
* data-pg-reels-views, the site's);
|
|
59
|
+
* down — a finger, the mouse — it stands still; its sound, play / pause
|
|
60
|
+
* and close at the video's top right, the clip's view count under them
|
|
61
|
+
* (its data-pg-reels-views, the site's); a close at the window's top
|
|
62
|
+
* right too, on a computer.
|
|
60
63
|
* Esc, Back, the dark around it close it too. The
|
|
61
64
|
* product: on a computer a panel beside the video — the product's
|
|
62
65
|
* <template data-pg-reels-detail>, the site's markup: a title (its
|
|
@@ -197,6 +200,8 @@ function partsOf(el, root) {
|
|
|
197
200
|
const own = (x) => x.closest(`[${GROUP}]`) === el;
|
|
198
201
|
const clips = [...el.querySelectorAll(`[${CLIP}]`)].filter(own);
|
|
199
202
|
const products = [...el.querySelectorAll(`[${PRODUCT}]`)].filter(own);
|
|
203
|
+
// A view count a clip, in order — or one, the group's.
|
|
204
|
+
const views = [...el.querySelectorAll(`[${VIEWS}]`)].filter(own);
|
|
200
205
|
const holder = [...el.querySelectorAll(`[${BARS}]`)].find(own);
|
|
201
206
|
// One bar a clip — made here, in the empty holder, once.
|
|
202
207
|
let bars = [];
|
|
@@ -214,7 +219,7 @@ function partsOf(el, root) {
|
|
|
214
219
|
bars = [...holder.children];
|
|
215
220
|
}
|
|
216
221
|
const current = clips.findIndex((c) => c.hasAttribute(CURRENT));
|
|
217
|
-
return { el, root, clips, products, bars, at: Math.max(0, current), ratio: 0, shown: 0, since: 0 };
|
|
222
|
+
return { el, root, clips, products, views, bars, at: Math.max(0, current), ratio: 0, shown: 0, since: 0 };
|
|
218
223
|
}
|
|
219
224
|
/* Show clip `i` of the group: its clip, its product, its bar. */
|
|
220
225
|
function show(g, i) {
|
|
@@ -234,6 +239,7 @@ function show(g, i) {
|
|
|
234
239
|
g.since = performance.now();
|
|
235
240
|
g.clips.forEach((c, k) => c.toggleAttribute(CURRENT, k === g.at));
|
|
236
241
|
g.products.forEach((p, k) => p.toggleAttribute(CURRENT, k === g.at));
|
|
242
|
+
g.views.forEach((v, k) => v.toggleAttribute(CURRENT, g.views.length === 1 || k === g.at));
|
|
237
243
|
g.bars.forEach((b, k) => {
|
|
238
244
|
b.toggleAttribute(DONE, k < g.at);
|
|
239
245
|
if (k === g.at)
|
|
@@ -596,7 +602,7 @@ export function initReels() {
|
|
|
596
602
|
// keys work at once, no ring on a button nobody chose.
|
|
597
603
|
dialog.tabIndex = -1;
|
|
598
604
|
dialog.innerHTML = `
|
|
599
|
-
<button type="button" data-pg-reels-
|
|
605
|
+
<button type="button" data-pg-reels-close aria-label="Close">${svg(ICONS.close)}</button>
|
|
600
606
|
<div data-pg-reels-stage>
|
|
601
607
|
<div data-pg-reels-view-steps>
|
|
602
608
|
<button type="button" data-pg-reels-view-up aria-label="Previous reel">${svg(ICONS.up)}</button>
|
|
@@ -618,6 +624,7 @@ export function initReels() {
|
|
|
618
624
|
<div data-pg-reels-view-tools>
|
|
619
625
|
<button type="button" ${SOUND} aria-pressed="false" aria-label="Sound">${svg(ICONS.soundOff)}${svg(ICONS.soundOn)}</button>
|
|
620
626
|
<button type="button" data-pg-reels-view-play aria-label="Pause">${svg(ICONS.pause)}${svg(ICONS.play)}</button>
|
|
627
|
+
<button type="button" data-pg-reels-view-close aria-label="Close">${svg(ICONS.close)}</button>
|
|
621
628
|
<div data-pg-reels-view-views></div>
|
|
622
629
|
</div>
|
|
623
630
|
</div>
|
|
@@ -680,9 +687,32 @@ export function initReels() {
|
|
|
680
687
|
const viewVideo = () => media.querySelector("video");
|
|
681
688
|
const current = () => view.list[view.gi];
|
|
682
689
|
let headOf = null;
|
|
690
|
+
// A clip's still: a video's poster, or the picture itself.
|
|
691
|
+
const stillOf = (clip) => clip?.querySelector("video")?.getAttribute("poster") || clip?.querySelector("img")?.getAttribute("src") || "";
|
|
692
|
+
// The stills shown next — the groups beside the one shown, the ones
|
|
693
|
+
// beside those, the clip after this one — fetched and decoded ahead: a
|
|
694
|
+
// group sliding in, the one coming in under it, the next clip, are
|
|
695
|
+
// never blank first.
|
|
696
|
+
const warmed = new Set();
|
|
697
|
+
const warm = (clip) => {
|
|
698
|
+
const src = stillOf(clip);
|
|
699
|
+
if (!src || warmed.has(src))
|
|
700
|
+
return;
|
|
701
|
+
warmed.add(src);
|
|
702
|
+
const img = new Image();
|
|
703
|
+
img.src = src;
|
|
704
|
+
img.decode?.().catch(() => { });
|
|
705
|
+
};
|
|
706
|
+
// Its still behind it too, painted at once from the cache, until the
|
|
707
|
+
// video's own poster and frames are there.
|
|
708
|
+
const backed = (holder, clip) => {
|
|
709
|
+
const src = stillOf(clip);
|
|
710
|
+
holder.style.background = src ? `#000 url(${JSON.stringify(src)}) center / cover no-repeat` : "";
|
|
711
|
+
};
|
|
683
712
|
// A group's first clip, for the video above or under the one shown:
|
|
684
713
|
// a picture, or a video on its poster — never playing.
|
|
685
714
|
const peekOf = (holder, g) => {
|
|
715
|
+
backed(holder, g?.clips[0]);
|
|
686
716
|
holder.replaceChildren(...(g ? [copyOf(g.clips[0])] : []));
|
|
687
717
|
holder.hidden = !g;
|
|
688
718
|
holder.querySelectorAll("video").forEach((x) => {
|
|
@@ -700,9 +730,9 @@ export function initReels() {
|
|
|
700
730
|
viewVideo()?.pause();
|
|
701
731
|
const head = g.el.querySelector(`[${HEAD}]`);
|
|
702
732
|
part("view-head").replaceChildren(...(head ? [copyOf(head)] : []));
|
|
703
|
-
// The
|
|
704
|
-
//
|
|
705
|
-
const views = g.
|
|
733
|
+
// The clip's view count — the site's, written in its card — under
|
|
734
|
+
// the close; the group's, when the card has only one.
|
|
735
|
+
const views = g.views.length === 1 ? g.views[0] : g.views[view.ci];
|
|
706
736
|
part("view-views").replaceChildren(...(views ? [copyOf(views)] : []));
|
|
707
737
|
// The head as it was before this group was looked at — its ring
|
|
708
738
|
// bright the first time, through all its clips — and from now on,
|
|
@@ -737,9 +767,12 @@ export function initReels() {
|
|
|
737
767
|
v.preload = "auto";
|
|
738
768
|
v.loop = false;
|
|
739
769
|
}
|
|
770
|
+
backed(media, clip);
|
|
740
771
|
media.replaceChildren(copy);
|
|
741
772
|
peekOf(before, view.list[view.gi - 1]);
|
|
742
773
|
peekOf(after, view.list[view.gi + 1]);
|
|
774
|
+
[-2, -1, 1, 2].forEach((d) => warm(view.list[view.gi + d]?.clips[0]));
|
|
775
|
+
warm(g.clips[view.ci + 1]);
|
|
743
776
|
const product = g.products[view.ci];
|
|
744
777
|
part("panel-summary").replaceChildren(...(product ? [copyOf(product)] : []));
|
|
745
778
|
// The details: in the product, or in the clip — a <template>, or
|
|
@@ -955,8 +988,10 @@ export function initReels() {
|
|
|
955
988
|
const g = current();
|
|
956
989
|
if (g)
|
|
957
990
|
show(g, view.ci);
|
|
958
|
-
//
|
|
959
|
-
|
|
991
|
+
// Closed, the cards are all muted again — the full view's sound
|
|
992
|
+
// stays in it, whichever card it came from.
|
|
993
|
+
sound = false;
|
|
994
|
+
owner = null;
|
|
960
995
|
if (dialog.open)
|
|
961
996
|
dialog.close();
|
|
962
997
|
media.replaceChildren();
|
|
@@ -979,7 +1014,7 @@ export function initReels() {
|
|
|
979
1014
|
// The dark around it.
|
|
980
1015
|
if (t === dialog || t.hasAttribute("data-pg-reels-stage"))
|
|
981
1016
|
return closeView();
|
|
982
|
-
if (t.closest("[data-pg-reels-view-close]"))
|
|
1017
|
+
if (t.closest("[data-pg-reels-view-close], [data-pg-reels-close]"))
|
|
983
1018
|
return closeView();
|
|
984
1019
|
if (sliding)
|
|
985
1020
|
return;
|
package/index.css
CHANGED
|
@@ -95,23 +95,50 @@
|
|
|
95
95
|
}
|
|
96
96
|
[data-pg-reels-bar] > span,
|
|
97
97
|
[data-pg-reels-view-bar] > span {
|
|
98
|
+
--rest: color-mix(in srgb, currentColor 25%, transparent);
|
|
98
99
|
display: block;
|
|
99
100
|
height: 100%;
|
|
100
101
|
border-radius: 999px;
|
|
101
|
-
background: linear-gradient(currentColor, currentColor) no-repeat left / calc(var(--pg-reels-progress, 0) * 100%) 100%,
|
|
102
|
+
background: linear-gradient(currentColor, currentColor) no-repeat left / calc(var(--pg-reels-progress, 0) * 100%) 100%, var(--rest);
|
|
103
|
+
transition: background-color 0.15s;
|
|
104
|
+
}
|
|
105
|
+
/* The bar under the mouse: its part still to play a shade between the
|
|
106
|
+
played and the rest — this one can be pressed. */
|
|
107
|
+
@media (hover: hover) {
|
|
108
|
+
[data-pg-reels-bar]:hover > span,
|
|
109
|
+
[data-pg-reels-view-bar]:hover > span {
|
|
110
|
+
--rest: color-mix(in srgb, currentColor 40%, transparent);
|
|
111
|
+
}
|
|
102
112
|
}
|
|
103
113
|
[data-pg-reels-bar][data-pg-reels-done] > span,
|
|
104
114
|
[data-pg-reels-view-bar][data-pg-reels-done] > span {
|
|
105
115
|
background-size: 100% 100%;
|
|
106
116
|
}
|
|
117
|
+
/* Under the card: a taller row to press — 1rem, the same room in the
|
|
118
|
+
page as before — and under the mouse every bar thickens, 2px to 6px. */
|
|
119
|
+
[data-pg-reels-bar] {
|
|
120
|
+
height: 1rem;
|
|
121
|
+
margin-block: -0.125rem;
|
|
122
|
+
padding-block: 0.4375rem;
|
|
123
|
+
transition: padding-block 0.15s ease;
|
|
124
|
+
}
|
|
125
|
+
@media (hover: hover) {
|
|
126
|
+
[data-pg-reels-bars]:hover > [data-pg-reels-bar] {
|
|
127
|
+
padding-block: 0.3125rem;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
[data-pg-reels-bars]:has(:focus-visible) > [data-pg-reels-bar] {
|
|
131
|
+
padding-block: 0.3125rem;
|
|
132
|
+
}
|
|
107
133
|
|
|
108
134
|
/* A product's details are for the full view only. */
|
|
109
135
|
[data-pg-reels-detail] {
|
|
110
136
|
display: none !important;
|
|
111
137
|
}
|
|
112
138
|
|
|
113
|
-
/* The products: only the playing clip's
|
|
114
|
-
[data-pg-reels-group] [data-pg-reels-product]:not([data-pg-reels-current])
|
|
139
|
+
/* The products and the view counts: only the playing clip's show. */
|
|
140
|
+
[data-pg-reels-group] [data-pg-reels-product]:not([data-pg-reels-current]),
|
|
141
|
+
[data-pg-reels-group] [data-pg-reels-views]:not([data-pg-reels-current]) {
|
|
115
142
|
display: none !important;
|
|
116
143
|
}
|
|
117
144
|
|
|
@@ -205,8 +232,10 @@ dialog[data-pg-reels-viewer] [data-pg-reels-view-side] {
|
|
|
205
232
|
cursor: pointer;
|
|
206
233
|
transition: background-color 0.15s;
|
|
207
234
|
}
|
|
208
|
-
|
|
209
|
-
|
|
235
|
+
@media (hover: hover) {
|
|
236
|
+
dialog[data-pg-reels-viewer] [data-pg-reels-view-side]:hover {
|
|
237
|
+
background: #fff;
|
|
238
|
+
}
|
|
210
239
|
}
|
|
211
240
|
[data-pg-reels-view-side="prev"] {
|
|
212
241
|
right: calc(100% + 0.75rem);
|
|
@@ -254,7 +283,7 @@ dialog[data-pg-reels-viewer] [data-pg-reels-view-side] svg {
|
|
|
254
283
|
flex: none;
|
|
255
284
|
height: var(--h);
|
|
256
285
|
aspect-ratio: var(--pg-reels-ratio, 9 / 16);
|
|
257
|
-
border-radius: 0.
|
|
286
|
+
border-radius: 0.75rem;
|
|
258
287
|
overflow: hidden;
|
|
259
288
|
background: #000;
|
|
260
289
|
isolation: isolate;
|
|
@@ -288,13 +317,11 @@ dialog[data-pg-reels-viewer] [data-pg-reels-view-side] svg {
|
|
|
288
317
|
aspect-ratio: var(--pg-reels-ratio, 9 / 16);
|
|
289
318
|
padding: 0;
|
|
290
319
|
border: 0;
|
|
291
|
-
border-radius: 0.
|
|
320
|
+
border-radius: 0.75rem;
|
|
292
321
|
overflow: hidden;
|
|
293
322
|
background: #000;
|
|
294
323
|
color: #fff;
|
|
295
|
-
opacity: 0.5;
|
|
296
324
|
cursor: pointer;
|
|
297
|
-
transition: opacity 0.2s;
|
|
298
325
|
}
|
|
299
326
|
[data-pg-reels-view-peek="before"] {
|
|
300
327
|
position: absolute;
|
|
@@ -302,10 +329,6 @@ dialog[data-pg-reels-viewer] [data-pg-reels-view-side] svg {
|
|
|
302
329
|
right: 0;
|
|
303
330
|
bottom: calc(100% + var(--gap));
|
|
304
331
|
}
|
|
305
|
-
[data-pg-reels-view-peek]:hover,
|
|
306
|
-
[data-pg-reels-sliding] [data-pg-reels-view-peek] {
|
|
307
|
-
opacity: 1;
|
|
308
|
-
}
|
|
309
332
|
[data-pg-reels-view-peek][hidden] {
|
|
310
333
|
display: block;
|
|
311
334
|
visibility: hidden;
|
|
@@ -376,12 +399,12 @@ dialog[data-pg-reels-viewer] [data-pg-reels-view-side] svg {
|
|
|
376
399
|
[data-pg-reels-view-head] {
|
|
377
400
|
min-width: 0;
|
|
378
401
|
}
|
|
379
|
-
/* The video's top right: the sound
|
|
380
|
-
count under them. Only the buttons take a press: the rest of the corner
|
|
402
|
+
/* The video's top right: the sound, play / pause and close, the group's
|
|
403
|
+
view count under them. Only the buttons take a press: the rest of the corner
|
|
381
404
|
is the video's. */
|
|
382
405
|
[data-pg-reels-view-row] > [data-pg-reels-view-tools] {
|
|
383
406
|
display: grid;
|
|
384
|
-
grid-template-columns: auto auto;
|
|
407
|
+
grid-template-columns: auto auto auto;
|
|
385
408
|
gap: 0.375rem;
|
|
386
409
|
pointer-events: none;
|
|
387
410
|
}
|
|
@@ -407,6 +430,13 @@ dialog[data-pg-reels-viewer] [data-pg-reels-view-side] svg {
|
|
|
407
430
|
border-radius: 50%;
|
|
408
431
|
background: rgb(0 0 0 / 0.35);
|
|
409
432
|
cursor: pointer;
|
|
433
|
+
transition: background-color 0.2s;
|
|
434
|
+
}
|
|
435
|
+
/* The video's own buttons a shade darker under the mouse. */
|
|
436
|
+
@media (hover: hover) {
|
|
437
|
+
[data-pg-reels-view-tools] > button:hover {
|
|
438
|
+
background: rgb(0 0 0 / 0.55);
|
|
439
|
+
}
|
|
410
440
|
}
|
|
411
441
|
/* Each button its two pictures: sound off / on, pause / play. */
|
|
412
442
|
[data-pg-reels-viewer] [data-pg-reels-sound] > svg:last-child,
|
|
@@ -420,8 +450,8 @@ dialog[data-pg-reels-viewer] [data-pg-reels-view-side] svg {
|
|
|
420
450
|
display: block;
|
|
421
451
|
}
|
|
422
452
|
|
|
423
|
-
/* ↑ ↓: the group before, the next —
|
|
424
|
-
round and grey, their name
|
|
453
|
+
/* ↑ ↓: the group before, the next — at the window's left, at the video's
|
|
454
|
+
middle, round and grey, their name on their right under the mouse. */
|
|
425
455
|
[data-pg-reels-view-steps] {
|
|
426
456
|
position: absolute;
|
|
427
457
|
left: 1.25rem;
|
|
@@ -432,8 +462,8 @@ dialog[data-pg-reels-viewer] [data-pg-reels-view-side] svg {
|
|
|
432
462
|
gap: 1rem;
|
|
433
463
|
}
|
|
434
464
|
|
|
435
|
-
/*
|
|
436
|
-
dialog[data-pg-reels-viewer] [data-pg-reels-
|
|
465
|
+
/* A second close at the window's top right, a plain ✕ as on Instagram. */
|
|
466
|
+
dialog[data-pg-reels-viewer] [data-pg-reels-close] {
|
|
437
467
|
position: absolute;
|
|
438
468
|
z-index: 3;
|
|
439
469
|
top: 0.75rem;
|
|
@@ -450,10 +480,12 @@ dialog[data-pg-reels-viewer] [data-pg-reels-view-close] {
|
|
|
450
480
|
cursor: pointer;
|
|
451
481
|
transition: background-color 0.15s;
|
|
452
482
|
}
|
|
453
|
-
|
|
454
|
-
|
|
483
|
+
@media (hover: hover) {
|
|
484
|
+
dialog[data-pg-reels-viewer] [data-pg-reels-close]:hover {
|
|
485
|
+
background: rgb(255 255 255 / 0.12);
|
|
486
|
+
}
|
|
455
487
|
}
|
|
456
|
-
dialog[data-pg-reels-viewer] [data-pg-reels-
|
|
488
|
+
dialog[data-pg-reels-viewer] [data-pg-reels-close] svg {
|
|
457
489
|
width: 1.75rem;
|
|
458
490
|
height: 1.75rem;
|
|
459
491
|
}
|
|
@@ -467,8 +499,10 @@ dialog[data-pg-reels-viewer] [data-pg-reels-view-steps] svg {
|
|
|
467
499
|
width: 1.5rem;
|
|
468
500
|
height: 1.5rem;
|
|
469
501
|
}
|
|
470
|
-
|
|
471
|
-
|
|
502
|
+
@media (hover: hover) {
|
|
503
|
+
[data-pg-reels-view-steps] > button:not(:disabled):hover {
|
|
504
|
+
background: rgb(255 255 255 / 0.2);
|
|
505
|
+
}
|
|
472
506
|
}
|
|
473
507
|
[data-pg-reels-view-steps] > button:disabled {
|
|
474
508
|
opacity: 0.3;
|
|
@@ -477,7 +511,7 @@ dialog[data-pg-reels-viewer] [data-pg-reels-view-steps] svg {
|
|
|
477
511
|
[data-pg-reels-view-steps] > button::after {
|
|
478
512
|
content: attr(aria-label);
|
|
479
513
|
position: absolute;
|
|
480
|
-
|
|
514
|
+
left: calc(100% + 0.75rem);
|
|
481
515
|
top: 50%;
|
|
482
516
|
translate: 0 -50%;
|
|
483
517
|
padding: 0.5rem 0.625rem;
|
|
@@ -491,12 +525,14 @@ dialog[data-pg-reels-viewer] [data-pg-reels-view-steps] svg {
|
|
|
491
525
|
pointer-events: none;
|
|
492
526
|
transition: opacity 0.1s;
|
|
493
527
|
}
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
528
|
+
@media (hover: hover) {
|
|
529
|
+
[data-pg-reels-view-steps] > button:not(:disabled):hover::after {
|
|
530
|
+
opacity: 1;
|
|
531
|
+
transition-delay: 0.4s;
|
|
532
|
+
}
|
|
497
533
|
}
|
|
498
534
|
|
|
499
|
-
/* The product: a panel
|
|
535
|
+
/* The product: a panel beside the video, as tall as it — a head with the product's
|
|
500
536
|
name (the template's data-pg-reels-title) and the close, a line under
|
|
501
537
|
it, the rest of the template under that, scrolling. A long name goes
|
|
502
538
|
onto a second line; the close stays at the top. */
|
|
@@ -508,8 +544,8 @@ dialog[data-pg-reels-viewer] [data-pg-reels-view-steps] svg {
|
|
|
508
544
|
flex: none;
|
|
509
545
|
box-sizing: border-box;
|
|
510
546
|
width: var(--pg-reels-panel);
|
|
511
|
-
height:
|
|
512
|
-
border-radius: 0.
|
|
547
|
+
height: var(--h);
|
|
548
|
+
border-radius: 0.75rem;
|
|
513
549
|
background: #fff;
|
|
514
550
|
color: #111;
|
|
515
551
|
overflow: hidden;
|
|
@@ -537,6 +573,11 @@ dialog[data-pg-reels-viewer] [data-pg-reels-view-steps] svg {
|
|
|
537
573
|
padding: 1.25rem;
|
|
538
574
|
overflow: auto;
|
|
539
575
|
overscroll-behavior: contain;
|
|
576
|
+
/* It scrolls — a finger, a wheel — with no bar showing. */
|
|
577
|
+
scrollbar-width: none;
|
|
578
|
+
}
|
|
579
|
+
[data-pg-reels-panel-detail]::-webkit-scrollbar {
|
|
580
|
+
display: none;
|
|
540
581
|
}
|
|
541
582
|
/* Variants: only the chosen one's gallery shows. */
|
|
542
583
|
[data-pg-reels-panel] [data-pg-reels-gallery]:not([data-pg-reels-current]) {
|
|
@@ -566,13 +607,9 @@ dialog[data-pg-reels-viewer] [data-pg-reels-view-steps] svg {
|
|
|
566
607
|
display: block;
|
|
567
608
|
padding: 0;
|
|
568
609
|
}
|
|
569
|
-
/* The
|
|
570
|
-
dialog[data-pg-reels-viewer] [data-pg-reels-
|
|
571
|
-
|
|
572
|
-
right: 0.375rem;
|
|
573
|
-
}
|
|
574
|
-
[data-pg-reels-view-row] > [data-pg-reels-view-tools] {
|
|
575
|
-
margin-right: 2.75rem;
|
|
610
|
+
/* The video fills the window: its own close is the one. */
|
|
611
|
+
dialog[data-pg-reels-viewer] [data-pg-reels-close] {
|
|
612
|
+
display: none;
|
|
576
613
|
}
|
|
577
614
|
[data-pg-reels-pair] {
|
|
578
615
|
display: contents;
|
|
@@ -603,7 +640,6 @@ dialog[data-pg-reels-viewer] [data-pg-reels-view-steps] svg {
|
|
|
603
640
|
height: 100%;
|
|
604
641
|
aspect-ratio: auto;
|
|
605
642
|
border-radius: 0;
|
|
606
|
-
opacity: 1;
|
|
607
643
|
}
|
|
608
644
|
[data-pg-reels-view-peek="before"] {
|
|
609
645
|
bottom: 100%;
|
package/index.ts
CHANGED
|
@@ -33,8 +33,10 @@
|
|
|
33
33
|
* data-pg-reels-duration;
|
|
34
34
|
* the bars under it fill as each plays. A bar pressed is that clip at
|
|
35
35
|
* once. The clip playing shows its product: the products under the card
|
|
36
|
-
* are one per clip, and only the playing one's shows.
|
|
37
|
-
*
|
|
36
|
+
* are one per clip, and only the playing one's shows. So with view
|
|
37
|
+
* counts: one data-pg-reels-views a clip, in order, and only the playing
|
|
38
|
+
* clip's shows — or one for the whole group, always shown. The others wait
|
|
39
|
+
* on their posters. Out of sight, nothing plays.
|
|
38
40
|
*
|
|
39
41
|
* The strip scrolls sideways — a finger, a wheel, its arrows; it never
|
|
40
42
|
* moves by itself. data-pg-reels-start / -end on the section while it
|
|
@@ -54,9 +56,10 @@
|
|
|
54
56
|
* goes on or back — its ↑ and ↓ buttons, a wheel, ↑ and ↓; after a
|
|
55
57
|
* group's last clip, the next group. The product changes once it has
|
|
56
58
|
* landed. Held
|
|
57
|
-
* down — a finger, the mouse — it stands still; its sound
|
|
58
|
-
*
|
|
59
|
-
* data-pg-reels-views, the site's);
|
|
59
|
+
* down — a finger, the mouse — it stands still; its sound, play / pause
|
|
60
|
+
* and close at the video's top right, the clip's view count under them
|
|
61
|
+
* (its data-pg-reels-views, the site's); a close at the window's top
|
|
62
|
+
* right too, on a computer.
|
|
60
63
|
* Esc, Back, the dark around it close it too. The
|
|
61
64
|
* product: on a computer a panel beside the video — the product's
|
|
62
65
|
* <template data-pg-reels-detail>, the site's markup: a title (its
|
|
@@ -154,6 +157,7 @@ type Group = {
|
|
|
154
157
|
root: HTMLElement;
|
|
155
158
|
clips: HTMLElement[];
|
|
156
159
|
products: HTMLElement[];
|
|
160
|
+
views: HTMLElement[];
|
|
157
161
|
bars: HTMLElement[];
|
|
158
162
|
at: number;
|
|
159
163
|
ratio: number;
|
|
@@ -223,6 +227,8 @@ function partsOf(el: HTMLElement, root: HTMLElement): Group {
|
|
|
223
227
|
const own = (x: Element): boolean => x.closest(`[${GROUP}]`) === el;
|
|
224
228
|
const clips = [...el.querySelectorAll<HTMLElement>(`[${CLIP}]`)].filter(own);
|
|
225
229
|
const products = [...el.querySelectorAll<HTMLElement>(`[${PRODUCT}]`)].filter(own);
|
|
230
|
+
// A view count a clip, in order — or one, the group's.
|
|
231
|
+
const views = [...el.querySelectorAll<HTMLElement>(`[${VIEWS}]`)].filter(own);
|
|
226
232
|
const holder = [...el.querySelectorAll<HTMLElement>(`[${BARS}]`)].find(own);
|
|
227
233
|
// One bar a clip — made here, in the empty holder, once.
|
|
228
234
|
let bars: HTMLElement[] = [];
|
|
@@ -242,7 +248,7 @@ function partsOf(el: HTMLElement, root: HTMLElement): Group {
|
|
|
242
248
|
bars = [...holder.children] as HTMLElement[];
|
|
243
249
|
}
|
|
244
250
|
const current = clips.findIndex((c) => c.hasAttribute(CURRENT));
|
|
245
|
-
return { el, root, clips, products, bars, at: Math.max(0, current), ratio: 0, shown: 0, since: 0 };
|
|
251
|
+
return { el, root, clips, products, views, bars, at: Math.max(0, current), ratio: 0, shown: 0, since: 0 };
|
|
246
252
|
}
|
|
247
253
|
|
|
248
254
|
/* Show clip `i` of the group: its clip, its product, its bar. */
|
|
@@ -262,6 +268,7 @@ function show(g: Group, i: number): void {
|
|
|
262
268
|
g.since = performance.now();
|
|
263
269
|
g.clips.forEach((c, k) => c.toggleAttribute(CURRENT, k === g.at));
|
|
264
270
|
g.products.forEach((p, k) => p.toggleAttribute(CURRENT, k === g.at));
|
|
271
|
+
g.views.forEach((v, k) => v.toggleAttribute(CURRENT, g.views.length === 1 || k === g.at));
|
|
265
272
|
g.bars.forEach((b, k) => {
|
|
266
273
|
b.toggleAttribute(DONE, k < g.at);
|
|
267
274
|
if (k === g.at) b.setAttribute("aria-current", "true");
|
|
@@ -614,7 +621,7 @@ export function initReels(): () => void {
|
|
|
614
621
|
// keys work at once, no ring on a button nobody chose.
|
|
615
622
|
dialog.tabIndex = -1;
|
|
616
623
|
dialog.innerHTML = `
|
|
617
|
-
<button type="button" data-pg-reels-
|
|
624
|
+
<button type="button" data-pg-reels-close aria-label="Close">${svg(ICONS.close)}</button>
|
|
618
625
|
<div data-pg-reels-stage>
|
|
619
626
|
<div data-pg-reels-view-steps>
|
|
620
627
|
<button type="button" data-pg-reels-view-up aria-label="Previous reel">${svg(ICONS.up)}</button>
|
|
@@ -636,6 +643,7 @@ export function initReels(): () => void {
|
|
|
636
643
|
<div data-pg-reels-view-tools>
|
|
637
644
|
<button type="button" ${SOUND} aria-pressed="false" aria-label="Sound">${svg(ICONS.soundOff)}${svg(ICONS.soundOn)}</button>
|
|
638
645
|
<button type="button" data-pg-reels-view-play aria-label="Pause">${svg(ICONS.pause)}${svg(ICONS.play)}</button>
|
|
646
|
+
<button type="button" data-pg-reels-view-close aria-label="Close">${svg(ICONS.close)}</button>
|
|
639
647
|
<div data-pg-reels-view-views></div>
|
|
640
648
|
</div>
|
|
641
649
|
</div>
|
|
@@ -701,9 +709,33 @@ export function initReels(): () => void {
|
|
|
701
709
|
const current = (): Group => view.list[view.gi];
|
|
702
710
|
let headOf: Group | null = null;
|
|
703
711
|
|
|
712
|
+
// A clip's still: a video's poster, or the picture itself.
|
|
713
|
+
const stillOf = (clip: HTMLElement | undefined): string =>
|
|
714
|
+
clip?.querySelector("video")?.getAttribute("poster") || clip?.querySelector("img")?.getAttribute("src") || "";
|
|
715
|
+
// The stills shown next — the groups beside the one shown, the ones
|
|
716
|
+
// beside those, the clip after this one — fetched and decoded ahead: a
|
|
717
|
+
// group sliding in, the one coming in under it, the next clip, are
|
|
718
|
+
// never blank first.
|
|
719
|
+
const warmed = new Set<string>();
|
|
720
|
+
const warm = (clip: HTMLElement | undefined): void => {
|
|
721
|
+
const src = stillOf(clip);
|
|
722
|
+
if (!src || warmed.has(src)) return;
|
|
723
|
+
warmed.add(src);
|
|
724
|
+
const img = new Image();
|
|
725
|
+
img.src = src;
|
|
726
|
+
img.decode?.().catch(() => {});
|
|
727
|
+
};
|
|
728
|
+
// Its still behind it too, painted at once from the cache, until the
|
|
729
|
+
// video's own poster and frames are there.
|
|
730
|
+
const backed = (holder: HTMLElement, clip: HTMLElement | undefined): void => {
|
|
731
|
+
const src = stillOf(clip);
|
|
732
|
+
holder.style.background = src ? `#000 url(${JSON.stringify(src)}) center / cover no-repeat` : "";
|
|
733
|
+
};
|
|
734
|
+
|
|
704
735
|
// A group's first clip, for the video above or under the one shown:
|
|
705
736
|
// a picture, or a video on its poster — never playing.
|
|
706
737
|
const peekOf = (holder: HTMLElement, g: Group | undefined): void => {
|
|
738
|
+
backed(holder, g?.clips[0]);
|
|
707
739
|
holder.replaceChildren(...(g ? [copyOf(g.clips[0])] : []));
|
|
708
740
|
holder.hidden = !g;
|
|
709
741
|
holder.querySelectorAll("video").forEach((x) => {
|
|
@@ -723,9 +755,9 @@ export function initReels(): () => void {
|
|
|
723
755
|
|
|
724
756
|
const head = g.el.querySelector(`[${HEAD}]`);
|
|
725
757
|
part("view-head").replaceChildren(...(head ? [copyOf(head)] : []));
|
|
726
|
-
// The
|
|
727
|
-
//
|
|
728
|
-
const views = g.
|
|
758
|
+
// The clip's view count — the site's, written in its card — under
|
|
759
|
+
// the close; the group's, when the card has only one.
|
|
760
|
+
const views = g.views.length === 1 ? g.views[0] : g.views[view.ci];
|
|
729
761
|
part("view-views").replaceChildren(...(views ? [copyOf(views)] : []));
|
|
730
762
|
// The head as it was before this group was looked at — its ring
|
|
731
763
|
// bright the first time, through all its clips — and from now on,
|
|
@@ -762,9 +794,12 @@ export function initReels(): () => void {
|
|
|
762
794
|
v.preload = "auto";
|
|
763
795
|
v.loop = false;
|
|
764
796
|
}
|
|
797
|
+
backed(media, clip);
|
|
765
798
|
media.replaceChildren(copy);
|
|
766
799
|
peekOf(before, view.list[view.gi - 1]);
|
|
767
800
|
peekOf(after, view.list[view.gi + 1]);
|
|
801
|
+
[-2, -1, 1, 2].forEach((d) => warm(view.list[view.gi + d]?.clips[0]));
|
|
802
|
+
warm(g.clips[view.ci + 1]);
|
|
768
803
|
|
|
769
804
|
const product = g.products[view.ci];
|
|
770
805
|
part("panel-summary").replaceChildren(...(product ? [copyOf(product)] : []));
|
|
@@ -967,8 +1002,10 @@ export function initReels(): () => void {
|
|
|
967
1002
|
press = null;
|
|
968
1003
|
const g = current();
|
|
969
1004
|
if (g) show(g, view.ci);
|
|
970
|
-
//
|
|
971
|
-
|
|
1005
|
+
// Closed, the cards are all muted again — the full view's sound
|
|
1006
|
+
// stays in it, whichever card it came from.
|
|
1007
|
+
sound = false;
|
|
1008
|
+
owner = null;
|
|
972
1009
|
if (dialog.open) dialog.close();
|
|
973
1010
|
media.replaceChildren();
|
|
974
1011
|
if (view.pushed && !byBack) history.back();
|
|
@@ -988,7 +1025,7 @@ export function initReels(): () => void {
|
|
|
988
1025
|
}
|
|
989
1026
|
// The dark around it.
|
|
990
1027
|
if (t === dialog || t.hasAttribute("data-pg-reels-stage")) return closeView();
|
|
991
|
-
if (t.closest("[data-pg-reels-view-close]")) return closeView();
|
|
1028
|
+
if (t.closest("[data-pg-reels-view-close], [data-pg-reels-close]")) return closeView();
|
|
992
1029
|
if (sliding) return;
|
|
993
1030
|
if (t.closest('[data-pg-reels-view-on], [data-pg-reels-view-side="next"]')) return nextClip();
|
|
994
1031
|
if (t.closest('[data-pg-reels-view-back], [data-pg-reels-view-side="prev"]')) return prevClip();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plusguard/reels",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.9.0",
|
|
4
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.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|