@sxl-studio/token-transformer 1.0.0 → 2.0.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 (93) hide show
  1. package/README.en.md +77 -608
  2. package/README.md +77 -685
  3. package/config/sxl-transform.config.yaml +120 -0
  4. package/dist/cli.d.ts +1 -1
  5. package/dist/cli.js +411 -141
  6. package/dist/cli.js.map +1 -1
  7. package/dist/config/loader.d.ts +6 -0
  8. package/dist/config/loader.js +160 -0
  9. package/dist/config/loader.js.map +1 -0
  10. package/dist/config/schema.d.ts +847 -0
  11. package/dist/config/schema.js +123 -0
  12. package/dist/config/schema.js.map +1 -0
  13. package/dist/core/color-modifiers.d.ts +31 -0
  14. package/dist/core/color-modifiers.js +289 -0
  15. package/dist/core/color-modifiers.js.map +1 -0
  16. package/dist/core/color-parser.d.ts +24 -0
  17. package/dist/core/color-parser.js +281 -0
  18. package/dist/core/color-parser.js.map +1 -0
  19. package/dist/core/debug-report.d.ts +11 -0
  20. package/dist/core/debug-report.js +161 -0
  21. package/dist/core/debug-report.js.map +1 -0
  22. package/dist/core/incremental.d.ts +18 -0
  23. package/dist/core/incremental.js +105 -0
  24. package/dist/core/incremental.js.map +1 -0
  25. package/dist/core/math.d.ts +3 -0
  26. package/dist/core/math.js +261 -0
  27. package/dist/core/math.js.map +1 -0
  28. package/dist/core/parser.d.ts +4 -3
  29. package/dist/core/parser.js +68 -172
  30. package/dist/core/parser.js.map +1 -1
  31. package/dist/core/resolver.d.ts +26 -0
  32. package/dist/core/resolver.js +431 -0
  33. package/dist/core/resolver.js.map +1 -0
  34. package/dist/core/token-loader.d.ts +11 -0
  35. package/dist/core/token-loader.js +380 -0
  36. package/dist/core/token-loader.js.map +1 -0
  37. package/dist/core/token-parser.d.ts +9 -0
  38. package/dist/core/token-parser.js +138 -0
  39. package/dist/core/token-parser.js.map +1 -0
  40. package/dist/core/token-types.d.ts +7 -0
  41. package/dist/core/token-types.js +132 -0
  42. package/dist/core/token-types.js.map +1 -0
  43. package/dist/core/types.d.ts +154 -63
  44. package/dist/core/writer.d.ts +18 -5
  45. package/dist/core/writer.js +545 -91
  46. package/dist/core/writer.js.map +1 -1
  47. package/dist/emit/css.d.ts +2 -0
  48. package/dist/emit/css.js +538 -0
  49. package/dist/emit/css.js.map +1 -0
  50. package/dist/emit/kotlin.d.ts +2 -0
  51. package/dist/emit/kotlin.js +406 -0
  52. package/dist/emit/kotlin.js.map +1 -0
  53. package/dist/emit/shared.d.ts +13 -0
  54. package/dist/emit/shared.js +127 -0
  55. package/dist/emit/shared.js.map +1 -0
  56. package/dist/emit/swift.d.ts +2 -0
  57. package/dist/emit/swift.js +432 -0
  58. package/dist/emit/swift.js.map +1 -0
  59. package/dist/emit/typography.d.ts +17 -0
  60. package/dist/emit/typography.js +132 -0
  61. package/dist/emit/typography.js.map +1 -0
  62. package/dist/emit/xml.d.ts +2 -0
  63. package/dist/emit/xml.js +311 -0
  64. package/dist/emit/xml.js.map +1 -0
  65. package/dist/index.d.ts +15 -6
  66. package/dist/index.js +13 -5
  67. package/dist/index.js.map +1 -1
  68. package/dist/transformers/css.d.ts +1 -1
  69. package/dist/transformers/css.js +13 -482
  70. package/dist/transformers/css.js.map +1 -1
  71. package/dist/transformers/kotlin.d.ts +2 -2
  72. package/dist/transformers/kotlin.js +14 -442
  73. package/dist/transformers/kotlin.js.map +1 -1
  74. package/dist/transformers/swiftui.d.ts +2 -2
  75. package/dist/transformers/swiftui.js +14 -433
  76. package/dist/transformers/swiftui.js.map +1 -1
  77. package/dist/utils/color.d.ts +7 -5
  78. package/dist/utils/color.js +90 -86
  79. package/dist/utils/color.js.map +1 -1
  80. package/dist/utils/dimension.d.ts +8 -5
  81. package/dist/utils/dimension.js +54 -52
  82. package/dist/utils/dimension.js.map +1 -1
  83. package/dist/utils/naming.d.ts +10 -12
  84. package/dist/utils/naming.js +102 -44
  85. package/dist/utils/naming.js.map +1 -1
  86. package/package.json +30 -10
  87. package/config.example.json +0 -45
  88. package/dist/core/loader.d.ts +0 -8
  89. package/dist/core/loader.js +0 -105
  90. package/dist/core/loader.js.map +0 -1
  91. package/dist/transformers/vue3.d.ts +0 -28
  92. package/dist/transformers/vue3.js +0 -534
  93. package/dist/transformers/vue3.js.map +0 -1
