@justai/core 0.35.0 → 0.37.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/analytics.d.ts +61 -0
- package/dist/analytics.js +129 -0
- package/dist/boot.d.ts +53 -0
- package/dist/boot.js +83 -0
- package/dist/chrome.d.ts +42 -0
- package/dist/chrome.js +25 -0
- package/dist/consent.d.ts +105 -0
- package/dist/consent.js +156 -0
- package/dist/face.d.ts +27 -0
- package/dist/face.js +85 -0
- package/dist/index.d.ts +55 -0
- package/dist/index.js +55 -0
- package/dist/mark.d.ts +26 -0
- package/dist/mark.js +286 -0
- package/dist/presentation.d.ts +10 -0
- package/dist/presentation.js +54 -0
- package/dist/scroll.d.ts +23 -0
- package/dist/scroll.js +612 -0
- package/dist/xray.d.ts +40 -0
- package/dist/xray.js +316 -0
- package/package.json +48 -5
- package/src/index.d.ts +0 -147
- package/src/index.js +0 -1662
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @justai/core/analytics — GA4: which stream a host reports into, and the head block that starts measuring. It knows the consent SIGNALS but not the consent DIALOG — the sheet lives in ./consent and calls `gtag`.
|
|
3
|
+
*
|
|
4
|
+
* Part of the framework-free heart of the persona shell. See `./index.js` for what this package is
|
|
5
|
+
* and why its behaviour lives one level below @justai/cuts.
|
|
6
|
+
*/
|
|
7
|
+
export declare function measurementIdFor(host: string | null | undefined): string;
|
|
8
|
+
/**
|
|
9
|
+
* queries: analytics inline script · gtag block · consent defaults · why is dev traffic in GA4 ·
|
|
10
|
+
* non-production guard · localhost 127.0.0.1 in analytics · how does a page start measuring
|
|
11
|
+
*
|
|
12
|
+
* The whole analytics head block, for any framework, given a measurement id.
|
|
13
|
+
*
|
|
14
|
+
* Everything load-bearing about it, in the order it matters:
|
|
15
|
+
*
|
|
16
|
+
* A NON-PRODUCTION PAGE MEASURES NOTHING. Found by reading the property through the analytics MCP:
|
|
17
|
+
* `127.0.0.1` and `localhost` were its TOP "persona" — 546 sessions in four days, and on one of them
|
|
18
|
+
* 127.0.0.1 alone outranked every real persona. Local dev and every headless verification sweep
|
|
19
|
+
* loading built HTML. The guard also covers the edge's `dev-` preview hosts: previews are rehearsals,
|
|
20
|
+
* not visits. Everything before 2026-07-24 in that property is inflated by this.
|
|
21
|
+
*
|
|
22
|
+
* `gtag` GOES ON `window`, never `function gtag`. A framework that scopes an injected variable wraps
|
|
23
|
+
* this in an IIFE, and a function declaration would then be trapped inside it — while the consent
|
|
24
|
+
* dialog's own script, elsewhere on the page, calls `gtag`. The failure is silent and specific: a
|
|
25
|
+
* European visitor clicks Allow, "gtag is not defined", the choice is never applied and the sheet
|
|
26
|
+
* never closes. The stub is also assigned BEFORE the guard returns, so a silenced host still has a
|
|
27
|
+
* callable `gtag` and that same script cannot throw there either.
|
|
28
|
+
*
|
|
29
|
+
* CONSENT DEFAULTS, twice — REVISED 2026-07-25 with the founder, and the revision IS the doctrine:
|
|
30
|
+
* MEASUREMENT follows one rule everywhere (granted by default, EEA asks first), PROFILING is refused
|
|
31
|
+
* everywhere forever. Globally: analytics_storage + ad_storage + ad_user_data granted — counting the
|
|
32
|
+
* visit, and telling an ad its click worked; the dialog's question covers both, in the visitor's
|
|
33
|
+
* language. ad_personalization is DENIED with no path anywhere, which is what keeps "never who"
|
|
34
|
+
* true. The EEA + UK + CH region list denies everything until the dialog's answer — where consent is
|
|
35
|
+
* owed we ask first; where it is not, measurement is simply on (the founder's explicit instruction).
|
|
36
|
+
*
|
|
37
|
+
* STORED CHOICES ARE VERSIONED: "granted+ads" replays the full grant, a legacy "granted" replays
|
|
38
|
+
* analytics ONLY — a visitor who said yes to the narrower question is never silently upgraded to the
|
|
39
|
+
* wider one. "denied" denies the measurement trio.
|
|
40
|
+
*
|
|
41
|
+
* LEGAL POSTURE, noted with the founder: one sentence carries two purposes (counting + ad
|
|
42
|
+
* measurement), both stated plainly — defensible at today's traffic; when traffic grows, granular
|
|
43
|
+
* consent (two separate switches) should be revisited. ad_personalization staying dead is the
|
|
44
|
+
* strongest card in that file.
|
|
45
|
+
*
|
|
46
|
+
* The region list has a sibling: the timezone list in the consent dialog's script. Change one and
|
|
47
|
+
* the other must change, or a visitor is denied by region while never being offered the dialog.
|
|
48
|
+
*
|
|
49
|
+
* `page_title` IS PINNED at load. Only one persona mutates `document.title` today — time shows a live
|
|
50
|
+
* clock — and without this its analytics reports "13:32 · Amsterdam" as the page name. It costs every
|
|
51
|
+
* other persona nothing and removes a trap the next persona that animates its tab would walk into.
|
|
52
|
+
*
|
|
53
|
+
* The tag itself loads on idle after `load`: measurement must never compete with the kernel.
|
|
54
|
+
*
|
|
55
|
+
* WRAPPED IN AN IIFE, and it has to be. The Astro binding used to get one for free from `define:vars`;
|
|
56
|
+
* lifting the block out of the template removed it, and the locals became globals on every persona
|
|
57
|
+
* page — three names a persona could collide with, leaked by the shell, with nothing to notice it. A
|
|
58
|
+
* shared shell does not put anything in the global scope it did not mean to. `window.gtag` is still
|
|
59
|
+
* assigned explicitly on window, which is the one thing that MUST escape.
|
|
60
|
+
*/
|
|
61
|
+
export declare function analyticsJs(gaId: string): string;
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @justai/core/analytics — GA4: which stream a host reports into, and the head block that starts measuring. It knows the consent SIGNALS but not the consent DIALOG — the sheet lives in ./consent and calls `gtag`.
|
|
3
|
+
*
|
|
4
|
+
* Part of the framework-free heart of the persona shell. See `./index.js` for what this package is
|
|
5
|
+
* and why its behaviour lives one level below @justai/cuts.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* queries: which measurement id does this host use · wrong GA4 stream · a persona reports into the
|
|
9
|
+
* wrong property · G-13L3BP6XCW vs G-K2J4FQTQ8L · pin.games analytics · a game reports into
|
|
10
|
+
* app.zone · how does feed pick its analytics tag · adding an apex to analytics ·
|
|
11
|
+
* measurementIdFor returns empty
|
|
12
|
+
*
|
|
13
|
+
* THE ECOSYSTEM'S STREAM LAYOUT — A ROW PER HOUSEHOLD.
|
|
14
|
+
*
|
|
15
|
+
* One GA4 property, a web stream per apex. A page reports into whichever stream ITS CODE loads, so
|
|
16
|
+
* which household a persona belongs to is a fact about our code rather than a rule the platform
|
|
17
|
+
* enforces — put a persona on the wrong one and nothing errors, nothing is missing, the numbers
|
|
18
|
+
* simply land in the wrong column. That is why the mapping is a function here and not a constant
|
|
19
|
+
* copied per repo.
|
|
20
|
+
*
|
|
21
|
+
* IT WAS A TERNARY, AND THE TERNARY WAS ALREADY WRONG. The previous version read
|
|
22
|
+
* `justai.pro ? K2J4 : 13L3` — everything that was not justai.pro reported into APP.ZONE's stream,
|
|
23
|
+
* pin.games included, while the comment above it promised that a third stream would be added *here*.
|
|
24
|
+
* pin.games got its stream (`G-PPMLN9SYD2`), the promise was not kept, and the mistake stayed
|
|
25
|
+
* invisible because it only shows on a SERVER-rendered surface: a static game persona carries its id
|
|
26
|
+
* from the template and is correct, while `/feed/*` on the same host would have counted as app.zone.
|
|
27
|
+
* Found on 2026-08-24 while standing up a third apex — which is exactly the moment a two-branch shape
|
|
28
|
+
* stops being able to hold the truth.
|
|
29
|
+
*
|
|
30
|
+
* AN UNKNOWN APEX RETURNS THE EMPTY STRING, and `analyticsJs` then measures nothing. That is the
|
|
31
|
+
* whole difference between the old shape and this one: a household we have not been told about must
|
|
32
|
+
* produce NO data rather than SOMEBODY ELSE'S data. Silence is a gap you can see in a report; a wrong
|
|
33
|
+
* column is a number you will trust. When a new apex arrives its row goes here — and until its stream
|
|
34
|
+
* exists, its pages honestly count as nobody.
|
|
35
|
+
*
|
|
36
|
+
* `cityinmotion.nl` was that case for exactly one day. It was added to this table the moment its GA4
|
|
37
|
+
* data stream existed, and the ORDER is the point: the stream is created first, and the row follows.
|
|
38
|
+
* A row written in anticipation would name an id that measures into nothing, which looks identical to
|
|
39
|
+
* a row that works.
|
|
40
|
+
*
|
|
41
|
+
* A STATIC persona cannot call this — it has no host at build time — so @justai/cuts keeps its own
|
|
42
|
+
* default and `justai` passes the override, while `templates/bin/new.mjs` writes the id at birth from
|
|
43
|
+
* its own apex table. A SERVER-rendered surface (feed) knows the Host header and must use this. All
|
|
44
|
+
* of them must agree, and this is the file that is right by construction.
|
|
45
|
+
*/
|
|
46
|
+
const STREAMS = {
|
|
47
|
+
"app.zone": "G-13L3BP6XCW",
|
|
48
|
+
"pin.games": "G-PPMLN9SYD2",
|
|
49
|
+
"justai.pro": "G-K2J4FQTQ8L",
|
|
50
|
+
"cityinmotion.nl": "G-JY34Z58S16",
|
|
51
|
+
};
|
|
52
|
+
export function measurementIdFor(host) {
|
|
53
|
+
const h = String(host || "").toLowerCase().split(":")[0];
|
|
54
|
+
const apex = Object.keys(STREAMS).find((a) => h === a || h.endsWith("." + a));
|
|
55
|
+
return apex ? STREAMS[apex] : "";
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* queries: analytics inline script · gtag block · consent defaults · why is dev traffic in GA4 ·
|
|
59
|
+
* non-production guard · localhost 127.0.0.1 in analytics · how does a page start measuring
|
|
60
|
+
*
|
|
61
|
+
* The whole analytics head block, for any framework, given a measurement id.
|
|
62
|
+
*
|
|
63
|
+
* Everything load-bearing about it, in the order it matters:
|
|
64
|
+
*
|
|
65
|
+
* A NON-PRODUCTION PAGE MEASURES NOTHING. Found by reading the property through the analytics MCP:
|
|
66
|
+
* `127.0.0.1` and `localhost` were its TOP "persona" — 546 sessions in four days, and on one of them
|
|
67
|
+
* 127.0.0.1 alone outranked every real persona. Local dev and every headless verification sweep
|
|
68
|
+
* loading built HTML. The guard also covers the edge's `dev-` preview hosts: previews are rehearsals,
|
|
69
|
+
* not visits. Everything before 2026-07-24 in that property is inflated by this.
|
|
70
|
+
*
|
|
71
|
+
* `gtag` GOES ON `window`, never `function gtag`. A framework that scopes an injected variable wraps
|
|
72
|
+
* this in an IIFE, and a function declaration would then be trapped inside it — while the consent
|
|
73
|
+
* dialog's own script, elsewhere on the page, calls `gtag`. The failure is silent and specific: a
|
|
74
|
+
* European visitor clicks Allow, "gtag is not defined", the choice is never applied and the sheet
|
|
75
|
+
* never closes. The stub is also assigned BEFORE the guard returns, so a silenced host still has a
|
|
76
|
+
* callable `gtag` and that same script cannot throw there either.
|
|
77
|
+
*
|
|
78
|
+
* CONSENT DEFAULTS, twice — REVISED 2026-07-25 with the founder, and the revision IS the doctrine:
|
|
79
|
+
* MEASUREMENT follows one rule everywhere (granted by default, EEA asks first), PROFILING is refused
|
|
80
|
+
* everywhere forever. Globally: analytics_storage + ad_storage + ad_user_data granted — counting the
|
|
81
|
+
* visit, and telling an ad its click worked; the dialog's question covers both, in the visitor's
|
|
82
|
+
* language. ad_personalization is DENIED with no path anywhere, which is what keeps "never who"
|
|
83
|
+
* true. The EEA + UK + CH region list denies everything until the dialog's answer — where consent is
|
|
84
|
+
* owed we ask first; where it is not, measurement is simply on (the founder's explicit instruction).
|
|
85
|
+
*
|
|
86
|
+
* STORED CHOICES ARE VERSIONED: "granted+ads" replays the full grant, a legacy "granted" replays
|
|
87
|
+
* analytics ONLY — a visitor who said yes to the narrower question is never silently upgraded to the
|
|
88
|
+
* wider one. "denied" denies the measurement trio.
|
|
89
|
+
*
|
|
90
|
+
* LEGAL POSTURE, noted with the founder: one sentence carries two purposes (counting + ad
|
|
91
|
+
* measurement), both stated plainly — defensible at today's traffic; when traffic grows, granular
|
|
92
|
+
* consent (two separate switches) should be revisited. ad_personalization staying dead is the
|
|
93
|
+
* strongest card in that file.
|
|
94
|
+
*
|
|
95
|
+
* The region list has a sibling: the timezone list in the consent dialog's script. Change one and
|
|
96
|
+
* the other must change, or a visitor is denied by region while never being offered the dialog.
|
|
97
|
+
*
|
|
98
|
+
* `page_title` IS PINNED at load. Only one persona mutates `document.title` today — time shows a live
|
|
99
|
+
* clock — and without this its analytics reports "13:32 · Amsterdam" as the page name. It costs every
|
|
100
|
+
* other persona nothing and removes a trap the next persona that animates its tab would walk into.
|
|
101
|
+
*
|
|
102
|
+
* The tag itself loads on idle after `load`: measurement must never compete with the kernel.
|
|
103
|
+
*
|
|
104
|
+
* WRAPPED IN AN IIFE, and it has to be. The Astro binding used to get one for free from `define:vars`;
|
|
105
|
+
* lifting the block out of the template removed it, and the locals became globals on every persona
|
|
106
|
+
* page — three names a persona could collide with, leaked by the shell, with nothing to notice it. A
|
|
107
|
+
* shared shell does not put anything in the global scope it did not mean to. `window.gtag` is still
|
|
108
|
+
* assigned explicitly on window, which is the one thing that MUST escape.
|
|
109
|
+
*/
|
|
110
|
+
export function analyticsJs(gaId) {
|
|
111
|
+
return `(function(){
|
|
112
|
+
window.gtag=window.gtag||function(){(window.dataLayer=window.dataLayer||[]).push(arguments)};
|
|
113
|
+
var __h=location.hostname;
|
|
114
|
+
if(!(__h==="localhost"||__h==="127.0.0.1"||__h==="::1"||__h==="[::1]"||__h.indexOf("dev-")===0)){
|
|
115
|
+
var __g=${JSON.stringify(gaId)};
|
|
116
|
+
if(!__g)return;
|
|
117
|
+
window.dataLayer=window.dataLayer||[];
|
|
118
|
+
window.gtag=window.gtag||function(){window.dataLayer.push(arguments)};
|
|
119
|
+
gtag("js",new Date());
|
|
120
|
+
gtag("consent","default",{ad_storage:"granted",ad_user_data:"granted",ad_personalization:"denied",analytics_storage:"granted"});
|
|
121
|
+
gtag("consent","default",{region:["AT","BE","BG","HR","CY","CZ","DK","EE","FI","FR","DE","GR","HU","IE","IT","LV","LT","LU","MT","NL","PL","PT","RO","SK","SI","ES","SE","IS","LI","NO","GB","CH"],ad_storage:"denied",ad_user_data:"denied",ad_personalization:"denied",analytics_storage:"denied"});
|
|
122
|
+
try{var __c=localStorage.getItem("consent");
|
|
123
|
+
if(__c==="granted+ads")gtag("consent","update",{analytics_storage:"granted",ad_storage:"granted",ad_user_data:"granted"});
|
|
124
|
+
else if(__c==="granted")gtag("consent","update",{analytics_storage:"granted"});
|
|
125
|
+
else if(__c==="denied")gtag("consent","update",{analytics_storage:"denied",ad_storage:"denied",ad_user_data:"denied"})}catch(e){}
|
|
126
|
+
gtag("config",__g,{cookie_expires:60*60*24*60,page_title:document.title,page_location:location.origin+location.pathname,allow_google_signals:false,allow_ad_personalization_signals:false});
|
|
127
|
+
addEventListener("load",function(){(window.requestIdleCallback||function(f){setTimeout(f,1200)})(function(){var s=document.createElement("script");s.async=true;s.src="https://www.googletagmanager.com/gtag/js?id="+__g;document.head.appendChild(s)})});
|
|
128
|
+
}})();`;
|
|
129
|
+
}
|
package/dist/boot.d.ts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @justai/core/boot — the first moments of a page — capture the token, admit that JS is running, hold the paint, let it go. It knows the head and the document, and nothing about analytics, consent or a persona's shape.
|
|
3
|
+
*
|
|
4
|
+
* Part of the framework-free heart of the persona shell. See `./index.js` for what this package is
|
|
5
|
+
* and why its behaviour lives one level below @justai/cuts.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Capture the SSO token from the URL fragment, synchronously, and stash it for the deferred auth SDK.
|
|
9
|
+
*
|
|
10
|
+
* MUST run before anything else can touch `location.hash`. Two later scripts would otherwise take it:
|
|
11
|
+
* a scroll-spy that rewrites the hash to `#kernel` CLOBBERS `#auth_token` before the SDK reads it, and
|
|
12
|
+
* a language picker that copies the current hash onto the next locale's URL would PROPAGATE the raw
|
|
13
|
+
* token into history. Injecting this first, in the head, defeats both. Move it later and sign-in breaks
|
|
14
|
+
* SILENTLY — no error, the visitor simply lands back signed out.
|
|
15
|
+
*/
|
|
16
|
+
export declare function authCapture(): void;
|
|
17
|
+
/** The capture as an injectable IIFE — derived from {@link authCapture}, never written twice. */
|
|
18
|
+
export declare const AUTH_CAPTURE_JS: string;
|
|
19
|
+
/**
|
|
20
|
+
* Mark that JavaScript is running, so the reveal below can hold paint only when JS can un-hold it.
|
|
21
|
+
*
|
|
22
|
+
* DELIBERATELY STILL A STRING, and it is the one that should be. It is a single expression with no
|
|
23
|
+
* name to leak, nothing to type and nothing to test — wrapping it in a function to derive an IIFE
|
|
24
|
+
* would add a closure around one statement and call it rigour. The pattern applies where behaviour
|
|
25
|
+
* has structure; knowing where it does not is the same judgement.
|
|
26
|
+
*/
|
|
27
|
+
export declare const JS_CLASS_JS = "document.documentElement.classList.add(\"js\")";
|
|
28
|
+
/**
|
|
29
|
+
* Hold the paint until a page marks itself ready (`body.ready`), gated behind `.js` so the page is
|
|
30
|
+
* always visible with JS off and never flashes before positioning at the Kernel.
|
|
31
|
+
*
|
|
32
|
+
* This is a TRAP as much as a feature, and the warning belongs beside it: ANY page using this without a
|
|
33
|
+
* script that sets `body.ready` stays invisible FOREVER, and nothing errors — the page is simply never
|
|
34
|
+
* shown. A page with no kernel script (a 404, or a sub-persona like feed) must carry {@link READY_JS}.
|
|
35
|
+
*/
|
|
36
|
+
export declare const REVEAL_CSS = "html.js body{opacity:0}html.js body.ready{opacity:1}";
|
|
37
|
+
/**
|
|
38
|
+
* The other half of {@link REVEAL_CSS}, for a page that has no kernel script to reveal it: set
|
|
39
|
+
* `body.ready` as soon as the body exists, and once more after load as a backstop. This is what keeps
|
|
40
|
+
* a sub-persona page (feed, a 404) from falling into the reveal trap.
|
|
41
|
+
*/
|
|
42
|
+
export declare function ready(): void;
|
|
43
|
+
/**
|
|
44
|
+
* The reveal as an injectable IIFE — derived from {@link ready}.
|
|
45
|
+
*
|
|
46
|
+
* IT USED TO BE BARE STATEMENTS, and that leaked. `var r = …` injected at the top level of a script
|
|
47
|
+
* tag is a GLOBAL named `r` on every page that carries it — `cuts-next` injects this raw through
|
|
48
|
+
* `dangerouslySetInnerHTML`, so every feed page in the fleet had one. Nothing errored and nothing
|
|
49
|
+
* could have: a leaked global only breaks when something else wants the name. The framework's own
|
|
50
|
+
* law says a shared shell puts nothing in the global scope it did not mean to, and generating the
|
|
51
|
+
* string from a function is what makes that automatic rather than remembered.
|
|
52
|
+
*/
|
|
53
|
+
export declare const READY_JS: string;
|
package/dist/boot.js
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @justai/core/boot — the first moments of a page — capture the token, admit that JS is running, hold the paint, let it go. It knows the head and the document, and nothing about analytics, consent or a persona's shape.
|
|
3
|
+
*
|
|
4
|
+
* Part of the framework-free heart of the persona shell. See `./index.js` for what this package is
|
|
5
|
+
* and why its behaviour lives one level below @justai/cuts.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Capture the SSO token from the URL fragment, synchronously, and stash it for the deferred auth SDK.
|
|
9
|
+
*
|
|
10
|
+
* MUST run before anything else can touch `location.hash`. Two later scripts would otherwise take it:
|
|
11
|
+
* a scroll-spy that rewrites the hash to `#kernel` CLOBBERS `#auth_token` before the SDK reads it, and
|
|
12
|
+
* a language picker that copies the current hash onto the next locale's URL would PROPAGATE the raw
|
|
13
|
+
* token into history. Injecting this first, in the head, defeats both. Move it later and sign-in breaks
|
|
14
|
+
* SILENTLY — no error, the visitor simply lands back signed out.
|
|
15
|
+
*/
|
|
16
|
+
export function authCapture() {
|
|
17
|
+
try {
|
|
18
|
+
const h = location.hash || "";
|
|
19
|
+
const m = h.match(/(?:^#|&)auth_token=([^&]+)/);
|
|
20
|
+
if (m) {
|
|
21
|
+
localStorage.setItem("justai_token", decodeURIComponent(m[1]));
|
|
22
|
+
}
|
|
23
|
+
else if (/(?:^#|&)auth_signout=1\b/.test(h)) {
|
|
24
|
+
localStorage.removeItem("justai_token");
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
history.replaceState(null, "", location.pathname + location.search);
|
|
30
|
+
}
|
|
31
|
+
catch (e) {
|
|
32
|
+
/* a storage the browser refuses is a visitor who stays signed out, not a page that breaks */
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
/** The capture as an injectable IIFE — derived from {@link authCapture}, never written twice. */
|
|
36
|
+
export const AUTH_CAPTURE_JS = "(" + authCapture.toString() + ")();";
|
|
37
|
+
/**
|
|
38
|
+
* Mark that JavaScript is running, so the reveal below can hold paint only when JS can un-hold it.
|
|
39
|
+
*
|
|
40
|
+
* DELIBERATELY STILL A STRING, and it is the one that should be. It is a single expression with no
|
|
41
|
+
* name to leak, nothing to type and nothing to test — wrapping it in a function to derive an IIFE
|
|
42
|
+
* would add a closure around one statement and call it rigour. The pattern applies where behaviour
|
|
43
|
+
* has structure; knowing where it does not is the same judgement.
|
|
44
|
+
*/
|
|
45
|
+
export const JS_CLASS_JS = `document.documentElement.classList.add("js")`;
|
|
46
|
+
/**
|
|
47
|
+
* Hold the paint until a page marks itself ready (`body.ready`), gated behind `.js` so the page is
|
|
48
|
+
* always visible with JS off and never flashes before positioning at the Kernel.
|
|
49
|
+
*
|
|
50
|
+
* This is a TRAP as much as a feature, and the warning belongs beside it: ANY page using this without a
|
|
51
|
+
* script that sets `body.ready` stays invisible FOREVER, and nothing errors — the page is simply never
|
|
52
|
+
* shown. A page with no kernel script (a 404, or a sub-persona like feed) must carry {@link READY_JS}.
|
|
53
|
+
*/
|
|
54
|
+
export const REVEAL_CSS = `html.js body{opacity:0}html.js body.ready{opacity:1}`;
|
|
55
|
+
/**
|
|
56
|
+
* The other half of {@link REVEAL_CSS}, for a page that has no kernel script to reveal it: set
|
|
57
|
+
* `body.ready` as soon as the body exists, and once more after load as a backstop. This is what keeps
|
|
58
|
+
* a sub-persona page (feed, a 404) from falling into the reveal trap.
|
|
59
|
+
*/
|
|
60
|
+
export function ready() {
|
|
61
|
+
const show = () => {
|
|
62
|
+
if (document.body)
|
|
63
|
+
document.body.classList.add("ready");
|
|
64
|
+
};
|
|
65
|
+
if (document.readyState !== "loading")
|
|
66
|
+
show();
|
|
67
|
+
else
|
|
68
|
+
addEventListener("DOMContentLoaded", show);
|
|
69
|
+
// The backstop. A page that never fires the event it is waiting for must still become visible —
|
|
70
|
+
// an invisible page is the one failure mode of REVEAL_CSS and it reports nothing.
|
|
71
|
+
setTimeout(show, 400);
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* The reveal as an injectable IIFE — derived from {@link ready}.
|
|
75
|
+
*
|
|
76
|
+
* IT USED TO BE BARE STATEMENTS, and that leaked. `var r = …` injected at the top level of a script
|
|
77
|
+
* tag is a GLOBAL named `r` on every page that carries it — `cuts-next` injects this raw through
|
|
78
|
+
* `dangerouslySetInnerHTML`, so every feed page in the fleet had one. Nothing errored and nothing
|
|
79
|
+
* could have: a leaked global only breaks when something else wants the name. The framework's own
|
|
80
|
+
* law says a shared shell puts nothing in the global scope it did not mean to, and generating the
|
|
81
|
+
* string from a function is what makes that automatic rather than remembered.
|
|
82
|
+
*/
|
|
83
|
+
export const READY_JS = "(" + ready.toString() + ")();";
|
package/dist/chrome.d.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @justai/core/chrome — Cancel and Done, in thirteen languages. Pure data. It knows nothing — which is why it is not in ./consent beside the other dictionary: they are two vocabularies with two owners.
|
|
3
|
+
*
|
|
4
|
+
* Part of the framework-free heart of the persona shell. See `./index.js` for what this package is
|
|
5
|
+
* and why its behaviour lives one level below @justai/cuts.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* queries: the sheet says Cancel in English · Cancel is not translated · Done is not translated ·
|
|
9
|
+
* the picker's cancel stays English in Arabic · sheet chrome language · translate a cut ·
|
|
10
|
+
* who owns the word Cancel · CHROME_COPY · a component's own words
|
|
11
|
+
*
|
|
12
|
+
* THE CHROME WORDS — Cancel and Done, in thirteen languages, said once.
|
|
13
|
+
*
|
|
14
|
+
* The same argument as CONSENT_COPY above, and found the same way: a picker opened on an Arabic page
|
|
15
|
+
* with every word around it in Arabic and `Cancel` in English, sitting in the sheet's own bar.
|
|
16
|
+
*
|
|
17
|
+
* `<Sheet>` had defaulted its Done to the literal "Done" and reasoned, in a comment, that a label is
|
|
18
|
+
* a prop "because the fleet speaks thirteen languages, and a cut that hardcoded the English would be
|
|
19
|
+
* a component making its consumer's copy decisions". The reasoning was inverted. Handing the word to
|
|
20
|
+
* the consumer does not avoid the decision — it makes it THIRTEEN TIMES, in every repo, and the
|
|
21
|
+
* hardcoded English default proved it: the cut was already deciding, and deciding wrong.
|
|
22
|
+
*
|
|
23
|
+
* These are not a persona's copy. `Cancel` is not qr's word or files' word; it is the ecosystem's,
|
|
24
|
+
* the way the back chevron is the ecosystem's shape. Law 1 — a component brings its own ground,
|
|
25
|
+
* style AND text — is what says the cut must carry them.
|
|
26
|
+
*
|
|
27
|
+
* WHY HERE rather than in @justai/cuts: same reason the consent copy is here. Every face reaches
|
|
28
|
+
* core; only the Astro shell reaches cuts.
|
|
29
|
+
*
|
|
30
|
+
* LIFTED FROM `files`, BYTE FOR BYTE, and that is the point rather than an economy. The file kernel
|
|
31
|
+
* mounts INSIDE a host's sheet: the guest draws its own cancel in the body and the host draws one in
|
|
32
|
+
* the bar, and a person looking at one surface must not be shown two different words for the one
|
|
33
|
+
* way out. One word per meaning — the same rule the `nameTaken` string learned the hard way.
|
|
34
|
+
*/
|
|
35
|
+
/** The two chrome words a component owns, for one language. */
|
|
36
|
+
export interface ChromeStrings {
|
|
37
|
+
cancel: string;
|
|
38
|
+
done: string;
|
|
39
|
+
}
|
|
40
|
+
export declare const CHROME_COPY: Record<string, ChromeStrings>;
|
|
41
|
+
/** The chrome words for a language, falling back to English. Never returns undefined. */
|
|
42
|
+
export declare function chromeCopy(lang: string | null | undefined): ChromeStrings;
|
package/dist/chrome.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @justai/core/chrome — Cancel and Done, in thirteen languages. Pure data. It knows nothing — which is why it is not in ./consent beside the other dictionary: they are two vocabularies with two owners.
|
|
3
|
+
*
|
|
4
|
+
* Part of the framework-free heart of the persona shell. See `./index.js` for what this package is
|
|
5
|
+
* and why its behaviour lives one level below @justai/cuts.
|
|
6
|
+
*/
|
|
7
|
+
export const CHROME_COPY = {
|
|
8
|
+
"ar": { "cancel": "إلغاء", "done": "تم" },
|
|
9
|
+
"de": { "cancel": "Abbrechen", "done": "Fertig" },
|
|
10
|
+
"en": { "cancel": "Cancel", "done": "Done" },
|
|
11
|
+
"es": { "cancel": "Cancelar", "done": "Listo" },
|
|
12
|
+
"fr": { "cancel": "Annuler", "done": "OK" },
|
|
13
|
+
"hi": { "cancel": "रद्द करें", "done": "हो गया" },
|
|
14
|
+
"it": { "cancel": "Annulla", "done": "Fine" },
|
|
15
|
+
"ja": { "cancel": "キャンセル", "done": "完了" },
|
|
16
|
+
"nl": { "cancel": "Annuleren", "done": "Klaar" },
|
|
17
|
+
"pt": { "cancel": "Cancelar", "done": "Concluído" },
|
|
18
|
+
"ru": { "cancel": "Отмена", "done": "Готово" },
|
|
19
|
+
"tr": { "cancel": "Vazgeç", "done": "Bitti" },
|
|
20
|
+
"zh": { "cancel": "取消", "done": "完成" }
|
|
21
|
+
};
|
|
22
|
+
/** The chrome words for a language, falling back to English. Never returns undefined. */
|
|
23
|
+
export function chromeCopy(lang) {
|
|
24
|
+
return CHROME_COPY[String(lang || "en").toLowerCase().split("-")[0]] || CHROME_COPY.en;
|
|
25
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @justai/core/consent — the ecosystem's question to a visitor: the words in thirteen languages, and the flow that asks them. The words are pure data and can be read without a browser; the flow needs a document.
|
|
3
|
+
*
|
|
4
|
+
* Part of the framework-free heart of the persona shell. See `./index.js` for what this package is
|
|
5
|
+
* and why its behaviour lives one level below @justai/cuts.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* queries: where does the consent dialog text live · change the consent wording · consentText ·
|
|
9
|
+
* consentAllow consentDecline consentChoice · why is the consent copy not in the persona ·
|
|
10
|
+
* feed cannot show the consent sheet · translate the consent question
|
|
11
|
+
*
|
|
12
|
+
* THE CONSENT COPY — the ecosystem's question to a visitor, in thirteen languages, said once.
|
|
13
|
+
*
|
|
14
|
+
* It used to live in every persona's own dictionary: thirteen languages across thirteen repos, and
|
|
15
|
+
* measured before this moved, all 52 strings were byte-identical in all of them. That is the tell.
|
|
16
|
+
* A persona's dictionary holds what makes it that persona; this is the ECOSYSTEM speaking, and the
|
|
17
|
+
* same sentence copied into a hundred and sixty-nine files is not localisation, it is a maintenance
|
|
18
|
+
* bill. Changing one word meant thirteen pull requests, and getting twelve of them right meant a
|
|
19
|
+
* visitor somewhere read an older promise than the one we thought we were making.
|
|
20
|
+
*
|
|
21
|
+
* It is legally load-bearing text. There is exactly one place it may be edited, and this is it.
|
|
22
|
+
*
|
|
23
|
+
* WHY HERE rather than in @justai/cuts: `feed` renders on every persona's host and depends on core,
|
|
24
|
+
* not on cuts. Putting the copy where only the Astro shell could reach it is what kept feed from
|
|
25
|
+
* asking the question at all. Content, like behaviour, belongs at the layer every face can reach.
|
|
26
|
+
*
|
|
27
|
+
* REWRITTEN 2026-08-23, after a native Dutch speaker read it on app.zone and said the translations
|
|
28
|
+
* were bad. He was right, and the fault was not in the Dutch — it was in the ENGLISH, which was
|
|
29
|
+
* written in a way no translator could carry:
|
|
30
|
+
*
|
|
31
|
+
* "anonymously, never who" an elliptical construction with no equivalent in most languages. The
|
|
32
|
+
* Dutch became "nooit wie", which a native reads as a fragment.
|
|
33
|
+
* "let it know it worked" two pronouns with different referents and a dropped subject. The
|
|
34
|
+
* Dutch lost the subject entirely — nobody could tell who told whom.
|
|
35
|
+
* "Count me in" an idiom, calqued straight into "Tel me mee".
|
|
36
|
+
*
|
|
37
|
+
* So the source was fixed first: two nouns in parallel ("as a number, never a name") instead of the
|
|
38
|
+
* ellipsis, two whole questions instead of one clause hanging off another, and "that ad" naming its
|
|
39
|
+
* own antecedent. Only then were the twelve languages redone.
|
|
40
|
+
*
|
|
41
|
+
* THREE RULES CAME OUT OF DOING IT, and they are the reason this reads better than a translation:
|
|
42
|
+
*
|
|
43
|
+
* 1. The INTIMATE second person, everywhere the language has one — tu, du, je, sen, tú, ты. A
|
|
44
|
+
* persona is a friend who is glad you came; the formal form turns a small warm question into a
|
|
45
|
+
* terms-of-service notice, and three languages had silently drifted into it.
|
|
46
|
+
* 2. Every clause names who is doing what TO WHOM. The recurring failure across five languages was
|
|
47
|
+
* the advertisement sentence losing its recipient: "may I let it be known that it worked".
|
|
48
|
+
* 3. Carry the feeling, not the figure of speech. English personifies the advertisement — you can
|
|
49
|
+
* TELL an ad it worked. In Hindi and Chinese nobody speaks to an advertisement, so those two say
|
|
50
|
+
* the ad was RECORDED as having worked. Same promise, no English showing through.
|
|
51
|
+
*
|
|
52
|
+
* The register and recipient checks are mechanical and worth repeating on any future edit: a formal
|
|
53
|
+
* pronoun and a dropped indirect object are both invisible to a spell-check and both change what the
|
|
54
|
+
* sentence means.
|
|
55
|
+
*
|
|
56
|
+
* A locale with no entry falls back to English rather than rendering an empty sheet — a missing
|
|
57
|
+
* translation must never become a dialog with no question in it.
|
|
58
|
+
*/
|
|
59
|
+
/** The consent question and its two answers, for one language. */
|
|
60
|
+
export interface ConsentStrings {
|
|
61
|
+
consentText: string;
|
|
62
|
+
consentAllow: string;
|
|
63
|
+
consentDecline: string;
|
|
64
|
+
consentChoice: string;
|
|
65
|
+
}
|
|
66
|
+
export declare const CONSENT_COPY: Record<string, ConsentStrings>;
|
|
67
|
+
/** The consent copy for a language, falling back to English. Never returns undefined. */
|
|
68
|
+
export declare function consentCopy(lang: string | null | undefined): ConsentStrings;
|
|
69
|
+
/**
|
|
70
|
+
* queries: consent dialog script · why does the sheet not appear on some pages · consent is asked
|
|
71
|
+
* per domain not per page · getElementById kernel · the sheet never opened on feed ·
|
|
72
|
+
* only a choice may be remembered · the change-your-mind door · consent timezone list
|
|
73
|
+
*
|
|
74
|
+
* The consent dialog's behaviour — one copy, for every surface on a persona's origin.
|
|
75
|
+
*
|
|
76
|
+
* CONSENT IS SCOPED TO THE ORIGIN, NOT TO A PAGE. Whichever page a visitor enters by, if this origin
|
|
77
|
+
* has never asked, it asks — once. That is what a consent flow IS, and it is worth stating because
|
|
78
|
+
* ours was accidentally page-scoped for three weeks: the script used to bail on
|
|
79
|
+
* `!document.getElementById("kernel")`, a DOM sniff added to avoid asking on a 404. Feed pages have
|
|
80
|
+
* no kernel either, so on every /feed/* page in the fleet the question was never asked — silently,
|
|
81
|
+
* with nothing to notice it. A trust decision must never be inferred from an unrelated layout
|
|
82
|
+
* detail; the check is gone, and any page that renders the sheet may ask.
|
|
83
|
+
*
|
|
84
|
+
* ONLY A CHOICE MAY BE REMEMBERED AS A CHOICE. "confirm" is the heart, "denied" is a chosen
|
|
85
|
+
* "Stay invisible". Anything else — Escape, a tap on the backdrop — is not an answer: nothing is
|
|
86
|
+
* stored, the regional default stands, and the ask returns next visit. The session flag only keeps
|
|
87
|
+
* THIS visit quiet, so one slip-away buys one visit of peace rather than an answer nobody gave.
|
|
88
|
+
*
|
|
89
|
+
* THE DOOR IS UNIVERSAL. The footer's hidden `[data-consent-open]` anchor is labelled, revealed and
|
|
90
|
+
* wired here for EVERY visitor in EVERY region — a non-EEA visitor gets a real opt-out they were
|
|
91
|
+
* never offered, and anyone can reverse either answer. Only the AUTO-ask has narrow gates.
|
|
92
|
+
*
|
|
93
|
+
* THE TIMEZONE LIST IS A PROXY for "consent is legally asked here", never the thing itself, and it is
|
|
94
|
+
* the sibling of the region array in {@link analyticsJs}. `Europe/` carries almost all of the EEA but
|
|
95
|
+
* not all of it: twelve zones sit on other continents. Change one list and you must change the other,
|
|
96
|
+
* or a visitor is denied by region while never being offered the dialog.
|
|
97
|
+
*
|
|
98
|
+
* `returnValue` survives a close, so it is reset before every open or a stale answer replays.
|
|
99
|
+
*
|
|
100
|
+
* FOCUS IS GIVEN AT OPEN, not by an autofocus attribute. Chrome refuses to process `autofocus` in
|
|
101
|
+
* any document whose URL carries a fragment and warns on every load — /me#profile met it first. So
|
|
102
|
+
* the sheet ships no attribute, and the opener places focus by the genre's law: the ask genre puts
|
|
103
|
+
* it on the invitation (here), the destructive genre on the cancel (that consumer's own open).
|
|
104
|
+
*/
|
|
105
|
+
export declare const CONSENT_JS = "(function(){try{\nvar h=location.hostname;\nif(h===\"localhost\"||h===\"127.0.0.1\"||h===\"::1\"||h===\"[::1]\"||h.indexOf(\"dev-\")===0)return;\nvar el=document.getElementById(\"consent\");if(!el||!el.showModal)return;\nvar open=function(){if(!el.open){el.returnValue=\"\";el.showModal();var p=el.querySelector(\".preferred\");if(p)p.focus()}};\nel.addEventListener(\"close\",function(){\nvar rv=el.returnValue;\nvar v=rv===\"confirm\"?\"granted+ads\":rv===\"denied\"?\"denied\":null;\nif(v){var g=v===\"denied\"?\"denied\":\"granted\";\ngtag(\"consent\",\"update\",{analytics_storage:g,ad_storage:g,ad_user_data:g});\ntry{localStorage.setItem(\"consent\",v)}catch(_){}}\nelse{try{sessionStorage.setItem(\"consent-later\",\"1\")}catch(_){}}\n});\nvar doors=document.querySelectorAll(\"[data-consent-open]\");\nfor(var i=0;i<doors.length;i++){var a=doors[i];\nif(!a.textContent)a.textContent=el.getAttribute(\"data-choice-label\")||\"privacy choice\";\na.hidden=false;var w=a.closest(\"[data-consent-door]\");if(w)w.hidden=false;\na.addEventListener(\"click\",function(ev){ev.preventDefault();open()})}\nif(localStorage.getItem(\"consent\"))return;\ntry{if(sessionStorage.getItem(\"consent-later\"))return}catch(_){}\nvar tz=Intl.DateTimeFormat().resolvedOptions().timeZone||\"\";\nvar asked=tz.indexOf(\"Europe/\")===0||[\n\"Asia/Nicosia\",\"Asia/Famagusta\",\n\"Atlantic/Canary\",\"Atlantic/Azores\",\"Atlantic/Madeira\",\"Atlantic/Reykjavik\",\n\"Arctic/Longyearbyen\",\n\"America/Guadeloupe\",\"America/Martinique\",\"America/Cayenne\",\n\"Indian/Reunion\",\"Indian/Mayotte\"].indexOf(tz)>=0;\nif(!asked)return;\nsetTimeout(open,700);\n}catch(_){}})();";
|