@justai/core 0.11.0 → 0.13.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.11.0",
3
+ "version": "0.13.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
@@ -110,3 +110,20 @@ export declare function childFace(options?: {
110
110
  /** Defaults to `https://api.justai.pro`. */
111
111
  api?: string;
112
112
  }): Promise<ChildFace | null>;
113
+
114
+ /**
115
+ * Derive a toolbar mark from a persona's `icon.svg` — the SAME file, not a second drawing.
116
+ *
117
+ * An `icon.svg` is a TILE: a squircle ground with the mark on it. In a row of icons that ground is
118
+ * the only object with a background. This removes it, namespaces every id so the avatar and the row
119
+ * can coexist on one page, and drops the authoring comment and the accessible name (the link around
120
+ * it carries that).
121
+ *
122
+ * It does not recolour: whether the row's mark takes `currentColor` is the persona's decision.
123
+ *
124
+ * @param iconSvg the file's contents — `import iconSvg from "../../public/icon.svg?raw"`
125
+ */
126
+ export declare function toolbarMark(
127
+ iconSvg: string,
128
+ options?: { id?: string; class?: string },
129
+ ): string;
package/src/index.js CHANGED
@@ -877,9 +877,92 @@ export async function childFace(options) {
877
877
  return null;
878
878
  }
879
879
  if (!face) return null;
880
- if (face.accent && typeof document !== "undefined") {
880
+ if (typeof document === "undefined") return face;
881
+ if (face.accent) {
881
882
  document.documentElement.style.setProperty("--accent", face.accent);
882
883
  if (root) root.style.setProperty("--accent", face.accent);
883
884
  }
885
+ // queries: pnName pnHandle pnMeta · the child persona shows its own name instead of the host's
886
+ //
887
+ // THE HOST'S IDENTITY, WRITTEN INTO THE SHELL'S IDS. <ChildPersona> renders name, handle and the
888
+ // small print as spans with these ids precisely so one function can fill them: the page is built
889
+ // once and mounted on every persona's host, so none of it is knowable at build time.
890
+ //
891
+ // Each write is guarded because a MISSING value must leave the server's fallback standing — the
892
+ // child's own words, which are correct when the lookup never returns. Blanking them on a failed
893
+ // fetch would turn "we could not reach the registry" into "this persona has no name".
894
+ const put = (id, text) => { const el = document.getElementById(id); if (el && text) el.textContent = text; };
895
+ put("pnName", face.name);
896
+ put("pnHandle", face.handle ? "@" + face.handle : null);
897
+ put("pnMeta", face.meta);
898
+ if (face.avatar) {
899
+ const slot = document.getElementById("hostGlyph");
900
+ if (slot) slot.innerHTML = '<img class="mk" src="' + face.avatar + '" alt="">';
901
+ }
884
902
  return face;
885
903
  }
904
+
905
+ // queries: toolbar mark · the persona icon has a background in the row · icon.svg in the toolbar ·
906
+ // a filled tile in the toolbar · derive the row's mark from the avatar · toolbarMark
907
+ //
908
+ // THE AVATAR'S MARK, MADE FIT FOR A ROW OF ICONS — from the SAME FILE, not a second drawing.
909
+ //
910
+ // A persona's `icon.svg` is a TILE: a squircle ground with the mark on it, drawn to sit in an avatar
911
+ // well or a Home Screen. Put that file in the toolbar as an `<img>` and it arrives with its ground
912
+ // intact — the only object in the row with a background, a little coloured card among four inks. It
913
+ // is exactly what the founder kept seeing and could not name: *"neden background olacak sekilde
914
+ // fill edip kullaniyorsun"*.
915
+ //
916
+ // qr had already solved it, and the shape of the solution is the reason this is here rather than in
917
+ // fifteen repos: **derive, never redraw.** Its comment says it best — *"THE SAME FILE, three edits
918
+ // deep — not a second drawing. Whatever happens to icon.svg happens here."* A clever second face is
919
+ // still a second face, and it drifts the day somebody redraws one of them.
920
+ //
921
+ // The three edits, generalised across the fleet's fourteen marks (all `viewBox="0 0 100 100"` with an
922
+ // identical `<rect width="100" height="100" rx="26" fill="#0a0d18">` ground):
923
+ //
924
+ // 1. THE GROUND GOES. In the avatar the mark is a tile ON something; in the row it is one item IN
925
+ // a line, and a filled tile there is the only thing with a background.
926
+ // 2. IDS ARE NAMESPACED. Both copies are on the same page — the avatar and the row — and two
927
+ // elements cannot share an id: a `url(#…)` silently resolves to whichever came first, so one of
928
+ // the two marks loses its gradient with nothing reported.
929
+ // 3. THE AUTHORING NOTE GOES. It is explanation aimed at whoever edits the file, and it has no
930
+ // business shipping twice on every page load.
931
+ //
932
+ // What it does NOT do is recolour. Whether the row's mark takes `currentColor` is the persona's own
933
+ // decision, made in its CSS — some marks are a silhouette and read as ink, some carry a gradient
934
+ // that IS the identity. This only removes what the row cannot use.
935
+ export function toolbarMark(iconSvg, options) {
936
+ const o = options || {};
937
+ const ns = o.id || "tb";
938
+ let s = String(iconSvg || "");
939
+ if (!s) return "";
940
+
941
+ // 1. the authoring note
942
+ s = s.replace(/<!--[\s\S]*?-->/g, "");
943
+
944
+ // 2. the ground — a rect that covers the whole viewBox, whatever its corner radius or fill.
945
+ // Matched against the viewBox rather than against "100" so a mark drawn at another size still
946
+ // loses its tile.
947
+ const vb = /viewBox="\s*0\s+0\s+([\d.]+)\s+([\d.]+)/.exec(s);
948
+ if (vb) {
949
+ const [, w, h] = vb;
950
+ const tile = new RegExp(`<rect(?=[^>]*\\bwidth="${w}")(?=[^>]*\\bheight="${h}")[^>]*/>\\s*`, "g");
951
+ s = s.replace(tile, "");
952
+ }
953
+
954
+ // 3. ids, and every reference to them. Done together so a rename cannot half-apply.
955
+ const ids = [...s.matchAll(/\bid="([^"]+)"/g)].map((m) => m[1]);
956
+ for (const id of ids) {
957
+ const safe = id.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
958
+ s = s.replace(new RegExp(`\\bid="${safe}"`, "g"), `id="${id}-${ns}"`)
959
+ .replace(new RegExp(`url\\(#${safe}\\)`, "g"), `url(#${id}-${ns})`)
960
+ .replace(new RegExp(`(href|xlink:href)="#${safe}"`, "g"), `$1="#${id}-${ns}"`);
961
+ }
962
+
963
+ // 4. it is decoration in the row — the link around it carries the name
964
+ s = s.replace(/\srole="img"/, "").replace(/\saria-label="[^"]*"/, "");
965
+ if (!/aria-hidden/.test(s)) s = s.replace(/<svg /, '<svg aria-hidden="true" ');
966
+ if (o.class) s = s.replace(/<svg /, `<svg class="${o.class}" `);
967
+ return s.trim();
968
+ }