@dsai-io/tools 1.3.0 → 1.3.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.
@@ -4594,13 +4594,98 @@ var init_groups = __esm({
4594
4594
  ];
4595
4595
  }
4596
4596
  });
4597
+
4598
+ // src/tokens/style-dictionary/preprocessors/fix-references.ts
4599
+ function fixValue(value, mappings) {
4600
+ if (typeof value !== "string" || !value.startsWith("{")) {
4601
+ return value;
4602
+ }
4603
+ let result = value;
4604
+ for (const mapping of mappings) {
4605
+ result = result.split(mapping[0]).join(mapping[1]);
4606
+ }
4607
+ return result;
4608
+ }
4609
+ function processTokens(obj, mappings) {
4610
+ for (const key of Object.keys(obj)) {
4611
+ const value = obj[key];
4612
+ if (value && typeof value === "object") {
4613
+ const typedValue = value;
4614
+ if ("$value" in typedValue) {
4615
+ typedValue["$value"] = fixValue(typedValue["$value"], mappings);
4616
+ } else if ("value" in typedValue) {
4617
+ typedValue["value"] = fixValue(typedValue["value"], mappings);
4618
+ } else {
4619
+ processTokens(typedValue, mappings);
4620
+ }
4621
+ }
4622
+ }
4623
+ }
4624
+ function createFixReferencesPreprocessor(mappings) {
4625
+ return {
4626
+ name: "fix-references-custom",
4627
+ preprocessor: (dictionary) => {
4628
+ processTokens(dictionary, mappings);
4629
+ return dictionary;
4630
+ }
4631
+ };
4632
+ }
4633
+ var DEFAULT_PATH_MAPPINGS, fixReferences;
4634
+ var init_fix_references = __esm({
4635
+ "src/tokens/style-dictionary/preprocessors/fix-references.ts"() {
4636
+ DEFAULT_PATH_MAPPINGS = [
4637
+ ["{colors.brand.", "{color."],
4638
+ ["{colors.neutral.", "{neutral."],
4639
+ ["{borders.width.", "{border.width."]
4640
+ ];
4641
+ fixReferences = {
4642
+ name: "fix-references",
4643
+ preprocessor: (dictionary) => {
4644
+ processTokens(dictionary, DEFAULT_PATH_MAPPINGS);
4645
+ return dictionary;
4646
+ }
4647
+ };
4648
+ }
4649
+ });
4650
+
4651
+ // src/tokens/style-dictionary/preprocessors/index.ts
4652
+ var preprocessors_exports = {};
4653
+ __export(preprocessors_exports, {
4654
+ builtInPreprocessors: () => builtInPreprocessors,
4655
+ createFixReferencesPreprocessor: () => createFixReferencesPreprocessor,
4656
+ fixReferences: () => fixReferences,
4657
+ registerPreprocessors: () => registerPreprocessors
4658
+ });
4659
+ function registerPreprocessors(sd, customPreprocessors = []) {
4660
+ const allPreprocessors = [...builtInPreprocessors, ...customPreprocessors];
4661
+ for (const preprocessor of allPreprocessors) {
4662
+ sd.registerPreprocessor({
4663
+ name: preprocessor.name,
4664
+ preprocessor: preprocessor.preprocessor
4665
+ });
4666
+ }
4667
+ }
4668
+ var builtInPreprocessors;
4669
+ var init_preprocessors = __esm({
4670
+ "src/tokens/style-dictionary/preprocessors/index.ts"() {
4671
+ init_fix_references();
4672
+ init_fix_references();
4673
+ builtInPreprocessors = [fixReferences];
4674
+ }
4675
+ });
4597
4676
  function generateThemeBuildConfig(options) {
4598
4677
  const { themeDefinition, files, outputDir, config } = options;
4599
4678
  const isDefault = themeDefinition.isDefault;
4600
4679
  const platformsMap = /* @__PURE__ */ new Map();
4601
4680
  const enabledFormats = config.formats;
4602
4681
  for (const format of enabledFormats) {
4603
- const platformConfig = generatePlatformConfig(format, themeDefinition, outputDir, isDefault);
4682
+ const platformConfig = generatePlatformConfig(
4683
+ format,
4684
+ themeDefinition,
4685
+ outputDir,
4686
+ isDefault,
4687
+ config.prefix
4688
+ );
4604
4689
  if (platformConfig) {
4605
4690
  platformsMap.set(format, platformConfig);
4606
4691
  }
@@ -4609,6 +4694,7 @@ function generateThemeBuildConfig(options) {
4609
4694
  return {
4610
4695
  source: files,
4611
4696
  platforms,
4697
+ preprocessors: ["fix-references"],
4612
4698
  // Enable DTCG format support (tokens with $value, $type, etc.)
4613
4699
  usesDtcg: true,
4614
4700
  // Configure logging to not throw on broken references (they'll be logged but build continues)
@@ -4621,7 +4707,7 @@ function generateThemeBuildConfig(options) {
4621
4707
  }
4622
4708
  };
4623
4709
  }
4624
- function generatePlatformConfig(format, themeDefinition, outputDir, isDefault) {
4710
+ function generatePlatformConfig(format, themeDefinition, outputDir, isDefault, prefix) {
4625
4711
  const formatConfig = FORMAT_MAPPING.get(format);
4626
4712
  if (!formatConfig) {
4627
4713
  console.warn(`Unknown format: ${format}`);
@@ -4636,8 +4722,15 @@ function generatePlatformConfig(format, themeDefinition, outputDir, isDefault) {
4636
4722
  destination: outputFile,
4637
4723
  format: sdFormat
4638
4724
  };
4725
+ if (prefix && (format === "css" || format === "scss")) {
4726
+ fileConfig.options = {
4727
+ ...fileConfig.options,
4728
+ prefix
4729
+ };
4730
+ }
4639
4731
  if (format === "css" && !isDefault) {
4640
4732
  fileConfig.options = {
4733
+ ...fileConfig.options,
4641
4734
  selector: themeDefinition.selector
4642
4735
  };
4643
4736
  }
@@ -4750,6 +4843,8 @@ async function runStyleDictionaryBuild(sdConfig, options) {
4750
4843
  registerCustomTransforms(StyleDictionary);
4751
4844
  const { registerTransformGroups: registerTransformGroups2 } = await Promise.resolve().then(() => (init_groups(), groups_exports));
4752
4845
  registerTransformGroups2(StyleDictionary);
4846
+ const { registerPreprocessors: registerPreprocessors2 } = await Promise.resolve().then(() => (init_preprocessors(), preprocessors_exports));
4847
+ registerPreprocessors2(StyleDictionary);
4753
4848
  if (options.verbose) {
4754
4849
  console.warn(` \u{1F527} Style Dictionary platforms:`);
4755
4850
  for (const [platform, config] of Object.entries(sdConfig.platforms)) {
@@ -4943,7 +5038,7 @@ var init_theme_builder = __esm({
4943
5038
  ["ios", { default: "ios/macros", themed: "ios/macros" }]
4944
5039
  ]);
4945
5040
  TRANSFORM_GROUPS = /* @__PURE__ */ new Map([
4946
- ["css", "css"],
5041
+ ["css", "custom/css"],
4947
5042
  ["scss", "scss"],
4948
5043
  ["js", "js-custom"],
4949
5044
  // Use custom transform group for valid JS identifiers
@@ -5182,7 +5277,7 @@ function getPipelinePaths(customPaths) {
5182
5277
  ...customPaths
5183
5278
  };
5184
5279
  }
5185
- function createStepFromName(stepName, tokensPackageDir, figmaExportsDir, tokensDir, paths, sdConfigFile, strict, snapshotService, themesConfig, outputDir, formats = ["css", "scss", "json"], cssOutputDir, postprocessConfig) {
5280
+ function createStepFromName(stepName, tokensPackageDir, figmaExportsDir, tokensDir, paths, sdConfigFile, strict, snapshotService, themesConfig, outputDir, formats = ["css", "scss", "json"], cssOutputDir, postprocessConfig, prefix) {
5186
5281
  const displayName = STEP_DISPLAY_NAMES.get(stepName) ?? `Unknown: ${stepName}`;
5187
5282
  switch (stepName) {
5188
5283
  case "validate":
@@ -5387,6 +5482,7 @@ function createStepFromName(stepName, tokensPackageDir, figmaExportsDir, tokensD
5387
5482
  const result = await buildAllThemes({
5388
5483
  config: {
5389
5484
  formats,
5485
+ prefix,
5390
5486
  themes: {
5391
5487
  definitions: themeDefinitions
5392
5488
  }
@@ -5502,7 +5598,8 @@ function createBuildSteps(tokensDir, _toolsDir, options, pipeline) {
5502
5598
  options.outputDir,
5503
5599
  formats,
5504
5600
  options.cssOutputDir,
5505
- options.postprocessConfig
5601
+ options.postprocessConfig,
5602
+ options.prefix
5506
5603
  );
5507
5604
  if (stepName === "validate" && skipValidate) {
5508
5605
  step.skip = true;
@@ -6887,78 +6984,6 @@ var init_types2 = __esm({
6887
6984
  }
6888
6985
  });
6889
6986
 
6890
- // src/tokens/style-dictionary/preprocessors/fix-references.ts
6891
- function fixValue(value, mappings) {
6892
- if (typeof value !== "string" || !value.startsWith("{")) {
6893
- return value;
6894
- }
6895
- let result = value;
6896
- for (const mapping of mappings) {
6897
- result = result.split(mapping[0]).join(mapping[1]);
6898
- }
6899
- return result;
6900
- }
6901
- function processTokens(obj, mappings) {
6902
- for (const key of Object.keys(obj)) {
6903
- const value = obj[key];
6904
- if (value && typeof value === "object") {
6905
- const typedValue = value;
6906
- if ("$value" in typedValue) {
6907
- typedValue["$value"] = fixValue(typedValue["$value"], mappings);
6908
- } else if ("value" in typedValue) {
6909
- typedValue["value"] = fixValue(typedValue["value"], mappings);
6910
- } else {
6911
- processTokens(typedValue, mappings);
6912
- }
6913
- }
6914
- }
6915
- }
6916
- function createFixReferencesPreprocessor(mappings) {
6917
- return {
6918
- name: "fix-references-custom",
6919
- preprocessor: (dictionary) => {
6920
- processTokens(dictionary, mappings);
6921
- return dictionary;
6922
- }
6923
- };
6924
- }
6925
- var DEFAULT_PATH_MAPPINGS, fixReferences;
6926
- var init_fix_references = __esm({
6927
- "src/tokens/style-dictionary/preprocessors/fix-references.ts"() {
6928
- DEFAULT_PATH_MAPPINGS = [
6929
- ["{colors.brand.", "{color."],
6930
- ["{colors.neutral.", "{neutral."],
6931
- ["{borders.width.", "{border.width."]
6932
- ];
6933
- fixReferences = {
6934
- name: "fix-references",
6935
- preprocessor: (dictionary) => {
6936
- processTokens(dictionary, DEFAULT_PATH_MAPPINGS);
6937
- return dictionary;
6938
- }
6939
- };
6940
- }
6941
- });
6942
-
6943
- // src/tokens/style-dictionary/preprocessors/index.ts
6944
- function registerPreprocessors(sd, customPreprocessors = []) {
6945
- const allPreprocessors = [...builtInPreprocessors, ...customPreprocessors];
6946
- for (const preprocessor of allPreprocessors) {
6947
- sd.registerPreprocessor({
6948
- name: preprocessor.name,
6949
- preprocessor: preprocessor.preprocessor
6950
- });
6951
- }
6952
- }
6953
- var builtInPreprocessors;
6954
- var init_preprocessors = __esm({
6955
- "src/tokens/style-dictionary/preprocessors/index.ts"() {
6956
- init_fix_references();
6957
- init_fix_references();
6958
- builtInPreprocessors = [fixReferences];
6959
- }
6960
- });
6961
-
6962
6987
  // src/tokens/style-dictionary/config.ts
6963
6988
  function createStyleDictionaryConfig(dsaiConfig, options = {}) {
6964
6989
  const {
@@ -9393,6 +9418,8 @@ async function runTokensBuild(options) {
9393
9418
  pipeline: config.tokens.pipeline,
9394
9419
  // Pass formats from config (default: css, scss, json)
9395
9420
  formats: config.tokens.formats,
9421
+ // Pass CSS custom property prefix from config
9422
+ prefix: config.tokens.prefix,
9396
9423
  // Pass output directory from config
9397
9424
  outputDir: config.tokens.outputDir ? path4.resolve(configDir, config.tokens.outputDir) : path4.resolve(configDir, "dist"),
9398
9425
  // Pass themes config for multi-theme builds