@justai/core 0.12.0 → 0.14.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 +28 -0
- package/src/index.js +86 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@justai/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.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,31 @@ 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?: {
|
|
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
|
+
},
|
|
140
|
+
): string;
|
package/src/index.js
CHANGED
|
@@ -901,3 +901,89 @@ 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
|
+
|
|
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
|
+
}
|
|
988
|
+
return s.trim();
|
|
989
|
+
}
|