@justai/core 0.10.0 → 0.12.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 +2 -2
- package/src/index.d.ts +36 -0
- package/src/index.js +66 -0
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@justai/core",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "The framework-free heart of the persona shell
|
|
3
|
+
"version": "0.12.0",
|
|
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": {
|
|
7
7
|
"type": "git",
|
package/src/index.d.ts
CHANGED
|
@@ -74,3 +74,39 @@ export declare function personaScroll(options?: PersonaScrollOptions): void;
|
|
|
74
74
|
* Generated from the function itself, so there is never a second implementation to keep in step.
|
|
75
75
|
*/
|
|
76
76
|
export declare function personaScrollJs(options?: PersonaScrollOptions): string;
|
|
77
|
+
|
|
78
|
+
/** The host persona's face, as a child persona reads it from `/api/face?host=`. */
|
|
79
|
+
export interface ChildFace {
|
|
80
|
+
handle: string;
|
|
81
|
+
home: string | null;
|
|
82
|
+
name: string | null;
|
|
83
|
+
/** The canonical icon — ONE face everywhere. */
|
|
84
|
+
avatar: string | null;
|
|
85
|
+
glyph: string | null;
|
|
86
|
+
accent: string | null;
|
|
87
|
+
bio: string | null;
|
|
88
|
+
meta: string | null;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Fetch the HOST persona's face and apply its accent — for a child persona (`/me`, `/files`,
|
|
93
|
+
* `/feed`) mounted on that host.
|
|
94
|
+
*
|
|
95
|
+
* Reads `/api/face?host=`, which answers "who owns this address" rather than "what is on the
|
|
96
|
+
* storefront": the catalog filters `visibility: hidden` on purpose, so a newborn persona would be
|
|
97
|
+
* invisible to its own child personas.
|
|
98
|
+
*
|
|
99
|
+
* The accent is written to BOTH `:root` and the `.pp` wrapper, because a child scopes its whole
|
|
100
|
+
* token set under `.pp` — writing only to the root is shadowed for the entire surface and changes
|
|
101
|
+
* nothing a person can see.
|
|
102
|
+
*
|
|
103
|
+
* Returns `null` when the host is not a persona, which is a legible state rather than an error.
|
|
104
|
+
*/
|
|
105
|
+
export declare function childFace(options?: {
|
|
106
|
+
/** Defaults to `location.hostname`. */
|
|
107
|
+
host?: string;
|
|
108
|
+
/** The `.pp` wrapper. Defaults to `document.getElementById("pp")`. */
|
|
109
|
+
root?: HTMLElement | null;
|
|
110
|
+
/** Defaults to `https://api.justai.pro`. */
|
|
111
|
+
api?: string;
|
|
112
|
+
}): Promise<ChildFace | null>;
|
package/src/index.js
CHANGED
|
@@ -835,3 +835,69 @@ export function personaScroll(options) {
|
|
|
835
835
|
export function personaScrollJs(options) {
|
|
836
836
|
return "(" + personaScroll.toString() + ")(" + JSON.stringify(options || {}) + ");";
|
|
837
837
|
}
|
|
838
|
+
|
|
839
|
+
// queries: child persona face · the file room is blue · my child persona has the wrong accent ·
|
|
840
|
+
// /api/face · a hidden persona's child · childFace · host persona colour in a child
|
|
841
|
+
//
|
|
842
|
+
// THE HOST PERSONA'S FACE, FOR A CHILD PERSONA THAT IS MOUNTED ON IT.
|
|
843
|
+
//
|
|
844
|
+
// `me`, `files` and `feed` render on every persona's host and have to wear that persona's colour,
|
|
845
|
+
// name and mark. Each of them wrote this fetch by hand, and the line has now moved THREE times —
|
|
846
|
+
// which is the argument for it living here rather than in a fourth copy:
|
|
847
|
+
//
|
|
848
|
+
// 1. `/api/personas` — serves five fields and none of the three needed. Every `if` was false, so
|
|
849
|
+
// every file room wore the platform's default blue. Nothing errored; a 200 is not a face.
|
|
850
|
+
// 2. `/api/catalog` — carries the face, and was right until a persona could be HIDDEN. The catalog
|
|
851
|
+
// filters `hidden` on purpose because it IS the storefront, so from 2026-08-02 a persona born
|
|
852
|
+
// from the template was invisible to its own child personas.
|
|
853
|
+
// 3. `/api/face?host=` — "who owns this address", which is the question this code was always
|
|
854
|
+
// asking. Only the storefront's question is about visibility.
|
|
855
|
+
//
|
|
856
|
+
// ── WHERE THE ACCENT HAS TO BE WRITTEN, WHICH IS BOTH PLACES ────────────────────────────────────
|
|
857
|
+
//
|
|
858
|
+
// A child scopes its whole token set under `.pp` — `--accent` included — so a value written only to
|
|
859
|
+
// `:root` is SHADOWED for everything inside it, which is the entire surface. It looks correct, it
|
|
860
|
+
// measures correct at `documentElement`, and it changes nothing a person can see. The root still
|
|
861
|
+
// gets it too, because a few rules live outside `.pp` (`::selection` is one) and read the document's.
|
|
862
|
+
//
|
|
863
|
+
// Learned by moving it off `.pp` "to be more correct" and undoing a shipped fix — so both, always.
|
|
864
|
+
export async function childFace(options) {
|
|
865
|
+
const o = options || {};
|
|
866
|
+
const host = o.host || (typeof location !== "undefined" ? location.hostname : "");
|
|
867
|
+
if (!host) return null;
|
|
868
|
+
const root = o.root || (typeof document !== "undefined" ? document.getElementById("pp") : null);
|
|
869
|
+
const base = o.api || "https://api.justai.pro";
|
|
870
|
+
let face = null;
|
|
871
|
+
try {
|
|
872
|
+
const r = await fetch(`${base}/api/face?host=${encodeURIComponent(host)}`);
|
|
873
|
+
face = r.ok ? await r.json() : null;
|
|
874
|
+
} catch {
|
|
875
|
+
// A child whose host cannot be resolved is a child wearing the platform's default, which is a
|
|
876
|
+
// legible state. It is not an error to report to somebody looking at their own files.
|
|
877
|
+
return null;
|
|
878
|
+
}
|
|
879
|
+
if (!face) return null;
|
|
880
|
+
if (typeof document === "undefined") return face;
|
|
881
|
+
if (face.accent) {
|
|
882
|
+
document.documentElement.style.setProperty("--accent", face.accent);
|
|
883
|
+
if (root) root.style.setProperty("--accent", face.accent);
|
|
884
|
+
}
|
|
885
|
+
// queries: pnName pnHandle pnMeta · the child persona shows its own name instead of the host's
|
|
886
|
+
//
|
|
887
|
+
// THE HOST'S IDENTITY, WRITTEN INTO THE SHELL'S IDS. <ChildPersona> renders name, handle and the
|
|
888
|
+
// small print as spans with these ids precisely so one function can fill them: the page is built
|
|
889
|
+
// once and mounted on every persona's host, so none of it is knowable at build time.
|
|
890
|
+
//
|
|
891
|
+
// Each write is guarded because a MISSING value must leave the server's fallback standing — the
|
|
892
|
+
// child's own words, which are correct when the lookup never returns. Blanking them on a failed
|
|
893
|
+
// fetch would turn "we could not reach the registry" into "this persona has no name".
|
|
894
|
+
const put = (id, text) => { const el = document.getElementById(id); if (el && text) el.textContent = text; };
|
|
895
|
+
put("pnName", face.name);
|
|
896
|
+
put("pnHandle", face.handle ? "@" + face.handle : null);
|
|
897
|
+
put("pnMeta", face.meta);
|
|
898
|
+
if (face.avatar) {
|
|
899
|
+
const slot = document.getElementById("hostGlyph");
|
|
900
|
+
if (slot) slot.innerHTML = '<img class="mk" src="' + face.avatar + '" alt="">';
|
|
901
|
+
}
|
|
902
|
+
return face;
|
|
903
|
+
}
|