@justai/core 0.20.0 → 0.22.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 +151 -0
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@justai/core",
3
- "version": "0.20.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.22.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,157 @@ 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
+ // 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
+ ".xr-rhythm{background:repeating-linear-gradient(to bottom,rgba(128,128,128,.22) 0 1px,transparent 1px 8px)}",
92
+ ".xr-f{position:fixed;pointer-events:none;z-index:2147483000}",
93
+ ".xr-f>i{position:absolute;top:3px;right:7px;font-size:.68rem;font-style:normal;letter-spacing:.07em;text-transform:uppercase;opacity:.55}",
94
+ ".xr-edge{border:3px solid #E8503A}",
95
+ ".xr-act{border:1px solid rgba(128,128,128,.65)}",
96
+ ".xr-ttl{border:1px dashed rgba(128,128,128,.5)}",
97
+ ".xr-c{position:fixed;background:rgba(128,128,128,.7);pointer-events:none;z-index:2147483000}",
98
+ ".xr-read{position:fixed;left:12px;bottom:12px;pointer-events:none;z-index:2147483001;",
99
+ "display:grid;grid-template-columns:auto 1fr;gap:2px 12px;padding:10px 12px;border-radius:10px;",
100
+ "background:rgba(20,22,28,.92);color:#f2f4f8;font:400 .78rem/1.35 ui-monospace,SFMono-Regular,Menlo,monospace}",
101
+ ".xr-read b{font-weight:400;opacity:.6}",
102
+ ".xr-read s{text-decoration:none;font-variant-numeric:tabular-nums}",
103
+ ".xr-read s[data-ok=no]{color:#ff6b6b;font-weight:700}",
104
+ ".xr-read s[data-ok=yes]{color:#7ee787}",
105
+ ].join("");
106
+ document.head.appendChild(css);
107
+
108
+ var mk = (cls, html) => { var d = document.createElement("div"); d.className = cls; if (html) d.innerHTML = html; document.body.appendChild(d); return d; };
109
+ var rhythm = mk("xr xr-rhythm");
110
+ var edge = mk("xr-f xr-edge", "<i>edge of frame</i>");
111
+ var act = mk("xr-f xr-act", "<i>action safe</i>");
112
+ var ttl = mk("xr-f xr-ttl", "<i>title safe</i>");
113
+ var ticks = [0,1,2,3,4,5].map(() => mk("xr-c"));
114
+ var read = mk("xr-read");
115
+
116
+ var row = (label) => {
117
+ var b = document.createElement("b"); b.textContent = label;
118
+ var s = document.createElement("s");
119
+ read.appendChild(b); read.appendChild(s);
120
+ return s;
121
+ };
122
+ var R = { viewport: row("viewport"), column: row("column"), gutter: row("gutter L/R"),
123
+ frame: row("frame"), act: row("action safe"), ttl: row("title safe"),
124
+ bar: row("toolbar"), clear: row("clears bar"), safe: row("safe area L/R"),
125
+ bleed: row("bleed") };
126
+ var put = (el, text, ok) => { el.textContent = text; if (ok !== undefined) el.dataset.ok = ok ? "yes" : "no"; };
127
+ var px = (n) => Math.round(n * 10) / 10 + "px";
128
+ var box = (el, r, inset) => {
129
+ el.style.left = (r.left + inset) + "px"; el.style.top = (r.top + inset) + "px";
130
+ el.style.width = Math.max(0, r.width - inset * 2) + "px";
131
+ el.style.height = Math.max(0, r.height - inset * 2) + "px";
132
+ };
133
+
134
+ var draw = () => {
135
+ var k = K(); if (!k) return;
136
+ var r = k.getBoundingClientRect();
137
+ var app = document.querySelector(".app");
138
+ var cs = app ? getComputedStyle(app) : null;
139
+ var padL = cs ? parseFloat(cs.paddingLeft) || 0 : 0;
140
+ var padR = cs ? parseFloat(cs.paddingRight) || 0 : 0;
141
+ var g = cs ? parseFloat(cs.getPropertyValue("--gutter")) || 16 : 16;
142
+
143
+ box(edge, r, 0); box(act, r, g); box(ttl, r, g * 2); box(rhythm, r, 0);
144
+
145
+ // ticks: N S W E and the centre cross — the two questions a printed overlay answers for free,
146
+ // is this centred and is the middle where you think it is
147
+ var t = [[r.left + r.width / 2, r.top, 1, 14], [r.left + r.width / 2, r.bottom - 14, 1, 14],
148
+ [r.left, r.top + r.height / 2, 14, 1], [r.right - 14, r.top + r.height / 2, 14, 1],
149
+ [r.left + r.width / 2, r.top + r.height / 2 - 9, 1, 18],
150
+ [r.left + r.width / 2 - 9, r.top + r.height / 2, 18, 1]];
151
+ ticks.forEach((el, i) => { el.style.left = t[i][0] + "px"; el.style.top = t[i][1] + "px";
152
+ el.style.width = t[i][2] + "px"; el.style.height = t[i][3] + "px"; });
153
+
154
+ var aw = app ? app.getBoundingClientRect().width : r.width;
155
+ put(R.viewport, Math.round(innerWidth) + " x " + Math.round(innerHeight));
156
+ put(R.column, px(aw), aw <= 640);
157
+ var even = Math.abs(padL - padR) < 0.5;
158
+ put(R.gutter, px(padL) + " / " + px(padR) + (even ? "" : " <- the two sides differ"), even);
159
+ put(R.frame, px(r.width) + " x " + px(r.height));
160
+ put(R.act, "inset " + px(g) + " . " + px(r.width - g * 2) + " wide");
161
+ put(R.ttl, "inset " + px(g * 2) + " . " + px(r.width - g * 4) + " wide");
162
+
163
+ var bar = document.querySelector(".toolbar");
164
+ if (bar) {
165
+ var bh = bar.getBoundingClientRect().height;
166
+ // Scroll-independent on purpose: comparing the kernel's top to the bar's bottom in viewport
167
+ // coordinates reports an overlap the moment the page has scrolled. The real question is about
168
+ // the LANDING — the bar is sticky, the page lands on #kernel, and scroll-margin-top decides
169
+ // whether the first thing here arrives below the bar or underneath it.
170
+ var landing = parseFloat(getComputedStyle(k).scrollMarginTop) || 0;
171
+ var air = landing - bh;
172
+ put(R.bar, px(bh) + " . lands at " + px(landing));
173
+ put(R.clear, air < -0.5 ? px(air) + " <- kernel UNDER the bar" : px(air), air >= -0.5);
174
+ } else { put(R.bar, "none"); put(R.clear, "-"); }
175
+
176
+ // env() is not readable from JS, so it is measured: what the browser applied minus what the CSS
177
+ // asked for IS the safe area.
178
+ put(R.safe, px(Math.max(0, padL - g)) + " / " + px(Math.max(0, padR - g)));
179
+ var over = Math.max(0, Math.round(document.documentElement.scrollWidth - innerWidth));
180
+ put(R.bleed, over ? over + "px past the viewport" : "none", over === 0);
181
+ };
182
+
183
+ var tick = false;
184
+ var schedule = () => { if (tick) return; tick = true; requestAnimationFrame(() => { tick = false; draw(); }); };
185
+ draw();
186
+ addEventListener("resize", schedule, { passive: true });
187
+ addEventListener("scroll", schedule, { passive: true });
188
+ if (document.fonts && document.fonts.ready) document.fonts.ready.then(draw);
189
+ }
190
+ })()`;
191
+
41
192
  /**
42
193
  * Hold the paint until a page marks itself ready (`body.ready`), gated behind `.js` so the page is
43
194
  * always visible with JS off and never flashes before positioning at the Kernel.