@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.
- package/package.json +1 -1
- package/src/index.js +80 -171
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@justai/core",
|
|
3
|
-
"version": "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 ·
|
|
686
|
-
//
|
|
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
|
-
//
|
|
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
|
-
//
|
|
692
|
-
//
|
|
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
|
-
//
|
|
695
|
-
//
|
|
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
|
|
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 —
|
|
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
|
-
//
|
|
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
|
-
//
|
|
852
|
-
//
|
|
853
|
-
//
|
|
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
|
-
//
|
|
860
|
-
// browser
|
|
861
|
-
// pixels short of where the kernel
|
|
862
|
-
//
|
|
863
|
-
//
|
|
864
|
-
//
|
|
865
|
-
//
|
|
866
|
-
//
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
//
|
|
871
|
-
//
|
|
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
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
//
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
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(
|
|
900
|
-
window.addEventListener("load",
|
|
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
|
|
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
|
|
1065
|
-
//
|
|
1066
|
-
// the
|
|
1067
|
-
else
|
|
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
|
-
|
|
1106
|
-
//
|
|
1107
|
-
//
|
|
1108
|
-
landed
|
|
1109
|
-
|
|
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
|
-
|
|
1121
|
-
|
|
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
|
}
|