@plusguard/reels 1.7.0 → 1.8.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 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.7.0/index.css" />
26
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@plusguard/reels@1.8.0/index.css" />
27
27
  <script type="module">
28
- import { initReels } from "https://cdn.jsdelivr.net/npm/@plusguard/reels@1.7.0/dist/index.js";
28
+ import { initReels } from "https://cdn.jsdelivr.net/npm/@plusguard/reels@1.8.0/dist/index.js";
29
29
  initReels();
30
30
  </script>
31
31
  ```
@@ -90,7 +90,7 @@ 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`).
@@ -158,14 +158,16 @@ 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 and play / pause at the video's top right,
162
- the group's view count under them — the card's `data-pg-reels-views`
163
- element, copied, so it looks as in the card. The number is the site's
164
- (from its own counting); the package shows it. The close is a plain ✕ at
165
- the window's top right, the ↑ ↓ at the window's left.
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, small ones
168
- outside), from its top to the window's foot, about a third of the
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
172
  (the example puts the category there) — a line under it; at the
171
173
  bottom a foot — the template's `data-pg-reels-foot`, the link to the
@@ -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 | The group's view count, the site's — copied into the full view, left of the close |
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,38 @@ 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, and `pg-reels:open` counted.
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; `?seen=off`,
302
- `?seen-for=1h` for the rings), each clip with a product and its
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
303
323
  details: its category (a link), its name in the panel's head, a big
304
324
  picture at 4:3, small ones — nine for the first product, a row that
305
325
  scrolls — the price, a line about it, a link. Under the card the product
306
- shows its category and price, its name in two lines' room (longer ends in
307
- "…"), so every row is as tall; the line over each clip's caption is the
308
- category too; in
309
- the full view the category is a tag on the video. The first group is
326
+ shows "In the video" over its name, the name in two lines' room (longer
327
+ ends in "…"), so every row is as tall — no price: it is one press away,
328
+ in the full view; over each clip's caption its category, a link to it
329
+ in a new tab — a dark pill, on the card and in the full view. The first group is
310
330
  three clips from a food shop, the second five from a scarf shop, the
311
331
  third four from a pasta and mantı maker, the fourth four from a
312
332
  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. The others wait on
