@dsai-io/tools 0.0.1 → 1.0.7

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 (40) hide show
  1. package/README.md +282 -30
  2. package/dist/cli/index.cjs +6271 -2233
  3. package/dist/cli/index.cjs.map +1 -1
  4. package/dist/cli/index.d.cts +4 -0
  5. package/dist/cli/index.d.ts +4 -0
  6. package/dist/cli/index.js +6232 -2195
  7. package/dist/cli/index.js.map +1 -1
  8. package/dist/config/index.cjs +198 -61
  9. package/dist/config/index.cjs.map +1 -1
  10. package/dist/config/index.d.cts +490 -1759
  11. package/dist/config/index.d.ts +490 -1759
  12. package/dist/config/index.js +197 -61
  13. package/dist/config/index.js.map +1 -1
  14. package/dist/icons/index.cjs +1 -1
  15. package/dist/icons/index.cjs.map +1 -1
  16. package/dist/icons/index.d.cts +1 -1
  17. package/dist/icons/index.d.ts +1 -1
  18. package/dist/icons/index.js +1 -1
  19. package/dist/icons/index.js.map +1 -1
  20. package/dist/index.cjs +6733 -2888
  21. package/dist/index.cjs.map +1 -1
  22. package/dist/index.d.cts +3 -3
  23. package/dist/index.d.ts +3 -3
  24. package/dist/index.js +6774 -2963
  25. package/dist/index.js.map +1 -1
  26. package/dist/tokens/index.cjs +4457 -737
  27. package/dist/tokens/index.cjs.map +1 -1
  28. package/dist/tokens/index.d.cts +1258 -17
  29. package/dist/tokens/index.d.ts +1258 -17
  30. package/dist/tokens/index.js +4368 -683
  31. package/dist/tokens/index.js.map +1 -1
  32. package/dist/{types-Idj08nad.d.cts → types-DabOzcsj.d.cts} +236 -3
  33. package/dist/{types-Idj08nad.d.ts → types-DabOzcsj.d.ts} +236 -3
  34. package/dist/utils/circuit-breaker.cjs +173 -0
  35. package/dist/utils/circuit-breaker.cjs.map +1 -0
  36. package/dist/utils/circuit-breaker.d.cts +123 -0
  37. package/dist/utils/circuit-breaker.d.ts +123 -0
  38. package/dist/utils/circuit-breaker.js +169 -0
  39. package/dist/utils/circuit-breaker.js.map +1 -0
  40. package/package.json +10 -5
@@ -42,37 +42,50 @@ var customTransformSchema = zod.z.object({
42
42
  name: zod.z.string().min(1, "Transform name is required"),
43
43
  description: zod.z.string().optional(),
44
44
  type: zod.z.enum(["value", "attribute", "name"]).optional().default("value"),
45
- transform: zod.z.function().args(zod.z.any(), zod.z.any()).returns(zod.z.any()).optional(),
46
- filter: zod.z.function().args(zod.z.any()).returns(zod.z.boolean()).optional(),
47
- matcher: zod.z.function().args(zod.z.any()).returns(zod.z.boolean()).optional()
45
+ transform: zod.z.function().optional(),
46
+ filter: zod.z.function().optional(),
47
+ matcher: zod.z.function().optional()
48
48
  });
49
49
  var customFormatSchema = zod.z.object({
50
50
  name: zod.z.string().min(1, "Format name is required"),
51
51
  description: zod.z.string().optional(),
52
- formatter: zod.z.function().args(zod.z.any()).returns(zod.z.string()).optional(),
52
+ formatter: zod.z.function().optional(),
53
53
  extension: zod.z.string().min(1).optional()
54
54
  });
