@plusguard/reels 1.9.1 → 1.9.2
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 +21 -4
- package/early.js +69 -0
- package/package.json +31 -7
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.9.
|
|
26
|
+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@plusguard/reels@1.9.2/index.css" />
|
|
27
27
|
<script type="module">
|
|
28
|
-
import { initReels } from "https://cdn.jsdelivr.net/npm/@plusguard/reels@1.9.
|
|
28
|
+
import { initReels } from "https://cdn.jsdelivr.net/npm/@plusguard/reels@1.9.2/dist/index.js";
|
|
29
29
|
initReels();
|
|
30
30
|
</script>
|
|
31
31
|
```
|
|
@@ -132,6 +132,22 @@ below).
|
|
|
132
132
|
[data-pg-reels-seen="true"] .avatar::before { background: rgb(255 255 255 / 0.5); }
|
|
133
133
|
```
|
|
134
134
|
|
|
135
|
+
**From the first paint.** `initReels()` marks what was seen once the module
|
|
136
|
+
has loaded — a moment after the page is drawn, so a ring seen before
|
|
137
|
+
would show bright for that moment, then go pale. `early.js`, a small
|
|
138
|
+
classic script in `<head>` after the stylesheets, marks each group as the
|
|
139
|
+
browser reads it, before anything is drawn:
|
|
140
|
+
|
|
141
|
+
```html
|
|
142
|
+
<script src="https://cdn.jsdelivr.net/npm/@plusguard/reels@1.9.2/early.js"></script>
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
No dependencies, nothing to call; `initReels()` takes over after. It reads
|
|
146
|
+
`--pg-reels-seen` and `--pg-reels-seen-for` from the stylesheets; set by a
|
|
147
|
+
script later, they are `initReels()`'s alone. In React no script is
|
|
148
|
+
needed: start the package in a layout effect (below), which runs before
|
|
149
|
+
the page is drawn.
|
|
150
|
+
|
|
135
151
|
## The full view
|
|
136
152
|
|
|
137
153
|
A `<dialog>` the package builds on `<body>` — its own buttons and icons;
|
|
@@ -262,11 +278,12 @@ and videos: the box has the shape, what is inside is 100% of it.
|
|
|
262
278
|
```tsx
|
|
263
279
|
"use client";
|
|
264
280
|
|
|
265
|
-
import {
|
|
281
|
+
import { useLayoutEffect } from "react";
|
|
266
282
|
import { initReels } from "@plusguard/reels";
|
|
267
283
|
|
|
268
284
|
export function ReelsInit() {
|
|
269
|
-
|
|
285
|
+
// Before the page is drawn: a ring seen before is pale from the start.
|
|
286
|
+
useLayoutEffect(() => initReels(), []);
|
|
270
287
|
return null;
|
|
271
288
|
}
|
|
272
289
|
```
|
package/early.js
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* reels — early.js: before the page is first drawn, the seen marks.
|
|
3
|
+
*
|
|
4
|
+
* initReels() marks data-pg-reels-seen="true" once the module has loaded —
|
|
5
|
+
* a moment after the page is drawn, so a group seen before shows its ring
|
|
6
|
+
* bright first, then pale. This little script marks each group as the
|
|
7
|
+
* browser reads it, before anything is drawn; initReels() takes over after.
|
|
8
|
+
*
|
|
9
|
+
* A classic script, in <head>, after the page's stylesheets and before its
|
|
10
|
+
* markup — not deferred, not a module:
|
|
11
|
+
*
|
|
12
|
+
* <script src="https://cdn.jsdelivr.net/npm/@plusguard/reels@1.9.2/early.js"></script>
|
|
13
|
+
*
|
|
14
|
+
* or its text written inline there. No dependencies; nothing to call. It
|
|
15
|
+
* reads --pg-reels-seen and --pg-reels-seen-for from the stylesheets, as
|
|
16
|
+
* initReels() does; set from a script later, they are initReels()'s alone.
|
|
17
|
+
*/
|
|
18
|
+
(function () {
|
|
19
|
+
var seen;
|
|
20
|
+
try {
|
|
21
|
+
seen = JSON.parse(localStorage.getItem("pg-reels-seen") || "{}");
|
|
22
|
+
} catch (e) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
if (!seen || typeof seen !== "object" || Array.isArray(seen)) return;
|
|
26
|
+
var any = false;
|
|
27
|
+
for (var key in seen) any = true;
|
|
28
|
+
if (!any) return;
|
|
29
|
+
|
|
30
|
+
// "24h", "30m", "90s", "500ms", "7d" → ms; "forever" → Infinity.
|
|
31
|
+
var DAY = 24 * 60 * 60 * 1000;
|
|
32
|
+
var spanOf = function (raw) {
|
|
33
|
+
var text = String(raw || "").trim().toLowerCase();
|
|
34
|
+
if (!text) return DAY;
|
|
35
|
+
if (text === "forever" || text === "none") return Infinity;
|
|
36
|
+
var m = /^(-?[\d.]+)\s*(ms|s|m|h|d)?$/.exec(text);
|
|
37
|
+
if (!m) return DAY;
|
|
38
|
+
var unit = { ms: 1, s: 1000, m: 60000, h: 3600000, d: 86400000 }[m[2] || "ms"];
|
|
39
|
+
var n = Number(m[1]) * unit;
|
|
40
|
+
return isFinite(n) ? Math.max(0, n) : DAY;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
var mark = function (el) {
|
|
44
|
+
var when = seen[el.getAttribute("data-pg-reels-id")];
|
|
45
|
+
if (typeof when !== "number") return;
|
|
46
|
+
var cs = getComputedStyle(el);
|
|
47
|
+
if (cs.getPropertyValue("--pg-reels-seen").trim() === "off") return;
|
|
48
|
+
if (Date.now() - when < spanOf(cs.getPropertyValue("--pg-reels-seen-for"))) el.setAttribute("data-pg-reels-seen", "true");
|
|
49
|
+
};
|
|
50
|
+
// Each group the browser adds while reading the page — or groups inside
|
|
51
|
+
// what it adds. The callback runs before the page is drawn.
|
|
52
|
+
var observer = new MutationObserver(function (records) {
|
|
53
|
+
for (var r = 0; r < records.length; r++) {
|
|
54
|
+
var added = records[r].addedNodes;
|
|
55
|
+
for (var n = 0; n < added.length; n++) {
|
|
56
|
+
var node = added[n];
|
|
57
|
+
if (node.nodeType !== 1) continue;
|
|
58
|
+
if (node.hasAttribute("data-pg-reels-group") && node.hasAttribute("data-pg-reels-id")) mark(node);
|
|
59
|
+
var inner = node.querySelectorAll("[data-pg-reels-group][data-pg-reels-id]");
|
|
60
|
+
for (var k = 0; k < inner.length; k++) mark(inner[k]);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
observer.observe(document.documentElement, { childList: true, subtree: true });
|
|
65
|
+
// The page is read: initReels() keeps the marks from here on.
|
|
66
|
+
document.addEventListener("DOMContentLoaded", function () {
|
|
67
|
+
observer.disconnect();
|
|
68
|
+
});
|
|
69
|
+
})();
|
package/package.json
CHANGED
|
@@ -1,22 +1,46 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plusguard/reels",
|
|
3
|
-
"version": "1.9.
|
|
3
|
+
"version": "1.9.2",
|
|
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",
|
|
7
7
|
"types": "./dist/index.d.ts",
|
|
8
8
|
"exports": {
|
|
9
|
-
".": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js"
|
|
12
|
+
},
|
|
10
13
|
"./index.css": "./index.css"
|
|
11
14
|
},
|
|
12
|
-
"files": [
|
|
13
|
-
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"index.ts",
|
|
18
|
+
"index.css",
|
|
19
|
+
"early.js",
|
|
20
|
+
"README.md",
|
|
21
|
+
"LICENSE"
|
|
22
|
+
],
|
|
23
|
+
"sideEffects": [
|
|
24
|
+
"*.css"
|
|
25
|
+
],
|
|
14
26
|
"scripts": {
|
|
15
27
|
"build": "npx -p typescript tsc index.ts --outDir dist --declaration --target es2020 --module es2020 --lib dom,dom.iterable,es2020 --strict"
|
|
16
28
|
},
|
|
17
|
-
"publishConfig": {
|
|
29
|
+
"publishConfig": {
|
|
30
|
+
"access": "public"
|
|
31
|
+
},
|
|
18
32
|
"license": "MIT",
|
|
19
33
|
"author": "PlusGuard",
|
|
20
|
-
"repository": {
|
|
21
|
-
|
|
34
|
+
"repository": {
|
|
35
|
+
"type": "git",
|
|
36
|
+
"url": "git+https://github.com/omisilli/reels.git"
|
|
37
|
+
},
|
|
38
|
+
"keywords": [
|
|
39
|
+
"reels",
|
|
40
|
+
"shoppable-video",
|
|
41
|
+
"video-commerce",
|
|
42
|
+
"stories",
|
|
43
|
+
"ecommerce",
|
|
44
|
+
"vanilla"
|
|
45
|
+
]
|
|
22
46
|
}
|