@usableapp/cardds 0.7.179 → 0.7.180

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.
@@ -31,6 +31,8 @@ export interface HeadProps extends Omit<ComponentProps<'div'>, 'title' | 'onClos
31
31
  * finishes the card (that goes in its `Foot`). In `date` it stands on a row under the date, the chips and the title; in `centre` it is the right round `Btn`;
32
32
  * in `stack` the sheet's tabs or an icon. Not in `sheet`: there the buttons are `actions` */
33
33
  end?: ReactNode;
34
+ /** set by a `Card folds`, never by the app: the card's fold arrow. In `date` it stands at the head's top right, beside the chips, and takes no row of its own under the title (an app's own `end` stays on its row); the other variants leave it out */
35
+ fold?: ReactNode;
34
36
  /** `sheet` only: round `Btn`s (an icon each) beside the close, before it — two at most (more are left out); drawn at the close's size */
35
37
  actions?: ReactNode;
36
38
  /** `sheet` only: the close was pressed. The head only asks: the app takes the sheet away (`state="away"`). Without it the `Sheet` round
@@ -61,4 +63,4 @@ export interface HeadProps extends Omit<ComponentProps<'div'>, 'title' | 'onClos
61
63
  * Never put buttons here that finish the card: they go in the foot. A head takes no children. A `Card` finds its `Head` by type, so a consumer's
62
64
  * own component that wraps a `Head` is not found.
63
65
  */
