@damarkuncoro/meta-architecture-style-engine 0.1.0 → 0.1.1
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 +985 -14
- package/lib/cjs/cli/index.js +160 -112
- package/lib/cjs/cli/index.js.map +1 -1
- package/lib/cjs/index.d.ts +202 -111
- package/lib/cjs/index.js +720 -642
- package/lib/cjs/index.js.map +1 -1
- package/lib/esm/cli/index.js +160 -112
- package/lib/esm/cli/index.js.map +1 -1
- package/lib/esm/index.d.mts +202 -111
- package/lib/esm/index.js +716 -643
- package/lib/esm/index.js.map +1 -1
- package/package.json +6 -4
package/lib/cjs/index.js
CHANGED
|
@@ -20,6 +20,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/index.ts
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
|
+
AllowedTokenValidator: () => AllowedTokenValidator,
|
|
23
24
|
ButtonConstitution: () => ButtonConstitution,
|
|
24
25
|
CSSMaterializer: () => CSSMaterializer,
|
|
25
26
|
CanonicalStyleGraph: () => CanonicalStyleGraph,
|
|
@@ -32,11 +33,13 @@ __export(index_exports, {
|
|
|
32
33
|
ContractDSLTokenizer: () => ContractDSLTokenizer,
|
|
33
34
|
ContractDSLValidator: () => ContractDSLValidator,
|
|
34
35
|
DefaultViolationHandlers: () => DefaultViolationHandlers,
|
|
36
|
+
DomainValidator: () => DomainValidator,
|
|
35
37
|
MaseGovernanceRule: () => MaseGovernanceRule,
|
|
36
38
|
MaseGraphValidationPlugin: () => MaseGraphValidationPlugin,
|
|
37
39
|
MaseValidationError: () => MaseValidationError,
|
|
38
40
|
MaseValidationRule: () => MaseValidationRule,
|
|
39
41
|
MaterializationError: () => MaterializationError,
|
|
42
|
+
NativePlatformAdapter: () => NativePlatformAdapter,
|
|
40
43
|
PDFMaterializer: () => PDFMaterializer,
|
|
41
44
|
RNMaterializer: () => RNMaterializer,
|
|
42
45
|
StyleContract: () => StyleContract,
|
|
@@ -44,208 +47,287 @@ __export(index_exports, {
|
|
|
44
47
|
StyleResolutionEngine: () => StyleResolutionEngine,
|
|
45
48
|
TOKENS: () => TOKENS,
|
|
46
49
|
ThemeResolver: () => ThemeResolver,
|
|
50
|
+
TokenExistenceValidator: () => TokenExistenceValidator,
|
|
47
51
|
TokenRegistry: () => TokenRegistry,
|
|
48
52
|
ViolationEngine: () => ViolationEngine,
|
|
53
|
+
WebPlatformAdapter: () => WebPlatformAdapter,
|
|
49
54
|
useStyleContext: () => useStyleContext
|
|
50
55
|
});
|
|
51
56
|
module.exports = __toCommonJS(index_exports);
|
|
52
57
|
|
|
53
|
-
// src/
|
|
54
|
-
var
|
|
55
|
-
|
|
56
|
-
|
|
58
|
+
// src/data/tokens.ts
|
|
59
|
+
var TOKENS = {
|
|
60
|
+
// Colors - Intent based
|
|
61
|
+
"color.primary": { id: "color.primary", domain: "color", value: "bg-blue-600" },
|
|
62
|
+
"color.secondary": { id: "color.secondary", domain: "color", value: "bg-gray-600" },
|
|
63
|
+
"color.danger": { id: "color.danger", domain: "color", value: "bg-red-600" },
|
|
64
|
+
// Spacing - Scale based
|
|
65
|
+
"space.sm": { id: "space.sm", domain: "layout", value: "p-2" },
|
|
66
|
+
"space.md": { id: "space.md", domain: "layout", value: "p-4" },
|
|
67
|
+
"space.lg": { id: "space.lg", domain: "layout", value: "p-6" },
|
|
68
|
+
// Forbidden/Raw tokens (for demo)
|
|
69
|
+
"raw.hex": { id: "raw.hex", domain: "color", value: "bg-[#123456]" },
|
|
70
|
+
// Illegal
|
|
71
|
+
// Surface (Theme Aware!)
|
|
72
|
+
"surface.card": {
|
|
73
|
+
id: "surface.card",
|
|
74
|
+
domain: "color",
|
|
75
|
+
value: {
|
|
76
|
+
light: "bg-white",
|
|
77
|
+
dark: "bg-slate-800"
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
"surface.ground": {
|
|
81
|
+
id: "surface.ground",
|
|
82
|
+
domain: "color",
|
|
83
|
+
value: {
|
|
84
|
+
light: "bg-gray-50",
|
|
85
|
+
dark: "bg-slate-900"
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
"surface.paper": {
|
|
89
|
+
id: "surface.paper",
|
|
90
|
+
domain: "color",
|
|
91
|
+
value: {
|
|
92
|
+
light: "bg-white",
|
|
93
|
+
dark: "bg-slate-700"
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
// Text (Theme Aware!)
|
|
97
|
+
"text.light": {
|
|
98
|
+
id: "text.light",
|
|
99
|
+
domain: "color",
|
|
100
|
+
value: {
|
|
101
|
+
light: "text-white",
|
|
102
|
+
dark: "text-gray-100"
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
"text.dark": {
|
|
106
|
+
id: "text.dark",
|
|
107
|
+
domain: "color",
|
|
108
|
+
value: {
|
|
109
|
+
light: "text-gray-900",
|
|
110
|
+
dark: "text-white"
|
|
111
|
+
}
|
|
112
|
+
},
|
|
113
|
+
"text.primary": {
|
|
114
|
+
id: "text.primary",
|
|
115
|
+
domain: "color",
|
|
116
|
+
value: {
|
|
117
|
+
light: "text-gray-900",
|
|
118
|
+
dark: "text-gray-50"
|
|
119
|
+
}
|
|
120
|
+
},
|
|
121
|
+
"text.secondary": {
|
|
122
|
+
id: "text.secondary",
|
|
123
|
+
domain: "color",
|
|
124
|
+
value: {
|
|
125
|
+
light: "text-gray-500",
|
|
126
|
+
dark: "text-gray-400"
|
|
127
|
+
}
|
|
128
|
+
},
|
|
129
|
+
"shadow.sm": { id: "shadow.sm", domain: "effect", value: "shadow-sm" },
|
|
130
|
+
"shadow.md": { id: "shadow.md", domain: "effect", value: "shadow-md" },
|
|
131
|
+
"shadow.lg": { id: "shadow.lg", domain: "effect", value: "shadow-lg" },
|
|
132
|
+
// Radius
|
|
133
|
+
"radius.md": { id: "radius.md", domain: "layout", value: "rounded-md" },
|
|
134
|
+
"radius.lg": { id: "radius.lg", domain: "layout", value: "rounded-lg" }
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
// src/domain/registry/TokenRegistry.ts
|
|
138
|
+
var TokenRegistry = class {
|
|
139
|
+
constructor(tokens = TOKENS) {
|
|
140
|
+
this.tokens = Object.freeze({ ...tokens });
|
|
57
141
|
}
|
|
58
142
|
/**
|
|
59
|
-
*
|
|
143
|
+
* Get token by ID
|
|
144
|
+
* @throws Error if token not found
|
|
60
145
|
*/
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
message: `Token '${tokenId}' does not exist in Registry.`,
|
|
66
|
-
severity: "error",
|
|
67
|
-
semantic: `${property}.${tokenId}`,
|
|
68
|
-
context: context ? { ...context } : void 0
|
|
69
|
-
};
|
|
146
|
+
getToken(id) {
|
|
147
|
+
const token = this.tokens[id];
|
|
148
|
+
if (!token) {
|
|
149
|
+
throw new Error(`Token '${id}' not found in registry`);
|
|
70
150
|
}
|
|
71
|
-
return
|
|
151
|
+
return token;
|
|
72
152
|
}
|
|
73
153
|
/**
|
|
74
|
-
*
|
|
154
|
+
* Check if token exists
|
|
75
155
|
*/
|
|
76
|
-
|
|
77
|
-
return
|
|
156
|
+
hasToken(id) {
|
|
157
|
+
return id in this.tokens;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Get all tokens (immutable)
|
|
161
|
+
*/
|
|
162
|
+
getAllTokens() {
|
|
163
|
+
return this.tokens;
|
|
78
164
|
}
|
|
79
165
|
};
|
|
80
166
|
|
|
81
|
-
// src/domain/
|
|
82
|
-
var
|
|
83
|
-
constructor(tokenRegistry) {
|
|
84
|
-
this.tokenRegistry = tokenRegistry;
|
|
85
|
-
}
|
|
167
|
+
// src/domain/resolution/ThemeResolver.ts
|
|
168
|
+
var ThemeResolver = class {
|
|
86
169
|
/**
|
|
87
|
-
*
|
|
170
|
+
* Resolve theme value based on current theme
|
|
88
171
|
*/
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
return {
|
|
93
|
-
rule: "domain-violation",
|
|
94
|
-
message: `Property '${property}' expects domain '${rule.domain}', but got token from '${token.domain}'.`,
|
|
95
|
-
severity: "error",
|
|
96
|
-
semantic: `${property}.${tokenId}`,
|
|
97
|
-
context: context ? { ...context } : void 0
|
|
98
|
-
};
|
|
172
|
+
resolve(value, theme) {
|
|
173
|
+
if (typeof value === "string") {
|
|
174
|
+
return value;
|
|
99
175
|
}
|
|
100
|
-
|
|
176
|
+
if (theme in value) {
|
|
177
|
+
return value[theme];
|
|
178
|
+
}
|
|
179
|
+
throw new Error(`Theme '${theme}' not found in value. Available themes: ${Object.keys(value).join(", ")}`);
|
|
101
180
|
}
|
|
102
181
|
/**
|
|
103
|
-
* Get
|
|
182
|
+
* Get current theme from context
|
|
183
|
+
* Defaults to 'light' if not specified
|
|
104
184
|
*/
|
|
105
|
-
|
|
106
|
-
return "
|
|
185
|
+
getCurrentTheme(context) {
|
|
186
|
+
return context?.theme || "light";
|
|
107
187
|
}
|
|
108
188
|
};
|
|
109
189
|
|
|
110
|
-
// src/domain/
|
|
111
|
-
var
|
|
190
|
+
// src/domain/resolution/ContextBinder.ts
|
|
191
|
+
var ContextBinder = class {
|
|
192
|
+
constructor(graph, bindingRules = []) {
|
|
193
|
+
this.graph = graph;
|
|
194
|
+
this.bindingRules = bindingRules;
|
|
195
|
+
}
|
|
112
196
|
/**
|
|
113
|
-
*
|
|
197
|
+
* Bind graph to a specific context
|
|
198
|
+
* @param context - Style context to bind to
|
|
199
|
+
* @returns Bound context with active contracts and disabled variants
|
|
114
200
|
*/
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
201
|
+
bind(context) {
|
|
202
|
+
const activeContracts = /* @__PURE__ */ new Set();
|
|
203
|
+
const disabledVariants = /* @__PURE__ */ new Map();
|
|
204
|
+
for (const rule of this.bindingRules) {
|
|
205
|
+
const isActive = rule.condition(context);
|
|
206
|
+
if (isActive) {
|
|
207
|
+
activeContracts.add(rule.contract);
|
|
208
|
+
if (rule.disabledVariants && rule.disabledVariants.length > 0) {
|
|
209
|
+
disabledVariants.set(rule.contract, rule.disabledVariants);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
124
212
|
}
|
|
125
|
-
|
|
213
|
+
const graphView = this.createGraphView(activeContracts, disabledVariants);
|
|
214
|
+
return {
|
|
215
|
+
context,
|
|
216
|
+
activeContracts,
|
|
217
|
+
disabledVariants,
|
|
218
|
+
graphView
|
|
219
|
+
};
|
|
126
220
|
}
|
|
127
221
|
/**
|
|
128
|
-
*
|
|
222
|
+
* Bind graph to multiple contexts
|
|
223
|
+
* @param contexts - Array of style contexts
|
|
224
|
+
* @returns Array of bound contexts
|
|
129
225
|
*/
|
|
130
|
-
|
|
131
|
-
return
|
|
132
|
-
}
|
|
133
|
-
};
|
|
134
|
-
|
|
135
|
-
// src/domain/StyleResolutionEngine.ts
|
|
136
|
-
var StyleResolutionEngine = class {
|
|
137
|
-
constructor(tokenRegistry, themeResolver, validators) {
|
|
138
|
-
this.tokenRegistry = tokenRegistry;
|
|
139
|
-
this.themeResolver = themeResolver;
|
|
140
|
-
this.validators = validators || [
|
|
141
|
-
new TokenExistenceValidator(tokenRegistry),
|
|
142
|
-
new DomainValidator(tokenRegistry),
|
|
143
|
-
new AllowedTokenValidator()
|
|
144
|
-
];
|
|
226
|
+
bindMultiple(contexts) {
|
|
227
|
+
return contexts.map((ctx) => this.bind(ctx));
|
|
145
228
|
}
|
|
146
229
|
/**
|
|
147
|
-
*
|
|
148
|
-
*
|
|
149
|
-
*
|
|
150
|
-
* @
|
|
151
|
-
* @param constitution - Component constitution
|
|
152
|
-
* @param context - Optional style context
|
|
153
|
-
* @returns Resolution result with nodes, violations, and className
|
|
230
|
+
* Create immutable view of the graph
|
|
231
|
+
* @param activeContracts - Set of active contract names
|
|
232
|
+
* @param disabledVariants - Map of disabled variants per contract
|
|
233
|
+
* @returns Immutable array of nodes
|
|
154
234
|
*/
|
|
155
|
-
|
|
156
|
-
const
|
|
157
|
-
const
|
|
158
|
-
const
|
|
159
|
-
|
|
160
|
-
const rule = constitution.rules.find((r) => r.property === property);
|
|
161
|
-
if (!rule) {
|
|
162
|
-
violations.push({
|
|
163
|
-
rule: "unknown-property",
|
|
164
|
-
message: `Property '${property}' is not defined in ${constitution.componentName} constitution.`,
|
|
165
|
-
severity: "warning",
|
|
166
|
-
semantic: `${property}`
|
|
167
|
-
});
|
|
235
|
+
createGraphView(activeContracts, disabledVariants) {
|
|
236
|
+
const allNodes = this.graph.getAllNodes();
|
|
237
|
+
const view = [];
|
|
238
|
+
for (const node of allNodes) {
|
|
239
|
+
if (!activeContracts.has(node.contractRef)) {
|
|
168
240
|
continue;
|
|
169
241
|
}
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
constitution,
|
|
176
|
-
violations,
|
|
177
|
-
nodes,
|
|
178
|
-
validClassNames,
|
|
179
|
-
void 0,
|
|
180
|
-
context
|
|
181
|
-
);
|
|
182
|
-
} else if (typeof rawValue === "object" && rawValue !== null) {
|
|
183
|
-
for (const [bp, tokenId] of Object.entries(rawValue)) {
|
|
184
|
-
this.validateAndResolve(
|
|
185
|
-
property,
|
|
186
|
-
tokenId,
|
|
187
|
-
rule,
|
|
188
|
-
constitution,
|
|
189
|
-
violations,
|
|
190
|
-
nodes,
|
|
191
|
-
validClassNames,
|
|
192
|
-
bp,
|
|
193
|
-
context
|
|
194
|
-
);
|
|
242
|
+
const disabledForContract = disabledVariants.get(node.contractRef);
|
|
243
|
+
if (disabledForContract && disabledForContract.length > 0) {
|
|
244
|
+
const variant = this.extractVariant(node.id);
|
|
245
|
+
if (variant && disabledForContract.includes(variant)) {
|
|
246
|
+
continue;
|
|
195
247
|
}
|
|
196
248
|
}
|
|
249
|
+
view.push(node);
|
|
197
250
|
}
|
|
198
|
-
return
|
|
199
|
-
valid: violations.length === 0,
|
|
200
|
-
nodes: Object.freeze(nodes),
|
|
201
|
-
violations: Object.freeze(violations),
|
|
202
|
-
className: validClassNames.join(" ")
|
|
203
|
-
};
|
|
251
|
+
return Object.freeze(view);
|
|
204
252
|
}
|
|
205
253
|
/**
|
|
206
|
-
*
|
|
207
|
-
*
|
|
254
|
+
* Extract variant from node ID
|
|
255
|
+
* @param nodeId - Node ID (e.g., "Button.padding.md")
|
|
256
|
+
* @returns Variant (e.g., "md") or null
|
|
208
257
|
*/
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
violations.push({
|
|
214
|
-
...violation,
|
|
215
|
-
context: breakpoint ? { breakpoint } : void 0
|
|
216
|
-
});
|
|
217
|
-
return;
|
|
218
|
-
}
|
|
258
|
+
extractVariant(nodeId) {
|
|
259
|
+
const parts = nodeId.split(".");
|
|
260
|
+
if (parts.length >= 3) {
|
|
261
|
+
return parts[2];
|
|
219
262
|
}
|
|
220
|
-
|
|
221
|
-
nodes.push({
|
|
222
|
-
domain: token.domain,
|
|
223
|
-
semantic: `${constitution.componentName}.${property}`,
|
|
224
|
-
tokenRef: token.id,
|
|
225
|
-
source: "SRE.v2",
|
|
226
|
-
breakpoint
|
|
227
|
-
});
|
|
228
|
-
const materializedValue = this.materializeToken(token, breakpoint, context);
|
|
229
|
-
validClassNames.push(materializedValue);
|
|
263
|
+
return null;
|
|
230
264
|
}
|
|
231
265
|
/**
|
|
232
|
-
*
|
|
233
|
-
*
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
266
|
+
* Add a binding rule
|
|
267
|
+
* @param rule - Context binding rule
|
|
268
|
+
*/
|
|
269
|
+
addBindingRule(rule) {
|
|
270
|
+
this.bindingRules.push(rule);
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* Remove a binding rule
|
|
274
|
+
* @param contract - Contract name
|
|
275
|
+
* @param property - Property name
|
|
237
276
|
*/
|
|
238
|
-
|
|
239
|
-
const
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
277
|
+
removeBindingRule(contract, property) {
|
|
278
|
+
const index = this.bindingRules.findIndex(
|
|
279
|
+
(r) => r.contract === contract && r.property === property
|
|
280
|
+
);
|
|
281
|
+
if (index !== -1) {
|
|
282
|
+
this.bindingRules.splice(index, 1);
|
|
243
283
|
}
|
|
244
|
-
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* Get all binding rules
|
|
287
|
+
* @returns Immutable array of binding rules
|
|
288
|
+
*/
|
|
289
|
+
getBindingRules() {
|
|
290
|
+
return Object.freeze([...this.bindingRules]);
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* Create default binding rules for common scenarios
|
|
294
|
+
* @returns Array of default binding rules
|
|
295
|
+
*/
|
|
296
|
+
static createDefaultRules() {
|
|
297
|
+
return [
|
|
298
|
+
// Mobile: Disable large spacing
|
|
299
|
+
{
|
|
300
|
+
contract: "Card",
|
|
301
|
+
property: "padding",
|
|
302
|
+
condition: (ctx) => ctx.device === "mobile",
|
|
303
|
+
disabledVariants: ["lg", "xl", "2xl"]
|
|
304
|
+
},
|
|
305
|
+
// Mobile: Disable large shadows
|
|
306
|
+
{
|
|
307
|
+
contract: "Card",
|
|
308
|
+
property: "shadow",
|
|
309
|
+
condition: (ctx) => ctx.device === "mobile",
|
|
310
|
+
disabledVariants: ["lg", "xl"]
|
|
311
|
+
},
|
|
312
|
+
// Dark mode: Disable light surfaces
|
|
313
|
+
{
|
|
314
|
+
contract: "Card",
|
|
315
|
+
property: "background",
|
|
316
|
+
condition: (ctx) => ctx.theme === "dark",
|
|
317
|
+
disabledVariants: ["surface.white", "surface.gray"]
|
|
318
|
+
},
|
|
319
|
+
// Reduced motion: Disable animations
|
|
320
|
+
{
|
|
321
|
+
contract: "Button",
|
|
322
|
+
property: "effect",
|
|
323
|
+
condition: (ctx) => ctx.state === "disabled",
|
|
324
|
+
disabledVariants: ["animate", "transition"]
|
|
325
|
+
}
|
|
326
|
+
];
|
|
245
327
|
}
|
|
246
328
|
};
|
|
247
329
|
|
|
248
|
-
// src/domain/CanonicalStyleGraph.ts
|
|
330
|
+
// src/domain/resolution/CanonicalStyleGraph.ts
|
|
249
331
|
var CanonicalStyleGraph = class {
|
|
250
332
|
constructor(contracts, tokenRegistry) {
|
|
251
333
|
this.nodes = /* @__PURE__ */ new Map();
|
|
@@ -418,357 +500,242 @@ var CanonicalStyleGraph = class {
|
|
|
418
500
|
const nodeId = queue.shift();
|
|
419
501
|
result.push(nodeId);
|
|
420
502
|
visited.add(nodeId);
|
|
421
|
-
const node = this.nodes.get(nodeId);
|
|
422
|
-
if (node) {
|
|
423
|
-
for (const edge of node.dependencies) {
|
|
424
|
-
const neighborId = edge.to;
|
|
425
|
-
const current = inDegree.get(neighborId) || 0;
|
|
426
|
-
inDegree.set(neighborId, current - 1);
|
|
427
|
-
if (current - 1 === 0) {
|
|
428
|
-
queue.push(neighborId);
|
|
429
|
-
}
|
|
430
|
-
}
|
|
431
|
-
}
|
|
432
|
-
}
|
|
433
|
-
if (visited.size !== this.nodes.size) {
|
|
434
|
-
throw new Error("Cannot resolve order: graph contains cycles");
|
|
435
|
-
}
|
|
436
|
-
return result;
|
|
437
|
-
}
|
|
438
|
-
/**
|
|
439
|
-
* Get node by ID
|
|
440
|
-
*/
|
|
441
|
-
getNode(id) {
|
|
442
|
-
return this.nodes.get(id);
|
|
443
|
-
}
|
|
444
|
-
/**
|
|
445
|
-
* Get all nodes
|
|
446
|
-
*/
|
|
447
|
-
getAllNodes() {
|
|
448
|
-
return Array.from(this.nodes.values());
|
|
449
|
-
}
|
|
450
|
-
/**
|
|
451
|
-
* Get all edges
|
|
452
|
-
*/
|
|
453
|
-
getAllEdges() {
|
|
454
|
-
return this.edges;
|
|
455
|
-
}
|
|
456
|
-
/**
|
|
457
|
-
* Get constitution by component name
|
|
458
|
-
*/
|
|
459
|
-
getConstitution(componentName) {
|
|
460
|
-
return this.constitutionsMap.get(componentName);
|
|
461
|
-
}
|
|
462
|
-
/**
|
|
463
|
-
* Get all constitutions
|
|
464
|
-
*/
|
|
465
|
-
getAllConstitutions() {
|
|
466
|
-
return Array.from(this.constitutionsMap.values());
|
|
467
|
-
}
|
|
468
|
-
/**
|
|
469
|
-
* Check if graph is empty
|
|
470
|
-
*/
|
|
471
|
-
isEmpty() {
|
|
472
|
-
return this.nodes.size === 0;
|
|
473
|
-
}
|
|
474
|
-
/**
|
|
475
|
-
* Get graph size
|
|
476
|
-
*/
|
|
477
|
-
size() {
|
|
478
|
-
return this.nodes.size;
|
|
479
|
-
}
|
|
480
|
-
};
|
|
481
|
-
|
|
482
|
-
// src/domain/ContextBinder.ts
|
|
483
|
-
var ContextBinder = class {
|
|
484
|
-
constructor(graph, bindingRules = []) {
|
|
485
|
-
this.graph = graph;
|
|
486
|
-
this.bindingRules = bindingRules;
|
|
487
|
-
}
|
|
488
|
-
/**
|
|
489
|
-
* Bind graph to a specific context
|
|
490
|
-
* @param context - Style context to bind to
|
|
491
|
-
* @returns Bound context with active contracts and disabled variants
|
|
492
|
-
*/
|
|
493
|
-
bind(context) {
|
|
494
|
-
const activeContracts = /* @__PURE__ */ new Set();
|
|
495
|
-
const disabledVariants = /* @__PURE__ */ new Map();
|
|
496
|
-
for (const rule of this.bindingRules) {
|
|
497
|
-
const isActive = rule.condition(context);
|
|
498
|
-
if (isActive) {
|
|
499
|
-
activeContracts.add(rule.contract);
|
|
500
|
-
if (rule.disabledVariants && rule.disabledVariants.length > 0) {
|
|
501
|
-
disabledVariants.set(rule.contract, rule.disabledVariants);
|
|
503
|
+
const node = this.nodes.get(nodeId);
|
|
504
|
+
if (node) {
|
|
505
|
+
for (const edge of node.dependencies) {
|
|
506
|
+
const neighborId = edge.to;
|
|
507
|
+
const current = inDegree.get(neighborId) || 0;
|
|
508
|
+
inDegree.set(neighborId, current - 1);
|
|
509
|
+
if (current - 1 === 0) {
|
|
510
|
+
queue.push(neighborId);
|
|
511
|
+
}
|
|
502
512
|
}
|
|
503
513
|
}
|
|
504
514
|
}
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
disabledVariants,
|
|
510
|
-
graphView
|
|
511
|
-
};
|
|
515
|
+
if (visited.size !== this.nodes.size) {
|
|
516
|
+
throw new Error("Cannot resolve order: graph contains cycles");
|
|
517
|
+
}
|
|
518
|
+
return result;
|
|
512
519
|
}
|
|
513
520
|
/**
|
|
514
|
-
*
|
|
515
|
-
* @param contexts - Array of style contexts
|
|
516
|
-
* @returns Array of bound contexts
|
|
521
|
+
* Get node by ID
|
|
517
522
|
*/
|
|
518
|
-
|
|
519
|
-
return
|
|
523
|
+
getNode(id) {
|
|
524
|
+
return this.nodes.get(id);
|
|
520
525
|
}
|
|
521
526
|
/**
|
|
522
|
-
*
|
|
523
|
-
* @param activeContracts - Set of active contract names
|
|
524
|
-
* @param disabledVariants - Map of disabled variants per contract
|
|
525
|
-
* @returns Immutable array of nodes
|
|
527
|
+
* Get all nodes
|
|
526
528
|
*/
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
const view = [];
|
|
530
|
-
for (const node of allNodes) {
|
|
531
|
-
if (!activeContracts.has(node.contractRef)) {
|
|
532
|
-
continue;
|
|
533
|
-
}
|
|
534
|
-
const disabledForContract = disabledVariants.get(node.contractRef);
|
|
535
|
-
if (disabledForContract && disabledForContract.length > 0) {
|
|
536
|
-
const variant = this.extractVariant(node.id);
|
|
537
|
-
if (variant && disabledForContract.includes(variant)) {
|
|
538
|
-
continue;
|
|
539
|
-
}
|
|
540
|
-
}
|
|
541
|
-
view.push(node);
|
|
542
|
-
}
|
|
543
|
-
return Object.freeze(view);
|
|
529
|
+
getAllNodes() {
|
|
530
|
+
return Array.from(this.nodes.values());
|
|
544
531
|
}
|
|
545
532
|
/**
|
|
546
|
-
*
|
|
547
|
-
* @param nodeId - Node ID (e.g., "Button.padding.md")
|
|
548
|
-
* @returns Variant (e.g., "md") or null
|
|
533
|
+
* Get all edges
|
|
549
534
|
*/
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
if (parts.length >= 3) {
|
|
553
|
-
return parts[2];
|
|
554
|
-
}
|
|
555
|
-
return null;
|
|
535
|
+
getAllEdges() {
|
|
536
|
+
return this.edges;
|
|
556
537
|
}
|
|
557
538
|
/**
|
|
558
|
-
*
|
|
559
|
-
* @param rule - Context binding rule
|
|
539
|
+
* Get constitution by component name
|
|
560
540
|
*/
|
|
561
|
-
|
|
562
|
-
this.
|
|
541
|
+
getConstitution(componentName) {
|
|
542
|
+
return this.constitutionsMap.get(componentName);
|
|
563
543
|
}
|
|
564
544
|
/**
|
|
565
|
-
*
|
|
566
|
-
* @param contract - Contract name
|
|
567
|
-
* @param property - Property name
|
|
545
|
+
* Get all constitutions
|
|
568
546
|
*/
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
(r) => r.contract === contract && r.property === property
|
|
572
|
-
);
|
|
573
|
-
if (index !== -1) {
|
|
574
|
-
this.bindingRules.splice(index, 1);
|
|
575
|
-
}
|
|
547
|
+
getAllConstitutions() {
|
|
548
|
+
return Array.from(this.constitutionsMap.values());
|
|
576
549
|
}
|
|
577
550
|
/**
|
|
578
|
-
*
|
|
579
|
-
* @returns Immutable array of binding rules
|
|
551
|
+
* Check if graph is empty
|
|
580
552
|
*/
|
|
581
|
-
|
|
582
|
-
return
|
|
553
|
+
isEmpty() {
|
|
554
|
+
return this.nodes.size === 0;
|
|
583
555
|
}
|
|
584
556
|
/**
|
|
585
|
-
*
|
|
586
|
-
* @returns Array of default binding rules
|
|
557
|
+
* Get graph size
|
|
587
558
|
*/
|
|
588
|
-
|
|
589
|
-
return
|
|
590
|
-
// Mobile: Disable large spacing
|
|
591
|
-
{
|
|
592
|
-
contract: "Card",
|
|
593
|
-
property: "padding",
|
|
594
|
-
condition: (ctx) => ctx.device === "mobile",
|
|
595
|
-
disabledVariants: ["lg", "xl", "2xl"]
|
|
596
|
-
},
|
|
597
|
-
// Mobile: Disable large shadows
|
|
598
|
-
{
|
|
599
|
-
contract: "Card",
|
|
600
|
-
property: "shadow",
|
|
601
|
-
condition: (ctx) => ctx.device === "mobile",
|
|
602
|
-
disabledVariants: ["lg", "xl"]
|
|
603
|
-
},
|
|
604
|
-
// Dark mode: Disable light surfaces
|
|
605
|
-
{
|
|
606
|
-
contract: "Card",
|
|
607
|
-
property: "background",
|
|
608
|
-
condition: (ctx) => ctx.theme === "dark",
|
|
609
|
-
disabledVariants: ["surface.white", "surface.gray"]
|
|
610
|
-
},
|
|
611
|
-
// Reduced motion: Disable animations
|
|
612
|
-
{
|
|
613
|
-
contract: "Button",
|
|
614
|
-
property: "effect",
|
|
615
|
-
condition: (ctx) => ctx.state === "disabled",
|
|
616
|
-
disabledVariants: ["animate", "transition"]
|
|
617
|
-
}
|
|
618
|
-
];
|
|
559
|
+
size() {
|
|
560
|
+
return this.nodes.size;
|
|
619
561
|
}
|
|
620
562
|
};
|
|
621
563
|
|
|
622
|
-
// src/domain/
|
|
623
|
-
var
|
|
624
|
-
constructor(
|
|
625
|
-
this.
|
|
626
|
-
this.handlers = /* @__PURE__ */ new Map();
|
|
627
|
-
if (handlers) {
|
|
628
|
-
for (const handler of handlers) {
|
|
629
|
-
this.handlers.set(handler.constructor.name, handler);
|
|
630
|
-
}
|
|
631
|
-
}
|
|
564
|
+
// src/domain/governance/strategies/TokenExistenceValidator.ts
|
|
565
|
+
var TokenExistenceValidator = class {
|
|
566
|
+
constructor(tokenRegistry) {
|
|
567
|
+
this.tokenRegistry = tokenRegistry;
|
|
632
568
|
}
|
|
633
569
|
/**
|
|
634
|
-
*
|
|
635
|
-
* @param violation - The violation to handle
|
|
636
|
-
* @returns Outcome (decision, not execution)
|
|
570
|
+
* Validate that token exists
|
|
637
571
|
*/
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
572
|
+
validate(property, tokenId, rule, context) {
|
|
573
|
+
if (!this.tokenRegistry.hasToken(tokenId)) {
|
|
574
|
+
return {
|
|
575
|
+
rule: "invalid-token",
|
|
576
|
+
message: `Token '${tokenId}' does not exist in Registry.`,
|
|
577
|
+
severity: "error",
|
|
578
|
+
semantic: `${property}.${tokenId}`,
|
|
579
|
+
context: context ? { ...context } : void 0
|
|
580
|
+
};
|
|
642
581
|
}
|
|
643
|
-
return
|
|
644
|
-
}
|
|
645
|
-
/**
|
|
646
|
-
* Handle multiple violations
|
|
647
|
-
* @param violations - Array of violations
|
|
648
|
-
* @returns Array of outcomes
|
|
649
|
-
*/
|
|
650
|
-
handleMultiple(violations) {
|
|
651
|
-
return violations.map((v) => this.handle(v));
|
|
582
|
+
return null;
|
|
652
583
|
}
|
|
653
584
|
/**
|
|
654
|
-
* Get
|
|
655
|
-
* @returns Current default action
|
|
585
|
+
* Get strategy name
|
|
656
586
|
*/
|
|
657
|
-
|
|
658
|
-
return
|
|
587
|
+
getName() {
|
|
588
|
+
return "TokenExistenceValidator";
|
|
659
589
|
}
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
const currentAction = this.getCurrentDefaultAction();
|
|
667
|
-
switch (currentAction) {
|
|
668
|
-
case "reject":
|
|
669
|
-
return {
|
|
670
|
-
action: "reject",
|
|
671
|
-
metadata: {
|
|
672
|
-
contract: violation.semantic || "unknown",
|
|
673
|
-
reason: violation.message,
|
|
674
|
-
context: violation.context || {},
|
|
675
|
-
severity: violation.severity
|
|
676
|
-
}
|
|
677
|
-
};
|
|
678
|
-
case "fallback":
|
|
679
|
-
return {
|
|
680
|
-
action: "fallback",
|
|
681
|
-
replacement: this.determineFallbackValue(violation),
|
|
682
|
-
metadata: {
|
|
683
|
-
contract: violation.semantic || "unknown",
|
|
684
|
-
reason: violation.message,
|
|
685
|
-
context: violation.context || {},
|
|
686
|
-
severity: "warning"
|
|
687
|
-
}
|
|
688
|
-
};
|
|
689
|
-
case "override":
|
|
690
|
-
return {
|
|
691
|
-
action: "override",
|
|
692
|
-
metadata: {
|
|
693
|
-
contract: violation.semantic || "unknown",
|
|
694
|
-
reason: violation.message,
|
|
695
|
-
context: violation.context || {},
|
|
696
|
-
severity: "warning"
|
|
697
|
-
}
|
|
698
|
-
};
|
|
699
|
-
case "warn":
|
|
700
|
-
return {
|
|
701
|
-
action: "warn",
|
|
702
|
-
metadata: {
|
|
703
|
-
contract: violation.semantic || "unknown",
|
|
704
|
-
reason: violation.message,
|
|
705
|
-
context: violation.context || {},
|
|
706
|
-
severity: "warning"
|
|
707
|
-
}
|
|
708
|
-
};
|
|
709
|
-
default:
|
|
710
|
-
throw new Error(`Unknown action: ${currentAction}`);
|
|
711
|
-
}
|
|
590
|
+
};
|
|
591
|
+
|
|
592
|
+
// src/domain/governance/strategies/DomainValidator.ts
|
|
593
|
+
var DomainValidator = class {
|
|
594
|
+
constructor(tokenRegistry) {
|
|
595
|
+
this.tokenRegistry = tokenRegistry;
|
|
712
596
|
}
|
|
713
597
|
/**
|
|
714
|
-
*
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
const property = parts[parts.length - 1];
|
|
727
|
-
const fallbacks = {
|
|
728
|
-
"padding": "md",
|
|
729
|
-
"margin": "md",
|
|
730
|
-
"spacing": "md",
|
|
731
|
-
"radius": "md",
|
|
732
|
-
"shadow": "md",
|
|
733
|
-
"background": "surface.card",
|
|
734
|
-
"color": "color.primary"
|
|
735
|
-
};
|
|
736
|
-
if (property in fallbacks) {
|
|
737
|
-
return fallbacks[property];
|
|
738
|
-
}
|
|
739
|
-
}
|
|
598
|
+
* Validate that token domain matches rule domain
|
|
599
|
+
*/
|
|
600
|
+
validate(property, tokenId, rule, context) {
|
|
601
|
+
const token = this.tokenRegistry.getToken(tokenId);
|
|
602
|
+
if (token.domain !== rule.domain) {
|
|
603
|
+
return {
|
|
604
|
+
rule: "domain-violation",
|
|
605
|
+
message: `Property '${property}' expects domain '${rule.domain}', but got token from '${token.domain}'.`,
|
|
606
|
+
severity: "error",
|
|
607
|
+
semantic: `${property}.${tokenId}`,
|
|
608
|
+
context: context ? { ...context } : void 0
|
|
609
|
+
};
|
|
740
610
|
}
|
|
741
|
-
return
|
|
611
|
+
return null;
|
|
742
612
|
}
|
|
743
613
|
/**
|
|
744
|
-
*
|
|
745
|
-
* @param handler - The handler to register
|
|
614
|
+
* Get strategy name
|
|
746
615
|
*/
|
|
747
|
-
|
|
748
|
-
|
|
616
|
+
getName() {
|
|
617
|
+
return "DomainValidator";
|
|
749
618
|
}
|
|
619
|
+
};
|
|
620
|
+
|
|
621
|
+
// src/domain/governance/strategies/AllowedTokenValidator.ts
|
|
622
|
+
var AllowedTokenValidator = class {
|
|
750
623
|
/**
|
|
751
|
-
*
|
|
752
|
-
* @param handlerName - Name of handler to unregister
|
|
624
|
+
* Validate that token is allowed
|
|
753
625
|
*/
|
|
754
|
-
|
|
755
|
-
|
|
626
|
+
validate(property, tokenId, rule, context) {
|
|
627
|
+
if (!rule.allowedTokens.includes(tokenId)) {
|
|
628
|
+
return {
|
|
629
|
+
rule: "illegal-token-usage",
|
|
630
|
+
message: `Token '${tokenId}' is NOT allowed for property '${property}'. Allowed: ${rule.allowedTokens.join(", ")}`,
|
|
631
|
+
severity: "error",
|
|
632
|
+
semantic: `${property}.${tokenId}`,
|
|
633
|
+
context: context ? { ...context } : void 0
|
|
634
|
+
};
|
|
635
|
+
}
|
|
636
|
+
return null;
|
|
756
637
|
}
|
|
757
638
|
/**
|
|
758
|
-
* Get
|
|
759
|
-
* @returns Array of handler names
|
|
639
|
+
* Get strategy name
|
|
760
640
|
*/
|
|
761
|
-
|
|
762
|
-
return
|
|
641
|
+
getName() {
|
|
642
|
+
return "AllowedTokenValidator";
|
|
643
|
+
}
|
|
644
|
+
};
|
|
645
|
+
|
|
646
|
+
// src/domain/resolution/StyleResolutionEngine.ts
|
|
647
|
+
var StyleResolutionEngine = class {
|
|
648
|
+
constructor(tokenRegistry, themeResolver, validators) {
|
|
649
|
+
this.tokenRegistry = tokenRegistry;
|
|
650
|
+
this.themeResolver = themeResolver;
|
|
651
|
+
this.validators = validators || [
|
|
652
|
+
new TokenExistenceValidator(tokenRegistry),
|
|
653
|
+
new DomainValidator(tokenRegistry),
|
|
654
|
+
new AllowedTokenValidator()
|
|
655
|
+
];
|
|
763
656
|
}
|
|
764
657
|
/**
|
|
765
|
-
*
|
|
766
|
-
*
|
|
658
|
+
* resolve()
|
|
659
|
+
* Main function: Validates style contract against constitution
|
|
660
|
+
*
|
|
661
|
+
* @param contract - Style contract definition
|
|
662
|
+
* @param constitution - Component constitution
|
|
663
|
+
* @param context - Optional style context
|
|
664
|
+
* @returns Resolution result with nodes and violations
|
|
767
665
|
*/
|
|
768
|
-
|
|
769
|
-
|
|
666
|
+
resolve(contract, constitution, context) {
|
|
667
|
+
const violations = [];
|
|
668
|
+
const nodes = [];
|
|
669
|
+
for (const [property, rawValue] of Object.entries(contract)) {
|
|
670
|
+
const rule = constitution.rules.find((r) => r.property === property);
|
|
671
|
+
if (!rule) {
|
|
672
|
+
violations.push({
|
|
673
|
+
rule: "unknown-property",
|
|
674
|
+
message: `Property '${property}' is not defined in ${constitution.componentName} constitution.`,
|
|
675
|
+
severity: "warning",
|
|
676
|
+
semantic: `${property}`
|
|
677
|
+
});
|
|
678
|
+
continue;
|
|
679
|
+
}
|
|
680
|
+
if (typeof rawValue === "string") {
|
|
681
|
+
this.validateAndResolve(
|
|
682
|
+
property,
|
|
683
|
+
rawValue,
|
|
684
|
+
rule,
|
|
685
|
+
constitution,
|
|
686
|
+
violations,
|
|
687
|
+
nodes,
|
|
688
|
+
void 0,
|
|
689
|
+
context
|
|
690
|
+
);
|
|
691
|
+
} else if (typeof rawValue === "object" && rawValue !== null) {
|
|
692
|
+
for (const [bp, tokenId] of Object.entries(rawValue)) {
|
|
693
|
+
this.validateAndResolve(
|
|
694
|
+
property,
|
|
695
|
+
tokenId,
|
|
696
|
+
rule,
|
|
697
|
+
constitution,
|
|
698
|
+
violations,
|
|
699
|
+
nodes,
|
|
700
|
+
bp,
|
|
701
|
+
context
|
|
702
|
+
);
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
}
|
|
706
|
+
return {
|
|
707
|
+
valid: violations.length === 0,
|
|
708
|
+
nodes: Object.freeze(nodes),
|
|
709
|
+
violations: Object.freeze(violations)
|
|
710
|
+
};
|
|
711
|
+
}
|
|
712
|
+
/**
|
|
713
|
+
* validateAndResolve()
|
|
714
|
+
* Internal helper to validate and resolve a single token
|
|
715
|
+
*/
|
|
716
|
+
validateAndResolve(property, tokenId, rule, constitution, violations, nodes, breakpoint, context) {
|
|
717
|
+
for (const validator of this.validators) {
|
|
718
|
+
const violation = validator.validate(property, tokenId, rule, context);
|
|
719
|
+
if (violation) {
|
|
720
|
+
violations.push({
|
|
721
|
+
...violation,
|
|
722
|
+
context: breakpoint ? { breakpoint } : void 0
|
|
723
|
+
});
|
|
724
|
+
return;
|
|
725
|
+
}
|
|
726
|
+
}
|
|
727
|
+
const token = this.tokenRegistry.getToken(tokenId);
|
|
728
|
+
nodes.push({
|
|
729
|
+
domain: token.domain,
|
|
730
|
+
semantic: `${constitution.componentName}.${property}`,
|
|
731
|
+
tokenRef: token.id,
|
|
732
|
+
source: "SRE.v2",
|
|
733
|
+
breakpoint
|
|
734
|
+
});
|
|
770
735
|
}
|
|
771
736
|
};
|
|
737
|
+
|
|
738
|
+
// src/domain/governance/DefaultViolationHandlers.ts
|
|
772
739
|
var DefaultViolationHandlers = class {
|
|
773
740
|
};
|
|
774
741
|
/**
|
|
@@ -844,139 +811,158 @@ DefaultViolationHandlers.ContextViolationHandler = {
|
|
|
844
811
|
}
|
|
845
812
|
};
|
|
846
813
|
|
|
847
|
-
// src/
|
|
848
|
-
var
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
"space.lg": { id: "space.lg", domain: "layout", value: "p-6" },
|
|
857
|
-
// Forbidden/Raw tokens (for demo)
|
|
858
|
-
"raw.hex": { id: "raw.hex", domain: "color", value: "bg-[#123456]" },
|
|
859
|
-
// Illegal
|
|
860
|
-
// Surface (Theme Aware!)
|
|
861
|
-
"surface.card": {
|
|
862
|
-
id: "surface.card",
|
|
863
|
-
domain: "color",
|
|
864
|
-
value: {
|
|
865
|
-
light: "bg-white",
|
|
866
|
-
dark: "bg-slate-800"
|
|
867
|
-
}
|
|
868
|
-
},
|
|
869
|
-
"surface.ground": {
|
|
870
|
-
id: "surface.ground",
|
|
871
|
-
domain: "color",
|
|
872
|
-
value: {
|
|
873
|
-
light: "bg-gray-50",
|
|
874
|
-
dark: "bg-slate-900"
|
|
875
|
-
}
|
|
876
|
-
},
|
|
877
|
-
"surface.paper": {
|
|
878
|
-
id: "surface.paper",
|
|
879
|
-
domain: "color",
|
|
880
|
-
value: {
|
|
881
|
-
light: "bg-white",
|
|
882
|
-
dark: "bg-slate-700"
|
|
883
|
-
}
|
|
884
|
-
},
|
|
885
|
-
// Text (Theme Aware!)
|
|
886
|
-
"text.light": {
|
|
887
|
-
id: "text.light",
|
|
888
|
-
domain: "color",
|
|
889
|
-
value: {
|
|
890
|
-
light: "text-white",
|
|
891
|
-
dark: "text-gray-100"
|
|
892
|
-
}
|
|
893
|
-
},
|
|
894
|
-
"text.dark": {
|
|
895
|
-
id: "text.dark",
|
|
896
|
-
domain: "color",
|
|
897
|
-
value: {
|
|
898
|
-
light: "text-gray-900",
|
|
899
|
-
dark: "text-white"
|
|
814
|
+
// src/domain/governance/ViolationEngine.ts
|
|
815
|
+
var ViolationEngine = class {
|
|
816
|
+
constructor(defaultAction = "reject", handlers) {
|
|
817
|
+
this.defaultAction = defaultAction;
|
|
818
|
+
this.handlers = /* @__PURE__ */ new Map();
|
|
819
|
+
if (handlers) {
|
|
820
|
+
for (const handler of handlers) {
|
|
821
|
+
this.handlers.set(handler.constructor.name, handler);
|
|
822
|
+
}
|
|
900
823
|
}
|
|
901
|
-
}
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
824
|
+
}
|
|
825
|
+
/**
|
|
826
|
+
* Handle a violation
|
|
827
|
+
* @param violation - The violation to handle
|
|
828
|
+
* @returns Outcome (decision, not execution)
|
|
829
|
+
*/
|
|
830
|
+
handle(violation) {
|
|
831
|
+
const handler = this.handlers.get(violation.rule);
|
|
832
|
+
if (handler) {
|
|
833
|
+
return handler.handle(violation);
|
|
908
834
|
}
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
835
|
+
return this.createDefaultOutcome(violation);
|
|
836
|
+
}
|
|
837
|
+
/**
|
|
838
|
+
* Handle multiple violations
|
|
839
|
+
* @param violations - Array of violations
|
|
840
|
+
* @returns Array of outcomes
|
|
841
|
+
*/
|
|
842
|
+
handleMultiple(violations) {
|
|
843
|
+
return violations.map((v) => this.handle(v));
|
|
844
|
+
}
|
|
845
|
+
/**
|
|
846
|
+
* Get current default action
|
|
847
|
+
* @returns Current default action
|
|
848
|
+
*/
|
|
849
|
+
getCurrentDefaultAction() {
|
|
850
|
+
return this.defaultAction;
|
|
851
|
+
}
|
|
852
|
+
/**
|
|
853
|
+
* Create default outcome based on default action
|
|
854
|
+
* @param violation - The violation
|
|
855
|
+
* @returns Default outcome
|
|
856
|
+
*/
|
|
857
|
+
createDefaultOutcome(violation) {
|
|
858
|
+
const currentAction = this.getCurrentDefaultAction();
|
|
859
|
+
switch (currentAction) {
|
|
860
|
+
case "reject":
|
|
861
|
+
return {
|
|
862
|
+
action: "reject",
|
|
863
|
+
metadata: {
|
|
864
|
+
contract: violation.semantic || "unknown",
|
|
865
|
+
reason: violation.message,
|
|
866
|
+
context: violation.context || {},
|
|
867
|
+
severity: violation.severity
|
|
868
|
+
}
|
|
869
|
+
};
|
|
870
|
+
case "fallback":
|
|
871
|
+
return {
|
|
872
|
+
action: "fallback",
|
|
873
|
+
replacement: this.determineFallbackValue(violation),
|
|
874
|
+
metadata: {
|
|
875
|
+
contract: violation.semantic || "unknown",
|
|
876
|
+
reason: violation.message,
|
|
877
|
+
context: violation.context || {},
|
|
878
|
+
severity: "warning"
|
|
879
|
+
}
|
|
880
|
+
};
|
|
881
|
+
case "override":
|
|
882
|
+
return {
|
|
883
|
+
action: "override",
|
|
884
|
+
metadata: {
|
|
885
|
+
contract: violation.semantic || "unknown",
|
|
886
|
+
reason: violation.message,
|
|
887
|
+
context: violation.context || {},
|
|
888
|
+
severity: "warning"
|
|
889
|
+
}
|
|
890
|
+
};
|
|
891
|
+
case "warn":
|
|
892
|
+
return {
|
|
893
|
+
action: "warn",
|
|
894
|
+
metadata: {
|
|
895
|
+
contract: violation.semantic || "unknown",
|
|
896
|
+
reason: violation.message,
|
|
897
|
+
context: violation.context || {},
|
|
898
|
+
severity: "warning"
|
|
899
|
+
}
|
|
900
|
+
};
|
|
901
|
+
default:
|
|
902
|
+
throw new Error(`Unknown action: ${currentAction}`);
|
|
916
903
|
}
|
|
917
|
-
},
|
|
918
|
-
"shadow.sm": { id: "shadow.sm", domain: "effect", value: "shadow-sm" },
|
|
919
|
-
"shadow.md": { id: "shadow.md", domain: "effect", value: "shadow-md" },
|
|
920
|
-
"shadow.lg": { id: "shadow.lg", domain: "effect", value: "shadow-lg" },
|
|
921
|
-
// Radius
|
|
922
|
-
"radius.md": { id: "radius.md", domain: "layout", value: "rounded-md" },
|
|
923
|
-
"radius.lg": { id: "radius.lg", domain: "layout", value: "rounded-lg" }
|
|
924
|
-
};
|
|
925
|
-
|
|
926
|
-
// src/domain/TokenRegistry.ts
|
|
927
|
-
var TokenRegistry = class {
|
|
928
|
-
constructor(tokens = TOKENS) {
|
|
929
|
-
this.tokens = Object.freeze({ ...tokens });
|
|
930
904
|
}
|
|
931
905
|
/**
|
|
932
|
-
*
|
|
933
|
-
* @
|
|
906
|
+
* Determine fallback value for a violation
|
|
907
|
+
* @param violation - The violation
|
|
908
|
+
* @returns Fallback value or undefined
|
|
934
909
|
*/
|
|
935
|
-
|
|
936
|
-
const
|
|
937
|
-
if (
|
|
938
|
-
|
|
910
|
+
determineFallbackValue(violation) {
|
|
911
|
+
const match = violation.message.match(/fallback to \[([^\]]+)\]/i);
|
|
912
|
+
if (match && match[1]) {
|
|
913
|
+
return match[1];
|
|
939
914
|
}
|
|
940
|
-
|
|
915
|
+
if (violation.semantic) {
|
|
916
|
+
const parts = violation.semantic.split(".");
|
|
917
|
+
if (parts.length >= 2) {
|
|
918
|
+
const property = parts[parts.length - 1];
|
|
919
|
+
const fallbacks = {
|
|
920
|
+
"padding": "md",
|
|
921
|
+
"margin": "md",
|
|
922
|
+
"spacing": "md",
|
|
923
|
+
"radius": "md",
|
|
924
|
+
"shadow": "md",
|
|
925
|
+
"background": "surface.card",
|
|
926
|
+
"color": "color.primary"
|
|
927
|
+
};
|
|
928
|
+
if (property in fallbacks) {
|
|
929
|
+
return fallbacks[property];
|
|
930
|
+
}
|
|
931
|
+
}
|
|
932
|
+
}
|
|
933
|
+
return void 0;
|
|
941
934
|
}
|
|
942
935
|
/**
|
|
943
|
-
*
|
|
936
|
+
* Register a handler
|
|
937
|
+
* @param handler - The handler to register
|
|
944
938
|
*/
|
|
945
|
-
|
|
946
|
-
|
|
939
|
+
registerHandler(handler) {
|
|
940
|
+
this.handlers.set(handler.constructor.name, handler);
|
|
947
941
|
}
|
|
948
942
|
/**
|
|
949
|
-
*
|
|
943
|
+
* Unregister a handler
|
|
944
|
+
* @param handlerName - Name of handler to unregister
|
|
950
945
|
*/
|
|
951
|
-
|
|
952
|
-
|
|
946
|
+
unregisterHandler(handlerName) {
|
|
947
|
+
this.handlers.delete(handlerName);
|
|
953
948
|
}
|
|
954
|
-
};
|
|
955
|
-
|
|
956
|
-
// src/domain/ThemeResolver.ts
|
|
957
|
-
var ThemeResolver = class {
|
|
958
949
|
/**
|
|
959
|
-
*
|
|
950
|
+
* Get all registered handlers
|
|
951
|
+
* @returns Array of handler names
|
|
960
952
|
*/
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
return value;
|
|
964
|
-
}
|
|
965
|
-
if (theme in value) {
|
|
966
|
-
return value[theme];
|
|
967
|
-
}
|
|
968
|
-
throw new Error(`Theme '${theme}' not found in value. Available themes: ${Object.keys(value).join(", ")}`);
|
|
953
|
+
getHandlers() {
|
|
954
|
+
return Array.from(this.handlers.keys());
|
|
969
955
|
}
|
|
970
956
|
/**
|
|
971
|
-
*
|
|
972
|
-
*
|
|
957
|
+
* Set default action
|
|
958
|
+
* @param action - The default action
|
|
973
959
|
*/
|
|
974
|
-
|
|
975
|
-
|
|
960
|
+
setDefaultAction(action) {
|
|
961
|
+
this.defaultAction = action;
|
|
976
962
|
}
|
|
977
963
|
};
|
|
978
964
|
|
|
979
|
-
// src/domain/ContextFactory.ts
|
|
965
|
+
// src/domain/factories/ContextFactory.ts
|
|
980
966
|
var ContextFactory = class {
|
|
981
967
|
/**
|
|
982
968
|
* Create a style context with all required fields
|
|
@@ -1023,7 +1009,7 @@ var ContextFactory = class {
|
|
|
1023
1009
|
}
|
|
1024
1010
|
};
|
|
1025
1011
|
|
|
1026
|
-
// src/runtime/StyleContract.ts
|
|
1012
|
+
// src/runtime/core/StyleContract.ts
|
|
1027
1013
|
var StyleContract = class {
|
|
1028
1014
|
constructor(contract, constitution, engine) {
|
|
1029
1015
|
this.contract = contract;
|
|
@@ -1120,8 +1106,51 @@ var StyleContract = class {
|
|
|
1120
1106
|
}
|
|
1121
1107
|
};
|
|
1122
1108
|
|
|
1123
|
-
// src/runtime/StyleProvider.tsx
|
|
1109
|
+
// src/runtime/react/StyleProvider.tsx
|
|
1124
1110
|
var import_react = require("react");
|
|
1111
|
+
|
|
1112
|
+
// src/runtime/adapters/WebPlatformAdapter.ts
|
|
1113
|
+
var WebPlatformAdapter = class {
|
|
1114
|
+
constructor() {
|
|
1115
|
+
this.platform = "web";
|
|
1116
|
+
}
|
|
1117
|
+
getInitialDevice() {
|
|
1118
|
+
if (typeof window === "undefined") return "desktop";
|
|
1119
|
+
const width = window.innerWidth;
|
|
1120
|
+
if (width < 768) return "mobile";
|
|
1121
|
+
if (width < 1024) return "tablet";
|
|
1122
|
+
return "desktop";
|
|
1123
|
+
}
|
|
1124
|
+
subscribeToResize(callback) {
|
|
1125
|
+
if (typeof window === "undefined") {
|
|
1126
|
+
return () => {
|
|
1127
|
+
};
|
|
1128
|
+
}
|
|
1129
|
+
const handleResize = () => {
|
|
1130
|
+
const width = window.innerWidth;
|
|
1131
|
+
let device = "desktop";
|
|
1132
|
+
if (width < 768) device = "mobile";
|
|
1133
|
+
else if (width < 1024) device = "tablet";
|
|
1134
|
+
callback(device);
|
|
1135
|
+
};
|
|
1136
|
+
window.addEventListener("resize", handleResize);
|
|
1137
|
+
handleResize();
|
|
1138
|
+
return () => {
|
|
1139
|
+
window.removeEventListener("resize", handleResize);
|
|
1140
|
+
};
|
|
1141
|
+
}
|
|
1142
|
+
applyTheme(theme) {
|
|
1143
|
+
if (typeof document === "undefined") return;
|
|
1144
|
+
const root = document.documentElement;
|
|
1145
|
+
if (theme === "dark") {
|
|
1146
|
+
root.classList.add("dark");
|
|
1147
|
+
} else {
|
|
1148
|
+
root.classList.remove("dark");
|
|
1149
|
+
}
|
|
1150
|
+
}
|
|
1151
|
+
};
|
|
1152
|
+
|
|
1153
|
+
// src/runtime/react/StyleProvider.tsx
|
|
1125
1154
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
1126
1155
|
var defaultContext = {
|
|
1127
1156
|
platform: "web",
|
|
@@ -1133,27 +1162,29 @@ var defaultContext = {
|
|
|
1133
1162
|
}
|
|
1134
1163
|
};
|
|
1135
1164
|
var StyleEngineContext = (0, import_react.createContext)(defaultContext);
|
|
1136
|
-
var StyleProvider = ({
|
|
1165
|
+
var StyleProvider = ({
|
|
1166
|
+
children,
|
|
1167
|
+
initialTheme = "light",
|
|
1168
|
+
adapter
|
|
1169
|
+
}) => {
|
|
1170
|
+
const platformAdapter = (0, import_react.useMemo)(() => adapter || new WebPlatformAdapter(), [adapter]);
|
|
1137
1171
|
const [theme, setThemeState] = (0, import_react.useState)(initialTheme);
|
|
1138
|
-
const [device, setDevice] = (0, import_react.useState)(
|
|
1172
|
+
const [device, setDevice] = (0, import_react.useState)(() => {
|
|
1173
|
+
try {
|
|
1174
|
+
return platformAdapter.getInitialDevice();
|
|
1175
|
+
} catch {
|
|
1176
|
+
return "desktop";
|
|
1177
|
+
}
|
|
1178
|
+
});
|
|
1139
1179
|
(0, import_react.useEffect)(() => {
|
|
1140
|
-
const
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
};
|
|
1146
|
-
handleResize();
|
|
1147
|
-
window.addEventListener("resize", handleResize);
|
|
1148
|
-
return () => window.removeEventListener("resize", handleResize);
|
|
1149
|
-
}, []);
|
|
1180
|
+
const unsubscribe = platformAdapter.subscribeToResize((newDevice) => {
|
|
1181
|
+
setDevice(newDevice);
|
|
1182
|
+
});
|
|
1183
|
+
return unsubscribe;
|
|
1184
|
+
}, [platformAdapter]);
|
|
1150
1185
|
(0, import_react.useEffect)(() => {
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
} else {
|
|
1154
|
-
document.documentElement.classList.remove("dark");
|
|
1155
|
-
}
|
|
1156
|
-
}, [theme]);
|
|
1186
|
+
platformAdapter.applyTheme(theme);
|
|
1187
|
+
}, [theme, platformAdapter]);
|
|
1157
1188
|
const toggleTheme = () => {
|
|
1158
1189
|
setThemeState((prev) => prev === "light" ? "dark" : "light");
|
|
1159
1190
|
};
|
|
@@ -1161,7 +1192,7 @@ var StyleProvider = ({ children, initialTheme = "light" }) => {
|
|
|
1161
1192
|
setThemeState(newTheme);
|
|
1162
1193
|
};
|
|
1163
1194
|
const value = {
|
|
1164
|
-
platform:
|
|
1195
|
+
platform: platformAdapter.platform,
|
|
1165
1196
|
theme,
|
|
1166
1197
|
device,
|
|
1167
1198
|
toggleTheme,
|
|
@@ -1171,7 +1202,23 @@ var StyleProvider = ({ children, initialTheme = "light" }) => {
|
|
|
1171
1202
|
};
|
|
1172
1203
|
var useStyleContext = () => (0, import_react.useContext)(StyleEngineContext);
|
|
1173
1204
|
|
|
1174
|
-
// src/
|
|
1205
|
+
// src/runtime/adapters/NativePlatformAdapter.ts
|
|
1206
|
+
var NativePlatformAdapter = class {
|
|
1207
|
+
constructor() {
|
|
1208
|
+
this.platform = "native";
|
|
1209
|
+
}
|
|
1210
|
+
getInitialDevice() {
|
|
1211
|
+
return "mobile";
|
|
1212
|
+
}
|
|
1213
|
+
subscribeToResize(callback) {
|
|
1214
|
+
return () => {
|
|
1215
|
+
};
|
|
1216
|
+
}
|
|
1217
|
+
applyTheme(theme) {
|
|
1218
|
+
}
|
|
1219
|
+
};
|
|
1220
|
+
|
|
1221
|
+
// src/adapter/meta-architecture/rules/MaseValidationRule.ts
|
|
1175
1222
|
var import_meta_architecture = require("@damarkuncoro/meta-architecture");
|
|
1176
1223
|
var MaseValidationRule = class {
|
|
1177
1224
|
constructor() {
|
|
@@ -1217,6 +1264,8 @@ var MaseValidationRule = class {
|
|
|
1217
1264
|
);
|
|
1218
1265
|
}
|
|
1219
1266
|
};
|
|
1267
|
+
|
|
1268
|
+
// src/adapter/meta-architecture/MasePlugin.ts
|
|
1220
1269
|
var MaseGraphValidationPlugin = class {
|
|
1221
1270
|
constructor() {
|
|
1222
1271
|
this.metadata = {
|
|
@@ -1238,7 +1287,46 @@ var MaseGraphValidationPlugin = class {
|
|
|
1238
1287
|
}
|
|
1239
1288
|
};
|
|
1240
1289
|
|
|
1241
|
-
// src/adapter/
|
|
1290
|
+
// src/adapter/meta-architecture/errors/MaseValidationError.ts
|
|
1291
|
+
var MaseValidationError = class extends Error {
|
|
1292
|
+
constructor(message, code, field) {
|
|
1293
|
+
super(message);
|
|
1294
|
+
this.name = "ValidationError";
|
|
1295
|
+
this.code = code;
|
|
1296
|
+
this.field = field;
|
|
1297
|
+
}
|
|
1298
|
+
};
|
|
1299
|
+
|
|
1300
|
+
// src/adapter/meta-architecture/rules/MaseGovernanceRule.ts
|
|
1301
|
+
var MaseGovernanceRule = class {
|
|
1302
|
+
constructor() {
|
|
1303
|
+
this.name = "MASE-Constitutional-Compliance";
|
|
1304
|
+
this.description = "Enforces strict adherence to Component Constitution using MASE SRE.";
|
|
1305
|
+
this.category = "business";
|
|
1306
|
+
// It's a business rule (Design System Law)
|
|
1307
|
+
this.severity = "error";
|
|
1308
|
+
const tokenRegistry = new TokenRegistry();
|
|
1309
|
+
const themeResolver = new ThemeResolver();
|
|
1310
|
+
this.engine = new StyleResolutionEngine(tokenRegistry, themeResolver);
|
|
1311
|
+
}
|
|
1312
|
+
async validate(target, _context) {
|
|
1313
|
+
const result = this.engine.resolve(target.contract, target.constitution);
|
|
1314
|
+
if (result.valid) {
|
|
1315
|
+
return null;
|
|
1316
|
+
}
|
|
1317
|
+
const primaryViolation = result.violations[0];
|
|
1318
|
+
const messages = result.violations.map((v) => `[${v.rule}] ${v.message} (${v.semantic})`).join("; ");
|
|
1319
|
+
return new MaseValidationError(
|
|
1320
|
+
messages,
|
|
1321
|
+
primaryViolation.rule,
|
|
1322
|
+
// code
|
|
1323
|
+
target.constitution.componentName
|
|
1324
|
+
// field/target
|
|
1325
|
+
);
|
|
1326
|
+
}
|
|
1327
|
+
};
|
|
1328
|
+
|
|
1329
|
+
// src/adapter/meta-architecture/factories/CompliancePipelineFactory.ts
|
|
1242
1330
|
var import_meta_architecture2 = require("@damarkuncoro/meta-architecture");
|
|
1243
1331
|
|
|
1244
1332
|
// src/data/constitutions/CardConstitution.ts
|
|
@@ -1269,7 +1357,7 @@ var CardConstitution = {
|
|
|
1269
1357
|
]
|
|
1270
1358
|
};
|
|
1271
1359
|
|
|
1272
|
-
// src/adapter/
|
|
1360
|
+
// src/adapter/meta-architecture/factories/CompliancePipelineFactory.ts
|
|
1273
1361
|
var CompliancePipelineFactory = class {
|
|
1274
1362
|
static async createPipeline() {
|
|
1275
1363
|
const pipeline = new import_meta_architecture2.ValidationPipeline();
|
|
@@ -1328,43 +1416,6 @@ var CompliancePipelineFactory = class {
|
|
|
1328
1416
|
}
|
|
1329
1417
|
};
|
|
1330
1418
|
|
|
1331
|
-
// src/adapter/rules.ts
|
|
1332
|
-
var MaseValidationError = class extends Error {
|
|
1333
|
-
constructor(message, code, field) {
|
|
1334
|
-
super(message);
|
|
1335
|
-
this.name = "ValidationError";
|
|
1336
|
-
this.code = code;
|
|
1337
|
-
this.field = field;
|
|
1338
|
-
}
|
|
1339
|
-
};
|
|
1340
|
-
var MaseGovernanceRule = class {
|
|
1341
|
-
constructor() {
|
|
1342
|
-
this.name = "MASE-Constitutional-Compliance";
|
|
1343
|
-
this.description = "Enforces strict adherence to Component Constitution using MASE SRE.";
|
|
1344
|
-
this.category = "business";
|
|
1345
|
-
// It's a business rule (Design System Law)
|
|
1346
|
-
this.severity = "error";
|
|
1347
|
-
const tokenRegistry = new TokenRegistry();
|
|
1348
|
-
const themeResolver = new ThemeResolver();
|
|
1349
|
-
this.engine = new StyleResolutionEngine(tokenRegistry, themeResolver);
|
|
1350
|
-
}
|
|
1351
|
-
async validate(target, _context) {
|
|
1352
|
-
const result = this.engine.resolve(target.contract, target.constitution);
|
|
1353
|
-
if (result.valid) {
|
|
1354
|
-
return null;
|
|
1355
|
-
}
|
|
1356
|
-
const primaryViolation = result.violations[0];
|
|
1357
|
-
const messages = result.violations.map((v) => `[${v.rule}] ${v.message} (${v.semantic})`).join("; ");
|
|
1358
|
-
return new MaseValidationError(
|
|
1359
|
-
messages,
|
|
1360
|
-
primaryViolation.rule,
|
|
1361
|
-
// code
|
|
1362
|
-
target.constitution.componentName
|
|
1363
|
-
// field/target
|
|
1364
|
-
);
|
|
1365
|
-
}
|
|
1366
|
-
};
|
|
1367
|
-
|
|
1368
1419
|
// src/data/constitutions/ButtonConstitution.ts
|
|
1369
1420
|
var ButtonConstitution = {
|
|
1370
1421
|
componentName: "Button",
|
|
@@ -1390,7 +1441,17 @@ var ButtonConstitution = {
|
|
|
1390
1441
|
]
|
|
1391
1442
|
};
|
|
1392
1443
|
|
|
1393
|
-
// src/dsl/
|
|
1444
|
+
// src/dsl/lexer/TokenizerError.ts
|
|
1445
|
+
var TokenizerError = class extends Error {
|
|
1446
|
+
constructor(message, line, column) {
|
|
1447
|
+
super(message);
|
|
1448
|
+
this.name = "TokenizerError";
|
|
1449
|
+
this.line = line;
|
|
1450
|
+
this.column = column;
|
|
1451
|
+
}
|
|
1452
|
+
};
|
|
1453
|
+
|
|
1454
|
+
// src/dsl/lexer/Tokenizer.ts
|
|
1394
1455
|
var TokenType = {
|
|
1395
1456
|
// Keywords
|
|
1396
1457
|
CONTRACT: "CONTRACT",
|
|
@@ -1432,14 +1493,6 @@ var TokenType = {
|
|
|
1432
1493
|
EOF: "EOF",
|
|
1433
1494
|
UNKNOWN: "UNKNOWN"
|
|
1434
1495
|
};
|
|
1435
|
-
var TokenizerError = class extends Error {
|
|
1436
|
-
constructor(message, line, column) {
|
|
1437
|
-
super(message);
|
|
1438
|
-
this.name = "TokenizerError";
|
|
1439
|
-
this.line = line;
|
|
1440
|
-
this.column = column;
|
|
1441
|
-
}
|
|
1442
|
-
};
|
|
1443
1496
|
var ContractDSLTokenizer = class {
|
|
1444
1497
|
constructor() {
|
|
1445
1498
|
this.source = "";
|
|
@@ -1463,7 +1516,7 @@ var ContractDSLTokenizer = class {
|
|
|
1463
1516
|
["web", TokenType.WEB],
|
|
1464
1517
|
["native", TokenType.NATIVE],
|
|
1465
1518
|
["canvas", TokenType.CANVAS],
|
|
1466
|
-
[
|
|
1519
|
+
// ['default', TokenType.DEFAULT_CTX], // Removed duplicate mapping
|
|
1467
1520
|
["hover", TokenType.HOVER],
|
|
1468
1521
|
["active", TokenType.ACTIVE],
|
|
1469
1522
|
["disabled", TokenType.DISABLED],
|
|
@@ -1623,7 +1676,7 @@ var ContractDSLTokenizer = class {
|
|
|
1623
1676
|
}
|
|
1624
1677
|
};
|
|
1625
1678
|
|
|
1626
|
-
// src/dsl/
|
|
1679
|
+
// src/dsl/parser/ParserError.ts
|
|
1627
1680
|
var ParserError = class extends Error {
|
|
1628
1681
|
constructor(message, line, column) {
|
|
1629
1682
|
super(message);
|
|
@@ -1632,6 +1685,8 @@ var ParserError = class extends Error {
|
|
|
1632
1685
|
this.column = column;
|
|
1633
1686
|
}
|
|
1634
1687
|
};
|
|
1688
|
+
|
|
1689
|
+
// src/dsl/parser/Parser.ts
|
|
1635
1690
|
var ContractDSLParser = class {
|
|
1636
1691
|
constructor() {
|
|
1637
1692
|
this.tokens = [];
|
|
@@ -1676,7 +1731,7 @@ var ContractDSLParser = class {
|
|
|
1676
1731
|
parseDomain() {
|
|
1677
1732
|
this.expect(TokenType.DOMAIN);
|
|
1678
1733
|
this.expect(TokenType.COLON);
|
|
1679
|
-
const domain = this.
|
|
1734
|
+
const domain = this.expectDomain();
|
|
1680
1735
|
this.expect(TokenType.SEMICOLON);
|
|
1681
1736
|
return domain;
|
|
1682
1737
|
}
|
|
@@ -1813,13 +1868,29 @@ var ContractDSLParser = class {
|
|
|
1813
1868
|
this.advance();
|
|
1814
1869
|
return token.value;
|
|
1815
1870
|
}
|
|
1871
|
+
/**
|
|
1872
|
+
* Expect domain token
|
|
1873
|
+
* @returns Domain value
|
|
1874
|
+
*/
|
|
1875
|
+
expectDomain() {
|
|
1876
|
+
const token = this.peek();
|
|
1877
|
+
if (!token || token.type !== TokenType.LAYOUT && token.type !== TokenType.TYPOGRAPHY && token.type !== TokenType.COLOR && token.type !== TokenType.EFFECT && token.type !== TokenType.INTERACTION && token.type !== TokenType.IDENTIFIER) {
|
|
1878
|
+
throw new ParserError(
|
|
1879
|
+
`Expected domain, got ${token?.type || "EOF"}`,
|
|
1880
|
+
token?.line || 0,
|
|
1881
|
+
token?.column || 0
|
|
1882
|
+
);
|
|
1883
|
+
}
|
|
1884
|
+
this.advance();
|
|
1885
|
+
return token.value;
|
|
1886
|
+
}
|
|
1816
1887
|
/**
|
|
1817
1888
|
* Expect context token
|
|
1818
1889
|
* @returns Context value
|
|
1819
1890
|
*/
|
|
1820
1891
|
expectContext() {
|
|
1821
1892
|
const token = this.peek();
|
|
1822
|
-
if (!token || token.type !== TokenType.MOBILE && token.type !== TokenType.TABLET && token.type !== TokenType.DESKTOP && token.type !== TokenType.LIGHT && token.type !== TokenType.DARK && token.type !== TokenType.WEB && token.type !== TokenType.NATIVE && token.type !== TokenType.CANVAS && token.type !== TokenType.DEFAULT_CTX && token.type !== TokenType.HOVER && token.type !== TokenType.ACTIVE && token.type !== TokenType.DISABLED) {
|
|
1893
|
+
if (!token || token.type !== TokenType.MOBILE && token.type !== TokenType.TABLET && token.type !== TokenType.DESKTOP && token.type !== TokenType.LIGHT && token.type !== TokenType.DARK && token.type !== TokenType.WEB && token.type !== TokenType.NATIVE && token.type !== TokenType.CANVAS && token.type !== TokenType.DEFAULT_CTX && token.type !== TokenType.DEFAULT && token.type !== TokenType.HOVER && token.type !== TokenType.ACTIVE && token.type !== TokenType.DISABLED) {
|
|
1823
1894
|
throw new ParserError(
|
|
1824
1895
|
`Expected context, got ${token?.type || "EOF"}`,
|
|
1825
1896
|
token?.line || 0,
|
|
@@ -1859,7 +1930,7 @@ var ContractDSLParser = class {
|
|
|
1859
1930
|
}
|
|
1860
1931
|
};
|
|
1861
1932
|
|
|
1862
|
-
// src/dsl/
|
|
1933
|
+
// src/dsl/validator/ValidationError.ts
|
|
1863
1934
|
var ValidationError2 = class extends Error {
|
|
1864
1935
|
constructor(message, path) {
|
|
1865
1936
|
super(message);
|
|
@@ -1867,6 +1938,8 @@ var ValidationError2 = class extends Error {
|
|
|
1867
1938
|
this.path = path;
|
|
1868
1939
|
}
|
|
1869
1940
|
};
|
|
1941
|
+
|
|
1942
|
+
// src/dsl/validator/Validator.ts
|
|
1870
1943
|
var ContractDSLValidator = class {
|
|
1871
1944
|
constructor() {
|
|
1872
1945
|
this.validDomains = /* @__PURE__ */ new Set([
|
|
@@ -2149,7 +2222,7 @@ var ContractDSLValidator = class {
|
|
|
2149
2222
|
}
|
|
2150
2223
|
};
|
|
2151
2224
|
|
|
2152
|
-
// src/dsl/Compiler.ts
|
|
2225
|
+
// src/dsl/compiler/Compiler.ts
|
|
2153
2226
|
var ContractDSLCompiler = class {
|
|
2154
2227
|
/**
|
|
2155
2228
|
* Compile AST to ComponentConstitution and StyleContractDefinition
|
|
@@ -2304,7 +2377,7 @@ var ContractDSLCompiler = class {
|
|
|
2304
2377
|
}
|
|
2305
2378
|
};
|
|
2306
2379
|
|
|
2307
|
-
// src/materializer/
|
|
2380
|
+
// src/materializer/core/MaterializationError.ts
|
|
2308
2381
|
var MaterializationError = class extends Error {
|
|
2309
2382
|
constructor(message, platform, semantic) {
|
|
2310
2383
|
super(message);
|
|
@@ -2314,7 +2387,7 @@ var MaterializationError = class extends Error {
|
|
|
2314
2387
|
}
|
|
2315
2388
|
};
|
|
2316
2389
|
|
|
2317
|
-
// src/materializer/CSSMaterializer.ts
|
|
2390
|
+
// src/materializer/targets/CSSMaterializer.ts
|
|
2318
2391
|
var CSSMaterializer = class {
|
|
2319
2392
|
constructor() {
|
|
2320
2393
|
this.semanticToCSS = this.buildSemanticToCSSMapping();
|
|
@@ -2476,7 +2549,7 @@ var CSSMaterializer = class {
|
|
|
2476
2549
|
}
|
|
2477
2550
|
};
|
|
2478
2551
|
|
|
2479
|
-
// src/materializer/RNMaterializer.ts
|
|
2552
|
+
// src/materializer/targets/RNMaterializer.ts
|
|
2480
2553
|
var RNMaterializer = class {
|
|
2481
2554
|
constructor() {
|
|
2482
2555
|
this.semanticToRN = this.buildSemanticToRNMapping();
|
|
@@ -2591,7 +2664,7 @@ var RNMaterializer = class {
|
|
|
2591
2664
|
}
|
|
2592
2665
|
};
|
|
2593
2666
|
|
|
2594
|
-
// src/materializer/PDFMaterializer.ts
|
|
2667
|
+
// src/materializer/targets/PDFMaterializer.ts
|
|
2595
2668
|
var PDFMaterializer = class {
|
|
2596
2669
|
constructor() {
|
|
2597
2670
|
this.semanticToPDF = this.buildSemanticToPDFMapping();
|
|
@@ -2707,6 +2780,7 @@ var PDFMaterializer = class {
|
|
|
2707
2780
|
};
|
|
2708
2781
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2709
2782
|
0 && (module.exports = {
|
|
2783
|
+
AllowedTokenValidator,
|
|
2710
2784
|
ButtonConstitution,
|
|
2711
2785
|
CSSMaterializer,
|
|
2712
2786
|
CanonicalStyleGraph,
|
|
@@ -2719,11 +2793,13 @@ var PDFMaterializer = class {
|
|
|
2719
2793
|
ContractDSLTokenizer,
|
|
2720
2794
|
ContractDSLValidator,
|
|
2721
2795
|
DefaultViolationHandlers,
|
|
2796
|
+
DomainValidator,
|
|
2722
2797
|
MaseGovernanceRule,
|
|
2723
2798
|
MaseGraphValidationPlugin,
|
|
2724
2799
|
MaseValidationError,
|
|
2725
2800
|
MaseValidationRule,
|
|
2726
2801
|
MaterializationError,
|
|
2802
|
+
NativePlatformAdapter,
|
|
2727
2803
|
PDFMaterializer,
|
|
2728
2804
|
RNMaterializer,
|
|
2729
2805
|
StyleContract,
|
|
@@ -2731,8 +2807,10 @@ var PDFMaterializer = class {
|
|
|
2731
2807
|
StyleResolutionEngine,
|
|
2732
2808
|
TOKENS,
|
|
2733
2809
|
ThemeResolver,
|
|
2810
|
+
TokenExistenceValidator,
|
|
2734
2811
|
TokenRegistry,
|
|
2735
2812
|
ViolationEngine,
|
|
2813
|
+
WebPlatformAdapter,
|
|
2736
2814
|
useStyleContext
|
|
2737
2815
|
});
|
|
2738
2816
|
//# sourceMappingURL=index.js.map
|