@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.
@@ -1178,6 +1178,85 @@ var init_groups = __esm({
1178
1178
  }
1179
1179
  });
1180
1180
 
1181
+ // src/tokens/style-dictionary/preprocessors/fix-references.ts
1182
+ function fixValue(value, mappings) {
1183
+ if (typeof value !== "string" || !value.startsWith("{")) {
1184
+ return value;
1185
+ }
1186
+ let result = value;
1187
+ for (const mapping of mappings) {
1188
+ result = result.split(mapping[0]).join(mapping[1]);
1189
+ }
1190
+ return result;
1191
+ }
1192
+ function processTokens(obj, mappings) {
1193
+ for (const key of Object.keys(obj)) {
1194
+ const value = obj[key];
1195
+ if (value && typeof value === "object") {
1196
+ const typedValue = value;
1197
+ if ("$value" in typedValue) {
1198
+ typedValue["$value"] = fixValue(typedValue["$value"], mappings);
1199
+ } else if ("value" in typedValue) {
1200
+ typedValue["value"] = fixValue(typedValue["value"], mappings);
1201
+ } else {
1202
+ processTokens(typedValue, mappings);
1203
+ }
1204
+ }
1205
+ }
1206
+ }
1207
+ function createFixReferencesPreprocessor(mappings) {
1208
+ return {
1209
+ name: "fix-references-custom",
1210
+ preprocessor: (dictionary) => {
1211
+ processTokens(dictionary, mappings);
1212
+ return dictionary;
1213
+ }
1214
+ };
1215
+ }
1216
+ var DEFAULT_PATH_MAPPINGS; exports.fixReferences = void 0;
1217
+ var init_fix_references = __esm({
1218
+ "src/tokens/style-dictionary/preprocessors/fix-references.ts"() {
1219
+ DEFAULT_PATH_MAPPINGS = [
1220
+ ["{colors.brand.", "{color."],
1221
+ ["{colors.neutral.", "{neutral."],
1222
+ ["{borders.width.", "{border.width."]
1223
+ ];
1224
+ exports.fixReferences = {
1225
+ name: "fix-references",
1226
+ preprocessor: (dictionary) => {
1227
+ processTokens(dictionary, DEFAULT_PATH_MAPPINGS);
1228
+ return dictionary;
1229
+ }
1230
+ };
1231
+ }
1232
+ });
1233
+
1234
+ // src/tokens/style-dictionary/preprocessors/index.ts
1235
+ var preprocessors_exports = {};
1236
+ __export(preprocessors_exports, {
1237
+ builtInPreprocessors: () => exports.builtInPreprocessors,
1238
+ createFixReferencesPreprocessor: () => createFixReferencesPreprocessor,
1239
+ fixReferences: () => exports.fixReferences,
1240
+ registerPreprocessors: () => registerPreprocessors
1241
+ });
1242
+ function registerPreprocessors(sd, customPreprocessors = []) {
1243
+ const allPreprocessors = [...exports.builtInPreprocessors, ...customPreprocessors];
1244
+ for (const preprocessor of allPreprocessors) {
1245
+ sd.registerPreprocessor({
1246
+ name: preprocessor.name,
1247
+ preprocessor: preprocessor.preprocessor
1248
+ });
1249
+ }
1250
+ }
1251
+ exports.builtInPreprocessors = void 0;
1252
+ var init_preprocessors = __esm({
1253
+ "src/tokens/style-dictionary/preprocessors/index.ts"() {
1254
+ init_fix_references();
1255
+ init_fix_references();
1256
+ exports.builtInPreprocessors = [exports.fixReferences];
1257
+ }
1258
+ });
1259
+
1181
1260
  // src/tokens/diff.ts
1182
1261
  var diff_exports = {};
