@slashsuite/ui-react 0.13.0 → 0.13.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/Button.d.ts CHANGED
@@ -12,9 +12,10 @@ export type ButtonSize = Size;
12
12
  export type ButtonTone = Extract<Tone, "neutral" | "positive" | "danger">;
13
13
  /** The padding table and its `md:` twin, for the data test. */
14
14
  export declare const buttonSizeTables: {
15
- box: Record<Size, string>;
16
- boxMd: Record<Size, string>;
15
+ box: Record<import("./core/index.js").ButtonSize, string>;
16
+ boxMd: Record<import("./core/index.js").ButtonSize, string>;
17
17
  };
18
+ /** The count chip's classes (a Badge's size, in the button's own text colour). */
18
19
  export declare const COUNT = "inline-flex min-h-4 min-w-4 items-center justify-center rounded-full border border-current px-1 text-[0.625rem]/[1.4] font-semibold tabular-nums";
19
20
  /** Size, tone and variant: the look of a button, apart from its state. */
20
21
  type ButtonLook = {
package/dist/Button.js CHANGED
@@ -1,102 +1,23 @@
1
1
  import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { BUTTON_BLOCKED, BUTTON_BLOCKED_BY_VARIANT, BUTTON_BOX, BUTTON_BOX_MD, BUTTON_BUSY, BUTTON_COUNT, BUTTON_DASHED_BOX, BUTTON_DISABLED_PLAIN, BUTTON_LINK_GAP, BUTTON_SHAPE, buttonLook, } from "./core/index.js";
2
3
  import { cx, focusRing } from "./cx.js";
3
4
  import { controlText, useResponsiveDensity, useTypeStep } from "./density.js";
4
5
  import { Icon } from "./Icon.js";
5
6
  import { hasReason, useBlocked } from "./blocked.js";
6
7
  import { renderLink } from "./link.js";
7
8
  import { sizeClass } from "./size.js";
8
- const SHAPE = "inline-flex items-center justify-center rounded-lg border font-medium transition";
9
- // Size sets the padding; the text is `controlText`'s, from the size and the type step. The link
10
- // variant has no box, so it takes the text size only.
11
- const BOX = {
12
- sm: "gap-1.5 px-2.5 py-1",
13
- md: "gap-2 px-4 py-2",
14
- lg: "gap-2 px-5 py-2.5",
15
- };
16
- // `BOX` from the `md` breakpoint up, for a responsive size, every class written out in full.
17
- const BOX_MD = {
18
- sm: "md:gap-1.5 md:px-2.5 md:py-1",
19
- md: "md:gap-2 md:px-4 md:py-2",
20
- lg: "md:gap-2 md:px-5 md:py-2.5",
21
- };
22
9
  /** The padding table and its `md:` twin, for the data test. */
23
- export const buttonSizeTables = { box: BOX, boxMd: BOX_MD };
24
- // A plain `disabled` washes out and ignores the pointer. A busy button is disabled too, but keeps
25
- // pointer events (the cursor says why) and does not take this; a blocked one is `aria-disabled`.
26
- const DISABLED_PLAIN = "disabled:pointer-events-none disabled:opacity-50";
27
- const LINK = "underline-offset-2";
28
- const TONE = {
29
- neutral: {
30
- primary: {
31
- color: "border-violet-600 bg-violet-600 text-violet-50",
32
- hover: "hover:bg-violet-700",
33
- },
34
- outline: { color: "border-violet-600 text-violet-600", hover: "hover:bg-violet-50" },
35
- ghost: { color: "border-transparent text-slate-600", hover: "hover:bg-slate-100" },
36
- link: {
37
- color: `border-transparent text-violet-600 ${LINK}`,
38
- hover: "hover:text-violet-700 hover:underline",
39
- },
40
- },
41
- positive: {
42
- primary: {
43
- color: "border-emerald-600 bg-emerald-600 text-emerald-50",
44
- hover: "hover:bg-emerald-700",
45
- },
46
- outline: { color: "border-emerald-200 text-emerald-700", hover: "hover:bg-emerald-50" },
47
- ghost: { color: "border-transparent text-emerald-700", hover: "hover:bg-emerald-50" },
48
- link: { color: `border-transparent text-emerald-700 ${LINK}`, hover: "hover:underline" },
49
- },
50
- danger: {
51
- primary: { color: "border-red-600 bg-red-600 text-red-50", hover: "hover:bg-red-700" },
52
- outline: { color: "border-red-200 text-red-700", hover: "hover:bg-red-50" },
53
- ghost: { color: "border-transparent text-red-700", hover: "hover:bg-red-50" },
54
- link: { color: `border-transparent text-red-700 ${LINK}`, hover: "hover:underline" },
55
- },
56
- };
57
- // The add row: Card dashed's outline and muted text, lit with the accent on hover. One look, so
58
- // `tone` does not apply to it.
59
- const DASHED = {
60
- color: "border-slate-300 text-slate-500",
61
- hover: "hover:border-violet-400 hover:text-violet-700",
62
- };
63
- // An outline or ghost Button with `pressed` set is a toggle, such as a filter chip: off is neutral
64
- // (the surface, a hairline, muted text, lit with the accent on hover), on is the tone's primary
65
- // fill, so the selected one stands out in every theme. A primary is already filled, and link and
66
- // dashed have no selected state; with `pressed` left out, outline and ghost keep their own look.
67
- const TOGGLE_OFF = {
68
- color: "border-slate-200 bg-white text-slate-600",
69
- hover: "hover:border-violet-400",
70
- };
71
- // The count chip: a pill in the button's own text colour (a hairline of `currentColor`), so it reads
72
- // on every variant and tone and needs no palette entry. The size is a Badge's: rem text and a
73
- // min-height, so the chip grows with the reader's text size.
74
- export const COUNT = "inline-flex min-h-4 min-w-4 items-center justify-center rounded-full border border-current px-1 text-[0.625rem]/[1.4] font-semibold tabular-nums";
10
+ export const buttonSizeTables = { box: BUTTON_BOX, boxMd: BUTTON_BOX_MD };
11
+ /** The count chip's classes (a Badge's size, in the button's own text colour). */
12
+ export const COUNT = BUTTON_COUNT;
75
13
  /** The label, then the count chip. The comma is for a screen reader only, so the name reads "Splits, 3". */
76
14
  function withCount(children, count) {
77
15
  if (count === undefined)
78
16
  return children;
79
17
  return (_jsxs(_Fragment, { children: [children, _jsx("span", { className: "sr-only", children: ", " }), _jsx("span", { className: COUNT, children: count })] }));
80
18
  }
81
- function lookOf(variant, tone, pressed) {
82
- if (variant === "dashed")
83
- return DASHED;
84
- if (pressed !== undefined && (variant === "outline" || variant === "ghost")) {
85
- return pressed ? TONE[tone].primary : TOGGLE_OFF;
86
- }
87
- return TONE[tone][variant];
88
- }
89
- // Blocked replaces the variant's colour and hover rather than overriding them, so no `!` is needed.
90
- const BLOCKED = "cursor-not-allowed border-slate-200 bg-slate-100 text-slate-400";
91
- const BLOCKED_DASHED = "cursor-not-allowed border-slate-200 text-slate-400";
92
- const BLOCKED_LINK = "cursor-not-allowed border-transparent text-slate-400";
93
- const BLOCKED_BY_VARIANT = {
94
- link: BLOCKED_LINK,
95
- dashed: BLOCKED_DASHED,
96
- };
97
- const BUSY = "cursor-progress opacity-85";
98
19
  function shape(variant, size, step) {
99
- return cx(SHAPE, variant !== "link" && sizeClass(BOX, BOX_MD, size), variant === "link" && "gap-1.5", variant === "dashed" && "w-full border-dashed", controlText(size, step, false), focusRing);
20
+ return cx(BUTTON_SHAPE, variant !== "link" && sizeClass(BUTTON_BOX, BUTTON_BOX_MD, size), variant === "link" && BUTTON_LINK_GAP, variant === "dashed" && BUTTON_DASHED_BOX, controlText(size, step, false), focusRing);
100
21
  }
101
22
  /** The classes of an idle Button: what `href` draws, and what the tests compare against. */
102
23
  export function buttonClass(variant = "primary", { size = "md", tone = "neutral" } = {}, step) {
@@ -110,8 +31,8 @@ export function blockedButtonClass(variant = "primary", { size = "md" } = {}, st
110
31
  return stateClass({ variant, size }, "blocked", undefined, step);
111
32
  }
112
33
  function idleClass(variant, size, tone, { step, pressed }) {
113
- const look = lookOf(variant, tone, pressed);
114
- return cx(shape(variant, size, step), "cursor-pointer", DISABLED_PLAIN, look.color, look.hover);
34
+ const look = buttonLook(variant, tone, pressed);
35
+ return cx(shape(variant, size, step), "cursor-pointer", BUTTON_DISABLED_PLAIN, look.color, look.hover);
115
36
  }
116
37
  function isLink(props) {
117
38
  return props.href !== undefined;
@@ -125,10 +46,10 @@ function stateOf(busy, disabledReason) {
125
46
  /** The classes of a Button in a given state: blocked swaps the colour out, busy keeps it. */
126
47
  function stateClass({ variant = "primary", size = "md", tone = "neutral" }, state, pressed, step) {
127
48
  if (state === "blocked") {
128
- return cx(shape(variant, size, step), BLOCKED_BY_VARIANT[variant] ?? BLOCKED);
49
+ return cx(shape(variant, size, step), BUTTON_BLOCKED_BY_VARIANT[variant] ?? BUTTON_BLOCKED);
129
50
  }
130
51
  if (state === "busy") {
131
- return cx(shape(variant, size, step), lookOf(variant, tone, pressed).color, BUSY);
52
+ return cx(shape(variant, size, step), buttonLook(variant, tone, pressed).color, BUTTON_BUSY);
132
53
  }
133
54
  return idleClass(variant, size, tone, { step, pressed });
134
55
  }
@@ -3,7 +3,7 @@ import { useState } from "react";
3
3
  import { FlowView } from "./FlowDiagram.js";
4
4
  import { Pill } from "./Pill.js";
5
5
  import { Bone, BusyLabel, busy, useLoading } from "./skeleton.js";
6
- import { COLS, dotLayer, placeOf, SLOT_H, SLOT_W, slotsFor, UNPLACED, useMoves, } from "./stateMachineDots.js";
6
+ import { boxContentSize, dotArea, dotLayer, placeOf, slotsFor, UNPLACED, useMoves, } from "./stateMachineDots.js";
7
7
  import { useFlowLayout } from "./useFlowLayout.js";
8
8
  /** Each kind's box tone, and the tag that says it in words. */
9
9
  const KIND_TONE = {
@@ -20,20 +20,21 @@ const KIND_TAG = {
20
20
  terminal: { text: "end", tone: "neutral" },
21
21
  failed: { text: "failed", tone: "danger" },
22
22
  };
23
- /** A box's tags: what kind of state it is, who owns it, and how many items it holds. */
23
+ /**
24
+ * A box's tags: what kind of state it is, who owns it, and how many items it holds. The row is
25
+ * always there: a box with no items keeps an invisible count tag in it, so an empty box and a full
26
+ * one are the same height.
27
+ */
24
28
  function boxTags(tag, owner, count) {
25
- if (!tag && !owner && count === 0)
26
- return null;
27
- return (_jsxs("span", { className: "flex flex-wrap items-center justify-center gap-1", children: [tag && (_jsx(Pill, { size: "sm", tone: tag.tone, children: tag.text })), owner && _jsx(Pill, { size: "sm", children: owner }), count > 0 && (_jsx(Pill, { size: "sm", tone: "accent", dot: true, children: count === 1 ? "1 item" : `${count} items` }))] }));
29
+ return (_jsxs("span", { className: "flex flex-wrap items-center justify-center gap-1", children: [tag && (_jsx(Pill, { size: "sm", tone: tag.tone, children: tag.text })), owner && _jsx(Pill, { size: "sm", children: owner }), count > 0 ? (_jsx(Pill, { size: "sm", tone: "accent", dot: true, children: count === 1 ? "1 item" : `${count} items` })) : (_jsx("span", { "aria-hidden": "true", className: "flex invisible", children: _jsx(Pill, { size: "sm", tone: "accent", dot: true, children: "0 items" }) }))] }));
28
30
  }
29
- /** What a box holds under its label: its tags and the room its dots take. */
31
+ /**
32
+ * What a box holds under its label: its tags, and the dot area it always reserves (the full grid,
33
+ * even empty), so a box keeps its size whatever its item count.
34
+ */
30
35
  function boxContent(state, count, slots) {
31
36
  const tags = boxTags(state ? KIND_TAG[state.kind ?? "normal"] : null, state?.owner, count);
32
- if (tags === null)
33
- return undefined;
34
- const cols = Math.min(COLS, slots);
35
- const rows = Math.ceil(slots / COLS);
36
- return (_jsxs(_Fragment, { children: [tags, slots > 0 && (_jsx("span", { "aria-hidden": "true", className: "mx-auto mt-1 block", style: { width: cols * SLOT_W, height: rows * SLOT_H } }))] }));
37
+ return (_jsxs(_Fragment, { children: [tags, _jsx("span", { "aria-hidden": "true", className: "mx-auto mt-1 block", style: dotArea(slots) })] }));
37
38
  }
38
39
  /** The items each box holds: its state's, and the unplaced box's for an unknown state. */
39
40
  function itemsByBox(items, known) {
@@ -53,6 +54,7 @@ function boxesFor(states, inBox, open) {
53
54
  label: s.label,
54
55
  tone: KIND_TONE[s.kind ?? "normal"],
55
56
  content: boxContent(s, inBox.get(s.id)?.length ?? 0, slots(s.id)),
57
+ contentSize: boxContentSize(slots(s.id)),
56
58
  }));
57
59
  const unplaced = inBox.get(UNPLACED)?.length ?? 0;
58
60
  if (unplaced === 0)
@@ -64,6 +66,7 @@ function boxesFor(states, inBox, open) {
64
66
  label: "Not in any state",
65
67
  tone: "warn",
66
68
  content: boxContent(null, unplaced, slots(UNPLACED)),
69
+ contentSize: boxContentSize(slots(UNPLACED)),
67
70
  },
68
71
  ];
69
72
  }
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Button's tokens: the class tables `@slashsuite/ui-react` draws a Button from, and the sizes the
3
+ * native renderer measures against. The tables are the web's (Tailwind utilities, remapped by every
4
+ * theme); `parity.ts` reads the box sizes from them, so a change here moves both renderers.
5
+ */
6
+ /** A Button's look: `primary` the one main action, `outline` and `ghost` the others, `link` text in running text, `dashed` the add-another row. */
7
+ export type ButtonVariant = "primary" | "outline" | "ghost" | "link" | "dashed";
8
+ /** A Button's height and text, on the library's one size scale. */
9
+ export type ButtonSize = "sm" | "md" | "lg";
10
+ /** A Button's tones: `neutral` (the accent fill, the default), `positive` and `danger`. */
11
+ export type ButtonTone = "neutral" | "positive" | "danger";
12
+ /** A colour and its hover, as two class strings. */
13
+ export type ButtonLook = {
14
+ color: string;
15
+ hover: string;
16
+ };
17
+ export declare const BUTTON_SHAPE = "inline-flex items-center justify-center rounded-lg border font-medium transition";
18
+ export declare const BUTTON_BOX: Record<ButtonSize, string>;
19
+ export declare const BUTTON_BOX_MD: Record<ButtonSize, string>;
20
+ /** The gap of the link variant, which has no box. */
21
+ export declare const BUTTON_LINK_GAP = "gap-1.5";
22
+ /** The dashed variant fills its container. */
23
+ export declare const BUTTON_DASHED_BOX = "w-full border-dashed";
24
+ export declare const BUTTON_DISABLED_PLAIN = "disabled:pointer-events-none disabled:opacity-50";
25
+ export declare const BUTTON_TONE: Record<ButtonTone, Record<Exclude<ButtonVariant, "dashed">, ButtonLook>>;
26
+ export declare const BUTTON_DASHED: ButtonLook;
27
+ export declare const BUTTON_TOGGLE_OFF: ButtonLook;
28
+ export declare const BUTTON_COUNT = "inline-flex min-h-4 min-w-4 items-center justify-center rounded-full border border-current px-1 text-[0.625rem]/[1.4] font-semibold tabular-nums";
29
+ export declare const BUTTON_BLOCKED = "cursor-not-allowed border-slate-200 bg-slate-100 text-slate-400";
30
+ export declare const BUTTON_BLOCKED_BY_VARIANT: Partial<Record<ButtonVariant, string>>;
31
+ export declare const BUTTON_BUSY = "cursor-progress opacity-85";
32
+ /** The look of an idle Button: the dashed look, a toggle's, or the tone's for the variant. */
33
+ export declare function buttonLook(variant: ButtonVariant, tone: ButtonTone, pressed?: boolean): ButtonLook;
@@ -0,0 +1,89 @@
1
+ /**
2
+ * Button's tokens: the class tables `@slashsuite/ui-react` draws a Button from, and the sizes the
3
+ * native renderer measures against. The tables are the web's (Tailwind utilities, remapped by every
4
+ * theme); `parity.ts` reads the box sizes from them, so a change here moves both renderers.
5
+ */
6
+ export const BUTTON_SHAPE = "inline-flex items-center justify-center rounded-lg border font-medium transition";
7
+ // Size sets the padding; the text is the renderer's control text, from the size and the type step.
8
+ // The link variant has no box, so it takes the text size only.
9
+ export const BUTTON_BOX = {
10
+ sm: "gap-1.5 px-2.5 py-1",
11
+ md: "gap-2 px-4 py-2",
12
+ lg: "gap-2 px-5 py-2.5",
13
+ };
14
+ // `BUTTON_BOX` from the `md` breakpoint up, for a responsive size, every class written out in full.
15
+ export const BUTTON_BOX_MD = {
16
+ sm: "md:gap-1.5 md:px-2.5 md:py-1",
17
+ md: "md:gap-2 md:px-4 md:py-2",
18
+ lg: "md:gap-2 md:px-5 md:py-2.5",
19
+ };
20
+ /** The gap of the link variant, which has no box. */
21
+ export const BUTTON_LINK_GAP = "gap-1.5";
22
+ /** The dashed variant fills its container. */
23
+ export const BUTTON_DASHED_BOX = "w-full border-dashed";
24
+ // A plain `disabled` washes out and ignores the pointer. A busy button is disabled too, but keeps
25
+ // pointer events (the cursor says why) and does not take this; a blocked one is `aria-disabled`.
26
+ export const BUTTON_DISABLED_PLAIN = "disabled:pointer-events-none disabled:opacity-50";
27
+ const LINK = "underline-offset-2";
28
+ export const BUTTON_TONE = {
29
+ neutral: {
30
+ primary: {
31
+ color: "border-violet-600 bg-violet-600 text-violet-50",
32
+ hover: "hover:bg-violet-700",
33
+ },
34
+ outline: { color: "border-violet-600 text-violet-600", hover: "hover:bg-violet-50" },
35
+ ghost: { color: "border-transparent text-slate-600", hover: "hover:bg-slate-100" },
36
+ link: {
37
+ color: `border-transparent text-violet-600 ${LINK}`,
38
+ hover: "hover:text-violet-700 hover:underline",
39
+ },
40
+ },
41
+ positive: {
42
+ primary: {
43
+ color: "border-emerald-600 bg-emerald-600 text-emerald-50",
44
+ hover: "hover:bg-emerald-700",
45
+ },
46
+ outline: { color: "border-emerald-200 text-emerald-700", hover: "hover:bg-emerald-50" },
47
+ ghost: { color: "border-transparent text-emerald-700", hover: "hover:bg-emerald-50" },
48
+ link: { color: `border-transparent text-emerald-700 ${LINK}`, hover: "hover:underline" },
49
+ },
50
+ danger: {
51
+ primary: { color: "border-red-600 bg-red-600 text-red-50", hover: "hover:bg-red-700" },
52
+ outline: { color: "border-red-200 text-red-700", hover: "hover:bg-red-50" },
53
+ ghost: { color: "border-transparent text-red-700", hover: "hover:bg-red-50" },
54
+ link: { color: `border-transparent text-red-700 ${LINK}`, hover: "hover:underline" },
55
+ },
56
+ };
57
+ // The add row: Card dashed's outline and muted text, lit with the accent on hover. One look, so
58
+ // `tone` does not apply to it.
59
+ export const BUTTON_DASHED = {
60
+ color: "border-slate-300 text-slate-500",
61
+ hover: "hover:border-violet-400 hover:text-violet-700",
62
+ };
63
+ // An outline or ghost Button with `pressed` set is a toggle, such as a filter chip: off is neutral
64
+ // (the surface, a hairline, muted text, lit with the accent on hover), on is the tone's primary
65
+ // fill, so the selected one stands out in every theme.
66
+ export const BUTTON_TOGGLE_OFF = {
67
+ color: "border-slate-200 bg-white text-slate-600",
68
+ hover: "hover:border-violet-400",
69
+ };
70
+ // The count chip: a pill in the button's own text colour (a hairline of `currentColor`), so it reads
71
+ // on every variant and tone and needs no palette entry. The size is a Badge's: rem text and a
72
+ // min-height, so the chip grows with the reader's text size.
73
+ export const BUTTON_COUNT = "inline-flex min-h-4 min-w-4 items-center justify-center rounded-full border border-current px-1 text-[0.625rem]/[1.4] font-semibold tabular-nums";
74
+ // Blocked replaces the variant's colour and hover rather than overriding them, so no `!` is needed.
75
+ export const BUTTON_BLOCKED = "cursor-not-allowed border-slate-200 bg-slate-100 text-slate-400";
76
+ export const BUTTON_BLOCKED_BY_VARIANT = {
77
+ link: "cursor-not-allowed border-transparent text-slate-400",
78
+ dashed: "cursor-not-allowed border-slate-200 text-slate-400",
79
+ };
80
+ export const BUTTON_BUSY = "cursor-progress opacity-85";
81
+ /** The look of an idle Button: the dashed look, a toggle's, or the tone's for the variant. */
82
+ export function buttonLook(variant, tone, pressed) {
83
+ if (variant === "dashed")
84
+ return BUTTON_DASHED;
85
+ if (pressed !== undefined && (variant === "outline" || variant === "ghost")) {
86
+ return pressed ? BUTTON_TONE[tone].primary : BUTTON_TOGGLE_OFF;
87
+ }
88
+ return BUTTON_TONE[tone][variant];
89
+ }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * A control's text: its type size by `size` at each type step, and its line height by `size`. A
3
+ * Button, a field and a pill take their text from here on every renderer, so a control's height
4
+ * (line height, padding and hairline) is the same on the web and on a phone.
5
+ */
6
+ import type { ButtonSize } from "./button.js";
7
+ /** The type step an app may set once: `compact` is one step down, for an app's chrome. */
8
+ export type ControlTypeStep = "default" | "compact";
9
+ /** A control's type size at each step: `md` is 16px at the default step, and `compact` is one step down. */
10
+ export declare const CONTROL_TEXT: Record<ControlTypeStep, Record<ButtonSize, string>>;
11
+ /**
12
+ * A control's line height by `size`, whatever its type step: 16, 20 and 24px, so with its padding
13
+ * every control is 26, 38 and 46px tall at both steps.
14
+ */
15
+ export declare const CONTROL_LEADING: Record<ButtonSize, string>;
@@ -0,0 +1,14 @@
1
+ /** A control's type size at each step: `md` is 16px at the default step, and `compact` is one step down. */
2
+ export const CONTROL_TEXT = {
3
+ default: { sm: "text-sm", md: "text-base", lg: "text-lg" },
4
+ compact: { sm: "text-xs", md: "text-sm", lg: "text-base" },
5
+ };
6
+ /**
7
+ * A control's line height by `size`, whatever its type step: 16, 20 and 24px, so with its padding
8
+ * every control is 26, 38 and 46px tall at both steps.
9
+ */
10
+ export const CONTROL_LEADING = {
11
+ sm: "leading-4",
12
+ md: "leading-5",
13
+ lg: "leading-6",
14
+ };
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Button's story fixtures: the stories both renderers draw from the same data, so a web story and
3
+ * its native shot share one story id (`actions-button--variants`). Each is a row of Buttons; the
4
+ * renderer lays the row out by `layout` and draws each item with its own Button.
5
+ */
6
+ import type { ButtonSize, ButtonTone, ButtonVariant } from "../button.js";
7
+ import type { StoryFixture } from "./types.js";
8
+ /** One Button in a fixture: its label and the props that change its look or state. */
9
+ export type ButtonFixtureItem = {
10
+ label: string;
11
+ variant?: ButtonVariant;
12
+ size?: ButtonSize;
13
+ tone?: ButtonTone;
14
+ pressed?: boolean;
15
+ disabledReason?: string;
16
+ busy?: boolean | string;
17
+ };
18
+ export declare const buttonFixtures: {
19
+ Variants: StoryFixture<ButtonFixtureItem>;
20
+ Small: StoryFixture<ButtonFixtureItem>;
21
+ Danger: StoryFixture<ButtonFixtureItem>;
22
+ Positive: StoryFixture<ButtonFixtureItem>;
23
+ Pressed: StoryFixture<ButtonFixtureItem>;
24
+ Blocked: StoryFixture<ButtonFixtureItem>;
25
+ Busy: StoryFixture<ButtonFixtureItem>;
26
+ };
@@ -0,0 +1,52 @@
1
+ const TITLE = "Actions/Button";
2
+ const fixture = (story, layout, items) => ({ title: TITLE, story, layout, items });
3
+ export const buttonFixtures = {
4
+ Variants: fixture("Variants", "wrap", [
5
+ { label: "Save" },
6
+ { label: "Cancel", variant: "outline" },
7
+ { label: "Skip", variant: "ghost" },
8
+ { label: "Edit", variant: "link" },
9
+ ]),
10
+ Small: fixture("Small", "wrap-center", [
11
+ { label: "Save", size: "sm" },
12
+ { label: "Cancel", size: "sm", variant: "outline" },
13
+ { label: "Skip", size: "sm", variant: "ghost" },
14
+ { label: "Edit", size: "sm", variant: "link" },
15
+ { label: "Remove", size: "sm", tone: "danger", variant: "outline" },
16
+ ]),
17
+ Danger: fixture("Danger", "wrap-center", [
18
+ { label: "Delete", tone: "danger" },
19
+ { label: "Clear", tone: "danger", variant: "outline" },
20
+ { label: "Remove", tone: "danger", variant: "ghost" },
21
+ { label: "Remove", tone: "danger", variant: "link" },
22
+ { label: "Delete", tone: "danger", size: "sm" },
23
+ { label: "Blocked", tone: "danger", disabledReason: "Nothing to delete" },
24
+ { label: "Delete", tone: "danger", busy: "Deleting…" },
25
+ ]),
26
+ Positive: fixture("Positive", "wrap-center", [
27
+ { label: "Accept", tone: "positive" },
28
+ { label: "Accept", tone: "positive", variant: "outline" },
29
+ { label: "Accept", tone: "positive", variant: "ghost" },
30
+ { label: "Accept", tone: "positive", variant: "link" },
31
+ { label: "Accept", tone: "positive", size: "sm" },
32
+ { label: "Blocked", tone: "positive", disabledReason: "Nothing to accept" },
33
+ { label: "Accept", tone: "positive", busy: "Accepting…" },
34
+ ]),
35
+ Pressed: fixture("Pressed", "wrap-center", [
36
+ { label: "Flag", variant: "outline", pressed: false },
37
+ { label: "Flag", variant: "outline", pressed: true },
38
+ { label: "Flag", variant: "ghost", pressed: true },
39
+ { label: "Accepted", variant: "outline", tone: "positive", pressed: true },
40
+ { label: "Rejected", variant: "outline", tone: "danger", pressed: true },
41
+ ]),
42
+ Blocked: fixture("Blocked", "wrap", [
43
+ { label: "Save", disabledReason: "Pick a shop first" },
44
+ { label: "Cancel", variant: "outline", disabledReason: "Pick a shop first" },
45
+ { label: "Skip", variant: "ghost", disabledReason: "Pick a shop first" },
46
+ ]),
47
+ Busy: fixture("Busy", "wrap", [
48
+ { label: "Save", busy: "Saving…" },
49
+ { label: "Cancel", variant: "outline", busy: "Cancelling…" },
50
+ { label: "Skip", variant: "ghost", busy: true },
51
+ ]),
52
+ };
@@ -0,0 +1,13 @@
1
+ /**
2
+ * A story fixture: a story as data, which every renderer draws. `title` and `story` give the story
3
+ * id both renderers use (`storyId`), and `layout` how the items sit: `wrap` a wrapping row with the
4
+ * standard gap, `wrap-center` the same row with its items centred on the cross axis.
5
+ */
6
+ export type StoryFixture<Item> = {
7
+ title: string;
8
+ story: string;
9
+ layout: "wrap" | "wrap-center";
10
+ items: Item[];
11
+ };
12
+ /** Storybook's id for a story: `Actions/Button` and `Variants` give `actions-button--variants`. */
13
+ export declare function storyId(title: string, story: string): string;
@@ -0,0 +1,10 @@
1
+ /** Storybook's slug of a title or a story name: camelCase split, lower-cased, hyphenated. */
2
+ const slug = (text) => text
3
+ .replace(/([a-z\d])([A-Z])/g, "$1-$2")
4
+ .toLowerCase()
5
+ .replace(/[^a-z\d]+/g, "-")
6
+ .replace(/^-|-$/g, "");
7
+ /** Storybook's id for a story: `Actions/Button` and `Variants` give `actions-button--variants`. */
8
+ export function storyId(title, story) {
9
+ return `${slug(title)}--${slug(story)}`;
10
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * The keyboard focus ring every interactive control shares, on every renderer: a 2px accent
3
+ * outline 2px out. `FOCUS_RING_INSET` draws it inside, for a control that fills a box which clips
4
+ * anything outside it (a table's sortable title, a scroller).
5
+ */
6
+ export declare const FOCUS_RING = "focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-violet-600";
7
+ export declare const FOCUS_RING_INSET = "focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-violet-600";
@@ -0,0 +1,7 @@
1
+ /**
2
+ * The keyboard focus ring every interactive control shares, on every renderer: a 2px accent
3
+ * outline 2px out. `FOCUS_RING_INSET` draws it inside, for a control that fills a box which clips
4
+ * anything outside it (a table's sortable title, a scroller).
5
+ */
6
+ export const FOCUS_RING = "focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-violet-600";
7
+ export const FOCUS_RING_INSET = "focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-violet-600";
@@ -0,0 +1,12 @@
1
+ /**
2
+ * `@slashsuite/core`: what every UISlash renderer shares. The token tables and prop types of the
3
+ * components that have moved here, their story fixtures, the parity manifest built from the
4
+ * tables, and the native theme generator. Pure TypeScript, no runtime dependencies.
5
+ */
6
+ export * from "./button.js";
7
+ export { buttonFixtures, type ButtonFixtureItem } from "./fixtures/button.js";
8
+ export { storyId, type StoryFixture } from "./fixtures/types.js";
9
+ export { parityJson, parityManifest, radiusPx, spacingPx, type BoxMetrics, type ParityManifest, } from "./parity.js";
10
+ export { missingFromNative, nativeTheme, nativeThemeJson, STATE_OF_VARIANT, type NativeCompound, type NativeState, type NativeStyle, type NativeTheme, } from "./themeNative.js";
11
+ export { CONTROL_LEADING, CONTROL_TEXT, type ControlTypeStep } from "./control.js";
12
+ export { FOCUS_RING, FOCUS_RING_INSET } from "./focus.js";
@@ -0,0 +1,12 @@
1
+ /**
2
+ * `@slashsuite/core`: what every UISlash renderer shares. The token tables and prop types of the
3
+ * components that have moved here, their story fixtures, the parity manifest built from the
4
+ * tables, and the native theme generator. Pure TypeScript, no runtime dependencies.
5
+ */
6
+ export * from "./button.js";
7
+ export { buttonFixtures } from "./fixtures/button.js";
8
+ export { storyId } from "./fixtures/types.js";
9
+ export { parityJson, parityManifest, radiusPx, spacingPx, } from "./parity.js";
10
+ export { missingFromNative, nativeTheme, nativeThemeJson, STATE_OF_VARIANT, } from "./themeNative.js";
11
+ export { CONTROL_LEADING, CONTROL_TEXT } from "./control.js";
12
+ export { FOCUS_RING, FOCUS_RING_INSET } from "./focus.js";
@@ -0,0 +1,22 @@
1
+ /** The px of the first `<prefix>-<n>` spacing class in `classes`, or 0 when there is none. */
2
+ export declare function spacingPx(classes: string, prefix: string): number;
3
+ /** The px of the radius class in `classes`, or 0 when there is none. */
4
+ export declare function radiusPx(classes: string): number;
5
+ /** One size of a component's box, in logical px. */
6
+ export type BoxMetrics = {
7
+ height: number;
8
+ paddingX: number;
9
+ paddingY: number;
10
+ gap: number;
11
+ radius: number;
12
+ borderWidth: number;
13
+ };
14
+ /** The manifest: component, then size, then its box. */
15
+ export type ParityManifest = {
16
+ version: 1;
17
+ components: Record<string, Record<string, BoxMetrics>>;
18
+ };
19
+ /** The manifest from the tables as they are now. */
20
+ export declare function parityManifest(): ParityManifest;
21
+ /** The manifest as the file holds it: two-space JSON with a trailing newline. */
22
+ export declare const parityJson: () => string;
@@ -0,0 +1,53 @@
1
+ /**
2
+ * The parity manifest: the box every renderer must draw for each component and size, in logical px,
3
+ * read from the token tables (never written by hand). `scripts/parity.ts` writes it to
4
+ * `parity.json`; its test fails when the file is stale, so a token change shows up as a diff of
5
+ * the manifest that both renderers are measured against.
6
+ */
7
+ import { BUTTON_BOX, BUTTON_SHAPE } from "./button.js";
8
+ import { CONTROL_LEADING } from "./control.js";
9
+ /** Tailwind's spacing step: `p-1` is 0.25rem, 4px at the default root size. */
10
+ const SPACING_PX = 4;
11
+ /** Tailwind v4's radius scale, in px. */
12
+ const RADIUS_PX = {
13
+ "rounded-sm": 4,
14
+ "rounded-md": 6,
15
+ "rounded-lg": 8,
16
+ "rounded-xl": 12,
17
+ "rounded-full": 9999,
18
+ };
19
+ /** The px of the first `<prefix>-<n>` spacing class in `classes`, or 0 when there is none. */
20
+ export function spacingPx(classes, prefix) {
21
+ const step = new RegExp(`(?:^|\\s)${prefix}-(\\d+(?:\\.\\d+)?)(?=\\s|$)`).exec(classes)?.[1];
22
+ return step === undefined ? 0 : Number(step) * SPACING_PX;
23
+ }
24
+ /** The px of the radius class in `classes`, or 0 when there is none. */
25
+ export function radiusPx(classes) {
26
+ const radius = classes.split(/\s+/).find((name) => name in RADIUS_PX);
27
+ return radius === undefined ? 0 : (RADIUS_PX[radius] ?? 0);
28
+ }
29
+ function buttonBox(size) {
30
+ const box = BUTTON_BOX[size];
31
+ const borderWidth = /(?:^|\s)border(?=\s|$)/.test(BUTTON_SHAPE) ? 1 : 0;
32
+ const paddingY = spacingPx(box, "py");
33
+ return {
34
+ height: spacingPx(CONTROL_LEADING[size], "leading") + 2 * paddingY + 2 * borderWidth,
35
+ paddingX: spacingPx(box, "px"),
36
+ paddingY,
37
+ gap: spacingPx(box, "gap"),
38
+ radius: radiusPx(BUTTON_SHAPE),
39
+ borderWidth,
40
+ };
41
+ }
42
+ const SIZES = ["sm", "md", "lg"];
43
+ /** The manifest from the tables as they are now. */
44
+ export function parityManifest() {
45
+ return {
46
+ version: 1,
47
+ components: {
48
+ Button: Object.fromEntries(SIZES.map((size) => [size, buttonBox(size)])),
49
+ },
50
+ };
51
+ }
52
+ /** The manifest as the file holds it: two-space JSON with a trailing newline. */
53
+ export const parityJson = () => `${JSON.stringify(parityManifest(), null, 2)}\n`;
@@ -0,0 +1,62 @@
1
+ /**
2
+ * The native theme generator: a theme's CSS (`themes/<id>.css`) as the style map a React Native
3
+ * renderer reads (`themes/<id>.native.json`). Pure: it takes the CSS text and the palette and
4
+ * returns the map, so the theme test can assert the committed file is current.
5
+ *
6
+ * Every palette utility lands in one place: a plain one (`bg-white`) in `utilities`, one behind a
7
+ * state variant in that state's slot (`hover:bg-violet-700` in `pressed`, `placeholder:text-slate-400`
8
+ * in `placeholderTextColor`, `backdrop:bg-slate-900/35` in `scrim`). A rule the map cannot hold as
9
+ * one utility (`.disabled\:opacity-50:disabled:is(…)`) is a compound. Anything else is listed in
10
+ * `unmapped`, so nothing is dropped silently, and the theme test requires that list to be empty.
11
+ */
12
+ /** A React Native style, as the theme sets it: colours as lower-case hex or `rgba(…)`, and opacity. */
13
+ export type NativeStyle = Record<string, string | number>;
14
+ /** The slot a state variant lands in. */
15
+ export type NativeState = "pressed" | "focused" | "placeholderTextColor" | "scrim" | "disabled" | "invalid" | "target";
16
+ /** A rule that holds only alongside other classes: `disabled:opacity-50` on a solid fill. */
17
+ export type NativeCompound = {
18
+ utility: string;
19
+ requiresAny: string[];
20
+ style: NativeStyle;
21
+ };
22
+ export type NativeTheme = {
23
+ /** The theme's id, its file name without `.css`. */
24
+ id: string;
25
+ /** The scope class the web theme sits under. */
26
+ scope: string;
27
+ scheme: "light" | "dark";
28
+ /** The status bar's content style: light content on a dark theme. */
29
+ statusBar: "light-content" | "dark-content";
30
+ /** The page: its canvas, its ink, its sans family and the family its headings take. */
31
+ base: {
32
+ backgroundColor: string;
33
+ color: string;
34
+ fontFamily: string | null;
35
+ headingFontFamily: string | null;
36
+ };
37
+ /** The text selection's colours. */
38
+ selection: NativeStyle;
39
+ /** Every plain palette utility, keyed as a component writes it. */
40
+ utilities: Record<string, NativeStyle>;
41
+ /** Each state's utilities, keyed by the plain utility they restyle: `hover:bg-violet-700` sits under `pressed`. */
42
+ states: Record<NativeState, Record<string, NativeStyle>>;
43
+ /** A utility drawn on a tint: `within["bg-violet-50"]["text-slate-500"]`. */
44
+ within: Record<string, Record<string, NativeStyle>>;
45
+ /** A utility as a heading draws it: `headings["text-slate-900"]`. */
46
+ headings: Record<string, NativeStyle>;
47
+ compounds: NativeCompound[];
48
+ };
49
+ /** Which slot each Tailwind variant the palette uses lands in. */
50
+ export declare const STATE_OF_VARIANT: Record<string, NativeState>;
51
+ /**
52
+ * The native map of one theme's CSS. `id` is the file name without `.css`. Returns the map and
53
+ * every rule or declaration it could not carry.
54
+ */
55
+ export declare function nativeTheme(css: string, id: string): {
56
+ theme: NativeTheme;
57
+ unmapped: string[];
58
+ };
59
+ /** The palette utilities a native map does not hold: each in `utilities`, or in its variant's slot. */
60
+ export declare function missingFromNative(theme: NativeTheme, palette: readonly string[]): string[];
61
+ /** The map as the file holds it: two-space JSON with a trailing newline. */
62
+ export declare const nativeThemeJson: (theme: NativeTheme) => string;
@@ -0,0 +1,290 @@
1
+ /**
2
+ * The native theme generator: a theme's CSS (`themes/<id>.css`) as the style map a React Native
3
+ * renderer reads (`themes/<id>.native.json`). Pure: it takes the CSS text and the palette and
4
+ * returns the map, so the theme test can assert the committed file is current.
5
+ *
6
+ * Every palette utility lands in one place: a plain one (`bg-white`) in `utilities`, one behind a
7
+ * state variant in that state's slot (`hover:bg-violet-700` in `pressed`, `placeholder:text-slate-400`
8
+ * in `placeholderTextColor`, `backdrop:bg-slate-900/35` in `scrim`). A rule the map cannot hold as
9
+ * one utility (`.disabled\:opacity-50:disabled:is(…)`) is a compound. Anything else is listed in
10
+ * `unmapped`, so nothing is dropped silently, and the theme test requires that list to be empty.
11
+ */
12
+ /** Which slot each Tailwind variant the palette uses lands in. */
13
+ export const STATE_OF_VARIANT = {
14
+ hover: "pressed",
15
+ "focus-visible": "focused",
16
+ "has-focus-visible": "focused",
17
+ placeholder: "placeholderTextColor",
18
+ backdrop: "scrim",
19
+ disabled: "disabled",
20
+ "aria-invalid": "invalid",
21
+ "has-aria-invalid": "invalid",
22
+ "user-invalid": "invalid",
23
+ "has-user-invalid": "invalid",
24
+ target: "target",
25
+ };
26
+ const CSS_TO_NATIVE = {
27
+ "background-color": "backgroundColor",
28
+ color: "color",
29
+ "border-color": "borderColor",
30
+ "outline-color": "outlineColor",
31
+ "accent-color": "accentColor",
32
+ opacity: "opacity",
33
+ "font-weight": "fontWeight",
34
+ };
35
+ /** Declarations a native map has no use for: web-only, or carried in `base`. Listed, so nothing else is dropped. */
36
+ const WEB_ONLY = new Set([
37
+ "transition",
38
+ "text-underline-offset",
39
+ "color-scheme",
40
+ "font-family",
41
+ "--font-mono",
42
+ "--font-sans",
43
+ "--font-heading",
44
+ ]);
45
+ const COLOUR = /^(#[0-9a-f]{3,8}|rgba?\([^)]*\)|transparent)$/i;
46
+ /** One canonical form of a colour: lower-case hex, `rgba(r, g, b, a)`. */
47
+ function colourOf(value, where, unmapped) {
48
+ if (!COLOUR.test(value)) {
49
+ unmapped.push(`${where}: "${value}" is not a colour React Native parses`);
50
+ return undefined;
51
+ }
52
+ return value
53
+ .toLowerCase()
54
+ .replace(/\(\s*/, "(")
55
+ .replace(/\s*\)/, ")")
56
+ .replace(/\s*,\s*/g, ", ");
57
+ }
58
+ function declarationsOf(body, where, unmapped) {
59
+ const style = {};
60
+ for (const declaration of body.split(";")) {
61
+ const colon = declaration.indexOf(":");
62
+ if (colon < 0)
63
+ continue;
64
+ const property = declaration.slice(0, colon).trim();
65
+ const value = declaration
66
+ .slice(colon + 1)
67
+ .replace(/\s+/g, " ")
68
+ .trim();
69
+ if (property === "" || WEB_ONLY.has(property) || property.startsWith("--hc-"))
70
+ continue;
71
+ const native = CSS_TO_NATIVE[property];
72
+ if (native === undefined) {
73
+ unmapped.push(`${where} { ${property} }`);
74
+ continue;
75
+ }
76
+ if (native === "opacity")
77
+ style[native] = Number(value);
78
+ else if (native === "fontWeight")
79
+ style[native] = value;
80
+ else {
81
+ const colour = colourOf(value, `${where} ${property}`, unmapped);
82
+ if (colour !== undefined)
83
+ style[native] = colour;
84
+ }
85
+ }
86
+ return style;
87
+ }
88
+ /** Split a selector list on the commas outside brackets. */
89
+ function selectorsOf(list) {
90
+ const parts = [];
91
+ let depth = 0;
92
+ let current = "";
93
+ for (const char of list) {
94
+ if (char === "(" || char === "[")
95
+ depth += 1;
96
+ if (char === ")" || char === "]")
97
+ depth -= 1;
98
+ if (char === "," && depth === 0) {
99
+ parts.push(current.trim());
100
+ current = "";
101
+ }
102
+ else
103
+ current += char;
104
+ }
105
+ return [...parts, current.trim()].filter(Boolean);
106
+ }
107
+ const unescapeClass = (name) => name.replace(/\\(.)/g, "$1");
108
+ const CLASS = String.raw `((?:\\.|[\w-])+)`;
109
+ /** `hover:bg-violet-700` as its variant and plain utility; no variant gives `undefined`. */
110
+ function splitVariant(utility) {
111
+ const colon = utility.lastIndexOf(":");
112
+ if (colon < 0)
113
+ return { variant: undefined, plain: utility };
114
+ return { variant: utility.slice(0, colon), plain: utility.slice(colon + 1) };
115
+ }
116
+ function merge(table, key, style) {
117
+ table[key] = { ...table[key], ...style };
118
+ }
119
+ function emptyParsed(scope) {
120
+ return {
121
+ scope,
122
+ base: { backgroundColor: "", color: "", fontFamily: null, headingFontFamily: null },
123
+ selection: {},
124
+ utilities: {},
125
+ states: {
126
+ pressed: {},
127
+ focused: {},
128
+ placeholderTextColor: {},
129
+ scrim: {},
130
+ disabled: {},
131
+ invalid: {},
132
+ target: {},
133
+ },
134
+ within: {},
135
+ headings: {},
136
+ compounds: [],
137
+ };
138
+ }
139
+ /** The first family of a `--font-…` stack in the scope rule, unquoted; none gives `null`. */
140
+ function familyOf(body, variable) {
141
+ const family = new RegExp(`--font-${variable}:([^;]+);`)
142
+ .exec(body)?.[1]
143
+ ?.split(",")[0]
144
+ ?.trim()
145
+ .replace(/^["']|["']$/g, "");
146
+ return family === undefined || family === "" ? null : family;
147
+ }
148
+ /** The scope rule: the page's canvas, ink, sans family and heading family. */
149
+ function readScope(parsed, body, file, unmapped) {
150
+ const style = declarationsOf(body, `${file} .${parsed.scope}`, unmapped);
151
+ parsed.base.backgroundColor = String(style["backgroundColor"] ?? "");
152
+ parsed.base.color = String(style["color"] ?? "");
153
+ parsed.base.fontFamily = familyOf(body, "sans");
154
+ parsed.base.headingFontFamily = familyOf(body, "heading");
155
+ }
156
+ /**
157
+ * A rule on the headings. The heading face is `base.headingFontFamily`, read from the scope rule, so
158
+ * a bare heading rule of font-family alone is taken; a utility on a heading
159
+ * (`:is(h1, h2, h3).text-slate-900`) lands in `headings`; anything else is unmapped.
160
+ */
161
+ function readHeading(parsed, rest, style) {
162
+ if (rest === "")
163
+ return Object.keys(style).every((key) => key === "fontFamily");
164
+ const utility = new RegExp(`^\\.${CLASS}$`).exec(rest)?.[1];
165
+ if (utility === undefined)
166
+ return false;
167
+ merge(parsed.headings, unescapeClass(utility), style);
168
+ return true;
169
+ }
170
+ /** A selector that is not one utility: the selection, the headings, a utility on a tint. */
171
+ function readSpecial(parsed, selector, style) {
172
+ const scope = parsed.scope;
173
+ if (new RegExp(`^\\.${scope}\\s*::selection$`).test(selector)) {
174
+ Object.assign(parsed.selection, style);
175
+ return true;
176
+ }
177
+ const heading = new RegExp(`^\\.${scope}\\s+:is\\(h1, h2, h3[^)]*\\)(.*)$`).exec(selector);
178
+ if (heading)
179
+ return readHeading(parsed, heading[1] ?? "", style);
180
+ const within = new RegExp(`^\\.${scope}\\s+\\.${CLASS}\\s+\\.${CLASS}$`).exec(selector);
181
+ if (!within)
182
+ return false;
183
+ const tint = unescapeClass(within[1] ?? "");
184
+ parsed.within[tint] = parsed.within[tint] ?? {};
185
+ merge(parsed.within[tint], unescapeClass(within[2] ?? ""), style);
186
+ return true;
187
+ }
188
+ /** One utility, plain, behind a state variant, or held only alongside other classes. */
189
+ function readUtility(parsed, utility, rest, style) {
190
+ const requires = /:is\(([^)]*)\)/.exec(rest)?.[1];
191
+ if (requires !== undefined) {
192
+ const requiresAny = requires.split(",").map((name) => unescapeClass(name.trim().slice(1)));
193
+ parsed.compounds.push({ utility, requiresAny, style });
194
+ return true;
195
+ }
196
+ const { variant, plain } = splitVariant(utility);
197
+ if (variant === undefined) {
198
+ // A plain class with its own `:hover` (`.link:hover`) is that class pressed; any other
199
+ // pseudo-class on a plain class has no slot.
200
+ if (rest === ":hover")
201
+ merge(parsed.states.pressed, plain, style);
202
+ else if (rest === "")
203
+ merge(parsed.utilities, plain, style);
204
+ else
205
+ return false;
206
+ return true;
207
+ }
208
+ const state = STATE_OF_VARIANT[variant];
209
+ if (state === undefined)
210
+ return false;
211
+ merge(parsed.states[state], plain, state === "placeholderTextColor" ? asPlaceholder(style) : style);
212
+ return true;
213
+ }
214
+ /** One `.scope …` selector into its place in the map; false when it has none. */
215
+ function readSelector(parsed, selector, style) {
216
+ if (readSpecial(parsed, selector, style))
217
+ return true;
218
+ const plain = new RegExp(`^\\.${parsed.scope}\\s+\\.${CLASS}(.*)$`).exec(selector);
219
+ if (!plain)
220
+ return false;
221
+ return readUtility(parsed, unescapeClass(plain[1] ?? ""), plain[2] ?? "", style);
222
+ }
223
+ /** A placeholder's colour is a prop on a native text input, not a style. */
224
+ const asPlaceholder = (style) => style["color"] === undefined ? style : { placeholderTextColor: style["color"] };
225
+ /**
226
+ * The native map of one theme's CSS. `id` is the file name without `.css`. Returns the map and
227
+ * every rule or declaration it could not carry.
228
+ */
229
+ export function nativeTheme(css, id) {
230
+ const file = `${id}.css`;
231
+ const uncommented = css.replace(/\/\*[\s\S]*?\*\//g, "");
232
+ const scheme = /@custom-variant\s+dark\b/.test(uncommented) ? "dark" : "light";
233
+ const unmapped = [];
234
+ const { scope, base, selection, utilities, states, within, headings, compounds } = parse(uncommented.replace(/@[^;{}]*;/g, ""), file, unmapped);
235
+ return {
236
+ theme: {
237
+ id,
238
+ scope,
239
+ scheme,
240
+ statusBar: scheme === "dark" ? "light-content" : "dark-content",
241
+ base,
242
+ selection,
243
+ utilities,
244
+ states,
245
+ within,
246
+ headings,
247
+ compounds,
248
+ },
249
+ unmapped,
250
+ };
251
+ }
252
+ /** The scope rule's map, from the first rule: its selector must be the one scope class. */
253
+ function parseScope(list, body, file, unmapped) {
254
+ const scope = /^\.([\w-]+)$/.exec(selectorsOf(list)[0] ?? "")?.[1];
255
+ if (scope === undefined)
256
+ throw new Error(`${file}: the first rule is not the scope rule`);
257
+ const parsed = emptyParsed(scope);
258
+ readScope(parsed, body, file, unmapped);
259
+ return parsed;
260
+ }
261
+ /** The rules of one theme's CSS, comments and at-statements gone: the scope rule first. */
262
+ function parse(source, file, unmapped) {
263
+ let parsed;
264
+ for (const [, list = "", body = ""] of source.matchAll(/([^{}]+)\{([^{}]*)\}/g)) {
265
+ if (parsed === undefined) {
266
+ parsed = parseScope(list, body, file, unmapped);
267
+ continue;
268
+ }
269
+ for (const selector of selectorsOf(list)) {
270
+ const style = declarationsOf(body, `${file} ${selector}`, unmapped);
271
+ if (!readSelector(parsed, selector, style))
272
+ unmapped.push(`${file}: selector ${selector}`);
273
+ }
274
+ }
275
+ if (parsed === undefined)
276
+ throw new Error(`${file}: no scope rule`);
277
+ return parsed;
278
+ }
279
+ /** The palette utilities a native map does not hold: each in `utilities`, or in its variant's slot. */
280
+ export function missingFromNative(theme, palette) {
281
+ return palette.filter((utility) => {
282
+ const { variant, plain } = splitVariant(utility);
283
+ if (variant === undefined)
284
+ return theme.utilities[plain] === undefined;
285
+ const state = STATE_OF_VARIANT[variant];
286
+ return state === undefined || theme.states[state][plain] === undefined;
287
+ });
288
+ }
289
+ /** The map as the file holds it: two-space JSON with a trailing newline. */
290
+ export const nativeThemeJson = (theme) => `${JSON.stringify(theme, null, 2)}\n`;
package/dist/cx.d.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  /** Join class names, dropping falsy parts. */
2
2
  export declare function cx(...parts: Array<string | false | null | undefined>): string;
3
- /** The keyboard focus ring every interactive control shares. */
4
- export declare const focusRing = "focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-violet-600";
3
+ export { focusRing, insetFocusRing } from "./focus.js";
5
4
  /**
6
5
  * A heading's lines are balanced, so a two-line title does not end on one orphaned word; prose is
7
6
  * wrapped `pretty`, which keeps a short last line off a paragraph. Only the wrap style is set, so a
@@ -15,12 +14,6 @@ export declare const pretty = "[text-wrap-style:pretty]";
15
14
  * colour the page names is kept, so the fill takes the system's Highlight; `!` beats a theme's scoped remap of the stock fill.
16
15
  */
17
16
  export declare const forcedFill = "forced-colors:bg-[color:Highlight]!";
18
- /**
19
- * The same ring drawn inside the control, for one that fills a box which clips anything outside
20
- * it (a table's sortable title, a scroller). `focusRing` with `-outline-offset-2` added would not
21
- * do, since `outline-offset-2` comes later in the CSS and wins.
22
- */
23
- export declare const insetFocusRing = "focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-violet-600";
24
17
  /**
25
18
  * On a row or card that holds a stretched link (`link-stretch`): every interactive descendant sits
26
19
  * above that link and is clickable on its own. `z-10` needs a position, so each gets `relative`,
package/dist/cx.js CHANGED
@@ -2,8 +2,8 @@
2
2
  export function cx(...parts) {
3
3
  return parts.filter(Boolean).join(" ");
4
4
  }
5
- /** The keyboard focus ring every interactive control shares. */
6
- export const focusRing = "focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-violet-600";
5
+ // The keyboard focus ring and its inset twin are core's, the one copy both renderers read.
6
+ export { focusRing, insetFocusRing } from "./focus.js";
7
7
  /**
8
8
  * A heading's lines are balanced, so a two-line title does not end on one orphaned word; prose is
9
9
  * wrapped `pretty`, which keeps a short last line off a paragraph. Only the wrap style is set, so a
@@ -17,12 +17,6 @@ export const pretty = "[text-wrap-style:pretty]";
17
17
  * colour the page names is kept, so the fill takes the system's Highlight; `!` beats a theme's scoped remap of the stock fill.
18
18
  */
19
19
  export const forcedFill = "forced-colors:bg-[color:Highlight]!";
20
- /**
21
- * The same ring drawn inside the control, for one that fills a box which clips anything outside
22
- * it (a table's sortable title, a scroller). `focusRing` with `-outline-offset-2` added would not
23
- * do, since `outline-offset-2` comes later in the CSS and wins.
24
- */
25
- export const insetFocusRing = "focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-violet-600";
26
20
  /**
27
21
  * On a row or card that holds a stretched link (`link-stretch`): every interactive descendant sits
28
22
  * above that link and is clickable on its own. `z-10` needs a position, so each gets `relative`,
package/dist/density.d.ts CHANGED
@@ -26,9 +26,9 @@ export declare function useResponsiveDensity(size: Size | ResponsiveSize | undef
26
26
  export declare function useTypeStep(): TypeStep | undefined;
27
27
  /** The size twins, for the data test that each is its table with `md:` on every class. */
28
28
  export declare const controlTextTables: {
29
- text: Record<"compact" | "default", Record<Size, string>>;
29
+ text: Record<import("./core/index.js").ControlTypeStep, Record<import("./core/index.js").ButtonSize, string>>;
30
30
  textMd: Record<"compact" | "default", Record<Size, string>>;
31
- leading: Record<Size, string>;
31
+ leading: Record<import("./core/index.js").ButtonSize, string>;
32
32
  leadingMd: Record<Size, string>;
33
33
  };
34
34
  /**
package/dist/density.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { createContext, createElement, useContext, useMemo, } from "react";
2
+ import { CONTROL_LEADING, CONTROL_TEXT } from "./core/index.js";
2
3
  import { isResponsive } from "./size.js";
3
4
  const DensityContext = createContext({ size: undefined, type: undefined });
4
5
  /**
@@ -28,11 +29,6 @@ export function useResponsiveDensity(size) {
28
29
  export function useTypeStep() {
29
30
  return useContext(DensityContext).type;
30
31
  }
31
- /** A control's type size at each step: `md` is 16px at the default step, and `compact` is one step down. */
32
- const CONTROL_TEXT = {
33
- default: { sm: "text-sm", md: "text-base", lg: "text-lg" },
34
- compact: { sm: "text-xs", md: "text-sm", lg: "text-base" },
35
- };
36
32
  /** `CONTROL_TEXT` from the `md` breakpoint up, for a responsive size. */
37
33
  const CONTROL_TEXT_MD = {
38
34
  default: { sm: "md:text-sm", md: "md:text-base", lg: "md:text-lg" },
@@ -43,12 +39,8 @@ const CONTROL_TEXT_MD = {
43
39
  * not zoom the page when it takes the focus.
44
40
  */
45
41
  const TOUCH_TEXT = "pointer-coarse:text-base";
46
- /**
47
- * A control's line height by `size`, whatever its type step: 16, 20 and 24px, so with its padding
48
- * every control is 26, 38 and 46px tall at both steps, and a `Select`, an `IconButton` and a
49
- * `DateRangePicker`, whose heights are fixed, line up with it.
50
- */
51
- const CONTROL_LEADING = { sm: "leading-4", md: "leading-5", lg: "leading-6" };
42
+ // `CONTROL_TEXT` and `CONTROL_LEADING` are core's, the one copy both renderers read; a `Select`, an
43
+ // `IconButton` and a `DateRangePicker`, whose heights are fixed, line up with them.
52
44
  /** `CONTROL_LEADING` from the `md` breakpoint up, for a responsive size. */
53
45
  const CONTROL_LEADING_MD = {
54
46
  sm: "md:leading-4",
@@ -0,0 +1,2 @@
1
+ export declare const focusRing = "focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-violet-600";
2
+ export declare const insetFocusRing = "focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-violet-600";
package/dist/focus.js ADDED
@@ -0,0 +1,9 @@
1
+ /**
2
+ * The keyboard focus ring every interactive control shares, and the same ring drawn inside the
3
+ * control, for one that fills a box which clips anything outside it (a table's sortable title, a
4
+ * scroller). `focusRing` with `-outline-offset-2` added would not do, since `outline-offset-2` comes
5
+ * later in the CSS and wins. Both are core's, so the native controls draw the same ring.
6
+ */
7
+ import { FOCUS_RING, FOCUS_RING_INSET } from "./core/index.js";
8
+ export const focusRing = FOCUS_RING;
9
+ export const insetFocusRing = FOCUS_RING_INSET;
@@ -1,5 +1,5 @@
1
1
  import { type ReactElement } from "react";
2
- import type { FlowLayout } from "./flowLayout.js";
2
+ import type { FlowLayout, FlowNodeBox } from "./flowLayout.js";
3
3
  import type { StateMachineItem } from "./StateMachine.js";
4
4
  /**
5
5
  * The box items whose `state` is no state of the machine go in. Printable, since it reaches the DOM
@@ -31,6 +31,38 @@ export declare function useMoves(items: readonly StateMachineItem[], known: Read
31
31
  };
32
32
  /** How many slots a box with `count` items draws: all of them, or the first few and a `+N`; one more for "fewer" when open. */
33
33
  export declare function slotsFor(count: number, open: boolean): number;
34
+ /**
35
+ * The rows a box reserves for its dots, whatever its count: the nine it shows (the `+N` included),
36
+ * or the rows of an open box's full list. A box with few or no items reserves the same rows, so
37
+ * its size does not depend on how many items it holds.
38
+ */
39
+ export declare function rowsFor(slots: number): number;
40
+ /**
41
+ * The room a box reserves under its tags for `slots` dots: the full grid's width and `rowsFor`'s
42
+ * height, so it is the same at 0, 1, 9 or 12 items (closed) and grows only when a box is opened.
43
+ */
44
+ export declare function dotArea(slots: number): {
45
+ width: number;
46
+ height: number;
47
+ };
48
+ /** A box's tag row: one small pill's height. */
49
+ export declare const TAG_ROW = 20;
50
+ /** The gap between the tag row and the dot area (`mt-1`). */
51
+ export declare const TAG_GAP = 4;
52
+ /**
53
+ * The size of what a box holds under its label: its tag row, then its dot area. The layout takes
54
+ * it before the box can be measured (a server render), so the dots, placed up from the box's
55
+ * bottom, already sit under the tags and never on them.
56
+ */
57
+ export declare function boxContentSize(slots: number): {
58
+ width: number;
59
+ height: number;
60
+ };
61
+ /** Where slot `i` of `slots` sits in `box`: its left edge and its vertical centre, on the box's fixed grid. */
62
+ export declare function slotAt(box: FlowNodeBox, i: number, slots: number): {
63
+ left: number;
64
+ y: number;
65
+ };
34
66
  /** What the dot layer draws from: the items in each box, the boxes' names, which boxes are open, and the moves. */
35
67
  type DotPlaces = {
36
68
  inBox: ReadonlyMap<string, readonly StateMachineItem[]>;
@@ -83,13 +83,39 @@ export function slotsFor(count, open) {
83
83
  return count;
84
84
  return open ? count + 1 : LIMIT;
85
85
  }
86
- /** Where slot `i` of `slots` sits in `box`: its left edge and its vertical centre. */
87
- function slotAt(box, i, slots) {
88
- const cols = Math.min(COLS, slots);
89
- const rows = Math.ceil(slots / COLS);
90
- const top = box.y + box.height - BOX_INSET - rows * SLOT_H;
86
+ /**
87
+ * The rows a box reserves for its dots, whatever its count: the nine it shows (the `+N` included),
88
+ * or the rows of an open box's full list. A box with few or no items reserves the same rows, so
89
+ * its size does not depend on how many items it holds.
90
+ */
91
+ export function rowsFor(slots) {
92
+ return Math.ceil(Math.max(LIMIT, slots) / COLS);
93
+ }
94
+ /**
95
+ * The room a box reserves under its tags for `slots` dots: the full grid's width and `rowsFor`'s
96
+ * height, so it is the same at 0, 1, 9 or 12 items (closed) and grows only when a box is opened.
97
+ */
98
+ export function dotArea(slots) {
99
+ return { width: COLS * SLOT_W, height: rowsFor(slots) * SLOT_H };
100
+ }
101
+ /** A box's tag row: one small pill's height. */
102
+ export const TAG_ROW = 20;
103
+ /** The gap between the tag row and the dot area (`mt-1`). */
104
+ export const TAG_GAP = 4;
105
+ /**
106
+ * The size of what a box holds under its label: its tag row, then its dot area. The layout takes
107
+ * it before the box can be measured (a server render), so the dots, placed up from the box's
108
+ * bottom, already sit under the tags and never on them.
109
+ */
110
+ export function boxContentSize(slots) {
111
+ const area = dotArea(slots);
112
+ return { width: area.width, height: TAG_ROW + TAG_GAP + area.height };
113
+ }
114
+ /** Where slot `i` of `slots` sits in `box`: its left edge and its vertical centre, on the box's fixed grid. */
115
+ export function slotAt(box, i, slots) {
116
+ const top = box.y + box.height - BOX_INSET - rowsFor(slots) * SLOT_H;
91
117
  return {
92
- left: box.x + box.width / 2 - (cols * SLOT_W) / 2 + (i % COLS) * SLOT_W,
118
+ left: box.x + box.width / 2 - (COLS * SLOT_W) / 2 + (i % COLS) * SLOT_W,
93
119
  y: top + Math.floor(i / COLS) * SLOT_H + SLOT_H / 2,
94
120
  };
95
121
  }
@@ -1,8 +1,19 @@
1
1
  import { type RefObject } from "react";
2
2
  import type { FlowEdge, FlowNode } from "./FlowDiagram.js";
3
3
  import { type FlowDirection, type FlowLayout } from "./flowLayout.js";
4
- /** What the layout reads from a node. */
5
- type SizedNode = Pick<FlowNode, "id" | "label" | "group" | "content">;
4
+ type Size = {
5
+ width: number;
6
+ height: number;
7
+ };
8
+ /**
9
+ * What the layout reads from a node. A caller that knows its content's size (`StateMachine`, whose
10
+ * boxes are a fixed size) gives it as `contentSize`, so the first layout, the one a server render
11
+ * shows, already has each box at its drawn size.
12
+ */
13
+ export type SizedNode = Pick<FlowNode, "id" | "label" | "group" | "content"> & {
14
+ contentSize?: Size | undefined;
15
+ };
16
+ export declare function guessNode(node: SizedNode): Size;
6
17
  export declare const nodeKey: (id: string) => string;
7
18
  export declare const edgeKey: (index: number) => string;
8
19
  /**
@@ -12,15 +12,18 @@ const NODE_PAD_X = 26;
12
12
  const NODE_PAD_Y = 18;
13
13
  const NODE_LINE = 20;
14
14
  const CONTENT_GUESS = 32;
15
+ /** The gap between a box's label and its content (`mt-2`). */
16
+ const CONTENT_GAP = 8;
15
17
  const EDGE_CHAR = 6.6;
16
18
  const EDGE_PAD = 8;
17
19
  const EDGE_LINE = 16;
18
- function guessNode(node) {
20
+ export function guessNode(node) {
19
21
  const text = Math.ceil(node.label.length * NODE_CHAR);
20
22
  const lines = Math.max(1, Math.ceil(text / (NODE_MAX - NODE_PAD_X)));
23
+ const content = node.contentSize ?? { width: 0, height: CONTENT_GUESS - CONTENT_GAP };
21
24
  return {
22
- width: Math.min(NODE_MAX, text + NODE_PAD_X),
23
- height: lines * NODE_LINE + NODE_PAD_Y + (node.content == null ? 0 : CONTENT_GUESS),
25
+ width: Math.min(NODE_MAX, Math.max(text, content.width) + NODE_PAD_X),
26
+ height: lines * NODE_LINE + NODE_PAD_Y + (node.content == null ? 0 : CONTENT_GAP + content.height),
24
27
  };
25
28
  }
26
29
  const guessLabel = (label) => ({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@slashsuite/ui-react",
3
- "version": "0.13.0",
3
+ "version": "0.13.1",
4
4
  "description": "UISlash React components: primitives, typography roles and a safe Markdown renderer, written against Tailwind v4 utilities. Pair with a theme from @slashsuite/themes.",
5
5
  "keywords": [
6
6
  "components",
@@ -43,7 +43,7 @@
43
43
  "./package.json": "./package.json"
44
44
  },
45
45
  "scripts": {
46
- "build": "rm -rf dist && tsc -p tsconfig.build.json",
46
+ "build": "rm -rf dist && tsc -p tsconfig.build.json && bun scripts/vendor-core.ts",
47
47
  "typecheck": "tsc --noEmit",
48
48
  "lint": "oxlint -c .oxlintrc.json --type-aware --deny-warnings --report-unused-disable-directives && bun ../../scripts/check-slop.ts",
49
49
  "test": "vitest run",
@@ -57,6 +57,7 @@
57
57
  "react-aria-components": "^1.22.1"
58
58
  },
59
59
  "devDependencies": {
60
+ "@slashsuite/core": "0.0.0",
60
61
  "@testing-library/dom": "10.4.2",
61
62
  "@testing-library/react": "16.3.3",
62
63
  "@testing-library/user-event": "14.6.12",