37
- * their posters. Out of sight, nothing plays.
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 and play /
58
- * pause at the video's top right, the group's view count under them (its
59
- * data-pg-reels-views, the site's); its close at the window's top right.
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-view-close aria-label="Close">${svg(ICONS.close)}</button>
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>
@@ -700,9 +707,9 @@ export function initReels() {
700
707
  viewVideo()?.pause();
701
708
  const head = g.el.querySelector(`[${HEAD}]`);
702
709
  part("view-head").replaceChildren(...(head ? [copyOf(head)] : []));
703
- // The group's view count — the site's, written in its card — left
704
- // of the close.
705
- const views = g.el.querySelector(`[${VIEWS}]`);
710
+ // The clip's view count — the site's, written in its card — under
711
+ // the close; the group's, when the card has only one.
712
+ const views = g.views.length === 1 ? g.views[0] : g.views[view.ci];
706
713
  part("view-views").replaceChildren(...(views ? [copyOf(views)] : []));
707
714
  // The head as it was before this group was looked at — its ring
708
715
  // bright the first time, through all its clips — and from now on,
@@ -979,7 +986,7 @@ export function initReels() {
979
986
  // The dark around it.
980
987
  if (t === dialog || t.hasAttribute("data-pg-reels-stage"))
981
988
  return closeView();
982
- if (t.closest("[data-pg-reels-view-close]"))
989
+ if (t.closest("[data-pg-reels-view-close], [data-pg-reels-close]"))
983
990
  return closeView();
984
991
  if (sliding)
985
992
  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%, color-mix(in srgb, currentColor 25%, transparent);
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 shows. */
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
- dialog[data-pg-reels-viewer] [data-pg-reels-view-side]:hover {
209
- background: #fff;
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.25rem;
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.25rem;
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 and play / pause, the group's view
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 — left of the video, at its middle,
424
- round and grey, their name beside them under the mouse. */
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
- /* The close: the window's top right, a plain ✕ as on Instagram. */
436
- dialog[data-pg-reels-viewer] [data-pg-reels-view-close] {
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
- dialog[data-pg-reels-viewer] [data-pg-reels-view-close]:hover {
454
- background: rgb(255 255 255 / 0.12);
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-view-close] svg {
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
- [data-pg-reels-view-steps] > button:not(:disabled):hover {
471
- background: rgb(255 255 255 / 0.2);
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
- right: calc(100% + 0.75rem);
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
- [data-pg-reels-view-steps] > button:not(:disabled):hover::after {
495
- opacity: 1;
496
- transition-delay: 0.4s;
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 from the video's top to the window's foot — a head with the product's
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: calc(100dvh - 2 * var(--gap));
512
- border-radius: 0.25rem;
547
+ height: var(--h);
548
+ border-radius: 0.75rem;
513
549
  background: #fff;
514
550
  color: #111;
515
551
  overflow: hidden;
@@ -566,13 +602,9 @@ dialog[data-pg-reels-viewer] [data-pg-reels-view-steps] svg {
566
602
  display: block;
567
603
  padding: 0;
568
604
  }
569
- /* The close over the video's top right; the sound and pause beside it. */
570
- dialog[data-pg-reels-viewer] [data-pg-reels-view-close] {
571
- top: max(0.5rem, env(safe-area-inset-top));
572
- right: 0.375rem;
573
- }
574
- [data-pg-reels-view-row] > [data-pg-reels-view-tools] {
575
- margin-right: 2.75rem;
605
+ /* The video fills the window: its own close is the one. */
606
+ dialog[data-pg-reels-viewer] [data-pg-reels-close] {
607
+ display: none;
576
608
  }
577
609
  [data-pg-reels-pair] {
578
610
  display: contents;
@@ -603,7 +635,6 @@ dialog[data-pg-reels-viewer] [data-pg-reels-view-steps] svg {
603
635
  height: 100%;
604
636
  aspect-ratio: auto;
605
637
  border-radius: 0;
606
- opacity: 1;
607
638
  }
608
639
  [data-pg-reels-view-peek="before"] {
609
640
  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. The others wait on
37
- * their posters. Out of sight, nothing plays.
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 and play /
58
- * pause at the video's top right, the group's view count under them (its
59
- * data-pg-reels-views, the site's); its close at the window's top right.
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-view-close aria-label="Close">${svg(ICONS.close)}</button>
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>
@@ -723,9 +731,9 @@ export function initReels(): () => void {
723
731
 
724
732
  const head = g.el.querySelector(`[${HEAD}]`);
725
733
  part("view-head").replaceChildren(...(head ? [copyOf(head)] : []));
726
- // The group's view count — the site's, written in its card — left
727
- // of the close.
728
- const views = g.el.querySelector(`[${VIEWS}]`);
734
+ // The clip's view count — the site's, written in its card — under
735
+ // the close; the group's, when the card has only one.
736
+ const views = g.views.length === 1 ? g.views[0] : g.views[view.ci];
729
737
  part("view-views").replaceChildren(...(views ? [copyOf(views)] : []));
730
738
  // The head as it was before this group was looked at — its ring
731
739
  // bright the first time, through all its clips — and from now on,
@@ -988,7 +996,7 @@ export function initReels(): () => void {
988
996
  }
989
997
  // The dark around it.
990
998
  if (t === dialog || t.hasAttribute("data-pg-reels-stage")) return closeView();
991
- if (t.closest("[data-pg-reels-view-close]")) return closeView();
999
+ if (t.closest("[data-pg-reels-view-close], [data-pg-reels-close]")) return closeView();
992
1000
  if (sliding) return;
993
1001
  if (t.closest('[data-pg-reels-view-on], [data-pg-reels-view-side="next"]')) return nextClip();
994
1002
  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.7.0",
3
+ "version": "1.8.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",