@justai/core 0.42.0 → 0.43.1

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/dist/analytics.js CHANGED
@@ -128,6 +128,8 @@ export function measurementIdFor(host) {
128
128
  * shared shell does not put anything in the global scope it did not mean to. `window.gtag` is still
129
129
  * assigned explicitly on window, which is the one thing that MUST escape.
130
130
  */
131
+ // THE STORED ANSWER is the apex's (2026-10-14, see ./consent): the `justai-consent` cookie on the
132
+ // registrable domain first, this origin's localStorage only as the pre-apex fallback.
131
133
  export function analyticsJs(gaId) {
132
134
  return `(function(){
133
135
  window.gtag=window.gtag||function(){(window.dataLayer=window.dataLayer||[]).push(arguments)};
@@ -140,7 +142,7 @@ window.gtag=window.gtag||function(){window.dataLayer.push(arguments)};
140
142
  gtag("js",new Date());
141
143
  gtag("consent","default",{ad_storage:"granted",ad_user_data:"granted",ad_personalization:"denied",analytics_storage:"granted"});
142
144
  gtag("consent","default",{region:["AT","BE","BG","HR","CY","CZ","DK","EE","FI","FR","DE","GR","HU","IE","IT","LV","LT","LU","MT","NL","PL","PT","RO","SK","SI","ES","SE","IS","LI","NO","GB","CH"],ad_storage:"denied",ad_user_data:"denied",ad_personalization:"denied",analytics_storage:"denied"});
143
- try{var __c=localStorage.getItem("consent");
145
+ try{var __m=document.cookie.match(/(?:^|; )justai-consent=([^;]*)/),__c=__m?decodeURIComponent(__m[1]):localStorage.getItem("consent");
144
146
  if(__c==="granted+ads")gtag("consent","update",{analytics_storage:"granted",ad_storage:"granted",ad_user_data:"granted"});
145
147
  else if(__c==="granted")gtag("consent","update",{analytics_storage:"granted"});
146
148
  else if(__c==="denied")gtag("consent","update",{analytics_storage:"denied",ad_storage:"denied",ad_user_data:"denied"})}catch(e){}
package/dist/consent.d.ts CHANGED
@@ -73,9 +73,29 @@ export declare function consentCopy(lang: string | null | undefined): ConsentStr
73
73
  *
74
74
  * The consent dialog's behaviour — one copy, for every surface on a persona's origin.
75
75
  *
76
- * CONSENT IS SCOPED TO THE ORIGIN, NOT TO A PAGE. Whichever page a visitor enters by, if this origin
77
- * has never asked, it asks — once. That is what a consent flow IS, and it is worth stating because
78
- * ours was accidentally page-scoped for three weeks: the script used to bail on
76
+ * CONSENT IS SCOPED TO THE APEX — every persona under app.zone, pin.games, justai.pro, cityinmotion.nl
77
+ * answers to one question (2026-10-14). It was scoped to the ORIGIN, on purpose: each persona honest
78
+ * with its own visitor, so somebody arriving from search straight at qr was asked by qr. The founder,
79
+ * from what visitors told him: *"app.zone'a giriyorum, count me. app.zone'daki bir app'e giriyorum,
80
+ * count me… kullanıcıya gına geliyor"* — by the third or fourth persona people answer "stay invisible"
81
+ * to make the asking stop, which is the question working against itself. So: an answer given on ANY
82
+ * persona of an apex — either answer — is that apex's answer, and no sibling asks again. Nobody on the
83
+ * apex has answered yet? The first persona visited asks, and its answer becomes everyone's. Another
84
+ * apex is another household and asks for itself.
85
+ *
86
+ * HOW: a cookie on the registrable domain (`justai-consent`, Domain=<apex>), because localStorage is
87
+ * per origin and every subdomain is its own origin — that is the whole reason each one asked. It
88
+ * lives 13 months (foundations/15: a label must not outlive what it labels; the choice is re-asked
89
+ * once a year, the usual ceiling for a stored consent in Europe). `localStorage["consent"]` is still
90
+ * written, for shells on older cores, and an answer found only there is PROMOTED to the apex cookie on
91
+ * the next visit — so everybody who answered any persona before this change is not asked by its
92
+ * siblings after it. The "not now" (Escape) flag is an apex SESSION cookie for the same reason: one
93
+ * dodge keeps the whole apex quiet for this visit, not just one persona. /me's erase must expire the
94
+ * cookie on every plausible domain (it cannot read the Domain attribute back).
95
+ *
96
+ * Whichever page a visitor enters by, if the apex has never been answered, it asks — once. That is
97
+ * what a consent flow IS, and it is worth stating because ours was accidentally page-scoped for three
98
+ * weeks: the script used to bail on
79
99
  * `!document.getElementById("kernel")`, a DOM sniff added to avoid asking on a 404. Feed pages have
80
100
  * no kernel either, so on every /feed/* page in the fleet the question was never asked — silently,
81
101
  * with nothing to notice it. A trust decision must never be inferred from an unrelated layout
@@ -102,4 +122,4 @@ export declare function consentCopy(lang: string | null | undefined): ConsentStr
102
122
  * the sheet ships no attribute, and the opener places focus by the genre's law: the ask genre puts
103
123
  * it on the invitation (here), the destructive genre on the cancel (that consumer's own open).
104
124
  */
105
- export declare const CONSENT_JS = "(function(){try{\nvar h=location.hostname;\nif(h===\"localhost\"||h===\"127.0.0.1\"||h===\"::1\"||h===\"[::1]\"||h.indexOf(\"dev-\")===0)return;\nvar el=document.getElementById(\"consent\");if(!el||!el.showModal)return;\nvar open=function(){if(!el.open){el.returnValue=\"\";el.showModal();var p=el.querySelector(\".preferred\");if(p)p.focus()}};\nel.addEventListener(\"close\",function(){\nvar rv=el.returnValue;\nvar v=rv===\"confirm\"?\"granted+ads\":rv===\"denied\"?\"denied\":null;\nif(v){var g=v===\"denied\"?\"denied\":\"granted\";\ngtag(\"consent\",\"update\",{analytics_storage:g,ad_storage:g,ad_user_data:g});\ntry{localStorage.setItem(\"consent\",v)}catch(_){}}\nelse{try{sessionStorage.setItem(\"consent-later\",\"1\")}catch(_){}}\n});\nvar doors=document.querySelectorAll(\"[data-consent-open]\");\nfor(var i=0;i<doors.length;i++){var a=doors[i];\nif(!a.textContent)a.textContent=el.getAttribute(\"data-choice-label\")||\"privacy choice\";\na.hidden=false;var w=a.closest(\"[data-consent-door]\");if(w)w.hidden=false;\na.addEventListener(\"click\",function(ev){ev.preventDefault();open()})}\nif(localStorage.getItem(\"consent\"))return;\ntry{if(sessionStorage.getItem(\"consent-later\"))return}catch(_){}\nvar tz=Intl.DateTimeFormat().resolvedOptions().timeZone||\"\";\nvar asked=tz.indexOf(\"Europe/\")===0||[\n\"Asia/Nicosia\",\"Asia/Famagusta\",\n\"Atlantic/Canary\",\"Atlantic/Azores\",\"Atlantic/Madeira\",\"Atlantic/Reykjavik\",\n\"Arctic/Longyearbyen\",\n\"America/Guadeloupe\",\"America/Martinique\",\"America/Cayenne\",\n\"Indian/Reunion\",\"Indian/Mayotte\"].indexOf(tz)>=0;\nif(!asked)return;\nsetTimeout(open,700);\n}catch(_){}})();";
125
+ export declare const CONSENT_JS = "(function(){try{\nvar h=location.hostname;\nif(h===\"localhost\"||h===\"127.0.0.1\"||h===\"::1\"||h===\"[::1]\"||h.indexOf(\"dev-\")===0)return;\nvar el=document.getElementById(\"consent\");if(!el||!el.showModal)return;\nvar hp=h.split(\".\"),ap=(hp.length>2&&!/^[0-9.]+$/.test(h))?hp.slice(-2).join(\".\"):h;\nvar AGE=34128000;\nvar rd=function(n){var m=document.cookie.match(new RegExp(\"(?:^|; )\"+n+\"=([^;]*)\"));return m?decodeURIComponent(m[1]):null};\nvar wr=function(n,v,age){document.cookie=n+\"=\"+encodeURIComponent(v)+\"; Domain=\"+ap+\"; Path=/\"+(age?\"; Max-Age=\"+age:\"\")+\"; SameSite=Lax; Secure\"};\nvar stored=function(){var c=rd(\"justai-consent\");if(c)return c;var l=null;try{l=localStorage.getItem(\"consent\")}catch(_){}if(l)wr(\"justai-consent\",l,AGE);return l};\nvar open=function(){if(!el.open){el.returnValue=\"\";el.showModal();var p=el.querySelector(\".preferred\");if(p)p.focus()}};\nel.addEventListener(\"close\",function(){\nvar rv=el.returnValue;\nvar v=rv===\"confirm\"?\"granted+ads\":rv===\"denied\"?\"denied\":null;\nif(v){var g=v===\"denied\"?\"denied\":\"granted\";\ngtag(\"consent\",\"update\",{analytics_storage:g,ad_storage:g,ad_user_data:g});\ntry{localStorage.setItem(\"consent\",v)}catch(_){}\nwr(\"justai-consent\",v,AGE)}\nelse{wr(\"justai-consent-later\",\"1\",0);try{sessionStorage.setItem(\"consent-later\",\"1\")}catch(_){}}\n});\nvar doors=document.querySelectorAll(\"[data-consent-open]\");\nfor(var i=0;i<doors.length;i++){var a=doors[i];\nif(!a.textContent)a.textContent=el.getAttribute(\"data-choice-label\")||\"privacy choice\";\na.hidden=false;var w=a.closest(\"[data-consent-door]\");if(w)w.hidden=false;\na.addEventListener(\"click\",function(ev){ev.preventDefault();open()})}\nif(stored())return;\nif(rd(\"justai-consent-later\"))return;\ntry{if(sessionStorage.getItem(\"consent-later\"))return}catch(_){}\nvar tz=Intl.DateTimeFormat().resolvedOptions().timeZone||\"\";\nvar asked=tz.indexOf(\"Europe/\")===0||[\n\"Asia/Nicosia\",\"Asia/Famagusta\",\n\"Atlantic/Canary\",\"Atlantic/Azores\",\"Atlantic/Madeira\",\"Atlantic/Reykjavik\",\n\"Arctic/Longyearbyen\",\n\"America/Guadeloupe\",\"America/Martinique\",\"America/Cayenne\",\n\"Indian/Reunion\",\"Indian/Mayotte\"].indexOf(tz)>=0;\nif(!asked)return;\nsetTimeout(open,700);\n}catch(_){}})();";
package/dist/consent.js CHANGED
@@ -95,9 +95,29 @@ export function consentCopy(lang) {
95
95
  *
96
96
  * The consent dialog's behaviour — one copy, for every surface on a persona's origin.
97
97
  *
98
- * CONSENT IS SCOPED TO THE ORIGIN, NOT TO A PAGE. Whichever page a visitor enters by, if this origin
99
- * has never asked, it asks — once. That is what a consent flow IS, and it is worth stating because
100
- * ours was accidentally page-scoped for three weeks: the script used to bail on
98
+ * CONSENT IS SCOPED TO THE APEX — every persona under app.zone, pin.games, justai.pro, cityinmotion.nl
99
+ * answers to one question (2026-10-14). It was scoped to the ORIGIN, on purpose: each persona honest
100
+ * with its own visitor, so somebody arriving from search straight at qr was asked by qr. The founder,
101
+ * from what visitors told him: *"app.zone'a giriyorum, count me. app.zone'daki bir app'e giriyorum,
102
+ * count me… kullanıcıya gına geliyor"* — by the third or fourth persona people answer "stay invisible"
103
+ * to make the asking stop, which is the question working against itself. So: an answer given on ANY
104
+ * persona of an apex — either answer — is that apex's answer, and no sibling asks again. Nobody on the
105
+ * apex has answered yet? The first persona visited asks, and its answer becomes everyone's. Another
106
+ * apex is another household and asks for itself.
107
+ *
108
+ * HOW: a cookie on the registrable domain (`justai-consent`, Domain=<apex>), because localStorage is
109
+ * per origin and every subdomain is its own origin — that is the whole reason each one asked. It
110
+ * lives 13 months (foundations/15: a label must not outlive what it labels; the choice is re-asked
111
+ * once a year, the usual ceiling for a stored consent in Europe). `localStorage["consent"]` is still
112
+ * written, for shells on older cores, and an answer found only there is PROMOTED to the apex cookie on
113
+ * the next visit — so everybody who answered any persona before this change is not asked by its
114
+ * siblings after it. The "not now" (Escape) flag is an apex SESSION cookie for the same reason: one
115
+ * dodge keeps the whole apex quiet for this visit, not just one persona. /me's erase must expire the
116
+ * cookie on every plausible domain (it cannot read the Domain attribute back).
117
+ *
118
+ * Whichever page a visitor enters by, if the apex has never been answered, it asks — once. That is
119
+ * what a consent flow IS, and it is worth stating because ours was accidentally page-scoped for three
120
+ * weeks: the script used to bail on
101
121
  * `!document.getElementById("kernel")`, a DOM sniff added to avoid asking on a 404. Feed pages have
102
122
  * no kernel either, so on every /feed/* page in the fleet the question was never asked — silently,
103
123
  * with nothing to notice it. A trust decision must never be inferred from an unrelated layout
@@ -128,21 +148,28 @@ export const CONSENT_JS = `(function(){try{
128
148
  var h=location.hostname;
129
149
  if(h==="localhost"||h==="127.0.0.1"||h==="::1"||h==="[::1]"||h.indexOf("dev-")===0)return;
130
150
  var el=document.getElementById("consent");if(!el||!el.showModal)return;
151
+ var hp=h.split("."),ap=(hp.length>2&&!/^[0-9.]+$/.test(h))?hp.slice(-2).join("."):h;
152
+ var AGE=34128000;
153
+ var rd=function(n){var m=document.cookie.match(new RegExp("(?:^|; )"+n+"=([^;]*)"));return m?decodeURIComponent(m[1]):null};
154
+ var wr=function(n,v,age){document.cookie=n+"="+encodeURIComponent(v)+"; Domain="+ap+"; Path=/"+(age?"; Max-Age="+age:"")+"; SameSite=Lax; Secure"};
155
+ var stored=function(){var c=rd("justai-consent");if(c)return c;var l=null;try{l=localStorage.getItem("consent")}catch(_){}if(l)wr("justai-consent",l,AGE);return l};
131
156
  var open=function(){if(!el.open){el.returnValue="";el.showModal();var p=el.querySelector(".preferred");if(p)p.focus()}};
132
157
  el.addEventListener("close",function(){
133
158
  var rv=el.returnValue;
134
159
  var v=rv==="confirm"?"granted+ads":rv==="denied"?"denied":null;
135
160
  if(v){var g=v==="denied"?"denied":"granted";
136
161
  gtag("consent","update",{analytics_storage:g,ad_storage:g,ad_user_data:g});
137
- try{localStorage.setItem("consent",v)}catch(_){}}
138
- else{try{sessionStorage.setItem("consent-later","1")}catch(_){}}
162
+ try{localStorage.setItem("consent",v)}catch(_){}
163
+ wr("justai-consent",v,AGE)}
164
+ else{wr("justai-consent-later","1",0);try{sessionStorage.setItem("consent-later","1")}catch(_){}}
139
165
  });
140
166
  var doors=document.querySelectorAll("[data-consent-open]");
141
167
  for(var i=0;i<doors.length;i++){var a=doors[i];
142
168
  if(!a.textContent)a.textContent=el.getAttribute("data-choice-label")||"privacy choice";
143
169
  a.hidden=false;var w=a.closest("[data-consent-door]");if(w)w.hidden=false;
144
170
  a.addEventListener("click",function(ev){ev.preventDefault();open()})}
145
- if(localStorage.getItem("consent"))return;
171
+ if(stored())return;
172
+ if(rd("justai-consent-later"))return;
146
173
  try{if(sessionStorage.getItem("consent-later"))return}catch(_){}
147
174
  var tz=Intl.DateTimeFormat().resolvedOptions().timeZone||"";
148
175
  var asked=tz.indexOf("Europe/")===0||[
package/dist/index.d.ts CHANGED
@@ -33,6 +33,12 @@
33
33
  * ./scroll landing on the kernel, and the spy
34
34
  * ./mark the persona's mark, and adopting a host's
35
35
  * ./face a host persona's face, for a child mounted on it
36
+ * ./random a fair random integer, pick, sample and shuffle — crypto.getRandomValues only
37
+ * ./list one item per line: trim, NFC, limits, duplicates reported (never removed)
38
+ *
39
+ * The last two have NO line in the barrel below, on purpose: they are not shell behaviour, and their
40
+ * generic names (`parse`, `pick`, `sample`) would crowd the namespace every persona imports. They are
41
+ * reached only through their own doors — `@justai/core/random`, `@justai/core/list`.
36
42
  *
37
43
  * The test that decided the boundaries, borrowed from `@justai/screen` — the framework's first
38
44
  * package written modular from its first line: **none of them knows what the others are for.** When
package/dist/index.js CHANGED
@@ -33,6 +33,12 @@
33
33
  * ./scroll landing on the kernel, and the spy
34
34
  * ./mark the persona's mark, and adopting a host's
35
35
  * ./face a host persona's face, for a child mounted on it
36
+ * ./random a fair random integer, pick, sample and shuffle — crypto.getRandomValues only
37
+ * ./list one item per line: trim, NFC, limits, duplicates reported (never removed)
38
+ *
39
+ * The last two have NO line in the barrel below, on purpose: they are not shell behaviour, and their
40
+ * generic names (`parse`, `pick`, `sample`) would crowd the namespace every persona imports. They are
41
+ * reached only through their own doors — `@justai/core/random`, `@justai/core/list`.
36
42
  *
37
43
  * The test that decided the boundaries, borrowed from `@justai/screen` — the framework's first
38
44
  * package written modular from its first line: **none of them knows what the others are for.** When
package/dist/list.d.ts ADDED
@@ -0,0 +1,36 @@
1
+ export declare const MAX_ITEMS = 1000;
2
+ export declare const MAX_GRAPHEMES = 120;
3
+ export interface Entry {
4
+ /** What is shown: trimmed, NFC, at most `maxGraphemes` graphemes. */
5
+ text: string;
6
+ /** The comparison key for duplicates: NFC and lower-cased. */
7
+ key: string;
8
+ }
9
+ export interface Duplicate {
10
+ text: string;
11
+ count: number;
12
+ }
13
+ export interface Parsed {
14
+ entries: Entry[];
15
+ /** Non-empty lines past `maxItems`, left out. */
16
+ overflow: number;
17
+ /** Lines cut down to `maxGraphemes`. */
18
+ shortened: number;
19
+ /** Every value that appears more than once, in first-seen order. Nothing is removed. */
20
+ duplicates: Duplicate[];
21
+ /** A single line holding two or more commas: offer to split it. */
22
+ commaHint: boolean;
23
+ }
24
+ export interface ParseOptions {
25
+ /** How many entries are kept (default 1000). */
26
+ maxItems?: number;
27
+ /** How many graphemes one entry may hold (default 120). */
28
+ maxGraphemes?: number;
29
+ }
30
+ /** How many characters a person sees. */
31
+ export declare const graphemeLength: (s: string) => number;
32
+ export declare function parse(raw: string, options?: ParseOptions): Parsed;
33
+ /** The same text with every duplicate after its first appearance removed. Blank lines go too. */
34
+ export declare function keepOneEach(raw: string): string;
35
+ /** One entry per comma-separated part, for when the person said yes to "Split by commas?". */
36
+ export declare function splitByCommas(raw: string): string;
package/dist/list.js ADDED
@@ -0,0 +1,97 @@
1
+ // THE LIST — what a person typed, turned into entries. No DOM, no product meaning. `@justai/core/list`.
2
+ //
3
+ // queries: core list · one item per line · parse a textarea · trim · NFC · blank lines · duplicates ·
4
+ // keep one each · split by commas · Smith, John · 1000 items · 120 characters · grapheme ·
5
+ // emoji length · maxItems · maxGraphemes
6
+ //
7
+ // Lifted from Name Picker (name-picker/src/lib/list.ts, production since 2026-10-22) when Team Generator
8
+ // became its second consumer. The parsing is the same; two things changed, both on purpose:
9
+ //
10
+ // · the limits are OPTIONS (`maxItems`, `maxGraphemes`) with Name Picker's values as defaults, and
11
+ // · the module no longer says what a duplicate MEANS.
12
+ //
13
+ // ── A DUPLICATE IS A FACT HERE, AND A MEANING ONLY IN A PRODUCT ─────────────────────────────────
14
+ //
15
+ // This file reports that the same normalised line appears more than once — trim, NFC, case-insensitive
16
+ // — and how many times, in first-seen order. It never removes one. What that means is the product's
17
+ // sentence: in a raffle (Name Picker) two lines are two tickets; in Team Generator they are two people
18
+ // who share a name. Neither sentence belongs at this layer, and `keepOneEach` runs only when the person
19
+ // asks for it.
20
+ //
21
+ // ── EACH LINE IS ONE ENTRY ─────────────────────────────────────────────────────────────────────
22
+ //
23
+ // A line is trimmed, normalised to NFC (so "é" typed two ways is one value) and kept if anything is
24
+ // left. Commas are never a separator by themselves — "Smith, John" is one person — so a single line
25
+ // holding two or more commas only raises `commaHint`, and `splitByCommas` breaks it up when asked.
26
+ //
27
+ // ── LIMITS ARE SAID OUT LOUD ─────────────────────────────────────────────────────────────────────
28
+ //
29
+ // Past `maxItems` entries the rest are counted in `overflow`, not silently dropped; a line longer than
30
+ // `maxGraphemes` is cut and counted in `shortened`. Length is in GRAPHEMES — what a person sees as one
31
+ // character — so a family emoji is one, not seven.
32
+ export const MAX_ITEMS = 1000;
33
+ export const MAX_GRAPHEMES = 120;
34
+ /** Commas a person might type between items: Latin, Arabic, fullwidth and ideographic. */
35
+ const COMMAS = /[,،,、]/;
36
+ let segmenter = null;
37
+ const graphemes = (s) => {
38
+ segmenter ??= new Intl.Segmenter(undefined, { granularity: "grapheme" });
39
+ return Array.from(segmenter.segment(s), (g) => g.segment);
40
+ };
41
+ /** How many characters a person sees. */
42
+ export const graphemeLength = (s) => graphemes(s).length;
43
+ const clean = (line) => line.trim().normalize("NFC");
44
+ const keyOf = (text) => text.toLowerCase().normalize("NFC");
45
+ export function parse(raw, options = {}) {
46
+ const maxItems = options.maxItems ?? MAX_ITEMS;
47
+ const maxGraphemes = options.maxGraphemes ?? MAX_GRAPHEMES;
48
+ const entries = [];
49
+ let overflow = 0;
50
+ let shortened = 0;
51
+ for (const line of raw.split(/\r\n|\r|\n/)) {
52
+ let text = clean(line);
53
+ if (!text)
54
+ continue;
55
+ if (entries.length >= maxItems) {
56
+ overflow++;
57
+ continue;
58
+ }
59
+ const g = graphemes(text);
60
+ if (g.length > maxGraphemes) {
61
+ text = g.slice(0, maxGraphemes).join("").trim();
62
+ shortened++;
63
+ }
64
+ entries.push({ text, key: keyOf(text) });
65
+ }
66
+ const counts = new Map();
67
+ for (const e of entries) {
68
+ const d = counts.get(e.key);
69
+ if (d)
70
+ d.count++;
71
+ else
72
+ counts.set(e.key, { text: e.text, count: 1 });
73
+ }
74
+ const duplicates = [...counts.values()].filter((d) => d.count > 1);
75
+ const commaHint = entries.length === 1 && entries[0].text.split(COMMAS).length >= 3;
76
+ return { entries, overflow, shortened, duplicates, commaHint };
77
+ }
78
+ /** The same text with every duplicate after its first appearance removed. Blank lines go too. */
79
+ export function keepOneEach(raw) {
80
+ const seen = new Set();
81
+ const out = [];
82
+ for (const line of raw.split(/\r\n|\r|\n/)) {
83
+ const text = clean(line);
84
+ if (!text)
85
+ continue;
86
+ const k = keyOf(text);
87
+ if (seen.has(k))
88
+ continue;
89
+ seen.add(k);
90
+ out.push(text);
91
+ }
92
+ return out.join("\n");
93
+ }
94
+ /** One entry per comma-separated part, for when the person said yes to "Split by commas?". */
95
+ export function splitByCommas(raw) {
96
+ return raw.split(/\r\n|\r|\n/).flatMap((l) => l.split(COMMAS)).map(clean).filter(Boolean).join("\n");
97
+ }
@@ -0,0 +1,14 @@
1
+ /** Fills the array with uniformly random 32-bit values. The default is `crypto.getRandomValues`. */
2
+ export type RandomSource = (buf: Uint32Array<ArrayBuffer>) => Uint32Array<ArrayBuffer>;
3
+ export declare const cryptoSource: RandomSource;
4
+ /** A uniformly random integer in [0, max). Throws for a max that is not a whole number in [1, 2³²]. */
5
+ export declare function randInt(max: number, source?: RandomSource): number;
6
+ /** One element, every element equally likely. Throws on an empty list rather than returning undefined. */
7
+ export declare function pick<T>(items: readonly T[], source?: RandomSource): T;
8
+ /**
9
+ * `k` distinct elements, in the order they were drawn — a partial Fisher–Yates on a copy.
10
+ * Every k-subset is equally likely, and so is every order of it. The input is never touched.
11
+ */
12
+ export declare function sample<T>(items: readonly T[], k: number, source?: RandomSource): T[];
13
+ /** A new array holding the same elements in a uniformly random order (full Fisher–Yates). */
14
+ export declare function shuffle<T>(items: readonly T[], source?: RandomSource): T[];
package/dist/random.js ADDED
@@ -0,0 +1,72 @@
1
+ // THE RANDOMNESS — one source, four verbs, no DOM. `@justai/core/random`.
2
+ //
3
+ // queries: core random · randInt · pick · sample · shuffle · Fisher–Yates · rejection sampling ·
4
+ // modulo bias · Math.random · crypto.getRandomValues · fair pick · injected source for tests
5
+ //
6
+ // Lifted UNCHANGED from Name Picker (name-picker/src/lib/random.ts, production since 2026-10-22) when
7
+ // Team Generator became its second new consumer — the doctrine's "a layer is proven by its second
8
+ // consumer; move it before it is copied". The bodies below are byte-for-byte the ones that shipped.
9
+ //
10
+ // ── ONE SOURCE, AND IT IS THE BROWSER'S CRYPTOGRAPHIC GENERATOR ──────────────────────────────────
11
+ //
12
+ // Every random choice goes through `randInt`. There is no Math.random here, and a persona that says
13
+ // "picked with your browser's cryptographic random generator" must route ALL of its randomness —
14
+ // decoration included — through this module, or the sentence is only true of some of the page.
15
+ //
16
+ // ── NO MODULO BIAS ────────────────────────────────────────────────────────────────────────────
17
+ //
18
+ // A 32-bit value `% n` favours the low remainders whenever 2³² is not a multiple of n. So the values
19
+ // in the incomplete last block are thrown away and drawn again: `limit` is the largest multiple of
20
+ // n that fits, and anything at or above it is rejected. At most one draw in two is ever rejected
21
+ // (n just over 2³¹); for a list of 1,000 items it is about one in four million.
22
+ //
23
+ // ── NO DOM, NO FRAMEWORK, NO NODE ─────────────────────────────────────────────────────────────
24
+ //
25
+ // `crypto.getRandomValues` exists in every browser and in Node/Bun as a global; nothing else is
26
+ // touched. The source is injectable (`RandomSource`), so a test can drive any function with a fixed
27
+ // sequence and check the rejection path and every boundary without statistics.
28
+ export const cryptoSource = (buf) => crypto.getRandomValues(buf);
29
+ const RANGE = 0x1_0000_0000; // 2³²
30
+ /** A uniformly random integer in [0, max). Throws for a max that is not a whole number in [1, 2³²]. */
31
+ export function randInt(max, source = cryptoSource) {
32
+ if (!Number.isInteger(max) || max < 1 || max > RANGE) {
33
+ throw new RangeError(`randInt: max must be an integer in [1, 2^32], got ${max}`);
34
+ }
35
+ if (max === 1)
36
+ return 0;
37
+ const limit = RANGE - (RANGE % max); // the largest multiple of max that fits in 32 bits
38
+ const buf = new Uint32Array(1);
39
+ for (;;) {
40
+ const x = source(buf)[0];
41
+ if (x < limit)
42
+ return x % max;
43
+ }
44
+ }
45
+ /** One element, every element equally likely. Throws on an empty list rather than returning undefined. */
46
+ export function pick(items, source = cryptoSource) {
47
+ if (items.length === 0)
48
+ throw new RangeError("pick: empty list");
49
+ return items[randInt(items.length, source)];
50
+ }
51
+ /**
52
+ * `k` distinct elements, in the order they were drawn — a partial Fisher–Yates on a copy.
53
+ * Every k-subset is equally likely, and so is every order of it. The input is never touched.
54
+ */
55
+ export function sample(items, k, source = cryptoSource) {
56
+ const n = items.length;
57
+ if (!Number.isInteger(k) || k < 0 || k > n) {
58
+ throw new RangeError(`sample: k must be an integer in [0, ${n}], got ${k}`);
59
+ }
60
+ const a = items.slice();
61
+ for (let i = 0; i < k; i++) {
62
+ const j = i + randInt(n - i, source);
63
+ const tmp = a[i];
64
+ a[i] = a[j];
65
+ a[j] = tmp;
66
+ }
67
+ return a.slice(0, k);
68
+ }
69
+ /** A new array holding the same elements in a uniformly random order (full Fisher–Yates). */
70
+ export function shuffle(items, source = cryptoSource) {
71
+ return sample(items, items.length, source);
72
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@justai/core",
3
- "version": "0.42.0",
3
+ "version": "0.43.1",
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": {
@@ -52,6 +52,14 @@
52
52
  "./face": {
53
53
  "types": "./dist/face.d.ts",
54
54
  "default": "./dist/face.js"
55
+ },
56
+ "./random": {
57
+ "types": "./dist/random.d.ts",
58
+ "default": "./dist/random.js"
59
+ },
60
+ "./list": {
61
+ "types": "./dist/list.d.ts",
62
+ "default": "./dist/list.js"
55
63
  }
56
64
  },
57
65
  "publishConfig": {