@justai/core 0.14.0 → 0.16.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 +1 -1
- package/src/index.js +79 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@justai/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.16.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
|
@@ -960,7 +960,22 @@ export function toolbarMark(iconSvg, options) {
|
|
|
960
960
|
.replace(new RegExp(`(href|xlink:href)="#${safe}"`, "g"), `$1="#${id}-${ns}"`);
|
|
961
961
|
}
|
|
962
962
|
|
|
963
|
-
//
|
|
963
|
+
// queries: the track ring disappears in the toolbar · white on white · the dial is missing in light
|
|
964
|
+
// mode · rgba(255,255,255,0.16) · half the mark vanished when the ground came off
|
|
965
|
+
//
|
|
966
|
+
// 4. WHAT ONLY MADE SENSE ON THE TILE. Five marks in the fleet draw an unlit "track" — a dial, the
|
|
967
|
+
// ring a progress arc runs on — as `rgba(255,255,255,0.16)`. White at 16% is a correct choice
|
|
968
|
+
// ON the near-black tile and a meaningless one off it: in a light toolbar it is white on white,
|
|
969
|
+
// so the mark arrives with a piece silently missing, and only in one colour scheme. time's dial
|
|
970
|
+
// vanished exactly this way the day it was drawn, leaving the two hands reading as an L.
|
|
971
|
+
//
|
|
972
|
+
// It becomes the row's own ink at the same weight. This is not recolouring the mark — the rule
|
|
973
|
+
// above still stands, and the FIGURE is left alone. It is the same act as removing the ground:
|
|
974
|
+
// the tile is gone, so what was drawn against the tile has to be told what it is against now.
|
|
975
|
+
s = s.replace(/(stroke|fill)="rgba\(\s*255\s*,\s*255\s*,\s*255\s*,\s*([\d.]+)\s*\)"/g,
|
|
976
|
+
(_, prop, a) => `${prop}="currentColor" ${prop}-opacity="${a}"`);
|
|
977
|
+
|
|
978
|
+
// 5. it is decoration in the row — the link around it carries the name
|
|
964
979
|
s = s.replace(/\srole="img"/, "").replace(/\saria-label="[^"]*"/, "");
|
|
965
980
|
if (!/aria-hidden/.test(s)) s = s.replace(/<svg /, '<svg aria-hidden="true" ');
|
|
966
981
|
if (o.class) s = s.replace(/<svg /, `<svg class="${o.class}" `);
|
|
@@ -987,3 +1002,66 @@ export function toolbarMark(iconSvg, options) {
|
|
|
987
1002
|
}
|
|
988
1003
|
return s.trim();
|
|
989
1004
|
}
|
|
1005
|
+
|
|
1006
|
+
// queries: the child persona shows the parent's icon with a background · navParent has a ground ·
|
|
1007
|
+
// a child cannot know the parent's fills · adopt the host's mark · adoptMark ·
|
|
1008
|
+
// the parent icon in the child toolbar is small · derive a mark I only have a URL for
|
|
1009
|
+
//
|
|
1010
|
+
// THE SAME RULE, FOR THE ONE CASE THAT CANNOT BE BUILT — a child persona holds a URL, not a drawing.
|
|
1011
|
+
//
|
|
1012
|
+
// `toolbarMark` above runs at BUILD time on a file the persona imports, and takes `fills` as data
|
|
1013
|
+
// because a persona knows its own drawing. A child persona knows neither: `/me`, `/files` and the
|
|
1014
|
+
// feed are built once and mounted on every host in the fleet, so the mark in their row belongs to
|
|
1015
|
+
// whichever persona they happen to be inside. It arrives as `<img src="/icon.svg">` — the tile, the
|
|
1016
|
+
// ground, the one background in a line of inks — and there is no build step at which it is known.
|
|
1017
|
+
//
|
|
1018
|
+
// So it is fetched and derived in the browser instead, through the SAME function, and then the thing
|
|
1019
|
+
// that could not be passed in is MEASURED: `getBBox()` reports the ink's extent in viewBox units,
|
|
1020
|
+
// which is `fills` — read off the drawing rather than told to us. That is the better half of this:
|
|
1021
|
+
// it needs no registry field, no per-parent table, and a persona that redraws its icon tomorrow gets
|
|
1022
|
+
// the right box the same afternoon, with nothing to bump.
|
|
1023
|
+
//
|
|
1024
|
+
// IT DEGRADES TO THE TILE. Every failure — offline, a 404 that answers with HTML, a hidden row where
|
|
1025
|
+
// `getBBox` throws — leaves the `<img>` standing, which is today's appearance and legible. The image
|
|
1026
|
+
// is removed only once the derived mark is in the document.
|
|
1027
|
+
export async function adoptMark(options) {
|
|
1028
|
+
const o = options || {};
|
|
1029
|
+
if (typeof document === "undefined") return null;
|
|
1030
|
+
const el = o.el || document.getElementById(o.id || "navParent");
|
|
1031
|
+
if (!el) return null;
|
|
1032
|
+
const img = el.querySelector("img");
|
|
1033
|
+
const url = o.url || (img && img.getAttribute("src")) || "/icon.svg";
|
|
1034
|
+
|
|
1035
|
+
let src = "";
|
|
1036
|
+
try {
|
|
1037
|
+
const r = await fetch(url);
|
|
1038
|
+
if (!r.ok) return null;
|
|
1039
|
+
src = await r.text();
|
|
1040
|
+
} catch { return null; }
|
|
1041
|
+
// A missing file that answers with the persona's 404 PAGE is still a 200 in some setups, and
|
|
1042
|
+
// injecting that would put a document where a glyph goes.
|
|
1043
|
+
if (!/<svg[\s>]/.test(src)) return null;
|
|
1044
|
+
|
|
1045
|
+
const html = toolbarMark(src, { id: o.ns || "adopted", class: o.class });
|
|
1046
|
+
if (!html) return null;
|
|
1047
|
+
el.insertAdjacentHTML("afterbegin", html);
|
|
1048
|
+
const svg = el.querySelector("svg");
|
|
1049
|
+
if (!svg) return null;
|
|
1050
|
+
if (img) img.remove();
|
|
1051
|
+
|
|
1052
|
+
// the measurement `fills` would have carried, taken from the drawing itself
|
|
1053
|
+
let box = 20;
|
|
1054
|
+
try {
|
|
1055
|
+
const vb = (svg.getAttribute("viewBox") || "").split(/[\s,]+/).map(Number);
|
|
1056
|
+
const bb = svg.getBBox();
|
|
1057
|
+
if (vb.length === 4 && vb[2] > 0 && vb[3] > 0 && bb.width > 0) {
|
|
1058
|
+
const fills = Math.max(bb.width / vb[2], bb.height / vb[3]);
|
|
1059
|
+
// a sane band: a drawing filling under a twentieth of its box is a parse we do not trust, and
|
|
1060
|
+
// one filling it whole needs no help.
|
|
1061
|
+
if (fills > 0.05 && fills < 1) box = 20 / fills;
|
|
1062
|
+
}
|
|
1063
|
+
} catch { /* not rendered — the row's default stands */ }
|
|
1064
|
+
svg.style.width = box.toFixed(2) + "px";
|
|
1065
|
+
svg.style.height = box.toFixed(2) + "px";
|
|
1066
|
+
return svg;
|
|
1067
|
+
}
|