@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.js CHANGED
@@ -1157,6 +1157,85 @@ var init_groups = __esm({
1157
1157
  }
1158
1158
  });
1159
1159
 
1160
+ // src/tokens/style-dictionary/preprocessors/fix-references.ts
1161
+ function fixValue(value, mappings) {
1162
+ if (typeof value !== "string" || !value.startsWith("{")) {
1163
+ return value;
1164
+ }
1165
+ let result = value;
1166
+ for (const mapping of mappings) {
1167
+ result = result.split(mapping[0]).join(mapping[1]);
1168
+ }
1169
+ return result;
1170
+ }
1171
+ function processTokens(obj, mappings) {
1172
+ for (const key of Object.keys(obj)) {
1173
+ const value = obj[key];
1174
+ if (value && typeof value === "object") {
1175
+ const typedValue = value;
1176
+ if ("$value" in typedValue) {
1177
+ typedValue["$value"] = fixValue(typedValue["$value"], mappings);
1178
+ } else if ("value" in typedValue) {
1179
+ typedValue["value"] = fixValue(typedValue["value"], mappings);
1180
+ } else {
1181
+ processTokens(typedValue, mappings);
1182
+ }
1183
+ }
1184
+ }
1185
+ }
1186
+ function createFixReferencesPreprocessor(mappings) {
1187
+ return {
1188
+ name: "fix-references-custom",
1189
+ preprocessor: (dictionary) => {
1190
+ processTokens(dictionary, mappings);
1191
+ return dictionary;
1192
+ }
1193
+ };
1194
+ }
1195
+ var DEFAULT_PATH_MAPPINGS, fixReferences;
1196
+ var init_fix_references = __esm({
1197
+ "src/tokens/style-dictionary/preprocessors/fix-references.ts"() {
1198
+ DEFAULT_PATH_MAPPINGS = [
1199
+ ["{colors.brand.", "{color."],
1200
+ ["{colors.neutral.", "{neutral."],
1201
+ ["{borders.width.", "{border.width."]
1202
+ ];
1203
+ fixReferences = {
1204
+ name: "fix-references",
1205
+ preprocessor: (dictionary) => {
1206
+ processTokens(dictionary, DEFAULT_PATH_MAPPINGS);
1207
+ return dictionary;
1208
+ }
1209
+ };
1210
+ }
1211
+ });
1212
+
1213
+ // src/tokens/style-dictionary/preprocessors/index.ts
1214
+ var preprocessors_exports = {};
1215
+ __export(preprocessors_exports, {
1216
+ builtInPreprocessors: () => builtInPreprocessors,
1217
+ createFixReferencesPreprocessor: () => createFixReferencesPreprocessor,
1218
+ fixReferences: () => fixReferences,
1219
+ registerPreprocessors: () => registerPreprocessors
1220
+ });
1221
+ function registerPreprocessors(sd, customPreprocessors = []) {
1222
+ const allPreprocessors = [...builtInPreprocessors, ...customPreprocessors];
1223
+ for (const preprocessor of allPreprocessors) {
1224
+ sd.registerPreprocessor({
1225
+ name: preprocessor.name,
1226
+ preprocessor: preprocessor.preprocessor
1227
+ });
1228
+ }
1229
+ }
1230
+ var builtInPreprocessors;
1231
+ var init_preprocessors = __esm({
1232
+ "src/tokens/style-dictionary/preprocessors/index.ts"() {
1233
+ init_fix_references();
1234
+ init_fix_references();
1235
+ builtInPreprocessors = [fixReferences];
1236
+ }
1237
+ });
1238
+
1160
1239
  // src/tokens/diff.ts
1161
1240
  var diff_exports = {};
