@pandacss/config 0.37.0 → 0.37.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
@@ -600,7 +600,7 @@ async function getResolvedConfig(config, cwd) {
600
600
 
601
601
  // src/resolve-config.ts
602
602
  var import_logger4 = require("@pandacss/logger");
603
- var import_shared9 = require("@pandacss/shared");
603
+ var import_shared10 = require("@pandacss/shared");
604
604
 
605
605
  // src/bundled-preset.ts
606
606
  var import_preset_base = require("@pandacss/preset-base");
@@ -618,21 +618,21 @@ var getBundledPreset = (preset) => {
618
618
 
619
619
  // src/validate-config.ts
620
620
  var import_logger3 = require("@pandacss/logger");
621
- var import_shared8 = require("@pandacss/shared");
621
+ var import_shared9 = require("@pandacss/shared");
622
622
 
623
623
  // src/validation/validate-artifact.ts
624
624
  var validateArtifactNames = (names, addError) => {
625
625
  names.recipes.forEach((recipeName) => {
626
626
  if (names.slotRecipes.has(recipeName)) {
627
- addError("recipes", `This recipe name is already used in \`config.theme.slotRecipes\`: ${recipeName}`);
627
+ addError("recipes", `This recipe name is already used in \`theme.slotRecipes\`: ${recipeName}`);
628
628
  }
629
629
  if (names.patterns.has(recipeName)) {
630
- addError("recipes", `This recipe name is already used in \`config.patterns\`: \`${recipeName}\``);
630
+ addError("recipes", `This recipe name is already used in \`patterns\`: \`${recipeName}\``);
631
631
  }
632
632
  });
633
633
  names.slotRecipes.forEach((recipeName) => {
634
634
  if (names.patterns.has(recipeName)) {
635
- addError("recipes", `This recipe name is already used in \`config.patterns\`: ${recipeName}`);
635
+ addError("recipes", `This recipe name is already used in \`patterns\`: ${recipeName}`);
636
636
  }
637
637
  });
638
638
  };
@@ -704,16 +704,42 @@ var validateRecipes = (options) => {
704
704
  };
705
705
 
706
706
  // src/validation/validate-tokens.ts
707
- var import_shared7 = require("@pandacss/shared");
707
+ var import_shared8 = require("@pandacss/shared");
708
708
 
709
709
  // src/validation/utils.ts
710
+ var import_shared7 = require("@pandacss/shared");
711
+ var REFERENCE_REGEX = /({([^}]*)})/g;
712
+ var curlyBracketRegex = /[{}]/g;
710
713
  var isValidToken = (token) => Object.hasOwnProperty.call(token, "value");
711
- var isTokenReference = (value) => typeof value === "string" && value.startsWith("{");
714
+ var isTokenReference = (value) => typeof value === "string" && REFERENCE_REGEX.test(value);
712
715
  var formatPath = (path2) => path2;
713
716
  var SEP = ".";
717
+ function getReferences(value) {
718
+ if (typeof value !== "string")
719
+ return [];
720
+ const matches = value.match(REFERENCE_REGEX);
721
+ if (!matches)
722
+ return [];
723
+ return matches.map((match) => match.replace(curlyBracketRegex, "")).map((value2) => {
724
+ return value2.trim().split("/")[0];
725
+ });
726
+ }
727
+ var serializeTokenValue = (value) => {
728
+ if ((0, import_shared7.isString)(value)) {
729
+ return value;
730
+ }
731
+ if ((0, import_shared7.isObject)(value)) {
732
+ return Object.values(value).map((v) => serializeTokenValue(v)).join(" ");
733
+ }
734
+ if (Array.isArray(value)) {
735
+ return value.map((v) => serializeTokenValue(v)).join(" ");
736
+ }
737
+ return value.toString();
738
+ };
714
739
 
715
740
  // src/validation/validate-token-references.ts
716
- var validateTokenReferences = (valueAtPath, refsByPath, addError) => {
741
+ var validateTokenReferences = (props) => {
742
+ const { valueAtPath, refsByPath, addError, typeByPath } = props;
717
743
  refsByPath.forEach((refs, path2) => {
718
744
  if (refs.has(path2)) {
719
745
  addError("tokens", `Self token reference: \`${path2}\``);
@@ -727,7 +753,8 @@ var validateTokenReferences = (valueAtPath, refsByPath, addError) => {
727
753
  }
728
754
  const value = valueAtPath.get(currentPath);
729
755
  if (!value) {
730
- addError("tokens", `Missing token: \`${currentPath}\` used in \`config.semanticTokens.${path2}\``);
756
+ const configKey = typeByPath.get(path2);
757
+ addError("tokens", `Missing token: \`${currentPath}\` used in \`theme.${configKey}.${path2}\``);
731
758
  }
732
759
  if (isTokenReference(value) && !refsByPath.has(value)) {
733
760
  addError("tokens", `Unknown token reference: \`${currentPath}\` used in \`${value}\``);
@@ -758,10 +785,10 @@ var validateTokens = (options) => {
758
785
  } = options;
759
786
  if (!theme)
760
787
  return;
761
- const { tokenNames, semanticTokenNames, valueAtPath, refsByPath } = tokens2;
788
+ const { tokenNames, semanticTokenNames, valueAtPath, refsByPath, typeByPath } = tokens2;
762
789
  if (theme.tokens) {
763
790
  const tokenPaths = /* @__PURE__ */ new Set();
764
- (0, import_shared7.walkObject)(
791
+ (0, import_shared8.walkObject)(
765
792
  theme.tokens,
766
793
  (value, paths) => {
767
794
  const path2 = paths.join(SEP);
@@ -777,9 +804,10 @@ var validateTokens = (options) => {
777
804
  }
778
805
  );
779
806
  tokenPaths.forEach((path2) => {
780
- const value = valueAtPath.get(path2);
807
+ const itemValue = valueAtPath.get(path2);
781
808
  const formattedPath = formatPath(path2);
782
- if (!isValidToken(value)) {
809
+ typeByPath.set(formattedPath, "tokens");
810
+ if (!isValidToken(itemValue)) {
783
811
  addError("tokens", `Token must contain 'value': \`theme.tokens.${formattedPath}\``);
784
812
  return;
785
813
  }
@@ -787,14 +815,21 @@ var validateTokens = (options) => {
787
815
  addError("tokens", `Token key must not contain spaces: \`theme.tokens.${formattedPath}\``);
788
816
  return;
789
817
  }
790
- if (isTokenReference(value)) {
818
+ const valueStr = serializeTokenValue(itemValue.value || itemValue);
819
+ if (isTokenReference(valueStr)) {
791
820
  refsByPath.set(formattedPath, /* @__PURE__ */ new Set([]));
792
821
  }
822
+ const references = refsByPath.get(formattedPath);
823
+ if (!references)
824
+ return;
825
+ getReferences(valueStr).forEach((reference) => {
826
+ references.add(reference);
827
+ });
793
828
  });
794
829
  }
795
830
  if (theme.semanticTokens) {
796
831
  const tokenPaths = /* @__PURE__ */ new Set();
797
- (0, import_shared7.walkObject)(
832
+ (0, import_shared8.walkObject)(
798
833
  theme.semanticTokens,
799
834
  (value, paths) => {
800
835
  const path2 = paths.join(SEP);
@@ -806,22 +841,25 @@ var validateTokens = (options) => {
806
841
  }
807
842
  if (!isValidToken(value))
808
843
  return;
809
- (0, import_shared7.walkObject)(value, (itemValue, paths2) => {
844
+ (0, import_shared8.walkObject)(value, (itemValue, paths2) => {
810
845
  const valuePath = paths2.join(SEP);
811
846
  const formattedPath = formatPath(path2);
847
+ typeByPath.set(formattedPath, "semanticTokens");
812
848
  const fullPath = formattedPath + "." + paths2.join(SEP);
813
849
  if (valuePath.includes("value" + SEP + "value")) {
814
850
  addError("tokens", `You used \`value\` twice resulting in an invalid token \`theme.tokens.${fullPath}\``);
815
851
  }
816
- if (isTokenReference(itemValue)) {
852
+ const valueStr = serializeTokenValue(itemValue.value || itemValue);
853
+ if (isTokenReference(valueStr)) {
817
854
  if (!refsByPath.has(formattedPath)) {
818
855
  refsByPath.set(formattedPath, /* @__PURE__ */ new Set());
819
856
  }
820
857
  const references = refsByPath.get(formattedPath);
821
858
  if (!references)
822
859
  return;
823
- const reference = itemValue.slice(1, -1);
824
- references.add(reference);
860
+ getReferences(valueStr).forEach((reference) => {
861
+ references.add(reference);
862
+ });
825
863
  }
826
864
  });
827
865
  },
@@ -836,12 +874,12 @@ var validateTokens = (options) => {
836
874
  addError("tokens", `Token key must not contain spaces: \`theme.tokens.${formattedPath}\``);
837
875
  return;
838
876
  }
839
- if (!(0, import_shared7.isObject)(value) && !path2.includes("value")) {
877
+ if (!(0, import_shared8.isObject)(value) && !path2.includes("value")) {
840
878
  addError("tokens", `Token must contain 'value': \`theme.semanticTokens.${formattedPath}\``);
841
879
  }
842
880
  });
843
- validateTokenReferences(valueAtPath, refsByPath, addError);
844
881
  }
882
+ validateTokenReferences({ valueAtPath, refsByPath, addError, typeByPath });
845
883
  };
846
884
 
847
885
  // src/validate-config.ts
@@ -863,7 +901,8 @@ var validateConfig = (config) => {
863
901
  tokenNames: /* @__PURE__ */ new Set(),
864
902
  semanticTokenNames: /* @__PURE__ */ new Set(),
865
903
  valueAtPath: /* @__PURE__ */ new Map(),
866
- refsByPath: /* @__PURE__ */ new Map()
904
+ refsByPath: /* @__PURE__ */ new Map(),
905
+ typeByPath: /* @__PURE__ */ new Map()
867
906
  };
868
907
  if (config.theme) {
869
908
  validateTokens({ config, tokens: tokens2, addError });
@@ -876,7 +915,7 @@ var validateConfig = (config) => {
876
915
  ${Array.from(warnings).map((err) => "- " + err).join("\n")}
877
916
  `;
878
917
  if (config.validation === "error") {
879
- throw new import_shared8.PandaError("CONFIG_ERROR", errors);
918
+ throw new import_shared9.PandaError("CONFIG_ERROR", errors);
880
919
  }
881
920
  import_logger3.logger.warn("config", errors);
882
921
  return warnings;
@@ -885,8 +924,8 @@ ${Array.from(warnings).map((err) => "- " + err).join("\n")}
885
924
 
886
925
  // src/resolve-config.ts
887
926
  var hookUtils = {
888
- omit: import_shared9.omit,
889
- traverse: import_shared9.traverse
927
+ omit: import_shared10.omit,
928
+ traverse: import_shared10.traverse
890
929
  };
891
930
  async function resolveConfig(result, cwd) {
892
931
  const presets = /* @__PURE__ */ new Set();
@@ -922,8 +961,8 @@ async function resolveConfig(result, cwd) {
922
961
  loadConfigResult.config = result2;
923
962
  }
924
963
  }
925
- const serialized = (0, import_shared9.stringifyJson)(loadConfigResult.config);
926
- const deserialize = () => (0, import_shared9.parseJson)(serialized);
964
+ const serialized = (0, import_shared10.stringifyJson)(loadConfigResult.config);
965
+ const deserialize = () => (0, import_shared10.parseJson)(serialized);
927
966
  return { ...loadConfigResult, serialized, deserialize, hooks };
928
967
  }
929
968
 
package/dist/index.mjs CHANGED
@@ -238,15 +238,15 @@ import { PandaError as PandaError3 } from "@pandacss/shared";
238
238
  var validateArtifactNames = (names, addError) => {
239
239
  names.recipes.forEach((recipeName) => {
240
240
  if (names.slotRecipes.has(recipeName)) {
241
- addError("recipes", `This recipe name is already used in \`config.theme.slotRecipes\`: ${recipeName}`);
241
+ addError("recipes", `This recipe name is already used in \`theme.slotRecipes\`: ${recipeName}`);
242
242
  }
243
243
  if (names.patterns.has(recipeName)) {
244
- addError("recipes", `This recipe name is already used in \`config.patterns\`: \`${recipeName}\``);
244
+ addError("recipes", `This recipe name is already used in \`patterns\`: \`${recipeName}\``);
245
245
  }
246
246
  });
247
247
  names.slotRecipes.forEach((recipeName) => {
248
248
  if (names.patterns.has(recipeName)) {
249
- addError("recipes", `This recipe name is already used in \`config.patterns\`: ${recipeName}`);
249
+ addError("recipes", `This recipe name is already used in \`patterns\`: ${recipeName}`);
250
250
  }
251
251
  });
252
252
  };
@@ -318,16 +318,42 @@ var validateRecipes = (options) => {
318
318
  };
319
319
 
320
320
  // src/validation/validate-tokens.ts
321
- import { isObject, walkObject } from "@pandacss/shared";
321
+ import { isObject as isObject2, walkObject } from "@pandacss/shared";
322
322
 
323
323
  // src/validation/utils.ts
324
+ import { isObject, isString as isString2 } from "@pandacss/shared";
325
+ var REFERENCE_REGEX = /({([^}]*)})/g;
326
+ var curlyBracketRegex = /[{}]/g;
324
327
  var isValidToken = (token) => Object.hasOwnProperty.call(token, "value");
325
- var isTokenReference = (value) => typeof value === "string" && value.startsWith("{");
328
+ var isTokenReference = (value) => typeof value === "string" && REFERENCE_REGEX.test(value);
326
329
  var formatPath = (path2) => path2;
327
330
  var SEP = ".";
331
+ function getReferences(value) {
332
+ if (typeof value !== "string")
333
+ return [];
334
+ const matches = value.match(REFERENCE_REGEX);
335
+ if (!matches)
336
+ return [];
337
+ return matches.map((match) => match.replace(curlyBracketRegex, "")).map((value2) => {
338
+ return value2.trim().split("/")[0];
339
+ });
340
+ }
341
+ var serializeTokenValue = (value) => {
342
+ if (isString2(value)) {
343
+ return value;
344
+ }
345
+ if (isObject(value)) {
346
+ return Object.values(value).map((v) => serializeTokenValue(v)).join(" ");
347
+ }
348
+ if (Array.isArray(value)) {
349
+ return value.map((v) => serializeTokenValue(v)).join(" ");
350
+ }
351
+ return value.toString();
352
+ };
328
353
 
329
354
  // src/validation/validate-token-references.ts
330
- var validateTokenReferences = (valueAtPath, refsByPath, addError) => {
355
+ var validateTokenReferences = (props) => {
356
+ const { valueAtPath, refsByPath, addError, typeByPath } = props;
331
357
  refsByPath.forEach((refs, path2) => {
332
358
  if (refs.has(path2)) {
333
359
  addError("tokens", `Self token reference: \`${path2}\``);
@@ -341,7 +367,8 @@ var validateTokenReferences = (valueAtPath, refsByPath, addError) => {
341
367
  }
342
368
  const value = valueAtPath.get(currentPath);
343
369
  if (!value) {
344
- addError("tokens", `Missing token: \`${currentPath}\` used in \`config.semanticTokens.${path2}\``);
370
+ const configKey = typeByPath.get(path2);
371
+ addError("tokens", `Missing token: \`${currentPath}\` used in \`theme.${configKey}.${path2}\``);
345
372
  }
346
373
  if (isTokenReference(value) && !refsByPath.has(value)) {
347
374
  addError("tokens", `Unknown token reference: \`${currentPath}\` used in \`${value}\``);
@@ -372,7 +399,7 @@ var validateTokens = (options) => {
372
399
  } = options;
373
400
  if (!theme)
374
401
  return;
375
- const { tokenNames, semanticTokenNames, valueAtPath, refsByPath } = tokens;
402
+ const { tokenNames, semanticTokenNames, valueAtPath, refsByPath, typeByPath } = tokens;
376
403
  if (theme.tokens) {
377
404
  const tokenPaths = /* @__PURE__ */ new Set();
378
405
  walkObject(
@@ -391,9 +418,10 @@ var validateTokens = (options) => {
391
418
  }
392
419
  );
393
420
  tokenPaths.forEach((path2) => {
394
- const value = valueAtPath.get(path2);
421
+ const itemValue = valueAtPath.get(path2);
395
422
  const formattedPath = formatPath(path2);
396
- if (!isValidToken(value)) {
423
+ typeByPath.set(formattedPath, "tokens");
424
+ if (!isValidToken(itemValue)) {
397
425
  addError("tokens", `Token must contain 'value': \`theme.tokens.${formattedPath}\``);
398
426
  return;
399
427
  }
@@ -401,9 +429,16 @@ var validateTokens = (options) => {
401
429
  addError("tokens", `Token key must not contain spaces: \`theme.tokens.${formattedPath}\``);
402
430
  return;
403
431
  }
404
- if (isTokenReference(value)) {
432
+ const valueStr = serializeTokenValue(itemValue.value || itemValue);
433
+ if (isTokenReference(valueStr)) {
405
434
  refsByPath.set(formattedPath, /* @__PURE__ */ new Set([]));
406
435
  }
436
+ const references = refsByPath.get(formattedPath);
437
+ if (!references)
438
+ return;
439
+ getReferences(valueStr).forEach((reference) => {
440
+ references.add(reference);
441
+ });
407
442
  });
408
443
  }
409
444
  if (theme.semanticTokens) {
@@ -423,19 +458,22 @@ var validateTokens = (options) => {
423
458
  walkObject(value, (itemValue, paths2) => {
424
459
  const valuePath = paths2.join(SEP);
425
460
  const formattedPath = formatPath(path2);
461
+ typeByPath.set(formattedPath, "semanticTokens");
426
462
  const fullPath = formattedPath + "." + paths2.join(SEP);
427
463
  if (valuePath.includes("value" + SEP + "value")) {
428
464
  addError("tokens", `You used \`value\` twice resulting in an invalid token \`theme.tokens.${fullPath}\``);
429
465
  }
430
- if (isTokenReference(itemValue)) {
466
+ const valueStr = serializeTokenValue(itemValue.value || itemValue);
467
+ if (isTokenReference(valueStr)) {
431
468
  if (!refsByPath.has(formattedPath)) {
432
469
  refsByPath.set(formattedPath, /* @__PURE__ */ new Set());
433
470
  }
434
471
  const references = refsByPath.get(formattedPath);
435
472
  if (!references)
436
473
  return;
437
- const reference = itemValue.slice(1, -1);
438
- references.add(reference);
474
+ getReferences(valueStr).forEach((reference) => {
475
+ references.add(reference);
476
+ });
439
477
  }
440
478
  });
441
479
  },
@@ -450,12 +488,12 @@ var validateTokens = (options) => {
450
488
  addError("tokens", `Token key must not contain spaces: \`theme.tokens.${formattedPath}\``);
451
489
  return;
452
490
  }
453
- if (!isObject(value) && !path2.includes("value")) {
491
+ if (!isObject2(value) && !path2.includes("value")) {
454
492
  addError("tokens", `Token must contain 'value': \`theme.semanticTokens.${formattedPath}\``);
455
493
  }
456
494
  });
457
- validateTokenReferences(valueAtPath, refsByPath, addError);
458
495
  }
496
+ validateTokenReferences({ valueAtPath, refsByPath, addError, typeByPath });
459
497
  };
460
498
 
461
499
  // src/validate-config.ts
@@ -477,7 +515,8 @@ var validateConfig = (config) => {
477
515
  tokenNames: /* @__PURE__ */ new Set(),
478
516
  semanticTokenNames: /* @__PURE__ */ new Set(),
479
517
  valueAtPath: /* @__PURE__ */ new Map(),
480
- refsByPath: /* @__PURE__ */ new Map()
518
+ refsByPath: /* @__PURE__ */ new Map(),
519
+ typeByPath: /* @__PURE__ */ new Map()
481
520
  };
482
521
  if (config.theme) {
483
522
  validateTokens({ config, tokens, addError });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pandacss/config",
3
- "version": "0.37.0",
3
+ "version": "0.37.1",
4
4
  "description": "Find and load panda config",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -73,11 +73,11 @@
73
73
  "merge-anything": "5.1.7",
74
74
  "microdiff": "1.3.2",
75
75
  "typescript": "5.3.3",
76
- "@pandacss/logger": "0.37.0",
77
- "@pandacss/preset-base": "0.37.0",
78
- "@pandacss/preset-panda": "0.37.0",
79
- "@pandacss/shared": "0.37.0",
80
- "@pandacss/types": "0.37.0"
76
+ "@pandacss/logger": "0.37.1",
77
+ "@pandacss/preset-base": "0.37.1",
78
+ "@pandacss/preset-panda": "0.37.1",
79
+ "@pandacss/shared": "0.37.1",
80
+ "@pandacss/types": "0.37.1"
81
81
  },
82
82
  "devDependencies": {
83
83
  "pkg-types": "1.0.3"