@justai/core 0.30.0 → 0.33.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 +155 -29
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@justai/core",
3
- "version": "0.30.0",
3
+ "version": "0.33.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
@@ -668,6 +668,11 @@ 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"));
671
676
 
672
677
  // A cut is a section AND the nav that points at it; anything missing either half is simply not one.
673
678
  // That is how a page with extra toolbar links — /me's vault, /files' host link — needs no
@@ -677,23 +682,52 @@ export function personaScroll(options) {
677
682
  .filter((c) => c[0] && c[1]);
678
683
  if (!cuts.length) return;
679
684
 
680
- // queries: --shell-top · what does the shell take above the kernel · landing offset ·
681
- // the kernel is under the toolbar · toolbar height
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
682
688
  //
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.
689
+ // ── NEVER SAMPLE AN ANIMATION AND CALL IT A LAYOUT ─────────────────────────────────────────
687
690
  //
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.
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.
691
693
  //
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.
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.
694
717
  const measureShell = () => {
695
718
  if (!toolbar) return;
696
- const h = Math.ceil(toolbar.getBoundingClientRect().height);
719
+ // THE BAR'S EXPANDED HEIGHT, WITHOUT WAITING FOR OR RACING THE STRIP'S 0.35s. The row is the bar
720
+ // minus whatever the strip currently is — the same number at every frame of the transition — and
721
+ // the bar-to-be is that row plus the strip's declared open height. Nothing samples the animation,
722
+ // so nothing depends on when it was sampled.
723
+ //
724
+ // CEIL, NOT ROUND, AND LOAD-BEARING: this is the slot's reserved box as well as the landing
725
+ // offset, so it must never be LESS than the bar's tallest state or the slot starts following the
726
+ // bar again and the 26px returns as a fraction. A bar under Dynamic Type is not an integer —
727
+ // 82.3 is recorded in this file — and rounding down is half a CSS pixel of permanent error.
728
+ const strip = tbTitle ? tbTitle.getBoundingClientRect().height : 0;
729
+ const open = parseFloat(getComputedStyle(toolbar).getPropertyValue("--tb-strip")) || 26;
730
+ const h = Math.ceil(toolbar.getBoundingClientRect().height - strip + open);
697
731
  // ON THE ROOT, because the kernel's `scroll-margin-top` reads it and THE BROWSER reads that when
698
732
  // it scrolls to the fragment on its own. Written on `.app` this reached the kernel only when the
699
733
  // kernel happened to sit inside one, and a surface where it did not is a surface where the
@@ -715,17 +749,31 @@ export function personaScroll(options) {
715
749
  // fragment, which reads the persona's stale copy. Thirty pixels, on every bare load.
716
750
  //
717
751
  // 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) {
752
+ // impossible: whoever measures the bar owns what clearing it means, so EVERY CUT BELOW THE FIRST
753
+ // clears it by exactly the bar — written inline, which outranks any stylesheet.
754
+ //
755
+ // NOT "every cut that already declares an offset". That was the first version of this rule and it
756
+ // was too polite by one case: it read a zero as *"this section is not claiming to clear
757
+ // anything"*, and a persona that never loads `@justai/ui`'s base.css at all has exactly that
758
+ // zero. Measured on pin.games the moment its local `82px` was deleted — the offset fell to 0, the
759
+ // browser's own scroll put the kernel's top at the viewport top, and the persona's first line sat
760
+ // UNDER the sticky bar. Not landing short any more; landing under. Same bug, other direction.
761
+ //
762
+ // So it does not matter what the persona's CSS says or whether it loaded ours: a sticky bar is
763
+ // above every cut but the first, and the first is the top of the page with nothing to clear.
764
+ // The warning is only for a persona that declared a DIFFERENT number — that one has a stale rule
765
+ // to go and delete. A zero is just a surface that never had the stylesheet, and healing it
766
+ // silently is the whole point of the framework owning this.
767
+ cuts.forEach(([sec], i) => {
768
+ if (i === 0) return;
722
769
  const declared = parseFloat(getComputedStyle(sec).scrollMarginTop) || 0;
723
- if (declared > 0 && Math.abs(declared - h) > 0.5) {
724
- sec.style.scrollMarginTop = h + "px";
770
+ if (Math.abs(declared - h) <= 0.5) return;
771
+ sec.style.scrollMarginTop = h + "px";
772
+ if (declared > 0) {
725
773
  // Said out loud, because a healed page is a page nobody goes and fixes.
726
774
  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
775
  }
728
- }
776
+ });
729
777
  };
730
778
  measureShell();
731
779
  addEventListener("resize", measureShell, { passive: true });
@@ -917,19 +965,50 @@ export function personaScroll(options) {
917
965
  const text = (sel) => (document.querySelector(sel)?.textContent || "").trim();
918
966
  // Kernel names the persona, Posts names its handle, Profile stays collapsed — its big header IS
919
967
  // the title, and repeating it in the bar above would say the same thing twice.
920
- // queries: the title strip jumps · the page jolts after tapping a cut · content shifts while scrolling
921
- // · toolbar title animation causes a layout shift · landing lands 26px off
968
+ const titleFor =
969
+ o.titleFor ||
970
+ ((id) => (id === "kernel" ? text(".pname") : id === "posts" ? text(".handle") : ""));
971
+
972
+ // queries: the title strip jumps · the page jolts after tapping a cut · content shifts while
973
+ // scrolling · toolbar title animation causes a layout shift · landing lands 26px off ·
974
+ // landingAfterStrip · why is there no strip compensation any more · tb-slot min-height
975
+ //
976
+ // ── THERE IS NOTHING LEFT TO COMPENSATE FOR, AND THAT IS THE WHOLE POINT OF THE SLOT ──────────
922
977
  //
923
- // ONE WRITER FOR THE STRIP, BECAUSE IT CHANGES THE PAGE'S HEIGHT.
978
+ // Two functions used to live here: one probed the strip's open height before it opened, the other
979
+ // aimed a scroll at where the page WOULD rest once the strip had finished moving. They existed
980
+ // because the strip was in flow above every section, so opening it pushed the whole page down by
981
+ // its own 26px and a landing computed before it opened was wrong by exactly that much. A person
982
+ // felt it as three motions for one tap.
924
983
  //
925
- // The strip is in flow, above every section, so opening it pushes the whole page down by its own
926
- // 26px. That makes it a LAYOUT input to `landingY`, not decoration — and a landing computed before it
927
- // opens is a landing that is wrong by exactly that much. Which is what a person felt: the smooth
928
- // scroll ran, the strip opened mid-flight and dragged the content under it, and then `land()` snapped
929
- // the page straight to the corrected number. Three motions for one tap.
984
+ // `.tb-slot` ends that at the source: the SLOT is what flow sees and its box is `--shell-top`, a
985
+ // constant; the BAR is static inside it and may be any height it likes. Opening the strip moves
986
+ // nothing outside the slot, so a landing computed before it opens is simply correct.
930
987
  //
931
- // So the write is factored out here and can be applied WITHOUT its transition, which lets a
932
- // navigation settle the height first and then scroll once, to a target that is already true.
988
+ // The compensation is therefore not merely dead — it would be WRONG, adding a strip's height to
989
+ // the posts landing for a shift that no longer happens. When the strip came back on 2026-08-06 the
990
+ // reserved box came back with it FOR EVERY KIND, not only for games, and these two went for good.
991
+ // If they are ever missed, the thing to check is whether the slot still reserves its box.
992
+ const setStrip = (id, animate) => {
993
+ if (!tbTitle) return;
994
+ const t = titleFor(id);
995
+ if (animate) {
996
+ tbTitle.classList.toggle("show", !!t);
997
+ if (t && tbTitleText && tbTitleText.textContent !== t) {
998
+ tbTitleText.classList.add("fade");
999
+ setTimeout(() => { tbTitleText.textContent = t; tbTitleText.classList.remove("fade"); }, 150);
1000
+ }
1001
+ return;
1002
+ }
1003
+ // Instant: the height must be final before this function returns, so the caller can measure. The
1004
+ // text goes with it — a settled height showing the previous words would be its own small lie.
1005
+ tbTitle.style.transition = "none";
1006
+ tbTitle.classList.toggle("show", !!t);
1007
+ if (t && tbTitleText) { tbTitleText.classList.remove("fade"); tbTitleText.textContent = t; }
1008
+ void tbTitle.offsetHeight;
1009
+ tbTitle.style.transition = "";
1010
+ };
1011
+
933
1012
  let lastCut = null;
934
1013
  let first = true;
935
1014
  // queries: the toolbar icon changes late · nav icon lags the tap · active state waits for the scroll
@@ -966,6 +1045,7 @@ export function personaScroll(options) {
966
1045
  // it arrives. Animating it in tells a person something changed when nothing did.
967
1046
  const wasFirst = first;
968
1047
  first = false;
1048
+ setStrip(current[0].id, !wasFirst);
969
1049
  };
970
1050
  // queries: scroll janks while the toolbar updates · scroll handler runs too often · the spy reads a
971
1051
  // stale position · the section is right but the toolbar is one behind · scrollend
@@ -1052,6 +1132,10 @@ export function personaScroll(options) {
1052
1132
  // `landed = true`, in the later bubble phase, so the flag ended true anyway. The listener is
1053
1133
  // spent after that, and from the SECOND tap onward the page snapped back every time — which is
1054
1134
  // exactly how the founder found it: "profile · kernel · profile · kernel … 2. cycle'da başlıyor."
1135
+ //
1136
+ // The strip still follows the tap — it is the row saying which cut you are on, which is the one
1137
+ // thing about it the founder said he could not give up.
1138
+ setStrip(t[0].id, true);
1055
1139
  window.scrollTo({ top: landingY(t[0], t[0].id), behavior: "smooth" });
1056
1140
  setHash(t[0].id);
1057
1141
  });
@@ -1064,6 +1148,7 @@ export function personaScroll(options) {
1064
1148
  navTo = t;
1065
1149
  for (const c of cuts) c[1].classList.toggle("active", c === t);
1066
1150
  // Nor here — same reason as the click above.
1151
+ setStrip(t[0].id, true);
1067
1152
  window.scrollTo({ top: landingY(t[0], t[0].id), behavior: "smooth" });
1068
1153
  }
1069
1154
  });