1162
1241
  __export(diff_exports, {
@@ -5993,7 +6072,7 @@ var FORMAT_MAPPING = /* @__PURE__ */ new Map([
5993
6072
  ["ios", { default: "ios/macros", themed: "ios/macros" }]
5994
6073
  ]);
5995
6074
  var TRANSFORM_GROUPS = /* @__PURE__ */ new Map([
5996
- ["css", "css"],
6075
+ ["css", "custom/css"],
5997
6076
  ["scss", "scss"],
5998
6077
  ["js", "js-custom"],
5999
6078
  // Use custom transform group for valid JS identifiers
@@ -6010,7 +6089,13 @@ function generateThemeBuildConfig(options) {
6010
6089
  const platformsMap = /* @__PURE__ */ new Map();
6011
6090
  const enabledFormats = config.formats;
6012
6091
  for (const format of enabledFormats) {
6013
- const platformConfig = generatePlatformConfig(format, themeDefinition, outputDir, isDefault);
6092
+ const platformConfig = generatePlatformConfig(
6093
+ format,
6094
+ themeDefinition,
6095
+ outputDir,
6096
+ isDefault,
6097
+ config.prefix
6098
+ );
6014
6099
  if (platformConfig) {
6015
6100
  platformsMap.set(format, platformConfig);
6016
6101
  }
@@ -6019,6 +6104,7 @@ function generateThemeBuildConfig(options) {
6019
6104
  return {
6020
6105
  source: files,
6021
6106
  platforms,
6107
+ preprocessors: ["fix-references"],
6022
6108
  // Enable DTCG format support (tokens with $value, $type, etc.)
6023
6109
  usesDtcg: true,
6024
6110
  // Configure logging to not throw on broken references (they'll be logged but build continues)
@@ -6031,7 +6117,7 @@ function generateThemeBuildConfig(options) {
6031
6117
  }
6032
6118
  };
6033
6119
  }
6034
- function generatePlatformConfig(format, themeDefinition, outputDir, isDefault) {
6120
+ function generatePlatformConfig(format, themeDefinition, outputDir, isDefault, prefix) {
6035
6121
  const formatConfig = FORMAT_MAPPING.get(format);
6036
6122
  if (!formatConfig) {
6037
6123
  console.warn(`Unknown format: ${format}`);
@@ -6046,8 +6132,15 @@ function generatePlatformConfig(format, themeDefinition, outputDir, isDefault) {
6046
6132
  destination: outputFile,
6047
6133
  format: sdFormat
6048
6134
  };
6135
+ if (prefix && (format === "css" || format === "scss")) {
6136
+ fileConfig.options = {
6137
+ ...fileConfig.options,
6138
+ prefix
6139
+ };
6140
+ }
6049
6141
  if (format === "css" && !isDefault) {
6050
6142
  fileConfig.options = {
6143
+ ...fileConfig.options,
6051
6144
  selector: themeDefinition.selector
6052
6145
  };
6053
6146
  }
@@ -6160,6 +6253,8 @@ async function runStyleDictionaryBuild(sdConfig, options) {
6160
6253
  registerCustomTransforms(StyleDictionary);
6161
6254
  const { registerTransformGroups: registerTransformGroups2 } = await Promise.resolve().then(() => (init_groups(), groups_exports));
6162
6255
  registerTransformGroups2(StyleDictionary);
6256
+ const { registerPreprocessors: registerPreprocessors2 } = await Promise.resolve().then(() => (init_preprocessors(), preprocessors_exports));
6257
+ registerPreprocessors2(StyleDictionary);
6163
6258
  if (options.verbose) {
6164
6259
  console.warn(` \u{1F527} Style Dictionary platforms:`);
6165
6260
  for (const [platform, config] of Object.entries(sdConfig.platforms)) {
@@ -6613,7 +6708,7 @@ var STEP_DISPLAY_NAMES = /* @__PURE__ */ new Map([
6613
6708
  ["sass-utilities-minified", "Compile DSAi Utilities (minified)"],
6614
6709
  ["bundle", "Bundle with tsup"]
6615
6710
  ]);
6616
- function createStepFromName(stepName, tokensPackageDir, figmaExportsDir, tokensDir, paths, sdConfigFile, strict, snapshotService, themesConfig, outputDir, formats = ["css", "scss", "json"], cssOutputDir, postprocessConfig) {
6711
+ function createStepFromName(stepName, tokensPackageDir, figmaExportsDir, tokensDir, paths, sdConfigFile, strict, snapshotService, themesConfig, outputDir, formats = ["css", "scss", "json"], cssOutputDir, postprocessConfig, prefix) {
6617
6712
  const displayName = STEP_DISPLAY_NAMES.get(stepName) ?? `Unknown: ${stepName}`;
6618
6713
  switch (stepName) {
6619
6714
  case "validate":
@@ -6818,6 +6913,7 @@ function createStepFromName(stepName, tokensPackageDir, figmaExportsDir, tokensD
6818
6913
  const result = await buildAllThemes({
6819
6914
  config: {
6820
6915
  formats,
6916
+ prefix,
6821
6917
  themes: {
6822
6918
  definitions: themeDefinitions
6823
6919
  }
@@ -6933,7 +7029,8 @@ function createBuildSteps(tokensDir, _toolsDir, options, pipeline) {
6933
7029
  options.outputDir,
6934
7030
  formats,
6935
7031
  options.cssOutputDir,
6936
- options.postprocessConfig
7032
+ options.postprocessConfig,
7033
+ options.prefix
6937
7034
  );
6938
7035
  if (stepName === "validate" && skipValidate) {
6939
7036
  step.skip = true;
@@ -8208,68 +8305,7 @@ function getSDTokenType(token) {
8208
8305
  // src/tokens/style-dictionary/config.ts
8209
8306
  init_formats();
8210
8307
  init_groups();
8211
-
8212
- // src/tokens/style-dictionary/preprocessors/fix-references.ts
8213
- var DEFAULT_PATH_MAPPINGS = [
8214
- ["{colors.brand.", "{color."],
8215
- ["{colors.neutral.", "{neutral."],
8216
- ["{borders.width.", "{border.width."]
8217
- ];
8218
- function fixValue(value, mappings) {
8219
- if (typeof value !== "string" || !value.startsWith("{")) {
8220
- return value;
8221
- }
8222
- let result = value;
8223
- for (const mapping of mappings) {
8224
- result = result.split(mapping[0]).join(mapping[1]);
8225
- }
8226
- return result;
8227
- }
8228
- function processTokens(obj, mappings) {
8229
- for (const key of Object.keys(obj)) {
8230
- const value = obj[key];
8231
- if (value && typeof value === "object") {
8232
- const typedValue = value;
8233
- if ("$value" in typedValue) {
8234
- typedValue["$value"] = fixValue(typedValue["$value"], mappings);
8235
- } else if ("value" in typedValue) {
8236
- typedValue["value"] = fixValue(typedValue["value"], mappings);
8237
- } else {
8238
- processTokens(typedValue, mappings);
8239
- }
8240
- }
8241
- }
8242
- }
8243
- var fixReferences = {
8244
- name: "fix-references",
8245
- preprocessor: (dictionary) => {
8246
- processTokens(dictionary, DEFAULT_PATH_MAPPINGS);
8247
- return dictionary;
8248
- }
8249
- };
8250
- function createFixReferencesPreprocessor(mappings) {
8251
- return {
8252
- name: "fix-references-custom",
8253
- preprocessor: (dictionary) => {
8254
- processTokens(dictionary, mappings);
8255
- return dictionary;
8256
- }
8257
- };
8258
- }
8259
-
8260
- // src/tokens/style-dictionary/preprocessors/index.ts
8261
- var builtInPreprocessors = [fixReferences];
8262
- function registerPreprocessors(sd, customPreprocessors = []) {
8263
- const allPreprocessors = [...builtInPreprocessors, ...customPreprocessors];
8264
- for (const preprocessor of allPreprocessors) {
8265
- sd.registerPreprocessor({
8266
- name: preprocessor.name,
8267
- preprocessor: preprocessor.preprocessor
8268
- });
8269
- }
8270
- }
8271
-
8272
- // src/tokens/style-dictionary/config.ts
8308
+ init_preprocessors();
8273
8309
  init_transforms();
8274
8310
  var DEFAULT_SOURCE_PATTERNS = [
8275
8311
  "collections/color/*.json",
@@ -8424,6 +8460,7 @@ function setupStyleDictionary(sd, dsaiConfig, options = {}) {
8424
8460
  // src/tokens/style-dictionary/index.ts
8425
8461
  init_transforms();
8426
8462
  init_formats();
8463
+ init_preprocessors();
8427
8464
  init_groups();
8428
8465
 
8429
8466
  // src/tokens/framework-mappers/index.ts