@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.
package/dist/index.cjs CHANGED
@@ -1183,6 +1183,85 @@ var init_groups = __esm({
1183
1183
  }
1184
1184
  });
1185
1185
 
1186
+ // src/tokens/style-dictionary/preprocessors/fix-references.ts
1187
+ function fixValue(value, mappings) {
1188
+ if (typeof value !== "string" || !value.startsWith("{")) {
1189
+ return value;
1190
+ }
1191
+ let result = value;
1192
+ for (const mapping of mappings) {
1193
+ result = result.split(mapping[0]).join(mapping[1]);
1194
+ }
1195
+ return result;
1196
+ }
1197
+ function processTokens(obj, mappings) {
1198
+ for (const key of Object.keys(obj)) {
1199
+ const value = obj[key];
1200
+ if (value && typeof value === "object") {
1201
+ const typedValue = value;
1202
+ if ("$value" in typedValue) {
1203
+ typedValue["$value"] = fixValue(typedValue["$value"], mappings);
1204
+ } else if ("value" in typedValue) {
1205
+ typedValue["value"] = fixValue(typedValue["value"], mappings);
1206
+ } else {
1207
+ processTokens(typedValue, mappings);
1208
+ }
1209
+ }
1210
+ }
1211
+ }
1212
+ function createFixReferencesPreprocessor(mappings) {
1213
+ return {
1214
+ name: "fix-references-custom",
1215
+ preprocessor: (dictionary) => {
1216
+ processTokens(dictionary, mappings);
1217
+ return dictionary;
1218
+ }
1219
+ };
1220
+ }
1221
+ var DEFAULT_PATH_MAPPINGS; exports.fixReferences = void 0;
1222
+ var init_fix_references = __esm({
1223
+ "src/tokens/style-dictionary/preprocessors/fix-references.ts"() {
1224
+ DEFAULT_PATH_MAPPINGS = [
1225
+ ["{colors.brand.", "{color."],
1226
+ ["{colors.neutral.", "{neutral."],
1227
+ ["{borders.width.", "{border.width."]
1228
+ ];
1229
+ exports.fixReferences = {
1230
+ name: "fix-references",
1231
+ preprocessor: (dictionary) => {
1232
+ processTokens(dictionary, DEFAULT_PATH_MAPPINGS);
1233
+ return dictionary;
1234
+ }
1235
+ };
1236
+ }
1237
+ });
1238
+
1239
+ // src/tokens/style-dictionary/preprocessors/index.ts
1240
+ var preprocessors_exports = {};
1241
+ __export(preprocessors_exports, {
1242
+ builtInPreprocessors: () => exports.builtInPreprocessors,
1243
+ createFixReferencesPreprocessor: () => createFixReferencesPreprocessor,
1244
+ fixReferences: () => exports.fixReferences,
1245
+ registerPreprocessors: () => registerPreprocessors
1246
+ });
1247
+ function registerPreprocessors(sd, customPreprocessors = []) {
1248
+ const allPreprocessors = [...exports.builtInPreprocessors, ...customPreprocessors];
1249
+ for (const preprocessor of allPreprocessors) {
1250
+ sd.registerPreprocessor({
1251
+ name: preprocessor.name,
1252
+ preprocessor: preprocessor.preprocessor
1253
+ });
1254
+ }
1255
+ }
1256
+ exports.builtInPreprocessors = void 0;
1257
+ var init_preprocessors = __esm({
1258
+ "src/tokens/style-dictionary/preprocessors/index.ts"() {
1259
+ init_fix_references();
1260
+ init_fix_references();
1261
+ exports.builtInPreprocessors = [exports.fixReferences];
1262
+ }
1263
+ });
1264
+
1186
1265
  // src/tokens/diff.ts
1187
1266
  var diff_exports = {};
