@justai/core 0.44.0 → 0.45.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/dist/account.d.ts +28 -0
- package/dist/account.js +84 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/mark.d.ts +7 -0
- package/dist/mark.js +1 -1
- package/dist/surfaces.d.ts +24 -0
- package/dist/surfaces.js +110 -2
- package/package.json +5 -1
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @justai/core/account — who is signed in, as the global shell asks it. One small contract with two
|
|
3
|
+
* implementations: the fleet's auth SDK (the default) and an app's own adapter.
|
|
4
|
+
*
|
|
5
|
+
* Part of the framework-free heart of the persona shell. See `./index.js` for what this package is.
|
|
6
|
+
*/
|
|
7
|
+
/** What the shell shows of an account. */
|
|
8
|
+
export interface ShellAccount {
|
|
9
|
+
name: string | null;
|
|
10
|
+
email: string | null;
|
|
11
|
+
picture: string | null;
|
|
12
|
+
}
|
|
13
|
+
/** The contract between the global shell and wherever an app's account lives. */
|
|
14
|
+
export interface AccountAdapter {
|
|
15
|
+
read(): ShellAccount | null;
|
|
16
|
+
subscribe(onChange: () => void): () => void;
|
|
17
|
+
signIn(): void;
|
|
18
|
+
signOut?(): void;
|
|
19
|
+
open?(anchor: HTMLElement): void;
|
|
20
|
+
}
|
|
21
|
+
/** The default adapter: the fleet's auth SDK. */
|
|
22
|
+
export declare const sdkAccount: AccountAdapter;
|
|
23
|
+
/** Register the app's own account adapter (the header's `account="adapter"` mode reads it). */
|
|
24
|
+
export declare function setAccountAdapter(adapter: AccountAdapter | null): void;
|
|
25
|
+
/** The registered app adapter, or null. */
|
|
26
|
+
export declare function accountAdapter(): AccountAdapter | null;
|
|
27
|
+
/** Hear when an app adapter is registered or replaced. Returns the unsubscribe. */
|
|
28
|
+
export declare function onAccountAdapter(fn: () => void): () => void;
|
package/dist/account.js
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @justai/core/account — who is signed in, as the global shell asks it. One small contract with two
|
|
3
|
+
* implementations: the fleet's auth SDK (the default) and an app's own adapter.
|
|
4
|
+
*
|
|
5
|
+
* Part of the framework-free heart of the persona shell. See `./index.js` for what this package is.
|
|
6
|
+
*/
|
|
7
|
+
const AUTH = "https://auth.justai.pro";
|
|
8
|
+
const here = () => location.origin + location.pathname + location.search;
|
|
9
|
+
const sdk = () => (typeof window !== "undefined" ? (window.justaiAuth ?? null) : null);
|
|
10
|
+
const SESSION_KEY = "justai_token";
|
|
11
|
+
const fromSession = () => {
|
|
12
|
+
try {
|
|
13
|
+
const tok = localStorage.getItem(SESSION_KEY);
|
|
14
|
+
if (!tok)
|
|
15
|
+
return null;
|
|
16
|
+
const b64 = tok.split(".")[1].replace(/-/g, "+").replace(/_/g, "/");
|
|
17
|
+
const p = JSON.parse(decodeURIComponent(escape(atob(b64))));
|
|
18
|
+
if (p.exp && p.exp * 1000 < Date.now())
|
|
19
|
+
return null;
|
|
20
|
+
return { name: p.name || null, email: p.email || null, picture: p.picture || null };
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
/** The default adapter: the fleet's auth SDK. */
|
|
27
|
+
export const sdkAccount = {
|
|
28
|
+
read() {
|
|
29
|
+
const s = sdk();
|
|
30
|
+
if (s && "user" in s) {
|
|
31
|
+
const u = s.user;
|
|
32
|
+
return u ? { name: u.name || null, email: u.email || null, picture: u.picture || null } : null;
|
|
33
|
+
}
|
|
34
|
+
return fromSession();
|
|
35
|
+
},
|
|
36
|
+
subscribe(onChange) {
|
|
37
|
+
const onStorage = (e) => { if (e.key === SESSION_KEY)
|
|
38
|
+
onChange(); };
|
|
39
|
+
addEventListener("storage", onStorage);
|
|
40
|
+
document.addEventListener("justai-auth", onChange);
|
|
41
|
+
return () => { removeEventListener("storage", onStorage); document.removeEventListener("justai-auth", onChange); };
|
|
42
|
+
},
|
|
43
|
+
signIn() {
|
|
44
|
+
const s = sdk();
|
|
45
|
+
if (s && typeof s.signIn === "function")
|
|
46
|
+
return s.signIn();
|
|
47
|
+
location.href = AUTH + "/?action=signin&return_url=" + encodeURIComponent(here());
|
|
48
|
+
},
|
|
49
|
+
signOut() {
|
|
50
|
+
const s = sdk();
|
|
51
|
+
if (s && typeof s.signOut === "function")
|
|
52
|
+
return s.signOut();
|
|
53
|
+
location.href = AUTH + "/?action=signout&return_url=" + encodeURIComponent(here());
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
// ── THE APP'S ADAPTER ─────────────────────────────────────────────────────────────────────────────
|
|
57
|
+
// Registered on globalThis for the same reason the surfaces registry is: an app chunk and the header's
|
|
58
|
+
// chunk may each bundle their own copy of this module.
|
|
59
|
+
const REGISTRY = "__justaiAccount";
|
|
60
|
+
const registry = () => {
|
|
61
|
+
const g = globalThis;
|
|
62
|
+
return g[REGISTRY] || (g[REGISTRY] = { adapter: null, waiting: new Set() });
|
|
63
|
+
};
|
|
64
|
+
/** Register the app's own account adapter (the header's `account="adapter"` mode reads it). */
|
|
65
|
+
export function setAccountAdapter(adapter) {
|
|
66
|
+
const r = registry();
|
|
67
|
+
r.adapter = adapter;
|
|
68
|
+
for (const fn of [...r.waiting]) {
|
|
69
|
+
try {
|
|
70
|
+
fn();
|
|
71
|
+
}
|
|
72
|
+
catch { /* one listener is not the registry */ }
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
/** The registered app adapter, or null. */
|
|
76
|
+
export function accountAdapter() {
|
|
77
|
+
return registry().adapter;
|
|
78
|
+
}
|
|
79
|
+
/** Hear when an app adapter is registered or replaced. Returns the unsubscribe. */
|
|
80
|
+
export function onAccountAdapter(fn) {
|
|
81
|
+
const r = registry();
|
|
82
|
+
r.waiting.add(fn);
|
|
83
|
+
return () => { r.waiting.delete(fn); };
|
|
84
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -32,6 +32,7 @@
|
|
|
32
32
|
* ./presentation standalone, or inside somebody else's sheet
|
|
33
33
|
* ./scroll landing on the kernel, and the spy
|
|
34
34
|
* ./surfaces the kernel as the document, the profile and the posts as layers (opt-in)
|
|
35
|
+
* ./account who is signed in, as the global shell asks it (the SDK, or an app's adapter)
|
|
35
36
|
* ./mark the persona's mark, and adopting a host's
|
|
36
37
|
* ./face a host persona's face, for a child mounted on it
|
|
37
38
|
* ./random a fair random integer, pick, sample and shuffle — crypto.getRandomValues only
|
|
@@ -59,5 +60,6 @@ export * from "./chrome.js";
|
|
|
59
60
|
export * from "./presentation.js";
|
|
60
61
|
export * from "./scroll.js";
|
|
61
62
|
export * from "./surfaces.js";
|
|
63
|
+
export * from "./account.js";
|
|
62
64
|
export * from "./mark.js";
|
|
63
65
|
export * from "./face.js";
|
package/dist/index.js
CHANGED
|
@@ -32,6 +32,7 @@
|
|
|
32
32
|
* ./presentation standalone, or inside somebody else's sheet
|
|
33
33
|
* ./scroll landing on the kernel, and the spy
|
|
34
34
|
* ./surfaces the kernel as the document, the profile and the posts as layers (opt-in)
|
|
35
|
+
* ./account who is signed in, as the global shell asks it (the SDK, or an app's adapter)
|
|
35
36
|
* ./mark the persona's mark, and adopting a host's
|
|
36
37
|
* ./face a host persona's face, for a child mounted on it
|
|
37
38
|
* ./random a fair random integer, pick, sample and shuffle — crypto.getRandomValues only
|
|
@@ -59,5 +60,6 @@ export * from "./chrome.js";
|
|
|
59
60
|
export * from "./presentation.js";
|
|
60
61
|
export * from "./scroll.js";
|
|
61
62
|
export * from "./surfaces.js";
|
|
63
|
+
export * from "./account.js";
|
|
62
64
|
export * from "./mark.js";
|
|
63
65
|
export * from "./face.js";
|
package/dist/mark.d.ts
CHANGED
|
@@ -11,6 +11,13 @@ export declare function toolbarMark(iconSvg: string, options?: {
|
|
|
11
11
|
fills?: number;
|
|
12
12
|
/** How many pixels of INK the surface wants, default 20 — the toolbar row's rule. */
|
|
13
13
|
ink?: number;
|
|
14
|
+
/**
|
|
15
|
+
* `"ink"` (default): the figure's paint becomes `currentColor` — the golden rule below.
|
|
16
|
+
* `"own"`: the figure keeps its own paint (its gradients, re-pointed to this copy's ids). For the
|
|
17
|
+
* LIT copy a shell shows while its cut is current, when the persona's mark is lit in its own colours
|
|
18
|
+
* (Shell R1, 2026-11-19) — the same picture a persona used to rebuild by re-pointing from its CSS.
|
|
19
|
+
*/
|
|
20
|
+
paint?: "ink" | "own";
|
|
14
21
|
}): string;
|
|
15
22
|
export declare function adoptMark(options?: {
|
|
16
23
|
/** The element holding the host's `<img>`. Defaults to `#navParent`. */
|
package/dist/mark.js
CHANGED
|
@@ -100,7 +100,7 @@ export function toolbarMark(iconSvg, options) {
|
|
|
100
100
|
// Only the PAINT is neutralised, and only outside `<defs>`: the gradients stay defined, so a
|
|
101
101
|
// persona that wants its own colours *while current* can re-point to them from its own CSS. qr
|
|
102
102
|
// does. That is a decision about what the accent looks like, never about when it appears.
|
|
103
|
-
{
|
|
103
|
+
if (o.paint !== "own") {
|
|
104
104
|
const cut = s.lastIndexOf("</defs>");
|
|
105
105
|
const head = cut >= 0 ? s.slice(0, cut + 7) : "";
|
|
106
106
|
const body = (cut >= 0 ? s.slice(cut + 7) : s)
|
package/dist/surfaces.d.ts
CHANGED
|
@@ -29,6 +29,30 @@ export declare function isShellFragment(hash: string): boolean;
|
|
|
29
29
|
export declare function surfaceBoot(): void;
|
|
30
30
|
/** The boot as an injectable IIFE — derived from {@link surfaceBoot}, never written twice. */
|
|
31
31
|
export declare const SURFACE_BOOT_JS: string;
|
|
32
|
+
/** The global shell's two modes: the Golden row over the kernel, or a document's own workspace. */
|
|
33
|
+
export type ShellMode = "app" | "document";
|
|
34
|
+
/** Called after a surface change, once the new surface is current and reachable. */
|
|
35
|
+
export type SurfaceListener = (now: Surface, from: Surface) => void;
|
|
36
|
+
/** The event the same change is announced as, on `document` (`detail: { surface, from }`). */
|
|
37
|
+
export declare const SURFACE_EVENT = "justai-surface";
|
|
38
|
+
/** The current surface, or `null` on a page that has not opted into the surfaces contract. */
|
|
39
|
+
export declare function currentSurface(): Surface | null;
|
|
40
|
+
/** True while the kernel is current — and on a page without surfaces, where there is nothing else. */
|
|
41
|
+
export declare function inKernel(): boolean;
|
|
42
|
+
/** Subscribe to surface changes. Returns the unsubscribe. */
|
|
43
|
+
export declare function onSurfaceChange(listener: SurfaceListener): () => void;
|
|
44
|
+
/**
|
|
45
|
+
* Bring the kernel back — the row's own trip home — and resolve once it is current and reachable
|
|
46
|
+
* (not inert, not covered). Resolves at once when it already is, or when the page has no surfaces.
|
|
47
|
+
*/
|
|
48
|
+
export declare function toKernel(): Promise<void>;
|
|
49
|
+
/** The global shell's current mode. */
|
|
50
|
+
export declare function shellMode(): ShellMode;
|
|
51
|
+
/**
|
|
52
|
+
* Enter or leave Shell R1's document mode. Entering brings the kernel back first; the returned promise
|
|
53
|
+
* resolves once the mode is in force. On a page without surfaces it only sets the mode.
|
|
54
|
+
*/
|
|
55
|
+
export declare function setShellMode(mode: ShellMode): Promise<void>;
|
|
32
56
|
export interface PersonaSurfacesOptions {
|
|
33
57
|
/** The bar that sticks over the kernel. Default `.toolbar`; pdf-edit's face passes `.fbar`. */
|
|
34
58
|
toolbar?: string | HTMLElement | null;
|
package/dist/surfaces.js
CHANGED
|
@@ -87,6 +87,91 @@ export function surfaceBoot() {
|
|
|
87
87
|
}
|
|
88
88
|
/** The boot as an injectable IIFE — derived from {@link surfaceBoot}, never written twice. */
|
|
89
89
|
export const SURFACE_BOOT_JS = "(" + surfaceBoot.toString() + ")();";
|
|
90
|
+
/** The event the same change is announced as, on `document` (`detail: { surface, from }`). */
|
|
91
|
+
export const SURFACE_EVENT = "justai-surface";
|
|
92
|
+
const REGISTRY = "__justaiSurfaces";
|
|
93
|
+
const registry = () => {
|
|
94
|
+
const g = globalThis;
|
|
95
|
+
return g[REGISTRY] || (g[REGISTRY] = { ctl: null, listeners: new Set(), mode: "app" });
|
|
96
|
+
};
|
|
97
|
+
const tell = (now, from) => {
|
|
98
|
+
for (const fn of [...registry().listeners]) {
|
|
99
|
+
try {
|
|
100
|
+
fn(now, from);
|
|
101
|
+
}
|
|
102
|
+
catch { /* one listener's error is not the shell's */ }
|
|
103
|
+
}
|
|
104
|
+
try {
|
|
105
|
+
document.dispatchEvent(new CustomEvent(SURFACE_EVENT, { detail: { surface: now, from } }));
|
|
106
|
+
}
|
|
107
|
+
catch { /* no DOM, no event */ }
|
|
108
|
+
};
|
|
109
|
+
/** The current surface, or `null` on a page that has not opted into the surfaces contract. */
|
|
110
|
+
export function currentSurface() {
|
|
111
|
+
const c = registry().ctl;
|
|
112
|
+
if (c)
|
|
113
|
+
return c.current();
|
|
114
|
+
if (typeof document === "undefined")
|
|
115
|
+
return null;
|
|
116
|
+
const a = document.documentElement.getAttribute("data-surface");
|
|
117
|
+
return a === "kernel" || a === "profile" || a === "posts" ? a : null;
|
|
118
|
+
}
|
|
119
|
+
/** True while the kernel is current — and on a page without surfaces, where there is nothing else. */
|
|
120
|
+
export function inKernel() {
|
|
121
|
+
const s = currentSurface();
|
|
122
|
+
return s === null || s === "kernel";
|
|
123
|
+
}
|
|
124
|
+
/** Subscribe to surface changes. Returns the unsubscribe. */
|
|
125
|
+
export function onSurfaceChange(listener) {
|
|
126
|
+
const r = registry();
|
|
127
|
+
r.listeners.add(listener);
|
|
128
|
+
return () => { r.listeners.delete(listener); };
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Bring the kernel back — the row's own trip home — and resolve once it is current and reachable
|
|
132
|
+
* (not inert, not covered). Resolves at once when it already is, or when the page has no surfaces.
|
|
133
|
+
*/
|
|
134
|
+
export function toKernel() {
|
|
135
|
+
const c = registry().ctl;
|
|
136
|
+
if (!c || c.current() === "kernel")
|
|
137
|
+
return Promise.resolve();
|
|
138
|
+
return new Promise((done) => {
|
|
139
|
+
let finished = false;
|
|
140
|
+
const finish = () => { if (finished)
|
|
141
|
+
return; finished = true; off(); clearTimeout(guard); done(); };
|
|
142
|
+
const off = onSurfaceChange((now) => { if (now === "kernel")
|
|
143
|
+
finish(); });
|
|
144
|
+
// The trip home goes Back over the shell's own entry; a Back the browser never delivers (a page
|
|
145
|
+
// opened at #posts has no entry under it to go back to) must not leave the caller waiting.
|
|
146
|
+
const guard = setTimeout(() => { if (c.current() !== "kernel")
|
|
147
|
+
c.land(); finish(); }, 900);
|
|
148
|
+
c.go("kernel");
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
/** The global shell's current mode. */
|
|
152
|
+
export function shellMode() {
|
|
153
|
+
return registry().mode;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Enter or leave Shell R1's document mode. Entering brings the kernel back first; the returned promise
|
|
157
|
+
* resolves once the mode is in force. On a page without surfaces it only sets the mode.
|
|
158
|
+
*/
|
|
159
|
+
export async function setShellMode(mode) {
|
|
160
|
+
if (mode === "document")
|
|
161
|
+
await toKernel();
|
|
162
|
+
const r = registry();
|
|
163
|
+
r.mode = mode;
|
|
164
|
+
if (typeof document === "undefined")
|
|
165
|
+
return;
|
|
166
|
+
const root = document.documentElement;
|
|
167
|
+
if (mode === "document")
|
|
168
|
+
root.setAttribute("data-shell-mode", "document");
|
|
169
|
+
else
|
|
170
|
+
root.removeAttribute("data-shell-mode");
|
|
171
|
+
// the bar comes back at its own height; anything measuring it (the kernel's floor) hears a resize
|
|
172
|
+
if (mode === "app")
|
|
173
|
+
requestAnimationFrame(() => dispatchEvent(new Event("resize")));
|
|
174
|
+
}
|
|
90
175
|
/** The history-state key a teardown leaves on the entry it replaced in place (see R2.1 above). */
|
|
91
176
|
const DUP_STATE = "justaiSurfaceDup";
|
|
92
177
|
export function personaSurfaces(options) {
|
|
@@ -435,6 +520,8 @@ export function personaSurfaces(options) {
|
|
|
435
520
|
back?.focus({ preventScroll: true });
|
|
436
521
|
}
|
|
437
522
|
keyboard = false;
|
|
523
|
+
// the new surface is current and reachable now (inert and cover are already written): say so
|
|
524
|
+
tell(next, from);
|
|
438
525
|
};
|
|
439
526
|
// Leaving the profile by scrolling out of it: in place. The entry the trip pushed becomes a kernel
|
|
440
527
|
// entry marked as a duplicate; nothing navigates, the address does not move.
|
|
@@ -444,6 +531,7 @@ export function personaSurfaces(options) {
|
|
|
444
531
|
current = "kernel";
|
|
445
532
|
paint("kernel");
|
|
446
533
|
replace(kernelState(ours));
|
|
534
|
+
tell("kernel", "profile");
|
|
447
535
|
};
|
|
448
536
|
// ── THE FIRST SURFACE ─────────────────────────────────────────────────────────────────────────
|
|
449
537
|
{
|
|
@@ -506,6 +594,17 @@ export function personaSurfaces(options) {
|
|
|
506
594
|
apply("kernel");
|
|
507
595
|
}
|
|
508
596
|
};
|
|
597
|
+
// the lifecycle API's handle on this page (see THE LIFECYCLE above). `land` is the trip home without a
|
|
598
|
+
// traversal — for a Back the browser could not deliver.
|
|
599
|
+
registry().ctl = {
|
|
600
|
+
current: () => current,
|
|
601
|
+
go: (to) => go(to),
|
|
602
|
+
land: () => { if (current !== "kernel") {
|
|
603
|
+
replace(kernelState(false));
|
|
604
|
+
apply("kernel");
|
|
605
|
+
} },
|
|
606
|
+
};
|
|
607
|
+
const documentMode = () => registry().mode === "document";
|
|
509
608
|
document.addEventListener("click", (e) => {
|
|
510
609
|
if (e.defaultPrevented || e.button !== 0 || e.metaKey || e.ctrlKey || e.shiftKey || e.altKey)
|
|
511
610
|
return;
|
|
@@ -517,6 +616,9 @@ export function personaSurfaces(options) {
|
|
|
517
616
|
if (!isShellFragment(href))
|
|
518
617
|
return;
|
|
519
618
|
e.preventDefault();
|
|
619
|
+
// a document's workspace has the screen: the shell's fragments open nothing until it closes
|
|
620
|
+
if (documentMode())
|
|
621
|
+
return;
|
|
520
622
|
// `detail` is the click count: 0 for an activation that came from the keyboard (Enter on a link) or
|
|
521
623
|
// assistive technology, never for a pointer or a finger.
|
|
522
624
|
keyboard = e.detail === 0;
|
|
@@ -537,7 +639,13 @@ export function personaSurfaces(options) {
|
|
|
537
639
|
const sameAddress = location.href === lastHref;
|
|
538
640
|
lastState = history.state;
|
|
539
641
|
lastHref = location.href;
|
|
540
|
-
|
|
642
|
+
let s = surfaceFor(location.hash, history.state, has);
|
|
643
|
+
// In document mode no surface can be shown (the shell is hidden): a Back or Forward onto a surface's
|
|
644
|
+
// entry lands on the kernel instead, and the entry is told so — nothing opens out of sight.
|
|
645
|
+
if (documentMode() && s !== "kernel") {
|
|
646
|
+
replace(kernelState(false));
|
|
647
|
+
s = "kernel";
|
|
648
|
+
}
|
|
541
649
|
if (isShellFragment(location.hash)) {
|
|
542
650
|
const st = stateObj();
|
|
543
651
|
if (s === "kernel")
|
|
@@ -568,7 +676,7 @@ export function personaSurfaces(options) {
|
|
|
568
676
|
}
|
|
569
677
|
};
|
|
570
678
|
document.addEventListener("keydown", (e) => {
|
|
571
|
-
if (e.key !== "Escape" || current === "kernel" || e.defaultPrevented || somethingOpen())
|
|
679
|
+
if (e.key !== "Escape" || current === "kernel" || e.defaultPrevented || somethingOpen() || documentMode())
|
|
572
680
|
return;
|
|
573
681
|
keyboard = true;
|
|
574
682
|
go("kernel");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@justai/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.45.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": {
|
|
@@ -49,6 +49,10 @@
|
|
|
49
49
|
"types": "./dist/surfaces.d.ts",
|
|
50
50
|
"default": "./dist/surfaces.js"
|
|
51
51
|
},
|
|
52
|
+
"./account": {
|
|
53
|
+
"types": "./dist/account.d.ts",
|
|
54
|
+
"default": "./dist/account.js"
|
|
55
|
+
},
|
|
52
56
|
"./mark": {
|
|
53
57
|
"types": "./dist/mark.d.ts",
|
|
54
58
|
"default": "./dist/mark.js"
|