@simmalugnt-se/payload-consent 0.6.3 → 0.6.5

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/CHANGELOG.md CHANGED
@@ -1,5 +1,24 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.6.5
4
+
5
+ - The Scan tab shows the card's shape with Payload's shimmer while the latest scan loads. Before,
6
+ it said "The site has not been scanned yet" for a moment on every load of a scanned site.
7
+
8
+ ## 0.6.4
9
+
10
+ - The Scan tab's time left counts down. It grew while a page took its time, since it was worked
11
+ out each second from the scan's start, start-up included, and the pages already done; it now
12
+ takes the pace between pages as the scanner begins them, counts down until the next one and
13
+ says "almost done" once the pace is spent. The card asks every two seconds instead of four.
14
+ - A scan that ends no longer flashes "Waiting for the scanner": while the result is on its way
15
+ from the scanner, the card says it is saving the result, with a full bar. The result then fades
16
+ in with a "Just finished" pill, so it does not look like the scan before it.
17
+ - The README says that `consent-scanner` binds each token to its site's hosts and refuses scans
18
+ and callbacks for other hosts, which hosts to give it, and that it treats a site with and
19
+ without `www.` as one, so a Site address without `www.` still finds the pages on `www.`
20
+ (`consent-scanner` at `0b7aba1` or later).
21
+
3
22
  ## 0.6.3
4
23
 
5
24
  - The Scan tab's findings follow the card above them. Each group (Needs action, Not in the Cookie
package/README.md CHANGED
@@ -130,6 +130,13 @@ consentPlugin({
130
130
  })
131
131
  ```
132
132
 
133
+ The scanner binds each token to its site's hosts (`token@example.se|example.vercel.app` in its
134
+ `SCANNER_TOKENS`), and refuses a scan whose address or callback is on another host: give it the
135
+ host of the scanned address and, when results come back elsewhere (`serverURL` or
136
+ `callbackBaseUrl`), that host too. A host covers itself with and without `www.`, and the scanner
137
+ treats a site with and without `www.` as one, so a Site address of `https://example.se` still finds
138
+ the pages on `https://www.example.se`. Both need `consent-scanner` at `0b7aba1` or later.
139
+
133
140
  The scanner picks the pages to visit from the site's sitemaps. A site with search indexing off
134
141
  often serves empty ones, and then only the start page is scanned. With `scanner.pages`, a scan
135
142
  sends the published documents of those collections instead: read as a visitor would, in the
@@ -1,21 +1,23 @@
1
1
  "use client";
2
2
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
- import { Button, Collapsible, Pill, SelectInput, TextInput, useConfig, useFormFields, useLocale, useTranslation, } from "@payloadcms/ui";
4
- import { useCallback, useEffect, useState } from "react";
3
+ import { Button, Collapsible, Pill, SelectInput, ShimmerEffect, TextInput, useConfig, useFormFields, useLocale, useTranslation, } from "@payloadcms/ui";
4
+ import { useCallback, useEffect, useRef, useState, } from "react";
5
5
  import { CATEGORIES } from "../defaults.js";
6
6
  import { CONSENT_SCANS } from "../types.js";
7
- import { describeProblem, estimateLeft, findingHeading, finishedPages, formatElapsed, pagePath, scanVerdict, } from "./scan-view.js";
7
+ import { describeProblem, estimateLeft, findingHeading, finishedPages, formatElapsed, markPace, pagePath, scanVerdict, } from "./scan-view.js";
8
8
  import "../styles/admin.css";
