@lushly-dev/violet-core 0.0.0-stage → 0.3.0-preview.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 (179) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +35 -2
  3. package/dist/constraints/index.d.ts +7 -0
  4. package/dist/constraints/index.d.ts.map +1 -0
  5. package/dist/constraints/index.js +7 -0
  6. package/dist/constraints/index.js.map +1 -0
  7. package/dist/constraints/pattern-safety.d.ts +31 -0
  8. package/dist/constraints/pattern-safety.d.ts.map +1 -0
  9. package/dist/constraints/pattern-safety.js +113 -0
  10. package/dist/constraints/pattern-safety.js.map +1 -0
  11. package/dist/constraints/validators.d.ts +71 -0
  12. package/dist/constraints/validators.d.ts.map +1 -0
  13. package/dist/constraints/validators.js +363 -0
  14. package/dist/constraints/validators.js.map +1 -0
  15. package/dist/css/index.d.ts +9 -0
  16. package/dist/css/index.d.ts.map +1 -0
  17. package/dist/css/index.js +9 -0
  18. package/dist/css/index.js.map +1 -0
  19. package/dist/css/safe-css.d.ts +64 -0
  20. package/dist/css/safe-css.d.ts.map +1 -0
  21. package/dist/css/safe-css.js +309 -0
  22. package/dist/css/safe-css.js.map +1 -0
  23. package/dist/css/specimens.d.ts +15 -0
  24. package/dist/css/specimens.d.ts.map +1 -0
  25. package/dist/css/specimens.js +47 -0
  26. package/dist/css/specimens.js.map +1 -0
  27. package/dist/db/index.d.ts +13 -0
  28. package/dist/db/index.d.ts.map +1 -0
  29. package/dist/db/index.js +13 -0
  30. package/dist/db/index.js.map +1 -0
  31. package/dist/db/memory.d.ts +74 -0
  32. package/dist/db/memory.d.ts.map +1 -0
  33. package/dist/db/memory.js +354 -0
  34. package/dist/db/memory.js.map +1 -0
  35. package/dist/db/neon.d.ts +13 -0
  36. package/dist/db/neon.d.ts.map +1 -0
  37. package/dist/db/neon.js +52 -0
  38. package/dist/db/neon.js.map +1 -0
  39. package/dist/db/overlay.d.ts +70 -0
  40. package/dist/db/overlay.d.ts.map +1 -0
  41. package/dist/db/overlay.js +146 -0
  42. package/dist/db/overlay.js.map +1 -0
  43. package/dist/db/postgres.d.ts +107 -0
  44. package/dist/db/postgres.d.ts.map +1 -0
  45. package/dist/db/postgres.js +801 -0
  46. package/dist/db/postgres.js.map +1 -0
  47. package/dist/db/sqlite.d.ts +68 -0
  48. package/dist/db/sqlite.d.ts.map +1 -0
  49. package/dist/db/sqlite.js +769 -0
  50. package/dist/db/sqlite.js.map +1 -0
  51. package/dist/engine/index.d.ts +17 -0
  52. package/dist/engine/index.d.ts.map +1 -0
  53. package/dist/engine/index.js +17 -0
  54. package/dist/engine/index.js.map +1 -0
  55. package/dist/engine/inheritance-graph.d.ts +24 -0
  56. package/dist/engine/inheritance-graph.d.ts.map +1 -0
  57. package/dist/engine/inheritance-graph.js +60 -0
  58. package/dist/engine/inheritance-graph.js.map +1 -0
  59. package/dist/engine/resolution-cache.d.ts +83 -0
  60. package/dist/engine/resolution-cache.d.ts.map +1 -0
  61. package/dist/engine/resolution-cache.js +67 -0
  62. package/dist/engine/resolution-cache.js.map +1 -0
  63. package/dist/engine/resolver.d.ts +95 -0
  64. package/dist/engine/resolver.d.ts.map +1 -0
  65. package/dist/engine/resolver.js +531 -0
  66. package/dist/engine/resolver.js.map +1 -0
  67. package/dist/export/index.d.ts +21 -0
  68. package/dist/export/index.d.ts.map +1 -0
  69. package/dist/export/index.js +61 -0
  70. package/dist/export/index.js.map +1 -0
  71. package/dist/export/registry.d.ts +35 -0
  72. package/dist/export/registry.d.ts.map +1 -0
  73. package/dist/export/registry.js +45 -0
  74. package/dist/export/registry.js.map +1 -0
  75. package/dist/export/transformer.d.ts +103 -0
  76. package/dist/export/transformer.d.ts.map +1 -0
  77. package/dist/export/transformer.js +105 -0
  78. package/dist/export/transformer.js.map +1 -0
  79. package/dist/export/transformers/css.d.ts +8 -0
  80. package/dist/export/transformers/css.d.ts.map +1 -0
  81. package/dist/export/transformers/css.js +85 -0
  82. package/dist/export/transformers/css.js.map +1 -0
  83. package/dist/export/transformers/dart.d.ts +8 -0
  84. package/dist/export/transformers/dart.d.ts.map +1 -0
  85. package/dist/export/transformers/dart.js +174 -0
  86. package/dist/export/transformers/dart.js.map +1 -0
  87. package/dist/export/transformers/json.d.ts +8 -0
  88. package/dist/export/transformers/json.d.ts.map +1 -0
  89. package/dist/export/transformers/json.js +35 -0
  90. package/dist/export/transformers/json.js.map +1 -0
  91. package/dist/export/transformers/kotlin.d.ts +8 -0
  92. package/dist/export/transformers/kotlin.d.ts.map +1 -0
  93. package/dist/export/transformers/kotlin.js +177 -0
  94. package/dist/export/transformers/kotlin.js.map +1 -0
  95. package/dist/export/transformers/lua.d.ts +16 -0
  96. package/dist/export/transformers/lua.d.ts.map +1 -0
  97. package/dist/export/transformers/lua.js +167 -0
  98. package/dist/export/transformers/lua.js.map +1 -0
  99. package/dist/export/transformers/scss.d.ts +8 -0
  100. package/dist/export/transformers/scss.d.ts.map +1 -0
  101. package/dist/export/transformers/scss.js +83 -0
  102. package/dist/export/transformers/scss.js.map +1 -0
  103. package/dist/export/transformers/swift.d.ts +8 -0
  104. package/dist/export/transformers/swift.d.ts.map +1 -0
  105. package/dist/export/transformers/swift.js +189 -0
  106. package/dist/export/transformers/swift.js.map +1 -0
  107. package/dist/export/transformers/tailwind.d.ts +8 -0
  108. package/dist/export/transformers/tailwind.d.ts.map +1 -0
  109. package/dist/export/transformers/tailwind.js +241 -0
  110. package/dist/export/transformers/tailwind.js.map +1 -0
  111. package/dist/export/transformers/typescript.d.ts +8 -0
  112. package/dist/export/transformers/typescript.d.ts.map +1 -0
  113. package/dist/export/transformers/typescript.js +140 -0
  114. package/dist/export/transformers/typescript.js.map +1 -0
  115. package/dist/index.d.ts +16 -0
  116. package/dist/index.d.ts.map +1 -0
  117. package/dist/index.js +21 -0
  118. package/dist/index.js.map +1 -0
  119. package/dist/openapi/index.d.ts +1110 -0
  120. package/dist/openapi/index.d.ts.map +1 -0
  121. package/dist/openapi/index.js +933 -0
  122. package/dist/openapi/index.js.map +1 -0
  123. package/dist/storage.d.ts +39 -0
  124. package/dist/storage.d.ts.map +1 -0
  125. package/dist/storage.js +2 -0
  126. package/dist/storage.js.map +1 -0
  127. package/dist/tokens.d.ts +58 -0
  128. package/dist/tokens.d.ts.map +1 -0
  129. package/dist/tokens.js +117 -0
  130. package/dist/tokens.js.map +1 -0
  131. package/dist/types/constraint.d.ts +192 -0
  132. package/dist/types/constraint.d.ts.map +1 -0
  133. package/dist/types/constraint.js +110 -0
  134. package/dist/types/constraint.js.map +1 -0
  135. package/dist/types/error-codes.d.ts +30 -0
  136. package/dist/types/error-codes.d.ts.map +1 -0
  137. package/dist/types/error-codes.js +34 -0
  138. package/dist/types/error-codes.js.map +1 -0
  139. package/dist/types/index.d.ts +15 -0
  140. package/dist/types/index.d.ts.map +1 -0
  141. package/dist/types/index.js +15 -0
  142. package/dist/types/index.js.map +1 -0
  143. package/dist/types/node.d.ts +159 -0
  144. package/dist/types/node.d.ts.map +1 -0
  145. package/dist/types/node.js +89 -0
  146. package/dist/types/node.js.map +1 -0
  147. package/dist/types/operation.d.ts +315 -0
  148. package/dist/types/operation.d.ts.map +1 -0
  149. package/dist/types/operation.js +82 -0
  150. package/dist/types/operation.js.map +1 -0
  151. package/dist/types/snapshot.d.ts +60 -0
  152. package/dist/types/snapshot.d.ts.map +1 -0
  153. package/dist/types/snapshot.js +34 -0
  154. package/dist/types/snapshot.js.map +1 -0
  155. package/dist/types/specimen.d.ts +17 -0
  156. package/dist/types/specimen.d.ts.map +1 -0
  157. package/dist/types/specimen.js +9 -0
  158. package/dist/types/specimen.js.map +1 -0
  159. package/dist/types/token-id.d.ts +22 -0
  160. package/dist/types/token-id.d.ts.map +1 -0
  161. package/dist/types/token-id.js +43 -0
  162. package/dist/types/token-id.js.map +1 -0
  163. package/dist/types/token.d.ts +253 -0
  164. package/dist/types/token.d.ts.map +1 -0
  165. package/dist/types/token.js +96 -0
  166. package/dist/types/token.js.map +1 -0
  167. package/dist/types/webhook.d.ts +181 -0
  168. package/dist/types/webhook.d.ts.map +1 -0
  169. package/dist/types/webhook.js +7 -0
  170. package/dist/types/webhook.js.map +1 -0
  171. package/dist/utils/glob.d.ts +22 -0
  172. package/dist/utils/glob.d.ts.map +1 -0
  173. package/dist/utils/glob.js +47 -0
  174. package/dist/utils/glob.js.map +1 -0
  175. package/dist/worker.d.ts +12 -0
  176. package/dist/worker.d.ts.map +1 -0
  177. package/dist/worker.js +11 -0
  178. package/dist/worker.js.map +1 -0
  179. package/package.json +103 -3
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Lushly
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,36 @@
1
- # Temporary Holding Version
1
+ # @lushly-dev/violet-core
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The native token engine behind Violet Design, a hierarchical design token platform. Nodes inherit tokens from their parents and add, override, subtract, reset or copy them; this package stores them, resolves inheritance and exports the result. It has no AFD dependency: the command layer that returns `CommandResult` envelopes for the CLI, REST API and MCP server is [`@lushly-dev/violet-afd`](../../../../integrations/violet-afd/README.md).
4
+
5
+ ```bash
6
+ npm install @lushly-dev/violet-core@preview
7
+ ```
8
+
9
+ ```ts
10
+ import { createMemoryDatabase, exportTokens, resolveTokens } from '@lushly-dev/violet-core';
11
+
12
+ const db = createMemoryDatabase(); // or SQLiteDatabase / PostgresDatabase, written by your own code
13
+ const { tokens } = await resolveTokens(db, 'brand-dark', { filter: 'color.*' });
14
+ const { content } = await exportTokens(db, 'brand-dark', { format: 'css' }); // :root { --color-…: … }
15
+ ```
16
+
17
+ Exports to CSS, SCSS, TypeScript, JSON, Swift, Kotlin, Dart, Tailwind and Lua. Failures throw `TokenDomainError` with the code, message and suggestion the matching command reports.
18
+
19
+ | Entry point | Contents |
20
+ | --- | --- |
21
+ | `.` | Data contracts and `ErrorCodes`, the `Database` interface, memory/overlay/SQLite/Postgres stores, export transformers, `resolveTokens`/`exportTokens`, the hosted API OpenAPI document and the CSS validators |
22
+ | `./worker` | Worker-safe subset: `createMemoryDatabase`, `resolveTokens`/`exportTokens`, the OpenAPI document |
23
+ | `./engine` | Worker-safe building blocks: resolver, resolution cache, dependency graph, glob and constraint validators, token ids, transformers, memory and overlay stores |
24
+ | `./neon` | The Neon store; needs the optional `@neondatabase/serverless` and `ws` |
25
+ | `./css` | CSS validators only |
26
+ | `./types` | Data contracts and `ErrorCodes` |
27
+
28
+ Storage backends are optional. SQLite needs the optional `better-sqlite3` package, and Neon needs `@neondatabase/serverless` and `ws`, declared as optional peers so your project's copies are used; `npm install --omit=optional` leaves only `zod`, and in-memory storage, resolution and export still work.
29
+
30
+ `@lushly-dev/violet-core/css` holds allow-list validators for drawing token values safely: `safeCssColor`, `safeCssLength`, `safeFontFamily`, `safeShadow`, `safeDuration`, `safeEasing` and `safeCssNumber`. Each returns a rebuilt, safe value or `null` (never the input passed through), so a token holding `url(…)`, `;` or `}` can't reach a stylesheet. The subpath has no other imports, so browser code can load it alone.
31
+
32
+ The command registry, command definitions, `initializeCore`, `CommandResult` helpers and demo seed moved to `@lushly-dev/violet-afd`; see the [transition notes](../../../../docs/features/complete/platform-monorepo/violet-transition.md).
33
+
34
+ ## License
35
+
36
+ MIT
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Constraints Module
3
+ *
4
+ * Validation of design tokens against defined rules.
5
+ */
6
+ export * from './validators.js';
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/constraints/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,iBAAiB,CAAC"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Constraints Module
3
+ *
4
+ * Validation of design tokens against defined rules.
5
+ */
6
+ export * from './validators.js';
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/constraints/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,iBAAiB,CAAC"}
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Safe compilation of user supplied constraint regexes.
3
+ *
4
+ * Constraint patterns come from API/CLI users and are executed against every
5
+ * matching token value, so a catastrophic pattern such as `^(a+)+$` can pin the
6
+ * process for seconds. This module rejects such patterns up front and is also
7
+ * used by the validator for constraints stored before the check existed.
8
+ *
9
+ * The nested quantifier check is a heuristic, not a proof: it rejects groups that
10
+ * contain an unbounded quantifier (`*`, `+`, `{n,}`) and are themselves repeated by
11
+ * an unbounded quantifier (for example `(a+)+`, `(\d*)*`, `(\w+\s?)*`). That is
12
+ * the dominant source of exponential backtracking; it deliberately errs on the side
13
+ * of rejecting a few safe patterns such as `(\d+\.)*\d+`.
14
+ */
15
+ /** Longest pattern accepted for a pattern constraint */
16
+ export declare const MAX_PATTERN_LENGTH = 500;
17
+ export type PatternCheck = {
18
+ ok: true;
19
+ regex: RegExp;
20
+ } | {
21
+ ok: false;
22
+ reason: string;
23
+ };
24
+ /** True when the pattern has a repeated group that itself contains an unbounded repeat. */
25
+ export declare function hasNestedQuantifier(pattern: string): boolean;
26
+ /**
27
+ * Validate and compile a user supplied pattern.
28
+ * Never throws: failures are reported as `{ ok: false, reason }`.
29
+ */
30
+ export declare function checkPattern(pattern: string, flags?: string): PatternCheck;
31
+ //# sourceMappingURL=pattern-safety.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pattern-safety.d.ts","sourceRoot":"","sources":["../../src/constraints/pattern-safety.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,wDAAwD;AACxD,eAAO,MAAM,kBAAkB,MAAM,CAAC;AAEtC,MAAM,MAAM,YAAY,GAAG;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAcvF,2FAA2F;AAC3F,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAiE5D;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,YAAY,CA2B1E"}
@@ -0,0 +1,113 @@
1
+ /**
2
+ * Safe compilation of user supplied constraint regexes.
3
+ *
4
+ * Constraint patterns come from API/CLI users and are executed against every
5
+ * matching token value, so a catastrophic pattern such as `^(a+)+$` can pin the
6
+ * process for seconds. This module rejects such patterns up front and is also
7
+ * used by the validator for constraints stored before the check existed.
8
+ *
9
+ * The nested quantifier check is a heuristic, not a proof: it rejects groups that
10
+ * contain an unbounded quantifier (`*`, `+`, `{n,}`) and are themselves repeated by
11
+ * an unbounded quantifier (for example `(a+)+`, `(\d*)*`, `(\w+\s?)*`). That is
12
+ * the dominant source of exponential backtracking; it deliberately errs on the side
13
+ * of rejecting a few safe patterns such as `(\d+\.)*\d+`.
14
+ */
15
+ /** Longest pattern accepted for a pattern constraint */
16
+ export const MAX_PATTERN_LENGTH = 500;
17
+ /** Length of an `{n}`, `{n,}` or `{n,m}` quantifier starting at `index`, with its kind. */
18
+ function readBraceQuantifier(pattern, index) {
19
+ const match = /^\{\d+(,(\d*))?\}/.exec(pattern.slice(index));
20
+ if (!match) {
21
+ return null;
22
+ }
23
+ return { length: match[0].length, unbounded: match[1] !== undefined && match[2] === '' };
24
+ }
25
+ /** True when the pattern has a repeated group that itself contains an unbounded repeat. */
26
+ export function hasNestedQuantifier(pattern) {
27
+ // One frame per open group; `hasRepeat` = an unbounded quantifier occurs inside it
28
+ const stack = [];
29
+ const unboundedAt = (index) => {
30
+ const char = pattern[index];
31
+ if (char === '*' || char === '+') {
32
+ return true;
33
+ }
34
+ if (char === '{') {
35
+ return readBraceQuantifier(pattern, index)?.unbounded ?? false;
36
+ }
37
+ return false;
38
+ };
39
+ for (let i = 0; i < pattern.length; i++) {
40
+ const char = pattern[i];
41
+ if (char === '\\') {
42
+ i++; // escaped character, never structural
43
+ continue;
44
+ }
45
+ if (char === '[') {
46
+ // Skip a character class (quantifier characters are literal inside it)
47
+ i++;
48
+ while (i < pattern.length && pattern[i] !== ']') {
49
+ if (pattern[i] === '\\') {
50
+ i++;
51
+ }
52
+ i++;
53
+ }
54
+ continue;
55
+ }
56
+ if (char === '(') {
57
+ stack.push({ hasRepeat: false });
58
+ continue;
59
+ }
60
+ if (char === ')') {
61
+ const frame = stack.pop();
62
+ if (!frame) {
63
+ continue;
64
+ }
65
+ const repeated = unboundedAt(i + 1);
66
+ if (frame.hasRepeat && repeated) {
67
+ return true;
68
+ }
69
+ const parent = stack[stack.length - 1];
70
+ if (parent && (frame.hasRepeat || repeated)) {
71
+ parent.hasRepeat = true;
72
+ }
73
+ continue;
74
+ }
75
+ if (unboundedAt(i)) {
76
+ const frame = stack[stack.length - 1];
77
+ if (frame) {
78
+ frame.hasRepeat = true;
79
+ }
80
+ }
81
+ }
82
+ return false;
83
+ }
84
+ /**
85
+ * Validate and compile a user supplied pattern.
86
+ * Never throws: failures are reported as `{ ok: false, reason }`.
87
+ */
88
+ export function checkPattern(pattern, flags) {
89
+ if (pattern.length > MAX_PATTERN_LENGTH) {
90
+ return {
91
+ ok: false,
92
+ reason: `Pattern is longer than ${MAX_PATTERN_LENGTH} characters`,
93
+ };
94
+ }
95
+ let regex;
96
+ try {
97
+ regex = new RegExp(pattern, flags);
98
+ }
99
+ catch (error) {
100
+ return {
101
+ ok: false,
102
+ reason: `Invalid regular expression: ${error instanceof Error ? error.message : String(error)}`,
103
+ };
104
+ }
105
+ if (hasNestedQuantifier(pattern)) {
106
+ return {
107
+ ok: false,
108
+ reason: 'Pattern contains a nested quantifier (for example "(a+)+") that can cause catastrophic backtracking',
109
+ };
110
+ }
111
+ return { ok: true, regex };
112
+ }
113
+ //# sourceMappingURL=pattern-safety.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pattern-safety.js","sourceRoot":"","sources":["../../src/constraints/pattern-safety.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,wDAAwD;AACxD,MAAM,CAAC,MAAM,kBAAkB,GAAG,GAAG,CAAC;AAItC,2FAA2F;AAC3F,SAAS,mBAAmB,CAC3B,OAAe,EACf,KAAa;IAEb,MAAM,KAAK,GAAG,mBAAmB,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;IAC7D,IAAI,CAAC,KAAK,EAAE,CAAC;QACZ,OAAO,IAAI,CAAC;IACb,CAAC;IACD,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC,CAAC,KAAK,SAAS,IAAI,KAAK,CAAC,CAAC,CAAC,KAAK,EAAE,EAAE,CAA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B,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE;SAC/F,CAAC;IACH,CAAC;IAED,IAAI,mBAAmB,CAAC,OAAO,CAAC,EAAE,CAAC;QAClC,OAAO;YACN,EAAE,EAAE,KAAK;YACT,MAAM,EACL,qGAAqG;SACtG,CAAC;IACH,CAAC;IAED,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;AAC5B,CAAC"}
@@ -0,0 +1,71 @@
1
+ /**
2
+ * Constraint Validators
3
+ *
4
+ * Validate token values against constraint configurations.
5
+ */
6
+ import type { ConstraintConfig, ConstraintViolation, ContrastConfig, EnumConfig, PatternConfig, RangeConfig, ReferenceConfig, ScaleConfig } from '../types/constraint.js';
7
+ export interface ValidatorToken {
8
+ id: string;
9
+ resolvedValue: string | number;
10
+ }
11
+ export interface ValidatorContext {
12
+ /** All resolved tokens (for reference/contrast validators) */
13
+ allTokens: Map<string, ValidatorToken>;
14
+ }
15
+ export interface Validator<T extends ConstraintConfig = ConstraintConfig> {
16
+ /** Constraint type this validator handles */
17
+ type: T['type'];
18
+ /**
19
+ * Validate a token value against the constraint config
20
+ * @returns null if valid, or a violation object if invalid
21
+ */
22
+ validate(value: unknown, config: T, constraintId: string, constraintName: string, context: ValidatorContext): ConstraintViolation | null;
23
+ }
24
+ export declare const enumValidator: Validator<EnumConfig>;
25
+ export declare const rangeValidator: Validator<RangeConfig>;
26
+ export declare const patternValidator: Validator<PatternConfig>;
27
+ export declare const scaleValidator: Validator<ScaleConfig>;
28
+ export declare const contrastValidator: Validator<ContrastConfig>;
29
+ export declare const referenceValidator: Validator<ReferenceConfig>;
30
+ export declare function getValidator(type: string): Validator | undefined;
31
+ export declare function validateValue(value: unknown, config: ConstraintConfig, constraintId: string, constraintName: string, context: ValidatorContext): ConstraintViolation | null;
32
+ /**
33
+ * Extract numeric value from a string (e.g., "8px" -> 8, "1.5rem" -> 1.5)
34
+ */
35
+ export declare function parseNumericValue(value: unknown): number | null;
36
+ /**
37
+ * Parse a CSS color to RGB. Supports #RGB, #RGBA, #RRGGBB, #RRGGBBAA (alpha is
38
+ * ignored), rgb()/rgba() with 0-255 or percentage channels (clamped), and
39
+ * hsl()/hsla().
40
+ */
41
+ export declare function parseColor(value: string): {
42
+ r: number;
43
+ g: number;
44
+ b: number;
45
+ } | null;
46
+ /**
47
+ * Calculate relative luminance (WCAG 2.0)
48
+ */
49
+ export declare function calculateLuminance(color: {
50
+ r: number;
51
+ g: number;
52
+ b: number;
53
+ }): number;
54
+ /**
55
+ * Calculate contrast ratio between two colors (WCAG 2.0)
56
+ */
57
+ export declare function calculateContrastRatio(color1: {
58
+ r: number;
59
+ g: number;
60
+ b: number;
61
+ }, color2: {
62
+ r: number;
63
+ g: number;
64
+ b: number;
65
+ }): number;
66
+ /**
67
+ * Check if a token ID matches a glob pattern.
68
+ * Uses the shared glob dialect: `*` matches any characters including dots.
69
+ */
70
+ export declare function matchesPattern(tokenId: string, pattern: string): boolean;
71
+ //# sourceMappingURL=validators.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validators.d.ts","sourceRoot":"","sources":["../../src/constraints/validators.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EACX,gBAAgB,EAChB,mBAAmB,EACnB,cAAc,EACd,UAAU,EACV,aAAa,EACb,WAAW,EACX,eAAe,EACf,WAAW,EACX,MAAM,wBAAwB,CAAC;AAQhC,MAAM,WAAW,cAAc;IAC9B,EAAE,EAAE,MAAM,CAAC;IACX,aAAa,EAAE,MAAM,GAAG,MAAM,CAAC;CAC/B;AAMD,MAAM,WAAW,gBAAgB;IAChC,8DAA8D;IAC9D,SAAS,EAAE,GAAG,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;CACvC;AAED,MAAM,WAAW,SAAS,CAAC,CAAC,SAAS,gBAAgB,GAAG,gBAAgB;IACvE,6CAA6C;IA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