@justai/core 0.17.0 → 0.19.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 +74 -9
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@justai/core",
3
- "version": "0.17.0",
3
+ "version": "0.19.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
@@ -526,15 +526,46 @@ export function personaScroll(options) {
526
526
  };
527
527
  const goTo = (sec, behavior) => window.scrollTo({ top: landingY(sec), behavior: behavior });
528
528
 
529
+ // queries: the page rests a few pixels short of the kernel · the hash flips to #profile on its own ·
530
+ // typing the bare host lands on the profile · below.top 4.36 · the landing is not repaired ·
531
+ // it works with #kernel in the URL but not without · unstable landing
532
+ //
533
+ // WHERE THIS PAGE WAS SENT — DECIDED ONCE, AND NEVER READ BACK OUT OF THE ADDRESS BAR.
534
+ //
535
+ // This used to be re-derived from `location.hash` on every attempt, and the spy WRITES that hash.
536
+ // So the repair mechanism took its definition of "where I was supposed to be" from the very thing
537
+ // that goes wrong. Traced frame by frame on a live persona at 1512×900:
538
+ //
539
+ // t=241 scrollTo(333.36) landed exactly, below.top 0.36, #kernel
540
+ // t=258 the title strip begins closing y 331, below.top 2.36
541
+ // t=272 below.top passes 1 the spy answers PROFILE and writes #profile
542
+ // t=313 the strip is closed, the page has drifted y 329, below.top 4.36
543
+ // t=342 the `load` repair runs — and reads #profile as its target, measures itself
544
+ // 329 against the PROFILE's landing, finds it further than any drift could be,
545
+ // and closes the promise for good.
546
+ //
547
+ // Four pixels, and the page is stable in the wrong state: the kernel is 4px under the toolbar, the
548
+ // spy says profile, the strip stays shut, and the address bar says #profile for a person who typed
549
+ // the bare host. It is not a hash bug — with #kernel in the URL the same drift flips the same spy
550
+ // and disarms the same repair. What made it look like one is that the two stable states are
551
+ // reachable by a hair: on a phone the landing happened to rest at below.top −0.27 and stayed right.
552
+ //
553
+ // Captured before the first landing, so the repair keeps asking the only question worth asking:
554
+ // *am I where I was SENT?* One re-assert settles it permanently — measured, four times over, no
555
+ // oscillation.
556
+ const sentTo = (() => {
557
+ const t = cuts.find((c) => "#" + c[0].id === location.hash);
558
+ // A section hash is honoured on load and refresh; anything else — including #kernel and no hash
559
+ // at all — lands on the kernel.
560
+ return t ? t[0] : kernel;
561
+ })();
562
+
529
563
  const land = () => {
530
564
  // presentation mode owns the viewport — a page presenting itself does not scroll out from under
531
565
  // whoever opened it
532
566
  if (document.body.dataset.present) return;
533
- const h = location.hash;
534
- const target = cuts.find((c) => "#" + c[0].id === h);
535
- // A section hash is honoured on load and refresh; anything else — including #kernel and no hash
536
- // at all — lands on the kernel. `instant` overrides the page's own scroll-behavior: smooth.
537
- goTo(target ? target[0] : kernel, "instant");
567
+ // `instant` overrides the page's own scroll-behavior: smooth.
568
+ goTo(sentTo, "instant");
538
569
  };
539
570
  // queries: the page did not land on the kernel · landing scroll ignored · scrollTo does nothing on
540
571
  // first paint · the page opens at the top sometimes
