@justai/core 0.28.0 → 0.30.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 +2 -2
  2. package/src/index.js +104 -65
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@justai/core",
3
- "version": "0.28.0",
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.",
3
+ "version": "0.30.0",
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": {
7
7
  "type": "git",
package/src/index.js CHANGED
@@ -693,10 +693,39 @@ export function personaScroll(options) {
693
693
  // row, and a landing offset that was right at load is a kernel under the bar afterwards.
694
694
  const measureShell = () => {
695
695
  if (!toolbar) return;
696
- const app = toolbar.closest(".app") || document.querySelector(".app");
697
- if (!app) return;
698
696
  const h = Math.ceil(toolbar.getBoundingClientRect().height);
699
- if (h > 0) app.style.setProperty("--shell-top", h + "px");
697
+ // ON THE ROOT, because the kernel's `scroll-margin-top` reads it and THE BROWSER reads that when
698
+ // it scrolls to the fragment on its own. Written on `.app` this reached the kernel only when the
699
+ // kernel happened to sit inside one, and a surface where it did not is a surface where the
700
+ // browser's landing and the script's disagree — which is the whole bug this measurement exists
701
+ // to prevent. The root is the one element every consumer is inside.
702
+ if (h <= 0) return;
703
+ document.documentElement.style.setProperty("--shell-top", h + "px");
704
+ // queries: a persona overrides the landing offset · scroll-margin-top 82px in my own component ·
705
+ // the page lands 30px short · duplicate landing offset · my persona has its own #kernel
706
+ // rule · the framework does not reach my css
707
+ //
708
+ // AND ENFORCED, NOT MERELY DECLARED.
709
+ //
710
+ // The framework exists so that a number like this lives in ONE place. It cannot: CSS has no way
711
+ // to refuse an override, and on 2026-08-06 EIGHT personas — both apexes and justai.pro among them
712
+ // — still carried `#kernel { scroll-margin-top: 82px }` from before the shell was shared, a
713
+ // constant that stopped being true the day the secondary title strip was removed. Every one of
714
+ // them lands the page by measurement and is then overruled by the browser's own scroll to the
715
+ // fragment, which reads the persona's stale copy. Thirty pixels, on every bare load.
716
+ //
717
+ // Deleting the eight copies is the honest fix and it is being done. This is what makes the ninth
718
+ // impossible: whoever measures the bar owns what clearing it means, so a section that says it
719
+ // clears the bar clears it by the bar — inline, which outranks any stylesheet. A section that
720
+ // asks for NO offset is left alone; it is not claiming to clear anything.
721
+ for (const [sec] of cuts) {
722
+ const declared = parseFloat(getComputedStyle(sec).scrollMarginTop) || 0;
723
+ if (declared > 0 && Math.abs(declared - h) > 0.5) {
724
+ sec.style.scrollMarginTop = h + "px";
725
+ // Said out loud, because a healed page is a page nobody goes and fixes.
726
+ console.warn("[justai] #" + sec.id + " declares scroll-margin-top " + declared + "px; the shell measures " + h + "px. The landing offset belongs to @justai/ui — delete the local rule.");
727
+ }
728
+ }
700
729
  };
701
730
  measureShell();
702
731
  addEventListener("resize", measureShell, { passive: true });
@@ -810,71 +839,70 @@ export function personaScroll(options) {
810
839
  // queries: the page did not land on the kernel · landing scroll ignored · scrollTo does nothing on
811
840
  // first paint · the page opens at the top sometimes
812
841
  //
813
- // LANDED, OR TRIED AGAIN — because a scroll can be silently refused.
842
+ // LANDED, OR TRIED AGAIN — but only for the one case where a scroll is REFUSED.
814
843
  //
815
844
  // `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.
845
+ // whose sections size themselves a frame later, the landing is CALLED, the browser declines it, and
846
+ // the page opens at the top with nothing anywhere saying so. Measured in this behaviour's own
847
+ // fixture: `scrollTo({top: 548})` followed by a scroll event reading 0. So it is attempted again on
848
+ // the next frame, on `load`, and once more when the page comes to rest.
849
+ //
850
+ // ── WHAT USED TO BE HERE, AND WHY IT IS NOT ────────────────────────────────────────────────
819
851
  //
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:
852
+ // A second, much larger mechanism: a landing that ARRIVED and then DRIFTED, held as a promise until
853
+ // a wheel, a finger or a key "took over", with a tolerance derived from the toolbar's own height.
854
+ // Its trace, recorded in this file:
823
855
  //
824
856
  // scrollTo(468) y = 468 the landing is exact
825
857
  // DOMContentLoaded y = 494 docH +26 — the title strip opened
826
858
  // settled y = 465 docH -26 — and the strip closed again
827
859
  //
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.
860
+ // Every term of it was the secondary strip. It sat above the kernel inside the sticky bar, so each
861
+ // time it opened or closed the browser moved the scroll position to keep the content under it
862
+ // steady, and the page came to rest three pixels short of where the kernel began — close enough to
863
+ // look landed, far enough that the spy answered "profile", which closed the strip, which is what
864
+ // moved it. The founder removed the strip on 2026-08-06, and this went with it: measured after, the
865
+ // page scrolls exactly ONCE to its landing and never moves again, at 402x710 and at 1440x900.
832
866
  //
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.
867
+ // A workaround outlives its cause silently. This one would have kept re-asserting a landing nobody
868
+ // needed, over a drift that can no longer happen, for as long as the file existed.
869
+ // Only the DESTINATION is released when somebody takes over, never the landing: a tap on a cut
870
+ // shows where the page is GOING, and nobody should be shown a destination they have abandoned.
871
+ // The landing itself no longer needs protecting — there is no drift left for it to be protected
872
+ // from, which is the whole point of the note above.
873
+ const takeOver = () => { navTo = null; };
841
874
  for (const ev of ["wheel", "touchmove", "keydown"]) window.addEventListener(ev, takeOver, { passive: true });
875
+
842
876
  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;
877
+
878
+ // A CLICK CLOSES THIS ONE, AND THAT IS THE DIFFERENCE FROM WHAT WAS HERE BEFORE. The old promise
879
+ // deliberately survived clicks, because a tap on a cut is a request for a landing rather than an
880
+ // override — but that promise existed to repair the strip's drift, and it could tell the two apart
881
+ // because it only ever corrected by less than a toolbar's height. This one has no such tolerance:
882
+ // it can only distinguish "the browser refused the scroll" from "the page is somewhere on purpose",
883
+ // and after a tap those look identical. Caught by the row's own spec: clicking Profile rested the
884
+ // page at 0, this read it as a refusal, and pulled it back to the kernel.
885
+ let landed = false;
886
+ const settle = () => { landed = true; };
887
+ for (const ev of ["wheel", "touchmove", "keydown", "click"]) {
888
+ window.addEventListener(ev, settle, { passive: true, once: true });
889
+ }
890
+ // The landing is attempted again when the page comes to rest, because `scrollTo` past a document
891
+ // that has not sized itself yet is a silent no-op — cause 1, and the only cause left here. The
892
+ // drift this used to repair as well was the secondary title strip moving the page after it landed,
893
+ // and the strip is gone; the thirty-pixel glide that looked like drift afterwards was not one
894
+ // either — it was the browser scrolling to the fragment with a number the persona still owned, and
895
+ // that is fixed where the number lives rather than chased from here. A repair that re-asserts
896
+ // against ANY movement fights a page that scrolls itself, which is a workaround growing back.
897
+ const landIfRefused = () => {
898
+ if (landed) return;
899
+ // Anywhere but the very top means the scroll was accepted. A landing that IS the top has nothing
900
+ // to be refused about. Either way this is the last thing it ever does.
901
+ if (window.scrollY > 1 || landingY(sentTo) <= 1) { landed = true; return; }
902
+ land();
867
903
  };
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.
904
+ requestAnimationFrame(landIfRefused);
905
+ window.addEventListener("load", landIfRefused);
878
906
 
879
907
 
880
908
  // The reveal rides with this on pages whose content is ready at first paint. A page that renders
@@ -926,7 +954,7 @@ export function personaScroll(options) {
926
954
  let current = cuts[0];
927
955
  for (const c of cuts) if (landingY(c[0]) <= y) current = c;
928
956
  if (navTo) {
929
- if (current === navTo || taken) navTo = null;
957
+ if (current === navTo) navTo = null;
930
958
  else current = navTo;
931
959
  }
932
960
  for (const c of cuts) c[1].classList.toggle("active", c === current);
@@ -969,10 +997,10 @@ export function personaScroll(options) {
969
997
  lastY = y;
970
998
  measure();
971
999
  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();
1000
+ // The page has stopped. If the landing was refused because the document had not sized itself
1001
+ // yet, this is the last chance to notice — and it is the ONLY thing left here: the drift this
1002
+ // used to repair was the secondary strip moving the page, and the strip is gone.
1003
+ else landIfRefused();
976
1004
  };
977
1005
  const schedule = () => { if (!queued) { queued = true; requestAnimationFrame(frame); } };
978
1006
  window.addEventListener("scroll", schedule, { passive: true });
@@ -1010,9 +1038,20 @@ export function personaScroll(options) {
1010
1038
  // The icon answers the tap NOW, not when the scroll lands. `navTo` keeps it answered for the trip.
1011
1039
  navTo = t;
1012
1040
  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;
1041
+ // queries: clicking profile throws me back to the kernel · the second cycle · landed re-armed
1042
+ //
1043
+ // ** NOTHING IS RE-ARMED HERE, AND THAT LINE COST AN HOUR. ** This used to set `landed = false`,
1044
+ // which was right while `landed` meant "the landing promise is open": a tap on a cut IS a request
1045
+ // for a landing, so the drift repair was re-armed to protect the new one. That promise is gone —
1046
+ // `landed` now means only "the initial scroll was accepted, stop retrying it" — and re-arming it
1047
+ // told the retry that the page had never landed. The tap scrolls to the profile, the page comes
1048
+ // to rest at 0, the retry reads `scrollY <= 1` with a landing of 376, calls it a refusal and
1049
+ // pulls the person back to the kernel.
1050
+ //
1051
+ // It survived the first cycle by luck: the same click also tripped the `once` listener that sets
1052
+ // `landed = true`, in the later bubble phase, so the flag ended true anyway. The listener is
1053
+ // spent after that, and from the SECOND tap onward the page snapped back every time — which is
1054
+ // exactly how the founder found it: "profile · kernel · profile · kernel … 2. cycle'da başlıyor."
1016
1055
  window.scrollTo({ top: landingY(t[0], t[0].id), behavior: "smooth" });
1017
1056
  setHash(t[0].id);
1018
1057
  });
@@ -1024,7 +1063,7 @@ export function personaScroll(options) {
1024
1063
  if (t) {
1025
1064
  navTo = t;
1026
1065
  for (const c of cuts) c[1].classList.toggle("active", c === t);
1027
- landed = false;
1066
+ // Nor here — same reason as the click above.
1028
1067
  window.scrollTo({ top: landingY(t[0], t[0].id), behavior: "smooth" });
1029
1068
  }
1030
1069
  });