@justai/core 0.28.0 → 0.29.1

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 +65 -62
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@justai/core",
3
- "version": "0.28.0",
3
+ "version": "0.29.1",
4
4
  "description": "The framework-free heart of the persona shell \u2014 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
@@ -810,71 +810,63 @@ export function personaScroll(options) {
810
810
  // queries: the page did not land on the kernel · landing scroll ignored · scrollTo does nothing on
811
811
  // first paint · the page opens at the top sometimes
812
812
  //
813
- // LANDED, OR TRIED AGAIN — because a scroll can be silently refused.
813
+ // LANDED, OR TRIED AGAIN — but only for the one case where a scroll is REFUSED.
814
814
  //
815
815
  // `scrollTo` past the current document height is a no-op, and it does not report one: on a page
816
- // whose sections size themselves a frame later, the landing is CALLED, the browser declines it,
817
- // and the page opens at the top with nothing anywhere saying so. Measured in this behaviour's own
818
- // fixture: `scrollTo({top: 548})` followed by a scroll event reading 0.
816
+ // whose sections size themselves a frame later, the landing is CALLED, the browser declines it, and
817
+ // the page opens at the top with nothing anywhere saying so. Measured in this behaviour's own
818
+ // fixture: `scrollTo({top: 548})` followed by a scroll event reading 0. So it is attempted again on
819
+ // the next frame, on `load`, and once more when the page comes to rest.
819
820
  //
820
- // So it is attempted again on the next frame and on `load`. It used to retry only while the page
821
- // was still at the VERY TOP — a landing that did nothing — and that missed the case that actually
822
- // bit: a landing that ARRIVED and then DRIFTED. Traced in the fixture:
821
+ // ── WHAT USED TO BE HERE, AND WHY IT IS NOT ────────────────────────────────────────────────
822
+ //
823
+ // A second, much larger mechanism: a landing that ARRIVED and then DRIFTED, held as a promise until
824
+ // a wheel, a finger or a key "took over", with a tolerance derived from the toolbar's own height.
825
+ // Its trace, recorded in this file:
823
826
  //
824
827
  // scrollTo(468) y = 468 the landing is exact
825
828
  // DOMContentLoaded y = 494 docH +26 — the title strip opened
826
829
  // settled y = 465 docH -26 — and the strip closed again
827
830
  //
828
- // The strip lives inside the sticky toolbar, ABOVE the kernel, so every time it opens or closes the
829
- // browser moves the scroll position to keep the content under it steady. The page came to rest three
830
- // pixels short of where the kernel begins — close enough to look landed, far enough that the spy
831
- // correctly answered "profile", which closed the strip, which is what moved it there.
831
+ // Every term of it was the secondary strip. It sat above the kernel inside the sticky bar, so each
832
+ // time it opened or closed the browser moved the scroll position to keep the content under it
833
+ // steady, and the page came to rest three pixels short of where the kernel began — close enough to
834
+ // look landed, far enough that the spy answered "profile", which closed the strip, which is what
835
+ // moved it. The founder removed the strip on 2026-08-06, and this went with it: measured after, the
836
+ // page scrolls exactly ONCE to its landing and never moves again, at 402x710 and at 1440x900.
832
837
  //
833
- // A LANDING IS A PROMISE, AND IT IS KEPT UNTIL THE PERSON TAKES OVER. Not "until the page moves" —
834
- // the page moves on its own here — but until somebody actually reaches for it. Once they have, the
835
- // promise is void forever: nobody is ever yanked back to a section they scrolled away from.
836
- let taken = false;
837
- let landed = false;
838
- const takeOver = () => { taken = true; navTo = null; };
839
- // What "reaching for it" IS: a wheel, a finger, a key, a drag on the bar. A CLICK is deliberately
840
- // not on this list — pressing a link to a cut is asking for a landing, not overriding one.
838
+ // A workaround outlives its cause silently. This one would have kept re-asserting a landing nobody
839
+ // needed, over a drift that can no longer happen, for as long as the file existed.
840
+ // Only the DESTINATION is released when somebody takes over, never the landing: a tap on a cut
841
+ // shows where the page is GOING, and nobody should be shown a destination they have abandoned.
842
+ // The landing itself no longer needs protecting — there is no drift left for it to be protected
843
+ // from, which is the whole point of the note above.
844
+ const takeOver = () => { navTo = null; };
841
845
  for (const ev of ["wheel", "touchmove", "keydown"]) window.addEventListener(ev, takeOver, { passive: true });
846
+
842
847
  land();
843
- const landIfUntouched = () => {
844
- // THE PROMISE BELONGS TO THE ARRIVAL, NOT TO THE PAGE'S WHOLE LIFE. It is released the first time
845
- // the page is found resting where it was sent — after that this never runs again, so a persona's
846
- // own scrolling, a deep link handled later, or anything else that moves the page is never undone.
847
- // Kept open until then rather than for a fixed number of tries, because the drift that has to be
848
- // repaired happens after load, once the title strip has opened and closed.
849
- if (taken || landed) return;
850
- const want = landingY(sentTo);
851
- // A pixel of slack: a browser is free to land a scroll a hair off the number it was handed, and
852
- // re-asserting over a rounding error would fight the person for the rest of the page's life.
853
- const off = Math.abs(window.scrollY - want);
854
- // HOW FAR OFF IS STILL "THE LANDING DRIFTED", and how far is somebody else moving the page? The
855
- // drift has a known size: it is caused by chrome above the kernel changing height, so it can never
856
- // exceed that chrome. Anything larger is a deliberate scroll — a spec, a deep link handled later,
857
- // a persona's own code — and is left alone. Derived from the toolbar rather than chosen, so it
858
- // stays true if the bar ever changes shape.
859
- const drift = toolbar ? toolbar.getBoundingClientRect().height : 0;
860
- // Arriving does NOT end the promise. The page can be nudged again long after it settled — a
861
- // consent sheet closing moved qr by 3px, and released early that is enough to hand the section
862
- // back to the profile while the kernel fills the screen. The promise ends when somebody takes
863
- // over, or when the page is moved somewhere it was plainly never sent.
864
- if (off <= 1) return;
865
- if (off <= drift) land();
866
- else landed = true;
848
+
849
+ // A CLICK CLOSES THIS ONE, AND THAT IS THE DIFFERENCE FROM WHAT WAS HERE BEFORE. The old promise
850
+ // deliberately survived clicks, because a tap on a cut is a request for a landing rather than an
851
+ // override — but that promise existed to repair the strip's drift, and it could tell the two apart
852
+ // because it only ever corrected by less than a toolbar's height. This one has no such tolerance:
853
+ // it can only distinguish "the browser refused the scroll" from "the page is somewhere on purpose",
854
+ // and after a tap those look identical. Caught by the row's own spec: clicking Profile rested the
855
+ // page at 0, this read it as a refusal, and pulled it back to the kernel.
856
+ let landed = false;
857
+ const settle = () => { landed = true; };
858
+ for (const ev of ["wheel", "touchmove", "keydown", "click"]) {
859
+ window.addEventListener(ev, settle, { passive: true, once: true });
860
+ }
861
+ const landIfRefused = () => {
862
+ if (landed) return;
863
+ // Anywhere but the very top means the scroll was accepted. A landing that IS the top has nothing
864
+ // to be refused about. Either way this is the last thing it ever does.
865
+ if (window.scrollY > 1 || landingY(sentTo) <= 1) { landed = true; return; }
866
+ land();
867
867
  };
868
- requestAnimationFrame(landIfUntouched);
869
- window.addEventListener("load", landIfUntouched);
870
- // queries: the landing is repaired too early · load fires before the strip settles · ResizeObserver
871
- //
872
- // AND WHEN THE THING THAT CAUSES THE DRIFT MOVES. rAF and `load` are two moments, and the drift is
873
- // an event: the toolbar changes height, everything under it shifts, and the page comes to rest
874
- // somewhere new. On the trace above `load` happened to fire after that; on a faster page it fires
875
- // before, and then there is nothing left to notice. Watching the toolbar is watching the cause —
876
- // and it costs nothing after the promise closes, because `landIfUntouched` returns on its first
877
- // line once somebody has taken over or the page has plainly been moved elsewhere.
868
+ requestAnimationFrame(landIfRefused);
869
+ window.addEventListener("load", landIfRefused);
878
870
 
879
871
 
880
872
  // The reveal rides with this on pages whose content is ready at first paint. A page that renders
@@ -926,7 +918,7 @@ export function personaScroll(options) {
926
918
  let current = cuts[0];
927
919
  for (const c of cuts) if (landingY(c[0]) <= y) current = c;
928
920
  if (navTo) {
929
- if (current === navTo || taken) navTo = null;
921
+ if (current === navTo) navTo = null;
930
922
  else current = navTo;
931
923
  }
932
924
  for (const c of cuts) c[1].classList.toggle("active", c === current);
@@ -969,10 +961,10 @@ export function personaScroll(options) {
969
961
  lastY = y;
970
962
  measure();
971
963
  if (moved) schedule();
972
- // The page has stopped. If it stopped somewhere it was never sent, and nobody has taken over,
973
- // finish the landing — this is where the three-pixel drift above is actually repaired, because
974
- // the drift happens after every earlier attempt has already run.
975
- else landIfUntouched();
964
+ // The page has stopped. If the landing was refused because the document had not sized itself
965
+ // yet, this is the last chance to notice — and it is the ONLY thing left here: the drift this
966
+ // used to repair was the secondary strip moving the page, and the strip is gone.
967
+ else landIfRefused();
976
968
  };
977
969
  const schedule = () => { if (!queued) { queued = true; requestAnimationFrame(frame); } };
978
970
  window.addEventListener("scroll", schedule, { passive: true });
@@ -1010,9 +1002,20 @@ export function personaScroll(options) {
1010
1002
  // The icon answers the tap NOW, not when the scroll lands. `navTo` keeps it answered for the trip.
1011
1003
  navTo = t;
1012
1004
  for (const c of cuts) c[1].classList.toggle("active", c === t);
1013
- // `landed` stays re-armed as a net. If the aim above is ever wrong the old instant repair still
1014
- // catches it — a rare snap is a better failure than a landing left in the wrong place.
1015
- landed = false;
1005
+ // queries: clicking profile throws me back to the kernel · the second cycle · landed re-armed
1006
+ //
1007
+ // ** NOTHING IS RE-ARMED HERE, AND THAT LINE COST AN HOUR. ** This used to set `landed = false`,
1008
+ // which was right while `landed` meant "the landing promise is open": a tap on a cut IS a request
1009
+ // for a landing, so the drift repair was re-armed to protect the new one. That promise is gone —
1010
+ // `landed` now means only "the initial scroll was accepted, stop retrying it" — and re-arming it
1011
+ // told the retry that the page had never landed. The tap scrolls to the profile, the page comes
1012
+ // to rest at 0, the retry reads `scrollY <= 1` with a landing of 376, calls it a refusal and
1013
+ // pulls the person back to the kernel.
1014
+ //
1015
+ // It survived the first cycle by luck: the same click also tripped the `once` listener that sets
1016
+ // `landed = true`, in the later bubble phase, so the flag ended true anyway. The listener is
1017
+ // spent after that, and from the SECOND tap onward the page snapped back every time — which is
1018
+ // exactly how the founder found it: "profile · kernel · profile · kernel … 2. cycle'da başlıyor."
1016
1019
  window.scrollTo({ top: landingY(t[0], t[0].id), behavior: "smooth" });
1017
1020
  setHash(t[0].id);
1018
1021
  });
@@ -1024,7 +1027,7 @@ export function personaScroll(options) {
1024
1027
  if (t) {
1025
1028
  navTo = t;
1026
1029
  for (const c of cuts) c[1].classList.toggle("active", c === t);
1027
- landed = false;
1030
+ // Nor here — same reason as the click above.
1028
1031
  window.scrollTo({ top: landingY(t[0], t[0].id), behavior: "smooth" });
1029
1032
  }
1030
1033
  });