@cobwds/mcp-server 1.19.3
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/README.md +235 -0
- package/data/cem/custom-elements.json +15923 -0
- package/data/guides/.gitkeep +0 -0
- package/data/guides/fonts.md +56 -0
- package/data/guides/form-validation.md +169 -0
- package/data/guides/frameworks/angular.md +71 -0
- package/data/guides/frameworks/dotnet.md +42 -0
- package/data/guides/frameworks/drupal.md +39 -0
- package/data/guides/frameworks/react.md +115 -0
- package/data/guides/frameworks/vanilla.md +45 -0
- package/data/guides/installation.md +73 -0
- package/data/guides/page-structure.md +161 -0
- package/data/guides/styles.md +48 -0
- package/data/guides/themes.md +61 -0
- package/data/tokens/tokens.css +479 -0
- package/data/tokens/tokens.json +1553 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +16 -0
- package/dist/lib/cem-parser.d.ts +102 -0
- package/dist/lib/cem-parser.d.ts.map +1 -0
- package/dist/lib/cem-parser.js +92 -0
- package/dist/lib/search.d.ts +20 -0
- package/dist/lib/search.d.ts.map +1 -0
- package/dist/lib/search.js +87 -0
- package/dist/lib/token-parser.d.ts +128 -0
- package/dist/lib/token-parser.d.ts.map +1 -0
- package/dist/lib/token-parser.js +431 -0
- package/dist/prompts/cobwds-mode.d.ts +8 -0
- package/dist/prompts/cobwds-mode.d.ts.map +1 -0
- package/dist/prompts/cobwds-mode.js +60 -0
- package/dist/resources/components.d.ts +12 -0
- package/dist/resources/components.d.ts.map +1 -0
- package/dist/resources/components.js +62 -0
- package/dist/resources/guides.d.ts +11 -0
- package/dist/resources/guides.d.ts.map +1 -0
- package/dist/resources/guides.js +76 -0
- package/dist/resources/index.d.ts +8 -0
- package/dist/resources/index.d.ts.map +1 -0
- package/dist/resources/index.js +13 -0
- package/dist/resources/tokens.d.ts +17 -0
- package/dist/resources/tokens.d.ts.map +1 -0
- package/dist/resources/tokens.js +312 -0
- package/dist/server.d.ts +11 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +30 -0
- package/dist/tools/component-tools.d.ts +12 -0
- package/dist/tools/component-tools.d.ts.map +1 -0
- package/dist/tools/component-tools.js +95 -0
- package/dist/tools/guide-tools.d.ts +9 -0
- package/dist/tools/guide-tools.d.ts.map +1 -0
- package/dist/tools/guide-tools.js +80 -0
- package/dist/tools/index.d.ts +8 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +17 -0
- package/dist/tools/token-tools.d.ts +13 -0
- package/dist/tools/token-tools.d.ts.map +1 -0
- package/dist/tools/token-tools.js +207 -0
- package/dist/tools/utility-tools.d.ts +8 -0
- package/dist/tools/utility-tools.d.ts.map +1 -0
- package/dist/tools/utility-tools.js +293 -0
- package/dist/tools/validation-tools.d.ts +11 -0
- package/dist/tools/validation-tools.d.ts.map +1 -0
- package/dist/tools/validation-tools.js +60 -0
- package/package.json +54 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA;;;;;GAKG"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* COBWDS MCP Server Entry Point
|
|
4
|
+
*
|
|
5
|
+
* Starts the MCP server with stdio transport for local execution.
|
|
6
|
+
* Run via: npx @cobwds/mcp-server
|
|
7
|
+
*/
|
|
8
|
+
import { createServer } from "./server.js";
|
|
9
|
+
async function main() {
|
|
10
|
+
const server = await createServer();
|
|
11
|
+
await server.start();
|
|
12
|
+
}
|
|
13
|
+
main().catch((error) => {
|
|
14
|
+
console.error("Failed to start COBWDS MCP server:", error);
|
|
15
|
+
process.exit(1);
|
|
16
|
+
});
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Custom Elements Manifest Parser
|
|
3
|
+
*
|
|
4
|
+
* Reads and parses the custom-elements.json manifest from @cobwds/components.
|
|
5
|
+
*/
|
|
6
|
+
export interface CEMAttribute {
|
|
7
|
+
name: string;
|
|
8
|
+
type?: {
|
|
9
|
+
text: string;
|
|
10
|
+
};
|
|
11
|
+
default?: string;
|
|
12
|
+
description?: string;
|
|
13
|
+
fieldName?: string;
|
|
14
|
+
}
|
|
15
|
+
export interface CEMMember {
|
|
16
|
+
kind: "field" | "method";
|
|
17
|
+
name: string;
|
|
18
|
+
type?: {
|
|
19
|
+
text: string;
|
|
20
|
+
};
|
|
21
|
+
default?: string;
|
|
22
|
+
description?: string;
|
|
23
|
+
privacy?: "public" | "private" | "protected";
|
|
24
|
+
attribute?: string;
|
|
25
|
+
}
|
|
26
|
+
export interface CEMEvent {
|
|
27
|
+
name: string;
|
|
28
|
+
type?: {
|
|
29
|
+
text: string;
|
|
30
|
+
};
|
|
31
|
+
description?: string;
|
|
32
|
+
}
|
|
33
|
+
export interface CEMSlot {
|
|
34
|
+
name: string;
|
|
35
|
+
description?: string;
|
|
36
|
+
}
|
|
37
|
+
export interface CEMCssProperty {
|
|
38
|
+
name: string;
|
|
39
|
+
default?: string;
|
|
40
|
+
description?: string;
|
|
41
|
+
}
|
|
42
|
+
export interface CEMCssPart {
|
|
43
|
+
name: string;
|
|
44
|
+
description?: string;
|
|
45
|
+
}
|
|
46
|
+
export interface CEMExample {
|
|
47
|
+
title: string;
|
|
48
|
+
code: string;
|
|
49
|
+
lang?: string;
|
|
50
|
+
}
|
|
51
|
+
export interface CEMDeclaration {
|
|
52
|
+
kind: "class";
|
|
53
|
+
name: string;
|
|
54
|
+
tagName?: string;
|
|
55
|
+
summary?: string;
|
|
56
|
+
description?: string;
|
|
57
|
+
attributes?: CEMAttribute[];
|
|
58
|
+
members?: CEMMember[];
|
|
59
|
+
events?: CEMEvent[];
|
|
60
|
+
slots?: CEMSlot[];
|
|
61
|
+
cssProperties?: CEMCssProperty[];
|
|
62
|
+
cssParts?: CEMCssPart[];
|
|
63
|
+
superclass?: {
|
|
64
|
+
name: string;
|
|
65
|
+
package?: string;
|
|
66
|
+
};
|
|
67
|
+
examples?: CEMExample[];
|
|
68
|
+
}
|
|
69
|
+
export interface CEMModule {
|
|
70
|
+
kind: "javascript-module";
|
|
71
|
+
path: string;
|
|
72
|
+
declarations?: CEMDeclaration[];
|
|
73
|
+
exports?: Array<{
|
|
74
|
+
kind: string;
|
|
75
|
+
name: string;
|
|
76
|
+
declaration: {
|
|
77
|
+
name: string;
|
|
78
|
+
};
|
|
79
|
+
}>;
|
|
80
|
+
}
|
|
81
|
+
export interface CustomElementsManifest {
|
|
82
|
+
schemaVersion: string;
|
|
83
|
+
readme?: string;
|
|
84
|
+
modules: CEMModule[];
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Load and parse the Custom Elements Manifest
|
|
88
|
+
*/
|
|
89
|
+
export declare function getCEM(): CustomElementsManifest;
|
|
90
|
+
/**
|
|
91
|
+
* Get all component declarations from the manifest
|
|
92
|
+
*/
|
|
93
|
+
export declare function getAllComponents(): CEMDeclaration[];
|
|
94
|
+
/**
|
|
95
|
+
* Get a specific component by tag name
|
|
96
|
+
*/
|
|
97
|
+
export declare function getComponent(tagName: string): CEMDeclaration | undefined;
|
|
98
|
+
/**
|
|
99
|
+
* Clear the cached CEM (useful for testing)
|
|
100
|
+
*/
|
|
101
|
+
export declare function clearCache(): void;
|
|
102
|
+
//# sourceMappingURL=cem-parser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cem-parser.d.ts","sourceRoot":"","sources":["../../src/lib/cem-parser.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AASH,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;IACxB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS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S,EAAE,CAAC;IACtB,MAAM,CAAC,EAAE,QAAQ,EAAE,CAAC;IACpB,KAAK,CAAC,EAAE,OAAO,EAAE,CAAC;IAClB,aAAa,CAAC,EAAE,cAAc,EAAE,CAAC;IACjC,QAAQ,CAAC,EAAE,UAAU,EAAE,CAAC;IACxB,UAAU,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IAChD,QAAQ,CAAC,EAAE,UAAU,EAAE,CAAC;CACzB;AAED,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,mBAAmB,CAAC;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,CAAC,EAAE,cAAc,EAAE,CAAC;IAChC,OAAO,CAAC,EAAE,KAAK,CAAC;QACd,IAAI,EAAE,MAAM,CAAC;QACb,IAAI,EAAE,MAAM,CAAC;QACb,WAAW,EAAE;YAAE,IAAI,EAAE,MAAM,CAAA;SAAE,CAAC;KAC/B,CAAC,CAAC;CACJ;AAED,MAAM,WAAW,sBAAsB;IACrC,aAAa,EAAE,MAAM,CAAC;IACtB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,SAAS,EAAE,CAAC;CACtB;AAsCD;;GAEG;AACH,wBAAgB,MAAM,IAAI,sBAAsB,CAe/C;AAED;;GAEG;AACH,wBAAgB,gBAAgB,IAAI,cAAc,EAAE,CAoBnD;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,cAAc,GAAG,SAAS,CAOxE;AAED;;GAEG;AACH,wBAAgB,UAAU,IAAI,IAAI,CAIjC"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Custom Elements Manifest Parser
|
|
3
|
+
*
|
|
4
|
+
* Reads and parses the custom-elements.json manifest from @cobwds/components.
|
|
5
|
+
*/
|
|
6
|
+
import { readFileSync, existsSync } from "node:fs";
|
|
7
|
+
import { resolve, dirname } from "node:path";
|
|
8
|
+
import { fileURLToPath } from "node:url";
|
|
9
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
10
|
+
let cachedCEM = null;
|
|
11
|
+
let cachedComponents = null;
|
|
12
|
+
let cachedComponentMap = null;
|
|
13
|
+
/**
|
|
14
|
+
* Get the path to the custom-elements.json file
|
|
15
|
+
*/
|
|
16
|
+
function getCEMPath() {
|
|
17
|
+
const possiblePaths = [
|
|
18
|
+
// Bundled data — works in standalone installs (most reliable)
|
|
19
|
+
resolve(__dirname, "../../data/cem/custom-elements.json"),
|
|
20
|
+
// Relative to the package (when installed as dependency)
|
|
21
|
+
resolve(__dirname, "../../../node_modules/@cobwds/components/dist/custom-elements.json"),
|
|
22
|
+
// Root of monorepo (during development) - WHERE CEM ACTUALLY OUTPUTS
|
|
23
|
+
resolve(__dirname, "../../../../custom-elements.json"),
|
|
24
|
+
// Legacy dist location
|
|
25
|
+
resolve(__dirname, "../../../../dist/custom-elements.json"),
|
|
26
|
+
// Direct path for testing
|
|
27
|
+
resolve(process.cwd(), "custom-elements.json"),
|
|
28
|
+
resolve(process.cwd(), "dist/custom-elements.json"),
|
|
29
|
+
];
|
|
30
|
+
for (const path of possiblePaths) {
|
|
31
|
+
if (existsSync(path)) {
|
|
32
|
+
return path;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
throw new Error(`custom-elements.json not found. Searched paths:\n${possiblePaths.join("\n")}`);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Load and parse the Custom Elements Manifest
|
|
39
|
+
*/
|
|
40
|
+
export function getCEM() {
|
|
41
|
+
if (cachedCEM) {
|
|
42
|
+
return cachedCEM;
|
|
43
|
+
}
|
|
44
|
+
try {
|
|
45
|
+
const cemPath = getCEMPath();
|
|
46
|
+
const content = readFileSync(cemPath, "utf-8");
|
|
47
|
+
cachedCEM = JSON.parse(content);
|
|
48
|
+
return cachedCEM;
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
console.error("Warning: Could not load custom-elements.json:", error);
|
|
52
|
+
cachedCEM = { schemaVersion: "1.0.0", modules: [] };
|
|
53
|
+
return cachedCEM;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Get all component declarations from the manifest
|
|
58
|
+
*/
|
|
59
|
+
export function getAllComponents() {
|
|
60
|
+
if (cachedComponents)
|
|
61
|
+
return cachedComponents;
|
|
62
|
+
const cem = getCEM();
|
|
63
|
+
const components = [];
|
|
64
|
+
for (const module of cem.modules) {
|
|
65
|
+
if (module.declarations) {
|
|
66
|
+
for (const declaration of module.declarations) {
|
|
67
|
+
if (declaration.kind === "class" && declaration.tagName) {
|
|
68
|
+
components.push(declaration);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
cachedComponents = components.sort((a, b) => (a.tagName || "").localeCompare(b.tagName || ""));
|
|
74
|
+
return cachedComponents;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Get a specific component by tag name
|
|
78
|
+
*/
|
|
79
|
+
export function getComponent(tagName) {
|
|
80
|
+
if (!cachedComponentMap) {
|
|
81
|
+
cachedComponentMap = new Map(getAllComponents().map((c) => [c.tagName.toLowerCase(), c]));
|
|
82
|
+
}
|
|
83
|
+
return cachedComponentMap.get(tagName.toLowerCase());
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Clear the cached CEM (useful for testing)
|
|
87
|
+
*/
|
|
88
|
+
export function clearCache() {
|
|
89
|
+
cachedCEM = null;
|
|
90
|
+
cachedComponents = null;
|
|
91
|
+
cachedComponentMap = null;
|
|
92
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Search Utilities
|
|
3
|
+
*
|
|
4
|
+
* Fuzzy search functionality for components and tokens.
|
|
5
|
+
*/
|
|
6
|
+
export interface SearchResult {
|
|
7
|
+
tagName: string;
|
|
8
|
+
name: string;
|
|
9
|
+
summary: string;
|
|
10
|
+
score: number;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Search components by name or description
|
|
14
|
+
*/
|
|
15
|
+
export declare function searchComponents(query: string): SearchResult[];
|
|
16
|
+
/**
|
|
17
|
+
* Check if a string matches a search query
|
|
18
|
+
*/
|
|
19
|
+
export declare function matchesQuery(text: string, query: string): boolean;
|
|
20
|
+
//# sourceMappingURL=search.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"search.d.ts","sourceRoot":"","sources":["../../src/lib/search.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;CACf;AAsDD;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,YAAY,EAAE,CA8B9D;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAEjE"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Search Utilities
|
|
3
|
+
*
|
|
4
|
+
* Fuzzy search functionality for components and tokens.
|
|
5
|
+
*/
|
|
6
|
+
import { getAllComponents } from "./cem-parser.js";
|
|
7
|
+
/**
|
|
8
|
+
* Simple fuzzy matching score
|
|
9
|
+
* Returns a score between 0 and 1, where 1 is an exact match
|
|
10
|
+
*/
|
|
11
|
+
function fuzzyScore(query, text) {
|
|
12
|
+
const lowerQuery = query.toLowerCase();
|
|
13
|
+
const lowerText = text.toLowerCase();
|
|
14
|
+
// Exact match
|
|
15
|
+
if (lowerText === lowerQuery)
|
|
16
|
+
return 1;
|
|
17
|
+
// Contains exact query
|
|
18
|
+
if (lowerText.includes(lowerQuery)) {
|
|
19
|
+
// Bonus for matching at word boundaries
|
|
20
|
+
const wordBoundary = new RegExp(`\\b${escapeRegex(lowerQuery)}`, "i");
|
|
21
|
+
if (wordBoundary.test(lowerText)) {
|
|
22
|
+
return 0.9;
|
|
23
|
+
}
|
|
24
|
+
return 0.7;
|
|
25
|
+
}
|
|
26
|
+
// Character-by-character fuzzy match
|
|
27
|
+
let queryIndex = 0;
|
|
28
|
+
let score = 0;
|
|
29
|
+
let consecutiveBonus = 0;
|
|
30
|
+
for (let i = 0; i < lowerText.length && queryIndex < lowerQuery.length; i++) {
|
|
31
|
+
if (lowerText[i] === lowerQuery[queryIndex]) {
|
|
32
|
+
score += 1 + consecutiveBonus * 0.5;
|
|
33
|
+
consecutiveBonus++;
|
|
34
|
+
queryIndex++;
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
consecutiveBonus = 0;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
// Did we match all query characters?
|
|
41
|
+
if (queryIndex < lowerQuery.length) {
|
|
42
|
+
return 0;
|
|
43
|
+
}
|
|
44
|
+
// Normalize score
|
|
45
|
+
return Math.min(score / (lowerQuery.length * 2), 0.6);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Escape special regex characters
|
|
49
|
+
*/
|
|
50
|
+
function escapeRegex(str) {
|
|
51
|
+
return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Search components by name or description
|
|
55
|
+
*/
|
|
56
|
+
export function searchComponents(query) {
|
|
57
|
+
const components = getAllComponents();
|
|
58
|
+
const results = [];
|
|
59
|
+
for (const component of components) {
|
|
60
|
+
const tagName = component.tagName || "";
|
|
61
|
+
const name = component.name || "";
|
|
62
|
+
const description = component.description || "";
|
|
63
|
+
const summary = component.summary || description.split("\n")[0] || "";
|
|
64
|
+
// Calculate scores for different fields
|
|
65
|
+
const tagScore = fuzzyScore(query, tagName) * 1.2; // Boost tag matches
|
|
66
|
+
const nameScore = fuzzyScore(query, name) * 1.1;
|
|
67
|
+
const summaryScore = fuzzyScore(query, summary);
|
|
68
|
+
const descScore = fuzzyScore(query, description) * 0.8;
|
|
69
|
+
const maxScore = Math.max(tagScore, nameScore, summaryScore, descScore);
|
|
70
|
+
if (maxScore > 0) {
|
|
71
|
+
results.push({
|
|
72
|
+
tagName,
|
|
73
|
+
name,
|
|
74
|
+
summary,
|
|
75
|
+
score: maxScore,
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
// Sort by score descending
|
|
80
|
+
return results.sort((a, b) => b.score - a.score);
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Check if a string matches a search query
|
|
84
|
+
*/
|
|
85
|
+
export function matchesQuery(text, query) {
|
|
86
|
+
return fuzzyScore(query, text) > 0;
|
|
87
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Design Token Parser
|
|
3
|
+
*
|
|
4
|
+
* Reads and parses COBWDS design tokens with a CSS-centric approach.
|
|
5
|
+
* Returns data aligned with tokens.css output (not JSON internals).
|
|
6
|
+
*
|
|
7
|
+
* Key transformations:
|
|
8
|
+
* - Token paths are converted to CSS variable names
|
|
9
|
+
* - Alias references become var() expressions
|
|
10
|
+
* - Layer prefixes (primitive, applied) are stripped
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* CSS-centric token info aligned with tokens.css output
|
|
14
|
+
*/
|
|
15
|
+
export interface CSSTokenInfo {
|
|
16
|
+
/** CSS variable name, e.g., "--cob-color-text" */
|
|
17
|
+
cssVariable: string;
|
|
18
|
+
/** CSS value as it appears in tokens.css, e.g., "var(--cob-color-neutral-900)" or "#1b1b1b" */
|
|
19
|
+
cssValue: string;
|
|
20
|
+
/** If this is an alias, the variable it references, e.g., "--cob-color-neutral-900" */
|
|
21
|
+
referencesVariable?: string;
|
|
22
|
+
/** Fully resolved value for previews, e.g., "#1b1b1b" */
|
|
23
|
+
resolvedValue?: string;
|
|
24
|
+
/** Token description from $description field */
|
|
25
|
+
description?: string;
|
|
26
|
+
/** Token category (color, font, space, etc.) */
|
|
27
|
+
category: string;
|
|
28
|
+
/** Token layer (primitive, applied, color, etc.) */
|
|
29
|
+
layer: string;
|
|
30
|
+
/** Original JSON path for debugging */
|
|
31
|
+
jsonPath: string;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Token dependency graph node
|
|
35
|
+
*/
|
|
36
|
+
export interface TokenGraphNode {
|
|
37
|
+
cssVariable: string;
|
|
38
|
+
referencesVariable?: string;
|
|
39
|
+
usedBy: string[];
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Get the path to tokens.json file
|
|
43
|
+
* Uses ESM-compatible path resolution with fallbacks for different contexts
|
|
44
|
+
*/
|
|
45
|
+
export declare function getTokensPath(): string | null;
|
|
46
|
+
/**
|
|
47
|
+
* Get the path to tokens.css file
|
|
48
|
+
*/
|
|
49
|
+
export declare function getTokensCSSPath(): string | null;
|
|
50
|
+
/**
|
|
51
|
+
* Transform a JSON token path to CSS variable name
|
|
52
|
+
*
|
|
53
|
+
* Examples:
|
|
54
|
+
* - "primitive.color.neutral.900" → "--cob-color-neutral-900"
|
|
55
|
+
* - "applied.color.text.default" → "--cob-color-text"
|
|
56
|
+
* - "color.theme.default" → "--cob-color-theme"
|
|
57
|
+
* - "font.size.md" → "--cob-font-size-md"
|
|
58
|
+
*/
|
|
59
|
+
export declare function toCSSVariable(jsonPath: string): string;
|
|
60
|
+
/**
|
|
61
|
+
* Convert an alias reference to CSS var() syntax
|
|
62
|
+
*
|
|
63
|
+
* Examples:
|
|
64
|
+
* - "{primitive.color.neutral.900}" → "var(--cob-color-neutral-900)"
|
|
65
|
+
* - "{font.size.md}" → "var(--cob-font-size-md)"
|
|
66
|
+
*/
|
|
67
|
+
export declare function aliasToVarRef(aliasValue: string): {
|
|
68
|
+
cssValue: string;
|
|
69
|
+
referencesVariable: string;
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* Build a dependency graph of tokens
|
|
73
|
+
* Shows which tokens reference which, and which tokens are used by which
|
|
74
|
+
*/
|
|
75
|
+
export declare function buildTokenGraph(): Map<string, TokenGraphNode>;
|
|
76
|
+
/**
|
|
77
|
+
* Get all tokens in CSS-centric format
|
|
78
|
+
*/
|
|
79
|
+
export declare function getCSSTokens(): CSSTokenInfo[];
|
|
80
|
+
/**
|
|
81
|
+
* Get CSS tokens filtered by category
|
|
82
|
+
*/
|
|
83
|
+
export declare function getCSSTokensByCategory(category: string): CSSTokenInfo[];
|
|
84
|
+
/**
|
|
85
|
+
* Get a single token by CSS variable name
|
|
86
|
+
*/
|
|
87
|
+
export declare function getCSSTokenByVariable(variableName: string): CSSTokenInfo | undefined;
|
|
88
|
+
/**
|
|
89
|
+
* Get all unique categories
|
|
90
|
+
*/
|
|
91
|
+
export declare function getCSSTokenCategories(): {
|
|
92
|
+
category: string;
|
|
93
|
+
count: number;
|
|
94
|
+
}[];
|
|
95
|
+
/**
|
|
96
|
+
* Get raw tokens.css content
|
|
97
|
+
*/
|
|
98
|
+
export declare function getTokensCSS(): string | null;
|
|
99
|
+
/**
|
|
100
|
+
* Get recommended tokens for everyday use.
|
|
101
|
+
*
|
|
102
|
+
* Excludes color primitive tokens (the ~150 palette ramps like neutral-*, red-*,
|
|
103
|
+
* blue-*) which are low-level raw values. For font tokens, applied aliases
|
|
104
|
+
* (body-*, h*, ui-*) are sorted before primitives so the most useful tokens
|
|
105
|
+
* appear first.
|
|
106
|
+
*/
|
|
107
|
+
export declare function getRecommendedTokens(): CSSTokenInfo[];
|
|
108
|
+
/**
|
|
109
|
+
* Get only primitive (raw value) tokens across all categories.
|
|
110
|
+
*/
|
|
111
|
+
export declare function getPrimitiveTokens(): CSSTokenInfo[];
|
|
112
|
+
/**
|
|
113
|
+
* Get alternative tokens in the same category that share the same name prefix.
|
|
114
|
+
*
|
|
115
|
+
* First looks for child variants (tokens starting with this token's name + "-"):
|
|
116
|
+
* --cob-color-text → finds --cob-color-text-weak, --cob-color-text-reverse, etc.
|
|
117
|
+
*
|
|
118
|
+
* If no children exist, looks for siblings (tokens sharing the same parent prefix):
|
|
119
|
+
* --cob-color-text-weak → parent: --cob-color-text → finds text, text-weaker, etc.
|
|
120
|
+
*
|
|
121
|
+
* Returns an array of cssVariable strings (empty if none found).
|
|
122
|
+
*/
|
|
123
|
+
export declare function getAlternativeTokens(token: CSSTokenInfo): string[];
|
|
124
|
+
/**
|
|
125
|
+
* Clear all cached tokens (useful for testing)
|
|
126
|
+
*/
|
|
127
|
+
export declare function clearTokenCache(): void;
|
|
128
|
+
//# sourceMappingURL=token-parser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"token-parser.d.ts","sourceRoot":"","sources":["../../src/lib/token-parser.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAcH;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,kDAAkD;IAClD,WAAW,EAAE,MAAM,CAAC;IACpB,+FAA+F;IAC/F,QAAQ,EAAE,MAAM,CAAC;IACjB,uFAAuF;IACvF,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,yDAAyD;IACzD,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,gDAAgD;IAChD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,gDAAgD;IAChD,QAAQ,EAAE,MAAM,CAAC;IACjB,oDAAoD;IACpD,KAAK,EAAE,MAAM,CAAC;IACd,uCAAuC;IACvC,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,WAAW,EAAE,MAAM,CAAC;IACpB,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB;AAcD;;;GAGG;AACH,wBAAgB,aAAa,IAAI,MAAM,GAAG,IAAI,CAuB7C;AAED;;GAEG;AACH,wBAAgB,gB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