64
- export declare function Head({ variant, title, meta, over, level, tag, lead, chips, chipsBelow, end, actions, onClose, closeLabel, back, backLabel, top, long, className, children, ...rest }: HeadProps): import("react").JSX.Element;
66
+ export declare function Head({ variant, title, meta, over, level, tag, lead, chips, chipsBelow, end, fold, actions, onClose, closeLabel, back, backLabel, top, long, className, children, ...rest }: HeadProps): import("react").JSX.Element;
@@ -65,7 +65,7 @@ function slotted(variant, given, words, close) {
65
65
  * Never put buttons here that finish the card: they go in the foot. A head takes no children. A `Card` finds its `Head` by type, so a consumer's
66
66
  * own component that wraps a `Head` is not found.
67
67
  */
68
- export function Head({ variant = 'plain', title, meta, over, level, tag, lead, chips, chipsBelow, end, actions, onClose, closeLabel, back, backLabel, top, long, className, children, ...rest }) {
68
+ export function Head({ variant = 'plain', title, meta, over, level, tag, lead, chips, chipsBelow, end, fold, actions, onClose, closeLabel, back, backLabel, top, long, className, children, ...rest }) {
69
69
  const tab = useContext(StackHeadCtx);
70
70
  const sheetClose = useContext(HeadCloseCtx);
71
71
  if (children != null)
@@ -77,5 +77,7 @@ export function Head({ variant = 'plain', title, meta, over, level, tag, lead, c
77
77
  const takesOver = TAKES[variant]?.includes('over') && over != null;
78
78
  const words = ((variant !== 'status' && title != null) || meta != null || takesOver) && (_jsx(Words, { title: variant === 'status' ? undefined : title, meta: meta, level: level, over: takesOver ? over : undefined }, "words"));
79
79
  const list = Children.toArray(slotted(variant, given, words, onClose ?? sheetClose));
80
+ if (variant === 'date' && fold != null)
81
+ list.push(_jsx("span", { className: "head__fold", children: fold }, "fold"));
80
82
  return (_jsx("div", { className: cx('head', top && 'head--top', variant === 'centre' && 'head--centre', variant === 'status' && 'head--status', className), ...rest, children: _jsx(HeadCtx.Provider, { value: { tab, long: !!long }, children: withEndRoom(list, Words) ?? list }) }));
81
83
  }
@@ -15,6 +15,8 @@ export interface SheetStackProps extends ComponentProps<'div'> {
15
15
  refreshing?: number | null;
16
16
  /** the grip every sheet wears at the middle of its top edge: `dots` (default, four small dots) or `line` (one line, as a `Sheet`'s). Either one changes colour the same way while its sheet is `refreshing` */
17
17
  mark?: 'dots' | 'line';
18
+ /** the tab names of its `StackSheet`s under their icons (default `true`); `false`: icons alone, the peeks as short as before. A sheet's own `tabLabels` wins */
19
+ tabLabels?: boolean;
18
20
  /** wider peeks so more of each title shows (display stacks) */
19
21
  fanned?: boolean;
20
22
  /** nothing open on arrival (tap mode): every sheet, the front one too, peeks at the stack's bottom; the room above is the base's (`base`). A tap opens any sheet over it */
@@ -40,4 +42,4 @@ export interface SheetStackProps extends ComponentProps<'div'> {
40
42
  * below, the ones before tuck under nearest-first; closing reverses in two beats. Only `translate` (stack.css); never a size.
41
43
  * The CURSOR is cardds's: a sheet that opens takes it in the field marked `data-autofocus`, else the first field, else the heading — write no `autoFocus` or `.focus()` for it.
42
44
  */
43
- export declare function SheetStack({ mode, open, defaultOpen, onOpenChange, onRefresh, refreshing, mark, fanned, closed, rise, base, className, children, onClickCapture, onPointerDownCapture, ref: passed, ...rest }: SheetStackProps): import("react").JSX.Element;
45
+ export declare function SheetStack({ mode, open, defaultOpen, onOpenChange, onRefresh, refreshing, mark, tabLabels, fanned, closed, rise, base, className, children, onClickCapture, onPointerDownCapture, ref: passed, ...rest }: SheetStackProps): import("react").JSX.Element;
@@ -69,7 +69,7 @@ function stamp(child, place) {
69
69
  * below, the ones before tuck under nearest-first; closing reverses in two beats. Only `translate` (stack.css); never a size.
70
70
  * The CURSOR is cardds's: a sheet that opens takes it in the field marked `data-autofocus`, else the first field, else the heading — write no `autoFocus` or `.focus()` for it.
71
71
  */
72
- export function SheetStack({ mode = 'tap', open, defaultOpen = null, onOpenChange, onRefresh, refreshing = null, mark = 'dots', fanned, closed, rise = 'under', base, className, children, onClickCapture, onPointerDownCapture, ref: passed, ...rest }) {
72
+ export function SheetStack({ mode = 'tap', open, defaultOpen = null, onOpenChange, onRefresh, refreshing = null, mark = 'dots', tabLabels, fanned, closed, rise = 'under', base, className, children, onClickCapture, onPointerDownCapture, ref: passed, ...rest }) {
73
73
  const [current, request] = useControlled(open, defaultOpen, onOpenChange);
74
74
  const prev = useRef(current);
75
75
  const [closingFrom, setClosingFrom] = useState(null);
@@ -166,6 +166,7 @@ export function SheetStack({ mode = 'tap', open, defaultOpen = null, onOpenChang
166
166
  open: !closing && current === i,
167
167
  refreshing: refreshing === i,
168
168
  mark,
169
+ tabLabels,
169
170
  before,
170
171
  after: !closing && current != null && i > current,
171
172
  stagger: before && anchor != null ? anchor - 1 - i : returning != null && i < returning ? returning - 1 - i : 0,
@@ -1,11 +1,11 @@
1
1
  import { type ComponentProps, type ReactNode } from 'react';
2
2
  import { type Tone } from '../cards/Card.js';
3
- import type { IconName } from '../type/Icon.js';
3
+ import { type IconName } from '../type/Icon.js';
4
4
  import type { StackPlace } from './stackCard.js';
5
5
  export interface StackSheetTab {
6
6
  id: string;
7
7
  icon: IconName;
8
- /** the tab's name, read aloud (the head shows the icon only) */
8
+ /** the tab's name: written under the icon (unless `tabLabels` is off) and read aloud with the count */
9
9
  label: string;
10
10
  /** a small count over the icon: what waits there (alerts, new asks); 0 or none = no circle */
11
11
  count?: number;
@@ -29,6 +29,8 @@ export interface StackSheetProps extends Omit<ComponentProps<'article'>, 'title'
29
29
  defaultTab?: string;
30
30
  /** a tab was tapped: its id */
31
31
  onTabChange?: (tab: string) => void;
32
+ /** each tab's name in writing under its icon, one line (default `true`); `false`: the icons alone, the name only read aloud. Omit it and the `SheetStack`'s `tabLabels` decides */
33
+ tabLabels?: boolean;
32
34
  /** a row pinned under the SHEET HEAD, outside the body's scroll and pull (a form button over a list): it never scrolls nor moves with a pull to refresh */
33
35
  top?: ReactNode;
34
36
  /** the SHEET FOOT: the CTA at the sheet's bottom (one row) */
@@ -43,9 +45,9 @@ export interface StackSheetProps extends Omit<ComponentProps<'article'>, 'title'
43
45
  }
44
46
  /**
45
47
  * StackSheet — ONE sheet of a `SheetStack`, in the one sheet shape: SHEET HEAD (back · title · tabs or an icon) pinned at the top ·
46
- * `top` (pinned under the head, optional) · SHEET BODY (the children; scrolls) · SHEET FOOT (`foot`, the CTA) at the bottom. Its tabs are icon buttons. The chosen one is filled
48
+ * `top` (pinned under the head, optional) · SHEET BODY (the children; scrolls) · SHEET FOOT (`foot`, the CTA) at the bottom. Its tabs are an icon over the tab's name (`tabLabels={false}`: icon buttons alone). The chosen one is filled
47
49
  * only while this sheet is open — a closed home shows every icon plain; the disc fades in with the rise and out with the fold.
48
50
  * A count shows as a small circle over its icon (`countPrefix` writes before it: "+1"), and is read with the tab's name. The body is the app's: render the page of the chosen tab (and nothing while the sheet
49
51
  * is closed — see `Home`). A direct child of `SheetStack`. Once open, cardds puts the cursor in the field marked `data-autofocus`, else the first field, else the heading — write no focus code.
50
52
  */
51
- export declare function StackSheet({ title, tone, paper, icon, tabs, tab: tabProp, defaultTab, onTabChange, top, foot, backLabel, backAt, stack, className, children, ...rest }: StackSheetProps): import("react").JSX.Element;
53
+ export declare function StackSheet({ title, tone, paper, icon, tabs, tab: tabProp, defaultTab, onTabChange, tabLabels, top, foot, backLabel, backAt, stack, className, children, ...rest }: StackSheetProps): import("react").JSX.Element;
@@ -7,17 +7,19 @@ import { Btn } from '../actions/Btn.js';
7
7
  import { Head } from '../parts/Head.js';
8
8
  import { Foot } from '../parts/Foot.js';
9
9
  import { Body } from '../parts/Body.js';
10
+ import { Icon } from '../type/Icon.js';
10
11
  import { Badge } from '../numbers/Badge.js';
11
12
  import { word } from '../words.js';
12
13
  import { runOver } from './sheetMeasure.js';
13
14
  /**
14
15
  * StackSheet — ONE sheet of a `SheetStack`, in the one sheet shape: SHEET HEAD (back · title · tabs or an icon) pinned at the top ·
15
- * `top` (pinned under the head, optional) · SHEET BODY (the children; scrolls) · SHEET FOOT (`foot`, the CTA) at the bottom. Its tabs are icon buttons. The chosen one is filled
16
+ * `top` (pinned under the head, optional) · SHEET BODY (the children; scrolls) · SHEET FOOT (`foot`, the CTA) at the bottom. Its tabs are an icon over the tab's name (`tabLabels={false}`: icon buttons alone). The chosen one is filled
16
17
  * only while this sheet is open — a closed home shows every icon plain; the disc fades in with the rise and out with the fold.
17
18
  * A count shows as a small circle over its icon (`countPrefix` writes before it: "+1"), and is read with the tab's name. The body is the app's: render the page of the chosen tab (and nothing while the sheet
18
19
  * is closed — see `Home`). A direct child of `SheetStack`. Once open, cardds puts the cursor in the field marked `data-autofocus`, else the first field, else the heading — write no focus code.
19
20
  */
20
- export function StackSheet({ title, tone, paper, icon, tabs, tab: tabProp, defaultTab, onTabChange, top, foot, backLabel = word('back'), backAt = 'none', stack, className, children, ...rest }) {
21
+ export function StackSheet({ title, tone, paper, icon, tabs, tab: tabProp, defaultTab, onTabChange, tabLabels, top, foot, backLabel = word('back'), backAt = 'none', stack, className, children, ...rest }) {
22
+ const named = (tabLabels ?? stack?.tabLabels) !== false;
21
23
  const [tab, pick] = useControlled(tabProp, defaultTab ?? tabs?.[0]?.id, onTabChange);
22
24
  // a title longer than its room does not wrap: it runs sideways, like a song title in a short slot — the room it overflows by
23
25
  // is measured here (the tabs may grow with the text size) and handed to the CSS as --_over / --_run, the Sheet's measurer
@@ -31,8 +33,11 @@ export function StackSheet({ title, tone, paper, icon, tabs, tab: tabProp, defau
31
33
  measure();
32
34
  return watchSize([h, run], measure);
33
35
  }, [title]);
34
- return (_jsxs(Card, { stack: stack, tone: tone, paper: paper, className: cx('stack-sheet', className), ...rest, children: [_jsx(Head, { ref: headRef, long: long, variant: "stack", back: backAt === 'none' ? undefined : backAt, backLabel: backLabel, title: _jsx("span", { className: "stack-sheet__run", children: title }), end: tabs?.length ? (_jsx("span", { className: "stack-sheet__tabs", role: "tablist", children: tabs.map((t) => {
36
+ return (_jsxs(Card, { stack: stack, tone: tone, paper: paper, className: cx('stack-sheet', className), ...rest, children: [_jsx(Head, { ref: headRef, long: long, variant: "stack", back: backAt === 'none' ? undefined : backAt, backLabel: backLabel, title: _jsx("span", { className: "stack-sheet__run", children: title }), end: tabs?.length ? (_jsx("span", { className: cx('stack-sheet__tabs', named && 'stack-sheet__tabs--named'), role: "tablist", children: tabs.map((t) => {
35
37
  const count = t.count ? `${t.countPrefix ?? ''}${t.count > 99 ? '99+' : t.count}` : '';
38
+ if (named) {
39
+ return (_jsxs("button", { type: "button", role: "tab", "aria-selected": t.id === tab, "aria-label": count ? `${t.label} ${count}` : t.label, className: "stack-sheet__tab stack-sheet__tab--named", onClick: () => pick(t.id), children: [_jsxs("span", { className: "stack-sheet__tab-icon", children: [_jsx(Icon, { name: t.icon }), count ? _jsx(Badge, { className: "stack-sheet__count", "aria-hidden": "true", children: count }) : null] }), _jsx("span", { className: "stack-sheet__tab-name", "aria-hidden": "true", children: t.label })] }, t.id));
40
+ }
36
41
  return (_jsx(Btn, { shape: "round", size: "sm", icon: t.icon, tone: t.id === tab ? 'primary' : undefined, role: "tab", "aria-selected": t.id === tab, label: count ? `${t.label} ${count}` : t.label, className: "stack-sheet__tab", onClick: () => pick(t.id), children: count ? _jsx(Badge, { className: "stack-sheet__count", children: count }) : null }, t.id));
37
42
  }) })) : icon }), top != null && _jsx("div", { className: "stack-sheet__top", children: top }), _jsx(Body, { role: tabs?.length ? 'tabpanel' : undefined, children: children }), foot != null && _jsx(Foot, { children: foot })] }));
38
43
  }
@@ -13,6 +13,8 @@ export interface StackPlace {
13
13
  after: boolean;
14
14
  /** nearest-first delay, while tucked and while those sheets return */
15
15
  stagger: number;
16
+ /** the stack's `tabLabels`: a `StackSheet` with no `tabLabels` of its own follows it */
17
+ tabLabels?: boolean;
16
18
  onOpen: () => void;
17
19
  onClose: () => void;
18
20
  onRefresh?: () => void;
@@ -45,6 +45,8 @@ export interface HomeProps extends Omit<ComponentProps<typeof Screen>, 'children
45
45
  refreshing?: number | null;
46
46
  /** the grip on every sheet: `dots` (default) or `line` — as `SheetStack mark` */
47
47
  mark?: 'dots' | 'line';
48
+ /** the tab names under the icons of every sheet (default `true`); `false`: icons alone, the heads peek as short as before — as `SheetStack tabLabels` */
49
+ tabLabels?: boolean;
48
50
  /** how an open sheet meets the top: `under` (default) stops under the AppBar · `flood` rises over it and fills the WHOLE screen, the bar covered while a sheet is open — as `SheetStack rise` */
49
51
  rise?: 'under' | 'flood';
50
52
  /** CONTENT above the sheet heads — one `Page`: a welcome, the news, a picture. It reads
@@ -66,4 +68,4 @@ export interface HomeProps extends Omit<ComponentProps<typeof Screen>, 'children
66
68
  * at the bottom). A tap on a head brings that sheet up to fill everything under the top (`rise="flood"`: the whole screen, over the bar). With a LayerHistory above and no `open` prop, that open sheet is one history entry named `home`. Only the open sheet's body is rendered — three
67
69
  * sections on one home never cost three pages (`keep` holds a body once opened).
68
70
  */
69
- export declare function Home({ top, title, sheets, open: openProp, defaultOpen, onOpenChange, onRefresh, refreshing, mark, rise, base, keep, backLabel, backAt, children, ...rest }: HomeProps): import("react").JSX.Element;
71
+ export declare function Home({ top, title, sheets, open: openProp, defaultOpen, onOpenChange, onRefresh, refreshing, mark, tabLabels, rise, base, keep, backLabel, backAt, children, ...rest }: HomeProps): import("react").JSX.Element;
@@ -16,7 +16,7 @@ const LEAVE = 800; // ms: a closing sheet keeps its body until it has slid home
16
16
  * at the bottom). A tap on a head brings that sheet up to fill everything under the top (`rise="flood"`: the whole screen, over the bar). With a LayerHistory above and no `open` prop, that open sheet is one history entry named `home`. Only the open sheet's body is rendered — three
17
17
  * sections on one home never cost three pages (`keep` holds a body once opened).
18
18
  */
19
- export function Home({ top, title, sheets, open: openProp, defaultOpen = null, onOpenChange, onRefresh, refreshing, mark, rise, base, keep, backLabel = word('back'), backAt, children, ...rest }) {
19
+ export function Home({ top, title, sheets, open: openProp, defaultOpen = null, onOpenChange, onRefresh, refreshing, mark, tabLabels, rise, base, keep, backLabel = word('back'), backAt, children, ...rest }) {
20
20
  const layer = useOptionalLayer('home');
21
21
  const [local, change] = useControlled(openProp, defaultOpen, onOpenChange);
22
22
  // A passed `open` is the parent's. With no LayerHistory the index stays local, so a story without a router still opens sheets.
@@ -51,5 +51,5 @@ export function Home({ top, title, sheets, open: openProp, defaultOpen = null, o
51
51
  const [tabs, setTabs] = useState(() => Object.fromEntries(sheets.map((x, i) => [i, x.defaultTab ?? x.tabs?.[0]?.id])));
52
52
  const shows = (i) => i === shown || i === leaving || (keep && seen.has(i));
53
53
  const tabOf = (i) => sheets[i].tab ?? tabs[i];
54
- return (_jsxs(Screen, { fill: true, top: top, ...rest, children: [_jsx(Text, { level: "h1", as: "h1", sr: true, children: title }), _jsx(SheetStack, { closed: true, open: shown, onOpenChange: request, onRefresh: onRefresh, refreshing: refreshing, mark: mark, rise: rise, base: base, children: sheets.map((s, i) => (_jsx(StackSheet, { tone: s.tone ?? TONES[i], paper: s.paper, title: s.title, icon: s.icon, tabs: s.tabs, tab: tabOf(i), onTabChange: (t) => { setTabs((v) => ({ ...v, [i]: t })); s.onTabChange?.(t); }, backLabel: backLabel, backAt: backAt, top: shows(i) ? (typeof s.top === 'function' ? s.top(tabOf(i)) : s.top) : null, foot: typeof s.foot === 'function' ? s.foot(tabOf(i)) : s.foot, children: shows(i) ? (typeof s.body === 'function' ? s.body(tabOf(i)) : s.body) : null }, i))) }), children] }));
54
+ return (_jsxs(Screen, { fill: true, top: top, ...rest, children: [_jsx(Text, { level: "h1", as: "h1", sr: true, children: title }), _jsx(SheetStack, { closed: true, open: shown, onOpenChange: request, onRefresh: onRefresh, refreshing: refreshing, mark: mark, tabLabels: tabLabels, rise: rise, base: base, children: sheets.map((s, i) => (_jsx(StackSheet, { tone: s.tone ?? TONES[i], paper: s.paper, title: s.title, icon: s.icon, tabs: s.tabs, tab: tabOf(i), onTabChange: (t) => { setTabs((v) => ({ ...v, [i]: t })); s.onTabChange?.(t); }, backLabel: backLabel, backAt: backAt, top: shows(i) ? (typeof s.top === 'function' ? s.top(tabOf(i)) : s.top) : null, foot: typeof s.foot === 'function' ? s.foot(tabOf(i)) : s.foot, children: shows(i) ? (typeof s.body === 'function' ? s.body(tabOf(i)) : s.body) : null }, i))) }), children] }));
55
55
  }
package/dist/type/Icon.js CHANGED
@@ -25,7 +25,7 @@ export function Icon({ name, children, size = 'md', label, className, ...rest })
25
25
  const icon = name === undefined ? undefined : OWN.get(name) ?? ICONS[name];
26
26
  if (name !== undefined && !icon)
27
27
  warnOnce(`icon:${name}`, `cardds Icon: no icon named "${name}" — a stock name is misspelt, or the project has not registered it (registerIcons)`);
28
- const shared = { className: cx('icon', size !== 'md' && `icon--${size}`, className), role: label ? 'img' : undefined, 'aria-label': label, 'aria-hidden': label ? undefined : true };
28
+ const shared = { className: cx('icon', size !== 'md' && `icon--${size}`, className), role: label ? 'img' : undefined, 'aria-label': label, 'aria-hidden': label ? undefined : true, 'data-icon': name };
29
29
  // an unknown name draws nothing but keeps its box — a missing icon never takes a screen down
30
30
  if (!icon)
31
31
  return _jsx("svg", { ...STROKE, ...shared, ...rest, children: children });
package/docs/reference.md CHANGED
@@ -153,6 +153,8 @@ npx cardds scaffold <id> # a whole file from a screen: tsx (the code) or
153
153
  npx cardds get <Name> [--html] # one component: its role, props (a ReactNode prop is a slot), what it composes, its knobs + variations with code
154
154
  npx cardds list # every name by what it is for: one · group-brief · group-detail, the show-only first, then by what the member can do
155
155
  npx cardds check <dir> # the rules — a person's tool, never a session's step
156
+ npx cardds audit [file.html…] # a screen against "Rules of the system": no file = the questions to put to a picture, one set per rule;
157
+ # one file = one rendered page, several = a flow in that order; each fault { rule, page?, where, says }
156
158
  npx cardds guide # the few rules no checker sees, in one short text
157
159
  ```
158
160
 
@@ -163,7 +165,8 @@ component **composes** (the catalog names its own source renders or calls: `Fab`
163
165
  turned on or off", "a code digit by digit") finds the piece (`Toggle`, `Pin`).
164
166
 
165
167
  `list` · `get` · `find` · `scaffold` take `--json` (the function's result) and `--root <path>` (a cardds checkout: rebuilt first, so never stale). The same
166
- five answers over MCP — `list_components` · `get_component` · `find_components` · `scaffold_screen` · `check_source`:
168
+ five answers over MCP — `list_components` · `get_component` · `find_components` · `scaffold_screen` · `check_source` — and a sixth, `audit_screen`, for
169
+ the screen as the member sees it: the questions for a picture (no argument), the faults of a rendered page (`html`), of a flow (`pages`):
167
170
 
168
171
  ```json
169
172
  { "mcpServers": { "cardds": { "command": "npx", "args": ["cardds", "mcp"] } } }
@@ -859,7 +862,12 @@ between: its own 40% point on the line 40% down the screen (see *Anatomy*, "Wher
859
862
  ring. A folding card is never pressed whole. Not on a `row`, `sm`, `stack`
860
863
  or `paper="bands"` card, nor with `back` or `onPress` (it is ignored there,
861
864
  with a warning). The card draws its own chevron down as the head's last
862
- end (after the app's ends), turned up while open, as a `Banner`'s. Stories `Card · Folds`, `FoldsControlled`.
865
+ end (after the app's ends), turned up while open, as a `Banner`'s. In a
866
+ `Head variant="date"` the chevron stands at the head's top right, beside
867
+ the chips (the upper row when there are two, `chipsBelow`), and makes no row
868
+ under the title; an `end` the app gives that head keeps its own row there.
869
+ Stories `Card · Folds`, `FoldsControlled`, `FoldsDate`, `FoldsDateOpen`,
870
+ `FoldsDateTwoRows`, `FoldsDateTwoRowsOpen`.
863
871
  - A page with **one feature and one CTA** (an install page, a single
864
872
  decision) may be contained in one card: head, the pitch, foot.
865
873
  - **A bottom sheet holds what the member acts on** — controls, or small
@@ -1384,6 +1392,33 @@ question and hunts for its answer. Rules 11–13 serve that:
1384
1392
  is a zero-specificity `:where()` list (the user-select list is a plain
1385
1393
  list of single selectors), so a component's own rule always wins.
1386
1394
 
1395
+ 16. **One layer over the screen: never a sheet in a sheet** (Lh 2026-11-24: "ตอนนี้เราเป็น sheet stack เปิด sheet
1396
+ แล้วไปการ์ด จากนั้นการ์ดเรากำลังจะกลับไป ชีท อีกทีนึง มันจะเป็นชีทในชีทแล้ว ภาษาดีไซน์คือมันกลายเป็นงานซ้อนกันข้างในเกินไป").
1397
+ A screen (a flooded stack sheet counts as the screen) takes at most ONE layer over it, and only for work the member
1398
+ writes or fills in. Before adding a layer, take the first of these that fits:
1399
+ - **More of what the member is looking at opens where it is.** A list of cards: `Card folds` (the head always
1400
+ shows; a tap opens the content and the foot in place). A queue the system hands over one card at a time:
1401
+ `CardFeed`. Never a sheet that repeats the card it was opened from.
1402
+ - **The moves on one thing are one button with a menu.** A small `Menu popover` that the button opens with
1403
+ `popoverTarget`, holding only the moves open at that moment; picking one closes it. The button says that it
1404
+ opens a menu: its words, then a `chevron-down` (`<Btn popoverTarget="…">มีปัญหา <Icon name="chevron-down"
1405
+ size="xs" /></Btn>`; Lh 2026-11-24: "ปุ่มมีปัญหาควรแสดงตัวด้วยว่าเป็นปุ่มประเภทที่กดแล้วจะมีเมนูอื่นๆ ให้เลือก").
1406
+ Never a sheet of options.
1407
+ - **Writing or filling in is the one task sheet.** `SheetStage over dim` holding one `Sheet` (`Head` · `Body` ·
1408
+ `Foot`), laid over the home as the ask sheet is (`Home/AskSheet`). Nothing in it opens a second sheet; a question
1409
+ it has to ask is a `Modal` with a `ModalAsk`.
1410
+ - **One thing keeps one card in every state.** The same parts in the same places and the same size from its first
1411
+ state to its last (Lh 2026-11-24: "การ์ดไม่ควรเปลี่ยนขนาดหรือเปลี่ยนรายละเอียด ทำให้การ์ด consistent"). A state
1412
+ changes only the signal chip, the status line under the title (the head's `meta`; Lh 2026-11-24: "ใต้ชื่อคำขอ"),
1413
+ the line that says where the thing's value stands, and the words of the primary button. The foot keeps one shape
1414
+ in every state that has moves: the menu button left, the one primary right.
1415
+
1416
+ The check (Lh 2026-11-24): draw the main screen once with everything open: every part of the card, one card open,
1417
+ its deepest menu shown open. "ถ้าหน้านั้นดูรู้เรื่อง และ UI ไม่เละถือว่าเป็นดีไซน์ที่ใช้ได้". A structure that only reads
1418
+ when it is shown screen by screen does not hold. The tool for this check is `audit_screen` (`npx cardds audit`): given
1419
+ a picture it asks this rule's questions, given the rendered DOM of a page or the pages of a flow it names what breaks
1420
+ this rule on the screen.
1421
+
1387
1422
  ## A project's theme
1388
1423
 
1389
1424
  A project retunes cardds from ONE file of its own, and nothing else. Copy
package/lib/audit.mjs ADDED
@@ -0,0 +1,330 @@
1
+ import { readFileSync } from 'node:fs';
2
+ import { dirname, join } from 'node:path';
3
+ import { fileURLToPath } from 'node:url';
4
+
5
+ const PACKAGE_ROOT = join(dirname(fileURLToPath(import.meta.url)), '..');
6
+ const REFERENCE_FILE = join(PACKAGE_ROOT, 'docs', 'reference.md');
7
+ const ICON_SPRITE_FILE = join(PACKAGE_ROOT, 'icons.svg');
8
+ const RULES_HEADING = '## Rules of the system';
9
+ const LAYER_RULE = 16;
10
+ const MENU_ICON = 'chevron-down';
11
+ const CLASSES_SHOWN_MAX = 3;
12
+ const WORDS_SHOWN_MAX = 40;
13
+ const WORDS_SEARCHED_MAX = WORDS_SHOWN_MAX * 4;
14
+
15
+ const VOID_TAGS = new Set(['area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'link', 'meta', 'source', 'track', 'wbr']);
16
+ const TEXT_TAGS = new Set(['script', 'style']);
17
+ const NAMED_CHARACTERS = { amp: '&', lt: '<', gt: '>', quot: '"', apos: "'", nbsp: ' ' };
18
+
19
+ const COMMENT_OPEN = '<!--';
20
+ const COMMENT_CLOSE = '-->';
21
+ const CDATA_OPEN = '<![CDATA[';
22
+ const CDATA_CLOSE = ']]>';
23
+ const TAG = /<[!?][^<>]*>|<\/([a-zA-Z][^\s>/<]*)[^<>]*>|<([a-zA-Z][^\s>/<]*)((?:"[^"]*"|'[^']*'|[^'"<>])*?)(\/?)>/y;
24
+ const ATTRIBUTE = /([^\s"'<>/=]+)(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'=<>`]+)))?/g;
25
+
26
+ const decodeEntities = (text) => text.replace(/&(#x[0-9a-f]+|#\d+|[a-z]+);/gi, (whole, name) => {
27
+ if (name[0] !== '#') return NAMED_CHARACTERS[name.toLowerCase()] ?? whole;
28
+ const code = name[1].toLowerCase() === 'x' ? parseInt(name.slice(2), 16) : Number(name.slice(1));
29
+ return code <= 0x10ffff ? String.fromCodePoint(code) : whole;
30
+ });
31
+
32
+ const attributesOf = (source) => Object.fromEntries(
33
+ [...source.matchAll(ATTRIBUTE)].map(([, name, double, single, bare]) => [name.toLowerCase(), decodeEntities(double ?? single ?? bare ?? '')]),
34
+ );
35
+
36
+ const endOfText = (html, tag, from) => {
37
+ const closing = new RegExp(`</${tag}`, 'gi');
38
+ closing.lastIndex = from;
39
+ return closing.exec(html)?.index ?? html.length;
40
+ };
41
+
42
+ const endOfMarkup = (html, closing, from) => {
43
+ const at = html.indexOf(closing, from);
44
+ return at < 0 ? html.length : at + closing.length;
45
+ };
46
+
47
+ export function parse(html) {
48
+ const root = { tag: '#document', attrs: {}, children: [], parent: null };
49
+ const openCounts = new Map();
50
+ const tag = new RegExp(TAG);
51
+ let current = root;
52
+ let consumed = 0;
53
+ let at = 0;
54
+ const addText = (to) => {
55
+ const raw = html.slice(consumed, to);
56
+ if (raw) current.children.push({ text: decodeEntities(raw), parent: current });
57
+ };
58
+ const closeTag = (name) => {
59
+ if (!openCounts.get(name)) return;
60
+ for (let node = current; node.parent; node = node.parent) {
61
+ openCounts.set(node.tag, openCounts.get(node.tag) - 1);
62
+ if (node.tag === name) {
63
+ current = node.parent;
64
+ return;
65
+ }
66
+ }
67
+ };
68
+ const skip = (to, from) => {
69
+ addText(from);
70
+ consumed = at = to;
71
+ };
72
+ while (at < html.length) {
73
+ const start = html.indexOf('<', at);
74
+ if (start < 0) break;
75
+ if (html.startsWith(COMMENT_OPEN, start)) {
76
+ skip(endOfMarkup(html, COMMENT_CLOSE, start + COMMENT_OPEN.length), start);
77
+ continue;
78
+ }
79
+ if (html.startsWith(CDATA_OPEN, start)) {
80
+ skip(endOfMarkup(html, CDATA_CLOSE, start + CDATA_OPEN.length), start);
81
+ continue;
82
+ }
83
+ tag.lastIndex = start;
84
+ const token = tag.exec(html);
85
+ if (!token) {
86
+ at = start + 1;
87
+ continue;
88
+ }
89
+ const [whole, closing, opening, attributes, selfClosed] = token;
90
+ skip(start + whole.length, start);
91
+ if (closing) closeTag(closing.toLowerCase());
92
+ if (!opening) continue;
93
+ const name = opening.toLowerCase();
94
+ const element = { tag: name, attrs: attributesOf(attributes), children: [], parent: current };
95
+ current.children.push(element);
96
+ if (TEXT_TAGS.has(name)) consumed = at = endOfText(html, name, at);
97
+ else if (!selfClosed && !VOID_TAGS.has(name)) {
98
+ openCounts.set(name, (openCounts.get(name) ?? 0) + 1);
99
+ current = element;
100
+ }
101
+ }
102
+ addText(html.length);
103
+ return root;
104
+ }
105
+
106
+ const isElement = (node) => node.tag !== undefined;
107
+ const classesOf = (node) => (node.attrs.class ?? '').split(/\s+/).filter(Boolean);
108
+ const hasClass = (node, name) => classesOf(node).includes(name);
109
+ const hasAttribute = (node, name) => Object.hasOwn(node.attrs, name);
110
+
111
+ const pushReversed = (pending, children) => {
112
+ for (let index = children.length - 1; index >= 0; index--) pending.push(children[index]);
113
+ };
114
+
115
+ function* descendants(node, isClosed = () => false) {
116
+ const pending = [];
117
+ pushReversed(pending, node.children);
118
+ while (pending.length) {
119
+ const child = pending.pop();
120
+ if (!isElement(child)) continue;
121
+ yield child;
122
+ if (!isClosed(child)) pushReversed(pending, child.children);
123
+ }
124
+ }
125
+
126
+ const wordsIn = (node, limit = Infinity) => {
127
+ const texts = [];
128
+ const pending = [];
129
+ let length = 0;
130
+ pushReversed(pending, node.children);
131
+ while (pending.length && length < limit) {
132
+ const child = pending.pop();
133
+ if (isElement(child)) pushReversed(pending, child.children);
134
+ else {
135
+ texts.push(child.text);
136
+ length += child.text.length;
137
+ }
138
+ }
139
+ return texts.join('').replace(/\s+/g, ' ').trim();
140
+ };
141
+
142
+ const clipped = (words) => (words.length > WORDS_SHOWN_MAX ? `${words.slice(0, WORDS_SHOWN_MAX - 1)}…` : words);
143
+
144
+ const isCard = (node) => hasClass(node, 'card');
145
+ const isSheet = (node) => isCard(node) && hasClass(node, 'sheet');
146
+ const isModal = (node) => isCard(node) && hasClass(node, 'modal');
147
+ const isLayer = (node) => isSheet(node) || isModal(node);
148
+ const isGone = (node) => hasClass(node, 'sheet--away') || hasAttribute(node, 'inert') || hasAttribute(node, 'hidden');
149
+ const isOpenLayer = (node) => isLayer(node) && !isGone(node);
150
+ const isButton = (node) => node.tag === 'button' || (node.tag === 'a' && (hasClass(node, 'btn') || hasClass(node, 'icon-btn')));
151
+
152
+ const headOf = (card) => [...descendants(card, isCard)].find((node) => hasClass(node, 'head'));
153
+
154
+ const titleOf = (card) => {
155
+ const head = headOf(card);
156
+ if (!head) return '';
157
+ const title = [...descendants(head)].find((node) => hasClass(node, 'words__title'));
158
+ return wordsIn(title ?? head);
159
+ };
160
+
161
+ const describe = (node) => {
162
+ const id = hasAttribute(node, 'id') ? `#${node.attrs.id}` : '';
163
+ const classes = classesOf(node).slice(0, CLASSES_SHOWN_MAX).map((name) => `.${name}`).join('');
164
+ const words = (isCard(node) && titleOf(node)) || clipped(wordsIn(node, WORDS_SEARCHED_MAX));
165
+ return `${node.tag}${id}${classes}${words ? ` "${words}"` : ''}`;
166
+ };
167
+
168
+ const found = (node, says) => ({ rule: LAYER_RULE, where: describe(node), says });
169
+ const onPage = (item, page) => ({ rule: item.rule, page, where: item.where, says: item.says });
170
+
171
+ const drawingOf = (svg) => svg.children.filter(isElement).map((part) => `${part.tag}${JSON.stringify(Object.entries(part.attrs).sort())}`).join('');
172
+
173
+ const iconDrawing = (name) => {
174
+ const sprite = parse(readFileSync(ICON_SPRITE_FILE, 'utf8'));
175
+ const symbol = [...descendants(sprite)].find((node) => node.tag === 'symbol' && node.attrs.id === name);
176
+ return symbol ? drawingOf(symbol) : null;
177
+ };
178
+
179
+ const LAYER_KINDS = [
180
+ { name: 'sheet', is: isSheet },
181
+ { name: 'modal', is: isModal },
182
+ ];
183
+
184
+ const layersOverScreen = (root) => {
185
+ const open = [...descendants(root)].filter(isOpenLayer);
186
+ return LAYER_KINDS.flatMap(({ name, is }) => {
187
+ const sameKind = open.filter(is);
188
+ return sameKind.slice(1).map((layer, index) => found(layer, `${name} ${index + 2} of ${sameKind.length} is open over the screen at the same time: a screen takes at most one layer`));
189
+ });
190
+ };
191
+
192
+ const isIcon = (svg, name, drawing) => (hasAttribute(svg, 'data-icon') ? svg.attrs['data-icon'] === name : drawingOf(svg) === drawing);
193
+
194
+ const menuButtonsWithoutChevron = (root) => {
195
+ const everything = [...descendants(root)];
196
+ const menuIds = new Set(everything.filter((node) => hasClass(node, 'menu') && hasAttribute(node, 'id')).map((node) => node.attrs.id));
197
+ const chevron = iconDrawing(MENU_ICON);
198
+ const showsChevron = (button) => [...descendants(button)].some((node) => node.tag === 'svg' && isIcon(node, MENU_ICON, chevron));
199
+ return everything
200
+ .filter((node) => menuIds.has(node.attrs.popovertarget) && !showsChevron(node))
201
+ .map((button) => found(button, `opens a Menu but has no ${MENU_ICON} icon: the button says it opens a menu, its words then <Icon name="${MENU_ICON}" size="xs" />`));
202
+ };
203
+
204
+ const sheetCardsRepeatingScreen = (root) => {
205
+ const everything = [...descendants(root)];
206
+ const onScreen = [...descendants(root, isLayer)].filter((node) => isCard(node) && !isLayer(node));
207
+ const screenTitles = new Set(onScreen.map(titleOf).filter(Boolean));
208
+ const openSheets = everything.filter((node) => isSheet(node) && !isGone(node));
209
+ const sheetCards = new Set(openSheets.flatMap((sheet) => [sheet, ...[...descendants(sheet, isSheet)].filter((node) => isCard(node) && !isModal(node))]));
210
+ return [...sheetCards]
211
+ .filter((card) => screenTitles.has(titleOf(card)))
212
+ .map((card) => found(card, `repeats the card "${titleOf(card)}" on the screen under the sheet: more of what the member is looking at opens where it is (Card folds), a sheet is for what they write or fill in`));
213
+ };
214
+
215
+ const auditPage = (root) => [...layersOverScreen(root), ...menuButtonsWithoutChevron(root), ...sheetCardsRepeatingScreen(root)];
216
+
217
+ const partsOf = (card) => {
218
+ const inside = [...descendants(card, (node) => isCard(node) || hasClass(node, 'menu'))];
219
+ const foot = inside.find((node) => hasClass(node, 'foot'));
220
+ const buttons = foot ? [...descendants(foot, (node) => hasClass(node, 'menu'))].filter(isButton).length : 0;
221
+ return [
222
+ 'head',
223
+ inside.some((node) => hasClass(node, 'note-row')) && 'NoteRow',
224
+ inside.some((node) => hasClass(node, 'rows')) && 'Rows',
225
+ foot && `foot with ${buttons} ${buttons === 1 ? 'button' : 'buttons'}`,
226
+ ].filter(Boolean).join(' · ');
227
+ };
228
+
229
+ const firstCardOfEachTitle = (root) => {
230
+ const cards = new Map();
231
+ for (const node of descendants(root)) {
232
+ const title = isCard(node) ? titleOf(node) : '';
233
+ if (title && !cards.has(title)) cards.set(title, node);
234
+ }
235
+ return cards;
236
+ };
237
+
238
+ const partsChangingAcrossPages = (pages) => {
239
+ const firstSeen = new Map();
240
+ return pages.flatMap(({ name, root }) => [...firstCardOfEachTitle(root)].flatMap(([title, card]) => {
241
+ const parts = partsOf(card);
242
+ const before = firstSeen.get(title);
243
+ if (!before) {
244
+ firstSeen.set(title, { page: name, parts });
245
+ return [];
246
+ }
247
+ if (before.parts === parts) return [];
248
+ return [onPage(found(card, `"${title}" has ${parts} here but ${before.parts} on ${before.page}: one thing keeps the same parts on every page`), name)];
249
+ }));
250
+ };
251
+
252
+ const pageName = (page, index) => (typeof page.name === 'string' && page.name ? page.name : `page ${index + 1}`);
253
+
254
+ export const screen = (html) => auditPage(parse(html));
255
+
256
+ export function flow(pages) {
257
+ const parsed = pages.map((page, index) => ({ name: pageName(page, index), root: parse(page.html) }));
258
+ return [
259
+ ...parsed.flatMap(({ name, root }) => auditPage(root).map((item) => onPage(item, name))),
260
+ ...partsChangingAcrossPages(parsed),
261
+ ];
262
+ }
263
+
264
+ const withoutMarks = (text) => text.replace(/\*\*/g, '').replace(/\s+/g, ' ').trim();
265
+
266
+ const rulesIn = (markdown) => {
267
+ const lines = markdown.split('\n');
268
+ const start = lines.findIndex((line) => line.startsWith(RULES_HEADING));
269
+ if (start < 0) return [];
270
+ const length = lines.slice(start + 1).findIndex((line) => line.startsWith('## '));
271
+ const section = lines.slice(start + 1, length < 0 ? undefined : start + 1 + length);
272
+ const rules = [];
273
+ let current = null;
274
+ for (const line of section) {
275
+ const heading = /^(\d+)\.\s+\*\*(.+?)\*\*\s?(.*)$/.exec(line);
276
+ if (heading) {
277
+ current = { number: Number(heading[1]), name: heading[2].replace(/\.$/, ''), lines: [heading[3]] };
278
+ rules.push(current);
279
+ } else if (current && (line.trim() === '' || /^\s/.test(line))) current.lines.push(line);
280
+ else current = null;
281
+ }
282
+ return rules;
283
+ };
284
+
285
+ const blocksIn = (lines) => {
286
+ const blocks = [];
287
+ let open = null;
288
+ let fenced = false;
289
+ for (const line of lines) {
290
+ if (/^\s*```/.test(line)) {
291
+ fenced = !fenced;
292
+ open = null;
293
+ } else if (fenced) continue;
294
+ else if (line.trim() === '') open = null;
295
+ else if (/^\s*[-*]\s+/.test(line)) {
296
+ open = { bullet: true, text: line.replace(/^\s*[-*]\s+/, '') };
297
+ blocks.push(open);
298
+ } else if (open) open.text += ` ${line.trim()}`;
299
+ else {
300
+ open = { bullet: false, text: line.trim() };
301
+ blocks.push(open);
302
+ }
303
+ }
304
+ return blocks;
305
+ };
306
+
307
+ const questionFor = (block, index) => {
308
+ const text = withoutMarks(block.text);
309
+ const labelled = block.bullet ? /^\*\*(.+?)\*\*\s*(.*)$/.exec(block.text) : null;
310
+ if (labelled) return `${labelled[1].replace(/\.$/, '')}: does the picture do this? ${withoutMarks(labelled[2])}`;
311
+ if (block.bullet) return `Does the picture do this? ${text}`;
312
+ if (/^The check\b/.test(text)) return `How to check: ${text.replace(/^The check\s*/, '')}`;
313
+ return index === 0 ? `Does the picture keep this? ${text}` : `Does the picture keep this too? ${text}`;
314
+ };
315
+
316
+ export const questions = (markdown = readFileSync(REFERENCE_FILE, 'utf8')) => rulesIn(markdown).map((rule) => ({
317
+ rule: rule.number,
318
+ name: rule.name,
319
+ questions: blocksIn(rule.lines).map(questionFor),
320
+ }));
321
+
322
+ export function audit({ html, pages } = {}) {
323
+ if (html !== undefined && pages !== undefined) return { error: 'give html (one page) or pages (a flow), not both' };
324
+ if (pages !== undefined) {
325
+ const listed = Array.isArray(pages) && pages.every((page) => typeof page?.html === 'string');
326
+ return listed ? flow(pages) : { error: 'pages is an array of { name, html }, each html a string' };
327
+ }
328
+ if (html === undefined) return questions();
329
+ return typeof html === 'string' ? screen(html) : { error: 'html is a string: the rendered DOM of one page' };
330
+ }
package/lib/guide.mjs CHANGED
@@ -4,7 +4,7 @@
4
4
  // not here — they are in its JSDoc (get_component) and in lint/rules.mjs.
5
5
  export const GUIDE = `cardds — BEFORE drawing any phone-width / mobile screen in a project with @usableapp/cardds, or that Lh asks to build "with cardds": load these tools (ToolSearch "cardds" if deferred) and call find_components. Even when the request only says prototype, poc, mock-up, sketch, "show me a design", หน้า, หน้าจอ, ขึ้นหน้า, ขอดู prototype — a screen, card, bottom sheet, sheet stack, form step, sticky note / post-it, chat of notes, stamp, postcard, home. Never hand-write HTML, CSS or emoji for what it has.
6
6
  ORDER: find → scaffold or get → write. First question: has cardds drawn this screen already? find BOTH ways: by the axes (represents · shape · interact) and by the task's English noun ("sticky", "stamp", "chat").
7
- TOOLS: find_components · scaffold_screen · get_component · list_components. No MCP: npx cardds find|scaffold|get|list --json. check / check_source: a person's tool, never a session's step.
7
+ TOOLS: find_components · scaffold_screen · get_component · list_components. No MCP: npx cardds find|scaffold|get|list --json. check / check_source: a person's tool, never a session's step. audit_screen (npx cardds audit): a screen drawn, as a picture or as the rendered DOM of a page or a flow, against the rules of the system.
8
8
  What no checker sees:
9
9
  1. cardds is a framework you take from outside. Never edit or release cardds, or node_modules, from a consumer project. What cannot be set from outside is a framework gap: STOP, tell the user what you needed.
10
10
  2. Adjust from outside only, widest first: theme.css bases → knobs (--<component>-<what>) → props/slots. Theme values are the user's call, never yours. cardGrounds() / inkGrounds() name a card or a word the member cannot see (docs/reference.md).