@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.
@@ -56,7 +56,6 @@ interface StyleResolutionResult {
56
56
  readonly valid: boolean;
57
57
  readonly nodes: ReadonlyArray<SemanticNode>;
58
58
  readonly violations: ReadonlyArray<StyleViolation>;
59
- readonly className: string;
60
59
  }
61
60
 
62
61
  /**
@@ -80,6 +79,29 @@ interface ITokenRegistry {
80
79
  getAllTokens(): Readonly<Record<string, Token$1>>;
81
80
  }
82
81
 
82
+ /**
83
+ * TokenRegistry
84
+ * Concrete implementation of ITokenRegistry.
85
+ * Provides immutable access to token definitions.
86
+ */
87
+ declare class TokenRegistry implements ITokenRegistry {
88
+ private readonly tokens;
89
+ constructor(tokens?: Record<string, Token$1>);
90
+ /**
91
+ * Get token by ID
92
+ * @throws Error if token not found
93
+ */
94
+ getToken(id: string): Token$1;
95
+ /**
96
+ * Check if token exists
97
+ */
98
+ hasToken(id: string): boolean;
99
+ /**
100
+ * Get all tokens (immutable)
101
+ */
102
+ getAllTokens(): Readonly<Record<string, Token$1>>;
103
+ }
104
+
83
105
  /**
84
106
  * IThemeResolver
85
107
  * Abstraction for theme-aware value resolution.
@@ -105,67 +127,22 @@ interface IThemeResolver {
105
127
  }
106
128
 
107
129
  /**
108
- * IValidationStrategy
109
- * Strategy pattern for validation logic.
110
- * Each strategy handles a specific validation concern.
111
- */
112
- interface IValidationStrategy {
113
- /**
114
- * Validate a single property against a rule
115
- * @param property - Property name being validated
116
- * @param value - Token ID being validated
117
- * @param rule - Style rule to validate against
118
- * @param context - Optional style context
119
- * @returns Violation if validation fails, null if passes
120
- */
121
- validate(property: string, value: string, rule: StyleRule, context?: StyleContext): StyleViolation | null;
122
- /**
123
- * Get strategy name for debugging and logging
124
- */
125
- getName(): string;
126
- }
127
-
128
- /**
129
- * StyleResolutionEngine (REFACTORED)
130
- *
131
- * Refactored to follow SOLID principles:
132
- * - SRP: Only handles resolution logic
133
- * - DIP: Depends on abstractions (ITokenRegistry, IThemeResolver)
134
- * - OCP: Extensible via validation strategies
135
- *
136
- * Responsibilities:
137
- * - Contract validation against constitution
138
- * - Semantic node generation
139
- * - Materialization (temporary, will move to SME)
130
+ * ThemeResolver
131
+ * Concrete implementation of IThemeResolver.
132
+ * Handles theme-aware value resolution.
140
133
  */
