@pandacss/token-dictionary 0.33.0 → 0.34.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 +9 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +51 -1
- package/dist/index.mjs +51 -1
- package/package.json +4 -4
package/dist/index.d.mts
CHANGED
|
@@ -130,6 +130,15 @@ declare class TokenDictionary {
|
|
|
130
130
|
filter(pattern: Partial<Token> | ((token: Token) => boolean)): Token[];
|
|
131
131
|
addConditionalTokens(): this;
|
|
132
132
|
expandTokenReferences(): this;
|
|
133
|
+
colorMix: (value: string, tokenFn: (path: string) => string) => {
|
|
134
|
+
invalid: boolean;
|
|
135
|
+
value: string;
|
|
136
|
+
color?: undefined;
|
|
137
|
+
} | {
|
|
138
|
+
invalid: boolean;
|
|
139
|
+
color: string;
|
|
140
|
+
value: string;
|
|
141
|
+
};
|
|
133
142
|
/**
|
|
134
143
|
* Expand token references to their CSS variable
|
|
135
144
|
*/
|
package/dist/index.d.ts
CHANGED
|
@@ -130,6 +130,15 @@ declare class TokenDictionary {
|
|
|
130
130
|
filter(pattern: Partial<Token> | ((token: Token) => boolean)): Token[];
|
|
131
131
|
addConditionalTokens(): this;
|
|
132
132
|
expandTokenReferences(): this;
|
|
133
|
+
colorMix: (value: string, tokenFn: (path: string) => string) => {
|
|
134
|
+
invalid: boolean;
|
|
135
|
+
value: string;
|
|
136
|
+
color?: undefined;
|
|
137
|
+
} | {
|
|
138
|
+
invalid: boolean;
|
|
139
|
+
color: string;
|
|
140
|
+
value: string;
|
|
141
|
+
};
|
|
133
142
|
/**
|
|
134
143
|
* Expand token references to their CSS variable
|
|
135
144
|
*/
|
package/dist/index.js
CHANGED
|
@@ -586,6 +586,25 @@ var transformAssets = {
|
|
|
586
586
|
return (0, import_ts_pattern2.match)(raw).with(import_ts_pattern2.P.string, (value) => value).with({ type: "url" }, ({ value }) => `url("${value}")`).with({ type: "svg" }, ({ value }) => `url("${svgToDataUri(value)}")`).exhaustive();
|
|
587
587
|
}
|
|
588
588
|
};
|
|
589
|
+
var transformColorMix = {
|
|
590
|
+
name: "tokens/color-mix",
|
|
591
|
+
match: (token) => {
|
|
592
|
+
return token.extensions.category === "colors" && token.value.includes("/");
|
|
593
|
+
},
|
|
594
|
+
transform(token, dict) {
|
|
595
|
+
return expandReferences(token.value, (path) => {
|
|
596
|
+
const tokenFn = (tokenPath) => {
|
|
597
|
+
const token2 = dict.getByName(tokenPath);
|
|
598
|
+
return token2?.extensions.varRef;
|
|
599
|
+
};
|
|
600
|
+
const mix = dict.colorMix(path, tokenFn);
|
|
601
|
+
if (mix.invalid) {
|
|
602
|
+
throw new Error("Invalid color mix at " + path + ": " + mix.value);
|
|
603
|
+
}
|
|
604
|
+
return mix.value;
|
|
605
|
+
});
|
|
606
|
+
}
|
|
607
|
+
};
|
|
589
608
|
var addCssVariables = {
|
|
590
609
|
type: "extensions",
|
|
591
610
|
name: "tokens/css-var",
|
|
@@ -668,6 +687,8 @@ var transforms = [
|
|
|
668
687
|
transformBorders,
|
|
669
688
|
transformAssets,
|
|
670
689
|
addCssVariables,
|
|
690
|
+
transformColorMix,
|
|
691
|
+
// depends on `addCssVariables`
|
|
671
692
|
addConditionalCssVariables,
|
|
672
693
|
addColorPalette
|
|
673
694
|
];
|
|
@@ -896,11 +917,40 @@ var TokenDictionary = class {
|
|
|
896
917
|
});
|
|
897
918
|
return this;
|
|
898
919
|
}
|
|
920
|
+
colorMix = (value, tokenFn) => {
|
|
921
|
+
if (!value || typeof value !== "string")
|
|
922
|
+
return { invalid: true, value };
|
|
923
|
+
const [colorPath, rawOpacity] = value.split("/");
|
|
924
|
+
if (!colorPath || !rawOpacity) {
|
|
925
|
+
return { invalid: true, value: colorPath };
|
|
926
|
+
}
|
|
927
|
+
const colorToken = tokenFn(colorPath);
|
|
928
|
+
const opacityToken = this.getByName(`opacity.${rawOpacity}`)?.value;
|
|
929
|
+
if (!opacityToken && isNaN(Number(rawOpacity))) {
|
|
930
|
+
return { invalid: true, value: colorPath };
|
|
931
|
+
}
|
|
932
|
+
const percent = opacityToken ? Number(opacityToken) * 100 + "%" : `${rawOpacity}%`;
|
|
933
|
+
const color = colorToken ?? colorPath;
|
|
934
|
+
return {
|
|
935
|
+
invalid: false,
|
|
936
|
+
color,
|
|
937
|
+
value: `color-mix(in srgb, ${color} ${percent}, transparent)`
|
|
938
|
+
};
|
|
939
|
+
};
|
|
899
940
|
/**
|
|
900
941
|
* Expand token references to their CSS variable
|
|
901
942
|
*/
|
|
902
943
|
expandReferenceInValue(value) {
|
|
903
|
-
return expandReferences(value, (path) =>
|
|
944
|
+
return expandReferences(value, (path) => {
|
|
945
|
+
if (path.includes("/")) {
|
|
946
|
+
const mix = this.colorMix(path, this.view.get.bind(this.view));
|
|
947
|
+
if (mix.invalid) {
|
|
948
|
+
throw new Error("Invalid color mix at " + path + ": " + mix.value);
|
|
949
|
+
}
|
|
950
|
+
return mix.value;
|
|
951
|
+
}
|
|
952
|
+
return this.view.get(path);
|
|
953
|
+
});
|
|
904
954
|
}
|
|
905
955
|
/**
|
|
906
956
|
* Resolve token references to their actual raw value
|
package/dist/index.mjs
CHANGED
|
@@ -566,6 +566,25 @@ var transformAssets = {
|
|
|
566
566
|
return match(raw).with(P2.string, (value) => value).with({ type: "url" }, ({ value }) => `url("${value}")`).with({ type: "svg" }, ({ value }) => `url("${svgToDataUri(value)}")`).exhaustive();
|
|
567
567
|
}
|
|
568
568
|
};
|
|
569
|
+
var transformColorMix = {
|
|
570
|
+
name: "tokens/color-mix",
|
|
571
|
+
match: (token) => {
|
|
572
|
+
return token.extensions.category === "colors" && token.value.includes("/");
|
|
573
|
+
},
|
|
574
|
+
transform(token, dict) {
|
|
575
|
+
return expandReferences(token.value, (path) => {
|
|
576
|
+
const tokenFn = (tokenPath) => {
|
|
577
|
+
const token2 = dict.getByName(tokenPath);
|
|
578
|
+
return token2?.extensions.varRef;
|
|
579
|
+
};
|
|
580
|
+
const mix = dict.colorMix(path, tokenFn);
|
|
581
|
+
if (mix.invalid) {
|
|
582
|
+
throw new Error("Invalid color mix at " + path + ": " + mix.value);
|
|
583
|
+
}
|
|
584
|
+
return mix.value;
|
|
585
|
+
});
|
|
586
|
+
}
|
|
587
|
+
};
|
|
569
588
|
var addCssVariables = {
|
|
570
589
|
type: "extensions",
|
|
571
590
|
name: "tokens/css-var",
|
|
@@ -648,6 +667,8 @@ var transforms = [
|
|
|
648
667
|
transformBorders,
|
|
649
668
|
transformAssets,
|
|
650
669
|
addCssVariables,
|
|
670
|
+
transformColorMix,
|
|
671
|
+
// depends on `addCssVariables`
|
|
651
672
|
addConditionalCssVariables,
|
|
652
673
|
addColorPalette
|
|
653
674
|
];
|
|
@@ -876,11 +897,40 @@ var TokenDictionary = class {
|
|
|
876
897
|
});
|
|
877
898
|
return this;
|
|
878
899
|
}
|
|
900
|
+
colorMix = (value, tokenFn) => {
|
|
901
|
+
if (!value || typeof value !== "string")
|
|
902
|
+
return { invalid: true, value };
|
|
903
|
+
const [colorPath, rawOpacity] = value.split("/");
|
|
904
|
+
if (!colorPath || !rawOpacity) {
|
|
905
|
+
return { invalid: true, value: colorPath };
|
|
906
|
+
}
|
|
907
|
+
const colorToken = tokenFn(colorPath);
|
|
908
|
+
const opacityToken = this.getByName(`opacity.${rawOpacity}`)?.value;
|
|
909
|
+
if (!opacityToken && isNaN(Number(rawOpacity))) {
|
|
910
|
+
return { invalid: true, value: colorPath };
|
|
911
|
+
}
|
|
912
|
+
const percent = opacityToken ? Number(opacityToken) * 100 + "%" : `${rawOpacity}%`;
|
|
913
|
+
const color = colorToken ?? colorPath;
|
|
914
|
+
return {
|
|
915
|
+
invalid: false,
|
|
916
|
+
color,
|
|
917
|
+
value: `color-mix(in srgb, ${color} ${percent}, transparent)`
|
|
918
|
+
};
|
|
919
|
+
};
|
|
879
920
|
/**
|
|
880
921
|
* Expand token references to their CSS variable
|
|
881
922
|
*/
|
|
882
923
|
expandReferenceInValue(value) {
|
|
883
|
-
return expandReferences(value, (path) =>
|
|
924
|
+
return expandReferences(value, (path) => {
|
|
925
|
+
if (path.includes("/")) {
|
|
926
|
+
const mix = this.colorMix(path, this.view.get.bind(this.view));
|
|
927
|
+
if (mix.invalid) {
|
|
928
|
+
throw new Error("Invalid color mix at " + path + ": " + mix.value);
|
|
929
|
+
}
|
|
930
|
+
return mix.value;
|
|
931
|
+
}
|
|
932
|
+
return this.view.get(path);
|
|
933
|
+
});
|
|
884
934
|
}
|
|
885
935
|
/**
|
|
886
936
|
* Resolve token references to their actual raw value
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pandacss/token-dictionary",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.34.0",
|
|
4
4
|
"description": "Common error messages for css panda",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -33,9 +33,9 @@
|
|
|
33
33
|
],
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"ts-pattern": "5.0.8",
|
|
36
|
-
"@pandacss/logger": "^0.
|
|
37
|
-
"@pandacss/shared": "0.
|
|
38
|
-
"@pandacss/types": "0.
|
|
36
|
+
"@pandacss/logger": "^0.34.0",
|
|
37
|
+
"@pandacss/shared": "0.34.0",
|
|
38
|
+
"@pandacss/types": "0.34.0"
|
|
39
39
|
},
|
|
40
40
|
"scripts": {
|
|
41
41
|
"build": "tsup src/index.ts --format=esm,cjs --dts",
|