1188
1267
  __export(diff_exports, {
@@ -6019,7 +6098,7 @@ var FORMAT_MAPPING = /* @__PURE__ */ new Map([
6019
6098
  ["ios", { default: "ios/macros", themed: "ios/macros" }]
6020
6099
  ]);
6021
6100
  var TRANSFORM_GROUPS = /* @__PURE__ */ new Map([
6022
- ["css", "css"],
6101
+ ["css", "custom/css"],
6023
6102
  ["scss", "scss"],
6024
6103
  ["js", "js-custom"],
6025
6104
  // Use custom transform group for valid JS identifiers
@@ -6036,7 +6115,13 @@ function generateThemeBuildConfig(options) {
6036
6115
  const platformsMap = /* @__PURE__ */ new Map();
6037
6116
  const enabledFormats = config.formats;
6038
6117
  for (const format of enabledFormats) {
6039
- const platformConfig = generatePlatformConfig(format, themeDefinition, outputDir, isDefault);
6118
+ const platformConfig = generatePlatformConfig(
6119
+ format,
6120
+ themeDefinition,
6121
+ outputDir,
6122
+ isDefault,
6123
+ config.prefix
6124
+ );
6040
6125
  if (platformConfig) {
6041
6126
  platformsMap.set(format, platformConfig);
6042
6127
  }
@@ -6045,6 +6130,7 @@ function generateThemeBuildConfig(options) {
6045
6130
  return {
6046
6131
  source: files,
6047
6132
  platforms,
6133
+ preprocessors: ["fix-references"],
6048
6134
  // Enable DTCG format support (tokens with $value, $type, etc.)
6049
6135
  usesDtcg: true,
6050
6136
  // Configure logging to not throw on broken references (they'll be logged but build continues)
@@ -6057,7 +6143,7 @@ function generateThemeBuildConfig(options) {
6057
6143
  }
6058
6144
  };
6059
6145
  }
6060
- function generatePlatformConfig(format, themeDefinition, outputDir, isDefault) {
6146
+ function generatePlatformConfig(format, themeDefinition, outputDir, isDefault, prefix) {
6061
6147
  const formatConfig = FORMAT_MAPPING.get(format);
6062
6148
  if (!formatConfig) {
6063
6149
  console.warn(`Unknown format: ${format}`);
@@ -6072,8 +6158,15 @@ function generatePlatformConfig(format, themeDefinition, outputDir, isDefault) {
6072
6158
  destination: outputFile,
6073
6159
  format: sdFormat
6074
6160
  };
6161
+ if (prefix && (format === "css" || format === "scss")) {
6162
+ fileConfig.options = {
6163
+ ...fileConfig.options,
6164
+ prefix
6165
+ };
6166
+ }
6075
6167
  if (format === "css" && !isDefault) {
6076
6168
  fileConfig.options = {
6169
+ ...fileConfig.options,
6077
6170
  selector: themeDefinition.selector
6078
6171
  };
6079
6172
  }
@@ -6186,6 +6279,8 @@ async function runStyleDictionaryBuild(sdConfig, options) {
6186
6279
  registerCustomTransforms(StyleDictionary);
6187
6280
  const { registerTransformGroups: registerTransformGroups2 } = await Promise.resolve().then(() => (init_groups(), groups_exports));
6188
6281
  registerTransformGroups2(StyleDictionary);
6282
+ const { registerPreprocessors: registerPreprocessors2 } = await Promise.resolve().then(() => (init_preprocessors(), preprocessors_exports));
6283
+ registerPreprocessors2(StyleDictionary);
6189
6284
  if (options.verbose) {
6190
6285
  console.warn(` \u{1F527} Style Dictionary platforms:`);
6191
6286
  for (const [platform, config] of Object.entries(sdConfig.platforms)) {
@@ -6639,7 +6734,7 @@ var STEP_DISPLAY_NAMES = /* @__PURE__ */ new Map([
6639
6734
  ["sass-utilities-minified", "Compile DSAi Utilities (minified)"],
6640
6735
  ["bundle", "Bundle with tsup"]
6641
6736
  ]);
6642
- function createStepFromName(stepName, tokensPackageDir, figmaExportsDir, tokensDir, paths, sdConfigFile, strict, snapshotService, themesConfig, outputDir, formats = ["css", "scss", "json"], cssOutputDir, postprocessConfig) {
6737
+ function createStepFromName(stepName, tokensPackageDir, figmaExportsDir, tokensDir, paths, sdConfigFile, strict, snapshotService, themesConfig, outputDir, formats = ["css", "scss", "json"], cssOutputDir, postprocessConfig, prefix) {
6643
6738
  const displayName = STEP_DISPLAY_NAMES.get(stepName) ?? `Unknown: ${stepName}`;
6644
6739
  switch (stepName) {
6645
6740
  case "validate":
@@ -6844,6 +6939,7 @@ function createStepFromName(stepName, tokensPackageDir, figmaExportsDir, tokensD
6844
6939
  const result = await buildAllThemes({
6845
6940
  config: {
6846
6941
  formats,
6942
+ prefix,
6847
6943
  themes: {
6848
6944
  definitions: themeDefinitions
6849
6945
  }
@@ -6959,7 +7055,8 @@ function createBuildSteps(tokensDir, _toolsDir, options, pipeline) {
6959
7055
  options.outputDir,
6960
7056
  formats,
6961
7057
  options.cssOutputDir,
6962
- options.postprocessConfig
7058
+ options.postprocessConfig,
7059
+ options.prefix
6963
7060
  );
6964
7061
  if (stepName === "validate" && skipValidate) {
6965
7062
  step.skip = true;
@@ -8234,68 +8331,7 @@ function getSDTokenType(token) {
8234
8331
  // src/tokens/style-dictionary/config.ts
8235
8332
  init_formats();
8236
8333
  init_groups();
8237
-
8238
- // src/tokens/style-dictionary/preprocessors/fix-references.ts
8239
- var DEFAULT_PATH_MAPPINGS = [
8240
- ["{colors.brand.", "{color."],
8241
- ["{colors.neutral.", "{neutral."],
8242
- ["{borders.width.", "{border.width."]
8243
- ];
8244
- function fixValue(value, mappings) {
8245
- if (typeof value !== "string" || !value.startsWith("{")) {
8246
- return value;
8247
- }
8248
- let result = value;
8249
- for (const mapping of mappings) {
8250
- result = result.split(mapping[0]).join(mapping[1]);
8251
- }
8252
- return result;
8253
- }
8254
- function processTokens(obj, mappings) {
8255
- for (const key of Object.keys(obj)) {
8256
- const value = obj[key];
8257
- if (value && typeof value === "object") {
8258
- const typedValue = value;
8259
- if ("$value" in typedValue) {
8260
- typedValue["$value"] = fixValue(typedValue["$value"], mappings);
8261
- } else if ("value" in typedValue) {
8262
- typedValue["value"] = fixValue(typedValue["value"], mappings);
8263
- } else {
8264
- processTokens(typedValue, mappings);
8265
- }
8266
- }
8267
- }
8268
- }
8269
- var fixReferences = {
8270
- name: "fix-references",
8271
- preprocessor: (dictionary) => {
8272
- processTokens(dictionary, DEFAULT_PATH_MAPPINGS);
8273
- return dictionary;
8274
- }
8275
- };
8276
- function createFixReferencesPreprocessor(mappings) {
8277
- return {
8278
- name: "fix-references-custom",
8279
- preprocessor: (dictionary) => {
8280
- processTokens(dictionary, mappings);
8281
- return dictionary;
8282
- }
8283
- };
8284
- }
8285
-
8286
- // src/tokens/style-dictionary/preprocessors/index.ts
8287
- var builtInPreprocessors = [fixReferences];
8288
- function registerPreprocessors(sd, customPreprocessors = []) {
8289
- const allPreprocessors = [...builtInPreprocessors, ...customPreprocessors];
8290
- for (const preprocessor of allPreprocessors) {
8291
- sd.registerPreprocessor({
8292
- name: preprocessor.name,
8293
- preprocessor: preprocessor.preprocessor
8294
- });
8295
- }
8296
- }
8297
-
8298
- // src/tokens/style-dictionary/config.ts
8334
+ init_preprocessors();
8299
8335
  init_transforms();
8300
8336
  var DEFAULT_SOURCE_PATTERNS = [
8301
8337
  "collections/color/*.json",
@@ -8450,6 +8486,7 @@ function setupStyleDictionary(sd, dsaiConfig, options = {}) {
8450
8486
  // src/tokens/style-dictionary/index.ts
8451
8487
  init_transforms();
8452
8488
  init_formats();
8489
+ init_preprocessors();
8453
8490
  init_groups();
8454
8491
 
8455
8492
  // src/tokens/framework-mappers/index.ts
@@ -10452,7 +10489,6 @@ exports.buildRegistry = buildRegistry;
10452
10489
  exports.buildTheme = buildTheme;
10453
10490
  exports.buildTokens = buildTokens;
10454
10491
  exports.buildTokensCLI = buildTokensCLI;
10455
- exports.builtInPreprocessors = builtInPreprocessors;
10456
10492
  exports.checkDeprecatedOptions = checkDeprecatedOptions;
10457
10493
  exports.checkMigrationNeeded = checkMigrationNeeded;
10458
10494
  exports.cleanSVGForReact = cleanSVGForReact;
@@ -10513,7 +10549,6 @@ exports.filePathSchema = filePathSchema;
10513
10549
  exports.filterDiff = filterDiff;
10514
10550
  exports.filterFiles = filterFiles;
10515
10551
  exports.findPackageJson = findPackageJson;
10516
- exports.fixReferences = fixReferences;
10517
10552
  exports.flattenModeStructure = flattenModeStructure;
10518
10553
  exports.formatDuration = formatDuration;
10519
10554
  exports.formatErrorMessage = formatErrorMessage;