@behavioral-agentic-design-system/core 0.12.2 → 0.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,199 @@
1
+ "use client";
2
+
3
+ import * as React from "react";
4
+ import { XIcon } from "lucide-react";
5
+ import { cn } from "../../lib/utils";
6
+
7
+ // ─── Types ────────────────────────────────────────────────────────────────────
8
+
9
+ export interface TagsInputProps
10
+ extends Omit<React.HTMLAttributes<HTMLDivElement>, "onChange"> {
11
+ /** The current list of tag values. */
12
+ value: string[];
13
+ /** Callback fired when the tag list changes. */
14
+ onValueChange: (value: string[]) => void;
15
+ /** Placeholder shown when no tags are present. */
16
+ placeholder?: string;
17
+ /** Disables the entire input. */
18
+ disabled?: boolean;
19
+ /** Maximum number of tags allowed. Input is blocked once reached. */
20
+ maxTags?: number;
21
+ /** Allow duplicate tag values. Defaults to false. */
22
+ allowDuplicates?: boolean;
23
+ /** Characters that trigger tag creation in addition to Enter. Default: [","]. */
24
+ delimiters?: string[];
25
+ }
26
+
27
+ // ─── Component ────────────────────────────────────────────────────────────────
28
+
29
+ export function TagsInput({
30
+ value,
31
+ onValueChange,
32
+ placeholder,
33
+ disabled = false,
34
+ maxTags,
35
+ allowDuplicates = false,
36
+ delimiters = [","],
37
+ className,
38
+ ...props
39
+ }: TagsInputProps) {
40
+ const [inputValue, setInputValue] = React.useState("");
41
+ const [focusedTagIndex, setFocusedTagIndex] = React.useState<number | null>(null);
42
+ const inputRef = React.useRef<HTMLInputElement>(null);
43
+
44
+ const atMax = maxTags !== undefined && value.length >= maxTags;
45
+
46
+ const addTag = React.useCallback(
47
+ (raw: string) => {
48
+ const trimmed = raw.trim();
49
+ if (!trimmed) return;
50
+ if (atMax) return;
51
+ if (!allowDuplicates && value.includes(trimmed)) return;
52
+ onValueChange([...value, trimmed]);
53
+ setInputValue("");
54
+ },
55
+ [atMax, allowDuplicates, value, onValueChange]
56
+ );
57
+
58
+ const removeTag = React.useCallback(
59
+ (index: number) => {
60
+ onValueChange(value.filter((_, i) => i !== index));
61
+ setFocusedTagIndex(null);
62
+ inputRef.current?.focus();
63
+ },
64
+ [value, onValueChange]
65
+ );
66
+
67
+ const handleKeyDown = React.useCallback(
68
+ (e: React.KeyboardEvent<HTMLInputElement>) => {
69
+ if (e.key === "Enter") {
70
+ e.preventDefault();
71
+ addTag(inputValue);
72
+ } else if (e.key === "Backspace" && inputValue === "") {
73
+ e.preventDefault();
74
+ if (focusedTagIndex !== null) {
75
+ removeTag(focusedTagIndex);
76
+ } else if (value.length > 0) {
77
+ setFocusedTagIndex(value.length - 1);
78
+ }
79
+ } else if (e.key === "Delete" && inputValue === "" && focusedTagIndex !== null) {
80
+ e.preventDefault();
81
+ removeTag(focusedTagIndex);
82
+ } else if (e.key === "ArrowLeft" && inputValue === "") {
83
+ if (focusedTagIndex === null && value.length > 0) {
84
+ setFocusedTagIndex(value.length - 1);
85
+ } else if (focusedTagIndex !== null && focusedTagIndex > 0) {
86
+ setFocusedTagIndex(focusedTagIndex - 1);
87
+ }
88
+ } else if (e.key === "ArrowRight" && inputValue === "") {
89
+ if (focusedTagIndex !== null) {
90
+ if (focusedTagIndex < value.length - 1) {
91
+ setFocusedTagIndex(focusedTagIndex + 1);
92
+ } else {
93
+ setFocusedTagIndex(null);
94
+ }
95
+ }
96
+ } else if (e.key === "Escape") {
97
+ setFocusedTagIndex(null);
98
+ } else {
99
+ setFocusedTagIndex(null);
100
+ }
101
+ },
102
+ [inputValue, focusedTagIndex, value, addTag, removeTag]
103
+ );
104
+
105
+ const handleInputChange = React.useCallback(
106
+ (e: React.ChangeEvent<HTMLInputElement>) => {
107
+ const val = e.target.value;
108
+ const lastChar = val[val.length - 1];
109
+ if (lastChar !== undefined && delimiters.includes(lastChar)) {
110
+ addTag(val.slice(0, -1));
111
+ } else {
112
+ setInputValue(val);
113
+ }
114
+ setFocusedTagIndex(null);
115
+ },
116
+ [delimiters, addTag]
117
+ );
118
+
119
+ const inputPlaceholder =
120
+ value.length === 0
121
+ ? placeholder
122
+ : atMax
123
+ ? `Max ${maxTags} tags reached`
124
+ : undefined;
125
+
126
+ return (
127
+ <div
128
+ data-slot="tags-input"
129
+ data-disabled={disabled || undefined}
130
+ aria-disabled={disabled || undefined}
131
+ onClick={() => !disabled && inputRef.current?.focus()}
132
+ className={cn(
133
+ "flex min-h-11 flex-wrap items-center gap-1.5 rounded-md border border-input bg-background px-3 py-2",
134
+ "cursor-text",
135
+ "focus-within:outline-none focus-within:ring-2 focus-within:ring-ring focus-within:ring-offset-2",
136
+ disabled && "cursor-not-allowed border-border/50 bg-muted/30 pointer-events-none",
137
+ className
138
+ )}
139
+ {...props}
140
+ >
141
+ {value.map((tag, index) => (
142
+ <span
143
+ key={`${tag}-${index}`}
144
+ data-slot="tags-input-item"
145
+ data-focused={focusedTagIndex === index || undefined}
146
+ className={cn(
147
+ "inline-flex max-w-[160px] items-center gap-1 rounded-md px-2 py-0.5",
148
+ "text-sm font-medium transition-colors",
149
+ disabled
150
+ ? "bg-muted text-muted-foreground"
151
+ : "bg-secondary text-secondary-foreground",
152
+ !disabled && focusedTagIndex === index && "ring-2 ring-ring ring-offset-1 ring-offset-background"
153
+ )}
154
+ >
155
+ <span className="truncate">{tag}</span>
156
+ {!disabled && (
157
+ <button
158
+ type="button"
159
+ data-slot="tags-input-item-delete"
160
+ aria-label={`Remove ${tag}`}
161
+ tabIndex={-1}
162
+ onClick={(e) => {
163
+ e.stopPropagation();
164
+ removeTag(index);
165
+ }}
166
+ className={cn(
167
+ "shrink-0 rounded-sm p-0.5",
168
+ "text-secondary-foreground/70 hover:text-secondary-foreground",
169
+ "transition-colors",
170
+ "focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring"
171
+ )}
172
+ style={{
173
+ transitionDuration: "var(--duration-fast)",
174
+ transitionTimingFunction: "var(--ease-out)",
175
+ }}
176
+ >
177
+ <XIcon className="size-3" strokeWidth={1.5} aria-hidden />
178
+ </button>
179
+ )}
180
+ </span>
181
+ ))}
182
+ <input
183
+ ref={inputRef}
184
+ type="text"
185
+ value={inputValue}
186
+ onChange={handleInputChange}
187
+ onKeyDown={handleKeyDown}
188
+ disabled={disabled || atMax}
189
+ placeholder={inputPlaceholder}
190
+ aria-label={placeholder ?? "Add tags, press Enter or comma to confirm"}
191
+ className={cn(
192
+ "min-w-[80px] flex-1 bg-transparent text-sm outline-none",
193
+ "placeholder:text-muted-foreground",
194
+ "disabled:cursor-not-allowed disabled:opacity-0"
195
+ )}
196
+ />
197
+ </div>
198
+ );
199
+ }
@@ -0,0 +1,171 @@
1
+ "use client";
2
+
3
+ import * as React from "react";
4
+ import { CheckIcon } from "lucide-react";
5
+ import { cva } from "class-variance-authority";
6
+ import { cn } from "../../lib/utils";
7
+
8
+ // ─── Types ────────────────────────────────────────────────────────────────────
9
+
10
+ export type TimelineStatus = "default" | "complete" | "active" | "pending";
11
+
12
+ // ─── Variants ─────────────────────────────────────────────────────────────────
13
+
14
+ const dotVariants = cva(
15
+ [
16
+ "absolute left-0 top-1 flex size-5 items-center justify-center",
17
+ "rounded-full border-2 ring-offset-background",
18
+ ],
19
+ {
20
+ variants: {
21
+ status: {
22
+ default: "border-border bg-background",
23
+ complete: "border-primary bg-primary text-primary-foreground",
24
+ active: "border-primary bg-primary text-primary-foreground",
25
+ pending: "border-border/40 bg-muted",
26
+ },
27
+ },
28
+ defaultVariants: { status: "default" },
29
+ }
30
+ );
31
+
32
+ // ─── Root ─────────────────────────────────────────────────────────────────────
33
+
34
+ export interface TimelineProps extends React.HTMLAttributes<HTMLOListElement> {}
35
+
36
+ export function Timeline({ className, children, ...props }: TimelineProps) {
37
+ return (
38
+ <ol
39
+ data-slot="timeline"
40
+ className={cn("relative space-y-0", className)}
41
+ {...props}
42
+ >
43
+ {children}
44
+ </ol>
45
+ );
46
+ }
47
+
48
+ // ─── Item ─────────────────────────────────────────────────────────────────────
49
+
50
+ export interface TimelineItemProps extends Omit<React.HTMLAttributes<HTMLLIElement>, "title"> {
51
+ /** Semantic status: affects dot fill and connector visibility. */
52
+ status?: TimelineStatus;
53
+ /**
54
+ * Icon inside the dot. For `status="complete"` defaults to a check mark.
55
+ * Pass `null` to render an empty dot. Pass any ReactNode for a custom icon.
56
+ */
57
+ icon?: React.ReactNode | null;
58
+ /** Primary label for this event. */
59
+ title?: React.ReactNode;
60
+ /** Secondary detail text. Ignored when `children` is provided. */
61
+ description?: React.ReactNode;
62
+ /** Human-readable timestamp label (e.g. "2 hours ago", "Jun 24"). */
63
+ time?: React.ReactNode;
64
+ /**
65
+ * Machine-readable datetime value (ISO 8601). When provided, the time is
66
+ * rendered as `<time datetime="...">` for screen readers. Without it,
67
+ * a `<span>` is used to avoid axe `time-datetime` violations.
68
+ */
69
+ dateTime?: string;
70
+ }
71
+
72
+ export function TimelineItem({
73
+ status = "default",
74
+ icon,
75
+ title,
76
+ description,
77
+ time,
78
+ dateTime,
79
+ className,
80
+ children,
81
+ ...props
82
+ }: TimelineItemProps) {
83
+ // Default icon: check mark for complete, nothing for others
84
+ const resolvedIcon =
85
+ icon !== undefined
86
+ ? icon
87
+ : status === "complete"
88
+ ? <CheckIcon className="size-3" strokeWidth={1.5} aria-hidden />
89
+ : null;
90
+
91
+ return (
92
+ <li
93
+ data-slot="timeline-item"
94
+ data-status={status}
95
+ className={cn("group relative pb-6 pl-8 last:pb-0", className)}
96
+ {...props}
97
+ >
98
+ {/* Connector line: runs from below the dot to the bottom of the item.
99
+ group-last:hidden removes it on the final item so there's no dangling line. */}
100
+ <span
101
+ aria-hidden
102
+ data-slot="timeline-connector"
103
+ className={cn(
104
+ "absolute left-[9px] top-5 bottom-0 w-px",
105
+ "group-last:hidden",
106
+ status === "pending" ? "bg-border/30" : "bg-border"
107
+ )}
108
+ style={{
109
+ transitionProperty: "background-color",
110
+ transitionDuration: "var(--duration-fast)",
111
+ transitionTimingFunction: "var(--ease-out)",
112
+ }}
113
+ />
114
+
115
+ {/* Dot */}
116
+ <span
117
+ aria-hidden
118
+ data-slot="timeline-dot"
119
+ className={cn(dotVariants({ status }))}
120
+ style={{
121
+ transitionProperty: "background-color, border-color",
122
+ transitionDuration: "var(--duration-fast)",
123
+ transitionTimingFunction: "var(--ease-out)",
124
+ }}
125
+ >
126
+ {resolvedIcon}
127
+ </span>
128
+
129
+ {/* Content */}
130
+ <div data-slot="timeline-content" className="min-w-0 pt-0.5">
131
+ {title && (
132
+ <p
133
+ data-slot="timeline-title"
134
+ className={cn(
135
+ "text-sm font-medium leading-5",
136
+ status === "pending" && "text-muted-foreground"
137
+ )}
138
+ >
139
+ {title}
140
+ </p>
141
+ )}
142
+ {(children != null || description != null) && (
143
+ <div
144
+ data-slot="timeline-description"
145
+ className="mt-0.5 text-sm text-muted-foreground"
146
+ >
147
+ {children ?? description}
148
+ </div>
149
+ )}
150
+ {time != null && (
151
+ dateTime != null ? (
152
+ <time
153
+ data-slot="timeline-time"
154
+ dateTime={dateTime}
155
+ className="mt-1 block text-xs text-muted-foreground"
156
+ >
157
+ {time}
158
+ </time>
159
+ ) : (
160
+ <span
161
+ data-slot="timeline-time"
162
+ className="mt-1 block text-xs text-muted-foreground"
163
+ >
164
+ {time}
165
+ </span>
166
+ )
167
+ )}
168
+ </div>
169
+ </li>
170
+ );
171
+ }
@@ -101,6 +101,7 @@ export const DOCS_INDEX: DocGroup[] = [
101
101
  description: "How the system stays honest — anti-patterns, the corrections log, the ethics floor.",
102
102
  entries: [
103
103
  { title: "Design rules", path: "DESIGN.md", summary: "Visual system + accessibility baseline." },
104
+ { title: "Gamification — responsible vs. manipulative", path: "layer-2-ethics-responsibility/gamification.md", summary: "Sir's 10 Core Drives (Octalysis 8 + Exploration & Discovery + Challenge & Competition) + the test gates that decide when Black Hat ships and when it refuses." },
104
105
  { title: "Corrections log", path: "corrections.md", summary: "Per-fork anti-pattern log. Read before every Path B build." },
105
106
  { title: "Anti-defaults refresh", path: "prompts/anti-defaults-refresh.md", summary: "Quarterly pressure-test of the current anti-defaults." },
106
107
  { title: "Promote corrections", path: "prompts/promote-corrections.md", summary: "Monthly: corrections → lint promotion candidates." },
@@ -10,8 +10,12 @@
10
10
  * - A mark that uses `currentColor` is **adaptive** — the monotone path in
11
11
  * svg-sanitize already rewrote it, so it follows the text color on its own.
12
12
  * Never filter those (inverting would fight the currentColor adaptation).
13
- * - A mark whose every resolvable color is dark is **dark** → invert it in
14
- * dark mode. Every color light → **light** → invert it in light mode.
13
+ * - A mark with any **saturated** color is a brand hue → **mixed** (left as
14
+ * authored). Inverting a saturated color rotates its hue — a blue logo
15
+ * becomes orange — so only neutrals are ever inverted. This check runs
16
+ * before the dark/light luminance test.
17
+ * - A mark whose every resolvable color is dark (and neutral) is **dark** →
18
+ * invert it in dark mode. Every color light → **light** → invert in light.
15
19
  * - Anything with a mix of light and dark fixed colors is **mixed** → left
16
20
  * exactly as authored, because inverting a multi-color logo wrecks the brand
17
21
  * colors. Same for marks whose colors we can't resolve (oklch/hsl/exotic
@@ -80,6 +84,41 @@ function luminanceOf(raw: string): number | null {
80
84
  return null;
81
85
  }
82
86
 
87
+ /**
88
+ * HSV saturation (0–1) of a color, or null if it can't be resolved. Near 0 =
89
+ * a neutral (black / gray / white) that inverts cleanly; high = a saturated
90
+ * brand hue (blue, orange, …) whose hue an `invert` filter would wreck.
91
+ */
92
+ function saturationOf(raw: string): number | null {
93
+ let v = raw.trim().toLowerCase();
94
+ if (!v || v === "none" || v === "transparent" || v === "inherit" || v === "currentcolor") {
95
+ return null;
96
+ }
97
+ if (NAMED_HEX[v]) v = NAMED_HEX[v];
98
+ if (/^#[0-9a-f]{3}$/.test(v)) {
99
+ v = `#${v[1]}${v[1]}${v[2]}${v[2]}${v[3]}${v[3]}`;
100
+ }
101
+ let r: number, g: number, b: number;
102
+ if (/^#[0-9a-f]{6}$/.test(v)) {
103
+ r = parseInt(v.slice(1, 3), 16);
104
+ g = parseInt(v.slice(3, 5), 16);
105
+ b = parseInt(v.slice(5, 7), 16);
106
+ } else {
107
+ const rgb = v.match(/^rgba?\(([^)]+)\)$/);
108
+ if (!rgb) return null;
109
+ const parts = rgb[1]
110
+ .split(/[,\s/]+/)
111
+ .filter(Boolean)
112
+ .slice(0, 3)
113
+ .map(Number);
114
+ if (parts.length !== 3 || parts.some((n) => Number.isNaN(n))) return null;
115
+ [r, g, b] = parts;
116
+ }
117
+ const max = Math.max(r, g, b);
118
+ const min = Math.min(r, g, b);
119
+ return max === 0 ? 0 : (max - min) / max;
120
+ }
121
+
83
122
  function colorTokens(svg: string): string[] {
84
123
  const tokens: string[] = [];
85
124
  let m: RegExpExecArray | null;
@@ -104,6 +143,11 @@ function colorTokens(svg: string): string[] {
104
143
  // and are left alone rather than aggressively inverted.
105
144
  const DARK_MAX = 0.22;
106
145
  const LIGHT_MIN = 0.6;
146
+ // At/above this HSV saturation a color is a brand hue, not a neutral. Only
147
+ // neutrals (black/gray/white) invert cleanly — inverting a saturated color
148
+ // rotates its hue (a blue mark becomes orange), which wrecks the brand. So a
149
+ // saturated mark is treated like a multi-color one: left exactly as authored.
150
+ const SAT_MAX = 0.4;
107
151
 
108
152
  export function classifyMarkTone(svg: string | null): MarkTone {
109
153
  if (!svg) return "adaptive";
@@ -111,6 +155,16 @@ export function classifyMarkTone(svg: string | null): MarkTone {
111
155
  // Any currentColor usage means the mark already adapts to the theme.
112
156
  if (tokens.some((t) => t.trim().toLowerCase() === "currentcolor")) return "adaptive";
113
157
 
158
+ // A saturated mark is a brand color — never invert it (the hue would flip).
159
+ if (
160
+ tokens.some((t) => {
161
+ const s = saturationOf(t);
162
+ return s !== null && s >= SAT_MAX;
163
+ })
164
+ ) {
165
+ return "mixed";
166
+ }
167
+
114
168
  const lums: number[] = [];
115
169
  for (const t of tokens) {
116
170
  const l = luminanceOf(t);