@@ -0,0 +1,160 @@
1
+ import fs from "node:fs/promises";
2
+ import path from "node:path";
3
+ import yaml from "js-yaml";
4
+ import { TransformerConfigSchema, } from "./schema.js";
5
+ export async function loadConfig(configPath, options = {}) {
6
+ const workspaceRoot = path.resolve(options.workspaceRoot ?? process.cwd());
7
+ void workspaceRoot;
8
+ const absoluteConfigPath = path.resolve(configPath);
9
+ const configDir = path.dirname(absoluteConfigPath);
10
+ if (!absoluteConfigPath.endsWith(".yaml") && !absoluteConfigPath.endsWith(".yml")) {
11
+ throw new Error(`JSON config is no longer supported. Use YAML config (e.g. sxl-transform.config.yaml). ` +
12
+ `Provided: ${absoluteConfigPath}`);
13
+ }
14
+ const content = await fs.readFile(absoluteConfigPath, "utf-8");
15
+ const raw = yaml.load(content);
16
+ if (!raw || typeof raw !== "object") {
17
+ throw new Error(`Config at ${absoluteConfigPath} must be a YAML object`);
18
+ }
19
+ const parsed = TransformerConfigSchema.parse(raw);
20
+ const tokenSetIdSet = new Set();
21
+ for (const tokenSet of parsed.tokenSets) {
22
+ if (tokenSetIdSet.has(tokenSet.id)) {
23
+ throw new Error(`Duplicate tokenSet id: "${tokenSet.id}"`);
24
+ }
25
+ tokenSetIdSet.add(tokenSet.id);
26
+ }
27
+ const outputIdSet = new Set();
28
+ for (const output of parsed.outputs) {
29
+ if (outputIdSet.has(output.id)) {
30
+ throw new Error(`Duplicate output id: "${output.id}"`);
31
+ }
32
+ outputIdSet.add(output.id);
33
+ for (const file of output.files) {
34
+ if (!tokenSetIdSet.has(file.tokenSet)) {
35
+ throw new Error(`Output "${output.id}" references unknown tokenSet "${file.tokenSet}". ` +
36
+ `Known tokenSets: ${Array.from(tokenSetIdSet).join(", ")}`);
37
+ }
38
+ }
39
+ }
40
+ const tokenDir = path.resolve(configDir, parsed.source.tokenDir);
41
+ const sourceConfigFile = path.resolve(tokenDir, parsed.source.configFile);
42
+ const resolved = {
43
+ ...parsed,
44
+ source: {
45
+ tokenDir,
46
+ configFile: sourceConfigFile,
47
+ include: parsed.source.include,
48
+ exclude: parsed.source.exclude,
49
+ },
50
+ outputs: parsed.outputs.map((output) => ({
51
+ ...output,
52
+ outputDir: path.resolve(configDir, output.outputDir),
53
+ })),
54
+ };
55
+ return resolved;
56
+ }
57
+ export function createInitConfigTemplate() {
58
+ return `version: 1
59
+ source:
60
+ tokenDir: ./tokens
61
+ configFile: config.json
62
+ include: ["**/*.json"]
63
+ exclude: ["config.json", "**/diff-id*.json"]
64
+
65
+ options:
66
+ remBase: 16
67
+ collisionStrategy: error
68
+ unsupportedTypes:
69
+ default: warn
70
+ types:
71
+ template: skip
72
+ composition: skip
73
+
74
+ tokenSets:
75
+ - id: app-root
76
+ selectors:
77
+ - collection: Foundations
78
+ mode: Default
79
+ - collection: Product
80
+ mode: Base
81
+ - collection: Theme
82
+ mode: Light
83
+ refModeMap:
84
+ Product: Base
85
+ Foundations: Default
86
+ - collection: Breakpoint
87
+ mode: Desktop
88
+ refModeMap:
89
+ Product: Base
90
+ Foundations: Default
91
+ - collection: Surface
92
+ mode: Low
93
+ refModeMap:
94
+ Theme: Light
95
+ Product: Base
96
+ Foundations: Default
97
+
98
+ - id: mode-dark
99
+ selectors:
100
+ - collection: Theme
101
+ mode: Dark
102
+ refModeMap:
103
+ Product: Base
104
+ Foundations: Default
105
+
106
+ - id: components-style
107
+ unresolvedAliases: ignore
108
+ selectors:
109
+ - files:
110
+ - components/**/*.style.json
111
+
112
+ outputs:
113
+ - id: css
114
+ platform: css
115
+ outputDir: ./ds/styles/css
116
+ prefix: null
117
+ resolveAliases: false
118
+ splitEffects: true
119
+ showDescriptions: true
120
+ files:
121
+ - tokenSet: app-root
122
+ output: root.css
123
+ - tokenSet: mode-dark
124
+ output: themes/dark.css
125
+ - tokenSet: components-style
126
+ output: ../components
127
+ splitBySourceFile:
128
+ include:
129
+ - components/**/*.style.json
130
+ outputPattern: "{component}/{component}.css"
131
+
132
+ - id: swift
133
+ platform: swift
134
+ outputDir: ./ds/styles/swift
135
+ resolveAliases: true
136
+ showDescriptions: true
137
+ files:
138
+ - tokenSet: app-root
139
+ output: Root.swift
140
+
141
+ - id: kotlin
142
+ platform: kotlin
143
+ outputDir: ./ds/styles/kotlin
144
+ resolveAliases: true
145
+ showDescriptions: true
146
+ files:
147
+ - tokenSet: app-root
148
+ output: Root.kt
149
+
150
+ - id: xml
151
+ platform: xml
152
+ outputDir: ./ds/styles/xml
153
+ resolveAliases: true
154
+ showDescriptions: false
155
+ files:
156
+ - tokenSet: app-root
157
+ output: values
158
+ `;
159
+ }
160
+ //# sourceMappingURL=loader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loader.js","sourceRoot":"","sources":["../../src/config/loader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAClC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,IAAI,MAAM,SAAS,CAAC;AAC3B,OAAO,EACL,uBAAuB,GAExB,MAAM,aAAa,CAAC;AAOrB,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,UAAkB,EAAE,UAA6B,EAAE;IAClF,MAAM,aAAa,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,aAAa,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;IAC3E,KAAK,aAAa,CAAC;IACnB,MAAM,kBAAkB,GAAG,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;IACpD,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAC;IAEnD,IAAI,CAAC,kBAAkB,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,kBAAkB,CAAC,QAAQ,CAAC,MAAM,CAAC,E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