@pandacss/token-dictionary 0.32.1 → 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 +75 -16
- package/dist/index.mjs +75 -16
- 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
|
@@ -583,7 +583,26 @@ var transformAssets = {
|
|
|
583
583
|
match: (token) => token.extensions.category === "assets",
|
|
584
584
|
transform(token) {
|
|
585
585
|
const raw = token.value;
|
|
586
|
-
return (0, import_ts_pattern2.match)(raw).with(import_ts_pattern2.P.string, (value) => value).with({ type: "url" }, ({ value }) => `url(
|
|
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
|
+
}
|
|
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
|
+
});
|
|
587
606
|
}
|
|
588
607
|
};
|
|
589
608
|
var addCssVariables = {
|
|
@@ -633,17 +652,23 @@ var addColorPalette = {
|
|
|
633
652
|
if (tokenPathClone.length === 0) {
|
|
634
653
|
return {};
|
|
635
654
|
}
|
|
636
|
-
const colorPaletteRoots = tokenPathClone.reduce(
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
655
|
+
const colorPaletteRoots = tokenPathClone.reduce(
|
|
656
|
+
(acc, _, i, arr) => {
|
|
657
|
+
const next = arr.slice(0, i + 1);
|
|
658
|
+
acc.push(next);
|
|
659
|
+
return acc;
|
|
660
|
+
},
|
|
661
|
+
[]
|
|
662
|
+
);
|
|
641
663
|
const colorPaletteRoot = tokenPathClone[0];
|
|
642
664
|
const colorPalette = dict.formatTokenName(tokenPathClone);
|
|
643
|
-
const colorPaletteTokenKeys = token.path.slice(token.path.indexOf(colorPaletteRoot) + 1).reduce(
|
|
644
|
-
acc
|
|
645
|
-
|
|
646
|
-
|
|
665
|
+
const colorPaletteTokenKeys = token.path.slice(token.path.indexOf(colorPaletteRoot) + 1).reduce(
|
|
666
|
+
(acc, _, i, arr) => {
|
|
667
|
+
acc.push(arr.slice(i));
|
|
668
|
+
return acc;
|
|
669
|
+
},
|
|
670
|
+
[]
|
|
671
|
+
);
|
|
647
672
|
if (colorPaletteTokenKeys.length === 0) {
|
|
648
673
|
colorPaletteTokenKeys.push([""]);
|
|
649
674
|
}
|
|
@@ -662,6 +687,8 @@ var transforms = [
|
|
|
662
687
|
transformBorders,
|
|
663
688
|
transformAssets,
|
|
664
689
|
addCssVariables,
|
|
690
|
+
transformColorMix,
|
|
691
|
+
// depends on `addCssVariables`
|
|
665
692
|
addConditionalCssVariables,
|
|
666
693
|
addColorPalette
|
|
667
694
|
];
|
|
@@ -858,10 +885,13 @@ var TokenDictionary = class {
|
|
|
858
885
|
return;
|
|
859
886
|
const references = this.getReferences(token.value);
|
|
860
887
|
token.setExtensions({
|
|
861
|
-
references: references.reduce(
|
|
862
|
-
object
|
|
863
|
-
|
|
864
|
-
|
|
888
|
+
references: references.reduce(
|
|
889
|
+
(object, reference) => {
|
|
890
|
+
object[reference.name] = reference;
|
|
891
|
+
return object;
|
|
892
|
+
},
|
|
893
|
+
{}
|
|
894
|
+
)
|
|
865
895
|
});
|
|
866
896
|
});
|
|
867
897
|
return this;
|
|
@@ -887,11 +917,40 @@ var TokenDictionary = class {
|
|
|
887
917
|
});
|
|
888
918
|
return this;
|
|
889
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
|
+
};
|
|
890
940
|
/**
|
|
891
941
|
* Expand token references to their CSS variable
|
|
892
942
|
*/
|
|
893
943
|
expandReferenceInValue(value) {
|
|
894
|
-
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
|
+
});
|
|
895
954
|
}
|
|
896
955
|
/**
|
|
897
956
|
* Resolve token references to their actual raw value
|
|
@@ -1018,7 +1077,7 @@ var TokenDictionaryView = class {
|
|
|
1018
1077
|
byCategory.set(category, /* @__PURE__ */ new Map());
|
|
1019
1078
|
const value = isNegative ? token.isConditional ? token.originalValue : token.value : varRef;
|
|
1020
1079
|
byCategory.get(category).set(prop, value);
|
|
1021
|
-
flat.set(
|
|
1080
|
+
flat.set(token.name, value);
|
|
1022
1081
|
}
|
|
1023
1082
|
processVars(token, group) {
|
|
1024
1083
|
const { condition, isNegative, isVirtual, var: varName } = token.extensions;
|
package/dist/index.mjs
CHANGED
|
@@ -563,7 +563,26 @@ var transformAssets = {
|
|
|
563
563
|
match: (token) => token.extensions.category === "assets",
|
|
564
564
|
transform(token) {
|
|
565
565
|
const raw = token.value;
|
|
566
|
-
return match(raw).with(P2.string, (value) => value).with({ type: "url" }, ({ value }) => `url(
|
|
566
|
+
return match(raw).with(P2.string, (value) => value).with({ type: "url" }, ({ value }) => `url("${value}")`).with({ type: "svg" }, ({ value }) => `url("${svgToDataUri(value)}")`).exhaustive();
|
|
567
|
+
}
|
|
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
|
+
});
|
|
567
586
|
}
|
|
568
587
|
};
|
|
569
588
|
var addCssVariables = {
|
|
@@ -613,17 +632,23 @@ var addColorPalette = {
|
|
|
613
632
|
if (tokenPathClone.length === 0) {
|
|
614
633
|
return {};
|
|
615
634
|
}
|
|
616
|
-
const colorPaletteRoots = tokenPathClone.reduce(
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
635
|
+
const colorPaletteRoots = tokenPathClone.reduce(
|
|
636
|
+
(acc, _, i, arr) => {
|
|
637
|
+
const next = arr.slice(0, i + 1);
|
|
638
|
+
acc.push(next);
|
|
639
|
+
return acc;
|
|
640
|
+
},
|
|
641
|
+
[]
|
|
642
|
+
);
|
|
621
643
|
const colorPaletteRoot = tokenPathClone[0];
|
|
622
644
|
const colorPalette = dict.formatTokenName(tokenPathClone);
|
|
623
|
-
const colorPaletteTokenKeys = token.path.slice(token.path.indexOf(colorPaletteRoot) + 1).reduce(
|
|
624
|
-
acc
|
|
625
|
-
|
|
626
|
-
|
|
645
|
+
const colorPaletteTokenKeys = token.path.slice(token.path.indexOf(colorPaletteRoot) + 1).reduce(
|
|
646
|
+
(acc, _, i, arr) => {
|
|
647
|
+
acc.push(arr.slice(i));
|
|
648
|
+
return acc;
|
|
649
|
+
},
|
|
650
|
+
[]
|
|
651
|
+
);
|
|
627
652
|
if (colorPaletteTokenKeys.length === 0) {
|
|
628
653
|
colorPaletteTokenKeys.push([""]);
|
|
629
654
|
}
|
|
@@ -642,6 +667,8 @@ var transforms = [
|
|
|
642
667
|
transformBorders,
|
|
643
668
|
transformAssets,
|
|
644
669
|
addCssVariables,
|
|
670
|
+
transformColorMix,
|
|
671
|
+
// depends on `addCssVariables`
|
|
645
672
|
addConditionalCssVariables,
|
|
646
673
|
addColorPalette
|
|
647
674
|
];
|
|
@@ -838,10 +865,13 @@ var TokenDictionary = class {
|
|
|
838
865
|
return;
|
|
839
866
|
const references = this.getReferences(token.value);
|
|
840
867
|
token.setExtensions({
|
|
841
|
-
references: references.reduce(
|
|
842
|
-
object
|
|
843
|
-
|
|
844
|
-
|
|
868
|
+
references: references.reduce(
|
|
869
|
+
(object, reference) => {
|
|
870
|
+
object[reference.name] = reference;
|
|
871
|
+
return object;
|
|
872
|
+
},
|
|
873
|
+
{}
|
|
874
|
+
)
|
|
845
875
|
});
|
|
846
876
|
});
|
|
847
877
|
return this;
|
|
@@ -867,11 +897,40 @@ var TokenDictionary = class {
|
|
|
867
897
|
});
|
|
868
898
|
return this;
|
|
869
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
|
+
};
|
|
870
920
|
/**
|
|
871
921
|
* Expand token references to their CSS variable
|
|
872
922
|
*/
|
|
873
923
|
expandReferenceInValue(value) {
|
|
874
|
-
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
|
+
});
|
|
875
934
|
}
|
|
876
935
|
/**
|
|
877
936
|
* Resolve token references to their actual raw value
|
|
@@ -998,7 +1057,7 @@ var TokenDictionaryView = class {
|
|
|
998
1057
|
byCategory.set(category, /* @__PURE__ */ new Map());
|
|
999
1058
|
const value = isNegative ? token.isConditional ? token.originalValue : token.value : varRef;
|
|
1000
1059
|
byCategory.get(category).set(prop, value);
|
|
1001
|
-
flat.set(
|
|
1060
|
+
flat.set(token.name, value);
|
|
1002
1061
|
}
|
|
1003
1062
|
processVars(token, group) {
|
|
1004
1063
|
const { condition, isNegative, isVirtual, var: varName } = token.extensions;
|
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/
|
|
38
|
-
"@pandacss/
|
|
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",
|