@justai/core 0.19.0 → 0.21.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.
Files changed (2) hide show
  1. package/package.json +2 -2
  2. package/src/index.js +171 -0
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@justai/core",
3
- "version": "0.19.0",
4
- "description": "The framework-free heart of the persona shell — the load-bearing behaviour (auth capture, reveal, ready) as plain strings, so Astro and Next inject the SAME logic instead of each re-writing it.",
3
+ "version": "0.21.0",
4
+ "description": "The framework-free heart of the persona shell \u2014 the load-bearing behaviour (auth capture, reveal, ready) as plain strings, so Astro and Next inject the SAME logic instead of each re-writing it.",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {
7
7
  "type": "git",
package/src/index.js CHANGED
@@ -38,6 +38,145 @@ export const AUTH_CAPTURE_JS =
38
38
  /** Mark that JavaScript is running, so the reveal below can hold paint only when JS can un-hold it. */
39
39
  export const JS_CLASS_JS = `document.documentElement.classList.add("js")`;
40
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
+ var K = () => document.getElementById("kernel");
75
+ if (!K()) return;
76
+
77
+ var css = document.createElement("style");
78
+ css.textContent = [
79
+ ".xr{position:fixed;pointer-events:none;z-index:2147483000}",
80
+ ".xr-rhythm{background:repeating-linear-gradient(to bottom,rgba(128,128,128,.22) 0 1px,transparent 1px 8px)}",
81
+ ".xr-f{position:fixed;pointer-events:none;z-index:2147483000}",
82
+ ".xr-f>i{position:absolute;top:3px;right:7px;font-size:.68rem;font-style:normal;letter-spacing:.07em;text-transform:uppercase;opacity:.55}",
83
+ ".xr-edge{border:3px solid #E8503A}",
84
+ ".xr-act{border:1px solid rgba(128,128,128,.65)}",
85
+ ".xr-ttl{border:1px dashed rgba(128,128,128,.5)}",
86
+ ".xr-c{position:fixed;background:rgba(128,128,128,.7);pointer-events:none;z-index:2147483000}",
87
+ ".xr-read{position:fixed;left:12px;bottom:12px;pointer-events:none;z-index:2147483001;",
88
+ "display:grid;grid-template-columns:auto 1fr;gap:2px 12px;padding:10px 12px;border-radius:10px;",
89
+ "background:rgba(20,22,28,.92);color:#f2f4f8;font:400 .78rem/1.35 ui-monospace,SFMono-Regular,Menlo,monospace}",
90
+ ".xr-read b{font-weight:400;opacity:.6}",
91
+ ".xr-read s{text-decoration:none;font-variant-numeric:tabular-nums}",
92
+ ".xr-read s[data-ok=no]{color:#ff6b6b;font-weight:700}",
93
+ ".xr-read s[data-ok=yes]{color:#7ee787}",
94
+ ].join("");
95
+ document.head.appendChild(css);
96
+
97
+ var mk = (cls, html) => { var d = document.createElement("div"); d.className = cls; if (html) d.innerHTML = html; document.body.appendChild(d); return d; };
98
+ var rhythm = mk("xr xr-rhythm");
99
+ var edge = mk("xr-f xr-edge", "<i>edge of frame</i>");
100
+ var act = mk("xr-f xr-act", "<i>action safe</i>");
101
+ var ttl = mk("xr-f xr-ttl", "<i>title safe</i>");
102
+ var ticks = [0,1,2,3,4,5].map(() => mk("xr-c"));
103
+ var read = mk("xr-read");
104
+
105
+ var row = (label) => {
106
+ var b = document.createElement("b"); b.textContent = label;
107
+ var s = document.createElement("s");
108
+ read.appendChild(b); read.appendChild(s);
109
+ return s;
110
+ };
111
+ var R = { viewport: row("viewport"), column: row("column"), gutter: row("gutter L/R"),
112
+ frame: row("frame"), act: row("action safe"), ttl: row("title safe"),
113
+ bar: row("toolbar"), clear: row("clears bar"), safe: row("safe area L/R"),
114
+ bleed: row("bleed") };
115
+ var put = (el, text, ok) => { el.textContent = text; if (ok !== undefined) el.dataset.ok = ok ? "yes" : "no"; };
116
+ var px = (n) => Math.round(n * 10) / 10 + "px";
117
+ var box = (el, r, inset) => {
118
+ el.style.left = (r.left + inset) + "px"; el.style.top = (r.top + inset) + "px";
119
+ el.style.width = Math.max(0, r.width - inset * 2) + "px";
120
+ el.style.height = Math.max(0, r.height - inset * 2) + "px";
121
+ };
122
+
123
+ var draw = () => {
124
+ var k = K(); if (!k) return;
125
+ var r = k.getBoundingClientRect();
126
+ var app = document.querySelector(".app");
127
+ var cs = app ? getComputedStyle(app) : null;
128
+ var padL = cs ? parseFloat(cs.paddingLeft) || 0 : 0;
129
+ var padR = cs ? parseFloat(cs.paddingRight) || 0 : 0;
130
+ var g = cs ? parseFloat(cs.getPropertyValue("--gutter")) || 16 : 16;
131
+
132
+ box(edge, r, 0); box(act, r, g); box(ttl, r, g * 2); box(rhythm, r, 0);
133
+
134
+ // ticks: N S W E and the centre cross — the two questions a printed overlay answers for free,
135
+ // is this centred and is the middle where you think it is
136
+ var t = [[r.left + r.width / 2, r.top, 1, 14], [r.left + r.width / 2, r.bottom - 14, 1, 14],
137
+ [r.left, r.top + r.height / 2, 14, 1], [r.right - 14, r.top + r.height / 2, 14, 1],
138
+ [r.left + r.width / 2, r.top + r.height / 2 - 9, 1, 18],
139
+ [r.left + r.width / 2 - 9, r.top + r.height / 2, 18, 1]];
140
+ ticks.forEach((el, i) => { el.style.left = t[i][0] + "px"; el.style.top = t[i][1] + "px";
141
+ el.style.width = t[i][2] + "px"; el.style.height = t[i][3] + "px"; });
142
+
143
+ var aw = app ? app.getBoundingClientRect().width : r.width;
144
+ put(R.viewport, Math.round(innerWidth) + " x " + Math.round(innerHeight));
145
+ put(R.column, px(aw), aw <= 640);
146
+ var even = Math.abs(padL - padR) < 0.5;
147
+ put(R.gutter, px(padL) + " / " + px(padR) + (even ? "" : " <- the two sides differ"), even);
148
+ put(R.frame, px(r.width) + " x " + px(r.height));
149
+ put(R.act, "inset " + px(g) + " . " + px(r.width - g * 2) + " wide");
150
+ put(R.ttl, "inset " + px(g * 2) + " . " + px(r.width - g * 4) + " wide");
151
+
152
+ var bar = document.querySelector(".toolbar");
153
+ if (bar) {
154
+ var bh = bar.getBoundingClientRect().height;
155
+ // Scroll-independent on purpose: comparing the kernel's top to the bar's bottom in viewport
156
+ // coordinates reports an overlap the moment the page has scrolled. The real question is about
157
+ // the LANDING — the bar is sticky, the page lands on #kernel, and scroll-margin-top decides
158
+ // whether the first thing here arrives below the bar or underneath it.
159
+ var landing = parseFloat(getComputedStyle(k).scrollMarginTop) || 0;
160
+ var air = landing - bh;
161
+ put(R.bar, px(bh) + " . lands at " + px(landing));
162
+ put(R.clear, air < -0.5 ? px(air) + " <- kernel UNDER the bar" : px(air), air >= -0.5);
163
+ } else { put(R.bar, "none"); put(R.clear, "-"); }
164
+
165
+ // env() is not readable from JS, so it is measured: what the browser applied minus what the CSS
166
+ // asked for IS the safe area.
167
+ put(R.safe, px(Math.max(0, padL - g)) + " / " + px(Math.max(0, padR - g)));
168
+ var over = Math.max(0, Math.round(document.documentElement.scrollWidth - innerWidth));
169
+ put(R.bleed, over ? over + "px past the viewport" : "none", over === 0);
170
+ };
171
+
172
+ var tick = false;
173
+ var schedule = () => { if (tick) return; tick = true; requestAnimationFrame(() => { tick = false; draw(); }); };
174
+ draw();
175
+ addEventListener("resize", schedule, { passive: true });
176
+ addEventListener("scroll", schedule, { passive: true });
177
+ if (document.fonts && document.fonts.ready) document.fonts.ready.then(draw);
178
+ })()`;
179
+
41
180
  /**
42
181
  * Hold the paint until a page marks itself ready (`body.ready`), gated behind `.js` so the page is
43
182
  * always visible with JS off and never flashes before positioning at the Kernel.
@@ -1049,6 +1188,38 @@ export function toolbarMark(iconSvg, options) {
1049
1188
  if (!/aria-hidden/.test(s)) s = s.replace(/<svg /, '<svg aria-hidden="true" ');
1050
1189
  if (o.class) s = s.replace(/<svg /, `<svg class="${o.class}" `);
1051
1190
 
1191
+ // queries: the persona mark is always coloured · two toolbar icons look active · the accent is
1192
+ // everywhere in the row · which icon should be coloured · currentColor toolbar mark
1193
+ //
1194
+ // THE MARK IS INK UNTIL ITS CUT IS CURRENT — the founder's golden rule, 2026-08-03:
1195
+ //
1196
+ // "active persona cut'un icon'u accent rengini alır. diğer passive cut iconları ise accent
1197
+ // rengini kullanmaz."
1198
+ //
1199
+ // The accent has exactly one job in this row: to answer *where am I*. A mark that keeps its own
1200
+ // colours while another cut is current is a second voice on that channel — measured at the kernel,
1201
+ // with the active bolt reading a chroma of 6 to 12, the passive marks read 8 to 20. Several were
1202
+ // MORE coloured than the icon that was actually current.
1203
+ //
1204
+ // THIS FILE ARGUED THE OPPOSITE, and the argument is kept because it shows a true premise ageing
1205
+ // into a wrong conclusion: *"a mark is an identity, not a UI state — a faded logo reads as disabled
1206
+ // rather than as not-current."* True while the mark arrived as an `<img>`, which cannot take
1207
+ // `currentColor`, so dimming was the only way to say "not here". That premise expired the day this
1208
+ // function started deriving an inline SVG. An inline mark can be ink, and ink is not dimming.
1209
+ //
1210
+ // Only the PAINT is neutralised, and only outside `<defs>`: the gradients stay defined, so a
1211
+ // persona that wants its own colours *while current* can re-point to them from its own CSS. qr
1212
+ // does. That is a decision about what the accent looks like, never about when it appears.
1213
+ {
1214
+ const cut = s.lastIndexOf("</defs>");
1215
+ const head = cut >= 0 ? s.slice(0, cut + 7) : "";
1216
+ const body = (cut >= 0 ? s.slice(cut + 7) : s)
1217
+ // `fill="none"` is not paint, it is the absence of it — a stroked shape says so and must keep
1218
+ // saying so, or every outline becomes a silhouette.
1219
+ .replace(/\b(fill|stroke)="(?!none")[^"]*"/g, '$1="currentColor"');
1220
+ s = head + body;
1221
+ }
1222
+
1052
1223
  // queries: the derived mark is too small · fills · the mark shrank when the ground came off ·
1053
1224
  // box for 20 ink
1054
1225
  //