55
- var themeModeSchema = zod.z.object({
55
+ var outputFormatEnum = zod.z.enum(["css", "scss", "js", "ts", "json", "android", "ios"]);
56
+ var themeDefinitionSchema = zod.z.object({
57
+ isDefault: zod.z.boolean().optional().default(false),
58
+ suffix: zod.z.string().nullable().optional(),
56
59
  selector: zod.z.string().min(1, "Theme selector is required"),
57
60
  mediaQuery: zod.z.string().optional(),
58
61
  dataAttribute: zod.z.string().optional(),
59
- cssVariables: zod.z.boolean().optional().default(true),
60
- generateSeparateFiles: zod.z.boolean().optional().default(false),
61
- prefix: zod.z.string().optional()
62
+ outputFiles: zod.z.record(outputFormatEnum, zod.z.string()).optional()
63
+ });
64
+ var themeSelectorPatternSchema = zod.z.object({
65
+ default: zod.z.string().optional().default(":root"),
66
+ others: zod.z.string().optional().default('[data-dsai-theme="{mode}"]')
62
67
  });
63
68
  var themesConfigSchema = zod.z.object({
64
69
  enabled: zod.z.boolean().optional().default(true),
65
- defaultMode: zod.z.enum(["light", "dark", "system"]).optional().default("light"),
66
- modes: zod.z.record(zod.z.string(), themeModeSchema).optional().default({
67
- light: { selector: ":root", cssVariables: true, generateSeparateFiles: false },
68
- dark: {
69
- selector: '[data-theme="dark"]',
70
- mediaQuery: "(prefers-color-scheme: dark)",
71
- cssVariables: true,
72
- generateSeparateFiles: false
73
- }
74
- }),
75
- outputFileName: zod.z.string().optional().default("themes"),
70
+ autoDetect: zod.z.boolean().optional().default(true),
71
+ default: zod.z.string().optional().default("light"),
72
+ ignoreModes: zod.z.array(zod.z.string()).optional().default([]),
73
+ selectorPattern: themeSelectorPatternSchema.optional(),
74
+ definitions: zod.z.record(zod.z.string(), themeDefinitionSchema).optional(),
75
+ // Legacy fields (for backward compatibility)
76
+ defaultMode: zod.z.enum(["light", "dark", "system"]).optional(),
77
+ modes: zod.z.record(
78
+ zod.z.string(),
79
+ zod.z.object({
80
+ selector: zod.z.string().min(1),
81
+ mediaQuery: zod.z.string().optional(),
82
+ dataAttribute: zod.z.string().optional(),
83
+ cssVariables: zod.z.boolean().optional(),
84
+ generateSeparateFiles: zod.z.boolean().optional(),
85
+ prefix: zod.z.string().optional()
86
+ })
87
+ ).optional(),
88
+ outputFileName: zod.z.string().optional(),
76
89
  colorScheme: zod.z.object({
77
90
  light: zod.z.string().optional(),
78
91
  dark: zod.z.string().optional()
@@ -115,10 +128,44 @@ var tokenBuildConfigSchema = zod.z.object({
115
128
  selector: zod.z.string().optional(),
116
129
  transforms: zod.z.array(zod.z.string()).optional(),
117
130
  customTransforms: zod.z.array(customTransformSchema).optional(),
118
- filter: zod.z.function().args(zod.z.any()).returns(zod.z.union([zod.z.boolean(), zod.z.promise(zod.z.boolean())])).optional(),
131
+ filter: zod.z.function().optional(),
119
132
  header: zod.z.string().optional(),
120
133
  footer: zod.z.string().optional()
121
134
  });
135
+ var postprocessConfigSchema = zod.z.object({
136
+ enabled: zod.z.boolean().optional(),
137
+ cssDir: zod.z.string().optional(),
138
+ files: zod.z.array(zod.z.string()).optional(),
139
+ replacements: zod.z.array(
140
+ zod.z.object({
141
+ description: zod.z.string().optional(),
142
+ from: zod.z.union([zod.z.string(), zod.z.instanceof(RegExp)]),
143
+ to: zod.z.string()
144
+ })
145
+ ).optional()
146
+ });
147
+ var scssConfigSchema = zod.z.object({
148
+ /** Output styles to generate: 'expanded' (readable) or 'compressed' (minified) */
149
+ outputStyles: zod.z.array(zod.z.enum(["expanded", "compressed"])).optional(),
150
+ /** Generate source maps for SCSS compilation */
151
+ generateSourceMaps: zod.z.boolean().optional(),
152
+ /** Suffix for minified files (e.g., '.min') */
153
+ minifiedSuffix: zod.z.string().optional(),
154
+ /** Theme entry point SCSS file */
155
+ themeEntry: zod.z.string().optional(),
156
+ /** Utilities entry point SCSS file */
157
+ utilitiesEntry: zod.z.string().optional(),
158
+ /** Output directory for compiled CSS files */
159
+ cssOutputDir: zod.z.string().optional(),
160
+ /** Additional Sass load paths */
161
+ loadPaths: zod.z.array(zod.z.string()).optional(),
162
+ /** Target CSS framework for variable name mapping */
163
+ framework: zod.z.enum(["bootstrap", "tailwind", "material", "custom"]).optional(),
164
+ /** Custom token to variable name mappings */
165
+ nameMapping: zod.z.record(zod.z.string(), zod.z.string()).optional(),
166
+ /** Output path for Bootstrap-compatible SCSS variables */
167
+ variablesOutput: zod.z.string().optional()
168
+ });
122
169
  var tokenCacheConfigSchema = zod.z.object({
123
170
  enabled: zod.z.boolean().optional().default(true),
124
171
  directory: zod.z.string().optional().default(".cache"),
@@ -132,14 +179,16 @@ var tokenWatchConfigSchema = zod.z.object({
132
179
  ignorePatterns: zod.z.array(zod.z.string()).optional().default([])
133
180
  });
134
181
  var tokensHooksSchema = zod.z.object({
135
- onBuildStart: zod.z.function().args(zod.z.any()).returns(zod.z.union([zod.z.void(), zod.z.promise(zod.z.void())])).optional(),
136
- onFormatComplete: zod.z.function().args(zod.z.any()).returns(zod.z.union([zod.z.void(), zod.z.promise(zod.z.void())])).optional(),
137
- onAllFormatsComplete: zod.z.function().args(zod.z.any()).returns(zod.z.union([zod.z.void(), zod.z.promise(zod.z.void())])).optional(),
138
- onBuildComplete: zod.z.function().args(zod.z.any()).returns(zod.z.union([zod.z.void(), zod.z.promise(zod.z.void())])).optional(),
139
- onError: zod.z.function().args(zod.z.any()).returns(zod.z.union([zod.z.void(), zod.z.promise(zod.z.void())])).optional()
182
+ onBuildStart: zod.z.function().optional(),
183
+ onFormatComplete: zod.z.function().optional(),
184
+ onAllFormatsComplete: zod.z.function().optional(),
185
+ onBuildComplete: zod.z.function().optional(),
186
+ onError: zod.z.function().optional()
140
187
  });
141
188
  var buildPipelineStepSchema = zod.z.enum([
142
189
  "validate",
190
+ "snapshot",
191
+ "preprocess",
143
192
  "transform",
144
193
  "style-dictionary",
145
194
  "sync",
@@ -157,41 +206,30 @@ var tokensBuildPipelineSchema = zod.z.object({
157
206
  * Default includes all steps for full @dsai-io/tokens build.
158
207
  * Simpler packages can use subset like ['validate', 'transform', 'style-dictionary']
159
208
  */
160
- steps: zod.z.array(buildPipelineStepSchema).optional().default([
161
- "validate",
162
- "transform",
163
- "style-dictionary",
164
- "sync",
165
- "sass-theme",
166
- "sass-theme-minified",
167
- "postprocess",
168
- "sass-utilities",
169
- "sass-utilities-minified",
170
- "bundle"
171
- ]),
209
+ steps: zod.z.array(buildPipelineStepSchema).optional(),
172
210
  /**
173
211
  * Paths configuration for build steps
174
212
  */
175
213
  paths: zod.z.object({
176
214
  /** Source file for sync step (Style Dictionary JS output) */
177
- syncSource: zod.z.string().optional().default("dist/js/tokens.js"),
215
+ syncSource: zod.z.string().optional(),
178
216
  /** Target file for sync step */
179
- syncTarget: zod.z.string().optional().default("src/tokens-flat.ts"),
217
+ syncTarget: zod.z.string().optional(),
180
218
  /** SCSS theme input file */
181
- sassThemeInput: zod.z.string().optional().default("src/scss/dsai-theme-bs.scss"),
219
+ sassThemeInput: zod.z.string().optional(),
182
220
  /** CSS theme output file */
183
- sassThemeOutput: zod.z.string().optional().default("dist/css/dsai-theme-bs.css"),
221
+ sassThemeOutput: zod.z.string().optional(),
184
222
  /** CSS theme minified output file */
185
- sassThemeMinifiedOutput: zod.z.string().optional().default("dist/css/dsai-theme-bs.min.css"),
223
+ sassThemeMinifiedOutput: zod.z.string().optional(),
186
224
  /** SCSS utilities input file */
187
- sassUtilitiesInput: zod.z.string().optional().default("src/scss/dsai-utilities.scss"),
225
+ sassUtilitiesInput: zod.z.string().optional(),
188
226
  /** CSS utilities output file */
189
- sassUtilitiesOutput: zod.z.string().optional().default("dist/css/dsai.css"),
227
+ sassUtilitiesOutput: zod.z.string().optional(),
190
228
  /** CSS utilities minified output file */
191
- sassUtilitiesMinifiedOutput: zod.z.string().optional().default("dist/css/dsai.min.css")
229
+ sassUtilitiesMinifiedOutput: zod.z.string().optional()
192
230
  }).optional(),
193
231
  /** Style Dictionary config file name */
194
- styleDictionaryConfig: zod.z.string().optional().default("sd.config.mjs")
232
+ styleDictionaryConfig: zod.z.string().optional()
195
233
  });
196
234
  var tokensConfigSchema = zod.z.object({
197
235
  enabled: zod.z.boolean().optional().default(true),
@@ -224,8 +262,12 @@ var tokensConfigSchema = zod.z.object({
224
262
  cache: tokenCacheConfigSchema.optional(),
225
263
  watch: tokenWatchConfigSchema.optional(),
226
264
  verbose: zod.z.boolean().optional().default(false),
265
+ /** SCSS/CSS output configuration */
266
+ scss: scssConfigSchema.optional(),
227
267
  /** Build pipeline configuration */
228
- pipeline: tokensBuildPipelineSchema.optional()
268
+ pipeline: tokensBuildPipelineSchema.optional(),
269
+ /** Postprocess configuration */
270
+ postprocess: postprocessConfigSchema.optional()
229
271
  });
230
272
  var buildConfigSchema = zod.z.object({
231
273
  outDir: zod.z.string().optional().default("dist"),
@@ -254,7 +296,7 @@ var dsaiConfigSchema = zod.z.object({
254
296
  icons: iconsConfigSchema.optional()
255
297
  });
256
298
  function formatValidationErrors(zodError) {
257
- return zodError.errors.map((err) => ({
299
+ return zodError.issues.map((err) => ({
258
300
  path: err.path.join(".") || "root",
259
301
  message: err.message,
260
302
  code: err.code,
@@ -353,11 +395,44 @@ var defaultSelectorPattern = {
353
395
  default: ":root",
354
396
  others: '[data-dsai-theme="{mode}"]'
355
397
  };
398
+ var defaultThemeDefinitions = {
399
+ light: {
400
+ isDefault: true,
401
+ suffix: null,
402
+ selector: ":root",
403
+ outputFiles: {
404
+ css: "tokens.css",
405
+ scss: "_tokens.scss",
406
+ js: "tokens.js",
407
+ ts: "tokens.ts",
408
+ json: "tokens.json",
409
+ android: "tokens.xml",
410
+ ios: "tokens.h"
411
+ }
412
+ },
413
+ dark: {
414
+ isDefault: false,
415
+ suffix: "-dark",
416
+ selector: '[data-dsai-theme="dark"]',
417
+ mediaQuery: "(prefers-color-scheme: dark)",
418
+ outputFiles: {
419
+ css: "tokens-dark.css",
420
+ scss: "_tokens-dark.scss",
421
+ js: "tokens-dark.js",
422
+ ts: "tokens-dark.ts",
423
+ json: "tokens-dark.json",
424
+ android: "tokens-dark.xml",
425
+ ios: "tokens-dark.h"
426
+ }
427
+ }
428
+ };
356
429
  var defaultThemesConfig = {
430
+ enabled: true,
357
431
  autoDetect: true,
358
- default: "Light",
432
+ default: "light",
359
433
  ignoreModes: [],
360
- selectorPattern: defaultSelectorPattern
434
+ selectorPattern: defaultSelectorPattern,
435
+ definitions: defaultThemeDefinitions
361
436
  };
362
437
  var defaultIconFramework = "react";
363
438
  var defaultIconsConfig = {
@@ -524,16 +599,75 @@ function resolveGlobalConfig(config, options) {
524
599
  logLevel: config?.logLevel ?? base.logLevel
525
600
  };
526
601
  }
602
+ function resolveThemeDefinition(themeName, definition, selectorPattern, _outputFileNames, isDefaultTheme) {
603
+ const generateOutputFiles = () => {
604
+ const suffix = isDefaultTheme ? "" : `-${themeName}`;
605
+ return {
606
+ css: `tokens${suffix}.css`,
607
+ scss: `_tokens${suffix}.scss`,
608
+ js: `tokens${suffix}.js`,
609
+ ts: `tokens${suffix}.ts`,
610
+ json: `tokens${suffix}.json`,
611
+ android: `tokens${suffix}.xml`,
612
+ ios: `tokens${suffix}.h`
613
+ };
614
+ };
615
+ const generateSelector = () => {
616
+ if (isDefaultTheme) {
617
+ return selectorPattern.default;
618
+ }
619
+ return selectorPattern.others.replace("{mode}", themeName);
620
+ };
621
+ const defaultOutputFiles = generateOutputFiles();
622
+ return {
623
+ isDefault: definition?.isDefault ?? isDefaultTheme,
624
+ suffix: definition?.suffix ?? (isDefaultTheme ? null : `-${themeName}`),
625
+ selector: definition?.selector ?? generateSelector(),
626
+ mediaQuery: definition?.mediaQuery,
627
+ dataAttribute: definition?.dataAttribute,
628
+ outputFiles: {
629
+ ...defaultOutputFiles,
630
+ ...definition?.outputFiles
631
+ }
632
+ };
633
+ }
527
634
  function resolveThemesConfig(config) {
528
635
  const base = defaultThemesConfig;
636
+ const selectorPattern = {
637
+ default: config?.selectorPattern?.default ?? base.selectorPattern.default,
638
+ others: config?.selectorPattern?.others ?? base.selectorPattern.others
639
+ };
640
+ const defaultThemeName = config?.default?.toLowerCase() ?? base.default;
641
+ let definitions;
642
+ if (config?.definitions && Object.keys(config.definitions).length > 0) {
643
+ definitions = {};
644
+ for (const [themeName, definition] of Object.entries(config.definitions)) {
645
+ const normalizedName = themeName.toLowerCase();
646
+ const isDefaultTheme = definition.isDefault ?? normalizedName === defaultThemeName;
647
+ const resolvedDef = resolveThemeDefinition(
648
+ normalizedName,
649
+ definition,
650
+ selectorPattern,
651
+ defaultOutputFileNames,
652
+ isDefaultTheme
653
+ );
654
+ Object.defineProperty(definitions, normalizedName, {
655
+ value: resolvedDef,
656
+ writable: true,
657
+ enumerable: true,
658
+ configurable: true
659
+ });
660
+ }
661
+ } else {
662
+ definitions = { ...defaultThemeDefinitions };
663
+ }
529
664
  return {
665
+ enabled: config?.enabled ?? base.enabled,
530
666
  autoDetect: config?.autoDetect ?? base.autoDetect,
531
- default: config?.default ?? base.default,
667
+ default: defaultThemeName,
532
668
  ignoreModes: config?.ignoreModes ?? [...base.ignoreModes],
533
- selectorPattern: {
534
- default: config?.selectorPattern?.default ?? base.selectorPattern.default,
535
- others: config?.selectorPattern?.others ?? base.selectorPattern.others
536
- }
669
+ selectorPattern,
670
+ definitions
537
671
  };
538
672
  }
539
673
  function resolveIconsConfig(config, options) {
@@ -601,7 +735,9 @@ function resolveTokensConfig(config, options) {
601
735
  separateThemeFiles: config?.separateThemeFiles ?? base.separateThemeFiles,
602
736
  watch: config?.watch ?? base.watch,
603
737
  watchDirectories,
604
- pipeline: config?.pipeline
738
+ pipeline: config?.pipeline,
739
+ scss: config?.scss,
740
+ postprocess: config?.postprocess
605
741
  };
606
742
  }
607
743
  function applyOverrides(config, overrides) {
@@ -816,7 +952,7 @@ function setNestedValue(obj, path3, value) {
816
952
  configurable: true
817
953
  });
818
954
  }
819
- const nested = obj[first];
955
+ const nested = Reflect.get(obj, first);
820
956
  Object.defineProperty(nested, second, {
821
957
  value,
822
958
  writable: true,
@@ -837,7 +973,7 @@ function setNestedValue(obj, path3, value) {
837
973
  configurable: true
838
974
  });
839
975
  }
840
- const nested1 = obj[first];
976
+ const nested1 = Reflect.get(obj, first);
841
977
  if (!(second in nested1)) {
842
978
  Object.defineProperty(nested1, second, {
843
979
  value: {},
@@ -846,7 +982,7 @@ function setNestedValue(obj, path3, value) {
846
982
  configurable: true
847
983
  });
848
984
  }
849
- const nested2 = nested1[second];
985
+ const nested2 = Reflect.get(nested1, second);
850
986
  Object.defineProperty(nested2, third, {
851
987
  value,
852
988
  writable: true,
@@ -864,7 +1000,7 @@ function getConfigFromEnv(options = {}) {
864
1000
  if (!envKey.startsWith(prefix)) {
865
1001
  continue;
866
1002
  }
867
- const envValue = env[envKey];
1003
+ const envValue = Reflect.get(env, envKey);
868
1004
  if (envValue === void 0) {
869
1005
  continue;
870
1006
  }
@@ -1100,7 +1236,8 @@ exports.outputFormatSchema = outputFormatSchema;
1100
1236
  exports.resolveConfig = resolveConfig;
1101
1237
  exports.searchConfigFile = searchConfigFile;
1102
1238
  exports.shouldDisableColors = shouldDisableColors;
1103
- exports.themeModeSchema = themeModeSchema;
1239
+ exports.themeDefinitionSchema = themeDefinitionSchema;
1240
+ exports.themeSelectorPatternSchema = themeSelectorPatternSchema;
1104
1241
  exports.themesConfigSchema = themesConfigSchema;
1105
1242
  exports.tokenBuildConfigSchema = tokenBuildConfigSchema;
1106
1243
  exports.tokenCacheConfigSchema = tokenCacheConfigSchema;