@pandacss/token-dictionary 1.4.3 → 1.5.0

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.mts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as _pandacss_types from '@pandacss/types';
2
- import { Tokens, SemanticTokens, ThemeVariantsMap, Token as Token$1 } from '@pandacss/types';
2
+ import { Tokens, SemanticTokens, ThemeVariantsMap, ColorPaletteOptions, Token as Token$1 } from '@pandacss/types';
3
3
  import { CssVarOptions, CssVar } from '@pandacss/shared';
4
4
 
5
5
  interface ExtensionData {
@@ -101,6 +101,7 @@ interface TokenDictionaryOptions {
101
101
  themes?: ThemeVariantsMap | undefined;
102
102
  prefix?: string;
103
103
  hash?: boolean;
104
+ colorPalette?: ColorPaletteOptions;
104
105
  }
105
106
  interface TokenMiddleware {
106
107
  enforce?: EnforcePhase;
@@ -115,6 +116,7 @@ declare class TokenDictionary {
115
116
  init(): this;
116
117
  get prefix(): string | undefined;
117
118
  get hash(): boolean | undefined;
119
+ get colorPalette(): ColorPaletteOptions | undefined;
118
120
  getByName: (path: string) => Token | undefined;
119
121
  formatTokenName: (path: string[]) => string;
120
122
  formatCssVar: (path: string[], options: CssVarOptions) => CssVar;
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as _pandacss_types from '@pandacss/types';
2
- import { Tokens, SemanticTokens, ThemeVariantsMap, Token as Token$1 } from '@pandacss/types';
2
+ import { Tokens, SemanticTokens, ThemeVariantsMap, ColorPaletteOptions, Token as Token$1 } from '@pandacss/types';
3
3
  import { CssVarOptions, CssVar } from '@pandacss/shared';
4
4
 
5
5
  interface ExtensionData {
@@ -101,6 +101,7 @@ interface TokenDictionaryOptions {
101
101
  themes?: ThemeVariantsMap | undefined;
102
102
  prefix?: string;
103
103
  hash?: boolean;
104
+ colorPalette?: ColorPaletteOptions;
104
105
  }
105
106
  interface TokenMiddleware {
106
107
  enforce?: EnforcePhase;
@@ -115,6 +116,7 @@ declare class TokenDictionary {
115
116
  init(): this;
116
117
  get prefix(): string | undefined;
117
118
  get hash(): boolean | undefined;
119
+ get colorPalette(): ColorPaletteOptions | undefined;
118
120
  getByName: (path: string) => Token | undefined;
119
121
  formatTokenName: (path: string[]) => string;
120
122
  formatCssVar: (path: string[], options: CssVarOptions) => CssVar;
package/dist/index.js CHANGED
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
5
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
8
  var __export = (target, all) => {
7
9
  for (var name in all)
@@ -15,6 +17,14 @@ var __copyProps = (to, from, except, desc) => {
15
17
  }
16
18
  return to;
17
19
  };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
18
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
29
 
20
30
  // src/index.ts
@@ -351,6 +361,9 @@ var addPixelUnit = {
351
361
  var addVirtualPalette = {
352
362
  enforce: "post",
353
363
  transform(dictionary) {
364
+ const colorPaletteConfig = dictionary.colorPalette;
365
+ const enabled = colorPaletteConfig?.enabled ?? true;
366
+ if (!enabled) return;
354
367
  const tokens = dictionary.filter({ extensions: { category: "colors" } });
355
368
  const keys = /* @__PURE__ */ new Map();
356
369
  const colorPalettes = /* @__PURE__ */ new Map();
@@ -398,6 +411,7 @@ var middlewares = [addNegativeTokens, addVirtualPalette, removeEmptyTokens, addP
398
411
 
399
412
  // src/transform.ts
400
413
  var import_shared4 = require("@pandacss/shared");
414
+ var import_picomatch = __toESM(require("picomatch"));
401
415
  var import_ts_pattern2 = require("ts-pattern");
402
416
 
403
417
  // src/mini-svg-uri.ts
@@ -660,34 +674,43 @@ var addColorPalette = {
660
674
  return token.extensions.category === "colors" && !token.extensions.isVirtual;
661
675
  },
662
676
  transform(token, dict) {
663
- let tokenPathClone = [...token.path];
664
- tokenPathClone.pop();
665
- tokenPathClone.shift();
666
- if (tokenPathClone.length === 0) {
667
- const newPath = [...token.path];
668
- newPath.shift();
669
- tokenPathClone = newPath;
677
+ const colorPaletteConfig = dict.colorPalette;
678
+ const enabled = colorPaletteConfig?.enabled ?? true;
679
+ const include = colorPaletteConfig?.include;
680
+ const exclude = colorPaletteConfig?.exclude;
681
+ if (!enabled) return {};
682
+ let colorPath = token.path.slice(1, -1);
683
+ if (colorPath.length === 0) {
684
+ colorPath = token.path.slice(1);
685
+ if (colorPath.length === 0) {
686
+ return {};
687
+ }
670
688
  }
671
- if (tokenPathClone.length === 0) {
672
- return {};
689
+ const colorPathString = colorPath.join(".");
690
+ if (exclude?.length) {
691
+ const excludeMatchers = exclude.map((pattern) => (0, import_picomatch.default)(pattern));
692
+ if (excludeMatchers.some((matcher) => matcher(colorPathString))) {
693
+ return {};
694
+ }
695
+ }
696
+ if (include?.length) {
697
+ const includeMatchers = include.map((pattern) => (0, import_picomatch.default)(pattern));
698
+ if (!includeMatchers.some((matcher) => matcher(colorPathString))) {
699
+ return {};
700
+ }
701
+ }
702
+ const colorPaletteRoots = [];
703
+ for (let i = 0; i < colorPath.length; i++) {
704
+ colorPaletteRoots.push(colorPath.slice(0, i + 1));
705
+ }
706
+ const colorPaletteRoot = colorPath[0];
707
+ const colorPalette = dict.formatTokenName(colorPath);
708
+ const startIndex = token.path.indexOf(colorPaletteRoot) + 1;
709
+ const remainingPath = token.path.slice(startIndex);
710
+ const colorPaletteTokenKeys = [];
711
+ for (let i = 0; i < remainingPath.length; i++) {
712
+ colorPaletteTokenKeys.push(remainingPath.slice(i));
673
713
  }
674
- const colorPaletteRoots = tokenPathClone.reduce(
675
- (acc, _, i, arr) => {
676
- const next = arr.slice(0, i + 1);
677
- acc.push(next);
678
- return acc;
679
- },
680
- []
681
- );
682
- const colorPaletteRoot = tokenPathClone[0];
683
- const colorPalette = dict.formatTokenName(tokenPathClone);
684
- const colorPaletteTokenKeys = token.path.slice(token.path.indexOf(colorPaletteRoot) + 1).reduce(
685
- (acc, _, i, arr) => {
686
- acc.push(arr.slice(i));
687
- return acc;
688
- },
689
- []
690
- );
691
714
  if (colorPaletteTokenKeys.length === 0) {
692
715
  colorPaletteTokenKeys.push([""]);
693
716
  }
@@ -876,6 +899,9 @@ var TokenDictionary = class {
876
899
  get hash() {
877
900
  return this.options.hash;
878
901
  }
902
+ get colorPalette() {
903
+ return this.options.colorPalette;
904
+ }
879
905
  getByName = (path) => {
880
906
  return this.byName.get(path);
881
907
  };
package/dist/index.mjs CHANGED
@@ -328,6 +328,9 @@ var addPixelUnit = {
328
328
  var addVirtualPalette = {
329
329
  enforce: "post",
330
330
  transform(dictionary) {
331
+ const colorPaletteConfig = dictionary.colorPalette;
332
+ const enabled = colorPaletteConfig?.enabled ?? true;
333
+ if (!enabled) return;
331
334
  const tokens = dictionary.filter({ extensions: { category: "colors" } });
332
335
  const keys = /* @__PURE__ */ new Map();
333
336
  const colorPalettes = /* @__PURE__ */ new Map();
@@ -375,6 +378,7 @@ var middlewares = [addNegativeTokens, addVirtualPalette, removeEmptyTokens, addP
375
378
 
376
379
  // src/transform.ts
377
380
  import { isCssUnit, isString, PandaError as PandaError2 } from "@pandacss/shared";
381
+ import picomatch from "picomatch";
378
382
  import { P as P2, match } from "ts-pattern";
379
383
 
380
384
  // src/mini-svg-uri.ts
@@ -637,34 +641,43 @@ var addColorPalette = {
637
641
  return token.extensions.category === "colors" && !token.extensions.isVirtual;
638
642
  },
639
643
  transform(token, dict) {
640
- let tokenPathClone = [...token.path];
641
- tokenPathClone.pop();
642
- tokenPathClone.shift();
643
- if (tokenPathClone.length === 0) {
644
- const newPath = [...token.path];
645
- newPath.shift();
646
- tokenPathClone = newPath;
644
+ const colorPaletteConfig = dict.colorPalette;
645
+ const enabled = colorPaletteConfig?.enabled ?? true;
646
+ const include = colorPaletteConfig?.include;
647
+ const exclude = colorPaletteConfig?.exclude;
648
+ if (!enabled) return {};
649
+ let colorPath = token.path.slice(1, -1);
650
+ if (colorPath.length === 0) {
651
+ colorPath = token.path.slice(1);
652
+ if (colorPath.length === 0) {
653
+ return {};
654
+ }
647
655
  }
648
- if (tokenPathClone.length === 0) {
649
- return {};
656
+ const colorPathString = colorPath.join(".");
657
+ if (exclude?.length) {
658
+ const excludeMatchers = exclude.map((pattern) => picomatch(pattern));
659
+ if (excludeMatchers.some((matcher) => matcher(colorPathString))) {
660
+ return {};
661
+ }
662
+ }
663
+ if (include?.length) {
664
+ const includeMatchers = include.map((pattern) => picomatch(pattern));
665
+ if (!includeMatchers.some((matcher) => matcher(colorPathString))) {
666
+ return {};
667
+ }
668
+ }
669
+ const colorPaletteRoots = [];
670
+ for (let i = 0; i < colorPath.length; i++) {
671
+ colorPaletteRoots.push(colorPath.slice(0, i + 1));
672
+ }
673
+ const colorPaletteRoot = colorPath[0];
674
+ const colorPalette = dict.formatTokenName(colorPath);
675
+ const startIndex = token.path.indexOf(colorPaletteRoot) + 1;
676
+ const remainingPath = token.path.slice(startIndex);
677
+ const colorPaletteTokenKeys = [];
678
+ for (let i = 0; i < remainingPath.length; i++) {
679
+ colorPaletteTokenKeys.push(remainingPath.slice(i));
650
680
  }
651
- const colorPaletteRoots = tokenPathClone.reduce(
652
- (acc, _, i, arr) => {
653
- const next = arr.slice(0, i + 1);
654
- acc.push(next);
655
- return acc;
656
- },
657
- []
658
- );
659
- const colorPaletteRoot = tokenPathClone[0];
660
- const colorPalette = dict.formatTokenName(tokenPathClone);
661
- const colorPaletteTokenKeys = token.path.slice(token.path.indexOf(colorPaletteRoot) + 1).reduce(
662
- (acc, _, i, arr) => {
663
- acc.push(arr.slice(i));
664
- return acc;
665
- },
666
- []
667
- );
668
681
  if (colorPaletteTokenKeys.length === 0) {
669
682
  colorPaletteTokenKeys.push([""]);
670
683
  }
@@ -853,6 +866,9 @@ var TokenDictionary = class {
853
866
  get hash() {
854
867
  return this.options.hash;
855
868
  }
869
+ get colorPalette() {
870
+ return this.options.colorPalette;
871
+ }
856
872
  getByName = (path) => {
857
873
  return this.byName.get(path);
858
874
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pandacss/token-dictionary",
3
- "version": "1.4.3",
3
+ "version": "1.5.0",
4
4
  "description": "Common error messages for css panda",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -33,10 +33,14 @@
33
33
  "dist"
34
34
  ],
35
35
  "dependencies": {
36
+ "picomatch": "^4.0.0",
36
37
  "ts-pattern": "5.8.0",
37
- "@pandacss/logger": "^1.4.3",
38
- "@pandacss/shared": "1.4.3",
39
- "@pandacss/types": "1.4.3"
38
+ "@pandacss/logger": "^1.5.0",
39
+ "@pandacss/shared": "1.5.0",
40
+ "@pandacss/types": "1.5.0"
41
+ },
42
+ "devDependencies": {
43
+ "@types/picomatch": "4.0.2"
40
44
  },
41
45
  "scripts": {
42
46
  "build": "tsup src/index.ts --format=esm,cjs --dts",