@plusguard/reels 0.0.0-stage → 1.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 PlusGuard
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,304 @@
1
- # Temporary Holding Version
1
+ # reels
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Shoppable reels for a store: a strip of video cards on the page — each card
4
+ a group of clips, each clip with its own product — that opens into a full
5
+ view. No dependencies.
6
+
7
+ ```sh
8
+ npm install @plusguard/reels
9
+ ```
10
+
11
+ ```ts
12
+ import { initReels, forgetReelsSeen } from "@plusguard/reels";
13
+ import "@plusguard/reels/index.css";
14
+
15
+ initReels(); // every reels section on the page, those rendered later too
16
+ // forgetReelsSeen(); — every ring bright again
17
+ ```
18
+
19
+ ### Without a build step
20
+
21
+ From npm, through jsDelivr — the npm package is the code alone (about
22
+ 36 KB); the examples' videos stay in the GitHub repo, which is too big for
23
+ jsDelivr's GitHub route.
24
+
25
+ ```html
26
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@plusguard/reels@1.3.1/index.css" />
27
+ <script type="module">
28
+ import { initReels } from "https://cdn.jsdelivr.net/npm/@plusguard/reels@1.3.1/dist/index.js";
29
+ initReels();
30
+ </script>
31
+ ```
32
+
33
+ ## The markup
34
+
35
+ ```html
36
+ <section data-pg-reels>
37
+ <button data-pg-reels-prev aria-controls="strip" aria-label="Previous">‹</button>
38
+ <div data-pg-reels-strip id="strip">
39
+ <article data-pg-reels-group data-pg-reels-id="enginar">
40
+ <div data-pg-reels-card>
41
+ <figure data-pg-reels-clip>
42
+ <video src="a.mp4" poster="a.jpg" muted playsinline preload="none"></video>
43
+ <figcaption><small>Kitchen</small>Blown by hand</figcaption>
44
+ </figure>
45
+ <figure data-pg-reels-clip data-pg-reels-duration="5s">
46
+ <img src="b.jpg" alt="" />
47
+ <figcaption>Morning in the studio</figcaption>
48
+ </figure>
49
+ <header data-pg-reels-head><!-- avatar, name, a Follow link --></header>
50
+ <button data-pg-reels-sound aria-pressed="false" aria-label="Sound">…</button>
51
+ <button data-pg-reels-open aria-label="Enlarge">…</button>
52
+ </div>
53
+ <div data-pg-reels-bars></div>
54
+ <div data-pg-reels-products>
55
+ <a data-pg-reels-product href="/carafe">
56
+ <!-- picture, name, price, an arrow -->
57
+ <template data-pg-reels-detail>
58
+ <h2 data-pg-reels-title>Glass pour-over carafe</h2>
59
+ <div class="pg-imageGroup" data-pg-reels-big><img src="carafe-1.jpg" alt="" /></div>
60
+ <button type="button" class="pg-imageGroup" data-pg-reels-thumb="carafe-1.jpg"><img src="carafe-1.jpg" alt="" /></button>
61
+ <button type="button" class="pg-imageGroup" data-pg-reels-thumb="carafe-2.jpg"><img src="carafe-2.jpg" alt="" /></button>
62
+ <p>$34</p>
63
+ <a href="/carafe" data-pg-reels-foot>Go to product</a>
64
+ </template>
65
+ </a>
66
+ <a data-pg-reels-product href="/throw">…</a>
67
+ </div>
68
+ </article>
69
+ <!-- more groups -->
70
+ </div>
71
+ <button data-pg-reels-next aria-controls="strip" aria-label="Next">›</button>
72
+ </section>
73
+ ```
74
+
75
+ A group is a card and what is under it: its clips, one bar a clip, one
76
+ product a clip, in the same order. A clip is a video — with its `poster` —
77
+ or a picture shown for a while. The header, the buttons, the caption and
78
+ the product's look are yours; the package only marks and moves. The
79
+ `<template data-pg-reels-detail>` in a product is its details for the full
80
+ view — not shown on the page. It may be any element instead, in the
81
+ product or in the clip — `<div data-pg-reels-detail hidden>`; `index.css`
82
+ keeps it hidden and the full view copies what is inside. React's way (see
83
+ below).
84
+
85
+ ## What it does
86
+
87
+ - **Every card in sight plays** — at least 60% of it on the screen —
88
+ muted. Its clips play one after another, round and round, as stories
89
+ do: a video to its end, a picture for its time —
90
+ `data-pg-reels-duration="4s"` on the clip, or `--pg-reels-duration` on
91
+ the group or above (5s by default). The bars under the card fill as each
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
94
+ stops them all.
95
+ - **The product is the clip's.** The products under a card are one a clip;
96
+ the playing one's shows (`data-pg-reels-current`).
97
+ - **Sound is one card's.** A sound button pressed gives the sound to its
98
+ card — every other card is muted; pressed again, off. The card going out
99
+ of sight takes the sound with it. The full view takes
100
+ it over while open, and gives it back on closing if the card last seen
101
+ there is the one that plays.
102
+ - **The strip scrolls sideways** — a finger, a wheel, its arrows, one card
103
+ a press. It never moves by itself. `data-pg-reels-start` / `-end` on the
104
+ section while it stands at either end, for the arrows.
105
+ - **A card pressed** — anywhere but its own links and buttons — or its
106
+ `data-pg-reels-open`: the full view, on that group and clip. First the
107
+ event `pg-reels:open` on the section, with `detail.group` and
108
+ `detail.clip`; `preventDefault()` on it and the site opens its own.
109
+ - **Reduced motion:** nothing plays by itself; a bar pressed shows its clip.
110
+ - **Seen.** A group shown in the full view is seen:
111
+ `data-pg-reels-seen="true"` on it (`"false"` until then), for the ring
112
+ round its avatar to go pale — stories' rings, in the site's CSS. With a
113
+ `data-pg-reels-id` it is remembered in this browser (`localStorage`,
114
+ `pg-reels-seen`); without, for this visit. In the full view the head's
115
+ copy keeps the ring as it was when the group came in, through all its
116
+ clips. `forgetReelsSeen()` forgets it all — every ring bright again, at
117
+ once, no reload.
118
+
119
+ ```css
120
+ .avatar { position: relative; padding: 4px; border-radius: 50%; }
121
+ .avatar::before {
122
+ content: ""; position: absolute; inset: 0; padding: 2px; border-radius: 50%;
123
+ background: linear-gradient(45deg, #f9c20c, #f95e1a, #f30863, #cc02c1);
124
+ mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
125
+ mask-composite: exclude;
126
+ }
127
+ [data-pg-reels-seen="true"] .avatar::before { background: rgb(255 255 255 / 0.5); }
128
+ ```
129
+
130
+ ## The full view
131
+
132
+ A `<dialog>` the package builds on `<body>` — its own buttons and icons;
133
+ in it, copies of the site's markup: the clip, the group's
134
+ `data-pg-reels-head`, the clip's product and its details.
135
+
136
+ - **Within a group:** the bars on top (none for a single clip), a press on
137
+ the video's right or left third, → and ←. Its clips play on, a video to
138
+ its end, a picture for its time; after the group's last clip, the next
139
+ group — after the last group, the first.
140
+ - **Between groups:** a finger — or the mouse — dragging the video up or
141
+ down, at once or after holding it: it follows, the next group coming in under it (the one before
142
+ above it), and let go it goes on if pulled a fifth of its height or
143
+ flicked, or back if not; past the first or the last it gives a little
144
+ and comes back. The ↑ ↓ buttons beside the video (round, their name
145
+ beside them under the mouse), a wheel or a trackpad, ↑ and ↓ slide it
146
+ the same way. On a computer the next group's top shows under the video
147
+ (`--pg-reels-peek`); pressed, it is the next. The product panel changes
148
+ once the slide has landed. `data-pg-reels-sliding` on the view while
149
+ it moves.
150
+ - **The clip's own links** — a category's tag on the video — are pressed as
151
+ links; the rest of the clip passes presses to the taps under it.
152
+ - **Held down** — a finger, the mouse — it stands still, the controls
153
+ out of the way; let go and it goes on. Its play / pause button, Space.
154
+ - **Its corner:** the close at the top right, the sound and play / pause
155
+ under it; on the close's left the group's view count — the card's
156
+ `data-pg-reels-views` element, copied, so it looks as in the card. The
157
+ number is the site's (from its own counting); the package shows it.
158
+ - **The product:** on a computer, a panel beside the video, from its top
159
+ to the window's foot, 9:16 like it: a head — the template's
160
+ `data-pg-reels-title`, moved there, and the close; a long name takes a
161
+ second line, the close stays at the top — a line under it; at the
162
+ bottom a foot — the template's `data-pg-reels-foot`, the link to the
163
+ product, always in sight; and between them the rest of the template,
164
+ scrolling.
165
+ The template is the product's `data-pg-reels-detail`, the site's markup: a
166
+ `data-pg-reels-thumb` pressed puts its picture (the attribute's value, or
167
+ its own `<img>`) into `data-pg-reels-big`, and is
168
+ `data-pg-reels-current`. On a phone the video fills the screen; the
169
+ product, as on the card, is a band at its foot, and a Details button
170
+ above the band's right opens the template under it. A clip without a
171
+ product: no panel.
172
+ - **Variants** — 1 kg, 500 g; a colour — in the template: buttons with
173
+ `data-pg-reels-variant="1kg"`, each with its `data-pg-reels-variant-price`
174
+ and `-href`. Pressed, it is `data-pg-reels-current` (and `aria-pressed`);
175
+ the `data-pg-reels-gallery="1kg"` of the same name shows — its big
176
+ picture and small ones — the others hide; `data-pg-reels-price` shows
177
+ its price; the foot's link goes to its page. The one marked current in
178
+ the markup, or the first, is chosen when the clip shows.
179
+
180
+ ```html
181
+ <div data-pg-reels-gallery="1kg" data-pg-reels-current>…big, thumbs…</div>
182
+ <div data-pg-reels-gallery="500g">…big, thumbs…</div>
183
+ <p data-pg-reels-price>₺850</p>
184
+ <button type="button" data-pg-reels-variant="1kg" data-pg-reels-variant-price="₺850" data-pg-reels-variant-href="/kahve?g=1kg" data-pg-reels-current>1 Kg</button>
185
+ <button type="button" data-pg-reels-variant="500g" data-pg-reels-variant-price="₺450" data-pg-reels-variant-href="/kahve?g=500g">500 Gr</button>
186
+ ```
187
+
188
+ - **A category instead of a product:** the clip's "product" is the
189
+ site's markup, so it can be a category — its picture and name under the
190
+ card, and in the template a few of its products and a foot link to the
191
+ category. Nothing changes in the package.
192
+ - **Closing:** its ✕, Esc, the dark around it, the browser's Back (opened,
193
+ it adds a step to the history). The card it came from shows the clip
194
+ last seen; the strip plays again.
195
+ - **The page under it** does not scroll (`overflow: hidden` on `<html>`
196
+ while it is open); `data-lenis-prevent` on the view for Lenis.
197
+ - **Reduced motion:** it opens still, for its play button.
198
+
199
+ ## CSS
200
+
201
+ | Variable | Default | What |
202
+ | -------- | ------- | ---- |
203
+ | `--pg-reels-show` | `4` | Cards across the strip; a fraction shows part of the next — `1.5` on a phone: one card and half the next |
204
+ | `--pg-reels-gap` | `1rem` | Between the cards |
205
+ | `--pg-reels-ratio` | `9 / 16` | The card's shape |
206
+ | `--pg-reels-duration` | `5s` | A picture's time |
207
+ | `--pg-reels-panel` | 9:16 of its height, 20–30rem | The full view: the product panel's width on a computer |
208
+ | `--pg-reels-peek` | `2rem` | The full view: how much of the next group shows under the video on a computer |
209
+ | `--pg-reels-band` | — | Written by the script on the view: the band's height at a phone's foot (0 on a computer) — to keep a caption above it |
210
+
211
+ The card holds the shape, the clip fills it — the house way for pictures
212
+ and videos: the box has the shape, what is inside is 100% of it.
213
+
214
+ ## Attributes
215
+
216
+ | Attribute | On | |
217
+ | --------- | -- | --- |
218
+ | `data-pg-reels` | the section | |
219
+ | `data-pg-reels-strip` | the row | Scrolls sideways |
220
+ | `data-pg-reels-group` | each group | A card and what is under it |
221
+ | `data-pg-reels-id` | a group | Its name, for what was seen to be remembered in this browser |
222
+ | `data-pg-reels-views` | in the card | The group's view count, the site's — copied into the full view, left of the close |
223
+ | `data-pg-reels-seen` | a group, the full view's head | Written: `"true"` once seen in the full view, `"false"` before |
224
+ | `data-pg-reels-card` | the card | The shape; its clips fill it |
225
+ | `data-pg-reels-clip` | each clip | A video with its poster, or a picture |
226
+ | `data-pg-reels-duration` | a clip | A picture's time — `5s`, `4000ms` |
227
+ | `data-pg-reels-head` | in the card | Copied to the full view's top |
228
+ | `data-pg-reels-bars` | under the card, empty | Its bars are written here, one a clip |
229
+ | `data-pg-reels-product` | one a clip | The clip's product |
230
+ | `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 |
231
+ | `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 |
232
+ | `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 |
233
+ | `data-pg-reels-variant`, `-variant-price`, `-variant-href` | buttons in the template | A variant: chosen, its gallery, price and link |
234
+ | `data-pg-reels-gallery` | in the template | A variant's pictures: shown while its variant is chosen |
235
+ | `data-pg-reels-price` | in the template | The price, written with the chosen variant's |
236
+ | `data-pg-reels-big`, `-thumb` | in the template | The big picture; the small ones that switch it — pressed, a small one is scrolled into sight |
237
+ | `data-pg-reels-sound` | a button | Sound on and off, for the page |
238
+ | `data-pg-reels-open` | a button | The full view |
239
+ | `data-pg-reels-prev`, `-next` | buttons, `aria-controls` | The strip, a card back or on |
240
+ | `data-pg-reels-current` | a clip, a product, a bar, a thumb | Written: the one showing |
241
+ | `data-pg-reels-playing` | a group | Written: the one playing |
242
+ | `data-pg-reels-start`, `-end` | the section | Written: the strip at either end |
243
+ | `data-pg-reels-sound-on` | the section | Written: sound is on |
244
+ | `data-pg-reels-viewer` | the `<dialog>` | The full view, built by the script; `-paused`, `-held`, `-sliding`, `-details` (phone: details open) and `-no-product` on it |
245
+
246
+ ## React (Next)
247
+
248
+ ```tsx
249
+ "use client";
250
+
251
+ import { useEffect } from "react";
252
+ import { initReels } from "@plusguard/reels";
253
+
254
+ export function ReelsInit() {
255
+ useEffect(() => initReels(), []);
256
+ return null;
257
+ }
258
+ ```
259
+
260
+ Mount it once, high in the tree; sections and groups rendered later —
261
+ a route change, a list that arrives — are taken up too. React's markup is
262
+ never moved: the package writes its marks as attributes, fills the empty
263
+ `data-pg-reels-bars` that React renders, and builds the full view on
264
+ `<body>` from copies. If `initReels` is called again before the first
265
+ cleanup runs (React remounting in development), only the newest call
266
+ answers.
267
+
268
+ The details: React does not hydrate what is inside a `<template>`, and the
269
+ details' own link cannot sit inside the product's link but in a template.
270
+ So in React they go in the clip, as an element kept hidden:
271
+
272
+ ```tsx
273
+ <figure data-pg-reels-clip>
274
+ <video src={clip.video} poster={clip.poster} muted playsInline preload="none" />
275
+ <figcaption>{clip.caption}</figcaption>
276
+ <div data-pg-reels-detail hidden>
277
+ {/* title, data-pg-reels-big, data-pg-reels-thumb buttons, price, link */}
278
+ </div>
279
+ </figure>
280
+ ```
281
+
282
+ Give its pictures `loading="lazy"`: hidden, they load when the full view
283
+ shows them. See [`examples/react/Example.tsx`](examples/react/Example.tsx)
284
+ — the section from data, and `pg-reels:open` counted.
285
+
286
+ ## Example
287
+
288
+ [`examples/static/index.html`](examples/static/index.html) — six groups of
289
+ one to five clips, videos and pictures (two with their own time — the
290
+ jellyfish 8s, the mist 3s; `?duration=2s` for the rest), each clip with a product and its
291
+ details: its category (a link), its name in the panel's head, a big
292
+ picture at 4:3, small ones — nine for the first product, a row that
293
+ scrolls — the price, a line about it, a link. Under the card the product
294
+ shows its category and price, its name in two lines' room (longer ends in
295
+ "…"), so every row is as tall; the line over each clip's caption is the
296
+ category too; in
297
+ the full view the category is a tag on the video. The first group is
298
+ three clips from a food shop, the second five from a scarf shop, the
299
+ third four from a pasta and mantı maker, the fourth four from a
300
+ jeweller, the fifth four from a nut and sweet shop — a coffee with four
301
+ weights (variants, each its pictures and price) and three categories,
302
+ each listing a few of its products — each with its product; the food products' further photos are from
303
+ [Unsplash](https://unsplash.com/license) (free to use). The other pictures
304
+ and the bubbles video are from stories' example.
@@ -0,0 +1,2 @@
1
+ export declare function forgetReelsSeen(): void;
2
+ export declare function initReels(): () => void;