141
- declare class StyleResolutionEngine {
142
- private readonly tokenRegistry;
143
- private readonly themeResolver;
144
- private readonly validators;
145
- constructor(tokenRegistry: ITokenRegistry, themeResolver: IThemeResolver, validators?: ReadonlyArray<IValidationStrategy>);
146
- /**
147
- * resolve()
148
- * Main function: Validates style contract against constitution
149
- *
150
- * @param contract - Style contract definition
151
- * @param constitution - Component constitution
152
- * @param context - Optional style context
153
- * @returns Resolution result with nodes, violations, and className
154
- */
155
- resolve(contract: StyleContractDefinition, constitution: ComponentConstitution, context?: StyleContext): StyleResolutionResult;
134
+ declare class ThemeResolver implements IThemeResolver {
156
135
  /**
157
- * validateAndResolve()
158
- * Internal helper to validate and resolve a single token
136
+ * Resolve theme value based on current theme
159
137
  */
160
- private validateAndResolve;
138
+ resolve(value: ThemeValue, theme: StyleTheme): string;
161
139
  /**
162
- * materializeToken()
163
- * Resolve token value based on context (Theme/Breakpoint)
164
- *
165
- * NOTE: This is temporary materialization logic.
166
- * In Phase 5, this will be replaced by StyleMaterializationEngine (SME).
140
+ * Get current theme from context
141
+ * Defaults to 'light' if not specified
167
142
  */
168
- private materializeToken;
143
+ getCurrentTheme(context?: {
144
+ theme?: StyleTheme;
145
+ }): StyleTheme;
169
146
  }
170
147
 
171
148
  /**
@@ -383,6 +360,61 @@ declare class ContextBinder {
383
360
  static createDefaultRules(): ContextBindingRule[];
384
361
  }
385
362
 
363
+ /**
364
+ * IValidationStrategy
365
+ * Strategy pattern for validation logic.
366
+ * Each strategy handles a specific validation concern.
367
+ */
368
+ interface IValidationStrategy {
369
+ /**
370
+ * Validate a single property against a rule
371
+ * @param property - Property name being validated
372
+ * @param value - Token ID being validated
373
+ * @param rule - Style rule to validate against
374
+ * @param context - Optional style context
375
+ * @returns Violation if validation fails, null if passes
376
+ */
377
+ validate(property: string, value: string, rule: StyleRule, context?: StyleContext): StyleViolation | null;
378
+ /**
379
+ * Get strategy name for debugging and logging
380
+ */
381
+ getName(): string;
382
+ }
383
+
384
+ /**
385
+ * StyleResolutionEngine (REFACTORED)
386
+ *
387
+ * Refactored to follow SOLID principles:
388
+ * - SRP: Only handles resolution logic
389
+ * - DIP: Depends on abstractions (ITokenRegistry, IThemeResolver)
390
+ * - OCP: Extensible via validation strategies
391
+ *
392
+ * Responsibilities:
393
+ * - Contract validation against constitution
394
+ * - Semantic node generation
395
+ */
396
+ declare class StyleResolutionEngine {
397
+ private readonly tokenRegistry;
398
+ private readonly themeResolver;
399
+ private readonly validators;
400
+ constructor(tokenRegistry: ITokenRegistry, themeResolver: IThemeResolver, validators?: ReadonlyArray<IValidationStrategy>);
401
+ /**
402
+ * resolve()
403
+ * Main function: Validates style contract against constitution
404
+ *
405
+ * @param contract - Style contract definition
406
+ * @param constitution - Component constitution
407
+ * @param context - Optional style context
408
+ * @returns Resolution result with nodes and violations
409
+ */
410
+ resolve(contract: StyleContractDefinition, constitution: ComponentConstitution, context?: StyleContext): StyleResolutionResult;
411
+ /**
412
+ * validateAndResolve()
413
+ * Internal helper to validate and resolve a single token
414
+ */
415
+ private validateAndResolve;
416
+ }
417
+
386
418
  /**
387
419
  * ViolationAction
388
420
  * Action to take when a violation is detected.
@@ -487,6 +519,7 @@ declare class ViolationEngine {
487
519
  */
488
520
  setDefaultAction(action: ViolationAction): void;
489
521
  }
522
+
490
523
  /**
491
524
  * DefaultViolationHandlers
492
525
  * Common violation handlers for typical scenarios.
@@ -515,45 +548,52 @@ declare class DefaultViolationHandlers {
515
548
  }
516
549
 
517
550
  /**
518
- * TokenRegistry
519
- * Concrete implementation of ITokenRegistry.
520
- * Provides immutable access to token definitions.
551
+ * AllowedTokenValidator
552
+ * Validates that token is in the allowed list for a rule.
521
553
  */
