@plusguard/reels 0.0.0-stage → 1.4.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,312 @@
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.4.1/index.css" />
27
+ <script type="module">
28
+ import { initReels } from "https://cdn.jsdelivr.net/npm/@plusguard/reels@1.4.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 is seen once **every one of its clips** has been shown
111
+ in the full view — one clip watched, and it is not; the rest watched
112
+ later in the same visit, and it is: `data-pg-reels-seen="true"` on it
113
+ (`"false"` until then), for the ring round its avatar to go pale —
114
+ stories' rings, in the site's CSS. It stays seen for
115
+ `--pg-reels-seen-for` (`24h` by default; `1h`, `30m`, `7d`, or `forever`)
116
+ and is bright again after; `--pg-reels-seen: off` and the rings never go
117
+ pale. With a `data-pg-reels-id` it is remembered in this browser
118
+ (`localStorage`, `pg-reels-seen`, with the time); without, for this
119
+ visit. In the full view the head's
120
+ copy keeps the ring as it was when the group came in, through all its
121
+ clips. `forgetReelsSeen()` forgets it all — every ring bright again, at
122
+ once, no reload.
123
+
124
+ ```css
125
+ .avatar { position: relative; padding: 4px; border-radius: 50%; }
126
+ .avatar::before {
127
+ content: ""; position: absolute; inset: 0; padding: 2px; border-radius: 50%;
128
+ background: linear-gradient(45deg, #f9c20c, #f95e1a, #f30863, #cc02c1);
129
+ mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
130
+ mask-composite: exclude;
131
+ }
132
+ [data-pg-reels-seen="true"] .avatar::before { background: rgb(255 255 255 / 0.5); }
133
+ ```
134
+
135
+ ## The full view
136
+
137
+ A `<dialog>` the package builds on `<body>` — its own buttons and icons;
138
+ in it, copies of the site's markup: the clip, the group's
139
+ `data-pg-reels-head`, the clip's product and its details.
140
+
141
+ - **Within a group:** the bars on top (none for a single clip), a press on
142
+ the video's right or left third, → and ←. Its clips play on, a video to
143
+ its end, a picture for its time; after the group's last clip, the next
144
+ group — after the last group, the first.
145
+ - **Between groups:** a finger — or the mouse — dragging the video up or
146
+ down, at once or after holding it: it follows, the next group coming in under it (the one before
147
+ above it), and let go it goes on if pulled a fifth of its height or
148
+ flicked, or back if not; past the first or the last it gives a little
149
+ and comes back. The ↑ ↓ buttons beside the video (round, their name
150
+ beside them under the mouse), a wheel or a trackpad, ↑ and ↓ slide it
151
+ the same way. On a computer the next group's top shows under the video
152
+ (`--pg-reels-peek`); pressed, it is the next. The product panel changes
153
+ once the slide has landed. `data-pg-reels-sliding` on the view while
154
+ it moves.
155
+ - **The clip's own links** — a category's tag on the video — are pressed as
156
+ links; the rest of the clip passes presses to the taps under it.
157
+ - **Held down** — a finger, the mouse — it stands still, the controls
158
+ out of the way; let go and it goes on. Its play / pause button, Space.
159
+ - **Its corner:** the close at the top right, the sound and play / pause
160
+ under it; on the close's left the group's view count — the card's
161
+ `data-pg-reels-views` element, copied, so it looks as in the card. The
162
+ number is the site's (from its own counting); the package shows it.
163
+ - **The product:** on a computer, a panel beside the video, from its top
164
+ to the window's foot, 9:16 like it: a head — the template's
165
+ `data-pg-reels-title`, moved there, and the close; a long name takes a
166
+ second line, the close stays at the top — a line under it; at the
167
+ bottom a foot — the template's `data-pg-reels-foot`, the link to the
168
+ product, always in sight; and between them the rest of the template,
169
+ scrolling.
170
+ The template is the product's `data-pg-reels-detail`, the site's markup: a
171
+ `data-pg-reels-thumb` pressed puts its picture (the attribute's value, or
172
+ its own `<img>`) into `data-pg-reels-big`, and is
173
+ `data-pg-reels-current`. On a phone the video fills the screen; the
174
+ product, as on the card, is a band at its foot, and a Details button
175
+ above the band's right opens the template under it. A clip without a
176
+ product: no panel.
177
+ - **Variants** — 1 kg, 500 g; a colour — in the template: buttons with
178
+ `data-pg-reels-variant="1kg"`, each with its `data-pg-reels-variant-price`
179
+ and `-href`. Pressed, it is `data-pg-reels-current` (and `aria-pressed`);
180
+ the `data-pg-reels-gallery="1kg"` of the same name shows — its big
181
+ picture and small ones — the others hide; `data-pg-reels-price` shows
182
+ its price; the foot's link goes to its page. The one marked current in
183
+ the markup, or the first, is chosen when the clip shows.
184
+
185
+ ```html
186
+ <div data-pg-reels-gallery="1kg" data-pg-reels-current>…big, thumbs…</div>
187
+ <div data-pg-reels-gallery="500g">…big, thumbs…</div>
188
+ <p data-pg-reels-price>₺850</p>
189
+ <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>
190
+ <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>
191
+ ```
192
+
193
+ - **A category instead of a product:** the clip's "product" is the
194
+ site's markup, so it can be a category — its picture and name under the
195
+ card, and in the template a few of its products and a foot link to the
196
+ category. Nothing changes in the package.
197
+ - **Closing:** its ✕, Esc, the dark around it, the browser's Back (opened,
198
+ it adds a step to the history). The card it came from shows the clip
199
+ last seen; the strip plays again.
200
+ - **The page under it** does not scroll (`overflow: hidden` on `<html>`
201
+ while it is open); `data-lenis-prevent` on the view for Lenis.
202
+ - **Reduced motion:** it opens still, for its play button.
203
+
204
+ ## CSS
205
+
206
+ | Variable | Default | What |
207
+ | -------- | ------- | ---- |
208
+ | `--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 |
209
+ | `--pg-reels-gap` | `1rem` | Between the cards |
210
+ | `--pg-reels-ratio` | `9 / 16` | The card's shape |
211
+ | `--pg-reels-duration` | `5s` | A picture's time |
212
+ | `--pg-reels-panel` | 9:16 of its height, 20–30rem | The full view: the product panel's width on a computer |
213
+ | `--pg-reels-seen` | `all` | `all`: a group is seen once all its clips have been shown in the full view · `off`: never |
214
+ | `--pg-reels-seen-for` | `24h` | How long a group stays seen — `1h`, `30m`, `7d`, `forever` — then its ring is bright again |
215
+ | `--pg-reels-peek` | `2rem` | The full view: how much of the next group shows under the video on a computer |
216
+ | `--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 |
217
+
218
+ The card holds the shape, the clip fills it — the house way for pictures
219
+ and videos: the box has the shape, what is inside is 100% of it.
220
+
221
+ ## Attributes
222
+
223
+ | Attribute | On | |
224
+ | --------- | -- | --- |
225
+ | `data-pg-reels` | the section | |
226
+ | `data-pg-reels-strip` | the row | Scrolls sideways |
227
+ | `data-pg-reels-group` | each group | A card and what is under it |
228
+ | `data-pg-reels-id` | a group | Its name, for what was seen to be remembered in this browser |
229
+ | `data-pg-reels-views` | in the card | The group's view count, the site's — copied into the full view, left of the close |
230
+ | `data-pg-reels-seen` | a group, the full view's head | Written: `"true"` once seen in the full view, `"false"` before |
231
+ | `data-pg-reels-card` | the card | The shape; its clips fill it |
232
+ | `data-pg-reels-clip` | each clip | A video with its poster, or a picture |
233
+ | `data-pg-reels-duration` | a clip | A picture's time — `5s`, `4000ms` |
234
+ | `data-pg-reels-head` | in the card | Copied to the full view's top |
235
+ | `data-pg-reels-bars` | under the card, empty | Its bars are written here, one a clip |
236
+ | `data-pg-reels-product` | one a clip | The clip's product |
237
+ | `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 |
238
+ | `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 |
239
+ | `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 |
240
+ | `data-pg-reels-variant`, `-variant-price`, `-variant-href` | buttons in the template | A variant: chosen, its gallery, price and link |
241
+ | `data-pg-reels-gallery` | in the template | A variant's pictures: shown while its variant is chosen |
242
+ | `data-pg-reels-price` | in the template | The price, written with the chosen variant's |
243
+ | `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 |
244
+ | `data-pg-reels-sound` | a button | Sound on and off, for the page |
245
+ | `data-pg-reels-open` | a button | The full view |
246
+ | `data-pg-reels-prev`, `-next` | buttons, `aria-controls` | The strip, a card back or on |
247
+ | `data-pg-reels-current` | a clip, a product, a bar, a thumb | Written: the one showing |
248
+ | `data-pg-reels-playing` | a group | Written: the one playing |
249
+ | `data-pg-reels-start`, `-end` | the section | Written: the strip at either end |
250
+ | `data-pg-reels-sound-on` | the section | Written: sound is on |
251
+ | `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 |
252
+
253
+ ## React (Next)
254
+
255
+ ```tsx
256
+ "use client";
257
+
258
+ import { useEffect } from "react";
259
+ import { initReels } from "@plusguard/reels";
260
+
261
+ export function ReelsInit() {
262
+ useEffect(() => initReels(), []);
263
+ return null;
264
+ }
265
+ ```
266
+
267
+ Mount it once, high in the tree; sections and groups rendered later —
268
+ a route change, a list that arrives — are taken up too. React's markup is
269
+ never moved: the package writes its marks as attributes, fills the empty
270
+ `data-pg-reels-bars` that React renders, and builds the full view on
271
+ `<body>` from copies. If `initReels` is called again before the first
272
+ cleanup runs (React remounting in development), only the newest call
273
+ answers.
274
+
275
+ The details: React does not hydrate what is inside a `<template>`, and the
276
+ details' own link cannot sit inside the product's link but in a template.
277
+ So in React they go in the clip, as an element kept hidden:
278
+
279
+ ```tsx
280
+ <figure data-pg-reels-clip>
281
+ <video src={clip.video} poster={clip.poster} muted playsInline preload="none" />
282
+ <figcaption>{clip.caption}</figcaption>
283
+ <div data-pg-reels-detail hidden>
284
+ {/* title, data-pg-reels-big, data-pg-reels-thumb buttons, price, link */}
285
+ </div>
286
+ </figure>
287
+ ```
288
+
289
+ Give its pictures `loading="lazy"`: hidden, they load when the full view
290
+ shows them. See [`examples/react/Example.tsx`](examples/react/Example.tsx)
291
+ — the section from data, and `pg-reels:open` counted.
292
+
293
+ ## Example
294
+
295
+ [`examples/static/index.html`](examples/static/index.html) — six groups of
296
+ one to five clips, videos and a picture (its own time, 4s; `?duration=2s` for
297
+ pictures without one; `?seen=off`, `?seen-for=1h` for the rings), each clip with a product and its
298
+ details: its category (a link), its name in the panel's head, a big
299
+ picture at 4:3, small ones — nine for the first product, a row that
300
+ scrolls — the price, a line about it, a link. Under the card the product
301
+ shows its category and price, its name in two lines' room (longer ends in
302
+ "…"), so every row is as tall; the line over each clip's caption is the
303
+ category too; in
304
+ the full view the category is a tag on the video. The first group is
305
+ three clips from a food shop, the second five from a scarf shop, the
306
+ third four from a pasta and mantı maker, the fourth four from a
307
+ jeweller, the fifth four from a nut and sweet shop — a coffee with four
308
+ weights (variants, each its pictures and price) and three categories,
309
+ each listing a few of its products — the sixth three from a pastırma and
310
+ sucuk shop and a picture — each with its product. The food products'
311
+ further photos are from [Unsplash](https://unsplash.com/license) (free to
312
+ use).
@@ -0,0 +1,2 @@
1
+ export declare function forgetReelsSeen(): void;
2
+ export declare function initReels(): () => void;