@justai/core 0.18.0 → 0.19.0

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 (2) hide show
  1. package/package.json +1 -1
  2. package/src/index.js +46 -8
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@justai/core",
3
- "version": "0.18.0",
3
+ "version": "0.19.0",
4
4
  "description": "The framework-free heart of the persona shell — the load-bearing behaviour (auth capture, reveal, ready) as plain strings, so Astro and Next inject the SAME logic instead of each re-writing it.",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {
package/src/index.js CHANGED
@@ -526,15 +526,46 @@ export function personaScroll(options) {
526
526
  };
527
527
  const goTo = (sec, behavior) => window.scrollTo({ top: landingY(sec), behavior: behavior });
528
528
 
529
+ // queries: the page rests a few pixels short of the kernel · the hash flips to #profile on its own ·
530
+ // typing the bare host lands on the profile · below.top 4.36 · the landing is not repaired ·
531
+ // it works with #kernel in the URL but not without · unstable landing
532
+ //
533
+ // WHERE THIS PAGE WAS SENT — DECIDED ONCE, AND NEVER READ BACK OUT OF THE ADDRESS BAR.
534
+ //
535
+ // This used to be re-derived from `location.hash` on every attempt, and the spy WRITES that hash.
536
+ // So the repair mechanism took its definition of "where I was supposed to be" from the very thing
537
+ // that goes wrong. Traced frame by frame on a live persona at 1512×900:
538
+ //
539
+ // t=241 scrollTo(333.36) landed exactly, below.top 0.36, #kernel
540
+ // t=258 the title strip begins closing y 331, below.top 2.36
541
+ // t=272 below.top passes 1 the spy answers PROFILE and writes #profile
542
+ // t=313 the strip is closed, the page has drifted y 329, below.top 4.36
543
+ // t=342 the `load` repair runs — and reads #profile as its target, measures itself
544
+ // 329 against the PROFILE's landing, finds it further than any drift could be,
545
+ // and closes the promise for good.
546
+ //
547
+ // Four pixels, and the page is stable in the wrong state: the kernel is 4px under the toolbar, the
548
+ // spy says profile, the strip stays shut, and the address bar says #profile for a person who typed
549
+ // the bare host. It is not a hash bug — with #kernel in the URL the same drift flips the same spy
550
+ // and disarms the same repair. What made it look like one is that the two stable states are
551
+ // reachable by a hair: on a phone the landing happened to rest at below.top −0.27 and stayed right.
552
+ //
553
+ // Captured before the first landing, so the repair keeps asking the only question worth asking:
554
+ // *am I where I was SENT?* One re-assert settles it permanently — measured, four times over, no
555
+ // oscillation.
556
+ const sentTo = (() => {
557
+ const t = cuts.find((c) => "#" + c[0].id === location.hash);
558
+ // A section hash is honoured on load and refresh; anything else — including #kernel and no hash
559
+ // at all — lands on the kernel.
560
+ return t ? t[0] : kernel;
561
+ })();
562
+
529
563
  const land = () => {
530
564
  // presentation mode owns the viewport — a page presenting itself does not scroll out from under
531
565
  // whoever opened it
532
566
  if (document.body.dataset.present) return;
533
- const h = location.hash;
534
- const target = cuts.find((c) => "#" + c[0].id === h);
535
- // A section hash is honoured on load and refresh; anything else — including #kernel and no hash
536
- // at all — lands on the kernel. `instant` overrides the page's own scroll-behavior: smooth.
537
- goTo(target ? target[0] : kernel, "instant");
567
+ // `instant` overrides the page's own scroll-behavior: smooth.
568
+ goTo(sentTo, "instant");
538
569
  };
539
570
  // queries: the page did not land on the kernel · landing scroll ignored · scrollTo does nothing on
540
571
  // first paint · the page opens at the top sometimes
@@ -576,9 +607,7 @@ export function personaScroll(options) {
576
607
  // Kept open until then rather than for a fixed number of tries, because the drift that has to be
577
608
  // repaired happens after load, once the title strip has opened and closed.
578
609
  if (taken || landed) return;
579
- const h = location.hash;
580
- const t = cuts.find((c) => "#" + c[0].id === h);
581
- const want = landingY(t ? t[0] : kernel);
610
+ const want = landingY(sentTo);
582
611
  // A pixel of slack: a browser is free to land a scroll a hair off the number it was handed, and
583
612
  // re-asserting over a rounding error would fight the person for the rest of the page's life.
584
613
  const off = Math.abs(window.scrollY - want);
@@ -598,6 +627,15 @@ export function personaScroll(options) {
598
627
  };
599
628
  requestAnimationFrame(landIfUntouched);
600
629
  window.addEventListener("load", landIfUntouched);
630
+ // queries: the landing is repaired too early · load fires before the strip settles · ResizeObserver
631
+ //
632
+ // AND WHEN THE THING THAT CAUSES THE DRIFT MOVES. rAF and `load` are two moments, and the drift is
633
+ // an event: the toolbar changes height, everything under it shifts, and the page comes to rest
634
+ // somewhere new. On the trace above `load` happened to fire after that; on a faster page it fires
635
+ // before, and then there is nothing left to notice. Watching the toolbar is watching the cause —
636
+ // and it costs nothing after the promise closes, because `landIfUntouched` returns on its first
637
+ // line once somebody has taken over or the page has plainly been moved elsewhere.
638
+
601
639
 
602
640
  // The reveal rides with this on pages whose content is ready at first paint. A page that renders
603
641
  // asynchronously — the vault, the file kernel — holds paint until its own data has arrived and