@peerproblem/sw3-ui 0.0.0-stage → 0.3.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.
Files changed (144) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +109 -2
  3. package/agent/components/accordion.md +95 -0
  4. package/agent/components/action-square.md +106 -0
  5. package/agent/components/agent-bridge.md +87 -0
  6. package/agent/components/agent-console.md +123 -0
  7. package/agent/components/alert-dialog.md +82 -0
  8. package/agent/components/app-shell.md +105 -0
  9. package/agent/components/area-chart.md +56 -0
  10. package/agent/components/async-options.md +47 -0
  11. package/agent/components/autocomplete.md +69 -0
  12. package/agent/components/avatar.md +88 -0
  13. package/agent/components/badge.md +51 -0
  14. package/agent/components/bar-chart.md +56 -0
  15. package/agent/components/bar-list.md +49 -0
  16. package/agent/components/breadcrumbs.md +43 -0
  17. package/agent/components/button.md +109 -0
  18. package/agent/components/calendar.md +114 -0
  19. package/agent/components/canvas.md +105 -0
  20. package/agent/components/card.md +78 -0
  21. package/agent/components/carousel.md +113 -0
  22. package/agent/components/chart-card.md +41 -0
  23. package/agent/components/chart-surface.md +56 -0
  24. package/agent/components/checkbox.md +88 -0
  25. package/agent/components/citation-chip.md +61 -0
  26. package/agent/components/collapsible.md +69 -0
  27. package/agent/components/color-picker.md +82 -0
  28. package/agent/components/combobox.md +104 -0
  29. package/agent/components/command.md +92 -0
  30. package/agent/components/dashboard-grid.md +73 -0
  31. package/agent/components/date-input.md +87 -0
  32. package/agent/components/date-picker.md +122 -0
  33. package/agent/components/dialog.md +97 -0
  34. package/agent/components/donut-chart.md +50 -0
  35. package/agent/components/drawer.md +101 -0
  36. package/agent/components/empty-state.md +52 -0
  37. package/agent/components/field.md +80 -0
  38. package/agent/components/file-input.md +84 -0
  39. package/agent/components/hover-card.md +64 -0
  40. package/agent/components/image-cropper.md +77 -0
  41. package/agent/components/input.md +49 -0
  42. package/agent/components/label.md +53 -0
  43. package/agent/components/line-chart.md +60 -0
  44. package/agent/components/listbox.md +84 -0
  45. package/agent/components/map-view.md +104 -0
  46. package/agent/components/menu.md +117 -0
  47. package/agent/components/menubar.md +67 -0
  48. package/agent/components/meter.md +59 -0
  49. package/agent/components/navigation-menu.md +98 -0
  50. package/agent/components/number-input.md +81 -0
  51. package/agent/components/otp-input.md +67 -0
  52. package/agent/components/pagination.md +80 -0
  53. package/agent/components/password-input.md +67 -0
  54. package/agent/components/pill-button.md +116 -0
  55. package/agent/components/popover.md +85 -0
  56. package/agent/components/poster-card.md +61 -0
  57. package/agent/components/preferences.md +92 -0
  58. package/agent/components/progress.md +63 -0
  59. package/agent/components/provider.md +47 -0
  60. package/agent/components/radio.md +91 -0
  61. package/agent/components/rating.md +66 -0
  62. package/agent/components/reorder.md +61 -0
  63. package/agent/components/resizable.md +87 -0
  64. package/agent/components/scatter-chart.md +49 -0
  65. package/agent/components/scroll-area.md +81 -0
  66. package/agent/components/segmented-control.md +56 -0
  67. package/agent/components/select.md +130 -0
  68. package/agent/components/separator.md +60 -0
  69. package/agent/components/shortcuts.md +50 -0
  70. package/agent/components/sidebar-nav.md +68 -0
  71. package/agent/components/skeleton.md +58 -0
  72. package/agent/components/slider.md +79 -0
  73. package/agent/components/sparkline.md +39 -0
  74. package/agent/components/squircle.md +58 -0
  75. package/agent/components/stat.md +58 -0
  76. package/agent/components/switch.md +48 -0
  77. package/agent/components/table.md +58 -0
  78. package/agent/components/tabs.md +108 -0
  79. package/agent/components/textarea.md +68 -0
  80. package/agent/components/time-input.md +84 -0
  81. package/agent/components/timeline.md +91 -0
  82. package/agent/components/toast.md +85 -0
  83. package/agent/components/toggle.md +76 -0
  84. package/agent/components/token-input.md +66 -0
  85. package/agent/components/toolbar.md +76 -0
  86. package/agent/components/tooltip.md +83 -0
  87. package/agent/components/tracker.md +47 -0
  88. package/agent/components/tree.md +87 -0
  89. package/agent/components/treemap.md +72 -0
  90. package/agent/components/trend-chart.md +80 -0
  91. package/agent/components/trigger-menu.md +67 -0
  92. package/agent/components/typography.md +51 -0
  93. package/agent/components/waterfall.md +78 -0
  94. package/agent/components/week-schedule.md +113 -0
  95. package/agent/llms/actions-and-layout.txt +1749 -0
  96. package/agent/llms/agents.txt +505 -0
  97. package/agent/llms/charts.txt +778 -0
  98. package/agent/llms/dashboards.txt +457 -0
  99. package/agent/llms/extend.txt +132 -0
  100. package/agent/llms/extras.txt +527 -0
  101. package/agent/llms/forms.txt +2152 -0
  102. package/agent/llms/foundations.txt +674 -0
  103. package/agent/llms/hooks.txt +178 -0
  104. package/agent/llms/maps.txt +229 -0
  105. package/agent/llms/overlays-and-navigation.txt +1167 -0
  106. package/agent/llms-full.txt +8717 -0
  107. package/agent/llms.txt +145 -0
  108. package/agent/registry.json +11289 -0
  109. package/agent/tokens.md +66 -0
  110. package/dist/agent/index.d.ts +235 -0
  111. package/dist/agent/index.js +21 -0
  112. package/dist/card-Ipm-Cj5f.d.ts +490 -0
  113. package/dist/charts/index.d.ts +289 -0
  114. package/dist/charts/index.js +815 -0
  115. package/dist/check/cli.d.ts +1 -0
  116. package/dist/check/cli.js +48 -0
  117. package/dist/check/rendered.d.ts +11 -0
  118. package/dist/check/rendered.js +77 -0
  119. package/dist/check/source.d.ts +13 -0
  120. package/dist/check/source.js +182 -0
  121. package/dist/chunk-3DXBM65D.js +65 -0
  122. package/dist/chunk-3H5X4ZP6.js +55 -0
  123. package/dist/chunk-6XC4BC5C.js +92 -0
  124. package/dist/chunk-7H6TEAWD.js +507 -0
  125. package/dist/chunk-I63ZTJOI.js +1089 -0
  126. package/dist/chunk-JCIRUM4W.js +33 -0
  127. package/dist/chunk-LTBEHZ3P.js +25 -0
  128. package/dist/chunk-QDPPLO4U.js +60 -0
  129. package/dist/chunk-U2XFBPU4.js +56 -0
  130. package/dist/chunk-UY2WH5AY.js +681 -0
  131. package/dist/extras.d.ts +203 -0
  132. package/dist/extras.js +904 -0
  133. package/dist/icons-BJiGEAnU.d.ts +68 -0
  134. package/dist/index.d.ts +3737 -0
  135. package/dist/index.js +14477 -0
  136. package/dist/map/index.d.ts +115 -0
  137. package/dist/map/index.js +394 -0
  138. package/dist/meta/index.d.ts +3314 -0
  139. package/dist/meta/index.js +5106 -0
  140. package/dist/rules-1RIZ_JZr.d.ts +38 -0
  141. package/dist/styles.css +4037 -0
  142. package/dist/themes/calm.css +42 -0
  143. package/dist/themes/frost.css +40 -0
  144. package/package.json +142 -4
