@diegopluna/narvi 0.5.6 → 0.5.7

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.
@@ -19,9 +19,9 @@ import { BROWSER } from 'esm-env';
19
19
  import { onPageShown, pageShown } from './visible.js';
20
20
  const FOCUSED_RATE = 30;
21
21
  const UNFOCUSED_RATE = 10;
22
- // A frame is drawn on the first beat of the display at most this early: half a beat at 120Hz,
23
- // so a 30-a-second clock lands on every fourth beat there and every second at 60Hz
24
- const EARLY = 4;
22
+ // The timer wakes this long before a frame is due, and the frame is drawn on the display's
23
+ // next beat: every fourth at 120Hz for a 30-a-second clock, every second at 60Hz
24
+ const EARLY = 8;
25
25
  /** What draws on the next frame: everything subscribed, less what is out of view. */
26
26
  const drawing = new Set();
27
27
  /** What draws while an element is in view, and whether it is. */
@@ -34,9 +34,13 @@ let listening = false;
34
34
  const interval = () => 1000 / (document.hasFocus() ? FOCUSED_RATE : UNFOCUSED_RATE);
35
35
  function tick(time) {
36
36
  request = undefined;
37
- // Woken a beat early, the frame waits for a later one
38
- if (time - last >= interval() - EARLY) {
39
- last = time;
37
+ // Measured as the timer is, when the callback runs: a frame's callbacks can run well after
38
+ // its start, so by its `time` a frame just drawn could already look overdue. Every wake-up
39
+ // draws on the first frame after it; half an interval only keeps a stray request from
40
+ // drawing twice in a row.
41
+ const now = performance.now();
42
+ if (now - last >= interval() / 2) {
43
+ last = now;
40
44
  for (const draw of drawing) {
41
45
  try {
42
46
  draw(time);
@@ -61,7 +65,7 @@ function schedule() {
61
65
  if (timer !== undefined || request !== undefined)
62
66
  return;
63
67
  // A little before the frame is due, so the beat it is drawn on is not the one after
64
- const delay = last + interval() - EARLY * 2 - performance.now();
68
+ const delay = last + interval() - EARLY - performance.now();
65
69
  if (delay <= 0) {
66
70
  request = requestAnimationFrame(tick);
67
71
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@diegopluna/narvi",
3
- "version": "0.5.6",
3
+ "version": "0.5.7",
4
4
  "packageManager": "pnpm@12.18.0",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -12,7 +12,7 @@ metadata:
12
12
  Grid, and Narvi's conventions for colour, labels and copy.
13
13
  type: core
14
14
  library: '@diegopluna/narvi'
15
- library_version: '0.5.6'
15
+ library_version: '0.5.7'
16
16
  requires:
17
17
  - setup
18
18
  sources:
@@ -12,7 +12,7 @@ metadata:
12
12
  patching the DOM, and decide which links and images text from a model may load.
13
13
  type: core
14
14
  library: '@diegopluna/narvi'
15
- library_version: '0.5.6'
15
+ library_version: '0.5.7'
16
16
  requires:
17
17
  - setup
18
18
  sources:
@@ -11,7 +11,7 @@ metadata:
11
11
  4 when the app uses it.
12
12
  type: lifecycle
13
13
  library: '@diegopluna/narvi'
14
- library_version: '0.5.6'
14
+ library_version: '0.5.7'
15
15
  sources:
16
16
  - src/lib/vite.ts
17
17
  - src/lib/base.css
@@ -12,7 +12,7 @@ metadata:
12
12
  hover, motion and forced-colour preferences.
13
13
  type: core
14
14
  library: '@diegopluna/narvi'
15
- library_version: '0.5.6'
15
+ library_version: '0.5.7'
16
16
  requires:
17
17
  - setup
18
18
  sources:
@@ -12,7 +12,7 @@ metadata:
12
12
  menus and dialogs, and resolve token colours for drawing code that cannot read CSS variables.
13
13
  type: core
14
14
  library: '@diegopluna/narvi'
15
- library_version: '0.5.6'
15
+ library_version: '0.5.7'
16
16
  requires:
17
17
  - setup
18
18
  sources: