@ngcorex/css 0.1.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 (66) hide show
  1. package/LICENSE.md +9 -0
  2. package/README.md +41 -0
  3. package/dist/config/define-config.d.ts +3 -0
  4. package/dist/config/define-config.d.ts.map +1 -0
  5. package/dist/config/define-config.js +3 -0
  6. package/dist/config/index.d.ts +3 -0
  7. package/dist/config/index.d.ts.map +1 -0
  8. package/dist/config/index.js +2 -0
  9. package/dist/config/schema.d.ts +68 -0
  10. package/dist/config/schema.d.ts.map +1 -0
  11. package/dist/config/schema.js +1 -0
  12. package/dist/constraints/colors.d.ts +6 -0
  13. package/dist/constraints/colors.d.ts.map +1 -0
  14. package/dist/constraints/colors.js +49 -0
  15. package/dist/constraints/constraint-error.d.ts +3 -0
  16. package/dist/constraints/constraint-error.d.ts.map +1 -0
  17. package/dist/constraints/constraint-error.js +11 -0
  18. package/dist/constraints/resolve-level.d.ts +3 -0
  19. package/dist/constraints/resolve-level.d.ts.map +1 -0
  20. package/dist/constraints/resolve-level.js +11 -0
  21. package/dist/constraints/run-constraints.d.ts +3 -0
  22. package/dist/constraints/run-constraints.d.ts.map +1 -0
  23. package/dist/constraints/run-constraints.js +14 -0
  24. package/dist/constraints/spacing.d.ts +3 -0
  25. package/dist/constraints/spacing.d.ts.map +1 -0
  26. package/dist/constraints/spacing.js +26 -0
  27. package/dist/constraints/types.d.ts +2 -0
  28. package/dist/constraints/types.d.ts.map +1 -0
  29. package/dist/constraints/types.js +1 -0
  30. package/dist/engine/build-css.d.ts +6 -0
  31. package/dist/engine/build-css.d.ts.map +1 -0
  32. package/dist/engine/build-css.js +53 -0
  33. package/dist/errors/ngcorex-error.d.ts +4 -0
  34. package/dist/errors/ngcorex-error.d.ts.map +1 -0
  35. package/dist/errors/ngcorex-error.js +8 -0
  36. package/dist/index.d.ts +12 -0
  37. package/dist/index.d.ts.map +1 -0
  38. package/dist/index.js +10 -0
  39. package/dist/internal.d.ts +2 -0
  40. package/dist/internal.d.ts.map +1 -0
  41. package/dist/internal.js +9 -0
  42. package/dist/output/wrap-css.d.ts +5 -0
  43. package/dist/output/wrap-css.d.ts.map +1 -0
  44. package/dist/output/wrap-css.js +15 -0
  45. package/dist/presets/default.d.ts +3 -0
  46. package/dist/presets/default.d.ts.map +1 -0
  47. package/dist/presets/default.js +24 -0
  48. package/dist/presets/index.d.ts +3 -0
  49. package/dist/presets/index.d.ts.map +1 -0
  50. package/dist/presets/index.js +4 -0
  51. package/dist/tokens/generate-css.d.ts +6 -0
  52. package/dist/tokens/generate-css.d.ts.map +1 -0
  53. package/dist/tokens/generate-css.js +13 -0
  54. package/dist/tokens/normalize-colors.d.ts +6 -0
  55. package/dist/tokens/normalize-colors.d.ts.map +1 -0
  56. package/dist/tokens/normalize-colors.js +30 -0
  57. package/dist/tokens/normalize.d.ts +6 -0
  58. package/dist/tokens/normalize.d.ts.map +1 -0
  59. package/dist/tokens/normalize.js +28 -0
  60. package/dist/tokens/types.d.ts +9 -0
  61. package/dist/tokens/types.d.ts.map +1 -0
  62. package/dist/tokens/types.js +1 -0
  63. package/dist/utils/deep-merge.d.ts +8 -0
  64. package/dist/utils/deep-merge.d.ts.map +1 -0
  65. package/dist/utils/deep-merge.js +26 -0
  66. package/package.json +23 -0
package/LICENSE.md ADDED
@@ -0,0 +1,9 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Ajay Kumar Sharma
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # @ngcorex/css
2
+
3
+ Core engine for **ngCorex**.
4
+
5
+ This package provides:
6
+
7
+ - design token normalization
8
+ - constraint validation
9
+ - CSS variable generation
10
+ - optional CSS layer wrapping
11
+
12
+ It is intended to be used via the ngCorex CLI, not directly in applications.
13
+
14
+ ## Installation
15
+
16
+ ```bash
17
+ npm install @ngcorex/css
18
+ ````
19
+
20
+ ## Usage
21
+
22
+ This package is usually consumed internally by the CLI.
23
+
24
+ Example:
25
+
26
+ ```ts
27
+ import { defineNgCorexConfig } from '@ngcorex/css';
28
+
29
+ export default defineNgCorexConfig({
30
+ tokens: {
31
+ spacing: {
32
+ 1: 4,
33
+ 2: 8
34
+ }
35
+ }
36
+ });
37
+ ```
38
+
39
+ ## License
40
+
41
+ MIT
@@ -0,0 +1,3 @@
1
+ import type { NgCorexConfig } from './schema.js';
2
+ export declare function defineNgCorexConfig(config: NgCorexConfig): NgCorexConfig;
3
+ //# sourceMappingURL=define-config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"define-config.d.ts","sourceRoot":"","sources":["../../src/config/define-config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAEjD,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,aAAa,GAAG,aAAa,CAExE"}
@@ -0,0 +1,3 @@
1
+ export function defineNgCorexConfig(config) {
2
+ return config;
3
+ }
@@ -0,0 +1,3 @@
1
+ export { defineNgCorexConfig } from './define-config.js';
2
+ export * from './schema.js';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AACzD,cAAc,aAAa,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { defineNgCorexConfig } from './define-config.js';
2
+ export * from './schema.js';
@@ -0,0 +1,68 @@
1
+ import type { TokenScale } from '../tokens/types.js';
2
+ import type { NestedTokenScale } from '../tokens/types.js';
3
+ export type ConstraintLevel = 'error' | 'warning' | 'off';
4
+ export interface ConstraintConfig {
5
+ spacing?: {
6
+ unit?: ConstraintLevel;
7
+ format?: ConstraintLevel;
8
+ type?: ConstraintLevel;
9
+ };
10
+ colors?: {
11
+ type?: ConstraintLevel;
12
+ format?: ConstraintLevel;
13
+ shadeKey?: ConstraintLevel;
14
+ };
15
+ }
16
+ export interface TokensConfig {
17
+ spacing?: TokenScale;
18
+ colors?: NestedTokenScale;
19
+ radius?: TokenScale;
20
+ typography?: {
21
+ fontSize?: TokenScale;
22
+ fontWeight?: TokenScale;
23
+ lineHeight?: TokenScale;
24
+ };
25
+ }
26
+ export interface UtilitiesConfig {
27
+ spacing?: {
28
+ margin?: boolean;
29
+ padding?: boolean;
30
+ gap?: boolean;
31
+ };
32
+ color?: {
33
+ text?: string[];
34
+ background?: string[];
35
+ border?: string[];
36
+ };
37
+ layout?: {
38
+ display?: boolean;
39
+ flex?: boolean;
40
+ grid?: boolean;
41
+ };
42
+ }
43
+ export type ConstraintSeverity = 'error' | 'warning' | 'info';
44
+ export interface ConstraintsConfig {
45
+ forbidArbitraryValues?: {
46
+ severity: ConstraintSeverity;
47
+ };
48
+ spacingScaleOnly?: {
49
+ allowed: string[];
50
+ severity: ConstraintSeverity;
51
+ };
52
+ maxUtilityCountPerElement?: {
53
+ max: number;
54
+ severity: ConstraintSeverity;
55
+ };
56
+ }
57
+ export interface OutputConfig {
58
+ file?: string;
59
+ layer?: string;
60
+ }
61
+ export interface NgCorexConfig {
62
+ tokens?: TokensConfig;
63
+ utilities?: UtilitiesConfig;
64
+ constraints?: ConstraintConfig;
65
+ presets?: string[];
66
+ output?: OutputConfig;
67
+ }
68
+ //# sourceMappingURL=schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/config/schema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAC3D,MAAM,MAAM,eAAe,GAAG,OAAO,GAAG,SAAS,GAAG,KAAK,CAAC;AAE1D,MAAM,WAAW,gBAAgB;IAC/B,OAAO,CAAC,EAAE;QACR,IAAI,CAAC,EAAE,eAAe,CAAC;QACvB,MAAM,CAAC,EAAE,eAAe,CAAC;QACzB,IAAI,CAAC,EAAE,eAAe,CAAC;KACxB,CAAC;IACF,MAAM,CAAC,EAAE;QACP,IAAI,CAAC,EAAE,eAAe,CAAC;QACvB,MAAM,CAAC,EAAE,eAAe,CAAC;QACzB,QAAQ,CAAC,EAAE,eAAe,CAAC;KAC5B,CAAC;CACH;AAGD,MAAM,WAAW,YAAY;IACzB,OAAO,CAAC,EAAE,UAAU,CAAC;IACrB,MAAM,CAAC,EAAE,gBAAgB,CAAC;IAC1B,MAAM,CAAC,EAAE,UAAU,CAAC;IACpB,UAAU,CAAC,EAAE;QACT,QAAQ,CAAC,EAAE,UAAU,CAAC;QACtB,UAAU,CAAC,EAAE,UAAU,CAAC;QACxB,UAAU,CAAC,EAAE,UAAU,CAAC;KAC3B,CAAC;CACL;AAED,MAAM,WAAW,eAAe;IAC5B,OAAO,CAAC,EAAE;QACN,MAAM,CAAC,EAAE,OAAO,CAAC;QACjB,OAAO,CAAC,EAAE,OAAO,CAAC;QAClB,GAAG,CAAC,EAAE,OAAO,CAAC;KACjB,CAAC;IACF,KAAK,CAAC,EAAE;QACJ,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;QAChB,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;QACtB,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;KACrB,CAAC;IACF,MAAM,CAAC,EAAE;QACL,OAAO,CAAC,EAAE,OAAO,CAAC;QAClB,IAAI,CAAC,EAAE,OAAO,CAAC;QACf,IAAI,CAAC,EAAE,OAAO,CAAC;KAClB,CAAC;CACL;AAED,MAAM,MAAM,kBAAkB,GAAG,OAAO,GAAG,SAAS,GAAG,MAAM,CAAC;AAE9D,MAAM,WAAW,iBAAiB;IAC9B,qBAAqB,CAAC,EAAE;QACpB,QAAQ,EAAE,kBAAkB,CAAC;KAChC,CAAC;IACF,gBAAgB,CAAC,EAAE;QACf,OAAO,EAAE,MAAM,EAAE,CAAC;QAClB,QAAQ,EAAE,kBAAkB,CAAC;KAChC,CAAC;IACF,yBAAyB,CAAC,EAAE;QACxB,GAAG,EAAE,MAAM,CAAC;QACZ,QAAQ,EAAE,kBAAkB,CAAC;KAChC,CAAC;CACL;AAED,MAAM,WAAW,YAAY;IAC3B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,aAAa;IAC1B,MAAM,CAAC,EAAE,YAAY,CAAC;IACtB,SAAS,CAAC,EAAE,eAAe,CAAC;IAC5B,WAAW,CAAC,EAAE,gBAAgB,CAAC;IAC/B,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,MAAM,CAAC,EAAE,YAAY,CAAC;CACzB"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,6 @@
1
+ import type { ConstraintConfig } from '../config/schema.js';
2
+ /**
3
+ * Validate color token constraints
4
+ */
5
+ export declare function validateColorConstraints(colors: Record<string, Record<string, string>>, config?: ConstraintConfig['colors']): void;
6
+ //# sourceMappingURL=colors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"colors.d.ts","sourceRoot":"","sources":["../../src/constraints/colors.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAE5D;;GAEG;AACH,wBAAgB,wBAAwB,CACtC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,EAC9C,MAAM,CAAC,EAAE,gBAAgB,CAAC,QAAQ,CAAC,GAClC,IAAI,CAkDN"}
@@ -0,0 +1,49 @@
1
+ import { constraintViolation } from './constraint-error.js';
2
+ import { resolveConstraintLevel } from './resolve-level.js';
3
+ /**
4
+ * Validate color token constraints
5
+ */
6
+ export function validateColorConstraints(colors, config) {
7
+ for (const paletteName in colors) {
8
+ const palette = colors[paletteName];
9
+ const shadeKeys = Object.keys(palette);
10
+ // 1. Shade keys must be numeric
11
+ for (const key of shadeKeys) {
12
+ if (Number.isNaN(Number(key))) {
13
+ constraintViolation(resolveConstraintLevel(config?.shadeKey, 'error'), 'color.shade.key', `Color scale "${paletteName}" contains non-numeric shade key "${key}".`, `Use numeric shade keys like 50, 100, 200, ..., 900.`);
14
+ }
15
+ }
16
+ // 2. Validate each shade value
17
+ for (const shade in palette) {
18
+ const value = palette[shade];
19
+ if (typeof value !== 'string') {
20
+ constraintViolation(resolveConstraintLevel(config?.type, 'error'), 'color.type', `Token colors.${paletteName}.${shade} is not a string.`, `Change colors.${paletteName}.${shade} to a valid color string.`);
21
+ continue;
22
+ }
23
+ if (!isValidColor(value)) {
24
+ constraintViolation(resolveConstraintLevel(config?.format, 'error'), 'color.format', `Token colors.${paletteName}.${shade} has invalid value "${value}".`, `Allowed formats:
25
+ - Hex: #RGB or #RRGGBB
26
+ - rgb(r, g, b)
27
+ - rgba(r, g, b, a)
28
+
29
+ Examples:
30
+ - "#2563eb"
31
+ - "rgb(37, 99, 235)"
32
+ - "rgba(37, 99, 235, 0.8)"`);
33
+ }
34
+ }
35
+ }
36
+ }
37
+ /**
38
+ * Allowed color formats:
39
+ * - #RGB
40
+ * - #RRGGBB
41
+ * - rgb()
42
+ * - rgba()
43
+ */
44
+ function isValidColor(value) {
45
+ const hex = /^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/;
46
+ const rgb = /^rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)$/;
47
+ const rgba = /^rgba\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(0|0?\.\d+|1(\.0+)?)\s*\)$/;
48
+ return hex.test(value) || rgb.test(value) || rgba.test(value);
49
+ }
@@ -0,0 +1,3 @@
1
+ import type { ConstraintLevel } from '../config/schema.js';
2
+ export declare function constraintViolation(level: ConstraintLevel, rule: string, message: string, fix: string): void;
3
+ //# sourceMappingURL=constraint-error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constraint-error.d.ts","sourceRoot":"","sources":["../../src/constraints/constraint-error.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAE3D,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,eAAe,EACtB,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,GAAG,EAAE,MAAM,GACV,IAAI,CAgBN"}
@@ -0,0 +1,11 @@
1
+ import { NgCorexError } from '../errors/ngcorex-error.js';
2
+ export function constraintViolation(level, rule, message, fix) {
3
+ if (level === 'off') {
4
+ return;
5
+ }
6
+ if (level === 'error') {
7
+ throw new NgCorexError(`Constraint violation: ${rule}`, `${message}\n\nFix:\n${fix}`);
8
+ }
9
+ // warning
10
+ console.warn(`ngCorex Warning: ${rule}\n\n${message}\n\nFix:\n${fix}\n`);
11
+ }
@@ -0,0 +1,3 @@
1
+ import type { ConstraintLevel } from '../config/schema.js';
2
+ export declare function resolveConstraintLevel(userLevel: ConstraintLevel | undefined, defaultLevel: ConstraintLevel): ConstraintLevel;
3
+ //# sourceMappingURL=resolve-level.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolve-level.d.ts","sourceRoot":"","sources":["../../src/constraints/resolve-level.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAE3D,wBAAgB,sBAAsB,CACpC,SAAS,EAAE,eAAe,GAAG,SAAS,EACtC,YAAY,EAAE,eAAe,GAC5B,eAAe,CAQjB"}
@@ -0,0 +1,11 @@
1
+ export function resolveConstraintLevel(userLevel, defaultLevel) {
2
+ if (!userLevel)
3
+ return defaultLevel;
4
+ if (userLevel === 'off')
5
+ return 'off';
6
+ if (userLevel === 'warning')
7
+ return 'warning';
8
+ if (userLevel === 'error')
9
+ return 'error';
10
+ return defaultLevel;
11
+ }
@@ -0,0 +1,3 @@
1
+ import type { NgCorexConfig } from '../config/schema.js';
2
+ export declare function runConstraints(config: NgCorexConfig): void;
3
+ //# sourceMappingURL=run-constraints.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run-constraints.d.ts","sourceRoot":"","sources":["../../src/constraints/run-constraints.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAoB,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAI3E,wBAAgB,cAAc,CAAC,MAAM,EAAE,aAAa,GAAG,IAAI,CAa1D"}
@@ -0,0 +1,14 @@
1
+ import { validateSpacingConstraints } from './spacing.js';
2
+ import { validateColorConstraints } from './colors.js';
3
+ export function runConstraints(config) {
4
+ const tokens = config.tokens;
5
+ const rules = config.constraints;
6
+ if (!tokens)
7
+ return;
8
+ if (tokens.spacing) {
9
+ validateSpacingConstraints(tokens.spacing, rules?.spacing);
10
+ }
11
+ if (tokens.colors) {
12
+ validateColorConstraints(tokens.colors, rules?.colors);
13
+ }
14
+ }
@@ -0,0 +1,3 @@
1
+ import type { ConstraintConfig } from '../config/schema.js';
2
+ export declare function validateSpacingConstraints(spacing: Record<string, string>, config?: ConstraintConfig['spacing']): void;
3
+ //# sourceMappingURL=spacing.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"spacing.d.ts","sourceRoot":"","sources":["../../src/constraints/spacing.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAE5D,wBAAgB,0BAA0B,CACxC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC/B,MAAM,CAAC,EAAE,gBAAgB,CAAC,SAAS,CAAC,GACnC,IAAI,CAqCN"}
@@ -0,0 +1,26 @@
1
+ import { constraintViolation } from './constraint-error.js';
2
+ import { resolveConstraintLevel } from './resolve-level.js';
3
+ export function validateSpacingConstraints(spacing, config) {
4
+ for (const key in spacing) {
5
+ const value = spacing[key];
6
+ if (typeof value !== 'string') {
7
+ constraintViolation(resolveConstraintLevel(config?.type, 'error'), 'spacing.type', `Token spacing.${key} is not a string.`, `Change spacing.${key} to a string value like "8px" or "0.5rem".`);
8
+ return;
9
+ }
10
+ if (isUnitlessNumber(value)) {
11
+ spacing[key] = `${value}px`;
12
+ constraintViolation(resolveConstraintLevel(config?.unit, 'warning'), 'spacing.unit', `Token spacing.${key} had no unit. Defaulted to "${spacing[key]}".`, `Explicitly add a unit (e.g. "px", "rem") to spacing.${key}.`);
13
+ continue;
14
+ }
15
+ if (isValidSpacingValue(value)) {
16
+ continue;
17
+ }
18
+ constraintViolation(resolveConstraintLevel(config?.format, 'error'), 'spacing.format', `Token spacing.${key} has invalid value "${value}".`, `Use a numeric value with a unit.`);
19
+ }
20
+ }
21
+ function isUnitlessNumber(value) {
22
+ return /^-?\d*\.?\d+$/.test(value);
23
+ }
24
+ function isValidSpacingValue(value) {
25
+ return /^-?\d*\.?\d+(px|rem|em|%)$/.test(value);
26
+ }
@@ -0,0 +1,2 @@
1
+ export type ConstraintSeverity = 'error' | 'warning';
2
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/constraints/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,kBAAkB,GAAG,OAAO,GAAG,SAAS,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,6 @@
1
+ import type { NgCorexConfig } from '../config/schema.js';
2
+ /**
3
+ * Build CSS variables from ngCorex config
4
+ */
5
+ export declare function buildCssFromConfig(config: NgCorexConfig): string;
6
+ //# sourceMappingURL=build-css.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"build-css.d.ts","sourceRoot":"","sources":["../../src/engine/build-css.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAazD;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,aAAa,GAAG,MAAM,CA+DhE"}
@@ -0,0 +1,53 @@
1
+ import { normalizeTokenScale } from '../tokens/normalize.js';
2
+ import { normalizeColorTokens } from '../tokens/normalize-colors.js';
3
+ import { generateCssVariables } from '../tokens/generate-css.js';
4
+ import { presetRegistry } from '../presets/index.js';
5
+ import { NgCorexError } from '../errors/ngcorex-error.js';
6
+ import { deepMerge } from '../utils/deep-merge.js';
7
+ import { runConstraints } from '../constraints/run-constraints.js';
8
+ import { wrapCss } from '../output/wrap-css.js';
9
+ /**
10
+ * Build CSS variables from ngCorex config
11
+ */
12
+ export function buildCssFromConfig(config) {
13
+ const allTokens = {};
14
+ let resolvedTokens = {};
15
+ // 1. Apply presets
16
+ if (config.presets) {
17
+ for (const presetName of config.presets) {
18
+ const preset = presetRegistry[presetName];
19
+ if (!preset) {
20
+ throw new NgCorexError('Unknown preset', `Preset "${presetName}" does not exist.
21
+
22
+ Available presets:
23
+ - ${Object.keys(presetRegistry).join('\n- ')}
24
+
25
+ Fix:
26
+ Use one of the available presets or remove it from ngcorex.config.ts`);
27
+ }
28
+ if (preset.tokens) {
29
+ resolvedTokens = deepMerge(resolvedTokens, preset.tokens);
30
+ }
31
+ }
32
+ }
33
+ // 2. Apply user overrides
34
+ if (config.tokens) {
35
+ resolvedTokens = deepMerge(resolvedTokens, config.tokens);
36
+ }
37
+ const tokens = resolvedTokens;
38
+ runConstraints({ tokens });
39
+ if (!tokens) {
40
+ return '';
41
+ }
42
+ // 3. Normalize spacing
43
+ if (tokens.spacing) {
44
+ Object.assign(allTokens, normalizeTokenScale('spacing', tokens.spacing));
45
+ }
46
+ // 4. Normalize colors
47
+ if (tokens.colors) {
48
+ Object.assign(allTokens, normalizeColorTokens(tokens.colors));
49
+ }
50
+ // 5. Generate CSS
51
+ const css = generateCssVariables(allTokens);
52
+ return wrapCss(css, config.output?.layer);
53
+ }
@@ -0,0 +1,4 @@
1
+ export declare class NgCorexError extends Error {
2
+ constructor(message: string, details?: string);
3
+ }
4
+ //# sourceMappingURL=ngcorex-error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ngcorex-error.d.ts","sourceRoot":"","sources":["../../src/errors/ngcorex-error.ts"],"names":[],"mappings":"AAAA,qBAAa,YAAa,SAAQ,KAAK;gBACzB,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM;CAQ9C"}
@@ -0,0 +1,8 @@
1
+ export class NgCorexError extends Error {
2
+ constructor(message, details) {
3
+ super(details
4
+ ? `ngCorex Error: ${message}\n\n${details}`
5
+ : `ngCorex Error: ${message}`);
6
+ this.name = 'NgCorexError';
7
+ }
8
+ }
@@ -0,0 +1,12 @@
1
+ export { defineNgCorexConfig } from './config/define-config.js';
2
+ export type { NgCorexConfig, TokensConfig, UtilitiesConfig, ConstraintsConfig } from './config/schema.js';
3
+ export type { TokenScale, NormalizedToken, NormalizedTokenGroup } from './tokens/types.js';
4
+ export { normalizeTokenScale } from './tokens/normalize.js';
5
+ export { normalizeColorTokens } from './tokens/normalize-colors.js';
6
+ export { generateCssVariables } from './tokens/generate-css.js';
7
+ export { buildCssFromConfig } from './engine/build-css.js';
8
+ export { presetRegistry } from './presets/index.js';
9
+ export { NgCorexError } from './errors/ngcorex-error.js';
10
+ export { runConstraints } from './constraints/run-constraints.js';
11
+ export { wrapCss } from './output/wrap-css.js';
12
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAChE,YAAY,EACV,aAAa,EACb,YAAY,EACZ,eAAe,EACf,iBAAiB,EAClB,MAAM,oBAAoB,CAAC;AAG5B,YAAY,EACV,UAAU,EACV,eAAe,EACf,oBAAoB,EACrB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAE5D,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AAEpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAEhE,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAE3D,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEpD,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAEzD,OAAO,EAAE,cAAc,EAAE,MAAM,kCAAkC,CAAC;AAElE,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,10 @@
1
+ // Config API
2
+ export { defineNgCorexConfig } from './config/define-config.js';
3
+ export { normalizeTokenScale } from './tokens/normalize.js';
4
+ export { normalizeColorTokens } from './tokens/normalize-colors.js';
5
+ export { generateCssVariables } from './tokens/generate-css.js';
6
+ export { buildCssFromConfig } from './engine/build-css.js';
7
+ export { presetRegistry } from './presets/index.js';
8
+ export { NgCorexError } from './errors/ngcorex-error.js';
9
+ export { runConstraints } from './constraints/run-constraints.js';
10
+ export { wrapCss } from './output/wrap-css.js';
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=internal.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":""}
@@ -0,0 +1,9 @@
1
+ import { buildCssFromConfig } from './engine/build-css.js';
2
+ const testConfig = {
3
+ presets: ['default'],
4
+ output: {
5
+ layer: 'tokens'
6
+ }
7
+ };
8
+ const css = buildCssFromConfig(testConfig);
9
+ console.log(css);
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Wrap CSS in a layer if configured
3
+ */
4
+ export declare function wrapCss(css: string, layer?: string): string;
5
+ //# sourceMappingURL=wrap-css.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wrap-css.d.ts","sourceRoot":"","sources":["../../src/output/wrap-css.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,wBAAgB,OAAO,CACrB,GAAG,EAAE,MAAM,EACX,KAAK,CAAC,EAAE,MAAM,GACb,MAAM,CAMR"}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Wrap CSS in a layer if configured
3
+ */
4
+ export function wrapCss(css, layer) {
5
+ if (!layer) {
6
+ return css;
7
+ }
8
+ return `@layer ${layer} {\n${indent(css)}\n}`;
9
+ }
10
+ function indent(css) {
11
+ return css
12
+ .split('\n')
13
+ .map(line => ` ${line}`)
14
+ .join('\n');
15
+ }
@@ -0,0 +1,3 @@
1
+ import type { NgCorexConfig } from '../config/schema.js';
2
+ export declare const presetDefault: NgCorexConfig;
3
+ //# sourceMappingURL=default.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"default.d.ts","sourceRoot":"","sources":["../../src/presets/default.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEzD,eAAO,MAAM,aAAa,EAAE,aAuB3B,CAAC"}
@@ -0,0 +1,24 @@
1
+ export const presetDefault = {
2
+ tokens: {
3
+ spacing: {
4
+ xs: '0.25rem',
5
+ sm: '0.5rem',
6
+ md: '1rem',
7
+ lg: '1.5rem',
8
+ xl: '2rem'
9
+ },
10
+ colors: {
11
+ neutral: {
12
+ 0: '#ffffff',
13
+ 100: '#f5f5f5',
14
+ 300: '#d4d4d4',
15
+ 500: '#737373',
16
+ 700: '#404040',
17
+ 900: '#171717'
18
+ },
19
+ primary: {
20
+ 500: '#2563eb'
21
+ }
22
+ }
23
+ }
24
+ };
@@ -0,0 +1,3 @@
1
+ import type { NgCorexConfig } from '../config/schema.js';
2
+ export declare const presetRegistry: Record<string, NgCorexConfig>;
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/presets/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAGzD,eAAO,MAAM,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAExD,CAAC"}
@@ -0,0 +1,4 @@
1
+ import { presetDefault } from './default.js';
2
+ export const presetRegistry = {
3
+ default: presetDefault
4
+ };
@@ -0,0 +1,6 @@
1
+ import type { NormalizedTokenGroup } from './types.js';
2
+ /**
3
+ * Generate CSS variables from normalized tokens
4
+ */
5
+ export declare function generateCssVariables(tokens: NormalizedTokenGroup): string;
6
+ //# sourceMappingURL=generate-css.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate-css.d.ts","sourceRoot":"","sources":["../../src/tokens/generate-css.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAEvD;;GAEG;AACH,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,oBAAoB,GAC3B,MAAM,CAaR"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Generate CSS variables from normalized tokens
3
+ */
4
+ export function generateCssVariables(tokens) {
5
+ const lines = [];
6
+ lines.push(':root {');
7
+ for (const key in tokens) {
8
+ const token = tokens[key];
9
+ lines.push(` ${token.cssVariable}: ${token.value};`);
10
+ }
11
+ lines.push('}');
12
+ return lines.join('\n');
13
+ }
@@ -0,0 +1,6 @@
1
+ import type { NestedTokenScale, NormalizedTokenGroup } from './types.js';
2
+ /**
3
+ * Normalize nested color tokens (e.g. primary.500)
4
+ */
5
+ export declare function normalizeColorTokens(colors: NestedTokenScale): NormalizedTokenGroup;
6
+ //# sourceMappingURL=normalize-colors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"normalize-colors.d.ts","sourceRoot":"","sources":["../../src/tokens/normalize-colors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAgB,EAChB,oBAAoB,EACrB,MAAM,YAAY,CAAC;AAKpB;;GAEG;AACH,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,gBAAgB,GACvB,oBAAoB,CAiCtB"}
@@ -0,0 +1,30 @@
1
+ import { NgCorexError } from '../errors/ngcorex-error.js';
2
+ const CSS_VAR_PREFIX = 'nx';
3
+ /**
4
+ * Normalize nested color tokens (e.g. primary.500)
5
+ */
6
+ export function normalizeColorTokens(colors) {
7
+ const result = {};
8
+ for (const paletteName in colors) {
9
+ const palette = colors[paletteName];
10
+ for (const shade in palette) {
11
+ const value = palette[shade];
12
+ if (typeof value !== 'string') {
13
+ throw new NgCorexError('Invalid color token', `Token: colors.${paletteName}.${shade}
14
+ Value: ${String(value)}
15
+ Expected: string (e.g. "#ffffff")
16
+
17
+ Fix:
18
+ Update colors.${paletteName}.${shade} in ngcorex.config.ts`);
19
+ }
20
+ const name = `color-${paletteName}-${shade}`;
21
+ const cssVariable = `--${CSS_VAR_PREFIX}-${name}`;
22
+ result[`${paletteName}-${shade}`] = {
23
+ name,
24
+ cssVariable,
25
+ value
26
+ };
27
+ }
28
+ }
29
+ return result;
30
+ }
@@ -0,0 +1,6 @@
1
+ import type { TokenScale, NormalizedTokenGroup } from './types.ts';
2
+ /**
3
+ * Normalize a single token scale (e.g. spacing, radius)
4
+ */
5
+ export declare function normalizeTokenScale(category: string, scale: TokenScale): NormalizedTokenGroup;
6
+ //# sourceMappingURL=normalize.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"normalize.d.ts","sourceRoot":"","sources":["../../src/tokens/normalize.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAmB,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAMpF;;GAEG;AACH,wBAAgB,mBAAmB,CACjC,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,UAAU,GAChB,oBAAoB,CA8BtB"}
@@ -0,0 +1,28 @@
1
+ import { NgCorexError } from '../errors/ngcorex-error.js';
2
+ const CSS_VAR_PREFIX = 'nx';
3
+ /**
4
+ * Normalize a single token scale (e.g. spacing, radius)
5
+ */
6
+ export function normalizeTokenScale(category, scale) {
7
+ const result = {};
8
+ for (const key in scale) {
9
+ const value = scale[key];
10
+ // Basic validation
11
+ if (typeof value !== 'string') {
12
+ throw new NgCorexError(`Invalid ${category} token`, `Token: ${category}.${key}
13
+ Value: ${String(value)}
14
+ Expected: string (e.g. "1rem")
15
+
16
+ Fix:
17
+ Update ${category}.${key} in ngcorex.config.ts`);
18
+ }
19
+ const name = `${category}-${key}`;
20
+ const cssVariable = `--${CSS_VAR_PREFIX}-${name}`;
21
+ result[key] = {
22
+ name,
23
+ cssVariable,
24
+ value
25
+ };
26
+ }
27
+ return result;
28
+ }
@@ -0,0 +1,9 @@
1
+ export type TokenScale = Record<string, string>;
2
+ export type NestedTokenScale = Record<string, TokenScale>;
3
+ export interface NormalizedToken {
4
+ name: string;
5
+ cssVariable: string;
6
+ value: string;
7
+ }
8
+ export type NormalizedTokenGroup = Record<string, NormalizedToken>;
9
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/tokens/types.ts"],"names":[],"mappings":"AACA,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAGhD,MAAM,MAAM,gBAAgB,GAAG,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;AAG1D,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;CACf;AAGD,MAAM,MAAM,oBAAoB,GAAG,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Deep merge two plain objects.
3
+ * - Objects are merged recursively
4
+ * - Primitive values are overridden
5
+ * - Arrays are replaced
6
+ */
7
+ export declare function deepMerge(base: Record<string, any>, override: Record<string, any>): Record<string, any>;
8
+ //# sourceMappingURL=deep-merge.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deep-merge.d.ts","sourceRoot":"","sources":["../../src/utils/deep-merge.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,wBAAgB,SAAS,CACvB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EACzB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAC5B,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAkBrB"}
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Deep merge two plain objects.
3
+ * - Objects are merged recursively
4
+ * - Primitive values are overridden
5
+ * - Arrays are replaced
6
+ */
7
+ export function deepMerge(base, override) {
8
+ const result = { ...base };
9
+ for (const key of Object.keys(override)) {
10
+ const baseValue = base[key];
11
+ const overrideValue = override[key];
12
+ if (isPlainObject(baseValue) &&
13
+ isPlainObject(overrideValue)) {
14
+ result[key] = deepMerge(baseValue, overrideValue);
15
+ }
16
+ else if (overrideValue !== undefined) {
17
+ result[key] = overrideValue;
18
+ }
19
+ }
20
+ return result;
21
+ }
22
+ function isPlainObject(value) {
23
+ return (typeof value === 'object' &&
24
+ value !== null &&
25
+ !Array.isArray(value));
26
+ }
package/package.json ADDED
@@ -0,0 +1,23 @@
1
+ {
2
+ "name": "@ngcorex/css",
3
+ "version": "0.1.0",
4
+ "description": "Angular-native design token and utility CSS engine",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "main": "dist/index.js",
8
+ "types": "dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "default": "./dist/index.js"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist",
17
+ "README.md",
18
+ "LICENSE.md"
19
+ ],
20
+ "scripts": {
21
+ "build": "tsc -p tsconfig.json"
22
+ }
23
+ }