tokka 0.2.3 → 0.2.5

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,478 @@
1
+ import { z } from 'zod';
2
+
3
+ declare const tokenTypeSchema: z.ZodEnum<["color", "number", "dimension", "radius", "shadow", "typography", "motion", "opacity", "zIndex"]>;
4
+ declare const tokenSourceSchema: z.ZodEnum<["primitive", "semantic", "component"]>;
5
+ declare const tokenSchema: z.ZodEffects<z.ZodObject<{
6
+ id: z.ZodString;
7
+ type: z.ZodEnum<["color", "number", "dimension", "radius", "shadow", "typography", "motion", "opacity", "zIndex"]>;
8
+ description: z.ZodString;
9
+ source: z.ZodEnum<["primitive", "semantic", "component"]>;
10
+ value: z.ZodOptional<z.ZodAny>;
11
+ modes: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
12
+ references: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
13
+ tags: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
14
+ deprecated: z.ZodOptional<z.ZodBoolean>;
15
+ replacedBy: z.ZodOptional<z.ZodString>;
16
+ figma: z.ZodOptional<z.ZodObject<{
17
+ collection: z.ZodOptional<z.ZodString>;
18
+ scopes: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
19
+ variableName: z.ZodOptional<z.ZodString>;
20
+ }, "strip", z.ZodTypeAny, {
21
+ collection?: string | undefined;
22
+ scopes?: string[] | undefined;
23
+ variableName?: string | undefined;
24
+ }, {
25
+ collection?: string | undefined;
26
+ scopes?: string[] | undefined;
27
+ variableName?: string | undefined;
28
+ }>>;
29
+ }, "strip", z.ZodTypeAny, {
30
+ id: string;
31
+ description: string;
32
+ type: "number" | "radius" | "motion" | "color" | "dimension" | "shadow" | "typography" | "opacity" | "zIndex";
33
+ source: "primitive" | "semantic" | "component";
34
+ value?: any;
35
+ tags?: string[] | undefined;
36
+ modes?: Record<string, any> | undefined;
37
+ figma?: {
38
+ collection?: string | undefined;
39
+ scopes?: string[] | undefined;
40
+ variableName?: string | undefined;
41
+ } | undefined;
42
+ references?: string[] | undefined;
43
+ deprecated?: boolean | undefined;
44
+ replacedBy?: string | undefined;
45
+ }, {
46
+ id: string;
47
+ description: string;
48
+ type: "number" | "radius" | "motion" | "color" | "dimension" | "shadow" | "typography" | "opacity" | "zIndex";
49
+ source: "primitive" | "semantic" | "component";
50
+ value?: any;
51
+ tags?: string[] | undefined;
52
+ modes?: Record<string, any> | undefined;
53
+ figma?: {
54
+ collection?: string | undefined;
55
+ scopes?: string[] | undefined;
56
+ variableName?: string | undefined;
57
+ } | undefined;
58
+ references?: string[] | undefined;
59
+ deprecated?: boolean | undefined;
60
+ replacedBy?: string | undefined;
61
+ }>, {
62
+ id: string;
63
+ description: string;
64
+ type: "number" | "radius" | "motion" | "color" | "dimension" | "shadow" | "typography" | "opacity" | "zIndex";
65
+ source: "primitive" | "semantic" | "component";
66
+ value?: any;
67
+ tags?: string[] | undefined;
68
+ modes?: Record<string, any> | undefined;
69
+ figma?: {
70
+ collection?: string | undefined;
71
+ scopes?: string[] | undefined;
72
+ variableName?: string | undefined;
73
+ } | undefined;
74
+ references?: string[] | undefined;
75
+ deprecated?: boolean | undefined;
76
+ replacedBy?: string | undefined;
77
+ }, {
78
+ id: string;
79
+ description: string;
80
+ type: "number" | "radius" | "motion" | "color" | "dimension" | "shadow" | "typography" | "opacity" | "zIndex";
81
+ source: "primitive" | "semantic" | "component";
82
+ value?: any;
83
+ tags?: string[] | undefined;
84
+ modes?: Record<string, any> | undefined;
85
+ figma?: {
86
+ collection?: string | undefined;
87
+ scopes?: string[] | undefined;
88
+ variableName?: string | undefined;
89
+ } | undefined;
90
+ references?: string[] | undefined;
91
+ deprecated?: boolean | undefined;
92
+ replacedBy?: string | undefined;
93
+ }>;
94
+ type Token = z.infer<typeof tokenSchema>;
95
+ type TokenType = z.infer<typeof tokenTypeSchema>;
96
+ type TokenSource = z.infer<typeof tokenSourceSchema>;
97
+ declare const tokenFileSchema: z.ZodObject<{
98
+ tokens: z.ZodArray<z.ZodEffects<z.ZodObject<{
99
+ id: z.ZodString;
100
+ type: z.ZodEnum<["color", "number", "dimension", "radius", "shadow", "typography", "motion", "opacity", "zIndex"]>;
101
+ description: z.ZodString;
102
+ source: z.ZodEnum<["primitive", "semantic", "component"]>;
103
+ value: z.ZodOptional<z.ZodAny>;
104
+ modes: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
105
+ references: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
106
+ tags: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
107
+ deprecated: z.ZodOptional<z.ZodBoolean>;
108
+ replacedBy: z.ZodOptional<z.ZodString>;
109
+ figma: z.ZodOptional<z.ZodObject<{
110
+ collection: z.ZodOptional<z.ZodString>;
111
+ scopes: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
112
+ variableName: z.ZodOptional<z.ZodString>;
113
+ }, "strip", z.ZodTypeAny, {
114
+ collection?: string | undefined;
115
+ scopes?: string[] | undefined;
116
+ variableName?: string | undefined;
117
+ }, {
118
+ collection?: string | undefined;
119
+ scopes?: string[] | undefined;
120
+ variableName?: string | undefined;
121
+ }>>;
122
+ }, "strip", z.ZodTypeAny, {
123
+ id: string;
124
+ description: string;
125
+ type: "number" | "radius" | "motion" | "color" | "dimension" | "shadow" | "typography" | "opacity" | "zIndex";
126
+ source: "primitive" | "semantic" | "component";
127
+ value?: any;
128
+ tags?: string[] | undefined;
129
+ modes?: Record<string, any> | undefined;
130
+ figma?: {
131
+ collection?: string | undefined;
132
+ scopes?: string[] | undefined;
133
+ variableName?: string | undefined;
134
+ } | undefined;
135
+ references?: string[] | undefined;
136
+ deprecated?: boolean | undefined;
137
+ replacedBy?: string | undefined;
138
+ }, {
139
+ id: string;
140
+ description: string;
141
+ type: "number" | "radius" | "motion" | "color" | "dimension" | "shadow" | "typography" | "opacity" | "zIndex";
142
+ source: "primitive" | "semantic" | "component";
143
+ value?: any;
144
+ tags?: string[] | undefined;
145
+ modes?: Record<string, any> | undefined;
146
+ figma?: {
147
+ collection?: string | undefined;
148
+ scopes?: string[] | undefined;
149
+ variableName?: string | undefined;
150
+ } | undefined;
151
+ references?: string[] | undefined;
152
+ deprecated?: boolean | undefined;
153
+ replacedBy?: string | undefined;
154
+ }>, {
155
+ id: string;
156
+ description: string;
157
+ type: "number" | "radius" | "motion" | "color" | "dimension" | "shadow" | "typography" | "opacity" | "zIndex";
158
+ source: "primitive" | "semantic" | "component";
159
+ value?: any;
160
+ tags?: string[] | undefined;
161
+ modes?: Record<string, any> | undefined;
162
+ figma?: {
163
+ collection?: string | undefined;
164
+ scopes?: string[] | undefined;
165
+ variableName?: string | undefined;
166
+ } | undefined;
167
+ references?: string[] | undefined;
168
+ deprecated?: boolean | undefined;
169
+ replacedBy?: string | undefined;
170
+ }, {
171
+ id: string;
172
+ description: string;
173
+ type: "number" | "radius" | "motion" | "color" | "dimension" | "shadow" | "typography" | "opacity" | "zIndex";
174
+ source: "primitive" | "semantic" | "component";
175
+ value?: any;
176
+ tags?: string[] | undefined;
177
+ modes?: Record<string, any> | undefined;
178
+ figma?: {
179
+ collection?: string | undefined;
180
+ scopes?: string[] | undefined;
181
+ variableName?: string | undefined;
182
+ } | undefined;
183
+ references?: string[] | undefined;
184
+ deprecated?: boolean | undefined;
185
+ replacedBy?: string | undefined;
186
+ }>, "many">;
187
+ }, "strip", z.ZodTypeAny, {
188
+ tokens: {
189
+ id: string;
190
+ description: string;
191
+ type: "number" | "radius" | "motion" | "color" | "dimension" | "shadow" | "typography" | "opacity" | "zIndex";
192
+ source: "primitive" | "semantic" | "component";
193
+ value?: any;
194
+ tags?: string[] | undefined;
195
+ modes?: Record<string, any> | undefined;
196
+ figma?: {
197
+ collection?: string | undefined;
198
+ scopes?: string[] | undefined;
199
+ variableName?: string | undefined;
200
+ } | undefined;
201
+ references?: string[] | undefined;
202
+ deprecated?: boolean | undefined;
203
+ replacedBy?: string | undefined;
204
+ }[];
205
+ }, {
206
+ tokens: {
207
+ id: string;
208
+ description: string;
209
+ type: "number" | "radius" | "motion" | "color" | "dimension" | "shadow" | "typography" | "opacity" | "zIndex";
210
+ source: "primitive" | "semantic" | "component";
211
+ value?: any;
212
+ tags?: string[] | undefined;
213
+ modes?: Record<string, any> | undefined;
214
+ figma?: {
215
+ collection?: string | undefined;
216
+ scopes?: string[] | undefined;
217
+ variableName?: string | undefined;
218
+ } | undefined;
219
+ references?: string[] | undefined;
220
+ deprecated?: boolean | undefined;
221
+ replacedBy?: string | undefined;
222
+ }[];
223
+ }>;
224
+ type TokenFile = z.infer<typeof tokenFileSchema>;
225
+ declare const systemSchema: z.ZodObject<{
226
+ id: z.ZodString;
227
+ name: z.ZodString;
228
+ description: z.ZodString;
229
+ tags: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
230
+ modes: z.ZodArray<z.ZodString, "many">;
231
+ policies: z.ZodOptional<z.ZodObject<{
232
+ radius: z.ZodOptional<z.ZodEnum<["sharp", "rounded", "pill"]>>;
233
+ density: z.ZodOptional<z.ZodEnum<["compact", "comfortable", "spacious"]>>;
234
+ contrast: z.ZodOptional<z.ZodEnum<["low", "medium", "high"]>>;
235
+ motion: z.ZodOptional<z.ZodEnum<["none", "subtle", "expressive"]>>;
236
+ }, "strip", z.ZodTypeAny, {
237
+ radius?: "sharp" | "rounded" | "pill" | undefined;
238
+ density?: "compact" | "comfortable" | "spacious" | undefined;
239
+ contrast?: "low" | "medium" | "high" | undefined;
240
+ motion?: "none" | "subtle" | "expressive" | undefined;
241
+ }, {
242
+ radius?: "sharp" | "rounded" | "pill" | undefined;
243
+ density?: "compact" | "comfortable" | "spacious" | undefined;
244
+ contrast?: "low" | "medium" | "high" | undefined;
245
+ motion?: "none" | "subtle" | "expressive" | undefined;
246
+ }>>;
247
+ defaults: z.ZodOptional<z.ZodObject<{
248
+ font: z.ZodOptional<z.ZodString>;
249
+ iconStyle: z.ZodOptional<z.ZodString>;
250
+ }, "strip", z.ZodTypeAny, {
251
+ font?: string | undefined;
252
+ iconStyle?: string | undefined;
253
+ }, {
254
+ font?: string | undefined;
255
+ iconStyle?: string | undefined;
256
+ }>>;
257
+ figma: z.ZodOptional<z.ZodObject<{
258
+ collections: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
259
+ }, "strip", z.ZodTypeAny, {
260
+ collections?: string[] | undefined;
261
+ }, {
262
+ collections?: string[] | undefined;
263
+ }>>;
264
+ }, "strip", z.ZodTypeAny, {
265
+ id: string;
266
+ name: string;
267
+ description: string;
268
+ modes: string[];
269
+ tags?: string[] | undefined;
270
+ policies?: {
271
+ radius?: "sharp" | "rounded" | "pill" | undefined;
272
+ density?: "compact" | "comfortable" | "spacious" | undefined;
273
+ contrast?: "low" | "medium" | "high" | undefined;
274
+ motion?: "none" | "subtle" | "expressive" | undefined;
275
+ } | undefined;
276
+ defaults?: {
277
+ font?: string | undefined;
278
+ iconStyle?: string | undefined;
279
+ } | undefined;
280
+ figma?: {
281
+ collections?: string[] | undefined;
282
+ } | undefined;
283
+ }, {
284
+ id: string;
285
+ name: string;
286
+ description: string;
287
+ modes: string[];
288
+ tags?: string[] | undefined;
289
+ policies?: {
290
+ radius?: "sharp" | "rounded" | "pill" | undefined;
291
+ density?: "compact" | "comfortable" | "spacious" | undefined;
292
+ contrast?: "low" | "medium" | "high" | undefined;
293
+ motion?: "none" | "subtle" | "expressive" | undefined;
294
+ } | undefined;
295
+ defaults?: {
296
+ font?: string | undefined;
297
+ iconStyle?: string | undefined;
298
+ } | undefined;
299
+ figma?: {
300
+ collections?: string[] | undefined;
301
+ } | undefined;
302
+ }>;
303
+ type System = z.infer<typeof systemSchema>;
304
+ interface ResolvedToken extends Token {
305
+ resolvedValue?: string;
306
+ resolvedModes?: Record<string, string>;
307
+ }
308
+ interface CompilationContext {
309
+ tokens: Token[];
310
+ system: System;
311
+ mode: "tier0" | "tier1" | "tier2";
312
+ }
313
+ interface CompilationResult {
314
+ tokens: ResolvedToken[];
315
+ errors: CompilationError[];
316
+ warnings: CompilationWarning[];
317
+ }
318
+ interface CompilationError {
319
+ type: "schema" | "reference" | "cycle" | "naming" | "layering";
320
+ message: string;
321
+ tokenId?: string;
322
+ }
323
+ interface CompilationWarning {
324
+ type: "unused" | "deprecated" | "missing-mode";
325
+ message: string;
326
+ tokenId?: string;
327
+ }
328
+
329
+ interface LoadOptions {
330
+ cwd: string;
331
+ tokensDir?: string;
332
+ }
333
+ interface LoadedTokens {
334
+ primitives: Token[];
335
+ semantics: Token[];
336
+ components: Token[];
337
+ all: Token[];
338
+ }
339
+ /**
340
+ * Load token files from a project directory
341
+ */
342
+ declare function loadTokens(options: LoadOptions): Promise<LoadedTokens>;
343
+ /**
344
+ * Load system metadata
345
+ */
346
+ declare function loadSystem(options: LoadOptions): Promise<System>;
347
+ /**
348
+ * Check if tokens directory exists
349
+ */
350
+ declare function hasTokens(cwd: string): Promise<boolean>;
351
+ /**
352
+ * Check if system.json exists
353
+ */
354
+ declare function hasSystem(cwd: string): Promise<boolean>;
355
+
356
+ /**
357
+ * Validate token naming conventions
358
+ */
359
+ declare function validateTokenNaming(tokens: Token[]): CompilationError[];
360
+ /**
361
+ * Validate token uniqueness
362
+ */
363
+ declare function validateTokenUniqueness(tokens: Token[]): CompilationError[];
364
+ /**
365
+ * Validate token references exist
366
+ */
367
+ declare function validateTokenReferences(tokens: Token[]): CompilationError[];
368
+ /**
369
+ * Validate token layering rules (Tier 2 only)
370
+ */
371
+ declare function validateTokenLayering(tokens: Token[], strict?: boolean): CompilationError[];
372
+ /**
373
+ * Validate mode coverage
374
+ */
375
+ declare function validateModeCoverage(tokens: Token[], requiredModes: string[]): CompilationError[];
376
+ /**
377
+ * Run all validations
378
+ */
379
+ declare function validateTokens(tokens: Token[], requiredModes: string[], options?: {
380
+ strict?: boolean;
381
+ }): CompilationError[];
382
+
383
+ /**
384
+ * Build a dependency graph from token references
385
+ */
386
+ declare function buildDependencyGraph(tokens: Token[]): Map<string, Set<string>>;
387
+ /**
388
+ * Detect cycles in the dependency graph
389
+ */
390
+ declare function detectCycles(graph: Map<string, Set<string>>): string[][];
391
+ /**
392
+ * Topological sort of tokens by dependencies
393
+ */
394
+ declare function topologicalSort(tokens: Token[], graph: Map<string, Set<string>>): Token[];
395
+ /**
396
+ * Resolve token values (alias-only in v1)
397
+ */
398
+ declare function resolveTokens(tokens: Token[], graph: Map<string, Set<string>>): {
399
+ resolved: ResolvedToken[];
400
+ errors: CompilationError[];
401
+ };
402
+
403
+ interface CSSGeneratorOptions {
404
+ modeSelector?: {
405
+ strategy: "class" | "data-attribute";
406
+ selectors?: {
407
+ light: string;
408
+ dark: string;
409
+ [key: string]: string;
410
+ };
411
+ };
412
+ }
413
+ /**
414
+ * Convert token ID to CSS variable name
415
+ * surface.brand → --surface-brand
416
+ * button.primary.bg → --button-primary-bg
417
+ */
418
+ declare function tokenIdToCSSVar(id: string): string;
419
+ /**
420
+ * Parse color value to HSL triplet format
421
+ * Supports: hsl(...), oklch(...), hex, rgb(...)
422
+ */
423
+ declare function parseColorToHSLTriplet(value: string): string;
424
+ /**
425
+ * Generate CSS variables for a mode
426
+ */
427
+ declare function generateCSSForMode(tokens: ResolvedToken[], mode: string | "default", options?: CSSGeneratorOptions): string;
428
+ /**
429
+ * Generate complete CSS output
430
+ */
431
+ declare function generateCSS(tokens: ResolvedToken[], system: System, options?: CSSGeneratorOptions): string;
432
+ /**
433
+ * Generate CSS output files
434
+ */
435
+ interface CSSOutput {
436
+ "tokens.css": string;
437
+ }
438
+ declare function generateCSSOutput(tokens: ResolvedToken[], system: System, options?: CSSGeneratorOptions): CSSOutput;
439
+
440
+ /**
441
+ * Generate Tailwind config mapping semantic tokens to CSS vars
442
+ */
443
+ declare function generateTailwindConfig(tokens: ResolvedToken[], _system: System): Record<string, any>;
444
+ /**
445
+ * Generate Tailwind config file content
446
+ */
447
+ declare function generateTailwindOutput(tokens: ResolvedToken[], system: System): string;
448
+
449
+ /**
450
+ * Generate TypeScript token map with full typing
451
+ */
452
+ declare function generateTypeScript(tokens: ResolvedToken[], system: System): string;
453
+ /**
454
+ * Generate TypeScript output
455
+ */
456
+ interface TypeScriptOutput {
457
+ "tokens.ts": string;
458
+ }
459
+ declare function generateTypeScriptOutput(tokens: ResolvedToken[], system: System): TypeScriptOutput;
460
+
461
+ /**
462
+ * Generate Tokens Studio compatible format
463
+ */
464
+ declare function generateFigmaTokens(tokens: ResolvedToken[], _system: System): Record<string, any>;
465
+ /**
466
+ * Generate Figma token export file
467
+ */
468
+ interface FigmaTokenOutput {
469
+ "tokka.tokens.json": string;
470
+ }
471
+ declare function generateFigmaTokenOutput(tokens: ResolvedToken[], system: System): FigmaTokenOutput;
472
+
473
+ /**
474
+ * Main compilation function
475
+ */
476
+ declare function compile(options: LoadOptions): Promise<CompilationResult>;
477
+
478
+ export { type CSSGeneratorOptions, type CSSOutput, type CompilationContext, type CompilationError, type CompilationResult, type CompilationWarning, type FigmaTokenOutput, type LoadOptions, type LoadedTokens, type ResolvedToken, type System, type Token, type TokenFile, type TokenSource, type TokenType, type TypeScriptOutput, buildDependencyGraph, compile, detectCycles, generateCSS, generateCSSForMode, generateCSSOutput, generateFigmaTokenOutput, generateFigmaTokens, generateTailwindConfig, generateTailwindOutput, generateTypeScript, generateTypeScriptOutput, hasSystem, hasTokens, loadSystem, loadTokens, parseColorToHSLTriplet, resolveTokens, systemSchema, tokenFileSchema, tokenIdToCSSVar, tokenSchema, tokenSourceSchema, tokenTypeSchema, topologicalSort, validateModeCoverage, validateTokenLayering, validateTokenNaming, validateTokenReferences, validateTokenUniqueness, validateTokens };