@justai/core 0.9.2 → 0.10.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.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@justai/core",
3
- "version": "0.9.2",
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.",
3
+ "version": "0.10.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.",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {
7
7
  "type": "git",
package/src/index.d.ts CHANGED
@@ -22,6 +22,12 @@ export declare const CONSENT_COPY: Record<string, { consentText: string; consent
22
22
  /** The consent copy for a language, falling back to English. */
23
23
  export declare function consentCopy(lang: string): { consentText: string; consentAllow: string; consentDecline: string; consentChoice: string };
24
24
 
25
+ /** Cancel and Done in thirteen languages — the ecosystem's chrome words, not a persona's copy. */
26
+ export declare const CHROME_COPY: Record<string, { cancel: string; done: string }>;
27
+
28
+ /** The chrome words for a language, falling back to English. */
29
+ export declare function chromeCopy(lang: string): { cancel: string; done: string };
30
+
25
31
  /** The consent dialog's behaviour — origin-scoped, asked once, with the universal change-your-mind door. */
26
32
  export declare const CONSENT_JS: string;
27
33
 
package/src/index.js CHANGED
@@ -263,6 +263,56 @@ export function consentCopy(lang) {
263
263
  }
264
264
 
265
265
 
266
+ /**
267
+ * queries: the sheet says Cancel in English · Cancel is not translated · Done is not translated ·
268
+ * the picker's cancel stays English in Arabic · sheet chrome language · translate a cut ·
269
+ * who owns the word Cancel · CHROME_COPY · a component's own words
270
+ *
271
+ * THE CHROME WORDS — Cancel and Done, in thirteen languages, said once.
272
+ *
273
+ * The same argument as CONSENT_COPY above, and found the same way: a picker opened on an Arabic page
274
+ * with every word around it in Arabic and `Cancel` in English, sitting in the sheet's own bar.
275
+ *
276
+ * `<Sheet>` had defaulted its Done to the literal "Done" and reasoned, in a comment, that a label is
277
+ * a prop "because the fleet speaks thirteen languages, and a cut that hardcoded the English would be
278
+ * a component making its consumer's copy decisions". The reasoning was inverted. Handing the word to
279
+ * the consumer does not avoid the decision — it makes it THIRTEEN TIMES, in every repo, and the
280
+ * hardcoded English default proved it: the cut was already deciding, and deciding wrong.
281
+ *
282
+ * These are not a persona's copy. `Cancel` is not qr's word or files' word; it is the ecosystem's,
283
+ * the way the back chevron is the ecosystem's shape. Law 1 — a component brings its own ground,
284
+ * style AND text — is what says the cut must carry them.
285
+ *
286
+ * WHY HERE rather than in @justai/cuts: same reason the consent copy is here. Every face reaches
287
+ * core; only the Astro shell reaches cuts.
288
+ *
289
+ * LIFTED FROM `files`, BYTE FOR BYTE, and that is the point rather than an economy. The file kernel
290
+ * mounts INSIDE a host's sheet: the guest draws its own cancel in the body and the host draws one in
291
+ * the bar, and a person looking at one surface must not be shown two different words for the one
292
+ * way out. One word per meaning — the same rule the `nameTaken` string learned the hard way.
293
+ */
294
+ export const CHROME_COPY = {
295
+ "ar": { "cancel": "إلغاء", "done": "تم" },
296
+ "de": { "cancel": "Abbrechen", "done": "Fertig" },
297
+ "en": { "cancel": "Cancel", "done": "Done" },
298
+ "es": { "cancel": "Cancelar", "done": "Listo" },
299
+ "fr": { "cancel": "Annuler", "done": "OK" },
300
+ "hi": { "cancel": "रद्द करें", "done": "हो गया" },
301
+ "it": { "cancel": "Annulla", "done": "Fine" },
302
+ "ja": { "cancel": "キャンセル", "done": "完了" },
303
+ "nl": { "cancel": "Annuleren", "done": "Klaar" },
304
+ "pt": { "cancel": "Cancelar", "done": "Concluído" },
305
+ "ru": { "cancel": "Отмена", "done": "Готово" },
306
+ "tr": { "cancel": "Vazgeç", "done": "Bitti" },
307
+ "zh": { "cancel": "取消", "done": "完成" }
308
+ };
309
+
310
+ /** The chrome words for a language, falling back to English. Never returns undefined. */
311
+ export function chromeCopy(lang) {
312
+ return CHROME_COPY[String(lang || "en").toLowerCase().split("-")[0]] || CHROME_COPY.en;
313
+ }
314
+
315
+
266
316
  /**
267
317
  * queries: consent dialog script · why does the sheet not appear on some pages · consent is asked
268
318
  * per domain not per page · getElementById kernel · the sheet never opened on feed ·
@@ -514,7 +564,7 @@ export function personaScroll(options) {
514
564
  // promise is void forever: nobody is ever yanked back to a section they scrolled away from.
515
565
  let taken = false;
516
566
  let landed = false;
517
- const takeOver = () => { taken = true; };
567
+ const takeOver = () => { taken = true; navTo = null; };
518
568
  // What "reaching for it" IS: a wheel, a finger, a key, a drag on the bar. A CLICK is deliberately
519
569
  // not on this list — pressing a link to a cut is asking for a landing, not overriding one.
520
570
  for (const ev of ["wheel", "touchmove", "keydown"]) window.addEventListener(ev, takeOver, { passive: true });
@@ -565,8 +615,90 @@ export function personaScroll(options) {
565
615
  o.titleFor ||
566
616
  ((id) => (id === "kernel" ? text(".pname") : id === "posts" ? text(".handle") : ""));
567
617
 
618
+ // queries: the title strip jumps · the page jolts after tapping a cut · content shifts while scrolling
619
+ // · toolbar title animation causes a layout shift · landing lands 26px off
620
+ //
621
+ // ONE WRITER FOR THE STRIP, BECAUSE IT CHANGES THE PAGE'S HEIGHT.
622
+ //
623
+ // The strip is in flow, above every section, so opening it pushes the whole page down by its own
624
+ // 26px. That makes it a LAYOUT input to `landingY`, not decoration — and a landing computed before it
625
+ // opens is a landing that is wrong by exactly that much. Which is what a person felt: the smooth
626
+ // scroll ran, the strip opened mid-flight and dragged the content under it, and then `land()` snapped
627
+ // the page straight to the corrected number. Three motions for one tap.
628
+ //
629
+ // So the write is factored out here and can be applied WITHOUT its transition, which lets a
630
+ // navigation settle the height first and then scroll once, to a target that is already true.
631
+ // queries: strip height before it opens · landing computed against the wrong toolbar height
632
+ //
633
+ // THE STRIP'S OPEN HEIGHT, NEEDED BEFORE IT OPENS. A landing for anything below the strip has to be
634
+ // computed against the height the strip is GOING to have, not the one it has. Probed once and
635
+ // synchronously — added, measured and removed inside a single task — so no paint ever shows it.
636
+ let stripH = 0;
637
+ const stripHeight = () => {
638
+ if (stripH) return stripH;
639
+ if (!tbTitle) return 0;
640
+ if (tbTitle.classList.contains("show")) { stripH = tbTitle.offsetHeight; return stripH; }
641
+ const keep = tbTitle.style.transition;
642
+ tbTitle.style.transition = "none";
643
+ tbTitle.classList.add("show");
644
+ stripH = tbTitle.offsetHeight;
645
+ tbTitle.classList.remove("show");
646
+ void tbTitle.offsetHeight;
647
+ tbTitle.style.transition = keep;
648
+ return stripH;
649
+ };
650
+
651
+ // WHERE THE PAGE WILL REST ONCE THE STRIP HAS FINISHED MOVING — so the scroll can be aimed there
652
+ // while the strip is still on its way, and the two motions arrive together.
653
+ //
654
+ // Only what FOLLOWS the strip is affected. The kernel is anchored to `#below`'s top, which the strip
655
+ // cannot move because it lives inside it; the profile sits above `#below` entirely. Asked of the
656
+ // document rather than assumed, so this stays true if the shell is ever rearranged.
657
+ const landingAfterStrip = (sec, id) => {
658
+ const y = landingY(sec);
659
+ if (!tbTitle || sec === kernel) return y;
660
+ const willShow = !!titleFor(id);
661
+ if (willShow === tbTitle.classList.contains("show")) return y;
662
+ const stripIsAbove = sec.compareDocumentPosition(tbTitle) & Node.DOCUMENT_POSITION_PRECEDING;
663
+ if (!stripIsAbove) return y;
664
+ return y + (willShow ? stripHeight() : -stripHeight());
665
+ };
666
+
667
+ const setStrip = (id, animate) => {
668
+ if (!tbTitle) return;
669
+ const t = titleFor(id);
670
+ if (animate) {
671
+ tbTitle.classList.toggle("show", !!t);
672
+ if (t && tbTitleText && tbTitleText.textContent !== t) {
673
+ tbTitleText.classList.add("fade");
674
+ setTimeout(() => { tbTitleText.textContent = t; tbTitleText.classList.remove("fade"); }, 150);
675
+ }
676
+ return;
677
+ }
678
+ // Instant: the height must be final before this function returns, so the caller can measure. The
679
+ // text goes with it — a settled height showing the previous words would be its own small lie.
680
+ tbTitle.style.transition = "none";
681
+ tbTitle.classList.toggle("show", !!t);
682
+ if (t && tbTitleText) { tbTitleText.classList.remove("fade"); tbTitleText.textContent = t; }
683
+ void tbTitle.offsetHeight;
684
+ tbTitle.style.transition = "";
685
+ };
686
+
568
687
  let lastCut = null;
569
688
  let first = true;
689
+ // queries: the toolbar icon changes late · nav icon lags the tap · active state waits for the scroll
690
+ //
691
+ // THE DESTINATION, HELD FOR THE LENGTH OF THE TRIP.
692
+ //
693
+ // The spy is truthful: it reports the section the page is actually over. During a smooth scroll that
694
+ // is the section being LEFT, so the toolbar answered a tap only once the scroll finished — the icon
695
+ // changed a beat late for no reason a person could see. A tap is a request to arrive, the same
696
+ // reading the landing promise already takes, so the toolbar may show where it is going.
697
+ //
698
+ // Held rather than merely set, because setting it optimistically would be undone by the very next
699
+ // spy frame and flicker. Released the moment the page arrives, or the moment somebody takes over —
700
+ // nobody is shown a destination they have already abandoned.
701
+ let navTo = null;
570
702
  // The cut you are on is the last one you have reached — asked in the one vocabulary `landingY`
571
703
  // defines, so this can never answer something a click could not produce. A pixel of tolerance,
572
704
  // because a browser is free to land a smooth scroll a hair short of the number it was given.
@@ -575,26 +707,20 @@ export function personaScroll(options) {
575
707
  const y = window.scrollY + 1;
576
708
  let current = cuts[0];
577
709
  for (const c of cuts) if (landingY(c[0]) <= y) current = c;
710
+ if (navTo) {
711
+ if (current === navTo || taken) navTo = null;
712
+ else current = navTo;
713
+ }
578
714
  for (const c of cuts) c[1].classList.toggle("active", c === current);
579
715
  if (current === lastCut) return;
580
716
  lastCut = current;
581
717
  if (current[0].id && "#" + current[0].id !== location.hash) setHash(current[0].id);
582
718
 
583
- const t = titleFor(current[0].id);
584
- if (first) {
585
- // First paint is not a transition: the page opens at the kernel, so the title is already true
586
- // when it arrives. Animating it in tells a person something changed when nothing did.
587
- first = false;
588
- if (tbTitle) { tbTitle.style.transition = "none"; tbTitle.classList.toggle("show", !!t); }
589
- if (t && tbTitleText) tbTitleText.textContent = t;
590
- if (tbTitle) { void tbTitle.offsetHeight; tbTitle.style.transition = ""; }
591
- } else {
592
- if (tbTitle) tbTitle.classList.toggle("show", !!t);
593
- if (t && tbTitleText && tbTitleText.textContent !== t) {
594
- tbTitleText.classList.add("fade");
595
- setTimeout(() => { tbTitleText.textContent = t; tbTitleText.classList.remove("fade"); }, 150);
596
- }
597
- }
719
+ // First paint is not a transition: the page opens at the kernel, so the title is already true when
720
+ // it arrives. Animating it in tells a person something changed when nothing did.
721
+ const wasFirst = first;
722
+ first = false;
723
+ setStrip(current[0].id, !wasFirst);
598
724
  };
599
725
  // queries: scroll janks while the toolbar updates · scroll handler runs too often · the spy reads a
600
726
  // stale position · the section is right but the toolbar is one behind · scrollend
@@ -659,8 +785,19 @@ export function personaScroll(options) {
659
785
  // becomes current, which drags the scroll ~18px past the mark and tucks the kernel's first line
660
786
  // under the sticky bar. Without this the toolbar's own icon landed flush and the avatar did not,
661
787
  // for no reason a person could see.
788
+ // THE STRIP AND THE SCROLL RUN TOGETHER. The strip keeps its own transition — it is meant to be
789
+ // seen growing, and snapping it open instead just moves the jolt to the moment of the tap. What
790
+ // changes is the AIM: the scroll is sent to where the page will rest once the strip has finished,
791
+ // so the growing band and the moving page arrive at the same place at the same time and nothing
792
+ // has to be corrected afterwards.
793
+ // The icon answers the tap NOW, not when the scroll lands. `navTo` keeps it answered for the trip.
794
+ navTo = t;
795
+ for (const c of cuts) c[1].classList.toggle("active", c === t);
796
+ setStrip(t[0].id, true);
797
+ // `landed` stays re-armed as a net. If the aim above is ever wrong the old instant repair still
798
+ // catches it — a rare snap is a better failure than a landing left in the wrong place.
662
799
  landed = false;
663
- goTo(t[0], "smooth");
800
+ window.scrollTo({ top: landingAfterStrip(t[0], t[0].id), behavior: "smooth" });
664
801
  setHash(t[0].id);
665
802
  });
666
803
 
@@ -668,7 +805,13 @@ export function personaScroll(options) {
668
805
  // `setHash` uses replaceState and fires nothing, so this can only be somebody else's navigation.
669
806
  window.addEventListener("hashchange", () => {
670
807
  const t = cuts.find((c) => "#" + c[0].id === location.hash);
671
- if (t) { landed = false; goTo(t[0], "smooth"); }
808
+ if (t) {
809
+ navTo = t;
810
+ for (const c of cuts) c[1].classList.toggle("active", c === t);
811
+ setStrip(t[0].id, true);
812
+ landed = false;
813
+ window.scrollTo({ top: landingAfterStrip(t[0], t[0].id), behavior: "smooth" });
814
+ }
672
815
  });
673
816
  }
674
817