@justai/core 0.13.0 → 0.15.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@justai/core",
3
- "version": "0.13.0",
3
+ "version": "0.15.0",
4
4
  "description": "The framework-free heart of the persona shell — the load-bearing behaviour (auth capture, reveal, ready) as plain strings, so Astro and Next inject the SAME logic instead of each re-writing it.",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {
package/src/index.d.ts CHANGED
@@ -125,5 +125,16 @@ export declare function childFace(options?: {
125
125
  */
126
126
  export declare function toolbarMark(
127
127
  iconSvg: string,
128
- options?: { id?: string; class?: string },
128
+ options?: {
129
+ id?: string;
130
+ class?: string;
131
+ /**
132
+ * How much of its viewBox this persona's drawing actually fills, 0–1. The row shows 20px of INK,
133
+ * so the box becomes `20 / fills` — a mark drawn inside a tile keeps the tile's padding and would
134
+ * otherwise read at 9–13px. Measure it once (`getBBox().width / viewBox width`, longer side) and
135
+ * write it down; it is this persona's own number, like its accent, and it moves when the mark is
136
+ * redrawn.
137
+ */
138
+ fills?: number;
139
+ },
129
140
  ): string;
package/src/index.js CHANGED
@@ -964,5 +964,89 @@ export function toolbarMark(iconSvg, options) {
964
964
  s = s.replace(/\srole="img"/, "").replace(/\saria-label="[^"]*"/, "");
965
965
  if (!/aria-hidden/.test(s)) s = s.replace(/<svg /, '<svg aria-hidden="true" ');
966
966
  if (o.class) s = s.replace(/<svg /, `<svg class="${o.class}" `);
967
+
968
+ // queries: the derived mark is too small · fills · the mark shrank when the ground came off ·
969
+ // box for 20 ink
970
+ //
971
+ // TAKING THE GROUND OFF DOES NOT MAKE THE DRAWING BIGGER — it only removes what was behind it. A
972
+ // mark drawn to sit inside a tile keeps the tile's padding: measured across the fleet, the marks
973
+ // occupy between 0.46 and 0.68 of their viewBox, so in a 20px box they put 9 to 13 on screen. The
974
+ // row's rule is 20 of INK, so the box has to be 20 divided by that fraction.
975
+ //
976
+ // `fills` is the persona's own measurement, the way its accent is — a property of ITS drawing, not
977
+ // a rule copied between repos. That distinction is the whole reason it is a number passed in
978
+ // rather than a stylesheet each persona keeps: copying a rule is O(N) debt, carrying your own
979
+ // measurement is data. Redraw the mark and this moves; nothing else does.
980
+ //
981
+ // Written as an inline style because the cut's `.tb-nav svg { width: 20px }` would beat a width
982
+ // ATTRIBUTE. Left out, the mark takes the row's default and reads small — which is what shipped for
983
+ // one deploy and is exactly how the fleet's ratios came to be measured.
984
+ if (o.fills > 0) {
985
+ const px = (20 / o.fills).toFixed(2);
986
+ s = s.replace(/<svg /, `<svg style="width:${px}px;height:${px}px" `);
987
+ }
967
988
  return s.trim();
968
989
  }
990
+
991
+ // queries: the child persona shows the parent's icon with a background · navParent has a ground ·
992
+ // a child cannot know the parent's fills · adopt the host's mark · adoptMark ·
993
+ // the parent icon in the child toolbar is small · derive a mark I only have a URL for
994
+ //
995
+ // THE SAME RULE, FOR THE ONE CASE THAT CANNOT BE BUILT — a child persona holds a URL, not a drawing.
996
+ //
997
+ // `toolbarMark` above runs at BUILD time on a file the persona imports, and takes `fills` as data
998
+ // because a persona knows its own drawing. A child persona knows neither: `/me`, `/files` and the
999
+ // feed are built once and mounted on every host in the fleet, so the mark in their row belongs to
1000
+ // whichever persona they happen to be inside. It arrives as `<img src="/icon.svg">` — the tile, the
1001
+ // ground, the one background in a line of inks — and there is no build step at which it is known.
1002
+ //
1003
+ // So it is fetched and derived in the browser instead, through the SAME function, and then the thing
1004
+ // that could not be passed in is MEASURED: `getBBox()` reports the ink's extent in viewBox units,
1005
+ // which is `fills` — read off the drawing rather than told to us. That is the better half of this:
1006
+ // it needs no registry field, no per-parent table, and a persona that redraws its icon tomorrow gets
1007
+ // the right box the same afternoon, with nothing to bump.
1008
+ //
1009
+ // IT DEGRADES TO THE TILE. Every failure — offline, a 404 that answers with HTML, a hidden row where
1010
+ // `getBBox` throws — leaves the `<img>` standing, which is today's appearance and legible. The image
1011
+ // is removed only once the derived mark is in the document.
1012
+ export async function adoptMark(options) {
1013
+ const o = options || {};
1014
+ if (typeof document === "undefined") return null;
1015
+ const el = o.el || document.getElementById(o.id || "navParent");
1016
+ if (!el) return null;
1017
+ const img = el.querySelector("img");
1018
+ const url = o.url || (img && img.getAttribute("src")) || "/icon.svg";
1019
+
1020
+ let src = "";
1021
+ try {
1022
+ const r = await fetch(url);
1023
+ if (!r.ok) return null;
1024
+ src = await r.text();
1025
+ } catch { return null; }
1026
+ // A missing file that answers with the persona's 404 PAGE is still a 200 in some setups, and
1027
+ // injecting that would put a document where a glyph goes.
1028
+ if (!/<svg[\s>]/.test(src)) return null;
1029
+
1030
+ const html = toolbarMark(src, { id: o.ns || "adopted", class: o.class });
1031
+ if (!html) return null;
1032
+ el.insertAdjacentHTML("afterbegin", html);
1033
+ const svg = el.querySelector("svg");
1034
+ if (!svg) return null;
1035
+ if (img) img.remove();
1036
+
1037
+ // the measurement `fills` would have carried, taken from the drawing itself
1038
+ let box = 20;
1039
+ try {
1040
+ const vb = (svg.getAttribute("viewBox") || "").split(/[\s,]+/).map(Number);
1041
+ const bb = svg.getBBox();
1042
+ if (vb.length === 4 && vb[2] > 0 && vb[3] > 0 && bb.width > 0) {
1043
+ const fills = Math.max(bb.width / vb[2], bb.height / vb[3]);
1044
+ // a sane band: a drawing filling under a twentieth of its box is a parse we do not trust, and
1045
+ // one filling it whole needs no help.
1046
+ if (fills > 0.05 && fills < 1) box = 20 / fills;
1047
+ }
1048
+ } catch { /* not rendered — the row's default stands */ }
1049
+ svg.style.width = box.toFixed(2) + "px";
1050
+ svg.style.height = box.toFixed(2) + "px";
1051
+ return svg;
1052
+ }