522
- declare class TokenRegistry implements ITokenRegistry {
523
- private readonly tokens;
524
- constructor(tokens?: Record<string, Token$1>);
554
+ declare class AllowedTokenValidator implements IValidationStrategy {
525
555
  /**
526
- * Get token by ID
527
- * @throws Error if token not found
556
+ * Validate that token is allowed
528
557
  */
529
- getToken(id: string): Token$1;
558
+ validate(property: string, tokenId: string, rule: StyleRule, context?: StyleContext): StyleViolation | null;
530
559
  /**
531
- * Check if token exists
560
+ * Get strategy name
532
561
  */
533
- hasToken(id: string): boolean;
562
+ getName(): string;
563
+ }
564
+
565
+ /**
566
+ * DomainValidator
567
+ * Validates that token domain matches rule domain.
568
+ */
569
+ declare class DomainValidator implements IValidationStrategy {
570
+ private readonly tokenRegistry;
571
+ constructor(tokenRegistry: ITokenRegistry);
534
572
  /**
535
- * Get all tokens (immutable)
573
+ * Validate that token domain matches rule domain
536
574
  */
537
- getAllTokens(): Readonly<Record<string, Token$1>>;
575
+ validate(property: string, tokenId: string, rule: StyleRule, context?: StyleContext): StyleViolation | null;
576
+ /**
577
+ * Get strategy name
578
+ */
579
+ getName(): string;
538
580
  }
539
581
 
540
582
  /**
541
- * ThemeResolver
542
- * Concrete implementation of IThemeResolver.
543
- * Handles theme-aware value resolution.
583
+ * TokenExistenceValidator
584
+ * Validates that a token exists in the registry.
544
585
  */
545
- declare class ThemeResolver implements IThemeResolver {
586
+ declare class TokenExistenceValidator implements IValidationStrategy {
587
+ private readonly tokenRegistry;
588
+ constructor(tokenRegistry: ITokenRegistry);
546
589
  /**
547
- * Resolve theme value based on current theme
590
+ * Validate that token exists
548
591
  */
549
- resolve(value: ThemeValue, theme: StyleTheme): string;
592
+ validate(property: string, tokenId: string, rule: StyleRule, context?: StyleContext): StyleViolation | null;
550
593
  /**
551
- * Get current theme from context
552
- * Defaults to 'light' if not specified
594
+ * Get strategy name
553
595
  */
554
- getCurrentTheme(context?: {
555
- theme?: StyleTheme;
556
- }): StyleTheme;
596
+ getName(): string;
557
597
  }
558
598
 
559
599
  /**
@@ -665,6 +705,26 @@ declare class StyleContract {
665
705
  toJSON(): Record<string, any>;
666
706
  }
667
707
 
708
+ interface PlatformAdapter {
709
+ /**
710
+ * Platform identifier
711
+ */
712
+ readonly platform: 'web' | 'native' | 'canvas';
713
+ /**
714
+ * Get initial device type based on environment
715
+ */
716
+ getInitialDevice(): 'mobile' | 'tablet' | 'desktop';
717
+ /**
718
+ * Subscribe to dimension/resize updates
719
+ * @returns Unsubscribe function
720
+ */
721
+ subscribeToResize(callback: (device: 'mobile' | 'tablet' | 'desktop') => void): () => void;
722
+ /**
723
+ * Apply theme side-effects (e.g., adding class to body/html)
724
+ */
725
+ applyTheme(theme: 'light' | 'dark'): void;
726
+ }
727
+
668
728
  interface StyleContextState extends StyleContext {
669
729
  toggleTheme: () => void;
670
730
  setTheme: (theme: StyleTheme) => void;
@@ -672,10 +732,37 @@ interface StyleContextState extends StyleContext {
672
732
  interface StyleProviderProps {
673
733
  children: ReactNode;
674
734
  initialTheme?: StyleTheme;
735
+ /**
736
+ * Platform adapter for device detection and theme application.
737
+ * Defaults to WebPlatformAdapter if not provided.
738
+ */
739
+ adapter?: PlatformAdapter;
675
740
  }
676
741
  declare const StyleProvider: React.FC<StyleProviderProps>;
677
742
  declare const useStyleContext: () => StyleContextState;
678
743
 
744
+ declare class WebPlatformAdapter implements PlatformAdapter {
745
+ readonly platform: "web";
746
+ getInitialDevice(): 'mobile' | 'tablet' | 'desktop';
747
+ subscribeToResize(callback: (device: 'mobile' | 'tablet' | 'desktop') => void): () => void;
748
+ applyTheme(theme: 'light' | 'dark'): void;
749
+ }
750
+
751
+ /**
752
+ * NativePlatformAdapter
753
+ *
754
+ * Implementation for React Native / Native environments.
755
+ * Currently a stub as we are primarily Web-first, but ensures architecture is ready.
756
+ *
757
+ * TODO: Implement with React Native Dimensions/Appearance API
758
+ */
759
+ declare class NativePlatformAdapter implements PlatformAdapter {
760
+ readonly platform: "native";
761
+ getInitialDevice(): 'mobile' | 'tablet' | 'desktop';
762
+ subscribeToResize(callback: (device: 'mobile' | 'tablet' | 'desktop') => void): () => void;
763
+ applyTheme(theme: 'light' | 'dark'): void;
764
+ }
765
+
679
766
  interface ValidationPluginMetadata {
680
767
  name: string;
681
768
  version: string;
@@ -701,18 +788,6 @@ interface ValidationPlugin {
701
788
  message?: string;
702
789
  }>;
703
790
  }
704
- /**
705
- * MaseValidationRule
706
- * Adapts MASE's StyleResolutionEngine to Meta Architecture's ValidationRule interface.
707
- * Allows "Style Audits" to be run as part of the broader governance pipeline.
708
- */
709
- declare class MaseValidationRule implements ValidationRule<any> {
710
- name: string;
711
- description: string;
712
- category: "business";
713
- severity: "error";
714
- validate(target: any, context: ValidationContext): Promise<ValidationError$1 | null>;
715
- }
716
791
  /**
717
792
  * MasePlugin
718
793
  * The entry point for Meta Architecture to load MASE capabilities.
@@ -728,15 +803,6 @@ declare class MaseGraphValidationPlugin implements ValidationPlugin {
728
803
  }>;
729
804
  }
730
805
 
731
- /**
732
- * Factory untuk membuat pipeline validasi yang sudah dikonfigurasi dengan MASE Plugin.
733
- * Ini mensimulasikan "System Boot" di environment Enterprise/Server-side.
734
- */
735
- declare class CompliancePipelineFactory {
736
- static createPipeline(): Promise<ValidationPipeline>;
737
- static createMockTargets(): any[];
738
- }
739
-
740
806
  declare class MaseValidationError extends Error {
741
807
  code: string;
742
808
  field?: string;
@@ -765,6 +831,28 @@ declare class MaseGovernanceRule implements ValidationRule<MaseContractTarget> {
765
831
  validate(target: MaseContractTarget, _context: ValidationContext): Promise<MaseValidationError | null>;
766
832
  }
767
833
 
834
+ /**
835
+ * MaseValidationRule
836
+ * Adapts MASE's StyleResolutionEngine to Meta Architecture's ValidationRule interface.
837
+ * Allows "Style Audits" to be run as part of the broader governance pipeline.
838
+ */
839
+ declare class MaseValidationRule implements ValidationRule<any> {
840
+ name: string;
841
+ description: string;
842
+ category: "business";
843
+ severity: "error";
844
+ validate(target: any, context: ValidationContext): Promise<ValidationError$1 | null>;
845
+ }
846
+
847
+ /**
848
+ * Factory untuk membuat pipeline validasi yang sudah dikonfigurasi dengan MASE Plugin.
849
+ * Ini mensimulasikan "System Boot" di environment Enterprise/Server-side.
850
+ */
851
+ declare class CompliancePipelineFactory {
852
+ static createPipeline(): Promise<ValidationPipeline>;
853
+ static createMockTargets(): any[];
854
+ }
855
+
768
856
  declare const TOKENS: Record<string, Token$1>;
769
857
 
770
858
  declare const ButtonConstitution: ComponentConstitution;
@@ -1006,6 +1094,11 @@ declare class ContractDSLParser {
1006
1094
  * @returns Identifier value
1007
1095
  */
1008
1096
  private expectIdentifier;
1097
+ /**
1098
+ * Expect domain token
1099
+ * @returns Domain value
1100
+ */
1101
+ private expectDomain;
1009
1102
  /**
1010
1103
  * Expect context token
1011
1104
  * @returns Context value
@@ -1027,6 +1120,11 @@ declare class ContractDSLParser {
1027
1120
  private advance;
1028
1121
  }
1029
1122
 
1123
+ declare class ValidationError extends Error {
1124
+ readonly path: string;
1125
+ constructor(message: string, path: string);
1126
+ }
1127
+
1030
1128
  /**
1031
1129
  * Contract DSL Validator
1032
1130
  *
@@ -1044,14 +1142,6 @@ declare class ContractDSLParser {
1044
1142
  * - DDD: Domain-specific validation rules
1045
1143
  */
1046
1144
 
1047
- /**
1048
- * ValidationError
1049
- * Error during validation.
1050
- */
1051
- declare class ValidationError extends Error {
1052
- readonly path: string;
1053
- constructor(message: string, path: string);
1054
- }
1055
1145
  /**
1056
1146
  * ValidationResult
1057
1147
  * Result of validation.
@@ -1280,6 +1370,7 @@ interface Materializer<T> {
1280
1370
  */
1281
1371
  materialize(nodes: readonly SemanticNode[], context: MaterializationContext): MaterializationResult<T>;
1282
1372
  }
1373
+
1283
1374
  /**
1284
1375
  * MaterializationError
1285
1376
  * Error during materialization.
@@ -1506,4 +1597,4 @@ declare class PDFMaterializer implements Materializer<PDFStyle> {
1506
1597
  private toCamelCase;
1507
1598
  }
1508
1599
 
1509
- export { type BoundContext, ButtonConstitution, type CSGEdge, type CSGNode, CSSMaterializer, CanonicalStyleGraph, CardConstitution, CompliancePipelineFactory, type ComponentConstitution, type ConstraintRule, ContextBinder, type ContextBindingRule, ContextFactory, ContractDSLCompiler, ContractDSLParser, ContractDSLTokenizer, ContractDSLValidator, DefaultViolationHandlers, type GraphValidation, type MaseContractTarget, MaseGovernanceRule, MaseGraphValidationPlugin, MaseValidationError, MaseValidationRule, type MaterializationContext, MaterializationError, type MaterializationResult, type Materializer, PDFMaterializer, RNMaterializer, type ResponsiveValue, type SemanticNode, type StyleBreakpoint, type StyleContext, StyleContract, type StyleContractDefinition, type StyleDomain, StyleProvider, StyleResolutionEngine, type StyleResolutionResult, type StyleRule, type StyleTheme, type StyleViolation, TOKENS, ThemeResolver, type ThemeValue, type Token$1 as Token, TokenRegistry, type ValidationPlugin, type ValidationPluginConfig, type ValidationPluginMetadata, type ViolationAction, ViolationEngine, type ViolationHandler, type ViolationOutcome, type ViolationSeverity, useStyleContext };
1600
+ export { AllowedTokenValidator, type BoundContext, ButtonConstitution, type CSGEdge, type CSGNode, CSSMaterializer, CanonicalStyleGraph, CardConstitution, CompliancePipelineFactory, type ComponentConstitution, type ConstraintRule, ContextBinder, type ContextBindingRule, ContextFactory, ContractDSLCompiler, ContractDSLParser, ContractDSLTokenizer, ContractDSLValidator, DefaultViolationHandlers, DomainValidator, type GraphValidation, type IThemeResolver, type ITokenRegistry, type IValidationStrategy, type MaseContractTarget, MaseGovernanceRule, MaseGraphValidationPlugin, MaseValidationError, MaseValidationRule, type MaterializationContext, MaterializationError, type MaterializationResult, type Materializer, NativePlatformAdapter, PDFMaterializer, type PlatformAdapter, RNMaterializer, type ResponsiveValue, type SemanticNode, type StyleBreakpoint, type StyleContext, StyleContract, type StyleContractDefinition, type StyleDomain, StyleProvider, StyleResolutionEngine, type StyleResolutionResult, type StyleRule, type StyleTheme, type StyleViolation, TOKENS, ThemeResolver, type ThemeValue, type Token$1 as Token, TokenExistenceValidator, TokenRegistry, type ViolationAction, ViolationEngine, type ViolationHandler, type ViolationOutcome, type ViolationSeverity, WebPlatformAdapter, useStyleContext };