@justai/core 0.27.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 +80 -171
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@justai/core",
3
- "version": "0.27.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
@@ -668,11 +668,6 @@ export function personaScroll(options) {
668
668
  if (!below || !kernel) return;
669
669
 
670
670
  const toolbar = typeof o.toolbar === "string" ? document.querySelector(o.toolbar) : o.toolbar || document.querySelector(".toolbar");
671
- const tbTitle = el(o.title || "tbTitle");
672
- const tbTitleText =
673
- (typeof o.titleText === "string" ? document.getElementById(o.titleText) : o.titleText) ||
674
- document.getElementById("tbTitleText") ||
675
- (tbTitle && tbTitle.querySelector(".tb-title-text"));
676
671
 
677
672
  // A cut is a section AND the nav that points at it; anything missing either half is simply not one.
678
673
  // That is how a page with extra toolbar links — /me's vault, /files' host link — needs no
@@ -682,51 +677,25 @@ export function personaScroll(options) {
682
677
  .filter((c) => c[0] && c[1]);
683
678
  if (!cuts.length) return;
684
679
 
685
- // queries: --shell-top · the kernel is 26px short · the game frame does not reach the fold ·
686
- // a strip of posts shows above the fold · opening at #kernel is different from #profile ·
687
- // the toolbar changes height · title strip · the layout depends on when it was measured
680
+ // queries: --shell-top · what does the shell take above the kernel · landing offset ·
681
+ // the kernel is under the toolbar · toolbar height
688
682
  //
689
- // ── NEVER SAMPLE AN ANIMATION AND CALL IT A LAYOUT ─────────────────────────────────────────
683
+ // WHAT THE SHELL TAKES ABOVE THE KERNEL. One row, one height — the founder removed the secondary
684
+ // strip on 2026-08-06 and with it the whole reason this number was ever hard: nothing above the
685
+ // kernel changes size any more, so there is no animation to avoid sampling and no "which state?"
686
+ // to answer. It is the bar, measured.
690
687
  //
691
- // `--shell-top` is what the shell takes above the kernel, and everything downstream reads it: the
692
- // landing offset, an app kernel's minimum height, a game kernel's exact one.
688
+ // CEIL, because a bar under iOS Dynamic Type is not an integer — this file has recorded one at
689
+ // 82.3 — and rounding down leaves half a CSS pixel of the next section above the fold on a kernel
690
+ // whose height is exact.
693
691
  //
694
- // It was the literal `82` for a long time and that was stable and slightly wrong. Reading the
695
- // toolbar's height instead made it exact and UNSTABLE, which is far worse: the row carries a title
696
- // strip that opens and closes over 0.35s, so its height is anywhere in a 26px range depending on
697
- // the instant somebody looked. Measured on tpl-sunshine at 1864x999, the same persona, same build:
698
- //
699
- // opened at #profile strip shut when measured shell-top 80 frame 919 reaches the fold
700
- // opened at #kernel strip open when measured shell-top 106 frame 893 33px SHORT
701
- //
702
- // and the second is what a visitor gets, because a game persona lands on its kernel. Thirty-three
703
- // pixels of the next section showing above the fold, and the "correct" case was correct by
704
- // coincidence — a shut row plus a gutter happened to equal an open one.
705
- //
706
- // THE FIX IS NOT A BETTER MOMENT TO MEASURE, IT IS NOT MEASURING THE MOVING PART. The row minus the
707
- // strip is the row, and it is the same number at every frame of the transition; the strip's OPEN
708
- // height is `--tb-strip`, which the Toolbar cut declares beside the rule that uses it. Their sum is
709
- // what the bar is whenever anybody is looking at the kernel — which is the only time this number
710
- // decides anything.
711
- //
712
- // AND NO GUTTER IS ADDED. The frame is the active view, so it begins where the shell ends; the air
713
- // an app keeps under the bar is its own padding, and adding a gutter here would spend it twice.
714
- //
715
- // Re-measured on resize because a rotation, a narrowing past 640 and a reader's text size all
716
- // change the ROW — none of which is the animation this is written to ignore.
692
+ // Re-measured on resize: a rotation, a narrowing past 640 and a reader's text size all change the
693
+ // row, and a landing offset that was right at load is a kernel under the bar afterwards.
717
694
  const measureShell = () => {
718
695
  if (!toolbar) return;
719
696
  const app = toolbar.closest(".app") || document.querySelector(".app");
720
697
  if (!app) return;
721
- const strip = tbTitle ? tbTitle.getBoundingClientRect().height : 0;
722
- const open = parseFloat(getComputedStyle(toolbar).getPropertyValue("--tb-strip")) || 26;
723
- // CEIL, NOT ROUND, AND IT IS LOAD-BEARING NOW: `--shell-top` is the slot's min-height as well as
724
- // the subtrahend, so it must never be LESS than the bar's tallest state or the slot starts
725
- // following the bar again and the 26px returns as a fraction. A bar under Dynamic Type is not an
726
- // integer — this file has already recorded one at 82.3 — and rounding down is half a CSS pixel,
727
- // one and a half device pixels at DPR 3, of permanent error in a law judged by eye against a
728
- // drawn rectangle.
729
- const h = Math.ceil(toolbar.getBoundingClientRect().height - strip + open);
698
+ const h = Math.ceil(toolbar.getBoundingClientRect().height);
730
699
  if (h > 0) app.style.setProperty("--shell-top", h + "px");
731
700
  };
732
701
  measureShell();
@@ -841,71 +810,63 @@ export function personaScroll(options) {
841
810
  // queries: the page did not land on the kernel · landing scroll ignored · scrollTo does nothing on
842
811
  // first paint · the page opens at the top sometimes
843
812
  //
844
- // 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.
845
814
  //
846
815
  // `scrollTo` past the current document height is a no-op, and it does not report one: on a page
847
- // whose sections size themselves a frame later, the landing is CALLED, the browser declines it,
848
- // and the page opens at the top with nothing anywhere saying so. Measured in this behaviour's own
849
- // 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.
820
+ //
821
+ // ── WHAT USED TO BE HERE, AND WHY IT IS NOT ────────────────────────────────────────────────
850
822
  //
851
- // So it is attempted again on the next frame and on `load`. It used to retry only while the page
852
- // was still at the VERY TOP — a landing that did nothing — and that missed the case that actually
853
- // bit: a landing that ARRIVED and then DRIFTED. Traced in the fixture:
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:
854
826
  //
855
827
  // scrollTo(468) y = 468 the landing is exact
856
828
  // DOMContentLoaded y = 494 docH +26 — the title strip opened
857
829
  // settled y = 465 docH -26 — and the strip closed again
858
830
  //
859
- // The strip lives inside the sticky toolbar, ABOVE the kernel, so every time it opens or closes the
860
- // browser moves the scroll position to keep the content under it steady. The page came to rest three
861
- // pixels short of where the kernel begins — close enough to look landed, far enough that the spy
862
- // correctly answered "profile", which closed the strip, which is what moved it there.
863
- //
864
- // A LANDING IS A PROMISE, AND IT IS KEPT UNTIL THE PERSON TAKES OVER. Not "until the page moves" —
865
- // the page moves on its own here — but until somebody actually reaches for it. Once they have, the
866
- // promise is void forever: nobody is ever yanked back to a section they scrolled away from.
867
- let taken = false;
868
- let landed = false;
869
- const takeOver = () => { taken = true; navTo = null; };
870
- // What "reaching for it" IS: a wheel, a finger, a key, a drag on the bar. A CLICK is deliberately
871
- // not on this list — pressing a link to a cut is asking for a landing, not overriding one.
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.
837
+ //
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; };
872
845
  for (const ev of ["wheel", "touchmove", "keydown"]) window.addEventListener(ev, takeOver, { passive: true });
846
+
873
847
  land();
874
- const landIfUntouched = () => {
875
- // THE PROMISE BELONGS TO THE ARRIVAL, NOT TO THE PAGE'S WHOLE LIFE. It is released the first time
876
- // the page is found resting where it was sent — after that this never runs again, so a persona's
877
- // own scrolling, a deep link handled later, or anything else that moves the page is never undone.
878
- // Kept open until then rather than for a fixed number of tries, because the drift that has to be
879
- // repaired happens after load, once the title strip has opened and closed.
880
- if (taken || landed) return;
881
- const want = landingY(sentTo);
882
- // A pixel of slack: a browser is free to land a scroll a hair off the number it was handed, and
883
- // re-asserting over a rounding error would fight the person for the rest of the page's life.
884
- const off = Math.abs(window.scrollY - want);
885
- // HOW FAR OFF IS STILL "THE LANDING DRIFTED", and how far is somebody else moving the page? The
886
- // drift has a known size: it is caused by chrome above the kernel changing height, so it can never
887
- // exceed that chrome. Anything larger is a deliberate scroll — a spec, a deep link handled later,
888
- // a persona's own code — and is left alone. Derived from the toolbar rather than chosen, so it
889
- // stays true if the bar ever changes shape.
890
- const drift = toolbar ? toolbar.getBoundingClientRect().height : 0;
891
- // Arriving does NOT end the promise. The page can be nudged again long after it settled — a
892
- // consent sheet closing moved qr by 3px, and released early that is enough to hand the section
893
- // back to the profile while the kernel fills the screen. The promise ends when somebody takes
894
- // over, or when the page is moved somewhere it was plainly never sent.
895
- if (off <= 1) return;
896
- if (off <= drift) land();
897
- 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();
898
867
  };
899
- requestAnimationFrame(landIfUntouched);
900
- window.addEventListener("load", landIfUntouched);
901
- // queries: the landing is repaired too early · load fires before the strip settles · ResizeObserver
902
- //
903
- // AND WHEN THE THING THAT CAUSES THE DRIFT MOVES. rAF and `load` are two moments, and the drift is
904
- // an event: the toolbar changes height, everything under it shifts, and the page comes to rest
905
- // somewhere new. On the trace above `load` happened to fire after that; on a faster page it fires
906
- // before, and then there is nothing left to notice. Watching the toolbar is watching the cause —
907
- // and it costs nothing after the promise closes, because `landIfUntouched` returns on its first
908
- // line once somebody has taken over or the page has plainly been moved elsewhere.
868
+ requestAnimationFrame(landIfRefused);
869
+ window.addEventListener("load", landIfRefused);
909
870
 
910
871
 
911
872
  // The reveal rides with this on pages whose content is ready at first paint. A page that renders
@@ -920,10 +881,6 @@ export function personaScroll(options) {
920
881
  const text = (sel) => (document.querySelector(sel)?.textContent || "").trim();
921
882
  // Kernel names the persona, Posts names its handle, Profile stays collapsed — its big header IS
922
883
  // the title, and repeating it in the bar above would say the same thing twice.
923
- const titleFor =
924
- o.titleFor ||
925
- ((id) => (id === "kernel" ? text(".pname") : id === "posts" ? text(".handle") : ""));
926
-
927
884
  // queries: the title strip jumps · the page jolts after tapping a cut · content shifts while scrolling
928
885
  // · toolbar title animation causes a layout shift · landing lands 26px off
929
886
  //
@@ -937,62 +894,6 @@ export function personaScroll(options) {
937
894
  //
938
895
  // So the write is factored out here and can be applied WITHOUT its transition, which lets a
939
896
  // navigation settle the height first and then scroll once, to a target that is already true.
940
- // queries: strip height before it opens · landing computed against the wrong toolbar height
941
- //
942
- // THE STRIP'S OPEN HEIGHT, NEEDED BEFORE IT OPENS. A landing for anything below the strip has to be
943
- // computed against the height the strip is GOING to have, not the one it has. Probed once and
944
- // synchronously — added, measured and removed inside a single task — so no paint ever shows it.
945
- let stripH = 0;
946
- const stripHeight = () => {
947
- if (stripH) return stripH;
948
- if (!tbTitle) return 0;
949
- if (tbTitle.classList.contains("show")) { stripH = tbTitle.offsetHeight; return stripH; }
950
- const keep = tbTitle.style.transition;
951
- tbTitle.style.transition = "none";
952
- tbTitle.classList.add("show");
953
- stripH = tbTitle.offsetHeight;
954
- tbTitle.classList.remove("show");
955
- void tbTitle.offsetHeight;
956
- tbTitle.style.transition = keep;
957
- return stripH;
958
- };
959
-
960
- // WHERE THE PAGE WILL REST ONCE THE STRIP HAS FINISHED MOVING — so the scroll can be aimed there
961
- // while the strip is still on its way, and the two motions arrive together.
962
- //
963
- // Only what FOLLOWS the strip is affected. The kernel is anchored to `#below`'s top, which the strip
964
- // cannot move because it lives inside it; the profile sits above `#below` entirely. Asked of the
965
- // document rather than assumed, so this stays true if the shell is ever rearranged.
966
- const landingAfterStrip = (sec, id) => {
967
- const y = landingY(sec);
968
- if (!tbTitle || sec === kernel) return y;
969
- const willShow = !!titleFor(id);
970
- if (willShow === tbTitle.classList.contains("show")) return y;
971
- const stripIsAbove = sec.compareDocumentPosition(tbTitle) & Node.DOCUMENT_POSITION_PRECEDING;
972
- if (!stripIsAbove) return y;
973
- return y + (willShow ? stripHeight() : -stripHeight());
974
- };
975
-
976
- const setStrip = (id, animate) => {
977
- if (!tbTitle) return;
978
- const t = titleFor(id);
979
- if (animate) {
980
- tbTitle.classList.toggle("show", !!t);
981
- if (t && tbTitleText && tbTitleText.textContent !== t) {
982
- tbTitleText.classList.add("fade");
983
- setTimeout(() => { tbTitleText.textContent = t; tbTitleText.classList.remove("fade"); }, 150);
984
- }
985
- return;
986
- }
987
- // Instant: the height must be final before this function returns, so the caller can measure. The
988
- // text goes with it — a settled height showing the previous words would be its own small lie.
989
- tbTitle.style.transition = "none";
990
- tbTitle.classList.toggle("show", !!t);
991
- if (t && tbTitleText) { tbTitleText.classList.remove("fade"); tbTitleText.textContent = t; }
992
- void tbTitle.offsetHeight;
993
- tbTitle.style.transition = "";
994
- };
995
-
996
897
  let lastCut = null;
997
898
  let first = true;
998
899
  // queries: the toolbar icon changes late · nav icon lags the tap · active state waits for the scroll
@@ -1017,7 +918,7 @@ export function personaScroll(options) {
1017
918
  let current = cuts[0];
1018
919
  for (const c of cuts) if (landingY(c[0]) <= y) current = c;
1019
920
  if (navTo) {
1020
- if (current === navTo || taken) navTo = null;
921
+ if (current === navTo) navTo = null;
1021
922
  else current = navTo;
1022
923
  }
1023
924
  for (const c of cuts) c[1].classList.toggle("active", c === current);
@@ -1029,7 +930,6 @@ export function personaScroll(options) {
1029
930
  // it arrives. Animating it in tells a person something changed when nothing did.
1030
931
  const wasFirst = first;
1031
932
  first = false;
1032
- setStrip(current[0].id, !wasFirst);
1033
933
  };
1034
934
  // queries: scroll janks while the toolbar updates · scroll handler runs too often · the spy reads a
1035
935
  // stale position · the section is right but the toolbar is one behind · scrollend
@@ -1061,10 +961,10 @@ export function personaScroll(options) {
1061
961
  lastY = y;
1062
962
  measure();
1063
963
  if (moved) schedule();
1064
- // The page has stopped. If it stopped somewhere it was never sent, and nobody has taken over,
1065
- // finish the landing — this is where the three-pixel drift above is actually repaired, because
1066
- // the drift happens after every earlier attempt has already run.
1067
- 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();
1068
968
  };
1069
969
  const schedule = () => { if (!queued) { queued = true; requestAnimationFrame(frame); } };
1070
970
  window.addEventListener("scroll", schedule, { passive: true });
@@ -1102,11 +1002,21 @@ export function personaScroll(options) {
1102
1002
  // The icon answers the tap NOW, not when the scroll lands. `navTo` keeps it answered for the trip.
1103
1003
  navTo = t;
1104
1004
  for (const c of cuts) c[1].classList.toggle("active", c === t);
1105
- setStrip(t[0].id, true);
1106
- // `landed` stays re-armed as a net. If the aim above is ever wrong the old instant repair still
1107
- // catches it — a rare snap is a better failure than a landing left in the wrong place.
1108
- landed = false;
1109
- window.scrollTo({ top: landingAfterStrip(t[0], t[0].id), behavior: "smooth" });
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."
1019
+ window.scrollTo({ top: landingY(t[0], t[0].id), behavior: "smooth" });
1110
1020
  setHash(t[0].id);
1111
1021
  });
1112
1022
 
@@ -1117,9 +1027,8 @@ export function personaScroll(options) {
1117
1027
  if (t) {
1118
1028
  navTo = t;
1119
1029
  for (const c of cuts) c[1].classList.toggle("active", c === t);
1120
- setStrip(t[0].id, true);
1121
- landed = false;
1122
- window.scrollTo({ top: landingAfterStrip(t[0], t[0].id), behavior: "smooth" });
1030
+ // Nor here — same reason as the click above.
1031
+ window.scrollTo({ top: landingY(t[0], t[0].id), behavior: "smooth" });
1123
1032
  }
1124
1033
  });
1125
1034
  }