@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.d.cts CHANGED
@@ -8,7 +8,7 @@ import { z } from 'zod';
8
8
  /**
9
9
  * Package version
10
10
  */
11
- declare const version = "0.0.1";
11
+ declare const version = "1.3.0";
12
12
 
13
13
  /**
14
14
  * Registry type definitions for DSAi component distribution.
package/dist/index.d.ts CHANGED
@@ -8,7 +8,7 @@ import { z } from 'zod';
8
8
  /**
9
9
  * Package version
10
10
  */
11
- declare const version = "0.0.1";
11
+ declare const version = "1.3.0";
12
12
 
13
13
  /**
14
14
  * Registry type definitions for DSAi component distribution.
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, {
@@ -1456,7 +1535,7 @@ var init_optimizer = __esm({
1456
1535
  });
1457
1536
 
1458
1537
  // src/version.ts
1459
- var version = "0.0.1";
1538
+ var version = "1.3.0";
1460
1539
  var logLevelSchema = z.enum(["silent", "error", "warn", "info", "debug", "verbose"]);
1461
1540
  var outputFormatSchema = z.enum(["css", "scss", "less", "json", "js", "ts", "esm", "cjs"]);
1462
1541
  var frameworkSchema = z.enum(["react", "vue", "angular", "svelte", "vanilla"]);
@@ -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
@@ -9808,7 +9845,7 @@ function analyzeImports(files, knownNpmDeps) {
9808
9845
  importPattern.lastIndex = 0;
9809
9846
  while ((m = importPattern.exec(file.content)) !== null) {
9810
9847
  const specifier = m[1] ?? "";
9811
- const typesPattern = /\.\.\/(?:\.\.\/)?types(?:\/.*)?$/;
9848
+ const typesPattern = /^\.\.\/\.\.\/types(?:\/.*)?$/;
9812
9849
  if (typesPattern.test(specifier)) {
9813
9850
  registryDeps.add("dsai-types");
9814
9851
  continue;
@@ -9828,6 +9865,16 @@ function analyzeImports(files, knownNpmDeps) {
9828
9865
  if (regName) registryDeps.add(regName);
9829
9866
  continue;
9830
9867
  }
9868
+ const siblingUtilPattern = /^\.\.\/([a-z][\w-]*)(?:\/.*)?$/;
9869
+ const siblingUtilMatch = siblingUtilPattern.exec(specifier);
9870
+ if (siblingUtilMatch && siblingUtilMatch[1]) {
9871
+ const siblingDir = siblingUtilMatch[1];
9872
+ const regName = UTIL_SUBPATH_TO_REGISTRY[siblingDir];
9873
+ if (regName) {
9874
+ registryDeps.add(regName);
9875
+ continue;
9876
+ }
9877
+ }
9831
9878
  const compPattern = /^\.\.\/(\.\.\/)?(?:components\/)?([A-Z]\w+)(?:\/.*)?$/;
9832
9879
  const compMatch = compPattern.exec(specifier);
9833
9880
  if (compMatch && compMatch[2]) {
@@ -9971,6 +10018,8 @@ function buildTypesItem(reactSrcDir, log) {
9971
10018
  const files = sourceFiles.map((f) => {
9972
10019
  let content = f.content;
9973
10020
  content = content.replace(/export \{[^}]*\} from ['"]\.\.\/utils\/[^'"]+['"];?\n?/g, "");
10021
+ content = content.replace(/export\s+(?!type)\{[^}]*\}\s+from\s+['"]\.\/[^'"]+['"];?\n?/g, "");
10022
+ content = content.replace(/\/\*\*\s*\n\s*\*\s*@deprecated[^*]*\*\/\s*\n/g, "");
9974
10023
  return {
9975
10024
  path: `types/${f.path}`,
9976
10025
  type: "registry:type",
@@ -10147,7 +10196,7 @@ function transformImports(content, options) {
10147
10196
  const { aliases } = options;
10148
10197
  let result = content;
10149
10198
  result = result.replace(
10150
- /(from\s+['"])(?:\.\.\/)+types(?:\/([^'"]+))?(['"])/g,
10199
+ /(from\s+['"])\.\.\/\.\.\/types(?:\/([^'"]+))?(['"])/g,
10151
10200
  (_match, prefix, subpath, suffix) => {
10152
10201
  if (subpath) {
10153
10202
  return `${prefix}${aliases.importAlias}${aliases.components}/types/${subpath}${suffix}`;
@@ -10155,6 +10204,18 @@ function transformImports(content, options) {
10155
10204
  return `${prefix}${aliases.importAlias}${aliases.components}/types${suffix}`;
10156
10205
  }
10157
10206
  );
10207
+ result = result.replace(
10208
+ /(from\s+['"])\.\.\/\.\.\/hooks\/(\w+)(['"])/g,
10209
+ `$1${aliases.importAlias}${aliases.hooks}/$2$3`
10210
+ );
10211
+ result = result.replace(
10212
+ /(from\s+['"])\.\.\/\.\.\/utils\/(\w+(?:\/\w+)?)(['"])/g,
10213
+ `$1${aliases.importAlias}${aliases.utils}/$2$3`
10214
+ );
10215
+ result = result.replace(
10216
+ /(from\s+['"])\.\.\/\.\.\/utils(['"])/g,
10217
+ `$1${aliases.importAlias}${aliases.utils}$2`
10218
+ );
10158
10219
  result = result.replace(
10159
10220
  /(from\s+['"])\.\.\/(([A-Z]\w+)(\/[^'"]+)?)(['"])/g,
10160
10221
  (_match, prefix, _fullPath, dirName, subPath, suffix) => {
@@ -10165,18 +10226,6 @@ function transformImports(content, options) {
10165
10226
  return `${prefix}${aliases.importAlias}${aliases.ui}/${kebab}${suffix}`;
10166
10227
  }
10167
10228
  );
10168
- result = result.replace(
10169
- /(from\s+['"])(?:\.\.\/)+hooks\/(\w+)(['"])/g,
10170
- `$1${aliases.importAlias}${aliases.hooks}/$2$3`
10171
- );
10172
- result = result.replace(
10173
- /(from\s+['"])(?:\.\.\/)+utils\/(\w+(?:\/\w+)?)(['"])/g,
10174
- `$1${aliases.importAlias}${aliases.utils}/$2$3`
10175
- );
10176
- result = result.replace(
10177
- /(from\s+['"])(?:\.\.\/)+utils(['"])/g,
10178
- `$1${aliases.importAlias}${aliases.utils}$2`
10179
- );
10180
10229
  return result;
10181
10230
  }
10182
10231
  function normalizeExtensions(content, tsx) {
@@ -10230,16 +10279,17 @@ function writeRegistryItems(tree, options) {
10230
10279
  for (const item of tree.items) {
10231
10280
  const targetBaseDir = getTargetDir(item.type, aliases);
10232
10281
  for (const file of item.files) {
10233
- const fileName = basename(file.path);
10234
10282
  let targetPath;
10235
10283
  if (file.target) {
10236
10284
  targetPath = join(projectDir, file.target);
10237
10285
  } else if (item.type === "registry:ui" || item.type === "registry:component") {
10238
- targetPath = join(projectDir, targetBaseDir, item.name, fileName);
10239
- } else if (item.type === "registry:type") {
10286
+ targetPath = join(projectDir, targetBaseDir, item.name, basename(file.path));
10287
+ } else if (item.type === "registry:hook") {
10288
+ targetPath = join(projectDir, targetBaseDir, item.name, basename(file.path));
10289
+ } else if (file.path.includes("/")) {
10240
10290
  targetPath = join(projectDir, targetBaseDir, file.path);
10241
10291
  } else {
10242
- targetPath = join(projectDir, targetBaseDir, fileName);
10292
+ targetPath = join(projectDir, targetBaseDir, basename(file.path));
10243
10293
  }
10244
10294
  if (existsSync(targetPath) && !shouldOverwrite) {
10245
10295
  if (log) log(` Skipped (exists): ${targetPath}`);