@@ -576,9 +607,7 @@ export function personaScroll(options) {
576
607
  // Kept open until then rather than for a fixed number of tries, because the drift that has to be
577
608
  // repaired happens after load, once the title strip has opened and closed.
578
609
  if (taken || landed) return;
579
- const h = location.hash;
580
- const t = cuts.find((c) => "#" + c[0].id === h);
581
- const want = landingY(t ? t[0] : kernel);
610
+ const want = landingY(sentTo);
582
611
  // A pixel of slack: a browser is free to land a scroll a hair off the number it was handed, and
583
612
  // re-asserting over a rounding error would fight the person for the rest of the page's life.
584
613
  const off = Math.abs(window.scrollY - want);
@@ -598,6 +627,15 @@ export function personaScroll(options) {
598
627
  };
599
628
  requestAnimationFrame(landIfUntouched);
600
629
  window.addEventListener("load", landIfUntouched);
630
+ // queries: the landing is repaired too early · load fires before the strip settles · ResizeObserver
631
+ //
632
+ // AND WHEN THE THING THAT CAUSES THE DRIFT MOVES. rAF and `load` are two moments, and the drift is
633
+ // an event: the toolbar changes height, everything under it shifts, and the page comes to rest
634
+ // somewhere new. On the trace above `load` happened to fire after that; on a faster page it fires
635
+ // before, and then there is nothing left to notice. Watching the toolbar is watching the cause —
636
+ // and it costs nothing after the promise closes, because `landIfUntouched` returns on its first
637
+ // line once somebody has taken over or the page has plainly been moved elsewhere.
638
+
601
639
 
602
640
  // The reveal rides with this on pages whose content is ready at first paint. A page that renders
603
641
  // asynchronously — the vault, the file kernel — holds paint until its own data has arrived and
@@ -1080,10 +1118,37 @@ export async function adoptMark(options) {
1080
1118
  if (!svg) return null;
1081
1119
  if (img) img.remove();
1082
1120
 
1121
+ // queries: the parent icon still has a background · app.zone mark has a black tile in the child
1122
+ // toolbar · the ground was not removed · a path ground · squircle path
1123
+ //
1124
+ // THE GROUND IS WHATEVER IS BEHIND EVERYTHING, AND HERE IT CAN BE MEASURED.
1125
+ //
1126
+ // `toolbarMark` finds a ground by matching a `<rect>` against the viewBox, because at build time a
1127
+ // string is all it has. Fourteen personas draw exactly that rect. The fifteenth is app.zone, whose
1128
+ // mark comes out of a design tool as a 1024 viewBox with the squircle as a hand-drawn `<path>` —
1129
+ // so its tile survived, and /me and /files on app.zone showed a black card in a row of inks while
1130
+ // every other host was correct.
1131
+ //
1132
+ // Chasing that with another string rule would be chasing the sixteenth drawing next. In the
1133
+ // browser the question is geometric and answerable: a ground is the BACKMOST painted shape that
1134
+ // covers the whole viewBox. Measure it and remove it, whatever it was drawn as.
1135
+ //
1136
+ // Only the first shape, and only a shape — a `<g>` may legitimately wrap the entire mark, and
1137
+ // removing that would remove the drawing rather than what is behind it.
1138
+ const vb = (svg.getAttribute("viewBox") || "").split(/[\s,]+/).map(Number);
1139
+ if (vb.length === 4 && vb[2] > 0 && vb[3] > 0) {
1140
+ const back = [...svg.children].find((n) => /^(path|rect|circle|ellipse|polygon|polyline)$/i.test(n.tagName));
1141
+ try {
1142
+ if (back) {
1143
+ const bb = back.getBBox();
1144
+ if (bb.width >= vb[2] * 0.97 && bb.height >= vb[3] * 0.97) back.remove();
1145
+ }
1146
+ } catch { /* not rendered — leave the drawing whole */ }
1147
+ }
1148
+
1083
1149
  // the measurement `fills` would have carried, taken from the drawing itself
1084
1150
  let box = 20;
1085
1151
  try {
1086
- const vb = (svg.getAttribute("viewBox") || "").split(/[\s,]+/).map(Number);
1087
1152
  const bb = svg.getBBox();
1088
1153
  if (vb.length === 4 && vb[2] > 0 && vb[3] > 0 && bb.width > 0) {
1089
1154
  const fills = Math.max(bb.width / vb[2], bb.height / vb[3]);