@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
@@ -36,37 +36,50 @@ var customTransformSchema = z.object({
36
36
  name: z.string().min(1, "Transform name is required"),
37
37
  description: z.string().optional(),
38
38
  type: z.enum(["value", "attribute", "name"]).optional().default("value"),
39
- transform: z.function().args(z.any(), z.any()).returns(z.any()).optional(),
40
- filter: z.function().args(z.any()).returns(z.boolean()).optional(),
41
- matcher: z.function().args(z.any()).returns(z.boolean()).optional()
39
+ transform: z.function().optional(),
40
+ filter: z.function().optional(),
41
+ matcher: z.function().optional()
42
42
  });
43
43
  var customFormatSchema = z.object({
44
44
  name: z.string().min(1, "Format name is required"),
45
45
  description: z.string().optional(),
46
- formatter: z.function().args(z.any()).returns(z.string()).optional(),
46
+ formatter: z.function().optional(),
47
47
  extension: z.string().min(1).optional()
48
48
  });
49
- var themeModeSchema = z.object({
49
+ var outputFormatEnum = z.enum(["css", "scss", "js", "ts", "json", "android", "ios"]);
50
+ var themeDefinitionSchema = z.object({
51
+ isDefault: z.boolean().optional().default(false),
52
+ suffix: z.string().nullable().optional(),
50
53
  selector: z.string().min(1, "Theme selector is required"),
51
54
  mediaQuery: z.string().optional(),
52
55
  dataAttribute: z.string().optional(),
53
- cssVariables: z.boolean().optional().default(true),
54
- generateSeparateFiles: z.boolean().optional().default(false),
55
- prefix: z.string().optional()
56
+ outputFiles: z.record(outputFormatEnum, z.string()).optional()
57
+ });
58
+ var themeSelectorPatternSchema = z.object({
59
+ default: z.string().optional().default(":root"),
60
+ others: z.string().optional().default('[data-dsai-theme="{mode}"]')
56
61
  });
57
62
  var themesConfigSchema = z.object({
58
63
  enabled: z.boolean().optional().default(true),
59
- defaultMode: z.enum(["light", "dark", "system"]).optional().default("light"),
60
- modes: z.record(z.string(), themeModeSchema).optional().default({
61
- light: { selector: ":root", cssVariables: true, generateSeparateFiles: false },
62
- dark: {
63
- selector: '[data-theme="dark"]',
64
- mediaQuery: "(prefers-color-scheme: dark)",
65
- cssVariables: true,
66
- generateSeparateFiles: false
67
- }
68
- }),
69
- outputFileName: z.string().optional().default("themes"),
64
+ autoDetect: z.boolean().optional().default(true),
65
+ default: z.string().optional().default("light"),
66
+ ignoreModes: z.array(z.string()).optional().default([]),
67
+ selectorPattern: themeSelectorPatternSchema.optional(),
68
+ definitions: z.record(z.string(), themeDefinitionSchema).optional(),
69
+ // Legacy fields (for backward compatibility)
70
+ defaultMode: z.enum(["light", "dark", "system"]).optional(),
71
+ modes: z.record(
72
+ z.string(),
73
+ z.object({
74
+ selector: z.string().min(1),
75
+ mediaQuery: z.string().optional(),
76
+ dataAttribute: z.string().optional(),
77
+ cssVariables: z.boolean().optional(),
78
+ generateSeparateFiles: z.boolean().optional(),
79
+ prefix: z.string().optional()
80
+ })
81
+ ).optional(),
82
+ outputFileName: z.string().optional(),
70
83
  colorScheme: z.object({
71
84
  light: z.string().optional(),
72
85
  dark: z.string().optional()
@@ -109,10 +122,44 @@ var tokenBuildConfigSchema = z.object({
109
122
  selector: z.string().optional(),
110
123
  transforms: z.array(z.string()).optional(),
111
124
  customTransforms: z.array(customTransformSchema).optional(),
112
- filter: z.function().args(z.any()).returns(z.union([z.boolean(), z.promise(z.boolean())])).optional(),
125
+ filter: z.function().optional(),
113
126
  header: z.string().optional(),
114
127
  footer: z.string().optional()
115
128
  });
129
+ var postprocessConfigSchema = z.object({
130
+ enabled: z.boolean().optional(),
131
+ cssDir: z.string().optional(),
132
+ files: z.array(z.string()).optional(),
133
+ replacements: z.array(
134
+ z.object({
135
+ description: z.string().optional(),
136
+ from: z.union([z.string(), z.instanceof(RegExp)]),
137
+ to: z.string()
138
+ })
139
+ ).optional()
140
+ });
141
+ var scssConfigSchema = z.object({
142
+ /** Output styles to generate: 'expanded' (readable) or 'compressed' (minified) */
143
+ outputStyles: z.array(z.enum(["expanded", "compressed"])).optional(),
144
+ /** Generate source maps for SCSS compilation */
145
+ generateSourceMaps: z.boolean().optional(),
146
+ /** Suffix for minified files (e.g., '.min') */
147
+ minifiedSuffix: z.string().optional(),
148
+ /** Theme entry point SCSS file */
149
+ themeEntry: z.string().optional(),
150
+ /** Utilities entry point SCSS file */
151
+ utilitiesEntry: z.string().optional(),
152
+ /** Output directory for compiled CSS files */
153
+ cssOutputDir: z.string().optional(),
154
+ /** Additional Sass load paths */
155
+ loadPaths: z.array(z.string()).optional(),
156
+ /** Target CSS framework for variable name mapping */
157
+ framework: z.enum(["bootstrap", "tailwind", "material", "custom"]).optional(),
158
+ /** Custom token to variable name mappings */
159
+ nameMapping: z.record(z.string(), z.string()).optional(),
160
+ /** Output path for Bootstrap-compatible SCSS variables */
161
+ variablesOutput: z.string().optional()
162
+ });
116
163
  var tokenCacheConfigSchema = z.object({
117
164
  enabled: z.boolean().optional().default(true),
118
165
  directory: z.string().optional().default(".cache"),
@@ -126,14 +173,16 @@ var tokenWatchConfigSchema = z.object({
126
173
  ignorePatterns: z.array(z.string()).optional().default([])
127
174
  });
128
175
  var tokensHooksSchema = z.object({
129
- onBuildStart: z.function().args(z.any()).returns(z.union([z.void(), z.promise(z.void())])).optional(),
130
- onFormatComplete: z.function().args(z.any()).returns(z.union([z.void(), z.promise(z.void())])).optional(),
131
- onAllFormatsComplete: z.function().args(z.any()).returns(z.union([z.void(), z.promise(z.void())])).optional(),
132
- onBuildComplete: z.function().args(z.any()).returns(z.union([z.void(), z.promise(z.void())])).optional(),
133
- onError: z.function().args(z.any()).returns(z.union([z.void(), z.promise(z.void())])).optional()
176
+ onBuildStart: z.function().optional(),
177
+ onFormatComplete: z.function().optional(),
178
+ onAllFormatsComplete: z.function().optional(),
179
+ onBuildComplete: z.function().optional(),
180
+ onError: z.function().optional()
134
181
  });
135
182
  var buildPipelineStepSchema = z.enum([
136
183
  "validate",
184
+ "snapshot",
185
+ "preprocess",
137
186
  "transform",
138
187
  "style-dictionary",
139
188
  "sync",
@@ -151,41 +200,30 @@ var tokensBuildPipelineSchema = z.object({
151
200
  * Default includes all steps for full @dsai-io/tokens build.
152
201
  * Simpler packages can use subset like ['validate', 'transform', 'style-dictionary']
153
202
  */
154
- steps: z.array(buildPipelineStepSchema).optional().default([
155
- "validate",
156
- "transform",
157
- "style-dictionary",
158
- "sync",
159
- "sass-theme",
160
- "sass-theme-minified",
161
- "postprocess",
162
- "sass-utilities",
163
- "sass-utilities-minified",
164
- "bundle"
165
- ]),
203
+ steps: z.array(buildPipelineStepSchema).optional(),
166
204
  /**
167
205
  * Paths configuration for build steps
168
206
  */
169
207
  paths: z.object({
170
208
  /** Source file for sync step (Style Dictionary JS output) */
171
- syncSource: z.string().optional().default("dist/js/tokens.js"),
209
+ syncSource: z.string().optional(),
172
210
  /** Target file for sync step */
173
- syncTarget: z.string().optional().default("src/tokens-flat.ts"),
211
+ syncTarget: z.string().optional(),
174
212
  /** SCSS theme input file */
175
- sassThemeInput: z.string().optional().default("src/scss/dsai-theme-bs.scss"),
213
+ sassThemeInput: z.string().optional(),
176
214
  /** CSS theme output file */
177
- sassThemeOutput: z.string().optional().default("dist/css/dsai-theme-bs.css"),
215
+ sassThemeOutput: z.string().optional(),
178
216
  /** CSS theme minified output file */
179
- sassThemeMinifiedOutput: z.string().optional().default("dist/css/dsai-theme-bs.min.css"),
217
+ sassThemeMinifiedOutput: z.string().optional(),
180
218
  /** SCSS utilities input file */
181
- sassUtilitiesInput: z.string().optional().default("src/scss/dsai-utilities.scss"),
219
+ sassUtilitiesInput: z.string().optional(),
182
220
  /** CSS utilities output file */
183
- sassUtilitiesOutput: z.string().optional().default("dist/css/dsai.css"),
221
+ sassUtilitiesOutput: z.string().optional(),
184
222
  /** CSS utilities minified output file */
185
- sassUtilitiesMinifiedOutput: z.string().optional().default("dist/css/dsai.min.css")
223
+ sassUtilitiesMinifiedOutput: z.string().optional()
186
224
  }).optional(),
187
225
  /** Style Dictionary config file name */
188
- styleDictionaryConfig: z.string().optional().default("sd.config.mjs")
226
+ styleDictionaryConfig: z.string().optional()
189
227
  });
190
228
  var tokensConfigSchema = z.object({
191
229
  enabled: z.boolean().optional().default(true),
@@ -218,8 +256,12 @@ var tokensConfigSchema = z.object({
218
256
  cache: tokenCacheConfigSchema.optional(),
219
257
  watch: tokenWatchConfigSchema.optional(),
220
258
  verbose: z.boolean().optional().default(false),
259
+ /** SCSS/CSS output configuration */
260
+ scss: scssConfigSchema.optional(),
221
261
  /** Build pipeline configuration */
222
- pipeline: tokensBuildPipelineSchema.optional()
262
+ pipeline: tokensBuildPipelineSchema.optional(),
263
+ /** Postprocess configuration */
264
+ postprocess: postprocessConfigSchema.optional()
223
265
  });
224
266
  var buildConfigSchema = z.object({
225
267
  outDir: z.string().optional().default("dist"),
@@ -248,7 +290,7 @@ var dsaiConfigSchema = z.object({
248
290
  icons: iconsConfigSchema.optional()
249
291
  });
250
292
  function formatValidationErrors(zodError) {
251
- return zodError.errors.map((err) => ({
293
+ return zodError.issues.map((err) => ({
252
294
  path: err.path.join(".") || "root",
253
295
  message: err.message,
254
296
  code: err.code,
@@ -347,11 +389,44 @@ var defaultSelectorPattern = {
347
389
  default: ":root",
348
390
  others: '[data-dsai-theme="{mode}"]'
349
391
  };
392
+ var defaultThemeDefinitions = {
393
+ light: {
394
+ isDefault: true,
395
+ suffix: null,
396
+ selector: ":root",
397
+ outputFiles: {
398
+ css: "tokens.css",
399
+ scss: "_tokens.scss",
400
+ js: "tokens.js",
401
+ ts: "tokens.ts",
402
+ json: "tokens.json",
403
+ android: "tokens.xml",
404
+ ios: "tokens.h"
405
+ }
406
+ },
407
+ dark: {
408
+ isDefault: false,
409
+ suffix: "-dark",
410
+ selector: '[data-dsai-theme="dark"]',
411
+ mediaQuery: "(prefers-color-scheme: dark)",
412
+ outputFiles: {
413
+ css: "tokens-dark.css",
414
+ scss: "_tokens-dark.scss",
415
+ js: "tokens-dark.js",
416
+ ts: "tokens-dark.ts",
417
+ json: "tokens-dark.json",
418
+ android: "tokens-dark.xml",
419
+ ios: "tokens-dark.h"
420
+ }
421
+ }
422
+ };
350
423
  var defaultThemesConfig = {
424
+ enabled: true,
351
425
  autoDetect: true,
352
- default: "Light",
426
+ default: "light",
353
427
  ignoreModes: [],
354
- selectorPattern: defaultSelectorPattern
428
+ selectorPattern: defaultSelectorPattern,
429
+ definitions: defaultThemeDefinitions
355
430
  };
356
431
  var defaultIconFramework = "react";
357
432
  var defaultIconsConfig = {
@@ -518,16 +593,75 @@ function resolveGlobalConfig(config, options) {
518
593
  logLevel: config?.logLevel ?? base.logLevel
519
594
  };
520
595
  }
596
+ function resolveThemeDefinition(themeName, definition, selectorPattern, _outputFileNames, isDefaultTheme) {
597
+ const generateOutputFiles = () => {
598
+ const suffix = isDefaultTheme ? "" : `-${themeName}`;
599
+ return {
600
+ css: `tokens${suffix}.css`,
601
+ scss: `_tokens${suffix}.scss`,
602
+ js: `tokens${suffix}.js`,
603
+ ts: `tokens${suffix}.ts`,
604
+ json: `tokens${suffix}.json`,
605
+ android: `tokens${suffix}.xml`,
606
+ ios: `tokens${suffix}.h`
607
+ };
608
+ };
609
+ const generateSelector = () => {
610
+ if (isDefaultTheme) {
611
+ return selectorPattern.default;
612
+ }
613
+ return selectorPattern.others.replace("{mode}", themeName);
614
+ };
615
+ const defaultOutputFiles = generateOutputFiles();
616
+ return {
617
+ isDefault: definition?.isDefault ?? isDefaultTheme,
618
+ suffix: definition?.suffix ?? (isDefaultTheme ? null : `-${themeName}`),
619
+ selector: definition?.selector ?? generateSelector(),
620
+ mediaQuery: definition?.mediaQuery,
621
+ dataAttribute: definition?.dataAttribute,
622
+ outputFiles: {
623
+ ...defaultOutputFiles,
624
+ ...definition?.outputFiles
625
+ }
626
+ };
627
+ }
521
628
  function resolveThemesConfig(config) {
522
629
  const base = defaultThemesConfig;
630
+ const selectorPattern = {
631
+ default: config?.selectorPattern?.default ?? base.selectorPattern.default,
632
+ others: config?.selectorPattern?.others ?? base.selectorPattern.others
633
+ };
634
+ const defaultThemeName = config?.default?.toLowerCase() ?? base.default;
635
+ let definitions;
636
+ if (config?.definitions && Object.keys(config.definitions).length > 0) {
637
+ definitions = {};
638
+ for (const [themeName, definition] of Object.entries(config.definitions)) {
639
+ const normalizedName = themeName.toLowerCase();
640
+ const isDefaultTheme = definition.isDefault ?? normalizedName === defaultThemeName;
641
+ const resolvedDef = resolveThemeDefinition(
642
+ normalizedName,
643
+ definition,
644
+ selectorPattern,
645
+ defaultOutputFileNames,
646
+ isDefaultTheme
647
+ );
648
+ Object.defineProperty(definitions, normalizedName, {
649
+ value: resolvedDef,
650
+ writable: true,
651
+ enumerable: true,
652
+ configurable: true
653
+ });
654
+ }
655
+ } else {
656
+ definitions = { ...defaultThemeDefinitions };
657
+ }
523
658
  return {
659
+ enabled: config?.enabled ?? base.enabled,
524
660
  autoDetect: config?.autoDetect ?? base.autoDetect,
525
- default: config?.default ?? base.default,
661
+ default: defaultThemeName,
526
662
  ignoreModes: config?.ignoreModes ?? [...base.ignoreModes],
527
- selectorPattern: {
528
- default: config?.selectorPattern?.default ?? base.selectorPattern.default,
529
- others: config?.selectorPattern?.others ?? base.selectorPattern.others
530
- }
663
+ selectorPattern,
664
+ definitions
531
665
  };
532
666
  }
533
667
  function resolveIconsConfig(config, options) {
@@ -595,7 +729,9 @@ function resolveTokensConfig(config, options) {
595
729
  separateThemeFiles: config?.separateThemeFiles ?? base.separateThemeFiles,
596
730
  watch: config?.watch ?? base.watch,
597
731
  watchDirectories,
598
- pipeline: config?.pipeline
732
+ pipeline: config?.pipeline,
733
+ scss: config?.scss,
734
+ postprocess: config?.postprocess
599
735
  };
600
736
  }
601
737
  function applyOverrides(config, overrides) {
@@ -810,7 +946,7 @@ function setNestedValue(obj, path3, value) {
810
946
  configurable: true
811
947
  });
812
948
  }
813
- const nested = obj[first];
949
+ const nested = Reflect.get(obj, first);
814
950
  Object.defineProperty(nested, second, {
815
951
  value,
816
952
  writable: true,
@@ -831,7 +967,7 @@ function setNestedValue(obj, path3, value) {
831
967
  configurable: true
832
968
  });
833
969
  }
834
- const nested1 = obj[first];
970
+ const nested1 = Reflect.get(obj, first);
835
971
  if (!(second in nested1)) {
836
972
  Object.defineProperty(nested1, second, {
837
973
  value: {},
@@ -840,7 +976,7 @@ function setNestedValue(obj, path3, value) {
840
976
  configurable: true
841
977
  });
842
978
  }
843
- const nested2 = nested1[second];
979
+ const nested2 = Reflect.get(nested1, second);
844
980
  Object.defineProperty(nested2, third, {
845
981
  value,
846
982
  writable: true,
@@ -858,7 +994,7 @@ function getConfigFromEnv(options = {}) {
858
994
  if (!envKey.startsWith(prefix)) {
859
995
  continue;
860
996
  }
861
- const envValue = env[envKey];
997
+ const envValue = Reflect.get(env, envKey);
862
998
  if (envValue === void 0) {
863
999
  continue;
864
1000
  }
@@ -1034,6 +1170,6 @@ export default defineConfig(${configJson.replace(/"([^"]+)":/g, "$1:")});
1034
1170
  `;
1035
1171
  }
1036
1172
 
1037
- export { CONFIG_FILE_NAMES, DEFAULT_COLLECTIONS_DIR, DEFAULT_ICONS_OUTPUT_DIR, DEFAULT_ICONS_SOURCE_DIR, DEFAULT_LOG_LEVEL, DEFAULT_OUTPUT_DIR, DEFAULT_PREFIX, DEFAULT_SOURCE_DIR, buildConfigSchema, checkDeprecatedOptions, checkMigrationNeeded, clearConfigCache, createResolvedConfig, customFormatSchema, customTransformSchema, defaultConfig, defaultFormats, defaultGlobalConfig, defaultIconFramework, defaultIconsConfig, defaultOutputFileNames, defaultSelectorPattern, defaultSourcePatterns, defaultThemesConfig, defaultTokensConfig, defineConfig, defineConfigAsync, dsaiConfigSchema, envArrayKeys, envBooleanKeys, envMappings, envNumberKeys, filePathSchema, formatErrorMessage, formatValidationErrors, frameworkSchema, generateMigrationScript, getConfigFromEnv, getDefaultExtension, getDefaultOutputDir, getEnvOverrides, getLogLevelFromEnv, getOutputFileName, globPatternSchema, globalConfigSchema, hashTypeSchema, iconOptimizationSchema, iconSpriteSchema, iconsConfigSchema, isCI, loadConfig, loadConfigSync, logLevelSchema, mergeConfigs, migrateConfig, migrateLegacyTokensConfig, outputFormatSchema, resolveConfig, searchConfigFile, shouldDisableColors, themeModeSchema, themesConfigSchema, tokenBuildConfigSchema, tokenCacheConfigSchema, tokenWatchConfigSchema, tokensConfigSchema, tokensHooksSchema, validateConfig, validateConfigOrThrow, validateConfigSection, versionSchema };
1173
+ export { CONFIG_FILE_NAMES, DEFAULT_COLLECTIONS_DIR, DEFAULT_ICONS_OUTPUT_DIR, DEFAULT_ICONS_SOURCE_DIR, DEFAULT_LOG_LEVEL, DEFAULT_OUTPUT_DIR, DEFAULT_PREFIX, DEFAULT_SOURCE_DIR, buildConfigSchema, checkDeprecatedOptions, checkMigrationNeeded, clearConfigCache, createResolvedConfig, customFormatSchema, customTransformSchema, defaultConfig, defaultFormats, defaultGlobalConfig, defaultIconFramework, defaultIconsConfig, defaultOutputFileNames, defaultSelectorPattern, defaultSourcePatterns, defaultThemesConfig, defaultTokensConfig, defineConfig, defineConfigAsync, dsaiConfigSchema, envArrayKeys, envBooleanKeys, envMappings, envNumberKeys, filePathSchema, formatErrorMessage, formatValidationErrors, frameworkSchema, generateMigrationScript, getConfigFromEnv, getDefaultExtension, getDefaultOutputDir, getEnvOverrides, getLogLevelFromEnv, getOutputFileName, globPatternSchema, globalConfigSchema, hashTypeSchema, iconOptimizationSchema, iconSpriteSchema, iconsConfigSchema, isCI, loadConfig, loadConfigSync, logLevelSchema, mergeConfigs, migrateConfig, migrateLegacyTokensConfig, outputFormatSchema, resolveConfig, searchConfigFile, shouldDisableColors, themeDefinitionSchema, themeSelectorPatternSchema, themesConfigSchema, tokenBuildConfigSchema, tokenCacheConfigSchema, tokenWatchConfigSchema, tokensConfigSchema, tokensHooksSchema, validateConfig, validateConfigOrThrow, validateConfigSection, versionSchema };
1038
1174
  //# sourceMappingURL=index.js.map
1039
1175
  //# sourceMappingURL=index.js.map