@justai/core 0.12.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 +1 -1
- package/src/index.d.ts +17 -0
- package/src/index.js +65 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@justai/core",
|
|
3
|
-
"version": "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
|
@@ -901,3 +901,68 @@ export async function childFace(options) {
|
|
|
901
901
|
}
|
|
902
902
|
return face;
|
|
903
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
|
+
}
|