@@ -0,0 +1 @@
1
+ #!/usr/bin/env node
@@ -0,0 +1,48 @@
1
+ #!/usr/bin/env node
2
+ 'use client';
3
+
4
+ // src/check/cli.ts
5
+ import { readdirSync, readFileSync, statSync } from "fs";
6
+ import { join } from "path";
7
+ var supported = /\.(?:[jt]sx|css)$/i;
8
+ var ignored = /* @__PURE__ */ new Set(["node_modules", "dist", "build", "coverage"]);
9
+ function* files(path) {
10
+ if (!statSync(path).isDirectory()) {
11
+ if (!supported.test(path)) throw new Error(`Expected a .tsx, .jsx, or .css file: ${path}`);
12
+ yield path;
13
+ return;
14
+ }
15
+ for (const item of readdirSync(path, { withFileTypes: true })) {
16
+ if (item.name.startsWith(".") || ignored.has(item.name)) continue;
17
+ const child = join(path, item.name);
18
+ if (item.isDirectory()) yield* files(child);
19
+ else if (item.isFile() && supported.test(item.name)) yield child;
20
+ }
21
+ }
22
+ async function main(paths) {
23
+ if (paths.length === 1 && ["--help", "-h"].includes(paths[0])) {
24
+ console.log("Usage: sw3-check <file-or-directory> [...]\nOutputs JSON diagnostics with the rule, source location, and suggested fix.");
25
+ return;
26
+ }
27
+ if (!paths.length) throw new Error("Usage: sw3-check <file-or-directory> [...]");
28
+ const diagnostics = [];
29
+ const inputs = new Set(paths.flatMap((path) => [...files(path)]));
30
+ if (!inputs.size) throw new Error("No .tsx, .jsx, or .css files found.");
31
+ const { checkDesignSource } = await import("./source.js").catch((error) => {
32
+ if (error.code === "ERR_MODULE_NOT_FOUND" && error.message.includes("package 'typescript'")) {
33
+ throw new Error("Install TypeScript to check source files: npm install -D typescript@^5.9.3");
34
+ }
35
+ throw error;
36
+ });
37
+ for (const file of [...inputs].sort()) {
38
+ diagnostics.push(...checkDesignSource(readFileSync(file, "utf8"), file));
39
+ }
40
+ console.log(JSON.stringify(diagnostics, null, 2));
41
+ if (diagnostics.length) process.exitCode = 1;
42
+ }
43
+ try {
44
+ await main(process.argv.slice(2));
45
+ } catch (error) {
46
+ console.error(error instanceof Error ? error.message : String(error));
47
+ process.exitCode = 2;
48
+ }
@@ -0,0 +1,11 @@
1
+ import { D as DesignFinding } from '../rules-1RIZ_JZr.js';
2
+ export { a as DesignRule } from '../rules-1RIZ_JZr.js';
3
+
4
+ interface RenderedDesignDiagnostic extends DesignFinding {
5
+ selector: string;
6
+ }
7
+ /** Check the current DOM for a single view. Supply the view root after React has rendered. */
8
+ declare function checkDesign(root: Element): RenderedDesignDiagnostic[];
9
+
10
+ export { DesignFinding, checkDesign };
11
+ export type { RenderedDesignDiagnostic };
@@ -0,0 +1,77 @@
1
+ 'use client';
2
+ import {
3
+ finding,
4
+ styleRule
5
+ } from "../chunk-3DXBM65D.js";
6
+
7
+ // src/check/rendered.ts
8
+ function selectorFor(element) {
9
+ const parts = [];
10
+ for (let node = element; node; node = node.parentElement) {
11
+ if (node.id && node.ownerDocument.getElementById(node.id) === node) {
12
+ parts.unshift(`#${CSS.escape(node.id)}`);
13
+ break;
14
+ }
15
+ const tag = CSS.escape(node.localName);
16
+ const siblings = node.parentElement?.children;
17
+ parts.unshift(siblings ? `${tag}:nth-child(${Array.prototype.indexOf.call(siblings, node) + 1})` : tag);
18
+ }
19
+ return parts.join(" > ");
20
+ }
21
+ function visible(element) {
22
+ if (element.closest('[hidden], [inert], [aria-hidden="true"]')) return false;
23
+ const view = element.ownerDocument.defaultView;
24
+ if (!view) return false;
25
+ const { visibility } = view.getComputedStyle(element);
26
+ if (visibility === "hidden" || visibility === "collapse") return false;
27
+ for (let node = element; node; node = node.parentElement) {
28
+ if (view.getComputedStyle(node).display === "none") return false;
29
+ }
30
+ return true;
31
+ }
32
+ function checkDesign(root) {
33
+ const diagnostics = [];
34
+ const report = (rule, node) => {
35
+ diagnostics.push({ ...finding(rule), selector: selectorFor(node) });
36
+ };
37
+ const matching = (selector) => [
38
+ ...root.matches(selector) ? [root] : [],
39
+ ...root.querySelectorAll(selector)
40
+ ];
41
+ let hasAccent = false;
42
+ for (const button of matching('[data-sw="button"][data-variant="accent"]')) {
43
+ if (!visible(button)) continue;
44
+ if (hasAccent) report("accent-count", button);
45
+ hasAccent = true;
46
+ }
47
+ for (const chart of matching('[data-sw="chart"]:not([data-chart="sparkline"])')) {
48
+ if (!visible(chart)) continue;
49
+ const card = chart.parentElement?.closest('[data-sw="chart-card"], [data-sw="dashboard-tile"], [data-sw="card"][data-layout="panel"]');
50
+ if (!card || !root.contains(card)) report("chart-card", chart);
51
+ if (!chart.getAttribute("aria-label")?.trim()) report("chart-label", chart);
52
+ }
53
+ for (const group of matching('[data-sw="toggle-group"]:not([data-multiple]):not([data-deselectable])')) {
54
+ if (!visible(group) || group.closest('[role="toolbar"]')) continue;
55
+ report("toggle-group-choice", group);
56
+ }
57
+ const framed = '[data-sw="card"][data-framed], [data-sw="listbox"][data-framed], [data-sw="dashboard-grid"][data-variant="joined"], [data-sw="accordion"][data-variant="framed"]';
58
+ for (const node of matching(framed)) {
59
+ if (!visible(node) || node.parentElement?.closest('[data-sw="dashboard-grid"][data-variant="gapped"]')) continue;
60
+ const outer = node.parentElement?.closest(`${framed}, [data-sw="app-shell-main"], [data-sw="dashboard-grid"][data-variant="flush"]`);
61
+ if (outer && root.contains(outer)) report("nested-frame", node);
62
+ }
63
+ for (const node of matching("[style]")) {
64
+ if (node.closest("[data-sw]") || !visible(node)) continue;
65
+ const style = node.style;
66
+ const rules = /* @__PURE__ */ new Set();
67
+ for (const name of Array.from(style ?? [])) {
68
+ const rule = styleRule(name, style.getPropertyValue(name));
69
+ if (rule) rules.add(rule);
70
+ }
71
+ for (const rule of rules) report(rule, node);
72
+ }
73
+ return diagnostics;
74
+ }
75
+ export {
76
+ checkDesign
77
+ };
@@ -0,0 +1,13 @@
1
+ import { D as DesignFinding } from '../rules-1RIZ_JZr.js';
2
+ export { a as DesignRule } from '../rules-1RIZ_JZr.js';
3
+
4
+ interface DesignDiagnostic extends DesignFinding {
5
+ file: string;
6
+ line: number;
7
+ column: number;
8
+ }
9
+ /** Check app-owned TSX/JSX or CSS. Source positions are one-based. */
10
+ declare function checkDesignSource(source: string, file: string): DesignDiagnostic[];
11
+
12
+ export { DesignFinding, checkDesignSource };
13
+ export type { DesignDiagnostic };
@@ -0,0 +1,182 @@
1
+ 'use client';
2
+ import {
3
+ radius
4
+ } from "../chunk-6XC4BC5C.js";
5
+ import {
6
+ finding,
7
+ styleRule
8
+ } from "../chunk-3DXBM65D.js";
9
+
10
+ // src/check/source.ts
11
+ import postcss from "postcss";
12
+ import ts from "typescript";
13
+ var charts = /* @__PURE__ */ new Set(["LineChart", "AreaChart", "BarChart", "ScatterChart", "DonutChart", "Treemap", "ChartSurface"]);
14
+ var sdkModules = /* @__PURE__ */ new Set(["@peerproblem/sw3-ui", "@peerproblem/sw3-ui/charts", "@peerproblem/sw3-ui/map"]);
15
+ function unwrap(node) {
16
+ while (ts.isParenthesizedExpression(node) || ts.isAsExpression(node) || ts.isSatisfiesExpression(node) || ts.isTypeAssertionExpression(node) || ts.isNonNullExpression(node)) node = node.expression;
17
+ return node;
18
+ }
19
+ function literal(node) {
20
+ if (!node) return;
21
+ if (ts.isExpression(node)) node = unwrap(node);
22
+ if (ts.isStringLiteralLike(node)) return node.text;
23
+ if (ts.isNumericLiteral(node)) return Number(node.text);
24
+ if (ts.isPrefixUnaryExpression(node) && ts.isNumericLiteral(node.operand)) return node.getText();
25
+ if (node.kind === ts.SyntaxKind.NullKeyword) return null;
26
+ if (node.kind === ts.SyntaxKind.TrueKeyword || node.kind === ts.SyntaxKind.FalseKeyword) return node.kind === ts.SyntaxKind.TrueKeyword;
27
+ }
28
+ function attribute(node) {
29
+ if (!node) return;
30
+ const value = node.initializer;
31
+ if (!value) return true;
32
+ return ts.isJsxExpression(value) ? literal(value.expression) : literal(value);
33
+ }
34
+ function checkDesignSource(source, file) {
35
+ const diagnostics = [];
36
+ const report = (rule, line, column) => {
37
+ diagnostics.push({ ...finding(rule), file, line, column });
38
+ };
39
+ if (/\.css$/i.test(file)) {
40
+ postcss.parse(source, { from: file }).walkDecls((declaration) => {
41
+ const rule = styleRule(declaration.prop.toLowerCase(), declaration.value);
42
+ const start = declaration.source?.start;
43
+ if (rule && start) report(rule, start.line, start.column);
44
+ });
45
+ return diagnostics;
46
+ }
47
+ if (!/\.[jt]sx$/i.test(file)) throw new Error(`Expected a .tsx, .jsx, or .css file: ${file}`);
48
+ const tree = ts.createSourceFile(file, source, ts.ScriptTarget.Latest, true);
49
+ const options = { noLib: true, noResolve: true, allowJs: true, jsx: ts.JsxEmit.Preserve };
50
+ const host = ts.createCompilerHost(options);
51
+ host.getSourceFile = () => tree;
52
+ const program = ts.createProgram([file], options, host);
53
+ const syntaxError = program.getSyntacticDiagnostics(tree)[0];
54
+ if (syntaxError) {
55
+ const { line, character } = tree.getLineAndCharacterOfPosition(syntaxError.start ?? 0);
56
+ throw new Error(`${file}:${line + 1}:${character + 1}: ${ts.flattenDiagnosticMessageText(syntaxError.messageText, " ")}`);
57
+ }
58
+ const symbols = program.getTypeChecker();
59
+ const names = /* @__PURE__ */ new Map();
60
+ const namespaces = /* @__PURE__ */ new Map();
61
+ for (const stmt of tree.statements) {
62
+ if (!ts.isImportDeclaration(stmt) || !ts.isStringLiteral(stmt.moduleSpecifier)) continue;
63
+ const module = stmt.moduleSpecifier.text;
64
+ const bindings = stmt.importClause?.namedBindings;
65
+ if (!bindings || stmt.importClause?.isTypeOnly || !sdkModules.has(module)) continue;
66
+ if (ts.isNamespaceImport(bindings)) {
67
+ const symbol = symbols.getSymbolAtLocation(bindings.name);
68
+ if (symbol) namespaces.set(symbol, module);
69
+ } else {
70
+ for (const entry of bindings.elements) {
71
+ const symbol = symbols.getSymbolAtLocation(entry.name);
72
+ if (symbol && !entry.isTypeOnly) names.set(symbol, { name: entry.propertyName?.text ?? entry.name.text, module });
73
+ }
74
+ }
75
+ }
76
+ const component = (tag) => {
77
+ if (ts.isIdentifier(tag)) {
78
+ const symbol = symbols.getSymbolAtLocation(tag);
79
+ if (symbol) return names.get(symbol);
80
+ }
81
+ if (ts.isPropertyAccessExpression(tag) && ts.isIdentifier(tag.expression)) {
82
+ const symbol = symbols.getSymbolAtLocation(tag.expression);
83
+ const module = symbol && namespaces.get(symbol);
84
+ if (module) return { name: tag.name.text, module };
85
+ }
86
+ };
87
+ const at = (rule, node) => {
88
+ const { line, character } = tree.getLineAndCharacterOfPosition(node.getStart(tree));
89
+ report(rule, line + 1, character + 1);
90
+ };
91
+ const inspectStyle = (expression) => {
92
+ const style = unwrap(expression);
93
+ if (!ts.isObjectLiteralExpression(style)) return;
94
+ for (const item of style.properties) {
95
+ if (!ts.isPropertyAssignment(item)) continue;
96
+ const name = ts.isIdentifier(item.name) ? item.name.text : literal(item.name);
97
+ if (typeof name !== "string") continue;
98
+ const rule = styleRule(name, String(literal(item.initializer) ?? ""));
99
+ if (rule) at(rule, item);
100
+ }
101
+ };
102
+ const inspectColors = (expression) => {
103
+ const list = unwrap(expression);
104
+ if (!ts.isArrayLiteralExpression(list)) return;
105
+ for (const entry of list.elements) {
106
+ if (!ts.isObjectLiteralExpression(entry)) continue;
107
+ for (const item of entry.properties) {
108
+ if (!ts.isPropertyAssignment(item)) continue;
109
+ const name = ts.isIdentifier(item.name) ? item.name.text : literal(item.name);
110
+ const value = literal(item.initializer);
111
+ if (name === "color" && typeof value === "string" && styleRule("color", value)) at("color-token", item);
112
+ }
113
+ }
114
+ };
115
+ const accents = /* @__PURE__ */ new Map();
116
+ function visit(node, root, inCard = false, branches = /* @__PURE__ */ new Map()) {
117
+ if (ts.isConditionalExpression(node)) {
118
+ const condition = literal(node.condition);
119
+ if (condition !== void 0) {
120
+ visit(condition ? node.whenTrue : node.whenFalse, root, inCard, branches);
121
+ return;
122
+ }
123
+ root ??= node;
124
+ visit(node.condition, root, inCard, branches);
125
+ visit(node.whenTrue, root, inCard, new Map([...branches, [node, true]]));
126
+ visit(node.whenFalse, root, inCard, new Map([...branches, [node, false]]));
127
+ return;
128
+ }
129
+ if (ts.isBinaryExpression(node) && node.operatorToken.kind === ts.SyntaxKind.AmpersandAmpersandToken && literal(node.left) === false) return;
130
+ if (ts.isJsxElement(node) || ts.isJsxFragment(node) || ts.isJsxSelfClosingElement(node) || ts.isArrayLiteralExpression(node)) {
131
+ root ??= node;
132
+ }
133
+ const opening = ts.isJsxElement(node) ? node.openingElement : ts.isJsxSelfClosingElement(node) ? node : void 0;
134
+ const sdk = opening && component(opening.tagName);
135
+ inCard ||= sdk?.module === "@peerproblem/sw3-ui/charts" && sdk.name === "ChartCard" || sdk?.module === "@peerproblem/sw3-ui" && (sdk.name === "DashboardTile" || sdk.name === "Card");
136
+ if (opening) {
137
+ const node2 = opening;
138
+ const props = node2.attributes.properties;
139
+ const prop = (name) => {
140
+ for (let i = props.length - 1; i >= 0; i--) {
141
+ const item = props[i];
142
+ if (!ts.isJsxAttribute(item)) return;
143
+ if (item.name.getText(tree) === name) return item;
144
+ }
145
+ };
146
+ if (root && sdk?.module === "@peerproblem/sw3-ui" && sdk.name === "Button" && attribute(prop("variant")) === "accent") {
147
+ const previous = accents.get(root) ?? [];
148
+ if (previous.some((path) => [...branches].every(([condition, side]) => !path.has(condition) || path.get(condition) === side))) at("accent-count", node2);
149
+ previous.push(branches);
150
+ accents.set(root, previous);
151
+ }
152
+ if (sdk?.module === "@peerproblem/sw3-ui/charts" && charts.has(sdk.name)) {
153
+ if (!inCard) at("chart-card", node2);
154
+ const label = prop("aria-label");
155
+ const value = attribute(label);
156
+ if (!label && !props.some(ts.isJsxSpreadAttribute) || label?.initializer && ts.isJsxExpression(label.initializer) && label.initializer.expression?.getText(tree) === "undefined" || value !== void 0 && (typeof value !== "string" || !value.trim())) at("chart-label", label ?? node2);
157
+ }
158
+ for (const item of props) {
159
+ if (!ts.isJsxAttribute(item)) continue;
160
+ const name = item.name.getText(tree);
161
+ if (name.startsWith("data-") || name.startsWith("aria-")) continue;
162
+ const value = attribute(item);
163
+ if (name === "style" && item.initializer && ts.isJsxExpression(item.initializer) && item.initializer.expression) {
164
+ inspectStyle(item.initializer.expression);
165
+ } else if (sdk?.module === "@peerproblem/sw3-ui/charts" && (["series", "legend", "groups"].includes(name) || sdk.name === "DonutChart" && name === "data") && item.initializer && ts.isJsxExpression(item.initializer) && item.initializer.expression) {
166
+ inspectColors(item.initializer.expression);
167
+ } else if (name === "radius" && sdk && value !== void 0 && (typeof value !== "string" || !Object.hasOwn(radius, value))) {
168
+ at("radius-token", item);
169
+ } else if (typeof value === "string" && (sdk || /^[a-z]/.test(node2.tagName.getText(tree)))) {
170
+ const rule = styleRule(name, value);
171
+ if (rule) at(rule, item);
172
+ }
173
+ }
174
+ }
175
+ ts.forEachChild(node, (child) => visit(child, root, inCard, branches));
176
+ }
177
+ visit(tree);
178
+ return diagnostics.sort((a, b) => a.line - b.line || a.column - b.column);
179
+ }
180
+ export {
181
+ checkDesignSource
182
+ };
@@ -0,0 +1,65 @@
1
+ 'use client';
2
+
3
+ // src/check/rules.ts
4
+ import { color } from "d3-color";
5
+ var designRules = {
6
+ "accent-count": {
7
+ message: "This view has more than one accent button.",
8
+ fix: 'Keep the accent on the main action. Set this Button to variant="primary", "secondary", "outline", or "ghost".'
9
+ },
10
+ "chart-card": {
11
+ message: "This chart needs a ChartCard, DashboardTile or a Card with a title in the checked view.",
12
+ fix: 'Wrap the chart in <ChartCard title="\u2026"> from @peerproblem/sw3-ui/charts, or put it in a titled <DashboardTile> or <Card title="\u2026">.'
13
+ },
14
+ "chart-label": {
15
+ message: "This chart needs a non-empty aria-label.",
16
+ fix: "Set aria-label on the chart itself to a short sentence describing the takeaway."
17
+ },
18
+ "color-token": {
19
+ message: "This color bypasses the SW3 palette.",
20
+ fix: "Use an SW3 color token such as var(--sw-foreground), var(--sw-background), or var(--sw-chart-1) for a chart series."
21
+ },
22
+ "nested-frame": {
23
+ message: "This framed surface sits inside another frame (frame-in-frame).",
24
+ fix: "Drop the inner frame: inside AppShellMain use a flush DashboardGrid; inside a panel Card or Accordion leave Cards and Listboxes unframed (the default). Group with lines and spacing, not boxes."
25
+ },
26
+ "toggle-group-choice": {
27
+ message: "This single-choice ToggleGroup always keeps a value and sits outside a toolbar, so it works as a value or view picker.",
28
+ fix: "Use SegmentedControl to pick one value or view. Keep ToggleGroup for formatting buttons inside a Toolbar (bold, alignment) or for multi-select (`multiple`)."
29
+ },
30
+ "radius-token": {
31
+ message: "This corner radius bypasses the SW3 squircle tokens.",
32
+ fix: 'Remove the CSS radius and use an SW3 surface with a token prop such as radius="md".'
33
+ }
34
+ };
35
+ function finding(rule) {
36
+ return { rule, ...designRules[rule] };
37
+ }
38
+ var radiusProperty = /^(?:-webkit-)?border-(?:radius|(?:top|bottom)-(?:left|right)-radius|(?:start|end)-(?:start|end)-radius)$/;
39
+ var colorProperty = /^(?:color|fill|stroke|flood-color|lighting-color|stop-color|(?:.+-)?color)$/;
40
+ var paintProperty = /^(?:background|background-image|border(?:-(?:top|left|bottom|right|inline|block)(?:-(?:start|end))?)?|outline|box-shadow|text-shadow|text-decoration)$/;
41
+ var colorOverride = /^--sw-(?:sq-(?:bg|border|ring)|.*(?:-color|-bg|-background|-foreground|-fill|-stroke))$/;
42
+ var radiusOverride = /^--sw-.*-radius$/;
43
+ var literalColor = /#[\da-f]{3,8}\b|\b(?:rgba?|hsla?|hwb|lab|lch|oklab|oklch|color|light-dark|device-cmyk)\(/i;
44
+ var colorKeywords = /^(?:transparent|currentcolor|none|inherit|initial|unset|revert(?:-layer)?)$/i;
45
+ function styleRule(property, value) {
46
+ const name = property.startsWith("--") ? property : property.replace(/[A-Z]/g, (c) => `-${c.toLowerCase()}`).toLowerCase();
47
+ if (radiusProperty.test(name)) return "radius-token";
48
+ const normalized = value.replace(/\/\*[\s\S]*?\*\//g, "").trim();
49
+ if (radiusOverride.test(name)) return /^(?:0|var\(\s*--sw-radius-[\w-]+\s*\))$/.test(normalized) ? void 0 : "radius-token";
50
+ const directColor = colorProperty.test(name) || colorOverride.test(name);
51
+ if (!directColor && !paintProperty.test(name)) return;
52
+ const paint = normalized.replace(/url\(\s*(?:"[^"]*"|'[^']*'|[^)]*)\)|"[^"]*"|'[^']*'/gi, "");
53
+ if (literalColor.test(paint)) return "color-token";
54
+ if (!paint.trim() || colorKeywords.test(paint)) return;
55
+ const references = [...paint.matchAll(/\bvar\(\s*(--[\w-]+)/gi)];
56
+ if (references.some(([, token]) => !token.startsWith("--sw-"))) return "color-token";
57
+ const withoutVariables = paint.replace(/\bvar\(\s*--[\w-]+/gi, "(");
58
+ if ((withoutVariables.match(/\b[a-z]+\b/gi) ?? []).some((word) => !colorKeywords.test(word) && color(word) !== null)) return "color-token";
59
+ if (directColor && references.length === 0) return "color-token";
60
+ }
61
+
62
+ export {
63
+ finding,
64
+ styleRule
65
+ };
@@ -0,0 +1,55 @@
1
+ 'use client';
2
+ import {
3
+ cx
4
+ } from "./chunk-UY2WH5AY.js";
5
+
6
+ // src/components/typography.tsx
7
+ import { forwardRef } from "react";
8
+ import { jsx } from "react/jsx-runtime";
9
+ function Display({ as: As = "h1", size = "lg", className, ...p }) {
10
+ return /* @__PURE__ */ jsx(As, { "data-sw": "display", "data-size": size, className: cx("sw-display", className), ...p });
11
+ }
12
+ function Outline({ children }) {
13
+ return /* @__PURE__ */ jsx("span", { className: "sw-outline", children });
14
+ }
15
+ function Heading({ as: As = "h2", size = "md", className, ...p }) {
16
+ return /* @__PURE__ */ jsx(As, { "data-sw": "heading", "data-size": size, className: cx("sw-heading", className), ...p });
17
+ }
18
+ function Text({ as: As = "p", size = "base", tone = "default", className, ...p }) {
19
+ return /* @__PURE__ */ jsx(As, { "data-sw": "text", "data-size": size, "data-tone": tone, className: cx("sw-text", className), ...p });
20
+ }
21
+ var Link = forwardRef(function Link2({ className, ...props }, ref) {
22
+ return /* @__PURE__ */ jsx("a", { ...props, ref, className: cx("sw-link", className), "data-sw": "link" });
23
+ });
24
+ function Caption({ className, ...p }) {
25
+ return /* @__PURE__ */ jsx("span", { "data-sw": "caption", className: cx("sw-caption", className), ...p });
26
+ }
27
+ function Kbd({ className, ...p }) {
28
+ return /* @__PURE__ */ jsx("kbd", { "data-sw": "kbd", className: cx("sw-kbd", className), ...p });
29
+ }
30
+
31
+ // src/primitives/element-size.ts
32
+ import { useLayoutEffect, useState } from "react";
33
+ function useElementWidth(ref) {
34
+ const [width, setWidth] = useState(0);
35
+ useLayoutEffect(() => {
36
+ const el = ref.current;
37
+ if (!el || typeof ResizeObserver === "undefined") return;
38
+ setWidth(el.getBoundingClientRect().width);
39
+ const ro = new ResizeObserver(([entry]) => setWidth(entry.contentRect.width));
40
+ ro.observe(el);
41
+ return () => ro.disconnect();
42
+ }, [ref]);
43
+ return width;
44
+ }
45
+
46
+ export {
47
+ Display,
48
+ Outline,
49
+ Heading,
50
+ Text,
51
+ Link,
52
+ Caption,
53
+ Kbd,
54
+ useElementWidth
55
+ };
@@ -0,0 +1,92 @@
1
+ 'use client';
2
+
3
+ // src/tokens/tokens.ts
4
+ var color = {
5
+ canvas: { light: "#f0f2f5", dark: "#101010", usage: "Page background behind cards and posters." },
6
+ background: { light: "#ffffff", dark: "#0a0a0a", usage: "Surface of cards, inputs and posters." },
7
+ foreground: { light: "#0a0a0a", dark: "#fafafa", usage: "Primary text and the primary (ink) button fill." },
8
+ muted: { light: "#f5f5f5", dark: "#262626", usage: "Quiet fills: secondary buttons, tracks, wells." },
9
+ "muted-foreground": { light: "#6f6f6f", dark: "#a1a1a1", usage: "Secondary text, captions, axis labels." },
10
+ subtle: { light: "#5d5d5d", dark: "#a4a4a4", usage: "Body copy one step quieter than foreground." },
11
+ frame: { light: "#c8c8c8", dark: "#303030", usage: "Card and poster borders (1px)." },
12
+ hairline: { light: "#ebebeb", dark: "#1b1b1b", usage: "Dividers, hatch patterns, grid lines." },
13
+ border: { light: "#e5e5e5", dark: "rgba(255,255,255,0.1)", usage: "Input and control borders." },
14
+ accent: { light: "#424242", dark: "#c9c9c9", usage: "Emphasis for text, focus rings and selected indicators. Apps can supply a brand color." },
15
+ "accent-solid": { light: "#0a0a0a", dark: "#fafafa", usage: "Fill for accent buttons and selected controls." },
16
+ "accent-solid-hover": { light: "#2d2d2d", dark: "#dedede", usage: "Hover fill for accent-solid." },
17
+ "accent-foreground": { light: "#ffffff", dark: "#0a0a0a", usage: "Text and marks on accent-solid." },
18
+ success: { light: "#00a74a", dark: "#7bf1a8", usage: "Positive deltas, success state." },
19
+ warning: { light: "#c27800", dark: "#f5b544", usage: "Caution: meters in the sub-optimum range, warning toasts." },
20
+ danger: { light: "#e40014", dark: "#ff6568", usage: "Destructive actions, negative deltas, errors." },
21
+ selection: { light: "#e4e4e4", dark: "#323232", usage: "Text selection and soft selected backgrounds." }
22
+ };
23
+ var chart = {
24
+ light: ["#006bff", "#0a0a0a", "#00a74a", "#ff7a00", "#8b5cf6", "#e40014", "#00b8d9", "#a1a1a1"],
25
+ dark: ["#5fa1f3", "#fafafa", "#7bf1a8", "#ffa94d", "#b197fc", "#ff6568", "#66d9e8", "#737373"]
26
+ };
27
+ var radius = {
28
+ none: 0,
29
+ xs: 6,
30
+ sm: 10,
31
+ md: 14,
32
+ lg: 20,
33
+ xl: 28,
34
+ "2xl": 36,
35
+ full: 9999
36
+ };
37
+ var smoothing = {
38
+ none: 0,
39
+ soft: 0.6,
40
+ max: 1
41
+ };
42
+ var space = {
43
+ 0: 0,
44
+ 1: 4,
45
+ 2: 8,
46
+ 3: 12,
47
+ 4: 16,
48
+ 5: 20,
49
+ 6: 24,
50
+ 8: 32,
51
+ 10: 40,
52
+ 12: 48,
53
+ 16: 64,
54
+ 20: 80
55
+ };
56
+ var font = {
57
+ sans: "'Geist Variable', 'Geist', ui-sans-serif, system-ui, -apple-system, sans-serif",
58
+ mono: "'Geist Mono Variable', 'Geist Mono', ui-monospace, 'SF Mono', Menlo, monospace"
59
+ };
60
+ var type = {
61
+ caption: { size: 11, line: 1.55, tracking: "0.08em", weight: 400, family: "mono", usage: "UPPERCASE mono labels on posters." },
62
+ xs: { size: 12, line: 1.33, tracking: "0", weight: 400, family: "sans", usage: "Meta text, badges." },
63
+ sm: { size: 14, line: 1.43, tracking: "0", weight: 400, family: "sans", usage: "Descriptions, secondary text." },
64
+ base: { size: 16, line: 1.5, tracking: "-0.011em", weight: 400, family: "sans", usage: "Body copy." },
65
+ lg: { size: 20, line: 1.5, tracking: "-0.015em", weight: 400, family: "sans", usage: "Lede paragraphs." },
66
+ title: { size: 24, line: 1.2, tracking: "-0.03em", weight: 450, family: "sans", usage: "Card titles, big buttons." },
67
+ heading: { size: 48, line: 1.08, tracking: "-0.045em", weight: 450, family: "sans", usage: "Section headings." },
68
+ display: { size: 72, line: 1, tracking: "-0.055em", weight: 450, family: "sans", usage: "Hero and poster words." }
69
+ };
70
+ var motion = {
71
+ duration: { instant: 0.1, fast: 0.15, base: 0.2, slow: 0.35, slower: 0.6 },
72
+ ease: {
73
+ standard: [0.4, 0, 0.2, 1],
74
+ out: [0, 0, 0.2, 1],
75
+ in: [0.4, 0, 1, 1],
76
+ emphasized: [0.2, 0, 0, 1]
77
+ },
78
+ spring: {
79
+ snappy: { type: "spring", stiffness: 520, damping: 34, mass: 0.7 },
80
+ gentle: { type: "spring", stiffness: 260, damping: 28 },
81
+ bouncy: { type: "spring", stiffness: 400, damping: 18 }
82
+ }
83
+ };
84
+ var tokens = { color, chart, radius, smoothing, space, font, type, motion };
85
+
86
+ export {
87
+ color,
88
+ radius,
89
+ smoothing,
90
+ motion,
91
+ tokens
92
+ };