1183
1262
  __export(diff_exports, {
@@ -4698,7 +4777,7 @@ var FORMAT_MAPPING = /* @__PURE__ */ new Map([
4698
4777
  ["ios", { default: "ios/macros", themed: "ios/macros" }]
4699
4778
  ]);
4700
4779
  var TRANSFORM_GROUPS = /* @__PURE__ */ new Map([
4701
- ["css", "css"],
4780
+ ["css", "custom/css"],
4702
4781
  ["scss", "scss"],
4703
4782
  ["js", "js-custom"],
4704
4783
  // Use custom transform group for valid JS identifiers
@@ -4715,7 +4794,13 @@ function generateThemeBuildConfig(options) {
4715
4794
  const platformsMap = /* @__PURE__ */ new Map();
4716
4795
  const enabledFormats = config.formats;
4717
4796
  for (const format of enabledFormats) {
4718
- const platformConfig = generatePlatformConfig(format, themeDefinition, outputDir, isDefault);
4797
+ const platformConfig = generatePlatformConfig(
4798
+ format,
4799
+ themeDefinition,
4800
+ outputDir,
4801
+ isDefault,
4802
+ config.prefix
4803
+ );
4719
4804
  if (platformConfig) {
4720
4805
  platformsMap.set(format, platformConfig);
4721
4806
  }
@@ -4724,6 +4809,7 @@ function generateThemeBuildConfig(options) {
4724
4809
  return {
4725
4810
  source: files,
4726
4811
  platforms,
4812
+ preprocessors: ["fix-references"],
4727
4813
  // Enable DTCG format support (tokens with $value, $type, etc.)
4728
4814
  usesDtcg: true,
4729
4815
  // Configure logging to not throw on broken references (they'll be logged but build continues)
@@ -4736,7 +4822,7 @@ function generateThemeBuildConfig(options) {
4736
4822
  }
4737
4823
  };
4738
4824
  }
4739
- function generatePlatformConfig(format, themeDefinition, outputDir, isDefault) {
4825
+ function generatePlatformConfig(format, themeDefinition, outputDir, isDefault, prefix) {
4740
4826
  const formatConfig = FORMAT_MAPPING.get(format);
4741
4827
  if (!formatConfig) {
4742
4828
  console.warn(`Unknown format: ${format}`);
@@ -4751,8 +4837,15 @@ function generatePlatformConfig(format, themeDefinition, outputDir, isDefault) {
4751
4837
  destination: outputFile,
4752
4838
  format: sdFormat
4753
4839
  };
4840
+ if (prefix && (format === "css" || format === "scss")) {
4841
+ fileConfig.options = {
4842
+ ...fileConfig.options,
4843
+ prefix
4844
+ };
4845
+ }
4754
4846
  if (format === "css" && !isDefault) {
4755
4847
  fileConfig.options = {
4848
+ ...fileConfig.options,
4756
4849
  selector: themeDefinition.selector
4757
4850
  };
4758
4851
  }
@@ -4865,6 +4958,8 @@ async function runStyleDictionaryBuild(sdConfig, options) {
4865
4958
  registerCustomTransforms(StyleDictionary);
4866
4959
  const { registerTransformGroups: registerTransformGroups2 } = await Promise.resolve().then(() => (init_groups(), groups_exports));
4867
4960
  registerTransformGroups2(StyleDictionary);
4961
+ const { registerPreprocessors: registerPreprocessors2 } = await Promise.resolve().then(() => (init_preprocessors(), preprocessors_exports));
4962
+ registerPreprocessors2(StyleDictionary);
4868
4963
  if (options.verbose) {
4869
4964
  console.warn(` \u{1F527} Style Dictionary platforms:`);
4870
4965
  for (const [platform, config] of Object.entries(sdConfig.platforms)) {
@@ -5318,7 +5413,7 @@ var STEP_DISPLAY_NAMES = /* @__PURE__ */ new Map([
5318
5413
  ["sass-utilities-minified", "Compile DSAi Utilities (minified)"],
5319
5414
  ["bundle", "Bundle with tsup"]
5320
5415
  ]);
5321
- function createStepFromName(stepName, tokensPackageDir, figmaExportsDir, tokensDir, paths, sdConfigFile, strict, snapshotService, themesConfig, outputDir, formats = ["css", "scss", "json"], cssOutputDir, postprocessConfig) {
5416
+ function createStepFromName(stepName, tokensPackageDir, figmaExportsDir, tokensDir, paths, sdConfigFile, strict, snapshotService, themesConfig, outputDir, formats = ["css", "scss", "json"], cssOutputDir, postprocessConfig, prefix) {
5322
5417
  const displayName = STEP_DISPLAY_NAMES.get(stepName) ?? `Unknown: ${stepName}`;
5323
5418
  switch (stepName) {
5324
5419
  case "validate":
@@ -5523,6 +5618,7 @@ function createStepFromName(stepName, tokensPackageDir, figmaExportsDir, tokensD
5523
5618
  const result = await buildAllThemes({
5524
5619
  config: {
5525
5620
  formats,
5621
+ prefix,
5526
5622
  themes: {
5527
5623
  definitions: themeDefinitions
5528
5624
  }
@@ -5638,7 +5734,8 @@ function createBuildSteps(tokensDir, _toolsDir, options, pipeline) {
5638
5734
  options.outputDir,
5639
5735
  formats,
5640
5736
  options.cssOutputDir,
5641
- options.postprocessConfig
5737
+ options.postprocessConfig,
5738
+ options.prefix
5642
5739
  );
5643
5740
  if (stepName === "validate" && skipValidate) {
5644
5741
  step.skip = true;
@@ -6913,68 +7010,7 @@ function getSDTokenType(token) {
6913
7010
  // src/tokens/style-dictionary/config.ts
6914
7011
  init_formats();
6915
7012
  init_groups();
6916
-
6917
- // src/tokens/style-dictionary/preprocessors/fix-references.ts
6918
- var DEFAULT_PATH_MAPPINGS = [
6919
- ["{colors.brand.", "{color."],
6920
- ["{colors.neutral.", "{neutral."],
6921
- ["{borders.width.", "{border.width."]
6922
- ];
6923
- function fixValue(value, mappings) {
6924
- if (typeof value !== "string" || !value.startsWith("{")) {
6925
- return value;
6926
- }
6927
- let result = value;
6928
- for (const mapping of mappings) {
6929
- result = result.split(mapping[0]).join(mapping[1]);
6930
- }
6931
- return result;
6932
- }
6933
- function processTokens(obj, mappings) {
6934
- for (const key of Object.keys(obj)) {
6935
- const value = obj[key];
6936
- if (value && typeof value === "object") {
6937
- const typedValue = value;
6938
- if ("$value" in typedValue) {
6939
- typedValue["$value"] = fixValue(typedValue["$value"], mappings);
6940
- } else if ("value" in typedValue) {
6941
- typedValue["value"] = fixValue(typedValue["value"], mappings);
6942
- } else {
6943
- processTokens(typedValue, mappings);
6944
- }
6945
- }
6946
- }
6947
- }
6948
- var fixReferences = {
6949
- name: "fix-references",
6950
- preprocessor: (dictionary) => {
6951
- processTokens(dictionary, DEFAULT_PATH_MAPPINGS);
6952
- return dictionary;
6953
- }
6954
- };
6955
- function createFixReferencesPreprocessor(mappings) {
6956
- return {
6957
- name: "fix-references-custom",
6958
- preprocessor: (dictionary) => {
6959
- processTokens(dictionary, mappings);
6960
- return dictionary;
6961
- }
6962
- };
6963
- }
6964
-
6965
- // src/tokens/style-dictionary/preprocessors/index.ts
6966
- var builtInPreprocessors = [fixReferences];
6967
- function registerPreprocessors(sd, customPreprocessors = []) {
6968
- const allPreprocessors = [...builtInPreprocessors, ...customPreprocessors];
6969
- for (const preprocessor of allPreprocessors) {
6970
- sd.registerPreprocessor({
6971
- name: preprocessor.name,
6972
- preprocessor: preprocessor.preprocessor
6973
- });
6974
- }
6975
- }
6976
-
6977
- // src/tokens/style-dictionary/config.ts
7013
+ init_preprocessors();
6978
7014
  init_transforms();
6979
7015
  var DEFAULT_SOURCE_PATTERNS = [
6980
7016
  "collections/color/*.json",
@@ -7129,6 +7165,7 @@ function setupStyleDictionary(sd, dsaiConfig, options = {}) {
7129
7165
  // src/tokens/style-dictionary/index.ts
7130
7166
  init_transforms();
7131
7167
  init_formats();
7168
+ init_preprocessors();
7132
7169
  init_groups();
7133
7170
 
7134
7171
  // src/tokens/framework-mappers/index.ts
@@ -7396,7 +7433,6 @@ exports.buildAllThemes = buildAllThemes;
7396
7433
  exports.buildTheme = buildTheme;
7397
7434
  exports.buildTokens = buildTokens;
7398
7435
  exports.buildTokensCLI = buildTokensCLI;
7399
- exports.builtInPreprocessors = builtInPreprocessors;
7400
7436
  exports.cleanTokenOutputs = cleanTokenOutputs;
7401
7437
  exports.cleanTokensCLI = cleanTokensCLI;
7402
7438
  exports.createBundle = createBundle;
@@ -7422,7 +7458,6 @@ exports.figmaExportWithMetadataSchema = figmaExportWithMetadataSchema;
7422
7458
  exports.figmaVariablesResponseSchema = figmaVariablesResponseSchema;
7423
7459
  exports.filterDiff = filterDiff;
7424
7460
  exports.filterFiles = filterFiles;
7425
- exports.fixReferences = fixReferences;
7426
7461
  exports.flattenModeStructure = flattenModeStructure;
7427
7462
  exports.generateAndWriteChangelog = generateAndWriteChangelog;
7428
7463
  exports.generateChangelog = generateChangelog;