@justai/core 0.14.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/index.js +63 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@justai/core",
3
- "version": "0.14.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.js CHANGED
@@ -987,3 +987,66 @@ export function toolbarMark(iconSvg, options) {
987
987
  }
988
988
  return s.trim();
989
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
+ }