@dsai-io/tools 1.2.5 → 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, {
@@ -1482,7 +1561,7 @@ var init_optimizer = __esm({
1482
1561
  });
1483
1562
 
1484
1563
  // src/version.ts
1485
- var version = "0.0.1";
1564
+ var version = "1.3.0";
1486
1565
  var logLevelSchema = zod.z.enum(["silent", "error", "warn", "info", "debug", "verbose"]);
1487
1566
  var outputFormatSchema = zod.z.enum(["css", "scss", "less", "json", "js", "ts", "esm", "cjs"]);
1488
1567
  var frameworkSchema = zod.z.enum(["react", "vue", "angular", "svelte", "vanilla"]);
@@ -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
@@ -9834,7 +9871,7 @@ function analyzeImports(files, knownNpmDeps) {
9834
9871
  importPattern.lastIndex = 0;
9835
9872
  while ((m = importPattern.exec(file.content)) !== null) {
9836
9873
  const specifier = m[1] ?? "";
9837
- const typesPattern = /\.\.\/(?:\.\.\/)?types(?:\/.*)?$/;
9874
+ const typesPattern = /^\.\.\/\.\.\/types(?:\/.*)?$/;
9838
9875
  if (typesPattern.test(specifier)) {
9839
9876
  registryDeps.add("dsai-types");
9840
9877
  continue;
@@ -9854,6 +9891,16 @@ function analyzeImports(files, knownNpmDeps) {
9854
9891
  if (regName) registryDeps.add(regName);
9855
9892
  continue;
9856
9893
  }
9894
+ const siblingUtilPattern = /^\.\.\/([a-z][\w-]*)(?:\/.*)?$/;
9895
+ const siblingUtilMatch = siblingUtilPattern.exec(specifier);
9896
+ if (siblingUtilMatch && siblingUtilMatch[1]) {
9897
+ const siblingDir = siblingUtilMatch[1];
9898
+ const regName = UTIL_SUBPATH_TO_REGISTRY[siblingDir];
9899
+ if (regName) {
9900
+ registryDeps.add(regName);
9901
+ continue;
9902
+ }
9903
+ }
9857
9904
  const compPattern = /^\.\.\/(\.\.\/)?(?:components\/)?([A-Z]\w+)(?:\/.*)?$/;
9858
9905
  const compMatch = compPattern.exec(specifier);
9859
9906
  if (compMatch && compMatch[2]) {
@@ -9997,6 +10044,8 @@ function buildTypesItem(reactSrcDir, log) {
9997
10044
  const files = sourceFiles.map((f) => {
9998
10045
  let content = f.content;
9999
10046
  content = content.replace(/export \{[^}]*\} from ['"]\.\.\/utils\/[^'"]+['"];?\n?/g, "");
10047
+ content = content.replace(/export\s+(?!type)\{[^}]*\}\s+from\s+['"]\.\/[^'"]+['"];?\n?/g, "");
10048
+ content = content.replace(/\/\*\*\s*\n\s*\*\s*@deprecated[^*]*\*\/\s*\n/g, "");
10000
10049
  return {
10001
10050
  path: `types/${f.path}`,
10002
10051
  type: "registry:type",
@@ -10173,7 +10222,7 @@ function transformImports(content, options) {
10173
10222
  const { aliases } = options;
10174
10223
  let result = content;
10175
10224
  result = result.replace(
10176
- /(from\s+['"])(?:\.\.\/)+types(?:\/([^'"]+))?(['"])/g,
10225
+ /(from\s+['"])\.\.\/\.\.\/types(?:\/([^'"]+))?(['"])/g,
10177
10226
  (_match, prefix, subpath, suffix) => {
10178
10227
  if (subpath) {
10179
10228
  return `${prefix}${aliases.importAlias}${aliases.components}/types/${subpath}${suffix}`;
@@ -10181,6 +10230,18 @@ function transformImports(content, options) {
10181
10230
  return `${prefix}${aliases.importAlias}${aliases.components}/types${suffix}`;
10182
10231
  }
10183
10232
  );
10233
+ result = result.replace(
10234
+ /(from\s+['"])\.\.\/\.\.\/hooks\/(\w+)(['"])/g,
10235
+ `$1${aliases.importAlias}${aliases.hooks}/$2$3`
10236
+ );
10237
+ result = result.replace(
10238
+ /(from\s+['"])\.\.\/\.\.\/utils\/(\w+(?:\/\w+)?)(['"])/g,
10239
+ `$1${aliases.importAlias}${aliases.utils}/$2$3`
10240
+ );
10241
+ result = result.replace(
10242
+ /(from\s+['"])\.\.\/\.\.\/utils(['"])/g,
10243
+ `$1${aliases.importAlias}${aliases.utils}$2`
10244
+ );
10184
10245
  result = result.replace(
10185
10246
  /(from\s+['"])\.\.\/(([A-Z]\w+)(\/[^'"]+)?)(['"])/g,
10186
10247
  (_match, prefix, _fullPath, dirName, subPath, suffix) => {
@@ -10191,18 +10252,6 @@ function transformImports(content, options) {
10191
10252
  return `${prefix}${aliases.importAlias}${aliases.ui}/${kebab}${suffix}`;
10192
10253
  }
10193
10254
  );
10194
- result = result.replace(
10195
- /(from\s+['"])(?:\.\.\/)+hooks\/(\w+)(['"])/g,
10196
- `$1${aliases.importAlias}${aliases.hooks}/$2$3`
10197
- );
10198
- result = result.replace(
10199
- /(from\s+['"])(?:\.\.\/)+utils\/(\w+(?:\/\w+)?)(['"])/g,
10200
- `$1${aliases.importAlias}${aliases.utils}/$2$3`
10201
- );
10202
- result = result.replace(
10203
- /(from\s+['"])(?:\.\.\/)+utils(['"])/g,
10204
- `$1${aliases.importAlias}${aliases.utils}$2`
10205
- );
10206
10255
  return result;
10207
10256
  }
10208
10257
  function normalizeExtensions(content, tsx) {
@@ -10256,16 +10305,17 @@ function writeRegistryItems(tree, options) {
10256
10305
  for (const item of tree.items) {
10257
10306
  const targetBaseDir = getTargetDir(item.type, aliases);
10258
10307
  for (const file of item.files) {
10259
- const fileName = path2.basename(file.path);
10260
10308
  let targetPath;
10261
10309
  if (file.target) {
10262
10310
  targetPath = path2.join(projectDir, file.target);
10263
10311
  } else if (item.type === "registry:ui" || item.type === "registry:component") {
10264
- targetPath = path2.join(projectDir, targetBaseDir, item.name, fileName);
10265
- } else if (item.type === "registry:type") {
10312
+ targetPath = path2.join(projectDir, targetBaseDir, item.name, path2.basename(file.path));
10313
+ } else if (item.type === "registry:hook") {
10314
+ targetPath = path2.join(projectDir, targetBaseDir, item.name, path2.basename(file.path));
10315
+ } else if (file.path.includes("/")) {
10266
10316
  targetPath = path2.join(projectDir, targetBaseDir, file.path);
10267
10317
  } else {
10268
- targetPath = path2.join(projectDir, targetBaseDir, fileName);
10318
+ targetPath = path2.join(projectDir, targetBaseDir, path2.basename(file.path));
10269
10319
  }
10270
10320
  if (fs3.existsSync(targetPath) && !shouldOverwrite) {
10271
10321
  if (log) log(` Skipped (exists): ${targetPath}`);
@@ -10439,7 +10489,6 @@ exports.buildRegistry = buildRegistry;
10439
10489
  exports.buildTheme = buildTheme;
10440
10490
  exports.buildTokens = buildTokens;
10441
10491
  exports.buildTokensCLI = buildTokensCLI;
10442
- exports.builtInPreprocessors = builtInPreprocessors;
10443
10492
  exports.checkDeprecatedOptions = checkDeprecatedOptions;
10444
10493
  exports.checkMigrationNeeded = checkMigrationNeeded;
10445
10494
  exports.cleanSVGForReact = cleanSVGForReact;
@@ -10500,7 +10549,6 @@ exports.filePathSchema = filePathSchema;
10500
10549
  exports.filterDiff = filterDiff;
10501
10550
  exports.filterFiles = filterFiles;
10502
10551
  exports.findPackageJson = findPackageJson;
10503
- exports.fixReferences = fixReferences;
10504
10552
  exports.flattenModeStructure = flattenModeStructure;
10505
10553
  exports.formatDuration = formatDuration;
10506
10554
  exports.formatErrorMessage = formatErrorMessage;