@justai/core 0.34.1 → 0.36.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/src/index.js DELETED
@@ -1,1612 +0,0 @@
1
- /**
2
- * @justai/core — the framework-free heart of the persona shell.
3
- *
4
- * The load-bearing behaviour of every persona page is plain JavaScript and CSS. It does not care
5
- * whether an Astro template or a React component put it in the head — the SAME string of JS captures
6
- * the SSO token whether it is injected with `set:html` or `dangerouslySetInnerHTML`. So it lives HERE,
7
- * once, and the framework bindings (@justai/cuts for Astro, and a Next equivalent) inject it. When a
8
- * string of shell logic lives inside a `.astro` component, a `.tsx` file that needs the same thing has
9
- * no choice but to hand-copy it — which is exactly how `feed` (Next) came to carry its own byte-for-byte
10
- * copy of the auth capture below. Two copies in two frameworks drift the same way nine copies in one
11
- * framework did; this package is the fix, one level lower than @justai/cuts.
12
- *
13
- * These are STRINGS, deliberately, not functions that build DOM — because the thing that is identical
14
- * across frameworks is the behaviour, and the thing that differs is only how a head is assembled. Keep
15
- * anything framework-specific (JSX, Astro directives, `define:vars`) OUT of here.
16
- *
17
- * Whenever you change one of these, you are changing it for every persona on both frameworks at once —
18
- * which is the point, and the responsibility. The reasons that make each one load-bearing live in
19
- * @justai/web's expert corpus (the-shell-guarantees-you-cannot-see), where they survive a refactor of
20
- * the code that carries them.
21
- */
22
-
23
- /**
24
- * Capture the SSO token from the URL fragment, synchronously, and stash it for the deferred auth SDK.
25
- *
26
- * MUST run before anything else can touch `location.hash`. Two later scripts would otherwise take it:
27
- * a scroll-spy that rewrites the hash to `#kernel` CLOBBERS `#auth_token` before the SDK reads it, and
28
- * a language picker that copies the current hash onto the next locale's URL would PROPAGATE the raw
29
- * token into history. Injecting this first, in the head, defeats both. Move it later and sign-in breaks
30
- * SILENTLY — no error, the visitor simply lands back signed out.
31
- */
32
- export const AUTH_CAPTURE_JS =
33
- `(function(){try{var h=location.hash||"";var m=h.match(/(?:^#|&)auth_token=([^&]+)/);` +
34
- `if(m){localStorage.setItem("justai_token",decodeURIComponent(m[1]))}` +
35
- `else if(/(?:^#|&)auth_signout=1\\b/.test(h)){localStorage.removeItem("justai_token")}else{return}` +
36
- `history.replaceState(null,"",location.pathname+location.search)}catch(e){}})();`;
37
-
38
- /** Mark that JavaScript is running, so the reveal below can hold paint only when JS can un-hold it. */
39
- export const JS_CLASS_JS = `document.documentElement.classList.add("js")`;
40
-
41
- /**
42
- * queries: design grid · x-ray · ?xray · safe area · title safe · action safe · edge of frame ·
43
- * debug overlay · is my content inside the safe area · does the kernel overlap the toolbar ·
44
- * horizontal bleed · the column is not centred · layout debugging · developing a persona
45
- *
46
- * ── THE X-RAY: THE SHELL'S DESIGN GRID, ON DEMAND ─────────────────────────────────────────────
47
- *
48
- * Open any persona with `?xray` and its skeleton appears over the live page: the kernel's own frame,
49
- * the two safe areas, centre crosshairs, an 8px rhythm, and every number the layout depends on with
50
- * a verdict on each. You look THROUGH the persona's own controls and see whether they sit inside the
51
- * safe areas or cross them.
52
- *
53
- * ── IT IS A PAIR OF GLASSES, NOT A RENOVATION ────────────────────────────────────────────────
54
- *
55
- * The founder's constraint, and it shapes every decision below: turning the x-ray on must not change
56
- * the layout it is measuring. An instrument that moves the thing it measures is not an instrument.
57
- *
58
- * So nothing here touches the page. No class is added to the kernel, no `position: relative`, no
59
- * flow element anywhere — the overlay is `position: fixed` and its coordinates are READ from
60
- * `#kernel.getBoundingClientRect()` on every frame that matters. The page cannot tell it is there.
61
- * `pointer-events: none` throughout, so it cannot even absorb a click.
62
- *
63
- * ── AND WHEN IT IS OFF IT COSTS NOTHING ──────────────────────────────────────────────────────
64
- *
65
- * This whole string returns on its second line unless the flag is present. The stylesheet, the DOM
66
- * and the listeners are built inside that branch: a persona that nobody is debugging ships one
67
- * `if`. A debug feature that is only free when somebody remembers to remove it is one that ships.
68
- *
69
- * The flag is read from `location.search`, so `?xray`, `?xray=1` and `&xray` all work. A flag you
70
- * have to spell exactly right is one you will spell wrong at the moment you need it.
71
- */
72
- export const XRAY_JS = `(() => {
73
- if (!new URLSearchParams(location.search).has("xray")) return;
74
- // IT RUNS IN <head>, SO IT WAITS. The shell mounts this beside its other inline scripts, which is
75
- // the right place — before first paint, so the overlay does not appear a beat late. But #kernel
76
- // does not exist yet at that moment, and the first version simply returned: the flag was read, the
77
- // element was absent, and nothing happened with nothing said. Deferring is one line; finding out
78
- // why an instrument silently does not work is not.
79
- if (document.readyState === "loading") {
80
- return void document.addEventListener("DOMContentLoaded", () => start(), { once: true });
81
- }
82
- start();
83
-
84
- function start() {
85
- var K = () => document.getElementById("kernel");
86
- if (!K()) return;
87
-
88
- var css = document.createElement("style");
89
- css.textContent = [
90
- ".xr{position:fixed;pointer-events:none;z-index:2147483000}",
91
- // ── THE RHYTHM IS DOT PAPER, THE SAME DOT PAPER THE FLEET ALREADY PAINTS ──────────────────
92
- // It was ruled horizontal lines, which is notebook paper: it reads as a THING to look at, it
93
- // fights every horizontal edge in the design, and it says nothing at all about the horizontal
94
- // axis it does not draw. Dots say both axes at once and disappear behind the content, which is
95
- // what a grid under a design is for.
96
- // Same construction as the page background @justai/ui paints on html — a radial-gradient dot on
97
- // a square tile — so the instrument speaks the fleet's own visual language rather than inventing
98
- // a second one. The tile is 8px here rather than the page's 16: this is the 8pt rhythm the
99
- // padding and the margins are actually built on.
100
- //
101
- // NO BACKTICKS ANYWHERE INSIDE THIS STRING. It is a template literal, so one in a COMMENT ends
102
- // it — the file still parses, the script it produces is truncated garbage, and the build fails
103
- // somewhere else entirely. Written here twice tonight before the fixture refused to build.
104
- ".xr-rhythm{background-image:radial-gradient(circle,rgba(128,128,128,.34) 1px,transparent 1.4px);background-size:8px 8px}",
105
- ".xr-f{position:fixed;pointer-events:none;z-index:2147483000}",
106
- // THREE CORNERS, BECAUSE THE ZONES ARE 16px APART AND A LABEL IS 11px TALL. Stacked at one
107
- // corner the way a broadcast overlay does it, they collided the moment the gutter was a
108
- // phone gutter rather than a television one: EDGE OF FRAME sat on ACTION SAFE and the amber
109
- // line ran through both. Broadcast can stack them because its safe margins are 5% and 10% of
110
- // the frame; ours are 16px and 32px. So each zone takes a corner of its own and they cannot
111
- // meet at any width. The colours already say which is which — the words are the confirmation.
112
- ".xr-f>i{position:absolute;font-size:.68rem;font-style:normal;letter-spacing:.07em;text-transform:uppercase;font-weight:700;white-space:nowrap}",
113
- // THEY DIFFER IN BOTH AXES, and the second axis is what makes it work at any gutter: each label
114
- // sits at its own box's top — 16px apart on a phone — AND at a different corner of it. Two of
115
- // them could be one pixel apart vertically and still not touch.
116
- // ALL THREE AT THE TOP, and that is not symmetry. An app kernel is at least a viewport tall, so
117
- // its box ends below the fold: a label anchored to the bottom of the action-safe frame was simply
118
- // not on the screen. Measured, after being written that way first.
119
- ".xr-edge>i{top:3px;right:7px}",
120
- ".xr-act>i{top:3px;left:50%;transform:translateX(-50%)}",
121
- ".xr-ttl>i{top:3px;left:7px}",
122
- // ── THREE ZONES, THREE COLOURS, AND THE ORDER MEANS SOMETHING ─────────────────────────────
123
- // Red, amber, green — outward to inward, danger to safe. Everyone already reads that gradient
124
- // without being taught it, and it is exactly what the three zones say: the edge is where things
125
- // get cut, action-safe is where a control may sit, title-safe is where a word is certain to be
126
- // read. Three greys distinguished only by their dash pattern made the reader count borders.
127
- ".xr-edge{border:3px solid #E8503A}",
128
- ".xr-edge>i{color:#E8503A}",
129
- ".xr-act{border:1.5px solid #F5A623}",
130
- ".xr-act>i{color:#C97F0B}",
131
- ".xr-ttl{border:1.5px dashed #2E9E5B}",
132
- ".xr-ttl>i{color:#2E9E5B}",
133
- // The centre cross runs the WHOLE frame, in both axes. Ticks at the four edges said where the
134
- // middle of each side was and left the reader to imagine the intersection; two full lines put
135
- // the kernel's centre on the screen as a point you can hold something against. Blue, because it
136
- // is the one thing on this overlay that is not a boundary — it is a reference.
137
- ".xr-c{position:fixed;background:rgba(61,111,217,.55);pointer-events:none;z-index:2147483000}",
138
- ".xr-read{position:fixed;left:12px;bottom:12px;pointer-events:none;z-index:2147483001;",
139
- "display:grid;grid-template-columns:auto 1fr;gap:2px 12px;padding:10px 12px;border-radius:10px;",
140
- "background:rgba(20,22,28,.92);color:#f2f4f8;font:400 .78rem/1.35 ui-monospace,SFMono-Regular,Menlo,monospace}",
141
- ".xr-read b{font-weight:400;opacity:.6}",
142
- ".xr-read s{text-decoration:none;font-variant-numeric:tabular-nums}",
143
- ".xr-read s[data-ok=no]{color:#ff6b6b;font-weight:700}",
144
- ".xr-read s[data-ok=yes]{color:#7ee787}",
145
- ].join("");
146
- document.head.appendChild(css);
147
-
148
- var mk = (cls, html) => { var d = document.createElement("div"); d.className = cls; if (html) d.innerHTML = html; document.body.appendChild(d); return d; };
149
- var rhythm = mk("xr xr-rhythm");
150
- var edge = mk("xr-f xr-edge", "<i>edge of frame</i>");
151
- var act = mk("xr-f xr-act", "<i>action safe</i>");
152
- var ttl = mk("xr-f xr-ttl", "<i>title safe</i>");
153
- var cross = [0,1].map(() => mk("xr-c"));
154
- var read = mk("xr-read");
155
-
156
- var row = (label) => {
157
- var b = document.createElement("b"); b.textContent = label;
158
- var s = document.createElement("s");
159
- read.appendChild(b); read.appendChild(s);
160
- return s;
161
- };
162
- var R = { viewport: row("viewport"), column: row("column"), gutter: row("gutter L/R"),
163
- frame: row("frame"), inset: row("kernel inset"), act: row("action safe"), ttl: row("title safe"),
164
- bar: row("toolbar"), clear: row("clears bar"), safe: row("safe area L/R"),
165
- bleed: row("bleed") };
166
- var put = (el, text, ok) => { el.textContent = text; if (ok !== undefined) el.dataset.ok = ok ? "yes" : "no"; };
167
- var px = (n) => Math.round(n * 10) / 10 + "px";
168
- var box = (el, r, inset) => {
169
- el.style.left = (r.left + inset) + "px"; el.style.top = (r.top + inset) + "px";
170
- el.style.width = Math.max(0, r.width - inset * 2) + "px";
171
- el.style.height = Math.max(0, r.height - inset * 2) + "px";
172
- };
173
-
174
- var draw = () => {
175
- var k = K(); if (!k) return;
176
- var r = k.getBoundingClientRect();
177
- var app = document.querySelector(".app");
178
- var cs = app ? getComputedStyle(app) : null;
179
- var padL = cs ? parseFloat(cs.paddingLeft) || 0 : 0;
180
- var padR = cs ? parseFloat(cs.paddingRight) || 0 : 0;
181
- var g = cs ? parseFloat(cs.getPropertyValue("--gutter")) || 16 : 16;
182
-
183
- box(edge, r, 0); box(act, r, g); box(ttl, r, g * 2); box(rhythm, r, 0);
184
-
185
- // THE CENTRE CROSS, EDGE TO EDGE. Their intersection IS the kernel's centre — the one point a
186
- // design gets measured against and the one an eye cannot find on its own. Drawn across the whole
187
- // frame rather than as ticks, so anything meant to be centred can be held against a line instead
188
- // of against a guess about where two marks would have met.
189
- var t = [[r.left + r.width / 2, r.top, 1, r.height],
190
- [r.left, r.top + r.height / 2, r.width, 1]];
191
- cross.forEach((el, i) => { el.style.left = t[i][0] + "px"; el.style.top = t[i][1] + "px";
192
- el.style.width = t[i][2] + "px"; el.style.height = t[i][3] + "px"; });
193
-
194
- var aw = app ? app.getBoundingClientRect().width : r.width;
195
- put(R.viewport, Math.round(innerWidth) + " x " + Math.round(innerHeight));
196
- put(R.column, px(aw), aw <= 640);
197
- var even = Math.abs(padL - padR) < 0.5;
198
- put(R.gutter, px(padL) + " / " + px(padR) + (even ? "" : " <- the two sides differ"), even);
199
- put(R.frame, px(r.width) + " x " + px(r.height));
200
- // THE KERNEL'S OWN INSET, WITH THE LAW IT IS JUDGED AGAINST. Two laws, and which one applies is
201
- // read from the document rather than guessed: an APP kernel is inset by the gutter on all four
202
- // sides, a GAME kernel by nothing at all. This row is the reason the second law stopped being
203
- // sixteen copies — 8px sat at the bottom of every persona in the fleet, matching neither the top
204
- // nor the sides, and there was nowhere it was ever printed next to what it should have been.
205
- var kind = document.documentElement.dataset.kind || "app";
206
- var ks = getComputedStyle(k);
207
- var kp = [ks.paddingTop, ks.paddingRight, ks.paddingBottom, ks.paddingLeft].map((v) => parseFloat(v) || 0);
208
- // ONE NUMBER ON ALL FOUR SIDES — the frame is the active view for both kinds now, so what tells
209
- // them apart is the padding INSIDE it: an app pads by the gutter, which puts its content exactly
210
- // on the action-safe ring below, and a game pads by nothing.
211
- // The bottom may EXCEED it and only the bottom may: env(safe-area-inset-bottom) is the strip the
212
- // OS keeps for its home indicator, and it is added rather than substituted.
213
- var want = kind === "game" ? 0 : g;
214
- var insetOk = kp[0] === want && kp[1] === want && kp[3] === want && kp[2] >= want;
215
- put(R.inset, kp.join(" / ") + " (" + kind + " wants " + want + ")", insetOk);
216
- put(R.act, "inset " + px(g) + " . " + px(r.width - g * 2) + " wide");
217
- put(R.ttl, "inset " + px(g * 2) + " . " + px(r.width - g * 4) + " wide");
218
-
219
- var bar = document.querySelector(".toolbar");
220
- if (bar) {
221
- var bh = bar.getBoundingClientRect().height;
222
- // Scroll-independent on purpose: comparing the kernel's top to the bar's bottom in viewport
223
- // coordinates reports an overlap the moment the page has scrolled. The real question is about
224
- // the LANDING — the bar is sticky, the page lands on #kernel, and scroll-margin-top decides
225
- // whether the first thing here arrives below the bar or underneath it.
226
- var landing = parseFloat(getComputedStyle(k).scrollMarginTop) || 0;
227
- var air = landing - bh;
228
- put(R.bar, px(bh) + " . lands at " + px(landing));
229
- put(R.clear, air < -0.5 ? px(air) + " <- kernel UNDER the bar" : px(air), air >= -0.5);
230
- } else { put(R.bar, "none"); put(R.clear, "-"); }
231
-
232
- // env() is not readable from JS, so it is measured: what the browser applied minus what the CSS
233
- // asked for IS the safe area.
234
- put(R.safe, px(Math.max(0, padL - g)) + " / " + px(Math.max(0, padR - g)));
235
- var over = Math.max(0, Math.round(document.documentElement.scrollWidth - innerWidth));
236
- put(R.bleed, over ? over + "px past the viewport" : "none", over === 0);
237
- };
238
-
239
- var tick = false;
240
- var schedule = () => { if (tick) return; tick = true; requestAnimationFrame(() => { tick = false; draw(); }); };
241
- draw();
242
- addEventListener("resize", schedule, { passive: true });
243
- addEventListener("scroll", schedule, { passive: true });
244
- if (document.fonts && document.fonts.ready) document.fonts.ready.then(draw);
245
- }
246
- })()`;
247
-
248
- /**
249
- * Hold the paint until a page marks itself ready (`body.ready`), gated behind `.js` so the page is
250
- * always visible with JS off and never flashes before positioning at the Kernel.
251
- *
252
- * This is a TRAP as much as a feature, and the warning belongs beside it: ANY page using this without a
253
- * script that sets `body.ready` stays invisible FOREVER, and nothing errors — the page is simply never
254
- * shown. A page with no kernel script (a 404, or a sub-persona like feed) must carry {@link READY_JS}.
255
- */
256
- export const REVEAL_CSS = `html.js body{opacity:0}html.js body.ready{opacity:1}`;
257
-
258
- /**
259
- * The other half of {@link REVEAL_CSS}, for a page that has no kernel script to reveal it: set
260
- * `body.ready` as soon as the body exists, and once more after load as a backstop. This is what keeps
261
- * a sub-persona page (feed, a 404) from falling into the reveal trap.
262
- */
263
- export const READY_JS =
264
- `var r=function(){document.body&&document.body.classList.add("ready")};` +
265
- `if(document.readyState!=="loading")r();else addEventListener("DOMContentLoaded",r);setTimeout(r,400);`;
266
-
267
- /**
268
- * queries: which measurement id does this host use · wrong GA4 stream · a persona reports into the
269
- * wrong property · G-13L3BP6XCW vs G-K2J4FQTQ8L · how does feed pick its analytics tag
270
- *
271
- * THE ECOSYSTEM'S STREAM LAYOUT, declared once.
272
- *
273
- * One GA4 property, two web streams: `G-13L3BP6XCW` for app.zone and its personas, `G-K2J4FQTQ8L`
274
- * for justai.pro and its own sub-domains. A page reports into whichever stream ITS CODE loads, so
275
- * "app.zone versus justai.pro" is a fact about our code rather than a rule the platform enforces —
276
- * put a persona on the wrong one and nothing errors, nothing is missing, the numbers simply land in
277
- * the wrong column. That is why the mapping is a function here and not a constant copied per repo.
278
- *
279
- * A STATIC persona cannot call this — it has no host at build time — so @justai/cuts keeps its own
280
- * default and `justai` passes the override. A SERVER-rendered surface (feed) knows the Host header
281
- * and must use this. The two must agree; if a third stream ever appears, this is the one place it
282
- * is added.
283
- */
284
- export function measurementIdFor(host) {
285
- const h = String(host || "").toLowerCase().split(":")[0];
286
- return h === "justai.pro" || h.endsWith(".justai.pro") ? "G-K2J4FQTQ8L" : "G-13L3BP6XCW";
287
- }
288
-
289
- /**
290
- * queries: analytics inline script · gtag block · consent defaults · why is dev traffic in GA4 ·
291
- * non-production guard · localhost 127.0.0.1 in analytics · how does a page start measuring
292
- *
293
- * The whole analytics head block, for any framework, given a measurement id.
294
- *
295
- * Everything load-bearing about it, in the order it matters:
296
- *
297
- * A NON-PRODUCTION PAGE MEASURES NOTHING. Found by reading the property through the analytics MCP:
298
- * `127.0.0.1` and `localhost` were its TOP "persona" — 546 sessions in four days, and on one of them
299
- * 127.0.0.1 alone outranked every real persona. Local dev and every headless verification sweep
300
- * loading built HTML. The guard also covers the edge's `dev-` preview hosts: previews are rehearsals,
301
- * not visits. Everything before 2026-07-24 in that property is inflated by this.
302
- *
303
- * `gtag` GOES ON `window`, never `function gtag`. A framework that scopes an injected variable wraps
304
- * this in an IIFE, and a function declaration would then be trapped inside it — while the consent
305
- * dialog's own script, elsewhere on the page, calls `gtag`. The failure is silent and specific: a
306
- * European visitor clicks Allow, "gtag is not defined", the choice is never applied and the sheet
307
- * never closes. The stub is also assigned BEFORE the guard returns, so a silenced host still has a
308
- * callable `gtag` and that same script cannot throw there either.
309
- *
310
- * CONSENT DEFAULTS, twice — REVISED 2026-07-25 with the founder, and the revision IS the doctrine:
311
- * MEASUREMENT follows one rule everywhere (granted by default, EEA asks first), PROFILING is refused
312
- * everywhere forever. Globally: analytics_storage + ad_storage + ad_user_data granted — counting the
313
- * visit, and telling an ad its click worked; the dialog's question covers both, in the visitor's
314
- * language. ad_personalization is DENIED with no path anywhere, which is what keeps "never who"
315
- * true. The EEA + UK + CH region list denies everything until the dialog's answer — where consent is
316
- * owed we ask first; where it is not, measurement is simply on (the founder's explicit instruction).
317
- *
318
- * STORED CHOICES ARE VERSIONED: "granted+ads" replays the full grant, a legacy "granted" replays
319
- * analytics ONLY — a visitor who said yes to the narrower question is never silently upgraded to the
320
- * wider one. "denied" denies the measurement trio.
321
- *
322
- * LEGAL POSTURE, noted with the founder: one sentence carries two purposes (counting + ad
323
- * measurement), both stated plainly — defensible at today's traffic; when traffic grows, granular
324
- * consent (two separate switches) should be revisited. ad_personalization staying dead is the
325
- * strongest card in that file.
326
- *
327
- * The region list has a sibling: the timezone list in the consent dialog's script. Change one and
328
- * the other must change, or a visitor is denied by region while never being offered the dialog.
329
- *
330
- * `page_title` IS PINNED at load. Only one persona mutates `document.title` today — time shows a live
331
- * clock — and without this its analytics reports "13:32 · Amsterdam" as the page name. It costs every
332
- * other persona nothing and removes a trap the next persona that animates its tab would walk into.
333
- *
334
- * The tag itself loads on idle after `load`: measurement must never compete with the kernel.
335
- *
336
- * WRAPPED IN AN IIFE, and it has to be. The Astro binding used to get one for free from `define:vars`;
337
- * lifting the block out of the template removed it, and the locals became globals on every persona
338
- * page — three names a persona could collide with, leaked by the shell, with nothing to notice it. A
339
- * shared shell does not put anything in the global scope it did not mean to. `window.gtag` is still
340
- * assigned explicitly on window, which is the one thing that MUST escape.
341
- */
342
- export function analyticsJs(gaId) {
343
- return `(function(){
344
- window.gtag=window.gtag||function(){(window.dataLayer=window.dataLayer||[]).push(arguments)};
345
- var __h=location.hostname;
346
- if(!(__h==="localhost"||__h==="127.0.0.1"||__h==="::1"||__h==="[::1]"||__h.indexOf("dev-")===0)){
347
- var __g=${JSON.stringify(gaId)};
348
- window.dataLayer=window.dataLayer||[];
349
- window.gtag=window.gtag||function(){window.dataLayer.push(arguments)};
350
- gtag("js",new Date());
351
- gtag("consent","default",{ad_storage:"granted",ad_user_data:"granted",ad_personalization:"denied",analytics_storage:"granted"});
352
- 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"});
353
- try{var __c=localStorage.getItem("consent");
354
- if(__c==="granted+ads")gtag("consent","update",{analytics_storage:"granted",ad_storage:"granted",ad_user_data:"granted"});
355
- else if(__c==="granted")gtag("consent","update",{analytics_storage:"granted"});
356
- else if(__c==="denied")gtag("consent","update",{analytics_storage:"denied",ad_storage:"denied",ad_user_data:"denied"})}catch(e){}
357
- 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});
358
- 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)})});
359
- }})();`;
360
- }
361
-
362
-
363
- /**
364
- * queries: where does the consent dialog text live · change the consent wording · consentText ·
365
- * consentAllow consentDecline consentChoice · why is the consent copy not in the persona ·
366
- * feed cannot show the consent sheet · translate the consent question
367
- *
368
- * THE CONSENT COPY — the ecosystem's question to a visitor, in thirteen languages, said once.
369
- *
370
- * It used to live in every persona's own dictionary: thirteen languages across thirteen repos, and
371
- * measured before this moved, all 52 strings were byte-identical in all of them. That is the tell.
372
- * A persona's dictionary holds what makes it that persona; this is the ECOSYSTEM speaking, and the
373
- * same sentence copied into a hundred and sixty-nine files is not localisation, it is a maintenance
374
- * bill. Changing one word meant thirteen pull requests, and getting twelve of them right meant a
375
- * visitor somewhere read an older promise than the one we thought we were making.
376
- *
377
- * It is legally load-bearing text. There is exactly one place it may be edited, and this is it.
378
- *
379
- * WHY HERE rather than in @justai/cuts: `feed` renders on every persona's host and depends on core,
380
- * not on cuts. Putting the copy where only the Astro shell could reach it is what kept feed from
381
- * asking the question at all. Content, like behaviour, belongs at the layer every face can reach.
382
- *
383
- * A locale with no entry falls back to English rather than rendering an empty sheet — a missing
384
- * translation must never become a dialog with no question in it.
385
- */
386
- export const CONSENT_COPY = {
387
- "ar": {
388
- "consentText": "أودّ أن أعرف أنّ أحدًا زارني — بشكل مجهول، دون معرفة من هو أبدًا. هل لي أن أحسب زيارتك — وإن كان إعلانٌ قد أوصلك إلى هنا، أن أخبره أنه نجح؟",
389
- "consentAllow": "احسبني ❤️",
390
- "consentDecline": "أبقِني خفيًّا",
391
- "consentChoice": "خيار الخصوصية"
392
- },
393
- "de": {
394
- "consentText": "Ich wüsste gern, dass jemand da war — anonym, nie wer. Darf ich deinen Besuch zählen — und falls dich eine Anzeige hergebracht hat, ihr sagen, dass sie gewirkt hat?",
395
- "consentAllow": "Zähl mich mit ❤️",
396
- "consentDecline": "Unsichtbar bleiben",
397
- "consentChoice": "Privatsphäre-Wahl"
398
- },
399
- "en": {
400
- "consentText": "I'd love to know someone was here — anonymously, never who. May I count your visit, and if an ad brought you here, let it know it worked?",
401
- "consentAllow": "Count me in ❤️",
402
- "consentDecline": "Stay invisible",
403
- "consentChoice": "privacy choice"
404
- },
405
- "es": {
406
- "consentText": "Me encantaría saber que alguien estuvo aquí — de forma anónima, nunca quién. ¿Puedo contar tu visita y, si un anuncio te trajo hasta aquí, decirle que funcionó?",
407
- "consentAllow": "Cuenta conmigo ❤️",
408
- "consentDecline": "Seguir invisible",
409
- "consentChoice": "elección de privacidad"
410
- },
411
- "fr": {
412
- "consentText": "J'aimerais savoir que quelqu'un est passé — anonymement, jamais qui. Puis-je compter ta visite — et si une publicité t'a amené ici, lui dire qu'elle a fonctionné ?",
413
- "consentAllow": "Compte ma visite ❤️",
414
- "consentDecline": "Rester invisible",
415
- "consentChoice": "choix de confidentialité"
416
- },
417
- "hi": {
418
- "consentText": "मुझे यह जानना अच्छा लगेगा कि कोई आया था — गुमनाम तौर पर, कभी नहीं कि कौन। क्या मैं आपकी विज़िट गिन सकता हूँ — और अगर कोई विज्ञापन आपको यहाँ लाया, तो उसे बता दूँ कि उसने काम किया?",
419
- "consentAllow": "मुझे गिनो ❤️",
420
- "consentDecline": "अदृश्य रहूँ",
421
- "consentChoice": "गोपनीयता विकल्प"
422
- },
423
- "it": {
424
- "consentText": "Mi piacerebbe sapere che qualcuno è passato — in forma anonima, mai chi. Posso contare la tua visita — e, se ti ha portato qui una pubblicità, dirle che ha funzionato?",
425
- "consentAllow": "Contami ❤️",
426
- "consentDecline": "Resta invisibile",
427
- "consentChoice": "scelta privacy"
428
- },
429
- "ja": {
430
- "consentText": "誰かが来てくれたことだけ知りたいのです — 匿名で、誰かは決して分かりません。訪問を数えてもいいですか?広告がきっかけで来てくれたなら、役に立ったと広告に伝えてもいいですか?",
431
- "consentAllow": "数えていいよ ❤️",
432
- "consentDecline": "見えないままで",
433
- "consentChoice": "プライバシー設定"
434
- },
435
- "nl": {
436
- "consentText": "Ik zou graag weten dat er iemand was — anoniem, nooit wie. Mag ik je bezoek meetellen — en als een advertentie je hierheen bracht, laten weten dat die werkte?",
437
- "consentAllow": "Tel me mee ❤️",
438
- "consentDecline": "Onzichtbaar blijven",
439
- "consentChoice": "privacykeuze"
440
- },
441
- "pt": {
442
- "consentText": "Adoraria saber que alguém esteve aqui — anonimamente, nunca quem. Posso contar sua visita — e, se um anúncio trouxe você até aqui, dizer a ele que funcionou?",
443
- "consentAllow": "Conta comigo ❤️",
444
- "consentDecline": "Ficar invisível",
445
- "consentChoice": "escolha de privacidade"
446
- },
447
- "ru": {
448
- "consentText": "Мне бы хотелось знать, что кто-то заходил — анонимно, и никогда кто именно. Можно посчитать твой визит — и, если тебя привела реклама, дать ей знать, что она сработала?",
449
- "consentAllow": "Посчитай меня ❤️",
450
- "consentDecline": "Остаться невидимым",
451
- "consentChoice": "выбор приватности"
452
- },
453
- "tr": {
454
- "consentText": "Birinin uğradığını bilmek isterim — anonim olarak, asla kim olduğunu değil. Ziyaretini sayabilir miyim — ve seni buraya bir reklam getirdiyse, ona işe yaradığını söyleyebilir miyim?",
455
- "consentAllow": "Beni say ❤️",
456
- "consentDecline": "Görünmez kalayım",
457
- "consentChoice": "gizlilik tercihi"
458
- },
459
- "zh": {
460
- "consentText": "我只想知道有人来过 — 完全匿名,永远不知道是谁。可以把你的访问算上吗——如果是广告把你带来的,也让它知道它起了作用?",
461
- "consentAllow": "算上我 ❤️",
462
- "consentDecline": "保持隐身",
463
- "consentChoice": "隐私选择"
464
- }
465
- };
466
-
467
- /** The consent copy for a language, falling back to English. Never returns undefined. */
468
- export function consentCopy(lang) {
469
- return CONSENT_COPY[String(lang || "en").toLowerCase()] || CONSENT_COPY.en;
470
- }
471
-
472
-
473
- /**
474
- * queries: the sheet says Cancel in English · Cancel is not translated · Done is not translated ·
475
- * the picker's cancel stays English in Arabic · sheet chrome language · translate a cut ·
476
- * who owns the word Cancel · CHROME_COPY · a component's own words
477
- *
478
- * THE CHROME WORDS — Cancel and Done, in thirteen languages, said once.
479
- *
480
- * The same argument as CONSENT_COPY above, and found the same way: a picker opened on an Arabic page
481
- * with every word around it in Arabic and `Cancel` in English, sitting in the sheet's own bar.
482
- *
483
- * `<Sheet>` had defaulted its Done to the literal "Done" and reasoned, in a comment, that a label is
484
- * a prop "because the fleet speaks thirteen languages, and a cut that hardcoded the English would be
485
- * a component making its consumer's copy decisions". The reasoning was inverted. Handing the word to
486
- * the consumer does not avoid the decision — it makes it THIRTEEN TIMES, in every repo, and the
487
- * hardcoded English default proved it: the cut was already deciding, and deciding wrong.
488
- *
489
- * These are not a persona's copy. `Cancel` is not qr's word or files' word; it is the ecosystem's,
490
- * the way the back chevron is the ecosystem's shape. Law 1 — a component brings its own ground,
491
- * style AND text — is what says the cut must carry them.
492
- *
493
- * WHY HERE rather than in @justai/cuts: same reason the consent copy is here. Every face reaches
494
- * core; only the Astro shell reaches cuts.
495
- *
496
- * LIFTED FROM `files`, BYTE FOR BYTE, and that is the point rather than an economy. The file kernel
497
- * mounts INSIDE a host's sheet: the guest draws its own cancel in the body and the host draws one in
498
- * the bar, and a person looking at one surface must not be shown two different words for the one
499
- * way out. One word per meaning — the same rule the `nameTaken` string learned the hard way.
500
- */
501
- export const CHROME_COPY = {
502
- "ar": { "cancel": "إلغاء", "done": "تم" },
503
- "de": { "cancel": "Abbrechen", "done": "Fertig" },
504
- "en": { "cancel": "Cancel", "done": "Done" },
505
- "es": { "cancel": "Cancelar", "done": "Listo" },
506
- "fr": { "cancel": "Annuler", "done": "OK" },
507
- "hi": { "cancel": "रद्द करें", "done": "हो गया" },
508
- "it": { "cancel": "Annulla", "done": "Fine" },
509
- "ja": { "cancel": "キャンセル", "done": "完了" },
510
- "nl": { "cancel": "Annuleren", "done": "Klaar" },
511
- "pt": { "cancel": "Cancelar", "done": "Concluído" },
512
- "ru": { "cancel": "Отмена", "done": "Готово" },
513
- "tr": { "cancel": "Vazgeç", "done": "Bitti" },
514
- "zh": { "cancel": "取消", "done": "完成" }
515
- };
516
-
517
- /** The chrome words for a language, falling back to English. Never returns undefined. */
518
- export function chromeCopy(lang) {
519
- return CHROME_COPY[String(lang || "en").toLowerCase().split("-")[0]] || CHROME_COPY.en;
520
- }
521
-
522
-
523
- /**
524
- * queries: consent dialog script · why does the sheet not appear on some pages · consent is asked
525
- * per domain not per page · getElementById kernel · the sheet never opened on feed ·
526
- * only a choice may be remembered · the change-your-mind door · consent timezone list
527
- *
528
- * The consent dialog's behaviour — one copy, for every surface on a persona's origin.
529
- *
530
- * CONSENT IS SCOPED TO THE ORIGIN, NOT TO A PAGE. Whichever page a visitor enters by, if this origin
531
- * has never asked, it asks — once. That is what a consent flow IS, and it is worth stating because
532
- * ours was accidentally page-scoped for three weeks: the script used to bail on
533
- * `!document.getElementById("kernel")`, a DOM sniff added to avoid asking on a 404. Feed pages have
534
- * no kernel either, so on every /feed/* page in the fleet the question was never asked — silently,
535
- * with nothing to notice it. A trust decision must never be inferred from an unrelated layout
536
- * detail; the check is gone, and any page that renders the sheet may ask.
537
- *
538
- * ONLY A CHOICE MAY BE REMEMBERED AS A CHOICE. "confirm" is the heart, "denied" is a chosen
539
- * "Stay invisible". Anything else — Escape, a tap on the backdrop — is not an answer: nothing is
540
- * stored, the regional default stands, and the ask returns next visit. The session flag only keeps
541
- * THIS visit quiet, so one slip-away buys one visit of peace rather than an answer nobody gave.
542
- *
543
- * THE DOOR IS UNIVERSAL. The footer's hidden `[data-consent-open]` anchor is labelled, revealed and
544
- * wired here for EVERY visitor in EVERY region — a non-EEA visitor gets a real opt-out they were
545
- * never offered, and anyone can reverse either answer. Only the AUTO-ask has narrow gates.
546
- *
547
- * THE TIMEZONE LIST IS A PROXY for "consent is legally asked here", never the thing itself, and it is
548
- * the sibling of the region array in {@link analyticsJs}. `Europe/` carries almost all of the EEA but
549
- * not all of it: twelve zones sit on other continents. Change one list and you must change the other,
550
- * or a visitor is denied by region while never being offered the dialog.
551
- *
552
- * `returnValue` survives a close, so it is reset before every open or a stale answer replays.
553
- *
554
- * FOCUS IS GIVEN AT OPEN, not by an autofocus attribute. Chrome refuses to process `autofocus` in
555
- * any document whose URL carries a fragment and warns on every load — /me#profile met it first. So
556
- * the sheet ships no attribute, and the opener places focus by the genre's law: the ask genre puts
557
- * it on the invitation (here), the destructive genre on the cancel (that consumer's own open).
558
- */
559
- export const CONSENT_JS = `(function(){try{
560
- var h=location.hostname;
561
- if(h==="localhost"||h==="127.0.0.1"||h==="::1"||h==="[::1]"||h.indexOf("dev-")===0)return;
562
- var el=document.getElementById("consent");if(!el||!el.showModal)return;
563
- var open=function(){if(!el.open){el.returnValue="";el.showModal();var p=el.querySelector(".preferred");if(p)p.focus()}};
564
- el.addEventListener("close",function(){
565
- var rv=el.returnValue;
566
- var v=rv==="confirm"?"granted+ads":rv==="denied"?"denied":null;
567
- if(v){var g=v==="denied"?"denied":"granted";
568
- gtag("consent","update",{analytics_storage:g,ad_storage:g,ad_user_data:g});
569
- try{localStorage.setItem("consent",v)}catch(_){}}
570
- else{try{sessionStorage.setItem("consent-later","1")}catch(_){}}
571
- });
572
- var doors=document.querySelectorAll("[data-consent-open]");
573
- for(var i=0;i<doors.length;i++){var a=doors[i];
574
- if(!a.textContent)a.textContent=el.getAttribute("data-choice-label")||"privacy choice";
575
- a.hidden=false;var w=a.closest("[data-consent-door]");if(w)w.hidden=false;
576
- a.addEventListener("click",function(ev){ev.preventDefault();open()})}
577
- if(localStorage.getItem("consent"))return;
578
- try{if(sessionStorage.getItem("consent-later"))return}catch(_){}
579
- var tz=Intl.DateTimeFormat().resolvedOptions().timeZone||"";
580
- var asked=tz.indexOf("Europe/")===0||[
581
- "Asia/Nicosia","Asia/Famagusta",
582
- "Atlantic/Canary","Atlantic/Azores","Atlantic/Madeira","Atlantic/Reykjavik",
583
- "Arctic/Longyearbyen",
584
- "America/Guadeloupe","America/Martinique","America/Cayenne",
585
- "Indian/Reunion","Indian/Mayotte"].indexOf(tz)>=0;
586
- if(!asked)return;
587
- setTimeout(open,700);
588
- }catch(_){}})();`;
589
-
590
- // queries: is this persona standalone or embedded · how does a persona know it is inside another
591
- // persona · mode=atrium · presentation mode · a sub-persona should not show Cancel when
592
- // opened directly · does this page have a caller
593
- //
594
- // WHICH PRESENTATION A PERSONA IS IN, AND WHY IT IS A QUESTION AT ALL.
595
- //
596
- // The founder, 2026-07-27, looking at `/files` opened directly in a tab and still wearing the
597
- // clothes it wears inside somebody else's sheet:
598
- //
599
- // "bir persona veya sub personanin kendisinin standalone calisip calismadigini bilmesi gerekir
600
- // ki ona gore ux deneyiminde degisiklige gidebilsin"
601
- //
602
- // A page opened by a person and a page opened by another persona are two different situations, and
603
- // the same controls do not belong in both. Standalone there is nothing to cancel — "Cancel" is a
604
- // button with no meaning, offered to somebody who never asked a question. "Choose from device" is
605
- // the phrasing of an answer; alone, the same control is simply "Upload".
606
- //
607
- // TWO SIGNALS, AND THEY ANSWER DIFFERENT QUESTIONS:
608
- //
609
- // · `window.parent !== window` is the BROWSER's answer to "am I in a frame". It is true and it is
610
- // free, but it says nothing about who put us there or what they want.
611
- // · `?mode=atrium` is the CALLER's declaration of the experience it is asking for. It is a claim —
612
- // anyone can type it — and that is fine, because it decides nothing but presentation.
613
- //
614
- // So both are required, and neither is a permission. Anything that must not be forged (who may read
615
- // a file, whose persona owns a write) is decided by the verified origin on the atrium channel, never
616
- // by this. What this decides is which words a person reads.
617
- //
618
- // The param exists at all because the frame is the SLOWER truth: a handshake takes a beat, and a
619
- // page that waits for it shows the wrong chrome first and then rearranges itself in front of the
620
- // person. The declaration is available in the first paint.
621
- export const PRESENTATION_PARAM = "mode";
622
- export const PRESENTATION_EMBEDDED = "atrium";
623
-
624
- export function presentation(loc, win) {
625
- const l = loc || (typeof location !== "undefined" ? location : null);
626
- const w = win || (typeof window !== "undefined" ? window : null);
627
- if (!l || !w) return "standalone";
628
- let declared = null;
629
- try {
630
- declared = new URLSearchParams(l.search).get(PRESENTATION_PARAM);
631
- } catch {
632
- /* a search string we cannot parse is a page nobody addressed */
633
- }
634
- const framed = w.parent !== w;
635
- return declared === PRESENTATION_EMBEDDED && framed ? "embedded" : "standalone";
636
- }
637
-
638
- // queries: persona page scroll behaviour · land on the kernel · scroll spy · toolbar title strip ·
639
- // the page opens on the profile instead of the kernel · toolbar hairline · hash sync ·
640
- // why is this in core rather than in the Toolbar cut
641
- //
642
- // THE PERSONA PAGE'S SCROLL BEHAVIOUR, ONCE, FOR EVERY SURFACE THAT HAS ONE.
643
- //
644
- // A persona page lands on its KERNEL. The profile is the face — it is there when you go looking for
645
- // it, and scrolling up is how you look; what a person came for is the thing the persona does. Once
646
- // the profile has scrolled away, the name it carried reappears in the toolbar's second row, or the
647
- // page loses its own title the moment you start using it.
648
- //
649
- // WHY HERE AND NOT IN THE TOOLBAR CUT. `@justai/cuts/Toolbar` owned this and still calls it, but the
650
- // cut can only serve pages that adopt its MARKUP — and three surfaces cannot: `/me` and `/files`
651
- // carry extra navigation of their own, and the feed is a different build. So all three hand-wrote
652
- // the same eighty lines, and by the third copy they had already drifted: `/files` opened on the
653
- // profile with an empty title strip for a week, and its hash writer clobbered the query string
654
- // (`?mode=atrium` disappeared on the first scroll) where the cut's preserves it.
655
- //
656
- // That is the shape core exists for — the load-bearing behaviour, framework-free, so an Astro cut, a
657
- // Next face and a hand-written page all run the SAME logic instead of three versions of it. What
658
- // stays in the cut is the markup and the CSS; what moves here is the part that was being copied.
659
- //
660
- // Every element is found by id so a surface can bring its own markup: only the ids are the contract.
661
- export function personaScroll(options) {
662
- const o = options || {};
663
- const cutIds = o.cuts || ["profile", "kernel", "posts"];
664
- const el = (id) => (typeof id === "string" ? document.getElementById(id) : id);
665
-
666
- const below = el(o.below || "below");
667
- const kernel = el("kernel");
668
- if (!below || !kernel) return;
669
-
670
- const toolbar = typeof o.toolbar === "string" ? document.querySelector(o.toolbar) : o.toolbar || document.querySelector(".toolbar");
671
- const tbTitle = el(o.title || "tbTitle");
672
- const tbTitleText =
673
- (typeof o.titleText === "string" ? document.getElementById(o.titleText) : o.titleText) ||
674
- document.getElementById("tbTitleText") ||
675
- (tbTitle && tbTitle.querySelector(".tb-title-text"));
676
-
677
- // A cut is a section AND the nav that points at it; anything missing either half is simply not one.
678
- // That is how a page with extra toolbar links — /me's vault, /files' host link — needs no
679
- // configuration: they are links, not cuts, and they fall out of this list on their own.
680
- const cuts = cutIds
681
- .map((id) => [el(id), el(o.navFor ? o.navFor(id) : "nav" + id.charAt(0).toUpperCase() + id.slice(1))])
682
- .filter((c) => c[0] && c[1]);
683
- if (!cuts.length) return;
684
-
685
- // queries: --shell-top · the kernel is 26px short · the game frame does not reach the fold ·
686
- // a strip of posts shows above the fold · opening at #kernel is different from #profile ·
687
- // the toolbar changes height · title strip · the layout depends on when it was measured
688
- //
689
- // ── NEVER SAMPLE AN ANIMATION AND CALL IT A LAYOUT ─────────────────────────────────────────
690
- //
691
- // `--shell-top` is what the shell takes above the kernel, and everything downstream reads it: the
692
- // landing offset, an app kernel's minimum height, a game kernel's exact one.
693
- //
694
- // It was the literal `82` for a long time and that was stable and slightly wrong. Reading the
695
- // toolbar's height instead made it exact and UNSTABLE, which is far worse: the row carries a title
696
- // strip that opens and closes over 0.35s, so its height is anywhere in a 26px range depending on
697
- // the instant somebody looked. Measured on tpl-sunshine at 1864x999, the same persona, same build:
698
- //
699
- // opened at #profile strip shut when measured shell-top 80 frame 919 reaches the fold
700
- // opened at #kernel strip open when measured shell-top 106 frame 893 33px SHORT
701
- //
702
- // and the second is what a visitor gets, because a game persona lands on its kernel. Thirty-three
703
- // pixels of the next section showing above the fold, and the "correct" case was correct by
704
- // coincidence — a shut row plus a gutter happened to equal an open one.
705
- //
706
- // THE FIX IS NOT A BETTER MOMENT TO MEASURE, IT IS NOT MEASURING THE MOVING PART. The row minus the
707
- // strip is the row, and it is the same number at every frame of the transition; the strip's OPEN
708
- // height is `--tb-strip`, which the Toolbar cut declares beside the rule that uses it. Their sum is
709
- // what the bar is whenever anybody is looking at the kernel — which is the only time this number
710
- // decides anything.
711
- //
712
- // AND NO GUTTER IS ADDED. The frame is the active view, so it begins where the shell ends; the air
713
- // an app keeps under the bar is its own padding, and adding a gutter here would spend it twice.
714
- //
715
- // Re-measured on resize because a rotation, a narrowing past 640 and a reader's text size all
716
- // change the ROW — none of which is the animation this is written to ignore.
717
- const measureShell = () => {
718
- if (!toolbar) return;
719
- // THE BAR'S EXPANDED HEIGHT, WITHOUT WAITING FOR OR RACING THE STRIP'S 0.35s. The row is the bar
720
- // minus whatever the strip currently is — the same number at every frame of the transition — and
721
- // the bar-to-be is that row plus the strip's declared open height. Nothing samples the animation,
722
- // so nothing depends on when it was sampled.
723
- //
724
- // CEIL, NOT ROUND, AND LOAD-BEARING: this is the slot's reserved box as well as the landing
725
- // offset, so it must never be LESS than the bar's tallest state or the slot starts following the
726
- // bar again and the 26px returns as a fraction. A bar under Dynamic Type is not an integer —
727
- // 82.3 is recorded in this file — and rounding down is half a CSS pixel of permanent error.
728
- const strip = tbTitle ? tbTitle.getBoundingClientRect().height : 0;
729
- const open = parseFloat(getComputedStyle(toolbar).getPropertyValue("--tb-strip")) || 26;
730
- const h = Math.ceil(toolbar.getBoundingClientRect().height - strip + open);
731
- // ON THE ROOT, because the kernel's `scroll-margin-top` reads it and THE BROWSER reads that when
732
- // it scrolls to the fragment on its own. Written on `.app` this reached the kernel only when the
733
- // kernel happened to sit inside one, and a surface where it did not is a surface where the
734
- // browser's landing and the script's disagree — which is the whole bug this measurement exists
735
- // to prevent. The root is the one element every consumer is inside.
736
- if (h <= 0) return;
737
- document.documentElement.style.setProperty("--shell-top", h + "px");
738
- // queries: a persona overrides the landing offset · scroll-margin-top 82px in my own component ·
739
- // the page lands 30px short · duplicate landing offset · my persona has its own #kernel
740
- // rule · the framework does not reach my css
741
- //
742
- // AND ENFORCED, NOT MERELY DECLARED.
743
- //
744
- // The framework exists so that a number like this lives in ONE place. It cannot: CSS has no way
745
- // to refuse an override, and on 2026-08-06 EIGHT personas — both apexes and justai.pro among them
746
- // — still carried `#kernel { scroll-margin-top: 82px }` from before the shell was shared, a
747
- // constant that stopped being true the day the secondary title strip was removed. Every one of
748
- // them lands the page by measurement and is then overruled by the browser's own scroll to the
749
- // fragment, which reads the persona's stale copy. Thirty pixels, on every bare load.
750
- //
751
- // Deleting the eight copies is the honest fix and it is being done. This is what makes the ninth
752
- // impossible: whoever measures the bar owns what clearing it means, so EVERY CUT BELOW THE FIRST
753
- // clears it by exactly the bar — written inline, which outranks any stylesheet.
754
- //
755
- // NOT "every cut that already declares an offset". That was the first version of this rule and it
756
- // was too polite by one case: it read a zero as *"this section is not claiming to clear
757
- // anything"*, and a persona that never loads `@justai/ui`'s base.css at all has exactly that
758
- // zero. Measured on pin.games the moment its local `82px` was deleted — the offset fell to 0, the
759
- // browser's own scroll put the kernel's top at the viewport top, and the persona's first line sat
760
- // UNDER the sticky bar. Not landing short any more; landing under. Same bug, other direction.
761
- //
762
- // So it does not matter what the persona's CSS says or whether it loaded ours: a sticky bar is
763
- // above every cut but the first, and the first is the top of the page with nothing to clear.
764
- // The warning is only for a persona that declared a DIFFERENT number — that one has a stale rule
765
- // to go and delete. A zero is just a surface that never had the stylesheet, and healing it
766
- // silently is the whole point of the framework owning this.
767
- cuts.forEach(([sec], i) => {
768
- if (i === 0) return;
769
- const declared = parseFloat(getComputedStyle(sec).scrollMarginTop) || 0;
770
- if (Math.abs(declared - h) <= 0.5) return;
771
- sec.style.scrollMarginTop = h + "px";
772
- if (declared > 0) {
773
- // Said out loud, because a healed page is a page nobody goes and fixes.
774
- console.warn("[justai] #" + sec.id + " declares scroll-margin-top " + declared + "px; the shell measures " + h + "px. The landing offset belongs to @justai/ui — delete the local rule.");
775
- }
776
- });
777
- };
778
- measureShell();
779
- addEventListener("resize", measureShell, { passive: true });
780
- if (document.fonts && document.fonts.ready) document.fonts.ready.then(measureShell);
781
-
782
- // queries: data-motion · the bar grows after load · animate only after interaction · first paint
783
- // animation · the toolbar changes height on arrival
784
- //
785
- // ── THE SHELL'S TRANSITIONS BELONG TO A PAGE SOMEBODY IS USING ──────────────────────────────
786
- //
787
- // The founder's question, and it is the root of the whole class: *"why is this not activated only
788
- // after the user's first interaction?"* A persona lands on its kernel, so the title strip's correct
789
- // state on the first frame is OPEN — animating into it makes the bar grow 26px just after the page
790
- // appears, and makes every measurement taken during that third of a second describe a state the
791
- // page is never actually in.
792
- //
793
- // Nobody can see a transition they have not yet done anything to cause, so there is nothing to
794
- // lose. `once: true` on each: the flag is set by whichever comes first and never again.
795
- if ("scrollRestoration" in history) history.scrollRestoration = "manual";
796
-
797
- // Only the FRAGMENT. `"#" + id` would clobber the path and the query, and both carry meaning here:
798
- // a `?data=` link, a `?city=`, a `?mode=atrium`. A copy of this got that wrong.
799
- const setHash = (id) => history.replaceState(null, "", location.pathname + location.search + "#" + id);
800
-
801
- // queries: what is the 84px line · the scroll spy reports the wrong section · the hash flips back to
802
- // #profile · clicking the avatar does not activate the kernel · the toolbar switches
803
- // sections on its own · hash does not guarantee the cut · where does a cut begin
804
- //
805
- // WHERE A CUT BEGINS — ONE DEFINITION, USED BY THE NAVIGATOR AND BY THE SPY.
806
- //
807
- // This is the keystone of the whole behaviour, and getting it wrong is what made the hash a
808
- // suggestion instead of a guarantee. There used to be TWO definitions: navigation scrolled to one
809
- // place, and the spy tested against a different one — a hardcoded 84px line, paired by nothing but a
810
- // comment with the `scroll-margin-top: 82px` that twelve personas each declared in their own CSS.
811
- // Two magic numbers, two pixels apart, and the bug lived in the gap:
812
- //
813
- // click the avatar -> lands the kernel at 82 -> spy's last mid-flight sample read 85 -> profile
814
- //
815
- // A cut begins where the page COMES TO REST when you go to it. That is the only definition either
816
- // side needs, and both now ask for it here — so the spy cannot contradict the navigator, because
817
- // there is no second number for it to disagree with. The hash stops being a hint.
818
- //
819
- // Nothing is guessed. The position comes from the browser, and the landing inset comes from the
820
- // CSS that already declares it (`scroll-margin-top`) rather than from a constant that has to be
821
- // kept in sync by hand.
822
- //
823
- // THE KERNEL IS THE ONE EXCEPTION, and it is what kills an oscillation rather than papering over
824
- // it. The kernel begins at the top of `#below` — above the sticky toolbar — not at its own box.
825
- // The toolbar's title strip lives INSIDE `#below` and is in flow, so opening it pushes every
826
- // section under it down by its own height (26px, measured). While the spy compared the kernel's own
827
- // box against a fixed line, that 26px carried the kernel from 82 (inside the line) to 108 (outside
828
- // it) — and the kernel being current is what opened the strip. Measured on app.zone by dispatching
829
- // scroll events at a page that never moved:
830
- //
831
- // rest hash #profile kernelTop 82 strip 0 active profile
832
- // spy run 1 hash #kernel kernelTop 108 strip 26 active kernel
833
- // spy run 2 hash #profile kernelTop 82 strip 0 active profile
834
- // spy run 3 hash #kernel kernelTop 108 strip 26 active kernel
835
- //
836
- // A bistable oscillator: the spy was measuring its own output. Anchoring the kernel to `#below`
837
- // removes the coupling at the source, because the strip is inside that boundary and cannot move it.
838
- // Widening the line would only have moved the tipping point.
839
- const landingY = (sec) => {
840
- if (sec === kernel) return below.getBoundingClientRect().top + window.scrollY;
841
- const inset = parseFloat(getComputedStyle(sec).scrollMarginTop) || 0;
842
- return sec.getBoundingClientRect().top + window.scrollY - inset;
843
- };
844
- const goTo = (sec, behavior) => window.scrollTo({ top: landingY(sec), behavior: behavior });
845
-
846
- // queries: the page rests a few pixels short of the kernel · the hash flips to #profile on its own ·
847
- // typing the bare host lands on the profile · below.top 4.36 · the landing is not repaired ·
848
- // it works with #kernel in the URL but not without · unstable landing
849
- //
850
- // WHERE THIS PAGE WAS SENT — DECIDED ONCE, AND NEVER READ BACK OUT OF THE ADDRESS BAR.
851
- //
852
- // This used to be re-derived from `location.hash` on every attempt, and the spy WRITES that hash.
853
- // So the repair mechanism took its definition of "where I was supposed to be" from the very thing
854
- // that goes wrong. Traced frame by frame on a live persona at 1512×900:
855
- //
856
- // t=241 scrollTo(333.36) landed exactly, below.top 0.36, #kernel
857
- // t=258 the title strip begins closing y 331, below.top 2.36
858
- // t=272 below.top passes 1 the spy answers PROFILE and writes #profile
859
- // t=313 the strip is closed, the page has drifted y 329, below.top 4.36
860
- // t=342 the `load` repair runs — and reads #profile as its target, measures itself
861
- // 329 against the PROFILE's landing, finds it further than any drift could be,
862
- // and closes the promise for good.
863
- //
864
- // Four pixels, and the page is stable in the wrong state: the kernel is 4px under the toolbar, the
865
- // spy says profile, the strip stays shut, and the address bar says #profile for a person who typed
866
- // the bare host. It is not a hash bug — with #kernel in the URL the same drift flips the same spy
867
- // and disarms the same repair. What made it look like one is that the two stable states are
868
- // reachable by a hair: on a phone the landing happened to rest at below.top −0.27 and stayed right.
869
- //
870
- // Captured before the first landing, so the repair keeps asking the only question worth asking:
871
- // *am I where I was SENT?* One re-assert settles it permanently — measured, four times over, no
872
- // oscillation.
873
- const sentTo = (() => {
874
- const t = cuts.find((c) => "#" + c[0].id === location.hash);
875
- // A section hash is honoured on load and refresh; anything else — including #kernel and no hash
876
- // at all — lands on the kernel.
877
- return t ? t[0] : kernel;
878
- })();
879
-
880
- const land = () => {
881
- // presentation mode owns the viewport — a page presenting itself does not scroll out from under
882
- // whoever opened it
883
- if (document.body.dataset.present) return;
884
- // `instant` overrides the page's own scroll-behavior: smooth.
885
- goTo(sentTo, "instant");
886
- };
887
- // queries: the page did not land on the kernel · landing scroll ignored · scrollTo does nothing on
888
- // first paint · the page opens at the top sometimes
889
- //
890
- // LANDED, OR TRIED AGAIN — but only for the one case where a scroll is REFUSED.
891
- //
892
- // `scrollTo` past the current document height is a no-op, and it does not report one: on a page
893
- // whose sections size themselves a frame later, the landing is CALLED, the browser declines it, and
894
- // the page opens at the top with nothing anywhere saying so. Measured in this behaviour's own
895
- // fixture: `scrollTo({top: 548})` followed by a scroll event reading 0. So it is attempted again on
896
- // the next frame, on `load`, and once more when the page comes to rest.
897
- //
898
- // ── WHAT USED TO BE HERE, AND WHY IT IS NOT ────────────────────────────────────────────────
899
- //
900
- // A second, much larger mechanism: a landing that ARRIVED and then DRIFTED, held as a promise until
901
- // a wheel, a finger or a key "took over", with a tolerance derived from the toolbar's own height.
902
- // Its trace, recorded in this file:
903
- //
904
- // scrollTo(468) y = 468 the landing is exact
905
- // DOMContentLoaded y = 494 docH +26 — the title strip opened
906
- // settled y = 465 docH -26 — and the strip closed again
907
- //
908
- // Every term of it was the secondary strip. It sat above the kernel inside the sticky bar, so each
909
- // time it opened or closed the browser moved the scroll position to keep the content under it
910
- // steady, and the page came to rest three pixels short of where the kernel began — close enough to
911
- // look landed, far enough that the spy answered "profile", which closed the strip, which is what
912
- // moved it. The founder removed the strip on 2026-08-06, and this went with it: measured after, the
913
- // page scrolls exactly ONCE to its landing and never moves again, at 402x710 and at 1440x900.
914
- //
915
- // A workaround outlives its cause silently. This one would have kept re-asserting a landing nobody
916
- // needed, over a drift that can no longer happen, for as long as the file existed.
917
- // Only the DESTINATION is released when somebody takes over, never the landing: a tap on a cut
918
- // shows where the page is GOING, and nobody should be shown a destination they have abandoned.
919
- // The landing itself no longer needs protecting — there is no drift left for it to be protected
920
- // from, which is the whole point of the note above.
921
- const takeOver = () => { navTo = null; };
922
- for (const ev of ["wheel", "touchmove", "keydown"]) window.addEventListener(ev, takeOver, { passive: true });
923
-
924
- land();
925
-
926
- // A CLICK CLOSES THIS ONE, AND THAT IS THE DIFFERENCE FROM WHAT WAS HERE BEFORE. The old promise
927
- // deliberately survived clicks, because a tap on a cut is a request for a landing rather than an
928
- // override — but that promise existed to repair the strip's drift, and it could tell the two apart
929
- // because it only ever corrected by less than a toolbar's height. This one has no such tolerance:
930
- // it can only distinguish "the browser refused the scroll" from "the page is somewhere on purpose",
931
- // and after a tap those look identical. Caught by the row's own spec: clicking Profile rested the
932
- // page at 0, this read it as a refusal, and pulled it back to the kernel.
933
- let landed = false;
934
- const settle = () => { landed = true; };
935
- for (const ev of ["wheel", "touchmove", "keydown", "click"]) {
936
- window.addEventListener(ev, settle, { passive: true, once: true });
937
- }
938
-
939
- // queries: the child persona lands short · /me lands a bit off · unstable landing · async content
940
- // moves the page after it lands · vault read shifts the layout · below.top -18 · the
941
- // landing is fine in one browser and off in another · ResizeObserver landing
942
- //
943
- // ── THE LANDING IS KEPT AGAINST LAYOUT — NEVER AGAINST SCROLLS ─────────────────────────────────
944
- //
945
- // A landing is a promise about a document that may not have finished becoming itself. The children
946
- // proved it: /me lands exactly, the vault's async read completes, the profile grows and settles,
947
- // and the page rests 18px from where it was put — with NOBODY having scrolled. Chromium's scroll
948
- // anchoring sometimes absorbs this and sometimes does not, and WebKit has no anchoring at all,
949
- // which is why the founder's phone showed what a laptop's headless run happened to hide. "Stable
950
- // olmayan bir durum" is half-applied compensation seen from the outside.
951
- //
952
- // A repair against ANY movement was tried once and fought a page that scrolls itself — that is the
953
- // workaround this file keeps warning about. The line is drawn elsewhere, and it is sharp: LAYOUT
954
- // is the page still under construction, so the promise holds; a SCROLL is an intent, and intents
955
- // are never fought. A ResizeObserver on the body sees exactly the first kind and cannot see the
956
- // second — a consumer calling scrollTo() resizes nothing. The first gesture ends it: after a
957
- // wheel, a finger, a key or a pointer the page belongs to the person, whatever the layout does.
958
- let touched = false;
959
- const takeBack = () => { touched = true; };
960
- for (const ev of ["wheel", "touchmove", "keydown", "pointerdown"]) {
961
- window.addEventListener(ev, takeBack, { passive: true, once: true, capture: true });
962
- }
963
- if (typeof ResizeObserver === "function") {
964
- // queries: the keeper fought a programmatic scroll · scrollTo(0) snapped back to the kernel ·
965
- // the query-survives spec times out in CI · near band 64
966
- //
967
- // AND THE KEEPER ONLY ACTS WHILE THE PAGE IS STILL AT THE LANDING. CI caught the first version
968
- // within the hour: a consumer's programmatic scrollTo(0) — which no gesture listener sees — was
969
- // followed by the fonts settling, the resize fired, and the keeper yanked the page back to the
970
- // kernel from somewhere it had been deliberately sent. Gestures cannot be the only release,
971
- // because a page is allowed to scroll ITSELF (lendcam's stage does; a spec does).
972
- //
973
- // So the promise is spatial as well: on every resize the keeper first asks whether the page is
974
- // still within a hand's width (64px) of where it last held it. Layout shifts displace a landed
975
- // page by small strokes — the vault's was 18px — while anybody scrolling AWAY, by hand or by
976
- // code, leaves that band immediately and permanently: the keeper reads leaving as being
977
- // relieved of duty, not as something to correct.
978
- let kept = landingY(sentTo);
979
- const keeper = new ResizeObserver(() => {
980
- if (touched || document.body.dataset.present) { keeper.disconnect(); return; }
981
- if (Math.abs(window.scrollY - kept) > 64) { keeper.disconnect(); return; }
982
- const want = landingY(sentTo);
983
- kept = want;
984
- // A pixel of slack: browsers land sub-pixel scrolls a hair off the number they were handed,
985
- // and re-asserting over a rounding error would run on every breath the page takes.
986
- if (Math.abs(window.scrollY - want) > 1) goTo(sentTo, "instant");
987
- });
988
- // NOT (only) the body: the fleet's ground gives `body { height: 100% }`, so the body's border
989
- // box is the viewport and never resizes when content grows — an observer there watched the one
990
- // box guaranteed to stay still. Caught by the spec modelling the vault's growth: 18px arrived,
991
- // the observer never fired. The boxes that actually change are the sections themselves, so the
992
- // keeper watches every cut and the below-boundary; body rides along for a consumer whose ground
993
- // differs.
994
- keeper.observe(document.body);
995
- keeper.observe(below);
996
- for (const c of cuts) keeper.observe(c[0]);
997
- }
998
- // The landing is attempted again when the page comes to rest, because `scrollTo` past a document
999
- // that has not sized itself yet is a silent no-op — cause 1, and the only cause left here. The
1000
- // drift this used to repair as well was the secondary title strip moving the page after it landed,
1001
- // and the strip is gone; the thirty-pixel glide that looked like drift afterwards was not one
1002
- // either — it was the browser scrolling to the fragment with a number the persona still owned, and
1003
- // that is fixed where the number lives rather than chased from here. A repair that re-asserts
1004
- // against ANY movement fights a page that scrolls itself, which is a workaround growing back.
1005
- const landIfRefused = () => {
1006
- if (landed) return;
1007
- // Anywhere but the very top means the scroll was accepted. A landing that IS the top has nothing
1008
- // to be refused about. Either way this is the last thing it ever does.
1009
- if (window.scrollY > 1 || landingY(sentTo) <= 1) { landed = true; return; }
1010
- land();
1011
- };
1012
- requestAnimationFrame(landIfRefused);
1013
- window.addEventListener("load", landIfRefused);
1014
-
1015
-
1016
- // The reveal rides with this on pages whose content is ready at first paint. A page that renders
1017
- // asynchronously — the vault, the file kernel — holds paint until its own data has arrived and
1018
- // passes `reveal: false`, because revealing before then shows an empty room.
1019
- if (o.reveal !== false) {
1020
- const reveal = () => document.body.classList.add("ready");
1021
- requestAnimationFrame(reveal);
1022
- setTimeout(reveal, 500);
1023
- }
1024
-
1025
- const text = (sel) => (document.querySelector(sel)?.textContent || "").trim();
1026
- // Kernel names the persona, Posts names its handle, Profile stays collapsed — its big header IS
1027
- // the title, and repeating it in the bar above would say the same thing twice.
1028
- const titleFor =
1029
- o.titleFor ||
1030
- ((id) => (id === "kernel" ? text(".pname") : id === "posts" ? text(".handle") : ""));
1031
-
1032
- // queries: the title strip jumps · the page jolts after tapping a cut · content shifts while
1033
- // scrolling · toolbar title animation causes a layout shift · landing lands 26px off ·
1034
- // landingAfterStrip · why is there no strip compensation any more · tb-slot min-height
1035
- //
1036
- // ── THERE IS NOTHING LEFT TO COMPENSATE FOR, AND THAT IS THE WHOLE POINT OF THE SLOT ──────────
1037
- //
1038
- // Two functions used to live here: one probed the strip's open height before it opened, the other
1039
- // aimed a scroll at where the page WOULD rest once the strip had finished moving. They existed
1040
- // because the strip was in flow above every section, so opening it pushed the whole page down by
1041
- // its own 26px and a landing computed before it opened was wrong by exactly that much. A person
1042
- // felt it as three motions for one tap.
1043
- //
1044
- // `.tb-slot` ends that at the source: the SLOT is what flow sees and its box is `--shell-top`, a
1045
- // constant; the BAR is static inside it and may be any height it likes. Opening the strip moves
1046
- // nothing outside the slot, so a landing computed before it opens is simply correct.
1047
- //
1048
- // The compensation is therefore not merely dead — it would be WRONG, adding a strip's height to
1049
- // the posts landing for a shift that no longer happens. When the strip came back on 2026-08-06 the
1050
- // reserved box came back with it FOR EVERY KIND, not only for games, and these two went for good.
1051
- // If they are ever missed, the thing to check is whether the slot still reserves its box.
1052
- const setStrip = (id, animate) => {
1053
- if (!tbTitle) return;
1054
- const t = titleFor(id);
1055
- if (animate) {
1056
- tbTitle.classList.toggle("show", !!t);
1057
- if (t && tbTitleText && tbTitleText.textContent !== t) {
1058
- tbTitleText.classList.add("fade");
1059
- setTimeout(() => { tbTitleText.textContent = t; tbTitleText.classList.remove("fade"); }, 150);
1060
- }
1061
- return;
1062
- }
1063
- // Instant: the height must be final before this function returns, so the caller can measure. The
1064
- // text goes with it — a settled height showing the previous words would be its own small lie.
1065
- tbTitle.style.transition = "none";
1066
- tbTitle.classList.toggle("show", !!t);
1067
- if (t && tbTitleText) { tbTitleText.classList.remove("fade"); tbTitleText.textContent = t; }
1068
- void tbTitle.offsetHeight;
1069
- tbTitle.style.transition = "";
1070
- };
1071
-
1072
- let lastCut = null;
1073
- let first = true;
1074
- // queries: the toolbar icon changes late · nav icon lags the tap · active state waits for the scroll
1075
- //
1076
- // THE DESTINATION, HELD FOR THE LENGTH OF THE TRIP.
1077
- //
1078
- // The spy is truthful: it reports the section the page is actually over. During a smooth scroll that
1079
- // is the section being LEFT, so the toolbar answered a tap only once the scroll finished — the icon
1080
- // changed a beat late for no reason a person could see. A tap is a request to arrive, the same
1081
- // reading the landing promise already takes, so the toolbar may show where it is going.
1082
- //
1083
- // Held rather than merely set, because setting it optimistically would be undone by the very next
1084
- // spy frame and flicker. Released the moment the page arrives, or the moment somebody takes over —
1085
- // nobody is shown a destination they have already abandoned.
1086
- let navTo = null;
1087
- // The cut you are on is the last one you have reached — asked in the one vocabulary `landingY`
1088
- // defines, so this can never answer something a click could not produce. A pixel of tolerance,
1089
- // because a browser is free to land a smooth scroll a hair short of the number it was given.
1090
- const measure = () => {
1091
- if (toolbar) toolbar.classList.toggle("stuck", window.scrollY >= below.offsetTop - 1);
1092
- const y = window.scrollY + 1;
1093
- let current = cuts[0];
1094
- for (const c of cuts) if (landingY(c[0]) <= y) current = c;
1095
- if (navTo) {
1096
- if (current === navTo) navTo = null;
1097
- else current = navTo;
1098
- }
1099
- for (const c of cuts) c[1].classList.toggle("active", c === current);
1100
- if (current === lastCut) return;
1101
- lastCut = current;
1102
- if (current[0].id && "#" + current[0].id !== location.hash) setHash(current[0].id);
1103
-
1104
- // First paint is not a transition: the page opens at the kernel, so the title is already true when
1105
- // it arrives. Animating it in tells a person something changed when nothing did.
1106
- const wasFirst = first;
1107
- first = false;
1108
- setStrip(current[0].id, !wasFirst);
1109
- };
1110
- // queries: scroll janks while the toolbar updates · scroll handler runs too often · the spy reads a
1111
- // stale position · the section is right but the toolbar is one behind · scrollend
1112
- //
1113
- // THE LISTENER SCHEDULES; THE FRAME MEASURES. AND THE LAST WORD IS ALWAYS THE RESTING POSITION.
1114
- //
1115
- // Two rules, and the second one is what actually fixed the reported bug.
1116
- //
1117
- // NEVER IN THE EVENT. `measure` reads geometry, and reading geometry inside a scroll handler forces
1118
- // the browser to lay the page out synchronously on a thread that is trying to move it. So the
1119
- // handler does nothing but ask for a frame; all reading and writing happens in that frame, at most
1120
- // once per frame however many events arrived. Intermediate positions are DISCARDED — only the
1121
- // newest is ever measured, which is the whole point of coalescing rather than throttling.
1122
- //
1123
- // AND THE PAGE MUST BE MEASURED WHERE IT STOPS. Scroll events stop arriving slightly before a
1124
- // smooth scroll finishes settling, so the last position the old code ever evaluated was in flight:
1125
- // it read 85, decided "profile", and the page then came to rest at 82 — inside the kernel — with
1126
- // nothing left to run and say so. That single unread pixel is the entire reported symptom.
1127
- //
1128
- // So a frame that finds the page still moving asks for another one, and the loop ends on the frame
1129
- // where nothing changed — which is, by construction, the resting position. No timer, no `scrollend`
1130
- // (still not everywhere), and nothing running once the page is still.
1131
- let queued = false;
1132
- let lastY = null;
1133
- const frame = () => {
1134
- queued = false;
1135
- const y = window.scrollY;
1136
- const moved = y !== lastY;
1137
- lastY = y;
1138
- measure();
1139
- if (moved) schedule();
1140
- // The page has stopped. If the landing was refused because the document had not sized itself
1141
- // yet, this is the last chance to notice — and it is the ONLY thing left here: the drift this
1142
- // used to repair was the secondary strip moving the page, and the strip is gone.
1143
- else landIfRefused();
1144
- };
1145
- const schedule = () => { if (!queued) { queued = true; requestAnimationFrame(frame); } };
1146
- window.addEventListener("scroll", schedule, { passive: true });
1147
- measure();
1148
-
1149
- // queries: a link to #kernel does not activate the kernel · the avatar link does not land · in-page
1150
- // hash link · anchor click · hash from another page
1151
- //
1152
- // EVERY HASH LINK IS A CUT LINK — not only the three in the toolbar.
1153
- //
1154
- // The toolbar's own navs used to be the only anchors wired up, so any OTHER link to the same place
1155
- // fell through to the browser's native anchor jump and was then overruled by the spy. The profile
1156
- // avatar is exactly that: a link to `#kernel` that took you near the kernel and left the page
1157
- // saying `#profile`. Delegated, so a cut link works wherever a persona puts one — today the avatar,
1158
- // tomorrow something nobody has written yet — with no registration and no per-persona wiring.
1159
- //
1160
- // Programmatic rather than native, so the landing is the one `landingY` defines. A native jump uses
1161
- // `scroll-margin` alone and lands the kernel below the sticky bar it should sit under.
1162
- document.addEventListener("click", (e) => {
1163
- const a = e.target && e.target.closest ? e.target.closest('a[href^="#"]') : null;
1164
- if (!a) return;
1165
- const t = cuts.find((c) => "#" + c[0].id === a.getAttribute("href"));
1166
- if (!t) return;
1167
- e.preventDefault();
1168
- // A NEW LANDING RE-ARMS THE PROMISE. Somebody asking for a cut is asking to arrive at it, and the
1169
- // arrival needs the same protection the page's first one had: the title strip opens as the kernel
1170
- // becomes current, which drags the scroll ~18px past the mark and tucks the kernel's first line
1171
- // under the sticky bar. Without this the toolbar's own icon landed flush and the avatar did not,
1172
- // for no reason a person could see.
1173
- // THE STRIP AND THE SCROLL RUN TOGETHER. The strip keeps its own transition — it is meant to be
1174
- // seen growing, and snapping it open instead just moves the jolt to the moment of the tap. What
1175
- // changes is the AIM: the scroll is sent to where the page will rest once the strip has finished,
1176
- // so the growing band and the moving page arrive at the same place at the same time and nothing
1177
- // has to be corrected afterwards.
1178
- // The icon answers the tap NOW, not when the scroll lands. `navTo` keeps it answered for the trip.
1179
- navTo = t;
1180
- for (const c of cuts) c[1].classList.toggle("active", c === t);
1181
- // queries: clicking profile throws me back to the kernel · the second cycle · landed re-armed
1182
- //
1183
- // ** NOTHING IS RE-ARMED HERE, AND THAT LINE COST AN HOUR. ** This used to set `landed = false`,
1184
- // which was right while `landed` meant "the landing promise is open": a tap on a cut IS a request
1185
- // for a landing, so the drift repair was re-armed to protect the new one. That promise is gone —
1186
- // `landed` now means only "the initial scroll was accepted, stop retrying it" — and re-arming it
1187
- // told the retry that the page had never landed. The tap scrolls to the profile, the page comes
1188
- // to rest at 0, the retry reads `scrollY <= 1` with a landing of 376, calls it a refusal and
1189
- // pulls the person back to the kernel.
1190
- //
1191
- // It survived the first cycle by luck: the same click also tripped the `once` listener that sets
1192
- // `landed = true`, in the later bubble phase, so the flag ended true anyway. The listener is
1193
- // spent after that, and from the SECOND tap onward the page snapped back every time — which is
1194
- // exactly how the founder found it: "profile · kernel · profile · kernel … 2. cycle'da başlıyor."
1195
- //
1196
- // The strip still follows the tap — it is the row saying which cut you are on, which is the one
1197
- // thing about it the founder said he could not give up.
1198
- setStrip(t[0].id, true);
1199
- window.scrollTo({ top: landingY(t[0], t[0].id), behavior: "smooth" });
1200
- setHash(t[0].id);
1201
- });
1202
-
1203
- // A hash that arrives without a click — the back button, or a link from another page to this one.
1204
- // `setHash` uses replaceState and fires nothing, so this can only be somebody else's navigation.
1205
- window.addEventListener("hashchange", () => {
1206
- // The back button or a link from outside — a person navigated, so the load-landing promise ends
1207
- // here too: the layout keeper must not snap a page somebody just steered somewhere else.
1208
- touched = true;
1209
- const t = cuts.find((c) => "#" + c[0].id === location.hash);
1210
- if (t) {
1211
- navTo = t;
1212
- for (const c of cuts) c[1].classList.toggle("active", c === t);
1213
- // Nor here — same reason as the click above.
1214
- setStrip(t[0].id, true);
1215
- window.scrollTo({ top: landingY(t[0], t[0].id), behavior: "smooth" });
1216
- }
1217
- });
1218
- }
1219
-
1220
- // queries: persona scroll for a surface that cannot bundle · inline scroll script · feed toolbar
1221
- // script · why is there a JS string version of personaScroll
1222
- //
1223
- // THE SAME BEHAVIOUR, AS A STRING, FOR A SURFACE THAT CANNOT IMPORT IT.
1224
- //
1225
- // The feed is served under every persona's host from its own origin, so its scripts are `is:inline`
1226
- // rather than bundled assets — a cross-origin module would need CORS on every one of them. That is
1227
- // why core's other load-bearing pieces are strings too (AUTH_CAPTURE_JS, READY_JS, CONSENT_JS).
1228
- //
1229
- // It is generated FROM the function rather than written twice, which is the only version of this
1230
- // worth having: a second hand-minified copy is what the feed already had, and it had drifted — its
1231
- // hash writer dropped the query, it never set the title text, and it found its navs by href. One
1232
- // source, two shapes.
1233
- //
1234
- // This works because `personaScroll` closes over nothing: every helper it uses is defined inside it.
1235
- // A future edit that reaches for a module-level helper would compile, ship, and throw here — so if
1236
- // you add one, inline it.
1237
- export function personaScrollJs(options) {
1238
- return "(" + personaScroll.toString() + ")(" + JSON.stringify(options || {}) + ");";
1239
- }
1240
-
1241
- // queries: child persona face · the file room is blue · my child persona has the wrong accent ·
1242
- // /api/face · a hidden persona's child · childFace · host persona colour in a child
1243
- //
1244
- // THE HOST PERSONA'S FACE, FOR A CHILD PERSONA THAT IS MOUNTED ON IT.
1245
- //
1246
- // `me`, `files` and `feed` render on every persona's host and have to wear that persona's colour,
1247
- // name and mark. Each of them wrote this fetch by hand, and the line has now moved THREE times —
1248
- // which is the argument for it living here rather than in a fourth copy:
1249
- //
1250
- // 1. `/api/personas` — serves five fields and none of the three needed. Every `if` was false, so
1251
- // every file room wore the platform's default blue. Nothing errored; a 200 is not a face.
1252
- // 2. `/api/catalog` — carries the face, and was right until a persona could be HIDDEN. The catalog
1253
- // filters `hidden` on purpose because it IS the storefront, so from 2026-08-02 a persona born
1254
- // from the template was invisible to its own child personas.
1255
- // 3. `/api/face?host=` — "who owns this address", which is the question this code was always
1256
- // asking. Only the storefront's question is about visibility.
1257
- //
1258
- // ── WHERE THE ACCENT HAS TO BE WRITTEN, WHICH IS BOTH PLACES ────────────────────────────────────
1259
- //
1260
- // A child scopes its whole token set under `.pp` — `--accent` included — so a value written only to
1261
- // `:root` is SHADOWED for everything inside it, which is the entire surface. It looks correct, it
1262
- // measures correct at `documentElement`, and it changes nothing a person can see. The root still
1263
- // gets it too, because a few rules live outside `.pp` (`::selection` is one) and read the document's.
1264
- //
1265
- // Learned by moving it off `.pp` "to be more correct" and undoing a shipped fix — so both, always.
1266
- export async function childFace(options) {
1267
- const o = options || {};
1268
- const host = o.host || (typeof location !== "undefined" ? location.hostname : "");
1269
- if (!host) return null;
1270
- const root = o.root || (typeof document !== "undefined" ? document.getElementById("pp") : null);
1271
- const base = o.api || "https://api.justai.pro";
1272
- let face = null;
1273
- try {
1274
- const r = await fetch(`${base}/api/face?host=${encodeURIComponent(host)}`);
1275
- face = r.ok ? await r.json() : null;
1276
- } catch {
1277
- // A child whose host cannot be resolved is a child wearing the platform's default, which is a
1278
- // legible state. It is not an error to report to somebody looking at their own files.
1279
- return null;
1280
- }
1281
- if (!face) return null;
1282
- if (typeof document === "undefined") return face;
1283
- if (face.accent) {
1284
- document.documentElement.style.setProperty("--accent", face.accent);
1285
- if (root) root.style.setProperty("--accent", face.accent);
1286
- }
1287
- // queries: pnName pnHandle pnMeta · the child persona shows its own name instead of the host's
1288
- //
1289
- // THE HOST'S IDENTITY, WRITTEN INTO THE SHELL'S IDS. <ChildPersona> renders name, handle and the
1290
- // small print as spans with these ids precisely so one function can fill them: the page is built
1291
- // once and mounted on every persona's host, so none of it is knowable at build time.
1292
- //
1293
- // Each write is guarded because a MISSING value must leave the server's fallback standing — the
1294
- // child's own words, which are correct when the lookup never returns. Blanking them on a failed
1295
- // fetch would turn "we could not reach the registry" into "this persona has no name".
1296
- const put = (id, text) => { const el = document.getElementById(id); if (el && text) el.textContent = text; };
1297
- put("pnName", face.name);
1298
- put("pnHandle", face.handle ? "@" + face.handle : null);
1299
-
1300
- // queries: the child persona shows raw HTML · <span class="mtag"> printed as text · the meta line
1301
- // shows markup · unrendered html in the profile · pnMeta
1302
- //
1303
- // THE META LINE IS MARKUP, AND IT ARRIVES FROM A REGISTRY. A persona's `meta` is a row of chips —
1304
- // `<span class="mtag">Fast</span>…` — and the Profile cut renders the persona's OWN with `set:html`
1305
- // because it is that persona's file. This is the same string coming back over the network, and
1306
- // `textContent` printed it verbatim: three child personas on every host showed a paragraph of angle
1307
- // brackets under the bio.
1308
- //
1309
- // `innerHTML` IS THE OBVIOUS FIX AND IT IS THE WRONG ONE. That would put remote markup into the
1310
- // document on every host in the fleet, and `meta` is written by each persona's own manifest — an
1311
- // `onerror=` in one persona's registry entry would then run inside /me, /files and the feed
1312
- // wherever they are mounted. A child persona is the LAST place to be permissive: it is the surface
1313
- // that shows a person their own vault.
1314
- //
1315
- // So the markup is parsed but never adopted. DOMParser builds an inert document — no scripts, no
1316
- // network — the TEXT of each chip is read out of it, and this file creates the elements itself.
1317
- // Whatever arrives, what reaches the page is spans this code made.
1318
- const meta = document.getElementById("pnMeta");
1319
- if (meta && face.meta) {
1320
- const inert = new DOMParser().parseFromString("<body>" + face.meta + "</body>", "text/html");
1321
- const chips = [...inert.body.querySelectorAll("span, li")].filter((n) => n.textContent.trim());
1322
- meta.textContent = "";
1323
- if (!chips.length) meta.textContent = inert.body.textContent.trim();
1324
- else for (const c of chips) {
1325
- const span = document.createElement("span");
1326
- span.className = "mtag";
1327
- span.textContent = c.textContent.trim();
1328
- meta.append(span);
1329
- }
1330
- }
1331
- if (face.avatar) {
1332
- const slot = document.getElementById("hostGlyph");
1333
- if (slot) slot.innerHTML = '<img class="mk" src="' + face.avatar + '" alt="">';
1334
- }
1335
- return face;
1336
- }
1337
-
1338
- // queries: toolbar mark · the persona icon has a background in the row · icon.svg in the toolbar ·
1339
- // a filled tile in the toolbar · derive the row's mark from the avatar · toolbarMark
1340
- //
1341
- // THE AVATAR'S MARK, MADE FIT FOR A ROW OF ICONS — from the SAME FILE, not a second drawing.
1342
- //
1343
- // A persona's `icon.svg` is a TILE: a squircle ground with the mark on it, drawn to sit in an avatar
1344
- // well or a Home Screen. Put that file in the toolbar as an `<img>` and it arrives with its ground
1345
- // intact — the only object in the row with a background, a little coloured card among four inks. It
1346
- // is exactly what the founder kept seeing and could not name: *"neden background olacak sekilde
1347
- // fill edip kullaniyorsun"*.
1348
- //
1349
- // qr had already solved it, and the shape of the solution is the reason this is here rather than in
1350
- // fifteen repos: **derive, never redraw.** Its comment says it best — *"THE SAME FILE, three edits
1351
- // deep — not a second drawing. Whatever happens to icon.svg happens here."* A clever second face is
1352
- // still a second face, and it drifts the day somebody redraws one of them.
1353
- //
1354
- // The three edits, generalised across the fleet's fourteen marks (all `viewBox="0 0 100 100"` with an
1355
- // identical `<rect width="100" height="100" rx="26" fill="#0a0d18">` ground):
1356
- //
1357
- // 1. THE GROUND GOES. In the avatar the mark is a tile ON something; in the row it is one item IN
1358
- // a line, and a filled tile there is the only thing with a background.
1359
- // 2. IDS ARE NAMESPACED. Both copies are on the same page — the avatar and the row — and two
1360
- // elements cannot share an id: a `url(#…)` silently resolves to whichever came first, so one of
1361
- // the two marks loses its gradient with nothing reported.
1362
- // 3. THE AUTHORING NOTE GOES. It is explanation aimed at whoever edits the file, and it has no
1363
- // business shipping twice on every page load.
1364
- //
1365
- // What it does NOT do is recolour. Whether the row's mark takes `currentColor` is the persona's own
1366
- // decision, made in its CSS — some marks are a silhouette and read as ink, some carry a gradient
1367
- // that IS the identity. This only removes what the row cannot use.
1368
- export function toolbarMark(iconSvg, options) {
1369
- const o = options || {};
1370
- const ns = o.id || "tb";
1371
- let s = String(iconSvg || "");
1372
- if (!s) return "";
1373
-
1374
- // 1. the authoring note
1375
- s = s.replace(/<!--[\s\S]*?-->/g, "");
1376
-
1377
- // 2. the ground — a rect that covers the whole viewBox, whatever its corner radius or fill.
1378
- // Matched against the viewBox rather than against "100" so a mark drawn at another size still
1379
- // loses its tile.
1380
- const vb = /viewBox="\s*0\s+0\s+([\d.]+)\s+([\d.]+)/.exec(s);
1381
- if (vb) {
1382
- const [, w, h] = vb;
1383
- const tile = new RegExp(`<rect(?=[^>]*\\bwidth="${w}")(?=[^>]*\\bheight="${h}")[^>]*/>\\s*`, "g");
1384
- s = s.replace(tile, "");
1385
- }
1386
-
1387
- // 3. ids, and every reference to them. Done together so a rename cannot half-apply.
1388
- const ids = [...s.matchAll(/\bid="([^"]+)"/g)].map((m) => m[1]);
1389
- for (const id of ids) {
1390
- const safe = id.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
1391
- s = s.replace(new RegExp(`\\bid="${safe}"`, "g"), `id="${id}-${ns}"`)
1392
- .replace(new RegExp(`url\\(#${safe}\\)`, "g"), `url(#${id}-${ns})`)
1393
- .replace(new RegExp(`(href|xlink:href)="#${safe}"`, "g"), `$1="#${id}-${ns}"`);
1394
- }
1395
-
1396
- // queries: the track ring disappears in the toolbar · white on white · the dial is missing in light
1397
- // mode · rgba(255,255,255,0.16) · half the mark vanished when the ground came off
1398
- //
1399
- // 4. WHAT ONLY MADE SENSE ON THE TILE. Five marks in the fleet draw an unlit "track" — a dial, the
1400
- // ring a progress arc runs on — as `rgba(255,255,255,0.16)`. White at 16% is a correct choice
1401
- // ON the near-black tile and a meaningless one off it: in a light toolbar it is white on white,
1402
- // so the mark arrives with a piece silently missing, and only in one colour scheme. time's dial
1403
- // vanished exactly this way the day it was drawn, leaving the two hands reading as an L.
1404
- //
1405
- // It becomes the row's own ink at the same weight. This is not recolouring the mark — the rule
1406
- // above still stands, and the FIGURE is left alone. It is the same act as removing the ground:
1407
- // the tile is gone, so what was drawn against the tile has to be told what it is against now.
1408
- s = s.replace(/(stroke|fill)="rgba\(\s*255\s*,\s*255\s*,\s*255\s*,\s*([\d.]+)\s*\)"/g,
1409
- (_, prop, a) => `${prop}="currentColor" ${prop}-opacity="${a}"`);
1410
-
1411
- // 5. it is decoration in the row — the link around it carries the name
1412
- s = s.replace(/\srole="img"/, "").replace(/\saria-label="[^"]*"/, "");
1413
- if (!/aria-hidden/.test(s)) s = s.replace(/<svg /, '<svg aria-hidden="true" ');
1414
- if (o.class) s = s.replace(/<svg /, `<svg class="${o.class}" `);
1415
-
1416
- // queries: the persona mark is always coloured · two toolbar icons look active · the accent is
1417
- // everywhere in the row · which icon should be coloured · currentColor toolbar mark
1418
- //
1419
- // THE MARK IS INK UNTIL ITS CUT IS CURRENT — the founder's golden rule, 2026-08-03:
1420
- //
1421
- // "active persona cut'un icon'u accent rengini alır. diğer passive cut iconları ise accent
1422
- // rengini kullanmaz."
1423
- //
1424
- // The accent has exactly one job in this row: to answer *where am I*. A mark that keeps its own
1425
- // colours while another cut is current is a second voice on that channel — measured at the kernel,
1426
- // with the active bolt reading a chroma of 6 to 12, the passive marks read 8 to 20. Several were
1427
- // MORE coloured than the icon that was actually current.
1428
- //
1429
- // THIS FILE ARGUED THE OPPOSITE, and the argument is kept because it shows a true premise ageing
1430
- // into a wrong conclusion: *"a mark is an identity, not a UI state — a faded logo reads as disabled
1431
- // rather than as not-current."* True while the mark arrived as an `<img>`, which cannot take
1432
- // `currentColor`, so dimming was the only way to say "not here". That premise expired the day this
1433
- // function started deriving an inline SVG. An inline mark can be ink, and ink is not dimming.
1434
- //
1435
- // Only the PAINT is neutralised, and only outside `<defs>`: the gradients stay defined, so a
1436
- // persona that wants its own colours *while current* can re-point to them from its own CSS. qr
1437
- // does. That is a decision about what the accent looks like, never about when it appears.
1438
- {
1439
- const cut = s.lastIndexOf("</defs>");
1440
- const head = cut >= 0 ? s.slice(0, cut + 7) : "";
1441
- const body = (cut >= 0 ? s.slice(cut + 7) : s)
1442
- // `fill="none"` is not paint, it is the absence of it — a stroked shape says so and must keep
1443
- // saying so, or every outline becomes a silhouette.
1444
- .replace(/\b(fill|stroke)="(?!none")[^"]*"/g, '$1="currentColor"');
1445
- s = head + body;
1446
- }
1447
-
1448
- // queries: the derived mark is too small · fills · the mark shrank when the ground came off ·
1449
- // box for 20 ink
1450
- //
1451
- // TAKING THE GROUND OFF DOES NOT MAKE THE DRAWING BIGGER — it only removes what was behind it. A
1452
- // mark drawn to sit inside a tile keeps the tile's padding: measured across the fleet, the marks
1453
- // occupy between 0.46 and 0.68 of their viewBox, so in a 20px box they put 9 to 13 on screen. The
1454
- // row's rule is 20 of INK, so the box has to be 20 divided by that fraction.
1455
- //
1456
- // `fills` is the persona's own measurement, the way its accent is — a property of ITS drawing, not
1457
- // a rule copied between repos. That distinction is the whole reason it is a number passed in
1458
- // rather than a stylesheet each persona keeps: copying a rule is O(N) debt, carrying your own
1459
- // measurement is data. Redraw the mark and this moves; nothing else does.
1460
- //
1461
- // Written as an inline style because the cut's `.tb-nav svg { width: 20px }` would beat a width
1462
- // ATTRIBUTE. Left out, the mark takes the row's default and reads small — which is what shipped for
1463
- // one deploy and is exactly how the fleet's ratios came to be measured.
1464
- // queries: the mark in the preroll is tiny · ink option · use the derived mark somewhere else ·
1465
- // toolbarMark size
1466
- //
1467
- // `ink` IS THE MEASURE, AND THE ROW IS ONLY ITS FIRST CUSTOMER. The derivation here — take the
1468
- // ground off, namespace the ids so two copies on one page do not fight over a gradient — is what
1469
- // ANY surface needs that wants the mark without its tile. The preroll wants exactly that at 300px
1470
- // rather than 20, and the alternative was a second copy of the stripping logic under a second
1471
- // name, which is the O(N) debt this package exists to refuse.
1472
- //
1473
- // So the number is a parameter and the default is the row's. The function keeps its name because
1474
- // the row is still what it is for nine times in ten; that the name is now narrower than the job is
1475
- // worth one line of honesty rather than a rename across sixteen repos.
1476
- if (o.fills > 0) {
1477
- const px = ((o.ink || 20) / o.fills).toFixed(2);
1478
- s = s.replace(/<svg /, `<svg style="width:${px}px;height:${px}px" `);
1479
- }
1480
- return s.trim();
1481
- }
1482
-
1483
- // queries: the child persona shows the parent's icon with a background · navParent has a ground ·
1484
- // a child cannot know the parent's fills · adopt the host's mark · adoptMark ·
1485
- // the parent icon in the child toolbar is small · derive a mark I only have a URL for
1486
- //
1487
- // THE SAME RULE, FOR THE ONE CASE THAT CANNOT BE BUILT — a child persona holds a URL, not a drawing.
1488
- //
1489
- // `toolbarMark` above runs at BUILD time on a file the persona imports, and takes `fills` as data
1490
- // because a persona knows its own drawing. A child persona knows neither: `/me`, `/files` and the
1491
- // feed are built once and mounted on every host in the fleet, so the mark in their row belongs to
1492
- // whichever persona they happen to be inside. It arrives as `<img src="/icon.svg">` — the tile, the
1493
- // ground, the one background in a line of inks — and there is no build step at which it is known.
1494
- //
1495
- // So it is fetched and derived in the browser instead, through the SAME function, and then the thing
1496
- // that could not be passed in is MEASURED: `getBBox()` reports the ink's extent in viewBox units,
1497
- // which is `fills` — read off the drawing rather than told to us. That is the better half of this:
1498
- // it needs no registry field, no per-parent table, and a persona that redraws its icon tomorrow gets
1499
- // the right box the same afternoon, with nothing to bump.
1500
- //
1501
- // IT DEGRADES TO THE TILE. Every failure — offline, a 404 that answers with HTML, a hidden row where
1502
- // `getBBox` throws — leaves the `<img>` standing, which is today's appearance and legible. The image
1503
- // is removed only once the derived mark is in the document.
1504
- export async function adoptMark(options) {
1505
- const o = options || {};
1506
- if (typeof document === "undefined") return null;
1507
- const el = o.el || document.getElementById(o.id || "navParent");
1508
- if (!el) return null;
1509
- const img = el.querySelector("img");
1510
- const url = o.url || (img && img.getAttribute("src")) || "/icon.svg";
1511
-
1512
- let src = "";
1513
- try {
1514
- const r = await fetch(url);
1515
- if (!r.ok) return null;
1516
- src = await r.text();
1517
- } catch { return null; }
1518
- // A missing file that answers with the persona's 404 PAGE is still a 200 in some setups, and
1519
- // injecting that would put a document where a glyph goes.
1520
- if (!/<svg[\s>]/.test(src)) return null;
1521
-
1522
- const html = toolbarMark(src, { id: o.ns || "adopted", class: o.class });
1523
- if (!html) return null;
1524
- el.insertAdjacentHTML("afterbegin", html);
1525
- const svg = el.querySelector("svg");
1526
- if (!svg) return null;
1527
- if (img) img.remove();
1528
-
1529
- // queries: the parent icon still has a background · app.zone mark has a black tile in the child
1530
- // toolbar · the ground was not removed · a path ground · squircle path
1531
- //
1532
- // THE GROUND IS WHATEVER IS BEHIND EVERYTHING, AND HERE IT CAN BE MEASURED.
1533
- //
1534
- // `toolbarMark` finds a ground by matching a `<rect>` against the viewBox, because at build time a
1535
- // string is all it has. Fourteen personas draw exactly that rect. The fifteenth is app.zone, whose
1536
- // mark comes out of a design tool as a 1024 viewBox with the squircle as a hand-drawn `<path>` —
1537
- // so its tile survived, and /me and /files on app.zone showed a black card in a row of inks while
1538
- // every other host was correct.
1539
- //
1540
- // Chasing that with another string rule would be chasing the sixteenth drawing next. In the
1541
- // browser the question is geometric and answerable: a ground is the BACKMOST painted shape that
1542
- // covers the whole viewBox. Measure it and remove it, whatever it was drawn as.
1543
- //
1544
- // Only the first shape, and only a shape — a `<g>` may legitimately wrap the entire mark, and
1545
- // removing that would remove the drawing rather than what is behind it.
1546
- const vb = (svg.getAttribute("viewBox") || "").split(/[\s,]+/).map(Number);
1547
- if (vb.length === 4 && vb[2] > 0 && vb[3] > 0) {
1548
- const back = [...svg.children].find((n) => /^(path|rect|circle|ellipse|polygon|polyline)$/i.test(n.tagName));
1549
- try {
1550
- if (back) {
1551
- const bb = back.getBBox();
1552
- if (bb.width >= vb[2] * 0.97 && bb.height >= vb[3] * 0.97) back.remove();
1553
- }
1554
- } catch { /* not rendered — leave the drawing whole */ }
1555
- }
1556
-
1557
- // the measurement `fills` would have carried, taken from the drawing itself
1558
- let box = 20;
1559
- try {
1560
- const bb = svg.getBBox();
1561
- if (vb.length === 4 && vb[2] > 0 && vb[3] > 0 && bb.width > 0) {
1562
- const fills = Math.max(bb.width / vb[2], bb.height / vb[3]);
1563
- // a sane band: a drawing filling under a twentieth of its box is a parse we do not trust, and
1564
- // one filling it whole needs no help.
1565
- if (fills > 0.05 && fills < 1) box = 20 / fills;
1566
- }
1567
- } catch { /* not rendered — the row's default stands */ }
1568
-
1569
- // queries: the parent icon is bigger than the other icons · the parent mark overflows the row ·
1570
- // navParent looks shifted · the child toolbar mark is twice the size · adoptMark overflow
1571
- //
1572
- // A CEILING, BECAUSE NORMALISING INK CANNOT BE ALLOWED TO BREAK THE ROW.
1573
- //
1574
- // The scale above equalises INK: whatever the drawing, its ink lands at 20px, so a mark with
1575
- // generous padding is scaled up until it reads like its neighbours. That is right, and it is
1576
- // unbounded — the more padding a drawing carries, the larger the box it asks for, with nothing
1577
- // stopping it at the size of the slot it lives in.
1578
- //
1579
- // Measured on the fleet, 2026-08-06, after the founder reported the parent mark looking shifted on
1580
- // pin.games' children and nowhere else:
1581
- //
1582
- // app.zone/icon.svg ink fills 73% → 27.3px, inside a 38×36 slot
1583
- // pin.games/icon.svg ink fills 37% → 53.8px, half again the slot's height
1584
- //
1585
- // pin.games draws its glyph with an app icon's padding — an iOS tile, correct on a home screen and
1586
- // twice the fleet's inset. Nothing was wrong with the file and nothing was wrong with the scale;
1587
- // what was missing is that a row icon belongs to the ROW, so the row's box is the limit. Clamped
1588
- // rather than skipped, so the mark still grows as far as it usefully can.
1589
- //
1590
- // The remaining half is the persona's: a mark clamped to the slot reads smaller than its
1591
- // neighbours, because the drawing genuinely carries less ink. That is a drawing to redraw, not a
1592
- // number to fudge here.
1593
- //
1594
- // THE CEILING IS THE SLOT AND NOT A PIXEL LESS, because the founder asked the right question —
1595
- // *"sadece pin games için böyle oldu, şimdi diğer tüm personalar bundan olumsuz etkilenir mi?"* —
1596
- // and the first answer was yes. A ceiling of `slot − 4` was measured against all twenty-one live
1597
- // personas and would have shrunk THIRTEEN of them, from 33–35px down to 32, none of which was
1598
- // overflowing anything. Computed across the fleet, 2026-08-06:
1599
- //
1600
- // under the slot, untouched app.zone 27.3 · justai.pro 29.4 · lendcam 30.8 · qr 34.2 ·
1601
- // time 34.5 · sudoku 34.6 · whatismyip 35.7 · fourteen more
1602
- // over it, clamped pin.games 53.8 · auth 38.5 · password-generator 38.5
1603
- //
1604
- // A rail that changes anything already inside its limit is not a rail, it is a redesign — so the
1605
- // limit is exactly the box the mark has to live in, and a mark that fits is left alone to the pixel.
1606
- const ceiling = Math.max(20, el.clientHeight || 36);
1607
- if (box > ceiling) box = ceiling;
1608
-
1609
- svg.style.width = box.toFixed(2) + "px";
1610
- svg.style.height = box.toFixed(2) + "px";
1611
- return svg;
1612
- }