9
9
  const COPY = {
10
10
  en: {
11
11
  noScanner: "No scanner is set up. Give the plugin `scanner: { url, token }` (see the README), then scan from here.",
12
12
  scan: "Scan now",
13
13
  starting: "Starting…",
14
+ loading: "Loading the latest scan",
14
15
  card: {
15
16
  pills: {
16
17
  none: "Not scanned",
17
18
  queued: "Waiting",
18
19
  running: "Scanning",
20
+ finishing: "Saving",
19
21
  failed: "Failed",
20
22
  action: "Needs action",
21
23
  unknown: "Not explained",
@@ -24,10 +26,12 @@ const COPY = {
24
26
  clean: "In order",
25
27
  },
26
28
  newPill: (n) => `${n} new`,
29
+ justFinished: "Just finished",
27
30
  title: {
28
31
  none: "The site has not been scanned yet",
29
32
  queued: "Waiting for the scanner",
30
33
  running: "Scanning the site",
34
+ finishing: "Saving the result",
31
35
  failed: "The scan failed",
32
36
  action: (n) => `${n} ${n === 1 ? "needs" : "need"} action`,
33
37
  unknown: (n) => `${n} not in the Cookie services`,
@@ -39,6 +43,8 @@ const COPY = {
39
43
  none: "Scan now to see which cookies, storage and other sites the published site uses, before and after the visitor's choice.",
40
44
  queued: (position) => position ? `Number ${position} in line.` : "It starts when the scanner is free.",
41
45
  choosing: "Choosing the pages to visit…",
46
+ finishing: "The scan is done. Its result is on its way to this site.",
47
+ late: "The result has not arrived. If the scanner could not reach this site, the scan is marked as failed within a day.",
42
48
  action: "Services load where the visitor has not allowed their category.",
43
49
  unknown: "The scan found storage or other sites that no Cookie service explains.",
44
50
  incomplete: "It may have missed something. Scan again once this is fixed:",
@@ -51,6 +57,7 @@ const COPY = {
51
57
  ...(stage.states > 1 ? [`state ${stage.stateNumber} of ${stage.states}`] : []),
52
58
  ].join(" · "),
53
59
  elapsed: (time, left) => (left ? `${time} · about ${left} left` : time),
60
+ almostDone: (time) => `${time} · almost done`,
54
61
  progress: (finished, total) => `${finished} of ${total} page visits done`,
55
62
  stats: {
56
63
  pages: (n, of) => n === of ? (n === 1 ? "page" : "pages") : `of ${of} ${of === 1 ? "page" : "pages"}`,
@@ -123,11 +130,13 @@ const COPY = {
123
130
  noScanner: "Ingen skanner är inställd. Ge pluginet `scanner: { url, token }` (se README), och skanna sedan härifrån.",
124
131
  scan: "Skanna nu",
125
132
  starting: "Startar…",
133
+ loading: "Hämtar den senaste skanningen",
126
134
  card: {
127
135
  pills: {
128
136
  none: "Inte skannad",
129
137
  queued: "Väntar",
130
138
  running: "Skannar",
139
+ finishing: "Sparar",
131
140
  failed: "Misslyckades",
132
141
  action: "Åtgärd krävs",
133
142
  unknown: "Okänt",
@@ -136,10 +145,12 @@ const COPY = {
136
145
  clean: "I ordning",
137
146
  },
138
147
  newPill: (n) => `${n} nya`,
148
+ justFinished: "Nyss klar",
139
149
  title: {
140
150
  none: "Webbplatsen har inte skannats än",
141
151
  queued: "Väntar på skannern",
142
152
  running: "Skannar webbplatsen",
153
+ finishing: "Sparar resultatet",
143
154
  failed: "Skanningen misslyckades",
144
155
  action: (n) => `${n} kräver åtgärd`,
145
156
  unknown: (n) => `${n} finns inte bland Cookietjänsterna`,
@@ -151,6 +162,8 @@ const COPY = {
151
162
  none: "Skanna nu för att se vilka cookies, vilken lagring och vilka andra webbplatser den publicerade webbplatsen använder, före och efter besökarens val.",
152
163
  queued: (position) => position ? `Nummer ${position} i kön.` : "Den startar när skannern är ledig.",
153
164
  choosing: "Väljer vilka sidor som ska besökas…",
165
+ finishing: "Skanningen är klar. Resultatet är på väg till webbplatsen.",
166
+ late: "Resultatet har inte kommit. Om skannern inte nådde webbplatsen markeras skanningen som misslyckad inom ett dygn.",
154
167
  action: "Tjänster laddas där besökaren inte har tillåtit kategorin.",
155
168
  unknown: "Skanningen hittade lagring eller andra webbplatser som ingen Cookietjänst förklarar.",
156
169
  incomplete: "Den kan ha missat något. Skanna igen när det här är åtgärdat:",
@@ -163,6 +176,7 @@ const COPY = {
163
176
  ...(stage.states > 1 ? [`läge ${stage.stateNumber} av ${stage.states}`] : []),
164
177
  ].join(" · "),
165
178
  elapsed: (time, left) => (left ? `${time} · ungefär ${left} kvar` : time),
179
+ almostDone: (time) => `${time} · snart klar`,
166
180
  progress: (finished, total) => `${finished} av ${total} sidbesök klara`,
167
181
  stats: {
168
182
  pages: (n, of) => n === of ? (n === 1 ? "sida" : "sidor") : `av ${of} ${of === 1 ? "sida" : "sidor"}`,
@@ -260,6 +274,7 @@ const CARD_PILL = {
260
274
  none: "light-gray",
261
275
  queued: "light-gray",
262
276
  running: "light-gray",
277
+ finishing: "light-gray",
263
278
  failed: "error",
264
279
  action: "error",
265
280
  unknown: "warning",
@@ -277,13 +292,17 @@ const GROUP_PILL = {
277
292
  * The scan at a glance: where it stands or what it found, with Scan now. A panel of our own like
278
293
  * the dashboard widget's: Payload's `Card` is a link, not a status.
279
294
  */
280
- function ScanCard({ active, busy, copy, current, error, language, live, now, onStart, scan, scansUrl, }) {
295
+ function ScanCard({ active, busy, copy, current, error, finishingSince, fresh, language, live, now, onStart, pace, scan, scansUrl, }) {
281
296
  const card = copy.card;
282
297
  const summary = scan?.status === "done" ? scan.summary : undefined;
298
+ // The scanner says a scan is done before the site has saved its result: until then the scan is
299
+ // finishing, not back in the queue.
283
300
  const state = active
284
301
  ? current === "running"
285
302
  ? "running"
286
- : "queued"
303
+ : current === "done" || current === "failed"
304
+ ? "finishing"
305
+ : "queued"
287
306
  : !scan
288
307
  ? "none"
289
308
  : scan.status === "failed"
@@ -297,7 +316,7 @@ function ScanCard({ active, busy, copy, current, error, language, live, now, onS
297
316
  ? card.title.unknown(summary?.unknown ?? 0)
298
317
  : card.title[state];
299
318
  const elapsed = live.startedAt ? now - Date.parse(live.startedAt) : undefined;
300
- const left = live.stage && elapsed !== undefined ? estimateLeft(elapsed, live.stage) : undefined;
319
+ const left = live.stage ? estimateLeft(pace, live.stage.total, now) : undefined;
301
320
  const findings = scan?.findings ?? [];
302
321
  const count = (kind) => findings.filter((f) => f.kind === kind).length;
303
322
  const pages = scan?.pages?.selected ?? [];
@@ -317,17 +336,21 @@ function ScanCard({ active, busy, copy, current, error, language, live, now, onS
317
336
  const took = scan?.startedAt && scan.finishedAt
318
337
  ? formatElapsed(Date.parse(scan.finishedAt) - Date.parse(scan.startedAt))
319
338
  : undefined;
320
- return (_jsxs("section", { className: `consent-scan__card consent-scan__card--${CARD_PILL[state]}`, children: [_jsxs("div", { className: "consent-scan__head", children: [_jsxs("div", { className: "consent-scan__pills", children: [_jsx(Pill, { pillStyle: CARD_PILL[state], size: "small", children: card.pills[state] }), summary?.new ? (_jsx(Pill, { pillStyle: "light", size: "small", children: card.newPill(summary.new) })) : null] }), _jsx(Button, { buttonStyle: state === "none" ? "primary" : "secondary", disabled: busy || active, margin: false, onClick: onStart, size: "small", children: busy ? copy.starting : copy.scan })] }), _jsxs("div", { "aria-live": "polite", className: "consent-scan__body", children: [_jsx("h3", { className: "consent-scan__title", children: title }), state === "none" ? _jsx("p", { children: card.text.none }) : null, state === "queued" ? _jsx("p", { children: card.text.queued(live.position) }) : null, state === "running" ? (_jsx("p", { children: live.stage
339
+ return (_jsxs("section", { className: `consent-scan__card consent-scan__card--${CARD_PILL[state]}${summary && fresh ? " consent-scan__card--fresh" : ""}`, children: [_jsxs("div", { className: "consent-scan__head", children: [_jsxs("div", { className: "consent-scan__pills", children: [_jsx(Pill, { pillStyle: CARD_PILL[state], size: "small", children: card.pills[state] }), summary && fresh ? (_jsx(Pill, { pillStyle: "light", size: "small", children: card.justFinished })) : null, summary?.new ? (_jsx(Pill, { pillStyle: "light", size: "small", children: card.newPill(summary.new) })) : null] }), _jsx(Button, { buttonStyle: state === "none" ? "primary" : "secondary", disabled: busy || active, margin: false, onClick: onStart, size: "small", children: busy ? copy.starting : copy.scan })] }), _jsxs("div", { "aria-live": "polite", className: "consent-scan__body", children: [_jsx("h3", { className: "consent-scan__title", children: title }), state === "none" ? _jsx("p", { children: card.text.none }) : null, state === "queued" ? _jsx("p", { children: card.text.queued(live.position) }) : null, state === "running" ? (_jsx("p", { children: live.stage
321
340
  ? card.stage(capitalize(stateLabel(copy, live.stage.state)), live.stage)
322
341
  : live.progress
323
342
  ? progressLabel(copy, live.progress)
324
- : card.text.choosing })) : null, state === "failed" ? _jsx("p", { children: scan?.error }) : null, state === "action" ||
343
+ : card.text.choosing })) : null, state === "finishing" ? (_jsx("p", { children: finishingSince !== undefined && now - finishingSince > 60_000
344
+ ? card.text.late
345
+ : card.text.finishing })) : null, state === "failed" ? _jsx("p", { children: scan?.error }) : null, state === "action" ||
325
346
  state === "unknown" ||
326
347
  state === "incomplete" ||
327
348
  state === "ok" ||
328
- state === "clean" ? (_jsx("p", { children: card.text[state] })) : null] }), state === "running" && live.stage ? (
349
+ state === "clean" ? (_jsx("p", { children: card.text[state] })) : null] }), (state === "running" || state === "finishing") && live.stage ? (
329
350
  // Payload has no progress bar for content (its ProgressBar follows route changes).
330
- _jsx("progress", { "aria-label": card.progress(finishedPages(live.stage), live.stage.total), className: "consent-scan__progress", max: live.stage.total, value: finishedPages(live.stage) })) : null, state === "running" && elapsed !== undefined ? (_jsx("p", { className: "consent-scan__meta", children: card.elapsed(formatElapsed(elapsed), left === undefined ? undefined : formatElapsed(left)) })) : null, summary?.problems?.length ? (_jsx("ul", { className: "consent-scan__problems", children: summary.problems.map((raw) => {
351
+ _jsx("progress", { "aria-label": card.progress(state === "finishing" ? live.stage.total : finishedPages(live.stage), live.stage.total), className: "consent-scan__progress", max: live.stage.total, value: state === "finishing" ? live.stage.total : finishedPages(live.stage) })) : null, state === "running" && elapsed !== undefined ? (_jsx("p", { className: "consent-scan__meta", children: left !== undefined && left < 1000
352
+ ? card.almostDone(formatElapsed(elapsed))
353
+ : card.elapsed(formatElapsed(elapsed), left === undefined ? undefined : formatElapsed(left)) })) : null, summary?.problems?.length ? (_jsx("ul", { className: "consent-scan__problems", children: summary.problems.map((raw) => {
331
354
  const problem = describeProblem(raw, stateIds);
332
355
  const label = problem.state ? stateLabel(copy, problem.state) : "";
333
356
  const text = problem.kind === "sitemap"
@@ -340,6 +363,13 @@ function ScanCard({ active, busy, copy, current, error, language, live, now, onS
340
363
  ? ` · ${card.states(stateIds.length, statesLabel(copy, stateIds, language))}`
341
364
  : "", " · ", _jsx("a", { href: scansUrl, children: card.all })] }), pages.length ? (_jsx(Collapsible, { className: "consent-scan__pages", header: card.pages(pages.length), initCollapsed: true, children: _jsx("ul", { children: pages.map((page) => (_jsx("li", { children: _jsx("a", { href: page, rel: "noopener noreferrer", target: "_blank", title: page, children: pagePath(page) }) }, page))) }) })) : null] })) : scan ? (_jsx("p", { className: "consent-scan__meta", children: _jsx("a", { href: scansUrl, children: card.all }) })) : null] }));
342
365
  }
366
+ /**
367
+ * The card's shape while the latest scan loads, so a scanned site never shows "not scanned yet"
368
+ * first; Payload's shimmer, as Admin shows while it loads.
369
+ */
370
+ function LoadingCard({ label }) {
371
+ return (_jsxs("section", { "aria-busy": "true", "aria-label": label, className: "consent-scan__card", children: [_jsx(ShimmerEffect, { height: 20, width: 80 }), _jsx(ShimmerEffect, { height: 24, width: "40%" }), _jsx(ShimmerEffect, { height: 16, width: "70%" }), _jsx(ShimmerEffect, { height: 44 }), _jsx(ShimmerEffect, { height: 16, width: "55%" })] }));
372
+ }
343
373
  function capitalize(value) {
344
374
  return value ? `${value[0]?.toUpperCase()}${value.slice(1)}` : value;
345
375
  }
@@ -363,6 +393,10 @@ export function ScanPanel() {
363
393
  const [busy, setBusy] = useState(false);
364
394
  const [error, setError] = useState();
365
395
  const [now, setNow] = useState(() => Date.now());
396
+ // The pace of the scan being watched, from when each page was first seen begun.
397
+ const [pace, setPace] = useState({ marks: [] });
398
+ // The scan the card has seen running or waiting, so its result shows as just finished.
399
+ const watched = useRef(undefined);
366
400
  const load = useCallback(async () => {
367
401
  const response = await fetch(`${api}?sort=-createdAt&limit=1&depth=0`, {
368
402
  credentials: "include",
@@ -373,35 +407,54 @@ export function ScanPanel() {
373
407
  useEffect(() => {
374
408
  load();
375
409
  }, [load]);
376
- // While a scan waits or runs, ask for its progress; reload it when it ends.
410
+ // While a scan waits or runs, ask for its progress; reload it until its result has arrived.
377
411
  useEffect(() => {
378
412
  if (!scan || (scan.status !== "queued" && scan.status !== "running"))
379
413
  return;
414
+ watched.current = scan.id;
380
415
  let stopped = false;
381
416
  const poll = async () => {
382
417
  const response = await fetch(`${api}/${scan.id}/status`, { credentials: "include" });
383
418
  const next = (await response.json().catch(() => ({})));
384
419
  if (stopped)
385
420
  return;
386
- setLive(next);
421
+ const at = Date.now();
422
+ // A finished scan no longer reports its stage: keep the last one for the full bar.
423
+ setLive((previous) => ({
424
+ ...next,
425
+ stage: next.stage ?? previous.stage,
426
+ startedAt: next.startedAt ?? previous.startedAt,
427
+ }));
428
+ setPace((previous) => ({
429
+ id: scan.id,
430
+ marks: markPace(previous.id === scan.id ? previous.marks : [], next.stage, at),
431
+ }));
387
432
  if (next.status === "done" || next.status === "failed")
388
433
  await load();
389
434
  };
390
435
  poll();
391
- const timer = setInterval(poll, 4000);
436
+ const timer = setInterval(poll, 2000);
392
437
  return () => {
393
438
  stopped = true;
394
439
  clearInterval(timer);
395
440
  };
396
441
  }, [api, load, scan]);
397
- // A running scan's clock ticks each second between the scanner's answers.
398
- const running = scan?.status === "running" || live.status === "running";
442
+ const active = scan?.status === "queued" || scan?.status === "running";
443
+ // The scanner knows first when a queued scan starts running, and when it is done.
444
+ const current = active ? (live.status ?? scan?.status) : scan?.status;
445
+ const finishing = active && (current === "done" || current === "failed");
446
+ const [finishingSince, setFinishingSince] = useState();
447
+ useEffect(() => {
448
+ setFinishingSince((since) => (finishing ? (since ?? Date.now()) : undefined));
449
+ }, [finishing]);
450
+ // A waiting or running scan's clock ticks each second between the scanner's answers.
451
+ const ticking = scan?.status === "queued" || scan?.status === "running";
399
452
  useEffect(() => {
400
- if (!running)
453
+ if (!ticking)
401
454
  return;
402
455
  const timer = setInterval(() => setNow(Date.now()), 1000);
403
456
  return () => clearInterval(timer);
404
- }, [running]);
457
+ }, [ticking]);
405
458
  async function start() {
406
459
  setBusy(true);
407
460
  setError(undefined);
@@ -422,11 +475,8 @@ export function ScanPanel() {
422
475
  }
423
476
  if (!hasScanner)
424
477
  return _jsx("p", { className: "consent-scan__note", children: copy.noScanner });
425
- const active = scan?.status === "queued" || scan?.status === "running";
426
- // The scanner knows first when a queued scan starts running.
427
- const current = active ? (live.status ?? scan?.status) : scan?.status;
428
478
  const findings = scan?.findings ?? [];
429
- return (_jsxs("div", { className: "consent-scan", children: [_jsx(ScanCard, { active: active, busy: busy, copy: copy, current: current, error: error, language: language, live: live, now: now, onStart: start, scan: scan ?? null, scansUrl: `${config.routes.admin}/collections/${CONSENT_SCANS}` }), scan?.status === "done"
479
+ return (_jsxs("div", { className: "consent-scan", children: [scan === undefined ? (_jsx(LoadingCard, { label: copy.loading })) : (_jsx(ScanCard, { active: active, busy: busy, copy: copy, current: current, error: error, finishingSince: finishingSince, fresh: Boolean(scan) && watched.current === scan?.id, language: language, live: live, now: now, onStart: start, pace: pace.id === scan?.id ? pace.marks : [], scan: scan, scansUrl: `${config.routes.admin}/collections/${CONSENT_SCANS}` })), scan?.status === "done"
430
480
  ? ["action", "unknown", "ok"].map((status) => {
431
481
  const rows = findings.filter((finding) => finding.status === status);
432
482
  if (!rows.length)
@@ -28,10 +28,19 @@ export type ScanProblem = {
28
28
  detail: string;
29
29
  };
30
30
  export declare function describeProblem(problem: string, stateIds: string[]): ScanProblem;
31
+ /** When the card first saw each count of pages begun (`stage.visited`), for the pace. */
32
+ export type PaceMark = {
33
+ visited: number;
34
+ at: number;
35
+ };
36
+ /** The marks with the scanner's latest answer, when it has begun a page the card had not seen. */
37
+ export declare function markPace(marks: PaceMark[], stage: ScanStage | undefined, now: number): PaceMark[];
31
38
  /**
32
- * Roughly how long a running scan has left, from the pace so far; `undefined` until a page is
33
- * done, when there is no pace to go by.
39
+ * Roughly how long a running scan has left. The pace is the time between the first and the latest
40
+ * page begun, so the scan's start-up is left out, and the estimate made when the latest page began
41
+ * counts down until the next one rather than grow while a page takes its time. Undefined until two
42
+ * pages have begun; 0 once the pace says the scan should be done, as it ends with WEC's report.
34
43
  */
35
- export declare function estimateLeft(elapsedMs: number, stage: ScanStage): number | undefined;
44
+ export declare function estimateLeft(marks: PaceMark[], total: number, now: number): number | undefined;
36
45
  /** `/about?x=1` for a page on the scanned site: the address without its origin. */
37
46
  export declare function pagePath(url: string): string;
@@ -44,15 +44,27 @@ export function describeProblem(problem, stateIds) {
44
44
  return { kind: "outOfTime", state, detail };
45
45
  return { kind: "pagesFailed", state, detail };
46
46
  }
47
+ /** The marks with the scanner's latest answer, when it has begun a page the card had not seen. */
48
+ export function markPace(marks, stage, now) {
49
+ const last = marks.at(-1);
50
+ if (!stage || stage.visited < 1 || (last && last.visited >= stage.visited))
51
+ return marks;
52
+ return [...marks, { visited: stage.visited, at: now }];
53
+ }
47
54
  /**
48
- * Roughly how long a running scan has left, from the pace so far; `undefined` until a page is
49
- * done, when there is no pace to go by.
55
+ * Roughly how long a running scan has left. The pace is the time between the first and the latest
56
+ * page begun, so the scan's start-up is left out, and the estimate made when the latest page began
57
+ * counts down until the next one rather than grow while a page takes its time. Undefined until two
58
+ * pages have begun; 0 once the pace says the scan should be done, as it ends with WEC's report.
50
59
  */
51
- export function estimateLeft(elapsedMs, stage) {
52
- const finished = finishedPages(stage);
53
- if (finished < 1 || elapsedMs <= 0)
60
+ export function estimateLeft(marks, total, now) {
61
+ const first = marks[0];
62
+ const last = marks.at(-1);
63
+ if (!first || !last || last.visited <= first.visited)
54
64
  return undefined;
55
- return (elapsedMs / finished) * Math.max(0, stage.total - finished);
65
+ const pace = (last.at - first.at) / (last.visited - first.visited);
66
+ // The latest page has only begun: it is left too, with every page after it.
67
+ return Math.max(0, pace * (total - last.visited + 1) - (now - last.at));
56
68
  }
57
69
  /** `/about?x=1` for a page on the scanned site: the address without its origin. */
58
70
  export function pagePath(url) {
@@ -24,6 +24,21 @@
24
24
  .consent-scan__card--warning {
25
25
  border-color: var(--theme-warning-500);
26
26
  }
27
+ /* A result that arrived while the card watched the scan: it fades in rather than swap in place. */
28
+ .consent-scan__card--fresh {
29
+ animation: consent-scan-fresh 400ms ease-out;
30
+ }
31
+ @keyframes consent-scan-fresh {
32
+ from {
33
+ opacity: 0.35;
34
+ transform: translateY(4px);
35
+ }
36
+ }
37
+ @media (prefers-reduced-motion: reduce) {
38
+ .consent-scan__card--fresh {
39
+ animation: none;
40
+ }
41
+ }
27
42
  .consent-scan__head {
28
43
  display: flex;
29
44
  align-items: center;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@simmalugnt-se/payload-consent",
3
- "version": "0.6.3",
3
+ "version": "0.6.5",
4
4
  "description": "Cookie consent for Payload sites: banner texts, services and scans in Admin",
5
5
  "keywords": [
6
6
  "payload",