@plusguard/reels 1.6.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.6.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.6.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,22 +158,26 @@ 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 close at the top right, the sound and play / pause
162
- under it; on the close's left the group's view count — the card's
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
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.
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.
165
168
  - **The product:** on a computer, a panel beside the video, touching it
166
- as a post opened on Instagram (no corners where they meet), from its top
167
- to the window's foot, 9:16 like it: a head — the template's
168
- `data-pg-reels-title`, moved there, and the close; a long name takes a
169
- second line, the close stays at the top — a line under it; at 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
171
+ window wide: a head — the template's `data-pg-reels-title`, moved there
172
+ (the example puts the category there) — a line under it; at the
170
173
  bottom a foot — the template's `data-pg-reels-foot`, the link to the
171
174
  product, always in sight; and between them the rest of the template,
172
175
  scrolling.
173
176
  The template is the product's `data-pg-reels-detail`, the site's markup: a
174
177
  `data-pg-reels-thumb` pressed puts its picture (the attribute's value, or
175
178
  its own `<img>`) into `data-pg-reels-big`, and is
176
- `data-pg-reels-current`. On a phone the video fills the screen; the
179
+ `data-pg-reels-current`. Below 1024px (Tailwind's `lg`) — a phone, a
180
+ tablet, a narrow window — the video fills the screen; the
177
181
  product, as on the card, is a band at its foot, and a Details button
178
182
  above the band's right opens the template under it. A clip without a
179
183
  product: no panel.
@@ -212,7 +216,7 @@ in it, copies of the site's markup: the clip, the group's
212
216
  | `--pg-reels-gap` | `1rem` | Between the cards |
213
217
  | `--pg-reels-ratio` | `9 / 16` | The card's shape |
214
218
  | `--pg-reels-duration` | `5s` | A picture's time |
215
- | `--pg-reels-panel` | 9:16 of its height, 20–30rem | The full view: the product panel's width on a computer |
219
+ | `--pg-reels-panel` | `30vw`, 21–31rem | The full view: the product panel's width on a computer |
216
220
  | `--pg-reels-seen` | `all` | `all`: a group is seen once all its clips have been shown in the full view · `off`: never |
217
221
  | `--pg-reels-seen-for` | `24h` | How long a group stays seen — `1h`, `30m`, `7d`, `forever` — then its ring is bright again |
218
222
  | `--pg-reels-peek` | `2rem` | The full view: how much of the next group shows under the video on a computer |
@@ -229,7 +233,7 @@ and videos: the box has the shape, what is inside is 100% of it.
229
233
  | `data-pg-reels-strip` | the row | Scrolls sideways |
230
234
  | `data-pg-reels-group` | each group | A card and what is under it |
231
235
  | `data-pg-reels-id` | a group | Its name, for what was seen to be remembered in this browser |
232
- | `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 |
233
237
  | `data-pg-reels-seen` | a group, the full view's head | Written: `"true"` once seen in the full view, `"false"` before |
234
238
  | `data-pg-reels-card` | the card | The shape; its clips fill it |
235
239
  | `data-pg-reels-clip` | each clip | A video with its poster, or a picture |
@@ -238,7 +242,7 @@ and videos: the box has the shape, what is inside is 100% of it.
238
242
  | `data-pg-reels-bars` | under the card, empty | Its bars are written here, one a clip |
239
243
  | `data-pg-reels-product` | one a clip | The clip's product |
240
244
  | `data-pg-reels-detail` | a `<template>` in a product — or any element, hidden, in the product or the clip | Its details, for the full view |
241
- | `data-pg-reels-title` | in the template | The product's name: shown in the panel's head, beside the close — short; the size or weight is better on a line below |
245
+ | `data-pg-reels-title` | in the template | What heads the panel — the category in the example; the product's name under the price |
242
246
  | `data-pg-reels-foot` | in the template | The link to the product: pinned to the panel's foot; on a phone, under the opened details |
243
247
  | `data-pg-reels-variant`, `-variant-price`, `-variant-href` | buttons in the template | A variant: chosen, its gallery, price and link |
244
248
  | `data-pg-reels-gallery` | in the template | A variant's pictures: shown while its variant is chosen |
@@ -291,20 +295,38 @@ So in React they go in the clip, as an element kept hidden:
291
295
 
292
296
  Give its pictures `loading="lazy"`: hidden, they load when the full view
293
297
  shows them. See [`examples/react/Example.tsx`](examples/react/Example.tsx)
294
- — 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
+ ```
295
315
 
296
316
  ## Example
297
317
 
298
318
  [`examples/static/index.html`](examples/static/index.html) — six groups of
299
- three to five clips, videos (`?duration=2s` sets a picture's time; `?seen=off`,
300
- `?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
301
323
  details: its category (a link), its name in the panel's head, a big
302
324
  picture at 4:3, small ones — nine for the first product, a row that
303
325
  scrolls — the price, a line about it, a link. Under the card the product
304
- shows its category and price, its name in two lines' room (longer ends in
305
- "…"), so every row is as tall; the line over each clip's caption is the
306
- category too; in
307
- 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
308
330
  three clips from a food shop, the second five from a scarf shop, the
309
331
  third four from a pasta and mantı maker, the fourth four from a
310
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,10 +56,11 @@
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 own play / pause, its
58
- * sound, its close — under the close; left of it, the group's view count
59
- * (its data-pg-reels-views, the site's). Esc, Back, the dark around it
60
- * close it too. The
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.
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
63
66
  * data-pg-reels-title goes to the panel's head, beside the close), a big
@@ -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,6 +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 = `
605
+ <button type="button" data-pg-reels-close aria-label="Close">${svg(ICONS.close)}</button>
599
606
  <div data-pg-reels-stage>
600
607
  <div data-pg-reels-view-steps>
601
608
  <button type="button" data-pg-reels-view-up aria-label="Previous reel">${svg(ICONS.up)}</button>
@@ -615,10 +622,10 @@ export function initReels() {
615
622
  <div data-pg-reels-view-row>
616
623
  <div data-pg-reels-view-head></div>
617
624
  <div data-pg-reels-view-tools>
618
- <div data-pg-reels-view-views></div>
619
- <button type="button" data-pg-reels-view-close aria-label="Close">${svg(ICONS.close)}</button>
620
625
  <button type="button" ${SOUND} aria-pressed="false" aria-label="Sound">${svg(ICONS.soundOff)}${svg(ICONS.soundOn)}</button>
621
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>
628
+ <div data-pg-reels-view-views></div>
622
629
  </div>
623
630
  </div>
624
631
  </div>
@@ -629,7 +636,6 @@ export function initReels() {
629
636
  <aside data-pg-reels-panel>
630
637
  <div data-pg-reels-panel-head>
631
638
  <div data-pg-reels-panel-title></div>
632
- <button type="button" data-pg-reels-panel-close aria-label="Close">${svg(ICONS.close)}</button>
633
639
  </div>
634
640
  <div data-pg-reels-panel-band>
635
641
  <div data-pg-reels-panel-summary></div>
@@ -701,9 +707,9 @@ export function initReels() {
701
707
  viewVideo()?.pause();
702
708
  const head = g.el.querySelector(`[${HEAD}]`);
703
709
  part("view-head").replaceChildren(...(head ? [copyOf(head)] : []));
704
- // The group's view count — the site's, written in its card — left
705
- // of the close.
706
- 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];
707
713
  part("view-views").replaceChildren(...(views ? [copyOf(views)] : []));
708
714
  // The head as it was before this group was looked at — its ring
709
715
  // bright the first time, through all its clips — and from now on,
@@ -980,7 +986,7 @@ export function initReels() {
980
986
  // The dark around it.
981
987
  if (t === dialog || t.hasAttribute("data-pg-reels-stage"))
982
988
  return closeView();
983
- if (t.closest("[data-pg-reels-view-close], [data-pg-reels-panel-close]"))
989
+ if (t.closest("[data-pg-reels-view-close], [data-pg-reels-close]"))
984
990
  return closeView();
985
991
  if (sliding)
986
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
 
@@ -126,7 +153,8 @@ html:has(dialog[data-pg-reels-viewer][open]) {
126
153
  dialog[data-pg-reels-viewer] {
127
154
  /* The panel 9:16, as the video: its width from its height — but at
128
155
  most half the room beside the arrows, and 20rem to 30rem. */
129
- --pg-reels-panel: clamp(20rem, min(calc((100dvh - 2rem) * 9 / 16), calc((100vw - 14rem) / 2)), 30rem);
156
+ /* The panel as on Instagram: a third of the window, 21rem to 31rem. */
157
+ --pg-reels-panel: clamp(21rem, 30vw, 31rem);
130
158
  --pg-reels-peek: 2rem;
131
159
  position: fixed;
132
160
  inset: 0;
@@ -160,13 +188,15 @@ dialog[data-pg-reels-viewer] svg {
160
188
  it (--pg-reels-peek) — and low enough to leave room for the panel. */
161
189
  [data-pg-reels-stage] {
162
190
  --gap: 1rem;
163
- --h: min(calc(100dvh - 2 * var(--gap) - var(--pg-reels-peek)), 56rem, calc((100vw - var(--pg-reels-panel) - 14rem) * 16 / 9));
191
+ --h: min(calc(100dvh - 2 * var(--gap) - var(--pg-reels-peek)), 56rem, calc((100vw - var(--pg-reels-panel) - 15rem) * 16 / 9));
192
+ position: relative;
164
193
  display: flex;
165
194
  align-items: flex-start;
166
195
  justify-content: center;
167
- gap: 1.5rem;
168
196
  height: 100%;
169
- padding: var(--gap) 1.5rem 0;
197
+ /* Room at the sides: the ↑ ↓ at the window's left, the close at its
198
+ right. */
199
+ padding: var(--gap) 5rem 0;
170
200
  box-sizing: border-box;
171
201
  }
172
202
 
@@ -202,8 +232,10 @@ dialog[data-pg-reels-viewer] [data-pg-reels-view-side] {
202
232
  cursor: pointer;
203
233
  transition: background-color 0.15s;
204
234
  }
205
- dialog[data-pg-reels-viewer] [data-pg-reels-view-side]:hover {
206
- background: #fff;
235
+ @media (hover: hover) {
236
+ dialog[data-pg-reels-viewer] [data-pg-reels-view-side]:hover {
237
+ background: #fff;
238
+ }
207
239
  }
208
240
  [data-pg-reels-view-side="prev"] {
209
241
  right: calc(100% + 0.75rem);
@@ -221,7 +253,7 @@ dialog[data-pg-reels-viewer] [data-pg-reels-view-side] svg {
221
253
  }
222
254
  /* Where they touch, no corners: the video's and the next one's right,
223
255
  the panel's left. */
224
- @media (min-width: 48rem) {
256
+ @media (min-width: 64rem) {
225
257
  [data-pg-reels-pair] [data-pg-reels-screen],
226
258
  [data-pg-reels-pair] [data-pg-reels-view-peek] {
227
259
  border-top-right-radius: 0;
@@ -289,9 +321,7 @@ dialog[data-pg-reels-viewer] [data-pg-reels-view-side] svg {
289
321
  overflow: hidden;
290
322
  background: #000;
291
323
  color: #fff;
292
- opacity: 0.5;
293
324
  cursor: pointer;
294
- transition: opacity 0.2s;
295
325
  }
296
326
  [data-pg-reels-view-peek="before"] {
297
327
  position: absolute;
@@ -299,10 +329,6 @@ dialog[data-pg-reels-viewer] [data-pg-reels-view-side] svg {
299
329
  right: 0;
300
330
  bottom: calc(100% + var(--gap));
301
331
  }
302
- [data-pg-reels-view-peek]:hover,
303
- [data-pg-reels-sliding] [data-pg-reels-view-peek] {
304
- opacity: 1;
305
- }
306
332
  [data-pg-reels-view-peek][hidden] {
307
333
  display: block;
308
334
  visibility: hidden;
@@ -373,30 +399,27 @@ dialog[data-pg-reels-viewer] [data-pg-reels-view-side] svg {
373
399
  [data-pg-reels-view-head] {
374
400
  min-width: 0;
375
401
  }
376
- /* The close at the top right, the sound and play / pause under it, the
377
- group's view count on its left. Only the buttons take a press: the rest
378
- of the corner is the video's. */
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
404
+ is the video's. */
379
405
  [data-pg-reels-view-row] > [data-pg-reels-view-tools] {
380
406
  display: grid;
381
- grid-template-columns: auto auto;
407
+ grid-template-columns: auto auto auto;
382
408
  gap: 0.375rem;
383
409
  pointer-events: none;
384
410
  }
385
411
  [data-pg-reels-view-tools] > button {
386
- grid-column: 2;
387
412
  pointer-events: auto;
388
413
  }
389
414
  [data-pg-reels-view-views] {
390
- grid-column: 1;
391
- grid-row: 1;
392
- align-self: center;
415
+ grid-column: 1 / -1;
416
+ justify-self: end;
393
417
  }
394
418
  [data-pg-reels-view-views]:empty {
395
419
  display: none;
396
420
  }
397
421
  [data-pg-reels-view-tools] > button,
398
- [data-pg-reels-view-steps] > button,
399
- [data-pg-reels-panel-close] {
422
+ [data-pg-reels-view-steps] > button {
400
423
  position: relative;
401
424
  display: grid;
402
425
  place-items: center;
@@ -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,13 +450,44 @@ 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] {
456
+ position: absolute;
457
+ left: 1.25rem;
458
+ top: calc(var(--gap) + var(--h) / 2);
459
+ translate: 0 -50%;
426
460
  display: flex;
427
461
  flex-direction: column;
428
462
  gap: 1rem;
429
- margin-top: calc(var(--h) / 2 - 4rem);
463
+ }
464
+
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] {
467
+ position: absolute;
468
+ z-index: 3;
469
+ top: 0.75rem;
470
+ right: 0.75rem;
471
+ display: grid;
472
+ place-items: center;
473
+ width: 2.75rem;
474
+ height: 2.75rem;
475
+ padding: 0;
476
+ border: 0;
477
+ border-radius: 50%;
478
+ background: none;
479
+ color: #fff;
480
+ cursor: pointer;
481
+ transition: background-color 0.15s;
482
+ }
483
+ @media (hover: hover) {
484
+ dialog[data-pg-reels-viewer] [data-pg-reels-close]:hover {
485
+ background: rgb(255 255 255 / 0.12);
486
+ }
487
+ }
488
+ dialog[data-pg-reels-viewer] [data-pg-reels-close] svg {
489
+ width: 1.75rem;
490
+ height: 1.75rem;
430
491
  }
431
492
  dialog[data-pg-reels-viewer] [data-pg-reels-view-steps] > button {
432
493
  width: 3.5rem;
@@ -438,8 +499,10 @@ dialog[data-pg-reels-viewer] [data-pg-reels-view-steps] svg {
438
499
  width: 1.5rem;
439
500
  height: 1.5rem;
440
501
  }
441
- [data-pg-reels-view-steps] > button:not(:disabled):hover {
442
- 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
+ }
443
506
  }
444
507
  [data-pg-reels-view-steps] > button:disabled {
445
508
  opacity: 0.3;
@@ -448,7 +511,7 @@ dialog[data-pg-reels-viewer] [data-pg-reels-view-steps] svg {
448
511
  [data-pg-reels-view-steps] > button::after {
449
512
  content: attr(aria-label);
450
513
  position: absolute;
451
- right: calc(100% + 0.75rem);
514
+ left: calc(100% + 0.75rem);
452
515
  top: 50%;
453
516
  translate: 0 -50%;
454
517
  padding: 0.5rem 0.625rem;
@@ -462,12 +525,14 @@ dialog[data-pg-reels-viewer] [data-pg-reels-view-steps] svg {
462
525
  pointer-events: none;
463
526
  transition: opacity 0.1s;
464
527
  }
465
- [data-pg-reels-view-steps] > button:not(:disabled):hover::after {
466
- opacity: 1;
467
- 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
+ }
468
533
  }
469
534
 
470
- /* 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
471
536
  name (the template's data-pg-reels-title) and the close, a line under
472
537
  it, the rest of the template under that, scrolling. A long name goes
473
538
  onto a second line; the close stays at the top. */
@@ -479,7 +544,7 @@ dialog[data-pg-reels-viewer] [data-pg-reels-view-steps] svg {
479
544
  flex: none;
480
545
  box-sizing: border-box;
481
546
  width: var(--pg-reels-panel);
482
- height: calc(100dvh - 2 * var(--gap));
547
+ height: var(--h);
483
548
  border-radius: 0.75rem;
484
549
  background: #fff;
485
550
  color: #111;
@@ -493,25 +558,14 @@ dialog[data-pg-reels-viewer] [data-pg-reels-view-steps] svg {
493
558
  align-items: flex-start;
494
559
  gap: 0.75rem;
495
560
  flex: none;
496
- padding: 0.875rem 0.875rem 0.875rem 1.25rem;
561
+ padding: 1rem 1.25rem;
497
562
  border-bottom: 1px solid color-mix(in srgb, currentColor 14%, transparent);
498
563
  }
499
564
  [data-pg-reels-panel-title] {
500
565
  flex: 1 1 auto;
501
566
  min-width: 0;
502
567
  align-self: center;
503
- }
504
- dialog[data-pg-reels-viewer] [data-pg-reels-panel-close] {
505
- flex: none;
506
- background: color-mix(in srgb, currentColor 10%, transparent);
507
- transition: background-color 0.15s;
508
- }
509
- dialog[data-pg-reels-viewer] [data-pg-reels-panel-close]:hover {
510
- background: color-mix(in srgb, currentColor 18%, transparent);
511
- }
512
- dialog[data-pg-reels-viewer] [data-pg-reels-panel-close] svg {
513
- width: 1.5rem;
514
- height: 1.5rem;
568
+ min-height: 1.5rem;
515
569
  }
516
570
  [data-pg-reels-panel-detail] {
517
571
  flex: 1 1 auto;
@@ -539,14 +593,19 @@ dialog[data-pg-reels-viewer] [data-pg-reels-panel-close] svg {
539
593
  display: none;
540
594
  }
541
595
 
542
- /* ---------- On a phone: the video fills the screen ----------
543
- The groups above and under it wait out of sight, full size, for the
544
- finger; the product is a band at the foot. */
545
- @media (max-width: 47.99rem) {
596
+ /* ---------- Below 1024px (Tailwind's lg): the video fills the screen ----------
597
+ A phone, a tablet, a narrow window. The groups above and under it wait
598
+ out of sight, full size, for the finger; the product is a band at the
599
+ foot, its content centred and no wider than 40rem. */
600
+ @media (max-width: 63.99rem) {
546
601
  [data-pg-reels-stage] {
547
602
  display: block;
548
603
  padding: 0;
549
604
  }
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;
608
+ }
550
609
  [data-pg-reels-pair] {
551
610
  display: contents;
552
611
  }
@@ -576,7 +635,6 @@ dialog[data-pg-reels-viewer] [data-pg-reels-panel-close] svg {
576
635
  height: 100%;
577
636
  aspect-ratio: auto;
578
637
  border-radius: 0;
579
- opacity: 1;
580
638
  }
581
639
  [data-pg-reels-view-peek="before"] {
582
640
  bottom: 100%;
@@ -607,6 +665,10 @@ dialog[data-pg-reels-viewer] [data-pg-reels-panel-close] svg {
607
665
  [data-pg-reels-no-product] [data-pg-reels-panel] {
608
666
  display: none;
609
667
  }
668
+ [data-pg-reels-panel] > * {
669
+ max-width: 40rem;
670
+ margin-inline: auto;
671
+ }
610
672
  [data-pg-reels-panel-band] {
611
673
  display: block;
612
674
  position: relative;
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,10 +56,11 @@
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 own play / pause, its
58
- * sound, its close — under the close; left of it, the group's view count
59
- * (its data-pg-reels-views, the site's). Esc, Back, the dark around it
60
- * close it too. The
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.
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
63
66
  * data-pg-reels-title goes to the panel's head, beside the close), a big
@@ -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,6 +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 = `
624
+ <button type="button" data-pg-reels-close aria-label="Close">${svg(ICONS.close)}</button>
617
625
  <div data-pg-reels-stage>
618
626
  <div data-pg-reels-view-steps>
619
627
  <button type="button" data-pg-reels-view-up aria-label="Previous reel">${svg(ICONS.up)}</button>
@@ -633,10 +641,10 @@ export function initReels(): () => void {
633
641
  <div data-pg-reels-view-row>
634
642
  <div data-pg-reels-view-head></div>
635
643
  <div data-pg-reels-view-tools>
636
- <div data-pg-reels-view-views></div>
637
- <button type="button" data-pg-reels-view-close aria-label="Close">${svg(ICONS.close)}</button>
638
644
  <button type="button" ${SOUND} aria-pressed="false" aria-label="Sound">${svg(ICONS.soundOff)}${svg(ICONS.soundOn)}</button>
639
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>
647
+ <div data-pg-reels-view-views></div>
640
648
  </div>
641
649
  </div>
642
650
  </div>
@@ -647,7 +655,6 @@ export function initReels(): () => void {
647
655
  <aside data-pg-reels-panel>
648
656
  <div data-pg-reels-panel-head>
649
657
  <div data-pg-reels-panel-title></div>
650
- <button type="button" data-pg-reels-panel-close aria-label="Close">${svg(ICONS.close)}</button>
651
658
  </div>
652
659
  <div data-pg-reels-panel-band>
653
660
  <div data-pg-reels-panel-summary></div>
@@ -724,9 +731,9 @@ export function initReels(): () => void {
724
731
 
725
732
  const head = g.el.querySelector(`[${HEAD}]`);
726
733
  part("view-head").replaceChildren(...(head ? [copyOf(head)] : []));
727
- // The group's view count — the site's, written in its card — left
728
- // of the close.
729
- 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];
730
737
  part("view-views").replaceChildren(...(views ? [copyOf(views)] : []));
731
738
  // The head as it was before this group was looked at — its ring
732
739
  // bright the first time, through all its clips — and from now on,
@@ -989,7 +996,7 @@ export function initReels(): () => void {
989
996
  }
990
997
  // The dark around it.
991
998
  if (t === dialog || t.hasAttribute("data-pg-reels-stage")) return closeView();
992
- if (t.closest("[data-pg-reels-view-close], [data-pg-reels-panel-close]")) return closeView();
999
+ if (t.closest("[data-pg-reels-view-close], [data-pg-reels-close]")) return closeView();
993
1000
  if (sliding) return;
994
1001
  if (t.closest('[data-pg-reels-view-on], [data-pg-reels-view-side="next"]')) return nextClip();
995
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.6.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",