@@ -1417,6 +1502,47 @@ export async function adoptMark(options) {
1417
1502
  if (fills > 0.05 && fills < 1) box = 20 / fills;
1418
1503
  }
1419
1504
  } catch { /* not rendered — the row's default stands */ }
1505
+
1506
+ // queries: the parent icon is bigger than the other icons · the parent mark overflows the row ·
1507
+ // navParent looks shifted · the child toolbar mark is twice the size · adoptMark overflow
1508
+ //
1509
+ // A CEILING, BECAUSE NORMALISING INK CANNOT BE ALLOWED TO BREAK THE ROW.
1510
+ //
1511
+ // The scale above equalises INK: whatever the drawing, its ink lands at 20px, so a mark with
1512
+ // generous padding is scaled up until it reads like its neighbours. That is right, and it is
1513
+ // unbounded — the more padding a drawing carries, the larger the box it asks for, with nothing
1514
+ // stopping it at the size of the slot it lives in.
1515
+ //
1516
+ // Measured on the fleet, 2026-08-06, after the founder reported the parent mark looking shifted on
1517
+ // pin.games' children and nowhere else:
1518
+ //
1519
+ // app.zone/icon.svg ink fills 73% → 27.3px, inside a 38×36 slot
1520
+ // pin.games/icon.svg ink fills 37% → 53.8px, half again the slot's height
1521
+ //
1522
+ // pin.games draws its glyph with an app icon's padding — an iOS tile, correct on a home screen and
1523
+ // twice the fleet's inset. Nothing was wrong with the file and nothing was wrong with the scale;
1524
+ // what was missing is that a row icon belongs to the ROW, so the row's box is the limit. Clamped
1525
+ // rather than skipped, so the mark still grows as far as it usefully can.
1526
+ //
1527
+ // The remaining half is the persona's: a mark clamped to the slot reads smaller than its
1528
+ // neighbours, because the drawing genuinely carries less ink. That is a drawing to redraw, not a
1529
+ // number to fudge here.
1530
+ //
1531
+ // THE CEILING IS THE SLOT AND NOT A PIXEL LESS, because the founder asked the right question —
1532
+ // *"sadece pin games için böyle oldu, şimdi diğer tüm personalar bundan olumsuz etkilenir mi?"* —
1533
+ // and the first answer was yes. A ceiling of `slot − 4` was measured against all twenty-one live
1534
+ // personas and would have shrunk THIRTEEN of them, from 33–35px down to 32, none of which was
1535
+ // overflowing anything. Computed across the fleet, 2026-08-06:
1536
+ //
1537
+ // under the slot, untouched app.zone 27.3 · justai.pro 29.4 · lendcam 30.8 · qr 34.2 ·
1538
+ // time 34.5 · sudoku 34.6 · whatismyip 35.7 · fourteen more
1539
+ // over it, clamped pin.games 53.8 · auth 38.5 · password-generator 38.5
1540
+ //
1541
+ // A rail that changes anything already inside its limit is not a rail, it is a redesign — so the
1542
+ // limit is exactly the box the mark has to live in, and a mark that fits is left alone to the pixel.
1543
+ const ceiling = Math.max(20, el.clientHeight || 36);
1544
+ if (box > ceiling) box = ceiling;
1545
+
1420
1546
  svg.style.width = box.toFixed(2) + "px";
1421
1547
  svg.style.height = box.toFixed(2) + "px";
1422
1548
  return svg;