@nakednous/host 0.0.12 → 0.0.14

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 CHANGED
@@ -75,7 +75,7 @@ dependency first and an options object last, and registers with the context so
75
75
  | `host.pointer` | the pointer source — presses queued per frame, per-pointer entries with a move counter, claims that capture on the canvas, Esc cancel, `flush()` |
76
76
  | `host.players` | the registry ticked each frame — `{ tick(dt) → boolean }`, removed on `false` |
77
77
  | `host.width` · `host.height` · `host.dpr` | the canvas observer's logical size and pixel ratio |
78
- | `host.dt` · `host.clock()` | last frame period and seconds since creation |
78
+ | `host.dt` · `host.clock()` | last frame period and seconds since creation — or since the `origin` the host was given, an epoch-ms instant a page passes so the figures it embeds share one start |
79
79
  | `host.handle(opts)` | `Handle` — a draggable core constraint (`SPHERE` · `PLANE` · `AXIS` · `DIAL` · `VIEW`, or a contract object); `update()`, `value(out, opts)`, snap, hover, cancel, `from` |
80
80
  | `host.router(handles, opts)` | `PointerRouter` — one shared pick over overlapping handles, nearest proxy wins; shared hover |
81
81
  | `host.cameraHelm(cam, opts)` · `host.poseHelm(opts)` | a core `PoseHelm` on the players: body-fly a camera state, or integrate into a pose in `WORLD` · `EYE` · `SELF` · a mat4 and `bind()` a target |
package/dist/index.js CHANGED
@@ -402,7 +402,7 @@ function createPlayers() {
402
402
  return players;
403
403
  }
404
404
 
405
- const _now$2 = () => (typeof performance !== 'undefined' && performance.now) ? performance.now() : Date.now();
405
+ const _now$1 = () => (typeof performance !== 'undefined' && performance.now) ? performance.now() : Date.now();
406
406
 
407
407
  /**
408
408
  * Create a frame loop. `onFrame(dt)` runs once per animation frame with the
@@ -418,7 +418,7 @@ function createLoop(opts) {
418
418
  const o = opts || {};
419
419
  const raf = o.raf || ((cb) => requestAnimationFrame(cb));
420
420
  const caf = o.caf || ((id) => cancelAnimationFrame(id));
421
- const now = o.now || _now$2;
421
+ const now = o.now || _now$1;
422
422
  const clamp = (o.clampMs ?? 50) / 1000;
423
423
  let handle = null, last = 0;
424
424
  const loop = {
@@ -2717,7 +2717,7 @@ function createLabels(host, opts) {
2717
2717
 
2718
2718
 
2719
2719
  const _clamp = { min: 0, max: Infinity };
2720
- const _now$1 = () => (typeof performance !== 'undefined' && performance.now) ? performance.now() : Date.now();
2720
+ const _now = () => (typeof performance !== 'undefined' && performance.now) ? performance.now() : Date.now();
2721
2721
  const EPS = 1e-4; // a rate below this in every lane ends the drain
2722
2722
  const DT_MAX = 0.1; // seconds, the measured frame's clamp
2723
2723
 
@@ -2801,7 +2801,7 @@ function createOrbit(host, cam, opts) {
2801
2801
  * @returns {boolean} Whether the camera moved.
2802
2802
  */
2803
2803
  update(dt) {
2804
- const now = _now$1();
2804
+ const now = _now();
2805
2805
  if (typeof dt !== 'number') dt = lastNow ? Math.min((now - lastNow) / 1000, DT_MAX) : 0;
2806
2806
  lastNow = now;
2807
2807
  if (!orbit.enabled) { tracked.clear(); wheelAcc = 0; cancel(); wasPressed = false; return false; }
@@ -3112,8 +3112,9 @@ function decodeRGBE(bytes, opts) {
3112
3112
  * nothing grabbed, draw.
3113
3113
  */
3114
3114
 
3115
-
3116
- const _now = () => (typeof performance !== 'undefined' && performance.now) ? performance.now() : Date.now();
3115
+ // The clock's own reading: epoch milliseconds, so a host can be told where its
3116
+ // zero is. Monotonic where performance.now is, since timeOrigin never moves.
3117
+ const _epoch = () => (typeof performance !== 'undefined' && performance.timeOrigin) ? performance.timeOrigin + performance.now() : Date.now();
3117
3118
 
3118
3119
  /**
3119
3120
  * Create the host context of a canvas.
@@ -3121,7 +3122,8 @@ const _now = () => (typeof performance !== 'undefined' && performance.now) ? per
3121
3122
  * @param {HTMLCanvasElement} canvas
3122
3123
  * @param {{ ndcZMin?:number, onFrame?:function(number, object):void,
3123
3124
  * afterFrame?:function(number, object):void, raf?:function,
3124
- * caf?:function, onSize?:function(number, number, number):void }} [opts]
3125
+ * caf?:function, onSize?:function(number, number, number):void,
3126
+ * origin?:number }} [opts]
3125
3127
  * ndcZMin: the GPU API's NDC-z convention, WEBGL (default) or WEBGPU —
3126
3128
  * written once, never detected. onFrame: the host's own loop; absent,
3127
3129
  * external-tick mode. afterFrame: called after the pointer source
@@ -3130,12 +3132,14 @@ const _now = () => (typeof performance !== 'undefined' && performance.now) ? per
3130
3132
  * command encoder there. The host's loop only: an external tick has
3131
3133
  * no frame end but the one its caller writes. dispose() clears it.
3132
3134
  * onSize(width, height, dpr): the bridge's chance to resize its
3133
- * drawing buffer.
3135
+ * drawing buffer. origin: the epoch-ms instant `clock()` counts from,
3136
+ * default the host's creation — pass a page's `performance.timeOrigin`
3137
+ * and the figures a page embeds share one start.
3134
3138
  * @returns {object} The host.
3135
3139
  */
3136
3140
  function createHost(canvas, opts) {
3137
3141
  const o = opts || {};
3138
- const t0 = _now();
3142
+ const origin = (typeof o.origin === 'number' && Number.isFinite(o.origin)) ? o.origin : _epoch();
3139
3143
  const constructs = new Set();
3140
3144
  let loop = null, observer = null, labels = null;
3141
3145
  let afterFrame = typeof o.afterFrame === 'function' ? o.afterFrame : null;
@@ -3145,8 +3149,8 @@ function createHost(canvas, opts) {
3145
3149
  dt: 0,
3146
3150
  view: null, pointer: null, players: null,
3147
3151
 
3148
- /** Seconds since the host was created. */
3149
- clock() { return (_now() - t0) / 1000; },
3152
+ /** Seconds since the host was created — or since the `origin` it was given. */
3153
+ clock() { return (_epoch() - origin) / 1000; },
3150
3154
 
3151
3155
  /**
3152
3156
  * External-loop mode: tick the players with dt (seconds). The caller