@plusguard/reels 1.9.0 → 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.
Files changed (4) hide show
  1. package/README.md +21 -4
  2. package/early.js +69 -0
  3. package/index.css +14 -4
  4. 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.0/index.css" />
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.0/dist/index.js";
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 { useEffect } from "react";
281
+ import { useLayoutEffect } from "react";
266
282
  import { initReels } from "@plusguard/reels";
267
283
 
268
284
  export function ReelsInit() {
269
- useEffect(() => initReels(), []);
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/index.css CHANGED
@@ -65,7 +65,11 @@
65
65
  inset: 0;
66
66
  margin: 0;
67
67
  }
68
- [data-pg-reels-card] [data-pg-reels-clip]:not([data-pg-reels-current]) {
68
+ /* The playing clip shows. Before the script has chosen one — the first
69
+ paint, the page still loading — the first does: the card is never
70
+ blank, and nothing comes and goes as the script starts. */
71
+ [data-pg-reels-card]:has([data-pg-reels-clip][data-pg-reels-current]) [data-pg-reels-clip]:not([data-pg-reels-current]),
72
+ [data-pg-reels-card]:not(:has([data-pg-reels-clip][data-pg-reels-current])) [data-pg-reels-clip] ~ [data-pg-reels-clip] {
69
73
  visibility: hidden;
70
74
  }
71
75
  [data-pg-reels-clip] > video,
@@ -82,6 +86,9 @@
82
86
  [data-pg-reels-bars] {
83
87
  display: flex;
84
88
  gap: 0.25rem;
89
+ /* Its row's room from the first paint, before the script fills it:
90
+ nothing under it moves down when the bars come. */
91
+ min-height: 0.75rem;
85
92
  }
86
93
  [data-pg-reels-bar],
87
94
  [data-pg-reels-view-bar] {
@@ -136,9 +143,12 @@
136
143
  display: none !important;
137
144
  }
138
145
 
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]) {
146
+ /* The products and the view counts: only the playing clip's show —
147
+ before the script has chosen, the first. */
148
+ [data-pg-reels-group]:has([data-pg-reels-product][data-pg-reels-current]) [data-pg-reels-product]:not([data-pg-reels-current]),
149
+ [data-pg-reels-group]:not(:has([data-pg-reels-product][data-pg-reels-current])) [data-pg-reels-product] ~ [data-pg-reels-product],
150
+ [data-pg-reels-group]:has([data-pg-reels-views][data-pg-reels-current]) [data-pg-reels-views]:not([data-pg-reels-current]),
151
+ [data-pg-reels-group]:not(:has([data-pg-reels-views][data-pg-reels-current])) [data-pg-reels-views] ~ [data-pg-reels-views] {
142
152
  display: none !important;
143
153
  }
144
154
 
package/package.json CHANGED
@@ -1,22 +1,46 @@
1
1
  {
2
2
  "name": "@plusguard/reels",
3
- "version": "1.9.0",
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
- ".": { "types": "./dist/index.d.ts", "import": "./dist/index.js" },
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js"
12
+ },
10
13
  "./index.css": "./index.css"
11
14
  },
12
- "files": ["dist", "index.ts", "index.css", "README.md", "LICENSE"],
13
- "sideEffects": ["*.css"],
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": { "access": "public" },
29
+ "publishConfig": {
30
+ "access": "public"
31
+ },
18
32
  "license": "MIT",
19
33
  "author": "PlusGuard",
20
- "repository": { "type": "git", "url": "git+https://github.com/omisilli/reels.git" },
21
- "keywords": ["reels", "shoppable-video", "video-commerce", "stories", "ecommerce", "vanilla"]
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
  }