@tjakoen/grain 0.1.28 → 0.1.30
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.
|
@@ -50,3 +50,26 @@ buttons render clean, because clicking them is the **human's** move, not AI-auth
|
|
|
50
50
|
|
|
51
51
|
Every verb here must exist in `ai/contract.ts` and walk the usual alignment row — an action button
|
|
52
52
|
in the chat is a door client like any other, so a new verb needs its reasoner branch + tests.
|
|
53
|
+
|
|
54
|
+
## Consent notice (the desk asks before it stores anything)
|
|
55
|
+
|
|
56
|
+
A consent question is not an AI offer, so it carries no `data-action`: the app owns the policy and
|
|
57
|
+
the endpoint. It is still an AI message (`data-role="ai"`, grain), because the desk asks it, and its
|
|
58
|
+
buttons stay clean because choosing is the human's move. Use the actions row with
|
|
59
|
+
`data-consent="allow|deny"`, name what is stored and for how long, and make the decline real.
|
|
60
|
+
|
|
61
|
+
```html
|
|
62
|
+
<div class="chat-message" data-role="ai" data-grade="grain" data-consent-notice>
|
|
63
|
+
<span class="chat-message__who">GRAIN</span>
|
|
64
|
+
<span class="chat-message__body">May the desk remember this conversation on this device with a cookie? It stores a session id for 30 days. Not now loses only the remembering.</span>
|
|
65
|
+
<div class="chat-message__actions">
|
|
66
|
+
<button class="btn" data-variant="soft" data-consent="allow" type="button">Remember this chat</button>
|
|
67
|
+
<button class="btn" data-variant="outline" data-consent="deny" type="button">Not now</button>
|
|
68
|
+
</div>
|
|
69
|
+
</div>
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
The app sets the server-issued id on `data-desk-session` (see `scripts/ai-dispatch.js`) or as
|
|
73
|
+
`window.__DESK_SESSION__` before the dispatcher runs, handles the two buttons, sets the cookie only
|
|
74
|
+
on allow, and dismisses the notice after either choice. A static site with no consent endpoint
|
|
75
|
+
simply never renders the notice.
|
|
@@ -20,6 +20,19 @@ function cssFiles(dir: string, out: string[] = []): string[] {
|
|
|
20
20
|
const HEX = /#[0-9a-fA-F]{3,8}\b/g;
|
|
21
21
|
const FUNC = /\b(rgb|rgba|hsl|hsla)\(/;
|
|
22
22
|
|
|
23
|
+
test("the dense type steps sit below the caption step, in order", () => {
|
|
24
|
+
const css = readFileSync(join(import.meta.dir, "../styles/variables.css"), "utf8");
|
|
25
|
+
const rem = (name: string) => {
|
|
26
|
+
const m = css.match(new RegExp(`--${name}:\\s*([\\d.]+)rem`));
|
|
27
|
+
return m ? Number(m[1]) : Number.NaN;
|
|
28
|
+
};
|
|
29
|
+
expect(rem("text-3xs")).toBe(0.625);
|
|
30
|
+
expect(rem("text-2xs")).toBe(0.6875);
|
|
31
|
+
expect(rem("text-xs")).toBe(0.8125);
|
|
32
|
+
expect(rem("text-3xs")).toBeLessThan(rem("text-2xs"));
|
|
33
|
+
expect(rem("text-2xs")).toBeLessThan(rem("text-xs"));
|
|
34
|
+
});
|
|
35
|
+
|
|
23
36
|
test("no component stylesheet hardcodes a color (tokens only, ever)", () => {
|
|
24
37
|
const offenders: string[] = [];
|
|
25
38
|
for (const f of cssFiles(import.meta.dir)) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tjakoen/grain",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.30",
|
|
4
4
|
"description": "GRAIN — an AI-interaction design system where every surface is operable by both a human and an AI through one shared vocabulary.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "Apache-2.0",
|
package/scripts/ai-dispatch.js
CHANGED
|
@@ -17,8 +17,17 @@ import { createSpotlight } from "/scripts/ai-spotlight.js";
|
|
|
17
17
|
(() => {
|
|
18
18
|
"use strict";
|
|
19
19
|
|
|
20
|
-
// A stable session id for this tab; the server pushes results back on it.
|
|
20
|
+
// A stable session id for this tab; the server pushes results back on it. A server that issues
|
|
21
|
+
// and validates ids can hand one in (a data attribute or a global, set before this script runs);
|
|
22
|
+
// the per-tab UUID stays the fallback for a fully static site, so a page with no server still
|
|
23
|
+
// works. The id is validated here too, because it ends up in a query string: 128 safe characters
|
|
24
|
+
// or it is ignored and the UUID is used.
|
|
25
|
+
const provided =
|
|
26
|
+
(document.documentElement.dataset.deskSession || "") ||
|
|
27
|
+
(document.body.dataset.deskSession || "") ||
|
|
28
|
+
(typeof window.__DESK_SESSION__ === "string" ? window.__DESK_SESSION__ : "");
|
|
21
29
|
const session =
|
|
30
|
+
(provided.length > 0 && provided.length <= 128 && /^[A-Za-z0-9_-]+$/.test(provided) && provided) ||
|
|
22
31
|
(crypto && crypto.randomUUID && crypto.randomUUID()) ||
|
|
23
32
|
"s-" + Math.random().toString(36).slice(2) + performance.now();
|
|
24
33
|
|
|
@@ -20,6 +20,14 @@ test("ai-dispatch.js registers a case for every RenderOpKind contract.ts declare
|
|
|
20
20
|
for (const kind of kinds) expect(dispatch).toContain(`case "${kind}":`);
|
|
21
21
|
});
|
|
22
22
|
|
|
23
|
+
test("the client takes a server-issued session id before falling back to the per-tab UUID", async () => {
|
|
24
|
+
const dispatch = await read("./ai-dispatch.js");
|
|
25
|
+
expect(dispatch).toContain("dataset.deskSession");
|
|
26
|
+
expect(dispatch).toContain("__DESK_SESSION__");
|
|
27
|
+
expect(dispatch.indexOf("dataset.deskSession")).toBeLessThan(dispatch.indexOf("crypto.randomUUID"));
|
|
28
|
+
expect(dispatch).toContain("provided.length <= 128");
|
|
29
|
+
});
|
|
30
|
+
|
|
23
31
|
test("SAFE_NAV_HREF in ai-dispatch.js matches contract.ts's isSafeNavigateHref regex verbatim", async () => {
|
|
24
32
|
const [dispatch, contract] = await Promise.all([read("./ai-dispatch.js"), read("../ai/contract.ts")]);
|
|
25
33
|
const dispatchRe = dispatch.match(/const SAFE_NAV_HREF = (\/.*\/);/)?.[1];
|
package/scripts/catalog-peek.js
CHANGED
|
@@ -10,8 +10,10 @@
|
|
|
10
10
|
// open/close hooks, the lazy iframe load (base, unconditional), and the hover/tap bridge (enhanced,
|
|
11
11
|
// gated on the demo root existing).
|
|
12
12
|
//
|
|
13
|
-
// It maps each rendered CSS class to its catalog section slug
|
|
14
|
-
//
|
|
13
|
+
// It maps each rendered CSS class to its catalog section slug. The lookup is read from the loaded
|
|
14
|
+
// catalog itself: a class matches an entry whose slug equals it, or whose title does once a
|
|
15
|
+
// trailing "(source)" is dropped, which is how a consumer's own components ("cv-entry (portfolio)")
|
|
16
|
+
// get found. The hand MAP below only holds the aliases where the class and the slug differ. The catalog exposes a "single" mode (data-peek-single + .is-peek-active,
|
|
15
17
|
// driven here via window.__catSetActive). The bridge adapts to the pointer: with a HOVERING
|
|
16
18
|
// pointer it's a hover-reveal in single mode (one entry at a time, cross-fading). On a COARSE
|
|
17
19
|
// pointer (touch, no hover) a finger can't hover, so the same usage→specimen link becomes a TAP:
|
|
@@ -34,10 +36,12 @@
|
|
|
34
36
|
// on touch it would be undrivable, so there we leave the full scrollable catalog.
|
|
35
37
|
const canHover = matchMedia("(hover: hover) and (pointer: fine)").matches;
|
|
36
38
|
|
|
37
|
-
// rendered CSS class → catalog slug
|
|
38
|
-
//
|
|
39
|
-
//
|
|
40
|
-
//
|
|
39
|
+
// ALIASES: rendered CSS class → catalog slug, only where the two differ ("icon-btn" →
|
|
40
|
+
// "icon-button", "field" → "input"). Every other class resolves through the index built from the
|
|
41
|
+
// loaded catalog (indexCatalog below), so a new component reveals on hover with no edit here.
|
|
42
|
+
// Identity rows are kept so the bridge still works in the moment before the catalog loads. A
|
|
43
|
+
// drift test (catalog-peek.test.ts) fails if a slug here stops matching a real component.
|
|
44
|
+
// Innermost match wins (hover the glyph → Icon; the row → Nav item).
|
|
41
45
|
const MAP = {
|
|
42
46
|
"action-badge": "action-badge", "icon-btn": "icon-button", "nav-item": "nav-item",
|
|
43
47
|
"tab-bar": "tab-bar", "side-rail": "side-rail", "app-shell": "app-shell",
|
|
@@ -46,6 +50,28 @@
|
|
|
46
50
|
"icon": "icon", "t": "typography",
|
|
47
51
|
};
|
|
48
52
|
|
|
53
|
+
// class → slug, filled from the embedded catalog's own entries once it loads.
|
|
54
|
+
const INDEX = new Map();
|
|
55
|
+
const titleKey = (t) => t.replace(/\s*\([^)]*\)\s*$/, "").toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "");
|
|
56
|
+
function indexCatalog(doc) {
|
|
57
|
+
for (const d of doc.querySelectorAll(".cat-doc[id]")) {
|
|
58
|
+
if (!INDEX.has(d.id)) INDEX.set(d.id, d.id);
|
|
59
|
+
const h = d.querySelector("h1, h2");
|
|
60
|
+
const key = h && titleKey(h.textContent || "");
|
|
61
|
+
if (key && !INDEX.has(key)) INDEX.set(key, d.id);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
// the slug for one element, or null: an alias first, then the catalog's own index
|
|
65
|
+
const slugFor = (el) => {
|
|
66
|
+
if (!el.classList) return null;
|
|
67
|
+
for (const cls of el.classList) {
|
|
68
|
+
if (Object.prototype.hasOwnProperty.call(MAP, cls)) return MAP[cls];
|
|
69
|
+
const hit = INDEX.get(cls);
|
|
70
|
+
if (hit) return hit;
|
|
71
|
+
}
|
|
72
|
+
return null;
|
|
73
|
+
};
|
|
74
|
+
|
|
49
75
|
const isOpen = () => !pane.hidden;
|
|
50
76
|
// open/close = switch the sidebar-panel's mode — REUSE the shell's one mechanic (click its mode
|
|
51
77
|
// tab; shell.js flips data-mode/hidden/aria-selected), never a parallel show/hide path. On the
|
|
@@ -74,6 +100,7 @@
|
|
|
74
100
|
// on touch we skip single mode and leave the full scrollable catalog.
|
|
75
101
|
frame.addEventListener("load", () => {
|
|
76
102
|
// touch: no single mode — honour a tap that fired before the frame finished loading.
|
|
103
|
+
try { if (frame.contentDocument) indexCatalog(frame.contentDocument); } catch { /* cross-origin — aliases only */ }
|
|
77
104
|
if (!canHover) { if (pendingTouch) { scrollToInFrame(pendingTouch); pendingTouch = null; } return; }
|
|
78
105
|
try {
|
|
79
106
|
const doc = frame.contentDocument;
|
|
@@ -119,7 +146,8 @@
|
|
|
119
146
|
if (!canHover || !isOpen()) return;
|
|
120
147
|
let el = e.target;
|
|
121
148
|
while (el && el !== demo) {
|
|
122
|
-
|
|
149
|
+
const slug = slugFor(el);
|
|
150
|
+
if (slug) { peek(slug); return; }
|
|
123
151
|
el = el.parentElement;
|
|
124
152
|
}
|
|
125
153
|
// No component under the pointer → HOLD the current reveal (don't switch on prose/gaps). This
|
|
@@ -144,7 +172,7 @@
|
|
|
144
172
|
if (e.target.closest("a,button,input,textarea,select,label,[data-action],[data-peek]")) return;
|
|
145
173
|
let el = e.target, slug = null;
|
|
146
174
|
while (el && el !== demo && !slug) {
|
|
147
|
-
|
|
175
|
+
slug = slugFor(el);
|
|
148
176
|
el = el.parentElement;
|
|
149
177
|
}
|
|
150
178
|
if (!slug) return;
|
package/styles/variables.css
CHANGED
|
@@ -82,6 +82,11 @@
|
|
|
82
82
|
--font-weight-bold: 700; /* reserved for rare extra punch */
|
|
83
83
|
|
|
84
84
|
/* type scale (mobile-first, rem @ 16px) — fluid display via clamp */
|
|
85
|
+
/* Dense instrument steps, below the caption. Only for packed panels and meters, never body copy,
|
|
86
|
+
and only where the foreground clears 4.5:1 at that size; a hint that cannot be read is not a
|
|
87
|
+
hint. The Nest panel is the surface these were added for (2026-11-08). */
|
|
88
|
+
--text-3xs: 0.625rem; /* 10px dense instrument: meter hints, micro-labels */
|
|
89
|
+
--text-2xs: 0.6875rem; /* 11px dense instrument: panel labels, captions */
|
|
85
90
|
--text-xs: 0.8125rem; /* 13px caption */
|
|
86
91
|
--text-sm: 0.875rem; /* 14px label / eyebrow */
|
|
87
92
|
--text-base: 0.9375rem; /* 15px body */
|